leds-net48xx.c 2.1 KB

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