ARM: shmobile: Move pm-rmobile.h, cleanup sh73xx.h
[cascardo/linux.git] / arch / arm / mach-shmobile / board-mackerel.c
1 /*
2  * mackerel board support
3  *
4  * Copyright (C) 2010 Renesas Solutions Corp.
5  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * based on ap4evb
8  * Copyright (C) 2010  Magnus Damm
9  * Copyright (C) 2008  Yoshihiro Shimoda
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; version 2 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  */
24 #include <linux/delay.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/irq.h>
29 #include <linux/platform_device.h>
30 #include <linux/gpio.h>
31 #include <linux/input.h>
32 #include <linux/io.h>
33 #include <linux/i2c.h>
34 #include <linux/leds.h>
35 #include <linux/mfd/tmio.h>
36 #include <linux/mmc/host.h>
37 #include <linux/mmc/sh_mmcif.h>
38 #include <linux/mmc/sh_mobile_sdhi.h>
39 #include <linux/mtd/mtd.h>
40 #include <linux/mtd/partitions.h>
41 #include <linux/mtd/physmap.h>
42 #include <linux/mtd/sh_flctl.h>
43 #include <linux/pinctrl/machine.h>
44 #include <linux/pinctrl/pinconf-generic.h>
45 #include <linux/platform_data/gpio_backlight.h>
46 #include <linux/pm_clock.h>
47 #include <linux/regulator/fixed.h>
48 #include <linux/regulator/machine.h>
49 #include <linux/smsc911x.h>
50 #include <linux/sh_clk.h>
51 #include <linux/tca6416_keypad.h>
52 #include <linux/usb/renesas_usbhs.h>
53 #include <linux/dma-mapping.h>
54 #include <video/sh_mobile_hdmi.h>
55 #include <video/sh_mobile_lcdc.h>
56 #include <media/sh_mobile_ceu.h>
57 #include <media/soc_camera.h>
58 #include <media/soc_camera_platform.h>
59 #include <sound/sh_fsi.h>
60 #include <sound/simple_card.h>
61 #include <mach/sh7372.h>
62 #include <asm/mach/arch.h>
63 #include <asm/mach-types.h>
64 #include "common.h"
65 #include "irqs.h"
66 #include "pm-rmobile.h"
67 #include "sh-gpio.h"
68
69 /*
70  * Address      Interface               BusWidth        note
71  * ------------------------------------------------------------------
72  * 0x0000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = ON
73  * 0x0800_0000  user area               -
74  * 0x1000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = OFF
75  * 0x1400_0000  Ether (LAN9220)         16bit
76  * 0x1600_0000  user area               -               cannot use with NAND
77  * 0x1800_0000  user area               -
78  * 0x1A00_0000  -
79  * 0x4000_0000  LPDDR2-SDRAM (POP)      32bit
80  */
81
82 /*
83  * CPU mode
84  *
85  * SW4                                     | Boot Area| Master   | Remarks
86  *  1  | 2   | 3   | 4   | 5   | 6   | 8   |          | Processor|
87  * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
88  * ON  | ON  | OFF | ON  | ON  | OFF | OFF | External | System   | External ROM
89  * ON  | ON  | ON  | ON  | ON  | OFF | OFF | External | System   | ROM Debug
90  * ON  | ON  | X   | ON  | OFF | OFF | OFF | Built-in | System   | ROM Debug
91  * X   | OFF | X   | X   | X   | X   | OFF | Built-in | System   | MaskROM
92  * OFF | X   | X   | X   | X   | X   | OFF | Built-in | System   | MaskROM
93  * X   | X   | X   | OFF | X   | X   | OFF | Built-in | System   | MaskROM
94  * OFF | ON  | OFF | X   | X   | OFF | ON  | External | System   | Standalone
95  * ON  | OFF | OFF | X   | X   | OFF | ON  | External | Realtime | Standalone
96 */
97
98 /*
99  * NOR Flash ROM
100  *
101  *  SW1  |     SW2    | SW7  | NOR Flash ROM
102  *  bit1 | bit1  bit2 | bit1 | Memory allocation
103  * ------+------------+------+------------------
104  *  OFF  | ON     OFF | ON   |    Area 0
105  *  OFF  | ON     OFF | OFF  |    Area 4
106  */
107
108 /*
109  * SMSC 9220
110  *
111  *  SW1         SMSC 9220
112  * -----------------------
113  *  ON          access disable
114  *  OFF         access enable
115  */
116
117 /*
118  * NAND Flash ROM
119  *
120  *  SW1  |     SW2    | SW7  | NAND Flash ROM
121  *  bit1 | bit1  bit2 | bit2 | Memory allocation
122  * ------+------------+------+------------------
123  *  OFF  | ON     OFF | ON   |    FCE 0
124  *  OFF  | ON     OFF | OFF  |    FCE 1
125  */
126
127 /*
128  * External interrupt pin settings
129  *
130  * IRQX  | pin setting        | device             | level
131  * ------+--------------------+--------------------+-------
132  * IRQ0  | ICR1A.IRQ0SA=0010  | SDHI2 card detect  | Low
133  * IRQ6  | ICR1A.IRQ6SA=0011  | Ether(LAN9220)     | High
134  * IRQ7  | ICR1A.IRQ7SA=0010  | LCD Touch Panel    | Low
135  * IRQ8  | ICR2A.IRQ8SA=0010  | MMC/SD card detect | Low
136  * IRQ9  | ICR2A.IRQ9SA=0010  | KEY(TCA6408)       | Low
137  * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345)    | High
138  * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975)     | High
139  */
140
141 /*
142  * USB
143  *
144  * USB0 : CN22 : Function
145  * USB1 : CN31 : Function/Host *1
146  *
147  * J30 (for CN31) *1
148  * ----------+---------------+-------------
149  * 1-2 short | VBUS 5V       | Host
150  * open      | external VBUS | Function
151  *
152  * CAUTION
153  *
154  * renesas_usbhs driver can use external interrupt mode
155  * (which come from USB-PHY) or autonomy mode (it use own interrupt)
156  * for detecting connection/disconnection when Function.
157  * USB will be power OFF while it has been disconnecting
158  * if external interrupt mode, and it is always power ON if autonomy mode,
159  *
160  * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
161  * because Touchscreen is using IRQ7-PORT40.
162  * It is impossible to use IRQ7 demux on this board.
163  */
164
165 /*
166  * SDHI0 (CN12)
167  *
168  * SW56 : OFF
169  *
170  */
171
172 /* MMC /SDHI1 (CN7)
173  *
174  * I/O voltage : 1.8v
175  *
176  * Power voltage : 1.8v or 3.3v
177  *  J22 : select power voltage *1
178  *      1-2 pin : 1.8v
179  *      2-3 pin : 3.3v
180  *
181  * *1
182  * Please change J22 depends the card to be used.
183  * MMC's OCR field set to support either voltage for the card inserted.
184  *
185  *      SW1     |       SW33
186  *              | bit1 | bit2 | bit3 | bit4
187  * -------------+------+------+------+-------
188  * MMC0   OFF   |  OFF |   X  |  ON  |  X       (Use MMCIF)
189  * SDHI1  OFF   |  ON  |   X  |  OFF |  X       (Use MFD_SH_MOBILE_SDHI)
190  *
191  */
192
193 /*
194  * SDHI2 (CN23)
195  *
196  * microSD card sloct
197  *
198  */
199
200 /*
201  * FSI - AK4642
202  *
203  * it needs amixer settings for playing
204  *
205  * amixer set "Headphone Enable" on
206  */
207
208 /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
209 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
210 {
211         /*
212          * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
213          * Since we cannot support both voltages, we support the default 1.8V
214          */
215         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
216         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
217         REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
218         REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
219 };
220
221 static struct regulator_consumer_supply fixed3v3_power_consumers[] =
222 {
223         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
224         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
225         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
226         REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
227 };
228
229 /* Dummy supplies, where voltage doesn't matter */
230 static struct regulator_consumer_supply dummy_supplies[] = {
231         REGULATOR_SUPPLY("vddvario", "smsc911x"),
232         REGULATOR_SUPPLY("vdd33a", "smsc911x"),
233 };
234
235 /* MTD */
236 static struct mtd_partition nor_flash_partitions[] = {
237         {
238                 .name           = "loader",
239                 .offset         = 0x00000000,
240                 .size           = 512 * 1024,
241                 .mask_flags     = MTD_WRITEABLE,
242         },
243         {
244                 .name           = "bootenv",
245                 .offset         = MTDPART_OFS_APPEND,
246                 .size           = 512 * 1024,
247                 .mask_flags     = MTD_WRITEABLE,
248         },
249         {
250                 .name           = "kernel_ro",
251                 .offset         = MTDPART_OFS_APPEND,
252                 .size           = 8 * 1024 * 1024,
253                 .mask_flags     = MTD_WRITEABLE,
254         },
255         {
256                 .name           = "kernel",
257                 .offset         = MTDPART_OFS_APPEND,
258                 .size           = 8 * 1024 * 1024,
259         },
260         {
261                 .name           = "data",
262                 .offset         = MTDPART_OFS_APPEND,
263                 .size           = MTDPART_SIZ_FULL,
264         },
265 };
266
267 static struct physmap_flash_data nor_flash_data = {
268         .width          = 2,
269         .parts          = nor_flash_partitions,
270         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
271 };
272
273 static struct resource nor_flash_resources[] = {
274         [0]     = {
275                 .start  = 0x20000000, /* CS0 shadow instead of regular CS0 */
276                 .end    = 0x28000000 - 1, /* needed by USB MASK ROM boot */
277                 .flags  = IORESOURCE_MEM,
278         }
279 };
280
281 static struct platform_device nor_flash_device = {
282         .name           = "physmap-flash",
283         .dev            = {
284                 .platform_data  = &nor_flash_data,
285         },
286         .num_resources  = ARRAY_SIZE(nor_flash_resources),
287         .resource       = nor_flash_resources,
288 };
289
290 /* SMSC */
291 static struct resource smc911x_resources[] = {
292         {
293                 .start  = 0x14000000,
294                 .end    = 0x16000000 - 1,
295                 .flags  = IORESOURCE_MEM,
296         }, {
297                 .start  = evt2irq(0x02c0) /* IRQ6A */,
298                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
299         },
300 };
301
302 static struct smsc911x_platform_config smsc911x_info = {
303         .flags          = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
304         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
305         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
306 };
307
308 static struct platform_device smc911x_device = {
309         .name           = "smsc911x",
310         .id             = -1,
311         .num_resources  = ARRAY_SIZE(smc911x_resources),
312         .resource       = smc911x_resources,
313         .dev            = {
314                 .platform_data = &smsc911x_info,
315         },
316 };
317
318 /* MERAM */
319 static struct sh_mobile_meram_info mackerel_meram_info = {
320         .addr_mode      = SH_MOBILE_MERAM_MODE1,
321 };
322
323 static struct resource meram_resources[] = {
324         [0] = {
325                 .name   = "regs",
326                 .start  = 0xe8000000,
327                 .end    = 0xe807ffff,
328                 .flags  = IORESOURCE_MEM,
329         },
330         [1] = {
331                 .name   = "meram",
332                 .start  = 0xe8080000,
333                 .end    = 0xe81fffff,
334                 .flags  = IORESOURCE_MEM,
335         },
336 };
337
338 static struct platform_device meram_device = {
339         .name           = "sh_mobile_meram",
340         .id             = 0,
341         .num_resources  = ARRAY_SIZE(meram_resources),
342         .resource       = meram_resources,
343         .dev            = {
344                 .platform_data = &mackerel_meram_info,
345         },
346 };
347
348 /* LCDC and backlight */
349 static struct fb_videomode mackerel_lcdc_modes[] = {
350         {
351                 .name           = "WVGA Panel",
352                 .xres           = 800,
353                 .yres           = 480,
354                 .left_margin    = 220,
355                 .right_margin   = 110,
356                 .hsync_len      = 70,
357                 .upper_margin   = 20,
358                 .lower_margin   = 5,
359                 .vsync_len      = 5,
360                 .sync           = 0,
361         },
362 };
363
364 static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
365         .icb[0] = {
366                 .meram_size     = 0x40,
367         },
368         .icb[1] = {
369                 .meram_size     = 0x40,
370         },
371 };
372
373 static struct sh_mobile_lcdc_info lcdc_info = {
374         .meram_dev = &mackerel_meram_info,
375         .clock_source = LCDC_CLK_BUS,
376         .ch[0] = {
377                 .chan = LCDC_CHAN_MAINLCD,
378                 .fourcc = V4L2_PIX_FMT_RGB565,
379                 .lcd_modes = mackerel_lcdc_modes,
380                 .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
381                 .interface_type         = RGB24,
382                 .clock_divider          = 3,
383                 .flags                  = 0,
384                 .panel_cfg = {
385                         .width          = 152,
386                         .height         = 91,
387                 },
388                 .meram_cfg = &lcd_meram_cfg,
389         }
390 };
391
392 static struct resource lcdc_resources[] = {
393         [0] = {
394                 .name   = "LCDC",
395                 .start  = 0xfe940000,
396                 .end    = 0xfe943fff,
397                 .flags  = IORESOURCE_MEM,
398         },
399         [1] = {
400                 .start  = intcs_evt2irq(0x580),
401                 .flags  = IORESOURCE_IRQ,
402         },
403 };
404
405 static struct platform_device lcdc_device = {
406         .name           = "sh_mobile_lcdc_fb",
407         .num_resources  = ARRAY_SIZE(lcdc_resources),
408         .resource       = lcdc_resources,
409         .dev    = {
410                 .platform_data  = &lcdc_info,
411                 .coherent_dma_mask = DMA_BIT_MASK(32),
412         },
413 };
414
415 static struct gpio_backlight_platform_data gpio_backlight_data = {
416         .fbdev = &lcdc_device.dev,
417         .gpio = 31,
418         .def_value = 1,
419         .name = "backlight",
420 };
421
422 static struct platform_device gpio_backlight_device = {
423         .name = "gpio-backlight",
424         .dev = {
425                 .platform_data = &gpio_backlight_data,
426         },
427 };
428
429 /* HDMI */
430 static struct sh_mobile_hdmi_info hdmi_info = {
431         .flags          = HDMI_SND_SRC_SPDIF,
432 };
433
434 static struct resource hdmi_resources[] = {
435         [0] = {
436                 .name   = "HDMI",
437                 .start  = 0xe6be0000,
438                 .end    = 0xe6be00ff,
439                 .flags  = IORESOURCE_MEM,
440         },
441         [1] = {
442                 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
443                 .start  = evt2irq(0x17e0),
444                 .flags  = IORESOURCE_IRQ,
445         },
446 };
447
448 static struct platform_device hdmi_device = {
449         .name           = "sh-mobile-hdmi",
450         .num_resources  = ARRAY_SIZE(hdmi_resources),
451         .resource       = hdmi_resources,
452         .id             = -1,
453         .dev    = {
454                 .platform_data  = &hdmi_info,
455         },
456 };
457
458 static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
459         .icb[0] = {
460                 .meram_size     = 0x100,
461         },
462         .icb[1] = {
463                 .meram_size     = 0x100,
464         },
465 };
466
467 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
468         .meram_dev = &mackerel_meram_info,
469         .clock_source = LCDC_CLK_EXTERNAL,
470         .ch[0] = {
471                 .chan = LCDC_CHAN_MAINLCD,
472                 .fourcc = V4L2_PIX_FMT_RGB565,
473                 .interface_type = RGB24,
474                 .clock_divider = 1,
475                 .flags = LCDC_FLAGS_DWPOL,
476                 .meram_cfg = &hdmi_meram_cfg,
477                 .tx_dev = &hdmi_device,
478         }
479 };
480
481 static struct resource hdmi_lcdc_resources[] = {
482         [0] = {
483                 .name   = "LCDC1",
484                 .start  = 0xfe944000,
485                 .end    = 0xfe947fff,
486                 .flags  = IORESOURCE_MEM,
487         },
488         [1] = {
489                 .start  = intcs_evt2irq(0x1780),
490                 .flags  = IORESOURCE_IRQ,
491         },
492 };
493
494 static struct platform_device hdmi_lcdc_device = {
495         .name           = "sh_mobile_lcdc_fb",
496         .num_resources  = ARRAY_SIZE(hdmi_lcdc_resources),
497         .resource       = hdmi_lcdc_resources,
498         .id             = 1,
499         .dev    = {
500                 .platform_data  = &hdmi_lcdc_info,
501                 .coherent_dma_mask = DMA_BIT_MASK(32),
502         },
503 };
504
505 static struct asoc_simple_card_info fsi2_hdmi_info = {
506         .name           = "HDMI",
507         .card           = "FSI2B-HDMI",
508         .codec          = "sh-mobile-hdmi",
509         .platform       = "sh_fsi2",
510         .daifmt         = SND_SOC_DAIFMT_CBS_CFS,
511         .cpu_dai = {
512                 .name   = "fsib-dai",
513         },
514         .codec_dai = {
515                 .name   = "sh_mobile_hdmi-hifi",
516         },
517 };
518
519 static struct platform_device fsi_hdmi_device = {
520         .name   = "asoc-simple-card",
521         .id     = 1,
522         .dev    = {
523                 .platform_data  = &fsi2_hdmi_info,
524         },
525 };
526
527 static void __init hdmi_init_pm_clock(void)
528 {
529         struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
530         int ret;
531         long rate;
532
533         if (IS_ERR(hdmi_ick)) {
534                 ret = PTR_ERR(hdmi_ick);
535                 pr_err("Cannot get HDMI ICK: %d\n", ret);
536                 goto out;
537         }
538
539         ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
540         if (ret < 0) {
541                 pr_err("Cannot set PLLC2 parent: %d, %d users\n",
542                        ret, sh7372_pllc2_clk.usecount);
543                 goto out;
544         }
545
546         pr_debug("PLLC2 initial frequency %lu\n",
547                  clk_get_rate(&sh7372_pllc2_clk));
548
549         rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
550         if (rate <= 0) {
551                 pr_err("Cannot get suitable rate: %ld\n", rate);
552                 ret = -EINVAL;
553                 goto out;
554         }
555
556         ret = clk_set_rate(&sh7372_pllc2_clk, rate);
557         if (ret < 0) {
558                 pr_err("Cannot set rate %ld: %d\n", rate, ret);
559                 goto out;
560         }
561
562         pr_debug("PLLC2 set frequency %lu\n", rate);
563
564         ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
565         if (ret < 0)
566                 pr_err("Cannot set HDMI parent: %d\n", ret);
567
568 out:
569         if (!IS_ERR(hdmi_ick))
570                 clk_put(hdmi_ick);
571 }
572
573 /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
574  *
575  * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
576  * but on this particular board IRQ7 is already used by
577  * the touch screen. This leaves us with software polling.
578  */
579 #define USBHS0_POLL_INTERVAL (HZ * 5)
580
581 struct usbhs_private {
582         void __iomem *usbphyaddr;
583         void __iomem *usbcrcaddr;
584         struct renesas_usbhs_platform_info info;
585         struct delayed_work work;
586         struct platform_device *pdev;
587 };
588
589 #define usbhs_get_priv(pdev)                            \
590         container_of(renesas_usbhs_get_info(pdev),      \
591                      struct usbhs_private, info)
592
593 #define usbhs_is_connected(priv)                        \
594         (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
595
596 static int usbhs_get_vbus(struct platform_device *pdev)
597 {
598         return usbhs_is_connected(usbhs_get_priv(pdev));
599 }
600
601 static int usbhs_phy_reset(struct platform_device *pdev)
602 {
603         struct usbhs_private *priv = usbhs_get_priv(pdev);
604
605         /* init phy */
606         __raw_writew(0x8a0a, priv->usbcrcaddr);
607
608         return 0;
609 }
610
611 static int usbhs0_get_id(struct platform_device *pdev)
612 {
613         return USBHS_GADGET;
614 }
615
616 static void usbhs0_work_function(struct work_struct *work)
617 {
618         struct usbhs_private *priv = container_of(work, struct usbhs_private,
619                                                   work.work);
620
621         renesas_usbhs_call_notify_hotplug(priv->pdev);
622         schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
623 }
624
625 static int usbhs0_hardware_init(struct platform_device *pdev)
626 {
627         struct usbhs_private *priv = usbhs_get_priv(pdev);
628
629         priv->pdev = pdev;
630         INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
631         schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
632         return 0;
633 }
634
635 static int usbhs0_hardware_exit(struct platform_device *pdev)
636 {
637         struct usbhs_private *priv = usbhs_get_priv(pdev);
638
639         cancel_delayed_work_sync(&priv->work);
640
641         return 0;
642 }
643
644 static struct usbhs_private usbhs0_private = {
645         .usbcrcaddr     = IOMEM(0xe605810c),            /* USBCR2 */
646         .info = {
647                 .platform_callback = {
648                         .hardware_init  = usbhs0_hardware_init,
649                         .hardware_exit  = usbhs0_hardware_exit,
650                         .phy_reset      = usbhs_phy_reset,
651                         .get_id         = usbhs0_get_id,
652                         .get_vbus       = usbhs_get_vbus,
653                 },
654                 .driver_param = {
655                         .buswait_bwait  = 4,
656                         .d0_tx_id       = SHDMA_SLAVE_USB0_TX,
657                         .d1_rx_id       = SHDMA_SLAVE_USB0_RX,
658                 },
659         },
660 };
661
662 static struct resource usbhs0_resources[] = {
663         [0] = {
664                 .name   = "USBHS0",
665                 .start  = 0xe6890000,
666                 .end    = 0xe68900e6 - 1,
667                 .flags  = IORESOURCE_MEM,
668         },
669         [1] = {
670                 .start  = evt2irq(0x1ca0) /* USB0_USB0I0 */,
671                 .flags  = IORESOURCE_IRQ,
672         },
673 };
674
675 static struct platform_device usbhs0_device = {
676         .name   = "renesas_usbhs",
677         .id     = 0,
678         .dev = {
679                 .platform_data          = &usbhs0_private.info,
680         },
681         .num_resources  = ARRAY_SIZE(usbhs0_resources),
682         .resource       = usbhs0_resources,
683 };
684
685 /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
686  *
687  * Use J30 to select between Host and Function. This setting
688  * can however not be detected by software. Hotplug of USBHS1
689  * is provided via IRQ8.
690  *
691  * Current USB1 works as "USB Host".
692  *  - set J30 "short"
693  *
694  * If you want to use it as "USB gadget",
695  *  - J30 "open"
696  *  - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
697  *  - add .get_vbus = usbhs_get_vbus in usbhs1_private
698  *  - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
699  */
700 #define IRQ8 evt2irq(0x0300)
701 #define USB_PHY_MODE            (1 << 4)
702 #define USB_PHY_INT_EN          ((1 << 3) | (1 << 2))
703 #define USB_PHY_ON              (1 << 1)
704 #define USB_PHY_OFF             (1 << 0)
705 #define USB_PHY_INT_CLR         (USB_PHY_ON | USB_PHY_OFF)
706
707 static irqreturn_t usbhs1_interrupt(int irq, void *data)
708 {
709         struct platform_device *pdev = data;
710         struct usbhs_private *priv = usbhs_get_priv(pdev);
711
712         dev_dbg(&pdev->dev, "%s\n", __func__);
713
714         renesas_usbhs_call_notify_hotplug(pdev);
715
716         /* clear status */
717         __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
718                      priv->usbphyaddr);
719
720         return IRQ_HANDLED;
721 }
722
723 static int usbhs1_hardware_init(struct platform_device *pdev)
724 {
725         struct usbhs_private *priv = usbhs_get_priv(pdev);
726         int ret;
727
728         /* clear interrupt status */
729         __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
730
731         ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
732                           dev_name(&pdev->dev), pdev);
733         if (ret) {
734                 dev_err(&pdev->dev, "request_irq err\n");
735                 return ret;
736         }
737
738         /* enable USB phy interrupt */
739         __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
740
741         return 0;
742 }
743
744 static int usbhs1_hardware_exit(struct platform_device *pdev)
745 {
746         struct usbhs_private *priv = usbhs_get_priv(pdev);
747
748         /* clear interrupt status */
749         __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
750
751         free_irq(IRQ8, pdev);
752
753         return 0;
754 }
755
756 static int usbhs1_get_id(struct platform_device *pdev)
757 {
758         return USBHS_HOST;
759 }
760
761 static u32 usbhs1_pipe_cfg[] = {
762         USB_ENDPOINT_XFER_CONTROL,
763         USB_ENDPOINT_XFER_ISOC,
764         USB_ENDPOINT_XFER_ISOC,
765         USB_ENDPOINT_XFER_BULK,
766         USB_ENDPOINT_XFER_BULK,
767         USB_ENDPOINT_XFER_BULK,
768         USB_ENDPOINT_XFER_INT,
769         USB_ENDPOINT_XFER_INT,
770         USB_ENDPOINT_XFER_INT,
771         USB_ENDPOINT_XFER_BULK,
772         USB_ENDPOINT_XFER_BULK,
773         USB_ENDPOINT_XFER_BULK,
774         USB_ENDPOINT_XFER_BULK,
775         USB_ENDPOINT_XFER_BULK,
776         USB_ENDPOINT_XFER_BULK,
777         USB_ENDPOINT_XFER_BULK,
778 };
779
780 static struct usbhs_private usbhs1_private = {
781         .usbphyaddr     = IOMEM(0xe60581e2),    /* USBPHY1INTAP */
782         .usbcrcaddr     = IOMEM(0xe6058130),    /* USBCR4 */
783         .info = {
784                 .platform_callback = {
785                         .hardware_init  = usbhs1_hardware_init,
786                         .hardware_exit  = usbhs1_hardware_exit,
787                         .get_id         = usbhs1_get_id,
788                         .phy_reset      = usbhs_phy_reset,
789                 },
790                 .driver_param = {
791                         .buswait_bwait  = 4,
792                         .has_otg        = 1,
793                         .pipe_type      = usbhs1_pipe_cfg,
794                         .pipe_size      = ARRAY_SIZE(usbhs1_pipe_cfg),
795                         .d0_tx_id       = SHDMA_SLAVE_USB1_TX,
796                         .d1_rx_id       = SHDMA_SLAVE_USB1_RX,
797                 },
798         },
799 };
800
801 static struct resource usbhs1_resources[] = {
802         [0] = {
803                 .name   = "USBHS1",
804                 .start  = 0xe68b0000,
805                 .end    = 0xe68b00e6 - 1,
806                 .flags  = IORESOURCE_MEM,
807         },
808         [1] = {
809                 .start  = evt2irq(0x1ce0) /* USB1_USB1I0 */,
810                 .flags  = IORESOURCE_IRQ,
811         },
812 };
813
814 static struct platform_device usbhs1_device = {
815         .name   = "renesas_usbhs",
816         .id     = 1,
817         .dev = {
818                 .platform_data          = &usbhs1_private.info,
819                 .dma_mask               = &usbhs1_device.dev.coherent_dma_mask,
820                 .coherent_dma_mask      = DMA_BIT_MASK(32),
821         },
822         .num_resources  = ARRAY_SIZE(usbhs1_resources),
823         .resource       = usbhs1_resources,
824 };
825
826 /* LED */
827 static struct gpio_led mackerel_leds[] = {
828         {
829                 .name           = "led0",
830                 .gpio           = 0,
831                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
832         },
833         {
834                 .name           = "led1",
835                 .gpio           = 1,
836                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
837         },
838         {
839                 .name           = "led2",
840                 .gpio           = 2,
841                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
842         },
843         {
844                 .name           = "led3",
845                 .gpio           = 159,
846                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
847         }
848 };
849
850 static struct gpio_led_platform_data mackerel_leds_pdata = {
851         .leds = mackerel_leds,
852         .num_leds = ARRAY_SIZE(mackerel_leds),
853 };
854
855 static struct platform_device leds_device = {
856         .name = "leds-gpio",
857         .id = 0,
858         .dev = {
859                 .platform_data  = &mackerel_leds_pdata,
860         },
861 };
862
863 /* FSI */
864 #define IRQ_FSI evt2irq(0x1840)
865 static struct sh_fsi_platform_info fsi_info = {
866         .port_a = {
867                 .tx_id = SHDMA_SLAVE_FSIA_TX,
868                 .rx_id = SHDMA_SLAVE_FSIA_RX,
869         },
870         .port_b = {
871                 .flags = SH_FSI_CLK_CPG |
872                          SH_FSI_FMT_SPDIF,
873         }
874 };
875
876 static struct resource fsi_resources[] = {
877         [0] = {
878                 /* we need 0xFE1F0000 to access DMA
879                  * instead of 0xFE3C0000 */
880                 .name   = "FSI",
881                 .start  = 0xFE1F0000,
882                 .end    = 0xFE1F0400 - 1,
883                 .flags  = IORESOURCE_MEM,
884         },
885         [1] = {
886                 .start  = IRQ_FSI,
887                 .flags  = IORESOURCE_IRQ,
888         },
889 };
890
891 static struct platform_device fsi_device = {
892         .name           = "sh_fsi2",
893         .id             = -1,
894         .num_resources  = ARRAY_SIZE(fsi_resources),
895         .resource       = fsi_resources,
896         .dev    = {
897                 .platform_data  = &fsi_info,
898         },
899 };
900
901 static struct asoc_simple_card_info fsi2_ak4643_info = {
902         .name           = "AK4643",
903         .card           = "FSI2A-AK4643",
904         .codec          = "ak4642-codec.0-0013",
905         .platform       = "sh_fsi2",
906         .daifmt         = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
907         .cpu_dai = {
908                 .name   = "fsia-dai",
909         },
910         .codec_dai = {
911                 .name   = "ak4642-hifi",
912                 .sysclk = 11289600,
913         },
914 };
915
916 static struct platform_device fsi_ak4643_device = {
917         .name   = "asoc-simple-card",
918         .dev    = {
919                 .platform_data  = &fsi2_ak4643_info,
920         },
921 };
922
923 /* FLCTL */
924 static struct mtd_partition nand_partition_info[] = {
925         {
926                 .name   = "system",
927                 .offset = 0,
928                 .size   = 128 * 1024 * 1024,
929         },
930         {
931                 .name   = "userdata",
932                 .offset = MTDPART_OFS_APPEND,
933                 .size   = 256 * 1024 * 1024,
934         },
935         {
936                 .name   = "cache",
937                 .offset = MTDPART_OFS_APPEND,
938                 .size   = 128 * 1024 * 1024,
939         },
940 };
941
942 static struct resource nand_flash_resources[] = {
943         [0] = {
944                 .start  = 0xe6a30000,
945                 .end    = 0xe6a3009b,
946                 .flags  = IORESOURCE_MEM,
947         },
948         [1] = {
949                 .start  = evt2irq(0x0d80), /* flstei: status error irq */
950                 .flags  = IORESOURCE_IRQ,
951         },
952 };
953
954 static struct sh_flctl_platform_data nand_flash_data = {
955         .parts          = nand_partition_info,
956         .nr_parts       = ARRAY_SIZE(nand_partition_info),
957         .flcmncr_val    = CLK_16B_12L_4H | TYPESEL_SET
958                         | SHBUSSEL | SEL_16BIT | SNAND_E,
959         .use_holden     = 1,
960 };
961
962 static struct platform_device nand_flash_device = {
963         .name           = "sh_flctl",
964         .resource       = nand_flash_resources,
965         .num_resources  = ARRAY_SIZE(nand_flash_resources),
966         .dev            = {
967                 .platform_data = &nand_flash_data,
968         },
969 };
970
971 /* SDHI0 */
972 static struct sh_mobile_sdhi_info sdhi0_info = {
973         .dma_slave_tx   = SHDMA_SLAVE_SDHI0_TX,
974         .dma_slave_rx   = SHDMA_SLAVE_SDHI0_RX,
975         .tmio_flags     = TMIO_MMC_USE_GPIO_CD,
976         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
977         .cd_gpio        = 172,
978 };
979
980 static struct resource sdhi0_resources[] = {
981         {
982                 .name   = "SDHI0",
983                 .start  = 0xe6850000,
984                 .end    = 0xe68500ff,
985                 .flags  = IORESOURCE_MEM,
986         }, {
987                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
988                 .start  = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
989                 .flags  = IORESOURCE_IRQ,
990         }, {
991                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
992                 .start  = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
993                 .flags  = IORESOURCE_IRQ,
994         },
995 };
996
997 static struct platform_device sdhi0_device = {
998         .name           = "sh_mobile_sdhi",
999         .num_resources  = ARRAY_SIZE(sdhi0_resources),
1000         .resource       = sdhi0_resources,
1001         .id             = 0,
1002         .dev    = {
1003                 .platform_data  = &sdhi0_info,
1004         },
1005 };
1006
1007 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1008 /* SDHI1 */
1009
1010 /* GPIO 41 can trigger IRQ8, but it is used by USBHS1, we have to poll */
1011 static struct sh_mobile_sdhi_info sdhi1_info = {
1012         .dma_slave_tx   = SHDMA_SLAVE_SDHI1_TX,
1013         .dma_slave_rx   = SHDMA_SLAVE_SDHI1_RX,
1014         .tmio_flags     = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1015         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1016                           MMC_CAP_NEEDS_POLL,
1017         .cd_gpio        = 41,
1018 };
1019
1020 static struct resource sdhi1_resources[] = {
1021         {
1022                 .name   = "SDHI1",
1023                 .start  = 0xe6860000,
1024                 .end    = 0xe68600ff,
1025                 .flags  = IORESOURCE_MEM,
1026         }, {
1027                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
1028                 .start  = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
1029                 .flags  = IORESOURCE_IRQ,
1030         }, {
1031                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
1032                 .start  = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
1033                 .flags  = IORESOURCE_IRQ,
1034         },
1035 };
1036
1037 static struct platform_device sdhi1_device = {
1038         .name           = "sh_mobile_sdhi",
1039         .num_resources  = ARRAY_SIZE(sdhi1_resources),
1040         .resource       = sdhi1_resources,
1041         .id             = 1,
1042         .dev    = {
1043                 .platform_data  = &sdhi1_info,
1044         },
1045 };
1046 #endif
1047
1048 /* SDHI2 */
1049
1050 /*
1051  * The card detect pin of the top SD/MMC slot (CN23) is active low and is
1052  * connected to GPIO SCIFB_SCK of SH7372 (GPIO 162).
1053  */
1054 static struct sh_mobile_sdhi_info sdhi2_info = {
1055         .dma_slave_tx   = SHDMA_SLAVE_SDHI2_TX,
1056         .dma_slave_rx   = SHDMA_SLAVE_SDHI2_RX,
1057         .tmio_flags     = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
1058         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1059                           MMC_CAP_NEEDS_POLL,
1060         .cd_gpio        = 162,
1061 };
1062
1063 static struct resource sdhi2_resources[] = {
1064         {
1065                 .name   = "SDHI2",
1066                 .start  = 0xe6870000,
1067                 .end    = 0xe68700ff,
1068                 .flags  = IORESOURCE_MEM,
1069         }, {
1070                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
1071                 .start  = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
1072                 .flags  = IORESOURCE_IRQ,
1073         }, {
1074                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
1075                 .start  = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
1076                 .flags  = IORESOURCE_IRQ,
1077         },
1078 };
1079
1080 static struct platform_device sdhi2_device = {
1081         .name   = "sh_mobile_sdhi",
1082         .num_resources  = ARRAY_SIZE(sdhi2_resources),
1083         .resource       = sdhi2_resources,
1084         .id             = 2,
1085         .dev    = {
1086                 .platform_data  = &sdhi2_info,
1087         },
1088 };
1089
1090 /* SH_MMCIF */
1091 #if IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1092 static struct resource sh_mmcif_resources[] = {
1093         [0] = {
1094                 .name   = "MMCIF",
1095                 .start  = 0xE6BD0000,
1096                 .end    = 0xE6BD00FF,
1097                 .flags  = IORESOURCE_MEM,
1098         },
1099         [1] = {
1100                 /* MMC ERR */
1101                 .start  = evt2irq(0x1ac0),
1102                 .flags  = IORESOURCE_IRQ,
1103         },
1104         [2] = {
1105                 /* MMC NOR */
1106                 .start  = evt2irq(0x1ae0),
1107                 .flags  = IORESOURCE_IRQ,
1108         },
1109 };
1110
1111 static struct sh_mmcif_plat_data sh_mmcif_plat = {
1112         .sup_pclk       = 0,
1113         .caps           = MMC_CAP_4_BIT_DATA |
1114                           MMC_CAP_8_BIT_DATA |
1115                           MMC_CAP_NEEDS_POLL,
1116         .use_cd_gpio    = true,
1117         /* card detect pin for SD/MMC slot (CN7) */
1118         .cd_gpio        = 41,
1119         .slave_id_tx    = SHDMA_SLAVE_MMCIF_TX,
1120         .slave_id_rx    = SHDMA_SLAVE_MMCIF_RX,
1121 };
1122
1123 static struct platform_device sh_mmcif_device = {
1124         .name           = "sh_mmcif",
1125         .id             = 0,
1126         .dev            = {
1127                 .dma_mask               = NULL,
1128                 .coherent_dma_mask      = 0xffffffff,
1129                 .platform_data          = &sh_mmcif_plat,
1130         },
1131         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
1132         .resource       = sh_mmcif_resources,
1133 };
1134 #endif
1135
1136 static int mackerel_camera_add(struct soc_camera_device *icd);
1137 static void mackerel_camera_del(struct soc_camera_device *icd);
1138
1139 static int camera_set_capture(struct soc_camera_platform_info *info,
1140                               int enable)
1141 {
1142         return 0; /* camera sensor always enabled */
1143 }
1144
1145 static struct soc_camera_platform_info camera_info = {
1146         .format_name = "UYVY",
1147         .format_depth = 16,
1148         .format = {
1149                 .code = V4L2_MBUS_FMT_UYVY8_2X8,
1150                 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1151                 .field = V4L2_FIELD_NONE,
1152                 .width = 640,
1153                 .height = 480,
1154         },
1155         .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1156         V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1157         V4L2_MBUS_DATA_ACTIVE_HIGH,
1158         .mbus_type = V4L2_MBUS_PARALLEL,
1159         .set_capture = camera_set_capture,
1160 };
1161
1162 static struct soc_camera_link camera_link = {
1163         .bus_id         = 0,
1164         .add_device     = mackerel_camera_add,
1165         .del_device     = mackerel_camera_del,
1166         .module_name    = "soc_camera_platform",
1167         .priv           = &camera_info,
1168 };
1169
1170 static struct platform_device *camera_device;
1171
1172 static void mackerel_camera_release(struct device *dev)
1173 {
1174         soc_camera_platform_release(&camera_device);
1175 }
1176
1177 static int mackerel_camera_add(struct soc_camera_device *icd)
1178 {
1179         return soc_camera_platform_add(icd, &camera_device, &camera_link,
1180                                        mackerel_camera_release, 0);
1181 }
1182
1183 static void mackerel_camera_del(struct soc_camera_device *icd)
1184 {
1185         soc_camera_platform_del(icd, camera_device, &camera_link);
1186 }
1187
1188 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
1189         .flags = SH_CEU_FLAG_USE_8BIT_BUS,
1190         .max_width = 8188,
1191         .max_height = 8188,
1192 };
1193
1194 static struct resource ceu_resources[] = {
1195         [0] = {
1196                 .name   = "CEU",
1197                 .start  = 0xfe910000,
1198                 .end    = 0xfe91009f,
1199                 .flags  = IORESOURCE_MEM,
1200         },
1201         [1] = {
1202                 .start  = intcs_evt2irq(0x880),
1203                 .flags  = IORESOURCE_IRQ,
1204         },
1205         [2] = {
1206                 /* place holder for contiguous memory */
1207         },
1208 };
1209
1210 static struct platform_device ceu_device = {
1211         .name           = "sh_mobile_ceu",
1212         .id             = 0, /* "ceu0" clock */
1213         .num_resources  = ARRAY_SIZE(ceu_resources),
1214         .resource       = ceu_resources,
1215         .dev            = {
1216                 .platform_data          = &sh_mobile_ceu_info,
1217                 .coherent_dma_mask      = 0xffffffff,
1218         },
1219 };
1220
1221 static struct platform_device mackerel_camera = {
1222         .name   = "soc-camera-pdrv",
1223         .id     = 0,
1224         .dev    = {
1225                 .platform_data = &camera_link,
1226         },
1227 };
1228
1229 static struct platform_device *mackerel_devices[] __initdata = {
1230         &nor_flash_device,
1231         &smc911x_device,
1232         &lcdc_device,
1233         &gpio_backlight_device,
1234         &usbhs0_device,
1235         &usbhs1_device,
1236         &leds_device,
1237         &fsi_device,
1238         &fsi_ak4643_device,
1239         &fsi_hdmi_device,
1240         &nand_flash_device,
1241         &sdhi0_device,
1242 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1243         &sdhi1_device,
1244 #else
1245         &sh_mmcif_device,
1246 #endif
1247         &sdhi2_device,
1248         &ceu_device,
1249         &mackerel_camera,
1250         &hdmi_device,
1251         &hdmi_lcdc_device,
1252         &meram_device,
1253 };
1254
1255 /* Keypad Initialization */
1256 #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
1257 {                                                               \
1258         .type           = ev_type,                              \
1259         .code           = ev_code,                              \
1260         .active_low     = act_low,                              \
1261 }
1262
1263 #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
1264
1265 static struct tca6416_button mackerel_gpio_keys[] = {
1266         KEYPAD_BUTTON_LOW(KEY_HOME),
1267         KEYPAD_BUTTON_LOW(KEY_MENU),
1268         KEYPAD_BUTTON_LOW(KEY_BACK),
1269         KEYPAD_BUTTON_LOW(KEY_POWER),
1270 };
1271
1272 static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
1273         .buttons        = mackerel_gpio_keys,
1274         .nbuttons       = ARRAY_SIZE(mackerel_gpio_keys),
1275         .rep            = 1,
1276         .use_polling    = 0,
1277         .pinmask        = 0x000F,
1278 };
1279
1280 /* I2C */
1281 #define IRQ7 evt2irq(0x02e0)
1282 #define IRQ9 evt2irq(0x0320)
1283
1284 static struct i2c_board_info i2c0_devices[] = {
1285         {
1286                 I2C_BOARD_INFO("ak4643", 0x13),
1287         },
1288         /* Keypad */
1289         {
1290                 I2C_BOARD_INFO("tca6408-keys", 0x20),
1291                 .platform_data = &mackerel_tca6416_keys_info,
1292                 .irq = IRQ9,
1293         },
1294         /* Touchscreen */
1295         {
1296                 I2C_BOARD_INFO("st1232-ts", 0x55),
1297                 .irq = IRQ7,
1298         },
1299 };
1300
1301 #define IRQ21 evt2irq(0x32a0)
1302
1303 static struct i2c_board_info i2c1_devices[] = {
1304         /* Accelerometer */
1305         {
1306                 I2C_BOARD_INFO("adxl34x", 0x53),
1307                 .irq = IRQ21,
1308         },
1309 };
1310
1311 static unsigned long pin_pulldown_conf[] = {
1312         PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_DOWN, 0),
1313 };
1314
1315 static const struct pinctrl_map mackerel_pinctrl_map[] = {
1316         /* ADXL34X */
1317         PIN_MAP_MUX_GROUP_DEFAULT("1-0053", "pfc-sh7372",
1318                                   "intc_irq21", "intc"),
1319         /* CEU */
1320         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1321                                   "ceu_data_0_7", "ceu"),
1322         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1323                                   "ceu_clk_0", "ceu"),
1324         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1325                                   "ceu_sync", "ceu"),
1326         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
1327                                   "ceu_field", "ceu"),
1328         /* FLCTL */
1329         PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1330                                   "flctl_data", "flctl"),
1331         PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1332                                   "flctl_ce0", "flctl"),
1333         PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
1334                                   "flctl_ctrl", "flctl"),
1335         /* FSIA (AK4643) */
1336         PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1337                                   "fsia_sclk_in", "fsia"),
1338         PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1339                                   "fsia_data_in", "fsia"),
1340         PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
1341                                   "fsia_data_out", "fsia"),
1342         /* FSIB (HDMI) */
1343         PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-sh7372",
1344                                   "fsib_mclk_in", "fsib"),
1345         /* HDMI */
1346         PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-sh7372",
1347                                   "hdmi", "hdmi"),
1348         /* LCDC */
1349         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1350                                   "lcd_data24", "lcd"),
1351         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
1352                                   "lcd_sync", "lcd"),
1353         /* SCIFA0 */
1354         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-sh7372",
1355                                   "scifa0_data", "scifa0"),
1356         /* SCIFA2 (GT-720F GPS module) */
1357         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh7372",
1358                                   "scifa2_data", "scifa2"),
1359         /* SDHI0 */
1360         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1361                                   "sdhi0_data4", "sdhi0"),
1362         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1363                                   "sdhi0_ctrl", "sdhi0"),
1364         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1365                                   "sdhi0_wp", "sdhi0"),
1366         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
1367                                   "intc_irq26_1", "intc"),
1368         /* SDHI1 */
1369 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1370         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1371                                   "sdhi1_data4", "sdhi1"),
1372         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
1373                                   "sdhi1_ctrl", "sdhi1"),
1374 #else
1375         /* MMCIF */
1376         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1377                                   "mmc0_data8_0", "mmc0"),
1378         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
1379                                   "mmc0_ctrl_0", "mmc0"),
1380 #endif
1381         /* SDHI2 */
1382         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1383                                   "sdhi2_data4", "sdhi2"),
1384         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
1385                                   "sdhi2_ctrl", "sdhi2"),
1386         /* SMSC911X */
1387         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1388                                   "bsc_cs5a", "bsc"),
1389         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
1390                                   "intc_irq6_0", "intc"),
1391         /* ST1232 */
1392         PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-sh7372",
1393                                   "intc_irq7_0", "intc"),
1394         /* TCA6416 */
1395         PIN_MAP_MUX_GROUP_DEFAULT("0-0020", "pfc-sh7372",
1396                                   "intc_irq9_0", "intc"),
1397         /* USBHS0 */
1398         PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1399                                   "usb0_vbus", "usb0"),
1400         PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
1401                                       "usb0_vbus", pin_pulldown_conf),
1402         /* USBHS1 */
1403         PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1404                                   "usb1_vbus", "usb1"),
1405         PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1406                                       "usb1_vbus", pin_pulldown_conf),
1407         PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
1408                                   "usb1_otg_id_0", "usb1"),
1409 };
1410
1411 #define GPIO_PORT9CR    IOMEM(0xE6051009)
1412 #define GPIO_PORT10CR   IOMEM(0xE605100A)
1413 #define SRCR4           IOMEM(0xe61580bc)
1414 #define USCCR1          IOMEM(0xE6058144)
1415 static void __init mackerel_init(void)
1416 {
1417         struct pm_domain_device domain_devices[] = {
1418                 { "A4LC", &lcdc_device, },
1419                 { "A4LC", &hdmi_lcdc_device, },
1420                 { "A4LC", &meram_device, },
1421                 { "A4MP", &fsi_device, },
1422                 { "A3SP", &usbhs0_device, },
1423                 { "A3SP", &usbhs1_device, },
1424                 { "A3SP", &nand_flash_device, },
1425                 { "A3SP", &sdhi0_device, },
1426 #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
1427                 { "A3SP", &sdhi1_device, },
1428 #else
1429                 { "A3SP", &sh_mmcif_device, },
1430 #endif
1431                 { "A3SP", &sdhi2_device, },
1432                 { "A4R", &ceu_device, },
1433         };
1434         u32 srcr4;
1435         struct clk *clk;
1436
1437         regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
1438                                      ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
1439         regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
1440                                      ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
1441         regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
1442
1443         /* External clock source */
1444         clk_set_rate(&sh7372_dv_clki_clk, 27000000);
1445
1446         pinctrl_register_mappings(mackerel_pinctrl_map,
1447                                   ARRAY_SIZE(mackerel_pinctrl_map));
1448         sh7372_pinmux_init();
1449
1450         gpio_request_one(151, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
1451
1452         /* FSI2 port A (ak4643) */
1453         gpio_request_one(161, GPIOF_OUT_INIT_LOW, NULL); /* slave */
1454
1455         gpio_request(9,  NULL);
1456         gpio_request(10, NULL);
1457         gpio_direction_none(GPIO_PORT9CR);  /* FSIAOBT needs no direction */
1458         gpio_direction_none(GPIO_PORT10CR); /* FSIAOLR needs no direction */
1459
1460         intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
1461
1462         /* FSI2 port B (HDMI) */
1463         __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1464
1465         /* set SPU2 clock to 119.6 MHz */
1466         clk = clk_get(NULL, "spu_clk");
1467         if (!IS_ERR(clk)) {
1468                 clk_set_rate(clk, clk_round_rate(clk, 119600000));
1469                 clk_put(clk);
1470         }
1471
1472         /* Keypad */
1473         irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
1474
1475         /* Touchscreen */
1476         irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
1477
1478         /* Accelerometer */
1479         irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
1480
1481         /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1482         srcr4 = __raw_readl(SRCR4);
1483         __raw_writel(srcr4 | (1 << 13), SRCR4);
1484         udelay(50);
1485         __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1486
1487         i2c_register_board_info(0, i2c0_devices,
1488                                 ARRAY_SIZE(i2c0_devices));
1489         i2c_register_board_info(1, i2c1_devices,
1490                                 ARRAY_SIZE(i2c1_devices));
1491
1492         sh7372_add_standard_devices();
1493
1494         platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
1495
1496         rmobile_add_devices_to_domains(domain_devices,
1497                                        ARRAY_SIZE(domain_devices));
1498
1499         hdmi_init_pm_clock();
1500         sh7372_pm_init();
1501         pm_clk_add(&fsi_device.dev, "spu2");
1502         pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
1503 }
1504
1505 static const char *mackerel_boards_compat_dt[] __initdata = {
1506         "renesas,mackerel",
1507         NULL,
1508 };
1509
1510 DT_MACHINE_START(MACKEREL_DT, "mackerel")
1511         .map_io         = sh7372_map_io,
1512         .init_early     = sh7372_add_early_devices,
1513         .init_irq       = sh7372_init_irq,
1514         .handle_irq     = shmobile_handle_irq_intc,
1515         .init_machine   = mackerel_init,
1516         .init_late      = sh7372_pm_init_late,
1517         .init_time      = sh7372_earlytimer_init,
1518         .dt_compat  = mackerel_boards_compat_dt,
1519 MACHINE_END