blob: ce01d6a953b8f05b5e6ac4aae9b52e34c79920f1 [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>
Guennadi Liakhovetskia469f622009-10-03 11:21:30 +000021#include <media/soc_camera.h>
22#include <media/sh_mobile_ceu.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000023#include <video/sh_mobile_lcdc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000024#include <asm/clock.h>
25#include <asm/machvec.h>
26#include <asm/io.h>
Magnus Damm39a6bf12009-07-22 16:23:45 +000027#include <asm/sh_keysc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000028#include <cpu/sh7724.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000029#include <mach/kfr2r09.h>
Magnus Damme7d16512009-07-22 16:20:54 +000030
Magnus Damma366aa642009-07-22 16:22:28 +000031static struct mtd_partition kfr2r09_nor_flash_partitions[] =
32{
33 {
34 .name = "boot",
35 .offset = 0,
36 .size = (4 * 1024 * 1024),
37 .mask_flags = MTD_WRITEABLE, /* Read-only */
38 },
39 {
40 .name = "other",
41 .offset = MTDPART_OFS_APPEND,
42 .size = MTDPART_SIZ_FULL,
43 },
44};
45
46static struct physmap_flash_data kfr2r09_nor_flash_data = {
47 .width = 2,
48 .parts = kfr2r09_nor_flash_partitions,
49 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
50};
51
52static struct resource kfr2r09_nor_flash_resources[] = {
53 [0] = {
54 .name = "NOR Flash",
55 .start = 0x00000000,
56 .end = 0x03ffffff,
57 .flags = IORESOURCE_MEM,
58 }
59};
60
61static struct platform_device kfr2r09_nor_flash_device = {
62 .name = "physmap-flash",
63 .resource = kfr2r09_nor_flash_resources,
64 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
65 .dev = {
66 .platform_data = &kfr2r09_nor_flash_data,
67 },
68};
69
Magnus Damm33893d72009-08-06 14:58:43 +000070static struct resource kfr2r09_nand_flash_resources[] = {
71 [0] = {
72 .name = "NAND Flash",
73 .start = 0x10000000,
74 .end = 0x1001ffff,
75 .flags = IORESOURCE_MEM,
76 }
77};
78
79static struct platform_device kfr2r09_nand_flash_device = {
80 .name = "onenand-flash",
81 .resource = kfr2r09_nand_flash_resources,
82 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
83};
84
Magnus Damm39a6bf12009-07-22 16:23:45 +000085static struct sh_keysc_info kfr2r09_sh_keysc_info = {
86 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
87 .scan_timing = 3,
88 .delay = 10,
89 .keycodes = {
90 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
91 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
92 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
93 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
94 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
95 0, 0, 0, 0, 0
96 },
97};
98
99static struct resource kfr2r09_sh_keysc_resources[] = {
100 [0] = {
101 .name = "KEYSC",
102 .start = 0x044b0000,
103 .end = 0x044b000f,
104 .flags = IORESOURCE_MEM,
105 },
106 [1] = {
107 .start = 79,
108 .flags = IORESOURCE_IRQ,
109 },
110};
111
112static struct platform_device kfr2r09_sh_keysc_device = {
113 .name = "sh_keysc",
114 .id = 0, /* "keysc0" clock */
115 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
116 .resource = kfr2r09_sh_keysc_resources,
117 .dev = {
118 .platform_data = &kfr2r09_sh_keysc_info,
119 },
Magnus Damm442c3752009-07-31 07:48:21 +0000120 .archdata = {
121 .hwblk_id = HWBLK_KEYSC,
122 },
Magnus Damm39a6bf12009-07-22 16:23:45 +0000123};
124
Magnus Damm9f26e652009-08-06 14:51:30 +0000125static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
126 .clock_source = LCDC_CLK_BUS,
127 .ch[0] = {
128 .chan = LCDC_CHAN_MAINLCD,
129 .bpp = 16,
130 .interface_type = SYS18,
131 .clock_divider = 6,
132 .flags = LCDC_FLAGS_DWPOL,
133 .lcd_cfg = {
134 .name = "TX07D34VM0AAA",
135 .xres = 240,
136 .yres = 400,
137 .left_margin = 0,
138 .right_margin = 16,
139 .hsync_len = 8,
140 .upper_margin = 0,
141 .lower_margin = 1,
142 .vsync_len = 1,
143 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
144 },
145 .lcd_size_cfg = {
146 .width = 35,
147 .height = 58,
148 },
149 .board_cfg = {
150 .setup_sys = kfr2r09_lcd_setup,
151 .display_on = kfr2r09_lcd_on,
152 .display_off = kfr2r09_lcd_off,
153 },
154 .sys_bus_cfg = {
155 .ldmt2r = 0x07010904,
156 .ldmt3r = 0x14012914,
157 /* set 1s delay to encourage fsync() */
158 .deferred_io_msec = 1000,
159 },
160 }
161};
162
163static struct resource kfr2r09_sh_lcdc_resources[] = {
164 [0] = {
165 .name = "LCDC",
166 .start = 0xfe940000, /* P4-only space */
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000167 .end = 0xfe942fff,
Magnus Damm9f26e652009-08-06 14:51:30 +0000168 .flags = IORESOURCE_MEM,
169 },
170 [1] = {
171 .start = 106,
172 .flags = IORESOURCE_IRQ,
173 },
174};
175
176static struct platform_device kfr2r09_sh_lcdc_device = {
177 .name = "sh_mobile_lcdc_fb",
178 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
179 .resource = kfr2r09_sh_lcdc_resources,
180 .dev = {
181 .platform_data = &kfr2r09_sh_lcdc_info,
182 },
Magnus Damm963e04c2009-08-15 03:02:08 +0000183 .archdata = {
184 .hwblk_id = HWBLK_LCDC,
185 },
Magnus Damm9f26e652009-08-06 14:51:30 +0000186};
187
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000188static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
189 .on_chip = 1,
190};
191
192static struct resource kfr2r09_usb0_gadget_resources[] = {
193 [0] = {
194 .start = 0x04d80000,
195 .end = 0x04d80123,
196 .flags = IORESOURCE_MEM,
197 },
198 [1] = {
199 .start = 65,
200 .end = 65,
201 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
202 },
203};
204
205static struct platform_device kfr2r09_usb0_gadget_device = {
206 .name = "r8a66597_udc",
207 .id = 0,
208 .dev = {
209 .dma_mask = NULL, /* not use dma */
210 .coherent_dma_mask = 0xffffffff,
211 .platform_data = &kfr2r09_usb0_gadget_data,
212 },
213 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
214 .resource = kfr2r09_usb0_gadget_resources,
215};
216
Guennadi Liakhovetskia469f622009-10-03 11:21:30 +0000217static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
218 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
219};
220
221static struct resource kfr2r09_ceu_resources[] = {
222 [0] = {
223 .name = "CEU",
224 .start = 0xfe910000,
225 .end = 0xfe91009f,
226 .flags = IORESOURCE_MEM,
227 },
228 [1] = {
229 .start = 52,
230 .end = 52,
231 .flags = IORESOURCE_IRQ,
232 },
233 [2] = {
234 /* place holder for contiguous memory */
235 },
236};
237
238static struct platform_device kfr2r09_ceu_device = {
239 .name = "sh_mobile_ceu",
240 .id = 0, /* "ceu0" clock */
241 .num_resources = ARRAY_SIZE(kfr2r09_ceu_resources),
242 .resource = kfr2r09_ceu_resources,
243 .dev = {
244 .platform_data = &sh_mobile_ceu_info,
245 },
246 .archdata = {
247 .hwblk_id = HWBLK_CEU0,
248 },
249};
250
251static struct i2c_board_info kfr2r09_i2c_camera = {
252 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
253};
254
255static struct clk *camera_clk;
256
257#define DRVCRB 0xA405018C
258static int camera_power(struct device *dev, int mode)
259{
260 int ret;
261
262 if (mode) {
263 long rate;
264
265 camera_clk = clk_get(NULL, "video_clk");
266 if (IS_ERR(camera_clk))
267 return PTR_ERR(camera_clk);
268
269 /* set VIO_CKO clock to 25MHz */
270 rate = clk_round_rate(camera_clk, 25000000);
271 ret = clk_set_rate(camera_clk, rate);
272 if (ret < 0)
273 goto eclkrate;
274
275 /* set DRVCRB
276 *
277 * use 1.8 V for VccQ_VIO
278 * use 2.85V for VccQ_SR
279 */
280 ctrl_outw((ctrl_inw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB);
281
282 /* reset clear */
283 ret = gpio_request(GPIO_PTB4, NULL);
284 if (ret < 0)
285 goto eptb4;
286 ret = gpio_request(GPIO_PTB7, NULL);
287 if (ret < 0)
288 goto eptb7;
289
290 ret = gpio_direction_output(GPIO_PTB4, 1);
291 if (!ret)
292 ret = gpio_direction_output(GPIO_PTB7, 1);
293 if (ret < 0)
294 goto egpioout;
295 msleep(1);
296
297 ret = clk_enable(camera_clk); /* start VIO_CKO */
298 if (ret < 0)
299 goto eclkon;
300
301 return 0;
302 }
303
304 ret = 0;
305
306 clk_disable(camera_clk);
307eclkon:
308 gpio_set_value(GPIO_PTB7, 0);
309egpioout:
310 gpio_set_value(GPIO_PTB4, 0);
311 gpio_free(GPIO_PTB7);
312eptb7:
313 gpio_free(GPIO_PTB4);
314eptb4:
315eclkrate:
316 clk_put(camera_clk);
317 return ret;
318}
319
320static struct soc_camera_link rj54n1_link = {
321 .power = camera_power,
322 .board_info = &kfr2r09_i2c_camera,
323 .i2c_adapter_id = 1,
324 .module_name = "rj54n1cb0c",
325};
326
327static struct platform_device kfr2r09_camera = {
328 .name = "soc-camera-pdrv",
329 .id = 0,
330 .dev = {
331 .platform_data = &rj54n1_link,
332 },
333};
334
Magnus Damma366aa642009-07-22 16:22:28 +0000335static struct platform_device *kfr2r09_devices[] __initdata = {
336 &kfr2r09_nor_flash_device,
Magnus Damm33893d72009-08-06 14:58:43 +0000337 &kfr2r09_nand_flash_device,
Magnus Damm39a6bf12009-07-22 16:23:45 +0000338 &kfr2r09_sh_keysc_device,
Magnus Damm9f26e652009-08-06 14:51:30 +0000339 &kfr2r09_sh_lcdc_device,
Guennadi Liakhovetskia469f622009-10-03 11:21:30 +0000340 &kfr2r09_ceu_device,
341 &kfr2r09_camera,
Magnus Damma366aa642009-07-22 16:22:28 +0000342};
343
344#define BSC_CS0BCR 0xfec10004
345#define BSC_CS0WCR 0xfec10024
Magnus Damm33893d72009-08-06 14:58:43 +0000346#define BSC_CS4BCR 0xfec10010
347#define BSC_CS4WCR 0xfec10030
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000348#define PORT_MSELCRB 0xa4050182
349
Magnus Damm045a4b72009-08-20 13:57:36 +0000350#ifdef CONFIG_I2C
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000351static int kfr2r09_usb0_gadget_i2c_setup(void)
352{
353 struct i2c_adapter *a;
354 struct i2c_msg msg;
355 unsigned char buf[2];
356 int ret;
357
358 a = i2c_get_adapter(0);
359 if (!a)
360 return -ENODEV;
361
362 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
363 buf[0] = 0x13;
364 msg.addr = 0x09;
365 msg.buf = buf;
366 msg.len = 1;
367 msg.flags = 0;
368 ret = i2c_transfer(a, &msg, 1);
369 if (ret != 1)
370 return -ENODEV;
371
372 buf[0] = 0;
373 msg.addr = 0x09;
374 msg.buf = buf;
375 msg.len = 1;
376 msg.flags = I2C_M_RD;
377 ret = i2c_transfer(a, &msg, 1);
378 if (ret != 1)
379 return -ENODEV;
380
381 buf[1] = buf[0] | (1 << 1);
382 buf[0] = 0x13;
383 msg.addr = 0x09;
384 msg.buf = buf;
385 msg.len = 2;
386 msg.flags = 0;
387 ret = i2c_transfer(a, &msg, 1);
388 if (ret != 1)
389 return -ENODEV;
390
391 return 0;
392}
Magnus Damm045a4b72009-08-20 13:57:36 +0000393#else
394static int kfr2r09_usb0_gadget_i2c_setup(void)
395{
396 return -ENODEV;
397}
398#endif
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000399
400static int kfr2r09_usb0_gadget_setup(void)
401{
402 int plugged_in;
403
404 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
405 gpio_direction_input(GPIO_PTN4);
406 plugged_in = gpio_get_value(GPIO_PTN4);
407 if (!plugged_in)
408 return -ENODEV; /* no cable plugged in */
409
410 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
411 return -ENODEV; /* unable to configure using i2c */
412
413 ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
414 gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
415 gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
416 gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
417 msleep(20); /* wait 20ms to let the clock settle */
418 clk_enable(clk_get(NULL, "usb0"));
419 ctrl_outw(0x0600, 0xa40501d4);
420
421 return 0;
422}
Magnus Damma366aa642009-07-22 16:22:28 +0000423
Magnus Damme7d16512009-07-22 16:20:54 +0000424static int __init kfr2r09_devices_setup(void)
425{
426 /* enable SCIF1 serial port for YC401 console support */
427 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
428 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
429
Magnus Damma366aa642009-07-22 16:22:28 +0000430 /* setup NOR flash at CS0 */
431 ctrl_outl(0x36db0400, BSC_CS0BCR);
432 ctrl_outl(0x00000500, BSC_CS0WCR);
433
Magnus Damm33893d72009-08-06 14:58:43 +0000434 /* setup NAND flash at CS4 */
435 ctrl_outl(0x36db0400, BSC_CS4BCR);
436 ctrl_outl(0x00000500, BSC_CS4WCR);
437
Magnus Damm39a6bf12009-07-22 16:23:45 +0000438 /* setup KEYSC pins */
439 gpio_request(GPIO_FN_KEYOUT0, NULL);
440 gpio_request(GPIO_FN_KEYOUT1, NULL);
441 gpio_request(GPIO_FN_KEYOUT2, NULL);
442 gpio_request(GPIO_FN_KEYOUT3, NULL);
443 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
444 gpio_request(GPIO_FN_KEYIN0, NULL);
445 gpio_request(GPIO_FN_KEYIN1, NULL);
446 gpio_request(GPIO_FN_KEYIN2, NULL);
447 gpio_request(GPIO_FN_KEYIN3, NULL);
448 gpio_request(GPIO_FN_KEYIN4, NULL);
449 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
450
Magnus Damm9f26e652009-08-06 14:51:30 +0000451 /* setup LCDC pins for SYS panel */
452 gpio_request(GPIO_FN_LCDD17, NULL);
453 gpio_request(GPIO_FN_LCDD16, NULL);
454 gpio_request(GPIO_FN_LCDD15, NULL);
455 gpio_request(GPIO_FN_LCDD14, NULL);
456 gpio_request(GPIO_FN_LCDD13, NULL);
457 gpio_request(GPIO_FN_LCDD12, NULL);
458 gpio_request(GPIO_FN_LCDD11, NULL);
459 gpio_request(GPIO_FN_LCDD10, NULL);
460 gpio_request(GPIO_FN_LCDD9, NULL);
461 gpio_request(GPIO_FN_LCDD8, NULL);
462 gpio_request(GPIO_FN_LCDD7, NULL);
463 gpio_request(GPIO_FN_LCDD6, NULL);
464 gpio_request(GPIO_FN_LCDD5, NULL);
465 gpio_request(GPIO_FN_LCDD4, NULL);
466 gpio_request(GPIO_FN_LCDD3, NULL);
467 gpio_request(GPIO_FN_LCDD2, NULL);
468 gpio_request(GPIO_FN_LCDD1, NULL);
469 gpio_request(GPIO_FN_LCDD0, NULL);
470 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
471 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
472 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
473 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
474 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
475 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
476 gpio_direction_output(GPIO_PTE4, 1);
477 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
478 gpio_direction_output(GPIO_PTF4, 1);
479 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
480 gpio_direction_output(GPIO_PTU0, 1);
481
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000482 /* setup USB function */
483 if (kfr2r09_usb0_gadget_setup() == 0)
484 platform_device_register(&kfr2r09_usb0_gadget_device);
485
Guennadi Liakhovetskia469f622009-10-03 11:21:30 +0000486 /* CEU */
487 gpio_request(GPIO_FN_VIO_CKO, NULL);
488 gpio_request(GPIO_FN_VIO0_CLK, NULL);
489 gpio_request(GPIO_FN_VIO0_VD, NULL);
490 gpio_request(GPIO_FN_VIO0_HD, NULL);
491 gpio_request(GPIO_FN_VIO0_FLD, NULL);
492 gpio_request(GPIO_FN_VIO0_D7, NULL);
493 gpio_request(GPIO_FN_VIO0_D6, NULL);
494 gpio_request(GPIO_FN_VIO0_D5, NULL);
495 gpio_request(GPIO_FN_VIO0_D4, NULL);
496 gpio_request(GPIO_FN_VIO0_D3, NULL);
497 gpio_request(GPIO_FN_VIO0_D2, NULL);
498 gpio_request(GPIO_FN_VIO0_D1, NULL);
499 gpio_request(GPIO_FN_VIO0_D0, NULL);
500
501 platform_resource_setup_memory(&kfr2r09_ceu_device, "ceu", 4 << 20);
502
Magnus Damma366aa642009-07-22 16:22:28 +0000503 return platform_add_devices(kfr2r09_devices,
504 ARRAY_SIZE(kfr2r09_devices));
Magnus Damme7d16512009-07-22 16:20:54 +0000505}
506device_initcall(kfr2r09_devices_setup);
507
508/* Return the board specific boot mode pin configuration */
509static int kfr2r09_mode_pins(void)
510{
511 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
512 * MD3=0: 16-bit Area0 Bus Width
513 * MD5=1: Little Endian
514 * MD8=1: Test Mode Disabled
515 */
516 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
517}
518
519/*
520 * The Machine Vector
521 */
522static struct sh_machine_vector mv_kfr2r09 __initmv = {
523 .mv_name = "kfr2r09",
524 .mv_mode_pins = kfr2r09_mode_pins,
525};