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
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 <video/sh_mobile_lcdc.h>
22 #include <asm/clock.h>
23 #include <asm/machvec.h>
25 #include <asm/sh_keysc.h>
26 #include <cpu/sh7724.h>
27 #include <mach/kfr2r09.h>
29 static struct mtd_partition kfr2r09_nor_flash_partitions[] =
34 .size = (4 * 1024 * 1024),
35 .mask_flags = MTD_WRITEABLE, /* Read-only */
39 .offset = MTDPART_OFS_APPEND,
40 .size = MTDPART_SIZ_FULL,
44 static struct physmap_flash_data kfr2r09_nor_flash_data = {
46 .parts = kfr2r09_nor_flash_partitions,
47 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
50 static struct resource kfr2r09_nor_flash_resources[] = {
55 .flags = IORESOURCE_MEM,
59 static 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),
64 .platform_data = &kfr2r09_nor_flash_data,
68 static struct resource kfr2r09_nand_flash_resources[] = {
73 .flags = IORESOURCE_MEM,
77 static 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),
83 static struct sh_keysc_info kfr2r09_sh_keysc_info = {
84 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
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,
97 static struct resource kfr2r09_sh_keysc_resources[] = {
102 .flags = IORESOURCE_MEM,
106 .flags = IORESOURCE_IRQ,
110 static struct platform_device kfr2r09_sh_keysc_device = {
112 .id = 0, /* "keysc0" clock */
113 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
114 .resource = kfr2r09_sh_keysc_resources,
116 .platform_data = &kfr2r09_sh_keysc_info,
119 .hwblk_id = HWBLK_KEYSC,
123 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
124 .clock_source = LCDC_CLK_BUS,
126 .chan = LCDC_CHAN_MAINLCD,
128 .interface_type = SYS18,
130 .flags = LCDC_FLAGS_DWPOL,
132 .name = "TX07D34VM0AAA",
141 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
148 .setup_sys = kfr2r09_lcd_setup,
149 .display_on = kfr2r09_lcd_on,
150 .display_off = kfr2r09_lcd_off,
153 .ldmt2r = 0x07010904,
154 .ldmt3r = 0x14012914,
155 /* set 1s delay to encourage fsync() */
156 .deferred_io_msec = 1000,
161 static struct resource kfr2r09_sh_lcdc_resources[] = {
164 .start = 0xfe940000, /* P4-only space */
166 .flags = IORESOURCE_MEM,
170 .flags = IORESOURCE_IRQ,
174 static 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,
179 .platform_data = &kfr2r09_sh_lcdc_info,
182 .hwblk_id = HWBLK_LCDC,
186 static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
190 static struct resource kfr2r09_usb0_gadget_resources[] = {
194 .flags = IORESOURCE_MEM,
199 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
203 static struct platform_device kfr2r09_usb0_gadget_device = {
204 .name = "r8a66597_udc",
207 .dma_mask = NULL, /* not use dma */
208 .coherent_dma_mask = 0xffffffff,
209 .platform_data = &kfr2r09_usb0_gadget_data,
211 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
212 .resource = kfr2r09_usb0_gadget_resources,
215 static struct resource kfr2r09_sh_sdhi0_resources[] = {
220 .flags = IORESOURCE_MEM,
224 .flags = IORESOURCE_IRQ,
228 static 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,
233 .hwblk_id = HWBLK_SDHI0,
237 static struct platform_device *kfr2r09_devices[] __initdata = {
238 &kfr2r09_nor_flash_device,
239 &kfr2r09_nand_flash_device,
240 &kfr2r09_sh_keysc_device,
241 &kfr2r09_sh_lcdc_device,
242 &kfr2r09_sh_sdhi0_device,
245 #define BSC_CS0BCR 0xfec10004
246 #define BSC_CS0WCR 0xfec10024
247 #define BSC_CS4BCR 0xfec10010
248 #define BSC_CS4WCR 0xfec10030
249 #define PORT_MSELCRB 0xa4050182
252 static int kfr2r09_usb0_gadget_i2c_setup(void)
254 struct i2c_adapter *a;
256 unsigned char buf[2];
259 a = i2c_get_adapter(0);
263 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
269 ret = i2c_transfer(a, &msg, 1);
277 msg.flags = I2C_M_RD;
278 ret = i2c_transfer(a, &msg, 1);
282 buf[1] = buf[0] | (1 << 1);
288 ret = i2c_transfer(a, &msg, 1);
295 static int kfr2r09_usb0_gadget_i2c_setup(void)
301 static int kfr2r09_usb0_gadget_setup(void)
305 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
306 gpio_direction_input(GPIO_PTN4);
307 plugged_in = gpio_get_value(GPIO_PTN4);
309 return -ENODEV; /* no cable plugged in */
311 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
312 return -ENODEV; /* unable to configure using i2c */
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);
325 static int __init kfr2r09_devices_setup(void)
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);
331 /* setup NOR flash at CS0 */
332 ctrl_outl(0x36db0400, BSC_CS0BCR);
333 ctrl_outl(0x00000500, BSC_CS0WCR);
335 /* setup NAND flash at CS4 */
336 ctrl_outl(0x36db0400, BSC_CS4BCR);
337 ctrl_outl(0x00000500, BSC_CS4WCR);
339 /* 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);
352 /* 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);
383 /* setup USB function */
384 if (kfr2r09_usb0_gadget_setup() == 0)
385 platform_device_register(&kfr2r09_usb0_gadget_device);
387 /* 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);
397 return platform_add_devices(kfr2r09_devices,
398 ARRAY_SIZE(kfr2r09_devices));
400 device_initcall(kfr2r09_devices_setup);
402 /* Return the board specific boot mode pin configuration */
403 static int kfr2r09_mode_pins(void)
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
410 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
416 static struct sh_machine_vector mv_kfr2r09 __initmv = {
417 .mv_name = "kfr2r09",
418 .mv_mode_pins = kfr2r09_mode_pins,