Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 2 | |
| 3 | #ifndef __DEVICE_SMBUS_HOST_H__ |
| 4 | #define __DEVICE_SMBUS_HOST_H__ |
| 5 | |
| 6 | #include <stdint.h> |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 7 | #include <console/console.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 8 | |
| 9 | /* Low-level SMBUS host controller. */ |
| 10 | |
| 11 | int do_smbus_recv_byte(uintptr_t base, u8 device); |
| 12 | int do_smbus_send_byte(uintptr_t base, u8 device, u8 val); |
| 13 | int do_smbus_read_byte(uintptr_t base, u8 device, u8 address); |
| 14 | int do_smbus_write_byte(uintptr_t base, u8 device, u8 address, u8 data); |
| 15 | int do_smbus_read_word(uintptr_t base, u8 device, u8 address); |
| 16 | int do_smbus_write_word(uintptr_t base, u8 device, u8 address, u16 data); |
| 17 | |
| 18 | int do_smbus_block_read(uintptr_t base, u8 device, u8 cmd, size_t max_bytes, u8 *buf); |
| 19 | int do_smbus_block_write(uintptr_t base, u8 device, u8 cmd, size_t bytes, const u8 *buf); |
Christian Walter | 04953eb | 2020-03-27 11:59:43 +0100 | [diff] [blame] | 20 | int do_smbus_process_call(uintptr_t base, u8 device, u8 cmd, u16 data, u16 *buf); |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 21 | |
| 22 | /* For Intel, implemented since ICH5. */ |
| 23 | int do_i2c_eeprom_read(uintptr_t base, u8 device, u8 offset, size_t bytes, u8 *buf); |
| 24 | int do_i2c_block_write(uintptr_t base, u8 device, size_t bytes, u8 *buf); |
| 25 | |
Kyösti Mälkki | 7cdcc38 | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 26 | /* Upstream API */ |
| 27 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 28 | uintptr_t smbus_base(void); |
| 29 | int smbus_enable_iobar(uintptr_t base); |
Kyösti Mälkki | 7cdcc38 | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 30 | void smbus_host_reset(uintptr_t base); |
Kyösti Mälkki | 73451fd | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 31 | void smbus_set_slave_addr(uintptr_t base, u8 slave_address); |
Kyösti Mälkki | 7cdcc38 | 2020-01-06 19:00:31 +0200 | [diff] [blame] | 32 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 33 | static inline void enable_smbus(void) |
| 34 | { |
| 35 | uintptr_t base = smbus_base(); |
| 36 | |
| 37 | if (smbus_enable_iobar(base) < 0) |
| 38 | die("SMBus controller not found!"); |
| 39 | |
| 40 | smbus_host_reset(base); |
| 41 | printk(BIOS_DEBUG, "SMBus controller enabled\n"); |
| 42 | } |
| 43 | |
Kyösti Mälkki | 1a1b04e | 2020-01-07 22:34:33 +0200 | [diff] [blame^] | 44 | #if DEVTREE_EARLY |
| 45 | static inline int smbus_read_byte(u8 device, u8 address) |
| 46 | { |
| 47 | uintptr_t base = smbus_base(); |
| 48 | return do_smbus_read_byte(base, device, address); |
| 49 | } |
| 50 | |
| 51 | static inline int smbus_read_word(u8 device, u8 address) |
| 52 | { |
| 53 | uintptr_t base = smbus_base(); |
| 54 | return do_smbus_read_word(base, device, address); |
| 55 | } |
| 56 | |
| 57 | static inline int smbus_write_byte(u8 device, u8 address, u8 data) |
| 58 | { |
| 59 | uintptr_t base = smbus_base(); |
| 60 | return do_smbus_write_byte(base, device, address, data); |
| 61 | } |
| 62 | |
| 63 | static inline int smbus_block_read(u8 device, u8 cmd, size_t max_bytes, u8 *buf) |
| 64 | { |
| 65 | uintptr_t base = smbus_base(); |
| 66 | return do_smbus_block_read(base, device, cmd, max_bytes, buf); |
| 67 | } |
| 68 | |
| 69 | static inline int smbus_block_write(u8 device, u8 cmd, size_t bytes, const u8 *buf) |
| 70 | { |
| 71 | uintptr_t base = smbus_base(); |
| 72 | return do_smbus_block_write(base, device, cmd, bytes, buf); |
| 73 | } |
| 74 | |
| 75 | static inline int i2c_eeprom_read(u8 device, u8 offset, size_t bytes, u8 *buf) |
| 76 | { |
| 77 | uintptr_t base = smbus_base(); |
| 78 | return do_i2c_eeprom_read(base, device, offset, bytes, buf); |
| 79 | } |
| 80 | #endif |
| 81 | |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 82 | #endif |