tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8800g / sc8800g_gpio_cfg.h
1 /******************************************************************************
2  ** File Name:    sc8800g_gpio_cfg.h                                         *
3  ** Author:       Steve.Zhan                                                 *
4  ** DATE:         06/05/2010                                                  *
5  ** Copyright:    2010 Spreatrum, Incoporated. All Rights Reserved.           *
6  ** Description:                                                              *
7  ******************************************************************************/
8 /******************************************************************************
9  **                   Edit    History                                         *
10  **---------------------------------------------------------------------------*
11  ** DATE          NAME            DESCRIPTION                                 *
12  ** 06/05/2010    Steve.Zhan      Create.                                     *
13  ******************************************************************************/
14 #ifndef _SC8800G_GPIO_CFG_H_
15 #define _SC8800G_GPIO_CFG_H_
16 #include "adi_reg_v3.h"
17 #include "sc8800g_reg_base.h"
18 #include "chip_drv_common_io.h"
19 #include "adi_hal_internal.h"
20 #include "sc8800g_reg_base.h"
21 /*----------------------------------------------------------------------------*
22  **                         Dependencies                                      *
23  **------------------------------------------------------------------------- */
24
25 /**---------------------------------------------------------------------------*
26  **                             Compiler Flag                                 *
27  **--------------------------------------------------------------------------*/
28 #ifdef   __cplusplus
29 extern   "C"
30 {
31 #endif
32 #if 0
33 /**---------------------------------------------------------------------------*
34 **                               Micro Define                                **
35 **---------------------------------------------------------------------------*/
36 typedef enum
37 {
38     GPIO_SECTION_GPI = 0x0,
39     GPIO_SECTION_GPO,
40     GPIO_SECTION_GPIO,
41     GPIO_SECTION_INVALID
42 }
43 GPIO_SECTION_E;
44
45
46 typedef struct
47 {
48     uint32 gpxx_pagex_base;
49     uint32 gpxx_pagex_size;
50     GPIO_SECTION_E gpxx_section_type;
51 } GPIO_SECTION_T;
52 #define ADI_GPIO_ADDR_MASK 0x08000000
53
54 typedef struct
55 {
56     uint32 int_logic_num;
57     void *isr_func;
58
59 } GPIO_INT_T;
60
61
62 //configable begin
63 #define GPIO_DRV_DEBUG
64 //#define GPIO_ASSERT_IF_WRONG_SECTION //is only using for debug mode
65
66 #define MIN_DESHAKING_INTERVAL  10
67 #define GPI_DEBOUNCE_PERIED                255
68 #define GPI_MAX_DEBOUCE_INTERVAL  (GPI_DEBOUNCE_PERIED+ MIN_DESHAKING_INTERVAL*4) /*255+ 40(ignore)*/
69
70
71
72 static __inline uint32 GpioCfg_GetBaseAddr (uint32 gpio_id)
73 {
74     if (gpio_id >= 160)
75     {
76         return ( (gpio_id - 160) >>4) * 0x80 + (unsigned int) 0x82000600;
77     }
78
79     return (gpio_id>>4) * 0x80 + (uint32) GPIO_BASE;
80 }
81
82 static __inline uint32 GpioCfg_GetBitNum (uint32 gpio_id)
83 {
84     return (gpio_id & 0xF);
85 }
86 static __inline void gpio_chip_reg_set (uint32 reg_addr, uint32 value)
87 {
88     if (reg_addr & ADI_GPIO_ADDR_MASK)
89     {
90         CHIP_REG_SET (reg_addr,value);
91     }
92     else
93     {
94         ANA_REG_SET (reg_addr,value);
95     }
96
97     return;
98 }
99
100 static __inline uint32 gpio_chip_reg32 (uint32 reg_addr)
101 {
102     if (reg_addr & ADI_GPIO_ADDR_MASK)
103     {
104         return REG32 (reg_addr);
105     }
106     else
107     {
108         return ANA_REG_GET (reg_addr);
109     }
110 }
111 static __inline void gpio_chip_reg_and (uint32 reg_addr, uint32 value)
112 {
113     if (reg_addr & ADI_GPIO_ADDR_MASK)
114     {
115         CHIP_REG_AND (reg_addr,value);
116     }
117     else
118     {
119         ANA_REG_AND (reg_addr,value);
120     }
121 }
122 static __inline void gpio_chip_reg_or (uint32 reg_addr, uint32 value)
123 {
124     if (reg_addr & ADI_GPIO_ADDR_MASK)
125     {
126         CHIP_REG_OR (reg_addr,value);
127     }
128     else
129     {
130         ANA_REG_OR (reg_addr,value);
131     }
132 }
133
134 #define GPIO_REG_SET(x,y) gpio_chip_reg_set(x,y)
135 #define GPIO_REG32(x) gpio_chip_reg32(x)
136 #define GPIO_REG_AND(reg_addr, value) gpio_chip_reg_and(reg_addr, value)
137 #define GPIO_REG_OR(reg_addr, value) gpio_chip_reg_or(reg_addr, value)
138
139 /*****************************************************************************/
140 //  Description:    This function should be called at the gpio module, to get
141 //                  the info(the gpio Pin register addr, section size, gpio type).
142 //  Dependency:     s_gpio_section_table
143 //  Author:         Steve.Zhan
144 //  Note:
145 /*****************************************************************************/
146 PUBLIC GPIO_SECTION_T *Gpio_GetCfgSectionTable (uint32 *size);
147
148
149 /**----------------------------------------------------------------------------*
150 **                           Function Prototype                               **
151 **----------------------------------------------------------------------------*/
152 /*****************************************************************************/
153 //  Description:    This function get the gpio type that have debounce function.
154 //
155 //  Dependency:     s_gpio_section_table
156 //  Author:         Steve.Zhan
157 //  Note:
158 /*****************************************************************************/
159 GPIO_SECTION_E *Gpio_GetCfgDebounceGpioTable (uint32 *pSize);
160
161 /**----------------------------------------------------------------------------*
162 **                         Local Function Prototype                           **
163 **----------------------------------------------------------------------------*/
164
165 /**---------------------------------------------------------------------------*
166  **                         Function Definitions                              *
167  **---------------------------------------------------------------------------*/
168 //  Description:    This function be called by interrupt handler when is
169 //                  GPIO interrupt.
170 //  Author:         Xueliang.Wang
171 //  Note:
172 /*****************************************************************************/
173 PUBLIC void GPIO_Handler (uint32 int_num);
174
175
176 PUBLIC GPIO_INT_T *Gpio_GetCfgGpioIntTable (uint32 *pSize);
177
178 /**----------------------------------------------------------------------------*
179 **                           Function Prototype                               **
180 **----------------------------------------------------------------------------*/
181
182
183 /**----------------------------------------------------------------------------*
184 **                         Compiler Flag                                      **
185 **----------------------------------------------------------------------------*/
186 #endif // end of if 0
187 #ifdef   __cplusplus
188 }
189 #endif
190 /**---------------------------------------------------------------------------*/
191 #endif
192 // End