Lines Matching +full:e +full:- +full:book

1 // SPDX-License-Identifier: GPL-2.0
3 // tas2781-lib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers
7 // Author: Shenghao Ding <shenghao-ding@ti.com>
48 unsigned short chn, int book) in tasdevice_change_chn_book() argument
50 struct i2c_client *client = (struct i2c_client *)tas_priv->client; in tasdevice_change_chn_book()
53 if (chn < tas_priv->ndev) { in tasdevice_change_chn_book()
54 struct tasdevice *tasdev = &tas_priv->tasdevice[chn]; in tasdevice_change_chn_book()
55 struct regmap *map = tas_priv->regmap; in tasdevice_change_chn_book()
57 if (client->addr != tasdev->dev_addr) { in tasdevice_change_chn_book()
58 client->addr = tasdev->dev_addr; in tasdevice_change_chn_book()
62 * is the same one for page-switching. in tasdevice_change_chn_book()
66 dev_err(tas_priv->dev, "%s, E=%d\n", in tasdevice_change_chn_book()
72 if (tasdev->cur_book != book) { in tasdevice_change_chn_book()
73 ret = regmap_write(map, TASDEVICE_BOOKCTL_REG, book); in tasdevice_change_chn_book()
75 dev_err(tas_priv->dev, "%s, E=%d\n", in tasdevice_change_chn_book()
79 tasdev->cur_book = book; in tasdevice_change_chn_book()
82 ret = -EINVAL; in tasdevice_change_chn_book()
83 dev_err(tas_priv->dev, "%s, no such channel(%d)\n", __func__, in tasdevice_change_chn_book()
96 if (chn < tas_priv->ndev) { in tasdevice_dev_read()
97 struct regmap *map = tas_priv->regmap; in tasdevice_dev_read()
106 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_dev_read()
108 ret = -EINVAL; in tasdevice_dev_read()
109 dev_err(tas_priv->dev, "%s, no such channel(%d)\n", __func__, in tasdevice_dev_read()
123 if (chn < tas_priv->ndev) { in tasdevice_dev_write()
124 struct regmap *map = tas_priv->regmap; in tasdevice_dev_write()
134 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_dev_write()
136 ret = -EINVAL; in tasdevice_dev_write()
137 dev_err(tas_priv->dev, "%s, no such channel(%d)\n", __func__, in tasdevice_dev_write()
153 if (chn < tas_priv->ndev) { in tasdevice_dev_bulk_write()
154 struct regmap *map = tas_priv->regmap; in tasdevice_dev_bulk_write()
164 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_dev_bulk_write()
166 ret = -EINVAL; in tasdevice_dev_bulk_write()
167 dev_err(tas_priv->dev, "%s, no such channel(%d)\n", __func__, in tasdevice_dev_bulk_write()
182 if (chn < tas_priv->ndev) { in tasdevice_dev_bulk_read()
183 struct regmap *map = tas_priv->regmap; in tasdevice_dev_bulk_read()
192 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_dev_bulk_read()
194 dev_err(tas_priv->dev, "%s, no such channel(%d)\n", __func__, in tasdevice_dev_bulk_read()
208 if (chn < tas_priv->ndev) { in tasdevice_dev_update_bits()
209 struct regmap *map = tas_priv->regmap; in tasdevice_dev_update_bits()
219 dev_err(tas_priv->dev, "%s, E=%d\n", __func__, ret); in tasdevice_dev_update_bits()
221 dev_err(tas_priv->dev, "%s, no such channel(%d)\n", __func__, in tasdevice_dev_update_bits()
223 ret = -EINVAL; in tasdevice_dev_update_bits()
235 tas_priv = devm_kzalloc(&i2c->dev, sizeof(*tas_priv), GFP_KERNEL); in tasdevice_kzalloc()
238 tas_priv->dev = &i2c->dev; in tasdevice_kzalloc()
239 tas_priv->client = (void *)i2c; in tasdevice_kzalloc()
249 if (tas_dev->reset) { in tas2781_reset()
250 gpiod_set_value_cansleep(tas_dev->reset, 0); in tas2781_reset()
252 gpiod_set_value_cansleep(tas_dev->reset, 1); in tas2781_reset()
254 for (i = 0; i < tas_dev->ndev; i++) { in tas2781_reset()
259 dev_err(tas_dev->dev, in tas2781_reset()
277 mutex_lock(&tas_priv->codec_lock); in tascodec_init()
279 scnprintf(tas_priv->rca_binaryname, 64, "%sRCA%d.bin", in tascodec_init()
280 tas_priv->dev_name, tas_priv->ndev); in tascodec_init()
281 crc8_populate_msb(tas_priv->crc8_lkp_tbl, TASDEVICE_CRC8_POLYNOMIAL); in tascodec_init()
282 tas_priv->codec = codec; in tascodec_init()
284 tas_priv->rca_binaryname, tas_priv->dev, GFP_KERNEL, tas_priv, in tascodec_init()
287 dev_err(tas_priv->dev, "request_firmware_nowait err:0x%08x\n", in tascodec_init()
291 mutex_unlock(&tas_priv->codec_lock); in tascodec_init()
301 tas_priv->regmap = devm_regmap_init_i2c(tas_priv->client, in tasdevice_init()
303 if (IS_ERR(tas_priv->regmap)) { in tasdevice_init()
304 ret = PTR_ERR(tas_priv->regmap); in tasdevice_init()
305 dev_err(tas_priv->dev, "Failed to allocate register map: %d\n", in tasdevice_init()
310 tas_priv->cur_prog = -1; in tasdevice_init()
311 tas_priv->cur_conf = -1; in tasdevice_init()
313 for (i = 0; i < tas_priv->ndev; i++) { in tasdevice_init()
314 tas_priv->tasdevice[i].cur_book = -1; in tasdevice_init()
315 tas_priv->tasdevice[i].cur_prog = -1; in tasdevice_init()
316 tas_priv->tasdevice[i].cur_conf = -1; in tasdevice_init()
319 mutex_init(&tas_priv->codec_lock); in tasdevice_init()
335 tas_dt = &(prog->dev_data); in tasdev_dsp_prog_blk_remove()
337 if (!tas_dt->dev_blks) in tasdev_dsp_prog_blk_remove()
340 for (i = 0; i < tas_dt->nr_blk; i++) { in tasdev_dsp_prog_blk_remove()
341 blk = &(tas_dt->dev_blks[i]); in tasdev_dsp_prog_blk_remove()
342 kfree(blk->data); in tasdev_dsp_prog_blk_remove()
344 kfree(tas_dt->dev_blks); in tasdev_dsp_prog_blk_remove()
364 tas_dt = &(cfg->dev_data); in tasdev_dsp_cfg_blk_remove()
366 if (!tas_dt->dev_blks) in tasdev_dsp_cfg_blk_remove()
369 for (i = 0; i < tas_dt->nr_blk; i++) { in tasdev_dsp_cfg_blk_remove()
370 blk = &(tas_dt->dev_blks[i]); in tasdev_dsp_cfg_blk_remove()
371 kfree(blk->data); in tasdev_dsp_cfg_blk_remove()
373 kfree(tas_dt->dev_blks); in tasdev_dsp_cfg_blk_remove()
390 struct tasdevice_fw *tas_fmw = tas_dev->fmw; in tasdevice_dsp_remove()
392 if (!tas_dev->fmw) in tasdevice_dsp_remove()
395 if (tas_fmw->programs) in tasdevice_dsp_remove()
396 tasdev_dsp_prog_remove(tas_fmw->programs, in tasdevice_dsp_remove()
397 tas_fmw->nr_programs); in tasdevice_dsp_remove()
398 if (tas_fmw->configs) in tasdevice_dsp_remove()
399 tasdev_dsp_cfg_remove(tas_fmw->configs, in tasdevice_dsp_remove()
400 tas_fmw->nr_configurations); in tasdevice_dsp_remove()
402 tas_dev->fmw = NULL; in tasdevice_dsp_remove()
408 mutex_destroy(&tas_priv->codec_lock); in tasdevice_remove()
414 if (tas_priv->save_calibration) in tasdevice_save_calibration()
415 return tas_priv->save_calibration(tas_priv); in tasdevice_save_calibration()
416 return -EINVAL; in tasdevice_save_calibration()
422 if (tas_priv->apply_calibration && tas_priv->cali_data.total_sz) in tasdevice_apply_calibration()
423 tas_priv->apply_calibration(tas_priv); in tasdevice_apply_calibration()
432 val = max - val; in tasdevice_clamp()
441 unsigned int invert = mc->invert; in tasdevice_amp_putvol()
443 int max = mc->max; in tasdevice_amp_putvol()
447 mask = (1 << fls(max)) - 1; in tasdevice_amp_putvol()
448 mask <<= mc->shift; in tasdevice_amp_putvol()
449 val = tasdevice_clamp(ucontrol->value.integer.value[0], max, invert); in tasdevice_amp_putvol()
450 for (i = 0; i < tas_priv->ndev; i++) { in tasdevice_amp_putvol()
452 mc->reg, mask, (unsigned int)(val << mc->shift)); in tasdevice_amp_putvol()
456 dev_err(tas_priv->dev, "set AMP vol error in dev %d\n", i); in tasdevice_amp_putvol()
460 return (err_cnt == tas_priv->ndev) ? 0 : 1; in tasdevice_amp_putvol()
467 unsigned int invert = mc->invert; in tasdevice_amp_getvol()
469 int max = mc->max; in tasdevice_amp_getvol()
474 ret = tasdevice_dev_read(tas_priv, 0, mc->reg, &val); in tasdevice_amp_getvol()
476 dev_err(tas_priv->dev, "%s, get AMP vol error\n", __func__); in tasdevice_amp_getvol()
480 mask = (1 << fls(max)) - 1; in tasdevice_amp_getvol()
481 mask <<= mc->shift; in tasdevice_amp_getvol()
482 val = (val & mask) >> mc->shift; in tasdevice_amp_getvol()
484 ucontrol->value.integer.value[0] = val; in tasdevice_amp_getvol()
495 unsigned int invert = mc->invert; in tasdevice_digital_putvol()
496 int max = mc->max; in tasdevice_digital_putvol()
501 val = tasdevice_clamp(ucontrol->value.integer.value[0], max, invert); in tasdevice_digital_putvol()
503 for (i = 0; i < tas_priv->ndev; i++) { in tasdevice_digital_putvol()
504 ret = tasdevice_dev_write(tas_priv, i, mc->reg, in tasdevice_digital_putvol()
509 dev_err(tas_priv->dev, in tasdevice_digital_putvol()
514 return (err_cnt == tas_priv->ndev) ? 0 : 1; in tasdevice_digital_putvol()
522 unsigned int invert = mc->invert; in tasdevice_digital_getvol()
523 int max = mc->max; in tasdevice_digital_getvol()
527 ret = tasdevice_dev_read(tas_priv, 0, mc->reg, &val); in tasdevice_digital_getvol()
529 dev_err(tas_priv->dev, "%s, get digital vol error\n", in tasdevice_digital_getvol()
535 ucontrol->value.integer.value[0] = val; in tasdevice_digital_getvol()
544 MODULE_AUTHOR("Shenghao Ding, TI, <shenghao-ding@ti.com>");