Lines Matching refs:aw_dev
27 static int aw_dev_dsp_write_16bit(struct aw_device *aw_dev, in aw_dev_dsp_write_16bit() argument
32 ret = regmap_write(aw_dev->regmap, AW88399_DSPMADD_REG, dsp_addr); in aw_dev_dsp_write_16bit()
34 dev_err(aw_dev->dev, "%s write addr error, ret=%d", __func__, ret); in aw_dev_dsp_write_16bit()
38 ret = regmap_write(aw_dev->regmap, AW88399_DSPMDAT_REG, (u16)dsp_data); in aw_dev_dsp_write_16bit()
40 dev_err(aw_dev->dev, "%s write data error, ret=%d", __func__, ret); in aw_dev_dsp_write_16bit()
47 static int aw_dev_dsp_read_16bit(struct aw_device *aw_dev, in aw_dev_dsp_read_16bit() argument
53 ret = regmap_write(aw_dev->regmap, AW88399_DSPMADD_REG, dsp_addr); in aw_dev_dsp_read_16bit()
55 dev_err(aw_dev->dev, "%s write error, ret=%d", __func__, ret); in aw_dev_dsp_read_16bit()
59 ret = regmap_read(aw_dev->regmap, AW88399_DSPMDAT_REG, &temp_data); in aw_dev_dsp_read_16bit()
61 dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret); in aw_dev_dsp_read_16bit()
69 static int aw_dev_dsp_read_32bit(struct aw_device *aw_dev, in aw_dev_dsp_read_32bit() argument
75 ret = regmap_write(aw_dev->regmap, AW88399_DSPMADD_REG, dsp_addr); in aw_dev_dsp_read_32bit()
77 dev_err(aw_dev->dev, "%s write error, ret=%d", __func__, ret); in aw_dev_dsp_read_32bit()
81 ret = regmap_read(aw_dev->regmap, AW88399_DSPMDAT_REG, &temp_data); in aw_dev_dsp_read_32bit()
83 dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret); in aw_dev_dsp_read_32bit()
88 ret = regmap_read(aw_dev->regmap, AW88399_DSPMDAT_REG, &temp_data); in aw_dev_dsp_read_32bit()
90 dev_err(aw_dev->dev, "%s read error, ret=%d", __func__, ret); in aw_dev_dsp_read_32bit()
98 static int aw_dev_dsp_read(struct aw_device *aw_dev, in aw_dev_dsp_read() argument
104 mutex_lock(&aw_dev->dsp_lock); in aw_dev_dsp_read()
107 ret = aw_dev_dsp_read_16bit(aw_dev, dsp_addr, dsp_data); in aw_dev_dsp_read()
109 dev_err(aw_dev->dev, "read dsp_addr[0x%x] 16-bit dsp_data[0x%x] failed", in aw_dev_dsp_read()
113 ret = aw_dev_dsp_read_32bit(aw_dev, dsp_addr, dsp_data); in aw_dev_dsp_read()
115 dev_err(aw_dev->dev, "read dsp_addr[0x%x] 32r-bit dsp_data[0x%x] failed", in aw_dev_dsp_read()
119 dev_err(aw_dev->dev, "data type[%d] unsupported", data_type); in aw_dev_dsp_read()
125 if (regmap_read(aw_dev->regmap, AW88399_ID_REG, ®_value)) in aw_dev_dsp_read()
126 dev_err(aw_dev->dev, "%s fail to clear chip state. ret=%d\n", __func__, ret); in aw_dev_dsp_read()
127 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_dsp_read()
132 static void aw_dev_pwd(struct aw_device *aw_dev, bool pwd) in aw_dev_pwd() argument
137 ret = regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw_dev_pwd()
140 ret = regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw_dev_pwd()
144 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_pwd()
147 static void aw_dev_get_int_status(struct aw_device *aw_dev, unsigned short *int_status) in aw_dev_get_int_status() argument
152 ret = regmap_read(aw_dev->regmap, AW88399_SYSINT_REG, ®_val); in aw_dev_get_int_status()
154 dev_err(aw_dev->dev, "read interrupt reg fail, ret=%d", ret); in aw_dev_get_int_status()
158 dev_dbg(aw_dev->dev, "read interrupt reg=0x%04x", *int_status); in aw_dev_get_int_status()
161 static void aw_dev_clear_int_status(struct aw_device *aw_dev) in aw_dev_clear_int_status() argument
166 aw_dev_get_int_status(aw_dev, &int_status); in aw_dev_clear_int_status()
168 aw_dev_get_int_status(aw_dev, &int_status); in aw_dev_clear_int_status()
170 dev_dbg(aw_dev->dev, "int status(%d) is not cleaned.\n", int_status); in aw_dev_clear_int_status()
173 static int aw_dev_get_iis_status(struct aw_device *aw_dev) in aw_dev_get_iis_status() argument
178 ret = regmap_read(aw_dev->regmap, AW88399_SYSST_REG, ®_val); in aw_dev_get_iis_status()
182 dev_err(aw_dev->dev, "check pll lock fail, reg_val:0x%04x", reg_val); in aw_dev_get_iis_status()
189 static int aw_dev_check_mode1_pll(struct aw_device *aw_dev) in aw_dev_check_mode1_pll() argument
194 ret = aw_dev_get_iis_status(aw_dev); in aw_dev_check_mode1_pll()
196 dev_err(aw_dev->dev, "mode1 iis signal check error"); in aw_dev_check_mode1_pll()
206 static int aw_dev_check_mode2_pll(struct aw_device *aw_dev) in aw_dev_check_mode2_pll() argument
211 ret = regmap_read(aw_dev->regmap, AW88399_PLLCTRL2_REG, ®_val); in aw_dev_check_mode2_pll()
217 dev_dbg(aw_dev->dev, "CCO_MUX is already divider"); in aw_dev_check_mode2_pll()
222 ret = regmap_update_bits(aw_dev->regmap, AW88399_PLLCTRL2_REG, in aw_dev_check_mode2_pll()
228 ret = aw_dev_get_iis_status(aw_dev); in aw_dev_check_mode2_pll()
230 dev_err(aw_dev->dev, "mode2 iis signal check error"); in aw_dev_check_mode2_pll()
238 regmap_update_bits(aw_dev->regmap, AW88399_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 switch to mode1, iis signal check error"); in aw_dev_check_mode2_pll()
256 static int aw_dev_check_syspll(struct aw_device *aw_dev) in aw_dev_check_syspll() argument
260 ret = aw_dev_check_mode1_pll(aw_dev); in aw_dev_check_syspll()
262 dev_dbg(aw_dev->dev, "mode1 check iis failed try switch to mode2 check"); in aw_dev_check_syspll()
263 ret = aw_dev_check_mode2_pll(aw_dev); in aw_dev_check_syspll()
265 dev_err(aw_dev->dev, "mode2 check iis failed"); in aw_dev_check_syspll()
273 static int aw_dev_check_sysst(struct aw_device *aw_dev) in aw_dev_check_sysst() argument
279 ret = regmap_read(aw_dev->regmap, AW88399_PWMCTRL3_REG, ®_val); in aw_dev_check_sysst()
289 ret = regmap_read(aw_dev->regmap, AW88399_SYSST_REG, ®_val); in aw_dev_check_sysst()
294 dev_err(aw_dev->dev, "check sysst fail, cnt=%d, reg_val=0x%04x, check:0x%x", in aw_dev_check_sysst()
305 static void aw_dev_amppd(struct aw_device *aw_dev, bool amppd) in aw_dev_amppd() argument
310 ret = regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw_dev_amppd()
313 ret = regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw_dev_amppd()
317 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_amppd()
320 static void aw_dev_dsp_enable(struct aw_device *aw_dev, bool is_enable) in aw_dev_dsp_enable() argument
325 ret = regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw_dev_dsp_enable()
328 ret = regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw_dev_dsp_enable()
332 dev_dbg(aw_dev->dev, "%s failed\n", __func__); in aw_dev_dsp_enable()
338 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_get_icalk() local
342 ret = regmap_read(aw_dev->regmap, AW88399_EFRH4_REG, ®_val); in aw88399_dev_get_icalk()
347 ret = regmap_read(aw_dev->regmap, AW88399_EFRL4_REG, ®_val); in aw88399_dev_get_icalk()
367 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_get_vcalk() local
371 ret = regmap_read(aw_dev->regmap, AW88399_EFRH3_REG, ®_val); in aw88399_dev_get_vcalk()
377 ret = regmap_read(aw_dev->regmap, AW88399_EFRL3_REG, ®_val); in aw88399_dev_get_vcalk()
398 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_get_internal_vcalk() local
402 ret = regmap_read(aw_dev->regmap, AW88399_EFRH2_REG, ®_val); in aw88399_dev_get_internal_vcalk()
407 ret = regmap_read(aw_dev->regmap, AW88399_EFRL2_REG, ®_val); in aw88399_dev_get_internal_vcalk()
429 struct aw_device *aw_dev = aw88399->aw_pa; in aw_dev_set_vcalb() local
436 ret = regmap_read(aw_dev->regmap, AW88399_VSNCTRL1_REG, &vsense_value); in aw_dev_set_vcalb()
444 dev_err(aw_dev->dev, "get icalk failed\n"); in aw_dev_set_vcalb()
465 dev_err(aw_dev->dev, "%s: unsupport vsense\n", __func__); in aw_dev_set_vcalb()
475 regmap_write(aw_dev->regmap, AW88399_DSPVCALB_REG, reg_val); in aw_dev_set_vcalb()
482 struct aw_device *aw_dev = in aw_dev_update_cali_re() local
488 if ((aw_dev->cali_desc.cali_re >= AW88399_CALI_RE_MAX) || in aw_dev_update_cali_re()
489 (aw_dev->cali_desc.cali_re <= AW88399_CALI_RE_MIN)) in aw_dev_update_cali_re()
492 cali_re = AW88399_SHOW_RE_TO_DSP_RE((aw_dev->cali_desc.cali_re + in aw_dev_update_cali_re()
493 aw_dev->cali_desc.ra), AW88399_DSP_RE_SHIFT); in aw_dev_update_cali_re()
498 ret = regmap_write(aw_dev->regmap, AW88399_ACR1_REG, re_hbits); in aw_dev_update_cali_re()
500 dev_err(aw_dev->dev, "set cali re error"); in aw_dev_update_cali_re()
504 ret = regmap_write(aw_dev->regmap, AW88399_ACR2_REG, re_lbits); in aw_dev_update_cali_re()
506 dev_err(aw_dev->dev, "set cali re error"); in aw_dev_update_cali_re()
511 static int aw_dev_fw_crc_check(struct aw_device *aw_dev) in aw_dev_fw_crc_check() argument
518 fw_len_val = ((aw_dev->dsp_fw_len / AW_FW_ADDR_LEN) - 1) + AW88399_CRC_FW_BASE_ADDR; in aw_dev_fw_crc_check()
521 ret = regmap_update_bits(aw_dev->regmap, AW88399_CRCCTRL_REG, in aw_dev_fw_crc_check()
526 ret = regmap_update_bits(aw_dev->regmap, AW88399_CRCCTRL_REG, in aw_dev_fw_crc_check()
532 regmap_read(aw_dev->regmap, AW88399_HAGCST_REG, ®_val); in aw_dev_fw_crc_check()
539 ret = regmap_update_bits(aw_dev->regmap, AW88399_CRCCTRL_REG, in aw_dev_fw_crc_check()
545 dev_err(aw_dev->dev, "%s failed, check_val 0x%x != 0x%x", in aw_dev_fw_crc_check()
553 static int aw_dev_cfg_crc_check(struct aw_device *aw_dev) in aw_dev_cfg_crc_check() argument
560 cfg_len_val = ((aw_dev->dsp_cfg_len / AW_FW_ADDR_LEN) - 1) + AW88399_CRC_CFG_BASE_ADDR; in aw_dev_cfg_crc_check()
563 ret = regmap_update_bits(aw_dev->regmap, AW88399_CRCCTRL_REG, in aw_dev_cfg_crc_check()
569 ret = regmap_update_bits(aw_dev->regmap, AW88399_CRCCTRL_REG, in aw_dev_cfg_crc_check()
577 ret = regmap_read(aw_dev->regmap, AW88399_HAGCST_REG, ®_val); in aw_dev_cfg_crc_check()
584 ret = regmap_update_bits(aw_dev->regmap, AW88399_CRCCTRL_REG, in aw_dev_cfg_crc_check()
590 dev_err(aw_dev->dev, "crc_check failed, check val 0x%x != 0x%x", in aw_dev_cfg_crc_check()
600 struct aw_device *aw_dev = aw88399->aw_pa; in aw_dev_hw_crc_check() local
603 ret = regmap_update_bits(aw_dev->regmap, AW88399_I2SCFG1_REG, in aw_dev_hw_crc_check()
608 ret = aw_dev_fw_crc_check(aw_dev); in aw_dev_hw_crc_check()
610 dev_err(aw_dev->dev, "fw_crc_check failed\n"); in aw_dev_hw_crc_check()
614 ret = aw_dev_cfg_crc_check(aw_dev); in aw_dev_hw_crc_check()
616 dev_err(aw_dev->dev, "cfg_crc_check failed\n"); in aw_dev_hw_crc_check()
620 ret = regmap_write(aw_dev->regmap, AW88399_CRCCTRL_REG, aw88399->crc_init_val); in aw_dev_hw_crc_check()
624 ret = regmap_update_bits(aw_dev->regmap, AW88399_I2SCFG1_REG, in aw_dev_hw_crc_check()
630 regmap_update_bits(aw_dev->regmap, AW88399_I2SCFG1_REG, in aw_dev_hw_crc_check()
635 static void aw_dev_i2s_tx_enable(struct aw_device *aw_dev, bool flag) in aw_dev_i2s_tx_enable() argument
640 ret = regmap_update_bits(aw_dev->regmap, AW88399_I2SCTRL3_REG, in aw_dev_i2s_tx_enable()
643 ret = regmap_update_bits(aw_dev->regmap, AW88399_I2SCFG1_REG, in aw_dev_i2s_tx_enable()
647 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_i2s_tx_enable()
650 static int aw_dev_get_dsp_status(struct aw_device *aw_dev) in aw_dev_get_dsp_status() argument
655 ret = regmap_read(aw_dev->regmap, AW88399_WDT_REG, ®_val); in aw_dev_get_dsp_status()
664 static int aw_dev_dsp_check(struct aw_device *aw_dev) in aw_dev_dsp_check() argument
668 switch (aw_dev->dsp_cfg) { in aw_dev_dsp_check()
670 dev_dbg(aw_dev->dev, "dsp bypass"); in aw_dev_dsp_check()
674 aw_dev_dsp_enable(aw_dev, false); in aw_dev_dsp_check()
675 aw_dev_dsp_enable(aw_dev, true); in aw_dev_dsp_check()
678 ret = aw_dev_get_dsp_status(aw_dev); in aw_dev_dsp_check()
680 dev_err(aw_dev->dev, "dsp wdt status error=%d", ret); in aw_dev_dsp_check()
686 dev_err(aw_dev->dev, "unknown dsp cfg=%d", aw_dev->dsp_cfg); in aw_dev_dsp_check()
694 static int aw_dev_set_volume(struct aw_device *aw_dev, unsigned int value) in aw_dev_set_volume() argument
696 struct aw_volume_desc *vol_desc = &aw_dev->volume_desc; in aw_dev_set_volume()
703 ret = regmap_read(aw_dev->regmap, AW88399_SYSCTRL2_REG, ®_value); in aw_dev_set_volume()
707 dev_dbg(aw_dev->dev, "value 0x%x , reg:0x%x", value, real_value); in aw_dev_set_volume()
711 ret = regmap_write(aw_dev->regmap, AW88399_SYSCTRL2_REG, real_value); in aw_dev_set_volume()
716 static void aw_dev_fade_in(struct aw_device *aw_dev) in aw_dev_fade_in() argument
718 struct aw_volume_desc *desc = &aw_dev->volume_desc; in aw_dev_fade_in()
720 int fade_step = aw_dev->fade_step; in aw_dev_fade_in()
723 if (fade_step == 0 || aw_dev->fade_in_time == 0) { in aw_dev_fade_in()
724 aw_dev_set_volume(aw_dev, fade_in_vol); in aw_dev_fade_in()
729 aw_dev_set_volume(aw_dev, i); in aw_dev_fade_in()
730 usleep_range(aw_dev->fade_in_time, aw_dev->fade_in_time + 10); in aw_dev_fade_in()
734 aw_dev_set_volume(aw_dev, fade_in_vol); in aw_dev_fade_in()
737 static void aw_dev_fade_out(struct aw_device *aw_dev) in aw_dev_fade_out() argument
739 struct aw_volume_desc *desc = &aw_dev->volume_desc; in aw_dev_fade_out()
740 int fade_step = aw_dev->fade_step; in aw_dev_fade_out()
743 if (fade_step == 0 || aw_dev->fade_out_time == 0) { in aw_dev_fade_out()
744 aw_dev_set_volume(aw_dev, AW88399_MUTE_VOL); in aw_dev_fade_out()
749 aw_dev_set_volume(aw_dev, i); in aw_dev_fade_out()
750 usleep_range(aw_dev->fade_out_time, aw_dev->fade_out_time + 10); in aw_dev_fade_out()
754 aw_dev_set_volume(aw_dev, AW88399_MUTE_VOL); in aw_dev_fade_out()
755 usleep_range(aw_dev->fade_out_time, aw_dev->fade_out_time + 10); in aw_dev_fade_out()
759 static void aw88399_dev_mute(struct aw_device *aw_dev, bool is_mute) in aw88399_dev_mute() argument
762 aw_dev_fade_out(aw_dev); in aw88399_dev_mute()
763 regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw88399_dev_mute()
766 regmap_update_bits(aw_dev->regmap, AW88399_SYSCTRL_REG, in aw88399_dev_mute()
768 aw_dev_fade_in(aw_dev); in aw88399_dev_mute()
774 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_set_dither() local
777 regmap_update_bits(aw_dev->regmap, AW88399_DBGCTRL_REG, in aw88399_dev_set_dither()
780 regmap_update_bits(aw_dev->regmap, AW88399_DBGCTRL_REG, in aw88399_dev_set_dither()
786 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_start() local
789 if (aw_dev->status == AW88399_DEV_PW_ON) { in aw88399_dev_start()
790 dev_dbg(aw_dev->dev, "already power on"); in aw88399_dev_start()
797 aw_dev_pwd(aw_dev, false); in aw88399_dev_start()
800 ret = aw_dev_check_syspll(aw_dev); in aw88399_dev_start()
802 dev_err(aw_dev->dev, "pll check failed cannot start"); in aw88399_dev_start()
807 aw_dev_amppd(aw_dev, false); in aw88399_dev_start()
811 ret = aw_dev_check_sysst(aw_dev); in aw88399_dev_start()
813 dev_err(aw_dev->dev, "sysst check failed"); in aw88399_dev_start()
817 if (aw_dev->dsp_cfg == AW88399_DEV_DSP_WORK) { in aw88399_dev_start()
820 dev_err(aw_dev->dev, "dsp crc check failed"); in aw88399_dev_start()
823 aw_dev_dsp_enable(aw_dev, false); in aw88399_dev_start()
825 aw_dev_update_cali_re(&aw_dev->cali_desc); in aw88399_dev_start()
827 ret = aw_dev_dsp_check(aw_dev); in aw88399_dev_start()
829 dev_err(aw_dev->dev, "dsp status check failed"); in aw88399_dev_start()
833 dev_dbg(aw_dev->dev, "start pa with dsp bypass"); in aw88399_dev_start()
837 aw_dev_i2s_tx_enable(aw_dev, true); in aw88399_dev_start()
843 aw88399_dev_mute(aw_dev, false); in aw88399_dev_start()
845 aw_dev_clear_int_status(aw_dev); in aw88399_dev_start()
846 aw_dev->status = AW88399_DEV_PW_ON; in aw88399_dev_start()
852 aw_dev_dsp_enable(aw_dev, false); in aw88399_dev_start()
854 aw_dev_clear_int_status(aw_dev); in aw88399_dev_start()
855 aw_dev_amppd(aw_dev, true); in aw88399_dev_start()
857 aw_dev_pwd(aw_dev, true); in aw88399_dev_start()
858 aw_dev->status = AW88399_DEV_PW_OFF; in aw88399_dev_start()
863 static int aw_dev_dsp_update_container(struct aw_device *aw_dev, in aw_dev_dsp_update_container() argument
869 mutex_lock(&aw_dev->dsp_lock); in aw_dev_dsp_update_container()
870 ret = regmap_write(aw_dev->regmap, AW88399_DSPMADD_REG, base); in aw_dev_dsp_update_container()
880 ret = regmap_raw_write(aw_dev->regmap, AW88399_DSPMDAT_REG, in aw_dev_dsp_update_container()
885 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_dsp_update_container()
890 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_dsp_update_container()
896 struct aw_device *aw_dev = in aw_dev_get_ra() local
901 ret = aw_dev_dsp_read(aw_dev, AW88399_DSP_REG_CFG_ADPZ_RA, in aw_dev_get_ra()
904 dev_err(aw_dev->dev, "read ra error"); in aw_dev_get_ra()
914 static int aw_dev_dsp_update_cfg(struct aw_device *aw_dev, in aw_dev_dsp_update_cfg() argument
919 dev_dbg(aw_dev->dev, "dsp config len:%d", len); in aw_dev_dsp_update_cfg()
922 dev_err(aw_dev->dev, "dsp config data is null or len is 0"); in aw_dev_dsp_update_cfg()
926 ret = aw_dev_dsp_update_container(aw_dev, data, len, AW88399_DSP_CFG_ADDR); in aw_dev_dsp_update_cfg()
930 aw_dev->dsp_cfg_len = len; in aw_dev_dsp_update_cfg()
932 ret = aw_dev_get_ra(&aw_dev->cali_desc); in aw_dev_dsp_update_cfg()
937 static int aw_dev_dsp_update_fw(struct aw_device *aw_dev, in aw_dev_dsp_update_fw() argument
942 dev_dbg(aw_dev->dev, "dsp firmware len:%d", len); in aw_dev_dsp_update_fw()
945 dev_err(aw_dev->dev, "dsp firmware data is null or len is 0"); in aw_dev_dsp_update_fw()
949 aw_dev->dsp_fw_len = len; in aw_dev_dsp_update_fw()
950 ret = aw_dev_dsp_update_container(aw_dev, data, len, AW88399_DSP_FW_ADDR); in aw_dev_dsp_update_fw()
955 static int aw_dev_check_sram(struct aw_device *aw_dev) in aw_dev_check_sram() argument
959 mutex_lock(&aw_dev->dsp_lock); in aw_dev_check_sram()
961 aw_dev_dsp_read_16bit(aw_dev, AW88399_DSP_ROM_CHECK_ADDR, ®_val); in aw_dev_check_sram()
963 dev_err(aw_dev->dev, "check dsp rom failed, read[0x%x] != check[0x%x]", in aw_dev_check_sram()
969 aw_dev_dsp_write_16bit(aw_dev, AW88399_DSP_CFG_ADDR, AW88399_DSP_ODD_NUM_BIT_TEST); in aw_dev_check_sram()
970 aw_dev_dsp_read_16bit(aw_dev, AW88399_DSP_CFG_ADDR, ®_val); in aw_dev_check_sram()
972 dev_err(aw_dev->dev, "check dsp cfg failed, read[0x%x] != write[0x%x]", in aw_dev_check_sram()
976 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_check_sram()
980 mutex_unlock(&aw_dev->dsp_lock); in aw_dev_check_sram()
984 static void aw_dev_select_memclk(struct aw_device *aw_dev, unsigned char flag) in aw_dev_select_memclk() argument
990 ret = regmap_update_bits(aw_dev->regmap, AW88399_DBGCTRL_REG, in aw_dev_select_memclk()
994 dev_err(aw_dev->dev, "memclk select pll failed"); in aw_dev_select_memclk()
997 ret = regmap_update_bits(aw_dev->regmap, AW88399_DBGCTRL_REG, in aw_dev_select_memclk()
1001 dev_err(aw_dev->dev, "memclk select OSC failed"); in aw_dev_select_memclk()
1004 dev_err(aw_dev->dev, "unknown memclk config, flag=0x%x", flag); in aw_dev_select_memclk()
1009 static void aw_dev_get_cur_mode_st(struct aw_device *aw_dev) in aw_dev_get_cur_mode_st() argument
1011 struct aw_profctrl_desc *profctrl_desc = &aw_dev->profctrl_desc; in aw_dev_get_cur_mode_st()
1015 ret = regmap_read(aw_dev->regmap, AW88399_SYSCTRL_REG, ®_val); in aw_dev_get_cur_mode_st()
1017 dev_dbg(aw_dev->dev, "%s failed", __func__); in aw_dev_get_cur_mode_st()
1029 struct aw_device *aw_dev = aw88399->aw_pa; in aw_dev_update_reg_container() local
1030 struct aw_volume_desc *vol_desc = &aw_dev->volume_desc; in aw_dev_update_reg_container()
1040 dev_err(aw_dev->dev, "data len:%d unsupported", data_len); in aw_dev_update_reg_container()
1055 aw_dev->dsp_cfg = AW88399_DEV_DSP_BYPASS; in aw_dev_update_reg_container()
1057 aw_dev->dsp_cfg = AW88399_DEV_DSP_WORK; in aw_dev_update_reg_container()
1073 aw_dev->volume_desc.init_volume = read_vol; in aw_dev_update_reg_container()
1088 ret = regmap_write(aw_dev->regmap, reg_addr, reg_val); in aw_dev_update_reg_container()
1093 aw_dev_pwd(aw_dev, false); in aw_dev_update_reg_container()
1096 aw_dev_get_cur_mode_st(aw_dev); in aw_dev_update_reg_container()
1098 if (aw_dev->prof_cur != aw_dev->prof_index) in aw_dev_update_reg_container()
1101 aw_dev_set_volume(aw_dev, vol_desc->ctl_volume); in aw_dev_update_reg_container()
1123 static int aw88399_dev_get_prof_name(struct aw_device *aw_dev, int index, char **prof_name) in aw88399_dev_get_prof_name() argument
1125 struct aw_prof_info *prof_info = &aw_dev->prof_info; in aw88399_dev_get_prof_name()
1128 if ((index >= aw_dev->prof_info.count) || (index < 0)) { in aw88399_dev_get_prof_name()
1129 dev_err(aw_dev->dev, "index[%d] overflow count[%d]", in aw88399_dev_get_prof_name()
1130 index, aw_dev->prof_info.count); in aw88399_dev_get_prof_name()
1134 prof_desc = &aw_dev->prof_info.prof_desc[index]; in aw88399_dev_get_prof_name()
1141 static int aw88399_dev_get_prof_data(struct aw_device *aw_dev, int index, in aw88399_dev_get_prof_data() argument
1144 if ((index >= aw_dev->prof_info.count) || (index < 0)) { in aw88399_dev_get_prof_data()
1145 dev_err(aw_dev->dev, "%s: index[%d] overflow count[%d]\n", in aw88399_dev_get_prof_data()
1146 __func__, index, aw_dev->prof_info.count); in aw88399_dev_get_prof_data()
1150 *prof_desc = &aw_dev->prof_info.prof_desc[index]; in aw88399_dev_get_prof_data()
1157 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_fw_update() local
1163 if ((aw_dev->prof_cur == aw_dev->prof_index) && in aw88399_dev_fw_update()
1165 dev_dbg(aw_dev->dev, "scene no change, not update"); in aw88399_dev_fw_update()
1169 if (aw_dev->fw_status == AW88399_DEV_FW_FAILED) { in aw88399_dev_fw_update()
1170 dev_err(aw_dev->dev, "fw status[%d] error", aw_dev->fw_status); in aw88399_dev_fw_update()
1174 ret = aw88399_dev_get_prof_name(aw_dev, aw_dev->prof_index, &prof_name); in aw88399_dev_fw_update()
1178 dev_dbg(aw_dev->dev, "start update %s", prof_name); in aw88399_dev_fw_update()
1180 ret = aw88399_dev_get_prof_data(aw_dev, aw_dev->prof_index, &prof_index_desc); in aw88399_dev_fw_update()
1189 dev_err(aw_dev->dev, "update reg failed"); in aw88399_dev_fw_update()
1193 aw88399_dev_mute(aw_dev, true); in aw88399_dev_fw_update()
1195 if (aw_dev->dsp_cfg == AW88399_DEV_DSP_WORK) in aw88399_dev_fw_update()
1196 aw_dev_dsp_enable(aw_dev, false); in aw88399_dev_fw_update()
1198 aw_dev_select_memclk(aw_dev, AW88399_DEV_MEMCLK_OSC); in aw88399_dev_fw_update()
1200 ret = aw_dev_check_sram(aw_dev); in aw88399_dev_fw_update()
1202 dev_err(aw_dev->dev, "check sram failed"); in aw88399_dev_fw_update()
1207 dev_dbg(aw_dev->dev, "fw_ver: [%x]", prof_index_desc->fw_ver); in aw88399_dev_fw_update()
1208 ret = aw_dev_dsp_update_fw(aw_dev, sec_desc[AW88395_DATA_TYPE_DSP_FW].data, in aw88399_dev_fw_update()
1211 dev_err(aw_dev->dev, "update dsp fw failed"); in aw88399_dev_fw_update()
1217 ret = aw_dev_dsp_update_cfg(aw_dev, sec_desc[AW88395_DATA_TYPE_DSP_CFG].data, in aw88399_dev_fw_update()
1220 dev_err(aw_dev->dev, "update dsp cfg failed"); in aw88399_dev_fw_update()
1224 aw_dev_select_memclk(aw_dev, AW88399_DEV_MEMCLK_PLL); in aw88399_dev_fw_update()
1226 aw_dev->prof_cur = aw_dev->prof_index; in aw88399_dev_fw_update()
1231 aw_dev_select_memclk(aw_dev, AW88399_DEV_MEMCLK_PLL); in aw88399_dev_fw_update()
1289 static int aw_dev_check_sysint(struct aw_device *aw_dev) in aw_dev_check_sysint() argument
1293 aw_dev_get_int_status(aw_dev, ®_val); in aw_dev_check_sysint()
1295 dev_err(aw_dev->dev, "pa stop check fail:0x%04x", reg_val); in aw_dev_check_sysint()
1302 static int aw88399_stop(struct aw_device *aw_dev) in aw88399_stop() argument
1305 &aw_dev->prof_info.prof_desc[aw_dev->prof_cur].sec_desc[AW88395_DATA_TYPE_DSP_CFG]; in aw88399_stop()
1307 &aw_dev->prof_info.prof_desc[aw_dev->prof_cur].sec_desc[AW88395_DATA_TYPE_DSP_FW]; in aw88399_stop()
1310 if (aw_dev->status == AW88399_DEV_PW_OFF) { in aw88399_stop()
1311 dev_dbg(aw_dev->dev, "already power off"); in aw88399_stop()
1315 aw_dev->status = AW88399_DEV_PW_OFF; in aw88399_stop()
1317 aw88399_dev_mute(aw_dev, true); in aw88399_stop()
1320 aw_dev_i2s_tx_enable(aw_dev, false); in aw88399_stop()
1323 int_st = aw_dev_check_sysint(aw_dev); in aw88399_stop()
1325 aw_dev_dsp_enable(aw_dev, false); in aw88399_stop()
1327 aw_dev_amppd(aw_dev, true); in aw88399_stop()
1330 aw_dev_select_memclk(aw_dev, AW88399_DEV_MEMCLK_OSC); in aw88399_stop()
1331 aw_dev_dsp_update_fw(aw_dev, dsp_fw->data, dsp_fw->len); in aw88399_stop()
1332 aw_dev_dsp_update_cfg(aw_dev, dsp_cfg->data, dsp_cfg->len); in aw88399_stop()
1333 aw_dev_select_memclk(aw_dev, AW88399_DEV_MEMCLK_PLL); in aw88399_stop()
1336 aw_dev_pwd(aw_dev, true); in aw88399_stop()
1367 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_get_fade_in_time() local
1369 ucontrol->value.integer.value[0] = aw_dev->fade_in_time; in aw88399_get_fade_in_time()
1381 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_set_fade_in_time() local
1389 if (time != aw_dev->fade_in_time) { in aw88399_set_fade_in_time()
1390 aw_dev->fade_in_time = time; in aw88399_set_fade_in_time()
1402 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_get_fade_out_time() local
1404 ucontrol->value.integer.value[0] = aw_dev->fade_out_time; in aw88399_get_fade_out_time()
1416 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_set_fade_out_time() local
1423 if (time != aw_dev->fade_out_time) { in aw88399_set_fade_out_time()
1424 aw_dev->fade_out_time = time; in aw88399_set_fade_out_time()
1431 static int aw88399_dev_set_profile_index(struct aw_device *aw_dev, int index) in aw88399_dev_set_profile_index() argument
1434 if ((index >= aw_dev->prof_info.count) || (index < 0)) in aw88399_dev_set_profile_index()
1437 if (aw_dev->prof_index == index) in aw88399_dev_set_profile_index()
1440 aw_dev->prof_index = index; in aw88399_dev_set_profile_index()
1441 dev_dbg(aw_dev->dev, "set prof[%s]", in aw88399_dev_set_profile_index()
1442 aw_dev->prof_info.prof_name_list[aw_dev->prof_info.prof_desc[index].id]); in aw88399_dev_set_profile_index()
1593 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_re_get() local
1595 ucontrol->value.integer.value[0] = aw_dev->cali_desc.cali_re; in aw88399_re_get()
1607 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_re_set() local
1614 if (aw_dev->cali_desc.cali_re != value) { in aw88399_re_set()
1615 aw_dev->cali_desc.cali_re = value; in aw88399_re_set()
1624 struct aw_device *aw_dev = aw88399->aw_pa; in aw88399_dev_init() local
1627 ret = aw88395_dev_cfg_load(aw_dev, aw_cfg); in aw88399_dev_init()
1629 dev_err(aw_dev->dev, "aw_dev acf parse failed"); in aw88399_dev_init()
1632 aw_dev->fade_in_time = AW88399_1000_US / 10; in aw88399_dev_init()
1633 aw_dev->fade_out_time = AW88399_1000_US >> 1; in aw88399_dev_init()
1634 aw_dev->prof_cur = aw_dev->prof_info.prof_desc[0].id; in aw88399_dev_init()
1635 aw_dev->prof_index = aw_dev->prof_info.prof_desc[0].id; in aw88399_dev_init()
1639 dev_err(aw_dev->dev, "fw update failed ret = %d\n", ret); in aw88399_dev_init()
1643 aw88399_dev_mute(aw_dev, true); in aw88399_dev_init()
1646 aw_dev_i2s_tx_enable(aw_dev, false); in aw88399_dev_init()
1650 aw_dev_amppd(aw_dev, true); in aw88399_dev_init()
1653 aw_dev_dsp_enable(aw_dev, false); in aw88399_dev_init()
1655 aw_dev_pwd(aw_dev, true); in aw88399_dev_init()
1801 static void aw88399_parse_channel_dt(struct aw_device *aw_dev) in aw88399_parse_channel_dt() argument
1803 struct device_node *np = aw_dev->dev->of_node; in aw88399_parse_channel_dt()
1807 aw_dev->channel = channel_value; in aw88399_parse_channel_dt()
1812 struct aw_device *aw_dev; in aw88399_init() local
1827 aw_dev = devm_kzalloc(&i2c->dev, sizeof(*aw_dev), GFP_KERNEL); in aw88399_init()
1828 if (!aw_dev) in aw88399_init()
1830 aw88399->aw_pa = aw_dev; in aw88399_init()
1832 aw_dev->i2c = i2c; in aw88399_init()
1833 aw_dev->dev = &i2c->dev; in aw88399_init()
1834 aw_dev->regmap = regmap; in aw88399_init()
1835 mutex_init(&aw_dev->dsp_lock); in aw88399_init()
1837 aw_dev->chip_id = chip_id; in aw88399_init()
1838 aw_dev->acf = NULL; in aw88399_init()
1839 aw_dev->prof_info.prof_desc = NULL; in aw88399_init()
1840 aw_dev->prof_info.count = 0; in aw88399_init()
1841 aw_dev->prof_info.prof_type = AW88395_DEV_NONE_TYPE_ID; in aw88399_init()
1842 aw_dev->channel = AW88399_DEV_DEFAULT_CH; in aw88399_init()
1843 aw_dev->fw_status = AW88399_DEV_FW_FAILED; in aw88399_init()
1845 aw_dev->fade_step = AW88399_VOLUME_STEP_DB; in aw88399_init()
1846 aw_dev->volume_desc.ctl_volume = AW88399_VOL_DEFAULT_VALUE; in aw88399_init()
1848 aw88399_parse_channel_dt(aw_dev); in aw88399_init()