Lines Matching +full:ctrl +full:- +full:a

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2017, The Linux Foundation
11 * slim_msg_response() - Deliver Message response received from a device to the
14 * @ctrl: Controller handle
20 * This helps in making the API asynchronous, and controller-driver doesn't need
24 void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len) in slim_msg_response() argument
30 spin_lock_irqsave(&ctrl->txn_lock, flags); in slim_msg_response()
31 txn = idr_find(&ctrl->tid_idr, tid); in slim_msg_response()
32 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_msg_response()
37 msg = txn->msg; in slim_msg_response()
38 if (msg == NULL || msg->rbuf == NULL) { in slim_msg_response()
39 dev_err(ctrl->dev, "Got response to invalid TID:%d, len:%d\n", in slim_msg_response()
44 slim_free_txn_tid(ctrl, txn); in slim_msg_response()
45 memcpy(msg->rbuf, reply, len); in slim_msg_response()
46 if (txn->comp) in slim_msg_response()
47 complete(txn->comp); in slim_msg_response()
49 /* Remove runtime-pm vote now that response was received for TID txn */ in slim_msg_response()
50 pm_runtime_mark_last_busy(ctrl->dev); in slim_msg_response()
51 pm_runtime_put_autosuspend(ctrl->dev); in slim_msg_response()
56 * slim_alloc_txn_tid() - Allocate a tid to txn
58 * @ctrl: Controller handle
61 * Return: zero on success with valid txn->tid and error code on failures.
63 int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn) in slim_alloc_txn_tid() argument
68 spin_lock_irqsave(&ctrl->txn_lock, flags); in slim_alloc_txn_tid()
69 ret = idr_alloc_cyclic(&ctrl->tid_idr, txn, 1, in slim_alloc_txn_tid()
72 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_alloc_txn_tid()
75 txn->tid = ret; in slim_alloc_txn_tid()
76 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_alloc_txn_tid()
82 * slim_free_txn_tid() - Free tid of txn
84 * @ctrl: Controller handle
87 void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn) in slim_free_txn_tid() argument
91 spin_lock_irqsave(&ctrl->txn_lock, flags); in slim_free_txn_tid()
92 idr_remove(&ctrl->tid_idr, txn->tid); in slim_free_txn_tid()
93 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_free_txn_tid()
98 * slim_do_transfer() - Process a SLIMbus-messaging transaction
100 * @ctrl: Controller handle
104 * Interface/Value elements. (e.g. transmitting a message to assign logical
105 * address to a slave device
107 * Return: -ETIMEDOUT: If transmission of this message timed out
110 int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) in slim_do_transfer() argument
118 * do not vote for runtime-PM if the transactions are part of clock in slim_do_transfer()
121 if (ctrl->sched.clk_state == SLIM_CLK_ENTERING_PAUSE && in slim_do_transfer()
122 (txn->mt == SLIM_MSG_MT_CORE && in slim_do_transfer()
123 txn->mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION && in slim_do_transfer()
124 txn->mc <= SLIM_MSG_MC_RECONFIGURE_NOW)) in slim_do_transfer()
128 ret = pm_runtime_get_sync(ctrl->dev); in slim_do_transfer()
129 if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) { in slim_do_transfer()
130 dev_err(ctrl->dev, "ctrl wrong state:%d, ret:%d\n", in slim_do_transfer()
131 ctrl->sched.clk_state, ret); in slim_do_transfer()
136 txn->tid = 0; in slim_do_transfer()
137 need_tid = slim_tid_txn(txn->mt, txn->mc); in slim_do_transfer()
140 ret = slim_alloc_txn_tid(ctrl, txn); in slim_do_transfer()
144 if (!txn->msg->comp) in slim_do_transfer()
145 txn->comp = &done; in slim_do_transfer()
147 txn->comp = txn->comp; in slim_do_transfer()
150 ret = ctrl->xfer_msg(ctrl, txn); in slim_do_transfer()
152 if (!ret && need_tid && !txn->msg->comp) { in slim_do_transfer()
153 unsigned long ms = txn->rl + HZ; in slim_do_transfer()
155 time_left = wait_for_completion_timeout(txn->comp, in slim_do_transfer()
158 ret = -ETIMEDOUT; in slim_do_transfer()
159 slim_free_txn_tid(ctrl, txn); in slim_do_transfer()
164 dev_err(ctrl->dev, "Tx:MT:0x%x, MC:0x%x, LA:0x%x failed:%d\n", in slim_do_transfer()
165 txn->mt, txn->mc, txn->la, ret); in slim_do_transfer()
168 if (!clk_pause_msg && (txn->tid == 0 || ret == -ETIMEDOUT)) { in slim_do_transfer()
170 * remove runtime-pm vote if this was TX only, or in slim_do_transfer()
173 pm_runtime_mark_last_busy(ctrl->dev); in slim_do_transfer()
174 pm_runtime_put_autosuspend(ctrl->dev); in slim_do_transfer()
180 static int slim_val_inf_sanity(struct slim_controller *ctrl, in slim_val_inf_sanity() argument
183 if (!msg || msg->num_bytes > 16 || in slim_val_inf_sanity()
184 (msg->start_offset + msg->num_bytes) > 0xC00) in slim_val_inf_sanity()
189 if (msg->rbuf != NULL) in slim_val_inf_sanity()
195 if (msg->wbuf != NULL) in slim_val_inf_sanity()
201 if (msg->rbuf != NULL && msg->wbuf != NULL) in slim_val_inf_sanity()
207 dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n", in slim_val_inf_sanity()
208 msg->start_offset, mc); in slim_val_inf_sanity()
209 return -EINVAL; in slim_val_inf_sanity()
220 return sizetocode[code - 1]; in slim_slicesize()
224 * slim_xfer_msg() - Transfer a value info message on slim device
230 * Called by drivers which want to transfer a vlaue or info elements.
232 * Return: -ETIMEDOUT: If transmission of this message timed out
237 DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg); in slim_xfer_msg()
239 struct slim_controller *ctrl = sbdev->ctrl; in slim_xfer_msg() local
243 if (!ctrl) in slim_xfer_msg()
244 return -EINVAL; in slim_xfer_msg()
246 ret = slim_val_inf_sanity(ctrl, msg, mc); in slim_xfer_msg()
250 sl = slim_slicesize(msg->num_bytes); in slim_xfer_msg()
252 dev_dbg(ctrl->dev, "SB xfer msg:os:%x, len:%d, MC:%x, sl:%x\n", in slim_xfer_msg()
253 msg->start_offset, msg->num_bytes, mc, sl); in slim_xfer_msg()
255 txn->ec = ((sl | (1 << 3)) | ((msg->start_offset & 0xFFF) << 4)); in slim_xfer_msg()
262 txn->rl += msg->num_bytes; in slim_xfer_msg()
268 if (slim_tid_txn(txn->mt, txn->mc)) in slim_xfer_msg()
269 txn->rl++; in slim_xfer_msg()
271 return slim_do_transfer(ctrl, txn); in slim_xfer_msg()
278 msg->start_offset = addr; in slim_fill_msg()
279 msg->num_bytes = count; in slim_fill_msg()
280 msg->rbuf = rbuf; in slim_fill_msg()
281 msg->wbuf = wbuf; in slim_fill_msg()
282 msg->comp = NULL; in slim_fill_msg()
286 * slim_read() - Read SLIMbus value element
293 * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
308 * slim_readb() - Read byte from SLIMbus value element
329 * slim_write() - Write SLIMbus value element
336 * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
351 * slim_writeb() - Write byte to SLIMbus value element
357 * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of