pwm-lpss-platform.c 2.7 KB

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