Merge git://git.infradead.org/mtd-2.6
[linux-2.6] / arch / avr32 / boards / mimc200 / flash.c
1 /*
2  * MIMC200 board-specific flash initialization
3  *
4  * Copyright (C) 2008 Mercury IMC Ltd
5  *
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.
9  */
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/mtd/physmap.h>
15
16 #include <mach/smc.h>
17
18 static struct smc_timing flash_timing __initdata = {
19         .ncs_read_setup         = 0,
20         .nrd_setup              = 15,
21         .ncs_write_setup        = 0,
22         .nwe_setup              = 0,
23
24         .ncs_read_pulse         = 115,
25         .nrd_pulse              = 110,
26         .ncs_write_pulse        = 60,
27         .nwe_pulse              = 60,
28
29         .read_cycle             = 115,
30         .write_cycle            = 100,
31 };
32
33 static struct smc_config flash_config __initdata = {
34         .bus_width              = 2,
35         .nrd_controlled         = 1,
36         .nwe_controlled         = 1,
37         .byte_write             = 1,
38 };
39
40 /* system flash definition */
41
42 static struct mtd_partition flash_parts_system[] = {
43         {
44                 .name           = "u-boot",
45                 .offset         = 0x00000000,
46                 .size           = 0x00020000,           /* 128 KiB */
47                 .mask_flags     = MTD_WRITEABLE,
48         },
49         {
50                 .name           = "root",
51                 .offset         = 0x00020000,
52                 .size           = 0x007c0000,
53         },
54         {
55                 .name           = "splash",
56                 .offset         = 0x007e0000,
57                 .size           = 0x00010000,           /* 64KiB */
58         },
59         {
60                 .name           = "env",
61                 .offset         = 0x007f0000,
62                 .size           = 0x00010000,
63                 .mask_flags     = MTD_WRITEABLE,
64         },
65 };
66
67 static struct physmap_flash_data flash_system = {
68         .width          = 2,
69         .nr_parts       = ARRAY_SIZE(flash_parts_system),
70         .parts          = flash_parts_system,
71 };
72
73 static struct resource flash_resource_system = {
74         .start          = 0x00000000,
75         .end            = 0x007fffff,
76         .flags          = IORESOURCE_MEM,
77 };
78
79 static struct platform_device flash_device_system = {
80         .name           = "physmap-flash",
81         .id             = 0,
82         .resource       = &flash_resource_system,
83         .num_resources  = 1,
84         .dev            = {
85                 .platform_data = &flash_system,
86         },
87 };
88
89 /* data flash definition */
90
91 static struct mtd_partition flash_parts_data[] = {
92         {
93                 .name           = "data",
94                 .offset         = 0x00000000,
95                 .size           = 0x00800000,
96         },
97 };
98
99 static struct physmap_flash_data flash_data = {
100         .width          = 2,
101         .nr_parts       = ARRAY_SIZE(flash_parts_data),
102         .parts          = flash_parts_data,
103 };
104
105 static struct resource flash_resource_data = {
106         .start          = 0x08000000,
107         .end            = 0x087fffff,
108         .flags          = IORESOURCE_MEM,
109 };
110
111 static struct platform_device flash_device_data = {
112         .name           = "physmap-flash",
113         .id             = 1,
114         .resource       = &flash_resource_data,
115         .num_resources  = 1,
116         .dev            = {
117                 .platform_data = &flash_data,
118         },
119 };
120
121 /* This needs to be called after the SMC has been initialized */
122 static int __init mimc200_flash_init(void)
123 {
124         int ret;
125
126         smc_set_timing(&flash_config, &flash_timing);
127         ret = smc_set_configuration(0, &flash_config);
128         if (ret < 0) {
129                 printk(KERN_ERR "mimc200: failed to set 'System' NOR flash timing\n");
130                 return ret;
131         }
132         ret = smc_set_configuration(1, &flash_config);
133         if (ret < 0) {
134                 printk(KERN_ERR "mimc200: failed to set 'Data' NOR flash timing\n");
135                 return ret;
136         }
137
138         platform_device_register(&flash_device_system);
139         platform_device_register(&flash_device_data);
140
141         return 0;
142 }
143 device_initcall(mimc200_flash_init);