mirror of
https://github.com/u-boot/u-boot.git
synced 2024-11-26 05:34:30 +08:00
pmic: dm: Rewrite pmic_reg_{read|write|clrsetbits} to support 3 bytes transmissions
This commit provides support for transmissions larger than 1 byte for PMIC devices used with DM (e.g. MC34708 from NXP). Signed-off-by: Lukasz Majewski <lukma@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
b8a6d6777b
commit
655b24cea6
@ -130,23 +130,35 @@ int pmic_write(struct udevice *dev, uint reg, const uint8_t *buffer, int len)
|
||||
|
||||
int pmic_reg_read(struct udevice *dev, uint reg)
|
||||
{
|
||||
u8 byte;
|
||||
struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
|
||||
u32 val = 0;
|
||||
int ret;
|
||||
|
||||
debug("%s: reg=%x", __func__, reg);
|
||||
ret = pmic_read(dev, reg, &byte, 1);
|
||||
debug(", value=%x, ret=%d\n", byte, ret);
|
||||
if (priv->trans_len < 1 || priv->trans_len > sizeof(val)) {
|
||||
debug("Wrong transmission size [%d]\n", priv->trans_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return ret ? ret : byte;
|
||||
debug("%s: reg=%x priv->trans_len:%d", __func__, reg, priv->trans_len);
|
||||
ret = pmic_read(dev, reg, (uint8_t *)&val, priv->trans_len);
|
||||
debug(", value=%x, ret=%d\n", val, ret);
|
||||
|
||||
return ret ? ret : val;
|
||||
}
|
||||
|
||||
int pmic_reg_write(struct udevice *dev, uint reg, uint value)
|
||||
{
|
||||
u8 byte = value;
|
||||
struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
|
||||
int ret;
|
||||
|
||||
debug("%s: reg=%x, value=%x", __func__, reg, value);
|
||||
ret = pmic_write(dev, reg, &byte, 1);
|
||||
if (priv->trans_len < 1 || priv->trans_len > sizeof(value)) {
|
||||
debug("Wrong transmission size [%d]\n", priv->trans_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
debug("%s: reg=%x, value=%x priv->trans_len:%d", __func__, reg, value,
|
||||
priv->trans_len);
|
||||
ret = pmic_write(dev, reg, (uint8_t *)&value, priv->trans_len);
|
||||
debug(", ret=%d\n", ret);
|
||||
|
||||
return ret;
|
||||
@ -154,15 +166,21 @@ int pmic_reg_write(struct udevice *dev, uint reg, uint value)
|
||||
|
||||
int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set)
|
||||
{
|
||||
u8 byte;
|
||||
struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
|
||||
u32 val = 0;
|
||||
int ret;
|
||||
|
||||
ret = pmic_reg_read(dev, reg);
|
||||
if (priv->trans_len < 1 || priv->trans_len > sizeof(val)) {
|
||||
debug("Wrong transmission size [%d]\n", priv->trans_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = pmic_read(dev, reg, (uint8_t *)&val, priv->trans_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
byte = (ret & ~clr) | set;
|
||||
|
||||
return pmic_reg_write(dev, reg, byte);
|
||||
val = (val & ~clr) | set;
|
||||
return pmic_write(dev, reg, (uint8_t *)&val, priv->trans_len);
|
||||
}
|
||||
|
||||
static int pmic_pre_probe(struct udevice *dev)
|
||||
|
Loading…
Reference in New Issue
Block a user