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)
17 static int smbus_wait_until_ready(unsigned smbus_io_base)
19 unsigned loops = SMBUS_TIMEOUT;
25 byte = inb(smbus_io_base + SMBHSTSTAT);
30 static int smbus_wait_until_done(unsigned smbus_io_base)
32 unsigned loops = SMBUS_TIMEOUT;
38 byte = inb(smbus_io_base + SMBHSTSTAT);
39 } while((byte & 1) || (byte & ~((1<<6)|(1<<0))) == 0);
43 static inline int smbus_wait_until_blk_done(unsigned smbus_io_base)
45 unsigned loops = SMBUS_TIMEOUT;
51 byte = inb(smbus_io_base + SMBHSTSTAT);
52 } while((byte&(1<<7)) == 0);
56 static int do_smbus_read_byte(unsigned smbus_io_base, unsigned device, unsigned address)
58 unsigned char global_status_register;
61 if (smbus_wait_until_ready(smbus_io_base) < 0) {
62 return SMBUS_WAIT_UNTIL_READY_TIMEOUT;
64 /* setup transaction */
65 /* disable interrupts */
66 outb(inb(smbus_io_base + SMBHSTCTL) & (~1), smbus_io_base + SMBHSTCTL);
67 /* set the device I'm talking too */
68 outb(((device & 0x7f) << 1) | 1, smbus_io_base + SMBXMITADD);
69 /* set the command/address... */
70 outb(address & 0xFF, smbus_io_base + SMBHSTCMD);
71 /* set up for a byte data read */
72 outb((inb(smbus_io_base + SMBHSTCTL) & 0xE3) | (0x2 << 2), smbus_io_base + SMBHSTCTL);
73 /* clear any lingering errors, so the transaction will run */
74 outb(inb(smbus_io_base + SMBHSTSTAT), smbus_io_base + SMBHSTSTAT);
76 /* clear the data byte...*/
77 outb(0, smbus_io_base + SMBHSTDAT0);
79 /* start the command */
80 outb((inb(smbus_io_base + SMBHSTCTL) | 0x40), smbus_io_base + SMBHSTCTL);
82 /* poll for transaction completion */
83 if (smbus_wait_until_done(smbus_io_base) < 0) {
84 return SMBUS_WAIT_UNTIL_DONE_TIMEOUT;
87 global_status_register = inb(smbus_io_base + SMBHSTSTAT);
89 /* Ignore the In Use Status... */
90 global_status_register &= ~(3 << 5);
92 /* read results of transaction */
93 byte = inb(smbus_io_base + SMBHSTDAT0);
94 if (global_status_register != (1 << 1)) {