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 | #include <device/smbus_def.h> |
| 8 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 9 | /* Common SMBus bus operations */ |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 10 | struct smbus_bus_operations { |
Lee Leahy | bab6bc4 | 2017-03-07 16:10:21 -0800 | [diff] [blame] | 11 | int (*recv_byte)(device_t dev); |
| 12 | int (*send_byte)(device_t dev, u8 value); |
| 13 | int (*read_byte)(device_t dev, u8 addr); |
| 14 | int (*write_byte)(device_t dev, u8 addr, u8 value); |
Lee Leahy | bab6bc4 | 2017-03-07 16:10:21 -0800 | [diff] [blame] | 15 | int (*block_read)(device_t dev, u8 cmd, u8 bytes, u8 *buffer); |
| 16 | int (*block_write)(device_t dev, u8 cmd, u8 bytes, 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 | |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 30 | struct bus *get_pbus_smbus(device_t dev); |
| 31 | int smbus_set_link(device_t dev); |
| 32 | |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame^] | 33 | static inline int smbus_recv_byte(struct device *const dev) |
| 34 | { |
| 35 | return i2c_readb(dev); |
| 36 | } |
| 37 | |
| 38 | static inline int smbus_send_byte(struct device *const dev, u8 byte) |
| 39 | { |
| 40 | return i2c_writeb(dev, byte); |
| 41 | } |
| 42 | |
| 43 | static inline int smbus_read_byte(struct device *const dev, u8 addr) |
| 44 | { |
| 45 | return i2c_readb_at(dev, addr); |
| 46 | } |
| 47 | |
| 48 | static inline int smbus_write_byte(struct device *const dev, u8 addr, u8 val) |
| 49 | { |
| 50 | return i2c_writeb_at(dev, addr, val); |
| 51 | } |
| 52 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 53 | int smbus_block_read(device_t dev, u8 cmd, u8 bytes, u8 *buffer); |
| 54 | int smbus_block_write(device_t dev, u8 cmd, u8 bytes, const u8 *buffer); |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 55 | |
Timothy Pearson | acbdade | 2015-10-17 04:36:47 -0500 | [diff] [blame] | 56 | #if IS_ENABLED(CONFIG_SMBUS_HAS_AUX_CHANNELS) |
| 57 | void smbus_switch_to_channel(uint8_t channel_number); |
| 58 | uint8_t smbus_get_current_channel(void); |
| 59 | #endif |
| 60 | |
Eric Biederman | 992cd00 | 2004-10-14 21:10:23 +0000 | [diff] [blame] | 61 | #endif /* DEVICE_SMBUS_H */ |