| 1 |
|
| 2 |
|
| 3 |
#include <device/device.h> |
| 4 |
#include <device/smbus.h> |
| 5 |
#include <device/pci.h> |
| 6 |
#include <device/pci_ids.h> |
| 7 |
#include <device/smbus_host.h> |
| 8 |
#include <southbridge/intel/common/smbus_ops.h> |
| 9 |
|
| 10 |
static int lsmbus_read_byte(struct device *dev, u8 address) |
| 11 |
{ |
| 12 |
u16 device; |
| 13 |
struct resource *res; |
| 14 |
struct bus *pbus; |
| 15 |
|
| 16 |
device = dev->path.i2c.device; |
| 17 |
pbus = get_pbus_smbus(dev); |
| 18 |
res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 19 |
|
| 20 |
return do_smbus_read_byte(res->base, device, address); |
| 21 |
} |
| 22 |
|
| 23 |
static int lsmbus_write_byte(struct device *dev, u8 address, u8 data) |
| 24 |
{ |
| 25 |
u16 device; |
| 26 |
struct resource *res; |
| 27 |
struct bus *pbus; |
| 28 |
|
| 29 |
device = dev->path.i2c.device; |
| 30 |
pbus = get_pbus_smbus(dev); |
| 31 |
res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 32 |
return do_smbus_write_byte(res->base, device, address, data); |
| 33 |
} |
| 34 |
|
| 35 |
static int lsmbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buf) |
| 36 |
{ |
| 37 |
u16 device; |
| 38 |
struct resource *res; |
| 39 |
struct bus *pbus; |
| 40 |
|
| 41 |
device = dev->path.i2c.device; |
| 42 |
pbus = get_pbus_smbus(dev); |
| 43 |
res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 44 |
return do_smbus_block_write(res->base, device, cmd, bytes, buf); |
| 45 |
} |
| 46 |
|
| 47 |
static int lsmbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buf) |
| 48 |
{ |
| 49 |
u16 device; |
| 50 |
struct resource *res; |
| 51 |
struct bus *pbus; |
| 52 |
|
| 53 |
device = dev->path.i2c.device; |
| 54 |
pbus = get_pbus_smbus(dev); |
| 55 |
res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4); |
| 56 |
return do_smbus_block_read(res->base, device, cmd, bytes, buf); |
| 57 |
} |
| 58 |
|
| 59 |
struct smbus_bus_operations lops_smbus_bus = { |
| 60 |
.read_byte = lsmbus_read_byte, |
| 61 |
.write_byte = lsmbus_write_byte, |
| 62 |
.block_read = lsmbus_block_read, |
| 63 |
.block_write = lsmbus_block_write, |
| 64 |
}; |
| 65 |
|
| 66 |
void smbus_read_resources(struct device *dev) |
| 67 |
{ |
| 68 |
pci_dev_read_resources(dev); |
| 69 |
|
| 70 |
struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4); |
| 71 |
res->base = CONFIG_FIXED_SMBUS_IO_BASE; |
| 72 |
res->size = 32; |
| 73 |
res->limit = res->base + res->size - 1; |
| 74 |
res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE | |
| 75 |
IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 76 |
} |