Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: provide helper to register "leds-gpio" devices

This function makes a deep copy of the platform data to allow it to live
in init memory. For a kernel that supports several machines and so
includes the definition for several leds-gpio devices this saves quite
some memory because all but one definition can be free'd after boot.

As the function is used by arch code it must be builtin and so cannot go
into leds-gpio.c.

[akpm@linux-foundation.org: s/CONFIG_LED_REGISTER_GPIO/CONFIG_LEDS_REGISTER_GPIO/]
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Russell King <rmk@arm.linux.org.uk>
Acked-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: H Hartley Sweeten <hartleys@visionengravers.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Uwe Kleine-König and committed by
Linus Torvalds
4440673a 9b2da53f

+53 -1
+1 -1
drivers/Makefile
··· 94 94 obj-$(CONFIG_DMA_ENGINE) += dma/ 95 95 obj-$(CONFIG_MMC) += mmc/ 96 96 obj-$(CONFIG_MEMSTICK) += memstick/ 97 - obj-$(CONFIG_NEW_LEDS) += leds/ 97 + obj-y += leds/ 98 98 obj-$(CONFIG_INFINIBAND) += infiniband/ 99 99 obj-$(CONFIG_SGI_SN) += sn/ 100 100 obj-y += firmware/
+7
drivers/leds/Kconfig
··· 14 14 This option enables the led sysfs class in /sys/class/leds. You'll 15 15 need this to do anything useful with LEDs. If unsure, say N. 16 16 17 + config LEDS_GPIO_REGISTER 18 + bool 19 + help 20 + This option provides the function gpio_led_register_device. 21 + As this function is used by arch code it must not be compiled as a 22 + module. 23 + 17 24 if NEW_LEDS 18 25 19 26 comment "LED drivers"
+1
drivers/leds/Makefile
··· 21 21 obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o 22 22 obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o 23 23 obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o 24 + obj-$(CONFIG_LEDS_GPIO_REGISTER) += leds-gpio-register.o 24 25 obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o 25 26 obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o 26 27 obj-$(CONFIG_LEDS_LP5521) += leds-lp5521.o
+42
drivers/leds/leds-gpio-register.c
··· 1 + /* 2 + * Copyright (C) 2011 Pengutronix 3 + * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> 4 + * 5 + * This program is free software; you can redistribute it and/or modify it under 6 + * the terms of the GNU General Public License version 2 as published by the 7 + * Free Software Foundation. 8 + */ 9 + #include <linux/err.h> 10 + #include <linux/platform_device.h> 11 + #include <linux/slab.h> 12 + #include <linux/leds.h> 13 + 14 + /** 15 + * gpio_led_register_device - register a gpio-led device 16 + * @pdata: the platform data used for the new device 17 + * 18 + * Makes a copy of pdata and pdata->leds and registers a new leds-gpio device 19 + * with the result. This allows to have pdata and pdata-leds in .init.rodata 20 + * and so saves some bytes compared to a static struct platform_device with 21 + * static platform data. 22 + * 23 + * Returns the registered device or an error pointer. 24 + */ 25 + struct platform_device *__init gpio_led_register_device( 26 + int id, const struct gpio_led_platform_data *pdata) 27 + { 28 + struct platform_device *ret; 29 + struct gpio_led_platform_data _pdata = *pdata; 30 + 31 + _pdata.leds = kmemdup(pdata->leds, 32 + pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL); 33 + if (!_pdata.leds) 34 + return ERR_PTR(-ENOMEM); 35 + 36 + ret = platform_device_register_resndata(NULL, "leds-gpio", id, 37 + NULL, 0, &_pdata, sizeof(_pdata)); 38 + if (IS_ERR(ret)) 39 + kfree(_pdata.leds); 40 + 41 + return ret; 42 + }
+2
include/linux/leds.h
··· 207 207 unsigned long *delay_off); 208 208 }; 209 209 210 + struct platform_device *gpio_led_register_device( 211 + int id, const struct gpio_led_platform_data *pdata); 210 212 211 213 #endif /* __LINUX_LEDS_H_INCLUDED */