leds-cm-x270.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * drivers/leds/leds-cm-x270.c
  3. *
  4. * Copyright 2007 CompuLab Ltd.
  5. * Author: Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * Based on leds-corgi.c
  8. * Author: Richard Purdie <rpurdie@openedhand.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  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/hardware.h>
  20. #include <mach/pxa-regs.h>
  21. #define GPIO_RED_LED (93)
  22. #define GPIO_GREEN_LED (94)
  23. static void cmx270_red_set(struct led_classdev *led_cdev,
  24. enum led_brightness value)
  25. {
  26. if (value)
  27. GPCR(GPIO_RED_LED) = GPIO_bit(GPIO_RED_LED);
  28. else
  29. GPSR(GPIO_RED_LED) = GPIO_bit(GPIO_RED_LED);
  30. }
  31. static void cmx270_green_set(struct led_classdev *led_cdev,
  32. enum led_brightness value)
  33. {
  34. if (value)
  35. GPCR(GPIO_GREEN_LED) = GPIO_bit(GPIO_GREEN_LED);
  36. else
  37. GPSR(GPIO_GREEN_LED) = GPIO_bit(GPIO_GREEN_LED);
  38. }
  39. static struct led_classdev cmx270_red_led = {
  40. .name = "cm-x270:red",
  41. .default_trigger = "nand-disk",
  42. .brightness_set = cmx270_red_set,
  43. };
  44. static struct led_classdev cmx270_green_led = {
  45. .name = "cm-x270:green",
  46. .default_trigger = "heartbeat",
  47. .brightness_set = cmx270_green_set,
  48. };
  49. #ifdef CONFIG_PM
  50. static int cmx270led_suspend(struct platform_device *dev, pm_message_t state)
  51. {
  52. led_classdev_suspend(&cmx270_red_led);
  53. led_classdev_suspend(&cmx270_green_led);
  54. return 0;
  55. }
  56. static int cmx270led_resume(struct platform_device *dev)
  57. {
  58. led_classdev_resume(&cmx270_red_led);
  59. led_classdev_resume(&cmx270_green_led);
  60. return 0;
  61. }
  62. #endif
  63. static int cmx270led_probe(struct platform_device *pdev)
  64. {
  65. int ret;
  66. ret = led_classdev_register(&pdev->dev, &cmx270_red_led);
  67. if (ret < 0)
  68. return ret;
  69. ret = led_classdev_register(&pdev->dev, &cmx270_green_led);
  70. if (ret < 0)
  71. led_classdev_unregister(&cmx270_red_led);
  72. return ret;
  73. }
  74. static int cmx270led_remove(struct platform_device *pdev)
  75. {
  76. led_classdev_unregister(&cmx270_red_led);
  77. led_classdev_unregister(&cmx270_green_led);
  78. return 0;
  79. }
  80. static struct platform_driver cmx270led_driver = {
  81. .probe = cmx270led_probe,
  82. .remove = cmx270led_remove,
  83. #ifdef CONFIG_PM
  84. .suspend = cmx270led_suspend,
  85. .resume = cmx270led_resume,
  86. #endif
  87. .driver = {
  88. .name = "cm-x270-led",
  89. .owner = THIS_MODULE,
  90. },
  91. };
  92. static int __init cmx270led_init(void)
  93. {
  94. return platform_driver_register(&cmx270led_driver);
  95. }
  96. static void __exit cmx270led_exit(void)
  97. {
  98. platform_driver_unregister(&cmx270led_driver);
  99. }
  100. module_init(cmx270led_init);
  101. module_exit(cmx270led_exit);
  102. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  103. MODULE_DESCRIPTION("CM-x270 LED driver");
  104. MODULE_LICENSE("GPL");
  105. MODULE_ALIAS("platform:cm-x270-led");