diff options
Diffstat (limited to 'drivers/pwm/pwm-lpss.c')
-rw-r--r-- | drivers/pwm/pwm-lpss.c | 136 |
1 files changed, 10 insertions, 126 deletions
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c index d04eee7aa967..ce9bf147811f 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c | |||
@@ -13,15 +13,10 @@ | |||
13 | * published by the Free Software Foundation. | 13 | * published by the Free Software Foundation. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/acpi.h> | ||
17 | #include <linux/device.h> | ||
18 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
19 | #include <linux/module.h> | 17 | #include <linux/module.h> |
20 | #include <linux/pwm.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/pci.h> | ||
23 | 18 | ||
24 | static int pci_drv, plat_drv; /* So we know which drivers registered */ | 19 | #include "pwm-lpss.h" |
25 | 20 | ||
26 | #define PWM 0x00000000 | 21 | #define PWM 0x00000000 |
27 | #define PWM_ENABLE BIT(31) | 22 | #define PWM_ENABLE BIT(31) |
@@ -39,19 +34,17 @@ struct pwm_lpss_chip { | |||
39 | unsigned long clk_rate; | 34 | unsigned long clk_rate; |
40 | }; | 35 | }; |
41 | 36 | ||
42 | struct pwm_lpss_boardinfo { | ||
43 | unsigned long clk_rate; | ||
44 | }; | ||
45 | |||
46 | /* BayTrail */ | 37 | /* BayTrail */ |
47 | static const struct pwm_lpss_boardinfo byt_info = { | 38 | const struct pwm_lpss_boardinfo pwm_lpss_byt_info = { |
48 | 25000000 | 39 | 25000000 |
49 | }; | 40 | }; |
41 | EXPORT_SYMBOL_GPL(pwm_lpss_byt_info); | ||
50 | 42 | ||
51 | /* Braswell */ | 43 | /* Braswell */ |
52 | static const struct pwm_lpss_boardinfo bsw_info = { | 44 | const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = { |
53 | 19200000 | 45 | 19200000 |
54 | }; | 46 | }; |
47 | EXPORT_SYMBOL_GPL(pwm_lpss_bsw_info); | ||
55 | 48 | ||
56 | static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip) | 49 | static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip) |
57 | { | 50 | { |
@@ -123,9 +116,8 @@ static const struct pwm_ops pwm_lpss_ops = { | |||
123 | .owner = THIS_MODULE, | 116 | .owner = THIS_MODULE, |
124 | }; | 117 | }; |
125 | 118 | ||
126 | static struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, | 119 | struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r, |
127 | struct resource *r, | 120 | const struct pwm_lpss_boardinfo *info) |
128 | const struct pwm_lpss_boardinfo *info) | ||
129 | { | 121 | { |
130 | struct pwm_lpss_chip *lpwm; | 122 | struct pwm_lpss_chip *lpwm; |
131 | int ret; | 123 | int ret; |
@@ -152,8 +144,9 @@ static struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, | |||
152 | 144 | ||
153 | return lpwm; | 145 | return lpwm; |
154 | } | 146 | } |
147 | EXPORT_SYMBOL_GPL(pwm_lpss_probe); | ||
155 | 148 | ||
156 | static int pwm_lpss_remove(struct pwm_lpss_chip *lpwm) | 149 | int pwm_lpss_remove(struct pwm_lpss_chip *lpwm) |
157 | { | 150 | { |
158 | u32 ctrl; | 151 | u32 ctrl; |
159 | 152 | ||
@@ -162,117 +155,8 @@ static int pwm_lpss_remove(struct pwm_lpss_chip *lpwm) | |||
162 | 155 | ||
163 | return pwmchip_remove(&lpwm->chip); | 156 | return pwmchip_remove(&lpwm->chip); |
164 | } | 157 | } |
165 | 158 | EXPORT_SYMBOL_GPL(pwm_lpss_remove); | |
166 | static int pwm_lpss_probe_pci(struct pci_dev *pdev, | ||
167 | const struct pci_device_id *id) | ||
168 | { | ||
169 | const struct pwm_lpss_boardinfo *info; | ||
170 | struct pwm_lpss_chip *lpwm; | ||
171 | int err; | ||
172 | |||
173 | err = pci_enable_device(pdev); | ||
174 | if (err < 0) | ||
175 | return err; | ||
176 | |||
177 | info = (struct pwm_lpss_boardinfo *)id->driver_data; | ||
178 | lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info); | ||
179 | if (IS_ERR(lpwm)) | ||
180 | return PTR_ERR(lpwm); | ||
181 | |||
182 | pci_set_drvdata(pdev, lpwm); | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static void pwm_lpss_remove_pci(struct pci_dev *pdev) | ||
187 | { | ||
188 | struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev); | ||
189 | |||
190 | pwm_lpss_remove(lpwm); | ||
191 | pci_disable_device(pdev); | ||
192 | } | ||
193 | |||
194 | static struct pci_device_id pwm_lpss_pci_ids[] = { | ||
195 | { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&byt_info}, | ||
196 | { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&byt_info}, | ||
197 | { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&bsw_info}, | ||
198 | { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&bsw_info}, | ||
199 | { }, | ||
200 | }; | ||
201 | MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids); | ||
202 | |||
203 | static struct pci_driver pwm_lpss_driver_pci = { | ||
204 | .name = "pwm-lpss", | ||
205 | .id_table = pwm_lpss_pci_ids, | ||
206 | .probe = pwm_lpss_probe_pci, | ||
207 | .remove = pwm_lpss_remove_pci, | ||
208 | }; | ||
209 | |||
210 | static int pwm_lpss_probe_platform(struct platform_device *pdev) | ||
211 | { | ||
212 | const struct pwm_lpss_boardinfo *info; | ||
213 | const struct acpi_device_id *id; | ||
214 | struct pwm_lpss_chip *lpwm; | ||
215 | struct resource *r; | ||
216 | |||
217 | id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); | ||
218 | if (!id) | ||
219 | return -ENODEV; | ||
220 | |||
221 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
222 | |||
223 | info = (struct pwm_lpss_boardinfo *)id->driver_data; | ||
224 | lpwm = pwm_lpss_probe(&pdev->dev, r, info); | ||
225 | if (IS_ERR(lpwm)) | ||
226 | return PTR_ERR(lpwm); | ||
227 | |||
228 | platform_set_drvdata(pdev, lpwm); | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static int pwm_lpss_remove_platform(struct platform_device *pdev) | ||
233 | { | ||
234 | struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev); | ||
235 | |||
236 | return pwm_lpss_remove(lpwm); | ||
237 | } | ||
238 | |||
239 | static const struct acpi_device_id pwm_lpss_acpi_match[] = { | ||
240 | { "80860F09", (unsigned long)&byt_info }, | ||
241 | { "80862288", (unsigned long)&bsw_info }, | ||
242 | { }, | ||
243 | }; | ||
244 | MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match); | ||
245 | |||
246 | static struct platform_driver pwm_lpss_driver_platform = { | ||
247 | .driver = { | ||
248 | .name = "pwm-lpss", | ||
249 | .acpi_match_table = pwm_lpss_acpi_match, | ||
250 | }, | ||
251 | .probe = pwm_lpss_probe_platform, | ||
252 | .remove = pwm_lpss_remove_platform, | ||
253 | }; | ||
254 | |||
255 | static int __init pwm_init(void) | ||
256 | { | ||
257 | pci_drv = pci_register_driver(&pwm_lpss_driver_pci); | ||
258 | plat_drv = platform_driver_register(&pwm_lpss_driver_platform); | ||
259 | if (pci_drv && plat_drv) | ||
260 | return pci_drv; | ||
261 | |||
262 | return 0; | ||
263 | } | ||
264 | module_init(pwm_init); | ||
265 | |||
266 | static void __exit pwm_exit(void) | ||
267 | { | ||
268 | if (!pci_drv) | ||
269 | pci_unregister_driver(&pwm_lpss_driver_pci); | ||
270 | if (!plat_drv) | ||
271 | platform_driver_unregister(&pwm_lpss_driver_platform); | ||
272 | } | ||
273 | module_exit(pwm_exit); | ||
274 | 159 | ||
275 | MODULE_DESCRIPTION("PWM driver for Intel LPSS"); | 160 | MODULE_DESCRIPTION("PWM driver for Intel LPSS"); |
276 | MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); | 161 | MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); |
277 | MODULE_LICENSE("GPL v2"); | 162 | MODULE_LICENSE("GPL v2"); |
278 | MODULE_ALIAS("platform:pwm-lpss"); | ||