Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 1 | #ifndef DEVICE_SMBUS_H |
| 2 | #define DEVICE_SMBUS_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <device/device.h> |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 6 | #include <device/i2c_bus.h> |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 7 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 8 | /* Common SMBus bus operations */ |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 9 | struct smbus_bus_operations { |
Elyes HAOUAS | 3b55275 | 2018-11-29 08:25:49 +0100 | [diff] [blame] | 10 | int (*recv_byte)(struct device *dev); |
| 11 | int (*send_byte)(struct device *dev, u8 value); |
| 12 | int (*read_byte)(struct device *dev, u8 addr); |
| 13 | int (*write_byte)(struct device *dev, u8 addr, u8 value); |
| 14 | int (*block_read)(struct device *dev, u8 cmd, u8 bytes, u8 *buffer); |
| 15 | int (*block_write)(struct device *dev, u8 cmd, u8 bytes, |
| 16 | const u8 *buffer); |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 17 | }; |
| 18 | |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 19 | static inline const struct smbus_bus_operations *ops_smbus_bus(struct bus *bus) |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 20 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 21 | const struct smbus_bus_operations *bops; |
| 22 | |
| 23 | bops = 0; |
| 24 | if (bus && bus->dev && bus->dev->ops) |
| 25 | bops = bus->dev->ops->ops_smbus_bus; |
| 26 | |
| 27 | return bops; |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 28 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 29 | |
Elyes HAOUAS | 3b55275 | 2018-11-29 08:25:49 +0100 | [diff] [blame] | 30 | struct bus *get_pbus_smbus(struct device *dev); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 31 | |
Kyösti Mälkki | 1a1b04e | 2020-01-07 22:34:33 +0200 | [diff] [blame] | 32 | #if !DEVTREE_EARLY |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 33 | static inline int smbus_recv_byte(struct device *const dev) |
| 34 | { |
Aaron Durbin | 439cee9 | 2018-01-22 21:24:35 -0700 | [diff] [blame] | 35 | return i2c_dev_readb(dev); |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static inline int smbus_send_byte(struct device *const dev, u8 byte) |
| 39 | { |
Aaron Durbin | 439cee9 | 2018-01-22 21:24:35 -0700 | [diff] [blame] | 40 | return i2c_dev_writeb(dev, byte); |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline int smbus_read_byte(struct device *const dev, u8 addr) |
| 44 | { |
Aaron Durbin | 439cee9 | 2018-01-22 21:24:35 -0700 | [diff] [blame] | 45 | return i2c_dev_readb_at(dev, addr); |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static inline int smbus_write_byte(struct device *const dev, u8 addr, u8 val) |
| 49 | { |
Aaron Durbin | 439cee9 | 2018-01-22 21:24:35 -0700 | [diff] [blame] | 50 | return i2c_dev_writeb_at(dev, addr, val); |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 51 | } |
| 52 | |
Elyes HAOUAS | f9e47cc | 2018-12-05 11:03:36 +0100 | [diff] [blame] | 53 | int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer); |
| 54 | int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer); |
Kyösti Mälkki | 1a1b04e | 2020-01-07 22:34:33 +0200 | [diff] [blame] | 55 | #endif |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 56 | |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 57 | #endif /* DEVICE_SMBUS_H */ |