-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhda-int.c
1511 lines (1354 loc) · 36.9 KB
/
hda-int.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* hda-emu - simple HD-audio codec emulator for debugging snd-hda-intel driver
*
* Emulate the communication of HD-audio codec
*
* Copyright (c) Takashi Iwai <[email protected]>
*
* This driver is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This driver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "hda-types.h"
#include "hda-log.h"
#define AC_AMP_GET_LEFT (1<<13)
#define AC_AMP_GET_RIGHT (0<<13)
#define AC_AMP_GET_OUTPUT (1<<15)
#define AC_AMP_GET_INPUT (0<<15)
#define AC_AMP_SET_INDEX (0xf<<8)
#define AC_AMP_SET_INDEX_SHIFT 8
#define AC_AMP_SET_RIGHT (1<<12)
#define AC_AMP_SET_LEFT (1<<13)
#define AC_AMP_SET_INPUT (1<<14)
#define AC_AMP_SET_OUTPUT (1<<15)
/* Audio Widget Capabilities */
#define AC_WCAP_STEREO (1<<0) /* stereo I/O */
#define AC_WCAP_IN_AMP (1<<1) /* AMP-in present */
#define AC_WCAP_OUT_AMP (1<<2) /* AMP-out present */
#define AC_WCAP_AMP_OVRD (1<<3) /* AMP-parameter override */
#define AC_WCAP_FORMAT_OVRD (1<<4) /* format override */
#define AC_WCAP_STRIPE (1<<5) /* stripe */
#define AC_WCAP_PROC_WID (1<<6) /* Proc Widget */
#define AC_WCAP_UNSOL_CAP (1<<7) /* Unsol capable */
#define AC_WCAP_CONN_LIST (1<<8) /* connection list */
#define AC_WCAP_DIGITAL (1<<9) /* digital I/O */
#define AC_WCAP_POWER (1<<10) /* power control */
#define AC_WCAP_LR_SWAP (1<<11) /* L/R swap */
#define AC_WCAP_DELAY (0xf<<16)
#define AC_WCAP_DELAY_SHIFT 16
#define AC_WCAP_TYPE (0xf<<20)
#define AC_WCAP_TYPE_SHIFT 20
/* Pin widget capabilies */
#define AC_PINCAP_IMP_SENSE (1<<0) /* impedance sense capable */
#define AC_PINCAP_TRIG_REQ (1<<1) /* trigger required */
#define AC_PINCAP_PRES_DETECT (1<<2) /* presence detect capable */
#define AC_PINCAP_HP_DRV (1<<3) /* headphone drive capable */
#define AC_PINCAP_OUT (1<<4) /* output capable */
#define AC_PINCAP_IN (1<<5) /* input capable */
#define AC_PINCAP_BALANCE (1<<6) /* balanced I/O capable */
/* Note: This LR_SWAP pincap is defined in the Realtek ALC883 specification,
* but is marked reserved in the Intel HDA specification.
*/
#define AC_PINCAP_LR_SWAP (1<<7) /* L/R swap */
/* Note: The same bit as LR_SWAP is newly defined as HDMI capability
* in HD-audio specification
*/
#define AC_PINCAP_HDMI (1<<7) /* HDMI pin */
#define AC_PINCAP_VREF (0x37<<8)
#define AC_PINCAP_VREF_SHIFT 8
#define AC_PINCAP_EAPD (1<<16) /* EAPD capable */
/* Vref status (used in pin cap) */
#define AC_PINCAP_VREF_HIZ (1<<0) /* Hi-Z */
#define AC_PINCAP_VREF_50 (1<<1) /* 50% */
#define AC_PINCAP_VREF_GRD (1<<2) /* ground */
#define AC_PINCAP_VREF_80 (1<<4) /* 80% */
#define AC_PINCAP_VREF_100 (1<<5) /* 100% */
/* Pin widget control - 8bit */
#define AC_PINCTL_EPT (0x3<<0)
#define AC_PINCTL_EPT_NATIVE 0
#define AC_PINCTL_EPT_HBR 3
#define AC_PINCTL_VREFEN (0x7<<0)
#define AC_PINCTL_VREF_HIZ 0 /* Hi-Z */
#define AC_PINCTL_VREF_50 1 /* 50% */
#define AC_PINCTL_VREF_GRD 2 /* ground */
#define AC_PINCTL_VREF_80 4 /* 80% */
#define AC_PINCTL_VREF_100 5 /* 100% */
#define AC_PINCTL_IN_EN (1<<5)
#define AC_PINCTL_OUT_EN (1<<6)
#define AC_PINCTL_HP_EN (1<<7)
/*
* widget types
*/
enum {
AC_WID_AUD_OUT, /* Audio Out */
AC_WID_AUD_IN, /* Audio In */
AC_WID_AUD_MIX, /* Audio Mixer */
AC_WID_AUD_SEL, /* Audio Selector */
AC_WID_PIN, /* Pin Complex */
AC_WID_POWER, /* Power */
AC_WID_VOL_KNB, /* Volume Knob */
AC_WID_BEEP, /* Beep Generator */
AC_WID_VENDOR = 0x0f /* Vendor specific */
};
/*
*/
static const struct xhda_verb_table *
find_verb(unsigned int verb, const struct xhda_verb_table *tbl)
{
for (; tbl->verb || tbl->func; tbl++)
if (tbl->verb == verb)
return tbl;
return NULL;
}
/*
*/
static int set_stream_format(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->stream_format = cmd & 0xffff;
return 0;
}
static int get_stream_format(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->stream_format;
}
static int set_amp(struct xhda_node *node,
struct xhda_amp_vals *vals, unsigned int idx,
unsigned int ampcap, unsigned int val)
{
unsigned int nsteps = (ampcap >> 8) & 0xff;
unsigned int has_mute = (ampcap >> 31) & 1;
unsigned int ampval;
ampval = val & 0xff;
if ((ampval & ~0x80) > nsteps) {
hda_log(HDA_LOG_ERR, "invalid amp value 0x%x (nsteps = 0x%x), NID=0x%x\n",
ampval, nsteps, node->nid);
ampval = (ampval & 0x80) | (nsteps - 1);
}
if ((ampval & 0x80) && !has_mute) {
hda_log(HDA_LOG_ERR, "turn on non-existing mute, NODE=0x%x\n",
node->nid);
ampval &= ~0x80;
}
if (val & AC_AMP_SET_LEFT)
vals->vals[idx][0] = ampval;
if (val & AC_AMP_SET_RIGHT)
vals->vals[idx][1] = ampval;
return 0;
}
static int par_amp_in_cap(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd);
static int par_amp_out_cap(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd);
static int set_amp_gain_mute(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
unsigned int ampval;
unsigned int idx, type;
if (!node)
return 0;
ampval = cmd & 0xffff;
idx = (ampval & AC_AMP_SET_INDEX) >> AC_AMP_SET_INDEX_SHIFT;
type = (node->wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
if (ampval & AC_AMP_SET_OUTPUT) {
if (!(node->wcaps & AC_WCAP_OUT_AMP))
hda_log(HDA_LOG_ERR, "no output-amp for node 0x%x\n",
node->nid);
if (idx) {
if (type != AC_WID_PIN ||
!codec->pin_amp_workaround) {
hda_log(HDA_LOG_ERR,
"invalid amp index %d for output\n",
idx);
idx = 0;
} else if (idx >= node->num_nodes) {
hda_log(HDA_LOG_ERR,
"invalid pin out-amp index %d "
"(conns=%d)\n",
idx, node->num_nodes);
idx = 0;
}
}
set_amp(node, &node->amp_out_vals, idx,
par_amp_out_cap(codec, node, 0),
ampval);
}
if (ampval & AC_AMP_SET_INPUT) {
if (!(node->wcaps & AC_WCAP_IN_AMP))
hda_log(HDA_LOG_ERR, "no input-amp for node 0x%x\n",
node->nid);
type = (node->wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
if ((type == AC_WID_PIN && idx != 0) ||
(type != AC_WID_PIN && idx >= node->num_nodes)) {
hda_log(HDA_LOG_ERR,
"invalid amp index %d (conns=%d)\n", idx,
node->num_nodes);
idx = 0;
}
set_amp(node, &node->amp_in_vals, idx,
par_amp_in_cap(codec, node, 0),
ampval);
}
return 0;
}
static int get_amp(struct xhda_amp_vals *vals, unsigned int idx,
unsigned int ampval)
{
if (ampval & AC_AMP_GET_LEFT)
return vals->vals[idx][0];
else
return vals->vals[idx][1];
}
static int get_amp_gain_mute(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
unsigned int ampval;
unsigned int idx, type;
if (!node)
return 0;
ampval = cmd & 0xffff;
idx = ampval & 0x1f;
type = (node->wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
if (ampval & AC_AMP_GET_OUTPUT) {
if (!(node->wcaps & AC_WCAP_OUT_AMP))
hda_log(HDA_LOG_ERR, "no output-amp for node 0x%x\n",
node->nid);
if (idx) {
if (type != AC_WID_PIN ||
!codec->pin_amp_workaround) {
hda_log(HDA_LOG_ERR,
"invalid amp index %d for output\n",
idx);
idx = 0;
} else if (idx >= node->num_nodes) {
hda_log(HDA_LOG_ERR,
"invalid pin out-amp index %d "
"(conns=%d)\n",
idx, node->num_nodes);
idx = 0;
}
}
return get_amp(&node->amp_out_vals, idx, ampval);
} else {
if (!(node->wcaps & AC_WCAP_IN_AMP))
hda_log(HDA_LOG_ERR, "no input-amp for node 0x%x\n",
node->nid);
if ((type == AC_WID_PIN && idx != 0) ||
(type != AC_WID_PIN && idx >= node->num_nodes)) {
hda_log(HDA_LOG_ERR,
"invalid amp index %d (conns=%d)\n", idx,
node->num_nodes);
idx = 0;
}
return get_amp(&node->amp_in_vals, idx, ampval);
}
}
static int set_connect_sel(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
unsigned int wid_type;
unsigned int sel;
if (!node)
return 0;
wid_type = (node->wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
if (wid_type == AC_WID_AUD_MIX || wid_type == AC_WID_VOL_KNB) {
hda_log(HDA_LOG_ERR, "invalid connect select for node 0x%x\n",
node->nid);
return 0;
}
sel = cmd & 0xff;
if (sel >= node->num_nodes)
hda_log(HDA_LOG_ERR,
"invalid connection index %d (conns=%d), NID=0x%x\n",
sel, node->num_nodes, node->nid);
else
node->curr_conn = sel;
return 0;
}
static int get_connect_sel(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->curr_conn;
}
static int get_connect_list(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
unsigned int idx, i;
unsigned int val;
if (!node)
return 0;
idx = cmd & 0xff;
if (idx >= node->num_nodes)
return 0;
val = 0;
for (i = 0; i < 4; i++, idx++) {
if (idx >= node->num_nodes)
break;
val |= node->node[idx] << (i * 8);
}
return val;
}
static int set_proc_state(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->proc_state = cmd & 0xff;
return 0;
}
static int get_proc_state(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->proc_state;
}
static int set_power_state(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
if (node->nid != 0x01 &&
!(node->wcaps & AC_WCAP_POWER))
return 0;
node->power_setting = cmd & 0x0f;
node->power_current = node->power_setting;
return 0;
}
static int get_power_state(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->power_setting | (node->power_current << 4);
}
static int set_sdi_select(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->sdi = cmd & 0x0f;
return 0;
}
static int get_sdi_select(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->sdi;
}
static int set_channel_streamid(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
if (!node)
return 0;
node->streamid = cmd & 0xff;
return 0;
}
static int get_channel_streamid(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
if (!node)
return 0;
return node->streamid;
}
void hda_verify_pin_ctl(struct xhda_node *node, int log,
unsigned int *sanified_pinctl)
{
int pinctl = node->pinctl;
/* sanity checks */
if ((node->pinctl & AC_PINCTL_OUT_EN) &&
!(node->pincap & AC_PINCAP_OUT)) {
if (log)
hda_log(HDA_LOG_ERR,
"setting OUT_EN to pin 0x%x without caps\n",
node->nid);
pinctl &= ~AC_PINCTL_OUT_EN;
}
if ((node->pinctl & AC_PINCTL_HP_EN) &&
!(node->pincap & AC_PINCAP_HP_DRV)) {
if (log)
hda_log(HDA_LOG_ERR,
"setting HP_EN to pin 0x%x without caps\n",
node->nid);
pinctl &= ~AC_PINCTL_HP_EN;
}
if ((node->pinctl & AC_PINCTL_IN_EN) &&
!(node->pincap & AC_PINCAP_IN)) {
if (log)
hda_log(HDA_LOG_ERR,
"setting IN_EN to pin 0x%x without caps\n",
node->nid);
pinctl &= ~AC_PINCTL_IN_EN;
}
if (node->pinctl & AC_PINCTL_IN_EN) {
unsigned int cap_set, cap_check;
const char *vref;
switch (node->pinctl & AC_PINCTL_VREFEN) {
case AC_PINCTL_VREF_HIZ:
cap_check = AC_PINCAP_VREF_HIZ;
vref = "HIZ";
break;
case AC_PINCTL_VREF_50:
cap_check = AC_PINCAP_VREF_50;
vref = "50";
break;
case AC_PINCTL_VREF_GRD:
cap_check = AC_PINCAP_VREF_GRD;
vref = "GRD";
break;
case AC_PINCTL_VREF_80:
cap_check = AC_PINCAP_VREF_80;
vref = "80";
break;
case AC_PINCTL_VREF_100:
cap_check = AC_PINCAP_VREF_100;
vref = "100";
break;
default:
cap_check = 0;
break;
}
cap_set = (node->pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
if (!cap_set)
cap_set = AC_PINCAP_VREF_HIZ;
if (cap_check && !(cap_set & cap_check)) {
if (log)
hda_log(HDA_LOG_ERR,
"setting VREF %s to pin 0x%x without caps 0x%x\n",
vref, node->nid, node->pincap);
pinctl &= ~AC_PINCTL_VREFEN;
}
}
if (sanified_pinctl)
*sanified_pinctl = pinctl;
}
static int set_pin_ctl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->pinctl = cmd & 0xff;
hda_verify_pin_ctl(node, 1, NULL);
return 0;
}
static int get_pin_ctl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->pinctl;
}
static int set_unsol_enable(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->unsol = cmd & 0xff;
return 0;
}
static int get_unsol_resp(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid unsol widget");
return 0;
}
return node->unsol;
}
static int exec_pin_sense(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return 0;
}
static int get_pin_sense(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid pin node\n");
return 0;
}
return node->jack_state ? (1 << 31) : 0;
}
static int set_eapd_btl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid EAPD node\n");
return 0;
}
node->eapd = cmd & 0xff;
if ((cmd & 0x02) && !(node->pincap & AC_PINCAP_EAPD))
hda_log(HDA_LOG_ERR, "EAPD command to non-capable pin 0x%x\n",
node->nid);
return 0;
}
static int get_eapd_btl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid EAPD node\n");
return 0;
}
return node->eapd;
}
static int set_digi_cvt_1(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid DIGI1 node\n");
return 0;
}
node->dig_conv = cmd & 0xff;
return 0;
}
static int set_digi_cvt_2(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid DIGI2 node\n");
return 0;
}
node->dig_category = cmd & 0xff;
return 0;
}
static int get_digi_cvt(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node) {
hda_log(HDA_LOG_ERR, "Invalid DIGI node\n");
return 0;
}
return (node->dig_category << 8) | node->dig_conv;
}
static int set_config_def_0(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->pin_default &= ~0xff;
node->pin_default |= (cmd & 0xff);
return 0;
}
static int set_config_def_1(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->pin_default &= ~0xff00;
node->pin_default |= (cmd & 0xff) << 8;
return 0;
}
static int set_config_def_2(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->pin_default &= ~0xff0000;
node->pin_default |= (cmd & 0xff) << 16;
return 0;
}
static int set_config_def_3(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
node->pin_default &= ~0xff000000;
node->pin_default |= (cmd & 0xff) << 24;
return 0;
}
static int get_config_default(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->pin_default;
}
static int get_ssid(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return codec->subsystem_id;
}
static int set_codec_reset(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
hda_log(HDA_LOG_INFO, "CODEC RESET\n");
return 0;
}
static int set_coef_index(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->coef_idx = cmd & 0xffff;
return 0;
}
static int get_coef_index(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->coef_idx;
}
static struct xhda_coef_table *find_proc_coef(struct xhda_node *node,
unsigned int idx)
{
struct xhda_coef_table *tbl;
for (tbl = node->coef_tbl; tbl; tbl = tbl->next) {
if (tbl->idx == idx)
return tbl;
}
return NULL;
}
static struct xhda_coef_table *create_proc_coef(struct xhda_node *node,
unsigned int idx)
{
struct xhda_coef_table *tbl;
tbl = xalloc(sizeof(*tbl));
tbl->idx = idx;
tbl->next = node->coef_tbl;
node->coef_tbl = tbl;
return tbl;
}
static int set_proc_coef(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
struct xhda_coef_table *tbl;
tbl = find_proc_coef(node, node->coef_idx);
if (!tbl) {
tbl = create_proc_coef(node, node->coef_idx);
if (!tbl)
return 0;
}
tbl->value = cmd & 0xffff;
node->coef_idx++;
return 0;
}
static int get_proc_coef(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
struct xhda_coef_table *tbl;
tbl = find_proc_coef(node, node->coef_idx);
node->coef_idx++;
return tbl ? tbl->value : 0;
}
static int set_beep_ctl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->beep_div = cmd & 0xff;
return 0;
}
static int get_beep_ctl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->beep_div;
}
static int set_volknob_ctl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->volknob_ctl = cmd & 0xff;
return 0;
}
static int get_volknob_ctl(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->volknob_ctl;
}
static int set_gpio_data(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->gpio_data = cmd & 0xff;
return 0;
}
static int get_gpio_data(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->gpio_data;
}
static int set_gpio_mask(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->gpio_mask = cmd & 0xff;
return 0;
}
static int get_gpio_mask(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->gpio_mask;
}
static int set_gpio_dir(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->gpio_dir = cmd & 0xff;
return 0;
}
static int get_gpio_dir(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->gpio_dir;
}
static int set_gpio_wake_mask(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->gpio_wake = cmd & 0xff;
return 0;
}
static int get_gpio_wake_mask(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->gpio_wake;
}
static int set_gpio_unsol_rsp(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
node->gpio_unsol = cmd & 0xff;
return 0;
}
static int get_gpio_unsol_rsp(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return node->gpio_unsol;
}
static int set_gpio_sticky_mask(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
node->gpio_sticky = cmd & 0xff;
return 0;
}
static int get_gpio_sticky_mask(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
return node->gpio_sticky;
}
static int set_cvt_channel_count(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
node->cvt_channel_count = cmd & 0xff;
return 0;
}
static int get_cvt_channel_count(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
return node->cvt_channel_count;
}
static int get_asp_channel_slot(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
return (node->asp_channel_slot[cmd & 0xf] << 4) + (cmd & 0xf);
}
static int set_asp_channel_slot(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
node->asp_channel_slot[cmd & 0xf] = (cmd & 0xf0) >> 4;
return 0;
}
static int set_dip_index(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
return 0; /* FIXME */
}
static int set_dip_data(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
return 0; /* FIXME */
}
static int get_dip_size(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
if (cmd & 0x8)
return 128; /* ELD buffer size */
return 32; /* DIP buffer size */
}
static int set_dip_xmitctrl(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
node->dip_xmitctrl = cmd & 0xc0;
return 0;
}
static int get_dip_xmitctrl(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
return node->dip_xmitctrl;
}
/*
* parameters
*/
static int par_vendor_id(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return codec->vendor_id;
}
static int par_subsystem_id(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return codec->subsystem_id;
}
static int par_revision_id(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return codec->revision_id;
}
static int par_node_count(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
unsigned int start_nid;
if (!node)
return codec->num_widgets | (0x01 << 16);
if (!codec->afg.next)
return 0;
start_nid = codec->afg.next->nid;
return (codec->num_widgets - start_nid + 1) | (start_nid << 16);
}
static int par_function_type(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (node) {
if (!codec->function_id && node->nid == 0x01)
return 0x01; /* FIXME */
if (node->nid == codec->afg.nid)
return codec->function_id ? codec->function_id : 0x01;
if (node->nid == codec->mfg.nid)
return codec->modem_function_id ? codec->modem_function_id : 0x02;
}
return 0;
}
static int par_fg_cap(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
return 0; /* FIXME */
}
static int par_audio_widget_cap(struct xhda_codec *codec,
struct xhda_node *node, unsigned int cmd)
{
if (!node)
return 0;
return node->wcaps;
}
static int par_pcm(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->pcm.rates | (node->pcm.bits << 16);
}
static int par_stream(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->pcm.formats;
}
static int par_pin_cap(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->pincap;
}
static int par_amp_cap(struct xhda_amp_caps *node_cap,
struct xhda_amp_caps *afg_cap)
{
if (node_cap->override)
return node_cap->ofs |
(node_cap->nsteps << 8) |
(node_cap->stepsize << 16) |
(node_cap->mute << 31);
else
return afg_cap->ofs |
(afg_cap->nsteps << 8) |
(afg_cap->stepsize << 16) |
(afg_cap->mute << 31);
}
static int par_amp_in_cap(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return par_amp_cap(&node->amp_in_caps, &codec->afg.amp_in_caps);
}
static int par_connlist_len(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
return node->num_nodes;
}
static int par_power_state(struct xhda_codec *codec, struct xhda_node *node,
unsigned int cmd)
{
if (!node)
return 0;
if (node->nid == 0x01)
return 0x0f;
if (node->wcaps & AC_WCAP_POWER)
return 0x0f;
return 0; /* FIXME */
}