Re: [PATCH v2 0/4] watchdog: add driver for Renesas Gen3 WDT watchdogs

2016-05-14 Thread Wim Van Sebroeck
Hi Wolfram,

> Here is V2 of this series with the following changes:
> 
> * include bitops.h
> * s/unsigned/unsigned int/
> * drop set_timeout() because core does it already
> * add get_timeleft()
> * don't make "nowayout" a readable parameter
> * use "watchdog" instead of "wdt" in the dt bindings
> 
> The dts and defconfig changes should go via Simon's tree once the driver is
> accepted.
> 
> To use this driver, you need a recent firmware/uboot which initializes the
> WDTRSTCR register which can only be changed in secure mode. 'md 0xe6160054 4'
> should give you 0x8002 or something else with bit 15 set and bit 0 cleared.
> 
> Also, you need the clock enablement patches which just have been posted in
> their newest version to the renesas-soc mailing list and are also in
> close-to-be-applied state.
> 
> A complete branch to test can be found here:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/v8-wdt
> 
> Please review, test, comment...
> 
> Thanks,
> 
>Wolfram
> 
> 
> Wolfram Sang (4):
>   watchdog: renesas-wdt: add driver
>   arm64: dts: r8a7795: Add RWDT node
>   arm64: dts: salvator-x: Enable watchdog timer
>   arm64: defconfig: enable Renesas Watchdog Timer
> 
>  .../devicetree/bindings/watchdog/renesas-wdt.txt   |  25 +++
>  arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts |   5 +
>  arch/arm64/boot/dts/renesas/r8a7795.dtsi   |   8 +
>  arch/arm64/configs/defconfig   |   2 +
>  drivers/watchdog/Kconfig   |   8 +
>  drivers/watchdog/Makefile  |   1 +
>  drivers/watchdog/renesas_wdt.c | 213 
> +
>  7 files changed, 262 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
>  create mode 100644 drivers/watchdog/renesas_wdt.c
> 
> -- 
> 2.7.0
>

Patch 1 and 4 have been added to linux-watchdog-next.

Kind regards,
Wim.
 


Re: [PATCH] watchdog: core: fix trivial typo in a comment

2016-05-14 Thread Wim Van Sebroeck
Hi Wolfram,

> From: Wolfram Sang 
> 
> Let's have balanced round brackets.
> 
> Signed-off-by: Wolfram Sang 
> ---
>  drivers/watchdog/watchdog_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/watchdog_core.c 
> b/drivers/watchdog/watchdog_core.c
> index c1658fe73d58a1..6249ed34214a9f 100644
> --- a/drivers/watchdog/watchdog_core.c
> +++ b/drivers/watchdog/watchdog_core.c
> @@ -104,7 +104,7 @@ static void watchdog_check_min_max_timeout(struct 
> watchdog_device *wdd)
>   * timeout module parameter (if it is valid value) or the timeout-sec 
> property
>   * (only if it is a valid value and the timeout_parm is out of bounds).
>   * If none of them are valid then we keep the old value (which should 
> normally
> - * be the default timeout value.
> + * be the default timeout value).
>   *
>   * A zero is returned on success and -EINVAL for failure.
>   */
> -- 
> 2.7.0
> 

This patch has been added to linux-watchdog-next.

Kind regards,
Wim.



[PATCHv2] i2c: rcar: add DMA support

2016-05-14 Thread Niklas Söderlund
Make it possible to transfer i2c message buffers via DMA.
Start/Stop/Sending_Slave_Address and some data is still handled using
the old state machine, it is sending the bulk of the data that is done
via DMA.

The first byte of a transmission and the last two bytes of reception are
sent/received using PIO. This is needed for the HW to have access to the
first byte before DMA transmit and to be able to set the STOP condition
for DMA reception.

Signed-off-by: Niklas Söderlund 
Tested-by: Wolfram Sang 
---

Changes since v1.
- Merge two if stamtents to one if (a || b)
- Droped a blank line insertion
- Added Tested-by tag from Wolfram

 Documentation/devicetree/bindings/i2c/i2c-rcar.txt |   3 +
 drivers/i2c/busses/i2c-rcar.c  | 236 -
 2 files changed, 235 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt 
b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
index cf8bfc9..5f0cb50 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
@@ -19,6 +19,9 @@ Optional properties:
 - clock-frequency: desired I2C bus clock frequency in Hz. The absence of this
   property indicates the default frequency 100 kHz.
 - clocks: clock specifier.
+- dmas: Must contain a list of two references to DMA specifiers, one for
+  transmission, and one for reception.
+- dma-names: Must contain a list of two DMA names, "tx" and "rx".
 
 - i2c-scl-falling-time-ns: see i2c.txt
 - i2c-scl-internal-delay-ns: see i2c.txt
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 68ecb56..6d90fc0 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -21,6 +21,8 @@
  */
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +45,8 @@
 #define ICSAR  0x1C/* slave address */
 #define ICMAR  0x20/* master address */
 #define ICRXTX 0x24/* data port */
+#define ICDMAER0x3c/* DMA enable */
+#define ICFBSCR0x38/* first bit setup cycle */
 
 /* ICSCR */
 #define SDBS   (1 << 3)/* slave data buffer select */
@@ -78,6 +82,16 @@
 #define MDR(1 << 1)
 #define MAT(1 << 0)/* slave addr xfer done */
 
+/* ICDMAER */
+#define RSDMAE (1 << 3)/* DMA Slave Received Enable */
+#define TSDMAE (1 << 2)/* DMA Slave Transmitted Enable */
+#define RMDMAE (1 << 1)/* DMA Master Received Enable */
+#define TMDMAE (1 << 0)/* DMA Master Transmitted Enable */
+
+/* ICFBSCR */
+#define TCYC06 0x04/*  6*Tcyc delay 1st bit between SDA and SCL */
+#define TCYC17 0x0f/* 17*Tcyc delay 1st bit between SDA and SCL */
+
 
 #define RCAR_BUS_PHASE_START   (MDBS | MIE | ESG)
 #define RCAR_BUS_PHASE_DATA(MDBS | MIE)
@@ -120,6 +134,12 @@ struct rcar_i2c_priv {
u32 flags;
enum rcar_i2c_type devtype;
struct i2c_client *slave;
+
+   struct resource *res;
+   struct dma_chan *dma_tx;
+   struct dma_chan *dma_rx;
+   struct scatterlist sg;
+   enum dma_data_direction dma_direction;
 };
 
 #define rcar_i2c_priv_to_dev(p)((p)->adap.dev.parent)
@@ -287,6 +307,121 @@ static void rcar_i2c_next_msg(struct rcar_i2c_priv *priv)
 /*
  * interrupt functions
  */
+static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
+{
+   struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE
+   ? priv->dma_rx : priv->dma_tx;
+
+   /* Disable DMA Master Received/Transmitted */
+   rcar_i2c_write(priv, ICDMAER, 0);
+
+   /* Reset default delay */
+   rcar_i2c_write(priv, ICFBSCR, TCYC06);
+
+   dma_unmap_single(chan->device->dev, sg_dma_address(>sg),
+priv->msg->len, priv->dma_direction);
+
+   priv->dma_direction = DMA_NONE;
+}
+
+static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv)
+{
+   if (priv->dma_direction == DMA_NONE)
+   return;
+   else if (priv->dma_direction == DMA_FROM_DEVICE)
+   dmaengine_terminate_all(priv->dma_rx);
+   else if (priv->dma_direction == DMA_TO_DEVICE)
+   dmaengine_terminate_all(priv->dma_tx);
+
+   rcar_i2c_dma_unmap(priv);
+}
+
+static void rcar_i2c_dma_callback(void *data)
+{
+   struct rcar_i2c_priv *priv = data;
+
+   priv->pos += sg_dma_len(>sg);
+
+   rcar_i2c_dma_unmap(priv);
+}
+
+static void rcar_i2c_dma(struct rcar_i2c_priv *priv)
+{
+   struct device *dev = rcar_i2c_priv_to_dev(priv);
+   struct i2c_msg *msg = priv->msg;
+   bool read = msg->flags & I2C_M_RD;
+   enum dma_data_direction dir = read ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   struct dma_chan *chan = read ? priv->dma_rx : priv->dma_tx;
+   struct dma_async_tx_descriptor *txdesc;
+   dma_addr_t dma_addr;
+   dma_cookie_t cookie;
+   unsigned char 

Re: [PATCH] i2c: rcar: add DMA support

2016-05-14 Thread Niklas Söderlund
Hi Wolfram,

Thanks for your feedback.

On 2016-05-12 23:31:27 +0200, Wolfram Sang wrote:
> Hi Niklas,
> 
> thanks for the submission. I was finally able to test this change.
> 
> On Wed, May 04, 2016 at 02:38:23PM +0200, Niklas Söderlund wrote:
> > Make it possible to transfer i2c message buffers via DMA.
> > Start/Stop/Sending_Slave_Address and some data is still handled using
> > the old state machine, it is sending the bulk of the data that is done
> > via DMA.
> > 
> > The first byte of a transmission and the last two bytes of reception are
> > sent/received using PIO. This is needed for the HW to have access to the
> > first byte before DMA transmit and to be able to set the STOP condition
> > for DMA reception.
> > 
> > Signed-off-by: Niklas Söderlund 
> 
> Tested-by: Wolfram Sang 
> 
> I did regression tests on my Salvator-X trying to trigger previously
> known issues. Nothing bad happened. This could be expected since START
> and STOP is done in PIO mode, but one never knows :) Also did verify
> that DMA is triggered for bigger transfers.
> 
> Did you have time to re-measure the threshold? Also, did you try booting

I did not re-measure the threshold, I'm not sure how to do that in a 
good correct way. I reasoned that I modeled my implementation on the 
sh_mobile-driver and there are roughly the same amount code in the DMA 
code path so I used the same threshold.

> without DMA and on Gen2? We had a bit of hazzle with !DMA with the
> sh_mobile-driver. Boot test and basic i2cdetect will suffice.

I tested in on Koelsch, but I don't have the schematics for the board so 
I could not hookup to an external i2c bus and look at it. But i2cdetect 
is working.

> 
> Patch looks good, only minor nits:
> 
> > +   /* Do not use DMA for messages shorter then 8 bytes */
> > +   if (msg->len < 8)
> > +   return;
> > +
> > +   if (IS_ERR(chan))
> > +   return;
> 
> Make this one if (a || b)?

Fill fix.

> 
> > @@ -516,6 +738,7 @@ static int rcar_i2c_master_xfer(struct i2c_adapter 
> > *adap,
> >  out:
> > pm_runtime_put(dev);
> >  
> > +
> 
> Unrelated change ;)

Fill fix.

> 
> Thanks,
> 
>Wolfram
> 

-- 
Regards,
Niklas Söderlund


Re: [PATCH] dmaengine: of_dma: approximate an average distribution

2016-05-14 Thread Vinod Koul
On Wed, May 11, 2016 at 03:15:11PM +0200, Niklas Söderlund wrote:
> Currently the following DT description would result in dmac0 always
> being tried first and dmac1 second if dmac0 was unavailable. This
> results in heavier use of dmac0 then of dmac1. This patch adds an
> approximate average distribution over the two nodes lessening the load
> of anyone of them.
> 
>i2c6: i2c@e60b {
>...
>dmas = < 0x77>, < 0x78>,
>   < 0x77>, < 0x78>;
>dma-names = "tx", "rx", "tx", "rx";
>...
>};

Applied, thanks

-- 
~Vinod