Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 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> |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 17 | |
| 18 | #include "pwm-lpss.h" |
| 19 | |
Andy Shevchenko | 9900073 | 2017-01-28 17:10:43 +0200 | [diff] [blame] | 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, |
Hans de Goede | b997e3e | 2017-04-06 14:54:01 +0300 | [diff] [blame] | 39 | .bypass = true, |
Andy Shevchenko | 9900073 | 2017-01-28 17:10:43 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Andy Shevchenko | 3c1460e | 2017-04-06 14:54:00 +0300 | [diff] [blame] | 42 | /* Tangier */ |
| 43 | static const struct pwm_lpss_boardinfo pwm_lpss_tng_info = { |
| 44 | .clk_rate = 19200000, |
| 45 | .npwm = 4, |
| 46 | .base_unit_bits = 22, |
| 47 | }; |
| 48 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 49 | static int pwm_lpss_probe_pci(struct pci_dev *pdev, |
| 50 | const struct pci_device_id *id) |
| 51 | { |
| 52 | const struct pwm_lpss_boardinfo *info; |
| 53 | struct pwm_lpss_chip *lpwm; |
| 54 | int err; |
| 55 | |
Andy Shevchenko | 90927fe | 2014-08-19 19:17:36 +0300 | [diff] [blame] | 56 | err = pcim_enable_device(pdev); |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 57 | if (err < 0) |
| 58 | return err; |
| 59 | |
| 60 | info = (struct pwm_lpss_boardinfo *)id->driver_data; |
| 61 | lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info); |
| 62 | if (IS_ERR(lpwm)) |
| 63 | return PTR_ERR(lpwm); |
| 64 | |
| 65 | pci_set_drvdata(pdev, lpwm); |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 66 | |
| 67 | pm_runtime_put(&pdev->dev); |
| 68 | pm_runtime_allow(&pdev->dev); |
| 69 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static void pwm_lpss_remove_pci(struct pci_dev *pdev) |
| 74 | { |
| 75 | struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev); |
| 76 | |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 77 | pm_runtime_forbid(&pdev->dev); |
| 78 | pm_runtime_get_sync(&pdev->dev); |
| 79 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 80 | pwm_lpss_remove(lpwm); |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 81 | } |
| 82 | |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_PM |
| 84 | static int pwm_lpss_runtime_suspend_pci(struct device *dev) |
| 85 | { |
| 86 | /* |
| 87 | * The PCI core will handle transition to D3 automatically. We only |
| 88 | * need to provide runtime PM hooks for that to happen. |
| 89 | */ |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static int pwm_lpss_runtime_resume_pci(struct device *dev) |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | static const struct dev_pm_ops pwm_lpss_pci_pm = { |
| 100 | SET_RUNTIME_PM_OPS(pwm_lpss_runtime_suspend_pci, |
| 101 | pwm_lpss_runtime_resume_pci, NULL) |
| 102 | }; |
| 103 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 104 | static const struct pci_device_id pwm_lpss_pci_ids[] = { |
Mika Westerberg | 87219cb | 2015-10-20 16:53:06 +0300 | [diff] [blame] | 105 | { PCI_VDEVICE(INTEL, 0x0ac8), (unsigned long)&pwm_lpss_bxt_info}, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 106 | { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&pwm_lpss_byt_info}, |
| 107 | { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&pwm_lpss_byt_info}, |
Andy Shevchenko | 3c1460e | 2017-04-06 14:54:00 +0300 | [diff] [blame] | 108 | { PCI_VDEVICE(INTEL, 0x11a5), (unsigned long)&pwm_lpss_tng_info}, |
Mika Westerberg | 87219cb | 2015-10-20 16:53:06 +0300 | [diff] [blame] | 109 | { PCI_VDEVICE(INTEL, 0x1ac8), (unsigned long)&pwm_lpss_bxt_info}, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 110 | { PCI_VDEVICE(INTEL, 0x2288), (unsigned long)&pwm_lpss_bsw_info}, |
| 111 | { PCI_VDEVICE(INTEL, 0x2289), (unsigned long)&pwm_lpss_bsw_info}, |
Mika Westerberg | ae25205 | 2017-01-28 17:10:44 +0200 | [diff] [blame] | 112 | { PCI_VDEVICE(INTEL, 0x31c8), (unsigned long)&pwm_lpss_bxt_info}, |
Mika Westerberg | 03f00e5 | 2015-10-20 16:53:07 +0300 | [diff] [blame] | 113 | { PCI_VDEVICE(INTEL, 0x5ac8), (unsigned long)&pwm_lpss_bxt_info}, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 114 | { }, |
| 115 | }; |
| 116 | MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids); |
| 117 | |
| 118 | static struct pci_driver pwm_lpss_driver_pci = { |
| 119 | .name = "pwm-lpss", |
| 120 | .id_table = pwm_lpss_pci_ids, |
| 121 | .probe = pwm_lpss_probe_pci, |
| 122 | .remove = pwm_lpss_remove_pci, |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 123 | .driver = { |
| 124 | .pm = &pwm_lpss_pci_pm, |
| 125 | }, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 126 | }; |
| 127 | module_pci_driver(pwm_lpss_driver_pci); |
| 128 | |
| 129 | MODULE_DESCRIPTION("PWM PCI driver for Intel LPSS"); |
| 130 | MODULE_LICENSE("GPL v2"); |