All of lore.kernel.org
 help / color / mirror / Atom feed
* Improve Terratec Grabby (hw rev 2) support
@ 2016-02-28 11:26 Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 1/3] [media] em28xx: add support for Terratec Grabby REC button Matthieu Rogez
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Matthieu Rogez @ 2016-02-28 11:26 UTC (permalink / raw)
  To: mchehab, linux-media, linux-kernel

These patches improve support for the Terratec Grabby A/V capture device.
The first two patches add support for the REC button and led.
The third patch fixes AC97 codec detection by delaying card setup until
i2c communication to EMP202 device is reliable.

To test this:
* modprobe em28xx-alsa
* connect Grabby
* mplayer tv:// -tv driver=v4l2:width=720:height=576:device=/dev/video1:input=0:fps=25:norm=SECAM-L:alsa:adevice=plughw.2:audiorate=48000:forceaudio:amode=1:immediatemode=0 -nocache -fps 60

NOTE: for some unknown reason, if em28xx-alsa is not loaded when Grabby is
connected, there will be no sound.
NOTE2: if Grabby is connected without loading em28xx-alsa first, just deconnect
the Grabby and reconnect it.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] [media] em28xx: add support for Terratec Grabby REC button
  2016-02-28 11:26 Improve Terratec Grabby (hw rev 2) support Matthieu Rogez
@ 2016-02-28 11:26 ` Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 2/3] [media] em28xx: add support for Terratec Grabby Record led Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection Matthieu Rogez
  2 siblings, 0 replies; 7+ messages in thread
From: Matthieu Rogez @ 2016-02-28 11:26 UTC (permalink / raw)
  To: mchehab, linux-media, linux-kernel; +Cc: Matthieu Rogez

Terratec Grabby (hw rev 2) REC button uses the standard snapshot button
configuration.

Signed-off-by: Matthieu Rogez <matthieu.rogez@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-cards.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 1f4047b..4051146 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -2015,6 +2015,7 @@ struct em28xx_board em28xx_boards[] = {
 			.vmux     = SAA7115_SVIDEO3,
 			.amux     = EM28XX_AMUX_LINE_IN,
 		} },
+		.buttons         = std_snapshot_button,
 	},
 	[EM2860_BOARD_TERRATEC_AV350] = {
 		.name            = "Terratec AV350",
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] [media] em28xx: add support for Terratec Grabby Record led
  2016-02-28 11:26 Improve Terratec Grabby (hw rev 2) support Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 1/3] [media] em28xx: add support for Terratec Grabby REC button Matthieu Rogez
@ 2016-02-28 11:26 ` Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection Matthieu Rogez
  2 siblings, 0 replies; 7+ messages in thread
From: Matthieu Rogez @ 2016-02-28 11:26 UTC (permalink / raw)
  To: mchehab, linux-media, linux-kernel; +Cc: Matthieu Rogez

Terratec Grabby (hw rev 2) Record led is connected to GPIO 3
and its logic is inverted: (PIO3 = 0: on, PIO3 = 1: off).

Signed-off-by: Matthieu Rogez <matthieu.rogez@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-cards.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 4051146..5e127e4 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -560,6 +560,16 @@ static struct em28xx_led pctv_80e_leds[] = {
 	{-1, 0, 0, 0},
 };
 
+static struct em28xx_led terratec_grabby_leds[] = {
+	{
+		.role      = EM28XX_LED_ANALOG_CAPTURING,
+		.gpio_reg  = EM2820_R08_GPIO_CTRL,
+		.gpio_mask = EM_GPIO_3,
+		.inverted  = 1,
+	},
+	{-1, 0, 0, 0},
+};
+
 /*
  *  Board definitions
  */
@@ -2016,6 +2026,7 @@ struct em28xx_board em28xx_boards[] = {
 			.amux     = EM28XX_AMUX_LINE_IN,
 		} },
 		.buttons         = std_snapshot_button,
+		.leds            = terratec_grabby_leds,
 	},
 	[EM2860_BOARD_TERRATEC_AV350] = {
 		.name            = "Terratec AV350",
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection
  2016-02-28 11:26 Improve Terratec Grabby (hw rev 2) support Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 1/3] [media] em28xx: add support for Terratec Grabby REC button Matthieu Rogez
  2016-02-28 11:26 ` [PATCH 2/3] [media] em28xx: add support for Terratec Grabby Record led Matthieu Rogez
@ 2016-02-28 11:26 ` Matthieu Rogez
  2016-03-03 17:26   ` Mauro Carvalho Chehab
  2 siblings, 1 reply; 7+ messages in thread
From: Matthieu Rogez @ 2016-02-28 11:26 UTC (permalink / raw)
  To: mchehab, linux-media, linux-kernel; +Cc: Matthieu Rogez

EMP202 chip inside Terratec Grabby (hw rev 2) seems to require some time before
accessing reliably its registers. Otherwise it returns some values previously
put on the I2C bus.

To account for that period, we delay card setup until we have a proof that
accessing AC97 registers is reliable. We get this proof by polling AC97_RESET
until the expected value is read.

Signed-off-by: Matthieu Rogez <matthieu.rogez@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-cards.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 5e127e4..2e04902 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -37,6 +37,7 @@
 #include <media/i2c-addr.h>
 #include <media/tveeprom.h>
 #include <media/v4l2-common.h>
+#include <sound/ac97_codec.h>
 
 #include "em28xx.h"
 
@@ -2563,6 +2564,24 @@ static inline void em28xx_set_model(struct em28xx *dev)
 	dev->def_i2c_bus = dev->board.def_i2c_bus;
 }
 
+/* Wait until AC97_RESET reports the expected value (or reading error)
+ * before proceeding.
+ * This can help ensuring AC97 register accesses are reliable.
+ */
+static int em28xx_wait_until_ac97_features_equals(struct em28xx *dev,
+						  int expected_feat)
+{
+	int feat;
+
+	do {
+		feat = em28xx_read_ac97(dev, AC97_RESET);
+		if (feat < 0)
+			return feat;
+	} while (feat != expected_feat);
+
+	return 0;
+}
+
 /* Since em28xx_pre_card_setup() requires a proper dev->model,
  * this won't work for boards with generic PCI IDs
  */
@@ -2668,6 +2687,13 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
 		em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
 		msleep(70);
 		break;
+
+	case EM2860_BOARD_TERRATEC_GRABBY:
+		/* HACK?: Ensure AC97 register reading is reliable before
+		 * proceeding. In practice, this will wait about 1.6 seconds.
+		 */
+		em28xx_wait_until_ac97_features_equals(dev, 0x6a90);
+		break;
 	}
 
 	em28xx_gpio_set(dev, dev->board.tuner_gpio);
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection
  2016-02-28 11:26 ` [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection Matthieu Rogez
@ 2016-03-03 17:26   ` Mauro Carvalho Chehab
  2016-03-04 21:33     ` [PATCH] Fix " Matthieu Rogez
  0 siblings, 1 reply; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2016-03-03 17:26 UTC (permalink / raw)
  To: Matthieu Rogez; +Cc: linux-media, linux-kernel

Em Sun, 28 Feb 2016 12:26:23 +0100
Matthieu Rogez <matthieu.rogez@gmail.com> escreveu:

> EMP202 chip inside Terratec Grabby (hw rev 2) seems to require some time before
> accessing reliably its registers. Otherwise it returns some values previously
> put on the I2C bus.
> 
> To account for that period, we delay card setup until we have a proof that
> accessing AC97 registers is reliable. We get this proof by polling AC97_RESET
> until the expected value is read.
> 
> Signed-off-by: Matthieu Rogez <matthieu.rogez@gmail.com>
> ---
>  drivers/media/usb/em28xx/em28xx-cards.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
> index 5e127e4..2e04902 100644
> --- a/drivers/media/usb/em28xx/em28xx-cards.c
> +++ b/drivers/media/usb/em28xx/em28xx-cards.c
> @@ -37,6 +37,7 @@
>  #include <media/i2c-addr.h>
>  #include <media/tveeprom.h>
>  #include <media/v4l2-common.h>
> +#include <sound/ac97_codec.h>
>  
>  #include "em28xx.h"
>  
> @@ -2563,6 +2564,24 @@ static inline void em28xx_set_model(struct em28xx *dev)
>  	dev->def_i2c_bus = dev->board.def_i2c_bus;
>  }
>  
> +/* Wait until AC97_RESET reports the expected value (or reading error)
> + * before proceeding.
> + * This can help ensuring AC97 register accesses are reliable.
> + */
> +static int em28xx_wait_until_ac97_features_equals(struct em28xx *dev,
> +						  int expected_feat)
> +{
> +	int feat;
> +
> +	do {
> +		feat = em28xx_read_ac97(dev, AC97_RESET);
> +		if (feat < 0)
> +			return feat;
> +	} while (feat != expected_feat);

Please add some sort of timeout here... We don't want the Kernel to
be in a dead lock here...

> +
> +	return 0;
> +}
> +
>  /* Since em28xx_pre_card_setup() requires a proper dev->model,
>   * this won't work for boards with generic PCI IDs
>   */
> @@ -2668,6 +2687,13 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
>  		em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
>  		msleep(70);
>  		break;
> +
> +	case EM2860_BOARD_TERRATEC_GRABBY:
> +		/* HACK?: Ensure AC97 register reading is reliable before
> +		 * proceeding. In practice, this will wait about 1.6 seconds.
> +		 */
> +		em28xx_wait_until_ac97_features_equals(dev, 0x6a90);
> +		break;
>  	}
>  
>  	em28xx_gpio_set(dev, dev->board.tuner_gpio);


-- 
Thanks,
Mauro

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] Fix Terratec Grabby AC97 codec detection
  2016-03-03 17:26   ` Mauro Carvalho Chehab
@ 2016-03-04 21:33     ` Matthieu Rogez
  2016-03-04 21:33       ` [PATCH] [media] em28xx: fix " Matthieu Rogez
  0 siblings, 1 reply; 7+ messages in thread
From: Matthieu Rogez @ 2016-03-04 21:33 UTC (permalink / raw)
  To: mchehab, linux-media, linux-kernel

Thanks Mauro for commenting on my work.
With respect to first version, I've:
* added a timeout mecanism as requested
* added an extra check to avoid cases when the same value is constantly
returned no matter which register is accessed.

---

To test this:
* modprobe em28xx-alsa
* connect Grabby
* mplayer tv:// -tv driver=v4l2:width=720:height=576:device=/dev/video1:input=0:fps=25:norm=SECAM-L:alsa:adevice=plughw.2:audiorate=48000:forceaudio:amode=1:immediatemode=0 -nocache -fps 60

NOTE: for some unknown reason, if em28xx-alsa is not loaded when Grabby is
connected, there will be no sound.
NOTE2: if Grabby is connected without loading em28xx-alsa first, just deconnect
the Grabby and reconnect it.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] [media] em28xx: fix Terratec Grabby AC97 codec detection
  2016-03-04 21:33     ` [PATCH] Fix " Matthieu Rogez
@ 2016-03-04 21:33       ` Matthieu Rogez
  0 siblings, 0 replies; 7+ messages in thread
From: Matthieu Rogez @ 2016-03-04 21:33 UTC (permalink / raw)
  To: mchehab, linux-media, linux-kernel; +Cc: Matthieu Rogez

EMP202 chip inside Terratec Grabby (hw rev 2) seems to require some time
before accessing reliably its registers. Otherwise it returns some values
previously put on the I2C bus.

To account for that period, we delay card setup until we have a proof that
accessing AC97 registers is reliable. We get this proof by polling
AC97_RESET until the expected value is read. We also check that unrelated
registers don't return the same value. This second check handles the case
where the expected value is constantly returned no matter which register
is accessed.

Signed-off-by: Matthieu Rogez <matthieu.rogez@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-cards.c | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 5e127e4..930e3e3 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -37,6 +37,7 @@
 #include <media/i2c-addr.h>
 #include <media/tveeprom.h>
 #include <media/v4l2-common.h>
+#include <sound/ac97_codec.h>
 
 #include "em28xx.h"
 
@@ -2563,6 +2564,36 @@ static inline void em28xx_set_model(struct em28xx *dev)
 	dev->def_i2c_bus = dev->board.def_i2c_bus;
 }
 
+/* Wait until AC97_RESET reports the expected value reliably before proceeding.
+ * We also check that two unrelated registers accesses don't return the same
+ * value to avoid premature return.
+ * This procedure helps ensuring AC97 register accesses are reliable.
+ */
+static int em28xx_wait_until_ac97_features_equals(struct em28xx *dev,
+						  int expected_feat)
+{
+	unsigned long timeout = jiffies + msecs_to_jiffies(2000);
+	int feat, powerdown;
+
+	while (time_is_after_jiffies(timeout)) {
+		feat = em28xx_read_ac97(dev, AC97_RESET);
+		if (feat < 0)
+			return feat;
+
+		powerdown = em28xx_read_ac97(dev, AC97_POWERDOWN);
+		if (powerdown < 0)
+			return powerdown;
+
+		if (feat == expected_feat && feat != powerdown)
+			return 0;
+
+		msleep(50);
+	}
+
+	em28xx_warn("AC97 registers access is not reliable !\n");
+	return -ETIMEDOUT;
+}
+
 /* Since em28xx_pre_card_setup() requires a proper dev->model,
  * this won't work for boards with generic PCI IDs
  */
@@ -2668,6 +2699,13 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
 		em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
 		msleep(70);
 		break;
+
+	case EM2860_BOARD_TERRATEC_GRABBY:
+		/* HACK?: Ensure AC97 register reading is reliable before
+		 * proceeding. In practice, this will wait about 1.6 seconds.
+		 */
+		em28xx_wait_until_ac97_features_equals(dev, 0x6a90);
+		break;
 	}
 
 	em28xx_gpio_set(dev, dev->board.tuner_gpio);
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-03-04 21:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-28 11:26 Improve Terratec Grabby (hw rev 2) support Matthieu Rogez
2016-02-28 11:26 ` [PATCH 1/3] [media] em28xx: add support for Terratec Grabby REC button Matthieu Rogez
2016-02-28 11:26 ` [PATCH 2/3] [media] em28xx: add support for Terratec Grabby Record led Matthieu Rogez
2016-02-28 11:26 ` [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection Matthieu Rogez
2016-03-03 17:26   ` Mauro Carvalho Chehab
2016-03-04 21:33     ` [PATCH] Fix " Matthieu Rogez
2016-03-04 21:33       ` [PATCH] [media] em28xx: fix " Matthieu Rogez

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.