889d4d9e9e97bc3e7a135f96c2c5b51328b40d9a
[15.05/openwrt.git] / target / linux / generic / files / crypto / ocf / kirkwood / mvHal / mv_hal / gpp / mvGpp.c
1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
3
4 This software file (the "File") is owned and distributed by Marvell 
5 International Ltd. and/or its affiliates ("Marvell") under the following
6 alternative licensing terms.  Once you have made an election to distribute the
7 File under one of the following license alternatives, please (i) delete this
8 introductory statement regarding license alternatives, (ii) delete the two
9 license alternatives that you have not elected to use and (iii) preserve the
10 Marvell copyright notice above.
11
12 ********************************************************************************
13 Marvell Commercial License Option
14
15 If you received this File from Marvell and you have entered into a commercial
16 license agreement (a "Commercial License") with Marvell, the File is licensed
17 to you under the terms of the applicable Commercial License.
18
19 ********************************************************************************
20 Marvell GPL License Option
21
22 If you received this File from Marvell, you may opt to use, redistribute and/or 
23 modify this File in accordance with the terms and conditions of the General 
24 Public License Version 2, June 1991 (the "GPL License"), a copy of which is 
25 available along with the File in the license.txt file or by writing to the Free 
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or 
27 on the worldwide web at http://www.gnu.org/licenses/gpl.txt. 
28
29 THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED 
30 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY 
31 DISCLAIMED.  The GPL License provides additional details about this warranty 
32 disclaimer.
33 ********************************************************************************
34 Marvell BSD License Option
35
36 If you received this File from Marvell, you may opt to use, redistribute and/or 
37 modify this File under the following licensing terms. 
38 Redistribution and use in source and binary forms, with or without modification, 
39 are permitted provided that the following conditions are met:
40
41     *   Redistributions of source code must retain the above copyright notice,
42             this list of conditions and the following disclaimer. 
43
44     *   Redistributions in binary form must reproduce the above copyright
45         notice, this list of conditions and the following disclaimer in the
46         documentation and/or other materials provided with the distribution. 
47
48     *   Neither the name of Marvell nor the names of its contributors may be 
49         used to endorse or promote products derived from this software without 
50         specific prior written permission. 
51     
52 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
53 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
54 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
55 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
56 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
57 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
58 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
59 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
60 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
63 *******************************************************************************/
64
65 #include "gpp/mvGpp.h"
66 #include "ctrlEnv/mvCtrlEnvLib.h"
67 /* defines  */       
68 #ifdef MV_DEBUG         
69         #define DB(x)   x
70 #else                
71         #define DB(x)    
72 #endif               
73
74 static MV_VOID gppRegSet(MV_U32 group, MV_U32 regOffs,MV_U32 mask,MV_U32 value);
75
76 /*******************************************************************************
77 * mvGppTypeSet - Enable a GPP (OUT) pin
78 *
79 * DESCRIPTION:
80 *
81 * INPUT:
82 *       group - GPP group number
83 *       mask  - 32bit mask value. Each set bit in the mask means that the type
84 *               of corresponding GPP will be set. Other GPPs are ignored.
85 *       value - 32bit value that describes GPP type per pin.
86 *
87 * OUTPUT:
88 *       None.
89 *
90 * EXAMPLE:
91 *       Set GPP8 to input and GPP15 to output.
92 *       mvGppTypeSet(0, (GPP8 | GPP15), 
93 *                    ((MV_GPP_IN & GPP8) | (MV_GPP_OUT & GPP15)) );
94 *
95 * RETURN:
96 *       None.
97 *
98 *******************************************************************************/
99 MV_STATUS mvGppTypeSet(MV_U32 group, MV_U32 mask, MV_U32 value)
100 {
101         if (group >= MV_GPP_MAX_GROUP)
102         {
103                 DB(mvOsPrintf("mvGppTypeSet: ERR. invalid group number \n"));
104                 return MV_BAD_PARAM;
105         }
106
107         gppRegSet(group, GPP_DATA_OUT_EN_REG(group), mask, value);
108
109     /* Workaround for Erratum FE-MISC-70*/
110     if(mvCtrlRevGet()==MV_88F6XXX_A0_REV && (group == 1))
111     {
112         mask &= 0x2;
113         gppRegSet(0, GPP_DATA_OUT_EN_REG(0), mask, value);
114     } /*End of WA*/
115
116         return MV_OK;
117
118 }
119
120 /*******************************************************************************
121 * mvGppBlinkEn - Set a GPP (IN) Pin list to blink every ~100ms
122 *
123 * DESCRIPTION:
124 *
125 * INPUT:
126 *       group - GPP group number
127 *       mask  - 32bit mask value. Each set bit in the mask means that the type
128 *               of corresponding GPP will be set. Other GPPs are ignored.
129 *       value - 32bit value that describes GPP blink per pin.
130 *
131 * OUTPUT:
132 *       None.
133 *
134 * EXAMPLE:
135 *       Set GPP8 to be static and GPP15 to be blinking.
136 *       mvGppBlinkEn(0, (GPP8 | GPP15), 
137 *                    ((MV_GPP_OUT_STATIC & GPP8) | (MV_GPP_OUT_BLINK & GPP15)) );
138 *
139 * RETURN:
140 *       None.
141 *
142 *******************************************************************************/
143 MV_STATUS mvGppBlinkEn(MV_U32 group, MV_U32 mask, MV_U32 value)
144 {
145         if (group >= MV_GPP_MAX_GROUP)
146         {
147                 DB(mvOsPrintf("mvGppBlinkEn: ERR. invalid group number \n"));
148                 return MV_BAD_PARAM;
149         }
150
151         gppRegSet(group, GPP_BLINK_EN_REG(group), mask, value);
152
153         return MV_OK;
154
155 }
156 /*******************************************************************************
157 * mvGppPolaritySet - Set a GPP (IN) Pin list Polarity mode
158 *
159 * DESCRIPTION:
160 *
161 * INPUT:
162 *       group - GPP group number
163 *       mask  - 32bit mask value. Each set bit in the mask means that the type
164 *               of corresponding GPP will be set. Other GPPs are ignored.
165 *       value - 32bit value that describes GPP polarity per pin.
166 *
167 * OUTPUT:
168 *       None.
169 *
170 * EXAMPLE:
171 *       Set GPP8 to the actual pin value and GPP15 to be inverted.
172 *       mvGppPolaritySet(0, (GPP8 | GPP15), 
173 *                    ((MV_GPP_IN_ORIGIN & GPP8) | (MV_GPP_IN_INVERT & GPP15)) );
174 *
175 * RETURN:
176 *       None.
177 *
178 *******************************************************************************/
179 MV_STATUS mvGppPolaritySet(MV_U32 group, MV_U32 mask, MV_U32 value)
180 {
181         if (group >= MV_GPP_MAX_GROUP)
182         {
183                 DB(mvOsPrintf("mvGppPolaritySet: ERR. invalid group number \n"));
184                 return MV_BAD_PARAM;
185         }
186
187         gppRegSet(group, GPP_DATA_IN_POL_REG(group), mask, value);
188
189         return MV_OK;
190
191 }
192
193 /*******************************************************************************
194 * mvGppPolarityGet - Get a value of relevant bits from GPP Polarity register.
195 *
196 * DESCRIPTION:
197 *
198 * INPUT:
199 *       group - GPP group number
200 *       mask  - 32bit mask value. Each set bit in the mask means that the 
201 *               returned value is valid for it.
202 *
203 * OUTPUT:
204 *       None.
205 *
206 * EXAMPLE:
207 *       Get GPP8 and GPP15 value.
208 *       mvGppPolarityGet(0, (GPP8 | GPP15));
209 *
210 * RETURN:
211 *       32bit value that describes GPP polatity mode per pin.
212 *
213 *******************************************************************************/
214 MV_U32  mvGppPolarityGet(MV_U32 group, MV_U32 mask)
215 {
216     MV_U32  regVal;
217
218         if (group >= MV_GPP_MAX_GROUP)
219         {
220                 DB(mvOsPrintf("mvGppActiveSet: Error invalid group number \n"));
221                 return MV_ERROR;
222         }
223     regVal = MV_REG_READ(GPP_DATA_IN_POL_REG(group));
224     
225     return (regVal & mask);
226 }
227
228 /*******************************************************************************
229 * mvGppValueGet - Get a GPP Pin list value.
230 *
231 * DESCRIPTION:
232 *       This function get GPP value.
233 *
234 * INPUT:
235 *       group - GPP group number
236 *       mask  - 32bit mask value. Each set bit in the mask means that the 
237 *               returned value is valid for it.
238 *
239 * OUTPUT:
240 *       None.
241 *
242 * EXAMPLE:
243 *       Get GPP8 and GPP15 value.
244 *       mvGppValueGet(0, (GPP8 | GPP15));
245 *
246 * RETURN:
247 *       32bit value that describes GPP activity mode per pin.
248 *
249 *******************************************************************************/
250 MV_U32 mvGppValueGet(MV_U32 group, MV_U32 mask)
251 {
252         MV_U32 gppData;
253
254         gppData = MV_REG_READ(GPP_DATA_IN_REG(group));
255
256         gppData &= mask;
257
258         return gppData;
259
260 }
261
262 /*******************************************************************************
263 * mvGppValueSet - Set a GPP Pin list value.
264 *
265 * DESCRIPTION:
266 *       This function set value for given GPP pin list.
267 *
268 * INPUT:
269 *       group - GPP group number
270 *       mask  - 32bit mask value. Each set bit in the mask means that the 
271 *               value of corresponding GPP will be set accordingly. Other GPP 
272 *               are not affected.
273 *       value - 32bit value that describes GPP value per pin.
274 *
275 * OUTPUT:
276 *       None.
277 *
278 * EXAMPLE:
279 *       Set GPP8 value of '0' and GPP15 value of '1'.
280 *       mvGppActiveSet(0, (GPP8 | GPP15), ((0 & GPP8) | (GPP15)) );
281 *
282 * RETURN:
283 *       None.
284 *
285 *******************************************************************************/
286 MV_STATUS mvGppValueSet (MV_U32 group, MV_U32 mask, MV_U32 value)
287 {
288         MV_U32 outEnable, tmp;
289         MV_U32 i;
290
291         if (group >= MV_GPP_MAX_GROUP)
292         {
293                 DB(mvOsPrintf("mvGppValueSet: Error invalid group number \n"));
294                 return MV_BAD_PARAM;
295         }
296
297         /* verify that the gpp pin is configured as output              */
298         /* Note that in the register out enabled -> bit = '0'.  */
299         outEnable = ~MV_REG_READ(GPP_DATA_OUT_EN_REG(group));
300
301     /* Workaround for Erratum FE-MISC-70*/
302     if(mvCtrlRevGet()==MV_88F6XXX_A0_REV && (group == 1))
303     {
304         tmp = ~MV_REG_READ(GPP_DATA_OUT_EN_REG(0));
305         outEnable &= 0xfffffffd;
306         outEnable |= (tmp & 0x2);
307     } /*End of WA*/
308
309         for (i = 0 ; i < 32 ;i++)
310         {
311                 if (((mask & (1 << i)) & (outEnable & (1 << i))) != (mask & (1 << i)))
312                 {
313                         mvOsPrintf("mvGppValueSet: Err. An attempt to set output "\
314                                            "value to GPP %d in input mode.\n", i);
315                         return MV_ERROR;
316                 }
317         }
318
319         gppRegSet(group, GPP_DATA_OUT_REG(group), mask, value);
320
321         return MV_OK;
322
323 }
324 /*******************************************************************************
325 * gppRegSet - Set a specific GPP pin on a specific GPP register
326 *
327 * DESCRIPTION:
328 *       This function set a specific GPP pin on a specific GPP register
329 *
330 * INPUT:
331 *               regOffs - GPP Register offset 
332 *       group - GPP group number
333 *       mask  - 32bit mask value. Each set bit in the mask means that the 
334 *               value of corresponding GPP will be set accordingly. Other GPP 
335 *               are not affected.
336 *       value - 32bit value that describes GPP value per pin.
337 *
338 * OUTPUT:
339 *       None.
340 *
341 * EXAMPLE:
342 *       Set GPP8 value of '0' and GPP15 value of '1'.
343 *       mvGppActiveSet(0, (GPP8 | GPP15), ((0 & GPP8) | (1 & GPP15)) );
344 *
345 * RETURN:
346 *       None.
347 *
348 *******************************************************************************/
349 static MV_VOID gppRegSet (MV_U32 group, MV_U32 regOffs,MV_U32 mask,MV_U32 value)
350 {
351         MV_U32 gppData;
352
353         gppData = MV_REG_READ(regOffs);
354
355         gppData &= ~mask;
356
357         gppData |= (value & mask);
358
359         MV_REG_WRITE(regOffs, gppData);
360 }
361
362