blob: 6ce550cf9ba9239ecb9ed4629f7785a025c88809 [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 Damm5a1c4cb2009-08-19 14:39:15 +000019#include <linux/i2c.h>
20#include <linux/usb/r8a66597.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000021#include <video/sh_mobile_lcdc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000022#include <asm/clock.h>
23#include <asm/machvec.h>
24#include <asm/io.h>
Magnus Damm39a6bf12009-07-22 16:23:45 +000025#include <asm/sh_keysc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000026#include <cpu/sh7724.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000027#include <mach/kfr2r09.h>
Magnus Damme7d16512009-07-22 16:20:54 +000028
Magnus Damma366aa642009-07-22 16:22:28 +000029static struct mtd_partition kfr2r09_nor_flash_partitions[] =
30{
31 {
32 .name = "boot",
33 .offset = 0,
34 .size = (4 * 1024 * 1024),
35 .mask_flags = MTD_WRITEABLE, /* Read-only */
36 },
37 {
38 .name = "other",
39 .offset = MTDPART_OFS_APPEND,
40 .size = MTDPART_SIZ_FULL,
41 },
42};
43
44static struct physmap_flash_data kfr2r09_nor_flash_data = {
45 .width = 2,
46 .parts = kfr2r09_nor_flash_partitions,
47 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
48};
49
50static struct resource kfr2r09_nor_flash_resources[] = {
51 [0] = {
52 .name = "NOR Flash",
53 .start = 0x00000000,
54 .end = 0x03ffffff,
55 .flags = IORESOURCE_MEM,
56 }
57};
58
59static struct platform_device kfr2r09_nor_flash_device = {
60 .name = "physmap-flash",
61 .resource = kfr2r09_nor_flash_resources,
62 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
63 .dev = {
64 .platform_data = &kfr2r09_nor_flash_data,
65 },
66};
67
Magnus Damm33893d72009-08-06 14:58:43 +000068static struct resource kfr2r09_nand_flash_resources[] = {
69 [0] = {
70 .name = "NAND Flash",
71 .start = 0x10000000,
72 .end = 0x1001ffff,
73 .flags = IORESOURCE_MEM,
74 }
75};
76
77static struct platform_device kfr2r09_nand_flash_device = {
78 .name = "onenand-flash",
79 .resource = kfr2r09_nand_flash_resources,
80 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
81};
82
Magnus Damm39a6bf12009-07-22 16:23:45 +000083static struct sh_keysc_info kfr2r09_sh_keysc_info = {
84 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
85 .scan_timing = 3,
86 .delay = 10,
87 .keycodes = {
88 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
89 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
90 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
91 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
92 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
93 0, 0, 0, 0, 0
94 },
95};
96
97static struct resource kfr2r09_sh_keysc_resources[] = {
98 [0] = {
99 .name = "KEYSC",
100 .start = 0x044b0000,
101 .end = 0x044b000f,
102 .flags = IORESOURCE_MEM,
103 },
104 [1] = {
105 .start = 79,
106 .flags = IORESOURCE_IRQ,
107 },
108};
109
110static struct platform_device kfr2r09_sh_keysc_device = {
111 .name = "sh_keysc",
112 .id = 0, /* "keysc0" clock */
113 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
114 .resource = kfr2r09_sh_keysc_resources,
115 .dev = {
116 .platform_data = &kfr2r09_sh_keysc_info,
117 },
Magnus Damm442c3752009-07-31 07:48:21 +0000118 .archdata = {
119 .hwblk_id = HWBLK_KEYSC,
120 },
Magnus Damm39a6bf12009-07-22 16:23:45 +0000121};
122
Magnus Damm9f26e652009-08-06 14:51:30 +0000123static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
124 .clock_source = LCDC_CLK_BUS,
125 .ch[0] = {
126 .chan = LCDC_CHAN_MAINLCD,
127 .bpp = 16,
128 .interface_type = SYS18,
129 .clock_divider = 6,
130 .flags = LCDC_FLAGS_DWPOL,
131 .lcd_cfg = {
132 .name = "TX07D34VM0AAA",
133 .xres = 240,
134 .yres = 400,
135 .left_margin = 0,
136 .right_margin = 16,
137 .hsync_len = 8,
138 .upper_margin = 0,
139 .lower_margin = 1,
140 .vsync_len = 1,
141 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
142 },
143 .lcd_size_cfg = {
144 .width = 35,
145 .height = 58,
146 },
147 .board_cfg = {
148 .setup_sys = kfr2r09_lcd_setup,
149 .display_on = kfr2r09_lcd_on,
150 .display_off = kfr2r09_lcd_off,
151 },
152 .sys_bus_cfg = {
153 .ldmt2r = 0x07010904,
154 .ldmt3r = 0x14012914,
155 /* set 1s delay to encourage fsync() */
156 .deferred_io_msec = 1000,
157 },
158 }
159};
160
161static struct resource kfr2r09_sh_lcdc_resources[] = {
162 [0] = {
163 .name = "LCDC",
164 .start = 0xfe940000, /* P4-only space */
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000165 .end = 0xfe942fff,
Magnus Damm9f26e652009-08-06 14:51:30 +0000166 .flags = IORESOURCE_MEM,
167 },
168 [1] = {
169 .start = 106,
170 .flags = IORESOURCE_IRQ,
171 },
172};
173
174static struct platform_device kfr2r09_sh_lcdc_device = {
175 .name = "sh_mobile_lcdc_fb",
176 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
177 .resource = kfr2r09_sh_lcdc_resources,
178 .dev = {
179 .platform_data = &kfr2r09_sh_lcdc_info,
180 },
Magnus Damm963e04c2009-08-15 03:02:08 +0000181 .archdata = {
182 .hwblk_id = HWBLK_LCDC,
183 },
Magnus Damm9f26e652009-08-06 14:51:30 +0000184};
185
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000186static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
187 .on_chip = 1,
188};
189
190static struct resource kfr2r09_usb0_gadget_resources[] = {
191 [0] = {
192 .start = 0x04d80000,
193 .end = 0x04d80123,
194 .flags = IORESOURCE_MEM,
195 },
196 [1] = {
197 .start = 65,
198 .end = 65,
199 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
200 },
201};
202
203static struct platform_device kfr2r09_usb0_gadget_device = {
204 .name = "r8a66597_udc",
205 .id = 0,
206 .dev = {
207 .dma_mask = NULL, /* not use dma */
208 .coherent_dma_mask = 0xffffffff,
209 .platform_data = &kfr2r09_usb0_gadget_data,
210 },
211 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
212 .resource = kfr2r09_usb0_gadget_resources,
213};
214
Magnus Dammd2a2fb92009-10-02 02:23:19 +0000215static struct resource kfr2r09_sh_sdhi0_resources[] = {
216 [0] = {
217 .name = "SDHI0",
218 .start = 0x04ce0000,
219 .end = 0x04ce01ff,
220 .flags = IORESOURCE_MEM,
221 },
222 [1] = {
223 .start = 101,
224 .flags = IORESOURCE_IRQ,
225 },
226};
227
228static struct platform_device kfr2r09_sh_sdhi0_device = {
229 .name = "sh_mobile_sdhi",
230 .num_resources = ARRAY_SIZE(kfr2r09_sh_sdhi0_resources),
231 .resource = kfr2r09_sh_sdhi0_resources,
232 .archdata = {
233 .hwblk_id = HWBLK_SDHI0,
234 },
235};
236
Magnus Damma366aa642009-07-22 16:22:28 +0000237static struct platform_device *kfr2r09_devices[] __initdata = {
238 &kfr2r09_nor_flash_device,
Magnus Damm33893d72009-08-06 14:58:43 +0000239 &kfr2r09_nand_flash_device,
Magnus Damm39a6bf12009-07-22 16:23:45 +0000240 &kfr2r09_sh_keysc_device,
Magnus Damm9f26e652009-08-06 14:51:30 +0000241 &kfr2r09_sh_lcdc_device,
Magnus Dammd2a2fb92009-10-02 02:23:19 +0000242 &kfr2r09_sh_sdhi0_device,
Magnus Damma366aa642009-07-22 16:22:28 +0000243};
244
245#define BSC_CS0BCR 0xfec10004
246#define BSC_CS0WCR 0xfec10024
Magnus Damm33893d72009-08-06 14:58:43 +0000247#define BSC_CS4BCR 0xfec10010
248#define BSC_CS4WCR 0xfec10030
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000249#define PORT_MSELCRB 0xa4050182
250
Magnus Damm045a4b72009-08-20 13:57:36 +0000251#ifdef CONFIG_I2C
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000252static int kfr2r09_usb0_gadget_i2c_setup(void)
253{
254 struct i2c_adapter *a;
255 struct i2c_msg msg;
256 unsigned char buf[2];
257 int ret;
258
259 a = i2c_get_adapter(0);
260 if (!a)
261 return -ENODEV;
262
263 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
264 buf[0] = 0x13;
265 msg.addr = 0x09;
266 msg.buf = buf;
267 msg.len = 1;
268 msg.flags = 0;
269 ret = i2c_transfer(a, &msg, 1);
270 if (ret != 1)
271 return -ENODEV;
272
273 buf[0] = 0;
274 msg.addr = 0x09;
275 msg.buf = buf;
276 msg.len = 1;
277 msg.flags = I2C_M_RD;
278 ret = i2c_transfer(a, &msg, 1);
279 if (ret != 1)
280 return -ENODEV;
281
282 buf[1] = buf[0] | (1 << 1);
283 buf[0] = 0x13;
284 msg.addr = 0x09;
285 msg.buf = buf;
286 msg.len = 2;
287 msg.flags = 0;
288 ret = i2c_transfer(a, &msg, 1);
289 if (ret != 1)
290 return -ENODEV;
291
292 return 0;
293}
Magnus Damm045a4b72009-08-20 13:57:36 +0000294#else
295static int kfr2r09_usb0_gadget_i2c_setup(void)
296{
297 return -ENODEV;
298}
299#endif
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000300
301static int kfr2r09_usb0_gadget_setup(void)
302{
303 int plugged_in;
304
305 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
306 gpio_direction_input(GPIO_PTN4);
307 plugged_in = gpio_get_value(GPIO_PTN4);
308 if (!plugged_in)
309 return -ENODEV; /* no cable plugged in */
310
311 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
312 return -ENODEV; /* unable to configure using i2c */
313
314 ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
315 gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
316 gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
317 gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
318 msleep(20); /* wait 20ms to let the clock settle */
319 clk_enable(clk_get(NULL, "usb0"));
320 ctrl_outw(0x0600, 0xa40501d4);
321
322 return 0;
323}
Magnus Damma366aa642009-07-22 16:22:28 +0000324
Magnus Damme7d16512009-07-22 16:20:54 +0000325static int __init kfr2r09_devices_setup(void)
326{
327 /* enable SCIF1 serial port for YC401 console support */
328 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
329 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
330
Magnus Damma366aa642009-07-22 16:22:28 +0000331 /* setup NOR flash at CS0 */
332 ctrl_outl(0x36db0400, BSC_CS0BCR);
333 ctrl_outl(0x00000500, BSC_CS0WCR);
334
Magnus Damm33893d72009-08-06 14:58:43 +0000335 /* setup NAND flash at CS4 */
336 ctrl_outl(0x36db0400, BSC_CS4BCR);
337 ctrl_outl(0x00000500, BSC_CS4WCR);
338
Magnus Damm39a6bf12009-07-22 16:23:45 +0000339 /* setup KEYSC pins */
340 gpio_request(GPIO_FN_KEYOUT0, NULL);
341 gpio_request(GPIO_FN_KEYOUT1, NULL);
342 gpio_request(GPIO_FN_KEYOUT2, NULL);
343 gpio_request(GPIO_FN_KEYOUT3, NULL);
344 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
345 gpio_request(GPIO_FN_KEYIN0, NULL);
346 gpio_request(GPIO_FN_KEYIN1, NULL);
347 gpio_request(GPIO_FN_KEYIN2, NULL);
348 gpio_request(GPIO_FN_KEYIN3, NULL);
349 gpio_request(GPIO_FN_KEYIN4, NULL);
350 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
351
Magnus Damm9f26e652009-08-06 14:51:30 +0000352 /* setup LCDC pins for SYS panel */
353 gpio_request(GPIO_FN_LCDD17, NULL);
354 gpio_request(GPIO_FN_LCDD16, NULL);
355 gpio_request(GPIO_FN_LCDD15, NULL);
356 gpio_request(GPIO_FN_LCDD14, NULL);
357 gpio_request(GPIO_FN_LCDD13, NULL);
358 gpio_request(GPIO_FN_LCDD12, NULL);
359 gpio_request(GPIO_FN_LCDD11, NULL);
360 gpio_request(GPIO_FN_LCDD10, NULL);
361 gpio_request(GPIO_FN_LCDD9, NULL);
362 gpio_request(GPIO_FN_LCDD8, NULL);
363 gpio_request(GPIO_FN_LCDD7, NULL);
364 gpio_request(GPIO_FN_LCDD6, NULL);
365 gpio_request(GPIO_FN_LCDD5, NULL);
366 gpio_request(GPIO_FN_LCDD4, NULL);
367 gpio_request(GPIO_FN_LCDD3, NULL);
368 gpio_request(GPIO_FN_LCDD2, NULL);
369 gpio_request(GPIO_FN_LCDD1, NULL);
370 gpio_request(GPIO_FN_LCDD0, NULL);
371 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
372 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
373 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
374 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
375 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
376 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
377 gpio_direction_output(GPIO_PTE4, 1);
378 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
379 gpio_direction_output(GPIO_PTF4, 1);
380 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
381 gpio_direction_output(GPIO_PTU0, 1);
382
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000383 /* setup USB function */
384 if (kfr2r09_usb0_gadget_setup() == 0)
385 platform_device_register(&kfr2r09_usb0_gadget_device);
386
Magnus Dammd2a2fb92009-10-02 02:23:19 +0000387 /* SDHI0 connected to yc304 */
388 gpio_request(GPIO_FN_SDHI0CD, NULL);
389 gpio_request(GPIO_FN_SDHI0WP, NULL);
390 gpio_request(GPIO_FN_SDHI0D3, NULL);
391 gpio_request(GPIO_FN_SDHI0D2, NULL);
392 gpio_request(GPIO_FN_SDHI0D1, NULL);
393 gpio_request(GPIO_FN_SDHI0D0, NULL);
394 gpio_request(GPIO_FN_SDHI0CMD, NULL);
395 gpio_request(GPIO_FN_SDHI0CLK, NULL);
396
Magnus Damma366aa642009-07-22 16:22:28 +0000397 return platform_add_devices(kfr2r09_devices,
398 ARRAY_SIZE(kfr2r09_devices));
Magnus Damme7d16512009-07-22 16:20:54 +0000399}
400device_initcall(kfr2r09_devices_setup);
401
402/* Return the board specific boot mode pin configuration */
403static int kfr2r09_mode_pins(void)
404{
405 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
406 * MD3=0: 16-bit Area0 Bus Width
407 * MD5=1: Little Endian
408 * MD8=1: Test Mode Disabled
409 */
410 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
411}
412
413/*
414 * The Machine Vector
415 */
416static struct sh_machine_vector mv_kfr2r09 __initmv = {
417 .mv_name = "kfr2r09",
418 .mv_mode_pins = kfr2r09_mode_pins,
419};