coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
smbus_ops.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/smbus.h>
7 
8 struct bus *get_pbus_smbus(struct device *dev)
9 {
10  struct bus *const pbus = i2c_link(dev);
11  if (!pbus->dev->ops->ops_smbus_bus) {
12  printk(BIOS_ALERT, "%s Cannot find SMBus bus operations",
13  dev_path(dev));
14  die("");
15  }
16  return pbus;
17 }
18 
19 #define CHECK_PRESENCE(x) \
20  if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \
21  printk(BIOS_ERR, "%s missing " #x "\n", \
22  dev_path(dev)); \
23  return -1; \
24  }
25 
26 int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer)
27 {
28  CHECK_PRESENCE(block_read);
29 
31  bytes, buffer);
32 }
33 
34 int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer)
35 {
36  CHECK_PRESENCE(block_write);
37 
39  bytes, buffer);
40 }
#define printk(level,...)
Definition: stdlib.h:16
void __noreturn die(const char *fmt,...)
Definition: die.c:17
int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer)
Definition: smbus_ops.c:34
#define CHECK_PRESENCE(x)
Definition: smbus_ops.c:19
struct bus * get_pbus_smbus(struct device *dev)
Definition: smbus_ops.c:8
int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer)
Definition: smbus_ops.c:26
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
struct bus * i2c_link(const struct device *const dev)
Definition: i2c_bus.c:9
static const struct smbus_bus_operations * ops_smbus_bus(struct bus *bus)
Definition: smbus.h:19
#define BIOS_ALERT
BIOS_ALERT - Dying / Unrecoverable.
Definition: loglevel.h:41
u8 buffer[C2P_BUFFER_MAXSIZE]
Definition: psp_smm.c:18
uint8_t u8
Definition: stdint.h:45
Definition: device.h:76
DEVTREE_CONST struct device * dev
Definition: device.h:78
const struct smbus_bus_operations * ops_smbus_bus
Definition: device.h:65
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
int(* block_write)(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer)
Definition: smbus.h:15
int(* block_read)(struct device *dev, u8 cmd, u8 bytes, u8 *buffer)
Definition: smbus.h:14