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 static const char *part_probes
[] = { "cmdlinepart", NULL
, };
37 struct mtd_partition
*parts
;
38 struct onenand_chip onenand
;
41 static int __devinit
generic_onenand_probe(struct platform_device
*pdev
)
43 struct onenand_info
*info
;
44 struct onenand_platform_data
*pdata
= pdev
->dev
.platform_data
;
45 struct resource
*res
= pdev
->resource
;
46 unsigned long size
= resource_size(res
);
49 info
= kzalloc(sizeof(struct onenand_info
), GFP_KERNEL
);
53 if (!request_mem_region(res
->start
, size
, dev_name(&pdev
->dev
))) {
58 info
->onenand
.base
= ioremap(res
->start
, size
);
59 if (!info
->onenand
.base
) {
61 goto out_release_mem_region
;
64 info
->onenand
.mmcontrol
= pdata
? pdata
->mmcontrol
: 0;
65 info
->onenand
.irq
= platform_get_irq(pdev
, 0);
67 info
->mtd
.name
= dev_name(&pdev
->dev
);
68 info
->mtd
.priv
= &info
->onenand
;
69 info
->mtd
.owner
= THIS_MODULE
;
71 if (onenand_scan(&info
->mtd
, 1)) {
76 err
= parse_mtd_partitions(&info
->mtd
, part_probes
, &info
->parts
, 0);
78 mtd_device_register(&info
->mtd
, info
->parts
, err
);
79 else if (err
<= 0 && pdata
&& pdata
->parts
)
80 mtd_device_register(&info
->mtd
, pdata
->parts
, pdata
->nr_parts
);
82 err
= mtd_device_register(&info
->mtd
, NULL
, 0);
84 platform_set_drvdata(pdev
, info
);
89 iounmap(info
->onenand
.base
);
90 out_release_mem_region
:
91 release_mem_region(res
->start
, size
);
98 static int __devexit
generic_onenand_remove(struct platform_device
*pdev
)
100 struct onenand_info
*info
= platform_get_drvdata(pdev
);
101 struct resource
*res
= pdev
->resource
;
102 unsigned long size
= resource_size(res
);
104 platform_set_drvdata(pdev
, NULL
);
107 mtd_device_unregister(&info
->mtd
);
108 onenand_release(&info
->mtd
);
109 release_mem_region(res
->start
, size
);
110 iounmap(info
->onenand
.base
);
117 static struct platform_driver generic_onenand_driver
= {
120 .owner
= THIS_MODULE
,
122 .probe
= generic_onenand_probe
,
123 .remove
= __devexit_p(generic_onenand_remove
),
126 MODULE_ALIAS("platform:" DRIVER_NAME
);
128 static int __init
generic_onenand_init(void)
130 return platform_driver_register(&generic_onenand_driver
);
133 static void __exit
generic_onenand_exit(void)
135 platform_driver_unregister(&generic_onenand_driver
);
138 module_init(generic_onenand_init
);
139 module_exit(generic_onenand_exit
);
141 MODULE_LICENSE("GPL");
142 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
143 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");