blob: b251596667c310d2bf5cf5efbbad89d066ec25a5 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer8e073822012-04-04 00:07:22 +02002
Stefan Reinauer8e073822012-04-04 00:07:22 +02003#include <device/device.h>
4#include <device/path.h>
5#include <device/smbus.h>
6#include <device/pci.h>
Elyes HAOUASa4dd33c2020-08-11 09:39:43 +02007#include <device/pci_def.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +02008#include <device/pci_ids.h>
9#include <device/pci_ops.h>
Kyösti Mälkki1cae4542020-01-06 12:31:34 +020010#include <device/smbus_host.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020011#include "pch.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020012
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020013static void pch_smbus_init(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020014{
15 struct resource *res;
16 u16 reg16;
17
18 /* Enable clock gating */
Angel Ponsc803f652020-06-07 22:09:01 +020019 /* FIXME: Using 32-bit ops with a 16-bit variable is a bug! These should be 16-bit! */
Stefan Reinauer8e073822012-04-04 00:07:22 +020020 reg16 = pci_read_config32(dev, 0x80);
21 reg16 &= ~((1 << 8)|(1 << 10)|(1 << 12)|(1 << 14));
22 pci_write_config32(dev, 0x80, reg16);
23
24 /* Set Receive Slave Address */
25 res = find_resource(dev, PCI_BASE_ADDRESS_4);
26 if (res)
Kyösti Mälkki73451fd2020-01-06 19:00:31 +020027 smbus_set_slave_addr(res->base, SMBUS_SLAVE_ADDR);
Stefan Reinauer8e073822012-04-04 00:07:22 +020028}
29
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020030static int lsmbus_read_byte(struct device *dev, u8 address)
Stefan Reinauer8e073822012-04-04 00:07:22 +020031{
32 u16 device;
33 struct resource *res;
34 struct bus *pbus;
35
36 device = dev->path.i2c.device;
37 pbus = get_pbus_smbus(dev);
Elyes HAOUASa4dd33c2020-08-11 09:39:43 +020038 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Stefan Reinauer8e073822012-04-04 00:07:22 +020039
40 return do_smbus_read_byte(res->base, device, address);
41}
42
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020043static int lsmbus_write_byte(struct device *dev, u8 address, u8 val)
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010044{
45 u16 device;
46 struct resource *res;
47 struct bus *pbus;
48
49 device = dev->path.i2c.device;
50 pbus = get_pbus_smbus(dev);
Elyes HAOUASa4dd33c2020-08-11 09:39:43 +020051 res = find_resource(pbus->dev, PCI_BASE_ADDRESS_4);
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010052
53 return do_smbus_write_byte(res->base, device, address, val);
54}
55
Stefan Reinauer8e073822012-04-04 00:07:22 +020056static struct smbus_bus_operations lops_smbus_bus = {
57 .read_byte = lsmbus_read_byte,
Vladimir Serbinenkoe57718f2014-01-27 23:48:27 +010058 .write_byte = lsmbus_write_byte,
Stefan Reinauer8e073822012-04-04 00:07:22 +020059};
60
Elyes HAOUAS4aec3402018-05-25 08:29:27 +020061static void smbus_read_resources(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +020062{
63 struct resource *res = new_resource(dev, PCI_BASE_ADDRESS_4);
Angel Ponsb21bffa2020-07-03 01:02:28 +020064 res->base = CONFIG_FIXED_SMBUS_IO_BASE;
Stefan Reinauer8e073822012-04-04 00:07:22 +020065 res->size = 32;
66 res->limit = res->base + res->size - 1;
67 res->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_RESERVE |
68 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
69
70 /* Also add MMIO resource */
71 res = pci_get_resource(dev, PCI_BASE_ADDRESS_0);
72}
73
Aaron Durbinaa090cb2017-09-13 16:01:52 -060074static const char *smbus_acpi_name(const struct device *dev)
Patrick Rudolph604f6982017-06-07 09:46:52 +020075{
76 return "SBUS";
77}
78
Stefan Reinauer8e073822012-04-04 00:07:22 +020079static struct device_operations smbus_ops = {
80 .read_resources = smbus_read_resources,
81 .set_resources = pci_dev_set_resources,
82 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020083 .scan_bus = scan_smbus,
Stefan Reinauer8e073822012-04-04 00:07:22 +020084 .init = pch_smbus_init,
85 .ops_smbus_bus = &lops_smbus_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +020086 .ops_pci = &pci_dev_ops_pci,
Patrick Rudolph604f6982017-06-07 09:46:52 +020087 .acpi_name = smbus_acpi_name,
Stefan Reinauer8e073822012-04-04 00:07:22 +020088};
89
Stefan Reinauer9a380ab2012-06-22 13:16:11 -070090static const unsigned short pci_device_ids[] = { 0x1c22, 0x1e22, 0 };
Stefan Reinauer8e073822012-04-04 00:07:22 +020091
Stefan Reinauer9a380ab2012-06-22 13:16:11 -070092static const struct pci_driver pch_smbus __pci_driver = {
93 .ops = &smbus_ops,
94 .vendor = PCI_VENDOR_ID_INTEL,
95 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +020096};