ar71xx: ar934x_nfc: return error code from some low-level functions
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / drivers / mtd / nand / ar934x_nfc.c
index 7939f9218ca58103e6db70d477e1b79be2e26428..1e387e875f6df066f0f79c8226cfcb3a7434f206 100644 (file)
@@ -410,7 +410,7 @@ ar934x_nfc_send_cmd(struct ar934x_nfc *nfc, unsigned command)
        ar934x_nfc_wait_dev_ready(nfc);
 }
 
-static void
+static int
 ar934x_nfc_do_rw_command(struct ar934x_nfc *nfc, int column, int page_addr,
                         int len, u32 cmd_reg, u32 ctrl_reg, bool write)
 {
@@ -475,29 +475,35 @@ retry:
                dev_err(nfc->parent, "%s operation failed on page %d\n",
                        (write) ? "write" : "read", page_addr);
        }
+
+       return err;
 }
 
-static void
+static int
 ar934x_nfc_send_readid(struct ar934x_nfc *nfc, unsigned command)
 {
        u32 cmd_reg;
+       int err;
 
        nfc_dbg(nfc, "readid, cmd:%02x\n", command);
 
        cmd_reg = AR934X_NFC_CMD_SEQ_1C1AXR;
        cmd_reg |= (command & AR934X_NFC_CMD_CMD0_M) << AR934X_NFC_CMD_CMD0_S;
 
-       ar934x_nfc_do_rw_command(nfc, -1, -1, AR934X_NFC_ID_BUF_SIZE, cmd_reg,
-                                nfc->ctrl_reg, false);
+       err = ar934x_nfc_do_rw_command(nfc, -1, -1, AR934X_NFC_ID_BUF_SIZE,
+                                      cmd_reg, nfc->ctrl_reg, false);
 
        nfc_debug_data("[id] ", nfc->buf, AR934X_NFC_ID_BUF_SIZE);
+
+       return err;
 }
 
-static void
+static int
 ar934x_nfc_send_read(struct ar934x_nfc *nfc, unsigned command, int column,
                     int page_addr, int len)
 {
        u32 cmd_reg;
+       int err;
 
        nfc_dbg(nfc, "read, column=%d page=%d len=%d\n",
                column, page_addr, len);
@@ -511,10 +517,12 @@ ar934x_nfc_send_read(struct ar934x_nfc *nfc, unsigned command, int column,
                cmd_reg |= AR934X_NFC_CMD_SEQ_1C5A1CXR;
        }
 
-       ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
-                                cmd_reg, nfc->ctrl_reg, false);
+       err = ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
+                                      cmd_reg, nfc->ctrl_reg, false);
 
        nfc_debug_data("[data] ", nfc->buf, len);
+
+       return err;
 }
 
 static void
@@ -555,7 +563,7 @@ ar934x_nfc_send_erase(struct ar934x_nfc *nfc, unsigned command, int column,
        ar934x_nfc_wait_dev_ready(nfc);
 }
 
-static void
+static int
 ar934x_nfc_send_write(struct ar934x_nfc *nfc, unsigned command, int column,
                     int page_addr, int len)
 {
@@ -570,8 +578,8 @@ ar934x_nfc_send_write(struct ar934x_nfc *nfc, unsigned command, int column,
        cmd_reg |= command << AR934X_NFC_CMD_CMD1_S;
        cmd_reg |= AR934X_NFC_CMD_SEQ_12;
 
-       ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
-                                cmd_reg, nfc->ctrl_reg, true);
+       return ar934x_nfc_do_rw_command(nfc, column, page_addr, len,
+                                       cmd_reg, nfc->ctrl_reg, true);
 }
 
 static void
@@ -872,7 +880,7 @@ ar934x_nfc_irq_handler(int irq, void *data)
        return IRQ_HANDLED;
 }
 
-static int __devinit
+static int
 ar934x_nfc_init_tail(struct mtd_info *mtd)
 {
        struct ar934x_nfc *nfc = mtd_to_ar934x_nfc(mtd);
@@ -998,7 +1006,7 @@ ar934x_nfc_init_tail(struct mtd_info *mtd)
        return err;
 }
 
-static int __devinit
+static int
 ar934x_nfc_probe(struct platform_device *pdev)
 {
        static const char *part_probes[] = { "cmdlinepart", NULL, };
@@ -1022,24 +1030,22 @@ ar934x_nfc_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       nfc = kzalloc(sizeof(struct ar934x_nfc), GFP_KERNEL);
+       nfc = devm_kzalloc(&pdev->dev, sizeof(struct ar934x_nfc), GFP_KERNEL);
        if (!nfc) {
                dev_err(&pdev->dev, "failed to allocate driver data\n");
                return -ENOMEM;
        }
 
-       nfc->base = ioremap(res->start, resource_size(res));
-       if (nfc->base == NULL) {
+       nfc->base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(nfc->base)) {
                dev_err(&pdev->dev, "failed to remap I/O memory\n");
-               ret = -ENXIO;
-               goto err_free_nand;
+               return PTR_ERR(nfc->base);
        }
 
        nfc->irq = platform_get_irq(pdev, 0);
        if (nfc->irq < 0) {
                dev_err(&pdev->dev, "no IRQ resource specified\n");
-               ret = -EINVAL;
-               goto err_unmap;
+               return -EINVAL;
        }
 
        init_waitqueue_head(&nfc->irq_waitq);
@@ -1047,7 +1053,7 @@ ar934x_nfc_probe(struct platform_device *pdev)
                          dev_name(&pdev->dev), nfc);
        if (ret) {
                dev_err(&pdev->dev, "requast_irq failed, err:%d\n", ret);
-               goto err_unmap;
+               return ret;
        }
 
        nfc->parent = &pdev->dev;
@@ -1120,15 +1126,10 @@ err_free_buf:
        ar934x_nfc_free_buf(nfc);
 err_free_irq:
        free_irq(nfc->irq, nfc);
-err_unmap:
-       iounmap(nfc->base);
-err_free_nand:
-       kfree(nfc);
-       platform_set_drvdata(pdev, NULL);
        return ret;
 }
 
-static int __devexit
+static int
 ar934x_nfc_remove(struct platform_device *pdev)
 {
        struct ar934x_nfc *nfc;
@@ -1138,8 +1139,6 @@ ar934x_nfc_remove(struct platform_device *pdev)
                nand_release(&nfc->mtd);
                ar934x_nfc_free_buf(nfc);
                free_irq(nfc->irq, nfc);
-               iounmap(nfc->base);
-               kfree(nfc);
        }
 
        return 0;
@@ -1147,7 +1146,7 @@ ar934x_nfc_remove(struct platform_device *pdev)
 
 static struct platform_driver ar934x_nfc_driver = {
        .probe          = ar934x_nfc_probe,
-       .remove         = __devexit_p(ar934x_nfc_remove),
+       .remove         = ar934x_nfc_remove,
        .driver = {
                .name   = AR934X_NFC_DRIVER_NAME,
                .owner  = THIS_MODULE,