blob: 1e2cb1976dfb7ce739e382c4c264b5459db81199 [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 },
118};
119
Magnus Damm9f26e652009-08-06 14:51:30 +0000120static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
121 .clock_source = LCDC_CLK_BUS,
122 .ch[0] = {
123 .chan = LCDC_CHAN_MAINLCD,
124 .bpp = 16,
125 .interface_type = SYS18,
126 .clock_divider = 6,
127 .flags = LCDC_FLAGS_DWPOL,
128 .lcd_cfg = {
129 .name = "TX07D34VM0AAA",
130 .xres = 240,
131 .yres = 400,
132 .left_margin = 0,
133 .right_margin = 16,
134 .hsync_len = 8,
135 .upper_margin = 0,
136 .lower_margin = 1,
137 .vsync_len = 1,
138 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
139 },
140 .lcd_size_cfg = {
141 .width = 35,
142 .height = 58,
143 },
144 .board_cfg = {
145 .setup_sys = kfr2r09_lcd_setup,
146 .display_on = kfr2r09_lcd_on,
147 .display_off = kfr2r09_lcd_off,
148 },
149 .sys_bus_cfg = {
150 .ldmt2r = 0x07010904,
151 .ldmt3r = 0x14012914,
152 /* set 1s delay to encourage fsync() */
153 .deferred_io_msec = 1000,
154 },
155 }
156};
157
158static struct resource kfr2r09_sh_lcdc_resources[] = {
159 [0] = {
160 .name = "LCDC",
161 .start = 0xfe940000, /* P4-only space */
162 .end = 0xfe941fff,
163 .flags = IORESOURCE_MEM,
164 },
165 [1] = {
166 .start = 106,
167 .flags = IORESOURCE_IRQ,
168 },
169};
170
171static 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,
175 .dev = {
176 .platform_data = &kfr2r09_sh_lcdc_info,
177 },
178};
179
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000180static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
181 .on_chip = 1,
182};
183
184static struct resource kfr2r09_usb0_gadget_resources[] = {
185 [0] = {
186 .start = 0x04d80000,
187 .end = 0x04d80123,
188 .flags = IORESOURCE_MEM,
189 },
190 [1] = {
191 .start = 65,
192 .end = 65,
193 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
194 },
195};
196
197static struct platform_device kfr2r09_usb0_gadget_device = {
198 .name = "r8a66597_udc",
199 .id = 0,
200 .dev = {
201 .dma_mask = NULL, /* not use dma */
202 .coherent_dma_mask = 0xffffffff,
203 .platform_data = &kfr2r09_usb0_gadget_data,
204 },
205 .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
206 .resource = kfr2r09_usb0_gadget_resources,
207};
208
Magnus Damma366aa642009-07-22 16:22:28 +0000209static struct platform_device *kfr2r09_devices[] __initdata = {
210 &kfr2r09_nor_flash_device,
Magnus Damm33893d72009-08-06 14:58:43 +0000211 &kfr2r09_nand_flash_device,
Magnus Damm39a6bf12009-07-22 16:23:45 +0000212 &kfr2r09_sh_keysc_device,
Magnus Damm9f26e652009-08-06 14:51:30 +0000213 &kfr2r09_sh_lcdc_device,
Magnus Damma366aa642009-07-22 16:22:28 +0000214};
215
216#define BSC_CS0BCR 0xfec10004
217#define BSC_CS0WCR 0xfec10024
Magnus Damm33893d72009-08-06 14:58:43 +0000218#define BSC_CS4BCR 0xfec10010
219#define BSC_CS4WCR 0xfec10030
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000220#define PORT_MSELCRB 0xa4050182
221
Magnus Damm045a4b72009-08-20 13:57:36 +0000222#ifdef CONFIG_I2C
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000223static int kfr2r09_usb0_gadget_i2c_setup(void)
224{
225 struct i2c_adapter *a;
226 struct i2c_msg msg;
227 unsigned char buf[2];
228 int ret;
229
230 a = i2c_get_adapter(0);
231 if (!a)
232 return -ENODEV;
233
234 /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
235 buf[0] = 0x13;
236 msg.addr = 0x09;
237 msg.buf = buf;
238 msg.len = 1;
239 msg.flags = 0;
240 ret = i2c_transfer(a, &msg, 1);
241 if (ret != 1)
242 return -ENODEV;
243
244 buf[0] = 0;
245 msg.addr = 0x09;
246 msg.buf = buf;
247 msg.len = 1;
248 msg.flags = I2C_M_RD;
249 ret = i2c_transfer(a, &msg, 1);
250 if (ret != 1)
251 return -ENODEV;
252
253 buf[1] = buf[0] | (1 << 1);
254 buf[0] = 0x13;
255 msg.addr = 0x09;
256 msg.buf = buf;
257 msg.len = 2;
258 msg.flags = 0;
259 ret = i2c_transfer(a, &msg, 1);
260 if (ret != 1)
261 return -ENODEV;
262
263 return 0;
264}
Magnus Damm045a4b72009-08-20 13:57:36 +0000265#else
266static int kfr2r09_usb0_gadget_i2c_setup(void)
267{
268 return -ENODEV;
269}
270#endif
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000271
272static int kfr2r09_usb0_gadget_setup(void)
273{
274 int plugged_in;
275
276 gpio_request(GPIO_PTN4, NULL); /* USB_DET */
277 gpio_direction_input(GPIO_PTN4);
278 plugged_in = gpio_get_value(GPIO_PTN4);
279 if (!plugged_in)
280 return -ENODEV; /* no cable plugged in */
281
282 if (kfr2r09_usb0_gadget_i2c_setup() != 0)
283 return -ENODEV; /* unable to configure using i2c */
284
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);
292
293 return 0;
294}
Magnus Damma366aa642009-07-22 16:22:28 +0000295
Magnus Damme7d16512009-07-22 16:20:54 +0000296static int __init kfr2r09_devices_setup(void)
297{
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);
301
Magnus Damma366aa642009-07-22 16:22:28 +0000302 /* setup NOR flash at CS0 */
303 ctrl_outl(0x36db0400, BSC_CS0BCR);
304 ctrl_outl(0x00000500, BSC_CS0WCR);
305
Magnus Damm33893d72009-08-06 14:58:43 +0000306 /* setup NAND flash at CS4 */
307 ctrl_outl(0x36db0400, BSC_CS4BCR);
308 ctrl_outl(0x00000500, BSC_CS4WCR);
309
Magnus Damm39a6bf12009-07-22 16:23:45 +0000310 /* 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);
322
Magnus Damm9f26e652009-08-06 14:51:30 +0000323 /* 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);
353
Magnus Damm5a1c4cb2009-08-19 14:39:15 +0000354 /* setup USB function */
355 if (kfr2r09_usb0_gadget_setup() == 0)
356 platform_device_register(&kfr2r09_usb0_gadget_device);
357
Magnus Damma366aa642009-07-22 16:22:28 +0000358 return platform_add_devices(kfr2r09_devices,
359 ARRAY_SIZE(kfr2r09_devices));
Magnus Damme7d16512009-07-22 16:20:54 +0000360}
361device_initcall(kfr2r09_devices_setup);
362
363/* Return the board specific boot mode pin configuration */
364static int kfr2r09_mode_pins(void)
365{
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
370 */
371 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
372}
373
374/*
375 * The Machine Vector
376 */
377static struct sh_machine_vector mv_kfr2r09 __initmv = {
378 .mv_name = "kfr2r09",
379 .mv_mode_pins = kfr2r09_mode_pins,
380};