Linux Audio

Check our new training course

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