2 * HD audio interface patch for Creative CA0132 chip
4 * Copyright (c) 2011, Creative Technology Ltd.
6 * Based on patch_ca0110.c
7 * Copyright (c) 2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/mutex.h>
29 #include <linux/module.h>
30 #include <linux/firmware.h>
31 #include <sound/core.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34 #include "hda_auto_parser.h"
37 #include "ca0132_regs.h"
39 /* Enable this to see controls for tuning purpose. */
40 /*#define ENABLE_TUNING_CONTROLS*/
42 #define FLOAT_ZERO 0x00000000
43 #define FLOAT_ONE 0x3f800000
44 #define FLOAT_TWO 0x40000000
45 #define FLOAT_MINUS_5 0xc0a00000
47 #define UNSOL_TAG_HP 0x10
48 #define UNSOL_TAG_AMIC1 0x12
49 #define UNSOL_TAG_DSP 0x16
51 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18)
52 #define DSP_DMA_WRITE_BUFLEN_OVLY (1UL<<15)
54 #define DMA_TRANSFER_FRAME_SIZE_NWORDS 8
55 #define DMA_TRANSFER_MAX_FRAME_SIZE_NWORDS 32
56 #define DMA_OVERLAY_FRAME_SIZE_NWORDS 2
58 #define MASTERCONTROL 0x80
59 #define MASTERCONTROL_ALLOC_DMA_CHAN 10
60 #define MASTERCONTROL_QUERY_SPEAKER_EQ_ADDRESS 60
62 #define WIDGET_CHIP_CTRL 0x15
63 #define WIDGET_DSP_CTRL 0x16
65 #define MEM_CONNID_MICIN1 3
66 #define MEM_CONNID_MICIN2 5
67 #define MEM_CONNID_MICOUT1 12
68 #define MEM_CONNID_MICOUT2 14
69 #define MEM_CONNID_WUH 10
70 #define MEM_CONNID_DSP 16
71 #define MEM_CONNID_DMIC 100
76 #define EFX_FILE "ctefx.bin"
78 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
79 MODULE_FIRMWARE(EFX_FILE
);
82 static char *dirstr
[2] = { "Playback", "Capture" };
95 #define VNODE_START_NID 0x80
96 VNID_SPK
= VNODE_START_NID
, /* Speaker vnid */
103 #define VNODES_COUNT (VNODE_END_NID - VNODE_START_NID)
105 #define EFFECT_START_NID 0x90
106 #define OUT_EFFECT_START_NID EFFECT_START_NID
107 SURROUND
= OUT_EFFECT_START_NID
,
114 #define OUT_EFFECTS_COUNT (OUT_EFFECT_END_NID - OUT_EFFECT_START_NID)
116 #define IN_EFFECT_START_NID OUT_EFFECT_END_NID
117 ECHO_CANCELLATION
= IN_EFFECT_START_NID
,
122 #define IN_EFFECTS_COUNT (IN_EFFECT_END_NID - IN_EFFECT_START_NID)
124 VOICEFX
= IN_EFFECT_END_NID
,
128 #define EFFECTS_COUNT (EFFECT_END_NID - EFFECT_START_NID)
131 /* Effects values size*/
132 #define EFFECT_VALS_MAX_COUNT 12
134 /* Latency introduced by DSP blocks in milliseconds. */
135 #define DSP_CAPTURE_INIT_LATENCY 0
136 #define DSP_CRYSTAL_VOICE_LATENCY 124
137 #define DSP_PLAYBACK_INIT_LATENCY 13
138 #define DSP_PLAY_ENHANCEMENT_LATENCY 30
139 #define DSP_SPEAKER_OUT_LATENCY 7
142 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
144 int mid
; /*effect module ID*/
145 int reqs
[EFFECT_VALS_MAX_COUNT
]; /*effect module request*/
146 int direct
; /* 0:output; 1:input*/
147 int params
; /* number of default non-on/off params */
148 /*effect default values, 1st is on/off. */
149 unsigned int def_vals
[EFFECT_VALS_MAX_COUNT
];
152 #define EFX_DIR_OUT 0
155 static struct ct_effect ca0132_effects
[EFFECTS_COUNT
] = {
156 { .name
= "Surround",
160 .direct
= EFX_DIR_OUT
,
162 .def_vals
= {0x3F800000, 0x3F2B851F}
164 { .name
= "Crystalizer",
168 .direct
= EFX_DIR_OUT
,
170 .def_vals
= {0x3F800000, 0x3F266666}
172 { .name
= "Dialog Plus",
176 .direct
= EFX_DIR_OUT
,
178 .def_vals
= {0x00000000, 0x3F000000}
180 { .name
= "Smart Volume",
184 .direct
= EFX_DIR_OUT
,
186 .def_vals
= {0x3F800000, 0x3F3D70A4, 0x00000000}
191 .reqs
= {24, 23, 25},
192 .direct
= EFX_DIR_OUT
,
194 .def_vals
= {0x3F800000, 0x42A00000, 0x3F000000}
196 { .name
= "Equalizer",
199 .reqs
= {9, 10, 11, 12, 13, 14,
200 15, 16, 17, 18, 19, 20},
201 .direct
= EFX_DIR_OUT
,
203 .def_vals
= {0x00000000, 0x00000000, 0x00000000, 0x00000000,
204 0x00000000, 0x00000000, 0x00000000, 0x00000000,
205 0x00000000, 0x00000000, 0x00000000, 0x00000000}
207 { .name
= "Echo Cancellation",
208 .nid
= ECHO_CANCELLATION
,
210 .reqs
= {0, 1, 2, 3},
211 .direct
= EFX_DIR_IN
,
213 .def_vals
= {0x00000000, 0x3F3A9692, 0x00000000, 0x00000000}
215 { .name
= "Voice Focus",
218 .reqs
= {6, 7, 8, 9},
219 .direct
= EFX_DIR_IN
,
221 .def_vals
= {0x3F800000, 0x3D7DF3B6, 0x41F00000, 0x41F00000}
227 .direct
= EFX_DIR_IN
,
229 .def_vals
= {0x00000000, 0x3F3D70A4}
231 { .name
= "Noise Reduction",
232 .nid
= NOISE_REDUCTION
,
235 .direct
= EFX_DIR_IN
,
237 .def_vals
= {0x3F800000, 0x3F000000}
242 .reqs
= {10, 11, 12, 13, 14, 15, 16, 17, 18},
243 .direct
= EFX_DIR_IN
,
245 .def_vals
= {0x00000000, 0x43C80000, 0x44AF0000, 0x44FA0000,
246 0x3F800000, 0x3F800000, 0x3F800000, 0x00000000,
251 /* Tuning controls */
252 #ifdef ENABLE_TUNING_CONTROLS
255 #define TUNING_CTL_START_NID 0xC0
256 WEDGE_ANGLE
= TUNING_CTL_START_NID
,
269 #define TUNING_CTLS_COUNT (TUNING_CTL_END_NID - TUNING_CTL_START_NID)
272 struct ct_tuning_ctl
{
273 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
274 hda_nid_t parent_nid
;
276 int mid
; /*effect module ID*/
277 int req
; /*effect module request*/
278 int direct
; /* 0:output; 1:input*/
279 unsigned int def_val
;/*effect default values*/
282 static struct ct_tuning_ctl ca0132_tuning_ctls
[] = {
283 { .name
= "Wedge Angle",
284 .parent_nid
= VOICE_FOCUS
,
288 .direct
= EFX_DIR_IN
,
289 .def_val
= 0x41F00000
291 { .name
= "SVM Level",
292 .parent_nid
= MIC_SVM
,
296 .direct
= EFX_DIR_IN
,
297 .def_val
= 0x3F3D70A4
299 { .name
= "EQ Band0",
300 .parent_nid
= EQUALIZER
,
301 .nid
= EQUALIZER_BAND_0
,
304 .direct
= EFX_DIR_OUT
,
305 .def_val
= 0x00000000
307 { .name
= "EQ Band1",
308 .parent_nid
= EQUALIZER
,
309 .nid
= EQUALIZER_BAND_1
,
312 .direct
= EFX_DIR_OUT
,
313 .def_val
= 0x00000000
315 { .name
= "EQ Band2",
316 .parent_nid
= EQUALIZER
,
317 .nid
= EQUALIZER_BAND_2
,
320 .direct
= EFX_DIR_OUT
,
321 .def_val
= 0x00000000
323 { .name
= "EQ Band3",
324 .parent_nid
= EQUALIZER
,
325 .nid
= EQUALIZER_BAND_3
,
328 .direct
= EFX_DIR_OUT
,
329 .def_val
= 0x00000000
331 { .name
= "EQ Band4",
332 .parent_nid
= EQUALIZER
,
333 .nid
= EQUALIZER_BAND_4
,
336 .direct
= EFX_DIR_OUT
,
337 .def_val
= 0x00000000
339 { .name
= "EQ Band5",
340 .parent_nid
= EQUALIZER
,
341 .nid
= EQUALIZER_BAND_5
,
344 .direct
= EFX_DIR_OUT
,
345 .def_val
= 0x00000000
347 { .name
= "EQ Band6",
348 .parent_nid
= EQUALIZER
,
349 .nid
= EQUALIZER_BAND_6
,
352 .direct
= EFX_DIR_OUT
,
353 .def_val
= 0x00000000
355 { .name
= "EQ Band7",
356 .parent_nid
= EQUALIZER
,
357 .nid
= EQUALIZER_BAND_7
,
360 .direct
= EFX_DIR_OUT
,
361 .def_val
= 0x00000000
363 { .name
= "EQ Band8",
364 .parent_nid
= EQUALIZER
,
365 .nid
= EQUALIZER_BAND_8
,
368 .direct
= EFX_DIR_OUT
,
369 .def_val
= 0x00000000
371 { .name
= "EQ Band9",
372 .parent_nid
= EQUALIZER
,
373 .nid
= EQUALIZER_BAND_9
,
376 .direct
= EFX_DIR_OUT
,
377 .def_val
= 0x00000000
382 /* Voice FX Presets */
383 #define VOICEFX_MAX_PARAM_COUNT 9
389 int reqs
[VOICEFX_MAX_PARAM_COUNT
]; /*effect module request*/
392 struct ct_voicefx_preset
{
393 char *name
; /*preset name*/
394 unsigned int vals
[VOICEFX_MAX_PARAM_COUNT
];
397 static struct ct_voicefx ca0132_voicefx
= {
398 .name
= "VoiceFX Capture Switch",
401 .reqs
= {10, 11, 12, 13, 14, 15, 16, 17, 18}
404 static struct ct_voicefx_preset ca0132_voicefx_presets
[] = {
406 .vals
= { 0x00000000, 0x43C80000, 0x44AF0000,
407 0x44FA0000, 0x3F800000, 0x3F800000,
408 0x3F800000, 0x00000000, 0x00000000 }
410 { .name
= "Female2Male",
411 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
412 0x44FA0000, 0x3F19999A, 0x3F866666,
413 0x3F800000, 0x00000000, 0x00000000 }
415 { .name
= "Male2Female",
416 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
417 0x450AC000, 0x4017AE14, 0x3F6B851F,
418 0x3F800000, 0x00000000, 0x00000000 }
420 { .name
= "ScrappyKid",
421 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
422 0x44FA0000, 0x40400000, 0x3F28F5C3,
423 0x3F800000, 0x00000000, 0x00000000 }
426 .vals
= { 0x3F800000, 0x44324000, 0x44BB8000,
427 0x44E10000, 0x3FB33333, 0x3FB9999A,
428 0x3F800000, 0x3E3A2E43, 0x00000000 }
431 .vals
= { 0x3F800000, 0x43EA0000, 0x44A52000,
432 0x45098000, 0x3F266666, 0x3FC00000,
433 0x3F800000, 0x00000000, 0x00000000 }
436 .vals
= { 0x3F800000, 0x43C70000, 0x44AE6000,
437 0x45193000, 0x3F8E147B, 0x3F75C28F,
438 0x3F800000, 0x00000000, 0x00000000 }
441 .vals
= { 0x3F800000, 0x43930000, 0x44BEE000,
442 0x45007000, 0x3F451EB8, 0x3F7851EC,
443 0x3F800000, 0x00000000, 0x00000000 }
445 { .name
= "AlienBrute",
446 .vals
= { 0x3F800000, 0x43BFC5AC, 0x44B28FDF,
447 0x451F6000, 0x3F266666, 0x3FA7D945,
448 0x3F800000, 0x3CF5C28F, 0x00000000 }
451 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
452 0x44FA0000, 0x3FB2718B, 0x3F800000,
453 0xBC07010E, 0x00000000, 0x00000000 }
456 .vals
= { 0x3F800000, 0x43C20000, 0x44906000,
457 0x44E70000, 0x3F4CCCCD, 0x3F8A3D71,
458 0x3F0A3D71, 0x00000000, 0x00000000 }
461 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
462 0x44FA0000, 0x3F800000, 0x3F800000,
463 0x3E4CCCCD, 0x00000000, 0x00000000 }
465 { .name
= "DeepVoice",
466 .vals
= { 0x3F800000, 0x43A9C5AC, 0x44AA4FDF,
467 0x44FFC000, 0x3EDBB56F, 0x3F99C4CA,
468 0x3F800000, 0x00000000, 0x00000000 }
470 { .name
= "Munchkin",
471 .vals
= { 0x3F800000, 0x43C80000, 0x44AF0000,
472 0x44FA0000, 0x3F800000, 0x3F1A043C,
473 0x3F800000, 0x00000000, 0x00000000 }
477 enum hda_cmd_vendor_io
{
479 VENDOR_DSPIO_SCP_WRITE_DATA_LOW
= 0x000,
480 VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
= 0x100,
482 VENDOR_DSPIO_STATUS
= 0xF01,
483 VENDOR_DSPIO_SCP_POST_READ_DATA
= 0x702,
484 VENDOR_DSPIO_SCP_READ_DATA
= 0xF02,
485 VENDOR_DSPIO_DSP_INIT
= 0x703,
486 VENDOR_DSPIO_SCP_POST_COUNT_QUERY
= 0x704,
487 VENDOR_DSPIO_SCP_READ_COUNT
= 0xF04,
489 /* for ChipIO node */
490 VENDOR_CHIPIO_ADDRESS_LOW
= 0x000,
491 VENDOR_CHIPIO_ADDRESS_HIGH
= 0x100,
492 VENDOR_CHIPIO_STREAM_FORMAT
= 0x200,
493 VENDOR_CHIPIO_DATA_LOW
= 0x300,
494 VENDOR_CHIPIO_DATA_HIGH
= 0x400,
496 VENDOR_CHIPIO_GET_PARAMETER
= 0xF00,
497 VENDOR_CHIPIO_STATUS
= 0xF01,
498 VENDOR_CHIPIO_HIC_POST_READ
= 0x702,
499 VENDOR_CHIPIO_HIC_READ_DATA
= 0xF03,
501 VENDOR_CHIPIO_8051_DATA_WRITE
= 0x707,
502 VENDOR_CHIPIO_8051_DATA_READ
= 0xF07,
504 VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
= 0x70A,
505 VENDOR_CHIPIO_CT_EXTENSIONS_GET
= 0xF0A,
507 VENDOR_CHIPIO_PLL_PMU_WRITE
= 0x70C,
508 VENDOR_CHIPIO_PLL_PMU_READ
= 0xF0C,
509 VENDOR_CHIPIO_8051_ADDRESS_LOW
= 0x70D,
510 VENDOR_CHIPIO_8051_ADDRESS_HIGH
= 0x70E,
511 VENDOR_CHIPIO_FLAG_SET
= 0x70F,
512 VENDOR_CHIPIO_FLAGS_GET
= 0xF0F,
513 VENDOR_CHIPIO_PARAM_SET
= 0x710,
514 VENDOR_CHIPIO_PARAM_GET
= 0xF10,
516 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
= 0x711,
517 VENDOR_CHIPIO_PORT_ALLOC_SET
= 0x712,
518 VENDOR_CHIPIO_PORT_ALLOC_GET
= 0xF12,
519 VENDOR_CHIPIO_PORT_FREE_SET
= 0x713,
521 VENDOR_CHIPIO_PARAM_EX_ID_GET
= 0xF17,
522 VENDOR_CHIPIO_PARAM_EX_ID_SET
= 0x717,
523 VENDOR_CHIPIO_PARAM_EX_VALUE_GET
= 0xF18,
524 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
= 0x718,
526 VENDOR_CHIPIO_DMIC_CTL_SET
= 0x788,
527 VENDOR_CHIPIO_DMIC_CTL_GET
= 0xF88,
528 VENDOR_CHIPIO_DMIC_PIN_SET
= 0x789,
529 VENDOR_CHIPIO_DMIC_PIN_GET
= 0xF89,
530 VENDOR_CHIPIO_DMIC_MCLK_SET
= 0x78A,
531 VENDOR_CHIPIO_DMIC_MCLK_GET
= 0xF8A,
533 VENDOR_CHIPIO_EAPD_SEL_SET
= 0x78D
539 enum control_flag_id
{
540 /* Connection manager stream setup is bypassed/enabled */
541 CONTROL_FLAG_C_MGR
= 0,
542 /* DSP DMA is bypassed/enabled */
543 CONTROL_FLAG_DMA
= 1,
544 /* 8051 'idle' mode is disabled/enabled */
545 CONTROL_FLAG_IDLE_ENABLE
= 2,
546 /* Tracker for the SPDIF-in path is bypassed/enabled */
547 CONTROL_FLAG_TRACKER
= 3,
548 /* DigitalOut to Spdif2Out connection is disabled/enabled */
549 CONTROL_FLAG_SPDIF2OUT
= 4,
550 /* Digital Microphone is disabled/enabled */
551 CONTROL_FLAG_DMIC
= 5,
552 /* ADC_B rate is 48 kHz/96 kHz */
553 CONTROL_FLAG_ADC_B_96KHZ
= 6,
554 /* ADC_C rate is 48 kHz/96 kHz */
555 CONTROL_FLAG_ADC_C_96KHZ
= 7,
556 /* DAC rate is 48 kHz/96 kHz (affects all DACs) */
557 CONTROL_FLAG_DAC_96KHZ
= 8,
558 /* DSP rate is 48 kHz/96 kHz */
559 CONTROL_FLAG_DSP_96KHZ
= 9,
560 /* SRC clock is 98 MHz/196 MHz (196 MHz forces rate to 96 KHz) */
561 CONTROL_FLAG_SRC_CLOCK_196MHZ
= 10,
562 /* SRC rate is 48 kHz/96 kHz (48 kHz disabled when clock is 196 MHz) */
563 CONTROL_FLAG_SRC_RATE_96KHZ
= 11,
564 /* Decode Loop (DSP->SRC->DSP) is disabled/enabled */
565 CONTROL_FLAG_DECODE_LOOP
= 12,
566 /* De-emphasis filter on DAC-1 disabled/enabled */
567 CONTROL_FLAG_DAC1_DEEMPHASIS
= 13,
568 /* De-emphasis filter on DAC-2 disabled/enabled */
569 CONTROL_FLAG_DAC2_DEEMPHASIS
= 14,
570 /* De-emphasis filter on DAC-3 disabled/enabled */
571 CONTROL_FLAG_DAC3_DEEMPHASIS
= 15,
572 /* High-pass filter on ADC_B disabled/enabled */
573 CONTROL_FLAG_ADC_B_HIGH_PASS
= 16,
574 /* High-pass filter on ADC_C disabled/enabled */
575 CONTROL_FLAG_ADC_C_HIGH_PASS
= 17,
576 /* Common mode on Port_A disabled/enabled */
577 CONTROL_FLAG_PORT_A_COMMON_MODE
= 18,
578 /* Common mode on Port_D disabled/enabled */
579 CONTROL_FLAG_PORT_D_COMMON_MODE
= 19,
580 /* Impedance for ramp generator on Port_A 16 Ohm/10K Ohm */
581 CONTROL_FLAG_PORT_A_10KOHM_LOAD
= 20,
582 /* Impedance for ramp generator on Port_D, 16 Ohm/10K Ohm */
583 CONTROL_FLAG_PORT_D_10KOHM_LOAD
= 21,
584 /* ASI rate is 48kHz/96kHz */
585 CONTROL_FLAG_ASI_96KHZ
= 22,
586 /* DAC power settings able to control attached ports no/yes */
587 CONTROL_FLAG_DACS_CONTROL_PORTS
= 23,
588 /* Clock Stop OK reporting is disabled/enabled */
589 CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
= 24,
590 /* Number of control flags */
591 CONTROL_FLAGS_MAX
= (CONTROL_FLAG_CONTROL_STOP_OK_ENABLE
+1)
595 * Control parameter IDs
597 enum control_param_id
{
598 /* 0: None, 1: Mic1In*/
599 CONTROL_PARAM_VIP_SOURCE
= 1,
600 /* 0: force HDA, 1: allow DSP if HDA Spdif1Out stream is idle */
601 CONTROL_PARAM_SPDIF1_SOURCE
= 2,
602 /* Port A output stage gain setting to use when 16 Ohm output
603 * impedance is selected*/
604 CONTROL_PARAM_PORTA_160OHM_GAIN
= 8,
605 /* Port D output stage gain setting to use when 16 Ohm output
606 * impedance is selected*/
607 CONTROL_PARAM_PORTD_160OHM_GAIN
= 10,
611 /* Select stream with the given ID */
612 CONTROL_PARAM_STREAM_ID
= 24,
613 /* Source connection point for the selected stream */
614 CONTROL_PARAM_STREAM_SOURCE_CONN_POINT
= 25,
615 /* Destination connection point for the selected stream */
616 CONTROL_PARAM_STREAM_DEST_CONN_POINT
= 26,
617 /* Number of audio channels in the selected stream */
618 CONTROL_PARAM_STREAMS_CHANNELS
= 27,
619 /*Enable control for the selected stream */
620 CONTROL_PARAM_STREAM_CONTROL
= 28,
622 /* Connection Point Control */
624 /* Select connection point with the given ID */
625 CONTROL_PARAM_CONN_POINT_ID
= 29,
626 /* Connection point sample rate */
627 CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
= 30,
631 /* Select HDA node with the given ID */
632 CONTROL_PARAM_NODE_ID
= 31
636 * Dsp Io Status codes
638 enum hda_vendor_status_dspio
{
640 VENDOR_STATUS_DSPIO_OK
= 0x00,
641 /* Busy, unable to accept new command, the host must retry */
642 VENDOR_STATUS_DSPIO_BUSY
= 0x01,
643 /* SCP command queue is full */
644 VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
= 0x02,
645 /* SCP response queue is empty */
646 VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
= 0x03
650 * Chip Io Status codes
652 enum hda_vendor_status_chipio
{
654 VENDOR_STATUS_CHIPIO_OK
= 0x00,
655 /* Busy, unable to accept new command, the host must retry */
656 VENDOR_STATUS_CHIPIO_BUSY
= 0x01
662 enum ca0132_sample_rate
{
682 SR_RATE_UNKNOWN
= 0x1F
685 enum dsp_download_state
{
686 DSP_DOWNLOAD_FAILED
= -1,
687 DSP_DOWNLOAD_INIT
= 0,
692 /* retrieve parameters from hda format */
693 #define get_hdafmt_chs(fmt) (fmt & 0xf)
694 #define get_hdafmt_bits(fmt) ((fmt >> 4) & 0x7)
695 #define get_hdafmt_rate(fmt) ((fmt >> 8) & 0x7f)
696 #define get_hdafmt_type(fmt) ((fmt >> 15) & 0x1)
703 struct snd_kcontrol_new
*mixers
[5];
704 unsigned int num_mixers
;
705 const struct hda_verb
*base_init_verbs
;
706 const struct hda_verb
*base_exit_verbs
;
707 const struct hda_verb
*init_verbs
[5];
708 unsigned int num_init_verbs
; /* exclude base init verbs */
709 struct auto_pin_cfg autocfg
;
711 /* Nodes configurations */
712 struct hda_multi_out multiout
;
713 hda_nid_t out_pins
[AUTO_CFG_MAX_OUTS
];
714 hda_nid_t dacs
[AUTO_CFG_MAX_OUTS
];
715 unsigned int num_outputs
;
716 hda_nid_t input_pins
[AUTO_PIN_LAST
];
717 hda_nid_t adcs
[AUTO_PIN_LAST
];
720 unsigned int num_inputs
;
721 hda_nid_t shared_mic_nid
;
722 hda_nid_t shared_out_nid
;
723 struct hda_pcm pcm_rec
[5]; /* PCM information */
726 struct mutex chipio_mutex
; /* chip access mutex */
729 /* DSP download related */
730 enum dsp_download_state dsp_state
;
731 unsigned int dsp_stream_id
;
732 unsigned int wait_scp
;
733 unsigned int wait_scp_header
;
734 unsigned int wait_num_data
;
735 unsigned int scp_resp_header
;
736 unsigned int scp_resp_data
[4];
737 unsigned int scp_resp_count
;
739 /* mixer and effects related */
740 unsigned char dmic_ctl
;
743 long vnode_lvol
[VNODES_COUNT
];
744 long vnode_rvol
[VNODES_COUNT
];
745 long vnode_lswitch
[VNODES_COUNT
];
746 long vnode_rswitch
[VNODES_COUNT
];
747 long effects_switch
[EFFECTS_COUNT
];
751 struct hda_codec
*codec
;
752 struct delayed_work unsol_hp_work
;
754 #ifdef ENABLE_TUNING_CONTROLS
755 long cur_ctl_vals
[TUNING_CTLS_COUNT
];
760 * CA0132 codec access
762 unsigned int codec_send_command(struct hda_codec
*codec
, hda_nid_t nid
,
763 unsigned int verb
, unsigned int parm
, unsigned int *res
)
765 unsigned int response
;
766 response
= snd_hda_codec_read(codec
, nid
, 0, verb
, parm
);
769 return ((response
== -1) ? -1 : 0);
772 static int codec_set_converter_format(struct hda_codec
*codec
, hda_nid_t nid
,
773 unsigned short converter_format
, unsigned int *res
)
775 return codec_send_command(codec
, nid
, VENDOR_CHIPIO_STREAM_FORMAT
,
776 converter_format
& 0xffff, res
);
779 static int codec_set_converter_stream_channel(struct hda_codec
*codec
,
780 hda_nid_t nid
, unsigned char stream
,
781 unsigned char channel
, unsigned int *res
)
783 unsigned char converter_stream_channel
= 0;
785 converter_stream_channel
= (stream
<< 4) | (channel
& 0x0f);
786 return codec_send_command(codec
, nid
, AC_VERB_SET_CHANNEL_STREAMID
,
787 converter_stream_channel
, res
);
790 /* Chip access helper function */
791 static int chipio_send(struct hda_codec
*codec
,
796 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
798 /* send bits of data specified by reg */
800 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
802 if (res
== VENDOR_STATUS_CHIPIO_OK
)
805 } while (time_before(jiffies
, timeout
));
811 * Write chip address through the vendor widget -- NOT protected by the Mutex!
813 static int chipio_write_address(struct hda_codec
*codec
,
814 unsigned int chip_addx
)
816 struct ca0132_spec
*spec
= codec
->spec
;
819 if (spec
->curr_chip_addx
== chip_addx
)
822 /* send low 16 bits of the address */
823 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_LOW
,
827 /* send high 16 bits of the address */
828 res
= chipio_send(codec
, VENDOR_CHIPIO_ADDRESS_HIGH
,
832 spec
->curr_chip_addx
= (res
< 0) ? ~0UL : chip_addx
;
838 * Write data through the vendor widget -- NOT protected by the Mutex!
840 static int chipio_write_data(struct hda_codec
*codec
, unsigned int data
)
842 struct ca0132_spec
*spec
= codec
->spec
;
845 /* send low 16 bits of the data */
846 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_LOW
, data
& 0xffff);
849 /* send high 16 bits of the data */
850 res
= chipio_send(codec
, VENDOR_CHIPIO_DATA_HIGH
,
854 /*If no error encountered, automatically increment the address
855 as per chip behaviour*/
856 spec
->curr_chip_addx
= (res
!= -EIO
) ?
857 (spec
->curr_chip_addx
+ 4) : ~0UL;
862 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
864 static int chipio_write_data_multiple(struct hda_codec
*codec
,
871 snd_printdd(KERN_ERR
"chipio_write_data null ptr\n");
875 while ((count
-- != 0) && (status
== 0))
876 status
= chipio_write_data(codec
, *data
++);
883 * Read data through the vendor widget -- NOT protected by the Mutex!
885 static int chipio_read_data(struct hda_codec
*codec
, unsigned int *data
)
887 struct ca0132_spec
*spec
= codec
->spec
;
891 res
= chipio_send(codec
, VENDOR_CHIPIO_HIC_POST_READ
, 0);
895 res
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
900 *data
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
901 VENDOR_CHIPIO_HIC_READ_DATA
,
905 /*If no error encountered, automatically increment the address
906 as per chip behaviour*/
907 spec
->curr_chip_addx
= (res
!= -EIO
) ?
908 (spec
->curr_chip_addx
+ 4) : ~0UL;
913 * Write given value to the given address through the chip I/O widget.
914 * protected by the Mutex
916 static int chipio_write(struct hda_codec
*codec
,
917 unsigned int chip_addx
, const unsigned int data
)
919 struct ca0132_spec
*spec
= codec
->spec
;
922 mutex_lock(&spec
->chipio_mutex
);
924 /* write the address, and if successful proceed to write data */
925 err
= chipio_write_address(codec
, chip_addx
);
929 err
= chipio_write_data(codec
, data
);
934 mutex_unlock(&spec
->chipio_mutex
);
939 * Write multiple values to the given address through the chip I/O widget.
940 * protected by the Mutex
942 static int chipio_write_multiple(struct hda_codec
*codec
,
947 struct ca0132_spec
*spec
= codec
->spec
;
950 mutex_lock(&spec
->chipio_mutex
);
951 status
= chipio_write_address(codec
, chip_addx
);
955 status
= chipio_write_data_multiple(codec
, data
, count
);
957 mutex_unlock(&spec
->chipio_mutex
);
963 * Read the given address through the chip I/O widget
964 * protected by the Mutex
966 static int chipio_read(struct hda_codec
*codec
,
967 unsigned int chip_addx
, unsigned int *data
)
969 struct ca0132_spec
*spec
= codec
->spec
;
972 mutex_lock(&spec
->chipio_mutex
);
974 /* write the address, and if successful proceed to write data */
975 err
= chipio_write_address(codec
, chip_addx
);
979 err
= chipio_read_data(codec
, data
);
984 mutex_unlock(&spec
->chipio_mutex
);
989 * Set chip control flags through the chip I/O widget.
991 static void chipio_set_control_flag(struct hda_codec
*codec
,
992 enum control_flag_id flag_id
,
996 unsigned int flag_bit
;
998 flag_bit
= (flag_state
? 1 : 0);
999 val
= (flag_bit
<< 7) | (flag_id
);
1000 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1001 VENDOR_CHIPIO_FLAG_SET
, val
);
1005 * Set chip parameters through the chip I/O widget.
1007 static void chipio_set_control_param(struct hda_codec
*codec
,
1008 enum control_param_id param_id
, int param_val
)
1010 struct ca0132_spec
*spec
= codec
->spec
;
1013 if ((param_id
< 32) && (param_val
< 8)) {
1014 val
= (param_val
<< 5) | (param_id
);
1015 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1016 VENDOR_CHIPIO_PARAM_SET
, val
);
1018 mutex_lock(&spec
->chipio_mutex
);
1019 if (chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0) == 0) {
1020 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1021 VENDOR_CHIPIO_PARAM_EX_ID_SET
,
1023 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1024 VENDOR_CHIPIO_PARAM_EX_VALUE_SET
,
1027 mutex_unlock(&spec
->chipio_mutex
);
1032 * Set sampling rate of the connection point.
1034 static void chipio_set_conn_rate(struct hda_codec
*codec
,
1035 int connid
, enum ca0132_sample_rate rate
)
1037 chipio_set_control_param(codec
, CONTROL_PARAM_CONN_POINT_ID
, connid
);
1038 chipio_set_control_param(codec
, CONTROL_PARAM_CONN_POINT_SAMPLE_RATE
,
1045 static void chipio_enable_clocks(struct hda_codec
*codec
)
1047 struct ca0132_spec
*spec
= codec
->spec
;
1049 mutex_lock(&spec
->chipio_mutex
);
1050 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1051 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0);
1052 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1053 VENDOR_CHIPIO_PLL_PMU_WRITE
, 0xff);
1054 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1055 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 5);
1056 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1057 VENDOR_CHIPIO_PLL_PMU_WRITE
, 0x0b);
1058 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1059 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 6);
1060 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1061 VENDOR_CHIPIO_PLL_PMU_WRITE
, 0xff);
1062 mutex_unlock(&spec
->chipio_mutex
);
1066 * CA0132 DSP IO stuffs
1068 static int dspio_send(struct hda_codec
*codec
, unsigned int reg
,
1072 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1074 /* send bits of data specified by reg to dsp */
1076 res
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0, reg
, data
);
1077 if ((res
>= 0) && (res
!= VENDOR_STATUS_DSPIO_BUSY
))
1080 } while (time_before(jiffies
, timeout
));
1086 * Wait for DSP to be ready for commands
1088 static void dspio_write_wait(struct hda_codec
*codec
)
1091 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1094 status
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
1095 VENDOR_DSPIO_STATUS
, 0);
1096 if ((status
== VENDOR_STATUS_DSPIO_OK
) ||
1097 (status
== VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
))
1100 } while (time_before(jiffies
, timeout
));
1104 * Write SCP data to DSP
1106 static int dspio_write(struct hda_codec
*codec
, unsigned int scp_data
)
1108 struct ca0132_spec
*spec
= codec
->spec
;
1111 dspio_write_wait(codec
);
1113 mutex_lock(&spec
->chipio_mutex
);
1114 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_WRITE_DATA_LOW
,
1119 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_WRITE_DATA_HIGH
,
1124 /* OK, now check if the write itself has executed*/
1125 status
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
1126 VENDOR_DSPIO_STATUS
, 0);
1128 mutex_unlock(&spec
->chipio_mutex
);
1130 return (status
== VENDOR_STATUS_DSPIO_SCP_COMMAND_QUEUE_FULL
) ?
1135 * Write multiple SCP data to DSP
1137 static int dspio_write_multiple(struct hda_codec
*codec
,
1138 unsigned int *buffer
, unsigned int size
)
1143 if ((buffer
== NULL
))
1147 while (count
< size
) {
1148 status
= dspio_write(codec
, *buffer
++);
1157 static int dspio_read(struct hda_codec
*codec
, unsigned int *data
)
1161 status
= dspio_send(codec
, VENDOR_DSPIO_SCP_POST_READ_DATA
, 0);
1165 status
= dspio_send(codec
, VENDOR_DSPIO_STATUS
, 0);
1166 if (status
== -EIO
||
1167 status
== VENDOR_STATUS_DSPIO_SCP_RESPONSE_QUEUE_EMPTY
)
1170 *data
= snd_hda_codec_read(codec
, WIDGET_DSP_CTRL
, 0,
1171 VENDOR_DSPIO_SCP_READ_DATA
, 0);
1176 static int dspio_read_multiple(struct hda_codec
*codec
, unsigned int *buffer
,
1177 unsigned int *buf_size
, unsigned int size_count
)
1180 unsigned int size
= *buf_size
;
1182 unsigned int skip_count
;
1185 if ((buffer
== NULL
))
1189 while (count
< size
&& count
< size_count
) {
1190 status
= dspio_read(codec
, buffer
++);
1198 while (skip_count
< size
) {
1199 status
= dspio_read(codec
, &dummy
);
1211 * Construct the SCP header using corresponding fields
1213 static inline unsigned int
1214 make_scp_header(unsigned int target_id
, unsigned int source_id
,
1215 unsigned int get_flag
, unsigned int req
,
1216 unsigned int device_flag
, unsigned int resp_flag
,
1217 unsigned int error_flag
, unsigned int data_size
)
1219 unsigned int header
= 0;
1221 header
= (data_size
& 0x1f) << 27;
1222 header
|= (error_flag
& 0x01) << 26;
1223 header
|= (resp_flag
& 0x01) << 25;
1224 header
|= (device_flag
& 0x01) << 24;
1225 header
|= (req
& 0x7f) << 17;
1226 header
|= (get_flag
& 0x01) << 16;
1227 header
|= (source_id
& 0xff) << 8;
1228 header
|= target_id
& 0xff;
1234 * Extract corresponding fields from SCP header
1237 extract_scp_header(unsigned int header
,
1238 unsigned int *target_id
, unsigned int *source_id
,
1239 unsigned int *get_flag
, unsigned int *req
,
1240 unsigned int *device_flag
, unsigned int *resp_flag
,
1241 unsigned int *error_flag
, unsigned int *data_size
)
1244 *data_size
= (header
>> 27) & 0x1f;
1246 *error_flag
= (header
>> 26) & 0x01;
1248 *resp_flag
= (header
>> 25) & 0x01;
1250 *device_flag
= (header
>> 24) & 0x01;
1252 *req
= (header
>> 17) & 0x7f;
1254 *get_flag
= (header
>> 16) & 0x01;
1256 *source_id
= (header
>> 8) & 0xff;
1258 *target_id
= header
& 0xff;
1261 #define SCP_MAX_DATA_WORDS (16)
1263 /* Structure to contain any SCP message */
1266 unsigned int data
[SCP_MAX_DATA_WORDS
];
1269 static void dspio_clear_response_queue(struct hda_codec
*codec
)
1271 unsigned int dummy
= 0;
1274 /* clear all from the response queue */
1276 status
= dspio_read(codec
, &dummy
);
1277 } while (status
== 0);
1280 static int dspio_get_response_data(struct hda_codec
*codec
)
1282 struct ca0132_spec
*spec
= codec
->spec
;
1283 unsigned int data
= 0;
1286 if (dspio_read(codec
, &data
) < 0)
1289 if ((data
& 0x00ffffff) == spec
->wait_scp_header
) {
1290 spec
->scp_resp_header
= data
;
1291 spec
->scp_resp_count
= data
>> 27;
1292 count
= spec
->wait_num_data
;
1293 dspio_read_multiple(codec
, spec
->scp_resp_data
,
1294 &spec
->scp_resp_count
, count
);
1302 * Send SCP message to DSP
1304 static int dspio_send_scp_message(struct hda_codec
*codec
,
1305 unsigned char *send_buf
,
1306 unsigned int send_buf_size
,
1307 unsigned char *return_buf
,
1308 unsigned int return_buf_size
,
1309 unsigned int *bytes_returned
)
1311 struct ca0132_spec
*spec
= codec
->spec
;
1313 unsigned int scp_send_size
= 0;
1314 unsigned int total_size
;
1315 bool waiting_for_resp
= false;
1316 unsigned int header
;
1317 struct scp_msg
*ret_msg
;
1318 unsigned int resp_src_id
, resp_target_id
;
1319 unsigned int data_size
, src_id
, target_id
, get_flag
, device_flag
;
1322 *bytes_returned
= 0;
1324 /* get scp header from buffer */
1325 header
= *((unsigned int *)send_buf
);
1326 extract_scp_header(header
, &target_id
, &src_id
, &get_flag
, NULL
,
1327 &device_flag
, NULL
, NULL
, &data_size
);
1328 scp_send_size
= data_size
+ 1;
1329 total_size
= (scp_send_size
* 4);
1331 if (send_buf_size
< total_size
)
1334 if (get_flag
|| device_flag
) {
1335 if (!return_buf
|| return_buf_size
< 4 || !bytes_returned
)
1338 spec
->wait_scp_header
= *((unsigned int *)send_buf
);
1340 /* swap source id with target id */
1341 resp_target_id
= src_id
;
1342 resp_src_id
= target_id
;
1343 spec
->wait_scp_header
&= 0xffff0000;
1344 spec
->wait_scp_header
|= (resp_src_id
<< 8) | (resp_target_id
);
1345 spec
->wait_num_data
= return_buf_size
/sizeof(unsigned int) - 1;
1347 waiting_for_resp
= true;
1350 status
= dspio_write_multiple(codec
, (unsigned int *)send_buf
,
1357 if (waiting_for_resp
) {
1358 unsigned long timeout
= jiffies
+ msecs_to_jiffies(1000);
1359 memset(return_buf
, 0, return_buf_size
);
1362 } while (spec
->wait_scp
&& time_before(jiffies
, timeout
));
1363 waiting_for_resp
= false;
1364 if (!spec
->wait_scp
) {
1365 ret_msg
= (struct scp_msg
*)return_buf
;
1366 memcpy(&ret_msg
->hdr
, &spec
->scp_resp_header
, 4);
1367 memcpy(&ret_msg
->data
, spec
->scp_resp_data
,
1368 spec
->wait_num_data
);
1369 *bytes_returned
= (spec
->scp_resp_count
+ 1) * 4;
1381 * Prepare and send the SCP message to DSP
1382 * @codec: the HDA codec
1383 * @mod_id: ID of the DSP module to send the command
1384 * @req: ID of request to send to the DSP module
1386 * @data: pointer to the data to send with the request, request specific
1387 * @len: length of the data, in bytes
1388 * @reply: point to the buffer to hold data returned for a reply
1389 * @reply_len: length of the reply buffer returned from GET
1391 * Returns zero or a negative error code.
1393 static int dspio_scp(struct hda_codec
*codec
,
1394 int mod_id
, int req
, int dir
, void *data
, unsigned int len
,
1395 void *reply
, unsigned int *reply_len
)
1398 struct scp_msg scp_send
, scp_reply
;
1399 unsigned int ret_bytes
, send_size
, ret_size
;
1400 unsigned int send_get_flag
, reply_resp_flag
, reply_error_flag
;
1401 unsigned int reply_data_size
;
1403 memset(&scp_send
, 0, sizeof(scp_send
));
1404 memset(&scp_reply
, 0, sizeof(scp_reply
));
1406 if ((len
!= 0 && data
== NULL
) || (len
> SCP_MAX_DATA_WORDS
))
1409 if (dir
== SCP_GET
&& reply
== NULL
) {
1410 snd_printdd(KERN_ERR
"dspio_scp get but has no buffer\n");
1414 if (reply
!= NULL
&& (reply_len
== NULL
|| (*reply_len
== 0))) {
1415 snd_printdd(KERN_ERR
"dspio_scp bad resp buf len parms\n");
1419 scp_send
.hdr
= make_scp_header(mod_id
, 0x20, (dir
== SCP_GET
), req
,
1420 0, 0, 0, len
/sizeof(unsigned int));
1421 if (data
!= NULL
&& len
> 0) {
1422 len
= min((unsigned int)(sizeof(scp_send
.data
)), len
);
1423 memcpy(scp_send
.data
, data
, len
);
1427 send_size
= sizeof(unsigned int) + len
;
1428 status
= dspio_send_scp_message(codec
, (unsigned char *)&scp_send
,
1429 send_size
, (unsigned char *)&scp_reply
,
1430 sizeof(scp_reply
), &ret_bytes
);
1433 snd_printdd(KERN_ERR
"dspio_scp: send scp msg failed\n");
1437 /* extract send and reply headers members */
1438 extract_scp_header(scp_send
.hdr
, NULL
, NULL
, &send_get_flag
,
1439 NULL
, NULL
, NULL
, NULL
, NULL
);
1440 extract_scp_header(scp_reply
.hdr
, NULL
, NULL
, NULL
, NULL
, NULL
,
1441 &reply_resp_flag
, &reply_error_flag
,
1447 if (reply_resp_flag
&& !reply_error_flag
) {
1448 ret_size
= (ret_bytes
- sizeof(scp_reply
.hdr
))
1449 / sizeof(unsigned int);
1451 if (*reply_len
< ret_size
*sizeof(unsigned int)) {
1452 snd_printdd(KERN_ERR
"reply too long for buf\n");
1454 } else if (ret_size
!= reply_data_size
) {
1455 snd_printdd(KERN_ERR
"RetLen and HdrLen .NE.\n");
1458 *reply_len
= ret_size
*sizeof(unsigned int);
1459 memcpy(reply
, scp_reply
.data
, *reply_len
);
1462 snd_printdd(KERN_ERR
"reply ill-formed or errflag set\n");
1470 * Set DSP parameters
1472 static int dspio_set_param(struct hda_codec
*codec
, int mod_id
,
1473 int req
, void *data
, unsigned int len
)
1475 return dspio_scp(codec
, mod_id
, req
, SCP_SET
, data
, len
, NULL
, NULL
);
1478 static int dspio_set_uint_param(struct hda_codec
*codec
, int mod_id
,
1479 int req
, unsigned int data
)
1481 return dspio_set_param(codec
, mod_id
, req
, &data
, sizeof(unsigned int));
1485 * Allocate a DSP DMA channel via an SCP message
1487 static int dspio_alloc_dma_chan(struct hda_codec
*codec
, unsigned int *dma_chan
)
1490 unsigned int size
= sizeof(dma_chan
);
1492 snd_printdd(KERN_INFO
" dspio_alloc_dma_chan() -- begin\n");
1493 status
= dspio_scp(codec
, MASTERCONTROL
, MASTERCONTROL_ALLOC_DMA_CHAN
,
1494 SCP_GET
, NULL
, 0, dma_chan
, &size
);
1497 snd_printdd(KERN_INFO
"dspio_alloc_dma_chan: SCP Failed\n");
1501 if ((*dma_chan
+ 1) == 0) {
1502 snd_printdd(KERN_INFO
"no free dma channels to allocate\n");
1506 snd_printdd("dspio_alloc_dma_chan: chan=%d\n", *dma_chan
);
1507 snd_printdd(KERN_INFO
" dspio_alloc_dma_chan() -- complete\n");
1513 * Free a DSP DMA via an SCP message
1515 static int dspio_free_dma_chan(struct hda_codec
*codec
, unsigned int dma_chan
)
1518 unsigned int dummy
= 0;
1520 snd_printdd(KERN_INFO
" dspio_free_dma_chan() -- begin\n");
1521 snd_printdd("dspio_free_dma_chan: chan=%d\n", dma_chan
);
1523 status
= dspio_scp(codec
, MASTERCONTROL
, MASTERCONTROL_ALLOC_DMA_CHAN
,
1524 SCP_SET
, &dma_chan
, sizeof(dma_chan
), NULL
, &dummy
);
1527 snd_printdd(KERN_INFO
"dspio_free_dma_chan: SCP Failed\n");
1531 snd_printdd(KERN_INFO
" dspio_free_dma_chan() -- complete\n");
1539 static int dsp_set_run_state(struct hda_codec
*codec
)
1541 unsigned int dbg_ctrl_reg
;
1542 unsigned int halt_state
;
1545 err
= chipio_read(codec
, DSP_DBGCNTL_INST_OFFSET
, &dbg_ctrl_reg
);
1549 halt_state
= (dbg_ctrl_reg
& DSP_DBGCNTL_STATE_MASK
) >>
1550 DSP_DBGCNTL_STATE_LOBIT
;
1552 if (halt_state
!= 0) {
1553 dbg_ctrl_reg
&= ~((halt_state
<< DSP_DBGCNTL_SS_LOBIT
) &
1554 DSP_DBGCNTL_SS_MASK
);
1555 err
= chipio_write(codec
, DSP_DBGCNTL_INST_OFFSET
,
1560 dbg_ctrl_reg
|= (halt_state
<< DSP_DBGCNTL_EXEC_LOBIT
) &
1561 DSP_DBGCNTL_EXEC_MASK
;
1562 err
= chipio_write(codec
, DSP_DBGCNTL_INST_OFFSET
,
1574 static int dsp_reset(struct hda_codec
*codec
)
1579 snd_printdd("dsp_reset\n");
1581 res
= dspio_send(codec
, VENDOR_DSPIO_DSP_INIT
, 0);
1583 } while (res
== -EIO
&& retry
);
1586 snd_printdd("dsp_reset timeout\n");
1594 * Convert chip address to DSP address
1596 static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx
,
1597 bool *code
, bool *yram
)
1599 *code
= *yram
= false;
1601 if (UC_RANGE(chip_addx
, 1)) {
1603 return UC_OFF(chip_addx
);
1604 } else if (X_RANGE_ALL(chip_addx
, 1)) {
1605 return X_OFF(chip_addx
);
1606 } else if (Y_RANGE_ALL(chip_addx
, 1)) {
1608 return Y_OFF(chip_addx
);
1611 return INVALID_CHIP_ADDRESS
;
1615 * Check if the DSP DMA is active
1617 static bool dsp_is_dma_active(struct hda_codec
*codec
, unsigned int dma_chan
)
1619 unsigned int dma_chnlstart_reg
;
1621 chipio_read(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
, &dma_chnlstart_reg
);
1623 return ((dma_chnlstart_reg
& (1 <<
1624 (DSPDMAC_CHNLSTART_EN_LOBIT
+ dma_chan
))) != 0);
1627 static int dsp_dma_setup_common(struct hda_codec
*codec
,
1628 unsigned int chip_addx
,
1629 unsigned int dma_chan
,
1630 unsigned int port_map_mask
,
1634 unsigned int chnl_prop
;
1635 unsigned int dsp_addx
;
1636 unsigned int active
;
1639 snd_printdd(KERN_INFO
"-- dsp_dma_setup_common() -- Begin ---------\n");
1641 if (dma_chan
>= DSPDMAC_DMA_CFG_CHANNEL_COUNT
) {
1642 snd_printdd(KERN_ERR
"dma chan num invalid\n");
1646 if (dsp_is_dma_active(codec
, dma_chan
)) {
1647 snd_printdd(KERN_ERR
"dma already active\n");
1651 dsp_addx
= dsp_chip_to_dsp_addx(chip_addx
, &code
, &yram
);
1653 if (dsp_addx
== INVALID_CHIP_ADDRESS
) {
1654 snd_printdd(KERN_ERR
"invalid chip addr\n");
1658 chnl_prop
= DSPDMAC_CHNLPROP_AC_MASK
;
1661 snd_printdd(KERN_INFO
" dsp_dma_setup_common() start reg pgm\n");
1664 status
= chipio_read(codec
, DSPDMAC_CHNLPROP_INST_OFFSET
,
1668 snd_printdd(KERN_ERR
"read CHNLPROP Reg fail\n");
1671 snd_printdd(KERN_INFO
"dsp_dma_setup_common() Read CHNLPROP\n");
1675 chnl_prop
&= ~(1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT
+ dma_chan
));
1677 chnl_prop
|= (1 << (DSPDMAC_CHNLPROP_MSPCE_LOBIT
+ dma_chan
));
1679 chnl_prop
&= ~(1 << (DSPDMAC_CHNLPROP_DCON_LOBIT
+ dma_chan
));
1681 status
= chipio_write(codec
, DSPDMAC_CHNLPROP_INST_OFFSET
, chnl_prop
);
1683 snd_printdd(KERN_ERR
"write CHNLPROP Reg fail\n");
1686 snd_printdd(KERN_INFO
" dsp_dma_setup_common() Write CHNLPROP\n");
1689 status
= chipio_read(codec
, DSPDMAC_ACTIVE_INST_OFFSET
,
1693 snd_printdd(KERN_ERR
"read ACTIVE Reg fail\n");
1696 snd_printdd(KERN_INFO
"dsp_dma_setup_common() Read ACTIVE\n");
1699 active
&= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT
+ dma_chan
))) &
1700 DSPDMAC_ACTIVE_AAR_MASK
;
1702 status
= chipio_write(codec
, DSPDMAC_ACTIVE_INST_OFFSET
, active
);
1704 snd_printdd(KERN_ERR
"write ACTIVE Reg fail\n");
1708 snd_printdd(KERN_INFO
" dsp_dma_setup_common() Write ACTIVE\n");
1710 status
= chipio_write(codec
, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan
),
1713 snd_printdd(KERN_ERR
"write AUDCHSEL Reg fail\n");
1716 snd_printdd(KERN_INFO
" dsp_dma_setup_common() Write AUDCHSEL\n");
1718 status
= chipio_write(codec
, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan
),
1719 DSPDMAC_IRQCNT_BICNT_MASK
| DSPDMAC_IRQCNT_CICNT_MASK
);
1721 snd_printdd(KERN_ERR
"write IRQCNT Reg fail\n");
1724 snd_printdd(KERN_INFO
" dsp_dma_setup_common() Write IRQCNT\n");
1727 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
1728 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
1729 chip_addx
, dsp_addx
, dma_chan
,
1730 port_map_mask
, chnl_prop
, active
);
1732 snd_printdd(KERN_INFO
"-- dsp_dma_setup_common() -- Complete ------\n");
1738 * Setup the DSP DMA per-transfer-specific registers
1740 static int dsp_dma_setup(struct hda_codec
*codec
,
1741 unsigned int chip_addx
,
1743 unsigned int dma_chan
)
1747 unsigned int dsp_addx
;
1748 unsigned int addr_field
;
1749 unsigned int incr_field
;
1750 unsigned int base_cnt
;
1751 unsigned int cur_cnt
;
1752 unsigned int dma_cfg
= 0;
1753 unsigned int adr_ofs
= 0;
1754 unsigned int xfr_cnt
= 0;
1755 const unsigned int max_dma_count
= 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT
-
1756 DSPDMAC_XFRCNT_BCNT_LOBIT
+ 1);
1758 snd_printdd(KERN_INFO
"-- dsp_dma_setup() -- Begin ---------\n");
1760 if (count
> max_dma_count
) {
1761 snd_printdd(KERN_ERR
"count too big\n");
1765 dsp_addx
= dsp_chip_to_dsp_addx(chip_addx
, &code
, &yram
);
1766 if (dsp_addx
== INVALID_CHIP_ADDRESS
) {
1767 snd_printdd(KERN_ERR
"invalid chip addr\n");
1771 snd_printdd(KERN_INFO
" dsp_dma_setup() start reg pgm\n");
1773 addr_field
= dsp_addx
<< DSPDMAC_DMACFG_DBADR_LOBIT
;
1779 addr_field
|= (1 << DSPDMAC_DMACFG_DBADR_LOBIT
);
1781 incr_field
= (1 << DSPDMAC_DMACFG_AINCR_LOBIT
);
1784 dma_cfg
= addr_field
+ incr_field
;
1785 status
= chipio_write(codec
, DSPDMAC_DMACFG_INST_OFFSET(dma_chan
),
1788 snd_printdd(KERN_ERR
"write DMACFG Reg fail\n");
1791 snd_printdd(KERN_INFO
" dsp_dma_setup() Write DMACFG\n");
1793 adr_ofs
= (count
- 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT
+
1796 status
= chipio_write(codec
, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan
),
1799 snd_printdd(KERN_ERR
"write DSPADROFS Reg fail\n");
1802 snd_printdd(KERN_INFO
" dsp_dma_setup() Write DSPADROFS\n");
1804 base_cnt
= (count
- 1) << DSPDMAC_XFRCNT_BCNT_LOBIT
;
1806 cur_cnt
= (count
- 1) << DSPDMAC_XFRCNT_CCNT_LOBIT
;
1808 xfr_cnt
= base_cnt
| cur_cnt
;
1810 status
= chipio_write(codec
,
1811 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan
), xfr_cnt
);
1813 snd_printdd(KERN_ERR
"write XFRCNT Reg fail\n");
1816 snd_printdd(KERN_INFO
" dsp_dma_setup() Write XFRCNT\n");
1819 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
1820 "ADROFS=0x%x, XFRCNT=0x%x\n",
1821 chip_addx
, count
, dma_cfg
, adr_ofs
, xfr_cnt
);
1823 snd_printdd(KERN_INFO
"-- dsp_dma_setup() -- Complete ---------\n");
1831 static int dsp_dma_start(struct hda_codec
*codec
,
1832 unsigned int dma_chan
, bool ovly
)
1834 unsigned int reg
= 0;
1837 snd_printdd(KERN_INFO
"-- dsp_dma_start() -- Begin ---------\n");
1840 status
= chipio_read(codec
,
1841 DSPDMAC_CHNLSTART_INST_OFFSET
, ®
);
1844 snd_printdd(KERN_ERR
"read CHNLSTART reg fail\n");
1847 snd_printdd(KERN_INFO
"-- dsp_dma_start() Read CHNLSTART\n");
1849 reg
&= ~(DSPDMAC_CHNLSTART_EN_MASK
|
1850 DSPDMAC_CHNLSTART_DIS_MASK
);
1853 status
= chipio_write(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
,
1854 reg
| (1 << (dma_chan
+ DSPDMAC_CHNLSTART_EN_LOBIT
)));
1856 snd_printdd(KERN_ERR
"write CHNLSTART reg fail\n");
1859 snd_printdd(KERN_INFO
"-- dsp_dma_start() -- Complete ---------\n");
1867 static int dsp_dma_stop(struct hda_codec
*codec
,
1868 unsigned int dma_chan
, bool ovly
)
1870 unsigned int reg
= 0;
1873 snd_printdd(KERN_INFO
"-- dsp_dma_stop() -- Begin ---------\n");
1876 status
= chipio_read(codec
,
1877 DSPDMAC_CHNLSTART_INST_OFFSET
, ®
);
1880 snd_printdd(KERN_ERR
"read CHNLSTART reg fail\n");
1883 snd_printdd(KERN_INFO
"-- dsp_dma_stop() Read CHNLSTART\n");
1884 reg
&= ~(DSPDMAC_CHNLSTART_EN_MASK
|
1885 DSPDMAC_CHNLSTART_DIS_MASK
);
1888 status
= chipio_write(codec
, DSPDMAC_CHNLSTART_INST_OFFSET
,
1889 reg
| (1 << (dma_chan
+ DSPDMAC_CHNLSTART_DIS_LOBIT
)));
1891 snd_printdd(KERN_ERR
"write CHNLSTART reg fail\n");
1894 snd_printdd(KERN_INFO
"-- dsp_dma_stop() -- Complete ---------\n");
1900 * Allocate router ports
1902 * @codec: the HDA codec
1903 * @num_chans: number of channels in the stream
1904 * @ports_per_channel: number of ports per channel
1905 * @start_device: start device
1906 * @port_map: pointer to the port list to hold the allocated ports
1908 * Returns zero or a negative error code.
1910 static int dsp_allocate_router_ports(struct hda_codec
*codec
,
1911 unsigned int num_chans
,
1912 unsigned int ports_per_channel
,
1913 unsigned int start_device
,
1914 unsigned int *port_map
)
1920 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
1924 val
= start_device
<< 6;
1925 val
|= (ports_per_channel
- 1) << 4;
1926 val
|= num_chans
- 1;
1928 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1929 VENDOR_CHIPIO_PORT_ALLOC_CONFIG_SET
,
1932 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1933 VENDOR_CHIPIO_PORT_ALLOC_SET
,
1936 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
1940 res
= snd_hda_codec_read(codec
, WIDGET_CHIP_CTRL
, 0,
1941 VENDOR_CHIPIO_PORT_ALLOC_GET
, 0);
1945 return (res
< 0) ? res
: 0;
1951 static int dsp_free_router_ports(struct hda_codec
*codec
)
1955 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
1959 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
1960 VENDOR_CHIPIO_PORT_FREE_SET
,
1963 status
= chipio_send(codec
, VENDOR_CHIPIO_STATUS
, 0);
1969 * Allocate DSP ports for the download stream
1971 static int dsp_allocate_ports(struct hda_codec
*codec
,
1972 unsigned int num_chans
,
1973 unsigned int rate_multi
, unsigned int *port_map
)
1977 snd_printdd(KERN_INFO
" dsp_allocate_ports() -- begin\n");
1979 if ((rate_multi
!= 1) && (rate_multi
!= 2) && (rate_multi
!= 4)) {
1980 snd_printdd(KERN_ERR
"bad rate multiple\n");
1984 status
= dsp_allocate_router_ports(codec
, num_chans
,
1985 rate_multi
, 0, port_map
);
1987 snd_printdd(KERN_INFO
" dsp_allocate_ports() -- complete\n");
1992 static int dsp_allocate_ports_format(struct hda_codec
*codec
,
1993 const unsigned short fmt
,
1994 unsigned int *port_map
)
1997 unsigned int num_chans
;
1999 unsigned int sample_rate_div
= ((get_hdafmt_rate(fmt
) >> 0) & 3) + 1;
2000 unsigned int sample_rate_mul
= ((get_hdafmt_rate(fmt
) >> 3) & 3) + 1;
2001 unsigned int rate_multi
= sample_rate_mul
/ sample_rate_div
;
2003 if ((rate_multi
!= 1) && (rate_multi
!= 2) && (rate_multi
!= 4)) {
2004 snd_printdd(KERN_ERR
"bad rate multiple\n");
2008 num_chans
= get_hdafmt_chs(fmt
) + 1;
2010 status
= dsp_allocate_ports(codec
, num_chans
, rate_multi
, port_map
);
2018 static int dsp_free_ports(struct hda_codec
*codec
)
2022 snd_printdd(KERN_INFO
" dsp_free_ports() -- begin\n");
2024 status
= dsp_free_router_ports(codec
);
2026 snd_printdd(KERN_ERR
"free router ports fail\n");
2029 snd_printdd(KERN_INFO
" dsp_free_ports() -- complete\n");
2035 * HDA DMA engine stuffs for DSP code download
2038 struct hda_codec
*codec
;
2039 unsigned short m_converter_format
;
2040 struct snd_dma_buffer
*dmab
;
2041 unsigned int buf_size
;
2050 static int dma_convert_to_hda_format(
2051 unsigned int sample_rate
,
2052 unsigned short channels
,
2053 unsigned short *hda_format
)
2055 unsigned int format_val
;
2057 format_val
= snd_hda_calc_stream_format(
2060 SNDRV_PCM_FORMAT_S32_LE
,
2064 *hda_format
= (unsigned short)format_val
;
2070 * Reset DMA for DSP download
2072 static int dma_reset(struct dma_engine
*dma
)
2074 struct hda_codec
*codec
= dma
->codec
;
2075 struct ca0132_spec
*spec
= codec
->spec
;
2078 if (dma
->dmab
->area
)
2079 snd_hda_codec_load_dsp_cleanup(codec
, dma
->dmab
);
2081 status
= snd_hda_codec_load_dsp_prepare(codec
,
2082 dma
->m_converter_format
,
2087 spec
->dsp_stream_id
= status
;
2091 static int dma_set_state(struct dma_engine
*dma
, enum dma_state state
)
2095 snd_printdd("dma_set_state state=%d\n", state
);
2098 case DMA_STATE_STOP
:
2108 snd_hda_codec_load_dsp_trigger(dma
->codec
, cmd
);
2112 static unsigned int dma_get_buffer_size(struct dma_engine
*dma
)
2114 return dma
->dmab
->bytes
;
2117 static unsigned char *dma_get_buffer_addr(struct dma_engine
*dma
)
2119 return dma
->dmab
->area
;
2122 static int dma_xfer(struct dma_engine
*dma
,
2123 const unsigned int *data
,
2126 memcpy(dma
->dmab
->area
, data
, count
);
2130 static void dma_get_converter_format(
2131 struct dma_engine
*dma
,
2132 unsigned short *format
)
2135 *format
= dma
->m_converter_format
;
2138 static unsigned int dma_get_stream_id(struct dma_engine
*dma
)
2140 struct ca0132_spec
*spec
= dma
->codec
->spec
;
2142 return spec
->dsp_stream_id
;
2145 struct dsp_image_seg
{
2152 static const u32 g_magic_value
= 0x4c46584d;
2153 static const u32 g_chip_addr_magic_value
= 0xFFFFFF01;
2155 static bool is_valid(const struct dsp_image_seg
*p
)
2157 return p
->magic
== g_magic_value
;
2160 static bool is_hci_prog_list_seg(const struct dsp_image_seg
*p
)
2162 return g_chip_addr_magic_value
== p
->chip_addr
;
2165 static bool is_last(const struct dsp_image_seg
*p
)
2167 return p
->count
== 0;
2170 static size_t dsp_sizeof(const struct dsp_image_seg
*p
)
2172 return sizeof(*p
) + p
->count
*sizeof(u32
);
2175 static const struct dsp_image_seg
*get_next_seg_ptr(
2176 const struct dsp_image_seg
*p
)
2178 return (struct dsp_image_seg
*)((unsigned char *)(p
) + dsp_sizeof(p
));
2182 * CA0132 chip DSP transfer stuffs. For DSP download.
2184 #define INVALID_DMA_CHANNEL (~0U)
2187 * Program a list of address/data pairs via the ChipIO widget.
2188 * The segment data is in the format of successive pairs of words.
2189 * These are repeated as indicated by the segment's count field.
2191 static int dspxfr_hci_write(struct hda_codec
*codec
,
2192 const struct dsp_image_seg
*fls
)
2198 if (fls
== NULL
|| fls
->chip_addr
!= g_chip_addr_magic_value
) {
2199 snd_printdd(KERN_ERR
"hci_write invalid params\n");
2204 data
= (u32
*)(fls
->data
);
2205 while (count
>= 2) {
2206 status
= chipio_write(codec
, data
[0], data
[1]);
2208 snd_printdd(KERN_ERR
"hci_write chipio failed\n");
2218 * Write a block of data into DSP code or data RAM using pre-allocated
2221 * @codec: the HDA codec
2222 * @fls: pointer to a fast load image
2223 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2225 * @dma_engine: pointer to DMA engine to be used for DSP download
2226 * @dma_chan: The number of DMA channels used for DSP download
2227 * @port_map_mask: port mapping
2228 * @ovly: TRUE if overlay format is required
2230 * Returns zero or a negative error code.
2232 static int dspxfr_one_seg(struct hda_codec
*codec
,
2233 const struct dsp_image_seg
*fls
,
2235 struct dma_engine
*dma_engine
,
2236 unsigned int dma_chan
,
2237 unsigned int port_map_mask
,
2241 bool comm_dma_setup_done
= false;
2242 const unsigned int *data
;
2243 unsigned int chip_addx
;
2244 unsigned int words_to_write
;
2245 unsigned int buffer_size_words
;
2246 unsigned char *buffer_addx
;
2247 unsigned short hda_format
;
2248 unsigned int sample_rate_div
;
2249 unsigned int sample_rate_mul
;
2250 unsigned int num_chans
;
2251 unsigned int hda_frame_size_words
;
2252 unsigned int remainder_words
;
2253 const u32
*data_remainder
;
2254 u32 chip_addx_remainder
;
2255 unsigned int run_size_words
;
2256 const struct dsp_image_seg
*hci_write
= NULL
;
2257 unsigned long timeout
;
2262 if (is_hci_prog_list_seg(fls
)) {
2264 fls
= get_next_seg_ptr(fls
);
2267 if (hci_write
&& (!fls
|| is_last(fls
))) {
2268 snd_printdd("hci_write\n");
2269 return dspxfr_hci_write(codec
, hci_write
);
2272 if (fls
== NULL
|| dma_engine
== NULL
|| port_map_mask
== 0) {
2273 snd_printdd("Invalid Params\n");
2278 chip_addx
= fls
->chip_addr
,
2279 words_to_write
= fls
->count
;
2281 if (!words_to_write
)
2282 return hci_write
? dspxfr_hci_write(codec
, hci_write
) : 0;
2284 chip_addx
= (chip_addx
& (0xFFFF0000 << 2)) + (reloc
<< 2);
2286 if (!UC_RANGE(chip_addx
, words_to_write
) &&
2287 !X_RANGE_ALL(chip_addx
, words_to_write
) &&
2288 !Y_RANGE_ALL(chip_addx
, words_to_write
)) {
2289 snd_printdd("Invalid chip_addx Params\n");
2293 buffer_size_words
= (unsigned int)dma_get_buffer_size(dma_engine
) /
2296 buffer_addx
= dma_get_buffer_addr(dma_engine
);
2298 if (buffer_addx
== NULL
) {
2299 snd_printdd(KERN_ERR
"dma_engine buffer NULL\n");
2303 dma_get_converter_format(dma_engine
, &hda_format
);
2304 sample_rate_div
= ((get_hdafmt_rate(hda_format
) >> 0) & 3) + 1;
2305 sample_rate_mul
= ((get_hdafmt_rate(hda_format
) >> 3) & 3) + 1;
2306 num_chans
= get_hdafmt_chs(hda_format
) + 1;
2308 hda_frame_size_words
= ((sample_rate_div
== 0) ? 0 :
2309 (num_chans
* sample_rate_mul
/ sample_rate_div
));
2311 if (hda_frame_size_words
== 0) {
2312 snd_printdd(KERN_ERR
"frmsz zero\n");
2316 buffer_size_words
= min(buffer_size_words
,
2317 (unsigned int)(UC_RANGE(chip_addx
, 1) ?
2319 buffer_size_words
-= buffer_size_words
% hda_frame_size_words
;
2321 "chpadr=0x%08x frmsz=%u nchan=%u "
2322 "rate_mul=%u div=%u bufsz=%u\n",
2323 chip_addx
, hda_frame_size_words
, num_chans
,
2324 sample_rate_mul
, sample_rate_div
, buffer_size_words
);
2326 if (buffer_size_words
< hda_frame_size_words
) {
2327 snd_printdd(KERN_ERR
"dspxfr_one_seg:failed\n");
2331 remainder_words
= words_to_write
% hda_frame_size_words
;
2332 data_remainder
= data
;
2333 chip_addx_remainder
= chip_addx
;
2335 data
+= remainder_words
;
2336 chip_addx
+= remainder_words
*sizeof(u32
);
2337 words_to_write
-= remainder_words
;
2339 while (words_to_write
!= 0) {
2340 run_size_words
= min(buffer_size_words
, words_to_write
);
2341 snd_printdd("dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2342 words_to_write
, run_size_words
, remainder_words
);
2343 dma_xfer(dma_engine
, data
, run_size_words
*sizeof(u32
));
2344 if (!comm_dma_setup_done
) {
2345 status
= dsp_dma_stop(codec
, dma_chan
, ovly
);
2348 status
= dsp_dma_setup_common(codec
, chip_addx
,
2349 dma_chan
, port_map_mask
, ovly
);
2352 comm_dma_setup_done
= true;
2355 status
= dsp_dma_setup(codec
, chip_addx
,
2356 run_size_words
, dma_chan
);
2359 status
= dsp_dma_start(codec
, dma_chan
, ovly
);
2362 if (!dsp_is_dma_active(codec
, dma_chan
)) {
2363 snd_printdd(KERN_ERR
"dspxfr:DMA did not start\n");
2366 status
= dma_set_state(dma_engine
, DMA_STATE_RUN
);
2369 if (remainder_words
!= 0) {
2370 status
= chipio_write_multiple(codec
,
2371 chip_addx_remainder
,
2376 remainder_words
= 0;
2379 status
= dspxfr_hci_write(codec
, hci_write
);
2385 timeout
= jiffies
+ msecs_to_jiffies(2000);
2387 dma_active
= dsp_is_dma_active(codec
, dma_chan
);
2391 } while (time_before(jiffies
, timeout
));
2395 snd_printdd(KERN_INFO
"+++++ DMA complete\n");
2396 dma_set_state(dma_engine
, DMA_STATE_STOP
);
2397 status
= dma_reset(dma_engine
);
2402 data
+= run_size_words
;
2403 chip_addx
+= run_size_words
*sizeof(u32
);
2404 words_to_write
-= run_size_words
;
2407 if (remainder_words
!= 0) {
2408 status
= chipio_write_multiple(codec
, chip_addx_remainder
,
2409 data_remainder
, remainder_words
);
2416 * Write the entire DSP image of a DSP code/data overlay to DSP memories
2418 * @codec: the HDA codec
2419 * @fls_data: pointer to a fast load image
2420 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2422 * @sample_rate: sampling rate of the stream used for DSP download
2423 * @number_channels: channels of the stream used for DSP download
2424 * @ovly: TRUE if overlay format is required
2426 * Returns zero or a negative error code.
2428 static int dspxfr_image(struct hda_codec
*codec
,
2429 const struct dsp_image_seg
*fls_data
,
2431 unsigned int sample_rate
,
2432 unsigned short channels
,
2435 struct ca0132_spec
*spec
= codec
->spec
;
2437 unsigned short hda_format
= 0;
2438 unsigned int response
;
2439 unsigned char stream_id
= 0;
2440 struct dma_engine
*dma_engine
;
2441 unsigned int dma_chan
;
2442 unsigned int port_map_mask
;
2444 if (fls_data
== NULL
)
2447 dma_engine
= kzalloc(sizeof(*dma_engine
), GFP_KERNEL
);
2451 dma_engine
->dmab
= kzalloc(sizeof(*dma_engine
->dmab
), GFP_KERNEL
);
2452 if (!dma_engine
->dmab
) {
2457 dma_engine
->codec
= codec
;
2458 dma_convert_to_hda_format(sample_rate
, channels
, &hda_format
);
2459 dma_engine
->m_converter_format
= hda_format
;
2460 dma_engine
->buf_size
= (ovly
? DSP_DMA_WRITE_BUFLEN_OVLY
:
2461 DSP_DMA_WRITE_BUFLEN_INIT
) * 2;
2463 dma_chan
= ovly
? INVALID_DMA_CHANNEL
: 0;
2465 status
= codec_set_converter_format(codec
, WIDGET_CHIP_CTRL
,
2466 hda_format
, &response
);
2469 snd_printdd(KERN_ERR
"set converter format fail\n");
2473 status
= snd_hda_codec_load_dsp_prepare(codec
,
2474 dma_engine
->m_converter_format
,
2475 dma_engine
->buf_size
,
2479 spec
->dsp_stream_id
= status
;
2482 status
= dspio_alloc_dma_chan(codec
, &dma_chan
);
2484 snd_printdd(KERN_ERR
"alloc dmachan fail\n");
2485 dma_chan
= INVALID_DMA_CHANNEL
;
2491 status
= dsp_allocate_ports_format(codec
, hda_format
,
2494 snd_printdd(KERN_ERR
"alloc ports fail\n");
2498 stream_id
= dma_get_stream_id(dma_engine
);
2499 status
= codec_set_converter_stream_channel(codec
,
2500 WIDGET_CHIP_CTRL
, stream_id
, 0, &response
);
2502 snd_printdd(KERN_ERR
"set stream chan fail\n");
2506 while ((fls_data
!= NULL
) && !is_last(fls_data
)) {
2507 if (!is_valid(fls_data
)) {
2508 snd_printdd(KERN_ERR
"FLS check fail\n");
2512 status
= dspxfr_one_seg(codec
, fls_data
, reloc
,
2513 dma_engine
, dma_chan
,
2514 port_map_mask
, ovly
);
2518 if (is_hci_prog_list_seg(fls_data
))
2519 fls_data
= get_next_seg_ptr(fls_data
);
2521 if ((fls_data
!= NULL
) && !is_last(fls_data
))
2522 fls_data
= get_next_seg_ptr(fls_data
);
2525 if (port_map_mask
!= 0)
2526 status
= dsp_free_ports(codec
);
2531 status
= codec_set_converter_stream_channel(codec
,
2532 WIDGET_CHIP_CTRL
, 0, 0, &response
);
2535 if (ovly
&& (dma_chan
!= INVALID_DMA_CHANNEL
))
2536 dspio_free_dma_chan(codec
, dma_chan
);
2538 if (dma_engine
->dmab
->area
)
2539 snd_hda_codec_load_dsp_cleanup(codec
, dma_engine
->dmab
);
2540 kfree(dma_engine
->dmab
);
2547 * CA0132 DSP download stuffs.
2549 static void dspload_post_setup(struct hda_codec
*codec
)
2551 snd_printdd(KERN_INFO
"---- dspload_post_setup ------\n");
2553 /*set DSP speaker to 2.0 configuration*/
2554 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
2555 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x19), 0x3f800000);
2557 /*update write pointer*/
2558 chipio_write(codec
, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
2562 * Download DSP from a DSP Image Fast Load structure. This structure is a
2563 * linear, non-constant sized element array of structures, each of which
2564 * contain the count of the data to be loaded, the data itself, and the
2565 * corresponding starting chip address of the starting data location.
2567 * @codec: the HDA codec
2568 * @fls: pointer to a fast load image
2569 * @ovly: TRUE if overlay format is required
2570 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2572 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
2573 * @router_chans: number of audio router channels to be allocated (0 means use
2574 * internal defaults; max is 32)
2576 * Returns zero or a negative error code.
2578 static int dspload_image(struct hda_codec
*codec
,
2579 const struct dsp_image_seg
*fls
,
2586 unsigned int sample_rate
;
2587 unsigned short channels
;
2589 snd_printdd(KERN_INFO
"---- dspload_image begin ------\n");
2590 if (router_chans
== 0) {
2592 router_chans
= DMA_TRANSFER_FRAME_SIZE_NWORDS
;
2594 router_chans
= DMA_OVERLAY_FRAME_SIZE_NWORDS
;
2597 sample_rate
= 48000;
2598 channels
= (unsigned short)router_chans
;
2600 while (channels
> 16) {
2606 snd_printdd(KERN_INFO
"Ready to program DMA\n");
2608 status
= dsp_reset(codec
);
2613 snd_printdd(KERN_INFO
"dsp_reset() complete\n");
2614 status
= dspxfr_image(codec
, fls
, reloc
, sample_rate
, channels
,
2620 snd_printdd(KERN_INFO
"dspxfr_image() complete\n");
2621 if (autostart
&& !ovly
) {
2622 dspload_post_setup(codec
);
2623 status
= dsp_set_run_state(codec
);
2626 snd_printdd(KERN_INFO
"LOAD FINISHED\n");
2632 #ifdef CONFIG_SND_HDA_CODEC_CA0132_DSP
2633 static bool dspload_is_loaded(struct hda_codec
*codec
)
2635 unsigned int data
= 0;
2638 status
= chipio_read(codec
, 0x40004, &data
);
2639 if ((status
< 0) || (data
!= 1))
2645 #define dspload_is_loaded(codec) false
2648 static bool dspload_wait_loaded(struct hda_codec
*codec
)
2650 unsigned long timeout
= jiffies
+ msecs_to_jiffies(2000);
2653 if (dspload_is_loaded(codec
)) {
2654 pr_info("ca0132 DOWNLOAD OK :-) DSP IS RUNNING.\n");
2658 } while (time_before(jiffies
, timeout
));
2660 pr_err("ca0132 DOWNLOAD FAILED!!! DSP IS NOT RUNNING.\n");
2667 static void ca0132_setup_stream(struct hda_codec
*codec
, hda_nid_t nid
,
2669 int channel_id
, int format
)
2671 unsigned int oldval
, newval
;
2677 "ca0132_setup_stream: NID=0x%x, stream=0x%x, "
2678 "channel=%d, format=0x%x\n",
2679 nid
, stream_tag
, channel_id
, format
);
2681 /* update the format-id if changed */
2682 oldval
= snd_hda_codec_read(codec
, nid
, 0,
2683 AC_VERB_GET_STREAM_FORMAT
,
2685 if (oldval
!= format
) {
2687 snd_hda_codec_write(codec
, nid
, 0,
2688 AC_VERB_SET_STREAM_FORMAT
,
2692 oldval
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
2693 newval
= (stream_tag
<< 4) | channel_id
;
2694 if (oldval
!= newval
) {
2695 snd_hda_codec_write(codec
, nid
, 0,
2696 AC_VERB_SET_CHANNEL_STREAMID
,
2701 static void ca0132_cleanup_stream(struct hda_codec
*codec
, hda_nid_t nid
)
2708 snd_printdd(KERN_INFO
"ca0132_cleanup_stream: NID=0x%x\n", nid
);
2710 val
= snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_CONV
, 0);
2714 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_STREAM_FORMAT
, 0);
2715 snd_hda_codec_write(codec
, nid
, 0, AC_VERB_SET_CHANNEL_STREAMID
, 0);
2721 static int ca0132_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2722 struct hda_codec
*codec
,
2723 unsigned int stream_tag
,
2724 unsigned int format
,
2725 struct snd_pcm_substream
*substream
)
2727 struct ca0132_spec
*spec
= codec
->spec
;
2729 ca0132_setup_stream(codec
, spec
->dacs
[0], stream_tag
, 0, format
);
2734 static int ca0132_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2735 struct hda_codec
*codec
,
2736 struct snd_pcm_substream
*substream
)
2738 struct ca0132_spec
*spec
= codec
->spec
;
2740 if (spec
->dsp_state
== DSP_DOWNLOADING
)
2743 /*If Playback effects are on, allow stream some time to flush
2745 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
2748 ca0132_cleanup_stream(codec
, spec
->dacs
[0]);
2753 static unsigned int ca0132_playback_pcm_delay(struct hda_pcm_stream
*info
,
2754 struct hda_codec
*codec
,
2755 struct snd_pcm_substream
*substream
)
2757 struct ca0132_spec
*spec
= codec
->spec
;
2758 unsigned int latency
= DSP_PLAYBACK_INIT_LATENCY
;
2759 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2761 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
2764 /* Add latency if playback enhancement and either effect is enabled. */
2765 if (spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
]) {
2766 if ((spec
->effects_switch
[SURROUND
- EFFECT_START_NID
]) ||
2767 (spec
->effects_switch
[DIALOG_PLUS
- EFFECT_START_NID
]))
2768 latency
+= DSP_PLAY_ENHANCEMENT_LATENCY
;
2771 /* Applying Speaker EQ adds latency as well. */
2772 if (spec
->cur_out_type
== SPEAKER_OUT
)
2773 latency
+= DSP_SPEAKER_OUT_LATENCY
;
2775 return (latency
* runtime
->rate
) / 1000;
2781 static int ca0132_dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
2782 struct hda_codec
*codec
,
2783 struct snd_pcm_substream
*substream
)
2785 struct ca0132_spec
*spec
= codec
->spec
;
2786 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
2789 static int ca0132_dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2790 struct hda_codec
*codec
,
2791 unsigned int stream_tag
,
2792 unsigned int format
,
2793 struct snd_pcm_substream
*substream
)
2795 struct ca0132_spec
*spec
= codec
->spec
;
2796 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
2797 stream_tag
, format
, substream
);
2800 static int ca0132_dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2801 struct hda_codec
*codec
,
2802 struct snd_pcm_substream
*substream
)
2804 struct ca0132_spec
*spec
= codec
->spec
;
2805 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
2808 static int ca0132_dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
2809 struct hda_codec
*codec
,
2810 struct snd_pcm_substream
*substream
)
2812 struct ca0132_spec
*spec
= codec
->spec
;
2813 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
2819 static int ca0132_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
2820 struct hda_codec
*codec
,
2821 unsigned int stream_tag
,
2822 unsigned int format
,
2823 struct snd_pcm_substream
*substream
)
2825 struct ca0132_spec
*spec
= codec
->spec
;
2827 ca0132_setup_stream(codec
, spec
->adcs
[substream
->number
],
2828 stream_tag
, 0, format
);
2833 static int ca0132_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
2834 struct hda_codec
*codec
,
2835 struct snd_pcm_substream
*substream
)
2837 struct ca0132_spec
*spec
= codec
->spec
;
2839 if (spec
->dsp_state
== DSP_DOWNLOADING
)
2842 ca0132_cleanup_stream(codec
, hinfo
->nid
);
2846 static unsigned int ca0132_capture_pcm_delay(struct hda_pcm_stream
*info
,
2847 struct hda_codec
*codec
,
2848 struct snd_pcm_substream
*substream
)
2850 struct ca0132_spec
*spec
= codec
->spec
;
2851 unsigned int latency
= DSP_CAPTURE_INIT_LATENCY
;
2852 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2854 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
2857 if (spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
])
2858 latency
+= DSP_CRYSTAL_VOICE_LATENCY
;
2860 return (latency
* runtime
->rate
) / 1000;
2868 * Mixer controls helpers.
2870 #define CA0132_CODEC_VOL_MONO(xname, nid, channel, dir) \
2871 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2873 .subdevice = HDA_SUBDEV_AMP_FLAG, \
2874 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2875 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2876 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2877 .info = ca0132_volume_info, \
2878 .get = ca0132_volume_get, \
2879 .put = ca0132_volume_put, \
2880 .tlv = { .c = ca0132_volume_tlv }, \
2881 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
2883 #define CA0132_CODEC_MUTE_MONO(xname, nid, channel, dir) \
2884 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2886 .subdevice = HDA_SUBDEV_AMP_FLAG, \
2887 .info = snd_hda_mixer_amp_switch_info, \
2888 .get = ca0132_switch_get, \
2889 .put = ca0132_switch_put, \
2890 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, 0, dir) }
2893 #define CA0132_CODEC_VOL(xname, nid, dir) \
2894 CA0132_CODEC_VOL_MONO(xname, nid, 3, dir)
2895 #define CA0132_CODEC_MUTE(xname, nid, dir) \
2896 CA0132_CODEC_MUTE_MONO(xname, nid, 3, dir)
2898 /* The followings are for tuning of products */
2899 #ifdef ENABLE_TUNING_CONTROLS
2901 static unsigned int voice_focus_vals_lookup
[] = {
2902 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000, 0x41C00000, 0x41C80000,
2903 0x41D00000, 0x41D80000, 0x41E00000, 0x41E80000, 0x41F00000, 0x41F80000,
2904 0x42000000, 0x42040000, 0x42080000, 0x420C0000, 0x42100000, 0x42140000,
2905 0x42180000, 0x421C0000, 0x42200000, 0x42240000, 0x42280000, 0x422C0000,
2906 0x42300000, 0x42340000, 0x42380000, 0x423C0000, 0x42400000, 0x42440000,
2907 0x42480000, 0x424C0000, 0x42500000, 0x42540000, 0x42580000, 0x425C0000,
2908 0x42600000, 0x42640000, 0x42680000, 0x426C0000, 0x42700000, 0x42740000,
2909 0x42780000, 0x427C0000, 0x42800000, 0x42820000, 0x42840000, 0x42860000,
2910 0x42880000, 0x428A0000, 0x428C0000, 0x428E0000, 0x42900000, 0x42920000,
2911 0x42940000, 0x42960000, 0x42980000, 0x429A0000, 0x429C0000, 0x429E0000,
2912 0x42A00000, 0x42A20000, 0x42A40000, 0x42A60000, 0x42A80000, 0x42AA0000,
2913 0x42AC0000, 0x42AE0000, 0x42B00000, 0x42B20000, 0x42B40000, 0x42B60000,
2914 0x42B80000, 0x42BA0000, 0x42BC0000, 0x42BE0000, 0x42C00000, 0x42C20000,
2915 0x42C40000, 0x42C60000, 0x42C80000, 0x42CA0000, 0x42CC0000, 0x42CE0000,
2916 0x42D00000, 0x42D20000, 0x42D40000, 0x42D60000, 0x42D80000, 0x42DA0000,
2917 0x42DC0000, 0x42DE0000, 0x42E00000, 0x42E20000, 0x42E40000, 0x42E60000,
2918 0x42E80000, 0x42EA0000, 0x42EC0000, 0x42EE0000, 0x42F00000, 0x42F20000,
2919 0x42F40000, 0x42F60000, 0x42F80000, 0x42FA0000, 0x42FC0000, 0x42FE0000,
2920 0x43000000, 0x43010000, 0x43020000, 0x43030000, 0x43040000, 0x43050000,
2921 0x43060000, 0x43070000, 0x43080000, 0x43090000, 0x430A0000, 0x430B0000,
2922 0x430C0000, 0x430D0000, 0x430E0000, 0x430F0000, 0x43100000, 0x43110000,
2923 0x43120000, 0x43130000, 0x43140000, 0x43150000, 0x43160000, 0x43170000,
2924 0x43180000, 0x43190000, 0x431A0000, 0x431B0000, 0x431C0000, 0x431D0000,
2925 0x431E0000, 0x431F0000, 0x43200000, 0x43210000, 0x43220000, 0x43230000,
2926 0x43240000, 0x43250000, 0x43260000, 0x43270000, 0x43280000, 0x43290000,
2927 0x432A0000, 0x432B0000, 0x432C0000, 0x432D0000, 0x432E0000, 0x432F0000,
2928 0x43300000, 0x43310000, 0x43320000, 0x43330000, 0x43340000
2931 static unsigned int mic_svm_vals_lookup
[] = {
2932 0x00000000, 0x3C23D70A, 0x3CA3D70A, 0x3CF5C28F, 0x3D23D70A, 0x3D4CCCCD,
2933 0x3D75C28F, 0x3D8F5C29, 0x3DA3D70A, 0x3DB851EC, 0x3DCCCCCD, 0x3DE147AE,
2934 0x3DF5C28F, 0x3E051EB8, 0x3E0F5C29, 0x3E19999A, 0x3E23D70A, 0x3E2E147B,
2935 0x3E3851EC, 0x3E428F5C, 0x3E4CCCCD, 0x3E570A3D, 0x3E6147AE, 0x3E6B851F,
2936 0x3E75C28F, 0x3E800000, 0x3E851EB8, 0x3E8A3D71, 0x3E8F5C29, 0x3E947AE1,
2937 0x3E99999A, 0x3E9EB852, 0x3EA3D70A, 0x3EA8F5C3, 0x3EAE147B, 0x3EB33333,
2938 0x3EB851EC, 0x3EBD70A4, 0x3EC28F5C, 0x3EC7AE14, 0x3ECCCCCD, 0x3ED1EB85,
2939 0x3ED70A3D, 0x3EDC28F6, 0x3EE147AE, 0x3EE66666, 0x3EEB851F, 0x3EF0A3D7,
2940 0x3EF5C28F, 0x3EFAE148, 0x3F000000, 0x3F028F5C, 0x3F051EB8, 0x3F07AE14,
2941 0x3F0A3D71, 0x3F0CCCCD, 0x3F0F5C29, 0x3F11EB85, 0x3F147AE1, 0x3F170A3D,
2942 0x3F19999A, 0x3F1C28F6, 0x3F1EB852, 0x3F2147AE, 0x3F23D70A, 0x3F266666,
2943 0x3F28F5C3, 0x3F2B851F, 0x3F2E147B, 0x3F30A3D7, 0x3F333333, 0x3F35C28F,
2944 0x3F3851EC, 0x3F3AE148, 0x3F3D70A4, 0x3F400000, 0x3F428F5C, 0x3F451EB8,
2945 0x3F47AE14, 0x3F4A3D71, 0x3F4CCCCD, 0x3F4F5C29, 0x3F51EB85, 0x3F547AE1,
2946 0x3F570A3D, 0x3F59999A, 0x3F5C28F6, 0x3F5EB852, 0x3F6147AE, 0x3F63D70A,
2947 0x3F666666, 0x3F68F5C3, 0x3F6B851F, 0x3F6E147B, 0x3F70A3D7, 0x3F733333,
2948 0x3F75C28F, 0x3F7851EC, 0x3F7AE148, 0x3F7D70A4, 0x3F800000
2951 static unsigned int equalizer_vals_lookup
[] = {
2952 0xC1C00000, 0xC1B80000, 0xC1B00000, 0xC1A80000, 0xC1A00000, 0xC1980000,
2953 0xC1900000, 0xC1880000, 0xC1800000, 0xC1700000, 0xC1600000, 0xC1500000,
2954 0xC1400000, 0xC1300000, 0xC1200000, 0xC1100000, 0xC1000000, 0xC0E00000,
2955 0xC0C00000, 0xC0A00000, 0xC0800000, 0xC0400000, 0xC0000000, 0xBF800000,
2956 0x00000000, 0x3F800000, 0x40000000, 0x40400000, 0x40800000, 0x40A00000,
2957 0x40C00000, 0x40E00000, 0x41000000, 0x41100000, 0x41200000, 0x41300000,
2958 0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41800000, 0x41880000,
2959 0x41900000, 0x41980000, 0x41A00000, 0x41A80000, 0x41B00000, 0x41B80000,
2963 static int tuning_ctl_set(struct hda_codec
*codec
, hda_nid_t nid
,
2964 unsigned int *lookup
, int idx
)
2968 for (i
= 0; i
< TUNING_CTLS_COUNT
; i
++)
2969 if (nid
== ca0132_tuning_ctls
[i
].nid
)
2972 snd_hda_power_up(codec
);
2973 dspio_set_param(codec
, ca0132_tuning_ctls
[i
].mid
,
2974 ca0132_tuning_ctls
[i
].req
,
2975 &(lookup
[idx
]), sizeof(unsigned int));
2976 snd_hda_power_down(codec
);
2981 static int tuning_ctl_get(struct snd_kcontrol
*kcontrol
,
2982 struct snd_ctl_elem_value
*ucontrol
)
2984 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2985 struct ca0132_spec
*spec
= codec
->spec
;
2986 hda_nid_t nid
= get_amp_nid(kcontrol
);
2987 long *valp
= ucontrol
->value
.integer
.value
;
2988 int idx
= nid
- TUNING_CTL_START_NID
;
2990 *valp
= spec
->cur_ctl_vals
[idx
];
2994 static int voice_focus_ctl_info(struct snd_kcontrol
*kcontrol
,
2995 struct snd_ctl_elem_info
*uinfo
)
2997 int chs
= get_amp_channels(kcontrol
);
2998 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2999 uinfo
->count
= chs
== 3 ? 2 : 1;
3000 uinfo
->value
.integer
.min
= 20;
3001 uinfo
->value
.integer
.max
= 180;
3002 uinfo
->value
.integer
.step
= 1;
3007 static int voice_focus_ctl_put(struct snd_kcontrol
*kcontrol
,
3008 struct snd_ctl_elem_value
*ucontrol
)
3010 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3011 struct ca0132_spec
*spec
= codec
->spec
;
3012 hda_nid_t nid
= get_amp_nid(kcontrol
);
3013 long *valp
= ucontrol
->value
.integer
.value
;
3016 idx
= nid
- TUNING_CTL_START_NID
;
3018 if (spec
->cur_ctl_vals
[idx
] == *valp
)
3021 spec
->cur_ctl_vals
[idx
] = *valp
;
3024 tuning_ctl_set(codec
, nid
, voice_focus_vals_lookup
, idx
);
3029 static int mic_svm_ctl_info(struct snd_kcontrol
*kcontrol
,
3030 struct snd_ctl_elem_info
*uinfo
)
3032 int chs
= get_amp_channels(kcontrol
);
3033 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3034 uinfo
->count
= chs
== 3 ? 2 : 1;
3035 uinfo
->value
.integer
.min
= 0;
3036 uinfo
->value
.integer
.max
= 100;
3037 uinfo
->value
.integer
.step
= 1;
3042 static int mic_svm_ctl_put(struct snd_kcontrol
*kcontrol
,
3043 struct snd_ctl_elem_value
*ucontrol
)
3045 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3046 struct ca0132_spec
*spec
= codec
->spec
;
3047 hda_nid_t nid
= get_amp_nid(kcontrol
);
3048 long *valp
= ucontrol
->value
.integer
.value
;
3051 idx
= nid
- TUNING_CTL_START_NID
;
3053 if (spec
->cur_ctl_vals
[idx
] == *valp
)
3056 spec
->cur_ctl_vals
[idx
] = *valp
;
3059 tuning_ctl_set(codec
, nid
, mic_svm_vals_lookup
, idx
);
3064 static int equalizer_ctl_info(struct snd_kcontrol
*kcontrol
,
3065 struct snd_ctl_elem_info
*uinfo
)
3067 int chs
= get_amp_channels(kcontrol
);
3068 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3069 uinfo
->count
= chs
== 3 ? 2 : 1;
3070 uinfo
->value
.integer
.min
= 0;
3071 uinfo
->value
.integer
.max
= 48;
3072 uinfo
->value
.integer
.step
= 1;
3077 static int equalizer_ctl_put(struct snd_kcontrol
*kcontrol
,
3078 struct snd_ctl_elem_value
*ucontrol
)
3080 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3081 struct ca0132_spec
*spec
= codec
->spec
;
3082 hda_nid_t nid
= get_amp_nid(kcontrol
);
3083 long *valp
= ucontrol
->value
.integer
.value
;
3086 idx
= nid
- TUNING_CTL_START_NID
;
3088 if (spec
->cur_ctl_vals
[idx
] == *valp
)
3091 spec
->cur_ctl_vals
[idx
] = *valp
;
3094 tuning_ctl_set(codec
, nid
, equalizer_vals_lookup
, idx
);
3099 static const DECLARE_TLV_DB_SCALE(voice_focus_db_scale
, 2000, 100, 0);
3100 static const DECLARE_TLV_DB_SCALE(eq_db_scale
, -2400, 100, 0);
3102 static int add_tuning_control(struct hda_codec
*codec
,
3103 hda_nid_t pnid
, hda_nid_t nid
,
3104 const char *name
, int dir
)
3106 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3107 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
3108 struct snd_kcontrol_new knew
=
3109 HDA_CODEC_VOLUME_MONO(namestr
, nid
, 1, 0, type
);
3111 knew
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
3112 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
3117 knew
.info
= voice_focus_ctl_info
;
3118 knew
.get
= tuning_ctl_get
;
3119 knew
.put
= voice_focus_ctl_put
;
3120 knew
.tlv
.p
= voice_focus_db_scale
;
3123 knew
.info
= mic_svm_ctl_info
;
3124 knew
.get
= tuning_ctl_get
;
3125 knew
.put
= mic_svm_ctl_put
;
3128 knew
.info
= equalizer_ctl_info
;
3129 knew
.get
= tuning_ctl_get
;
3130 knew
.put
= equalizer_ctl_put
;
3131 knew
.tlv
.p
= eq_db_scale
;
3136 knew
.private_value
=
3137 HDA_COMPOSE_AMP_VAL(nid
, 1, 0, type
);
3138 sprintf(namestr
, "%s %s Volume", name
, dirstr
[dir
]);
3139 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
3142 static int add_tuning_ctls(struct hda_codec
*codec
)
3147 for (i
= 0; i
< TUNING_CTLS_COUNT
; i
++) {
3148 err
= add_tuning_control(codec
,
3149 ca0132_tuning_ctls
[i
].parent_nid
,
3150 ca0132_tuning_ctls
[i
].nid
,
3151 ca0132_tuning_ctls
[i
].name
,
3152 ca0132_tuning_ctls
[i
].direct
);
3160 static void ca0132_init_tuning_defaults(struct hda_codec
*codec
)
3162 struct ca0132_spec
*spec
= codec
->spec
;
3165 /* Wedge Angle defaults to 30. 10 below is 30 - 20. 20 is min. */
3166 spec
->cur_ctl_vals
[WEDGE_ANGLE
- TUNING_CTL_START_NID
] = 10;
3167 /* SVM level defaults to 0.74. */
3168 spec
->cur_ctl_vals
[SVM_LEVEL
- TUNING_CTL_START_NID
] = 74;
3170 /* EQ defaults to 0dB. */
3171 for (i
= 2; i
< TUNING_CTLS_COUNT
; i
++)
3172 spec
->cur_ctl_vals
[i
] = 24;
3174 #endif /*ENABLE_TUNING_CONTROLS*/
3177 * Select the active output.
3178 * If autodetect is enabled, output will be selected based on jack detection.
3179 * If jack inserted, headphone will be selected, else built-in speakers
3180 * If autodetect is disabled, output will be selected based on selection.
3182 static int ca0132_select_out(struct hda_codec
*codec
)
3184 struct ca0132_spec
*spec
= codec
->spec
;
3185 unsigned int pin_ctl
;
3191 snd_printdd(KERN_INFO
"ca0132_select_out\n");
3193 snd_hda_power_up(codec
);
3195 auto_jack
= spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
3198 jack_present
= snd_hda_jack_detect(codec
, spec
->out_pins
[1]);
3201 spec
->vnode_lswitch
[VNID_HP_SEL
- VNODE_START_NID
];
3204 spec
->cur_out_type
= HEADPHONE_OUT
;
3206 spec
->cur_out_type
= SPEAKER_OUT
;
3208 if (spec
->cur_out_type
== SPEAKER_OUT
) {
3209 snd_printdd(KERN_INFO
"ca0132_select_out speaker\n");
3210 /*speaker out config*/
3212 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
3215 /*enable speaker EQ*/
3217 err
= dspio_set_uint_param(codec
, 0x8f, 0x00, tmp
);
3222 snd_hda_codec_write(codec
, spec
->out_pins
[1], 0,
3223 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x02);
3224 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3225 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
3226 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3227 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x00);
3228 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3229 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
3231 /* disable headphone node */
3232 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
3233 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3234 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
3236 /* enable speaker node */
3237 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
3238 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3239 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
3242 snd_printdd(KERN_INFO
"ca0132_select_out hp\n");
3243 /*headphone out config*/
3245 err
= dspio_set_uint_param(codec
, 0x80, 0x04, tmp
);
3248 /*disable speaker EQ*/
3250 err
= dspio_set_uint_param(codec
, 0x8f, 0x00, tmp
);
3255 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3256 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x00);
3257 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3258 AC_VERB_SET_EAPD_BTLENABLE
, 0x00);
3259 snd_hda_codec_write(codec
, spec
->out_pins
[1], 0,
3260 VENDOR_CHIPIO_EAPD_SEL_SET
, 0x02);
3261 snd_hda_codec_write(codec
, spec
->out_pins
[0], 0,
3262 AC_VERB_SET_EAPD_BTLENABLE
, 0x02);
3264 /* disable speaker*/
3265 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[0], 0,
3266 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3267 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[0],
3269 /* enable headphone*/
3270 pin_ctl
= snd_hda_codec_read(codec
, spec
->out_pins
[1], 0,
3271 AC_VERB_GET_PIN_WIDGET_CONTROL
, 0);
3272 snd_hda_set_pin_ctl(codec
, spec
->out_pins
[1],
3277 snd_hda_power_down(codec
);
3279 return err
< 0 ? err
: 0;
3282 static void ca0132_unsol_hp_delayed(struct work_struct
*work
)
3284 struct ca0132_spec
*spec
= container_of(
3285 to_delayed_work(work
), struct ca0132_spec
, unsol_hp_work
);
3286 ca0132_select_out(spec
->codec
);
3287 snd_hda_jack_report_sync(spec
->codec
);
3290 static void ca0132_set_dmic(struct hda_codec
*codec
, int enable
);
3291 static int ca0132_mic_boost_set(struct hda_codec
*codec
, long val
);
3292 static int ca0132_effects_set(struct hda_codec
*codec
, hda_nid_t nid
, long val
);
3295 * Select the active VIP source
3297 static int ca0132_set_vipsource(struct hda_codec
*codec
, int val
)
3299 struct ca0132_spec
*spec
= codec
->spec
;
3302 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
3305 /* if CrystalVoice if off, vipsource should be 0 */
3306 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ||
3308 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, 0);
3309 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
3310 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
3311 if (spec
->cur_mic_type
== DIGITAL_MIC
)
3315 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
3317 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
3319 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_16_000
);
3320 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_16_000
);
3321 if (spec
->cur_mic_type
== DIGITAL_MIC
)
3325 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
3327 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
3329 chipio_set_control_param(codec
, CONTROL_PARAM_VIP_SOURCE
, val
);
3336 * Select the active microphone.
3337 * If autodetect is enabled, mic will be selected based on jack detection.
3338 * If jack inserted, ext.mic will be selected, else built-in mic
3339 * If autodetect is disabled, mic will be selected based on selection.
3341 static int ca0132_select_mic(struct hda_codec
*codec
)
3343 struct ca0132_spec
*spec
= codec
->spec
;
3347 snd_printdd(KERN_INFO
"ca0132_select_mic\n");
3349 snd_hda_power_up(codec
);
3351 auto_jack
= spec
->vnode_lswitch
[VNID_AMIC1_ASEL
- VNODE_START_NID
];
3354 jack_present
= snd_hda_jack_detect(codec
, spec
->input_pins
[0]);
3357 spec
->vnode_lswitch
[VNID_AMIC1_SEL
- VNODE_START_NID
];
3360 spec
->cur_mic_type
= LINE_MIC_IN
;
3362 spec
->cur_mic_type
= DIGITAL_MIC
;
3364 if (spec
->cur_mic_type
== DIGITAL_MIC
) {
3365 /* enable digital Mic */
3366 chipio_set_conn_rate(codec
, MEM_CONNID_DMIC
, SR_32_000
);
3367 ca0132_set_dmic(codec
, 1);
3368 ca0132_mic_boost_set(codec
, 0);
3369 /* set voice focus */
3370 ca0132_effects_set(codec
, VOICE_FOCUS
,
3371 spec
->effects_switch
3372 [VOICE_FOCUS
- EFFECT_START_NID
]);
3374 /* disable digital Mic */
3375 chipio_set_conn_rate(codec
, MEM_CONNID_DMIC
, SR_96_000
);
3376 ca0132_set_dmic(codec
, 0);
3377 ca0132_mic_boost_set(codec
, spec
->cur_mic_boost
);
3378 /* disable voice focus */
3379 ca0132_effects_set(codec
, VOICE_FOCUS
, 0);
3382 snd_hda_power_down(codec
);
3388 * Check if VNODE settings take effect immediately.
3390 static bool ca0132_is_vnode_effective(struct hda_codec
*codec
,
3392 hda_nid_t
*shared_nid
)
3394 struct ca0132_spec
*spec
= codec
->spec
;
3399 nid
= spec
->shared_out_nid
;
3402 nid
= spec
->shared_mic_nid
;
3415 * The following functions are control change helpers.
3416 * They return 0 if no changed. Return 1 if changed.
3418 static int ca0132_voicefx_set(struct hda_codec
*codec
, int enable
)
3420 struct ca0132_spec
*spec
= codec
->spec
;
3423 /* based on CrystalVoice state to enable VoiceFX. */
3425 tmp
= spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] ?
3426 FLOAT_ONE
: FLOAT_ZERO
;
3431 dspio_set_uint_param(codec
, ca0132_voicefx
.mid
,
3432 ca0132_voicefx
.reqs
[0], tmp
);
3438 * Set the effects parameters
3440 static int ca0132_effects_set(struct hda_codec
*codec
, hda_nid_t nid
, long val
)
3442 struct ca0132_spec
*spec
= codec
->spec
;
3444 int num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
3446 int idx
= nid
- EFFECT_START_NID
;
3448 if ((idx
< 0) || (idx
>= num_fx
))
3449 return 0; /* no changed */
3451 /* for out effect, qualify with PE */
3452 if ((nid
>= OUT_EFFECT_START_NID
) && (nid
< OUT_EFFECT_END_NID
)) {
3453 /* if PE if off, turn off out effects. */
3454 if (!spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
])
3458 /* for in effect, qualify with CrystalVoice */
3459 if ((nid
>= IN_EFFECT_START_NID
) && (nid
< IN_EFFECT_END_NID
)) {
3460 /* if CrystalVoice if off, turn off in effects. */
3461 if (!spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
])
3464 /* Voice Focus applies to 2-ch Mic, Digital Mic */
3465 if ((nid
== VOICE_FOCUS
) && (spec
->cur_mic_type
!= DIGITAL_MIC
))
3469 snd_printdd(KERN_INFO
"ca0132_effect_set: nid=0x%x, val=%ld\n",
3472 on
= (val
== 0) ? FLOAT_ZERO
: FLOAT_ONE
;
3473 err
= dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
3474 ca0132_effects
[idx
].reqs
[0], on
);
3477 return 0; /* no changed */
3483 * Turn on/off Playback Enhancements
3485 static int ca0132_pe_switch_set(struct hda_codec
*codec
)
3487 struct ca0132_spec
*spec
= codec
->spec
;
3491 snd_printdd(KERN_INFO
"ca0132_pe_switch_set: val=%ld\n",
3492 spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
]);
3494 i
= OUT_EFFECT_START_NID
- EFFECT_START_NID
;
3495 nid
= OUT_EFFECT_START_NID
;
3496 /* PE affects all out effects */
3497 for (; nid
< OUT_EFFECT_END_NID
; nid
++, i
++)
3498 ret
|= ca0132_effects_set(codec
, nid
, spec
->effects_switch
[i
]);
3503 /* Check if Mic1 is streaming, if so, stop streaming */
3504 static int stop_mic1(struct hda_codec
*codec
)
3506 struct ca0132_spec
*spec
= codec
->spec
;
3507 unsigned int oldval
= snd_hda_codec_read(codec
, spec
->adcs
[0], 0,
3508 AC_VERB_GET_CONV
, 0);
3510 snd_hda_codec_write(codec
, spec
->adcs
[0], 0,
3511 AC_VERB_SET_CHANNEL_STREAMID
,
3516 /* Resume Mic1 streaming if it was stopped. */
3517 static void resume_mic1(struct hda_codec
*codec
, unsigned int oldval
)
3519 struct ca0132_spec
*spec
= codec
->spec
;
3520 /* Restore the previous stream and channel */
3522 snd_hda_codec_write(codec
, spec
->adcs
[0], 0,
3523 AC_VERB_SET_CHANNEL_STREAMID
,
3528 * Turn on/off CrystalVoice
3530 static int ca0132_cvoice_switch_set(struct hda_codec
*codec
)
3532 struct ca0132_spec
*spec
= codec
->spec
;
3535 unsigned int oldval
;
3537 snd_printdd(KERN_INFO
"ca0132_cvoice_switch_set: val=%ld\n",
3538 spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
]);
3540 i
= IN_EFFECT_START_NID
- EFFECT_START_NID
;
3541 nid
= IN_EFFECT_START_NID
;
3542 /* CrystalVoice affects all in effects */
3543 for (; nid
< IN_EFFECT_END_NID
; nid
++, i
++)
3544 ret
|= ca0132_effects_set(codec
, nid
, spec
->effects_switch
[i
]);
3546 /* including VoiceFX */
3547 ret
|= ca0132_voicefx_set(codec
, (spec
->voicefx_val
? 1 : 0));
3549 /* set correct vipsource */
3550 oldval
= stop_mic1(codec
);
3551 ret
|= ca0132_set_vipsource(codec
, 1);
3552 resume_mic1(codec
, oldval
);
3556 static int ca0132_mic_boost_set(struct hda_codec
*codec
, long val
)
3558 struct ca0132_spec
*spec
= codec
->spec
;
3562 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
3563 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, 3);
3565 ret
= snd_hda_codec_amp_update(codec
, spec
->input_pins
[0], 0,
3566 HDA_INPUT
, 0, HDA_AMP_VOLMASK
, 0);
3571 static int ca0132_vnode_switch_set(struct snd_kcontrol
*kcontrol
,
3572 struct snd_ctl_elem_value
*ucontrol
)
3574 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3575 hda_nid_t nid
= get_amp_nid(kcontrol
);
3576 hda_nid_t shared_nid
= 0;
3579 struct ca0132_spec
*spec
= codec
->spec
;
3582 if (nid
== VNID_HP_SEL
) {
3584 spec
->vnode_lswitch
[VNID_HP_ASEL
- VNODE_START_NID
];
3586 ca0132_select_out(codec
);
3590 if (nid
== VNID_AMIC1_SEL
) {
3592 spec
->vnode_lswitch
[VNID_AMIC1_ASEL
- VNODE_START_NID
];
3594 ca0132_select_mic(codec
);
3598 if (nid
== VNID_HP_ASEL
) {
3599 ca0132_select_out(codec
);
3603 if (nid
== VNID_AMIC1_ASEL
) {
3604 ca0132_select_mic(codec
);
3608 /* if effective conditions, then update hw immediately. */
3609 effective
= ca0132_is_vnode_effective(codec
, nid
, &shared_nid
);
3611 int dir
= get_amp_direction(kcontrol
);
3612 int ch
= get_amp_channels(kcontrol
);
3615 mutex_lock(&codec
->control_mutex
);
3616 pval
= kcontrol
->private_value
;
3617 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(shared_nid
, ch
,
3619 ret
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
3620 kcontrol
->private_value
= pval
;
3621 mutex_unlock(&codec
->control_mutex
);
3626 /* End of control change helpers. */
3628 static int ca0132_voicefx_info(struct snd_kcontrol
*kcontrol
,
3629 struct snd_ctl_elem_info
*uinfo
)
3631 unsigned int items
= sizeof(ca0132_voicefx_presets
)
3632 / sizeof(struct ct_voicefx_preset
);
3634 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3636 uinfo
->value
.enumerated
.items
= items
;
3637 if (uinfo
->value
.enumerated
.item
>= items
)
3638 uinfo
->value
.enumerated
.item
= items
- 1;
3639 strcpy(uinfo
->value
.enumerated
.name
,
3640 ca0132_voicefx_presets
[uinfo
->value
.enumerated
.item
].name
);
3644 static int ca0132_voicefx_get(struct snd_kcontrol
*kcontrol
,
3645 struct snd_ctl_elem_value
*ucontrol
)
3647 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3648 struct ca0132_spec
*spec
= codec
->spec
;
3650 ucontrol
->value
.enumerated
.item
[0] = spec
->voicefx_val
;
3654 static int ca0132_voicefx_put(struct snd_kcontrol
*kcontrol
,
3655 struct snd_ctl_elem_value
*ucontrol
)
3657 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3658 struct ca0132_spec
*spec
= codec
->spec
;
3660 int sel
= ucontrol
->value
.enumerated
.item
[0];
3661 unsigned int items
= sizeof(ca0132_voicefx_presets
)
3662 / sizeof(struct ct_voicefx_preset
);
3667 snd_printdd(KERN_INFO
"ca0132_voicefx_put: sel=%d, preset=%s\n",
3668 sel
, ca0132_voicefx_presets
[sel
].name
);
3672 * Default needs to qualify with CrystalVoice state.
3674 for (i
= 0; i
< VOICEFX_MAX_PARAM_COUNT
; i
++) {
3675 err
= dspio_set_uint_param(codec
, ca0132_voicefx
.mid
,
3676 ca0132_voicefx
.reqs
[i
],
3677 ca0132_voicefx_presets
[sel
].vals
[i
]);
3683 spec
->voicefx_val
= sel
;
3684 /* enable voice fx */
3685 ca0132_voicefx_set(codec
, (sel
? 1 : 0));
3691 static int ca0132_switch_get(struct snd_kcontrol
*kcontrol
,
3692 struct snd_ctl_elem_value
*ucontrol
)
3694 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3695 struct ca0132_spec
*spec
= codec
->spec
;
3696 hda_nid_t nid
= get_amp_nid(kcontrol
);
3697 int ch
= get_amp_channels(kcontrol
);
3698 long *valp
= ucontrol
->value
.integer
.value
;
3701 if ((nid
>= VNODE_START_NID
) && (nid
< VNODE_END_NID
)) {
3703 *valp
= spec
->vnode_lswitch
[nid
- VNODE_START_NID
];
3707 *valp
= spec
->vnode_rswitch
[nid
- VNODE_START_NID
];
3713 /* effects, include PE and CrystalVoice */
3714 if ((nid
>= EFFECT_START_NID
) && (nid
< EFFECT_END_NID
)) {
3715 *valp
= spec
->effects_switch
[nid
- EFFECT_START_NID
];
3720 if (nid
== spec
->input_pins
[0]) {
3721 *valp
= spec
->cur_mic_boost
;
3728 static int ca0132_switch_put(struct snd_kcontrol
*kcontrol
,
3729 struct snd_ctl_elem_value
*ucontrol
)
3731 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3732 struct ca0132_spec
*spec
= codec
->spec
;
3733 hda_nid_t nid
= get_amp_nid(kcontrol
);
3734 int ch
= get_amp_channels(kcontrol
);
3735 long *valp
= ucontrol
->value
.integer
.value
;
3738 snd_printdd(KERN_INFO
"ca0132_switch_put: nid=0x%x, val=%ld\n",
3741 snd_hda_power_up(codec
);
3743 if ((nid
>= VNODE_START_NID
) && (nid
< VNODE_END_NID
)) {
3745 spec
->vnode_lswitch
[nid
- VNODE_START_NID
] = *valp
;
3749 spec
->vnode_rswitch
[nid
- VNODE_START_NID
] = *valp
;
3752 changed
= ca0132_vnode_switch_set(kcontrol
, ucontrol
);
3757 if (nid
== PLAY_ENHANCEMENT
) {
3758 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
3759 changed
= ca0132_pe_switch_set(codec
);
3764 if (nid
== CRYSTAL_VOICE
) {
3765 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
3766 changed
= ca0132_cvoice_switch_set(codec
);
3770 /* out and in effects */
3771 if (((nid
>= OUT_EFFECT_START_NID
) && (nid
< OUT_EFFECT_END_NID
)) ||
3772 ((nid
>= IN_EFFECT_START_NID
) && (nid
< IN_EFFECT_END_NID
))) {
3773 spec
->effects_switch
[nid
- EFFECT_START_NID
] = *valp
;
3774 changed
= ca0132_effects_set(codec
, nid
, *valp
);
3779 if (nid
== spec
->input_pins
[0]) {
3780 spec
->cur_mic_boost
= *valp
;
3782 /* Mic boost does not apply to Digital Mic */
3783 if (spec
->cur_mic_type
!= DIGITAL_MIC
)
3784 changed
= ca0132_mic_boost_set(codec
, *valp
);
3789 snd_hda_power_down(codec
);
3796 static int ca0132_volume_info(struct snd_kcontrol
*kcontrol
,
3797 struct snd_ctl_elem_info
*uinfo
)
3799 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3800 struct ca0132_spec
*spec
= codec
->spec
;
3801 hda_nid_t nid
= get_amp_nid(kcontrol
);
3802 int ch
= get_amp_channels(kcontrol
);
3803 int dir
= get_amp_direction(kcontrol
);
3809 /* follow shared_out info */
3810 nid
= spec
->shared_out_nid
;
3811 mutex_lock(&codec
->control_mutex
);
3812 pval
= kcontrol
->private_value
;
3813 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
3814 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
3815 kcontrol
->private_value
= pval
;
3816 mutex_unlock(&codec
->control_mutex
);
3819 /* follow shared_mic info */
3820 nid
= spec
->shared_mic_nid
;
3821 mutex_lock(&codec
->control_mutex
);
3822 pval
= kcontrol
->private_value
;
3823 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
3824 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
3825 kcontrol
->private_value
= pval
;
3826 mutex_unlock(&codec
->control_mutex
);
3829 err
= snd_hda_mixer_amp_volume_info(kcontrol
, uinfo
);
3834 static int ca0132_volume_get(struct snd_kcontrol
*kcontrol
,
3835 struct snd_ctl_elem_value
*ucontrol
)
3837 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3838 struct ca0132_spec
*spec
= codec
->spec
;
3839 hda_nid_t nid
= get_amp_nid(kcontrol
);
3840 int ch
= get_amp_channels(kcontrol
);
3841 long *valp
= ucontrol
->value
.integer
.value
;
3843 /* store the left and right volume */
3845 *valp
= spec
->vnode_lvol
[nid
- VNODE_START_NID
];
3849 *valp
= spec
->vnode_rvol
[nid
- VNODE_START_NID
];
3855 static int ca0132_volume_put(struct snd_kcontrol
*kcontrol
,
3856 struct snd_ctl_elem_value
*ucontrol
)
3858 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3859 struct ca0132_spec
*spec
= codec
->spec
;
3860 hda_nid_t nid
= get_amp_nid(kcontrol
);
3861 int ch
= get_amp_channels(kcontrol
);
3862 long *valp
= ucontrol
->value
.integer
.value
;
3863 hda_nid_t shared_nid
= 0;
3867 /* store the left and right volume */
3869 spec
->vnode_lvol
[nid
- VNODE_START_NID
] = *valp
;
3873 spec
->vnode_rvol
[nid
- VNODE_START_NID
] = *valp
;
3877 /* if effective conditions, then update hw immediately. */
3878 effective
= ca0132_is_vnode_effective(codec
, nid
, &shared_nid
);
3880 int dir
= get_amp_direction(kcontrol
);
3883 snd_hda_power_up(codec
);
3884 mutex_lock(&codec
->control_mutex
);
3885 pval
= kcontrol
->private_value
;
3886 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(shared_nid
, ch
,
3888 changed
= snd_hda_mixer_amp_volume_put(kcontrol
, ucontrol
);
3889 kcontrol
->private_value
= pval
;
3890 mutex_unlock(&codec
->control_mutex
);
3891 snd_hda_power_down(codec
);
3897 static int ca0132_volume_tlv(struct snd_kcontrol
*kcontrol
, int op_flag
,
3898 unsigned int size
, unsigned int __user
*tlv
)
3900 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3901 struct ca0132_spec
*spec
= codec
->spec
;
3902 hda_nid_t nid
= get_amp_nid(kcontrol
);
3903 int ch
= get_amp_channels(kcontrol
);
3904 int dir
= get_amp_direction(kcontrol
);
3910 /* follow shared_out tlv */
3911 nid
= spec
->shared_out_nid
;
3912 mutex_lock(&codec
->control_mutex
);
3913 pval
= kcontrol
->private_value
;
3914 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
3915 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
3916 kcontrol
->private_value
= pval
;
3917 mutex_unlock(&codec
->control_mutex
);
3920 /* follow shared_mic tlv */
3921 nid
= spec
->shared_mic_nid
;
3922 mutex_lock(&codec
->control_mutex
);
3923 pval
= kcontrol
->private_value
;
3924 kcontrol
->private_value
= HDA_COMPOSE_AMP_VAL(nid
, ch
, 0, dir
);
3925 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
3926 kcontrol
->private_value
= pval
;
3927 mutex_unlock(&codec
->control_mutex
);
3930 err
= snd_hda_mixer_amp_tlv(kcontrol
, op_flag
, size
, tlv
);
3935 static int add_fx_switch(struct hda_codec
*codec
, hda_nid_t nid
,
3936 const char *pfx
, int dir
)
3938 char namestr
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3939 int type
= dir
? HDA_INPUT
: HDA_OUTPUT
;
3940 struct snd_kcontrol_new knew
=
3941 CA0132_CODEC_MUTE_MONO(namestr
, nid
, 1, type
);
3942 sprintf(namestr
, "%s %s Switch", pfx
, dirstr
[dir
]);
3943 return snd_hda_ctl_add(codec
, nid
, snd_ctl_new1(&knew
, codec
));
3946 static int add_voicefx(struct hda_codec
*codec
)
3948 struct snd_kcontrol_new knew
=
3949 HDA_CODEC_MUTE_MONO(ca0132_voicefx
.name
,
3950 VOICEFX
, 1, 0, HDA_INPUT
);
3951 knew
.info
= ca0132_voicefx_info
;
3952 knew
.get
= ca0132_voicefx_get
;
3953 knew
.put
= ca0132_voicefx_put
;
3954 return snd_hda_ctl_add(codec
, VOICEFX
, snd_ctl_new1(&knew
, codec
));
3958 * When changing Node IDs for Mixer Controls below, make sure to update
3959 * Node IDs in ca0132_config() as well.
3961 static struct snd_kcontrol_new ca0132_mixer
[] = {
3962 CA0132_CODEC_VOL("Master Playback Volume", VNID_SPK
, HDA_OUTPUT
),
3963 CA0132_CODEC_MUTE("Master Playback Switch", VNID_SPK
, HDA_OUTPUT
),
3964 CA0132_CODEC_VOL("Capture Volume", VNID_MIC
, HDA_INPUT
),
3965 CA0132_CODEC_MUTE("Capture Switch", VNID_MIC
, HDA_INPUT
),
3966 HDA_CODEC_VOLUME("Analog-Mic2 Capture Volume", 0x08, 0, HDA_INPUT
),
3967 HDA_CODEC_MUTE("Analog-Mic2 Capture Switch", 0x08, 0, HDA_INPUT
),
3968 HDA_CODEC_VOLUME("What U Hear Capture Volume", 0x0a, 0, HDA_INPUT
),
3969 HDA_CODEC_MUTE("What U Hear Capture Switch", 0x0a, 0, HDA_INPUT
),
3970 CA0132_CODEC_MUTE_MONO("Mic1-Boost (30dB) Capture Switch",
3971 0x12, 1, HDA_INPUT
),
3972 CA0132_CODEC_MUTE_MONO("HP/Speaker Playback Switch",
3973 VNID_HP_SEL
, 1, HDA_OUTPUT
),
3974 CA0132_CODEC_MUTE_MONO("AMic1/DMic Capture Switch",
3975 VNID_AMIC1_SEL
, 1, HDA_INPUT
),
3976 CA0132_CODEC_MUTE_MONO("HP/Speaker Auto Detect Playback Switch",
3977 VNID_HP_ASEL
, 1, HDA_OUTPUT
),
3978 CA0132_CODEC_MUTE_MONO("AMic1/DMic Auto Detect Capture Switch",
3979 VNID_AMIC1_ASEL
, 1, HDA_INPUT
),
3983 static int ca0132_build_controls(struct hda_codec
*codec
)
3985 struct ca0132_spec
*spec
= codec
->spec
;
3989 /* Add Mixer controls */
3990 for (i
= 0; i
< spec
->num_mixers
; i
++) {
3991 err
= snd_hda_add_new_ctls(codec
, spec
->mixers
[i
]);
3996 /* Add in and out effects controls.
3997 * VoiceFX, PE and CrystalVoice are added separately.
3999 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
4000 for (i
= 0; i
< num_fx
; i
++) {
4001 err
= add_fx_switch(codec
, ca0132_effects
[i
].nid
,
4002 ca0132_effects
[i
].name
,
4003 ca0132_effects
[i
].direct
);
4008 err
= add_fx_switch(codec
, PLAY_ENHANCEMENT
, "PlayEnhancement", 0);
4012 err
= add_fx_switch(codec
, CRYSTAL_VOICE
, "CrystalVoice", 1);
4018 #ifdef ENABLE_TUNING_CONTROLS
4019 add_tuning_ctls(codec
);
4022 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
4026 if (spec
->dig_out
) {
4027 err
= snd_hda_create_spdif_out_ctls(codec
, spec
->dig_out
,
4031 err
= snd_hda_create_spdif_share_sw(codec
, &spec
->multiout
);
4034 /* spec->multiout.share_spdif = 1; */
4038 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in
);
4048 static struct hda_pcm_stream ca0132_pcm_analog_playback
= {
4053 .prepare
= ca0132_playback_pcm_prepare
,
4054 .cleanup
= ca0132_playback_pcm_cleanup
,
4055 .get_delay
= ca0132_playback_pcm_delay
,
4059 static struct hda_pcm_stream ca0132_pcm_analog_capture
= {
4064 .prepare
= ca0132_capture_pcm_prepare
,
4065 .cleanup
= ca0132_capture_pcm_cleanup
,
4066 .get_delay
= ca0132_capture_pcm_delay
,
4070 static struct hda_pcm_stream ca0132_pcm_digital_playback
= {
4075 .open
= ca0132_dig_playback_pcm_open
,
4076 .close
= ca0132_dig_playback_pcm_close
,
4077 .prepare
= ca0132_dig_playback_pcm_prepare
,
4078 .cleanup
= ca0132_dig_playback_pcm_cleanup
4082 static struct hda_pcm_stream ca0132_pcm_digital_capture
= {
4088 static int ca0132_build_pcms(struct hda_codec
*codec
)
4090 struct ca0132_spec
*spec
= codec
->spec
;
4091 struct hda_pcm
*info
= spec
->pcm_rec
;
4093 codec
->pcm_info
= info
;
4094 codec
->num_pcms
= 0;
4096 info
->name
= "CA0132 Analog";
4097 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = ca0132_pcm_analog_playback
;
4098 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dacs
[0];
4099 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
4100 spec
->multiout
.max_channels
;
4101 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
4102 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
4103 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[0];
4107 info
->name
= "CA0132 Analog Mic-In2";
4108 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
4109 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
4110 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[1];
4114 info
->name
= "CA0132 What U Hear";
4115 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = ca0132_pcm_analog_capture
;
4116 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
= 1;
4117 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adcs
[2];
4120 if (!spec
->dig_out
&& !spec
->dig_in
)
4124 info
->name
= "CA0132 Digital";
4125 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
4126 if (spec
->dig_out
) {
4127 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
4128 ca0132_pcm_digital_playback
;
4129 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->dig_out
;
4132 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
4133 ca0132_pcm_digital_capture
;
4134 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in
;
4141 static void init_output(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t dac
)
4144 snd_hda_set_pin_ctl(codec
, pin
, PIN_HP
);
4145 if (get_wcaps(codec
, pin
) & AC_WCAP_OUT_AMP
)
4146 snd_hda_codec_write(codec
, pin
, 0,
4147 AC_VERB_SET_AMP_GAIN_MUTE
,
4150 if (dac
&& (get_wcaps(codec
, dac
) & AC_WCAP_OUT_AMP
))
4151 snd_hda_codec_write(codec
, dac
, 0,
4152 AC_VERB_SET_AMP_GAIN_MUTE
, AMP_OUT_ZERO
);
4155 static void init_input(struct hda_codec
*codec
, hda_nid_t pin
, hda_nid_t adc
)
4158 snd_hda_set_pin_ctl(codec
, pin
, PIN_VREF80
);
4159 if (get_wcaps(codec
, pin
) & AC_WCAP_IN_AMP
)
4160 snd_hda_codec_write(codec
, pin
, 0,
4161 AC_VERB_SET_AMP_GAIN_MUTE
,
4164 if (adc
&& (get_wcaps(codec
, adc
) & AC_WCAP_IN_AMP
)) {
4165 snd_hda_codec_write(codec
, adc
, 0, AC_VERB_SET_AMP_GAIN_MUTE
,
4168 /* init to 0 dB and unmute. */
4169 snd_hda_codec_amp_stereo(codec
, adc
, HDA_INPUT
, 0,
4170 HDA_AMP_VOLMASK
, 0x5a);
4171 snd_hda_codec_amp_stereo(codec
, adc
, HDA_INPUT
, 0,
4176 static void ca0132_init_unsol(struct hda_codec
*codec
)
4178 snd_hda_jack_detect_enable(codec
, UNSOL_TAG_HP
, UNSOL_TAG_HP
);
4179 snd_hda_jack_detect_enable(codec
, UNSOL_TAG_AMIC1
, UNSOL_TAG_AMIC1
);
4182 static void refresh_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
, int dir
)
4186 caps
= snd_hda_param_read(codec
, nid
, dir
== HDA_OUTPUT
?
4187 AC_PAR_AMP_OUT_CAP
: AC_PAR_AMP_IN_CAP
);
4188 snd_hda_override_amp_caps(codec
, nid
, dir
, caps
);
4192 * Switch between Digital built-in mic and analog mic.
4194 static void ca0132_set_dmic(struct hda_codec
*codec
, int enable
)
4196 struct ca0132_spec
*spec
= codec
->spec
;
4199 unsigned int oldval
;
4201 snd_printdd(KERN_INFO
"ca0132_set_dmic: enable=%d\n", enable
);
4203 oldval
= stop_mic1(codec
);
4204 ca0132_set_vipsource(codec
, 0);
4206 /* set DMic input as 2-ch */
4208 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4210 val
= spec
->dmic_ctl
;
4212 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
4213 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
4215 if (!(spec
->dmic_ctl
& 0x20))
4216 chipio_set_control_flag(codec
, CONTROL_FLAG_DMIC
, 1);
4218 /* set AMic input as mono */
4220 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4222 val
= spec
->dmic_ctl
;
4223 /* clear bit7 and bit5 to disable dmic */
4225 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
4226 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
4228 if (!(spec
->dmic_ctl
& 0x20))
4229 chipio_set_control_flag(codec
, CONTROL_FLAG_DMIC
, 0);
4231 ca0132_set_vipsource(codec
, 1);
4232 resume_mic1(codec
, oldval
);
4236 * Initialization for Digital Mic.
4238 static void ca0132_init_dmic(struct hda_codec
*codec
)
4240 struct ca0132_spec
*spec
= codec
->spec
;
4243 /* Setup Digital Mic here, but don't enable.
4244 * Enable based on jack detect.
4247 /* MCLK uses MPIO1, set to enable.
4248 * Bit 2-0: MPIO select
4249 * Bit 3: set to disable
4253 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
4254 VENDOR_CHIPIO_DMIC_MCLK_SET
, val
);
4256 /* Data1 uses MPIO3. Data2 not use
4257 * Bit 2-0: Data1 MPIO select
4258 * Bit 3: set disable Data1
4259 * Bit 6-4: Data2 MPIO select
4260 * Bit 7: set disable Data2
4263 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
4264 VENDOR_CHIPIO_DMIC_PIN_SET
, val
);
4266 /* Use Ch-0 and Ch-1. Rate is 48K, mode 1. Disable DMic first.
4267 * Bit 3-0: Channel mask
4268 * Bit 4: set for 48KHz, clear for 32KHz
4270 * Bit 6: set to select Data2, clear for Data1
4271 * Bit 7: set to enable DMic, clear for AMic
4274 /* keep a copy of dmic ctl val for enable/disable dmic purpuse */
4275 spec
->dmic_ctl
= val
;
4276 snd_hda_codec_write(codec
, spec
->input_pins
[0], 0,
4277 VENDOR_CHIPIO_DMIC_CTL_SET
, val
);
4281 * Initialization for Analog Mic 2
4283 static void ca0132_init_analog_mic2(struct hda_codec
*codec
)
4285 struct ca0132_spec
*spec
= codec
->spec
;
4287 mutex_lock(&spec
->chipio_mutex
);
4288 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
4289 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x20);
4290 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
4291 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x19);
4292 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
4293 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x00);
4294 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
4295 VENDOR_CHIPIO_8051_ADDRESS_LOW
, 0x2D);
4296 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
4297 VENDOR_CHIPIO_8051_ADDRESS_HIGH
, 0x19);
4298 snd_hda_codec_write(codec
, WIDGET_CHIP_CTRL
, 0,
4299 VENDOR_CHIPIO_8051_DATA_WRITE
, 0x00);
4300 mutex_unlock(&spec
->chipio_mutex
);
4303 static void ca0132_refresh_widget_caps(struct hda_codec
*codec
)
4305 struct ca0132_spec
*spec
= codec
->spec
;
4309 snd_printdd(KERN_INFO
"ca0132_refresh_widget_caps.\n");
4310 nid
= codec
->start_nid
;
4311 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++)
4312 codec
->wcaps
[i
] = snd_hda_param_read(codec
, nid
,
4313 AC_PAR_AUDIO_WIDGET_CAP
);
4315 for (i
= 0; i
< spec
->multiout
.num_dacs
; i
++)
4316 refresh_amp_caps(codec
, spec
->dacs
[i
], HDA_OUTPUT
);
4318 for (i
= 0; i
< spec
->num_outputs
; i
++)
4319 refresh_amp_caps(codec
, spec
->out_pins
[i
], HDA_OUTPUT
);
4321 for (i
= 0; i
< spec
->num_inputs
; i
++) {
4322 refresh_amp_caps(codec
, spec
->adcs
[i
], HDA_INPUT
);
4323 refresh_amp_caps(codec
, spec
->input_pins
[i
], HDA_INPUT
);
4328 * Setup default parameters for DSP
4330 static void ca0132_setup_defaults(struct hda_codec
*codec
)
4332 struct ca0132_spec
*spec
= codec
->spec
;
4337 if (spec
->dsp_state
!= DSP_DOWNLOADED
)
4340 /* out, in effects + voicefx */
4341 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
+ 1;
4342 for (idx
= 0; idx
< num_fx
; idx
++) {
4343 for (i
= 0; i
<= ca0132_effects
[idx
].params
; i
++) {
4344 dspio_set_uint_param(codec
, ca0132_effects
[idx
].mid
,
4345 ca0132_effects
[idx
].reqs
[i
],
4346 ca0132_effects
[idx
].def_vals
[i
]);
4350 /*remove DSP headroom*/
4352 dspio_set_uint_param(codec
, 0x96, 0x3C, tmp
);
4354 /*set speaker EQ bypass attenuation*/
4355 dspio_set_uint_param(codec
, 0x8f, 0x01, tmp
);
4357 /* set AMic1 and AMic2 as mono mic */
4359 dspio_set_uint_param(codec
, 0x80, 0x00, tmp
);
4360 dspio_set_uint_param(codec
, 0x80, 0x01, tmp
);
4362 /* set AMic1 as CrystalVoice input */
4364 dspio_set_uint_param(codec
, 0x80, 0x05, tmp
);
4366 /* set WUH source */
4368 dspio_set_uint_param(codec
, 0x31, 0x00, tmp
);
4372 * Initialization of flags in chip
4374 static void ca0132_init_flags(struct hda_codec
*codec
)
4376 chipio_set_control_flag(codec
, CONTROL_FLAG_IDLE_ENABLE
, 0);
4377 chipio_set_control_flag(codec
, CONTROL_FLAG_PORT_A_COMMON_MODE
, 0);
4378 chipio_set_control_flag(codec
, CONTROL_FLAG_PORT_D_COMMON_MODE
, 0);
4379 chipio_set_control_flag(codec
, CONTROL_FLAG_PORT_A_10KOHM_LOAD
, 0);
4380 chipio_set_control_flag(codec
, CONTROL_FLAG_PORT_D_10KOHM_LOAD
, 0);
4381 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_HIGH_PASS
, 1);
4385 * Initialization of parameters in chip
4387 static void ca0132_init_params(struct hda_codec
*codec
)
4389 chipio_set_control_param(codec
, CONTROL_PARAM_PORTA_160OHM_GAIN
, 6);
4390 chipio_set_control_param(codec
, CONTROL_PARAM_PORTD_160OHM_GAIN
, 6);
4393 static void ca0132_set_dsp_msr(struct hda_codec
*codec
, bool is96k
)
4395 chipio_set_control_flag(codec
, CONTROL_FLAG_DSP_96KHZ
, is96k
);
4396 chipio_set_control_flag(codec
, CONTROL_FLAG_DAC_96KHZ
, is96k
);
4397 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_RATE_96KHZ
, is96k
);
4398 chipio_set_control_flag(codec
, CONTROL_FLAG_SRC_CLOCK_196MHZ
, is96k
);
4399 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_B_96KHZ
, is96k
);
4400 chipio_set_control_flag(codec
, CONTROL_FLAG_ADC_C_96KHZ
, is96k
);
4402 chipio_set_conn_rate(codec
, MEM_CONNID_MICIN1
, SR_96_000
);
4403 chipio_set_conn_rate(codec
, MEM_CONNID_MICOUT1
, SR_96_000
);
4404 chipio_set_conn_rate(codec
, MEM_CONNID_WUH
, SR_48_000
);
4407 static bool ca0132_download_dsp_images(struct hda_codec
*codec
)
4409 bool dsp_loaded
= false;
4410 const struct dsp_image_seg
*dsp_os_image
;
4411 const struct firmware
*fw_entry
;
4413 if (request_firmware(&fw_entry
, EFX_FILE
, codec
->bus
->card
->dev
) != 0)
4416 dsp_os_image
= (struct dsp_image_seg
*)(fw_entry
->data
);
4417 if (dspload_image(codec
, dsp_os_image
, 0, 0, true, 0)) {
4418 pr_err("ca0132 dspload_image failed.\n");
4422 dsp_loaded
= dspload_wait_loaded(codec
);
4425 release_firmware(fw_entry
);
4430 static void ca0132_download_dsp(struct hda_codec
*codec
)
4432 struct ca0132_spec
*spec
= codec
->spec
;
4434 #ifndef CONFIG_SND_HDA_CODEC_CA0132_DSP
4438 chipio_enable_clocks(codec
);
4439 spec
->dsp_state
= DSP_DOWNLOADING
;
4440 if (!ca0132_download_dsp_images(codec
))
4441 spec
->dsp_state
= DSP_DOWNLOAD_FAILED
;
4443 spec
->dsp_state
= DSP_DOWNLOADED
;
4445 if (spec
->dsp_state
== DSP_DOWNLOADED
)
4446 ca0132_set_dsp_msr(codec
, true);
4449 static void ca0132_process_dsp_response(struct hda_codec
*codec
)
4451 struct ca0132_spec
*spec
= codec
->spec
;
4453 snd_printdd(KERN_INFO
"ca0132_process_dsp_response\n");
4454 if (spec
->wait_scp
) {
4455 if (dspio_get_response_data(codec
) >= 0)
4459 dspio_clear_response_queue(codec
);
4462 static void ca0132_unsol_event(struct hda_codec
*codec
, unsigned int res
)
4464 struct ca0132_spec
*spec
= codec
->spec
;
4466 if (((res
>> AC_UNSOL_RES_TAG_SHIFT
) & 0x3f) == UNSOL_TAG_DSP
) {
4467 ca0132_process_dsp_response(codec
);
4469 res
= snd_hda_jack_get_action(codec
,
4470 (res
>> AC_UNSOL_RES_TAG_SHIFT
) & 0x3f);
4472 snd_printdd(KERN_INFO
"snd_hda_jack_get_action: 0x%x\n", res
);
4476 /* Delay enabling the HP amp, to let the mic-detection
4477 * state machine run.
4479 cancel_delayed_work_sync(&spec
->unsol_hp_work
);
4480 queue_delayed_work(codec
->bus
->workq
,
4481 &spec
->unsol_hp_work
,
4482 msecs_to_jiffies(500));
4484 case UNSOL_TAG_AMIC1
:
4485 ca0132_select_mic(codec
);
4486 snd_hda_jack_report_sync(codec
);
4498 /* Sends before DSP download. */
4499 static struct hda_verb ca0132_base_init_verbs
[] = {
4500 /*enable ct extension*/
4501 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
, 0x1},
4502 /*enable DSP node unsol, needed for DSP download*/
4503 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| UNSOL_TAG_DSP
},
4508 static struct hda_verb ca0132_base_exit_verbs
[] = {
4510 {0x01, AC_VERB_SET_POWER_STATE
, 0x03},
4511 /*disable ct extension*/
4512 {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE
, 0},
4516 /* Other verbs tables. Sends after DSP download. */
4517 static struct hda_verb ca0132_init_verbs0
[] = {
4518 /* chip init verbs */
4519 {0x15, 0x70D, 0xF0},
4520 {0x15, 0x70E, 0xFE},
4521 {0x15, 0x707, 0x75},
4522 {0x15, 0x707, 0xD3},
4523 {0x15, 0x707, 0x09},
4524 {0x15, 0x707, 0x53},
4525 {0x15, 0x707, 0xD4},
4526 {0x15, 0x707, 0xEF},
4527 {0x15, 0x707, 0x75},
4528 {0x15, 0x707, 0xD3},
4529 {0x15, 0x707, 0x09},
4530 {0x15, 0x707, 0x02},
4531 {0x15, 0x707, 0x37},
4532 {0x15, 0x707, 0x78},
4533 {0x15, 0x53C, 0xCE},
4534 {0x15, 0x575, 0xC9},
4535 {0x15, 0x53D, 0xCE},
4536 {0x15, 0x5B7, 0xC9},
4537 {0x15, 0x70D, 0xE8},
4538 {0x15, 0x70E, 0xFE},
4539 {0x15, 0x707, 0x02},
4540 {0x15, 0x707, 0x68},
4541 {0x15, 0x707, 0x62},
4542 {0x15, 0x53A, 0xCE},
4543 {0x15, 0x546, 0xC9},
4544 {0x15, 0x53B, 0xCE},
4545 {0x15, 0x5E8, 0xC9},
4546 {0x15, 0x717, 0x0D},
4547 {0x15, 0x718, 0x20},
4551 static struct hda_verb ca0132_init_verbs1
[] = {
4552 {0x10, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| UNSOL_TAG_HP
},
4553 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE
, AC_USRSP_EN
| UNSOL_TAG_AMIC1
},
4555 {0x0b, 0x78D, 0x00},
4556 /*{0x0b, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/
4557 /*{0x10, 0x78D, 0x02},*/
4558 /*{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/
4562 static void ca0132_init_chip(struct hda_codec
*codec
)
4564 struct ca0132_spec
*spec
= codec
->spec
;
4569 mutex_init(&spec
->chipio_mutex
);
4571 spec
->cur_out_type
= SPEAKER_OUT
;
4572 spec
->cur_mic_type
= DIGITAL_MIC
;
4573 spec
->cur_mic_boost
= 0;
4575 for (i
= 0; i
< VNODES_COUNT
; i
++) {
4576 spec
->vnode_lvol
[i
] = 0x5a;
4577 spec
->vnode_rvol
[i
] = 0x5a;
4578 spec
->vnode_lswitch
[i
] = 0;
4579 spec
->vnode_rswitch
[i
] = 0;
4583 * Default states for effects are in ca0132_effects[].
4585 num_fx
= OUT_EFFECTS_COUNT
+ IN_EFFECTS_COUNT
;
4586 for (i
= 0; i
< num_fx
; i
++) {
4587 on
= (unsigned int)ca0132_effects
[i
].reqs
[0];
4588 spec
->effects_switch
[i
] = on
? 1 : 0;
4591 spec
->voicefx_val
= 0;
4592 spec
->effects_switch
[PLAY_ENHANCEMENT
- EFFECT_START_NID
] = 1;
4593 spec
->effects_switch
[CRYSTAL_VOICE
- EFFECT_START_NID
] = 0;
4595 #ifdef ENABLE_TUNING_CONTROLS
4596 ca0132_init_tuning_defaults(codec
);
4600 static void ca0132_exit_chip(struct hda_codec
*codec
)
4602 /* put any chip cleanup stuffs here. */
4604 if (dspload_is_loaded(codec
))
4608 static int ca0132_init(struct hda_codec
*codec
)
4610 struct ca0132_spec
*spec
= codec
->spec
;
4611 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4614 spec
->dsp_state
= DSP_DOWNLOAD_INIT
;
4615 spec
->curr_chip_addx
= INVALID_CHIP_ADDRESS
;
4617 snd_hda_power_up(codec
);
4619 ca0132_init_params(codec
);
4620 ca0132_init_flags(codec
);
4621 snd_hda_sequence_write(codec
, spec
->base_init_verbs
);
4622 ca0132_download_dsp(codec
);
4623 ca0132_refresh_widget_caps(codec
);
4624 ca0132_setup_defaults(codec
);
4625 ca0132_init_analog_mic2(codec
);
4626 ca0132_init_dmic(codec
);
4628 for (i
= 0; i
< spec
->num_outputs
; i
++)
4629 init_output(codec
, spec
->out_pins
[i
], spec
->dacs
[0]);
4631 init_output(codec
, cfg
->dig_out_pins
[0], spec
->dig_out
);
4633 for (i
= 0; i
< spec
->num_inputs
; i
++)
4634 init_input(codec
, spec
->input_pins
[i
], spec
->adcs
[i
]);
4636 init_input(codec
, cfg
->dig_in_pin
, spec
->dig_in
);
4638 for (i
= 0; i
< spec
->num_init_verbs
; i
++)
4639 snd_hda_sequence_write(codec
, spec
->init_verbs
[i
]);
4641 ca0132_init_unsol(codec
);
4643 ca0132_select_out(codec
);
4644 ca0132_select_mic(codec
);
4646 snd_hda_jack_report_sync(codec
);
4648 snd_hda_power_down(codec
);
4653 static void ca0132_free(struct hda_codec
*codec
)
4655 struct ca0132_spec
*spec
= codec
->spec
;
4657 cancel_delayed_work_sync(&spec
->unsol_hp_work
);
4658 snd_hda_power_up(codec
);
4659 snd_hda_sequence_write(codec
, spec
->base_exit_verbs
);
4660 ca0132_exit_chip(codec
);
4661 snd_hda_power_down(codec
);
4665 static struct hda_codec_ops ca0132_patch_ops
= {
4666 .build_controls
= ca0132_build_controls
,
4667 .build_pcms
= ca0132_build_pcms
,
4668 .init
= ca0132_init
,
4669 .free
= ca0132_free
,
4670 .unsol_event
= ca0132_unsol_event
,
4673 static void ca0132_config(struct hda_codec
*codec
)
4675 struct ca0132_spec
*spec
= codec
->spec
;
4676 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4678 spec
->dacs
[0] = 0x2;
4679 spec
->dacs
[1] = 0x3;
4680 spec
->dacs
[2] = 0x4;
4682 spec
->multiout
.dac_nids
= spec
->dacs
;
4683 spec
->multiout
.num_dacs
= 3;
4684 spec
->multiout
.max_channels
= 2;
4686 spec
->num_outputs
= 2;
4687 spec
->out_pins
[0] = 0x0b; /* speaker out */
4688 spec
->out_pins
[1] = 0x10; /* headphone out */
4689 spec
->shared_out_nid
= 0x2;
4691 spec
->num_inputs
= 3;
4692 spec
->adcs
[0] = 0x7; /* digital mic / analog mic1 */
4693 spec
->adcs
[1] = 0x8; /* analog mic2 */
4694 spec
->adcs
[2] = 0xa; /* what u hear */
4695 spec
->shared_mic_nid
= 0x7;
4697 spec
->input_pins
[0] = 0x12;
4698 spec
->input_pins
[1] = 0x11;
4699 spec
->input_pins
[2] = 0x13;
4702 spec
->dig_out
= 0x05;
4703 spec
->multiout
.dig_out_nid
= spec
->dig_out
;
4704 cfg
->dig_out_pins
[0] = 0x0c;
4706 cfg
->dig_out_type
[0] = HDA_PCM_TYPE_SPDIF
;
4707 spec
->dig_in
= 0x09;
4708 cfg
->dig_in_pin
= 0x0e;
4709 cfg
->dig_in_type
= HDA_PCM_TYPE_SPDIF
;
4712 static int patch_ca0132(struct hda_codec
*codec
)
4714 struct ca0132_spec
*spec
;
4717 snd_printdd("patch_ca0132\n");
4719 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
4723 spec
->codec
= codec
;
4725 spec
->num_mixers
= 1;
4726 spec
->mixers
[0] = ca0132_mixer
;
4728 spec
->base_init_verbs
= ca0132_base_init_verbs
;
4729 spec
->base_exit_verbs
= ca0132_base_exit_verbs
;
4730 spec
->init_verbs
[0] = ca0132_init_verbs0
;
4731 spec
->init_verbs
[1] = ca0132_init_verbs1
;
4732 spec
->num_init_verbs
= 2;
4734 INIT_DELAYED_WORK(&spec
->unsol_hp_work
, ca0132_unsol_hp_delayed
);
4736 ca0132_init_chip(codec
);
4738 ca0132_config(codec
);
4740 err
= snd_hda_parse_pin_def_config(codec
, &spec
->autocfg
, NULL
);
4744 codec
->patch_ops
= ca0132_patch_ops
;
4752 static struct hda_codec_preset snd_hda_preset_ca0132
[] = {
4753 { .id
= 0x11020011, .name
= "CA0132", .patch
= patch_ca0132
},
4757 MODULE_ALIAS("snd-hda-codec-id:11020011");
4759 MODULE_LICENSE("GPL");
4760 MODULE_DESCRIPTION("Creative Sound Core3D codec");
4762 static struct hda_codec_preset_list ca0132_list
= {
4763 .preset
= snd_hda_preset_ca0132
,
4764 .owner
= THIS_MODULE
,
4767 static int __init
patch_ca0132_init(void)
4769 return snd_hda_add_codec_preset(&ca0132_list
);
4772 static void __exit
patch_ca0132_exit(void)
4774 snd_hda_delete_codec_preset(&ca0132_list
);
4777 module_init(patch_ca0132_init
)
4778 module_exit(patch_ca0132_exit
)