2019-05-29 22:18:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-02-02 10:52:51 +08:00
|
|
|
/*
|
|
|
|
* Intel Quark MFD PCI driver for I2C & GPIO
|
|
|
|
*
|
|
|
|
* Copyright(c) 2014 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Intel Quark PCI device for I2C and GPIO controller sharing the same
|
|
|
|
* PCI function. This PCI driver will split the 2 devices into their
|
|
|
|
* respective drivers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <linux/clkdev.h>
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/dmi.h>
|
2021-03-02 21:56:19 +08:00
|
|
|
#include <linux/i2c.h>
|
2015-02-02 10:52:51 +08:00
|
|
|
#include <linux/platform_data/gpio-dwapb.h>
|
2021-03-31 23:48:50 +08:00
|
|
|
#include <linux/property.h>
|
2015-02-02 10:52:51 +08:00
|
|
|
|
|
|
|
/* PCI BAR for register base address */
|
|
|
|
#define MFD_I2C_BAR 0
|
|
|
|
#define MFD_GPIO_BAR 1
|
|
|
|
|
2015-10-23 17:16:43 +08:00
|
|
|
/* ACPI _ADR value to match the child node */
|
|
|
|
#define MFD_ACPI_MATCH_GPIO 0ULL
|
|
|
|
#define MFD_ACPI_MATCH_I2C 1ULL
|
|
|
|
|
2015-02-02 10:52:51 +08:00
|
|
|
/* The base GPIO number under GPIOLIB framework */
|
|
|
|
#define INTEL_QUARK_MFD_GPIO_BASE 8
|
|
|
|
|
|
|
|
/* The default number of South-Cluster GPIO on Quark. */
|
|
|
|
#define INTEL_QUARK_MFD_NGPIO 8
|
|
|
|
|
|
|
|
/* The DesignWare GPIO ports on Quark. */
|
|
|
|
#define INTEL_QUARK_GPIO_NPORTS 1
|
|
|
|
|
|
|
|
#define INTEL_QUARK_IORES_MEM 0
|
|
|
|
#define INTEL_QUARK_IORES_IRQ 1
|
|
|
|
|
|
|
|
#define INTEL_QUARK_I2C_CONTROLLER_CLK "i2c_designware.0"
|
|
|
|
|
|
|
|
/* The Quark I2C controller source clock */
|
|
|
|
#define INTEL_QUARK_I2C_CLK_HZ 33000000
|
|
|
|
|
|
|
|
struct intel_quark_mfd {
|
|
|
|
struct clk *i2c_clk;
|
|
|
|
struct clk_lookup *i2c_clk_lookup;
|
|
|
|
};
|
|
|
|
|
2021-03-31 23:48:50 +08:00
|
|
|
static const struct property_entry intel_quark_i2c_controller_standard_properties[] = {
|
|
|
|
PROPERTY_ENTRY_U32("clock-frequency", I2C_MAX_STANDARD_MODE_FREQ),
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct software_node intel_quark_i2c_controller_standard_node = {
|
|
|
|
.name = "intel-quark-i2c-controller",
|
|
|
|
.properties = intel_quark_i2c_controller_standard_properties,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct property_entry intel_quark_i2c_controller_fast_properties[] = {
|
|
|
|
PROPERTY_ENTRY_U32("clock-frequency", I2C_MAX_FAST_MODE_FREQ),
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct software_node intel_quark_i2c_controller_fast_node = {
|
|
|
|
.name = "intel-quark-i2c-controller",
|
|
|
|
.properties = intel_quark_i2c_controller_fast_properties,
|
|
|
|
};
|
|
|
|
|
2017-05-30 16:17:40 +08:00
|
|
|
static const struct dmi_system_id dmi_platform_info[] = {
|
2015-02-02 10:52:51 +08:00
|
|
|
{
|
2017-05-30 16:17:40 +08:00
|
|
|
.matches = {
|
|
|
|
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Galileo"),
|
|
|
|
},
|
2021-03-31 23:48:50 +08:00
|
|
|
.driver_data = (void *)&intel_quark_i2c_controller_standard_node,
|
2015-02-02 10:52:51 +08:00
|
|
|
},
|
|
|
|
{
|
2017-05-30 16:17:40 +08:00
|
|
|
.matches = {
|
|
|
|
DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
|
|
|
|
},
|
2021-03-31 23:48:50 +08:00
|
|
|
.driver_data = (void *)&intel_quark_i2c_controller_fast_node,
|
2015-02-02 10:52:51 +08:00
|
|
|
},
|
2017-05-30 16:17:41 +08:00
|
|
|
{
|
|
|
|
.matches = {
|
|
|
|
DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
|
|
|
|
},
|
2021-03-31 23:48:50 +08:00
|
|
|
.driver_data = (void *)&intel_quark_i2c_controller_fast_node,
|
2017-05-30 16:17:41 +08:00
|
|
|
},
|
2015-03-26 02:03:55 +08:00
|
|
|
{}
|
2015-02-02 10:52:51 +08:00
|
|
|
};
|
|
|
|
|
2021-03-02 21:56:16 +08:00
|
|
|
/* This is used as a place holder and will be modified at run-time */
|
|
|
|
static struct resource intel_quark_i2c_res[] = {
|
2015-02-02 10:52:51 +08:00
|
|
|
[INTEL_QUARK_IORES_MEM] = {
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
},
|
|
|
|
[INTEL_QUARK_IORES_IRQ] = {
|
|
|
|
.flags = IORESOURCE_IRQ,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-10-23 17:16:43 +08:00
|
|
|
static struct mfd_cell_acpi_match intel_quark_acpi_match_i2c = {
|
|
|
|
.adr = MFD_ACPI_MATCH_I2C,
|
|
|
|
};
|
|
|
|
|
2021-03-02 21:56:16 +08:00
|
|
|
/* This is used as a place holder and will be modified at run-time */
|
|
|
|
static struct resource intel_quark_gpio_res[] = {
|
2015-02-02 10:52:51 +08:00
|
|
|
[INTEL_QUARK_IORES_MEM] = {
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-10-23 17:16:43 +08:00
|
|
|
static struct mfd_cell_acpi_match intel_quark_acpi_match_gpio = {
|
|
|
|
.adr = MFD_ACPI_MATCH_GPIO,
|
|
|
|
};
|
|
|
|
|
2015-02-02 10:52:51 +08:00
|
|
|
static struct mfd_cell intel_quark_mfd_cells[] = {
|
2021-03-23 20:34:32 +08:00
|
|
|
[MFD_I2C_BAR] = {
|
2015-10-23 17:16:42 +08:00
|
|
|
.id = MFD_I2C_BAR,
|
|
|
|
.name = "i2c_designware",
|
2015-10-23 17:16:43 +08:00
|
|
|
.acpi_match = &intel_quark_acpi_match_i2c,
|
2015-10-23 17:16:42 +08:00
|
|
|
.num_resources = ARRAY_SIZE(intel_quark_i2c_res),
|
|
|
|
.resources = intel_quark_i2c_res,
|
|
|
|
.ignore_resource_conflicts = true,
|
|
|
|
},
|
2021-03-23 20:34:32 +08:00
|
|
|
[MFD_GPIO_BAR] = {
|
|
|
|
.id = MFD_GPIO_BAR,
|
|
|
|
.name = "gpio-dwapb",
|
|
|
|
.acpi_match = &intel_quark_acpi_match_gpio,
|
|
|
|
.num_resources = ARRAY_SIZE(intel_quark_gpio_res),
|
|
|
|
.resources = intel_quark_gpio_res,
|
|
|
|
.ignore_resource_conflicts = true,
|
|
|
|
},
|
2015-02-02 10:52:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct pci_device_id intel_quark_mfd_ids[] = {
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x0934), },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, intel_quark_mfd_ids);
|
|
|
|
|
2016-02-19 16:42:11 +08:00
|
|
|
static int intel_quark_register_i2c_clk(struct device *dev)
|
2015-02-02 10:52:51 +08:00
|
|
|
{
|
2016-02-19 16:42:11 +08:00
|
|
|
struct intel_quark_mfd *quark_mfd = dev_get_drvdata(dev);
|
2015-02-02 10:52:51 +08:00
|
|
|
struct clk *i2c_clk;
|
|
|
|
|
2016-02-19 16:42:11 +08:00
|
|
|
i2c_clk = clk_register_fixed_rate(dev,
|
2015-02-02 10:52:51 +08:00
|
|
|
INTEL_QUARK_I2C_CONTROLLER_CLK, NULL,
|
2016-04-20 09:19:20 +08:00
|
|
|
0, INTEL_QUARK_I2C_CLK_HZ);
|
2016-02-09 09:45:28 +08:00
|
|
|
if (IS_ERR(i2c_clk))
|
|
|
|
return PTR_ERR(i2c_clk);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
|
|
|
quark_mfd->i2c_clk = i2c_clk;
|
2016-02-09 09:45:28 +08:00
|
|
|
quark_mfd->i2c_clk_lookup = clkdev_create(i2c_clk, NULL,
|
|
|
|
INTEL_QUARK_I2C_CONTROLLER_CLK);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2016-02-09 09:45:28 +08:00
|
|
|
if (!quark_mfd->i2c_clk_lookup) {
|
2016-02-19 16:42:10 +08:00
|
|
|
clk_unregister(quark_mfd->i2c_clk);
|
2016-02-19 16:42:11 +08:00
|
|
|
dev_err(dev, "Fixed clk register failed\n");
|
2016-02-09 09:45:28 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2016-02-09 09:45:28 +08:00
|
|
|
return 0;
|
2015-02-02 10:52:51 +08:00
|
|
|
}
|
|
|
|
|
2016-02-19 16:42:11 +08:00
|
|
|
static void intel_quark_unregister_i2c_clk(struct device *dev)
|
2015-02-02 10:52:51 +08:00
|
|
|
{
|
2016-02-19 16:42:11 +08:00
|
|
|
struct intel_quark_mfd *quark_mfd = dev_get_drvdata(dev);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2016-02-19 16:42:10 +08:00
|
|
|
if (!quark_mfd->i2c_clk_lookup)
|
2015-02-02 10:52:51 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
clkdev_drop(quark_mfd->i2c_clk_lookup);
|
|
|
|
clk_unregister(quark_mfd->i2c_clk);
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:48:42 +08:00
|
|
|
static int intel_quark_i2c_setup(struct pci_dev *pdev)
|
2015-02-02 10:52:51 +08:00
|
|
|
{
|
2021-03-26 20:48:42 +08:00
|
|
|
struct mfd_cell *cell = &intel_quark_mfd_cells[MFD_I2C_BAR];
|
|
|
|
struct resource *res = intel_quark_i2c_res;
|
2017-05-30 16:17:40 +08:00
|
|
|
const struct dmi_system_id *dmi_id;
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2021-03-26 20:48:42 +08:00
|
|
|
res[INTEL_QUARK_IORES_MEM].start = pci_resource_start(pdev, MFD_I2C_BAR);
|
|
|
|
res[INTEL_QUARK_IORES_MEM].end = pci_resource_end(pdev, MFD_I2C_BAR);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2021-03-25 01:08:34 +08:00
|
|
|
res[INTEL_QUARK_IORES_IRQ].start = pci_irq_vector(pdev, 0);
|
|
|
|
res[INTEL_QUARK_IORES_IRQ].end = pci_irq_vector(pdev, 0);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2015-03-26 02:03:55 +08:00
|
|
|
/* Normal mode by default */
|
2021-03-31 23:48:50 +08:00
|
|
|
cell->swnode = &intel_quark_i2c_controller_standard_node;
|
2015-03-26 02:03:55 +08:00
|
|
|
|
2017-05-30 16:17:40 +08:00
|
|
|
dmi_id = dmi_first_match(dmi_platform_info);
|
|
|
|
if (dmi_id)
|
2021-03-31 23:48:50 +08:00
|
|
|
cell->swnode = (struct software_node *)dmi_id->driver_data;
|
2015-02-02 10:52:51 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:48:42 +08:00
|
|
|
static int intel_quark_gpio_setup(struct pci_dev *pdev)
|
2015-02-02 10:52:51 +08:00
|
|
|
{
|
2021-03-26 20:48:42 +08:00
|
|
|
struct mfd_cell *cell = &intel_quark_mfd_cells[MFD_GPIO_BAR];
|
|
|
|
struct resource *res = intel_quark_gpio_res;
|
2015-02-02 10:52:51 +08:00
|
|
|
struct dwapb_platform_data *pdata;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
|
2021-03-26 20:48:42 +08:00
|
|
|
res[INTEL_QUARK_IORES_MEM].start = pci_resource_start(pdev, MFD_GPIO_BAR);
|
|
|
|
res[INTEL_QUARK_IORES_MEM].end = pci_resource_end(pdev, MFD_GPIO_BAR);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
|
|
|
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* For intel quark x1000, it has only one port: portA */
|
|
|
|
pdata->nports = INTEL_QUARK_GPIO_NPORTS;
|
|
|
|
pdata->properties = devm_kcalloc(dev, pdata->nports,
|
|
|
|
sizeof(*pdata->properties),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!pdata->properties)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Set the properties for portA */
|
2016-04-28 17:32:02 +08:00
|
|
|
pdata->properties->fwnode = NULL;
|
2015-02-02 10:52:51 +08:00
|
|
|
pdata->properties->idx = 0;
|
|
|
|
pdata->properties->ngpio = INTEL_QUARK_MFD_NGPIO;
|
|
|
|
pdata->properties->gpio_base = INTEL_QUARK_MFD_GPIO_BASE;
|
2021-03-25 01:08:34 +08:00
|
|
|
pdata->properties->irq[0] = pci_irq_vector(pdev, 0);
|
2015-02-02 10:52:51 +08:00
|
|
|
pdata->properties->irq_shared = true;
|
|
|
|
|
|
|
|
cell->platform_data = pdata;
|
|
|
|
cell->pdata_size = sizeof(*pdata);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int intel_quark_mfd_probe(struct pci_dev *pdev,
|
|
|
|
const struct pci_device_id *id)
|
|
|
|
{
|
|
|
|
struct intel_quark_mfd *quark_mfd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pcim_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
quark_mfd = devm_kzalloc(&pdev->dev, sizeof(*quark_mfd), GFP_KERNEL);
|
|
|
|
if (!quark_mfd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-02-19 16:42:10 +08:00
|
|
|
dev_set_drvdata(&pdev->dev, quark_mfd);
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2016-02-19 16:42:11 +08:00
|
|
|
ret = intel_quark_register_i2c_clk(&pdev->dev);
|
2015-02-02 10:52:51 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-03-25 01:08:34 +08:00
|
|
|
pci_set_master(pdev);
|
|
|
|
|
|
|
|
/* This driver only requires 1 IRQ vector */
|
|
|
|
ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
|
|
|
|
if (ret < 0)
|
2016-02-19 16:42:10 +08:00
|
|
|
goto err_unregister_i2c_clk;
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2021-03-26 20:48:42 +08:00
|
|
|
ret = intel_quark_i2c_setup(pdev);
|
2015-02-02 10:52:51 +08:00
|
|
|
if (ret)
|
2021-03-25 01:08:34 +08:00
|
|
|
goto err_free_irq_vectors;
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2021-03-26 20:48:42 +08:00
|
|
|
ret = intel_quark_gpio_setup(pdev);
|
2015-02-02 10:52:51 +08:00
|
|
|
if (ret)
|
2021-03-25 01:08:34 +08:00
|
|
|
goto err_free_irq_vectors;
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2016-02-19 16:42:10 +08:00
|
|
|
ret = mfd_add_devices(&pdev->dev, 0, intel_quark_mfd_cells,
|
|
|
|
ARRAY_SIZE(intel_quark_mfd_cells), NULL, 0,
|
|
|
|
NULL);
|
|
|
|
if (ret)
|
2021-03-25 01:08:34 +08:00
|
|
|
goto err_free_irq_vectors;
|
2016-02-19 16:42:10 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-02-02 10:52:51 +08:00
|
|
|
|
2021-03-25 01:08:34 +08:00
|
|
|
err_free_irq_vectors:
|
|
|
|
pci_free_irq_vectors(pdev);
|
2016-02-19 16:42:10 +08:00
|
|
|
err_unregister_i2c_clk:
|
2016-02-19 16:42:11 +08:00
|
|
|
intel_quark_unregister_i2c_clk(&pdev->dev);
|
2016-02-19 16:42:10 +08:00
|
|
|
return ret;
|
2015-02-02 10:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void intel_quark_mfd_remove(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
mfd_remove_devices(&pdev->dev);
|
2021-03-25 01:08:34 +08:00
|
|
|
pci_free_irq_vectors(pdev);
|
2021-03-02 21:56:17 +08:00
|
|
|
intel_quark_unregister_i2c_clk(&pdev->dev);
|
2015-02-02 10:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_driver intel_quark_mfd_driver = {
|
|
|
|
.name = "intel_quark_mfd_i2c_gpio",
|
|
|
|
.id_table = intel_quark_mfd_ids,
|
|
|
|
.probe = intel_quark_mfd_probe,
|
|
|
|
.remove = intel_quark_mfd_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_pci_driver(intel_quark_mfd_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Raymond Tan <raymond.tan@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Intel Quark MFD PCI driver for I2C & GPIO");
|
|
|
|
MODULE_LICENSE("GPL v2");
|