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> |
| 20 | |
| 21 | #define DRVNAME "wrap-led" |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 22 | #define WRAP_POWER_LED_GPIO 2 |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 23 | #define WRAP_ERROR_LED_GPIO 3 |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 24 | #define WRAP_EXTRA_LED_GPIO 18 |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 25 | |
| 26 | static struct platform_device *pdev; |
| 27 | |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 28 | static void wrap_power_led_set(struct led_classdev *led_cdev, |
| 29 | enum led_brightness value) |
| 30 | { |
| 31 | if (value) |
| 32 | scx200_gpio_set_low(WRAP_POWER_LED_GPIO); |
| 33 | else |
| 34 | scx200_gpio_set_high(WRAP_POWER_LED_GPIO); |
| 35 | } |
| 36 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 37 | static void wrap_error_led_set(struct led_classdev *led_cdev, |
| 38 | enum led_brightness value) |
| 39 | { |
| 40 | if (value) |
| 41 | scx200_gpio_set_low(WRAP_ERROR_LED_GPIO); |
| 42 | else |
| 43 | scx200_gpio_set_high(WRAP_ERROR_LED_GPIO); |
| 44 | } |
| 45 | |
| 46 | static void wrap_extra_led_set(struct led_classdev *led_cdev, |
| 47 | enum led_brightness value) |
| 48 | { |
| 49 | if (value) |
| 50 | scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO); |
| 51 | else |
| 52 | scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO); |
| 53 | } |
| 54 | |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 55 | static struct led_classdev wrap_power_led = { |
Sven Wegener | 6af4f55 | 2008-10-13 10:43:47 +0100 | [diff] [blame] | 56 | .name = "wrap::power", |
| 57 | .brightness_set = wrap_power_led_set, |
| 58 | .default_trigger = "default-on", |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 61 | static struct led_classdev wrap_error_led = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 62 | .name = "wrap::error", |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 63 | .brightness_set = wrap_error_led_set, |
| 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, |
| 69 | }; |
| 70 | |
| 71 | #ifdef CONFIG_PM |
| 72 | static int wrap_led_suspend(struct platform_device *dev, |
| 73 | pm_message_t state) |
| 74 | { |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 75 | led_classdev_suspend(&wrap_power_led); |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 76 | led_classdev_suspend(&wrap_error_led); |
| 77 | led_classdev_suspend(&wrap_extra_led); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int wrap_led_resume(struct platform_device *dev) |
| 82 | { |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 83 | led_classdev_resume(&wrap_power_led); |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 84 | led_classdev_resume(&wrap_error_led); |
| 85 | led_classdev_resume(&wrap_extra_led); |
| 86 | return 0; |
| 87 | } |
| 88 | #else |
| 89 | #define wrap_led_suspend NULL |
| 90 | #define wrap_led_resume NULL |
| 91 | #endif |
| 92 | |
| 93 | static int wrap_led_probe(struct platform_device *pdev) |
| 94 | { |
| 95 | int ret; |
| 96 | |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 97 | ret = led_classdev_register(&pdev->dev, &wrap_power_led); |
| 98 | if (ret < 0) |
| 99 | return ret; |
| 100 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 101 | ret = led_classdev_register(&pdev->dev, &wrap_error_led); |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 102 | if (ret < 0) |
| 103 | goto err1; |
| 104 | |
| 105 | ret = led_classdev_register(&pdev->dev, &wrap_extra_led); |
| 106 | if (ret < 0) |
| 107 | goto err2; |
| 108 | |
| 109 | return ret; |
| 110 | |
| 111 | err2: |
| 112 | led_classdev_unregister(&wrap_error_led); |
| 113 | err1: |
| 114 | led_classdev_unregister(&wrap_power_led); |
| 115 | |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | static int wrap_led_remove(struct platform_device *pdev) |
| 120 | { |
Michael Loeffler | f5506a2 | 2008-01-13 23:20:52 +0000 | [diff] [blame] | 121 | led_classdev_unregister(&wrap_power_led); |
Kristian Kielhofner | 0d75565 | 2006-12-06 20:37:28 -0800 | [diff] [blame] | 122 | led_classdev_unregister(&wrap_error_led); |
| 123 | led_classdev_unregister(&wrap_extra_led); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static struct platform_driver wrap_led_driver = { |
| 128 | .probe = wrap_led_probe, |
| 129 | .remove = wrap_led_remove, |
| 130 | .suspend = wrap_led_suspend, |
| 131 | .resume = wrap_led_resume, |
| 132 | .driver = { |
| 133 | .name = DRVNAME, |
| 134 | .owner = THIS_MODULE, |
| 135 | }, |
| 136 | }; |
| 137 | |
| 138 | static int __init wrap_led_init(void) |
| 139 | { |
| 140 | int ret; |
| 141 | |
| 142 | if (!scx200_gpio_present()) { |
| 143 | ret = -ENODEV; |
| 144 | goto out; |
| 145 | } |
| 146 | |
| 147 | ret = platform_driver_register(&wrap_led_driver); |
| 148 | if (ret < 0) |
| 149 | goto out; |
| 150 | |
| 151 | pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); |
| 152 | if (IS_ERR(pdev)) { |
| 153 | ret = PTR_ERR(pdev); |
| 154 | platform_driver_unregister(&wrap_led_driver); |
| 155 | goto out; |
| 156 | } |
| 157 | |
| 158 | out: |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | static void __exit wrap_led_exit(void) |
| 163 | { |
| 164 | platform_device_unregister(pdev); |
| 165 | platform_driver_unregister(&wrap_led_driver); |
| 166 | } |
| 167 | |
| 168 | module_init(wrap_led_init); |
| 169 | module_exit(wrap_led_exit); |
| 170 | |
| 171 | MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>"); |
| 172 | MODULE_DESCRIPTION("PCEngines WRAP LED driver"); |
| 173 | MODULE_LICENSE("GPL"); |
| 174 | |