mb/siemens/mc_apl2: Disable unused I2C controllers
[coreboot.git] / src / device / i2c.c
blobe05270f685b53fd9ebad7f51e11af0c558b31968
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/i2c_simple.h>
4 #include <stdint.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)
9 int ret;
10 uint8_t buf = 0;
12 ret = i2c_readb(bus, chip, reg, &buf);
14 buf &= (mask << shift);
15 *data = (buf >> shift);
17 return ret;
20 int i2c_write_field(unsigned int bus, uint8_t chip, uint8_t reg, uint8_t data,
21 uint8_t mask, uint8_t shift)
23 int ret;
24 uint8_t buf = 0;
26 ret = i2c_readb(bus, chip, reg, &buf);
28 buf &= ~(mask << shift);
29 buf |= (data << shift);
31 ret |= i2c_writeb(bus, chip, reg, buf);
33 return ret;