diff options
| author | Sebastian Reichel <[email protected]> | 2021-07-15 17:39:59 +0200 |
|---|---|---|
| committer | Heiko Schocher <[email protected]> | 2021-08-22 10:52:53 +0200 |
| commit | 2aefa6e3f2ab621483ca645b16c7bf8cb9334fa3 (patch) | |
| tree | ce32ac1a9ee05266489dd58f9ff0ade8852e51cb /drivers | |
| parent | 79d389a54891a67269bfa366f044a2079409e499 (diff) | |
i2c: add dm_i2c_reg_clrset
Add function to apply a bitmask to an i2c register, so
that specific bits can be cleared and/or set.
Suggested-by: Simon Glass <[email protected]>
Signed-off-by: Sebastian Reichel <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/i2c/i2c-uclass.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index 04c88503a2f..db1c9d94624 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -247,6 +247,21 @@ int dm_i2c_reg_write(struct udevice *dev, uint offset, uint value) return dm_i2c_write(dev, offset, &val, 1); } +int dm_i2c_reg_clrset(struct udevice *dev, uint offset, u32 clr, u32 set) +{ + uint8_t val; + int ret; + + ret = dm_i2c_read(dev, offset, &val, 1); + if (ret < 0) + return ret; + + val &= ~clr; + val |= set; + + return dm_i2c_write(dev, offset, &val, 1); +} + /** * i2c_probe_chip() - probe for a chip on a bus * |
