1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/smbus.h>
8 struct bus
*get_pbus_smbus(struct device
*dev
)
10 struct bus
*const pbus
= i2c_link(dev
);
11 if (!pbus
->dev
->ops
->ops_smbus_bus
)
12 die("%s Cannot find SMBus bus operations", dev_path(dev
));
16 #define CHECK_PRESENCE(x) \
17 if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \
18 printk(BIOS_ERR, "%s missing " #x "\n", \
23 int smbus_block_read(struct device
*dev
, u8 cmd
, u8 bytes
, u8
*buffer
)
25 CHECK_PRESENCE(block_read
);
27 return ops_smbus_bus(get_pbus_smbus(dev
))->block_read(dev
, cmd
,
31 int smbus_block_write(struct device
*dev
, u8 cmd
, u8 bytes
, const u8
*buffer
)
33 CHECK_PRESENCE(block_write
);
35 return ops_smbus_bus(get_pbus_smbus(dev
))->block_write(dev
, cmd
,