2 * KZM-A9-GT board support
4 * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
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.
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
20 #include <linux/delay.h>
21 #include <linux/gpio.h>
22 #include <linux/gpio_keys.h>
24 #include <linux/irq.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c/pcf857x.h>
27 #include <linux/input.h>
28 #include <linux/mmc/host.h>
29 #include <linux/mmc/sh_mmcif.h>
30 #include <linux/mmc/sh_mobile_sdhi.h>
31 #include <linux/mfd/tmio.h>
32 #include <linux/platform_device.h>
33 #include <linux/smsc911x.h>
34 #include <linux/usb/r8a66597.h>
35 #include <linux/videodev2.h>
36 #include <mach/irqs.h>
37 #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>
43 #include <video/sh_mobile_lcdc.h>
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)
58 static struct resource smsc9221_resources
[] = {
60 .start
= 0x10000000, /* CS4 */
62 .flags
= IORESOURCE_MEM
,
65 .start
= intcs_evt2irq(0x260), /* IRQ3 */
66 .flags
= IORESOURCE_IRQ
,
70 static 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
,
77 static struct platform_device smsc_device
= {
80 .platform_data
= &smsc9221_platdata
,
82 .resource
= smsc9221_resources
,
83 .num_resources
= ARRAY_SIZE(smsc9221_resources
),
86 /* USB external chip */
87 static struct r8a66597_platdata usb_host_data
= {
89 .xtal
= R8A66597_PLATDATA_XTAL_48MHZ
,
92 static struct resource usb_resources
[] = {
95 .end
= 0x1001ffff - 1,
96 .flags
= IORESOURCE_MEM
,
99 .start
= intcs_evt2irq(0x220), /* IRQ1 */
100 .flags
= IORESOURCE_IRQ
,
104 static struct platform_device usb_host_device
= {
105 .name
= "r8a66597_hcd",
107 .platform_data
= &usb_host_data
,
109 .coherent_dma_mask
= 0xffffffff,
111 .num_resources
= ARRAY_SIZE(usb_resources
),
112 .resource
= usb_resources
,
116 static struct fb_videomode kzm_lcdc_mode
= {
117 .name
= "WVGA Panel",
129 static struct sh_mobile_lcdc_info lcdc_info
= {
130 .clock_source
= LCDC_CLK_BUS
,
132 .chan
= LCDC_CHAN_MAINLCD
,
133 .fourcc
= V4L2_PIX_FMT_RGB565
,
134 .interface_type
= RGB24
,
135 .lcd_modes
= &kzm_lcdc_mode
,
146 static struct resource lcdc_resources
[] = {
151 .flags
= IORESOURCE_MEM
,
154 .start
= intcs_evt2irq(0x580),
155 .flags
= IORESOURCE_IRQ
,
159 static struct platform_device lcdc_device
= {
160 .name
= "sh_mobile_lcdc_fb",
161 .num_resources
= ARRAY_SIZE(lcdc_resources
),
162 .resource
= lcdc_resources
,
164 .platform_data
= &lcdc_info
,
165 .coherent_dma_mask
= ~0,
170 static struct resource sh_mmcif_resources
[] = {
175 .flags
= IORESOURCE_MEM
,
178 .start
= gic_spi(141),
179 .flags
= IORESOURCE_IRQ
,
182 .start
= gic_spi(140),
183 .flags
= IORESOURCE_IRQ
,
187 static struct sh_mmcif_plat_data sh_mmcif_platdata
= {
188 .ocr
= MMC_VDD_165_195
,
189 .caps
= MMC_CAP_8_BIT_DATA
| MMC_CAP_NONREMOVABLE
,
192 static struct platform_device mmc_device
= {
196 .coherent_dma_mask
= 0xffffffff,
197 .platform_data
= &sh_mmcif_platdata
,
199 .num_resources
= ARRAY_SIZE(sh_mmcif_resources
),
200 .resource
= sh_mmcif_resources
,
204 static 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
,
210 static struct resource sdhi0_resources
[] = {
215 .flags
= IORESOURCE_MEM
,
218 .name
= SH_MOBILE_SDHI_IRQ_CARD_DETECT
,
219 .start
= gic_spi(83),
220 .flags
= IORESOURCE_IRQ
,
223 .name
= SH_MOBILE_SDHI_IRQ_SDCARD
,
224 .start
= gic_spi(84),
225 .flags
= IORESOURCE_IRQ
,
228 .name
= SH_MOBILE_SDHI_IRQ_SDIO
,
229 .start
= gic_spi(85),
230 .flags
= IORESOURCE_IRQ
,
234 static struct platform_device sdhi0_device
= {
235 .name
= "sh_mobile_sdhi",
236 .num_resources
= ARRAY_SIZE(sdhi0_resources
),
237 .resource
= sdhi0_resources
,
239 .platform_data
= &sdhi0_info
,
244 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
246 static 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"),
256 static 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 */
262 static struct platform_device gpio_keys_device
= {
263 /* gpio-pcf857x.c driver doesn't support gpio_to_irq() */
264 .name
= "gpio-keys-polled",
266 .platform_data
= &gpio_key_info
,
271 static struct pcf857x_platform_data pcf8575_pdata
= {
272 .gpio_base
= GPIO_PCF8575_BASE
,
275 static struct i2c_board_info i2c1_devices
[] = {
277 I2C_BOARD_INFO("st1232-ts", 0x55),
278 .irq
= intcs_evt2irq(0x300), /* IRQ8 */
282 static struct i2c_board_info i2c3_devices
[] = {
284 I2C_BOARD_INFO("pcf8575", 0x20),
285 .platform_data
= &pcf8575_pdata
,
289 static struct platform_device
*kzm_devices
[] __initdata
= {
301 * This is quick hack for enabling LCDC backlight
303 static int __init
as3711_enable_lcdc_backlight(void)
305 struct i2c_adapter
*a
= i2c_get_adapter(0);
316 0xff, 0x00, /* wait */
322 if (!machine_is_kzm9g())
332 for (i
= 0; i
< ARRAY_SIZE(magic
); i
+= 2) {
335 if (0xff == msg
.buf
[0]) {
340 ret
= i2c_transfer(a
, &msg
, 1);
342 pr_err("i2c transfer fail\n");
349 device_initcall(as3711_enable_lcdc_backlight
);
351 static void __init
kzm_init(void)
353 sh73a0_pinmux_init();
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
);
361 /* CS4 for SMSC/USB */
362 gpio_request(GPIO_FN_CS4_
, NULL
); /* CS4 */
365 gpio_request(GPIO_PORT224
, NULL
); /* IRQ3 */
366 gpio_direction_input(GPIO_PORT224
);
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
);
396 gpio_request(GPIO_PORT222
, NULL
); /* LCDCDON */
397 gpio_request(GPIO_PORT226
, NULL
); /* SC */
398 gpio_direction_output(GPIO_PORT222
, 1);
399 gpio_direction_output(GPIO_PORT226
, 1);
402 gpio_request(GPIO_PORT223
, NULL
); /* IRQ8 */
403 gpio_direction_input(GPIO_PORT223
);
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
);
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 */
431 gpio_request(GPIO_FN_PORT27_I2C_SCL3
, NULL
);
432 gpio_request(GPIO_FN_PORT28_I2C_SDA3
, NULL
);
434 #ifdef CONFIG_CACHE_L2X0
435 /* Early BRESP enable, Shared attribute override enable, 64K*8way */
436 l2x0_init(IOMEM(0xf0100000), 0x40460000, 0x82000fff);
439 i2c_register_board_info(1, i2c1_devices
, ARRAY_SIZE(i2c1_devices
));
440 i2c_register_board_info(3, i2c3_devices
, ARRAY_SIZE(i2c3_devices
));
442 sh73a0_add_standard_devices();
443 platform_add_devices(kzm_devices
, ARRAY_SIZE(kzm_devices
));
446 static const char *kzm9g_boards_compat_dt
[] __initdata
= {
451 DT_MACHINE_START(KZM9G_DT
, "kzm9g")
452 .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
,
458 .init_late
= shmobile_init_late
,
459 .timer
= &shmobile_timer
,
460 .dt_compat
= kzm9g_boards_compat_dt
,