From: Matthieu Rogez <matthieu.rogez@gmail.com>
To: mchehab@osg.samsung.com, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Matthieu Rogez <matthieu.rogez@gmail.com>
Subject: [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection
Date: Sun, 28 Feb 2016 12:26:23 +0100 [thread overview]
Message-ID: <1456658783-32345-4-git-send-email-matthieu.rogez@gmail.com> (raw)
In-Reply-To: <1456658783-32345-1-git-send-email-matthieu.rogez@gmail.com>
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
next prev parent reply other threads:[~2016-02-28 11:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2016-03-03 17:26 ` [PATCH 3/3] [media] em28xx: fix Terratec Grabby AC97 codec detection Mauro Carvalho Chehab
2016-03-04 21:33 ` [PATCH] Fix " Matthieu Rogez
2016-03-04 21:33 ` [PATCH] [media] em28xx: fix " Matthieu Rogez
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=1456658783-32345-4-git-send-email-matthieu.rogez@gmail.com \
--to=matthieu.rogez@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@osg.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®