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