2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-10-15 15:50:19 +08:00
|
|
|
* Copyright (c) by Jaroslav Kysela <perex@perex.cz>
|
2005-04-17 06:20:36 +08:00
|
|
|
* Universal interface for Audio Codec '97
|
|
|
|
*
|
|
|
|
* For more details look to AC '97 component specification revision 2.2
|
|
|
|
* by Intel Corporation (http://developer.intel.com).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/pci.h>
|
2011-07-16 01:13:37 +08:00
|
|
|
#include <linux/module.h>
|
2006-01-16 23:34:20 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
2006-08-22 00:44:31 +08:00
|
|
|
#include <sound/tlv.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sound/ac97_codec.h>
|
|
|
|
#include <sound/asoundef.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include "ac97_id.h"
|
2007-02-22 19:58:27 +08:00
|
|
|
|
|
|
|
#include "ac97_patch.c"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-15 15:50:19 +08:00
|
|
|
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_DESCRIPTION("Universal interface for Audio Codec '97");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2011-12-15 11:19:36 +08:00
|
|
|
static bool enable_loopback;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
module_param(enable_loopback, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(enable_loopback, "Enable AC97 ADC/DAC Loopback Control");
|
|
|
|
|
2006-06-28 00:28:53 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
2007-09-18 01:07:46 +08:00
|
|
|
static int power_save = CONFIG_SND_AC97_POWER_SAVE_DEFAULT;
|
2008-06-08 15:17:27 +08:00
|
|
|
module_param(power_save, int, 0644);
|
|
|
|
MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
|
|
|
|
"(in second, 0 = disable).");
|
2006-06-28 00:28:53 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
struct ac97_codec_id {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int id;
|
|
|
|
unsigned int mask;
|
|
|
|
const char *name;
|
2005-11-17 21:21:36 +08:00
|
|
|
int (*patch)(struct snd_ac97 *ac97);
|
|
|
|
int (*mpatch)(struct snd_ac97 *ac97);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int flags;
|
2005-11-17 21:21:36 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x41445300, 0xffffff00, "Analog Devices", NULL, NULL },
|
2008-07-15 22:24:50 +08:00
|
|
|
{ 0x414b4d00, 0xffffff00, "Asahi Kasei", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x414c4300, 0xffffff00, "Realtek", NULL, NULL },
|
|
|
|
{ 0x414c4700, 0xffffff00, "Realtek", NULL, NULL },
|
2011-02-19 07:49:48 +08:00
|
|
|
/*
|
|
|
|
* This is an _inofficial_ Aztech Labs entry
|
|
|
|
* (value might differ from unknown official Aztech ID),
|
|
|
|
* currently used by the AC97 emulation of the almost-AC97 PCI168 card.
|
|
|
|
*/
|
|
|
|
{ 0x415a5400, 0xffffff00, "Aztech Labs (emulated)", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x434d4900, 0xffffff00, "C-Media Electronics", NULL, NULL },
|
|
|
|
{ 0x43525900, 0xffffff00, "Cirrus Logic", NULL, NULL },
|
|
|
|
{ 0x43585400, 0xffffff00, "Conexant", NULL, NULL },
|
|
|
|
{ 0x44543000, 0xffffff00, "Diamond Technology", NULL, NULL },
|
|
|
|
{ 0x454d4300, 0xffffff00, "eMicro", NULL, NULL },
|
|
|
|
{ 0x45838300, 0xffffff00, "ESS Technology", NULL, NULL },
|
|
|
|
{ 0x48525300, 0xffffff00, "Intersil", NULL, NULL },
|
|
|
|
{ 0x49434500, 0xffffff00, "ICEnsemble", NULL, NULL },
|
|
|
|
{ 0x49544500, 0xffffff00, "ITE Tech.Inc", NULL, NULL },
|
|
|
|
{ 0x4e534300, 0xffffff00, "National Semiconductor", NULL, NULL },
|
|
|
|
{ 0x50534300, 0xffffff00, "Philips", NULL, NULL },
|
|
|
|
{ 0x53494c00, 0xffffff00, "Silicon Laboratory", NULL, NULL },
|
2010-01-11 00:21:14 +08:00
|
|
|
{ 0x53544d00, 0xffffff00, "STMicroelectronics", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x54524100, 0xffffff00, "TriTech", NULL, NULL },
|
|
|
|
{ 0x54584e00, 0xffffff00, "Texas Instruments", NULL, NULL },
|
|
|
|
{ 0x56494100, 0xffffff00, "VIA Technologies", NULL, NULL },
|
|
|
|
{ 0x57454300, 0xffffff00, "Winbond", NULL, NULL },
|
|
|
|
{ 0x574d4c00, 0xffffff00, "Wolfson", NULL, NULL },
|
|
|
|
{ 0x594d4800, 0xffffff00, "Yamaha", NULL, NULL },
|
|
|
|
{ 0x83847600, 0xffffff00, "SigmaTel", NULL, NULL },
|
|
|
|
{ 0, 0, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct ac97_codec_id snd_ac97_codec_ids[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x41445303, 0xffffffff, "AD1819", patch_ad1819, NULL },
|
|
|
|
{ 0x41445340, 0xffffffff, "AD1881", patch_ad1881, NULL },
|
|
|
|
{ 0x41445348, 0xffffffff, "AD1881A", patch_ad1881, NULL },
|
|
|
|
{ 0x41445360, 0xffffffff, "AD1885", patch_ad1885, NULL },
|
|
|
|
{ 0x41445361, 0xffffffff, "AD1886", patch_ad1886, NULL },
|
|
|
|
{ 0x41445362, 0xffffffff, "AD1887", patch_ad1881, NULL },
|
|
|
|
{ 0x41445363, 0xffffffff, "AD1886A", patch_ad1881, NULL },
|
|
|
|
{ 0x41445368, 0xffffffff, "AD1888", patch_ad1888, NULL },
|
|
|
|
{ 0x41445370, 0xffffffff, "AD1980", patch_ad1980, NULL },
|
|
|
|
{ 0x41445372, 0xffffffff, "AD1981A", patch_ad1981a, NULL },
|
|
|
|
{ 0x41445374, 0xffffffff, "AD1981B", patch_ad1981b, NULL },
|
|
|
|
{ 0x41445375, 0xffffffff, "AD1985", patch_ad1985, NULL },
|
2006-12-22 19:44:25 +08:00
|
|
|
{ 0x41445378, 0xffffffff, "AD1986", patch_ad1986, NULL },
|
2008-07-15 22:24:50 +08:00
|
|
|
{ 0x414b4d00, 0xffffffff, "AK4540", NULL, NULL },
|
|
|
|
{ 0x414b4d01, 0xffffffff, "AK4542", NULL, NULL },
|
|
|
|
{ 0x414b4d02, 0xffffffff, "AK4543", NULL, NULL },
|
|
|
|
{ 0x414b4d06, 0xffffffff, "AK4544A", NULL, NULL },
|
|
|
|
{ 0x414b4d07, 0xffffffff, "AK4545", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x414c4300, 0xffffff00, "ALC100,100P", NULL, NULL },
|
|
|
|
{ 0x414c4710, 0xfffffff0, "ALC200,200P", NULL, NULL },
|
|
|
|
{ 0x414c4721, 0xffffffff, "ALC650D", NULL, NULL }, /* already patched */
|
|
|
|
{ 0x414c4722, 0xffffffff, "ALC650E", NULL, NULL }, /* already patched */
|
|
|
|
{ 0x414c4723, 0xffffffff, "ALC650F", NULL, NULL }, /* already patched */
|
|
|
|
{ 0x414c4720, 0xfffffff0, "ALC650", patch_alc650, NULL },
|
|
|
|
{ 0x414c4730, 0xffffffff, "ALC101", NULL, NULL },
|
|
|
|
{ 0x414c4740, 0xfffffff0, "ALC202", NULL, NULL },
|
|
|
|
{ 0x414c4750, 0xfffffff0, "ALC250", NULL, NULL },
|
2008-07-15 22:24:50 +08:00
|
|
|
{ 0x414c4760, 0xfffffff0, "ALC655", patch_alc655, NULL },
|
2008-08-05 21:45:45 +08:00
|
|
|
{ 0x414c4770, 0xfffffff0, "ALC203", patch_alc203, NULL },
|
2008-07-15 22:24:50 +08:00
|
|
|
{ 0x414c4781, 0xffffffff, "ALC658D", NULL, NULL }, /* already patched */
|
|
|
|
{ 0x414c4780, 0xfffffff0, "ALC658", patch_alc655, NULL },
|
|
|
|
{ 0x414c4790, 0xfffffff0, "ALC850", patch_alc850, NULL },
|
2011-02-19 07:49:48 +08:00
|
|
|
{ 0x415a5401, 0xffffffff, "AZF3328", patch_aztech_azf3328, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x434d4941, 0xffffffff, "CMI9738", patch_cm9738, NULL },
|
|
|
|
{ 0x434d4961, 0xffffffff, "CMI9739", patch_cm9739, NULL },
|
2005-04-07 21:53:20 +08:00
|
|
|
{ 0x434d4969, 0xffffffff, "CMI9780", patch_cm9780, NULL },
|
2006-12-13 01:05:24 +08:00
|
|
|
{ 0x434d4978, 0xffffffff, "CMI9761A", patch_cm9761, NULL },
|
|
|
|
{ 0x434d4982, 0xffffffff, "CMI9761B", patch_cm9761, NULL },
|
|
|
|
{ 0x434d4983, 0xffffffff, "CMI9761A+", patch_cm9761, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x43525900, 0xfffffff8, "CS4297", NULL, NULL },
|
|
|
|
{ 0x43525910, 0xfffffff8, "CS4297A", patch_cirrus_spdif, NULL },
|
|
|
|
{ 0x43525920, 0xfffffff8, "CS4298", patch_cirrus_spdif, NULL },
|
|
|
|
{ 0x43525928, 0xfffffff8, "CS4294", NULL, NULL },
|
|
|
|
{ 0x43525930, 0xfffffff8, "CS4299", patch_cirrus_cs4299, NULL },
|
|
|
|
{ 0x43525948, 0xfffffff8, "CS4201", NULL, NULL },
|
|
|
|
{ 0x43525958, 0xfffffff8, "CS4205", patch_cirrus_spdif, NULL },
|
|
|
|
{ 0x43525960, 0xfffffff8, "CS4291", NULL, NULL },
|
|
|
|
{ 0x43525970, 0xfffffff8, "CS4202", NULL, NULL },
|
|
|
|
{ 0x43585421, 0xffffffff, "HSD11246", NULL, NULL }, // SmartMC II
|
|
|
|
{ 0x43585428, 0xfffffff8, "Cx20468", patch_conexant, NULL }, // SmartAMC fixme: the mask might be different
|
2009-03-06 21:30:08 +08:00
|
|
|
{ 0x43585430, 0xffffffff, "Cx20468-31", patch_conexant, NULL },
|
2007-02-09 19:42:03 +08:00
|
|
|
{ 0x43585431, 0xffffffff, "Cx20551", patch_cx20551, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x44543031, 0xfffffff0, "DT0398", NULL, NULL },
|
2005-11-17 22:30:43 +08:00
|
|
|
{ 0x454d4328, 0xffffffff, "EM28028", NULL, NULL }, // same as TR28028?
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x45838308, 0xffffffff, "ESS1988", NULL, NULL },
|
|
|
|
{ 0x48525300, 0xffffff00, "HMP9701", NULL, NULL },
|
|
|
|
{ 0x49434501, 0xffffffff, "ICE1230", NULL, NULL },
|
|
|
|
{ 0x49434511, 0xffffffff, "ICE1232", NULL, NULL }, // alias VIA VT1611A?
|
|
|
|
{ 0x49434514, 0xffffffff, "ICE1232A", NULL, NULL },
|
|
|
|
{ 0x49434551, 0xffffffff, "VT1616", patch_vt1616, NULL },
|
|
|
|
{ 0x49434552, 0xffffffff, "VT1616i", patch_vt1616, NULL }, // VT1616 compatible (chipset integrated)
|
|
|
|
{ 0x49544520, 0xffffffff, "IT2226E", NULL, NULL },
|
|
|
|
{ 0x49544561, 0xffffffff, "IT2646E", patch_it2646, NULL },
|
|
|
|
{ 0x4e534300, 0xffffffff, "LM4540,43,45,46,48", NULL, NULL }, // only guess --jk
|
|
|
|
{ 0x4e534331, 0xffffffff, "LM4549", NULL, NULL },
|
2006-02-09 18:48:21 +08:00
|
|
|
{ 0x4e534350, 0xffffffff, "LM4550", patch_lm4550, NULL }, // volume wrap fix
|
2006-06-29 23:15:33 +08:00
|
|
|
{ 0x50534304, 0xffffffff, "UCB1400", patch_ucb1400, NULL },
|
2005-05-29 21:08:23 +08:00
|
|
|
{ 0x53494c20, 0xffffffe0, "Si3036,8", mpatch_si3036, mpatch_si3036, AC97_MODEM_PATCH },
|
2010-01-11 00:21:14 +08:00
|
|
|
{ 0x53544d02, 0xffffffff, "ST7597", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x54524102, 0xffffffff, "TR28022", NULL, NULL },
|
2008-07-15 09:00:21 +08:00
|
|
|
{ 0x54524103, 0xffffffff, "TR28023", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x54524106, 0xffffffff, "TR28026", NULL, NULL },
|
|
|
|
{ 0x54524108, 0xffffffff, "TR28028", patch_tritech_tr28028, NULL }, // added by xin jin [07/09/99]
|
|
|
|
{ 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)]
|
2013-09-28 02:27:58 +08:00
|
|
|
{ 0x54584e03, 0xffffffff, "TLV320AIC27", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x54584e20, 0xffffffff, "TLC320AD9xC", NULL, NULL },
|
2015-03-06 23:59:00 +08:00
|
|
|
{ 0x56494120, 0xfffffff0, "VIA1613", patch_vt1613, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x56494161, 0xffffffff, "VIA1612A", NULL, NULL }, // modified ICE1232 with S/PDIF
|
2005-08-12 22:46:17 +08:00
|
|
|
{ 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF
|
2008-08-28 22:04:40 +08:00
|
|
|
{ 0x56494182, 0xffffffff, "VIA1618", patch_vt1618, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x57454301, 0xffffffff, "W83971D", NULL, NULL },
|
2008-07-15 09:00:21 +08:00
|
|
|
{ 0x574d4c00, 0xffffffff, "WM9701,WM9701A", NULL, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x574d4C03, 0xffffffff, "WM9703,WM9707,WM9708,WM9717", patch_wolfson03, NULL},
|
|
|
|
{ 0x574d4C04, 0xffffffff, "WM9704M,WM9704Q", patch_wolfson04, NULL},
|
|
|
|
{ 0x574d4C05, 0xffffffff, "WM9705,WM9710", patch_wolfson05, NULL},
|
|
|
|
{ 0x574d4C09, 0xffffffff, "WM9709", NULL, NULL},
|
2008-12-01 22:54:45 +08:00
|
|
|
{ 0x574d4C12, 0xffffffff, "WM9711,WM9712,WM9715", patch_wolfson11, NULL},
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x574d4c13, 0xffffffff, "WM9713,WM9714", patch_wolfson13, NULL, AC97_DEFAULT_POWER_OFF},
|
2007-09-19 20:29:37 +08:00
|
|
|
{ 0x594d4800, 0xffffffff, "YMF743", patch_yamaha_ymf743, NULL },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x594d4802, 0xffffffff, "YMF752", NULL, NULL },
|
|
|
|
{ 0x594d4803, 0xffffffff, "YMF753", patch_yamaha_ymf753, NULL },
|
|
|
|
{ 0x83847600, 0xffffffff, "STAC9700,83,84", patch_sigmatel_stac9700, NULL },
|
|
|
|
{ 0x83847604, 0xffffffff, "STAC9701,3,4,5", NULL, NULL },
|
|
|
|
{ 0x83847605, 0xffffffff, "STAC9704", NULL, NULL },
|
|
|
|
{ 0x83847608, 0xffffffff, "STAC9708,11", patch_sigmatel_stac9708, NULL },
|
|
|
|
{ 0x83847609, 0xffffffff, "STAC9721,23", patch_sigmatel_stac9721, NULL },
|
|
|
|
{ 0x83847644, 0xffffffff, "STAC9744", patch_sigmatel_stac9744, NULL },
|
|
|
|
{ 0x83847650, 0xffffffff, "STAC9750,51", NULL, NULL }, // patch?
|
|
|
|
{ 0x83847652, 0xffffffff, "STAC9752,53", NULL, NULL }, // patch?
|
|
|
|
{ 0x83847656, 0xffffffff, "STAC9756,57", patch_sigmatel_stac9756, NULL },
|
|
|
|
{ 0x83847658, 0xffffffff, "STAC9758,59", patch_sigmatel_stac9758, NULL },
|
|
|
|
{ 0x83847666, 0xffffffff, "STAC9766,67", NULL, NULL }, // patch?
|
|
|
|
{ 0, 0, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-06-28 00:28:53 +08:00
|
|
|
static void update_power_regs(struct snd_ac97 *ac97);
|
2006-10-25 00:25:29 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
|
|
|
#define ac97_is_power_save_mode(ac97) \
|
|
|
|
((ac97->scaps & AC97_SCAP_POWER_SAVE) && power_save)
|
|
|
|
#else
|
|
|
|
#define ac97_is_power_save_mode(ac97) 0
|
|
|
|
#endif
|
|
|
|
|
2014-02-25 22:37:50 +08:00
|
|
|
#define ac97_err(ac97, fmt, args...) \
|
|
|
|
dev_err((ac97)->bus->card->dev, fmt, ##args)
|
|
|
|
#define ac97_warn(ac97, fmt, args...) \
|
|
|
|
dev_warn((ac97)->bus->card->dev, fmt, ##args)
|
|
|
|
#define ac97_dbg(ac97, fmt, args...) \
|
|
|
|
dev_dbg((ac97)->bus->card->dev, fmt, ##args)
|
2006-06-28 00:28:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* I/O routines
|
|
|
|
*/
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* filter some registers for buggy codecs */
|
|
|
|
switch (ac97->id) {
|
2010-01-11 00:21:14 +08:00
|
|
|
case AC97_ID_ST_AC97_ID4:
|
|
|
|
if (reg == 0x08)
|
|
|
|
return 0;
|
|
|
|
/* fall through */
|
|
|
|
case AC97_ID_ST7597:
|
|
|
|
if (reg == 0x22 || reg == 0x7a)
|
|
|
|
return 1;
|
|
|
|
/* fall through */
|
2005-04-17 06:20:36 +08:00
|
|
|
case AC97_ID_AK4540:
|
|
|
|
case AC97_ID_AK4542:
|
|
|
|
if (reg <= 0x1c || reg == 0x20 || reg == 0x26 || reg >= 0x7c)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
case AC97_ID_AD1819: /* AD1819 */
|
|
|
|
case AC97_ID_AD1881: /* AD1881 */
|
|
|
|
case AC97_ID_AD1881A: /* AD1881A */
|
|
|
|
if (reg >= 0x3a && reg <= 0x6e) /* 0x59 */
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
case AC97_ID_AD1885: /* AD1885 */
|
|
|
|
case AC97_ID_AD1886: /* AD1886 */
|
|
|
|
case AC97_ID_AD1886A: /* AD1886A - !!verify!! --jk */
|
|
|
|
case AC97_ID_AD1887: /* AD1887 - !!verify!! --jk */
|
|
|
|
if (reg == 0x5a)
|
|
|
|
return 1;
|
|
|
|
if (reg >= 0x3c && reg <= 0x6e) /* 0x59 */
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
case AC97_ID_STAC9700:
|
|
|
|
case AC97_ID_STAC9704:
|
|
|
|
case AC97_ID_STAC9705:
|
|
|
|
case AC97_ID_STAC9708:
|
|
|
|
case AC97_ID_STAC9721:
|
|
|
|
case AC97_ID_STAC9744:
|
|
|
|
case AC97_ID_STAC9756:
|
|
|
|
if (reg <= 0x3a || reg >= 0x5a)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_ac97_write - write a value on the given register
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
* @reg: the register to change
|
|
|
|
* @value: the value to set
|
|
|
|
*
|
|
|
|
* Writes a value on the given register. This will invoke the write
|
|
|
|
* callback directly after the register check.
|
|
|
|
* This function doesn't change the register cache unlike
|
|
|
|
* #snd_ca97_write_cache(), so use this only when you don't want to
|
|
|
|
* reflect the change to the suspend/resume state.
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
void snd_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (!snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return;
|
|
|
|
if ((ac97->id & 0xffffff00) == AC97_ID_ALC100) {
|
|
|
|
/* Fix H/W bug of ALC100/100P */
|
|
|
|
if (reg == AC97_MASTER || reg == AC97_HEADPHONE)
|
|
|
|
ac97->bus->ops->write(ac97, AC97_RESET, 0); /* reset audio codec */
|
|
|
|
}
|
|
|
|
ac97->bus->ops->write(ac97, reg, value);
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_write);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* snd_ac97_read - read a value from the given register
|
|
|
|
*
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
* @reg: the register to read
|
|
|
|
*
|
|
|
|
* Reads a value from the given register. This will invoke the read
|
|
|
|
* callback directly after the register check.
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: The read value.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (!snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return 0;
|
|
|
|
return ac97->bus->ops->read(ac97, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read a register - return the cached value if already read */
|
2005-11-17 21:21:36 +08:00
|
|
|
static inline unsigned short snd_ac97_read_cache(struct snd_ac97 *ac97, unsigned short reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (! test_bit(reg, ac97->reg_accessed)) {
|
|
|
|
ac97->regs[reg] = ac97->bus->ops->read(ac97, reg);
|
|
|
|
// set_bit(reg, ac97->reg_accessed);
|
|
|
|
}
|
|
|
|
return ac97->regs[reg];
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_read);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* snd_ac97_write_cache - write a value on the given register and update the cache
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
* @reg: the register to change
|
|
|
|
* @value: the value to set
|
|
|
|
*
|
|
|
|
* Writes a value on the given register and updates the register
|
|
|
|
* cache. The cached values are used for the cached-read and the
|
|
|
|
* suspend/resume.
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (!snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return;
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
ac97->regs[reg] = value;
|
|
|
|
ac97->bus->ops->write(ac97, reg, value);
|
|
|
|
set_bit(reg, ac97->reg_accessed);
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_write_cache);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* snd_ac97_update - update the value on the given register
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
* @reg: the register to change
|
|
|
|
* @value: the value to set
|
|
|
|
*
|
|
|
|
* Compares the value with the register cache and updates the value
|
|
|
|
* only when the value is changed.
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: 1 if the value is changed, 0 if no change, or a negative
|
2005-04-17 06:20:36 +08:00
|
|
|
* code on failure.
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int change;
|
|
|
|
|
|
|
|
if (!snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return -EINVAL;
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
change = ac97->regs[reg] != value;
|
|
|
|
if (change) {
|
|
|
|
ac97->regs[reg] = value;
|
|
|
|
ac97->bus->ops->write(ac97, reg, value);
|
|
|
|
}
|
2005-06-30 19:47:06 +08:00
|
|
|
set_bit(reg, ac97->reg_accessed);
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_update);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* snd_ac97_update_bits - update the bits on the given register
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
* @reg: the register to change
|
|
|
|
* @mask: the bit-mask to change
|
|
|
|
* @value: the value to set
|
|
|
|
*
|
|
|
|
* Updates the masked-bits on the given register only when the value
|
|
|
|
* is changed.
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: 1 if the bits are changed, 0 if no change, or a negative
|
2005-04-17 06:20:36 +08:00
|
|
|
* code on failure.
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int change;
|
|
|
|
|
|
|
|
if (!snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return -EINVAL;
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_update_bits);
|
|
|
|
|
2009-01-29 04:20:06 +08:00
|
|
|
/* no lock version - see snd_ac97_update_bits() */
|
2005-11-17 21:21:36 +08:00
|
|
|
int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned short mask, unsigned short value)
|
|
|
|
{
|
|
|
|
int change;
|
|
|
|
unsigned short old, new;
|
|
|
|
|
|
|
|
old = snd_ac97_read_cache(ac97, reg);
|
2006-12-07 15:10:57 +08:00
|
|
|
new = (old & ~mask) | (value & mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
change = old != new;
|
|
|
|
if (change) {
|
|
|
|
ac97->regs[reg] = new;
|
|
|
|
ac97->bus->ops->write(ac97, reg, new);
|
|
|
|
}
|
2005-06-30 19:47:06 +08:00
|
|
|
set_bit(reg, ac97->reg_accessed);
|
2005-04-17 06:20:36 +08:00
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, unsigned short mask, unsigned short value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int change;
|
|
|
|
unsigned short old, new, cfg;
|
|
|
|
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->page_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
old = ac97->spec.ad18xx.pcmreg[codec];
|
2006-12-07 15:10:57 +08:00
|
|
|
new = (old & ~mask) | (value & mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
change = old != new;
|
|
|
|
if (change) {
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
cfg = snd_ac97_read_cache(ac97, AC97_AD_SERIAL_CFG);
|
|
|
|
ac97->spec.ad18xx.pcmreg[codec] = new;
|
|
|
|
/* select single codec */
|
|
|
|
ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
|
|
|
|
(cfg & ~0x7000) |
|
|
|
|
ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
|
|
|
|
/* update PCM bits */
|
|
|
|
ac97->bus->ops->write(ac97, AC97_PCM, new);
|
|
|
|
/* select all codecs */
|
|
|
|
ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
|
|
|
|
cfg | 0x7000);
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->page_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controls
|
|
|
|
*/
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
|
|
|
|
|
2014-10-21 00:15:36 +08:00
|
|
|
return snd_ctl_enum_info(uinfo, e->shift_l == e->shift_r ? 1 : 2,
|
|
|
|
e->mask, e->texts);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
|
2005-04-07 21:53:20 +08:00
|
|
|
unsigned short val, bitmask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-25 17:22:20 +08:00
|
|
|
for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
|
2005-04-07 21:53:20 +08:00
|
|
|
;
|
2005-04-17 06:20:36 +08:00
|
|
|
val = snd_ac97_read_cache(ac97, e->reg);
|
2005-04-07 21:53:20 +08:00
|
|
|
ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (e->shift_l != e->shift_r)
|
2005-04-07 21:53:20 +08:00
|
|
|
ucontrol->value.enumerated.item[1] = (val >> e->shift_r) & (bitmask - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_put_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ac97_enum *e = (struct ac97_enum *)kcontrol->private_value;
|
|
|
|
unsigned short val;
|
2005-04-07 21:53:20 +08:00
|
|
|
unsigned short mask, bitmask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-25 17:22:20 +08:00
|
|
|
for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
|
2005-04-07 21:53:20 +08:00
|
|
|
;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ucontrol->value.enumerated.item[0] > e->mask - 1)
|
|
|
|
return -EINVAL;
|
|
|
|
val = ucontrol->value.enumerated.item[0] << e->shift_l;
|
2005-04-07 21:53:20 +08:00
|
|
|
mask = (bitmask - 1) << e->shift_l;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (e->shift_l != e->shift_r) {
|
|
|
|
if (ucontrol->value.enumerated.item[1] > e->mask - 1)
|
|
|
|
return -EINVAL;
|
|
|
|
val |= ucontrol->value.enumerated.item[1] << e->shift_r;
|
2005-04-07 21:53:20 +08:00
|
|
|
mask |= (bitmask - 1) << e->shift_r;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return snd_ac97_update_bits(ac97, e->reg, mask, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save/restore ac97 v2.3 paging */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_page_save(struct snd_ac97 *ac97, int reg, struct snd_kcontrol *kcontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int page_save = -1;
|
|
|
|
if ((kcontrol->private_value & (1<<25)) &&
|
|
|
|
(ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
|
|
|
|
(reg >= 0x60 && reg < 0x70)) {
|
|
|
|
unsigned short page = (kcontrol->private_value >> 26) & 0x0f;
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->page_mutex); /* lock paging */
|
2005-04-17 06:20:36 +08:00
|
|
|
page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
|
|
|
|
snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
|
|
|
|
}
|
|
|
|
return page_save;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static void snd_ac97_page_restore(struct snd_ac97 *ac97, int page_save)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (page_save >= 0) {
|
|
|
|
snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->page_mutex); /* unlock paging */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* volume and switch controls */
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_info_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
int shift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
|
|
|
|
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = shift == rshift ? 1 : 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = mask;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_get_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int reg = kcontrol->private_value & 0xff;
|
|
|
|
int shift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
int invert = (kcontrol->private_value >> 24) & 0x01;
|
|
|
|
int page_save;
|
|
|
|
|
|
|
|
page_save = snd_ac97_page_save(ac97, reg, kcontrol);
|
|
|
|
ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask;
|
|
|
|
if (shift != rshift)
|
|
|
|
ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask;
|
|
|
|
if (invert) {
|
|
|
|
ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
|
|
|
if (shift != rshift)
|
|
|
|
ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
|
|
|
|
}
|
|
|
|
snd_ac97_page_restore(ac97, page_save);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_put_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int reg = kcontrol->private_value & 0xff;
|
|
|
|
int shift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
int invert = (kcontrol->private_value >> 24) & 0x01;
|
|
|
|
int err, page_save;
|
|
|
|
unsigned short val, val2, val_mask;
|
|
|
|
|
|
|
|
page_save = snd_ac97_page_save(ac97, reg, kcontrol);
|
|
|
|
val = (ucontrol->value.integer.value[0] & mask);
|
|
|
|
if (invert)
|
|
|
|
val = mask - val;
|
|
|
|
val_mask = mask << shift;
|
|
|
|
val = val << shift;
|
|
|
|
if (shift != rshift) {
|
|
|
|
val2 = (ucontrol->value.integer.value[1] & mask);
|
|
|
|
if (invert)
|
|
|
|
val2 = mask - val2;
|
|
|
|
val_mask |= mask << rshift;
|
|
|
|
val |= val2 << rshift;
|
|
|
|
}
|
|
|
|
err = snd_ac97_update_bits(ac97, reg, val_mask, val);
|
|
|
|
snd_ac97_page_restore(ac97, page_save);
|
2006-06-28 00:28:53 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
|
|
|
/* check analog mixer power-down */
|
2011-02-17 07:17:53 +08:00
|
|
|
if ((val_mask & AC97_PD_EAPD) &&
|
2006-06-28 00:28:53 +08:00
|
|
|
(kcontrol->private_value & (1<<30))) {
|
2011-02-17 07:17:53 +08:00
|
|
|
if (val & AC97_PD_EAPD)
|
2006-06-28 00:28:53 +08:00
|
|
|
ac97->power_up &= ~(1 << (reg>>1));
|
|
|
|
else
|
|
|
|
ac97->power_up |= 1 << (reg>>1);
|
2006-10-19 21:20:08 +08:00
|
|
|
update_power_regs(ac97);
|
2006-06-28 00:28:53 +08:00
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_tone[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("Tone Control - Bass", AC97_MASTER_TONE, 8, 15, 1),
|
|
|
|
AC97_SINGLE("Tone Control - Treble", AC97_MASTER_TONE, 0, 15, 1)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = {
|
2009-11-03 22:47:25 +08:00
|
|
|
AC97_SINGLE("Beep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
|
|
|
|
AC97_SINGLE("Beep Playback Volume", AC97_PC_BEEP, 1, 15, 1)
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_mic_boost =
|
2006-09-01 12:27:50 +08:00
|
|
|
AC97_SINGLE("Mic Boost (+20dB)", AC97_MIC, 6, 1, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
static const char* std_rec_sel[] = {"Mic", "CD", "Video", "Aux", "Line", "Mix", "Mix Mono", "Phone"};
|
|
|
|
static const char* std_3d_path[] = {"pre 3D", "post 3D"};
|
|
|
|
static const char* std_mix[] = {"Mix", "Mic"};
|
|
|
|
static const char* std_mic[] = {"Mic1", "Mic2"};
|
|
|
|
|
|
|
|
static const struct ac97_enum std_enum[] = {
|
|
|
|
AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, std_rec_sel),
|
|
|
|
AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, std_3d_path),
|
|
|
|
AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 9, 2, std_mix),
|
|
|
|
AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, std_mic),
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_control_capture_src =
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_ENUM("Capture Source", std_enum[0]);
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_control_capture_vol =
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0);
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_mic_capture[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("Mic Capture Switch", AC97_REC_GAIN_MIC, 15, 1, 1),
|
|
|
|
AC97_SINGLE("Mic Capture Volume", AC97_REC_GAIN_MIC, 0, 15, 0)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
enum {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_GENERAL_PCM_OUT = 0,
|
|
|
|
AC97_GENERAL_STEREO_ENHANCEMENT,
|
|
|
|
AC97_GENERAL_3D,
|
|
|
|
AC97_GENERAL_LOUDNESS,
|
|
|
|
AC97_GENERAL_MONO,
|
|
|
|
AC97_GENERAL_MIC,
|
|
|
|
AC97_GENERAL_LOOPBACK
|
2005-11-17 21:21:36 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_general[7] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_ENUM("PCM Out Path & Mute", std_enum[1]),
|
|
|
|
AC97_SINGLE("Simulated Stereo Enhancement", AC97_GENERAL_PURPOSE, 14, 1, 0),
|
|
|
|
AC97_SINGLE("3D Control - Switch", AC97_GENERAL_PURPOSE, 13, 1, 0),
|
|
|
|
AC97_SINGLE("Loudness (bass boost)", AC97_GENERAL_PURPOSE, 12, 1, 0),
|
|
|
|
AC97_ENUM("Mono Output Select", std_enum[2]),
|
2006-09-01 12:27:50 +08:00
|
|
|
AC97_ENUM("Mic Select", std_enum[3]),
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("ADC/DAC Loopback", AC97_GENERAL_PURPOSE, 7, 1, 0)
|
|
|
|
};
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_3d[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("3D Control - Center", AC97_3D_CONTROL, 8, 15, 0),
|
|
|
|
AC97_SINGLE("3D Control - Depth", AC97_3D_CONTROL, 0, 15, 0)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_center[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("Center Playback Switch", AC97_CENTER_LFE_MASTER, 7, 1, 1),
|
|
|
|
AC97_SINGLE("Center Playback Volume", AC97_CENTER_LFE_MASTER, 0, 31, 1)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_lfe[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("LFE Playback Switch", AC97_CENTER_LFE_MASTER, 15, 1, 1),
|
|
|
|
AC97_SINGLE("LFE Playback Volume", AC97_CENTER_LFE_MASTER, 8, 31, 1)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_control_eapd =
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("External Amplifier", AC97_POWERDOWN, 15, 1, 1);
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_modem_switches[2] = {
|
2005-05-29 21:08:23 +08:00
|
|
|
AC97_SINGLE("Off-hook Switch", AC97_GPIO_STATUS, 0, 1, 0),
|
|
|
|
AC97_SINGLE("Caller ID Switch", AC97_GPIO_STATUS, 2, 1, 0)
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* change the existing EAPD control as inverted */
|
2005-11-17 21:21:36 +08:00
|
|
|
static void set_inv_eapd(struct snd_ac97 *ac97, struct snd_kcontrol *kctl)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
kctl->private_value = AC97_SINGLE_VALUE(AC97_POWERDOWN, 15, 1, 0);
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN, (1<<15), (1<<15)); /* EAPD up */
|
|
|
|
ac97->scaps |= AC97_SCAP_INV_EAPD;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
|
|
|
|
uinfo->count = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_spdif_cmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
|
|
|
|
IEC958_AES0_NONAUDIO |
|
|
|
|
IEC958_AES0_CON_EMPHASIS_5015 |
|
|
|
|
IEC958_AES0_CON_NOT_COPYRIGHT;
|
|
|
|
ucontrol->value.iec958.status[1] = IEC958_AES1_CON_CATEGORY |
|
|
|
|
IEC958_AES1_CON_ORIGINAL;
|
|
|
|
ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_spdif_pmask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* FIXME: AC'97 spec doesn't say which bits are used for what */
|
|
|
|
ucontrol->value.iec958.status[0] = IEC958_AES0_PROFESSIONAL |
|
|
|
|
IEC958_AES0_NONAUDIO |
|
|
|
|
IEC958_AES0_PRO_FS |
|
|
|
|
IEC958_AES0_PRO_EMPHASIS_5015;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
ucontrol->value.iec958.status[0] = ac97->spdif_status & 0xff;
|
|
|
|
ucontrol->value.iec958.status[1] = (ac97->spdif_status >> 8) & 0xff;
|
|
|
|
ucontrol->value.iec958.status[2] = (ac97->spdif_status >> 16) & 0xff;
|
|
|
|
ucontrol->value.iec958.status[3] = (ac97->spdif_status >> 24) & 0xff;
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int new = 0;
|
|
|
|
unsigned short val = 0;
|
|
|
|
int change;
|
|
|
|
|
|
|
|
new = val = ucontrol->value.iec958.status[0] & (IEC958_AES0_PROFESSIONAL|IEC958_AES0_NONAUDIO);
|
|
|
|
if (ucontrol->value.iec958.status[0] & IEC958_AES0_PROFESSIONAL) {
|
|
|
|
new |= ucontrol->value.iec958.status[0] & (IEC958_AES0_PRO_FS|IEC958_AES0_PRO_EMPHASIS_5015);
|
|
|
|
switch (new & IEC958_AES0_PRO_FS) {
|
|
|
|
case IEC958_AES0_PRO_FS_44100: val |= 0<<12; break;
|
|
|
|
case IEC958_AES0_PRO_FS_48000: val |= 2<<12; break;
|
|
|
|
case IEC958_AES0_PRO_FS_32000: val |= 3<<12; break;
|
|
|
|
default: val |= 1<<12; break;
|
|
|
|
}
|
|
|
|
if ((new & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
|
|
|
|
val |= 1<<3;
|
|
|
|
} else {
|
|
|
|
new |= ucontrol->value.iec958.status[0] & (IEC958_AES0_CON_EMPHASIS_5015|IEC958_AES0_CON_NOT_COPYRIGHT);
|
|
|
|
new |= ((ucontrol->value.iec958.status[1] & (IEC958_AES1_CON_CATEGORY|IEC958_AES1_CON_ORIGINAL)) << 8);
|
|
|
|
new |= ((ucontrol->value.iec958.status[3] & IEC958_AES3_CON_FS) << 24);
|
|
|
|
if ((new & IEC958_AES0_CON_EMPHASIS) == IEC958_AES0_CON_EMPHASIS_5015)
|
|
|
|
val |= 1<<3;
|
|
|
|
if (!(new & IEC958_AES0_CON_NOT_COPYRIGHT))
|
|
|
|
val |= 1<<2;
|
|
|
|
val |= ((new >> 8) & 0xff) << 4; // category + original
|
|
|
|
switch ((new >> 24) & 0xff) {
|
|
|
|
case IEC958_AES3_CON_FS_44100: val |= 0<<12; break;
|
|
|
|
case IEC958_AES3_CON_FS_48000: val |= 2<<12; break;
|
|
|
|
case IEC958_AES3_CON_FS_32000: val |= 3<<12; break;
|
|
|
|
default: val |= 1<<12; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
change = ac97->spdif_status != new;
|
|
|
|
ac97->spdif_status = new;
|
|
|
|
|
|
|
|
if (ac97->flags & AC97_CS_SPDIF) {
|
|
|
|
int x = (val >> 12) & 0x03;
|
|
|
|
switch (x) {
|
|
|
|
case 0: x = 1; break; // 44.1
|
|
|
|
case 2: x = 0; break; // 48.0
|
|
|
|
default: x = 0; break; // illegal.
|
|
|
|
}
|
|
|
|
change |= snd_ac97_update_bits_nolock(ac97, AC97_CSR_SPDIF, 0x3fff, ((val & 0xcfff) | (x << 12)));
|
|
|
|
} else if (ac97->flags & AC97_CX_SPDIF) {
|
|
|
|
int v;
|
|
|
|
v = new & (IEC958_AES0_CON_EMPHASIS_5015|IEC958_AES0_CON_NOT_COPYRIGHT) ? 0 : AC97_CXR_COPYRGT;
|
|
|
|
v |= new & IEC958_AES0_NONAUDIO ? AC97_CXR_SPDIF_AC3 : AC97_CXR_SPDIF_PCM;
|
|
|
|
change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC,
|
|
|
|
AC97_CXR_SPDIF_MASK | AC97_CXR_COPYRGT,
|
|
|
|
v);
|
2007-09-19 20:29:37 +08:00
|
|
|
} else if (ac97->id == AC97_ID_YMF743) {
|
|
|
|
change |= snd_ac97_update_bits_nolock(ac97,
|
|
|
|
AC97_YMF7X3_DIT_CTRL,
|
|
|
|
0xff38,
|
|
|
|
((val << 4) & 0xff00) |
|
|
|
|
((val << 2) & 0x0038));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
|
|
|
|
snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
|
|
|
|
|
|
|
|
change |= snd_ac97_update_bits_nolock(ac97, AC97_SPDIF, 0x3fff, val);
|
|
|
|
if (extst & AC97_EA_SPDIF) {
|
|
|
|
snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
|
|
|
|
}
|
|
|
|
}
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_put_spsa(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int reg = kcontrol->private_value & 0xff;
|
2018-11-23 22:44:00 +08:00
|
|
|
int shift = (kcontrol->private_value >> 8) & 0x0f;
|
2005-04-17 06:20:36 +08:00
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
// int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
unsigned short value, old, new;
|
|
|
|
int change;
|
|
|
|
|
|
|
|
value = (ucontrol->value.integer.value[0] & mask);
|
|
|
|
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
mask <<= shift;
|
|
|
|
value <<= shift;
|
|
|
|
old = snd_ac97_read_cache(ac97, reg);
|
|
|
|
new = (old & ~mask) | value;
|
|
|
|
change = old != new;
|
|
|
|
|
|
|
|
if (change) {
|
|
|
|
unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
|
|
|
|
snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
|
|
|
|
change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
|
|
|
|
if (extst & AC97_EA_SPDIF)
|
|
|
|
snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
|
|
|
|
}
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->reg_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_spdif[5] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
|
|
|
|
.info = snd_ac97_spdif_mask_info,
|
|
|
|
.get = snd_ac97_spdif_cmask_get,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
|
|
|
|
.info = snd_ac97_spdif_mask_info,
|
|
|
|
.get = snd_ac97_spdif_pmask_get,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
|
|
|
|
.info = snd_ac97_spdif_mask_info,
|
|
|
|
.get = snd_ac97_spdif_default_get,
|
|
|
|
.put = snd_ac97_spdif_default_put,
|
|
|
|
},
|
|
|
|
|
|
|
|
AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),AC97_EXTENDED_STATUS, 2, 1, 0),
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA",
|
|
|
|
.info = snd_ac97_info_volsw,
|
|
|
|
.get = snd_ac97_get_volsw,
|
|
|
|
.put = snd_ac97_put_spsa,
|
|
|
|
.private_value = AC97_SINGLE_VALUE(AC97_EXTENDED_STATUS, 4, 3, 0)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define AD18XX_PCM_BITS(xname, codec, lshift, rshift, mask) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_ad18xx_pcm_info_bits, \
|
|
|
|
.get = snd_ac97_ad18xx_pcm_get_bits, .put = snd_ac97_ad18xx_pcm_put_bits, \
|
|
|
|
.private_value = (codec) | ((lshift) << 8) | ((rshift) << 12) | ((mask) << 16) }
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_pcm_info_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int mask = (kcontrol->private_value >> 16) & 0x0f;
|
|
|
|
int lshift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
|
|
|
|
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
|
|
|
|
uinfo->count = 2;
|
|
|
|
else
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = mask;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_pcm_get_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int codec = kcontrol->private_value & 3;
|
|
|
|
int lshift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask);
|
|
|
|
if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
|
|
|
|
ucontrol->value.integer.value[1] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> rshift) & mask);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_pcm_put_bits(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int codec = kcontrol->private_value & 3;
|
|
|
|
int lshift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
unsigned short val, valmask;
|
|
|
|
|
|
|
|
val = (mask - (ucontrol->value.integer.value[0] & mask)) << lshift;
|
|
|
|
valmask = mask << lshift;
|
|
|
|
if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) {
|
|
|
|
val |= (mask - (ucontrol->value.integer.value[1] & mask)) << rshift;
|
|
|
|
valmask |= mask << rshift;
|
|
|
|
}
|
|
|
|
return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, valmask, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define AD18XX_PCM_VOLUME(xname, codec) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_ad18xx_pcm_info_volume, \
|
|
|
|
.get = snd_ac97_ad18xx_pcm_get_volume, .put = snd_ac97_ad18xx_pcm_put_volume, \
|
|
|
|
.private_value = codec }
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_pcm_info_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = 31;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_pcm_get_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int codec = kcontrol->private_value & 3;
|
|
|
|
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_lock(&ac97->page_mutex);
|
2024-06-12 13:13:20 +08:00
|
|
|
ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 8) & 31);
|
|
|
|
ucontrol->value.integer.value[1] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31);
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_unlock(&ac97->page_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_ad18xx_pcm_put_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int codec = kcontrol->private_value & 3;
|
|
|
|
unsigned short val1, val2;
|
|
|
|
|
|
|
|
val1 = 31 - (ucontrol->value.integer.value[0] & 31);
|
|
|
|
val2 = 31 - (ucontrol->value.integer.value[1] & 31);
|
|
|
|
return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, 0x1f1f, (val1 << 8) | val2);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_pcm[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AD18XX_PCM_BITS("PCM Playback Switch", 0, 15, 7, 1),
|
|
|
|
AD18XX_PCM_VOLUME("PCM Playback Volume", 0)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_surround[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AD18XX_PCM_BITS("Surround Playback Switch", 1, 15, 7, 1),
|
|
|
|
AD18XX_PCM_VOLUME("Surround Playback Volume", 1)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_center[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AD18XX_PCM_BITS("Center Playback Switch", 2, 15, 15, 1),
|
|
|
|
AD18XX_PCM_BITS("Center Playback Volume", 2, 8, 8, 31)
|
|
|
|
};
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_lfe[2] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
AD18XX_PCM_BITS("LFE Playback Switch", 2, 7, 7, 1),
|
|
|
|
AD18XX_PCM_BITS("LFE Playback Volume", 2, 0, 0, 31)
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static void snd_ac97_powerdown(struct snd_ac97 *ac97);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_bus_free(struct snd_ac97_bus *bus)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (bus) {
|
|
|
|
snd_ac97_bus_proc_done(bus);
|
|
|
|
kfree(bus->pcms);
|
|
|
|
if (bus->private_free)
|
|
|
|
bus->private_free(bus);
|
|
|
|
kfree(bus);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_bus_dev_free(struct snd_device *device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97_bus *bus = device->device_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
return snd_ac97_bus_free(bus);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_free(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (ac97) {
|
2006-06-28 00:28:53 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
2010-12-12 00:51:26 +08:00
|
|
|
cancel_delayed_work_sync(&ac97->power_work);
|
2006-06-28 00:28:53 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_proc_done(ac97);
|
2005-09-29 18:58:24 +08:00
|
|
|
if (ac97->bus)
|
2005-04-17 06:20:36 +08:00
|
|
|
ac97->bus->codec[ac97->num] = NULL;
|
|
|
|
if (ac97->private_free)
|
|
|
|
ac97->private_free(ac97);
|
|
|
|
kfree(ac97);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_dev_free(struct snd_device *device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = device->device_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_powerdown(ac97); /* for avoiding click noises during shut down */
|
|
|
|
return snd_ac97_free(ac97);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_try_volume_mix(struct snd_ac97 * ac97, int reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-02-17 07:17:53 +08:00
|
|
|
unsigned short val, mask = AC97_MUTE_MASK_MONO;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (! snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case AC97_MASTER_TONE:
|
2011-02-17 07:17:53 +08:00
|
|
|
return ac97->caps & AC97_BC_BASS_TREBLE ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
case AC97_HEADPHONE:
|
2011-02-17 07:17:53 +08:00
|
|
|
return ac97->caps & AC97_BC_HEADPHONE ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
case AC97_REC_GAIN_MIC:
|
2011-02-17 07:17:53 +08:00
|
|
|
return ac97->caps & AC97_BC_DEDICATED_MIC ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
case AC97_3D_CONTROL:
|
2011-02-17 07:17:53 +08:00
|
|
|
if (ac97->caps & AC97_BC_3D_TECH_ID_MASK) {
|
2005-04-17 06:20:36 +08:00
|
|
|
val = snd_ac97_read(ac97, reg);
|
|
|
|
/* if nonzero - fixed and we can't set it */
|
|
|
|
return val == 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case AC97_CENTER_LFE_MASTER: /* center */
|
|
|
|
if ((ac97->ext_id & AC97_EI_CDAC) == 0)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case AC97_CENTER_LFE_MASTER+1: /* lfe */
|
|
|
|
if ((ac97->ext_id & AC97_EI_LDAC) == 0)
|
|
|
|
return 0;
|
|
|
|
reg = AC97_CENTER_LFE_MASTER;
|
|
|
|
mask = 0x0080;
|
|
|
|
break;
|
|
|
|
case AC97_SURROUND_MASTER:
|
|
|
|
if ((ac97->ext_id & AC97_EI_SDAC) == 0)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = snd_ac97_read(ac97, reg);
|
|
|
|
if (!(val & mask)) {
|
|
|
|
/* nothing seems to be here - mute flag is not set */
|
|
|
|
/* try another test */
|
|
|
|
snd_ac97_write_cache(ac97, reg, val | mask);
|
|
|
|
val = snd_ac97_read(ac97, reg);
|
2005-11-17 21:21:36 +08:00
|
|
|
val = snd_ac97_read(ac97, reg);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(val & mask))
|
|
|
|
return 0; /* nothing here */
|
|
|
|
}
|
|
|
|
return 1; /* success, useable */
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static void check_volume_resolution(struct snd_ac97 *ac97, int reg, unsigned char *lo_max, unsigned char *hi_max)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short cbit[3] = { 0x20, 0x10, 0x01 };
|
|
|
|
unsigned char max[3] = { 63, 31, 15 };
|
|
|
|
int i;
|
|
|
|
|
2006-02-09 18:45:20 +08:00
|
|
|
/* first look up the static resolution table */
|
|
|
|
if (ac97->res_table) {
|
|
|
|
const struct snd_ac97_res_table *tbl;
|
|
|
|
for (tbl = ac97->res_table; tbl->reg; tbl++) {
|
|
|
|
if (tbl->reg == reg) {
|
|
|
|
*lo_max = tbl->bits & 0xff;
|
|
|
|
*hi_max = (tbl->bits >> 8) & 0xff;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
*lo_max = *hi_max = 0;
|
|
|
|
for (i = 0 ; i < ARRAY_SIZE(cbit); i++) {
|
|
|
|
unsigned short val;
|
2011-02-17 07:17:53 +08:00
|
|
|
snd_ac97_write(
|
|
|
|
ac97, reg,
|
|
|
|
AC97_MUTE_MASK_STEREO | cbit[i] | (cbit[i] << 8)
|
|
|
|
);
|
2005-07-10 18:04:29 +08:00
|
|
|
/* Do the read twice due to buffers on some ac97 codecs.
|
2007-05-09 14:57:56 +08:00
|
|
|
* e.g. The STAC9704 returns exactly what you wrote to the register
|
2005-07-10 18:04:29 +08:00
|
|
|
* if you read it immediately. This causes the detect routine to fail.
|
|
|
|
*/
|
|
|
|
val = snd_ac97_read(ac97, reg);
|
2005-04-17 06:20:36 +08:00
|
|
|
val = snd_ac97_read(ac97, reg);
|
2005-03-29 22:33:28 +08:00
|
|
|
if (! *lo_max && (val & 0x7f) == cbit[i])
|
2005-04-17 06:20:36 +08:00
|
|
|
*lo_max = max[i];
|
2005-03-29 22:33:28 +08:00
|
|
|
if (! *hi_max && ((val >> 8) & 0x7f) == cbit[i])
|
2005-04-17 06:20:36 +08:00
|
|
|
*hi_max = max[i];
|
|
|
|
if (*lo_max && *hi_max)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short mask, val, orig, res;
|
|
|
|
|
|
|
|
mask = 1 << bit;
|
|
|
|
orig = snd_ac97_read(ac97, reg);
|
|
|
|
val = orig ^ mask;
|
|
|
|
snd_ac97_write(ac97, reg, val);
|
|
|
|
res = snd_ac97_read(ac97, reg);
|
|
|
|
snd_ac97_write_cache(ac97, reg, orig);
|
|
|
|
return res == val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check the volume resolution of center/lfe */
|
2005-11-17 21:21:36 +08:00
|
|
|
static void snd_ac97_change_volume_params2(struct snd_ac97 * ac97, int reg, int shift, unsigned char *max)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short val, val1;
|
|
|
|
|
|
|
|
*max = 63;
|
2011-02-17 07:17:53 +08:00
|
|
|
val = AC97_MUTE_MASK_STEREO | (0x20 << shift);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write(ac97, reg, val);
|
|
|
|
val1 = snd_ac97_read(ac97, reg);
|
|
|
|
if (val != val1) {
|
|
|
|
*max = 31;
|
|
|
|
}
|
|
|
|
/* reset volume to zero */
|
2011-02-17 07:17:53 +08:00
|
|
|
snd_ac97_write_cache(ac97, reg, AC97_MUTE_MASK_STEREO);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int printable(unsigned int x)
|
|
|
|
{
|
|
|
|
x &= 0xff;
|
|
|
|
if (x < ' ' || x >= 0x71) {
|
|
|
|
if (x <= 0x89)
|
|
|
|
return x - 0x71 + 'A';
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-02-22 19:58:27 +08:00
|
|
|
static struct snd_kcontrol *snd_ac97_cnew(const struct snd_kcontrol_new *_template,
|
|
|
|
struct snd_ac97 * ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol_new template;
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(&template, _template, sizeof(template));
|
|
|
|
template.index = ac97->num;
|
|
|
|
return snd_ctl_new1(&template, ac97);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create mute switch(es) for normal stereo controls
|
|
|
|
*/
|
2006-06-28 00:28:53 +08:00
|
|
|
static int snd_ac97_cmute_new_stereo(struct snd_card *card, char *name, int reg,
|
|
|
|
int check_stereo, int check_amix,
|
|
|
|
struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *kctl;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
unsigned short val, val1, mute_mask;
|
|
|
|
|
|
|
|
if (! snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return 0;
|
|
|
|
|
2011-02-17 07:17:53 +08:00
|
|
|
mute_mask = AC97_MUTE_MASK_MONO;
|
2005-04-17 06:20:36 +08:00
|
|
|
val = snd_ac97_read(ac97, reg);
|
|
|
|
if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) {
|
|
|
|
/* check whether both mute bits work */
|
2011-02-17 07:17:53 +08:00
|
|
|
val1 = val | AC97_MUTE_MASK_STEREO;
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write(ac97, reg, val1);
|
|
|
|
if (val1 == snd_ac97_read(ac97, reg))
|
2011-02-17 07:17:53 +08:00
|
|
|
mute_mask = AC97_MUTE_MASK_STEREO;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-02-17 07:17:53 +08:00
|
|
|
if (mute_mask == AC97_MUTE_MASK_STEREO) {
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol_new tmp = AC97_DOUBLE(name, reg, 15, 7, 1, 1);
|
2006-06-28 00:28:53 +08:00
|
|
|
if (check_amix)
|
|
|
|
tmp.private_value |= (1 << 30);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp.index = ac97->num;
|
|
|
|
kctl = snd_ctl_new1(&tmp, ac97);
|
|
|
|
} else {
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol_new tmp = AC97_SINGLE(name, reg, 15, 1, 1);
|
2006-06-28 00:28:53 +08:00
|
|
|
if (check_amix)
|
|
|
|
tmp.private_value |= (1 << 30);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp.index = ac97->num;
|
|
|
|
kctl = snd_ctl_new1(&tmp, ac97);
|
|
|
|
}
|
|
|
|
err = snd_ctl_add(card, kctl);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
/* mute as default */
|
|
|
|
snd_ac97_write_cache(ac97, reg, val | mute_mask);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-22 00:44:31 +08:00
|
|
|
/*
|
|
|
|
* set dB information
|
|
|
|
*/
|
2007-01-29 22:33:49 +08:00
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
|
2006-08-22 00:44:31 +08:00
|
|
|
|
2007-01-29 22:33:49 +08:00
|
|
|
static const unsigned int *find_db_scale(unsigned int maxval)
|
2006-08-22 00:44:31 +08:00
|
|
|
{
|
|
|
|
switch (maxval) {
|
|
|
|
case 0x0f: return db_scale_4bit;
|
|
|
|
case 0x1f: return db_scale_5bit;
|
|
|
|
case 0x3f: return db_scale_6bit;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-29 22:33:49 +08:00
|
|
|
static void set_tlv_db_scale(struct snd_kcontrol *kctl, const unsigned int *tlv)
|
|
|
|
{
|
2006-08-22 00:44:31 +08:00
|
|
|
kctl->tlv.p = tlv;
|
|
|
|
if (tlv)
|
|
|
|
kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* create a volume for normal stereo/mono controls
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_cvol_new(struct snd_card *card, char *name, int reg, unsigned int lo_max,
|
|
|
|
unsigned int hi_max, struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *kctl;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (! snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return 0;
|
|
|
|
if (hi_max) {
|
|
|
|
/* invert */
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol_new tmp = AC97_DOUBLE(name, reg, 8, 0, lo_max, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp.index = ac97->num;
|
|
|
|
kctl = snd_ctl_new1(&tmp, ac97);
|
|
|
|
} else {
|
|
|
|
/* invert */
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol_new tmp = AC97_SINGLE(name, reg, 0, lo_max, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp.index = ac97->num;
|
|
|
|
kctl = snd_ctl_new1(&tmp, ac97);
|
|
|
|
}
|
2012-10-11 22:43:40 +08:00
|
|
|
if (!kctl)
|
|
|
|
return -ENOMEM;
|
2006-08-22 00:44:31 +08:00
|
|
|
if (reg >= AC97_PHONE && reg <= AC97_PCM)
|
|
|
|
set_tlv_db_scale(kctl, db_scale_5bit_12db_max);
|
|
|
|
else
|
|
|
|
set_tlv_db_scale(kctl, find_db_scale(lo_max));
|
2005-04-17 06:20:36 +08:00
|
|
|
err = snd_ctl_add(card, kctl);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2011-02-17 07:17:53 +08:00
|
|
|
snd_ac97_write_cache(
|
|
|
|
ac97, reg,
|
|
|
|
(snd_ac97_read(ac97, reg) & AC97_MUTE_MASK_STEREO)
|
|
|
|
| lo_max | (hi_max << 8)
|
|
|
|
);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a mute-switch and a volume for normal stereo/mono controls
|
|
|
|
*/
|
2006-06-28 00:28:53 +08:00
|
|
|
static int snd_ac97_cmix_new_stereo(struct snd_card *card, const char *pfx,
|
|
|
|
int reg, int check_stereo, int check_amix,
|
|
|
|
struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2013-06-28 17:56:49 +08:00
|
|
|
char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char lo_max, hi_max;
|
|
|
|
|
|
|
|
if (! snd_ac97_valid_reg(ac97, reg))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (snd_ac97_try_bit(ac97, reg, 15)) {
|
|
|
|
sprintf(name, "%s Switch", pfx);
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmute_new_stereo(card, name, reg,
|
|
|
|
check_stereo, check_amix,
|
|
|
|
ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
check_volume_resolution(ac97, reg, &lo_max, &hi_max);
|
|
|
|
if (lo_max) {
|
|
|
|
sprintf(name, "%s Volume", pfx);
|
|
|
|
if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-28 00:28:53 +08:00
|
|
|
#define snd_ac97_cmix_new(card, pfx, reg, acheck, ac97) \
|
|
|
|
snd_ac97_cmix_new_stereo(card, pfx, reg, 0, acheck, ac97)
|
|
|
|
#define snd_ac97_cmute_new(card, name, reg, acheck, ac97) \
|
|
|
|
snd_ac97_cmute_new_stereo(card, name, reg, 0, acheck, ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_card *card = ac97->bus->card;
|
|
|
|
struct snd_kcontrol *kctl;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
unsigned int idx;
|
|
|
|
unsigned char max;
|
|
|
|
|
|
|
|
/* build master controls */
|
|
|
|
/* AD claims to remove this control from AD1887, although spec v2.2 does not allow this */
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
|
|
|
|
if (ac97->flags & AC97_HAS_NO_MASTER_VOL)
|
2006-06-28 00:28:53 +08:00
|
|
|
err = snd_ac97_cmute_new(card, "Master Playback Switch",
|
|
|
|
AC97_MASTER, 0, ac97);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2006-06-28 00:28:53 +08:00
|
|
|
err = snd_ac97_cmix_new(card, "Master Playback",
|
|
|
|
AC97_MASTER, 0, ac97);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-02-17 07:17:53 +08:00
|
|
|
ac97->regs[AC97_CENTER_LFE_MASTER] = AC97_MUTE_MASK_STEREO;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* build center controls */
|
2006-06-12 16:08:02 +08:00
|
|
|
if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER))
|
|
|
|
&& !(ac97->flags & AC97_AD_MULTI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max);
|
|
|
|
kctl->private_value &= ~(0xff << 16);
|
|
|
|
kctl->private_value |= (int)max << 16;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, find_db_scale(max));
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build LFE controls */
|
2006-06-12 16:08:02 +08:00
|
|
|
if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1))
|
|
|
|
&& !(ac97->flags & AC97_AD_MULTI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max);
|
|
|
|
kctl->private_value &= ~(0xff << 16);
|
|
|
|
kctl->private_value |= (int)max << 16;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, find_db_scale(max));
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build surround controls */
|
2006-06-12 16:08:02 +08:00
|
|
|
if ((snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER))
|
|
|
|
&& !(ac97->flags & AC97_AD_MULTI)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Surround Master (0x38) is with stereo mutes */
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new_stereo(card, "Surround Playback",
|
|
|
|
AC97_SURROUND_MASTER, 1, 0,
|
|
|
|
ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build headphone controls */
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Headphone Playback",
|
|
|
|
AC97_HEADPHONE, 0, ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build master mono controls */
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Master Mono Playback",
|
|
|
|
AC97_MASTER_MONO, 0, ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build master tone controls */
|
2005-07-29 17:41:55 +08:00
|
|
|
if (!(ac97->flags & AC97_HAS_NO_TONE)) {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) {
|
|
|
|
for (idx = 0; idx < 2; idx++) {
|
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
|
|
|
|
return err;
|
2007-09-19 20:29:37 +08:00
|
|
|
if (ac97->id == AC97_ID_YMF743 ||
|
|
|
|
ac97->id == AC97_ID_YMF753) {
|
2005-07-29 17:41:55 +08:00
|
|
|
kctl->private_value &= ~(0xff << 16);
|
|
|
|
kctl->private_value |= 7 << 16;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-07-29 17:41:55 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-03 22:47:25 +08:00
|
|
|
/* build Beep controls */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
|
|
|
|
((ac97->flags & AC97_HAS_PC_BEEP) ||
|
|
|
|
snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
|
|
|
|
for (idx = 0; idx < 2; idx++)
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_4bit);
|
2011-02-17 07:17:53 +08:00
|
|
|
snd_ac97_write_cache(
|
|
|
|
ac97,
|
|
|
|
AC97_PC_BEEP,
|
|
|
|
(snd_ac97_read(ac97, AC97_PC_BEEP)
|
|
|
|
| AC97_MUTE_MASK_MONO | 0x001e)
|
|
|
|
);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* build Phone controls */
|
|
|
|
if (!(ac97->flags & AC97_HAS_NO_PHONE)) {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Phone Playback",
|
|
|
|
AC97_PHONE, 1, ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build MIC controls */
|
2005-07-29 17:41:55 +08:00
|
|
|
if (!(ac97->flags & AC97_HAS_NO_MIC)) {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_MIC)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Mic Playback",
|
|
|
|
AC97_MIC, 1, ac97)) < 0)
|
2005-07-29 17:41:55 +08:00
|
|
|
return err;
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* build Line controls */
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_LINE)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Line Playback",
|
|
|
|
AC97_LINE, 1, ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build CD controls */
|
|
|
|
if (!(ac97->flags & AC97_HAS_NO_CD)) {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_CD)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "CD Playback",
|
|
|
|
AC97_CD, 1, ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build Video controls */
|
|
|
|
if (!(ac97->flags & AC97_HAS_NO_VIDEO)) {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Video Playback",
|
|
|
|
AC97_VIDEO, 1, ac97)) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build Aux controls */
|
2006-06-19 21:04:54 +08:00
|
|
|
if (!(ac97->flags & AC97_HAS_NO_AUX)) {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_AUX)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
if ((err = snd_ac97_cmix_new(card, "Aux Playback",
|
|
|
|
AC97_AUX, 1, ac97)) < 0)
|
2006-06-19 21:04:54 +08:00
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* build PCM controls */
|
|
|
|
if (ac97->flags & AC97_AD_MULTI) {
|
|
|
|
unsigned short init_val;
|
|
|
|
if (ac97->flags & AC97_STEREO_MUTES)
|
|
|
|
init_val = 0x9f9f;
|
|
|
|
else
|
|
|
|
init_val = 0x9f1f;
|
|
|
|
for (idx = 0; idx < 2; idx++)
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_5bit);
|
2005-04-17 06:20:36 +08:00
|
|
|
ac97->spec.ad18xx.pcmreg[0] = init_val;
|
|
|
|
if (ac97->scaps & AC97_SCAP_SURROUND_DAC) {
|
|
|
|
for (idx = 0; idx < 2; idx++)
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_5bit);
|
2005-04-17 06:20:36 +08:00
|
|
|
ac97->spec.ad18xx.pcmreg[1] = init_val;
|
|
|
|
}
|
|
|
|
if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) {
|
|
|
|
for (idx = 0; idx < 2; idx++)
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_5bit);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (idx = 0; idx < 2; idx++)
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_5bit);
|
2005-04-17 06:20:36 +08:00
|
|
|
ac97->spec.ad18xx.pcmreg[2] = init_val;
|
|
|
|
}
|
|
|
|
snd_ac97_write_cache(ac97, AC97_PCM, init_val);
|
|
|
|
} else {
|
2005-07-29 17:41:55 +08:00
|
|
|
if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) {
|
|
|
|
if (ac97->flags & AC97_HAS_NO_PCM_VOL)
|
2006-06-28 00:28:53 +08:00
|
|
|
err = snd_ac97_cmute_new(card,
|
|
|
|
"PCM Playback Switch",
|
|
|
|
AC97_PCM, 0, ac97);
|
2005-07-29 17:41:55 +08:00
|
|
|
else
|
2006-06-28 00:28:53 +08:00
|
|
|
err = snd_ac97_cmix_new(card, "PCM Playback",
|
|
|
|
AC97_PCM, 0, ac97);
|
2005-07-29 17:41:55 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* build Capture controls */
|
|
|
|
if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) {
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) {
|
2006-06-28 00:28:53 +08:00
|
|
|
err = snd_ac97_cmute_new(card, "Capture Switch",
|
|
|
|
AC97_REC_GAIN, 0, ac97);
|
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_rec_gain);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000);
|
|
|
|
snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000);
|
|
|
|
}
|
|
|
|
/* build MIC Capture controls */
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) {
|
|
|
|
for (idx = 0; idx < 2; idx++)
|
2006-08-22 00:44:31 +08:00
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97))) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
2006-08-22 00:44:31 +08:00
|
|
|
set_tlv_db_scale(kctl, db_scale_rec_gain);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_REC_GAIN_MIC, 0x0000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build PCM out path & mute control */
|
|
|
|
if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 15)) {
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_PCM_OUT], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build Simulated Stereo Enhancement control */
|
2011-02-17 07:17:53 +08:00
|
|
|
if (ac97->caps & AC97_BC_SIM_STEREO) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_STEREO_ENHANCEMENT], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build 3D Stereo Enhancement control */
|
|
|
|
if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 13)) {
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_3D], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build Loudness control */
|
2011-02-17 07:17:53 +08:00
|
|
|
if (ac97->caps & AC97_BC_LOUDNESS) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOUDNESS], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build Mono output select control */
|
|
|
|
if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 9)) {
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MONO], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build Mic select control */
|
|
|
|
if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 8)) {
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MIC], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build ADC/DAC loopback control */
|
|
|
|
if (enable_loopback && snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 7)) {
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOOPBACK], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, ~AC97_GP_DRSS_MASK, 0x0000);
|
|
|
|
|
|
|
|
/* build 3D controls */
|
|
|
|
if (ac97->build_ops->build_3d) {
|
|
|
|
ac97->build_ops->build_3d(ac97);
|
|
|
|
} else {
|
|
|
|
if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) {
|
|
|
|
unsigned short val;
|
|
|
|
val = 0x0707;
|
|
|
|
snd_ac97_write(ac97, AC97_3D_CONTROL, val);
|
|
|
|
val = snd_ac97_read(ac97, AC97_3D_CONTROL);
|
|
|
|
val = val == 0x0606;
|
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
if (val)
|
|
|
|
kctl->private_value = AC97_3D_CONTROL | (9 << 8) | (7 << 16);
|
|
|
|
if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
if (val)
|
|
|
|
kctl->private_value = AC97_3D_CONTROL | (1 << 8) | (7 << 16);
|
|
|
|
snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build S/PDIF controls */
|
2006-08-22 19:33:12 +08:00
|
|
|
|
|
|
|
/* Hack for ASUS P5P800-VM, which does not indicate S/PDIF capability */
|
|
|
|
if (ac97->subsystem_vendor == 0x1043 &&
|
|
|
|
ac97->subsystem_device == 0x810f)
|
|
|
|
ac97->ext_id |= AC97_EI_SPDIF;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((ac97->ext_id & AC97_EI_SPDIF) && !(ac97->scaps & AC97_SCAP_NO_SPDIF)) {
|
|
|
|
if (ac97->build_ops->build_spdif) {
|
|
|
|
if ((err = ac97->build_ops->build_spdif(ac97)) < 0)
|
|
|
|
return err;
|
|
|
|
} else {
|
|
|
|
for (idx = 0; idx < 5; idx++)
|
|
|
|
if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0)
|
|
|
|
return err;
|
|
|
|
if (ac97->build_ops->build_post_spdif) {
|
|
|
|
if ((err = ac97->build_ops->build_post_spdif(ac97)) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/* set default PCM S/PDIF params */
|
|
|
|
/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
|
|
|
|
snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20);
|
|
|
|
ac97->rates[AC97_RATES_SPDIF] = snd_ac97_determine_spdif_rates(ac97);
|
|
|
|
}
|
|
|
|
ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build chip specific controls */
|
|
|
|
if (ac97->build_ops->build_specific)
|
|
|
|
if ((err = ac97->build_ops->build_specific(ac97)) < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (snd_ac97_try_bit(ac97, AC97_POWERDOWN, 15)) {
|
|
|
|
kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97);
|
|
|
|
if (! kctl)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (ac97->scaps & AC97_SCAP_INV_EAPD)
|
|
|
|
set_inv_eapd(ac97, kctl);
|
|
|
|
if ((err = snd_ctl_add(card, kctl)) < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-05-29 21:08:23 +08:00
|
|
|
int err, idx;
|
|
|
|
|
2009-02-05 23:11:31 +08:00
|
|
|
/*
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_dbg(ac97, "AC97_GPIO_CFG = %x\n",
|
2009-02-05 23:11:31 +08:00
|
|
|
snd_ac97_read(ac97,AC97_GPIO_CFG));
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
|
|
|
|
snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH));
|
|
|
|
snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff);
|
|
|
|
snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0);
|
|
|
|
snd_ac97_write(ac97, AC97_MISC_AFE, 0x0);
|
2005-05-29 21:08:23 +08:00
|
|
|
|
|
|
|
/* build modem switches */
|
|
|
|
for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_modem_switches); idx++)
|
2005-09-13 17:21:30 +08:00
|
|
|
if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ac97_controls_modem_switches[idx], ac97))) < 0)
|
2005-05-29 21:08:23 +08:00
|
|
|
return err;
|
|
|
|
|
|
|
|
/* build chip specific controls */
|
|
|
|
if (ac97->build_ops->build_specific)
|
|
|
|
if ((err = ac97->build_ops->build_specific(ac97)) < 0)
|
|
|
|
return err;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_test_rate(struct snd_ac97 *ac97, int reg, int shadow_reg, int rate)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
unsigned int tmp;
|
|
|
|
|
|
|
|
tmp = ((unsigned int)rate * ac97->bus->clock) / 48000;
|
|
|
|
snd_ac97_write_cache(ac97, reg, tmp & 0xffff);
|
|
|
|
if (shadow_reg)
|
|
|
|
snd_ac97_write_cache(ac97, shadow_reg, tmp & 0xffff);
|
|
|
|
val = snd_ac97_read(ac97, reg);
|
|
|
|
return val == (tmp & 0xffff);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static void snd_ac97_determine_rates(struct snd_ac97 *ac97, int reg, int shadow_reg, unsigned int *r_result)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int result = 0;
|
|
|
|
unsigned short saved;
|
|
|
|
|
|
|
|
if (ac97->bus->no_vra) {
|
|
|
|
*r_result = SNDRV_PCM_RATE_48000;
|
|
|
|
if ((ac97->flags & AC97_DOUBLE_RATE) &&
|
|
|
|
reg == AC97_PCM_FRONT_DAC_RATE)
|
|
|
|
*r_result |= SNDRV_PCM_RATE_96000;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
saved = snd_ac97_read(ac97, reg);
|
|
|
|
if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE)
|
|
|
|
snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
|
|
|
|
AC97_EA_DRA, 0);
|
|
|
|
/* test a non-standard rate */
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000))
|
|
|
|
result |= SNDRV_PCM_RATE_CONTINUOUS;
|
|
|
|
/* let's try to obtain standard rates */
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000))
|
|
|
|
result |= SNDRV_PCM_RATE_8000;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025))
|
|
|
|
result |= SNDRV_PCM_RATE_11025;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000))
|
|
|
|
result |= SNDRV_PCM_RATE_16000;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050))
|
|
|
|
result |= SNDRV_PCM_RATE_22050;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000))
|
|
|
|
result |= SNDRV_PCM_RATE_32000;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100))
|
|
|
|
result |= SNDRV_PCM_RATE_44100;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000))
|
|
|
|
result |= SNDRV_PCM_RATE_48000;
|
|
|
|
if ((ac97->flags & AC97_DOUBLE_RATE) &&
|
|
|
|
reg == AC97_PCM_FRONT_DAC_RATE) {
|
|
|
|
/* test standard double rates */
|
|
|
|
snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
|
|
|
|
AC97_EA_DRA, AC97_EA_DRA);
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2))
|
|
|
|
result |= SNDRV_PCM_RATE_64000;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2))
|
|
|
|
result |= SNDRV_PCM_RATE_88200;
|
|
|
|
if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2))
|
|
|
|
result |= SNDRV_PCM_RATE_96000;
|
|
|
|
/* some codecs don't support variable double rates */
|
|
|
|
if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2))
|
|
|
|
result &= ~SNDRV_PCM_RATE_CONTINUOUS;
|
|
|
|
snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
|
|
|
|
AC97_EA_DRA, 0);
|
|
|
|
}
|
|
|
|
/* restore the default value */
|
|
|
|
snd_ac97_write_cache(ac97, reg, saved);
|
|
|
|
if (shadow_reg)
|
|
|
|
snd_ac97_write_cache(ac97, shadow_reg, saved);
|
|
|
|
*r_result = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check AC97_SPDIF register to accept which sample rates */
|
2005-11-17 21:21:36 +08:00
|
|
|
static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int result = 0;
|
|
|
|
int i;
|
|
|
|
static unsigned short ctl_bits[] = {
|
|
|
|
AC97_SC_SPSR_44K, AC97_SC_SPSR_32K, AC97_SC_SPSR_48K
|
|
|
|
};
|
|
|
|
static unsigned int rate_bits[] = {
|
|
|
|
SNDRV_PCM_RATE_44100, SNDRV_PCM_RATE_32000, SNDRV_PCM_RATE_48000
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < (int)ARRAY_SIZE(ctl_bits); i++) {
|
|
|
|
snd_ac97_update_bits(ac97, AC97_SPDIF, AC97_SC_SPSR_MASK, ctl_bits[i]);
|
|
|
|
if ((snd_ac97_read(ac97, AC97_SPDIF) & AC97_SC_SPSR_MASK) == ctl_bits[i])
|
|
|
|
result |= rate_bits[i];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for the codec id table matching with the given id */
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct ac97_codec_id *look_for_codec_id(const struct ac97_codec_id *table,
|
|
|
|
unsigned int id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
const struct ac97_codec_id *pid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (pid = table; pid->id; pid++)
|
|
|
|
if (pid->id == (id & pid->mask))
|
|
|
|
return pid;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, int modem)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
const struct ac97_codec_id *pid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sprintf(name, "0x%x %c%c%c", id,
|
|
|
|
printable(id >> 24),
|
|
|
|
printable(id >> 16),
|
|
|
|
printable(id >> 8));
|
|
|
|
pid = look_for_codec_id(snd_ac97_codec_id_vendors, id);
|
|
|
|
if (! pid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strcpy(name, pid->name);
|
|
|
|
if (ac97 && pid->patch) {
|
|
|
|
if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
|
|
|
|
(! modem && ! (pid->flags & AC97_MODEM_PATCH)))
|
|
|
|
pid->patch(ac97);
|
|
|
|
}
|
|
|
|
|
|
|
|
pid = look_for_codec_id(snd_ac97_codec_ids, id);
|
|
|
|
if (pid) {
|
|
|
|
strcat(name, " ");
|
|
|
|
strcat(name, pid->name);
|
|
|
|
if (pid->mask != 0xffffffff)
|
|
|
|
sprintf(name + strlen(name), " rev %d", id & ~pid->mask);
|
|
|
|
if (ac97 && pid->patch) {
|
|
|
|
if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
|
|
|
|
(! modem && ! (pid->flags & AC97_MODEM_PATCH)))
|
|
|
|
pid->patch(ac97);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sprintf(name + strlen(name), " id %x", id & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_ac97_get_short_name - retrieve codec name
|
|
|
|
* @ac97: the codec instance
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: The short identifying name of the codec.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
const char *snd_ac97_get_short_name(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
const struct ac97_codec_id *pid;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (pid = snd_ac97_codec_ids; pid->id; pid++)
|
|
|
|
if (pid->id == (ac97->id & pid->mask))
|
|
|
|
return pid->name;
|
|
|
|
return "unknown codec";
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_get_short_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* wait for a while until registers are accessible after RESET
|
|
|
|
* return 0 if ok, negative not ready
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
static int ac97_reset_wait(struct snd_ac97 *ac97, int timeout, int with_modem)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long end_time;
|
|
|
|
unsigned short val;
|
|
|
|
|
|
|
|
end_time = jiffies + timeout;
|
|
|
|
do {
|
|
|
|
|
|
|
|
/* use preliminary reads to settle the communication */
|
|
|
|
snd_ac97_read(ac97, AC97_RESET);
|
|
|
|
snd_ac97_read(ac97, AC97_VENDOR_ID1);
|
|
|
|
snd_ac97_read(ac97, AC97_VENDOR_ID2);
|
|
|
|
/* modem? */
|
|
|
|
if (with_modem) {
|
|
|
|
val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
|
|
|
|
if (val != 0xffff && (val & 1) != 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) {
|
|
|
|
/* probably only Xbox issue - all registers are read as zero */
|
|
|
|
val = snd_ac97_read(ac97, AC97_VENDOR_ID1);
|
|
|
|
if (val != 0 && val != 0xffff)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* because the PCM or MASTER volume registers can be modified,
|
|
|
|
* the REC_GAIN register is used for tests
|
|
|
|
*/
|
|
|
|
/* test if we can write to the record gain volume register */
|
|
|
|
snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05);
|
|
|
|
if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-24 21:02:37 +08:00
|
|
|
schedule_timeout_uninterruptible(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (time_after_eq(end_time, jiffies));
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_ac97_bus - create an AC97 bus component
|
|
|
|
* @card: the card instance
|
|
|
|
* @num: the bus number
|
|
|
|
* @ops: the bus callbacks table
|
|
|
|
* @private_data: private data pointer for the new instance
|
|
|
|
* @rbus: the pointer to store the new AC97 bus instance.
|
|
|
|
*
|
2005-11-17 21:21:36 +08:00
|
|
|
* Creates an AC97 bus component. An struct snd_ac97_bus instance is newly
|
2005-04-17 06:20:36 +08:00
|
|
|
* allocated and initialized.
|
|
|
|
*
|
|
|
|
* The ops table must include valid callbacks (at least read and
|
|
|
|
* write). The other callbacks, wait and reset, are not mandatory.
|
|
|
|
*
|
|
|
|
* The clock is set to 48000. If another clock is needed, set
|
2016-11-15 05:19:41 +08:00
|
|
|
* ``(*rbus)->clock`` manually.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* The AC97 bus instance is registered as a low-level device, so you don't
|
|
|
|
* have to release it manually.
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: Zero if successful, or a negative error code on failure.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
|
|
|
|
void *private_data, struct snd_ac97_bus **rbus)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97_bus *bus;
|
|
|
|
static struct snd_device_ops dev_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dev_free = snd_ac97_bus_dev_free,
|
|
|
|
};
|
|
|
|
|
2008-08-08 23:12:14 +08:00
|
|
|
if (snd_BUG_ON(!card))
|
|
|
|
return -EINVAL;
|
[ALSA] Replace with kzalloc() - pci stuff
AD1889 driver,ATIIXP driver,ATIIXP-modem driver,AZT3328 driver
BT87x driver,CMIPCI driver,CS4281 driver,ENS1370/1+ driver
ES1938 driver,ES1968 driver,FM801 driver,Intel8x0 driver
Intel8x0-modem driver,Maestro3 driver,SonicVibes driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,AK4531 codec,au88x0 driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,HDA Codec driver
HDA generic driver,HDA Intel driver,ICE1712 driver,ICE1724 driver
KORG1212 driver,MIXART driver,NM256 driver,Trident driver,YMFPCI driver
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:21:46 +08:00
|
|
|
bus = kzalloc(sizeof(*bus), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (bus == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
bus->card = card;
|
|
|
|
bus->num = num;
|
|
|
|
bus->ops = ops;
|
|
|
|
bus->private_data = private_data;
|
|
|
|
bus->clock = 48000;
|
|
|
|
spin_lock_init(&bus->bus_lock);
|
|
|
|
snd_ac97_bus_proc_init(bus);
|
|
|
|
if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &dev_ops)) < 0) {
|
|
|
|
snd_ac97_bus_free(bus);
|
|
|
|
return err;
|
|
|
|
}
|
2008-08-08 23:12:14 +08:00
|
|
|
if (rbus)
|
|
|
|
*rbus = bus;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_bus);
|
|
|
|
|
2005-07-29 22:13:36 +08:00
|
|
|
/* stop no dev release warning */
|
|
|
|
static void ac97_device_release(struct device * dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register ac97 codec to bus */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int snd_ac97_dev_register(struct snd_device *device)
|
2005-07-29 22:13:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = device->device_data;
|
2005-07-29 22:13:36 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
ac97->dev.bus = &ac97_bus_type;
|
|
|
|
ac97->dev.parent = ac97->bus->card->dev;
|
|
|
|
ac97->dev.release = ac97_device_release;
|
2008-10-30 09:27:20 +08:00
|
|
|
dev_set_name(&ac97->dev, "%d-%d:%s",
|
|
|
|
ac97->bus->card->number, ac97->num,
|
|
|
|
snd_ac97_get_short_name(ac97));
|
2005-07-29 22:13:36 +08:00
|
|
|
if ((err = device_register(&ac97->dev)) < 0) {
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97, "Can't register ac97 bus\n");
|
2024-06-12 13:13:20 +08:00
|
|
|
put_device(&ac97->dev);
|
2005-07-29 22:13:36 +08:00
|
|
|
ac97->dev.bus = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-23 20:38:23 +08:00
|
|
|
/* disconnect ac97 codec */
|
|
|
|
static int snd_ac97_dev_disconnect(struct snd_device *device)
|
2005-07-29 22:13:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = device->device_data;
|
2005-07-29 22:13:36 +08:00
|
|
|
if (ac97->dev.bus)
|
|
|
|
device_unregister(&ac97->dev);
|
2006-06-23 20:38:23 +08:00
|
|
|
return 0;
|
2005-07-29 22:13:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* build_ops to do nothing */
|
2011-01-15 02:14:47 +08:00
|
|
|
static const struct snd_ac97_build_ops null_build_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-28 00:28:53 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
2006-11-22 22:57:56 +08:00
|
|
|
static void do_update_power(struct work_struct *work)
|
2006-06-28 00:28:53 +08:00
|
|
|
{
|
2006-11-22 22:57:56 +08:00
|
|
|
update_power_regs(
|
|
|
|
container_of(work, struct snd_ac97, power_work.work));
|
2006-06-28 00:28:53 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* snd_ac97_mixer - create an Codec97 component
|
|
|
|
* @bus: the AC97 bus which codec is attached to
|
|
|
|
* @template: the template of ac97, including index, callbacks and
|
|
|
|
* the private data.
|
|
|
|
* @rac97: the pointer to store the new ac97 instance.
|
|
|
|
*
|
2005-11-17 21:21:36 +08:00
|
|
|
* Creates an Codec97 component. An struct snd_ac97 instance is newly
|
2005-04-17 06:20:36 +08:00
|
|
|
* allocated and initialized from the template. The codec
|
|
|
|
* is then initialized by the standard procedure.
|
|
|
|
*
|
|
|
|
* The template must include the codec number (num) and address (addr),
|
|
|
|
* and the private data (private_data).
|
|
|
|
*
|
|
|
|
* The ac97 instance is registered as a low-level device, so you don't
|
|
|
|
* have to release it manually.
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: Zero if successful, or a negative error code on failure.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template, struct snd_ac97 **rac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97;
|
|
|
|
struct snd_card *card;
|
2005-04-17 06:20:36 +08:00
|
|
|
char name[64];
|
|
|
|
unsigned long end_time;
|
|
|
|
unsigned int reg;
|
2005-11-17 21:21:36 +08:00
|
|
|
const struct ac97_codec_id *pid;
|
|
|
|
static struct snd_device_ops ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.dev_free = snd_ac97_dev_free,
|
2005-07-29 22:13:36 +08:00
|
|
|
.dev_register = snd_ac97_dev_register,
|
2006-06-23 20:38:23 +08:00
|
|
|
.dev_disconnect = snd_ac97_dev_disconnect,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2008-08-08 23:12:14 +08:00
|
|
|
if (rac97)
|
|
|
|
*rac97 = NULL;
|
|
|
|
if (snd_BUG_ON(!bus || !template))
|
|
|
|
return -EINVAL;
|
|
|
|
if (snd_BUG_ON(template->num >= 4))
|
|
|
|
return -EINVAL;
|
|
|
|
if (bus->codec[template->num])
|
|
|
|
return -EBUSY;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
card = bus->card;
|
[ALSA] Replace with kzalloc() - pci stuff
AD1889 driver,ATIIXP driver,ATIIXP-modem driver,AZT3328 driver
BT87x driver,CMIPCI driver,CS4281 driver,ENS1370/1+ driver
ES1938 driver,ES1968 driver,FM801 driver,Intel8x0 driver
Intel8x0-modem driver,Maestro3 driver,SonicVibes driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,AK4531 codec,au88x0 driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,HDA Codec driver
HDA generic driver,HDA Intel driver,ICE1712 driver,ICE1724 driver
KORG1212 driver,MIXART driver,NM256 driver,Trident driver,YMFPCI driver
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 20:21:46 +08:00
|
|
|
ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ac97 == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
ac97->private_data = template->private_data;
|
|
|
|
ac97->private_free = template->private_free;
|
|
|
|
ac97->bus = bus;
|
|
|
|
ac97->pci = template->pci;
|
|
|
|
ac97->num = template->num;
|
|
|
|
ac97->addr = template->addr;
|
|
|
|
ac97->scaps = template->scaps;
|
2006-03-15 20:52:54 +08:00
|
|
|
ac97->res_table = template->res_table;
|
2005-04-17 06:20:36 +08:00
|
|
|
bus->codec[ac97->num] = ac97;
|
2006-01-16 23:34:20 +08:00
|
|
|
mutex_init(&ac97->reg_mutex);
|
|
|
|
mutex_init(&ac97->page_mutex);
|
2006-06-28 00:28:53 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
2006-11-22 22:57:56 +08:00
|
|
|
INIT_DELAYED_WORK(&ac97->power_work, do_update_power);
|
2006-06-28 00:28:53 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-12-01 17:49:58 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ac97->pci) {
|
|
|
|
pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor);
|
|
|
|
pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device);
|
|
|
|
}
|
2005-12-01 17:49:58 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
if (bus->ops->reset) {
|
|
|
|
bus->ops->reset(ac97);
|
|
|
|
goto __access_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
|
|
|
|
ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
|
|
|
|
if (ac97->id && ac97->id != (unsigned int)-1) {
|
|
|
|
pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
|
|
|
|
if (pid && (pid->flags & AC97_DEFAULT_POWER_OFF))
|
|
|
|
goto __access_ok;
|
|
|
|
}
|
|
|
|
|
2005-04-08 02:23:58 +08:00
|
|
|
/* reset to defaults */
|
|
|
|
if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
|
|
|
|
snd_ac97_write(ac97, AC97_RESET, 0);
|
|
|
|
if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
|
|
|
|
snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (bus->ops->wait)
|
|
|
|
bus->ops->wait(ac97);
|
|
|
|
else {
|
|
|
|
udelay(50);
|
|
|
|
if (ac97->scaps & AC97_SCAP_SKIP_AUDIO)
|
2007-08-10 22:50:37 +08:00
|
|
|
err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
2007-08-10 22:50:37 +08:00
|
|
|
err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err < 0)
|
2007-08-10 22:50:37 +08:00
|
|
|
err = ac97_reset_wait(ac97,
|
|
|
|
msecs_to_jiffies(500), 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (err < 0) {
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_warn(ac97, "AC'97 %d does not respond - RESET\n",
|
|
|
|
ac97->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* proceed anyway - it's often non-critical */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__access_ok:
|
|
|
|
ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
|
|
|
|
ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
|
|
|
|
if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) &&
|
|
|
|
(ac97->id == 0x00000000 || ac97->id == 0xffffffff)) {
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97,
|
|
|
|
"AC'97 %d access is not valid [0x%x], removing mixer.\n",
|
|
|
|
ac97->num, ac97->id);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
|
|
|
|
if (pid)
|
|
|
|
ac97->flags |= pid->flags;
|
|
|
|
|
|
|
|
/* test for AC'97 */
|
|
|
|
if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) {
|
|
|
|
/* test if we can write to the record gain volume register */
|
|
|
|
snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06);
|
|
|
|
if (((err = snd_ac97_read(ac97, AC97_REC_GAIN)) & 0x7fff) == 0x0a06)
|
|
|
|
ac97->scaps |= AC97_SCAP_AUDIO;
|
|
|
|
}
|
|
|
|
if (ac97->scaps & AC97_SCAP_AUDIO) {
|
|
|
|
ac97->caps = snd_ac97_read(ac97, AC97_RESET);
|
|
|
|
ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
|
|
|
|
if (ac97->ext_id == 0xffff) /* invalid combination */
|
|
|
|
ac97->ext_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test for MC'97 */
|
|
|
|
if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) {
|
|
|
|
ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID);
|
|
|
|
if (ac97->ext_mid == 0xffff) /* invalid combination */
|
|
|
|
ac97->ext_mid = 0;
|
|
|
|
if (ac97->ext_mid & 1)
|
|
|
|
ac97->scaps |= AC97_SCAP_MODEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
|
|
|
|
if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM)))
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97,
|
|
|
|
"AC'97 %d access error (not audio or modem codec)\n",
|
|
|
|
ac97->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bus->ops->reset) // FIXME: always skipping?
|
|
|
|
goto __ready_ok;
|
|
|
|
|
|
|
|
/* FIXME: add powerdown control */
|
|
|
|
if (ac97_is_audio(ac97)) {
|
|
|
|
/* nothing should be in powerdown mode */
|
|
|
|
snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
|
|
|
|
if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
|
|
|
|
snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */
|
|
|
|
udelay(100);
|
|
|
|
snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
|
|
|
|
}
|
|
|
|
/* nothing should be in powerdown mode */
|
|
|
|
snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
|
ALSA: ac97_codec - increase timeout for analog sections to 5 second
I have a Soundblaster 16PCI. For many years, alsa has had a bug where
not all of the card's controls are detected (many alsa versions,
many kernel versions). In particular, Master Playback Volume is
usually not detected, and so I get no sound or extremely faint sound.
The problem has always been inconsistent: sometimes all of the controls
are detected correctly, and sometimes a partial set is detected. It works
correctly about 10% of the time.
Finally, I got around to tracking down the problem. When the driver
fails, it prints the kernel message "AC'97 0 analog subsections not
ready". This message is generated from the function snd_ac97_mixer()
in ac97_codec.c. The message indicates that the card failed to come
back after reset within the time limit. The time limit is
120 milliseconds.
I tried increasing the time limit to 1 second, and found that this
made the driver work about 70% of the time. I tried increasing it
to 5 seconds, and it now seems to work 100% of the time.
I expect that this change would be completely harmless for
existing cards that work, and would only introduce additional
delay for cards that do not work.
ALSA bug#4032.
Signed-off-by: Steve Soule <sts11dbxr@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2009-12-15 02:06:03 +08:00
|
|
|
end_time = jiffies + msecs_to_jiffies(5000);
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
|
|
|
if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
|
|
|
|
goto __ready_ok;
|
2005-10-24 21:02:37 +08:00
|
|
|
schedule_timeout_uninterruptible(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (time_after_eq(end_time, jiffies));
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_warn(ac97,
|
|
|
|
"AC'97 %d analog subsections not ready\n", ac97->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: add powerdown control */
|
|
|
|
if (ac97_is_modem(ac97)) {
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
/* nothing should be in powerdown mode */
|
|
|
|
/* note: it's important to set the rate at first */
|
|
|
|
tmp = AC97_MEA_GPIO;
|
|
|
|
if (ac97->ext_mid & AC97_MEI_LINE1) {
|
2005-04-08 02:22:58 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp |= AC97_MEA_ADC1 | AC97_MEA_DAC1;
|
|
|
|
}
|
|
|
|
if (ac97->ext_mid & AC97_MEI_LINE2) {
|
2005-04-08 02:22:58 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp |= AC97_MEA_ADC2 | AC97_MEA_DAC2;
|
|
|
|
}
|
|
|
|
if (ac97->ext_mid & AC97_MEI_HANDSET) {
|
2005-04-08 02:22:58 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000);
|
2005-04-17 06:20:36 +08:00
|
|
|
tmp |= AC97_MEA_HADC | AC97_MEA_HDAC;
|
|
|
|
}
|
2005-04-08 02:22:58 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(100);
|
|
|
|
/* nothing should be in powerdown mode */
|
2005-04-08 02:22:58 +08:00
|
|
|
snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
|
2007-08-10 22:50:37 +08:00
|
|
|
end_time = jiffies + msecs_to_jiffies(100);
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
|
|
|
if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
|
|
|
|
goto __ready_ok;
|
2005-10-24 21:02:37 +08:00
|
|
|
schedule_timeout_uninterruptible(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
} while (time_after_eq(end_time, jiffies));
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_warn(ac97,
|
|
|
|
"MC'97 %d converters and GPIO not ready (0x%x)\n",
|
|
|
|
ac97->num,
|
|
|
|
snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
__ready_ok:
|
|
|
|
if (ac97_is_audio(ac97))
|
|
|
|
ac97->addr = (ac97->ext_id & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT;
|
|
|
|
else
|
|
|
|
ac97->addr = (ac97->ext_mid & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT;
|
|
|
|
if (ac97->ext_id & 0x01c9) { /* L/R, MIC, SDAC, LDAC VRA support */
|
|
|
|
reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
|
|
|
|
reg |= ac97->ext_id & 0x01c0; /* LDAC/SDAC/CDAC */
|
|
|
|
if (! bus->no_vra)
|
|
|
|
reg |= ac97->ext_id & 0x0009; /* VRA/VRM */
|
|
|
|
snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);
|
|
|
|
}
|
|
|
|
if ((ac97->ext_id & AC97_EI_DRA) && bus->dra) {
|
|
|
|
/* Intel controllers require double rate data to be put in
|
|
|
|
* slots 7+8, so let's hope the codec supports it. */
|
|
|
|
snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
|
|
|
|
if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
|
|
|
|
ac97->flags |= AC97_DOUBLE_RATE;
|
2005-10-28 02:56:35 +08:00
|
|
|
/* restore to slots 10/11 to avoid the confliction with surrounds */
|
|
|
|
snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
|
|
|
|
snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
|
|
|
|
snd_ac97_determine_rates(ac97, AC97_PCM_LR_ADC_RATE, 0, &ac97->rates[AC97_RATES_ADC]);
|
|
|
|
} else {
|
|
|
|
ac97->rates[AC97_RATES_FRONT_DAC] = SNDRV_PCM_RATE_48000;
|
|
|
|
if (ac97->flags & AC97_DOUBLE_RATE)
|
|
|
|
ac97->rates[AC97_RATES_FRONT_DAC] |= SNDRV_PCM_RATE_96000;
|
|
|
|
ac97->rates[AC97_RATES_ADC] = SNDRV_PCM_RATE_48000;
|
|
|
|
}
|
|
|
|
if (ac97->ext_id & AC97_EI_SPDIF) {
|
|
|
|
/* codec specific code (patch) should override these values */
|
|
|
|
ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_32000;
|
|
|
|
}
|
|
|
|
if (ac97->ext_id & AC97_EI_VRM) { /* MIC VRA support */
|
|
|
|
snd_ac97_determine_rates(ac97, AC97_PCM_MIC_ADC_RATE, 0, &ac97->rates[AC97_RATES_MIC_ADC]);
|
|
|
|
} else {
|
|
|
|
ac97->rates[AC97_RATES_MIC_ADC] = SNDRV_PCM_RATE_48000;
|
|
|
|
}
|
|
|
|
if (ac97->ext_id & AC97_EI_SDAC) { /* SDAC support */
|
|
|
|
snd_ac97_determine_rates(ac97, AC97_PCM_SURR_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_SURR_DAC]);
|
|
|
|
ac97->scaps |= AC97_SCAP_SURROUND_DAC;
|
|
|
|
}
|
|
|
|
if (ac97->ext_id & AC97_EI_LDAC) { /* LDAC support */
|
|
|
|
snd_ac97_determine_rates(ac97, AC97_PCM_LFE_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_LFE_DAC]);
|
|
|
|
ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
|
|
|
|
}
|
|
|
|
/* additional initializations */
|
|
|
|
if (bus->ops->init)
|
|
|
|
bus->ops->init(ac97);
|
|
|
|
snd_ac97_get_name(ac97, ac97->id, name, !ac97_is_audio(ac97));
|
|
|
|
snd_ac97_get_name(NULL, ac97->id, name, !ac97_is_audio(ac97)); // ac97->id might be changed in the special setup code
|
|
|
|
if (! ac97->build_ops)
|
|
|
|
ac97->build_ops = &null_build_ops;
|
|
|
|
|
|
|
|
if (ac97_is_audio(ac97)) {
|
|
|
|
char comp[16];
|
|
|
|
if (card->mixername[0] == '\0') {
|
|
|
|
strcpy(card->mixername, name);
|
|
|
|
} else {
|
|
|
|
if (strlen(card->mixername) + 1 + strlen(name) + 1 <= sizeof(card->mixername)) {
|
|
|
|
strcat(card->mixername, ",");
|
|
|
|
strcat(card->mixername, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(comp, "AC97a:%08x", ac97->id);
|
|
|
|
if ((err = snd_component_add(card, comp)) < 0) {
|
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (snd_ac97_mixer_build(ac97) < 0) {
|
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ac97_is_modem(ac97)) {
|
|
|
|
char comp[16];
|
|
|
|
if (card->mixername[0] == '\0') {
|
|
|
|
strcpy(card->mixername, name);
|
|
|
|
} else {
|
|
|
|
if (strlen(card->mixername) + 1 + strlen(name) + 1 <= sizeof(card->mixername)) {
|
|
|
|
strcat(card->mixername, ",");
|
|
|
|
strcat(card->mixername, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(comp, "AC97m:%08x", ac97->id);
|
|
|
|
if ((err = snd_component_add(card, comp)) < 0) {
|
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (snd_ac97_modem_build(card, ac97) < 0) {
|
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
2006-06-28 00:28:53 +08:00
|
|
|
if (ac97_is_audio(ac97))
|
|
|
|
update_power_regs(ac97);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_proc_init(ac97);
|
|
|
|
if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) {
|
|
|
|
snd_ac97_free(ac97);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
*rac97 = ac97;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_mixer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Power down the chip.
|
|
|
|
*
|
|
|
|
* MASTER and HEADPHONE registers are muted but the register cache values
|
|
|
|
* are not changed, so that the values can be restored in snd_ac97_resume().
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
static void snd_ac97_powerdown(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short power;
|
|
|
|
|
|
|
|
if (ac97_is_audio(ac97)) {
|
|
|
|
/* some codecs have stereo mute bits */
|
|
|
|
snd_ac97_write(ac97, AC97_MASTER, 0x9f9f);
|
|
|
|
snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f);
|
|
|
|
}
|
|
|
|
|
2006-06-28 00:28:53 +08:00
|
|
|
/* surround, CLFE, mic powerdown */
|
|
|
|
power = ac97->regs[AC97_EXTENDED_STATUS];
|
|
|
|
if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
|
|
|
|
power |= AC97_EA_PRJ;
|
|
|
|
if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
|
|
|
|
power |= AC97_EA_PRI | AC97_EA_PRK;
|
|
|
|
power |= AC97_EA_PRL;
|
|
|
|
snd_ac97_write(ac97, AC97_EXTENDED_STATUS, power);
|
|
|
|
|
|
|
|
/* powerdown external amplifier */
|
|
|
|
if (ac97->scaps & AC97_SCAP_INV_EAPD)
|
|
|
|
power = ac97->regs[AC97_POWERDOWN] & ~AC97_PD_EAPD;
|
|
|
|
else if (! (ac97->scaps & AC97_SCAP_EAPD_LED))
|
|
|
|
power = ac97->regs[AC97_POWERDOWN] | AC97_PD_EAPD;
|
|
|
|
power |= AC97_PD_PR6; /* Headphone amplifier powerdown */
|
|
|
|
power |= AC97_PD_PR0 | AC97_PD_PR1; /* ADC & DAC powerdown */
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, power);
|
|
|
|
udelay(100);
|
2008-06-27 17:55:20 +08:00
|
|
|
power |= AC97_PD_PR2; /* Analog Mixer powerdown (Vref on) */
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, power);
|
2006-10-25 00:25:29 +08:00
|
|
|
if (ac97_is_power_save_mode(ac97)) {
|
2008-06-27 17:55:20 +08:00
|
|
|
power |= AC97_PD_PR3; /* Analog Mixer powerdown */
|
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, power);
|
2006-06-28 00:28:53 +08:00
|
|
|
udelay(100);
|
|
|
|
/* AC-link powerdown, internal Clk disable */
|
|
|
|
/* FIXME: this may cause click noises on some boards */
|
|
|
|
power |= AC97_PD_PR4 | AC97_PD_PR5;
|
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, power);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-28 00:28:53 +08:00
|
|
|
struct ac97_power_reg {
|
|
|
|
unsigned short reg;
|
|
|
|
unsigned short power_reg;
|
|
|
|
unsigned short mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum { PWIDX_ADC, PWIDX_FRONT, PWIDX_CLFE, PWIDX_SURR, PWIDX_MIC, PWIDX_SIZE };
|
|
|
|
|
|
|
|
static struct ac97_power_reg power_regs[PWIDX_SIZE] = {
|
|
|
|
[PWIDX_ADC] = { AC97_PCM_LR_ADC_RATE, AC97_POWERDOWN, AC97_PD_PR0},
|
|
|
|
[PWIDX_FRONT] = { AC97_PCM_FRONT_DAC_RATE, AC97_POWERDOWN, AC97_PD_PR1},
|
|
|
|
[PWIDX_CLFE] = { AC97_PCM_LFE_DAC_RATE, AC97_EXTENDED_STATUS,
|
|
|
|
AC97_EA_PRI | AC97_EA_PRK},
|
|
|
|
[PWIDX_SURR] = { AC97_PCM_SURR_DAC_RATE, AC97_EXTENDED_STATUS,
|
|
|
|
AC97_EA_PRJ},
|
|
|
|
[PWIDX_MIC] = { AC97_PCM_MIC_ADC_RATE, AC97_EXTENDED_STATUS,
|
|
|
|
AC97_EA_PRL},
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
|
|
|
/**
|
|
|
|
* snd_ac97_update_power - update the powerdown register
|
|
|
|
* @ac97: the codec instance
|
|
|
|
* @reg: the rate register, e.g. AC97_PCM_FRONT_DAC_RATE
|
|
|
|
* @powerup: non-zero when power up the part
|
|
|
|
*
|
|
|
|
* Update the AC97 powerdown register bits of the given part.
|
2013-03-12 05:05:14 +08:00
|
|
|
*
|
|
|
|
* Return: Zero.
|
2006-06-28 00:28:53 +08:00
|
|
|
*/
|
|
|
|
int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (! ac97)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (reg) {
|
|
|
|
/* SPDIF requires DAC power, too */
|
|
|
|
if (reg == AC97_SPDIF)
|
|
|
|
reg = AC97_PCM_FRONT_DAC_RATE;
|
|
|
|
for (i = 0; i < PWIDX_SIZE; i++) {
|
|
|
|
if (power_regs[i].reg == reg) {
|
|
|
|
if (powerup)
|
|
|
|
ac97->power_up |= (1 << i);
|
|
|
|
else
|
|
|
|
ac97->power_up &= ~(1 << i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-25 00:25:29 +08:00
|
|
|
if (ac97_is_power_save_mode(ac97) && !powerup)
|
2006-06-28 00:28:53 +08:00
|
|
|
/* adjust power-down bits after two seconds delay
|
|
|
|
* (for avoiding loud click noises for many (OSS) apps
|
|
|
|
* that open/close frequently)
|
|
|
|
*/
|
2007-08-10 22:50:37 +08:00
|
|
|
schedule_delayed_work(&ac97->power_work,
|
2008-06-08 15:17:27 +08:00
|
|
|
msecs_to_jiffies(power_save * 1000));
|
2006-10-25 00:25:29 +08:00
|
|
|
else {
|
|
|
|
cancel_delayed_work(&ac97->power_work);
|
2006-06-28 00:28:53 +08:00
|
|
|
update_power_regs(ac97);
|
2006-10-25 00:25:29 +08:00
|
|
|
}
|
2006-06-28 00:28:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(snd_ac97_update_power);
|
|
|
|
#endif /* CONFIG_SND_AC97_POWER_SAVE */
|
|
|
|
|
|
|
|
static void update_power_regs(struct snd_ac97 *ac97)
|
|
|
|
{
|
|
|
|
unsigned int power_up, bits;
|
|
|
|
int i;
|
|
|
|
|
2006-10-25 00:25:29 +08:00
|
|
|
power_up = (1 << PWIDX_FRONT) | (1 << PWIDX_ADC);
|
|
|
|
power_up |= (1 << PWIDX_MIC);
|
|
|
|
if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
|
|
|
|
power_up |= (1 << PWIDX_SURR);
|
|
|
|
if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
|
|
|
|
power_up |= (1 << PWIDX_CLFE);
|
2006-06-28 00:28:53 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
2006-10-25 00:25:29 +08:00
|
|
|
if (ac97_is_power_save_mode(ac97))
|
2006-06-28 00:28:53 +08:00
|
|
|
power_up = ac97->power_up;
|
|
|
|
#endif
|
|
|
|
if (power_up) {
|
|
|
|
if (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2) {
|
|
|
|
/* needs power-up analog mix and vref */
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN,
|
|
|
|
AC97_PD_PR3, 0);
|
|
|
|
msleep(1);
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN,
|
|
|
|
AC97_PD_PR2, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < PWIDX_SIZE; i++) {
|
|
|
|
if (power_up & (1 << i))
|
|
|
|
bits = 0;
|
|
|
|
else
|
|
|
|
bits = power_regs[i].mask;
|
|
|
|
snd_ac97_update_bits(ac97, power_regs[i].power_reg,
|
|
|
|
power_regs[i].mask, bits);
|
|
|
|
}
|
|
|
|
if (! power_up) {
|
|
|
|
if (! (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2)) {
|
|
|
|
/* power down analog mix and vref */
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN,
|
|
|
|
AC97_PD_PR2, AC97_PD_PR2);
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN,
|
|
|
|
AC97_PD_PR3, AC97_PD_PR3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
/**
|
|
|
|
* snd_ac97_suspend - General suspend function for AC97 codec
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
*
|
|
|
|
* Suspends the codec, power down the chip.
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
void snd_ac97_suspend(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 23:00:01 +08:00
|
|
|
if (! ac97)
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ac97->build_ops->suspend)
|
|
|
|
ac97->build_ops->suspend(ac97);
|
2007-01-31 21:34:38 +08:00
|
|
|
#ifdef CONFIG_SND_AC97_POWER_SAVE
|
2010-12-12 00:51:26 +08:00
|
|
|
cancel_delayed_work_sync(&ac97->power_work);
|
2007-01-31 21:34:38 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_ac97_powerdown(ac97);
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_ac97_suspend);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* restore ac97 status
|
|
|
|
*/
|
2007-07-30 20:52:41 +08:00
|
|
|
static void snd_ac97_restore_status(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 2; i < 0x7c ; i += 2) {
|
|
|
|
if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
|
|
|
|
continue;
|
|
|
|
/* restore only accessible registers
|
|
|
|
* some chip (e.g. nm256) may hang up when unsupported registers
|
|
|
|
* are accessed..!
|
|
|
|
*/
|
|
|
|
if (test_bit(i, ac97->reg_accessed)) {
|
|
|
|
snd_ac97_write(ac97, i, ac97->regs[i]);
|
|
|
|
snd_ac97_read(ac97, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* restore IEC958 status
|
|
|
|
*/
|
2007-07-30 20:52:41 +08:00
|
|
|
static void snd_ac97_restore_iec958(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (ac97->ext_id & AC97_EI_SPDIF) {
|
|
|
|
if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) {
|
|
|
|
/* reset spdif status */
|
|
|
|
snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
|
|
|
|
snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]);
|
|
|
|
if (ac97->flags & AC97_CS_SPDIF)
|
|
|
|
snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]);
|
|
|
|
else
|
|
|
|
snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]);
|
|
|
|
snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_ac97_resume - General resume function for AC97 codec
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
*
|
|
|
|
* Do the standard resume procedure, power up and restoring the
|
|
|
|
* old register values.
|
|
|
|
*/
|
2005-11-17 21:21:36 +08:00
|
|
|
void snd_ac97_resume(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 16:13:22 +08:00
|
|
|
unsigned long end_time;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-17 23:00:01 +08:00
|
|
|
if (! ac97)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ac97->bus->ops->reset) {
|
|
|
|
ac97->bus->ops->reset(ac97);
|
|
|
|
goto __reset_ready;
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, 0);
|
|
|
|
if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
|
2007-08-29 21:12:46 +08:00
|
|
|
if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
|
|
|
|
snd_ac97_write(ac97, AC97_RESET, 0);
|
|
|
|
else if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
|
|
|
|
snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(100);
|
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, 0);
|
|
|
|
}
|
|
|
|
snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0);
|
|
|
|
|
|
|
|
snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]);
|
|
|
|
if (ac97_is_audio(ac97)) {
|
|
|
|
ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101);
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 16:13:22 +08:00
|
|
|
end_time = jiffies + msecs_to_jiffies(100);
|
|
|
|
do {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
|
|
|
|
break;
|
2005-10-24 21:02:37 +08:00
|
|
|
schedule_timeout_uninterruptible(1);
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 16:13:22 +08:00
|
|
|
} while (time_after_eq(end_time, jiffies));
|
2005-04-17 06:20:36 +08:00
|
|
|
/* FIXME: extra delay */
|
2011-02-17 07:17:53 +08:00
|
|
|
ac97->bus->ops->write(ac97, AC97_MASTER, AC97_MUTE_MASK_MONO);
|
|
|
|
if (snd_ac97_read(ac97, AC97_MASTER) != AC97_MUTE_MASK_MONO)
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 16:13:22 +08:00
|
|
|
msleep(250);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 16:13:22 +08:00
|
|
|
end_time = jiffies + msecs_to_jiffies(100);
|
|
|
|
do {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
|
|
|
|
if (val != 0xffff && (val & 1) != 0)
|
|
|
|
break;
|
2005-10-24 21:02:37 +08:00
|
|
|
schedule_timeout_uninterruptible(1);
|
[ALSA] sound/pci: fix-up sleeping paths
ENS1370/1+ driver,ES1968 driver,Intel8x0 driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,ALI5451 driver,CS46xx driver
MIXART driver,RME HDSP driver,Trident driver,YMFPCI driver
Description: Fix-up sleeping in sound/pci. These changes fall under the
following two categories:
1) Replace schedule_timeout() with msleep() to guarantee the
task delays as expected. This also involved replacing/removing
custom sleep functions.
2) Do not assume jiffies will only increment by one if you
request a 1 jiffy sleep, i.e. use time_after/time_before in
while loops.
Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
2005-07-09 16:13:22 +08:00
|
|
|
} while (time_after_eq(end_time, jiffies));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
__reset_ready:
|
|
|
|
|
|
|
|
if (ac97->bus->ops->init)
|
|
|
|
ac97->bus->ops->init(ac97);
|
|
|
|
|
|
|
|
if (ac97->build_ops->resume)
|
|
|
|
ac97->build_ops->resume(ac97);
|
|
|
|
else {
|
|
|
|
snd_ac97_restore_status(ac97);
|
|
|
|
snd_ac97_restore_iec958(ac97);
|
|
|
|
}
|
|
|
|
}
|
2006-04-28 21:13:39 +08:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(snd_ac97_resume);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hardware tuning
|
|
|
|
*/
|
|
|
|
static void set_ctl_name(char *dst, const char *src, const char *suffix)
|
|
|
|
{
|
|
|
|
if (suffix)
|
|
|
|
sprintf(dst, "%s %s", src, suffix);
|
|
|
|
else
|
|
|
|
strcpy(dst, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the control with the given name and optional suffix */
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name,
|
|
|
|
const char *suffix)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ctl_elem_id id;
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(&id, 0, sizeof(id));
|
|
|
|
set_ctl_name(id.name, name, suffix);
|
|
|
|
id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
|
|
|
|
return snd_ctl_remove_id(ac97->bus->card, &id);
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static struct snd_kcontrol *ctl_find(struct snd_ac97 *ac97, const char *name, const char *suffix)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ctl_elem_id sid;
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(&sid, 0, sizeof(sid));
|
|
|
|
set_ctl_name(sid.name, name, suffix);
|
|
|
|
sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
|
|
|
|
return snd_ctl_find_id(ac97->bus->card, &sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rename the control with the given name and optional suffix */
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src,
|
|
|
|
const char *dst, const char *suffix)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (kctl) {
|
|
|
|
set_ctl_name(kctl->id.name, dst, suffix);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rename both Volume and Switch controls - don't check the return value */
|
2007-02-22 19:58:27 +08:00
|
|
|
static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src,
|
|
|
|
const char *dst)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
snd_ac97_rename_ctl(ac97, src, dst, "Switch");
|
|
|
|
snd_ac97_rename_ctl(ac97, src, dst, "Volume");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* swap controls */
|
2007-02-22 19:58:27 +08:00
|
|
|
static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1,
|
|
|
|
const char *s2, const char *suffix)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *kctl1, *kctl2;
|
2005-04-17 06:20:36 +08:00
|
|
|
kctl1 = ctl_find(ac97, s1, suffix);
|
|
|
|
kctl2 = ctl_find(ac97, s2, suffix);
|
|
|
|
if (kctl1 && kctl2) {
|
|
|
|
set_ctl_name(kctl1->id.name, s2, suffix);
|
|
|
|
set_ctl_name(kctl2->id.name, s1, suffix);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
/* bind hp and master controls instead of using only hp control */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int bind_hp_volsw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err = snd_ac97_put_volsw(kcontrol, ucontrol);
|
|
|
|
if (err > 0) {
|
|
|
|
unsigned long priv_saved = kcontrol->private_value;
|
|
|
|
kcontrol->private_value = (kcontrol->private_value & ~0xff) | AC97_HEADPHONE;
|
|
|
|
snd_ac97_put_volsw(kcontrol, ucontrol);
|
|
|
|
kcontrol->private_value = priv_saved;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ac97 tune: bind Master and Headphone controls */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_hp_only(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
|
|
|
|
struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (! msw || ! mvol)
|
|
|
|
return -ENOENT;
|
|
|
|
msw->put = bind_hp_volsw_put;
|
|
|
|
mvol->put = bind_hp_volsw_put;
|
|
|
|
snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
|
|
|
|
snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* ac97 tune: use Headphone control as master */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_hp_only(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
snd_ac97_remove_ctl(ac97, "Master Playback", "Switch");
|
|
|
|
snd_ac97_remove_ctl(ac97, "Master Playback", "Volume");
|
|
|
|
snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ac97 tune: swap Headphone and Master controls */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_swap_hp(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Line-Out Playback");
|
|
|
|
snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ac97 tune: swap Surround and Master controls */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_swap_surround(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Switch") ||
|
|
|
|
snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Volume"))
|
|
|
|
return -ENOENT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ac97 tune: set up mic sharing for AD codecs */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_ad_sharing(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short scfg;
|
|
|
|
if ((ac97->id & 0xffffff00) != 0x41445300) {
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97, "ac97_quirk AD_SHARING is only for AD codecs\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* Turn on OMS bit to route microphone to back panel */
|
|
|
|
scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
|
|
|
|
snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x0200);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static const struct snd_kcontrol_new snd_ac97_alc_jack_detect =
|
2005-04-17 06:20:36 +08:00
|
|
|
AC97_SINGLE("Jack Detect", AC97_ALC650_CLOCK, 5, 1, 0);
|
|
|
|
|
|
|
|
/* ac97 tune: set up ALC jack-select */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_alc_jack(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if ((ac97->id & 0xffffff00) != 0x414c4700) {
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97,
|
|
|
|
"ac97_quirk ALC_JACK is only for Realtek codecs\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */
|
|
|
|
snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */
|
2005-12-06 03:51:43 +08:00
|
|
|
if (ac97->id == AC97_ID_ALC658D)
|
|
|
|
snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
|
2005-04-17 06:20:36 +08:00
|
|
|
return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ac97 tune: inversed EAPD bit */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_inv_eapd(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *kctl = ctl_find(ac97, "External Amplifier", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (! kctl)
|
|
|
|
return -ENOENT;
|
|
|
|
set_inv_eapd(ac97, kctl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:21:36 +08:00
|
|
|
static int master_mute_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err = snd_ac97_put_volsw(kcontrol, ucontrol);
|
|
|
|
if (err > 0) {
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
2005-04-17 06:20:36 +08:00
|
|
|
int shift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
unsigned short mask;
|
|
|
|
if (shift != rshift)
|
2011-02-17 07:17:53 +08:00
|
|
|
mask = AC97_MUTE_MASK_STEREO;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2011-02-17 07:17:53 +08:00
|
|
|
mask = AC97_MUTE_MASK_MONO;
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN, AC97_PD_EAPD,
|
2005-04-17 06:20:36 +08:00
|
|
|
(ac97->regs[AC97_MASTER] & mask) == mask ?
|
2011-02-17 07:17:53 +08:00
|
|
|
AC97_PD_EAPD : 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ac97 tune: EAPD controls mute LED bound with the master mute */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int tune_mute_led(struct snd_ac97 *ac97)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:21:36 +08:00
|
|
|
struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (! msw)
|
|
|
|
return -ENOENT;
|
|
|
|
msw->put = master_mute_sw_put;
|
|
|
|
snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
|
2011-02-17 07:17:53 +08:00
|
|
|
snd_ac97_update_bits(
|
|
|
|
ac97, AC97_POWERDOWN,
|
|
|
|
AC97_PD_EAPD, AC97_PD_EAPD /* mute LED on */
|
|
|
|
);
|
2006-06-28 00:28:53 +08:00
|
|
|
ac97->scaps |= AC97_SCAP_EAPD_LED;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-06 20:59:12 +08:00
|
|
|
static int hp_master_mute_sw_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
int err = bind_hp_volsw_put(kcontrol, ucontrol);
|
|
|
|
if (err > 0) {
|
|
|
|
struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
|
|
|
|
int shift = (kcontrol->private_value >> 8) & 0x0f;
|
|
|
|
int rshift = (kcontrol->private_value >> 12) & 0x0f;
|
|
|
|
unsigned short mask;
|
|
|
|
if (shift != rshift)
|
2011-02-17 07:17:53 +08:00
|
|
|
mask = AC97_MUTE_MASK_STEREO;
|
2005-12-06 20:59:12 +08:00
|
|
|
else
|
2011-02-17 07:17:53 +08:00
|
|
|
mask = AC97_MUTE_MASK_MONO;
|
|
|
|
snd_ac97_update_bits(ac97, AC97_POWERDOWN, AC97_PD_EAPD,
|
2005-12-06 20:59:12 +08:00
|
|
|
(ac97->regs[AC97_MASTER] & mask) == mask ?
|
2011-02-17 07:17:53 +08:00
|
|
|
AC97_PD_EAPD : 0);
|
2005-12-06 20:59:12 +08:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tune_hp_mute_led(struct snd_ac97 *ac97)
|
|
|
|
{
|
|
|
|
struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
|
|
|
|
struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
|
|
|
|
if (! msw || ! mvol)
|
|
|
|
return -ENOENT;
|
|
|
|
msw->put = hp_master_mute_sw_put;
|
|
|
|
mvol->put = bind_hp_volsw_put;
|
|
|
|
snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
|
|
|
|
snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
|
|
|
|
snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
|
2011-02-17 07:17:53 +08:00
|
|
|
snd_ac97_update_bits(
|
|
|
|
ac97, AC97_POWERDOWN,
|
|
|
|
AC97_PD_EAPD, AC97_PD_EAPD /* mute LED on */
|
|
|
|
);
|
2005-12-06 20:59:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct quirk_table {
|
|
|
|
const char *name;
|
2005-11-17 21:21:36 +08:00
|
|
|
int (*func)(struct snd_ac97 *);
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct quirk_table applicable_quirks[] = {
|
|
|
|
{ "none", NULL },
|
|
|
|
{ "hp_only", tune_hp_only },
|
|
|
|
{ "swap_hp", tune_swap_hp },
|
|
|
|
{ "swap_surround", tune_swap_surround },
|
|
|
|
{ "ad_sharing", tune_ad_sharing },
|
|
|
|
{ "alc_jack", tune_alc_jack },
|
|
|
|
{ "inv_eapd", tune_inv_eapd },
|
|
|
|
{ "mute_led", tune_mute_led },
|
2005-12-06 20:59:12 +08:00
|
|
|
{ "hp_mute_led", tune_hp_mute_led },
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* apply the quirk with the given type */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int apply_quirk(struct snd_ac97 *ac97, int type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (type <= 0)
|
|
|
|
return 0;
|
|
|
|
else if (type >= ARRAY_SIZE(applicable_quirks))
|
|
|
|
return -EINVAL;
|
|
|
|
if (applicable_quirks[type].func)
|
|
|
|
return applicable_quirks[type].func(ac97);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply the quirk with the given name */
|
2005-11-17 21:21:36 +08:00
|
|
|
static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct quirk_table *q;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(applicable_quirks); i++) {
|
|
|
|
q = &applicable_quirks[i];
|
|
|
|
if (q->name && ! strcmp(typestr, q->name))
|
|
|
|
return apply_quirk(ac97, i);
|
|
|
|
}
|
|
|
|
/* for compatibility, accept the numbers, too */
|
|
|
|
if (*typestr >= '0' && *typestr <= '9')
|
|
|
|
return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_ac97_tune_hardware - tune up the hardware
|
|
|
|
* @ac97: the ac97 instance
|
|
|
|
* @quirk: quirk list
|
|
|
|
* @override: explicit quirk value (overrides the list if non-NULL)
|
|
|
|
*
|
|
|
|
* Do some workaround for each pci device, such as renaming of the
|
|
|
|
* headphone (true line-out) control as "Master".
|
|
|
|
* The quirk-list must be terminated with a zero-filled entry.
|
|
|
|
*
|
2013-03-12 05:05:14 +08:00
|
|
|
* Return: Zero if successful, or a negative error code on failure.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2015-04-05 04:38:25 +08:00
|
|
|
int snd_ac97_tune_hardware(struct snd_ac97 *ac97,
|
|
|
|
const struct ac97_quirk *quirk, const char *override)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* quirk overriden? */
|
|
|
|
if (override && strcmp(override, "-1") && strcmp(override, "default")) {
|
|
|
|
result = apply_quirk_str(ac97, override);
|
|
|
|
if (result < 0)
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97, "applying quirk type %s failed (%d)\n",
|
|
|
|
override, result);
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-08-12 22:46:17 +08:00
|
|
|
if (! quirk)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-05-30 20:48:16 +08:00
|
|
|
for (; quirk->subvendor; quirk++) {
|
|
|
|
if (quirk->subvendor != ac97->subsystem_vendor)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2005-05-30 20:48:16 +08:00
|
|
|
if ((! quirk->mask && quirk->subdevice == ac97->subsystem_device) ||
|
|
|
|
quirk->subdevice == (quirk->mask & ac97->subsystem_device)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (quirk->codec_id && quirk->codec_id != ac97->id)
|
|
|
|
continue;
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_dbg(ac97, "ac97 quirk for %s (%04x:%04x)\n",
|
|
|
|
quirk->name, ac97->subsystem_vendor,
|
|
|
|
ac97->subsystem_device);
|
2005-04-17 06:20:36 +08:00
|
|
|
result = apply_quirk(ac97, quirk->type);
|
|
|
|
if (result < 0)
|
2014-02-25 22:37:50 +08:00
|
|
|
ac97_err(ac97,
|
|
|
|
"applying quirk type %d for %s failed (%d)\n",
|
|
|
|
quirk->type, quirk->name, result);
|
2005-04-17 06:20:36 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(snd_ac97_tune_hardware);
|