Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 1 | /* |
| 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 Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 16 | #include <device/pci.h> |
| 17 | #include <device/pci_def.h> |
| 18 | #include <device/pci_ids.h> |
Chris Ching | b8dc63b | 2017-12-06 14:26:15 -0700 | [diff] [blame] | 19 | #include <drivers/i2c/designware/dw_i2c.h> |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 20 | |
Chris Ching | b8dc63b | 2017-12-06 14:26:15 -0700 | [diff] [blame] | 21 | uintptr_t dw_i2c_base_address(unsigned int bus) |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 22 | { |
| 23 | int devfn; |
| 24 | struct device *dev; |
| 25 | struct resource *res; |
| 26 | |
| 27 | /* bus -> devfn */ |
Aaron Durbin | 9aee819 | 2018-01-22 20:29:25 -0700 | [diff] [blame] | 28 | devfn = dw_i2c_soc_bus_to_devfn(bus); |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 29 | |
| 30 | if (devfn < 0) |
| 31 | return (uintptr_t)NULL; |
| 32 | |
| 33 | /* devfn -> dev */ |
| 34 | dev = dev_find_slot(0, devfn); |
Furquan Shaikh | d629e433 | 2017-06-09 17:54:00 -0700 | [diff] [blame] | 35 | if (!dev || !dev->enabled) |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 36 | 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 Durbin | b7d79cd | 2018-01-22 21:31:48 -0700 | [diff] [blame] | 46 | int dw_i2c_soc_dev_to_bus(struct device *dev) |
Chris Ching | b8dc63b | 2017-12-06 14:26:15 -0700 | [diff] [blame] | 47 | { |
| 48 | pci_devfn_t devfn = dev->path.pci.devfn; |
Aaron Durbin | 9aee819 | 2018-01-22 20:29:25 -0700 | [diff] [blame] | 49 | return dw_i2c_soc_devfn_to_bus(devfn); |
Chris Ching | b8dc63b | 2017-12-06 14:26:15 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 52 | static 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 Durbin | b7d79cd | 2018-01-22 21:31:48 -0700 | [diff] [blame] | 57 | .ops_i2c_bus = &dw_i2c_bus_ops, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 58 | .ops_pci = &pci_dev_ops_pci, |
Aaron Durbin | b7d79cd | 2018-01-22 21:31:48 -0700 | [diff] [blame] | 59 | .init = &dw_i2c_dev_init, |
| 60 | .acpi_fill_ssdt_generator = &dw_i2c_acpi_fill_ssdt, |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static 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 Sowmya | acc2a48 | 2018-01-23 15:27:23 +0530 | [diff] [blame] | 70 | 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 Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 74 | 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 Zhao | bbedef9 | 2017-07-29 16:38:38 -0700 | [diff] [blame] | 82 | 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 Sarawadi | 3038e9b | 2017-05-18 16:00:35 -0700 | [diff] [blame] | 88 | 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 Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static 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 | }; |