Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: SMA1303: Convert the TDM slot properties in devicetree to mixer

It seems correct that the user changes the TDM slot needed after
device probe.

Signed-off-by: Kiseok Jo <kiseok.jo@irondevice.com>
Link: https://lore.kernel.org/r/20230208092420.5037-6-kiseok.jo@irondevice.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kiseok Jo and committed by
Mark Brown
1f5ffd57 1edc70c3

+82 -18
+82 -18
sound/soc/codecs/sma1303.c
··· 292 292 static const char * const sma1303_aif_out_source_text[] = { 293 293 "Disable", "After_FmtC", "After_Mixer", "After_DSP", "After_Post", 294 294 "Clk_PLL", "Clk_OSC"}; 295 + static const char * const sma1303_tdm_slot_text[] = { 296 + "Slot0", "Slot1", "Slot2", "Slot3", 297 + "Slot4", "Slot5", "Slot6", "Slot7"}; 295 298 296 299 static const struct soc_enum sma1303_aif_in_source_enum = 297 300 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1303_aif_in_source_text), ··· 302 299 static const struct soc_enum sma1303_aif_out_source_enum = 303 300 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1303_aif_out_source_text), 304 301 sma1303_aif_out_source_text); 302 + static const struct soc_enum sma1303_tdm_slot_enum = 303 + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sma1303_tdm_slot_text), 304 + sma1303_tdm_slot_text); 305 305 306 306 static int sma1303_force_mute_get(struct snd_kcontrol *kcontrol, 307 307 struct snd_ctl_elem_value *ucontrol) ··· 368 362 369 363 ret = sma1303_regmap_update_bits(sma1303, 370 364 SMA1303_90_POSTSCALER, 0x7E, (val << 1), &change); 365 + if (ret < 0) 366 + return -EINVAL; 367 + 368 + return change; 369 + } 370 + 371 + static int sma1303_tdm_slot_rx_get(struct snd_kcontrol *kcontrol, 372 + struct snd_ctl_elem_value *ucontrol) 373 + { 374 + struct snd_soc_component *component = 375 + snd_soc_kcontrol_component(kcontrol); 376 + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); 377 + int val, ret; 378 + 379 + ret = sma1303_regmap_read(sma1303, SMA1303_A5_TDM1, &val); 380 + if (ret < 0) 381 + return -EINVAL; 382 + 383 + ucontrol->value.integer.value[0] = (val & 0x38) >> 3; 384 + sma1303->tdm_slot_rx = ucontrol->value.integer.value[0]; 385 + 386 + return 0; 387 + } 388 + 389 + static int sma1303_tdm_slot_rx_put(struct snd_kcontrol *kcontrol, 390 + struct snd_ctl_elem_value *ucontrol) 391 + { 392 + struct snd_soc_component *component = 393 + snd_soc_kcontrol_component(kcontrol); 394 + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); 395 + int ret, val = (int)ucontrol->value.integer.value[0]; 396 + bool change; 397 + 398 + ret = sma1303_regmap_update_bits(sma1303, 399 + SMA1303_A5_TDM1, 0x38, (val << 3), &change); 400 + if (ret < 0) 401 + return -EINVAL; 402 + 403 + return change; 404 + } 405 + 406 + static int sma1303_tdm_slot_tx_get(struct snd_kcontrol *kcontrol, 407 + struct snd_ctl_elem_value *ucontrol) 408 + { 409 + struct snd_soc_component *component = 410 + snd_soc_kcontrol_component(kcontrol); 411 + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); 412 + int val, ret; 413 + 414 + ret = sma1303_regmap_read(sma1303, SMA1303_A6_TDM2, &val); 415 + if (ret < 0) 416 + return -EINVAL; 417 + 418 + ucontrol->value.integer.value[0] = (val & 0x38) >> 3; 419 + sma1303->tdm_slot_tx = ucontrol->value.integer.value[0]; 420 + 421 + return 0; 422 + } 423 + 424 + static int sma1303_tdm_slot_tx_put(struct snd_kcontrol *kcontrol, 425 + struct snd_ctl_elem_value *ucontrol) 426 + { 427 + struct snd_soc_component *component = 428 + snd_soc_kcontrol_component(kcontrol); 429 + struct sma1303_priv *sma1303 = snd_soc_component_get_drvdata(component); 430 + int ret, val = (int)ucontrol->value.integer.value[0]; 431 + bool change; 432 + 433 + ret = sma1303_regmap_update_bits(sma1303, 434 + SMA1303_A6_TDM2, 0x38, (val << 3), &change); 371 435 if (ret < 0) 372 436 return -EINVAL; 373 437 ··· 857 781 sma1303_force_mute_get, sma1303_force_mute_put), 858 782 SOC_SINGLE_EXT("Postscaler Gain", SMA1303_90_POSTSCALER, 1, 0x30, 0, 859 783 sma1303_postscaler_get, sma1303_postscaler_put), 784 + SOC_ENUM_EXT("TDM RX Slot Position", sma1303_tdm_slot_enum, 785 + sma1303_tdm_slot_rx_get, sma1303_tdm_slot_rx_put), 786 + SOC_ENUM_EXT("TDM TX Slot Position", sma1303_tdm_slot_enum, 787 + sma1303_tdm_slot_tx_get, sma1303_tdm_slot_tx_put), 860 788 }; 861 789 862 790 static const struct snd_soc_dapm_widget sma1303_dapm_widgets[] = { ··· 1701 1621 } 1702 1622 1703 1623 if (np) { 1704 - if (!of_property_read_u32(np, "tdm-slot-rx", &value)) { 1705 - dev_dbg(&client->dev, 1706 - "tdm slot rx is '%d' from DT\n", value); 1707 - sma1303->tdm_slot_rx = value; 1708 - } else { 1709 - dev_dbg(&client->dev, 1710 - "Default setting of tdm slot rx is '0'\n"); 1711 - sma1303->tdm_slot_rx = 0; 1712 - } 1713 - if (!of_property_read_u32(np, "tdm-slot-tx", &value)) { 1714 - dev_dbg(&client->dev, 1715 - "tdm slot tx is '%u' from DT\n", value); 1716 - sma1303->tdm_slot_tx = value; 1717 - } else { 1718 - dev_dbg(&client->dev, 1719 - "Default setting of tdm slot tx is '0'\n"); 1720 - sma1303->tdm_slot_tx = 0; 1721 - } 1722 1624 if (!of_property_read_u32(np, "sys-clk-id", &value)) { 1723 1625 switch (value) { 1724 1626 case SMA1303_EXTERNAL_CLOCK_19_2: ··· 1781 1719 sma1303->last_over_temp = 0xC0; 1782 1720 sma1303->tsdw_cnt = 0; 1783 1721 sma1303->retry_cnt = SMA1303_I2C_RETRY_COUNT; 1722 + sma1303->tdm_slot_rx = 0; 1723 + sma1303->tdm_slot_tx = 0; 1784 1724 1785 1725 sma1303->dev = &client->dev; 1786 1726 sma1303->kobj = &client->dev.kobj;