| 1 |
|
| 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 |
die("%s Cannot find SMBus bus operations", dev_path(dev)); |
| 13 |
return pbus; |
| 14 |
} |
| 15 |
|
| 16 |
#define CHECK_PRESENCE(x) \ |
| 17 |
if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \ |
| 18 |
printk(BIOS_ERR, "%s missing " #x "\n", \ |
| 19 |
dev_path(dev)); \ |
| 20 |
return -1; \ |
| 21 |
} |
| 22 |
|
| 23 |
int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer) |
| 24 |
{ |
| 25 |
CHECK_PRESENCE(block_read); |
| 26 |
|
| 27 |
return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, |
| 28 |
bytes, buffer); |
| 29 |
} |
| 30 |
|
| 31 |
int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer) |
| 32 |
{ |
| 33 |
CHECK_PRESENCE(block_write); |
| 34 |
|
| 35 |
return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, |
| 36 |
bytes, buffer); |
| 37 |
} |