blob: 7dd40db146d0994683c0bca181e329adb5cf2bf5 [file] [log] [blame]
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +05301/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2017 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053016#include <device/pci.h>
17#include <device/pci_def.h>
18#include <device/pci_ids.h>
Chris Chingb8dc63b2017-12-06 14:26:15 -070019#include <drivers/i2c/designware/dw_i2c.h>
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053020
Chris Chingb8dc63b2017-12-06 14:26:15 -070021uintptr_t dw_i2c_base_address(unsigned int bus)
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053022{
23 int devfn;
24 struct device *dev;
25 struct resource *res;
26
27 /* bus -> devfn */
Aaron Durbin9aee8192018-01-22 20:29:25 -070028 devfn = dw_i2c_soc_bus_to_devfn(bus);
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053029
30 if (devfn < 0)
31 return (uintptr_t)NULL;
32
33 /* devfn -> dev */
34 dev = dev_find_slot(0, devfn);
Furquan Shaikhd629e4332017-06-09 17:54:00 -070035 if (!dev || !dev->enabled)
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053036 return (uintptr_t)NULL;
37
38 /* dev -> bar0 */
39 res = find_resource(dev, PCI_BASE_ADDRESS_0);
40 if (res)
41 return res->base;
42
43 return (uintptr_t)NULL;
44}
45
Aaron Durbinb7d79cd2018-01-22 21:31:48 -070046int dw_i2c_soc_dev_to_bus(struct device *dev)
Chris Chingb8dc63b2017-12-06 14:26:15 -070047{
48 pci_devfn_t devfn = dev->path.pci.devfn;
Aaron Durbin9aee8192018-01-22 20:29:25 -070049 return dw_i2c_soc_devfn_to_bus(devfn);
Chris Chingb8dc63b2017-12-06 14:26:15 -070050}
51
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053052static struct device_operations i2c_dev_ops = {
53 .read_resources = &pci_dev_read_resources,
54 .set_resources = &pci_dev_set_resources,
55 .enable_resources = &pci_dev_enable_resources,
56 .scan_bus = &scan_smbus,
Aaron Durbinb7d79cd2018-01-22 21:31:48 -070057 .ops_i2c_bus = &dw_i2c_bus_ops,
Subrata Banik6bbc91a2017-12-07 14:55:51 +053058 .ops_pci = &pci_dev_ops_pci,
Aaron Durbinb7d79cd2018-01-22 21:31:48 -070059 .init = &dw_i2c_dev_init,
60 .acpi_fill_ssdt_generator = &dw_i2c_acpi_fill_ssdt,
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053061};
62
63static const unsigned short pci_device_ids[] = {
64 PCI_DEVICE_ID_INTEL_SPT_I2C0,
65 PCI_DEVICE_ID_INTEL_SPT_I2C1,
66 PCI_DEVICE_ID_INTEL_SPT_I2C2,
67 PCI_DEVICE_ID_INTEL_SPT_I2C3,
68 PCI_DEVICE_ID_INTEL_SPT_I2C4,
69 PCI_DEVICE_ID_INTEL_SPT_I2C5,
V Sowmyaacc2a482018-01-23 15:27:23 +053070 PCI_DEVICE_ID_INTEL_KBP_H_I2C0,
71 PCI_DEVICE_ID_INTEL_KBP_H_I2C1,
72 PCI_DEVICE_ID_INTEL_KBP_H_I2C2,
73 PCI_DEVICE_ID_INTEL_KBP_H_I2C3,
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053074 PCI_DEVICE_ID_INTEL_APL_I2C0,
75 PCI_DEVICE_ID_INTEL_APL_I2C1,
76 PCI_DEVICE_ID_INTEL_APL_I2C2,
77 PCI_DEVICE_ID_INTEL_APL_I2C3,
78 PCI_DEVICE_ID_INTEL_APL_I2C4,
79 PCI_DEVICE_ID_INTEL_APL_I2C5,
80 PCI_DEVICE_ID_INTEL_APL_I2C6,
81 PCI_DEVICE_ID_INTEL_APL_I2C7,
Lijian Zhaobbedef92017-07-29 16:38:38 -070082 PCI_DEVICE_ID_INTEL_CNL_I2C0,
83 PCI_DEVICE_ID_INTEL_CNL_I2C1,
84 PCI_DEVICE_ID_INTEL_CNL_I2C2,
85 PCI_DEVICE_ID_INTEL_CNL_I2C3,
86 PCI_DEVICE_ID_INTEL_CNL_I2C4,
87 PCI_DEVICE_ID_INTEL_CNL_I2C5,
Ravi Sarawadi3038e9b2017-05-18 16:00:35 -070088 PCI_DEVICE_ID_INTEL_GLK_I2C0,
89 PCI_DEVICE_ID_INTEL_GLK_I2C1,
90 PCI_DEVICE_ID_INTEL_GLK_I2C2,
91 PCI_DEVICE_ID_INTEL_GLK_I2C3,
92 PCI_DEVICE_ID_INTEL_GLK_I2C4,
93 PCI_DEVICE_ID_INTEL_GLK_I2C5,
94 PCI_DEVICE_ID_INTEL_GLK_I2C6,
95 PCI_DEVICE_ID_INTEL_GLK_I2C7,
96 0,
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053097};
98
99static const struct pci_driver pch_i2c __pci_driver = {
100 .ops = &i2c_dev_ops,
101 .vendor = PCI_VENDOR_ID_INTEL,
102 .devices = pci_device_ids,
103};