leds-hp6xx.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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, enum led_brightness value)
  19. {
  20. u8 v8;
  21. v8 = inb(PKDR);
  22. if (value)
  23. outb(v8 & (~PKDR_LED_GREEN), PKDR);
  24. else
  25. outb(v8 | PKDR_LED_GREEN, PKDR);
  26. }
  27. static void hp6xxled_red_set(struct led_classdev *led_cdev, enum led_brightness value)
  28. {
  29. u16 v16;
  30. v16 = inw(HD64461_GPBDR);
  31. if (value)
  32. outw(v16 & (~HD64461_GPBDR_LED_RED), HD64461_GPBDR);
  33. else
  34. outw(v16 | HD64461_GPBDR_LED_RED, HD64461_GPBDR);
  35. }
  36. static struct led_classdev hp6xx_red_led = {
  37. .name = "hp6xx:red",
  38. .default_trigger = "hp6xx-charge",
  39. .brightness_set = hp6xxled_red_set,
  40. };
  41. static struct led_classdev hp6xx_green_led = {
  42. .name = "hp6xx:green",
  43. .default_trigger = "ide-disk",
  44. .brightness_set = hp6xxled_green_set,
  45. };
  46. #ifdef CONFIG_PM
  47. static int hp6xxled_suspend(struct platform_device *dev, pm_message_t state)
  48. {
  49. led_classdev_suspend(&hp6xx_red_led);
  50. led_classdev_suspend(&hp6xx_green_led);
  51. return 0;
  52. }
  53. static int hp6xxled_resume(struct platform_device *dev)
  54. {
  55. led_classdev_resume(&hp6xx_red_led);
  56. led_classdev_resume(&hp6xx_green_led);
  57. return 0;
  58. }
  59. #endif
  60. static int hp6xxled_probe(struct platform_device *pdev)
  61. {
  62. int ret;
  63. ret = led_classdev_register(&pdev->dev, &hp6xx_red_led);
  64. if (ret < 0)
  65. return ret;
  66. ret = led_classdev_register(&pdev->dev, &hp6xx_green_led);
  67. if (ret < 0)
  68. led_classdev_unregister(&hp6xx_red_led);
  69. return ret;
  70. }
  71. static int hp6xxled_remove(struct platform_device *pdev)
  72. {
  73. led_classdev_unregister(&hp6xx_red_led);
  74. led_classdev_unregister(&hp6xx_green_led);
  75. return 0;
  76. }
  77. /* work with hotplug and coldplug */
  78. MODULE_ALIAS("platform:hp6xx-led");
  79. static struct platform_driver hp6xxled_driver = {
  80. .probe = hp6xxled_probe,
  81. .remove = hp6xxled_remove,
  82. #ifdef CONFIG_PM
  83. .suspend = hp6xxled_suspend,
  84. .resume = hp6xxled_resume,
  85. #endif
  86. .driver = {
  87. .name = "hp6xx-led",
  88. .owner = THIS_MODULE,
  89. },
  90. };
  91. static int __init hp6xxled_init(void)
  92. {
  93. return platform_driver_register(&hp6xxled_driver);
  94. }
  95. static void __exit hp6xxled_exit(void)
  96. {
  97. platform_driver_unregister(&hp6xxled_driver);
  98. }
  99. module_init(hp6xxled_init);
  100. module_exit(hp6xxled_exit);
  101. MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>");
  102. MODULE_DESCRIPTION("HP Jornada 6xx LED driver");
  103. MODULE_LICENSE("GPL");