Lines Matching refs:aw_dev
44 static int aw_dev_dsp_write_16bit(struct aw_device *aw_dev, in aw_dev_dsp_write_16bit() argument
49 ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, dsp_addr); in aw_dev_dsp_write_16bit()
51 dev_err(aw_dev->dev, "%s write addr error, ret=%d", __func__, ret); in aw_dev_dsp_write_16bit()
55 ret = regmap_write(aw_dev->regmap, AW88166_DSPMDAT_REG, (u16)dsp_data); in aw_dev_dsp_write_16bit()
57 dev_err(aw_dev->dev, "%s write data error, ret=%d", __func__, ret); in aw_dev_dsp_write_16bit()
64 static int aw_dev_dsp_read_16bit(struct aw_device *aw_dev, in aw_dev_dsp_read_16bit() argument
70 ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, dsp_addr); in aw_dev_dsp_read_16bit()
72 dev_err(aw_dev->dev, "%s write error, ret=%d", __func__, ret); in aw_dev_dsp_read_16bit()
76 ret = regmap_read(aw_dev->regmap, AW88166_DSPMDAT_REG, &temp_data); in aw_dev_dsp_read_16bit()
78 dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret); in aw_dev_dsp_read_16bit()
86 static int aw_dev_dsp_read_32bit(struct aw_device *aw_dev, in aw_dev_dsp_read_32bit() argument
92 ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, dsp_addr); in aw_dev_dsp_read_32bit()
94 dev_err(aw_dev->dev, "%s write error, ret=%d", __func__, ret); in aw_dev_dsp_read_32bit()
98 ret = regmap_read(aw_dev->regmap, AW88166_DSPMDAT_REG, &temp_data); in aw_dev_dsp_read_32bit()
100 dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret); in aw_dev_dsp_read_32bit()
105 ret = regmap_read(aw_dev->regmap, AW88166_DSPMDAT_REG, &temp_data); in aw_dev_dsp_read_32bit()
107 dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret); in aw_dev_dsp_read_32bit()
115 static int aw_dev_dsp_read(struct aw_device *aw_dev, in aw_dev_dsp_read() argument
121 mutex_lock(&aw_dev->dsp_lock); in aw_dev_dsp_read()
124 ret = aw_dev_dsp_read_16bit(aw_dev, dsp_addr, dsp_data); in aw_dev_dsp_read()
126 dev_err(aw_dev->dev, "read dsp_addr[0x%x] 16-bit failed", (u32)dsp_addr); in aw_dev_dsp_read()
129 ret = aw_dev_dsp_read_32bit(aw_dev, dsp_addr, dsp_data); in aw_dev_dsp_read()
131 dev_err(aw_dev->dev, "read dsp_addr[0x%x] 32-bit failed", (u32)dsp_addr); in aw_dev_dsp_read()
134 dev_err(aw_dev->dev, "data type[%d] unsupported", data_type); in aw_dev_dsp_read()
140 if (regmap_read(aw_dev->regmap, AW88166_ID_REG, ®_value)) in aw_dev_dsp_read()
141 dev_err(aw_dev->dev, "%s fail to clear chip state. ret=%d\n", __func__, ret); in aw_dev_dsp_read()
142 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_dsp_read()
147 static void aw_dev_pwd(struct aw_device *aw_dev, bool pwd) in aw_dev_pwd() argument
152 ret = regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw_dev_pwd()
155 ret = regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw_dev_pwd()
159 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_pwd()
162 static void aw_dev_get_int_status(struct aw_device *aw_dev, unsigned short *int_status) in aw_dev_get_int_status() argument
167 ret = regmap_read(aw_dev->regmap, AW88166_SYSINT_REG, ®_val); in aw_dev_get_int_status()
169 dev_err(aw_dev->dev, "read interrupt reg fail, ret=%d", ret); in aw_dev_get_int_status()
173 dev_dbg(aw_dev->dev, "read interrupt reg=0x%04x", *int_status); in aw_dev_get_int_status()
176 static void aw_dev_clear_int_status(struct aw_device *aw_dev) in aw_dev_clear_int_status() argument
181 aw_dev_get_int_status(aw_dev, &int_status); in aw_dev_clear_int_status()
183 aw_dev_get_int_status(aw_dev, &int_status); in aw_dev_clear_int_status()
185 dev_dbg(aw_dev->dev, "int status(%d) is not cleaned.\n", int_status); in aw_dev_clear_int_status()
188 static int aw_dev_get_iis_status(struct aw_device *aw_dev) in aw_dev_get_iis_status() argument
193 ret = regmap_read(aw_dev->regmap, AW88166_SYSST_REG, ®_val); in aw_dev_get_iis_status()
197 dev_err(aw_dev->dev, "check pll lock fail, reg_val:0x%04x", reg_val); in aw_dev_get_iis_status()
204 static int aw_dev_check_mode1_pll(struct aw_device *aw_dev) in aw_dev_check_mode1_pll() argument
209 ret = aw_dev_get_iis_status(aw_dev); in aw_dev_check_mode1_pll()
211 dev_err(aw_dev->dev, "mode1 iis signal check error"); in aw_dev_check_mode1_pll()
221 static int aw_dev_check_mode2_pll(struct aw_device *aw_dev) in aw_dev_check_mode2_pll() argument
226 ret = regmap_read(aw_dev->regmap, AW88166_PLLCTRL2_REG, ®_val); in aw_dev_check_mode2_pll()
232 dev_dbg(aw_dev->dev, "CCO_MUX is already divider"); in aw_dev_check_mode2_pll()
237 ret = regmap_update_bits(aw_dev->regmap, AW88166_PLLCTRL2_REG, in aw_dev_check_mode2_pll()
243 ret = aw_dev_get_iis_status(aw_dev); in aw_dev_check_mode2_pll()
245 dev_err(aw_dev->dev, "mode2 iis signal check error"); in aw_dev_check_mode2_pll()
253 regmap_update_bits(aw_dev->regmap, AW88166_PLLCTRL2_REG, in aw_dev_check_mode2_pll()
258 ret = aw_dev_get_iis_status(aw_dev); in aw_dev_check_mode2_pll()
260 dev_err(aw_dev->dev, "mode2 switch to mode1, iis signal check error"); in aw_dev_check_mode2_pll()
271 static int aw_dev_check_syspll(struct aw_device *aw_dev) in aw_dev_check_syspll() argument
275 ret = aw_dev_check_mode1_pll(aw_dev); in aw_dev_check_syspll()
277 dev_dbg(aw_dev->dev, "mode1 check iis failed try switch to mode2 check"); in aw_dev_check_syspll()
278 ret = aw_dev_check_mode2_pll(aw_dev); in aw_dev_check_syspll()
280 dev_err(aw_dev->dev, "mode2 check iis failed"); in aw_dev_check_syspll()
288 static int aw_dev_check_sysst(struct aw_device *aw_dev) in aw_dev_check_sysst() argument
294 ret = regmap_read(aw_dev->regmap, AW88166_PWMCTRL3_REG, ®_val); in aw_dev_check_sysst()
304 ret = regmap_read(aw_dev->regmap, AW88166_SYSST_REG, ®_val); in aw_dev_check_sysst()
309 dev_err(aw_dev->dev, "check sysst fail, cnt=%d, reg_val=0x%04x, check:0x%x", in aw_dev_check_sysst()
320 static void aw_dev_amppd(struct aw_device *aw_dev, bool amppd) in aw_dev_amppd() argument
325 ret = regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw_dev_amppd()
328 ret = regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw_dev_amppd()
332 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_amppd()
335 static void aw_dev_dsp_enable(struct aw_device *aw_dev, bool is_enable) in aw_dev_dsp_enable() argument
340 ret = regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw_dev_dsp_enable()
343 ret = regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw_dev_dsp_enable()
347 dev_dbg(aw_dev->dev, "%s failed\n", __func__); in aw_dev_dsp_enable()
352 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_get_icalk() local
358 ret = regmap_read(aw_dev->regmap, AW88166_EFRM2_REG, &efrm_reg_val); in aw88166_dev_get_icalk()
365 ret = regmap_read(aw_dev->regmap, AW88166_EFRL_REG, &efrl_reg_val); in aw88166_dev_get_icalk()
386 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_get_vcalk() local
392 ret = regmap_read(aw_dev->regmap, AW88166_EFRM2_REG, &efrm_reg_val); in aw88166_dev_get_vcalk()
399 ret = regmap_read(aw_dev->regmap, AW88166_EFRL_REG, &efrl_reg_val); in aw88166_dev_get_vcalk()
420 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_set_vcalb() local
428 dev_err(aw_dev->dev, "get icalk failed\n"); in aw88166_dev_set_vcalb()
435 dev_err(aw_dev->dev, "get vbcalk failed\n"); in aw88166_dev_set_vcalb()
446 regmap_write(aw_dev->regmap, AW88166_DSPVCALB_REG, reg_val); in aw88166_dev_set_vcalb()
453 struct aw_device *aw_dev = aw88166->aw_pa; in aw_dev_init_vcalb_update() local
458 ret = regmap_write(aw_dev->regmap, AW88166_DSPVCALB_REG, aw88166->vcalb_init_val); in aw_dev_init_vcalb_update()
461 ret = regmap_read(aw_dev->regmap, AW88166_DSPVCALB_REG, &aw88166->vcalb_init_val); in aw_dev_init_vcalb_update()
464 dev_err(aw_dev->dev, "unsupported type:%d\n", flag); in aw_dev_init_vcalb_update()
474 struct aw_device *aw_dev = aw88166->aw_pa; in aw_dev_init_re_update() local
480 ret = regmap_write(aw_dev->regmap, AW88166_ACR1_REG, aw88166->re_init_val >> 16); in aw_dev_init_re_update()
483 ret = regmap_write(aw_dev->regmap, AW88166_ACR2_REG, in aw_dev_init_re_update()
489 ret = regmap_read(aw_dev->regmap, AW88166_ACR1_REG, &re_temp_h); in aw_dev_init_re_update()
492 ret = regmap_read(aw_dev->regmap, AW88166_ACR2_REG, &re_temp_l); in aw_dev_init_re_update()
498 dev_err(aw_dev->dev, "unsupported type:%d\n", flag); in aw_dev_init_re_update()
520 struct aw_device *aw_dev = in aw_dev_update_cali_re() local
526 if ((aw_dev->cali_desc.cali_re >= AW88166_CALI_RE_MAX) || in aw_dev_update_cali_re()
527 (aw_dev->cali_desc.cali_re <= AW88166_CALI_RE_MIN)) in aw_dev_update_cali_re()
530 cali_re = AW88166_SHOW_RE_TO_DSP_RE((aw_dev->cali_desc.cali_re + in aw_dev_update_cali_re()
531 aw_dev->cali_desc.ra), AW88166_DSP_RE_SHIFT); in aw_dev_update_cali_re()
536 ret = regmap_write(aw_dev->regmap, AW88166_ACR1_REG, re_hbits); in aw_dev_update_cali_re()
538 dev_err(aw_dev->dev, "set cali re error"); in aw_dev_update_cali_re()
542 ret = regmap_write(aw_dev->regmap, AW88166_ACR2_REG, re_lbits); in aw_dev_update_cali_re()
544 dev_err(aw_dev->dev, "set cali re error"); in aw_dev_update_cali_re()
549 static int aw_dev_fw_crc_check(struct aw_device *aw_dev) in aw_dev_fw_crc_check() argument
556 fw_len_val = ((aw_dev->dsp_fw_len / AW_FW_ADDR_LEN) - 1) + AW88166_CRC_FW_BASE_ADDR; in aw_dev_fw_crc_check()
559 ret = regmap_update_bits(aw_dev->regmap, AW88166_CRCCTRL_REG, in aw_dev_fw_crc_check()
564 ret = regmap_update_bits(aw_dev->regmap, AW88166_CRCCTRL_REG, in aw_dev_fw_crc_check()
570 regmap_read(aw_dev->regmap, AW88166_HAGCST_REG, ®_val); in aw_dev_fw_crc_check()
577 ret = regmap_update_bits(aw_dev->regmap, AW88166_CRCCTRL_REG, in aw_dev_fw_crc_check()
583 dev_err(aw_dev->dev, "%s failed, check_val 0x%x != 0x%x\n", in aw_dev_fw_crc_check()
591 static int aw_dev_cfg_crc_check(struct aw_device *aw_dev) in aw_dev_cfg_crc_check() argument
598 cfg_len_val = ((aw_dev->dsp_cfg_len / AW_FW_ADDR_LEN) - 1) + AW88166_CRC_CFG_BASE_ADDR; in aw_dev_cfg_crc_check()
601 ret = regmap_update_bits(aw_dev->regmap, AW88166_CRCCTRL_REG, in aw_dev_cfg_crc_check()
607 ret = regmap_update_bits(aw_dev->regmap, AW88166_CRCCTRL_REG, in aw_dev_cfg_crc_check()
615 ret = regmap_read(aw_dev->regmap, AW88166_HAGCST_REG, ®_val); in aw_dev_cfg_crc_check()
622 ret = regmap_update_bits(aw_dev->regmap, AW88166_CRCCTRL_REG, in aw_dev_cfg_crc_check()
628 dev_err(aw_dev->dev, "crc_check failed, check val 0x%x != 0x%x\n", in aw_dev_cfg_crc_check()
638 struct aw_device *aw_dev = aw88166->aw_pa; in aw_dev_hw_crc_check() local
641 ret = regmap_update_bits(aw_dev->regmap, AW88166_I2SCFG1_REG, in aw_dev_hw_crc_check()
646 ret = aw_dev_fw_crc_check(aw_dev); in aw_dev_hw_crc_check()
648 dev_err(aw_dev->dev, "fw_crc_check failed\n"); in aw_dev_hw_crc_check()
652 ret = aw_dev_cfg_crc_check(aw_dev); in aw_dev_hw_crc_check()
654 dev_err(aw_dev->dev, "cfg_crc_check failed\n"); in aw_dev_hw_crc_check()
658 ret = regmap_write(aw_dev->regmap, AW88166_CRCCTRL_REG, aw88166->crc_init_val); in aw_dev_hw_crc_check()
662 ret = regmap_update_bits(aw_dev->regmap, AW88166_I2SCFG1_REG, in aw_dev_hw_crc_check()
668 regmap_update_bits(aw_dev->regmap, AW88166_I2SCFG1_REG, in aw_dev_hw_crc_check()
673 static void aw_dev_i2s_tx_enable(struct aw_device *aw_dev, bool flag) in aw_dev_i2s_tx_enable() argument
678 ret = regmap_update_bits(aw_dev->regmap, AW88166_I2SCTRL3_REG, in aw_dev_i2s_tx_enable()
681 ret = regmap_update_bits(aw_dev->regmap, AW88166_I2SCTRL3_REG, in aw_dev_i2s_tx_enable()
685 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_i2s_tx_enable()
688 static int aw_dev_get_dsp_status(struct aw_device *aw_dev) in aw_dev_get_dsp_status() argument
693 ret = regmap_read(aw_dev->regmap, AW88166_WDT_REG, ®_val); in aw_dev_get_dsp_status()
702 static int aw_dev_dsp_check(struct aw_device *aw_dev) in aw_dev_dsp_check() argument
706 switch (aw_dev->dsp_cfg) { in aw_dev_dsp_check()
708 dev_dbg(aw_dev->dev, "dsp bypass"); in aw_dev_dsp_check()
712 aw_dev_dsp_enable(aw_dev, false); in aw_dev_dsp_check()
713 aw_dev_dsp_enable(aw_dev, true); in aw_dev_dsp_check()
716 ret = aw_dev_get_dsp_status(aw_dev); in aw_dev_dsp_check()
718 dev_err(aw_dev->dev, "dsp wdt status error=%d", ret); in aw_dev_dsp_check()
724 dev_err(aw_dev->dev, "unknown dsp cfg=%d", aw_dev->dsp_cfg); in aw_dev_dsp_check()
732 static int aw_dev_set_volume(struct aw_device *aw_dev, unsigned int value) in aw_dev_set_volume() argument
734 struct aw_volume_desc *vol_desc = &aw_dev->volume_desc; in aw_dev_set_volume()
741 ret = regmap_read(aw_dev->regmap, AW88166_SYSCTRL2_REG, ®_value); in aw_dev_set_volume()
745 dev_dbg(aw_dev->dev, "value 0x%x , reg:0x%x", value, real_value); in aw_dev_set_volume()
749 ret = regmap_write(aw_dev->regmap, AW88166_SYSCTRL2_REG, real_value); in aw_dev_set_volume()
754 static void aw_dev_fade_in(struct aw_device *aw_dev) in aw_dev_fade_in() argument
756 struct aw_volume_desc *desc = &aw_dev->volume_desc; in aw_dev_fade_in()
758 int fade_step = aw_dev->fade_step; in aw_dev_fade_in()
761 if (fade_step == 0 || aw_dev->fade_in_time == 0) { in aw_dev_fade_in()
762 aw_dev_set_volume(aw_dev, fade_in_vol); in aw_dev_fade_in()
767 aw_dev_set_volume(aw_dev, i); in aw_dev_fade_in()
768 usleep_range(aw_dev->fade_in_time, aw_dev->fade_in_time + 10); in aw_dev_fade_in()
772 aw_dev_set_volume(aw_dev, fade_in_vol); in aw_dev_fade_in()
775 static void aw_dev_fade_out(struct aw_device *aw_dev) in aw_dev_fade_out() argument
777 struct aw_volume_desc *desc = &aw_dev->volume_desc; in aw_dev_fade_out()
778 int fade_step = aw_dev->fade_step; in aw_dev_fade_out()
781 if (fade_step == 0 || aw_dev->fade_out_time == 0) { in aw_dev_fade_out()
782 aw_dev_set_volume(aw_dev, AW88166_MUTE_VOL); in aw_dev_fade_out()
787 aw_dev_set_volume(aw_dev, i); in aw_dev_fade_out()
788 usleep_range(aw_dev->fade_out_time, aw_dev->fade_out_time + 10); in aw_dev_fade_out()
792 aw_dev_set_volume(aw_dev, AW88166_MUTE_VOL); in aw_dev_fade_out()
793 usleep_range(aw_dev->fade_out_time, aw_dev->fade_out_time + 10); in aw_dev_fade_out()
797 static void aw88166_dev_mute(struct aw_device *aw_dev, bool is_mute) in aw88166_dev_mute() argument
800 aw_dev_fade_out(aw_dev); in aw88166_dev_mute()
801 regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw88166_dev_mute()
804 regmap_update_bits(aw_dev->regmap, AW88166_SYSCTRL_REG, in aw88166_dev_mute()
806 aw_dev_fade_in(aw_dev); in aw88166_dev_mute()
812 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_set_dither() local
815 regmap_update_bits(aw_dev->regmap, AW88166_DBGCTRL_REG, in aw88166_dev_set_dither()
818 regmap_update_bits(aw_dev->regmap, AW88166_DBGCTRL_REG, in aw88166_dev_set_dither()
824 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_start() local
827 if (aw_dev->status == AW88166_DEV_PW_ON) { in aw88166_dev_start()
828 dev_dbg(aw_dev->dev, "already power on"); in aw88166_dev_start()
835 aw_dev_pwd(aw_dev, false); in aw88166_dev_start()
838 ret = aw_dev_check_syspll(aw_dev); in aw88166_dev_start()
840 dev_err(aw_dev->dev, "pll check failed cannot start\n"); in aw88166_dev_start()
845 aw_dev_amppd(aw_dev, false); in aw88166_dev_start()
849 ret = aw_dev_check_sysst(aw_dev); in aw88166_dev_start()
851 dev_err(aw_dev->dev, "sysst check failed\n"); in aw88166_dev_start()
855 if (aw_dev->dsp_cfg == AW88166_DEV_DSP_WORK) { in aw88166_dev_start()
859 dev_err(aw_dev->dev, "dsp crc check failed\n"); in aw88166_dev_start()
862 aw_dev_dsp_enable(aw_dev, false); in aw88166_dev_start()
864 aw_dev_update_cali_re(&aw_dev->cali_desc); in aw88166_dev_start()
865 ret = aw_dev_dsp_check(aw_dev); in aw88166_dev_start()
867 dev_err(aw_dev->dev, "dsp status check failed\n"); in aw88166_dev_start()
871 dev_dbg(aw_dev->dev, "start pa with dsp bypass"); in aw88166_dev_start()
875 aw_dev_i2s_tx_enable(aw_dev, true); in aw88166_dev_start()
881 aw88166_dev_mute(aw_dev, false); in aw88166_dev_start()
883 aw_dev_clear_int_status(aw_dev); in aw88166_dev_start()
884 aw_dev->status = AW88166_DEV_PW_ON; in aw88166_dev_start()
890 aw_dev_dsp_enable(aw_dev, false); in aw88166_dev_start()
892 aw_dev_clear_int_status(aw_dev); in aw88166_dev_start()
893 aw_dev_amppd(aw_dev, true); in aw88166_dev_start()
895 aw_dev_pwd(aw_dev, true); in aw88166_dev_start()
896 aw_dev->status = AW88166_DEV_PW_OFF; in aw88166_dev_start()
901 static int aw_dev_dsp_update_container(struct aw_device *aw_dev, in aw_dev_dsp_update_container() argument
907 mutex_lock(&aw_dev->dsp_lock); in aw_dev_dsp_update_container()
908 ret = regmap_write(aw_dev->regmap, AW88166_DSPMADD_REG, base); in aw_dev_dsp_update_container()
914 ret = regmap_raw_write(aw_dev->regmap, AW88166_DSPMDAT_REG, in aw_dev_dsp_update_container()
919 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_dsp_update_container()
924 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_dsp_update_container()
930 struct aw_device *aw_dev = in aw_dev_get_ra() local
935 ret = aw_dev_dsp_read(aw_dev, AW88166_DSP_REG_CFG_ADPZ_RA, in aw_dev_get_ra()
938 dev_err(aw_dev->dev, "read ra error\n"); in aw_dev_get_ra()
948 static int aw_dev_dsp_update_cfg(struct aw_device *aw_dev, in aw_dev_dsp_update_cfg() argument
953 dev_dbg(aw_dev->dev, "dsp config len:%d", len); in aw_dev_dsp_update_cfg()
956 dev_err(aw_dev->dev, "dsp config data is null or len is 0\n"); in aw_dev_dsp_update_cfg()
960 ret = aw_dev_dsp_update_container(aw_dev, data, len, AW88166_DSP_CFG_ADDR); in aw_dev_dsp_update_cfg()
964 aw_dev->dsp_cfg_len = len; in aw_dev_dsp_update_cfg()
966 ret = aw_dev_get_ra(&aw_dev->cali_desc); in aw_dev_dsp_update_cfg()
971 static int aw_dev_dsp_update_fw(struct aw_device *aw_dev, in aw_dev_dsp_update_fw() argument
976 dev_dbg(aw_dev->dev, "dsp firmware len:%d", len); in aw_dev_dsp_update_fw()
979 dev_err(aw_dev->dev, "dsp firmware data is null or len is 0\n"); in aw_dev_dsp_update_fw()
983 aw_dev->dsp_fw_len = len; in aw_dev_dsp_update_fw()
984 ret = aw_dev_dsp_update_container(aw_dev, data, len, AW88166_DSP_FW_ADDR); in aw_dev_dsp_update_fw()
989 static int aw_dev_check_sram(struct aw_device *aw_dev) in aw_dev_check_sram() argument
993 mutex_lock(&aw_dev->dsp_lock); in aw_dev_check_sram()
995 aw_dev_dsp_read_16bit(aw_dev, AW88166_DSP_ROM_CHECK_ADDR, ®_val); in aw_dev_check_sram()
997 dev_err(aw_dev->dev, "check dsp rom failed, read[0x%x] != check[0x%x]\n", in aw_dev_check_sram()
1003 aw_dev_dsp_write_16bit(aw_dev, AW88166_DSP_CFG_ADDR, AW88166_DSP_ODD_NUM_BIT_TEST); in aw_dev_check_sram()
1004 aw_dev_dsp_read_16bit(aw_dev, AW88166_DSP_CFG_ADDR, ®_val); in aw_dev_check_sram()
1006 dev_err(aw_dev->dev, "check dsp cfg failed, read[0x%x] != write[0x%x]\n", in aw_dev_check_sram()
1010 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_check_sram()
1014 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_check_sram()
1018 static void aw_dev_select_memclk(struct aw_device *aw_dev, unsigned char flag) in aw_dev_select_memclk() argument
1024 ret = regmap_update_bits(aw_dev->regmap, AW88166_DBGCTRL_REG, in aw_dev_select_memclk()
1028 dev_err(aw_dev->dev, "memclk select pll failed\n"); in aw_dev_select_memclk()
1031 ret = regmap_update_bits(aw_dev->regmap, AW88166_DBGCTRL_REG, in aw_dev_select_memclk()
1035 dev_err(aw_dev->dev, "memclk select OSC failed\n"); in aw_dev_select_memclk()
1038 dev_err(aw_dev->dev, "unknown memclk config, flag=0x%x\n", flag); in aw_dev_select_memclk()
1046 struct aw_device *aw_dev = aw88166->aw_pa; in aw_dev_update_reg_container() local
1047 struct aw_volume_desc *vol_desc = &aw_dev->volume_desc; in aw_dev_update_reg_container()
1057 dev_err(aw_dev->dev, "data len:%d unsupported\n", data_len); in aw_dev_update_reg_container()
1072 aw_dev->dsp_cfg = AW88166_DEV_DSP_BYPASS; in aw_dev_update_reg_container()
1074 aw_dev->dsp_cfg = AW88166_DEV_DSP_WORK; in aw_dev_update_reg_container()
1090 aw_dev->volume_desc.init_volume = read_vol; in aw_dev_update_reg_container()
1115 ret = regmap_write(aw_dev->regmap, reg_addr, reg_val); in aw_dev_update_reg_container()
1120 aw_dev_pwd(aw_dev, false); in aw_dev_update_reg_container()
1123 if (aw_dev->prof_cur != aw_dev->prof_index) in aw_dev_update_reg_container()
1126 aw_dev_set_volume(aw_dev, vol_desc->ctl_volume); in aw_dev_update_reg_container()
1148 static int aw88166_dev_get_prof_name(struct aw_device *aw_dev, int index, char **prof_name) in aw88166_dev_get_prof_name() argument
1150 struct aw_prof_info *prof_info = &aw_dev->prof_info; in aw88166_dev_get_prof_name()
1153 if ((index >= aw_dev->prof_info.count) || (index < 0)) { in aw88166_dev_get_prof_name()
1154 dev_err(aw_dev->dev, "index[%d] overflow count[%d]\n", in aw88166_dev_get_prof_name()
1155 index, aw_dev->prof_info.count); in aw88166_dev_get_prof_name()
1159 prof_desc = &aw_dev->prof_info.prof_desc[index]; in aw88166_dev_get_prof_name()
1166 static int aw88166_dev_get_prof_data(struct aw_device *aw_dev, int index, in aw88166_dev_get_prof_data() argument
1169 if ((index >= aw_dev->prof_info.count) || (index < 0)) { in aw88166_dev_get_prof_data()
1170 dev_err(aw_dev->dev, "%s: index[%d] overflow count[%d]\n", in aw88166_dev_get_prof_data()
1171 __func__, index, aw_dev->prof_info.count); in aw88166_dev_get_prof_data()
1175 *prof_desc = &aw_dev->prof_info.prof_desc[index]; in aw88166_dev_get_prof_data()
1182 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_fw_update() local
1188 if ((aw_dev->prof_cur == aw_dev->prof_index) && in aw88166_dev_fw_update()
1190 dev_dbg(aw_dev->dev, "scene no change, not update"); in aw88166_dev_fw_update()
1194 if (aw_dev->fw_status == AW88166_DEV_FW_FAILED) { in aw88166_dev_fw_update()
1195 dev_err(aw_dev->dev, "fw status[%d] error\n", aw_dev->fw_status); in aw88166_dev_fw_update()
1199 ret = aw88166_dev_get_prof_name(aw_dev, aw_dev->prof_index, &prof_name); in aw88166_dev_fw_update()
1203 dev_dbg(aw_dev->dev, "start update %s", prof_name); in aw88166_dev_fw_update()
1205 ret = aw88166_dev_get_prof_data(aw_dev, aw_dev->prof_index, &prof_index_desc); in aw88166_dev_fw_update()
1214 dev_err(aw_dev->dev, "update reg failed\n"); in aw88166_dev_fw_update()
1218 aw88166_dev_mute(aw_dev, true); in aw88166_dev_fw_update()
1220 if (aw_dev->dsp_cfg == AW88166_DEV_DSP_WORK) in aw88166_dev_fw_update()
1221 aw_dev_dsp_enable(aw_dev, false); in aw88166_dev_fw_update()
1223 aw_dev_select_memclk(aw_dev, AW88166_DEV_MEMCLK_OSC); in aw88166_dev_fw_update()
1225 ret = aw_dev_check_sram(aw_dev); in aw88166_dev_fw_update()
1227 dev_err(aw_dev->dev, "check sram failed\n"); in aw88166_dev_fw_update()
1234 dev_dbg(aw_dev->dev, "fw_ver: [%x]", prof_index_desc->fw_ver); in aw88166_dev_fw_update()
1235 ret = aw_dev_dsp_update_fw(aw_dev, sec_desc[AW88395_DATA_TYPE_DSP_FW].data, in aw88166_dev_fw_update()
1238 dev_err(aw_dev->dev, "update dsp fw failed\n"); in aw88166_dev_fw_update()
1244 ret = aw_dev_dsp_update_cfg(aw_dev, sec_desc[AW88395_DATA_TYPE_DSP_CFG].data, in aw88166_dev_fw_update()
1247 dev_err(aw_dev->dev, "update dsp cfg failed\n"); in aw88166_dev_fw_update()
1253 aw_dev_select_memclk(aw_dev, AW88166_DEV_MEMCLK_PLL); in aw88166_dev_fw_update()
1255 aw_dev->prof_cur = aw_dev->prof_index; in aw88166_dev_fw_update()
1260 aw_dev_select_memclk(aw_dev, AW88166_DEV_MEMCLK_PLL); in aw88166_dev_fw_update()
1318 static int aw_dev_check_sysint(struct aw_device *aw_dev) in aw_dev_check_sysint() argument
1322 aw_dev_get_int_status(aw_dev, ®_val); in aw_dev_check_sysint()
1324 dev_err(aw_dev->dev, "pa stop check fail:0x%04x\n", reg_val); in aw_dev_check_sysint()
1331 static int aw88166_stop(struct aw_device *aw_dev) in aw88166_stop() argument
1334 &aw_dev->prof_info.prof_desc[aw_dev->prof_cur].sec_desc[AW88395_DATA_TYPE_DSP_CFG]; in aw88166_stop()
1336 &aw_dev->prof_info.prof_desc[aw_dev->prof_cur].sec_desc[AW88395_DATA_TYPE_DSP_FW]; in aw88166_stop()
1339 if (aw_dev->status == AW88166_DEV_PW_OFF) { in aw88166_stop()
1340 dev_dbg(aw_dev->dev, "already power off"); in aw88166_stop()
1344 aw_dev->status = AW88166_DEV_PW_OFF; in aw88166_stop()
1346 aw88166_dev_mute(aw_dev, true); in aw88166_stop()
1349 aw_dev_i2s_tx_enable(aw_dev, false); in aw88166_stop()
1352 int_st = aw_dev_check_sysint(aw_dev); in aw88166_stop()
1354 aw_dev_dsp_enable(aw_dev, false); in aw88166_stop()
1356 aw_dev_amppd(aw_dev, true); in aw88166_stop()
1359 aw_dev_select_memclk(aw_dev, AW88166_DEV_MEMCLK_OSC); in aw88166_stop()
1360 aw_dev_dsp_update_fw(aw_dev, dsp_fw->data, dsp_fw->len); in aw88166_stop()
1361 aw_dev_dsp_update_cfg(aw_dev, dsp_cfg->data, dsp_cfg->len); in aw88166_stop()
1362 aw_dev_select_memclk(aw_dev, AW88166_DEV_MEMCLK_PLL); in aw88166_stop()
1365 aw_dev_pwd(aw_dev, true); in aw88166_stop()
1396 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_get_fade_in_time() local
1398 ucontrol->value.integer.value[0] = aw_dev->fade_in_time; in aw88166_get_fade_in_time()
1410 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_set_fade_in_time() local
1418 if (time != aw_dev->fade_in_time) { in aw88166_set_fade_in_time()
1419 aw_dev->fade_in_time = time; in aw88166_set_fade_in_time()
1431 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_get_fade_out_time() local
1433 ucontrol->value.integer.value[0] = aw_dev->fade_out_time; in aw88166_get_fade_out_time()
1445 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_set_fade_out_time() local
1452 if (time != aw_dev->fade_out_time) { in aw88166_set_fade_out_time()
1453 aw_dev->fade_out_time = time; in aw88166_set_fade_out_time()
1460 static int aw88166_dev_set_profile_index(struct aw_device *aw_dev, int index) in aw88166_dev_set_profile_index() argument
1463 if ((index >= aw_dev->prof_info.count) || (index < 0)) in aw88166_dev_set_profile_index()
1466 if (aw_dev->prof_index == index) in aw88166_dev_set_profile_index()
1469 aw_dev->prof_index = index; in aw88166_dev_set_profile_index()
1470 dev_dbg(aw_dev->dev, "set prof[%s]", in aw88166_dev_set_profile_index()
1471 aw_dev->prof_info.prof_name_list[aw_dev->prof_info.prof_desc[index].id]); in aw88166_dev_set_profile_index()
1620 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_re_get() local
1622 ucontrol->value.integer.value[0] = aw_dev->cali_desc.cali_re; in aw88166_re_get()
1634 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_re_set() local
1641 if (aw_dev->cali_desc.cali_re != value) { in aw88166_re_set()
1642 aw_dev->cali_desc.cali_re = value; in aw88166_re_set()
1651 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_dev_init() local
1654 ret = aw88395_dev_cfg_load(aw_dev, aw_cfg); in aw88166_dev_init()
1656 dev_err(aw_dev->dev, "aw_dev acf parse failed\n"); in aw88166_dev_init()
1659 aw_dev->fade_in_time = AW88166_1000_US / 10; in aw88166_dev_init()
1660 aw_dev->fade_out_time = AW88166_1000_US >> 1; in aw88166_dev_init()
1661 aw_dev->prof_cur = aw_dev->prof_info.prof_desc[0].id; in aw88166_dev_init()
1662 aw_dev->prof_index = aw_dev->prof_info.prof_desc[0].id; in aw88166_dev_init()
1666 dev_err(aw_dev->dev, "fw update failed ret = %d\n", ret); in aw88166_dev_init()
1670 aw88166_dev_mute(aw_dev, true); in aw88166_dev_init()
1673 aw_dev_i2s_tx_enable(aw_dev, false); in aw88166_dev_init()
1677 aw_dev_amppd(aw_dev, true); in aw88166_dev_init()
1680 aw_dev_dsp_enable(aw_dev, false); in aw88166_dev_init()
1682 aw_dev_pwd(aw_dev, true); in aw88166_dev_init()
1828 struct aw_device *aw_dev = aw88166->aw_pa; in aw88166_parse_channel_dt() local
1829 struct device_node *np = aw_dev->dev->of_node; in aw88166_parse_channel_dt()
1833 aw_dev->channel = channel_value; in aw88166_parse_channel_dt()
1839 struct aw_device *aw_dev; in aw88166_init() local
1849 aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); in aw88166_init()
1850 if (!aw_dev) in aw88166_init()
1852 aw88166->aw_pa = aw_dev; in aw88166_init()
1854 aw_dev->i2c = i2c; in aw88166_init()
1855 aw_dev->dev = &i2c->dev; in aw88166_init()
1856 aw_dev->regmap = regmap; in aw88166_init()
1857 mutex_init(&aw_dev->dsp_lock); in aw88166_init()
1859 aw_dev->chip_id = chip_id; in aw88166_init()
1860 aw_dev->acf = NULL; in aw88166_init()
1861 aw_dev->prof_info.prof_desc = NULL; in aw88166_init()
1862 aw_dev->prof_info.count = 0; in aw88166_init()
1863 aw_dev->prof_info.prof_type = AW88395_DEV_NONE_TYPE_ID; in aw88166_init()
1864 aw_dev->channel = AW88166_DEV_DEFAULT_CH; in aw88166_init()
1865 aw_dev->fw_status = AW88166_DEV_FW_FAILED; in aw88166_init()
1867 aw_dev->fade_step = AW88166_VOLUME_STEP_DB; in aw88166_init()
1868 aw_dev->volume_desc.ctl_volume = AW88166_VOL_DEFAULT_VALUE; in aw88166_init()