Andy Shevchenko | 15c566f | 2018-08-10 13:26:49 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Synopsys DesignWare I2C adapter driver (master only). |
| 4 | * |
| 5 | * Based on the TI DAVINCI I2C adapter driver. |
| 6 | * |
| 7 | * Copyright (C) 2006 Texas Instruments. |
| 8 | * Copyright (C) 2007 MontaVista Software Inc. |
| 9 | * Copyright (C) 2009 Provigent Ltd. |
Andy Shevchenko | 45bc35e | 2016-06-15 18:05:07 +0300 | [diff] [blame] | 10 | * Copyright (C) 2011, 2015, 2016 Intel Corporation. |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 11 | */ |
Andy Shevchenko | 45bc35e | 2016-06-15 18:05:07 +0300 | [diff] [blame] | 12 | #include <linux/acpi.h> |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 13 | #include <linux/delay.h> |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 14 | #include <linux/err.h> |
Andy Shevchenko | 45bc35e | 2016-06-15 18:05:07 +0300 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | #include <linux/i2c.h> |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/io.h> |
Andy Shevchenko | 45bc35e | 2016-06-15 18:05:07 +0300 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 21 | #include <linux/pci.h> |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 22 | #include <linux/pm_runtime.h> |
Andy Shevchenko | 45bc35e | 2016-06-15 18:05:07 +0300 | [diff] [blame] | 23 | #include <linux/sched.h> |
| 24 | #include <linux/slab.h> |
| 25 | |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 26 | #include "i2c-designware-core.h" |
| 27 | |
| 28 | #define DRIVER_NAME "i2c-designware-pci" |
| 29 | |
| 30 | enum dw_pci_ctl_id_t { |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 31 | medfield, |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 32 | merrifield, |
Mika Westerberg | 089c729 | 2014-02-19 16:10:29 +0200 | [diff] [blame] | 33 | baytrail, |
Hans de Goede | fd476fa | 2017-02-10 11:27:58 +0100 | [diff] [blame] | 34 | cherrytrail, |
Mika Westerberg | 157a801 | 2014-05-15 17:37:24 +0300 | [diff] [blame] | 35 | haswell, |
Jarkko Nikula | 70fb95e | 2019-08-15 17:29:44 +0300 | [diff] [blame] | 36 | elkhartlake, |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Chew, Chiau Ee | 8efd1e9 | 2014-03-11 19:33:45 +0800 | [diff] [blame] | 39 | struct dw_scl_sda_cfg { |
| 40 | u32 ss_hcnt; |
| 41 | u32 fs_hcnt; |
| 42 | u32 ss_lcnt; |
| 43 | u32 fs_lcnt; |
| 44 | u32 sda_hold; |
| 45 | }; |
| 46 | |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 47 | struct dw_pci_controller { |
| 48 | u32 bus_num; |
Hans de Goede | fd476fa | 2017-02-10 11:27:58 +0100 | [diff] [blame] | 49 | u32 flags; |
Chew, Chiau Ee | 8efd1e9 | 2014-03-11 19:33:45 +0800 | [diff] [blame] | 50 | struct dw_scl_sda_cfg *scl_sda_cfg; |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 51 | int (*setup)(struct pci_dev *pdev, struct dw_pci_controller *c); |
Andy Shevchenko | ab0ef8b | 2020-05-19 15:50:37 +0300 | [diff] [blame] | 52 | u32 (*get_clk_rate_khz)(struct dw_i2c_dev *dev); |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 55 | /* Merrifield HCNT/LCNT/SDA hold time */ |
| 56 | static struct dw_scl_sda_cfg mrfld_config = { |
| 57 | .ss_hcnt = 0x2f8, |
| 58 | .fs_hcnt = 0x87, |
| 59 | .ss_lcnt = 0x37b, |
| 60 | .fs_lcnt = 0x10a, |
| 61 | }; |
| 62 | |
Chew, Chiau Ee | 8efd1e9 | 2014-03-11 19:33:45 +0800 | [diff] [blame] | 63 | /* BayTrail HCNT/LCNT/SDA hold time */ |
| 64 | static struct dw_scl_sda_cfg byt_config = { |
| 65 | .ss_hcnt = 0x200, |
| 66 | .fs_hcnt = 0x55, |
| 67 | .ss_lcnt = 0x200, |
| 68 | .fs_lcnt = 0x99, |
| 69 | .sda_hold = 0x6, |
| 70 | }; |
| 71 | |
Mika Westerberg | 157a801 | 2014-05-15 17:37:24 +0300 | [diff] [blame] | 72 | /* Haswell HCNT/LCNT/SDA hold time */ |
| 73 | static struct dw_scl_sda_cfg hsw_config = { |
| 74 | .ss_hcnt = 0x01b0, |
| 75 | .fs_hcnt = 0x48, |
| 76 | .ss_lcnt = 0x01fb, |
| 77 | .fs_lcnt = 0xa0, |
| 78 | .sda_hold = 0x9, |
| 79 | }; |
| 80 | |
Andy Shevchenko | ab0ef8b | 2020-05-19 15:50:37 +0300 | [diff] [blame] | 81 | static u32 mfld_get_clk_rate_khz(struct dw_i2c_dev *dev) |
| 82 | { |
| 83 | return 25000; |
| 84 | } |
| 85 | |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 86 | static int mfld_setup(struct pci_dev *pdev, struct dw_pci_controller *c) |
| 87 | { |
Andy Shevchenko | 42ab001 | 2020-04-25 16:44:46 +0300 | [diff] [blame] | 88 | struct dw_i2c_dev *dev = dev_get_drvdata(&pdev->dev); |
| 89 | |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 90 | switch (pdev->device) { |
| 91 | case 0x0817: |
Andy Shevchenko | 42ab001 | 2020-04-25 16:44:46 +0300 | [diff] [blame] | 92 | dev->timings.bus_freq_hz = I2C_MAX_STANDARD_MODE_FREQ; |
Gustavo A. R. Silva | 4db7e17 | 2020-07-21 18:05:10 -0500 | [diff] [blame] | 93 | fallthrough; |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 94 | case 0x0818: |
| 95 | case 0x0819: |
| 96 | c->bus_num = pdev->device - 0x817 + 3; |
| 97 | return 0; |
| 98 | case 0x082C: |
| 99 | case 0x082D: |
| 100 | case 0x082E: |
| 101 | c->bus_num = pdev->device - 0x82C + 0; |
| 102 | return 0; |
| 103 | } |
| 104 | return -ENODEV; |
| 105 | } |
| 106 | |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 107 | static int mrfld_setup(struct pci_dev *pdev, struct dw_pci_controller *c) |
| 108 | { |
| 109 | /* |
Andy Shevchenko | 24d3fdc | 2020-03-19 17:30:12 +0200 | [diff] [blame] | 110 | * On Intel Merrifield the user visible i2c buses are enumerated |
Andy Shevchenko | ec2790e | 2016-06-20 11:58:09 +0300 | [diff] [blame] | 111 | * [1..7]. So, we add 1 to shift the default range. Besides that the |
| 112 | * first PCI slot provides 4 functions, that's why we have to add 0 to |
| 113 | * the first slot and 4 to the next one. |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 114 | */ |
| 115 | switch (PCI_SLOT(pdev->devfn)) { |
| 116 | case 8: |
| 117 | c->bus_num = PCI_FUNC(pdev->devfn) + 0 + 1; |
| 118 | return 0; |
| 119 | case 9: |
| 120 | c->bus_num = PCI_FUNC(pdev->devfn) + 4 + 1; |
| 121 | return 0; |
| 122 | } |
| 123 | return -ENODEV; |
| 124 | } |
| 125 | |
Andy Shevchenko | ab0ef8b | 2020-05-19 15:50:37 +0300 | [diff] [blame] | 126 | static u32 ehl_get_clk_rate_khz(struct dw_i2c_dev *dev) |
| 127 | { |
| 128 | return 100000; |
| 129 | } |
| 130 | |
Andy Shevchenko | a93ac57 | 2015-02-06 13:47:02 +0200 | [diff] [blame] | 131 | static struct dw_pci_controller dw_pci_controllers[] = { |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 132 | [medfield] = { |
| 133 | .bus_num = -1, |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 134 | .setup = mfld_setup, |
Andy Shevchenko | ab0ef8b | 2020-05-19 15:50:37 +0300 | [diff] [blame] | 135 | .get_clk_rate_khz = mfld_get_clk_rate_khz, |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 136 | }, |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 137 | [merrifield] = { |
| 138 | .bus_num = -1, |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 139 | .scl_sda_cfg = &mrfld_config, |
| 140 | .setup = mrfld_setup, |
| 141 | }, |
Mika Westerberg | 089c729 | 2014-02-19 16:10:29 +0200 | [diff] [blame] | 142 | [baytrail] = { |
| 143 | .bus_num = -1, |
Chew, Chiau Ee | 8efd1e9 | 2014-03-11 19:33:45 +0800 | [diff] [blame] | 144 | .scl_sda_cfg = &byt_config, |
Mika Westerberg | 089c729 | 2014-02-19 16:10:29 +0200 | [diff] [blame] | 145 | }, |
Mika Westerberg | 157a801 | 2014-05-15 17:37:24 +0300 | [diff] [blame] | 146 | [haswell] = { |
| 147 | .bus_num = -1, |
Mika Westerberg | 157a801 | 2014-05-15 17:37:24 +0300 | [diff] [blame] | 148 | .scl_sda_cfg = &hsw_config, |
| 149 | }, |
Hans de Goede | fd476fa | 2017-02-10 11:27:58 +0100 | [diff] [blame] | 150 | [cherrytrail] = { |
| 151 | .bus_num = -1, |
Hans de Goede | fd476fa | 2017-02-10 11:27:58 +0100 | [diff] [blame] | 152 | .scl_sda_cfg = &byt_config, |
| 153 | }, |
Jarkko Nikula | 70fb95e | 2019-08-15 17:29:44 +0300 | [diff] [blame] | 154 | [elkhartlake] = { |
| 155 | .bus_num = -1, |
Andy Shevchenko | ab0ef8b | 2020-05-19 15:50:37 +0300 | [diff] [blame] | 156 | .get_clk_rate_khz = ehl_get_clk_rate_khz, |
Jarkko Nikula | 70fb95e | 2019-08-15 17:29:44 +0300 | [diff] [blame] | 157 | }, |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 158 | }; |
Alan Cox | 0409516 | 2014-07-23 13:06:57 +0100 | [diff] [blame] | 159 | |
Mika Westerberg | be58eda | 2014-02-04 14:37:07 +0200 | [diff] [blame] | 160 | #ifdef CONFIG_PM |
Octavian Purdila | 52c2843 | 2011-10-06 11:26:37 -0700 | [diff] [blame] | 161 | static int i2c_dw_pci_suspend(struct device *dev) |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 162 | { |
Chuhong Yuan | 7735eee | 2019-07-23 19:11:10 +0800 | [diff] [blame] | 163 | struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 164 | |
Hans de Goede | 2751541 | 2019-02-22 14:08:40 +0100 | [diff] [blame] | 165 | i_dev->suspended = true; |
Luis Oliveira | 9031235 | 2017-06-14 11:43:23 +0100 | [diff] [blame] | 166 | i_dev->disable(i_dev); |
| 167 | |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
Octavian Purdila | 52c2843 | 2011-10-06 11:26:37 -0700 | [diff] [blame] | 171 | static int i2c_dw_pci_resume(struct device *dev) |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 172 | { |
Chuhong Yuan | 7735eee | 2019-07-23 19:11:10 +0800 | [diff] [blame] | 173 | struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); |
Hans de Goede | 2751541 | 2019-02-22 14:08:40 +0100 | [diff] [blame] | 174 | int ret; |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 175 | |
Hans de Goede | 2751541 | 2019-02-22 14:08:40 +0100 | [diff] [blame] | 176 | ret = i_dev->init(i_dev); |
| 177 | i_dev->suspended = false; |
| 178 | |
| 179 | return ret; |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 180 | } |
Mika Westerberg | be58eda | 2014-02-04 14:37:07 +0200 | [diff] [blame] | 181 | #endif |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 182 | |
Mika Westerberg | be58eda | 2014-02-04 14:37:07 +0200 | [diff] [blame] | 183 | static UNIVERSAL_DEV_PM_OPS(i2c_dw_pm_ops, i2c_dw_pci_suspend, |
| 184 | i2c_dw_pci_resume, NULL); |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 185 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 186 | static int i2c_dw_pci_probe(struct pci_dev *pdev, |
Andy Shevchenko | ca0c1ff | 2013-04-10 00:36:37 +0000 | [diff] [blame] | 187 | const struct pci_device_id *id) |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 188 | { |
| 189 | struct dw_i2c_dev *dev; |
| 190 | struct i2c_adapter *adap; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 191 | int r; |
Andy Shevchenko | 45bc35e | 2016-06-15 18:05:07 +0300 | [diff] [blame] | 192 | struct dw_pci_controller *controller; |
Chew, Chiau Ee | 8efd1e9 | 2014-03-11 19:33:45 +0800 | [diff] [blame] | 193 | struct dw_scl_sda_cfg *cfg; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 194 | |
| 195 | if (id->driver_data >= ARRAY_SIZE(dw_pci_controllers)) { |
Andy Shevchenko | ca0c1ff | 2013-04-10 00:36:37 +0000 | [diff] [blame] | 196 | dev_err(&pdev->dev, "%s: invalid driver data %ld\n", __func__, |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 197 | id->driver_data); |
| 198 | return -EINVAL; |
| 199 | } |
| 200 | |
| 201 | controller = &dw_pci_controllers[id->driver_data]; |
| 202 | |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 203 | r = pcim_enable_device(pdev); |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 204 | if (r) { |
| 205 | dev_err(&pdev->dev, "Failed to enable I2C PCI device (%d)\n", |
| 206 | r); |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 207 | return r; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 210 | pci_set_master(pdev); |
| 211 | |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 212 | r = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev)); |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 213 | if (r) { |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 214 | dev_err(&pdev->dev, "I/O memory remapping failed\n"); |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 215 | return r; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 218 | dev = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL); |
| 219 | if (!dev) |
| 220 | return -ENOMEM; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 221 | |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 222 | r = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); |
| 223 | if (r < 0) |
| 224 | return r; |
| 225 | |
Andy Shevchenko | ab0ef8b | 2020-05-19 15:50:37 +0300 | [diff] [blame] | 226 | dev->get_clk_rate_khz = controller->get_clk_rate_khz; |
Andy Shevchenko | 42ab001 | 2020-04-25 16:44:46 +0300 | [diff] [blame] | 227 | dev->timings.bus_freq_hz = I2C_MAX_FAST_MODE_FREQ; |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 228 | dev->base = pcim_iomap_table(pdev)[0]; |
| 229 | dev->dev = &pdev->dev; |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 230 | dev->irq = pci_irq_vector(pdev, 0); |
Hans de Goede | fd476fa | 2017-02-10 11:27:58 +0100 | [diff] [blame] | 231 | dev->flags |= controller->flags; |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 232 | |
Andy Shevchenko | 42ab001 | 2020-04-25 16:44:46 +0300 | [diff] [blame] | 233 | pci_set_drvdata(pdev, dev); |
| 234 | |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 235 | if (controller->setup) { |
| 236 | r = controller->setup(pdev, controller); |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 237 | if (r) { |
| 238 | pci_free_irq_vectors(pdev); |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 239 | return r; |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 240 | } |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 241 | } |
| 242 | |
Andy Shevchenko | 852f719 | 2020-06-23 12:15:01 +0300 | [diff] [blame] | 243 | i2c_dw_adjust_bus_speed(dev); |
Andy Shevchenko | 64d0a07 | 2020-05-19 15:50:42 +0300 | [diff] [blame] | 244 | |
| 245 | if (has_acpi_companion(&pdev->dev)) |
| 246 | i2c_dw_acpi_configure(&pdev->dev); |
| 247 | |
| 248 | r = i2c_dw_validate_speed(dev); |
| 249 | if (r) { |
| 250 | pci_free_irq_vectors(pdev); |
| 251 | return r; |
| 252 | } |
| 253 | |
Andy Shevchenko | 7943f1d | 2020-04-25 16:44:48 +0300 | [diff] [blame] | 254 | i2c_dw_configure(dev); |
Chew, Chiau Ee | ceccd29 | 2014-03-07 22:12:50 +0800 | [diff] [blame] | 255 | |
Chew, Chiau Ee | 8efd1e9 | 2014-03-11 19:33:45 +0800 | [diff] [blame] | 256 | if (controller->scl_sda_cfg) { |
| 257 | cfg = controller->scl_sda_cfg; |
| 258 | dev->ss_hcnt = cfg->ss_hcnt; |
| 259 | dev->fs_hcnt = cfg->fs_hcnt; |
| 260 | dev->ss_lcnt = cfg->ss_lcnt; |
| 261 | dev->fs_lcnt = cfg->fs_lcnt; |
| 262 | dev->sda_hold_time = cfg->sda_hold; |
| 263 | } |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 264 | |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 265 | adap = &dev->adapter; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 266 | adap->owner = THIS_MODULE; |
| 267 | adap->class = 0; |
Dustin Byford | 8eb5c87 | 2015-10-23 12:27:07 -0700 | [diff] [blame] | 268 | ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev)); |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 269 | adap->nr = controller->bus_num; |
Mika Westerberg | 089c729 | 2014-02-19 16:10:29 +0200 | [diff] [blame] | 270 | |
Andy Shevchenko | 7943f1d | 2020-04-25 16:44:48 +0300 | [diff] [blame] | 271 | r = i2c_dw_probe(dev); |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 272 | if (r) { |
| 273 | pci_free_irq_vectors(pdev); |
Andy Shevchenko | 76cf3fc | 2013-04-10 00:36:38 +0000 | [diff] [blame] | 274 | return r; |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 275 | } |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 276 | |
Mika Westerberg | 4345233 | 2013-04-10 00:36:42 +0000 | [diff] [blame] | 277 | pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); |
| 278 | pm_runtime_use_autosuspend(&pdev->dev); |
Mika Westerberg | be58eda | 2014-02-04 14:37:07 +0200 | [diff] [blame] | 279 | pm_runtime_put_autosuspend(&pdev->dev); |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 280 | pm_runtime_allow(&pdev->dev); |
| 281 | |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 282 | return 0; |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 285 | static void i2c_dw_pci_remove(struct pci_dev *pdev) |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 286 | { |
| 287 | struct dw_i2c_dev *dev = pci_get_drvdata(pdev); |
| 288 | |
Luis Oliveira | 9031235 | 2017-06-14 11:43:23 +0100 | [diff] [blame] | 289 | dev->disable(dev); |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 290 | pm_runtime_forbid(&pdev->dev); |
| 291 | pm_runtime_get_noresume(&pdev->dev); |
| 292 | |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 293 | i2c_del_adapter(&dev->adapter); |
Jarkko Nikula | 9be8bc4 | 2020-02-13 17:15:03 +0200 | [diff] [blame] | 294 | devm_free_irq(&pdev->dev, dev->irq, dev); |
Felipe Balbi | 21aa398 | 2019-08-15 17:29:43 +0300 | [diff] [blame] | 295 | pci_free_irq_vectors(pdev); |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* work with hotplug and coldplug */ |
| 299 | MODULE_ALIAS("i2c_designware-pci"); |
| 300 | |
Jingoo Han | 392debf | 2013-12-03 08:11:20 +0900 | [diff] [blame] | 301 | static const struct pci_device_id i2_designware_pci_ids[] = { |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 302 | /* Medfield */ |
Andy Shevchenko | ed1bf03 | 2016-06-15 18:05:05 +0300 | [diff] [blame] | 303 | { PCI_VDEVICE(INTEL, 0x0817), medfield }, |
| 304 | { PCI_VDEVICE(INTEL, 0x0818), medfield }, |
| 305 | { PCI_VDEVICE(INTEL, 0x0819), medfield }, |
| 306 | { PCI_VDEVICE(INTEL, 0x082C), medfield }, |
| 307 | { PCI_VDEVICE(INTEL, 0x082D), medfield }, |
| 308 | { PCI_VDEVICE(INTEL, 0x082E), medfield }, |
Andy Shevchenko | b20551c | 2016-06-15 18:05:06 +0300 | [diff] [blame] | 309 | /* Merrifield */ |
| 310 | { PCI_VDEVICE(INTEL, 0x1195), merrifield }, |
| 311 | { PCI_VDEVICE(INTEL, 0x1196), merrifield }, |
Mika Westerberg | 089c729 | 2014-02-19 16:10:29 +0200 | [diff] [blame] | 312 | /* Baytrail */ |
| 313 | { PCI_VDEVICE(INTEL, 0x0F41), baytrail }, |
| 314 | { PCI_VDEVICE(INTEL, 0x0F42), baytrail }, |
| 315 | { PCI_VDEVICE(INTEL, 0x0F43), baytrail }, |
| 316 | { PCI_VDEVICE(INTEL, 0x0F44), baytrail }, |
| 317 | { PCI_VDEVICE(INTEL, 0x0F45), baytrail }, |
| 318 | { PCI_VDEVICE(INTEL, 0x0F46), baytrail }, |
| 319 | { PCI_VDEVICE(INTEL, 0x0F47), baytrail }, |
Mika Westerberg | 157a801 | 2014-05-15 17:37:24 +0300 | [diff] [blame] | 320 | /* Haswell */ |
| 321 | { PCI_VDEVICE(INTEL, 0x9c61), haswell }, |
| 322 | { PCI_VDEVICE(INTEL, 0x9c62), haswell }, |
Alan Cox | 0409516 | 2014-07-23 13:06:57 +0100 | [diff] [blame] | 323 | /* Braswell / Cherrytrail */ |
Hans de Goede | fd476fa | 2017-02-10 11:27:58 +0100 | [diff] [blame] | 324 | { PCI_VDEVICE(INTEL, 0x22C1), cherrytrail }, |
| 325 | { PCI_VDEVICE(INTEL, 0x22C2), cherrytrail }, |
| 326 | { PCI_VDEVICE(INTEL, 0x22C3), cherrytrail }, |
| 327 | { PCI_VDEVICE(INTEL, 0x22C4), cherrytrail }, |
| 328 | { PCI_VDEVICE(INTEL, 0x22C5), cherrytrail }, |
| 329 | { PCI_VDEVICE(INTEL, 0x22C6), cherrytrail }, |
| 330 | { PCI_VDEVICE(INTEL, 0x22C7), cherrytrail }, |
Jarkko Nikula | 70fb95e | 2019-08-15 17:29:44 +0300 | [diff] [blame] | 331 | /* Elkhart Lake (PSE I2C) */ |
| 332 | { PCI_VDEVICE(INTEL, 0x4bb9), elkhartlake }, |
| 333 | { PCI_VDEVICE(INTEL, 0x4bba), elkhartlake }, |
| 334 | { PCI_VDEVICE(INTEL, 0x4bbb), elkhartlake }, |
| 335 | { PCI_VDEVICE(INTEL, 0x4bbc), elkhartlake }, |
| 336 | { PCI_VDEVICE(INTEL, 0x4bbd), elkhartlake }, |
| 337 | { PCI_VDEVICE(INTEL, 0x4bbe), elkhartlake }, |
| 338 | { PCI_VDEVICE(INTEL, 0x4bbf), elkhartlake }, |
| 339 | { PCI_VDEVICE(INTEL, 0x4bc0), elkhartlake }, |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 340 | { 0,} |
| 341 | }; |
| 342 | MODULE_DEVICE_TABLE(pci, i2_designware_pci_ids); |
| 343 | |
| 344 | static struct pci_driver dw_i2c_driver = { |
| 345 | .name = DRIVER_NAME, |
| 346 | .id_table = i2_designware_pci_ids, |
| 347 | .probe = i2c_dw_pci_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 348 | .remove = i2c_dw_pci_remove, |
Dirk Brandewie | 18dbdda | 2011-10-06 11:26:36 -0700 | [diff] [blame] | 349 | .driver = { |
| 350 | .pm = &i2c_dw_pm_ops, |
| 351 | }, |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 352 | }; |
| 353 | |
Axel Lin | 56f2178 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 354 | module_pci_driver(dw_i2c_driver); |
Dirk Brandewie | fe20ff5 | 2011-10-06 11:26:35 -0700 | [diff] [blame] | 355 | |
| 356 | MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); |
| 357 | MODULE_DESCRIPTION("Synopsys DesignWare PCI I2C bus adapter"); |
| 358 | MODULE_LICENSE("GPL"); |