Merge git://1984.lsi.us.es/nf-next
[cascardo/linux.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/regulator/fixed.h>
32 #include <linux/regulator/machine.h>
33 #include <linux/sh_eth.h>
34 #include <linux/videodev2.h>
35 #include <linux/usb/renesas_usbhs.h>
36 #include <linux/mfd/tmio.h>
37 #include <linux/mmc/host.h>
38 #include <linux/mmc/sh_mmcif.h>
39 #include <linux/mmc/sh_mobile_sdhi.h>
40 #include <mach/common.h>
41 #include <mach/irqs.h>
42 #include <mach/r8a7740.h>
43 #include <media/mt9t112.h>
44 #include <media/sh_mobile_ceu.h>
45 #include <media/soc_camera.h>
46 #include <asm/page.h>
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <asm/mach/map.h>
50 #include <asm/mach/time.h>
51 #include <asm/hardware/cache-l2x0.h>
52 #include <video/sh_mobile_lcdc.h>
53 #include <video/sh_mobile_hdmi.h>
54 #include <sound/sh_fsi.h>
55 #include <sound/simple_card.h>
56
57 /*
58  * CON1         Camera Module
59  * CON2         Extension Bus
60  * CON3         HDMI Output
61  * CON4         Composite Video Output
62  * CON5         H-UDI JTAG
63  * CON6         ARM JTAG
64  * CON7         SD1
65  * CON8         SD2
66  * CON9         RTC BackUp
67  * CON10        Monaural Mic Input
68  * CON11        Stereo Headphone Output
69  * CON12        Audio Line Output(L)
70  * CON13        Audio Line Output(R)
71  * CON14        AWL13 Module
72  * CON15        Extension
73  * CON16        LCD1
74  * CON17        LCD2
75  * CON19        Power Input
76  * CON20        USB1
77  * CON21        USB2
78  * CON22        Serial
79  * CON23        LAN
80  * CON24        USB3
81  * LED1         Camera LED(Yellow)
82  * LED2         Power LED (Green)
83  * ED3-LED6     User LED(Yellow)
84  * LED7         LAN link LED(Green)
85  * LED8         LAN activity LED(Yellow)
86  */
87
88 /*
89  * DipSwitch
90  *
91  *                    SW1
92  *
93  * -12345678-+---------------+----------------------------
94  *  1        | boot          | hermit
95  *  0        | boot          | OS auto boot
96  * -12345678-+---------------+----------------------------
97  *   00      | boot device   | eMMC
98  *   10      | boot device   | SDHI0 (CON7)
99  *   01      | boot device   | -
100  *   11      | boot device   | Extension Buss (CS0)
101  * -12345678-+---------------+----------------------------
102  *     0     | Extension Bus | D8-D15 disable, eMMC enable
103  *     1     | Extension Bus | D8-D15 enable,  eMMC disable
104  * -12345678-+---------------+----------------------------
105  *      0    | SDHI1         | COM8 disable, COM14 enable
106  *      1    | SDHI1         | COM8 enable,  COM14 disable
107  * -12345678-+---------------+----------------------------
108  *       0   | USB0          | COM20 enable,  COM24 disable
109  *       1   | USB0          | COM20 disable, COM24 enable
110  * -12345678-+---------------+----------------------------
111  *        00 | JTAG          | SH-X2
112  *        10 | JTAG          | ARM
113  *        01 | JTAG          | -
114  *        11 | JTAG          | Boundary Scan
115  *-----------+---------------+----------------------------
116  */
117
118 /*
119  * FSI-WM8978
120  *
121  * this command is required when playback.
122  *
123  * # amixer set "Headphone" 50
124  */
125
126 /*
127  * USB function
128  *
129  * When you use USB Function,
130  * set SW1.6 ON, and connect cable to CN24.
131  *
132  * USBF needs workaround on R8A7740 chip.
133  * These are a little bit complex.
134  * see
135  *      usbhsf_power_ctrl()
136  */
137 #define IRQ7            evt2irq(0x02e0)
138 #define USBCR1          0xe605810a
139 #define USBH            0xC6700000
140 #define USBH_USBCTR     0x10834
141
142 struct usbhsf_private {
143         struct clk *phy;
144         struct clk *usb24;
145         struct clk *pci;
146         struct clk *func;
147         struct clk *host;
148         void __iomem *usbh_base;
149         struct renesas_usbhs_platform_info info;
150 };
151
152 #define usbhsf_get_priv(pdev)                           \
153         container_of(renesas_usbhs_get_info(pdev),      \
154                      struct usbhsf_private, info)
155
156 static int usbhsf_get_id(struct platform_device *pdev)
157 {
158         return USBHS_GADGET;
159 }
160
161 static void usbhsf_power_ctrl(struct platform_device *pdev,
162                               void __iomem *base, int enable)
163 {
164         struct usbhsf_private *priv = usbhsf_get_priv(pdev);
165
166         /*
167          * Work around for USB Function.
168          * It needs USB host clock, and settings
169          */
170         if (enable) {
171                 /*
172                  * enable all the related usb clocks
173                  * for usb workaround
174                  */
175                 clk_enable(priv->usb24);
176                 clk_enable(priv->pci);
177                 clk_enable(priv->host);
178                 clk_enable(priv->func);
179                 clk_enable(priv->phy);
180
181                 /*
182                  * set USBCR1
183                  *
184                  * Port1 is driven by USB function,
185                  * Port2 is driven by USB HOST
186                  * One HOST (Port1 or Port2 is HOST)
187                  * USB PLL input clock = 24MHz
188                  */
189                 __raw_writew(0xd750, USBCR1);
190                 mdelay(1);
191
192                 /*
193                  * start USB Host
194                  */
195                 __raw_writel(0x0000000c, priv->usbh_base + USBH_USBCTR);
196                 __raw_writel(0x00000008, priv->usbh_base + USBH_USBCTR);
197                 mdelay(10);
198
199                 /*
200                  * USB PHY Power ON
201                  */
202                 __raw_writew(0xd770, USBCR1);
203                 __raw_writew(0x4000, base + 0x102); /* USBF :: SUSPMODE */
204
205         } else {
206                 __raw_writel(0x0000010f, priv->usbh_base + USBH_USBCTR);
207                 __raw_writew(0xd7c0, USBCR1); /* GPIO */
208
209                 clk_disable(priv->phy);
210                 clk_disable(priv->func);        /* usb work around */
211                 clk_disable(priv->host);        /* usb work around */
212                 clk_disable(priv->pci);         /* usb work around */
213                 clk_disable(priv->usb24);       /* usb work around */
214         }
215 }
216
217 static int usbhsf_get_vbus(struct platform_device *pdev)
218 {
219         return gpio_get_value(GPIO_PORT209);
220 }
221
222 static irqreturn_t usbhsf_interrupt(int irq, void *data)
223 {
224         struct platform_device *pdev = data;
225
226         renesas_usbhs_call_notify_hotplug(pdev);
227
228         return IRQ_HANDLED;
229 }
230
231 static void usbhsf_hardware_exit(struct platform_device *pdev)
232 {
233         struct usbhsf_private *priv = usbhsf_get_priv(pdev);
234
235         if (!IS_ERR(priv->phy))
236                 clk_put(priv->phy);
237         if (!IS_ERR(priv->usb24))
238                 clk_put(priv->usb24);
239         if (!IS_ERR(priv->pci))
240                 clk_put(priv->pci);
241         if (!IS_ERR(priv->host))
242                 clk_put(priv->host);
243         if (!IS_ERR(priv->func))
244                 clk_put(priv->func);
245         if (priv->usbh_base)
246                 iounmap(priv->usbh_base);
247
248         priv->phy       = NULL;
249         priv->usb24     = NULL;
250         priv->pci       = NULL;
251         priv->host      = NULL;
252         priv->func      = NULL;
253         priv->usbh_base = NULL;
254
255         free_irq(IRQ7, pdev);
256 }
257
258 static int usbhsf_hardware_init(struct platform_device *pdev)
259 {
260         struct usbhsf_private *priv = usbhsf_get_priv(pdev);
261         int ret;
262
263         priv->phy       = clk_get(&pdev->dev, "phy");
264         priv->usb24     = clk_get(&pdev->dev, "usb24");
265         priv->pci       = clk_get(&pdev->dev, "pci");
266         priv->func      = clk_get(&pdev->dev, "func");
267         priv->host      = clk_get(&pdev->dev, "host");
268         priv->usbh_base = ioremap_nocache(USBH, 0x20000);
269
270         if (IS_ERR(priv->phy)           ||
271             IS_ERR(priv->usb24)         ||
272             IS_ERR(priv->pci)           ||
273             IS_ERR(priv->host)          ||
274             IS_ERR(priv->func)          ||
275             !priv->usbh_base) {
276                 dev_err(&pdev->dev, "USB clock setting failed\n");
277                 usbhsf_hardware_exit(pdev);
278                 return -EIO;
279         }
280
281         ret = request_irq(IRQ7, usbhsf_interrupt, IRQF_TRIGGER_NONE,
282                           dev_name(&pdev->dev), pdev);
283         if (ret) {
284                 dev_err(&pdev->dev, "request_irq err\n");
285                 return ret;
286         }
287         irq_set_irq_type(IRQ7, IRQ_TYPE_EDGE_BOTH);
288
289         /* usb24 use 1/1 of parent clock (= usb24s = 24MHz) */
290         clk_set_rate(priv->usb24,
291                      clk_get_rate(clk_get_parent(priv->usb24)));
292
293         return 0;
294 }
295
296 static struct usbhsf_private usbhsf_private = {
297         .info = {
298                 .platform_callback = {
299                         .get_id         = usbhsf_get_id,
300                         .get_vbus       = usbhsf_get_vbus,
301                         .hardware_init  = usbhsf_hardware_init,
302                         .hardware_exit  = usbhsf_hardware_exit,
303                         .power_ctrl     = usbhsf_power_ctrl,
304                 },
305                 .driver_param = {
306                         .buswait_bwait          = 5,
307                         .detection_delay        = 5,
308                         .d0_rx_id       = SHDMA_SLAVE_USBHS_RX,
309                         .d1_tx_id       = SHDMA_SLAVE_USBHS_TX,
310                 },
311         }
312 };
313
314 static struct resource usbhsf_resources[] = {
315         {
316                 .name   = "USBHS",
317                 .start  = 0xe6890000,
318                 .end    = 0xe6890104 - 1,
319                 .flags  = IORESOURCE_MEM,
320         },
321         {
322                 .start  = evt2irq(0x0A20),
323                 .flags  = IORESOURCE_IRQ,
324         },
325 };
326
327 static struct platform_device usbhsf_device = {
328         .name   = "renesas_usbhs",
329         .dev = {
330                 .platform_data = &usbhsf_private.info,
331         },
332         .id = -1,
333         .num_resources  = ARRAY_SIZE(usbhsf_resources),
334         .resource       = usbhsf_resources,
335 };
336
337 /* Ether */
338 static struct sh_eth_plat_data sh_eth_platdata = {
339         .phy                    = 0x00, /* LAN8710A */
340         .edmac_endian           = EDMAC_LITTLE_ENDIAN,
341         .register_type          = SH_ETH_REG_GIGABIT,
342         .phy_interface          = PHY_INTERFACE_MODE_MII,
343 };
344
345 static struct resource sh_eth_resources[] = {
346         {
347                 .start  = 0xe9a00000,
348                 .end    = 0xe9a00800 - 1,
349                 .flags  = IORESOURCE_MEM,
350         }, {
351                 .start  = 0xe9a01800,
352                 .end    = 0xe9a02000 - 1,
353                 .flags  = IORESOURCE_MEM,
354         }, {
355                 .start  = evt2irq(0x0500),
356                 .flags  = IORESOURCE_IRQ,
357         },
358 };
359
360 static struct platform_device sh_eth_device = {
361         .name = "sh-eth",
362         .id = -1,
363         .dev = {
364                 .platform_data = &sh_eth_platdata,
365         },
366         .resource = sh_eth_resources,
367         .num_resources = ARRAY_SIZE(sh_eth_resources),
368 };
369
370 /* LCDC */
371 static struct fb_videomode lcdc0_mode = {
372         .name           = "AMPIER/AM-800480",
373         .xres           = 800,
374         .yres           = 480,
375         .left_margin    = 88,
376         .right_margin   = 40,
377         .hsync_len      = 128,
378         .upper_margin   = 20,
379         .lower_margin   = 5,
380         .vsync_len      = 5,
381         .sync           = 0,
382 };
383
384 static struct sh_mobile_lcdc_info lcdc0_info = {
385         .clock_source   = LCDC_CLK_BUS,
386         .ch[0] = {
387                 .chan           = LCDC_CHAN_MAINLCD,
388                 .fourcc         = V4L2_PIX_FMT_RGB565,
389                 .interface_type = RGB24,
390                 .clock_divider  = 5,
391                 .flags          = 0,
392                 .lcd_modes      = &lcdc0_mode,
393                 .num_modes      = 1,
394                 .panel_cfg = {
395                         .width  = 111,
396                         .height = 68,
397                 },
398         },
399 };
400
401 static struct resource lcdc0_resources[] = {
402         [0] = {
403                 .name   = "LCD0",
404                 .start  = 0xfe940000,
405                 .end    = 0xfe943fff,
406                 .flags  = IORESOURCE_MEM,
407         },
408         [1] = {
409                 .start  = intcs_evt2irq(0x580),
410                 .flags  = IORESOURCE_IRQ,
411         },
412 };
413
414 static struct platform_device lcdc0_device = {
415         .name           = "sh_mobile_lcdc_fb",
416         .num_resources  = ARRAY_SIZE(lcdc0_resources),
417         .resource       = lcdc0_resources,
418         .id             = 0,
419         .dev    = {
420                 .platform_data  = &lcdc0_info,
421                 .coherent_dma_mask = ~0,
422         },
423 };
424
425 /*
426  * LCDC1/HDMI
427  */
428 static struct sh_mobile_hdmi_info hdmi_info = {
429         .flags          = HDMI_OUTPUT_PUSH_PULL |
430                           HDMI_OUTPUT_POLARITY_HI |
431                           HDMI_32BIT_REG |
432                           HDMI_HAS_HTOP1 |
433                           HDMI_SND_SRC_SPDIF,
434 };
435
436 static struct resource hdmi_resources[] = {
437         [0] = {
438                 .name   = "HDMI",
439                 .start  = 0xe6be0000,
440                 .end    = 0xe6be03ff,
441                 .flags  = IORESOURCE_MEM,
442         },
443         [1] = {
444                 .start  = evt2irq(0x1700),
445                 .flags  = IORESOURCE_IRQ,
446         },
447         [2] = {
448                 .name   = "HDMI emma3pf",
449                 .start  = 0xe6be4000,
450                 .end    = 0xe6be43ff,
451                 .flags  = IORESOURCE_MEM,
452         },
453 };
454
455 static struct platform_device hdmi_device = {
456         .name           = "sh-mobile-hdmi",
457         .num_resources  = ARRAY_SIZE(hdmi_resources),
458         .resource       = hdmi_resources,
459         .id             = -1,
460         .dev    = {
461                 .platform_data  = &hdmi_info,
462         },
463 };
464
465 static const struct fb_videomode lcdc1_mode = {
466         .name           = "HDMI 720p",
467         .xres           = 1280,
468         .yres           = 720,
469         .pixclock       = 13468,
470         .left_margin    = 220,
471         .right_margin   = 110,
472         .hsync_len      = 40,
473         .upper_margin   = 20,
474         .lower_margin   = 5,
475         .vsync_len      = 5,
476         .refresh        = 60,
477         .sync           = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
478 };
479
480 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
481         .clock_source   = LCDC_CLK_PERIPHERAL, /* HDMI clock */
482         .ch[0] = {
483                 .chan                   = LCDC_CHAN_MAINLCD,
484                 .fourcc                 = V4L2_PIX_FMT_RGB565,
485                 .interface_type         = RGB24,
486                 .clock_divider          = 1,
487                 .flags                  = LCDC_FLAGS_DWPOL,
488                 .lcd_modes              = &lcdc1_mode,
489                 .num_modes              = 1,
490                 .tx_dev                 = &hdmi_device,
491                 .panel_cfg = {
492                         .width  = 1280,
493                         .height = 720,
494                 },
495         },
496 };
497
498 static struct resource hdmi_lcdc_resources[] = {
499         [0] = {
500                 .name   = "LCDC1",
501                 .start  = 0xfe944000,
502                 .end    = 0xfe948000 - 1,
503                 .flags  = IORESOURCE_MEM,
504         },
505         [1] = {
506                 .start  = intcs_evt2irq(0x1780),
507                 .flags  = IORESOURCE_IRQ,
508         },
509 };
510
511 static struct platform_device hdmi_lcdc_device = {
512         .name           = "sh_mobile_lcdc_fb",
513         .num_resources  = ARRAY_SIZE(hdmi_lcdc_resources),
514         .resource       = hdmi_lcdc_resources,
515         .id             = 1,
516         .dev    = {
517                 .platform_data  = &hdmi_lcdc_info,
518                 .coherent_dma_mask = ~0,
519         },
520 };
521
522 /* GPIO KEY */
523 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
524
525 static struct gpio_keys_button gpio_buttons[] = {
526         GPIO_KEY(KEY_POWER,     GPIO_PORT99,    "SW1"),
527         GPIO_KEY(KEY_BACK,      GPIO_PORT100,   "SW2"),
528         GPIO_KEY(KEY_MENU,      GPIO_PORT97,    "SW3"),
529         GPIO_KEY(KEY_HOME,      GPIO_PORT98,    "SW4"),
530 };
531
532 static struct gpio_keys_platform_data gpio_key_info = {
533         .buttons        = gpio_buttons,
534         .nbuttons       = ARRAY_SIZE(gpio_buttons),
535 };
536
537 static struct platform_device gpio_keys_device = {
538         .name   = "gpio-keys",
539         .id     = -1,
540         .dev    = {
541                 .platform_data  = &gpio_key_info,
542         },
543 };
544
545 /* Fixed 3.3V regulator to be used by SDHI0, SDHI1, MMCIF */
546 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
547 {
548         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
549         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
550         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
551         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
552         REGULATOR_SUPPLY("vmmc", "sh_mmcif"),
553         REGULATOR_SUPPLY("vqmmc", "sh_mmcif"),
554 };
555
556 /* SDHI0 */
557 /*
558  * FIXME
559  *
560  * It use polling mode here, since
561  * CD (= Card Detect) pin is not connected to SDHI0_CD.
562  * We can use IRQ31 as card detect irq,
563  * but it needs chattering removal operation
564  */
565 #define IRQ31   evt2irq(0x33E0)
566 static struct sh_mobile_sdhi_info sdhi0_info = {
567         .dma_slave_tx   = SHDMA_SLAVE_SDHI0_TX,
568         .dma_slave_rx   = SHDMA_SLAVE_SDHI0_RX,
569         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |\
570                           MMC_CAP_NEEDS_POLL,
571         .tmio_ocr_mask  = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
572         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT,
573 };
574
575 static struct resource sdhi0_resources[] = {
576         {
577                 .name   = "SDHI0",
578                 .start  = 0xe6850000,
579                 .end    = 0xe6850100 - 1,
580                 .flags  = IORESOURCE_MEM,
581         },
582         /*
583          * no SH_MOBILE_SDHI_IRQ_CARD_DETECT here
584          */
585         {
586                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
587                 .start  = evt2irq(0x0E20),
588                 .flags  = IORESOURCE_IRQ,
589         },
590         {
591                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
592                 .start  = evt2irq(0x0E40),
593                 .flags  = IORESOURCE_IRQ,
594         },
595 };
596
597 static struct platform_device sdhi0_device = {
598         .name           = "sh_mobile_sdhi",
599         .id             = 0,
600         .dev            = {
601                 .platform_data  = &sdhi0_info,
602         },
603         .num_resources  = ARRAY_SIZE(sdhi0_resources),
604         .resource       = sdhi0_resources,
605 };
606
607 /* SDHI1 */
608 static struct sh_mobile_sdhi_info sdhi1_info = {
609         .dma_slave_tx   = SHDMA_SLAVE_SDHI1_TX,
610         .dma_slave_rx   = SHDMA_SLAVE_SDHI1_RX,
611         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
612         .tmio_ocr_mask  = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
613         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT,
614 };
615
616 static struct resource sdhi1_resources[] = {
617         [0] = {
618                 .name   = "SDHI1",
619                 .start  = 0xe6860000,
620                 .end    = 0xe6860100 - 1,
621                 .flags  = IORESOURCE_MEM,
622         },
623         [1] = {
624                 .start  = evt2irq(0x0E80),
625                 .flags  = IORESOURCE_IRQ,
626         },
627         [2] = {
628                 .start  = evt2irq(0x0EA0),
629                 .flags  = IORESOURCE_IRQ,
630         },
631         [3] = {
632                 .start  = evt2irq(0x0EC0),
633                 .flags  = IORESOURCE_IRQ,
634         },
635 };
636
637 static struct platform_device sdhi1_device = {
638         .name           = "sh_mobile_sdhi",
639         .id             = 1,
640         .dev            = {
641                 .platform_data  = &sdhi1_info,
642         },
643         .num_resources  = ARRAY_SIZE(sdhi1_resources),
644         .resource       = sdhi1_resources,
645 };
646
647 /* MMCIF */
648 static struct sh_mmcif_plat_data sh_mmcif_plat = {
649         .sup_pclk       = 0,
650         .ocr            = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
651         .caps           = MMC_CAP_4_BIT_DATA |
652                           MMC_CAP_8_BIT_DATA |
653                           MMC_CAP_NONREMOVABLE,
654 };
655
656 static struct resource sh_mmcif_resources[] = {
657         [0] = {
658                 .name   = "MMCIF",
659                 .start  = 0xe6bd0000,
660                 .end    = 0xe6bd0100 - 1,
661                 .flags  = IORESOURCE_MEM,
662         },
663         [1] = {
664                 /* MMC ERR */
665                 .start  = evt2irq(0x1AC0),
666                 .flags  = IORESOURCE_IRQ,
667         },
668         [2] = {
669                 /* MMC NOR */
670                 .start  = evt2irq(0x1AE0),
671                 .flags  = IORESOURCE_IRQ,
672         },
673 };
674
675 static struct platform_device sh_mmcif_device = {
676         .name           = "sh_mmcif",
677         .id             = -1,
678         .dev            = {
679                 .platform_data  = &sh_mmcif_plat,
680         },
681         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
682         .resource       = sh_mmcif_resources,
683 };
684
685 /* Camera */
686 static int mt9t111_power(struct device *dev, int mode)
687 {
688         struct clk *mclk = clk_get(NULL, "video1");
689
690         if (IS_ERR(mclk)) {
691                 dev_err(dev, "can't get video1 clock\n");
692                 return -EINVAL;
693         }
694
695         if (mode) {
696                 /* video1 (= CON1 camera) expect 24MHz */
697                 clk_set_rate(mclk, clk_round_rate(mclk, 24000000));
698                 clk_enable(mclk);
699                 gpio_direction_output(GPIO_PORT158, 1);
700         } else {
701                 gpio_direction_output(GPIO_PORT158, 0);
702                 clk_disable(mclk);
703         }
704
705         clk_put(mclk);
706
707         return 0;
708 }
709
710 static struct i2c_board_info i2c_camera_mt9t111 = {
711         I2C_BOARD_INFO("mt9t112", 0x3d),
712 };
713
714 static struct mt9t112_camera_info mt9t111_info = {
715         .divider = { 16, 0, 0, 7, 0, 10, 14, 7, 7 },
716 };
717
718 static struct soc_camera_link mt9t111_link = {
719         .i2c_adapter_id = 0,
720         .bus_id         = 0,
721         .board_info     = &i2c_camera_mt9t111,
722         .power          = mt9t111_power,
723         .priv           = &mt9t111_info,
724 };
725
726 static struct platform_device camera_device = {
727         .name   = "soc-camera-pdrv",
728         .id     = 0,
729         .dev    = {
730                 .platform_data = &mt9t111_link,
731         },
732 };
733
734 /* CEU0 */
735 static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
736         .flags = SH_CEU_FLAG_LOWER_8BIT,
737 };
738
739 static struct resource ceu0_resources[] = {
740         [0] = {
741                 .name   = "CEU",
742                 .start  = 0xfe910000,
743                 .end    = 0xfe91009f,
744                 .flags  = IORESOURCE_MEM,
745         },
746         [1] = {
747                 .start  = intcs_evt2irq(0x0500),
748                 .flags  = IORESOURCE_IRQ,
749         },
750         [2] = {
751                 /* place holder for contiguous memory */
752         },
753 };
754
755 static struct platform_device ceu0_device = {
756         .name           = "sh_mobile_ceu",
757         .id             = 0,
758         .num_resources  = ARRAY_SIZE(ceu0_resources),
759         .resource       = ceu0_resources,
760         .dev    = {
761                 .platform_data          = &sh_mobile_ceu0_info,
762                 .coherent_dma_mask      = 0xffffffff,
763         },
764 };
765
766 /* FSI */
767 static int fsi_hdmi_set_rate(struct device *dev, int rate, int enable)
768 {
769         struct clk *fsib;
770         int ret;
771
772         /* it support 48KHz only */
773         if (48000 != rate)
774                 return -EINVAL;
775
776         fsib = clk_get(dev, "ickb");
777         if (IS_ERR(fsib))
778                 return -EINVAL;
779
780         if (enable) {
781                 ret = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
782                 clk_enable(fsib);
783         } else {
784                 ret = 0;
785                 clk_disable(fsib);
786         }
787
788         clk_put(fsib);
789
790         return ret;
791 }
792
793 static struct sh_fsi_platform_info fsi_info = {
794         /* FSI-WM8978 */
795         .port_a = {
796                 .tx_id = SHDMA_SLAVE_FSIA_TX,
797         },
798         /* FSI-HDMI */
799         .port_b = {
800                 .flags          = SH_FSI_FMT_SPDIF |
801                                   SH_FSI_ENABLE_STREAM_MODE,
802                 .set_rate       = fsi_hdmi_set_rate,
803                 .tx_id          = SHDMA_SLAVE_FSIB_TX,
804         }
805 };
806
807 static struct resource fsi_resources[] = {
808         [0] = {
809                 .name   = "FSI",
810                 .start  = 0xfe1f0000,
811                 .end    = 0xfe1f8400 - 1,
812                 .flags  = IORESOURCE_MEM,
813         },
814         [1] = {
815                 .start  = evt2irq(0x1840),
816                 .flags  = IORESOURCE_IRQ,
817         },
818 };
819
820 static struct platform_device fsi_device = {
821         .name           = "sh_fsi2",
822         .id             = -1,
823         .num_resources  = ARRAY_SIZE(fsi_resources),
824         .resource       = fsi_resources,
825         .dev    = {
826                 .platform_data  = &fsi_info,
827         },
828 };
829
830 /* FSI-WM8978 */
831 static struct asoc_simple_dai_init_info fsi_wm8978_init_info = {
832         .fmt            = SND_SOC_DAIFMT_I2S,
833         .codec_daifmt   = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
834         .cpu_daifmt     = SND_SOC_DAIFMT_CBS_CFS,
835         .sysclk         = 12288000,
836 };
837
838 static struct asoc_simple_card_info fsi_wm8978_info = {
839         .name           = "wm8978",
840         .card           = "FSI2A-WM8978",
841         .cpu_dai        = "fsia-dai",
842         .codec          = "wm8978.0-001a",
843         .platform       = "sh_fsi2",
844         .codec_dai      = "wm8978-hifi",
845         .init           = &fsi_wm8978_init_info,
846 };
847
848 static struct platform_device fsi_wm8978_device = {
849         .name   = "asoc-simple-card",
850         .id     = 0,
851         .dev    = {
852                 .platform_data  = &fsi_wm8978_info,
853         },
854 };
855
856 /* FSI-HDMI */
857 static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
858         .cpu_daifmt     = SND_SOC_DAIFMT_CBM_CFM,
859 };
860
861 static struct asoc_simple_card_info fsi2_hdmi_info = {
862         .name           = "HDMI",
863         .card           = "FSI2B-HDMI",
864         .cpu_dai        = "fsib-dai",
865         .codec          = "sh-mobile-hdmi",
866         .platform       = "sh_fsi2",
867         .codec_dai      = "sh_mobile_hdmi-hifi",
868         .init           = &fsi2_hdmi_init_info,
869 };
870
871 static struct platform_device fsi_hdmi_device = {
872         .name   = "asoc-simple-card",
873         .id     = 1,
874         .dev    = {
875                 .platform_data  = &fsi2_hdmi_info,
876         },
877 };
878
879 /* I2C */
880 static struct i2c_board_info i2c0_devices[] = {
881         {
882                 I2C_BOARD_INFO("st1232-ts", 0x55),
883                 .irq = evt2irq(0x0340),
884         },
885         {
886                 I2C_BOARD_INFO("wm8978", 0x1a),
887         },
888 };
889
890 /*
891  * board devices
892  */
893 static struct platform_device *eva_devices[] __initdata = {
894         &lcdc0_device,
895         &gpio_keys_device,
896         &sh_eth_device,
897         &sdhi0_device,
898         &sh_mmcif_device,
899         &hdmi_device,
900         &hdmi_lcdc_device,
901         &camera_device,
902         &ceu0_device,
903         &fsi_device,
904         &fsi_hdmi_device,
905         &fsi_wm8978_device,
906 };
907
908 static void __init eva_clock_init(void)
909 {
910         struct clk *system      = clk_get(NULL, "system_clk");
911         struct clk *xtal1       = clk_get(NULL, "extal1");
912         struct clk *usb24s      = clk_get(NULL, "usb24s");
913         struct clk *fsibck      = clk_get(NULL, "fsibck");
914         struct clk *fsib        = clk_get(&fsi_device.dev, "ickb");
915
916         if (IS_ERR(system)      ||
917             IS_ERR(xtal1)       ||
918             IS_ERR(usb24s)      ||
919             IS_ERR(fsibck)      ||
920             IS_ERR(fsib)) {
921                 pr_err("armadillo800eva board clock init failed\n");
922                 goto clock_error;
923         }
924
925         /* armadillo 800 eva extal1 is 24MHz */
926         clk_set_rate(xtal1, 24000000);
927
928         /* usb24s use extal1 (= system) clock (= 24MHz) */
929         clk_set_parent(usb24s, system);
930
931         /* FSIBCK is 12.288MHz, and it is parent of FSI-B */
932         clk_set_parent(fsib, fsibck);
933         clk_set_rate(fsibck, 12288000);
934         clk_set_rate(fsib,   12288000);
935
936 clock_error:
937         if (!IS_ERR(system))
938                 clk_put(system);
939         if (!IS_ERR(xtal1))
940                 clk_put(xtal1);
941         if (!IS_ERR(usb24s))
942                 clk_put(usb24s);
943         if (!IS_ERR(fsibck))
944                 clk_put(fsibck);
945         if (!IS_ERR(fsib))
946                 clk_put(fsib);
947 }
948
949 /*
950  * board init
951  */
952 #define GPIO_PORT7CR    0xe6050007
953 #define GPIO_PORT8CR    0xe6050008
954 static void __init eva_init(void)
955 {
956         struct platform_device *usb = NULL;
957
958         regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
959                                      ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
960
961         r8a7740_pinmux_init();
962         r8a7740_meram_workaround();
963
964         /* SCIFA1 */
965         gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
966         gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
967
968         /* LCDC0 */
969         gpio_request(GPIO_FN_LCDC0_SELECT,      NULL);
970         gpio_request(GPIO_FN_LCD0_D0,           NULL);
971         gpio_request(GPIO_FN_LCD0_D1,           NULL);
972         gpio_request(GPIO_FN_LCD0_D2,           NULL);
973         gpio_request(GPIO_FN_LCD0_D3,           NULL);
974         gpio_request(GPIO_FN_LCD0_D4,           NULL);
975         gpio_request(GPIO_FN_LCD0_D5,           NULL);
976         gpio_request(GPIO_FN_LCD0_D6,           NULL);
977         gpio_request(GPIO_FN_LCD0_D7,           NULL);
978         gpio_request(GPIO_FN_LCD0_D8,           NULL);
979         gpio_request(GPIO_FN_LCD0_D9,           NULL);
980         gpio_request(GPIO_FN_LCD0_D10,          NULL);
981         gpio_request(GPIO_FN_LCD0_D11,          NULL);
982         gpio_request(GPIO_FN_LCD0_D12,          NULL);
983         gpio_request(GPIO_FN_LCD0_D13,          NULL);
984         gpio_request(GPIO_FN_LCD0_D14,          NULL);
985         gpio_request(GPIO_FN_LCD0_D15,          NULL);
986         gpio_request(GPIO_FN_LCD0_D16,          NULL);
987         gpio_request(GPIO_FN_LCD0_D17,          NULL);
988         gpio_request(GPIO_FN_LCD0_D18_PORT40,   NULL);
989         gpio_request(GPIO_FN_LCD0_D19_PORT4,    NULL);
990         gpio_request(GPIO_FN_LCD0_D20_PORT3,    NULL);
991         gpio_request(GPIO_FN_LCD0_D21_PORT2,    NULL);
992         gpio_request(GPIO_FN_LCD0_D22_PORT0,    NULL);
993         gpio_request(GPIO_FN_LCD0_D23_PORT1,    NULL);
994         gpio_request(GPIO_FN_LCD0_DCK,          NULL);
995         gpio_request(GPIO_FN_LCD0_VSYN,         NULL);
996         gpio_request(GPIO_FN_LCD0_HSYN,         NULL);
997         gpio_request(GPIO_FN_LCD0_DISP,         NULL);
998         gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
999
1000         gpio_request(GPIO_PORT61, NULL); /* LCDDON */
1001         gpio_direction_output(GPIO_PORT61, 1);
1002
1003         gpio_request(GPIO_PORT202, NULL); /* LCD0_LED_CONT */
1004         gpio_direction_output(GPIO_PORT202, 0);
1005
1006         /* Touchscreen */
1007         gpio_request(GPIO_FN_IRQ10,     NULL); /* TP_INT */
1008         gpio_request(GPIO_PORT166,      NULL); /* TP_RST_B */
1009         gpio_direction_output(GPIO_PORT166, 1);
1010
1011         /* GETHER */
1012         gpio_request(GPIO_FN_ET_CRS,            NULL);
1013         gpio_request(GPIO_FN_ET_MDC,            NULL);
1014         gpio_request(GPIO_FN_ET_MDIO,           NULL);
1015         gpio_request(GPIO_FN_ET_TX_ER,          NULL);
1016         gpio_request(GPIO_FN_ET_RX_ER,          NULL);
1017         gpio_request(GPIO_FN_ET_ERXD0,          NULL);
1018         gpio_request(GPIO_FN_ET_ERXD1,          NULL);
1019         gpio_request(GPIO_FN_ET_ERXD2,          NULL);
1020         gpio_request(GPIO_FN_ET_ERXD3,          NULL);
1021         gpio_request(GPIO_FN_ET_TX_CLK,         NULL);
1022         gpio_request(GPIO_FN_ET_TX_EN,          NULL);
1023         gpio_request(GPIO_FN_ET_ETXD0,          NULL);
1024         gpio_request(GPIO_FN_ET_ETXD1,          NULL);
1025         gpio_request(GPIO_FN_ET_ETXD2,          NULL);
1026         gpio_request(GPIO_FN_ET_ETXD3,          NULL);
1027         gpio_request(GPIO_FN_ET_PHY_INT,        NULL);
1028         gpio_request(GPIO_FN_ET_COL,            NULL);
1029         gpio_request(GPIO_FN_ET_RX_DV,          NULL);
1030         gpio_request(GPIO_FN_ET_RX_CLK,         NULL);
1031
1032         gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
1033         gpio_direction_output(GPIO_PORT18, 1);
1034
1035         /* USB */
1036         gpio_request(GPIO_PORT159, NULL); /* USB_DEVICE_MODE */
1037         gpio_direction_input(GPIO_PORT159);
1038
1039         if (gpio_get_value(GPIO_PORT159)) {
1040                 /* USB Host */
1041         } else {
1042                 /* USB Func */
1043                 /*
1044                  * A1 chip has 2 IRQ7 pin and it was controled by MSEL register.
1045                  * OTOH, usbhs interrupt needs its value (HI/LOW) to decide
1046                  * USB connection/disconnection (usbhsf_get_vbus()).
1047                  * This means we needs to select GPIO_FN_IRQ7_PORT209 first,
1048                  * and select GPIO_PORT209 here
1049                  */
1050                 gpio_request(GPIO_FN_IRQ7_PORT209, NULL);
1051                 gpio_request(GPIO_PORT209, NULL);
1052                 gpio_direction_input(GPIO_PORT209);
1053
1054                 platform_device_register(&usbhsf_device);
1055                 usb = &usbhsf_device;
1056         }
1057
1058         /* SDHI0 */
1059         gpio_request(GPIO_FN_SDHI0_CMD, NULL);
1060         gpio_request(GPIO_FN_SDHI0_CLK, NULL);
1061         gpio_request(GPIO_FN_SDHI0_D0, NULL);
1062         gpio_request(GPIO_FN_SDHI0_D1, NULL);
1063         gpio_request(GPIO_FN_SDHI0_D2, NULL);
1064         gpio_request(GPIO_FN_SDHI0_D3, NULL);
1065         gpio_request(GPIO_FN_SDHI0_WP, NULL);
1066
1067         gpio_request(GPIO_PORT17, NULL);        /* SDHI0_18/33_B */
1068         gpio_request(GPIO_PORT74, NULL);        /* SDHI0_PON */
1069         gpio_request(GPIO_PORT75, NULL);        /* SDSLOT1_PON */
1070         gpio_direction_output(GPIO_PORT17, 0);
1071         gpio_direction_output(GPIO_PORT74, 1);
1072         gpio_direction_output(GPIO_PORT75, 1);
1073
1074         /* we can use GPIO_FN_IRQ31_PORT167 here for SDHI0 CD irq */
1075
1076         /*
1077          * MMCIF
1078          *
1079          * Here doesn't care SW1.4 status,
1080          * since CON2 is not mounted.
1081          */
1082         gpio_request(GPIO_FN_MMC1_CLK_PORT103,  NULL);
1083         gpio_request(GPIO_FN_MMC1_CMD_PORT104,  NULL);
1084         gpio_request(GPIO_FN_MMC1_D0_PORT149,   NULL);
1085         gpio_request(GPIO_FN_MMC1_D1_PORT148,   NULL);
1086         gpio_request(GPIO_FN_MMC1_D2_PORT147,   NULL);
1087         gpio_request(GPIO_FN_MMC1_D3_PORT146,   NULL);
1088         gpio_request(GPIO_FN_MMC1_D4_PORT145,   NULL);
1089         gpio_request(GPIO_FN_MMC1_D5_PORT144,   NULL);
1090         gpio_request(GPIO_FN_MMC1_D6_PORT143,   NULL);
1091         gpio_request(GPIO_FN_MMC1_D7_PORT142,   NULL);
1092
1093         /* CEU0 */
1094         gpio_request(GPIO_FN_VIO0_D7,           NULL);
1095         gpio_request(GPIO_FN_VIO0_D6,           NULL);
1096         gpio_request(GPIO_FN_VIO0_D5,           NULL);
1097         gpio_request(GPIO_FN_VIO0_D4,           NULL);
1098         gpio_request(GPIO_FN_VIO0_D3,           NULL);
1099         gpio_request(GPIO_FN_VIO0_D2,           NULL);
1100         gpio_request(GPIO_FN_VIO0_D1,           NULL);
1101         gpio_request(GPIO_FN_VIO0_D0,           NULL);
1102         gpio_request(GPIO_FN_VIO0_CLK,          NULL);
1103         gpio_request(GPIO_FN_VIO0_HD,           NULL);
1104         gpio_request(GPIO_FN_VIO0_VD,           NULL);
1105         gpio_request(GPIO_FN_VIO0_FIELD,        NULL);
1106         gpio_request(GPIO_FN_VIO_CKO,           NULL);
1107
1108         /* CON1/CON15 Camera */
1109         gpio_request(GPIO_PORT173, NULL); /* STANDBY */
1110         gpio_request(GPIO_PORT172, NULL); /* RST */
1111         gpio_request(GPIO_PORT158, NULL); /* CAM_PON */
1112         gpio_direction_output(GPIO_PORT173, 0);
1113         gpio_direction_output(GPIO_PORT172, 1);
1114         gpio_direction_output(GPIO_PORT158, 0); /* see mt9t111_power() */
1115
1116         /* FSI-WM8978 */
1117         gpio_request(GPIO_FN_FSIAIBT,           NULL);
1118         gpio_request(GPIO_FN_FSIAILR,           NULL);
1119         gpio_request(GPIO_FN_FSIAOMC,           NULL);
1120         gpio_request(GPIO_FN_FSIAOSLD,          NULL);
1121         gpio_request(GPIO_FN_FSIAISLD_PORT5,    NULL);
1122
1123         gpio_request(GPIO_PORT7, NULL);
1124         gpio_request(GPIO_PORT8, NULL);
1125         gpio_direction_none(GPIO_PORT7CR); /* FSIAOBT needs no direction */
1126         gpio_direction_none(GPIO_PORT8CR); /* FSIAOLR needs no direction */
1127
1128         /* FSI-HDMI */
1129         gpio_request(GPIO_FN_FSIBCK,            NULL);
1130
1131         /* HDMI */
1132         gpio_request(GPIO_FN_HDMI_HPD,          NULL);
1133         gpio_request(GPIO_FN_HDMI_CEC,          NULL);
1134
1135         /*
1136          * CAUTION
1137          *
1138          * DBGMD/LCDC0/FSIA MUX
1139          * DBGMD_SELECT_B should be set after setting PFC Function.
1140          */
1141         gpio_request(GPIO_PORT176, NULL);
1142         gpio_direction_output(GPIO_PORT176, 1);
1143
1144         /*
1145          * We can switch CON8/CON14 by SW1.5,
1146          * but it needs after DBGMD_SELECT_B
1147          */
1148         gpio_request(GPIO_PORT6, NULL);
1149         gpio_direction_input(GPIO_PORT6);
1150         if (gpio_get_value(GPIO_PORT6)) {
1151                 /* CON14 enable */
1152         } else {
1153                 /* CON8 (SDHI1) enable */
1154                 gpio_request(GPIO_FN_SDHI1_CLK, NULL);
1155                 gpio_request(GPIO_FN_SDHI1_CMD, NULL);
1156                 gpio_request(GPIO_FN_SDHI1_D0,  NULL);
1157                 gpio_request(GPIO_FN_SDHI1_D1,  NULL);
1158                 gpio_request(GPIO_FN_SDHI1_D2,  NULL);
1159                 gpio_request(GPIO_FN_SDHI1_D3,  NULL);
1160                 gpio_request(GPIO_FN_SDHI1_CD,  NULL);
1161                 gpio_request(GPIO_FN_SDHI1_WP,  NULL);
1162
1163                 gpio_request(GPIO_PORT16, NULL); /* SDSLOT2_PON */
1164                 gpio_direction_output(GPIO_PORT16, 1);
1165
1166                 platform_device_register(&sdhi1_device);
1167         }
1168
1169
1170 #ifdef CONFIG_CACHE_L2X0
1171         /* Early BRESP enable, Shared attribute override enable, 32K*8way */
1172         l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
1173 #endif
1174
1175         i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
1176
1177         r8a7740_add_standard_devices();
1178
1179         platform_add_devices(eva_devices,
1180                              ARRAY_SIZE(eva_devices));
1181
1182         eva_clock_init();
1183
1184         rmobile_add_device_to_domain(&r8a7740_pd_a4lc, &lcdc0_device);
1185         rmobile_add_device_to_domain(&r8a7740_pd_a4lc, &hdmi_lcdc_device);
1186         if (usb)
1187                 rmobile_add_device_to_domain(&r8a7740_pd_a3sp, usb);
1188 }
1189
1190 static void __init eva_earlytimer_init(void)
1191 {
1192         r8a7740_clock_init(MD_CK0 | MD_CK2);
1193         shmobile_earlytimer_init();
1194 }
1195
1196 static void __init eva_add_early_devices(void)
1197 {
1198         r8a7740_add_early_devices();
1199
1200         /* override timer setup with board-specific code */
1201         shmobile_timer.init = eva_earlytimer_init;
1202 }
1203
1204 static const char *eva_boards_compat_dt[] __initdata = {
1205         "renesas,armadillo800eva",
1206         NULL,
1207 };
1208
1209 DT_MACHINE_START(ARMADILLO800EVA_DT, "armadillo800eva")
1210         .map_io         = r8a7740_map_io,
1211         .init_early     = eva_add_early_devices,
1212         .init_irq       = r8a7740_init_irq,
1213         .handle_irq     = shmobile_handle_irq_intc,
1214         .init_machine   = eva_init,
1215         .init_late      = shmobile_init_late,
1216         .timer          = &shmobile_timer,
1217         .dt_compat      = eva_boards_compat_dt,
1218 MACHINE_END