1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* This file is part of the coreboot project. */
4 #include <device/i2c_simple.h>
7 int i2c_read_field(unsigned int bus
, uint8_t chip
, uint8_t reg
, uint8_t *data
,
8 uint8_t mask
, uint8_t shift
)
13 ret
= i2c_readb(bus
, chip
, reg
, &buf
);
15 buf
&= (mask
<< shift
);
16 *data
= (buf
>> shift
);
21 int i2c_write_field(unsigned int bus
, uint8_t chip
, uint8_t reg
, uint8_t data
,
22 uint8_t mask
, uint8_t shift
)
27 ret
= i2c_readb(bus
, chip
, reg
, &buf
);
29 buf
&= ~(mask
<< shift
);
30 buf
|= (data
<< shift
);
32 ret
|= i2c_writeb(bus
, chip
, reg
, buf
);