blob: 053088b9b66edb4c50c3b47c5e942b6e2e343c00 [file] [log] [blame]
Andy Shevchenkoc558e392014-08-19 19:17:35 +03001/*
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>
Qipeng Zhaf080be22015-10-26 12:58:27 +020016#include <linux/pm_runtime.h>
Andy Shevchenkoc558e392014-08-19 19:17:35 +030017
18#include "pwm-lpss.h"
19
Andy Shevchenko99000732017-01-28 17:10:43 +020020/* BayTrail */
21static 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 */
28static 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 */
35static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
36 .clk_rate = 19200000,
37 .npwm = 4,
38 .base_unit_bits = 22,
39};
40
Andy Shevchenkoc558e392014-08-19 19:17:35 +030041static int pwm_lpss_probe_pci(struct pci_dev *pdev,
42 const struct pci_device_id *id)
43{
44 const struct pwm_lpss_boardinfo *info;
45 struct pwm_lpss_chip *lpwm;
46 int err;
47
Andy Shevchenko90927fe2014-08-19 19:17:36 +030048 err = pcim_enable_device(pdev);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030049 if (err < 0)
50 return err;
51
52 info = (struct pwm_lpss_boardinfo *)id->driver_data;
53 lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info);
54 if (IS_ERR(lpwm))
55 return PTR_ERR(lpwm);
56
57 pci_set_drvdata(pdev, lpwm);
Qipeng Zhaf080be22015-10-26 12:58:27 +020058
59 pm_runtime_put(&pdev->dev);
60 pm_runtime_allow(&pdev->dev);
61
Andy Shevchenkoc558e392014-08-19 19:17:35 +030062 return 0;
63}
64
65static void pwm_lpss_remove_pci(struct pci_dev *pdev)
66{
67 struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev);
68
Qipeng Zhaf080be22015-10-26 12:58:27 +020069 pm_runtime_forbid(&pdev->dev);
70 pm_runtime_get_sync(&pdev->dev);
71
Andy Shevchenkoc558e392014-08-19 19:17:35 +030072 pwm_lpss_remove(lpwm);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030073}
74
Qipeng Zhaf080be22015-10-26 12:58:27 +020075#ifdef CONFIG_PM
76static int pwm_lpss_runtime_suspend_pci(struct device *dev)
77{
78 /*
79 * The PCI core will handle transition to D3 automatically. We only
80 * need to provide runtime PM hooks for that to happen.
81 */
82 return 0;
83}
84
85static int pwm_lpss_runtime_resume_pci(struct device *dev)
86{
87 return 0;
88}
89#endif
90
91static const struct dev_pm_ops pwm_lpss_pci_pm = {
92 SET_RUNTIME_PM_OPS(pwm_lpss_runtime_suspend_pci,
93 pwm_lpss_runtime_resume_pci, NULL)
94};
95
Andy Shevchenkoc558e392014-08-19 19:17:35 +030096static const struct pci_device_id pwm_lpss_pci_ids[] = {
Mika Westerberg87219cb2015-10-20 16:53:06 +030097 { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info},
Andy Shevchenkoc558e392014-08-19 19:17:35 +030098 { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info},
99 { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info},
Andy Shevchenkob89b4b72016-06-13 21:52:19 +0300100 { PCI_VDEVICE(INTEL, 0x11a5), (unsigned long)&pwm_lpss_bxt_info},
Mika Westerberg87219cb2015-10-20 16:53:06 +0300101 { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info},
Andy Shevchenkoc558e392014-08-19 19:17:35 +0300102 { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info},
103 { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info},
Mika Westerbergae2520542017-01-28 17:10:44 +0200104 { PCI_VDEVICE(INTEL, 0x31c8), (unsigned long)&pwm_lpss_bxt_info},
Mika Westerberg03f00e52015-10-20 16:53:07 +0300105 { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info},
Andy Shevchenkoc558e392014-08-19 19:17:35 +0300106 { },
107};
108MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids);
109
110static struct pci_driver pwm_lpss_driver_pci = {
111 .name = "pwm-lpss",
112 .id_table = pwm_lpss_pci_ids,
113 .probe = pwm_lpss_probe_pci,
114 .remove = pwm_lpss_remove_pci,
Qipeng Zhaf080be22015-10-26 12:58:27 +0200115 .driver = {
116 .pm = &pwm_lpss_pci_pm,
117 },
Andy Shevchenkoc558e392014-08-19 19:17:35 +0300118};
119module_pci_driver(pwm_lpss_driver_pci);
120
121MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
122MODULE_LICENSE("GPL v2");