Lines Matching +full:nconfig +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (C) 2022 - 2024 Texas Instruments Incorporated
12 // Author: Shenghao Ding <shenghao-ding@ti.com>
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;
522 struct regmap *map = pcm_priv->regmap;
525 if (client->addr == pcm_priv->addr[dev_no])
528 client->addr = pcm_priv->addr[dev_no];
532 * one for page-switching.
536 dev_err(pcm_priv->dev, "%s: err = %d\n", __func__, ret);
544 struct regmap *map = pcm_dev->regmap;
547 if (dev_no >= pcm_dev->ndev) {
548 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__,
550 return -EINVAL;
555 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret);
561 dev_err(pcm_dev->dev, "%s: err = %d\n", __func__, ret);
570 struct regmap *map = pcm_dev->regmap;
573 if (dev_no >= pcm_dev->ndev) {
574 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__,
576 return -EINVAL;
581 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret);
587 dev_err(pcm_dev->dev, "%s: update_bits err=%d\n",
600 (struct pcmdevice_mixer_control *)kcontrol->private_value;
601 int max = mc->max, ret;
602 unsigned int mask = BIT(fls(max)) - 1;
603 unsigned int dev_no = mc->dev_no;
604 unsigned int shift = mc->shift;
605 unsigned int reg = mc->reg;
608 mutex_lock(&pcm_dev->codec_lock);
610 if (pcm_dev->chip_id == PCM1690) {
614 dev_err(pcm_dev->dev, "%s: read mode err=%d\n",
619 /* Set to wide-range mode, before using vol ctrl. */
621 ucontrol->value.integer.value[0] = -25500;
626 ucontrol->value.integer.value[0] = -12750;
633 dev_err(pcm_dev->dev, "%s: read err=%d\n",
640 val = mc->invert ? max - val : val;
641 ucontrol->value.integer.value[0] = val;
643 mutex_unlock(&pcm_dev->codec_lock);
673 (struct pcmdevice_mixer_control *)kcontrol->private_value;
674 int max = mc->max, rc;
675 unsigned int mask = BIT(fls(max)) - 1;
676 unsigned int dev_no = mc->dev_no;
677 unsigned int shift = mc->shift;
679 unsigned int reg = mc->reg;
681 mutex_lock(&pcm_dev->codec_lock);
682 val = ucontrol->value.integer.value[0] & mask;
684 val = mc->invert ? max - val : val;
701 dev_err(pcm_dev->dev, "%s: update_bits err = %d\n",
705 mutex_unlock(&pcm_dev->codec_lock);
1090 struct regmap *map = pcm_dev->regmap;
1093 if (dev_no >= pcm_dev->ndev) {
1094 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__,
1096 return -EINVAL;
1101 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret);
1107 dev_err(pcm_dev->dev, "%s: bulk_write err = %d\n", __func__,
1116 struct regmap *map = pcm_dev->regmap;
1119 if (dev_no >= pcm_dev->ndev) {
1120 dev_err(pcm_dev->dev, "%s: no such channel(%d)\n", __func__,
1122 return -EINVAL;
1127 dev_err(pcm_dev->dev, "%s: chg dev err = %d\n", __func__, ret);
1133 dev_err(pcm_dev->dev, "%s: err = %d\n", __func__, ret);
1147 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1148 uinfo->count = 1;
1149 uinfo->value.integer.min = 0;
1150 uinfo->value.integer.max = max(0, pcm_dev->regbin.ncfgs - 1);
1164 ucontrol->value.integer.value[0] = pcm_dev->cur_conf;
1177 int nr_profile = ucontrol->value.integer.value[0];
1178 int max = pcm_dev->regbin.ncfgs - 1;
1183 if (pcm_dev->cur_conf != nr_profile) {
1184 pcm_dev->cur_conf = nr_profile;
1195 (struct pcmdevice_mixer_control *)kcontrol->private_value;
1197 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1198 uinfo->count = 1;
1199 uinfo->value.integer.min = 0;
1200 uinfo->value.integer.max = mc->max;
1208 for (i = 0; i < pcm_dev->ndev; i++) {
1213 dev_err(pcm_dev->dev, "%s: dev %d swreset fail %d\n",
1222 for (i = 0; i < pcm_dev->ndev; i++) {
1226 dev_err(pcm_dev->dev, "%s: dev %d swreset fail %d\n",
1242 *status = -ENOMEM;
1246 if (pcm_dev->regbin.fw_hdr.binary_version_num >= 0x105) {
1248 *status = -EINVAL;
1249 dev_err(pcm_dev->dev,
1253 memcpy(cfg_info->cfg_name, &config_data[config_offset], 64);
1258 *status = -EINVAL;
1259 dev_err(pcm_dev->dev, "%s: nblocks out of boundary\n",
1263 cfg_info->nblocks =
1267 bk_da = cfg_info->blk_data = kcalloc(cfg_info->nblocks,
1270 *status = -ENOMEM;
1273 cfg_info->real_nblocks = 0;
1274 for (i = 0; i < cfg_info->nblocks; i++) {
1276 *status = -EINVAL;
1277 dev_err(pcm_dev->dev,
1279 __func__, i, cfg_info->nblocks);
1285 *status = -ENOMEM;
1288 bk_da[i]->dev_idx = config_data[config_offset];
1291 bk_da[i]->block_type = config_data[config_offset];
1294 if (bk_da[i]->block_type == PCMDEVICE_BIN_BLK_PRE_POWER_UP) {
1295 if (bk_da[i]->dev_idx == 0)
1296 cfg_info->active_dev =
1297 (1 << pcm_dev->ndev) - 1;
1299 cfg_info->active_dev =
1300 1 << (bk_da[i]->dev_idx - 1);
1303 bk_da[i]->yram_checksum =
1306 bk_da[i]->block_size =
1310 bk_da[i]->n_subblks =
1315 if (config_offset + bk_da[i]->block_size > config_size) {
1316 *status = -EINVAL;
1317 dev_err(pcm_dev->dev,
1319 __func__, i, cfg_info->nblocks);
1323 bk_da[i]->regdata = kmemdup(&config_data[config_offset],
1324 bk_da[i]->block_size, GFP_KERNEL);
1325 if (!bk_da[i]->regdata) {
1326 *status = -ENOMEM;
1329 config_offset += bk_da[i]->block_size;
1330 cfg_info->real_nblocks += 1;
1339 struct i2c_adapter *adap = pcm_dev->client->adapter;
1340 struct snd_soc_component *comp = pcm_dev->component;
1344 unsigned int id = pcm_dev->chip_id;
1351 dev_dbg(pcm_dev->dev, "%s: no gain ctrl for %s\n", __func__,
1352 pcm_dev->dev_name);
1356 pcmdev_controls = devm_kzalloc(pcm_dev->dev,
1359 return -ENOMEM;
1366 name = devm_kzalloc(pcm_dev->dev,
1369 ret = -ENOMEM;
1373 ctrl_name, pcm_dev->upper_dev_name, adap->nr,
1377 pcmdev_ctrl = devm_kmemdup(pcm_dev->dev,
1378 &pcmdev_gain_ctl_info[id][ctl_id].pcmdev_ctrl[chn - 1],
1381 ret = -ENOMEM;
1384 pcmdev_ctrl->dev_no = dev_no;
1403 dev_err(pcm_dev->dev, "%s: add_controls err = %d\n",
1411 struct snd_soc_component *comp = pcm_dev->component;
1412 struct i2c_adapter *adap = pcm_dev->client->adapter;
1417 pcmdev_ctrl = devm_kzalloc(pcm_dev->dev,
1420 return -ENOMEM;
1423 name = devm_kzalloc(pcm_dev->dev, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
1426 return -ENOMEM;
1429 "%s i2c%d Profile id", pcm_dev->upper_dev_name, adap->nr);
1430 pcmdev_ctrl->name = name;
1431 pcmdev_ctrl->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1432 pcmdev_ctrl->info = pcmdevice_info_profile;
1433 pcmdev_ctrl->get = pcmdevice_get_profile_id;
1434 pcmdev_ctrl->put = pcmdevice_set_profile_id;
1438 dev_err(pcm_dev->dev, "%s: add_controls err = %d\n",
1447 struct pcmdevice_regbin *regbin = &(pcm_dev->regbin);
1448 struct pcmdevice_config_info **cfg_info = regbin->cfg_info;
1453 for (i = 0; i < regbin->ncfgs; i++) {
1456 if (cfg_info[i]->blk_data) {
1457 for (j = 0; j < (int)cfg_info[i]->real_nblocks; j++) {
1458 if (!cfg_info[i]->blk_data[j])
1460 kfree(cfg_info[i]->blk_data[j]->regdata);
1461 kfree(cfg_info[i]->blk_data[j]);
1463 kfree(cfg_info[i]->blk_data);
1480 regbin = &(pcm_dev->regbin);
1481 fw_hdr = &(regbin->fw_hdr);
1482 if (!fmw || !fmw->data) {
1483 dev_err(pcm_dev->dev, "%s: failed to read %s\n",
1484 __func__, pcm_dev->bin_name);
1485 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1486 ret = -EINVAL;
1489 buf = (unsigned char *)fmw->data;
1491 fw_hdr->img_sz = get_unaligned_be32(&buf[offset]);
1493 if (fw_hdr->img_sz != fmw->size) {
1494 dev_err(pcm_dev->dev, "%s: file size(%d) not match %u",
1495 __func__, (int)fmw->size, fw_hdr->img_sz);
1496 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1497 ret = -EINVAL;
1501 fw_hdr->checksum = get_unaligned_be32(&buf[offset]);
1503 fw_hdr->binary_version_num = get_unaligned_be32(&buf[offset]);
1504 if (fw_hdr->binary_version_num < 0x103) {
1505 dev_err(pcm_dev->dev, "%s: bin version 0x%04x is out of date",
1506 __func__, fw_hdr->binary_version_num);
1507 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1508 ret = -EINVAL;
1512 fw_hdr->drv_fw_version = get_unaligned_be32(&buf[offset]);
1514 fw_hdr->plat_type = buf[offset];
1516 fw_hdr->dev_family = buf[offset];
1518 fw_hdr->reserve = buf[offset];
1520 fw_hdr->ndev = buf[offset];
1522 if (fw_hdr->ndev != pcm_dev->ndev) {
1523 dev_err(pcm_dev->dev, "%s: invalid ndev(%u)\n", __func__,
1524 fw_hdr->ndev);
1525 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1526 ret = -EINVAL;
1530 if (offset + PCMDEVICE_MAX_REGBIN_DEVICES > fw_hdr->img_sz) {
1531 dev_err(pcm_dev->dev, "%s: devs out of boundary!\n", __func__);
1532 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1533 ret = -EINVAL;
1538 fw_hdr->devs[i] = buf[offset];
1540 fw_hdr->nconfig = get_unaligned_be32(&buf[offset]);
1544 fw_hdr->config_size[i] = get_unaligned_be32(&buf[offset]);
1546 total_config_sz += fw_hdr->config_size[i];
1549 if (fw_hdr->img_sz - total_config_sz != (unsigned int)offset) {
1550 dev_err(pcm_dev->dev, "%s: bin file error!\n", __func__);
1551 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1552 ret = -EINVAL;
1555 cfg_info = kcalloc(fw_hdr->nconfig, sizeof(*cfg_info), GFP_KERNEL);
1557 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1558 ret = -ENOMEM;
1561 regbin->cfg_info = cfg_info;
1562 regbin->ncfgs = 0;
1563 for (i = 0; i < (int)fw_hdr->nconfig; i++) {
1565 fw_hdr->config_size[i], &ret);
1568 if (regbin->ncfgs == 0)
1569 pcm_dev->fw_state = PCMDEVICE_FW_LOAD_FAILED;
1572 offset += (int)fw_hdr->config_size[i];
1573 regbin->ncfgs += 1;
1577 if (pcm_dev->fw_state == PCMDEVICE_FW_LOAD_FAILED) {
1578 dev_err(pcm_dev->dev,
1589 struct i2c_adapter *adap = pcm_dev->client->adapter;
1593 mutex_lock(&pcm_dev->codec_lock);
1595 pcm_dev->component = comp;
1597 for (i = 0; i < pcm_dev->ndev; i++) {
1605 if (comp->name_prefix) {
1613 scnprintf(pcm_dev->bin_name, PCMDEVICE_BIN_FILENAME_LEN,
1614 "%s.bin", comp->name_prefix);
1617 * device-name[defined in pcmdevice_i2c_id]-i2c-bus_id
1618 * [0,1,...,N]-sum[1,...,4]dev.bin stores the firmware
1625 scnprintf(pcm_dev->bin_name, PCMDEVICE_BIN_FILENAME_LEN,
1626 "%s-i2c-%d-%udev.bin", pcm_dev->dev_name, adap->nr,
1627 pcm_dev->ndev);
1630 ret = request_firmware(&fw_entry, pcm_dev->bin_name, pcm_dev->dev);
1632 dev_err(pcm_dev->dev, "%s: request %s err = %d\n", __func__,
1633 pcm_dev->bin_name, ret);
1639 dev_err(pcm_dev->dev, "%s: %s parse err = %d\n", __func__,
1640 pcm_dev->bin_name, ret);
1648 mutex_unlock(&pcm_dev->codec_lock);
1659 mutex_lock(&pcm_dev->codec_lock);
1661 mutex_unlock(&pcm_dev->codec_lock);
1700 dev_err(pcm_dev->dev, "%s: dev-%d byt wr out of boundary\n",
1702 return -EINVAL;
1711 dev_err(pcm_dev->dev, "%s: dev-%d single write err\n",
1729 dev_err(pcm_dev->dev, "%s: dev-%d burst Out of boundary\n",
1731 return -EINVAL;
1734 dev_err(pcm_dev->dev, "%s: dev-%d bst-len(%u) not div by 4\n",
1736 return -EINVAL;
1743 dev_err(pcm_dev->dev, "%s: dev-%d bulk_write err = %d\n",
1758 dev_err(pcm_dev->dev, "%s: dev-%d delay out of boundary\n",
1760 return -EINVAL;
1776 dev_err(pcm_dev->dev, "%s: dev-%d bit write out of memory\n",
1778 return -EINVAL;
1785 dev_err(pcm_dev->dev, "%s: dev-%d update_bits err = %d\n",
1801 devn = dev_idx - 1;
1805 dev_end = pcm_dev->ndev;
1808 /* loop in case of several devices sharing the same sub-block */
1827 * In case of sub-block error, break the loop for the rest of
1841 struct pcmdevice_regbin *regbin = &(pcm_dev->regbin);
1842 struct pcmdevice_config_info **cfg_info = regbin->cfg_info;
1846 if (conf_no >= regbin->ncfgs || conf_no < 0 || NULL == cfg_info) {
1847 dev_err(pcm_dev->dev, "%s: conf_no should be less than %u\n",
1848 __func__, regbin->ncfgs);
1851 blk_data = cfg_info[conf_no]->blk_data;
1853 for (j = 0; j < (int)cfg_info[conf_no]->real_nblocks; j++) {
1857 dev_err(pcm_dev->dev,
1862 if (block_type != blk_data[j]->block_type)
1865 for (k = 0; k < (int)blk_data[j]->n_subblks; k++) {
1867 blk_data[j]->regdata + length,
1868 blk_data[j]->dev_idx,
1869 blk_data[j]->block_size - length);
1871 if (blk_data[j]->block_size < length) {
1872 dev_err(pcm_dev->dev,
1875 blk_data[j]->block_size);
1879 if (length != blk_data[j]->block_size)
1880 dev_err(pcm_dev->dev, "%s: %u %u size is not same\n",
1881 __func__, length, blk_data[j]->block_size);
1890 struct snd_soc_component *codec = dai->component;
1894 if (pcm_dev->fw_state == PCMDEVICE_FW_LOAD_FAILED) {
1895 dev_err(pcm_dev->dev, "%s: bin file not loaded\n", __func__);
1896 return -EINVAL;
1904 mutex_lock(&pcm_dev->codec_lock);
1905 pcmdevice_select_cfg_blk(pcm_dev, pcm_dev->cur_conf, block_type);
1906 mutex_unlock(&pcm_dev->codec_lock);
1926 dev_err(pcm_dev->dev, "%s: incorrect sample rate = %u\n",
1928 ret = -EINVAL;
1943 dev_err(pcm_dev->dev, "%s: incorrect slot width = %u\n",
1945 ret = -EINVAL;
1951 dev_err(pcm_dev->dev, "%s: incorrect bclk rate = %d\n",
1967 .name = "pcmdevice-codec",
2038 if (gpio_is_valid(pcm_dev->irq_info.gpio)) {
2039 gpio_free(pcm_dev->irq_info.gpio);
2040 free_irq(pcm_dev->irq_info.nmb, pcm_dev);
2042 mutex_destroy(&pcm_dev->codec_lock);
2067 pcm_dev = devm_kzalloc(&i2c->dev, sizeof(*pcm_dev), GFP_KERNEL);
2069 return -ENOMEM;
2071 pcm_dev->chip_id = (uintptr_t)i2c_get_match_data(i2c);
2073 pcm_dev->dev = &i2c->dev;
2074 pcm_dev->client = i2c;
2076 if (pcm_dev->chip_id >= MAX_DEVICE)
2077 pcm_dev->chip_id = 0;
2079 strscpy(pcm_dev->dev_name, pcmdevice_i2c_id[pcm_dev->chip_id].name,
2080 sizeof(pcm_dev->dev_name));
2082 strscpy(pcm_dev->upper_dev_name,
2083 pcmdevice_i2c_id[pcm_dev->chip_id].name,
2084 sizeof(pcm_dev->upper_dev_name));
2086 str_to_upper(pcm_dev->upper_dev_name);
2088 pcm_dev->regmap = devm_regmap_init_i2c(i2c, &pcmdevice_i2c_regmap);
2089 if (IS_ERR(pcm_dev->regmap)) {
2090 ret = PTR_ERR(pcm_dev->regmap);
2091 dev_err(&i2c->dev, "%s: failed to allocate register map: %d\n",
2097 mutex_init(&pcm_dev->codec_lock);
2098 np = pcm_dev->dev->of_node;
2110 dev_addrs[0] = i2c->addr;
2112 pcm_dev->irq_info.gpio = of_irq_get(np, 0);
2115 pcm_dev->addr[i] = dev_addrs[i];
2117 pcm_dev->ndev = ndev;
2119 pcm_dev->hw_rst = devm_gpiod_get_optional(&i2c->dev,
2120 "reset-gpios", GPIOD_OUT_HIGH);
2121 /* No reset GPIO, no side-effect */
2122 if (IS_ERR(pcm_dev->hw_rst)) {
2123 if (pcm_dev->chip_id == PCM9211 || pcm_dev->chip_id == PCM1690)
2128 gpiod_set_value_cansleep(pcm_dev->hw_rst, 0);
2130 gpiod_set_value_cansleep(pcm_dev->hw_rst, 1);
2133 if (pcm_dev->chip_id == PCM1690)
2135 if (gpio_is_valid(pcm_dev->irq_info.gpio)) {
2136 dev_dbg(pcm_dev->dev, "irq-gpio = %d", pcm_dev->irq_info.gpio);
2138 ret = gpio_request(pcm_dev->irq_info.gpio, "PCMDEV-IRQ");
2140 int gpio = pcm_dev->irq_info.gpio;
2143 pcm_dev->irq_info.nmb = gpio_to_irq(gpio);
2146 dev_err(pcm_dev->dev, "%s: GPIO %d request error\n",
2147 __func__, pcm_dev->irq_info.gpio);
2149 dev_err(pcm_dev->dev, "Looking up irq-gpio failed %d\n",
2150 pcm_dev->irq_info.gpio);
2153 ret = devm_snd_soc_register_component(&i2c->dev,
2157 dev_err(&i2c->dev, "probe register comp failed %d\n", ret);
2174 .name = "pcmdevice-codec",
2183 MODULE_AUTHOR("Shenghao Ding <shenghao-ding@ti.com>");