1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | /* |
3 | * Intel Low Power Subsystem PWM controller PCI driver |
4 | * |
5 | * Copyright (C) 2014, Intel Corporation |
6 | * |
7 | * Derived from the original pwm-lpss.c |
8 | */ |
9 | |
10 | #include <linux/kernel.h> |
11 | #include <linux/module.h> |
12 | #include <linux/pci.h> |
13 | #include <linux/pm_runtime.h> |
14 | |
15 | #include "pwm-lpss.h" |
16 | |
17 | static int pwm_lpss_probe_pci(struct pci_dev *pdev, |
18 | const struct pci_device_id *id) |
19 | { |
20 | const struct pwm_lpss_boardinfo *info; |
21 | struct pwm_chip *chip; |
22 | int err; |
23 | |
24 | err = pcim_enable_device(pdev); |
25 | if (err < 0) |
26 | return err; |
27 | |
28 | err = pcim_iomap_regions(pdev, BIT(0), name: pci_name(pdev)); |
29 | if (err) |
30 | return err; |
31 | |
32 | info = (struct pwm_lpss_boardinfo *)id->driver_data; |
33 | chip = devm_pwm_lpss_probe(dev: &pdev->dev, base: pcim_iomap_table(pdev)[0], info); |
34 | if (IS_ERR(ptr: chip)) |
35 | return PTR_ERR(ptr: chip); |
36 | |
37 | pm_runtime_put(dev: &pdev->dev); |
38 | pm_runtime_allow(dev: &pdev->dev); |
39 | |
40 | return 0; |
41 | } |
42 | |
43 | static void pwm_lpss_remove_pci(struct pci_dev *pdev) |
44 | { |
45 | pm_runtime_forbid(dev: &pdev->dev); |
46 | pm_runtime_get_sync(dev: &pdev->dev); |
47 | } |
48 | |
49 | static int pwm_lpss_runtime_suspend_pci(struct device *dev) |
50 | { |
51 | /* |
52 | * The PCI core will handle transition to D3 automatically. We only |
53 | * need to provide runtime PM hooks for that to happen. |
54 | */ |
55 | return 0; |
56 | } |
57 | |
58 | static int pwm_lpss_runtime_resume_pci(struct device *dev) |
59 | { |
60 | return 0; |
61 | } |
62 | |
63 | static DEFINE_RUNTIME_DEV_PM_OPS(pwm_lpss_pci_pm, |
64 | pwm_lpss_runtime_suspend_pci, |
65 | pwm_lpss_runtime_resume_pci, |
66 | NULL); |
67 | |
68 | static const struct pci_device_id pwm_lpss_pci_ids[] = { |
69 | { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info}, |
70 | { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info}, |
71 | { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info}, |
72 | { PCI_VDEVICE(INTEL, 0x11a5), (unsigned long)&pwm_lpss_tng_info}, |
73 | { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info}, |
74 | { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info}, |
75 | { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info}, |
76 | { PCI_VDEVICE(INTEL, 0x31c8), (unsigned long)&pwm_lpss_bxt_info}, |
77 | { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info}, |
78 | { }, |
79 | }; |
80 | MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids); |
81 | |
82 | static struct pci_driver pwm_lpss_driver_pci = { |
83 | .name = "pwm-lpss" , |
84 | .id_table = pwm_lpss_pci_ids, |
85 | .probe = pwm_lpss_probe_pci, |
86 | .remove = pwm_lpss_remove_pci, |
87 | .driver = { |
88 | .pm = pm_ptr(&pwm_lpss_pci_pm), |
89 | }, |
90 | }; |
91 | module_pci_driver(pwm_lpss_driver_pci); |
92 | |
93 | MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS" ); |
94 | MODULE_LICENSE("GPL v2" ); |
95 | MODULE_IMPORT_NS(PWM_LPSS); |
96 | |