All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frank Schäfer" <fschaefer.oss@googlemail.com>
To: m.chehab@samsung.com
Cc: linux-media@vger.kernel.org,
	"Frank Schäfer" <fschaefer.oss@googlemail.com>
Subject: [PATCH 5/7] em28xx: prepare for supporting multiple LEDs
Date: Sun,  1 Dec 2013 22:06:55 +0100	[thread overview]
Message-ID: <1385932017-2276-6-git-send-email-fschaefer.oss@googlemail.com> (raw)
In-Reply-To: <1385932017-2276-1-git-send-email-fschaefer.oss@googlemail.com>

Introduce a LED role and store all LEDs in an array.
Also provide a helper function to retrieve a specific LED.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
 drivers/media/usb/em28xx/em28xx-core.c |   31 ++++++++++++++++++++++++-------
 drivers/media/usb/em28xx/em28xx.h      |   10 +++++++++-
 2 Dateien geändert, 33 Zeilen hinzugefügt(+), 8 Zeilen entfernt(-)

diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c
index 31d6ab2..4a8179a 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -600,6 +600,22 @@ int em28xx_colorlevels_set_default(struct em28xx *dev)
 	return em28xx_write_reg(dev, EM28XX_R1A_BOFFSET, 0x00);
 }
 
+const struct em28xx_led *em28xx_find_led(struct em28xx *dev,
+					 enum em28xx_led_role role)
+{
+	if (dev->board.leds) {
+		u8 k = 0;
+		while (dev->board.leds[k].role >= 0 &&
+			       dev->board.leds[k].role < EM28XX_NUM_LED_ROLES) {
+			if (dev->board.leds[k].role == role)
+				return &dev->board.leds[k];
+			k++;
+		}
+	}
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(em28xx_find_led);
+
 int em28xx_capture_start(struct em28xx *dev, int start)
 {
 	int rc;
@@ -645,13 +661,14 @@ int em28xx_capture_start(struct em28xx *dev, int start)
 		return rc;
 
 	/* Switch (explicitly controlled) analog capturing LED on/off */
-	if ((dev->mode == EM28XX_ANALOG_MODE)
-	    && dev->board.analog_capturing_led) {
-		struct em28xx_led *led = dev->board.analog_capturing_led;
-		em28xx_write_reg_bits(dev, led->gpio_reg,
-				      (!start ^ led->inverted) ?
-				      ~led->gpio_mask : led->gpio_mask,
-				      led->gpio_mask);
+	if (dev->mode == EM28XX_ANALOG_MODE) {
+		const struct em28xx_led *led;
+		led = em28xx_find_led(dev, EM28XX_LED_ANALOG_CAPTURING);
+		if (led)
+			em28xx_write_reg_bits(dev, led->gpio_reg,
+					      (!start ^ led->inverted) ?
+					      ~led->gpio_mask : led->gpio_mask,
+					      led->gpio_mask);
 	}
 
 	return rc;
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index df828c6..f60f236 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -377,7 +377,13 @@ enum em28xx_adecoder {
 	EM28XX_TVAUDIO,
 };
 
+enum em28xx_led_role {
+	EM28XX_LED_ANALOG_CAPTURING = 0,
+	EM28XX_NUM_LED_ROLES, /* must be the last */
+};
+
 struct em28xx_led {
+	enum em28xx_led_role role;
 	u8 gpio_reg;
 	u8 gpio_mask;
 	bool inverted;
@@ -433,7 +439,7 @@ struct em28xx_board {
 	char			  *ir_codes;
 
 	/* LEDs that need to be controlled explicitly */
-	struct em28xx_led	  *analog_capturing_led;
+	struct em28xx_led	  *leds;
 
 	/* Buttons */
 	struct em28xx_button	  *buttons;
@@ -711,6 +717,8 @@ int em28xx_audio_analog_set(struct em28xx *dev);
 int em28xx_audio_setup(struct em28xx *dev);
 
 int em28xx_colorlevels_set_default(struct em28xx *dev);
+const struct em28xx_led *em28xx_find_led(struct em28xx *dev,
+					 enum em28xx_led_role role);
 int em28xx_capture_start(struct em28xx *dev, int start);
 int em28xx_vbi_supported(struct em28xx *dev);
 int em28xx_set_outfmt(struct em28xx *dev);
-- 
1.7.10.4


  parent reply	other threads:[~2013-12-01 21:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-01 21:06 [PATCH 0/7] em28xx: add basic support for the SpeedLink Vicious And Devine Laplace webcams Frank Schäfer
2013-12-01 21:06 ` [PATCH 1/7] em28xx: add support for GPO controlled analog capturing LEDs Frank Schäfer
2013-12-01 21:06 ` [PATCH 2/7] em28xx: extend the support for device buttons Frank Schäfer
2013-12-01 21:06 ` [PATCH 3/7] em28xx: add debouncing mechanism for GPI-connected buttons Frank Schäfer
2013-12-01 21:06 ` [PATCH 4/7] em28xx: reduce the polling interval for buttons Frank Schäfer
2013-12-10 21:27   ` Mauro Carvalho Chehab
2013-12-01 21:06 ` Frank Schäfer [this message]
2013-12-01 21:06 ` [PATCH 6/7] em28xx: add support for illumination button and LED Frank Schäfer
2013-12-01 21:06 ` [PATCH 7/7] em28xx: add support for the SpeedLink Vicious And Devine Laplace webcams Frank Schäfer

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=1385932017-2276-6-git-send-email-fschaefer.oss@googlemail.com \
    --to=fschaefer.oss@googlemail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.