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