Merge branch 'renesas-soc' into renesas-board
[linux-2.6-microblaze.git] / arch / arm / mach-shmobile / board-armadillo800eva.c
1 /*
2  * armadillo 800 eva board support
3  *
4  * Copyright (C) 2012 Renesas Solutions Corp.
5  * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #include <linux/clk.h>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/kernel.h>
26 #include <linux/input.h>
27 #include <linux/irq.h>
28 #include <linux/platform_device.h>
29 #include <linux/gpio.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/sh_eth.h>
32 #include <linux/videodev2.h>
33 #include <linux/usb/renesas_usbhs.h>
34 #include <linux/mfd/tmio.h>
35 #include <linux/mmc/host.h>
36 #include <linux/mmc/sh_mmcif.h>
37 #include <linux/mmc/sh_mobile_sdhi.h>
38 #include <mach/common.h>
39 #include <mach/irqs.h>
40 #include <mach/r8a7740.h>
41 #include <media/mt9t112.h>
42 #include <media/sh_mobile_ceu.h>
43 #include <media/soc_camera.h>
44 #include <asm/page.h>
45 #include <asm/mach-types.h>
46 #include <asm/mach/arch.h>
47 #include <asm/mach/map.h>
48 #include <asm/mach/time.h>
49 #include <asm/hardware/cache-l2x0.h>
50 #include <video/sh_mobile_lcdc.h>
51 #include <video/sh_mobile_hdmi.h>
52
53 /*
54  * CON1         Camera Module
55  * CON2         Extension Bus
56  * CON3         HDMI Output
57  * CON4         Composite Video Output
58  * CON5         H-UDI JTAG
59  * CON6         ARM JTAG
60  * CON7         SD1
61  * CON8         SD2
62  * CON9         RTC BackUp
63  * CON10        Monaural Mic Input
64  * CON11        Stereo Headphone Output
65  * CON12        Audio Line Output(L)
66  * CON13        Audio Line Output(R)
67  * CON14        AWL13 Module
68  * CON15        Extension
69  * CON16        LCD1
70  * CON17        LCD2
71  * CON19        Power Input
72  * CON20        USB1
73  * CON21        USB2
74  * CON22        Serial
75  * CON23        LAN
76  * CON24        USB3
77  * LED1         Camera LED(Yellow)
78  * LED2         Power LED (Green)
79  * ED3-LED6     User LED(Yellow)
80  * LED7         LAN link LED(Green)
81  * LED8         LAN activity LED(Yellow)
82  */
83
84 /*
85  * DipSwitch
86  *
87  *                    SW1
88  *
89  * -12345678-+---------------+----------------------------
90  *  1        | boot          | hermit
91  *  0        | boot          | OS auto boot
92  * -12345678-+---------------+----------------------------
93  *   00      | boot device   | eMMC
94  *   10      | boot device   | SDHI0 (CON7)
95  *   01      | boot device   | -
96  *   11      | boot device   | Extension Buss (CS0)
97  * -12345678-+---------------+----------------------------
98  *     0     | Extension Bus | D8-D15 disable, eMMC enable
99  *     1     | Extension Bus | D8-D15 enable,  eMMC disable
100  * -12345678-+---------------+----------------------------
101  *      0    | SDHI1         | COM8 disable, COM14 enable
102  *      1    | SDHI1         | COM8 enable,  COM14 disable
103  * -12345678-+---------------+----------------------------
104  *       0   | USB0          | COM20 enable,  COM24 disable
105  *       1   | USB0          | COM20 disable, COM24 enable
106  * -12345678-+---------------+----------------------------
107  *        00 | JTAG          | SH-X2
108  *        10 | JTAG          | ARM
109  *        01 | JTAG          | -
110  *        11 | JTAG          | Boundary Scan
111  *-----------+---------------+----------------------------
112  */
113
114 /*
115  * USB function
116  *
117  * When you use USB Function,
118  * set SW1.6 ON, and connect cable to CN24.
119  *
120  * USBF needs workaround on R8A7740 chip.
121  * These are a little bit complex.
122  * see
123  *      usbhsf_power_ctrl()
124  *
125  * CAUTION
126  *
127  * It uses autonomy mode for USB hotplug at this point
128  * (= usbhs_private.platform_callback.get_vbus is NULL),
129  * since we don't know what's happen on PM control
130  * on this workaround.
131  */
132 #define USBCR1          0xe605810a
133 #define USBH            0xC6700000
134 #define USBH_USBCTR     0x10834
135
136 struct usbhsf_private {
137         struct clk *phy;
138         struct clk *usb24;
139         struct clk *pci;
140         struct clk *func;
141         struct clk *host;
142         void __iomem *usbh_base;
143         struct renesas_usbhs_platform_info info;
144 };
145
146 #define usbhsf_get_priv(pdev)                           \
147         container_of(renesas_usbhs_get_info(pdev),      \
148                      struct usbhsf_private, info)
149
150 static int usbhsf_get_id(struct platform_device *pdev)
151 {
152         return USBHS_GADGET;
153 }
154
155 static void usbhsf_power_ctrl(struct platform_device *pdev,
156                               void __iomem *base, int enable)
157 {
158         struct usbhsf_private *priv = usbhsf_get_priv(pdev);
159
160         /*
161          * Work around for USB Function.
162          * It needs USB host clock, and settings
163          */
164         if (enable) {
165                 /*
166                  * enable all the related usb clocks
167                  * for usb workaround
168                  */
169                 clk_enable(priv->usb24);
170                 clk_enable(priv->pci);
171                 clk_enable(priv->host);
172                 clk_enable(priv->func);
173                 clk_enable(priv->phy);
174
175                 /*
176                  * set USBCR1
177                  *
178                  * Port1 is driven by USB function,
179                  * Port2 is driven by USB HOST
180                  * One HOST (Port1 or Port2 is HOST)
181                  * USB PLL input clock = 24MHz
182                  */
183                 __raw_writew(0xd750, USBCR1);
184                 mdelay(1);
185
186                 /*
187                  * start USB Host
188                  */
189                 __raw_writel(0x0000000c, priv->usbh_base + USBH_USBCTR);
190                 __raw_writel(0x00000008, priv->usbh_base + USBH_USBCTR);
191                 mdelay(10);
192
193                 /*
194                  * USB PHY Power ON
195                  */
196                 __raw_writew(0xd770, USBCR1);
197                 __raw_writew(0x4000, base + 0x102); /* USBF :: SUSPMODE */
198
199         } else {
200                 __raw_writel(0x0000010f, priv->usbh_base + USBH_USBCTR);
201                 __raw_writew(0xd7c0, USBCR1); /* GPIO */
202
203                 clk_disable(priv->phy);
204                 clk_disable(priv->func);        /* usb work around */
205                 clk_disable(priv->host);        /* usb work around */
206                 clk_disable(priv->pci);         /* usb work around */
207                 clk_disable(priv->usb24);       /* usb work around */
208         }
209 }
210
211 static void usbhsf_hardware_exit(struct platform_device *pdev)
212 {
213         struct usbhsf_private *priv = usbhsf_get_priv(pdev);
214
215         if (!IS_ERR(priv->phy))
216                 clk_put(priv->phy);
217         if (!IS_ERR(priv->usb24))
218                 clk_put(priv->usb24);
219         if (!IS_ERR(priv->pci))
220                 clk_put(priv->pci);
221         if (!IS_ERR(priv->host))
222                 clk_put(priv->host);
223         if (!IS_ERR(priv->func))
224                 clk_put(priv->func);
225         if (priv->usbh_base)
226                 iounmap(priv->usbh_base);
227
228         priv->phy       = NULL;
229         priv->usb24     = NULL;
230         priv->pci       = NULL;
231         priv->host      = NULL;
232         priv->func      = NULL;
233         priv->usbh_base = NULL;
234 }
235
236 static int usbhsf_hardware_init(struct platform_device *pdev)
237 {
238         struct usbhsf_private *priv = usbhsf_get_priv(pdev);
239
240         priv->phy       = clk_get(&pdev->dev, "phy");
241         priv->usb24     = clk_get(&pdev->dev, "usb24");
242         priv->pci       = clk_get(&pdev->dev, "pci");
243         priv->func      = clk_get(&pdev->dev, "func");
244         priv->host      = clk_get(&pdev->dev, "host");
245         priv->usbh_base = ioremap_nocache(USBH, 0x20000);
246
247         if (IS_ERR(priv->phy)           ||
248             IS_ERR(priv->usb24)         ||
249             IS_ERR(priv->pci)           ||
250             IS_ERR(priv->host)          ||
251             IS_ERR(priv->func)          ||
252             !priv->usbh_base) {
253                 dev_err(&pdev->dev, "USB clock setting failed\n");
254                 usbhsf_hardware_exit(pdev);
255                 return -EIO;
256         }
257
258         /* usb24 use 1/1 of parent clock (= usb24s = 24MHz) */
259         clk_set_rate(priv->usb24,
260                      clk_get_rate(clk_get_parent(priv->usb24)));
261
262         return 0;
263 }
264
265 static struct usbhsf_private usbhsf_private = {
266         .info = {
267                 .platform_callback = {
268                         .get_id         = usbhsf_get_id,
269                         .hardware_init  = usbhsf_hardware_init,
270                         .hardware_exit  = usbhsf_hardware_exit,
271                         .power_ctrl     = usbhsf_power_ctrl,
272                 },
273                 .driver_param = {
274                         .buswait_bwait          = 5,
275                         .detection_delay        = 5,
276                 },
277         }
278 };
279
280 static struct resource usbhsf_resources[] = {
281         {
282                 .name   = "USBHS",
283                 .start  = 0xe6890000,
284                 .end    = 0xe6890104 - 1,
285                 .flags  = IORESOURCE_MEM,
286         },
287         {
288                 .start  = evt2irq(0x0A20),
289                 .flags  = IORESOURCE_IRQ,
290         },
291 };
292
293 static struct platform_device usbhsf_device = {
294         .name   = "renesas_usbhs",
295         .dev = {
296                 .platform_data = &usbhsf_private.info,
297         },
298         .id = -1,
299         .num_resources  = ARRAY_SIZE(usbhsf_resources),
300         .resource       = usbhsf_resources,
301 };
302
303 /* Ether */
304 static struct sh_eth_plat_data sh_eth_platdata = {
305         .phy                    = 0x00, /* LAN8710A */
306         .edmac_endian           = EDMAC_LITTLE_ENDIAN,
307         .register_type          = SH_ETH_REG_GIGABIT,
308         .phy_interface          = PHY_INTERFACE_MODE_MII,
309 };
310
311 static struct resource sh_eth_resources[] = {
312         {
313                 .start  = 0xe9a00000,
314                 .end    = 0xe9a00800 - 1,
315                 .flags  = IORESOURCE_MEM,
316         }, {
317                 .start  = 0xe9a01800,
318                 .end    = 0xe9a02000 - 1,
319                 .flags  = IORESOURCE_MEM,
320         }, {
321                 .start  = evt2irq(0x0500),
322                 .flags  = IORESOURCE_IRQ,
323         },
324 };
325
326 static struct platform_device sh_eth_device = {
327         .name = "sh-eth",
328         .id = -1,
329         .dev = {
330                 .platform_data = &sh_eth_platdata,
331         },
332         .resource = sh_eth_resources,
333         .num_resources = ARRAY_SIZE(sh_eth_resources),
334 };
335
336 /* LCDC */
337 static struct fb_videomode lcdc0_mode = {
338         .name           = "AMPIER/AM-800480",
339         .xres           = 800,
340         .yres           = 480,
341         .left_margin    = 88,
342         .right_margin   = 40,
343         .hsync_len      = 128,
344         .upper_margin   = 20,
345         .lower_margin   = 5,
346         .vsync_len      = 5,
347         .sync           = 0,
348 };
349
350 static struct sh_mobile_lcdc_info lcdc0_info = {
351         .clock_source   = LCDC_CLK_BUS,
352         .ch[0] = {
353                 .chan           = LCDC_CHAN_MAINLCD,
354                 .fourcc         = V4L2_PIX_FMT_RGB565,
355                 .interface_type = RGB24,
356                 .clock_divider  = 5,
357                 .flags          = 0,
358                 .lcd_modes      = &lcdc0_mode,
359                 .num_modes      = 1,
360                 .panel_cfg = {
361                         .width  = 111,
362                         .height = 68,
363                 },
364         },
365 };
366
367 static struct resource lcdc0_resources[] = {
368         [0] = {
369                 .name   = "LCD0",
370                 .start  = 0xfe940000,
371                 .end    = 0xfe943fff,
372                 .flags  = IORESOURCE_MEM,
373         },
374         [1] = {
375                 .start  = intcs_evt2irq(0x580),
376                 .flags  = IORESOURCE_IRQ,
377         },
378 };
379
380 static struct platform_device lcdc0_device = {
381         .name           = "sh_mobile_lcdc_fb",
382         .num_resources  = ARRAY_SIZE(lcdc0_resources),
383         .resource       = lcdc0_resources,
384         .id             = 0,
385         .dev    = {
386                 .platform_data  = &lcdc0_info,
387                 .coherent_dma_mask = ~0,
388         },
389 };
390
391 /*
392  * LCDC1/HDMI
393  */
394 static struct sh_mobile_hdmi_info hdmi_info = {
395         .flags          = HDMI_OUTPUT_PUSH_PULL |
396                           HDMI_OUTPUT_POLARITY_HI |
397                           HDMI_32BIT_REG |
398                           HDMI_HAS_HTOP1 |
399                           HDMI_SND_SRC_SPDIF,
400 };
401
402 static struct resource hdmi_resources[] = {
403         [0] = {
404                 .name   = "HDMI",
405                 .start  = 0xe6be0000,
406                 .end    = 0xe6be03ff,
407                 .flags  = IORESOURCE_MEM,
408         },
409         [1] = {
410                 .start  = evt2irq(0x1700),
411                 .flags  = IORESOURCE_IRQ,
412         },
413         [2] = {
414                 .name   = "HDMI emma3pf",
415                 .start  = 0xe6be4000,
416                 .end    = 0xe6be43ff,
417                 .flags  = IORESOURCE_MEM,
418         },
419 };
420
421 static struct platform_device hdmi_device = {
422         .name           = "sh-mobile-hdmi",
423         .num_resources  = ARRAY_SIZE(hdmi_resources),
424         .resource       = hdmi_resources,
425         .id             = -1,
426         .dev    = {
427                 .platform_data  = &hdmi_info,
428         },
429 };
430
431 static const struct fb_videomode lcdc1_mode = {
432         .name           = "HDMI 720p",
433         .xres           = 1280,
434         .yres           = 720,
435         .pixclock       = 13468,
436         .left_margin    = 220,
437         .right_margin   = 110,
438         .hsync_len      = 40,
439         .upper_margin   = 20,
440         .lower_margin   = 5,
441         .vsync_len      = 5,
442         .refresh        = 60,
443         .sync           = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
444 };
445
446 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
447         .clock_source   = LCDC_CLK_PERIPHERAL, /* HDMI clock */
448         .ch[0] = {
449                 .chan                   = LCDC_CHAN_MAINLCD,
450                 .fourcc                 = V4L2_PIX_FMT_RGB565,
451                 .interface_type         = RGB24,
452                 .clock_divider          = 1,
453                 .flags                  = LCDC_FLAGS_DWPOL,
454                 .lcd_modes              = &lcdc1_mode,
455                 .num_modes              = 1,
456                 .tx_dev                 = &hdmi_device,
457                 .panel_cfg = {
458                         .width  = 1280,
459                         .height = 720,
460                 },
461         },
462 };
463
464 static struct resource hdmi_lcdc_resources[] = {
465         [0] = {
466                 .name   = "LCDC1",
467                 .start  = 0xfe944000,
468                 .end    = 0xfe948000 - 1,
469                 .flags  = IORESOURCE_MEM,
470         },
471         [1] = {
472                 .start  = intcs_evt2irq(0x1780),
473                 .flags  = IORESOURCE_IRQ,
474         },
475 };
476
477 static struct platform_device hdmi_lcdc_device = {
478         .name           = "sh_mobile_lcdc_fb",
479         .num_resources  = ARRAY_SIZE(hdmi_lcdc_resources),
480         .resource       = hdmi_lcdc_resources,
481         .id             = 1,
482         .dev    = {
483                 .platform_data  = &hdmi_lcdc_info,
484                 .coherent_dma_mask = ~0,
485         },
486 };
487
488 /* GPIO KEY */
489 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
490
491 static struct gpio_keys_button gpio_buttons[] = {
492         GPIO_KEY(KEY_POWER,     GPIO_PORT99,    "SW1"),
493         GPIO_KEY(KEY_BACK,      GPIO_PORT100,   "SW2"),
494         GPIO_KEY(KEY_MENU,      GPIO_PORT97,    "SW3"),
495         GPIO_KEY(KEY_HOME,      GPIO_PORT98,    "SW4"),
496 };
497
498 static struct gpio_keys_platform_data gpio_key_info = {
499         .buttons        = gpio_buttons,
500         .nbuttons       = ARRAY_SIZE(gpio_buttons),
501 };
502
503 static struct platform_device gpio_keys_device = {
504         .name   = "gpio-keys",
505         .id     = -1,
506         .dev    = {
507                 .platform_data  = &gpio_key_info,
508         },
509 };
510
511 /* SDHI0 */
512 /*
513  * FIXME
514  *
515  * It use polling mode here, since
516  * CD (= Card Detect) pin is not connected to SDHI0_CD.
517  * We can use IRQ31 as card detect irq,
518  * but it needs chattering removal operation
519  */
520 #define IRQ31   evt2irq(0x33E0)
521 static struct sh_mobile_sdhi_info sdhi0_info = {
522         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |\
523                           MMC_CAP_NEEDS_POLL,
524         .tmio_ocr_mask  = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
525         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT,
526 };
527
528 static struct resource sdhi0_resources[] = {
529         {
530                 .name   = "SDHI0",
531                 .start  = 0xe6850000,
532                 .end    = 0xe6850100 - 1,
533                 .flags  = IORESOURCE_MEM,
534         },
535         /*
536          * no SH_MOBILE_SDHI_IRQ_CARD_DETECT here
537          */
538         {
539                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
540                 .start  = evt2irq(0x0E20),
541                 .flags  = IORESOURCE_IRQ,
542         },
543         {
544                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
545                 .start  = evt2irq(0x0E40),
546                 .flags  = IORESOURCE_IRQ,
547         },
548 };
549
550 static struct platform_device sdhi0_device = {
551         .name           = "sh_mobile_sdhi",
552         .id             = 0,
553         .dev            = {
554                 .platform_data  = &sdhi0_info,
555         },
556         .num_resources  = ARRAY_SIZE(sdhi0_resources),
557         .resource       = sdhi0_resources,
558 };
559
560 /* SDHI1 */
561 static struct sh_mobile_sdhi_info sdhi1_info = {
562         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
563         .tmio_ocr_mask  = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
564         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT,
565 };
566
567 static struct resource sdhi1_resources[] = {
568         [0] = {
569                 .name   = "SDHI1",
570                 .start  = 0xe6860000,
571                 .end    = 0xe6860100 - 1,
572                 .flags  = IORESOURCE_MEM,
573         },
574         [1] = {
575                 .start  = evt2irq(0x0E80),
576                 .flags  = IORESOURCE_IRQ,
577         },
578         [2] = {
579                 .start  = evt2irq(0x0EA0),
580                 .flags  = IORESOURCE_IRQ,
581         },
582         [3] = {
583                 .start  = evt2irq(0x0EC0),
584                 .flags  = IORESOURCE_IRQ,
585         },
586 };
587
588 static struct platform_device sdhi1_device = {
589         .name           = "sh_mobile_sdhi",
590         .id             = 1,
591         .dev            = {
592                 .platform_data  = &sdhi1_info,
593         },
594         .num_resources  = ARRAY_SIZE(sdhi1_resources),
595         .resource       = sdhi1_resources,
596 };
597
598 /* MMCIF */
599 static struct sh_mmcif_plat_data sh_mmcif_plat = {
600         .sup_pclk       = 0,
601         .ocr            = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
602         .caps           = MMC_CAP_4_BIT_DATA |
603                           MMC_CAP_8_BIT_DATA |
604                           MMC_CAP_NONREMOVABLE,
605 };
606
607 static struct resource sh_mmcif_resources[] = {
608         [0] = {
609                 .name   = "MMCIF",
610                 .start  = 0xe6bd0000,
611                 .end    = 0xe6bd0100 - 1,
612                 .flags  = IORESOURCE_MEM,
613         },
614         [1] = {
615                 /* MMC ERR */
616                 .start  = evt2irq(0x1AC0),
617                 .flags  = IORESOURCE_IRQ,
618         },
619         [2] = {
620                 /* MMC NOR */
621                 .start  = evt2irq(0x1AE0),
622                 .flags  = IORESOURCE_IRQ,
623         },
624 };
625
626 static struct platform_device sh_mmcif_device = {
627         .name           = "sh_mmcif",
628         .id             = -1,
629         .dev            = {
630                 .platform_data  = &sh_mmcif_plat,
631         },
632         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
633         .resource       = sh_mmcif_resources,
634 };
635
636 /* Camera */
637 static int mt9t111_power(struct device *dev, int mode)
638 {
639         struct clk *mclk = clk_get(NULL, "video1");
640
641         if (IS_ERR(mclk)) {
642                 dev_err(dev, "can't get video1 clock\n");
643                 return -EINVAL;
644         }
645
646         if (mode) {
647                 /* video1 (= CON1 camera) expect 24MHz */
648                 clk_set_rate(mclk, clk_round_rate(mclk, 24000000));
649                 clk_enable(mclk);
650                 gpio_direction_output(GPIO_PORT158, 1);
651         } else {
652                 gpio_direction_output(GPIO_PORT158, 0);
653                 clk_disable(mclk);
654         }
655
656         clk_put(mclk);
657
658         return 0;
659 }
660
661 static struct i2c_board_info i2c_camera_mt9t111 = {
662         I2C_BOARD_INFO("mt9t112", 0x3d),
663 };
664
665 static struct mt9t112_camera_info mt9t111_info = {
666         .divider = { 16, 0, 0, 7, 0, 10, 14, 7, 7 },
667 };
668
669 static struct soc_camera_link mt9t111_link = {
670         .i2c_adapter_id = 0,
671         .bus_id         = 0,
672         .board_info     = &i2c_camera_mt9t111,
673         .power          = mt9t111_power,
674         .priv           = &mt9t111_info,
675 };
676
677 static struct platform_device camera_device = {
678         .name   = "soc-camera-pdrv",
679         .id     = 0,
680         .dev    = {
681                 .platform_data = &mt9t111_link,
682         },
683 };
684
685 /* CEU0 */
686 static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
687         .flags = SH_CEU_FLAG_LOWER_8BIT,
688 };
689
690 static struct resource ceu0_resources[] = {
691         [0] = {
692                 .name   = "CEU",
693                 .start  = 0xfe910000,
694                 .end    = 0xfe91009f,
695                 .flags  = IORESOURCE_MEM,
696         },
697         [1] = {
698                 .start  = intcs_evt2irq(0x0500),
699                 .flags  = IORESOURCE_IRQ,
700         },
701         [2] = {
702                 /* place holder for contiguous memory */
703         },
704 };
705
706 static struct platform_device ceu0_device = {
707         .name           = "sh_mobile_ceu",
708         .id             = 0,
709         .num_resources  = ARRAY_SIZE(ceu0_resources),
710         .resource       = ceu0_resources,
711         .dev    = {
712                 .platform_data          = &sh_mobile_ceu0_info,
713                 .coherent_dma_mask      = 0xffffffff,
714         },
715 };
716
717 /* I2C */
718 static struct i2c_board_info i2c0_devices[] = {
719         {
720                 I2C_BOARD_INFO("st1232-ts", 0x55),
721                 .irq = evt2irq(0x0340),
722         },
723 };
724
725 /*
726  * board devices
727  */
728 static struct platform_device *eva_devices[] __initdata = {
729         &lcdc0_device,
730         &gpio_keys_device,
731         &sh_eth_device,
732         &sdhi0_device,
733         &sh_mmcif_device,
734         &hdmi_device,
735         &hdmi_lcdc_device,
736         &camera_device,
737         &ceu0_device,
738 };
739
740 static void __init eva_clock_init(void)
741 {
742         struct clk *system      = clk_get(NULL, "system_clk");
743         struct clk *xtal1       = clk_get(NULL, "extal1");
744         struct clk *usb24s      = clk_get(NULL, "usb24s");
745
746         if (IS_ERR(system)      ||
747             IS_ERR(xtal1)       ||
748             IS_ERR(usb24s)) {
749                 pr_err("armadillo800eva board clock init failed\n");
750                 goto clock_error;
751         }
752
753         /* armadillo 800 eva extal1 is 24MHz */
754         clk_set_rate(xtal1, 24000000);
755
756         /* usb24s use extal1 (= system) clock (= 24MHz) */
757         clk_set_parent(usb24s, system);
758
759 clock_error:
760         if (!IS_ERR(system))
761                 clk_put(system);
762         if (!IS_ERR(xtal1))
763                 clk_put(xtal1);
764         if (!IS_ERR(usb24s))
765                 clk_put(usb24s);
766 }
767
768 /*
769  * board init
770  */
771 static void __init eva_init(void)
772 {
773         eva_clock_init();
774
775         r8a7740_pinmux_init();
776         r8a7740_meram_workaround();
777
778         /* SCIFA1 */
779         gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
780         gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
781
782         /* LCDC0 */
783         gpio_request(GPIO_FN_LCDC0_SELECT,      NULL);
784         gpio_request(GPIO_FN_LCD0_D0,           NULL);
785         gpio_request(GPIO_FN_LCD0_D1,           NULL);
786         gpio_request(GPIO_FN_LCD0_D2,           NULL);
787         gpio_request(GPIO_FN_LCD0_D3,           NULL);
788         gpio_request(GPIO_FN_LCD0_D4,           NULL);
789         gpio_request(GPIO_FN_LCD0_D5,           NULL);
790         gpio_request(GPIO_FN_LCD0_D6,           NULL);
791         gpio_request(GPIO_FN_LCD0_D7,           NULL);
792         gpio_request(GPIO_FN_LCD0_D8,           NULL);
793         gpio_request(GPIO_FN_LCD0_D9,           NULL);
794         gpio_request(GPIO_FN_LCD0_D10,          NULL);
795         gpio_request(GPIO_FN_LCD0_D11,          NULL);
796         gpio_request(GPIO_FN_LCD0_D12,          NULL);
797         gpio_request(GPIO_FN_LCD0_D13,          NULL);
798         gpio_request(GPIO_FN_LCD0_D14,          NULL);
799         gpio_request(GPIO_FN_LCD0_D15,          NULL);
800         gpio_request(GPIO_FN_LCD0_D16,          NULL);
801         gpio_request(GPIO_FN_LCD0_D17,          NULL);
802         gpio_request(GPIO_FN_LCD0_D18_PORT40,   NULL);
803         gpio_request(GPIO_FN_LCD0_D19_PORT4,    NULL);
804         gpio_request(GPIO_FN_LCD0_D20_PORT3,    NULL);
805         gpio_request(GPIO_FN_LCD0_D21_PORT2,    NULL);
806         gpio_request(GPIO_FN_LCD0_D22_PORT0,    NULL);
807         gpio_request(GPIO_FN_LCD0_D23_PORT1,    NULL);
808         gpio_request(GPIO_FN_LCD0_DCK,          NULL);
809         gpio_request(GPIO_FN_LCD0_VSYN,         NULL);
810         gpio_request(GPIO_FN_LCD0_HSYN,         NULL);
811         gpio_request(GPIO_FN_LCD0_DISP,         NULL);
812         gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
813
814         gpio_request(GPIO_PORT61, NULL); /* LCDDON */
815         gpio_direction_output(GPIO_PORT61, 1);
816
817         gpio_request(GPIO_PORT202, NULL); /* LCD0_LED_CONT */
818         gpio_direction_output(GPIO_PORT202, 0);
819
820         /* Touchscreen */
821         gpio_request(GPIO_FN_IRQ10,     NULL); /* TP_INT */
822         gpio_request(GPIO_PORT166,      NULL); /* TP_RST_B */
823         gpio_direction_output(GPIO_PORT166, 1);
824
825         /* GETHER */
826         gpio_request(GPIO_FN_ET_CRS,            NULL);
827         gpio_request(GPIO_FN_ET_MDC,            NULL);
828         gpio_request(GPIO_FN_ET_MDIO,           NULL);
829         gpio_request(GPIO_FN_ET_TX_ER,          NULL);
830         gpio_request(GPIO_FN_ET_RX_ER,          NULL);
831         gpio_request(GPIO_FN_ET_ERXD0,          NULL);
832         gpio_request(GPIO_FN_ET_ERXD1,          NULL);
833         gpio_request(GPIO_FN_ET_ERXD2,          NULL);
834         gpio_request(GPIO_FN_ET_ERXD3,          NULL);
835         gpio_request(GPIO_FN_ET_TX_CLK,         NULL);
836         gpio_request(GPIO_FN_ET_TX_EN,          NULL);
837         gpio_request(GPIO_FN_ET_ETXD0,          NULL);
838         gpio_request(GPIO_FN_ET_ETXD1,          NULL);
839         gpio_request(GPIO_FN_ET_ETXD2,          NULL);
840         gpio_request(GPIO_FN_ET_ETXD3,          NULL);
841         gpio_request(GPIO_FN_ET_PHY_INT,        NULL);
842         gpio_request(GPIO_FN_ET_COL,            NULL);
843         gpio_request(GPIO_FN_ET_RX_DV,          NULL);
844         gpio_request(GPIO_FN_ET_RX_CLK,         NULL);
845
846         gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
847         gpio_direction_output(GPIO_PORT18, 1);
848
849         /* USB */
850         gpio_request(GPIO_PORT159, NULL); /* USB_DEVICE_MODE */
851         gpio_direction_input(GPIO_PORT159);
852
853         if (gpio_get_value(GPIO_PORT159)) {
854                 /* USB Host */
855         } else {
856                 /* USB Func */
857                 gpio_request(GPIO_FN_VBUS, NULL);
858                 platform_device_register(&usbhsf_device);
859         }
860
861         /* SDHI0 */
862         gpio_request(GPIO_FN_SDHI0_CMD, NULL);
863         gpio_request(GPIO_FN_SDHI0_CLK, NULL);
864         gpio_request(GPIO_FN_SDHI0_D0, NULL);
865         gpio_request(GPIO_FN_SDHI0_D1, NULL);
866         gpio_request(GPIO_FN_SDHI0_D2, NULL);
867         gpio_request(GPIO_FN_SDHI0_D3, NULL);
868         gpio_request(GPIO_FN_SDHI0_WP, NULL);
869
870         gpio_request(GPIO_PORT17, NULL);        /* SDHI0_18/33_B */
871         gpio_request(GPIO_PORT74, NULL);        /* SDHI0_PON */
872         gpio_request(GPIO_PORT75, NULL);        /* SDSLOT1_PON */
873         gpio_direction_output(GPIO_PORT17, 0);
874         gpio_direction_output(GPIO_PORT74, 1);
875         gpio_direction_output(GPIO_PORT75, 1);
876
877         /* we can use GPIO_FN_IRQ31_PORT167 here for SDHI0 CD irq */
878
879         /*
880          * MMCIF
881          *
882          * Here doesn't care SW1.4 status,
883          * since CON2 is not mounted.
884          */
885         gpio_request(GPIO_FN_MMC1_CLK_PORT103,  NULL);
886         gpio_request(GPIO_FN_MMC1_CMD_PORT104,  NULL);
887         gpio_request(GPIO_FN_MMC1_D0_PORT149,   NULL);
888         gpio_request(GPIO_FN_MMC1_D1_PORT148,   NULL);
889         gpio_request(GPIO_FN_MMC1_D2_PORT147,   NULL);
890         gpio_request(GPIO_FN_MMC1_D3_PORT146,   NULL);
891         gpio_request(GPIO_FN_MMC1_D4_PORT145,   NULL);
892         gpio_request(GPIO_FN_MMC1_D5_PORT144,   NULL);
893         gpio_request(GPIO_FN_MMC1_D6_PORT143,   NULL);
894         gpio_request(GPIO_FN_MMC1_D7_PORT142,   NULL);
895
896         /* CEU0 */
897         gpio_request(GPIO_FN_VIO0_D7,           NULL);
898         gpio_request(GPIO_FN_VIO0_D6,           NULL);
899         gpio_request(GPIO_FN_VIO0_D5,           NULL);
900         gpio_request(GPIO_FN_VIO0_D4,           NULL);
901         gpio_request(GPIO_FN_VIO0_D3,           NULL);
902         gpio_request(GPIO_FN_VIO0_D2,           NULL);
903         gpio_request(GPIO_FN_VIO0_D1,           NULL);
904         gpio_request(GPIO_FN_VIO0_D0,           NULL);
905         gpio_request(GPIO_FN_VIO0_CLK,          NULL);
906         gpio_request(GPIO_FN_VIO0_HD,           NULL);
907         gpio_request(GPIO_FN_VIO0_VD,           NULL);
908         gpio_request(GPIO_FN_VIO0_FIELD,        NULL);
909         gpio_request(GPIO_FN_VIO_CKO,           NULL);
910
911         /* CON1/CON15 Camera */
912         gpio_request(GPIO_PORT173, NULL); /* STANDBY */
913         gpio_request(GPIO_PORT172, NULL); /* RST */
914         gpio_request(GPIO_PORT158, NULL); /* CAM_PON */
915         gpio_direction_output(GPIO_PORT173, 0);
916         gpio_direction_output(GPIO_PORT172, 1);
917         gpio_direction_output(GPIO_PORT158, 0); /* see mt9t111_power() */
918
919         /*
920          * CAUTION
921          *
922          * DBGMD/LCDC0/FSIA MUX
923          * DBGMD_SELECT_B should be set after setting PFC Function.
924          */
925         gpio_request(GPIO_PORT176, NULL);
926         gpio_direction_output(GPIO_PORT176, 1);
927
928         /*
929          * We can switch CON8/CON14 by SW1.5,
930          * but it needs after DBGMD_SELECT_B
931          */
932         gpio_request(GPIO_PORT6, NULL);
933         gpio_direction_input(GPIO_PORT6);
934         if (gpio_get_value(GPIO_PORT6)) {
935                 /* CON14 enable */
936         } else {
937                 /* CON8 (SDHI1) enable */
938                 gpio_request(GPIO_FN_SDHI1_CLK, NULL);
939                 gpio_request(GPIO_FN_SDHI1_CMD, NULL);
940                 gpio_request(GPIO_FN_SDHI1_D0,  NULL);
941                 gpio_request(GPIO_FN_SDHI1_D1,  NULL);
942                 gpio_request(GPIO_FN_SDHI1_D2,  NULL);
943                 gpio_request(GPIO_FN_SDHI1_D3,  NULL);
944                 gpio_request(GPIO_FN_SDHI1_CD,  NULL);
945                 gpio_request(GPIO_FN_SDHI1_WP,  NULL);
946
947                 gpio_request(GPIO_PORT16, NULL); /* SDSLOT2_PON */
948                 gpio_direction_output(GPIO_PORT16, 1);
949
950                 platform_device_register(&sdhi1_device);
951         }
952
953
954 #ifdef CONFIG_CACHE_L2X0
955         /* Early BRESP enable, Shared attribute override enable, 32K*8way */
956         l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
957 #endif
958
959         i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
960
961         r8a7740_add_standard_devices();
962
963         platform_add_devices(eva_devices,
964                              ARRAY_SIZE(eva_devices));
965 }
966
967 static void __init eva_earlytimer_init(void)
968 {
969         r8a7740_clock_init(MD_CK0 | MD_CK2);
970         shmobile_earlytimer_init();
971 }
972
973 static void __init eva_add_early_devices(void)
974 {
975         r8a7740_add_early_devices();
976
977         /* override timer setup with board-specific code */
978         shmobile_timer.init = eva_earlytimer_init;
979 }
980
981 static const char *eva_boards_compat_dt[] __initdata = {
982         "renesas,armadillo800eva",
983         NULL,
984 };
985
986 DT_MACHINE_START(ARMADILLO800EVA_DT, "armadillo800eva")
987         .map_io         = r8a7740_map_io,
988         .init_early     = eva_add_early_devices,
989         .init_irq       = r8a7740_init_irq,
990         .handle_irq     = shmobile_handle_irq_intc,
991         .init_machine   = eva_init,
992         .init_late      = shmobile_init_late,
993         .timer          = &shmobile_timer,
994         .dt_compat      = eva_boards_compat_dt,
995 MACHINE_END