diff options
author | Marcel Hasler <mahasler@gmail.com> | 2016-12-15 20:17:26 -0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-02-03 11:25:51 -0200 |
commit | e36e6b5f26c14fd588d5c7e78527d3707f8ac836 (patch) | |
tree | 9c8422f72379195fe5bc0944f13d4eea02d6ed55 /drivers/media/usb/stk1160/stk1160-ac97.c | |
parent | 814e92b8cadf73ee79f689ec48f64408f3904d19 (diff) |
[media] stk1160: Remove stk1160-mixer and setup internal AC97 codec automatically
Exposing all the channels of the device's internal AC97 codec to
userspace is unnecessary and confusing. Instead the driver should setup
the codec with proper values. This patch removes the mixer and sets up
the codec using optimal values, i.e. the same values set by the Windows
driver. This also makes the device work out-of-the-box, without the need
for the user to reconfigure the device every time it's plugged in.
Signed-off-by: Marcel Hasler <mahasler@gmail.com>
Acked-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/usb/stk1160/stk1160-ac97.c')
-rw-r--r-- | drivers/media/usb/stk1160/stk1160-ac97.c | 126 |
1 files changed, 46 insertions, 80 deletions
diff --git a/drivers/media/usb/stk1160/stk1160-ac97.c b/drivers/media/usb/stk1160/stk1160-ac97.c index 2dd308f9541f..502fc8ee9a97 100644 --- a/drivers/media/usb/stk1160/stk1160-ac97.c +++ b/drivers/media/usb/stk1160/stk1160-ac97.c @@ -4,6 +4,9 @@ * Copyright (C) 2012 Ezequiel Garcia * <elezegarcia--a.t--gmail.com> * + * Copyright (C) 2016 Marcel Hasler + * <mahasler--a.t--gmail.com> + * * Based on Easycap driver by R.M. Thomas * Copyright (C) 2010 R.M. Thomas * <rmthomas--a.t--sciolus.org> @@ -20,20 +23,11 @@ * */ -#include <linux/module.h> -#include <sound/core.h> -#include <sound/initval.h> -#include <sound/ac97_codec.h> - #include "stk1160.h" #include "stk1160-reg.h" -static struct snd_ac97 *stk1160_ac97; - -static void stk1160_write_ac97(struct snd_ac97 *ac97, u16 reg, u16 value) +static void stk1160_write_ac97(struct stk1160 *dev, u16 reg, u16 value) { - struct stk1160 *dev = ac97->private_data; - /* Set codec register address */ stk1160_write_reg(dev, STK1160_AC97_ADDR, reg); @@ -48,9 +42,9 @@ static void stk1160_write_ac97(struct snd_ac97 *ac97, u16 reg, u16 value) stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x8c); } -static u16 stk1160_read_ac97(struct snd_ac97 *ac97, u16 reg) +#ifdef DEBUG +static u16 stk1160_read_ac97(struct stk1160 *dev, u16 reg) { - struct stk1160 *dev = ac97->private_data; u8 vall = 0; u8 valh = 0; @@ -70,81 +64,53 @@ static u16 stk1160_read_ac97(struct snd_ac97 *ac97, u16 reg) return (valh << 8) | vall; } -static void stk1160_reset_ac97(struct snd_ac97 *ac97) +void stk1160_ac97_dump_regs(struct stk1160 *dev) { - struct stk1160 *dev = ac97->private_data; - /* Two-step reset AC97 interface and hardware codec */ - stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x94); - stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x88); + u16 value; - /* Set 16-bit audio data and choose L&R channel*/ - stk1160_write_reg(dev, STK1160_AC97CTL_1 + 2, 0x01); -} + value = stk1160_read_ac97(dev, 0x12); /* CD volume */ + stk1160_dbg("0x12 == 0x%04x", value); -static struct snd_ac97_bus_ops stk1160_ac97_ops = { - .read = stk1160_read_ac97, - .write = stk1160_write_ac97, - .reset = stk1160_reset_ac97, -}; + value = stk1160_read_ac97(dev, 0x10); /* Line-in volume */ + stk1160_dbg("0x10 == 0x%04x", value); -int stk1160_ac97_register(struct stk1160 *dev) -{ - struct snd_card *card = NULL; - struct snd_ac97_bus *ac97_bus; - struct snd_ac97_template ac97_template; - int rc; + value = stk1160_read_ac97(dev, 0x0e); /* MIC volume (mono) */ + stk1160_dbg("0x0e == 0x%04x", value); - /* - * Just want a card to access ac96 controls, - * the actual capture interface will be handled by snd-usb-audio - */ - rc = snd_card_new(dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, - THIS_MODULE, 0, &card); - if (rc < 0) - return rc; - - /* TODO: I'm not sure where should I get these names :-( */ - snprintf(card->shortname, sizeof(card->shortname), - "stk1160-mixer"); - snprintf(card->longname, sizeof(card->longname), - "stk1160 ac97 codec mixer control"); - strlcpy(card->driver, dev->dev->driver->name, sizeof(card->driver)); - - rc = snd_ac97_bus(card, 0, &stk1160_ac97_ops, NULL, &ac97_bus); - if (rc) - goto err; - - /* We must set private_data before calling snd_ac97_mixer */ - memset(&ac97_template, 0, sizeof(ac97_template)); - ac97_template.private_data = dev; - ac97_template.scaps = AC97_SCAP_SKIP_MODEM; - rc = snd_ac97_mixer(ac97_bus, &ac97_template, &stk1160_ac97); - if (rc) - goto err; - - dev->snd_card = card; - rc = snd_card_register(card); - if (rc) - goto err; - - return 0; - -err: - dev->snd_card = NULL; - snd_card_free(card); - return rc; + value = stk1160_read_ac97(dev, 0x16); /* Aux volume */ + stk1160_dbg("0x16 == 0x%04x", value); + + value = stk1160_read_ac97(dev, 0x1a); /* Record select */ + stk1160_dbg("0x1a == 0x%04x", value); + + value = stk1160_read_ac97(dev, 0x02); /* Master volume */ + stk1160_dbg("0x02 == 0x%04x", value); + + value = stk1160_read_ac97(dev, 0x1c); /* Record gain */ + stk1160_dbg("0x1c == 0x%04x", value); } +#endif -int stk1160_ac97_unregister(struct stk1160 *dev) +void stk1160_ac97_setup(struct stk1160 *dev) { - struct snd_card *card = dev->snd_card; - - /* - * We need to check usb_device, - * because ac97 release attempts to communicate with codec - */ - if (card && dev->udev) - snd_card_free(card); + /* Two-step reset AC97 interface and hardware codec */ + stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x94); + stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x8c); - return 0; + /* Set 16-bit audio data and choose L&R channel*/ + stk1160_write_reg(dev, STK1160_AC97CTL_1 + 2, 0x01); + stk1160_write_reg(dev, STK1160_AC97CTL_1 + 3, 0x00); + + /* Setup channels */ + stk1160_write_ac97(dev, 0x12, 0x8808); /* CD volume */ + stk1160_write_ac97(dev, 0x10, 0x0808); /* Line-in volume */ + stk1160_write_ac97(dev, 0x0e, 0x0008); /* MIC volume (mono) */ + stk1160_write_ac97(dev, 0x16, 0x0808); /* Aux volume */ + stk1160_write_ac97(dev, 0x1a, 0x0404); /* Record select */ + stk1160_write_ac97(dev, 0x02, 0x0000); /* Master volume */ + stk1160_write_ac97(dev, 0x1c, 0x0808); /* Record gain */ + +#ifdef DEBUG + stk1160_ac97_dump_regs(dev); +#endif } |