mm-only debug patch...
[mmotm.git] / arch / sh / boards / mach-kfr2r09 / setup.c
blobce01d6a953b8f05b5e6ac4aae9b52e34c79920f1
1 /*
2 * KFR2R09 board support code
4 * Copyright (C) 2009 Magnus Damm
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>
13 #include <linux/mtd/physmap.h>
14 #include <linux/mtd/onenand.h>
15 #include <linux/delay.h>
16 #include <linux/clk.h>
17 #include <linux/gpio.h>
18 #include <linux/input.h>
19 #include <linux/i2c.h>
20 #include <linux/usb/r8a66597.h>
21 #include <media/soc_camera.h>
22 #include <media/sh_mobile_ceu.h>
23 #include <video/sh_mobile_lcdc.h>
24 #include <asm/clock.h>
25 #include <asm/machvec.h>
26 #include <asm/io.h>
27 #include <asm/sh_keysc.h>
28 #include <cpu/sh7724.h>
29 #include <mach/kfr2r09.h>
31 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
34 .name = "boot",
35 .offset = 0,
36 .size = (4 * 1024 * 1024),
37 .mask_flags = MTD_WRITEABLE, /* Read-only */
40 .name = "other",
41 .offset = MTDPART_OFS_APPEND,
42 .size = MTDPART_SIZ_FULL,
46 static 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),
52 static struct resource kfr2r09_nor_flash_resources[] = {
53 [0] = {
54 .name = "NOR Flash",
55 .start = 0x00000000,
56 .end = 0x03ffffff,
57 .flags = IORESOURCE_MEM,
61 static 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,
70 static struct resource kfr2r09_nand_flash_resources[] = {
71 [0] = {
72 .name = "NAND Flash",
73 .start = 0x10000000,
74 .end = 0x1001ffff,
75 .flags = IORESOURCE_MEM,
79 static 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),
85 static 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
99 static struct resource kfr2r09_sh_keysc_resources[] = {
100 [0] = {
101 .name = "KEYSC",
102 .start = 0x044b0000,
103 .end = 0x044b000f,
104 .flags = IORESOURCE_MEM,
106 [1] = {
107 .start = 79,
108 .flags = IORESOURCE_IRQ,
112 static 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,
120 .archdata = {
121 .hwblk_id = HWBLK_KEYSC,
125 static 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,
145 .lcd_size_cfg = {
146 .width = 35,
147 .height = 58,
149 .board_cfg = {
150 .setup_sys = kfr2r09_lcd_setup,
151 .display_on = kfr2r09_lcd_on,
152 .display_off = kfr2r09_lcd_off,
154 .sys_bus_cfg = {
155 .ldmt2r = 0x07010904,
156 .ldmt3r = 0x14012914,
157 /* set 1s delay to encourage fsync() */
158 .deferred_io_msec = 1000,
163 static struct resource kfr2r09_sh_lcdc_resources[] = {
164 [0] = {
165 .name = "LCDC",
166 .start = 0xfe940000, /* P4-only space */
167 .end = 0xfe942fff,
168 .flags = IORESOURCE_MEM,
170 [1] = {
171 .start = 106,
172 .flags = IORESOURCE_IRQ,
176 static 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,
183 .archdata = {
184 .hwblk_id = HWBLK_LCDC,
188 static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
189 .on_chip = 1,
192 static struct resource kfr2r09_usb0_gadget_resources[] = {
193 [0] = {
194 .start = 0x04d80000,
195 .end = 0x04d80123,
196 .flags = IORESOURCE_MEM,
198 [1] = {
199 .start = 65,
200 .end = 65,
201 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
205 static 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,
213 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
214 .resource = kfr2r09_usb0_gadget_resources,
217 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
218 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
221 static struct resource kfr2r09_ceu_resources[] = {
222 [0] = {
223 .name = "CEU",
224 .start = 0xfe910000,
225 .end = 0xfe91009f,
226 .flags = IORESOURCE_MEM,
228 [1] = {
229 .start = 52,
230 .end = 52,
231 .flags = IORESOURCE_IRQ,
233 [2] = {
234 /* place holder for contiguous memory */
238 static 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,
246 .archdata = {
247 .hwblk_id = HWBLK_CEU0,
251 static struct i2c_board_info kfr2r09_i2c_camera = {
252 I2C_BOARD_INFO("rj54n1cb0c", 0x50),
255 static struct clk *camera_clk;
257 #define DRVCRB 0xA405018C
258 static int camera_power(struct device *dev, int mode)
260 int ret;
262 if (mode) {
263 long rate;
265 camera_clk = clk_get(NULL, "video_clk");
266 if (IS_ERR(camera_clk))
267 return PTR_ERR(camera_clk);
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;
275 /* set DRVCRB
277 * use 1.8 V for VccQ_VIO
278 * use 2.85V for VccQ_SR
280 ctrl_outw((ctrl_inw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB);
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;
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);
297 ret = clk_enable(camera_clk); /* start VIO_CKO */
298 if (ret < 0)
299 goto eclkon;
301 return 0;
304 ret = 0;
306 clk_disable(camera_clk);
307 eclkon:
308 gpio_set_value(GPIO_PTB7, 0);
309 egpioout:
310 gpio_set_value(GPIO_PTB4, 0);
311 gpio_free(GPIO_PTB7);
312 eptb7:
313 gpio_free(GPIO_PTB4);
314 eptb4:
315 eclkrate:
316 clk_put(camera_clk);
317 return ret;
320 static 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",
327 static struct platform_device kfr2r09_camera = {
328 .name = "soc-camera-pdrv",
329 .id = 0,
330 .dev = {
331 .platform_data = &rj54n1_link,
335 static struct platform_device *kfr2r09_devices[] __initdata = {
336 &kfr2r09_nor_flash_device,
337 &kfr2r09_nand_flash_device,
338 &kfr2r09_sh_keysc_device,
339 &kfr2r09_sh_lcdc_device,
340 &kfr2r09_ceu_device,
341 &kfr2r09_camera,
344 #define BSC_CS0BCR 0xfec10004
345 #define BSC_CS0WCR 0xfec10024
346 #define BSC_CS4BCR 0xfec10010
347 #define BSC_CS4WCR 0xfec10030
348 #define PORT_MSELCRB 0xa4050182
350 #ifdef CONFIG_I2C
351 static int kfr2r09_usb0_gadget_i2c_setup(void)
353 struct i2c_adapter *a;
354 struct i2c_msg msg;
355 unsigned char buf[2];
356 int ret;
358 a = i2c_get_adapter(0);
359 if (!a)
360 return -ENODEV;
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;
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;
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;
391 return 0;
393 #else
394 static int kfr2r09_usb0_gadget_i2c_setup(void)
396 return -ENODEV;
398 #endif
400 static int kfr2r09_usb0_gadget_setup(void)
402 int plugged_in;
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 */
410 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
411 return -ENODEV; /* unable to configure using i2c */
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);
421 return 0;
424 static int __init kfr2r09_devices_setup(void)
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);
430 /* setup NOR flash at CS0 */
431 ctrl_outl(0x36db0400, BSC_CS0BCR);
432 ctrl_outl(0x00000500, BSC_CS0WCR);
434 /* setup NAND flash at CS4 */
435 ctrl_outl(0x36db0400, BSC_CS4BCR);
436 ctrl_outl(0x00000500, BSC_CS4WCR);
438 /* 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);
451 /* 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);
482 /* setup USB function */
483 if (kfr2r09_usb0_gadget_setup() == 0)
484 platform_device_register(&kfr2r09_usb0_gadget_device);
486 /* 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);
501 platform_resource_setup_memory(&kfr2r09_ceu_device, "ceu", 4 << 20);
503 return platform_add_devices(kfr2r09_devices,
504 ARRAY_SIZE(kfr2r09_devices));
506 device_initcall(kfr2r09_devices_setup);
508 /* Return the board specific boot mode pin configuration */
509 static int kfr2r09_mode_pins(void)
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
516 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
520 * The Machine Vector
522 static struct sh_machine_vector mv_kfr2r09 __initmv = {
523 .mv_name = "kfr2r09",
524 .mv_mode_pins = kfr2r09_mode_pins,