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 void __iomem *base; 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 32 base = devm_platform_ioremap_resource(pdev, 0); 33 if (IS_ERR(base)) 34 return PTR_ERR(base); 35 36 lpwm = pwm_lpss_probe(&pdev->dev, base, info); 37 if (IS_ERR(lpwm)) 38 return PTR_ERR(lpwm); 39 40 platform_set_drvdata(pdev, lpwm); 41 42 /* 43 * On Cherry Trail devices the GFX0._PS0 AML checks if the controller 44 * is on and if it is not on it turns it on and restores what it 45 * believes is the correct state to the PWM controller. 46 * Because of this we must disallow direct-complete, which keeps the 47 * controller (runtime)suspended on resume, to avoid 2 issues: 48 * 1. The controller getting turned on without the linux-pm code 49 * knowing about this. On devices where the controller is unused 50 * this causes it to stay on during the next suspend causing high 51 * battery drain (because S0i3 is not reached) 52 * 2. The state restoring code unexpectedly messing with the controller 53 * 54 * Leaving the controller runtime-suspended (skipping runtime-resume + 55 * normal-suspend) during suspend is fine. 56 */ 57 if (info->other_devices_aml_touches_pwm_regs) 58 dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE| 59 DPM_FLAG_SMART_SUSPEND); 60 61 pm_runtime_set_active(&pdev->dev); 62 pm_runtime_enable(&pdev->dev); 63 64 return 0; 65 } 66 67 static int pwm_lpss_remove_platform(struct platform_device *pdev) 68 { 69 pm_runtime_disable(&pdev->dev); 70 return 0; 71 } 72 73 static const struct acpi_device_id pwm_lpss_acpi_match[] = { 74 { "80860F09", (unsigned long)&pwm_lpss_byt_info }, 75 { "80862288", (unsigned long)&pwm_lpss_bsw_info }, 76 { "80862289", (unsigned long)&pwm_lpss_bsw_info }, 77 { "80865AC8", (unsigned long)&pwm_lpss_bxt_info }, 78 { }, 79 }; 80 MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match); 81 82 static struct platform_driver pwm_lpss_driver_platform = { 83 .driver = { 84 .name = "pwm-lpss", 85 .acpi_match_table = pwm_lpss_acpi_match, 86 }, 87 .probe = pwm_lpss_probe_platform, 88 .remove = pwm_lpss_remove_platform, 89 }; 90 module_platform_driver(pwm_lpss_driver_platform); 91 92 MODULE_DESCRIPTION("PWM platform driver for Intel LPSS"); 93 MODULE_LICENSE("GPL v2"); 94 MODULE_IMPORT_NS(PWM_LPSS); 95 MODULE_ALIAS("platform:pwm-lpss"); 96