Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 2 | /* |
| 3 | * LEDs driver for PCEngines WRAP |
| 4 | * |
| 5 | * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org> |
| 6 | * |
| 7 | * Based on leds-net48xx.c |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/leds.h> |
| 14 | #include <linux/err.h> |
Sachin Kamat | 572dc62 | 2012-11-25 12:48:32 +0530 | [diff] [blame] | 15 | #include <linux/io.h> |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 16 | #include <linux/scx200_gpio.h> |
Paul Gortmaker | 54f4ded | 2011-07-03 13:56:03 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 18 | |
| 19 | #define DRVNAME "wrap-led" |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 20 | #define WRAP_POWER_LED_GPIO 2 |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 21 | #define WRAP_ERROR_LED_GPIO 3 |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 22 | #define WRAP_EXTRA_LED_GPIO 18 |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 23 | |
| 24 | static struct platform_device *pdev; |
| 25 | |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 26 | static void wrap_power_led_set(struct led_classdev *led_cdev, |
| 27 | enum led_brightness value) |
| 28 | { |
| 29 | if (value) |
| 30 | scx200_gpio_set_low(WRAP_POWER_LED_GPIO); |
| 31 | else |
| 32 | scx200_gpio_set_high(WRAP_POWER_LED_GPIO); |
| 33 | } |
| 34 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 35 | static void wrap_error_led_set(struct led_classdev *led_cdev, |
| 36 | enum led_brightness value) |
| 37 | { |
| 38 | if (value) |
| 39 | scx200_gpio_set_low(WRAP_ERROR_LED_GPIO); |
| 40 | else |
| 41 | scx200_gpio_set_high(WRAP_ERROR_LED_GPIO); |
| 42 | } |
| 43 | |
| 44 | static void wrap_extra_led_set(struct led_classdev *led_cdev, |
| 45 | enum led_brightness value) |
| 46 | { |
| 47 | if (value) |
| 48 | scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO); |
| 49 | else |
| 50 | scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO); |
| 51 | } |
| 52 | |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 53 | static struct led_classdev wrap_power_led = { |
Sven Wegener | 6af4f55 | 2008-10-13 10:43:47 +0100 | [diff] [blame] | 54 | .name = "wrap::power", |
| 55 | .brightness_set = wrap_power_led_set, |
| 56 | .default_trigger = "default-on", |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 57 | .flags = LED_CORE_SUSPENDRESUME, |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 60 | static struct led_classdev wrap_error_led = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 61 | .name = "wrap::error", |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 62 | .brightness_set = wrap_error_led_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 63 | .flags = LED_CORE_SUSPENDRESUME, |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static struct led_classdev wrap_extra_led = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 67 | .name = "wrap::extra", |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 68 | .brightness_set = wrap_extra_led_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 69 | .flags = LED_CORE_SUSPENDRESUME, |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 72 | static int wrap_led_probe(struct platform_device *pdev) |
| 73 | { |
| 74 | int ret; |
| 75 | |
Fida Mohammad | e9aadb8 | 2015-10-21 03:58:35 -0700 | [diff] [blame] | 76 | ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led); |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 77 | if (ret < 0) |
| 78 | return ret; |
| 79 | |
Fida Mohammad | e9aadb8 | 2015-10-21 03:58:35 -0700 | [diff] [blame] | 80 | ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led); |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 81 | if (ret < 0) |
Fida Mohammad | e9aadb8 | 2015-10-21 03:58:35 -0700 | [diff] [blame] | 82 | return ret; |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 83 | |
Fida Mohammad | e9aadb8 | 2015-10-21 03:58:35 -0700 | [diff] [blame] | 84 | return devm_led_classdev_register(&pdev->dev, &wrap_extra_led); |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static struct platform_driver wrap_led_driver = { |
| 88 | .probe = wrap_led_probe, |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 89 | .driver = { |
| 90 | .name = DRVNAME, |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 91 | }, |
| 92 | }; |
| 93 | |
| 94 | static int __init wrap_led_init(void) |
| 95 | { |
| 96 | int ret; |
| 97 | |
| 98 | if (!scx200_gpio_present()) { |
| 99 | ret = -ENODEV; |
| 100 | goto out; |
| 101 | } |
| 102 | |
| 103 | ret = platform_driver_register(&wrap_led_driver); |
| 104 | if (ret < 0) |
| 105 | goto out; |
| 106 | |
| 107 | pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); |
| 108 | if (IS_ERR(pdev)) { |
| 109 | ret = PTR_ERR(pdev); |
| 110 | platform_driver_unregister(&wrap_led_driver); |
| 111 | goto out; |
| 112 | } |
| 113 | |
| 114 | out: |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | static void __exit wrap_led_exit(void) |
| 119 | { |
| 120 | platform_device_unregister(pdev); |
| 121 | platform_driver_unregister(&wrap_led_driver); |
| 122 | } |
| 123 | |
| 124 | module_init(wrap_led_init); |
| 125 | module_exit(wrap_led_exit); |
| 126 | |
| 127 | MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>"); |
| 128 | MODULE_DESCRIPTION("PCEngines WRAP LED driver"); |
| 129 | MODULE_LICENSE("GPL"); |
| 130 | |