summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/device/smbus_ops.c51
-rw-r--r--src/include/device/smbus.h26
2 files changed, 24 insertions, 53 deletions
diff --git a/src/device/smbus_ops.c b/src/device/smbus_ops.c
index 4072402555..2a8670272b 100644
--- a/src/device/smbus_ops.c
+++ b/src/device/smbus_ops.c
@@ -15,35 +15,19 @@
* GNU General Public License for more details.
*/
-#include <console/console.h>
#include <stdint.h>
+#include <console/console.h>
#include <device/device.h>
-#include <device/path.h>
#include <device/smbus.h>
struct bus *get_pbus_smbus(device_t dev)
{
- struct bus *pbus = dev->bus;
-
- while (pbus && pbus->dev && !ops_smbus_bus(pbus)) {
- if (pbus->dev->bus != pbus) {
- pbus = pbus->dev->bus;
- }
- else {
- printk(BIOS_WARNING,
- "%s Find SMBus bus operations: unable to proceed\n",
- dev_path(dev));
- break;
- }
- }
-
- if (!pbus || !pbus->dev || !pbus->dev->ops
- || !pbus->dev->ops->ops_smbus_bus) {
+ struct bus *const pbus = i2c_link(dev);
+ if (!pbus->dev->ops->ops_smbus_bus) {
printk(BIOS_ALERT, "%s Cannot find SMBus bus operations",
dev_path(dev));
die("");
}
-
return pbus;
}
@@ -91,35 +75,6 @@ int smbus_set_link(device_t dev)
return -1; \
}
-
-int smbus_recv_byte(device_t dev)
-{
- CHECK_PRESENCE(recv_byte);
-
- return ops_smbus_bus(get_pbus_smbus(dev))->recv_byte(dev);
-}
-
-int smbus_send_byte(device_t dev, u8 byte)
-{
- CHECK_PRESENCE(send_byte);
-
- return ops_smbus_bus(get_pbus_smbus(dev))->send_byte(dev, byte);
-}
-
-int smbus_read_byte(device_t dev, u8 addr)
-{
- CHECK_PRESENCE(read_byte);
-
- return ops_smbus_bus(get_pbus_smbus(dev))->read_byte(dev, addr);
-}
-
-int smbus_write_byte(device_t dev, u8 addr, u8 val)
-{
- CHECK_PRESENCE(write_byte);
-
- return ops_smbus_bus(get_pbus_smbus(dev))->write_byte(dev, addr, val);
-}
-
int smbus_block_read(device_t dev, u8 cmd, u8 bytes, u8 *buffer)
{
CHECK_PRESENCE(block_read);
diff --git a/src/include/device/smbus.h b/src/include/device/smbus.h
index 80eafdb969..5e51b5d267 100644
--- a/src/include/device/smbus.h
+++ b/src/include/device/smbus.h
@@ -3,7 +3,7 @@
#include <stdint.h>
#include <device/device.h>
-#include <device/path.h>
+#include <device/i2c_bus.h>
#include <device/smbus_def.h>
/* Common SMBus bus operations */
@@ -30,10 +30,26 @@ static inline const struct smbus_bus_operations *ops_smbus_bus(struct bus *bus)
struct bus *get_pbus_smbus(device_t dev);
int smbus_set_link(device_t dev);
-int smbus_recv_byte(device_t dev);
-int smbus_send_byte(device_t dev, u8 byte);
-int smbus_read_byte(device_t dev, u8 addr);
-int smbus_write_byte(device_t dev, u8 addr, u8 val);
+static inline int smbus_recv_byte(struct device *const dev)
+{
+ return i2c_readb(dev);
+}
+
+static inline int smbus_send_byte(struct device *const dev, u8 byte)
+{
+ return i2c_writeb(dev, byte);
+}
+
+static inline int smbus_read_byte(struct device *const dev, u8 addr)
+{
+ return i2c_readb_at(dev, addr);
+}
+
+static inline int smbus_write_byte(struct device *const dev, u8 addr, u8 val)
+{
+ return i2c_writeb_at(dev, addr, val);
+}
+
int smbus_block_read(device_t dev, u8 cmd, u8 bytes, u8 *buffer);
int smbus_block_write(device_t dev, u8 cmd, u8 bytes, const u8 *buffer);