blob: d4ac32b63572fa245649032e01e0d45bc1d23cc0 [file] [log] [blame]
Kuninori Morimoto4138b742009-08-19 12:08:33 +00001/*
2 * Copyright (C) 2009 Renesas Solutions Corp.
3 *
4 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
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
11#include <linux/init.h>
12#include <linux/device.h>
13#include <linux/platform_device.h>
14#include <linux/mtd/physmap.h>
15#include <linux/gpio.h>
16#include <linux/interrupt.h>
Kuninori Morimoto35a35402009-08-26 11:04:26 +000017#include <linux/io.h>
18#include <linux/delay.h>
Kuninori Morimoto907050a2009-08-26 11:04:31 +000019#include <linux/usb/r8a66597.h>
Kuninori Morimoto4907d572009-09-10 01:39:58 +000020#include <linux/i2c.h>
Kuninori Morimoto8810e052009-09-28 08:21:41 +000021#include <linux/i2c/tsc2007.h>
Magnus Damm1ce4da72009-12-07 14:05:45 +000022#include <linux/spi/spi.h>
23#include <linux/spi/sh_msiof.h>
24#include <linux/spi/mmc_spi.h>
25#include <linux/mmc/host.h>
Kuninori Morimotoe9103e72009-09-14 11:23:00 +000026#include <linux/input.h>
Magnus Dammfc1d0032009-11-27 07:32:24 +000027#include <linux/input/sh_keysc.h>
Magnus Damm98779ad2009-11-27 04:36:58 +000028#include <linux/mfd/sh_mobile_sdhi.h>
Kuninori Morimotofa3ba512009-08-26 11:04:34 +000029#include <video/sh_mobile_lcdc.h>
Kuninori Morimoto2153ad32009-08-26 11:04:36 +000030#include <media/sh_mobile_ceu.h>
Kuninori Morimoto207efd02009-12-15 05:37:16 +000031#include <media/tw9910.h>
Kuninori Morimoto4138b742009-08-19 12:08:33 +000032#include <asm/heartbeat.h>
Kuninori Morimoto35a35402009-08-26 11:04:26 +000033#include <asm/sh_eth.h>
Kuninori Morimotoa9918012009-09-14 11:23:16 +000034#include <asm/clock.h>
Magnus Dammeb0cd9e2009-10-30 04:23:59 +000035#include <asm/suspend.h>
Kuninori Morimoto4138b742009-08-19 12:08:33 +000036#include <cpu/sh7724.h>
37
38/*
Kuninori Morimotob7056bc2009-08-26 11:04:22 +000039 * Address Interface BusWidth
40 *-----------------------------------------
41 * 0x0000_0000 uboot 16bit
42 * 0x0004_0000 Linux romImage 16bit
43 * 0x0014_0000 MTD for Linux 16bit
44 * 0x0400_0000 Internal I/O 16/32bit
45 * 0x0800_0000 DRAM 32bit
46 * 0x1800_0000 MFI 16bit
Kuninori Morimoto4138b742009-08-19 12:08:33 +000047 */
48
Kuninori Morimoto9c472c42009-10-02 07:52:20 +000049/* SWITCH
50 *------------------------------
51 * DS2[1] = FlashROM write protect ON : write protect
52 * OFF : No write protect
53 * DS2[2] = RMII / TS, SCIF ON : RMII
54 * OFF : TS, SCIF3
55 * DS2[3] = Camera / Video ON : Camera
56 * OFF : NTSC/PAL (IN)
57 * DS2[5] = NTSC_OUT Clock ON : On board OSC
58 * OFF : SH7724 DV_CLK
59 * DS2[6-7] = MMC / SD ON-OFF : SD
60 * OFF-ON : MMC
61 */
62
Kuninori Morimoto4138b742009-08-19 12:08:33 +000063/* Heartbeat */
64static unsigned char led_pos[] = { 0, 1, 2, 3 };
65static struct heartbeat_data heartbeat_data = {
66 .regsize = 8,
67 .nr_bits = 4,
68 .bit_pos = led_pos,
69};
70
71static struct resource heartbeat_resources[] = {
72 [0] = {
73 .start = 0xA405012C, /* PTG */
74 .end = 0xA405012E - 1,
75 .flags = IORESOURCE_MEM,
76 },
77};
78
79static struct platform_device heartbeat_device = {
80 .name = "heartbeat",
81 .id = -1,
82 .dev = {
83 .platform_data = &heartbeat_data,
84 },
85 .num_resources = ARRAY_SIZE(heartbeat_resources),
86 .resource = heartbeat_resources,
87};
88
89/* MTD */
90static struct mtd_partition nor_flash_partitions[] = {
91 {
Kuninori Morimotob7056bc2009-08-26 11:04:22 +000092 .name = "boot loader",
Kuninori Morimoto4138b742009-08-19 12:08:33 +000093 .offset = 0,
Kuninori Morimotob7056bc2009-08-26 11:04:22 +000094 .size = (5 * 1024 * 1024),
Kuninori Morimotod5ce0102009-09-30 00:50:30 +000095 .mask_flags = MTD_WRITEABLE, /* force read-only */
Kuninori Morimoto4138b742009-08-19 12:08:33 +000096 }, {
Kuninori Morimoto4138b742009-08-19 12:08:33 +000097 .name = "free-area",
98 .offset = MTDPART_OFS_APPEND,
99 .size = MTDPART_SIZ_FULL,
100 },
101};
102
103static struct physmap_flash_data nor_flash_data = {
104 .width = 2,
105 .parts = nor_flash_partitions,
106 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
107};
108
109static struct resource nor_flash_resources[] = {
110 [0] = {
111 .name = "NOR Flash",
112 .start = 0x00000000,
113 .end = 0x03ffffff,
114 .flags = IORESOURCE_MEM,
115 }
116};
117
118static struct platform_device nor_flash_device = {
119 .name = "physmap-flash",
120 .resource = nor_flash_resources,
121 .num_resources = ARRAY_SIZE(nor_flash_resources),
122 .dev = {
123 .platform_data = &nor_flash_data,
124 },
125};
126
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000127/* SH Eth */
128#define SH_ETH_ADDR (0xA4600000)
129#define SH_ETH_MAHR (SH_ETH_ADDR + 0x1C0)
130#define SH_ETH_MALR (SH_ETH_ADDR + 0x1C8)
131static struct resource sh_eth_resources[] = {
132 [0] = {
133 .start = SH_ETH_ADDR,
134 .end = SH_ETH_ADDR + 0x1FC,
135 .flags = IORESOURCE_MEM,
136 },
137 [1] = {
138 .start = 91,
139 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
140 },
141};
142
143struct sh_eth_plat_data sh_eth_plat = {
144 .phy = 0x1f, /* SMSC LAN8700 */
145 .edmac_endian = EDMAC_LITTLE_ENDIAN,
Kuninori Morimotoacf3cc22009-09-24 06:28:27 +0000146 .ether_link_active_low = 1
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000147};
148
149static struct platform_device sh_eth_device = {
150 .name = "sh-eth",
151 .id = 0,
152 .dev = {
153 .platform_data = &sh_eth_plat,
154 },
155 .num_resources = ARRAY_SIZE(sh_eth_resources),
156 .resource = sh_eth_resources,
Magnus Damm40e42312009-10-26 10:41:58 +0000157 .archdata = {
158 .hwblk_id = HWBLK_ETHER,
159 },
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000160};
161
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000162/* USB0 host */
163void usb0_port_power(int port, int power)
164{
165 gpio_set_value(GPIO_PTB4, power);
166}
167
168static struct r8a66597_platdata usb0_host_data = {
169 .on_chip = 1,
170 .port_power = usb0_port_power,
171};
172
173static struct resource usb0_host_resources[] = {
174 [0] = {
175 .start = 0xa4d80000,
176 .end = 0xa4d80124 - 1,
177 .flags = IORESOURCE_MEM,
178 },
179 [1] = {
180 .start = 65,
181 .end = 65,
182 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
183 },
184};
185
186static struct platform_device usb0_host_device = {
187 .name = "r8a66597_hcd",
188 .id = 0,
189 .dev = {
190 .dma_mask = NULL, /* not use dma */
191 .coherent_dma_mask = 0xffffffff,
192 .platform_data = &usb0_host_data,
193 },
194 .num_resources = ARRAY_SIZE(usb0_host_resources),
195 .resource = usb0_host_resources,
196};
197
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000198/* USB1 host/function */
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000199void usb1_port_power(int port, int power)
200{
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000201 gpio_set_value(GPIO_PTB5, power);
202}
203
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000204static struct r8a66597_platdata usb1_common_data = {
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000205 .on_chip = 1,
206 .port_power = usb1_port_power,
207};
208
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000209static struct resource usb1_common_resources[] = {
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000210 [0] = {
211 .start = 0xa4d90000,
212 .end = 0xa4d90124 - 1,
213 .flags = IORESOURCE_MEM,
214 },
215 [1] = {
216 .start = 66,
217 .end = 66,
218 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
219 },
220};
221
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000222static struct platform_device usb1_common_device = {
223 /* .name will be added in arch_setup */
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000224 .id = 1,
225 .dev = {
226 .dma_mask = NULL, /* not use dma */
227 .coherent_dma_mask = 0xffffffff,
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000228 .platform_data = &usb1_common_data,
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000229 },
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000230 .num_resources = ARRAY_SIZE(usb1_common_resources),
231 .resource = usb1_common_resources,
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000232};
233
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000234/* LCDC */
235static struct sh_mobile_lcdc_info lcdc_info = {
236 .ch[0] = {
237 .interface_type = RGB18,
238 .chan = LCDC_CHAN_MAINLCD,
239 .bpp = 16,
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000240 .lcd_cfg = {
241 .sync = 0, /* hsync and vsync are active low */
242 },
243 .lcd_size_cfg = { /* 7.0 inch */
244 .width = 152,
245 .height = 91,
246 },
247 .board_cfg = {
248 },
249 }
250};
251
252static struct resource lcdc_resources[] = {
253 [0] = {
254 .name = "LCDC",
255 .start = 0xfe940000,
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000256 .end = 0xfe942fff,
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000257 .flags = IORESOURCE_MEM,
258 },
259 [1] = {
260 .start = 106,
261 .flags = IORESOURCE_IRQ,
262 },
263};
264
265static struct platform_device lcdc_device = {
266 .name = "sh_mobile_lcdc_fb",
267 .num_resources = ARRAY_SIZE(lcdc_resources),
268 .resource = lcdc_resources,
269 .dev = {
270 .platform_data = &lcdc_info,
271 },
272 .archdata = {
273 .hwblk_id = HWBLK_LCDC,
274 },
275};
276
Kuninori Morimoto2153ad32009-08-26 11:04:36 +0000277/* CEU0 */
278static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
279 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
280};
281
282static struct resource ceu0_resources[] = {
283 [0] = {
284 .name = "CEU0",
285 .start = 0xfe910000,
286 .end = 0xfe91009f,
287 .flags = IORESOURCE_MEM,
288 },
289 [1] = {
290 .start = 52,
291 .flags = IORESOURCE_IRQ,
292 },
293 [2] = {
294 /* place holder for contiguous memory */
295 },
296};
297
298static struct platform_device ceu0_device = {
299 .name = "sh_mobile_ceu",
300 .id = 0, /* "ceu0" clock */
301 .num_resources = ARRAY_SIZE(ceu0_resources),
302 .resource = ceu0_resources,
303 .dev = {
304 .platform_data = &sh_mobile_ceu0_info,
305 },
306 .archdata = {
307 .hwblk_id = HWBLK_CEU0,
308 },
309};
310
311/* CEU1 */
312static struct sh_mobile_ceu_info sh_mobile_ceu1_info = {
313 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
314};
315
316static struct resource ceu1_resources[] = {
317 [0] = {
318 .name = "CEU1",
319 .start = 0xfe914000,
320 .end = 0xfe91409f,
321 .flags = IORESOURCE_MEM,
322 },
323 [1] = {
324 .start = 63,
325 .flags = IORESOURCE_IRQ,
326 },
327 [2] = {
328 /* place holder for contiguous memory */
329 },
330};
331
332static struct platform_device ceu1_device = {
333 .name = "sh_mobile_ceu",
334 .id = 1, /* "ceu1" clock */
335 .num_resources = ARRAY_SIZE(ceu1_resources),
336 .resource = ceu1_resources,
337 .dev = {
338 .platform_data = &sh_mobile_ceu1_info,
339 },
340 .archdata = {
341 .hwblk_id = HWBLK_CEU1,
342 },
343};
344
Kuninori Morimoto125ecce2009-09-10 01:39:37 +0000345/* I2C device */
346static struct i2c_board_info i2c1_devices[] = {
347 {
348 I2C_BOARD_INFO("r2025sd", 0x32),
349 },
350};
351
Kuninori Morimotoe9103e72009-09-14 11:23:00 +0000352/* KEYSC */
353static struct sh_keysc_info keysc_info = {
354 .mode = SH_KEYSC_MODE_1,
355 .scan_timing = 3,
356 .delay = 50,
357 .kycr2_delay = 100,
358 .keycodes = { KEY_1, 0, 0, 0, 0,
359 KEY_2, 0, 0, 0, 0,
360 KEY_3, 0, 0, 0, 0,
361 KEY_4, 0, 0, 0, 0,
362 KEY_5, 0, 0, 0, 0,
363 KEY_6, 0, 0, 0, 0, },
364};
365
366static struct resource keysc_resources[] = {
367 [0] = {
368 .name = "KEYSC",
369 .start = 0x044b0000,
370 .end = 0x044b000f,
371 .flags = IORESOURCE_MEM,
372 },
373 [1] = {
374 .start = 79,
375 .flags = IORESOURCE_IRQ,
376 },
377};
378
379static struct platform_device keysc_device = {
380 .name = "sh_keysc",
381 .id = 0, /* keysc0 clock */
382 .num_resources = ARRAY_SIZE(keysc_resources),
383 .resource = keysc_resources,
384 .dev = {
385 .platform_data = &keysc_info,
386 },
387 .archdata = {
388 .hwblk_id = HWBLK_KEYSC,
389 },
390};
391
Kuninori Morimoto8810e052009-09-28 08:21:41 +0000392/* TouchScreen */
393#define IRQ0 32
394static int ts_get_pendown_state(void)
395{
396 int val = 0;
397 gpio_free(GPIO_FN_INTC_IRQ0);
398 gpio_request(GPIO_PTZ0, NULL);
399 gpio_direction_input(GPIO_PTZ0);
400
401 val = gpio_get_value(GPIO_PTZ0);
402
403 gpio_free(GPIO_PTZ0);
404 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
405
406 return val ? 0 : 1;
407}
408
409static int ts_init(void)
410{
411 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
412 return 0;
413}
414
415struct tsc2007_platform_data tsc2007_info = {
416 .model = 2007,
417 .x_plate_ohms = 180,
418 .get_pendown_state = ts_get_pendown_state,
419 .init_platform_hw = ts_init,
420};
421
422static struct i2c_board_info ts_i2c_clients = {
423 I2C_BOARD_INFO("tsc2007", 0x48),
424 .type = "tsc2007",
425 .platform_data = &tsc2007_info,
426 .irq = IRQ0,
427};
428
Magnus Damm1ce4da72009-12-07 14:05:45 +0000429#ifdef CONFIG_MFD_SH_MOBILE_SDHI
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000430/* SHDI0 */
Magnus Damm98779ad2009-11-27 04:36:58 +0000431static void sdhi0_set_pwr(struct platform_device *pdev, int state)
432{
433 gpio_set_value(GPIO_PTB6, state);
434}
435
436static struct sh_mobile_sdhi_info sdhi0_info = {
437 .set_pwr = sdhi0_set_pwr,
438};
439
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000440static struct resource sdhi0_resources[] = {
441 [0] = {
442 .name = "SDHI0",
443 .start = 0x04ce0000,
444 .end = 0x04ce01ff,
445 .flags = IORESOURCE_MEM,
446 },
447 [1] = {
448 .start = 101,
449 .flags = IORESOURCE_IRQ,
450 },
451};
452
453static struct platform_device sdhi0_device = {
454 .name = "sh_mobile_sdhi",
455 .num_resources = ARRAY_SIZE(sdhi0_resources),
456 .resource = sdhi0_resources,
457 .id = 0,
Magnus Damm98779ad2009-11-27 04:36:58 +0000458 .dev = {
459 .platform_data = &sdhi0_info,
460 },
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000461 .archdata = {
462 .hwblk_id = HWBLK_SDHI0,
463 },
464};
465
466/* SHDI1 */
Magnus Damm98779ad2009-11-27 04:36:58 +0000467static void sdhi1_set_pwr(struct platform_device *pdev, int state)
468{
469 gpio_set_value(GPIO_PTB7, state);
470}
471
472static struct sh_mobile_sdhi_info sdhi1_info = {
473 .set_pwr = sdhi1_set_pwr,
474};
475
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000476static struct resource sdhi1_resources[] = {
477 [0] = {
478 .name = "SDHI1",
479 .start = 0x04cf0000,
480 .end = 0x04cf01ff,
481 .flags = IORESOURCE_MEM,
482 },
483 [1] = {
484 .start = 24,
485 .flags = IORESOURCE_IRQ,
486 },
487};
488
489static struct platform_device sdhi1_device = {
490 .name = "sh_mobile_sdhi",
491 .num_resources = ARRAY_SIZE(sdhi1_resources),
492 .resource = sdhi1_resources,
493 .id = 1,
Magnus Damm98779ad2009-11-27 04:36:58 +0000494 .dev = {
495 .platform_data = &sdhi1_info,
496 },
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000497 .archdata = {
498 .hwblk_id = HWBLK_SDHI1,
499 },
500};
501
Magnus Damm1ce4da72009-12-07 14:05:45 +0000502#else
503
504static int mmc_spi_get_ro(struct device *dev)
505{
506 return gpio_get_value(GPIO_PTY6);
507}
508
509static int mmc_spi_get_cd(struct device *dev)
510{
511 return !gpio_get_value(GPIO_PTY7);
512}
513
514static void mmc_spi_setpower(struct device *dev, unsigned int maskval)
515{
516 gpio_set_value(GPIO_PTB6, maskval ? 1 : 0);
517}
518
519static struct mmc_spi_platform_data mmc_spi_info = {
520 .get_ro = mmc_spi_get_ro,
521 .get_cd = mmc_spi_get_cd,
522 .caps = MMC_CAP_NEEDS_POLL,
523 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* 3.3V only */
524 .setpower = mmc_spi_setpower,
525};
526
527static struct spi_board_info spi_bus[] = {
528 {
529 .modalias = "mmc_spi",
530 .platform_data = &mmc_spi_info,
531 .max_speed_hz = 5000000,
532 .mode = SPI_MODE_0,
533 .controller_data = (void *) GPIO_PTM4,
534 },
535};
536
537static struct sh_msiof_spi_info msiof0_data = {
538 .num_chipselect = 1,
539};
540
541static struct resource msiof0_resources[] = {
542 [0] = {
543 .name = "MSIOF0",
544 .start = 0xa4c40000,
545 .end = 0xa4c40063,
546 .flags = IORESOURCE_MEM,
547 },
548 [1] = {
549 .start = 84,
550 .flags = IORESOURCE_IRQ,
551 },
552};
553
554static struct platform_device msiof0_device = {
555 .name = "spi_sh_msiof",
556 .id = 0, /* MSIOF0 */
557 .dev = {
558 .platform_data = &msiof0_data,
559 },
560 .num_resources = ARRAY_SIZE(msiof0_resources),
561 .resource = msiof0_resources,
562 .archdata = {
563 .hwblk_id = HWBLK_MSIOF0,
564 },
565};
566
567#endif
568
Kuninori Morimoto207efd02009-12-15 05:37:16 +0000569/* I2C Video */
570static struct i2c_board_info i2c_camera[] = {
571 {
572 I2C_BOARD_INFO("tw9910", 0x45),
573 },
574};
575
576/* tw9910 */
577static int tw9910_power(struct device *dev, int mode)
578{
579 int val = mode ? 0 : 1;
580
581 gpio_set_value(GPIO_PTU2, val);
582 if (mode)
583 mdelay(100);
584
585 return 0;
586}
587
588static struct tw9910_video_info tw9910_info = {
589 .buswidth = SOCAM_DATAWIDTH_8,
590 .mpout = TW9910_MPO_FIELD,
591};
592
593static struct soc_camera_link tw9910_link = {
594 .i2c_adapter_id = 0,
595 .bus_id = 1,
596 .power = tw9910_power,
597 .board_info = &i2c_camera[0],
598 .module_name = "tw9910",
599 .priv = &tw9910_info,
600};
601
602
603static struct platform_device camera_devices[] = {
604 {
605 .name = "soc-camera-pdrv",
606 .id = 0,
607 .dev = {
608 .platform_data = &tw9910_link,
609 },
610 },
611};
612
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000613static struct platform_device *ecovec_devices[] __initdata = {
614 &heartbeat_device,
615 &nor_flash_device,
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000616 &sh_eth_device,
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000617 &usb0_host_device,
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000618 &usb1_common_device,
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000619 &lcdc_device,
Kuninori Morimoto2153ad32009-08-26 11:04:36 +0000620 &ceu0_device,
621 &ceu1_device,
Kuninori Morimotoe9103e72009-09-14 11:23:00 +0000622 &keysc_device,
Magnus Damm1ce4da72009-12-07 14:05:45 +0000623#ifdef CONFIG_MFD_SH_MOBILE_SDHI
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000624 &sdhi0_device,
625 &sdhi1_device,
Magnus Damm1ce4da72009-12-07 14:05:45 +0000626#else
627 &msiof0_device,
628#endif
Kuninori Morimoto207efd02009-12-15 05:37:16 +0000629 &camera_devices[0],
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000630};
631
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000632#define EEPROM_ADDR 0x50
633static u8 mac_read(struct i2c_adapter *a, u8 command)
634{
635 struct i2c_msg msg[2];
636 u8 buf;
637 int ret;
638
639 msg[0].addr = EEPROM_ADDR;
640 msg[0].flags = 0;
641 msg[0].len = 1;
642 msg[0].buf = &command;
643
644 msg[1].addr = EEPROM_ADDR;
645 msg[1].flags = I2C_M_RD;
646 msg[1].len = 1;
647 msg[1].buf = &buf;
648
649 ret = i2c_transfer(a, msg, 2);
650 if (ret < 0) {
651 printk(KERN_ERR "error %d\n", ret);
652 buf = 0xff;
653 }
654
655 return buf;
656}
657
Magnus Damm376abbb2009-10-26 10:44:37 +0000658static void __init sh_eth_init(struct sh_eth_plat_data *pd)
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000659{
660 struct i2c_adapter *a = i2c_get_adapter(1);
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000661 int i;
662
663 if (!a) {
664 pr_err("can not get I2C 1\n");
665 return;
666 }
667
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000668 /* read MAC address frome EEPROM */
Magnus Damm376abbb2009-10-26 10:44:37 +0000669 for (i = 0; i < sizeof(pd->mac_addr); i++) {
670 pd->mac_addr[i] = mac_read(a, 0x10 + i);
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000671 msleep(10);
672 }
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000673}
674
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000675#define PORT_HIZA 0xA4050158
Kuninori Morimotoea15edb2009-08-26 11:04:39 +0000676#define IODRIVEA 0xA405018A
Magnus Dammeb0cd9e2009-10-30 04:23:59 +0000677
678extern char ecovec24_sdram_enter_start;
679extern char ecovec24_sdram_enter_end;
680extern char ecovec24_sdram_leave_start;
681extern char ecovec24_sdram_leave_end;
682
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000683static int __init arch_setup(void)
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000684{
Magnus Dammeb0cd9e2009-10-30 04:23:59 +0000685 /* register board specific self-refresh code */
686 sh_mobile_register_self_refresh(SUSP_SH_STANDBY | SUSP_SH_SF,
687 &ecovec24_sdram_enter_start,
688 &ecovec24_sdram_enter_end,
689 &ecovec24_sdram_leave_start,
690 &ecovec24_sdram_leave_end);
691
Magnus Dammf78bab32009-10-07 09:00:06 +0000692 /* enable STATUS0, STATUS2 and PDSTATUS */
693 gpio_request(GPIO_FN_STATUS0, NULL);
694 gpio_request(GPIO_FN_STATUS2, NULL);
695 gpio_request(GPIO_FN_PDSTATUS, NULL);
696
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000697 /* enable SCIFA0 */
698 gpio_request(GPIO_FN_SCIF0_TXD, NULL);
699 gpio_request(GPIO_FN_SCIF0_RXD, NULL);
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000700
701 /* enable debug LED */
702 gpio_request(GPIO_PTG0, NULL);
703 gpio_request(GPIO_PTG1, NULL);
704 gpio_request(GPIO_PTG2, NULL);
705 gpio_request(GPIO_PTG3, NULL);
Kuninori Morimotob7056bc2009-08-26 11:04:22 +0000706 gpio_direction_output(GPIO_PTG0, 0);
707 gpio_direction_output(GPIO_PTG1, 0);
708 gpio_direction_output(GPIO_PTG2, 0);
709 gpio_direction_output(GPIO_PTG3, 0);
Kuninori Morimoto643e9d12009-09-10 01:40:00 +0000710 ctrl_outw((ctrl_inw(PORT_HIZA) & ~(0x1 << 1)) , PORT_HIZA);
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000711
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000712 /* enable SH-Eth */
713 gpio_request(GPIO_PTA1, NULL);
714 gpio_direction_output(GPIO_PTA1, 1);
715 mdelay(20);
716
717 gpio_request(GPIO_FN_RMII_RXD0, NULL);
718 gpio_request(GPIO_FN_RMII_RXD1, NULL);
719 gpio_request(GPIO_FN_RMII_TXD0, NULL);
720 gpio_request(GPIO_FN_RMII_TXD1, NULL);
721 gpio_request(GPIO_FN_RMII_REF_CLK, NULL);
722 gpio_request(GPIO_FN_RMII_TX_EN, NULL);
723 gpio_request(GPIO_FN_RMII_RX_ER, NULL);
724 gpio_request(GPIO_FN_RMII_CRS_DV, NULL);
725 gpio_request(GPIO_FN_MDIO, NULL);
726 gpio_request(GPIO_FN_MDC, NULL);
727 gpio_request(GPIO_FN_LNKSTA, NULL);
728
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000729 /* enable USB */
Kuninori Morimotobe4ebf92009-09-10 01:39:55 +0000730 ctrl_outw(0x0000, 0xA4D80000);
Kuninori Morimoto147df2d2009-09-14 11:22:31 +0000731 ctrl_outw(0x0000, 0xA4D90000);
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000732 gpio_request(GPIO_PTB3, NULL);
733 gpio_request(GPIO_PTB4, NULL);
734 gpio_request(GPIO_PTB5, NULL);
735 gpio_direction_input(GPIO_PTB3);
736 gpio_direction_output(GPIO_PTB4, 0);
737 gpio_direction_output(GPIO_PTB5, 0);
738 ctrl_outw(0x0600, 0xa40501d4);
739 ctrl_outw(0x0600, 0xa4050192);
740
Kuninori Morimoto3714a9a2009-10-28 06:31:57 +0000741 if (gpio_get_value(GPIO_PTB3)) {
742 printk(KERN_INFO "USB1 function is selected\n");
743 usb1_common_device.name = "r8a66597_udc";
744 } else {
745 printk(KERN_INFO "USB1 host is selected\n");
746 usb1_common_device.name = "r8a66597_hcd";
747 }
748
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000749 /* enable LCDC */
750 gpio_request(GPIO_FN_LCDD23, NULL);
751 gpio_request(GPIO_FN_LCDD22, NULL);
752 gpio_request(GPIO_FN_LCDD21, NULL);
753 gpio_request(GPIO_FN_LCDD20, NULL);
754 gpio_request(GPIO_FN_LCDD19, NULL);
755 gpio_request(GPIO_FN_LCDD18, NULL);
756 gpio_request(GPIO_FN_LCDD17, NULL);
757 gpio_request(GPIO_FN_LCDD16, NULL);
758 gpio_request(GPIO_FN_LCDD15, NULL);
759 gpio_request(GPIO_FN_LCDD14, NULL);
760 gpio_request(GPIO_FN_LCDD13, NULL);
761 gpio_request(GPIO_FN_LCDD12, NULL);
762 gpio_request(GPIO_FN_LCDD11, NULL);
763 gpio_request(GPIO_FN_LCDD10, NULL);
764 gpio_request(GPIO_FN_LCDD9, NULL);
765 gpio_request(GPIO_FN_LCDD8, NULL);
766 gpio_request(GPIO_FN_LCDD7, NULL);
767 gpio_request(GPIO_FN_LCDD6, NULL);
768 gpio_request(GPIO_FN_LCDD5, NULL);
769 gpio_request(GPIO_FN_LCDD4, NULL);
770 gpio_request(GPIO_FN_LCDD3, NULL);
771 gpio_request(GPIO_FN_LCDD2, NULL);
772 gpio_request(GPIO_FN_LCDD1, NULL);
773 gpio_request(GPIO_FN_LCDD0, NULL);
774 gpio_request(GPIO_FN_LCDDISP, NULL);
775 gpio_request(GPIO_FN_LCDHSYN, NULL);
776 gpio_request(GPIO_FN_LCDDCK, NULL);
777 gpio_request(GPIO_FN_LCDVSYN, NULL);
778 gpio_request(GPIO_FN_LCDDON, NULL);
779 gpio_request(GPIO_FN_LCDLCLK, NULL);
780 ctrl_outw((ctrl_inw(PORT_HIZA) & ~0x0001), PORT_HIZA);
781
782 gpio_request(GPIO_PTE6, NULL);
783 gpio_request(GPIO_PTU1, NULL);
784 gpio_request(GPIO_PTR1, NULL);
785 gpio_request(GPIO_PTA2, NULL);
786 gpio_direction_input(GPIO_PTE6);
787 gpio_direction_output(GPIO_PTU1, 0);
788 gpio_direction_output(GPIO_PTR1, 0);
789 gpio_direction_output(GPIO_PTA2, 0);
790
Kuninori Morimoto82b33222009-12-02 09:35:42 +0000791 /* I/O buffer drive ability is high */
792 ctrl_outw((ctrl_inw(IODRIVEA) & ~0x00c0) | 0x0080 , IODRIVEA);
Kuninori Morimotoea15edb2009-08-26 11:04:39 +0000793
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000794 if (gpio_get_value(GPIO_PTE6)) {
795 /* DVI */
796 lcdc_info.clock_source = LCDC_CLK_EXTERNAL;
Kuninori Morimotoea15edb2009-08-26 11:04:39 +0000797 lcdc_info.ch[0].clock_divider = 1,
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000798 lcdc_info.ch[0].lcd_cfg.name = "DVI";
799 lcdc_info.ch[0].lcd_cfg.xres = 1280;
800 lcdc_info.ch[0].lcd_cfg.yres = 720;
801 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
802 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
803 lcdc_info.ch[0].lcd_cfg.hsync_len = 40;
804 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
805 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
806 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
807
808 gpio_set_value(GPIO_PTA2, 1);
809 gpio_set_value(GPIO_PTU1, 1);
810 } else {
811 /* Panel */
Kuninori Morimotoea15edb2009-08-26 11:04:39 +0000812
813 lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
814 lcdc_info.ch[0].clock_divider = 2,
815 lcdc_info.ch[0].lcd_cfg.name = "Panel";
816 lcdc_info.ch[0].lcd_cfg.xres = 800;
817 lcdc_info.ch[0].lcd_cfg.yres = 480;
818 lcdc_info.ch[0].lcd_cfg.left_margin = 220;
819 lcdc_info.ch[0].lcd_cfg.right_margin = 110;
820 lcdc_info.ch[0].lcd_cfg.hsync_len = 70;
821 lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
822 lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
823 lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
824
825 gpio_set_value(GPIO_PTR1, 1);
826
827 /* FIXME
828 *
829 * LCDDON control is needed for Panel,
830 * but current sh_mobile_lcdc driver doesn't control it.
831 * It is temporary correspondence
832 */
833 gpio_request(GPIO_PTF4, NULL);
834 gpio_direction_output(GPIO_PTF4, 1);
Kuninori Morimoto8810e052009-09-28 08:21:41 +0000835
836 /* enable TouchScreen */
837 i2c_register_board_info(0, &ts_i2c_clients, 1);
838 set_irq_type(IRQ0, IRQ_TYPE_LEVEL_LOW);
Kuninori Morimotofa3ba512009-08-26 11:04:34 +0000839 }
840
Kuninori Morimoto2153ad32009-08-26 11:04:36 +0000841 /* enable CEU0 */
842 gpio_request(GPIO_FN_VIO0_D15, NULL);
843 gpio_request(GPIO_FN_VIO0_D14, NULL);
844 gpio_request(GPIO_FN_VIO0_D13, NULL);
845 gpio_request(GPIO_FN_VIO0_D12, NULL);
846 gpio_request(GPIO_FN_VIO0_D11, NULL);
847 gpio_request(GPIO_FN_VIO0_D10, NULL);
848 gpio_request(GPIO_FN_VIO0_D9, NULL);
849 gpio_request(GPIO_FN_VIO0_D8, NULL);
850 gpio_request(GPIO_FN_VIO0_D7, NULL);
851 gpio_request(GPIO_FN_VIO0_D6, NULL);
852 gpio_request(GPIO_FN_VIO0_D5, NULL);
853 gpio_request(GPIO_FN_VIO0_D4, NULL);
854 gpio_request(GPIO_FN_VIO0_D3, NULL);
855 gpio_request(GPIO_FN_VIO0_D2, NULL);
856 gpio_request(GPIO_FN_VIO0_D1, NULL);
857 gpio_request(GPIO_FN_VIO0_D0, NULL);
858 gpio_request(GPIO_FN_VIO0_VD, NULL);
859 gpio_request(GPIO_FN_VIO0_CLK, NULL);
860 gpio_request(GPIO_FN_VIO0_FLD, NULL);
861 gpio_request(GPIO_FN_VIO0_HD, NULL);
862 platform_resource_setup_memory(&ceu0_device, "ceu0", 4 << 20);
863
864 /* enable CEU1 */
865 gpio_request(GPIO_FN_VIO1_D7, NULL);
866 gpio_request(GPIO_FN_VIO1_D6, NULL);
867 gpio_request(GPIO_FN_VIO1_D5, NULL);
868 gpio_request(GPIO_FN_VIO1_D4, NULL);
869 gpio_request(GPIO_FN_VIO1_D3, NULL);
870 gpio_request(GPIO_FN_VIO1_D2, NULL);
871 gpio_request(GPIO_FN_VIO1_D1, NULL);
872 gpio_request(GPIO_FN_VIO1_D0, NULL);
873 gpio_request(GPIO_FN_VIO1_FLD, NULL);
874 gpio_request(GPIO_FN_VIO1_HD, NULL);
875 gpio_request(GPIO_FN_VIO1_VD, NULL);
876 gpio_request(GPIO_FN_VIO1_CLK, NULL);
877 platform_resource_setup_memory(&ceu1_device, "ceu1", 4 << 20);
878
Kuninori Morimotoe9103e72009-09-14 11:23:00 +0000879 /* enable KEYSC */
880 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
881 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
882 gpio_request(GPIO_FN_KEYOUT3, NULL);
883 gpio_request(GPIO_FN_KEYOUT2, NULL);
884 gpio_request(GPIO_FN_KEYOUT1, NULL);
885 gpio_request(GPIO_FN_KEYOUT0, NULL);
886 gpio_request(GPIO_FN_KEYIN0, NULL);
887
Kuninori Morimoto064a16d2009-09-16 11:34:34 +0000888 /* enable user debug switch */
889 gpio_request(GPIO_PTR0, NULL);
890 gpio_request(GPIO_PTR4, NULL);
891 gpio_request(GPIO_PTR5, NULL);
892 gpio_request(GPIO_PTR6, NULL);
893 gpio_direction_input(GPIO_PTR0);
894 gpio_direction_input(GPIO_PTR4);
895 gpio_direction_input(GPIO_PTR5);
896 gpio_direction_input(GPIO_PTR6);
897
Magnus Damm1ce4da72009-12-07 14:05:45 +0000898#ifdef CONFIG_MFD_SH_MOBILE_SDHI
899 /* enable SDHI0 on CN11 (needs DS2.4 set to ON) */
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000900 gpio_request(GPIO_FN_SDHI0CD, NULL);
901 gpio_request(GPIO_FN_SDHI0WP, NULL);
902 gpio_request(GPIO_FN_SDHI0CMD, NULL);
903 gpio_request(GPIO_FN_SDHI0CLK, NULL);
904 gpio_request(GPIO_FN_SDHI0D3, NULL);
905 gpio_request(GPIO_FN_SDHI0D2, NULL);
906 gpio_request(GPIO_FN_SDHI0D1, NULL);
907 gpio_request(GPIO_FN_SDHI0D0, NULL);
Magnus Damm98779ad2009-11-27 04:36:58 +0000908 gpio_request(GPIO_PTB6, NULL);
909 gpio_direction_output(GPIO_PTB6, 0);
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000910
Magnus Damm1ce4da72009-12-07 14:05:45 +0000911 /* enable SDHI1 on CN12 (needs DS2.6,7 set to ON,OFF) */
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000912 gpio_request(GPIO_FN_SDHI1CD, NULL);
913 gpio_request(GPIO_FN_SDHI1WP, NULL);
914 gpio_request(GPIO_FN_SDHI1CMD, NULL);
915 gpio_request(GPIO_FN_SDHI1CLK, NULL);
916 gpio_request(GPIO_FN_SDHI1D3, NULL);
917 gpio_request(GPIO_FN_SDHI1D2, NULL);
918 gpio_request(GPIO_FN_SDHI1D1, NULL);
919 gpio_request(GPIO_FN_SDHI1D0, NULL);
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000920 gpio_request(GPIO_PTB7, NULL);
Magnus Damm98779ad2009-11-27 04:36:58 +0000921 gpio_direction_output(GPIO_PTB7, 0);
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000922
923 /* I/O buffer drive ability is high for SDHI1 */
924 ctrl_outw((ctrl_inw(IODRIVEA) & ~0x3000) | 0x2000 , IODRIVEA);
Magnus Damm1ce4da72009-12-07 14:05:45 +0000925#else
926 /* enable MSIOF0 on CN11 (needs DS2.4 set to OFF) */
927 gpio_request(GPIO_FN_MSIOF0_TXD, NULL);
928 gpio_request(GPIO_FN_MSIOF0_RXD, NULL);
929 gpio_request(GPIO_FN_MSIOF0_TSCK, NULL);
930 gpio_request(GPIO_PTM4, NULL); /* software CS control of TSYNC pin */
931 gpio_direction_output(GPIO_PTM4, 1); /* active low CS */
932 gpio_request(GPIO_PTB6, NULL); /* 3.3V power control */
933 gpio_direction_output(GPIO_PTB6, 0); /* disable power by default */
934 gpio_request(GPIO_PTY6, NULL); /* write protect */
935 gpio_direction_input(GPIO_PTY6);
936 gpio_request(GPIO_PTY7, NULL); /* card detect */
937 gpio_direction_input(GPIO_PTY7);
938
939 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus));
940#endif
Kuninori Morimoto96987d92009-10-02 07:54:42 +0000941
Kuninori Morimoto207efd02009-12-15 05:37:16 +0000942 /* enable Video */
943 gpio_request(GPIO_PTU2, NULL);
944 gpio_direction_output(GPIO_PTU2, 1);
945
Kuninori Morimoto125ecce2009-09-10 01:39:37 +0000946 /* enable I2C device */
947 i2c_register_board_info(1, i2c1_devices,
948 ARRAY_SIZE(i2c1_devices));
949
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000950 return platform_add_devices(ecovec_devices,
951 ARRAY_SIZE(ecovec_devices));
952}
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000953arch_initcall(arch_setup);
954
955static int __init devices_setup(void)
956{
Magnus Damm376abbb2009-10-26 10:44:37 +0000957 sh_eth_init(&sh_eth_plat);
Kuninori Morimoto4907d572009-09-10 01:39:58 +0000958 return 0;
959}
960device_initcall(devices_setup);
961
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000962static struct sh_machine_vector mv_ecovec __initmv = {
963 .mv_name = "R0P7724 (EcoVec)",
964};