aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/nand/sharpsl.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 0a99188a7730..6851806b7015 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -26,6 +26,11 @@
26#include <mach/hardware.h> 26#include <mach/hardware.h>
27#include <asm/mach-types.h> 27#include <asm/mach-types.h>
28 28
29struct sharpsl_nand {
30 struct mtd_info mtd;
31 struct nand_chip chip;
32};
33
29static void __iomem *sharpsl_io_base; 34static void __iomem *sharpsl_io_base;
30 35
31/* register offset */ 36/* register offset */
@@ -46,11 +51,6 @@ static void __iomem *sharpsl_io_base;
46#define FLCE0 (1 << 0) 51#define FLCE0 (1 << 0)
47 52
48/* 53/*
49 * MTD structure for SharpSL
50 */
51static struct mtd_info *sharpsl_mtd = NULL;
52
53/*
54 * Define partitions for flash device 54 * Define partitions for flash device
55 */ 55 */
56#define DEFAULT_NUM_PARTITIONS 3 56#define DEFAULT_NUM_PARTITIONS 3
@@ -157,10 +157,11 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
157 struct mtd_partition *sharpsl_partition_info; 157 struct mtd_partition *sharpsl_partition_info;
158 struct resource *r; 158 struct resource *r;
159 int err = 0; 159 int err = 0;
160 struct sharpsl_nand *sharpsl;
160 161
161 /* Allocate memory for MTD device structure and private data */ 162 /* Allocate memory for MTD device structure and private data */
162 sharpsl_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 163 sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL);
163 if (!sharpsl_mtd) { 164 if (!sharpsl) {
164 printk("Unable to allocate SharpSL NAND MTD device structure.\n"); 165 printk("Unable to allocate SharpSL NAND MTD device structure.\n");
165 return -ENOMEM; 166 return -ENOMEM;
166 } 167 }
@@ -176,20 +177,18 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
176 sharpsl_io_base = ioremap(r->start, resource_size(r)); 177 sharpsl_io_base = ioremap(r->start, resource_size(r));
177 if (!sharpsl_io_base) { 178 if (!sharpsl_io_base) {
178 printk("ioremap to access Sharp SL NAND chip failed\n"); 179 printk("ioremap to access Sharp SL NAND chip failed\n");
179 kfree(sharpsl_mtd); 180 err = -EIO;
180 return -EIO; 181 goto err_ioremap;
181 } 182 }
182 183
183 /* Get pointer to private data */ 184 /* Get pointer to private data */
184 this = (struct nand_chip *)(&sharpsl_mtd[1]); 185 this = (struct nand_chip *)(&sharpsl->chip);
185
186 /* Initialize structures */
187 memset(sharpsl_mtd, 0, sizeof(struct mtd_info));
188 memset(this, 0, sizeof(struct nand_chip));
189 186
190 /* Link the private data with the MTD structure */ 187 /* Link the private data with the MTD structure */
191 sharpsl_mtd->priv = this; 188 sharpsl->mtd.priv = this;
192 sharpsl_mtd->owner = THIS_MODULE; 189 sharpsl->mtd.owner = THIS_MODULE;
190
191 platform_set_drvdata(pdev, sharpsl);
193 192
194 /* 193 /*
195 * PXA initialize 194 * PXA initialize
@@ -218,16 +217,17 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
218 this->ecc.correct = nand_correct_data; 217 this->ecc.correct = nand_correct_data;
219 218
220 /* Scan to find existence of the device */ 219 /* Scan to find existence of the device */
221 err = nand_scan(sharpsl_mtd, 1); 220 err = nand_scan(&sharpsl->mtd, 1);
222 if (err) { 221 if (err) {
222 platform_set_drvdata(pdev, NULL);
223 iounmap(sharpsl_io_base); 223 iounmap(sharpsl_io_base);
224 kfree(sharpsl_mtd); 224 kfree(sharpsl);
225 return err; 225 return err;
226 } 226 }
227 227
228 /* Register the partitions */ 228 /* Register the partitions */
229 sharpsl_mtd->name = "sharpsl-nand"; 229 sharpsl->mtd.name = "sharpsl-nand";
230 nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, &sharpsl_partition_info, 0); 230 nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0);
231 231
232 if (nr_partitions <= 0) { 232 if (nr_partitions <= 0) {
233 nr_partitions = DEFAULT_NUM_PARTITIONS; 233 nr_partitions = DEFAULT_NUM_PARTITIONS;
@@ -247,13 +247,14 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
247 } 247 }
248 } 248 }
249 249
250 add_mtd_partitions(sharpsl_mtd, sharpsl_partition_info, nr_partitions); 250 add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions);
251 251
252 /* Return happy */ 252 /* Return happy */
253 return 0; 253 return 0;
254 254
255err_ioremap:
255err_get_res: 256err_get_res:
256 kfree(sharpsl_mtd); 257 kfree(sharpsl);
257 return err; 258 return err;
258} 259}
259 260
@@ -262,13 +263,17 @@ err_get_res:
262 */ 263 */
263static int __devexit sharpsl_nand_remove(struct platform_device *pdev) 264static int __devexit sharpsl_nand_remove(struct platform_device *pdev)
264{ 265{
266 struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev);
267
265 /* Release resources, unregister device */ 268 /* Release resources, unregister device */
266 nand_release(sharpsl_mtd); 269 nand_release(&sharpsl->mtd);
270
271 platform_set_drvdata(pdev, NULL);
267 272
268 iounmap(sharpsl_io_base); 273 iounmap(sharpsl_io_base);
269 274
270 /* Free the MTD device structure */ 275 /* Free the MTD device structure */
271 kfree(sharpsl_mtd); 276 kfree(sharpsl);
272 277
273 return 0; 278 return 0;
274} 279}