aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_codec.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r--sound/pci/hda/hda_codec.c745
1 files changed, 622 insertions, 123 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index af989f660cca..0e76ac2b2ace 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -30,6 +30,7 @@
30#include <sound/tlv.h> 30#include <sound/tlv.h>
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_beep.h"
33#include <sound/hda_hwdep.h> 34#include <sound/hda_hwdep.h>
34 35
35/* 36/*
@@ -93,6 +94,13 @@ static void hda_keep_power_on(struct hda_codec *codec);
93static inline void hda_keep_power_on(struct hda_codec *codec) {} 94static inline void hda_keep_power_on(struct hda_codec *codec) {}
94#endif 95#endif
95 96
97/**
98 * snd_hda_get_jack_location - Give a location string of the jack
99 * @cfg: pin default config value
100 *
101 * Parse the pin default config value and returns the string of the
102 * jack location, e.g. "Rear", "Front", etc.
103 */
96const char *snd_hda_get_jack_location(u32 cfg) 104const char *snd_hda_get_jack_location(u32 cfg)
97{ 105{
98 static char *bases[7] = { 106 static char *bases[7] = {
@@ -120,6 +128,13 @@ const char *snd_hda_get_jack_location(u32 cfg)
120} 128}
121EXPORT_SYMBOL_HDA(snd_hda_get_jack_location); 129EXPORT_SYMBOL_HDA(snd_hda_get_jack_location);
122 130
131/**
132 * snd_hda_get_jack_connectivity - Give a connectivity string of the jack
133 * @cfg: pin default config value
134 *
135 * Parse the pin default config value and returns the string of the
136 * jack connectivity, i.e. external or internal connection.
137 */
123const char *snd_hda_get_jack_connectivity(u32 cfg) 138const char *snd_hda_get_jack_connectivity(u32 cfg)
124{ 139{
125 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" }; 140 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
@@ -128,6 +143,13 @@ const char *snd_hda_get_jack_connectivity(u32 cfg)
128} 143}
129EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity); 144EXPORT_SYMBOL_HDA(snd_hda_get_jack_connectivity);
130 145
146/**
147 * snd_hda_get_jack_type - Give a type string of the jack
148 * @cfg: pin default config value
149 *
150 * Parse the pin default config value and returns the string of the
151 * jack type, i.e. the purpose of the jack, such as Line-Out or CD.
152 */
131const char *snd_hda_get_jack_type(u32 cfg) 153const char *snd_hda_get_jack_type(u32 cfg)
132{ 154{
133 static char *jack_types[16] = { 155 static char *jack_types[16] = {
@@ -515,6 +537,7 @@ static int snd_hda_bus_dev_register(struct snd_device *device)
515 struct hda_codec *codec; 537 struct hda_codec *codec;
516 list_for_each_entry(codec, &bus->codec_list, list) { 538 list_for_each_entry(codec, &bus->codec_list, list) {
517 snd_hda_hwdep_add_sysfs(codec); 539 snd_hda_hwdep_add_sysfs(codec);
540 snd_hda_hwdep_add_power_sysfs(codec);
518 } 541 }
519 return 0; 542 return 0;
520} 543}
@@ -801,6 +824,9 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
801 struct hda_pincfg *pin; 824 struct hda_pincfg *pin;
802 unsigned int oldcfg; 825 unsigned int oldcfg;
803 826
827 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
828 return -EINVAL;
829
804 oldcfg = snd_hda_codec_get_pincfg(codec, nid); 830 oldcfg = snd_hda_codec_get_pincfg(codec, nid);
805 pin = look_up_pincfg(codec, list, nid); 831 pin = look_up_pincfg(codec, list, nid);
806 if (!pin) { 832 if (!pin) {
@@ -820,6 +846,16 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
820 return 0; 846 return 0;
821} 847}
822 848
849/**
850 * snd_hda_codec_set_pincfg - Override a pin default configuration
851 * @codec: the HDA codec
852 * @nid: NID to set the pin config
853 * @cfg: the pin default config value
854 *
855 * Override a pin default configuration value in the cache.
856 * This value can be read by snd_hda_codec_get_pincfg() in a higher
857 * priority than the real hardware value.
858 */
823int snd_hda_codec_set_pincfg(struct hda_codec *codec, 859int snd_hda_codec_set_pincfg(struct hda_codec *codec,
824 hda_nid_t nid, unsigned int cfg) 860 hda_nid_t nid, unsigned int cfg)
825{ 861{
@@ -827,7 +863,15 @@ int snd_hda_codec_set_pincfg(struct hda_codec *codec,
827} 863}
828EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg); 864EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
829 865
830/* get the current pin config value of the given pin NID */ 866/**
867 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
868 * @codec: the HDA codec
869 * @nid: NID to get the pin config
870 *
871 * Get the current pin config value of the given pin NID.
872 * If the pincfg value is cached or overridden via sysfs or driver,
873 * returns the cached value.
874 */
831unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) 875unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
832{ 876{
833 struct hda_pincfg *pin; 877 struct hda_pincfg *pin;
@@ -858,6 +902,25 @@ static void restore_pincfgs(struct hda_codec *codec)
858 } 902 }
859} 903}
860 904
905/**
906 * snd_hda_shutup_pins - Shut up all pins
907 * @codec: the HDA codec
908 *
909 * Clear all pin controls to shup up before suspend for avoiding click noise.
910 * The controls aren't cached so that they can be resumed properly.
911 */
912void snd_hda_shutup_pins(struct hda_codec *codec)
913{
914 int i;
915 for (i = 0; i < codec->init_pins.used; i++) {
916 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
917 /* use read here for syncing after issuing each verb */
918 snd_hda_codec_read(codec, pin->nid, 0,
919 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
920 }
921}
922EXPORT_SYMBOL_HDA(snd_hda_shutup_pins);
923
861static void init_hda_cache(struct hda_cache_rec *cache, 924static void init_hda_cache(struct hda_cache_rec *cache,
862 unsigned int record_size); 925 unsigned int record_size);
863static void free_hda_cache(struct hda_cache_rec *cache); 926static void free_hda_cache(struct hda_cache_rec *cache);
@@ -890,6 +953,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
890#endif 953#endif
891 list_del(&codec->list); 954 list_del(&codec->list);
892 snd_array_free(&codec->mixers); 955 snd_array_free(&codec->mixers);
956 snd_array_free(&codec->nids);
893 codec->bus->caddr_tbl[codec->addr] = NULL; 957 codec->bus->caddr_tbl[codec->addr] = NULL;
894 if (codec->patch_ops.free) 958 if (codec->patch_ops.free)
895 codec->patch_ops.free(codec); 959 codec->patch_ops.free(codec);
@@ -914,8 +978,9 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
914 * 978 *
915 * Returns 0 if successful, or a negative error code. 979 * Returns 0 if successful, or a negative error code.
916 */ 980 */
917int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr, 981int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus,
918 struct hda_codec **codecp) 982 unsigned int codec_addr,
983 struct hda_codec **codecp)
919{ 984{
920 struct hda_codec *codec; 985 struct hda_codec *codec;
921 char component[31]; 986 char component[31];
@@ -944,7 +1009,8 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
944 mutex_init(&codec->control_mutex); 1009 mutex_init(&codec->control_mutex);
945 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 1010 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
946 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 1011 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
947 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32); 1012 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
1013 snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
948 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 1014 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
949 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 1015 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
950 if (codec->bus->modelname) { 1016 if (codec->bus->modelname) {
@@ -1026,6 +1092,15 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
1026} 1092}
1027EXPORT_SYMBOL_HDA(snd_hda_codec_new); 1093EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1028 1094
1095/**
1096 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1097 * @codec: the HDA codec
1098 *
1099 * Start parsing of the given codec tree and (re-)initialize the whole
1100 * patch instance.
1101 *
1102 * Returns 0 if successful or a negative error code.
1103 */
1029int snd_hda_codec_configure(struct hda_codec *codec) 1104int snd_hda_codec_configure(struct hda_codec *codec)
1030{ 1105{
1031 int err; 1106 int err;
@@ -1036,11 +1111,6 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1036 if (err < 0) 1111 if (err < 0)
1037 return err; 1112 return err;
1038 } 1113 }
1039 /* audio codec should override the mixer name */
1040 if (codec->afg || !*codec->bus->card->mixername)
1041 snprintf(codec->bus->card->mixername,
1042 sizeof(codec->bus->card->mixername),
1043 "%s %s", codec->vendor_name, codec->chip_name);
1044 1114
1045 if (is_generic_config(codec)) { 1115 if (is_generic_config(codec)) {
1046 err = snd_hda_parse_generic_codec(codec); 1116 err = snd_hda_parse_generic_codec(codec);
@@ -1059,6 +1129,11 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1059 patched: 1129 patched:
1060 if (!err && codec->patch_ops.unsol_event) 1130 if (!err && codec->patch_ops.unsol_event)
1061 err = init_unsol_queue(codec->bus); 1131 err = init_unsol_queue(codec->bus);
1132 /* audio codec should override the mixer name */
1133 if (!err && (codec->afg || !*codec->bus->card->mixername))
1134 snprintf(codec->bus->card->mixername,
1135 sizeof(codec->bus->card->mixername),
1136 "%s %s", codec->vendor_name, codec->chip_name);
1062 return err; 1137 return err;
1063} 1138}
1064EXPORT_SYMBOL_HDA(snd_hda_codec_configure); 1139EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
@@ -1088,6 +1163,11 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1088} 1163}
1089EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); 1164EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1090 1165
1166/**
1167 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1168 * @codec: the CODEC to clean up
1169 * @nid: the NID to clean up
1170 */
1091void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 1171void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1092{ 1172{
1093 if (!nid) 1173 if (!nid)
@@ -1107,7 +1187,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
1107 */ 1187 */
1108 1188
1109/* FIXME: more better hash key? */ 1189/* FIXME: more better hash key? */
1110#define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24)) 1190#define HDA_HASH_KEY(nid, dir, idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1111#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24)) 1191#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
1112#define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24)) 1192#define HDA_HASH_PARPCM_KEY(nid) (u32)((nid) + (0x03 << 24))
1113#define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24)) 1193#define HDA_HASH_PARSTR_KEY(nid) (u32)((nid) + (0x04 << 24))
@@ -1163,8 +1243,17 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1163 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1243 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1164} 1244}
1165 1245
1166/* 1246/**
1167 * query AMP capabilities for the given widget and direction 1247 * query_amp_caps - query AMP capabilities
1248 * @codec: the HD-auio codec
1249 * @nid: the NID to query
1250 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1251 *
1252 * Query AMP capabilities for the given widget and direction.
1253 * Returns the obtained capability bits.
1254 *
1255 * When cap bits have been already read, this doesn't read again but
1256 * returns the cached value.
1168 */ 1257 */
1169u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1258u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1170{ 1259{
@@ -1187,6 +1276,19 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1187} 1276}
1188EXPORT_SYMBOL_HDA(query_amp_caps); 1277EXPORT_SYMBOL_HDA(query_amp_caps);
1189 1278
1279/**
1280 * snd_hda_override_amp_caps - Override the AMP capabilities
1281 * @codec: the CODEC to clean up
1282 * @nid: the NID to clean up
1283 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1284 * @caps: the capability bits to set
1285 *
1286 * Override the cached AMP caps bits value by the given one.
1287 * This function is useful if the driver needs to adjust the AMP ranges,
1288 * e.g. limit to 0dB, etc.
1289 *
1290 * Returns zero if successful or a negative error code.
1291 */
1190int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1292int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1191 unsigned int caps) 1293 unsigned int caps)
1192{ 1294{
@@ -1222,6 +1324,17 @@ static unsigned int read_pin_cap(struct hda_codec *codec, hda_nid_t nid)
1222 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 1324 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1223} 1325}
1224 1326
1327/**
1328 * snd_hda_query_pin_caps - Query PIN capabilities
1329 * @codec: the HD-auio codec
1330 * @nid: the NID to query
1331 *
1332 * Query PIN capabilities for the given widget.
1333 * Returns the obtained capability bits.
1334 *
1335 * When cap bits have been already read, this doesn't read again but
1336 * returns the cached value.
1337 */
1225u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1338u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1226{ 1339{
1227 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1340 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
@@ -1229,6 +1342,43 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1229} 1342}
1230EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1343EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1231 1344
1345/**
1346 * snd_hda_pin_sense - execute pin sense measurement
1347 * @codec: the CODEC to sense
1348 * @nid: the pin NID to sense
1349 *
1350 * Execute necessary pin sense measurement and return its Presence Detect,
1351 * Impedance, ELD Valid etc. status bits.
1352 */
1353u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1354{
1355 u32 pincap;
1356
1357 if (!codec->no_trigger_sense) {
1358 pincap = snd_hda_query_pin_caps(codec, nid);
1359 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1360 snd_hda_codec_read(codec, nid, 0,
1361 AC_VERB_SET_PIN_SENSE, 0);
1362 }
1363 return snd_hda_codec_read(codec, nid, 0,
1364 AC_VERB_GET_PIN_SENSE, 0);
1365}
1366EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1367
1368/**
1369 * snd_hda_jack_detect - query pin Presence Detect status
1370 * @codec: the CODEC to sense
1371 * @nid: the pin NID to sense
1372 *
1373 * Query and return the pin's Presence Detect status.
1374 */
1375int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1376{
1377 u32 sense = snd_hda_pin_sense(codec, nid);
1378 return !!(sense & AC_PINSENSE_PRESENCE);
1379}
1380EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1381
1232/* 1382/*
1233 * read the current volume to info 1383 * read the current volume to info
1234 * if the cache exists, read the cache value. 1384 * if the cache exists, read the cache value.
@@ -1269,8 +1419,15 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1269 info->vol[ch] = val; 1419 info->vol[ch] = val;
1270} 1420}
1271 1421
1272/* 1422/**
1273 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. 1423 * snd_hda_codec_amp_read - Read AMP value
1424 * @codec: HD-audio codec
1425 * @nid: NID to read the AMP value
1426 * @ch: channel (left=0 or right=1)
1427 * @direction: #HDA_INPUT or #HDA_OUTPUT
1428 * @index: the index value (only for input direction)
1429 *
1430 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1274 */ 1431 */
1275int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 1432int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1276 int direction, int index) 1433 int direction, int index)
@@ -1283,8 +1440,18 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1283} 1440}
1284EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1441EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1285 1442
1286/* 1443/**
1287 * update the AMP value, mask = bit mask to set, val = the value 1444 * snd_hda_codec_amp_update - update the AMP value
1445 * @codec: HD-audio codec
1446 * @nid: NID to read the AMP value
1447 * @ch: channel (left=0 or right=1)
1448 * @direction: #HDA_INPUT or #HDA_OUTPUT
1449 * @idx: the index value (only for input direction)
1450 * @mask: bit mask to set
1451 * @val: the bits value to set
1452 *
1453 * Update the AMP value with a bit mask.
1454 * Returns 0 if the value is unchanged, 1 if changed.
1288 */ 1455 */
1289int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1456int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1290 int direction, int idx, int mask, int val) 1457 int direction, int idx, int mask, int val)
@@ -1303,8 +1470,17 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1303} 1470}
1304EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); 1471EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1305 1472
1306/* 1473/**
1307 * update the AMP stereo with the same mask and value 1474 * snd_hda_codec_amp_stereo - update the AMP stereo values
1475 * @codec: HD-audio codec
1476 * @nid: NID to read the AMP value
1477 * @direction: #HDA_INPUT or #HDA_OUTPUT
1478 * @idx: the index value (only for input direction)
1479 * @mask: bit mask to set
1480 * @val: the bits value to set
1481 *
1482 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1483 * stereo widget with the same mask and value.
1308 */ 1484 */
1309int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 1485int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1310 int direction, int idx, int mask, int val) 1486 int direction, int idx, int mask, int val)
@@ -1318,7 +1494,12 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1318EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); 1494EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1319 1495
1320#ifdef SND_HDA_NEEDS_RESUME 1496#ifdef SND_HDA_NEEDS_RESUME
1321/* resume the all amp commands from the cache */ 1497/**
1498 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1499 * @codec: HD-audio codec
1500 *
1501 * Resume the all amp commands from the cache.
1502 */
1322void snd_hda_codec_resume_amp(struct hda_codec *codec) 1503void snd_hda_codec_resume_amp(struct hda_codec *codec)
1323{ 1504{
1324 struct hda_amp_info *buffer = codec->amp_cache.buf.list; 1505 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
@@ -1344,7 +1525,12 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
1344EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); 1525EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1345#endif /* SND_HDA_NEEDS_RESUME */ 1526#endif /* SND_HDA_NEEDS_RESUME */
1346 1527
1347/* volume */ 1528/**
1529 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1530 *
1531 * The control element is supposed to have the private_value field
1532 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1533 */
1348int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 1534int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_info *uinfo) 1535 struct snd_ctl_elem_info *uinfo)
1350{ 1536{
@@ -1400,6 +1586,12 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1400 HDA_AMP_VOLMASK, val); 1586 HDA_AMP_VOLMASK, val);
1401} 1587}
1402 1588
1589/**
1590 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1591 *
1592 * The control element is supposed to have the private_value field
1593 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1594 */
1403int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1595int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1404 struct snd_ctl_elem_value *ucontrol) 1596 struct snd_ctl_elem_value *ucontrol)
1405{ 1597{
@@ -1419,6 +1611,12 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1419} 1611}
1420EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); 1612EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1421 1613
1614/**
1615 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1616 *
1617 * The control element is supposed to have the private_value field
1618 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1619 */
1422int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1620int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol) 1621 struct snd_ctl_elem_value *ucontrol)
1424{ 1622{
@@ -1443,6 +1641,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1443} 1641}
1444EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put); 1642EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1445 1643
1644/**
1645 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1646 *
1647 * The control element is supposed to have the private_value field
1648 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1649 */
1446int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1650int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1447 unsigned int size, unsigned int __user *_tlv) 1651 unsigned int size, unsigned int __user *_tlv)
1448{ 1652{
@@ -1472,8 +1676,16 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1472} 1676}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv); 1677EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1474 1678
1475/* 1679/**
1476 * set (static) TLV for virtual master volume; recalculated as max 0dB 1680 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1681 * @codec: HD-audio codec
1682 * @nid: NID of a reference widget
1683 * @dir: #HDA_INPUT or #HDA_OUTPUT
1684 * @tlv: TLV data to be stored, at least 4 elements
1685 *
1686 * Set (static) TLV data for a virtual master volume using the AMP caps
1687 * obtained from the reference NID.
1688 * The volume range is recalculated as if the max volume is 0dB.
1477 */ 1689 */
1478void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 1690void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1479 unsigned int *tlv) 1691 unsigned int *tlv)
@@ -1507,6 +1719,13 @@ _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1507 return snd_ctl_find_id(codec->bus->card, &id); 1719 return snd_ctl_find_id(codec->bus->card, &id);
1508} 1720}
1509 1721
1722/**
1723 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1724 * @codec: HD-audio codec
1725 * @name: ctl id name string
1726 *
1727 * Get the control element with the given id string and IFACE_MIXER.
1728 */
1510struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1729struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1511 const char *name) 1730 const char *name)
1512{ 1731{
@@ -1514,31 +1733,97 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1514} 1733}
1515EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); 1734EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1516 1735
1517/* Add a control element and assign to the codec */ 1736/**
1518int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl) 1737 * snd_hda_ctl_add - Add a control element and assign to the codec
1738 * @codec: HD-audio codec
1739 * @nid: corresponding NID (optional)
1740 * @kctl: the control element to assign
1741 *
1742 * Add the given control element to an array inside the codec instance.
1743 * All control elements belonging to a codec are supposed to be added
1744 * by this function so that a proper clean-up works at the free or
1745 * reconfiguration time.
1746 *
1747 * If non-zero @nid is passed, the NID is assigned to the control element.
1748 * The assignment is shown in the codec proc file.
1749 *
1750 * snd_hda_ctl_add() checks the control subdev id field whether
1751 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1752 * bits value is taken as the NID to assign. The #HDA_NID_ITEM_AMP bit
1753 * specifies if kctl->private_value is a HDA amplifier value.
1754 */
1755int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1756 struct snd_kcontrol *kctl)
1519{ 1757{
1520 int err; 1758 int err;
1521 struct snd_kcontrol **knewp; 1759 unsigned short flags = 0;
1760 struct hda_nid_item *item;
1522 1761
1762 if (kctl->id.subdevice & HDA_SUBDEV_AMP_FLAG) {
1763 flags |= HDA_NID_ITEM_AMP;
1764 if (nid == 0)
1765 nid = get_amp_nid_(kctl->private_value);
1766 }
1767 if ((kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) != 0 && nid == 0)
1768 nid = kctl->id.subdevice & 0xffff;
1769 if (kctl->id.subdevice & (HDA_SUBDEV_NID_FLAG|HDA_SUBDEV_AMP_FLAG))
1770 kctl->id.subdevice = 0;
1523 err = snd_ctl_add(codec->bus->card, kctl); 1771 err = snd_ctl_add(codec->bus->card, kctl);
1524 if (err < 0) 1772 if (err < 0)
1525 return err; 1773 return err;
1526 knewp = snd_array_new(&codec->mixers); 1774 item = snd_array_new(&codec->mixers);
1527 if (!knewp) 1775 if (!item)
1528 return -ENOMEM; 1776 return -ENOMEM;
1529 *knewp = kctl; 1777 item->kctl = kctl;
1778 item->nid = nid;
1779 item->flags = flags;
1530 return 0; 1780 return 0;
1531} 1781}
1532EXPORT_SYMBOL_HDA(snd_hda_ctl_add); 1782EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1533 1783
1534/* Clear all controls assigned to the given codec */ 1784/**
1785 * snd_hda_add_nid - Assign a NID to a control element
1786 * @codec: HD-audio codec
1787 * @nid: corresponding NID (optional)
1788 * @kctl: the control element to assign
1789 * @index: index to kctl
1790 *
1791 * Add the given control element to an array inside the codec instance.
1792 * This function is used when #snd_hda_ctl_add cannot be used for 1:1
1793 * NID:KCTL mapping - for example "Capture Source" selector.
1794 */
1795int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
1796 unsigned int index, hda_nid_t nid)
1797{
1798 struct hda_nid_item *item;
1799
1800 if (nid > 0) {
1801 item = snd_array_new(&codec->nids);
1802 if (!item)
1803 return -ENOMEM;
1804 item->kctl = kctl;
1805 item->index = index;
1806 item->nid = nid;
1807 return 0;
1808 }
1809 printk(KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n",
1810 kctl->id.name, kctl->id.index, index);
1811 return -EINVAL;
1812}
1813EXPORT_SYMBOL_HDA(snd_hda_add_nid);
1814
1815/**
1816 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1817 * @codec: HD-audio codec
1818 */
1535void snd_hda_ctls_clear(struct hda_codec *codec) 1819void snd_hda_ctls_clear(struct hda_codec *codec)
1536{ 1820{
1537 int i; 1821 int i;
1538 struct snd_kcontrol **kctls = codec->mixers.list; 1822 struct hda_nid_item *items = codec->mixers.list;
1539 for (i = 0; i < codec->mixers.used; i++) 1823 for (i = 0; i < codec->mixers.used; i++)
1540 snd_ctl_remove(codec->bus->card, kctls[i]); 1824 snd_ctl_remove(codec->bus->card, items[i].kctl);
1541 snd_array_free(&codec->mixers); 1825 snd_array_free(&codec->mixers);
1826 snd_array_free(&codec->nids);
1542} 1827}
1543 1828
1544/* pseudo device locking 1829/* pseudo device locking
@@ -1563,6 +1848,16 @@ static void hda_unlock_devices(struct snd_card *card)
1563 spin_unlock(&card->files_lock); 1848 spin_unlock(&card->files_lock);
1564} 1849}
1565 1850
1851/**
1852 * snd_hda_codec_reset - Clear all objects assigned to the codec
1853 * @codec: HD-audio codec
1854 *
1855 * This frees the all PCM and control elements assigned to the codec, and
1856 * clears the caches and restores the pin default configurations.
1857 *
1858 * When a device is being used, it returns -EBSY. If successfully freed,
1859 * returns zero.
1860 */
1566int snd_hda_codec_reset(struct hda_codec *codec) 1861int snd_hda_codec_reset(struct hda_codec *codec)
1567{ 1862{
1568 struct snd_card *card = codec->bus->card; 1863 struct snd_card *card = codec->bus->card;
@@ -1626,7 +1921,22 @@ int snd_hda_codec_reset(struct hda_codec *codec)
1626 return 0; 1921 return 0;
1627} 1922}
1628 1923
1629/* create a virtual master control and add slaves */ 1924/**
1925 * snd_hda_add_vmaster - create a virtual master control and add slaves
1926 * @codec: HD-audio codec
1927 * @name: vmaster control name
1928 * @tlv: TLV data (optional)
1929 * @slaves: slave control names (optional)
1930 *
1931 * Create a virtual master control with the given name. The TLV data
1932 * must be either NULL or a valid data.
1933 *
1934 * @slaves is a NULL-terminated array of strings, each of which is a
1935 * slave control name. All controls with these names are assigned to
1936 * the new virtual master control.
1937 *
1938 * This function returns zero if successful or a negative error code.
1939 */
1630int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1940int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1631 unsigned int *tlv, const char **slaves) 1941 unsigned int *tlv, const char **slaves)
1632{ 1942{
@@ -1643,10 +1953,10 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1643 kctl = snd_ctl_make_virtual_master(name, tlv); 1953 kctl = snd_ctl_make_virtual_master(name, tlv);
1644 if (!kctl) 1954 if (!kctl)
1645 return -ENOMEM; 1955 return -ENOMEM;
1646 err = snd_hda_ctl_add(codec, kctl); 1956 err = snd_hda_ctl_add(codec, 0, kctl);
1647 if (err < 0) 1957 if (err < 0)
1648 return err; 1958 return err;
1649 1959
1650 for (s = slaves; *s; s++) { 1960 for (s = slaves; *s; s++) {
1651 struct snd_kcontrol *sctl; 1961 struct snd_kcontrol *sctl;
1652 int i = 0; 1962 int i = 0;
@@ -1668,7 +1978,12 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1668} 1978}
1669EXPORT_SYMBOL_HDA(snd_hda_add_vmaster); 1979EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1670 1980
1671/* switch */ 1981/**
1982 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
1983 *
1984 * The control element is supposed to have the private_value field
1985 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1986 */
1672int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1987int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_info *uinfo) 1988 struct snd_ctl_elem_info *uinfo)
1674{ 1989{
@@ -1682,6 +1997,12 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1682} 1997}
1683EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info); 1998EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1684 1999
2000/**
2001 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
2002 *
2003 * The control element is supposed to have the private_value field
2004 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2005 */
1685int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 2006int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol) 2007 struct snd_ctl_elem_value *ucontrol)
1687{ 2008{
@@ -1702,6 +2023,12 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1702} 2023}
1703EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get); 2024EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1704 2025
2026/**
2027 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
2028 *
2029 * The control element is supposed to have the private_value field
2030 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
2031 */
1705int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 2032int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol) 2033 struct snd_ctl_elem_value *ucontrol)
1707{ 2034{
@@ -1733,6 +2060,25 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1733} 2060}
1734EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put); 2061EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1735 2062
2063#ifdef CONFIG_SND_HDA_INPUT_BEEP
2064/**
2065 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
2066 *
2067 * This function calls snd_hda_enable_beep_device(), which behaves differently
2068 * depending on beep_mode option.
2069 */
2070int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2071 struct snd_ctl_elem_value *ucontrol)
2072{
2073 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2074 long *valp = ucontrol->value.integer.value;
2075
2076 snd_hda_enable_beep_device(codec, *valp);
2077 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2078}
2079EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2080#endif /* CONFIG_SND_HDA_INPUT_BEEP */
2081
1736/* 2082/*
1737 * bound volume controls 2083 * bound volume controls
1738 * 2084 *
@@ -1742,6 +2088,12 @@ EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1742#define AMP_VAL_IDX_SHIFT 19 2088#define AMP_VAL_IDX_SHIFT 19
1743#define AMP_VAL_IDX_MASK (0x0f<<19) 2089#define AMP_VAL_IDX_MASK (0x0f<<19)
1744 2090
2091/**
2092 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2093 *
2094 * The control element is supposed to have the private_value field
2095 * set up via HDA_BIND_MUTE*() macros.
2096 */
1745int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, 2097int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol) 2098 struct snd_ctl_elem_value *ucontrol)
1747{ 2099{
@@ -1759,6 +2111,12 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1759} 2111}
1760EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get); 2112EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1761 2113
2114/**
2115 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2116 *
2117 * The control element is supposed to have the private_value field
2118 * set up via HDA_BIND_MUTE*() macros.
2119 */
1762int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 2120int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol) 2121 struct snd_ctl_elem_value *ucontrol)
1764{ 2122{
@@ -1783,8 +2141,11 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1783} 2141}
1784EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put); 2142EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1785 2143
1786/* 2144/**
1787 * generic bound volume/swtich controls 2145 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2146 *
2147 * The control element is supposed to have the private_value field
2148 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
1788 */ 2149 */
1789int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, 2150int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_info *uinfo) 2151 struct snd_ctl_elem_info *uinfo)
@@ -1803,6 +2164,12 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1803} 2164}
1804EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info); 2165EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1805 2166
2167/**
2168 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2169 *
2170 * The control element is supposed to have the private_value field
2171 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2172 */
1806int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 2173int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1807 struct snd_ctl_elem_value *ucontrol) 2174 struct snd_ctl_elem_value *ucontrol)
1808{ 2175{
@@ -1820,6 +2187,12 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1820} 2187}
1821EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get); 2188EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1822 2189
2190/**
2191 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2192 *
2193 * The control element is supposed to have the private_value field
2194 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2195 */
1823int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 2196int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol) 2197 struct snd_ctl_elem_value *ucontrol)
1825{ 2198{
@@ -1843,6 +2216,12 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1843} 2216}
1844EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put); 2217EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1845 2218
2219/**
2220 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2221 *
2222 * The control element is supposed to have the private_value field
2223 * set up via HDA_BIND_VOL() macro.
2224 */
1846int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 2225int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1847 unsigned int size, unsigned int __user *tlv) 2226 unsigned int size, unsigned int __user *tlv)
1848{ 2227{
@@ -2064,27 +2443,27 @@ static struct snd_kcontrol_new dig_mixes[] = {
2064 { 2443 {
2065 .access = SNDRV_CTL_ELEM_ACCESS_READ, 2444 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2066 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2445 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2067 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), 2446 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
2068 .info = snd_hda_spdif_mask_info, 2447 .info = snd_hda_spdif_mask_info,
2069 .get = snd_hda_spdif_cmask_get, 2448 .get = snd_hda_spdif_cmask_get,
2070 }, 2449 },
2071 { 2450 {
2072 .access = SNDRV_CTL_ELEM_ACCESS_READ, 2451 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2073 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2452 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2074 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), 2453 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
2075 .info = snd_hda_spdif_mask_info, 2454 .info = snd_hda_spdif_mask_info,
2076 .get = snd_hda_spdif_pmask_get, 2455 .get = snd_hda_spdif_pmask_get,
2077 }, 2456 },
2078 { 2457 {
2079 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2458 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2080 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), 2459 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
2081 .info = snd_hda_spdif_mask_info, 2460 .info = snd_hda_spdif_mask_info,
2082 .get = snd_hda_spdif_default_get, 2461 .get = snd_hda_spdif_default_get,
2083 .put = snd_hda_spdif_default_put, 2462 .put = snd_hda_spdif_default_put,
2084 }, 2463 },
2085 { 2464 {
2086 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2465 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2087 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 2466 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
2088 .info = snd_hda_spdif_out_switch_info, 2467 .info = snd_hda_spdif_out_switch_info,
2089 .get = snd_hda_spdif_out_switch_get, 2468 .get = snd_hda_spdif_out_switch_get,
2090 .put = snd_hda_spdif_out_switch_put, 2469 .put = snd_hda_spdif_out_switch_put,
@@ -2126,7 +2505,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2126 return -ENOMEM; 2505 return -ENOMEM;
2127 kctl->id.index = idx; 2506 kctl->id.index = idx;
2128 kctl->private_value = nid; 2507 kctl->private_value = nid;
2129 err = snd_hda_ctl_add(codec, kctl); 2508 err = snd_hda_ctl_add(codec, nid, kctl);
2130 if (err < 0) 2509 if (err < 0)
2131 return err; 2510 return err;
2132 } 2511 }
@@ -2165,14 +2544,19 @@ static struct snd_kcontrol_new spdif_share_sw = {
2165 .put = spdif_share_sw_put, 2544 .put = spdif_share_sw_put,
2166}; 2545};
2167 2546
2547/**
2548 * snd_hda_create_spdif_share_sw - create Default PCM switch
2549 * @codec: the HDA codec
2550 * @mout: multi-out instance
2551 */
2168int snd_hda_create_spdif_share_sw(struct hda_codec *codec, 2552int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2169 struct hda_multi_out *mout) 2553 struct hda_multi_out *mout)
2170{ 2554{
2171 if (!mout->dig_out_nid) 2555 if (!mout->dig_out_nid)
2172 return 0; 2556 return 0;
2173 /* ATTENTION: here mout is passed as private_data, instead of codec */ 2557 /* ATTENTION: here mout is passed as private_data, instead of codec */
2174 return snd_hda_ctl_add(codec, 2558 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2175 snd_ctl_new1(&spdif_share_sw, mout)); 2559 snd_ctl_new1(&spdif_share_sw, mout));
2176} 2560}
2177EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw); 2561EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2178 2562
@@ -2230,7 +2614,7 @@ static int snd_hda_spdif_in_status_get(struct snd_kcontrol *kcontrol,
2230static struct snd_kcontrol_new dig_in_ctls[] = { 2614static struct snd_kcontrol_new dig_in_ctls[] = {
2231 { 2615 {
2232 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2616 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2233 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 2617 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
2234 .info = snd_hda_spdif_in_switch_info, 2618 .info = snd_hda_spdif_in_switch_info,
2235 .get = snd_hda_spdif_in_switch_get, 2619 .get = snd_hda_spdif_in_switch_get,
2236 .put = snd_hda_spdif_in_switch_put, 2620 .put = snd_hda_spdif_in_switch_put,
@@ -2238,7 +2622,7 @@ static struct snd_kcontrol_new dig_in_ctls[] = {
2238 { 2622 {
2239 .access = SNDRV_CTL_ELEM_ACCESS_READ, 2623 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2240 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2241 .name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT), 2625 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
2242 .info = snd_hda_spdif_mask_info, 2626 .info = snd_hda_spdif_mask_info,
2243 .get = snd_hda_spdif_in_status_get, 2627 .get = snd_hda_spdif_in_status_get,
2244 }, 2628 },
@@ -2276,7 +2660,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2276 if (!kctl) 2660 if (!kctl)
2277 return -ENOMEM; 2661 return -ENOMEM;
2278 kctl->private_value = nid; 2662 kctl->private_value = nid;
2279 err = snd_hda_ctl_add(codec, kctl); 2663 err = snd_hda_ctl_add(codec, nid, kctl);
2280 if (err < 0) 2664 if (err < 0)
2281 return err; 2665 return err;
2282 } 2666 }
@@ -2332,7 +2716,12 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2332} 2716}
2333EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); 2717EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2334 2718
2335/* resume the all commands from the cache */ 2719/**
2720 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2721 * @codec: HD-audio codec
2722 *
2723 * Execute all verbs recorded in the command caches to resume.
2724 */
2336void snd_hda_codec_resume_cache(struct hda_codec *codec) 2725void snd_hda_codec_resume_cache(struct hda_codec *codec)
2337{ 2726{
2338 struct hda_cache_head *buffer = codec->cmd_cache.buf.list; 2727 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
@@ -2382,7 +2771,8 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2382 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 2771 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
2383 power_state); 2772 power_state);
2384 /* partial workaround for "azx_get_response timeout" */ 2773 /* partial workaround for "azx_get_response timeout" */
2385 if (power_state == AC_PWRST_D0) 2774 if (power_state == AC_PWRST_D0 &&
2775 (codec->vendor_id & 0xffff0000) == 0x14f10000)
2386 msleep(10); 2776 msleep(10);
2387 2777
2388 nid = codec->start_nid; 2778 nid = codec->start_nid;
@@ -2416,7 +2806,6 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2416 if (power_state == AC_PWRST_D0) { 2806 if (power_state == AC_PWRST_D0) {
2417 unsigned long end_time; 2807 unsigned long end_time;
2418 int state; 2808 int state;
2419 msleep(10);
2420 /* wait until the codec reachs to D0 */ 2809 /* wait until the codec reachs to D0 */
2421 end_time = jiffies + msecs_to_jiffies(500); 2810 end_time = jiffies + msecs_to_jiffies(500);
2422 do { 2811 do {
@@ -2452,9 +2841,11 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
2452 codec->afg ? codec->afg : codec->mfg, 2841 codec->afg ? codec->afg : codec->mfg,
2453 AC_PWRST_D3); 2842 AC_PWRST_D3);
2454#ifdef CONFIG_SND_HDA_POWER_SAVE 2843#ifdef CONFIG_SND_HDA_POWER_SAVE
2844 snd_hda_update_power_acct(codec);
2455 cancel_delayed_work(&codec->power_work); 2845 cancel_delayed_work(&codec->power_work);
2456 codec->power_on = 0; 2846 codec->power_on = 0;
2457 codec->power_transition = 0; 2847 codec->power_transition = 0;
2848 codec->power_jiffies = jiffies;
2458#endif 2849#endif
2459} 2850}
2460 2851
@@ -2495,8 +2886,8 @@ int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
2495 list_for_each_entry(codec, &bus->codec_list, list) { 2886 list_for_each_entry(codec, &bus->codec_list, list) {
2496 int err = snd_hda_codec_build_controls(codec); 2887 int err = snd_hda_codec_build_controls(codec);
2497 if (err < 0) { 2888 if (err < 0) {
2498 printk(KERN_ERR "hda_codec: cannot build controls" 2889 printk(KERN_ERR "hda_codec: cannot build controls "
2499 "for #%d (error %d)\n", codec->addr, err); 2890 "for #%d (error %d)\n", codec->addr, err);
2500 err = snd_hda_codec_reset(codec); 2891 err = snd_hda_codec_reset(codec);
2501 if (err < 0) { 2892 if (err < 0) {
2502 printk(KERN_ERR 2893 printk(KERN_ERR
@@ -2592,8 +2983,12 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
2592 val |= channels - 1; 2983 val |= channels - 1;
2593 2984
2594 switch (snd_pcm_format_width(format)) { 2985 switch (snd_pcm_format_width(format)) {
2595 case 8: val |= 0x00; break; 2986 case 8:
2596 case 16: val |= 0x10; break; 2987 val |= 0x00;
2988 break;
2989 case 16:
2990 val |= 0x10;
2991 break;
2597 case 20: 2992 case 20:
2598 case 24: 2993 case 24:
2599 case 32: 2994 case 32:
@@ -2756,8 +3151,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2756} 3151}
2757 3152
2758/** 3153/**
2759 * snd_hda_is_supported_format - check whether the given node supports 3154 * snd_hda_is_supported_format - Check the validity of the format
2760 * the format val 3155 * @codec: HD-audio codec
3156 * @nid: NID to check
3157 * @format: the HD-audio format value to check
3158 *
3159 * Check whether the given node supports the format value.
2761 * 3160 *
2762 * Returns 1 if supported, 0 if not. 3161 * Returns 1 if supported, 0 if not.
2763 */ 3162 */
@@ -2877,51 +3276,39 @@ static int set_pcm_default_values(struct hda_codec *codec,
2877 return 0; 3276 return 0;
2878} 3277}
2879 3278
3279/* global */
3280const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3281 "Audio", "SPDIF", "HDMI", "Modem"
3282};
3283
2880/* 3284/*
2881 * get the empty PCM device number to assign 3285 * get the empty PCM device number to assign
3286 *
3287 * note the max device number is limited by HDA_MAX_PCMS, currently 10
2882 */ 3288 */
2883static int get_empty_pcm_device(struct hda_bus *bus, int type) 3289static int get_empty_pcm_device(struct hda_bus *bus, int type)
2884{ 3290{
2885 static const char *dev_name[HDA_PCM_NTYPES] = { 3291 /* audio device indices; not linear to keep compatibility */
2886 "Audio", "SPDIF", "HDMI", "Modem" 3292 static int audio_idx[HDA_PCM_NTYPES][5] = {
3293 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
3294 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
3295 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
3296 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
2887 }; 3297 };
2888 /* starting device index for each PCM type */ 3298 int i;
2889 static int dev_idx[HDA_PCM_NTYPES] = { 3299
2890 [HDA_PCM_TYPE_AUDIO] = 0, 3300 if (type >= HDA_PCM_NTYPES) {
2891 [HDA_PCM_TYPE_SPDIF] = 1,
2892 [HDA_PCM_TYPE_HDMI] = 3,
2893 [HDA_PCM_TYPE_MODEM] = 6
2894 };
2895 /* normal audio device indices; not linear to keep compatibility */
2896 static int audio_idx[4] = { 0, 2, 4, 5 };
2897 int i, dev;
2898
2899 switch (type) {
2900 case HDA_PCM_TYPE_AUDIO:
2901 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
2902 dev = audio_idx[i];
2903 if (!test_bit(dev, bus->pcm_dev_bits))
2904 goto ok;
2905 }
2906 snd_printk(KERN_WARNING "Too many audio devices\n");
2907 return -EAGAIN;
2908 case HDA_PCM_TYPE_SPDIF:
2909 case HDA_PCM_TYPE_HDMI:
2910 case HDA_PCM_TYPE_MODEM:
2911 dev = dev_idx[type];
2912 if (test_bit(dev, bus->pcm_dev_bits)) {
2913 snd_printk(KERN_WARNING "%s already defined\n",
2914 dev_name[type]);
2915 return -EAGAIN;
2916 }
2917 break;
2918 default:
2919 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); 3301 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2920 return -EINVAL; 3302 return -EINVAL;
2921 } 3303 }
2922 ok: 3304
2923 set_bit(dev, bus->pcm_dev_bits); 3305 for (i = 0; audio_idx[type][i] >= 0 ; i++)
2924 return dev; 3306 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3307 return audio_idx[type][i];
3308
3309 snd_printk(KERN_WARNING "Too many %s devices\n",
3310 snd_hda_pcm_type_name[type]);
3311 return -EAGAIN;
2925} 3312}
2926 3313
2927/* 3314/*
@@ -2958,7 +3345,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
2958 err = codec->patch_ops.build_pcms(codec); 3345 err = codec->patch_ops.build_pcms(codec);
2959 if (err < 0) { 3346 if (err < 0) {
2960 printk(KERN_ERR "hda_codec: cannot build PCMs" 3347 printk(KERN_ERR "hda_codec: cannot build PCMs"
2961 "for #%d (error %d)\n", codec->addr, err); 3348 "for #%d (error %d)\n", codec->addr, err);
2962 err = snd_hda_codec_reset(codec); 3349 err = snd_hda_codec_reset(codec);
2963 if (err < 0) { 3350 if (err < 0) {
2964 printk(KERN_ERR 3351 printk(KERN_ERR
@@ -3088,8 +3475,8 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_config);
3088 3475
3089/** 3476/**
3090 * snd_hda_check_board_codec_sid_config - compare the current codec 3477 * snd_hda_check_board_codec_sid_config - compare the current codec
3091 subsystem ID with the 3478 subsystem ID with the
3092 config table 3479 config table
3093 3480
3094 This is important for Gateway notebooks with SB450 HDA Audio 3481 This is important for Gateway notebooks with SB450 HDA Audio
3095 where the vendor ID of the PCI device is: 3482 where the vendor ID of the PCI device is:
@@ -3159,14 +3546,16 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3159 */ 3546 */
3160int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew) 3547int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3161{ 3548{
3162 int err; 3549 int err;
3163 3550
3164 for (; knew->name; knew++) { 3551 for (; knew->name; knew++) {
3165 struct snd_kcontrol *kctl; 3552 struct snd_kcontrol *kctl;
3553 if (knew->iface == -1) /* skip this codec private value */
3554 continue;
3166 kctl = snd_ctl_new1(knew, codec); 3555 kctl = snd_ctl_new1(knew, codec);
3167 if (!kctl) 3556 if (!kctl)
3168 return -ENOMEM; 3557 return -ENOMEM;
3169 err = snd_hda_ctl_add(codec, kctl); 3558 err = snd_hda_ctl_add(codec, 0, kctl);
3170 if (err < 0) { 3559 if (err < 0) {
3171 if (!codec->addr) 3560 if (!codec->addr)
3172 return err; 3561 return err;
@@ -3174,7 +3563,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3174 if (!kctl) 3563 if (!kctl)
3175 return -ENOMEM; 3564 return -ENOMEM;
3176 kctl->id.device = codec->addr; 3565 kctl->id.device = codec->addr;
3177 err = snd_hda_ctl_add(codec, kctl); 3566 err = snd_hda_ctl_add(codec, 0, kctl);
3178 if (err < 0) 3567 if (err < 0)
3179 return err; 3568 return err;
3180 } 3569 }
@@ -3207,8 +3596,27 @@ static void hda_keep_power_on(struct hda_codec *codec)
3207{ 3596{
3208 codec->power_count++; 3597 codec->power_count++;
3209 codec->power_on = 1; 3598 codec->power_on = 1;
3599 codec->power_jiffies = jiffies;
3600}
3601
3602/* update the power on/off account with the current jiffies */
3603void snd_hda_update_power_acct(struct hda_codec *codec)
3604{
3605 unsigned long delta = jiffies - codec->power_jiffies;
3606 if (codec->power_on)
3607 codec->power_on_acct += delta;
3608 else
3609 codec->power_off_acct += delta;
3610 codec->power_jiffies += delta;
3210} 3611}
3211 3612
3613/**
3614 * snd_hda_power_up - Power-up the codec
3615 * @codec: HD-audio codec
3616 *
3617 * Increment the power-up counter and power up the hardware really when
3618 * not turned on yet.
3619 */
3212void snd_hda_power_up(struct hda_codec *codec) 3620void snd_hda_power_up(struct hda_codec *codec)
3213{ 3621{
3214 struct hda_bus *bus = codec->bus; 3622 struct hda_bus *bus = codec->bus;
@@ -3217,7 +3625,9 @@ void snd_hda_power_up(struct hda_codec *codec)
3217 if (codec->power_on || codec->power_transition) 3625 if (codec->power_on || codec->power_transition)
3218 return; 3626 return;
3219 3627
3628 snd_hda_update_power_acct(codec);
3220 codec->power_on = 1; 3629 codec->power_on = 1;
3630 codec->power_jiffies = jiffies;
3221 if (bus->ops.pm_notify) 3631 if (bus->ops.pm_notify)
3222 bus->ops.pm_notify(bus); 3632 bus->ops.pm_notify(bus);
3223 hda_call_codec_resume(codec); 3633 hda_call_codec_resume(codec);
@@ -3229,9 +3639,13 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up);
3229#define power_save(codec) \ 3639#define power_save(codec) \
3230 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3640 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3231 3641
3232#define power_save(codec) \ 3642/**
3233 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3643 * snd_hda_power_down - Power-down the codec
3234 3644 * @codec: HD-audio codec
3645 *
3646 * Decrement the power-up counter and schedules the power-off work if
3647 * the counter rearches to zero.
3648 */
3235void snd_hda_power_down(struct hda_codec *codec) 3649void snd_hda_power_down(struct hda_codec *codec)
3236{ 3650{
3237 --codec->power_count; 3651 --codec->power_count;
@@ -3245,6 +3659,19 @@ void snd_hda_power_down(struct hda_codec *codec)
3245} 3659}
3246EXPORT_SYMBOL_HDA(snd_hda_power_down); 3660EXPORT_SYMBOL_HDA(snd_hda_power_down);
3247 3661
3662/**
3663 * snd_hda_check_amp_list_power - Check the amp list and update the power
3664 * @codec: HD-audio codec
3665 * @check: the object containing an AMP list and the status
3666 * @nid: NID to check / update
3667 *
3668 * Check whether the given NID is in the amp list. If it's in the list,
3669 * check the current AMP status, and update the the power-status according
3670 * to the mute status.
3671 *
3672 * This function is supposed to be set or called from the check_power_status
3673 * patch ops.
3674 */
3248int snd_hda_check_amp_list_power(struct hda_codec *codec, 3675int snd_hda_check_amp_list_power(struct hda_codec *codec,
3249 struct hda_loopback_check *check, 3676 struct hda_loopback_check *check,
3250 hda_nid_t nid) 3677 hda_nid_t nid)
@@ -3286,6 +3713,10 @@ EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3286/* 3713/*
3287 * Channel mode helper 3714 * Channel mode helper
3288 */ 3715 */
3716
3717/**
3718 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3719 */
3289int snd_hda_ch_mode_info(struct hda_codec *codec, 3720int snd_hda_ch_mode_info(struct hda_codec *codec,
3290 struct snd_ctl_elem_info *uinfo, 3721 struct snd_ctl_elem_info *uinfo,
3291 const struct hda_channel_mode *chmode, 3722 const struct hda_channel_mode *chmode,
@@ -3302,6 +3733,9 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
3302} 3733}
3303EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info); 3734EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3304 3735
3736/**
3737 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3738 */
3305int snd_hda_ch_mode_get(struct hda_codec *codec, 3739int snd_hda_ch_mode_get(struct hda_codec *codec,
3306 struct snd_ctl_elem_value *ucontrol, 3740 struct snd_ctl_elem_value *ucontrol,
3307 const struct hda_channel_mode *chmode, 3741 const struct hda_channel_mode *chmode,
@@ -3320,6 +3754,9 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
3320} 3754}
3321EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get); 3755EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3322 3756
3757/**
3758 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3759 */
3323int snd_hda_ch_mode_put(struct hda_codec *codec, 3760int snd_hda_ch_mode_put(struct hda_codec *codec,
3324 struct snd_ctl_elem_value *ucontrol, 3761 struct snd_ctl_elem_value *ucontrol,
3325 const struct hda_channel_mode *chmode, 3762 const struct hda_channel_mode *chmode,
@@ -3344,6 +3781,10 @@ EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3344/* 3781/*
3345 * input MUX helper 3782 * input MUX helper
3346 */ 3783 */
3784
3785/**
3786 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3787 */
3347int snd_hda_input_mux_info(const struct hda_input_mux *imux, 3788int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3348 struct snd_ctl_elem_info *uinfo) 3789 struct snd_ctl_elem_info *uinfo)
3349{ 3790{
@@ -3362,6 +3803,9 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3362} 3803}
3363EXPORT_SYMBOL_HDA(snd_hda_input_mux_info); 3804EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3364 3805
3806/**
3807 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3808 */
3365int snd_hda_input_mux_put(struct hda_codec *codec, 3809int snd_hda_input_mux_put(struct hda_codec *codec,
3366 const struct hda_input_mux *imux, 3810 const struct hda_input_mux *imux,
3367 struct snd_ctl_elem_value *ucontrol, 3811 struct snd_ctl_elem_value *ucontrol,
@@ -3395,7 +3839,7 @@ static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
3395{ 3839{
3396 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ 3840 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
3397 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) 3841 if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
3398 set_dig_out_convert(codec, nid, 3842 set_dig_out_convert(codec, nid,
3399 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff, 3843 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff,
3400 -1); 3844 -1);
3401 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format); 3845 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
@@ -3421,8 +3865,29 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3421 } 3865 }
3422} 3866}
3423 3867
3424/* 3868/**
3425 * open the digital out in the exclusive mode 3869 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3870 * @bus: HD-audio bus
3871 */
3872void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3873{
3874 struct hda_codec *codec;
3875
3876 if (!bus)
3877 return;
3878 list_for_each_entry(codec, &bus->codec_list, list) {
3879#ifdef CONFIG_SND_HDA_POWER_SAVE
3880 if (!codec->power_on)
3881 continue;
3882#endif
3883 if (codec->patch_ops.reboot_notify)
3884 codec->patch_ops.reboot_notify(codec);
3885 }
3886}
3887EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3888
3889/**
3890 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3426 */ 3891 */
3427int snd_hda_multi_out_dig_open(struct hda_codec *codec, 3892int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3428 struct hda_multi_out *mout) 3893 struct hda_multi_out *mout)
@@ -3437,6 +3902,9 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3437} 3902}
3438EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open); 3903EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3439 3904
3905/**
3906 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3907 */
3440int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3908int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3441 struct hda_multi_out *mout, 3909 struct hda_multi_out *mout,
3442 unsigned int stream_tag, 3910 unsigned int stream_tag,
@@ -3450,6 +3918,9 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3450} 3918}
3451EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare); 3919EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3452 3920
3921/**
3922 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3923 */
3453int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, 3924int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3454 struct hda_multi_out *mout) 3925 struct hda_multi_out *mout)
3455{ 3926{
@@ -3460,8 +3931,8 @@ int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3460} 3931}
3461EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup); 3932EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
3462 3933
3463/* 3934/**
3464 * release the digital out 3935 * snd_hda_multi_out_dig_close - release the digital out stream
3465 */ 3936 */
3466int snd_hda_multi_out_dig_close(struct hda_codec *codec, 3937int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3467 struct hda_multi_out *mout) 3938 struct hda_multi_out *mout)
@@ -3473,8 +3944,12 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3473} 3944}
3474EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close); 3945EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
3475 3946
3476/* 3947/**
3477 * set up more restrictions for analog out 3948 * snd_hda_multi_out_analog_open - open analog outputs
3949 *
3950 * Open analog outputs and set up the hw-constraints.
3951 * If the digital outputs can be opened as slave, open the digital
3952 * outputs, too.
3478 */ 3953 */
3479int snd_hda_multi_out_analog_open(struct hda_codec *codec, 3954int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3480 struct hda_multi_out *mout, 3955 struct hda_multi_out *mout,
@@ -3519,9 +3994,11 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3519} 3994}
3520EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open); 3995EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
3521 3996
3522/* 3997/**
3523 * set up the i/o for analog out 3998 * snd_hda_multi_out_analog_prepare - Preapre the analog outputs.
3524 * when the digital out is available, copy the front out to digital out, too. 3999 *
4000 * Set up the i/o for analog out.
4001 * When the digital out is available, copy the front out to digital out, too.
3525 */ 4002 */
3526int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 4003int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3527 struct hda_multi_out *mout, 4004 struct hda_multi_out *mout,
@@ -3578,8 +4055,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3578} 4055}
3579EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); 4056EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
3580 4057
3581/* 4058/**
3582 * clean up the setting for analog out 4059 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3583 */ 4060 */
3584int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, 4061int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3585 struct hda_multi_out *mout) 4062 struct hda_multi_out *mout)
@@ -3621,13 +4098,13 @@ static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
3621/* 4098/*
3622 * Sort an associated group of pins according to their sequence numbers. 4099 * Sort an associated group of pins according to their sequence numbers.
3623 */ 4100 */
3624static void sort_pins_by_sequence(hda_nid_t * pins, short * sequences, 4101static void sort_pins_by_sequence(hda_nid_t *pins, short *sequences,
3625 int num_pins) 4102 int num_pins)
3626{ 4103{
3627 int i, j; 4104 int i, j;
3628 short seq; 4105 short seq;
3629 hda_nid_t nid; 4106 hda_nid_t nid;
3630 4107
3631 for (i = 0; i < num_pins; i++) { 4108 for (i = 0; i < num_pins; i++) {
3632 for (j = i + 1; j < num_pins; j++) { 4109 for (j = i + 1; j < num_pins; j++) {
3633 if (sequences[i] > sequences[j]) { 4110 if (sequences[i] > sequences[j]) {
@@ -3655,7 +4132,7 @@ static void sort_pins_by_sequence(hda_nid_t * pins, short * sequences,
3655 * is detected, one of speaker of HP pins is assigned as the primary 4132 * is detected, one of speaker of HP pins is assigned as the primary
3656 * output, i.e. to line_out_pins[0]. So, line_outs is always positive 4133 * output, i.e. to line_out_pins[0]. So, line_outs is always positive
3657 * if any analog output exists. 4134 * if any analog output exists.
3658 * 4135 *
3659 * The analog input pins are assigned to input_pins array. 4136 * The analog input pins are assigned to input_pins array.
3660 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, 4137 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
3661 * respectively. 4138 * respectively.
@@ -3718,9 +4195,9 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3718 case AC_JACK_SPEAKER: 4195 case AC_JACK_SPEAKER:
3719 seq = get_defcfg_sequence(def_conf); 4196 seq = get_defcfg_sequence(def_conf);
3720 assoc = get_defcfg_association(def_conf); 4197 assoc = get_defcfg_association(def_conf);
3721 if (! assoc) 4198 if (!assoc)
3722 continue; 4199 continue;
3723 if (! assoc_speaker) 4200 if (!assoc_speaker)
3724 assoc_speaker = assoc; 4201 assoc_speaker = assoc;
3725 else if (assoc_speaker != assoc) 4202 else if (assoc_speaker != assoc)
3726 continue; 4203 continue;
@@ -3818,7 +4295,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3818 cfg->speaker_outs); 4295 cfg->speaker_outs);
3819 sort_pins_by_sequence(cfg->hp_pins, sequences_hp, 4296 sort_pins_by_sequence(cfg->hp_pins, sequences_hp,
3820 cfg->hp_outs); 4297 cfg->hp_outs);
3821 4298
3822 /* if we have only one mic, make it AUTO_PIN_MIC */ 4299 /* if we have only one mic, make it AUTO_PIN_MIC */
3823 if (!cfg->input_pins[AUTO_PIN_MIC] && 4300 if (!cfg->input_pins[AUTO_PIN_MIC] &&
3824 cfg->input_pins[AUTO_PIN_FRONT_MIC]) { 4301 cfg->input_pins[AUTO_PIN_FRONT_MIC]) {
@@ -3965,8 +4442,14 @@ EXPORT_SYMBOL_HDA(snd_hda_resume);
3965 * generic arrays 4442 * generic arrays
3966 */ 4443 */
3967 4444
3968/* get a new element from the given array 4445/**
3969 * if it exceeds the pre-allocated array size, re-allocate the array 4446 * snd_array_new - get a new element from the given array
4447 * @array: the array object
4448 *
4449 * Get a new element from the given array. If it exceeds the
4450 * pre-allocated array size, re-allocate the array.
4451 *
4452 * Returns NULL if allocation failed.
3970 */ 4453 */
3971void *snd_array_new(struct snd_array *array) 4454void *snd_array_new(struct snd_array *array)
3972{ 4455{
@@ -3990,7 +4473,10 @@ void *snd_array_new(struct snd_array *array)
3990} 4473}
3991EXPORT_SYMBOL_HDA(snd_array_new); 4474EXPORT_SYMBOL_HDA(snd_array_new);
3992 4475
3993/* free the given array elements */ 4476/**
4477 * snd_array_free - free the given array elements
4478 * @array: the array object
4479 */
3994void snd_array_free(struct snd_array *array) 4480void snd_array_free(struct snd_array *array)
3995{ 4481{
3996 kfree(array->list); 4482 kfree(array->list);
@@ -4000,7 +4486,12 @@ void snd_array_free(struct snd_array *array)
4000} 4486}
4001EXPORT_SYMBOL_HDA(snd_array_free); 4487EXPORT_SYMBOL_HDA(snd_array_free);
4002 4488
4003/* 4489/**
4490 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4491 * @pcm: PCM caps bits
4492 * @buf: the string buffer to write
4493 * @buflen: the max buffer length
4494 *
4004 * used by hda_proc.c and hda_eld.c 4495 * used by hda_proc.c and hda_eld.c
4005 */ 4496 */
4006void snd_print_pcm_rates(int pcm, char *buf, int buflen) 4497void snd_print_pcm_rates(int pcm, char *buf, int buflen)
@@ -4019,6 +4510,14 @@ void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4019} 4510}
4020EXPORT_SYMBOL_HDA(snd_print_pcm_rates); 4511EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4021 4512
4513/**
4514 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4515 * @pcm: PCM caps bits
4516 * @buf: the string buffer to write
4517 * @buflen: the max buffer length
4518 *
4519 * used by hda_proc.c and hda_eld.c
4520 */
4022void snd_print_pcm_bits(int pcm, char *buf, int buflen) 4521void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4023{ 4522{
4024 static unsigned int bits[] = { 8, 16, 20, 24, 32 }; 4523 static unsigned int bits[] = { 8, 16, 20, 24, 32 };