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,
120 static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
121 .clock_source = LCDC_CLK_BUS,
123 .chan = LCDC_CHAN_MAINLCD,
125 .interface_type = SYS18,
127 .flags = LCDC_FLAGS_DWPOL,
129 .name = "TX07D34VM0AAA",
138 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
145 .setup_sys = kfr2r09_lcd_setup,
146 .display_on = kfr2r09_lcd_on,
147 .display_off = kfr2r09_lcd_off,
150 .ldmt2r = 0x07010904,
151 .ldmt3r = 0x14012914,
152 /* set 1s delay to encourage fsync() */
153 .deferred_io_msec = 1000,
158 static struct resource kfr2r09_sh_lcdc_resources[] = {
161 .start = 0xfe940000, /* P4-only space */
163 .flags = IORESOURCE_MEM,
167 .flags = IORESOURCE_IRQ,
171 static struct platform_device kfr2r09_sh_lcdc_device = {
172 .name = "sh_mobile_lcdc_fb",
173 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
174 .resource = kfr2r09_sh_lcdc_resources,
176 .platform_data = &kfr2r09_sh_lcdc_info,
180 static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
184 static struct resource kfr2r09_usb0_gadget_resources[] = {
188 .flags = IORESOURCE_MEM,
193 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
197 static struct platform_device kfr2r09_usb0_gadget_device = {
198 .name = "r8a66597_udc",
201 .dma_mask = NULL, /* not use dma */
202 .coherent_dma_mask = 0xffffffff,
203 .platform_data = &kfr2r09_usb0_gadget_data,
205 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
206 .resource = kfr2r09_usb0_gadget_resources,
209 static struct platform_device *kfr2r09_devices[] __initdata = {
210 &kfr2r09_nor_flash_device,
211 &kfr2r09_nand_flash_device,
212 &kfr2r09_sh_keysc_device,
213 &kfr2r09_sh_lcdc_device,
216 #define BSC_CS0BCR 0xfec10004
217 #define BSC_CS0WCR 0xfec10024
218 #define BSC_CS4BCR 0xfec10010
219 #define BSC_CS4WCR 0xfec10030
220 #define PORT_MSELCRB 0xa4050182
223 static int kfr2r09_usb0_gadget_i2c_setup(void)
225 struct i2c_adapter *a;
227 unsigned char buf[2];
230 a = i2c_get_adapter(0);
234 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
240 ret = i2c_transfer(a, &msg, 1);
248 msg.flags = I2C_M_RD;
249 ret = i2c_transfer(a, &msg, 1);
253 buf[1] = buf[0] | (1 << 1);
259 ret = i2c_transfer(a, &msg, 1);
266 static int kfr2r09_usb0_gadget_i2c_setup(void)
272 static int kfr2r09_usb0_gadget_setup(void)
276 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
277 gpio_direction_input(GPIO_PTN4);
278 plugged_in = gpio_get_value(GPIO_PTN4);
280 return -ENODEV; /* no cable plugged in */
282 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
283 return -ENODEV; /* unable to configure using i2c */
285 ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
286 gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
287 gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
288 gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
289 msleep(20); /* wait 20ms to let the clock settle */
290 clk_enable(clk_get(NULL, "usb0"));
291 ctrl_outw(0x0600, 0xa40501d4);
296 static int __init kfr2r09_devices_setup(void)
298 /* enable SCIF1 serial port for YC401 console support */
299 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
300 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
302 /* setup NOR flash at CS0 */
303 ctrl_outl(0x36db0400, BSC_CS0BCR);
304 ctrl_outl(0x00000500, BSC_CS0WCR);
306 /* setup NAND flash at CS4 */
307 ctrl_outl(0x36db0400, BSC_CS4BCR);
308 ctrl_outl(0x00000500, BSC_CS4WCR);
310 /* setup KEYSC pins */
311 gpio_request(GPIO_FN_KEYOUT0, NULL);
312 gpio_request(GPIO_FN_KEYOUT1, NULL);
313 gpio_request(GPIO_FN_KEYOUT2, NULL);
314 gpio_request(GPIO_FN_KEYOUT3, NULL);
315 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
316 gpio_request(GPIO_FN_KEYIN0, NULL);
317 gpio_request(GPIO_FN_KEYIN1, NULL);
318 gpio_request(GPIO_FN_KEYIN2, NULL);
319 gpio_request(GPIO_FN_KEYIN3, NULL);
320 gpio_request(GPIO_FN_KEYIN4, NULL);
321 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
323 /* setup LCDC pins for SYS panel */
324 gpio_request(GPIO_FN_LCDD17, NULL);
325 gpio_request(GPIO_FN_LCDD16, NULL);
326 gpio_request(GPIO_FN_LCDD15, NULL);
327 gpio_request(GPIO_FN_LCDD14, NULL);
328 gpio_request(GPIO_FN_LCDD13, NULL);
329 gpio_request(GPIO_FN_LCDD12, NULL);
330 gpio_request(GPIO_FN_LCDD11, NULL);
331 gpio_request(GPIO_FN_LCDD10, NULL);
332 gpio_request(GPIO_FN_LCDD9, NULL);
333 gpio_request(GPIO_FN_LCDD8, NULL);
334 gpio_request(GPIO_FN_LCDD7, NULL);
335 gpio_request(GPIO_FN_LCDD6, NULL);
336 gpio_request(GPIO_FN_LCDD5, NULL);
337 gpio_request(GPIO_FN_LCDD4, NULL);
338 gpio_request(GPIO_FN_LCDD3, NULL);
339 gpio_request(GPIO_FN_LCDD2, NULL);
340 gpio_request(GPIO_FN_LCDD1, NULL);
341 gpio_request(GPIO_FN_LCDD0, NULL);
342 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
343 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
344 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
345 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
346 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
347 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
348 gpio_direction_output(GPIO_PTE4, 1);
349 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
350 gpio_direction_output(GPIO_PTF4, 1);
351 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
352 gpio_direction_output(GPIO_PTU0, 1);
354 /* setup USB function */
355 if (kfr2r09_usb0_gadget_setup() == 0)
356 platform_device_register(&kfr2r09_usb0_gadget_device);
358 return platform_add_devices(kfr2r09_devices,
359 ARRAY_SIZE(kfr2r09_devices));
361 device_initcall(kfr2r09_devices_setup);
363 /* Return the board specific boot mode pin configuration */
364 static int kfr2r09_mode_pins(void)
366 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
367 * MD3=0: 16-bit Area0 Bus Width
368 * MD5=1: Little Endian
369 * MD8=1: Test Mode Disabled
371 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
377 static struct sh_machine_vector mv_kfr2r09 __initmv = {
378 .mv_name = "kfr2r09",
379 .mv_mode_pins = kfr2r09_mode_pins,