2 * rbtx4939-flash (based on physmap.c)
4 * This is a simplified physmap driver with map_init callback function.
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.
10 * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/device.h>
19 #include <linux/platform_device.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <asm/txx9/rbtx4939.h>
25 struct rbtx4939_flash_info
{
28 #ifdef CONFIG_MTD_PARTITIONS
30 struct mtd_partition
*parts
;
34 static int rbtx4939_flash_remove(struct platform_device
*dev
)
36 struct rbtx4939_flash_info
*info
;
38 info
= platform_get_drvdata(dev
);
41 platform_set_drvdata(dev
, NULL
);
44 #ifdef CONFIG_MTD_PARTITIONS
45 struct rbtx4939_flash_data
*pdata
= dev
->dev
.platform_data
;
48 del_mtd_partitions(info
->mtd
);
50 } else if (pdata
->nr_parts
)
51 del_mtd_partitions(info
->mtd
);
53 del_mtd_device(info
->mtd
);
55 del_mtd_device(info
->mtd
);
57 map_destroy(info
->mtd
);
62 static const char *rom_probe_types
[] = { "cfi_probe", "jedec_probe", NULL
};
63 #ifdef CONFIG_MTD_PARTITIONS
64 static const char *part_probe_types
[] = { "cmdlinepart", NULL
};
67 static int rbtx4939_flash_probe(struct platform_device
*dev
)
69 struct rbtx4939_flash_data
*pdata
;
70 struct rbtx4939_flash_info
*info
;
72 const char **probe_type
;
76 pdata
= dev
->dev
.platform_data
;
80 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
83 info
= devm_kzalloc(&dev
->dev
, sizeof(struct rbtx4939_flash_info
),
88 platform_set_drvdata(dev
, info
);
90 size
= resource_size(res
);
91 pr_notice("rbtx4939 platform flash device: %pR\n", res
);
93 if (!devm_request_mem_region(&dev
->dev
, res
->start
, size
,
97 info
->map
.name
= dev_name(&dev
->dev
);
98 info
->map
.phys
= res
->start
;
99 info
->map
.size
= size
;
100 info
->map
.bankwidth
= pdata
->width
;
102 info
->map
.virt
= devm_ioremap(&dev
->dev
, info
->map
.phys
, size
);
107 (*pdata
->map_init
)(&info
->map
);
109 simple_map_init(&info
->map
);
111 probe_type
= rom_probe_types
;
112 for (; !info
->mtd
&& *probe_type
; probe_type
++)
113 info
->mtd
= do_map_probe(*probe_type
, &info
->map
);
115 dev_err(&dev
->dev
, "map_probe failed\n");
119 info
->mtd
->owner
= THIS_MODULE
;
123 #ifdef CONFIG_MTD_PARTITIONS
124 err
= parse_mtd_partitions(info
->mtd
, part_probe_types
,
127 add_mtd_partitions(info
->mtd
, info
->parts
, err
);
128 info
->nr_parts
= err
;
132 if (pdata
->nr_parts
) {
133 pr_notice("Using rbtx4939 partition information\n");
134 add_mtd_partitions(info
->mtd
, pdata
->parts
, pdata
->nr_parts
);
139 add_mtd_device(info
->mtd
);
143 rbtx4939_flash_remove(dev
);
148 static int rbtx4939_flash_suspend(struct platform_device
*dev
,
151 struct rbtx4939_flash_info
*info
= platform_get_drvdata(dev
);
153 if (info
->mtd
->suspend
)
154 return info
->mtd
->suspend(info
->mtd
);
158 static int rbtx4939_flash_resume(struct platform_device
*dev
)
160 struct rbtx4939_flash_info
*info
= platform_get_drvdata(dev
);
162 if (info
->mtd
->resume
)
163 info
->mtd
->resume(info
->mtd
);
167 static void rbtx4939_flash_shutdown(struct platform_device
*dev
)
169 struct rbtx4939_flash_info
*info
= platform_get_drvdata(dev
);
171 if (info
->mtd
->suspend
&& info
->mtd
->resume
)
172 if (info
->mtd
->suspend(info
->mtd
) == 0)
173 info
->mtd
->resume(info
->mtd
);
176 #define rbtx4939_flash_suspend NULL
177 #define rbtx4939_flash_resume NULL
178 #define rbtx4939_flash_shutdown NULL
181 static struct platform_driver rbtx4939_flash_driver
= {
182 .probe
= rbtx4939_flash_probe
,
183 .remove
= rbtx4939_flash_remove
,
184 .suspend
= rbtx4939_flash_suspend
,
185 .resume
= rbtx4939_flash_resume
,
186 .shutdown
= rbtx4939_flash_shutdown
,
188 .name
= "rbtx4939-flash",
189 .owner
= THIS_MODULE
,
193 static int __init
rbtx4939_flash_init(void)
195 return platform_driver_register(&rbtx4939_flash_driver
);
198 static void __exit
rbtx4939_flash_exit(void)
200 platform_driver_unregister(&rbtx4939_flash_driver
);
203 module_init(rbtx4939_flash_init
);
204 module_exit(rbtx4939_flash_exit
);
206 MODULE_LICENSE("GPL");
207 MODULE_DESCRIPTION("RBTX4939 MTD map driver");
208 MODULE_ALIAS("platform:rbtx4939-flash");