aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/mdm_hsic_pm.c
blob: 0ec7531964ddd5a92bc30d97fe6d74737f2cacfb (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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
/* linux/arch/arm/mach-xxxx/mdm_hsic_pm.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/module.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/kernel.h>
#include <linux/irq.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/usb.h>
#include <linux/pm_runtime.h>
#include <plat/gpio-cfg.h>
#include <linux/mdm_hsic_pm.h>
#include <linux/suspend.h>
#include <linux/wakelock.h>
#include <mach/subsystem_restart.h>
#include <mach/sec_modem.h>
#include <linux/msm_charm.h>
#include "mdm_private.h"
#include <linux/wakelock.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/usb/ehci_def.h>

#ifdef CONFIG_CPU_FREQ_TETHERING
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <mach/mdm2.h>
#endif
#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
#include <linux/usb/android_composite.h>
#endif
#ifdef CONFIG_USBIRQ_BALANCING_LTE_HIGHTP
#include <mach/mdm2.h>
#include <linux/cpu.h>
#include <linux/cpufreq_pegasusq.h>
#define dev_put devput
#include <linux/netdevice.h>
#undef dev_put
#include <mach/dev.h>
#endif

#define EXTERNAL_MODEM "external_modem"
#define EHCI_REG_DUMP
#define DEFAULT_RAW_WAKE_TIME (0*HZ)

BLOCKING_NOTIFIER_HEAD(mdm_reset_notifier_list);

/**
 * TODO:
 * pm notifier register
 *
 * think the way to use notifier to register or unregister device
 *
 * disconnect also can be notified
 *
 * block request under kernel power off seq.
 *
 * in suspend function if busy has set, return
 *
 */

/**
 * struct mdm_hsic_pm_data - hsic pm platform driver private data
 *	provide data and information for pm state transition
 *
 * @name:		name of this pm driver
 * @udev:		usb driver for resuming device from device request
 * @intf_cnt:		count of registered interface driver
 * @block_request:	block and ignore requested resume interrupt
 * @state_busy:		it is not determined to use, it can be replaced to
 *			rpm status check
 * @pm_notifier:	notifier block to control block_request variable
 *			block_reqeust set to true at PM_SUSPEND_PREPARE and
 *			release at PM_POST_RESUME
 *
 */
struct mdm_hsic_pm_data {
	struct list_head list;
	char name[32];

	struct usb_device *udev;
	int intf_cnt;

	/* control variables */
	struct notifier_block pm_notifier;
#ifdef CONFIG_CPU_FREQ_TETHERING
	struct notifier_block netdev_notifier;
#endif
#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
	struct notifier_block usb_composite_notifier;
#endif
#ifdef CONFIG_USBIRQ_BALANCING_LTE_HIGHTP
	struct notifier_block rndis_notifier;
	struct notifier_block cpu_hotplug_notifier;
	struct delayed_work hotplug_work;
	bool is_rndis_running;
#endif

	bool block_request;
	bool state_busy;
	atomic_t pmlock_cnt;
	bool shutdown;

	/* gpio-s and irq */
	int gpio_host_ready;
	int gpio_device_ready;
	int gpio_host_wake;
	int irq;

	/* wakelock for L0 - L2 */
	struct wake_lock l2_wake;

	/* wakelock for boot */
	struct wake_lock boot_wake;

	/* wakelock for fast dormancy */
	struct wake_lock fd_wake;
	long fd_wake_time; /* wake time for raw packet in jiffies */

	/* workqueue, work for delayed autosuspend */
	struct workqueue_struct *wq;
	struct delayed_work auto_rpm_start_work;
	struct delayed_work auto_rpm_restart_work;
	struct delayed_work request_resume_work;
	struct delayed_work fast_dormancy_work;

	struct mdm_hsic_pm_platform_data *mdm_pdata;

	/* QMICM mode value */
	bool qmicm_mode;
};

/* indicate wakeup from lpa state */
bool lpa_handling;

/* indicate receive hallo_packet_rx */
int hello_packet_rx;

#ifdef EHCI_REG_DUMP
struct dump_ehci_regs {
	unsigned caps_hc_capbase;
	unsigned caps_hcs_params;
	unsigned caps_hcc_params;
	unsigned reserved0;
	struct ehci_regs regs;
	unsigned port_usb;  /*0x54*/
	unsigned port_hsic0;
	unsigned port_hsic1;
	unsigned reserved[12];
	unsigned insnreg00;	/*0x90*/
	unsigned insnreg01;
	unsigned insnreg02;
	unsigned insnreg03;
	unsigned insnreg04;
	unsigned insnreg05;
	unsigned insnreg06;
	unsigned insnreg07;
};

struct s5p_ehci_hcd_stub {
	struct device *dev;
	struct usb_hcd *hcd;
	struct clk *clk;
	int power_on;
};
/* for EHCI register dump */
struct dump_ehci_regs sec_debug_ehci_regs;

#define pr_hcd(s, r) printk(KERN_DEBUG "hcd reg(%s):\t 0x%08x\n", s, r)
static void print_ehci_regs(struct dump_ehci_regs *base)
{
	pr_hcd("HCCPBASE", base->caps_hc_capbase);
	pr_hcd("HCSPARAMS", base->caps_hcs_params);
	pr_hcd("HCCPARAMS", base->caps_hcc_params);
	pr_hcd("USBCMD", base->regs.command);
	pr_hcd("USBSTS", base->regs.status);
	pr_hcd("USBINTR", base->regs.intr_enable);
	pr_hcd("FRINDEX", base->regs.frame_index);
	pr_hcd("CTRLDSSEGMENT", base->regs.segment);
	pr_hcd("PERIODICLISTBASE", base->regs.frame_list);
	pr_hcd("ASYNCLISTADDR", base->regs.async_next);
	pr_hcd("CONFIGFLAG", base->regs.configured_flag);
	pr_hcd("PORT0 Status/Control", base->port_usb);
	pr_hcd("PORT1 Status/Control", base->port_hsic0);
	pr_hcd("PORT2 Status/Control", base->port_hsic1);
	pr_hcd("INSNREG00", base->insnreg00);
	pr_hcd("INSNREG01", base->insnreg01);
	pr_hcd("INSNREG02", base->insnreg02);
	pr_hcd("INSNREG03", base->insnreg03);
	pr_hcd("INSNREG04", base->insnreg04);
	pr_hcd("INSNREG05", base->insnreg05);
	pr_hcd("INSNREG06", base->insnreg06);
	pr_hcd("INSNREG07", base->insnreg07);
}

void debug_ehci_reg_dump(struct device *hdev)
{
	struct s5p_ehci_hcd_stub *s5p_ehci = dev_get_drvdata(hdev);
	struct usb_hcd *hcd = s5p_ehci->hcd;
	char *buf = (char *)&sec_debug_ehci_regs;
	pr_info("%s\n", __func__);
	pr_info("EHCI %s, %s\n", dev_driver_string(hdev), dev_name(hdev));

	print_ehci_regs(hcd->regs);

	memcpy(buf, hcd->regs, 0xB);
	memcpy(buf + 0x10, hcd->regs + 0x10, 0x1F);
	memcpy(buf + 0x50, hcd->regs + 0x50, 0xF);
	memcpy(buf + 0x90, hcd->regs + 0x90, 0x1F);
}
#else
#define debug_ehci_reg_dump (NULL)
#endif

/**
 * hsic pm device list for multiple modem support
 */
static LIST_HEAD(hsic_pm_dev_list);

static void print_pm_dev_info(struct mdm_hsic_pm_data *pm_data)
{
	pr_info("pm device\n\tname = %s\n"
		"\tudev = 0x%p\n"
		"\tintf_cnt = %d\n"
		"\tblock_request = %s\n",
		pm_data->name,
		pm_data->udev,
		pm_data->intf_cnt,
		pm_data->block_request ? "true" : "false");
}

static struct mdm_hsic_pm_data *get_pm_data_by_dev_name(const char *name)
{
	struct mdm_hsic_pm_data *pm_data;

	if (list_empty(&hsic_pm_dev_list)) {
		pr_err("%s:there's no dev on pm dev list\n", __func__);
		return NULL;
	};

	/* get device from list */
	list_for_each_entry(pm_data, &hsic_pm_dev_list, list) {
		if (!strncmp(pm_data->name, name, strlen(name)))
			return pm_data;
	}

	return NULL;
}

/* do not call in irq context */
int pm_dev_runtime_get_enabled(struct usb_device *udev)
{
	int spin = 50;

	while (spin--) {
		pr_debug("%s: rpm status: %d\n", __func__,
						udev->dev.power.runtime_status);
		if (udev->dev.power.runtime_status == RPM_ACTIVE ||
			udev->dev.power.runtime_status == RPM_SUSPENDED) {
			usb_mark_last_busy(udev);
			break;
		}
		msleep(20);
	}
	if (spin <= 0) {
		pr_err("%s: rpm status %d, return -EAGAIN\n", __func__,
						udev->dev.power.runtime_status);
		return -EAGAIN;
	}
	usb_mark_last_busy(udev);

	return 0;
}

/* do not call in irq context */
int pm_dev_wait_lpa_wake(void)
{
	int spin = 50;

	while (lpa_handling && spin--) {
		pr_debug("%s: lpa wake wait loop\n", __func__);
		msleep(20);
	}

	if (lpa_handling) {
		pr_err("%s: in lpa wakeup, return EAGAIN\n", __func__);
		return -EAGAIN;
	}

	return 0;
}

void set_shutdown(void)
{
	struct mdm_hsic_pm_data *pm_data =
		get_pm_data_by_dev_name("mdm_hsic_pm0");

	pm_data->shutdown = true;
}

void notify_modem_fatal(void)
{
	struct mdm_hsic_pm_data *pm_data =
				get_pm_data_by_dev_name("mdm_hsic_pm0");

	pr_info("%s or shutdown\n", __func__);
	print_mdm_gpio_state();

	if (!pm_data || !pm_data->intf_cnt || !pm_data->udev)
		return;

	if (pm_data->shutdown == true) {
		pr_info("During shutdown, return %s\n", __func__);
		return;
	}

	pm_data->shutdown = true;

	/* crash from sleep, ehci is in waking up, so do not control ehci */
	if (!pm_data->block_request) {
		struct device *dev, *hdev;
		hdev = pm_data->udev->bus->root_hub->dev.parent;
		dev = &pm_data->udev->dev;

		pm_runtime_get_noresume(dev);
		pm_runtime_dont_use_autosuspend(dev);
		/* if it's in going suspend, give settle time before wake up */
		msleep(100);
		wake_up_all(&dev->power.wait_queue);
		pm_runtime_resume(dev);
		pm_runtime_get_noresume(dev);

		blocking_notifier_call_chain(&mdm_reset_notifier_list, 0, 0);
	}
}

void request_autopm_lock(int status)
{
	struct mdm_hsic_pm_data *pm_data =
					get_pm_data_by_dev_name("mdm_hsic_pm0");
	int spin = 5;

	if (!pm_data || !pm_data->udev)
		return;

	pr_debug("%s: set runtime pm lock : %d\n", __func__, status);

	if (status) {
		if (!atomic_read(&pm_data->pmlock_cnt)) {
			atomic_inc(&pm_data->pmlock_cnt);
			pr_info("get lock\n");

			do {
				if (!pm_dev_runtime_get_enabled(pm_data->udev))
					break;
			} while (spin--);

			if (spin <= 0)
				mdm_force_fatal();

			pm_runtime_get(&pm_data->udev->dev);
			pm_runtime_forbid(&pm_data->udev->dev);
		} else
			atomic_inc(&pm_data->pmlock_cnt);
	} else {
		if (!atomic_read(&pm_data->pmlock_cnt))
			pr_info("unbalanced release\n");
		else if (atomic_dec_and_test(&pm_data->pmlock_cnt)) {
			pr_info("release lock\n");
			pm_runtime_allow(&pm_data->udev->dev);
			pm_runtime_put(&pm_data->udev->dev);
		}
		/* initailize hello_packet_rx */
		hello_packet_rx = 0;
	}
}

void request_active_lock_set(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	pr_info("%s\n", __func__);
	if (pm_data)
		wake_lock(&pm_data->l2_wake);
}

void request_active_lock_release(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	pr_info("%s\n", __func__);
	if (pm_data)
		wake_unlock(&pm_data->l2_wake);
}

void request_boot_lock_set(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	pr_info("%s\n", __func__);
	if (pm_data)
		wake_lock(&pm_data->boot_wake);
}

void request_boot_lock_release(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	pr_info("%s\n", __func__);
	if (pm_data)
		wake_unlock(&pm_data->boot_wake);
}

bool check_request_blocked(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	if (!pm_data)
		return false;

	return pm_data->block_request;
}

void set_host_stat(const char *name, enum pwr_stat status)
{
	/* find pm device from list by name */
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);

	if (!pm_data) {
		pr_err("%s:no pm device(%s) exist\n", __func__, name);
		return;
	}

	/* crash during kernel suspend/resume, do not control host ready pin */
	/* and it has to be controlled when host driver initialized again */
	if (pm_data->block_request && pm_data->shutdown)
		return;

	if (pm_data->gpio_host_ready) {
		pr_info("dev rdy val = %d\n",
				gpio_get_value(pm_data->gpio_device_ready));
		pr_info("%s:set host port power status to [%d]\n",
							__func__, status);

		/*
		 * need get some delay for MDM9x15 suspend
		 * if L3 drive goes out to modem in suspending
		 * modem goes to unstable PM state. now 10 ms is enough
		 */
		if(status == POWER_OFF)
			mdelay(10);

		gpio_set_value(pm_data->gpio_host_ready, status);
	}
}

#define DEV_POWER_WAIT_SPIN	10
#define DEV_POWER_WAIT_MS	10
int wait_dev_pwr_stat(const char *name, enum pwr_stat status)
{
	int spin;
	/* find pm device from list by name */
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);

	if (!pm_data) {
		pr_err("%s:no pm device(%s) exist\n", __func__, name);
		return -ENODEV;
	}

	/* in shutdown(including modem fatal) do not need to wait dev ready */
	if (pm_data->shutdown)
		return 0;

	pr_info("%s:[%s]...\n", __func__, status ? "PWR ON" : "PWR OFF");

	if (pm_data->gpio_device_ready) {
		for (spin = 0; spin < DEV_POWER_WAIT_SPIN ; spin++) {
			if (gpio_get_value(pm_data->gpio_device_ready) ==
								status)
				break;
			else
				mdelay(DEV_POWER_WAIT_MS);
		}
	}

	if (gpio_get_value(pm_data->gpio_device_ready) == status)
		pr_info(" done\n");
	else {
		subsystem_restart(EXTERNAL_MODEM);
		return -ETIMEDOUT;
	}
	return 0;
}

/**
 * check suspended state for L3 drive
 * if not, L3 blocked and stay at L2 / L0 state
 */
int check_udev_suspend_allowed(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	struct device *dev;

	if (!pm_data) {
		pr_err("%s:no pm device(%s) exist\n", __func__, name);
		return -ENODEV;
	}
	if (!pm_data->intf_cnt || !pm_data->udev)
		return -ENODEV;

	dev = &pm_data->udev->dev;

	pr_info("%s:state_busy = %d, suspended = %d(rpmstat = %d:dpth:%d),"
		" suspended_child = %d\n", __func__, pm_data->state_busy,
		pm_runtime_suspended(dev), dev->power.runtime_status,
		dev->power.disable_depth, pm_children_suspended(dev));

	if (pm_data->state_busy)
		return -EBUSY;

	return pm_runtime_suspended(dev) && pm_children_suspended(dev);
}

int set_hsic_lpa_states(int states)
{
	struct mdm_hsic_pm_data *pm_data =
				get_pm_data_by_dev_name("mdm_hsic_pm0");
	/* if modem need to check survive, get status in variable */
	int val = 1;
	int ret = 0;

	/* set state for LPA enter */
	if (val) {
		switch (states) {
		case STATE_HSIC_LPA_ENTER:
			set_host_stat("mdm_hsic_pm0", POWER_OFF);
			ret = wait_dev_pwr_stat("mdm_hsic_pm0", POWER_OFF);
			if (ret)
				return ret;
			pr_info("set hsic lpa enter\n");
			break;
		case STATE_HSIC_LPA_WAKE:
			lpa_handling = true;
			pr_info("%s: set lpa handling to true\n", __func__);
			request_active_lock_set("mdm_hsic_pm0");
			pr_info("set hsic lpa wake\n");
			break;
		case STATE_HSIC_LPA_PHY_INIT:
			pr_info("set hsic lpa phy init\n");
			break;
		case STATE_HSIC_LPA_CHECK:
			if (lpcharge)
				return 0;
			else
				if (!get_pm_data_by_dev_name("mdm_hsic_pm0"))
					return 1;
				else
					return 0;
		case STATE_HSIC_LPA_ENABLE:
			if (lpcharge)
				return 0;
			else if (pm_data)
				return pm_data->shutdown;
			else
				return 1;
		default:
			pr_info("unknown lpa state\n");
			break;
		}
	}
	return 0;
}

bool mdm_check_main_connect(const char *name)
{
	/* find pm device from list by name */
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);

	if (!pm_data) {
		pr_err("%s:no pm device(%s)\n", __func__, name);
		return false;
	}

	print_pm_dev_info(pm_data);

	if (pm_data->intf_cnt >= 3)
		return true;
	else
		return false;
}

#define PM_START_DELAY_MS 3000
int register_udev_to_pm_dev(const char *name, struct usb_device *udev)
{
	/* find pm device from list by name */
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);

	if (!pm_data) {
		pr_err("%s:no pm device(%s) exist for udev(0x%p)\n",
					__func__, name, udev);
		return -ENODEV;
	}

	print_pm_dev_info(pm_data);

	if (!pm_data->intf_cnt) {
		pr_info("%s: registering new udev(0x%p) to %s\n", __func__,
							udev, pm_data->name);
		pm_data->udev = udev;
		atomic_set(&pm_data->pmlock_cnt, 0);
		usb_disable_autosuspend(udev);
		pm_data->shutdown = false;
#ifdef CONFIG_SIM_DETECT
		get_sim_state_at_boot();
#endif
	} else if (pm_data->udev && pm_data->udev != udev) {
		pr_err("%s:udev mismatching: pm_data->udev(0x%p), udev(0x%p)\n",
		__func__, pm_data->udev, udev);
		return -EINVAL;
	}

	pm_data->intf_cnt++;
	pr_info("%s:udev(0x%p) successfully registerd to %s, intf count = %d\n",
			__func__, udev, pm_data->name, pm_data->intf_cnt);

	queue_delayed_work(pm_data->wq, &pm_data->auto_rpm_start_work,
					msecs_to_jiffies(PM_START_DELAY_MS));
	return 0;
}

int set_qmicm_mode(const char *name)
{
	/* find pm device from list by name */
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);

	if (!pm_data) {
		pr_err("%s:no pm device(%s) exist\n", __func__, name);
		return -ENODEV;
	}

	pm_data->qmicm_mode = true;
	pr_info("%s: set QMICM mode\n", __func__);

	return 0;
}

/* force fatal for debug when HSIC disconnect */
extern void mdm_force_fatal(void);

void unregister_udev_from_pm_dev(const char *name, struct usb_device *udev)
{
	/* find pm device from list by name */
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);
	struct device *hdev;

	pr_info("%s\n", __func__);

	if (!pm_data) {
		pr_err("%s:no pm device(%s) exist for udev(0x%p)\n",
					__func__, name, udev);
		return;
	}

	if (!pm_data->shutdown) {
		hdev = udev->bus->root_hub->dev.parent;
		pm_runtime_forbid(hdev); /*ehci*/
		debug_ehci_reg_dump(hdev);
	}

	if (pm_data->udev && pm_data->udev != udev) {
		pr_err("%s:udev mismatching: pm_data->udev(0x%p), udev(0x%p)\n",
		__func__, pm_data->udev, udev);
		return;
	}

	pm_data->intf_cnt--;
	pr_info("%s:udev(0x%p) unregistered from %s, intf count = %d\n",
			__func__, udev, pm_data->name, pm_data->intf_cnt);

	if (!pm_data->intf_cnt) {
		pr_info("%s: all intf device unregistered from %s\n",
						__func__, pm_data->name);
		pm_data->udev = NULL;
		/* force fatal for debug when HSIC disconnect */
		if (!pm_data->shutdown) {
			mdm_force_fatal();
		}
	}
}

static void mdm_hsic_rpm_check(struct work_struct *work)
{
	struct mdm_hsic_pm_data *pm_data =
			container_of(work, struct mdm_hsic_pm_data,
					request_resume_work.work);
	struct device *dev;

	if (pm_data->shutdown)
		return;

	pr_info("%s\n", __func__);

	if (!pm_data->udev)
		return;

	if (lpa_handling) {
		pr_info("ignore resume req, lpa handling\n");
		return;
	}

	dev = &pm_data->udev->dev;

	if (pm_runtime_resume(dev) < 0)
		queue_delayed_work(pm_data->wq, &pm_data->request_resume_work,
							msecs_to_jiffies(20));

	if (pm_runtime_suspended(dev))
		queue_delayed_work(pm_data->wq, &pm_data->request_resume_work,
							msecs_to_jiffies(20));
};

static void mdm_hsic_rpm_start(struct work_struct *work)
{
	struct mdm_hsic_pm_data *pm_data =
			container_of(work, struct mdm_hsic_pm_data,
					auto_rpm_start_work.work);
	struct usb_device *udev = pm_data->udev;
	struct device *dev, *pdev, *hdev;

	pr_info("%s\n", __func__);

	if (!pm_data->intf_cnt || !pm_data->udev)
		return;

	dev = &pm_data->udev->dev;
	pdev = dev->parent;
	pm_runtime_set_autosuspend_delay(dev, 500);
	hdev = udev->bus->root_hub->dev.parent;
	pr_info("EHCI runtime %s, %s\n", dev_driver_string(hdev),
			dev_name(hdev));

	pm_runtime_allow(dev);
	pm_runtime_allow(hdev);/*ehci*/

	pm_data->shutdown = false;
}

static void mdm_hsic_rpm_restart(struct work_struct *work)
{
	struct mdm_hsic_pm_data *pm_data =
			container_of(work, struct mdm_hsic_pm_data,
					auto_rpm_restart_work.work);
	struct device *dev;

	pr_info("%s\n", __func__);

	if (!pm_data->intf_cnt || !pm_data->udev)
		return;

	dev = &pm_data->udev->dev;
	pm_runtime_set_autosuspend_delay(dev, 500);
}

static void fast_dormancy_func(struct work_struct *work)
{
	struct mdm_hsic_pm_data *pm_data =
			container_of(work, struct mdm_hsic_pm_data,
					fast_dormancy_work.work);
	pr_debug("%s\n", __func__);

	if (!pm_data || !pm_data->fd_wake_time)
		return;

	wake_lock_timeout(&pm_data->fd_wake, pm_data->fd_wake_time);
};

void fast_dormancy_wakelock(const char *name)
{
	struct mdm_hsic_pm_data *pm_data = get_pm_data_by_dev_name(name);

	if (!pm_data || !pm_data->fd_wake_time)
		return;

	queue_delayed_work(pm_data->wq, &pm_data->fast_dormancy_work, 0);
}

static ssize_t show_waketime(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct mdm_hsic_pm_data *pm_data = platform_get_drvdata(pdev);
	char *p = buf;
	unsigned int msec;

	if (!pm_data)
		return 0;

	msec = jiffies_to_msecs(pm_data->fd_wake_time);
	p += sprintf(p, "%u\n", msec);

	return p - buf;
}

static ssize_t store_waketime(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct mdm_hsic_pm_data *pm_data = platform_get_drvdata(pdev);
	unsigned long msec;
	int r;

	if (!pm_data)
		return count;

	r = strict_strtoul(buf, 10, &msec);
	if (r)
		return count;

	pm_data->fd_wake_time = msecs_to_jiffies(msec);

	return count;
}
static DEVICE_ATTR(waketime, 0660, show_waketime, store_waketime);

static ssize_t store_runtime(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t count)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct mdm_hsic_pm_data *pm_data = platform_get_drvdata(pdev);
	int value;

	if (sscanf(buf, "%d", &value) != 1)
		return -EINVAL;

	if (!pm_data || !pm_data->intf_cnt || !pm_data->udev)
		return -ENXIO;

	if (value == 1) {
		pr_info("%s: request runtime resume\n", __func__);
		if (pm_request_resume(&pm_data->udev->dev) < 0)
			pr_err("%s: unable to add pm work for rpm\n", __func__);
	}

	return count;
}
static DEVICE_ATTR(runtime, 0664, NULL, store_runtime);

static struct attribute *mdm_hsic_attrs[] = {
	&dev_attr_waketime.attr,
	&dev_attr_runtime.attr,
	NULL
};

static struct attribute_group mdm_hsic_attrgroup = {
	.attrs = mdm_hsic_attrs,
};

static int mdm_reset_notify_main(struct notifier_block *this,
				unsigned long event, void *ptr) {
	pr_info("%s\n", __func__);

	return NOTIFY_DONE;
};

static struct notifier_block mdm_reset_main_block = {
	.notifier_call = mdm_reset_notify_main,
};

static int mdm_hsic_pm_notify_event(struct notifier_block *this,
				unsigned long event, void *ptr)
{
	struct mdm_hsic_pm_data *pm_data =
		container_of(this, struct mdm_hsic_pm_data, pm_notifier);

	switch (event) {
	case PM_SUSPEND_PREPARE:
		/* to catch blocked resume req */
		pm_data->state_busy = false;
		pm_data->block_request = true;
		pr_info("%s: block request\n", __func__);
		return NOTIFY_OK;
	case PM_POST_SUSPEND:
		pm_data->block_request = false;
		pr_info("%s: unblock request\n", __func__);

		if (pm_data->shutdown) {
			notify_modem_fatal();
			return NOTIFY_DONE;
		}
		/**
		 * cover L2 -> L3 broken and resume req blocked case :
		 * force resume request for the lost request
		 */
		/* pm_request_resume(&pm_data->udev->dev); */
		queue_delayed_work(pm_data->wq, &pm_data->request_resume_work,
							msecs_to_jiffies(20));
		/*pm_runtime_set_autosuspend_delay(&pm_data->udev->dev, 200);*/
		queue_delayed_work(pm_data->wq, &pm_data->auto_rpm_restart_work,
						msecs_to_jiffies(20));

		request_active_lock_set(pm_data->name);

		return NOTIFY_OK;
	}
	return NOTIFY_DONE;
}

#define HSIC_RESUME_TRIGGER_LEVEL	1
static irqreturn_t mdm_hsic_irq_handler(int irq, void *data)
{
	int irq_level;
	struct mdm_hsic_pm_data *pm_data = data;

	if (!pm_data || !pm_data->intf_cnt || !pm_data->udev)
		return IRQ_HANDLED;

	if (pm_data->shutdown)
		return IRQ_HANDLED;

	/**
	 * host wake up handler, takes both edge
	 * in rising, isr triggers L2 ->  L0 resume
	 */

	irq_level = gpio_get_value(pm_data->gpio_host_wake);
	pr_info("%s: detect %s edge\n", __func__,
					irq_level ? "Rising" : "Falling");

	if (irq_level != HSIC_RESUME_TRIGGER_LEVEL)
		return IRQ_HANDLED;

	if (pm_data->block_request) {
		pr_info("%s: request blocked by kernel suspending\n", __func__);
		pm_data->state_busy = true;
		/* for blocked request, set wakelock to return at dpm suspend */
		wake_lock(&pm_data->l2_wake);
		return IRQ_HANDLED;
	}
#if 0
	if (pm_request_resume(&pm_data->udev->dev) < 0)
		pr_err("%s: unable to add pm work for rpm\n", __func__);
	/* check runtime pm runs in Active state, after 100ms */
	queue_delayed_work(pm_data->wq, &pm_data->request_resume_work,
							msecs_to_jiffies(200));
#else
	queue_delayed_work(pm_data->wq, &pm_data->request_resume_work, 0);
#endif
	return IRQ_HANDLED;
}

static int mdm_hsic_pm_gpio_init(struct mdm_hsic_pm_data *pm_data,
						struct platform_device *pdev)
{
	int ret;
	struct resource *res;

	/* get gpio from platform data */

	/* host ready gpio */
	res = platform_get_resource_byname(pdev, IORESOURCE_IO,
					"AP2MDM_HSIC_ACTIVE");
	if (res)
		pm_data->gpio_host_ready = res->start;

	if (pm_data->gpio_host_ready) {
		ret = gpio_request(pm_data->gpio_host_ready, "host_rdy");
		if (ret < 0)
			return ret;
		gpio_direction_output(pm_data->gpio_host_ready, 1);
		s3c_gpio_cfgpin(pm_data->gpio_host_ready, S3C_GPIO_OUTPUT);
		s3c_gpio_setpull(pm_data->gpio_host_ready, S3C_GPIO_PULL_NONE);
		s5p_gpio_set_drvstr(pm_data->gpio_host_ready,
							S5P_GPIO_DRVSTR_LV4);
		gpio_set_value(pm_data->gpio_host_ready, 1);
	} else
		return -ENXIO;

	/* device ready gpio */
	res = platform_get_resource_byname(pdev, IORESOURCE_IO,
					"MDM2AP_DEVICE_PWR_ACTIVE");
	if (res)
		pm_data->gpio_device_ready = res->start;
	if (pm_data->gpio_device_ready) {
		ret = gpio_request(pm_data->gpio_device_ready, "device_rdy");
		if (ret < 0)
			return ret;
		gpio_direction_input(pm_data->gpio_device_ready);
		s3c_gpio_cfgpin(pm_data->gpio_device_ready, S3C_GPIO_INPUT);
	} else
		return -ENXIO;

	/* host wake gpio */
	res = platform_get_resource_byname(pdev, IORESOURCE_IO,
					"MDM2AP_RESUME_REQ");
	if (res)
		pm_data->gpio_host_wake = res->start;
	if (pm_data->gpio_host_wake) {
		ret = gpio_request(pm_data->gpio_host_wake, "host_wake");
		if (ret < 0)
			return ret;
		gpio_direction_input(pm_data->gpio_host_wake);
		s3c_gpio_cfgpin(pm_data->gpio_host_wake, S3C_GPIO_SFN(0xF));
	} else
		return -ENXIO;

	if (pm_data->gpio_host_wake)
		pm_data->irq = gpio_to_irq(pm_data->gpio_host_wake);

	if (!pm_data->irq) {
		pr_err("fail to get host wake irq\n");
		return -ENXIO;
	}

	return 0;
}

static void mdm_hsic_pm_gpio_free(struct mdm_hsic_pm_data *pm_data)
{
	if (pm_data->gpio_host_ready)
		gpio_free(pm_data->gpio_host_ready);

	if (pm_data->gpio_device_ready)
		gpio_free(pm_data->gpio_device_ready);

	if (pm_data->gpio_host_wake)
		gpio_free(pm_data->gpio_host_wake);
}

#ifdef CONFIG_CPU_FREQ_TETHERING
static int link_pm_netdev_event(struct notifier_block *this,
				unsigned long event, void *ptr)
{
	struct mdm_hsic_pm_data *pm_data =
		container_of(this, struct mdm_hsic_pm_data, netdev_notifier);
	struct mdm_hsic_pm_platform_data *mdm_pdata = pm_data->mdm_pdata;
	struct net_device *dev = ptr;

	if (!net_eq(dev_net(dev), &init_net))
		return NOTIFY_DONE;

	if (!strncmp(dev->name, "rndis", 5)) {
		switch (event) {
		case NETDEV_UP:
			pr_info("%s: %s UP\n", __func__, dev->name);
			if (mdm_pdata->freq_lock)
				mdm_pdata->freq_lock(mdm_pdata->dev);

			break;
		case NETDEV_DOWN:
			pr_info("%s: %s DOWN\n", __func__, dev->name);
			if (mdm_pdata->freq_unlock)
				mdm_pdata->freq_unlock(mdm_pdata->dev);
			break;
		}
	}
	return NOTIFY_DONE;
}

static int usb_composite_notifier_event(struct notifier_block *this,
		unsigned long event, void *ptr)
{
	struct mdm_hsic_pm_data *pm_data =
		container_of(this, struct mdm_hsic_pm_data,
				usb_composite_notifier);
	struct mdm_hsic_pm_platform_data *mdm_pdata = pm_data->mdm_pdata;

	switch (event) {
	case 0:
		if (mdm_pdata->freq_unlock)
			mdm_pdata->freq_unlock(mdm_pdata->dev);
		pr_info("%s: USB detached\n", __func__);
		break;
	case 1:
		if (mdm_pdata->freq_lock)
			mdm_pdata->freq_lock(mdm_pdata->dev);
		pr_info("%s: USB attached\n", __func__);
		break;
	}
	pr_info("%s: usb configuration: %s\n", __func__, (char *)ptr);

	return NOTIFY_DONE;
}
#endif
#ifdef CONFIG_USBIRQ_BALANCING_LTE_HIGHTP
int boost_busfreq(struct device *dev, int enable)
{
	int ret = 0;
	unsigned int busfreq = 440220; // T0
	struct device *busdev = NULL;

	if (dev == NULL)
		return -ENODEV;

	busdev = dev_get("exynos-busfreq");
	if (busdev == NULL)
		return -ENODEV;

	if (enable)
		ret = dev_lock(busdev, dev, busfreq);
	else
		ret = dev_unlock(busdev, dev);

	return ret;
}

// only for T0 USB HOST
int clear_cpu0_from_usbhost_irq(int enable)
{
	unsigned int irq = IRQ_USB_HOST;
//	unsigned int irq = IRQ_USB_HSOTG;

	cpumask_var_t new_value;
	int err = 0;

	if (!irq_can_set_affinity(irq))
		return -EIO;

	if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
		return -ENOMEM;

	cpumask_setall(new_value);

	if (enable) {
		cpumask_and(new_value, new_value, cpu_online_mask);
		cpumask_clear_cpu(0, new_value);
	}

	if (cpumask_intersects(new_value, cpu_online_mask)) {
		err = irq_set_affinity(irq, new_value);
	}

	free_cpumask:
	free_cpumask_var(new_value);
	return err;
}

static int link_pm_rndis_event(struct notifier_block *this,
				unsigned long event, void *ptr)
{
	struct mdm_hsic_pm_data *pm_data =
		container_of(this, struct mdm_hsic_pm_data, rndis_notifier);
	struct mdm_hsic_pm_platform_data *mdm_pdata = pm_data->mdm_pdata;
	struct net_device *dev = ptr;

	if (!net_eq(dev_net(dev), &init_net))
		return NOTIFY_DONE;

	if (!strncmp(dev->name, "rndis", 5)) {
		switch (event) {
		case NETDEV_UP:
			if (mdm_pdata && mdm_pdata->dev)
				boost_busfreq(mdm_pdata->dev, 1);
			cpufreq_pegasusq_min_cpu_lock(2);
			clear_cpu0_from_usbhost_irq(1);
			pm_data->is_rndis_running = true;
			pr_info("%s: %s UP\n", __func__, dev->name);
			break;
		case NETDEV_DOWN:
			pm_data->is_rndis_running = false;
			clear_cpu0_from_usbhost_irq(0);
			cpufreq_pegasusq_min_cpu_unlock();
			if (mdm_pdata && mdm_pdata->dev)
				boost_busfreq(mdm_pdata->dev, 0);
			pr_info("%s: %s DOWN\n", __func__, dev->name);
			break;
		}
	}
	return NOTIFY_DONE;
}

static void hotplug_work_start(struct work_struct *work)
{
	struct mdm_hsic_pm_data *pm_data =
			container_of(work, struct mdm_hsic_pm_data,
					hotplug_work.work);
	clear_cpu0_from_usbhost_irq(1);
}

static int hotplug_notify_callback(struct notifier_block *this,
		unsigned long action, void *hcpu)
{
	struct mdm_hsic_pm_data *pm_data =
		container_of(this, struct mdm_hsic_pm_data, cpu_hotplug_notifier);

	if (pm_data->is_rndis_running) {
		switch (action) {

		case CPU_POST_DEAD:
			if (1 == num_online_cpus())
			{
				cpufreq_pegasusq_min_cpu_lock(2);
				queue_delayed_work(pm_data->wq, &pm_data->hotplug_work,
					msecs_to_jiffies(100));
			}
			break;
		}
	}
	return NOTIFY_OK;
}
#endif
static int mdm_hsic_pm_probe(struct platform_device *pdev)
{
	int ret;
	struct mdm_hsic_pm_data *pm_data;

	pr_info("%s for %s\n", __func__, pdev->name);

	pm_data = kzalloc(sizeof(struct mdm_hsic_pm_data), GFP_KERNEL);
	if (!pm_data) {
		pr_err("%s: fail to alloc pm_data\n", __func__);
		return -ENOMEM;
	}

	/* initial value */
	memcpy(pm_data->name, pdev->name, strlen(pdev->name));

	ret = mdm_hsic_pm_gpio_init(pm_data, pdev);
	if (ret < 0)
		goto err_gpio_init_fail;

	/* request irq for host wake interrupt */
	ret = request_irq(pm_data->irq, mdm_hsic_irq_handler,
		IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_DISABLED,
		pm_data->name, (void *)pm_data);
	if (ret < 0) {
		pr_err("%s: fail to request irq(%d)\n", __func__, ret);
		goto err_request_irq;
	}

	ret = enable_irq_wake(pm_data->irq);
	if (ret < 0) {
		pr_err("%s: fail to set wake irq(%d)\n", __func__, ret);
		goto err_set_wake_irq;
	}

	pm_data->wq = create_singlethread_workqueue("hsicrpmd");
	if (!pm_data->wq) {
		pr_err("%s: fail to create wq\n", __func__);
		goto err_create_wq;
	}

	if (sysfs_create_group(&pdev->dev.kobj, &mdm_hsic_attrgroup) < 0) {
		pr_err("%s: fail to create sysfs\n", __func__);
		goto err_create_sys_file;
	}

	pm_data->mdm_pdata =
		(struct mdm_hsic_pm_platform_data *)pdev->dev.platform_data;
	INIT_DELAYED_WORK(&pm_data->auto_rpm_start_work, mdm_hsic_rpm_start);
	INIT_DELAYED_WORK(&pm_data->auto_rpm_restart_work,
							mdm_hsic_rpm_restart);
	INIT_DELAYED_WORK(&pm_data->request_resume_work, mdm_hsic_rpm_check);
	INIT_DELAYED_WORK(&pm_data->fast_dormancy_work, fast_dormancy_func);
	/* register notifier call */
	pm_data->pm_notifier.notifier_call = mdm_hsic_pm_notify_event;
	register_pm_notifier(&pm_data->pm_notifier);
	blocking_notifier_chain_register(&mdm_reset_notifier_list,
							&mdm_reset_main_block);

#ifdef CONFIG_CPU_FREQ_TETHERING
	pm_data->netdev_notifier.notifier_call = link_pm_netdev_event;
	register_netdevice_notifier(&pm_data->netdev_notifier);

	pm_data->usb_composite_notifier.notifier_call =
		usb_composite_notifier_event;
	register_usb_composite_notifier(&pm_data->usb_composite_notifier);
#endif
#ifdef CONFIG_USBIRQ_BALANCING_LTE_HIGHTP
	pm_data->is_rndis_running = false;
	INIT_DELAYED_WORK(&pm_data->hotplug_work, hotplug_work_start);

	pm_data->rndis_notifier.notifier_call = link_pm_rndis_event;
	register_netdevice_notifier(&pm_data->rndis_notifier);

	pm_data->cpu_hotplug_notifier.notifier_call = hotplug_notify_callback;
	register_cpu_notifier(&pm_data->cpu_hotplug_notifier);
#endif

	wake_lock_init(&pm_data->l2_wake, WAKE_LOCK_SUSPEND, pm_data->name);
	wake_lock_init(&pm_data->boot_wake, WAKE_LOCK_SUSPEND, "mdm_boot");
	wake_lock_init(&pm_data->fd_wake, WAKE_LOCK_SUSPEND, "fast_dormancy");
	pm_data->fd_wake_time = DEFAULT_RAW_WAKE_TIME;
	pm_data->qmicm_mode = false;

	print_pm_dev_info(pm_data);
	list_add(&pm_data->list, &hsic_pm_dev_list);
	platform_set_drvdata(pdev, pm_data);
	pr_info("%s for %s has done\n", __func__, pdev->name);

	return 0;

err_create_sys_file:
	destroy_workqueue(pm_data->wq);
err_create_wq:
	disable_irq_wake(pm_data->irq);
err_set_wake_irq:
	free_irq(pm_data->irq, (void *)pm_data);
err_request_irq:
err_gpio_init_fail:
	mdm_hsic_pm_gpio_free(pm_data);
	kfree(pm_data);
	return -ENXIO;
}

static struct platform_driver mdm_pm_driver = {
	.probe = mdm_hsic_pm_probe,
	.driver = {
		.name = "mdm_hsic_pm0",
		.owner = THIS_MODULE,
	},
};

static int __init mdm_hsic_pm_init(void)
{
	/* in lpm mode, do not load modem driver */
	if (lpcharge)
		return 0;
	return platform_driver_register(&mdm_pm_driver);
}

static void __exit mdm_hsic_pm_exit(void)
{
	platform_driver_unregister(&mdm_pm_driver);
}

late_initcall(mdm_hsic_pm_init);