linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Trent Piepho <tpiepho@freescale.com>
Cc: devicetree-discuss@ozlabs.org, linux-kernel@vger.kernel.org,
	linuxppc-dev@ozlabs.org, Richard Purdie <rpurdie@rpsys.net>,
	Sean MacLennan <smaclennan@pikatech.com>
Subject: Re: [PATCH 1/4] leds: Support OpenFirmware led bindings
Date: Wed, 10 Dec 2008 19:32:18 +0300	[thread overview]
Message-ID: <20081210163217.GA20150@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <1228923703-16370-1-git-send-email-tpiepho@freescale.com>

Hi Trent,

On Wed, Dec 10, 2008 at 07:41:40AM -0800, Trent Piepho wrote:
> Add bindings to support LEDs defined as of_platform devices in addition to
> the existing bindings for platform devices.
> 
> New options in Kconfig allow the platform binding code and/or the
> of_platform code to be turned on.  The of_platform code is of course only
> available on archs that have OF support.
> 
> The existing probe and remove methods are refactored to use new functions
> create_gpio_led(), to create and register one led, and delete_gpio_led(),
> to unregister and free one led.  The new probe and remove methods for the
> of_platform driver can then share most of the common probe and remove code
> with the platform driver.
> 
> The suspend and resume methods aren't shared, but they are very short.  The
> actual led driving code is the same for LEDs created by either binding.
> 
> The OF bindings are based on patch by Anton Vorontsov
> <avorontsov@ru.mvista.com>.  They have been extended to allow multiple LEDs
> per device.
> 
> Signed-off-by: Trent Piepho <tpiepho@freescale.com>
> Acked-by: Grant Likely <grant.likely@secretlab.ca>
> Acked-by: Sean MacLennan <smaclennan@pikatech.com>
> CC: devicetree-discuss@ozlabs.org
> ---

Some petty notes below...

[...]  
> -static int gpio_led_probe(struct platform_device *pdev)
> +static int __devinit create_gpio_led(const struct gpio_led *template,
> +	struct gpio_led_data *led_dat, struct device *parent,
> +	int (*blink_set)(unsigned, unsigned long *, unsigned long *))
> +{
> +	int ret;
> +
> +	ret = gpio_request(template->gpio, template->name);
> +	if (ret < 0)
> +		return ret;
> +
> +	led_dat->cdev.name = template->name;
> +	led_dat->cdev.default_trigger = template->default_trigger;
> +	led_dat->gpio = template->gpio;
> +	led_dat->can_sleep = gpio_cansleep(template->gpio);
> +	led_dat->active_low = template->active_low;
> +	if (blink_set) {
> +		led_dat->platform_gpio_blink_set = blink_set;
> +		led_dat->cdev.blink_set = gpio_blink_set;
> +	}
> +	led_dat->cdev.brightness_set = gpio_led_set;
> +	led_dat->cdev.brightness = LED_OFF;
> +
> +	gpio_direction_output(led_dat->gpio, led_dat->active_low);

This can fail (yeah, the original code didn't check return value
either).

> +	INIT_WORK(&led_dat->work, gpio_led_work);
> +
> +	ret = led_classdev_register(parent, &led_dat->cdev);
> +	if (ret < 0)
> +		gpio_free(led_dat->gpio);
> +
> +	return ret;
> +}
[...]
> +static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
> +					const struct of_device_id *match)
> +{
> +	struct device_node *np = ofdev->node, *child;
> +	struct gpio_led led;
> +	struct gpio_led_of_platform_data *pdata;
> +	int count = 0, ret;
> +
> +	/* count LEDs defined by this device, so we know how much to allocate */
> +	for_each_child_of_node(np, child)
> +		count++;
> +	if (!count)
> +		return 0; /* or ENODEV? */
> +
> +	pdata = kzalloc(sizeof(*pdata) + sizeof(struct gpio_led_data) * count,
> +			GFP_KERNEL);
> +	if (!pdata)
> +		return -ENOMEM;
> +
> +	memset(&led, 0, sizeof(led));
> +	for_each_child_of_node(np, child) {
> +		unsigned int flags;

I think it would be better to use `enum of_gpio_flags' type here,
just for clarity.

> +
> +		led.gpio = of_get_gpio_flags(child, 0, &flags);
> +		led.active_low = flags & OF_GPIO_ACTIVE_LOW;
> +		led.name = of_get_property(child, "label", NULL) ? : child->name;
> +		led.default_trigger =
> +			of_get_property(child, "linux,default-trigger", NULL);
> +
> +		ret = create_gpio_led(&led, &pdata->led_data[pdata->num_leds++],
> +				      &ofdev->dev, NULL);
> +		if (ret < 0)

of_node_put(np); is missing here.

> +			goto err;
> +	}
> +
> +	dev_set_drvdata(&ofdev->dev, pdata);
> +
> +	return 0;
> +
> +err:
> +	for (count = pdata->num_leds - 2; count >= 0; count--)
> +		delete_gpio_led(&pdata->led_data[count]);
> +
> +	kfree(pdata);
> +
> +	return ret;
> +}
[...]

Thanks,

-- 
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2

  parent reply	other threads:[~2008-12-10 16:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-10 15:41 [PATCH 1/4] leds: Support OpenFirmware led bindings Trent Piepho
2008-12-10 15:41 ` [PATCH 2/4] leds: Add option to have GPIO LEDs start on Trent Piepho
2008-12-10 15:41 ` [PATCH 3/4] leds: Let GPIO LEDs keep their current state Trent Piepho
2008-12-10 15:41 ` [PATCH 4/4] leds: Use tristate property in platform data Trent Piepho
2008-12-10 16:32 ` Anton Vorontsov [this message]
2008-12-11 21:33   ` [PATCH 1/4] leds: Support OpenFirmware led bindings Trent Piepho
2008-12-11 21:49     ` [PATCH v2 " Trent Piepho
2008-12-11 21:49     ` [PATCH v2 2/4] leds: Add option to have GPIO LEDs start on Trent Piepho
2008-12-11 21:49     ` [PATCH v2 3/4] leds: Let GPIO LEDs keep their current state Trent Piepho
2008-12-11 21:49     ` [PATCH v2 4/4] leds: Use tristate property in platform data Trent Piepho

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=20081210163217.GA20150@oksana.dev.rtsoft.ru \
    --to=avorontsov@ru.mvista.com \
    --cc=devicetree-discuss@ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=rpurdie@rpsys.net \
    --cc=smaclennan@pikatech.com \
    --cc=tpiepho@freescale.com \
    /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).