1 // SPDX-License-Identifier: GPL-2.0-only 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 8 */ 9 10 #include <linux/acpi.h> 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/platform_device.h> 14 #include <linux/pm_runtime.h> 15 16 #include "pwm-lpss.h" 17 18 19 static int pwm_lpss_probe_platform(struct platform_device *pdev) 20 { 21 const struct pwm_lpss_boardinfo *info; 22 const struct acpi_device_id *id; 23 struct pwm_lpss_chip *lpwm; 24 struct resource *r; 25 26 id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); 27 if (!id) 28 return -ENODEV; 29 30 info = (const struct pwm_lpss_boardinfo *)id->driver_data; 31 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 32 33 lpwm = pwm_lpss_probe(&pdev->dev, r, info); 34 if (IS_ERR(lpwm)) 35 return PTR_ERR(lpwm); 36 37 platform_set_drvdata(pdev, lpwm); 38 39 /* 40 * On Cherry Trail devices the GFX0._PS0 AML checks if the controller 41 * is on and if it is not on it turns it on and restores what it 42 * believes is the correct state to the PWM controller. 43 * Because of this we must disallow direct-complete, which keeps the 44 * controller (runtime)suspended on resume, to avoid 2 issues: 45 * 1. The controller getting turned on without the linux-pm code 46 * knowing about this. On devices where the controller is unused 47 * this causes it to stay on during the next suspend causing high 48 * battery drain (because S0i3 is not reached) 49 * 2. The state restoring code unexpectedly messing with the controller 50 * 51 * Leaving the controller runtime-suspended (skipping runtime-resume + 52 * normal-suspend) during suspend is fine. 53 */ 54 if (info->other_devices_aml_touches_pwm_regs) 55 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE| 56 DPM_FLAG_SMART_SUSPEND); 57 58 pm_runtime_set_active(&pdev->dev); 59 pm_runtime_enable(&pdev->dev); 60 61 return 0; 62 } 63 64 static int pwm_lpss_remove_platform(struct platform_device *pdev) 65 { 66 pm_runtime_disable(&pdev->dev); 67 return 0; 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 }, 73 { "80862289", (unsigned long)&pwm_lpss_bsw_info }, 74 { "80865AC8", (unsigned long)&pwm_lpss_bxt_info }, 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, 83 }, 84 .probe = pwm_lpss_probe_platform, 85 .remove = pwm_lpss_remove_platform, 86 }; 87 module_platform_driver(pwm_lpss_driver_platform); 88 89 MODULE_DESCRIPTION("PWM platform driver for Intel LPSS"); 90 MODULE_LICENSE("GPL v2"); 91 MODULE_ALIAS("platform:pwm-lpss"); 92