1 // SPDX-License-Identifier: GPL-2.0
3 * Texas Instruments System Control Interface Protocol Driver
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://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_rm_type_map - Structure representing TISCI Resource
69 * management representation of dev_ids.
70 * @dev_id: TISCI device ID
71 * @type: Corresponding id as identified by TISCI RM.
73 * Note: This is used only as a work around for using RM range apis
74 * for AM654 SoC. For future SoCs dev_id will be used as type
75 * for RM range APIs. In order to maintain ABI backward compatibility
76 * type is not being changed for AM654 SoC.
78 struct ti_sci_rm_type_map
{
84 * struct ti_sci_desc - Description of SoC integration
85 * @default_host_id: Host identifier representing the compute entity
86 * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
87 * @max_msgs: Maximum number of messages that can be pending
88 * simultaneously in the system
89 * @max_msg_size: Maximum size of data per message that can be handled.
90 * @rm_type_map: RM resource type mapping structure.
94 int max_rx_timeout_ms
;
97 struct ti_sci_rm_type_map
*rm_type_map
;
101 * struct ti_sci_info - Structure representing a TI SCI instance
102 * @dev: Device pointer
103 * @desc: SoC description for this instance
104 * @nb: Reboot Notifier block
105 * @d: Debugfs file entry
106 * @debug_region: Memory region where the debug message are available
107 * @debug_region_size: Debug region size
108 * @debug_buffer: Buffer allocated to copy debug messages.
109 * @handle: Instance of TI SCI handle to send to clients.
110 * @cl: Mailbox Client
111 * @chan_tx: Transmit mailbox channel
112 * @chan_rx: Receive mailbox channel
113 * @minfo: Message info
116 * @users: Number of users of this instance
120 struct notifier_block nb
;
121 const struct ti_sci_desc
*desc
;
123 void __iomem
*debug_region
;
125 size_t debug_region_size
;
126 struct ti_sci_handle handle
;
127 struct mbox_client cl
;
128 struct mbox_chan
*chan_tx
;
129 struct mbox_chan
*chan_rx
;
130 struct ti_sci_xfers_info minfo
;
131 struct list_head node
;
133 /* protected by ti_sci_list_mutex */
138 #define cl_to_ti_sci_info(c) container_of(c, struct ti_sci_info, cl)
139 #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle)
140 #define reboot_to_ti_sci_info(n) container_of(n, struct ti_sci_info, nb)
142 #ifdef CONFIG_DEBUG_FS
145 * ti_sci_debug_show() - Helper to dump the debug log
146 * @s: sequence file pointer
151 static int ti_sci_debug_show(struct seq_file
*s
, void *unused
)
153 struct ti_sci_info
*info
= s
->private;
155 memcpy_fromio(info
->debug_buffer
, info
->debug_region
,
156 info
->debug_region_size
);
158 * We don't trust firmware to leave NULL terminated last byte (hence
159 * we have allocated 1 extra 0 byte). Since we cannot guarantee any
160 * specific data format for debug messages, We just present the data
161 * in the buffer as is - we expect the messages to be self explanatory.
163 seq_puts(s
, info
->debug_buffer
);
167 /* Provide the log file operations interface*/
168 DEFINE_SHOW_ATTRIBUTE(ti_sci_debug
);
171 * ti_sci_debugfs_create() - Create log debug file
172 * @pdev: platform device pointer
173 * @info: Pointer to SCI entity information
175 * Return: 0 if all went fine, else corresponding error.
177 static int ti_sci_debugfs_create(struct platform_device
*pdev
,
178 struct ti_sci_info
*info
)
180 struct device
*dev
= &pdev
->dev
;
181 struct resource
*res
;
182 char debug_name
[50] = "ti_sci_debug@";
184 /* Debug region is optional */
185 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
187 info
->debug_region
= devm_ioremap_resource(dev
, res
);
188 if (IS_ERR(info
->debug_region
))
190 info
->debug_region_size
= resource_size(res
);
192 info
->debug_buffer
= devm_kcalloc(dev
, info
->debug_region_size
+ 1,
193 sizeof(char), GFP_KERNEL
);
194 if (!info
->debug_buffer
)
196 /* Setup NULL termination */
197 info
->debug_buffer
[info
->debug_region_size
] = 0;
199 info
->d
= debugfs_create_file(strncat(debug_name
, dev_name(dev
),
201 sizeof("ti_sci_debug@")),
202 0444, NULL
, info
, &ti_sci_debug_fops
);
204 return PTR_ERR(info
->d
);
206 dev_dbg(dev
, "Debug region => %p, size = %zu bytes, resource: %pr\n",
207 info
->debug_region
, info
->debug_region_size
, res
);
212 * ti_sci_debugfs_destroy() - clean up log debug file
213 * @pdev: platform device pointer
214 * @info: Pointer to SCI entity information
216 static void ti_sci_debugfs_destroy(struct platform_device
*pdev
,
217 struct ti_sci_info
*info
)
219 if (IS_ERR(info
->debug_region
))
222 debugfs_remove(info
->d
);
224 #else /* CONFIG_DEBUG_FS */
225 static inline int ti_sci_debugfs_create(struct platform_device
*dev
,
226 struct ti_sci_info
*info
)
231 static inline void ti_sci_debugfs_destroy(struct platform_device
*dev
,
232 struct ti_sci_info
*info
)
235 #endif /* CONFIG_DEBUG_FS */
238 * ti_sci_dump_header_dbg() - Helper to dump a message header.
239 * @dev: Device pointer corresponding to the SCI entity
240 * @hdr: pointer to header.
242 static inline void ti_sci_dump_header_dbg(struct device
*dev
,
243 struct ti_sci_msg_hdr
*hdr
)
245 dev_dbg(dev
, "MSGHDR:type=0x%04x host=0x%02x seq=0x%02x flags=0x%08x\n",
246 hdr
->type
, hdr
->host
, hdr
->seq
, hdr
->flags
);
250 * ti_sci_rx_callback() - mailbox client callback for receive messages
251 * @cl: client pointer
252 * @m: mailbox message
254 * Processes one received message to appropriate transfer information and
255 * signals completion of the transfer.
257 * NOTE: This function will be invoked in IRQ context, hence should be
258 * as optimal as possible.
260 static void ti_sci_rx_callback(struct mbox_client
*cl
, void *m
)
262 struct ti_sci_info
*info
= cl_to_ti_sci_info(cl
);
263 struct device
*dev
= info
->dev
;
264 struct ti_sci_xfers_info
*minfo
= &info
->minfo
;
265 struct ti_msgmgr_message
*mbox_msg
= m
;
266 struct ti_sci_msg_hdr
*hdr
= (struct ti_sci_msg_hdr
*)mbox_msg
->buf
;
267 struct ti_sci_xfer
*xfer
;
273 * Are we even expecting this?
274 * NOTE: barriers were implicit in locks used for modifying the bitmap
276 if (!test_bit(xfer_id
, minfo
->xfer_alloc_table
)) {
277 dev_err(dev
, "Message for %d is not expected!\n", xfer_id
);
281 xfer
= &minfo
->xfer_block
[xfer_id
];
283 /* Is the message of valid length? */
284 if (mbox_msg
->len
> info
->desc
->max_msg_size
) {
285 dev_err(dev
, "Unable to handle %zu xfer(max %d)\n",
286 mbox_msg
->len
, info
->desc
->max_msg_size
);
287 ti_sci_dump_header_dbg(dev
, hdr
);
290 if (mbox_msg
->len
< xfer
->rx_len
) {
291 dev_err(dev
, "Recv xfer %zu < expected %d length\n",
292 mbox_msg
->len
, xfer
->rx_len
);
293 ti_sci_dump_header_dbg(dev
, hdr
);
297 ti_sci_dump_header_dbg(dev
, hdr
);
298 /* Take a copy to the rx buffer.. */
299 memcpy(xfer
->xfer_buf
, mbox_msg
->buf
, xfer
->rx_len
);
300 complete(&xfer
->done
);
304 * ti_sci_get_one_xfer() - Allocate one message
305 * @info: Pointer to SCI entity information
306 * @msg_type: Message type
307 * @msg_flags: Flag to set for the message
308 * @tx_message_size: transmit message size
309 * @rx_message_size: receive message size
311 * Helper function which is used by various command functions that are
312 * exposed to clients of this driver for allocating a message traffic event.
314 * This function can sleep depending on pending requests already in the system
315 * for the SCI entity. Further, this also holds a spinlock to maintain integrity
316 * of internal data structures.
318 * Return: 0 if all went fine, else corresponding error.
320 static struct ti_sci_xfer
*ti_sci_get_one_xfer(struct ti_sci_info
*info
,
321 u16 msg_type
, u32 msg_flags
,
322 size_t tx_message_size
,
323 size_t rx_message_size
)
325 struct ti_sci_xfers_info
*minfo
= &info
->minfo
;
326 struct ti_sci_xfer
*xfer
;
327 struct ti_sci_msg_hdr
*hdr
;
329 unsigned long bit_pos
;
334 /* Ensure we have sane transfer sizes */
335 if (rx_message_size
> info
->desc
->max_msg_size
||
336 tx_message_size
> info
->desc
->max_msg_size
||
337 rx_message_size
< sizeof(*hdr
) || tx_message_size
< sizeof(*hdr
))
338 return ERR_PTR(-ERANGE
);
341 * Ensure we have only controlled number of pending messages.
342 * Ideally, we might just have to wait a single message, be
343 * conservative and wait 5 times that..
345 timeout
= msecs_to_jiffies(info
->desc
->max_rx_timeout_ms
) * 5;
346 ret
= down_timeout(&minfo
->sem_xfer_count
, timeout
);
350 /* Keep the locked section as small as possible */
351 spin_lock_irqsave(&minfo
->xfer_lock
, flags
);
352 bit_pos
= find_first_zero_bit(minfo
->xfer_alloc_table
,
353 info
->desc
->max_msgs
);
354 set_bit(bit_pos
, minfo
->xfer_alloc_table
);
355 spin_unlock_irqrestore(&minfo
->xfer_lock
, flags
);
358 * We already ensured in probe that we can have max messages that can
359 * fit in hdr.seq - NOTE: this improves access latencies
360 * to predictable O(1) access, BUT, it opens us to risk if
361 * remote misbehaves with corrupted message sequence responses.
362 * If that happens, we are going to be messed up anyways..
364 xfer_id
= (u8
)bit_pos
;
366 xfer
= &minfo
->xfer_block
[xfer_id
];
368 hdr
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
369 xfer
->tx_message
.len
= tx_message_size
;
370 xfer
->rx_len
= (u8
)rx_message_size
;
372 reinit_completion(&xfer
->done
);
375 hdr
->type
= msg_type
;
376 hdr
->host
= info
->host_id
;
377 hdr
->flags
= msg_flags
;
383 * ti_sci_put_one_xfer() - Release a message
384 * @minfo: transfer info pointer
385 * @xfer: message that was reserved by ti_sci_get_one_xfer
387 * This holds a spinlock to maintain integrity of internal data structures.
389 static void ti_sci_put_one_xfer(struct ti_sci_xfers_info
*minfo
,
390 struct ti_sci_xfer
*xfer
)
393 struct ti_sci_msg_hdr
*hdr
;
396 hdr
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
400 * Keep the locked section as small as possible
401 * NOTE: we might escape with smp_mb and no lock here..
402 * but just be conservative and symmetric.
404 spin_lock_irqsave(&minfo
->xfer_lock
, flags
);
405 clear_bit(xfer_id
, minfo
->xfer_alloc_table
);
406 spin_unlock_irqrestore(&minfo
->xfer_lock
, flags
);
408 /* Increment the count for the next user to get through */
409 up(&minfo
->sem_xfer_count
);
413 * ti_sci_do_xfer() - Do one transfer
414 * @info: Pointer to SCI entity information
415 * @xfer: Transfer to initiate and wait for response
417 * Return: -ETIMEDOUT in case of no response, if transmit error,
418 * return corresponding error, else if all goes well,
421 static inline int ti_sci_do_xfer(struct ti_sci_info
*info
,
422 struct ti_sci_xfer
*xfer
)
426 struct device
*dev
= info
->dev
;
428 ret
= mbox_send_message(info
->chan_tx
, &xfer
->tx_message
);
434 /* And we wait for the response. */
435 timeout
= msecs_to_jiffies(info
->desc
->max_rx_timeout_ms
);
436 if (!wait_for_completion_timeout(&xfer
->done
, timeout
)) {
437 dev_err(dev
, "Mbox timedout in resp(caller: %pS)\n",
442 * NOTE: we might prefer not to need the mailbox ticker to manage the
443 * transfer queueing since the protocol layer queues things by itself.
444 * Unfortunately, we have to kick the mailbox framework after we have
445 * received our message.
447 mbox_client_txdone(info
->chan_tx
, ret
);
453 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
454 * @info: Pointer to SCI entity information
456 * Updates the SCI information in the internal data structure.
458 * Return: 0 if all went fine, else return appropriate error.
460 static int ti_sci_cmd_get_revision(struct ti_sci_info
*info
)
462 struct device
*dev
= info
->dev
;
463 struct ti_sci_handle
*handle
= &info
->handle
;
464 struct ti_sci_version_info
*ver
= &handle
->version
;
465 struct ti_sci_msg_resp_version
*rev_info
;
466 struct ti_sci_xfer
*xfer
;
469 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_VERSION
,
470 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
471 sizeof(struct ti_sci_msg_hdr
),
475 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
479 rev_info
= (struct ti_sci_msg_resp_version
*)xfer
->xfer_buf
;
481 ret
= ti_sci_do_xfer(info
, xfer
);
483 dev_err(dev
, "Mbox send fail %d\n", ret
);
487 ver
->abi_major
= rev_info
->abi_major
;
488 ver
->abi_minor
= rev_info
->abi_minor
;
489 ver
->firmware_revision
= rev_info
->firmware_revision
;
490 strncpy(ver
->firmware_description
, rev_info
->firmware_description
,
491 sizeof(ver
->firmware_description
));
494 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
499 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
500 * @r: pointer to response buffer
502 * Return: true if the response was an ACK, else returns false.
504 static inline bool ti_sci_is_response_ack(void *r
)
506 struct ti_sci_msg_hdr
*hdr
= r
;
508 return hdr
->flags
& TI_SCI_FLAG_RESP_GENERIC_ACK
? true : false;
512 * ti_sci_set_device_state() - Set device state helper
513 * @handle: pointer to TI SCI handle
514 * @id: Device identifier
515 * @flags: flags to setup for the device
516 * @state: State to move the device to
518 * Return: 0 if all went well, else returns appropriate error value.
520 static int ti_sci_set_device_state(const struct ti_sci_handle
*handle
,
521 u32 id
, u32 flags
, u8 state
)
523 struct ti_sci_info
*info
;
524 struct ti_sci_msg_req_set_device_state
*req
;
525 struct ti_sci_msg_hdr
*resp
;
526 struct ti_sci_xfer
*xfer
;
531 return PTR_ERR(handle
);
535 info
= handle_to_ti_sci_info(handle
);
538 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_DEVICE_STATE
,
539 flags
| TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
540 sizeof(*req
), sizeof(*resp
));
543 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
546 req
= (struct ti_sci_msg_req_set_device_state
*)xfer
->xfer_buf
;
550 ret
= ti_sci_do_xfer(info
, xfer
);
552 dev_err(dev
, "Mbox send fail %d\n", ret
);
556 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
558 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
561 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
567 * ti_sci_get_device_state() - Get device state helper
568 * @handle: Handle to the device
569 * @id: Device Identifier
570 * @clcnt: Pointer to Context Loss Count
571 * @resets: pointer to resets
572 * @p_state: pointer to p_state
573 * @c_state: pointer to c_state
575 * Return: 0 if all went fine, else return appropriate error.
577 static int ti_sci_get_device_state(const struct ti_sci_handle
*handle
,
578 u32 id
, u32
*clcnt
, u32
*resets
,
579 u8
*p_state
, u8
*c_state
)
581 struct ti_sci_info
*info
;
582 struct ti_sci_msg_req_get_device_state
*req
;
583 struct ti_sci_msg_resp_get_device_state
*resp
;
584 struct ti_sci_xfer
*xfer
;
589 return PTR_ERR(handle
);
593 if (!clcnt
&& !resets
&& !p_state
&& !c_state
)
596 info
= handle_to_ti_sci_info(handle
);
599 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_DEVICE_STATE
,
600 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
601 sizeof(*req
), sizeof(*resp
));
604 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
607 req
= (struct ti_sci_msg_req_get_device_state
*)xfer
->xfer_buf
;
610 ret
= ti_sci_do_xfer(info
, xfer
);
612 dev_err(dev
, "Mbox send fail %d\n", ret
);
616 resp
= (struct ti_sci_msg_resp_get_device_state
*)xfer
->xfer_buf
;
617 if (!ti_sci_is_response_ack(resp
)) {
623 *clcnt
= resp
->context_loss_count
;
625 *resets
= resp
->resets
;
627 *p_state
= resp
->programmed_state
;
629 *c_state
= resp
->current_state
;
631 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
637 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
638 * that can be shared with other hosts.
639 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
640 * @id: Device Identifier
642 * Request for the device - NOTE: the client MUST maintain integrity of
643 * usage count by balancing get_device with put_device. No refcounting is
644 * managed by driver for that purpose.
646 * Return: 0 if all went fine, else return appropriate error.
648 static int ti_sci_cmd_get_device(const struct ti_sci_handle
*handle
, u32 id
)
650 return ti_sci_set_device_state(handle
, id
, 0,
651 MSG_DEVICE_SW_STATE_ON
);
655 * ti_sci_cmd_get_device_exclusive() - command to request for device managed by
656 * TISCI that is exclusively owned by the
658 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
659 * @id: Device Identifier
661 * Request for the device - NOTE: the client MUST maintain integrity of
662 * usage count by balancing get_device with put_device. No refcounting is
663 * managed by driver for that purpose.
665 * Return: 0 if all went fine, else return appropriate error.
667 static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle
*handle
,
670 return ti_sci_set_device_state(handle
, id
,
671 MSG_FLAG_DEVICE_EXCLUSIVE
,
672 MSG_DEVICE_SW_STATE_ON
);
676 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
677 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
678 * @id: Device Identifier
680 * Request for the device - NOTE: the client MUST maintain integrity of
681 * usage count by balancing get_device with put_device. No refcounting is
682 * managed by driver for that purpose.
684 * Return: 0 if all went fine, else return appropriate error.
686 static int ti_sci_cmd_idle_device(const struct ti_sci_handle
*handle
, u32 id
)
688 return ti_sci_set_device_state(handle
, id
, 0,
689 MSG_DEVICE_SW_STATE_RETENTION
);
693 * ti_sci_cmd_idle_device_exclusive() - Command to idle a device managed by
694 * TISCI that is exclusively owned by
696 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
697 * @id: Device Identifier
699 * Request for the device - NOTE: the client MUST maintain integrity of
700 * usage count by balancing get_device with put_device. No refcounting is
701 * managed by driver for that purpose.
703 * Return: 0 if all went fine, else return appropriate error.
705 static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle
*handle
,
708 return ti_sci_set_device_state(handle
, id
,
709 MSG_FLAG_DEVICE_EXCLUSIVE
,
710 MSG_DEVICE_SW_STATE_RETENTION
);
714 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
715 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
716 * @id: Device Identifier
718 * Request for the device - NOTE: the client MUST maintain integrity of
719 * usage count by balancing get_device with put_device. No refcounting is
720 * managed by driver for that purpose.
722 * Return: 0 if all went fine, else return appropriate error.
724 static int ti_sci_cmd_put_device(const struct ti_sci_handle
*handle
, u32 id
)
726 return ti_sci_set_device_state(handle
, id
,
727 0, MSG_DEVICE_SW_STATE_AUTO_OFF
);
731 * ti_sci_cmd_dev_is_valid() - Is the device valid
732 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
733 * @id: Device Identifier
735 * Return: 0 if all went fine and the device ID is valid, else return
738 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle
*handle
, u32 id
)
742 /* check the device state which will also tell us if the ID is valid */
743 return ti_sci_get_device_state(handle
, id
, NULL
, NULL
, NULL
, &unused
);
747 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
748 * @handle: Pointer to TISCI handle
749 * @id: Device Identifier
750 * @count: Pointer to Context Loss counter to populate
752 * Return: 0 if all went fine, else return appropriate error.
754 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle
*handle
, u32 id
,
757 return ti_sci_get_device_state(handle
, id
, count
, NULL
, NULL
, NULL
);
761 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
762 * @handle: Pointer to TISCI handle
763 * @id: Device Identifier
764 * @r_state: true if requested to be idle
766 * Return: 0 if all went fine, else return appropriate error.
768 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle
*handle
, u32 id
,
777 ret
= ti_sci_get_device_state(handle
, id
, NULL
, NULL
, &state
, NULL
);
781 *r_state
= (state
== MSG_DEVICE_SW_STATE_RETENTION
);
787 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
788 * @handle: Pointer to TISCI handle
789 * @id: Device Identifier
790 * @r_state: true if requested to be stopped
791 * @curr_state: true if currently stopped.
793 * Return: 0 if all went fine, else return appropriate error.
795 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle
*handle
, u32 id
,
796 bool *r_state
, bool *curr_state
)
801 if (!r_state
&& !curr_state
)
805 ti_sci_get_device_state(handle
, id
, NULL
, NULL
, &p_state
, &c_state
);
810 *r_state
= (p_state
== MSG_DEVICE_SW_STATE_AUTO_OFF
);
812 *curr_state
= (c_state
== MSG_DEVICE_HW_STATE_OFF
);
818 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
819 * @handle: Pointer to TISCI handle
820 * @id: Device Identifier
821 * @r_state: true if requested to be ON
822 * @curr_state: true if currently ON and active
824 * Return: 0 if all went fine, else return appropriate error.
826 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle
*handle
, u32 id
,
827 bool *r_state
, bool *curr_state
)
832 if (!r_state
&& !curr_state
)
836 ti_sci_get_device_state(handle
, id
, NULL
, NULL
, &p_state
, &c_state
);
841 *r_state
= (p_state
== MSG_DEVICE_SW_STATE_ON
);
843 *curr_state
= (c_state
== MSG_DEVICE_HW_STATE_ON
);
849 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
850 * @handle: Pointer to TISCI handle
851 * @id: Device Identifier
852 * @curr_state: true if currently transitioning.
854 * Return: 0 if all went fine, else return appropriate error.
856 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle
*handle
, u32 id
,
865 ret
= ti_sci_get_device_state(handle
, id
, NULL
, NULL
, NULL
, &state
);
869 *curr_state
= (state
== MSG_DEVICE_HW_STATE_TRANS
);
875 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
877 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
878 * @id: Device Identifier
879 * @reset_state: Device specific reset bit field
881 * Return: 0 if all went fine, else return appropriate error.
883 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle
*handle
,
884 u32 id
, u32 reset_state
)
886 struct ti_sci_info
*info
;
887 struct ti_sci_msg_req_set_device_resets
*req
;
888 struct ti_sci_msg_hdr
*resp
;
889 struct ti_sci_xfer
*xfer
;
894 return PTR_ERR(handle
);
898 info
= handle_to_ti_sci_info(handle
);
901 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_DEVICE_RESETS
,
902 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
903 sizeof(*req
), sizeof(*resp
));
906 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
909 req
= (struct ti_sci_msg_req_set_device_resets
*)xfer
->xfer_buf
;
911 req
->resets
= reset_state
;
913 ret
= ti_sci_do_xfer(info
, xfer
);
915 dev_err(dev
, "Mbox send fail %d\n", ret
);
919 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
921 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
924 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
930 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
932 * @handle: Pointer to TISCI handle
933 * @id: Device Identifier
934 * @reset_state: Pointer to reset state to populate
936 * Return: 0 if all went fine, else return appropriate error.
938 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle
*handle
,
939 u32 id
, u32
*reset_state
)
941 return ti_sci_get_device_state(handle
, id
, NULL
, reset_state
, NULL
,
946 * ti_sci_set_clock_state() - Set clock state helper
947 * @handle: pointer to TI SCI handle
948 * @dev_id: Device identifier this request is for
949 * @clk_id: Clock identifier for the device for this request.
950 * Each device has it's own set of clock inputs. This indexes
951 * which clock input to modify.
952 * @flags: Header flags as needed
953 * @state: State to request for the clock.
955 * Return: 0 if all went well, else returns appropriate error value.
957 static int ti_sci_set_clock_state(const struct ti_sci_handle
*handle
,
958 u32 dev_id
, u32 clk_id
,
961 struct ti_sci_info
*info
;
962 struct ti_sci_msg_req_set_clock_state
*req
;
963 struct ti_sci_msg_hdr
*resp
;
964 struct ti_sci_xfer
*xfer
;
969 return PTR_ERR(handle
);
973 info
= handle_to_ti_sci_info(handle
);
976 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CLOCK_STATE
,
977 flags
| TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
978 sizeof(*req
), sizeof(*resp
));
981 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
984 req
= (struct ti_sci_msg_req_set_clock_state
*)xfer
->xfer_buf
;
985 req
->dev_id
= dev_id
;
987 req
->clk_id
= clk_id
;
990 req
->clk_id_32
= clk_id
;
992 req
->request_state
= state
;
994 ret
= ti_sci_do_xfer(info
, xfer
);
996 dev_err(dev
, "Mbox send fail %d\n", ret
);
1000 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1002 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1005 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1011 * ti_sci_cmd_get_clock_state() - Get clock state helper
1012 * @handle: pointer to TI SCI handle
1013 * @dev_id: Device identifier this request is for
1014 * @clk_id: Clock identifier for the device for this request.
1015 * Each device has it's own set of clock inputs. This indexes
1016 * which clock input to modify.
1017 * @programmed_state: State requested for clock to move to
1018 * @current_state: State that the clock is currently in
1020 * Return: 0 if all went well, else returns appropriate error value.
1022 static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle
*handle
,
1023 u32 dev_id
, u32 clk_id
,
1024 u8
*programmed_state
, u8
*current_state
)
1026 struct ti_sci_info
*info
;
1027 struct ti_sci_msg_req_get_clock_state
*req
;
1028 struct ti_sci_msg_resp_get_clock_state
*resp
;
1029 struct ti_sci_xfer
*xfer
;
1034 return PTR_ERR(handle
);
1038 if (!programmed_state
&& !current_state
)
1041 info
= handle_to_ti_sci_info(handle
);
1044 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_CLOCK_STATE
,
1045 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1046 sizeof(*req
), sizeof(*resp
));
1048 ret
= PTR_ERR(xfer
);
1049 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1052 req
= (struct ti_sci_msg_req_get_clock_state
*)xfer
->xfer_buf
;
1053 req
->dev_id
= dev_id
;
1055 req
->clk_id
= clk_id
;
1058 req
->clk_id_32
= clk_id
;
1061 ret
= ti_sci_do_xfer(info
, xfer
);
1063 dev_err(dev
, "Mbox send fail %d\n", ret
);
1067 resp
= (struct ti_sci_msg_resp_get_clock_state
*)xfer
->xfer_buf
;
1069 if (!ti_sci_is_response_ack(resp
)) {
1074 if (programmed_state
)
1075 *programmed_state
= resp
->programmed_state
;
1077 *current_state
= resp
->current_state
;
1080 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1086 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
1087 * @handle: pointer to TI SCI handle
1088 * @dev_id: Device identifier this request is for
1089 * @clk_id: Clock identifier for the device for this request.
1090 * Each device has it's own set of clock inputs. This indexes
1091 * which clock input to modify.
1092 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
1093 * @can_change_freq: 'true' if frequency change is desired, else 'false'
1094 * @enable_input_term: 'true' if input termination is desired, else 'false'
1096 * Return: 0 if all went well, else returns appropriate error value.
1098 static int ti_sci_cmd_get_clock(const struct ti_sci_handle
*handle
, u32 dev_id
,
1099 u32 clk_id
, bool needs_ssc
,
1100 bool can_change_freq
, bool enable_input_term
)
1104 flags
|= needs_ssc
? MSG_FLAG_CLOCK_ALLOW_SSC
: 0;
1105 flags
|= can_change_freq
? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE
: 0;
1106 flags
|= enable_input_term
? MSG_FLAG_CLOCK_INPUT_TERM
: 0;
1108 return ti_sci_set_clock_state(handle
, dev_id
, clk_id
, flags
,
1109 MSG_CLOCK_SW_STATE_REQ
);
1113 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
1114 * @handle: pointer to TI SCI handle
1115 * @dev_id: Device identifier this request is for
1116 * @clk_id: Clock identifier for the device for this request.
1117 * Each device has it's own set of clock inputs. This indexes
1118 * which clock input to modify.
1120 * NOTE: This clock must have been requested by get_clock previously.
1122 * Return: 0 if all went well, else returns appropriate error value.
1124 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle
*handle
,
1125 u32 dev_id
, u32 clk_id
)
1127 return ti_sci_set_clock_state(handle
, dev_id
, clk_id
, 0,
1128 MSG_CLOCK_SW_STATE_UNREQ
);
1132 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
1133 * @handle: pointer to TI SCI handle
1134 * @dev_id: Device identifier this request is for
1135 * @clk_id: Clock identifier for the device for this request.
1136 * Each device has it's own set of clock inputs. This indexes
1137 * which clock input to modify.
1139 * NOTE: This clock must have been requested by get_clock previously.
1141 * Return: 0 if all went well, else returns appropriate error value.
1143 static int ti_sci_cmd_put_clock(const struct ti_sci_handle
*handle
,
1144 u32 dev_id
, u32 clk_id
)
1146 return ti_sci_set_clock_state(handle
, dev_id
, clk_id
, 0,
1147 MSG_CLOCK_SW_STATE_AUTO
);
1151 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
1152 * @handle: pointer to TI SCI handle
1153 * @dev_id: Device identifier this request is for
1154 * @clk_id: Clock identifier for the device for this request.
1155 * Each device has it's own set of clock inputs. This indexes
1156 * which clock input to modify.
1157 * @req_state: state indicating if the clock is auto managed
1159 * Return: 0 if all went well, else returns appropriate error value.
1161 static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle
*handle
,
1162 u32 dev_id
, u32 clk_id
, bool *req_state
)
1170 ret
= ti_sci_cmd_get_clock_state(handle
, dev_id
, clk_id
, &state
, NULL
);
1174 *req_state
= (state
== MSG_CLOCK_SW_STATE_AUTO
);
1179 * ti_sci_cmd_clk_is_on() - Is the clock ON
1180 * @handle: pointer to TI SCI handle
1181 * @dev_id: Device identifier this request is for
1182 * @clk_id: Clock identifier for the device for this request.
1183 * Each device has it's own set of clock inputs. This indexes
1184 * which clock input to modify.
1185 * @req_state: state indicating if the clock is managed by us and enabled
1186 * @curr_state: state indicating if the clock is ready for operation
1188 * Return: 0 if all went well, else returns appropriate error value.
1190 static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle
*handle
, u32 dev_id
,
1191 u32 clk_id
, bool *req_state
, bool *curr_state
)
1193 u8 c_state
= 0, r_state
= 0;
1196 if (!req_state
&& !curr_state
)
1199 ret
= ti_sci_cmd_get_clock_state(handle
, dev_id
, clk_id
,
1200 &r_state
, &c_state
);
1205 *req_state
= (r_state
== MSG_CLOCK_SW_STATE_REQ
);
1207 *curr_state
= (c_state
== MSG_CLOCK_HW_STATE_READY
);
1212 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1213 * @handle: pointer to TI SCI handle
1214 * @dev_id: Device identifier this request is for
1215 * @clk_id: Clock identifier for the device for this request.
1216 * Each device has it's own set of clock inputs. This indexes
1217 * which clock input to modify.
1218 * @req_state: state indicating if the clock is managed by us and disabled
1219 * @curr_state: state indicating if the clock is NOT ready for operation
1221 * Return: 0 if all went well, else returns appropriate error value.
1223 static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle
*handle
, u32 dev_id
,
1224 u32 clk_id
, bool *req_state
, bool *curr_state
)
1226 u8 c_state
= 0, r_state
= 0;
1229 if (!req_state
&& !curr_state
)
1232 ret
= ti_sci_cmd_get_clock_state(handle
, dev_id
, clk_id
,
1233 &r_state
, &c_state
);
1238 *req_state
= (r_state
== MSG_CLOCK_SW_STATE_UNREQ
);
1240 *curr_state
= (c_state
== MSG_CLOCK_HW_STATE_NOT_READY
);
1245 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1246 * @handle: pointer to TI SCI handle
1247 * @dev_id: Device identifier this request is for
1248 * @clk_id: Clock identifier for the device for this request.
1249 * Each device has it's own set of clock inputs. This indexes
1250 * which clock input to modify.
1251 * @parent_id: Parent clock identifier to set
1253 * Return: 0 if all went well, else returns appropriate error value.
1255 static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle
*handle
,
1256 u32 dev_id
, u32 clk_id
, u32 parent_id
)
1258 struct ti_sci_info
*info
;
1259 struct ti_sci_msg_req_set_clock_parent
*req
;
1260 struct ti_sci_msg_hdr
*resp
;
1261 struct ti_sci_xfer
*xfer
;
1266 return PTR_ERR(handle
);
1270 info
= handle_to_ti_sci_info(handle
);
1273 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CLOCK_PARENT
,
1274 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1275 sizeof(*req
), sizeof(*resp
));
1277 ret
= PTR_ERR(xfer
);
1278 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1281 req
= (struct ti_sci_msg_req_set_clock_parent
*)xfer
->xfer_buf
;
1282 req
->dev_id
= dev_id
;
1284 req
->clk_id
= clk_id
;
1287 req
->clk_id_32
= clk_id
;
1289 if (parent_id
< 255) {
1290 req
->parent_id
= parent_id
;
1292 req
->parent_id
= 255;
1293 req
->parent_id_32
= parent_id
;
1296 ret
= ti_sci_do_xfer(info
, xfer
);
1298 dev_err(dev
, "Mbox send fail %d\n", ret
);
1302 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1304 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1307 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1313 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1314 * @handle: pointer to TI SCI handle
1315 * @dev_id: Device identifier this request is for
1316 * @clk_id: Clock identifier for the device for this request.
1317 * Each device has it's own set of clock inputs. This indexes
1318 * which clock input to modify.
1319 * @parent_id: Current clock parent
1321 * Return: 0 if all went well, else returns appropriate error value.
1323 static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle
*handle
,
1324 u32 dev_id
, u32 clk_id
, u32
*parent_id
)
1326 struct ti_sci_info
*info
;
1327 struct ti_sci_msg_req_get_clock_parent
*req
;
1328 struct ti_sci_msg_resp_get_clock_parent
*resp
;
1329 struct ti_sci_xfer
*xfer
;
1334 return PTR_ERR(handle
);
1335 if (!handle
|| !parent_id
)
1338 info
= handle_to_ti_sci_info(handle
);
1341 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_CLOCK_PARENT
,
1342 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1343 sizeof(*req
), sizeof(*resp
));
1345 ret
= PTR_ERR(xfer
);
1346 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1349 req
= (struct ti_sci_msg_req_get_clock_parent
*)xfer
->xfer_buf
;
1350 req
->dev_id
= dev_id
;
1352 req
->clk_id
= clk_id
;
1355 req
->clk_id_32
= clk_id
;
1358 ret
= ti_sci_do_xfer(info
, xfer
);
1360 dev_err(dev
, "Mbox send fail %d\n", ret
);
1364 resp
= (struct ti_sci_msg_resp_get_clock_parent
*)xfer
->xfer_buf
;
1366 if (!ti_sci_is_response_ack(resp
)) {
1369 if (resp
->parent_id
< 255)
1370 *parent_id
= resp
->parent_id
;
1372 *parent_id
= resp
->parent_id_32
;
1376 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1382 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1383 * @handle: pointer to TI SCI handle
1384 * @dev_id: Device identifier this request is for
1385 * @clk_id: Clock identifier for the device for this request.
1386 * Each device has it's own set of clock inputs. This indexes
1387 * which clock input to modify.
1388 * @num_parents: Returns he number of parents to the current clock.
1390 * Return: 0 if all went well, else returns appropriate error value.
1392 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle
*handle
,
1393 u32 dev_id
, u32 clk_id
,
1396 struct ti_sci_info
*info
;
1397 struct ti_sci_msg_req_get_clock_num_parents
*req
;
1398 struct ti_sci_msg_resp_get_clock_num_parents
*resp
;
1399 struct ti_sci_xfer
*xfer
;
1404 return PTR_ERR(handle
);
1405 if (!handle
|| !num_parents
)
1408 info
= handle_to_ti_sci_info(handle
);
1411 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS
,
1412 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1413 sizeof(*req
), sizeof(*resp
));
1415 ret
= PTR_ERR(xfer
);
1416 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1419 req
= (struct ti_sci_msg_req_get_clock_num_parents
*)xfer
->xfer_buf
;
1420 req
->dev_id
= dev_id
;
1422 req
->clk_id
= clk_id
;
1425 req
->clk_id_32
= clk_id
;
1428 ret
= ti_sci_do_xfer(info
, xfer
);
1430 dev_err(dev
, "Mbox send fail %d\n", ret
);
1434 resp
= (struct ti_sci_msg_resp_get_clock_num_parents
*)xfer
->xfer_buf
;
1436 if (!ti_sci_is_response_ack(resp
)) {
1439 if (resp
->num_parents
< 255)
1440 *num_parents
= resp
->num_parents
;
1442 *num_parents
= resp
->num_parents_32
;
1446 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1452 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1453 * @handle: pointer to TI SCI handle
1454 * @dev_id: Device identifier this request is for
1455 * @clk_id: Clock identifier for the device for this request.
1456 * Each device has it's own set of clock inputs. This indexes
1457 * which clock input to modify.
1458 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1459 * allowable programmed frequency and does not account for clock
1460 * tolerances and jitter.
1461 * @target_freq: The target clock frequency in Hz. A frequency will be
1462 * processed as close to this target frequency as possible.
1463 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1464 * allowable programmed frequency and does not account for clock
1465 * tolerances and jitter.
1466 * @match_freq: Frequency match in Hz response.
1468 * Return: 0 if all went well, else returns appropriate error value.
1470 static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle
*handle
,
1471 u32 dev_id
, u32 clk_id
, u64 min_freq
,
1472 u64 target_freq
, u64 max_freq
,
1475 struct ti_sci_info
*info
;
1476 struct ti_sci_msg_req_query_clock_freq
*req
;
1477 struct ti_sci_msg_resp_query_clock_freq
*resp
;
1478 struct ti_sci_xfer
*xfer
;
1483 return PTR_ERR(handle
);
1484 if (!handle
|| !match_freq
)
1487 info
= handle_to_ti_sci_info(handle
);
1490 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_QUERY_CLOCK_FREQ
,
1491 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1492 sizeof(*req
), sizeof(*resp
));
1494 ret
= PTR_ERR(xfer
);
1495 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1498 req
= (struct ti_sci_msg_req_query_clock_freq
*)xfer
->xfer_buf
;
1499 req
->dev_id
= dev_id
;
1501 req
->clk_id
= clk_id
;
1504 req
->clk_id_32
= clk_id
;
1506 req
->min_freq_hz
= min_freq
;
1507 req
->target_freq_hz
= target_freq
;
1508 req
->max_freq_hz
= max_freq
;
1510 ret
= ti_sci_do_xfer(info
, xfer
);
1512 dev_err(dev
, "Mbox send fail %d\n", ret
);
1516 resp
= (struct ti_sci_msg_resp_query_clock_freq
*)xfer
->xfer_buf
;
1518 if (!ti_sci_is_response_ack(resp
))
1521 *match_freq
= resp
->freq_hz
;
1524 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1530 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1531 * @handle: pointer to TI SCI handle
1532 * @dev_id: Device identifier this request is for
1533 * @clk_id: Clock identifier for the device for this request.
1534 * Each device has it's own set of clock inputs. This indexes
1535 * which clock input to modify.
1536 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1537 * allowable programmed frequency and does not account for clock
1538 * tolerances and jitter.
1539 * @target_freq: The target clock frequency in Hz. A frequency will be
1540 * processed as close to this target frequency as possible.
1541 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1542 * allowable programmed frequency and does not account for clock
1543 * tolerances and jitter.
1545 * Return: 0 if all went well, else returns appropriate error value.
1547 static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle
*handle
,
1548 u32 dev_id
, u32 clk_id
, u64 min_freq
,
1549 u64 target_freq
, u64 max_freq
)
1551 struct ti_sci_info
*info
;
1552 struct ti_sci_msg_req_set_clock_freq
*req
;
1553 struct ti_sci_msg_hdr
*resp
;
1554 struct ti_sci_xfer
*xfer
;
1559 return PTR_ERR(handle
);
1563 info
= handle_to_ti_sci_info(handle
);
1566 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CLOCK_FREQ
,
1567 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1568 sizeof(*req
), sizeof(*resp
));
1570 ret
= PTR_ERR(xfer
);
1571 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1574 req
= (struct ti_sci_msg_req_set_clock_freq
*)xfer
->xfer_buf
;
1575 req
->dev_id
= dev_id
;
1577 req
->clk_id
= clk_id
;
1580 req
->clk_id_32
= clk_id
;
1582 req
->min_freq_hz
= min_freq
;
1583 req
->target_freq_hz
= target_freq
;
1584 req
->max_freq_hz
= max_freq
;
1586 ret
= ti_sci_do_xfer(info
, xfer
);
1588 dev_err(dev
, "Mbox send fail %d\n", ret
);
1592 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1594 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1597 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1603 * ti_sci_cmd_clk_get_freq() - Get current frequency
1604 * @handle: pointer to TI SCI handle
1605 * @dev_id: Device identifier this request is for
1606 * @clk_id: Clock identifier for the device for this request.
1607 * Each device has it's own set of clock inputs. This indexes
1608 * which clock input to modify.
1609 * @freq: Currently frequency in Hz
1611 * Return: 0 if all went well, else returns appropriate error value.
1613 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle
*handle
,
1614 u32 dev_id
, u32 clk_id
, u64
*freq
)
1616 struct ti_sci_info
*info
;
1617 struct ti_sci_msg_req_get_clock_freq
*req
;
1618 struct ti_sci_msg_resp_get_clock_freq
*resp
;
1619 struct ti_sci_xfer
*xfer
;
1624 return PTR_ERR(handle
);
1625 if (!handle
|| !freq
)
1628 info
= handle_to_ti_sci_info(handle
);
1631 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_CLOCK_FREQ
,
1632 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1633 sizeof(*req
), sizeof(*resp
));
1635 ret
= PTR_ERR(xfer
);
1636 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1639 req
= (struct ti_sci_msg_req_get_clock_freq
*)xfer
->xfer_buf
;
1640 req
->dev_id
= dev_id
;
1642 req
->clk_id
= clk_id
;
1645 req
->clk_id_32
= clk_id
;
1648 ret
= ti_sci_do_xfer(info
, xfer
);
1650 dev_err(dev
, "Mbox send fail %d\n", ret
);
1654 resp
= (struct ti_sci_msg_resp_get_clock_freq
*)xfer
->xfer_buf
;
1656 if (!ti_sci_is_response_ack(resp
))
1659 *freq
= resp
->freq_hz
;
1662 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1667 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle
*handle
)
1669 struct ti_sci_info
*info
;
1670 struct ti_sci_msg_req_reboot
*req
;
1671 struct ti_sci_msg_hdr
*resp
;
1672 struct ti_sci_xfer
*xfer
;
1677 return PTR_ERR(handle
);
1681 info
= handle_to_ti_sci_info(handle
);
1684 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SYS_RESET
,
1685 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1686 sizeof(*req
), sizeof(*resp
));
1688 ret
= PTR_ERR(xfer
);
1689 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1692 req
= (struct ti_sci_msg_req_reboot
*)xfer
->xfer_buf
;
1694 ret
= ti_sci_do_xfer(info
, xfer
);
1696 dev_err(dev
, "Mbox send fail %d\n", ret
);
1700 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1702 if (!ti_sci_is_response_ack(resp
))
1708 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1713 static int ti_sci_get_resource_type(struct ti_sci_info
*info
, u16 dev_id
,
1716 struct ti_sci_rm_type_map
*rm_type_map
= info
->desc
->rm_type_map
;
1720 /* If map is not provided then assume dev_id is used as type */
1726 for (i
= 0; rm_type_map
[i
].dev_id
; i
++) {
1727 if (rm_type_map
[i
].dev_id
== dev_id
) {
1728 *type
= rm_type_map
[i
].type
;
1741 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1742 * to a host. Resource is uniquely identified by
1744 * @handle: Pointer to TISCI handle.
1745 * @dev_id: TISCI device ID.
1746 * @subtype: Resource assignment subtype that is being requested
1747 * from the given device.
1748 * @s_host: Host processor ID to which the resources are allocated
1749 * @range_start: Start index of the resource range
1750 * @range_num: Number of resources in the range
1752 * Return: 0 if all went fine, else return appropriate error.
1754 static int ti_sci_get_resource_range(const struct ti_sci_handle
*handle
,
1755 u32 dev_id
, u8 subtype
, u8 s_host
,
1756 u16
*range_start
, u16
*range_num
)
1758 struct ti_sci_msg_resp_get_resource_range
*resp
;
1759 struct ti_sci_msg_req_get_resource_range
*req
;
1760 struct ti_sci_xfer
*xfer
;
1761 struct ti_sci_info
*info
;
1767 return PTR_ERR(handle
);
1771 info
= handle_to_ti_sci_info(handle
);
1774 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_RESOURCE_RANGE
,
1775 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1776 sizeof(*req
), sizeof(*resp
));
1778 ret
= PTR_ERR(xfer
);
1779 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1783 ret
= ti_sci_get_resource_type(info
, dev_id
, &type
);
1785 dev_err(dev
, "rm type lookup failed for %u\n", dev_id
);
1789 req
= (struct ti_sci_msg_req_get_resource_range
*)xfer
->xfer_buf
;
1790 req
->secondary_host
= s_host
;
1791 req
->type
= type
& MSG_RM_RESOURCE_TYPE_MASK
;
1792 req
->subtype
= subtype
& MSG_RM_RESOURCE_SUBTYPE_MASK
;
1794 ret
= ti_sci_do_xfer(info
, xfer
);
1796 dev_err(dev
, "Mbox send fail %d\n", ret
);
1800 resp
= (struct ti_sci_msg_resp_get_resource_range
*)xfer
->xfer_buf
;
1802 if (!ti_sci_is_response_ack(resp
)) {
1804 } else if (!resp
->range_start
&& !resp
->range_num
) {
1807 *range_start
= resp
->range_start
;
1808 *range_num
= resp
->range_num
;
1812 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1818 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1819 * that is same as ti sci interface host.
1820 * @handle: Pointer to TISCI handle.
1821 * @dev_id: TISCI device ID.
1822 * @subtype: Resource assignment subtype that is being requested
1823 * from the given device.
1824 * @range_start: Start index of the resource range
1825 * @range_num: Number of resources in the range
1827 * Return: 0 if all went fine, else return appropriate error.
1829 static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle
*handle
,
1830 u32 dev_id
, u8 subtype
,
1831 u16
*range_start
, u16
*range_num
)
1833 return ti_sci_get_resource_range(handle
, dev_id
, subtype
,
1834 TI_SCI_IRQ_SECONDARY_HOST_INVALID
,
1835 range_start
, range_num
);
1839 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1840 * assigned to a specified host.
1841 * @handle: Pointer to TISCI handle.
1842 * @dev_id: TISCI device ID.
1843 * @subtype: Resource assignment subtype that is being requested
1844 * from the given device.
1845 * @s_host: Host processor ID to which the resources are allocated
1846 * @range_start: Start index of the resource range
1847 * @range_num: Number of resources in the range
1849 * Return: 0 if all went fine, else return appropriate error.
1852 int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle
*handle
,
1853 u32 dev_id
, u8 subtype
, u8 s_host
,
1854 u16
*range_start
, u16
*range_num
)
1856 return ti_sci_get_resource_range(handle
, dev_id
, subtype
, s_host
,
1857 range_start
, range_num
);
1861 * ti_sci_manage_irq() - Helper api to configure/release the irq route between
1862 * the requested source and destination
1863 * @handle: Pointer to TISCI handle.
1864 * @valid_params: Bit fields defining the validity of certain params
1865 * @src_id: Device ID of the IRQ source
1866 * @src_index: IRQ source index within the source device
1867 * @dst_id: Device ID of the IRQ destination
1868 * @dst_host_irq: IRQ number of the destination device
1869 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1870 * @vint: Virtual interrupt to be used within the IA
1871 * @global_event: Global event number to be used for the requesting event
1872 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1873 * @s_host: Secondary host ID to which the irq/event is being
1875 * @type: Request type irq set or release.
1877 * Return: 0 if all went fine, else return appropriate error.
1879 static int ti_sci_manage_irq(const struct ti_sci_handle
*handle
,
1880 u32 valid_params
, u16 src_id
, u16 src_index
,
1881 u16 dst_id
, u16 dst_host_irq
, u16 ia_id
, u16 vint
,
1882 u16 global_event
, u8 vint_status_bit
, u8 s_host
,
1885 struct ti_sci_msg_req_manage_irq
*req
;
1886 struct ti_sci_msg_hdr
*resp
;
1887 struct ti_sci_xfer
*xfer
;
1888 struct ti_sci_info
*info
;
1893 return PTR_ERR(handle
);
1897 info
= handle_to_ti_sci_info(handle
);
1900 xfer
= ti_sci_get_one_xfer(info
, type
, TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
1901 sizeof(*req
), sizeof(*resp
));
1903 ret
= PTR_ERR(xfer
);
1904 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
1907 req
= (struct ti_sci_msg_req_manage_irq
*)xfer
->xfer_buf
;
1908 req
->valid_params
= valid_params
;
1909 req
->src_id
= src_id
;
1910 req
->src_index
= src_index
;
1911 req
->dst_id
= dst_id
;
1912 req
->dst_host_irq
= dst_host_irq
;
1915 req
->global_event
= global_event
;
1916 req
->vint_status_bit
= vint_status_bit
;
1917 req
->secondary_host
= s_host
;
1919 ret
= ti_sci_do_xfer(info
, xfer
);
1921 dev_err(dev
, "Mbox send fail %d\n", ret
);
1925 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
1927 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
1930 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
1936 * ti_sci_set_irq() - Helper api to configure the irq route between the
1937 * requested source and destination
1938 * @handle: Pointer to TISCI handle.
1939 * @valid_params: Bit fields defining the validity of certain params
1940 * @src_id: Device ID of the IRQ source
1941 * @src_index: IRQ source index within the source device
1942 * @dst_id: Device ID of the IRQ destination
1943 * @dst_host_irq: IRQ number of the destination device
1944 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1945 * @vint: Virtual interrupt to be used within the IA
1946 * @global_event: Global event number to be used for the requesting event
1947 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1948 * @s_host: Secondary host ID to which the irq/event is being
1951 * Return: 0 if all went fine, else return appropriate error.
1953 static int ti_sci_set_irq(const struct ti_sci_handle
*handle
, u32 valid_params
,
1954 u16 src_id
, u16 src_index
, u16 dst_id
,
1955 u16 dst_host_irq
, u16 ia_id
, u16 vint
,
1956 u16 global_event
, u8 vint_status_bit
, u8 s_host
)
1958 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",
1959 __func__
, valid_params
, src_id
, src_index
,
1960 dst_id
, dst_host_irq
, ia_id
, vint
, global_event
,
1963 return ti_sci_manage_irq(handle
, valid_params
, src_id
, src_index
,
1964 dst_id
, dst_host_irq
, ia_id
, vint
,
1965 global_event
, vint_status_bit
, s_host
,
1966 TI_SCI_MSG_SET_IRQ
);
1970 * ti_sci_free_irq() - Helper api to free the irq route between the
1971 * requested source and destination
1972 * @handle: Pointer to TISCI handle.
1973 * @valid_params: Bit fields defining the validity of certain params
1974 * @src_id: Device ID of the IRQ source
1975 * @src_index: IRQ source index within the source device
1976 * @dst_id: Device ID of the IRQ destination
1977 * @dst_host_irq: IRQ number of the destination device
1978 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
1979 * @vint: Virtual interrupt to be used within the IA
1980 * @global_event: Global event number to be used for the requesting event
1981 * @vint_status_bit: Virtual interrupt status bit to be used for the event
1982 * @s_host: Secondary host ID to which the irq/event is being
1985 * Return: 0 if all went fine, else return appropriate error.
1987 static int ti_sci_free_irq(const struct ti_sci_handle
*handle
, u32 valid_params
,
1988 u16 src_id
, u16 src_index
, u16 dst_id
,
1989 u16 dst_host_irq
, u16 ia_id
, u16 vint
,
1990 u16 global_event
, u8 vint_status_bit
, u8 s_host
)
1992 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",
1993 __func__
, valid_params
, src_id
, src_index
,
1994 dst_id
, dst_host_irq
, ia_id
, vint
, global_event
,
1997 return ti_sci_manage_irq(handle
, valid_params
, src_id
, src_index
,
1998 dst_id
, dst_host_irq
, ia_id
, vint
,
1999 global_event
, vint_status_bit
, s_host
,
2000 TI_SCI_MSG_FREE_IRQ
);
2004 * ti_sci_cmd_set_irq() - Configure a host irq route between the requested
2005 * source and destination.
2006 * @handle: Pointer to TISCI handle.
2007 * @src_id: Device ID of the IRQ source
2008 * @src_index: IRQ source index within the source device
2009 * @dst_id: Device ID of the IRQ destination
2010 * @dst_host_irq: IRQ number of the destination device
2011 * @vint_irq: Boolean specifying if this interrupt belongs to
2012 * Interrupt Aggregator.
2014 * Return: 0 if all went fine, else return appropriate error.
2016 static int ti_sci_cmd_set_irq(const struct ti_sci_handle
*handle
, u16 src_id
,
2017 u16 src_index
, u16 dst_id
, u16 dst_host_irq
)
2019 u32 valid_params
= MSG_FLAG_DST_ID_VALID
| MSG_FLAG_DST_HOST_IRQ_VALID
;
2021 return ti_sci_set_irq(handle
, valid_params
, src_id
, src_index
, dst_id
,
2022 dst_host_irq
, 0, 0, 0, 0, 0);
2026 * ti_sci_cmd_set_event_map() - Configure an event based irq route between the
2027 * requested source and Interrupt Aggregator.
2028 * @handle: Pointer to TISCI handle.
2029 * @src_id: Device ID of the IRQ source
2030 * @src_index: IRQ source index within the source device
2031 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
2032 * @vint: Virtual interrupt to be used within the IA
2033 * @global_event: Global event number to be used for the requesting event
2034 * @vint_status_bit: Virtual interrupt status bit to be used for the event
2036 * Return: 0 if all went fine, else return appropriate error.
2038 static int ti_sci_cmd_set_event_map(const struct ti_sci_handle
*handle
,
2039 u16 src_id
, u16 src_index
, u16 ia_id
,
2040 u16 vint
, u16 global_event
,
2043 u32 valid_params
= MSG_FLAG_IA_ID_VALID
| MSG_FLAG_VINT_VALID
|
2044 MSG_FLAG_GLB_EVNT_VALID
|
2045 MSG_FLAG_VINT_STS_BIT_VALID
;
2047 return ti_sci_set_irq(handle
, valid_params
, src_id
, src_index
, 0, 0,
2048 ia_id
, vint
, global_event
, vint_status_bit
, 0);
2052 * ti_sci_cmd_free_irq() - Free a host irq route between the between the
2053 * requested source and destination.
2054 * @handle: Pointer to TISCI handle.
2055 * @src_id: Device ID of the IRQ source
2056 * @src_index: IRQ source index within the source device
2057 * @dst_id: Device ID of the IRQ destination
2058 * @dst_host_irq: IRQ number of the destination device
2059 * @vint_irq: Boolean specifying if this interrupt belongs to
2060 * Interrupt Aggregator.
2062 * Return: 0 if all went fine, else return appropriate error.
2064 static int ti_sci_cmd_free_irq(const struct ti_sci_handle
*handle
, u16 src_id
,
2065 u16 src_index
, u16 dst_id
, u16 dst_host_irq
)
2067 u32 valid_params
= MSG_FLAG_DST_ID_VALID
| MSG_FLAG_DST_HOST_IRQ_VALID
;
2069 return ti_sci_free_irq(handle
, valid_params
, src_id
, src_index
, dst_id
,
2070 dst_host_irq
, 0, 0, 0, 0, 0);
2074 * ti_sci_cmd_free_event_map() - Free an event map between the requested source
2075 * and Interrupt Aggregator.
2076 * @handle: Pointer to TISCI handle.
2077 * @src_id: Device ID of the IRQ source
2078 * @src_index: IRQ source index within the source device
2079 * @ia_id: Device ID of the IA, if the IRQ flows through this IA
2080 * @vint: Virtual interrupt to be used within the IA
2081 * @global_event: Global event number to be used for the requesting event
2082 * @vint_status_bit: Virtual interrupt status bit to be used for the event
2084 * Return: 0 if all went fine, else return appropriate error.
2086 static int ti_sci_cmd_free_event_map(const struct ti_sci_handle
*handle
,
2087 u16 src_id
, u16 src_index
, u16 ia_id
,
2088 u16 vint
, u16 global_event
,
2091 u32 valid_params
= MSG_FLAG_IA_ID_VALID
|
2092 MSG_FLAG_VINT_VALID
| MSG_FLAG_GLB_EVNT_VALID
|
2093 MSG_FLAG_VINT_STS_BIT_VALID
;
2095 return ti_sci_free_irq(handle
, valid_params
, src_id
, src_index
, 0, 0,
2096 ia_id
, vint
, global_event
, vint_status_bit
, 0);
2100 * ti_sci_cmd_ring_config() - configure RA ring
2101 * @handle: Pointer to TI SCI handle.
2102 * @valid_params: Bitfield defining validity of ring configuration
2104 * @nav_id: Device ID of Navigator Subsystem from which the ring is
2106 * @index: Ring index
2107 * @addr_lo: The ring base address lo 32 bits
2108 * @addr_hi: The ring base address hi 32 bits
2109 * @count: Number of ring elements
2110 * @mode: The mode of the ring
2111 * @size: The ring element size.
2112 * @order_id: Specifies the ring's bus order ID
2114 * Return: 0 if all went well, else returns appropriate error value.
2116 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2118 static int ti_sci_cmd_ring_config(const struct ti_sci_handle
*handle
,
2119 u32 valid_params
, u16 nav_id
, u16 index
,
2120 u32 addr_lo
, u32 addr_hi
, u32 count
,
2121 u8 mode
, u8 size
, u8 order_id
)
2123 struct ti_sci_msg_rm_ring_cfg_req
*req
;
2124 struct ti_sci_msg_hdr
*resp
;
2125 struct ti_sci_xfer
*xfer
;
2126 struct ti_sci_info
*info
;
2130 if (IS_ERR_OR_NULL(handle
))
2133 info
= handle_to_ti_sci_info(handle
);
2136 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_RING_CFG
,
2137 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2138 sizeof(*req
), sizeof(*resp
));
2140 ret
= PTR_ERR(xfer
);
2141 dev_err(dev
, "RM_RA:Message config failed(%d)\n", ret
);
2144 req
= (struct ti_sci_msg_rm_ring_cfg_req
*)xfer
->xfer_buf
;
2145 req
->valid_params
= valid_params
;
2146 req
->nav_id
= nav_id
;
2148 req
->addr_lo
= addr_lo
;
2149 req
->addr_hi
= addr_hi
;
2153 req
->order_id
= order_id
;
2155 ret
= ti_sci_do_xfer(info
, xfer
);
2157 dev_err(dev
, "RM_RA:Mbox config send fail %d\n", ret
);
2161 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2162 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2165 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2166 dev_dbg(dev
, "RM_RA:config ring %u ret:%d\n", index
, ret
);
2171 * ti_sci_cmd_ring_get_config() - get RA ring configuration
2172 * @handle: Pointer to TI SCI handle.
2173 * @nav_id: Device ID of Navigator Subsystem from which the ring is
2175 * @index: Ring index
2176 * @addr_lo: Returns ring's base address lo 32 bits
2177 * @addr_hi: Returns ring's base address hi 32 bits
2178 * @count: Returns number of ring elements
2179 * @mode: Returns mode of the ring
2180 * @size: Returns ring element size
2181 * @order_id: Returns ring's bus order ID
2183 * Return: 0 if all went well, else returns appropriate error value.
2185 * See @ti_sci_msg_rm_ring_get_cfg_req for more info.
2187 static int ti_sci_cmd_ring_get_config(const struct ti_sci_handle
*handle
,
2188 u32 nav_id
, u32 index
, u8
*mode
,
2189 u32
*addr_lo
, u32
*addr_hi
,
2190 u32
*count
, u8
*size
, u8
*order_id
)
2192 struct ti_sci_msg_rm_ring_get_cfg_resp
*resp
;
2193 struct ti_sci_msg_rm_ring_get_cfg_req
*req
;
2194 struct ti_sci_xfer
*xfer
;
2195 struct ti_sci_info
*info
;
2199 if (IS_ERR_OR_NULL(handle
))
2202 info
= handle_to_ti_sci_info(handle
);
2205 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_RING_GET_CFG
,
2206 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2207 sizeof(*req
), sizeof(*resp
));
2209 ret
= PTR_ERR(xfer
);
2211 "RM_RA:Message get config failed(%d)\n", ret
);
2214 req
= (struct ti_sci_msg_rm_ring_get_cfg_req
*)xfer
->xfer_buf
;
2215 req
->nav_id
= nav_id
;
2218 ret
= ti_sci_do_xfer(info
, xfer
);
2220 dev_err(dev
, "RM_RA:Mbox get config send fail %d\n", ret
);
2224 resp
= (struct ti_sci_msg_rm_ring_get_cfg_resp
*)xfer
->xfer_buf
;
2226 if (!ti_sci_is_response_ack(resp
)) {
2232 *addr_lo
= resp
->addr_lo
;
2234 *addr_hi
= resp
->addr_hi
;
2236 *count
= resp
->count
;
2240 *order_id
= resp
->order_id
;
2244 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2245 dev_dbg(dev
, "RM_RA:get config ring %u ret:%d\n", index
, ret
);
2250 * ti_sci_cmd_rm_psil_pair() - Pair PSI-L source to destination thread
2251 * @handle: Pointer to TI SCI handle.
2252 * @nav_id: Device ID of Navigator Subsystem which should be used for
2254 * @src_thread: Source PSI-L thread ID
2255 * @dst_thread: Destination PSI-L thread ID
2257 * Return: 0 if all went well, else returns appropriate error value.
2259 static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle
*handle
,
2260 u32 nav_id
, u32 src_thread
, u32 dst_thread
)
2262 struct ti_sci_msg_psil_pair
*req
;
2263 struct ti_sci_msg_hdr
*resp
;
2264 struct ti_sci_xfer
*xfer
;
2265 struct ti_sci_info
*info
;
2270 return PTR_ERR(handle
);
2274 info
= handle_to_ti_sci_info(handle
);
2277 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_PSIL_PAIR
,
2278 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2279 sizeof(*req
), sizeof(*resp
));
2281 ret
= PTR_ERR(xfer
);
2282 dev_err(dev
, "RM_PSIL:Message reconfig failed(%d)\n", ret
);
2285 req
= (struct ti_sci_msg_psil_pair
*)xfer
->xfer_buf
;
2286 req
->nav_id
= nav_id
;
2287 req
->src_thread
= src_thread
;
2288 req
->dst_thread
= dst_thread
;
2290 ret
= ti_sci_do_xfer(info
, xfer
);
2292 dev_err(dev
, "RM_PSIL:Mbox send fail %d\n", ret
);
2296 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2297 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2300 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2306 * ti_sci_cmd_rm_psil_unpair() - Unpair PSI-L source from destination thread
2307 * @handle: Pointer to TI SCI handle.
2308 * @nav_id: Device ID of Navigator Subsystem which should be used for
2310 * @src_thread: Source PSI-L thread ID
2311 * @dst_thread: Destination PSI-L thread ID
2313 * Return: 0 if all went well, else returns appropriate error value.
2315 static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle
*handle
,
2316 u32 nav_id
, u32 src_thread
, u32 dst_thread
)
2318 struct ti_sci_msg_psil_unpair
*req
;
2319 struct ti_sci_msg_hdr
*resp
;
2320 struct ti_sci_xfer
*xfer
;
2321 struct ti_sci_info
*info
;
2326 return PTR_ERR(handle
);
2330 info
= handle_to_ti_sci_info(handle
);
2333 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_RM_PSIL_UNPAIR
,
2334 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2335 sizeof(*req
), sizeof(*resp
));
2337 ret
= PTR_ERR(xfer
);
2338 dev_err(dev
, "RM_PSIL:Message reconfig failed(%d)\n", ret
);
2341 req
= (struct ti_sci_msg_psil_unpair
*)xfer
->xfer_buf
;
2342 req
->nav_id
= nav_id
;
2343 req
->src_thread
= src_thread
;
2344 req
->dst_thread
= dst_thread
;
2346 ret
= ti_sci_do_xfer(info
, xfer
);
2348 dev_err(dev
, "RM_PSIL:Mbox send fail %d\n", ret
);
2352 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2353 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2356 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2362 * ti_sci_cmd_rm_udmap_tx_ch_cfg() - Configure a UDMAP TX channel
2363 * @handle: Pointer to TI SCI handle.
2364 * @params: Pointer to ti_sci_msg_rm_udmap_tx_ch_cfg TX channel config
2367 * Return: 0 if all went well, else returns appropriate error value.
2369 * See @ti_sci_msg_rm_udmap_tx_ch_cfg and @ti_sci_msg_rm_udmap_tx_ch_cfg_req for
2372 static int ti_sci_cmd_rm_udmap_tx_ch_cfg(const struct ti_sci_handle
*handle
,
2373 const struct ti_sci_msg_rm_udmap_tx_ch_cfg
*params
)
2375 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req
*req
;
2376 struct ti_sci_msg_hdr
*resp
;
2377 struct ti_sci_xfer
*xfer
;
2378 struct ti_sci_info
*info
;
2382 if (IS_ERR_OR_NULL(handle
))
2385 info
= handle_to_ti_sci_info(handle
);
2388 xfer
= ti_sci_get_one_xfer(info
, TISCI_MSG_RM_UDMAP_TX_CH_CFG
,
2389 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2390 sizeof(*req
), sizeof(*resp
));
2392 ret
= PTR_ERR(xfer
);
2393 dev_err(dev
, "Message TX_CH_CFG alloc failed(%d)\n", ret
);
2396 req
= (struct ti_sci_msg_rm_udmap_tx_ch_cfg_req
*)xfer
->xfer_buf
;
2397 req
->valid_params
= params
->valid_params
;
2398 req
->nav_id
= params
->nav_id
;
2399 req
->index
= params
->index
;
2400 req
->tx_pause_on_err
= params
->tx_pause_on_err
;
2401 req
->tx_filt_einfo
= params
->tx_filt_einfo
;
2402 req
->tx_filt_pswords
= params
->tx_filt_pswords
;
2403 req
->tx_atype
= params
->tx_atype
;
2404 req
->tx_chan_type
= params
->tx_chan_type
;
2405 req
->tx_supr_tdpkt
= params
->tx_supr_tdpkt
;
2406 req
->tx_fetch_size
= params
->tx_fetch_size
;
2407 req
->tx_credit_count
= params
->tx_credit_count
;
2408 req
->txcq_qnum
= params
->txcq_qnum
;
2409 req
->tx_priority
= params
->tx_priority
;
2410 req
->tx_qos
= params
->tx_qos
;
2411 req
->tx_orderid
= params
->tx_orderid
;
2412 req
->fdepth
= params
->fdepth
;
2413 req
->tx_sched_priority
= params
->tx_sched_priority
;
2414 req
->tx_burst_size
= params
->tx_burst_size
;
2416 ret
= ti_sci_do_xfer(info
, xfer
);
2418 dev_err(dev
, "Mbox send TX_CH_CFG fail %d\n", ret
);
2422 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2423 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2426 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2427 dev_dbg(dev
, "TX_CH_CFG: chn %u ret:%u\n", params
->index
, ret
);
2432 * ti_sci_cmd_rm_udmap_rx_ch_cfg() - Configure a UDMAP RX channel
2433 * @handle: Pointer to TI SCI handle.
2434 * @params: Pointer to ti_sci_msg_rm_udmap_rx_ch_cfg RX channel config
2437 * Return: 0 if all went well, else returns appropriate error value.
2439 * See @ti_sci_msg_rm_udmap_rx_ch_cfg and @ti_sci_msg_rm_udmap_rx_ch_cfg_req for
2442 static int ti_sci_cmd_rm_udmap_rx_ch_cfg(const struct ti_sci_handle
*handle
,
2443 const struct ti_sci_msg_rm_udmap_rx_ch_cfg
*params
)
2445 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req
*req
;
2446 struct ti_sci_msg_hdr
*resp
;
2447 struct ti_sci_xfer
*xfer
;
2448 struct ti_sci_info
*info
;
2452 if (IS_ERR_OR_NULL(handle
))
2455 info
= handle_to_ti_sci_info(handle
);
2458 xfer
= ti_sci_get_one_xfer(info
, TISCI_MSG_RM_UDMAP_RX_CH_CFG
,
2459 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2460 sizeof(*req
), sizeof(*resp
));
2462 ret
= PTR_ERR(xfer
);
2463 dev_err(dev
, "Message RX_CH_CFG alloc failed(%d)\n", ret
);
2466 req
= (struct ti_sci_msg_rm_udmap_rx_ch_cfg_req
*)xfer
->xfer_buf
;
2467 req
->valid_params
= params
->valid_params
;
2468 req
->nav_id
= params
->nav_id
;
2469 req
->index
= params
->index
;
2470 req
->rx_fetch_size
= params
->rx_fetch_size
;
2471 req
->rxcq_qnum
= params
->rxcq_qnum
;
2472 req
->rx_priority
= params
->rx_priority
;
2473 req
->rx_qos
= params
->rx_qos
;
2474 req
->rx_orderid
= params
->rx_orderid
;
2475 req
->rx_sched_priority
= params
->rx_sched_priority
;
2476 req
->flowid_start
= params
->flowid_start
;
2477 req
->flowid_cnt
= params
->flowid_cnt
;
2478 req
->rx_pause_on_err
= params
->rx_pause_on_err
;
2479 req
->rx_atype
= params
->rx_atype
;
2480 req
->rx_chan_type
= params
->rx_chan_type
;
2481 req
->rx_ignore_short
= params
->rx_ignore_short
;
2482 req
->rx_ignore_long
= params
->rx_ignore_long
;
2483 req
->rx_burst_size
= params
->rx_burst_size
;
2485 ret
= ti_sci_do_xfer(info
, xfer
);
2487 dev_err(dev
, "Mbox send RX_CH_CFG fail %d\n", ret
);
2491 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2492 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2495 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2496 dev_dbg(dev
, "RX_CH_CFG: chn %u ret:%d\n", params
->index
, ret
);
2501 * ti_sci_cmd_rm_udmap_rx_flow_cfg() - Configure UDMAP RX FLOW
2502 * @handle: Pointer to TI SCI handle.
2503 * @params: Pointer to ti_sci_msg_rm_udmap_flow_cfg RX FLOW config
2506 * Return: 0 if all went well, else returns appropriate error value.
2508 * See @ti_sci_msg_rm_udmap_flow_cfg and @ti_sci_msg_rm_udmap_flow_cfg_req for
2511 static int ti_sci_cmd_rm_udmap_rx_flow_cfg(const struct ti_sci_handle
*handle
,
2512 const struct ti_sci_msg_rm_udmap_flow_cfg
*params
)
2514 struct ti_sci_msg_rm_udmap_flow_cfg_req
*req
;
2515 struct ti_sci_msg_hdr
*resp
;
2516 struct ti_sci_xfer
*xfer
;
2517 struct ti_sci_info
*info
;
2521 if (IS_ERR_OR_NULL(handle
))
2524 info
= handle_to_ti_sci_info(handle
);
2527 xfer
= ti_sci_get_one_xfer(info
, TISCI_MSG_RM_UDMAP_FLOW_CFG
,
2528 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2529 sizeof(*req
), sizeof(*resp
));
2531 ret
= PTR_ERR(xfer
);
2532 dev_err(dev
, "RX_FL_CFG: Message alloc failed(%d)\n", ret
);
2535 req
= (struct ti_sci_msg_rm_udmap_flow_cfg_req
*)xfer
->xfer_buf
;
2536 req
->valid_params
= params
->valid_params
;
2537 req
->nav_id
= params
->nav_id
;
2538 req
->flow_index
= params
->flow_index
;
2539 req
->rx_einfo_present
= params
->rx_einfo_present
;
2540 req
->rx_psinfo_present
= params
->rx_psinfo_present
;
2541 req
->rx_error_handling
= params
->rx_error_handling
;
2542 req
->rx_desc_type
= params
->rx_desc_type
;
2543 req
->rx_sop_offset
= params
->rx_sop_offset
;
2544 req
->rx_dest_qnum
= params
->rx_dest_qnum
;
2545 req
->rx_src_tag_hi
= params
->rx_src_tag_hi
;
2546 req
->rx_src_tag_lo
= params
->rx_src_tag_lo
;
2547 req
->rx_dest_tag_hi
= params
->rx_dest_tag_hi
;
2548 req
->rx_dest_tag_lo
= params
->rx_dest_tag_lo
;
2549 req
->rx_src_tag_hi_sel
= params
->rx_src_tag_hi_sel
;
2550 req
->rx_src_tag_lo_sel
= params
->rx_src_tag_lo_sel
;
2551 req
->rx_dest_tag_hi_sel
= params
->rx_dest_tag_hi_sel
;
2552 req
->rx_dest_tag_lo_sel
= params
->rx_dest_tag_lo_sel
;
2553 req
->rx_fdq0_sz0_qnum
= params
->rx_fdq0_sz0_qnum
;
2554 req
->rx_fdq1_qnum
= params
->rx_fdq1_qnum
;
2555 req
->rx_fdq2_qnum
= params
->rx_fdq2_qnum
;
2556 req
->rx_fdq3_qnum
= params
->rx_fdq3_qnum
;
2557 req
->rx_ps_location
= params
->rx_ps_location
;
2559 ret
= ti_sci_do_xfer(info
, xfer
);
2561 dev_err(dev
, "RX_FL_CFG: Mbox send fail %d\n", ret
);
2565 resp
= (struct ti_sci_msg_hdr
*)xfer
->xfer_buf
;
2566 ret
= ti_sci_is_response_ack(resp
) ? 0 : -EINVAL
;
2569 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2570 dev_dbg(info
->dev
, "RX_FL_CFG: %u ret:%d\n", params
->flow_index
, ret
);
2575 * ti_sci_cmd_proc_request() - Command to request a physical processor control
2576 * @handle: Pointer to TI SCI handle
2577 * @proc_id: Processor ID this request is for
2579 * Return: 0 if all went well, else returns appropriate error value.
2581 static int ti_sci_cmd_proc_request(const struct ti_sci_handle
*handle
,
2584 struct ti_sci_msg_req_proc_request
*req
;
2585 struct ti_sci_msg_hdr
*resp
;
2586 struct ti_sci_info
*info
;
2587 struct ti_sci_xfer
*xfer
;
2594 return PTR_ERR(handle
);
2596 info
= handle_to_ti_sci_info(handle
);
2599 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_PROC_REQUEST
,
2600 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2601 sizeof(*req
), sizeof(*resp
));
2603 ret
= PTR_ERR(xfer
);
2604 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2607 req
= (struct ti_sci_msg_req_proc_request
*)xfer
->xfer_buf
;
2608 req
->processor_id
= proc_id
;
2610 ret
= ti_sci_do_xfer(info
, xfer
);
2612 dev_err(dev
, "Mbox send fail %d\n", ret
);
2616 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2618 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2621 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2627 * ti_sci_cmd_proc_release() - Command to release a physical processor control
2628 * @handle: Pointer to TI SCI handle
2629 * @proc_id: Processor ID this request is for
2631 * Return: 0 if all went well, else returns appropriate error value.
2633 static int ti_sci_cmd_proc_release(const struct ti_sci_handle
*handle
,
2636 struct ti_sci_msg_req_proc_release
*req
;
2637 struct ti_sci_msg_hdr
*resp
;
2638 struct ti_sci_info
*info
;
2639 struct ti_sci_xfer
*xfer
;
2646 return PTR_ERR(handle
);
2648 info
= handle_to_ti_sci_info(handle
);
2651 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_PROC_RELEASE
,
2652 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2653 sizeof(*req
), sizeof(*resp
));
2655 ret
= PTR_ERR(xfer
);
2656 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2659 req
= (struct ti_sci_msg_req_proc_release
*)xfer
->xfer_buf
;
2660 req
->processor_id
= proc_id
;
2662 ret
= ti_sci_do_xfer(info
, xfer
);
2664 dev_err(dev
, "Mbox send fail %d\n", ret
);
2668 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2670 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2673 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2679 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
2680 * control to a host in the processor's access
2682 * @handle: Pointer to TI SCI handle
2683 * @proc_id: Processor ID this request is for
2684 * @host_id: Host ID to get the control of the processor
2686 * Return: 0 if all went well, else returns appropriate error value.
2688 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle
*handle
,
2689 u8 proc_id
, u8 host_id
)
2691 struct ti_sci_msg_req_proc_handover
*req
;
2692 struct ti_sci_msg_hdr
*resp
;
2693 struct ti_sci_info
*info
;
2694 struct ti_sci_xfer
*xfer
;
2701 return PTR_ERR(handle
);
2703 info
= handle_to_ti_sci_info(handle
);
2706 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_PROC_HANDOVER
,
2707 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2708 sizeof(*req
), sizeof(*resp
));
2710 ret
= PTR_ERR(xfer
);
2711 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2714 req
= (struct ti_sci_msg_req_proc_handover
*)xfer
->xfer_buf
;
2715 req
->processor_id
= proc_id
;
2716 req
->host_id
= host_id
;
2718 ret
= ti_sci_do_xfer(info
, xfer
);
2720 dev_err(dev
, "Mbox send fail %d\n", ret
);
2724 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2726 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2729 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2735 * ti_sci_cmd_proc_set_config() - Command to set the processor boot
2736 * configuration flags
2737 * @handle: Pointer to TI SCI handle
2738 * @proc_id: Processor ID this request is for
2739 * @config_flags_set: Configuration flags to be set
2740 * @config_flags_clear: Configuration flags to be cleared.
2742 * Return: 0 if all went well, else returns appropriate error value.
2744 static int ti_sci_cmd_proc_set_config(const struct ti_sci_handle
*handle
,
2745 u8 proc_id
, u64 bootvector
,
2746 u32 config_flags_set
,
2747 u32 config_flags_clear
)
2749 struct ti_sci_msg_req_set_config
*req
;
2750 struct ti_sci_msg_hdr
*resp
;
2751 struct ti_sci_info
*info
;
2752 struct ti_sci_xfer
*xfer
;
2759 return PTR_ERR(handle
);
2761 info
= handle_to_ti_sci_info(handle
);
2764 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CONFIG
,
2765 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2766 sizeof(*req
), sizeof(*resp
));
2768 ret
= PTR_ERR(xfer
);
2769 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2772 req
= (struct ti_sci_msg_req_set_config
*)xfer
->xfer_buf
;
2773 req
->processor_id
= proc_id
;
2774 req
->bootvector_low
= bootvector
& TI_SCI_ADDR_LOW_MASK
;
2775 req
->bootvector_high
= (bootvector
& TI_SCI_ADDR_HIGH_MASK
) >>
2776 TI_SCI_ADDR_HIGH_SHIFT
;
2777 req
->config_flags_set
= config_flags_set
;
2778 req
->config_flags_clear
= config_flags_clear
;
2780 ret
= ti_sci_do_xfer(info
, xfer
);
2782 dev_err(dev
, "Mbox send fail %d\n", ret
);
2786 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2788 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2791 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2797 * ti_sci_cmd_proc_set_control() - Command to set the processor boot
2799 * @handle: Pointer to TI SCI handle
2800 * @proc_id: Processor ID this request is for
2801 * @control_flags_set: Control flags to be set
2802 * @control_flags_clear: Control flags to be cleared
2804 * Return: 0 if all went well, else returns appropriate error value.
2806 static int ti_sci_cmd_proc_set_control(const struct ti_sci_handle
*handle
,
2807 u8 proc_id
, u32 control_flags_set
,
2808 u32 control_flags_clear
)
2810 struct ti_sci_msg_req_set_ctrl
*req
;
2811 struct ti_sci_msg_hdr
*resp
;
2812 struct ti_sci_info
*info
;
2813 struct ti_sci_xfer
*xfer
;
2820 return PTR_ERR(handle
);
2822 info
= handle_to_ti_sci_info(handle
);
2825 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_SET_CTRL
,
2826 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2827 sizeof(*req
), sizeof(*resp
));
2829 ret
= PTR_ERR(xfer
);
2830 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2833 req
= (struct ti_sci_msg_req_set_ctrl
*)xfer
->xfer_buf
;
2834 req
->processor_id
= proc_id
;
2835 req
->control_flags_set
= control_flags_set
;
2836 req
->control_flags_clear
= control_flags_clear
;
2838 ret
= ti_sci_do_xfer(info
, xfer
);
2840 dev_err(dev
, "Mbox send fail %d\n", ret
);
2844 resp
= (struct ti_sci_msg_hdr
*)xfer
->tx_message
.buf
;
2846 ret
= ti_sci_is_response_ack(resp
) ? 0 : -ENODEV
;
2849 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2855 * ti_sci_cmd_get_boot_status() - Command to get the processor boot status
2856 * @handle: Pointer to TI SCI handle
2857 * @proc_id: Processor ID this request is for
2859 * Return: 0 if all went well, else returns appropriate error value.
2861 static int ti_sci_cmd_proc_get_status(const struct ti_sci_handle
*handle
,
2862 u8 proc_id
, u64
*bv
, u32
*cfg_flags
,
2863 u32
*ctrl_flags
, u32
*sts_flags
)
2865 struct ti_sci_msg_resp_get_status
*resp
;
2866 struct ti_sci_msg_req_get_status
*req
;
2867 struct ti_sci_info
*info
;
2868 struct ti_sci_xfer
*xfer
;
2875 return PTR_ERR(handle
);
2877 info
= handle_to_ti_sci_info(handle
);
2880 xfer
= ti_sci_get_one_xfer(info
, TI_SCI_MSG_GET_STATUS
,
2881 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED
,
2882 sizeof(*req
), sizeof(*resp
));
2884 ret
= PTR_ERR(xfer
);
2885 dev_err(dev
, "Message alloc failed(%d)\n", ret
);
2888 req
= (struct ti_sci_msg_req_get_status
*)xfer
->xfer_buf
;
2889 req
->processor_id
= proc_id
;
2891 ret
= ti_sci_do_xfer(info
, xfer
);
2893 dev_err(dev
, "Mbox send fail %d\n", ret
);
2897 resp
= (struct ti_sci_msg_resp_get_status
*)xfer
->tx_message
.buf
;
2899 if (!ti_sci_is_response_ack(resp
)) {
2902 *bv
= (resp
->bootvector_low
& TI_SCI_ADDR_LOW_MASK
) |
2903 (((u64
)resp
->bootvector_high
<< TI_SCI_ADDR_HIGH_SHIFT
) &
2904 TI_SCI_ADDR_HIGH_MASK
);
2905 *cfg_flags
= resp
->config_flags
;
2906 *ctrl_flags
= resp
->control_flags
;
2907 *sts_flags
= resp
->status_flags
;
2911 ti_sci_put_one_xfer(&info
->minfo
, xfer
);
2917 * ti_sci_setup_ops() - Setup the operations structures
2918 * @info: pointer to TISCI pointer
2920 static void ti_sci_setup_ops(struct ti_sci_info
*info
)
2922 struct ti_sci_ops
*ops
= &info
->handle
.ops
;
2923 struct ti_sci_core_ops
*core_ops
= &ops
->core_ops
;
2924 struct ti_sci_dev_ops
*dops
= &ops
->dev_ops
;
2925 struct ti_sci_clk_ops
*cops
= &ops
->clk_ops
;
2926 struct ti_sci_rm_core_ops
*rm_core_ops
= &ops
->rm_core_ops
;
2927 struct ti_sci_rm_irq_ops
*iops
= &ops
->rm_irq_ops
;
2928 struct ti_sci_rm_ringacc_ops
*rops
= &ops
->rm_ring_ops
;
2929 struct ti_sci_rm_psil_ops
*psilops
= &ops
->rm_psil_ops
;
2930 struct ti_sci_rm_udmap_ops
*udmap_ops
= &ops
->rm_udmap_ops
;
2931 struct ti_sci_proc_ops
*pops
= &ops
->proc_ops
;
2933 core_ops
->reboot_device
= ti_sci_cmd_core_reboot
;
2935 dops
->get_device
= ti_sci_cmd_get_device
;
2936 dops
->get_device_exclusive
= ti_sci_cmd_get_device_exclusive
;
2937 dops
->idle_device
= ti_sci_cmd_idle_device
;
2938 dops
->idle_device_exclusive
= ti_sci_cmd_idle_device_exclusive
;
2939 dops
->put_device
= ti_sci_cmd_put_device
;
2941 dops
->is_valid
= ti_sci_cmd_dev_is_valid
;
2942 dops
->get_context_loss_count
= ti_sci_cmd_dev_get_clcnt
;
2943 dops
->is_idle
= ti_sci_cmd_dev_is_idle
;
2944 dops
->is_stop
= ti_sci_cmd_dev_is_stop
;
2945 dops
->is_on
= ti_sci_cmd_dev_is_on
;
2946 dops
->is_transitioning
= ti_sci_cmd_dev_is_trans
;
2947 dops
->set_device_resets
= ti_sci_cmd_set_device_resets
;
2948 dops
->get_device_resets
= ti_sci_cmd_get_device_resets
;
2950 cops
->get_clock
= ti_sci_cmd_get_clock
;
2951 cops
->idle_clock
= ti_sci_cmd_idle_clock
;
2952 cops
->put_clock
= ti_sci_cmd_put_clock
;
2953 cops
->is_auto
= ti_sci_cmd_clk_is_auto
;
2954 cops
->is_on
= ti_sci_cmd_clk_is_on
;
2955 cops
->is_off
= ti_sci_cmd_clk_is_off
;
2957 cops
->set_parent
= ti_sci_cmd_clk_set_parent
;
2958 cops
->get_parent
= ti_sci_cmd_clk_get_parent
;
2959 cops
->get_num_parents
= ti_sci_cmd_clk_get_num_parents
;
2961 cops
->get_best_match_freq
= ti_sci_cmd_clk_get_match_freq
;
2962 cops
->set_freq
= ti_sci_cmd_clk_set_freq
;
2963 cops
->get_freq
= ti_sci_cmd_clk_get_freq
;
2965 rm_core_ops
->get_range
= ti_sci_cmd_get_resource_range
;
2966 rm_core_ops
->get_range_from_shost
=
2967 ti_sci_cmd_get_resource_range_from_shost
;
2969 iops
->set_irq
= ti_sci_cmd_set_irq
;
2970 iops
->set_event_map
= ti_sci_cmd_set_event_map
;
2971 iops
->free_irq
= ti_sci_cmd_free_irq
;
2972 iops
->free_event_map
= ti_sci_cmd_free_event_map
;
2974 rops
->config
= ti_sci_cmd_ring_config
;
2975 rops
->get_config
= ti_sci_cmd_ring_get_config
;
2977 psilops
->pair
= ti_sci_cmd_rm_psil_pair
;
2978 psilops
->unpair
= ti_sci_cmd_rm_psil_unpair
;
2980 udmap_ops
->tx_ch_cfg
= ti_sci_cmd_rm_udmap_tx_ch_cfg
;
2981 udmap_ops
->rx_ch_cfg
= ti_sci_cmd_rm_udmap_rx_ch_cfg
;
2982 udmap_ops
->rx_flow_cfg
= ti_sci_cmd_rm_udmap_rx_flow_cfg
;
2984 pops
->request
= ti_sci_cmd_proc_request
;
2985 pops
->release
= ti_sci_cmd_proc_release
;
2986 pops
->handover
= ti_sci_cmd_proc_handover
;
2987 pops
->set_config
= ti_sci_cmd_proc_set_config
;
2988 pops
->set_control
= ti_sci_cmd_proc_set_control
;
2989 pops
->get_status
= ti_sci_cmd_proc_get_status
;
2993 * ti_sci_get_handle() - Get the TI SCI handle for a device
2994 * @dev: Pointer to device for which we want SCI handle
2996 * NOTE: The function does not track individual clients of the framework
2997 * and is expected to be maintained by caller of TI SCI protocol library.
2998 * ti_sci_put_handle must be balanced with successful ti_sci_get_handle
2999 * Return: pointer to handle if successful, else:
3000 * -EPROBE_DEFER if the instance is not ready
3001 * -ENODEV if the required node handler is missing
3002 * -EINVAL if invalid conditions are encountered.
3004 const struct ti_sci_handle
*ti_sci_get_handle(struct device
*dev
)
3006 struct device_node
*ti_sci_np
;
3007 struct list_head
*p
;
3008 struct ti_sci_handle
*handle
= NULL
;
3009 struct ti_sci_info
*info
;
3012 pr_err("I need a device pointer\n");
3013 return ERR_PTR(-EINVAL
);
3015 ti_sci_np
= of_get_parent(dev
->of_node
);
3017 dev_err(dev
, "No OF information\n");
3018 return ERR_PTR(-EINVAL
);
3021 mutex_lock(&ti_sci_list_mutex
);
3022 list_for_each(p
, &ti_sci_list
) {
3023 info
= list_entry(p
, struct ti_sci_info
, node
);
3024 if (ti_sci_np
== info
->dev
->of_node
) {
3025 handle
= &info
->handle
;
3030 mutex_unlock(&ti_sci_list_mutex
);
3031 of_node_put(ti_sci_np
);
3034 return ERR_PTR(-EPROBE_DEFER
);
3038 EXPORT_SYMBOL_GPL(ti_sci_get_handle
);
3041 * ti_sci_put_handle() - Release the handle acquired by ti_sci_get_handle
3042 * @handle: Handle acquired by ti_sci_get_handle
3044 * NOTE: The function does not track individual clients of the framework
3045 * and is expected to be maintained by caller of TI SCI protocol library.
3046 * ti_sci_put_handle must be balanced with successful ti_sci_get_handle
3048 * Return: 0 is successfully released
3049 * if an error pointer was passed, it returns the error value back,
3050 * if null was passed, it returns -EINVAL;
3052 int ti_sci_put_handle(const struct ti_sci_handle
*handle
)
3054 struct ti_sci_info
*info
;
3057 return PTR_ERR(handle
);
3061 info
= handle_to_ti_sci_info(handle
);
3062 mutex_lock(&ti_sci_list_mutex
);
3063 if (!WARN_ON(!info
->users
))
3065 mutex_unlock(&ti_sci_list_mutex
);
3069 EXPORT_SYMBOL_GPL(ti_sci_put_handle
);
3071 static void devm_ti_sci_release(struct device
*dev
, void *res
)
3073 const struct ti_sci_handle
**ptr
= res
;
3074 const struct ti_sci_handle
*handle
= *ptr
;
3077 ret
= ti_sci_put_handle(handle
);
3079 dev_err(dev
, "failed to put handle %d\n", ret
);
3083 * devm_ti_sci_get_handle() - Managed get handle
3084 * @dev: device for which we want SCI handle for.
3086 * NOTE: This releases the handle once the device resources are
3087 * no longer needed. MUST NOT BE released with ti_sci_put_handle.
3088 * The function does not track individual clients of the framework
3089 * and is expected to be maintained by caller of TI SCI protocol library.
3091 * Return: 0 if all went fine, else corresponding error.
3093 const struct ti_sci_handle
*devm_ti_sci_get_handle(struct device
*dev
)
3095 const struct ti_sci_handle
**ptr
;
3096 const struct ti_sci_handle
*handle
;
3098 ptr
= devres_alloc(devm_ti_sci_release
, sizeof(*ptr
), GFP_KERNEL
);
3100 return ERR_PTR(-ENOMEM
);
3101 handle
= ti_sci_get_handle(dev
);
3103 if (!IS_ERR(handle
)) {
3105 devres_add(dev
, ptr
);
3112 EXPORT_SYMBOL_GPL(devm_ti_sci_get_handle
);
3115 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
3117 * @property: property name containing phandle on TISCI node
3119 * NOTE: The function does not track individual clients of the framework
3120 * and is expected to be maintained by caller of TI SCI protocol library.
3121 * ti_sci_put_handle must be balanced with successful ti_sci_get_by_phandle
3122 * Return: pointer to handle if successful, else:
3123 * -EPROBE_DEFER if the instance is not ready
3124 * -ENODEV if the required node handler is missing
3125 * -EINVAL if invalid conditions are encountered.
3127 const struct ti_sci_handle
*ti_sci_get_by_phandle(struct device_node
*np
,
3128 const char *property
)
3130 struct ti_sci_handle
*handle
= NULL
;
3131 struct device_node
*ti_sci_np
;
3132 struct ti_sci_info
*info
;
3133 struct list_head
*p
;
3136 pr_err("I need a device pointer\n");
3137 return ERR_PTR(-EINVAL
);
3140 ti_sci_np
= of_parse_phandle(np
, property
, 0);
3142 return ERR_PTR(-ENODEV
);
3144 mutex_lock(&ti_sci_list_mutex
);
3145 list_for_each(p
, &ti_sci_list
) {
3146 info
= list_entry(p
, struct ti_sci_info
, node
);
3147 if (ti_sci_np
== info
->dev
->of_node
) {
3148 handle
= &info
->handle
;
3153 mutex_unlock(&ti_sci_list_mutex
);
3154 of_node_put(ti_sci_np
);
3157 return ERR_PTR(-EPROBE_DEFER
);
3161 EXPORT_SYMBOL_GPL(ti_sci_get_by_phandle
);
3164 * devm_ti_sci_get_by_phandle() - Managed get handle using phandle
3165 * @dev: Device pointer requesting TISCI handle
3166 * @property: property name containing phandle on TISCI node
3168 * NOTE: This releases the handle once the device resources are
3169 * no longer needed. MUST NOT BE released with ti_sci_put_handle.
3170 * The function does not track individual clients of the framework
3171 * and is expected to be maintained by caller of TI SCI protocol library.
3173 * Return: 0 if all went fine, else corresponding error.
3175 const struct ti_sci_handle
*devm_ti_sci_get_by_phandle(struct device
*dev
,
3176 const char *property
)
3178 const struct ti_sci_handle
*handle
;
3179 const struct ti_sci_handle
**ptr
;
3181 ptr
= devres_alloc(devm_ti_sci_release
, sizeof(*ptr
), GFP_KERNEL
);
3183 return ERR_PTR(-ENOMEM
);
3184 handle
= ti_sci_get_by_phandle(dev_of_node(dev
), property
);
3186 if (!IS_ERR(handle
)) {
3188 devres_add(dev
, ptr
);
3195 EXPORT_SYMBOL_GPL(devm_ti_sci_get_by_phandle
);
3198 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
3199 * @res: Pointer to the TISCI resource
3201 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
3203 u16
ti_sci_get_free_resource(struct ti_sci_resource
*res
)
3205 unsigned long flags
;
3208 raw_spin_lock_irqsave(&res
->lock
, flags
);
3209 for (set
= 0; set
< res
->sets
; set
++) {
3210 free_bit
= find_first_zero_bit(res
->desc
[set
].res_map
,
3211 res
->desc
[set
].num
);
3212 if (free_bit
!= res
->desc
[set
].num
) {
3213 set_bit(free_bit
, res
->desc
[set
].res_map
);
3214 raw_spin_unlock_irqrestore(&res
->lock
, flags
);
3215 return res
->desc
[set
].start
+ free_bit
;
3218 raw_spin_unlock_irqrestore(&res
->lock
, flags
);
3220 return TI_SCI_RESOURCE_NULL
;
3222 EXPORT_SYMBOL_GPL(ti_sci_get_free_resource
);
3225 * ti_sci_release_resource() - Release a resource from TISCI resource.
3226 * @res: Pointer to the TISCI resource
3227 * @id: Resource id to be released.
3229 void ti_sci_release_resource(struct ti_sci_resource
*res
, u16 id
)
3231 unsigned long flags
;
3234 raw_spin_lock_irqsave(&res
->lock
, flags
);
3235 for (set
= 0; set
< res
->sets
; set
++) {
3236 if (res
->desc
[set
].start
<= id
&&
3237 (res
->desc
[set
].num
+ res
->desc
[set
].start
) > id
)
3238 clear_bit(id
- res
->desc
[set
].start
,
3239 res
->desc
[set
].res_map
);
3241 raw_spin_unlock_irqrestore(&res
->lock
, flags
);
3243 EXPORT_SYMBOL_GPL(ti_sci_release_resource
);
3246 * ti_sci_get_num_resources() - Get the number of resources in TISCI resource
3247 * @res: Pointer to the TISCI resource
3249 * Return: Total number of available resources.
3251 u32
ti_sci_get_num_resources(struct ti_sci_resource
*res
)
3255 for (set
= 0; set
< res
->sets
; set
++)
3256 count
+= res
->desc
[set
].num
;
3260 EXPORT_SYMBOL_GPL(ti_sci_get_num_resources
);
3263 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3264 * @handle: TISCI handle
3265 * @dev: Device pointer to which the resource is assigned
3266 * @dev_id: TISCI device id to which the resource is assigned
3267 * @of_prop: property name by which the resource are represented
3269 * Return: Pointer to ti_sci_resource if all went well else appropriate
3272 struct ti_sci_resource
*
3273 devm_ti_sci_get_of_resource(const struct ti_sci_handle
*handle
,
3274 struct device
*dev
, u32 dev_id
, char *of_prop
)
3276 struct ti_sci_resource
*res
;
3277 bool valid_set
= false;
3278 u32 resource_subtype
;
3281 res
= devm_kzalloc(dev
, sizeof(*res
), GFP_KERNEL
);
3283 return ERR_PTR(-ENOMEM
);
3285 ret
= of_property_count_elems_of_size(dev_of_node(dev
), of_prop
,
3288 dev_err(dev
, "%s resource type ids not available\n", of_prop
);
3289 return ERR_PTR(ret
);
3293 res
->desc
= devm_kcalloc(dev
, res
->sets
, sizeof(*res
->desc
),
3296 return ERR_PTR(-ENOMEM
);
3298 for (i
= 0; i
< res
->sets
; i
++) {
3299 ret
= of_property_read_u32_index(dev_of_node(dev
), of_prop
, i
,
3302 return ERR_PTR(-EINVAL
);
3304 ret
= handle
->ops
.rm_core_ops
.get_range(handle
, dev_id
,
3306 &res
->desc
[i
].start
,
3309 dev_dbg(dev
, "dev = %d subtype %d not allocated for this host\n",
3310 dev_id
, resource_subtype
);
3311 res
->desc
[i
].start
= 0;
3312 res
->desc
[i
].num
= 0;
3316 dev_dbg(dev
, "dev = %d, subtype = %d, start = %d, num = %d\n",
3317 dev_id
, resource_subtype
, res
->desc
[i
].start
,
3321 res
->desc
[i
].res_map
=
3322 devm_kzalloc(dev
, BITS_TO_LONGS(res
->desc
[i
].num
) *
3323 sizeof(*res
->desc
[i
].res_map
), GFP_KERNEL
);
3324 if (!res
->desc
[i
].res_map
)
3325 return ERR_PTR(-ENOMEM
);
3327 raw_spin_lock_init(&res
->lock
);
3332 return ERR_PTR(-EINVAL
);
3335 static int tisci_reboot_handler(struct notifier_block
*nb
, unsigned long mode
,
3338 struct ti_sci_info
*info
= reboot_to_ti_sci_info(nb
);
3339 const struct ti_sci_handle
*handle
= &info
->handle
;
3341 ti_sci_cmd_core_reboot(handle
);
3343 /* call fail OR pass, we should not be here in the first place */
3347 /* Description for K2G */
3348 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc
= {
3349 .default_host_id
= 2,
3350 /* Conservative duration */
3351 .max_rx_timeout_ms
= 1000,
3352 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3355 .rm_type_map
= NULL
,
3358 static struct ti_sci_rm_type_map ti_sci_am654_rm_type_map
[] = {
3359 {.dev_id
= 56, .type
= 0x00b}, /* GIC_IRQ */
3360 {.dev_id
= 179, .type
= 0x000}, /* MAIN_NAV_UDMASS_IA0 */
3361 {.dev_id
= 187, .type
= 0x009}, /* MAIN_NAV_RA */
3362 {.dev_id
= 188, .type
= 0x006}, /* MAIN_NAV_UDMAP */
3363 {.dev_id
= 194, .type
= 0x007}, /* MCU_NAV_UDMAP */
3364 {.dev_id
= 195, .type
= 0x00a}, /* MCU_NAV_RA */
3365 {.dev_id
= 0, .type
= 0x000}, /* end of table */
3368 /* Description for AM654 */
3369 static const struct ti_sci_desc ti_sci_pmmc_am654_desc
= {
3370 .default_host_id
= 12,
3371 /* Conservative duration */
3372 .max_rx_timeout_ms
= 10000,
3373 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3376 .rm_type_map
= ti_sci_am654_rm_type_map
,
3379 static const struct of_device_id ti_sci_of_match
[] = {
3380 {.compatible
= "ti,k2g-sci", .data
= &ti_sci_pmmc_k2g_desc
},
3381 {.compatible
= "ti,am654-sci", .data
= &ti_sci_pmmc_am654_desc
},
3384 MODULE_DEVICE_TABLE(of
, ti_sci_of_match
);
3386 static int ti_sci_probe(struct platform_device
*pdev
)
3388 struct device
*dev
= &pdev
->dev
;
3389 const struct of_device_id
*of_id
;
3390 const struct ti_sci_desc
*desc
;
3391 struct ti_sci_xfer
*xfer
;
3392 struct ti_sci_info
*info
= NULL
;
3393 struct ti_sci_xfers_info
*minfo
;
3394 struct mbox_client
*cl
;
3400 of_id
= of_match_device(ti_sci_of_match
, dev
);
3402 dev_err(dev
, "OF data missing\n");
3407 info
= devm_kzalloc(dev
, sizeof(*info
), GFP_KERNEL
);
3413 ret
= of_property_read_u32(dev
->of_node
, "ti,host-id", &h_id
);
3414 /* if the property is not present in DT, use a default from desc */
3416 info
->host_id
= info
->desc
->default_host_id
;
3419 dev_warn(dev
, "Host ID 0 is reserved for firmware\n");
3420 info
->host_id
= info
->desc
->default_host_id
;
3422 info
->host_id
= h_id
;
3426 reboot
= of_property_read_bool(dev
->of_node
,
3427 "ti,system-reboot-controller");
3428 INIT_LIST_HEAD(&info
->node
);
3429 minfo
= &info
->minfo
;
3432 * Pre-allocate messages
3433 * NEVER allocate more than what we can indicate in hdr.seq
3434 * if we have data description bug, force a fix..
3436 if (WARN_ON(desc
->max_msgs
>=
3437 1 << 8 * sizeof(((struct ti_sci_msg_hdr
*)0)->seq
)))
3440 minfo
->xfer_block
= devm_kcalloc(dev
,
3442 sizeof(*minfo
->xfer_block
),
3444 if (!minfo
->xfer_block
)
3447 minfo
->xfer_alloc_table
= devm_kcalloc(dev
,
3448 BITS_TO_LONGS(desc
->max_msgs
),
3449 sizeof(unsigned long),
3451 if (!minfo
->xfer_alloc_table
)
3453 bitmap_zero(minfo
->xfer_alloc_table
, desc
->max_msgs
);
3455 /* Pre-initialize the buffer pointer to pre-allocated buffers */
3456 for (i
= 0, xfer
= minfo
->xfer_block
; i
< desc
->max_msgs
; i
++, xfer
++) {
3457 xfer
->xfer_buf
= devm_kcalloc(dev
, 1, desc
->max_msg_size
,
3459 if (!xfer
->xfer_buf
)
3462 xfer
->tx_message
.buf
= xfer
->xfer_buf
;
3463 init_completion(&xfer
->done
);
3466 ret
= ti_sci_debugfs_create(pdev
, info
);
3468 dev_warn(dev
, "Failed to create debug file\n");
3470 platform_set_drvdata(pdev
, info
);
3474 cl
->tx_block
= false;
3475 cl
->rx_callback
= ti_sci_rx_callback
;
3476 cl
->knows_txdone
= true;
3478 spin_lock_init(&minfo
->xfer_lock
);
3479 sema_init(&minfo
->sem_xfer_count
, desc
->max_msgs
);
3481 info
->chan_rx
= mbox_request_channel_byname(cl
, "rx");
3482 if (IS_ERR(info
->chan_rx
)) {
3483 ret
= PTR_ERR(info
->chan_rx
);
3487 info
->chan_tx
= mbox_request_channel_byname(cl
, "tx");
3488 if (IS_ERR(info
->chan_tx
)) {
3489 ret
= PTR_ERR(info
->chan_tx
);
3492 ret
= ti_sci_cmd_get_revision(info
);
3494 dev_err(dev
, "Unable to communicate with TISCI(%d)\n", ret
);
3498 ti_sci_setup_ops(info
);
3501 info
->nb
.notifier_call
= tisci_reboot_handler
;
3502 info
->nb
.priority
= 128;
3504 ret
= register_restart_handler(&info
->nb
);
3506 dev_err(dev
, "reboot registration fail(%d)\n", ret
);
3511 dev_info(dev
, "ABI: %d.%d (firmware rev 0x%04x '%s')\n",
3512 info
->handle
.version
.abi_major
, info
->handle
.version
.abi_minor
,
3513 info
->handle
.version
.firmware_revision
,
3514 info
->handle
.version
.firmware_description
);
3516 mutex_lock(&ti_sci_list_mutex
);
3517 list_add_tail(&info
->node
, &ti_sci_list
);
3518 mutex_unlock(&ti_sci_list_mutex
);
3520 return of_platform_populate(dev
->of_node
, NULL
, NULL
, dev
);
3522 if (!IS_ERR(info
->chan_tx
))
3523 mbox_free_channel(info
->chan_tx
);
3524 if (!IS_ERR(info
->chan_rx
))
3525 mbox_free_channel(info
->chan_rx
);
3526 debugfs_remove(info
->d
);
3530 static int ti_sci_remove(struct platform_device
*pdev
)
3532 struct ti_sci_info
*info
;
3533 struct device
*dev
= &pdev
->dev
;
3536 of_platform_depopulate(dev
);
3538 info
= platform_get_drvdata(pdev
);
3540 if (info
->nb
.notifier_call
)
3541 unregister_restart_handler(&info
->nb
);
3543 mutex_lock(&ti_sci_list_mutex
);
3547 list_del(&info
->node
);
3548 mutex_unlock(&ti_sci_list_mutex
);
3551 ti_sci_debugfs_destroy(pdev
, info
);
3553 /* Safe to free channels since no more users */
3554 mbox_free_channel(info
->chan_tx
);
3555 mbox_free_channel(info
->chan_rx
);
3561 static struct platform_driver ti_sci_driver
= {
3562 .probe
= ti_sci_probe
,
3563 .remove
= ti_sci_remove
,
3566 .of_match_table
= of_match_ptr(ti_sci_of_match
),
3569 module_platform_driver(ti_sci_driver
);
3571 MODULE_LICENSE("GPL v2");
3572 MODULE_DESCRIPTION("TI System Control Interface(SCI) driver");
3573 MODULE_AUTHOR("Nishanth Menon");
3574 MODULE_ALIAS("platform:ti-sci");