Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * LEDs driver for GPIOs |
| 3 | * |
| 4 | * Copyright (C) 2007 8D Technologies inc. |
| 5 | * Raphael Assenat <raph@8d.com> |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008 Freescale Semiconductor, Inc. |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 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 | */ |
Xiubo Li | 4cc7234 | 2014-09-28 01:57:14 -0700 | [diff] [blame] | 13 | #include <linux/err.h> |
Mark Brown | 16db7f9 | 2012-03-23 15:02:11 -0700 | [diff] [blame] | 14 | #include <linux/gpio.h> |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 15 | #include <linux/gpio/consumer.h> |
Xiubo Li | 4cc7234 | 2014-09-28 01:57:14 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 17 | #include <linux/leds.h> |
Xiubo Li | 4cc7234 | 2014-09-28 01:57:14 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
Xiubo Li | 4cc7234 | 2014-09-28 01:57:14 -0700 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 20 | #include <linux/property.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
David Brownell | 0085227 | 2007-05-10 10:51:41 +0100 | [diff] [blame] | 22 | #include <linux/workqueue.h> |
| 23 | |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 24 | struct gpio_led_data { |
| 25 | struct led_classdev cdev; |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 26 | struct gpio_desc *gpiod; |
David Brownell | 0085227 | 2007-05-10 10:51:41 +0100 | [diff] [blame] | 27 | struct work_struct work; |
| 28 | u8 new_level; |
| 29 | u8 can_sleep; |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 30 | u8 blinking; |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 31 | int (*platform_gpio_blink_set)(struct gpio_desc *desc, int state, |
Herbert Valerio Riedel | ca3259b | 2008-03-09 23:48:25 +0000 | [diff] [blame] | 32 | unsigned long *delay_on, unsigned long *delay_off); |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
David Brownell | 0085227 | 2007-05-10 10:51:41 +0100 | [diff] [blame] | 35 | static void gpio_led_work(struct work_struct *work) |
| 36 | { |
Xiubo Li | a4c84e6 | 2014-09-28 01:57:16 -0700 | [diff] [blame] | 37 | struct gpio_led_data *led_dat = |
David Brownell | 0085227 | 2007-05-10 10:51:41 +0100 | [diff] [blame] | 38 | container_of(work, struct gpio_led_data, work); |
| 39 | |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 40 | if (led_dat->blinking) { |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 41 | led_dat->platform_gpio_blink_set(led_dat->gpiod, |
| 42 | led_dat->new_level, NULL, NULL); |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 43 | led_dat->blinking = 0; |
| 44 | } else |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 45 | gpiod_set_value_cansleep(led_dat->gpiod, led_dat->new_level); |
David Brownell | 0085227 | 2007-05-10 10:51:41 +0100 | [diff] [blame] | 46 | } |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 47 | |
| 48 | static void gpio_led_set(struct led_classdev *led_cdev, |
| 49 | enum led_brightness value) |
| 50 | { |
| 51 | struct gpio_led_data *led_dat = |
| 52 | container_of(led_cdev, struct gpio_led_data, cdev); |
| 53 | int level; |
| 54 | |
| 55 | if (value == LED_OFF) |
| 56 | level = 0; |
| 57 | else |
| 58 | level = 1; |
| 59 | |
David Brownell | 306dd85 | 2008-03-27 00:59:02 +0000 | [diff] [blame] | 60 | /* Setting GPIOs with I2C/etc requires a task context, and we don't |
| 61 | * seem to have a reliable way to know if we're already in one; so |
| 62 | * let's just assume the worst. |
| 63 | */ |
David Brownell | 0085227 | 2007-05-10 10:51:41 +0100 | [diff] [blame] | 64 | if (led_dat->can_sleep) { |
David Brownell | 306dd85 | 2008-03-27 00:59:02 +0000 | [diff] [blame] | 65 | led_dat->new_level = level; |
| 66 | schedule_work(&led_dat->work); |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 67 | } else { |
| 68 | if (led_dat->blinking) { |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 69 | led_dat->platform_gpio_blink_set(led_dat->gpiod, level, |
| 70 | NULL, NULL); |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 71 | led_dat->blinking = 0; |
| 72 | } else |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 73 | gpiod_set_value(led_dat->gpiod, level); |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 74 | } |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Herbert Valerio Riedel | ca3259b | 2008-03-09 23:48:25 +0000 | [diff] [blame] | 77 | static int gpio_blink_set(struct led_classdev *led_cdev, |
| 78 | unsigned long *delay_on, unsigned long *delay_off) |
| 79 | { |
| 80 | struct gpio_led_data *led_dat = |
| 81 | container_of(led_cdev, struct gpio_led_data, cdev); |
| 82 | |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 83 | led_dat->blinking = 1; |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 84 | return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK, |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 85 | delay_on, delay_off); |
Herbert Valerio Riedel | ca3259b | 2008-03-09 23:48:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 88 | static int create_gpio_led(const struct gpio_led *template, |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 89 | struct gpio_led_data *led_dat, struct device *parent, |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 90 | int (*blink_set)(struct gpio_desc *, int, unsigned long *, |
| 91 | unsigned long *)) |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 92 | { |
Trent Piepho | ed88bae | 2009-05-12 15:33:12 -0700 | [diff] [blame] | 93 | int ret, state; |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 94 | |
Geert Uytterhoeven | ec98a49 | 2014-11-06 12:23:23 +0100 | [diff] [blame] | 95 | led_dat->gpiod = template->gpiod; |
| 96 | if (!led_dat->gpiod) { |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 97 | /* |
| 98 | * This is the legacy code path for platform code that |
| 99 | * still uses GPIO numbers. Ultimately we would like to get |
| 100 | * rid of this block completely. |
| 101 | */ |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 102 | unsigned long flags = 0; |
Dmitry Eremin-Solenikov | 0b4634f | 2009-11-16 01:48:32 +0300 | [diff] [blame] | 103 | |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 104 | /* skip leds that aren't available */ |
| 105 | if (!gpio_is_valid(template->gpio)) { |
| 106 | dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n", |
| 107 | template->gpio, template->name); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | if (template->active_low) |
| 112 | flags |= GPIOF_ACTIVE_LOW; |
| 113 | |
| 114 | ret = devm_gpio_request_one(parent, template->gpio, flags, |
| 115 | template->name); |
| 116 | if (ret < 0) |
| 117 | return ret; |
| 118 | |
| 119 | led_dat->gpiod = gpio_to_desc(template->gpio); |
| 120 | if (IS_ERR(led_dat->gpiod)) |
| 121 | return PTR_ERR(led_dat->gpiod); |
David Brownell | d379ee8 | 2009-03-05 16:46:44 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 124 | led_dat->cdev.name = template->name; |
| 125 | led_dat->cdev.default_trigger = template->default_trigger; |
Geert Uytterhoeven | ec98a49 | 2014-11-06 12:23:23 +0100 | [diff] [blame] | 126 | led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod); |
Benjamin Herrenschmidt | 2146325 | 2010-05-22 20:54:55 +1000 | [diff] [blame] | 127 | led_dat->blinking = 0; |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 128 | if (blink_set) { |
| 129 | led_dat->platform_gpio_blink_set = blink_set; |
| 130 | led_dat->cdev.blink_set = gpio_blink_set; |
| 131 | } |
| 132 | led_dat->cdev.brightness_set = gpio_led_set; |
Trent Piepho | ed88bae | 2009-05-12 15:33:12 -0700 | [diff] [blame] | 133 | if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 134 | state = !!gpiod_get_value_cansleep(led_dat->gpiod); |
Trent Piepho | ed88bae | 2009-05-12 15:33:12 -0700 | [diff] [blame] | 135 | else |
| 136 | state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); |
| 137 | led_dat->cdev.brightness = state ? LED_FULL : LED_OFF; |
Richard Purdie | defb512 | 2009-02-17 15:04:07 +0000 | [diff] [blame] | 138 | if (!template->retain_state_suspended) |
| 139 | led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 140 | |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 141 | ret = gpiod_direction_output(led_dat->gpiod, state); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 142 | if (ret < 0) |
Jingoo Han | a99d76f | 2012-10-23 05:17:11 -0700 | [diff] [blame] | 143 | return ret; |
| 144 | |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 145 | INIT_WORK(&led_dat->work, gpio_led_work); |
| 146 | |
Mika Westerberg | 5c51277 | 2014-10-27 23:29:32 +0100 | [diff] [blame] | 147 | return led_classdev_register(parent, &led_dat->cdev); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static void delete_gpio_led(struct gpio_led_data *led) |
| 151 | { |
| 152 | led_classdev_unregister(&led->cdev); |
| 153 | cancel_work_sync(&led->work); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 156 | struct gpio_leds_priv { |
| 157 | int num_leds; |
| 158 | struct gpio_led_data leds[]; |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 161 | static inline int sizeof_gpio_leds_priv(int num_leds) |
| 162 | { |
| 163 | return sizeof(struct gpio_leds_priv) + |
| 164 | (sizeof(struct gpio_led_data) * num_leds); |
| 165 | } |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 166 | |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 167 | static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 168 | { |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 169 | struct device *dev = &pdev->dev; |
| 170 | struct fwnode_handle *child; |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 171 | struct gpio_leds_priv *priv; |
Tobias Klauser | 127aedc | 2012-08-21 17:21:53 +0800 | [diff] [blame] | 172 | int count, ret; |
Fabio Estevam | 29470ea | 2014-12-04 02:28:19 +0100 | [diff] [blame] | 173 | struct device_node *np; |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 174 | |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 175 | count = device_get_child_node_count(dev); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 176 | if (!count) |
Roland Stigge | 04553e9 | 2012-10-28 08:34:59 -0700 | [diff] [blame] | 177 | return ERR_PTR(-ENODEV); |
| 178 | |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 179 | priv = devm_kzalloc(dev, sizeof_gpio_leds_priv(count), GFP_KERNEL); |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 180 | if (!priv) |
Roland Stigge | 04553e9 | 2012-10-28 08:34:59 -0700 | [diff] [blame] | 181 | return ERR_PTR(-ENOMEM); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 182 | |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 183 | device_for_each_child_node(dev, child) { |
Anton Vorontsov | 0493a4f | 2010-03-11 13:58:47 -0800 | [diff] [blame] | 184 | struct gpio_led led = {}; |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 185 | const char *state = NULL; |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 186 | |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 187 | led.gpiod = devm_get_gpiod_from_child(dev, child); |
| 188 | if (IS_ERR(led.gpiod)) { |
| 189 | fwnode_handle_put(child); |
| 190 | goto err; |
| 191 | } |
| 192 | |
Fabio Estevam | 29470ea | 2014-12-04 02:28:19 +0100 | [diff] [blame] | 193 | np = of_node(child); |
| 194 | |
| 195 | if (fwnode_property_present(child, "label")) { |
| 196 | fwnode_property_read_string(child, "label", &led.name); |
| 197 | } else { |
| 198 | if (IS_ENABLED(CONFIG_OF) && !led.name && np) |
| 199 | led.name = np->name; |
| 200 | if (!led.name) |
| 201 | return ERR_PTR(-EINVAL); |
| 202 | } |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 203 | fwnode_property_read_string(child, "linux,default-trigger", |
| 204 | &led.default_trigger); |
| 205 | |
Fabio Estevam | d735d25 | 2014-12-10 01:57:07 +0100 | [diff] [blame] | 206 | if (!fwnode_property_read_string(child, "default-state", |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 207 | &state)) { |
Trent Piepho | ed88bae | 2009-05-12 15:33:12 -0700 | [diff] [blame] | 208 | if (!strcmp(state, "keep")) |
| 209 | led.default_state = LEDS_GPIO_DEFSTATE_KEEP; |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 210 | else if (!strcmp(state, "on")) |
Trent Piepho | ed88bae | 2009-05-12 15:33:12 -0700 | [diff] [blame] | 211 | led.default_state = LEDS_GPIO_DEFSTATE_ON; |
| 212 | else |
| 213 | led.default_state = LEDS_GPIO_DEFSTATE_OFF; |
| 214 | } |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 215 | |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 216 | if (fwnode_property_present(child, "retain-state-suspended")) |
Robin Gong | 4270a78 | 2014-01-20 03:41:26 -0800 | [diff] [blame] | 217 | led.retain_state_suspended = 1; |
| 218 | |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 219 | ret = create_gpio_led(&led, &priv->leds[priv->num_leds++], |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 220 | dev, NULL); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 221 | if (ret < 0) { |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 222 | fwnode_handle_put(child); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 223 | goto err; |
| 224 | } |
| 225 | } |
| 226 | |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 227 | return priv; |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 228 | |
| 229 | err: |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 230 | for (count = priv->num_leds - 2; count >= 0; count--) |
| 231 | delete_gpio_led(&priv->leds[count]); |
Roland Stigge | 04553e9 | 2012-10-28 08:34:59 -0700 | [diff] [blame] | 232 | return ERR_PTR(-ENODEV); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static const struct of_device_id of_gpio_leds_match[] = { |
| 236 | { .compatible = "gpio-leds", }, |
| 237 | {}, |
| 238 | }; |
Paolo Pisati | 472b854 | 2014-03-06 09:18:37 -0800 | [diff] [blame] | 239 | |
| 240 | MODULE_DEVICE_TABLE(of, of_gpio_leds_match); |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 241 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 242 | static int gpio_led_probe(struct platform_device *pdev) |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 243 | { |
Jingoo Han | 87aae1e | 2013-07-30 01:07:35 -0700 | [diff] [blame] | 244 | struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 245 | struct gpio_leds_priv *priv; |
| 246 | int i, ret = 0; |
| 247 | |
| 248 | if (pdata && pdata->num_leds) { |
Sachin Kamat | 198b861 | 2012-07-04 11:35:44 +0800 | [diff] [blame] | 249 | priv = devm_kzalloc(&pdev->dev, |
| 250 | sizeof_gpio_leds_priv(pdata->num_leds), |
| 251 | GFP_KERNEL); |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 252 | if (!priv) |
| 253 | return -ENOMEM; |
| 254 | |
| 255 | priv->num_leds = pdata->num_leds; |
| 256 | for (i = 0; i < priv->num_leds; i++) { |
| 257 | ret = create_gpio_led(&pdata->leds[i], |
| 258 | &priv->leds[i], |
| 259 | &pdev->dev, pdata->gpio_blink_set); |
| 260 | if (ret < 0) { |
| 261 | /* On failure: unwind the led creations */ |
| 262 | for (i = i - 1; i >= 0; i--) |
| 263 | delete_gpio_led(&priv->leds[i]); |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 264 | return ret; |
| 265 | } |
| 266 | } |
| 267 | } else { |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 268 | priv = gpio_leds_create(pdev); |
Roland Stigge | 04553e9 | 2012-10-28 08:34:59 -0700 | [diff] [blame] | 269 | if (IS_ERR(priv)) |
| 270 | return PTR_ERR(priv); |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | platform_set_drvdata(pdev, priv); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
Bill Pemberton | 678e8a6 | 2012-11-19 13:26:00 -0500 | [diff] [blame] | 278 | static int gpio_led_remove(struct platform_device *pdev) |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 279 | { |
Tobias Klauser | 59c4dce | 2012-08-16 18:36:13 +0800 | [diff] [blame] | 280 | struct gpio_leds_priv *priv = platform_get_drvdata(pdev); |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 281 | int i; |
| 282 | |
| 283 | for (i = 0; i < priv->num_leds; i++) |
| 284 | delete_gpio_led(&priv->leds[i]); |
| 285 | |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static struct platform_driver gpio_led_driver = { |
| 290 | .probe = gpio_led_probe, |
Bill Pemberton | df07cf8 | 2012-11-19 13:20:20 -0500 | [diff] [blame] | 291 | .remove = gpio_led_remove, |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 292 | .driver = { |
| 293 | .name = "leds-gpio", |
Rafael J. Wysocki | a43f2cb | 2014-10-27 23:30:10 +0100 | [diff] [blame] | 294 | .of_match_table = of_gpio_leds_match, |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 295 | }, |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 296 | }; |
Grant Likely | a314c5c | 2011-02-22 20:06:04 -0700 | [diff] [blame] | 297 | |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 298 | module_platform_driver(gpio_led_driver); |
Richard Purdie | b2bdc3e | 2009-02-02 23:04:42 +0000 | [diff] [blame] | 299 | |
Trent Piepho | a7d878a | 2009-01-10 17:26:01 +0000 | [diff] [blame] | 300 | MODULE_AUTHOR("Raphael Assenat <raph@8d.com>, Trent Piepho <tpiepho@freescale.com>"); |
Raphael Assenat | 22e03f3 | 2007-02-27 19:49:53 +0000 | [diff] [blame] | 301 | MODULE_DESCRIPTION("GPIO LED driver"); |
| 302 | MODULE_LICENSE("GPL"); |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 303 | MODULE_ALIAS("platform:leds-gpio"); |