aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/board-p8ltevzw-modems.c
blob: a2e0540828b65cfa173b569fe0b5b48bfca171b7 (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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
/* linux/arch/arm/mach-xxxx/board-p8vzw-modems.c
 * Copyright (C) 2010 Samsung Electronics. All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/regulator/consumer.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/clk.h>

/* inlcude platform specific file */
#include <linux/platform_data/modem_na.h>
#include <mach/sec_modem.h>
#include <mach/gpio.h>
#include <mach/gpio-exynos4.h>
#include <plat/gpio-cfg.h>
#include <mach/regs-mem.h>
#include <plat/regs-srom.h>

#include <plat/devs.h>
#include <plat/ehci.h>


#define IDPRAM_SIZE	0x4000
#define IDPRAM_PHY_START	0x13A00000
#define IDPRAM_PHY_END (IDPRAM_PHY_START + IDPRAM_SIZE)
#define MAGIC_DMDL                      0x4445444C

/*S5PV210 Interanl Dpram Special Function Register*/
#define IDPRAM_MIFCON_INT2APEN      (1<<2)
#define IDPRAM_MIFCON_INT2MSMEN     (1<<3)
#define IDPRAM_MIFCON_DMATXREQEN_0  (1<<16)
#define IDPRAM_MIFCON_DMATXREQEN_1  (1<<17)
#define IDPRAM_MIFCON_DMARXREQEN_0  (1<<18)
#define IDPRAM_MIFCON_DMARXREQEN_1  (1<<19)
#define IDPRAM_MIFCON_FIXBIT        (1<<20)

#define IDPRAM_MIFPCON_ADM_MODE     (1<<6) /* mux / demux mode  */

#define IDPRAM_DMA_ADR_MASK         0x3FFF
#define IDPRAM_DMA_TX_ADR_0         /* shift 0 */
#define IDPRAM_DMA_TX_ADR_1         /* shift 16  */
#define IDPRAM_DMA_RX_ADR_0         /* shift 0  */
#define IDPRAM_DMA_RX_ADR_1         /* shift 16  */

#define IDPRAM_SFR_PHYSICAL_ADDR 0x13A08000
#define IDPRAM_SFR_SIZE 0x1C

#define IDPRAM_ADDRESS_DEMUX

static int __init init_modem(void);
static int p8_lte_ota_reset(void);

struct idpram_sfr_reg {
	unsigned int2ap;
	unsigned int2msm;
	unsigned mifcon;
	unsigned mifpcon;
	unsigned msmintclr;
	unsigned dma_tx_adr;
	unsigned dma_rx_adr;
};

/*S5PV210 Internal Dpram GPIO table*/
struct idpram_gpio_data {
	unsigned num;
	unsigned cfg;
	unsigned pud;
	unsigned val;
};

static volatile void __iomem *s5pv310_dpram_sfr_va;

static struct idpram_gpio_data idpram_gpio_address[] = {
#ifdef IDPRAM_ADDRESS_DEMUX
	{
		.num = EXYNOS4210_GPE1(0),	/* MSM_ADDR 0 -12 */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(1),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(2),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(3),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(4),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(5),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(6),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE1(7),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE2(0),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE2(1),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE2(2),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE2(3),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE2(4),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE2(5),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	},
#endif
};

static struct idpram_gpio_data idpram_gpio_data[] = {
	{
		.num = EXYNOS4210_GPE3(0), /* MSM_DATA 0 - 15 */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(1),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(2),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(3),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(4),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(5),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(6),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE3(7),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(0),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(1),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(2),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(3),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(4),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(5),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(6),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE4(7),
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	},
};

static struct idpram_gpio_data idpram_gpio_init_control[] = {
	{
		.num = EXYNOS4210_GPE0(1), /* MDM_CSn */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE0(0), /* MDM_WEn */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE0(2), /* MDM_Rn */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	}, {
		.num = EXYNOS4210_GPE0(3), /* MDM_IRQn */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_UP,
	},
#ifndef IDPRAM_ADDRESS_DEMUX
	{
		.num = EXYNOS4210_GPE0(4), /* MDM_ADVN */
		.cfg = S3C_GPIO_SFN(0x2),
		.pud = S3C_GPIO_PULL_NONE,
	},
#endif
};

static void idpram_gpio_cfg(struct idpram_gpio_data *gpio)
{
	printk(KERN_DEBUG "MIF: idpram set gpio num=%d, cfg=0x%x, pud=%d, val=%d\n",
		gpio->num, gpio->cfg, gpio->pud, gpio->val);

	s3c_gpio_cfgpin(gpio->num, gpio->cfg);
	s3c_gpio_setpull(gpio->num, gpio->pud);
	if (gpio->val)
		gpio_set_value(gpio->num, gpio->val);
}

static void idpram_gpio_init(void)
{
	int i;

#ifdef IDPRAM_ADDRESS_DEMUX
	for (i = 0; i < ARRAY_SIZE(idpram_gpio_address); i++)
		idpram_gpio_cfg(&idpram_gpio_address[i]);
#endif

	for (i = 0; i < ARRAY_SIZE(idpram_gpio_data); i++)
		idpram_gpio_cfg(&idpram_gpio_data[i]);

	for (i = 0; i < ARRAY_SIZE(idpram_gpio_init_control); i++)
		idpram_gpio_cfg(&idpram_gpio_init_control[i]);
}

static void idpram_sfr_init(void)
{
	volatile struct idpram_sfr_reg __iomem *sfr = s5pv310_dpram_sfr_va;

	sfr->mifcon = (IDPRAM_MIFCON_FIXBIT | IDPRAM_MIFCON_INT2APEN |
		IDPRAM_MIFCON_INT2MSMEN);
#ifndef IDPRAM_ADDRESS_DEMUX
	sfr->mifpcon = (IDPRAM_MIFPCON_ADM_MODE);
#endif
}

static void idpram_init(void)
{
	struct clk *clk;

	/* enable internal dpram clock */
	clk = clk_get(NULL, "modem");
	if (!clk)
		pr_err("MIF: idpram failed to get clock %s\n", __func__);

	clk_enable(clk);

	if (!s5pv310_dpram_sfr_va) {
		s5pv310_dpram_sfr_va = (struct idpram_sfr_reg __iomem *)
		ioremap_nocache(IDPRAM_SFR_PHYSICAL_ADDR, IDPRAM_SFR_SIZE);
		if (!s5pv310_dpram_sfr_va) {
			printk(KERN_ERR "MIF: idpram_sfr_base io-remap fail\n");
			/*iounmap(idpram_base);*/
		}
	}

	idpram_sfr_init();
}

static void idpram_clr_intr(void)
{
	volatile struct idpram_sfr_reg __iomem *sfr = s5pv310_dpram_sfr_va;
	sfr->msmintclr = 0xFF;
}


/*
	magic_code +
	access_enable +
	fmt_tx_head + fmt_tx_tail + fmt_tx_buff +
	raw_tx_head + raw_tx_tail + raw_tx_buff +
	fmt_rx_head + fmt_rx_tail + fmt_rx_buff +
	raw_rx_head + raw_rx_tail + raw_rx_buff +
	padding +
	mbx_cp2ap +
	mbx_ap2cp
 =	2 +
	2 +
	2 + 2 + 2044 +
	2 + 2 + 6128 +
	2 + 2 + 2044 +
	2 + 2 + 6128 +
	16 +
	2 +
	2
 =	16384
*/

#define CBP_DP_FMT_TX_BUFF_SZ	2044
#define CBP_DP_RAW_TX_BUFF_SZ	6128
#define CBP_DP_FMT_RX_BUFF_SZ	2044
#define CBP_DP_RAW_RX_BUFF_SZ	6128

#define MAX_CBP_IDPRAM_IPC_DEV	(IPC_RAW + 1)	/* FMT, RAW */

/*
** CDMA target platform data
*/
static struct modem_io_t cdma_io_devices[] = {
	[0] = {
		.name = "multipdp",
		.id = 0x1,
		.format = IPC_MULTI_RAW,
		.io_type = IODEV_DUMMY,
		.link = LINKDEV_DPRAM,
	},
	[1] = {
		.name = "cdma_ipc0",
		.id = 0x1,
		.format = IPC_FMT,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
	[2] = {
		.name = "cdma_rfs0",
		.id = 0x33,		/* 0x13 (ch.id) | 0x20 (mask) */
		.format = IPC_RAW,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
	[3] = {
		.name = "cdma_boot0",
		.id = 0x1,
		.format = IPC_BOOT,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
	[4] = {
		.name = "cdma_rmnet0",
		.id = 0x2A,
		.format = IPC_RAW,
		.io_type = IODEV_NET,
		.link = LINKDEV_DPRAM,
	},
	[5] = {
		.name = "cdma_rmnet1",
		.id = 0x2B,
		.format = IPC_RAW,
		.io_type = IODEV_NET,
		.link = LINKDEV_DPRAM,
	},
	[6] = {
		.name = "cdma_rmnet2",
		.id = 0x2C,
		.format = IPC_RAW,
		.io_type = IODEV_NET,
		.link = LINKDEV_DPRAM,
	},
	[7] = {
		.name = "cdma_rmnet3",
		.id = 0x2D,
		.format = IPC_RAW,
		.io_type = IODEV_NET,
		.link = LINKDEV_DPRAM,
	},
	[8] = {
		.name = "cdma_rmnet4",
		.id = 0x27,
		.format = IPC_RAW,
		.io_type = IODEV_NET,
		.link = LINKDEV_DPRAM,
	},
	[9] = {
		.name = "cdma_rmnet5", /* DM Port IO device */
		.id = 0x3A,
		.format = IPC_RAW,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
	[10] = {
		.name = "cdma_rmnet6", /* AT CMD IO device */
		.id = 0x31,
		.format = IPC_RAW,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
	[11] = {
		.name = "cdma_ramdump0",
		.id = 0x1,
		.format = IPC_RAMDUMP,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
		[12] = {
		.name = "cdma_cplog", /* cp log io-device */
		.id = 0x3D,
		.format = IPC_RAW,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
		[13] = {
		.name = "cdma_router", /* AT commands */
		.id = 0x39,
		.format = IPC_RAW,
		.io_type = IODEV_MISC,
		.link = LINKDEV_DPRAM,
	},
};

static struct modem_data cdma_modem_data = {
	.name = "cbp7.1",

	.gpio_cp_on        = GPIO_PHONE_ON,
	.gpio_cp_off	= GPIO_VIA_PS_HOLD_OFF,
	.gpio_cp_reset     = GPIO_CP_RST,
	.gpio_pda_active   = GPIO_PDA_ACTIVE,
	.gpio_phone_active = GPIO_PHONE_ACTIVE,
	.gpio_ap_wakeup = GPIO_CP_AP_DPRAM_INT,
	.gpio_mbx_intr = GPIO_VIA_DPRAM_INT_N,

	.modem_net  = CDMA_NETWORK,
	.modem_type = VIA_CBP71,
	.link_type = LINKDEV_DPRAM,

	.num_iodevs = ARRAY_SIZE(cdma_io_devices),
	.iodevs     = cdma_io_devices,

	.clear_intr = idpram_clr_intr,
	.ota_reset = p8_lte_ota_reset,
	.sfr_init = idpram_sfr_init,
	.align = 1, /* Adjust the IPC raw and Multi Raw HDLC buffer offsets */
};

static struct resource cdma_modem_res[] = {
	[0] = {
		.name = "dpram",
		.start = IDPRAM_PHY_START,
		.end = IDPRAM_PHY_END,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.name = "dpram_irq",
		.start = IRQ_MODEM_IF,
		.end = IRQ_MODEM_IF,
		.flags = IORESOURCE_IRQ,
	},
};

static struct platform_device cdma_modem = {
	.name = "modem_if",
	.id = 1,
	.num_resources = ARRAY_SIZE(cdma_modem_res),
	.resource = cdma_modem_res,
	.dev = {
		.platform_data = &cdma_modem_data,
	},
};
static int p8_lte_ota_reset(void)
{
	unsigned gpio_cp_rst = cdma_modem_data.gpio_cp_reset;
	unsigned gpio_cp_on = cdma_modem_data.gpio_cp_on;
	unsigned int *magickey_va;
	int i;

	pr_err("[MODEM_IF] %s Modem OTA reset\n", __func__);
	magickey_va = ioremap_nocache(IDPRAM_PHY_START, sizeof(unsigned int));
	if (!magickey_va) {
		pr_err("%s: ioremap fail\n", __func__);
		return -ENOMEM;
	}

	gpio_set_value(gpio_cp_on, 1);
	msleep(100);
	gpio_set_value(gpio_cp_rst, 0);

	for (i = 0; i < 3; i++) {
		*magickey_va = MAGIC_DMDL;
		if (*magickey_va == MAGIC_DMDL) {
			pr_err("magic key is ok!");
			break;
		}
	}

	msleep(500);
	gpio_set_value(gpio_cp_rst, 1);
	for (i = 0; i < 3; i++) {
		*magickey_va = MAGIC_DMDL;
		if (*magickey_va == MAGIC_DMDL) {
			pr_err("magic key is ok!");
			break;
		}
	}

	iounmap(magickey_va);

	return 0;
}
static void config_cdma_modem_gpio(void)
{
	int err;
	unsigned gpio_cp_on = cdma_modem_data.gpio_cp_on;
	unsigned gpio_cp_off = cdma_modem_data.gpio_cp_off;
	unsigned gpio_cp_rst = cdma_modem_data.gpio_cp_reset;
	unsigned gpio_pda_active = cdma_modem_data.gpio_pda_active;
	unsigned gpio_phone_active = cdma_modem_data.gpio_phone_active;
	unsigned gpio_ap_wakeup = cdma_modem_data.gpio_ap_wakeup;

	pr_info("MIF: <%s>\n", __func__);

	if (gpio_cp_on) {
		err = gpio_request(gpio_cp_on, "VIACP_ON");
		if (err)
			pr_err("fail to request gpio %s\n", "VIACP_ON");
		 else
			gpio_direction_output(gpio_cp_on, 0);
			}

	if (gpio_cp_rst) {
		err = gpio_request(gpio_cp_rst, "VAICP_RST");
		if (err)
			pr_err("fail to request gpio %s\n", "VIACP_RST");
		 else
			gpio_direction_output(gpio_cp_rst, 0);
			}

	if (gpio_cp_off) {
		err = gpio_request(gpio_cp_off, "VAICP_OFF");
		if (err)
			pr_err("fail to request gpio %s\n", "VIACP_OFF");
		 else
			gpio_direction_output(gpio_cp_off, 1);
			}

	if (gpio_pda_active) {
		err = gpio_request(gpio_pda_active, "PDA_ACTIVE");
		if (err)
			pr_err("fail to request gpio %s\n", "PDA_ACTIVE");
		 else
			gpio_direction_output(gpio_pda_active, 0);
		}

	if (gpio_phone_active) {
		err = gpio_request(gpio_phone_active, "PHONE_ACTIVE");
		if (err) {
			pr_err("fail to request gpio %s\n", "PHONE_ACTIVE");
		} else {
			s3c_gpio_cfgpin(gpio_phone_active, S3C_GPIO_SFN(0xF));
			s3c_gpio_setpull(gpio_phone_active, S3C_GPIO_PULL_NONE);
		}
	}
	if (gpio_ap_wakeup) {
		err = gpio_request(GPIO_CP_AP_DPRAM_INT, "HOST_WAKEUP");
		if (err) {
			pr_err("fail to request gpio %s\n", "HOST_WAKEUP");
		} else {
			s3c_gpio_cfgpin(GPIO_CP_AP_DPRAM_INT, \
			S3C_GPIO_SFN(0xF));
			s3c_gpio_setpull(GPIO_CP_AP_DPRAM_INT, \
			S3C_GPIO_PULL_NONE);
			}
	}

}

/* lte target platform data */
static struct modem_io_t lte_io_devices[] = {
	[0] = {
	.name = "lte_ipc0",
	.id = 0x1,
	.format = IPC_FMT,
	.io_type = IODEV_MISC,
	.link = LINKDEV_USB,
	},
	[1] = {
	.name = "lte_rmnet0",
	.id = 0x2A,
	.format = IPC_RAW,
	.io_type = IODEV_NET,
	.link = LINKDEV_USB,
	},
	[2] = {
	.name = "lte_rfs0",
	.id = 0x0,
	.format = IPC_RFS,
	.io_type = IODEV_MISC,
	.link = LINKDEV_USB,
	},
	[3] = {
	.name = "lte_boot0",
	.id = 0x0,
	.format = IPC_BOOT,
	.io_type = IODEV_MISC,
	.link = LINKDEV_USB,
	},
	[4] = {
	.name = "lte_rmnet1",
	.id = 0x2B,
	.format = IPC_RAW,
	.io_type = IODEV_NET,
	.link = LINKDEV_USB,
	},
	[5] = {
	.name = "lte_rmnet2",
	.id = 0x2C,
	.format = IPC_RAW,
	.io_type = IODEV_NET,
	.link = LINKDEV_USB,
	},
	[6] = {
	.name = "lte_rmnet3",
	.id = 0x2D,
	.format = IPC_RAW,
	.io_type = IODEV_NET,
	.link = LINKDEV_USB,
	},
	[7] = {
	.name = "lte_multipdp",
	.id = 0x1,
	.format = IPC_MULTI_RAW,
	.io_type = IODEV_DUMMY,
	.link = LINKDEV_USB,
	},
	 [8] = {
	.name = "lte_rmnet4", /* DM Port io-device */
	.id = 0x3F,
	.format = IPC_RAW,
	.io_type = IODEV_MISC,
	.link = LINKDEV_USB,
	},
	[9] = {
	.name = "lte_ramdump0",
	.id = 0x0,
	.format = IPC_RAMDUMP,
	.io_type = IODEV_MISC,
	.link = LINKDEV_USB,
	},
};

static struct modemlink_pm_data lte_link_pm_data = {
	.name = "lte_link_pm",

	.gpio_link_enable = 0,
	.gpio_link_active  = GPIO_AP2LTE_STATUS,
	.gpio_link_hostwake = GPIO_LTE2AP_WAKEUP,
	.gpio_link_slavewake = GPIO_AP2LTE_WAKEUP,

	/*
	.port_enable = host_port_enable,
	.freqlock = ATOMIC_INIT(0),
	.cpufreq_lock = exynos_cpu_frequency_lock,
	.cpufreq_unlock = exynos_cpu_frequency_unlock,
	*/
};

static struct modem_data lte_modem_data = {
	.name = "cmc220",
	.gpio_cp_on = GPIO_220_PMIC_PWRON,
	.gpio_reset_req_n = 0,
	.gpio_cp_reset = GPIO_CMC_RST,
	.gpio_pda_active = 0,/*NOT YET CONNECTED*/
	.gpio_phone_active = GPIO_LTE_ACTIVE,
	.gpio_cp_dump_int = GPIO_LTE_ACTIVE,/*TO BE CHECKED*/
	.gpio_cp_warm_reset = 0,
	/*.gpio_cp_off = GPIO_220_PMIC_PWRHOLD_OFF,*/
#ifdef CONFIG_LTE_MODEM_CMC220
	.gpio_cp_off = GPIO_LTE_PS_HOLD_OFF,
	.gpio_slave_wakeup = GPIO_AP2LTE_WAKEUP,
	.gpio_host_wakeup = GPIO_LTE2AP_WAKEUP,
	.gpio_host_active = GPIO_AP2LTE_STATUS,
#endif
	.modem_type = SEC_CMC220,
	.link_type = LINKDEV_USB,
	.modem_net = LTE_NETWORK,

	.num_iodevs = ARRAY_SIZE(lte_io_devices),
	.iodevs = lte_io_devices,

	.link_pm_data = &lte_link_pm_data,
};

static struct resource lte_modem_res[] = {
	[0] = {
		.name = "lte_phone_active",
		/* phone active irq */
		.start = IRQ_LTE_ACTIVE,
		.end = IRQ_LTE_ACTIVE,
		.flags = IORESOURCE_IRQ,
		},
	[1] = {
		.name = "lte_host_wakeup",
		/* host wakeup irq */
		.start = IRQ_LTE2AP_WAKEUP,
		.end = IRQ_LTE2AP_WAKEUP,
		.flags = IORESOURCE_IRQ,
	},
};

static struct platform_device lte_modem_wake = {
	.name = "modem_lte_wake",
	.id = -1,
};

static struct platform_device lte_modem = {
	.name = "modem_if",
	.id = 2,
	.num_resources = ARRAY_SIZE(lte_modem_res),
	.resource = lte_modem_res,
	.dev = {
		.platform_data = &lte_modem_data,
	},
};

static void lte_modem_cfg_gpio(void)
{
	unsigned gpio_cp_on = lte_modem_data.gpio_cp_on;
	unsigned gpio_cp_rst = lte_modem_data.gpio_cp_reset;
	unsigned gpio_phone_active = lte_modem_data.gpio_phone_active;
#ifdef CONFIG_LTE_MODEM_CMC220
	unsigned gpio_cp_off = lte_modem_data.gpio_cp_off;
	unsigned gpio_slave_wakeup = lte_modem_data.gpio_slave_wakeup;
	unsigned gpio_host_wakeup = lte_modem_data.gpio_host_wakeup;
	unsigned gpio_host_active = lte_modem_data.gpio_host_active;
#endif

	if (gpio_cp_on) {
		gpio_request(gpio_cp_on, "LTE_ON");
		gpio_direction_output(gpio_cp_on, 0);
		s3c_gpio_setpull(gpio_cp_on, S3C_GPIO_PULL_NONE);
	}

	if (gpio_cp_rst) {
		gpio_request(gpio_cp_rst, "LTE_RST");
		gpio_direction_output(gpio_cp_rst, 0);
		s3c_gpio_setpull(gpio_cp_rst, S3C_GPIO_PULL_NONE);
	}

	if (gpio_phone_active) {
		gpio_request(gpio_phone_active, "LTE_ACTIVE");
		gpio_direction_input(gpio_phone_active);
		s3c_gpio_setpull(gpio_phone_active, S3C_GPIO_PULL_DOWN);
		s3c_gpio_cfgpin(gpio_phone_active, S3C_GPIO_SFN(0xF));
	}

#ifdef CONFIG_LTE_MODEM_CMC220
	if (gpio_cp_off) {
		gpio_request(gpio_cp_off, "LTE_OFF");
		gpio_direction_output(gpio_cp_off, 1);
		s3c_gpio_setpull(gpio_cp_off, S3C_GPIO_PULL_NONE);
	}

	if (gpio_slave_wakeup) {
		gpio_request(gpio_slave_wakeup, "LTE_SLAVE_WAKEUP");
		gpio_direction_output(gpio_slave_wakeup, 0);
		s3c_gpio_setpull(gpio_slave_wakeup, S3C_GPIO_PULL_NONE);
	}

	if (gpio_host_wakeup) {
		gpio_request(gpio_host_wakeup, "LTE_HOST_WAKEUP");
		gpio_direction_input(gpio_host_wakeup);
		s3c_gpio_setpull(gpio_host_wakeup, S3C_GPIO_PULL_DOWN);
		s3c_gpio_cfgpin(gpio_host_wakeup, S3C_GPIO_SFN(0xF));
	}

	if (gpio_host_active) {
		gpio_request(gpio_host_active, "LTE_HOST_ACTIVE");
		gpio_direction_output(gpio_host_active, 1);
		s3c_gpio_setpull(gpio_host_active, S3C_GPIO_PULL_NONE);
	}
#endif
}

void set_host_states(struct platform_device *pdev, int type)
{
	int spin = 20;

	if (!type) {
		gpio_direction_output(lte_modem_data.gpio_host_active, type);
		return;
	}

	if (gpio_get_value(lte_modem_data.gpio_host_wakeup)) {
		gpio_direction_output(lte_modem_data.gpio_host_active, type);
		mdelay(10);
		while (spin--) {
			if (!gpio_get_value(lte_modem_data.gpio_host_wakeup))
				break;
			mdelay(10);
		}
	} else {
		pr_err("mif: host wakeup is low\n");
	}
}

int get_cp_active_state(void)
{
	return gpio_get_value(lte_modem_data.gpio_phone_active);
}

void set_hsic_lpa_states(int states)
{
	int val = gpio_get_value(lte_modem_data.gpio_cp_reset);

	pr_info("mif: %s: states = %d\n", __func__, states);

	if (val) {
		switch (states) {
		case STATE_HSIC_LPA_ENTER:
			/*
			gpio_set_value(lte_modem_data.gpio_link_active, 0);
			gpio_set_value(umts_modem_data.gpio_pda_active, 0);
			pr_info(LOG_TAG "set hsic lpa enter: "
				"active state (%d)" ", pda active (%d)\n",
				gpio_get_value(
					lte_modem_data.gpio_link_active),
				gpio_get_value(umts_modem_data.gpio_pda_active)
				);
			*/
			break;
		case STATE_HSIC_LPA_WAKE:
			/*
			gpio_set_value(umts_modem_data.gpio_pda_active, 1);
			pr_info(LOG_TAG "set hsic lpa wake: "
				"pda active (%d)\n",
				gpio_get_value(umts_modem_data.gpio_pda_active)
				);
			*/
			break;
		case STATE_HSIC_LPA_PHY_INIT:
			/*
			gpio_set_value(umts_modem_data.gpio_pda_active, 1);
			gpio_set_value(lte_modem_data.gpio_link_slavewake,
				1);
			pr_info(LOG_TAG "set hsic lpa phy init: "
				"slave wake-up (%d)\n",
				gpio_get_value(
					lte_modem_data.gpio_link_slavewake)
				);
			*/
			break;
		}
	}
}

/* lte_modem_wake must be registered before the ehci driver */
void __init modem_p8ltevzw_init(void)
{
	lte_modem_wake.dev.platform_data = &lte_modem_data;
	platform_device_register(&lte_modem_wake);
}

static int __init init_modem(void)
{
	pr_err("[MDM] <%s>\n", __func__);

	/* interanl dpram gpio configure */
	idpram_gpio_init();
	idpram_init();
	config_cdma_modem_gpio();
	platform_device_register(&cdma_modem);

	/* lte gpios configuration */
	lte_modem_cfg_gpio();
	platform_device_register(&lte_modem);

	return 0;
}
late_initcall(init_modem);