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.c607
1 files changed, 515 insertions, 92 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index af989f660cca..9cfdb771928c 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}
@@ -820,6 +843,16 @@ int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
820 return 0; 843 return 0;
821} 844}
822 845
846/**
847 * snd_hda_codec_set_pincfg - Override a pin default configuration
848 * @codec: the HDA codec
849 * @nid: NID to set the pin config
850 * @cfg: the pin default config value
851 *
852 * Override a pin default configuration value in the cache.
853 * This value can be read by snd_hda_codec_get_pincfg() in a higher
854 * priority than the real hardware value.
855 */
823int snd_hda_codec_set_pincfg(struct hda_codec *codec, 856int snd_hda_codec_set_pincfg(struct hda_codec *codec,
824 hda_nid_t nid, unsigned int cfg) 857 hda_nid_t nid, unsigned int cfg)
825{ 858{
@@ -827,7 +860,15 @@ int snd_hda_codec_set_pincfg(struct hda_codec *codec,
827} 860}
828EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg); 861EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
829 862
830/* get the current pin config value of the given pin NID */ 863/**
864 * snd_hda_codec_get_pincfg - Obtain a pin-default configuration
865 * @codec: the HDA codec
866 * @nid: NID to get the pin config
867 *
868 * Get the current pin config value of the given pin NID.
869 * If the pincfg value is cached or overridden via sysfs or driver,
870 * returns the cached value.
871 */
831unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid) 872unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
832{ 873{
833 struct hda_pincfg *pin; 874 struct hda_pincfg *pin;
@@ -944,7 +985,7 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
944 mutex_init(&codec->control_mutex); 985 mutex_init(&codec->control_mutex);
945 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 986 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
946 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 987 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
947 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32); 988 snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 60);
948 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); 989 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
949 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); 990 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
950 if (codec->bus->modelname) { 991 if (codec->bus->modelname) {
@@ -1026,6 +1067,15 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
1026} 1067}
1027EXPORT_SYMBOL_HDA(snd_hda_codec_new); 1068EXPORT_SYMBOL_HDA(snd_hda_codec_new);
1028 1069
1070/**
1071 * snd_hda_codec_configure - (Re-)configure the HD-audio codec
1072 * @codec: the HDA codec
1073 *
1074 * Start parsing of the given codec tree and (re-)initialize the whole
1075 * patch instance.
1076 *
1077 * Returns 0 if successful or a negative error code.
1078 */
1029int snd_hda_codec_configure(struct hda_codec *codec) 1079int snd_hda_codec_configure(struct hda_codec *codec)
1030{ 1080{
1031 int err; 1081 int err;
@@ -1088,6 +1138,11 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1088} 1138}
1089EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream); 1139EXPORT_SYMBOL_HDA(snd_hda_codec_setup_stream);
1090 1140
1141/**
1142 * snd_hda_codec_cleanup_stream - clean up the codec for closing
1143 * @codec: the CODEC to clean up
1144 * @nid: the NID to clean up
1145 */
1091void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid) 1146void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
1092{ 1147{
1093 if (!nid) 1148 if (!nid)
@@ -1163,8 +1218,17 @@ get_alloc_amp_hash(struct hda_codec *codec, u32 key)
1163 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key); 1218 return (struct hda_amp_info *)get_alloc_hash(&codec->amp_cache, key);
1164} 1219}
1165 1220
1166/* 1221/**
1167 * query AMP capabilities for the given widget and direction 1222 * query_amp_caps - query AMP capabilities
1223 * @codec: the HD-auio codec
1224 * @nid: the NID to query
1225 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1226 *
1227 * Query AMP capabilities for the given widget and direction.
1228 * Returns the obtained capability bits.
1229 *
1230 * When cap bits have been already read, this doesn't read again but
1231 * returns the cached value.
1168 */ 1232 */
1169u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction) 1233u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1170{ 1234{
@@ -1187,6 +1251,19 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction)
1187} 1251}
1188EXPORT_SYMBOL_HDA(query_amp_caps); 1252EXPORT_SYMBOL_HDA(query_amp_caps);
1189 1253
1254/**
1255 * snd_hda_override_amp_caps - Override the AMP capabilities
1256 * @codec: the CODEC to clean up
1257 * @nid: the NID to clean up
1258 * @direction: either #HDA_INPUT or #HDA_OUTPUT
1259 * @caps: the capability bits to set
1260 *
1261 * Override the cached AMP caps bits value by the given one.
1262 * This function is useful if the driver needs to adjust the AMP ranges,
1263 * e.g. limit to 0dB, etc.
1264 *
1265 * Returns zero if successful or a negative error code.
1266 */
1190int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 1267int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
1191 unsigned int caps) 1268 unsigned int caps)
1192{ 1269{
@@ -1222,6 +1299,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); 1299 return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1223} 1300}
1224 1301
1302/**
1303 * snd_hda_query_pin_caps - Query PIN capabilities
1304 * @codec: the HD-auio codec
1305 * @nid: the NID to query
1306 *
1307 * Query PIN capabilities for the given widget.
1308 * Returns the obtained capability bits.
1309 *
1310 * When cap bits have been already read, this doesn't read again but
1311 * returns the cached value.
1312 */
1225u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) 1313u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1226{ 1314{
1227 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid), 1315 return query_caps_hash(codec, nid, HDA_HASH_PINCAP_KEY(nid),
@@ -1229,6 +1317,40 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1229} 1317}
1230EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1318EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1231 1319
1320/**
1321 * snd_hda_pin_sense - execute pin sense measurement
1322 * @codec: the CODEC to sense
1323 * @nid: the pin NID to sense
1324 *
1325 * Execute necessary pin sense measurement and return its Presence Detect,
1326 * Impedance, ELD Valid etc. status bits.
1327 */
1328u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1329{
1330 u32 pincap = snd_hda_query_pin_caps(codec, nid);
1331
1332 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1333 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
1334
1335 return snd_hda_codec_read(codec, nid, 0,
1336 AC_VERB_GET_PIN_SENSE, 0);
1337}
1338EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1339
1340/**
1341 * snd_hda_jack_detect - query pin Presence Detect status
1342 * @codec: the CODEC to sense
1343 * @nid: the pin NID to sense
1344 *
1345 * Query and return the pin's Presence Detect status.
1346 */
1347int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1348{
1349 u32 sense = snd_hda_pin_sense(codec, nid);
1350 return !!(sense & AC_PINSENSE_PRESENCE);
1351}
1352EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1353
1232/* 1354/*
1233 * read the current volume to info 1355 * read the current volume to info
1234 * if the cache exists, read the cache value. 1356 * if the cache exists, read the cache value.
@@ -1269,8 +1391,15 @@ static void put_vol_mute(struct hda_codec *codec, struct hda_amp_info *info,
1269 info->vol[ch] = val; 1391 info->vol[ch] = val;
1270} 1392}
1271 1393
1272/* 1394/**
1273 * read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit. 1395 * snd_hda_codec_amp_read - Read AMP value
1396 * @codec: HD-audio codec
1397 * @nid: NID to read the AMP value
1398 * @ch: channel (left=0 or right=1)
1399 * @direction: #HDA_INPUT or #HDA_OUTPUT
1400 * @index: the index value (only for input direction)
1401 *
1402 * Read AMP value. The volume is between 0 to 0x7f, 0x80 = mute bit.
1274 */ 1403 */
1275int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch, 1404int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1276 int direction, int index) 1405 int direction, int index)
@@ -1283,8 +1412,18 @@ int snd_hda_codec_amp_read(struct hda_codec *codec, hda_nid_t nid, int ch,
1283} 1412}
1284EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read); 1413EXPORT_SYMBOL_HDA(snd_hda_codec_amp_read);
1285 1414
1286/* 1415/**
1287 * update the AMP value, mask = bit mask to set, val = the value 1416 * snd_hda_codec_amp_update - update the AMP value
1417 * @codec: HD-audio codec
1418 * @nid: NID to read the AMP value
1419 * @ch: channel (left=0 or right=1)
1420 * @direction: #HDA_INPUT or #HDA_OUTPUT
1421 * @idx: the index value (only for input direction)
1422 * @mask: bit mask to set
1423 * @val: the bits value to set
1424 *
1425 * Update the AMP value with a bit mask.
1426 * Returns 0 if the value is unchanged, 1 if changed.
1288 */ 1427 */
1289int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, 1428int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1290 int direction, int idx, int mask, int val) 1429 int direction, int idx, int mask, int val)
@@ -1303,8 +1442,17 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
1303} 1442}
1304EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update); 1443EXPORT_SYMBOL_HDA(snd_hda_codec_amp_update);
1305 1444
1306/* 1445/**
1307 * update the AMP stereo with the same mask and value 1446 * snd_hda_codec_amp_stereo - update the AMP stereo values
1447 * @codec: HD-audio codec
1448 * @nid: NID to read the AMP value
1449 * @direction: #HDA_INPUT or #HDA_OUTPUT
1450 * @idx: the index value (only for input direction)
1451 * @mask: bit mask to set
1452 * @val: the bits value to set
1453 *
1454 * Update the AMP values like snd_hda_codec_amp_update(), but for a
1455 * stereo widget with the same mask and value.
1308 */ 1456 */
1309int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid, 1457int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1310 int direction, int idx, int mask, int val) 1458 int direction, int idx, int mask, int val)
@@ -1318,7 +1466,12 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
1318EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo); 1466EXPORT_SYMBOL_HDA(snd_hda_codec_amp_stereo);
1319 1467
1320#ifdef SND_HDA_NEEDS_RESUME 1468#ifdef SND_HDA_NEEDS_RESUME
1321/* resume the all amp commands from the cache */ 1469/**
1470 * snd_hda_codec_resume_amp - Resume all AMP commands from the cache
1471 * @codec: HD-audio codec
1472 *
1473 * Resume the all amp commands from the cache.
1474 */
1322void snd_hda_codec_resume_amp(struct hda_codec *codec) 1475void snd_hda_codec_resume_amp(struct hda_codec *codec)
1323{ 1476{
1324 struct hda_amp_info *buffer = codec->amp_cache.buf.list; 1477 struct hda_amp_info *buffer = codec->amp_cache.buf.list;
@@ -1344,7 +1497,12 @@ void snd_hda_codec_resume_amp(struct hda_codec *codec)
1344EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp); 1497EXPORT_SYMBOL_HDA(snd_hda_codec_resume_amp);
1345#endif /* SND_HDA_NEEDS_RESUME */ 1498#endif /* SND_HDA_NEEDS_RESUME */
1346 1499
1347/* volume */ 1500/**
1501 * snd_hda_mixer_amp_volume_info - Info callback for a standard AMP mixer
1502 *
1503 * The control element is supposed to have the private_value field
1504 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1505 */
1348int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol, 1506int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1349 struct snd_ctl_elem_info *uinfo) 1507 struct snd_ctl_elem_info *uinfo)
1350{ 1508{
@@ -1400,6 +1558,12 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1400 HDA_AMP_VOLMASK, val); 1558 HDA_AMP_VOLMASK, val);
1401} 1559}
1402 1560
1561/**
1562 * snd_hda_mixer_amp_volume_get - Get callback for a standard AMP mixer volume
1563 *
1564 * The control element is supposed to have the private_value field
1565 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1566 */
1403int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1567int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1404 struct snd_ctl_elem_value *ucontrol) 1568 struct snd_ctl_elem_value *ucontrol)
1405{ 1569{
@@ -1419,6 +1583,12 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1419} 1583}
1420EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); 1584EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
1421 1585
1586/**
1587 * snd_hda_mixer_amp_volume_put - Put callback for a standard AMP mixer volume
1588 *
1589 * The control element is supposed to have the private_value field
1590 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1591 */
1422int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, 1592int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol) 1593 struct snd_ctl_elem_value *ucontrol)
1424{ 1594{
@@ -1443,6 +1613,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1443} 1613}
1444EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put); 1614EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_put);
1445 1615
1616/**
1617 * snd_hda_mixer_amp_volume_put - TLV callback for a standard AMP mixer volume
1618 *
1619 * The control element is supposed to have the private_value field
1620 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1621 */
1446int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag, 1622int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1447 unsigned int size, unsigned int __user *_tlv) 1623 unsigned int size, unsigned int __user *_tlv)
1448{ 1624{
@@ -1472,8 +1648,16 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1472} 1648}
1473EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv); 1649EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_tlv);
1474 1650
1475/* 1651/**
1476 * set (static) TLV for virtual master volume; recalculated as max 0dB 1652 * snd_hda_set_vmaster_tlv - Set TLV for a virtual master control
1653 * @codec: HD-audio codec
1654 * @nid: NID of a reference widget
1655 * @dir: #HDA_INPUT or #HDA_OUTPUT
1656 * @tlv: TLV data to be stored, at least 4 elements
1657 *
1658 * Set (static) TLV data for a virtual master volume using the AMP caps
1659 * obtained from the reference NID.
1660 * The volume range is recalculated as if the max volume is 0dB.
1477 */ 1661 */
1478void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, 1662void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1479 unsigned int *tlv) 1663 unsigned int *tlv)
@@ -1507,6 +1691,13 @@ _snd_hda_find_mixer_ctl(struct hda_codec *codec,
1507 return snd_ctl_find_id(codec->bus->card, &id); 1691 return snd_ctl_find_id(codec->bus->card, &id);
1508} 1692}
1509 1693
1694/**
1695 * snd_hda_find_mixer_ctl - Find a mixer control element with the given name
1696 * @codec: HD-audio codec
1697 * @name: ctl id name string
1698 *
1699 * Get the control element with the given id string and IFACE_MIXER.
1700 */
1510struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1701struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1511 const char *name) 1702 const char *name)
1512{ 1703{
@@ -1514,30 +1705,57 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1514} 1705}
1515EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl); 1706EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);
1516 1707
1517/* Add a control element and assign to the codec */ 1708/**
1518int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl) 1709 * snd_hda_ctl-add - Add a control element and assign to the codec
1710 * @codec: HD-audio codec
1711 * @nid: corresponding NID (optional)
1712 * @kctl: the control element to assign
1713 *
1714 * Add the given control element to an array inside the codec instance.
1715 * All control elements belonging to a codec are supposed to be added
1716 * by this function so that a proper clean-up works at the free or
1717 * reconfiguration time.
1718 *
1719 * If non-zero @nid is passed, the NID is assigned to the control element.
1720 * The assignment is shown in the codec proc file.
1721 *
1722 * snd_hda_ctl_add() checks the control subdev id field whether
1723 * #HDA_SUBDEV_NID_FLAG bit is set. If set (and @nid is zero), the lower
1724 * bits value is taken as the NID to assign.
1725 */
1726int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
1727 struct snd_kcontrol *kctl)
1519{ 1728{
1520 int err; 1729 int err;
1521 struct snd_kcontrol **knewp; 1730 struct hda_nid_item *item;
1522 1731
1732 if (kctl->id.subdevice & HDA_SUBDEV_NID_FLAG) {
1733 if (nid == 0)
1734 nid = kctl->id.subdevice & 0xffff;
1735 kctl->id.subdevice = 0;
1736 }
1523 err = snd_ctl_add(codec->bus->card, kctl); 1737 err = snd_ctl_add(codec->bus->card, kctl);
1524 if (err < 0) 1738 if (err < 0)
1525 return err; 1739 return err;
1526 knewp = snd_array_new(&codec->mixers); 1740 item = snd_array_new(&codec->mixers);
1527 if (!knewp) 1741 if (!item)
1528 return -ENOMEM; 1742 return -ENOMEM;
1529 *knewp = kctl; 1743 item->kctl = kctl;
1744 item->nid = nid;
1530 return 0; 1745 return 0;
1531} 1746}
1532EXPORT_SYMBOL_HDA(snd_hda_ctl_add); 1747EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1533 1748
1534/* Clear all controls assigned to the given codec */ 1749/**
1750 * snd_hda_ctls_clear - Clear all controls assigned to the given codec
1751 * @codec: HD-audio codec
1752 */
1535void snd_hda_ctls_clear(struct hda_codec *codec) 1753void snd_hda_ctls_clear(struct hda_codec *codec)
1536{ 1754{
1537 int i; 1755 int i;
1538 struct snd_kcontrol **kctls = codec->mixers.list; 1756 struct hda_nid_item *items = codec->mixers.list;
1539 for (i = 0; i < codec->mixers.used; i++) 1757 for (i = 0; i < codec->mixers.used; i++)
1540 snd_ctl_remove(codec->bus->card, kctls[i]); 1758 snd_ctl_remove(codec->bus->card, items[i].kctl);
1541 snd_array_free(&codec->mixers); 1759 snd_array_free(&codec->mixers);
1542} 1760}
1543 1761
@@ -1563,6 +1781,16 @@ static void hda_unlock_devices(struct snd_card *card)
1563 spin_unlock(&card->files_lock); 1781 spin_unlock(&card->files_lock);
1564} 1782}
1565 1783
1784/**
1785 * snd_hda_codec_reset - Clear all objects assigned to the codec
1786 * @codec: HD-audio codec
1787 *
1788 * This frees the all PCM and control elements assigned to the codec, and
1789 * clears the caches and restores the pin default configurations.
1790 *
1791 * When a device is being used, it returns -EBSY. If successfully freed,
1792 * returns zero.
1793 */
1566int snd_hda_codec_reset(struct hda_codec *codec) 1794int snd_hda_codec_reset(struct hda_codec *codec)
1567{ 1795{
1568 struct snd_card *card = codec->bus->card; 1796 struct snd_card *card = codec->bus->card;
@@ -1626,7 +1854,22 @@ int snd_hda_codec_reset(struct hda_codec *codec)
1626 return 0; 1854 return 0;
1627} 1855}
1628 1856
1629/* create a virtual master control and add slaves */ 1857/**
1858 * snd_hda_add_vmaster - create a virtual master control and add slaves
1859 * @codec: HD-audio codec
1860 * @name: vmaster control name
1861 * @tlv: TLV data (optional)
1862 * @slaves: slave control names (optional)
1863 *
1864 * Create a virtual master control with the given name. The TLV data
1865 * must be either NULL or a valid data.
1866 *
1867 * @slaves is a NULL-terminated array of strings, each of which is a
1868 * slave control name. All controls with these names are assigned to
1869 * the new virtual master control.
1870 *
1871 * This function returns zero if successful or a negative error code.
1872 */
1630int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1873int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1631 unsigned int *tlv, const char **slaves) 1874 unsigned int *tlv, const char **slaves)
1632{ 1875{
@@ -1643,7 +1886,7 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1643 kctl = snd_ctl_make_virtual_master(name, tlv); 1886 kctl = snd_ctl_make_virtual_master(name, tlv);
1644 if (!kctl) 1887 if (!kctl)
1645 return -ENOMEM; 1888 return -ENOMEM;
1646 err = snd_hda_ctl_add(codec, kctl); 1889 err = snd_hda_ctl_add(codec, 0, kctl);
1647 if (err < 0) 1890 if (err < 0)
1648 return err; 1891 return err;
1649 1892
@@ -1668,7 +1911,12 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1668} 1911}
1669EXPORT_SYMBOL_HDA(snd_hda_add_vmaster); 1912EXPORT_SYMBOL_HDA(snd_hda_add_vmaster);
1670 1913
1671/* switch */ 1914/**
1915 * snd_hda_mixer_amp_switch_info - Info callback for a standard AMP mixer switch
1916 *
1917 * The control element is supposed to have the private_value field
1918 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1919 */
1672int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol, 1920int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_info *uinfo) 1921 struct snd_ctl_elem_info *uinfo)
1674{ 1922{
@@ -1682,6 +1930,12 @@ int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
1682} 1930}
1683EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info); 1931EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_info);
1684 1932
1933/**
1934 * snd_hda_mixer_amp_switch_get - Get callback for a standard AMP mixer switch
1935 *
1936 * The control element is supposed to have the private_value field
1937 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1938 */
1685int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol, 1939int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1686 struct snd_ctl_elem_value *ucontrol) 1940 struct snd_ctl_elem_value *ucontrol)
1687{ 1941{
@@ -1702,6 +1956,12 @@ int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
1702} 1956}
1703EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get); 1957EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_get);
1704 1958
1959/**
1960 * snd_hda_mixer_amp_switch_put - Put callback for a standard AMP mixer switch
1961 *
1962 * The control element is supposed to have the private_value field
1963 * set up via HDA_COMPOSE_AMP_VAL*() or related macros.
1964 */
1705int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, 1965int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol) 1966 struct snd_ctl_elem_value *ucontrol)
1707{ 1967{
@@ -1733,6 +1993,25 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
1733} 1993}
1734EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put); 1994EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1735 1995
1996#ifdef CONFIG_SND_HDA_INPUT_BEEP
1997/**
1998 * snd_hda_mixer_amp_switch_put_beep - Put callback for a beep AMP switch
1999 *
2000 * This function calls snd_hda_enable_beep_device(), which behaves differently
2001 * depending on beep_mode option.
2002 */
2003int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
2004 struct snd_ctl_elem_value *ucontrol)
2005{
2006 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2007 long *valp = ucontrol->value.integer.value;
2008
2009 snd_hda_enable_beep_device(codec, *valp);
2010 return snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
2011}
2012EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put_beep);
2013#endif /* CONFIG_SND_HDA_INPUT_BEEP */
2014
1736/* 2015/*
1737 * bound volume controls 2016 * bound volume controls
1738 * 2017 *
@@ -1742,6 +2021,12 @@ EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_switch_put);
1742#define AMP_VAL_IDX_SHIFT 19 2021#define AMP_VAL_IDX_SHIFT 19
1743#define AMP_VAL_IDX_MASK (0x0f<<19) 2022#define AMP_VAL_IDX_MASK (0x0f<<19)
1744 2023
2024/**
2025 * snd_hda_mixer_bind_switch_get - Get callback for a bound volume control
2026 *
2027 * The control element is supposed to have the private_value field
2028 * set up via HDA_BIND_MUTE*() macros.
2029 */
1745int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol, 2030int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol) 2031 struct snd_ctl_elem_value *ucontrol)
1747{ 2032{
@@ -1759,6 +2044,12 @@ int snd_hda_mixer_bind_switch_get(struct snd_kcontrol *kcontrol,
1759} 2044}
1760EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get); 2045EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_get);
1761 2046
2047/**
2048 * snd_hda_mixer_bind_switch_put - Put callback for a bound volume control
2049 *
2050 * The control element is supposed to have the private_value field
2051 * set up via HDA_BIND_MUTE*() macros.
2052 */
1762int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol, 2053int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol) 2054 struct snd_ctl_elem_value *ucontrol)
1764{ 2055{
@@ -1783,8 +2074,11 @@ int snd_hda_mixer_bind_switch_put(struct snd_kcontrol *kcontrol,
1783} 2074}
1784EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put); 2075EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_switch_put);
1785 2076
1786/* 2077/**
1787 * generic bound volume/swtich controls 2078 * snd_hda_mixer_bind_ctls_info - Info callback for a generic bound control
2079 *
2080 * The control element is supposed to have the private_value field
2081 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
1788 */ 2082 */
1789int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, 2083int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_info *uinfo) 2084 struct snd_ctl_elem_info *uinfo)
@@ -1803,6 +2097,12 @@ int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
1803} 2097}
1804EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info); 2098EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_info);
1805 2099
2100/**
2101 * snd_hda_mixer_bind_ctls_get - Get callback for a generic bound control
2102 *
2103 * The control element is supposed to have the private_value field
2104 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2105 */
1806int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol, 2106int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1807 struct snd_ctl_elem_value *ucontrol) 2107 struct snd_ctl_elem_value *ucontrol)
1808{ 2108{
@@ -1820,6 +2120,12 @@ int snd_hda_mixer_bind_ctls_get(struct snd_kcontrol *kcontrol,
1820} 2120}
1821EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get); 2121EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_get);
1822 2122
2123/**
2124 * snd_hda_mixer_bind_ctls_put - Put callback for a generic bound control
2125 *
2126 * The control element is supposed to have the private_value field
2127 * set up via HDA_BIND_VOL() or HDA_BIND_SW() macros.
2128 */
1823int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol, 2129int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1824 struct snd_ctl_elem_value *ucontrol) 2130 struct snd_ctl_elem_value *ucontrol)
1825{ 2131{
@@ -1843,6 +2149,12 @@ int snd_hda_mixer_bind_ctls_put(struct snd_kcontrol *kcontrol,
1843} 2149}
1844EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put); 2150EXPORT_SYMBOL_HDA(snd_hda_mixer_bind_ctls_put);
1845 2151
2152/**
2153 * snd_hda_mixer_bind_tlv - TLV callback for a generic bound control
2154 *
2155 * The control element is supposed to have the private_value field
2156 * set up via HDA_BIND_VOL() macro.
2157 */
1846int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag, 2158int snd_hda_mixer_bind_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1847 unsigned int size, unsigned int __user *tlv) 2159 unsigned int size, unsigned int __user *tlv)
1848{ 2160{
@@ -2126,7 +2438,7 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
2126 return -ENOMEM; 2438 return -ENOMEM;
2127 kctl->id.index = idx; 2439 kctl->id.index = idx;
2128 kctl->private_value = nid; 2440 kctl->private_value = nid;
2129 err = snd_hda_ctl_add(codec, kctl); 2441 err = snd_hda_ctl_add(codec, nid, kctl);
2130 if (err < 0) 2442 if (err < 0)
2131 return err; 2443 return err;
2132 } 2444 }
@@ -2165,14 +2477,19 @@ static struct snd_kcontrol_new spdif_share_sw = {
2165 .put = spdif_share_sw_put, 2477 .put = spdif_share_sw_put,
2166}; 2478};
2167 2479
2480/**
2481 * snd_hda_create_spdif_share_sw - create Default PCM switch
2482 * @codec: the HDA codec
2483 * @mout: multi-out instance
2484 */
2168int snd_hda_create_spdif_share_sw(struct hda_codec *codec, 2485int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
2169 struct hda_multi_out *mout) 2486 struct hda_multi_out *mout)
2170{ 2487{
2171 if (!mout->dig_out_nid) 2488 if (!mout->dig_out_nid)
2172 return 0; 2489 return 0;
2173 /* ATTENTION: here mout is passed as private_data, instead of codec */ 2490 /* ATTENTION: here mout is passed as private_data, instead of codec */
2174 return snd_hda_ctl_add(codec, 2491 return snd_hda_ctl_add(codec, mout->dig_out_nid,
2175 snd_ctl_new1(&spdif_share_sw, mout)); 2492 snd_ctl_new1(&spdif_share_sw, mout));
2176} 2493}
2177EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw); 2494EXPORT_SYMBOL_HDA(snd_hda_create_spdif_share_sw);
2178 2495
@@ -2276,7 +2593,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
2276 if (!kctl) 2593 if (!kctl)
2277 return -ENOMEM; 2594 return -ENOMEM;
2278 kctl->private_value = nid; 2595 kctl->private_value = nid;
2279 err = snd_hda_ctl_add(codec, kctl); 2596 err = snd_hda_ctl_add(codec, nid, kctl);
2280 if (err < 0) 2597 if (err < 0)
2281 return err; 2598 return err;
2282 } 2599 }
@@ -2332,7 +2649,12 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2332} 2649}
2333EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); 2650EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
2334 2651
2335/* resume the all commands from the cache */ 2652/**
2653 * snd_hda_codec_resume_cache - Resume the all commands from the cache
2654 * @codec: HD-audio codec
2655 *
2656 * Execute all verbs recorded in the command caches to resume.
2657 */
2336void snd_hda_codec_resume_cache(struct hda_codec *codec) 2658void snd_hda_codec_resume_cache(struct hda_codec *codec)
2337{ 2659{
2338 struct hda_cache_head *buffer = codec->cmd_cache.buf.list; 2660 struct hda_cache_head *buffer = codec->cmd_cache.buf.list;
@@ -2452,9 +2774,11 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
2452 codec->afg ? codec->afg : codec->mfg, 2774 codec->afg ? codec->afg : codec->mfg,
2453 AC_PWRST_D3); 2775 AC_PWRST_D3);
2454#ifdef CONFIG_SND_HDA_POWER_SAVE 2776#ifdef CONFIG_SND_HDA_POWER_SAVE
2777 snd_hda_update_power_acct(codec);
2455 cancel_delayed_work(&codec->power_work); 2778 cancel_delayed_work(&codec->power_work);
2456 codec->power_on = 0; 2779 codec->power_on = 0;
2457 codec->power_transition = 0; 2780 codec->power_transition = 0;
2781 codec->power_jiffies = jiffies;
2458#endif 2782#endif
2459} 2783}
2460 2784
@@ -2756,8 +3080,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2756} 3080}
2757 3081
2758/** 3082/**
2759 * snd_hda_is_supported_format - check whether the given node supports 3083 * snd_hda_is_supported_format - Check the validity of the format
2760 * the format val 3084 * @codec: HD-audio codec
3085 * @nid: NID to check
3086 * @format: the HD-audio format value to check
3087 *
3088 * Check whether the given node supports the format value.
2761 * 3089 *
2762 * Returns 1 if supported, 0 if not. 3090 * Returns 1 if supported, 0 if not.
2763 */ 3091 */
@@ -2877,51 +3205,36 @@ static int set_pcm_default_values(struct hda_codec *codec,
2877 return 0; 3205 return 0;
2878} 3206}
2879 3207
3208/* global */
3209const char *snd_hda_pcm_type_name[HDA_PCM_NTYPES] = {
3210 "Audio", "SPDIF", "HDMI", "Modem"
3211};
3212
2880/* 3213/*
2881 * get the empty PCM device number to assign 3214 * get the empty PCM device number to assign
2882 */ 3215 */
2883static int get_empty_pcm_device(struct hda_bus *bus, int type) 3216static int get_empty_pcm_device(struct hda_bus *bus, int type)
2884{ 3217{
2885 static const char *dev_name[HDA_PCM_NTYPES] = { 3218 /* audio device indices; not linear to keep compatibility */
2886 "Audio", "SPDIF", "HDMI", "Modem" 3219 static int audio_idx[HDA_PCM_NTYPES][5] = {
2887 }; 3220 [HDA_PCM_TYPE_AUDIO] = { 0, 2, 4, 5, -1 },
2888 /* starting device index for each PCM type */ 3221 [HDA_PCM_TYPE_SPDIF] = { 1, -1 },
2889 static int dev_idx[HDA_PCM_NTYPES] = { 3222 [HDA_PCM_TYPE_HDMI] = { 3, 7, 8, 9, -1 },
2890 [HDA_PCM_TYPE_AUDIO] = 0, 3223 [HDA_PCM_TYPE_MODEM] = { 6, -1 },
2891 [HDA_PCM_TYPE_SPDIF] = 1,
2892 [HDA_PCM_TYPE_HDMI] = 3,
2893 [HDA_PCM_TYPE_MODEM] = 6
2894 }; 3224 };
2895 /* normal audio device indices; not linear to keep compatibility */ 3225 int i;
2896 static int audio_idx[4] = { 0, 2, 4, 5 }; 3226
2897 int i, dev; 3227 if (type >= HDA_PCM_NTYPES) {
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); 3228 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2920 return -EINVAL; 3229 return -EINVAL;
2921 } 3230 }
2922 ok: 3231
2923 set_bit(dev, bus->pcm_dev_bits); 3232 for (i = 0; audio_idx[type][i] >= 0 ; i++)
2924 return dev; 3233 if (!test_and_set_bit(audio_idx[type][i], bus->pcm_dev_bits))
3234 return audio_idx[type][i];
3235
3236 snd_printk(KERN_WARNING "Too many %s devices\n", snd_hda_pcm_type_name[type]);
3237 return -EAGAIN;
2925} 3238}
2926 3239
2927/* 3240/*
@@ -3159,14 +3472,14 @@ EXPORT_SYMBOL_HDA(snd_hda_check_board_codec_sid_config);
3159 */ 3472 */
3160int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew) 3473int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3161{ 3474{
3162 int err; 3475 int err;
3163 3476
3164 for (; knew->name; knew++) { 3477 for (; knew->name; knew++) {
3165 struct snd_kcontrol *kctl; 3478 struct snd_kcontrol *kctl;
3166 kctl = snd_ctl_new1(knew, codec); 3479 kctl = snd_ctl_new1(knew, codec);
3167 if (!kctl) 3480 if (!kctl)
3168 return -ENOMEM; 3481 return -ENOMEM;
3169 err = snd_hda_ctl_add(codec, kctl); 3482 err = snd_hda_ctl_add(codec, 0, kctl);
3170 if (err < 0) { 3483 if (err < 0) {
3171 if (!codec->addr) 3484 if (!codec->addr)
3172 return err; 3485 return err;
@@ -3174,7 +3487,7 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
3174 if (!kctl) 3487 if (!kctl)
3175 return -ENOMEM; 3488 return -ENOMEM;
3176 kctl->id.device = codec->addr; 3489 kctl->id.device = codec->addr;
3177 err = snd_hda_ctl_add(codec, kctl); 3490 err = snd_hda_ctl_add(codec, 0, kctl);
3178 if (err < 0) 3491 if (err < 0)
3179 return err; 3492 return err;
3180 } 3493 }
@@ -3207,8 +3520,27 @@ static void hda_keep_power_on(struct hda_codec *codec)
3207{ 3520{
3208 codec->power_count++; 3521 codec->power_count++;
3209 codec->power_on = 1; 3522 codec->power_on = 1;
3523 codec->power_jiffies = jiffies;
3210} 3524}
3211 3525
3526/* update the power on/off account with the current jiffies */
3527void snd_hda_update_power_acct(struct hda_codec *codec)
3528{
3529 unsigned long delta = jiffies - codec->power_jiffies;
3530 if (codec->power_on)
3531 codec->power_on_acct += delta;
3532 else
3533 codec->power_off_acct += delta;
3534 codec->power_jiffies += delta;
3535}
3536
3537/**
3538 * snd_hda_power_up - Power-up the codec
3539 * @codec: HD-audio codec
3540 *
3541 * Increment the power-up counter and power up the hardware really when
3542 * not turned on yet.
3543 */
3212void snd_hda_power_up(struct hda_codec *codec) 3544void snd_hda_power_up(struct hda_codec *codec)
3213{ 3545{
3214 struct hda_bus *bus = codec->bus; 3546 struct hda_bus *bus = codec->bus;
@@ -3217,7 +3549,9 @@ void snd_hda_power_up(struct hda_codec *codec)
3217 if (codec->power_on || codec->power_transition) 3549 if (codec->power_on || codec->power_transition)
3218 return; 3550 return;
3219 3551
3552 snd_hda_update_power_acct(codec);
3220 codec->power_on = 1; 3553 codec->power_on = 1;
3554 codec->power_jiffies = jiffies;
3221 if (bus->ops.pm_notify) 3555 if (bus->ops.pm_notify)
3222 bus->ops.pm_notify(bus); 3556 bus->ops.pm_notify(bus);
3223 hda_call_codec_resume(codec); 3557 hda_call_codec_resume(codec);
@@ -3229,9 +3563,13 @@ EXPORT_SYMBOL_HDA(snd_hda_power_up);
3229#define power_save(codec) \ 3563#define power_save(codec) \
3230 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3564 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0)
3231 3565
3232#define power_save(codec) \ 3566/**
3233 ((codec)->bus->power_save ? *(codec)->bus->power_save : 0) 3567 * snd_hda_power_down - Power-down the codec
3234 3568 * @codec: HD-audio codec
3569 *
3570 * Decrement the power-up counter and schedules the power-off work if
3571 * the counter rearches to zero.
3572 */
3235void snd_hda_power_down(struct hda_codec *codec) 3573void snd_hda_power_down(struct hda_codec *codec)
3236{ 3574{
3237 --codec->power_count; 3575 --codec->power_count;
@@ -3245,6 +3583,19 @@ void snd_hda_power_down(struct hda_codec *codec)
3245} 3583}
3246EXPORT_SYMBOL_HDA(snd_hda_power_down); 3584EXPORT_SYMBOL_HDA(snd_hda_power_down);
3247 3585
3586/**
3587 * snd_hda_check_amp_list_power - Check the amp list and update the power
3588 * @codec: HD-audio codec
3589 * @check: the object containing an AMP list and the status
3590 * @nid: NID to check / update
3591 *
3592 * Check whether the given NID is in the amp list. If it's in the list,
3593 * check the current AMP status, and update the the power-status according
3594 * to the mute status.
3595 *
3596 * This function is supposed to be set or called from the check_power_status
3597 * patch ops.
3598 */
3248int snd_hda_check_amp_list_power(struct hda_codec *codec, 3599int snd_hda_check_amp_list_power(struct hda_codec *codec,
3249 struct hda_loopback_check *check, 3600 struct hda_loopback_check *check,
3250 hda_nid_t nid) 3601 hda_nid_t nid)
@@ -3286,6 +3637,10 @@ EXPORT_SYMBOL_HDA(snd_hda_check_amp_list_power);
3286/* 3637/*
3287 * Channel mode helper 3638 * Channel mode helper
3288 */ 3639 */
3640
3641/**
3642 * snd_hda_ch_mode_info - Info callback helper for the channel mode enum
3643 */
3289int snd_hda_ch_mode_info(struct hda_codec *codec, 3644int snd_hda_ch_mode_info(struct hda_codec *codec,
3290 struct snd_ctl_elem_info *uinfo, 3645 struct snd_ctl_elem_info *uinfo,
3291 const struct hda_channel_mode *chmode, 3646 const struct hda_channel_mode *chmode,
@@ -3302,6 +3657,9 @@ int snd_hda_ch_mode_info(struct hda_codec *codec,
3302} 3657}
3303EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info); 3658EXPORT_SYMBOL_HDA(snd_hda_ch_mode_info);
3304 3659
3660/**
3661 * snd_hda_ch_mode_get - Get callback helper for the channel mode enum
3662 */
3305int snd_hda_ch_mode_get(struct hda_codec *codec, 3663int snd_hda_ch_mode_get(struct hda_codec *codec,
3306 struct snd_ctl_elem_value *ucontrol, 3664 struct snd_ctl_elem_value *ucontrol,
3307 const struct hda_channel_mode *chmode, 3665 const struct hda_channel_mode *chmode,
@@ -3320,6 +3678,9 @@ int snd_hda_ch_mode_get(struct hda_codec *codec,
3320} 3678}
3321EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get); 3679EXPORT_SYMBOL_HDA(snd_hda_ch_mode_get);
3322 3680
3681/**
3682 * snd_hda_ch_mode_put - Put callback helper for the channel mode enum
3683 */
3323int snd_hda_ch_mode_put(struct hda_codec *codec, 3684int snd_hda_ch_mode_put(struct hda_codec *codec,
3324 struct snd_ctl_elem_value *ucontrol, 3685 struct snd_ctl_elem_value *ucontrol,
3325 const struct hda_channel_mode *chmode, 3686 const struct hda_channel_mode *chmode,
@@ -3344,6 +3705,10 @@ EXPORT_SYMBOL_HDA(snd_hda_ch_mode_put);
3344/* 3705/*
3345 * input MUX helper 3706 * input MUX helper
3346 */ 3707 */
3708
3709/**
3710 * snd_hda_input_mux_info_info - Info callback helper for the input-mux enum
3711 */
3347int snd_hda_input_mux_info(const struct hda_input_mux *imux, 3712int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3348 struct snd_ctl_elem_info *uinfo) 3713 struct snd_ctl_elem_info *uinfo)
3349{ 3714{
@@ -3362,6 +3727,9 @@ int snd_hda_input_mux_info(const struct hda_input_mux *imux,
3362} 3727}
3363EXPORT_SYMBOL_HDA(snd_hda_input_mux_info); 3728EXPORT_SYMBOL_HDA(snd_hda_input_mux_info);
3364 3729
3730/**
3731 * snd_hda_input_mux_info_put - Put callback helper for the input-mux enum
3732 */
3365int snd_hda_input_mux_put(struct hda_codec *codec, 3733int snd_hda_input_mux_put(struct hda_codec *codec,
3366 const struct hda_input_mux *imux, 3734 const struct hda_input_mux *imux,
3367 struct snd_ctl_elem_value *ucontrol, 3735 struct snd_ctl_elem_value *ucontrol,
@@ -3421,8 +3789,29 @@ static void cleanup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid)
3421 } 3789 }
3422} 3790}
3423 3791
3424/* 3792/**
3425 * open the digital out in the exclusive mode 3793 * snd_hda_bus_reboot_notify - call the reboot notifier of each codec
3794 * @bus: HD-audio bus
3795 */
3796void snd_hda_bus_reboot_notify(struct hda_bus *bus)
3797{
3798 struct hda_codec *codec;
3799
3800 if (!bus)
3801 return;
3802 list_for_each_entry(codec, &bus->codec_list, list) {
3803#ifdef CONFIG_SND_HDA_POWER_SAVE
3804 if (!codec->power_on)
3805 continue;
3806#endif
3807 if (codec->patch_ops.reboot_notify)
3808 codec->patch_ops.reboot_notify(codec);
3809 }
3810}
3811EXPORT_SYMBOL_HDA(snd_hda_bus_reboot_notify);
3812
3813/**
3814 * snd_hda_multi_out_dig_open - open the digital out in the exclusive mode
3426 */ 3815 */
3427int snd_hda_multi_out_dig_open(struct hda_codec *codec, 3816int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3428 struct hda_multi_out *mout) 3817 struct hda_multi_out *mout)
@@ -3437,6 +3826,9 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
3437} 3826}
3438EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open); 3827EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_open);
3439 3828
3829/**
3830 * snd_hda_multi_out_dig_prepare - prepare the digital out stream
3831 */
3440int snd_hda_multi_out_dig_prepare(struct hda_codec *codec, 3832int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3441 struct hda_multi_out *mout, 3833 struct hda_multi_out *mout,
3442 unsigned int stream_tag, 3834 unsigned int stream_tag,
@@ -3450,6 +3842,9 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
3450} 3842}
3451EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare); 3843EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_prepare);
3452 3844
3845/**
3846 * snd_hda_multi_out_dig_cleanup - clean-up the digital out stream
3847 */
3453int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec, 3848int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3454 struct hda_multi_out *mout) 3849 struct hda_multi_out *mout)
3455{ 3850{
@@ -3460,8 +3855,8 @@ int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
3460} 3855}
3461EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup); 3856EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_cleanup);
3462 3857
3463/* 3858/**
3464 * release the digital out 3859 * snd_hda_multi_out_dig_close - release the digital out stream
3465 */ 3860 */
3466int snd_hda_multi_out_dig_close(struct hda_codec *codec, 3861int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3467 struct hda_multi_out *mout) 3862 struct hda_multi_out *mout)
@@ -3473,8 +3868,12 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
3473} 3868}
3474EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close); 3869EXPORT_SYMBOL_HDA(snd_hda_multi_out_dig_close);
3475 3870
3476/* 3871/**
3477 * set up more restrictions for analog out 3872 * snd_hda_multi_out_analog_open - open analog outputs
3873 *
3874 * Open analog outputs and set up the hw-constraints.
3875 * If the digital outputs can be opened as slave, open the digital
3876 * outputs, too.
3478 */ 3877 */
3479int snd_hda_multi_out_analog_open(struct hda_codec *codec, 3878int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3480 struct hda_multi_out *mout, 3879 struct hda_multi_out *mout,
@@ -3519,9 +3918,11 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3519} 3918}
3520EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open); 3919EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_open);
3521 3920
3522/* 3921/**
3523 * set up the i/o for analog out 3922 * 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. 3923 *
3924 * Set up the i/o for analog out.
3925 * When the digital out is available, copy the front out to digital out, too.
3525 */ 3926 */
3526int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 3927int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3527 struct hda_multi_out *mout, 3928 struct hda_multi_out *mout,
@@ -3578,8 +3979,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
3578} 3979}
3579EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare); 3980EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_prepare);
3580 3981
3581/* 3982/**
3582 * clean up the setting for analog out 3983 * snd_hda_multi_out_analog_cleanup - clean up the setting for analog out
3583 */ 3984 */
3584int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, 3985int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
3585 struct hda_multi_out *mout) 3986 struct hda_multi_out *mout)
@@ -3965,8 +4366,14 @@ EXPORT_SYMBOL_HDA(snd_hda_resume);
3965 * generic arrays 4366 * generic arrays
3966 */ 4367 */
3967 4368
3968/* get a new element from the given array 4369/**
3969 * if it exceeds the pre-allocated array size, re-allocate the array 4370 * snd_array_new - get a new element from the given array
4371 * @array: the array object
4372 *
4373 * Get a new element from the given array. If it exceeds the
4374 * pre-allocated array size, re-allocate the array.
4375 *
4376 * Returns NULL if allocation failed.
3970 */ 4377 */
3971void *snd_array_new(struct snd_array *array) 4378void *snd_array_new(struct snd_array *array)
3972{ 4379{
@@ -3990,7 +4397,10 @@ void *snd_array_new(struct snd_array *array)
3990} 4397}
3991EXPORT_SYMBOL_HDA(snd_array_new); 4398EXPORT_SYMBOL_HDA(snd_array_new);
3992 4399
3993/* free the given array elements */ 4400/**
4401 * snd_array_free - free the given array elements
4402 * @array: the array object
4403 */
3994void snd_array_free(struct snd_array *array) 4404void snd_array_free(struct snd_array *array)
3995{ 4405{
3996 kfree(array->list); 4406 kfree(array->list);
@@ -4000,7 +4410,12 @@ void snd_array_free(struct snd_array *array)
4000} 4410}
4001EXPORT_SYMBOL_HDA(snd_array_free); 4411EXPORT_SYMBOL_HDA(snd_array_free);
4002 4412
4003/* 4413/**
4414 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
4415 * @pcm: PCM caps bits
4416 * @buf: the string buffer to write
4417 * @buflen: the max buffer length
4418 *
4004 * used by hda_proc.c and hda_eld.c 4419 * used by hda_proc.c and hda_eld.c
4005 */ 4420 */
4006void snd_print_pcm_rates(int pcm, char *buf, int buflen) 4421void snd_print_pcm_rates(int pcm, char *buf, int buflen)
@@ -4019,6 +4434,14 @@ void snd_print_pcm_rates(int pcm, char *buf, int buflen)
4019} 4434}
4020EXPORT_SYMBOL_HDA(snd_print_pcm_rates); 4435EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
4021 4436
4437/**
4438 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
4439 * @pcm: PCM caps bits
4440 * @buf: the string buffer to write
4441 * @buflen: the max buffer length
4442 *
4443 * used by hda_proc.c and hda_eld.c
4444 */
4022void snd_print_pcm_bits(int pcm, char *buf, int buflen) 4445void snd_print_pcm_bits(int pcm, char *buf, int buflen)
4023{ 4446{
4024 static unsigned int bits[] = { 8, 16, 20, 24, 32 }; 4447 static unsigned int bits[] = { 8, 16, 20, 24, 32 };