linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho@freescale.com>
To: linux-kernel@vger.kernel.org
Cc: linuxppc-dev@ozlabs.org, Richard Purdie <rpurdie@rpsys.net>,
	Trent Piepho <tpiepho@freescale.com>
Subject: [PATCH v2 4/4] leds: Use tristate property in platform data
Date: Thu, 11 Dec 2008 13:49:58 -0800	[thread overview]
Message-ID: <1229032198-19775-4-git-send-email-tpiepho@freescale.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0812111326480.28806@t2.domain.actdsltmp>

Replace the two boolean properties default_state and keep_state with a
single tristate property that can be set to
LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP).  This ends up being more complicated,
requires more code, and makes developers remember not just the name of the
field to set but also the symbolic constant to set it to.  Yet despite
these shortcomings it remains more popular.

Signed-off-by: Trent Piepho <tpiepho@freescale.com>
---
 drivers/leds/leds-gpio.c |   15 +++++++++++----
 include/linux/leds.h     |    7 +++++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index bb9d9ff..2d1b71f 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -92,10 +92,10 @@ static int __devinit create_gpio_led(const struct gpio_led *template,
 		led_dat->cdev.blink_set = gpio_blink_set;
 	}
 	led_dat->cdev.brightness_set = gpio_led_set;
-	if (template->keep_state)
+	if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
 		state = !!gpio_get_value(led_dat->gpio) ^ led_dat->active_low;
 	else
-		state = template->default_state;
+		state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
 	led_dat->cdev.brightness = state ? LED_FULL : LED_OFF;
 
 	ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state);
@@ -273,8 +273,15 @@ static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
 		led.default_trigger =
 			of_get_property(child, "linux,default-trigger", NULL);
 		state = of_get_property(child, "default-state", NULL);
-		led.default_state = state && !strcmp(state, "on");
-		led.keep_state = state && !strcmp(state, "keep");
+		if (state) {
+			if (!strcmp(state, "keep")) {
+				led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
+			} else if(!strcmp(state, "on")) {
+				led.default_state = LEDS_GPIO_DEFSTATE_ON;
+			} else {
+				led.default_state = LEDS_GPIO_DEFSTATE_OFF;
+			}
+		}
 
 		ret = create_gpio_led(&led, &pdata->led_data[pdata->num_leds++],
 				      &ofdev->dev, NULL);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index c51b625..f4a125c 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -138,9 +138,12 @@ struct gpio_led {
 	const char *default_trigger;
 	unsigned 	gpio;
 	u8 		active_low;
-	u8		default_state;	/* 0 = off, 1 = on */
-	u8		keep_state; /* overrides default_state */
+	u8		default_state;
+	/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
 };
+#define LEDS_GPIO_DEFSTATE_OFF	0
+#define LEDS_GPIO_DEFSTATE_ON	1
+#define LEDS_GPIO_DEFSTATE_KEEP	2
 
 struct gpio_led_platform_data {
 	int 		num_leds;
-- 
1.5.4.1

      parent reply	other threads:[~2008-12-11 21:50 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 ` [PATCH 1/4] leds: Support OpenFirmware led bindings Anton Vorontsov
2008-12-11 21:33   ` 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     ` Trent Piepho [this message]

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=1229032198-19775-4-git-send-email-tpiepho@freescale.com \
    --to=tpiepho@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=rpurdie@rpsys.net \
    /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).