leds-corgi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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,
  23. 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,
  31. enum led_brightness value)
  32. {
  33. if (value)
  34. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  35. else
  36. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  37. }
  38. static struct led_classdev corgi_amber_led = {
  39. .name = "corgi:amber:charge",
  40. .default_trigger = "sharpsl-charge",
  41. .brightness_set = corgiled_amber_set,
  42. };
  43. static struct led_classdev corgi_green_led = {
  44. .name = "corgi:green:mail",
  45. .default_trigger = "nand-disk",
  46. .brightness_set = corgiled_green_set,
  47. };
  48. #ifdef CONFIG_PM
  49. static int corgiled_suspend(struct platform_device *dev, pm_message_t state)
  50. {
  51. #ifdef CONFIG_LEDS_TRIGGERS
  52. if (corgi_amber_led.trigger &&
  53. strcmp(corgi_amber_led.trigger->name, "sharpsl-charge"))
  54. #endif
  55. led_classdev_suspend(&corgi_amber_led);
  56. led_classdev_suspend(&corgi_green_led);
  57. return 0;
  58. }
  59. static int corgiled_resume(struct platform_device *dev)
  60. {
  61. led_classdev_resume(&corgi_amber_led);
  62. led_classdev_resume(&corgi_green_led);
  63. return 0;
  64. }
  65. #endif
  66. static int corgiled_probe(struct platform_device *pdev)
  67. {
  68. int ret;
  69. ret = led_classdev_register(&pdev->dev, &corgi_amber_led);
  70. if (ret < 0)
  71. return ret;
  72. ret = led_classdev_register(&pdev->dev, &corgi_green_led);
  73. if (ret < 0)
  74. led_classdev_unregister(&corgi_amber_led);
  75. return ret;
  76. }
  77. static int corgiled_remove(struct platform_device *pdev)
  78. {
  79. led_classdev_unregister(&corgi_amber_led);
  80. led_classdev_unregister(&corgi_green_led);
  81. return 0;
  82. }
  83. static struct platform_driver corgiled_driver = {
  84. .probe = corgiled_probe,
  85. .remove = corgiled_remove,
  86. #ifdef CONFIG_PM
  87. .suspend = corgiled_suspend,
  88. .resume = corgiled_resume,
  89. #endif
  90. .driver = {
  91. .name = "corgi-led",
  92. .owner = THIS_MODULE,
  93. },
  94. };
  95. static int __init corgiled_init(void)
  96. {
  97. return platform_driver_register(&corgiled_driver);
  98. }
  99. static void __exit corgiled_exit(void)
  100. {
  101. platform_driver_unregister(&corgiled_driver);
  102. }
  103. module_init(corgiled_init);
  104. module_exit(corgiled_exit);
  105. MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
  106. MODULE_DESCRIPTION("Corgi LED driver");
  107. MODULE_LICENSE("GPL");
  108. MODULE_ALIAS("platform:corgi-led");