2 * Synopsys DesignWare I2C adapter driver (master only).
4 * Based on the TI DAVINCI I2C adapter driver.
6 * Copyright (C) 2006 Texas Instruments.
7 * Copyright (C) 2007 MontaVista Software Inc.
8 * Copyright (C) 2009 Provigent Ltd.
9 * Copyright (C) 2011, 2015 Intel Corporation.
11 * ----------------------------------------------------------------------------
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 * ----------------------------------------------------------------------------
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/delay.h>
29 #include <linux/i2c.h>
30 #include <linux/errno.h>
31 #include <linux/sched.h>
32 #include <linux/err.h>
33 #include <linux/interrupt.h>
35 #include <linux/slab.h>
36 #include <linux/pci.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/acpi.h>
39 #include "i2c-designware-core.h"
41 #define DRIVER_NAME "i2c-designware-pci"
43 enum dw_pci_ctl_id_t
{
55 struct dw_scl_sda_cfg
{
63 struct dw_pci_controller
{
70 struct dw_scl_sda_cfg
*scl_sda_cfg
;
73 #define INTEL_MID_STD_CFG (DW_IC_CON_MASTER | \
74 DW_IC_CON_SLAVE_DISABLE | \
77 #define DW_DEFAULT_FUNCTIONALITY (I2C_FUNC_I2C | \
78 I2C_FUNC_SMBUS_BYTE | \
79 I2C_FUNC_SMBUS_BYTE_DATA | \
80 I2C_FUNC_SMBUS_WORD_DATA | \
81 I2C_FUNC_SMBUS_I2C_BLOCK)
83 /* BayTrail HCNT/LCNT/SDA hold time */
84 static struct dw_scl_sda_cfg byt_config
= {
92 /* Haswell HCNT/LCNT/SDA hold time */
93 static struct dw_scl_sda_cfg hsw_config
= {
101 static struct dw_pci_controller dw_pci_controllers
[] = {
104 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
111 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
118 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
125 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_STD
,
132 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
139 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
146 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
149 .functionality
= I2C_FUNC_10BIT_ADDR
,
150 .scl_sda_cfg
= &byt_config
,
154 .bus_cfg
= INTEL_MID_STD_CFG
| DW_IC_CON_SPEED_FAST
,
157 .functionality
= I2C_FUNC_10BIT_ADDR
,
158 .scl_sda_cfg
= &hsw_config
,
163 static int i2c_dw_pci_suspend(struct device
*dev
)
165 struct pci_dev
*pdev
= to_pci_dev(dev
);
167 i2c_dw_disable(pci_get_drvdata(pdev
));
171 static int i2c_dw_pci_resume(struct device
*dev
)
173 struct pci_dev
*pdev
= to_pci_dev(dev
);
175 return i2c_dw_init(pci_get_drvdata(pdev
));
179 static UNIVERSAL_DEV_PM_OPS(i2c_dw_pm_ops
, i2c_dw_pci_suspend
,
180 i2c_dw_pci_resume
, NULL
);
182 static u32
i2c_dw_get_clk_rate_khz(struct dw_i2c_dev
*dev
)
184 return dev
->controller
->clk_khz
;
187 static int i2c_dw_pci_probe(struct pci_dev
*pdev
,
188 const struct pci_device_id
*id
)
190 struct dw_i2c_dev
*dev
;
191 struct i2c_adapter
*adap
;
193 struct dw_pci_controller
*controller
;
194 struct dw_scl_sda_cfg
*cfg
;
196 if (id
->driver_data
>= ARRAY_SIZE(dw_pci_controllers
)) {
197 dev_err(&pdev
->dev
, "%s: invalid driver data %ld\n", __func__
,
202 controller
= &dw_pci_controllers
[id
->driver_data
];
204 r
= pcim_enable_device(pdev
);
206 dev_err(&pdev
->dev
, "Failed to enable I2C PCI device (%d)\n",
211 r
= pcim_iomap_regions(pdev
, 1 << 0, pci_name(pdev
));
213 dev_err(&pdev
->dev
, "I/O memory remapping failed\n");
217 dev
= devm_kzalloc(&pdev
->dev
, sizeof(struct dw_i2c_dev
), GFP_KERNEL
);
222 dev
->controller
= controller
;
223 dev
->get_clk_rate_khz
= i2c_dw_get_clk_rate_khz
;
224 dev
->base
= pcim_iomap_table(pdev
)[0];
225 dev
->dev
= &pdev
->dev
;
226 dev
->irq
= pdev
->irq
;
227 dev
->functionality
= controller
->functionality
|
228 DW_DEFAULT_FUNCTIONALITY
;
230 dev
->master_cfg
= controller
->bus_cfg
;
231 if (controller
->scl_sda_cfg
) {
232 cfg
= controller
->scl_sda_cfg
;
233 dev
->ss_hcnt
= cfg
->ss_hcnt
;
234 dev
->fs_hcnt
= cfg
->fs_hcnt
;
235 dev
->ss_lcnt
= cfg
->ss_lcnt
;
236 dev
->fs_lcnt
= cfg
->fs_lcnt
;
237 dev
->sda_hold_time
= cfg
->sda_hold
;
240 pci_set_drvdata(pdev
, dev
);
242 dev
->tx_fifo_depth
= controller
->tx_fifo_depth
;
243 dev
->rx_fifo_depth
= controller
->rx_fifo_depth
;
245 adap
= &dev
->adapter
;
246 adap
->owner
= THIS_MODULE
;
248 ACPI_COMPANION_SET(&adap
->dev
, ACPI_COMPANION(&pdev
->dev
));
249 adap
->nr
= controller
->bus_num
;
251 r
= i2c_dw_probe(dev
);
255 pm_runtime_set_autosuspend_delay(&pdev
->dev
, 1000);
256 pm_runtime_use_autosuspend(&pdev
->dev
);
257 pm_runtime_put_autosuspend(&pdev
->dev
);
258 pm_runtime_allow(&pdev
->dev
);
263 static void i2c_dw_pci_remove(struct pci_dev
*pdev
)
265 struct dw_i2c_dev
*dev
= pci_get_drvdata(pdev
);
268 pm_runtime_forbid(&pdev
->dev
);
269 pm_runtime_get_noresume(&pdev
->dev
);
271 i2c_del_adapter(&dev
->adapter
);
274 /* work with hotplug and coldplug */
275 MODULE_ALIAS("i2c_designware-pci");
277 static const struct pci_device_id i2_designware_pci_ids
[] = {
279 { PCI_VDEVICE(INTEL
, 0x0817), medfield_3
},
280 { PCI_VDEVICE(INTEL
, 0x0818), medfield_4
},
281 { PCI_VDEVICE(INTEL
, 0x0819), medfield_5
},
282 { PCI_VDEVICE(INTEL
, 0x082C), medfield_0
},
283 { PCI_VDEVICE(INTEL
, 0x082D), medfield_1
},
284 { PCI_VDEVICE(INTEL
, 0x082E), medfield_2
},
286 { PCI_VDEVICE(INTEL
, 0x0F41), baytrail
},
287 { PCI_VDEVICE(INTEL
, 0x0F42), baytrail
},
288 { PCI_VDEVICE(INTEL
, 0x0F43), baytrail
},
289 { PCI_VDEVICE(INTEL
, 0x0F44), baytrail
},
290 { PCI_VDEVICE(INTEL
, 0x0F45), baytrail
},
291 { PCI_VDEVICE(INTEL
, 0x0F46), baytrail
},
292 { PCI_VDEVICE(INTEL
, 0x0F47), baytrail
},
294 { PCI_VDEVICE(INTEL
, 0x9c61), haswell
},
295 { PCI_VDEVICE(INTEL
, 0x9c62), haswell
},
296 /* Braswell / Cherrytrail */
297 { PCI_VDEVICE(INTEL
, 0x22C1), baytrail
},
298 { PCI_VDEVICE(INTEL
, 0x22C2), baytrail
},
299 { PCI_VDEVICE(INTEL
, 0x22C3), baytrail
},
300 { PCI_VDEVICE(INTEL
, 0x22C4), baytrail
},
301 { PCI_VDEVICE(INTEL
, 0x22C5), baytrail
},
302 { PCI_VDEVICE(INTEL
, 0x22C6), baytrail
},
303 { PCI_VDEVICE(INTEL
, 0x22C7), baytrail
},
306 MODULE_DEVICE_TABLE(pci
, i2_designware_pci_ids
);
308 static struct pci_driver dw_i2c_driver
= {
310 .id_table
= i2_designware_pci_ids
,
311 .probe
= i2c_dw_pci_probe
,
312 .remove
= i2c_dw_pci_remove
,
314 .pm
= &i2c_dw_pm_ops
,
318 module_pci_driver(dw_i2c_driver
);
320 MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
321 MODULE_DESCRIPTION("Synopsys DesignWare PCI I2C bus adapter");
322 MODULE_LICENSE("GPL");