atheros: ar2315-spiflash: use devm_* API to simplify the code

Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@42489 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
John Crispin 2014-09-12 06:51:46 +00:00
parent 692156cc12
commit 0dcf34e7f4
1 changed files with 15 additions and 33 deletions

View File

@ -23,7 +23,7 @@
--- /dev/null --- /dev/null
+++ b/drivers/mtd/devices/ar2315.c +++ b/drivers/mtd/devices/ar2315.c
@@ -0,0 +1,536 @@ @@ -0,0 +1,518 @@
+ +
+/* +/*
+ * MTD driver for the SPI Flash Memory support on Atheros AR2315 + * MTD driver for the SPI Flash Memory support on Atheros AR2315
@ -452,41 +452,33 @@
+ int index; + int index;
+ int result = 0; + int result = 0;
+ +
+ priv = kzalloc(sizeof(struct spiflash_priv), GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ spin_lock_init(&priv->lock); + spin_lock_init(&priv->lock);
+ init_waitqueue_head(&priv->wq); + init_waitqueue_head(&priv->wq);
+ priv->state = FL_READY; + priv->state = FL_READY;
+ mtd = &priv->mtd; + mtd = &priv->mtd;
+ +
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ if (!res) { + priv->mmraddr = devm_ioremap_resource(&pdev->dev, res);
+ dev_err(&pdev->dev, "No MMR resource found\n"); + if (IS_ERR(priv->mmraddr)) {
+ goto error; + dev_warn(&pdev->dev, "failed to map flash MMR\n");
+ } + return PTR_ERR(priv->mmraddr);
+
+ priv->mmraddr = ioremap_nocache(res->start, resource_size(res));
+ if (!priv->mmraddr) {
+ dev_warn(&pdev->dev, SPIFLASH "Failed to map flash device\n");
+ goto error;
+ } + }
+ +
+ index = spiflash_probe_chip(priv); + index = spiflash_probe_chip(priv);
+ if (!index) { + if (!index) {
+ dev_warn(&pdev->dev, SPIFLASH "Found no flash device\n"); + dev_warn(&pdev->dev, SPIFLASH "Found no flash device\n");
+ goto error; + return -ENODEV;
+ } + }
+ +
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) { + priv->readaddr = devm_ioremap_resource(&pdev->dev, res);
+ dev_err(&pdev->dev, "No flash readmem resource found\n"); + if (IS_ERR(priv->readaddr)) {
+ goto error; + dev_warn(&pdev->dev, "failed to map flash read mem\n");
+ } + return PTR_ERR(priv->readaddr);
+
+ priv->readaddr = ioremap_nocache(res->start,
+ flashconfig_tbl[index].byte_cnt);
+ if (!priv->readaddr) {
+ dev_warn(&pdev->dev, SPIFLASH "Failed to map flash device\n");
+ goto error;
+ } + }
+ +
+ platform_set_drvdata(pdev, priv); + platform_set_drvdata(pdev, priv);
@ -513,24 +505,14 @@
+#endif +#endif
+ +
+ return result; + return result;
+
+error:
+ if (priv->mmraddr)
+ iounmap(priv->mmraddr);
+ kfree(priv);
+ return -ENXIO;
+} +}
+ +
+static int +static int
+spiflash_remove(struct platform_device *pdev) +spiflash_remove(struct platform_device *pdev)
+{ +{
+ struct spiflash_priv *priv = platform_get_drvdata(pdev); + struct spiflash_priv *priv = platform_get_drvdata(pdev);
+ struct mtd_info *mtd = &priv->mtd;
+ +
+ mtd_device_unregister(mtd); + mtd_device_unregister(&priv->mtd);
+ iounmap(priv->mmraddr);
+ iounmap(priv->readaddr);
+ kfree(priv);
+ +
+ return 0; + return 0;
+} +}