rtq9128: Fix pm runtime and TDM usage
Merge series from cy_huang@richtek.com: This patch series fix rtq9128 pm_runtime and TDM usage.
This commit is contained in:
commit
15de2a2702
@ -59,6 +59,7 @@
|
|||||||
|
|
||||||
struct rtq9128_data {
|
struct rtq9128_data {
|
||||||
struct gpio_desc *enable;
|
struct gpio_desc *enable;
|
||||||
|
unsigned int daifmt;
|
||||||
int tdm_slots;
|
int tdm_slots;
|
||||||
int tdm_slot_width;
|
int tdm_slot_width;
|
||||||
bool tdm_input_data2_select;
|
bool tdm_input_data2_select;
|
||||||
@ -391,7 +392,11 @@ static int rtq9128_component_probe(struct snd_soc_component *comp)
|
|||||||
unsigned int val;
|
unsigned int val;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
pm_runtime_resume_and_get(comp->dev);
|
ret = pm_runtime_resume_and_get(comp->dev);
|
||||||
|
if (ret < 0) {
|
||||||
|
dev_err(comp->dev, "Failed to resume device (%d)\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
val = snd_soc_component_read(comp, RTQ9128_REG_EFUSE_DATA);
|
val = snd_soc_component_read(comp, RTQ9128_REG_EFUSE_DATA);
|
||||||
|
|
||||||
@ -437,10 +442,7 @@ static const struct snd_soc_component_driver rtq9128_comp_driver = {
|
|||||||
static int rtq9128_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
static int rtq9128_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
||||||
{
|
{
|
||||||
struct rtq9128_data *data = snd_soc_dai_get_drvdata(dai);
|
struct rtq9128_data *data = snd_soc_dai_get_drvdata(dai);
|
||||||
struct snd_soc_component *comp = dai->component;
|
|
||||||
struct device *dev = dai->dev;
|
struct device *dev = dai->dev;
|
||||||
unsigned int audfmt, fmtval;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
dev_dbg(dev, "%s: fmt 0x%8x\n", __func__, fmt);
|
dev_dbg(dev, "%s: fmt 0x%8x\n", __func__, fmt);
|
||||||
|
|
||||||
@ -450,35 +452,10 @@ static int rtq9128_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fmtval = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
|
/* Store here and will be used in runtime hw_params for DAI format setting */
|
||||||
if (data->tdm_slots && fmtval != SND_SOC_DAIFMT_DSP_A && fmtval != SND_SOC_DAIFMT_DSP_B) {
|
data->daifmt = fmt;
|
||||||
dev_err(dev, "TDM is used, format only support DSP_A or DSP_B\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (fmtval) {
|
return 0;
|
||||||
case SND_SOC_DAIFMT_I2S:
|
|
||||||
audfmt = 8;
|
|
||||||
break;
|
|
||||||
case SND_SOC_DAIFMT_LEFT_J:
|
|
||||||
audfmt = 9;
|
|
||||||
break;
|
|
||||||
case SND_SOC_DAIFMT_RIGHT_J:
|
|
||||||
audfmt = 10;
|
|
||||||
break;
|
|
||||||
case SND_SOC_DAIFMT_DSP_A:
|
|
||||||
audfmt = data->tdm_slots ? 12 : 11;
|
|
||||||
break;
|
|
||||||
case SND_SOC_DAIFMT_DSP_B:
|
|
||||||
audfmt = data->tdm_slots ? 4 : 3;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dev_err(dev, "Unsupported format 0x%8x\n", fmt);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDFMT_MASK, audfmt);
|
|
||||||
return ret < 0 ? ret : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtq9128_dai_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
|
static int rtq9128_dai_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
|
||||||
@ -554,10 +531,38 @@ static int rtq9128_dai_hw_params(struct snd_pcm_substream *stream, struct snd_pc
|
|||||||
unsigned int width, slot_width, bitrate, audbit, dolen;
|
unsigned int width, slot_width, bitrate, audbit, dolen;
|
||||||
struct snd_soc_component *comp = dai->component;
|
struct snd_soc_component *comp = dai->component;
|
||||||
struct device *dev = dai->dev;
|
struct device *dev = dai->dev;
|
||||||
|
unsigned int fmtval, audfmt;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dev_dbg(dev, "%s: width %d\n", __func__, params_width(param));
|
dev_dbg(dev, "%s: width %d\n", __func__, params_width(param));
|
||||||
|
|
||||||
|
fmtval = FIELD_GET(SND_SOC_DAIFMT_FORMAT_MASK, data->daifmt);
|
||||||
|
if (data->tdm_slots && fmtval != SND_SOC_DAIFMT_DSP_A && fmtval != SND_SOC_DAIFMT_DSP_B) {
|
||||||
|
dev_err(dev, "TDM is used, format only support DSP_A or DSP_B\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (fmtval) {
|
||||||
|
case SND_SOC_DAIFMT_I2S:
|
||||||
|
audfmt = 8;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_LEFT_J:
|
||||||
|
audfmt = 9;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_RIGHT_J:
|
||||||
|
audfmt = 10;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_DSP_A:
|
||||||
|
audfmt = data->tdm_slots ? 12 : 11;
|
||||||
|
break;
|
||||||
|
case SND_SOC_DAIFMT_DSP_B:
|
||||||
|
audfmt = data->tdm_slots ? 4 : 3;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(dev, "Unsupported format 0x%8x\n", fmtval);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (width = params_width(param)) {
|
switch (width = params_width(param)) {
|
||||||
case 16:
|
case 16:
|
||||||
audbit = 0;
|
audbit = 0;
|
||||||
@ -611,6 +616,10 @@ static int rtq9128_dai_hw_params(struct snd_pcm_substream *stream, struct snd_pc
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDFMT_MASK, audfmt);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDBIT_MASK, audbit);
|
ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDBIT_MASK, audbit);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user