Merge tag 'cleanup-for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[cascardo/linux.git] / arch / arm / mach-shmobile / board-kzm9g.c
1 /*
2  * KZM-A9-GT board support
3  *
4  * Copyright (C) 2012   Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #include <linux/delay.h>
21 #include <linux/gpio.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/io.h>
24 #include <linux/irq.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c/pcf857x.h>
27 #include <linux/input.h>
28 #include <linux/irqchip/arm-gic.h>
29 #include <linux/mmc/host.h>
30 #include <linux/mmc/sh_mmcif.h>
31 #include <linux/mmc/sh_mobile_sdhi.h>
32 #include <linux/mfd/as3711.h>
33 #include <linux/mfd/tmio.h>
34 #include <linux/pinctrl/machine.h>
35 #include <linux/pinctrl/pinconf-generic.h>
36 #include <linux/platform_device.h>
37 #include <linux/reboot.h>
38 #include <linux/regulator/fixed.h>
39 #include <linux/regulator/machine.h>
40 #include <linux/smsc911x.h>
41 #include <linux/usb/r8a66597.h>
42 #include <linux/usb/renesas_usbhs.h>
43 #include <linux/videodev2.h>
44
45 #include <sound/sh_fsi.h>
46 #include <sound/simple_card.h>
47 #include <asm/hardware/cache-l2x0.h>
48 #include <asm/mach-types.h>
49 #include <asm/mach/arch.h>
50 #include <video/sh_mobile_lcdc.h>
51
52 #include "common.h"
53 #include "irqs.h"
54 #include "sh73a0.h"
55
56 /*
57  * external GPIO
58  */
59 #define GPIO_PCF8575_BASE       (310)
60 #define GPIO_PCF8575_PORT10     (GPIO_PCF8575_BASE + 8)
61 #define GPIO_PCF8575_PORT11     (GPIO_PCF8575_BASE + 9)
62 #define GPIO_PCF8575_PORT12     (GPIO_PCF8575_BASE + 10)
63 #define GPIO_PCF8575_PORT13     (GPIO_PCF8575_BASE + 11)
64 #define GPIO_PCF8575_PORT14     (GPIO_PCF8575_BASE + 12)
65 #define GPIO_PCF8575_PORT15     (GPIO_PCF8575_BASE + 13)
66 #define GPIO_PCF8575_PORT16     (GPIO_PCF8575_BASE + 14)
67
68 /* Dummy supplies, where voltage doesn't matter */
69 static struct regulator_consumer_supply dummy_supplies[] = {
70         REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
71         REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
72 };
73
74 /*
75  * FSI-AK4648
76  *
77  * this command is required when playback.
78  *
79  * # amixer set "LINEOUT Mixer DACL" on
80  */
81
82 /* SMSC 9221 */
83 static struct resource smsc9221_resources[] = {
84         [0] = {
85                 .start  = 0x10000000, /* CS4 */
86                 .end    = 0x100000ff,
87                 .flags  = IORESOURCE_MEM,
88         },
89         [1] = {
90                 .start  = irq_pin(3), /* IRQ3 */
91                 .flags  = IORESOURCE_IRQ,
92         },
93 };
94
95 static struct smsc911x_platform_config smsc9221_platdata = {
96         .flags          = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
97         .phy_interface  = PHY_INTERFACE_MODE_MII,
98         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
99         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
100 };
101
102 static struct platform_device smsc_device = {
103         .name           = "smsc911x",
104         .dev  = {
105                 .platform_data = &smsc9221_platdata,
106         },
107         .resource       = smsc9221_resources,
108         .num_resources  = ARRAY_SIZE(smsc9221_resources),
109 };
110
111 /* USB external chip */
112 static struct r8a66597_platdata usb_host_data = {
113         .on_chip        = 0,
114         .xtal           = R8A66597_PLATDATA_XTAL_48MHZ,
115 };
116
117 static struct resource usb_resources[] = {
118         [0] = {
119                 .start  = 0x10010000,
120                 .end    = 0x1001ffff - 1,
121                 .flags  = IORESOURCE_MEM,
122         },
123         [1] = {
124                 .start  = irq_pin(1), /* IRQ1 */
125                 .flags  = IORESOURCE_IRQ,
126         },
127 };
128
129 static struct platform_device usb_host_device = {
130         .name   = "r8a66597_hcd",
131         .dev = {
132                 .platform_data          = &usb_host_data,
133                 .dma_mask               = NULL,
134                 .coherent_dma_mask      = 0xffffffff,
135         },
136         .num_resources  = ARRAY_SIZE(usb_resources),
137         .resource       = usb_resources,
138 };
139
140 /* USB Func CN17 */
141 struct usbhs_private {
142         void __iomem *phy;
143         void __iomem *cr2;
144         struct renesas_usbhs_platform_info info;
145 };
146
147 #define IRQ15                   irq_pin(15)
148 #define USB_PHY_MODE            (1 << 4)
149 #define USB_PHY_INT_EN          ((1 << 3) | (1 << 2))
150 #define USB_PHY_ON              (1 << 1)
151 #define USB_PHY_OFF             (1 << 0)
152 #define USB_PHY_INT_CLR         (USB_PHY_ON | USB_PHY_OFF)
153
154 #define usbhs_get_priv(pdev) \
155         container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
156
157 static int usbhs_get_vbus(struct platform_device *pdev)
158 {
159         struct usbhs_private *priv = usbhs_get_priv(pdev);
160
161         return !((1 << 7) & __raw_readw(priv->cr2));
162 }
163
164 static int usbhs_phy_reset(struct platform_device *pdev)
165 {
166         struct usbhs_private *priv = usbhs_get_priv(pdev);
167
168         /* init phy */
169         __raw_writew(0x8a0a, priv->cr2);
170
171         return 0;
172 }
173
174 static int usbhs_get_id(struct platform_device *pdev)
175 {
176         return USBHS_GADGET;
177 }
178
179 static irqreturn_t usbhs_interrupt(int irq, void *data)
180 {
181         struct platform_device *pdev = data;
182         struct usbhs_private *priv = usbhs_get_priv(pdev);
183
184         renesas_usbhs_call_notify_hotplug(pdev);
185
186         /* clear status */
187         __raw_writew(__raw_readw(priv->phy) | USB_PHY_INT_CLR, priv->phy);
188
189         return IRQ_HANDLED;
190 }
191
192 static int usbhs_hardware_init(struct platform_device *pdev)
193 {
194         struct usbhs_private *priv = usbhs_get_priv(pdev);
195         int ret;
196
197         /* clear interrupt status */
198         __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->phy);
199
200         ret = request_irq(IRQ15, usbhs_interrupt, IRQF_TRIGGER_HIGH,
201                           dev_name(&pdev->dev), pdev);
202         if (ret) {
203                 dev_err(&pdev->dev, "request_irq err\n");
204                 return ret;
205         }
206
207         /* enable USB phy interrupt */
208         __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->phy);
209
210         return 0;
211 }
212
213 static int usbhs_hardware_exit(struct platform_device *pdev)
214 {
215         struct usbhs_private *priv = usbhs_get_priv(pdev);
216
217         /* clear interrupt status */
218         __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->phy);
219
220         free_irq(IRQ15, pdev);
221
222         return 0;
223 }
224
225 static u32 usbhs_pipe_cfg[] = {
226         USB_ENDPOINT_XFER_CONTROL,
227         USB_ENDPOINT_XFER_ISOC,
228         USB_ENDPOINT_XFER_ISOC,
229         USB_ENDPOINT_XFER_BULK,
230         USB_ENDPOINT_XFER_BULK,
231         USB_ENDPOINT_XFER_BULK,
232         USB_ENDPOINT_XFER_INT,
233         USB_ENDPOINT_XFER_INT,
234         USB_ENDPOINT_XFER_INT,
235         USB_ENDPOINT_XFER_BULK,
236         USB_ENDPOINT_XFER_BULK,
237         USB_ENDPOINT_XFER_BULK,
238         USB_ENDPOINT_XFER_BULK,
239         USB_ENDPOINT_XFER_BULK,
240         USB_ENDPOINT_XFER_BULK,
241         USB_ENDPOINT_XFER_BULK,
242 };
243
244 static struct usbhs_private usbhs_private = {
245         .phy    = IOMEM(0xe60781e0),            /* USBPHYINT */
246         .cr2    = IOMEM(0xe605810c),            /* USBCR2 */
247         .info = {
248                 .platform_callback = {
249                         .hardware_init  = usbhs_hardware_init,
250                         .hardware_exit  = usbhs_hardware_exit,
251                         .get_id         = usbhs_get_id,
252                         .phy_reset      = usbhs_phy_reset,
253                         .get_vbus       = usbhs_get_vbus,
254                 },
255                 .driver_param = {
256                         .buswait_bwait  = 4,
257                         .has_otg        = 1,
258                         .pipe_type      = usbhs_pipe_cfg,
259                         .pipe_size      = ARRAY_SIZE(usbhs_pipe_cfg),
260                 },
261         },
262 };
263
264 static struct resource usbhs_resources[] = {
265         [0] = {
266                 .start  = 0xE6890000,
267                 .end    = 0xE68900e6 - 1,
268                 .flags  = IORESOURCE_MEM,
269         },
270         [1] = {
271                 .start  = gic_spi(62),
272                 .end    = gic_spi(62),
273                 .flags  = IORESOURCE_IRQ,
274         },
275 };
276
277 static struct platform_device usbhs_device = {
278         .name   = "renesas_usbhs",
279         .id     = -1,
280         .dev = {
281                 .dma_mask               = NULL,
282                 .coherent_dma_mask      = 0xffffffff,
283                 .platform_data          = &usbhs_private.info,
284         },
285         .num_resources  = ARRAY_SIZE(usbhs_resources),
286         .resource       = usbhs_resources,
287 };
288
289 /* LCDC */
290 static struct fb_videomode kzm_lcdc_mode = {
291         .name           = "WVGA Panel",
292         .xres           = 800,
293         .yres           = 480,
294         .left_margin    = 220,
295         .right_margin   = 110,
296         .hsync_len      = 70,
297         .upper_margin   = 20,
298         .lower_margin   = 5,
299         .vsync_len      = 5,
300         .sync           = 0,
301 };
302
303 static struct sh_mobile_lcdc_info lcdc_info = {
304         .clock_source = LCDC_CLK_BUS,
305         .ch[0] = {
306                 .chan           = LCDC_CHAN_MAINLCD,
307                 .fourcc         = V4L2_PIX_FMT_RGB565,
308                 .interface_type = RGB24,
309                 .lcd_modes      = &kzm_lcdc_mode,
310                 .num_modes      = 1,
311                 .clock_divider  = 5,
312                 .flags          = 0,
313                 .panel_cfg = {
314                         .width  = 152,
315                         .height = 91,
316                 },
317         }
318 };
319
320 static struct resource lcdc_resources[] = {
321         [0] = {
322                 .name   = "LCDC",
323                 .start  = 0xfe940000,
324                 .end    = 0xfe943fff,
325                 .flags  = IORESOURCE_MEM,
326         },
327         [1] = {
328                 .start  = intcs_evt2irq(0x580),
329                 .flags  = IORESOURCE_IRQ,
330         },
331 };
332
333 static struct platform_device lcdc_device = {
334         .name           = "sh_mobile_lcdc_fb",
335         .num_resources  = ARRAY_SIZE(lcdc_resources),
336         .resource       = lcdc_resources,
337         .dev    = {
338                 .platform_data  = &lcdc_info,
339                 .coherent_dma_mask = DMA_BIT_MASK(32),
340         },
341 };
342
343 /* Fixed 1.8V regulator to be used by MMCIF */
344 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
345 {
346         REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
347         REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
348 };
349
350 /* MMCIF */
351 static struct resource sh_mmcif_resources[] = {
352         [0] = {
353                 .name   = "MMCIF",
354                 .start  = 0xe6bd0000,
355                 .end    = 0xe6bd00ff,
356                 .flags  = IORESOURCE_MEM,
357         },
358         [1] = {
359                 .start  = gic_spi(140),
360                 .flags  = IORESOURCE_IRQ,
361         },
362         [2] = {
363                 .start  = gic_spi(141),
364                 .flags  = IORESOURCE_IRQ,
365         },
366 };
367
368 static struct sh_mmcif_plat_data sh_mmcif_platdata = {
369         .ocr            = MMC_VDD_165_195,
370         .caps           = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
371         .ccs_unsupported = true,
372         .slave_id_tx    = SHDMA_SLAVE_MMCIF_TX,
373         .slave_id_rx    = SHDMA_SLAVE_MMCIF_RX,
374 };
375
376 static struct platform_device mmc_device = {
377         .name           = "sh_mmcif",
378         .dev            = {
379                 .dma_mask               = NULL,
380                 .coherent_dma_mask      = 0xffffffff,
381                 .platform_data          = &sh_mmcif_platdata,
382         },
383         .num_resources  = ARRAY_SIZE(sh_mmcif_resources),
384         .resource       = sh_mmcif_resources,
385 };
386
387 /* Fixed 3.3V regulators to be used by SDHI0 */
388 static struct regulator_consumer_supply vcc_sdhi0_consumers[] =
389 {
390         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
391 };
392
393 static struct regulator_init_data vcc_sdhi0_init_data = {
394         .constraints = {
395                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
396         },
397         .num_consumer_supplies  = ARRAY_SIZE(vcc_sdhi0_consumers),
398         .consumer_supplies      = vcc_sdhi0_consumers,
399 };
400
401 static struct fixed_voltage_config vcc_sdhi0_info = {
402         .supply_name = "SDHI0 Vcc",
403         .microvolts = 3300000,
404         .gpio = 15,
405         .enable_high = 1,
406         .init_data = &vcc_sdhi0_init_data,
407 };
408
409 static struct platform_device vcc_sdhi0 = {
410         .name = "reg-fixed-voltage",
411         .id   = 0,
412         .dev  = {
413                 .platform_data = &vcc_sdhi0_info,
414         },
415 };
416
417 /* Fixed 3.3V regulators to be used by SDHI2 */
418 static struct regulator_consumer_supply vcc_sdhi2_consumers[] =
419 {
420         REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
421 };
422
423 static struct regulator_init_data vcc_sdhi2_init_data = {
424         .constraints = {
425                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
426         },
427         .num_consumer_supplies  = ARRAY_SIZE(vcc_sdhi2_consumers),
428         .consumer_supplies      = vcc_sdhi2_consumers,
429 };
430
431 static struct fixed_voltage_config vcc_sdhi2_info = {
432         .supply_name = "SDHI2 Vcc",
433         .microvolts = 3300000,
434         .gpio = 14,
435         .enable_high = 1,
436         .init_data = &vcc_sdhi2_init_data,
437 };
438
439 static struct platform_device vcc_sdhi2 = {
440         .name = "reg-fixed-voltage",
441         .id   = 1,
442         .dev  = {
443                 .platform_data = &vcc_sdhi2_info,
444         },
445 };
446
447 /* SDHI */
448 static struct sh_mobile_sdhi_info sdhi0_info = {
449         .dma_slave_tx   = SHDMA_SLAVE_SDHI0_TX,
450         .dma_slave_rx   = SHDMA_SLAVE_SDHI0_RX,
451         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT,
452         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
453                           MMC_CAP_POWER_OFF_CARD,
454 };
455
456 static struct resource sdhi0_resources[] = {
457         [0] = {
458                 .name   = "SDHI0",
459                 .start  = 0xee100000,
460                 .end    = 0xee1000ff,
461                 .flags  = IORESOURCE_MEM,
462         },
463         [1] = {
464                 .name   = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
465                 .start  = gic_spi(83),
466                 .flags  = IORESOURCE_IRQ,
467         },
468         [2] = {
469                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
470                 .start  = gic_spi(84),
471                 .flags  = IORESOURCE_IRQ,
472         },
473         [3] = {
474                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
475                 .start  = gic_spi(85),
476                 .flags  = IORESOURCE_IRQ,
477         },
478 };
479
480 static struct platform_device sdhi0_device = {
481         .name           = "sh_mobile_sdhi",
482         .num_resources  = ARRAY_SIZE(sdhi0_resources),
483         .resource       = sdhi0_resources,
484         .dev    = {
485                 .platform_data  = &sdhi0_info,
486         },
487 };
488
489 /* Micro SD */
490 static struct sh_mobile_sdhi_info sdhi2_info = {
491         .dma_slave_tx   = SHDMA_SLAVE_SDHI2_TX,
492         .dma_slave_rx   = SHDMA_SLAVE_SDHI2_RX,
493         .tmio_flags     = TMIO_MMC_HAS_IDLE_WAIT |
494                           TMIO_MMC_USE_GPIO_CD |
495                           TMIO_MMC_WRPROTECT_DISABLE,
496         .tmio_caps      = MMC_CAP_SD_HIGHSPEED | MMC_CAP_POWER_OFF_CARD,
497         .cd_gpio        = 13,
498 };
499
500 static struct resource sdhi2_resources[] = {
501         [0] = {
502                 .name   = "SDHI2",
503                 .start  = 0xee140000,
504                 .end    = 0xee1400ff,
505                 .flags  = IORESOURCE_MEM,
506         },
507         [1] = {
508                 .name   = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
509                 .start  = gic_spi(103),
510                 .flags  = IORESOURCE_IRQ,
511         },
512         [2] = {
513                 .name   = SH_MOBILE_SDHI_IRQ_SDCARD,
514                 .start  = gic_spi(104),
515                 .flags  = IORESOURCE_IRQ,
516         },
517         [3] = {
518                 .name   = SH_MOBILE_SDHI_IRQ_SDIO,
519                 .start  = gic_spi(105),
520                 .flags  = IORESOURCE_IRQ,
521         },
522 };
523
524 static struct platform_device sdhi2_device = {
525         .name           = "sh_mobile_sdhi",
526         .id             = 2,
527         .num_resources  = ARRAY_SIZE(sdhi2_resources),
528         .resource       = sdhi2_resources,
529         .dev    = {
530                 .platform_data  = &sdhi2_info,
531         },
532 };
533
534 /* KEY */
535 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
536
537 static struct gpio_keys_button gpio_buttons[] = {
538         GPIO_KEY(KEY_BACK,      GPIO_PCF8575_PORT10,    "SW3"),
539         GPIO_KEY(KEY_RIGHT,     GPIO_PCF8575_PORT11,    "SW2-R"),
540         GPIO_KEY(KEY_LEFT,      GPIO_PCF8575_PORT12,    "SW2-L"),
541         GPIO_KEY(KEY_ENTER,     GPIO_PCF8575_PORT13,    "SW2-P"),
542         GPIO_KEY(KEY_UP,        GPIO_PCF8575_PORT14,    "SW2-U"),
543         GPIO_KEY(KEY_DOWN,      GPIO_PCF8575_PORT15,    "SW2-D"),
544         GPIO_KEY(KEY_HOME,      GPIO_PCF8575_PORT16,    "SW1"),
545 };
546
547 static struct gpio_keys_platform_data gpio_key_info = {
548         .buttons        = gpio_buttons,
549         .nbuttons       = ARRAY_SIZE(gpio_buttons),
550 };
551
552 static struct platform_device gpio_keys_device = {
553         .name   = "gpio-keys",
554         .dev    = {
555                 .platform_data  = &gpio_key_info,
556         },
557 };
558
559 /* FSI-AK4648 */
560 static struct sh_fsi_platform_info fsi_info = {
561         .port_a = {
562                 .tx_id = SHDMA_SLAVE_FSI2A_TX,
563         },
564 };
565
566 static struct resource fsi_resources[] = {
567         [0] = {
568                 .name   = "FSI",
569                 .start  = 0xEC230000,
570                 .end    = 0xEC230400 - 1,
571                 .flags  = IORESOURCE_MEM,
572         },
573         [1] = {
574                 .start  = gic_spi(146),
575                 .flags  = IORESOURCE_IRQ,
576         },
577 };
578
579 static struct platform_device fsi_device = {
580         .name           = "sh_fsi2",
581         .id             = -1,
582         .num_resources  = ARRAY_SIZE(fsi_resources),
583         .resource       = fsi_resources,
584         .dev    = {
585                 .platform_data  = &fsi_info,
586         },
587 };
588
589 static struct asoc_simple_card_info fsi2_ak4648_info = {
590         .name           = "AK4648",
591         .card           = "FSI2A-AK4648",
592         .codec          = "ak4642-codec.0-0012",
593         .platform       = "sh_fsi2",
594         .daifmt         = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
595         .cpu_dai = {
596                 .name   = "fsia-dai",
597         },
598         .codec_dai = {
599                 .name   = "ak4642-hifi",
600                 .sysclk = 11289600,
601         },
602 };
603
604 static struct platform_device fsi_ak4648_device = {
605         .name   = "asoc-simple-card",
606         .dev    = {
607                 .platform_data  = &fsi2_ak4648_info,
608                 .coherent_dma_mask = DMA_BIT_MASK(32),
609                 .dma_mask = &fsi_ak4648_device.dev.coherent_dma_mask,
610         },
611 };
612
613 /* I2C */
614
615 /* StepDown1 is used to supply 1.315V to the CPU */
616 static struct regulator_init_data as3711_sd1 = {
617         .constraints = {
618                 .name = "1.315V CPU",
619                 .boot_on = 1,
620                 .always_on = 1,
621                 .min_uV = 1315000,
622                 .max_uV = 1335000,
623         },
624 };
625
626 /* StepDown2 is used to supply 1.8V to the CPU and to the board */
627 static struct regulator_init_data as3711_sd2 = {
628         .constraints = {
629                 .name = "1.8V",
630                 .boot_on = 1,
631                 .always_on = 1,
632                 .min_uV = 1800000,
633                 .max_uV = 1800000,
634         },
635 };
636
637 /*
638  * StepDown3 is switched in parallel with StepDown2, seems to be off,
639  * according to read-back pre-set register values
640  */
641
642 /* StepDown4 is used to supply 1.215V to the CPU and to the board */
643 static struct regulator_init_data as3711_sd4 = {
644         .constraints = {
645                 .name = "1.215V",
646                 .boot_on = 1,
647                 .always_on = 1,
648                 .min_uV = 1215000,
649                 .max_uV = 1235000,
650         },
651 };
652
653 /* LDO1 is unused and unconnected */
654
655 /* LDO2 is used to supply 2.8V to the CPU */
656 static struct regulator_init_data as3711_ldo2 = {
657         .constraints = {
658                 .name = "2.8V CPU",
659                 .boot_on = 1,
660                 .always_on = 1,
661                 .min_uV = 2800000,
662                 .max_uV = 2800000,
663         },
664 };
665
666 /* LDO3 is used to supply 3.0V to the CPU */
667 static struct regulator_init_data as3711_ldo3 = {
668         .constraints = {
669                 .name = "3.0V CPU",
670                 .boot_on = 1,
671                 .always_on = 1,
672                 .min_uV = 3000000,
673                 .max_uV = 3000000,
674         },
675 };
676
677 /* LDO4 is used to supply 2.8V to the board */
678 static struct regulator_init_data as3711_ldo4 = {
679         .constraints = {
680                 .name = "2.8V",
681                 .boot_on = 1,
682                 .always_on = 1,
683                 .min_uV = 2800000,
684                 .max_uV = 2800000,
685         },
686 };
687
688 /* LDO5 is switched parallel to LDO4, also set to 2.8V */
689 static struct regulator_init_data as3711_ldo5 = {
690         .constraints = {
691                 .name = "2.8V #2",
692                 .boot_on = 1,
693                 .always_on = 1,
694                 .min_uV = 2800000,
695                 .max_uV = 2800000,
696         },
697 };
698
699 /* LDO6 is unused and unconnected */
700
701 /* LDO7 is used to supply 1.15V to the CPU */
702 static struct regulator_init_data as3711_ldo7 = {
703         .constraints = {
704                 .name = "1.15V CPU",
705                 .boot_on = 1,
706                 .always_on = 1,
707                 .min_uV = 1150000,
708                 .max_uV = 1150000,
709         },
710 };
711
712 /* LDO8 is switched parallel to LDO7, also set to 1.15V */
713 static struct regulator_init_data as3711_ldo8 = {
714         .constraints = {
715                 .name = "1.15V CPU #2",
716                 .boot_on = 1,
717                 .always_on = 1,
718                 .min_uV = 1150000,
719                 .max_uV = 1150000,
720         },
721 };
722
723 static struct as3711_platform_data as3711_pdata = {
724         .regulator      = {
725                 .init_data      = {
726                         [AS3711_REGULATOR_SD_1] = &as3711_sd1,
727                         [AS3711_REGULATOR_SD_2] = &as3711_sd2,
728                         [AS3711_REGULATOR_SD_4] = &as3711_sd4,
729                         [AS3711_REGULATOR_LDO_2] = &as3711_ldo2,
730                         [AS3711_REGULATOR_LDO_3] = &as3711_ldo3,
731                         [AS3711_REGULATOR_LDO_4] = &as3711_ldo4,
732                         [AS3711_REGULATOR_LDO_5] = &as3711_ldo5,
733                         [AS3711_REGULATOR_LDO_7] = &as3711_ldo7,
734                         [AS3711_REGULATOR_LDO_8] = &as3711_ldo8,
735                 },
736         },
737         .backlight      = {
738                 .su2_fb = "sh_mobile_lcdc_fb.0",
739                 .su2_max_uA = 36000,
740                 .su2_feedback = AS3711_SU2_CURR_AUTO,
741                 .su2_fbprot = AS3711_SU2_GPIO4,
742                 .su2_auto_curr1 = true,
743                 .su2_auto_curr2 = true,
744                 .su2_auto_curr3 = true,
745         },
746 };
747
748 static struct pcf857x_platform_data pcf8575_pdata = {
749         .gpio_base      = GPIO_PCF8575_BASE,
750 };
751
752 static struct i2c_board_info i2c0_devices[] = {
753         {
754                 I2C_BOARD_INFO("ak4648", 0x12),
755         },
756         {
757                 I2C_BOARD_INFO("r2025sd", 0x32),
758         },
759         {
760                 I2C_BOARD_INFO("ak8975", 0x0c),
761                 .irq = irq_pin(28), /* IRQ28 */
762         },
763         {
764                 I2C_BOARD_INFO("adxl34x", 0x1d),
765                 .irq = irq_pin(26), /* IRQ26 */
766         },
767         {
768                 I2C_BOARD_INFO("as3711", 0x40),
769                 .irq = intcs_evt2irq(0x3300), /* IRQ24 */
770                 .platform_data = &as3711_pdata,
771         },
772 };
773
774 static struct i2c_board_info i2c1_devices[] = {
775         {
776                 I2C_BOARD_INFO("st1232-ts", 0x55),
777                 .irq = irq_pin(8), /* IRQ8 */
778         },
779 };
780
781 static struct i2c_board_info i2c3_devices[] = {
782         {
783                 I2C_BOARD_INFO("pcf8575", 0x20),
784                 .irq = irq_pin(19), /* IRQ19 */
785                 .platform_data = &pcf8575_pdata,
786         },
787 };
788
789 static struct platform_device *kzm_devices[] __initdata = {
790         &smsc_device,
791         &usb_host_device,
792         &usbhs_device,
793         &lcdc_device,
794         &mmc_device,
795         &vcc_sdhi0,
796         &vcc_sdhi2,
797         &sdhi0_device,
798         &sdhi2_device,
799         &gpio_keys_device,
800         &fsi_device,
801         &fsi_ak4648_device,
802 };
803
804 static unsigned long pin_pullup_conf[] = {
805         PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_UP, 0),
806 };
807
808 static const struct pinctrl_map kzm_pinctrl_map[] = {
809         /* FSIA (AK4648) */
810         PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2", "pfc-sh73a0",
811                                   "fsia_mclk_in", "fsia"),
812         PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2", "pfc-sh73a0",
813                                   "fsia_sclk_in", "fsia"),
814         PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2", "pfc-sh73a0",
815                                   "fsia_data_in", "fsia"),
816         PIN_MAP_MUX_GROUP_DEFAULT("sh_fsi2", "pfc-sh73a0",
817                                   "fsia_data_out", "fsia"),
818         /* I2C3 */
819         PIN_MAP_MUX_GROUP_DEFAULT("i2c-sh_mobile.3", "pfc-sh73a0",
820                                   "i2c3_1", "i2c3"),
821         /* LCD */
822         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh73a0",
823                                   "lcd_data24", "lcd"),
824         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh73a0",
825                                   "lcd_sync", "lcd"),
826         /* MMCIF */
827         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
828                                   "mmc0_data8_0", "mmc0"),
829         PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
830                                   "mmc0_ctrl_0", "mmc0"),
831         PIN_MAP_CONFIGS_PIN_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
832                                     "PORT279", pin_pullup_conf),
833         PIN_MAP_CONFIGS_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh73a0",
834                                       "mmc0_data8_0", pin_pullup_conf),
835         /* SCIFA4 */
836         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.4", "pfc-sh73a0",
837                                   "scifa4_data", "scifa4"),
838         PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.4", "pfc-sh73a0",
839                                   "scifa4_ctrl", "scifa4"),
840         /* SDHI0 */
841         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
842                                   "sdhi0_data4", "sdhi0"),
843         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
844                                   "sdhi0_ctrl", "sdhi0"),
845         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
846                                   "sdhi0_cd", "sdhi0"),
847         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh73a0",
848                                   "sdhi0_wp", "sdhi0"),
849         /* SDHI2 */
850         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh73a0",
851                                   "sdhi2_data4", "sdhi2"),
852         PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh73a0",
853                                   "sdhi2_ctrl", "sdhi2"),
854         /* SMSC */
855         PIN_MAP_MUX_GROUP_DEFAULT("smsc911x.0", "pfc-sh73a0",
856                                   "bsc_cs4", "bsc"),
857         /* USB */
858         PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs", "pfc-sh73a0",
859                                   "usb_vbus", "usb"),
860 };
861
862 static void __init kzm_init(void)
863 {
864         regulator_register_always_on(2, "fixed-1.8V", fixed1v8_power_consumers,
865                                      ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
866         regulator_register_fixed(3, dummy_supplies, ARRAY_SIZE(dummy_supplies));
867
868         pinctrl_register_mappings(kzm_pinctrl_map, ARRAY_SIZE(kzm_pinctrl_map));
869
870         sh73a0_pinmux_init();
871
872         /* SMSC */
873         gpio_request_one(224, GPIOF_IN, NULL); /* IRQ3 */
874
875         /* LCDC */
876         gpio_request_one(222, GPIOF_OUT_INIT_HIGH, NULL); /* LCDCDON */
877         gpio_request_one(226, GPIOF_OUT_INIT_HIGH, NULL); /* SC */
878
879         /* Touchscreen */
880         gpio_request_one(223, GPIOF_IN, NULL); /* IRQ8 */
881
882 #ifdef CONFIG_CACHE_L2X0
883         /* Shared attribute override enable, 64K*8way */
884         l2x0_init(IOMEM(0xf0100000), 0x00400000, 0xc20f0fff);
885 #endif
886
887         i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
888         i2c_register_board_info(1, i2c1_devices, ARRAY_SIZE(i2c1_devices));
889         i2c_register_board_info(3, i2c3_devices, ARRAY_SIZE(i2c3_devices));
890
891         sh73a0_add_standard_devices();
892         platform_add_devices(kzm_devices, ARRAY_SIZE(kzm_devices));
893
894         sh73a0_pm_init();
895 }
896
897 static void kzm9g_restart(enum reboot_mode mode, const char *cmd)
898 {
899 #define RESCNT2 IOMEM(0xe6188020)
900         /* Do soft power on reset */
901         writel((1 << 31), RESCNT2);
902 }
903
904 static const char *kzm9g_boards_compat_dt[] __initdata = {
905         "renesas,kzm9g",
906         NULL,
907 };
908
909 DT_MACHINE_START(KZM9G_DT, "kzm9g")
910         .smp            = smp_ops(sh73a0_smp_ops),
911         .map_io         = sh73a0_map_io,
912         .init_early     = sh73a0_add_early_devices,
913         .nr_irqs        = NR_IRQS_LEGACY,
914         .init_irq       = sh73a0_init_irq,
915         .init_machine   = kzm_init,
916         .init_late      = shmobile_init_late,
917         .init_time      = sh73a0_earlytimer_init,
918         .restart        = kzm9g_restart,
919         .dt_compat      = kzm9g_boards_compat_dt,
920 MACHINE_END