Lines Matching +full:i2c +full:- +full:retry +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0-only
3 // aw88395.c -- ALSA SoC AW88395 codec support
5 // Copyright (c) 2022-2023 AWINIC Technology CO., LTD
12 #include <linux/i2c.h>
24 .max_register = AW88395_REG_MAX - 1,
34 ret = aw88395_dev_start(aw88395->aw_pa); in aw88395_start_pa()
36 dev_err(aw88395->aw_pa->dev, "aw88395 device start failed. retry = %d", i); in aw88395_start_pa()
37 ret = aw88395_dev_fw_update(aw88395->aw_pa, AW88395_DSP_FW_UPDATE_ON, true); in aw88395_start_pa()
39 dev_err(aw88395->aw_pa->dev, "fw update failed"); in aw88395_start_pa()
43 dev_info(aw88395->aw_pa->dev, "start success\n"); in aw88395_start_pa()
54 mutex_lock(&aw88395->lock); in aw88395_startup_work()
56 mutex_unlock(&aw88395->lock); in aw88395_startup_work()
63 if (aw88395->aw_pa->fw_status != AW88395_DEV_FW_OK) in aw88395_start()
66 if (aw88395->aw_pa->status == AW88395_DEV_PW_ON) in aw88395_start()
69 ret = aw88395_dev_fw_update(aw88395->aw_pa, AW88395_DSP_FW_UPDATE_OFF, true); in aw88395_start()
71 dev_err(aw88395->aw_pa->dev, "fw update failed."); in aw88395_start()
79 &aw88395->start_work, in aw88395_start()
85 .name = "aw88395-aif",
109 struct aw_device *aw_dev = aw88395->aw_pa; in aw88395_get_fade_in_time()
111 ucontrol->value.integer.value[0] = aw_dev->fade_in_time; in aw88395_get_fade_in_time()
122 (struct soc_mixer_control *)kcontrol->private_value; in aw88395_set_fade_in_time()
123 struct aw_device *aw_dev = aw88395->aw_pa; in aw88395_set_fade_in_time()
126 time = ucontrol->value.integer.value[0]; in aw88395_set_fade_in_time()
128 if (time < mc->min || time > mc->max) in aw88395_set_fade_in_time()
129 return -EINVAL; in aw88395_set_fade_in_time()
131 if (time != aw_dev->fade_in_time) { in aw88395_set_fade_in_time()
132 aw_dev->fade_in_time = time; in aw88395_set_fade_in_time()
144 struct aw_device *aw_dev = aw88395->aw_pa; in aw88395_get_fade_out_time()
146 ucontrol->value.integer.value[0] = aw_dev->fade_out_time; in aw88395_get_fade_out_time()
157 (struct soc_mixer_control *)kcontrol->private_value; in aw88395_set_fade_out_time()
158 struct aw_device *aw_dev = aw88395->aw_pa; in aw88395_set_fade_out_time()
161 time = ucontrol->value.integer.value[0]; in aw88395_set_fade_out_time()
162 if (time < mc->min || time > mc->max) in aw88395_set_fade_out_time()
163 return -EINVAL; in aw88395_set_fade_out_time()
165 if (time != aw_dev->fade_out_time) { in aw88395_set_fade_out_time()
166 aw_dev->fade_out_time = time; in aw88395_set_fade_out_time()
179 int count, ret; in aw88395_profile_info() local
181 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; in aw88395_profile_info()
182 uinfo->count = 1; in aw88395_profile_info()
184 count = aw88395_dev_get_profile_count(aw88395->aw_pa); in aw88395_profile_info()
185 if (count <= 0) { in aw88395_profile_info()
186 uinfo->value.enumerated.items = 0; in aw88395_profile_info()
190 uinfo->value.enumerated.items = count; in aw88395_profile_info()
192 if (uinfo->value.enumerated.item >= count) in aw88395_profile_info()
193 uinfo->value.enumerated.item = count - 1; in aw88395_profile_info()
195 name = uinfo->value.enumerated.name; in aw88395_profile_info()
196 count = uinfo->value.enumerated.item; in aw88395_profile_info()
198 ret = aw88395_dev_get_prof_name(aw88395->aw_pa, count, &prof_name); in aw88395_profile_info()
200 strscpy(uinfo->value.enumerated.name, "null", in aw88395_profile_info()
205 strscpy(name, prof_name, sizeof(uinfo->value.enumerated.name)); in aw88395_profile_info()
216 ucontrol->value.integer.value[0] = aw88395_dev_get_profile_index(aw88395->aw_pa); in aw88395_profile_get()
229 mutex_lock(&aw88395->lock); in aw88395_profile_set()
230 ret = aw88395_dev_set_profile_index(aw88395->aw_pa, ucontrol->value.integer.value[0]); in aw88395_profile_set()
232 dev_dbg(codec->dev, "profile index does not change"); in aw88395_profile_set()
233 mutex_unlock(&aw88395->lock); in aw88395_profile_set()
237 if (aw88395->aw_pa->status) { in aw88395_profile_set()
238 aw88395_dev_stop(aw88395->aw_pa); in aw88395_profile_set()
242 mutex_unlock(&aw88395->lock); in aw88395_profile_set()
252 struct aw_volume_desc *vol_desc = &aw88395->aw_pa->volume_desc; in aw88395_volume_get()
254 ucontrol->value.integer.value[0] = vol_desc->ctl_volume; in aw88395_volume_get()
264 struct aw_volume_desc *vol_desc = &aw88395->aw_pa->volume_desc; in aw88395_volume_set()
266 (struct soc_mixer_control *)kcontrol->private_value; in aw88395_volume_set()
269 value = ucontrol->value.integer.value[0]; in aw88395_volume_set()
270 if (value < mc->min || value > mc->max) in aw88395_volume_set()
271 return -EINVAL; in aw88395_volume_set()
273 if (vol_desc->ctl_volume != value) { in aw88395_volume_set()
274 vol_desc->ctl_volume = value; in aw88395_volume_set()
275 aw88395_dev_set_volume(aw88395->aw_pa, vol_desc->ctl_volume); in aw88395_volume_set()
289 ucontrol->value.integer.value[0] = aw88395->aw_pa->fade_step; in aw88395_get_fade_step()
300 (struct soc_mixer_control *)kcontrol->private_value; in aw88395_set_fade_step()
303 value = ucontrol->value.integer.value[0]; in aw88395_set_fade_step()
304 if (value < mc->min || value > mc->max) in aw88395_set_fade_step()
305 return -EINVAL; in aw88395_set_fade_step()
307 if (aw88395->aw_pa->fade_step != value) { in aw88395_set_fade_step()
308 aw88395->aw_pa->fade_step = value; in aw88395_set_fade_step()
320 struct aw_device *aw_dev = aw88395->aw_pa; in aw88395_re_get()
322 ucontrol->value.integer.value[0] = aw_dev->cali_desc.cali_re; in aw88395_re_get()
333 (struct soc_mixer_control *)kcontrol->private_value; in aw88395_re_set()
334 struct aw_device *aw_dev = aw88395->aw_pa; in aw88395_re_set()
337 value = ucontrol->value.integer.value[0]; in aw88395_re_set()
338 if (value < mc->min || value > mc->max) in aw88395_re_set()
339 return -EINVAL; in aw88395_re_set()
341 if (aw_dev->cali_desc.cali_re != value) { in aw88395_re_set()
342 aw_dev->cali_desc.cali_re = value; in aw88395_re_set()
368 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in aw88395_playback_event()
371 mutex_lock(&aw88395->lock); in aw88395_playback_event()
377 aw88395_dev_stop(aw88395->aw_pa); in aw88395_playback_event()
382 mutex_unlock(&aw88395->lock); in aw88395_playback_event()
410 INIT_DELAYED_WORK(&aw88395->start_work, aw88395_startup_work); in aw88395_codec_probe()
434 cancel_delayed_work_sync(&aw88395->start_work); in aw88395_codec_remove()
442 static struct aw88395 *aw88395_malloc_init(struct i2c_client *i2c) in aw88395_malloc_init() argument
444 struct aw88395 *aw88395 = devm_kzalloc(&i2c->dev, in aw88395_malloc_init()
449 mutex_init(&aw88395->lock); in aw88395_malloc_init()
456 if (aw88395->reset_gpio) { in aw88395_hw_reset()
457 gpiod_set_value_cansleep(aw88395->reset_gpio, 0); in aw88395_hw_reset()
459 gpiod_set_value_cansleep(aw88395->reset_gpio, 1); in aw88395_hw_reset()
462 dev_err(aw88395->aw_pa->dev, "%s failed", __func__); in aw88395_hw_reset()
471 aw88395->aw_pa->fw_status = AW88395_DEV_FW_FAILED; in aw88395_request_firmware_file()
473 ret = request_firmware(&cont, AW88395_ACF_FILE, aw88395->aw_pa->dev); in aw88395_request_firmware_file()
475 dev_err(aw88395->aw_pa->dev, "load [%s] failed!", AW88395_ACF_FILE); in aw88395_request_firmware_file()
479 dev_info(aw88395->aw_pa->dev, "loaded %s - size: %zu\n", in aw88395_request_firmware_file()
480 AW88395_ACF_FILE, cont ? cont->size : 0); in aw88395_request_firmware_file()
482 aw88395->aw_cfg = devm_kzalloc(aw88395->aw_pa->dev, cont->size + sizeof(int), GFP_KERNEL); in aw88395_request_firmware_file()
483 if (!aw88395->aw_cfg) { in aw88395_request_firmware_file()
485 return -ENOMEM; in aw88395_request_firmware_file()
487 aw88395->aw_cfg->len = (int)cont->size; in aw88395_request_firmware_file()
488 memcpy(aw88395->aw_cfg->data, cont->data, cont->size); in aw88395_request_firmware_file()
491 ret = aw88395_dev_load_acf_check(aw88395->aw_pa, aw88395->aw_cfg); in aw88395_request_firmware_file()
493 dev_err(aw88395->aw_pa->dev, "Load [%s] failed ....!", AW88395_ACF_FILE); in aw88395_request_firmware_file()
497 dev_dbg(aw88395->aw_pa->dev, "%s : bin load success\n", __func__); in aw88395_request_firmware_file()
499 mutex_lock(&aw88395->lock); in aw88395_request_firmware_file()
501 ret = aw88395_dev_init(aw88395->aw_pa, aw88395->aw_cfg); in aw88395_request_firmware_file()
503 dev_err(aw88395->aw_pa->dev, "dev init failed"); in aw88395_request_firmware_file()
504 mutex_unlock(&aw88395->lock); in aw88395_request_firmware_file()
509 static int aw88395_i2c_probe(struct i2c_client *i2c) in aw88395_i2c_probe() argument
514 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) { in aw88395_i2c_probe()
515 dev_err(&i2c->dev, "check_functionality failed"); in aw88395_i2c_probe()
516 return -EIO; in aw88395_i2c_probe()
519 aw88395 = aw88395_malloc_init(i2c); in aw88395_i2c_probe()
521 dev_err(&i2c->dev, "malloc aw88395 failed"); in aw88395_i2c_probe()
522 return -ENOMEM; in aw88395_i2c_probe()
524 i2c_set_clientdata(i2c, aw88395); in aw88395_i2c_probe()
526 aw88395->reset_gpio = devm_gpiod_get_optional(&i2c->dev, "reset", GPIOD_OUT_LOW); in aw88395_i2c_probe()
527 if (IS_ERR(aw88395->reset_gpio)) in aw88395_i2c_probe()
528 dev_info(&i2c->dev, "reset gpio not defined\n"); in aw88395_i2c_probe()
533 aw88395->regmap = devm_regmap_init_i2c(i2c, &aw88395_remap_config); in aw88395_i2c_probe()
534 if (IS_ERR(aw88395->regmap)) { in aw88395_i2c_probe()
535 ret = PTR_ERR(aw88395->regmap); in aw88395_i2c_probe()
536 dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); in aw88395_i2c_probe()
541 ret = aw88395_init(&aw88395->aw_pa, i2c, aw88395->regmap); in aw88395_i2c_probe()
547 dev_err(&i2c->dev, "%s failed\n", __func__); in aw88395_i2c_probe()
551 ret = devm_snd_soc_register_component(&i2c->dev, in aw88395_i2c_probe()
555 dev_err(&i2c->dev, "failed to register aw88395: %d", ret); in aw88395_i2c_probe()
566 MODULE_DEVICE_TABLE(i2c, aw88395_i2c_id);