Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Intel Low Power Subsystem PWM controller driver |
| 4 | * |
| 5 | * Copyright (C) 2014, Intel Corporation |
| 6 | * |
| 7 | * Derived from the original pwm-lpss.c |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 8 | */ |
| 9 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 10 | #include <linux/kernel.h> |
Andy Shevchenko | 7f8dd16 | 2022-09-27 19:24:18 +0300 | [diff] [blame] | 11 | #include <linux/mod_devicetable.h> |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/platform_device.h> |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 14 | #include <linux/pm_runtime.h> |
Andy Shevchenko | 7f8dd16 | 2022-09-27 19:24:18 +0300 | [diff] [blame] | 15 | #include <linux/property.h> |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 16 | |
| 17 | #include "pwm-lpss.h" |
| 18 | |
Andy Shevchenko | 9900073 | 2017-01-28 17:10:43 +0200 | [diff] [blame] | 19 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 20 | static int pwm_lpss_probe_platform(struct platform_device *pdev) |
| 21 | { |
| 22 | const struct pwm_lpss_boardinfo *info; |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 23 | struct pwm_lpss_chip *lpwm; |
Andy Shevchenko | 68af6fb | 2022-09-27 19:24:17 +0300 | [diff] [blame] | 24 | void __iomem *base; |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 25 | |
Andy Shevchenko | 7f8dd16 | 2022-09-27 19:24:18 +0300 | [diff] [blame] | 26 | info = device_get_match_data(&pdev->dev); |
| 27 | if (!info) |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 28 | return -ENODEV; |
| 29 | |
Andy Shevchenko | 68af6fb | 2022-09-27 19:24:17 +0300 | [diff] [blame] | 30 | base = devm_platform_ioremap_resource(pdev, 0); |
| 31 | if (IS_ERR(base)) |
| 32 | return PTR_ERR(base); |
| 33 | |
Andy Shevchenko | f0f31de | 2022-11-17 13:08:04 +0200 | [diff] [blame] | 34 | lpwm = devm_pwm_lpss_probe(&pdev->dev, base, info); |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 35 | if (IS_ERR(lpwm)) |
| 36 | return PTR_ERR(lpwm); |
| 37 | |
| 38 | platform_set_drvdata(pdev, lpwm); |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 39 | |
Hans de Goede | b9c90f1 | 2020-11-09 11:57:25 +0100 | [diff] [blame] | 40 | /* |
| 41 | * On Cherry Trail devices the GFX0._PS0 AML checks if the controller |
| 42 | * is on and if it is not on it turns it on and restores what it |
| 43 | * believes is the correct state to the PWM controller. |
| 44 | * Because of this we must disallow direct-complete, which keeps the |
| 45 | * controller (runtime)suspended on resume, to avoid 2 issues: |
| 46 | * 1. The controller getting turned on without the linux-pm code |
| 47 | * knowing about this. On devices where the controller is unused |
| 48 | * this causes it to stay on during the next suspend causing high |
| 49 | * battery drain (because S0i3 is not reached) |
| 50 | * 2. The state restoring code unexpectedly messing with the controller |
Hans de Goede | e3aa45f2 | 2020-11-09 11:57:26 +0100 | [diff] [blame] | 51 | * |
| 52 | * Leaving the controller runtime-suspended (skipping runtime-resume + |
| 53 | * normal-suspend) during suspend is fine. |
Hans de Goede | b9c90f1 | 2020-11-09 11:57:25 +0100 | [diff] [blame] | 54 | */ |
| 55 | if (info->other_devices_aml_touches_pwm_regs) |
Hans de Goede | e3aa45f2 | 2020-11-09 11:57:26 +0100 | [diff] [blame] | 56 | dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE| |
| 57 | DPM_FLAG_SMART_SUSPEND); |
Hans de Goede | b9c90f1 | 2020-11-09 11:57:25 +0100 | [diff] [blame] | 58 | |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 59 | pm_runtime_set_active(&pdev->dev); |
| 60 | pm_runtime_enable(&pdev->dev); |
| 61 | |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
Uwe Kleine-König | 9a9174e | 2023-03-03 19:54:29 +0100 | [diff] [blame] | 65 | static void pwm_lpss_remove_platform(struct platform_device *pdev) |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 66 | { |
Qipeng Zha | f080be2 | 2015-10-26 12:58:27 +0200 | [diff] [blame] | 67 | pm_runtime_disable(&pdev->dev); |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static const struct acpi_device_id pwm_lpss_acpi_match[] = { |
| 71 | { "80860F09", (unsigned long)&pwm_lpss_byt_info }, |
| 72 | { "80862288", (unsigned long)&pwm_lpss_bsw_info }, |
Hans de Goede | 1688c87 | 2018-10-12 12:12:25 +0200 | [diff] [blame] | 73 | { "80862289", (unsigned long)&pwm_lpss_bsw_info }, |
Mika Westerberg | 03f00e5 | 2015-10-20 16:53:07 +0300 | [diff] [blame] | 74 | { "80865AC8", (unsigned long)&pwm_lpss_bxt_info }, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 75 | { }, |
| 76 | }; |
| 77 | MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match); |
| 78 | |
| 79 | static struct platform_driver pwm_lpss_driver_platform = { |
| 80 | .driver = { |
| 81 | .name = "pwm-lpss", |
| 82 | .acpi_match_table = pwm_lpss_acpi_match, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 83 | }, |
| 84 | .probe = pwm_lpss_probe_platform, |
Uwe Kleine-König | 9a9174e | 2023-03-03 19:54:29 +0100 | [diff] [blame] | 85 | .remove_new = pwm_lpss_remove_platform, |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 86 | }; |
| 87 | module_platform_driver(pwm_lpss_driver_platform); |
| 88 | |
| 89 | MODULE_DESCRIPTION("PWM platform driver for Intel LPSS"); |
| 90 | MODULE_LICENSE("GPL v2"); |
Andy Shevchenko | a3682d2 | 2022-09-27 19:24:16 +0300 | [diff] [blame] | 91 | MODULE_IMPORT_NS(PWM_LPSS); |
Andy Shevchenko | c558e39 | 2014-08-19 19:17:35 +0300 | [diff] [blame] | 92 | MODULE_ALIAS("platform:pwm-lpss"); |