aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-mx6/board-mx6q_hdmidongle.c
blob: ffd8d9afef6a2a5a7002d89ecfd97c8745d4a7c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/*
 * Copyright (C) 2012-2013 Freescale Semiconductor, Inc. All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <linux/types.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/nodemask.h>
#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/fsl_devices.h>
#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
#include <linux/i2c.h>
#include <linux/i2c/pca953x.h>
#include <linux/ata.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/regulator/consumer.h>
#include <linux/pmic_external.h>
#include <linux/pmic_status.h>
#include <linux/ipu.h>
#include <linux/mxcfb.h>
#include <linux/pwm_backlight.h>
#include <linux/fec.h>
#include <linux/memblock.h>
#include <linux/gpio.h>
#include <linux/etherdevice.h>
#include <linux/regulator/anatop-regulator.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/fixed.h>
#include <linux/mfd/mxc-hdmi-core.h>

#include <mach/common.h>
#include <mach/hardware.h>
#include <mach/mxc_dvfs.h>
#include <mach/memory.h>
#include <mach/iomux-mx6q.h>
#include <mach/imx-uart.h>
#include <mach/viv_gpu.h>
#include <mach/ipu-v3.h>
#include <mach/mxc_hdmi.h>

#include <asm/irq.h>
#include <asm/setup.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/time.h>

#ifdef CONFIG_MFD_WM831X
#include <linux/mfd/wm831x/core.h>
#include <linux/mfd/wm831x/pdata.h>
#include <linux/mfd/wm831x/regulator.h>
#include <linux/mfd/wm831x/gpio.h>
#endif

#include "usb.h"
#include "devices-imx6q.h"
#include "crm_regs.h"
#include "cpu_op-mx6.h"
#include "board-mx6q_hdmidongle.h"
#include "board-mx6dl_hdmidongle.h"

#define HDMIDONGLE_USB_OTG_PWR	IMX_GPIO_NR(4, 15)
#define HDMIDONGLE_USB_H1_PWR	IMX_GPIO_NR(4, 14)
#define HDMIDONGLE_ECSPI2_CS0  IMX_GPIO_NR(2, 26)
#define HDMIDONGLE_HDMI_CEC_IN	IMX_GPIO_NR(4, 11)


#define HDMIDONGLE_BT_RST	IMX_GPIO_NR(3, 7)
#define HDMIDONGLE_BT_EN	IMX_GPIO_NR(3, 9)
#define HDMIDONGLE_WL_EN        IMX_GPIO_NR(3, 10)

#define HDMIDONGLE_SD2_CD		IMX_GPIO_NR(1, 4)
#define HDMIDONGLE_REVA_POWER_KEY	IMX_GPIO_NR(6, 16)
#define HDMIDONGLE_REVB_POWER_KEY	IMX_GPIO_NR(1, 27)

#ifdef CONFIG_IMX_PCIE
#define HDMIDONGLE_PCIE_PWR_EN	IMX_GPIO_NR(3, 7) /*fake pcie power enable */
#define HDMIDONGLE_PCIE_RST     IMX_GPIO_NR(3, 9)
#define HDMIDONGLE_PCIE_WAKE	IMX_GPIO_NR(3, 22)
#define HDMIDONGLE_PCIE_DIS		IMX_GPIO_NR(3, 10)
#endif

extern char *gp_reg_id;
extern char *soc_reg_id;
extern char *pu_reg_id;

static const struct esdhc_platform_data mx6q_hdmidongle_sd1_data __initconst = {
	.always_present = 1,
};

static const struct esdhc_platform_data mx6q_hdmidongle_sd2_data __initconst = {
	.cd_gpio = HDMIDONGLE_SD2_CD,
	.keep_power_at_suspend = 1,
	.support_8bit = 0,
	.delay_line = 0,
	.cd_type = ESDHC_CD_CONTROLLER,
};

static const struct esdhc_platform_data mx6q_hdmidongle_sd3_data __initconst = {
	.always_present = 1,
	.keep_power_at_suspend = 1,
	.support_8bit = 1,
	.delay_line = 0,
	.cd_type = ESDHC_CD_PERMANENT,
};

static const struct esdhc_platform_data mx6q_hdmidongle_revc_sd3_data __initconst = {
	.always_present = 1,
	.keep_power_at_suspend = 1,
	.support_8bit = 0,
	.delay_line = 0,
	.cd_type = ESDHC_CD_PERMANENT,
};


static int __init gpmi_nand_platform_init(void)
{
	iomux_v3_cfg_t *nand_pads = NULL;
	u32 nand_pads_cnt;

	if (cpu_is_mx6q()) {
		nand_pads = mx6q_gpmi_nand;
		nand_pads_cnt = ARRAY_SIZE(mx6q_gpmi_nand);
	} else if (cpu_is_mx6dl()) {
		nand_pads = mx6dl_gpmi_nand;
		nand_pads_cnt = ARRAY_SIZE(mx6dl_gpmi_nand);

	}
	BUG_ON(!nand_pads);
	return mxc_iomux_v3_setup_multiple_pads(nand_pads, nand_pads_cnt);
}

static struct gpmi_nand_platform_data
mx6_gpmi_nand_platform_data __initdata = {
	.platform_init           = gpmi_nand_platform_init,
	.min_prop_delay_in_ns    = 5,
	.max_prop_delay_in_ns    = 9,
	.max_chip_count          = 1,
	.enable_bbt              = 1,
	.enable_ddr              = 0,
};

static int __init board_support_onfi_nand(char *p)
{
	mx6_gpmi_nand_platform_data.enable_ddr = 1;
	return 0;
}

early_param("onfi_support", board_support_onfi_nand);


static const struct anatop_thermal_platform_data
	mx6q_hdmidongle_anatop_thermal_data __initconst = {
		.name = "anatop_thermal",
};

static inline void mx6q_hdmidongle_init_uart(void)
{
	if (board_is_mx6_reva())
		imx6q_add_imx_uart(1, NULL);
	imx6q_add_imx_uart(0, NULL);
	imx6q_add_imx_uart(3, NULL);
}

static int mx6q_hdmidongle_spi_cs[] = {
	HDMIDONGLE_ECSPI2_CS0,
};

static const struct spi_imx_master mx6q_hdmidongle_spi_data __initconst = {
	.chipselect     = mx6q_hdmidongle_spi_cs,
	.num_chipselect = ARRAY_SIZE(mx6q_hdmidongle_spi_cs),
};



#ifdef CONFIG_MFD_WM831X
#if 0
/* 1.4125, 1.4125. 1.5 */
#define WM831X_DC1_ON_CONFIG_VAL            (0x48<<WM831X_DC1_ON_VSEL_SHIFT)
#define WM831X_DC2_ON_CONFIG_VAL            (0x48<<WM831X_DC2_ON_VSEL_SHIFT)
#define WM831X_DC3_ON_CONFIG_VAL            (0x1A<<WM831X_DC3_ON_VSEL_SHIFT)
#else
/* 1.375, 1.375. 1.5 */

#define WM831X_DC1_ON_CONFIG_VAL            (0x44<<WM831X_DC1_ON_VSEL_SHIFT)
#define WM831X_DC2_ON_CONFIG_VAL            (0x44<<WM831X_DC2_ON_VSEL_SHIFT)
#define WM831X_DC3_ON_CONFIG_VAL            (0x1A<<WM831X_DC3_ON_VSEL_SHIFT)

#endif

#define WM831X_DC1_DVS_MODE_VAL             (0x02<<WM831X_DC1_DVS_SRC_SHIFT)
#define WM831X_DC2_DVS_MODE_VAL             (0x02<<WM831X_DC2_DVS_SRC_SHIFT)

#define WM831X_DC1_DVS_CONTROL_VAL           (0x20<<WM831X_DC1_DVS_VSEL_SHIFT)
#define WM831X_DC2_DVS_CONTROL_VAL           (0x20<<WM831X_DC2_DVS_VSEL_SHIFT)

#define WM831X_DC1_DVS_MASK                  (WM831X_DC1_DVS_SRC_MASK|WM831X_DC1_DVS_VSEL_MASK)
#define WM831X_DC2_DVS_MASK                  (WM831X_DC2_DVS_SRC_MASK|WM831X_DC1_DVS_VSEL_MASK)

#define WM831X_DC1_DVS_VAL                   (WM831X_DC1_DVS_MODE_VAL|WM831X_DC1_DVS_CONTROL_VAL)
#define WM831X_DC2_DVS_VAL                   (WM831X_DC2_DVS_MODE_VAL|WM831X_DC2_DVS_CONTROL_VAL)

#define WM831X_GPN_FN_VAL_HW_EN              (0x0A<<WM831X_GPN_FN_SHIFT)
#define WM831X_GPN_FN_VAL_HW_CTL             (0x0C<<WM831X_GPN_FN_SHIFT)
#define WM831X_GPN_FN_VAL_DVS1               (0x08<<WM831X_GPN_FN_SHIFT)

#define WM831X_GPN_DIR_VAL                   (0x1<<WM831X_GPN_DIR_SHIFT)
#define WM831X_GPN_PULL_VAL                  (0x3<<WM831X_GPN_PULL_SHIFT)
#define WM831X_GPN_INT_MODE_VAL              (0x1<<WM831X_GPN_INT_MODE_SHIFT)
#define WM831X_GPN_POL_VAL                   (0x1<<WM831X_GPN_POL_SHIFT)
#define WM831X_GPN_ENA_VAL                   (0x1<<WM831X_GPN_ENA_SHIFT)

#define WM831X_GPIO7_8_9_MASK               (WM831X_GPN_DIR_MASK|WM831X_GPN_INT_MODE_MASK|WM831X_GPN_PULL_MASK|WM831X_GPN_POL_MASK|WM831X_GPN_FN_MASK)


#define WM831X_GPIO7_VAL                     (WM831X_GPN_DIR_VAL|WM831X_GPN_PULL_VAL|WM831X_GPN_INT_MODE_VAL|WM831X_GPN_POL_VAL|WM831X_GPN_ENA_VAL|WM831X_GPN_FN_VAL_HW_EN)
#define WM831X_GPIO8_VAL                     (WM831X_GPN_DIR_VAL|WM831X_GPN_PULL_VAL|WM831X_GPN_INT_MODE_VAL|WM831X_GPN_POL_VAL|WM831X_GPN_ENA_VAL|WM831X_GPN_FN_VAL_HW_CTL)
#define WM831X_GPIO9_VAL                     (WM831X_GPN_DIR_VAL|WM831X_GPN_PULL_VAL|WM831X_GPN_INT_MODE_VAL|WM831X_GPN_POL_VAL|WM831X_GPN_ENA_VAL|WM831X_GPN_FN_VAL_DVS1)

#define WM831X_STATUS_LED_MASK                0xC000
#define WM831X_STATUS_LED_ON                  (0x1 << 14)
#define WM831X_STATUS_LED_OFF                 (0x0 << 14)

static int wm8326_post_init(struct wm831x *wm831x)
{
	wm831x_set_bits(wm831x, WM831X_DC1_ON_CONFIG, WM831X_DC1_ON_VSEL_MASK, WM831X_DC1_ON_CONFIG_VAL);
	wm831x_set_bits(wm831x, WM831X_DC2_ON_CONFIG, WM831X_DC2_ON_VSEL_MASK, WM831X_DC2_ON_CONFIG_VAL);
	wm831x_set_bits(wm831x, WM831X_DC3_ON_CONFIG, WM831X_DC3_ON_VSEL_MASK, WM831X_DC3_ON_CONFIG_VAL);

	wm831x_set_bits(wm831x, WM831X_DC1_DVS_CONTROL, WM831X_DC1_DVS_MASK, WM831X_DC1_DVS_VAL);
	wm831x_set_bits(wm831x, WM831X_DC2_DVS_CONTROL, WM831X_DC2_DVS_MASK, WM831X_DC2_DVS_VAL);

	wm831x_set_bits(wm831x, WM831X_GPIO7_CONTROL, WM831X_GPIO7_8_9_MASK, WM831X_GPIO7_VAL);
	wm831x_set_bits(wm831x, WM831X_GPIO8_CONTROL, WM831X_GPIO7_8_9_MASK, WM831X_GPIO8_VAL);
	wm831x_set_bits(wm831x, WM831X_GPIO9_CONTROL, WM831X_GPIO7_8_9_MASK, WM831X_GPIO9_VAL);

    wm831x_set_bits(wm831x, WM831X_STATUS_LED_1 , WM831X_STATUS_LED_MASK, WM831X_STATUS_LED_OFF);
    wm831x_set_bits(wm831x, WM831X_STATUS_LED_2 , WM831X_STATUS_LED_MASK, WM831X_STATUS_LED_ON);
	return 0;
}

static struct wm831x_pdata hdmidongle_wm8326_pdata = {
	.post_init = wm8326_post_init,
};
#endif

static struct i2c_board_info mxc_i2c2_board_info[] __initdata = {
	{
#ifdef CONFIG_MFD_WM831X
	I2C_BOARD_INFO("wm8326", 0x34),
	.platform_data = &hdmidongle_wm8326_pdata,
#endif
	},
};

static struct spi_board_info wm8326_spi1_board_info[] __initdata = {
#if defined(CONFIG_MFD_WM831X_SPI)
	{
	/* The modalias must be the same as spi device driver name */
	.modalias	= "wm8326",
	.max_speed_hz	= 20000000,
	.bus_num	= 1,
	.chip_select	= 0,
	},
#endif
};

static void spi_device_init(void)
{
	spi_register_board_info(wm8326_spi1_board_info,
				ARRAY_SIZE(wm8326_spi1_board_info));
}

static struct imxi2c_platform_data mx6q_hdmidongle_i2c_data = {
	.bitrate = 100000,
};

static struct i2c_board_info mxc_i2c1_board_info[] __initdata = {
	{
		I2C_BOARD_INFO("mxc_hdmi_i2c", 0x50),
	},
};


static void imx6q_hdmidongle_usbotg_vbus(bool on)
{
	if (on)
		gpio_set_value(HDMIDONGLE_USB_OTG_PWR, 1);
	else
		gpio_set_value(HDMIDONGLE_USB_OTG_PWR, 0);
}

static void __init imx6q_hdmidongle_init_usb(void)
{
	int ret = 0;

	imx_otg_base = MX6_IO_ADDRESS(MX6Q_USB_OTG_BASE_ADDR);
	/* disable external charger detect,
	 * or it will affect signal quality at dp .
	 */
	ret = gpio_request(HDMIDONGLE_USB_OTG_PWR, "usb-pwr");
	if (ret) {
		pr_err("failed to get GPIO HDMIDONGLE_USB_OTG_PWR: %d\n",
			ret);
		return;
	}
	gpio_direction_output(HDMIDONGLE_USB_OTG_PWR, 0);
	/* keep USB host1 VBUS always on */
	if (board_is_mx6_reva()) {
		ret = gpio_request(HDMIDONGLE_USB_H1_PWR, "usb-h1-pwr");
		if (ret) {
			pr_err("failed to get GPIO HDMIDONGLE_USB_H1_PWR: %d\n",
				ret);
			return;
		}
		gpio_direction_output(HDMIDONGLE_USB_H1_PWR, 1);
	}
	mxc_iomux_set_gpr_register(1, 13, 1, 1);

	mx6_set_otghost_vbus_func(imx6q_hdmidongle_usbotg_vbus);
}


static struct viv_gpu_platform_data imx6q_gpu_pdata __initdata = {
	.reserved_mem_size = SZ_128M + SZ_64M,
};


static struct ipuv3_fb_platform_data hdmidongle_fb_data[] = {
	{/*fb0*/
	.disp_dev = "hdmi",
	.interface_pix_fmt = IPU_PIX_FMT_RGB24,
	.mode_str = "1920x1080M@60",
	.default_bpp = 32,
	.int_clk = false,
	},
};

static void hdmi_init(int ipu_id, int disp_id)
{
	int hdmi_mux_setting;

	if ((ipu_id > 1) || (ipu_id < 0)) {
		pr_err("Invalid IPU select for HDMI: %d. Set to 0\n", ipu_id);
		ipu_id = 0;
	}

	if ((disp_id > 1) || (disp_id < 0)) {
		pr_err("Invalid DI select for HDMI: %d. Set to 0\n", disp_id);
		disp_id = 0;
	}

	/* Configure the connection between IPU1/2 and HDMI */
	hdmi_mux_setting = 2*ipu_id + disp_id;

	/* GPR3, bits 2-3 = HDMI_MUX_CTL */
	mxc_iomux_set_gpr_register(3, 2, 2, hdmi_mux_setting);
	/* Set HDMI event as SDMA event2 while Chip version later than TO1.2 */
	if (hdmi_SDMA_check())
		mxc_iomux_set_gpr_register(0, 0, 1, 1);
}

/* On mx6x sabresd board i2c2 iomux with hdmi ddc,
 * the pins default work at i2c2 function,
 when hdcp enable, the pins should work at ddc function */

static void hdmi_enable_ddc_pin(void)
{
	if (cpu_is_mx6dl())
		mxc_iomux_v3_setup_multiple_pads(mx6dl_hdmidongle_hdmi_ddc_pads,
			ARRAY_SIZE(mx6dl_hdmidongle_hdmi_ddc_pads));
	else
		mxc_iomux_v3_setup_multiple_pads(mx6q_hdmidongle_hdmi_ddc_pads,
			ARRAY_SIZE(mx6q_hdmidongle_hdmi_ddc_pads));
}

static void hdmi_disable_ddc_pin(void)
{
	if (cpu_is_mx6dl())
		mxc_iomux_v3_setup_multiple_pads(mx6dl_hdmidongle_i2c2_pads,
			ARRAY_SIZE(mx6dl_hdmidongle_i2c2_pads));
	else
		mxc_iomux_v3_setup_multiple_pads(mx6q_hdmidongle_i2c2_pads,
			ARRAY_SIZE(mx6q_hdmidongle_i2c2_pads));
}


static struct fsl_mxc_hdmi_platform_data hdmi_data = {
	.init = hdmi_init,
	.enable_pins = hdmi_enable_ddc_pin,
	.disable_pins = hdmi_disable_ddc_pin,
	.phy_reg_vlev = 0x0294,
	.phy_reg_cksymtx = 0x800d,
};

static struct fsl_mxc_hdmi_core_platform_data hdmi_core_data = {
	.ipu_id = 0,
	.disp_id = 0,
};

static struct imx_ipuv3_platform_data ipu_data[] = {
	{
	.rev = 4,
	.csi_clk[0] = "clko_clk",
	}, {
	.rev = 4,
	.csi_clk[0] = "clko_clk",
	},
};

static void hdmidongle_suspend_enter(void)
{
	/* suspend preparation */
}

static void hdmidongle_suspend_exit(void)
{
	/* resume restore */
}
static const struct pm_platform_data mx6q_hdmidongle_pm_data __initconst = {
	.name = "imx_pm",
	.suspend_enter = hdmidongle_suspend_enter,
	.suspend_exit = hdmidongle_suspend_exit,
};

static struct regulator_consumer_supply hdmidongle_vmmc_consumers[] = {
	REGULATOR_SUPPLY("vmmc", "sdhci-esdhc-imx.1"),
	REGULATOR_SUPPLY("vmmc", "sdhci-esdhc-imx.2"),
	REGULATOR_SUPPLY("vmmc", "sdhci-esdhc-imx.3"),
};

static struct regulator_init_data hdmidongle_vmmc_init = {
	.num_consumer_supplies = ARRAY_SIZE(hdmidongle_vmmc_consumers),
	.consumer_supplies = hdmidongle_vmmc_consumers,
};

static struct fixed_voltage_config hdmidongle_vmmc_reg_config = {
	.supply_name		= "vmmc",
	.microvolts		= 3300000,
	.gpio			= -1,
	.init_data		= &hdmidongle_vmmc_init,
};

static struct platform_device hdmidongle_vmmc_reg_devices = {
	.name	= "reg-fixed-voltage",
	.id	= 3,
	.dev	= {
		.platform_data = &hdmidongle_vmmc_reg_config,
	},
};

#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
#define GPIO_BUTTON(gpio_num, ev_code, act_low, descr, wake, debounce)	\
{								\
	.gpio		= gpio_num,				\
	.type		= EV_KEY,				\
	.code		= ev_code,				\
	.active_low	= act_low,				\
	.desc		= "btn " descr,				\
	.wakeup		= wake,					\
	.debounce_interval = debounce,				\
}

static struct gpio_keys_button hdmidongle_reva_buttons[] = {
	GPIO_BUTTON(HDMIDONGLE_REVA_POWER_KEY, KEY_POWER, 1, "power", 1, 1),
};

static struct gpio_keys_platform_data hdmidongle_reva_button_data = {
	.buttons	= hdmidongle_reva_buttons,
	.nbuttons	= ARRAY_SIZE(hdmidongle_reva_buttons),
};

static struct platform_device hdmidongle_reva_button_device = {
	.name		= "gpio-keys",
	.id		= -1,
	.num_resources  = 0,
	.dev		= {
		.platform_data = &hdmidongle_reva_button_data,
	}
};

static struct gpio_keys_button hdmidongle_revb_buttons[] = {
	GPIO_BUTTON(HDMIDONGLE_REVB_POWER_KEY, KEY_POWER, 1, "power", 1, 1),
};

static struct gpio_keys_platform_data hdmidongle_revb_button_data = {
	.buttons	= hdmidongle_revb_buttons,
	.nbuttons	= ARRAY_SIZE(hdmidongle_revb_buttons),
};

static struct platform_device hdmidongle_revb_button_device = {
	.name		= "gpio-keys",
	.id		= -1,
	.num_resources  = 0,
	.dev		= {
		.platform_data = &hdmidongle_revb_button_data,
	}
};


static void __init imx6q_add_device_buttons(void)
{
	if (board_is_mx6_reva())
		platform_device_register(&hdmidongle_reva_button_device);
	else
		platform_device_register(&hdmidongle_revb_button_device);
}
#else
static void __init imx6q_add_device_buttons(void) {}
#endif

static struct mxc_dvfs_platform_data hdmidongle_dvfscore_data = {
	#ifdef CONFIG_MX6_INTER_LDO_BYPASS
	.reg_id = "VDDCORE",
	#else
	.reg_id = "cpu_vddgp",
	.soc_id = "cpu_vddsoc",
	.pu_id = "cpu_vddvpu",
	#endif
	.clk1_id = "cpu_clk",
	.clk2_id = "gpc_dvfs_clk",
	.gpc_cntr_offset = MXC_GPC_CNTR_OFFSET,
	.ccm_cdcr_offset = MXC_CCM_CDCR_OFFSET,
	.ccm_cacrr_offset = MXC_CCM_CACRR_OFFSET,
	.ccm_cdhipr_offset = MXC_CCM_CDHIPR_OFFSET,
	.prediv_mask = 0x1F800,
	.prediv_offset = 11,
	.prediv_val = 3,
	.div3ck_mask = 0xE0000000,
	.div3ck_offset = 29,
	.div3ck_val = 2,
	.emac_val = 0x08,
	.upthr_val = 25,
	.dnthr_val = 9,
	.pncthr_val = 33,
	.upcnt_val = 10,
	.dncnt_val = 10,
	.delay_time = 80,
};

static void __init fixup_mxc_board(struct machine_desc *desc, struct tag *tags,
				   char **cmdline, struct meminfo *mi)
{
	char *str;
	struct tag *t;
	int i = 0;
	struct ipuv3_fb_platform_data *pdata_fb = hdmidongle_fb_data;

	for_each_tag(t, tags) {
		if (t->hdr.tag == ATAG_CMDLINE) {
			str = t->u.cmdline.cmdline;
			str = strstr(str, "fbmem=");
			if (str != NULL) {
				str += 6;
				pdata_fb[i++].res_size[0] = memparse(str, &str);
				while (*str == ',' &&
					i < ARRAY_SIZE(hdmidongle_fb_data)) {
					str++;
					pdata_fb[i++].res_size[0] = memparse(str, &str);
				}
			}
			break;
		}
	}
}

#define SNVS_LPCR 0x38
static void mx6_snvs_poweroff(void)
{

	void __iomem *mx6_snvs_base =  MX6_IO_ADDRESS(MX6Q_SNVS_BASE_ADDR);
	u32 value;
	value = readl(mx6_snvs_base + SNVS_LPCR);
	/*set TOP and DP_EN bit*/
	writel(value | 0x60, mx6_snvs_base + SNVS_LPCR);
}

#ifdef CONFIG_IMX_PCIE
static const struct imx_pcie_platform_data mx6_hdmidongle_pcie_data __initconst = {
	.pcie_pwr_en	= HDMIDONGLE_PCIE_PWR_EN,
	.pcie_rst	= HDMIDONGLE_PCIE_RST,
	.pcie_wake_up	= HDMIDONGLE_PCIE_WAKE,
	.pcie_dis	= HDMIDONGLE_PCIE_DIS,
};
#endif

/*!
 * Board specific initialization.
 */
static void __init mx6_hdmidongle_board_init(void)
{
	int i;

	if (cpu_is_mx6q()) {
		if (board_is_mx6_revb() || board_is_mx6_revc())
			mxc_iomux_v3_setup_multiple_pads(mx6q_hdmidongle_rev_b_pads,
				ARRAY_SIZE(mx6q_hdmidongle_rev_b_pads));
		else
			mxc_iomux_v3_setup_multiple_pads(mx6q_hdmidongle_rev_a_pads,
				ARRAY_SIZE(mx6q_hdmidongle_rev_a_pads));
	} else if (cpu_is_mx6dl()) {
		if (board_is_mx6_revb() || board_is_mx6_revc())
			mxc_iomux_v3_setup_multiple_pads(mx6dl_hdmidongle_rev_b_pads,
				ARRAY_SIZE(mx6dl_hdmidongle_rev_b_pads));
		else
			mxc_iomux_v3_setup_multiple_pads(mx6dl_hdmidongle_rev_a_pads,
				ARRAY_SIZE(mx6dl_hdmidongle_rev_a_pads));
	}

	gp_reg_id = hdmidongle_dvfscore_data.reg_id;
	soc_reg_id = hdmidongle_dvfscore_data.soc_id;
	pu_reg_id = hdmidongle_dvfscore_data.pu_id;
	mx6q_hdmidongle_init_uart();

	/*
	 * MX6DL/Solo only supports single IPU
	 * The following codes are used to change ipu id
	 * and display id information for MX6DL/Solo. Then
	 * register 1 IPU device and up to 2 displays for
	 * MX6DL/Solo
	 */
	if (cpu_is_mx6dl())
		hdmi_core_data.disp_id = 0;

	imx6q_add_mxc_hdmi_core(&hdmi_core_data);

	imx6q_add_ipuv3(0, &ipu_data[0]);
	if (cpu_is_mx6q())
		imx6q_add_ipuv3(1, &ipu_data[1]);
	for (i = 0; i < ARRAY_SIZE(hdmidongle_fb_data); i++)
		imx6q_add_ipuv3fb(i, &hdmidongle_fb_data[i]);

	imx6q_add_vdoa();

	imx6q_add_v4l2_output(0);

	imx6q_add_imx_snvs_rtc();

	imx6q_add_imx_i2c(1, &mx6q_hdmidongle_i2c_data);
    imx6q_add_imx_i2c(2, &mx6q_hdmidongle_i2c_data);

	i2c_register_board_info(1, mxc_i2c1_board_info,
			ARRAY_SIZE(mxc_i2c1_board_info));


	i2c_register_board_info(2, mxc_i2c2_board_info,
			ARRAY_SIZE(mxc_i2c2_board_info));


	/* SPI */
	imx6q_add_ecspi(1, &mx6q_hdmidongle_spi_data);
	spi_device_init();

	imx6q_add_mxc_hdmi(&hdmi_data);

	imx6q_add_anatop_thermal_imx(1, &mx6q_hdmidongle_anatop_thermal_data);
	imx6q_add_pm_imx(0, &mx6q_hdmidongle_pm_data);
	/* Move sd3 to first because sd3 connect to emmc.
	   Mfgtools want emmc is mmcblk0 and other sd card is mmcblk1.
	*/
	if (board_is_mx6_revc())
		imx6q_add_sdhci_usdhc_imx(2, &mx6q_hdmidongle_revc_sd3_data);
	else
		imx6q_add_sdhci_usdhc_imx(2, &mx6q_hdmidongle_sd3_data);
	imx6q_add_sdhci_usdhc_imx(1, &mx6q_hdmidongle_sd2_data);
	if (board_is_mx6_reva())
		imx6q_add_sdhci_usdhc_imx(0, &mx6q_hdmidongle_sd1_data);
	imx_add_viv_gpu(&imx6_gpu_data, &imx6q_gpu_pdata);
	imx6q_hdmidongle_init_usb();

	imx6q_add_vpu();

	platform_device_register(&hdmidongle_vmmc_reg_devices);

	imx6q_add_otp();
	imx6q_add_viim();
	imx6q_add_imx2_wdt(0, NULL);
	imx6q_add_dma();
	if (board_is_mx6_revb() || board_is_mx6_revc())
		imx6q_add_gpmi(&mx6_gpmi_nand_platform_data);

	imx6q_add_dvfs_core(&hdmidongle_dvfscore_data);
	#ifndef CONFIG_MX6_INTER_LDO_BYPASS
	mx6_cpu_regulator_init();
	#endif

	imx6q_add_device_buttons();

	imx6q_add_hdmi_soc();
	imx6q_add_hdmi_soc_dai();

	if (board_is_mx6_reva()) {
		gpio_request(HDMIDONGLE_BT_RST, "bt_reset");
		gpio_direction_output(HDMIDONGLE_BT_RST, 1);
		gpio_set_value(HDMIDONGLE_BT_RST, 1);
		msleep(1000);
		gpio_request(HDMIDONGLE_BT_EN, "bt_en");
		gpio_direction_output(HDMIDONGLE_BT_EN, 1);
		gpio_set_value(HDMIDONGLE_BT_EN, 1);

		msleep(1000);
		gpio_request(HDMIDONGLE_WL_EN, "wl_en");
		gpio_direction_output(HDMIDONGLE_WL_EN, 1);
		gpio_set_value(HDMIDONGLE_WL_EN, 1);
		msleep(1000);
	} else if (board_is_mx6_revb() || board_is_mx6_revc()) {
		/* Add PCIe RC interface support */
#ifdef CONFIG_IMX_PCIE
		imx6q_add_pcie(&mx6_hdmidongle_pcie_data);
#endif
	}
	pm_power_off = mx6_snvs_poweroff;
	imx6q_add_busfreq();
}

extern void __iomem *twd_base;
static void __init mx6_hdmidongle_timer_init(void)
{
	struct clk *uart_clk;
#ifdef CONFIG_LOCAL_TIMERS
	twd_base = ioremap(LOCAL_TWD_ADDR, SZ_256);
	BUG_ON(!twd_base);
#endif
	mx6_clocks_init(32768, 24000000, 0, 0);

	uart_clk = clk_get_sys("imx-uart.0", NULL);
	early_console_setup(UART4_BASE_ADDR, uart_clk);
}

static struct sys_timer mx6_hdmidongle_timer = {
	.init   = mx6_hdmidongle_timer_init,
};

static void __init mx6q_hdmidongle_reserve(void)
{
	phys_addr_t phys;
	int i;

#if defined(CONFIG_MXC_GPU_VIV) || defined(CONFIG_MXC_GPU_VIV_MODULE)
	if (imx6q_gpu_pdata.reserved_mem_size) {
		phys = memblock_alloc_base(imx6q_gpu_pdata.reserved_mem_size,
					   SZ_4K, SZ_1G);
		memblock_remove(phys, imx6q_gpu_pdata.reserved_mem_size);
		imx6q_gpu_pdata.reserved_mem_base = phys;
	}
#endif
#if defined(CONFIG_ION)
	if (imx_ion_data.heaps[0].size) {
		phys = memblock_alloc(imx_ion_data.heaps[0].size, SZ_4K);
		memblock_remove(phys, imx_ion_data.heaps[0].size);
		imx_ion_data.heaps[0].base = phys;
	}
#endif

	for (i = 0; i < ARRAY_SIZE(hdmidongle_fb_data); i++)
		if (hdmidongle_fb_data[i].res_size[0]) {
			/* reserve for background buffer */
			phys = memblock_alloc(hdmidongle_fb_data[i].res_size[0],
						SZ_4K);
			memblock_remove(phys, hdmidongle_fb_data[i].res_size[0]);
			hdmidongle_fb_data[i].res_base[0] = phys;
		}
}

/*
 * initialize __mach_desc_MX6Q_HDMIDONGLE data structure.
 */
MACHINE_START(MX6Q_HDMIDONGLE, "Freescale i.MX 6Quad/DualLite HDMI Dongle Board")
	/* Maintainer: Freescale Semiconductor, Inc. */
	.boot_params = MX6_PHYS_OFFSET + 0x100,
	.fixup = fixup_mxc_board,
	.map_io = mx6_map_io,
	.init_irq = mx6_init_irq,
	.init_machine = mx6_hdmidongle_board_init,
	.timer = &mx6_hdmidongle_timer,
	.reserve = mx6q_hdmidongle_reserve,
MACHINE_END