^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2011-2017, The Linux Foundation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "slimbus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * slim_msg_response() - Deliver Message response received from a device to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * framework.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * @ctrl: Controller handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * @reply: Reply received from the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * @len: Length of the reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * @tid: Transaction ID received with which framework can associate reply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Called by controller to inform framework about the response received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * This helps in making the API asynchronous, and controller-driver doesn't need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * to manage 1 more table other than the one managed by framework mapping TID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * with buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct slim_msg_txn *txn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct slim_val_inf *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) spin_lock_irqsave(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) txn = idr_find(&ctrl->tid_idr, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) spin_unlock_irqrestore(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (txn == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) msg = txn->msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (msg == NULL || msg->rbuf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) dev_err(ctrl->dev, "Got response to invalid TID:%d, len:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) tid, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) slim_free_txn_tid(ctrl, txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) memcpy(msg->rbuf, reply, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (txn->comp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) complete(txn->comp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Remove runtime-pm vote now that response was received for TID txn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) pm_runtime_mark_last_busy(ctrl->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) pm_runtime_put_autosuspend(ctrl->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) EXPORT_SYMBOL_GPL(slim_msg_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * slim_alloc_txn_tid() - Allocate a tid to txn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @ctrl: Controller handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @txn: transaction to be allocated with tid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Return: zero on success with valid txn->tid and error code on failures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) spin_lock_irqsave(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ret = idr_alloc_cyclic(&ctrl->tid_idr, txn, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) SLIM_MAX_TIDS, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spin_unlock_irqrestore(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) txn->tid = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spin_unlock_irqrestore(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) EXPORT_SYMBOL_GPL(slim_alloc_txn_tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * slim_free_txn_tid() - Freee tid of txn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @ctrl: Controller handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * @txn: transaction whose tid should be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) spin_lock_irqsave(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) idr_remove(&ctrl->tid_idr, txn->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) spin_unlock_irqrestore(&ctrl->txn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) EXPORT_SYMBOL_GPL(slim_free_txn_tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * slim_do_transfer() - Process a SLIMbus-messaging transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * @ctrl: Controller handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @txn: Transaction to be sent over SLIMbus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Called by controller to transmit messaging transactions not dealing with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Interface/Value elements. (e.g. transmittting a message to assign logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * address to a slave device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * Return: -ETIMEDOUT: If transmission of this message timed out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * (e.g. due to bus lines not being clocked or driven by controller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) DECLARE_COMPLETION_ONSTACK(done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) bool need_tid = false, clk_pause_msg = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int ret, timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * do not vote for runtime-PM if the transactions are part of clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * pause sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (ctrl->sched.clk_state == SLIM_CLK_ENTERING_PAUSE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) (txn->mt == SLIM_MSG_MT_CORE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) txn->mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) txn->mc <= SLIM_MSG_MC_RECONFIGURE_NOW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) clk_pause_msg = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (!clk_pause_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ret = pm_runtime_get_sync(ctrl->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) dev_err(ctrl->dev, "ctrl wrong state:%d, ret:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ctrl->sched.clk_state, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto slim_xfer_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Initialize tid to invalid value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) txn->tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) need_tid = slim_tid_txn(txn->mt, txn->mc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (need_tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ret = slim_alloc_txn_tid(ctrl, txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!txn->msg->comp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) txn->comp = &done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) txn->comp = txn->comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = ctrl->xfer_msg(ctrl, txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!ret && need_tid && !txn->msg->comp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned long ms = txn->rl + HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) timeout = wait_for_completion_timeout(txn->comp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) msecs_to_jiffies(ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ret = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) slim_free_txn_tid(ctrl, txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) dev_err(ctrl->dev, "Tx:MT:0x%x, MC:0x%x, LA:0x%x failed:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) txn->mt, txn->mc, txn->la, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) slim_xfer_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (!clk_pause_msg && (txn->tid == 0 || ret == -ETIMEDOUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * remove runtime-pm vote if this was TX only, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * if there was error during this transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) pm_runtime_mark_last_busy(ctrl->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pm_runtime_put_autosuspend(ctrl->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) EXPORT_SYMBOL_GPL(slim_do_transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int slim_val_inf_sanity(struct slim_controller *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct slim_val_inf *msg, u8 mc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!msg || msg->num_bytes > 16 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) (msg->start_offset + msg->num_bytes) > 0xC00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto reterr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) switch (mc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) case SLIM_MSG_MC_REQUEST_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case SLIM_MSG_MC_REQUEST_INFORMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (msg->rbuf != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) case SLIM_MSG_MC_CHANGE_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case SLIM_MSG_MC_CLEAR_INFORMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (msg->wbuf != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) case SLIM_MSG_MC_REQUEST_CHANGE_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (msg->rbuf != NULL && msg->wbuf != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) reterr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) msg->start_offset, mc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static u16 slim_slicesize(int code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static const u8 sizetocode[16] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) code = clamp(code, 1, (int)ARRAY_SIZE(sizetocode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return sizetocode[code - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * slim_xfer_msg() - Transfer a value info message on slim device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @sbdev: slim device to which this msg has to be transfered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @msg: value info message pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * @mc: message code of the message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Called by drivers which want to transfer a vlaue or info elements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * Return: -ETIMEDOUT: If transmission of this message timed out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) u8 mc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct slim_msg_txn *txn = &txn_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct slim_controller *ctrl = sbdev->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) u16 sl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ret = slim_val_inf_sanity(ctrl, msg, mc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) sl = slim_slicesize(msg->num_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) dev_dbg(ctrl->dev, "SB xfer msg:os:%x, len:%d, MC:%x, sl:%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) msg->start_offset, msg->num_bytes, mc, sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) txn->ec = ((sl | (1 << 3)) | ((msg->start_offset & 0xFFF) << 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) switch (mc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case SLIM_MSG_MC_REQUEST_CHANGE_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case SLIM_MSG_MC_CHANGE_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) case SLIM_MSG_MC_CLEAR_INFORMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) txn->rl += msg->num_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (slim_tid_txn(txn->mt, txn->mc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) txn->rl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return slim_do_transfer(ctrl, txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) EXPORT_SYMBOL_GPL(slim_xfer_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static void slim_fill_msg(struct slim_val_inf *msg, u32 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) size_t count, u8 *rbuf, u8 *wbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) msg->start_offset = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) msg->num_bytes = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) msg->rbuf = rbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) msg->wbuf = wbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) msg->comp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * slim_read() - Read SLIMbus value element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * @sdev: client handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * @addr: address of value element to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * @count: number of bytes to read. Maximum bytes allowed are 16.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * @val: will return what the value element value was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * this message timed out (e.g. due to bus lines not being clocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * or driven by controller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int slim_read(struct slim_device *sdev, u32 addr, size_t count, u8 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct slim_val_inf msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) slim_fill_msg(&msg, addr, count, val, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return slim_xfer_msg(sdev, &msg, SLIM_MSG_MC_REQUEST_VALUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) EXPORT_SYMBOL_GPL(slim_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * slim_readb() - Read byte from SLIMbus value element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * @sdev: client handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * @addr: address in the value element to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * Return: byte value of value element.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int slim_readb(struct slim_device *sdev, u32 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) u8 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ret = slim_read(sdev, addr, 1, &buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) EXPORT_SYMBOL_GPL(slim_readb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * slim_write() - Write SLIMbus value element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * @sdev: client handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * @addr: address in the value element to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * @count: number of bytes to write. Maximum bytes allowed are 16.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * @val: value to write to value element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * this message timed out (e.g. due to bus lines not being clocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * or driven by controller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) int slim_write(struct slim_device *sdev, u32 addr, size_t count, u8 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct slim_val_inf msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) slim_fill_msg(&msg, addr, count, NULL, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return slim_xfer_msg(sdev, &msg, SLIM_MSG_MC_CHANGE_VALUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) EXPORT_SYMBOL_GPL(slim_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * slim_writeb() - Write byte to SLIMbus value element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * @sdev: client handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * @addr: address of value element to write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * @value: value to write to value element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * this message timed out (e.g. due to bus lines not being clocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * or driven by controller)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int slim_writeb(struct slim_device *sdev, u32 addr, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return slim_write(sdev, addr, 1, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) EXPORT_SYMBOL_GPL(slim_writeb);