Lines Matching +full:data +full:- +full:shift

1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (C) 2022 - 2024 Texas Instruments Incorporated
12 // Author: Shenghao Ding <shenghao-ding@ti.com>
63 .shift = 1,
69 .shift = 1,
78 .shift = 0,
84 .shift = 0,
93 .shift = 0,
99 .shift = 0,
105 .shift = 0,
111 .shift = 0,
117 .shift = 0,
123 .shift = 0,
129 .shift = 0,
135 .shift = 0,
144 .shift = 2,
150 .shift = 2,
156 .shift = 2,
162 .shift = 2,
171 .shift = 0,
177 .shift = 0,
183 .shift = 0,
189 .shift = 0,
198 .shift = 2,
204 .shift = 2,
210 .shift = 2,
216 .shift = 2,
222 .shift = 2,
228 .shift = 2,
237 .shift = 0,
243 .shift = 0,
249 .shift = 0,
255 .shift = 0,
261 .shift = 0,
267 .shift = 0,
276 .shift = 0,
282 .shift = 0,
291 .shift = 0,
297 .shift = 0,
303 .shift = 0,
309 .shift = 0,
318 .shift = 4,
324 .shift = 4,
330 .shift = 4,
336 .shift = 4,
345 .shift = 0,
351 .shift = 0,
357 .shift = 0,
363 .shift = 0,
369 .shift = 0,
375 .shift = 0,
381 .shift = 0,
387 .shift = 0,
396 .shift = 4,
402 .shift = 4,
408 .shift = 4,
414 .shift = 4,
420 .shift = 4,
426 .shift = 4,
432 .shift = 4,
438 .shift = 4,
447 .shift = 0,
453 .shift = 0,
459 .shift = 0,
465 .shift = 0,
474 .shift = 4,
480 .shift = 4,
486 .shift = 4,
492 .shift = 0,
500 -10000, 2700);
502 -12750, 0);
504 -25500, 0);
506 -11450, 2000);
508 -10050, 2700);
511 -10000, 2700);
514 -8050, 4700);
516 -80, 70);
521 struct i2c_client *client = (struct i2c_client *)pcm_priv->client; in pcmdev_change_dev()
522 struct regmap *map = pcm_priv->regmap; in pcmdev_change_dev()
525 if (client->addr == pcm_priv->addr[dev_no]) in pcmdev_change_dev()
528 client->addr = pcm_priv->addr[dev_no]; in pcmdev_change_dev()
532 * one for page-switching. in pcmdev_change_dev()
536 dev_err(pcm_priv->dev, "%s: err = %d\n", __func__, ret); in pcmdev_change_dev()
544 struct regmap *map = pcm_dev->regmap; in pcmdev_dev_read()
547 if (dev_no >= pcm_dev->ndev) { in pcmdev_dev_read()
548 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__, in pcmdev_dev_read()
550 return -EINVAL; in pcmdev_dev_read()
555 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret); in pcmdev_dev_read()
561 dev_err(pcm_dev->dev, "%s: err = %d\n", __func__, ret); in pcmdev_dev_read()
570 struct regmap *map = pcm_dev->regmap; in pcmdev_dev_update_bits()
573 if (dev_no >= pcm_dev->ndev) { in pcmdev_dev_update_bits()
574 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__, in pcmdev_dev_update_bits()
576 return -EINVAL; in pcmdev_dev_update_bits()
581 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret); in pcmdev_dev_update_bits()
587 dev_err(pcm_dev->dev, "%s: update_bits err=%d\n", in pcmdev_dev_update_bits()
600 (struct pcmdevice_mixer_control *)kcontrol->private_value; in pcmdev_get_volsw()
601 int max = mc->max, ret; in pcmdev_get_volsw()
602 unsigned int mask = BIT(fls(max)) - 1; in pcmdev_get_volsw()
603 unsigned int dev_no = mc->dev_no; in pcmdev_get_volsw()
604 unsigned int shift = mc->shift; in pcmdev_get_volsw() local
605 unsigned int reg = mc->reg; in pcmdev_get_volsw()
608 mutex_lock(&pcm_dev->codec_lock); in pcmdev_get_volsw()
610 if (pcm_dev->chip_id == PCM1690) { in pcmdev_get_volsw()
614 dev_err(pcm_dev->dev, "%s: read mode err=%d\n", in pcmdev_get_volsw()
619 /* Set to wide-range mode, before using vol ctrl. */ in pcmdev_get_volsw()
621 ucontrol->value.integer.value[0] = -25500; in pcmdev_get_volsw()
626 ucontrol->value.integer.value[0] = -12750; in pcmdev_get_volsw()
633 dev_err(pcm_dev->dev, "%s: read err=%d\n", in pcmdev_get_volsw()
638 val = (val >> shift) & mask; in pcmdev_get_volsw()
640 val = mc->invert ? max - val : val; in pcmdev_get_volsw()
641 ucontrol->value.integer.value[0] = val; in pcmdev_get_volsw()
643 mutex_unlock(&pcm_dev->codec_lock); in pcmdev_get_volsw()
673 (struct pcmdevice_mixer_control *)kcontrol->private_value; in pcmdev_put_volsw()
674 int max = mc->max, rc; in pcmdev_put_volsw()
675 unsigned int mask = BIT(fls(max)) - 1; in pcmdev_put_volsw()
676 unsigned int dev_no = mc->dev_no; in pcmdev_put_volsw()
677 unsigned int shift = mc->shift; in pcmdev_put_volsw() local
679 unsigned int reg = mc->reg; in pcmdev_put_volsw()
681 mutex_lock(&pcm_dev->codec_lock); in pcmdev_put_volsw()
682 val = ucontrol->value.integer.value[0] & mask; in pcmdev_put_volsw()
684 val = mc->invert ? max - val : val; in pcmdev_put_volsw()
685 val_mask = mask << shift; in pcmdev_put_volsw()
686 val = val << shift; in pcmdev_put_volsw()
701 dev_err(pcm_dev->dev, "%s: update_bits err = %d\n", in pcmdev_put_volsw()
705 mutex_unlock(&pcm_dev->codec_lock); in pcmdev_put_volsw()
1087 unsigned int dev_no, unsigned int reg, unsigned char *data, in pcmdev_dev_bulk_write() argument
1090 struct regmap *map = pcm_dev->regmap; in pcmdev_dev_bulk_write()
1093 if (dev_no >= pcm_dev->ndev) { in pcmdev_dev_bulk_write()
1094 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__, in pcmdev_dev_bulk_write()
1096 return -EINVAL; in pcmdev_dev_bulk_write()
1101 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret); in pcmdev_dev_bulk_write()
1105 ret = regmap_bulk_write(map, reg, data, len); in pcmdev_dev_bulk_write()
1107 dev_err(pcm_dev->dev, "%s: bulk_write err = %d\n", __func__, in pcmdev_dev_bulk_write()
1116 struct regmap *map = pcm_dev->regmap; in pcmdev_dev_write()
1119 if (dev_no >= pcm_dev->ndev) { in pcmdev_dev_write()
1120 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__, in pcmdev_dev_write()
1122 return -EINVAL; in pcmdev_dev_write()
1127 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret); in pcmdev_dev_write()
1133 dev_err(pcm_dev->dev, "%s: err = %d\n", __func__, ret); in pcmdev_dev_write()
1147 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in pcmdevice_info_profile()
1148 uinfo->count = 1; in pcmdevice_info_profile()
1149 uinfo->value.integer.min = 0; in pcmdevice_info_profile()
1150 uinfo->value.integer.max = max(0, pcm_dev->regbin.ncfgs - 1); in pcmdevice_info_profile()
1164 ucontrol->value.integer.value[0] = pcm_dev->cur_conf; in pcmdevice_get_profile_id()
1177 int nr_profile = ucontrol->value.integer.value[0]; in pcmdevice_set_profile_id()
1178 int max = pcm_dev->regbin.ncfgs - 1; in pcmdevice_set_profile_id()
1183 if (pcm_dev->cur_conf != nr_profile) { in pcmdevice_set_profile_id()
1184 pcm_dev->cur_conf = nr_profile; in pcmdevice_set_profile_id()
1195 (struct pcmdevice_mixer_control *)kcontrol->private_value; in pcmdevice_info_volsw()
1197 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in pcmdevice_info_volsw()
1198 uinfo->count = 1; in pcmdevice_info_volsw()
1199 uinfo->value.integer.min = 0; in pcmdevice_info_volsw()
1200 uinfo->value.integer.max = mc->max; in pcmdevice_info_volsw()
1208 for (i = 0; i < pcm_dev->ndev; i++) { in pcm9211_sw_rst()
1213 dev_err(pcm_dev->dev, "%s: dev %d swreset fail %d\n", in pcm9211_sw_rst()
1222 for (i = 0; i < pcm_dev->ndev; i++) { in pcmdevice_sw_rst()
1226 dev_err(pcm_dev->dev, "%s: dev %d swreset fail %d\n", in pcmdevice_sw_rst()
1242 *status = -ENOMEM; in pcmdevice_add_config()
1246 if (pcm_dev->regbin.fw_hdr.binary_version_num >= 0x105) { in pcmdevice_add_config()
1248 *status = -EINVAL; in pcmdevice_add_config()
1249 dev_err(pcm_dev->dev, in pcmdevice_add_config()
1253 memcpy(cfg_info->cfg_name, &config_data[config_offset], 64); in pcmdevice_add_config()
1258 *status = -EINVAL; in pcmdevice_add_config()
1259 dev_err(pcm_dev->dev, "%s: nblocks out of boundary\n", in pcmdevice_add_config()
1263 cfg_info->nblocks = in pcmdevice_add_config()
1267 bk_da = cfg_info->blk_data = kcalloc(cfg_info->nblocks, in pcmdevice_add_config()
1270 *status = -ENOMEM; in pcmdevice_add_config()
1273 cfg_info->real_nblocks = 0; in pcmdevice_add_config()
1274 for (i = 0; i < cfg_info->nblocks; i++) { in pcmdevice_add_config()
1276 *status = -EINVAL; in pcmdevice_add_config()
1277 dev_err(pcm_dev->dev, in pcmdevice_add_config()
1279 __func__, i, cfg_info->nblocks); in pcmdevice_add_config()
1285 *status = -ENOMEM; in pcmdevice_add_config()
1288 bk_da[i]->dev_idx = config_data[config_offset]; in pcmdevice_add_config()
1291 bk_da[i]->block_type = config_data[config_offset]; in pcmdevice_add_config()
1294 if (bk_da[i]->block_type == PCMDEVICE_BIN_BLK_PRE_POWER_UP) { in pcmdevice_add_config()
1295 if (bk_da[i]->dev_idx == 0) in pcmdevice_add_config()
1296 cfg_info->active_dev = in pcmdevice_add_config()
1297 (1 << pcm_dev->ndev) - 1; in pcmdevice_add_config()
1299 cfg_info->active_dev = in pcmdevice_add_config()
1300 1 << (bk_da[i]->dev_idx - 1); in pcmdevice_add_config()
1303 bk_da[i]->yram_checksum = in pcmdevice_add_config()
1306 bk_da[i]->block_size = in pcmdevice_add_config()
1310 bk_da[i]->n_subblks = in pcmdevice_add_config()
1315 if (config_offset + bk_da[i]->block_size > config_size) { in pcmdevice_add_config()
1316 *status = -EINVAL; in pcmdevice_add_config()
1317 dev_err(pcm_dev->dev, in pcmdevice_add_config()
1319 __func__, i, cfg_info->nblocks); in pcmdevice_add_config()
1323 bk_da[i]->regdata = kmemdup(&config_data[config_offset], in pcmdevice_add_config()
1324 bk_da[i]->block_size, GFP_KERNEL); in pcmdevice_add_config()
1325 if (!bk_da[i]->regdata) { in pcmdevice_add_config()
1326 *status = -ENOMEM; in pcmdevice_add_config()
1329 config_offset += bk_da[i]->block_size; in pcmdevice_add_config()
1330 cfg_info->real_nblocks += 1; in pcmdevice_add_config()
1339 struct i2c_adapter *adap = pcm_dev->client->adapter; in pcmdev_gain_ctrl_add()
1340 struct snd_soc_component *comp = pcm_dev->component; in pcmdev_gain_ctrl_add()
1344 unsigned int id = pcm_dev->chip_id; in pcmdev_gain_ctrl_add()
1351 dev_dbg(pcm_dev->dev, "%s: no gain ctrl for %s\n", __func__, in pcmdev_gain_ctrl_add()
1352 pcm_dev->dev_name); in pcmdev_gain_ctrl_add()
1356 pcmdev_controls = devm_kzalloc(pcm_dev->dev, in pcmdev_gain_ctrl_add()
1359 return -ENOMEM; in pcmdev_gain_ctrl_add()
1366 name = devm_kzalloc(pcm_dev->dev, in pcmdev_gain_ctrl_add()
1369 ret = -ENOMEM; in pcmdev_gain_ctrl_add()
1373 ctrl_name, pcm_dev->upper_dev_name, adap->nr, in pcmdev_gain_ctrl_add()
1377 pcmdev_ctrl = devm_kmemdup(pcm_dev->dev, in pcmdev_gain_ctrl_add()
1378 &pcmdev_gain_ctl_info[id][ctl_id].pcmdev_ctrl[chn - 1], in pcmdev_gain_ctrl_add()
1381 ret = -ENOMEM; in pcmdev_gain_ctrl_add()
1384 pcmdev_ctrl->dev_no = dev_no; in pcmdev_gain_ctrl_add()
1403 dev_err(pcm_dev->dev, "%s: add_controls err = %d\n", in pcmdev_gain_ctrl_add()
1411 struct snd_soc_component *comp = pcm_dev->component; in pcmdev_profile_ctrl_add()
1412 struct i2c_adapter *adap = pcm_dev->client->adapter; in pcmdev_profile_ctrl_add()
1417 pcmdev_ctrl = devm_kzalloc(pcm_dev->dev, in pcmdev_profile_ctrl_add()
1420 return -ENOMEM; in pcmdev_profile_ctrl_add()
1423 name = devm_kzalloc(pcm_dev->dev, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, in pcmdev_profile_ctrl_add()
1426 return -ENOMEM; in pcmdev_profile_ctrl_add()
1429 "%s i2c%d Profile id", pcm_dev->upper_dev_name, adap->nr); in pcmdev_profile_ctrl_add()
1430 pcmdev_ctrl->name = name; in pcmdev_profile_ctrl_add()
1431 pcmdev_ctrl->iface = SNDRV_CTL_ELEM_IFACE_MIXER; in pcmdev_profile_ctrl_add()
1432 pcmdev_ctrl->info = pcmdevice_info_profile; in pcmdev_profile_ctrl_add()
1433 pcmdev_ctrl->get = pcmdevice_get_profile_id; in pcmdev_profile_ctrl_add()
1434 pcmdev_ctrl->put = pcmdevice_set_profile_id; in pcmdev_profile_ctrl_add()
1438 dev_err(pcm_dev->dev, "%s: add_controls err = %d\n", in pcmdev_profile_ctrl_add()
1447 struct pcmdevice_regbin *regbin = &(pcm_dev->regbin); in pcmdevice_config_info_remove()
1448 struct pcmdevice_config_info **cfg_info = regbin->cfg_info; in pcmdevice_config_info_remove()
1453 for (i = 0; i < regbin->ncfgs; i++) { in pcmdevice_config_info_remove()
1456 if (cfg_info[i]->blk_data) { in pcmdevice_config_info_remove()
1457 for (j = 0; j < (int)cfg_info[i]->real_nblocks; j++) { in pcmdevice_config_info_remove()
1458 if (!cfg_info[i]->blk_data[j]) in pcmdevice_config_info_remove()
1460 kfree(cfg_info[i]->blk_data[j]->regdata); in pcmdevice_config_info_remove()
1461 kfree(cfg_info[i]->blk_data[j]); in pcmdevice_config_info_remove()
1463 kfree(cfg_info[i]->blk_data); in pcmdevice_config_info_remove()
1480 regbin = &(pcm_dev->regbin); in pcmdev_regbin_ready()
1481 fw_hdr = &(regbin->fw_hdr); in pcmdev_regbin_ready()
1482 if (!fmw || !fmw->data) { in pcmdev_regbin_ready()
1483 dev_err(pcm_dev->dev, "%s: failed to read %s\n", in pcmdev_regbin_ready()
1484 __func__, pcm_dev->bin_name); in pcmdev_regbin_ready()
1485 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1486 ret = -EINVAL; in pcmdev_regbin_ready()
1489 buf = (unsigned char *)fmw->data; in pcmdev_regbin_ready()
1491 fw_hdr->img_sz = get_unaligned_be32(&buf[offset]); in pcmdev_regbin_ready()
1493 if (fw_hdr->img_sz != fmw->size) { in pcmdev_regbin_ready()
1494 dev_err(pcm_dev->dev, "%s: file size(%d) not match %u", in pcmdev_regbin_ready()
1495 __func__, (int)fmw->size, fw_hdr->img_sz); in pcmdev_regbin_ready()
1496 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1497 ret = -EINVAL; in pcmdev_regbin_ready()
1501 fw_hdr->checksum = get_unaligned_be32(&buf[offset]); in pcmdev_regbin_ready()
1503 fw_hdr->binary_version_num = get_unaligned_be32(&buf[offset]); in pcmdev_regbin_ready()
1504 if (fw_hdr->binary_version_num < 0x103) { in pcmdev_regbin_ready()
1505 dev_err(pcm_dev->dev, "%s: bin version 0x%04x is out of date", in pcmdev_regbin_ready()
1506 __func__, fw_hdr->binary_version_num); in pcmdev_regbin_ready()
1507 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1508 ret = -EINVAL; in pcmdev_regbin_ready()
1512 fw_hdr->drv_fw_version = get_unaligned_be32(&buf[offset]); in pcmdev_regbin_ready()
1514 fw_hdr->plat_type = buf[offset]; in pcmdev_regbin_ready()
1516 fw_hdr->dev_family = buf[offset]; in pcmdev_regbin_ready()
1518 fw_hdr->reserve = buf[offset]; in pcmdev_regbin_ready()
1520 fw_hdr->ndev = buf[offset]; in pcmdev_regbin_ready()
1522 if (fw_hdr->ndev != pcm_dev->ndev) { in pcmdev_regbin_ready()
1523 dev_err(pcm_dev->dev, "%s: invalid ndev(%u)\n", __func__, in pcmdev_regbin_ready()
1524 fw_hdr->ndev); in pcmdev_regbin_ready()
1525 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1526 ret = -EINVAL; in pcmdev_regbin_ready()
1530 if (offset + PCMDEVICE_MAX_REGBIN_DEVICES > fw_hdr->img_sz) { in pcmdev_regbin_ready()
1531 dev_err(pcm_dev->dev, "%s: devs out of boundary!\n", __func__); in pcmdev_regbin_ready()
1532 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1533 ret = -EINVAL; in pcmdev_regbin_ready()
1538 fw_hdr->devs[i] = buf[offset]; in pcmdev_regbin_ready()
1540 fw_hdr->nconfig = get_unaligned_be32(&buf[offset]); in pcmdev_regbin_ready()
1544 fw_hdr->config_size[i] = get_unaligned_be32(&buf[offset]); in pcmdev_regbin_ready()
1546 total_config_sz += fw_hdr->config_size[i]; in pcmdev_regbin_ready()
1549 if (fw_hdr->img_sz - total_config_sz != (unsigned int)offset) { in pcmdev_regbin_ready()
1550 dev_err(pcm_dev->dev, "%s: bin file error!\n", __func__); in pcmdev_regbin_ready()
1551 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1552 ret = -EINVAL; in pcmdev_regbin_ready()
1555 cfg_info = kcalloc(fw_hdr->nconfig, sizeof(*cfg_info), GFP_KERNEL); in pcmdev_regbin_ready()
1557 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1558 ret = -ENOMEM; in pcmdev_regbin_ready()
1561 regbin->cfg_info = cfg_info; in pcmdev_regbin_ready()
1562 regbin->ncfgs = 0; in pcmdev_regbin_ready()
1563 for (i = 0; i < (int)fw_hdr->nconfig; i++) { in pcmdev_regbin_ready()
1565 fw_hdr->config_size[i], &ret); in pcmdev_regbin_ready()
1568 if (regbin->ncfgs == 0) in pcmdev_regbin_ready()
1569 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED; in pcmdev_regbin_ready()
1572 offset += (int)fw_hdr->config_size[i]; in pcmdev_regbin_ready()
1573 regbin->ncfgs += 1; in pcmdev_regbin_ready()
1577 if (pcm_dev->fw_state == PCMDEVICE_FW_LOAD_FAILED) { in pcmdev_regbin_ready()
1578 dev_err(pcm_dev->dev, in pcmdev_regbin_ready()
1589 struct i2c_adapter *adap = pcm_dev->client->adapter; in pcmdevice_comp_probe()
1593 mutex_lock(&pcm_dev->codec_lock); in pcmdevice_comp_probe()
1595 pcm_dev->component = comp; in pcmdevice_comp_probe()
1597 for (i = 0; i < pcm_dev->ndev; i++) { in pcmdevice_comp_probe()
1605 if (comp->name_prefix) { in pcmdevice_comp_probe()
1613 scnprintf(pcm_dev->bin_name, PCMDEVICE_BIN_FILENAME_LEN, in pcmdevice_comp_probe()
1614 "%s.bin", comp->name_prefix); in pcmdevice_comp_probe()
1617 * device-name[defined in pcmdevice_i2c_id]-i2c-bus_id in pcmdevice_comp_probe()
1618 * [0,1,...,N]-sum[1,...,4]dev.bin stores the firmware in pcmdevice_comp_probe()
1625 scnprintf(pcm_dev->bin_name, PCMDEVICE_BIN_FILENAME_LEN, in pcmdevice_comp_probe()
1626 "%s-i2c-%d-%udev.bin", pcm_dev->dev_name, adap->nr, in pcmdevice_comp_probe()
1627 pcm_dev->ndev); in pcmdevice_comp_probe()
1630 ret = request_firmware(&fw_entry, pcm_dev->bin_name, pcm_dev->dev); in pcmdevice_comp_probe()
1632 dev_err(pcm_dev->dev, "%s: request %s err = %d\n", __func__, in pcmdevice_comp_probe()
1633 pcm_dev->bin_name, ret); in pcmdevice_comp_probe()
1639 dev_err(pcm_dev->dev, "%s: %s parse err = %d\n", __func__, in pcmdevice_comp_probe()
1640 pcm_dev->bin_name, ret); in pcmdevice_comp_probe()
1648 mutex_unlock(&pcm_dev->codec_lock); in pcmdevice_comp_probe()
1659 mutex_lock(&pcm_dev->codec_lock); in pcmdevice_comp_remove()
1661 mutex_unlock(&pcm_dev->codec_lock); in pcmdevice_comp_remove()
1692 unsigned char *data, int devn, int sublocksize) in pcmdev_single_byte_wr() argument
1694 unsigned short len = get_unaligned_be16(&data[2]); in pcmdev_single_byte_wr()
1700 dev_err(pcm_dev->dev, "%s: dev-%d byt wr out of boundary\n", in pcmdev_single_byte_wr()
1702 return -EINVAL; in pcmdev_single_byte_wr()
1707 PCMDEVICE_REG(data[offset + 1], data[offset + 2]), in pcmdev_single_byte_wr()
1708 data[offset + 3]); in pcmdev_single_byte_wr()
1711 dev_err(pcm_dev->dev, "%s: dev-%d single write err\n", in pcmdev_single_byte_wr()
1721 unsigned char *data, int devn, int sublocksize) in pcmdev_burst_wr() argument
1723 unsigned short len = get_unaligned_be16(&data[2]); in pcmdev_burst_wr()
1729 dev_err(pcm_dev->dev, "%s: dev-%d burst Out of boundary\n", in pcmdev_burst_wr()
1731 return -EINVAL; in pcmdev_burst_wr()
1734 dev_err(pcm_dev->dev, "%s: dev-%d bst-len(%u) not div by 4\n", in pcmdev_burst_wr()
1736 return -EINVAL; in pcmdev_burst_wr()
1739 PCMDEVICE_REG(data[offset + 1], data[offset + 2]), in pcmdev_burst_wr()
1740 &(data[offset + 4]), len); in pcmdev_burst_wr()
1743 dev_err(pcm_dev->dev, "%s: dev-%d bulk_write err = %d\n", in pcmdev_burst_wr()
1752 unsigned char *data, int devn, int sublocksize) in pcmdev_delay() argument
1758 dev_err(pcm_dev->dev, "%s: dev-%d delay out of boundary\n", in pcmdev_delay()
1760 return -EINVAL; in pcmdev_delay()
1762 delay_time = get_unaligned_be16(&data[2]) * 1000; in pcmdev_delay()
1770 unsigned char *data, int devn, int sublocksize) in pcmdev_bits_wr() argument
1776 dev_err(pcm_dev->dev, "%s: dev-%d bit write out of memory\n", in pcmdev_bits_wr()
1778 return -EINVAL; in pcmdev_bits_wr()
1781 PCMDEVICE_REG(data[offset + 3], data[offset + 4]), in pcmdev_bits_wr()
1782 data[offset + 1], data[offset + 5]); in pcmdev_bits_wr()
1785 dev_err(pcm_dev->dev, "%s: dev-%d update_bits err = %d\n", in pcmdev_bits_wr()
1793 static int pcmdevice_process_block(void *ctxt, unsigned char *data, in pcmdevice_process_block() argument
1798 unsigned char subblk_typ = data[1]; in pcmdevice_process_block()
1801 devn = dev_idx - 1; in pcmdevice_process_block()
1805 dev_end = pcm_dev->ndev; in pcmdevice_process_block()
1808 /* loop in case of several devices sharing the same sub-block */ in pcmdevice_process_block()
1812 ret = pcmdev_single_byte_wr(pcm_dev, data, devn, sublocksize); in pcmdevice_process_block()
1815 ret = pcmdev_burst_wr(pcm_dev, data, devn, sublocksize); in pcmdevice_process_block()
1818 ret = pcmdev_delay(pcm_dev, data, devn, sublocksize); in pcmdevice_process_block()
1821 ret = pcmdev_bits_wr(pcm_dev, data, devn, sublocksize); in pcmdevice_process_block()
1827 * In case of sub-block error, break the loop for the rest of in pcmdevice_process_block()
1841 struct pcmdevice_regbin *regbin = &(pcm_dev->regbin); in pcmdevice_select_cfg_blk()
1842 struct pcmdevice_config_info **cfg_info = regbin->cfg_info; in pcmdevice_select_cfg_blk()
1846 if (conf_no >= regbin->ncfgs || conf_no < 0 || NULL == cfg_info) { in pcmdevice_select_cfg_blk()
1847 dev_err(pcm_dev->dev, "%s: conf_no should be less than %u\n", in pcmdevice_select_cfg_blk()
1848 __func__, regbin->ncfgs); in pcmdevice_select_cfg_blk()
1851 blk_data = cfg_info[conf_no]->blk_data; in pcmdevice_select_cfg_blk()
1853 for (j = 0; j < (int)cfg_info[conf_no]->real_nblocks; j++) { in pcmdevice_select_cfg_blk()
1857 dev_err(pcm_dev->dev, in pcmdevice_select_cfg_blk()
1862 if (block_type != blk_data[j]->block_type) in pcmdevice_select_cfg_blk()
1865 for (k = 0; k < (int)blk_data[j]->n_subblks; k++) { in pcmdevice_select_cfg_blk()
1867 blk_data[j]->regdata + length, in pcmdevice_select_cfg_blk()
1868 blk_data[j]->dev_idx, in pcmdevice_select_cfg_blk()
1869 blk_data[j]->block_size - length); in pcmdevice_select_cfg_blk()
1871 if (blk_data[j]->block_size < length) { in pcmdevice_select_cfg_blk()
1872 dev_err(pcm_dev->dev, in pcmdevice_select_cfg_blk()
1875 blk_data[j]->block_size); in pcmdevice_select_cfg_blk()
1879 if (length != blk_data[j]->block_size) in pcmdevice_select_cfg_blk()
1880 dev_err(pcm_dev->dev, "%s: %u %u size is not same\n", in pcmdevice_select_cfg_blk()
1881 __func__, length, blk_data[j]->block_size); in pcmdevice_select_cfg_blk()
1890 struct snd_soc_component *codec = dai->component; in pcmdevice_mute()
1894 if (pcm_dev->fw_state == PCMDEVICE_FW_LOAD_FAILED) { in pcmdevice_mute()
1895 dev_err(pcm_dev->dev, "%s: bin file not loaded\n", __func__); in pcmdevice_mute()
1896 return -EINVAL; in pcmdevice_mute()
1904 mutex_lock(&pcm_dev->codec_lock); in pcmdevice_mute()
1905 pcmdevice_select_cfg_blk(pcm_dev, pcm_dev->cur_conf, block_type); in pcmdevice_mute()
1906 mutex_unlock(&pcm_dev->codec_lock); in pcmdevice_mute()
1926 dev_err(pcm_dev->dev, "%s: incorrect sample rate = %u\n", in pcmdevice_hw_params()
1928 ret = -EINVAL; in pcmdevice_hw_params()
1943 dev_err(pcm_dev->dev, "%s: incorrect slot width = %u\n", in pcmdevice_hw_params()
1945 ret = -EINVAL; in pcmdevice_hw_params()
1951 dev_err(pcm_dev->dev, "%s: incorrect bclk rate = %d\n", in pcmdevice_hw_params()
1967 .name = "pcmdevice-codec",
2038 if (gpio_is_valid(pcm_dev->irq_info.gpio)) { in pcmdevice_remove()
2039 gpio_free(pcm_dev->irq_info.gpio); in pcmdevice_remove()
2040 free_irq(pcm_dev->irq_info.nmb, pcm_dev); in pcmdevice_remove()
2042 mutex_destroy(&pcm_dev->codec_lock); in pcmdevice_remove()
2068 pcm_dev = devm_kzalloc(&i2c->dev, sizeof(*pcm_dev), GFP_KERNEL); in pcmdevice_i2c_probe()
2070 return -ENOMEM; in pcmdevice_i2c_probe()
2072 pcm_dev->chip_id = (id != NULL) ? id->driver_data : 0; in pcmdevice_i2c_probe()
2074 pcm_dev->dev = &i2c->dev; in pcmdevice_i2c_probe()
2075 pcm_dev->client = i2c; in pcmdevice_i2c_probe()
2077 if (pcm_dev->chip_id >= MAX_DEVICE) in pcmdevice_i2c_probe()
2078 pcm_dev->chip_id = 0; in pcmdevice_i2c_probe()
2080 strscpy(pcm_dev->dev_name, pcmdevice_i2c_id[pcm_dev->chip_id].name, in pcmdevice_i2c_probe()
2081 sizeof(pcm_dev->dev_name)); in pcmdevice_i2c_probe()
2083 strscpy(pcm_dev->upper_dev_name, in pcmdevice_i2c_probe()
2084 pcmdevice_i2c_id[pcm_dev->chip_id].name, in pcmdevice_i2c_probe()
2085 sizeof(pcm_dev->upper_dev_name)); in pcmdevice_i2c_probe()
2087 str_to_upper(pcm_dev->upper_dev_name); in pcmdevice_i2c_probe()
2089 pcm_dev->regmap = devm_regmap_init_i2c(i2c, &pcmdevice_i2c_regmap); in pcmdevice_i2c_probe()
2090 if (IS_ERR(pcm_dev->regmap)) { in pcmdevice_i2c_probe()
2091 ret = PTR_ERR(pcm_dev->regmap); in pcmdevice_i2c_probe()
2092 dev_err(&i2c->dev, "%s: failed to allocate register map: %d\n", in pcmdevice_i2c_probe()
2098 mutex_init(&pcm_dev->codec_lock); in pcmdevice_i2c_probe()
2099 np = pcm_dev->dev->of_node; in pcmdevice_i2c_probe()
2111 dev_addrs[0] = i2c->addr; in pcmdevice_i2c_probe()
2113 pcm_dev->irq_info.gpio = of_irq_get(np, 0); in pcmdevice_i2c_probe()
2116 pcm_dev->addr[i] = dev_addrs[i]; in pcmdevice_i2c_probe()
2118 pcm_dev->ndev = ndev; in pcmdevice_i2c_probe()
2120 pcm_dev->hw_rst = devm_gpiod_get_optional(&i2c->dev, in pcmdevice_i2c_probe()
2121 "reset-gpios", GPIOD_OUT_HIGH); in pcmdevice_i2c_probe()
2122 /* No reset GPIO, no side-effect */ in pcmdevice_i2c_probe()
2123 if (IS_ERR(pcm_dev->hw_rst)) { in pcmdevice_i2c_probe()
2124 if (pcm_dev->chip_id == PCM9211 || pcm_dev->chip_id == PCM1690) in pcmdevice_i2c_probe()
2129 gpiod_set_value_cansleep(pcm_dev->hw_rst, 0); in pcmdevice_i2c_probe()
2131 gpiod_set_value_cansleep(pcm_dev->hw_rst, 1); in pcmdevice_i2c_probe()
2134 if (pcm_dev->chip_id == PCM1690) in pcmdevice_i2c_probe()
2136 if (gpio_is_valid(pcm_dev->irq_info.gpio)) { in pcmdevice_i2c_probe()
2137 dev_dbg(pcm_dev->dev, "irq-gpio = %d", pcm_dev->irq_info.gpio); in pcmdevice_i2c_probe()
2139 ret = gpio_request(pcm_dev->irq_info.gpio, "PCMDEV-IRQ"); in pcmdevice_i2c_probe()
2141 int gpio = pcm_dev->irq_info.gpio; in pcmdevice_i2c_probe()
2144 pcm_dev->irq_info.nmb = gpio_to_irq(gpio); in pcmdevice_i2c_probe()
2147 dev_err(pcm_dev->dev, "%s: GPIO %d request error\n", in pcmdevice_i2c_probe()
2148 __func__, pcm_dev->irq_info.gpio); in pcmdevice_i2c_probe()
2150 dev_err(pcm_dev->dev, "Looking up irq-gpio failed %d\n", in pcmdevice_i2c_probe()
2151 pcm_dev->irq_info.gpio); in pcmdevice_i2c_probe()
2154 ret = devm_snd_soc_register_component(&i2c->dev, in pcmdevice_i2c_probe()
2158 dev_err(&i2c->dev, "probe register comp failed %d\n", ret); in pcmdevice_i2c_probe()
2175 .name = "pcmdevice-codec",
2184 MODULE_AUTHOR("Shenghao Ding <shenghao-ding@ti.com>");