Version:  2.0.40 2.2.26 2.4.37 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5

Linux/drivers/mtd/nand/plat_nand.c

  1 /*
  2  * Generic NAND driver
  3  *
  4  * Author: Vitaly Wool <vitalywool@gmail.com>
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License version 2 as
  8  * published by the Free Software Foundation.
  9  *
 10  */
 11 
 12 #include <linux/err.h>
 13 #include <linux/io.h>
 14 #include <linux/module.h>
 15 #include <linux/platform_device.h>
 16 #include <linux/slab.h>
 17 #include <linux/mtd/mtd.h>
 18 #include <linux/mtd/nand.h>
 19 #include <linux/mtd/partitions.h>
 20 
 21 struct plat_nand_data {
 22         struct nand_chip        chip;
 23         void __iomem            *io_base;
 24 };
 25 
 26 /*
 27  * Probe for the NAND device.
 28  */
 29 static int plat_nand_probe(struct platform_device *pdev)
 30 {
 31         struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
 32         struct plat_nand_data *data;
 33         struct mtd_info *mtd;
 34         struct resource *res;
 35         const char **part_types;
 36         int err = 0;
 37 
 38         if (!pdata) {
 39                 dev_err(&pdev->dev, "platform_nand_data is missing\n");
 40                 return -EINVAL;
 41         }
 42 
 43         if (pdata->chip.nr_chips < 1) {
 44                 dev_err(&pdev->dev, "invalid number of chips specified\n");
 45                 return -EINVAL;
 46         }
 47 
 48         /* Allocate memory for the device structure (and zero it) */
 49         data = devm_kzalloc(&pdev->dev, sizeof(struct plat_nand_data),
 50                             GFP_KERNEL);
 51         if (!data)
 52                 return -ENOMEM;
 53 
 54         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 55         data->io_base = devm_ioremap_resource(&pdev->dev, res);
 56         if (IS_ERR(data->io_base))
 57                 return PTR_ERR(data->io_base);
 58 
 59         nand_set_flash_node(&data->chip, pdev->dev.of_node);
 60         mtd = nand_to_mtd(&data->chip);
 61         mtd->dev.parent = &pdev->dev;
 62 
 63         data->chip.IO_ADDR_R = data->io_base;
 64         data->chip.IO_ADDR_W = data->io_base;
 65         data->chip.cmd_ctrl = pdata->ctrl.cmd_ctrl;
 66         data->chip.dev_ready = pdata->ctrl.dev_ready;
 67         data->chip.select_chip = pdata->ctrl.select_chip;
 68         data->chip.write_buf = pdata->ctrl.write_buf;
 69         data->chip.read_buf = pdata->ctrl.read_buf;
 70         data->chip.read_byte = pdata->ctrl.read_byte;
 71         data->chip.chip_delay = pdata->chip.chip_delay;
 72         data->chip.options |= pdata->chip.options;
 73         data->chip.bbt_options |= pdata->chip.bbt_options;
 74 
 75         data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
 76         data->chip.ecc.layout = pdata->chip.ecclayout;
 77         data->chip.ecc.mode = NAND_ECC_SOFT;
 78 
 79         platform_set_drvdata(pdev, data);
 80 
 81         /* Handle any platform specific setup */
 82         if (pdata->ctrl.probe) {
 83                 err = pdata->ctrl.probe(pdev);
 84                 if (err)
 85                         goto out;
 86         }
 87 
 88         /* Scan to find existence of the device */
 89         if (nand_scan(mtd, pdata->chip.nr_chips)) {
 90                 err = -ENXIO;
 91                 goto out;
 92         }
 93 
 94         part_types = pdata->chip.part_probe_types;
 95 
 96         err = mtd_device_parse_register(mtd, part_types, NULL,
 97                                         pdata->chip.partitions,
 98                                         pdata->chip.nr_partitions);
 99 
100         if (!err)
101                 return err;
102 
103         nand_release(mtd);
104 out:
105         if (pdata->ctrl.remove)
106                 pdata->ctrl.remove(pdev);
107         return err;
108 }
109 
110 /*
111  * Remove a NAND device.
112  */
113 static int plat_nand_remove(struct platform_device *pdev)
114 {
115         struct plat_nand_data *data = platform_get_drvdata(pdev);
116         struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
117 
118         nand_release(nand_to_mtd(&data->chip));
119         if (pdata->ctrl.remove)
120                 pdata->ctrl.remove(pdev);
121 
122         return 0;
123 }
124 
125 static const struct of_device_id plat_nand_match[] = {
126         { .compatible = "gen_nand" },
127         {},
128 };
129 MODULE_DEVICE_TABLE(of, plat_nand_match);
130 
131 static struct platform_driver plat_nand_driver = {
132         .probe  = plat_nand_probe,
133         .remove = plat_nand_remove,
134         .driver = {
135                 .name           = "gen_nand",
136                 .of_match_table = plat_nand_match,
137         },
138 };
139 
140 module_platform_driver(plat_nand_driver);
141 
142 MODULE_LICENSE("GPL");
143 MODULE_AUTHOR("Vitaly Wool");
144 MODULE_DESCRIPTION("Simple generic NAND driver");
145 MODULE_ALIAS("platform:gen_nand");
146 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us