blob: 319809aac2c46cc32366d33a001a8b64b53d9be4 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Andy Shevchenkoc558e392014-08-19 19:17:35 +03002/*
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 Shevchenkoc558e392014-08-19 19:17:35 +03008 */
9
Andy Shevchenkoc558e392014-08-19 19:17:35 +030010#include <linux/kernel.h>
Andy Shevchenko7f8dd162022-09-27 19:24:18 +030011#include <linux/mod_devicetable.h>
Andy Shevchenkoc558e392014-08-19 19:17:35 +030012#include <linux/module.h>
13#include <linux/platform_device.h>
Qipeng Zhaf080be22015-10-26 12:58:27 +020014#include <linux/pm_runtime.h>
Andy Shevchenko7f8dd162022-09-27 19:24:18 +030015#include <linux/property.h>
Andy Shevchenkoc558e392014-08-19 19:17:35 +030016
17#include "pwm-lpss.h"
18
Andy Shevchenko99000732017-01-28 17:10:43 +020019
Andy Shevchenkoc558e392014-08-19 19:17:35 +030020static int pwm_lpss_probe_platform(struct platform_device *pdev)
21{
22 const struct pwm_lpss_boardinfo *info;
Andy Shevchenkoc558e392014-08-19 19:17:35 +030023 struct pwm_lpss_chip *lpwm;
Andy Shevchenko68af6fb2022-09-27 19:24:17 +030024 void __iomem *base;
Andy Shevchenkoc558e392014-08-19 19:17:35 +030025
Andy Shevchenko7f8dd162022-09-27 19:24:18 +030026 info = device_get_match_data(&pdev->dev);
27 if (!info)
Andy Shevchenkoc558e392014-08-19 19:17:35 +030028 return -ENODEV;
29
Andy Shevchenko68af6fb2022-09-27 19:24:17 +030030 base = devm_platform_ioremap_resource(pdev, 0);
31 if (IS_ERR(base))
32 return PTR_ERR(base);
33
Andy Shevchenkof0f31de2022-11-17 13:08:04 +020034 lpwm = devm_pwm_lpss_probe(&pdev->dev, base, info);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030035 if (IS_ERR(lpwm))
36 return PTR_ERR(lpwm);
37
38 platform_set_drvdata(pdev, lpwm);
Qipeng Zhaf080be22015-10-26 12:58:27 +020039
Hans de Goedeb9c90f12020-11-09 11:57:25 +010040 /*
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 Goedee3aa45f22020-11-09 11:57:26 +010051 *
52 * Leaving the controller runtime-suspended (skipping runtime-resume +
53 * normal-suspend) during suspend is fine.
Hans de Goedeb9c90f12020-11-09 11:57:25 +010054 */
55 if (info->other_devices_aml_touches_pwm_regs)
Hans de Goedee3aa45f22020-11-09 11:57:26 +010056 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE|
57 DPM_FLAG_SMART_SUSPEND);
Hans de Goedeb9c90f12020-11-09 11:57:25 +010058
Qipeng Zhaf080be22015-10-26 12:58:27 +020059 pm_runtime_set_active(&pdev->dev);
60 pm_runtime_enable(&pdev->dev);
61
Andy Shevchenkoc558e392014-08-19 19:17:35 +030062 return 0;
63}
64
Uwe Kleine-König9a9174e2023-03-03 19:54:29 +010065static void pwm_lpss_remove_platform(struct platform_device *pdev)
Andy Shevchenkoc558e392014-08-19 19:17:35 +030066{
Qipeng Zhaf080be22015-10-26 12:58:27 +020067 pm_runtime_disable(&pdev->dev);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030068}
69
70static 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 Goede1688c872018-10-12 12:12:25 +020073 { "80862289", (unsigned long)&pwm_lpss_bsw_info },
Mika Westerberg03f00e52015-10-20 16:53:07 +030074 { "80865AC8", (unsigned long)&pwm_lpss_bxt_info },
Andy Shevchenkoc558e392014-08-19 19:17:35 +030075 { },
76};
77MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
78
79static struct platform_driver pwm_lpss_driver_platform = {
80 .driver = {
81 .name = "pwm-lpss",
82 .acpi_match_table = pwm_lpss_acpi_match,
Andy Shevchenkoc558e392014-08-19 19:17:35 +030083 },
84 .probe = pwm_lpss_probe_platform,
Uwe Kleine-König9a9174e2023-03-03 19:54:29 +010085 .remove_new = pwm_lpss_remove_platform,
Andy Shevchenkoc558e392014-08-19 19:17:35 +030086};
87module_platform_driver(pwm_lpss_driver_platform);
88
89MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
90MODULE_LICENSE("GPL v2");
Andy Shevchenkoa3682d22022-09-27 19:24:16 +030091MODULE_IMPORT_NS(PWM_LPSS);
Andy Shevchenkoc558e392014-08-19 19:17:35 +030092MODULE_ALIAS("platform:pwm-lpss");