include/spd_bin.h: Add SPD IO layer
[coreboot2.git] / src / include / device / smbus_host.h
blobe113aec94a30608b1c919f2b874c9d6f35c267bb
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef __DEVICE_SMBUS_HOST_H__
4 #define __DEVICE_SMBUS_HOST_H__
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <console/console.h>
10 /* Low-level SMBUS host controller. */
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);
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);
21 int do_smbus_process_call(uintptr_t base, u8 device, u8 cmd, u16 data, u16 *buf);
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);
27 /* Upstream API */
29 uintptr_t smbus_base(void);
30 int smbus_enable_iobar(uintptr_t base);
31 void smbus_host_reset(uintptr_t base);
32 void smbus_set_slave_addr(uintptr_t base, u8 slave_address);
34 static inline void enable_smbus(void)
36 uintptr_t base = smbus_base();
38 if (smbus_enable_iobar(base) < 0)
39 die("SMBus controller not found!");
41 smbus_host_reset(base);
42 printk(BIOS_DEBUG, "SMBus controller enabled\n");
45 #if DEVTREE_EARLY
46 static inline int smbus_read_byte(u8 device, u8 address)
48 uintptr_t base = smbus_base();
49 return do_smbus_read_byte(base, device, address);
52 static inline int smbus_read_word(u8 device, u8 address)
54 uintptr_t base = smbus_base();
55 return do_smbus_read_word(base, device, address);
58 static inline int smbus_write_byte(u8 device, u8 address, u8 data)
60 uintptr_t base = smbus_base();
61 return do_smbus_write_byte(base, device, address, data);
64 static inline int smbus_block_read(u8 device, u8 cmd, size_t max_bytes, u8 *buf)
66 uintptr_t base = smbus_base();
67 return do_smbus_block_read(base, device, cmd, max_bytes, buf);
70 static inline int smbus_block_write(u8 device, u8 cmd, size_t bytes, const u8 *buf)
72 uintptr_t base = smbus_base();
73 return do_smbus_block_write(base, device, cmd, bytes, buf);
76 static inline int i2c_eeprom_read(u8 device, u8 offset, size_t bytes, u8 *buf)
78 uintptr_t base = smbus_base();
79 return do_i2c_eeprom_read(base, device, offset, bytes, buf);
81 #endif
83 #endif