Ejemplo n.º 1
0
int do_smbus_read_byte(u32 mmio, u8 device, u8 address)
{
	u8 byte;

	if (smbus_wait_until_ready(mmio) < 0)
		return -2;	/* not ready */

	/* set the command/address... */
	smbus_write8(mmio, SMBHSTCMD, address & 0xff);

	/* set the device I'm talking to */
	smbus_write8(mmio, SMBHSTADDR, ((device & 0x7f) << 1) | 1);

	byte = smbus_read8(mmio, SMBHSTCTRL);
	byte &= ~SMBHST_CTRL_MODE_BITS;			/* Clear [4:2] */
	byte |= SMBHST_CTRL_STRT | SMBHST_CTRL_BDT_RW;	/* set mode, start */
	smbus_write8(mmio, SMBHSTCTRL, byte);

	/* poll for transaction completion */
	if (smbus_wait_until_done(mmio) < 0)
		return -3;	/* timeout or error */

	/* read results of transaction */
	byte = smbus_read8(mmio, SMBHSTDAT0);

	return byte;
}
Ejemplo n.º 2
0
static int lsmbus_read_byte(struct device *dev, u8 address)
{
	u16 device;
	struct resource *res;
	struct bus *pbus;
	device = dev->path.i2c.device;
	pbus = get_pbus_smbus(dev);
	res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
	return smbus_read8(res->base, device, address);
}
Ejemplo n.º 3
0
static int smbus_wait_until_ready(u32 mmio)
{
	u32 loops;
	loops = SMBUS_TIMEOUT;
	do {
		u8 val;
		val = smbus_read8(mmio, SMBHSTSTAT);
		val &= SMBHST_STAT_VAL_BITS;
		if (val == 0) {	/* ready now */
			return 0;
		}
		smbus_write8(mmio, SMBHSTSTAT, val);
	} while (--loops);
	return -2;		/* time out */
}
Ejemplo n.º 4
0
static int smbus_wait_until_done(u32 mmio)
{
	u32 loops;
	loops = SMBUS_TIMEOUT;
	do {
		u8 val;

		val = smbus_read8(mmio, SMBHSTSTAT);
		val &= SMBHST_STAT_VAL_BITS;	/* mask off reserved bits */
		if (val & SMBHST_STAT_ERROR_BITS)
			return -5;	/* error */
		if (val == SMBHST_STAT_NOERROR) {
			smbus_write8(mmio, SMBHSTSTAT, val); /* clear sts */
			return 0;
		}
	} while (--loops);
	return -3;		/* timeout */
}
Ejemplo n.º 5
0
int do_smbus_send_byte(u32 mmio, u8 device, u8 val)
{
	u8 byte;

	if (smbus_wait_until_ready(mmio) < 0)
		return -2;	/* not ready */

	/* set the command... */
	smbus_write8(mmio, SMBHSTDAT0, val);

	/* set the device I'm talking to */
	smbus_write8(mmio, SMBHSTADDR, ((device & 0x7f) << 1) | 0);

	byte = smbus_read8(mmio, SMBHSTCTRL);
	byte &= ~SMBHST_CTRL_MODE_BITS;			/* Clear [4:2] */
	byte |= SMBHST_CTRL_STRT | SMBHST_CTRL_BTE_RW;	/* set mode, start */
	smbus_write8(mmio, SMBHSTCTRL, byte);

	/* poll for transaction completion */
	if (smbus_wait_until_done(mmio) < 0)
		return -3;	/* timeout or error */

	return 0;
}
Ejemplo n.º 6
0
u8 smbus_read_byte(u32 smbus_dev, u8 addr, u8 offset)
{
	return smbus_read8(SMBUS_IO_BASE, addr, offset);
}