GNU Linux-libre 4.19.264-gnu1
[releases.git] / drivers / mfd / intel-lpss-pci.c
1 /*
2  * Intel LPSS PCI support.
3  *
4  * Copyright (C) 2015, Intel Corporation
5  *
6  * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
7  *          Mika Westerberg <mika.westerberg@linux.intel.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/ioport.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 #include <linux/pm.h>
19 #include <linux/pm_runtime.h>
20 #include <linux/property.h>
21
22 #include "intel-lpss.h"
23
24 static int intel_lpss_pci_probe(struct pci_dev *pdev,
25                                 const struct pci_device_id *id)
26 {
27         struct intel_lpss_platform_info *info;
28         int ret;
29
30         ret = pcim_enable_device(pdev);
31         if (ret)
32                 return ret;
33
34         info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
35                             GFP_KERNEL);
36         if (!info)
37                 return -ENOMEM;
38
39         info->mem = &pdev->resource[0];
40         info->irq = pdev->irq;
41
42         pdev->d3cold_delay = 0;
43
44         /* Probably it is enough to set this for iDMA capable devices only */
45         pci_set_master(pdev);
46         pci_try_set_mwi(pdev);
47
48         ret = intel_lpss_probe(&pdev->dev, info);
49         if (ret)
50                 return ret;
51
52         pm_runtime_put(&pdev->dev);
53         pm_runtime_allow(&pdev->dev);
54
55         return 0;
56 }
57
58 static void intel_lpss_pci_remove(struct pci_dev *pdev)
59 {
60         pm_runtime_forbid(&pdev->dev);
61         pm_runtime_get_sync(&pdev->dev);
62
63         intel_lpss_remove(&pdev->dev);
64 }
65
66 static INTEL_LPSS_PM_OPS(intel_lpss_pci_pm_ops);
67
68 static const struct intel_lpss_platform_info spt_info = {
69         .clk_rate = 120000000,
70 };
71
72 static struct property_entry spt_i2c_properties[] = {
73         PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 230),
74         { },
75 };
76
77 static const struct intel_lpss_platform_info spt_i2c_info = {
78         .clk_rate = 120000000,
79         .properties = spt_i2c_properties,
80 };
81
82 static struct property_entry uart_properties[] = {
83         PROPERTY_ENTRY_U32("reg-io-width", 4),
84         PROPERTY_ENTRY_U32("reg-shift", 2),
85         PROPERTY_ENTRY_BOOL("snps,uart-16550-compatible"),
86         { },
87 };
88
89 static const struct intel_lpss_platform_info spt_uart_info = {
90         .clk_rate = 120000000,
91         .clk_con_id = "baudclk",
92         .properties = uart_properties,
93 };
94
95 static const struct intel_lpss_platform_info bxt_info = {
96         .clk_rate = 100000000,
97 };
98
99 static const struct intel_lpss_platform_info bxt_uart_info = {
100         .clk_rate = 100000000,
101         .clk_con_id = "baudclk",
102         .properties = uart_properties,
103 };
104
105 static struct property_entry bxt_i2c_properties[] = {
106         PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 42),
107         PROPERTY_ENTRY_U32("i2c-sda-falling-time-ns", 171),
108         PROPERTY_ENTRY_U32("i2c-scl-falling-time-ns", 208),
109         { },
110 };
111
112 static const struct intel_lpss_platform_info bxt_i2c_info = {
113         .clk_rate = 133000000,
114         .properties = bxt_i2c_properties,
115 };
116
117 static struct property_entry apl_i2c_properties[] = {
118         PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 207),
119         PROPERTY_ENTRY_U32("i2c-sda-falling-time-ns", 171),
120         PROPERTY_ENTRY_U32("i2c-scl-falling-time-ns", 208),
121         { },
122 };
123
124 static const struct intel_lpss_platform_info apl_i2c_info = {
125         .clk_rate = 133000000,
126         .properties = apl_i2c_properties,
127 };
128
129 static struct property_entry glk_i2c_properties[] = {
130         PROPERTY_ENTRY_U32("i2c-sda-hold-time-ns", 313),
131         PROPERTY_ENTRY_U32("i2c-sda-falling-time-ns", 171),
132         PROPERTY_ENTRY_U32("i2c-scl-falling-time-ns", 290),
133         { },
134 };
135
136 static const struct intel_lpss_platform_info glk_i2c_info = {
137         .clk_rate = 133000000,
138         .properties = glk_i2c_properties,
139 };
140
141 static const struct intel_lpss_platform_info cnl_i2c_info = {
142         .clk_rate = 216000000,
143         .properties = spt_i2c_properties,
144 };
145
146 static const struct pci_device_id intel_lpss_pci_ids[] = {
147         /* BXT A-Step */
148         { PCI_VDEVICE(INTEL, 0x0aac), (kernel_ulong_t)&bxt_i2c_info },
149         { PCI_VDEVICE(INTEL, 0x0aae), (kernel_ulong_t)&bxt_i2c_info },
150         { PCI_VDEVICE(INTEL, 0x0ab0), (kernel_ulong_t)&bxt_i2c_info },
151         { PCI_VDEVICE(INTEL, 0x0ab2), (kernel_ulong_t)&bxt_i2c_info },
152         { PCI_VDEVICE(INTEL, 0x0ab4), (kernel_ulong_t)&bxt_i2c_info },
153         { PCI_VDEVICE(INTEL, 0x0ab6), (kernel_ulong_t)&bxt_i2c_info },
154         { PCI_VDEVICE(INTEL, 0x0ab8), (kernel_ulong_t)&bxt_i2c_info },
155         { PCI_VDEVICE(INTEL, 0x0aba), (kernel_ulong_t)&bxt_i2c_info },
156         { PCI_VDEVICE(INTEL, 0x0abc), (kernel_ulong_t)&bxt_uart_info },
157         { PCI_VDEVICE(INTEL, 0x0abe), (kernel_ulong_t)&bxt_uart_info },
158         { PCI_VDEVICE(INTEL, 0x0ac0), (kernel_ulong_t)&bxt_uart_info },
159         { PCI_VDEVICE(INTEL, 0x0ac2), (kernel_ulong_t)&bxt_info },
160         { PCI_VDEVICE(INTEL, 0x0ac4), (kernel_ulong_t)&bxt_info },
161         { PCI_VDEVICE(INTEL, 0x0ac6), (kernel_ulong_t)&bxt_info },
162         { PCI_VDEVICE(INTEL, 0x0aee), (kernel_ulong_t)&bxt_uart_info },
163         /* BXT B-Step */
164         { PCI_VDEVICE(INTEL, 0x1aac), (kernel_ulong_t)&bxt_i2c_info },
165         { PCI_VDEVICE(INTEL, 0x1aae), (kernel_ulong_t)&bxt_i2c_info },
166         { PCI_VDEVICE(INTEL, 0x1ab0), (kernel_ulong_t)&bxt_i2c_info },
167         { PCI_VDEVICE(INTEL, 0x1ab2), (kernel_ulong_t)&bxt_i2c_info },
168         { PCI_VDEVICE(INTEL, 0x1ab4), (kernel_ulong_t)&bxt_i2c_info },
169         { PCI_VDEVICE(INTEL, 0x1ab6), (kernel_ulong_t)&bxt_i2c_info },
170         { PCI_VDEVICE(INTEL, 0x1ab8), (kernel_ulong_t)&bxt_i2c_info },
171         { PCI_VDEVICE(INTEL, 0x1aba), (kernel_ulong_t)&bxt_i2c_info },
172         { PCI_VDEVICE(INTEL, 0x1abc), (kernel_ulong_t)&bxt_uart_info },
173         { PCI_VDEVICE(INTEL, 0x1abe), (kernel_ulong_t)&bxt_uart_info },
174         { PCI_VDEVICE(INTEL, 0x1ac0), (kernel_ulong_t)&bxt_uart_info },
175         { PCI_VDEVICE(INTEL, 0x1ac2), (kernel_ulong_t)&bxt_info },
176         { PCI_VDEVICE(INTEL, 0x1ac4), (kernel_ulong_t)&bxt_info },
177         { PCI_VDEVICE(INTEL, 0x1ac6), (kernel_ulong_t)&bxt_info },
178         { PCI_VDEVICE(INTEL, 0x1aee), (kernel_ulong_t)&bxt_uart_info },
179         /* EBG */
180         { PCI_VDEVICE(INTEL, 0x1bad), (kernel_ulong_t)&bxt_uart_info },
181         { PCI_VDEVICE(INTEL, 0x1bae), (kernel_ulong_t)&bxt_uart_info },
182         /* GLK */
183         { PCI_VDEVICE(INTEL, 0x31ac), (kernel_ulong_t)&glk_i2c_info },
184         { PCI_VDEVICE(INTEL, 0x31ae), (kernel_ulong_t)&glk_i2c_info },
185         { PCI_VDEVICE(INTEL, 0x31b0), (kernel_ulong_t)&glk_i2c_info },
186         { PCI_VDEVICE(INTEL, 0x31b2), (kernel_ulong_t)&glk_i2c_info },
187         { PCI_VDEVICE(INTEL, 0x31b4), (kernel_ulong_t)&glk_i2c_info },
188         { PCI_VDEVICE(INTEL, 0x31b6), (kernel_ulong_t)&glk_i2c_info },
189         { PCI_VDEVICE(INTEL, 0x31b8), (kernel_ulong_t)&glk_i2c_info },
190         { PCI_VDEVICE(INTEL, 0x31ba), (kernel_ulong_t)&glk_i2c_info },
191         { PCI_VDEVICE(INTEL, 0x31bc), (kernel_ulong_t)&bxt_uart_info },
192         { PCI_VDEVICE(INTEL, 0x31be), (kernel_ulong_t)&bxt_uart_info },
193         { PCI_VDEVICE(INTEL, 0x31c0), (kernel_ulong_t)&bxt_uart_info },
194         { PCI_VDEVICE(INTEL, 0x31ee), (kernel_ulong_t)&bxt_uart_info },
195         { PCI_VDEVICE(INTEL, 0x31c2), (kernel_ulong_t)&bxt_info },
196         { PCI_VDEVICE(INTEL, 0x31c4), (kernel_ulong_t)&bxt_info },
197         { PCI_VDEVICE(INTEL, 0x31c6), (kernel_ulong_t)&bxt_info },
198         /* ICL-LP */
199         { PCI_VDEVICE(INTEL, 0x34a8), (kernel_ulong_t)&spt_uart_info },
200         { PCI_VDEVICE(INTEL, 0x34a9), (kernel_ulong_t)&spt_uart_info },
201         { PCI_VDEVICE(INTEL, 0x34aa), (kernel_ulong_t)&spt_info },
202         { PCI_VDEVICE(INTEL, 0x34ab), (kernel_ulong_t)&spt_info },
203         { PCI_VDEVICE(INTEL, 0x34c5), (kernel_ulong_t)&bxt_i2c_info },
204         { PCI_VDEVICE(INTEL, 0x34c6), (kernel_ulong_t)&bxt_i2c_info },
205         { PCI_VDEVICE(INTEL, 0x34c7), (kernel_ulong_t)&spt_uart_info },
206         { PCI_VDEVICE(INTEL, 0x34e8), (kernel_ulong_t)&bxt_i2c_info },
207         { PCI_VDEVICE(INTEL, 0x34e9), (kernel_ulong_t)&bxt_i2c_info },
208         { PCI_VDEVICE(INTEL, 0x34ea), (kernel_ulong_t)&bxt_i2c_info },
209         { PCI_VDEVICE(INTEL, 0x34eb), (kernel_ulong_t)&bxt_i2c_info },
210         { PCI_VDEVICE(INTEL, 0x34fb), (kernel_ulong_t)&spt_info },
211         /* APL */
212         { PCI_VDEVICE(INTEL, 0x5aac), (kernel_ulong_t)&apl_i2c_info },
213         { PCI_VDEVICE(INTEL, 0x5aae), (kernel_ulong_t)&apl_i2c_info },
214         { PCI_VDEVICE(INTEL, 0x5ab0), (kernel_ulong_t)&apl_i2c_info },
215         { PCI_VDEVICE(INTEL, 0x5ab2), (kernel_ulong_t)&apl_i2c_info },
216         { PCI_VDEVICE(INTEL, 0x5ab4), (kernel_ulong_t)&apl_i2c_info },
217         { PCI_VDEVICE(INTEL, 0x5ab6), (kernel_ulong_t)&apl_i2c_info },
218         { PCI_VDEVICE(INTEL, 0x5ab8), (kernel_ulong_t)&apl_i2c_info },
219         { PCI_VDEVICE(INTEL, 0x5aba), (kernel_ulong_t)&apl_i2c_info },
220         { PCI_VDEVICE(INTEL, 0x5abc), (kernel_ulong_t)&bxt_uart_info },
221         { PCI_VDEVICE(INTEL, 0x5abe), (kernel_ulong_t)&bxt_uart_info },
222         { PCI_VDEVICE(INTEL, 0x5ac0), (kernel_ulong_t)&bxt_uart_info },
223         { PCI_VDEVICE(INTEL, 0x5ac2), (kernel_ulong_t)&bxt_info },
224         { PCI_VDEVICE(INTEL, 0x5ac4), (kernel_ulong_t)&bxt_info },
225         { PCI_VDEVICE(INTEL, 0x5ac6), (kernel_ulong_t)&bxt_info },
226         { PCI_VDEVICE(INTEL, 0x5aee), (kernel_ulong_t)&bxt_uart_info },
227         /* SPT-LP */
228         { PCI_VDEVICE(INTEL, 0x9d27), (kernel_ulong_t)&spt_uart_info },
229         { PCI_VDEVICE(INTEL, 0x9d28), (kernel_ulong_t)&spt_uart_info },
230         { PCI_VDEVICE(INTEL, 0x9d29), (kernel_ulong_t)&spt_info },
231         { PCI_VDEVICE(INTEL, 0x9d2a), (kernel_ulong_t)&spt_info },
232         { PCI_VDEVICE(INTEL, 0x9d60), (kernel_ulong_t)&spt_i2c_info },
233         { PCI_VDEVICE(INTEL, 0x9d61), (kernel_ulong_t)&spt_i2c_info },
234         { PCI_VDEVICE(INTEL, 0x9d62), (kernel_ulong_t)&spt_i2c_info },
235         { PCI_VDEVICE(INTEL, 0x9d63), (kernel_ulong_t)&spt_i2c_info },
236         { PCI_VDEVICE(INTEL, 0x9d64), (kernel_ulong_t)&spt_i2c_info },
237         { PCI_VDEVICE(INTEL, 0x9d65), (kernel_ulong_t)&spt_i2c_info },
238         { PCI_VDEVICE(INTEL, 0x9d66), (kernel_ulong_t)&spt_uart_info },
239         /* CNL-LP */
240         { PCI_VDEVICE(INTEL, 0x9da8), (kernel_ulong_t)&spt_uart_info },
241         { PCI_VDEVICE(INTEL, 0x9da9), (kernel_ulong_t)&spt_uart_info },
242         { PCI_VDEVICE(INTEL, 0x9daa), (kernel_ulong_t)&spt_info },
243         { PCI_VDEVICE(INTEL, 0x9dab), (kernel_ulong_t)&spt_info },
244         { PCI_VDEVICE(INTEL, 0x9dfb), (kernel_ulong_t)&spt_info },
245         { PCI_VDEVICE(INTEL, 0x9dc5), (kernel_ulong_t)&cnl_i2c_info },
246         { PCI_VDEVICE(INTEL, 0x9dc6), (kernel_ulong_t)&cnl_i2c_info },
247         { PCI_VDEVICE(INTEL, 0x9dc7), (kernel_ulong_t)&spt_uart_info },
248         { PCI_VDEVICE(INTEL, 0x9de8), (kernel_ulong_t)&cnl_i2c_info },
249         { PCI_VDEVICE(INTEL, 0x9de9), (kernel_ulong_t)&cnl_i2c_info },
250         { PCI_VDEVICE(INTEL, 0x9dea), (kernel_ulong_t)&cnl_i2c_info },
251         { PCI_VDEVICE(INTEL, 0x9deb), (kernel_ulong_t)&cnl_i2c_info },
252         /* SPT-H */
253         { PCI_VDEVICE(INTEL, 0xa127), (kernel_ulong_t)&spt_uart_info },
254         { PCI_VDEVICE(INTEL, 0xa128), (kernel_ulong_t)&spt_uart_info },
255         { PCI_VDEVICE(INTEL, 0xa129), (kernel_ulong_t)&spt_info },
256         { PCI_VDEVICE(INTEL, 0xa12a), (kernel_ulong_t)&spt_info },
257         { PCI_VDEVICE(INTEL, 0xa160), (kernel_ulong_t)&spt_i2c_info },
258         { PCI_VDEVICE(INTEL, 0xa161), (kernel_ulong_t)&spt_i2c_info },
259         { PCI_VDEVICE(INTEL, 0xa162), (kernel_ulong_t)&spt_i2c_info },
260         { PCI_VDEVICE(INTEL, 0xa166), (kernel_ulong_t)&spt_uart_info },
261         /* KBL-H */
262         { PCI_VDEVICE(INTEL, 0xa2a7), (kernel_ulong_t)&spt_uart_info },
263         { PCI_VDEVICE(INTEL, 0xa2a8), (kernel_ulong_t)&spt_uart_info },
264         { PCI_VDEVICE(INTEL, 0xa2a9), (kernel_ulong_t)&spt_info },
265         { PCI_VDEVICE(INTEL, 0xa2aa), (kernel_ulong_t)&spt_info },
266         { PCI_VDEVICE(INTEL, 0xa2e0), (kernel_ulong_t)&spt_i2c_info },
267         { PCI_VDEVICE(INTEL, 0xa2e1), (kernel_ulong_t)&spt_i2c_info },
268         { PCI_VDEVICE(INTEL, 0xa2e2), (kernel_ulong_t)&spt_i2c_info },
269         { PCI_VDEVICE(INTEL, 0xa2e3), (kernel_ulong_t)&spt_i2c_info },
270         { PCI_VDEVICE(INTEL, 0xa2e6), (kernel_ulong_t)&spt_uart_info },
271         /* CNL-H */
272         { PCI_VDEVICE(INTEL, 0xa328), (kernel_ulong_t)&spt_uart_info },
273         { PCI_VDEVICE(INTEL, 0xa329), (kernel_ulong_t)&spt_uart_info },
274         { PCI_VDEVICE(INTEL, 0xa32a), (kernel_ulong_t)&spt_info },
275         { PCI_VDEVICE(INTEL, 0xa32b), (kernel_ulong_t)&spt_info },
276         { PCI_VDEVICE(INTEL, 0xa37b), (kernel_ulong_t)&spt_info },
277         { PCI_VDEVICE(INTEL, 0xa347), (kernel_ulong_t)&spt_uart_info },
278         { PCI_VDEVICE(INTEL, 0xa368), (kernel_ulong_t)&cnl_i2c_info },
279         { PCI_VDEVICE(INTEL, 0xa369), (kernel_ulong_t)&cnl_i2c_info },
280         { PCI_VDEVICE(INTEL, 0xa36a), (kernel_ulong_t)&cnl_i2c_info },
281         { PCI_VDEVICE(INTEL, 0xa36b), (kernel_ulong_t)&cnl_i2c_info },
282         { }
283 };
284 MODULE_DEVICE_TABLE(pci, intel_lpss_pci_ids);
285
286 static struct pci_driver intel_lpss_pci_driver = {
287         .name = "intel-lpss",
288         .id_table = intel_lpss_pci_ids,
289         .probe = intel_lpss_pci_probe,
290         .remove = intel_lpss_pci_remove,
291         .driver = {
292                 .pm = &intel_lpss_pci_pm_ops,
293         },
294 };
295
296 module_pci_driver(intel_lpss_pci_driver);
297
298 MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
299 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
300 MODULE_DESCRIPTION("Intel LPSS PCI driver");
301 MODULE_LICENSE("GPL v2");