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