soc/intel/tigerlake: Add PMC mux control
[coreboot.git] / src / device / i2c.c
blobdbb355470f898aff89eef60d7f31e0eb0f3456b1
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* This file is part of the coreboot project. */
4 #include <device/i2c_simple.h>
5 #include <stdint.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)
10 int ret;
11 uint8_t buf = 0;
13 ret = i2c_readb(bus, chip, reg, &buf);
15 buf &= (mask << shift);
16 *data = (buf >> shift);
18 return ret;
21 int i2c_write_field(unsigned int bus, uint8_t chip, uint8_t reg, uint8_t data,
22 uint8_t mask, uint8_t shift)
24 int ret;
25 uint8_t buf = 0;
27 ret = i2c_readb(bus, chip, reg, &buf);
29 buf &= ~(mask << shift);
30 buf |= (data << shift);
32 ret |= i2c_writeb(bus, chip, reg, buf);
34 return ret;