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