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