2 * linux/drivers/mtd/onenand/generic.c
4 * Copyright (c) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 * This is a device driver for the OneNAND flash for generic boards.
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/platform_device.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/onenand.h>
21 #include <linux/mtd/partitions.h>
25 * Note: Driver name and platform data format have been updated!
27 * This version of the driver is named "onenand-flash" and takes struct
28 * onenand_platform_data as platform data. The old ARM-specific version
29 * with the name "onenand" used to take struct flash_platform_data.
31 #define DRIVER_NAME "onenand-flash"
33 #ifdef CONFIG_MTD_PARTITIONS
34 static const char *part_probes
[] = { "cmdlinepart", NULL
, };
39 struct mtd_partition
*parts
;
40 struct onenand_chip onenand
;
43 static int __devinit
generic_onenand_probe(struct platform_device
*pdev
)
45 struct onenand_info
*info
;
46 struct onenand_platform_data
*pdata
= pdev
->dev
.platform_data
;
47 struct resource
*res
= pdev
->resource
;
48 unsigned long size
= resource_size(res
);
51 info
= kzalloc(sizeof(struct onenand_info
), GFP_KERNEL
);
55 if (!request_mem_region(res
->start
, size
, dev_name(&pdev
->dev
))) {
60 info
->onenand
.base
= ioremap(res
->start
, size
);
61 if (!info
->onenand
.base
) {
63 goto out_release_mem_region
;
66 info
->onenand
.mmcontrol
= pdata
? pdata
->mmcontrol
: 0;
67 info
->onenand
.irq
= platform_get_irq(pdev
, 0);
69 info
->mtd
.name
= dev_name(&pdev
->dev
);
70 info
->mtd
.priv
= &info
->onenand
;
71 info
->mtd
.owner
= THIS_MODULE
;
73 if (onenand_scan(&info
->mtd
, 1)) {
78 #ifdef CONFIG_MTD_PARTITIONS
79 err
= parse_mtd_partitions(&info
->mtd
, part_probes
, &info
->parts
, 0);
81 add_mtd_partitions(&info
->mtd
, info
->parts
, err
);
82 else if (err
<= 0 && pdata
&& pdata
->parts
)
83 add_mtd_partitions(&info
->mtd
, pdata
->parts
, pdata
->nr_parts
);
86 err
= add_mtd_device(&info
->mtd
);
88 platform_set_drvdata(pdev
, info
);
93 iounmap(info
->onenand
.base
);
94 out_release_mem_region
:
95 release_mem_region(res
->start
, size
);
102 static int __devexit
generic_onenand_remove(struct platform_device
*pdev
)
104 struct onenand_info
*info
= platform_get_drvdata(pdev
);
105 struct resource
*res
= pdev
->resource
;
106 unsigned long size
= resource_size(res
);
108 platform_set_drvdata(pdev
, NULL
);
112 del_mtd_partitions(&info
->mtd
);
114 del_mtd_device(&info
->mtd
);
116 onenand_release(&info
->mtd
);
117 release_mem_region(res
->start
, size
);
118 iounmap(info
->onenand
.base
);
125 static struct platform_driver generic_onenand_driver
= {
128 .owner
= THIS_MODULE
,
130 .probe
= generic_onenand_probe
,
131 .remove
= __devexit_p(generic_onenand_remove
),
134 MODULE_ALIAS("platform:" DRIVER_NAME
);
136 static int __init
generic_onenand_init(void)
138 return platform_driver_register(&generic_onenand_driver
);
141 static void __exit
generic_onenand_exit(void)
143 platform_driver_unregister(&generic_onenand_driver
);
146 module_init(generic_onenand_init
);
147 module_exit(generic_onenand_exit
);
149 MODULE_LICENSE("GPL");
150 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
151 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");