leds-net48xx.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/nsc_gpio.h>
  19. #include <linux/scx200_gpio.h>
  20. #define DRVNAME "net48xx-led"
  21. #define NET48XX_ERROR_LED_GPIO 20
  22. static struct platform_device *pdev;
  23. static void net48xx_error_led_set(struct led_classdev *led_cdev,
  24. enum led_brightness value)
  25. {
  26. scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
  27. }
  28. static struct led_classdev net48xx_error_led = {
  29. .name = "net48xx::error",
  30. .brightness_set = net48xx_error_led_set,
  31. .flags = LED_CORE_SUSPENDRESUME,
  32. };
  33. static int net48xx_led_probe(struct platform_device *pdev)
  34. {
  35. return led_classdev_register(&pdev->dev, &net48xx_error_led);
  36. }
  37. static int net48xx_led_remove(struct platform_device *pdev)
  38. {
  39. led_classdev_unregister(&net48xx_error_led);
  40. return 0;
  41. }
  42. static struct platform_driver net48xx_led_driver = {
  43. .probe = net48xx_led_probe,
  44. .remove = net48xx_led_remove,
  45. .driver = {
  46. .name = DRVNAME,
  47. .owner = THIS_MODULE,
  48. },
  49. };
  50. static int __init net48xx_led_init(void)
  51. {
  52. int ret;
  53. /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
  54. if (!scx200_gpio_ops.dev) {
  55. ret = -ENODEV;
  56. goto out;
  57. }
  58. ret = platform_driver_register(&net48xx_led_driver);
  59. if (ret < 0)
  60. goto out;
  61. pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
  62. if (IS_ERR(pdev)) {
  63. ret = PTR_ERR(pdev);
  64. platform_driver_unregister(&net48xx_led_driver);
  65. goto out;
  66. }
  67. out:
  68. return ret;
  69. }
  70. static void __exit net48xx_led_exit(void)
  71. {
  72. platform_device_unregister(pdev);
  73. platform_driver_unregister(&net48xx_led_driver);
  74. }
  75. module_init(net48xx_led_init);
  76. module_exit(net48xx_led_exit);
  77. MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  78. MODULE_DESCRIPTION("Soekris net48xx LED driver");
  79. MODULE_LICENSE("GPL");