leds-hp6xx.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <asm/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. };
  43. static struct led_classdev hp6xx_green_led = {
  44. .name = "hp6xx:green",
  45. .default_trigger = "ide-disk",
  46. .brightness_set = hp6xxled_green_set,
  47. };
  48. #ifdef CONFIG_PM
  49. static int hp6xxled_suspend(struct platform_device *dev, pm_message_t state)
  50. {
  51. led_classdev_suspend(&hp6xx_red_led);
  52. led_classdev_suspend(&hp6xx_green_led);
  53. return 0;
  54. }
  55. static int hp6xxled_resume(struct platform_device *dev)
  56. {
  57. led_classdev_resume(&hp6xx_red_led);
  58. led_classdev_resume(&hp6xx_green_led);
  59. return 0;
  60. }
  61. #endif
  62. static int hp6xxled_probe(struct platform_device *pdev)
  63. {
  64. int ret;
  65. ret = led_classdev_register(&pdev->dev, &hp6xx_red_led);
  66. if (ret < 0)
  67. return ret;
  68. ret = led_classdev_register(&pdev->dev, &hp6xx_green_led);
  69. if (ret < 0)
  70. led_classdev_unregister(&hp6xx_red_led);
  71. return ret;
  72. }
  73. static int hp6xxled_remove(struct platform_device *pdev)
  74. {
  75. led_classdev_unregister(&hp6xx_red_led);
  76. led_classdev_unregister(&hp6xx_green_led);
  77. return 0;
  78. }
  79. /* work with hotplug and coldplug */
  80. MODULE_ALIAS("platform:hp6xx-led");
  81. static struct platform_driver hp6xxled_driver = {
  82. .probe = hp6xxled_probe,
  83. .remove = hp6xxled_remove,
  84. #ifdef CONFIG_PM
  85. .suspend = hp6xxled_suspend,
  86. .resume = hp6xxled_resume,
  87. #endif
  88. .driver = {
  89. .name = "hp6xx-led",
  90. .owner = THIS_MODULE,
  91. },
  92. };
  93. static int __init hp6xxled_init(void)
  94. {
  95. return platform_driver_register(&hp6xxled_driver);
  96. }
  97. static void __exit hp6xxled_exit(void)
  98. {
  99. platform_driver_unregister(&hp6xxled_driver);
  100. }
  101. module_init(hp6xxled_init);
  102. module_exit(hp6xxled_exit);
  103. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  104. MODULE_DESCRIPTION("HP Jornada 6xx LED driver");
  105. MODULE_LICENSE("GPL");