1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/i2c_simple.h>
6 int i2c_read_field(unsigned int bus
, uint8_t chip
, uint8_t reg
, uint8_t *data
,
7 uint8_t mask
, uint8_t shift
)
12 ret
= i2c_readb(bus
, chip
, reg
, &buf
);
14 buf
&= (mask
<< shift
);
15 *data
= (buf
>> shift
);
20 int i2c_write_field(unsigned int bus
, uint8_t chip
, uint8_t reg
, uint8_t data
,
21 uint8_t mask
, uint8_t shift
)
26 ret
= i2c_readb(bus
, chip
, reg
, &buf
);
28 buf
&= ~(mask
<< shift
);
29 buf
|= (data
<< shift
);
31 ret
|= i2c_writeb(bus
, chip
, reg
, buf
);