1 #include <device/smbus_def.h>
10 #define SMBTRNSADD 0x9
11 #define SMBSLVDATA 0xa
12 #define SMLINK_PIN_CTL 0xe
13 #define SMBUS_PIN_CTL 0xf
15 #define SMBUS_TIMEOUT (100*1000*10)
18 static void smbus_delay(void)
23 static int smbus_wait_until_ready(unsigned smbus_io_base)
25 unsigned loops = SMBUS_TIMEOUT;
31 byte = inb(smbus_io_base + SMBHSTSTAT);
36 static int smbus_wait_until_done(unsigned smbus_io_base)
38 unsigned loops = SMBUS_TIMEOUT;
44 byte = inb(smbus_io_base + SMBHSTSTAT);
45 } while((byte & 1) || (byte & ~((1<<6)|(1<<0))) == 0);
49 static inline int smbus_wait_until_blk_done(unsigned smbus_io_base)
51 unsigned loops = SMBUS_TIMEOUT;
57 byte = inb(smbus_io_base + SMBHSTSTAT);
58 } while((byte&(1<<7)) == 0);
62 static int do_smbus_read_byte(unsigned smbus_io_base, unsigned device, unsigned address)
64 unsigned char global_status_register;
67 if (smbus_wait_until_ready(smbus_io_base) < 0) {
68 return SMBUS_WAIT_UNTIL_READY_TIMEOUT;
70 /* setup transaction */
71 /* disable interrupts */
72 outb(inb(smbus_io_base + SMBHSTCTL) & (~1), smbus_io_base + SMBHSTCTL);
73 /* set the device I'm talking too */
74 outb(((device & 0x7f) << 1) | 1, smbus_io_base + SMBXMITADD);
75 /* set the command/address... */
76 outb(address & 0xFF, smbus_io_base + SMBHSTCMD);
77 /* set up for a byte data read */
78 outb((inb(smbus_io_base + SMBHSTCTL) & 0xE3) | (0x2 << 2), smbus_io_base + SMBHSTCTL);
79 /* clear any lingering errors, so the transaction will run */
80 outb(inb(smbus_io_base + SMBHSTSTAT), smbus_io_base + SMBHSTSTAT);
82 /* clear the data byte...*/
83 outb(0, smbus_io_base + SMBHSTDAT0);
85 /* start the command */
86 outb((inb(smbus_io_base + SMBHSTCTL) | 0x40), smbus_io_base + SMBHSTCTL);
88 /* poll for transaction completion */
89 if (smbus_wait_until_done(smbus_io_base) < 0) {
90 return SMBUS_WAIT_UNTIL_DONE_TIMEOUT;
93 global_status_register = inb(smbus_io_base + SMBHSTSTAT);
95 /* Ignore the In Use Status... */
96 global_status_register &= ~(3 << 5);
98 /* read results of transaction */
99 byte = inb(smbus_io_base + SMBHSTDAT0);
100 if (global_status_register != (1 << 1)) {