Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board-kzm9g.c
Go to the documentation of this file.
1 /*
2  * KZM-A9-GT board support
3  *
4  * Copyright (C) 2012 Kuninori Morimoto <[email protected]>
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/mmc/host.h>
29 #include <linux/mmc/sh_mmcif.h>
31 #include <linux/mfd/tmio.h>
32 #include <linux/platform_device.h>
33 #include <linux/regulator/fixed.h>
35 #include <linux/smsc911x.h>
36 #include <linux/usb/r8a66597.h>
38 #include <linux/videodev2.h>
39 #include <sound/sh_fsi.h>
40 #include <sound/simple_card.h>
41 #include <mach/irqs.h>
42 #include <mach/sh73a0.h>
43 #include <mach/common.h>
45 #include <asm/hardware/gic.h>
46 #include <asm/mach-types.h>
47 #include <asm/mach/arch.h>
48 #include <video/sh_mobile_lcdc.h>
49 
50 /*
51  * external GPIO
52  */
53 #define GPIO_PCF8575_BASE (GPIO_NR)
54 #define GPIO_PCF8575_PORT10 (GPIO_NR + 8)
55 #define GPIO_PCF8575_PORT11 (GPIO_NR + 9)
56 #define GPIO_PCF8575_PORT12 (GPIO_NR + 10)
57 #define GPIO_PCF8575_PORT13 (GPIO_NR + 11)
58 #define GPIO_PCF8575_PORT14 (GPIO_NR + 12)
59 #define GPIO_PCF8575_PORT15 (GPIO_NR + 13)
60 #define GPIO_PCF8575_PORT16 (GPIO_NR + 14)
61 
62 /* Dummy supplies, where voltage doesn't matter */
63 static struct regulator_consumer_supply dummy_supplies[] = {
64  REGULATOR_SUPPLY("vddvario", "smsc911x"),
65  REGULATOR_SUPPLY("vdd33a", "smsc911x"),
66 };
67 
68 /*
69  * FSI-AK4648
70  *
71  * this command is required when playback.
72  *
73  * # amixer set "LINEOUT Mixer DACL" on
74  */
75 
76 /* SMSC 9221 */
77 static struct resource smsc9221_resources[] = {
78  [0] = {
79  .start = 0x10000000, /* CS4 */
80  .end = 0x100000ff,
81  .flags = IORESOURCE_MEM,
82  },
83  [1] = {
84  .start = intcs_evt2irq(0x260), /* IRQ3 */
85  .flags = IORESOURCE_IRQ,
86  },
87 };
88 
89 static struct smsc911x_platform_config smsc9221_platdata = {
91  .phy_interface = PHY_INTERFACE_MODE_MII,
92  .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
93  .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
94 };
95 
96 static struct platform_device smsc_device = {
97  .name = "smsc911x",
98  .dev = {
99  .platform_data = &smsc9221_platdata,
100  },
101  .resource = smsc9221_resources,
102  .num_resources = ARRAY_SIZE(smsc9221_resources),
103 };
104 
105 /* USB external chip */
106 static struct r8a66597_platdata usb_host_data = {
107  .on_chip = 0,
109 };
110 
111 static struct resource usb_resources[] = {
112  [0] = {
113  .start = 0x10010000,
114  .end = 0x1001ffff - 1,
115  .flags = IORESOURCE_MEM,
116  },
117  [1] = {
118  .start = intcs_evt2irq(0x220), /* IRQ1 */
119  .flags = IORESOURCE_IRQ,
120  },
121 };
122 
123 static struct platform_device usb_host_device = {
124  .name = "r8a66597_hcd",
125  .dev = {
126  .platform_data = &usb_host_data,
127  .dma_mask = NULL,
128  .coherent_dma_mask = 0xffffffff,
129  },
130  .num_resources = ARRAY_SIZE(usb_resources),
131  .resource = usb_resources,
132 };
133 
134 /* USB Func CN17 */
136  void __iomem *phy;
137  void __iomem *cr2;
139 };
140 
141 #define IRQ15 intcs_evt2irq(0x03e0)
142 #define USB_PHY_MODE (1 << 4)
143 #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
144 #define USB_PHY_ON (1 << 1)
145 #define USB_PHY_OFF (1 << 0)
146 #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
147 
148 #define usbhs_get_priv(pdev) \
149  container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
150 
151 static int usbhs_get_vbus(struct platform_device *pdev)
152 {
153  struct usbhs_private *priv = usbhs_get_priv(pdev);
154 
155  return !((1 << 7) & __raw_readw(priv->cr2));
156 }
157 
158 static void usbhs_phy_reset(struct platform_device *pdev)
159 {
160  struct usbhs_private *priv = usbhs_get_priv(pdev);
161 
162  /* init phy */
163  __raw_writew(0x8a0a, priv->cr2);
164 }
165 
166 static int usbhs_get_id(struct platform_device *pdev)
167 {
168  return USBHS_GADGET;
169 }
170 
171 static irqreturn_t usbhs_interrupt(int irq, void *data)
172 {
173  struct platform_device *pdev = data;
174  struct usbhs_private *priv = usbhs_get_priv(pdev);
175 
177 
178  /* clear status */
180 
181  return IRQ_HANDLED;
182 }
183 
184 static int usbhs_hardware_init(struct platform_device *pdev)
185 {
186  struct usbhs_private *priv = usbhs_get_priv(pdev);
187  int ret;
188 
189  /* clear interrupt status */
191 
192  ret = request_irq(IRQ15, usbhs_interrupt, IRQF_TRIGGER_HIGH,
193  dev_name(&pdev->dev), pdev);
194  if (ret) {
195  dev_err(&pdev->dev, "request_irq err\n");
196  return ret;
197  }
198 
199  /* enable USB phy interrupt */
201 
202  return 0;
203 }
204 
205 static void usbhs_hardware_exit(struct platform_device *pdev)
206 {
207  struct usbhs_private *priv = usbhs_get_priv(pdev);
208 
209  /* clear interrupt status */
211 
212  free_irq(IRQ15, pdev);
213 }
214 
215 static u32 usbhs_pipe_cfg[] = {
232 };
233 
234 static struct usbhs_private usbhs_private = {
235  .phy = IOMEM(0xe60781e0), /* USBPHYINT */
236  .cr2 = IOMEM(0xe605810c), /* USBCR2 */
237  .info = {
238  .platform_callback = {
239  .hardware_init = usbhs_hardware_init,
240  .hardware_exit = usbhs_hardware_exit,
241  .get_id = usbhs_get_id,
242  .phy_reset = usbhs_phy_reset,
243  .get_vbus = usbhs_get_vbus,
244  },
245  .driver_param = {
246  .buswait_bwait = 4,
247  .has_otg = 1,
248  .pipe_type = usbhs_pipe_cfg,
249  .pipe_size = ARRAY_SIZE(usbhs_pipe_cfg),
250  },
251  },
252 };
253 
254 static struct resource usbhs_resources[] = {
255  [0] = {
256  .start = 0xE6890000,
257  .end = 0xE68900e6 - 1,
258  .flags = IORESOURCE_MEM,
259  },
260  [1] = {
261  .start = gic_spi(62),
262  .end = gic_spi(62),
263  .flags = IORESOURCE_IRQ,
264  },
265 };
266 
267 static struct platform_device usbhs_device = {
268  .name = "renesas_usbhs",
269  .id = -1,
270  .dev = {
271  .dma_mask = NULL,
272  .coherent_dma_mask = 0xffffffff,
273  .platform_data = &usbhs_private.info,
274  },
275  .num_resources = ARRAY_SIZE(usbhs_resources),
276  .resource = usbhs_resources,
277 };
278 
279 /* LCDC */
280 static struct fb_videomode kzm_lcdc_mode = {
281  .name = "WVGA Panel",
282  .xres = 800,
283  .yres = 480,
284  .left_margin = 220,
285  .right_margin = 110,
286  .hsync_len = 70,
287  .upper_margin = 20,
288  .lower_margin = 5,
289  .vsync_len = 5,
290  .sync = 0,
291 };
292 
293 static struct sh_mobile_lcdc_info lcdc_info = {
294  .clock_source = LCDC_CLK_BUS,
295  .ch[0] = {
296  .chan = LCDC_CHAN_MAINLCD,
297  .fourcc = V4L2_PIX_FMT_RGB565,
298  .interface_type = RGB24,
299  .lcd_modes = &kzm_lcdc_mode,
300  .num_modes = 1,
301  .clock_divider = 5,
302  .flags = 0,
303  .panel_cfg = {
304  .width = 152,
305  .height = 91,
306  },
307  }
308 };
309 
310 static struct resource lcdc_resources[] = {
311  [0] = {
312  .name = "LCDC",
313  .start = 0xfe940000,
314  .end = 0xfe943fff,
315  .flags = IORESOURCE_MEM,
316  },
317  [1] = {
318  .start = intcs_evt2irq(0x580),
319  .flags = IORESOURCE_IRQ,
320  },
321 };
322 
323 static struct platform_device lcdc_device = {
324  .name = "sh_mobile_lcdc_fb",
325  .num_resources = ARRAY_SIZE(lcdc_resources),
326  .resource = lcdc_resources,
327  .dev = {
328  .platform_data = &lcdc_info,
329  .coherent_dma_mask = ~0,
330  },
331 };
332 
333 /* Fixed 1.8V regulator to be used by MMCIF */
334 static struct regulator_consumer_supply fixed1v8_power_consumers[] =
335 {
336  REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
337  REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
338 };
339 
340 /* MMCIF */
341 static struct resource sh_mmcif_resources[] = {
342  [0] = {
343  .name = "MMCIF",
344  .start = 0xe6bd0000,
345  .end = 0xe6bd00ff,
346  .flags = IORESOURCE_MEM,
347  },
348  [1] = {
349  .start = gic_spi(140),
350  .flags = IORESOURCE_IRQ,
351  },
352  [2] = {
353  .start = gic_spi(141),
354  .flags = IORESOURCE_IRQ,
355  },
356 };
357 
358 static struct sh_mmcif_plat_data sh_mmcif_platdata = {
359  .ocr = MMC_VDD_165_195,
361  .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
362  .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
363 };
364 
365 static struct platform_device mmc_device = {
366  .name = "sh_mmcif",
367  .dev = {
368  .dma_mask = NULL,
369  .coherent_dma_mask = 0xffffffff,
370  .platform_data = &sh_mmcif_platdata,
371  },
372  .num_resources = ARRAY_SIZE(sh_mmcif_resources),
373  .resource = sh_mmcif_resources,
374 };
375 
376 /* Fixed 2.8V regulators to be used by SDHI0 and SDHI2 */
377 static struct regulator_consumer_supply fixed2v8_power_consumers[] =
378 {
379  REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
380  REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
381  REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
382  REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
383 };
384 
385 /* SDHI */
386 static struct sh_mobile_sdhi_info sdhi0_info = {
387  .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
388  .tmio_caps = MMC_CAP_SD_HIGHSPEED,
389  .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
390 };
391 
392 static struct resource sdhi0_resources[] = {
393  [0] = {
394  .name = "SDHI0",
395  .start = 0xee100000,
396  .end = 0xee1000ff,
397  .flags = IORESOURCE_MEM,
398  },
399  [1] = {
401  .start = gic_spi(83),
402  .flags = IORESOURCE_IRQ,
403  },
404  [2] = {
406  .start = gic_spi(84),
407  .flags = IORESOURCE_IRQ,
408  },
409  [3] = {
410  .name = SH_MOBILE_SDHI_IRQ_SDIO,
411  .start = gic_spi(85),
412  .flags = IORESOURCE_IRQ,
413  },
414 };
415 
416 static struct platform_device sdhi0_device = {
417  .name = "sh_mobile_sdhi",
418  .num_resources = ARRAY_SIZE(sdhi0_resources),
419  .resource = sdhi0_resources,
420  .dev = {
421  .platform_data = &sdhi0_info,
422  },
423 };
424 
425 /* Micro SD */
426 static struct sh_mobile_sdhi_info sdhi2_info = {
427  .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT |
430  .tmio_caps = MMC_CAP_SD_HIGHSPEED,
431  .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
432  .cd_gpio = GPIO_PORT13,
433 };
434 
435 static struct resource sdhi2_resources[] = {
436  [0] = {
437  .name = "SDHI2",
438  .start = 0xee140000,
439  .end = 0xee1400ff,
440  .flags = IORESOURCE_MEM,
441  },
442  [1] = {
444  .start = gic_spi(103),
445  .flags = IORESOURCE_IRQ,
446  },
447  [2] = {
449  .start = gic_spi(104),
450  .flags = IORESOURCE_IRQ,
451  },
452  [3] = {
453  .name = SH_MOBILE_SDHI_IRQ_SDIO,
454  .start = gic_spi(105),
455  .flags = IORESOURCE_IRQ,
456  },
457 };
458 
459 static struct platform_device sdhi2_device = {
460  .name = "sh_mobile_sdhi",
461  .id = 2,
462  .num_resources = ARRAY_SIZE(sdhi2_resources),
463  .resource = sdhi2_resources,
464  .dev = {
465  .platform_data = &sdhi2_info,
466  },
467 };
468 
469 /* KEY */
470 #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
471 
472 static struct gpio_keys_button gpio_buttons[] = {
480 };
481 
482 static struct gpio_keys_platform_data gpio_key_info = {
483  .buttons = gpio_buttons,
484  .nbuttons = ARRAY_SIZE(gpio_buttons),
485 };
486 
487 static struct platform_device gpio_keys_device = {
488  .name = "gpio-keys",
489  .dev = {
490  .platform_data = &gpio_key_info,
491  },
492 };
493 
494 /* FSI-AK4648 */
495 static struct sh_fsi_platform_info fsi_info = {
496  .port_a = {
497  .tx_id = SHDMA_SLAVE_FSI2A_TX,
498  },
499 };
500 
501 static struct resource fsi_resources[] = {
502  [0] = {
503  .name = "FSI",
504  .start = 0xEC230000,
505  .end = 0xEC230400 - 1,
506  .flags = IORESOURCE_MEM,
507  },
508  [1] = {
509  .start = gic_spi(146),
510  .flags = IORESOURCE_IRQ,
511  },
512 };
513 
514 static struct platform_device fsi_device = {
515  .name = "sh_fsi2",
516  .id = -1,
517  .num_resources = ARRAY_SIZE(fsi_resources),
518  .resource = fsi_resources,
519  .dev = {
520  .platform_data = &fsi_info,
521  },
522 };
523 
524 static struct asoc_simple_dai_init_info fsi2_ak4648_init_info = {
525  .fmt = SND_SOC_DAIFMT_LEFT_J,
526  .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM,
527  .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
528  .sysclk = 11289600,
529 };
530 
531 static struct asoc_simple_card_info fsi2_ak4648_info = {
532  .name = "AK4648",
533  .card = "FSI2A-AK4648",
534  .cpu_dai = "fsia-dai",
535  .codec = "ak4642-codec.0-0012",
536  .platform = "sh_fsi2",
537  .codec_dai = "ak4642-hifi",
538  .init = &fsi2_ak4648_init_info,
539 };
540 
541 static struct platform_device fsi_ak4648_device = {
542  .name = "asoc-simple-card",
543  .dev = {
544  .platform_data = &fsi2_ak4648_info,
545  },
546 };
547 
548 /* I2C */
549 static struct pcf857x_platform_data pcf8575_pdata = {
550  .gpio_base = GPIO_PCF8575_BASE,
551  .irq = intcs_evt2irq(0x3260), /* IRQ19 */
552 };
553 
554 static struct i2c_board_info i2c0_devices[] = {
555  {
556  I2C_BOARD_INFO("ak4648", 0x12),
557  },
558  {
559  I2C_BOARD_INFO("r2025sd", 0x32),
560  }
561 };
562 
563 static struct i2c_board_info i2c1_devices[] = {
564  {
565  I2C_BOARD_INFO("st1232-ts", 0x55),
566  .irq = intcs_evt2irq(0x300), /* IRQ8 */
567  },
568 };
569 
570 static struct i2c_board_info i2c3_devices[] = {
571  {
572  I2C_BOARD_INFO("pcf8575", 0x20),
573  .platform_data = &pcf8575_pdata,
574  },
575 };
576 
577 static struct platform_device *kzm_devices[] __initdata = {
578  &smsc_device,
579  &usb_host_device,
580  &usbhs_device,
581  &lcdc_device,
582  &mmc_device,
583  &sdhi0_device,
584  &sdhi2_device,
585  &gpio_keys_device,
586  &fsi_device,
587  &fsi_ak4648_device,
588 };
589 
590 /*
591  * FIXME
592  *
593  * This is quick hack for enabling LCDC backlight
594  */
595 static int __init as3711_enable_lcdc_backlight(void)
596 {
597  struct i2c_adapter *a = i2c_get_adapter(0);
598  struct i2c_msg msg;
599  int i, ret;
600  __u8 magic[] = {
601  0x40, 0x2a,
602  0x43, 0x3c,
603  0x44, 0x3c,
604  0x45, 0x3c,
605  0x54, 0x03,
606  0x51, 0x00,
607  0x51, 0x01,
608  0xff, 0x00, /* wait */
609  0x43, 0xf0,
610  0x44, 0xf0,
611  0x45, 0xf0,
612  };
613 
614  if (!machine_is_kzm9g())
615  return 0;
616 
617  if (!a)
618  return 0;
619 
620  msg.addr = 0x40;
621  msg.len = 2;
622  msg.flags = 0;
623 
624  for (i = 0; i < ARRAY_SIZE(magic); i += 2) {
625  msg.buf = magic + i;
626 
627  if (0xff == msg.buf[0]) {
628  udelay(500);
629  continue;
630  }
631 
632  ret = i2c_transfer(a, &msg, 1);
633  if (ret < 0) {
634  pr_err("i2c transfer fail\n");
635  break;
636  }
637  }
638 
639  return 0;
640 }
641 device_initcall(as3711_enable_lcdc_backlight);
642 
643 static void __init kzm_init(void)
644 {
645  regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
646  ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
647  regulator_register_always_on(1, "fixed-2.8V", fixed2v8_power_consumers,
648  ARRAY_SIZE(fixed2v8_power_consumers), 2800000);
649  regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
650 
652 
653  /* enable SCIFA4 */
658 
659  /* CS4 for SMSC/USB */
660  gpio_request(GPIO_FN_CS4_, NULL); /* CS4 */
661 
662  /* SMSC */
663  gpio_request(GPIO_PORT224, NULL); /* IRQ3 */
665 
666  /* LCDC */
693 
694  gpio_request(GPIO_PORT222, NULL); /* LCDCDON */
695  gpio_request(GPIO_PORT226, NULL); /* SC */
698 
699  /* Touchscreen */
700  gpio_request(GPIO_PORT223, NULL); /* IRQ8 */
702 
703  /* enable MMCIF */
714 
715  /* enable SD */
726  gpio_direction_output(GPIO_PORT15, 1); /* power */
727 
728  /* enable Micro SD */
736  gpio_direction_output(GPIO_PORT14, 1); /* power */
737 
738  /* I2C 3 */
741 
742  /* enable FSI2 port A (ak4648) */
748 
749  /* enable USB */
751 
752 #ifdef CONFIG_CACHE_L2X0
753  /* Early BRESP enable, Shared attribute override enable, 64K*8way */
754  l2x0_init(IOMEM(0xf0100000), 0x40460000, 0x82000fff);
755 #endif
756 
757  i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
758  i2c_register_board_info(1, i2c1_devices, ARRAY_SIZE(i2c1_devices));
759  i2c_register_board_info(3, i2c3_devices, ARRAY_SIZE(i2c3_devices));
760 
762  platform_add_devices(kzm_devices, ARRAY_SIZE(kzm_devices));
763 }
764 
765 static void kzm9g_restart(char mode, const char *cmd)
766 {
767 #define RESCNT2 IOMEM(0xe6188020)
768  /* Do soft power on reset */
769  writel((1 << 31), RESCNT2);
770 }
771 
772 static const char *kzm9g_boards_compat_dt[] __initdata = {
773  "renesas,kzm9g",
774  NULL,
775 };
776 
777 DT_MACHINE_START(KZM9G_DT, "kzm9g")
778  .smp = smp_ops(sh73a0_smp_ops),
779  .map_io = sh73a0_map_io,
781  .nr_irqs = NR_IRQS_LEGACY,
782  .init_irq = sh73a0_init_irq,
783  .handle_irq = gic_handle_irq,
784  .init_machine = kzm_init,
785  .init_late = shmobile_init_late,
786  .timer = &shmobile_timer,
787  .restart = kzm9g_restart,
788  .dt_compat = kzm9g_boards_compat_dt,