Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Intel Low Power Subsystem PWM controller driver
0004  *
0005  * Copyright (C) 2014, Intel Corporation
0006  *
0007  * Derived from the original pwm-lpss.c
0008  */
0009 
0010 #include <linux/acpi.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/pm_runtime.h>
0015 
0016 #include "pwm-lpss.h"
0017 
0018 /* BayTrail */
0019 static const struct pwm_lpss_boardinfo pwm_lpss_byt_info = {
0020     .clk_rate = 25000000,
0021     .npwm = 1,
0022     .base_unit_bits = 16,
0023 };
0024 
0025 /* Braswell */
0026 static const struct pwm_lpss_boardinfo pwm_lpss_bsw_info = {
0027     .clk_rate = 19200000,
0028     .npwm = 1,
0029     .base_unit_bits = 16,
0030     .other_devices_aml_touches_pwm_regs = true,
0031 };
0032 
0033 /* Broxton */
0034 static const struct pwm_lpss_boardinfo pwm_lpss_bxt_info = {
0035     .clk_rate = 19200000,
0036     .npwm = 4,
0037     .base_unit_bits = 22,
0038     .bypass = true,
0039 };
0040 
0041 static int pwm_lpss_probe_platform(struct platform_device *pdev)
0042 {
0043     const struct pwm_lpss_boardinfo *info;
0044     const struct acpi_device_id *id;
0045     struct pwm_lpss_chip *lpwm;
0046     struct resource *r;
0047 
0048     id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev);
0049     if (!id)
0050         return -ENODEV;
0051 
0052     info = (const struct pwm_lpss_boardinfo *)id->driver_data;
0053     r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0054 
0055     lpwm = pwm_lpss_probe(&pdev->dev, r, info);
0056     if (IS_ERR(lpwm))
0057         return PTR_ERR(lpwm);
0058 
0059     platform_set_drvdata(pdev, lpwm);
0060 
0061     /*
0062      * On Cherry Trail devices the GFX0._PS0 AML checks if the controller
0063      * is on and if it is not on it turns it on and restores what it
0064      * believes is the correct state to the PWM controller.
0065      * Because of this we must disallow direct-complete, which keeps the
0066      * controller (runtime)suspended on resume, to avoid 2 issues:
0067      * 1. The controller getting turned on without the linux-pm code
0068      *    knowing about this. On devices where the controller is unused
0069      *    this causes it to stay on during the next suspend causing high
0070      *    battery drain (because S0i3 is not reached)
0071      * 2. The state restoring code unexpectedly messing with the controller
0072      *
0073      * Leaving the controller runtime-suspended (skipping runtime-resume +
0074      * normal-suspend) during suspend is fine.
0075      */
0076     if (info->other_devices_aml_touches_pwm_regs)
0077         dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE|
0078                             DPM_FLAG_SMART_SUSPEND);
0079 
0080     pm_runtime_set_active(&pdev->dev);
0081     pm_runtime_enable(&pdev->dev);
0082 
0083     return 0;
0084 }
0085 
0086 static int pwm_lpss_remove_platform(struct platform_device *pdev)
0087 {
0088     pm_runtime_disable(&pdev->dev);
0089     return 0;
0090 }
0091 
0092 static const struct acpi_device_id pwm_lpss_acpi_match[] = {
0093     { "80860F09", (unsigned long)&pwm_lpss_byt_info },
0094     { "80862288", (unsigned long)&pwm_lpss_bsw_info },
0095     { "80862289", (unsigned long)&pwm_lpss_bsw_info },
0096     { "80865AC8", (unsigned long)&pwm_lpss_bxt_info },
0097     { },
0098 };
0099 MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
0100 
0101 static struct platform_driver pwm_lpss_driver_platform = {
0102     .driver = {
0103         .name = "pwm-lpss",
0104         .acpi_match_table = pwm_lpss_acpi_match,
0105     },
0106     .probe = pwm_lpss_probe_platform,
0107     .remove = pwm_lpss_remove_platform,
0108 };
0109 module_platform_driver(pwm_lpss_driver_platform);
0110 
0111 MODULE_DESCRIPTION("PWM platform driver for Intel LPSS");
0112 MODULE_LICENSE("GPL v2");
0113 MODULE_ALIAS("platform:pwm-lpss");