leds-msm-pmic.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * leds-msm-pmic.c - MSM PMIC LEDs driver.
  3. *
  4. * Copyright (c) 2009, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/leds.h>
  19. #include <mach/pmic.h>
  20. #define MAX_KEYPAD_BL_LEVEL 16
  21. static void msm_keypad_bl_led_set(struct led_classdev *led_cdev,
  22. enum led_brightness value)
  23. {
  24. int ret;
  25. ret = pmic_set_led_intensity(LED_KEYPAD, value / MAX_KEYPAD_BL_LEVEL);
  26. if (ret)
  27. dev_err(led_cdev->dev, "can't set keypad backlight\n");
  28. }
  29. static struct led_classdev msm_kp_bl_led = {
  30. .name = "keyboard-backlight",
  31. .brightness_set = msm_keypad_bl_led_set,
  32. .brightness = LED_OFF,
  33. };
  34. static int msm_pmic_led_probe(struct platform_device *pdev)
  35. {
  36. int rc;
  37. rc = led_classdev_register(&pdev->dev, &msm_kp_bl_led);
  38. if (rc) {
  39. dev_err(&pdev->dev, "unable to register led class driver\n");
  40. return rc;
  41. }
  42. msm_keypad_bl_led_set(&msm_kp_bl_led, LED_OFF);
  43. return rc;
  44. }
  45. static int __devexit msm_pmic_led_remove(struct platform_device *pdev)
  46. {
  47. led_classdev_unregister(&msm_kp_bl_led);
  48. return 0;
  49. }
  50. #ifdef CONFIG_PM
  51. static int msm_pmic_led_suspend(struct platform_device *dev,
  52. pm_message_t state)
  53. {
  54. led_classdev_suspend(&msm_kp_bl_led);
  55. return 0;
  56. }
  57. static int msm_pmic_led_resume(struct platform_device *dev)
  58. {
  59. led_classdev_resume(&msm_kp_bl_led);
  60. return 0;
  61. }
  62. #else
  63. #define msm_pmic_led_suspend NULL
  64. #define msm_pmic_led_resume NULL
  65. #endif
  66. static struct platform_driver msm_pmic_led_driver = {
  67. .probe = msm_pmic_led_probe,
  68. .remove = __devexit_p(msm_pmic_led_remove),
  69. .suspend = msm_pmic_led_suspend,
  70. .resume = msm_pmic_led_resume,
  71. .driver = {
  72. .name = "pmic-leds",
  73. .owner = THIS_MODULE,
  74. },
  75. };
  76. static int __init msm_pmic_led_init(void)
  77. {
  78. return platform_driver_register(&msm_pmic_led_driver);
  79. }
  80. module_init(msm_pmic_led_init);
  81. static void __exit msm_pmic_led_exit(void)
  82. {
  83. platform_driver_unregister(&msm_pmic_led_driver);
  84. }
  85. module_exit(msm_pmic_led_exit);
  86. MODULE_DESCRIPTION("MSM PMIC LEDs driver");
  87. MODULE_LICENSE("GPL v2");
  88. MODULE_ALIAS("platform:pmic-leds");