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 | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 44 | #endif |