blob: f9ba43635dc1eb14af700819b0c8f2a5b975177d [file] [log] [blame]
Magnus Damme7d16512009-07-22 16:20:54 +00001/*
2 * KFR2R09 board support code
3 *
4 * Copyright (C) 2009 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/init.h>
11#include <linux/platform_device.h>
12#include <linux/interrupt.h>
Magnus Damma366aa642009-07-22 16:22:28 +000013#include <linux/mtd/physmap.h>
Magnus Damm33893d72009-08-06 14:58:43 +000014#include <linux/mtd/onenand.h>
Magnus Damme7d16512009-07-22 16:20:54 +000015#include <linux/delay.h>
16#include <linux/clk.h>
17#include <linux/gpio.h>
Magnus Damm39a6bf12009-07-22 16:23:45 +000018#include <linux/input.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000019#include <video/sh_mobile_lcdc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000020#include <asm/clock.h>
21#include <asm/machvec.h>
22#include <asm/io.h>
Magnus Damm39a6bf12009-07-22 16:23:45 +000023#include <asm/sh_keysc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000024#include <cpu/sh7724.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000025#include <mach/kfr2r09.h>
Magnus Damme7d16512009-07-22 16:20:54 +000026
Magnus Damma366aa642009-07-22 16:22:28 +000027static struct mtd_partition kfr2r09_nor_flash_partitions[] =
28{
29 {
30 .name = "boot",
31 .offset = 0,
32 .size = (4 * 1024 * 1024),
33 .mask_flags = MTD_WRITEABLE, /* Read-only */
34 },
35 {
36 .name = "other",
37 .offset = MTDPART_OFS_APPEND,
38 .size = MTDPART_SIZ_FULL,
39 },
40};
41
42static struct physmap_flash_data kfr2r09_nor_flash_data = {
43 .width = 2,
44 .parts = kfr2r09_nor_flash_partitions,
45 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
46};
47
48static struct resource kfr2r09_nor_flash_resources[] = {
49 [0] = {
50 .name = "NOR Flash",
51 .start = 0x00000000,
52 .end = 0x03ffffff,
53 .flags = IORESOURCE_MEM,
54 }
55};
56
57static struct platform_device kfr2r09_nor_flash_device = {
58 .name = "physmap-flash",
59 .resource = kfr2r09_nor_flash_resources,
60 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
61 .dev = {
62 .platform_data = &kfr2r09_nor_flash_data,
63 },
64};
65
Magnus Damm33893d72009-08-06 14:58:43 +000066static struct resource kfr2r09_nand_flash_resources[] = {
67 [0] = {
68 .name = "NAND Flash",
69 .start = 0x10000000,
70 .end = 0x1001ffff,
71 .flags = IORESOURCE_MEM,
72 }
73};
74
75static struct platform_device kfr2r09_nand_flash_device = {
76 .name = "onenand-flash",
77 .resource = kfr2r09_nand_flash_resources,
78 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
79};
80
Magnus Damm39a6bf12009-07-22 16:23:45 +000081static struct sh_keysc_info kfr2r09_sh_keysc_info = {
82 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
83 .scan_timing = 3,
84 .delay = 10,
85 .keycodes = {
86 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
87 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
88 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
89 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
90 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
91 0, 0, 0, 0, 0
92 },
93};
94
95static struct resource kfr2r09_sh_keysc_resources[] = {
96 [0] = {
97 .name = "KEYSC",
98 .start = 0x044b0000,
99 .end = 0x044b000f,
100 .flags = IORESOURCE_MEM,
101 },
102 [1] = {
103 .start = 79,
104 .flags = IORESOURCE_IRQ,
105 },
106};
107
108static struct platform_device kfr2r09_sh_keysc_device = {
109 .name = "sh_keysc",
110 .id = 0, /* "keysc0" clock */
111 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
112 .resource = kfr2r09_sh_keysc_resources,
113 .dev = {
114 .platform_data = &kfr2r09_sh_keysc_info,
115 },
Magnus Damm442c3752009-07-31 07:48:21 +0000116 .archdata = {
117 .hwblk_id = HWBLK_KEYSC,
118 },
Magnus Damm39a6bf12009-07-22 16:23:45 +0000119};
120
Magnus Damm9f26e652009-08-06 14:51:30 +0000121static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
122 .clock_source = LCDC_CLK_BUS,
123 .ch[0] = {
124 .chan = LCDC_CHAN_MAINLCD,
125 .bpp = 16,
126 .interface_type = SYS18,
127 .clock_divider = 6,
128 .flags = LCDC_FLAGS_DWPOL,
129 .lcd_cfg = {
130 .name = "TX07D34VM0AAA",
131 .xres = 240,
132 .yres = 400,
133 .left_margin = 0,
134 .right_margin = 16,
135 .hsync_len = 8,
136 .upper_margin = 0,
137 .lower_margin = 1,
138 .vsync_len = 1,
139 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
140 },
141 .lcd_size_cfg = {
142 .width = 35,
143 .height = 58,
144 },
145 .board_cfg = {
146 .setup_sys = kfr2r09_lcd_setup,
147 .display_on = kfr2r09_lcd_on,
148 .display_off = kfr2r09_lcd_off,
149 },
150 .sys_bus_cfg = {
151 .ldmt2r = 0x07010904,
152 .ldmt3r = 0x14012914,
153 /* set 1s delay to encourage fsync() */
154 .deferred_io_msec = 1000,
155 },
156 }
157};
158
159static struct resource kfr2r09_sh_lcdc_resources[] = {
160 [0] = {
161 .name = "LCDC",
162 .start = 0xfe940000, /* P4-only space */
163 .end = 0xfe941fff,
164 .flags = IORESOURCE_MEM,
165 },
166 [1] = {
167 .start = 106,
168 .flags = IORESOURCE_IRQ,
169 },
170};
171
172static struct platform_device kfr2r09_sh_lcdc_device = {
173 .name = "sh_mobile_lcdc_fb",
174 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
175 .resource = kfr2r09_sh_lcdc_resources,
176 .dev = {
177 .platform_data = &kfr2r09_sh_lcdc_info,
178 },
Magnus Damm963e04c2009-08-15 03:02:08 +0000179 .archdata = {
180 .hwblk_id = HWBLK_LCDC,
181 },
Magnus Damm9f26e652009-08-06 14:51:30 +0000182};
183
Magnus Damma366aa642009-07-22 16:22:28 +0000184static struct platform_device *kfr2r09_devices[] __initdata = {
185 &kfr2r09_nor_flash_device,
Magnus Damm33893d72009-08-06 14:58:43 +0000186 &kfr2r09_nand_flash_device,
Magnus Damm39a6bf12009-07-22 16:23:45 +0000187 &kfr2r09_sh_keysc_device,
Magnus Damm9f26e652009-08-06 14:51:30 +0000188 &kfr2r09_sh_lcdc_device,
Magnus Damma366aa642009-07-22 16:22:28 +0000189};
190
191#define BSC_CS0BCR 0xfec10004
192#define BSC_CS0WCR 0xfec10024
Magnus Damm33893d72009-08-06 14:58:43 +0000193#define BSC_CS4BCR 0xfec10010
194#define BSC_CS4WCR 0xfec10030
Magnus Damma366aa642009-07-22 16:22:28 +0000195
Magnus Damme7d16512009-07-22 16:20:54 +0000196static int __init kfr2r09_devices_setup(void)
197{
198 /* enable SCIF1 serial port for YC401 console support */
199 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
200 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
201
Magnus Damma366aa642009-07-22 16:22:28 +0000202 /* setup NOR flash at CS0 */
203 ctrl_outl(0x36db0400, BSC_CS0BCR);
204 ctrl_outl(0x00000500, BSC_CS0WCR);
205
Magnus Damm33893d72009-08-06 14:58:43 +0000206 /* setup NAND flash at CS4 */
207 ctrl_outl(0x36db0400, BSC_CS4BCR);
208 ctrl_outl(0x00000500, BSC_CS4WCR);
209
Magnus Damm39a6bf12009-07-22 16:23:45 +0000210 /* setup KEYSC pins */
211 gpio_request(GPIO_FN_KEYOUT0, NULL);
212 gpio_request(GPIO_FN_KEYOUT1, NULL);
213 gpio_request(GPIO_FN_KEYOUT2, NULL);
214 gpio_request(GPIO_FN_KEYOUT3, NULL);
215 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
216 gpio_request(GPIO_FN_KEYIN0, NULL);
217 gpio_request(GPIO_FN_KEYIN1, NULL);
218 gpio_request(GPIO_FN_KEYIN2, NULL);
219 gpio_request(GPIO_FN_KEYIN3, NULL);
220 gpio_request(GPIO_FN_KEYIN4, NULL);
221 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
222
Magnus Damm9f26e652009-08-06 14:51:30 +0000223 /* setup LCDC pins for SYS panel */
224 gpio_request(GPIO_FN_LCDD17, NULL);
225 gpio_request(GPIO_FN_LCDD16, NULL);
226 gpio_request(GPIO_FN_LCDD15, NULL);
227 gpio_request(GPIO_FN_LCDD14, NULL);
228 gpio_request(GPIO_FN_LCDD13, NULL);
229 gpio_request(GPIO_FN_LCDD12, NULL);
230 gpio_request(GPIO_FN_LCDD11, NULL);
231 gpio_request(GPIO_FN_LCDD10, NULL);
232 gpio_request(GPIO_FN_LCDD9, NULL);
233 gpio_request(GPIO_FN_LCDD8, NULL);
234 gpio_request(GPIO_FN_LCDD7, NULL);
235 gpio_request(GPIO_FN_LCDD6, NULL);
236 gpio_request(GPIO_FN_LCDD5, NULL);
237 gpio_request(GPIO_FN_LCDD4, NULL);
238 gpio_request(GPIO_FN_LCDD3, NULL);
239 gpio_request(GPIO_FN_LCDD2, NULL);
240 gpio_request(GPIO_FN_LCDD1, NULL);
241 gpio_request(GPIO_FN_LCDD0, NULL);
242 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
243 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
244 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
245 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
246 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
247 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
248 gpio_direction_output(GPIO_PTE4, 1);
249 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
250 gpio_direction_output(GPIO_PTF4, 1);
251 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
252 gpio_direction_output(GPIO_PTU0, 1);
253
Magnus Damma366aa642009-07-22 16:22:28 +0000254 return platform_add_devices(kfr2r09_devices,
255 ARRAY_SIZE(kfr2r09_devices));
Magnus Damme7d16512009-07-22 16:20:54 +0000256}
257device_initcall(kfr2r09_devices_setup);
258
259/* Return the board specific boot mode pin configuration */
260static int kfr2r09_mode_pins(void)
261{
262 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
263 * MD3=0: 16-bit Area0 Bus Width
264 * MD5=1: Little Endian
265 * MD8=1: Test Mode Disabled
266 */
267 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
268}
269
270/*
271 * The Machine Vector
272 */
273static struct sh_machine_vector mv_kfr2r09 __initmv = {
274 .mv_name = "kfr2r09",
275 .mv_mode_pins = kfr2r09_mode_pins,
276};