]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/pwm/pwm-lpss-pci.c
073dfb2337e0a471e9f25f01786d096de3bf70ed
[karo-tx-linux.git] / drivers / pwm / pwm-lpss-pci.c
1 /*
2  * Intel Low Power Subsystem PWM controller PCI driver
3  *
4  * Copyright (C) 2014, Intel Corporation
5  *
6  * Derived from the original pwm-lpss.c
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/pm_runtime.h>
17
18 #include "pwm-lpss.h"
19
20 /* BayTrail */
21 static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
22         .clk_rate = 25000000,
23         .npwm = 1,
24         .base_unit_bits = 16,
25 };
26
27 /* Braswell */
28 static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
29         .clk_rate = 19200000,
30         .npwm = 1,
31         .base_unit_bits = 16,
32 };
33
34 /* Broxton */
35 static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
36         .clk_rate = 19200000,
37         .npwm = 4,
38         .base_unit_bits = 22,
39 };
40
41 /* Tangier */
42 static const struct pwm_lpss_boardinfo pwm_lpss_tng_info = {
43         .clk_rate = 19200000,
44         .npwm = 4,
45         .base_unit_bits = 22,
46 };
47
48 static int pwm_lpss_probe_pci(struct pci_dev *pdev,
49                               const struct pci_device_id *id)
50 {
51         const struct pwm_lpss_boardinfo *info;
52         struct pwm_lpss_chip *lpwm;
53         int err;
54
55         err = pcim_enable_device(pdev);
56         if (err < 0)
57                 return err;
58
59         info = (struct pwm_lpss_boardinfo *)id->driver_data;
60         lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info);
61         if (IS_ERR(lpwm))
62                 return PTR_ERR(lpwm);
63
64         pci_set_drvdata(pdev, lpwm);
65
66         pm_runtime_put(&pdev->dev);
67         pm_runtime_allow(&pdev->dev);
68
69         return 0;
70 }
71
72 static void pwm_lpss_remove_pci(struct pci_dev *pdev)
73 {
74         struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev);
75
76         pm_runtime_forbid(&pdev->dev);
77         pm_runtime_get_sync(&pdev->dev);
78
79         pwm_lpss_remove(lpwm);
80 }
81
82 #ifdef CONFIG_PM
83 static int pwm_lpss_runtime_suspend_pci(struct device *dev)
84 {
85         /*
86          * The PCI core will handle transition to D3 automatically. We only
87          * need to provide runtime PM hooks for that to happen.
88          */
89         return 0;
90 }
91
92 static int pwm_lpss_runtime_resume_pci(struct device *dev)
93 {
94         return 0;
95 }
96 #endif
97
98 static const struct dev_pm_ops pwm_lpss_pci_pm = {
99         SET_RUNTIME_PM_OPS(pwm_lpss_runtime_suspend_pci,
100                            pwm_lpss_runtime_resume_pci, NULL)
101 };
102
103 static const struct pci_device_id pwm_lpss_pci_ids[] = {
104         { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info},
105         { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info},
106         { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info},
107         { PCI_VDEVICE(INTEL, 0x11a5), (unsigned long)&pwm_lpss_tng_info},
108         { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info},
109         { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info},
110         { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info},
111         { PCI_VDEVICE(INTEL, 0x31c8), (unsigned long)&pwm_lpss_bxt_info},
112         { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info},
113         { },
114 };
115 MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids);
116
117 static struct pci_driver pwm_lpss_driver_pci = {
118         .name = "pwm-lpss",
119         .id_table = pwm_lpss_pci_ids,
120         .probe = pwm_lpss_probe_pci,
121         .remove = pwm_lpss_remove_pci,
122         .driver = {
123                 .pm = &pwm_lpss_pci_pm,
124         },
125 };
126 module_pci_driver(pwm_lpss_driver_pci);
127
128 MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
129 MODULE_LICENSE("GPL v2");