xref: /openbmc/linux/drivers/leds/leds-ns2.c (revision 1a59d1b8)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
211efe71fSSimon Guinot /*
311efe71fSSimon Guinot  * leds-ns2.c - Driver for the Network Space v2 (and parents) dual-GPIO LED
411efe71fSSimon Guinot  *
511efe71fSSimon Guinot  * Copyright (C) 2010 LaCie
611efe71fSSimon Guinot  *
711efe71fSSimon Guinot  * Author: Simon Guinot <sguinot@lacie.com>
811efe71fSSimon Guinot  *
911efe71fSSimon Guinot  * Based on leds-gpio.c by Raphael Assenat <raph@8d.com>
1011efe71fSSimon Guinot  */
1111efe71fSSimon Guinot 
1211efe71fSSimon Guinot #include <linux/kernel.h>
1311efe71fSSimon Guinot #include <linux/platform_device.h>
1411efe71fSSimon Guinot #include <linux/slab.h>
1511efe71fSSimon Guinot #include <linux/gpio.h>
1611efe71fSSimon Guinot #include <linux/leds.h>
1754f4dedbSPaul Gortmaker #include <linux/module.h>
18c02cecb9SArnd Bergmann #include <linux/platform_data/leds-kirkwood-ns2.h>
19c68f46ddSSachin Kamat #include <linux/of.h>
2072052fccSSimon Guinot #include <linux/of_gpio.h>
214b90432dSSimon Guinot #include "leds.h"
2211efe71fSSimon Guinot 
2311efe71fSSimon Guinot /*
24f7fafd08SVincent Donnefort  * The Network Space v2 dual-GPIO LED is wired to a CPLD. Three different LED
25f7fafd08SVincent Donnefort  * modes are available: off, on and SATA activity blinking. The LED modes are
26f7fafd08SVincent Donnefort  * controlled through two GPIOs (command and slow): each combination of values
27f7fafd08SVincent Donnefort  * for the command/slow GPIOs corresponds to a LED mode.
2811efe71fSSimon Guinot  */
2911efe71fSSimon Guinot 
3011efe71fSSimon Guinot struct ns2_led_data {
3111efe71fSSimon Guinot 	struct led_classdev	cdev;
322224f2ffSKitone Elvis Peter 	unsigned int		cmd;
332224f2ffSKitone Elvis Peter 	unsigned int		slow;
344b90432dSSimon Guinot 	bool			can_sleep;
3511efe71fSSimon Guinot 	unsigned char		sata; /* True when SATA mode active. */
3611efe71fSSimon Guinot 	rwlock_t		rw_lock; /* Lock GPIOs. */
37f7fafd08SVincent Donnefort 	int			num_modes;
38f7fafd08SVincent Donnefort 	struct ns2_led_modval	*modval;
3911efe71fSSimon Guinot };
4011efe71fSSimon Guinot 
4111efe71fSSimon Guinot static int ns2_led_get_mode(struct ns2_led_data *led_dat,
4211efe71fSSimon Guinot 			    enum ns2_led_modes *mode)
4311efe71fSSimon Guinot {
4411efe71fSSimon Guinot 	int i;
4511efe71fSSimon Guinot 	int ret = -EINVAL;
4611efe71fSSimon Guinot 	int cmd_level;
4711efe71fSSimon Guinot 	int slow_level;
4811efe71fSSimon Guinot 
494b90432dSSimon Guinot 	cmd_level = gpio_get_value_cansleep(led_dat->cmd);
504b90432dSSimon Guinot 	slow_level = gpio_get_value_cansleep(led_dat->slow);
5111efe71fSSimon Guinot 
52f7fafd08SVincent Donnefort 	for (i = 0; i < led_dat->num_modes; i++) {
53f7fafd08SVincent Donnefort 		if (cmd_level == led_dat->modval[i].cmd_level &&
54f7fafd08SVincent Donnefort 		    slow_level == led_dat->modval[i].slow_level) {
55f7fafd08SVincent Donnefort 			*mode = led_dat->modval[i].mode;
5611efe71fSSimon Guinot 			ret = 0;
5711efe71fSSimon Guinot 			break;
5811efe71fSSimon Guinot 		}
5911efe71fSSimon Guinot 	}
6011efe71fSSimon Guinot 
6111efe71fSSimon Guinot 	return ret;
6211efe71fSSimon Guinot }
6311efe71fSSimon Guinot 
6411efe71fSSimon Guinot static void ns2_led_set_mode(struct ns2_led_data *led_dat,
6511efe71fSSimon Guinot 			     enum ns2_led_modes mode)
6611efe71fSSimon Guinot {
6711efe71fSSimon Guinot 	int i;
684b90432dSSimon Guinot 	bool found = false;
69f539dfedSSimon Guinot 	unsigned long flags;
7011efe71fSSimon Guinot 
714b90432dSSimon Guinot 	for (i = 0; i < led_dat->num_modes; i++)
724b90432dSSimon Guinot 		if (mode == led_dat->modval[i].mode) {
734b90432dSSimon Guinot 			found = true;
744b90432dSSimon Guinot 			break;
754b90432dSSimon Guinot 		}
764b90432dSSimon Guinot 
774b90432dSSimon Guinot 	if (!found)
784b90432dSSimon Guinot 		return;
794b90432dSSimon Guinot 
80f539dfedSSimon Guinot 	write_lock_irqsave(&led_dat->rw_lock, flags);
8111efe71fSSimon Guinot 
824b90432dSSimon Guinot 	if (!led_dat->can_sleep) {
8311efe71fSSimon Guinot 		gpio_set_value(led_dat->cmd,
84f7fafd08SVincent Donnefort 			       led_dat->modval[i].cmd_level);
8511efe71fSSimon Guinot 		gpio_set_value(led_dat->slow,
86f7fafd08SVincent Donnefort 			       led_dat->modval[i].slow_level);
874b90432dSSimon Guinot 		goto exit_unlock;
8811efe71fSSimon Guinot 	}
8911efe71fSSimon Guinot 
90c29e650bSJacek Anaszewski 	gpio_set_value_cansleep(led_dat->cmd, led_dat->modval[i].cmd_level);
91c29e650bSJacek Anaszewski 	gpio_set_value_cansleep(led_dat->slow, led_dat->modval[i].slow_level);
924b90432dSSimon Guinot 
934b90432dSSimon Guinot exit_unlock:
94f539dfedSSimon Guinot 	write_unlock_irqrestore(&led_dat->rw_lock, flags);
9511efe71fSSimon Guinot }
9611efe71fSSimon Guinot 
9711efe71fSSimon Guinot static void ns2_led_set(struct led_classdev *led_cdev,
9811efe71fSSimon Guinot 			enum led_brightness value)
9911efe71fSSimon Guinot {
10011efe71fSSimon Guinot 	struct ns2_led_data *led_dat =
10111efe71fSSimon Guinot 		container_of(led_cdev, struct ns2_led_data, cdev);
10211efe71fSSimon Guinot 	enum ns2_led_modes mode;
10311efe71fSSimon Guinot 
10411efe71fSSimon Guinot 	if (value == LED_OFF)
10511efe71fSSimon Guinot 		mode = NS_V2_LED_OFF;
10611efe71fSSimon Guinot 	else if (led_dat->sata)
10711efe71fSSimon Guinot 		mode = NS_V2_LED_SATA;
10811efe71fSSimon Guinot 	else
10911efe71fSSimon Guinot 		mode = NS_V2_LED_ON;
11011efe71fSSimon Guinot 
11111efe71fSSimon Guinot 	ns2_led_set_mode(led_dat, mode);
11211efe71fSSimon Guinot }
11311efe71fSSimon Guinot 
114c29e650bSJacek Anaszewski static int ns2_led_set_blocking(struct led_classdev *led_cdev,
115c29e650bSJacek Anaszewski 			enum led_brightness value)
116c29e650bSJacek Anaszewski {
117c29e650bSJacek Anaszewski 	ns2_led_set(led_cdev, value);
118c29e650bSJacek Anaszewski 	return 0;
119c29e650bSJacek Anaszewski }
120c29e650bSJacek Anaszewski 
12111efe71fSSimon Guinot static ssize_t ns2_led_sata_store(struct device *dev,
12211efe71fSSimon Guinot 				  struct device_attribute *attr,
12311efe71fSSimon Guinot 				  const char *buff, size_t count)
12411efe71fSSimon Guinot {
125e5971bbcSSimon Guinot 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
126e5971bbcSSimon Guinot 	struct ns2_led_data *led_dat =
127e5971bbcSSimon Guinot 		container_of(led_cdev, struct ns2_led_data, cdev);
12811efe71fSSimon Guinot 	int ret;
12911efe71fSSimon Guinot 	unsigned long enable;
13011efe71fSSimon Guinot 
1313874350cSJingoo Han 	ret = kstrtoul(buff, 10, &enable);
13211efe71fSSimon Guinot 	if (ret < 0)
13311efe71fSSimon Guinot 		return ret;
13411efe71fSSimon Guinot 
13511efe71fSSimon Guinot 	enable = !!enable;
13611efe71fSSimon Guinot 
13711efe71fSSimon Guinot 	if (led_dat->sata == enable)
1384b90432dSSimon Guinot 		goto exit;
13911efe71fSSimon Guinot 
14011efe71fSSimon Guinot 	led_dat->sata = enable;
14111efe71fSSimon Guinot 
1424b90432dSSimon Guinot 	if (!led_get_brightness(led_cdev))
1434b90432dSSimon Guinot 		goto exit;
1444b90432dSSimon Guinot 
1454b90432dSSimon Guinot 	if (enable)
1464b90432dSSimon Guinot 		ns2_led_set_mode(led_dat, NS_V2_LED_SATA);
1474b90432dSSimon Guinot 	else
1484b90432dSSimon Guinot 		ns2_led_set_mode(led_dat, NS_V2_LED_ON);
1494b90432dSSimon Guinot 
1504b90432dSSimon Guinot exit:
15111efe71fSSimon Guinot 	return count;
15211efe71fSSimon Guinot }
15311efe71fSSimon Guinot 
15411efe71fSSimon Guinot static ssize_t ns2_led_sata_show(struct device *dev,
15511efe71fSSimon Guinot 				 struct device_attribute *attr, char *buf)
15611efe71fSSimon Guinot {
157e5971bbcSSimon Guinot 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
158e5971bbcSSimon Guinot 	struct ns2_led_data *led_dat =
159e5971bbcSSimon Guinot 		container_of(led_cdev, struct ns2_led_data, cdev);
16011efe71fSSimon Guinot 
16111efe71fSSimon Guinot 	return sprintf(buf, "%d\n", led_dat->sata);
16211efe71fSSimon Guinot }
16311efe71fSSimon Guinot 
16411efe71fSSimon Guinot static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
16511efe71fSSimon Guinot 
166475f8548SJohan Hovold static struct attribute *ns2_led_attrs[] = {
167475f8548SJohan Hovold 	&dev_attr_sata.attr,
168475f8548SJohan Hovold 	NULL
169475f8548SJohan Hovold };
170475f8548SJohan Hovold ATTRIBUTE_GROUPS(ns2_led);
171475f8548SJohan Hovold 
17298ea1ea2SBill Pemberton static int
17311efe71fSSimon Guinot create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
17411efe71fSSimon Guinot 	       const struct ns2_led *template)
17511efe71fSSimon Guinot {
17611efe71fSSimon Guinot 	int ret;
17711efe71fSSimon Guinot 	enum ns2_led_modes mode;
17811efe71fSSimon Guinot 
17904195823SSachin Kamat 	ret = devm_gpio_request_one(&pdev->dev, template->cmd,
1804b90432dSSimon Guinot 			gpio_get_value_cansleep(template->cmd) ?
1819d04cbaaSJingoo Han 			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
18231c3dc74SJingoo Han 			template->name);
18311efe71fSSimon Guinot 	if (ret) {
18411efe71fSSimon Guinot 		dev_err(&pdev->dev, "%s: failed to setup command GPIO\n",
18511efe71fSSimon Guinot 			template->name);
18631c3dc74SJingoo Han 		return ret;
18711efe71fSSimon Guinot 	}
18811efe71fSSimon Guinot 
18904195823SSachin Kamat 	ret = devm_gpio_request_one(&pdev->dev, template->slow,
1904b90432dSSimon Guinot 			gpio_get_value_cansleep(template->slow) ?
1919d04cbaaSJingoo Han 			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
19231c3dc74SJingoo Han 			template->name);
19311efe71fSSimon Guinot 	if (ret) {
19411efe71fSSimon Guinot 		dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n",
19511efe71fSSimon Guinot 			template->name);
19604195823SSachin Kamat 		return ret;
19711efe71fSSimon Guinot 	}
19811efe71fSSimon Guinot 
19911efe71fSSimon Guinot 	rwlock_init(&led_dat->rw_lock);
20011efe71fSSimon Guinot 
20111efe71fSSimon Guinot 	led_dat->cdev.name = template->name;
20211efe71fSSimon Guinot 	led_dat->cdev.default_trigger = template->default_trigger;
20311efe71fSSimon Guinot 	led_dat->cdev.blink_set = NULL;
20411efe71fSSimon Guinot 	led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
205475f8548SJohan Hovold 	led_dat->cdev.groups = ns2_led_groups;
20611efe71fSSimon Guinot 	led_dat->cmd = template->cmd;
20711efe71fSSimon Guinot 	led_dat->slow = template->slow;
2084b90432dSSimon Guinot 	led_dat->can_sleep = gpio_cansleep(led_dat->cmd) |
2094b90432dSSimon Guinot 				gpio_cansleep(led_dat->slow);
210c29e650bSJacek Anaszewski 	if (led_dat->can_sleep)
211c29e650bSJacek Anaszewski 		led_dat->cdev.brightness_set_blocking = ns2_led_set_blocking;
212c29e650bSJacek Anaszewski 	else
213c29e650bSJacek Anaszewski 		led_dat->cdev.brightness_set = ns2_led_set;
214f7fafd08SVincent Donnefort 	led_dat->modval = template->modval;
215f7fafd08SVincent Donnefort 	led_dat->num_modes = template->num_modes;
21611efe71fSSimon Guinot 
21711efe71fSSimon Guinot 	ret = ns2_led_get_mode(led_dat, &mode);
21811efe71fSSimon Guinot 	if (ret < 0)
21904195823SSachin Kamat 		return ret;
22011efe71fSSimon Guinot 
22111efe71fSSimon Guinot 	/* Set LED initial state. */
22211efe71fSSimon Guinot 	led_dat->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
22311efe71fSSimon Guinot 	led_dat->cdev.brightness =
22411efe71fSSimon Guinot 		(mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
22511efe71fSSimon Guinot 
22611efe71fSSimon Guinot 	ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
22711efe71fSSimon Guinot 	if (ret < 0)
22804195823SSachin Kamat 		return ret;
22911efe71fSSimon Guinot 
23011efe71fSSimon Guinot 	return 0;
23111efe71fSSimon Guinot }
23211efe71fSSimon Guinot 
233b8cd742aSArnd Bergmann static void delete_ns2_led(struct ns2_led_data *led_dat)
23411efe71fSSimon Guinot {
23511efe71fSSimon Guinot 	led_classdev_unregister(&led_dat->cdev);
23611efe71fSSimon Guinot }
23711efe71fSSimon Guinot 
23872052fccSSimon Guinot #ifdef CONFIG_OF_GPIO
23972052fccSSimon Guinot /*
24072052fccSSimon Guinot  * Translate OpenFirmware node properties into platform_data.
24172052fccSSimon Guinot  */
242cf4af012SLinus Torvalds static int
24372052fccSSimon Guinot ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
24472052fccSSimon Guinot {
24572052fccSSimon Guinot 	struct device_node *np = dev->of_node;
24672052fccSSimon Guinot 	struct device_node *child;
247f7fafd08SVincent Donnefort 	struct ns2_led *led, *leds;
24872052fccSSimon Guinot 	int num_leds = 0;
24972052fccSSimon Guinot 
25072052fccSSimon Guinot 	num_leds = of_get_child_count(np);
25172052fccSSimon Guinot 	if (!num_leds)
25272052fccSSimon Guinot 		return -ENODEV;
25372052fccSSimon Guinot 
254a86854d0SKees Cook 	leds = devm_kcalloc(dev, num_leds, sizeof(struct ns2_led),
25572052fccSSimon Guinot 			    GFP_KERNEL);
25672052fccSSimon Guinot 	if (!leds)
25772052fccSSimon Guinot 		return -ENOMEM;
25872052fccSSimon Guinot 
259f7fafd08SVincent Donnefort 	led = leds;
26072052fccSSimon Guinot 	for_each_child_of_node(np, child) {
26172052fccSSimon Guinot 		const char *string;
262f7fafd08SVincent Donnefort 		int ret, i, num_modes;
263f7fafd08SVincent Donnefort 		struct ns2_led_modval *modval;
26472052fccSSimon Guinot 
26572052fccSSimon Guinot 		ret = of_get_named_gpio(child, "cmd-gpio", 0);
26672052fccSSimon Guinot 		if (ret < 0)
26772052fccSSimon Guinot 			return ret;
268f7fafd08SVincent Donnefort 		led->cmd = ret;
26972052fccSSimon Guinot 		ret = of_get_named_gpio(child, "slow-gpio", 0);
27072052fccSSimon Guinot 		if (ret < 0)
27172052fccSSimon Guinot 			return ret;
272f7fafd08SVincent Donnefort 		led->slow = ret;
27372052fccSSimon Guinot 		ret = of_property_read_string(child, "label", &string);
274f7fafd08SVincent Donnefort 		led->name = (ret == 0) ? string : child->name;
27572052fccSSimon Guinot 		ret = of_property_read_string(child, "linux,default-trigger",
27672052fccSSimon Guinot 					      &string);
27772052fccSSimon Guinot 		if (ret == 0)
278f7fafd08SVincent Donnefort 			led->default_trigger = string;
27972052fccSSimon Guinot 
280f7fafd08SVincent Donnefort 		ret = of_property_count_u32_elems(child, "modes-map");
281f7fafd08SVincent Donnefort 		if (ret < 0 || ret % 3) {
282f7fafd08SVincent Donnefort 			dev_err(dev,
283f7fafd08SVincent Donnefort 				"Missing or malformed modes-map property\n");
284f7fafd08SVincent Donnefort 			return -EINVAL;
285f7fafd08SVincent Donnefort 		}
286f7fafd08SVincent Donnefort 
287f7fafd08SVincent Donnefort 		num_modes = ret / 3;
288a86854d0SKees Cook 		modval = devm_kcalloc(dev,
289a86854d0SKees Cook 				      num_modes,
290a86854d0SKees Cook 				      sizeof(struct ns2_led_modval),
291f7fafd08SVincent Donnefort 				      GFP_KERNEL);
292f7fafd08SVincent Donnefort 		if (!modval)
293f7fafd08SVincent Donnefort 			return -ENOMEM;
294f7fafd08SVincent Donnefort 
295f7fafd08SVincent Donnefort 		for (i = 0; i < num_modes; i++) {
296f7fafd08SVincent Donnefort 			of_property_read_u32_index(child,
297f7fafd08SVincent Donnefort 						"modes-map", 3 * i,
298f7fafd08SVincent Donnefort 						(u32 *) &modval[i].mode);
299f7fafd08SVincent Donnefort 			of_property_read_u32_index(child,
300f7fafd08SVincent Donnefort 						"modes-map", 3 * i + 1,
301f7fafd08SVincent Donnefort 						(u32 *) &modval[i].cmd_level);
302f7fafd08SVincent Donnefort 			of_property_read_u32_index(child,
303f7fafd08SVincent Donnefort 						"modes-map", 3 * i + 2,
304f7fafd08SVincent Donnefort 						(u32 *) &modval[i].slow_level);
305f7fafd08SVincent Donnefort 		}
306f7fafd08SVincent Donnefort 
307f7fafd08SVincent Donnefort 		led->num_modes = num_modes;
308f7fafd08SVincent Donnefort 		led->modval = modval;
309f7fafd08SVincent Donnefort 
310f7fafd08SVincent Donnefort 		led++;
31172052fccSSimon Guinot 	}
31272052fccSSimon Guinot 
31372052fccSSimon Guinot 	pdata->leds = leds;
31472052fccSSimon Guinot 	pdata->num_leds = num_leds;
31572052fccSSimon Guinot 
31672052fccSSimon Guinot 	return 0;
31772052fccSSimon Guinot }
31872052fccSSimon Guinot 
31972052fccSSimon Guinot static const struct of_device_id of_ns2_leds_match[] = {
32072052fccSSimon Guinot 	{ .compatible = "lacie,ns2-leds", },
32172052fccSSimon Guinot 	{},
32272052fccSSimon Guinot };
32398f9cc7fSLuis de Bethencourt MODULE_DEVICE_TABLE(of, of_ns2_leds_match);
32472052fccSSimon Guinot #endif /* CONFIG_OF_GPIO */
32572052fccSSimon Guinot 
3263de1929bSSimon Guinot struct ns2_led_priv {
3273de1929bSSimon Guinot 	int num_leds;
3283de1929bSSimon Guinot 	struct ns2_led_data leds_data[];
3293de1929bSSimon Guinot };
3303de1929bSSimon Guinot 
3313de1929bSSimon Guinot static inline int sizeof_ns2_led_priv(int num_leds)
3323de1929bSSimon Guinot {
3333de1929bSSimon Guinot 	return sizeof(struct ns2_led_priv) +
3343de1929bSSimon Guinot 		      (sizeof(struct ns2_led_data) * num_leds);
3353de1929bSSimon Guinot }
3363de1929bSSimon Guinot 
33798ea1ea2SBill Pemberton static int ns2_led_probe(struct platform_device *pdev)
33811efe71fSSimon Guinot {
33987aae1eaSJingoo Han 	struct ns2_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
3403de1929bSSimon Guinot 	struct ns2_led_priv *priv;
34111efe71fSSimon Guinot 	int i;
34211efe71fSSimon Guinot 	int ret;
34311efe71fSSimon Guinot 
34472052fccSSimon Guinot #ifdef CONFIG_OF_GPIO
34572052fccSSimon Guinot 	if (!pdata) {
34672052fccSSimon Guinot 		pdata = devm_kzalloc(&pdev->dev,
34772052fccSSimon Guinot 				     sizeof(struct ns2_led_platform_data),
34872052fccSSimon Guinot 				     GFP_KERNEL);
34972052fccSSimon Guinot 		if (!pdata)
35072052fccSSimon Guinot 			return -ENOMEM;
35172052fccSSimon Guinot 
35272052fccSSimon Guinot 		ret = ns2_leds_get_of_pdata(&pdev->dev, pdata);
35372052fccSSimon Guinot 		if (ret)
35472052fccSSimon Guinot 			return ret;
35572052fccSSimon Guinot 	}
35672052fccSSimon Guinot #else
35711efe71fSSimon Guinot 	if (!pdata)
35811efe71fSSimon Guinot 		return -EINVAL;
35972052fccSSimon Guinot #endif /* CONFIG_OF_GPIO */
36011efe71fSSimon Guinot 
3613de1929bSSimon Guinot 	priv = devm_kzalloc(&pdev->dev,
3623de1929bSSimon Guinot 			    sizeof_ns2_led_priv(pdata->num_leds), GFP_KERNEL);
3633de1929bSSimon Guinot 	if (!priv)
36411efe71fSSimon Guinot 		return -ENOMEM;
3653de1929bSSimon Guinot 	priv->num_leds = pdata->num_leds;
36611efe71fSSimon Guinot 
3673de1929bSSimon Guinot 	for (i = 0; i < priv->num_leds; i++) {
3683de1929bSSimon Guinot 		ret = create_ns2_led(pdev, &priv->leds_data[i],
3693de1929bSSimon Guinot 				     &pdata->leds[i]);
370a209f766SBryan Wu 		if (ret < 0) {
371a209f766SBryan Wu 			for (i = i - 1; i >= 0; i--)
3723de1929bSSimon Guinot 				delete_ns2_led(&priv->leds_data[i]);
373a209f766SBryan Wu 			return ret;
374a209f766SBryan Wu 		}
37511efe71fSSimon Guinot 	}
37611efe71fSSimon Guinot 
3773de1929bSSimon Guinot 	platform_set_drvdata(pdev, priv);
37811efe71fSSimon Guinot 
37911efe71fSSimon Guinot 	return 0;
38011efe71fSSimon Guinot }
38111efe71fSSimon Guinot 
382678e8a6bSBill Pemberton static int ns2_led_remove(struct platform_device *pdev)
38311efe71fSSimon Guinot {
38411efe71fSSimon Guinot 	int i;
3853de1929bSSimon Guinot 	struct ns2_led_priv *priv;
38611efe71fSSimon Guinot 
3873de1929bSSimon Guinot 	priv = platform_get_drvdata(pdev);
38811efe71fSSimon Guinot 
3893de1929bSSimon Guinot 	for (i = 0; i < priv->num_leds; i++)
3903de1929bSSimon Guinot 		delete_ns2_led(&priv->leds_data[i]);
39111efe71fSSimon Guinot 
39211efe71fSSimon Guinot 	return 0;
39311efe71fSSimon Guinot }
39411efe71fSSimon Guinot 
39511efe71fSSimon Guinot static struct platform_driver ns2_led_driver = {
39611efe71fSSimon Guinot 	.probe		= ns2_led_probe,
397df07cf81SBill Pemberton 	.remove		= ns2_led_remove,
39811efe71fSSimon Guinot 	.driver		= {
39911efe71fSSimon Guinot 		.name		= "leds-ns2",
40072052fccSSimon Guinot 		.of_match_table	= of_match_ptr(of_ns2_leds_match),
40111efe71fSSimon Guinot 	},
40211efe71fSSimon Guinot };
40311efe71fSSimon Guinot 
404892a8843SAxel Lin module_platform_driver(ns2_led_driver);
40511efe71fSSimon Guinot 
40611efe71fSSimon Guinot MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>");
40711efe71fSSimon Guinot MODULE_DESCRIPTION("Network Space v2 LED driver");
40811efe71fSSimon Guinot MODULE_LICENSE("GPL");
409892a8843SAxel Lin MODULE_ALIAS("platform:leds-ns2");
410