leds-corgi.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * LED Triggers Core
  3. *
  4. * Copyright 2005-2006 Openedhand Ltd.
  5. *
  6. * Author: Richard Purdie <rpurdie@openedhand.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/leds.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/arch/corgi.h>
  19. #include <asm/arch/hardware.h>
  20. #include <asm/arch/pxa-regs.h>
  21. #include <asm/hardware/scoop.h>
  22. static void corgiled_amber_set(struct led_classdev *led_cdev, enum led_brightness value)
  23. {
  24. if (value)
  25. GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
  26. else
  27. GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
  28. }
  29. static void corgiled_green_set(struct led_classdev *led_cdev, enum led_brightness value)
  30. {
  31. if (value)
  32. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  33. else
  34. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  35. }
  36. static struct led_classdev corgi_amber_led = {
  37. .name = "corgi:amber",
  38. .default_trigger = "sharpsl-charge",
  39. .brightness_set = corgiled_amber_set,
  40. };
  41. static struct led_classdev corgi_green_led = {
  42. .name = "corgi:green",
  43. .default_trigger = "nand-disk",
  44. .brightness_set = corgiled_green_set,
  45. };
  46. #ifdef CONFIG_PM
  47. static int corgiled_suspend(struct platform_device *dev, pm_message_t state)
  48. {
  49. #ifdef CONFIG_LEDS_TRIGGERS
  50. if (corgi_amber_led.trigger && strcmp(corgi_amber_led.trigger->name, "sharpsl-charge"))
  51. #endif
  52. led_classdev_suspend(&corgi_amber_led);
  53. led_classdev_suspend(&corgi_green_led);
  54. return 0;
  55. }
  56. static int corgiled_resume(struct platform_device *dev)
  57. {
  58. led_classdev_resume(&corgi_amber_led);
  59. led_classdev_resume(&corgi_green_led);
  60. return 0;
  61. }
  62. #endif
  63. static int corgiled_probe(struct platform_device *pdev)
  64. {
  65. int ret;
  66. ret = led_classdev_register(&pdev->dev, &corgi_amber_led);
  67. if (ret < 0)
  68. return ret;
  69. ret = led_classdev_register(&pdev->dev, &corgi_green_led);
  70. if (ret < 0)
  71. led_classdev_unregister(&corgi_amber_led);
  72. return ret;
  73. }
  74. static int corgiled_remove(struct platform_device *pdev)
  75. {
  76. led_classdev_unregister(&corgi_amber_led);
  77. led_classdev_unregister(&corgi_green_led);
  78. return 0;
  79. }
  80. static struct platform_driver corgiled_driver = {
  81. .probe = corgiled_probe,
  82. .remove = corgiled_remove,
  83. #ifdef CONFIG_PM
  84. .suspend = corgiled_suspend,
  85. .resume = corgiled_resume,
  86. #endif
  87. .driver = {
  88. .name = "corgi-led",
  89. },
  90. };
  91. static int __init corgiled_init(void)
  92. {
  93. return platform_driver_register(&corgiled_driver);
  94. }
  95. static void __exit corgiled_exit(void)
  96. {
  97. platform_driver_unregister(&corgiled_driver);
  98. }
  99. module_init(corgiled_init);
  100. module_exit(corgiled_exit);
  101. MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
  102. MODULE_DESCRIPTION("Corgi LED driver");
  103. MODULE_LICENSE("GPL");