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