coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
i2c.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/i2c_simple.h>
4 #include <stdint.h>
5 
6 int i2c_read_field(unsigned int bus, uint8_t chip, uint8_t reg, uint8_t *data,
7  uint8_t mask, uint8_t shift)
8 {
9  int ret;
10  uint8_t buf = 0;
11 
12  ret = i2c_readb(bus, chip, reg, &buf);
13 
14  buf &= (mask << shift);
15  *data = (buf >> shift);
16 
17  return ret;
18 }
19 
20 int i2c_write_field(unsigned int bus, uint8_t chip, uint8_t reg, uint8_t data,
21  uint8_t mask, uint8_t shift)
22 {
23  int ret;
24  uint8_t buf = 0;
25 
26  ret = i2c_readb(bus, chip, reg, &buf);
27 
28  buf &= ~(mask << shift);
29  buf |= (data << shift);
30 
31  ret |= i2c_writeb(bus, chip, reg, buf);
32 
33  return ret;
34 }
int i2c_read_field(unsigned int bus, uint8_t chip, uint8_t reg, uint8_t *data, uint8_t mask, uint8_t shift)
Definition: i2c.c:6
int i2c_write_field(unsigned int bus, uint8_t chip, uint8_t reg, uint8_t data, uint8_t mask, uint8_t shift)
Definition: i2c.c:20
static struct tpm_chip chip
Definition: tis.c:17
static int i2c_writeb(unsigned int bus, uint8_t slave, uint8_t reg, uint8_t data)
Write a byte with one segment in one frame.
Definition: i2c_simple.h:131
static int i2c_readb(unsigned int bus, uint8_t slave, uint8_t reg, uint8_t *data)
Read a byte with two segments in one frame.
Definition: i2c_simple.h:109
static uint8_t * buf
Definition: uart.c:7
static const int mask[4]
Definition: gpio.c:308
unsigned char uint8_t
Definition: stdint.h:8
Definition: device.h:76