leds-net48xx.c 2.5 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/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. };
  32. #ifdef CONFIG_PM
  33. static int net48xx_led_suspend(struct platform_device *dev,
  34. pm_message_t state)
  35. {
  36. led_classdev_suspend(&net48xx_error_led);
  37. return 0;
  38. }
  39. static int net48xx_led_resume(struct platform_device *dev)
  40. {
  41. led_classdev_resume(&net48xx_error_led);
  42. return 0;
  43. }
  44. #else
  45. #define net48xx_led_suspend NULL
  46. #define net48xx_led_resume NULL
  47. #endif
  48. static int net48xx_led_probe(struct platform_device *pdev)
  49. {
  50. return led_classdev_register(&pdev->dev, &net48xx_error_led);
  51. }
  52. static int net48xx_led_remove(struct platform_device *pdev)
  53. {
  54. led_classdev_unregister(&net48xx_error_led);
  55. return 0;
  56. }
  57. static struct platform_driver net48xx_led_driver = {
  58. .probe = net48xx_led_probe,
  59. .remove = net48xx_led_remove,
  60. .suspend = net48xx_led_suspend,
  61. .resume = net48xx_led_resume,
  62. .driver = {
  63. .name = DRVNAME,
  64. .owner = THIS_MODULE,
  65. },
  66. };
  67. static int __init net48xx_led_init(void)
  68. {
  69. int ret;
  70. /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
  71. if (!scx200_gpio_ops.dev) {
  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(DRVNAME, -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");