Add Broadcom's code for bcm63xx support
[project/bcm63xx/atf.git] / plat / bcm / include / command.h
1 /*
2 <:copyright-BRCM:2013:DUAL/GPL:standard
3
4 Copyright (c) 2013 Broadcom
5 All Rights Reserved
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License, version 2, as published by
9 the Free Software Foundation (the "GPL").
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16
17 A copy of the GPL is available at http://www.broadcom.com/licenses/GPLv2.php, or by
18 writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21 :>
22 */
23
24 #ifndef PMCCOMMAND_H
25 #define PMCCOMMAND_H
26
27 #include "pmc_drv.h"
28
29 typedef union {
30 struct {
31 #ifdef PMC_LITTLE_ENDIAN
32 uint32_t cmdID:8;
33 uint32_t error:8;
34 uint32_t msgID:8;
35 uint32_t srcPort:8;
36 #else
37 uint32_t srcPort:8;
38 uint32_t msgID:8;
39 uint32_t error:8;
40 uint32_t cmdID:8;
41 #endif
42 } Bits;
43 uint32_t Reg32;
44 } TCommandWord0;
45
46 #ifdef PMC_IMPL_3_X
47 typedef union {
48 struct {
49 uint32_t devAddr:16; // [15:00] bus in upper nibble (only values of 0-7 are allowed), device address in lower 12 bits (4096 devices = 0..4095)
50 uint32_t zoneIdx:10; // [25:16] maximum 1023 registers/zone (0..1022)
51 uint32_t island:4; // [27:26] maximum 15 power islands (0..15) (island 15 = ALL islands!
52 uint32_t reserved:2; // [31:28]
53 } Bits;
54 uint32_t Reg32;
55 } TCommandWord1;
56 #else
57 typedef union {
58 struct {
59 #ifdef PMC_LITTLE_ENDIAN
60 uint32_t zoneIdx:10;
61 uint32_t devAddr:10;
62 uint32_t island:4;
63 uint32_t logNum:8;
64 #else
65 uint32_t logNum:8;
66 uint32_t island:4;
67 uint32_t devAddr:10;
68 uint32_t zoneIdx:10;
69 #endif
70 } Bits;
71 uint32_t Reg32;
72 } TCommandWord1;
73 #endif
74
75 // Ping, GetNextLogEntry, GetRMON and Sigma
76 typedef struct {
77 uint32_t unused[2];
78 } TCommandNoParams;
79
80 typedef struct {
81 uint32_t params[2];
82 } TCommandGenericParams;
83
84 // PowerZoneOnOff, SetRunState, SetPowerState
85 typedef struct {
86 #if defined(PMC_LITTLE_ENDIAN) && defined(PMC_CPU_BIG_ENDIAN)
87 uint8_t reserved[3];
88 uint8_t state;
89 #else
90 uint8_t state;
91 uint8_t reserved[3];
92 #endif
93 uint32_t unused;
94 } TCommandStateOnly;
95
96 // PowerDevOnOff
97 typedef struct {
98 #if defined(PMC_LITTLE_ENDIAN) && defined(PMC_CPU_BIG_ENDIAN)
99 uint8_t reserved[2];
100 uint8_t restore;
101 uint8_t state;
102 #else
103 uint8_t state;
104 uint8_t restore;
105 uint8_t reserved[2];
106 #endif
107 uint32_t unused;
108 } TCommandPowerDevice;
109
110 // PowerOffIsland
111 typedef struct {
112 #if defined(PMC_LITTLE_ENDIAN) && defined(PMC_CPU_BIG_ENDIAN)
113 uint8_t reserved[3];
114 uint8_t restore;
115 #else
116 uint8_t restore;
117 uint8_t reserved[3];
118 #endif
119 uint32_t unused;
120 } TCommandPowerIsland;
121
122 // SetClockLowGear, SetClockHighGear
123 typedef struct {
124 #if defined(PMC_LITTLE_ENDIAN) && defined(PMC_CPU_BIG_ENDIAN)
125 uint8_t reserved[3];
126 uint8_t clkN;
127 #else
128 uint8_t clkN;
129 uint8_t reserved[3];
130 #endif
131 uint32_t unused;
132 } TCommandSetClockN;
133
134 // SetClockGear
135 typedef struct {
136 #if defined(PMC_LITTLE_ENDIAN) && defined(PMC_CPU_BIG_ENDIAN)
137 uint8_t reserved[3];
138 uint8_t gear;
139 #else
140 uint8_t gear;
141 uint8_t reserved[3];
142 #endif
143 uint32_t unused;
144 } TCommandSetClockGear;
145
146 typedef struct {
147 #if defined(PMC_LITTLE_ENDIAN) && defined(PMC_CPU_BIG_ENDIAN)
148 uint8_t unused1;
149 uint8_t numTokens;
150 uint8_t tokenSize;
151 uint8_t queueNumber;
152 uint16_t unused2;
153 uint8_t high_watermark;
154 uint8_t low_watermark;
155 #else
156 uint8_t queueNumber;
157 uint8_t tokenSize;
158 uint8_t numTokens;
159 uint8_t unused1;
160 uint8_t low_watermark;
161 uint8_t high_watermark;
162 uint16_t unused2;
163 #endif
164 } TCommandAllocDQM;
165
166 typedef struct {
167 uint32_t phy_src_addr;
168 uint32_t dest_addr; // lower 8 bits **may** be log2 window size
169 } TCommandJumpApp;
170
171 typedef struct {
172 #if defined(PMC_IMPL_3_X) || IS_BCMCHIP(63158)
173 union {
174 uint32_t word2;
175 struct {
176 uint16_t margin_mv_slow;
177 uint16_t maximum_mv;
178 };
179 };
180 union {
181 uint32_t word3;
182 struct {
183 uint16_t margin_mv_fast;
184 uint16_t minimum_mv;
185 };
186 };
187 #else
188 uint32_t margin_mv_slow;
189 uint32_t margin_mv_fast;
190 #endif
191 } TCommandCloseAVS;
192
193 typedef struct {
194 uint32_t word2;
195 uint32_t word3;
196 } TCommandResponse;
197
198 typedef struct {
199 TCommandWord0 word0;
200 TCommandWord1 word1;
201 union {
202 TCommandNoParams cmdNoParams;
203 TCommandGenericParams cmdGenericParams;
204 TCommandStateOnly cmdStateOnlyParam;
205 TCommandPowerDevice cmdPowerDevice;
206 TCommandPowerIsland cmdPowerIsland;
207 TCommandSetClockN cmdSetClockN;
208 TCommandSetClockGear cmdSetClockGear;
209 TCommandAllocDQM cmdAllocDqm;
210 TCommandJumpApp cmdJumpApp;
211 TCommandCloseAVS cmdCloseAVS;
212 TCommandResponse cmdResponse;
213 } u;
214 } TCommand;
215
216 // special values to select all devices/zones
217 #define ALL_DEVICES 0x3ff
218 #define ALL_ZONES 0x3ff
219
220 // used in validate caller to prevent/allow restrictions on island, device and/or zone
221 #define ANY_ISLAND 998
222 #define ANY_DEVICE 1024
223 #define ANY_ZONE 1024
224 #define NO_ISLAND 999
225 #define NO_DEVICE 1025
226 #define NO_ZONE 1025
227
228 // error codes
229 enum {
230 NO_ERROR = 0,
231 INVALID_ISLAND,
232 INVALID_DEVICE,
233 INVALID_ZONE,
234 INVALID_STATE,
235 INVALID_COMMAND,
236 LOG_EMPTY,
237 INVALID_PARAM,
238 BPCM_READ_TIMEOUT,
239 INVALID_BUS,
240 INVALID_QUEUE_NUMBER,
241 QUEUE_NOT_AVAILABLE,
242 INVALID_TOKEN_SIZE,
243 INVALID_WATERMARKS,
244 INSUFFIENT_QSM_MEMORY_AVAILABLE,
245 INVALID_BOOT_COMMAND,
246 BPCM_WRITE_TIMEOUT,
247 CMD_TABLE_FULL,
248 CMD_TABLE_LOCKED,
249 };
250
251 // command codes
252 enum {
253 // low-level commands
254 cmdReserved = 0,
255 cmdGetDevPresence,
256 cmdGetSWStrap,
257 cmdGetHWRev,
258 cmdGetNumZones,
259 cmdPing,
260 cmdGetNextLogEntry,
261 cmdGetRMON,
262 cmdSetClockHighGear,
263 cmdSetClockLowGear,
264 cmdSetClockGear,
265 cmdReadBpcmReg,
266 cmdReadZoneReg,
267 cmdWriteBpcmReg,
268 cmdWriteZoneReg,
269 // general-purpose high-level commands
270 cmdSetRunState,
271 cmdSetPowerState,
272 cmdShutdownAllowed,
273 cmdGetSelect0,
274 cmdGetSelect3,
275 cmdGetAvsDisableState,
276 cmdGetPVT,
277 // specific-purpose high-level commands
278 cmdPowerDevOnOff,
279 cmdPowerZoneOnOff,
280 cmdResetDevice,
281 cmdResetZone,
282 cmdAllocateG2UDQM,
283 cmdQSMAvailable,
284 cmdRevision,
285 cmdRegisterCmdHandler,
286 cmdFindUnusedCommand,
287 cmdLockCmdTable,
288 cmdJumpApp,
289 cmdStall,
290 cmdCloseAVS,
291 cmdReadROs,
292 cmdGetTrackTemp,
293 cmdSetTrackTemp,
294 #ifdef PMC_IMPL_3_X
295 cmdGetIslandStatus,
296 cmdGetTMON,
297 cmdSetTemperatureThresholds,
298 cmdResetTemperatureWarning,
299 #endif
300 };
301
302 extern void ProcessCommand(TCommand * cmd, TCommand * response);
303 extern int SendCommand(int cmdID, int devAddr, int zone, int island, uint32_t word2,
304 uint32_t word3, TCommand *rsp);
305
306
307 #endif // PMCCOMMAND_H