841c45409856adaacebe49ecf5535a39ff77e97f
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc9630 / gpio_phy_v0.c
1 /******************************************************************************
2  ** File Name:      gpio_phy_v0.c                                                 *
3  ** Author:         Steve.Zhan                                                   *
4  ** DATE:           07/28/2010                                                *
5  ** Copyright:      2010 Spreatrum, Incoporated. All Rights Reserved.         *
6  ** Description:    This file define the physical layer of I2C device.      *
7  ******************************************************************************
8
9  ******************************************************************************
10  **                        Edit History                                       *
11  ** ------------------------------------------------------------------------- *
12  ** DATE           NAME             DESCRIPTION                               *
13  ** 07/28/2010     Steve.Zhan       Create.                                   *
14  ******************************************************************************/
15
16 /**---------------------------------------------------------------------------*
17  **                         Dependencies                                      *
18  **---------------------------------------------------------------------------*/
19 #include "sci_types.h"
20 #include "os_api.h"
21 #include "chip_plf_export.h"
22 #include "gpio_drvapi.h"
23 #include "../gpio_phy.h"
24 #ifdef PLATFORM_SC6800H
25 #include "gpio_reg_v0.h"
26 #endif
27 /*lint -e30 -e502 -e26 -e63 */
28 /**---------------------------------------------------------------------------*
29  **                            Macro Define
30  **---------------------------------------------------------------------------*/
31 #ifndef GPI_DATA
32 #define GPI_DATA           0xFFFF
33 #endif
34
35 #ifndef GPO_DATA
36 #define GPO_DATA           0xFFFF
37 #endif
38
39 #ifndef GPIO_DATA
40 #define GPIO_DATA          0xFFFF
41 #endif
42
43 #ifndef GPI_DMSK
44 #define GPI_DMSK           0xFFFF
45 #endif
46
47 #ifndef GPO_TRI
48 #define GPO_TRI            0xFFFF
49 #endif
50
51 #ifndef GPIO_DMSK
52 #define GPIO_DMSK          0xFFFF
53 #endif
54
55 #ifndef GPI_IE
56 #define GPI_IE             0xFFFF
57 #endif
58
59 #ifndef GPIO_IE
60 #define GPIO_IE            0xFFFF
61 #endif
62
63 #ifndef GPIO_DIR
64 #define GPIO_DIR           0xFFFF
65 #endif
66
67 #ifndef GPI_MIS
68 #define GPI_MIS            0xFFFF
69 #endif
70
71 #ifndef GPIO_MIS
72 #define GPIO_MIS           0xFFFF
73 #endif
74
75 #ifndef GPI_IC
76 #define GPI_IC             0xFFFF
77 #endif
78
79 #ifndef GPIO_IC
80 #define GPIO_IC            0xFFFF
81 #endif
82
83 #ifndef GPI_IEV
84 #define GPI_IEV            0xFFFF
85 #endif
86
87 #ifndef GPIO_IS
88 #define GPIO_IS            0xFFFF
89 #endif
90
91 #ifndef GPIO_IC
92 #define GPIO_IC            0xFFFF
93 #endif
94
95 #ifndef GPIO_IBE
96 #define GPIO_IBE           0xFFFF
97 #endif
98
99 #ifndef GPI_0CTRL
100 #define GPI_0CTRL          0xFFFF
101 #endif
102
103 #ifndef GPI_TRIG
104 #define GPI_TRIG           0xFFFF
105 #endif
106
107 #ifndef GPI_DEBOUNCE_BIT
108 #define GPI_DEBOUNCE_BIT   255
109 #endif
110
111 #ifndef GPIO_REG_SET
112 #define GPIO_REG_SET       CHIP_REG_SET
113 #endif
114
115 #ifndef GPIO_REG32
116 #define GPIO_REG32         REG32
117 #endif
118
119 #ifndef GPIO_REG_AND
120 #define GPIO_REG_AND       CHIP_REG_AND
121 #endif
122
123 #ifndef GPIO_REG_OR
124 #define GPIO_REG_OR        CHIP_REG_OR
125 #endif
126
127 /*****************************************************************************/
128 //  Description:    This function get gpio module base info.
129 //  Dependency:     Gpio_GetCfgSectionTable(uint32 *table)
130 //  Author:         Steve.Zhan
131 //  Note:
132 /*****************************************************************************/
133 /*lint -e{681} -e{737}*/
134 PUBLIC void GPIO_PHY_GetBaseInfo (uint32 gpio_id, GPIO_INFO_T *pGpio_info)
135 {
136     uint32 i = 0;
137     uint32 table_size = 0;
138
139     GPIO_SECTION_T  *p_gpio_section_table = (GPIO_SECTION_T *) Gpio_GetCfgSectionTable (&table_size);
140
141     SCI_ASSERT (gpio_id < GPIO_MAX_PIN_NUM && table_size > 0);
142     
143
144     pGpio_info->baseAddr = GpioCfg_GetBaseAddr (gpio_id);//lint !e527 eliminate pclint "e533" by steve.zhan
145     pGpio_info->bit_num  = GpioCfg_GetBitNum (gpio_id);
146
147     for (i = 0; i < table_size; ++i)
148     {
149         if (p_gpio_section_table[i].gpxx_pagex_base == pGpio_info->baseAddr)
150         {
151             if (p_gpio_section_table[i].gpxx_pagex_size > pGpio_info->bit_num)
152             {
153                 pGpio_info->gpio_type = p_gpio_section_table[i].gpxx_section_type;
154                 return;
155             }
156
157             break;
158         }
159     }
160
161     pGpio_info->gpio_type = GPIO_SECTION_INVALID;
162
163     return;
164 }
165
166 /*****************************************************************************/
167 //  Description:    This function get gpio data register addr.
168 //  Dependency:
169 //  Author:
170 //  Note:
171 /*****************************************************************************/
172 LOCAL BOOLEAN _GPIO_GetGpioDataRegAddr (GPIO_INFO_T *pGpio_info, uint32 *pOffsetAddr)
173 {
174     switch (pGpio_info->gpio_type)
175     {
176         case GPIO_SECTION_GPI:
177             *pOffsetAddr = GPI_DATA;
178             break;
179         case GPIO_SECTION_GPO:
180             *pOffsetAddr = GPO_DATA;
181             break;
182         case GPIO_SECTION_GPIO:
183             *pOffsetAddr = GPIO_DATA;
184             break;
185         case GPIO_SECTION_INVALID:
186             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
187             GPIO_SECTION_ASSERT (0);
188             return SCI_FALSE;
189         default:
190             SCI_ASSERT (0);
191             break;
192     }
193
194     return TRUE;
195
196 }
197
198 /*****************************************************************************/
199 //  Description:    This function used to get the state of a gpio gpi gpo pin
200 //  Author:         Zhemin.Lin
201 //  retread by:     Steve.Zhan
202 //  Note:
203 /*****************************************************************************/
204 PUBLIC BOOLEAN GPIO_PHY_GetPinData (GPIO_INFO_T *pGpio_info)
205 {
206     uint32 offsetAddr = 0;
207     uint32 reg_addr = 0;
208
209     reg_addr = pGpio_info->baseAddr;
210
211     if (_GPIO_GetGpioDataRegAddr (pGpio_info, &offsetAddr))
212     {
213         reg_addr += offsetAddr;
214         return ( (GPIO_REG32 (reg_addr) & (1<<pGpio_info->bit_num)) ? SCI_TRUE : SCI_FALSE);
215     }
216
217     return SCI_FALSE;
218 }
219
220 /*****************************************************************************/
221 //  Description:    This function used to get the state of a gpio pin
222 //  Author:         Yiyue.He
223 //  Note:
224 /*****************************************************************************/
225 PUBLIC void GPIO_PHY_SetPinData (GPIO_INFO_T *pGpio_info ,BOOLEAN b_on)
226 {
227     uint32 offsetAddr = 0;
228     uint32 reg_addr = 0;
229     BOOLEAN value = (b_on ? SCI_TRUE : SCI_FALSE);
230
231     reg_addr = pGpio_info->baseAddr;
232
233     _GPIO_GetGpioDataRegAddr (pGpio_info, &offsetAddr);
234     reg_addr += offsetAddr;
235
236     GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) |
237                               (value<<pGpio_info->bit_num)));
238
239 }
240
241 /*****************************************************************************/
242 //  Description:    This function get gpio data Mask register addr.
243 //  Dependency:
244 //  Author:
245 //  Note:
246 /*****************************************************************************/
247 LOCAL BOOLEAN _GPIO_GetGpioDataMaskRegAddr (GPIO_INFO_T *pGpio_info, uint32 *pOffsetAddr)
248 {
249     switch (pGpio_info->gpio_type)
250     {
251         case GPIO_SECTION_GPI:
252             *pOffsetAddr = GPI_DMSK;
253             break;
254         case GPIO_SECTION_GPO:
255             *pOffsetAddr = GPO_TRI;
256             break;
257         case GPIO_SECTION_GPIO:
258             *pOffsetAddr = GPIO_DMSK;
259             break;
260         case GPIO_SECTION_INVALID:
261             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
262             GPIO_SECTION_ASSERT (0);
263             return SCI_FALSE;
264         default:
265             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
266             SCI_ASSERT (0);
267             return SCI_FALSE;//lint !e527, by steve.zhan
268     }
269
270     return TRUE;
271 }
272
273
274 /*****************************************************************************/
275 //  Description:    This function used to know whether the gpio port is enabled.
276 //  notes:
277 /*****************************************************************************/
278 PUBLIC BOOLEAN GPIO_PHY_GetDataMask (GPIO_INFO_T *pGpio_info)
279 {
280     uint32 offsetAddr = 0;
281     uint32 reg_addr = 0;
282
283     reg_addr = pGpio_info->baseAddr;
284
285     if (_GPIO_GetGpioDataMaskRegAddr (pGpio_info, &offsetAddr))
286     {
287         reg_addr += offsetAddr;
288         return ( (GPIO_REG32 (reg_addr) & (1<<pGpio_info->bit_num)) ? SCI_TRUE : SCI_FALSE);
289     }
290
291     return SCI_FALSE;
292 }
293
294 /*****************************************************************************/
295 //  Description:    This function used to know whether the gpio port is enabled.
296 //  Note:              0 - disable
297 //                     1 - enable
298 /*****************************************************************************/
299 PUBLIC void GPIO_PHY_SetDataMask (GPIO_INFO_T *pGpio_info, BOOLEAN b_on)
300 {
301     BOOLEAN value = (b_on ? SCI_TRUE : SCI_FALSE);
302     uint32 reg_addr = 0;
303     uint32 offsetAddr = 0;
304
305     reg_addr = pGpio_info->baseAddr;
306
307     if (_GPIO_GetGpioDataMaskRegAddr (pGpio_info, &offsetAddr))
308     {
309         reg_addr += offsetAddr;
310         GPIO_REG_SET ( (reg_addr), ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) |
311                                      (value<<pGpio_info->bit_num)));
312     }
313
314     return;
315 }
316
317 LOCAL BOOLEAN _GPIO_GetGpioIntMaskAddr (GPIO_INFO_T *pGpio_info, uint32 *pOffsetAddr)
318 {
319     switch (pGpio_info->gpio_type)
320     {
321         case GPIO_SECTION_GPI:
322             *pOffsetAddr = GPI_IE;
323             break;
324         case GPIO_SECTION_GPO:
325             GPIO_PRINT ( ("[GPIO_DRV]this opretion can not belong to GPO"));
326             return SCI_FALSE;
327
328         case GPIO_SECTION_GPIO:
329             *pOffsetAddr = GPIO_IE;
330             break;
331
332         case GPIO_SECTION_INVALID:
333             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
334             //          GPIO_SECTION_ASSERT (0);
335             return SCI_FALSE;
336
337         default:
338             SCI_ASSERT (0);
339             break;
340     }
341
342     return TRUE;
343
344 }
345
346 /*****************************************************************************/
347 //  Description:    This function used to know whether the gpio int mask is enabled.
348 //                  Interrupt mask register, "1" corresponding pin is not masked.
349 //                  "0" corresponding pin interrupt is masked
350 //  Author:         Benjamin.Wang
351 //  Retreat by:     Steve.Zhan
352 //  Note:           SCI_FALSE - disable
353 //                  SCI_TRUE - enable
354 /*****************************************************************************/
355 PUBLIC BOOLEAN GPIO_PHY_GetIntIsMask (GPIO_INFO_T *pGpio_info)
356 {
357     uint32 reg_addr = 0;
358     uint32 offsetAddr = 0;
359
360     reg_addr = pGpio_info->baseAddr;
361
362     if (_GPIO_GetGpioIntMaskAddr (pGpio_info, &offsetAddr))
363     {
364         reg_addr += offsetAddr;
365         return ( (GPIO_REG32 (reg_addr) & (1<<pGpio_info->bit_num)) ? SCI_TRUE : SCI_FALSE);
366     }
367
368     return FALSE;
369 }
370
371 /*****************************************************************************/
372 //  Description:    This function used to Set GPIO IE. enable interrupt.
373 //  Note:
374 //
375 /*****************************************************************************/
376 PUBLIC void GPIO_PHY_SetIntMask (GPIO_INFO_T *pGpio_info)
377 {
378     BOOLEAN value = SCI_TRUE;
379     uint32 reg_addr = 0;
380     uint32 offsetAddr = 0;
381
382     reg_addr = pGpio_info->baseAddr;
383
384     if (_GPIO_GetGpioIntMaskAddr (pGpio_info, &offsetAddr))
385     {
386         reg_addr += offsetAddr;
387         GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) |
388                                   (value<<pGpio_info->bit_num)));
389     }
390
391     return;
392 }
393
394 /*****************************************************************************/
395 //  Description:    This function used to Set GPIO IE. disable interrupt.
396 //  Note:
397 //
398 /*****************************************************************************/
399 PUBLIC void GPIO_PHY_CleanIntMask (GPIO_INFO_T *pGpio_info)
400 {
401     BOOLEAN value = SCI_FALSE;
402     uint32 reg_addr = 0;
403     uint32 offsetAddr = 0;
404
405     reg_addr = pGpio_info->baseAddr;
406
407     if (_GPIO_GetGpioIntMaskAddr (pGpio_info, &offsetAddr))
408     {
409         reg_addr += offsetAddr;
410         GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) |
411                                   (value<<pGpio_info->bit_num)));
412     }
413
414     return;
415
416 }
417
418 /*****************************************************************************/
419 //  Description:    This function used to get the direction of a gpio pin
420 //  Note:              0 - Input
421 //                     1 - Output
422 /*****************************************************************************/
423 PUBLIC BOOLEAN GPIO_PHY_GetDirection (GPIO_INFO_T *pGpio_info)
424 {
425     uint32 reg_addr = 0;
426     reg_addr = pGpio_info->baseAddr;
427
428     switch (pGpio_info->gpio_type)
429     {
430         case GPIO_SECTION_GPI:
431             return SCI_FALSE;
432
433         case GPIO_SECTION_GPO:
434             return SCI_TRUE;
435
436         case GPIO_SECTION_GPIO:
437             reg_addr += GPIO_DIR;
438             break;
439
440         case GPIO_SECTION_INVALID:
441             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
442             GPIO_SECTION_ASSERT (0);
443             return SCI_FALSE;
444
445         default:
446             SCI_ASSERT (0);
447             break;
448     }
449
450     return ( (GPIO_REG32 (reg_addr) & (1<<pGpio_info->bit_num)) ? SCI_TRUE : SCI_FALSE);
451 }
452
453 /*****************************************************************************/
454 //  Description:    This function used to set the direction of a gpio pin
455 //  Note:              0 - Input
456 //                        1 - Output
457 /*****************************************************************************/
458 PUBLIC void GPIO_PHY_SetDirection (GPIO_INFO_T *pGpio_info, BOOLEAN directions)
459 {
460     BOOLEAN value = (directions ? SCI_TRUE : SCI_FALSE);
461     uint32 reg_addr = 0;
462     reg_addr = pGpio_info->baseAddr;
463
464     switch (pGpio_info->gpio_type)
465     {
466         case GPIO_SECTION_GPI:
467
468             if (directions)
469             {
470                 GPIO_PRINT ( ("[GPIO_DRV]GPIO_SetDirection error"));
471                 GPIO_SECTION_ASSERT (0);
472             }
473
474             return;
475
476         case GPIO_SECTION_GPO:
477
478             if (!directions)
479             {
480                 GPIO_PRINT ( ("[GPIO_DRV]GPIO_SetDirection error"));
481                 GPIO_SECTION_ASSERT (0);
482             }
483
484             return;
485
486         case GPIO_SECTION_GPIO:
487             reg_addr += GPIO_DIR;
488             break;
489         case GPIO_SECTION_INVALID:
490             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
491             GPIO_SECTION_ASSERT (0);
492             return;
493
494         default:
495             SCI_ASSERT (0);
496             break;
497     }
498
499     GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) | (value<<pGpio_info->bit_num)));
500
501 }
502
503
504 /*****************************************************************************/
505 //  Description:    This function used to get the intr state of a gpio pin
506 //  Author:         Zhemin.Lin
507 //  retread by:    Yiyue.He
508 //  Retreat by:     Steve.Zhan
509 //  Note:
510 /*****************************************************************************/
511 PUBLIC BOOLEAN GPIO_PHY_GetIntState (GPIO_INFO_T *pGpio_info)
512 {
513     uint32 reg_addr = 0;
514
515     reg_addr = pGpio_info->baseAddr;
516
517     switch (pGpio_info->gpio_type)
518     {
519         case GPIO_SECTION_GPI:
520             reg_addr += GPI_MIS;
521             break;
522         case GPIO_SECTION_GPO:
523             GPIO_PRINT ( ("[GPIO_DRV]The corresponding reg of this GPIO_ID is a GPO! No Intr!"));
524             return SCI_FALSE;
525
526         case GPIO_SECTION_GPIO:
527             reg_addr += GPIO_MIS;
528             break;
529         case GPIO_SECTION_INVALID:
530             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
531             GPIO_SECTION_ASSERT (0);
532             return SCI_FALSE;
533
534         default:
535             SCI_ASSERT (0);
536             break;
537     }
538
539     return ( (GPIO_REG32 (reg_addr) & (1<<pGpio_info->bit_num)) ? SCI_TRUE : SCI_FALSE);
540 }
541
542 /*****************************************************************************/
543 //  Description:    This function used to clear the given interrupt status bit.
544 //  Author:           Benjamin.Wang
545 // retread by:        Yiyue.He
546 //  Retreat by:     Steve.Zhan
547 //  Note:
548 /*****************************************************************************/
549 PUBLIC void GPIO_PHY_ClearIntStatus (GPIO_INFO_T *pGpio_info)
550 {
551     BOOLEAN value = SCI_TRUE;
552     uint32 reg_addr = 0;
553
554     reg_addr = pGpio_info->baseAddr;
555
556     switch (pGpio_info->gpio_type)
557     {
558         case GPIO_SECTION_GPI:
559             reg_addr += GPI_IC;
560             break;
561         case GPIO_SECTION_GPO:
562             GPIO_PRINT ( ("[GPIO_DRV]this opretion can not belong to GPO"));
563             return;
564         case GPIO_SECTION_GPIO:
565             reg_addr += GPIO_IC;
566             break;
567         case GPIO_SECTION_INVALID:
568             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
569             GPIO_SECTION_ASSERT (0);
570             return;
571
572         default:
573             SCI_ASSERT (0);
574             break;
575     }
576
577     GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) | (value <<pGpio_info->bit_num)));
578 }
579
580 /*****************************************************************************/
581 //  Description:    This function used to set gpio Interrupt sense type.
582 //  Author:         Benjamin.Wang
583 //  Retreat by:     Steve.Zhan
584 //  Note:
585 /*****************************************************************************/
586 /*lint -e{737}*/
587 PUBLIC void GPIO_PHY_SetInterruptSense (GPIO_INFO_T *pGpio_info, GPIO_INT_TYPE sensetype)
588 {
589     switch (pGpio_info->gpio_type)
590     {
591         case GPIO_SECTION_GPI:
592             {
593                 switch (sensetype)
594                 {
595                     case GPIO_INT_LEVEL_HIGH:   // detect high level.
596                         GPIO_REG_OR ( (pGpio_info->baseAddr + GPI_IEV), (0x1 << pGpio_info->bit_num));
597                         break;
598
599                     case GPIO_INT_LEVEL_LOW:    // detect low level.
600                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPI_IEV), ~ (0x1 << pGpio_info->bit_num));
601                         break;
602
603                     case GPIO_INT_EDGES_BOTH:    // detect the rising edges and falling edges.
604                     case GPIO_INT_EDGES_RISING:  // detect the rising edges.
605                     case GPIO_INT_EDGES_FALLING:
606
607                     default:
608                         GPIO_PRINT ( ("This Intr sense type is invalid for GPI. \n"));
609                         SCI_ASSERT (0);
610                         break;
611                 }
612             }
613             break;
614
615         case GPIO_SECTION_GPO:
616             GPIO_PRINT ( ("[GPIO_DRV]this opretion can not belong to GPO"));
617             GPIO_SECTION_ASSERT (0);
618             return;
619           
620         case GPIO_SECTION_GPIO:
621             {
622                 switch (sensetype)
623                 {
624                     case GPIO_INT_LEVEL_HIGH:   // detect high level.
625                         GPIO_REG_OR ( (pGpio_info->baseAddr + GPIO_IS), (0x1 << pGpio_info->bit_num));
626                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IBE), ~ (0x1 << pGpio_info->bit_num));
627                         GPIO_REG_OR ( (pGpio_info->baseAddr + GPIO_IEV), (0x1 << pGpio_info->bit_num));
628                         break;
629
630                     case GPIO_INT_LEVEL_LOW:    // detect low level.
631                         GPIO_REG_OR ( (pGpio_info->baseAddr + GPIO_IS), (0x1 << pGpio_info->bit_num));
632                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IBE), ~ (0x1 <<pGpio_info->bit_num));
633                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IEV), ~ (0x1 <<pGpio_info->bit_num));
634                         break;
635
636                     case GPIO_INT_EDGES_BOTH:    // detect the rising edges and falling edges.
637                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IS), ~ (0x1 << pGpio_info->bit_num));
638                         GPIO_REG_OR ( (pGpio_info->baseAddr + GPIO_IBE), (0x1 << pGpio_info->bit_num));
639                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IEV), ~ (0x1 << pGpio_info->bit_num));
640                         break;
641
642                     case GPIO_INT_EDGES_RISING:  // detect the rising edges.
643                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IS), ~ (0x1 << pGpio_info->bit_num));
644                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IBE), ~ (0x1 << pGpio_info->bit_num));
645                         GPIO_REG_OR ( (pGpio_info->baseAddr + GPIO_IEV), (0x1 << pGpio_info->bit_num));
646                         break;
647
648                     case GPIO_INT_EDGES_FALLING:
649                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IS), ~ (0x1 << pGpio_info->bit_num));
650                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IBE), ~ (0x1 << pGpio_info->bit_num));
651                         GPIO_REG_AND ( (pGpio_info->baseAddr + GPIO_IEV), ~ (0x1 << pGpio_info->bit_num));
652                         break;
653
654                     default:
655                         GPIO_PRINT ( ("This operation is invalid. \n"));
656                 }
657             }
658             break;
659         case GPIO_SECTION_INVALID:
660             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
661             GPIO_SECTION_ASSERT (0);
662             return;
663         default:
664             SCI_ASSERT (0);
665             break;
666     }
667
668 }
669
670 /*****************************************************************************/
671 //  Description:    This function used to set gpin Debounce time.
672 //  Author:         Steve.Zhan
673 //  Note:
674 /*****************************************************************************/
675 /*lint -e{737} -e{718}*/
676 PUBLIC void GPIO_PHY_SetGPIDebounce (GPIO_INFO_T *pGpio_info, uint8 debounce_period)
677 {
678     uint32 i = 0;
679     uint32 reg_addr = 0;
680     uint32 size  = 0;
681     GPIO_SECTION_E *gpio_type = NULL;
682     
683     gpio_type = Gpio_GetCfgDebounceGpioTable (&size);
684
685     for (i = 0; i< size ; ++i)
686     {
687         if ( (int) pGpio_info->gpio_type != (int) gpio_type[i])
688         {
689             continue; 
690         }
691         else
692         {
693             break;
694         }
695     }
696
697     if (i == size)
698     {
699         GPIO_PRINT ( ("[GPIO_DRV]this opretion can not belong to SetGPIDebounce"));
700         return;
701     }
702
703     reg_addr = pGpio_info->baseAddr;
704
705     reg_addr += (GPI_0CTRL+ (pGpio_info->bit_num<<2));
706
707     if (debounce_period >= 1)
708     {
709         GPIO_REG_OR (reg_addr, GPI_DEBOUNCE_BIT);
710         GPIO_REG_SET (reg_addr, (GPIO_REG32 (reg_addr) & 0xFF00) +debounce_period);
711     }
712     else// not recommend
713     {
714         GPIO_REG_AND (reg_addr, ~GPI_DEBOUNCE_BIT); //bypass mode
715     }
716
717 }
718
719 /*****************************************************************************/
720 //  Description:    This function used to set  gpi  Interrupt Trigering
721 //  Author:         Steve.Zhan
722 //  Note:
723 /*****************************************************************************/
724 PUBLIC void GPIO_PHY_TrigGPIDetect (GPIO_INFO_T *pGpio_info)
725 {
726     BOOLEAN value=SCI_TRUE;
727     uint32 reg_addr = 0;
728
729     reg_addr = pGpio_info->baseAddr;
730
731     switch (pGpio_info->gpio_type)
732     {
733         case GPIO_SECTION_GPI:
734             reg_addr += GPI_TRIG;
735             break;
736
737         case GPIO_SECTION_GPO:
738         case GPIO_SECTION_GPIO:
739             GPIO_PRINT ( ("[GPIO_DRV]this opretion can not belong to GPO/GPIO"));
740             return;
741
742         case GPIO_SECTION_INVALID:
743             GPIO_PRINT ( ("[GPIO_DRV]the GPIO_ID is Invalid in this chip"));
744             GPIO_SECTION_ASSERT (0);
745             return;
746
747         default:
748             SCI_ASSERT (0);
749             break;
750     }
751
752     GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) | (value<<pGpio_info->bit_num)));
753
754 }
755
756 /*****************************************************************************/
757 //  Description:    This function used to Enable gpi Detect function
758 //  Author:         Steve.Zhan
759 //  Note:
760 /*****************************************************************************/
761 PUBLIC void GPIO_PHY_EnableGPIDetect (GPIO_INFO_T *pGpio_info)
762 {
763     switch (pGpio_info->gpio_type)
764     {
765         case GPIO_SECTION_GPI:
766             GPIO_PHY_SetIntMask (pGpio_info);
767             GPIO_PHY_TrigGPIDetect (pGpio_info);
768             break;
769         case GPIO_SECTION_GPO:
770         case GPIO_SECTION_GPIO:
771             return;
772
773         default:
774             SCI_ASSERT (0);
775             break;
776     }
777 }