xref: /openbmc/linux/drivers/pwm/pwm-lpss-platform.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c558e39eSAndy Shevchenko /*
3c558e39eSAndy Shevchenko  * Intel Low Power Subsystem PWM controller driver
4c558e39eSAndy Shevchenko  *
5c558e39eSAndy Shevchenko  * Copyright (C) 2014, Intel Corporation
6c558e39eSAndy Shevchenko  *
7c558e39eSAndy Shevchenko  * Derived from the original pwm-lpss.c
8c558e39eSAndy Shevchenko  */
9c558e39eSAndy Shevchenko 
10c558e39eSAndy Shevchenko #include <linux/kernel.h>
117f8dd161SAndy Shevchenko #include <linux/mod_devicetable.h>
12c558e39eSAndy Shevchenko #include <linux/module.h>
13c558e39eSAndy Shevchenko #include <linux/platform_device.h>
14f080be27SQipeng Zha #include <linux/pm_runtime.h>
157f8dd161SAndy Shevchenko #include <linux/property.h>
16c558e39eSAndy Shevchenko 
17c558e39eSAndy Shevchenko #include "pwm-lpss.h"
18c558e39eSAndy Shevchenko 
199900073cSAndy Shevchenko 
pwm_lpss_probe_platform(struct platform_device * pdev)20c558e39eSAndy Shevchenko static int pwm_lpss_probe_platform(struct platform_device *pdev)
21c558e39eSAndy Shevchenko {
22c558e39eSAndy Shevchenko 	const struct pwm_lpss_boardinfo *info;
23c558e39eSAndy Shevchenko 	struct pwm_lpss_chip *lpwm;
2468af6fb0SAndy Shevchenko 	void __iomem *base;
25c558e39eSAndy Shevchenko 
267f8dd161SAndy Shevchenko 	info = device_get_match_data(&pdev->dev);
277f8dd161SAndy Shevchenko 	if (!info)
28c558e39eSAndy Shevchenko 		return -ENODEV;
29c558e39eSAndy Shevchenko 
3068af6fb0SAndy Shevchenko 	base = devm_platform_ioremap_resource(pdev, 0);
3168af6fb0SAndy Shevchenko 	if (IS_ERR(base))
3268af6fb0SAndy Shevchenko 		return PTR_ERR(base);
3368af6fb0SAndy Shevchenko 
34f0f31de3SAndy Shevchenko 	lpwm = devm_pwm_lpss_probe(&pdev->dev, base, info);
35c558e39eSAndy Shevchenko 	if (IS_ERR(lpwm))
36c558e39eSAndy Shevchenko 		return PTR_ERR(lpwm);
37c558e39eSAndy Shevchenko 
38c558e39eSAndy Shevchenko 	platform_set_drvdata(pdev, lpwm);
39f080be27SQipeng Zha 
40b9c90f15SHans de Goede 	/*
41b9c90f15SHans de Goede 	 * On Cherry Trail devices the GFX0._PS0 AML checks if the controller
42b9c90f15SHans de Goede 	 * is on and if it is not on it turns it on and restores what it
43b9c90f15SHans de Goede 	 * believes is the correct state to the PWM controller.
44b9c90f15SHans de Goede 	 * Because of this we must disallow direct-complete, which keeps the
45b9c90f15SHans de Goede 	 * controller (runtime)suspended on resume, to avoid 2 issues:
46b9c90f15SHans de Goede 	 * 1. The controller getting turned on without the linux-pm code
47b9c90f15SHans de Goede 	 *    knowing about this. On devices where the controller is unused
48b9c90f15SHans de Goede 	 *    this causes it to stay on during the next suspend causing high
49b9c90f15SHans de Goede 	 *    battery drain (because S0i3 is not reached)
50b9c90f15SHans de Goede 	 * 2. The state restoring code unexpectedly messing with the controller
51e3aa45f2SHans de Goede 	 *
52e3aa45f2SHans de Goede 	 * Leaving the controller runtime-suspended (skipping runtime-resume +
53e3aa45f2SHans de Goede 	 * normal-suspend) during suspend is fine.
54b9c90f15SHans de Goede 	 */
55b9c90f15SHans de Goede 	if (info->other_devices_aml_touches_pwm_regs)
56e3aa45f2SHans de Goede 		dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE|
57e3aa45f2SHans de Goede 						    DPM_FLAG_SMART_SUSPEND);
58b9c90f15SHans de Goede 
59f080be27SQipeng Zha 	pm_runtime_set_active(&pdev->dev);
60f080be27SQipeng Zha 	pm_runtime_enable(&pdev->dev);
61f080be27SQipeng Zha 
62c558e39eSAndy Shevchenko 	return 0;
63c558e39eSAndy Shevchenko }
64c558e39eSAndy Shevchenko 
pwm_lpss_remove_platform(struct platform_device * pdev)65*9a9174eaSUwe Kleine-König static void pwm_lpss_remove_platform(struct platform_device *pdev)
66c558e39eSAndy Shevchenko {
67f080be27SQipeng Zha 	pm_runtime_disable(&pdev->dev);
68c558e39eSAndy Shevchenko }
69c558e39eSAndy Shevchenko 
70c558e39eSAndy Shevchenko static const struct acpi_device_id pwm_lpss_acpi_match[] = {
71c558e39eSAndy Shevchenko 	{ "80860F09", (unsigned long)&pwm_lpss_byt_info },
72c558e39eSAndy Shevchenko 	{ "80862288", (unsigned long)&pwm_lpss_bsw_info },
731688c871SHans de Goede 	{ "80862289", (unsigned long)&pwm_lpss_bsw_info },
7403f00e53SMika Westerberg 	{ "80865AC8", (unsigned long)&pwm_lpss_bxt_info },
75c558e39eSAndy Shevchenko 	{ },
76c558e39eSAndy Shevchenko };
77c558e39eSAndy Shevchenko MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
78c558e39eSAndy Shevchenko 
79c558e39eSAndy Shevchenko static struct platform_driver pwm_lpss_driver_platform = {
80c558e39eSAndy Shevchenko 	.driver = {
81c558e39eSAndy Shevchenko 		.name = "pwm-lpss",
82c558e39eSAndy Shevchenko 		.acpi_match_table = pwm_lpss_acpi_match,
83c558e39eSAndy Shevchenko 	},
84c558e39eSAndy Shevchenko 	.probe = pwm_lpss_probe_platform,
85*9a9174eaSUwe Kleine-König 	.remove_new = pwm_lpss_remove_platform,
86c558e39eSAndy Shevchenko };
87c558e39eSAndy Shevchenko module_platform_driver(pwm_lpss_driver_platform);
88c558e39eSAndy Shevchenko 
89c558e39eSAndy Shevchenko MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
90c558e39eSAndy Shevchenko MODULE_LICENSE("GPL v2");
91a3682d2fSAndy Shevchenko MODULE_IMPORT_NS(PWM_LPSS);
92c558e39eSAndy Shevchenko MODULE_ALIAS("platform:pwm-lpss");
93