blob: 7160e8ab38a4ea83f7cd01b21f58b6309b0859fc [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
20static int pwm_lpss_probe_pci(struct pci_dev *pdev,
21 const struct pci_device_id *id)
22{
23 const struct pwm_lpss_boardinfo *info;
24 struct pwm_lpss_chip *lpwm;
25 int err;
26
Andy Shevchenko90927fe2014-08-19 19:17:36 +030027 err = pcim_enable_device(pdev);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030028 if (err < 0)
29 return err;
30
31 info = (struct pwm_lpss_boardinfo *)id->driver_data;
32 lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info);
33 if (IS_ERR(lpwm))
34 return PTR_ERR(lpwm);
35
36 pci_set_drvdata(pdev, lpwm);
Qipeng Zhaf080be22015-10-26 12:58:27 +020037
38 pm_runtime_put(&pdev->dev);
39 pm_runtime_allow(&pdev->dev);
40
Andy Shevchenkoc558e392014-08-19 19:17:35 +030041 return 0;
42}
43
44static void pwm_lpss_remove_pci(struct pci_dev *pdev)
45{
46 struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev);
47
Qipeng Zhaf080be22015-10-26 12:58:27 +020048 pm_runtime_forbid(&pdev->dev);
49 pm_runtime_get_sync(&pdev->dev);
50
Andy Shevchenkoc558e392014-08-19 19:17:35 +030051 pwm_lpss_remove(lpwm);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030052}
53
Qipeng Zhaf080be22015-10-26 12:58:27 +020054#ifdef CONFIG_PM
55static int pwm_lpss_runtime_suspend_pci(struct device *dev)
56{
57 /*
58 * The PCI core will handle transition to D3 automatically. We only
59 * need to provide runtime PM hooks for that to happen.
60 */
61 return 0;
62}
63
64static int pwm_lpss_runtime_resume_pci(struct device *dev)
65{
66 return 0;
67}
68#endif
69
70static const struct dev_pm_ops pwm_lpss_pci_pm = {
71 SET_RUNTIME_PM_OPS(pwm_lpss_runtime_suspend_pci,
72 pwm_lpss_runtime_resume_pci, NULL)
73};
74
Andy Shevchenkoc558e392014-08-19 19:17:35 +030075static const struct pci_device_id pwm_lpss_pci_ids[] = {
Mika Westerberg87219cb2015-10-20 16:53:06 +030076 { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info},
Andy Shevchenkoc558e392014-08-19 19:17:35 +030077 { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info},
78 { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info},
Mika Westerberg87219cb2015-10-20 16:53:06 +030079 { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info},
Andy Shevchenkoc558e392014-08-19 19:17:35 +030080 { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info},
81 { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info},
Mika Westerberg03f00e52015-10-20 16:53:07 +030082 { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info},
Andy Shevchenkoc558e392014-08-19 19:17:35 +030083 { },
84};
85MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids);
86
87static struct pci_driver pwm_lpss_driver_pci = {
88 .name = "pwm-lpss",
89 .id_table = pwm_lpss_pci_ids,
90 .probe = pwm_lpss_probe_pci,
91 .remove = pwm_lpss_remove_pci,
Qipeng Zhaf080be22015-10-26 12:58:27 +020092 .driver = {
93 .pm = &pwm_lpss_pci_pm,
94 },
Andy Shevchenkoc558e392014-08-19 19:17:35 +030095};
96module_pci_driver(pwm_lpss_driver_pci);
97
98MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS");
99MODULE_LICENSE("GPL v2");