leds-net48xx.c 2.4 KB

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