summaryrefslogtreecommitdiff
path: root/drivers/misc/gpsip/cgdriver/platform.c
blob: 44f9e64dd09babafebcdb35156de173db8233988 (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
/******************************************************************************
 *                                LEGAL NOTICE                                *
 *                                                                            *
 *  USE OF THIS SOFTWARE (including any copy or compiled version thereof) AND *
 *  DOCUMENTATION IS SUBJECT TO THE SOFTWARE LICENSE AND RESTRICTIONS AND THE *
 *  WARRANTY DISLCAIMER SET FORTH IN LEGAL_NOTICE.TXT FILE. IF YOU DO NOT     *
 *  FULLY ACCEPT THE TERMS, YOU MAY NOT INSTALL OR OTHERWISE USE THE SOFTWARE *
 *  OR DOCUMENTATION.                                                         *
 *  NOTWITHSTANDING ANYTHING TO THE CONTRARY IN THIS NOTICE, INSTALLING OR    *
 *  OTHERISE USING THE SOFTWARE OR DOCUMENTATION INDICATES YOUR ACCEPTANCE OF *
 *  THE LICENSE TERMS AS STATED.                                              *
 *                                                                            *
 ******************************************************************************/
/* Version: 1.8.9\3686 */
/* Build  : 13 */
/* Date   : 12/08/2012 */

/**
	\file
	\brief platform/CPU specific code

	\defgroup CGX_DRIVER_PLATFORM_ANDROID CPU/Android platform specific defines
	\{
*/

#include <asm/uaccess.h>
#include <soc/sprd/gpio.h>
#include <linux/regulator/consumer.h>
#include <soc/sprd/regulator.h>
#include <linux/clk.h>
#include <linux/delay.h>

#include "CgxDriverApi.h"
#include "CgCpu.h"
#include "platform.h"
#include "CgReturnCodes.h"
#include "CgxDriverOs.h"
#include "CgxDriverCore.h"

#ifdef CONFIG_ARCH_SCX20
#include <linux/sprd_2351.h>
#endif

#ifndef CGCORE_ACCESS_VIA_SPI
extern TCgReturnCode CGCoreSclkEnable(int enable);
struct sprd_2351_interface *gps_rf_ops;
#endif

/** Native byte order for this CPU */
const TCgByteOrder CGX_DRIVER_NATIVE_BYTE_ORDER = ECG_BYTE_ORDER_4321;	// SPRD_FPGA is little endian

/*
    Reset the core and timers and initialize GPIO (direction and special function)
*/
TCgReturnCode CgxDriverInit(void *pDriver)
{
	// Check all addresses are defined
	/*
	#if CG_DRIVER_CGSNAP_BASE_PA == CG_UNDEFINED_ADDRESS
		#error please define CG_DRIVER_CGSNAP_BASE_PA with correct address
	#endif
	#if CG_DRIVER_REVISION_BASE_PA == CG_UNDEFINED_ADDRESS
		#error please define CG_DRIVER_REVISION_BASE_PA with correct address
	#endif
	#if CG_DRIVER_GPIO_BASE_PA == CG_UNDEFINED_ADDRESS
		#error please define CG_DRIVER_GPIO_BASE_PA with correct address
	#endif
	#if CG_DRIVER_DMA_BASE_PA == CG_UNDEFINED_ADDRESS
		#error please define CG_DRIVER_DMA_BASE_PA with correct address
	#endif
	#if CG_DRIVER_INTR_BASE_PA == CG_UNDEFINED_ADDRESS
		#error please define CG_DRIVER_INTR_BASE_PA with correct address
	#endif
	#if CG_DRIVER_CLK_BASE_PA == CG_UNDEFINED_ADDRESS
		#error please define CG_DRIVER_CLK_BASE_PA with correct address
	#endif
	*/
	// TODO 1st time initialization

    return ECgOk;
}






TCgReturnCode CgxDriverDataReadyPrepare(void)
{
	return CgCpuGpioModeSet(CGX5000_DR, ECG_CPU_GPIO_FALLING_INT);
}


TCgReturnCode CgxDriverInterruptPrepare(void)
{
	TCgReturnCode rc = ECgOk;

	// not using 'GPS' interrupt, so there is nothing to do

	return rc;
}

TCgReturnCode CgxDriverDmaInterruptPrepare(void)
{
	// TODO initial setup for DMA interrupt.
	// if no special work is required, leave this function empty
	return ECgOk;
}




TCgReturnCode CgxDriverGpsInterruptPrepare(void)
{
	// TODO return the interrupt code for 'CGsnap' interrupt
	// if no special work is required, leave this function empty
	return ECgOk;
}




U32 CgxDriverDataReadyInterruptCode(void)
{
	// TODO return the interrupt code for 'DMA end of transfer' interrupt

	return 0;
}


U32 CgxDriverGpsInterruptCode(void)
{
	// TODO return the interrupt code for 'CGsnap' interrupt
#ifndef CGCORE_ACCESS_VIA_SPI
	return SPRD_GPS_INT;
#else
	gpio_direction_input (CG_DRIVER_GPIO_GPS_INT);
	return gpio_to_irq(CG_DRIVER_GPIO_GPS_INT);
#endif
}


TCgReturnCode CgxDriverWriteData(unsigned char *aSourceVirtualAddress, unsigned long aSourcePhysicalAddress, unsigned long aLengthBytes)
{
    //DBG_FUNC_NAME("CgxDriverWriteData")
    TCgReturnCode rc = ECgOk;

// 	#if WRITE_MODE == CG_CPU_SPI_MODE_DMA
// 		if (OK(rc)) rc = CgCpuSpiDmaStop(SPI_CHANNEL);
// 		CgCpuCacheSync();
// 		CgCpuSpiSetup(SPI_CHANNEL, SPI_PRESCALE, ECG_CPU_SPI_OUTPUT_DMA);
// 		CgCpuDmaSetupToDevice(aSourcePhysicalAddress,aLengthBytes,0,0);
// 		if (OK(rc)) rc = CgCpuSpiDmaStart(SPI_CHANNEL);
// 		if (OK(rc)) rc = CgCpuDmaWaitFinish(CG_DRIVER_DMA_CHANNEL_WRITE);
// 	#elif WRITE_MODE == CG_CPU_SPI_MODE_MANUAL
// 		U32 i;
// 		CgCpuSpiSetup(SPI_CHANNEL, SPI_PRESCALE, ECG_CPU_SPI_OUTPUT_POLLING);
//
// 		for(i = 0; i < aLengthBytes; i++) {
// 			CgCpuSpiTxFinishWait(SPI_CHANNEL);
// 			CgCpuSpiWriteByte(SPI_CHANNEL, aSourceVirtualAddress[i]);
// 		}
// 	#endif

    return rc;
}


TCgReturnCode CgxDriverGpioCode(int aControlLine, int *aGpioCode)
{
	*aGpioCode = 0;
	return ECgNotSupported;
}

TCgReturnCode CgxDriverReadData(unsigned char *aTargetVirtualAddress, unsigned long aTargetPhysicalAddress, unsigned long aLengthBytes)
{
	//DBG_FUNC_NAME("CgxDriverReadData")
	TCgReturnCode rc = ECgOk;

// 	#if READ_MODE==CG_CPU_SPI_MODE_DMA
// 		// memset(aTargetVirtualAddress, 0x55, aLengthBytes); //NG! debug
// 		CgCpuCacheSync();//NG! debug
// 		// Buffer data (not register data) is written in DMA mode
// 		if (OK(rc)) rc = CgCpuSpiDmaStop(SPI_CHANNEL);
//
// 		CgCpuCacheSync();
// 		if (OK(rc)) rc = CgCpuSpiSetup(SPI_CHANNEL, SPI_PRESCALE, ECG_CPU_SPI_INPUT_DMA);
// 		if (OK(rc)) rc = CgCpuDmaSetupFromDevice(aTargetPhysicalAddress, aLengthBytes, SPI_PRESCALE, CG_DRIVER_DMA_CHANNEL_READ, CG_DRIVER_DMA_CHANNEL_WRITE, SPI_CHANNEL);
// 		if (OK(rc)) rc = CgCpuSpiDmaStart(SPI_CHANNEL);
// 		// no need to wait for DMA to finish
//
// 	#elif READ_MODE==CG_CPU_SPI_MODE_MANUAL
// 		unsigned long i;
// 		CgCpuSpiSetup(SPI_CHANNEL, SPI_PRESCALE, ECG_CPU_SPI_INPUT_POLLING);
// 		for(i = 0; i < aLengthBytes; i++) {
// 			CgCpuSpiWriteByte(SPI_CHANNEL, 0); //dummy transmit
// 			CgCpuSpiRxFinishWait(SPI_CHANNEL);
// 			CgCpuSpiReadByte(SPI_CHANNEL, (volatile unsigned char *)(aTargetVirtualAddress + i));
// 			}
// 	#endif

	return rc;

}


TCgReturnCode CgxDriverClearData(unsigned char *aTargetVirtualAddress, unsigned long aTargetPhysicalAddress, unsigned long aLengthBytes)
{
	return CgxDriverReadData(aTargetVirtualAddress, aTargetPhysicalAddress, aLengthBytes);
}


TCgReturnCode CgxDriverIsDataReady(void)
{
	unsigned int val = 0;
	CgCpuGpioModeSet(CGX5000_DR, ECG_CPU_GPIO_INPUT);
	CgCpuGpioGet(CGX5000_DR, &val);
	return (val == 0) ? ECgOk : ECgGeneralFailure;
}


TCgReturnCode CgxDriverReadDataTail(unsigned char *aTargetVirtualAddress, unsigned long aTargetPhysicalAddress, unsigned long aLengthBytes)
{
	// no tail reading is required for SPRD_FPGA

	return ECgOk;
}

#ifdef CGCORE_ACCESS_VIA_SPI
static void CgxDriverRFInit(void)
{
	unsigned int value;

	value = 0x005f8420;
	gps_spi_write_bytes(1, 0x82*4, value);
	gps_spi_read_bytes(1, 0x82*4, &value);

	value = 0x00010003;
	gps_spi_write_bytes(1, 0x83*4, value);

	/*RF4in1 */
	value = 0x006f0609;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x007b8020;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x07000001;//GPS Mode 0:Idle 1:Rx
	gps_spi_write_bytes(1, 0x80*4, value);

#if 0
	value = 0x004af417;
	gps_spi_write_bytes(1, 0x80*4, value);
#endif
	value = 0x07385400;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x076c0721;
	gps_spi_write_bytes(1, 0x80*4, value);

	/*for 26M/16M TCXO AGC 1bit*/
	value = 0x07635140;//0x07635141;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x0704ef00;//max gain
	gps_spi_write_bytes(1, 0x80*4, value);

#if 1 //def CGCORE_GPS_26M  /*for 26M  TCXO*/
	value = 0x073c08d2;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x07023d61;
	gps_spi_write_bytes(1, 0x80*4, value);
#else  /*for 16M TCXO*/
	value = 0x073c0000;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x07026180;
	gps_spi_write_bytes(1, 0x80*4, value);
#endif

	//for dma block size
	gps_spi_sysreg_read_bytes(1,0x01,&value);;
	value = 0;
	value = ((1<<28)|(1<<26)|(1<<25));
	gps_spi_sysreg_write_bytes(1,0x01,value );
	gps_spi_sysreg_read_bytes(1,0x01,&value);

#if 1
	/*When for RX  Analog test such as GAIN and IF frequency ,
	we will add following  configuration*/
	value = 0x077b0112;//0x077b0101;
	gps_spi_write_bytes(1, 0x80*4, value);
#endif

#if 0 //for RF Test
	value = 0x075d88e6;
	gps_spi_write_bytes(1, 0x80*4, value);

	value = 0x070a7835;
	gps_spi_write_bytes(1, 0x80*4, value);
#endif
	
	//read reg
	value = 0x806f0000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x006f0609:0x%x\n",value);

	value = 0x807b0000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x007b8020:0x%x\n",value);

	value = 0x87000000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x07000001:0x%x\n",value);

	value = 0x87380000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x07385400:0x%x\n",value);

	value = 0x876c0000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x076c0721:0x%x\n",value);


	value = 0x87630000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x07635140:0x%x\n",value);

	value = 0x87040000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x0704ef00:0x%x\n",value);

#if 1   /*for 26M  TCXO*/
	value = 0x873c0000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x073c08d2:0x%x\n",value);

	value = 0x87020000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x07023d61:0x%x\n",value);
#else
	value = 0x873c0000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x073c0000:0x%x\n",value);

	value = 0x87020000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x07026180:0x%x\n",value);
#endif

	value = 0x877b0000;
	gps_spi_write_bytes(1, 0x80*4, value);
	gps_spi_read_bytes(1, 0x81*4, &value);
	printk("rf 0x077b0112:0x%x\n",value);

}

void gps_gpio_request(void)
{
	int ret;
	ret = gpio_request (CG_DRIVER_GPIO_GPS_PDN, "gps_pdn");
	if (ret){
		printk ("gps_pdn request err: %d\n", CG_DRIVER_GPIO_GPS_PDN);
	}

	ret = gpio_request (CG_DRIVER_GPIO_GPS_MRSTN, "gps_reset");
	if (ret){
		printk ("gps_reset request err: %d\n", CG_DRIVER_GPIO_GPS_MRSTN);
	}

	ret = gpio_request (CG_DRIVER_GPIO_GPS_SPI_CS, "gps_spi_cs");
	if (ret){
		printk ("gps_spi_cs request err: %d\n", CG_DRIVER_GPIO_GPS_SPI_CS);
	}

	ret = gpio_request (CG_DRIVER_GPIO_GPS_INT, "gps-req-int");
	if (ret)
	{
		printk ("gps-req- int err: %d\n", CG_DRIVER_GPIO_GPS_INT);
	}
}

static struct regulator *greeneye_vdd = NULL;
static void greeneye_vddsim2_enable(bool on)
{
	int ret;
	if (greeneye_vdd == NULL) {
		greeneye_vdd = regulator_get(NULL, "vddsim2");

		if (IS_ERR(greeneye_vdd)) {
			pr_err("Get regulator of vddsim2  error!\n");
			return;
		}
	}
	if (on) {
		regulator_set_voltage(greeneye_vdd, 2800000, 2800000);
		ret = regulator_enable(greeneye_vdd);
	}
	else if (regulator_is_enabled(greeneye_vdd)) {
		ret = regulator_disable(greeneye_vdd);
	}
}


static void gps_clk_init(bool enable)
{
	static struct clk *gps_clk_32k=NULL;

	if (gps_clk_32k == NULL) {
		gps_clk_32k = clk_get(NULL, "ext_32k");
		if (IS_ERR(gps_clk_32k)) {
			printk("failed to get parent ext_32k\n");
			return;
		}
	}
	if (enable) {
		#ifndef CONFIG_OF
		clk_enable(gps_clk_32k);
		#else
		clk_prepare_enable(gps_clk_32k);
		#endif
	}else{
		#ifndef CONFIG_OF
		clk_disable(gps_clk_32k);
		#else
		clk_disable_unprepare(gps_clk_32k);
		#endif
	}
}

TCgReturnCode CgxDriverRFPowerDown(void)
{
	//DBG_FUNC_NAME("CgxDriverRFPowerDown")
	TCgReturnCode rc = ECgOk;
	unsigned int value;

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

	/*RF4in1 */
	value = 0x07000000;//GPS Mode 0:Idle 1:Rx
	gps_spi_write_bytes(1, 0x80*4, value);
	return rc;
}

TCgReturnCode CgxDriverRFPowerUp(void)
{
	//DBG_FUNC_NAME("CgxDriverRFPowerDown")
	TCgReturnCode rc = ECgOk;

	printk("%s\n",__func__);
	CgxDriverRFInit();
	return rc;
}

void gps_chip_power_on(void)
{
	printk("%s\n",__func__);

	greeneye_vddsim2_enable(1);
	gps_clk_init(1);

	//pdn pin pull high
	CgCpuGpioModeSet(CG_DRIVER_GPIO_GPS_PDN, ECG_CPU_GPIO_OUTPUT);
	CgCpuGpioSet(CG_DRIVER_GPIO_GPS_PDN);
	CgCpuDelay(1000);

	//reset
	CgCpuGpioModeSet(CG_DRIVER_GPIO_GPS_MRSTN, ECG_CPU_GPIO_OUTPUT);
	CgCpuIPMasterResetClear();
	msleep(1);
	CgCpuIPMasterResetOn();
	msleep(5);
	CgCpuIPMasterResetClear();
	msleep(1);

	//gps core reset
	gps_spi_write_bytes(1, 0Xfc, 0x0);
	gps_spi_write_bytes(1, 0Xfc, 0x0f);
	msleep(1);
	CgxDriverRFPowerUp();
}

void gps_chip_power_off(void)
{
	printk("%s\n",__func__);

	//pdn pin pull low
	CgCpuGpioModeSet(CG_DRIVER_GPIO_GPS_PDN, ECG_CPU_GPIO_OUTPUT);
	CgCpuGpioReset(CG_DRIVER_GPIO_GPS_PDN);
	CgCpuDelay(1000);
	msleep(1);

	//reset pin pull low
	CgCpuIPMasterResetOn();

	//spi2  pin pull low
	gpio_direction_output(CG_DRIVER_GPIO_GPS_SPI_CS, 0);
	greeneye_vddsim2_enable(0);
	gps_clk_init(0);
}

#else
static TCgReturnCode CgxDriverRFInit(void)
{
	u32 value;
	gps_rf_ops->write_reg(0x0700,0x0001);
	gps_rf_ops->write_reg(0x004a,0xf417);
	gps_rf_ops->write_reg(0x076c,0x0721);
	gps_rf_ops->write_reg(0x0763,0x5141);
	gps_rf_ops->write_reg(0x0738,0x5400);
	gps_rf_ops->write_reg(0x0704,0xef00);
	gps_rf_ops->write_reg(0X077b,0x0102);

	#if 1 /*for 26M  TCXO*/
	gps_rf_ops->write_reg(0X073c,0x08d2);
	gps_rf_ops->write_reg(0X0702,0x3d61);
	#else /*for 16M  TCXO*/
	gps_rf_ops->write_reg(0x073c,0x0000);
	gps_rf_ops->write_reg(0X0702,0x6180);
	#endif

	/* for IF*/
	#if 0
	gps_rf_ops->write_reg(0x075d,0x88e6);
	gps_rf_ops->write_reg(0x070a,0x7835);
	#endif

#if 1
	/*for debug log */
	gps_rf_ops->read_reg(0x004a,&value);
	printk("0x004af417 value: %x\n", value);

	gps_rf_ops->read_reg(0x076c,&value);
	printk("0x076c0721 value: %x\n", value);

	gps_rf_ops->read_reg(0x0763,&value);
	printk("0x07635141 value: %x\n", value);

	gps_rf_ops->read_reg(0x0738,&value);
	printk("0x07385400 value: %x\n", value);

	gps_rf_ops->read_reg(0x0704,&value);
	printk("0x0704ef00 value: %x\n", value);

	gps_rf_ops->read_reg(0X077b,&value);
	printk("0x077b0102 value: %x\n", value);

	gps_rf_ops->read_reg(0x0700,&value);
	printk("0x07000001 value: %x\n", value);

	#if 1 /*for 26M  TCXO*/
	gps_rf_ops->read_reg(0X073c,&value);
	printk("0x073c08d2 value: %x\n", value);

	gps_rf_ops->read_reg(0X0702,&value);
	printk("0x07023d61 value: %x\n", value);
	#else /*for 16M  TCXO*/
	gps_rf_ops->read_reg(0x073c,&value);
	printk("0x073c0000 value: %x\n", value);

	gps_rf_ops->read_reg(0X0702,&value);
	printk("0x07026180 value: %x\n", value);
	#endif

	/* for IF*/
	#if 0
	gps_rf_ops->read_reg(0x075d,&value);
	printk("0x075d88e6 value: %x\n", value);

	gps_rf_ops->read_reg(0x070a,&value);
	printk("0x070a7835 value: %x\n", value);
	#endif
#endif

	return 0;

}

void gps_gpio_request(void)
{
	int ret;
	ret = gpio_request (SPRD_GPS_LNA_EN, "gps_lna");
	if (ret){
		printk ("GPS_LNE request err: %d\n", SPRD_GPS_LNA_EN);
	}
}

static void gps_lna_enable(void)
{
	gpio_direction_output(SPRD_GPS_LNA_EN,1);
}

static void gps_lna_disable(void)
{
	gpio_direction_output(SPRD_GPS_LNA_EN,0);
}

static void gps_reg_init(void)
{
#ifdef CONFIG_ARCH_SCX30G
	/*GPS Clock Select to CLK_SINE0*/
	sci_glb_clr(SPRD_GPS_CLK_SEL,BIT_3);

	/*Disable 26M Clock Gating*/
	sci_glb_clr(SPRD_GPS_CLK_AUTO_GATING,BIT_0);
#endif
}

TCgReturnCode CgxDriverRFPowerDown(void)
{
	//DBG_FUNC_NAME("CgxDriverRFPowerDown")
	TCgReturnCode rc = ECgOk;

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

	gps_rf_ops->mspi_enable();
	gps_rf_ops->write_reg(0x0700,0x0000);
	gps_lna_disable();
	gps_rf_ops->mspi_disable();
	return rc;
}

TCgReturnCode CgxDriverRFPowerUp(void)
{
	//DBG_FUNC_NAME("CgxDriverRFPowerDown")
	TCgReturnCode rc = ECgOk;

	printk("%s\n",__func__);
	gps_rf_ops->mspi_enable();
	gps_lna_enable();
	gps_reg_init();
	CgxDriverRFInit();
	gps_rf_ops->mspi_disable();
	return rc;
}

void gps_chip_power_on(void)
{
	printk("%s\n",__func__);
#ifdef CONFIG_ARCH_SCX20
    rf2351_vddwpa_ctrl_power_enable(1);
#endif
	//enable gps sysclk
	CGCoreSclkEnable(1);

	//gps core reset
	CgxCpuWriteMemory((U32)CG_DRIVER_CGCORE_BASE_VA, 0xfc,0xf);
	CgxDriverRFPowerUp();
}

void gps_chip_power_off(void)
{
	printk("%s\n",__func__);
	CgxDriverRFPowerDown();

	//gps core reset
	CgxCpuWriteMemory((U32)CG_DRIVER_CGCORE_BASE_VA, 0xfc,0x0);
	CGCoreSclkEnable(0);
#ifdef CONFIG_ARCH_SCX20
    rf2351_vddwpa_ctrl_power_enable(0);
#endif
}
#endif

TCgReturnCode CgxDriverTcxoEnable(U32 aEnable)
{
	// default implementation assumes direct manipulation of TCXO LDO via a dedicated GPIO pin.
	// either CG_DRIVER_GPIO_TCXO_ENABLE or CG_DRIVER_GPIO_TCXO_DISABLE should be defined depending
	// on the LDO control level (active high / active low)

	#if defined(CG_DRIVER_GPIO_TCXO_ENABLE)
		if (aEnable)
			CgCpuGpioSet(CG_DRIVER_GPIO_TCXO_ENABLE);
		else
			CgCpuGpioReset(CG_DRIVER_GPIO_TCXO_ENABLE);
	#elif defined(CG_DRIVER_GPIO_TCXO_DISABLE)
		if (aEnable)
			CgCpuGpioReset(CG_DRIVER_GPIO_TCXO_DISABLE);
		else
			CgCpuGpioSet(CG_DRIVER_GPIO_TCXO_DISABLE);
	#endif

	return ECgOk;
}



TCgReturnCode CgCpuRevision(char *apRevisionCode)
{

    //sprintf(apRevisionCode,"SPRD_FPGA-R255",0);
    sprintf(apRevisionCode,"SPRD_FPGA-R255");

	return ECgOk;

}


TCgReturnCode CgCpuClockDestroy(void)
{
	TCgReturnCode rc = ECgOk;
	return rc;
}

TCgReturnCode CgCpuIntrDestroy(void)
{
 	TCgReturnCode rc = ECgOk;
 //   #if defined(CG_DRIVER_INTR_BASE_PA) && !defined(CG_DRIVER_INTR_BASE_VA)
//        rc = CgCpuVirtualFree((volatile void **)&gpINTR);
 //   #endif
	return rc;
}


TCgReturnCode CgCpuIPMasterResetClear(void)
{
	TCgReturnCode rc = ECgOk;
        DBG_FUNC_NAME("CgCpuIPMasterResetClear");

	DBGMSG("start");
	// Set master reset pin to '1' (reset off - device active)
	#ifdef CGCORE_ACCESS_VIA_SPI
	CgCpuGpioSet(CG_DRIVER_GPIO_GPS_MRSTN);
	#else
   // CgCpuGpioSet(CG_DRIVER_GPIO_GPS_MRSTN);
	#endif

	return rc;
}




TCgReturnCode CgCpuIPMasterResetOn(void)
{
	TCgReturnCode rc = ECgOk;
    DBG_FUNC_NAME("CgCpuIPMasterResetOn");

	DBGMSG("start");
	// Set master reset pin to '0' (reset on - device inactive)

	#ifdef CGCORE_ACCESS_VIA_SPI
	CgCpuGpioReset(CG_DRIVER_GPIO_GPS_MRSTN);
	#else
    //CgCpuGpioReset(CG_DRIVER_GPIO_GPS_MRSTN);
	#endif

	return rc;
}


TCgReturnCode CgCpuAllocateVa(void)
{
	// Nothing to do for SPRD_FPGA
	return ECgOk;
}