ASoC: ti: davinci-mcasp: Simplify the configuration parameter handling
Replace the davinci_mcasp_set_pdata_from_of() function which returned a pdata pointer with davinci_mcasp_get_config() to return an actual error code and handle all pdata validation and private mcasp struct setup in there. Drop the unused ram-size-playback and sram-size-capture query from DT at the same time. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Link: https://lore.kernel.org/r/20201106072551.689-4-peter.ujfalusi@ti.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
db8793a39b
commit
1125d92599
@ -76,6 +76,7 @@ struct davinci_mcasp_ruledata {
|
|||||||
|
|
||||||
struct davinci_mcasp {
|
struct davinci_mcasp {
|
||||||
struct snd_dmaengine_dai_dma_data dma_data[2];
|
struct snd_dmaengine_dai_dma_data dma_data[2];
|
||||||
|
struct davinci_mcasp_pdata *pdata;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
u32 fifo_base;
|
u32 fifo_base;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
@ -1747,44 +1748,37 @@ err1:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
|
static int davinci_mcasp_get_config(struct davinci_mcasp *mcasp,
|
||||||
struct platform_device *pdev)
|
struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
const struct of_device_id *match = of_match_device(mcasp_dt_ids, &pdev->dev);
|
||||||
struct device_node *np = pdev->dev.of_node;
|
struct device_node *np = pdev->dev.of_node;
|
||||||
struct davinci_mcasp_pdata *pdata = NULL;
|
struct davinci_mcasp_pdata *pdata = NULL;
|
||||||
const struct of_device_id *match =
|
|
||||||
of_match_device(mcasp_dt_ids, &pdev->dev);
|
|
||||||
|
|
||||||
const u32 *of_serial_dir32;
|
const u32 *of_serial_dir32;
|
||||||
u32 val;
|
u32 val;
|
||||||
int i, ret = 0;
|
int i;
|
||||||
|
|
||||||
if (pdev->dev.platform_data) {
|
if (pdev->dev.platform_data) {
|
||||||
pdata = pdev->dev.platform_data;
|
pdata = pdev->dev.platform_data;
|
||||||
pdata->dismod = DISMOD_LOW;
|
pdata->dismod = DISMOD_LOW;
|
||||||
return pdata;
|
goto out;
|
||||||
} else if (match) {
|
} else if (match) {
|
||||||
pdata = devm_kmemdup(&pdev->dev, match->data, sizeof(*pdata),
|
pdata = devm_kmemdup(&pdev->dev, match->data, sizeof(*pdata),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!pdata)
|
if (!pdata)
|
||||||
return NULL;
|
return -ENOMEM;
|
||||||
} else {
|
} else {
|
||||||
/* control shouldn't reach here. something is wrong */
|
dev_err(&pdev->dev, "No compatible match found\n");
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto nodata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "op-mode", &val);
|
if (of_property_read_u32(np, "op-mode", &val) == 0)
|
||||||
if (ret >= 0)
|
|
||||||
pdata->op_mode = val;
|
pdata->op_mode = val;
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "tdm-slots", &val);
|
if (of_property_read_u32(np, "tdm-slots", &val) == 0) {
|
||||||
if (ret >= 0) {
|
|
||||||
if (val < 2 || val > 32) {
|
if (val < 2 || val > 32) {
|
||||||
dev_err(&pdev->dev,
|
dev_err(&pdev->dev, "tdm-slots must be in rage [2-32]\n");
|
||||||
"tdm-slots must be in rage [2-32]\n");
|
return -EINVAL;
|
||||||
ret = -EINVAL;
|
|
||||||
goto nodata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pdata->tdm_slots = val;
|
pdata->tdm_slots = val;
|
||||||
@ -1796,10 +1790,8 @@ static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
|
|||||||
u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
|
u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
|
||||||
(sizeof(*of_serial_dir) * val),
|
(sizeof(*of_serial_dir) * val),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!of_serial_dir) {
|
if (!of_serial_dir)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto nodata;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < val; i++)
|
for (i = 0; i < val; i++)
|
||||||
of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
|
of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
|
||||||
@ -1808,24 +1800,16 @@ static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
|
|||||||
pdata->serial_dir = of_serial_dir;
|
pdata->serial_dir = of_serial_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "tx-num-evt", &val);
|
if (of_property_read_u32(np, "tx-num-evt", &val) == 0)
|
||||||
if (ret >= 0)
|
|
||||||
pdata->txnumevt = val;
|
pdata->txnumevt = val;
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "rx-num-evt", &val);
|
if (of_property_read_u32(np, "rx-num-evt", &val) == 0)
|
||||||
if (ret >= 0)
|
|
||||||
pdata->rxnumevt = val;
|
pdata->rxnumevt = val;
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "sram-size-playback", &val);
|
if (of_property_read_u32(np, "auxclk-fs-ratio", &val) == 0)
|
||||||
if (ret >= 0)
|
mcasp->auxclk_fs_ratio = val;
|
||||||
pdata->sram_size_playback = val;
|
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "sram-size-capture", &val);
|
if (of_property_read_u32(np, "dismod", &val) == 0) {
|
||||||
if (ret >= 0)
|
|
||||||
pdata->sram_size_capture = val;
|
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "dismod", &val);
|
|
||||||
if (ret >= 0) {
|
|
||||||
if (val == 0 || val == 2 || val == 3) {
|
if (val == 0 || val == 2 || val == 3) {
|
||||||
pdata->dismod = DISMOD_VAL(val);
|
pdata->dismod = DISMOD_VAL(val);
|
||||||
} else {
|
} else {
|
||||||
@ -1836,15 +1820,40 @@ static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
|
|||||||
pdata->dismod = DISMOD_LOW;
|
pdata->dismod = DISMOD_LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pdata;
|
out:
|
||||||
|
mcasp->pdata = pdata;
|
||||||
|
|
||||||
nodata:
|
mcasp->op_mode = pdata->op_mode;
|
||||||
if (ret < 0) {
|
/* sanity check for tdm slots parameter */
|
||||||
dev_err(&pdev->dev, "Error populating platform data, err %d\n",
|
if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) {
|
||||||
ret);
|
if (pdata->tdm_slots < 2) {
|
||||||
pdata = NULL;
|
dev_warn(&pdev->dev, "invalid tdm slots: %d\n",
|
||||||
|
pdata->tdm_slots);
|
||||||
|
mcasp->tdm_slots = 2;
|
||||||
|
} else if (pdata->tdm_slots > 32) {
|
||||||
|
dev_warn(&pdev->dev, "invalid tdm slots: %d\n",
|
||||||
|
pdata->tdm_slots);
|
||||||
|
mcasp->tdm_slots = 32;
|
||||||
|
} else {
|
||||||
|
mcasp->tdm_slots = pdata->tdm_slots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return pdata;
|
|
||||||
|
mcasp->num_serializer = pdata->num_serializer;
|
||||||
|
#ifdef CONFIG_PM
|
||||||
|
mcasp->context.xrsr_regs = devm_kcalloc(&pdev->dev,
|
||||||
|
mcasp->num_serializer, sizeof(u32),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!mcasp->context.xrsr_regs)
|
||||||
|
return -ENOMEM;
|
||||||
|
#endif
|
||||||
|
mcasp->serial_dir = pdata->serial_dir;
|
||||||
|
mcasp->version = pdata->version;
|
||||||
|
mcasp->txnumevt = pdata->txnumevt;
|
||||||
|
mcasp->rxnumevt = pdata->rxnumevt;
|
||||||
|
mcasp->dismod = pdata->dismod;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -2083,25 +2092,10 @@ static inline int davinci_mcasp_init_gpiochip(struct davinci_mcasp *mcasp)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_GPIOLIB */
|
#endif /* CONFIG_GPIOLIB */
|
||||||
|
|
||||||
static void davinci_mcasp_get_dt_params(struct davinci_mcasp *mcasp)
|
|
||||||
{
|
|
||||||
struct device_node *np = mcasp->dev->of_node;
|
|
||||||
int ret;
|
|
||||||
u32 val;
|
|
||||||
|
|
||||||
if (!np)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "auxclk-fs-ratio", &val);
|
|
||||||
if (ret >= 0)
|
|
||||||
mcasp->auxclk_fs_ratio = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int davinci_mcasp_probe(struct platform_device *pdev)
|
static int davinci_mcasp_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct snd_dmaengine_dai_dma_data *dma_data;
|
struct snd_dmaengine_dai_dma_data *dma_data;
|
||||||
struct resource *mem, *dat;
|
struct resource *mem, *dat;
|
||||||
struct davinci_mcasp_pdata *pdata;
|
|
||||||
struct davinci_mcasp *mcasp;
|
struct davinci_mcasp *mcasp;
|
||||||
char *irq_name;
|
char *irq_name;
|
||||||
int irq;
|
int irq;
|
||||||
@ -2117,11 +2111,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
|
|||||||
if (!mcasp)
|
if (!mcasp)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
pdata = davinci_mcasp_set_pdata_from_of(pdev);
|
mcasp->dev = &pdev->dev;
|
||||||
if (!pdata) {
|
ret = davinci_mcasp_get_config(mcasp, pdev);
|
||||||
dev_err(&pdev->dev, "no platform data\n");
|
if (ret)
|
||||||
return -EINVAL;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
|
mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
@ -2140,40 +2133,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
pm_runtime_enable(&pdev->dev);
|
pm_runtime_enable(&pdev->dev);
|
||||||
|
|
||||||
mcasp->op_mode = pdata->op_mode;
|
|
||||||
/* sanity check for tdm slots parameter */
|
|
||||||
if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) {
|
|
||||||
if (pdata->tdm_slots < 2) {
|
|
||||||
dev_err(&pdev->dev, "invalid tdm slots: %d\n",
|
|
||||||
pdata->tdm_slots);
|
|
||||||
mcasp->tdm_slots = 2;
|
|
||||||
} else if (pdata->tdm_slots > 32) {
|
|
||||||
dev_err(&pdev->dev, "invalid tdm slots: %d\n",
|
|
||||||
pdata->tdm_slots);
|
|
||||||
mcasp->tdm_slots = 32;
|
|
||||||
} else {
|
|
||||||
mcasp->tdm_slots = pdata->tdm_slots;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mcasp->num_serializer = pdata->num_serializer;
|
|
||||||
#ifdef CONFIG_PM
|
|
||||||
mcasp->context.xrsr_regs = devm_kcalloc(&pdev->dev,
|
|
||||||
mcasp->num_serializer, sizeof(u32),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!mcasp->context.xrsr_regs) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
mcasp->serial_dir = pdata->serial_dir;
|
|
||||||
mcasp->version = pdata->version;
|
|
||||||
mcasp->txnumevt = pdata->txnumevt;
|
|
||||||
mcasp->rxnumevt = pdata->rxnumevt;
|
|
||||||
mcasp->dismod = pdata->dismod;
|
|
||||||
|
|
||||||
mcasp->dev = &pdev->dev;
|
|
||||||
|
|
||||||
irq = platform_get_irq_byname_optional(pdev, "common");
|
irq = platform_get_irq_byname_optional(pdev, "common");
|
||||||
if (irq > 0) {
|
if (irq > 0) {
|
||||||
irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common",
|
irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common",
|
||||||
@ -2242,7 +2201,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
|
|||||||
if (dat)
|
if (dat)
|
||||||
dma_data->addr = dat->start;
|
dma_data->addr = dat->start;
|
||||||
else
|
else
|
||||||
dma_data->addr = mem->start + davinci_mcasp_txdma_offset(pdata);
|
dma_data->addr = mem->start + davinci_mcasp_txdma_offset(mcasp->pdata);
|
||||||
|
|
||||||
|
|
||||||
/* RX is not valid in DIT mode */
|
/* RX is not valid in DIT mode */
|
||||||
@ -2253,7 +2212,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
|
|||||||
dma_data->addr = dat->start;
|
dma_data->addr = dat->start;
|
||||||
else
|
else
|
||||||
dma_data->addr =
|
dma_data->addr =
|
||||||
mem->start + davinci_mcasp_rxdma_offset(pdata);
|
mem->start + davinci_mcasp_rxdma_offset(mcasp->pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcasp->version < MCASP_VERSION_3) {
|
if (mcasp->version < MCASP_VERSION_3) {
|
||||||
@ -2306,11 +2265,8 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
davinci_mcasp_get_dt_params(mcasp);
|
ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
|
||||||
|
&davinci_mcasp_dai[mcasp->op_mode], 1);
|
||||||
ret = devm_snd_soc_register_component(&pdev->dev,
|
|
||||||
&davinci_mcasp_component,
|
|
||||||
&davinci_mcasp_dai[pdata->op_mode], 1);
|
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user