leds-net48xx.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * LEDs driver for Soekris net48xx
  4. *
  5. * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
  6. *
  7. * Based on leds-ams-delta.c
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/leds.h>
  13. #include <linux/err.h>
  14. #include <linux/io.h>
  15. #include <linux/nsc_gpio.h>
  16. #include <linux/scx200_gpio.h>
  17. #include <linux/module.h>
  18. #define DRVNAME "net48xx-led"
  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. scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
  25. }
  26. static struct led_classdev net48xx_error_led = {
  27. .name = "net48xx::error",
  28. .brightness_set = net48xx_error_led_set,
  29. .flags = LED_CORE_SUSPENDRESUME,
  30. };
  31. static int net48xx_led_probe(struct platform_device *pdev)
  32. {
  33. return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
  34. }
  35. static struct platform_driver net48xx_led_driver = {
  36. .probe = net48xx_led_probe,
  37. .driver = {
  38. .name = DRVNAME,
  39. },
  40. };
  41. static int __init net48xx_led_init(void)
  42. {
  43. int ret;
  44. /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
  45. if (!scx200_gpio_ops.dev) {
  46. ret = -ENODEV;
  47. goto out;
  48. }
  49. ret = platform_driver_register(&net48xx_led_driver);
  50. if (ret < 0)
  51. goto out;
  52. pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
  53. if (IS_ERR(pdev)) {
  54. ret = PTR_ERR(pdev);
  55. platform_driver_unregister(&net48xx_led_driver);
  56. goto out;
  57. }
  58. out:
  59. return ret;
  60. }
  61. static void __exit net48xx_led_exit(void)
  62. {
  63. platform_device_unregister(pdev);
  64. platform_driver_unregister(&net48xx_led_driver);
  65. }
  66. module_init(net48xx_led_init);
  67. module_exit(net48xx_led_exit);
  68. MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  69. MODULE_DESCRIPTION("Soekris net48xx LED driver");
  70. MODULE_LICENSE("GPL");