1 #define SMBUS_IO_BASE 0x1000
3 #define SMBGSTATUS 0xe0
5 #define SMBHSTADDR 0xe4
8 #define SMBHSTFIFO 0xe9
10 #define SMBUS_TIMEOUT (100*1000*10)
12 static void enable_smbus(void)
15 dev = pci_locate_device(PCI_ID(0x1022, 0x746b), 0);
16 if (dev == PCI_DEV_INVALID) {
17 die("SMBUS controller not found\r\n");
20 print_debug("SMBus controller enabled\r\n");
21 pci_write_config32(dev, 0x58, SMBUS_IO_BASE | 1);
22 enable = pci_read_config8(dev, 0x41);
23 pci_write_config8(dev, 0x41, enable | (1 << 7));
27 static inline void smbus_delay(void)
32 static int smbus_wait_until_ready(void)
35 loops = SMBUS_TIMEOUT;
39 val = inw(SMBUS_IO_BASE + SMBGSTATUS);
40 if ((val & 0x800) == 0) {
47 static int smbus_wait_until_done(void)
50 loops = SMBUS_TIMEOUT;
55 val = inw(SMBUS_IO_BASE + SMBGSTATUS);
56 if (((val & 0x8) == 0) | ((val & 0x437) != 0)) {
63 static int smbus_read_byte(unsigned device, unsigned address)
65 unsigned char global_control_register;
66 unsigned char global_status_register;
69 if (smbus_wait_until_ready() < 0) {
73 /* setup transaction */
74 /* disable interrupts */
75 outw(inw(SMBUS_IO_BASE + SMBGCTL) & ~((1<<10)|(1<<9)|(1<<8)|(1<<4)), SMBUS_IO_BASE + SMBGCTL);
76 /* set the device I'm talking too */
77 outw(((device & 0x7f) << 1) | 1, SMBUS_IO_BASE + SMBHSTADDR);
78 /* set the command/address... */
79 outb(address & 0xFF, SMBUS_IO_BASE + SMBHSTCMD);
80 /* set up for a byte data read */
81 outw((inw(SMBUS_IO_BASE + SMBGCTL) & ~7) | (0x2), SMBUS_IO_BASE + SMBGCTL);
83 /* clear any lingering errors, so the transaction will run */
84 /* Do I need to write the bits to a 1 to clear an error? */
85 outw(inw(SMBUS_IO_BASE + SMBGSTATUS), SMBUS_IO_BASE + SMBGSTATUS);
87 /* clear the data word...*/
88 outw(0, SMBUS_IO_BASE + SMBHSTDAT);
90 /* start the command */
91 outw((inw(SMBUS_IO_BASE + SMBGCTL) | (1 << 3)), SMBUS_IO_BASE + SMBGCTL);
94 /* poll for transaction completion */
95 if (smbus_wait_until_done() < 0) {
99 global_status_register = inw(SMBUS_IO_BASE + SMBGSTATUS);
101 /* read results of transaction */
102 byte = inw(SMBUS_IO_BASE + SMBHSTDAT) & 0xff;
104 if (global_status_register != (1 << 4)) {