leds-hp6xx.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * LED Triggers Core
  3. * For the HP Jornada 620/660/680/690 handhelds
  4. *
  5. * Copyright 2008 Kristoffer Ericson <kristoffer.ericson@gmail.com>
  6. * this driver is based on leds-spitz.c by Richard Purdie.
  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. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/leds.h>
  17. #include <asm/hd64461.h>
  18. #include <mach/hp6xx.h>
  19. static void hp6xxled_green_set(struct led_classdev *led_cdev,
  20. enum led_brightness value)
  21. {
  22. u8 v8;
  23. v8 = inb(PKDR);
  24. if (value)
  25. outb(v8 & (~PKDR_LED_GREEN), PKDR);
  26. else
  27. outb(v8 | PKDR_LED_GREEN, PKDR);
  28. }
  29. static void hp6xxled_red_set(struct led_classdev *led_cdev,
  30. enum led_brightness value)
  31. {
  32. u16 v16;
  33. v16 = inw(HD64461_GPBDR);
  34. if (value)
  35. outw(v16 & (~HD64461_GPBDR_LED_RED), HD64461_GPBDR);
  36. else
  37. outw(v16 | HD64461_GPBDR_LED_RED, HD64461_GPBDR);
  38. }
  39. static struct led_classdev hp6xx_red_led = {
  40. .name = "hp6xx:red",
  41. .default_trigger = "hp6xx-charge",
  42. .brightness_set = hp6xxled_red_set,
  43. .flags = LED_CORE_SUSPENDRESUME,
  44. };
  45. static struct led_classdev hp6xx_green_led = {
  46. .name = "hp6xx:green",
  47. .default_trigger = "ide-disk",
  48. .brightness_set = hp6xxled_green_set,
  49. .flags = LED_CORE_SUSPENDRESUME,
  50. };
  51. static int hp6xxled_probe(struct platform_device *pdev)
  52. {
  53. int ret;
  54. ret = led_classdev_register(&pdev->dev, &hp6xx_red_led);
  55. if (ret < 0)
  56. return ret;
  57. ret = led_classdev_register(&pdev->dev, &hp6xx_green_led);
  58. if (ret < 0)
  59. led_classdev_unregister(&hp6xx_red_led);
  60. return ret;
  61. }
  62. static int hp6xxled_remove(struct platform_device *pdev)
  63. {
  64. led_classdev_unregister(&hp6xx_red_led);
  65. led_classdev_unregister(&hp6xx_green_led);
  66. return 0;
  67. }
  68. /* work with hotplug and coldplug */
  69. MODULE_ALIAS("platform:hp6xx-led");
  70. static struct platform_driver hp6xxled_driver = {
  71. .probe = hp6xxled_probe,
  72. .remove = hp6xxled_remove,
  73. .driver = {
  74. .name = "hp6xx-led",
  75. .owner = THIS_MODULE,
  76. },
  77. };
  78. static int __init hp6xxled_init(void)
  79. {
  80. return platform_driver_register(&hp6xxled_driver);
  81. }
  82. static void __exit hp6xxled_exit(void)
  83. {
  84. platform_driver_unregister(&hp6xxled_driver);
  85. }
  86. module_init(hp6xxled_init);
  87. module_exit(hp6xxled_exit);
  88. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  89. MODULE_DESCRIPTION("HP Jornada 6xx LED driver");
  90. MODULE_LICENSE("GPL");