Example #1
0
def smbus_init():
    # Accessing ports < 0x400 needs special privileges    
    ioport.iopl(3)
    # Try to identify whether there's "something" at 0x400 with the status register
    ioport.outb(0xff, SMBHSTSTS)
    if ioport.inb(SMBHSTSTS) & 0x01:
        return False
    return True
Example #2
0
def smbus_write_block(addr, command, data):
    if addr_validate(addr) == False:
        return False
    if cmd_validate(command) == False:
        return False
    if len(data) > 32:
        return False
    # Clear status register
    ioport.outb(0xff, SMBHSTSTS)
    # Set up command register, slave address register
    addr = (addr << 1) | 0x00       # We're writing data
    ioport.outb(addr, SMBHSTADD)
    ioport.outb(command, SMBHSTCMD)
    # Use block buffer
    ioport.outb(0x02, SMBAUXCTL)
    # Set Data0 to length and Data1 to sane value
    ioport.outb(len(data), SMBHSTDAT0)
    ioport.outb(0, SMBHSTDAT1)
    # Fill block buffer with data
    ioport.inb(SMBHSTCNT)
    for b in data:
        ioport.outb(b, SMBBLKDAT)
    # Send block read command and start reading immediately
    cmd = I801_BLOCK_DATA | I801_START
    ioport.outb(cmd, SMBHSTCNT)
    # Wait for the write to finish
    while (not (ioport.inb(SMBHSTSTS) & 0x02) and not (ioport.inb(SMBHSTSTS) & 0x1c)): pass
    # Check whether the operation was successful
    status = ioport.inb(SMBHSTSTS)
    if (status & SMBHSTERRMASK):
        return False
    return True
Example #3
0
def smbus_read_block(addr, command):
    if addr_validate(addr) == False:
        return False
    if cmd_validate(command) == False:
        return False   
    # Clear status register
    ioport.outb(0xff, SMBHSTSTS)
    # Set up command register, slave address register
    addr = (addr << 1) | 0x01       # We're reading data
    ioport.outb(addr, SMBHSTADD)
    ioport.outb(command, SMBHSTCMD)
    # Use block buffer
    ioport.outb(0x02, SMBAUXCTL)
    # Set Data0 and Data1 to sane values
    ioport.outb(32, SMBHSTDAT0) # Read 32 bytes maximum
    ioport.outb(0, SMBHSTDAT1)
    # Send block read command and start reading immediately
    cmd = I801_BLOCK_DATA | I801_START
    ioport.outb(cmd, SMBHSTCNT)
    # Wait for the read to finish
    while (not (ioport.inb(SMBHSTSTS) & 0x02) and not (ioport.inb(SMBHSTSTS) & 0x1c)): pass
    # Check whether the operation was successful
    status = ioport.inb(SMBHSTSTS)
    if (status & SMBHSTERRMASK):
        return False
    # Retrieve the data
    len = ioport.inb(SMBHSTDAT0)
    ioport.inb(SMBHSTCNT)
    data = []
    for i in xrange(len):
        data.append(ioport.inb(SMBBLKDAT))
    return data
Example #4
0
def ec_write(adr, data):
    ioport.outb(adr >> 8, EC_BASE+1)
    ioport.outb(adr & 0xff, EC_BASE+2)
    ioport.outb(data, EC_BASE+3)
Example #5
0
def ec_read(adr):
    ioport.outb(adr >> 8, EC_BASE+1)
    ioport.outb(adr & 0xff, EC_BASE+2)
    return ioport.inb(EC_BASE+3)