summaryrefslogtreecommitdiffstats
path: root/sound/soc/ti
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2020-11-06 08:25:50 +0100
committerMark Brown <broonie@kernel.org>2020-11-06 18:46:03 +0100
commit1125d925990b8d8166c45396c9281e2a705c97f8 (patch)
treedffbff6865de5eb30db2e628a51746637818656a /sound/soc/ti
parentASoC: ti: davinci-mcasp: Remove legacy dma_request parsing (diff)
downloadlinux-1125d925990b8d8166c45396c9281e2a705c97f8.tar.xz
linux-1125d925990b8d8166c45396c9281e2a705c97f8.zip
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>
Diffstat (limited to 'sound/soc/ti')
-rw-r--r--sound/soc/ti/davinci-mcasp.c164
1 files changed, 60 insertions, 104 deletions
diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c
index 90b05a879214..5aa6a647dfdc 100644
--- a/sound/soc/ti/davinci-mcasp.c
+++ b/sound/soc/ti/davinci-mcasp.c
@@ -76,6 +76,7 @@ struct davinci_mcasp_ruledata {
struct davinci_mcasp {
struct snd_dmaengine_dai_dma_data dma_data[2];
+ struct davinci_mcasp_pdata *pdata;
void __iomem *base;
u32 fifo_base;
struct device *dev;
@@ -1747,44 +1748,37 @@ err1:
return ret;
}
-static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
- struct platform_device *pdev)
+static int davinci_mcasp_get_config(struct davinci_mcasp *mcasp,
+ 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 davinci_mcasp_pdata *pdata = NULL;
- const struct of_device_id *match =
- of_match_device(mcasp_dt_ids, &pdev->dev);
-
const u32 *of_serial_dir32;
u32 val;
- int i, ret = 0;
+ int i;
if (pdev->dev.platform_data) {
pdata = pdev->dev.platform_data;
pdata->dismod = DISMOD_LOW;
- return pdata;
+ goto out;
} else if (match) {
pdata = devm_kmemdup(&pdev->dev, match->data, sizeof(*pdata),
GFP_KERNEL);
if (!pdata)
- return NULL;
+ return -ENOMEM;
} else {
- /* control shouldn't reach here. something is wrong */
- ret = -EINVAL;
- goto nodata;
+ dev_err(&pdev->dev, "No compatible match found\n");
+ return -EINVAL;
}
- ret = of_property_read_u32(np, "op-mode", &val);
- if (ret >= 0)
+ if (of_property_read_u32(np, "op-mode", &val) == 0)
pdata->op_mode = val;
- ret = of_property_read_u32(np, "tdm-slots", &val);
- if (ret >= 0) {
+ if (of_property_read_u32(np, "tdm-slots", &val) == 0) {
if (val < 2 || val > 32) {
- dev_err(&pdev->dev,
- "tdm-slots must be in rage [2-32]\n");
- ret = -EINVAL;
- goto nodata;
+ dev_err(&pdev->dev, "tdm-slots must be in rage [2-32]\n");
+ return -EINVAL;
}
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,
(sizeof(*of_serial_dir) * val),
GFP_KERNEL);
- if (!of_serial_dir) {
- ret = -ENOMEM;
- goto nodata;
- }
+ if (!of_serial_dir)
+ return -ENOMEM;
for (i = 0; i < val; 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;
}
- ret = of_property_read_u32(np, "tx-num-evt", &val);
- if (ret >= 0)
+ if (of_property_read_u32(np, "tx-num-evt", &val) == 0)
pdata->txnumevt = val;
- ret = of_property_read_u32(np, "rx-num-evt", &val);
- if (ret >= 0)
+ if (of_property_read_u32(np, "rx-num-evt", &val) == 0)
pdata->rxnumevt = val;
- ret = of_property_read_u32(np, "sram-size-playback", &val);
- if (ret >= 0)
- pdata->sram_size_playback = val;
-
- ret = of_property_read_u32(np, "sram-size-capture", &val);
- if (ret >= 0)
- pdata->sram_size_capture = val;
+ if (of_property_read_u32(np, "auxclk-fs-ratio", &val) == 0)
+ mcasp->auxclk_fs_ratio = val;
- ret = of_property_read_u32(np, "dismod", &val);
- if (ret >= 0) {
+ if (of_property_read_u32(np, "dismod", &val) == 0) {
if (val == 0 || val == 2 || val == 3) {
pdata->dismod = DISMOD_VAL(val);
} else {
@@ -1836,15 +1820,40 @@ static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
pdata->dismod = DISMOD_LOW;
}
- return pdata;
+out:
+ mcasp->pdata = pdata;
-nodata:
- if (ret < 0) {
- dev_err(&pdev->dev, "Error populating platform data, err %d\n",
- ret);
- pdata = NULL;
+ 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_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 {
@@ -2083,25 +2092,10 @@ static inline int davinci_mcasp_init_gpiochip(struct davinci_mcasp *mcasp)
}
#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)
{
struct snd_dmaengine_dai_dma_data *dma_data;
struct resource *mem, *dat;
- struct davinci_mcasp_pdata *pdata;
struct davinci_mcasp *mcasp;
char *irq_name;
int irq;
@@ -2117,11 +2111,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
if (!mcasp)
return -ENOMEM;
- pdata = davinci_mcasp_set_pdata_from_of(pdev);
- if (!pdata) {
- dev_err(&pdev->dev, "no platform data\n");
- return -EINVAL;
- }
+ mcasp->dev = &pdev->dev;
+ ret = davinci_mcasp_get_config(mcasp, pdev);
+ if (ret)
+ return ret;
mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
if (!mem) {
@@ -2140,40 +2133,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
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");
if (irq > 0) {
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)
dma_data->addr = dat->start;
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 */
@@ -2253,7 +2212,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
dma_data->addr = dat->start;
else
dma_data->addr =
- mem->start + davinci_mcasp_rxdma_offset(pdata);
+ mem->start + davinci_mcasp_rxdma_offset(mcasp->pdata);
}
if (mcasp->version < MCASP_VERSION_3) {
@@ -2306,11 +2265,8 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
if (ret)
goto err;
- davinci_mcasp_get_dt_params(mcasp);
-
- ret = devm_snd_soc_register_component(&pdev->dev,
- &davinci_mcasp_component,
- &davinci_mcasp_dai[pdata->op_mode], 1);
+ ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
+ &davinci_mcasp_dai[mcasp->op_mode], 1);
if (ret != 0)
goto err;