1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Quark MFD PCI driver for I2C & GPIO
5 * Copyright(c) 2014 Intel Corporation.
7 * Intel Quark PCI device for I2C and GPIO controller sharing the same
8 * PCI function. This PCI driver will split the 2 devices into their
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/mfd/core.h>
16 #include <linux/clkdev.h>
17 #include <linux/clk-provider.h>
18 #include <linux/dmi.h>
19 #include <linux/platform_data/gpio-dwapb.h>
20 #include <linux/platform_data/i2c-designware.h>
22 /* PCI BAR for register base address */
24 #define MFD_GPIO_BAR 1
26 /* ACPI _ADR value to match the child node */
27 #define MFD_ACPI_MATCH_GPIO 0ULL
28 #define MFD_ACPI_MATCH_I2C 1ULL
30 /* The base GPIO number under GPIOLIB framework */
31 #define INTEL_QUARK_MFD_GPIO_BASE 8
33 /* The default number of South-Cluster GPIO on Quark. */
34 #define INTEL_QUARK_MFD_NGPIO 8
36 /* The DesignWare GPIO ports on Quark. */
37 #define INTEL_QUARK_GPIO_NPORTS 1
39 #define INTEL_QUARK_IORES_MEM 0
40 #define INTEL_QUARK_IORES_IRQ 1
42 #define INTEL_QUARK_I2C_CONTROLLER_CLK "i2c_designware.0"
44 /* The Quark I2C controller source clock */
45 #define INTEL_QUARK_I2C_CLK_HZ 33000000
47 struct intel_quark_mfd
{
50 struct clk_lookup
*i2c_clk_lookup
;
53 static const struct dmi_system_id dmi_platform_info
[] = {
56 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Galileo"),
58 .driver_data
= (void *)100000,
62 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "GalileoGen2"),
64 .driver_data
= (void *)400000,
68 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "SIMATIC IOT2000"),
70 .driver_data
= (void *)400000,
75 static struct resource intel_quark_i2c_res
[] = {
76 [INTEL_QUARK_IORES_MEM
] = {
77 .flags
= IORESOURCE_MEM
,
79 [INTEL_QUARK_IORES_IRQ
] = {
80 .flags
= IORESOURCE_IRQ
,
84 static struct mfd_cell_acpi_match intel_quark_acpi_match_i2c
= {
85 .adr
= MFD_ACPI_MATCH_I2C
,
88 static struct resource intel_quark_gpio_res
[] = {
89 [INTEL_QUARK_IORES_MEM
] = {
90 .flags
= IORESOURCE_MEM
,
94 static struct mfd_cell_acpi_match intel_quark_acpi_match_gpio
= {
95 .adr
= MFD_ACPI_MATCH_GPIO
,
98 static struct mfd_cell intel_quark_mfd_cells
[] = {
101 .name
= "gpio-dwapb",
102 .acpi_match
= &intel_quark_acpi_match_gpio
,
103 .num_resources
= ARRAY_SIZE(intel_quark_gpio_res
),
104 .resources
= intel_quark_gpio_res
,
105 .ignore_resource_conflicts
= true,
109 .name
= "i2c_designware",
110 .acpi_match
= &intel_quark_acpi_match_i2c
,
111 .num_resources
= ARRAY_SIZE(intel_quark_i2c_res
),
112 .resources
= intel_quark_i2c_res
,
113 .ignore_resource_conflicts
= true,
117 static const struct pci_device_id intel_quark_mfd_ids
[] = {
118 { PCI_VDEVICE(INTEL
, 0x0934), },
121 MODULE_DEVICE_TABLE(pci
, intel_quark_mfd_ids
);
123 static int intel_quark_register_i2c_clk(struct device
*dev
)
125 struct intel_quark_mfd
*quark_mfd
= dev_get_drvdata(dev
);
128 i2c_clk
= clk_register_fixed_rate(dev
,
129 INTEL_QUARK_I2C_CONTROLLER_CLK
, NULL
,
130 0, INTEL_QUARK_I2C_CLK_HZ
);
132 return PTR_ERR(i2c_clk
);
134 quark_mfd
->i2c_clk
= i2c_clk
;
135 quark_mfd
->i2c_clk_lookup
= clkdev_create(i2c_clk
, NULL
,
136 INTEL_QUARK_I2C_CONTROLLER_CLK
);
138 if (!quark_mfd
->i2c_clk_lookup
) {
139 clk_unregister(quark_mfd
->i2c_clk
);
140 dev_err(dev
, "Fixed clk register failed\n");
147 static void intel_quark_unregister_i2c_clk(struct device
*dev
)
149 struct intel_quark_mfd
*quark_mfd
= dev_get_drvdata(dev
);
151 if (!quark_mfd
->i2c_clk_lookup
)
154 clkdev_drop(quark_mfd
->i2c_clk_lookup
);
155 clk_unregister(quark_mfd
->i2c_clk
);
158 static int intel_quark_i2c_setup(struct pci_dev
*pdev
, struct mfd_cell
*cell
)
160 const struct dmi_system_id
*dmi_id
;
161 struct dw_i2c_platform_data
*pdata
;
162 struct resource
*res
= (struct resource
*)cell
->resources
;
163 struct device
*dev
= &pdev
->dev
;
165 res
[INTEL_QUARK_IORES_MEM
].start
=
166 pci_resource_start(pdev
, MFD_I2C_BAR
);
167 res
[INTEL_QUARK_IORES_MEM
].end
=
168 pci_resource_end(pdev
, MFD_I2C_BAR
);
170 res
[INTEL_QUARK_IORES_IRQ
].start
= pdev
->irq
;
171 res
[INTEL_QUARK_IORES_IRQ
].end
= pdev
->irq
;
173 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
177 /* Normal mode by default */
178 pdata
->i2c_scl_freq
= 100000;
180 dmi_id
= dmi_first_match(dmi_platform_info
);
182 pdata
->i2c_scl_freq
= (uintptr_t)dmi_id
->driver_data
;
184 cell
->platform_data
= pdata
;
185 cell
->pdata_size
= sizeof(*pdata
);
190 static int intel_quark_gpio_setup(struct pci_dev
*pdev
, struct mfd_cell
*cell
)
192 struct dwapb_platform_data
*pdata
;
193 struct resource
*res
= (struct resource
*)cell
->resources
;
194 struct device
*dev
= &pdev
->dev
;
196 res
[INTEL_QUARK_IORES_MEM
].start
=
197 pci_resource_start(pdev
, MFD_GPIO_BAR
);
198 res
[INTEL_QUARK_IORES_MEM
].end
=
199 pci_resource_end(pdev
, MFD_GPIO_BAR
);
201 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
205 /* For intel quark x1000, it has only one port: portA */
206 pdata
->nports
= INTEL_QUARK_GPIO_NPORTS
;
207 pdata
->properties
= devm_kcalloc(dev
, pdata
->nports
,
208 sizeof(*pdata
->properties
),
210 if (!pdata
->properties
)
213 /* Set the properties for portA */
214 pdata
->properties
->fwnode
= NULL
;
215 pdata
->properties
->idx
= 0;
216 pdata
->properties
->ngpio
= INTEL_QUARK_MFD_NGPIO
;
217 pdata
->properties
->gpio_base
= INTEL_QUARK_MFD_GPIO_BASE
;
218 pdata
->properties
->irq
[0] = pdev
->irq
;
219 pdata
->properties
->has_irq
= true;
220 pdata
->properties
->irq_shared
= true;
222 cell
->platform_data
= pdata
;
223 cell
->pdata_size
= sizeof(*pdata
);
228 static int intel_quark_mfd_probe(struct pci_dev
*pdev
,
229 const struct pci_device_id
*id
)
231 struct intel_quark_mfd
*quark_mfd
;
234 ret
= pcim_enable_device(pdev
);
238 quark_mfd
= devm_kzalloc(&pdev
->dev
, sizeof(*quark_mfd
), GFP_KERNEL
);
242 quark_mfd
->dev
= &pdev
->dev
;
243 dev_set_drvdata(&pdev
->dev
, quark_mfd
);
245 ret
= intel_quark_register_i2c_clk(&pdev
->dev
);
249 ret
= intel_quark_i2c_setup(pdev
, &intel_quark_mfd_cells
[1]);
251 goto err_unregister_i2c_clk
;
253 ret
= intel_quark_gpio_setup(pdev
, &intel_quark_mfd_cells
[0]);
255 goto err_unregister_i2c_clk
;
257 ret
= mfd_add_devices(&pdev
->dev
, 0, intel_quark_mfd_cells
,
258 ARRAY_SIZE(intel_quark_mfd_cells
), NULL
, 0,
261 goto err_unregister_i2c_clk
;
265 err_unregister_i2c_clk
:
266 intel_quark_unregister_i2c_clk(&pdev
->dev
);
270 static void intel_quark_mfd_remove(struct pci_dev
*pdev
)
272 intel_quark_unregister_i2c_clk(&pdev
->dev
);
273 mfd_remove_devices(&pdev
->dev
);
276 static struct pci_driver intel_quark_mfd_driver
= {
277 .name
= "intel_quark_mfd_i2c_gpio",
278 .id_table
= intel_quark_mfd_ids
,
279 .probe
= intel_quark_mfd_probe
,
280 .remove
= intel_quark_mfd_remove
,
283 module_pci_driver(intel_quark_mfd_driver
);
285 MODULE_AUTHOR("Raymond Tan <raymond.tan@intel.com>");
286 MODULE_DESCRIPTION("Intel Quark MFD PCI driver for I2C & GPIO");
287 MODULE_LICENSE("GPL v2");