xref: /openbmc/linux/drivers/leds/leds-ns2.c (revision f7fafd083ccc340502448903aaddc76f10785c8c)
111efe71fSSimon Guinot /*
211efe71fSSimon Guinot  * leds-ns2.c - Driver for the Network Space v2 (and parents) dual-GPIO LED
311efe71fSSimon Guinot  *
411efe71fSSimon Guinot  * Copyright (C) 2010 LaCie
511efe71fSSimon Guinot  *
611efe71fSSimon Guinot  * Author: Simon Guinot <sguinot@lacie.com>
711efe71fSSimon Guinot  *
811efe71fSSimon Guinot  * Based on leds-gpio.c by Raphael Assenat <raph@8d.com>
911efe71fSSimon Guinot  *
1011efe71fSSimon Guinot  * This program is free software; you can redistribute it and/or modify
1111efe71fSSimon Guinot  * it under the terms of the GNU General Public License as published by
1211efe71fSSimon Guinot  * the Free Software Foundation; either version 2 of the License, or
1311efe71fSSimon Guinot  * (at your option) any later version.
1411efe71fSSimon Guinot  *
1511efe71fSSimon Guinot  * This program is distributed in the hope that it will be useful,
1611efe71fSSimon Guinot  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1711efe71fSSimon Guinot  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1811efe71fSSimon Guinot  * GNU General Public License for more details.
1911efe71fSSimon Guinot  *
2011efe71fSSimon Guinot  * You should have received a copy of the GNU General Public License
2111efe71fSSimon Guinot  * along with this program; if not, write to the Free Software
2211efe71fSSimon Guinot  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2311efe71fSSimon Guinot  */
2411efe71fSSimon Guinot 
2511efe71fSSimon Guinot #include <linux/kernel.h>
2611efe71fSSimon Guinot #include <linux/platform_device.h>
2711efe71fSSimon Guinot #include <linux/slab.h>
2811efe71fSSimon Guinot #include <linux/gpio.h>
2911efe71fSSimon Guinot #include <linux/leds.h>
3054f4dedbSPaul Gortmaker #include <linux/module.h>
31c02cecb9SArnd Bergmann #include <linux/platform_data/leds-kirkwood-ns2.h>
32c68f46ddSSachin Kamat #include <linux/of.h>
3372052fccSSimon Guinot #include <linux/of_gpio.h>
3411efe71fSSimon Guinot 
3511efe71fSSimon Guinot /*
36*f7fafd08SVincent Donnefort  * The Network Space v2 dual-GPIO LED is wired to a CPLD. Three different LED
37*f7fafd08SVincent Donnefort  * modes are available: off, on and SATA activity blinking. The LED modes are
38*f7fafd08SVincent Donnefort  * controlled through two GPIOs (command and slow): each combination of values
39*f7fafd08SVincent Donnefort  * for the command/slow GPIOs corresponds to a LED mode.
4011efe71fSSimon Guinot  */
4111efe71fSSimon Guinot 
4211efe71fSSimon Guinot struct ns2_led_data {
4311efe71fSSimon Guinot 	struct led_classdev	cdev;
4411efe71fSSimon Guinot 	unsigned		cmd;
4511efe71fSSimon Guinot 	unsigned		slow;
4611efe71fSSimon Guinot 	unsigned char		sata; /* True when SATA mode active. */
4711efe71fSSimon Guinot 	rwlock_t		rw_lock; /* Lock GPIOs. */
48*f7fafd08SVincent Donnefort 	int			num_modes;
49*f7fafd08SVincent Donnefort 	struct ns2_led_modval	*modval;
5011efe71fSSimon Guinot };
5111efe71fSSimon Guinot 
5211efe71fSSimon Guinot static int ns2_led_get_mode(struct ns2_led_data *led_dat,
5311efe71fSSimon Guinot 			    enum ns2_led_modes *mode)
5411efe71fSSimon Guinot {
5511efe71fSSimon Guinot 	int i;
5611efe71fSSimon Guinot 	int ret = -EINVAL;
5711efe71fSSimon Guinot 	int cmd_level;
5811efe71fSSimon Guinot 	int slow_level;
5911efe71fSSimon Guinot 
60f539dfedSSimon Guinot 	read_lock_irq(&led_dat->rw_lock);
6111efe71fSSimon Guinot 
6211efe71fSSimon Guinot 	cmd_level = gpio_get_value(led_dat->cmd);
6311efe71fSSimon Guinot 	slow_level = gpio_get_value(led_dat->slow);
6411efe71fSSimon Guinot 
65*f7fafd08SVincent Donnefort 	for (i = 0; i < led_dat->num_modes; i++) {
66*f7fafd08SVincent Donnefort 		if (cmd_level == led_dat->modval[i].cmd_level &&
67*f7fafd08SVincent Donnefort 		    slow_level == led_dat->modval[i].slow_level) {
68*f7fafd08SVincent Donnefort 			*mode = led_dat->modval[i].mode;
6911efe71fSSimon Guinot 			ret = 0;
7011efe71fSSimon Guinot 			break;
7111efe71fSSimon Guinot 		}
7211efe71fSSimon Guinot 	}
7311efe71fSSimon Guinot 
74f539dfedSSimon Guinot 	read_unlock_irq(&led_dat->rw_lock);
7511efe71fSSimon Guinot 
7611efe71fSSimon Guinot 	return ret;
7711efe71fSSimon Guinot }
7811efe71fSSimon Guinot 
7911efe71fSSimon Guinot static void ns2_led_set_mode(struct ns2_led_data *led_dat,
8011efe71fSSimon Guinot 			     enum ns2_led_modes mode)
8111efe71fSSimon Guinot {
8211efe71fSSimon Guinot 	int i;
83f539dfedSSimon Guinot 	unsigned long flags;
8411efe71fSSimon Guinot 
85f539dfedSSimon Guinot 	write_lock_irqsave(&led_dat->rw_lock, flags);
8611efe71fSSimon Guinot 
87*f7fafd08SVincent Donnefort 	for (i = 0; i < led_dat->num_modes; i++) {
88*f7fafd08SVincent Donnefort 		if (mode == led_dat->modval[i].mode) {
8911efe71fSSimon Guinot 			gpio_set_value(led_dat->cmd,
90*f7fafd08SVincent Donnefort 				       led_dat->modval[i].cmd_level);
9111efe71fSSimon Guinot 			gpio_set_value(led_dat->slow,
92*f7fafd08SVincent Donnefort 				       led_dat->modval[i].slow_level);
9311efe71fSSimon Guinot 		}
9411efe71fSSimon Guinot 	}
9511efe71fSSimon Guinot 
96f539dfedSSimon Guinot 	write_unlock_irqrestore(&led_dat->rw_lock, flags);
9711efe71fSSimon Guinot }
9811efe71fSSimon Guinot 
9911efe71fSSimon Guinot static void ns2_led_set(struct led_classdev *led_cdev,
10011efe71fSSimon Guinot 			enum led_brightness value)
10111efe71fSSimon Guinot {
10211efe71fSSimon Guinot 	struct ns2_led_data *led_dat =
10311efe71fSSimon Guinot 		container_of(led_cdev, struct ns2_led_data, cdev);
10411efe71fSSimon Guinot 	enum ns2_led_modes mode;
10511efe71fSSimon Guinot 
10611efe71fSSimon Guinot 	if (value == LED_OFF)
10711efe71fSSimon Guinot 		mode = NS_V2_LED_OFF;
10811efe71fSSimon Guinot 	else if (led_dat->sata)
10911efe71fSSimon Guinot 		mode = NS_V2_LED_SATA;
11011efe71fSSimon Guinot 	else
11111efe71fSSimon Guinot 		mode = NS_V2_LED_ON;
11211efe71fSSimon Guinot 
11311efe71fSSimon Guinot 	ns2_led_set_mode(led_dat, mode);
11411efe71fSSimon Guinot }
11511efe71fSSimon Guinot 
11611efe71fSSimon Guinot static ssize_t ns2_led_sata_store(struct device *dev,
11711efe71fSSimon Guinot 				  struct device_attribute *attr,
11811efe71fSSimon Guinot 				  const char *buff, size_t count)
11911efe71fSSimon Guinot {
120e5971bbcSSimon Guinot 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
121e5971bbcSSimon Guinot 	struct ns2_led_data *led_dat =
122e5971bbcSSimon Guinot 		container_of(led_cdev, struct ns2_led_data, cdev);
12311efe71fSSimon Guinot 	int ret;
12411efe71fSSimon Guinot 	unsigned long enable;
12511efe71fSSimon Guinot 	enum ns2_led_modes mode;
12611efe71fSSimon Guinot 
1273874350cSJingoo Han 	ret = kstrtoul(buff, 10, &enable);
12811efe71fSSimon Guinot 	if (ret < 0)
12911efe71fSSimon Guinot 		return ret;
13011efe71fSSimon Guinot 
13111efe71fSSimon Guinot 	enable = !!enable;
13211efe71fSSimon Guinot 
13311efe71fSSimon Guinot 	if (led_dat->sata == enable)
13411efe71fSSimon Guinot 		return count;
13511efe71fSSimon Guinot 
13611efe71fSSimon Guinot 	ret = ns2_led_get_mode(led_dat, &mode);
13711efe71fSSimon Guinot 	if (ret < 0)
13811efe71fSSimon Guinot 		return ret;
13911efe71fSSimon Guinot 
14011efe71fSSimon Guinot 	if (enable && mode == NS_V2_LED_ON)
14111efe71fSSimon Guinot 		ns2_led_set_mode(led_dat, NS_V2_LED_SATA);
14211efe71fSSimon Guinot 	if (!enable && mode == NS_V2_LED_SATA)
14311efe71fSSimon Guinot 		ns2_led_set_mode(led_dat, NS_V2_LED_ON);
14411efe71fSSimon Guinot 
14511efe71fSSimon Guinot 	led_dat->sata = enable;
14611efe71fSSimon Guinot 
14711efe71fSSimon Guinot 	return count;
14811efe71fSSimon Guinot }
14911efe71fSSimon Guinot 
15011efe71fSSimon Guinot static ssize_t ns2_led_sata_show(struct device *dev,
15111efe71fSSimon Guinot 				 struct device_attribute *attr, char *buf)
15211efe71fSSimon Guinot {
153e5971bbcSSimon Guinot 	struct led_classdev *led_cdev = dev_get_drvdata(dev);
154e5971bbcSSimon Guinot 	struct ns2_led_data *led_dat =
155e5971bbcSSimon Guinot 		container_of(led_cdev, struct ns2_led_data, cdev);
15611efe71fSSimon Guinot 
15711efe71fSSimon Guinot 	return sprintf(buf, "%d\n", led_dat->sata);
15811efe71fSSimon Guinot }
15911efe71fSSimon Guinot 
16011efe71fSSimon Guinot static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
16111efe71fSSimon Guinot 
162475f8548SJohan Hovold static struct attribute *ns2_led_attrs[] = {
163475f8548SJohan Hovold 	&dev_attr_sata.attr,
164475f8548SJohan Hovold 	NULL
165475f8548SJohan Hovold };
166475f8548SJohan Hovold ATTRIBUTE_GROUPS(ns2_led);
167475f8548SJohan Hovold 
16898ea1ea2SBill Pemberton static int
16911efe71fSSimon Guinot create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
17011efe71fSSimon Guinot 	       const struct ns2_led *template)
17111efe71fSSimon Guinot {
17211efe71fSSimon Guinot 	int ret;
17311efe71fSSimon Guinot 	enum ns2_led_modes mode;
17411efe71fSSimon Guinot 
17504195823SSachin Kamat 	ret = devm_gpio_request_one(&pdev->dev, template->cmd,
1769d04cbaaSJingoo Han 			gpio_get_value(template->cmd) ?
1779d04cbaaSJingoo Han 			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
17831c3dc74SJingoo Han 			template->name);
17911efe71fSSimon Guinot 	if (ret) {
18011efe71fSSimon Guinot 		dev_err(&pdev->dev, "%s: failed to setup command GPIO\n",
18111efe71fSSimon Guinot 			template->name);
18231c3dc74SJingoo Han 		return ret;
18311efe71fSSimon Guinot 	}
18411efe71fSSimon Guinot 
18504195823SSachin Kamat 	ret = devm_gpio_request_one(&pdev->dev, template->slow,
1869d04cbaaSJingoo Han 			gpio_get_value(template->slow) ?
1879d04cbaaSJingoo Han 			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
18831c3dc74SJingoo Han 			template->name);
18911efe71fSSimon Guinot 	if (ret) {
19011efe71fSSimon Guinot 		dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n",
19111efe71fSSimon Guinot 			template->name);
19204195823SSachin Kamat 		return ret;
19311efe71fSSimon Guinot 	}
19411efe71fSSimon Guinot 
19511efe71fSSimon Guinot 	rwlock_init(&led_dat->rw_lock);
19611efe71fSSimon Guinot 
19711efe71fSSimon Guinot 	led_dat->cdev.name = template->name;
19811efe71fSSimon Guinot 	led_dat->cdev.default_trigger = template->default_trigger;
19911efe71fSSimon Guinot 	led_dat->cdev.blink_set = NULL;
20011efe71fSSimon Guinot 	led_dat->cdev.brightness_set = ns2_led_set;
20111efe71fSSimon Guinot 	led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
202475f8548SJohan Hovold 	led_dat->cdev.groups = ns2_led_groups;
20311efe71fSSimon Guinot 	led_dat->cmd = template->cmd;
20411efe71fSSimon Guinot 	led_dat->slow = template->slow;
205*f7fafd08SVincent Donnefort 	led_dat->modval = template->modval;
206*f7fafd08SVincent Donnefort 	led_dat->num_modes = template->num_modes;
20711efe71fSSimon Guinot 
20811efe71fSSimon Guinot 	ret = ns2_led_get_mode(led_dat, &mode);
20911efe71fSSimon Guinot 	if (ret < 0)
21004195823SSachin Kamat 		return ret;
21111efe71fSSimon Guinot 
21211efe71fSSimon Guinot 	/* Set LED initial state. */
21311efe71fSSimon Guinot 	led_dat->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
21411efe71fSSimon Guinot 	led_dat->cdev.brightness =
21511efe71fSSimon Guinot 		(mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
21611efe71fSSimon Guinot 
21711efe71fSSimon Guinot 	ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
21811efe71fSSimon Guinot 	if (ret < 0)
21904195823SSachin Kamat 		return ret;
22011efe71fSSimon Guinot 
22111efe71fSSimon Guinot 	return 0;
22211efe71fSSimon Guinot }
22311efe71fSSimon Guinot 
224b8cd742aSArnd Bergmann static void delete_ns2_led(struct ns2_led_data *led_dat)
22511efe71fSSimon Guinot {
22611efe71fSSimon Guinot 	led_classdev_unregister(&led_dat->cdev);
22711efe71fSSimon Guinot }
22811efe71fSSimon Guinot 
22972052fccSSimon Guinot #ifdef CONFIG_OF_GPIO
23072052fccSSimon Guinot /*
23172052fccSSimon Guinot  * Translate OpenFirmware node properties into platform_data.
23272052fccSSimon Guinot  */
233cf4af012SLinus Torvalds static int
23472052fccSSimon Guinot ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
23572052fccSSimon Guinot {
23672052fccSSimon Guinot 	struct device_node *np = dev->of_node;
23772052fccSSimon Guinot 	struct device_node *child;
238*f7fafd08SVincent Donnefort 	struct ns2_led *led, *leds;
23972052fccSSimon Guinot 	int num_leds = 0;
24072052fccSSimon Guinot 
24172052fccSSimon Guinot 	num_leds = of_get_child_count(np);
24272052fccSSimon Guinot 	if (!num_leds)
24372052fccSSimon Guinot 		return -ENODEV;
24472052fccSSimon Guinot 
24572052fccSSimon Guinot 	leds = devm_kzalloc(dev, num_leds * sizeof(struct ns2_led),
24672052fccSSimon Guinot 			    GFP_KERNEL);
24772052fccSSimon Guinot 	if (!leds)
24872052fccSSimon Guinot 		return -ENOMEM;
24972052fccSSimon Guinot 
250*f7fafd08SVincent Donnefort 	led = leds;
25172052fccSSimon Guinot 	for_each_child_of_node(np, child) {
25272052fccSSimon Guinot 		const char *string;
253*f7fafd08SVincent Donnefort 		int ret, i, num_modes;
254*f7fafd08SVincent Donnefort 		struct ns2_led_modval *modval;
25572052fccSSimon Guinot 
25672052fccSSimon Guinot 		ret = of_get_named_gpio(child, "cmd-gpio", 0);
25772052fccSSimon Guinot 		if (ret < 0)
25872052fccSSimon Guinot 			return ret;
259*f7fafd08SVincent Donnefort 		led->cmd = ret;
26072052fccSSimon Guinot 		ret = of_get_named_gpio(child, "slow-gpio", 0);
26172052fccSSimon Guinot 		if (ret < 0)
26272052fccSSimon Guinot 			return ret;
263*f7fafd08SVincent Donnefort 		led->slow = ret;
26472052fccSSimon Guinot 		ret = of_property_read_string(child, "label", &string);
265*f7fafd08SVincent Donnefort 		led->name = (ret == 0) ? string : child->name;
26672052fccSSimon Guinot 		ret = of_property_read_string(child, "linux,default-trigger",
26772052fccSSimon Guinot 					      &string);
26872052fccSSimon Guinot 		if (ret == 0)
269*f7fafd08SVincent Donnefort 			led->default_trigger = string;
27072052fccSSimon Guinot 
271*f7fafd08SVincent Donnefort 		ret = of_property_count_u32_elems(child, "modes-map");
272*f7fafd08SVincent Donnefort 		if (ret < 0 || ret % 3) {
273*f7fafd08SVincent Donnefort 			dev_err(dev,
274*f7fafd08SVincent Donnefort 				"Missing or malformed modes-map property\n");
275*f7fafd08SVincent Donnefort 			return -EINVAL;
276*f7fafd08SVincent Donnefort 		}
277*f7fafd08SVincent Donnefort 
278*f7fafd08SVincent Donnefort 		num_modes = ret / 3;
279*f7fafd08SVincent Donnefort 		modval = devm_kzalloc(dev,
280*f7fafd08SVincent Donnefort 				      num_modes * sizeof(struct ns2_led_modval),
281*f7fafd08SVincent Donnefort 				      GFP_KERNEL);
282*f7fafd08SVincent Donnefort 		if (!modval)
283*f7fafd08SVincent Donnefort 			return -ENOMEM;
284*f7fafd08SVincent Donnefort 
285*f7fafd08SVincent Donnefort 		for (i = 0; i < num_modes; i++) {
286*f7fafd08SVincent Donnefort 			of_property_read_u32_index(child,
287*f7fafd08SVincent Donnefort 						"modes-map", 3 * i,
288*f7fafd08SVincent Donnefort 						(u32 *) &modval[i].mode);
289*f7fafd08SVincent Donnefort 			of_property_read_u32_index(child,
290*f7fafd08SVincent Donnefort 						"modes-map", 3 * i + 1,
291*f7fafd08SVincent Donnefort 						(u32 *) &modval[i].cmd_level);
292*f7fafd08SVincent Donnefort 			of_property_read_u32_index(child,
293*f7fafd08SVincent Donnefort 						"modes-map", 3 * i + 2,
294*f7fafd08SVincent Donnefort 						(u32 *) &modval[i].slow_level);
295*f7fafd08SVincent Donnefort 		}
296*f7fafd08SVincent Donnefort 
297*f7fafd08SVincent Donnefort 		led->num_modes = num_modes;
298*f7fafd08SVincent Donnefort 		led->modval = modval;
299*f7fafd08SVincent Donnefort 
300*f7fafd08SVincent Donnefort 		led++;
30172052fccSSimon Guinot 	}
30272052fccSSimon Guinot 
30372052fccSSimon Guinot 	pdata->leds = leds;
30472052fccSSimon Guinot 	pdata->num_leds = num_leds;
30572052fccSSimon Guinot 
30672052fccSSimon Guinot 	return 0;
30772052fccSSimon Guinot }
30872052fccSSimon Guinot 
30972052fccSSimon Guinot static const struct of_device_id of_ns2_leds_match[] = {
31072052fccSSimon Guinot 	{ .compatible = "lacie,ns2-leds", },
31172052fccSSimon Guinot 	{},
31272052fccSSimon Guinot };
31372052fccSSimon Guinot #endif /* CONFIG_OF_GPIO */
31472052fccSSimon Guinot 
3153de1929bSSimon Guinot struct ns2_led_priv {
3163de1929bSSimon Guinot 	int num_leds;
3173de1929bSSimon Guinot 	struct ns2_led_data leds_data[];
3183de1929bSSimon Guinot };
3193de1929bSSimon Guinot 
3203de1929bSSimon Guinot static inline int sizeof_ns2_led_priv(int num_leds)
3213de1929bSSimon Guinot {
3223de1929bSSimon Guinot 	return sizeof(struct ns2_led_priv) +
3233de1929bSSimon Guinot 		      (sizeof(struct ns2_led_data) * num_leds);
3243de1929bSSimon Guinot }
3253de1929bSSimon Guinot 
32698ea1ea2SBill Pemberton static int ns2_led_probe(struct platform_device *pdev)
32711efe71fSSimon Guinot {
32887aae1eaSJingoo Han 	struct ns2_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
3293de1929bSSimon Guinot 	struct ns2_led_priv *priv;
33011efe71fSSimon Guinot 	int i;
33111efe71fSSimon Guinot 	int ret;
33211efe71fSSimon Guinot 
33372052fccSSimon Guinot #ifdef CONFIG_OF_GPIO
33472052fccSSimon Guinot 	if (!pdata) {
33572052fccSSimon Guinot 		pdata = devm_kzalloc(&pdev->dev,
33672052fccSSimon Guinot 				     sizeof(struct ns2_led_platform_data),
33772052fccSSimon Guinot 				     GFP_KERNEL);
33872052fccSSimon Guinot 		if (!pdata)
33972052fccSSimon Guinot 			return -ENOMEM;
34072052fccSSimon Guinot 
34172052fccSSimon Guinot 		ret = ns2_leds_get_of_pdata(&pdev->dev, pdata);
34272052fccSSimon Guinot 		if (ret)
34372052fccSSimon Guinot 			return ret;
34472052fccSSimon Guinot 	}
34572052fccSSimon Guinot #else
34611efe71fSSimon Guinot 	if (!pdata)
34711efe71fSSimon Guinot 		return -EINVAL;
34872052fccSSimon Guinot #endif /* CONFIG_OF_GPIO */
34911efe71fSSimon Guinot 
3503de1929bSSimon Guinot 	priv = devm_kzalloc(&pdev->dev,
3513de1929bSSimon Guinot 			    sizeof_ns2_led_priv(pdata->num_leds), GFP_KERNEL);
3523de1929bSSimon Guinot 	if (!priv)
35311efe71fSSimon Guinot 		return -ENOMEM;
3543de1929bSSimon Guinot 	priv->num_leds = pdata->num_leds;
35511efe71fSSimon Guinot 
3563de1929bSSimon Guinot 	for (i = 0; i < priv->num_leds; i++) {
3573de1929bSSimon Guinot 		ret = create_ns2_led(pdev, &priv->leds_data[i],
3583de1929bSSimon Guinot 				     &pdata->leds[i]);
359a209f766SBryan Wu 		if (ret < 0) {
360a209f766SBryan Wu 			for (i = i - 1; i >= 0; i--)
3613de1929bSSimon Guinot 				delete_ns2_led(&priv->leds_data[i]);
362a209f766SBryan Wu 			return ret;
363a209f766SBryan Wu 		}
36411efe71fSSimon Guinot 	}
36511efe71fSSimon Guinot 
3663de1929bSSimon Guinot 	platform_set_drvdata(pdev, priv);
36711efe71fSSimon Guinot 
36811efe71fSSimon Guinot 	return 0;
36911efe71fSSimon Guinot }
37011efe71fSSimon Guinot 
371678e8a6bSBill Pemberton static int ns2_led_remove(struct platform_device *pdev)
37211efe71fSSimon Guinot {
37311efe71fSSimon Guinot 	int i;
3743de1929bSSimon Guinot 	struct ns2_led_priv *priv;
37511efe71fSSimon Guinot 
3763de1929bSSimon Guinot 	priv = platform_get_drvdata(pdev);
37711efe71fSSimon Guinot 
3783de1929bSSimon Guinot 	for (i = 0; i < priv->num_leds; i++)
3793de1929bSSimon Guinot 		delete_ns2_led(&priv->leds_data[i]);
38011efe71fSSimon Guinot 
38111efe71fSSimon Guinot 	return 0;
38211efe71fSSimon Guinot }
38311efe71fSSimon Guinot 
38411efe71fSSimon Guinot static struct platform_driver ns2_led_driver = {
38511efe71fSSimon Guinot 	.probe		= ns2_led_probe,
386df07cf81SBill Pemberton 	.remove		= ns2_led_remove,
38711efe71fSSimon Guinot 	.driver		= {
38811efe71fSSimon Guinot 		.name		= "leds-ns2",
38972052fccSSimon Guinot 		.of_match_table	= of_match_ptr(of_ns2_leds_match),
39011efe71fSSimon Guinot 	},
39111efe71fSSimon Guinot };
39211efe71fSSimon Guinot 
393892a8843SAxel Lin module_platform_driver(ns2_led_driver);
39411efe71fSSimon Guinot 
39511efe71fSSimon Guinot MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>");
39611efe71fSSimon Guinot MODULE_DESCRIPTION("Network Space v2 LED driver");
39711efe71fSSimon Guinot MODULE_LICENSE("GPL");
398892a8843SAxel Lin MODULE_ALIAS("platform:leds-ns2");
399