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
{
30 static int rbtx4939_flash_remove(struct platform_device
*dev
)
32 struct rbtx4939_flash_info
*info
;
34 info
= platform_get_drvdata(dev
);
37 platform_set_drvdata(dev
, NULL
);
40 struct rbtx4939_flash_data
*pdata
= dev
->dev
.platform_data
;
42 mtd_device_unregister(info
->mtd
);
43 map_destroy(info
->mtd
);
48 static const char *rom_probe_types
[] = { "cfi_probe", "jedec_probe", NULL
};
50 static int rbtx4939_flash_probe(struct platform_device
*dev
)
52 struct rbtx4939_flash_data
*pdata
;
53 struct rbtx4939_flash_info
*info
;
55 const char **probe_type
;
59 pdata
= dev
->dev
.platform_data
;
63 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
66 info
= devm_kzalloc(&dev
->dev
, sizeof(struct rbtx4939_flash_info
),
71 platform_set_drvdata(dev
, info
);
73 size
= resource_size(res
);
74 pr_notice("rbtx4939 platform flash device: %pR\n", res
);
76 if (!devm_request_mem_region(&dev
->dev
, res
->start
, size
,
80 info
->map
.name
= dev_name(&dev
->dev
);
81 info
->map
.phys
= res
->start
;
82 info
->map
.size
= size
;
83 info
->map
.bankwidth
= pdata
->width
;
85 info
->map
.virt
= devm_ioremap(&dev
->dev
, info
->map
.phys
, size
);
90 (*pdata
->map_init
)(&info
->map
);
92 simple_map_init(&info
->map
);
94 probe_type
= rom_probe_types
;
95 for (; !info
->mtd
&& *probe_type
; probe_type
++)
96 info
->mtd
= do_map_probe(*probe_type
, &info
->map
);
98 dev_err(&dev
->dev
, "map_probe failed\n");
102 info
->mtd
->owner
= THIS_MODULE
;
105 err
= mtd_device_parse_register(info
->mtd
, NULL
, 0,
106 pdata
->parts
, pdata
->nr_parts
);
113 rbtx4939_flash_remove(dev
);
118 static void rbtx4939_flash_shutdown(struct platform_device
*dev
)
120 struct rbtx4939_flash_info
*info
= platform_get_drvdata(dev
);
122 if (mtd_suspend(info
->mtd
) == 0)
123 mtd_resume(info
->mtd
);
126 #define rbtx4939_flash_shutdown NULL
129 static struct platform_driver rbtx4939_flash_driver
= {
130 .probe
= rbtx4939_flash_probe
,
131 .remove
= rbtx4939_flash_remove
,
132 .shutdown
= rbtx4939_flash_shutdown
,
134 .name
= "rbtx4939-flash",
135 .owner
= THIS_MODULE
,
139 module_platform_driver(rbtx4939_flash_driver
);
141 MODULE_LICENSE("GPL");
142 MODULE_DESCRIPTION("RBTX4939 MTD map driver");
143 MODULE_ALIAS("platform:rbtx4939-flash");