7 #define PM_DEVFN PCI_DEVFN(0x1f,3)
10 #define SMBUS_IO_BASE 0x1000
20 void smbus_enable(void)
24 pcibios_write_config_dword(PM_BUS, PM_DEVFN, 0x20, SMBUS_IO_BASE | 1);
26 pcibios_write_config_byte(PM_BUS, PM_DEVFN, 0x40, 1);
28 pcibios_write_config_word(PM_BUS, PM_DEVFN, 0x4, 1);
30 /* Disable interrupt generation */
31 outb(0, SMBUS_IO_BASE + SMBHSTCTL);
35 void smbus_setup(void)
37 outb(0, SMBUS_IO_BASE + SMBHSTSTAT);
40 static void smbus_wait_until_ready(void)
42 while((inb(SMBUS_IO_BASE + SMBHSTSTAT) & 1) == 1) {
47 static void smbus_wait_until_done(void)
51 byte = inb(SMBUS_IO_BASE + SMBHSTSTAT);
53 while((byte &1) == 1);
54 while( (byte & ~1) == 0) {
55 byte = inb(SMBUS_IO_BASE + SMBHSTSTAT);
59 int smbus_read_byte(unsigned device, unsigned address, unsigned char *result)
61 unsigned char host_status_register;
64 smbus_wait_until_ready();
66 /* setup transaction */
67 /* disable interrupts */
68 outb(inb(SMBUS_IO_BASE + SMBHSTCTL) & (~1), SMBUS_IO_BASE + SMBHSTCTL);
69 /* set the device I'm talking too */
70 outb(((device & 0x7f) << 1) | 1, SMBUS_IO_BASE + SMBHSTADD);
71 /* set the command/address... */
72 outb(address & 0xFF, SMBUS_IO_BASE + SMBHSTCMD);
73 /* set up for a byte data read */
74 outb((inb(SMBUS_IO_BASE + SMBHSTCTL) & 0xE3) | (0x2 << 2), SMBUS_IO_BASE + SMBHSTCTL);
76 /* clear any lingering errors, so the transaction will run */
77 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
79 /* clear the data byte...*/
80 outb(0, SMBUS_IO_BASE + SMBHSTDAT0);
82 /* start the command */
83 outb((inb(SMBUS_IO_BASE + SMBHSTCTL) | 0x40), SMBUS_IO_BASE + SMBHSTCTL);
85 /* poll for transaction completion */
86 smbus_wait_until_done();
88 host_status_register = inb(SMBUS_IO_BASE + SMBHSTSTAT);
90 /* read results of transaction */
91 byte = inb(SMBUS_IO_BASE + SMBHSTDAT0);
94 return host_status_register != 0x02;