diff options
Diffstat (limited to 'drivers/mtd/maps/autcpu12-nvram.c')
-rw-r--r-- | drivers/mtd/maps/autcpu12-nvram.c | 153 |
1 files changed, 79 insertions, 74 deletions
diff --git a/drivers/mtd/maps/autcpu12-nvram.c b/drivers/mtd/maps/autcpu12-nvram.c index e5bfd0e093bb..76fb594bb1d9 100644 --- a/drivers/mtd/maps/autcpu12-nvram.c +++ b/drivers/mtd/maps/autcpu12-nvram.c | |||
@@ -15,43 +15,54 @@ | |||
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | * | ||
19 | */ | 18 | */ |
19 | #include <linux/sizes.h> | ||
20 | 20 | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/types.h> | 21 | #include <linux/types.h> |
23 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
24 | #include <linux/ioport.h> | ||
25 | #include <linux/init.h> | 23 | #include <linux/init.h> |
26 | #include <asm/io.h> | 24 | #include <linux/device.h> |
27 | #include <asm/sizes.h> | 25 | #include <linux/module.h> |
28 | #include <mach/hardware.h> | 26 | #include <linux/platform_device.h> |
29 | #include <mach/autcpu12.h> | 27 | |
30 | #include <linux/mtd/mtd.h> | 28 | #include <linux/mtd/mtd.h> |
31 | #include <linux/mtd/map.h> | 29 | #include <linux/mtd/map.h> |
32 | #include <linux/mtd/partitions.h> | ||
33 | |||
34 | |||
35 | static struct mtd_info *sram_mtd; | ||
36 | 30 | ||
37 | struct map_info autcpu12_sram_map = { | 31 | struct autcpu12_nvram_priv { |
38 | .name = "SRAM", | 32 | struct mtd_info *mtd; |
39 | .size = 32768, | 33 | struct map_info map; |
40 | .bankwidth = 4, | ||
41 | .phys = 0x12000000, | ||
42 | }; | 34 | }; |
43 | 35 | ||
44 | static int __init init_autcpu12_sram (void) | 36 | static int __devinit autcpu12_nvram_probe(struct platform_device *pdev) |
45 | { | 37 | { |
46 | int err, save0, save1; | 38 | map_word tmp, save0, save1; |
39 | struct resource *res; | ||
40 | struct autcpu12_nvram_priv *priv; | ||
47 | 41 | ||
48 | autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K); | 42 | priv = devm_kzalloc(&pdev->dev, |
49 | if (!autcpu12_sram_map.virt) { | 43 | sizeof(struct autcpu12_nvram_priv), GFP_KERNEL); |
50 | printk("Failed to ioremap autcpu12 NV-RAM space\n"); | 44 | if (!priv) |
51 | err = -EIO; | 45 | return -ENOMEM; |
52 | goto out; | 46 | |
47 | platform_set_drvdata(pdev, priv); | ||
48 | |||
49 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
50 | if (!res) { | ||
51 | dev_err(&pdev->dev, "failed to get memory resource\n"); | ||
52 | return -ENOENT; | ||
53 | } | ||
54 | |||
55 | priv->map.bankwidth = 4; | ||
56 | priv->map.phys = res->start; | ||
57 | priv->map.size = resource_size(res); | ||
58 | priv->map.virt = devm_request_and_ioremap(&pdev->dev, res); | ||
59 | strcpy((char *)priv->map.name, res->name); | ||
60 | if (!priv->map.virt) { | ||
61 | dev_err(&pdev->dev, "failed to remap mem resource\n"); | ||
62 | return -EBUSY; | ||
53 | } | 63 | } |
54 | simple_map_init(&autcpu_sram_map); | 64 | |
65 | simple_map_init(&priv->map); | ||
55 | 66 | ||
56 | /* | 67 | /* |
57 | * Check for 32K/128K | 68 | * Check for 32K/128K |
@@ -61,65 +72,59 @@ static int __init init_autcpu12_sram (void) | |||
61 | * Read and check result on ofs 0x0 | 72 | * Read and check result on ofs 0x0 |
62 | * Restore contents | 73 | * Restore contents |
63 | */ | 74 | */ |
64 | save0 = map_read32(&autcpu12_sram_map,0); | 75 | save0 = map_read(&priv->map, 0); |
65 | save1 = map_read32(&autcpu12_sram_map,0x10000); | 76 | save1 = map_read(&priv->map, 0x10000); |
66 | map_write32(&autcpu12_sram_map,~save0,0x10000); | 77 | tmp.x[0] = ~save0.x[0]; |
67 | /* if we find this pattern on 0x0, we have 32K size | 78 | map_write(&priv->map, tmp, 0x10000); |
68 | * restore contents and exit | 79 | tmp = map_read(&priv->map, 0); |
69 | */ | 80 | /* if we find this pattern on 0x0, we have 32K size */ |
70 | if ( map_read32(&autcpu12_sram_map,0) != save0) { | 81 | if (!map_word_equal(&priv->map, tmp, save0)) { |
71 | map_write32(&autcpu12_sram_map,save0,0x0); | 82 | map_write(&priv->map, save0, 0x0); |
72 | goto map; | 83 | priv->map.size = SZ_32K; |
84 | } else | ||
85 | map_write(&priv->map, save1, 0x10000); | ||
86 | |||
87 | priv->mtd = do_map_probe("map_ram", &priv->map); | ||
88 | if (!priv->mtd) { | ||
89 | dev_err(&pdev->dev, "probing failed\n"); | ||
90 | return -ENXIO; | ||
73 | } | 91 | } |
74 | /* We have a 128K found, restore 0x10000 and set size | ||
75 | * to 128K | ||
76 | */ | ||
77 | map_write32(&autcpu12_sram_map,save1,0x10000); | ||
78 | autcpu12_sram_map.size = SZ_128K; | ||
79 | |||
80 | map: | ||
81 | sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map); | ||
82 | if (!sram_mtd) { | ||
83 | printk("NV-RAM probe failed\n"); | ||
84 | err = -ENXIO; | ||
85 | goto out_ioremap; | ||
86 | } | ||
87 | |||
88 | sram_mtd->owner = THIS_MODULE; | ||
89 | sram_mtd->erasesize = 16; | ||
90 | 92 | ||
91 | if (mtd_device_register(sram_mtd, NULL, 0)) { | 93 | priv->mtd->owner = THIS_MODULE; |
92 | printk("NV-RAM device addition failed\n"); | 94 | priv->mtd->erasesize = 16; |
93 | err = -ENOMEM; | 95 | priv->mtd->dev.parent = &pdev->dev; |
94 | goto out_probe; | 96 | if (!mtd_device_register(priv->mtd, NULL, 0)) { |
97 | dev_info(&pdev->dev, | ||
98 | "NV-RAM device size %ldKiB registered on AUTCPU12\n", | ||
99 | priv->map.size / SZ_1K); | ||
100 | return 0; | ||
95 | } | 101 | } |
96 | 102 | ||
97 | printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K); | 103 | map_destroy(priv->mtd); |
98 | 104 | dev_err(&pdev->dev, "NV-RAM device addition failed\n"); | |
99 | return 0; | 105 | return -ENOMEM; |
100 | |||
101 | out_probe: | ||
102 | map_destroy(sram_mtd); | ||
103 | sram_mtd = 0; | ||
104 | |||
105 | out_ioremap: | ||
106 | iounmap((void *)autcpu12_sram_map.virt); | ||
107 | out: | ||
108 | return err; | ||
109 | } | 106 | } |
110 | 107 | ||
111 | static void __exit cleanup_autcpu12_maps(void) | 108 | static int __devexit autcpu12_nvram_remove(struct platform_device *pdev) |
112 | { | 109 | { |
113 | if (sram_mtd) { | 110 | struct autcpu12_nvram_priv *priv = platform_get_drvdata(pdev); |
114 | mtd_device_unregister(sram_mtd); | 111 | |
115 | map_destroy(sram_mtd); | 112 | mtd_device_unregister(priv->mtd); |
116 | iounmap((void *)autcpu12_sram_map.virt); | 113 | map_destroy(priv->mtd); |
117 | } | 114 | |
115 | return 0; | ||
118 | } | 116 | } |
119 | 117 | ||
120 | module_init(init_autcpu12_sram); | 118 | static struct platform_driver autcpu12_nvram_driver = { |
121 | module_exit(cleanup_autcpu12_maps); | 119 | .driver = { |
120 | .name = "autcpu12_nvram", | ||
121 | .owner = THIS_MODULE, | ||
122 | }, | ||
123 | .probe = autcpu12_nvram_probe, | ||
124 | .remove = __devexit_p(autcpu12_nvram_remove), | ||
125 | }; | ||
126 | module_platform_driver(autcpu12_nvram_driver); | ||
122 | 127 | ||
123 | MODULE_AUTHOR("Thomas Gleixner"); | 128 | MODULE_AUTHOR("Thomas Gleixner"); |
124 | MODULE_DESCRIPTION("autcpu12 NV-RAM map driver"); | 129 | MODULE_DESCRIPTION("autcpu12 NVRAM map driver"); |
125 | MODULE_LICENSE("GPL"); | 130 | MODULE_LICENSE("GPL"); |