]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/firmware/ti_sci.h
firmware: ti_sci: Add support for Clock control
[mirror_ubuntu-artful-kernel.git] / drivers / firmware / ti_sci.h
CommitLineData
aa276781
NM
1/*
2 * Texas Instruments System Control Interface (TISCI) Protocol
3 *
4 * Communication protocol with TI SCI hardware
5 * The system works in a message response protocol
6 * See: http://processors.wiki.ti.com/index.php/TISCI for details
7 *
8 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 */
39
40#ifndef __TI_SCI_H
41#define __TI_SCI_H
42
43/* Generic Messages */
44#define TI_SCI_MSG_ENABLE_WDT 0x0000
45#define TI_SCI_MSG_WAKE_RESET 0x0001
46#define TI_SCI_MSG_VERSION 0x0002
47#define TI_SCI_MSG_WAKE_REASON 0x0003
48#define TI_SCI_MSG_GOODBYE 0x0004
49
9e7d756d
NM
50/* Device requests */
51#define TI_SCI_MSG_SET_DEVICE_STATE 0x0200
52#define TI_SCI_MSG_GET_DEVICE_STATE 0x0201
53#define TI_SCI_MSG_SET_DEVICE_RESETS 0x0202
54
9f723220
NM
55/* Clock requests */
56#define TI_SCI_MSG_SET_CLOCK_STATE 0x0100
57#define TI_SCI_MSG_GET_CLOCK_STATE 0x0101
58#define TI_SCI_MSG_SET_CLOCK_PARENT 0x0102
59#define TI_SCI_MSG_GET_CLOCK_PARENT 0x0103
60#define TI_SCI_MSG_GET_NUM_CLOCK_PARENTS 0x0104
61#define TI_SCI_MSG_SET_CLOCK_FREQ 0x010c
62#define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d
63#define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e
64
aa276781
NM
65/**
66 * struct ti_sci_msg_hdr - Generic Message Header for All messages and responses
67 * @type: Type of messages: One of TI_SCI_MSG* values
68 * @host: Host of the message
69 * @seq: Message identifier indicating a transfer sequence
70 * @flags: Flag for the message
71 */
72struct ti_sci_msg_hdr {
73 u16 type;
74 u8 host;
75 u8 seq;
76#define TI_SCI_MSG_FLAG(val) (1 << (val))
77#define TI_SCI_FLAG_REQ_GENERIC_NORESPONSE 0x0
78#define TI_SCI_FLAG_REQ_ACK_ON_RECEIVED TI_SCI_MSG_FLAG(0)
79#define TI_SCI_FLAG_REQ_ACK_ON_PROCESSED TI_SCI_MSG_FLAG(1)
80#define TI_SCI_FLAG_RESP_GENERIC_NACK 0x0
81#define TI_SCI_FLAG_RESP_GENERIC_ACK TI_SCI_MSG_FLAG(1)
82 /* Additional Flags */
83 u32 flags;
84} __packed;
85
86/**
87 * struct ti_sci_msg_resp_version - Response for a message
88 * @hdr: Generic header
89 * @firmware_description: String describing the firmware
90 * @firmware_revision: Firmware revision
91 * @abi_major: Major version of the ABI that firmware supports
92 * @abi_minor: Minor version of the ABI that firmware supports
93 *
94 * In general, ABI version changes follow the rule that minor version increments
95 * are backward compatible. Major revision changes in ABI may not be
96 * backward compatible.
97 *
98 * Response to a generic message with message type TI_SCI_MSG_VERSION
99 */
100struct ti_sci_msg_resp_version {
101 struct ti_sci_msg_hdr hdr;
102 char firmware_description[32];
103 u16 firmware_revision;
104 u8 abi_major;
105 u8 abi_minor;
106} __packed;
107
9e7d756d
NM
108/**
109 * struct ti_sci_msg_req_set_device_state - Set the desired state of the device
110 * @hdr: Generic header
111 * @id: Indicates which device to modify
112 * @reserved: Reserved space in message, must be 0 for backward compatibility
113 * @state: The desired state of the device.
114 *
115 * Certain flags can also be set to alter the device state:
116 * + MSG_FLAG_DEVICE_WAKE_ENABLED - Configure the device to be a wake source.
117 * The meaning of this flag will vary slightly from device to device and from
118 * SoC to SoC but it generally allows the device to wake the SoC out of deep
119 * suspend states.
120 * + MSG_FLAG_DEVICE_RESET_ISO - Enable reset isolation for this device.
121 * + MSG_FLAG_DEVICE_EXCLUSIVE - Claim this device exclusively. When passed
122 * with STATE_RETENTION or STATE_ON, it will claim the device exclusively.
123 * If another host already has this device set to STATE_RETENTION or STATE_ON,
124 * the message will fail. Once successful, other hosts attempting to set
125 * STATE_RETENTION or STATE_ON will fail.
126 *
127 * Request type is TI_SCI_MSG_SET_DEVICE_STATE, responded with a generic
128 * ACK/NACK message.
129 */
130struct ti_sci_msg_req_set_device_state {
131 /* Additional hdr->flags options */
132#define MSG_FLAG_DEVICE_WAKE_ENABLED TI_SCI_MSG_FLAG(8)
133#define MSG_FLAG_DEVICE_RESET_ISO TI_SCI_MSG_FLAG(9)
134#define MSG_FLAG_DEVICE_EXCLUSIVE TI_SCI_MSG_FLAG(10)
135 struct ti_sci_msg_hdr hdr;
136 u32 id;
137 u32 reserved;
138
139#define MSG_DEVICE_SW_STATE_AUTO_OFF 0
140#define MSG_DEVICE_SW_STATE_RETENTION 1
141#define MSG_DEVICE_SW_STATE_ON 2
142 u8 state;
143} __packed;
144
145/**
146 * struct ti_sci_msg_req_get_device_state - Request to get device.
147 * @hdr: Generic header
148 * @id: Device Identifier
149 *
150 * Request type is TI_SCI_MSG_GET_DEVICE_STATE, responded device state
151 * information
152 */
153struct ti_sci_msg_req_get_device_state {
154 struct ti_sci_msg_hdr hdr;
155 u32 id;
156} __packed;
157
158/**
159 * struct ti_sci_msg_resp_get_device_state - Response to get device request.
160 * @hdr: Generic header
161 * @context_loss_count: Indicates how many times the device has lost context. A
162 * driver can use this monotonic counter to determine if the device has
163 * lost context since the last time this message was exchanged.
164 * @resets: Programmed state of the reset lines.
165 * @programmed_state: The state as programmed by set_device.
166 * - Uses the MSG_DEVICE_SW_* macros
167 * @current_state: The actual state of the hardware.
168 *
169 * Response to request TI_SCI_MSG_GET_DEVICE_STATE.
170 */
171struct ti_sci_msg_resp_get_device_state {
172 struct ti_sci_msg_hdr hdr;
173 u32 context_loss_count;
174 u32 resets;
175 u8 programmed_state;
176#define MSG_DEVICE_HW_STATE_OFF 0
177#define MSG_DEVICE_HW_STATE_ON 1
178#define MSG_DEVICE_HW_STATE_TRANS 2
179 u8 current_state;
180} __packed;
181
182/**
183 * struct ti_sci_msg_req_set_device_resets - Set the desired resets
184 * configuration of the device
185 * @hdr: Generic header
186 * @id: Indicates which device to modify
187 * @resets: A bit field of resets for the device. The meaning, behavior,
188 * and usage of the reset flags are device specific. 0 for a bit
189 * indicates releasing the reset represented by that bit while 1
190 * indicates keeping it held.
191 *
192 * Request type is TI_SCI_MSG_SET_DEVICE_RESETS, responded with a generic
193 * ACK/NACK message.
194 */
195struct ti_sci_msg_req_set_device_resets {
196 struct ti_sci_msg_hdr hdr;
197 u32 id;
198 u32 resets;
199} __packed;
200
9f723220
NM
201/**
202 * struct ti_sci_msg_req_set_clock_state - Request to setup a Clock state
203 * @hdr: Generic Header, Certain flags can be set specific to the clocks:
204 * MSG_FLAG_CLOCK_ALLOW_SSC: Allow this clock to be modified
205 * via spread spectrum clocking.
206 * MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE: Allow this clock's
207 * frequency to be changed while it is running so long as it
208 * is within the min/max limits.
209 * MSG_FLAG_CLOCK_INPUT_TERM: Enable input termination, this
210 * is only applicable to clock inputs on the SoC pseudo-device.
211 * @dev_id: Device identifier this request is for
212 * @clk_id: Clock identifier for the device for this request.
213 * Each device has it's own set of clock inputs. This indexes
214 * which clock input to modify.
215 * @request_state: Request the state for the clock to be set to.
216 * MSG_CLOCK_SW_STATE_UNREQ: The IP does not require this clock,
217 * it can be disabled, regardless of the state of the device
218 * MSG_CLOCK_SW_STATE_AUTO: Allow the System Controller to
219 * automatically manage the state of this clock. If the device
220 * is enabled, then the clock is enabled. If the device is set
221 * to off or retention, then the clock is internally set as not
222 * being required by the device.(default)
223 * MSG_CLOCK_SW_STATE_REQ: Configure the clock to be enabled,
224 * regardless of the state of the device.
225 *
226 * Normally, all required clocks are managed by TISCI entity, this is used
227 * only for specific control *IF* required. Auto managed state is
228 * MSG_CLOCK_SW_STATE_AUTO, in other states, TISCI entity assume remote
229 * will explicitly control.
230 *
231 * Request type is TI_SCI_MSG_SET_CLOCK_STATE, response is a generic
232 * ACK or NACK message.
233 */
234struct ti_sci_msg_req_set_clock_state {
235 /* Additional hdr->flags options */
236#define MSG_FLAG_CLOCK_ALLOW_SSC TI_SCI_MSG_FLAG(8)
237#define MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE TI_SCI_MSG_FLAG(9)
238#define MSG_FLAG_CLOCK_INPUT_TERM TI_SCI_MSG_FLAG(10)
239 struct ti_sci_msg_hdr hdr;
240 u32 dev_id;
241 u8 clk_id;
242#define MSG_CLOCK_SW_STATE_UNREQ 0
243#define MSG_CLOCK_SW_STATE_AUTO 1
244#define MSG_CLOCK_SW_STATE_REQ 2
245 u8 request_state;
246} __packed;
247
248/**
249 * struct ti_sci_msg_req_get_clock_state - Request for clock state
250 * @hdr: Generic Header
251 * @dev_id: Device identifier this request is for
252 * @clk_id: Clock identifier for the device for this request.
253 * Each device has it's own set of clock inputs. This indexes
254 * which clock input to get state of.
255 *
256 * Request type is TI_SCI_MSG_GET_CLOCK_STATE, response is state
257 * of the clock
258 */
259struct ti_sci_msg_req_get_clock_state {
260 struct ti_sci_msg_hdr hdr;
261 u32 dev_id;
262 u8 clk_id;
263} __packed;
264
265/**
266 * struct ti_sci_msg_resp_get_clock_state - Response to get clock state
267 * @hdr: Generic Header
268 * @programmed_state: Any programmed state of the clock. This is one of
269 * MSG_CLOCK_SW_STATE* values.
270 * @current_state: Current state of the clock. This is one of:
271 * MSG_CLOCK_HW_STATE_NOT_READY: Clock is not ready
272 * MSG_CLOCK_HW_STATE_READY: Clock is ready
273 *
274 * Response to TI_SCI_MSG_GET_CLOCK_STATE.
275 */
276struct ti_sci_msg_resp_get_clock_state {
277 struct ti_sci_msg_hdr hdr;
278 u8 programmed_state;
279#define MSG_CLOCK_HW_STATE_NOT_READY 0
280#define MSG_CLOCK_HW_STATE_READY 1
281 u8 current_state;
282} __packed;
283
284/**
285 * struct ti_sci_msg_req_set_clock_parent - Set the clock parent
286 * @hdr: Generic Header
287 * @dev_id: Device identifier this request is for
288 * @clk_id: Clock identifier for the device for this request.
289 * Each device has it's own set of clock inputs. This indexes
290 * which clock input to modify.
291 * @parent_id: The new clock parent is selectable by an index via this
292 * parameter.
293 *
294 * Request type is TI_SCI_MSG_SET_CLOCK_PARENT, response is generic
295 * ACK / NACK message.
296 */
297struct ti_sci_msg_req_set_clock_parent {
298 struct ti_sci_msg_hdr hdr;
299 u32 dev_id;
300 u8 clk_id;
301 u8 parent_id;
302} __packed;
303
304/**
305 * struct ti_sci_msg_req_get_clock_parent - Get the clock parent
306 * @hdr: Generic Header
307 * @dev_id: Device identifier this request is for
308 * @clk_id: Clock identifier for the device for this request.
309 * Each device has it's own set of clock inputs. This indexes
310 * which clock input to get the parent for.
311 *
312 * Request type is TI_SCI_MSG_GET_CLOCK_PARENT, response is parent information
313 */
314struct ti_sci_msg_req_get_clock_parent {
315 struct ti_sci_msg_hdr hdr;
316 u32 dev_id;
317 u8 clk_id;
318} __packed;
319
320/**
321 * struct ti_sci_msg_resp_get_clock_parent - Response with clock parent
322 * @hdr: Generic Header
323 * @parent_id: The current clock parent
324 *
325 * Response to TI_SCI_MSG_GET_CLOCK_PARENT.
326 */
327struct ti_sci_msg_resp_get_clock_parent {
328 struct ti_sci_msg_hdr hdr;
329 u8 parent_id;
330} __packed;
331
332/**
333 * struct ti_sci_msg_req_get_clock_num_parents - Request to get clock parents
334 * @hdr: Generic header
335 * @dev_id: Device identifier this request is for
336 * @clk_id: Clock identifier for the device for this request.
337 *
338 * This request provides information about how many clock parent options
339 * are available for a given clock to a device. This is typically used
340 * for input clocks.
341 *
342 * Request type is TI_SCI_MSG_GET_NUM_CLOCK_PARENTS, response is appropriate
343 * message, or NACK in case of inability to satisfy request.
344 */
345struct ti_sci_msg_req_get_clock_num_parents {
346 struct ti_sci_msg_hdr hdr;
347 u32 dev_id;
348 u8 clk_id;
349} __packed;
350
351/**
352 * struct ti_sci_msg_resp_get_clock_num_parents - Response for get clk parents
353 * @hdr: Generic header
354 * @num_parents: Number of clock parents
355 *
356 * Response to TI_SCI_MSG_GET_NUM_CLOCK_PARENTS
357 */
358struct ti_sci_msg_resp_get_clock_num_parents {
359 struct ti_sci_msg_hdr hdr;
360 u8 num_parents;
361} __packed;
362
363/**
364 * struct ti_sci_msg_req_query_clock_freq - Request to query a frequency
365 * @hdr: Generic Header
366 * @dev_id: Device identifier this request is for
367 * @min_freq_hz: The minimum allowable frequency in Hz. This is the minimum
368 * allowable programmed frequency and does not account for clock
369 * tolerances and jitter.
370 * @target_freq_hz: The target clock frequency. A frequency will be found
371 * as close to this target frequency as possible.
372 * @max_freq_hz: The maximum allowable frequency in Hz. This is the maximum
373 * allowable programmed frequency and does not account for clock
374 * tolerances and jitter.
375 * @clk_id: Clock identifier for the device for this request.
376 *
377 * NOTE: Normally clock frequency management is automatically done by TISCI
378 * entity. In case of specific requests, TISCI evaluates capability to achieve
379 * requested frequency within provided range and responds with
380 * result message.
381 *
382 * Request type is TI_SCI_MSG_QUERY_CLOCK_FREQ, response is appropriate message,
383 * or NACK in case of inability to satisfy request.
384 */
385struct ti_sci_msg_req_query_clock_freq {
386 struct ti_sci_msg_hdr hdr;
387 u32 dev_id;
388 u64 min_freq_hz;
389 u64 target_freq_hz;
390 u64 max_freq_hz;
391 u8 clk_id;
392} __packed;
393
394/**
395 * struct ti_sci_msg_resp_query_clock_freq - Response to a clock frequency query
396 * @hdr: Generic Header
397 * @freq_hz: Frequency that is the best match in Hz.
398 *
399 * Response to request type TI_SCI_MSG_QUERY_CLOCK_FREQ. NOTE: if the request
400 * cannot be satisfied, the message will be of type NACK.
401 */
402struct ti_sci_msg_resp_query_clock_freq {
403 struct ti_sci_msg_hdr hdr;
404 u64 freq_hz;
405} __packed;
406
407/**
408 * struct ti_sci_msg_req_set_clock_freq - Request to setup a clock frequency
409 * @hdr: Generic Header
410 * @dev_id: Device identifier this request is for
411 * @min_freq_hz: The minimum allowable frequency in Hz. This is the minimum
412 * allowable programmed frequency and does not account for clock
413 * tolerances and jitter.
414 * @target_freq_hz: The target clock frequency. The clock will be programmed
415 * at a rate as close to this target frequency as possible.
416 * @max_freq_hz: The maximum allowable frequency in Hz. This is the maximum
417 * allowable programmed frequency and does not account for clock
418 * tolerances and jitter.
419 * @clk_id: Clock identifier for the device for this request.
420 *
421 * NOTE: Normally clock frequency management is automatically done by TISCI
422 * entity. In case of specific requests, TISCI evaluates capability to achieve
423 * requested range and responds with success/failure message.
424 *
425 * This sets the desired frequency for a clock within an allowable
426 * range. This message will fail on an enabled clock unless
427 * MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE is set for the clock. Additionally,
428 * if other clocks have their frequency modified due to this message,
429 * they also must have the MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE or be disabled.
430 *
431 * Calling set frequency on a clock input to the SoC pseudo-device will
432 * inform the PMMC of that clock's frequency. Setting a frequency of
433 * zero will indicate the clock is disabled.
434 *
435 * Calling set frequency on clock outputs from the SoC pseudo-device will
436 * function similarly to setting the clock frequency on a device.
437 *
438 * Request type is TI_SCI_MSG_SET_CLOCK_FREQ, response is a generic ACK/NACK
439 * message.
440 */
441struct ti_sci_msg_req_set_clock_freq {
442 struct ti_sci_msg_hdr hdr;
443 u32 dev_id;
444 u64 min_freq_hz;
445 u64 target_freq_hz;
446 u64 max_freq_hz;
447 u8 clk_id;
448} __packed;
449
450/**
451 * struct ti_sci_msg_req_get_clock_freq - Request to get the clock frequency
452 * @hdr: Generic Header
453 * @dev_id: Device identifier this request is for
454 * @clk_id: Clock identifier for the device for this request.
455 *
456 * NOTE: Normally clock frequency management is automatically done by TISCI
457 * entity. In some cases, clock frequencies are configured by host.
458 *
459 * Request type is TI_SCI_MSG_GET_CLOCK_FREQ, responded with clock frequency
460 * that the clock is currently at.
461 */
462struct ti_sci_msg_req_get_clock_freq {
463 struct ti_sci_msg_hdr hdr;
464 u32 dev_id;
465 u8 clk_id;
466} __packed;
467
468/**
469 * struct ti_sci_msg_resp_get_clock_freq - Response of clock frequency request
470 * @hdr: Generic Header
471 * @freq_hz: Frequency that the clock is currently on, in Hz.
472 *
473 * Response to request type TI_SCI_MSG_GET_CLOCK_FREQ.
474 */
475struct ti_sci_msg_resp_get_clock_freq {
476 struct ti_sci_msg_hdr hdr;
477 u64 freq_hz;
478} __packed;
479
aa276781 480#endif /* __TI_SCI_H */