mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
ASoC: mt8188-mt6359: Cleanups
Merge series from AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>: This series performs some cleanups to the mt8188-mt6359 driver, including usage of bitfield macros, adding definitions of register fields and some others for readability and consistency.
This commit is contained in:
commit
08e6c4bb17
1 changed files with 45 additions and 42 deletions
|
@ -6,6 +6,7 @@
|
|||
* Author: Trevor Wu <trevor.wu@mediatek.com>
|
||||
*/
|
||||
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of_device.h>
|
||||
|
@ -19,6 +20,15 @@
|
|||
#include "../common/mtk-afe-platform-driver.h"
|
||||
#include "../common/mtk-soundcard-driver.h"
|
||||
|
||||
#define CKSYS_AUD_TOP_CFG 0x032c
|
||||
#define RG_TEST_ON BIT(0)
|
||||
#define RG_TEST_TYPE BIT(2)
|
||||
#define CKSYS_AUD_TOP_MON 0x0330
|
||||
#define TEST_MISO_COUNT_1 GENMASK(3, 0)
|
||||
#define TEST_MISO_COUNT_2 GENMASK(7, 4)
|
||||
#define TEST_MISO_DONE_1 BIT(28)
|
||||
#define TEST_MISO_DONE_2 BIT(29)
|
||||
|
||||
#define NAU8825_HS_PRESENT BIT(0)
|
||||
|
||||
/*
|
||||
|
@ -251,9 +261,6 @@ static const struct snd_kcontrol_new mt8188_nau8825_controls[] = {
|
|||
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
|
||||
};
|
||||
|
||||
#define CKSYS_AUD_TOP_CFG 0x032c
|
||||
#define CKSYS_AUD_TOP_MON 0x0330
|
||||
|
||||
static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
struct snd_soc_component *cmpnt_afe =
|
||||
|
@ -265,13 +272,13 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
|||
struct mtkaif_param *param;
|
||||
int chosen_phase_1, chosen_phase_2;
|
||||
int prev_cycle_1, prev_cycle_2;
|
||||
int test_done_1, test_done_2;
|
||||
u8 test_done_1, test_done_2;
|
||||
int cycle_1, cycle_2;
|
||||
int mtkaif_chosen_phase[MT8188_MTKAIF_MISO_NUM];
|
||||
int mtkaif_phase_cycle[MT8188_MTKAIF_MISO_NUM];
|
||||
int mtkaif_calibration_num_phase;
|
||||
bool mtkaif_calibration_ok;
|
||||
unsigned int monitor = 0;
|
||||
u32 monitor = 0;
|
||||
int counter;
|
||||
int phase;
|
||||
int i;
|
||||
|
@ -303,8 +310,7 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
|||
mt6359_mtkaif_calibration_enable(cmpnt_codec);
|
||||
|
||||
/* set test type to synchronizer pulse */
|
||||
regmap_update_bits(afe_priv->topckgen,
|
||||
CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
|
||||
regmap_write(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_TYPE);
|
||||
mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */
|
||||
mtkaif_calibration_ok = true;
|
||||
|
||||
|
@ -314,7 +320,7 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
|||
mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
|
||||
phase, phase, phase);
|
||||
|
||||
regmap_set_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, 0x1);
|
||||
regmap_set_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON);
|
||||
|
||||
test_done_1 = 0;
|
||||
test_done_2 = 0;
|
||||
|
@ -326,20 +332,19 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
|||
while (!(test_done_1 & test_done_2)) {
|
||||
regmap_read(afe_priv->topckgen,
|
||||
CKSYS_AUD_TOP_MON, &monitor);
|
||||
test_done_1 = (monitor >> 28) & 0x1;
|
||||
test_done_2 = (monitor >> 29) & 0x1;
|
||||
test_done_1 = FIELD_GET(TEST_MISO_DONE_1, monitor);
|
||||
test_done_2 = FIELD_GET(TEST_MISO_DONE_2, monitor);
|
||||
|
||||
if (test_done_1 == 1)
|
||||
cycle_1 = monitor & 0xf;
|
||||
cycle_1 = FIELD_GET(TEST_MISO_COUNT_1, monitor);
|
||||
|
||||
if (test_done_2 == 1)
|
||||
cycle_2 = (monitor >> 4) & 0xf;
|
||||
cycle_2 = FIELD_GET(TEST_MISO_COUNT_2, monitor);
|
||||
|
||||
/* handle if never test done */
|
||||
if (++counter > 10000) {
|
||||
dev_info(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, monitor 0x%x\n",
|
||||
__func__,
|
||||
cycle_1, cycle_2, monitor);
|
||||
dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, monitor 0x%x\n",
|
||||
__func__, cycle_1, cycle_2, monitor);
|
||||
mtkaif_calibration_ok = false;
|
||||
break;
|
||||
}
|
||||
|
@ -362,7 +367,7 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
|||
mtkaif_phase_cycle[MT8188_MTKAIF_MISO_1] = prev_cycle_2;
|
||||
}
|
||||
|
||||
regmap_clear_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, 0x1);
|
||||
regmap_clear_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON);
|
||||
|
||||
if (mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] >= 0 &&
|
||||
mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] >= 0)
|
||||
|
@ -398,8 +403,8 @@ static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
|
|||
for (i = 0; i < MT8188_MTKAIF_MISO_NUM; i++)
|
||||
param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i];
|
||||
|
||||
dev_info(afe->dev, "%s(), end, calibration ok %d\n",
|
||||
__func__, param->mtkaif_calibration_ok);
|
||||
dev_dbg(afe->dev, "%s(), end, calibration ok %d\n",
|
||||
__func__, param->mtkaif_calibration_ok);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -486,16 +491,18 @@ static int mt8188_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd)
|
|||
mt8188_hdmi_jack_pins,
|
||||
ARRAY_SIZE(mt8188_hdmi_jack_pins));
|
||||
if (ret) {
|
||||
dev_info(rtd->dev, "%s, new jack failed: %d\n", __func__, ret);
|
||||
dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = snd_soc_component_set_jack(component, &priv->hdmi_jack, NULL);
|
||||
if (ret)
|
||||
dev_info(rtd->dev, "%s, set jack failed on %s (ret=%d)\n",
|
||||
__func__, component->name, ret);
|
||||
if (ret) {
|
||||
dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n",
|
||||
__func__, component->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
|
@ -508,16 +515,18 @@ static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime *rtd)
|
|||
&priv->dp_jack, mt8188_dp_jack_pins,
|
||||
ARRAY_SIZE(mt8188_dp_jack_pins));
|
||||
if (ret) {
|
||||
dev_info(rtd->dev, "%s, new jack failed: %d\n", __func__, ret);
|
||||
dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = snd_soc_component_set_jack(component, &priv->dp_jack, NULL);
|
||||
if (ret)
|
||||
dev_info(rtd->dev, "%s, set jack failed on %s (ret=%d)\n",
|
||||
__func__, component->name, ret);
|
||||
if (ret) {
|
||||
dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n",
|
||||
__func__, component->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mt8188_dumb_amp_init(struct snd_soc_pcm_runtime *rtd)
|
||||
|
@ -539,7 +548,7 @@ static int mt8188_dumb_amp_init(struct snd_soc_pcm_runtime *rtd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mt8188_max98390_hw_params(struct snd_pcm_substream *substream,
|
||||
|
@ -594,7 +603,7 @@ static int mt8188_max98390_codec_init(struct snd_soc_pcm_runtime *rtd)
|
|||
}
|
||||
|
||||
if (rtd->dai_link->num_codecs <= 2)
|
||||
return ret;
|
||||
return 0;
|
||||
|
||||
/* add widgets/controls/dapm for rear speakers */
|
||||
ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_rear_spk_widgets,
|
||||
|
@ -612,7 +621,7 @@ static int mt8188_max98390_codec_init(struct snd_soc_pcm_runtime *rtd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
|
@ -660,7 +669,7 @@ static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
};
|
||||
|
||||
static void mt8188_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
|
||||
|
@ -697,7 +706,7 @@ static int mt8188_nau8825_hw_params(struct snd_pcm_substream *substream,
|
|||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_ops mt8188_nau8825_ops = {
|
||||
|
@ -1117,15 +1126,9 @@ static struct mt8188_card_data mt8188_nau8825_card = {
|
|||
};
|
||||
|
||||
static const struct of_device_id mt8188_mt6359_dt_match[] = {
|
||||
{
|
||||
.compatible = "mediatek,mt8188-mt6359-evb",
|
||||
.data = &mt8188_evb_card,
|
||||
},
|
||||
{
|
||||
.compatible = "mediatek,mt8188-nau8825",
|
||||
.data = &mt8188_nau8825_card,
|
||||
},
|
||||
{},
|
||||
{ .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, },
|
||||
{ .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, },
|
||||
{ /* sentinel */ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, mt8188_mt6359_dt_match);
|
||||
|
||||
|
|
Loading…
Reference in a new issue