Lines Matching +full:spk +full:- +full:mute

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 // sma1303.c -- sma1303 ALSA SoC Audio driver
236 static const DECLARE_TLV_DB_SCALE(sma1303_spk_tlv, -6000, 50, 0);
242 int cnt = sma1303->retry_cnt; in sma1303_regmap_write()
244 while (cnt--) { in sma1303_regmap_write()
245 ret = regmap_write(sma1303->regmap, reg, val); in sma1303_regmap_write()
247 dev_err(sma1303->dev, in sma1303_regmap_write()
259 int cnt = sma1303->retry_cnt; in sma1303_regmap_update_bits()
261 while (cnt--) { in sma1303_regmap_update_bits()
262 ret = regmap_update_bits_check(sma1303->regmap, reg, in sma1303_regmap_update_bits()
265 dev_err(sma1303->dev, in sma1303_regmap_update_bits()
277 int cnt = sma1303->retry_cnt; in sma1303_regmap_read()
279 while (cnt--) { in sma1303_regmap_read()
280 ret = regmap_read(sma1303->regmap, reg, val); in sma1303_regmap_read()
282 dev_err(sma1303->dev, in sma1303_regmap_read()
316 ucontrol->value.integer.value[0] = (int)sma1303->force_mute_status; in sma1303_force_mute_get()
317 dev_dbg(sma1303->dev, "%s : Force Mute %s\n", __func__, in sma1303_force_mute_get()
318 sma1303->force_mute_status ? "ON" : "OFF"); in sma1303_force_mute_get()
329 bool change = false, val = (bool)ucontrol->value.integer.value[0]; in sma1303_force_mute_put()
331 if (sma1303->force_mute_status == val) in sma1303_force_mute_put()
335 sma1303->force_mute_status = val; in sma1303_force_mute_put()
337 dev_dbg(sma1303->dev, "%s : Force Mute %s\n", __func__, in sma1303_force_mute_put()
338 sma1303->force_mute_status ? "ON" : "OFF"); in sma1303_force_mute_put()
353 return -EINVAL; in sma1303_postscaler_get()
355 ucontrol->value.integer.value[0] = (val & 0x7E) >> 1; in sma1303_postscaler_get()
366 int ret, val = (int)ucontrol->value.integer.value[0]; in sma1303_postscaler_put()
372 return -EINVAL; in sma1303_postscaler_put()
387 return -EINVAL; in sma1303_tdm_slot_rx_get()
389 ucontrol->value.integer.value[0] = (val & 0x38) >> 3; in sma1303_tdm_slot_rx_get()
390 sma1303->tdm_slot_rx = ucontrol->value.integer.value[0]; in sma1303_tdm_slot_rx_get()
401 int ret, val = (int)ucontrol->value.integer.value[0]; in sma1303_tdm_slot_rx_put()
407 return -EINVAL; in sma1303_tdm_slot_rx_put()
422 return -EINVAL; in sma1303_tdm_slot_tx_get()
424 ucontrol->value.integer.value[0] = (val & 0x38) >> 3; in sma1303_tdm_slot_tx_get()
425 sma1303->tdm_slot_tx = ucontrol->value.integer.value[0]; in sma1303_tdm_slot_tx_get()
436 int ret, val = (int)ucontrol->value.integer.value[0]; in sma1303_tdm_slot_tx_put()
442 return -EINVAL; in sma1303_tdm_slot_tx_put()
462 if (sma1303->amp_mode == SMA1303_MONO) { in sma1303_startup()
481 if (sma1303->check_fault_status) { in sma1303_startup()
482 if (sma1303->check_fault_period > 0) in sma1303_startup()
484 &sma1303->check_fault_work, in sma1303_startup()
485 sma1303->check_fault_period * HZ); in sma1303_startup()
488 &sma1303->check_fault_work, in sma1303_startup()
492 sma1303->amp_power_status = true; in sma1303_startup()
502 cancel_delayed_work_sync(&sma1303->check_fault_work); in sma1303_shutdown()
518 sma1303->amp_power_status = false; in sma1303_shutdown()
527 snd_soc_dapm_to_component(w->dapm); in sma1303_aif_in_event()
529 unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]); in sma1303_aif_in_event()
542 sma1303->amp_mode = SMA1303_MONO; in sma1303_aif_in_event()
559 sma1303->amp_mode = SMA1303_STEREO; in sma1303_aif_in_event()
576 sma1303->amp_mode = SMA1303_STEREO; in sma1303_aif_in_event()
579 dev_err(sma1303->dev, "%s : Invalid value (%d)\n", in sma1303_aif_in_event()
581 return -EINVAL; in sma1303_aif_in_event()
584 dev_dbg(sma1303->dev, "%s : Source : %s\n", __func__, in sma1303_aif_in_event()
589 return -EINVAL; in sma1303_aif_in_event()
597 snd_soc_dapm_to_component(w->dapm); in sma1303_aif_out_event()
599 unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]); in sma1303_aif_out_event()
719 dev_err(sma1303->dev, "%s : Invalid value (%d)\n", in sma1303_aif_out_event()
721 return -EINVAL; in sma1303_aif_out_event()
724 dev_dbg(sma1303->dev, "%s : Source : %s\n", __func__, in sma1303_aif_out_event()
729 return -EINVAL; in sma1303_aif_out_event()
737 snd_soc_dapm_to_component(w->dapm); in sma1303_sdo_event()
744 dev_dbg(sma1303->dev, in sma1303_sdo_event()
762 dev_dbg(sma1303->dev, in sma1303_sdo_event()
781 return -EINVAL; in sma1303_sdo_event()
789 snd_soc_dapm_to_component(w->dapm); in sma1303_post_scaler_event()
796 dev_dbg(sma1303->dev, in sma1303_post_scaler_event()
805 dev_dbg(sma1303->dev, in sma1303_post_scaler_event()
815 return -EINVAL; in sma1303_post_scaler_event()
823 snd_soc_dapm_to_component(w->dapm); in sma1303_power_event()
829 dev_dbg(sma1303->dev, in sma1303_power_event()
834 dev_dbg(sma1303->dev, in sma1303_power_event()
856 SOC_SINGLE_BOOL_EXT("Force Mute Switch", 0,
868 SND_SOC_DAPM_OUTPUT("SPK"),
923 {"SPK", NULL, "AMP Enable"},
936 dev_dbg(component->dev, "%s : BCLK = %dHz\n", in sma1303_setup_pll()
939 if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_MCLK) { in sma1303_setup_pll()
940 dev_dbg(component->dev, "%s : MCLK is not supported\n", in sma1303_setup_pll()
942 } else if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) { in sma1303_setup_pll()
943 for (i = 0; i < sma1303->num_of_pll_matches; i++) { in sma1303_setup_pll()
944 if (sma1303->pll_matches[i].input_clk == bclk) in sma1303_setup_pll()
947 if (i == sma1303->num_of_pll_matches) { in sma1303_setup_pll()
948 dev_dbg(component->dev, "%s : No matching value between pll table and SCK\n", in sma1303_setup_pll()
950 return -EINVAL; in sma1303_setup_pll()
962 sma1303->pll_matches[i].post_n); in sma1303_setup_pll()
966 sma1303->pll_matches[i].n); in sma1303_setup_pll()
970 sma1303->pll_matches[i].vco); in sma1303_setup_pll()
974 sma1303->pll_matches[i].p_cp); in sma1303_setup_pll()
976 return -EINVAL; in sma1303_setup_pll()
984 struct snd_soc_component *component = dai->component; in sma1303_dai_hw_params_amp()
989 if (sma1303->format == SND_SOC_DAIFMT_DSP_A) in sma1303_dai_hw_params_amp()
990 bclk = params_rate(params) * sma1303->frame_size; in sma1303_dai_hw_params_amp()
995 dev_dbg(component->dev, in sma1303_dai_hw_params_amp()
1000 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in sma1303_dai_hw_params_amp()
1001 if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) { in sma1303_dai_hw_params_amp()
1002 if (sma1303->last_bclk != bclk) { in sma1303_dai_hw_params_amp()
1004 sma1303->last_bclk = bclk; in sma1303_dai_hw_params_amp()
1045 dev_err(component->dev, "%s not support rate : %d\n", in sma1303_dai_hw_params_amp()
1048 return -EINVAL; in sma1303_dai_hw_params_amp()
1056 dev_dbg(component->dev, in sma1303_dai_hw_params_amp()
1067 dev_dbg(component->dev, in sma1303_dai_hw_params_amp()
1077 dev_dbg(component->dev, in sma1303_dai_hw_params_amp()
1087 dev_err(component->dev, in sma1303_dai_hw_params_amp()
1090 return -EINVAL; in sma1303_dai_hw_params_amp()
1094 switch (sma1303->format) { in sma1303_dai_hw_params_amp()
1158 dev_err(component->dev, in sma1303_dai_hw_params_amp()
1161 return -EINVAL; in sma1303_dai_hw_params_amp()
1164 return -EINVAL; in sma1303_dai_hw_params_amp()
1172 struct snd_soc_component *component = dai->component; in sma1303_dai_set_sysclk_amp()
1185 dev_err(component->dev, "Invalid clk id: %d\n", clk_id); in sma1303_dai_set_sysclk_amp()
1186 return -EINVAL; in sma1303_dai_set_sysclk_amp()
1188 sma1303->sys_clk_id = clk_id; in sma1303_dai_set_sysclk_amp()
1192 static int sma1303_dai_mute(struct snd_soc_dai *dai, int mute, int stream) in sma1303_dai_mute() argument
1194 struct snd_soc_component *component = dai->component; in sma1303_dai_mute()
1201 if (mute) { in sma1303_dai_mute()
1202 dev_dbg(component->dev, "%s : %s\n", __func__, "MUTE"); in sma1303_dai_mute()
1210 /* Need to wait time for mute slope */ in sma1303_dai_mute()
1213 if (!sma1303->force_mute_status) { in sma1303_dai_mute()
1214 dev_dbg(component->dev, "%s : %s\n", in sma1303_dai_mute()
1222 dev_dbg(sma1303->dev, in sma1303_dai_mute()
1223 "%s : FORCE MUTE!!!\n", __func__); in sma1303_dai_mute()
1228 return -EINVAL; in sma1303_dai_mute()
1235 struct snd_soc_component *component = dai->component; in sma1303_dai_set_fmt_amp()
1242 dev_dbg(component->dev, in sma1303_dai_set_fmt_amp()
1252 dev_dbg(component->dev, in sma1303_dai_set_fmt_amp()
1262 dev_err(component->dev, in sma1303_dai_set_fmt_amp()
1264 return -EINVAL; in sma1303_dai_set_fmt_amp()
1274 sma1303->format = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in sma1303_dai_set_fmt_amp()
1277 dev_err(component->dev, in sma1303_dai_set_fmt_amp()
1279 return -EINVAL; in sma1303_dai_set_fmt_amp()
1285 dev_dbg(component->dev, "%s : %s\n", in sma1303_dai_set_fmt_amp()
1294 dev_dbg(component->dev, "%s : %s\n", in sma1303_dai_set_fmt_amp()
1303 dev_dbg(component->dev, "%s : %s\n", in sma1303_dai_set_fmt_amp()
1312 dev_dbg(component->dev, "%s : %s\n", in sma1303_dai_set_fmt_amp()
1316 dev_err(component->dev, in sma1303_dai_set_fmt_amp()
1318 return -EINVAL; in sma1303_dai_set_fmt_amp()
1322 return -EINVAL; in sma1303_dai_set_fmt_amp()
1330 struct snd_soc_component *component = dai->component; in sma1303_dai_set_tdm_slot()
1334 dev_dbg(component->dev, "%s : slots = %d, slot_width - %d\n", in sma1303_dai_set_tdm_slot()
1337 sma1303->frame_size = slot_width * slots; in sma1303_dai_set_tdm_slot()
1361 dev_err(component->dev, "%s not support TDM %d slot_width\n", in sma1303_dai_set_tdm_slot()
1382 dev_err(component->dev, "%s not support TDM %d slots\n", in sma1303_dai_set_tdm_slot()
1387 if (sma1303->tdm_slot_rx < slots) in sma1303_dai_set_tdm_slot()
1391 (sma1303->tdm_slot_rx) << 3, in sma1303_dai_set_tdm_slot()
1394 dev_err(component->dev, "%s Incorrect tdm-slot-rx %d set\n", in sma1303_dai_set_tdm_slot()
1395 __func__, sma1303->tdm_slot_rx); in sma1303_dai_set_tdm_slot()
1409 if (sma1303->tdm_slot_tx < slots) in sma1303_dai_set_tdm_slot()
1413 (sma1303->tdm_slot_tx) << 3, in sma1303_dai_set_tdm_slot()
1416 dev_err(component->dev, "%s Incorrect tdm-slot-tx %d set\n", in sma1303_dai_set_tdm_slot()
1417 __func__, sma1303->tdm_slot_tx); in sma1303_dai_set_tdm_slot()
1420 return -EINVAL; in sma1303_dai_set_tdm_slot()
1438 .name = "sma1303-amplifier",
1465 if (sma1303->tsdw_cnt) in sma1303_check_fault_worker()
1467 SMA1303_0A_SPK_VOL, &sma1303->cur_vol); in sma1303_check_fault_worker()
1470 SMA1303_0A_SPK_VOL, &sma1303->init_vol); in sma1303_check_fault_worker()
1473 dev_err(sma1303->dev, in sma1303_check_fault_worker()
1480 dev_err(sma1303->dev, in sma1303_check_fault_worker()
1487 dev_err(sma1303->dev, in sma1303_check_fault_worker()
1494 dev_err(sma1303->dev, in sma1303_check_fault_worker()
1500 dev_crit(sma1303->dev, in sma1303_check_fault_worker()
1503 if ((sma1303->cur_vol + 6) <= 0xFF) in sma1303_check_fault_worker()
1505 SMA1303_0A_SPK_VOL, sma1303->cur_vol + 6); in sma1303_check_fault_worker()
1507 sma1303->tsdw_cnt++; in sma1303_check_fault_worker()
1508 } else if (sma1303->tsdw_cnt) { in sma1303_check_fault_worker()
1510 SMA1303_0A_SPK_VOL, sma1303->init_vol); in sma1303_check_fault_worker()
1511 sma1303->tsdw_cnt = 0; in sma1303_check_fault_worker()
1512 sma1303->cur_vol = sma1303->init_vol; in sma1303_check_fault_worker()
1516 dev_crit(sma1303->dev, in sma1303_check_fault_worker()
1520 dev_crit(sma1303->dev, in sma1303_check_fault_worker()
1521 "%s : OCP_SPK(Over Current Protect SPK)\n", __func__); in sma1303_check_fault_worker()
1524 dev_crit(sma1303->dev, in sma1303_check_fault_worker()
1527 if ((ocp_val & SMA1303_CLK_MON_STATUS) && (sma1303->amp_power_status)) { in sma1303_check_fault_worker()
1528 dev_crit(sma1303->dev, in sma1303_check_fault_worker()
1532 dev_crit(sma1303->dev, in sma1303_check_fault_worker()
1536 if ((over_temp != sma1303->last_over_temp) || in sma1303_check_fault_worker()
1537 (ocp_val != sma1303->last_ocp_val)) { in sma1303_check_fault_worker()
1539 dev_crit(sma1303->dev, "Please check AMP status"); in sma1303_check_fault_worker()
1540 dev_dbg(sma1303->dev, "STATUS1=0x%02X : STATUS2=0x%02X\n", in sma1303_check_fault_worker()
1542 sma1303->last_over_temp = over_temp; in sma1303_check_fault_worker()
1543 sma1303->last_ocp_val = ocp_val; in sma1303_check_fault_worker()
1546 if (sma1303->check_fault_status) { in sma1303_check_fault_worker()
1547 if (sma1303->check_fault_period > 0) in sma1303_check_fault_worker()
1549 &sma1303->check_fault_work, in sma1303_check_fault_worker()
1550 sma1303->check_fault_period * HZ); in sma1303_check_fault_worker()
1553 &sma1303->check_fault_work, in sma1303_check_fault_worker()
1580 cancel_delayed_work_sync(&sma1303->check_fault_work); in sma1303_remove()
1613 return sysfs_emit(buf, "%ld\n", sma1303->check_fault_period); in check_fault_period_show()
1622 ret = kstrtol(buf, 10, &sma1303->check_fault_period); in check_fault_period_store()
1625 return -EINVAL; in check_fault_period_store()
1637 return sysfs_emit(buf, "%ld\n", sma1303->check_fault_status); in check_fault_status_show()
1646 ret = kstrtol(buf, 10, &sma1303->check_fault_status); in check_fault_status_store()
1649 return -EINVAL; in check_fault_status_store()
1651 if (sma1303->check_fault_status) { in check_fault_status_store()
1652 if (sma1303->check_fault_period > 0) in check_fault_status_store()
1654 &sma1303->check_fault_work, in check_fault_status_store()
1655 sma1303->check_fault_period * HZ); in check_fault_status_store()
1658 &sma1303->check_fault_work, in check_fault_status_store()
1683 sma1303 = devm_kzalloc(&client->dev, in sma1303_i2c_probe()
1686 return -ENOMEM; in sma1303_i2c_probe()
1687 sma1303->dev = &client->dev; in sma1303_i2c_probe()
1689 sma1303->regmap = devm_regmap_init_i2c(client, &sma_i2c_regmap); in sma1303_i2c_probe()
1690 if (IS_ERR(sma1303->regmap)) { in sma1303_i2c_probe()
1691 ret = PTR_ERR(sma1303->regmap); in sma1303_i2c_probe()
1692 dev_err(&client->dev, in sma1303_i2c_probe()
1702 dev_err(&client->dev, "device initialization error (%d 0x%02X)", in sma1303_i2c_probe()
1705 dev_dbg(&client->dev, "chip version 0x%02X\n", device_info); in sma1303_i2c_probe()
1713 sma1303->rev_num = status & SMA1303_REV_NUM_STATUS; in sma1303_i2c_probe()
1714 if (sma1303->rev_num == SMA1303_REV_NUM_TV0) in sma1303_i2c_probe()
1715 dev_dbg(&client->dev, "SMA1303 Trimming Version 0\n"); in sma1303_i2c_probe()
1716 else if (sma1303->rev_num == SMA1303_REV_NUM_TV1) in sma1303_i2c_probe()
1717 dev_dbg(&client->dev, "SMA1303 Trimming Version 1\n"); in sma1303_i2c_probe()
1721 dev_err(&client->dev, in sma1303_i2c_probe()
1725 if (((sma1303->rev_num == SMA1303_REV_NUM_TV0) && in sma1303_i2c_probe()
1727 ((sma1303->rev_num != SMA1303_REV_NUM_TV0) && in sma1303_i2c_probe()
1729 dev_dbg(&client->dev, "SMA1303 OTP Status Successful\n"); in sma1303_i2c_probe()
1731 dev_dbg(&client->dev, "SMA1303 OTP Status Fail\n"); in sma1303_i2c_probe()
1738 sma1303->amp_mode = SMA1303_MONO; in sma1303_i2c_probe()
1739 sma1303->amp_power_status = false; in sma1303_i2c_probe()
1740 sma1303->check_fault_period = CHECK_PERIOD_TIME; in sma1303_i2c_probe()
1741 sma1303->check_fault_status = true; in sma1303_i2c_probe()
1742 sma1303->force_mute_status = false; in sma1303_i2c_probe()
1743 sma1303->init_vol = 0x31; in sma1303_i2c_probe()
1744 sma1303->cur_vol = sma1303->init_vol; in sma1303_i2c_probe()
1745 sma1303->last_bclk = 0; in sma1303_i2c_probe()
1746 sma1303->last_ocp_val = 0x08; in sma1303_i2c_probe()
1747 sma1303->last_over_temp = 0xC0; in sma1303_i2c_probe()
1748 sma1303->tsdw_cnt = 0; in sma1303_i2c_probe()
1749 sma1303->retry_cnt = SMA1303_I2C_RETRY_COUNT; in sma1303_i2c_probe()
1750 sma1303->tdm_slot_rx = 0; in sma1303_i2c_probe()
1751 sma1303->tdm_slot_tx = 0; in sma1303_i2c_probe()
1752 sma1303->sys_clk_id = SMA1303_PLL_CLKIN_BCLK; in sma1303_i2c_probe()
1754 sma1303->dev = &client->dev; in sma1303_i2c_probe()
1755 sma1303->kobj = &client->dev.kobj; in sma1303_i2c_probe()
1757 INIT_DELAYED_WORK(&sma1303->check_fault_work, in sma1303_i2c_probe()
1762 sma1303->pll_matches = sma1303_pll_matches; in sma1303_i2c_probe()
1763 sma1303->num_of_pll_matches = in sma1303_i2c_probe()
1766 ret = devm_snd_soc_register_component(&client->dev, in sma1303_i2c_probe()
1769 dev_err(&client->dev, "Failed to register component"); in sma1303_i2c_probe()
1774 sma1303->attr_grp = &sma1303_attr_group; in sma1303_i2c_probe()
1775 ret = sysfs_create_group(sma1303->kobj, sma1303->attr_grp); in sma1303_i2c_probe()
1777 dev_err(&client->dev, in sma1303_i2c_probe()
1779 sma1303->attr_grp = NULL; in sma1303_i2c_probe()
1790 cancel_delayed_work_sync(&sma1303->check_fault_work); in sma1303_i2c_remove()