blob: bdb10c29ef1827c5f4d40021f7a1a14c4ac0e6ec [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 Damm9f26e652009-08-06 14:51:30 +000019#include <video/sh_mobile_lcdc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000020#include <asm/clock.h>
21#include <asm/machvec.h>
22#include <asm/io.h>
Magnus Damm39a6bf12009-07-22 16:23:45 +000023#include <asm/sh_keysc.h>
Magnus Damme7d16512009-07-22 16:20:54 +000024#include <cpu/sh7724.h>
Magnus Damm9f26e652009-08-06 14:51:30 +000025#include <mach/kfr2r09.h>
Magnus Damme7d16512009-07-22 16:20:54 +000026
Magnus Damma366aa642009-07-22 16:22:28 +000027static struct mtd_partition kfr2r09_nor_flash_partitions[] =
28{
29 {
30 .name = "boot",
31 .offset = 0,
32 .size = (4 * 1024 * 1024),
33 .mask_flags = MTD_WRITEABLE, /* Read-only */
34 },
35 {
36 .name = "other",
37 .offset = MTDPART_OFS_APPEND,
38 .size = MTDPART_SIZ_FULL,
39 },
40};
41
42static struct physmap_flash_data kfr2r09_nor_flash_data = {
43 .width = 2,
44 .parts = kfr2r09_nor_flash_partitions,
45 .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
46};
47
48static struct resource kfr2r09_nor_flash_resources[] = {
49 [0] = {
50 .name = "NOR Flash",
51 .start = 0x00000000,
52 .end = 0x03ffffff,
53 .flags = IORESOURCE_MEM,
54 }
55};
56
57static struct platform_device kfr2r09_nor_flash_device = {
58 .name = "physmap-flash",
59 .resource = kfr2r09_nor_flash_resources,
60 .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
61 .dev = {
62 .platform_data = &kfr2r09_nor_flash_data,
63 },
64};
65
Magnus Damm33893d72009-08-06 14:58:43 +000066static struct resource kfr2r09_nand_flash_resources[] = {
67 [0] = {
68 .name = "NAND Flash",
69 .start = 0x10000000,
70 .end = 0x1001ffff,
71 .flags = IORESOURCE_MEM,
72 }
73};
74
75static struct platform_device kfr2r09_nand_flash_device = {
76 .name = "onenand-flash",
77 .resource = kfr2r09_nand_flash_resources,
78 .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
79};
80
Magnus Damm39a6bf12009-07-22 16:23:45 +000081static struct sh_keysc_info kfr2r09_sh_keysc_info = {
82 .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
83 .scan_timing = 3,
84 .delay = 10,
85 .keycodes = {
86 KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
87 KEY_1, KEY_2, KEY_3, 0, KEY_UP,
88 KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
89 KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
90 KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
91 0, 0, 0, 0, 0
92 },
93};
94
95static struct resource kfr2r09_sh_keysc_resources[] = {
96 [0] = {
97 .name = "KEYSC",
98 .start = 0x044b0000,
99 .end = 0x044b000f,
100 .flags = IORESOURCE_MEM,
101 },
102 [1] = {
103 .start = 79,
104 .flags = IORESOURCE_IRQ,
105 },
106};
107
108static struct platform_device kfr2r09_sh_keysc_device = {
109 .name = "sh_keysc",
110 .id = 0, /* "keysc0" clock */
111 .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
112 .resource = kfr2r09_sh_keysc_resources,
113 .dev = {
114 .platform_data = &kfr2r09_sh_keysc_info,
115 },
116};
117
Magnus Damm9f26e652009-08-06 14:51:30 +0000118static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
119 .clock_source = LCDC_CLK_BUS,
120 .ch[0] = {
121 .chan = LCDC_CHAN_MAINLCD,
122 .bpp = 16,
123 .interface_type = SYS18,
124 .clock_divider = 6,
125 .flags = LCDC_FLAGS_DWPOL,
126 .lcd_cfg = {
127 .name = "TX07D34VM0AAA",
128 .xres = 240,
129 .yres = 400,
130 .left_margin = 0,
131 .right_margin = 16,
132 .hsync_len = 8,
133 .upper_margin = 0,
134 .lower_margin = 1,
135 .vsync_len = 1,
136 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
137 },
138 .lcd_size_cfg = {
139 .width = 35,
140 .height = 58,
141 },
142 .board_cfg = {
143 .setup_sys = kfr2r09_lcd_setup,
144 .display_on = kfr2r09_lcd_on,
145 .display_off = kfr2r09_lcd_off,
146 },
147 .sys_bus_cfg = {
148 .ldmt2r = 0x07010904,
149 .ldmt3r = 0x14012914,
150 /* set 1s delay to encourage fsync() */
151 .deferred_io_msec = 1000,
152 },
153 }
154};
155
156static struct resource kfr2r09_sh_lcdc_resources[] = {
157 [0] = {
158 .name = "LCDC",
159 .start = 0xfe940000, /* P4-only space */
160 .end = 0xfe941fff,
161 .flags = IORESOURCE_MEM,
162 },
163 [1] = {
164 .start = 106,
165 .flags = IORESOURCE_IRQ,
166 },
167};
168
169static struct platform_device kfr2r09_sh_lcdc_device = {
170 .name = "sh_mobile_lcdc_fb",
171 .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
172 .resource = kfr2r09_sh_lcdc_resources,
173 .dev = {
174 .platform_data = &kfr2r09_sh_lcdc_info,
175 },
176};
177
Magnus Damma366aa642009-07-22 16:22:28 +0000178static struct platform_device *kfr2r09_devices[] __initdata = {
179 &kfr2r09_nor_flash_device,
Magnus Damm33893d72009-08-06 14:58:43 +0000180 &kfr2r09_nand_flash_device,
Magnus Damm39a6bf12009-07-22 16:23:45 +0000181 &kfr2r09_sh_keysc_device,
Magnus Damm9f26e652009-08-06 14:51:30 +0000182 &kfr2r09_sh_lcdc_device,
Magnus Damma366aa642009-07-22 16:22:28 +0000183};
184
185#define BSC_CS0BCR 0xfec10004
186#define BSC_CS0WCR 0xfec10024
Magnus Damm33893d72009-08-06 14:58:43 +0000187#define BSC_CS4BCR 0xfec10010
188#define BSC_CS4WCR 0xfec10030
Magnus Damma366aa642009-07-22 16:22:28 +0000189
Magnus Damme7d16512009-07-22 16:20:54 +0000190static int __init kfr2r09_devices_setup(void)
191{
192 /* enable SCIF1 serial port for YC401 console support */
193 gpio_request(GPIO_FN_SCIF1_RXD, NULL);
194 gpio_request(GPIO_FN_SCIF1_TXD, NULL);
195
Magnus Damma366aa642009-07-22 16:22:28 +0000196 /* setup NOR flash at CS0 */
197 ctrl_outl(0x36db0400, BSC_CS0BCR);
198 ctrl_outl(0x00000500, BSC_CS0WCR);
199
Magnus Damm33893d72009-08-06 14:58:43 +0000200 /* setup NAND flash at CS4 */
201 ctrl_outl(0x36db0400, BSC_CS4BCR);
202 ctrl_outl(0x00000500, BSC_CS4WCR);
203
Magnus Damm39a6bf12009-07-22 16:23:45 +0000204 /* setup KEYSC pins */
205 gpio_request(GPIO_FN_KEYOUT0, NULL);
206 gpio_request(GPIO_FN_KEYOUT1, NULL);
207 gpio_request(GPIO_FN_KEYOUT2, NULL);
208 gpio_request(GPIO_FN_KEYOUT3, NULL);
209 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
210 gpio_request(GPIO_FN_KEYIN0, NULL);
211 gpio_request(GPIO_FN_KEYIN1, NULL);
212 gpio_request(GPIO_FN_KEYIN2, NULL);
213 gpio_request(GPIO_FN_KEYIN3, NULL);
214 gpio_request(GPIO_FN_KEYIN4, NULL);
215 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
216
Magnus Damm9f26e652009-08-06 14:51:30 +0000217 /* setup LCDC pins for SYS panel */
218 gpio_request(GPIO_FN_LCDD17, NULL);
219 gpio_request(GPIO_FN_LCDD16, NULL);
220 gpio_request(GPIO_FN_LCDD15, NULL);
221 gpio_request(GPIO_FN_LCDD14, NULL);
222 gpio_request(GPIO_FN_LCDD13, NULL);
223 gpio_request(GPIO_FN_LCDD12, NULL);
224 gpio_request(GPIO_FN_LCDD11, NULL);
225 gpio_request(GPIO_FN_LCDD10, NULL);
226 gpio_request(GPIO_FN_LCDD9, NULL);
227 gpio_request(GPIO_FN_LCDD8, NULL);
228 gpio_request(GPIO_FN_LCDD7, NULL);
229 gpio_request(GPIO_FN_LCDD6, NULL);
230 gpio_request(GPIO_FN_LCDD5, NULL);
231 gpio_request(GPIO_FN_LCDD4, NULL);
232 gpio_request(GPIO_FN_LCDD3, NULL);
233 gpio_request(GPIO_FN_LCDD2, NULL);
234 gpio_request(GPIO_FN_LCDD1, NULL);
235 gpio_request(GPIO_FN_LCDD0, NULL);
236 gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
237 gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
238 gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
239 gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
240 gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
241 gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
242 gpio_direction_output(GPIO_PTE4, 1);
243 gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
244 gpio_direction_output(GPIO_PTF4, 1);
245 gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
246 gpio_direction_output(GPIO_PTU0, 1);
247
Magnus Damma366aa642009-07-22 16:22:28 +0000248 return platform_add_devices(kfr2r09_devices,
249 ARRAY_SIZE(kfr2r09_devices));
Magnus Damme7d16512009-07-22 16:20:54 +0000250}
251device_initcall(kfr2r09_devices_setup);
252
253/* Return the board specific boot mode pin configuration */
254static int kfr2r09_mode_pins(void)
255{
256 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
257 * MD3=0: 16-bit Area0 Bus Width
258 * MD5=1: Little Endian
259 * MD8=1: Test Mode Disabled
260 */
261 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
262}
263
264/*
265 * The Machine Vector
266 */
267static struct sh_machine_vector mv_kfr2r09 __initmv = {
268 .mv_name = "kfr2r09",
269 .mv_mode_pins = kfr2r09_mode_pins,
270};