2020-04-02 23:48:16 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2007-04-22 21:08:13 +02:00
|
|
|
|
2004-12-03 04:39:04 +01:00
|
|
|
#include <stdint.h>
|
2017-08-02 16:57:17 +02:00
|
|
|
#include <console/console.h>
|
2004-12-03 04:39:04 +01:00
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/smbus.h>
|
|
|
|
|
2018-05-02 21:26:01 +02:00
|
|
|
struct bus *get_pbus_smbus(struct device *dev)
|
2004-12-03 04:39:04 +01:00
|
|
|
{
|
2017-08-02 16:57:17 +02:00
|
|
|
struct bus *const pbus = i2c_link(dev);
|
|
|
|
if (!pbus->dev->ops->ops_smbus_bus) {
|
2010-10-18 02:00:57 +02:00
|
|
|
printk(BIOS_ALERT, "%s Cannot find SMBus bus operations",
|
|
|
|
dev_path(dev));
|
2004-12-03 04:39:04 +01:00
|
|
|
die("");
|
|
|
|
}
|
|
|
|
return pbus;
|
|
|
|
}
|
|
|
|
|
2014-01-27 23:46:46 +01:00
|
|
|
#define CHECK_PRESENCE(x) \
|
|
|
|
if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \
|
|
|
|
printk(BIOS_ERR, "%s missing " #x "\n", \
|
|
|
|
dev_path(dev)); \
|
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:26:01 +02:00
|
|
|
int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer)
|
2004-12-03 04:39:04 +01:00
|
|
|
{
|
2014-01-27 23:46:46 +01:00
|
|
|
CHECK_PRESENCE(block_read);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd,
|
|
|
|
bytes, buffer);
|
2004-12-03 04:39:04 +01:00
|
|
|
}
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2018-05-02 21:26:01 +02:00
|
|
|
int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer)
|
2004-12-03 04:39:04 +01:00
|
|
|
{
|
2014-01-27 23:46:46 +01:00
|
|
|
CHECK_PRESENCE(block_write);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd,
|
|
|
|
bytes, buffer);
|
2004-12-03 04:39:04 +01:00
|
|
|
}
|