aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2010-08-30 05:00:19 -0400
committerTakashi Iwai <tiwai@suse.de>2010-08-30 05:00:19 -0400
commitf3268512c3a5dea587cfe875b8bca98d9e164cd9 (patch)
tree3d9a79d10eb04d001840daf9c2606ecf8315cc02 /sound
parent73413b120d5d6eb6c98451bbc19acf43e0e300ae (diff)
ALSA: hda - Refactor input-pin parser for VIA codecs
patch_via.c has redundant codes for parsing the input-pins. Although they are pretty similar, but all implemented in different functions just because of hard-coded ids and slight incompatibilities. This patch refactors the codes to use the common helper function, resulting in the reduction of many lines. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/pci/hda/patch_via.c390
1 files changed, 60 insertions, 330 deletions
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index ae3acb2b42d1..41861388f43a 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -2413,51 +2413,53 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2413} 2413}
2414 2414
2415/* create playback/capture controls for input pins */ 2415/* create playback/capture controls for input pins */
2416static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec, 2416static int vt_auto_create_analog_input_ctls(struct via_spec *spec,
2417 const struct auto_pin_cfg *cfg) 2417 const struct auto_pin_cfg *cfg,
2418 hda_nid_t cap_nid,
2419 hda_nid_t pin_idxs[], int num_idxs)
2418{ 2420{
2419 static char *labels[] = {
2420 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2421 };
2422 struct hda_input_mux *imux = &spec->private_imux[0]; 2421 struct hda_input_mux *imux = &spec->private_imux[0];
2423 int i, err, idx = 0; 2422 int i, err, idx;
2424 2423
2425 /* for internal loopback recording select */ 2424 /* for internal loopback recording select */
2426 imux->items[imux->num_items].label = "Stereo Mixer"; 2425 for (idx = 0; idx < num_idxs; idx++) {
2427 imux->items[imux->num_items].index = idx; 2426 if (pin_idxs[idx] == 0xff) {
2428 imux->num_items++; 2427 imux->items[imux->num_items].label = "Stereo Mixer";
2428 imux->items[imux->num_items].index = idx;
2429 imux->num_items++;
2430 break;
2431 }
2432 }
2429 2433
2430 for (i = 0; i < AUTO_PIN_LAST; i++) { 2434 for (i = 0; i < AUTO_PIN_LAST; i++) {
2431 if (!cfg->input_pins[i]) 2435 if (!cfg->input_pins[i])
2432 continue; 2436 continue;
2433 2437
2434 switch (cfg->input_pins[i]) { 2438 for (idx = 0; idx < num_idxs; idx++)
2435 case 0x1d: /* Mic */ 2439 if (pin_idxs[idx] == cfg->input_pins[i])
2436 idx = 2; 2440 break;
2437 break; 2441 if (idx >= num_idxs)
2438 2442 continue;
2439 case 0x1e: /* Line In */ 2443 err = via_new_analog_input(spec, auto_pin_cfg_labels[i],
2440 idx = 3; 2444 idx, cap_nid);
2441 break;
2442
2443 case 0x21: /* Front Mic */
2444 idx = 4;
2445 break;
2446
2447 case 0x24: /* CD */
2448 idx = 1;
2449 break;
2450 }
2451 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2452 if (err < 0) 2445 if (err < 0)
2453 return err; 2446 return err;
2454 imux->items[imux->num_items].label = labels[i]; 2447 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2455 imux->items[imux->num_items].index = idx; 2448 imux->items[imux->num_items].index = idx;
2456 imux->num_items++; 2449 imux->num_items++;
2457 } 2450 }
2458 return 0; 2451 return 0;
2459} 2452}
2460 2453
2454/* create playback/capture controls for input pins */
2455static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2456 const struct auto_pin_cfg *cfg)
2457{
2458 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2459 return vt_auto_create_analog_input_ctls(spec, cfg, 0x17, pin_idxs,
2460 ARRAY_SIZE(pin_idxs));
2461}
2462
2461#ifdef CONFIG_SND_HDA_POWER_SAVE 2463#ifdef CONFIG_SND_HDA_POWER_SAVE
2462static struct hda_amp_list vt1708_loopbacks[] = { 2464static struct hda_amp_list vt1708_loopbacks[] = {
2463 { 0x17, HDA_INPUT, 1 }, 2465 { 0x17, HDA_INPUT, 1 },
@@ -3024,46 +3026,9 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3024static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec, 3026static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
3025 const struct auto_pin_cfg *cfg) 3027 const struct auto_pin_cfg *cfg)
3026{ 3028{
3027 static char *labels[] = { 3029 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3028 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 3030 return vt_auto_create_analog_input_ctls(spec, cfg, 0x18, pin_idxs,
3029 }; 3031 ARRAY_SIZE(pin_idxs));
3030 struct hda_input_mux *imux = &spec->private_imux[0];
3031 int i, err, idx = 0;
3032
3033 /* for internal loopback recording select */
3034 imux->items[imux->num_items].label = "Stereo Mixer";
3035 imux->items[imux->num_items].index = idx;
3036 imux->num_items++;
3037
3038 for (i = 0; i < AUTO_PIN_LAST; i++) {
3039 if (!cfg->input_pins[i])
3040 continue;
3041
3042 switch (cfg->input_pins[i]) {
3043 case 0x1d: /* Mic */
3044 idx = 2;
3045 break;
3046
3047 case 0x1e: /* Line In */
3048 idx = 3;
3049 break;
3050
3051 case 0x21: /* Front Mic */
3052 idx = 4;
3053 break;
3054
3055 case 0x23: /* CD */
3056 idx = 1;
3057 break;
3058 }
3059 err = via_new_analog_input(spec, labels[i], idx, 0x18);
3060 if (err < 0)
3061 return err;
3062 imux->items[imux->num_items].label = labels[i];
3063 imux->items[imux->num_items].index = idx;
3064 imux->num_items++;
3065 }
3066 return 0;
3067} 3032}
3068 3033
3069static int vt1709_parse_auto_config(struct hda_codec *codec) 3034static int vt1709_parse_auto_config(struct hda_codec *codec)
@@ -3591,46 +3556,9 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3591static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec, 3556static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3592 const struct auto_pin_cfg *cfg) 3557 const struct auto_pin_cfg *cfg)
3593{ 3558{
3594 static char *labels[] = { 3559 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3595 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 3560 return vt_auto_create_analog_input_ctls(spec, cfg, 0x16, pin_idxs,
3596 }; 3561 ARRAY_SIZE(pin_idxs));
3597 struct hda_input_mux *imux = &spec->private_imux[0];
3598 int i, err, idx = 0;
3599
3600 /* for internal loopback recording select */
3601 imux->items[imux->num_items].label = "Stereo Mixer";
3602 imux->items[imux->num_items].index = idx;
3603 imux->num_items++;
3604
3605 for (i = 0; i < AUTO_PIN_LAST; i++) {
3606 if (!cfg->input_pins[i])
3607 continue;
3608
3609 switch (cfg->input_pins[i]) {
3610 case 0x1a: /* Mic */
3611 idx = 2;
3612 break;
3613
3614 case 0x1b: /* Line In */
3615 idx = 3;
3616 break;
3617
3618 case 0x1e: /* Front Mic */
3619 idx = 4;
3620 break;
3621
3622 case 0x1f: /* CD */
3623 idx = 1;
3624 break;
3625 }
3626 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3627 if (err < 0)
3628 return err;
3629 imux->items[imux->num_items].label = labels[i];
3630 imux->items[imux->num_items].index = idx;
3631 imux->num_items++;
3632 }
3633 return 0;
3634} 3562}
3635 3563
3636static int vt1708B_parse_auto_config(struct hda_codec *codec) 3564static int vt1708B_parse_auto_config(struct hda_codec *codec)
@@ -4064,46 +3992,9 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4064static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec, 3992static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
4065 const struct auto_pin_cfg *cfg) 3993 const struct auto_pin_cfg *cfg)
4066{ 3994{
4067 static char *labels[] = { 3995 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
4068 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 3996 return vt_auto_create_analog_input_ctls(spec, cfg, 0x16, pin_idxs,
4069 }; 3997 ARRAY_SIZE(pin_idxs));
4070 struct hda_input_mux *imux = &spec->private_imux[0];
4071 int i, err, idx = 0;
4072
4073 /* for internal loopback recording select */
4074 imux->items[imux->num_items].label = "Stereo Mixer";
4075 imux->items[imux->num_items].index = 5;
4076 imux->num_items++;
4077
4078 for (i = 0; i < AUTO_PIN_LAST; i++) {
4079 if (!cfg->input_pins[i])
4080 continue;
4081
4082 switch (cfg->input_pins[i]) {
4083 case 0x1a: /* Mic */
4084 idx = 2;
4085 break;
4086
4087 case 0x1b: /* Line In */
4088 idx = 3;
4089 break;
4090
4091 case 0x1e: /* Front Mic */
4092 idx = 4;
4093 break;
4094
4095 case 0x1f: /* CD */
4096 idx = 1;
4097 break;
4098 }
4099 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4100 if (err < 0)
4101 return err;
4102 imux->items[imux->num_items].label = labels[i];
4103 imux->items[imux->num_items].index = idx-1;
4104 imux->num_items++;
4105 }
4106 return 0;
4107} 3998}
4108 3999
4109/* fill out digital output widgets; one for master and one for slave outputs */ 4000/* fill out digital output widgets; one for master and one for slave outputs */
@@ -4457,42 +4348,9 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4457static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec, 4348static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4458 const struct auto_pin_cfg *cfg) 4349 const struct auto_pin_cfg *cfg)
4459{ 4350{
4460 static char *labels[] = { 4351 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4461 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 4352 return vt_auto_create_analog_input_ctls(spec, cfg, 0x1a, pin_idxs,
4462 }; 4353 ARRAY_SIZE(pin_idxs));
4463 struct hda_input_mux *imux = &spec->private_imux[0];
4464 int i, err, idx = 0;
4465
4466 /* for internal loopback recording select */
4467 imux->items[imux->num_items].label = "Stereo Mixer";
4468 imux->items[imux->num_items].index = 3;
4469 imux->num_items++;
4470
4471 for (i = 0; i < AUTO_PIN_LAST; i++) {
4472 if (!cfg->input_pins[i])
4473 continue;
4474
4475 switch (cfg->input_pins[i]) {
4476 case 0x14: /* Mic */
4477 idx = 1;
4478 break;
4479
4480 case 0x15: /* Line In */
4481 idx = 2;
4482 break;
4483
4484 case 0x18: /* Front Mic */
4485 idx = 3;
4486 break;
4487 }
4488 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4489 if (err < 0)
4490 return err;
4491 imux->items[imux->num_items].label = labels[i];
4492 imux->items[imux->num_items].index = idx-1;
4493 imux->num_items++;
4494 }
4495 return 0;
4496} 4354}
4497 4355
4498static int vt1702_parse_auto_config(struct hda_codec *codec) 4356static int vt1702_parse_auto_config(struct hda_codec *codec)
@@ -4875,46 +4733,9 @@ static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4875static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec, 4733static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4876 const struct auto_pin_cfg *cfg) 4734 const struct auto_pin_cfg *cfg)
4877{ 4735{
4878 static char *labels[] = { 4736 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4879 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 4737 return vt_auto_create_analog_input_ctls(spec, cfg, 0x21, pin_idxs,
4880 }; 4738 ARRAY_SIZE(pin_idxs));
4881 struct hda_input_mux *imux = &spec->private_imux[0];
4882 int i, err, idx = 0;
4883
4884 /* for internal loopback recording select */
4885 imux->items[imux->num_items].label = "Stereo Mixer";
4886 imux->items[imux->num_items].index = 5;
4887 imux->num_items++;
4888
4889 for (i = 0; i < AUTO_PIN_LAST; i++) {
4890 if (!cfg->input_pins[i])
4891 continue;
4892
4893 switch (cfg->input_pins[i]) {
4894 case 0x2b: /* Mic */
4895 idx = 1;
4896 break;
4897
4898 case 0x2a: /* Line In */
4899 idx = 2;
4900 break;
4901
4902 case 0x29: /* Front Mic */
4903 idx = 3;
4904 break;
4905
4906 case 0x2c: /* CD */
4907 idx = 0;
4908 break;
4909 }
4910 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4911 if (err < 0)
4912 return err;
4913 imux->items[imux->num_items].label = labels[i];
4914 imux->items[imux->num_items].index = idx;
4915 imux->num_items++;
4916 }
4917 return 0;
4918} 4739}
4919 4740
4920static int vt1718S_parse_auto_config(struct hda_codec *codec) 4741static int vt1718S_parse_auto_config(struct hda_codec *codec)
@@ -5374,46 +5195,9 @@ static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5374static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec, 5195static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5375 const struct auto_pin_cfg *cfg) 5196 const struct auto_pin_cfg *cfg)
5376{ 5197{
5377 static char *labels[] = { 5198 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5378 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL 5199 return vt_auto_create_analog_input_ctls(spec, cfg, 0x16, pin_idxs,
5379 }; 5200 ARRAY_SIZE(pin_idxs));
5380 struct hda_input_mux *imux = &spec->private_imux[0];
5381 int i, err, idx = 0;
5382
5383 /* for internal loopback recording select */
5384 imux->items[imux->num_items].label = "Stereo Mixer";
5385 imux->items[imux->num_items].index = 5;
5386 imux->num_items++;
5387
5388 for (i = 0; i < AUTO_PIN_LAST; i++) {
5389 if (!cfg->input_pins[i])
5390 continue;
5391
5392 switch (cfg->input_pins[i]) {
5393 case 0x1a: /* Mic */
5394 idx = 2;
5395 break;
5396
5397 case 0x1b: /* Line In */
5398 idx = 3;
5399 break;
5400
5401 case 0x1e: /* Front Mic */
5402 idx = 4;
5403 break;
5404
5405 case 0x1f: /* CD */
5406 idx = 1;
5407 break;
5408 }
5409 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5410 if (err < 0)
5411 return err;
5412 imux->items[imux->num_items].label = labels[i];
5413 imux->items[imux->num_items].index = idx-1;
5414 imux->num_items++;
5415 }
5416 return 0;
5417} 5201}
5418 5202
5419static int vt1716S_parse_auto_config(struct hda_codec *codec) 5203static int vt1716S_parse_auto_config(struct hda_codec *codec)
@@ -5720,47 +5504,19 @@ static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5720static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec, 5504static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5721 const struct auto_pin_cfg *cfg) 5505 const struct auto_pin_cfg *cfg)
5722{ 5506{
5723 static char *labels[] = {
5724 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5725 };
5726 struct hda_input_mux *imux = &spec->private_imux[0]; 5507 struct hda_input_mux *imux = &spec->private_imux[0];
5727 int i, err, idx = 0; 5508 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5728 5509 int err;
5729 for (i = 0; i < AUTO_PIN_LAST; i++) {
5730 if (!cfg->input_pins[i])
5731 continue;
5732
5733 switch (cfg->input_pins[i]) {
5734 case 0x2b: /* Mic */
5735 idx = 0;
5736 break;
5737
5738 case 0x2a: /* Line In */
5739 idx = 1;
5740 break;
5741
5742 case 0x29: /* Front Mic */
5743 idx = 2;
5744 break;
5745 }
5746 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5747 if (err < 0)
5748 return err;
5749 imux->items[imux->num_items].label = labels[i];
5750 imux->items[imux->num_items].index = idx;
5751 imux->num_items++;
5752 }
5753 5510
5511 err = vt_auto_create_analog_input_ctls(spec, cfg, 0x21, pin_idxs,
5512 ARRAY_SIZE(pin_idxs));
5513 if (err < 0)
5514 return err;
5754 /* build volume/mute control of loopback */ 5515 /* build volume/mute control of loopback */
5755 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21); 5516 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5756 if (err < 0) 5517 if (err < 0)
5757 return err; 5518 return err;
5758 5519
5759 /* for internal loopback recording select */
5760 imux->items[imux->num_items].label = "Stereo Mixer";
5761 imux->items[imux->num_items].index = 3;
5762 imux->num_items++;
5763
5764 /* for digital mic select */ 5520 /* for digital mic select */
5765 imux->items[imux->num_items].label = "Digital Mic"; 5521 imux->items[imux->num_items].label = "Digital Mic";
5766 imux->items[imux->num_items].index = 4; 5522 imux->items[imux->num_items].index = 4;
@@ -6070,46 +5826,20 @@ static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
6070static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec, 5826static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
6071 const struct auto_pin_cfg *cfg) 5827 const struct auto_pin_cfg *cfg)
6072{ 5828{
6073 static char *labels[] = {
6074 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6075 };
6076 struct hda_input_mux *imux = &spec->private_imux[0]; 5829 struct hda_input_mux *imux = &spec->private_imux[0];
6077 int i, err, idx = 0; 5830 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
6078 5831 int err;
6079 for (i = 0; i < AUTO_PIN_LAST; i++) {
6080 if (!cfg->input_pins[i])
6081 continue;
6082
6083 switch (cfg->input_pins[i]) {
6084 case 0x2b: /* Mic */
6085 idx = 0;
6086 break;
6087 5832
6088 case 0x2a: /* Line In */ 5833 err = vt_auto_create_analog_input_ctls(spec, cfg, 0x21, pin_idxs,
6089 idx = 1; 5834 ARRAY_SIZE(pin_idxs));
6090 break; 5835 if (err < 0)
5836 return err;
6091 5837
6092 case 0x29: /* Front Mic */
6093 idx = 2;
6094 break;
6095 }
6096 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6097 if (err < 0)
6098 return err;
6099 imux->items[imux->num_items].label = labels[i];
6100 imux->items[imux->num_items].index = idx;
6101 imux->num_items++;
6102 }
6103 /* build volume/mute control of loopback */ 5838 /* build volume/mute control of loopback */
6104 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21); 5839 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6105 if (err < 0) 5840 if (err < 0)
6106 return err; 5841 return err;
6107 5842
6108 /* for internal loopback recording select */
6109 imux->items[imux->num_items].label = "Stereo Mixer";
6110 imux->items[imux->num_items].index = 5;
6111 imux->num_items++;
6112
6113 /* for digital mic select */ 5843 /* for digital mic select */
6114 imux->items[imux->num_items].label = "Digital Mic"; 5844 imux->items[imux->num_items].label = "Digital Mic";
6115 imux->items[imux->num_items].index = 6; 5845 imux->items[imux->num_items].index = 6;