aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mediatek/c2k_ccci/cbp_sdio.c
blob: 728cfe0b847e61a79c21b570269d78d6af456ac8 (plain) (blame)
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
/*
 * drivers/mmc/card/cbp_sdio.c
 *
 * VIA CBP SDIO driver for Linux
 *
 * Copyright (C) 2009 VIA TELECOM Corporation, Inc.
 * Author: VIA TELECOM Corporation, Inc.
 *
 * This package is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/mmc/core.h>
#include <linux/mmc/card.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/sdio_ids.h>
#include <linux/platform_device.h>
#include <linux/irq.h>
#include <linux/circ_buf.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/kfifo.h>
#include <linux/slab.h>

#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mutex.h>
#include <linux/mmc/host.h>
#include <linux/gpio.h>
#include <linux/wait.h>
#include <linux/suspend.h>

#include "modem_sdio.h"

extern struct sdio_modem *c2k_modem;

extern void modem_reset_handler(void);

static int modem_detect_host(const char *host_id)
{
	/* HACK!!!
	 * Rely on mmc->class_dev.class set in mmc_alloc_host
	 * Tricky part: a new mmc hook is being (temporary) created
	 * to discover mmc_host class.
	 * Do you know more elegant way how to enumerate mmc_hosts?
	 */
	struct mmc_host *mmc = NULL;
	struct class_dev_iter iter;
	struct device *dev;
	int ret = -1;
#if 1
	printk("[C2K] before alloc host\n");
	mmc = mmc_alloc_host(0, NULL);
	if (!mmc){
		printk("[C2K] mmc_aloc_host error\n");
		ret =  -ENOMEM;
		goto out;
	}

	printk("[C2K] mmc_aloc_host success\n");
	BUG_ON(!mmc->class_dev.class);
	class_dev_iter_init(&iter, mmc->class_dev.class, NULL, NULL);
	for (;;) {
		dev = class_dev_iter_next(&iter);
		if (!dev) {
			printk("[C2K] class dev iter next failed\n");
			LOGPRT(LOG_ERR,  "%s: %d\n", __func__, __LINE__);
			break;
		} else {
			struct mmc_host *host = container_of(dev,
				struct mmc_host, class_dev);
			if (dev_name(&host->class_dev) &&
				strcmp(dev_name(&host->class_dev),
					host_id))
				continue;
			ret = 0;
			break;
		}
	}
	mmc_free_host(mmc);
#endif
	//ret = 0;
out:
	return ret;
}

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
extern unsigned int get_c2k_wdt_irq_id();
#endif

static struct cbp_platform_data cbp_data = {
	.bus					=	"sdio",
	.host_id				=	MDM_MMC_ID,
	.ipc_enable				=	false,
	.rst_ind_enable			=	false,
	.data_ack_enable		=	false,
	.flow_ctrl_enable		=	false,
	.tx_disable_irq			=	true,
	
	.gpio_ap_wkup_cp		=	GPIO_C2K_SDIO_AP_WAKE_MDM,
	.gpio_cp_ready			=	GPIO_C2K_SDIO_MDM_RDY,
	.gpio_cp_wkup_ap		=	GPIO_C2K_SDIO_MDM_WAKE_AP,
	.gpio_ap_ready			=	GPIO_C2K_SDIO_AP_RDY,
	.gpio_sync_polar		=	GPIO_C2K_SDIO_SYNC_POLAR,

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
	.gpio_cp_exception		=	GPIO_C2K_EXCEPTION,
	.c2k_wdt_irq_id			=	0,
#endif

	.gpio_rst_ind			=	GPIO_C2K_MDM_RST_IND,
	.gpio_rst_ind_polar		=	GPIO_C2K_MDM_RST_IND_POLAR,
	
	.gpio_data_ack			=	GPIO_C2K_SDIO_DATA_ACK,
	.gpio_data_ack_polar 	=	GPIO_C2K_SDIO_DATA_ACK_POLAR,

	.gpio_flow_ctrl			=	GPIO_C2K_SDIO_FLOW_CTRL,
	.gpio_flow_ctrl_polar	=	GPIO_C2K_SDIO_FLOW_CTRL_POLAR,
	
	.gpio_pwr_on			=	GPIO_C2K_MDM_PWR_EN,
	.gpio_rst				=	GPIO_C2K_MDM_RST,
	//for the level transfor chip fssd06
	.gpio_sd_select			=	GPIO_C2K_SD_SEL_N,
	.gpio_mc3_enable		=	GPIO_C2K_MC3_EN_N,

	.modem					=	NULL,

	.detect_host			=	modem_detect_host,
	.cbp_setup				=	modem_sdio_init,
	.cbp_destroy			=	modem_sdio_exit,
};


/*----------------------data_ack functions-------------------*/
static struct cbp_wait_event *cbp_data_ack = NULL;

static irqreturn_t gpio_irq_data_ack(int irq, void *data)
{
	struct cbp_wait_event *cbp_data_ack = (struct cbp_wait_event *)data;
	int level;
	//unsigned long long hr_t1,hr_t2;
	//hr_t1 = sched_clock();

	level = !!c2k_gpio_get_value(cbp_data_ack->wait_gpio);
	//LOGPRT(LOG_NOTICE,  "%s enter, level = %d!\n", __func__, level);

	if(level == cbp_data_ack->wait_polar){
		atomic_set(&cbp_data_ack->state, MODEM_ST_READY);
		wake_up(&cbp_data_ack->wait_q);
	}
	c2k_gpio_irq_unmask(cbp_data_ack->wait_gpio);
	//hr_t2 = sched_clock();
	//printk("[sdio]ack: t1=%llu,t2 =%llu,delta=%llu \n",hr_t1, hr_t2, hr_t2-hr_t1);
	return IRQ_HANDLED;
}

static void data_ack_wait_event(struct cbp_wait_event *pdata_ack)
{
	struct sdio_modem *modem = c2k_modem;
	struct cbp_wait_event *cbp_data_ack = (struct cbp_wait_event *)pdata_ack;

	wait_event(cbp_data_ack->wait_q, (MODEM_ST_READY == atomic_read(&cbp_data_ack->state))||(modem->status == MD_OFF));
}

/*----------------------flow control functions-------------------*/
unsigned long long hr_t1=0;
unsigned long long hr_t2=0;

static struct cbp_wait_event *cbp_flow_ctrl = NULL;

static irqreturn_t gpio_irq_flow_ctrl(int irq, void *data)
{
	struct cbp_wait_event *cbp_flow_ctrl = (struct cbp_wait_event *)data;
	int level;
    //hr_t1 = sched_clock();
	level = !!c2k_gpio_get_value(cbp_flow_ctrl->wait_gpio);
	
	//c2k_gpio_set_irq_type(cbp_flow_ctrl->wait_gpio, IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING);
	//c2k_gpio_set_irq_type(cbp_flow_ctrl->wait_gpio, IRQF_TRIGGER_FALLING );
	//c2k_gpio_set_irq_type(cbp_flow_ctrl->wait_gpio, IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_LEVEL_HIGH);
	c2k_gpio_irq_unmask(cbp_flow_ctrl->wait_gpio);

	if(level == cbp_flow_ctrl->wait_polar){
		atomic_set(&cbp_flow_ctrl->state, FLOW_CTRL_ENABLE);
		//LOGPRT(LOG_DEBUG,  "%s: flow control is enable, please write later!\n", __func__);
	}
	else{
		atomic_set(&cbp_flow_ctrl->state, FLOW_CTRL_DISABLE);
		//LOGPRT(LOG_DEBUG,  "%s: %d flow control is disable, can write now!\n", __func__,flw_count);
		wake_up(&cbp_flow_ctrl->wait_q);
	}
	
	//hr_t2 = sched_clock();
	//printk("[sdio] t1=%llu,t2 =%llu,delta=%llu \n",hr_t1, hr_t2, hr_t2-hr_t1);
	return IRQ_HANDLED;
}

static void flow_ctrl_wait_event(struct cbp_wait_event *pflow_ctrl)
{
	struct cbp_wait_event *cbp_flow_ctrl = (struct cbp_wait_event *)pflow_ctrl;
	struct sdio_modem *modem = c2k_modem;
	//wait_event(cbp_flow_ctrl->wait_q, FLOW_CTRL_DISABLE == atomic_read(&cbp_flow_ctrl->state));
	wait_event_timeout(cbp_flow_ctrl->wait_q, (FLOW_CTRL_DISABLE == atomic_read(&cbp_flow_ctrl->state)||(modem->status == MD_OFF)),msecs_to_jiffies(20));
}

/*----------------------IPC functions-------------------*/
static int modem_sdio_tx_notifier(int event, void *data);
static int modem_sdio_rx_notifier(int event, void *data);

static struct asc_config sdio_tx_handle ={
	.name = CBP_TX_HD_NAME,
};
static struct asc_infor sdio_tx_user ={
	.name = CBP_TX_USER_NAME,
	.data = &sdio_tx_handle,
	.notifier = modem_sdio_tx_notifier,
};

static struct asc_config sdio_rx_handle = {
	.name = SDIO_RX_HD_NAME,
};
static struct asc_infor sdio_rx_user = {
	.name = SDIO_RX_USER_NAME,
	.data = &sdio_rx_handle,
	.notifier = modem_sdio_rx_notifier,
};

static int modem_sdio_tx_notifier(int event, void *data)
{
	return 0;
}
#ifdef WAKE_HOST_BY_SYNC/*wake up sdio host by four wire sync mechanis*/
//extern void VIA_trigger_signal(int i_on);
extern void SRC_trigger_signal(int i_on);
#endif

static int modem_sdio_rx_notifier(int event, void *data)
{
	struct asc_config *rx_config  = (struct asc_config *)data;
	struct sdio_modem *modem = c2k_modem;
	int ret = 0;
	LOGPRT(LOG_NOTICE,  "%s event=%d\n", __func__,event);
	switch(event){
		case ASC_NTF_RX_PREPARE:
#ifdef WAKE_HOST_BY_SYNC/*wake up sdio host by four wire sync mechanis*/
			if(modem->status != MD_OFF)
				SRC_trigger_signal(1);
			else
				LOGPRT(LOG_ERR,  "ignor asc event to resume sdio host\n");
#endif
			asc_rx_confirm_ready(rx_config->name, 1);
			break;
		case ASC_NTF_RX_POST:
#ifdef WAKE_HOST_BY_SYNC/*wake up sdio host by four wire sync mechanis*/
			if(modem->status != MD_OFF)
				SRC_trigger_signal(0);
			else
				LOGPRT(LOG_ERR,  "ignor asc event to suspend sdio host\n");
#endif
			//asc_rx_confirm_ready(rx_config->name, 0);
			break;
		default:
			LOGPRT(LOG_ERR,  "%s: ignor unknow evernt!!\n", __func__);
			break;
	}
	return ret;
}

static struct cbp_exception *cbp_excp_ind = NULL;
/*----------------------reset indication functions-------------------*/
static struct cbp_reset *cbp_rst_ind = NULL;
static int modem_detect_card(struct cbp_reset *cbp_rst_ind)
{
	/* HACK!!!
	 * Rely on mmc->class_dev.class set in mmc_alloc_host
	 * Tricky part: a new mmc hook is being (temporary) created
	 * to discover mmc_host class.
	 * Do you know more elegant way how to enumerate mmc_hosts?
	 */
	struct mmc_host *mmc = NULL;
	struct class_dev_iter iter;
	struct device *dev;
	int ret = -1;

	mmc = mmc_alloc_host(0, NULL);
	if (!mmc){
		ret =  -ENOMEM;
		goto out;
	}

	BUG_ON(!mmc->class_dev.class);
	class_dev_iter_init(&iter, mmc->class_dev.class, NULL, NULL);
	for (;;) {
		dev = class_dev_iter_next(&iter);
		if (!dev) {
			break;
		} else {
			struct mmc_host *host = container_of(dev,
				struct mmc_host, class_dev);
			if (dev_name(&host->class_dev) &&
				strcmp(dev_name(&host->class_dev),
					MDM_MMC_ID)){
				printk("[MODEM SDIO] detect card not match\n");
				continue;
			}
			printk("[MODEM SDIO] detect card matched\n");
			cbp_rst_ind->host = host;
			mmc_detect_change(host, 0);
			ret = 0;
			break;
		}
	}
	mmc_free_host(mmc);
out:
	return ret;
}

#ifdef WAKE_HOST_BY_SYNC/*wake up sdio host by four wire sync mechanis*/

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
extern void via_sdio_on (int sdio_port_num);
extern void via_sdio_off (int sdio_port_num);
#endif
void c2k_wake_host(int wake)
{
#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
	static int host_status = 1;		/*we should set host off for the first time, so set status to be 1*/
	if(wake && !host_status){		/*wake sdio host to enum device for sth host*/
		host_status = 1;
		LOGPRT(LOG_NOTICE,  "%s %d host on.\n",__func__,__LINE__);
		via_sdio_on(3);
	}else if(host_status){
		host_status = 0;
		LOGPRT(LOG_NOTICE,  "%s %d host off.\n",__func__,__LINE__);
		via_sdio_off(3);
	}
#endif
}

static void modem_detect(struct work_struct *work)
{
	struct cbp_reset *cbp_rst_ind = NULL;
	int ret;
	int level = 0;

	LOGPRT(LOG_NOTICE,  "%s %d .\n",__func__,__LINE__);
	cbp_rst_ind = container_of(work, struct cbp_reset, reset_work);
#ifdef CONFIG_EVDO_DT_VIA_SUPPORT
	if((cbp_rst_ind->host == NULL)){/*for first detection and ipoh*/
         LOGPRT(LOG_NOTICE,  "%s %d modem_detect_card.\n",__func__,__LINE__);
        ret = modem_detect_card(cbp_rst_ind);
		if (ret){
			LOGPRT(LOG_ERR,  "%s: modem detect failed.\n", __func__);
		}
	}
	else{/*for device reset*/
		level = !!c2k_gpio_get_value(cbp_rst_ind->rst_ind_gpio);
		if(level == cbp_rst_ind->rst_ind_polar){
			LOGPRT(LOG_NOTICE,  "%s %d power on sdio host\n", __func__, __LINE__);
		c2k_wake_host(0);
            c2k_wake_host(1);
		}
		else{
			LOGPRT(LOG_NOTICE,  "%s %d power off sdio host\n", __func__, __LINE__);
			//c2k_gpio_direction_output(GPIO_C2K_MDM_PWR_EN, 1);
			modem_reset_handler();
			c2k_wake_host(0);
		}
	}
#else

	level = !!c2k_gpio_get_value(cbp_rst_ind->rst_ind_gpio);
	if(level == cbp_rst_ind->rst_ind_polar){
		LOGPRT(LOG_NOTICE,  "%s %d power on sdio host\n", __func__, __LINE__);
		c2k_wake_host(0);
		c2k_wake_host(1);
	}
	else{
		LOGPRT(LOG_NOTICE,  "%s %d power off sdio host\n", __func__, __LINE__);
		//c2k_gpio_direction_output(GPIO_C2K_MDM_PWR_EN, 1);
		modem_reset_handler();
		c2k_wake_host(0);
	}

#endif


}

static void modem_detect_for_excp(struct work_struct *work)
{
	printk("[MODEM SDIO] excp work sched!!!\n");
	modem_reset_handler();
	c2k_wake_host(0);
	msleep(1000);
	c2k_wake_host(1);
	
}

#else
static void modem_detect(struct work_struct *work)
{
	struct cbp_reset *cbp_rst_ind = NULL;
	int ret;
	int level = 0;

	LOGPRT(LOG_NOTICE,  "%s %d.\n",__func__,__LINE__);
	cbp_rst_ind = container_of(work, struct cbp_reset, reset_work);
	ret = modem_detect_card(cbp_rst_ind);
	if (ret){
		LOGPRT(LOG_ERR,  "%s: modem detect failed.\n", __func__);
	}
}

#endif

void gpio_irq_cbp_rst_ind(void)
{
	int level = 0;
	unsigned long flags;
	struct cbp_platform_data *cdata = &cbp_data;

	level = !!c2k_gpio_get_value(cbp_rst_ind->rst_ind_gpio);
	if(level != cbp_rst_ind->rst_ind_polar){/*1:cbp reset happened*/
		if (cdata->modem){
			LOGPRT(LOG_INFO,  "%s: set md off.\n", __func__);
			spin_lock_irqsave(&cdata->modem->status_lock, flags);
			cdata->modem->status = MD_OFF;
			spin_unlock_irqrestore(&cdata->modem->status_lock, flags);
		}
#ifdef CONFIG_EVDO_DT_VIA_SUPPORT
		wake_up(&cbp_flow_ctrl->wait_q);
		wake_up(&cbp_data_ack->wait_q);
#else
		atomic_set(&cdata->modem->tx_fifo_cnt, TX_FIFO_SZ);
		wake_up(&cdata->modem->wait_tx_done_q);
#endif
	}
	queue_work(cbp_rst_ind->reset_wq, &cbp_rst_ind->reset_work);
}
EXPORT_SYMBOL(gpio_irq_cbp_rst_ind);

void gpio_irq_cbp_excp_ind(void)
{
	unsigned long flags;
	
	struct cbp_platform_data *cdata = &cbp_data;

	LOGPRT(LOG_ERR,  "%s: receive c2k exception interrupt...\n", __func__);
	spin_lock_irqsave(&cdata->modem->status_lock, flags);
	if(cdata->modem->status != MD_OFF){
		cdata->modem->status = MD_EXCEPTION;
		modem_notify_event(MDM_EVT_NOTIFY_EXCP);
		queue_work(cbp_excp_ind->excp_wq, &cbp_excp_ind->excp_work);
	}else{
		LOGPRT(LOG_ERR,  "%s: md off now, ignore this EE\n", __func__);
	}
	spin_unlock_irqrestore(&cdata->modem->status_lock, flags);
	c2k_gpio_irq_unmask(cbp_excp_ind->excp_ind_gpio);

}
EXPORT_SYMBOL(gpio_irq_cbp_excp_ind);


#ifndef CONFIG_EVDO_DT_VIA_SUPPORT

void modem_notify_event(int event);

static irqreturn_t c2k_wdt_isr(int irq, void *data)
{
	unsigned long flags;
	struct cbp_platform_data *cdata = &cbp_data;
	
	LOGPRT(LOG_ERR,  "%s: receive c2k wdt interrupt, prepare to reset c2k...!\n", __func__);
	dump_c2k_iram();
	//wake_lock_timeout(&cmdata->wlock, MDM_RST_LOCK_TIME * HZ);
    modem_notify_event(MDM_EVT_NOTIFY_WDT);

	spin_lock_irqsave(&cdata->modem->status_lock, flags);
	cdata->modem->status = MD_OFF;
	spin_unlock_irqrestore(&cdata->modem->status_lock, flags);

	atomic_set(&cdata->modem->tx_fifo_cnt, TX_FIFO_SZ);
	wake_up(&cdata->modem->wait_tx_done_q);
	
	return IRQ_HANDLED;
}
#endif

/*----------------------cbp sys interface --------------------------*/
static void sys_power_on_cbp(void)
{
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 0);
	c2k_gpio_direction_output(GPIO_C2K_MDM_PWR_EN, 0); 
	
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 1);
	c2k_gpio_direction_output(GPIO_C2K_MDM_PWR_EN, 1);
	msleep(400);
	
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 0); //MDM_RST
}

static void sys_power_off_cbp(void)
{
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 0);
	c2k_gpio_direction_output(GPIO_C2K_MDM_PWR_EN, 0);
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 1);
	msleep(500);
	msleep(600);
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 0);
}

static void sys_reset_cbp(void)
{
	c2k_gpio_direction_output(GPIO_C2K_MDM_PWR_EN, 1);
	msleep(10);
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 1);
	msleep(100);
	msleep(300);
	c2k_gpio_direction_output(GPIO_C2K_MDM_RST, 0); //MDM_RST
}

static ssize_t cbp_power_show(struct kobject *kobj, struct kobj_attribute *attr,
			     char *buf)
{
	struct cbp_platform_data *cdata = &cbp_data;
	char *s = buf;
	if (cdata->modem)
		s += sprintf(s, "%d\n", cdata->modem->status);

	return (s - buf);
}

static ssize_t cbp_power_store(struct kobject *kobj, struct kobj_attribute *attr,
			   const char *buf, size_t n)
{
	unsigned long val;
	struct cbp_platform_data *cdata = &cbp_data;
	unsigned long flags;	
	
	if (strict_strtoul(buf, 10, &val))
		return -EINVAL;

	if (val < 0)
		return -EINVAL;

	if (val){
		if (cdata->modem){
			if (cdata->modem->status == MD_OFF){
				//sys_power_on_cbp();
				/*
				spin_lock_irqsave(cdata->modem->status_lock, flags);
				cdata.modem->status = MD_OFF;
				spin_unlock_irqrestore(cdata->modem->status_lock, flags);
				*/
				LOGPRT(LOG_INFO,  "AP power on CBP.\n");
			}else{
				LOGPRT(LOG_ERR,  "%s: CBP is already power on.\n", __func__);
			}
			
		}
		
	}
	else{
		if (cdata->modem){
			if (cdata->modem->status != MD_OFF){
				//sys_power_off_cbp();
				LOGPRT(LOG_INFO,  "AP power off CBP.\n");
				spin_lock_irqsave(&cdata->modem->status_lock, flags);
				cdata->modem->status = MD_OFF;
				spin_unlock_irqrestore(&cdata->modem->status_lock, flags);
			}
			else{
				LOGPRT(LOG_ERR,  "%s: CBP is already power off.\n", __func__);
			}
		}
	}

	return n;
}

static ssize_t cbp_reset_show(struct kobject *kobj, struct kobj_attribute *attr,
			     char *buf)
{
	return 0;
}

extern void c2k_modem_reset_platform(void);
extern void c2k_reset_modem(void);
static ssize_t cbp_reset_store(struct kobject *kobj, struct kobj_attribute *attr,
			   const char *buf, size_t n)
{
	unsigned long val;

	if (strict_strtoul(buf, 10, &val))
		return -EINVAL;

	if (val < 0)
		return -EINVAL;

	if (val){
		//sys_reset_cbp();
		//c2k_modem_reset_platform();
		c2k_reset_modem();
		
		LOGPRT(LOG_INFO,  "AP reset CBP.\n");
	}
	else{
		LOGPRT(LOG_ERR,  "%s: reset cbp use value 1.\n", __func__);
	}

	return n;
}

static int jtag_mode = 0;
static ssize_t cbp_jtag_show(struct kobject *kobj, struct kobj_attribute *attr,
			     char *buf)
{
	char *s = buf;

	s += sprintf(s, "%d\n", jtag_mode);

	return (s - buf);
}


extern void enable_c2k_jtag(int mode);
static ssize_t cbp_jtag_store(struct kobject *kobj, struct kobj_attribute *attr,
			   const char *buf, size_t n)
{
	unsigned long val;

	if (strict_strtoul(buf, 10, &val))
		return -EINVAL;

	if (val < 0)
		return -EINVAL;

	if (val){
		//sys_reset_cbp();
		//c2k_modem_reset_platform();
		jtag_mode = val;
		enable_c2k_jtag(val);
		
		LOGPRT(LOG_INFO,  "set cbp jtag to mode %d.\n", jtag_mode);
	}

	return n;
}


#define cbp_attr(_name) \
static struct kobj_attribute _name##_attr = {	\
	.attr	= {				\
		.name = __stringify(_name),	\
		.mode = 0660,			\
	},					\
	.show	= cbp_##_name##_show,			\
	.store	= cbp_##_name##_store,		\
}
cbp_attr(power);
cbp_attr(reset);
cbp_attr(jtag);

static struct attribute * cbp_power_attr[] = {
	&power_attr.attr,
	&reset_attr.attr,
	&jtag_attr.attr,
	NULL,
};

static struct kobject *cbp_power_kobj;
static struct attribute_group g_power_attr_group = {
	.attrs = cbp_power_attr,
};

/*----------------------- cbp platform driver ------------------------*/

//static int __devinit cbp_probe(struct platform_device *pdev)
static int cbp_probe(struct platform_device *pdev)
{
	struct cbp_platform_data *plat = pdev->dev.platform_data;
	int ret = -1;
	
	/* must have platform data */
	if (!plat) {
		LOGPRT(LOG_ERR,  "%s: no platform data!\n", __func__);
		ret = -EINVAL;
		goto out;
	}
#if 0
	if(plat->bus && !strcmp(plat->bus,"sdio")){
		if(plat->detect_host){
			ret = plat->detect_host(plat->host_id);
			if(ret){
				LOGPRT(LOG_ERR,  "%s: host %s dectect failed!\n", __func__, plat->host_id);
				goto out;
			}
		}
		else{
			LOGPRT(LOG_ERR,  "%s: bus %s have no dectect function!\n", __func__, plat->bus);
			goto out;
		}
	}
	else{
		LOGPRT(LOG_ERR,  "%s: unknow bus!\n", __func__);
		goto out;
	}
#endif

	if(GPIO_C2K_VALID(plat->gpio_data_ack)){
		cbp_data_ack = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_data_ack){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_data_ack failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_data_ack;    
		}

		init_waitqueue_head(&cbp_data_ack->wait_q);
		atomic_set(&cbp_data_ack->state, MODEM_ST_UNKNOW);
		cbp_data_ack->wait_gpio = plat->gpio_data_ack;
		cbp_data_ack->wait_polar = plat->gpio_data_ack_polar;
		LOGPRT(LOG_ERR,  "cbp_data_ack->wait_gpio=%d\n",cbp_data_ack->wait_gpio);
		LOGPRT(LOG_ERR,  "cbp_data_ack->wait_polar=%d\n",cbp_data_ack->wait_polar);
		
		c2k_gpio_irq_mask(plat->gpio_data_ack);
		c2k_gpio_direction_input_for_irq(plat->gpio_data_ack);
		c2k_gpio_set_irq_type(plat->gpio_data_ack, IRQF_TRIGGER_FALLING);
		ret = c2k_gpio_request_irq(plat->gpio_data_ack, gpio_irq_data_ack, 
				IRQF_SHARED | IRQF_TRIGGER_FALLING, DRIVER_NAME "(data_ack)", cbp_data_ack);
		c2k_gpio_irq_unmask(plat->gpio_data_ack);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for data_ack!!\n", __func__, __LINE__);
			goto err_req_irq_data_ack;
		}
		plat->cbp_data_ack = cbp_data_ack;
		plat->data_ack_wait_event = data_ack_wait_event;
		plat->data_ack_enable =true;
	}

	if(GPIO_C2K_VALID(plat->gpio_flow_ctrl)){
		cbp_flow_ctrl = kzalloc(sizeof(struct cbp_wait_event), GFP_KERNEL);
		if (!cbp_flow_ctrl){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_flow_ctrl failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_flow_ctrl;    
		}

		init_waitqueue_head(&cbp_flow_ctrl->wait_q);
		atomic_set(&cbp_flow_ctrl->state, FLOW_CTRL_DISABLE);
		cbp_flow_ctrl->wait_gpio = plat->gpio_flow_ctrl;
		cbp_flow_ctrl->wait_polar = plat->gpio_flow_ctrl_polar;
		LOGPRT(LOG_ERR,  "cbp_flow_ctrl->wait_gpio=%d\n",cbp_flow_ctrl->wait_gpio);
		LOGPRT(LOG_ERR,  "cbp_flow_ctrl->wait_polar=%d\n",cbp_flow_ctrl->wait_polar);
		
		c2k_gpio_irq_mask(plat->gpio_flow_ctrl);
		c2k_gpio_direction_input_for_irq(plat->gpio_flow_ctrl);
		//c2k_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_LEVEL_HIGH);
		c2k_gpio_set_irq_type(plat->gpio_flow_ctrl, IRQF_TRIGGER_FALLING);
		ret = c2k_gpio_request_irq(plat->gpio_flow_ctrl, gpio_irq_flow_ctrl, 
				IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 
				DRIVER_NAME "(flow_ctrl)", cbp_flow_ctrl);
		c2k_gpio_irq_unmask(plat->gpio_flow_ctrl);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for flow_ctrl!!\n", __func__, __LINE__);
			goto err_req_irq_flow_ctrl;
		}
		
		plat->cbp_flow_ctrl= cbp_flow_ctrl;
		plat->flow_ctrl_wait_event = flow_ctrl_wait_event;
		plat->flow_ctrl_enable = true;
	}
	
	
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		cbp_rst_ind = kzalloc(sizeof(struct cbp_reset), GFP_KERNEL);
		if (!cbp_rst_ind){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_rst_ind failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_rst_ind;    
		}

		cbp_rst_ind->name = "cbp_rst_ind_wq";
		cbp_rst_ind->reset_wq = create_singlethread_workqueue(cbp_rst_ind->name);
		if (cbp_rst_ind->reset_wq == NULL) {
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d error creat rst_ind_workqueue \n",__func__, __LINE__);
			goto err_create_work_queue;
		}
		INIT_WORK(&cbp_rst_ind->reset_work, modem_detect);
		cbp_rst_ind->rst_ind_gpio = plat->gpio_rst_ind;
		cbp_rst_ind->rst_ind_polar = plat->gpio_rst_ind_polar;
		cbp_rst_ind->host = NULL;
#if 0		
		c2k_gpio_irq_mask(plat->gpio_rst_ind);
		c2k_gpio_direction_input_for_irq(plat->gpio_rst_ind);
		c2k_gpio_set_irq_type(plat->gpio_rst_ind, IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING);
		ret = c2k_gpio_request_irq(plat->gpio_rst_ind, gpio_irq_cbp_rst_ind, 
			IRQF_SHARED |IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING, 
			DRIVER_NAME "(rst_ind)", cbp_rst_ind);
		c2k_gpio_irq_unmask(plat->gpio_rst_ind);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for rst_ind!!\n", __func__, __LINE__);
			goto err_req_irq_rst_ind;
		}
#endif
		plat->rst_ind_enable = true;
	}

		cbp_excp_ind = kzalloc(sizeof(struct cbp_exception), GFP_KERNEL);
		if (!cbp_excp_ind){
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d kzalloc cbp_rst_ind failed \n",__func__, __LINE__);
			goto err_kzalloc_cbp_excp_ind;	 
		}

		cbp_excp_ind->name = "cbp_excp_ind_wq";
		cbp_excp_ind->excp_wq = create_singlethread_workqueue(cbp_excp_ind->name);
		if (cbp_excp_ind->excp_wq == NULL) {
			ret = -ENOMEM;
			LOGPRT(LOG_ERR,  "%s %d error creat rst_ind_workqueue \n",__func__, __LINE__);
			goto err_create_excp_work_queue;
		}
		//Todo: workqueue function need to be implemented
		//INIT_WORK(&cbp_excp_ind->excp_work, modem_detect);
		INIT_WORK(&cbp_excp_ind->excp_work, modem_detect_for_excp);
		cbp_excp_ind->host = NULL;

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
	if (GPIO_C2K_VALID(plat->gpio_cp_exception)){
		cbp_excp_ind->excp_ind_gpio = plat->gpio_cp_exception;
		
		c2k_gpio_irq_mask(plat->gpio_cp_exception);
		c2k_gpio_set_irq_type(plat->gpio_cp_exception, IRQF_TRIGGER_FALLING);
		ret = c2k_gpio_request_irq(plat->gpio_cp_exception, gpio_irq_cbp_excp_ind, 
				IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 
				DRIVER_NAME "(c2k EE)", cbp_excp_ind);
		c2k_gpio_irq_unmask(plat->gpio_cp_exception);
		if (ret < 0) {
			LOGPRT(LOG_ERR,  "%s: %d fail to request irq for flow_ctrl!!\n", __func__, __LINE__);
			goto err_req_irq_excp;
		}
	}
	plat->c2k_wdt_irq_id = get_c2k_wdt_irq_id();
	LOGPRT(LOG_INFO, "get c2k wdt irq id %d\n", plat->c2k_wdt_irq_id);
#if 1
	if (plat->c2k_wdt_irq_id)
		ret = request_irq(plat->c2k_wdt_irq_id, c2k_wdt_isr, IRQF_TRIGGER_NONE, "C2K_CCCI", plat);
	else
		LOGPRT(LOG_ERR,  "%s: %d fail to get wdt irq id!!\n", __func__, __LINE__);
#endif
#endif

	if((GPIO_C2K_VALID(plat->gpio_ap_wkup_cp)) && (GPIO_C2K_VALID(plat->gpio_cp_ready)) &&
		(GPIO_C2K_VALID(plat->gpio_cp_wkup_ap))  && (GPIO_C2K_VALID(plat->gpio_ap_ready))){
		sdio_tx_handle.gpio_wake = plat->gpio_ap_wkup_cp;
		sdio_tx_handle.gpio_ready = plat->gpio_cp_ready;
		sdio_tx_handle.polar = plat->gpio_sync_polar;
		ret = asc_tx_register_handle(&sdio_tx_handle);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_tx_register_handle failed.\n",__func__,__LINE__);
			goto err_ipc;
		}
		ret = asc_tx_add_user(sdio_tx_handle.name, &sdio_tx_user);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_tx_add_user failed.\n",__func__,__LINE__);
			goto err_ipc;
		}

		sdio_rx_handle.gpio_wake = plat->gpio_cp_wkup_ap;
		sdio_rx_handle.gpio_ready = plat->gpio_ap_ready;
		sdio_rx_handle.polar = plat->gpio_sync_polar;
		ret = asc_rx_register_handle(&sdio_rx_handle);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_rx_register_handle failed.\n",__func__,__LINE__);
			goto err_ipc;
		}
		ret = asc_rx_add_user(sdio_rx_handle.name, &sdio_rx_user);
		if(ret){
			LOGPRT(LOG_ERR,  "%s %d asc_rx_add_user failed.\n",__func__,__LINE__);
			goto err_ipc;
		}
		plat->ipc_enable = true;
		plat->tx_handle = &sdio_tx_handle;
	}
	
	ret = plat->cbp_setup(plat);
	if(ret){
		LOGPRT(LOG_ERR,  "%s: host %s setup failed!\n", __func__, plat->host_id);
		goto err_ipc;
	}
	cbp_power_kobj = c2k_kobject_add("power");
	if (!cbp_power_kobj){
		LOGPRT(LOG_ERR,  "error c2k_kobject_add!\n");
		ret = -ENOMEM;
		goto err_create_kobj;
	}
	LOGPRT(LOG_INFO,  " cbp initialized on host %s successfully, bus is %s !\n", plat->host_id, plat->bus);
	return sysfs_create_group(cbp_power_kobj, &g_power_attr_group);
	
err_create_kobj:
	plat->cbp_destroy();
err_ipc:
#if 0
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		free_irq(c2k_gpio_to_irq(plat->gpio_rst_ind), cbp_rst_ind);
	}
err_req_irq_rst_ind:
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
	}
#endif

#ifndef CONFIG_EVDO_DT_VIA_SUPPORT
err_req_irq_excp:
	if(GPIO_C2K_VALID(plat->gpio_cp_exception)){
		destroy_workqueue(cbp_excp_ind->excp_wq);
	}
#endif
err_create_excp_work_queue:
		kfree(cbp_excp_ind);
err_kzalloc_cbp_excp_ind:

	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		destroy_workqueue(cbp_rst_ind->reset_wq);
	}
err_create_work_queue:
	if(GPIO_C2K_VALID(plat->gpio_rst_ind)){
		kfree(cbp_rst_ind);
	}
err_kzalloc_cbp_rst_ind:
	if(GPIO_C2K_VALID(plat->gpio_flow_ctrl)){
		free_irq(c2k_gpio_to_irq(plat->gpio_flow_ctrl), cbp_flow_ctrl);
	}
err_req_irq_flow_ctrl:
	if(GPIO_C2K_VALID(plat->gpio_flow_ctrl)){
		kfree(cbp_flow_ctrl);
	}
err_kzalloc_cbp_flow_ctrl:
	if(GPIO_C2K_VALID(plat->gpio_data_ack)){
		free_irq(c2k_gpio_to_irq(plat->gpio_data_ack), cbp_data_ack);
	}
err_req_irq_data_ack:
	if(GPIO_C2K_VALID(plat->gpio_data_ack)){
		kfree(cbp_data_ack);
	}
err_kzalloc_cbp_data_ack:
out:
	return ret;
}

//static int __devexit cbp_remove(struct platform_device *pdev)
static int cbp_remove(struct platform_device *pdev)
{
	struct cbp_platform_data *plat = pdev->dev.platform_data;
	
	if((GPIO_C2K_VALID(plat->gpio_sd_select)) && (GPIO_C2K_VALID(plat->gpio_mc3_enable))){
	}
	
	if(plat->data_ack_enable && (GPIO_C2K_VALID(plat->gpio_data_ack))){
		free_irq(c2k_gpio_to_irq(plat->gpio_data_ack), cbp_data_ack);
		kfree(cbp_data_ack);
	}

	if(plat->flow_ctrl_enable && (GPIO_C2K_VALID(plat->gpio_flow_ctrl))){
		free_irq(c2k_gpio_to_irq(plat->gpio_flow_ctrl), cbp_flow_ctrl);
		kfree(cbp_flow_ctrl);
	}

	if(plat->rst_ind_enable && (GPIO_C2K_VALID(plat->gpio_rst_ind))){
		free_irq(c2k_gpio_to_irq(plat->gpio_rst_ind), cbp_rst_ind);
		destroy_workqueue(cbp_rst_ind->reset_wq);
		kfree(cbp_rst_ind);
	}

	destroy_workqueue(cbp_excp_ind->excp_wq);
	kfree(cbp_excp_ind);
		
	plat->cbp_destroy();
	sysfs_remove_group(cbp_power_kobj, &g_power_attr_group);
	kobject_put(cbp_power_kobj);
	LOGPRT(LOG_INFO,  " cbp removed on host %s, bus is %s!\n", plat->host_id, plat->bus);
	return 0;
}

static struct platform_device cbp_device = {
	.name = "cbp",
	.dev = {
		.platform_data = &cbp_data,
	},
};

static struct platform_driver cbp_driver = {
	.driver = {
		.name = "cbp",
		.owner = THIS_MODULE,
	},
	.probe		= cbp_probe,
	.remove		= cbp_remove,
};

extern void c2k_platform_restore_first_init(void);

static int cbp_pm_event(struct notifier_block *notifier, unsigned long pm_event, void *unused)
{
	struct cbp_platform_data *cdata = &cbp_data;
	unsigned long flags;
	
	LOGPRT(LOG_NOTICE,"%s pm_event=%ld\n",__func__,pm_event);
	switch(pm_event) {
	case PM_HIBERNATION_PREPARE:
		// This event is recieved when system is preparing to hibernation.
		// i.e., IPO-H power off in kernel space, where user/kernel space processes are not freezed yet.
		return NOTIFY_DONE;
	case PM_RESTORE_PREPARE:
		// This event is recieved before system is preparing to restore,
		// i.e., IPO-H power on, where kernel is on the way to late_initcall() in normal boot.
		return NOTIFY_DONE;
	case PM_POST_HIBERNATION:
		// This event is recieved, after system is restored, and user/kernel processes are unfreezed and can operate on.
		if (cdata->modem){
			LOGPRT(LOG_INFO,  "%s: set md off.\n", __func__);
			spin_lock_irqsave(&cdata->modem->status_lock, flags);
			cdata->modem->status = MD_OFF;
			spin_unlock_irqrestore(&cdata->modem->status_lock, flags);
		}
		LOGPRT(LOG_NOTICE,"[%s] ipoh occured\n", __func__);
		modem_reset_handler();
		c2k_platform_restore_first_init();
		LOGPRT(LOG_NOTICE,  "%s %d power off sdio host\n", __func__, __LINE__);
		c2k_wake_host(0);
		LOGPRT(LOG_NOTICE,  "%s %d notify user space ipoh\n", __func__, __LINE__);
		modem_ipoh_indication_usr();
		return NOTIFY_DONE;
	}
	return NOTIFY_OK;
}

static struct notifier_block cbp_pm_notifier_block = {
   .notifier_call = cbp_pm_event,
   .priority = 0,
};


static int __init cbp_init(void)
{
	int ret;

	ret = platform_device_register(&cbp_device);
	if (ret) {
		LOGPRT(LOG_ERR,  "platform_device_register failed\n");
		goto err_platform_device_register;
	}

	ret = platform_driver_register(&cbp_driver);
	if (ret) {
		LOGPRT(LOG_ERR,  "platform_driver_register failed\n");
		goto err_platform_driver_register;
	}


   ret = register_pm_notifier(&cbp_pm_notifier_block);
   if (ret) {
       LOGPRT(LOG_ERR,  "%s failed to register PM notifier\n", __func__);
       goto err_platform_driver_register;
   }else{
       LOGPRT(LOG_ERR,  "%s sucess to register PM notifier\n", __func__);
    }


	return ret;
err_platform_driver_register:
	platform_device_unregister(&cbp_device);
err_platform_device_register:
	return ret;
}

late_initcall(cbp_init);