ramips: modernize snd-mt7620 driver

Use more devm and remove gotos.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16631
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Rosen Penev 2024-09-26 17:35:34 -07:00 committed by Hauke Mehrtens
parent e659298a84
commit 19d84c60f8

View File

@ -5,7 +5,6 @@ Subject: [PATCH 48/53] asoc: add mt7620 support
Signed-off-by: John Crispin <blogic@openwrt.org> Signed-off-by: John Crispin <blogic@openwrt.org>
--- ---
arch/mips/ralink/of.c | 2 +
sound/soc/Kconfig | 1 + sound/soc/Kconfig | 1 +
sound/soc/Makefile | 1 + sound/soc/Makefile | 1 +
sound/soc/ralink/Kconfig | 15 ++ sound/soc/ralink/Kconfig | 15 ++
@ -60,7 +59,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+obj-$(CONFIG_SND_RALINK_SOC_I2S) += snd-soc-ralink-i2s.o +obj-$(CONFIG_SND_RALINK_SOC_I2S) += snd-soc-ralink-i2s.o
--- /dev/null --- /dev/null
+++ b/sound/soc/ralink/ralink-i2s.c +++ b/sound/soc/ralink/ralink-i2s.c
@@ -0,0 +1,968 @@ @@ -0,0 +1,941 @@
+/* +/*
+ * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de> + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
+ * Copyright (C) 2016 Michael Lee <igvtee@gmail.com> + * Copyright (C) 2016 Michael Lee <igvtee@gmail.com>
@ -869,20 +868,20 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+{ +{
+ const struct of_device_id *match; + const struct of_device_id *match;
+ struct device_node *np = pdev->dev.of_node; + struct device_node *np = pdev->dev.of_node;
+ struct ralink_i2s *i2s; + struct device *dev = &pdev->dev;
+ struct resource *res; + struct resource *res;
+ struct ralink_i2s *i2s;
+ int irq, ret; + int irq, ret;
+ u32 dma_req; + u32 dma_req;
+ struct rt_i2s_data *data; + struct rt_i2s_data *data;
+ +
+ i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL);
+ if (!i2s) + if (!i2s)
+ return -ENOMEM; + return -ENOMEM;
+ +
+ platform_set_drvdata(pdev, i2s); + i2s->dev = dev;
+ i2s->dev = &pdev->dev;
+ +
+ match = of_match_device(ralink_i2s_match_table, &pdev->dev); + match = of_match_device(ralink_i2s_match_table, dev);
+ if (!match) + if (!match)
+ return -EINVAL; + return -EINVAL;
+ data = (struct rt_i2s_data *)match->data; + data = (struct rt_i2s_data *)match->data;
@ -892,68 +891,49 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ data->refclk_setup(); + data->refclk_setup();
+ +
+ if (of_property_read_u32(np, "txdma-req", &dma_req)) { + if (of_property_read_u32(np, "txdma-req", &dma_req)) {
+ dev_err(&pdev->dev, "no txdma-req define\n"); + dev_err(dev, "no txdma-req define\n");
+ return -EINVAL; + return -EINVAL;
+ } + }
+ i2s->txdma_req = (u16)dma_req; + i2s->txdma_req = (u16)dma_req;
+ if (!(i2s->flags & RALINK_FLAGS_TXONLY)) { + if (!(i2s->flags & RALINK_FLAGS_TXONLY)) {
+ if (of_property_read_u32(np, "rxdma-req", &dma_req)) { + if (of_property_read_u32(np, "rxdma-req", &dma_req)) {
+ dev_err(&pdev->dev, "no rxdma-req define\n"); + dev_err(dev, "no rxdma-req define\n");
+ return -EINVAL; + return -EINVAL;
+ } + }
+ i2s->rxdma_req = (u16)dma_req; + i2s->rxdma_req = (u16)dma_req;
+ } + }
+ +
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + i2s->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+ i2s->regs = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(i2s->regs)) + if (IS_ERR(i2s->regs))
+ return PTR_ERR(i2s->regs); + return PTR_ERR(i2s->regs);
+ +
+ i2s->regmap = devm_regmap_init_mmio(&pdev->dev, i2s->regs, + i2s->regmap = devm_regmap_init_mmio(dev, i2s->regs,
+ &ralink_i2s_regmap_config); + &ralink_i2s_regmap_config);
+ if (IS_ERR(i2s->regmap)) { + if (IS_ERR(i2s->regmap))
+ dev_err(&pdev->dev, "regmap init failed\n"); + return dev_err_probe(dev, PTR_ERR(i2s->regmap), "regmap init failed");
+ return PTR_ERR(i2s->regmap);
+ }
+ +
+ irq = platform_get_irq(pdev, 0); + irq = platform_get_irq(pdev, 0);
+ if (irq < 0) { + if (irq < 0) {
+ dev_err(&pdev->dev, "failed to get irq\n"); + dev_err(dev, "failed to get irq\n");
+ return -EINVAL; + return -EINVAL;
+ } + }
+ +
+#if (RALINK_I2S_INT_EN) +#if (RALINK_I2S_INT_EN)
+ ret = devm_request_irq(&pdev->dev, irq, ralink_i2s_irq, + ret = devm_request_irq(dev, irq, ralink_i2s_irq,
+ 0, dev_name(&pdev->dev), i2s); + 0, dev_name(dev), i2s);
+ if (ret) { + if (ret)
+ dev_err(&pdev->dev, "failed to request irq\n"); + return dev_err_probe(dev, ret, "failed to request irq");
+ return ret;
+ }
+#endif +#endif
+ +
+ i2s->clk = devm_clk_get(&pdev->dev, NULL); + i2s->clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(i2s->clk)) { + if (IS_ERR(i2s->clk))
+ dev_err(&pdev->dev, "no clock defined\n"); + return dev_err_probe(dev, PTR_ERR(i2s->clk), "no clock defined");
+ return PTR_ERR(i2s->clk);
+ }
+
+ ret = clk_prepare_enable(i2s->clk);
+ if (ret)
+ return ret;
+ +
+ ralink_i2s_init_dma_data(i2s, res); + ralink_i2s_init_dma_data(i2s, res);
+ +
+ ret = device_reset(&pdev->dev); + ret = device_reset(dev);
+ if (ret) { + if (ret)
+ dev_err(&pdev->dev, "failed to reset device\n"); + return dev_err_probe(dev, ret, "failed to reset device\n");
+ goto err_clk_disable;
+ }
+
+ ret = ralink_i2s_debugfs_create(i2s);
+ if (ret) {
+ dev_err(&pdev->dev, "create debugfs failed\n");
+ goto err_clk_disable;
+ }
+ +
+ /* enable 24bits support */ + /* enable 24bits support */
+ if (i2s->flags & RALINK_FLAGS_24BIT) { + if (i2s->flags & RALINK_FLAGS_24BIT) {
@ -981,28 +961,21 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ memset(&ralink_i2s_dai.capture, sizeof(ralink_i2s_dai.capture), + memset(&ralink_i2s_dai.capture, sizeof(ralink_i2s_dai.capture),
+ 0); + 0);
+ +
+ ret = devm_snd_soc_register_component(&pdev->dev, &ralink_i2s_component, + ret = devm_snd_soc_register_component(dev, &ralink_i2s_component,
+ &ralink_i2s_dai, 1); + &ralink_i2s_dai, 1);
+ if (ret) + if (ret)
+ goto err_debugfs; + return ret;
+ +
+ ret = devm_snd_dmaengine_pcm_register(&pdev->dev, + ret = devm_snd_dmaengine_pcm_register(dev,
+ &ralink_dmaengine_pcm_config, + &ralink_dmaengine_pcm_config,
+ SND_DMAENGINE_PCM_FLAG_COMPAT); + SND_DMAENGINE_PCM_FLAG_COMPAT);
+ if (ret) + if (ret)
+ goto err_debugfs; + return ret;
+ +
+ dev_info(i2s->dev, "mclk %luMHz\n", clk_get_rate(i2s->clk) / 1000000); + dev_info(i2s->dev, "mclk %luMHz\n", clk_get_rate(i2s->clk) / 1000000);
+ +
+ return 0; + platform_set_drvdata(pdev, i2s);
+ + return ralink_i2s_debugfs_create(i2s);
+err_debugfs:
+ ralink_i2s_debugfs_remove(i2s);
+
+err_clk_disable:
+ clk_disable_unprepare(i2s->clk);
+
+ return ret;
+} +}
+ +
+static int ralink_i2s_remove(struct platform_device *pdev) +static int ralink_i2s_remove(struct platform_device *pdev)
@ -1010,7 +983,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
+ struct ralink_i2s *i2s = platform_get_drvdata(pdev); + struct ralink_i2s *i2s = platform_get_drvdata(pdev);
+ +
+ ralink_i2s_debugfs_remove(i2s); + ralink_i2s_debugfs_remove(i2s);
+ clk_disable_unprepare(i2s->clk);
+ +
+ return 0; + return 0;
+} +}