提交 82fe39a6 编写于 作者: W Wolfram Sang 提交者: Wolfram Sang

i2c: refactor function to release a DMA safe buffer

a) rename to 'put' instead of 'release' to match 'get' when obtaining
   the buffer
b) change the argument order to have the buffer as first argument
c) add a new argument telling the function if the message was
   transferred. This allows the function to be used also in cases
   where setting up DMA failed, so the buffer needs to be freed without
   syncing to the message buffer.

Also convert the only user.
Signed-off-by: NWolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: NNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: NWolfram Sang <wsa@the-dreams.de>
上级 1204d12a
...@@ -50,10 +50,14 @@ bounce buffer. But you don't need to care about that detail, just use the ...@@ -50,10 +50,14 @@ bounce buffer. But you don't need to care about that detail, just use the
returned buffer. If NULL is returned, the threshold was not met or a bounce returned buffer. If NULL is returned, the threshold was not met or a bounce
buffer could not be allocated. Fall back to PIO in that case. buffer could not be allocated. Fall back to PIO in that case.
In any case, a buffer obtained from above needs to be released. It ensures data In any case, a buffer obtained from above needs to be released. Another helper
is copied back to the message and a potentially used bounce buffer is freed:: function ensures a potentially used bounce buffer is freed::
i2c_release_dma_safe_msg_buf(msg, dma_buf); i2c_put_dma_safe_msg_buf(dma_buf, msg, xferred);
The last argument 'xferred' controls if the buffer is synced back to the
message or not. No syncing is needed in cases setting up DMA had an error and
there was no data transferred.
The bounce buffer handling from the core is generic and simple. It will always The bounce buffer handling from the core is generic and simple. It will always
allocate a new bounce buffer. If you want a more sophisticated handling (e.g. allocate a new bounce buffer. If you want a more sophisticated handling (e.g.
......
...@@ -507,7 +507,7 @@ static void sh_mobile_i2c_dma_callback(void *data) ...@@ -507,7 +507,7 @@ static void sh_mobile_i2c_dma_callback(void *data)
pd->pos = pd->msg->len; pd->pos = pd->msg->len;
pd->stop_after_dma = true; pd->stop_after_dma = true;
i2c_release_dma_safe_msg_buf(pd->msg, pd->dma_buf); i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg, true);
iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE); iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
} }
......
...@@ -2293,21 +2293,22 @@ u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold) ...@@ -2293,21 +2293,22 @@ u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf); EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf);
/** /**
* i2c_release_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg * i2c_put_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg
* @msg: the message to be synced with
* @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL. * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL.
* @msg: the message which the buffer corresponds to
* @xferred: bool saying if the message was transferred
*/ */
void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred)
{ {
if (!buf || buf == msg->buf) if (!buf || buf == msg->buf)
return; return;
if (msg->flags & I2C_M_RD) if (xferred && msg->flags & I2C_M_RD)
memcpy(msg->buf, buf, msg->len); memcpy(msg->buf, buf, msg->len);
kfree(buf); kfree(buf);
} }
EXPORT_SYMBOL_GPL(i2c_release_dma_safe_msg_buf); EXPORT_SYMBOL_GPL(i2c_put_dma_safe_msg_buf);
MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
MODULE_DESCRIPTION("I2C-Bus main module"); MODULE_DESCRIPTION("I2C-Bus main module");
......
...@@ -855,7 +855,7 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) ...@@ -855,7 +855,7 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
} }
u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold); u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf); void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr); int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr);
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册