linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: u.kleine-koenig@pengutronix.de (Uwe Kleine-König)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 1/2] ARM: mxc: Introduce imx_add_gpio_leds
Date: Mon, 4 Apr 2011 19:42:44 +0200	[thread overview]
Message-ID: <20110404174244.GH13963@pengutronix.de> (raw)
In-Reply-To: <20110404171927.GG7285@pengutronix.de>

On Mon, Apr 04, 2011 at 07:19:27PM +0200, Sascha Hauer wrote:
> On Mon, Apr 04, 2011 at 02:06:45PM -0300, Fabio Estevam wrote:
> > Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> > ---
> >  arch/arm/plat-mxc/devices/Kconfig               |    3 +++
> >  arch/arm/plat-mxc/devices/Makefile              |    1 +
> >  arch/arm/plat-mxc/devices/platform-gpio_leds.c  |   22 ++++++++++++++++++++++
> >  arch/arm/plat-mxc/include/mach/devices-common.h |    4 ++++
> >  4 files changed, 30 insertions(+), 0 deletions(-)
> >  create mode 100644 arch/arm/plat-mxc/devices/platform-gpio_leds.c
> > 
> > diff --git a/arch/arm/plat-mxc/devices/Kconfig b/arch/arm/plat-mxc/devices/Kconfig
> > index b9ab1d5..3d4f63c 100644
> > --- a/arch/arm/plat-mxc/devices/Kconfig
> > +++ b/arch/arm/plat-mxc/devices/Kconfig
> > @@ -13,6 +13,9 @@ config IMX_HAVE_PLATFORM_GPIO_KEYS
> >  	bool
> >  	default y if SOC_IMX51
> >  
> > +config IMX_HAVE_PLATFORM_GPIO_LEDS
> > +	bool
> > +
> >  config IMX_HAVE_PLATFORM_IMX21_HCD
> >  	bool
> >  	
> > diff --git a/arch/arm/plat-mxc/devices/Makefile b/arch/arm/plat-mxc/devices/Makefile
> > index 75cd2ec..ceefca6 100644
> > --- a/arch/arm/plat-mxc/devices/Makefile
> > +++ b/arch/arm/plat-mxc/devices/Makefile
> > @@ -2,6 +2,7 @@ obj-$(CONFIG_IMX_HAVE_PLATFORM_FEC) += platform-fec.o
> >  obj-$(CONFIG_IMX_HAVE_PLATFORM_FLEXCAN) += platform-flexcan.o
> >  obj-$(CONFIG_IMX_HAVE_PLATFORM_FSL_USB2_UDC) += platform-fsl-usb2-udc.o
> >  obj-$(CONFIG_IMX_HAVE_PLATFORM_GPIO_KEYS) += platform-gpio_keys.o
> > +obj-$(CONFIG_IMX_HAVE_PLATFORM_GPIO_LEDS) += platform-gpio_leds.o
> >  obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX21_HCD) += platform-imx21-hcd.o
> >  obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX2_WDT) += platform-imx2-wdt.o
> >  obj-$(CONFIG_IMX_HAVE_PLATFORM_IMXDI_RTC) += platform-imxdi_rtc.o
> > diff --git a/arch/arm/plat-mxc/devices/platform-gpio_leds.c b/arch/arm/plat-mxc/devices/platform-gpio_leds.c
> > new file mode 100644
> > index 0000000..a430213
> > --- /dev/null
> > +++ b/arch/arm/plat-mxc/devices/platform-gpio_leds.c
> > @@ -0,0 +1,22 @@
> > +/*
> > + * Copyright (C) 2011 Freescale Semiconductor, Inc.
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * as published by the Free Software Foundation; either version 2
> > + * of the License, or (at your option) any later version.
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + */
> > +#include <asm/sizes.h>
> > +#include <mach/hardware.h>
> > +#include <mach/devices-common.h>
> > +
> > +struct platform_device *__init imx_add_gpio_leds(
> > +		 const struct gpio_led_platform_data *pdata)
> > +{
> > +	return imx_add_platform_device("leds-gpio", -1, NULL,
> > +		 0, pdata, sizeof(*pdata));
> > +}
> 
> Does this really make sense? There's nothing imx specific in this
> function, so it shouldn't be named imx_* and it shouldn't be under
> plat-mxc. Also, any user of imx_add_gpio_leds could call
> platform_device_register_resndata instead.
hmm, as long as the function lives in plat-mxc it's IMHO even required
to be named imx_*. But other than that, you're obivously right.
(Well, the central approach would assert that only one instance of
"leds-gpio" is used. But that alone probably isn't worth the
optimisation.)

The mechanims could be made a bit more aggressive by something like
that:

	struct gpio_led_platform_data *_pdata = *pdata;
	_pdata->leds = kmemdup(pdata->leds, pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL)
	if (!_pdata->leds)
		return ...

	ret = imx_add_platform_device("leds-gpio", -1, NULL, 0, _pdata, sizeof(_pdata));
	if (IS_ERR(ret))
		kfree(_pdata->leds);

	return PTR_RET(ret);

This would allow to have the struct gpio_led array in init memory, too.

Is it worth the effort?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  reply	other threads:[~2011-04-04 17:42 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04 17:06 [PATCH v2 1/2] ARM: mxc: Introduce imx_add_gpio_leds Fabio Estevam
2011-04-04 17:06 ` [PATCH v2 2/2] ARM: mx5/mx53_evk.c: Add LED support Fabio Estevam
2011-04-04 17:19 ` [PATCH v2 1/2] ARM: mxc: Introduce imx_add_gpio_leds Sascha Hauer
2011-04-04 17:42   ` Uwe Kleine-König [this message]
2011-04-04 17:52     ` Russell King - ARM Linux
2011-04-04 18:06       ` H Hartley Sweeten
2011-04-04 18:17         ` Russell King - ARM Linux
2011-04-04 21:52           ` H Hartley Sweeten
2011-04-05  7:30             ` Uwe Kleine-König
2011-04-05  7:40               ` Russell King - ARM Linux
2011-04-05  7:43                 ` Uwe Kleine-König
2011-04-05  7:47                   ` Russell King - ARM Linux
2011-04-05  7:51                     ` Uwe Kleine-König
2011-04-05  7:59                       ` Russell King - ARM Linux
2011-04-05  8:32                         ` Uwe Kleine-König
2011-04-05  8:43                           ` Russell King - ARM Linux
2011-04-05  8:46                             ` Uwe Kleine-König
2011-04-05  8:37               ` [PATCH] leds: provide helper to register "leds-gpio" devices Uwe Kleine-König
2011-04-05 16:13                 ` Fabio Estevam
2011-04-05 16:29                   ` Fabio Estevam
2011-04-05 18:12                     ` H Hartley Sweeten
2011-04-05 16:33                 ` Russell King - ARM Linux
2011-04-05 20:24                   ` [PATCH v2] " Uwe Kleine-König
2011-04-06 11:45                     ` Fabio Estevam
2011-04-06 11:52                     ` Richard Purdie
2011-04-06 12:33                       ` Uwe Kleine-König
2011-04-06 13:38                         ` Richard Purdie
2011-04-11 20:35                           ` [PATCH v3] " Uwe Kleine-König
2011-04-12 21:48                             ` Russell King - ARM Linux
2011-04-13  6:23                               ` Uwe Kleine-König
2011-05-06 21:03                                 ` Richard Purdie
2011-05-09  8:00                                   ` Uwe Kleine-König
2011-04-26 15:08                             ` Uwe Kleine-König
2011-05-06  8:25                               ` Uwe Kleine-König
2011-05-09 22:02                             ` Andrew Morton
2011-05-09 22:17                               ` Russell King - ARM Linux
2011-05-10  6:45                                 ` Uwe Kleine-König
2011-05-10  7:31                               ` Uwe Kleine-König
2011-05-10  8:50                                 ` [PATCH v4] " Uwe Kleine-König
2011-05-10  8:50                                   ` [PATCH] [wip] ARM: imx: register "leds-gpio" device using new helper function Uwe Kleine-König
2011-05-10 22:26                                     ` H Hartley Sweeten
2011-05-11  6:22                                       ` Uwe Kleine-König
2011-05-10 23:02                                     ` H Hartley Sweeten
2011-04-19 23:19                   ` [PATCH] leds: provide helper to register "leds-gpio" devices Andrew Morton
2011-04-19 23:24                     ` Russell King - ARM Linux
2011-04-19 23:50                       ` Andrew Morton
2011-04-05 16:41               ` [PATCH v2 1/2] ARM: mxc: Introduce imx_add_gpio_leds H Hartley Sweeten

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110404174244.GH13963@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).