xref: /openbmc/linux/drivers/mfd/intel-lpss-pci.c (revision ec14c5395dfbc1d40a49c9f19d2bfde6739d89d5)
14b45efe8SAndy Shevchenko /*
24b45efe8SAndy Shevchenko  * Intel LPSS PCI support.
34b45efe8SAndy Shevchenko  *
44b45efe8SAndy Shevchenko  * Copyright (C) 2015, Intel Corporation
54b45efe8SAndy Shevchenko  *
64b45efe8SAndy Shevchenko  * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
74b45efe8SAndy Shevchenko  *          Mika Westerberg <mika.westerberg@linux.intel.com>
84b45efe8SAndy Shevchenko  *
94b45efe8SAndy Shevchenko  * This program is free software; you can redistribute it and/or modify
104b45efe8SAndy Shevchenko  * it under the terms of the GNU General Public License version 2 as
114b45efe8SAndy Shevchenko  * published by the Free Software Foundation.
124b45efe8SAndy Shevchenko  */
134b45efe8SAndy Shevchenko 
144b45efe8SAndy Shevchenko #include <linux/ioport.h>
154b45efe8SAndy Shevchenko #include <linux/kernel.h>
164b45efe8SAndy Shevchenko #include <linux/module.h>
174b45efe8SAndy Shevchenko #include <linux/pci.h>
184b45efe8SAndy Shevchenko #include <linux/pm.h>
194b45efe8SAndy Shevchenko #include <linux/pm_runtime.h>
20028af594SMika Westerberg #include <linux/property.h>
214b45efe8SAndy Shevchenko 
224b45efe8SAndy Shevchenko #include "intel-lpss.h"
234b45efe8SAndy Shevchenko 
244b45efe8SAndy Shevchenko static int intel_lpss_pci_probe(struct pci_dev *pdev,
254b45efe8SAndy Shevchenko 				const struct pci_device_id *id)
264b45efe8SAndy Shevchenko {
274b45efe8SAndy Shevchenko 	struct intel_lpss_platform_info *info;
284b45efe8SAndy Shevchenko 	int ret;
294b45efe8SAndy Shevchenko 
304b45efe8SAndy Shevchenko 	ret = pcim_enable_device(pdev);
314b45efe8SAndy Shevchenko 	if (ret)
324b45efe8SAndy Shevchenko 		return ret;
334b45efe8SAndy Shevchenko 
344b45efe8SAndy Shevchenko 	info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
354b45efe8SAndy Shevchenko 			    GFP_KERNEL);
364b45efe8SAndy Shevchenko 	if (!info)
374b45efe8SAndy Shevchenko 		return -ENOMEM;
384b45efe8SAndy Shevchenko 
394b45efe8SAndy Shevchenko 	info->mem = &pdev->resource[0];
404b45efe8SAndy Shevchenko 	info->irq = pdev->irq;
414b45efe8SAndy Shevchenko 
424b45efe8SAndy Shevchenko 	/* Probably it is enough to set this for iDMA capable devices only */
434b45efe8SAndy Shevchenko 	pci_set_master(pdev);
444b45efe8SAndy Shevchenko 
454b45efe8SAndy Shevchenko 	ret = intel_lpss_probe(&pdev->dev, info);
464b45efe8SAndy Shevchenko 	if (ret)
474b45efe8SAndy Shevchenko 		return ret;
484b45efe8SAndy Shevchenko 
494b45efe8SAndy Shevchenko 	pm_runtime_put(&pdev->dev);
504b45efe8SAndy Shevchenko 	pm_runtime_allow(&pdev->dev);
514b45efe8SAndy Shevchenko 
524b45efe8SAndy Shevchenko 	return 0;
534b45efe8SAndy Shevchenko }
544b45efe8SAndy Shevchenko 
554b45efe8SAndy Shevchenko static void intel_lpss_pci_remove(struct pci_dev *pdev)
564b45efe8SAndy Shevchenko {
574b45efe8SAndy Shevchenko 	pm_runtime_forbid(&pdev->dev);
584b45efe8SAndy Shevchenko 	pm_runtime_get_sync(&pdev->dev);
594b45efe8SAndy Shevchenko 
604b45efe8SAndy Shevchenko 	intel_lpss_remove(&pdev->dev);
614b45efe8SAndy Shevchenko }
624b45efe8SAndy Shevchenko 
634b45efe8SAndy Shevchenko static INTEL_LPSS_PM_OPS(intel_lpss_pci_pm_ops);
644b45efe8SAndy Shevchenko 
654b45efe8SAndy Shevchenko static const struct intel_lpss_platform_info spt_info = {
664b45efe8SAndy Shevchenko 	.clk_rate = 120000000,
674b45efe8SAndy Shevchenko };
684b45efe8SAndy Shevchenko 
69028af594SMika Westerberg static struct property_entry spt_i2c_properties[] = {
70028af594SMika Westerberg 	PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 230),
71028af594SMika Westerberg 	{ },
72028af594SMika Westerberg };
73028af594SMika Westerberg 
74028af594SMika Westerberg static struct property_set spt_i2c_pset = {
75028af594SMika Westerberg 	.properties = spt_i2c_properties,
76028af594SMika Westerberg };
77028af594SMika Westerberg 
78028af594SMika Westerberg static const struct intel_lpss_platform_info spt_i2c_info = {
79028af594SMika Westerberg 	.clk_rate = 120000000,
80028af594SMika Westerberg 	.pset = &spt_i2c_pset,
81028af594SMika Westerberg };
82028af594SMika Westerberg 
83*ec14c539SAndy Shevchenko static struct property_entry uart_properties[] = {
84*ec14c539SAndy Shevchenko 	PROPERTY_ENTRY_U32("reg-io-width", 4),
85*ec14c539SAndy Shevchenko 	PROPERTY_ENTRY_U32("reg-shift", 2),
86*ec14c539SAndy Shevchenko 	PROPERTY_ENTRY_BOOL("snps,uart-16550-compatible"),
87*ec14c539SAndy Shevchenko 	{ },
88*ec14c539SAndy Shevchenko };
89*ec14c539SAndy Shevchenko 
90*ec14c539SAndy Shevchenko static struct property_set uart_pset = {
91*ec14c539SAndy Shevchenko 	.properties = uart_properties,
92*ec14c539SAndy Shevchenko };
93*ec14c539SAndy Shevchenko 
944b45efe8SAndy Shevchenko static const struct intel_lpss_platform_info spt_uart_info = {
954b45efe8SAndy Shevchenko 	.clk_rate = 120000000,
964b45efe8SAndy Shevchenko 	.clk_con_id = "baudclk",
97*ec14c539SAndy Shevchenko 	.pset = &uart_pset,
984b45efe8SAndy Shevchenko };
994b45efe8SAndy Shevchenko 
100ff0a04a6SAndy Shevchenko static const struct intel_lpss_platform_info bxt_info = {
101ff0a04a6SAndy Shevchenko 	.clk_rate = 100000000,
102ff0a04a6SAndy Shevchenko };
103ff0a04a6SAndy Shevchenko 
104ff0a04a6SAndy Shevchenko static const struct intel_lpss_platform_info bxt_uart_info = {
105ff0a04a6SAndy Shevchenko 	.clk_rate = 100000000,
106ff0a04a6SAndy Shevchenko 	.clk_con_id = "baudclk",
107*ec14c539SAndy Shevchenko 	.pset = &uart_pset,
108ff0a04a6SAndy Shevchenko };
109ff0a04a6SAndy Shevchenko 
110ff0a04a6SAndy Shevchenko static const struct intel_lpss_platform_info bxt_i2c_info = {
111ff0a04a6SAndy Shevchenko 	.clk_rate = 133000000,
112ff0a04a6SAndy Shevchenko };
113ff0a04a6SAndy Shevchenko 
1144b45efe8SAndy Shevchenko static const struct pci_device_id intel_lpss_pci_ids[] = {
115ff0a04a6SAndy Shevchenko 	/* BXT */
116ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0aac), (kernel_ulong_t)&bxt_i2c_info },
117ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0aae), (kernel_ulong_t)&bxt_i2c_info },
118ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ab0), (kernel_ulong_t)&bxt_i2c_info },
119ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ab2), (kernel_ulong_t)&bxt_i2c_info },
120ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ab4), (kernel_ulong_t)&bxt_i2c_info },
121ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ab6), (kernel_ulong_t)&bxt_i2c_info },
122ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ab8), (kernel_ulong_t)&bxt_i2c_info },
123ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0aba), (kernel_ulong_t)&bxt_i2c_info },
124ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0abc), (kernel_ulong_t)&bxt_uart_info },
125ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0abe), (kernel_ulong_t)&bxt_uart_info },
126ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ac0), (kernel_ulong_t)&bxt_uart_info },
127ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ac2), (kernel_ulong_t)&bxt_info },
128ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ac4), (kernel_ulong_t)&bxt_info },
129ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0ac6), (kernel_ulong_t)&bxt_info },
130ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x0aee), (kernel_ulong_t)&bxt_uart_info },
131ff0a04a6SAndy Shevchenko 	/* APL */
132ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5aac), (kernel_ulong_t)&bxt_i2c_info },
133ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5aae), (kernel_ulong_t)&bxt_i2c_info },
134ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ab0), (kernel_ulong_t)&bxt_i2c_info },
135ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ab2), (kernel_ulong_t)&bxt_i2c_info },
136ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ab4), (kernel_ulong_t)&bxt_i2c_info },
137ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ab6), (kernel_ulong_t)&bxt_i2c_info },
138ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ab8), (kernel_ulong_t)&bxt_i2c_info },
139ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5aba), (kernel_ulong_t)&bxt_i2c_info },
140ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5abc), (kernel_ulong_t)&bxt_uart_info },
141ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5abe), (kernel_ulong_t)&bxt_uart_info },
142ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ac0), (kernel_ulong_t)&bxt_uart_info },
143ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ac2), (kernel_ulong_t)&bxt_info },
144ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ac4), (kernel_ulong_t)&bxt_info },
145ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5ac6), (kernel_ulong_t)&bxt_info },
146ff0a04a6SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x5aee), (kernel_ulong_t)&bxt_uart_info },
1474b45efe8SAndy Shevchenko 	/* SPT-LP */
1484b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x9d27), (kernel_ulong_t)&spt_uart_info },
1494b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x9d28), (kernel_ulong_t)&spt_uart_info },
1504b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x9d29), (kernel_ulong_t)&spt_info },
1514b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x9d2a), (kernel_ulong_t)&spt_info },
152028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0x9d60), (kernel_ulong_t)&spt_i2c_info },
153028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0x9d61), (kernel_ulong_t)&spt_i2c_info },
154028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0x9d62), (kernel_ulong_t)&spt_i2c_info },
155028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0x9d63), (kernel_ulong_t)&spt_i2c_info },
156028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0x9d64), (kernel_ulong_t)&spt_i2c_info },
157028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0x9d65), (kernel_ulong_t)&spt_i2c_info },
1584b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0x9d66), (kernel_ulong_t)&spt_uart_info },
1594b45efe8SAndy Shevchenko 	/* SPT-H */
1604b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0xa127), (kernel_ulong_t)&spt_uart_info },
1614b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0xa128), (kernel_ulong_t)&spt_uart_info },
1624b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0xa129), (kernel_ulong_t)&spt_info },
1634b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0xa12a), (kernel_ulong_t)&spt_info },
164028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0xa160), (kernel_ulong_t)&spt_i2c_info },
165028af594SMika Westerberg 	{ PCI_VDEVICE(INTEL, 0xa161), (kernel_ulong_t)&spt_i2c_info },
1664b45efe8SAndy Shevchenko 	{ PCI_VDEVICE(INTEL, 0xa166), (kernel_ulong_t)&spt_uart_info },
1674b45efe8SAndy Shevchenko 	{ }
1684b45efe8SAndy Shevchenko };
1694b45efe8SAndy Shevchenko MODULE_DEVICE_TABLE(pci, intel_lpss_pci_ids);
1704b45efe8SAndy Shevchenko 
1714b45efe8SAndy Shevchenko static struct pci_driver intel_lpss_pci_driver = {
1724b45efe8SAndy Shevchenko 	.name = "intel-lpss",
1734b45efe8SAndy Shevchenko 	.id_table = intel_lpss_pci_ids,
1744b45efe8SAndy Shevchenko 	.probe = intel_lpss_pci_probe,
1754b45efe8SAndy Shevchenko 	.remove = intel_lpss_pci_remove,
1764b45efe8SAndy Shevchenko 	.driver = {
1774b45efe8SAndy Shevchenko 		.pm = &intel_lpss_pci_pm_ops,
1784b45efe8SAndy Shevchenko 	},
1794b45efe8SAndy Shevchenko };
1804b45efe8SAndy Shevchenko 
1814b45efe8SAndy Shevchenko module_pci_driver(intel_lpss_pci_driver);
1824b45efe8SAndy Shevchenko 
1834b45efe8SAndy Shevchenko MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
1844b45efe8SAndy Shevchenko MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
1854b45efe8SAndy Shevchenko MODULE_DESCRIPTION("Intel LPSS PCI driver");
1864b45efe8SAndy Shevchenko MODULE_LICENSE("GPL v2");
187