From: Marek Vasut <marex@denx.de>
To: Yuan Yao <yao.yuan@freescale.com>
Cc: wsa@the-dreams.de, LW@karo-electronics.de, mark.rutland@arm.com,
fugang.duan@freescale.com, shawn.guo@linaro.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH v7 1/2] i2c: imx: add DMA support for freescale i2c driver
Date: Thu, 4 Sep 2014 16:38:45 +0200 [thread overview]
Message-ID: <201409041638.45537.marex@denx.de> (raw)
In-Reply-To: <1407923215-3749-2-git-send-email-yao.yuan@freescale.com>
On Wednesday, August 13, 2014 at 11:46:54 AM, Yuan Yao wrote:
> Add dma support for i2c. This function depend on DMA driver.
> You can turn on it by write both the dmas and dma-name properties in dts
> node. DMA is optional, even DMA request unsuccessfully, i2c can also work
> well.
>
> Signed-off-by: Yuan Yao <yao.yuan@freescale.com>
[...]
> +/* Enable DMA if transfer byte size is bigger than this threshold.
> + * As the hardware request, it must bigger than 4.
The comment is unclear, just by reading it, I have no clue what are the units
for this value. I can guess those would be bytes, but it would be a good idea
to be explicit.
Also, wasn't kernel comment style starting with leading /* , with the text
starting only on the next line ?
> + */
> +#define IMX_I2C_DMA_THRESHOLD 16
> +#define IMX_I2C_DMA_TIMEOUT 1000
> +
[...]
> +static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
> + struct i2c_msg *msgs)
> +{
> + int result;
> + unsigned int temp = 0;
> + unsigned long orig_jiffies = jiffies;
> + struct imx_i2c_dma *dma = i2c_imx->dma;
> + struct device *dev = &i2c_imx->adapter.dev;
> +
> + dev_dbg(dev, "<%s> write slave address: addr=0x%x\n",
> + __func__, msgs->addr << 1);
> +
> + reinit_completion(&i2c_imx->dma->cmd_complete);
> + dma->chan_using = dma->chan_tx;
> + dma->dma_transfer_dir = DMA_MEM_TO_DEV;
> + dma->dma_data_dir = DMA_TO_DEVICE;
> + dma->dma_len = msgs->len - 1;
> + result = i2c_imx_dma_xfer(i2c_imx, msgs);
> + if (result)
> + return result;
> +
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> + temp |= I2CR_DMAEN;
> + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> +
> + /*
> + * Write slave address.
> + * The first byte muse be transmitted by the CPU.
> + */
> + imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR);
> + result = wait_for_completion_interruptible_timeout(
> + &i2c_imx->dma->cmd_complete,
> + msecs_to_jiffies(IMX_I2C_DMA_TIMEOUT));
> + if (result <= 0) {
> + dmaengine_terminate_all(dma->chan_using);
> + if (result)
> + return result;
> + else
> + return -ETIMEDOUT;
Shouldn't you force-disable the DMA here somehow (like unsetting I2CR_DMAEN
bit), if it failed or timed out?
> + }
> +
> + /* Waiting for Transfer complete. */
> + while (1) {
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
> + if (temp & I2SR_ICF)
> + break;
> + if (time_after(jiffies, orig_jiffies +
> + msecs_to_jiffies(IMX_I2C_DMA_TIMEOUT))) {
> + dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n",
> + __func__);
> + return -ETIMEDOUT;
> + }
> + schedule();
> + }
> +
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> + temp &= ~I2CR_DMAEN;
> + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> +
> + /* The last data byte must be transferred by the CPU. */
> + imx_i2c_write_reg(msgs->buf[msgs->len-1],
> + i2c_imx, IMX_I2C_I2DR);
> + result = i2c_imx_trx_complete(i2c_imx);
> + if (result)
> + return result;
> +
> + result = i2c_imx_acked(i2c_imx);
> + if (result)
> + return result;
> +
> + return 0;
> +}
[...]
Thanks!
WARNING: multiple messages have this Message-ID (diff)
From: marex@denx.de (Marek Vasut)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 1/2] i2c: imx: add DMA support for freescale i2c driver
Date: Thu, 4 Sep 2014 16:38:45 +0200 [thread overview]
Message-ID: <201409041638.45537.marex@denx.de> (raw)
In-Reply-To: <1407923215-3749-2-git-send-email-yao.yuan@freescale.com>
On Wednesday, August 13, 2014 at 11:46:54 AM, Yuan Yao wrote:
> Add dma support for i2c. This function depend on DMA driver.
> You can turn on it by write both the dmas and dma-name properties in dts
> node. DMA is optional, even DMA request unsuccessfully, i2c can also work
> well.
>
> Signed-off-by: Yuan Yao <yao.yuan@freescale.com>
[...]
> +/* Enable DMA if transfer byte size is bigger than this threshold.
> + * As the hardware request, it must bigger than 4.
The comment is unclear, just by reading it, I have no clue what are the units
for this value. I can guess those would be bytes, but it would be a good idea
to be explicit.
Also, wasn't kernel comment style starting with leading /* , with the text
starting only on the next line ?
> + */
> +#define IMX_I2C_DMA_THRESHOLD 16
> +#define IMX_I2C_DMA_TIMEOUT 1000
> +
[...]
> +static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
> + struct i2c_msg *msgs)
> +{
> + int result;
> + unsigned int temp = 0;
> + unsigned long orig_jiffies = jiffies;
> + struct imx_i2c_dma *dma = i2c_imx->dma;
> + struct device *dev = &i2c_imx->adapter.dev;
> +
> + dev_dbg(dev, "<%s> write slave address: addr=0x%x\n",
> + __func__, msgs->addr << 1);
> +
> + reinit_completion(&i2c_imx->dma->cmd_complete);
> + dma->chan_using = dma->chan_tx;
> + dma->dma_transfer_dir = DMA_MEM_TO_DEV;
> + dma->dma_data_dir = DMA_TO_DEVICE;
> + dma->dma_len = msgs->len - 1;
> + result = i2c_imx_dma_xfer(i2c_imx, msgs);
> + if (result)
> + return result;
> +
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> + temp |= I2CR_DMAEN;
> + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> +
> + /*
> + * Write slave address.
> + * The first byte muse be transmitted by the CPU.
> + */
> + imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR);
> + result = wait_for_completion_interruptible_timeout(
> + &i2c_imx->dma->cmd_complete,
> + msecs_to_jiffies(IMX_I2C_DMA_TIMEOUT));
> + if (result <= 0) {
> + dmaengine_terminate_all(dma->chan_using);
> + if (result)
> + return result;
> + else
> + return -ETIMEDOUT;
Shouldn't you force-disable the DMA here somehow (like unsetting I2CR_DMAEN
bit), if it failed or timed out?
> + }
> +
> + /* Waiting for Transfer complete. */
> + while (1) {
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
> + if (temp & I2SR_ICF)
> + break;
> + if (time_after(jiffies, orig_jiffies +
> + msecs_to_jiffies(IMX_I2C_DMA_TIMEOUT))) {
> + dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n",
> + __func__);
> + return -ETIMEDOUT;
> + }
> + schedule();
> + }
> +
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> + temp &= ~I2CR_DMAEN;
> + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> +
> + /* The last data byte must be transferred by the CPU. */
> + imx_i2c_write_reg(msgs->buf[msgs->len-1],
> + i2c_imx, IMX_I2C_I2DR);
> + result = i2c_imx_trx_complete(i2c_imx);
> + if (result)
> + return result;
> +
> + result = i2c_imx_acked(i2c_imx);
> + if (result)
> + return result;
> +
> + return 0;
> +}
[...]
Thanks!
next prev parent reply other threads:[~2014-09-04 14:38 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-13 9:46 [PATCH v7 0/2] i2c: imx: add DMA support for freescale i2c driver Yuan Yao
2014-08-13 9:46 ` Yuan Yao
2014-08-13 9:46 ` Yuan Yao
[not found] ` <1407923215-3749-1-git-send-email-yao.yuan-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-08-13 9:46 ` [PATCH v7 1/2] " Yuan Yao
2014-08-13 9:46 ` Yuan Yao
2014-08-13 9:46 ` Yuan Yao
[not found] ` <1407923215-3749-2-git-send-email-yao.yuan-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-09-04 3:38 ` Yao Yuan
2014-09-04 3:38 ` Yao Yuan
2014-09-04 3:38 ` Yao Yuan
2014-09-04 14:38 ` Marek Vasut [this message]
2014-09-04 14:38 ` Marek Vasut
2014-09-05 10:32 ` Yao Yuan
2014-09-05 10:32 ` Yao Yuan
2014-09-05 10:32 ` Yao Yuan
[not found] ` <c10c1960255e4dbca2a281b995290c6d-AZ66ij2kwaZYLYlmg7qx2OO6mTEJWrR4XA4E9RH9d+qIuWR1G4zioA@public.gmane.org>
2014-09-05 10:40 ` Marek Vasut
2014-09-05 10:40 ` Marek Vasut
2014-09-05 10:40 ` Marek Vasut
2014-09-10 14:48 ` Yao Yuan
2014-09-10 14:48 ` Yao Yuan
2014-09-10 14:48 ` Yao Yuan
2014-09-16 18:17 ` Marek Vasut
2014-09-16 18:17 ` Marek Vasut
2014-09-17 14:50 ` Yao Yuan
2014-09-17 14:50 ` Yao Yuan
2014-09-17 14:50 ` Yao Yuan
[not found] ` <1410965416759.91038-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-09-17 19:14 ` Marek Vasut
2014-09-17 19:14 ` Marek Vasut
2014-09-17 19:14 ` Marek Vasut
[not found] ` <201409172114.36617.marex-ynQEQJNshbs@public.gmane.org>
2014-09-18 15:46 ` Yao Yuan
2014-09-18 15:46 ` Yao Yuan
2014-09-18 15:46 ` Yao Yuan
[not found] ` <1411055145666.72178-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2014-09-19 12:15 ` Marek Vasut
2014-09-19 12:15 ` Marek Vasut
2014-09-19 12:15 ` Marek Vasut
2014-08-13 9:46 ` [PATCH v7 2/2] Documentation:add " Yuan Yao
2014-08-13 9:46 ` Yuan Yao
2014-08-13 9:46 ` Yuan Yao
-- strict thread matches above, loose matches on Subject: below --
2014-08-13 9:37 [PATCH v7 1/2] i2c: imx: add " Yuan Yao
2014-08-13 9:37 ` Yuan Yao
2014-08-13 9:37 ` Yuan Yao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201409041638.45537.marex@denx.de \
--to=marex@denx.de \
--cc=LW@karo-electronics.de \
--cc=fugang.duan@freescale.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=shawn.guo@linaro.org \
--cc=wsa@the-dreams.de \
--cc=yao.yuan@freescale.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.