Skip to contentSkip to conversation

spi: mpc5xxx-psc: Clean up even more and fix

PATCH In review Andy Shevchenko 2 participants 7 messages Mar 6, 2023 – Mar 8, 2023 SPI

lore
Share & tools
lore
#0 lore raw

cover spi: mpc5xxx-psc: Clean up even more and fix

The recent cleanup series broke the error path in the drivers. So fix it and do even more cleanups.

Andy Shevchenko (5):
spi: mpc5xxx-psc: Correct error check for
devm_platform_get_and_ioremap_resource()
spi: mpc5xxx-psc: Return immediately if IRQ resource is unavailable
spi: mpc5xxx-psc: use devm_clk_get_enabled() for core clock
spi: mpc5xxx-psc: Propagate firmware node
spi: mpc5xxx-psc: Consistently use device property APIs

 drivers/spi/spi-mpc512x-psc.c | 50 +++++++++--------------------------
 drivers/spi/spi-mpc52xx-psc.c | 15 +++++++----
 2 files changed, 22 insertions(+), 43 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH 1/5 spi: mpc5xxx-psc: Correct error check for devm_platform_get_and_ioremap_resource()

devm_platform_get_and_ioremap_resource() may return pointer or error pointer, never the NULL. Correct error check for it.

Fixes 60a6c8257f41 ("spi: mpc5xxx-psc: Use platform resources instead of parsing DT properties")
---
 drivers/spi/spi-mpc512x-psc.c | 4 ++--
 drivers/spi/spi-mpc52xx-psc.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/spi/spi-mpc512x-psc.c +2 -2
index 5bdfe4a740e9..a2ea24a63cb4 100644
@@ -483,8 +483,8 @@ static int mpc512x_psc_spi_of_probe(struct platform_device *pdev)
 	master->dev.of_node = dev->of_node;
 
 	tempp = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
-	if (!tempp)
-		return dev_err_probe(dev, -EFAULT, "could not ioremap I/O port range\n");
+	if (IS_ERR(tempp))
+		return dev_err_probe(dev, PTR_ERR(tempp), "could not ioremap I/O port range\n");
 	mps->psc = tempp;
 	mps->fifo =
 		(struct mpc512x_psc_fifo *)(tempp + sizeof(struct mpc52xx_psc));
drivers/spi/spi-mpc52xx-psc.c +3 -2
index 95a4a511c388..1bf728f4d766 100644
@@ -321,8 +321,9 @@ static int mpc52xx_psc_spi_of_probe(struct platform_device *pdev)
 	master->dev.of_node = dev->of_node;
 
 	mps->psc = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
-	if (!mps->psc)
-		return dev_err_probe(dev, -EFAULT, "could not ioremap I/O port range\n");
+	if (IS_ERR(mps->psc))
+		return dev_err_probe(dev, PTR_ERR(mps->psc), "could not ioremap I/O port range\n");
+
 	/* On the 5200, fifo regs are immediately ajacent to the psc regs */
 	mps->fifo = ((void __iomem *)mps->psc) + sizeof(struct mpc52xx_psc);
 
Signature · 1 line
2.39.1
#2 lore raw

PATCH 2/5 spi: mpc5xxx-psc: Return immediately if IRQ resource is unavailable

In reply to Andy Shevchenko

Return immediately if IRQ resource is unavailable. This will also propagate the correct error code in such cases.

---
 drivers/spi/spi-mpc512x-psc.c | 3 +++
 drivers/spi/spi-mpc52xx-psc.c | 3 +++
 2 files changed, 6 insertions(+)
drivers/spi/spi-mpc512x-psc.c +3 -0
index a2ea24a63cb4..8a436d1906eb 100644
@@ -490,6 +490,9 @@ static int mpc512x_psc_spi_of_probe(struct platform_device *pdev)
 		(struct mpc512x_psc_fifo *)(tempp + sizeof(struct mpc52xx_psc));
 
 	mps->irq = platform_get_irq(pdev, 0);
+	if (mps->irq < 0)
+		return mps->irq;
+
 	ret = devm_request_irq(dev, mps->irq, mpc512x_psc_spi_isr, IRQF_SHARED,
 				"mpc512x-psc-spi", mps);
 	if (ret)
drivers/spi/spi-mpc52xx-psc.c +3 -0
index 1bf728f4d766..b75bc2457883 100644
@@ -328,6 +328,9 @@ static int mpc52xx_psc_spi_of_probe(struct platform_device *pdev)
 	mps->fifo = ((void __iomem *)mps->psc) + sizeof(struct mpc52xx_psc);
 
 	mps->irq = platform_get_irq(pdev, 0);
+	if (mps->irq < 0)
+		return mps->irq;
+
 	ret = devm_request_irq(dev, mps->irq, mpc52xx_psc_spi_isr, 0,
 			       "mpc52xx-psc-spi", mps);
 	if (ret)
Signature · 1 line
2.39.1
#3 lore raw

PATCH 3/5 spi: mpc5xxx-psc: use devm_clk_get_enabled() for core clock

In reply to Andy Shevchenko

Use devm_clk_get_enabled() to simplify the code.

---
 drivers/spi/spi-mpc512x-psc.c | 39 ++++-------------------------------
 1 file changed, 4 insertions(+), 35 deletions(-)
drivers/spi/spi-mpc512x-psc.c +4 -35
index 8a436d1906eb..739df2b241e9 100644
@@ -54,8 +54,6 @@ struct mpc512x_psc_spi {
 	struct mpc512x_psc_fifo __iomem *fifo;
 	unsigned int irq;
 	u8 bits_per_word;
-	struct clk *clk_mclk;
-	struct clk *clk_ipg;
 	u32 mclk_rate;
 
 	struct completion txisrdone;
@@ -499,25 +497,15 @@ static int mpc512x_psc_spi_of_probe(struct platform_device *pdev)
 		return ret;
 	init_completion(&mps->txisrdone);
 
-	clk = devm_clk_get(dev, "mclk");
+	clk = devm_clk_get_enabled(dev, "mclk");
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
-	ret = clk_prepare_enable(clk);
-	if (ret)
-		return ret;
-	mps->clk_mclk = clk;
 	mps->mclk_rate = clk_get_rate(clk);
 
-	clk = devm_clk_get(dev, "ipg");
-	if (IS_ERR(clk)) {
-		ret = PTR_ERR(clk);
-		goto free_mclk_clock;
-	}
-	ret = clk_prepare_enable(clk);
-	if (ret)
-		goto free_mclk_clock;
-	mps->clk_ipg = clk;
+	clk = devm_clk_get_enabled(dev, "ipg");
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
 
 	ret = mpc512x_psc_spi_port_config(master, mps);
 	if (ret < 0)
@@ -528,24 +516,6 @@ static int mpc512x_psc_spi_of_probe(struct platform_device *pdev)
 		goto free_ipg_clock;
 
 	return ret;
-
-free_ipg_clock:
-	clk_disable_unprepare(mps->clk_ipg);
-free_mclk_clock:
-	clk_disable_unprepare(mps->clk_mclk);
-
-	return ret;
-}
-
-static int mpc512x_psc_spi_of_remove(struct platform_device *pdev)
-{
-	struct spi_master *master = dev_get_drvdata(&pdev->dev);
-	struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
-
-	clk_disable_unprepare(mps->clk_mclk);
-	clk_disable_unprepare(mps->clk_ipg);
-
-	return 0;
 }
 
 static const struct of_device_id mpc512x_psc_spi_of_match[] = {
@@ -558,7 +528,6 @@ MODULE_DEVICE_TABLE(of, mpc512x_psc_spi_of_match);
 
 static struct platform_driver mpc512x_psc_spi_of_driver = {
 	.probe = mpc512x_psc_spi_of_probe,
-	.remove = mpc512x_psc_spi_of_remove,
 	.driver = {
 		.name = "mpc512x-psc-spi",
 		.of_match_table = mpc512x_psc_spi_of_match,
Signature · 1 line
2.39.1
#4 lore raw

PATCH 4/5 spi: mpc5xxx-psc: Propagate firmware node

In reply to Andy Shevchenko

Propagate firmware node by using a specific API call, i.e. device_set_node().

---
 drivers/spi/spi-mpc512x-psc.c | 4 +++-
 drivers/spi/spi-mpc52xx-psc.c | 5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/spi/spi-mpc512x-psc.c +3 -1
index 739df2b241e9..77a228f633d1 100644
@@ -17,6 +17,7 @@
 #include <linux/completion.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/delay.h>
 #include <linux/clk.h>
 #include <linux/spi/spi.h>
@@ -478,7 +479,8 @@ static int mpc512x_psc_spi_of_probe(struct platform_device *pdev)
 	master->unprepare_transfer_hardware = mpc512x_psc_spi_unprep_xfer_hw;
 	master->use_gpio_descriptors = true;
 	master->cleanup = mpc512x_psc_spi_cleanup;
-	master->dev.of_node = dev->of_node;
+
+	device_set_node(&master->dev, dev_fwnode(dev));
 
 	tempp = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
 	if (IS_ERR(tempp))
drivers/spi/spi-mpc52xx-psc.c +3 -2
index b75bc2457883..335a6b9eb141 100644
@@ -11,8 +11,8 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/interrupt.h>
-#include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/io.h>
@@ -318,7 +318,8 @@ static int mpc52xx_psc_spi_of_probe(struct platform_device *pdev)
 	master->setup = mpc52xx_psc_spi_setup;
 	master->transfer_one_message = mpc52xx_psc_spi_transfer_one_message;
 	master->cleanup = mpc52xx_psc_spi_cleanup;
-	master->dev.of_node = dev->of_node;
+
+	device_set_node(&master->dev, dev_fwnode(dev));
 
 	mps->psc = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
 	if (IS_ERR(mps->psc))
Signature · 1 line
2.39.1
#5 lore raw

PATCH 5/5 spi: mpc5xxx-psc: Consistently use device property APIs

In reply to Andy Shevchenko

Instead of calling the OF APIs mixed with device property APIs, just switch to use the latter everywhere.

---
 drivers/spi/spi-mpc52xx-psc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-mpc52xx-psc.c +1 -1
index 335a6b9eb141..9a1a080fb688 100644
@@ -309,7 +309,7 @@ static int mpc52xx_psc_spi_of_probe(struct platform_device *pdev)
 	/* the spi->mode bits understood by this driver: */
 	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
 
-	ret = of_property_read_u32(dev->of_node, "cell-index", &bus_num);
+	ret = device_property_read_u32(dev, "cell-index", &bus_num);
 	if (ret || bus_num > 5)
 		return dev_err_probe(dev, ret ? : -EINVAL, "Invalid cell-index property\n");
 	master->bus_num = bus_num + 1;
Signature · 1 line
2.39.1
maintainer
#6 lore raw
In reply to Andy Shevchenko
Quoted 11 lines · Andy Shevchenko

The recent cleanup series broke the error path in the drivers. So fix it and do even more cleanups.

Andy Shevchenko (5):
spi: mpc5xxx-psc: Correct error check for
devm_platform_get_and_ioremap_resource()
spi: mpc5xxx-psc: Return immediately if IRQ resource is unavailable
spi: mpc5xxx-psc: use devm_clk_get_enabled() for core clock
spi: mpc5xxx-psc: Propagate firmware node
spi: mpc5xxx-psc: Consistently use device property APIs

Quoted 1 line

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/5] spi: mpc5xxx-psc: Correct error check for devm_platform_get_and_ioremap_resource()

      commit: ee493fa5d91dec02402239a072820b18beb36265
[2/5] spi: mpc5xxx-psc: Return immediately if IRQ resource is unavailable
      commit: 208ee586f86237969a91ac60ea10f48db9135143
[3/5] spi: mpc5xxx-psc: use devm_clk_get_enabled() for core clock
      commit: 9e21720a49589304aef9e37e8b6c6a4196daf156
[4/5] spi: mpc5xxx-psc: Propagate firmware node
      commit: 289c084ddc1317e6ed911911f95371679c10af1e
[5/5] spi: mpc5xxx-psc: Consistently use device property APIs
      commit: 3169c5816a55ba671e9c8a671c6c75818d30c657

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark