--- zzzz-none-000/linux-3.10.107/sound/pci/hda/patch_ca0132.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/sound/pci/hda/patch_ca0132.c 2021-02-04 17:41:59.000000000 +0000 @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -44,8 +43,6 @@ #define FLOAT_TWO 0x40000000 #define FLOAT_MINUS_5 0xc0a00000 -#define UNSOL_TAG_HP 0x10 -#define UNSOL_TAG_AMIC1 0x12 #define UNSOL_TAG_DSP 0x16 #define DSP_DMA_WRITE_BUFLEN_INIT (1UL<<18) @@ -139,7 +136,7 @@ #define DSP_SPEAKER_OUT_LATENCY 7 struct ct_effect { - char name[44]; + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; hda_nid_t nid; int mid; /*effect module ID*/ int reqs[EFFECT_VALS_MAX_COUNT]; /*effect module request*/ @@ -270,7 +267,7 @@ }; struct ct_tuning_ctl { - char name[44]; + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; hda_nid_t parent_nid; hda_nid_t nid; int mid; /*effect module ID*/ @@ -704,8 +701,8 @@ unsigned int num_mixers; const struct hda_verb *base_init_verbs; const struct hda_verb *base_exit_verbs; - const struct hda_verb *init_verbs[5]; - unsigned int num_init_verbs; /* exclude base init verbs */ + const struct hda_verb *chip_init_verbs; + struct hda_verb *spec_init_verbs; struct auto_pin_cfg autocfg; /* Nodes configurations */ @@ -720,7 +717,8 @@ unsigned int num_inputs; hda_nid_t shared_mic_nid; hda_nid_t shared_out_nid; - struct hda_pcm pcm_rec[5]; /* PCM information */ + hda_nid_t unsol_tag_hp; + hda_nid_t unsol_tag_amic1; /* chip access */ struct mutex chipio_mutex; /* chip access mutex */ @@ -750,6 +748,7 @@ struct hda_codec *codec; struct delayed_work unsol_hp_work; + int quirk; #ifdef ENABLE_TUNING_CONTROLS long cur_ctl_vals[TUNING_CTLS_COUNT]; @@ -757,9 +756,38 @@ }; /* + * CA0132 quirks table + */ +enum { + QUIRK_NONE, + QUIRK_ALIENWARE, +}; + +static const struct hda_pintbl alienware_pincfgs[] = { + { 0x0b, 0x90170110 }, /* Builtin Speaker */ + { 0x0c, 0x411111f0 }, /* N/A */ + { 0x0d, 0x411111f0 }, /* N/A */ + { 0x0e, 0x411111f0 }, /* N/A */ + { 0x0f, 0x0321101f }, /* HP */ + { 0x10, 0x411111f0 }, /* Headset? disabled for now */ + { 0x11, 0x03a11021 }, /* Mic */ + { 0x12, 0xd5a30140 }, /* Builtin Mic */ + { 0x13, 0x411111f0 }, /* N/A */ + { 0x18, 0x411111f0 }, /* N/A */ + {} +}; + +static const struct snd_pci_quirk ca0132_quirks[] = { + SND_PCI_QUIRK(0x1028, 0x0685, "Alienware 15 2015", QUIRK_ALIENWARE), + SND_PCI_QUIRK(0x1028, 0x0688, "Alienware 17 2015", QUIRK_ALIENWARE), + SND_PCI_QUIRK(0x1028, 0x0708, "Alienware 15 R2 2016", QUIRK_ALIENWARE), + {} +}; + +/* * CA0132 codec access */ -unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid, +static unsigned int codec_send_command(struct hda_codec *codec, hda_nid_t nid, unsigned int verb, unsigned int parm, unsigned int *res) { unsigned int response; @@ -868,7 +896,7 @@ int status = 0; if (data == NULL) { - snd_printdd(KERN_ERR "chipio_write_data null ptr\n"); + codec_dbg(codec, "chipio_write_data null ptr\n"); return -EINVAL; } @@ -1407,12 +1435,12 @@ return -EINVAL; if (dir == SCP_GET && reply == NULL) { - snd_printdd(KERN_ERR "dspio_scp get but has no buffer\n"); + codec_dbg(codec, "dspio_scp get but has no buffer\n"); return -EINVAL; } if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) { - snd_printdd(KERN_ERR "dspio_scp bad resp buf len parms\n"); + codec_dbg(codec, "dspio_scp bad resp buf len parms\n"); return -EINVAL; } @@ -1430,7 +1458,7 @@ sizeof(scp_reply), &ret_bytes); if (status < 0) { - snd_printdd(KERN_ERR "dspio_scp: send scp msg failed\n"); + codec_dbg(codec, "dspio_scp: send scp msg failed\n"); return status; } @@ -1449,17 +1477,17 @@ / sizeof(unsigned int); if (*reply_len < ret_size*sizeof(unsigned int)) { - snd_printdd(KERN_ERR "reply too long for buf\n"); + codec_dbg(codec, "reply too long for buf\n"); return -EINVAL; } else if (ret_size != reply_data_size) { - snd_printdd(KERN_ERR "RetLen and HdrLen .NE.\n"); + codec_dbg(codec, "RetLen and HdrLen .NE.\n"); return -EINVAL; } else { *reply_len = ret_size*sizeof(unsigned int); memcpy(reply, scp_reply.data, *reply_len); } } else { - snd_printdd(KERN_ERR "reply ill-formed or errflag set\n"); + codec_dbg(codec, "reply ill-formed or errflag set\n"); return -EIO; } @@ -1489,22 +1517,22 @@ int status = 0; unsigned int size = sizeof(dma_chan); - snd_printdd(KERN_INFO " dspio_alloc_dma_chan() -- begin\n"); + codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n"); status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN, SCP_GET, NULL, 0, dma_chan, &size); if (status < 0) { - snd_printdd(KERN_INFO "dspio_alloc_dma_chan: SCP Failed\n"); + codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n"); return status; } if ((*dma_chan + 1) == 0) { - snd_printdd(KERN_INFO "no free dma channels to allocate\n"); + codec_dbg(codec, "no free dma channels to allocate\n"); return -EBUSY; } - snd_printdd("dspio_alloc_dma_chan: chan=%d\n", *dma_chan); - snd_printdd(KERN_INFO " dspio_alloc_dma_chan() -- complete\n"); + codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan); + codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n"); return status; } @@ -1517,18 +1545,18 @@ int status = 0; unsigned int dummy = 0; - snd_printdd(KERN_INFO " dspio_free_dma_chan() -- begin\n"); - snd_printdd("dspio_free_dma_chan: chan=%d\n", dma_chan); + codec_dbg(codec, " dspio_free_dma_chan() -- begin\n"); + codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan); status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN, SCP_SET, &dma_chan, sizeof(dma_chan), NULL, &dummy); if (status < 0) { - snd_printdd(KERN_INFO "dspio_free_dma_chan: SCP Failed\n"); + codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n"); return status; } - snd_printdd(KERN_INFO " dspio_free_dma_chan() -- complete\n"); + codec_dbg(codec, " dspio_free_dma_chan() -- complete\n"); return status; } @@ -1576,14 +1604,14 @@ unsigned int res; int retry = 20; - snd_printdd("dsp_reset\n"); + codec_dbg(codec, "dsp_reset\n"); do { res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0); retry--; } while (res == -EIO && retry); if (!retry) { - snd_printdd("dsp_reset timeout\n"); + codec_dbg(codec, "dsp_reset timeout\n"); return -EIO; } @@ -1636,39 +1664,39 @@ unsigned int active; bool code, yram; - snd_printdd(KERN_INFO "-- dsp_dma_setup_common() -- Begin ---------\n"); + codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n"); if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) { - snd_printdd(KERN_ERR "dma chan num invalid\n"); + codec_dbg(codec, "dma chan num invalid\n"); return -EINVAL; } if (dsp_is_dma_active(codec, dma_chan)) { - snd_printdd(KERN_ERR "dma already active\n"); + codec_dbg(codec, "dma already active\n"); return -EBUSY; } dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram); if (dsp_addx == INVALID_CHIP_ADDRESS) { - snd_printdd(KERN_ERR "invalid chip addr\n"); + codec_dbg(codec, "invalid chip addr\n"); return -ENXIO; } chnl_prop = DSPDMAC_CHNLPROP_AC_MASK; active = 0; - snd_printdd(KERN_INFO " dsp_dma_setup_common() start reg pgm\n"); + codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n"); if (ovly) { status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET, &chnl_prop); if (status < 0) { - snd_printdd(KERN_ERR "read CHNLPROP Reg fail\n"); + codec_dbg(codec, "read CHNLPROP Reg fail\n"); return status; } - snd_printdd(KERN_INFO "dsp_dma_setup_common() Read CHNLPROP\n"); + codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n"); } if (!code) @@ -1680,20 +1708,20 @@ status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop); if (status < 0) { - snd_printdd(KERN_ERR "write CHNLPROP Reg fail\n"); + codec_dbg(codec, "write CHNLPROP Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup_common() Write CHNLPROP\n"); + codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n"); if (ovly) { status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET, &active); if (status < 0) { - snd_printdd(KERN_ERR "read ACTIVE Reg fail\n"); + codec_dbg(codec, "read ACTIVE Reg fail\n"); return status; } - snd_printdd(KERN_INFO "dsp_dma_setup_common() Read ACTIVE\n"); + codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n"); } active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) & @@ -1701,35 +1729,35 @@ status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active); if (status < 0) { - snd_printdd(KERN_ERR "write ACTIVE Reg fail\n"); + codec_dbg(codec, "write ACTIVE Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup_common() Write ACTIVE\n"); + codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n"); status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan), port_map_mask); if (status < 0) { - snd_printdd(KERN_ERR "write AUDCHSEL Reg fail\n"); + codec_dbg(codec, "write AUDCHSEL Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup_common() Write AUDCHSEL\n"); + codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n"); status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan), DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK); if (status < 0) { - snd_printdd(KERN_ERR "write IRQCNT Reg fail\n"); + codec_dbg(codec, "write IRQCNT Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup_common() Write IRQCNT\n"); + codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n"); - snd_printdd( + codec_dbg(codec, "ChipA=0x%x,DspA=0x%x,dmaCh=%u, " "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n", chip_addx, dsp_addx, dma_chan, port_map_mask, chnl_prop, active); - snd_printdd(KERN_INFO "-- dsp_dma_setup_common() -- Complete ------\n"); + codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n"); return 0; } @@ -1755,20 +1783,20 @@ const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT - DSPDMAC_XFRCNT_BCNT_LOBIT + 1); - snd_printdd(KERN_INFO "-- dsp_dma_setup() -- Begin ---------\n"); + codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n"); if (count > max_dma_count) { - snd_printdd(KERN_ERR "count too big\n"); + codec_dbg(codec, "count too big\n"); return -EINVAL; } dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram); if (dsp_addx == INVALID_CHIP_ADDRESS) { - snd_printdd(KERN_ERR "invalid chip addr\n"); + codec_dbg(codec, "invalid chip addr\n"); return -ENXIO; } - snd_printdd(KERN_INFO " dsp_dma_setup() start reg pgm\n"); + codec_dbg(codec, " dsp_dma_setup() start reg pgm\n"); addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT; incr_field = 0; @@ -1785,10 +1813,10 @@ status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan), dma_cfg); if (status < 0) { - snd_printdd(KERN_ERR "write DMACFG Reg fail\n"); + codec_dbg(codec, "write DMACFG Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup() Write DMACFG\n"); + codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n"); adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT + (code ? 0 : 1)); @@ -1796,10 +1824,10 @@ status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan), adr_ofs); if (status < 0) { - snd_printdd(KERN_ERR "write DSPADROFS Reg fail\n"); + codec_dbg(codec, "write DSPADROFS Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup() Write DSPADROFS\n"); + codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n"); base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT; @@ -1810,17 +1838,17 @@ status = chipio_write(codec, DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt); if (status < 0) { - snd_printdd(KERN_ERR "write XFRCNT Reg fail\n"); + codec_dbg(codec, "write XFRCNT Reg fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_dma_setup() Write XFRCNT\n"); + codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n"); - snd_printdd( + codec_dbg(codec, "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, " "ADROFS=0x%x, XFRCNT=0x%x\n", chip_addx, count, dma_cfg, adr_ofs, xfr_cnt); - snd_printdd(KERN_INFO "-- dsp_dma_setup() -- Complete ---------\n"); + codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n"); return 0; } @@ -1834,17 +1862,17 @@ unsigned int reg = 0; int status = 0; - snd_printdd(KERN_INFO "-- dsp_dma_start() -- Begin ---------\n"); + codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n"); if (ovly) { status = chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, ®); if (status < 0) { - snd_printdd(KERN_ERR "read CHNLSTART reg fail\n"); + codec_dbg(codec, "read CHNLSTART reg fail\n"); return status; } - snd_printdd(KERN_INFO "-- dsp_dma_start() Read CHNLSTART\n"); + codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n"); reg &= ~(DSPDMAC_CHNLSTART_EN_MASK | DSPDMAC_CHNLSTART_DIS_MASK); @@ -1853,10 +1881,10 @@ status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET, reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT))); if (status < 0) { - snd_printdd(KERN_ERR "write CHNLSTART reg fail\n"); + codec_dbg(codec, "write CHNLSTART reg fail\n"); return status; } - snd_printdd(KERN_INFO "-- dsp_dma_start() -- Complete ---------\n"); + codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n"); return status; } @@ -1870,17 +1898,17 @@ unsigned int reg = 0; int status = 0; - snd_printdd(KERN_INFO "-- dsp_dma_stop() -- Begin ---------\n"); + codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n"); if (ovly) { status = chipio_read(codec, DSPDMAC_CHNLSTART_INST_OFFSET, ®); if (status < 0) { - snd_printdd(KERN_ERR "read CHNLSTART reg fail\n"); + codec_dbg(codec, "read CHNLSTART reg fail\n"); return status; } - snd_printdd(KERN_INFO "-- dsp_dma_stop() Read CHNLSTART\n"); + codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n"); reg &= ~(DSPDMAC_CHNLSTART_EN_MASK | DSPDMAC_CHNLSTART_DIS_MASK); } @@ -1888,10 +1916,10 @@ status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET, reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT))); if (status < 0) { - snd_printdd(KERN_ERR "write CHNLSTART reg fail\n"); + codec_dbg(codec, "write CHNLSTART reg fail\n"); return status; } - snd_printdd(KERN_INFO "-- dsp_dma_stop() -- Complete ---------\n"); + codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n"); return status; } @@ -1974,17 +2002,17 @@ { int status; - snd_printdd(KERN_INFO " dsp_allocate_ports() -- begin\n"); + codec_dbg(codec, " dsp_allocate_ports() -- begin\n"); if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) { - snd_printdd(KERN_ERR "bad rate multiple\n"); + codec_dbg(codec, "bad rate multiple\n"); return -EINVAL; } status = dsp_allocate_router_ports(codec, num_chans, rate_multi, 0, port_map); - snd_printdd(KERN_INFO " dsp_allocate_ports() -- complete\n"); + codec_dbg(codec, " dsp_allocate_ports() -- complete\n"); return status; } @@ -2001,7 +2029,7 @@ unsigned int rate_multi = sample_rate_mul / sample_rate_div; if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) { - snd_printdd(KERN_ERR "bad rate multiple\n"); + codec_dbg(codec, "bad rate multiple\n"); return -EINVAL; } @@ -2019,14 +2047,14 @@ { int status; - snd_printdd(KERN_INFO " dsp_free_ports() -- begin\n"); + codec_dbg(codec, " dsp_free_ports() -- begin\n"); status = dsp_free_router_ports(codec); if (status < 0) { - snd_printdd(KERN_ERR "free router ports fail\n"); + codec_dbg(codec, "free router ports fail\n"); return status; } - snd_printdd(KERN_INFO " dsp_free_ports() -- complete\n"); + codec_dbg(codec, " dsp_free_ports() -- complete\n"); return status; } @@ -2047,18 +2075,15 @@ DMA_STATE_RUN = 1 }; -static int dma_convert_to_hda_format( +static int dma_convert_to_hda_format(struct hda_codec *codec, unsigned int sample_rate, unsigned short channels, unsigned short *hda_format) { unsigned int format_val; - format_val = snd_hda_calc_stream_format( - sample_rate, - channels, - SNDRV_PCM_FORMAT_S32_LE, - 32, 0); + format_val = snd_hdac_calc_stream_format(sample_rate, + channels, SNDRV_PCM_FORMAT_S32_LE, 32, 0); if (hda_format) *hda_format = (unsigned short)format_val; @@ -2092,8 +2117,6 @@ { bool cmd; - snd_printdd("dma_set_state state=%d\n", state); - switch (state) { case DMA_STATE_STOP: cmd = false; @@ -2196,7 +2219,7 @@ unsigned int count; if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) { - snd_printdd(KERN_ERR "hci_write invalid params\n"); + codec_dbg(codec, "hci_write invalid params\n"); return -EINVAL; } @@ -2205,7 +2228,7 @@ while (count >= 2) { status = chipio_write(codec, data[0], data[1]); if (status < 0) { - snd_printdd(KERN_ERR "hci_write chipio failed\n"); + codec_dbg(codec, "hci_write chipio failed\n"); return status; } count -= 2; @@ -2265,12 +2288,12 @@ } if (hci_write && (!fls || is_last(fls))) { - snd_printdd("hci_write\n"); + codec_dbg(codec, "hci_write\n"); return dspxfr_hci_write(codec, hci_write); } if (fls == NULL || dma_engine == NULL || port_map_mask == 0) { - snd_printdd("Invalid Params\n"); + codec_dbg(codec, "Invalid Params\n"); return -EINVAL; } @@ -2286,7 +2309,7 @@ if (!UC_RANGE(chip_addx, words_to_write) && !X_RANGE_ALL(chip_addx, words_to_write) && !Y_RANGE_ALL(chip_addx, words_to_write)) { - snd_printdd("Invalid chip_addx Params\n"); + codec_dbg(codec, "Invalid chip_addx Params\n"); return -EINVAL; } @@ -2296,7 +2319,7 @@ buffer_addx = dma_get_buffer_addr(dma_engine); if (buffer_addx == NULL) { - snd_printdd(KERN_ERR "dma_engine buffer NULL\n"); + codec_dbg(codec, "dma_engine buffer NULL\n"); return -EINVAL; } @@ -2309,7 +2332,7 @@ (num_chans * sample_rate_mul / sample_rate_div)); if (hda_frame_size_words == 0) { - snd_printdd(KERN_ERR "frmsz zero\n"); + codec_dbg(codec, "frmsz zero\n"); return -EINVAL; } @@ -2317,14 +2340,14 @@ (unsigned int)(UC_RANGE(chip_addx, 1) ? 65536 : 32768)); buffer_size_words -= buffer_size_words % hda_frame_size_words; - snd_printdd( + codec_dbg(codec, "chpadr=0x%08x frmsz=%u nchan=%u " "rate_mul=%u div=%u bufsz=%u\n", chip_addx, hda_frame_size_words, num_chans, sample_rate_mul, sample_rate_div, buffer_size_words); if (buffer_size_words < hda_frame_size_words) { - snd_printdd(KERN_ERR "dspxfr_one_seg:failed\n"); + codec_dbg(codec, "dspxfr_one_seg:failed\n"); return -EINVAL; } @@ -2338,7 +2361,7 @@ while (words_to_write != 0) { run_size_words = min(buffer_size_words, words_to_write); - snd_printdd("dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n", + codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n", words_to_write, run_size_words, remainder_words); dma_xfer(dma_engine, data, run_size_words*sizeof(u32)); if (!comm_dma_setup_done) { @@ -2360,7 +2383,7 @@ if (status < 0) return status; if (!dsp_is_dma_active(codec, dma_chan)) { - snd_printdd(KERN_ERR "dspxfr:DMA did not start\n"); + codec_dbg(codec, "dspxfr:DMA did not start\n"); return -EIO; } status = dma_set_state(dma_engine, DMA_STATE_RUN); @@ -2392,7 +2415,7 @@ if (dma_active) break; - snd_printdd(KERN_INFO "+++++ DMA complete\n"); + codec_dbg(codec, "+++++ DMA complete\n"); dma_set_state(dma_engine, DMA_STATE_STOP); status = dma_reset(dma_engine); @@ -2420,7 +2443,7 @@ * @reloc: Relocation address for loading single-segment overlays, or 0 for * no relocation * @sample_rate: sampling rate of the stream used for DSP download - * @number_channels: channels of the stream used for DSP download + * @channels: channels of the stream used for DSP download * @ovly: TRUE if overlay format is required * * Returns zero or a negative error code. @@ -2455,7 +2478,7 @@ } dma_engine->codec = codec; - dma_convert_to_hda_format(sample_rate, channels, &hda_format); + dma_convert_to_hda_format(codec, sample_rate, channels, &hda_format); dma_engine->m_converter_format = hda_format; dma_engine->buf_size = (ovly ? DSP_DMA_WRITE_BUFLEN_OVLY : DSP_DMA_WRITE_BUFLEN_INIT) * 2; @@ -2466,7 +2489,7 @@ hda_format, &response); if (status < 0) { - snd_printdd(KERN_ERR "set converter format fail\n"); + codec_dbg(codec, "set converter format fail\n"); goto exit; } @@ -2481,7 +2504,7 @@ if (ovly) { status = dspio_alloc_dma_chan(codec, &dma_chan); if (status < 0) { - snd_printdd(KERN_ERR "alloc dmachan fail\n"); + codec_dbg(codec, "alloc dmachan fail\n"); dma_chan = INVALID_DMA_CHANNEL; goto exit; } @@ -2491,7 +2514,7 @@ status = dsp_allocate_ports_format(codec, hda_format, &port_map_mask); if (status < 0) { - snd_printdd(KERN_ERR "alloc ports fail\n"); + codec_dbg(codec, "alloc ports fail\n"); goto exit; } @@ -2499,13 +2522,13 @@ status = codec_set_converter_stream_channel(codec, WIDGET_CHIP_CTRL, stream_id, 0, &response); if (status < 0) { - snd_printdd(KERN_ERR "set stream chan fail\n"); + codec_dbg(codec, "set stream chan fail\n"); goto exit; } while ((fls_data != NULL) && !is_last(fls_data)) { if (!is_valid(fls_data)) { - snd_printdd(KERN_ERR "FLS check fail\n"); + codec_dbg(codec, "FLS check fail\n"); status = -EINVAL; goto exit; } @@ -2548,7 +2571,7 @@ */ static void dspload_post_setup(struct hda_codec *codec) { - snd_printdd(KERN_INFO "---- dspload_post_setup ------\n"); + codec_dbg(codec, "---- dspload_post_setup ------\n"); /*set DSP speaker to 2.0 configuration*/ chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080); @@ -2559,10 +2582,7 @@ } /** - * Download DSP from a DSP Image Fast Load structure. This structure is a - * linear, non-constant sized element array of structures, each of which - * contain the count of the data to be loaded, the data itself, and the - * corresponding starting chip address of the starting data location. + * dspload_image - Download DSP from a DSP Image Fast Load structure. * * @codec: the HDA codec * @fls: pointer to a fast load image @@ -2573,6 +2593,10 @@ * @router_chans: number of audio router channels to be allocated (0 means use * internal defaults; max is 32) * + * Download DSP from a DSP Image Fast Load structure. This structure is a + * linear, non-constant sized element array of structures, each of which + * contain the count of the data to be loaded, the data itself, and the + * corresponding starting chip address of the starting data location. * Returns zero or a negative error code. */ static int dspload_image(struct hda_codec *codec, @@ -2586,7 +2610,7 @@ unsigned int sample_rate; unsigned short channels; - snd_printdd(KERN_INFO "---- dspload_image begin ------\n"); + codec_dbg(codec, "---- dspload_image begin ------\n"); if (router_chans == 0) { if (!ovly) router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS; @@ -2603,27 +2627,27 @@ } do { - snd_printdd(KERN_INFO "Ready to program DMA\n"); + codec_dbg(codec, "Ready to program DMA\n"); if (!ovly) status = dsp_reset(codec); if (status < 0) break; - snd_printdd(KERN_INFO "dsp_reset() complete\n"); + codec_dbg(codec, "dsp_reset() complete\n"); status = dspxfr_image(codec, fls, reloc, sample_rate, channels, ovly); if (status < 0) break; - snd_printdd(KERN_INFO "dspxfr_image() complete\n"); + codec_dbg(codec, "dspxfr_image() complete\n"); if (autostart && !ovly) { dspload_post_setup(codec); status = dsp_set_run_state(codec); } - snd_printdd(KERN_INFO "LOAD FINISHED\n"); + codec_dbg(codec, "LOAD FINISHED\n"); } while (0); return status; @@ -2651,13 +2675,13 @@ do { if (dspload_is_loaded(codec)) { - pr_info("ca0132 DOWNLOAD OK :-) DSP IS RUNNING.\n"); + codec_info(codec, "ca0132 DSP downloaded and running\n"); return true; } msleep(20); } while (time_before(jiffies, timeout)); - pr_err("ca0132 DOWNLOAD FAILED!!! DSP IS NOT RUNNING.\n"); + codec_err(codec, "ca0132 failed to download DSP\n"); return false; } @@ -3047,7 +3071,7 @@ hda_nid_t pnid, hda_nid_t nid, const char *name, int dir) { - char namestr[44]; + char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; int type = dir ? HDA_INPUT : HDA_OUTPUT; struct snd_kcontrol_new knew = HDA_CODEC_VOLUME_MONO(namestr, nid, 1, 0, type); @@ -3132,14 +3156,14 @@ unsigned int tmp; int err; - snd_printdd(KERN_INFO "ca0132_select_out\n"); + codec_dbg(codec, "ca0132_select_out\n"); - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); auto_jack = spec->vnode_lswitch[VNID_HP_ASEL - VNODE_START_NID]; if (auto_jack) - jack_present = snd_hda_jack_detect(codec, spec->out_pins[1]); + jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_hp); else jack_present = spec->vnode_lswitch[VNID_HP_SEL - VNODE_START_NID]; @@ -3150,7 +3174,7 @@ spec->cur_out_type = SPEAKER_OUT; if (spec->cur_out_type == SPEAKER_OUT) { - snd_printdd(KERN_INFO "ca0132_select_out speaker\n"); + codec_dbg(codec, "ca0132_select_out speaker\n"); /*speaker out config*/ tmp = FLOAT_ONE; err = dspio_set_uint_param(codec, 0x80, 0x04, tmp); @@ -3183,7 +3207,7 @@ snd_hda_set_pin_ctl(codec, spec->out_pins[0], pin_ctl | PIN_OUT); } else { - snd_printdd(KERN_INFO "ca0132_select_out hp\n"); + codec_dbg(codec, "ca0132_select_out hp\n"); /*headphone out config*/ tmp = FLOAT_ZERO; err = dspio_set_uint_param(codec, 0x80, 0x04, tmp); @@ -3218,7 +3242,7 @@ } exit: - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return err < 0 ? err : 0; } @@ -3227,8 +3251,14 @@ { struct ca0132_spec *spec = container_of( to_delayed_work(work), struct ca0132_spec, unsol_hp_work); + struct hda_jack_tbl *jack; + ca0132_select_out(spec->codec); - snd_hda_jack_report_sync(spec->codec); + jack = snd_hda_jack_tbl_get(spec->codec, spec->unsol_tag_hp); + if (jack) { + jack->block_report = 0; + snd_hda_jack_report_sync(spec->codec); + } } static void ca0132_set_dmic(struct hda_codec *codec, int enable); @@ -3288,14 +3318,14 @@ int jack_present; int auto_jack; - snd_printdd(KERN_INFO "ca0132_select_mic\n"); + codec_dbg(codec, "ca0132_select_mic\n"); - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); auto_jack = spec->vnode_lswitch[VNID_AMIC1_ASEL - VNODE_START_NID]; if (auto_jack) - jack_present = snd_hda_jack_detect(codec, spec->input_pins[0]); + jack_present = snd_hda_jack_detect(codec, spec->unsol_tag_amic1); else jack_present = spec->vnode_lswitch[VNID_AMIC1_SEL - VNODE_START_NID]; @@ -3323,7 +3353,7 @@ ca0132_effects_set(codec, VOICE_FOCUS, 0); } - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return 0; } @@ -3410,7 +3440,7 @@ val = 0; } - snd_printdd(KERN_INFO "ca0132_effect_set: nid=0x%x, val=%ld\n", + codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n", nid, val); on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE; @@ -3432,7 +3462,7 @@ hda_nid_t nid; int i, ret = 0; - snd_printdd(KERN_INFO "ca0132_pe_switch_set: val=%ld\n", + codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n", spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]); i = OUT_EFFECT_START_NID - EFFECT_START_NID; @@ -3478,7 +3508,7 @@ int i, ret = 0; unsigned int oldval; - snd_printdd(KERN_INFO "ca0132_cvoice_switch_set: val=%ld\n", + codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n", spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]); i = IN_EFFECT_START_NID - EFFECT_START_NID; @@ -3608,7 +3638,7 @@ if (sel >= items) return 0; - snd_printdd(KERN_INFO "ca0132_voicefx_put: sel=%d, preset=%s\n", + codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n", sel, ca0132_voicefx_presets[sel].name); /* @@ -3679,7 +3709,7 @@ long *valp = ucontrol->value.integer.value; int changed = 1; - snd_printdd(KERN_INFO "ca0132_switch_put: nid=0x%x, val=%ld\n", + codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n", nid, *valp); snd_hda_power_up(codec); @@ -3879,7 +3909,7 @@ static int add_fx_switch(struct hda_codec *codec, hda_nid_t nid, const char *pfx, int dir) { - char namestr[44]; + char namestr[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; int type = dir ? HDA_INPUT : HDA_OUTPUT; struct snd_kcontrol_new knew = CA0132_CODEC_MUTE_MONO(namestr, nid, 1, type); @@ -4032,12 +4062,11 @@ static int ca0132_build_pcms(struct hda_codec *codec) { struct ca0132_spec *spec = codec->spec; - struct hda_pcm *info = spec->pcm_rec; - - codec->pcm_info = info; - codec->num_pcms = 0; + struct hda_pcm *info; - info->name = "CA0132 Analog"; + info = snd_hda_codec_pcm_new(codec, "CA0132 Analog"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ca0132_pcm_analog_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dacs[0]; info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = @@ -4045,27 +4074,27 @@ info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[0]; - codec->num_pcms++; - info++; - info->name = "CA0132 Analog Mic-In2"; + info = snd_hda_codec_pcm_new(codec, "CA0132 Analog Mic-In2"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[1]; - codec->num_pcms++; - info++; - info->name = "CA0132 What U Hear"; + info = snd_hda_codec_pcm_new(codec, "CA0132 What U Hear"); + if (!info) + return -ENOMEM; info->stream[SNDRV_PCM_STREAM_CAPTURE] = ca0132_pcm_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adcs[2]; - codec->num_pcms++; if (!spec->dig_out && !spec->dig_in) return 0; - info++; - info->name = "CA0132 Digital"; + info = snd_hda_codec_pcm_new(codec, "CA0132 Digital"); + if (!info) + return -ENOMEM; info->pcm_type = HDA_PCM_TYPE_SPDIF; if (spec->dig_out) { info->stream[SNDRV_PCM_STREAM_PLAYBACK] = @@ -4077,7 +4106,6 @@ ca0132_pcm_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in; } - codec->num_pcms++; return 0; } @@ -4117,12 +4145,6 @@ } } -static void ca0132_init_unsol(struct hda_codec *codec) -{ - snd_hda_jack_detect_enable(codec, UNSOL_TAG_HP, UNSOL_TAG_HP); - snd_hda_jack_detect_enable(codec, UNSOL_TAG_AMIC1, UNSOL_TAG_AMIC1); -} - static void refresh_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir) { unsigned int caps; @@ -4142,7 +4164,7 @@ u8 val; unsigned int oldval; - snd_printdd(KERN_INFO "ca0132_set_dmic: enable=%d\n", enable); + codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable); oldval = stop_mic1(codec); ca0132_set_vipsource(codec, 0); @@ -4248,13 +4270,9 @@ { struct ca0132_spec *spec = codec->spec; int i; - hda_nid_t nid; - snd_printdd(KERN_INFO "ca0132_refresh_widget_caps.\n"); - nid = codec->start_nid; - for (i = 0; i < codec->num_nodes; i++, nid++) - codec->wcaps[i] = snd_hda_param_read(codec, nid, - AC_PAR_AUDIO_WIDGET_CAP); + codec_dbg(codec, "ca0132_refresh_widget_caps.\n"); + snd_hda_codec_update_widgets(codec); for (i = 0; i < spec->multiout.num_dacs; i++) refresh_amp_caps(codec, spec->dacs[i], HDA_OUTPUT); @@ -4354,12 +4372,12 @@ const struct dsp_image_seg *dsp_os_image; const struct firmware *fw_entry; - if (request_firmware(&fw_entry, EFX_FILE, codec->bus->card->dev) != 0) + if (request_firmware(&fw_entry, EFX_FILE, codec->card->dev) != 0) return false; dsp_os_image = (struct dsp_image_seg *)(fw_entry->data); if (dspload_image(codec, dsp_os_image, 0, 0, true, 0)) { - pr_err("ca0132 dspload_image failed.\n"); + codec_err(codec, "ca0132 DSP load image failed\n"); goto exit_download; } @@ -4393,11 +4411,12 @@ ca0132_set_dsp_msr(codec, true); } -static void ca0132_process_dsp_response(struct hda_codec *codec) +static void ca0132_process_dsp_response(struct hda_codec *codec, + struct hda_jack_callback *callback) { struct ca0132_spec *spec = codec->spec; - snd_printdd(KERN_INFO "ca0132_process_dsp_response\n"); + codec_dbg(codec, "ca0132_process_dsp_response\n"); if (spec->wait_scp) { if (dspio_get_response_data(codec) >= 0) spec->wait_scp = 0; @@ -4406,36 +4425,34 @@ dspio_clear_response_queue(codec); } -static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res) +static void hp_callback(struct hda_codec *codec, struct hda_jack_callback *cb) { struct ca0132_spec *spec = codec->spec; + struct hda_jack_tbl *tbl; - if (((res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f) == UNSOL_TAG_DSP) { - ca0132_process_dsp_response(codec); - } else { - res = snd_hda_jack_get_action(codec, - (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f); + /* Delay enabling the HP amp, to let the mic-detection + * state machine run. + */ + cancel_delayed_work_sync(&spec->unsol_hp_work); + schedule_delayed_work(&spec->unsol_hp_work, msecs_to_jiffies(500)); + tbl = snd_hda_jack_tbl_get(codec, cb->nid); + if (tbl) + tbl->block_report = 1; +} - snd_printdd(KERN_INFO "snd_hda_jack_get_action: 0x%x\n", res); +static void amic_callback(struct hda_codec *codec, struct hda_jack_callback *cb) +{ + ca0132_select_mic(codec); +} - switch (res) { - case UNSOL_TAG_HP: - /* Delay enabling the HP amp, to let the mic-detection - * state machine run. - */ - cancel_delayed_work_sync(&spec->unsol_hp_work); - queue_delayed_work(codec->bus->workq, - &spec->unsol_hp_work, - msecs_to_jiffies(500)); - break; - case UNSOL_TAG_AMIC1: - ca0132_select_mic(codec); - snd_hda_jack_report_sync(codec); - break; - default: - break; - } - } +static void ca0132_init_unsol(struct hda_codec *codec) +{ + struct ca0132_spec *spec = codec->spec; + snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_hp, hp_callback); + snd_hda_jack_detect_enable_callback(codec, spec->unsol_tag_amic1, + amic_callback); + snd_hda_jack_detect_enable_callback(codec, UNSOL_TAG_DSP, + ca0132_process_dsp_response); } /* @@ -4446,8 +4463,6 @@ static struct hda_verb ca0132_base_init_verbs[] = { /*enable ct extension*/ {0x15, VENDOR_CHIPIO_CT_EXTENSIONS_ENABLE, 0x1}, - /*enable DSP node unsol, needed for DSP download*/ - {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_DSP}, {} }; @@ -4495,17 +4510,6 @@ {} }; -static struct hda_verb ca0132_init_verbs1[] = { - {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_HP}, - {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | UNSOL_TAG_AMIC1}, - /* config EAPD */ - {0x0b, 0x78D, 0x00}, - /*{0x0b, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/ - /*{0x10, 0x78D, 0x02},*/ - /*{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x02},*/ - {} -}; - static void ca0132_init_chip(struct hda_codec *codec) { struct ca0132_spec *spec = codec->spec; @@ -4562,7 +4566,9 @@ spec->dsp_state = DSP_DOWNLOAD_INIT; spec->curr_chip_addx = INVALID_CHIP_ADDRESS; - snd_hda_power_up(codec); + snd_hda_power_up_pm(codec); + + ca0132_init_unsol(codec); ca0132_init_params(codec); ca0132_init_flags(codec); @@ -4583,17 +4589,15 @@ init_input(codec, cfg->dig_in_pin, spec->dig_in); - for (i = 0; i < spec->num_init_verbs; i++) - snd_hda_sequence_write(codec, spec->init_verbs[i]); - - ca0132_init_unsol(codec); + snd_hda_sequence_write(codec, spec->chip_init_verbs); + snd_hda_sequence_write(codec, spec->spec_init_verbs); ca0132_select_out(codec); ca0132_select_mic(codec); snd_hda_jack_report_sync(codec); - snd_hda_power_down(codec); + snd_hda_power_down_pm(codec); return 0; } @@ -4607,6 +4611,7 @@ snd_hda_sequence_write(codec, spec->base_exit_verbs); ca0132_exit_chip(codec); snd_hda_power_down(codec); + kfree(spec->spec_init_verbs); kfree(codec->spec); } @@ -4615,7 +4620,7 @@ .build_pcms = ca0132_build_pcms, .init = ca0132_init, .free = ca0132_free, - .unsol_event = ca0132_unsol_event, + .unsol_event = snd_hda_jack_unsol_event, }; static void ca0132_config(struct hda_codec *codec) @@ -4631,38 +4636,108 @@ spec->multiout.num_dacs = 3; spec->multiout.max_channels = 2; - spec->num_outputs = 2; - spec->out_pins[0] = 0x0b; /* speaker out */ - spec->out_pins[1] = 0x10; /* headphone out */ - spec->shared_out_nid = 0x2; - - spec->num_inputs = 3; - spec->adcs[0] = 0x7; /* digital mic / analog mic1 */ - spec->adcs[1] = 0x8; /* analog mic2 */ - spec->adcs[2] = 0xa; /* what u hear */ - spec->shared_mic_nid = 0x7; - - spec->input_pins[0] = 0x12; - spec->input_pins[1] = 0x11; - spec->input_pins[2] = 0x13; - - /* SPDIF I/O */ - spec->dig_out = 0x05; - spec->multiout.dig_out_nid = spec->dig_out; - cfg->dig_out_pins[0] = 0x0c; - cfg->dig_outs = 1; - cfg->dig_out_type[0] = HDA_PCM_TYPE_SPDIF; - spec->dig_in = 0x09; - cfg->dig_in_pin = 0x0e; - cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; + if (spec->quirk == QUIRK_ALIENWARE) { + codec_dbg(codec, "ca0132_config: QUIRK_ALIENWARE applied.\n"); + snd_hda_apply_pincfgs(codec, alienware_pincfgs); + + spec->num_outputs = 2; + spec->out_pins[0] = 0x0b; /* speaker out */ + spec->out_pins[1] = 0x0f; + spec->shared_out_nid = 0x2; + spec->unsol_tag_hp = 0x0f; + + spec->adcs[0] = 0x7; /* digital mic / analog mic1 */ + spec->adcs[1] = 0x8; /* analog mic2 */ + spec->adcs[2] = 0xa; /* what u hear */ + + spec->num_inputs = 3; + spec->input_pins[0] = 0x12; + spec->input_pins[1] = 0x11; + spec->input_pins[2] = 0x13; + spec->shared_mic_nid = 0x7; + spec->unsol_tag_amic1 = 0x11; + } else { + spec->num_outputs = 2; + spec->out_pins[0] = 0x0b; /* speaker out */ + spec->out_pins[1] = 0x10; /* headphone out */ + spec->shared_out_nid = 0x2; + spec->unsol_tag_hp = spec->out_pins[1]; + + spec->adcs[0] = 0x7; /* digital mic / analog mic1 */ + spec->adcs[1] = 0x8; /* analog mic2 */ + spec->adcs[2] = 0xa; /* what u hear */ + + spec->num_inputs = 3; + spec->input_pins[0] = 0x12; + spec->input_pins[1] = 0x11; + spec->input_pins[2] = 0x13; + spec->shared_mic_nid = 0x7; + spec->unsol_tag_amic1 = spec->input_pins[0]; + + /* SPDIF I/O */ + spec->dig_out = 0x05; + spec->multiout.dig_out_nid = spec->dig_out; + cfg->dig_out_pins[0] = 0x0c; + cfg->dig_outs = 1; + cfg->dig_out_type[0] = HDA_PCM_TYPE_SPDIF; + spec->dig_in = 0x09; + cfg->dig_in_pin = 0x0e; + cfg->dig_in_type = HDA_PCM_TYPE_SPDIF; + } +} + +static int ca0132_prepare_verbs(struct hda_codec *codec) +{ +/* Verbs + terminator (an empty element) */ +#define NUM_SPEC_VERBS 4 + struct ca0132_spec *spec = codec->spec; + + spec->chip_init_verbs = ca0132_init_verbs0; + spec->spec_init_verbs = kzalloc(sizeof(struct hda_verb) * NUM_SPEC_VERBS, GFP_KERNEL); + if (!spec->spec_init_verbs) + return -ENOMEM; + + /* HP jack autodetection */ + spec->spec_init_verbs[0].nid = spec->unsol_tag_hp; + spec->spec_init_verbs[0].param = AC_VERB_SET_UNSOLICITED_ENABLE; + spec->spec_init_verbs[0].verb = AC_USRSP_EN | spec->unsol_tag_hp; + + /* MIC1 jack autodetection */ + spec->spec_init_verbs[1].nid = spec->unsol_tag_amic1; + spec->spec_init_verbs[1].param = AC_VERB_SET_UNSOLICITED_ENABLE; + spec->spec_init_verbs[1].verb = AC_USRSP_EN | spec->unsol_tag_amic1; + + /* config EAPD */ + spec->spec_init_verbs[2].nid = 0x0b; + spec->spec_init_verbs[2].param = 0x78D; + spec->spec_init_verbs[2].verb = 0x00; + + /* Previously commented configuration */ + /* + spec->spec_init_verbs[3].nid = 0x0b; + spec->spec_init_verbs[3].param = AC_VERB_SET_EAPD_BTLENABLE; + spec->spec_init_verbs[3].verb = 0x02; + + spec->spec_init_verbs[4].nid = 0x10; + spec->spec_init_verbs[4].param = 0x78D; + spec->spec_init_verbs[4].verb = 0x02; + + spec->spec_init_verbs[5].nid = 0x10; + spec->spec_init_verbs[5].param = AC_VERB_SET_EAPD_BTLENABLE; + spec->spec_init_verbs[5].verb = 0x02; + */ + + /* Terminator: spec->spec_init_verbs[NUM_SPEC_VERBS-1] */ + return 0; } static int patch_ca0132(struct hda_codec *codec) { struct ca0132_spec *spec; int err; + const struct snd_pci_quirk *quirk; - snd_printdd("patch_ca0132\n"); + codec_dbg(codec, "patch_ca0132\n"); spec = kzalloc(sizeof(*spec), GFP_KERNEL); if (!spec) @@ -4670,15 +4745,23 @@ codec->spec = spec; spec->codec = codec; + codec->patch_ops = ca0132_patch_ops; + codec->pcm_format_first = 1; + codec->no_sticky_stream = 1; + + /* Detect codec quirk */ + quirk = snd_pci_quirk_lookup(codec->bus->pci, ca0132_quirks); + if (quirk) + spec->quirk = quirk->value; + else + spec->quirk = QUIRK_NONE; + spec->dsp_state = DSP_DOWNLOAD_INIT; spec->num_mixers = 1; spec->mixers[0] = ca0132_mixer; spec->base_init_verbs = ca0132_base_init_verbs; spec->base_exit_verbs = ca0132_base_exit_verbs; - spec->init_verbs[0] = ca0132_init_verbs0; - spec->init_verbs[1] = ca0132_init_verbs1; - spec->num_init_verbs = 2; INIT_DELAYED_WORK(&spec->unsol_hp_work, ca0132_unsol_hp_delayed); @@ -4686,13 +4769,13 @@ ca0132_config(codec); - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); + err = ca0132_prepare_verbs(codec); if (err < 0) return err; - codec->patch_ops = ca0132_patch_ops; - codec->pcm_format_first = 1; - codec->no_sticky_stream = 1; + err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); + if (err < 0) + return err; return 0; } @@ -4700,30 +4783,17 @@ /* * patch entries */ -static struct hda_codec_preset snd_hda_preset_ca0132[] = { - { .id = 0x11020011, .name = "CA0132", .patch = patch_ca0132 }, +static struct hda_device_id snd_hda_id_ca0132[] = { + HDA_CODEC_ENTRY(0x11020011, "CA0132", patch_ca0132), {} /* terminator */ }; - -MODULE_ALIAS("snd-hda-codec-id:11020011"); +MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_ca0132); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Creative Sound Core3D codec"); -static struct hda_codec_preset_list ca0132_list = { - .preset = snd_hda_preset_ca0132, - .owner = THIS_MODULE, +static struct hda_codec_driver ca0132_driver = { + .id = snd_hda_id_ca0132, }; -static int __init patch_ca0132_init(void) -{ - return snd_hda_add_codec_preset(&ca0132_list); -} - -static void __exit patch_ca0132_exit(void) -{ - snd_hda_delete_codec_preset(&ca0132_list); -} - -module_init(patch_ca0132_init) -module_exit(patch_ca0132_exit) +module_hda_codec_driver(ca0132_driver);