diff options
author | Alexander Shiyan <shc_work@mail.ru> | 2012-08-15 12:28:06 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2012-09-29 09:55:19 -0400 |
commit | ce55754c4f3ea6985d19e24aa8972918bd07c88d (patch) | |
tree | fae3ea5859b30a26fa3d080e361227664207f28f | |
parent | d1f55c680e5d021e7066f4461dd678d42af18898 (diff) |
mtd: autcpu12-nvram: Convert driver to platform_device
Because we can have a single kernel to support multiple machines, we
need to make loading specific drivers for the target platform only.
For this, driver is converted to the platform driver.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r-- | arch/arm/mach-clps711x/autcpu12.c | 19 | ||||
-rw-r--r-- | drivers/mtd/maps/Kconfig | 2 | ||||
-rw-r--r-- | drivers/mtd/maps/autcpu12-nvram.c | 150 |
3 files changed, 101 insertions, 70 deletions
diff --git a/arch/arm/mach-clps711x/autcpu12.c b/arch/arm/mach-clps711x/autcpu12.c index 3fb79a1d0bde..32871918bb6e 100644 --- a/arch/arm/mach-clps711x/autcpu12.c +++ b/arch/arm/mach-clps711x/autcpu12.c | |||
@@ -23,6 +23,8 @@ | |||
23 | #include <linux/string.h> | 23 | #include <linux/string.h> |
24 | #include <linux/mm.h> | 24 | #include <linux/mm.h> |
25 | #include <linux/io.h> | 25 | #include <linux/io.h> |
26 | #include <linux/ioport.h> | ||
27 | #include <linux/platform_device.h> | ||
26 | 28 | ||
27 | #include <mach/hardware.h> | 29 | #include <mach/hardware.h> |
28 | #include <asm/sizes.h> | 30 | #include <asm/sizes.h> |
@@ -62,9 +64,26 @@ void __init autcpu12_map_io(void) | |||
62 | iotable_init(autcpu12_io_desc, ARRAY_SIZE(autcpu12_io_desc)); | 64 | iotable_init(autcpu12_io_desc, ARRAY_SIZE(autcpu12_io_desc)); |
63 | } | 65 | } |
64 | 66 | ||
67 | static struct resource autcpu12_nvram_resource[] __initdata = { | ||
68 | DEFINE_RES_MEM_NAMED(AUTCPU12_PHYS_NVRAM, SZ_128K, "SRAM"), | ||
69 | }; | ||
70 | |||
71 | static struct platform_device autcpu12_nvram_pdev __initdata = { | ||
72 | .name = "autcpu12_nvram", | ||
73 | .id = -1, | ||
74 | .resource = autcpu12_nvram_resource, | ||
75 | .num_resources = ARRAY_SIZE(autcpu12_nvram_resource), | ||
76 | }; | ||
77 | |||
78 | static void __init autcpu12_init(void) | ||
79 | { | ||
80 | platform_device_register(&autcpu12_nvram_pdev); | ||
81 | } | ||
82 | |||
65 | MACHINE_START(AUTCPU12, "autronix autcpu12") | 83 | MACHINE_START(AUTCPU12, "autronix autcpu12") |
66 | /* Maintainer: Thomas Gleixner */ | 84 | /* Maintainer: Thomas Gleixner */ |
67 | .atag_offset = 0x20000, | 85 | .atag_offset = 0x20000, |
86 | .init_machine = autcpu12_init, | ||
68 | .map_io = autcpu12_map_io, | 87 | .map_io = autcpu12_map_io, |
69 | .init_irq = clps711x_init_irq, | 88 | .init_irq = clps711x_init_irq, |
70 | .timer = &clps711x_timer, | 89 | .timer = &clps711x_timer, |
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 53850f19db8c..dbe7df1149d3 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig | |||
@@ -373,7 +373,7 @@ config MTD_FORTUNET | |||
373 | have such a board, say 'Y'. | 373 | have such a board, say 'Y'. |
374 | 374 | ||
375 | config MTD_AUTCPU12 | 375 | config MTD_AUTCPU12 |
376 | tristate "NV-RAM mapping AUTCPU12 board" | 376 | bool "NV-RAM mapping AUTCPU12 board" |
377 | depends on ARCH_AUTCPU12 | 377 | depends on ARCH_AUTCPU12 |
378 | help | 378 | help |
379 | This enables access to the NV-RAM on autronix autcpu12 board. | 379 | This enables access to the NV-RAM on autronix autcpu12 board. |
diff --git a/drivers/mtd/maps/autcpu12-nvram.c b/drivers/mtd/maps/autcpu12-nvram.c index 0598d52eaf9f..ef420d984d1a 100644 --- a/drivers/mtd/maps/autcpu12-nvram.c +++ b/drivers/mtd/maps/autcpu12-nvram.c | |||
@@ -15,44 +15,57 @@ | |||
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 | 30 | ||
34 | 31 | struct autcpu12_nvram_priv { | |
35 | static struct mtd_info *sram_mtd; | 32 | struct mtd_info *mtd; |
36 | 33 | struct map_info map; | |
37 | struct map_info autcpu12_sram_map = { | ||
38 | .name = "SRAM", | ||
39 | .size = 32768, | ||
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 | map_word tmp, save0, save1; | 38 | map_word tmp, save0, save1; |
39 | struct resource *res; | ||
40 | struct autcpu12_nvram_priv *priv; | ||
47 | int err; | 41 | int err; |
48 | 42 | ||
49 | autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K); | 43 | priv = devm_kzalloc(&pdev->dev, |
50 | if (!autcpu12_sram_map.virt) { | 44 | sizeof(struct autcpu12_nvram_priv), GFP_KERNEL); |
51 | printk("Failed to ioremap autcpu12 NV-RAM space\n"); | 45 | if (!priv) |
52 | err = -EIO; | 46 | return -ENOMEM; |
47 | |||
48 | platform_set_drvdata(pdev, priv); | ||
49 | |||
50 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
51 | if (!res) { | ||
52 | dev_err(&pdev->dev, "failed to get memory resource\n"); | ||
53 | err = -ENOENT; | ||
54 | goto out; | ||
55 | } | ||
56 | |||
57 | priv->map.bankwidth = 4; | ||
58 | priv->map.phys = res->start; | ||
59 | priv->map.size = resource_size(res); | ||
60 | priv->map.virt = devm_request_and_ioremap(&pdev->dev, res); | ||
61 | strcpy((char *)priv->map.name, res->name); | ||
62 | if (!priv->map.virt) { | ||
63 | dev_err(&pdev->dev, "failed to remap mem resource\n"); | ||
64 | err = -EBUSY; | ||
53 | goto out; | 65 | goto out; |
54 | } | 66 | } |
55 | simple_map_init(&autcpu12_sram_map); | 67 | |
68 | simple_map_init(&priv->map); | ||
56 | 69 | ||
57 | /* | 70 | /* |
58 | * Check for 32K/128K | 71 | * Check for 32K/128K |
@@ -62,67 +75,66 @@ static int __init init_autcpu12_sram (void) | |||
62 | * Read and check result on ofs 0x0 | 75 | * Read and check result on ofs 0x0 |
63 | * Restore contents | 76 | * Restore contents |
64 | */ | 77 | */ |
65 | save0 = map_read(&autcpu12_sram_map, 0); | 78 | save0 = map_read(&priv->map, 0); |
66 | save1 = map_read(&autcpu12_sram_map, 0x10000); | 79 | save1 = map_read(&priv->map, 0x10000); |
67 | tmp.x[0] = ~save0.x[0]; | 80 | tmp.x[0] = ~save0.x[0]; |
68 | map_write(&autcpu12_sram_map, tmp, 0x10000); | 81 | map_write(&priv->map, tmp, 0x10000); |
69 | /* if we find this pattern on 0x0, we have 32K size | 82 | tmp = map_read(&priv->map, 0); |
70 | * restore contents and exit | 83 | /* if we find this pattern on 0x0, we have 32K size */ |
71 | */ | 84 | if (!map_word_equal(&priv->map, tmp, save0)) { |
72 | tmp = map_read(&autcpu12_sram_map, 0); | 85 | map_write(&priv->map, save0, 0x0); |
73 | if (!map_word_equal(&autcpu12_sram_map, tmp, save0)) { | 86 | priv->map.size = SZ_32K; |
74 | map_write(&autcpu12_sram_map, save0, 0x0); | 87 | } else |
75 | goto map; | 88 | map_write(&priv->map, save1, 0x10000); |
76 | } | 89 | |
77 | /* We have a 128K found, restore 0x10000 and set size | 90 | priv->mtd = do_map_probe("map_ram", &priv->map); |
78 | * to 128K | 91 | if (!priv->mtd) { |
79 | */ | 92 | dev_err(&pdev->dev, "probing failed\n"); |
80 | map_write(&autcpu12_sram_map, save1, 0x10000); | ||
81 | autcpu12_sram_map.size = SZ_128K; | ||
82 | |||
83 | map: | ||
84 | sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map); | ||
85 | if (!sram_mtd) { | ||
86 | printk("NV-RAM probe failed\n"); | ||
87 | err = -ENXIO; | 93 | err = -ENXIO; |
88 | goto out_ioremap; | 94 | goto out; |
89 | } | 95 | } |
90 | 96 | ||
91 | sram_mtd->owner = THIS_MODULE; | 97 | priv->mtd->owner = THIS_MODULE; |
92 | sram_mtd->erasesize = 16; | 98 | priv->mtd->erasesize = 16; |
93 | 99 | priv->mtd->dev.parent = &pdev->dev; | |
94 | if (mtd_device_register(sram_mtd, NULL, 0)) { | 100 | if (!mtd_device_register(priv->mtd, NULL, 0)) { |
95 | printk("NV-RAM device addition failed\n"); | 101 | dev_info(&pdev->dev, |
96 | err = -ENOMEM; | 102 | "NV-RAM device size %ldKiB registered on AUTCPU12\n", |
97 | goto out_probe; | 103 | priv->map.size / SZ_1K); |
104 | return 0; | ||
98 | } | 105 | } |
99 | 106 | ||
100 | printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K); | 107 | map_destroy(priv->mtd); |
101 | 108 | dev_err(&pdev->dev, "NV-RAM device addition failed\n"); | |
102 | return 0; | 109 | err = -ENOMEM; |
103 | |||
104 | out_probe: | ||
105 | map_destroy(sram_mtd); | ||
106 | sram_mtd = 0; | ||
107 | 110 | ||
108 | out_ioremap: | ||
109 | iounmap((void *)autcpu12_sram_map.virt); | ||
110 | out: | 111 | out: |
112 | devm_kfree(&pdev->dev, priv); | ||
113 | |||
111 | return err; | 114 | return err; |
112 | } | 115 | } |
113 | 116 | ||
114 | static void __exit cleanup_autcpu12_maps(void) | 117 | static int __devexit autcpu12_nvram_remove(struct platform_device *pdev) |
115 | { | 118 | { |
116 | if (sram_mtd) { | 119 | struct autcpu12_nvram_priv *priv = platform_get_drvdata(pdev); |
117 | mtd_device_unregister(sram_mtd); | 120 | |
118 | map_destroy(sram_mtd); | 121 | mtd_device_unregister(priv->mtd); |
119 | iounmap((void *)autcpu12_sram_map.virt); | 122 | map_destroy(priv->mtd); |
120 | } | 123 | devm_kfree(&pdev->dev, priv); |
124 | |||
125 | return 0; | ||
121 | } | 126 | } |
122 | 127 | ||
123 | module_init(init_autcpu12_sram); | 128 | static struct platform_driver autcpu12_nvram_driver = { |
124 | module_exit(cleanup_autcpu12_maps); | 129 | .driver = { |
130 | .name = "autcpu12_nvram", | ||
131 | .owner = THIS_MODULE, | ||
132 | }, | ||
133 | .probe = autcpu12_nvram_probe, | ||
134 | .remove = __devexit_p(autcpu12_nvram_remove), | ||
135 | }; | ||
136 | module_platform_driver(autcpu12_nvram_driver); | ||
125 | 137 | ||
126 | MODULE_AUTHOR("Thomas Gleixner"); | 138 | MODULE_AUTHOR("Thomas Gleixner"); |
127 | MODULE_DESCRIPTION("autcpu12 NV-RAM map driver"); | 139 | MODULE_DESCRIPTION("autcpu12 NVRAM map driver"); |
128 | MODULE_LICENSE("GPL"); | 140 | MODULE_LICENSE("GPL"); |