• Home
  • Raw
  • Download

Lines Matching +full:sci +full:- +full:dev +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
21 #include <linux/soc/ti/ti-msgmgr.h>
27 /* List of all TI SCI devices active in system */
33 * struct ti_sci_xfer - Structure representing a message flow
37 * Since we work with request-ACK protocol, we can
50 * struct ti_sci_xfers_info - Structure to manage transfer information
68 * struct ti_sci_desc - Description of SoC integration
83 * struct ti_sci_info - Structure representing a TI SCI instance
84 * @dev: Device pointer
91 * @handle: Instance of TI SCI handle to send to clients.
100 struct device *dev; member
125 * ti_sci_debug_show() - Helper to dump the debug log
133 struct ti_sci_info *info = s->private; in ti_sci_debug_show()
135 memcpy_fromio(info->debug_buffer, info->debug_region, in ti_sci_debug_show()
136 info->debug_region_size); in ti_sci_debug_show()
141 * in the buffer as is - we expect the messages to be self explanatory. in ti_sci_debug_show()
143 seq_puts(s, info->debug_buffer); in ti_sci_debug_show()
148 * ti_sci_debug_open() - debug file open
156 return single_open(file, ti_sci_debug_show, inode->i_private); in ti_sci_debug_open()
168 * ti_sci_debugfs_create() - Create log debug file
170 * @info: Pointer to SCI entity information
177 struct device *dev = &pdev->dev; in ti_sci_debugfs_create() local
184 info->debug_region = devm_ioremap_resource(dev, res); in ti_sci_debugfs_create()
185 if (IS_ERR(info->debug_region)) in ti_sci_debugfs_create()
187 info->debug_region_size = resource_size(res); in ti_sci_debugfs_create()
189 info->debug_buffer = devm_kcalloc(dev, info->debug_region_size + 1, in ti_sci_debugfs_create()
191 if (!info->debug_buffer) in ti_sci_debugfs_create()
192 return -ENOMEM; in ti_sci_debugfs_create()
194 info->debug_buffer[info->debug_region_size] = 0; in ti_sci_debugfs_create()
196 info->d = debugfs_create_file(strncat(debug_name, dev_name(dev), in ti_sci_debugfs_create()
197 sizeof(debug_name) - in ti_sci_debugfs_create()
200 if (IS_ERR(info->d)) in ti_sci_debugfs_create()
201 return PTR_ERR(info->d); in ti_sci_debugfs_create()
203 dev_dbg(dev, "Debug region => %p, size = %zu bytes, resource: %pr\n", in ti_sci_debugfs_create()
204 info->debug_region, info->debug_region_size, res); in ti_sci_debugfs_create()
209 * ti_sci_debugfs_destroy() - clean up log debug file
211 * @info: Pointer to SCI entity information
216 if (IS_ERR(info->debug_region)) in ti_sci_debugfs_destroy()
219 debugfs_remove(info->d); in ti_sci_debugfs_destroy()
222 static inline int ti_sci_debugfs_create(struct platform_device *dev, in ti_sci_debugfs_create() argument
228 static inline void ti_sci_debugfs_destroy(struct platform_device *dev, in ti_sci_debugfs_destroy() argument
235 * ti_sci_dump_header_dbg() - Helper to dump a message header.
236 * @dev: Device pointer corresponding to the SCI entity
239 static inline void ti_sci_dump_header_dbg(struct device *dev, in ti_sci_dump_header_dbg() argument
242 dev_dbg(dev, "MSGHDR:type=0x%04x host=0x%02x seq=0x%02x flags=0x%08x\n", in ti_sci_dump_header_dbg()
243 hdr->type, hdr->host, hdr->seq, hdr->flags); in ti_sci_dump_header_dbg()
247 * ti_sci_rx_callback() - mailbox client callback for receive messages
260 struct device *dev = info->dev; in ti_sci_rx_callback() local
261 struct ti_sci_xfers_info *minfo = &info->minfo; in ti_sci_rx_callback()
263 struct ti_sci_msg_hdr *hdr = (struct ti_sci_msg_hdr *)mbox_msg->buf; in ti_sci_rx_callback()
267 xfer_id = hdr->seq; in ti_sci_rx_callback()
273 if (!test_bit(xfer_id, minfo->xfer_alloc_table)) { in ti_sci_rx_callback()
274 dev_err(dev, "Message for %d is not expected!\n", xfer_id); in ti_sci_rx_callback()
278 xfer = &minfo->xfer_block[xfer_id]; in ti_sci_rx_callback()
281 if (mbox_msg->len > info->desc->max_msg_size) { in ti_sci_rx_callback()
282 dev_err(dev, "Unable to handle %zu xfer(max %d)\n", in ti_sci_rx_callback()
283 mbox_msg->len, info->desc->max_msg_size); in ti_sci_rx_callback()
284 ti_sci_dump_header_dbg(dev, hdr); in ti_sci_rx_callback()
287 if (mbox_msg->len < xfer->rx_len) { in ti_sci_rx_callback()
288 dev_err(dev, "Recv xfer %zu < expected %d length\n", in ti_sci_rx_callback()
289 mbox_msg->len, xfer->rx_len); in ti_sci_rx_callback()
290 ti_sci_dump_header_dbg(dev, hdr); in ti_sci_rx_callback()
294 ti_sci_dump_header_dbg(dev, hdr); in ti_sci_rx_callback()
296 memcpy(xfer->xfer_buf, mbox_msg->buf, xfer->rx_len); in ti_sci_rx_callback()
297 complete(&xfer->done); in ti_sci_rx_callback()
301 * ti_sci_get_one_xfer() - Allocate one message
302 * @info: Pointer to SCI entity information
312 * for the SCI entity. Further, this also holds a spinlock to maintain integrity
322 struct ti_sci_xfers_info *minfo = &info->minfo; in ti_sci_get_one_xfer()
332 if (rx_message_size > info->desc->max_msg_size || in ti_sci_get_one_xfer()
333 tx_message_size > info->desc->max_msg_size || in ti_sci_get_one_xfer()
335 return ERR_PTR(-ERANGE); in ti_sci_get_one_xfer()
342 timeout = msecs_to_jiffies(info->desc->max_rx_timeout_ms) * 5; in ti_sci_get_one_xfer()
343 ret = down_timeout(&minfo->sem_xfer_count, timeout); in ti_sci_get_one_xfer()
348 spin_lock_irqsave(&minfo->xfer_lock, flags); in ti_sci_get_one_xfer()
349 bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, in ti_sci_get_one_xfer()
350 info->desc->max_msgs); in ti_sci_get_one_xfer()
351 set_bit(bit_pos, minfo->xfer_alloc_table); in ti_sci_get_one_xfer()
352 spin_unlock_irqrestore(&minfo->xfer_lock, flags); in ti_sci_get_one_xfer()
356 * fit in hdr.seq - NOTE: this improves access latencies in ti_sci_get_one_xfer()
363 xfer = &minfo->xfer_block[xfer_id]; in ti_sci_get_one_xfer()
365 hdr = (struct ti_sci_msg_hdr *)xfer->tx_message.buf; in ti_sci_get_one_xfer()
366 xfer->tx_message.len = tx_message_size; in ti_sci_get_one_xfer()
367 xfer->rx_len = (u8)rx_message_size; in ti_sci_get_one_xfer()
369 reinit_completion(&xfer->done); in ti_sci_get_one_xfer()
371 hdr->seq = xfer_id; in ti_sci_get_one_xfer()
372 hdr->type = msg_type; in ti_sci_get_one_xfer()
373 hdr->host = info->desc->host_id; in ti_sci_get_one_xfer()
374 hdr->flags = msg_flags; in ti_sci_get_one_xfer()
380 * ti_sci_put_one_xfer() - Release a message
393 hdr = (struct ti_sci_msg_hdr *)xfer->tx_message.buf; in ti_sci_put_one_xfer()
394 xfer_id = hdr->seq; in ti_sci_put_one_xfer()
401 spin_lock_irqsave(&minfo->xfer_lock, flags); in ti_sci_put_one_xfer()
402 clear_bit(xfer_id, minfo->xfer_alloc_table); in ti_sci_put_one_xfer()
403 spin_unlock_irqrestore(&minfo->xfer_lock, flags); in ti_sci_put_one_xfer()
406 up(&minfo->sem_xfer_count); in ti_sci_put_one_xfer()
410 * ti_sci_do_xfer() - Do one transfer
411 * @info: Pointer to SCI entity information
414 * Return: -ETIMEDOUT in case of no response, if transmit error,
423 struct device *dev = info->dev; in ti_sci_do_xfer() local
425 ret = mbox_send_message(info->chan_tx, &xfer->tx_message); in ti_sci_do_xfer()
432 timeout = msecs_to_jiffies(info->desc->max_rx_timeout_ms); in ti_sci_do_xfer()
433 if (!wait_for_completion_timeout(&xfer->done, timeout)) { in ti_sci_do_xfer()
434 dev_err(dev, "Mbox timedout in resp(caller: %pS)\n", in ti_sci_do_xfer()
436 ret = -ETIMEDOUT; in ti_sci_do_xfer()
444 mbox_client_txdone(info->chan_tx, ret); in ti_sci_do_xfer()
450 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
451 * @info: Pointer to SCI entity information
453 * Updates the SCI information in the internal data structure.
459 struct device *dev = info->dev; in ti_sci_cmd_get_revision() local
460 struct ti_sci_handle *handle = &info->handle; in ti_sci_cmd_get_revision()
461 struct ti_sci_version_info *ver = &handle->version; in ti_sci_cmd_get_revision()
472 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_get_revision()
476 rev_info = (struct ti_sci_msg_resp_version *)xfer->xfer_buf; in ti_sci_cmd_get_revision()
480 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_get_revision()
484 ver->abi_major = rev_info->abi_major; in ti_sci_cmd_get_revision()
485 ver->abi_minor = rev_info->abi_minor; in ti_sci_cmd_get_revision()
486 ver->firmware_revision = rev_info->firmware_revision; in ti_sci_cmd_get_revision()
487 strncpy(ver->firmware_description, rev_info->firmware_description, in ti_sci_cmd_get_revision()
488 sizeof(ver->firmware_description)); in ti_sci_cmd_get_revision()
491 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_get_revision()
496 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
505 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false; in ti_sci_is_response_ack()
509 * ti_sci_set_device_state() - Set device state helper
510 * @handle: pointer to TI SCI handle
511 * @id: Device identifier
518 u32 id, u32 flags, u8 state) in ti_sci_set_device_state() argument
524 struct device *dev; in ti_sci_set_device_state() local
530 return -EINVAL; in ti_sci_set_device_state()
533 dev = info->dev; in ti_sci_set_device_state()
540 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_set_device_state()
543 req = (struct ti_sci_msg_req_set_device_state *)xfer->xfer_buf; in ti_sci_set_device_state()
544 req->id = id; in ti_sci_set_device_state()
545 req->state = state; in ti_sci_set_device_state()
549 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_set_device_state()
553 resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; in ti_sci_set_device_state()
555 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; in ti_sci_set_device_state()
558 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_set_device_state()
564 * ti_sci_get_device_state() - Get device state helper
566 * @id: Device Identifier
575 u32 id, u32 *clcnt, u32 *resets, in ti_sci_get_device_state() argument
582 struct device *dev; in ti_sci_get_device_state() local
588 return -EINVAL; in ti_sci_get_device_state()
591 return -EINVAL; in ti_sci_get_device_state()
594 dev = info->dev; in ti_sci_get_device_state()
601 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_get_device_state()
604 req = (struct ti_sci_msg_req_get_device_state *)xfer->xfer_buf; in ti_sci_get_device_state()
605 req->id = id; in ti_sci_get_device_state()
609 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_get_device_state()
613 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->xfer_buf; in ti_sci_get_device_state()
615 ret = -ENODEV; in ti_sci_get_device_state()
620 *clcnt = resp->context_loss_count; in ti_sci_get_device_state()
622 *resets = resp->resets; in ti_sci_get_device_state()
624 *p_state = resp->programmed_state; in ti_sci_get_device_state()
626 *c_state = resp->current_state; in ti_sci_get_device_state()
628 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_get_device_state()
634 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
636 * @id: Device Identifier
638 * Request for the device - NOTE: the client MUST maintain integrity of
646 static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id) in ti_sci_cmd_get_device() argument
648 return ti_sci_set_device_state(handle, id, in ti_sci_cmd_get_device()
654 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
656 * @id: Device Identifier
658 * Request for the device - NOTE: the client MUST maintain integrity of
664 static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id) in ti_sci_cmd_idle_device() argument
666 return ti_sci_set_device_state(handle, id, in ti_sci_cmd_idle_device()
672 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
674 * @id: Device Identifier
676 * Request for the device - NOTE: the client MUST maintain integrity of
682 static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id) in ti_sci_cmd_put_device() argument
684 return ti_sci_set_device_state(handle, id, in ti_sci_cmd_put_device()
689 * ti_sci_cmd_dev_is_valid() - Is the device valid
691 * @id: Device Identifier
693 * Return: 0 if all went fine and the device ID is valid, else return
696 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id) in ti_sci_cmd_dev_is_valid() argument
700 /* check the device state which will also tell us if the ID is valid */ in ti_sci_cmd_dev_is_valid()
701 return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused); in ti_sci_cmd_dev_is_valid()
705 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
707 * @id: Device Identifier
712 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id, in ti_sci_cmd_dev_get_clcnt() argument
715 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL); in ti_sci_cmd_dev_get_clcnt()
719 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
721 * @id: Device Identifier
726 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id, in ti_sci_cmd_dev_is_idle() argument
733 return -EINVAL; in ti_sci_cmd_dev_is_idle()
735 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL); in ti_sci_cmd_dev_is_idle()
745 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
747 * @id: Device Identifier
753 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id, in ti_sci_cmd_dev_is_stop() argument
760 return -EINVAL; in ti_sci_cmd_dev_is_stop()
763 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state); in ti_sci_cmd_dev_is_stop()
776 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
778 * @id: Device Identifier
784 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id, in ti_sci_cmd_dev_is_on() argument
791 return -EINVAL; in ti_sci_cmd_dev_is_on()
794 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state); in ti_sci_cmd_dev_is_on()
807 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
809 * @id: Device Identifier
814 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id, in ti_sci_cmd_dev_is_trans() argument
821 return -EINVAL; in ti_sci_cmd_dev_is_trans()
823 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state); in ti_sci_cmd_dev_is_trans()
833 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
836 * @id: Device Identifier
842 u32 id, u32 reset_state) in ti_sci_cmd_set_device_resets() argument
848 struct device *dev; in ti_sci_cmd_set_device_resets() local
854 return -EINVAL; in ti_sci_cmd_set_device_resets()
857 dev = info->dev; in ti_sci_cmd_set_device_resets()
864 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_set_device_resets()
867 req = (struct ti_sci_msg_req_set_device_resets *)xfer->xfer_buf; in ti_sci_cmd_set_device_resets()
868 req->id = id; in ti_sci_cmd_set_device_resets()
869 req->resets = reset_state; in ti_sci_cmd_set_device_resets()
873 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_set_device_resets()
877 resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; in ti_sci_cmd_set_device_resets()
879 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; in ti_sci_cmd_set_device_resets()
882 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_set_device_resets()
888 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
891 * @id: Device Identifier
897 u32 id, u32 *reset_state) in ti_sci_cmd_get_device_resets() argument
899 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL, in ti_sci_cmd_get_device_resets()
904 * ti_sci_set_clock_state() - Set clock state helper
905 * @handle: pointer to TI SCI handle
923 struct device *dev; in ti_sci_set_clock_state() local
929 return -EINVAL; in ti_sci_set_clock_state()
932 dev = info->dev; in ti_sci_set_clock_state()
939 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_set_clock_state()
942 req = (struct ti_sci_msg_req_set_clock_state *)xfer->xfer_buf; in ti_sci_set_clock_state()
943 req->dev_id = dev_id; in ti_sci_set_clock_state()
944 req->clk_id = clk_id; in ti_sci_set_clock_state()
945 req->request_state = state; in ti_sci_set_clock_state()
949 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_set_clock_state()
953 resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; in ti_sci_set_clock_state()
955 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; in ti_sci_set_clock_state()
958 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_set_clock_state()
964 * ti_sci_cmd_get_clock_state() - Get clock state helper
965 * @handle: pointer to TI SCI handle
983 struct device *dev; in ti_sci_cmd_get_clock_state() local
989 return -EINVAL; in ti_sci_cmd_get_clock_state()
992 return -EINVAL; in ti_sci_cmd_get_clock_state()
995 dev = info->dev; in ti_sci_cmd_get_clock_state()
1002 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_get_clock_state()
1005 req = (struct ti_sci_msg_req_get_clock_state *)xfer->xfer_buf; in ti_sci_cmd_get_clock_state()
1006 req->dev_id = dev_id; in ti_sci_cmd_get_clock_state()
1007 req->clk_id = clk_id; in ti_sci_cmd_get_clock_state()
1011 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_get_clock_state()
1015 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->xfer_buf; in ti_sci_cmd_get_clock_state()
1018 ret = -ENODEV; in ti_sci_cmd_get_clock_state()
1023 *programmed_state = resp->programmed_state; in ti_sci_cmd_get_clock_state()
1025 *current_state = resp->current_state; in ti_sci_cmd_get_clock_state()
1028 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_get_clock_state()
1034 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
1035 * @handle: pointer to TI SCI handle
1061 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
1062 * @handle: pointer to TI SCI handle
1080 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
1081 * @handle: pointer to TI SCI handle
1099 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
1100 * @handle: pointer to TI SCI handle
1116 return -EINVAL; in ti_sci_cmd_clk_is_auto()
1127 * ti_sci_cmd_clk_is_on() - Is the clock ON
1128 * @handle: pointer to TI SCI handle
1145 return -EINVAL; in ti_sci_cmd_clk_is_on()
1160 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1161 * @handle: pointer to TI SCI handle
1178 return -EINVAL; in ti_sci_cmd_clk_is_off()
1193 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1194 * @handle: pointer to TI SCI handle
1210 struct device *dev; in ti_sci_cmd_clk_set_parent() local
1216 return -EINVAL; in ti_sci_cmd_clk_set_parent()
1219 dev = info->dev; in ti_sci_cmd_clk_set_parent()
1226 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_clk_set_parent()
1229 req = (struct ti_sci_msg_req_set_clock_parent *)xfer->xfer_buf; in ti_sci_cmd_clk_set_parent()
1230 req->dev_id = dev_id; in ti_sci_cmd_clk_set_parent()
1231 req->clk_id = clk_id; in ti_sci_cmd_clk_set_parent()
1232 req->parent_id = parent_id; in ti_sci_cmd_clk_set_parent()
1236 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_clk_set_parent()
1240 resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; in ti_sci_cmd_clk_set_parent()
1242 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; in ti_sci_cmd_clk_set_parent()
1245 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_clk_set_parent()
1251 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1252 * @handle: pointer to TI SCI handle
1268 struct device *dev; in ti_sci_cmd_clk_get_parent() local
1274 return -EINVAL; in ti_sci_cmd_clk_get_parent()
1277 dev = info->dev; in ti_sci_cmd_clk_get_parent()
1284 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_clk_get_parent()
1287 req = (struct ti_sci_msg_req_get_clock_parent *)xfer->xfer_buf; in ti_sci_cmd_clk_get_parent()
1288 req->dev_id = dev_id; in ti_sci_cmd_clk_get_parent()
1289 req->clk_id = clk_id; in ti_sci_cmd_clk_get_parent()
1293 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_clk_get_parent()
1297 resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->xfer_buf; in ti_sci_cmd_clk_get_parent()
1300 ret = -ENODEV; in ti_sci_cmd_clk_get_parent()
1302 *parent_id = resp->parent_id; in ti_sci_cmd_clk_get_parent()
1305 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_clk_get_parent()
1311 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1312 * @handle: pointer to TI SCI handle
1329 struct device *dev; in ti_sci_cmd_clk_get_num_parents() local
1335 return -EINVAL; in ti_sci_cmd_clk_get_num_parents()
1338 dev = info->dev; in ti_sci_cmd_clk_get_num_parents()
1345 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_clk_get_num_parents()
1348 req = (struct ti_sci_msg_req_get_clock_num_parents *)xfer->xfer_buf; in ti_sci_cmd_clk_get_num_parents()
1349 req->dev_id = dev_id; in ti_sci_cmd_clk_get_num_parents()
1350 req->clk_id = clk_id; in ti_sci_cmd_clk_get_num_parents()
1354 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_clk_get_num_parents()
1358 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)xfer->xfer_buf; in ti_sci_cmd_clk_get_num_parents()
1361 ret = -ENODEV; in ti_sci_cmd_clk_get_num_parents()
1363 *num_parents = resp->num_parents; in ti_sci_cmd_clk_get_num_parents()
1366 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_clk_get_num_parents()
1372 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1373 * @handle: pointer to TI SCI handle
1399 struct device *dev; in ti_sci_cmd_clk_get_match_freq() local
1405 return -EINVAL; in ti_sci_cmd_clk_get_match_freq()
1408 dev = info->dev; in ti_sci_cmd_clk_get_match_freq()
1415 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_clk_get_match_freq()
1418 req = (struct ti_sci_msg_req_query_clock_freq *)xfer->xfer_buf; in ti_sci_cmd_clk_get_match_freq()
1419 req->dev_id = dev_id; in ti_sci_cmd_clk_get_match_freq()
1420 req->clk_id = clk_id; in ti_sci_cmd_clk_get_match_freq()
1421 req->min_freq_hz = min_freq; in ti_sci_cmd_clk_get_match_freq()
1422 req->target_freq_hz = target_freq; in ti_sci_cmd_clk_get_match_freq()
1423 req->max_freq_hz = max_freq; in ti_sci_cmd_clk_get_match_freq()
1427 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_clk_get_match_freq()
1431 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->xfer_buf; in ti_sci_cmd_clk_get_match_freq()
1434 ret = -ENODEV; in ti_sci_cmd_clk_get_match_freq()
1436 *match_freq = resp->freq_hz; in ti_sci_cmd_clk_get_match_freq()
1439 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_clk_get_match_freq()
1445 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1446 * @handle: pointer to TI SCI handle
1470 struct device *dev; in ti_sci_cmd_clk_set_freq() local
1476 return -EINVAL; in ti_sci_cmd_clk_set_freq()
1479 dev = info->dev; in ti_sci_cmd_clk_set_freq()
1486 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_clk_set_freq()
1489 req = (struct ti_sci_msg_req_set_clock_freq *)xfer->xfer_buf; in ti_sci_cmd_clk_set_freq()
1490 req->dev_id = dev_id; in ti_sci_cmd_clk_set_freq()
1491 req->clk_id = clk_id; in ti_sci_cmd_clk_set_freq()
1492 req->min_freq_hz = min_freq; in ti_sci_cmd_clk_set_freq()
1493 req->target_freq_hz = target_freq; in ti_sci_cmd_clk_set_freq()
1494 req->max_freq_hz = max_freq; in ti_sci_cmd_clk_set_freq()
1498 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_clk_set_freq()
1502 resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; in ti_sci_cmd_clk_set_freq()
1504 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV; in ti_sci_cmd_clk_set_freq()
1507 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_clk_set_freq()
1513 * ti_sci_cmd_clk_get_freq() - Get current frequency
1514 * @handle: pointer to TI SCI handle
1530 struct device *dev; in ti_sci_cmd_clk_get_freq() local
1536 return -EINVAL; in ti_sci_cmd_clk_get_freq()
1539 dev = info->dev; in ti_sci_cmd_clk_get_freq()
1546 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_clk_get_freq()
1549 req = (struct ti_sci_msg_req_get_clock_freq *)xfer->xfer_buf; in ti_sci_cmd_clk_get_freq()
1550 req->dev_id = dev_id; in ti_sci_cmd_clk_get_freq()
1551 req->clk_id = clk_id; in ti_sci_cmd_clk_get_freq()
1555 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_clk_get_freq()
1559 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->xfer_buf; in ti_sci_cmd_clk_get_freq()
1562 ret = -ENODEV; in ti_sci_cmd_clk_get_freq()
1564 *freq = resp->freq_hz; in ti_sci_cmd_clk_get_freq()
1567 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_clk_get_freq()
1578 struct device *dev; in ti_sci_cmd_core_reboot() local
1584 return -EINVAL; in ti_sci_cmd_core_reboot()
1587 dev = info->dev; in ti_sci_cmd_core_reboot()
1594 dev_err(dev, "Message alloc failed(%d)\n", ret); in ti_sci_cmd_core_reboot()
1597 req = (struct ti_sci_msg_req_reboot *)xfer->xfer_buf; in ti_sci_cmd_core_reboot()
1601 dev_err(dev, "Mbox send fail %d\n", ret); in ti_sci_cmd_core_reboot()
1605 resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; in ti_sci_cmd_core_reboot()
1608 ret = -ENODEV; in ti_sci_cmd_core_reboot()
1613 ti_sci_put_one_xfer(&info->minfo, xfer); in ti_sci_cmd_core_reboot()
1619 * ti_sci_setup_ops() - Setup the operations structures
1624 struct ti_sci_ops *ops = &info->handle.ops; in ti_sci_setup_ops()
1625 struct ti_sci_core_ops *core_ops = &ops->core_ops; in ti_sci_setup_ops()
1626 struct ti_sci_dev_ops *dops = &ops->dev_ops; in ti_sci_setup_ops()
1627 struct ti_sci_clk_ops *cops = &ops->clk_ops; in ti_sci_setup_ops()
1629 core_ops->reboot_device = ti_sci_cmd_core_reboot; in ti_sci_setup_ops()
1631 dops->get_device = ti_sci_cmd_get_device; in ti_sci_setup_ops()
1632 dops->idle_device = ti_sci_cmd_idle_device; in ti_sci_setup_ops()
1633 dops->put_device = ti_sci_cmd_put_device; in ti_sci_setup_ops()
1635 dops->is_valid = ti_sci_cmd_dev_is_valid; in ti_sci_setup_ops()
1636 dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt; in ti_sci_setup_ops()
1637 dops->is_idle = ti_sci_cmd_dev_is_idle; in ti_sci_setup_ops()
1638 dops->is_stop = ti_sci_cmd_dev_is_stop; in ti_sci_setup_ops()
1639 dops->is_on = ti_sci_cmd_dev_is_on; in ti_sci_setup_ops()
1640 dops->is_transitioning = ti_sci_cmd_dev_is_trans; in ti_sci_setup_ops()
1641 dops->set_device_resets = ti_sci_cmd_set_device_resets; in ti_sci_setup_ops()
1642 dops->get_device_resets = ti_sci_cmd_get_device_resets; in ti_sci_setup_ops()
1644 cops->get_clock = ti_sci_cmd_get_clock; in ti_sci_setup_ops()
1645 cops->idle_clock = ti_sci_cmd_idle_clock; in ti_sci_setup_ops()
1646 cops->put_clock = ti_sci_cmd_put_clock; in ti_sci_setup_ops()
1647 cops->is_auto = ti_sci_cmd_clk_is_auto; in ti_sci_setup_ops()
1648 cops->is_on = ti_sci_cmd_clk_is_on; in ti_sci_setup_ops()
1649 cops->is_off = ti_sci_cmd_clk_is_off; in ti_sci_setup_ops()
1651 cops->set_parent = ti_sci_cmd_clk_set_parent; in ti_sci_setup_ops()
1652 cops->get_parent = ti_sci_cmd_clk_get_parent; in ti_sci_setup_ops()
1653 cops->get_num_parents = ti_sci_cmd_clk_get_num_parents; in ti_sci_setup_ops()
1655 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq; in ti_sci_setup_ops()
1656 cops->set_freq = ti_sci_cmd_clk_set_freq; in ti_sci_setup_ops()
1657 cops->get_freq = ti_sci_cmd_clk_get_freq; in ti_sci_setup_ops()
1661 * ti_sci_get_handle() - Get the TI SCI handle for a device
1662 * @dev: Pointer to device for which we want SCI handle
1665 * and is expected to be maintained by caller of TI SCI protocol library.
1668 * -EPROBE_DEFER if the instance is not ready
1669 * -ENODEV if the required node handler is missing
1670 * -EINVAL if invalid conditions are encountered.
1672 const struct ti_sci_handle *ti_sci_get_handle(struct device *dev) in ti_sci_get_handle() argument
1679 if (!dev) { in ti_sci_get_handle()
1681 return ERR_PTR(-EINVAL); in ti_sci_get_handle()
1683 ti_sci_np = of_get_parent(dev->of_node); in ti_sci_get_handle()
1685 dev_err(dev, "No OF information\n"); in ti_sci_get_handle()
1686 return ERR_PTR(-EINVAL); in ti_sci_get_handle()
1692 if (ti_sci_np == info->dev->of_node) { in ti_sci_get_handle()
1693 handle = &info->handle; in ti_sci_get_handle()
1694 info->users++; in ti_sci_get_handle()
1702 return ERR_PTR(-EPROBE_DEFER); in ti_sci_get_handle()
1709 * ti_sci_put_handle() - Release the handle acquired by ti_sci_get_handle
1713 * and is expected to be maintained by caller of TI SCI protocol library.
1718 * if null was passed, it returns -EINVAL;
1727 return -EINVAL; in ti_sci_put_handle()
1731 if (!WARN_ON(!info->users)) in ti_sci_put_handle()
1732 info->users--; in ti_sci_put_handle()
1739 static void devm_ti_sci_release(struct device *dev, void *res) in devm_ti_sci_release() argument
1747 dev_err(dev, "failed to put handle %d\n", ret); in devm_ti_sci_release()
1751 * devm_ti_sci_get_handle() - Managed get handle
1752 * @dev: device for which we want SCI handle for.
1757 * and is expected to be maintained by caller of TI SCI protocol library.
1761 const struct ti_sci_handle *devm_ti_sci_get_handle(struct device *dev) in devm_ti_sci_get_handle() argument
1768 return ERR_PTR(-ENOMEM); in devm_ti_sci_get_handle()
1769 handle = ti_sci_get_handle(dev); in devm_ti_sci_get_handle()
1773 devres_add(dev, ptr); in devm_ti_sci_get_handle()
1786 const struct ti_sci_handle *handle = &info->handle; in tisci_reboot_handler()
1805 {.compatible = "ti,k2g-sci", .data = &ti_sci_pmmc_k2g_desc},
1812 struct device *dev = &pdev->dev; in ti_sci_probe() local
1819 int ret = -EINVAL; in ti_sci_probe()
1823 of_id = of_match_device(ti_sci_of_match, dev); in ti_sci_probe()
1825 dev_err(dev, "OF data missing\n"); in ti_sci_probe()
1826 return -EINVAL; in ti_sci_probe()
1828 desc = of_id->data; in ti_sci_probe()
1830 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); in ti_sci_probe()
1832 return -ENOMEM; in ti_sci_probe()
1834 info->dev = dev; in ti_sci_probe()
1835 info->desc = desc; in ti_sci_probe()
1836 reboot = of_property_read_bool(dev->of_node, in ti_sci_probe()
1837 "ti,system-reboot-controller"); in ti_sci_probe()
1838 INIT_LIST_HEAD(&info->node); in ti_sci_probe()
1839 minfo = &info->minfo; in ti_sci_probe()
1842 * Pre-allocate messages in ti_sci_probe()
1846 if (WARN_ON(desc->max_msgs >= in ti_sci_probe()
1847 1 << 8 * sizeof(((struct ti_sci_msg_hdr *)0)->seq))) in ti_sci_probe()
1848 return -EINVAL; in ti_sci_probe()
1850 minfo->xfer_block = devm_kcalloc(dev, in ti_sci_probe()
1851 desc->max_msgs, in ti_sci_probe()
1852 sizeof(*minfo->xfer_block), in ti_sci_probe()
1854 if (!minfo->xfer_block) in ti_sci_probe()
1855 return -ENOMEM; in ti_sci_probe()
1857 minfo->xfer_alloc_table = devm_kcalloc(dev, in ti_sci_probe()
1858 BITS_TO_LONGS(desc->max_msgs), in ti_sci_probe()
1861 if (!minfo->xfer_alloc_table) in ti_sci_probe()
1862 return -ENOMEM; in ti_sci_probe()
1863 bitmap_zero(minfo->xfer_alloc_table, desc->max_msgs); in ti_sci_probe()
1865 /* Pre-initialize the buffer pointer to pre-allocated buffers */ in ti_sci_probe()
1866 for (i = 0, xfer = minfo->xfer_block; i < desc->max_msgs; i++, xfer++) { in ti_sci_probe()
1867 xfer->xfer_buf = devm_kcalloc(dev, 1, desc->max_msg_size, in ti_sci_probe()
1869 if (!xfer->xfer_buf) in ti_sci_probe()
1870 return -ENOMEM; in ti_sci_probe()
1872 xfer->tx_message.buf = xfer->xfer_buf; in ti_sci_probe()
1873 init_completion(&xfer->done); in ti_sci_probe()
1878 dev_warn(dev, "Failed to create debug file\n"); in ti_sci_probe()
1882 cl = &info->cl; in ti_sci_probe()
1883 cl->dev = dev; in ti_sci_probe()
1884 cl->tx_block = false; in ti_sci_probe()
1885 cl->rx_callback = ti_sci_rx_callback; in ti_sci_probe()
1886 cl->knows_txdone = true; in ti_sci_probe()
1888 spin_lock_init(&minfo->xfer_lock); in ti_sci_probe()
1889 sema_init(&minfo->sem_xfer_count, desc->max_msgs); in ti_sci_probe()
1891 info->chan_rx = mbox_request_channel_byname(cl, "rx"); in ti_sci_probe()
1892 if (IS_ERR(info->chan_rx)) { in ti_sci_probe()
1893 ret = PTR_ERR(info->chan_rx); in ti_sci_probe()
1897 info->chan_tx = mbox_request_channel_byname(cl, "tx"); in ti_sci_probe()
1898 if (IS_ERR(info->chan_tx)) { in ti_sci_probe()
1899 ret = PTR_ERR(info->chan_tx); in ti_sci_probe()
1904 dev_err(dev, "Unable to communicate with TISCI(%d)\n", ret); in ti_sci_probe()
1911 info->nb.notifier_call = tisci_reboot_handler; in ti_sci_probe()
1912 info->nb.priority = 128; in ti_sci_probe()
1914 ret = register_restart_handler(&info->nb); in ti_sci_probe()
1916 dev_err(dev, "reboot registration fail(%d)\n", ret); in ti_sci_probe()
1921 dev_info(dev, "ABI: %d.%d (firmware rev 0x%04x '%s')\n", in ti_sci_probe()
1922 info->handle.version.abi_major, info->handle.version.abi_minor, in ti_sci_probe()
1923 info->handle.version.firmware_revision, in ti_sci_probe()
1924 info->handle.version.firmware_description); in ti_sci_probe()
1927 list_add_tail(&info->node, &ti_sci_list); in ti_sci_probe()
1930 return of_platform_populate(dev->of_node, NULL, NULL, dev); in ti_sci_probe()
1932 if (!IS_ERR(info->chan_tx)) in ti_sci_probe()
1933 mbox_free_channel(info->chan_tx); in ti_sci_probe()
1934 if (!IS_ERR(info->chan_rx)) in ti_sci_probe()
1935 mbox_free_channel(info->chan_rx); in ti_sci_probe()
1936 debugfs_remove(info->d); in ti_sci_probe()
1943 struct device *dev = &pdev->dev; in ti_sci_remove() local
1946 of_platform_depopulate(dev); in ti_sci_remove()
1950 if (info->nb.notifier_call) in ti_sci_remove()
1951 unregister_restart_handler(&info->nb); in ti_sci_remove()
1954 if (info->users) in ti_sci_remove()
1955 ret = -EBUSY; in ti_sci_remove()
1957 list_del(&info->node); in ti_sci_remove()
1964 mbox_free_channel(info->chan_tx); in ti_sci_remove()
1965 mbox_free_channel(info->chan_rx); in ti_sci_remove()
1975 .name = "ti-sci",
1982 MODULE_DESCRIPTION("TI System Control Interface(SCI) driver");
1984 MODULE_ALIAS("platform:ti-sci");