arm: sc8830: remove build warnings
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8830 / eic.c
1 /*
2  *  linux/arch/arm/mach-sprd/gpio.c
3  *
4  *  Generic SPRD GPIO handling
5  *
6  *  Author:     Yingchun Li(yingchun.li@spreadtrum.com)
7  *  Created:    March 10, 2010
8  *  Copyright:  Spreadtrum Inc.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License version 2 as
12  *  published by the Free Software Foundation.
13  */
14 #include <common.h>
15 #include <asm/io.h>
16 #include <asm/arch/sprd_reg.h>
17 #include <asm/arch/sci_types.h>
18 #include <asm/arch/sprd_eic.h>
19 #include <asm/arch/adi_hal_internal.h>
20 #include <asm/arch/chip_drv_common_io.h>
21 #include <asm/arch/regs_adi.h>
22
23 #define KERN_WARNING ""
24 #define WARN(nmu, fmt...) printf(fmt)
25 #define WARN_ON(num)
26 #define pr_err(fmt...) printf(fmt)
27 #define pr_debug(fmt...) printf(fmt)
28
29 //#define DEBUG
30
31
32 #ifdef DEBUG
33 #define GPIO_DBG(fmt...) pr_debug(fmt)
34 #else
35 #define GPIO_DBG(fmt...)
36 #endif
37
38 struct eic_info{
39         u32 base_addr;
40         int die;
41         u8  bit_num;
42 };
43
44 enum eic_die {
45         A_DIE = 0,
46         D_DIE = 1,
47 };
48
49 #define GPIO_INVALID_ID (0xffff)
50 #define INVALID_REG     (~(u32)0)
51
52 #define EIC_DATA 0x00
53 #define EIC_MASK 0x04
54 #define EIC_IEV  0x14
55 #define EIC_IE   0x18
56 #define EIC_RIS  0x1C
57 #define EIC_MIS  0x20
58 #define EIC_IC   0x24
59 #define EIC_TRIG 0x28
60
61 #define EIC0_CTL 0x40
62 #define EIC1_CTL 0x44
63 #define EIC2_CTL 0x48
64 #define EIC3_CTL 0x4C
65 #define EIC4_CTL 0x50
66 #define EIC5_CTL 0x54
67 #define EIC6_CTL 0x58
68 #define EIC7_CTL 0x5C
69 #if defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723)
70 #define EIC8_CTL 0x60
71 #define EIC9_CTL 0x64
72 #define EIC10_CTL 0x68
73 #endif
74
75
76 static void __get_eic_base_info (u32 eic_id, struct eic_info *info)
77 {
78         if (eic_id>=SPRD_ADIE_EIC_START && eic_id<=SPRD_ADIE_EIC_END)
79         {
80                 info->base_addr= SPRD_ANA_EIC_PHYS;
81                 #if defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723)
82                 info->bit_num  = eic_id&0xF;
83                 #else
84                 info->bit_num  = eic_id&0x7;
85                 #endif
86                 info->die          = A_DIE;
87
88         }
89         else if (eic_id>=SPRD_DDIE_EIC_START && eic_id<=SPRD_DDIE_EIC_END)
90         {
91                 info->base_addr= SPRD_EIC_PHYS+0x80;
92                 info->bit_num  = eic_id&0x7;
93                 info->die          = D_DIE;
94         }
95         else
96         {
97                 info->base_addr = INVALID_REG;
98         }
99 }
100
101 static int __eic_get_pin_data (struct eic_info *info)
102 {
103         u32 reg_addr = 0, reg_data;
104
105         if (info->base_addr == INVALID_REG)
106         {
107                 return  -1;
108         }
109
110         reg_addr = info->base_addr + EIC_DATA;
111
112         if (info->die == D_DIE)
113                 reg_data = __raw_readl (reg_addr);
114         else
115                 reg_data = ANA_REG_GET (reg_addr);
116         reg_data &= 1<<info->bit_num;
117
118         return reg_data;
119 }
120
121 static int __eic_get_data_mask (struct eic_info *info)
122 {
123         u32 reg_addr = 0, reg_data;
124
125         if (info->base_addr == INVALID_REG)
126         {
127                 return  -1;
128         }
129
130         reg_addr = info->base_addr + EIC_MASK;
131
132         if (info->die == D_DIE)
133                 reg_data = __raw_readl (reg_addr);
134         else
135                 reg_data = ANA_REG_GET (reg_addr);
136         reg_data &= 1<<info->bit_num;
137
138         return reg_data;
139 }
140
141 /*
142         set data mask, the gpio data register can be access
143  */
144 static void __eic_set_data_mask (struct eic_info *info, int b_on)
145 {
146         u32 reg_addr = 0, reg_data;
147
148         reg_addr = info->base_addr + EIC_MASK;
149
150         if (info->base_addr == INVALID_REG)
151         {
152                 return;
153         }
154
155         if (info->die == D_DIE)
156                 reg_data = __raw_readl (reg_addr);
157         else
158                 reg_data = ANA_REG_GET (reg_addr);
159
160         if (b_on)
161         {
162                 if (!(reg_data&(1<<info->bit_num)))
163                 {
164                         reg_data |= 1<<info->bit_num;
165                         if (info->die == D_DIE)
166                                 __raw_writel (reg_addr, reg_data);
167                         else
168                                 ANA_REG_SET (reg_addr, reg_data);
169                 }
170         }
171         else
172         {
173                 if (reg_data&(1<<info->bit_num))
174                 {
175                         reg_data &= ~(1<<info->bit_num);
176                         if (info->die == D_DIE)
177                                 __raw_writel (reg_addr, reg_data);
178                         else
179                                 ANA_REG_SET (reg_addr, reg_data);
180                 }
181         }
182 }
183
184 int sprd_eic_get(unsigned offset)
185 {
186         unsigned eic_id = offset;
187         struct eic_info gpio_info;
188
189         __get_eic_base_info (eic_id, &gpio_info);
190
191         if (!__eic_get_data_mask (&gpio_info)) {
192                 WARN(1, "GPIO_%d data mask hasn't been opened!\n", eic_id);
193         }
194
195         return __eic_get_pin_data (&gpio_info);
196 }
197
198 int sprd_eic_irq_set_type(unsigned offset, unsigned flow_type)
199 {
200         return 0;
201 }
202
203 int sprd_eic_irq_sts(unsigned offset)
204 {
205         return 0;
206 }
207
208 int sprd_eic_request(unsigned offset)
209 {
210         unsigned eic_id = offset;
211         struct eic_info gpio_info;
212
213         __get_eic_base_info (eic_id, &gpio_info);
214         __eic_set_data_mask (&gpio_info, 1);
215         return 0;
216 }
217
218 #if 0
219 static void sprd_eic_free(unsigned offset)
220 {
221         unsigned eic_id = offset;
222         struct eic_info gpio_info;
223
224         __get_eic_base_info (eic_id, &gpio_info);
225         __eic_set_data_mask (&gpio_info, 0);
226         return;
227 }
228 #endif
229
230 void sprd_eic_init(void)
231 {
232         REG32(REG_AON_APB_APB_EB0) |= BIT_EIC_EB;
233         REG32(REG_AON_APB_APB_RTC_EB) |= BIT_EIC_RTC_EB|BIT_EIC_RTCDV5_EB;
234         ANA_REG_OR(ANA_REG_GLB_ARM_MODULE_EN, BIT_ANA_EIC_EN);
235         ANA_REG_OR(ANA_REG_GLB_RTC_CLK_EN,    BIT_RTC_EIC_EN);
236 }
237
238 int get_volumn_down_status2(void)
239 {
240         int temp_cnt = 600;
241         int status = 0;
242
243         ANA_REG_SET(ADI_EIC_MASK, 0xffff);
244         udelay(3000);
245
246         do {
247                 temp_cnt --;
248
249                 status = ANA_REG_GET(ADI_EIC_DATA);
250                 status = status & (1 << 10);
251         } while(temp_cnt > 0);
252
253         return status;
254 }