leds-corgi.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/config.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/leds.h>
  18. #include <asm/mach-types.h>
  19. #include <asm/arch/corgi.h>
  20. #include <asm/arch/hardware.h>
  21. #include <asm/arch/pxa-regs.h>
  22. #include <asm/hardware/scoop.h>
  23. static void corgiled_amber_set(struct led_classdev *led_cdev, enum led_brightness value)
  24. {
  25. if (value)
  26. GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
  27. else
  28. GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
  29. }
  30. static void corgiled_green_set(struct led_classdev *led_cdev, enum led_brightness value)
  31. {
  32. if (value)
  33. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  34. else
  35. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  36. }
  37. static struct led_classdev corgi_amber_led = {
  38. .name = "corgi:amber",
  39. .default_trigger = "sharpsl-charge",
  40. .brightness_set = corgiled_amber_set,
  41. };
  42. static struct led_classdev corgi_green_led = {
  43. .name = "corgi:green",
  44. .default_trigger = "nand-disk",
  45. .brightness_set = corgiled_green_set,
  46. };
  47. #ifdef CONFIG_PM
  48. static int corgiled_suspend(struct platform_device *dev, pm_message_t state)
  49. {
  50. #ifdef CONFIG_LEDS_TRIGGERS
  51. if (corgi_amber_led.trigger && strcmp(corgi_amber_led.trigger->name, "sharpsl-charge"))
  52. #endif
  53. led_classdev_suspend(&corgi_amber_led);
  54. led_classdev_suspend(&corgi_green_led);
  55. return 0;
  56. }
  57. static int corgiled_resume(struct platform_device *dev)
  58. {
  59. led_classdev_resume(&corgi_amber_led);
  60. led_classdev_resume(&corgi_green_led);
  61. return 0;
  62. }
  63. #endif
  64. static int corgiled_probe(struct platform_device *pdev)
  65. {
  66. int ret;
  67. ret = led_classdev_register(&pdev->dev, &corgi_amber_led);
  68. if (ret < 0)
  69. return ret;
  70. ret = led_classdev_register(&pdev->dev, &corgi_green_led);
  71. if (ret < 0)
  72. led_classdev_unregister(&corgi_amber_led);
  73. return ret;
  74. }
  75. static int corgiled_remove(struct platform_device *pdev)
  76. {
  77. led_classdev_unregister(&corgi_amber_led);
  78. led_classdev_unregister(&corgi_green_led);
  79. return 0;
  80. }
  81. static struct platform_driver corgiled_driver = {
  82. .probe = corgiled_probe,
  83. .remove = corgiled_remove,
  84. #ifdef CONFIG_PM
  85. .suspend = corgiled_suspend,
  86. .resume = corgiled_resume,
  87. #endif
  88. .driver = {
  89. .name = "corgi-led",
  90. },
  91. };
  92. static int __init corgiled_init(void)
  93. {
  94. return platform_driver_register(&corgiled_driver);
  95. }
  96. static void __exit corgiled_exit(void)
  97. {
  98. platform_driver_unregister(&corgiled_driver);
  99. }
  100. module_init(corgiled_init);
  101. module_exit(corgiled_exit);
  102. MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
  103. MODULE_DESCRIPTION("Corgi LED driver");
  104. MODULE_LICENSE("GPL");