leds-net48xx.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * LEDs driver for Soekris net48xx
  3. *
  4. * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
  5. *
  6. * Based on leds-ams-delta.c
  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 <linux/err.h>
  17. #include <asm/io.h>
  18. #include <linux/scx200_gpio.h>
  19. #define NET48XX_ERROR_LED_GPIO 20
  20. static struct platform_device *pdev;
  21. static void net48xx_error_led_set(struct led_classdev *led_cdev,
  22. enum led_brightness value)
  23. {
  24. if (value)
  25. scx200_gpio_set_high(NET48XX_ERROR_LED_GPIO);
  26. else
  27. scx200_gpio_set_low(NET48XX_ERROR_LED_GPIO);
  28. }
  29. static struct led_classdev net48xx_error_led = {
  30. .name = "net48xx:error",
  31. .brightness_set = net48xx_error_led_set,
  32. };
  33. #ifdef CONFIG_PM
  34. static int net48xx_led_suspend(struct platform_device *dev,
  35. pm_message_t state)
  36. {
  37. led_classdev_suspend(&net48xx_error_led);
  38. return 0;
  39. }
  40. static int net48xx_led_resume(struct platform_device *dev)
  41. {
  42. led_classdev_resume(&net48xx_error_led);
  43. return 0;
  44. }
  45. #else
  46. #define net48xx_led_suspend NULL
  47. #define net48xx_led_resume NULL
  48. #endif
  49. static int net48xx_led_probe(struct platform_device *pdev)
  50. {
  51. return led_classdev_register(&pdev->dev, &net48xx_error_led);
  52. }
  53. static int net48xx_led_remove(struct platform_device *pdev)
  54. {
  55. led_classdev_unregister(&net48xx_error_led);
  56. return 0;
  57. }
  58. static struct platform_driver net48xx_led_driver = {
  59. .driver.owner = THIS_MODULE,
  60. .probe = net48xx_led_probe,
  61. .remove = net48xx_led_remove,
  62. .suspend = net48xx_led_suspend,
  63. .resume = net48xx_led_resume,
  64. .driver = {
  65. .name = "net48xx-led",
  66. },
  67. };
  68. static int __init net48xx_led_init(void)
  69. {
  70. int ret;
  71. if (!scx200_gpio_present()) {
  72. ret = -ENODEV;
  73. goto out;
  74. }
  75. ret = platform_driver_register(&net48xx_led_driver);
  76. if (ret < 0)
  77. goto out;
  78. pdev = platform_device_register_simple("net48xx-led", -1, NULL, 0);
  79. if (IS_ERR(pdev)) {
  80. ret = PTR_ERR(pdev);
  81. platform_driver_unregister(&net48xx_led_driver);
  82. goto out;
  83. }
  84. out:
  85. return ret;
  86. }
  87. static void __exit net48xx_led_exit(void)
  88. {
  89. platform_device_unregister(pdev);
  90. platform_driver_unregister(&net48xx_led_driver);
  91. }
  92. module_init(net48xx_led_init);
  93. module_exit(net48xx_led_exit);
  94. MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  95. MODULE_DESCRIPTION("Soekris net48xx LED driver");
  96. MODULE_LICENSE("GPL");