Lines Matching defs:sma1303

3 // sma1303.c -- sma1303 ALSA SoC Audio driver
28 #include "sma1303.h"
238 static int sma1303_regmap_write(struct sma1303_priv *sma1303,
242 int cnt = sma1303->retry_cnt;
245 ret = regmap_write(sma1303->regmap, reg, val);
247 dev_err(sma1303->dev,
255 static int sma1303_regmap_update_bits(struct sma1303_priv *sma1303,
259 int cnt = sma1303->retry_cnt;
262 ret = regmap_update_bits_check(sma1303->regmap, reg,
265 dev_err(sma1303->dev,
273 static int sma1303_regmap_read(struct sma1303_priv *sma1303,
277 int cnt = sma1303->retry_cnt;
280 ret = regmap_read(sma1303->regmap, reg, val);
282 dev_err(sma1303->dev,
314 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
316 ucontrol->value.integer.value[0] = (int)sma1303->force_mute_status;
317 dev_dbg(sma1303->dev, "%s : Force Mute %s\n", __func__,
318 sma1303->force_mute_status ? "ON" : "OFF");
328 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
331 if (sma1303->force_mute_status == val)
335 sma1303->force_mute_status = val;
337 dev_dbg(sma1303->dev, "%s : Force Mute %s\n", __func__,
338 sma1303->force_mute_status ? "ON" : "OFF");
348 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
351 ret = sma1303_regmap_read(sma1303, SMA1303_90_POSTSCALER, &val);
365 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
369 ret = sma1303_regmap_update_bits(sma1303,
382 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
385 ret = sma1303_regmap_read(sma1303, SMA1303_A5_TDM1, &val);
390 sma1303->tdm_slot_rx = ucontrol->value.integer.value[0];
400 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
404 ret = sma1303_regmap_update_bits(sma1303,
417 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
420 ret = sma1303_regmap_read(sma1303, SMA1303_A6_TDM2, &val);
425 sma1303->tdm_slot_tx = ucontrol->value.integer.value[0];
435 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
439 ret = sma1303_regmap_update_bits(sma1303,
449 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
452 sma1303_regmap_update_bits(sma1303, SMA1303_8E_PLL_CTRL,
457 sma1303_regmap_update_bits(sma1303, SMA1303_00_SYSTEM_CTRL,
462 if (sma1303->amp_mode == SMA1303_MONO) {
463 sma1303_regmap_update_bits(sma1303,
472 sma1303_regmap_update_bits(sma1303,
481 if (sma1303->check_fault_status) {
482 if (sma1303->check_fault_period > 0)
484 &sma1303->check_fault_work,
485 sma1303->check_fault_period * HZ);
488 &sma1303->check_fault_work,
492 sma1303->amp_power_status = true;
499 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
502 cancel_delayed_work_sync(&sma1303->check_fault_work);
504 sma1303_regmap_update_bits(sma1303, SMA1303_10_SYSTEM_CTRL1,
509 sma1303_regmap_update_bits(sma1303, SMA1303_00_SYSTEM_CTRL,
513 sma1303_regmap_update_bits(sma1303, SMA1303_8E_PLL_CTRL,
518 sma1303->amp_power_status = false;
528 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
537 ret += sma1303_regmap_update_bits(sma1303,
542 sma1303->amp_mode = SMA1303_MONO;
545 ret += sma1303_regmap_update_bits(sma1303,
552 ret += sma1303_regmap_update_bits(sma1303,
559 sma1303->amp_mode = SMA1303_STEREO;
562 ret += sma1303_regmap_update_bits(sma1303,
569 ret += sma1303_regmap_update_bits(sma1303,
576 sma1303->amp_mode = SMA1303_STEREO;
579 dev_err(sma1303->dev, "%s : Invalid value (%d)\n",
584 dev_dbg(sma1303->dev, "%s : Source : %s\n", __func__,
598 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
607 ret += sma1303_regmap_update_bits(sma1303,
614 ret += sma1303_regmap_update_bits(sma1303,
623 ret += sma1303_regmap_update_bits(sma1303,
630 ret += sma1303_regmap_update_bits(sma1303,
639 ret += sma1303_regmap_update_bits(sma1303,
646 ret += sma1303_regmap_update_bits(sma1303,
655 ret += sma1303_regmap_update_bits(sma1303,
662 ret += sma1303_regmap_update_bits(sma1303,
671 ret += sma1303_regmap_update_bits(sma1303,
678 ret += sma1303_regmap_update_bits(sma1303,
687 ret += sma1303_regmap_update_bits(sma1303,
694 ret += sma1303_regmap_update_bits(sma1303,
703 ret += sma1303_regmap_update_bits(sma1303,
710 ret += sma1303_regmap_update_bits(sma1303,
719 dev_err(sma1303->dev, "%s : Invalid value (%d)\n",
724 dev_dbg(sma1303->dev, "%s : Source : %s\n", __func__,
738 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
744 dev_dbg(sma1303->dev,
746 ret += sma1303_regmap_update_bits(sma1303,
753 ret += sma1303_regmap_update_bits(sma1303,
762 dev_dbg(sma1303->dev,
764 ret += sma1303_regmap_update_bits(sma1303,
771 ret += sma1303_regmap_update_bits(sma1303,
790 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
796 dev_dbg(sma1303->dev,
798 ret += sma1303_regmap_update_bits(sma1303,
805 dev_dbg(sma1303->dev,
807 ret += sma1303_regmap_update_bits(sma1303,
824 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
829 dev_dbg(sma1303->dev,
834 dev_dbg(sma1303->dev,
932 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
939 if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_MCLK) {
942 } else if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) {
943 for (i = 0; i < sma1303->num_of_pll_matches; i++) {
944 if (sma1303->pll_matches[i].input_clk == bclk)
947 if (i == sma1303->num_of_pll_matches) {
953 ret += sma1303_regmap_update_bits(sma1303,
960 ret += sma1303_regmap_write(sma1303,
962 sma1303->pll_matches[i].post_n);
964 ret += sma1303_regmap_write(sma1303,
966 sma1303->pll_matches[i].n);
968 ret += sma1303_regmap_write(sma1303,
970 sma1303->pll_matches[i].vco);
972 ret += sma1303_regmap_write(sma1303,
974 sma1303->pll_matches[i].p_cp);
985 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
989 if (sma1303->format == SND_SOC_DAIFMT_DSP_A)
990 bclk = params_rate(params) * sma1303->frame_size;
1001 if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) {
1002 if (sma1303->last_bclk != bclk) {
1004 sma1303->last_bclk = bclk;
1017 ret += sma1303_regmap_update_bits(sma1303,
1023 ret += sma1303_regmap_update_bits(sma1303,
1031 ret += sma1303_regmap_update_bits(sma1303,
1037 ret += sma1303_regmap_update_bits(sma1303,
1059 ret += sma1303_regmap_update_bits(sma1303,
1070 ret += sma1303_regmap_update_bits(sma1303,
1080 ret += sma1303_regmap_update_bits(sma1303,
1094 switch (sma1303->format) {
1096 ret += sma1303_regmap_update_bits(sma1303,
1101 ret += sma1303_regmap_update_bits(sma1303,
1108 ret += sma1303_regmap_update_bits(sma1303,
1113 ret += sma1303_regmap_update_bits(sma1303,
1122 ret += sma1303_regmap_update_bits(sma1303,
1130 ret += sma1303_regmap_update_bits(sma1303,
1139 ret += sma1303_regmap_update_bits(sma1303,
1144 ret += sma1303_regmap_update_bits(sma1303,
1173 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
1188 sma1303->sys_clk_id = clk_id;
1195 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
1204 ret += sma1303_regmap_update_bits(sma1303,
1213 if (!sma1303->force_mute_status) {
1216 ret += sma1303_regmap_update_bits(sma1303,
1222 dev_dbg(sma1303->dev,
1236 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
1244 ret += sma1303_regmap_update_bits(sma1303,
1254 ret += sma1303_regmap_update_bits(sma1303,
1274 sma1303->format = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
1287 ret += sma1303_regmap_update_bits(sma1303,
1296 ret += sma1303_regmap_update_bits(sma1303,
1305 ret += sma1303_regmap_update_bits(sma1303,
1331 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
1337 sma1303->frame_size = slot_width * slots;
1339 ret += sma1303_regmap_update_bits(sma1303,
1347 ret += sma1303_regmap_update_bits(sma1303,
1354 ret += sma1303_regmap_update_bits(sma1303,
1368 ret += sma1303_regmap_update_bits(sma1303,
1375 ret += sma1303_regmap_update_bits(sma1303,
1387 if (sma1303->tdm_slot_rx < slots)
1388 ret += sma1303_regmap_update_bits(sma1303,
1391 (sma1303->tdm_slot_rx) << 3,
1395 __func__, sma1303->tdm_slot_rx);
1397 ret += sma1303_regmap_update_bits(sma1303,
1403 ret += sma1303_regmap_update_bits(sma1303,
1409 if (sma1303->tdm_slot_tx < slots)
1410 ret += sma1303_regmap_update_bits(sma1303,
1413 (sma1303->tdm_slot_tx) << 3,
1417 __func__, sma1303->tdm_slot_tx);
1438 .name = "sma1303-amplifier",
1460 struct sma1303_priv *sma1303 =
1465 if (sma1303->tsdw_cnt)
1466 ret = sma1303_regmap_read(sma1303,
1467 SMA1303_0A_SPK_VOL, &sma1303->cur_vol);
1469 ret = sma1303_regmap_read(sma1303,
1470 SMA1303_0A_SPK_VOL, &sma1303->init_vol);
1473 dev_err(sma1303->dev,
1478 ret = sma1303_regmap_read(sma1303, SMA1303_FA_STATUS1, &over_temp);
1480 dev_err(sma1303->dev,
1485 ret = sma1303_regmap_read(sma1303, SMA1303_FB_STATUS2, &ocp_val);
1487 dev_err(sma1303->dev,
1492 ret = sma1303_regmap_read(sma1303, SMA1303_FF_DEVICE_INDEX, &uvlo_val);
1494 dev_err(sma1303->dev,
1500 dev_crit(sma1303->dev,
1503 if ((sma1303->cur_vol + 6) <= 0xFF)
1504 sma1303_regmap_write(sma1303,
1505 SMA1303_0A_SPK_VOL, sma1303->cur_vol + 6);
1507 sma1303->tsdw_cnt++;
1508 } else if (sma1303->tsdw_cnt) {
1509 sma1303_regmap_write(sma1303,
1510 SMA1303_0A_SPK_VOL, sma1303->init_vol);
1511 sma1303->tsdw_cnt = 0;
1512 sma1303->cur_vol = sma1303->init_vol;
1516 dev_crit(sma1303->dev,
1520 dev_crit(sma1303->dev,
1524 dev_crit(sma1303->dev,
1527 if ((ocp_val & SMA1303_CLK_MON_STATUS) && (sma1303->amp_power_status)) {
1528 dev_crit(sma1303->dev,
1532 dev_crit(sma1303->dev,
1536 if ((over_temp != sma1303->last_over_temp) ||
1537 (ocp_val != sma1303->last_ocp_val)) {
1539 dev_crit(sma1303->dev, "Please check AMP status");
1540 dev_dbg(sma1303->dev, "STATUS1=0x%02X : STATUS2=0x%02X\n",
1542 sma1303->last_over_temp = over_temp;
1543 sma1303->last_ocp_val = ocp_val;
1546 if (sma1303->check_fault_status) {
1547 if (sma1303->check_fault_period > 0)
1549 &sma1303->check_fault_work,
1550 sma1303->check_fault_period * HZ);
1553 &sma1303->check_fault_work,
1578 struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component);
1580 cancel_delayed_work_sync(&sma1303->check_fault_work);
1611 struct sma1303_priv *sma1303 = dev_get_drvdata(dev);
1613 return sysfs_emit(buf, "%ld\n", sma1303->check_fault_period);
1619 struct sma1303_priv *sma1303 = dev_get_drvdata(dev);
1622 ret = kstrtol(buf, 10, &sma1303->check_fault_period);
1635 struct sma1303_priv *sma1303 = dev_get_drvdata(dev);
1637 return sysfs_emit(buf, "%ld\n", sma1303->check_fault_status);
1643 struct sma1303_priv *sma1303 = dev_get_drvdata(dev);
1646 ret = kstrtol(buf, 10, &sma1303->check_fault_status);
1651 if (sma1303->check_fault_status) {
1652 if (sma1303->check_fault_period > 0)
1654 &sma1303->check_fault_work,
1655 sma1303->check_fault_period * HZ);
1658 &sma1303->check_fault_work,
1679 struct sma1303_priv *sma1303;
1683 sma1303 = devm_kzalloc(&client->dev,
1685 if (!sma1303)
1687 sma1303->dev = &client->dev;
1689 sma1303->regmap = devm_regmap_init_i2c(client, &sma_i2c_regmap);
1690 if (IS_ERR(sma1303->regmap)) {
1691 ret = PTR_ERR(sma1303->regmap);
1698 ret = sma1303_regmap_read(sma1303,
1707 ret += sma1303_regmap_update_bits(sma1303,
1712 ret += sma1303_regmap_read(sma1303, SMA1303_FF_DEVICE_INDEX, &status);
1713 sma1303->rev_num = status & SMA1303_REV_NUM_STATUS;
1714 if (sma1303->rev_num == SMA1303_REV_NUM_TV0)
1716 else if (sma1303->rev_num == SMA1303_REV_NUM_TV1)
1719 ret += sma1303_regmap_read(sma1303, SMA1303_FB_STATUS2, &otp_stat);
1725 if (((sma1303->rev_num == SMA1303_REV_NUM_TV0) &&
1727 ((sma1303->rev_num != SMA1303_REV_NUM_TV0) &&
1734 ret += sma1303_regmap_write(sma1303,
1738 sma1303->amp_mode = SMA1303_MONO;
1739 sma1303->amp_power_status = false;
1740 sma1303->check_fault_period = CHECK_PERIOD_TIME;
1741 sma1303->check_fault_status = true;
1742 sma1303->force_mute_status = false;
1743 sma1303->init_vol = 0x31;
1744 sma1303->cur_vol = sma1303->init_vol;
1745 sma1303->last_bclk = 0;
1746 sma1303->last_ocp_val = 0x08;
1747 sma1303->last_over_temp = 0xC0;
1748 sma1303->tsdw_cnt = 0;
1749 sma1303->retry_cnt = SMA1303_I2C_RETRY_COUNT;
1750 sma1303->tdm_slot_rx = 0;
1751 sma1303->tdm_slot_tx = 0;
1752 sma1303->sys_clk_id = SMA1303_PLL_CLKIN_BCLK;
1754 sma1303->dev = &client->dev;
1755 sma1303->kobj = &client->dev.kobj;
1757 INIT_DELAYED_WORK(&sma1303->check_fault_work,
1760 i2c_set_clientdata(client, sma1303);
1762 sma1303->pll_matches = sma1303_pll_matches;
1763 sma1303->num_of_pll_matches =
1774 sma1303->attr_grp = &sma1303_attr_group;
1775 ret = sysfs_create_group(sma1303->kobj, sma1303->attr_grp);
1779 sma1303->attr_grp = NULL;
1787 struct sma1303_priv *sma1303 =
1790 cancel_delayed_work_sync(&sma1303->check_fault_work);
1794 {"sma1303"},
1800 { .compatible = "irondevice,sma1303", },
1807 .name = "sma1303",