blob: c0ae815e7beb18a9be40be4bb892bfb725af7b78 [file] [log] [blame]
Kuninori Morimoto9b93e242012-04-10 20:57:31 -07001/*
2 * KZM-A9-GT board support
3 *
4 * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
Kuninori Morimoto26786112012-04-10 20:58:33 -070019
20#include <linux/delay.h>
Kuninori Morimoto9b93e242012-04-10 20:57:31 -070021#include <linux/gpio.h>
Kuninori Morimoto1e354642012-04-22 23:54:14 -070022#include <linux/gpio_keys.h>
Kuninori Morimoto9b93e242012-04-10 20:57:31 -070023#include <linux/io.h>
24#include <linux/irq.h>
Kuninori Morimoto407c0522012-04-10 20:58:45 -070025#include <linux/i2c.h>
Kuninori Morimoto1e354642012-04-22 23:54:14 -070026#include <linux/i2c/pcf857x.h>
27#include <linux/input.h>
Kuninori Morimotocc2512b2012-04-22 23:53:40 -070028#include <linux/mmc/host.h>
29#include <linux/mmc/sh_mmcif.h>
Kuninori Morimoto7775a932012-04-22 23:53:59 -070030#include <linux/mmc/sh_mobile_sdhi.h>
31#include <linux/mfd/tmio.h>
Kuninori Morimoto9b93e242012-04-10 20:57:31 -070032#include <linux/platform_device.h>
Kuninori Morimotoc15c4252012-04-10 20:57:58 -070033#include <linux/smsc911x.h>
Kuninori Morimotodd818182012-04-10 20:58:10 -070034#include <linux/usb/r8a66597.h>
Kuninori Morimoto26786112012-04-10 20:58:33 -070035#include <linux/videodev2.h>
Kuninori Morimotoc15c4252012-04-10 20:57:58 -070036#include <mach/irqs.h>
Kuninori Morimoto9b93e242012-04-10 20:57:31 -070037#include <mach/sh73a0.h>
38#include <mach/common.h>
39#include <asm/hardware/cache-l2x0.h>
40#include <asm/hardware/gic.h>
41#include <asm/mach-types.h>
42#include <asm/mach/arch.h>
Kuninori Morimoto26786112012-04-10 20:58:33 -070043#include <video/sh_mobile_lcdc.h>
Kuninori Morimoto9b93e242012-04-10 20:57:31 -070044
Kuninori Morimoto1e354642012-04-22 23:54:14 -070045/*
46 * external GPIO
47 */
48#define GPIO_PCF8575_BASE (GPIO_NR)
49#define GPIO_PCF8575_PORT10 (GPIO_NR + 8)
50#define GPIO_PCF8575_PORT11 (GPIO_NR + 9)
51#define GPIO_PCF8575_PORT12 (GPIO_NR + 10)
52#define GPIO_PCF8575_PORT13 (GPIO_NR + 11)
53#define GPIO_PCF8575_PORT14 (GPIO_NR + 12)
54#define GPIO_PCF8575_PORT15 (GPIO_NR + 13)
55#define GPIO_PCF8575_PORT16 (GPIO_NR + 14)
56
Kuninori Morimotoc15c4252012-04-10 20:57:58 -070057/* SMSC 9221 */
58static struct resource smsc9221_resources[] = {
59 [0] = {
60 .start = 0x10000000, /* CS4 */
61 .end = 0x100000ff,
62 .flags = IORESOURCE_MEM,
63 },
64 [1] = {
65 .start = intcs_evt2irq(0x260), /* IRQ3 */
66 .flags = IORESOURCE_IRQ,
67 },
68};
69
70static struct smsc911x_platform_config smsc9221_platdata = {
71 .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
72 .phy_interface = PHY_INTERFACE_MODE_MII,
73 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
74 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
75};
76
77static struct platform_device smsc_device = {
78 .name = "smsc911x",
79 .dev = {
80 .platform_data = &smsc9221_platdata,
81 },
82 .resource = smsc9221_resources,
83 .num_resources = ARRAY_SIZE(smsc9221_resources),
84};
85
Kuninori Morimotodd818182012-04-10 20:58:10 -070086/* USB external chip */
87static struct r8a66597_platdata usb_host_data = {
88 .on_chip = 0,
89 .xtal = R8A66597_PLATDATA_XTAL_48MHZ,
90};
91
92static struct resource usb_resources[] = {
93 [0] = {
94 .start = 0x10010000,
95 .end = 0x1001ffff - 1,
96 .flags = IORESOURCE_MEM,
97 },
98 [1] = {
99 .start = intcs_evt2irq(0x220), /* IRQ1 */
100 .flags = IORESOURCE_IRQ,
101 },
102};
103
104static struct platform_device usb_host_device = {
105 .name = "r8a66597_hcd",
106 .dev = {
107 .platform_data = &usb_host_data,
108 .dma_mask = NULL,
109 .coherent_dma_mask = 0xffffffff,
110 },
111 .num_resources = ARRAY_SIZE(usb_resources),
112 .resource = usb_resources,
113};
114
Kuninori Morimoto26786112012-04-10 20:58:33 -0700115/* LCDC */
116static struct fb_videomode kzm_lcdc_mode = {
117 .name = "WVGA Panel",
118 .xres = 800,
119 .yres = 480,
120 .left_margin = 220,
121 .right_margin = 110,
122 .hsync_len = 70,
123 .upper_margin = 20,
124 .lower_margin = 5,
125 .vsync_len = 5,
126 .sync = 0,
127};
128
129static struct sh_mobile_lcdc_info lcdc_info = {
130 .clock_source = LCDC_CLK_BUS,
131 .ch[0] = {
132 .chan = LCDC_CHAN_MAINLCD,
133 .fourcc = V4L2_PIX_FMT_RGB565,
134 .interface_type = RGB24,
135 .lcd_modes = &kzm_lcdc_mode,
136 .num_modes = 1,
137 .clock_divider = 5,
138 .flags = 0,
139 .panel_cfg = {
140 .width = 152,
141 .height = 91,
142 },
143 }
144};
145
146static struct resource lcdc_resources[] = {
147 [0] = {
148 .name = "LCDC",
149 .start = 0xfe940000,
150 .end = 0xfe943fff,
151 .flags = IORESOURCE_MEM,
152 },
153 [1] = {
154 .start = intcs_evt2irq(0x580),
155 .flags = IORESOURCE_IRQ,
156 },
157};
158
159static struct platform_device lcdc_device = {
160 .name = "sh_mobile_lcdc_fb",
161 .num_resources = ARRAY_SIZE(lcdc_resources),
162 .resource = lcdc_resources,
163 .dev = {
164 .platform_data = &lcdc_info,
165 .coherent_dma_mask = ~0,
166 },
167};
168
Kuninori Morimotocc2512b2012-04-22 23:53:40 -0700169/* MMCIF */
170static struct resource sh_mmcif_resources[] = {
171 [0] = {
172 .name = "MMCIF",
173 .start = 0xe6bd0000,
174 .end = 0xe6bd00ff,
175 .flags = IORESOURCE_MEM,
176 },
177 [1] = {
178 .start = gic_spi(141),
179 .flags = IORESOURCE_IRQ,
180 },
181 [2] = {
182 .start = gic_spi(140),
183 .flags = IORESOURCE_IRQ,
184 },
185};
186
187static struct sh_mmcif_plat_data sh_mmcif_platdata = {
188 .ocr = MMC_VDD_165_195,
189 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
190};
191
192static struct platform_device mmc_device = {
193 .name = "sh_mmcif",
194 .dev = {
195 .dma_mask = NULL,
196 .coherent_dma_mask = 0xffffffff,
197 .platform_data = &sh_mmcif_platdata,
198 },
199 .num_resources = ARRAY_SIZE(sh_mmcif_resources),
200 .resource = sh_mmcif_resources,
201};
202
Kuninori Morimoto7775a932012-04-22 23:53:59 -0700203/* SDHI */
204static struct sh_mobile_sdhi_info sdhi0_info = {
205 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
206 .tmio_caps = MMC_CAP_SD_HIGHSPEED,
207 .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
208};
209
210static struct resource sdhi0_resources[] = {
211 [0] = {
212 .name = "SDHI0",
213 .start = 0xee100000,
214 .end = 0xee1000ff,
215 .flags = IORESOURCE_MEM,
216 },
217 [1] = {
218 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
219 .start = gic_spi(83),
220 .flags = IORESOURCE_IRQ,
221 },
222 [2] = {
223 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
224 .start = gic_spi(84),
225 .flags = IORESOURCE_IRQ,
226 },
227 [3] = {
228 .name = SH_MOBILE_SDHI_IRQ_SDIO,
229 .start = gic_spi(85),
230 .flags = IORESOURCE_IRQ,
231 },
232};
233
234static struct platform_device sdhi0_device = {
235 .name = "sh_mobile_sdhi",
236 .num_resources = ARRAY_SIZE(sdhi0_resources),
237 .resource = sdhi0_resources,
238 .dev = {
239 .platform_data = &sdhi0_info,
240 },
241};
242
Kuninori Morimoto1e354642012-04-22 23:54:14 -0700243/* KEY */
244#define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
245
246static struct gpio_keys_button gpio_buttons[] = {
247 GPIO_KEY(KEY_BACK, GPIO_PCF8575_PORT10, "SW3"),
248 GPIO_KEY(KEY_RIGHT, GPIO_PCF8575_PORT11, "SW2-R"),
249 GPIO_KEY(KEY_LEFT, GPIO_PCF8575_PORT12, "SW2-L"),
250 GPIO_KEY(KEY_ENTER, GPIO_PCF8575_PORT13, "SW2-P"),
251 GPIO_KEY(KEY_UP, GPIO_PCF8575_PORT14, "SW2-U"),
252 GPIO_KEY(KEY_DOWN, GPIO_PCF8575_PORT15, "SW2-D"),
253 GPIO_KEY(KEY_HOME, GPIO_PCF8575_PORT16, "SW1"),
254};
255
256static struct gpio_keys_platform_data gpio_key_info = {
257 .buttons = gpio_buttons,
258 .nbuttons = ARRAY_SIZE(gpio_buttons),
259 .poll_interval = 250, /* poling at this point */
260};
261
262static struct platform_device gpio_keys_device = {
263 /* gpio-pcf857x.c driver doesn't support gpio_to_irq() */
264 .name = "gpio-keys-polled",
265 .dev = {
266 .platform_data = &gpio_key_info,
267 },
268};
269
Kuninori Morimoto7775a932012-04-22 23:53:59 -0700270/* I2C */
Kuninori Morimoto1e354642012-04-22 23:54:14 -0700271static struct pcf857x_platform_data pcf8575_pdata = {
272 .gpio_base = GPIO_PCF8575_BASE,
273};
274
Kuninori Morimoto407c0522012-04-10 20:58:45 -0700275static struct i2c_board_info i2c1_devices[] = {
276 {
277 I2C_BOARD_INFO("st1232-ts", 0x55),
278 .irq = intcs_evt2irq(0x300), /* IRQ8 */
279 },
280};
281
Kuninori Morimoto1e354642012-04-22 23:54:14 -0700282static struct i2c_board_info i2c3_devices[] = {
283 {
284 I2C_BOARD_INFO("pcf8575", 0x20),
285 .platform_data = &pcf8575_pdata,
286 },
287};
288
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700289static struct platform_device *kzm_devices[] __initdata = {
Kuninori Morimotoc15c4252012-04-10 20:57:58 -0700290 &smsc_device,
Kuninori Morimotodd818182012-04-10 20:58:10 -0700291 &usb_host_device,
Kuninori Morimoto26786112012-04-10 20:58:33 -0700292 &lcdc_device,
Kuninori Morimotocc2512b2012-04-22 23:53:40 -0700293 &mmc_device,
Kuninori Morimoto7775a932012-04-22 23:53:59 -0700294 &sdhi0_device,
Kuninori Morimoto1e354642012-04-22 23:54:14 -0700295 &gpio_keys_device,
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700296};
297
Kuninori Morimoto26786112012-04-10 20:58:33 -0700298/*
299 * FIXME
300 *
301 * This is quick hack for enabling LCDC backlight
302 */
303static int __init as3711_enable_lcdc_backlight(void)
304{
305 struct i2c_adapter *a = i2c_get_adapter(0);
306 struct i2c_msg msg;
307 int i, ret;
308 __u8 magic[] = {
309 0x40, 0x2a,
310 0x43, 0x3c,
311 0x44, 0x3c,
312 0x45, 0x3c,
313 0x54, 0x03,
314 0x51, 0x00,
315 0x51, 0x01,
316 0xff, 0x00, /* wait */
317 0x43, 0xf0,
318 0x44, 0xf0,
319 0x45, 0xf0,
320 };
321
322 if (!machine_is_kzm9g())
323 return 0;
324
325 if (!a)
326 return 0;
327
328 msg.addr = 0x40;
329 msg.len = 2;
330 msg.flags = 0;
331
332 for (i = 0; i < ARRAY_SIZE(magic); i += 2) {
333 msg.buf = magic + i;
334
335 if (0xff == msg.buf[0]) {
336 udelay(500);
337 continue;
338 }
339
340 ret = i2c_transfer(a, &msg, 1);
341 if (ret < 0) {
342 pr_err("i2c transfer fail\n");
343 break;
344 }
345 }
346
347 return 0;
348}
349device_initcall(as3711_enable_lcdc_backlight);
350
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700351static void __init kzm_init(void)
352{
353 sh73a0_pinmux_init();
354
355 /* enable SCIFA4 */
356 gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
357 gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
358 gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
359 gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
360
Kuninori Morimotoc15c4252012-04-10 20:57:58 -0700361 /* CS4 for SMSC/USB */
362 gpio_request(GPIO_FN_CS4_, NULL); /* CS4 */
363
364 /* SMSC */
365 gpio_request(GPIO_PORT224, NULL); /* IRQ3 */
366 gpio_direction_input(GPIO_PORT224);
367
Kuninori Morimoto26786112012-04-10 20:58:33 -0700368 /* LCDC */
369 gpio_request(GPIO_FN_LCDD23, NULL);
370 gpio_request(GPIO_FN_LCDD22, NULL);
371 gpio_request(GPIO_FN_LCDD21, NULL);
372 gpio_request(GPIO_FN_LCDD20, NULL);
373 gpio_request(GPIO_FN_LCDD19, NULL);
374 gpio_request(GPIO_FN_LCDD18, NULL);
375 gpio_request(GPIO_FN_LCDD17, NULL);
376 gpio_request(GPIO_FN_LCDD16, NULL);
377 gpio_request(GPIO_FN_LCDD15, NULL);
378 gpio_request(GPIO_FN_LCDD14, NULL);
379 gpio_request(GPIO_FN_LCDD13, NULL);
380 gpio_request(GPIO_FN_LCDD12, NULL);
381 gpio_request(GPIO_FN_LCDD11, NULL);
382 gpio_request(GPIO_FN_LCDD10, NULL);
383 gpio_request(GPIO_FN_LCDD9, NULL);
384 gpio_request(GPIO_FN_LCDD8, NULL);
385 gpio_request(GPIO_FN_LCDD7, NULL);
386 gpio_request(GPIO_FN_LCDD6, NULL);
387 gpio_request(GPIO_FN_LCDD5, NULL);
388 gpio_request(GPIO_FN_LCDD4, NULL);
389 gpio_request(GPIO_FN_LCDD3, NULL);
390 gpio_request(GPIO_FN_LCDD2, NULL);
391 gpio_request(GPIO_FN_LCDD1, NULL);
392 gpio_request(GPIO_FN_LCDD0, NULL);
393 gpio_request(GPIO_FN_LCDDISP, NULL);
394 gpio_request(GPIO_FN_LCDDCK, NULL);
395
Kuninori Morimoto601df612012-04-22 23:53:24 -0700396 gpio_request(GPIO_PORT222, NULL); /* LCDCDON */
397 gpio_request(GPIO_PORT226, NULL); /* SC */
Kuninori Morimoto26786112012-04-10 20:58:33 -0700398 gpio_direction_output(GPIO_PORT222, 1);
Kuninori Morimoto601df612012-04-22 23:53:24 -0700399 gpio_direction_output(GPIO_PORT226, 1);
Kuninori Morimoto26786112012-04-10 20:58:33 -0700400
Kuninori Morimoto407c0522012-04-10 20:58:45 -0700401 /* Touchscreen */
402 gpio_request(GPIO_PORT223, NULL); /* IRQ8 */
403 gpio_direction_input(GPIO_PORT223);
404
Kuninori Morimotocc2512b2012-04-22 23:53:40 -0700405 /* enable MMCIF */
406 gpio_request(GPIO_FN_MMCCLK0, NULL);
407 gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
408 gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
409 gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
410 gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
411 gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
412 gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
413 gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
414 gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
415 gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
416
Kuninori Morimoto7775a932012-04-22 23:53:59 -0700417 /* enable SD */
418 gpio_request(GPIO_FN_SDHIWP0, NULL);
419 gpio_request(GPIO_FN_SDHICD0, NULL);
420 gpio_request(GPIO_FN_SDHICMD0, NULL);
421 gpio_request(GPIO_FN_SDHICLK0, NULL);
422 gpio_request(GPIO_FN_SDHID0_3, NULL);
423 gpio_request(GPIO_FN_SDHID0_2, NULL);
424 gpio_request(GPIO_FN_SDHID0_1, NULL);
425 gpio_request(GPIO_FN_SDHID0_0, NULL);
426 gpio_request(GPIO_FN_SDHI0_VCCQ_MC0_ON, NULL);
427 gpio_request(GPIO_PORT15, NULL);
428 gpio_direction_output(GPIO_PORT15, 1); /* power */
429
Kuninori Morimoto1e354642012-04-22 23:54:14 -0700430 /* I2C 3 */
431 gpio_request(GPIO_FN_PORT27_I2C_SCL3, NULL);
432 gpio_request(GPIO_FN_PORT28_I2C_SDA3, NULL);
433
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700434#ifdef CONFIG_CACHE_L2X0
435 /* Early BRESP enable, Shared attribute override enable, 64K*8way */
436 l2x0_init(IOMEM(0xf0100000), 0x40460000, 0x82000fff);
437#endif
438
Kuninori Morimoto407c0522012-04-10 20:58:45 -0700439 i2c_register_board_info(1, i2c1_devices, ARRAY_SIZE(i2c1_devices));
Kuninori Morimoto1e354642012-04-22 23:54:14 -0700440 i2c_register_board_info(3, i2c3_devices, ARRAY_SIZE(i2c3_devices));
Kuninori Morimoto407c0522012-04-10 20:58:45 -0700441
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700442 sh73a0_add_standard_devices();
443 platform_add_devices(kzm_devices, ARRAY_SIZE(kzm_devices));
444}
445
Magnus Damm7296d932012-05-14 23:22:28 +0200446static const char *kzm9g_boards_compat_dt[] __initdata = {
447 "renesas,kzm9g",
448 NULL,
449};
450
451DT_MACHINE_START(KZM9G_DT, "kzm9g")
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700452 .map_io = sh73a0_map_io,
453 .init_early = sh73a0_add_early_devices,
454 .nr_irqs = NR_IRQS_LEGACY,
455 .init_irq = sh73a0_init_irq,
456 .handle_irq = gic_handle_irq,
457 .init_machine = kzm_init,
Kuninori Morimoto14dd52f42012-06-20 22:40:08 -0700458 .init_late = shmobile_init_late,
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700459 .timer = &shmobile_timer,
Magnus Damm7296d932012-05-14 23:22:28 +0200460 .dt_compat = kzm9g_boards_compat_dt,
Kuninori Morimoto9b93e242012-04-10 20:57:31 -0700461MACHINE_END