1 /* ===================================================================================
2 * Copyright (c) <2009> Synopsys, Inc.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software annotated with this license and associated documentation files
7 * (the "Software"), to deal in the Software without restriction, including without
8 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * =================================================================================== */
23
24 /**\file
25 * This file serves as the wrapper for the platform/OS dependent functions
26 * It is needed to modify these functions accordingly based on the platform and the
27 * OS. Whenever the synopsys GMAC driver ported on to different platform, this file
28 * should be handled at most care.
29 * The corresponding function definitions for non-inline functions are available in
30 * synopGMAC_plat.c file.
31 * \internal
32 * -------------------------------------REVISION HISTORY---------------------------
33 * Synopsys 01/Aug/2007 Created
34 */
35
36
37 #ifndef SYNOP_GMAC_PLAT_H
38 #define SYNOP_GMAC_PLAT_H 1
39
40 #include <stdio.h>
41 #include "NuMicro.h"
42
43 #define TR0(fmt, args...) printf("SynopGMAC: " fmt, ##args)
44
45 //#define DEBUG
46 #ifdef DEBUG
47 #undef TR
48 # define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
49 #else
50 # define TR(fmt, args...) /* not debugging: nothing */
51 #endif
52
53 typedef unsigned char u8; ///< Define 8-bit unsigned data type
54 typedef unsigned short u16; ///< Define 16-bit unsigned data type
55 typedef unsigned int u32; ///< Define 32-bit unsigned data type
56 typedef signed int s32; ///< Define 32-bit signed data type
57 //typedef unsigned long long u64;
58 typedef unsigned int u64;
59
60 #ifndef bool
61 typedef int bool;
62 #endif
63
64 #ifndef false
65 enum synopGMAC_boolean {
66 false = 0,
67 true = 1
68 };
69 #endif
70
71 #define DEFAULT_DELAY_VARIABLE 10
72 #define DEFAULT_LOOP_VARIABLE 10000
73
74 /* There are platform related endian conversions
75 *
76 */
77
78 #define LE32_TO_CPU __le32_to_cpu
79 #define BE32_TO_CPU __be32_to_cpu
80 #define CPU_TO_LE32 __cpu_to_le32
81
82 /* Error Codes */
83 #define ESYNOPGMACNOERR 0
84 #define ESYNOPGMACNOMEM 1
85 #define ESYNOPGMACPHYERR 2
86 #define ESYNOPGMACBUSY 3
87
88
89 /**
90 * These are the wrapper function prototypes for OS/platform related routines
91 */
92
93 extern void plat_delay(uint32_t ticks);
94
95
96 /**
97 * The Low level function to read register contents from Hardware.
98 *
99 * @param[in] pointer to the base of register map
100 * @param[in] Offset from the base
101 * \return Returns the register contents
102 */
synopGMACReadReg(u32 * RegBase,u32 RegOffset)103 static u32 __INLINE synopGMACReadReg(u32 *RegBase, u32 RegOffset)
104 {
105
106 u64 addr = (u64)RegBase + RegOffset;
107 u32 data = inp32((void *)addr);
108 return data;
109
110 }
111
112 /**
113 * The Low level function to write to a register in Hardware.
114 *
115 * @param[in] pointer to the base of register map
116 * @param[in] Offset from the base
117 * @param[in] Data to be written
118 * \return void
119 */
synopGMACWriteReg(u32 * RegBase,u32 RegOffset,u32 RegData)120 static void __INLINE synopGMACWriteReg(u32 *RegBase, u32 RegOffset, u32 RegData)
121 {
122
123 u64 addr = (u64)RegBase + RegOffset;
124 if(RegOffset == 0)
125 plat_delay(1);
126 outp32((void *)addr, RegData);
127 return;
128 }
129
130 /**
131 * The Low level function to set bits of a register in Hardware.
132 *
133 * @param[in] pointer to the base of register map
134 * @param[in] Offset from the base
135 * @param[in] Bit mask to set bits to logical 1
136 * \return void
137 */
synopGMACSetBits(u32 * RegBase,u32 RegOffset,u32 BitPos)138 static void __INLINE synopGMACSetBits(u32 *RegBase, u32 RegOffset, u32 BitPos)
139 {
140 u64 addr = (u64)RegBase + RegOffset;
141 u32 data = inp32((void *)addr);
142 data |= BitPos;
143
144 outp32((void *)addr, data);
145
146 return;
147 }
148
149
150 /**
151 * The Low level function to clear bits of a register in Hardware.
152 *
153 * @param[in] pointer to the base of register map
154 * @param[in] Offset from the base
155 * @param[in] Bit mask to clear bits to logical 0
156 * \return void
157 */
synopGMACClearBits(u32 * RegBase,u32 RegOffset,u32 BitPos)158 static void __INLINE synopGMACClearBits(u32 *RegBase, u32 RegOffset, u32 BitPos)
159 {
160 u64 addr = (u64)RegBase + RegOffset;
161 u32 data = inp32((void *)addr);
162 data &= (~BitPos);
163
164 outp32((void *)addr, data);
165 return;
166 }
167
168 /**
169 * The Low level function to Check the setting of the bits.
170 *
171 * @param[in] pointer to the base of register map
172 * @param[in] Offset from the base
173 * @param[in] Bit mask to set bits to logical 1
174 * \return returns TRUE if set to '1' returns FALSE if set to '0'. Result undefined there are no bit set in the BitPos argument.
175 *
176 */
synopGMACCheckBits(u32 * RegBase,u32 RegOffset,u32 BitPos)177 static bool __INLINE synopGMACCheckBits(u32 *RegBase, u32 RegOffset, u32 BitPos)
178 {
179 u64 addr = (u64)RegBase + RegOffset;
180 u32 data = inp32((void *)addr);
181 data &= BitPos;
182 if(data) return true;
183 else return false;
184
185 }
186
187
188 #endif
189