[media] em28xx: prepare for supporting multiple LEDs
authorFrank Schaefer <fschaefer.oss@googlemail.com>
Sun, 1 Dec 2013 21:06:55 +0000 (18:06 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Tue, 10 Dec 2013 18:18:40 +0000 (16:18 -0200)
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>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/usb/em28xx/em28xx-core.c
drivers/media/usb/em28xx/em28xx.h

index 31d6ab2555f2dc25e9da2d3b2be66a997e29b59f..4a8179aafc4d0310925260150a5e621a9a233b2f 100644 (file)
@@ -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;
index df828c68ef4489f95e81d0011131dcef30ec4f1c..f60f236a245f9ce6dcb2e4e6c58e8d5b8c089b8c 100644 (file)
@@ -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);