Merge branch 'rmobile/fbdev' into rmobile-latest
[pandora-kernel.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/smsc911x.h>
43 #include <linux/sh_intc.h>
44 #include <linux/tca6416_keypad.h>
45 #include <linux/usb/r8a66597.h>
46 #include <linux/usb/renesas_usbhs.h>
47
48 #include <video/sh_mobile_hdmi.h>
49 #include <video/sh_mobile_lcdc.h>
50 #include <media/sh_mobile_ceu.h>
51 #include <media/soc_camera.h>
52 #include <media/soc_camera_platform.h>
53 #include <sound/sh_fsi.h>
54
55 #include <mach/common.h>
56 #include <mach/sh7372.h>
57
58 #include <asm/mach/arch.h>
59 #include <asm/mach/time.h>
60 #include <asm/mach/map.h>
61 #include <asm/mach-types.h>
62
63 /*
64  * Address      Interface               BusWidth        note
65  * ------------------------------------------------------------------
66  * 0x0000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = ON
67  * 0x0800_0000  user area               -
68  * 0x1000_0000  NOR Flash ROM (MCP)     16bit           SW7 : bit1 = OFF
69  * 0x1400_0000  Ether (LAN9220)         16bit
70  * 0x1600_0000  user area               -               cannot use with NAND
71  * 0x1800_0000  user area               -
72  * 0x1A00_0000  -
73  * 0x4000_0000  LPDDR2-SDRAM (POP)      32bit
74  */
75
76 /*
77  * CPU mode
78  *
79  * SW4                                     | Boot Area| Master   | Remarks
80  *  1  | 2   | 3   | 4   | 5   | 6   | 8   |          | Processor|
81  * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
82  * ON  | ON  | OFF | ON  | ON  | OFF | OFF | External | System   | External ROM
83  * ON  | ON  | ON  | ON  | ON  | OFF | OFF | External | System   | ROM Debug
84  * ON  | ON  | X   | ON  | OFF | OFF | OFF | Built-in | System   | ROM Debug
85  * X   | OFF | X   | X   | X   | X   | OFF | Built-in | System   | MaskROM
86  * OFF | X   | X   | X   | X   | X   | OFF | Built-in | System   | MaskROM
87  * X   | X   | X   | OFF | X   | X   | OFF | Built-in | System   | MaskROM
88  * OFF | ON  | OFF | X   | X   | OFF | ON  | External | System   | Standalone
89  * ON  | OFF | OFF | X   | X   | OFF | ON  | External | Realtime | Standalone
90 */
91
92 /*
93  * NOR Flash ROM
94  *
95  *  SW1  |     SW2    | SW7  | NOR Flash ROM
96  *  bit1 | bit1  bit2 | bit1 | Memory allocation
97  * ------+------------+------+------------------
98  *  OFF  | ON     OFF | ON   |    Area 0
99  *  OFF  | ON     OFF | OFF  |    Area 4
100  */
101
102 /*
103  * SMSC 9220
104  *
105  *  SW1         SMSC 9220
106  * -----------------------
107  *  ON          access disable
108  *  OFF         access enable
109  */
110
111 /*
112  * NAND Flash ROM
113  *
114  *  SW1  |     SW2    | SW7  | NAND Flash ROM
115  *  bit1 | bit1  bit2 | bit2 | Memory allocation
116  * ------+------------+------+------------------
117  *  OFF  | ON     OFF | ON   |    FCE 0
118  *  OFF  | ON     OFF | OFF  |    FCE 1
119  */
120
121 /*
122  * External interrupt pin settings
123  *
124  * IRQX  | pin setting        | device             | level
125  * ------+--------------------+--------------------+-------
126  * IRQ0  | ICR1A.IRQ0SA=0010  | SDHI2 card detect  | Low
127  * IRQ6  | ICR1A.IRQ6SA=0011  | Ether(LAN9220)     | High
128  * IRQ7  | ICR1A.IRQ7SA=0010  | LCD Tuch Panel     | Low
129  * IRQ8  | ICR2A.IRQ8SA=0010  | MMC/SD card detect | Low
130  * IRQ9  | ICR2A.IRQ9SA=0010  | KEY(TCA6408)       | Low
131  * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345)    | High
132  * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975)     | High
133  */
134
135 /*
136  * USB
137  *
138  * USB0 : CN22 : Function
139  * USB1 : CN31 : Function/Host *1
140  *
141  * J30 (for CN31) *1
142  * ----------+---------------+-------------
143  * 1-2 short | VBUS 5V       | Host
144  * open      | external VBUS | Function
145  *
146  * *1
147  * CN31 is used as
148  * CONFIG_USB_R8A66597_HCD      Host
149  * CONFIG_USB_RENESAS_USBHS     Function
150  *
151  * CAUTION
152  *
153  * renesas_usbhs driver can use external interrupt mode
154  * (which come from USB-PHY) or autonomy mode (it use own interrupt)
155  * for detecting connection/disconnection when Function.
156  * USB will be power OFF while it has been disconnecting
157  * if external interrupt mode, and it is always power ON if autonomy mode,
158  *
159  * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
160  * because Touchscreen is using IRQ7-PORT40.
161  * It is impossible to use IRQ7 demux on this board.
162  *
163  * We can use external interrupt mode USB-Function on "USB1".
164  * USB1 can become Host by r8a66597, and become Function by renesas_usbhs.
165  * But don't select both drivers in same time.
166  * These uses same IRQ number for request_irq(), and aren't supporting
167  * IRQF_SHARD / IORESOURCE_IRQ_SHAREABLE.
168  *
169  * Actually these are old/new version of USB driver.
170  * This mean its register will be broken if it supports SHARD IRQ,
171  */
172
173 /*
174  * SDHI0 (CN12)
175  *
176  * SW56 : OFF
177  *
178  */
179
180 /* MMC /SDHI1 (CN7)
181  *
182  * I/O voltage : 1.8v
183  *
184  * Power voltage : 1.8v or 3.3v
185  *  J22 : select power voltage *1
186  *      1-2 pin : 1.8v
187  *      2-3 pin : 3.3v
188  *
189  * *1
190  * Please change J22 depends the card to be used.
191  * MMC's OCR field set to support either voltage for the card inserted.
192  *
193  *      SW1     |       SW33
194  *              | bit1 | bit2 | bit3 | bit4
195  * -------------+------+------+------+-------
196  * MMC0   OFF   |  OFF |   X  |  ON  |  X       (Use MMCIF)
197  * SDHI1  OFF   |  ON  |   X  |  OFF |  X       (Use MFD_SH_MOBILE_SDHI)
198  *
199  */
200
201 /*
202  * SDHI2 (CN23)
203  *
204  * microSD card sloct
205  *
206  */
207
208 /*
209  * FIXME !!
210  *
211  * gpio_no_direction
212  * gpio_pull_down
213  * are quick_hack.
214  *
215  * current gpio frame work doesn't have
216  * the method to control only pull up/down/free.
217  * this function should be replaced by correct gpio function
218  */
219 static void __init gpio_no_direction(u32 addr)
220 {
221         __raw_writeb(0x00, addr);
222 }
223
224 static void __init gpio_pull_down(u32 addr)
225 {
226         u8 data = __raw_readb(addr);
227
228         data &= 0x0F;
229         data |= 0xA0;
230
231         __raw_writeb(data, addr);
232 }
233
234 /* MTD */
235 static struct mtd_partition nor_flash_partitions[] = {
236         {
237                 .name           = "loader",
238                 .offset         = 0x00000000,
239                 .size           = 512 * 1024,
240                 .mask_flags     = MTD_WRITEABLE,
241         },
242         {
243                 .name           = "bootenv",
244                 .offset         = MTDPART_OFS_APPEND,
245                 .size           = 512 * 1024,
246                 .mask_flags     = MTD_WRITEABLE,
247         },
248         {
249                 .name           = "kernel_ro",
250                 .offset         = MTDPART_OFS_APPEND,
251                 .size           = 8 * 1024 * 1024,
252                 .mask_flags     = MTD_WRITEABLE,
253         },
254         {
255                 .name           = "kernel",
256                 .offset         = MTDPART_OFS_APPEND,
257                 .size           = 8 * 1024 * 1024,
258         },
259         {
260                 .name           = "data",
261                 .offset         = MTDPART_OFS_APPEND,
262                 .size           = MTDPART_SIZ_FULL,
263         },
264 };
265
266 static struct physmap_flash_data nor_flash_data = {
267         .width          = 2,
268         .parts          = nor_flash_partitions,
269         .nr_parts       = ARRAY_SIZE(nor_flash_partitions),
270 };
271
272 static struct resource nor_flash_resources[] = {
273         [0]     = {
274                 .start  = 0x00000000,
275                 .end    = 0x08000000 - 1,
276                 .flags  = IORESOURCE_MEM,
277         }
278 };
279
280 static struct platform_device nor_flash_device = {
281         .name           = "physmap-flash",
282         .dev            = {
283                 .platform_data  = &nor_flash_data,
284         },
285         .num_resources  = ARRAY_SIZE(nor_flash_resources),
286         .resource       = nor_flash_resources,
287 };
288
289 /* SMSC */
290 static struct resource smc911x_resources[] = {
291         {
292                 .start  = 0x14000000,
293                 .end    = 0x16000000 - 1,
294                 .flags  = IORESOURCE_MEM,
295         }, {
296                 .start  = evt2irq(0x02c0) /* IRQ6A */,
297                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
298         },
299 };
300
301 static struct smsc911x_platform_config smsc911x_info = {
302         .flags          = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
303         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
304         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
305 };
306
307 static struct platform_device smc911x_device = {
308         .name           = "smsc911x",
309         .id             = -1,
310         .num_resources  = ARRAY_SIZE(smc911x_resources),
311         .resource       = smc911x_resources,
312         .dev            = {
313                 .platform_data = &smsc911x_info,
314         },
315 };
316
317 /* MERAM */
318 static struct sh_mobile_meram_info mackerel_meram_info = {
319         .addr_mode      = SH_MOBILE_MERAM_MODE1,
320 };
321
322 static struct resource meram_resources[] = {
323         [0] = {
324                 .name   = "MERAM",
325                 .start  = 0xe8000000,
326                 .end    = 0xe81fffff,
327                 .flags  = IORESOURCE_MEM,
328         },
329 };
330
331 static struct platform_device meram_device = {
332         .name           = "sh_mobile_meram",
333         .id             = 0,
334         .num_resources  = ARRAY_SIZE(meram_resources),
335         .resource       = meram_resources,
336         .dev            = {
337                 .platform_data = &mackerel_meram_info,
338         },
339 };
340
341 /* LCDC */
342 static struct fb_videomode mackerel_lcdc_modes[] = {
343         {
344                 .name           = "WVGA Panel",
345                 .xres           = 800,
346                 .yres           = 480,
347                 .left_margin    = 220,
348                 .right_margin   = 110,
349                 .hsync_len      = 70,
350                 .upper_margin   = 20,
351                 .lower_margin   = 5,
352                 .vsync_len      = 5,
353                 .sync           = 0,
354         },
355 };
356
357 static int mackerel_set_brightness(void *board_data, int brightness)
358 {
359         gpio_set_value(GPIO_PORT31, brightness);
360
361         return 0;
362 }
363
364 static int mackerel_get_brightness(void *board_data)
365 {
366         return gpio_get_value(GPIO_PORT31);
367 }
368
369 static struct sh_mobile_meram_cfg lcd_meram_cfg = {
370         .icb[0] = {
371                 .marker_icb     = 28,
372                 .cache_icb      = 24,
373                 .meram_offset   = 0x0,
374                 .meram_size     = 0x40,
375         },
376         .icb[1] = {
377                 .marker_icb     = 29,
378                 .cache_icb      = 25,
379                 .meram_offset   = 0x40,
380                 .meram_size     = 0x40,
381         },
382 };
383
384 static struct sh_mobile_lcdc_info lcdc_info = {
385         .meram_dev = &mackerel_meram_info,
386         .clock_source = LCDC_CLK_BUS,
387         .ch[0] = {
388                 .chan = LCDC_CHAN_MAINLCD,
389                 .bpp = 16,
390                 .lcd_cfg = mackerel_lcdc_modes,
391                 .num_cfg = ARRAY_SIZE(mackerel_lcdc_modes),
392                 .interface_type         = RGB24,
393                 .clock_divider          = 3,
394                 .flags                  = 0,
395                 .lcd_size_cfg.width     = 152,
396                 .lcd_size_cfg.height    = 91,
397                 .board_cfg = {
398                         .set_brightness = mackerel_set_brightness,
399                         .get_brightness = mackerel_get_brightness,
400                 },
401                 .bl_info = {
402                         .name = "sh_mobile_lcdc_bl",
403                         .max_brightness = 1,
404                 },
405                 .meram_cfg = &lcd_meram_cfg,
406         }
407 };
408
409 static struct resource lcdc_resources[] = {
410         [0] = {
411                 .name   = "LCDC",
412                 .start  = 0xfe940000,
413                 .end    = 0xfe943fff,
414                 .flags  = IORESOURCE_MEM,
415         },
416         [1] = {
417                 .start  = intcs_evt2irq(0x580),
418                 .flags  = IORESOURCE_IRQ,
419         },
420 };
421
422 static struct platform_device lcdc_device = {
423         .name           = "sh_mobile_lcdc_fb",
424         .num_resources  = ARRAY_SIZE(lcdc_resources),
425         .resource       = lcdc_resources,
426         .dev    = {
427                 .platform_data  = &lcdc_info,
428                 .coherent_dma_mask = ~0,
429         },
430 };
431
432 static struct sh_mobile_meram_cfg hdmi_meram_cfg = {
433         .icb[0] = {
434                 .marker_icb     = 30,
435                 .cache_icb      = 26,
436                 .meram_offset   = 0x80,
437                 .meram_size     = 0x100,
438         },
439         .icb[1] = {
440                 .marker_icb     = 31,
441                 .cache_icb      = 27,
442                 .meram_offset   = 0x180,
443                 .meram_size     = 0x100,
444         },
445 };
446 /* HDMI */
447 static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
448         .meram_dev = &mackerel_meram_info,
449         .clock_source = LCDC_CLK_EXTERNAL,
450         .ch[0] = {
451                 .chan = LCDC_CHAN_MAINLCD,
452                 .bpp = 16,
453                 .interface_type = RGB24,
454                 .clock_divider = 1,
455                 .flags = LCDC_FLAGS_DWPOL,
456                 .meram_cfg = &hdmi_meram_cfg,
457         }
458 };
459
460 static struct resource hdmi_lcdc_resources[] = {
461         [0] = {
462                 .name   = "LCDC1",
463                 .start  = 0xfe944000,
464                 .end    = 0xfe947fff,
465                 .flags  = IORESOURCE_MEM,
466         },
467         [1] = {
468                 .start  = intcs_evt2irq(0x1780),
469                 .flags  = IORESOURCE_IRQ,
470         },
471 };
472
473 static struct platform_device hdmi_lcdc_device = {
474         .name           = "sh_mobile_lcdc_fb",
475         .num_resources  = ARRAY_SIZE(hdmi_lcdc_resources),
476         .resource       = hdmi_lcdc_resources,
477         .id             = 1,
478         .dev    = {
479                 .platform_data  = &hdmi_lcdc_info,
480                 .coherent_dma_mask = ~0,
481         },
482 };
483
484 static struct sh_mobile_hdmi_info hdmi_info = {
485         .lcd_chan       = &hdmi_lcdc_info.ch[0],
486         .lcd_dev        = &hdmi_lcdc_device.dev,
487         .flags          = HDMI_SND_SRC_SPDIF,
488 };
489
490 static struct resource hdmi_resources[] = {
491         [0] = {
492                 .name   = "HDMI",
493                 .start  = 0xe6be0000,
494                 .end    = 0xe6be00ff,
495                 .flags  = IORESOURCE_MEM,
496         },
497         [1] = {
498                 /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
499                 .start  = evt2irq(0x17e0),
500                 .flags  = IORESOURCE_IRQ,
501         },
502 };
503
504 static struct platform_device hdmi_device = {
505         .name           = "sh-mobile-hdmi",
506         .num_resources  = ARRAY_SIZE(hdmi_resources),
507         .resource       = hdmi_resources,
508         .id             = -1,
509         .dev    = {
510                 .platform_data  = &hdmi_info,
511         },
512 };
513
514 static struct platform_device fsi_hdmi_device = {
515         .name           = "sh_fsi2_b_hdmi",
516 };
517
518 static void __init hdmi_init_pm_clock(void)
519 {
520         struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
521         int ret;
522         long rate;
523
524         if (IS_ERR(hdmi_ick)) {
525                 ret = PTR_ERR(hdmi_ick);
526                 pr_err("Cannot get HDMI ICK: %d\n", ret);
527                 goto out;
528         }
529
530         ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
531         if (ret < 0) {
532                 pr_err("Cannot set PLLC2 parent: %d, %d users\n",
533                        ret, sh7372_pllc2_clk.usecount);
534                 goto out;
535         }
536
537         pr_debug("PLLC2 initial frequency %lu\n",
538                  clk_get_rate(&sh7372_pllc2_clk));
539
540         rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
541         if (rate < 0) {
542                 pr_err("Cannot get suitable rate: %ld\n", rate);
543                 ret = rate;
544                 goto out;
545         }
546
547         ret = clk_set_rate(&sh7372_pllc2_clk, rate);
548         if (ret < 0) {
549                 pr_err("Cannot set rate %ld: %d\n", rate, ret);
550                 goto out;
551         }
552
553         pr_debug("PLLC2 set frequency %lu\n", rate);
554
555         ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
556         if (ret < 0)
557                 pr_err("Cannot set HDMI parent: %d\n", ret);
558
559 out:
560         if (!IS_ERR(hdmi_ick))
561                 clk_put(hdmi_ick);
562 }
563
564 /* USB1 (Host) */
565 static void usb1_host_port_power(int port, int power)
566 {
567         if (!power) /* only power-on is supported for now */
568                 return;
569
570         /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
571         __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
572 }
573
574 static struct r8a66597_platdata usb1_host_data = {
575         .on_chip        = 1,
576         .port_power     = usb1_host_port_power,
577 };
578
579 static struct resource usb1_host_resources[] = {
580         [0] = {
581                 .name   = "USBHS",
582                 .start  = 0xE68B0000,
583                 .end    = 0xE68B00E6 - 1,
584                 .flags  = IORESOURCE_MEM,
585         },
586         [1] = {
587                 .start  = evt2irq(0x1ce0) /* USB1_USB1I0 */,
588                 .flags  = IORESOURCE_IRQ,
589         },
590 };
591
592 static struct platform_device usb1_host_device = {
593         .name   = "r8a66597_hcd",
594         .id     = 1,
595         .dev = {
596                 .dma_mask               = NULL,         /*  not use dma */
597                 .coherent_dma_mask      = 0xffffffff,
598                 .platform_data          = &usb1_host_data,
599         },
600         .num_resources  = ARRAY_SIZE(usb1_host_resources),
601         .resource       = usb1_host_resources,
602 };
603
604 /* USB1 (Function) */
605 #define USB_PHY_MODE            (1 << 4)
606 #define USB_PHY_INT_EN          ((1 << 3) | (1 << 2))
607 #define USB_PHY_ON              (1 << 1)
608 #define USB_PHY_OFF             (1 << 0)
609 #define USB_PHY_INT_CLR         (USB_PHY_ON | USB_PHY_OFF)
610
611 struct usbhs_private {
612         unsigned int irq;
613         unsigned int usbphyaddr;
614         unsigned int usbcrcaddr;
615         struct renesas_usbhs_platform_info info;
616 };
617
618 #define usbhs_get_priv(pdev)                            \
619         container_of(renesas_usbhs_get_info(pdev),      \
620                      struct usbhs_private, info)
621
622 #define usbhs_is_connected(priv)                        \
623         (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
624
625 static int usbhs1_get_id(struct platform_device *pdev)
626 {
627         return USBHS_GADGET;
628 }
629
630 static int usbhs1_get_vbus(struct platform_device *pdev)
631 {
632         return usbhs_is_connected(usbhs_get_priv(pdev));
633 }
634
635 static irqreturn_t usbhs1_interrupt(int irq, void *data)
636 {
637         struct platform_device *pdev = data;
638         struct usbhs_private *priv = usbhs_get_priv(pdev);
639
640         dev_dbg(&pdev->dev, "%s\n", __func__);
641
642         renesas_usbhs_call_notify_hotplug(pdev);
643
644         /* clear status */
645         __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
646                      priv->usbphyaddr);
647
648         return IRQ_HANDLED;
649 }
650
651 static int usbhs1_hardware_init(struct platform_device *pdev)
652 {
653         struct usbhs_private *priv = usbhs_get_priv(pdev);
654         int ret;
655
656         irq_set_irq_type(priv->irq, IRQ_TYPE_LEVEL_HIGH);
657
658         /* clear interrupt status */
659         __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
660
661         ret = request_irq(priv->irq, usbhs1_interrupt, 0,
662                           dev_name(&pdev->dev), pdev);
663         if (ret) {
664                 dev_err(&pdev->dev, "request_irq err\n");
665                 return ret;
666         }
667
668         /* enable USB phy interrupt */
669         __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
670
671         return 0;
672 }
673
674 static void usbhs1_hardware_exit(struct platform_device *pdev)
675 {
676         struct usbhs_private *priv = usbhs_get_priv(pdev);
677
678         /* clear interrupt status */
679         __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
680
681         free_irq(priv->irq, pdev);
682 }
683
684 static void usbhs1_phy_reset(struct platform_device *pdev)
685 {
686         struct usbhs_private *priv = usbhs_get_priv(pdev);
687
688         /* init phy */
689         __raw_writew(0x8a0a, priv->usbcrcaddr);
690 }
691
692 static u32 usbhs1_pipe_cfg[] = {
693         USB_ENDPOINT_XFER_CONTROL,
694         USB_ENDPOINT_XFER_ISOC,
695         USB_ENDPOINT_XFER_ISOC,
696         USB_ENDPOINT_XFER_BULK,
697         USB_ENDPOINT_XFER_BULK,
698         USB_ENDPOINT_XFER_BULK,
699         USB_ENDPOINT_XFER_INT,
700         USB_ENDPOINT_XFER_INT,
701         USB_ENDPOINT_XFER_INT,
702         USB_ENDPOINT_XFER_BULK,
703         USB_ENDPOINT_XFER_BULK,
704         USB_ENDPOINT_XFER_BULK,
705         USB_ENDPOINT_XFER_BULK,
706         USB_ENDPOINT_XFER_BULK,
707         USB_ENDPOINT_XFER_BULK,
708         USB_ENDPOINT_XFER_BULK,
709 };
710
711 static struct usbhs_private usbhs1_private = {
712         .irq            = evt2irq(0x0300),      /* IRQ8 */
713         .usbphyaddr     = 0xE60581E2,           /* USBPHY1INTAP */
714         .usbcrcaddr     = 0xE6058130,           /* USBCR4 */
715         .info = {
716                 .platform_callback = {
717                         .hardware_init  = usbhs1_hardware_init,
718                         .hardware_exit  = usbhs1_hardware_exit,
719                         .phy_reset      = usbhs1_phy_reset,
720                         .get_id         = usbhs1_get_id,
721                         .get_vbus       = usbhs1_get_vbus,
722                 },
723                 .driver_param = {
724                         .buswait_bwait  = 4,
725                         .pipe_type      = usbhs1_pipe_cfg,
726                         .pipe_size      = ARRAY_SIZE(usbhs1_pipe_cfg),
727                 },
728         },
729 };
730
731 static struct resource usbhs1_resources[] = {
732         [0] = {
733                 .name   = "USBHS",
734                 .start  = 0xE68B0000,
735                 .end    = 0xE68B00E6 - 1,
736                 .flags  = IORESOURCE_MEM,
737         },
738         [1] = {
739                 .start  = evt2irq(0x1ce0) /* USB1_USB1I0 */,
740                 .flags  = IORESOURCE_IRQ,
741         },
742 };
743
744 static struct platform_device usbhs1_device = {
745         .name   = "renesas_usbhs",
746         .id     = 1,
747         .dev = {
748                 .platform_data          = &usbhs1_private.info,
749         },
750         .num_resources  = ARRAY_SIZE(usbhs1_resources),
751         .resource       = usbhs1_resources,
752 };
753
754
755 /* LED */
756 static struct gpio_led mackerel_leds[] = {
757         {
758                 .name           = "led0",
759                 .gpio           = GPIO_PORT0,
760                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
761         },
762         {
763                 .name           = "led1",
764                 .gpio           = GPIO_PORT1,
765                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
766         },
767         {
768                 .name           = "led2",
769                 .gpio           = GPIO_PORT2,
770                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
771         },
772         {
773                 .name           = "led3",
774                 .gpio           = GPIO_PORT159,
775                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
776         }
777 };
778
779 static struct gpio_led_platform_data mackerel_leds_pdata = {
780         .leds = mackerel_leds,
781         .num_leds = ARRAY_SIZE(mackerel_leds),
782 };
783
784 static struct platform_device leds_device = {
785         .name = "leds-gpio",
786         .id = 0,
787         .dev = {
788                 .platform_data  = &mackerel_leds_pdata,
789         },
790 };
791
792 /* FSI */
793 #define IRQ_FSI evt2irq(0x1840)
794 static int __fsi_set_round_rate(struct clk *clk, long rate, int enable)
795 {
796         int ret;
797
798         if (rate <= 0)
799                 return 0;
800
801         if (!enable) {
802                 clk_disable(clk);
803                 return 0;
804         }
805
806         ret = clk_set_rate(clk, clk_round_rate(clk, rate));
807         if (ret < 0)
808                 return ret;
809
810         return clk_enable(clk);
811 }
812
813 static int fsi_set_rate(struct device *dev, int is_porta, int rate, int enable)
814 {
815         struct clk *fsib_clk;
816         struct clk *fdiv_clk = &sh7372_fsidivb_clk;
817         long fsib_rate = 0;
818         long fdiv_rate = 0;
819         int ackmd_bpfmd;
820         int ret;
821
822         /* FSIA is slave mode. nothing to do here */
823         if (is_porta)
824                 return 0;
825
826         /* clock start */
827         switch (rate) {
828         case 44100:
829                 fsib_rate       = rate * 256;
830                 ackmd_bpfmd     = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
831                 break;
832         case 48000:
833                 fsib_rate       = 85428000; /* around 48kHz x 256 x 7 */
834                 fdiv_rate       = rate * 256;
835                 ackmd_bpfmd     = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
836                 break;
837         default:
838                 pr_err("unsupported rate in FSI2 port B\n");
839                 return -EINVAL;
840         }
841
842         /* FSI B setting */
843         fsib_clk = clk_get(dev, "ickb");
844         if (IS_ERR(fsib_clk))
845                 return -EIO;
846
847         /* fsib */
848         ret = __fsi_set_round_rate(fsib_clk, fsib_rate, enable);
849         if (ret < 0)
850                 goto fsi_set_rate_end;
851
852         /* FSI DIV */
853         ret = __fsi_set_round_rate(fdiv_clk, fdiv_rate, enable);
854         if (ret < 0) {
855                 /* disable FSI B */
856                 if (enable)
857                         __fsi_set_round_rate(fsib_clk, fsib_rate, 0);
858                 goto fsi_set_rate_end;
859         }
860
861         ret = ackmd_bpfmd;
862
863 fsi_set_rate_end:
864         clk_put(fsib_clk);
865         return ret;
866 }
867
868 static struct sh_fsi_platform_info fsi_info = {
869         .porta_flags =  SH_FSI_BRS_INV,
870
871         .portb_flags =  SH_FSI_BRS_INV  |
872                         SH_FSI_BRM_INV  |
873                         SH_FSI_LRS_INV  |
874                         SH_FSI_FMT_SPDIF,
875
876         .set_rate = fsi_set_rate,
877 };
878
879 static struct resource fsi_resources[] = {
880         [0] = {
881                 .name   = "FSI",
882                 .start  = 0xFE3C0000,
883                 .end    = 0xFE3C0400 - 1,
884                 .flags  = IORESOURCE_MEM,
885         },
886         [1] = {
887                 .start  = IRQ_FSI,
888                 .flags  = IORESOURCE_IRQ,
889         },
890 };
891
892 static struct platform_device fsi_device = {
893         .name           = "sh_fsi2",
894         .id             = -1,
895         .num_resources  = ARRAY_SIZE(fsi_resources),
896         .resource       = fsi_resources,
897         .dev    = {
898                 .platform_data  = &fsi_info,
899         },
900 };
901
902 static struct platform_device fsi_ak4643_device = {
903         .name           = "sh_fsi2_a_ak4643",
904 };
905
906 /*
907  * The card detect pin of the top SD/MMC slot (CN7) is active low and is
908  * connected to GPIO A22 of SH7372 (GPIO_PORT41).
909  */
910 static int slot_cn7_get_cd(struct platform_device *pdev)
911 {
912         return !gpio_get_value(GPIO_PORT41);
913 }
914
915 /* SDHI0 */
916 static struct sh_mobile_sdhi_info sdhi0_info = {
917         .dma_slave_tx   = SHDMA_SLAVE_SDHI0_TX,
918         .dma_slave_rx   = SHDMA_SLAVE_SDHI0_RX,
919         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
920 };
921
922 static struct resource sdhi0_resources[] = {
923         [0] = {
924                 .name   = "SDHI0",
925                 .start  = 0xe6850000,
926                 .end    = 0xe68500ff,
927                 .flags  = IORESOURCE_MEM,
928         },
929         [1] = {
930                 .start  = evt2irq(0x0e00) /* SDHI0_SDHI0I0 */,
931                 .flags  = IORESOURCE_IRQ,
932         },
933         [2] = {
934                 .start  = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
935                 .flags  = IORESOURCE_IRQ,
936         },
937         [3] = {
938                 .start  = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
939                 .flags  = IORESOURCE_IRQ,
940         },
941 };
942
943 static struct platform_device sdhi0_device = {
944         .name           = "sh_mobile_sdhi",
945         .num_resources  = ARRAY_SIZE(sdhi0_resources),
946         .resource       = sdhi0_resources,
947         .id             = 0,
948         .dev    = {
949                 .platform_data  = &sdhi0_info,
950         },
951 };
952
953 #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
954 /* SDHI1 */
955 static struct sh_mobile_sdhi_info sdhi1_info = {
956         .dma_slave_tx   = SHDMA_SLAVE_SDHI1_TX,
957         .dma_slave_rx   = SHDMA_SLAVE_SDHI1_RX,
958         .tmio_ocr_mask  = MMC_VDD_165_195,
959         .tmio_flags     = TMIO_MMC_WRPROTECT_DISABLE,
960         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
961                           MMC_CAP_NEEDS_POLL,
962         .get_cd         = slot_cn7_get_cd,
963 };
964
965 static struct resource sdhi1_resources[] = {
966         [0] = {
967                 .name   = "SDHI1",
968                 .start  = 0xe6860000,
969                 .end    = 0xe68600ff,
970                 .flags  = IORESOURCE_MEM,
971         },
972         [1] = {
973                 .start  = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */
974                 .flags  = IORESOURCE_IRQ,
975         },
976         [2] = {
977                 .start  = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
978                 .flags  = IORESOURCE_IRQ,
979         },
980         [3] = {
981                 .start  = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
982                 .flags  = IORESOURCE_IRQ,
983         },
984 };
985
986 static struct platform_device sdhi1_device = {
987         .name           = "sh_mobile_sdhi",
988         .num_resources  = ARRAY_SIZE(sdhi1_resources),
989         .resource       = sdhi1_resources,
990         .id             = 1,
991         .dev    = {
992                 .platform_data  = &sdhi1_info,
993         },
994 };
995 #endif
996
997 /*
998  * The card detect pin of the top SD/MMC slot (CN23) is active low and is
999  * connected to GPIO SCIFB_SCK of SH7372 (GPIO_PORT162).
1000  */
1001 static int slot_cn23_get_cd(struct platform_device *pdev)
1002 {
1003         return !gpio_get_value(GPIO_PORT162);
1004 }
1005
1006 /* SDHI2 */
1007 static struct sh_mobile_sdhi_info sdhi2_info = {
1008         .dma_slave_tx   = SHDMA_SLAVE_SDHI2_TX,
1009         .dma_slave_rx   = SHDMA_SLAVE_SDHI2_RX,
1010         .tmio_flags     = TMIO_MMC_WRPROTECT_DISABLE,
1011         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
1012                           MMC_CAP_NEEDS_POLL,
1013         .get_cd         = slot_cn23_get_cd,
1014 };
1015
1016 static struct resource sdhi2_resources[] = {
1017         [0] = {
1018                 .name   = "SDHI2",
1019                 .start  = 0xe6870000,
1020                 .end    = 0xe68700ff,
1021                 .flags  = IORESOURCE_MEM,
1022         },
1023         [1] = {
1024                 .start  = evt2irq(0x1200), /* SDHI2_SDHI2I0 */
1025                 .flags  = IORESOURCE_IRQ,
1026         },
1027         [2] = {
1028                 .start  = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
1029                 .flags  = IORESOURCE_IRQ,
1030         },
1031         [3] = {
1032                 .start  = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
1033                 .flags  = IORESOURCE_IRQ,
1034         },
1035 };
1036
1037 static struct platform_device sdhi2_device = {
1038         .name   = "sh_mobile_sdhi",
1039         .num_resources  = ARRAY_SIZE(sdhi2_resources),
1040         .resource       = sdhi2_resources,
1041         .id             = 2,
1042         .dev    = {
1043                 .platform_data  = &sdhi2_info,
1044         },
1045 };
1046
1047 /* SH_MMCIF */
1048 static struct resource sh_mmcif_resources[] = {
1049         [0] = {
1050                 .name   = "MMCIF",
1051                 .start  = 0xE6BD0000,
1052                 .end    = 0xE6BD00FF,
1053                 .flags  = IORESOURCE_MEM,
1054         },
1055         [1] = {
1056                 /* MMC ERR */
1057                 .start  = evt2irq(0x1ac0),
1058                 .flags  = IORESOURCE_IRQ,
1059         },
1060         [2] = {
1061                 /* MMC NOR */
1062                 .start  = evt2irq(0x1ae0),
1063                 .flags  = IORESOURCE_IRQ,
1064         },
1065 };
1066
1067 static struct sh_mmcif_dma sh_mmcif_dma = {
1068         .chan_priv_rx   = {
1069                 .slave_id       = SHDMA_SLAVE_MMCIF_RX,
1070         },
1071         .chan_priv_tx   = {
1072                 .slave_id       = SHDMA_SLAVE_MMCIF_TX,
1073         },
1074 };
1075
1076 static struct sh_mmcif_plat_data sh_mmcif_plat = {
1077         .sup_pclk       = 0,
1078         .ocr            = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
1079         .caps           = MMC_CAP_4_BIT_DATA |
1080                           MMC_CAP_8_BIT_DATA |
1081                           MMC_CAP_NEEDS_POLL,
1082         .get_cd         = slot_cn7_get_cd,
1083         .dma            = &sh_mmcif_dma,
1084 };
1085
1086 static struct platform_device sh_mmcif_device = {
1087         .name           = "sh_mmcif",
1088         .id             = 0,
1089         .dev            = {
1090                 .dma_mask               = NULL,
1091                 .coherent_dma_mask      = 0xffffffff,
1092                 .platform_data          = &sh_mmcif_plat,
1093         },
1094         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
1095         .resource       = sh_mmcif_resources,
1096 };
1097
1098
1099 static int mackerel_camera_add(struct soc_camera_link *icl, struct device *dev);
1100 static void mackerel_camera_del(struct soc_camera_link *icl);
1101
1102 static int camera_set_capture(struct soc_camera_platform_info *info,
1103                               int enable)
1104 {
1105         return 0; /* camera sensor always enabled */
1106 }
1107
1108 static struct soc_camera_platform_info camera_info = {
1109         .format_name = "UYVY",
1110         .format_depth = 16,
1111         .format = {
1112                 .code = V4L2_MBUS_FMT_UYVY8_2X8,
1113                 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1114                 .field = V4L2_FIELD_NONE,
1115                 .width = 640,
1116                 .height = 480,
1117         },
1118         .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
1119         SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
1120         SOCAM_DATA_ACTIVE_HIGH,
1121         .set_capture = camera_set_capture,
1122 };
1123
1124 static struct soc_camera_link camera_link = {
1125         .bus_id         = 0,
1126         .add_device     = mackerel_camera_add,
1127         .del_device     = mackerel_camera_del,
1128         .module_name    = "soc_camera_platform",
1129         .priv           = &camera_info,
1130 };
1131
1132 static struct platform_device *camera_device;
1133
1134 static void mackerel_camera_release(struct device *dev)
1135 {
1136         soc_camera_platform_release(&camera_device);
1137 }
1138
1139 static int mackerel_camera_add(struct soc_camera_link *icl,
1140                                struct device *dev)
1141 {
1142         return soc_camera_platform_add(icl, dev, &camera_device, &camera_link,
1143                                        mackerel_camera_release, 0);
1144 }
1145
1146 static void mackerel_camera_del(struct soc_camera_link *icl)
1147 {
1148         soc_camera_platform_del(icl, camera_device, &camera_link);
1149 }
1150
1151 static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
1152         .flags = SH_CEU_FLAG_USE_8BIT_BUS,
1153 };
1154
1155 static struct resource ceu_resources[] = {
1156         [0] = {
1157                 .name   = "CEU",
1158                 .start  = 0xfe910000,
1159                 .end    = 0xfe91009f,
1160                 .flags  = IORESOURCE_MEM,
1161         },
1162         [1] = {
1163                 .start  = intcs_evt2irq(0x880),
1164                 .flags  = IORESOURCE_IRQ,
1165         },
1166         [2] = {
1167                 /* place holder for contiguous memory */
1168         },
1169 };
1170
1171 static struct platform_device ceu_device = {
1172         .name           = "sh_mobile_ceu",
1173         .id             = 0, /* "ceu0" clock */
1174         .num_resources  = ARRAY_SIZE(ceu_resources),
1175         .resource       = ceu_resources,
1176         .dev            = {
1177                 .platform_data          = &sh_mobile_ceu_info,
1178                 .coherent_dma_mask      = 0xffffffff,
1179         },
1180 };
1181
1182 static struct platform_device mackerel_camera = {
1183         .name   = "soc-camera-pdrv",
1184         .id     = 0,
1185         .dev    = {
1186                 .platform_data = &camera_link,
1187         },
1188 };
1189
1190 static struct platform_device *mackerel_devices[] __initdata = {
1191         &nor_flash_device,
1192         &smc911x_device,
1193         &lcdc_device,
1194         &usb1_host_device,
1195         &usbhs1_device,
1196         &leds_device,
1197         &fsi_device,
1198         &fsi_ak4643_device,
1199         &fsi_hdmi_device,
1200         &sdhi0_device,
1201 #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
1202         &sdhi1_device,
1203 #endif
1204         &sdhi2_device,
1205         &sh_mmcif_device,
1206         &ceu_device,
1207         &mackerel_camera,
1208         &hdmi_lcdc_device,
1209         &hdmi_device,
1210         &meram_device,
1211 };
1212
1213 /* Keypad Initialization */
1214 #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
1215 {                                                               \
1216         .type           = ev_type,                              \
1217         .code           = ev_code,                              \
1218         .active_low     = act_low,                              \
1219 }
1220
1221 #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
1222
1223 static struct tca6416_button mackerel_gpio_keys[] = {
1224         KEYPAD_BUTTON_LOW(KEY_HOME),
1225         KEYPAD_BUTTON_LOW(KEY_MENU),
1226         KEYPAD_BUTTON_LOW(KEY_BACK),
1227         KEYPAD_BUTTON_LOW(KEY_POWER),
1228 };
1229
1230 static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
1231         .buttons        = mackerel_gpio_keys,
1232         .nbuttons       = ARRAY_SIZE(mackerel_gpio_keys),
1233         .rep            = 1,
1234         .use_polling    = 0,
1235         .pinmask        = 0x000F,
1236 };
1237
1238 /* I2C */
1239 #define IRQ7 evt2irq(0x02e0)
1240 #define IRQ9 evt2irq(0x0320)
1241
1242 static struct i2c_board_info i2c0_devices[] = {
1243         {
1244                 I2C_BOARD_INFO("ak4643", 0x13),
1245         },
1246         /* Keypad */
1247         {
1248                 I2C_BOARD_INFO("tca6408-keys", 0x20),
1249                 .platform_data = &mackerel_tca6416_keys_info,
1250                 .irq = IRQ9,
1251         },
1252         /* Touchscreen */
1253         {
1254                 I2C_BOARD_INFO("st1232-ts", 0x55),
1255                 .irq = IRQ7,
1256         },
1257 };
1258
1259 #define IRQ21 evt2irq(0x32a0)
1260
1261 static struct i2c_board_info i2c1_devices[] = {
1262         /* Accelerometer */
1263         {
1264                 I2C_BOARD_INFO("adxl34x", 0x53),
1265                 .irq = IRQ21,
1266         },
1267 };
1268
1269 static struct map_desc mackerel_io_desc[] __initdata = {
1270         /* create a 1:1 entity map for 0xe6xxxxxx
1271          * used by CPGA, INTC and PFC.
1272          */
1273         {
1274                 .virtual        = 0xe6000000,
1275                 .pfn            = __phys_to_pfn(0xe6000000),
1276                 .length         = 256 << 20,
1277                 .type           = MT_DEVICE_NONSHARED
1278         },
1279 };
1280
1281 static void __init mackerel_map_io(void)
1282 {
1283         iotable_init(mackerel_io_desc, ARRAY_SIZE(mackerel_io_desc));
1284
1285         /* setup early devices and console here as well */
1286         sh7372_add_early_devices();
1287         shmobile_setup_console();
1288 }
1289
1290 #define GPIO_PORT9CR    0xE6051009
1291 #define GPIO_PORT10CR   0xE605100A
1292 #define GPIO_PORT168CR  0xE60520A8
1293 #define SRCR4           0xe61580bc
1294 #define USCCR1          0xE6058144
1295 static void __init mackerel_init(void)
1296 {
1297         u32 srcr4;
1298         struct clk *clk;
1299
1300         sh7372_pinmux_init();
1301
1302         /* enable SCIFA0 */
1303         gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
1304         gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
1305
1306         /* enable SMSC911X */
1307         gpio_request(GPIO_FN_CS5A,      NULL);
1308         gpio_request(GPIO_FN_IRQ6_39,   NULL);
1309
1310         /* LCDC */
1311         gpio_request(GPIO_FN_LCDD23,   NULL);
1312         gpio_request(GPIO_FN_LCDD22,   NULL);
1313         gpio_request(GPIO_FN_LCDD21,   NULL);
1314         gpio_request(GPIO_FN_LCDD20,   NULL);
1315         gpio_request(GPIO_FN_LCDD19,   NULL);
1316         gpio_request(GPIO_FN_LCDD18,   NULL);
1317         gpio_request(GPIO_FN_LCDD17,   NULL);
1318         gpio_request(GPIO_FN_LCDD16,   NULL);
1319         gpio_request(GPIO_FN_LCDD15,   NULL);
1320         gpio_request(GPIO_FN_LCDD14,   NULL);
1321         gpio_request(GPIO_FN_LCDD13,   NULL);
1322         gpio_request(GPIO_FN_LCDD12,   NULL);
1323         gpio_request(GPIO_FN_LCDD11,   NULL);
1324         gpio_request(GPIO_FN_LCDD10,   NULL);
1325         gpio_request(GPIO_FN_LCDD9,    NULL);
1326         gpio_request(GPIO_FN_LCDD8,    NULL);
1327         gpio_request(GPIO_FN_LCDD7,    NULL);
1328         gpio_request(GPIO_FN_LCDD6,    NULL);
1329         gpio_request(GPIO_FN_LCDD5,    NULL);
1330         gpio_request(GPIO_FN_LCDD4,    NULL);
1331         gpio_request(GPIO_FN_LCDD3,    NULL);
1332         gpio_request(GPIO_FN_LCDD2,    NULL);
1333         gpio_request(GPIO_FN_LCDD1,    NULL);
1334         gpio_request(GPIO_FN_LCDD0,    NULL);
1335         gpio_request(GPIO_FN_LCDDISP,  NULL);
1336         gpio_request(GPIO_FN_LCDDCK,   NULL);
1337
1338         gpio_request(GPIO_PORT31, NULL); /* backlight */
1339         gpio_direction_output(GPIO_PORT31, 0); /* off by default */
1340
1341         gpio_request(GPIO_PORT151, NULL); /* LCDDON */
1342         gpio_direction_output(GPIO_PORT151, 1);
1343
1344         /* USB enable */
1345         gpio_request(GPIO_FN_VBUS0_1,    NULL);
1346         gpio_request(GPIO_FN_IDIN_1_18,  NULL);
1347         gpio_request(GPIO_FN_PWEN_1_115, NULL);
1348         gpio_request(GPIO_FN_OVCN_1_114, NULL);
1349         gpio_request(GPIO_FN_EXTLP_1,    NULL);
1350         gpio_request(GPIO_FN_OVCN2_1,    NULL);
1351         gpio_pull_down(GPIO_PORT168CR);
1352
1353         /* setup USB phy */
1354         __raw_writew(0x8a0a, 0xE6058130);       /* USBCR4 */
1355
1356         /* enable FSI2 port A (ak4643) */
1357         gpio_request(GPIO_FN_FSIAIBT,   NULL);
1358         gpio_request(GPIO_FN_FSIAILR,   NULL);
1359         gpio_request(GPIO_FN_FSIAISLD,  NULL);
1360         gpio_request(GPIO_FN_FSIAOSLD,  NULL);
1361         gpio_request(GPIO_PORT161,      NULL);
1362         gpio_direction_output(GPIO_PORT161, 0); /* slave */
1363
1364         gpio_request(GPIO_PORT9,  NULL);
1365         gpio_request(GPIO_PORT10, NULL);
1366         gpio_no_direction(GPIO_PORT9CR);  /* FSIAOBT needs no direction */
1367         gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
1368
1369         intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
1370
1371         /* setup FSI2 port B (HDMI) */
1372         gpio_request(GPIO_FN_FSIBCK, NULL);
1373         __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
1374
1375         /* set SPU2 clock to 119.6 MHz */
1376         clk = clk_get(NULL, "spu_clk");
1377         if (!IS_ERR(clk)) {
1378                 clk_set_rate(clk, clk_round_rate(clk, 119600000));
1379                 clk_put(clk);
1380         }
1381
1382         /* enable Keypad */
1383         gpio_request(GPIO_FN_IRQ9_42,   NULL);
1384         irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
1385
1386         /* enable Touchscreen */
1387         gpio_request(GPIO_FN_IRQ7_40,   NULL);
1388         irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
1389
1390         /* enable Accelerometer */
1391         gpio_request(GPIO_FN_IRQ21,     NULL);
1392         irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
1393
1394         /* enable SDHI0 */
1395         gpio_request(GPIO_FN_SDHICD0, NULL);
1396         gpio_request(GPIO_FN_SDHIWP0, NULL);
1397         gpio_request(GPIO_FN_SDHICMD0, NULL);
1398         gpio_request(GPIO_FN_SDHICLK0, NULL);
1399         gpio_request(GPIO_FN_SDHID0_3, NULL);
1400         gpio_request(GPIO_FN_SDHID0_2, NULL);
1401         gpio_request(GPIO_FN_SDHID0_1, NULL);
1402         gpio_request(GPIO_FN_SDHID0_0, NULL);
1403
1404 #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
1405         /* enable SDHI1 */
1406         gpio_request(GPIO_FN_SDHICMD1, NULL);
1407         gpio_request(GPIO_FN_SDHICLK1, NULL);
1408         gpio_request(GPIO_FN_SDHID1_3, NULL);
1409         gpio_request(GPIO_FN_SDHID1_2, NULL);
1410         gpio_request(GPIO_FN_SDHID1_1, NULL);
1411         gpio_request(GPIO_FN_SDHID1_0, NULL);
1412 #endif
1413         /* card detect pin for MMC slot (CN7) */
1414         gpio_request(GPIO_PORT41, NULL);
1415         gpio_direction_input(GPIO_PORT41);
1416
1417         /* enable SDHI2 */
1418         gpio_request(GPIO_FN_SDHICMD2, NULL);
1419         gpio_request(GPIO_FN_SDHICLK2, NULL);
1420         gpio_request(GPIO_FN_SDHID2_3, NULL);
1421         gpio_request(GPIO_FN_SDHID2_2, NULL);
1422         gpio_request(GPIO_FN_SDHID2_1, NULL);
1423         gpio_request(GPIO_FN_SDHID2_0, NULL);
1424
1425         /* card detect pin for microSD slot (CN23) */
1426         gpio_request(GPIO_PORT162, NULL);
1427         gpio_direction_input(GPIO_PORT162);
1428
1429         /* MMCIF */
1430         gpio_request(GPIO_FN_MMCD0_0, NULL);
1431         gpio_request(GPIO_FN_MMCD0_1, NULL);
1432         gpio_request(GPIO_FN_MMCD0_2, NULL);
1433         gpio_request(GPIO_FN_MMCD0_3, NULL);
1434         gpio_request(GPIO_FN_MMCD0_4, NULL);
1435         gpio_request(GPIO_FN_MMCD0_5, NULL);
1436         gpio_request(GPIO_FN_MMCD0_6, NULL);
1437         gpio_request(GPIO_FN_MMCD0_7, NULL);
1438         gpio_request(GPIO_FN_MMCCMD0, NULL);
1439         gpio_request(GPIO_FN_MMCCLK0, NULL);
1440
1441         /* enable GPS module (GT-720F) */
1442         gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
1443         gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
1444
1445         /* CEU */
1446         gpio_request(GPIO_FN_VIO_CLK, NULL);
1447         gpio_request(GPIO_FN_VIO_VD, NULL);
1448         gpio_request(GPIO_FN_VIO_HD, NULL);
1449         gpio_request(GPIO_FN_VIO_FIELD, NULL);
1450         gpio_request(GPIO_FN_VIO_CKO, NULL);
1451         gpio_request(GPIO_FN_VIO_D7, NULL);
1452         gpio_request(GPIO_FN_VIO_D6, NULL);
1453         gpio_request(GPIO_FN_VIO_D5, NULL);
1454         gpio_request(GPIO_FN_VIO_D4, NULL);
1455         gpio_request(GPIO_FN_VIO_D3, NULL);
1456         gpio_request(GPIO_FN_VIO_D2, NULL);
1457         gpio_request(GPIO_FN_VIO_D1, NULL);
1458         gpio_request(GPIO_FN_VIO_D0, NULL);
1459
1460         /* HDMI */
1461         gpio_request(GPIO_FN_HDMI_HPD, NULL);
1462         gpio_request(GPIO_FN_HDMI_CEC, NULL);
1463
1464         /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
1465         srcr4 = __raw_readl(SRCR4);
1466         __raw_writel(srcr4 | (1 << 13), SRCR4);
1467         udelay(50);
1468         __raw_writel(srcr4 & ~(1 << 13), SRCR4);
1469
1470         i2c_register_board_info(0, i2c0_devices,
1471                                 ARRAY_SIZE(i2c0_devices));
1472         i2c_register_board_info(1, i2c1_devices,
1473                                 ARRAY_SIZE(i2c1_devices));
1474
1475         sh7372_add_standard_devices();
1476
1477         platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
1478
1479         hdmi_init_pm_clock();
1480         sh7372_pm_init();
1481 }
1482
1483 static void __init mackerel_timer_init(void)
1484 {
1485         sh7372_clock_init();
1486         shmobile_timer.init();
1487
1488         /* External clock source */
1489         clk_set_rate(&sh7372_dv_clki_clk, 27000000);
1490 }
1491
1492 static struct sys_timer mackerel_timer = {
1493         .init           = mackerel_timer_init,
1494 };
1495
1496 MACHINE_START(MACKEREL, "mackerel")
1497         .map_io         = mackerel_map_io,
1498         .init_irq       = sh7372_init_irq,
1499         .handle_irq     = shmobile_handle_irq_intc,
1500         .init_machine   = mackerel_init,
1501         .timer          = &mackerel_timer,
1502 MACHINE_END