Skip to content

Commit

Permalink
i2c: sh_mobile: use core helper to decide when to use DMA
Browse files Browse the repository at this point in the history
This ensures that we fall back to PIO if the message length is too small
for DMA being useful. Otherwise, we use DMA. A bounce buffer might be
applied by the helper if the original message buffer is not DMA safe.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Wolfram Sang authored and Wolfram Sang committed Dec 3, 2017
1 parent d4e0118 commit fe23aa9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/i2c/busses/i2c-sh_mobile.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ struct sh_mobile_i2c_data {
struct dma_chan *dma_rx;
struct scatterlist sg;
enum dma_data_direction dma_direction;
u8 *dma_buf;
};

struct sh_mobile_dt_config {
Expand Down Expand Up @@ -501,6 +502,8 @@ static void sh_mobile_i2c_dma_callback(void *data)
pd->pos = pd->msg->len;
pd->stop_after_dma = true;

i2c_release_dma_safe_msg_buf(pd->msg, pd->dma_buf);

iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
}

Expand Down Expand Up @@ -561,7 +564,7 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
if (IS_ERR(chan))
return;

dma_addr = dma_map_single(chan->device->dev, pd->msg->buf, pd->msg->len, dir);
dma_addr = dma_map_single(chan->device->dev, pd->dma_buf, pd->msg->len, dir);
if (dma_mapping_error(chan->device->dev, dma_addr)) {
dev_dbg(pd->dev, "dma map failed, using PIO\n");
return;
Expand Down Expand Up @@ -618,7 +621,8 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg,
pd->pos = -1;
pd->sr = 0;

if (pd->msg->len > 8)
pd->dma_buf = i2c_get_dma_safe_msg_buf(pd->msg, 8);
if (pd->dma_buf)
sh_mobile_i2c_xfer_dma(pd);

/* Enable all interrupts to begin with */
Expand Down

0 comments on commit fe23aa9

Please sign in to comment.