1 // SPDX-License-Identifier: GPL-2.0
3 * Texas Instruments System Control Interface Protocol Driver
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
9 #define pr_fmt(fmt) "%s: " fmt, __func__
11 #include <linux/bitmap.h>
12 #include <linux/debugfs.h>
13 #include <linux/export.h>
15 #include <linux/kernel.h>
16 #include <linux/mailbox_client.h>
17 #include <linux/module.h>
18 #include <linux/of_device.h>
19 #include <linux/semaphore.h>
20 #include <linux/slab.h>
21 #include <linux/soc/ti/ti-msgmgr.h>
22 #include <linux/soc/ti/ti_sci_protocol.h>
23 #include <linux/reboot.h>
27 /* List of all TI SCI devices active in system */
28 static LIST_HEAD(ti_sci_list
);
29 /* Protection for the entire list */
30 static DEFINE_MUTEX(ti_sci_list_mutex
);
33 * struct ti_sci_xfer - Structure representing a message flow
34 * @tx_message: Transmit message
35 * @rx_len: Receive message length
36 * @xfer_buf: Preallocated buffer to store receive message
37 * Since we work with request-ACK protocol, we can
38 * reuse the same buffer for the rx path as we
39 * use for the tx path.
40 * @done: completion event
43 struct ti_msgmgr_message tx_message
;
46 struct completion done
;
50 * struct ti_sci_xfers_info - Structure to manage transfer information
51 * @sem_xfer_count: Counting Semaphore for managing max simultaneous
53 * @xfer_block: Preallocated Message array
54 * @xfer_alloc_table: Bitmap table for allocated messages.
55 * Index of this bitmap table is also used for message
56 * sequence identifier.
57 * @xfer_lock: Protection for message allocation
59 struct ti_sci_xfers_info
{
60 struct semaphore sem_xfer_count
;
61 struct ti_sci_xfer
*xfer_block
;
62 unsigned long *xfer_alloc_table
;
63 /* protect transfer allocation */
68 * struct ti_sci_desc - Description of SoC integration
69 * @default_host_id: Host identifier representing the compute entity
70 * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
71 * @max_msgs: Maximum number of messages that can be pending
72 * simultaneously in the system
73 * @max_msg_size: Maximum size of data per message that can be handled.
77 int max_rx_timeout_ms
;
83 * struct ti_sci_info - Structure representing a TI SCI instance
84 * @dev: Device pointer
85 * @desc: SoC description for this instance
86 * @nb: Reboot Notifier block
87 * @d: Debugfs file entry
88 * @debug_region: Memory region where the debug message are available
89 * @debug_region_size: Debug region size
90 * @debug_buffer: Buffer allocated to copy debug messages.
91 * @handle: Instance of TI SCI handle to send to clients.
93 * @chan_tx: Transmit mailbox channel
94 * @chan_rx: Receive mailbox channel
95 * @minfo: Message info
98 * @users: Number of users of this instance
102 struct notifier_block nb
;
103 const struct ti_sci_desc
*desc
;
105 void __iomem
*debug_region
;
107 size_t debug_region_size
;
108 struct ti_sci_handle handle
;
109 struct mbox_client cl
;
110 struct mbox_chan
*chan_tx
;
111 struct mbox_chan
*chan_rx
;
112 struct ti_sci_xfers_info minfo
;
113 struct list_head node
;
115 /* protected by ti_sci_list_mutex */
120 #define cl_to_ti_sci_info(c) container_of(c, struct ti_sci_info, cl)
121 #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle)
122 #define reboot_to_ti_sci_info(n) container_of(n, struct ti_sci_info, nb)
124 #ifdef CONFIG_DEBUG_FS
127 * ti_sci_debug_show() - Helper to dump the debug log
128 * @s: sequence file pointer
133 static int ti_sci_debug_show(struct seq_file
*s
, void *unused
)
135 struct ti_sci_info
*info
= s
->private;
137 memcpy_fromio(info
->debug_buffer
, info
->debug_region
,
138 info
->debug_region_size
);
140 * We don't trust firmware to leave NULL terminated last byte (hence
141 * we have allocated 1 extra 0 byte). Since we cannot guarantee any
142 * specific data format for debug messages, We just present the data
143 * in the buffer as is - we expect the messages to be self explanatory.
145 seq_puts(s
, info
->debug_buffer
);
149 /* Provide the log file operations interface*/
150 DEFINE_SHOW_ATTRIBUTE(ti_sci_debug
);
153 * ti_sci_debugfs_create() - Create log debug file
154 * @pdev: platform device pointer
155 * @info: Pointer to SCI entity information
157 * Return: 0 if all went fine, else corresponding error.
159 static int ti_sci_debugfs_create(struct platform_device
*pdev
,
160 struct ti_sci_info
*info
)
162 struct device
*dev
= &pdev
->dev
;
163 struct resource
*res
;
164 char debug_name
[50] = "ti_sci_debug@";
166 /* Debug region is optional */
167 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
169 info
->debug_region
= devm_ioremap_resource(dev
, res
);
170 if (IS_ERR(info
->debug_region
))
172 info
->debug_region_size
= resource_size(res
);
174 info
->debug_buffer
= devm_kcalloc(dev
, info
->debug_region_size
+ 1,
175 sizeof(char), GFP_KERNEL
);
176 if (!info
->debug_buffer
)
178 /* Setup NULL termination */
179 info
->debug_buffer
[info
->debug_region_size
] = 0;
181 info
->d
= debugfs_create_file(strncat(debug_name
, dev_name(dev
),
183 sizeof("ti_sci_debug@")),
184 0444, NULL
, info
, &ti_sci_debug_fops
);
186 return PTR_ERR(info
->d
);
188 dev_dbg(dev
, "Debug region => %p, size = %zu bytes, resource: %pr\n",
189 info
->debug_region
, info
->debug_region_size
, res
);
194 * ti_sci_debugfs_destroy() - clean up log debug file
195 * @pdev: platform device pointer
196 * @info: Pointer to SCI entity information
198 static void ti_sci_debugfs_destroy(struct platform_device
*pdev
,
199 struct ti_sci_info
*info
)
201 if (IS_ERR(info
->debug_region
))
204 debugfs_remove(info
->d
);
206 #else /* CONFIG_DEBUG_FS */
207 static inline int ti_sci_debugfs_create(struct platform_device
*dev
,
208 struct ti_sci_info
*info
)
213 static inline void ti_sci_debugfs_destroy(struct platform_device
*dev
,
214 struct ti_sci_info
*info
)
217 #endif /* CONFIG_DEBUG_FS */
220 * ti_sci_dump_header_dbg() - Helper to dump a message header.
221 * @dev: Device pointer corresponding to the SCI entity
222 * @hdr: pointer to header.
224 static inline void ti_sci_dump_header_dbg(struct device
*dev
,
225 struct ti_sci_msg_hdr
*hdr
)
227 dev_dbg(dev
, "MSGHDR:type=0x%04x host=0x%02x seq=0x%02x flags=0x%08x\n",
228 hdr
->type
, hdr
->host
, hdr
->seq
, hdr
->flags
);
232 * ti_sci_rx_callback() - mailbox client callback for receive messages
233 * @cl: client pointer
234 * @m: mailbox message
236 * Processes one received message to appropriate transfer information and
237 * signals completion of the transfer.
239 * NOTE: This function will be invoked in IRQ context, hence should be
240 * as optimal as possible.
242 static void ti_sci_rx_callback(struct mbox_client
*cl
, void *m
)
244 struct ti_sci_info
*info
= cl_to_ti_sci_info(cl
);
245 struct device
*dev
= info
->dev
;
246 struct ti_sci_xfers_info
*minfo
= &info
->minfo
;
247 struct ti_msgmgr_message
*mbox_msg
= m
;
248 struct ti_sci_msg_hdr
*hdr
= (struct ti_sci_msg_hdr
*)mbox_msg
->buf
;
249 struct ti_sci_xfer
*xfer
;
255 * Are we even expecting this?
256 * NOTE: barriers were implicit in locks used for modifying the bitmap
258 if (!test_bit(xfer_id
, minfo
->xfer_alloc_table
)) {
259 dev_err(dev
, "Message for %d is not expected!\n", xfer_id
);
263 xfer
= &minfo
->xfer_block
[xfer_id
];
265 /* Is the message of valid length? */
266 if (mbox_msg
->len
> info
->desc
->max_msg_size
) {
267 dev_err(dev
, "Unable to handle %zu xfer(max %d)\n",
268 mbox_msg
->len
, info
->desc
->max_msg_size
);
269 ti_sci_dump_header_dbg(dev
, hdr
);
272 if (mbox_msg
->len
< xfer
->rx_len
) {
273 dev_err(dev
, "Recv xfer %zu < expected %d length\n",
274 mbox_msg
->len
, xfer
->rx_len
);
275 ti_sci_dump_header_dbg(dev
, hdr
);
279 ti_sci_dump_header_dbg(dev
, hdr
);
280 /* Take a copy to the rx buffer.. */
281 memcpy(xfer
->xfer_buf
, mbox_msg
->buf
, xfer
->rx_len
);
282 complete(&xfer
->done
);
286 * ti_sci_get_one_xfer() - Allocate one message
287 * @info: Pointer to SCI entity information
288 * @msg_type: Message type
289 * @msg_flags: Flag to set for the message
290 * @tx_message_size: transmit message size
291 * @rx_message_size: receive message size
293 * Helper function which is used by various command functions that are
294 * exposed to clients of this driver for allocating a message traffic event.
296 * This function can sleep depending on pending requests already in the system
297 * for the SCI entity. Further, this also holds a spinlock to maintain integrity
298 * of internal data structures.
300 * Return: 0 if all went fine, else corresponding error.
302 static struct ti_sci_xfer
*ti_sci_get_one_xfer(struct ti_sci_info
*info
,
303 u16 msg_type
, u32 msg_flags
,
304 size_t tx_message_size
,
305 size_t rx_message_size
)
307 struct ti_sci_xfers_info
*minfo
= &info
->minfo
;
308 struct ti_sci_xfer
*xfer
;
309 struct ti_sci_msg_hdr
*hdr
;
311 unsigned long bit_pos
;
316 /* Ensure we have sane transfer sizes */
317 if (rx_message_size
> info
->desc
->max_msg_size
||
318 tx_message_size
> info
->desc
->max_msg_size
||
319 rx_message_size
< sizeof(*hdr
) || tx_message_size
< sizeof(*hdr
))
320 return ERR_PTR(-ERANGE
);
323 * Ensure we have only controlled number of pending messages.
324 * Ideally, we might just have to wait a single message, be
325 * conservative and wait 5 times that..
327 timeout
= msecs_to_jiffies(info
->desc
->max_rx_timeout_ms
) * 5;
328 ret
= down_timeout(&minfo
->sem_xfer_count
, timeout
);
332 /* Keep the locked section as small as possible */
333 spin_lock_irqsave(&minfo
->xfer_lock
, flags
);
334 bit_pos
= find_first_zero_bit(minfo
->xfer_alloc_table
,
335 info
->desc
->max_msgs
);
336 set_bit(bit_pos
, minfo
->xfer_alloc_table
);
337 spin_unlock_irqrestore(&minfo
->xfer_lock
, flags
);
340 * We already ensured in probe that we can have max messages that can
341 * fit in hdr.seq - NOTE: this improves access latencies
342 * to predictable O(1) access, BUT, it opens us to risk if
343 * remote misbehaves with corrupted message sequence responses.
344 * If that happens, we are going to be messed up anyways..
346 xfer_id
= (u8
)bit_pos
;
348 xfer
= &minfo
->xfer_block
[xfer_id
];
350 hdr
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
351 xfer
->tx_message
.len
= tx_message_size
;
352 xfer
->rx_len
= (u8
)rx_message_size
;
354 reinit_completion(&xfer
->done
);
357 hdr
->type
= msg_type
;
358 hdr
->host
= info
->host_id
;
359 hdr
->flags
= msg_flags
;
365 * ti_sci_put_one_xfer() - Release a message
366 * @minfo: transfer info pointer
367 * @xfer: message that was reserved by ti_sci_get_one_xfer
369 * This holds a spinlock to maintain integrity of internal data structures.
371 static void ti_sci_put_one_xfer(struct ti_sci_xfers_info
*minfo
,
372 struct ti_sci_xfer
*xfer
)
375 struct ti_sci_msg_hdr
*hdr
;
378 hdr
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
382 * Keep the locked section as small as possible
383 * NOTE: we might escape with smp_mb and no lock here..
384 * but just be conservative and symmetric.
386 spin_lock_irqsave(&minfo
->xfer_lock
, flags
);
387 clear_bit(xfer_id
, minfo
->xfer_alloc_table
);
388 spin_unlock_irqrestore(&minfo
->xfer_lock
, flags
);
390 /* Increment the count for the next user to get through */
391 up(&minfo
->sem_xfer_count
);
395 * ti_sci_do_xfer() - Do one transfer
396 * @info: Pointer to SCI entity information
397 * @xfer: Transfer to initiate and wait for response
399 * Return: -ETIMEDOUT in case of no response, if transmit error,
400 * return corresponding error, else if all goes well,
403 static inline int ti_sci_do_xfer(struct ti_sci_info
*info
,
404 struct ti_sci_xfer
*xfer
)
408 struct device
*dev
= info
->dev
;
410 ret
= mbox_send_message(info
->chan_tx
, &xfer
->tx_message
);
416 /* And we wait for the response. */
417 timeout
= msecs_to_jiffies(info
->desc
->max_rx_timeout_ms
);
418 if (!wait_for_completion_timeout(&xfer
->done
, timeout
)) {
419 dev_err(dev
, "Mbox timedout in resp(caller: %pS)\n",
424 * NOTE: we might prefer not to need the mailbox ticker to manage the
425 * transfer queueing since the protocol layer queues things by itself.
426 * Unfortunately, we have to kick the mailbox framework after we have
427 * received our message.
429 mbox_client_txdone(info
->chan_tx
, ret
);
435 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
436 * @info: Pointer to SCI entity information
438 * Updates the SCI information in the internal data structure.
440 * Return: 0 if all went fine, else return appropriate error.
442 static int ti_sci_cmd_get_revision(struct ti_sci_info
*info
)
444 struct device
*dev
= info
->dev
;
445 struct ti_sci_handle
*handle
= &info
->handle
;
446 struct ti_sci_version_info
*ver
= &handle
->version
;
447 struct ti_sci_msg_resp_version
*rev_info
;
448 struct ti_sci_xfer
*xfer
;
451 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_VERSION
,
452 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
453 sizeof(struct ti_sci_msg_hdr
),
457 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
461 rev_info
= (struct ti_sci_msg_resp_version
*)xfer
->xfer_buf
;
463 ret
= ti_sci_do_xfer(info
, xfer
);
465 dev_err(dev
, "Mbox send fail %d\n", ret
);
469 ver
->abi_major
= rev_info
->abi_major
;
470 ver
->abi_minor
= rev_info
->abi_minor
;
471 ver
->firmware_revision
= rev_info
->firmware_revision
;
472 strncpy(ver
->firmware_description
, rev_info
->firmware_description
,
473 sizeof(ver
->firmware_description
));
476 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
481 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
482 * @r: pointer to response buffer
484 * Return: true if the response was an ACK, else returns false.
486 static inline bool ti_sci_is_response_ack(void *r
)
488 struct ti_sci_msg_hdr
*hdr
= r
;
490 return hdr
->flags
& TI_SCI_FLAG_RESP_GENERIC_ACK
? true : false;
494 * ti_sci_set_device_state() - Set device state helper
495 * @handle: pointer to TI SCI handle
496 * @id: Device identifier
497 * @flags: flags to setup for the device
498 * @state: State to move the device to
500 * Return: 0 if all went well, else returns appropriate error value.
502 static int ti_sci_set_device_state(const struct ti_sci_handle
*handle
,
503 u32 id
, u32 flags
, u8 state
)
505 struct ti_sci_info
*info
;
506 struct ti_sci_msg_req_set_device_state
*req
;
507 struct ti_sci_msg_hdr
*resp
;
508 struct ti_sci_xfer
*xfer
;
513 return PTR_ERR(handle
);
517 info
= handle_to_ti_sci_info(handle
);
520 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_DEVICE_STATE
,
521 flags
| TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
522 sizeof(*req
), sizeof(*resp
));
525 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
528 req
= (struct ti_sci_msg_req_set_device_state
*)xfer
->xfer_buf
;
532 ret
= ti_sci_do_xfer(info
, xfer
);
534 dev_err(dev
, "Mbox send fail %d\n", ret
);
538 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
540 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
543 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
549 * ti_sci_get_device_state() - Get device state helper
550 * @handle: Handle to the device
551 * @id: Device Identifier
552 * @clcnt: Pointer to Context Loss Count
553 * @resets: pointer to resets
554 * @p_state: pointer to p_state
555 * @c_state: pointer to c_state
557 * Return: 0 if all went fine, else return appropriate error.
559 static int ti_sci_get_device_state(const struct ti_sci_handle
*handle
,
560 u32 id
, u32
*clcnt
, u32
*resets
,
561 u8
*p_state
, u8
*c_state
)
563 struct ti_sci_info
*info
;
564 struct ti_sci_msg_req_get_device_state
*req
;
565 struct ti_sci_msg_resp_get_device_state
*resp
;
566 struct ti_sci_xfer
*xfer
;
571 return PTR_ERR(handle
);
575 if (!clcnt
&& !resets
&& !p_state
&& !c_state
)
578 info
= handle_to_ti_sci_info(handle
);
581 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_DEVICE_STATE
,
582 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
583 sizeof(*req
), sizeof(*resp
));
586 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
589 req
= (struct ti_sci_msg_req_get_device_state
*)xfer
->xfer_buf
;
592 ret
= ti_sci_do_xfer(info
, xfer
);
594 dev_err(dev
, "Mbox send fail %d\n", ret
);
598 resp
= (struct ti_sci_msg_resp_get_device_state
*)xfer
->xfer_buf
;
599 if (!ti_sci_is_response_ack(resp
)) {
605 *clcnt
= resp
->context_loss_count
;
607 *resets
= resp
->resets
;
609 *p_state
= resp
->programmed_state
;
611 *c_state
= resp
->current_state
;
613 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
619 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
620 * that can be shared with other hosts.
621 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
622 * @id: Device Identifier
624 * Request for the device - NOTE: the client MUST maintain integrity of
625 * usage count by balancing get_device with put_device. No refcounting is
626 * managed by driver for that purpose.
628 * Return: 0 if all went fine, else return appropriate error.
630 static int ti_sci_cmd_get_device(const struct ti_sci_handle
*handle
, u32 id
)
632 return ti_sci_set_device_state(handle
, id
, 0,
633 MSG_DEVICE_SW_STATE_ON
);
637 * ti_sci_cmd_get_device_exclusive() - command to request for device managed by
638 * TISCI that is exclusively owned by the
640 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
641 * @id: Device Identifier
643 * Request for the device - NOTE: the client MUST maintain integrity of
644 * usage count by balancing get_device with put_device. No refcounting is
645 * managed by driver for that purpose.
647 * Return: 0 if all went fine, else return appropriate error.
649 static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle
*handle
,
652 return ti_sci_set_device_state(handle
, id
,
653 MSG_FLAG_DEVICE_EXCLUSIVE
,
654 MSG_DEVICE_SW_STATE_ON
);
658 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
659 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
660 * @id: Device Identifier
662 * Request for the device - NOTE: the client MUST maintain integrity of
663 * usage count by balancing get_device with put_device. No refcounting is
664 * managed by driver for that purpose.
666 * Return: 0 if all went fine, else return appropriate error.
668 static int ti_sci_cmd_idle_device(const struct ti_sci_handle
*handle
, u32 id
)
670 return ti_sci_set_device_state(handle
, id
, 0,
671 MSG_DEVICE_SW_STATE_RETENTION
);
675 * ti_sci_cmd_idle_device_exclusive() - Command to idle a device managed by
676 * TISCI that is exclusively owned by
678 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
679 * @id: Device Identifier
681 * Request for the device - NOTE: the client MUST maintain integrity of
682 * usage count by balancing get_device with put_device. No refcounting is
683 * managed by driver for that purpose.
685 * Return: 0 if all went fine, else return appropriate error.
687 static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle
*handle
,
690 return ti_sci_set_device_state(handle
, id
,
691 MSG_FLAG_DEVICE_EXCLUSIVE
,
692 MSG_DEVICE_SW_STATE_RETENTION
);
696 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
697 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
698 * @id: Device Identifier
700 * Request for the device - NOTE: the client MUST maintain integrity of
701 * usage count by balancing get_device with put_device. No refcounting is
702 * managed by driver for that purpose.
704 * Return: 0 if all went fine, else return appropriate error.
706 static int ti_sci_cmd_put_device(const struct ti_sci_handle
*handle
, u32 id
)
708 return ti_sci_set_device_state(handle
, id
,
709 0, MSG_DEVICE_SW_STATE_AUTO_OFF
);
713 * ti_sci_cmd_dev_is_valid() - Is the device valid
714 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
715 * @id: Device Identifier
717 * Return: 0 if all went fine and the device ID is valid, else return
720 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle
*handle
, u32 id
)
724 /* check the device state which will also tell us if the ID is valid */
725 return ti_sci_get_device_state(handle
, id
, NULL
, NULL
, NULL
, &unused
);
729 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
730 * @handle: Pointer to TISCI handle
731 * @id: Device Identifier
732 * @count: Pointer to Context Loss counter to populate
734 * Return: 0 if all went fine, else return appropriate error.
736 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle
*handle
, u32 id
,
739 return ti_sci_get_device_state(handle
, id
, count
, NULL
, NULL
, NULL
);
743 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
744 * @handle: Pointer to TISCI handle
745 * @id: Device Identifier
746 * @r_state: true if requested to be idle
748 * Return: 0 if all went fine, else return appropriate error.
750 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle
*handle
, u32 id
,
759 ret
= ti_sci_get_device_state(handle
, id
, NULL
, NULL
, &state
, NULL
);
763 *r_state
= (state
== MSG_DEVICE_SW_STATE_RETENTION
);
769 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
770 * @handle: Pointer to TISCI handle
771 * @id: Device Identifier
772 * @r_state: true if requested to be stopped
773 * @curr_state: true if currently stopped.
775 * Return: 0 if all went fine, else return appropriate error.
777 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle
*handle
, u32 id
,
778 bool *r_state
, bool *curr_state
)
783 if (!r_state
&& !curr_state
)
787 ti_sci_get_device_state(handle
, id
, NULL
, NULL
, &p_state
, &c_state
);
792 *r_state
= (p_state
== MSG_DEVICE_SW_STATE_AUTO_OFF
);
794 *curr_state
= (c_state
== MSG_DEVICE_HW_STATE_OFF
);
800 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
801 * @handle: Pointer to TISCI handle
802 * @id: Device Identifier
803 * @r_state: true if requested to be ON
804 * @curr_state: true if currently ON and active
806 * Return: 0 if all went fine, else return appropriate error.
808 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle
*handle
, u32 id
,
809 bool *r_state
, bool *curr_state
)
814 if (!r_state
&& !curr_state
)
818 ti_sci_get_device_state(handle
, id
, NULL
, NULL
, &p_state
, &c_state
);
823 *r_state
= (p_state
== MSG_DEVICE_SW_STATE_ON
);
825 *curr_state
= (c_state
== MSG_DEVICE_HW_STATE_ON
);
831 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
832 * @handle: Pointer to TISCI handle
833 * @id: Device Identifier
834 * @curr_state: true if currently transitioning.
836 * Return: 0 if all went fine, else return appropriate error.
838 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle
*handle
, u32 id
,
847 ret
= ti_sci_get_device_state(handle
, id
, NULL
, NULL
, NULL
, &state
);
851 *curr_state
= (state
== MSG_DEVICE_HW_STATE_TRANS
);
857 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
859 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
860 * @id: Device Identifier
861 * @reset_state: Device specific reset bit field
863 * Return: 0 if all went fine, else return appropriate error.
865 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle
*handle
,
866 u32 id
, u32 reset_state
)
868 struct ti_sci_info
*info
;
869 struct ti_sci_msg_req_set_device_resets
*req
;
870 struct ti_sci_msg_hdr
*resp
;
871 struct ti_sci_xfer
*xfer
;
876 return PTR_ERR(handle
);
880 info
= handle_to_ti_sci_info(handle
);
883 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_DEVICE_RESETS
,
884 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
885 sizeof(*req
), sizeof(*resp
));
888 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
891 req
= (struct ti_sci_msg_req_set_device_resets
*)xfer
->xfer_buf
;
893 req
->resets
= reset_state
;
895 ret
= ti_sci_do_xfer(info
, xfer
);
897 dev_err(dev
, "Mbox send fail %d\n", ret
);
901 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
903 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
906 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
912 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
914 * @handle: Pointer to TISCI handle
915 * @id: Device Identifier
916 * @reset_state: Pointer to reset state to populate
918 * Return: 0 if all went fine, else return appropriate error.
920 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle
*handle
,
921 u32 id
, u32
*reset_state
)
923 return ti_sci_get_device_state(handle
, id
, NULL
, reset_state
, NULL
,
928 * ti_sci_set_clock_state() - Set clock state helper
929 * @handle: pointer to TI SCI handle
930 * @dev_id: Device identifier this request is for
931 * @clk_id: Clock identifier for the device for this request.
932 * Each device has it's own set of clock inputs. This indexes
933 * which clock input to modify.
934 * @flags: Header flags as needed
935 * @state: State to request for the clock.
937 * Return: 0 if all went well, else returns appropriate error value.
939 static int ti_sci_set_clock_state(const struct ti_sci_handle
*handle
,
940 u32 dev_id
, u32 clk_id
,
943 struct ti_sci_info
*info
;
944 struct ti_sci_msg_req_set_clock_state
*req
;
945 struct ti_sci_msg_hdr
*resp
;
946 struct ti_sci_xfer
*xfer
;
951 return PTR_ERR(handle
);
955 info
= handle_to_ti_sci_info(handle
);
958 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CLOCK_STATE
,
959 flags
| TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
960 sizeof(*req
), sizeof(*resp
));
963 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
966 req
= (struct ti_sci_msg_req_set_clock_state
*)xfer
->xfer_buf
;
967 req
->dev_id
= dev_id
;
969 req
->clk_id
= clk_id
;
972 req
->clk_id_32
= clk_id
;
974 req
->request_state
= state
;
976 ret
= ti_sci_do_xfer(info
, xfer
);
978 dev_err(dev
, "Mbox send fail %d\n", ret
);
982 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
984 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
987 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
993 * ti_sci_cmd_get_clock_state() - Get clock state helper
994 * @handle: pointer to TI SCI handle
995 * @dev_id: Device identifier this request is for
996 * @clk_id: Clock identifier for the device for this request.
997 * Each device has it's own set of clock inputs. This indexes
998 * which clock input to modify.
999 * @programmed_state: State requested for clock to move to
1000 * @current_state: State that the clock is currently in
1002 * Return: 0 if all went well, else returns appropriate error value.
1004 static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle
*handle
,
1005 u32 dev_id
, u32 clk_id
,
1006 u8
*programmed_state
, u8
*current_state
)
1008 struct ti_sci_info
*info
;
1009 struct ti_sci_msg_req_get_clock_state
*req
;
1010 struct ti_sci_msg_resp_get_clock_state
*resp
;
1011 struct ti_sci_xfer
*xfer
;
1016 return PTR_ERR(handle
);
1020 if (!programmed_state
&& !current_state
)
1023 info
= handle_to_ti_sci_info(handle
);
1026 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_CLOCK_STATE
,
1027 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1028 sizeof(*req
), sizeof(*resp
));
1030 ret
= PTR_ERR(xfer
);
1031 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1034 req
= (struct ti_sci_msg_req_get_clock_state
*)xfer
->xfer_buf
;
1035 req
->dev_id
= dev_id
;
1037 req
->clk_id
= clk_id
;
1040 req
->clk_id_32
= clk_id
;
1043 ret
= ti_sci_do_xfer(info
, xfer
);
1045 dev_err(dev
, "Mbox send fail %d\n", ret
);
1049 resp
= (struct ti_sci_msg_resp_get_clock_state
*)xfer
->xfer_buf
;
1051 if (!ti_sci_is_response_ack(resp
)) {
1056 if (programmed_state
)
1057 *programmed_state
= resp
->programmed_state
;
1059 *current_state
= resp
->current_state
;
1062 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1068 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
1069 * @handle: pointer to TI SCI handle
1070 * @dev_id: Device identifier this request is for
1071 * @clk_id: Clock identifier for the device for this request.
1072 * Each device has it's own set of clock inputs. This indexes
1073 * which clock input to modify.
1074 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
1075 * @can_change_freq: 'true' if frequency change is desired, else 'false'
1076 * @enable_input_term: 'true' if input termination is desired, else 'false'
1078 * Return: 0 if all went well, else returns appropriate error value.
1080 static int ti_sci_cmd_get_clock(const struct ti_sci_handle
*handle
, u32 dev_id
,
1081 u32 clk_id
, bool needs_ssc
,
1082 bool can_change_freq
, bool enable_input_term
)
1086 flags
|= needs_ssc
? MSG_FLAG_CLOCK_ALLOW_SSC
: 0;
1087 flags
|= can_change_freq
? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE
: 0;
1088 flags
|= enable_input_term
? MSG_FLAG_CLOCK_INPUT_TERM
: 0;
1090 return ti_sci_set_clock_state(handle
, dev_id
, clk_id
, flags
,
1091 MSG_CLOCK_SW_STATE_REQ
);
1095 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
1096 * @handle: pointer to TI SCI handle
1097 * @dev_id: Device identifier this request is for
1098 * @clk_id: Clock identifier for the device for this request.
1099 * Each device has it's own set of clock inputs. This indexes
1100 * which clock input to modify.
1102 * NOTE: This clock must have been requested by get_clock previously.
1104 * Return: 0 if all went well, else returns appropriate error value.
1106 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle
*handle
,
1107 u32 dev_id
, u32 clk_id
)
1109 return ti_sci_set_clock_state(handle
, dev_id
, clk_id
,
1110 MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE
,
1111 MSG_CLOCK_SW_STATE_UNREQ
);
1115 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
1116 * @handle: pointer to TI SCI handle
1117 * @dev_id: Device identifier this request is for
1118 * @clk_id: Clock identifier for the device for this request.
1119 * Each device has it's own set of clock inputs. This indexes
1120 * which clock input to modify.
1122 * NOTE: This clock must have been requested by get_clock previously.
1124 * Return: 0 if all went well, else returns appropriate error value.
1126 static int ti_sci_cmd_put_clock(const struct ti_sci_handle
*handle
,
1127 u32 dev_id
, u32 clk_id
)
1129 return ti_sci_set_clock_state(handle
, dev_id
, clk_id
,
1130 MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE
,
1131 MSG_CLOCK_SW_STATE_AUTO
);
1135 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
1136 * @handle: pointer to TI SCI handle
1137 * @dev_id: Device identifier this request is for
1138 * @clk_id: Clock identifier for the device for this request.
1139 * Each device has it's own set of clock inputs. This indexes
1140 * which clock input to modify.
1141 * @req_state: state indicating if the clock is auto managed
1143 * Return: 0 if all went well, else returns appropriate error value.
1145 static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle
*handle
,
1146 u32 dev_id
, u32 clk_id
, bool *req_state
)
1154 ret
= ti_sci_cmd_get_clock_state(handle
, dev_id
, clk_id
, &state
, NULL
);
1158 *req_state
= (state
== MSG_CLOCK_SW_STATE_AUTO
);
1163 * ti_sci_cmd_clk_is_on() - Is the clock ON
1164 * @handle: pointer to TI SCI handle
1165 * @dev_id: Device identifier this request is for
1166 * @clk_id: Clock identifier for the device for this request.
1167 * Each device has it's own set of clock inputs. This indexes
1168 * which clock input to modify.
1169 * @req_state: state indicating if the clock is managed by us and enabled
1170 * @curr_state: state indicating if the clock is ready for operation
1172 * Return: 0 if all went well, else returns appropriate error value.
1174 static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle
*handle
, u32 dev_id
,
1175 u32 clk_id
, bool *req_state
, bool *curr_state
)
1177 u8 c_state
= 0, r_state
= 0;
1180 if (!req_state
&& !curr_state
)
1183 ret
= ti_sci_cmd_get_clock_state(handle
, dev_id
, clk_id
,
1184 &r_state
, &c_state
);
1189 *req_state
= (r_state
== MSG_CLOCK_SW_STATE_REQ
);
1191 *curr_state
= (c_state
== MSG_CLOCK_HW_STATE_READY
);
1196 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1197 * @handle: pointer to TI SCI handle
1198 * @dev_id: Device identifier this request is for
1199 * @clk_id: Clock identifier for the device for this request.
1200 * Each device has it's own set of clock inputs. This indexes
1201 * which clock input to modify.
1202 * @req_state: state indicating if the clock is managed by us and disabled
1203 * @curr_state: state indicating if the clock is NOT ready for operation
1205 * Return: 0 if all went well, else returns appropriate error value.
1207 static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle
*handle
, u32 dev_id
,
1208 u32 clk_id
, bool *req_state
, bool *curr_state
)
1210 u8 c_state
= 0, r_state
= 0;
1213 if (!req_state
&& !curr_state
)
1216 ret
= ti_sci_cmd_get_clock_state(handle
, dev_id
, clk_id
,
1217 &r_state
, &c_state
);
1222 *req_state
= (r_state
== MSG_CLOCK_SW_STATE_UNREQ
);
1224 *curr_state
= (c_state
== MSG_CLOCK_HW_STATE_NOT_READY
);
1229 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1230 * @handle: pointer to TI SCI handle
1231 * @dev_id: Device identifier this request is for
1232 * @clk_id: Clock identifier for the device for this request.
1233 * Each device has it's own set of clock inputs. This indexes
1234 * which clock input to modify.
1235 * @parent_id: Parent clock identifier to set
1237 * Return: 0 if all went well, else returns appropriate error value.
1239 static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle
*handle
,
1240 u32 dev_id
, u32 clk_id
, u32 parent_id
)
1242 struct ti_sci_info
*info
;
1243 struct ti_sci_msg_req_set_clock_parent
*req
;
1244 struct ti_sci_msg_hdr
*resp
;
1245 struct ti_sci_xfer
*xfer
;
1250 return PTR_ERR(handle
);
1254 info
= handle_to_ti_sci_info(handle
);
1257 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CLOCK_PARENT
,
1258 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1259 sizeof(*req
), sizeof(*resp
));
1261 ret
= PTR_ERR(xfer
);
1262 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1265 req
= (struct ti_sci_msg_req_set_clock_parent
*)xfer
->xfer_buf
;
1266 req
->dev_id
= dev_id
;
1268 req
->clk_id
= clk_id
;
1271 req
->clk_id_32
= clk_id
;
1273 if (parent_id
< 255) {
1274 req
->parent_id
= parent_id
;
1276 req
->parent_id
= 255;
1277 req
->parent_id_32
= parent_id
;
1280 ret
= ti_sci_do_xfer(info
, xfer
);
1282 dev_err(dev
, "Mbox send fail %d\n", ret
);
1286 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1288 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1291 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1297 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1298 * @handle: pointer to TI SCI handle
1299 * @dev_id: Device identifier this request is for
1300 * @clk_id: Clock identifier for the device for this request.
1301 * Each device has it's own set of clock inputs. This indexes
1302 * which clock input to modify.
1303 * @parent_id: Current clock parent
1305 * Return: 0 if all went well, else returns appropriate error value.
1307 static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle
*handle
,
1308 u32 dev_id
, u32 clk_id
, u32
*parent_id
)
1310 struct ti_sci_info
*info
;
1311 struct ti_sci_msg_req_get_clock_parent
*req
;
1312 struct ti_sci_msg_resp_get_clock_parent
*resp
;
1313 struct ti_sci_xfer
*xfer
;
1318 return PTR_ERR(handle
);
1319 if (!handle
|| !parent_id
)
1322 info
= handle_to_ti_sci_info(handle
);
1325 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_CLOCK_PARENT
,
1326 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1327 sizeof(*req
), sizeof(*resp
));
1329 ret
= PTR_ERR(xfer
);
1330 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1333 req
= (struct ti_sci_msg_req_get_clock_parent
*)xfer
->xfer_buf
;
1334 req
->dev_id
= dev_id
;
1336 req
->clk_id
= clk_id
;
1339 req
->clk_id_32
= clk_id
;
1342 ret
= ti_sci_do_xfer(info
, xfer
);
1344 dev_err(dev
, "Mbox send fail %d\n", ret
);
1348 resp
= (struct ti_sci_msg_resp_get_clock_parent
*)xfer
->xfer_buf
;
1350 if (!ti_sci_is_response_ack(resp
)) {
1353 if (resp
->parent_id
< 255)
1354 *parent_id
= resp
->parent_id
;
1356 *parent_id
= resp
->parent_id_32
;
1360 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1366 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1367 * @handle: pointer to TI SCI handle
1368 * @dev_id: Device identifier this request is for
1369 * @clk_id: Clock identifier for the device for this request.
1370 * Each device has it's own set of clock inputs. This indexes
1371 * which clock input to modify.
1372 * @num_parents: Returns he number of parents to the current clock.
1374 * Return: 0 if all went well, else returns appropriate error value.
1376 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle
*handle
,
1377 u32 dev_id
, u32 clk_id
,
1380 struct ti_sci_info
*info
;
1381 struct ti_sci_msg_req_get_clock_num_parents
*req
;
1382 struct ti_sci_msg_resp_get_clock_num_parents
*resp
;
1383 struct ti_sci_xfer
*xfer
;
1388 return PTR_ERR(handle
);
1389 if (!handle
|| !num_parents
)
1392 info
= handle_to_ti_sci_info(handle
);
1395 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS
,
1396 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1397 sizeof(*req
), sizeof(*resp
));
1399 ret
= PTR_ERR(xfer
);
1400 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1403 req
= (struct ti_sci_msg_req_get_clock_num_parents
*)xfer
->xfer_buf
;
1404 req
->dev_id
= dev_id
;
1406 req
->clk_id
= clk_id
;
1409 req
->clk_id_32
= clk_id
;
1412 ret
= ti_sci_do_xfer(info
, xfer
);
1414 dev_err(dev
, "Mbox send fail %d\n", ret
);
1418 resp
= (struct ti_sci_msg_resp_get_clock_num_parents
*)xfer
->xfer_buf
;
1420 if (!ti_sci_is_response_ack(resp
)) {
1423 if (resp
->num_parents
< 255)
1424 *num_parents
= resp
->num_parents
;
1426 *num_parents
= resp
->num_parents_32
;
1430 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1436 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1437 * @handle: pointer to TI SCI handle
1438 * @dev_id: Device identifier this request is for
1439 * @clk_id: Clock identifier for the device for this request.
1440 * Each device has it's own set of clock inputs. This indexes
1441 * which clock input to modify.
1442 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1443 * allowable programmed frequency and does not account for clock
1444 * tolerances and jitter.
1445 * @target_freq: The target clock frequency in Hz. A frequency will be
1446 * processed as close to this target frequency as possible.
1447 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1448 * allowable programmed frequency and does not account for clock
1449 * tolerances and jitter.
1450 * @match_freq: Frequency match in Hz response.
1452 * Return: 0 if all went well, else returns appropriate error value.
1454 static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle
*handle
,
1455 u32 dev_id
, u32 clk_id
, u64 min_freq
,
1456 u64 target_freq
, u64 max_freq
,
1459 struct ti_sci_info
*info
;
1460 struct ti_sci_msg_req_query_clock_freq
*req
;
1461 struct ti_sci_msg_resp_query_clock_freq
*resp
;
1462 struct ti_sci_xfer
*xfer
;
1467 return PTR_ERR(handle
);
1468 if (!handle
|| !match_freq
)
1471 info
= handle_to_ti_sci_info(handle
);
1474 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_QUERY_CLOCK_FREQ
,
1475 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1476 sizeof(*req
), sizeof(*resp
));
1478 ret
= PTR_ERR(xfer
);
1479 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1482 req
= (struct ti_sci_msg_req_query_clock_freq
*)xfer
->xfer_buf
;
1483 req
->dev_id
= dev_id
;
1485 req
->clk_id
= clk_id
;
1488 req
->clk_id_32
= clk_id
;
1490 req
->min_freq_hz
= min_freq
;
1491 req
->target_freq_hz
= target_freq
;
1492 req
->max_freq_hz
= max_freq
;
1494 ret
= ti_sci_do_xfer(info
, xfer
);
1496 dev_err(dev
, "Mbox send fail %d\n", ret
);
1500 resp
= (struct ti_sci_msg_resp_query_clock_freq
*)xfer
->xfer_buf
;
1502 if (!ti_sci_is_response_ack(resp
))
1505 *match_freq
= resp
->freq_hz
;
1508 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1514 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1515 * @handle: pointer to TI SCI handle
1516 * @dev_id: Device identifier this request is for
1517 * @clk_id: Clock identifier for the device for this request.
1518 * Each device has it's own set of clock inputs. This indexes
1519 * which clock input to modify.
1520 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1521 * allowable programmed frequency and does not account for clock
1522 * tolerances and jitter.
1523 * @target_freq: The target clock frequency in Hz. A frequency will be
1524 * processed as close to this target frequency as possible.
1525 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1526 * allowable programmed frequency and does not account for clock
1527 * tolerances and jitter.
1529 * Return: 0 if all went well, else returns appropriate error value.
1531 static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle
*handle
,
1532 u32 dev_id
, u32 clk_id
, u64 min_freq
,
1533 u64 target_freq
, u64 max_freq
)
1535 struct ti_sci_info
*info
;
1536 struct ti_sci_msg_req_set_clock_freq
*req
;
1537 struct ti_sci_msg_hdr
*resp
;
1538 struct ti_sci_xfer
*xfer
;
1543 return PTR_ERR(handle
);
1547 info
= handle_to_ti_sci_info(handle
);
1550 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CLOCK_FREQ
,
1551 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1552 sizeof(*req
), sizeof(*resp
));
1554 ret
= PTR_ERR(xfer
);
1555 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1558 req
= (struct ti_sci_msg_req_set_clock_freq
*)xfer
->xfer_buf
;
1559 req
->dev_id
= dev_id
;
1561 req
->clk_id
= clk_id
;
1564 req
->clk_id_32
= clk_id
;
1566 req
->min_freq_hz
= min_freq
;
1567 req
->target_freq_hz
= target_freq
;
1568 req
->max_freq_hz
= max_freq
;
1570 ret
= ti_sci_do_xfer(info
, xfer
);
1572 dev_err(dev
, "Mbox send fail %d\n", ret
);
1576 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1578 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1581 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1587 * ti_sci_cmd_clk_get_freq() - Get current frequency
1588 * @handle: pointer to TI SCI handle
1589 * @dev_id: Device identifier this request is for
1590 * @clk_id: Clock identifier for the device for this request.
1591 * Each device has it's own set of clock inputs. This indexes
1592 * which clock input to modify.
1593 * @freq: Currently frequency in Hz
1595 * Return: 0 if all went well, else returns appropriate error value.
1597 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle
*handle
,
1598 u32 dev_id
, u32 clk_id
, u64
*freq
)
1600 struct ti_sci_info
*info
;
1601 struct ti_sci_msg_req_get_clock_freq
*req
;
1602 struct ti_sci_msg_resp_get_clock_freq
*resp
;
1603 struct ti_sci_xfer
*xfer
;
1608 return PTR_ERR(handle
);
1609 if (!handle
|| !freq
)
1612 info
= handle_to_ti_sci_info(handle
);
1615 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_CLOCK_FREQ
,
1616 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1617 sizeof(*req
), sizeof(*resp
));
1619 ret
= PTR_ERR(xfer
);
1620 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1623 req
= (struct ti_sci_msg_req_get_clock_freq
*)xfer
->xfer_buf
;
1624 req
->dev_id
= dev_id
;
1626 req
->clk_id
= clk_id
;
1629 req
->clk_id_32
= clk_id
;
1632 ret
= ti_sci_do_xfer(info
, xfer
);
1634 dev_err(dev
, "Mbox send fail %d\n", ret
);
1638 resp
= (struct ti_sci_msg_resp_get_clock_freq
*)xfer
->xfer_buf
;
1640 if (!ti_sci_is_response_ack(resp
))
1643 *freq
= resp
->freq_hz
;
1646 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1651 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle
*handle
)
1653 struct ti_sci_info
*info
;
1654 struct ti_sci_msg_req_reboot
*req
;
1655 struct ti_sci_msg_hdr
*resp
;
1656 struct ti_sci_xfer
*xfer
;
1661 return PTR_ERR(handle
);
1665 info
= handle_to_ti_sci_info(handle
);
1668 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SYS_RESET
,
1669 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1670 sizeof(*req
), sizeof(*resp
));
1672 ret
= PTR_ERR(xfer
);
1673 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1676 req
= (struct ti_sci_msg_req_reboot
*)xfer
->xfer_buf
;
1678 ret
= ti_sci_do_xfer(info
, xfer
);
1680 dev_err(dev
, "Mbox send fail %d\n", ret
);
1684 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1686 if (!ti_sci_is_response_ack(resp
))
1692 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1698 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1699 * to a host. Resource is uniquely identified by
1701 * @handle: Pointer to TISCI handle.
1702 * @dev_id: TISCI device ID.
1703 * @subtype: Resource assignment subtype that is being requested
1704 * from the given device.
1705 * @s_host: Host processor ID to which the resources are allocated
1706 * @range_start: Start index of the resource range
1707 * @range_num: Number of resources in the range
1709 * Return: 0 if all went fine, else return appropriate error.
1711 static int ti_sci_get_resource_range(const struct ti_sci_handle
*handle
,
1712 u32 dev_id
, u8 subtype
, u8 s_host
,
1713 u16
*range_start
, u16
*range_num
)
1715 struct ti_sci_msg_resp_get_resource_range
*resp
;
1716 struct ti_sci_msg_req_get_resource_range
*req
;
1717 struct ti_sci_xfer
*xfer
;
1718 struct ti_sci_info
*info
;
1723 return PTR_ERR(handle
);
1727 info
= handle_to_ti_sci_info(handle
);
1730 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_RESOURCE_RANGE
,
1731 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1732 sizeof(*req
), sizeof(*resp
));
1734 ret
= PTR_ERR(xfer
);
1735 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1739 req
= (struct ti_sci_msg_req_get_resource_range
*)xfer
->xfer_buf
;
1740 req
->secondary_host
= s_host
;
1741 req
->type
= dev_id
& MSG_RM_RESOURCE_TYPE_MASK
;
1742 req
->subtype
= subtype
& MSG_RM_RESOURCE_SUBTYPE_MASK
;
1744 ret
= ti_sci_do_xfer(info
, xfer
);
1746 dev_err(dev
, "Mbox send fail %d\n", ret
);
1750 resp
= (struct ti_sci_msg_resp_get_resource_range
*)xfer
->xfer_buf
;
1752 if (!ti_sci_is_response_ack(resp
)) {
1754 } else if (!resp
->range_start
&& !resp
->range_num
) {
1757 *range_start
= resp
->range_start
;
1758 *range_num
= resp
->range_num
;
1762 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1768 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1769 * that is same as ti sci interface host.
1770 * @handle: Pointer to TISCI handle.
1771 * @dev_id: TISCI device ID.
1772 * @subtype: Resource assignment subtype that is being requested
1773 * from the given device.
1774 * @range_start: Start index of the resource range
1775 * @range_num: Number of resources in the range
1777 * Return: 0 if all went fine, else return appropriate error.
1779 static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle
*handle
,
1780 u32 dev_id
, u8 subtype
,
1781 u16
*range_start
, u16
*range_num
)
1783 return ti_sci_get_resource_range(handle
, dev_id
, subtype
,
1784 TI_SCI_IRQ_SECONDARY_HOST_INVALID
,
1785 range_start
, range_num
);
1789 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1790 * assigned to a specified host.
1791 * @handle: Pointer to TISCI handle.
1792 * @dev_id: TISCI device ID.
1793 * @subtype: Resource assignment subtype that is being requested
1794 * from the given device.
1795 * @s_host: Host processor ID to which the resources are allocated
1796 * @range_start: Start index of the resource range
1797 * @range_num: Number of resources in the range
1799 * Return: 0 if all went fine, else return appropriate error.
1802 int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle
*handle
,
1803 u32 dev_id
, u8 subtype
, u8 s_host
,
1804 u16
*range_start
, u16
*range_num
)
1806 return ti_sci_get_resource_range(handle
, dev_id
, subtype
, s_host
,
1807 range_start
, range_num
);
1811 * ti_sci_manage_irq() - Helper api to configure/release the irq route between
1812 * the requested source and destination
1813 * @handle: Pointer to TISCI handle.
1814 * @valid_params: Bit fields defining the validity of certain params
1815 * @src_id: Device ID of the IRQ source
1816 * @src_index: IRQ source index within the source device
1817 * @dst_id: Device ID of the IRQ destination
1818 * @dst_host_irq: IRQ number of the destination device
1819 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1820 * @vint: Virtual interrupt to be used within the IA
1821 * @global_event: Global event number to be used for the requesting event
1822 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1823 * @s_host: Secondary host ID to which the irq/event is being
1825 * @type: Request type irq set or release.
1827 * Return: 0 if all went fine, else return appropriate error.
1829 static int ti_sci_manage_irq(const struct ti_sci_handle
*handle
,
1830 u32 valid_params
, u16 src_id
, u16 src_index
,
1831 u16 dst_id
, u16 dst_host_irq
, u16 ia_id
, u16 vint
,
1832 u16 global_event
, u8 vint_status_bit
, u8 s_host
,
1835 struct ti_sci_msg_req_manage_irq
*req
;
1836 struct ti_sci_msg_hdr
*resp
;
1837 struct ti_sci_xfer
*xfer
;
1838 struct ti_sci_info
*info
;
1843 return PTR_ERR(handle
);
1847 info
= handle_to_ti_sci_info(handle
);
1850 xfer
= ti_sci_get_one_xfer(info
, type
, TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1851 sizeof(*req
), sizeof(*resp
));
1853 ret
= PTR_ERR(xfer
);
1854 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1857 req
= (struct ti_sci_msg_req_manage_irq
*)xfer
->xfer_buf
;
1858 req
->valid_params
= valid_params
;
1859 req
->src_id
= src_id
;
1860 req
->src_index
= src_index
;
1861 req
->dst_id
= dst_id
;
1862 req
->dst_host_irq
= dst_host_irq
;
1865 req
->global_event
= global_event
;
1866 req
->vint_status_bit
= vint_status_bit
;
1867 req
->secondary_host
= s_host
;
1869 ret
= ti_sci_do_xfer(info
, xfer
);
1871 dev_err(dev
, "Mbox send fail %d\n", ret
);
1875 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1877 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1880 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1886 * ti_sci_set_irq() - Helper api to configure the irq route between the
1887 * requested source and destination
1888 * @handle: Pointer to TISCI handle.
1889 * @valid_params: Bit fields defining the validity of certain params
1890 * @src_id: Device ID of the IRQ source
1891 * @src_index: IRQ source index within the source device
1892 * @dst_id: Device ID of the IRQ destination
1893 * @dst_host_irq: IRQ number of the destination device
1894 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1895 * @vint: Virtual interrupt to be used within the IA
1896 * @global_event: Global event number to be used for the requesting event
1897 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1898 * @s_host: Secondary host ID to which the irq/event is being
1901 * Return: 0 if all went fine, else return appropriate error.
1903 static int ti_sci_set_irq(const struct ti_sci_handle
*handle
, u32 valid_params
,
1904 u16 src_id
, u16 src_index
, u16 dst_id
,
1905 u16 dst_host_irq
, u16 ia_id
, u16 vint
,
1906 u16 global_event
, u8 vint_status_bit
, u8 s_host
)
1908 pr_debug("%s: IRQ set with valid_params = 0x%x from src = %d, index = %d, to dst = %d, irq = %d,via ia_id = %d, vint = %d, global event = %d,status_bit = %d\n",
1909 __func__
, valid_params
, src_id
, src_index
,
1910 dst_id
, dst_host_irq
, ia_id
, vint
, global_event
,
1913 return ti_sci_manage_irq(handle
, valid_params
, src_id
, src_index
,
1914 dst_id
, dst_host_irq
, ia_id
, vint
,
1915 global_event
, vint_status_bit
, s_host
,
1916 TI_SCI_MSG_SET_IRQ
);
1920 * ti_sci_free_irq() - Helper api to free the irq route between the
1921 * requested source and destination
1922 * @handle: Pointer to TISCI handle.
1923 * @valid_params: Bit fields defining the validity of certain params
1924 * @src_id: Device ID of the IRQ source
1925 * @src_index: IRQ source index within the source device
1926 * @dst_id: Device ID of the IRQ destination
1927 * @dst_host_irq: IRQ number of the destination device
1928 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1929 * @vint: Virtual interrupt to be used within the IA
1930 * @global_event: Global event number to be used for the requesting event
1931 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1932 * @s_host: Secondary host ID to which the irq/event is being
1935 * Return: 0 if all went fine, else return appropriate error.
1937 static int ti_sci_free_irq(const struct ti_sci_handle
*handle
, u32 valid_params
,
1938 u16 src_id
, u16 src_index
, u16 dst_id
,
1939 u16 dst_host_irq
, u16 ia_id
, u16 vint
,
1940 u16 global_event
, u8 vint_status_bit
, u8 s_host
)
1942 pr_debug("%s: IRQ release with valid_params = 0x%x from src = %d, index = %d, to dst = %d, irq = %d,via ia_id = %d, vint = %d, global event = %d,status_bit = %d\n",
1943 __func__
, valid_params
, src_id
, src_index
,
1944 dst_id
, dst_host_irq
, ia_id
, vint
, global_event
,
1947 return ti_sci_manage_irq(handle
, valid_params
, src_id
, src_index
,
1948 dst_id
, dst_host_irq
, ia_id
, vint
,
1949 global_event
, vint_status_bit
, s_host
,
1950 TI_SCI_MSG_FREE_IRQ
);
1954 * ti_sci_cmd_set_irq() - Configure a host irq route between the requested
1955 * source and destination.
1956 * @handle: Pointer to TISCI handle.
1957 * @src_id: Device ID of the IRQ source
1958 * @src_index: IRQ source index within the source device
1959 * @dst_id: Device ID of the IRQ destination
1960 * @dst_host_irq: IRQ number of the destination device
1961 * @vint_irq: Boolean specifying if this interrupt belongs to
1962 * Interrupt Aggregator.
1964 * Return: 0 if all went fine, else return appropriate error.
1966 static int ti_sci_cmd_set_irq(const struct ti_sci_handle
*handle
, u16 src_id
,
1967 u16 src_index
, u16 dst_id
, u16 dst_host_irq
)
1969 u32 valid_params
= MSG_FLAG_DST_ID_VALID
| MSG_FLAG_DST_HOST_IRQ_VALID
;
1971 return ti_sci_set_irq(handle
, valid_params
, src_id
, src_index
, dst_id
,
1972 dst_host_irq
, 0, 0, 0, 0, 0);
1976 * ti_sci_cmd_set_event_map() - Configure an event based irq route between the
1977 * requested source and Interrupt Aggregator.
1978 * @handle: Pointer to TISCI handle.
1979 * @src_id: Device ID of the IRQ source
1980 * @src_index: IRQ source index within the source device
1981 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1982 * @vint: Virtual interrupt to be used within the IA
1983 * @global_event: Global event number to be used for the requesting event
1984 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1986 * Return: 0 if all went fine, else return appropriate error.
1988 static int ti_sci_cmd_set_event_map(const struct ti_sci_handle
*handle
,
1989 u16 src_id
, u16 src_index
, u16 ia_id
,
1990 u16 vint
, u16 global_event
,
1993 u32 valid_params
= MSG_FLAG_IA_ID_VALID
| MSG_FLAG_VINT_VALID
|
1994 MSG_FLAG_GLB_EVNT_VALID
|
1995 MSG_FLAG_VINT_STS_BIT_VALID
;
1997 return ti_sci_set_irq(handle
, valid_params
, src_id
, src_index
, 0, 0,
1998 ia_id
, vint
, global_event
, vint_status_bit
, 0);
2002 * ti_sci_cmd_free_irq() - Free a host irq route between the between the
2003 * requested source and destination.
2004 * @handle: Pointer to TISCI handle.
2005 * @src_id: Device ID of the IRQ source
2006 * @src_index: IRQ source index within the source device
2007 * @dst_id: Device ID of the IRQ destination
2008 * @dst_host_irq: IRQ number of the destination device
2009 * @vint_irq: Boolean specifying if this interrupt belongs to
2010 * Interrupt Aggregator.
2012 * Return: 0 if all went fine, else return appropriate error.
2014 static int ti_sci_cmd_free_irq(const struct ti_sci_handle
*handle
, u16 src_id
,
2015 u16 src_index
, u16 dst_id
, u16 dst_host_irq
)
2017 u32 valid_params
= MSG_FLAG_DST_ID_VALID
| MSG_FLAG_DST_HOST_IRQ_VALID
;
2019 return ti_sci_free_irq(handle
, valid_params
, src_id
, src_index
, dst_id
,
2020 dst_host_irq
, 0, 0, 0, 0, 0);
2024 * ti_sci_cmd_free_event_map() - Free an event map between the requested source
2025 * and Interrupt Aggregator.
2026 * @handle: Pointer to TISCI handle.
2027 * @src_id: Device ID of the IRQ source
2028 * @src_index: IRQ source index within the source device
2029 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
2030 * @vint: Virtual interrupt to be used within the IA
2031 * @global_event: Global event number to be used for the requesting event
2032 * @vint_status_bit: Virtual interrupt status bit to be used for the event
2034 * Return: 0 if all went fine, else return appropriate error.
2036 static int ti_sci_cmd_free_event_map(const struct ti_sci_handle
*handle
,
2037 u16 src_id
, u16 src_index
, u16 ia_id
,
2038 u16 vint
, u16 global_event
,
2041 u32 valid_params
= MSG_FLAG_IA_ID_VALID
|
2042 MSG_FLAG_VINT_VALID
| MSG_FLAG_GLB_EVNT_VALID
|
2043 MSG_FLAG_VINT_STS_BIT_VALID
;
2045 return ti_sci_free_irq(handle
, valid_params
, src_id
, src_index
, 0, 0,
2046 ia_id
, vint
, global_event
, vint_status_bit
, 0);
2050 * ti_sci_cmd_ring_config() - configure RA ring
2051 * @handle: Pointer to TI SCI handle.
2052 * @valid_params: Bitfield defining validity of ring configuration
2054 * @nav_id: Device ID of Navigator Subsystem from which the ring is
2056 * @index: Ring index
2057 * @addr_lo: The ring base address lo 32 bits
2058 * @addr_hi: The ring base address hi 32 bits
2059 * @count: Number of ring elements
2060 * @mode: The mode of the ring
2061 * @size: The ring element size.
2062 * @order_id: Specifies the ring's bus order ID
2064 * Return: 0 if all went well, else returns appropriate error value.
2066 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2068 static int ti_sci_cmd_ring_config(const struct ti_sci_handle
*handle
,
2069 u32 valid_params
, u16 nav_id
, u16 index
,
2070 u32 addr_lo
, u32 addr_hi
, u32 count
,
2071 u8 mode
, u8 size
, u8 order_id
)
2073 struct ti_sci_msg_rm_ring_cfg_req
*req
;
2074 struct ti_sci_msg_hdr
*resp
;
2075 struct ti_sci_xfer
*xfer
;
2076 struct ti_sci_info
*info
;
2080 if (IS_ERR_OR_NULL(handle
))
2083 info
= handle_to_ti_sci_info(handle
);
2086 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_RING_CFG
,
2087 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2088 sizeof(*req
), sizeof(*resp
));
2090 ret
= PTR_ERR(xfer
);
2091 dev_err(dev
, "RM_RA:Message config failed(%d)\n", ret
);
2094 req
= (struct ti_sci_msg_rm_ring_cfg_req
*)xfer
->xfer_buf
;
2095 req
->valid_params
= valid_params
;
2096 req
->nav_id
= nav_id
;
2098 req
->addr_lo
= addr_lo
;
2099 req
->addr_hi
= addr_hi
;
2103 req
->order_id
= order_id
;
2105 ret
= ti_sci_do_xfer(info
, xfer
);
2107 dev_err(dev
, "RM_RA:Mbox config send fail %d\n", ret
);
2111 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2112 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2115 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2116 dev_dbg(dev
, "RM_RA:config ring %u ret:%d\n", index
, ret
);
2121 * ti_sci_cmd_ring_get_config() - get RA ring configuration
2122 * @handle: Pointer to TI SCI handle.
2123 * @nav_id: Device ID of Navigator Subsystem from which the ring is
2125 * @index: Ring index
2126 * @addr_lo: Returns ring's base address lo 32 bits
2127 * @addr_hi: Returns ring's base address hi 32 bits
2128 * @count: Returns number of ring elements
2129 * @mode: Returns mode of the ring
2130 * @size: Returns ring element size
2131 * @order_id: Returns ring's bus order ID
2133 * Return: 0 if all went well, else returns appropriate error value.
2135 * See @ti_sci_msg_rm_ring_get_cfg_req for more info.
2137 static int ti_sci_cmd_ring_get_config(const struct ti_sci_handle
*handle
,
2138 u32 nav_id
, u32 index
, u8
*mode
,
2139 u32
*addr_lo
, u32
*addr_hi
,
2140 u32
*count
, u8
*size
, u8
*order_id
)
2142 struct ti_sci_msg_rm_ring_get_cfg_resp
*resp
;
2143 struct ti_sci_msg_rm_ring_get_cfg_req
*req
;
2144 struct ti_sci_xfer
*xfer
;
2145 struct ti_sci_info
*info
;
2149 if (IS_ERR_OR_NULL(handle
))
2152 info
= handle_to_ti_sci_info(handle
);
2155 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_RING_GET_CFG
,
2156 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2157 sizeof(*req
), sizeof(*resp
));
2159 ret
= PTR_ERR(xfer
);
2161 "RM_RA:Message get config failed(%d)\n", ret
);
2164 req
= (struct ti_sci_msg_rm_ring_get_cfg_req
*)xfer
->xfer_buf
;
2165 req
->nav_id
= nav_id
;
2168 ret
= ti_sci_do_xfer(info
, xfer
);
2170 dev_err(dev
, "RM_RA:Mbox get config send fail %d\n", ret
);
2174 resp
= (struct ti_sci_msg_rm_ring_get_cfg_resp
*)xfer
->xfer_buf
;
2176 if (!ti_sci_is_response_ack(resp
)) {
2182 *addr_lo
= resp
->addr_lo
;
2184 *addr_hi
= resp
->addr_hi
;
2186 *count
= resp
->count
;
2190 *order_id
= resp
->order_id
;
2194 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2195 dev_dbg(dev
, "RM_RA:get config ring %u ret:%d\n", index
, ret
);
2200 * ti_sci_cmd_rm_psil_pair() - Pair PSI-L source to destination thread
2201 * @handle: Pointer to TI SCI handle.
2202 * @nav_id: Device ID of Navigator Subsystem which should be used for
2204 * @src_thread: Source PSI-L thread ID
2205 * @dst_thread: Destination PSI-L thread ID
2207 * Return: 0 if all went well, else returns appropriate error value.
2209 static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle
*handle
,
2210 u32 nav_id
, u32 src_thread
, u32 dst_thread
)
2212 struct ti_sci_msg_psil_pair
*req
;
2213 struct ti_sci_msg_hdr
*resp
;
2214 struct ti_sci_xfer
*xfer
;
2215 struct ti_sci_info
*info
;
2220 return PTR_ERR(handle
);
2224 info
= handle_to_ti_sci_info(handle
);
2227 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_PSIL_PAIR
,
2228 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2229 sizeof(*req
), sizeof(*resp
));
2231 ret
= PTR_ERR(xfer
);
2232 dev_err(dev
, "RM_PSIL:Message reconfig failed(%d)\n", ret
);
2235 req
= (struct ti_sci_msg_psil_pair
*)xfer
->xfer_buf
;
2236 req
->nav_id
= nav_id
;
2237 req
->src_thread
= src_thread
;
2238 req
->dst_thread
= dst_thread
;
2240 ret
= ti_sci_do_xfer(info
, xfer
);
2242 dev_err(dev
, "RM_PSIL:Mbox send fail %d\n", ret
);
2246 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2247 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2250 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2256 * ti_sci_cmd_rm_psil_unpair() - Unpair PSI-L source from destination thread
2257 * @handle: Pointer to TI SCI handle.
2258 * @nav_id: Device ID of Navigator Subsystem which should be used for
2260 * @src_thread: Source PSI-L thread ID
2261 * @dst_thread: Destination PSI-L thread ID
2263 * Return: 0 if all went well, else returns appropriate error value.
2265 static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle
*handle
,
2266 u32 nav_id
, u32 src_thread
, u32 dst_thread
)
2268 struct ti_sci_msg_psil_unpair
*req
;
2269 struct ti_sci_msg_hdr
*resp
;
2270 struct ti_sci_xfer
*xfer
;
2271 struct ti_sci_info
*info
;
2276 return PTR_ERR(handle
);
2280 info
= handle_to_ti_sci_info(handle
);
2283 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_PSIL_UNPAIR
,
2284 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2285 sizeof(*req
), sizeof(*resp
));
2287 ret
= PTR_ERR(xfer
);
2288 dev_err(dev
, "RM_PSIL:Message reconfig failed(%d)\n", ret
);
2291 req
= (struct ti_sci_msg_psil_unpair
*)xfer
->xfer_buf
;
2292 req
->nav_id
= nav_id
;
2293 req
->src_thread
= src_thread
;
2294 req
->dst_thread
= dst_thread
;
2296 ret
= ti_sci_do_xfer(info
, xfer
);
2298 dev_err(dev
, "RM_PSIL:Mbox send fail %d\n", ret
);
2302 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2303 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2306 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2312 * ti_sci_cmd_rm_udmap_tx_ch_cfg() - Configure a UDMAP TX channel
2313 * @handle: Pointer to TI SCI handle.
2314 * @params: Pointer to ti_sci_msg_rm_udmap_tx_ch_cfg TX channel config
2317 * Return: 0 if all went well, else returns appropriate error value.
2319 * See @ti_sci_msg_rm_udmap_tx_ch_cfg and @ti_sci_msg_rm_udmap_tx_ch_cfg_req for
2322 static int ti_sci_cmd_rm_udmap_tx_ch_cfg(const struct ti_sci_handle
*handle
,
2323 const struct ti_sci_msg_rm_udmap_tx_ch_cfg
*params
)
2325 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req
*req
;
2326 struct ti_sci_msg_hdr
*resp
;
2327 struct ti_sci_xfer
*xfer
;
2328 struct ti_sci_info
*info
;
2332 if (IS_ERR_OR_NULL(handle
))
2335 info
= handle_to_ti_sci_info(handle
);
2338 xfer
= ti_sci_get_one_xfer(info
, TISCI_MSG_RM_UDMAP_TX_CH_CFG
,
2339 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2340 sizeof(*req
), sizeof(*resp
));
2342 ret
= PTR_ERR(xfer
);
2343 dev_err(dev
, "Message TX_CH_CFG alloc failed(%d)\n", ret
);
2346 req
= (struct ti_sci_msg_rm_udmap_tx_ch_cfg_req
*)xfer
->xfer_buf
;
2347 req
->valid_params
= params
->valid_params
;
2348 req
->nav_id
= params
->nav_id
;
2349 req
->index
= params
->index
;
2350 req
->tx_pause_on_err
= params
->tx_pause_on_err
;
2351 req
->tx_filt_einfo
= params
->tx_filt_einfo
;
2352 req
->tx_filt_pswords
= params
->tx_filt_pswords
;
2353 req
->tx_atype
= params
->tx_atype
;
2354 req
->tx_chan_type
= params
->tx_chan_type
;
2355 req
->tx_supr_tdpkt
= params
->tx_supr_tdpkt
;
2356 req
->tx_fetch_size
= params
->tx_fetch_size
;
2357 req
->tx_credit_count
= params
->tx_credit_count
;
2358 req
->txcq_qnum
= params
->txcq_qnum
;
2359 req
->tx_priority
= params
->tx_priority
;
2360 req
->tx_qos
= params
->tx_qos
;
2361 req
->tx_orderid
= params
->tx_orderid
;
2362 req
->fdepth
= params
->fdepth
;
2363 req
->tx_sched_priority
= params
->tx_sched_priority
;
2364 req
->tx_burst_size
= params
->tx_burst_size
;
2366 ret
= ti_sci_do_xfer(info
, xfer
);
2368 dev_err(dev
, "Mbox send TX_CH_CFG fail %d\n", ret
);
2372 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2373 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2376 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2377 dev_dbg(dev
, "TX_CH_CFG: chn %u ret:%u\n", params
->index
, ret
);
2382 * ti_sci_cmd_rm_udmap_rx_ch_cfg() - Configure a UDMAP RX channel
2383 * @handle: Pointer to TI SCI handle.
2384 * @params: Pointer to ti_sci_msg_rm_udmap_rx_ch_cfg RX channel config
2387 * Return: 0 if all went well, else returns appropriate error value.
2389 * See @ti_sci_msg_rm_udmap_rx_ch_cfg and @ti_sci_msg_rm_udmap_rx_ch_cfg_req for
2392 static int ti_sci_cmd_rm_udmap_rx_ch_cfg(const struct ti_sci_handle
*handle
,
2393 const struct ti_sci_msg_rm_udmap_rx_ch_cfg
*params
)
2395 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req
*req
;
2396 struct ti_sci_msg_hdr
*resp
;
2397 struct ti_sci_xfer
*xfer
;
2398 struct ti_sci_info
*info
;
2402 if (IS_ERR_OR_NULL(handle
))
2405 info
= handle_to_ti_sci_info(handle
);
2408 xfer
= ti_sci_get_one_xfer(info
, TISCI_MSG_RM_UDMAP_RX_CH_CFG
,
2409 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2410 sizeof(*req
), sizeof(*resp
));
2412 ret
= PTR_ERR(xfer
);
2413 dev_err(dev
, "Message RX_CH_CFG alloc failed(%d)\n", ret
);
2416 req
= (struct ti_sci_msg_rm_udmap_rx_ch_cfg_req
*)xfer
->xfer_buf
;
2417 req
->valid_params
= params
->valid_params
;
2418 req
->nav_id
= params
->nav_id
;
2419 req
->index
= params
->index
;
2420 req
->rx_fetch_size
= params
->rx_fetch_size
;
2421 req
->rxcq_qnum
= params
->rxcq_qnum
;
2422 req
->rx_priority
= params
->rx_priority
;
2423 req
->rx_qos
= params
->rx_qos
;
2424 req
->rx_orderid
= params
->rx_orderid
;
2425 req
->rx_sched_priority
= params
->rx_sched_priority
;
2426 req
->flowid_start
= params
->flowid_start
;
2427 req
->flowid_cnt
= params
->flowid_cnt
;
2428 req
->rx_pause_on_err
= params
->rx_pause_on_err
;
2429 req
->rx_atype
= params
->rx_atype
;
2430 req
->rx_chan_type
= params
->rx_chan_type
;
2431 req
->rx_ignore_short
= params
->rx_ignore_short
;
2432 req
->rx_ignore_long
= params
->rx_ignore_long
;
2433 req
->rx_burst_size
= params
->rx_burst_size
;
2435 ret
= ti_sci_do_xfer(info
, xfer
);
2437 dev_err(dev
, "Mbox send RX_CH_CFG fail %d\n", ret
);
2441 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2442 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2445 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2446 dev_dbg(dev
, "RX_CH_CFG: chn %u ret:%d\n", params
->index
, ret
);
2451 * ti_sci_cmd_rm_udmap_rx_flow_cfg() - Configure UDMAP RX FLOW
2452 * @handle: Pointer to TI SCI handle.
2453 * @params: Pointer to ti_sci_msg_rm_udmap_flow_cfg RX FLOW config
2456 * Return: 0 if all went well, else returns appropriate error value.
2458 * See @ti_sci_msg_rm_udmap_flow_cfg and @ti_sci_msg_rm_udmap_flow_cfg_req for
2461 static int ti_sci_cmd_rm_udmap_rx_flow_cfg(const struct ti_sci_handle
*handle
,
2462 const struct ti_sci_msg_rm_udmap_flow_cfg
*params
)
2464 struct ti_sci_msg_rm_udmap_flow_cfg_req
*req
;
2465 struct ti_sci_msg_hdr
*resp
;
2466 struct ti_sci_xfer
*xfer
;
2467 struct ti_sci_info
*info
;
2471 if (IS_ERR_OR_NULL(handle
))
2474 info
= handle_to_ti_sci_info(handle
);
2477 xfer
= ti_sci_get_one_xfer(info
, TISCI_MSG_RM_UDMAP_FLOW_CFG
,
2478 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2479 sizeof(*req
), sizeof(*resp
));
2481 ret
= PTR_ERR(xfer
);
2482 dev_err(dev
, "RX_FL_CFG: Message alloc failed(%d)\n", ret
);
2485 req
= (struct ti_sci_msg_rm_udmap_flow_cfg_req
*)xfer
->xfer_buf
;
2486 req
->valid_params
= params
->valid_params
;
2487 req
->nav_id
= params
->nav_id
;
2488 req
->flow_index
= params
->flow_index
;
2489 req
->rx_einfo_present
= params
->rx_einfo_present
;
2490 req
->rx_psinfo_present
= params
->rx_psinfo_present
;
2491 req
->rx_error_handling
= params
->rx_error_handling
;
2492 req
->rx_desc_type
= params
->rx_desc_type
;
2493 req
->rx_sop_offset
= params
->rx_sop_offset
;
2494 req
->rx_dest_qnum
= params
->rx_dest_qnum
;
2495 req
->rx_src_tag_hi
= params
->rx_src_tag_hi
;
2496 req
->rx_src_tag_lo
= params
->rx_src_tag_lo
;
2497 req
->rx_dest_tag_hi
= params
->rx_dest_tag_hi
;
2498 req
->rx_dest_tag_lo
= params
->rx_dest_tag_lo
;
2499 req
->rx_src_tag_hi_sel
= params
->rx_src_tag_hi_sel
;
2500 req
->rx_src_tag_lo_sel
= params
->rx_src_tag_lo_sel
;
2501 req
->rx_dest_tag_hi_sel
= params
->rx_dest_tag_hi_sel
;
2502 req
->rx_dest_tag_lo_sel
= params
->rx_dest_tag_lo_sel
;
2503 req
->rx_fdq0_sz0_qnum
= params
->rx_fdq0_sz0_qnum
;
2504 req
->rx_fdq1_qnum
= params
->rx_fdq1_qnum
;
2505 req
->rx_fdq2_qnum
= params
->rx_fdq2_qnum
;
2506 req
->rx_fdq3_qnum
= params
->rx_fdq3_qnum
;
2507 req
->rx_ps_location
= params
->rx_ps_location
;
2509 ret
= ti_sci_do_xfer(info
, xfer
);
2511 dev_err(dev
, "RX_FL_CFG: Mbox send fail %d\n", ret
);
2515 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2516 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2519 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2520 dev_dbg(info
->dev
, "RX_FL_CFG: %u ret:%d\n", params
->flow_index
, ret
);
2525 * ti_sci_cmd_proc_request() - Command to request a physical processor control
2526 * @handle: Pointer to TI SCI handle
2527 * @proc_id: Processor ID this request is for
2529 * Return: 0 if all went well, else returns appropriate error value.
2531 static int ti_sci_cmd_proc_request(const struct ti_sci_handle
*handle
,
2534 struct ti_sci_msg_req_proc_request
*req
;
2535 struct ti_sci_msg_hdr
*resp
;
2536 struct ti_sci_info
*info
;
2537 struct ti_sci_xfer
*xfer
;
2544 return PTR_ERR(handle
);
2546 info
= handle_to_ti_sci_info(handle
);
2549 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_PROC_REQUEST
,
2550 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2551 sizeof(*req
), sizeof(*resp
));
2553 ret
= PTR_ERR(xfer
);
2554 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2557 req
= (struct ti_sci_msg_req_proc_request
*)xfer
->xfer_buf
;
2558 req
->processor_id
= proc_id
;
2560 ret
= ti_sci_do_xfer(info
, xfer
);
2562 dev_err(dev
, "Mbox send fail %d\n", ret
);
2566 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2568 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2571 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2577 * ti_sci_cmd_proc_release() - Command to release a physical processor control
2578 * @handle: Pointer to TI SCI handle
2579 * @proc_id: Processor ID this request is for
2581 * Return: 0 if all went well, else returns appropriate error value.
2583 static int ti_sci_cmd_proc_release(const struct ti_sci_handle
*handle
,
2586 struct ti_sci_msg_req_proc_release
*req
;
2587 struct ti_sci_msg_hdr
*resp
;
2588 struct ti_sci_info
*info
;
2589 struct ti_sci_xfer
*xfer
;
2596 return PTR_ERR(handle
);
2598 info
= handle_to_ti_sci_info(handle
);
2601 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_PROC_RELEASE
,
2602 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2603 sizeof(*req
), sizeof(*resp
));
2605 ret
= PTR_ERR(xfer
);
2606 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2609 req
= (struct ti_sci_msg_req_proc_release
*)xfer
->xfer_buf
;
2610 req
->processor_id
= proc_id
;
2612 ret
= ti_sci_do_xfer(info
, xfer
);
2614 dev_err(dev
, "Mbox send fail %d\n", ret
);
2618 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2620 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2623 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2629 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
2630 * control to a host in the processor's access
2632 * @handle: Pointer to TI SCI handle
2633 * @proc_id: Processor ID this request is for
2634 * @host_id: Host ID to get the control of the processor
2636 * Return: 0 if all went well, else returns appropriate error value.
2638 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle
*handle
,
2639 u8 proc_id
, u8 host_id
)
2641 struct ti_sci_msg_req_proc_handover
*req
;
2642 struct ti_sci_msg_hdr
*resp
;
2643 struct ti_sci_info
*info
;
2644 struct ti_sci_xfer
*xfer
;
2651 return PTR_ERR(handle
);
2653 info
= handle_to_ti_sci_info(handle
);
2656 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_PROC_HANDOVER
,
2657 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2658 sizeof(*req
), sizeof(*resp
));
2660 ret
= PTR_ERR(xfer
);
2661 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2664 req
= (struct ti_sci_msg_req_proc_handover
*)xfer
->xfer_buf
;
2665 req
->processor_id
= proc_id
;
2666 req
->host_id
= host_id
;
2668 ret
= ti_sci_do_xfer(info
, xfer
);
2670 dev_err(dev
, "Mbox send fail %d\n", ret
);
2674 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2676 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2679 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2685 * ti_sci_cmd_proc_set_config() - Command to set the processor boot
2686 * configuration flags
2687 * @handle: Pointer to TI SCI handle
2688 * @proc_id: Processor ID this request is for
2689 * @config_flags_set: Configuration flags to be set
2690 * @config_flags_clear: Configuration flags to be cleared.
2692 * Return: 0 if all went well, else returns appropriate error value.
2694 static int ti_sci_cmd_proc_set_config(const struct ti_sci_handle
*handle
,
2695 u8 proc_id
, u64 bootvector
,
2696 u32 config_flags_set
,
2697 u32 config_flags_clear
)
2699 struct ti_sci_msg_req_set_config
*req
;
2700 struct ti_sci_msg_hdr
*resp
;
2701 struct ti_sci_info
*info
;
2702 struct ti_sci_xfer
*xfer
;
2709 return PTR_ERR(handle
);
2711 info
= handle_to_ti_sci_info(handle
);
2714 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CONFIG
,
2715 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2716 sizeof(*req
), sizeof(*resp
));
2718 ret
= PTR_ERR(xfer
);
2719 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2722 req
= (struct ti_sci_msg_req_set_config
*)xfer
->xfer_buf
;
2723 req
->processor_id
= proc_id
;
2724 req
->bootvector_low
= bootvector
& TI_SCI_ADDR_LOW_MASK
;
2725 req
->bootvector_high
= (bootvector
& TI_SCI_ADDR_HIGH_MASK
) >>
2726 TI_SCI_ADDR_HIGH_SHIFT
;
2727 req
->config_flags_set
= config_flags_set
;
2728 req
->config_flags_clear
= config_flags_clear
;
2730 ret
= ti_sci_do_xfer(info
, xfer
);
2732 dev_err(dev
, "Mbox send fail %d\n", ret
);
2736 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2738 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2741 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2747 * ti_sci_cmd_proc_set_control() - Command to set the processor boot
2749 * @handle: Pointer to TI SCI handle
2750 * @proc_id: Processor ID this request is for
2751 * @control_flags_set: Control flags to be set
2752 * @control_flags_clear: Control flags to be cleared
2754 * Return: 0 if all went well, else returns appropriate error value.
2756 static int ti_sci_cmd_proc_set_control(const struct ti_sci_handle
*handle
,
2757 u8 proc_id
, u32 control_flags_set
,
2758 u32 control_flags_clear
)
2760 struct ti_sci_msg_req_set_ctrl
*req
;
2761 struct ti_sci_msg_hdr
*resp
;
2762 struct ti_sci_info
*info
;
2763 struct ti_sci_xfer
*xfer
;
2770 return PTR_ERR(handle
);
2772 info
= handle_to_ti_sci_info(handle
);
2775 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CTRL
,
2776 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2777 sizeof(*req
), sizeof(*resp
));
2779 ret
= PTR_ERR(xfer
);
2780 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2783 req
= (struct ti_sci_msg_req_set_ctrl
*)xfer
->xfer_buf
;
2784 req
->processor_id
= proc_id
;
2785 req
->control_flags_set
= control_flags_set
;
2786 req
->control_flags_clear
= control_flags_clear
;
2788 ret
= ti_sci_do_xfer(info
, xfer
);
2790 dev_err(dev
, "Mbox send fail %d\n", ret
);
2794 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2796 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2799 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2805 * ti_sci_cmd_get_boot_status() - Command to get the processor boot status
2806 * @handle: Pointer to TI SCI handle
2807 * @proc_id: Processor ID this request is for
2809 * Return: 0 if all went well, else returns appropriate error value.
2811 static int ti_sci_cmd_proc_get_status(const struct ti_sci_handle
*handle
,
2812 u8 proc_id
, u64
*bv
, u32
*cfg_flags
,
2813 u32
*ctrl_flags
, u32
*sts_flags
)
2815 struct ti_sci_msg_resp_get_status
*resp
;
2816 struct ti_sci_msg_req_get_status
*req
;
2817 struct ti_sci_info
*info
;
2818 struct ti_sci_xfer
*xfer
;
2825 return PTR_ERR(handle
);
2827 info
= handle_to_ti_sci_info(handle
);
2830 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_STATUS
,
2831 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2832 sizeof(*req
), sizeof(*resp
));
2834 ret
= PTR_ERR(xfer
);
2835 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2838 req
= (struct ti_sci_msg_req_get_status
*)xfer
->xfer_buf
;
2839 req
->processor_id
= proc_id
;
2841 ret
= ti_sci_do_xfer(info
, xfer
);
2843 dev_err(dev
, "Mbox send fail %d\n", ret
);
2847 resp
= (struct ti_sci_msg_resp_get_status
*)xfer
->tx_message
.buf
;
2849 if (!ti_sci_is_response_ack(resp
)) {
2852 *bv
= (resp
->bootvector_low
& TI_SCI_ADDR_LOW_MASK
) |
2853 (((u64
)resp
->bootvector_high
<< TI_SCI_ADDR_HIGH_SHIFT
) &
2854 TI_SCI_ADDR_HIGH_MASK
);
2855 *cfg_flags
= resp
->config_flags
;
2856 *ctrl_flags
= resp
->control_flags
;
2857 *sts_flags
= resp
->status_flags
;
2861 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2867 * ti_sci_setup_ops() - Setup the operations structures
2868 * @info: pointer to TISCI pointer
2870 static void ti_sci_setup_ops(struct ti_sci_info
*info
)
2872 struct ti_sci_ops
*ops
= &info
->handle
.ops
;
2873 struct ti_sci_core_ops
*core_ops
= &ops
->core_ops
;
2874 struct ti_sci_dev_ops
*dops
= &ops
->dev_ops
;
2875 struct ti_sci_clk_ops
*cops
= &ops
->clk_ops
;
2876 struct ti_sci_rm_core_ops
*rm_core_ops
= &ops
->rm_core_ops
;
2877 struct ti_sci_rm_irq_ops
*iops
= &ops
->rm_irq_ops
;
2878 struct ti_sci_rm_ringacc_ops
*rops
= &ops
->rm_ring_ops
;
2879 struct ti_sci_rm_psil_ops
*psilops
= &ops
->rm_psil_ops
;
2880 struct ti_sci_rm_udmap_ops
*udmap_ops
= &ops
->rm_udmap_ops
;
2881 struct ti_sci_proc_ops
*pops
= &ops
->proc_ops
;
2883 core_ops
->reboot_device
= ti_sci_cmd_core_reboot
;
2885 dops
->get_device
= ti_sci_cmd_get_device
;
2886 dops
->get_device_exclusive
= ti_sci_cmd_get_device_exclusive
;
2887 dops
->idle_device
= ti_sci_cmd_idle_device
;
2888 dops
->idle_device_exclusive
= ti_sci_cmd_idle_device_exclusive
;
2889 dops
->put_device
= ti_sci_cmd_put_device
;
2891 dops
->is_valid
= ti_sci_cmd_dev_is_valid
;
2892 dops
->get_context_loss_count
= ti_sci_cmd_dev_get_clcnt
;
2893 dops
->is_idle
= ti_sci_cmd_dev_is_idle
;
2894 dops
->is_stop
= ti_sci_cmd_dev_is_stop
;
2895 dops
->is_on
= ti_sci_cmd_dev_is_on
;
2896 dops
->is_transitioning
= ti_sci_cmd_dev_is_trans
;
2897 dops
->set_device_resets
= ti_sci_cmd_set_device_resets
;
2898 dops
->get_device_resets
= ti_sci_cmd_get_device_resets
;
2900 cops
->get_clock
= ti_sci_cmd_get_clock
;
2901 cops
->idle_clock
= ti_sci_cmd_idle_clock
;
2902 cops
->put_clock
= ti_sci_cmd_put_clock
;
2903 cops
->is_auto
= ti_sci_cmd_clk_is_auto
;
2904 cops
->is_on
= ti_sci_cmd_clk_is_on
;
2905 cops
->is_off
= ti_sci_cmd_clk_is_off
;
2907 cops
->set_parent
= ti_sci_cmd_clk_set_parent
;
2908 cops
->get_parent
= ti_sci_cmd_clk_get_parent
;
2909 cops
->get_num_parents
= ti_sci_cmd_clk_get_num_parents
;
2911 cops
->get_best_match_freq
= ti_sci_cmd_clk_get_match_freq
;
2912 cops
->set_freq
= ti_sci_cmd_clk_set_freq
;
2913 cops
->get_freq
= ti_sci_cmd_clk_get_freq
;
2915 rm_core_ops
->get_range
= ti_sci_cmd_get_resource_range
;
2916 rm_core_ops
->get_range_from_shost
=
2917 ti_sci_cmd_get_resource_range_from_shost
;
2919 iops
->set_irq
= ti_sci_cmd_set_irq
;
2920 iops
->set_event_map
= ti_sci_cmd_set_event_map
;
2921 iops
->free_irq
= ti_sci_cmd_free_irq
;
2922 iops
->free_event_map
= ti_sci_cmd_free_event_map
;
2924 rops
->config
= ti_sci_cmd_ring_config
;
2925 rops
->get_config
= ti_sci_cmd_ring_get_config
;
2927 psilops
->pair
= ti_sci_cmd_rm_psil_pair
;
2928 psilops
->unpair
= ti_sci_cmd_rm_psil_unpair
;
2930 udmap_ops
->tx_ch_cfg
= ti_sci_cmd_rm_udmap_tx_ch_cfg
;
2931 udmap_ops
->rx_ch_cfg
= ti_sci_cmd_rm_udmap_rx_ch_cfg
;
2932 udmap_ops
->rx_flow_cfg
= ti_sci_cmd_rm_udmap_rx_flow_cfg
;
2934 pops
->request
= ti_sci_cmd_proc_request
;
2935 pops
->release
= ti_sci_cmd_proc_release
;
2936 pops
->handover
= ti_sci_cmd_proc_handover
;
2937 pops
->set_config
= ti_sci_cmd_proc_set_config
;
2938 pops
->set_control
= ti_sci_cmd_proc_set_control
;
2939 pops
->get_status
= ti_sci_cmd_proc_get_status
;
2943 * ti_sci_get_handle() - Get the TI SCI handle for a device
2944 * @dev: Pointer to device for which we want SCI handle
2946 * NOTE: The function does not track individual clients of the framework
2947 * and is expected to be maintained by caller of TI SCI protocol library.
2948 * ti_sci_put_handle must be balanced with successful ti_sci_get_handle
2949 * Return: pointer to handle if successful, else:
2950 * -EPROBE_DEFER if the instance is not ready
2951 * -ENODEV if the required node handler is missing
2952 * -EINVAL if invalid conditions are encountered.
2954 const struct ti_sci_handle
*ti_sci_get_handle(struct device
*dev
)
2956 struct device_node
*ti_sci_np
;
2957 struct list_head
*p
;
2958 struct ti_sci_handle
*handle
= NULL
;
2959 struct ti_sci_info
*info
;
2962 pr_err("I need a device pointer\n");
2963 return ERR_PTR(-EINVAL
);
2965 ti_sci_np
= of_get_parent(dev
->of_node
);
2967 dev_err(dev
, "No OF information\n");
2968 return ERR_PTR(-EINVAL
);
2971 mutex_lock(&ti_sci_list_mutex
);
2972 list_for_each(p
, &ti_sci_list
) {
2973 info
= list_entry(p
, struct ti_sci_info
, node
);
2974 if (ti_sci_np
== info
->dev
->of_node
) {
2975 handle
= &info
->handle
;
2980 mutex_unlock(&ti_sci_list_mutex
);
2981 of_node_put(ti_sci_np
);
2984 return ERR_PTR(-EPROBE_DEFER
);
2988 EXPORT_SYMBOL_GPL(ti_sci_get_handle
);
2991 * ti_sci_put_handle() - Release the handle acquired by ti_sci_get_handle
2992 * @handle: Handle acquired by ti_sci_get_handle
2994 * NOTE: The function does not track individual clients of the framework
2995 * and is expected to be maintained by caller of TI SCI protocol library.
2996 * ti_sci_put_handle must be balanced with successful ti_sci_get_handle
2998 * Return: 0 is successfully released
2999 * if an error pointer was passed, it returns the error value back,
3000 * if null was passed, it returns -EINVAL;
3002 int ti_sci_put_handle(const struct ti_sci_handle
*handle
)
3004 struct ti_sci_info
*info
;
3007 return PTR_ERR(handle
);
3011 info
= handle_to_ti_sci_info(handle
);
3012 mutex_lock(&ti_sci_list_mutex
);
3013 if (!WARN_ON(!info
->users
))
3015 mutex_unlock(&ti_sci_list_mutex
);
3019 EXPORT_SYMBOL_GPL(ti_sci_put_handle
);
3021 static void devm_ti_sci_release(struct device
*dev
, void *res
)
3023 const struct ti_sci_handle
**ptr
= res
;
3024 const struct ti_sci_handle
*handle
= *ptr
;
3027 ret
= ti_sci_put_handle(handle
);
3029 dev_err(dev
, "failed to put handle %d\n", ret
);
3033 * devm_ti_sci_get_handle() - Managed get handle
3034 * @dev: device for which we want SCI handle for.
3036 * NOTE: This releases the handle once the device resources are
3037 * no longer needed. MUST NOT BE released with ti_sci_put_handle.
3038 * The function does not track individual clients of the framework
3039 * and is expected to be maintained by caller of TI SCI protocol library.
3041 * Return: 0 if all went fine, else corresponding error.
3043 const struct ti_sci_handle
*devm_ti_sci_get_handle(struct device
*dev
)
3045 const struct ti_sci_handle
**ptr
;
3046 const struct ti_sci_handle
*handle
;
3048 ptr
= devres_alloc(devm_ti_sci_release
, sizeof(*ptr
), GFP_KERNEL
);
3050 return ERR_PTR(-ENOMEM
);
3051 handle
= ti_sci_get_handle(dev
);
3053 if (!IS_ERR(handle
)) {
3055 devres_add(dev
, ptr
);
3062 EXPORT_SYMBOL_GPL(devm_ti_sci_get_handle
);
3065 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
3067 * @property: property name containing phandle on TISCI node
3069 * NOTE: The function does not track individual clients of the framework
3070 * and is expected to be maintained by caller of TI SCI protocol library.
3071 * ti_sci_put_handle must be balanced with successful ti_sci_get_by_phandle
3072 * Return: pointer to handle if successful, else:
3073 * -EPROBE_DEFER if the instance is not ready
3074 * -ENODEV if the required node handler is missing
3075 * -EINVAL if invalid conditions are encountered.
3077 const struct ti_sci_handle
*ti_sci_get_by_phandle(struct device_node
*np
,
3078 const char *property
)
3080 struct ti_sci_handle
*handle
= NULL
;
3081 struct device_node
*ti_sci_np
;
3082 struct ti_sci_info
*info
;
3083 struct list_head
*p
;
3086 pr_err("I need a device pointer\n");
3087 return ERR_PTR(-EINVAL
);
3090 ti_sci_np
= of_parse_phandle(np
, property
, 0);
3092 return ERR_PTR(-ENODEV
);
3094 mutex_lock(&ti_sci_list_mutex
);
3095 list_for_each(p
, &ti_sci_list
) {
3096 info
= list_entry(p
, struct ti_sci_info
, node
);
3097 if (ti_sci_np
== info
->dev
->of_node
) {
3098 handle
= &info
->handle
;
3103 mutex_unlock(&ti_sci_list_mutex
);
3104 of_node_put(ti_sci_np
);
3107 return ERR_PTR(-EPROBE_DEFER
);
3111 EXPORT_SYMBOL_GPL(ti_sci_get_by_phandle
);
3114 * devm_ti_sci_get_by_phandle() - Managed get handle using phandle
3115 * @dev: Device pointer requesting TISCI handle
3116 * @property: property name containing phandle on TISCI node
3118 * NOTE: This releases the handle once the device resources are
3119 * no longer needed. MUST NOT BE released with ti_sci_put_handle.
3120 * The function does not track individual clients of the framework
3121 * and is expected to be maintained by caller of TI SCI protocol library.
3123 * Return: 0 if all went fine, else corresponding error.
3125 const struct ti_sci_handle
*devm_ti_sci_get_by_phandle(struct device
*dev
,
3126 const char *property
)
3128 const struct ti_sci_handle
*handle
;
3129 const struct ti_sci_handle
**ptr
;
3131 ptr
= devres_alloc(devm_ti_sci_release
, sizeof(*ptr
), GFP_KERNEL
);
3133 return ERR_PTR(-ENOMEM
);
3134 handle
= ti_sci_get_by_phandle(dev_of_node(dev
), property
);
3136 if (!IS_ERR(handle
)) {
3138 devres_add(dev
, ptr
);
3145 EXPORT_SYMBOL_GPL(devm_ti_sci_get_by_phandle
);
3148 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
3149 * @res: Pointer to the TISCI resource
3151 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
3153 u16
ti_sci_get_free_resource(struct ti_sci_resource
*res
)
3155 unsigned long flags
;
3158 raw_spin_lock_irqsave(&res
->lock
, flags
);
3159 for (set
= 0; set
< res
->sets
; set
++) {
3160 free_bit
= find_first_zero_bit(res
->desc
[set
].res_map
,
3161 res
->desc
[set
].num
);
3162 if (free_bit
!= res
->desc
[set
].num
) {
3163 set_bit(free_bit
, res
->desc
[set
].res_map
);
3164 raw_spin_unlock_irqrestore(&res
->lock
, flags
);
3165 return res
->desc
[set
].start
+ free_bit
;
3168 raw_spin_unlock_irqrestore(&res
->lock
, flags
);
3170 return TI_SCI_RESOURCE_NULL
;
3172 EXPORT_SYMBOL_GPL(ti_sci_get_free_resource
);
3175 * ti_sci_release_resource() - Release a resource from TISCI resource.
3176 * @res: Pointer to the TISCI resource
3177 * @id: Resource id to be released.
3179 void ti_sci_release_resource(struct ti_sci_resource
*res
, u16 id
)
3181 unsigned long flags
;
3184 raw_spin_lock_irqsave(&res
->lock
, flags
);
3185 for (set
= 0; set
< res
->sets
; set
++) {
3186 if (res
->desc
[set
].start
<= id
&&
3187 (res
->desc
[set
].num
+ res
->desc
[set
].start
) > id
)
3188 clear_bit(id
- res
->desc
[set
].start
,
3189 res
->desc
[set
].res_map
);
3191 raw_spin_unlock_irqrestore(&res
->lock
, flags
);
3193 EXPORT_SYMBOL_GPL(ti_sci_release_resource
);
3196 * ti_sci_get_num_resources() - Get the number of resources in TISCI resource
3197 * @res: Pointer to the TISCI resource
3199 * Return: Total number of available resources.
3201 u32
ti_sci_get_num_resources(struct ti_sci_resource
*res
)
3205 for (set
= 0; set
< res
->sets
; set
++)
3206 count
+= res
->desc
[set
].num
;
3210 EXPORT_SYMBOL_GPL(ti_sci_get_num_resources
);
3213 * devm_ti_sci_get_resource_sets() - Get a TISCI resources assigned to a device
3214 * @handle: TISCI handle
3215 * @dev: Device pointer to which the resource is assigned
3216 * @dev_id: TISCI device id to which the resource is assigned
3217 * @sub_types: Array of sub_types assigned corresponding to device
3218 * @sets: Number of sub_types
3220 * Return: Pointer to ti_sci_resource if all went well else appropriate
3223 static struct ti_sci_resource
*
3224 devm_ti_sci_get_resource_sets(const struct ti_sci_handle
*handle
,
3225 struct device
*dev
, u32 dev_id
, u32
*sub_types
,
3228 struct ti_sci_resource
*res
;
3229 bool valid_set
= false;
3232 res
= devm_kzalloc(dev
, sizeof(*res
), GFP_KERNEL
);
3234 return ERR_PTR(-ENOMEM
);
3237 res
->desc
= devm_kcalloc(dev
, res
->sets
, sizeof(*res
->desc
),
3240 return ERR_PTR(-ENOMEM
);
3242 for (i
= 0; i
< res
->sets
; i
++) {
3243 ret
= handle
->ops
.rm_core_ops
.get_range(handle
, dev_id
,
3245 &res
->desc
[i
].start
,
3248 dev_dbg(dev
, "dev = %d subtype %d not allocated for this host\n",
3249 dev_id
, sub_types
[i
]);
3250 res
->desc
[i
].start
= 0;
3251 res
->desc
[i
].num
= 0;
3255 dev_dbg(dev
, "dev = %d, subtype = %d, start = %d, num = %d\n",
3256 dev_id
, sub_types
[i
], res
->desc
[i
].start
,
3260 res
->desc
[i
].res_map
=
3261 devm_kzalloc(dev
, BITS_TO_LONGS(res
->desc
[i
].num
) *
3262 sizeof(*res
->desc
[i
].res_map
), GFP_KERNEL
);
3263 if (!res
->desc
[i
].res_map
)
3264 return ERR_PTR(-ENOMEM
);
3266 raw_spin_lock_init(&res
->lock
);
3271 return ERR_PTR(-EINVAL
);
3275 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3276 * @handle: TISCI handle
3277 * @dev: Device pointer to which the resource is assigned
3278 * @dev_id: TISCI device id to which the resource is assigned
3279 * @of_prop: property name by which the resource are represented
3281 * Return: Pointer to ti_sci_resource if all went well else appropriate
3284 struct ti_sci_resource
*
3285 devm_ti_sci_get_of_resource(const struct ti_sci_handle
*handle
,
3286 struct device
*dev
, u32 dev_id
, char *of_prop
)
3288 struct ti_sci_resource
*res
;
3292 sets
= of_property_count_elems_of_size(dev_of_node(dev
), of_prop
,
3295 dev_err(dev
, "%s resource type ids not available\n", of_prop
);
3296 return ERR_PTR(sets
);
3299 sub_types
= kcalloc(sets
, sizeof(*sub_types
), GFP_KERNEL
);
3301 return ERR_PTR(-ENOMEM
);
3303 of_property_read_u32_array(dev_of_node(dev
), of_prop
, sub_types
, sets
);
3304 res
= devm_ti_sci_get_resource_sets(handle
, dev
, dev_id
, sub_types
,
3310 EXPORT_SYMBOL_GPL(devm_ti_sci_get_of_resource
);
3313 * devm_ti_sci_get_resource() - Get a resource range assigned to the device
3314 * @handle: TISCI handle
3315 * @dev: Device pointer to which the resource is assigned
3316 * @dev_id: TISCI device id to which the resource is assigned
3317 * @suub_type: TISCI resource subytpe representing the resource.
3319 * Return: Pointer to ti_sci_resource if all went well else appropriate
3322 struct ti_sci_resource
*
3323 devm_ti_sci_get_resource(const struct ti_sci_handle
*handle
, struct device
*dev
,
3324 u32 dev_id
, u32 sub_type
)
3326 return devm_ti_sci_get_resource_sets(handle
, dev
, dev_id
, &sub_type
, 1);
3328 EXPORT_SYMBOL_GPL(devm_ti_sci_get_resource
);
3330 static int tisci_reboot_handler(struct notifier_block
*nb
, unsigned long mode
,
3333 struct ti_sci_info
*info
= reboot_to_ti_sci_info(nb
);
3334 const struct ti_sci_handle
*handle
= &info
->handle
;
3336 ti_sci_cmd_core_reboot(handle
);
3338 /* call fail OR pass, we should not be here in the first place */
3342 /* Description for K2G */
3343 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc
= {
3344 .default_host_id
= 2,
3345 /* Conservative duration */
3346 .max_rx_timeout_ms
= 1000,
3347 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3352 /* Description for AM654 */
3353 static const struct ti_sci_desc ti_sci_pmmc_am654_desc
= {
3354 .default_host_id
= 12,
3355 /* Conservative duration */
3356 .max_rx_timeout_ms
= 10000,
3357 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3362 static const struct of_device_id ti_sci_of_match
[] = {
3363 {.compatible
= "ti,k2g-sci", .data
= &ti_sci_pmmc_k2g_desc
},
3364 {.compatible
= "ti,am654-sci", .data
= &ti_sci_pmmc_am654_desc
},
3367 MODULE_DEVICE_TABLE(of
, ti_sci_of_match
);
3369 static int ti_sci_probe(struct platform_device
*pdev
)
3371 struct device
*dev
= &pdev
->dev
;
3372 const struct of_device_id
*of_id
;
3373 const struct ti_sci_desc
*desc
;
3374 struct ti_sci_xfer
*xfer
;
3375 struct ti_sci_info
*info
= NULL
;
3376 struct ti_sci_xfers_info
*minfo
;
3377 struct mbox_client
*cl
;
3383 of_id
= of_match_device(ti_sci_of_match
, dev
);
3385 dev_err(dev
, "OF data missing\n");
3390 info
= devm_kzalloc(dev
, sizeof(*info
), GFP_KERNEL
);
3396 ret
= of_property_read_u32(dev
->of_node
, "ti,host-id", &h_id
);
3397 /* if the property is not present in DT, use a default from desc */
3399 info
->host_id
= info
->desc
->default_host_id
;
3402 dev_warn(dev
, "Host ID 0 is reserved for firmware\n");
3403 info
->host_id
= info
->desc
->default_host_id
;
3405 info
->host_id
= h_id
;
3409 reboot
= of_property_read_bool(dev
->of_node
,
3410 "ti,system-reboot-controller");
3411 INIT_LIST_HEAD(&info
->node
);
3412 minfo
= &info
->minfo
;
3415 * Pre-allocate messages
3416 * NEVER allocate more than what we can indicate in hdr.seq
3417 * if we have data description bug, force a fix..
3419 if (WARN_ON(desc
->max_msgs
>=
3420 1 << 8 * sizeof(((struct ti_sci_msg_hdr
*)0)->seq
)))
3423 minfo
->xfer_block
= devm_kcalloc(dev
,
3425 sizeof(*minfo
->xfer_block
),
3427 if (!minfo
->xfer_block
)
3430 minfo
->xfer_alloc_table
= devm_kcalloc(dev
,
3431 BITS_TO_LONGS(desc
->max_msgs
),
3432 sizeof(unsigned long),
3434 if (!minfo
->xfer_alloc_table
)
3436 bitmap_zero(minfo
->xfer_alloc_table
, desc
->max_msgs
);
3438 /* Pre-initialize the buffer pointer to pre-allocated buffers */
3439 for (i
= 0, xfer
= minfo
->xfer_block
; i
< desc
->max_msgs
; i
++, xfer
++) {
3440 xfer
->xfer_buf
= devm_kcalloc(dev
, 1, desc
->max_msg_size
,
3442 if (!xfer
->xfer_buf
)
3445 xfer
->tx_message
.buf
= xfer
->xfer_buf
;
3446 init_completion(&xfer
->done
);
3449 ret
= ti_sci_debugfs_create(pdev
, info
);
3451 dev_warn(dev
, "Failed to create debug file\n");
3453 platform_set_drvdata(pdev
, info
);
3457 cl
->tx_block
= false;
3458 cl
->rx_callback
= ti_sci_rx_callback
;
3459 cl
->knows_txdone
= true;
3461 spin_lock_init(&minfo
->xfer_lock
);
3462 sema_init(&minfo
->sem_xfer_count
, desc
->max_msgs
);
3464 info
->chan_rx
= mbox_request_channel_byname(cl
, "rx");
3465 if (IS_ERR(info
->chan_rx
)) {
3466 ret
= PTR_ERR(info
->chan_rx
);
3470 info
->chan_tx
= mbox_request_channel_byname(cl
, "tx");
3471 if (IS_ERR(info
->chan_tx
)) {
3472 ret
= PTR_ERR(info
->chan_tx
);
3475 ret
= ti_sci_cmd_get_revision(info
);
3477 dev_err(dev
, "Unable to communicate with TISCI(%d)\n", ret
);
3481 ti_sci_setup_ops(info
);
3484 info
->nb
.notifier_call
= tisci_reboot_handler
;
3485 info
->nb
.priority
= 128;
3487 ret
= register_restart_handler(&info
->nb
);
3489 dev_err(dev
, "reboot registration fail(%d)\n", ret
);
3494 dev_info(dev
, "ABI: %d.%d (firmware rev 0x%04x '%s')\n",
3495 info
->handle
.version
.abi_major
, info
->handle
.version
.abi_minor
,
3496 info
->handle
.version
.firmware_revision
,
3497 info
->handle
.version
.firmware_description
);
3499 mutex_lock(&ti_sci_list_mutex
);
3500 list_add_tail(&info
->node
, &ti_sci_list
);
3501 mutex_unlock(&ti_sci_list_mutex
);
3503 return of_platform_populate(dev
->of_node
, NULL
, NULL
, dev
);
3505 if (!IS_ERR(info
->chan_tx
))
3506 mbox_free_channel(info
->chan_tx
);
3507 if (!IS_ERR(info
->chan_rx
))
3508 mbox_free_channel(info
->chan_rx
);
3509 debugfs_remove(info
->d
);
3513 static int ti_sci_remove(struct platform_device
*pdev
)
3515 struct ti_sci_info
*info
;
3516 struct device
*dev
= &pdev
->dev
;
3519 of_platform_depopulate(dev
);
3521 info
= platform_get_drvdata(pdev
);
3523 if (info
->nb
.notifier_call
)
3524 unregister_restart_handler(&info
->nb
);
3526 mutex_lock(&ti_sci_list_mutex
);
3530 list_del(&info
->node
);
3531 mutex_unlock(&ti_sci_list_mutex
);
3534 ti_sci_debugfs_destroy(pdev
, info
);
3536 /* Safe to free channels since no more users */
3537 mbox_free_channel(info
->chan_tx
);
3538 mbox_free_channel(info
->chan_rx
);
3544 static struct platform_driver ti_sci_driver
= {
3545 .probe
= ti_sci_probe
,
3546 .remove
= ti_sci_remove
,
3549 .of_match_table
= of_match_ptr(ti_sci_of_match
),
3552 module_platform_driver(ti_sci_driver
);
3554 MODULE_LICENSE("GPL v2");
3555 MODULE_DESCRIPTION("TI System Control Interface(SCI) driver");
3556 MODULE_AUTHOR("Nishanth Menon");
3557 MODULE_ALIAS("platform:ti-sci");