Re: [PATCH v9 03/28] rcar-vin: unregister video device on driver removal

2017-12-07 Thread Laurent Pinchart
Hi Niklas,

Thank you for the patch.

On Friday, 8 December 2017 03:08:17 EET Niklas Söderlund wrote:
> If the video device was registered by the complete() callback it should
> be unregistered when the driver is removed.

The .remove() operation indicates device removal, not driver removal (or, the 
be more precise, it indicates that the device is unbound from the driver). I'd 
update the commit message accordingly.

> Protect from printing an uninitialized video device node name by adding a
> check in rvin_v4l2_unregister() to identify that the video device is
> registered.
> 
> Signed-off-by: Niklas Söderlund 
> Reviewed-by: Kieran Bingham 
> Reviewed-by: Hans Verkuil 
> ---
>  drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 3 +++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-core.c
> b/drivers/media/platform/rcar-vin/rcar-core.c index
> f7a4c21909da6923..6d99542ec74b49a7 100644
> --- a/drivers/media/platform/rcar-vin/rcar-core.c
> +++ b/drivers/media/platform/rcar-vin/rcar-core.c
> @@ -272,6 +272,8 @@ static int rcar_vin_remove(struct platform_device *pdev)
> 
>   pm_runtime_disable(>dev);
> 
> + rvin_v4l2_unregister(vin);

Unless I'm mistaken, you're unregistering the video device both here and in 
the unbound() function. That's messy, but it's not really your fault, the V4L2 
core is very messy in the first place, and registering video devices in the 
complete() handler is a bad idea. As that can't be fixed for now,

Acked-by: Laurent Pinchart 

Hans, I still would like to hear your opinion on how this should be solved. 
You've voiced a few weeks ago that register video devices at probe() time 
isn't a good idea but you've never explained how we should fix the problem. I 
still firmly believe that video devices should be registered at probe time, 
and we need to reach an agreement on a technical solution to this problem.

>   v4l2_async_notifier_unregister(>notifier);
>   v4l2_async_notifier_cleanup(>notifier);
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> b/drivers/media/platform/rcar-vin/rcar-v4l2.c index
> 178aecc94962abe2..32a658214f48fa49 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -841,6 +841,9 @@ static const struct v4l2_file_operations rvin_fops = {
> 
>  void rvin_v4l2_unregister(struct rvin_dev *vin)
>  {
> + if (!video_is_registered(>vdev))
> + return;
> +
>   v4l2_info(>v4l2_dev, "Removing %s\n",
> video_device_node_name(>vdev));

-- 
Regards,

Laurent Pinchart



Re: [PATCH v9 02/28] rcar-vin: rename poorly named initialize and cleanup functions

2017-12-07 Thread Laurent Pinchart
Hi Niklas,

Thank you for the patch.

On Friday, 8 December 2017 03:08:16 EET Niklas Söderlund wrote:
> The functions to initialize and cleanup the hardware and video device
> where poorly named from the start. Rename them to better describe their
> intended function.

It's interesting that you describe the functions' purpose as initialize and 
cleanup here and name them register and unregister :-) It's not a big deal, 
but you might want some consistency between the commit message and the code.

> Signed-off-by: Niklas Söderlund 
> Reviewed-by: Kieran Bingham 
> Reviewed-by: Hans Verkuil 

Either way,

Reviewed-by: Laurent Pinchart 

> ---
>  drivers/media/platform/rcar-vin/rcar-core.c | 10 +-
>  drivers/media/platform/rcar-vin/rcar-dma.c  |  6 +++---
>  drivers/media/platform/rcar-vin/rcar-v4l2.c |  4 ++--
>  drivers/media/platform/rcar-vin/rcar-vin.h  |  8 
>  4 files changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-core.c
> b/drivers/media/platform/rcar-vin/rcar-core.c index
> 108d776f32651b27..f7a4c21909da6923 100644
> --- a/drivers/media/platform/rcar-vin/rcar-core.c
> +++ b/drivers/media/platform/rcar-vin/rcar-core.c
> @@ -93,7 +93,7 @@ static int rvin_digital_notify_complete(struct
> v4l2_async_notifier *notifier) return ret;
>   }
> 
> - return rvin_v4l2_probe(vin);
> + return rvin_v4l2_register(vin);
>  }
> 
>  static void rvin_digital_notify_unbind(struct v4l2_async_notifier
> *notifier, @@ -103,7 +103,7 @@ static void
> rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier, struct
> rvin_dev *vin = notifier_to_vin(notifier);
> 
>   vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
> - rvin_v4l2_remove(vin);
> + rvin_v4l2_unregister(vin);
>   vin->digital->subdev = NULL;
>  }
> 
> @@ -245,7 +245,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
>   if (irq < 0)
>   return irq;
> 
> - ret = rvin_dma_probe(vin, irq);
> + ret = rvin_dma_register(vin, irq);
>   if (ret)
>   return ret;
> 
> @@ -260,7 +260,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
> 
>   return 0;
>  error:
> - rvin_dma_remove(vin);
> + rvin_dma_unregister(vin);
>   v4l2_async_notifier_cleanup(>notifier);
> 
>   return ret;
> @@ -275,7 +275,7 @@ static int rcar_vin_remove(struct platform_device *pdev)
> v4l2_async_notifier_unregister(>notifier);
>   v4l2_async_notifier_cleanup(>notifier);
> 
> - rvin_dma_remove(vin);
> + rvin_dma_unregister(vin);
> 
>   return 0;
>  }
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c
> b/drivers/media/platform/rcar-vin/rcar-dma.c index
> 23fdff7a7370842e..d701b52d198243b5 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -1153,14 +1153,14 @@ static const struct vb2_ops rvin_qops = {
>   .wait_finish= vb2_ops_wait_finish,
>  };
> 
> -void rvin_dma_remove(struct rvin_dev *vin)
> +void rvin_dma_unregister(struct rvin_dev *vin)
>  {
>   mutex_destroy(>lock);
> 
>   v4l2_device_unregister(>v4l2_dev);
>  }
> 
> -int rvin_dma_probe(struct rvin_dev *vin, int irq)
> +int rvin_dma_register(struct rvin_dev *vin, int irq)
>  {
>   struct vb2_queue *q = >queue;
>   int i, ret;
> @@ -1208,7 +1208,7 @@ int rvin_dma_probe(struct rvin_dev *vin, int irq)
> 
>   return 0;
>  error:
> - rvin_dma_remove(vin);
> + rvin_dma_unregister(vin);
> 
>   return ret;
>  }
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> b/drivers/media/platform/rcar-vin/rcar-v4l2.c index
> b479b882da12f62d..178aecc94962abe2 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -839,7 +839,7 @@ static const struct v4l2_file_operations rvin_fops = {
>   .read   = vb2_fop_read,
>  };
> 
> -void rvin_v4l2_remove(struct rvin_dev *vin)
> +void rvin_v4l2_unregister(struct rvin_dev *vin)
>  {
>   v4l2_info(>v4l2_dev, "Removing %s\n",
> video_device_node_name(>vdev));
> @@ -866,7 +866,7 @@ static void rvin_notify(struct v4l2_subdev *sd,
>   }
>  }
> 
> -int rvin_v4l2_probe(struct rvin_dev *vin)
> +int rvin_v4l2_register(struct rvin_dev *vin)
>  {
>   struct video_device *vdev = >vdev;
>   struct v4l2_subdev *sd = vin_to_source(vin);
> diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h
> b/drivers/media/platform/rcar-vin/rcar-vin.h index
> 5382078143fb3869..85cb7ec53d2b08b5 100644
> --- a/drivers/media/platform/rcar-vin/rcar-vin.h
> +++ b/drivers/media/platform/rcar-vin/rcar-vin.h
> @@ -153,11 +153,11 @@ struct rvin_dev {
>  #define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
>  #define vin_err(d, fmt, arg...)  dev_err(d->dev, fmt, ##arg)
> 
> 

Re: [PATCH v9 01/28] rcar-vin: add Gen3 devicetree bindings documentation

2017-12-07 Thread Laurent Pinchart
Hi Niklas,

Thank you for the patch.

On Friday, 8 December 2017 03:08:15 EET Niklas Söderlund wrote:
> Document the devicetree bindings for the CSI-2 inputs available on Gen3.
> 
> There is a need to add a custom property 'renesas,id' and to define
> which CSI-2 input is described in which endpoint under the port@1 node.
> This information is needed since there are a set of predefined routes
> between each VIN and CSI-2 block. This routing table will be kept
> inside the driver but in order for it to act on it it must know which
> VIN and CSI-2 is which.
> 
> Signed-off-by: Niklas Söderlund 
> Acked-by: Rob Herring 
> ---
>  .../devicetree/bindings/media/rcar_vin.txt | 116 +++---
>  1 file changed, 104 insertions(+), 12 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt
> b/Documentation/devicetree/bindings/media/rcar_vin.txt index
> ff9697ed81396e64..5a95d9668d2c7dfd 100644
> --- a/Documentation/devicetree/bindings/media/rcar_vin.txt
> +++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
> @@ -2,8 +2,12 @@ Renesas R-Car Video Input driver (rcar_vin)
>  ---
> 
>  The rcar_vin device provides video input capabilities for the Renesas R-Car
> -family of devices. The current blocks are always slaves and suppot one
> input
> -channel which can be either RGB, YUYV or BT656.
> +family of devices.
> +
> +Each VIN instance has a single parallel input that supports RGB and YUV
> video,
> +with both external synchronization and BT.656 synchronization for the
> latter.
> +Depending on the instance the VIN input is connected to external SoC pins,
> or
> +on Gen3 to a CSI-2 receiver.
> 
>   - compatible: Must be one or more of the following
> - "renesas,vin-r8a7743" for the R8A7743 device
> @@ -31,21 +35,38 @@ channel which can be either RGB, YUYV or BT656.
>  Additionally, an alias named vinX will need to be created to specify
>  which video input device this is.
> 
> -The per-board settings:
> +The per-board settings Gen2:

Nitpicking, s/Gen2/for Gen2 platforms/

(or Gen2 hardware, or Gen2 systems, pick the one you like best)

>   - port sub-node describing a single endpoint connected to the vin
> as described in video-interfaces.txt[1]. Only the first one will
> be considered as each vin interface has one input port.
> 
> -   These settings are used to work out video input format and widths
> -   into the system.
> +The per-board settings Gen3:

Ditto.

> +
> +Gen3 can support both a single connected parallel input source from
> +external SoC pins (port0) and/or multiple parallel input sources from
> +local SoC CSI-2 receivers (port1) depending on SoC.
> 
> +- renesas,id - ID number of the VIN, VINx in the documentation.
> +- ports
> +- port0 - sub-node describing a single endpoint connected to the VIN
> +  from external SoC pins described in video-interfaces.txt[1]. Only
> +  the first one will be considered as each VIN interface has at most
> +  one set of SoC external input pins.

s/port0/port 0/ or s/port0/port@0/

I'd go further than that and make it invalid to have multiple endpoints 
instead of ignoring all but the first one.

I would also explicitly state that VIN instances not connected to external 
pins shall have no port 0.

> +- port1 - sub-nodes describing one or more endpoints connected to
> +  the VIN from local SoC CSI-2 receivers. The endpoint numbers must
> +  use the following schema.

Nitpicking again, the Gen2-specific properties are indented above while the 
Gen3 properties are not indented here. Pick the one you prefer :-)

> -Device node example
> 
> +- Endpoint 0 - sub-node describing the endpoint which is CSI20
> +- Endpoint 1 - sub-node describing the endpoint which is CSI21
> +- Endpoint 2 - sub-node describing the endpoint which is CSI40
> +- Endpoint 3 - sub-node describing the endpoint which is CSI41

How about s/which is/connected to/ ?

> - aliases {
> -vin0 = 
> - };
> +Device node example Gen2

s/Gen2/for Gen2 platforms/

and same in a few places below.

> +
> +
> +aliases {
> +vin0 = 
> +};

This is unrelated, but do we need aliases ?

>  vin0: vin@0xe6ef {
>  compatible = "renesas,vin-r8a7790",
> "renesas,rcar-gen2-vin"; @@ -55,8 +76,8 @@ Device node example
>  status = "disabled";
>  };
> 
> -Board setup example (vin1 composite video input)
> -
> +Board setup example Gen2 (vin1 composite video input)
> +-
> 
> {
>  status = "ok";
> @@ -95,6 +116,77 @@ Board setup example (vin1 composite video input)
>  };
>  };
> 
> +Device node example Gen3
> +
> +
> +vin0: 

[PATCH v9 12/28] rcar-vin: read subdevice format for crop only when needed

2017-12-07 Thread Niklas Söderlund
Instead of caching the subdevice format each time the video device
format is set read it directly when it's needed. As it turns out the
format is only needed when figuring out the max rectangle for cropping.

This simplifies the code and makes it clearer what the source format is
used for.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 88 ++---
 drivers/media/platform/rcar-vin/rcar-vin.h  | 12 
 2 files changed, 42 insertions(+), 58 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index d6298c684ab2d731..9cf9ff48ac1e2f4f 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -90,24 +90,30 @@ static u32 rvin_format_sizeimage(struct v4l2_pix_format 
*pix)
  * V4L2
  */
 
-static int rvin_reset_format(struct rvin_dev *vin)
+static int rvin_get_sd_format(struct rvin_dev *vin, struct v4l2_pix_format 
*pix)
 {
struct v4l2_subdev_format fmt = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+   .pad = vin->digital->source_pad,
};
-   struct v4l2_mbus_framefmt *mf = 
int ret;
 
-   fmt.pad = vin->digital->source_pad;
-
ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, );
if (ret)
return ret;
 
-   vin->format.width   = mf->width;
-   vin->format.height  = mf->height;
-   vin->format.colorspace  = mf->colorspace;
-   vin->format.field   = mf->field;
+   v4l2_fill_pix_format(pix, );
+
+   return 0;
+}
+
+static int rvin_reset_format(struct rvin_dev *vin)
+{
+   int ret;
+
+   ret = rvin_get_sd_format(vin, >format);
+   if (ret)
+   return ret;
 
/*
 * If the subdevice uses ALTERNATE field mode and G_STD is
@@ -137,12 +143,12 @@ static int rvin_reset_format(struct rvin_dev *vin)
}
 
vin->crop.top = vin->crop.left = 0;
-   vin->crop.width = mf->width;
-   vin->crop.height = mf->height;
+   vin->crop.width = vin->format.width;
+   vin->crop.height = vin->format.height;
 
vin->compose.top = vin->compose.left = 0;
-   vin->compose.width = mf->width;
-   vin->compose.height = mf->height;
+   vin->compose.width = vin->format.width;
+   vin->compose.height = vin->format.height;
 
vin->format.bytesperline = rvin_format_bytesperline(>format);
vin->format.sizeimage = rvin_format_sizeimage(>format);
@@ -151,9 +157,7 @@ static int rvin_reset_format(struct rvin_dev *vin)
 }
 
 static int __rvin_try_format_source(struct rvin_dev *vin,
-   u32 which,
-   struct v4l2_pix_format *pix,
-   struct rvin_source_fmt *source)
+   u32 which, struct v4l2_pix_format *pix)
 {
struct v4l2_subdev *sd;
struct v4l2_subdev_pad_config *pad_cfg;
@@ -186,25 +190,15 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
v4l2_fill_pix_format(pix, );
 
pix->field = field;
-
-   source->width = pix->width;
-   source->height = pix->height;
-
pix->width = width;
pix->height = height;
-
-   vin_dbg(vin, "Source resolution: %ux%u\n", source->width,
-   source->height);
-
 done:
v4l2_subdev_free_pad_config(pad_cfg);
return ret;
 }
 
 static int __rvin_try_format(struct rvin_dev *vin,
-u32 which,
-struct v4l2_pix_format *pix,
-struct rvin_source_fmt *source)
+u32 which, struct v4l2_pix_format *pix)
 {
u32 walign;
int ret;
@@ -225,7 +219,7 @@ static int __rvin_try_format(struct rvin_dev *vin,
pix->sizeimage = 0;
 
/* Limit to source capabilities */
-   ret = __rvin_try_format_source(vin, which, pix, source);
+   ret = __rvin_try_format_source(vin, which, pix);
if (ret)
return ret;
 
@@ -234,7 +228,6 @@ static int __rvin_try_format(struct rvin_dev *vin,
case V4L2_FIELD_BOTTOM:
case V4L2_FIELD_ALTERNATE:
pix->height /= 2;
-   source->height /= 2;
break;
case V4L2_FIELD_NONE:
case V4L2_FIELD_INTERLACED_TB:
@@ -286,30 +279,23 @@ static int rvin_try_fmt_vid_cap(struct file *file, void 
*priv,
struct v4l2_format *f)
 {
struct rvin_dev *vin = video_drvdata(file);
-   struct rvin_source_fmt source;
 
-   return __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, >fmt.pix,
-);
+   return __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, >fmt.pix);
 }
 
 static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
 

[PATCH v9 06/28] rcar-vin: move max width and height information to chip information

2017-12-07 Thread Niklas Söderlund
On Gen3 the max supported width and height will be different from Gen2.
Move the limits to the struct rvin_info to prepare for Gen3 support.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Kieran Bingham 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 6 ++
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 6 ++
 drivers/media/platform/rcar-vin/rcar-vin.h  | 6 ++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 73c1700a409bfd35..03d3cd63e38bee11 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -232,14 +232,20 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
 
 static const struct rvin_info rcar_info_h1 = {
.chip = RCAR_H1,
+   .max_width = 2048,
+   .max_height = 2048,
 };
 
 static const struct rvin_info rcar_info_m1 = {
.chip = RCAR_M1,
+   .max_width = 2048,
+   .max_height = 2048,
 };
 
 static const struct rvin_info rcar_info_gen2 = {
.chip = RCAR_GEN2,
+   .max_width = 2048,
+   .max_height = 2048,
 };
 
 static const struct of_device_id rvin_of_id_table[] = {
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index b1caa04921aa23bb..59ec6d3d119590aa 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -23,8 +23,6 @@
 #include "rcar-vin.h"
 
 #define RVIN_DEFAULT_FORMATV4L2_PIX_FMT_YUYV
-#define RVIN_MAX_WIDTH 2048
-#define RVIN_MAX_HEIGHT2048
 
 /* 
-
  * Format Conversions
@@ -258,8 +256,8 @@ static int __rvin_try_format(struct rvin_dev *vin,
walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
 
/* Limit to VIN capabilities */
-   v4l_bound_align_image(>width, 2, RVIN_MAX_WIDTH, walign,
- >height, 4, RVIN_MAX_HEIGHT, 2, 0);
+   v4l_bound_align_image(>width, 2, vin->info->max_width, walign,
+ >height, 4, vin->info->max_height, 2, 0);
 
pix->bytesperline = max_t(u32, pix->bytesperline,
  rvin_format_bytesperline(pix));
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 0d3949c8c08c8f63..646f897f5c05ec4e 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -91,9 +91,15 @@ struct rvin_graph_entity {
 /**
  * struct rvin_info - Information about the particular VIN implementation
  * @chip:  type of VIN chip
+ *
+ * max_width:  max input width the VIN supports
+ * max_height: max input height the VIN supports
  */
 struct rvin_info {
enum chip_id chip;
+
+   unsigned int max_width;
+   unsigned int max_height;
 };
 
 /**
-- 
2.15.0



[PATCH v9 03/28] rcar-vin: unregister video device on driver removal

2017-12-07 Thread Niklas Söderlund
If the video device was registered by the complete() callback it should
be unregistered when the driver is removed. Protect from printing an
uninitialized video device node name by adding a check in
rvin_v4l2_unregister() to identify that the video device is registered.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Kieran Bingham 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index f7a4c21909da6923..6d99542ec74b49a7 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -272,6 +272,8 @@ static int rcar_vin_remove(struct platform_device *pdev)
 
pm_runtime_disable(>dev);
 
+   rvin_v4l2_unregister(vin);
+
v4l2_async_notifier_unregister(>notifier);
v4l2_async_notifier_cleanup(>notifier);
 
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 178aecc94962abe2..32a658214f48fa49 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -841,6 +841,9 @@ static const struct v4l2_file_operations rvin_fops = {
 
 void rvin_v4l2_unregister(struct rvin_dev *vin)
 {
+   if (!video_is_registered(>vdev))
+   return;
+
v4l2_info(>v4l2_dev, "Removing %s\n",
  video_device_node_name(>vdev));
 
-- 
2.15.0



[PATCH v9 10/28] rcar-vin: do not reset crop and compose when setting format

2017-12-07 Thread Niklas Söderlund
It was a bad idea to reset the crop and compose settings when a new
format is set. This would overwrite any crop/compose set by s_select and
cause unexpected behaviors, remove it. Also fold the reset helper in to
the only remaining caller.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 1c5e7f6d5b963740..254fa1c8770275a5 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -90,17 +90,6 @@ static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
  * V4L2
  */
 
-static void rvin_reset_crop_compose(struct rvin_dev *vin)
-{
-   vin->crop.top = vin->crop.left = 0;
-   vin->crop.width = vin->source.width;
-   vin->crop.height = vin->source.height;
-
-   vin->compose.top = vin->compose.left = 0;
-   vin->compose.width = vin->format.width;
-   vin->compose.height = vin->format.height;
-}
-
 static int rvin_reset_format(struct rvin_dev *vin)
 {
struct v4l2_subdev_format fmt = {
@@ -147,7 +136,13 @@ static int rvin_reset_format(struct rvin_dev *vin)
break;
}
 
-   rvin_reset_crop_compose(vin);
+   vin->crop.top = vin->crop.left = 0;
+   vin->crop.width = mf->width;
+   vin->crop.height = mf->height;
+
+   vin->compose.top = vin->compose.left = 0;
+   vin->compose.width = mf->width;
+   vin->compose.height = mf->height;
 
vin->format.bytesperline = rvin_format_bytesperline(>format);
vin->format.sizeimage = rvin_format_sizeimage(>format);
@@ -317,8 +312,6 @@ static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
 
vin->format = f->fmt.pix;
 
-   rvin_reset_crop_compose(vin);
-
return 0;
 }
 
-- 
2.15.0



[PATCH v9 13/28] rcar-vin: fix handling of single field frames (top, bottom and alternate fields)

2017-12-07 Thread Niklas Söderlund
There was never proper support in the VIN driver to deliver ALTERNATING
field format to user-space, remove this field option. For sources using
this field format instead use the VIN hardware feature of combining the
fields to an interlaced format. This mode of operation was previously
the default behavior and ALTERNATING was only delivered to user-space if
explicitly requested. Allowing this to be explicitly requested was a
mistake and was never properly tested and never worked due to the
constraints put on the field format when it comes to sequence numbers and
timestamps etc.

The height should not be cut in half for the format for TOP or BOTTOM
fields settings. This was a mistake and it was made visible by the
scaling refactoring. Correct behavior is that the user should request a
frame size that fits the half height frame reflected in the field
setting. If not the VIN will do its best to scale the top or bottom to
the requested format and cropping and scaling do not work as expected.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c  | 15 +
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 48 +++--
 2 files changed, 19 insertions(+), 44 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 7be5080f742825fb..e6478088d9464221 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -617,7 +617,6 @@ static int rvin_setup(struct rvin_dev *vin)
case V4L2_FIELD_INTERLACED_BT:
vnmc = VNMC_IM_FULL | VNMC_FOC;
break;
-   case V4L2_FIELD_ALTERNATE:
case V4L2_FIELD_NONE:
if (vin->continuous) {
vnmc = VNMC_IM_ODD_EVEN;
@@ -757,18 +756,6 @@ static int rvin_get_active_slot(struct rvin_dev *vin, u32 
vnms)
return 0;
 }
 
-static enum v4l2_field rvin_get_active_field(struct rvin_dev *vin, u32 vnms)
-{
-   if (vin->format.field == V4L2_FIELD_ALTERNATE) {
-   /* If FS is set it's a Even field */
-   if (vnms & VNMS_FS)
-   return V4L2_FIELD_BOTTOM;
-   return V4L2_FIELD_TOP;
-   }
-
-   return vin->format.field;
-}
-
 static void rvin_set_slot_addr(struct rvin_dev *vin, int slot, dma_addr_t addr)
 {
const struct rvin_video_format *fmt;
@@ -941,7 +928,7 @@ static irqreturn_t rvin_irq(int irq, void *data)
goto done;
 
/* Capture frame */
-   vin->queue_buf[slot]->field = rvin_get_active_field(vin, vnms);
+   vin->queue_buf[slot]->field = vin->format.field;
vin->queue_buf[slot]->sequence = sequence;
vin->queue_buf[slot]->vb2_buf.timestamp = ktime_get_ns();
vb2_buffer_done(>queue_buf[slot]->vb2_buf, VB2_BUF_STATE_DONE);
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 9cf9ff48ac1e2f4f..37fe1f6c646b0ea3 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -102,6 +102,24 @@ static int rvin_get_sd_format(struct rvin_dev *vin, struct 
v4l2_pix_format *pix)
if (ret)
return ret;
 
+   switch (fmt.format.field) {
+   case V4L2_FIELD_TOP:
+   case V4L2_FIELD_BOTTOM:
+   case V4L2_FIELD_NONE:
+   case V4L2_FIELD_INTERLACED_TB:
+   case V4L2_FIELD_INTERLACED_BT:
+   case V4L2_FIELD_INTERLACED:
+   break;
+   case V4L2_FIELD_ALTERNATE:
+   /* Use VIN hardware to combine the two fields */
+   fmt.format.field = V4L2_FIELD_INTERLACED;
+   fmt.format.height *= 2;
+   break;
+   default:
+   vin->format.field = V4L2_FIELD_NONE;
+   break;
+   }
+
v4l2_fill_pix_format(pix, );
 
return 0;
@@ -115,33 +133,6 @@ static int rvin_reset_format(struct rvin_dev *vin)
if (ret)
return ret;
 
-   /*
-* If the subdevice uses ALTERNATE field mode and G_STD is
-* implemented use the VIN HW to combine the two fields to
-* one INTERLACED frame. The ALTERNATE field mode can still
-* be requested in S_FMT and be respected, this is just the
-* default which is applied at probing or when S_STD is called.
-*/
-   if (vin->format.field == V4L2_FIELD_ALTERNATE &&
-   v4l2_subdev_has_op(vin_to_source(vin), video, g_std))
-   vin->format.field = V4L2_FIELD_INTERLACED;
-
-   switch (vin->format.field) {
-   case V4L2_FIELD_TOP:
-   case V4L2_FIELD_BOTTOM:
-   case V4L2_FIELD_ALTERNATE:
-   vin->format.height /= 2;
-   break;
-   case V4L2_FIELD_NONE:
-   case V4L2_FIELD_INTERLACED_TB:
-   case V4L2_FIELD_INTERLACED_BT:
-   case 

[PATCH v9 09/28] rcar-vin: all Gen2 boards can scale simplify logic

2017-12-07 Thread Niklas Söderlund
The logic to preserve the requested format width and height are too
complex and come from a premature optimization for Gen3. All Gen2 SoC
can scale and the Gen3 implementation will not use these functions at
all so simply preserve the width and height when interacting with the
subdevice much like the field is preserved simplifies the logic quite a
bit.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c  |  8 
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 22 ++
 drivers/media/platform/rcar-vin/rcar-vin.h  |  2 --
 3 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index a7cda3922cb74baa..fd14be20a6604d7a 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -585,14 +585,6 @@ void rvin_crop_scale_comp(struct rvin_dev *vin)
0, 0);
 }
 
-void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
-   u32 width, u32 height)
-{
-   /* All VIN channels on Gen2 have scalers */
-   pix->width = width;
-   pix->height = height;
-}
-
 /* 
-
  * Hardware setup
  */
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 19de99133f048960..1c5e7f6d5b963740 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -166,6 +166,7 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
.which = which,
};
enum v4l2_field field;
+   u32 width, height;
int ret;
 
sd = vin_to_source(vin);
@@ -178,7 +179,10 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 
format.pad = vin->digital->source_pad;
 
+   /* Allow the video device to override field and to scale */
field = pix->field;
+   width = pix->width;
+   height = pix->height;
 
ret = v4l2_subdev_call(sd, pad, set_fmt, pad_cfg, );
if (ret < 0 && ret != -ENOIOCTLCMD)
@@ -191,6 +195,9 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
source->width = pix->width;
source->height = pix->height;
 
+   pix->width = width;
+   pix->height = height;
+
vin_dbg(vin, "Source resolution: %ux%u\n", source->width,
source->height);
 
@@ -204,13 +211,9 @@ static int __rvin_try_format(struct rvin_dev *vin,
 struct v4l2_pix_format *pix,
 struct rvin_source_fmt *source)
 {
-   u32 rwidth, rheight, walign;
+   u32 walign;
int ret;
 
-   /* Requested */
-   rwidth = pix->width;
-   rheight = pix->height;
-
/* Keep current field if no specific one is asked for */
if (pix->field == V4L2_FIELD_ANY)
pix->field = vin->format.field;
@@ -248,10 +251,6 @@ static int __rvin_try_format(struct rvin_dev *vin,
break;
}
 
-   /* If source can't match format try if VIN can scale */
-   if (source->width != rwidth || source->height != rheight)
-   rvin_scale_try(vin, pix, rwidth, rheight);
-
/* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
 
@@ -270,9 +269,8 @@ static int __rvin_try_format(struct rvin_dev *vin,
return -EINVAL;
}
 
-   vin_dbg(vin, "Requested %ux%u Got %ux%u bpl: %d size: %d\n",
-   rwidth, rheight, pix->width, pix->height,
-   pix->bytesperline, pix->sizeimage);
+   vin_dbg(vin, "Format %ux%u bpl: %d size: %d\n",
+   pix->width, pix->height, pix->bytesperline, pix->sizeimage);
 
return 0;
 }
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 646f897f5c05ec4e..36d0f0cc4ce01a6e 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -176,8 +176,6 @@ void rvin_v4l2_unregister(struct rvin_dev *vin);
 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
 
 /* Cropping, composing and scaling */
-void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
-   u32 width, u32 height);
 void rvin_crop_scale_comp(struct rvin_dev *vin);
 
 #endif
-- 
2.15.0



[PATCH v9 07/28] rcar-vin: change name of video device

2017-12-07 Thread Niklas Söderlund
The rcar-vin driver needs to be part of a media controller to support
Gen3. Give each VIN instance a unique name so it can be referenced from
userspace.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Kieran Bingham 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 59ec6d3d119590aa..19de99133f048960 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -876,7 +876,8 @@ int rvin_v4l2_register(struct rvin_dev *vin)
vdev->fops = _fops;
vdev->v4l2_dev = >v4l2_dev;
vdev->queue = >queue;
-   strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name));
+   snprintf(vdev->name, sizeof(vdev->name), "%s %s", KBUILD_MODNAME,
+dev_name(vin->dev));
vdev->release = video_device_release_empty;
vdev->ioctl_ops = _ioctl_ops;
vdev->lock = >lock;
-- 
2.15.0



[PATCH v9 04/28] rcar-vin: move subdevice handling to async callbacks

2017-12-07 Thread Niklas Söderlund
In preparation for Gen3 support move the subdevice initialization and
clean up from rvin_v4l2_{register,unregister}() directly to the async
callbacks. This simplifies the addition of Gen3 support as the
rvin_v4l2_register() can be shared for both Gen2 and Gen3 while direct
subdevice control are only used on Gen2.

While moving this code drop a large comment which is copied from the
framework documentation and fold rvin_mbus_supported() into its only
caller.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 105 ++--
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  35 --
 2 files changed, 67 insertions(+), 73 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 6d99542ec74b49a7..6ab51acd676641ec 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -46,47 +46,11 @@ static int rvin_find_pad(struct v4l2_subdev *sd, int 
direction)
return -EINVAL;
 }
 
-static bool rvin_mbus_supported(struct rvin_graph_entity *entity)
-{
-   struct v4l2_subdev *sd = entity->subdev;
-   struct v4l2_subdev_mbus_code_enum code = {
-   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
-   };
-
-   code.index = 0;
-   code.pad = entity->source_pad;
-   while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, )) {
-   code.index++;
-   switch (code.code) {
-   case MEDIA_BUS_FMT_YUYV8_1X16:
-   case MEDIA_BUS_FMT_UYVY8_2X8:
-   case MEDIA_BUS_FMT_UYVY10_2X10:
-   case MEDIA_BUS_FMT_RGB888_1X24:
-   entity->code = code.code;
-   return true;
-   default:
-   break;
-   }
-   }
-
-   return false;
-}
-
 static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
 {
struct rvin_dev *vin = notifier_to_vin(notifier);
int ret;
 
-   /* Verify subdevices mbus format */
-   if (!rvin_mbus_supported(vin->digital)) {
-   vin_err(vin, "Unsupported media bus format for %s\n",
-   vin->digital->subdev->name);
-   return -EINVAL;
-   }
-
-   vin_dbg(vin, "Found media bus format for %s: %d\n",
-   vin->digital->subdev->name, vin->digital->code);
-
ret = v4l2_device_register_subdev_nodes(>v4l2_dev);
if (ret < 0) {
vin_err(vin, "Failed to register subdev nodes\n");
@@ -103,8 +67,16 @@ static void rvin_digital_notify_unbind(struct 
v4l2_async_notifier *notifier,
struct rvin_dev *vin = notifier_to_vin(notifier);
 
vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
+
+   mutex_lock(>lock);
+
rvin_v4l2_unregister(vin);
+   v4l2_ctrl_handler_free(>ctrl_handler);
+
+   vin->vdev.ctrl_handler = NULL;
vin->digital->subdev = NULL;
+
+   mutex_unlock(>lock);
 }
 
 static int rvin_digital_notify_bound(struct v4l2_async_notifier *notifier,
@@ -112,12 +84,14 @@ static int rvin_digital_notify_bound(struct 
v4l2_async_notifier *notifier,
 struct v4l2_async_subdev *asd)
 {
struct rvin_dev *vin = notifier_to_vin(notifier);
+   struct v4l2_subdev_mbus_code_enum code = {
+   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+   };
int ret;
 
v4l2_set_subdev_hostdata(subdev, vin);
 
/* Find source and sink pad of remote subdevice */
-
ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SOURCE);
if (ret < 0)
return ret;
@@ -126,21 +100,74 @@ static int rvin_digital_notify_bound(struct 
v4l2_async_notifier *notifier,
ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SINK);
vin->digital->sink_pad = ret < 0 ? 0 : ret;
 
+   /* Find compatible subdevices mbus format */
+   vin->digital->code = 0;
+   code.index = 0;
+   code.pad = vin->digital->source_pad;
+   while (!vin->digital->code &&
+  !v4l2_subdev_call(subdev, pad, enum_mbus_code, NULL, )) {
+   code.index++;
+   switch (code.code) {
+   case MEDIA_BUS_FMT_YUYV8_1X16:
+   case MEDIA_BUS_FMT_UYVY8_2X8:
+   case MEDIA_BUS_FMT_UYVY10_2X10:
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   vin->digital->code = code.code;
+   vin_dbg(vin, "Found media bus format for %s: %d\n",
+   subdev->name, vin->digital->code);
+   break;
+   default:
+   break;
+   }
+   }
+
+   if (!vin->digital->code) {
+   vin_err(vin, "Unsupported media bus format for %s\n",
+   subdev->name);
+   return -EINVAL;
+   

[PATCH v9 23/28] rcar-vin: parse Gen3 OF and setup media graph

2017-12-07 Thread Niklas Söderlund
Parse the VIN Gen3 OF graph and register all CSI-2 devices in the VIN
group common media device. Once all CSI-2 subdevices are added to the
common media device create links between them.

The parsing and registering CSI-2 subdevices with the v4l2 async
framework is a collaborative effort shared between the VIN instances
which are part of the group. The first rcar-vin instance parses OF and
finds all other VIN and CSI-2 nodes which are part of the graph. It
stores a bit mask of all VIN instances found and handles to all CSI-2
nodes.

The bit mask is used to figure out when all VIN instances have been
probed. Once the last VIN instance is probed this is detected and this
instance registers all CSI-2 subdevices in its private async notifier.
Once the .complete() callback of this notifier is called it registers
all video devices and creates the media controller links between all
entities.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 320 +++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  10 +-
 2 files changed, 326 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index a6713fd61dd87a88..4a147437fa69c364 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -86,6 +86,7 @@ static struct rvin_group *__rvin_group_allocate(struct 
rvin_dev *vin)
return NULL;
 
kref_init(>refcount);
+   group->notifier = NULL;
rvin_group_data = group;
 
vin_dbg(vin, "%s: alloc group=%p\n", __func__, group);
@@ -392,10 +393,281 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
  * Group async notifier
  */
 
-static int rvin_group_init(struct rvin_dev *vin)
+/* group lock should be held when calling this function */
+static int rvin_group_add_link(struct rvin_dev *vin,
+  struct media_entity *source,
+  unsigned int source_idx,
+  struct media_entity *sink,
+  unsigned int sink_idx,
+  u32 flags)
+{
+   struct media_pad *source_pad, *sink_pad;
+   int ret = 0;
+
+   source_pad = >pads[source_idx];
+   sink_pad = >pads[sink_idx];
+
+   if (!media_entity_find_link(source_pad, sink_pad))
+   ret = media_create_pad_link(source, source_idx,
+   sink, sink_idx, flags);
+
+   if (ret)
+   vin_err(vin, "Error adding link from %s to %s\n",
+   source->name, sink->name);
+
+   return ret;
+}
+
+static int rvin_group_update_links(struct rvin_dev *vin)
+{
+   struct media_entity *source, *sink;
+   struct rvin_dev *master;
+   unsigned int i, n, idx, csi;
+   int ret = 0;
+
+   mutex_lock(>group->lock);
+
+   for (n = 0; n < RCAR_VIN_NUM; n++) {
+
+   /* Check that VIN is part of the group */
+   if (!vin->group->vin[n])
+   continue;
+
+   /* Check that subgroup master is part of the group */
+   master = vin->group->vin[n < 4 ? 0 : 4];
+   if (!master)
+   continue;
+
+   for (i = 0; i < vin->info->num_chsels; i++) {
+   csi = vin->info->chsels[n][i].csi;
+
+   /* If the CSI-2 is out of bounds it's a noop, skip */
+   if (csi >= RVIN_CSI_MAX)
+   continue;
+
+   /* Check that CSI-2 are part of the group */
+   if (!vin->group->csi[csi].subdev)
+   continue;
+
+   source = >group->csi[csi].subdev->entity;
+   sink = >group->vin[n]->vdev.entity;
+   idx = vin->info->chsels[n][i].chan + 1;
+
+   ret = rvin_group_add_link(vin, source, idx, sink, 0,
+ 0);
+   if (ret)
+   goto out;
+   }
+   }
+out:
+   mutex_unlock(>group->lock);
+
+   return ret;
+}
+
+static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier)
 {
+   struct rvin_dev *vin = notifier_to_vin(notifier);
+   unsigned int i;
int ret;
 
+   ret = v4l2_device_register_subdev_nodes(>v4l2_dev);
+   if (ret) {
+   vin_err(vin, "Failed to register subdev nodes\n");
+   return ret;
+   }
+
+   for (i = 0; i < RCAR_VIN_NUM; i++) {
+   if (vin->group->vin[i]) {
+   ret = rvin_v4l2_register(vin->group->vin[i]);
+   if (ret)
+   return ret;
+   }
+   }
+
+ 

[PATCH v9 08/28] rcar-vin: move functions regarding scaling

2017-12-07 Thread Niklas Söderlund
In preparation of refactoring the scaling code move the code regarding
scaling to to the top of the file to avoid the need to add forward
declarations. No code is changed in this commit only whole functions
moved inside the same file.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 806 +++--
 1 file changed, 405 insertions(+), 401 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index d701b52d198243b5..a7cda3922cb74baa 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -138,305 +138,6 @@ static u32 rvin_read(struct rvin_dev *vin, u32 offset)
return ioread32(vin->base + offset);
 }
 
-static int rvin_setup(struct rvin_dev *vin)
-{
-   u32 vnmc, dmr, dmr2, interrupts;
-   v4l2_std_id std;
-   bool progressive = false, output_is_yuv = false, input_is_yuv = false;
-
-   switch (vin->format.field) {
-   case V4L2_FIELD_TOP:
-   vnmc = VNMC_IM_ODD;
-   break;
-   case V4L2_FIELD_BOTTOM:
-   vnmc = VNMC_IM_EVEN;
-   break;
-   case V4L2_FIELD_INTERLACED:
-   /* Default to TB */
-   vnmc = VNMC_IM_FULL;
-   /* Use BT if video standard can be read and is 60 Hz format */
-   if (!v4l2_subdev_call(vin_to_source(vin), video, g_std, )) {
-   if (std & V4L2_STD_525_60)
-   vnmc = VNMC_IM_FULL | VNMC_FOC;
-   }
-   break;
-   case V4L2_FIELD_INTERLACED_TB:
-   vnmc = VNMC_IM_FULL;
-   break;
-   case V4L2_FIELD_INTERLACED_BT:
-   vnmc = VNMC_IM_FULL | VNMC_FOC;
-   break;
-   case V4L2_FIELD_ALTERNATE:
-   case V4L2_FIELD_NONE:
-   if (vin->continuous) {
-   vnmc = VNMC_IM_ODD_EVEN;
-   progressive = true;
-   } else {
-   vnmc = VNMC_IM_ODD;
-   }
-   break;
-   default:
-   vnmc = VNMC_IM_ODD;
-   break;
-   }
-
-   /*
-* Input interface
-*/
-   switch (vin->digital->code) {
-   case MEDIA_BUS_FMT_YUYV8_1X16:
-   /* BT.601/BT.1358 16bit YCbCr422 */
-   vnmc |= VNMC_INF_YUV16;
-   input_is_yuv = true;
-   break;
-   case MEDIA_BUS_FMT_UYVY8_2X8:
-   /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
-   vnmc |= vin->digital->mbus_cfg.type == V4L2_MBUS_BT656 ?
-   VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
-   input_is_yuv = true;
-   break;
-   case MEDIA_BUS_FMT_RGB888_1X24:
-   vnmc |= VNMC_INF_RGB888;
-   break;
-   case MEDIA_BUS_FMT_UYVY10_2X10:
-   /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
-   vnmc |= vin->digital->mbus_cfg.type == V4L2_MBUS_BT656 ?
-   VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
-   input_is_yuv = true;
-   break;
-   default:
-   break;
-   }
-
-   /* Enable VSYNC Field Toogle mode after one VSYNC input */
-   dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
-
-   /* Hsync Signal Polarity Select */
-   if (!(vin->digital->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
-   dmr2 |= VNDMR2_HPS;
-
-   /* Vsync Signal Polarity Select */
-   if (!(vin->digital->mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
-   dmr2 |= VNDMR2_VPS;
-
-   /*
-* Output format
-*/
-   switch (vin->format.pixelformat) {
-   case V4L2_PIX_FMT_NV16:
-   rvin_write(vin,
-  ALIGN(vin->format.width * vin->format.height, 0x80),
-  VNUVAOF_REG);
-   dmr = VNDMR_DTMD_YCSEP;
-   output_is_yuv = true;
-   break;
-   case V4L2_PIX_FMT_YUYV:
-   dmr = VNDMR_BPSM;
-   output_is_yuv = true;
-   break;
-   case V4L2_PIX_FMT_UYVY:
-   dmr = 0;
-   output_is_yuv = true;
-   break;
-   case V4L2_PIX_FMT_XRGB555:
-   dmr = VNDMR_DTMD_ARGB1555;
-   break;
-   case V4L2_PIX_FMT_RGB565:
-   dmr = 0;
-   break;
-   case V4L2_PIX_FMT_XBGR32:
-   /* Note: not supported on M1 */
-   dmr = VNDMR_EXRGB;
-   break;
-   default:
-   vin_err(vin, "Invalid pixelformat (0x%x)\n",
-   vin->format.pixelformat);
-   return -EINVAL;
-   }
-
-   /* Always update on field change */
-   vnmc |= VNMC_VUP;
-
-   /* If input and 

[PATCH v9 27/28] rcar-vin: enable support for r8a7796

2017-12-07 Thread Niklas Söderlund
Add the SoC specific information for Renesas r8a7796.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/media/rcar_vin.txt |  1 +
 drivers/media/platform/rcar-vin/rcar-core.c| 64 ++
 2 files changed, 65 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt 
b/Documentation/devicetree/bindings/media/rcar_vin.txt
index 5a95d9668d2c7dfd..314743532bbb4523 100644
--- a/Documentation/devicetree/bindings/media/rcar_vin.txt
+++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
@@ -20,6 +20,7 @@ on Gen3 to a CSI-2 receiver.
- "renesas,vin-r8a7793" for the R8A7793 device
- "renesas,vin-r8a7794" for the R8A7794 device
- "renesas,vin-r8a7795" for the R8A7795 device
+   - "renesas,vin-r8a7796" for the R8A7796 device
- "renesas,rcar-gen2-vin" for a generic R-Car Gen2 or RZ/G1 compatible
  device.
- "renesas,rcar-gen3-vin" for a generic R-Car Gen3 compatible device.
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 66a8144fbba437d3..ed7fbb58ad6846c1 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -1085,6 +1085,66 @@ static const struct rvin_info rcar_info_r8a7795es1 = {
},
 };
 
+static const struct rvin_info rcar_info_r8a7796 = {
+   .chip = RCAR_GEN3,
+   .use_mc = true,
+   .max_width = 4096,
+   .max_height = 4096,
+
+   .num_chsels = 5,
+   .chsels = {
+   {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   }, {
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_NC, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   }, {
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_NC, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   },
+   },
+};
+
 static const struct of_device_id rvin_of_id_table[] = {
{
.compatible = "renesas,vin-r8a7778",
@@ -1118,6 +1178,10 @@ static const struct of_device_id rvin_of_id_table[] = {
.compatible = "renesas,vin-r8a7795",
.data = _info_r8a7795,
},
+   {
+   .compatible = "renesas,vin-r8a7796",
+   .data = _info_r8a7796,
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
-- 
2.15.0



[PATCH v9 11/28] rcar-vin: do not allow changing scaling and composing while streaming

2017-12-07 Thread Niklas Söderlund
It is possible on Gen2 to change the registers controlling composing and
scaling while the stream is running. It is however not a good idea to do
so and could result in trouble. There are also no good reasons to allow
this, remove immediate reflection in hardware registers from
vidioc_s_selection and only configure scaling and composing when the
stream starts.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c  | 2 +-
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 3 ---
 drivers/media/platform/rcar-vin/rcar-vin.h  | 3 ---
 3 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index fd14be20a6604d7a..7be5080f742825fb 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -514,7 +514,7 @@ static void rvin_set_coeff(struct rvin_dev *vin, unsigned 
short xs)
rvin_write(vin, p_set->coeff_set[23], VNC8C_REG);
 }
 
-void rvin_crop_scale_comp(struct rvin_dev *vin)
+static void rvin_crop_scale_comp(struct rvin_dev *vin)
 {
u32 xs, ys;
 
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 254fa1c8770275a5..d6298c684ab2d731 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -436,9 +436,6 @@ static int rvin_s_selection(struct file *file, void *fh,
return -EINVAL;
}
 
-   /* HW supports modifying configuration while running */
-   rvin_crop_scale_comp(vin);
-
return 0;
 }
 
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 36d0f0cc4ce01a6e..67541b483ee43c52 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -175,7 +175,4 @@ void rvin_v4l2_unregister(struct rvin_dev *vin);
 
 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
 
-/* Cropping, composing and scaling */
-void rvin_crop_scale_comp(struct rvin_dev *vin);
-
 #endif
-- 
2.15.0



[PATCH v9 25/28] rcar-vin: extend {start,stop}_streaming to work with media controller

2017-12-07 Thread Niklas Söderlund
The procedure to start or stop streaming using the non-MC single
subdevice and the MC graph and multiple subdevices are quite different.
Create a new function to abstract which method is used based on which
mode the driver is running in and add logic to start the MC graph.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 112 +++--
 1 file changed, 105 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 6c5df13b30d6dd14..8a6674a891aab357 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1087,15 +1087,115 @@ static void rvin_buffer_queue(struct vb2_buffer *vb)
spin_unlock_irqrestore(>qlock, flags);
 }
 
+static int rvin_set_stream(struct rvin_dev *vin, int on)
+{
+   struct v4l2_subdev_format fmt = {
+   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+   };
+   struct media_pipeline *pipe;
+   struct  v4l2_subdev *sd;
+   struct media_pad *pad;
+   int ret;
+
+   /* No media controller used, simply pass operation to subdevice */
+   if (!vin->info->use_mc) {
+   ret = v4l2_subdev_call(vin->digital->subdev, video, s_stream,
+  on);
+
+   return ret == -ENOIOCTLCMD ? 0 : ret;
+   }
+
+   pad = media_entity_remote_pad(>pad);
+   if (!pad)
+   return -EPIPE;
+
+   sd = media_entity_to_v4l2_subdev(pad->entity);
+   if (!sd)
+   return -EPIPE;
+
+   if (!on) {
+   media_pipeline_stop(>vdev.entity);
+   return v4l2_subdev_call(sd, video, s_stream, 0);
+   }
+
+   fmt.pad = pad->index;
+   if (v4l2_subdev_call(sd, pad, get_fmt, NULL, ))
+   return -EPIPE;
+
+   switch (fmt.format.code) {
+   case MEDIA_BUS_FMT_YUYV8_1X16:
+   case MEDIA_BUS_FMT_UYVY8_2X8:
+   case MEDIA_BUS_FMT_UYVY10_2X10:
+   case MEDIA_BUS_FMT_RGB888_1X24:
+   vin->code = fmt.format.code;
+   break;
+   default:
+   return -EPIPE;
+   }
+
+   switch (fmt.format.field) {
+   case V4L2_FIELD_TOP:
+   case V4L2_FIELD_BOTTOM:
+   case V4L2_FIELD_NONE:
+   case V4L2_FIELD_INTERLACED_TB:
+   case V4L2_FIELD_INTERLACED_BT:
+   case V4L2_FIELD_INTERLACED:
+   case V4L2_FIELD_SEQ_TB:
+   case V4L2_FIELD_SEQ_BT:
+   /* Supported natively */
+   break;
+   case V4L2_FIELD_ALTERNATE:
+   switch (vin->format.field) {
+   case V4L2_FIELD_TOP:
+   case V4L2_FIELD_BOTTOM:
+   case V4L2_FIELD_NONE:
+   break;
+   case V4L2_FIELD_INTERLACED_TB:
+   case V4L2_FIELD_INTERLACED_BT:
+   case V4L2_FIELD_INTERLACED:
+   case V4L2_FIELD_SEQ_TB:
+   case V4L2_FIELD_SEQ_BT:
+   /* Use VIN hardware to combine the two fields */
+   fmt.format.height *= 2;
+   break;
+   default:
+   return -EPIPE;
+   }
+   break;
+   default:
+   return -EPIPE;
+   }
+
+   if (fmt.format.width != vin->format.width ||
+   fmt.format.height != vin->format.height)
+   return -EPIPE;
+
+   pipe = sd->entity.pipe ? sd->entity.pipe : >vdev.pipe;
+   if (media_pipeline_start(>vdev.entity, pipe))
+   return -EPIPE;
+
+   ret = v4l2_subdev_call(sd, video, s_stream, 1);
+   if (ret == -ENOIOCTLCMD)
+   ret = 0;
+   if (ret)
+   media_pipeline_stop(>vdev.entity);
+
+   return ret;
+}
+
 static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
struct rvin_dev *vin = vb2_get_drv_priv(vq);
-   struct v4l2_subdev *sd;
unsigned long flags;
int ret;
 
-   sd = vin_to_source(vin);
-   v4l2_subdev_call(sd, video, s_stream, 1);
+   ret = rvin_set_stream(vin, 1);
+   if (ret) {
+   spin_lock_irqsave(>qlock, flags);
+   return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
+   spin_unlock_irqrestore(>qlock, flags);
+   return ret;
+   }
 
spin_lock_irqsave(>qlock, flags);
 
@@ -1104,7 +1204,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, 
unsigned int count)
ret = rvin_capture_start(vin);
if (ret) {
return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
-   v4l2_subdev_call(sd, video, s_stream, 0);
+   rvin_set_stream(vin, 0);
}
 
spin_unlock_irqrestore(>qlock, flags);
@@ -1115,7 +1215,6 @@ static int rvin_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 static 

[PATCH v9 05/28] rcar-vin: move chip information to own struct

2017-12-07 Thread Niklas Söderlund
When Gen3 support is added to the driver more than chip ID will be
different for the different SoCs. To avoid a lot of if statements in the
code create a struct chip_info to store this information.

And while we are at it sort the compatible string entries and make use
of of_device_get_match_data() which will always work as the driver is DT
only, so there's always a valid match.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Kieran Bingham 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 54 ++---
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  3 +-
 drivers/media/platform/rcar-vin/rcar-vin.h  | 12 +--
 3 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 6ab51acd676641ec..73c1700a409bfd35 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -230,21 +230,53 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
  * Platform Device Driver
  */
 
+static const struct rvin_info rcar_info_h1 = {
+   .chip = RCAR_H1,
+};
+
+static const struct rvin_info rcar_info_m1 = {
+   .chip = RCAR_M1,
+};
+
+static const struct rvin_info rcar_info_gen2 = {
+   .chip = RCAR_GEN2,
+};
+
 static const struct of_device_id rvin_of_id_table[] = {
-   { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
-   { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
-   { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
-   { .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },
+   {
+   .compatible = "renesas,vin-r8a7778",
+   .data = _info_m1,
+   },
+   {
+   .compatible = "renesas,vin-r8a7779",
+   .data = _info_h1,
+   },
+   {
+   .compatible = "renesas,vin-r8a7790",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7791",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7793",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7794",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,rcar-gen2-vin",
+   .data = _info_gen2,
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
 
 static int rcar_vin_probe(struct platform_device *pdev)
 {
-   const struct of_device_id *match;
struct rvin_dev *vin;
struct resource *mem;
int irq, ret;
@@ -253,12 +285,8 @@ static int rcar_vin_probe(struct platform_device *pdev)
if (!vin)
return -ENOMEM;
 
-   match = of_match_device(of_match_ptr(rvin_of_id_table), >dev);
-   if (!match)
-   return -ENODEV;
-
vin->dev = >dev;
-   vin->chip = (enum chip_id)match->data;
+   vin->info = of_device_get_match_data(>dev);
 
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (mem == NULL)
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 4a0610a6b4503501..b1caa04921aa23bb 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -266,7 +266,8 @@ static int __rvin_try_format(struct rvin_dev *vin,
pix->sizeimage = max_t(u32, pix->sizeimage,
   rvin_format_sizeimage(pix));
 
-   if (vin->chip == RCAR_M1 && pix->pixelformat == V4L2_PIX_FMT_XBGR32) {
+   if (vin->info->chip == RCAR_M1 &&
+   pix->pixelformat == V4L2_PIX_FMT_XBGR32) {
vin_err(vin, "pixel format XBGR32 not supported on M1\n");
return -EINVAL;
}
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 85cb7ec53d2b08b5..0d3949c8c08c8f63 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -88,11 +88,19 @@ struct rvin_graph_entity {
unsigned int sink_pad;
 };
 
+/**
+ * struct rvin_info - Information about the particular VIN implementation
+ * @chip:  type of VIN chip
+ */
+struct rvin_info {
+   enum chip_id chip;
+};
+
 /**
  * struct rvin_dev - Renesas VIN device structure
  * @dev:   (OF) device
  * @base:  device I/O register space remapped to virtual memory
- * @chip:  type of VIN chip
+ * @info:  info about VIN instance
 

[PATCH v9 24/28] rcar-vin: add link notify for Gen3

2017-12-07 Thread Niklas Söderlund
Add the ability to process media device link change request. Link
enabling is a bit complicated on Gen3, whether or not it's possible to
enable a link depends on what other links already are enabled. On Gen3
the 8 VINs are split into two subgroup's (VIN0-3 and VIN4-7) and from a
routing perspective these two groups are independent of each other.
Each subgroup's routing is controlled by the subgroup VIN master
instance (VIN0 and VIN4).

There are a limited number of possible route setups available for each
subgroup and the configuration of each setup is dictated by the
hardware. On H3 for example there are 6 possible route setups for each
subgroup to choose from.

This leads to the media device link notification code being rather large
since it will find the best routing configuration to try and accommodate
as many links as possible. When it's not possible to enable a new link
due to hardware constrains the link_notifier callback will return
-EMLINK.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 205 
 1 file changed, 205 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 4a147437fa69c364..09ebeff1580556dc 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -27,6 +27,209 @@
 
 #include "rcar-vin.h"
 
+/* 
-
+ * Media Controller link notification
+ */
+
+static unsigned int rvin_group_csi_pad_to_chan(unsigned int pad)
+{
+   /*
+* The companion CSI-2 receiver driver (rcar-csi2) is known
+* and we know it have one source pad (pad 0) and four sink
+* pads (pad 1-4). So to translate a pad on the remote
+* CSI-2 receiver to the VIN internal channel number simply
+* subtract one from the pad number.
+*/
+   return pad - 1;
+}
+
+/* group lock should be held when calling this function */
+static int rvin_group_entity_to_vin_num(struct rvin_group *group,
+   struct media_entity *entity)
+{
+   struct video_device *vdev;
+   int i;
+
+   if (!is_media_entity_v4l2_video_device(entity))
+   return -ENODEV;
+
+   vdev = media_entity_to_video_device(entity);
+
+   for (i = 0; i < RCAR_VIN_NUM; i++) {
+   if (!group->vin[i])
+   continue;
+
+   if (>vin[i]->vdev == vdev)
+   return i;
+   }
+
+   return -ENODEV;
+}
+
+/* group lock should be held when calling this function */
+static int rvin_group_entity_to_csi_num(struct rvin_group *group,
+   struct media_entity *entity)
+{
+   struct v4l2_subdev *sd;
+   int i;
+
+   if (!is_media_entity_v4l2_subdev(entity))
+   return -ENODEV;
+
+   sd = media_entity_to_v4l2_subdev(entity);
+
+   for (i = 0; i < RVIN_CSI_MAX; i++)
+   if (group->csi[i].subdev == sd)
+   return i;
+
+   return -ENODEV;
+}
+
+/* group lock should be held when calling this function */
+static void __rvin_group_build_link_list(struct rvin_group *group,
+struct rvin_group_chsel *map,
+int start, int len)
+{
+   struct media_pad *vin_pad, *remote_pad;
+   unsigned int n;
+
+   for (n = 0; n < len; n++) {
+   map[n].csi = -1;
+   map[n].chan = -1;
+
+   if (!group->vin[start + n])
+   continue;
+
+   vin_pad = >vin[start + n]->vdev.entity.pads[0];
+
+   remote_pad = media_entity_remote_pad(vin_pad);
+   if (!remote_pad)
+   continue;
+
+   map[n].csi =
+   rvin_group_entity_to_csi_num(group, remote_pad->entity);
+   map[n].chan = rvin_group_csi_pad_to_chan(remote_pad->index);
+   }
+}
+
+/* group lock should be held when calling this function */
+static int __rvin_group_try_get_chsel(struct rvin_group *group,
+ struct rvin_group_chsel *map,
+ int start, int len)
+{
+   const struct rvin_group_chsel *sel;
+   unsigned int i, n;
+   int chsel;
+
+   for (i = 0; i < group->vin[start]->info->num_chsels; i++) {
+   chsel = i;
+   for (n = 0; n < len; n++) {
+
+   /* If the link is not active it's OK */
+   if (map[n].csi == -1)
+   continue;
+
+   /* Check if chsel matches requested link */
+   sel = >vin[start]->info->chsels[start + n][i];
+   if (map[n].csi != sel->csi ||
+  

[PATCH v9 21/28] rcar-vin: add group allocator functions

2017-12-07 Thread Niklas Söderlund
In media controller mode all VIN instances needs to be part of the same
media graph. There is also a need to each VIN instance to know and in
some cases be able to communicate with other VIN instances.

Add an allocator framework where the first VIN instance to be probed
creates a shared data structure and creates a media device.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 179 +++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  38 ++
 2 files changed, 215 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 45de4079fd835759..a6713fd61dd87a88 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -20,12 +20,170 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
 
 #include "rcar-vin.h"
 
+/* 
-
+ * Gen3 CSI2 Group Allocator
+ */
+
+static int rvin_group_read_id(struct rvin_dev *vin, struct device_node *np)
+{
+   u32 val;
+   int ret;
+
+   ret = of_property_read_u32(np, "renesas,id", );
+   if (ret) {
+   vin_err(vin, "%pOF: No renesas,id property found\n", np);
+   return -EINVAL;
+   }
+
+   if (val >= RCAR_VIN_NUM) {
+   vin_err(vin, "%pOF: Invalid renesas,id '%u'\n", np, val);
+   return -EINVAL;
+   }
+
+   return val;
+}
+
+static DEFINE_MUTEX(rvin_group_lock);
+static struct rvin_group *rvin_group_data;
+
+static void rvin_group_release(struct kref *kref)
+{
+   struct rvin_group *group =
+   container_of(kref, struct rvin_group, refcount);
+
+   mutex_lock(_group_lock);
+
+   media_device_unregister(>mdev);
+   media_device_cleanup(>mdev);
+
+   rvin_group_data = NULL;
+
+   mutex_unlock(_group_lock);
+
+   kfree(group);
+}
+
+static struct rvin_group *__rvin_group_allocate(struct rvin_dev *vin)
+{
+   struct rvin_group *group;
+
+   if (rvin_group_data) {
+   group = rvin_group_data;
+   kref_get(>refcount);
+   vin_dbg(vin, "%s: get group=%p\n", __func__, group);
+   return group;
+   }
+
+   group = kzalloc(sizeof(*group), GFP_KERNEL);
+   if (!group)
+   return NULL;
+
+   kref_init(>refcount);
+   rvin_group_data = group;
+
+   vin_dbg(vin, "%s: alloc group=%p\n", __func__, group);
+   return group;
+}
+
+static int rvin_group_add_vin(struct rvin_dev *vin)
+{
+   int ret;
+
+   ret = rvin_group_read_id(vin, vin->dev->of_node);
+   if (ret < 0)
+   return ret;
+
+   mutex_lock(>group->lock);
+
+   if (vin->group->vin[ret]) {
+   mutex_unlock(>group->lock);
+   vin_err(vin, "VIN number %d already occupied\n", ret);
+   return -EINVAL;
+   }
+
+   vin->group->vin[ret] = vin;
+
+   mutex_unlock(>group->lock);
+
+   vin_dbg(vin, "I'm VIN number %d", ret);
+
+   return 0;
+}
+
+static int rvin_group_allocate(struct rvin_dev *vin)
+{
+   struct rvin_group *group;
+   struct media_device *mdev;
+   int ret;
+
+   mutex_lock(_group_lock);
+
+   group = __rvin_group_allocate(vin);
+   if (!group) {
+   mutex_unlock(_group_lock);
+   return -ENOMEM;
+   }
+
+   /* Init group data if it is not already initialized */
+   mdev = >mdev;
+   if (!mdev->dev) {
+   mutex_init(>lock);
+   mdev->dev = vin->dev;
+
+   strlcpy(mdev->driver_name, "Renesas VIN",
+   sizeof(mdev->driver_name));
+   strlcpy(mdev->model, vin->dev->of_node->name,
+   sizeof(mdev->model));
+
+   snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
+dev_name(mdev->dev));
+   media_device_init(mdev);
+
+   ret = media_device_register(mdev);
+   if (ret) {
+   vin_err(vin, "Failed to register media device\n");
+   kref_put(>refcount, rvin_group_release);
+   mutex_unlock(_group_lock);
+   return ret;
+   }
+   }
+
+   vin->group = group;
+   vin->v4l2_dev.mdev = mdev;
+
+   ret = rvin_group_add_vin(vin);
+   if (ret) {
+   kref_put(>refcount, rvin_group_release);
+   mutex_unlock(_group_lock);
+   return ret;
+   }
+
+   mutex_unlock(_group_lock);
+
+   return 0;
+}
+
+static void rvin_group_delete(struct rvin_dev *vin)
+{
+   unsigned int i;
+
+   mutex_lock(>group->lock);
+   for (i = 0; i < RCAR_VIN_NUM; i++)
+   if (vin->group->vin[i] 

[PATCH v9 19/28] rcar-vin: use different v4l2 operations in media controller mode

2017-12-07 Thread Niklas Söderlund
When the driver runs in media controller mode it should not directly
control the subdevice instead userspace will be responsible for
configuring the pipeline. To be able to run in this mode a different set
of v4l2 operations needs to be used.

Add a new set of v4l2 operations to support the running without directly
interacting with the source subdevice.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c  |   3 +-
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 155 +++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |   1 +
 3 files changed, 155 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index d2788d8bb9565aaa..6c5df13b30d6dd14 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -628,7 +628,8 @@ static int rvin_setup(struct rvin_dev *vin)
/* Default to TB */
vnmc = VNMC_IM_FULL;
/* Use BT if video standard can be read and is 60 Hz format */
-   if (!v4l2_subdev_call(vin_to_source(vin), video, g_std, )) {
+   if (!vin->info->use_mc &&
+   !v4l2_subdev_call(vin_to_source(vin), video, g_std, )) {
if (std & V4L2_STD_525_60)
vnmc = VNMC_IM_FULL | VNMC_FOC;
}
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 0ffbf0c16fb7b00e..5fea2856fd61030f 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -23,6 +23,9 @@
 #include "rcar-vin.h"
 
 #define RVIN_DEFAULT_FORMATV4L2_PIX_FMT_YUYV
+#define RVIN_DEFAULT_WIDTH 800
+#define RVIN_DEFAULT_HEIGHT600
+#define RVIN_DEFAULT_COLORSPACEV4L2_COLORSPACE_SRGB
 
 /* 
-
  * Format Conversions
@@ -671,6 +674,84 @@ static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
.vidioc_unsubscribe_event   = v4l2_event_unsubscribe,
 };
 
+/* 
-
+ * V4L2 Media Controller
+ */
+
+static int __rvin_mc_try_format(struct rvin_dev *vin,
+   struct v4l2_pix_format *pix)
+{
+   /* Keep current field if no specific one is asked for */
+   if (pix->field == V4L2_FIELD_ANY)
+   pix->field = vin->format.field;
+
+   return rvin_format_align(vin, pix);
+}
+
+static int rvin_mc_try_fmt_vid_cap(struct file *file, void *priv,
+  struct v4l2_format *f)
+{
+   struct rvin_dev *vin = video_drvdata(file);
+
+   return __rvin_mc_try_format(vin, >fmt.pix);
+}
+
+static int rvin_mc_s_fmt_vid_cap(struct file *file, void *priv,
+struct v4l2_format *f)
+{
+   struct rvin_dev *vin = video_drvdata(file);
+   int ret;
+
+   if (vb2_is_busy(>queue))
+   return -EBUSY;
+
+   ret = __rvin_mc_try_format(vin, >fmt.pix);
+   if (ret)
+   return ret;
+
+   vin->format = f->fmt.pix;
+
+   return 0;
+}
+
+static int rvin_mc_enum_input(struct file *file, void *priv,
+ struct v4l2_input *i)
+{
+   if (i->index != 0)
+   return -EINVAL;
+
+   i->type = V4L2_INPUT_TYPE_CAMERA;
+   strlcpy(i->name, "Camera", sizeof(i->name));
+
+   return 0;
+}
+
+static const struct v4l2_ioctl_ops rvin_mc_ioctl_ops = {
+   .vidioc_querycap= rvin_querycap,
+   .vidioc_try_fmt_vid_cap = rvin_mc_try_fmt_vid_cap,
+   .vidioc_g_fmt_vid_cap   = rvin_g_fmt_vid_cap,
+   .vidioc_s_fmt_vid_cap   = rvin_mc_s_fmt_vid_cap,
+   .vidioc_enum_fmt_vid_cap= rvin_enum_fmt_vid_cap,
+
+   .vidioc_enum_input  = rvin_mc_enum_input,
+   .vidioc_g_input = rvin_g_input,
+   .vidioc_s_input = rvin_s_input,
+
+   .vidioc_reqbufs = vb2_ioctl_reqbufs,
+   .vidioc_create_bufs = vb2_ioctl_create_bufs,
+   .vidioc_querybuf= vb2_ioctl_querybuf,
+   .vidioc_qbuf= vb2_ioctl_qbuf,
+   .vidioc_dqbuf   = vb2_ioctl_dqbuf,
+   .vidioc_expbuf  = vb2_ioctl_expbuf,
+   .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+   .vidioc_streamon= vb2_ioctl_streamon,
+   .vidioc_streamoff   = vb2_ioctl_streamoff,
+
+   .vidioc_log_status  = v4l2_ctrl_log_status,
+   .vidioc_subscribe_event = rvin_subscribe_event,
+   .vidioc_unsubscribe_event   = v4l2_event_unsubscribe,
+};
+
 /* 

[PATCH v9 00/28] rcar-vin: Add Gen3 with media controller

2017-12-07 Thread Niklas Söderlund
Hi,

This series adds Gen3 VIN support to rcar-vin driver for Renesas r8a7795,
r8a7796 and r8a77970. It is based on the media-tree and depends on some 
of Fabrizio Castro patches as they touches the order of the compatible 
strings in the documentation to reduce merge conflicts. The dependencies 
are:

[PATCH v2 1/4] dt-bindings: media: rcar_vin: Reverse SoC part number list
[PATCH v2 2/4] dt-bindings: media: rcar_vin: add device tree support for 
r8a774[35]

The driver is tested on Renesas H3 (r8a7795, ES2.0),
M3-W (r8a7796) together with the rcar-csi2 driver (posted separately and
not yet upstream) and the Salvator-X onboard ADV7482. It is also tested 
on the V3M (r8a77970) on the Eagle board together with its expansion 
board with a ADV7482.

It is possible to capture both CVBS and HDMI video streams,
v4l2-compliance passes with no errors and media-ctl can be used to
change the routing and formats for the different entities in the media
graph.

Gen2 compatibility is verified on Koelsch and no problems where found,
video can be captured just like before and v4l2-compliance passes
without errors or warnings just like before this series.

I have started on a very basic test suite for the VIN driver at:

  https://git.ragnatech.se/vin-tests

And as before the state of the driver and information about how to test
it can be found on the elinux wiki:

  http://elinux.org/R-Car/Tests:rcar-vin

* Changes since b8
- Fixed issue in rvin_group_init() where rvin_group_update_links() was 
  called, but after moving the video device registration to the 
  complete() callback this is now invalid.
- Fixed spelling in commit messages.
- Added review and acks from Hans, Kieran and Rob.

* Changes since v7
- Dropped '[PATCH v7 02/25] rcar-vin: register the video device at probe time'
- Add patch which renames four badly name functions. Some of the 
  renaming was in v7 part of the dropped patch 02/25. Make it a own 
  patch and rename all badly named functions in one patch.
- Add patch to replace part of the functionality of the dropped patch v7 
  02/25. The new patch keeps the subdevice (un)registration calls in the 
  async callbacks bind() and unbind() but moves the direct subdevice 
  initialization which only is used on Gen2 from the Gen2 and Gen3 
  shared rvin_v4l2_register().
- Add patch to enable Renesas V3M (r8a77970)
- Patch 'rcar-vin: parse Gen3 OF and setup media graph' have had code 
  additions since v7 since it now registers the video devices in the 
  async complete() callback instead of at probe time as an effect of 
  dropping v7 02/25.
  - The complete() callback now register all video devices.
  - The unbind() callback now unregister all video devices.
  - A new member '*notifier' is added to struct rvin_group which keeps 
track of which rcar-vin instance have registered its notifier on the 
groups behalf.
  For the reason above all Reviewed-by tags have been dropped for this 
  patch.
- Replaced all kernel messages which used of_node_full_name() as now 
  only returns the basename and not till full path, thanks Geert.

printk("%s", of_node_full_name(ep)); -> printk("%pOF", ep);

- Added Reviewed-by tags from Hans, big thanks!

* Changes since v6
- Rebase ontop of latest media-tree which brings in the use of the
  fwnode async helpers for Gen2.
- Updated DT binding documentation, thanks Laurent for very helpful
  input!
- Removed help text which where copied in from v4l2_ctrl_handler_init()
  documentation when moving that code block, this was a residue from the
  soc_camera conversion and should have been removed at that time.
- Removed bad check of tvnorms which disables IOCTLs if it's not set,
  this was a residue from soc_camera conversion and have use in the
  current driver.
- Moved all subdevice initialization from complete to bound handler
  while improving the unbind handler. With this move all operations of
  the ctrl_handler from the subdevice is handled in either bound or
  unbind removing races pointed out by Laurent.
- Renamed rvin_v4l2_probe() -> rvin_v4l2_register() and
  rvin_v4l2_remove() -> rvin_v4l2_unregister().
- Fold rvin_mbus_supported() into its only caller.
- Sort compatible string entries in ascending order.
- Improved documentation for struct rvin_group_chsel.
- Clarify comment in rvin_group_csi_pad_to_chan().
- Make use of of_device_get_match_data() as suggested by Geert.
- Fixed spelling mistakes.
- Added review tags from Hans.

* Changes since v5
- Extract and make use of common format checking for both Gen2 and Gen3.
- Assign pad at declaration time in rvin_get_sd_format()
- Always call pm_runtime_{get_sync,put}() and v4l2_pipeline_pm_use()
  when opening/closing a video device, remove the check of
  v4l2_fh_is_singular_file().
- Make rvin_set_chsel() return void instead of int since it always
  return 0.
- Simplify the VIN group allocator functions.
- Make the group notifier callbacks and setup more robust.
- Moved the video device registration back to 

[PATCH v9 22/28] rcar-vin: add chsel information to rvin_info

2017-12-07 Thread Niklas Söderlund
Each Gen3 SoC has a limited set of predefined routing possibilities for
which CSI-2 device and virtual channel can be routed to which VIN
instance. Prepare to store this information in the struct rvin_info.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-vin.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 5f736a3500b6e10f..41bf24aa8a1a0aed 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -35,6 +35,9 @@
 /* Max number on VIN instances that can be in a system */
 #define RCAR_VIN_NUM 8
 
+/* Max number of CHSEL values for any Gen3 SoC */
+#define RCAR_CHSEL_MAX 6
+
 enum chip_id {
RCAR_H1,
RCAR_M1,
@@ -91,6 +94,22 @@ struct rvin_graph_entity {
 
 struct rvin_group;
 
+/** struct rvin_group_chsel - Map a CSI-2 receiver and channel to a CHSEL value
+ * @csi:   VIN internal number for CSI-2 device
+ * @chan:  Output channel of the CSI-2 receiver. Each R-Car CSI-2
+ * receiver has four output channels facing the VIN
+ * devices, each channel can carry one CSI-2 Virtual
+ * Channel (VC) and there are no correlation between
+ * output channel number and CSI-2 VC. It's up to the
+ * CSI-2 receiver driver to configure which VC is
+ * outputted on which channel, the VIN devices only
+ * cares about output channels.
+ */
+struct rvin_group_chsel {
+   enum rvin_csi_id csi;
+   unsigned int chan;
+};
+
 /**
  * struct rvin_info - Information about the particular VIN implementation
  * @chip:  type of VIN chip
@@ -98,6 +117,9 @@ struct rvin_group;
  *
  * max_width:  max input width the VIN supports
  * max_height: max input height the VIN supports
+ *
+ * num_chsels: number of possible chsel values for this VIN
+ * chsels: routing table VIN <-> CSI-2 for the chsel values
  */
 struct rvin_info {
enum chip_id chip;
@@ -105,6 +127,9 @@ struct rvin_info {
 
unsigned int max_width;
unsigned int max_height;
+
+   unsigned int num_chsels;
+   struct rvin_group_chsel chsels[RCAR_VIN_NUM][RCAR_CHSEL_MAX];
 };
 
 /**
-- 
2.15.0



[PATCH v9 28/28] rcar-vin: enable support for r8a77970

2017-12-07 Thread Niklas Söderlund
Add the SoC specific information for Renesas r8a77970.

Signed-off-by: Niklas Söderlund 
Tested-by: Kieran Bingham 
Acked-by: Rob Herring 
Reviewed-by: Hans Verkuil 
---
 .../devicetree/bindings/media/rcar_vin.txt |  1 +
 drivers/media/platform/rcar-vin/rcar-core.c| 40 ++
 2 files changed, 41 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt 
b/Documentation/devicetree/bindings/media/rcar_vin.txt
index 314743532bbb4523..6b98f8a3398fa493 100644
--- a/Documentation/devicetree/bindings/media/rcar_vin.txt
+++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
@@ -21,6 +21,7 @@ on Gen3 to a CSI-2 receiver.
- "renesas,vin-r8a7794" for the R8A7794 device
- "renesas,vin-r8a7795" for the R8A7795 device
- "renesas,vin-r8a7796" for the R8A7796 device
+   - "renesas,vin-r8a77970" for the R8A77970 device
- "renesas,rcar-gen2-vin" for a generic R-Car Gen2 or RZ/G1 compatible
  device.
- "renesas,rcar-gen3-vin" for a generic R-Car Gen3 compatible device.
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index ed7fbb58ad6846c1..136179ffeebf6862 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -1145,6 +1145,42 @@ static const struct rvin_info rcar_info_r8a7796 = {
},
 };
 
+static const struct rvin_info rcar_info_r8a77970 = {
+   .chip = RCAR_GEN3,
+   .use_mc = true,
+   .max_width = 4096,
+   .max_height = 4096,
+
+   .num_chsels = 5,
+   .chsels = {
+   {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   }, {
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_NC, .chan = 0 },
+   }, {
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_NC, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_NC, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_NC, .chan = 0 },
+   },
+   },
+};
+
 static const struct of_device_id rvin_of_id_table[] = {
{
.compatible = "renesas,vin-r8a7778",
@@ -1182,6 +1218,10 @@ static const struct of_device_id rvin_of_id_table[] = {
.compatible = "renesas,vin-r8a7796",
.data = _info_r8a7796,
},
+   {
+   .compatible = "renesas,vin-r8a77970",
+   .data = _info_r8a77970,
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
-- 
2.15.0



[PATCH v9 18/28] rcar-vin: break out format alignment and checking

2017-12-07 Thread Niklas Söderlund
Part of the format alignment and checking can be shared with the Gen3
format handling. Break that part out to its own function. While doing
this clean up the checking and add more checks.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 98 +++--
 1 file changed, 51 insertions(+), 47 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 56c5183f55922e1d..0ffbf0c16fb7b00e 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -86,6 +86,56 @@ static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
return pix->bytesperline * pix->height;
 }
 
+static int rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
+{
+   u32 walign;
+
+   /* If requested format is not supported fallback to the default */
+   if (!rvin_format_from_pixel(pix->pixelformat)) {
+   vin_dbg(vin, "Format 0x%x not found, using default 0x%x\n",
+   pix->pixelformat, RVIN_DEFAULT_FORMAT);
+   pix->pixelformat = RVIN_DEFAULT_FORMAT;
+   }
+
+   switch (pix->field) {
+   case V4L2_FIELD_TOP:
+   case V4L2_FIELD_BOTTOM:
+   case V4L2_FIELD_NONE:
+   case V4L2_FIELD_INTERLACED_TB:
+   case V4L2_FIELD_INTERLACED_BT:
+   case V4L2_FIELD_INTERLACED:
+   break;
+   default:
+   pix->field = V4L2_FIELD_NONE;
+   break;
+   }
+
+   /* Check that colorspace is reasonable, if not keep current */
+   if (!pix->colorspace || pix->colorspace >= 0xff)
+   pix->colorspace = vin->format.colorspace;
+
+   /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
+   walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
+
+   /* Limit to VIN capabilities */
+   v4l_bound_align_image(>width, 2, vin->info->max_width, walign,
+ >height, 4, vin->info->max_height, 2, 0);
+
+   pix->bytesperline = rvin_format_bytesperline(pix);
+   pix->sizeimage = rvin_format_sizeimage(pix);
+
+   if (vin->info->chip == RCAR_M1 &&
+   pix->pixelformat == V4L2_PIX_FMT_XBGR32) {
+   vin_err(vin, "pixel format XBGR32 not supported on M1\n");
+   return -EINVAL;
+   }
+
+   vin_dbg(vin, "Format %ux%u bpl: %d size: %d\n",
+   pix->width, pix->height, pix->bytesperline, pix->sizeimage);
+
+   return 0;
+}
+
 /* 
-
  * V4L2
  */
@@ -191,64 +241,18 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 static int __rvin_try_format(struct rvin_dev *vin,
 u32 which, struct v4l2_pix_format *pix)
 {
-   u32 walign;
int ret;
 
/* Keep current field if no specific one is asked for */
if (pix->field == V4L2_FIELD_ANY)
pix->field = vin->format.field;
 
-   /* If requested format is not supported fallback to the default */
-   if (!rvin_format_from_pixel(pix->pixelformat)) {
-   vin_dbg(vin, "Format 0x%x not found, using default 0x%x\n",
-   pix->pixelformat, RVIN_DEFAULT_FORMAT);
-   pix->pixelformat = RVIN_DEFAULT_FORMAT;
-   }
-
-   /* Always recalculate */
-   pix->bytesperline = 0;
-   pix->sizeimage = 0;
-
/* Limit to source capabilities */
ret = __rvin_try_format_source(vin, which, pix);
if (ret)
return ret;
 
-   switch (pix->field) {
-   case V4L2_FIELD_TOP:
-   case V4L2_FIELD_BOTTOM:
-   case V4L2_FIELD_NONE:
-   case V4L2_FIELD_INTERLACED_TB:
-   case V4L2_FIELD_INTERLACED_BT:
-   case V4L2_FIELD_INTERLACED:
-   break;
-   default:
-   pix->field = V4L2_FIELD_NONE;
-   break;
-   }
-
-   /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
-   walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
-
-   /* Limit to VIN capabilities */
-   v4l_bound_align_image(>width, 2, vin->info->max_width, walign,
- >height, 4, vin->info->max_height, 2, 0);
-
-   pix->bytesperline = max_t(u32, pix->bytesperline,
- rvin_format_bytesperline(pix));
-   pix->sizeimage = max_t(u32, pix->sizeimage,
-  rvin_format_sizeimage(pix));
-
-   if (vin->info->chip == RCAR_M1 &&
-   pix->pixelformat == V4L2_PIX_FMT_XBGR32) {
-   vin_err(vin, "pixel format XBGR32 not supported on M1\n");
-   return -EINVAL;
-   }
-
-   vin_dbg(vin, "Format %ux%u bpl: %d size: %d\n",
-   pix->width, pix->height, pix->bytesperline, 

[PATCH v9 20/28] rcar-vin: prepare for media controller mode initialization

2017-12-07 Thread Niklas Söderlund
When running in media controller mode a media pad is needed, register
one. Also set the media bus format to CSI-2.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 24 ++--
 drivers/media/platform/rcar-vin/rcar-vin.h  |  4 
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 61f48ecc1ab815ec..45de4079fd835759 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -46,6 +46,10 @@ static int rvin_find_pad(struct v4l2_subdev *sd, int 
direction)
return -EINVAL;
 }
 
+/* 
-
+ * Digital async notifier
+ */
+
 static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
 {
struct rvin_dev *vin = notifier_to_vin(notifier);
@@ -226,6 +230,20 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
return 0;
 }
 
+/* 
-
+ * Group async notifier
+ */
+
+static int rvin_group_init(struct rvin_dev *vin)
+{
+   /* All our sources are CSI-2 */
+   vin->mbus_cfg.type = V4L2_MBUS_CSI2;
+   vin->mbus_cfg.flags = 0;
+
+   vin->pad.flags = MEDIA_PAD_FL_SINK;
+   return media_entity_pads_init(>vdev.entity, 1, >pad);
+}
+
 /* 
-
  * Platform Device Driver
  */
@@ -314,8 +332,10 @@ static int rcar_vin_probe(struct platform_device *pdev)
return ret;
 
platform_set_drvdata(pdev, vin);
-
-   ret = rvin_digital_graph_init(vin);
+   if (vin->info->use_mc)
+   ret = rvin_group_init(vin);
+   else
+   ret = rvin_digital_graph_init(vin);
if (ret < 0)
goto error;
 
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index fd3cd781be0ab1cf..07d270a976893cdb 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -103,6 +103,8 @@ struct rvin_info {
  * @notifier:  V4L2 asynchronous subdevs notifier
  * @digital:   entity in the DT for local digital subdevice
  *
+ * @pad:   pad for media controller
+ *
  * @lock:  protects @queue
  * @queue: vb2 buffers queue
  *
@@ -132,6 +134,8 @@ struct rvin_dev {
struct v4l2_async_notifier notifier;
struct rvin_graph_entity *digital;
 
+   struct media_pad pad;
+
struct mutex lock;
struct vb2_queue queue;
 
-- 
2.15.0



[PATCH v9 15/28] rcar-vin: enable Gen3 hardware configuration

2017-12-07 Thread Niklas Söderlund
Add the register needed to work with Gen3 hardware. This patch adds
the logic for how to work with the Gen3 hardware. More work is required
to enable the subdevice structure needed to configure capturing.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 94 --
 drivers/media/platform/rcar-vin/rcar-vin.h |  1 +
 2 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index d7660f485a2df9e4..ace95d5b543a17e3 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -33,21 +33,23 @@
 #define VNELPRC_REG0x10/* Video n End Line Pre-Clip Register */
 #define VNSPPRC_REG0x14/* Video n Start Pixel Pre-Clip Register */
 #define VNEPPRC_REG0x18/* Video n End Pixel Pre-Clip Register */
-#define VNSLPOC_REG0x1C/* Video n Start Line Post-Clip Register */
-#define VNELPOC_REG0x20/* Video n End Line Post-Clip Register */
-#define VNSPPOC_REG0x24/* Video n Start Pixel Post-Clip Register */
-#define VNEPPOC_REG0x28/* Video n End Pixel Post-Clip Register */
 #define VNIS_REG   0x2C/* Video n Image Stride Register */
 #define VNMB_REG(m)(0x30 + ((m) << 2)) /* Video n Memory Base m Register */
 #define VNIE_REG   0x40/* Video n Interrupt Enable Register */
 #define VNINTS_REG 0x44/* Video n Interrupt Status Register */
 #define VNSI_REG   0x48/* Video n Scanline Interrupt Register */
 #define VNMTC_REG  0x4C/* Video n Memory Transfer Control Register */
-#define VNYS_REG   0x50/* Video n Y Scale Register */
-#define VNXS_REG   0x54/* Video n X Scale Register */
 #define VNDMR_REG  0x58/* Video n Data Mode Register */
 #define VNDMR2_REG 0x5C/* Video n Data Mode Register 2 */
 #define VNUVAOF_REG0x60/* Video n UV Address Offset Register */
+
+/* Register offsets specific for Gen2 */
+#define VNSLPOC_REG0x1C/* Video n Start Line Post-Clip Register */
+#define VNELPOC_REG0x20/* Video n End Line Post-Clip Register */
+#define VNSPPOC_REG0x24/* Video n Start Pixel Post-Clip Register */
+#define VNEPPOC_REG0x28/* Video n End Pixel Post-Clip Register */
+#define VNYS_REG   0x50/* Video n Y Scale Register */
+#define VNXS_REG   0x54/* Video n X Scale Register */
 #define VNC1A_REG  0x80/* Video n Coefficient Set C1A Register */
 #define VNC1B_REG  0x84/* Video n Coefficient Set C1B Register */
 #define VNC1C_REG  0x88/* Video n Coefficient Set C1C Register */
@@ -73,9 +75,13 @@
 #define VNC8B_REG  0xF4/* Video n Coefficient Set C8B Register */
 #define VNC8C_REG  0xF8/* Video n Coefficient Set C8C Register */
 
+/* Register offsets specific for Gen3 */
+#define VNCSI_IFMD_REG 0x20 /* Video n CSI2 Interface Mode Register */
 
 /* Register bit fields for R-Car VIN */
 /* Video n Main Control Register bits */
+#define VNMC_DPINE (1 << 27) /* Gen3 specific */
+#define VNMC_SCLE  (1 << 26) /* Gen3 specific */
 #define VNMC_FOC   (1 << 21)
 #define VNMC_YCAL  (1 << 19)
 #define VNMC_INF_YUV8_BT656(0 << 16)
@@ -119,6 +125,13 @@
 #define VNDMR2_FTEV(1 << 17)
 #define VNDMR2_VLV(n)  ((n & 0xf) << 12)
 
+/* Video n CSI2 Interface Mode Register (Gen3) */
+#define VNCSI_IFMD_DES2(1 << 27)
+#define VNCSI_IFMD_DES1(1 << 26)
+#define VNCSI_IFMD_DES0(1 << 25)
+#define VNCSI_IFMD_CSI_CHSEL(n) ((n & 0xf) << 0)
+#define VNCSI_IFMD_CSI_CHSEL_MASK 0xf
+
 struct rvin_buffer {
struct vb2_v4l2_buffer vb;
struct list_head list;
@@ -514,28 +527,10 @@ static void rvin_set_coeff(struct rvin_dev *vin, unsigned 
short xs)
rvin_write(vin, p_set->coeff_set[23], VNC8C_REG);
 }
 
-static void rvin_crop_scale_comp(struct rvin_dev *vin)
+static void rvin_crop_scale_comp_gen2(struct rvin_dev *vin)
 {
u32 xs, ys;
 
-   /* Set Start/End Pixel/Line Pre-Clip */
-   rvin_write(vin, vin->crop.left, VNSPPRC_REG);
-   rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG);
-   switch (vin->format.field) {
-   case V4L2_FIELD_INTERLACED:
-   case V4L2_FIELD_INTERLACED_TB:
-   case V4L2_FIELD_INTERLACED_BT:
-   rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG);
-   rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1,
-  VNELPRC_REG);
-   break;
-   default:
-   rvin_write(vin, vin->crop.top, VNSLPRC_REG);
-   rvin_write(vin, vin->crop.top + vin->crop.height - 1,
-  VNELPRC_REG);
-   break;
-   }
-
/* Set scaling coefficient */

[PATCH v9 14/28] rcar-vin: move media bus configuration to struct rvin_info

2017-12-07 Thread Niklas Söderlund
Bus configuration will once the driver is extended to support Gen3
contain information not specific to only the directly connected parallel
subdevice. Move it to struct rvin_info to show it's not always coupled
to the parallel subdevice.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 18 +-
 drivers/media/platform/rcar-vin/rcar-dma.c  | 11 ++-
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  2 +-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  9 -
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 03d3cd63e38bee11..7d49904cab9cb2d9 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -101,10 +101,10 @@ static int rvin_digital_notify_bound(struct 
v4l2_async_notifier *notifier,
vin->digital->sink_pad = ret < 0 ? 0 : ret;
 
/* Find compatible subdevices mbus format */
-   vin->digital->code = 0;
+   vin->code = 0;
code.index = 0;
code.pad = vin->digital->source_pad;
-   while (!vin->digital->code &&
+   while (!vin->code &&
   !v4l2_subdev_call(subdev, pad, enum_mbus_code, NULL, )) {
code.index++;
switch (code.code) {
@@ -112,16 +112,16 @@ static int rvin_digital_notify_bound(struct 
v4l2_async_notifier *notifier,
case MEDIA_BUS_FMT_UYVY8_2X8:
case MEDIA_BUS_FMT_UYVY10_2X10:
case MEDIA_BUS_FMT_RGB888_1X24:
-   vin->digital->code = code.code;
+   vin->code = code.code;
vin_dbg(vin, "Found media bus format for %s: %d\n",
-   subdev->name, vin->digital->code);
+   subdev->name, vin->code);
break;
default:
break;
}
}
 
-   if (!vin->digital->code) {
+   if (!vin->code) {
vin_err(vin, "Unsupported media bus format for %s\n",
subdev->name);
return -EINVAL;
@@ -179,16 +179,16 @@ static int rvin_digital_parse_v4l2(struct device *dev,
if (vep->base.port || vep->base.id)
return -ENOTCONN;
 
-   rvge->mbus_cfg.type = vep->bus_type;
+   vin->mbus_cfg.type = vep->bus_type;
 
-   switch (rvge->mbus_cfg.type) {
+   switch (vin->mbus_cfg.type) {
case V4L2_MBUS_PARALLEL:
vin_dbg(vin, "Found PARALLEL media bus\n");
-   rvge->mbus_cfg.flags = vep->bus.parallel.flags;
+   vin->mbus_cfg.flags = vep->bus.parallel.flags;
break;
case V4L2_MBUS_BT656:
vin_dbg(vin, "Found BT656 media bus\n");
-   rvge->mbus_cfg.flags = 0;
+   vin->mbus_cfg.flags = 0;
break;
default:
vin_err(vin, "Unknown media bus type\n");
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index e6478088d9464221..d7660f485a2df9e4 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -633,7 +633,7 @@ static int rvin_setup(struct rvin_dev *vin)
/*
 * Input interface
 */
-   switch (vin->digital->code) {
+   switch (vin->code) {
case MEDIA_BUS_FMT_YUYV8_1X16:
/* BT.601/BT.1358 16bit YCbCr422 */
vnmc |= VNMC_INF_YUV16;
@@ -641,7 +641,7 @@ static int rvin_setup(struct rvin_dev *vin)
break;
case MEDIA_BUS_FMT_UYVY8_2X8:
/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
-   vnmc |= vin->digital->mbus_cfg.type == V4L2_MBUS_BT656 ?
+   vnmc |= vin->mbus_cfg.type == V4L2_MBUS_BT656 ?
VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
input_is_yuv = true;
break;
@@ -650,7 +650,7 @@ static int rvin_setup(struct rvin_dev *vin)
break;
case MEDIA_BUS_FMT_UYVY10_2X10:
/* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
-   vnmc |= vin->digital->mbus_cfg.type == V4L2_MBUS_BT656 ?
+   vnmc |= vin->mbus_cfg.type == V4L2_MBUS_BT656 ?
VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
input_is_yuv = true;
break;
@@ -662,11 +662,11 @@ static int rvin_setup(struct rvin_dev *vin)
dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
 
/* Hsync Signal Polarity Select */
-   if (!(vin->digital->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
+   if (!(vin->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
dmr2 |= VNDMR2_HPS;
 
/* Vsync Signal Polarity 

[PATCH v9 26/28] rcar-vin: enable support for r8a7795

2017-12-07 Thread Niklas Söderlund
Add the SoC specific information for Renesas r8a7795 ES1.x and ES2.0.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/Kconfig |   2 +-
 drivers/media/platform/rcar-vin/rcar-core.c | 150 
 2 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/Kconfig 
b/drivers/media/platform/rcar-vin/Kconfig
index af4c98b44d2e22cb..8fa7ee468c63afb9 100644
--- a/drivers/media/platform/rcar-vin/Kconfig
+++ b/drivers/media/platform/rcar-vin/Kconfig
@@ -6,7 +6,7 @@ config VIDEO_RCAR_VIN
select V4L2_FWNODE
---help---
  Support for Renesas R-Car Video Input (VIN) driver.
- Supports R-Car Gen2 SoCs.
+ Supports R-Car Gen2 and Gen3 SoCs.
 
  To compile this driver as a module, choose M here: the
  module will be called rcar-vin.
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 09ebeff1580556dc..66a8144fbba437d3 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -956,6 +957,134 @@ static const struct rvin_info rcar_info_gen2 = {
.max_height = 2048,
 };
 
+static const struct rvin_info rcar_info_r8a7795 = {
+   .chip = RCAR_GEN3,
+   .use_mc = true,
+   .max_width = 4096,
+   .max_height = 4096,
+
+   .num_chsels = 5,
+   .chsels = {
+   {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI40, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   }, {
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 1 },
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 1 },
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI41, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI41, .chan = 2 },
+   { .csi = RVIN_CSI20, .chan = 2 },
+   }, {
+   { .csi = RVIN_CSI41, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI20, .chan = 1 },
+   { .csi = RVIN_CSI41, .chan = 3 },
+   { .csi = RVIN_CSI20, .chan = 3 },
+   },
+   },
+};
+
+static const struct rvin_info rcar_info_r8a7795es1 = {
+   .chip = RCAR_GEN3,
+   .use_mc = true,
+   .max_width = 4096,
+   .max_height = 4096,
+
+   .num_chsels = 6,
+   .chsels = {
+   {
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   }, {
+   { .csi = RVIN_CSI20, .chan = 0 },
+   { .csi = RVIN_CSI21, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 0 },
+   { .csi = RVIN_CSI40, .chan = 1 },
+   { .csi = RVIN_CSI20, 

[PATCH v9 17/28] rcar-vin: add flag to switch to media controller mode

2017-12-07 Thread Niklas Söderlund
On Gen3 a media controller API needs to be used to allow userspace to
configure the subdevices in the pipeline instead of directly controlling
a single source subdevice, which is and will continue to be the mode of
operation on Gen2.

Prepare for these two modes of operation by adding a flag to struct
rvin_info which will control which mode to use.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 6 +-
 drivers/media/platform/rcar-vin/rcar-vin.h  | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 7d49904cab9cb2d9..61f48ecc1ab815ec 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -232,18 +232,21 @@ static int rvin_digital_graph_init(struct rvin_dev *vin)
 
 static const struct rvin_info rcar_info_h1 = {
.chip = RCAR_H1,
+   .use_mc = false,
.max_width = 2048,
.max_height = 2048,
 };
 
 static const struct rvin_info rcar_info_m1 = {
.chip = RCAR_M1,
+   .use_mc = false,
.max_width = 2048,
.max_height = 2048,
 };
 
 static const struct rvin_info rcar_info_gen2 = {
.chip = RCAR_GEN2,
+   .use_mc = false,
.max_width = 2048,
.max_height = 2048,
 };
@@ -338,7 +341,8 @@ static int rcar_vin_remove(struct platform_device *pdev)
v4l2_async_notifier_unregister(>notifier);
v4l2_async_notifier_cleanup(>notifier);
 
-   v4l2_ctrl_handler_free(>ctrl_handler);
+   if (!vin->info->use_mc)
+   v4l2_ctrl_handler_free(>ctrl_handler);
 
rvin_dma_unregister(vin);
 
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 7819c760c2c13422..0747873c2b9cb74c 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -77,12 +77,14 @@ struct rvin_graph_entity {
 /**
  * struct rvin_info - Information about the particular VIN implementation
  * @chip:  type of VIN chip
+ * @use_mc:use media controller instead of controlling subdevice
  *
  * max_width:  max input width the VIN supports
  * max_height: max input height the VIN supports
  */
 struct rvin_info {
enum chip_id chip;
+   bool use_mc;
 
unsigned int max_width;
unsigned int max_height;
-- 
2.15.0



[PATCH v9 16/28] rcar-vin: add function to manipulate Gen3 chsel value

2017-12-07 Thread Niklas Söderlund
On Gen3 the CSI-2 routing is controlled by the VnCSI_IFMD register. One
feature of this register is that it's only present in the VIN0 and VIN4
instances. The register in VIN0 controls the routing for VIN0-3 and the
register in VIN4 controls routing for VIN4-7.

To be able to control routing from a media device this function is need
to control runtime PM for the subgroup master (VIN0 and VIN4). The
subgroup master must be switched on before the register is manipulated,
once the operation is complete it's safe to switch the master off and
the new routing will still be in effect.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 25 +
 drivers/media/platform/rcar-vin/rcar-vin.h |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index ace95d5b543a17e3..d2788d8bb9565aaa 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -16,6 +16,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -1228,3 +1229,27 @@ int rvin_dma_register(struct rvin_dev *vin, int irq)
 
return ret;
 }
+
+/* 
-
+ * Gen3 CHSEL manipulation
+ */
+
+void rvin_set_chsel(struct rvin_dev *vin, u8 chsel)
+{
+   u32 ifmd, vnmc;
+
+   pm_runtime_get_sync(vin->dev);
+
+   /* Make register writes take effect immediately */
+   vnmc = rvin_read(vin, VNMC_REG) & ~VNMC_VUP;
+   rvin_write(vin, vnmc, VNMC_REG);
+
+   ifmd = VNCSI_IFMD_DES2 | VNCSI_IFMD_DES1 | VNCSI_IFMD_DES0 |
+   VNCSI_IFMD_CSI_CHSEL(chsel);
+
+   rvin_write(vin, ifmd, VNCSI_IFMD_REG);
+
+   vin_dbg(vin, "Set IFMD 0x%x\n", ifmd);
+
+   pm_runtime_put(vin->dev);
+}
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index a440effe4b86af31..7819c760c2c13422 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -163,4 +163,6 @@ void rvin_v4l2_unregister(struct rvin_dev *vin);
 
 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
 
+void rvin_set_chsel(struct rvin_dev *vin, u8 chsel);
+
 #endif
-- 
2.15.0



[PATCH v9 01/28] rcar-vin: add Gen3 devicetree bindings documentation

2017-12-07 Thread Niklas Söderlund
Document the devicetree bindings for the CSI-2 inputs available on Gen3.

There is a need to add a custom property 'renesas,id' and to define
which CSI-2 input is described in which endpoint under the port@1 node.
This information is needed since there are a set of predefined routes
between each VIN and CSI-2 block. This routing table will be kept
inside the driver but in order for it to act on it it must know which
VIN and CSI-2 is which.

Signed-off-by: Niklas Söderlund 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/media/rcar_vin.txt | 116 ++---
 1 file changed, 104 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt 
b/Documentation/devicetree/bindings/media/rcar_vin.txt
index ff9697ed81396e64..5a95d9668d2c7dfd 100644
--- a/Documentation/devicetree/bindings/media/rcar_vin.txt
+++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
@@ -2,8 +2,12 @@ Renesas R-Car Video Input driver (rcar_vin)
 ---
 
 The rcar_vin device provides video input capabilities for the Renesas R-Car
-family of devices. The current blocks are always slaves and suppot one input
-channel which can be either RGB, YUYV or BT656.
+family of devices.
+
+Each VIN instance has a single parallel input that supports RGB and YUV video,
+with both external synchronization and BT.656 synchronization for the latter.
+Depending on the instance the VIN input is connected to external SoC pins, or
+on Gen3 to a CSI-2 receiver.
 
  - compatible: Must be one or more of the following
- "renesas,vin-r8a7743" for the R8A7743 device
@@ -31,21 +35,38 @@ channel which can be either RGB, YUYV or BT656.
 Additionally, an alias named vinX will need to be created to specify
 which video input device this is.
 
-The per-board settings:
+The per-board settings Gen2:
  - port sub-node describing a single endpoint connected to the vin
as described in video-interfaces.txt[1]. Only the first one will
be considered as each vin interface has one input port.
 
-   These settings are used to work out video input format and widths
-   into the system.
+The per-board settings Gen3:
+
+Gen3 can support both a single connected parallel input source from
+external SoC pins (port0) and/or multiple parallel input sources from
+local SoC CSI-2 receivers (port1) depending on SoC.
 
+- renesas,id - ID number of the VIN, VINx in the documentation.
+- ports
+- port0 - sub-node describing a single endpoint connected to the VIN
+  from external SoC pins described in video-interfaces.txt[1]. Only
+  the first one will be considered as each VIN interface has at most
+  one set of SoC external input pins.
+- port1 - sub-nodes describing one or more endpoints connected to
+  the VIN from local SoC CSI-2 receivers. The endpoint numbers must
+  use the following schema.
 
-Device node example

+- Endpoint 0 - sub-node describing the endpoint which is CSI20
+- Endpoint 1 - sub-node describing the endpoint which is CSI21
+- Endpoint 2 - sub-node describing the endpoint which is CSI40
+- Endpoint 3 - sub-node describing the endpoint which is CSI41
 
-   aliases {
-  vin0 = 
-   };
+Device node example Gen2
+
+
+aliases {
+vin0 = 
+};
 
 vin0: vin@0xe6ef {
 compatible = "renesas,vin-r8a7790", "renesas,rcar-gen2-vin";
@@ -55,8 +76,8 @@ Device node example
 status = "disabled";
 };
 
-Board setup example (vin1 composite video input)
-
+Board setup example Gen2 (vin1 composite video input)
+-
 
{
 status = "ok";
@@ -95,6 +116,77 @@ Board setup example (vin1 composite video input)
 };
 };
 
+Device node example Gen3
+
+
+vin0: video@e6ef {
+compatible = "renesas,vin-r8a7795";
+reg = <0 0xe6ef 0 0x1000>;
+interrupts = ;
+clocks = < CPG_MOD 811>;
+power-domains = < R8A7795_PD_ALWAYS_ON>;
+resets = < 811>;
+renesas,id = <0>;
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@1 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+reg = <1>;
+
+vin0csi20: endpoint@0 {
+reg = <0>;
+remote-endpoint= <>;
+};
+vin0csi21: endpoint@1 {
+reg = <1>;
+  

[PATCH v9 02/28] rcar-vin: rename poorly named initialize and cleanup functions

2017-12-07 Thread Niklas Söderlund
The functions to initialize and cleanup the hardware and video device
where poorly named from the start. Rename them to better describe their
intended function.

Signed-off-by: Niklas Söderlund 
Reviewed-by: Kieran Bingham 
Reviewed-by: Hans Verkuil 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 10 +-
 drivers/media/platform/rcar-vin/rcar-dma.c  |  6 +++---
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  4 ++--
 drivers/media/platform/rcar-vin/rcar-vin.h  |  8 
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 108d776f32651b27..f7a4c21909da6923 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -93,7 +93,7 @@ static int rvin_digital_notify_complete(struct 
v4l2_async_notifier *notifier)
return ret;
}
 
-   return rvin_v4l2_probe(vin);
+   return rvin_v4l2_register(vin);
 }
 
 static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier,
@@ -103,7 +103,7 @@ static void rvin_digital_notify_unbind(struct 
v4l2_async_notifier *notifier,
struct rvin_dev *vin = notifier_to_vin(notifier);
 
vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
-   rvin_v4l2_remove(vin);
+   rvin_v4l2_unregister(vin);
vin->digital->subdev = NULL;
 }
 
@@ -245,7 +245,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
if (irq < 0)
return irq;
 
-   ret = rvin_dma_probe(vin, irq);
+   ret = rvin_dma_register(vin, irq);
if (ret)
return ret;
 
@@ -260,7 +260,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
 
return 0;
 error:
-   rvin_dma_remove(vin);
+   rvin_dma_unregister(vin);
v4l2_async_notifier_cleanup(>notifier);
 
return ret;
@@ -275,7 +275,7 @@ static int rcar_vin_remove(struct platform_device *pdev)
v4l2_async_notifier_unregister(>notifier);
v4l2_async_notifier_cleanup(>notifier);
 
-   rvin_dma_remove(vin);
+   rvin_dma_unregister(vin);
 
return 0;
 }
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 23fdff7a7370842e..d701b52d198243b5 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1153,14 +1153,14 @@ static const struct vb2_ops rvin_qops = {
.wait_finish= vb2_ops_wait_finish,
 };
 
-void rvin_dma_remove(struct rvin_dev *vin)
+void rvin_dma_unregister(struct rvin_dev *vin)
 {
mutex_destroy(>lock);
 
v4l2_device_unregister(>v4l2_dev);
 }
 
-int rvin_dma_probe(struct rvin_dev *vin, int irq)
+int rvin_dma_register(struct rvin_dev *vin, int irq)
 {
struct vb2_queue *q = >queue;
int i, ret;
@@ -1208,7 +1208,7 @@ int rvin_dma_probe(struct rvin_dev *vin, int irq)
 
return 0;
 error:
-   rvin_dma_remove(vin);
+   rvin_dma_unregister(vin);
 
return ret;
 }
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index b479b882da12f62d..178aecc94962abe2 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -839,7 +839,7 @@ static const struct v4l2_file_operations rvin_fops = {
.read   = vb2_fop_read,
 };
 
-void rvin_v4l2_remove(struct rvin_dev *vin)
+void rvin_v4l2_unregister(struct rvin_dev *vin)
 {
v4l2_info(>v4l2_dev, "Removing %s\n",
  video_device_node_name(>vdev));
@@ -866,7 +866,7 @@ static void rvin_notify(struct v4l2_subdev *sd,
}
 }
 
-int rvin_v4l2_probe(struct rvin_dev *vin)
+int rvin_v4l2_register(struct rvin_dev *vin)
 {
struct video_device *vdev = >vdev;
struct v4l2_subdev *sd = vin_to_source(vin);
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 5382078143fb3869..85cb7ec53d2b08b5 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -153,11 +153,11 @@ struct rvin_dev {
 #define vin_warn(d, fmt, arg...)   dev_warn(d->dev, fmt, ##arg)
 #define vin_err(d, fmt, arg...)dev_err(d->dev, fmt, ##arg)
 
-int rvin_dma_probe(struct rvin_dev *vin, int irq);
-void rvin_dma_remove(struct rvin_dev *vin);
+int rvin_dma_register(struct rvin_dev *vin, int irq);
+void rvin_dma_unregister(struct rvin_dev *vin);
 
-int rvin_v4l2_probe(struct rvin_dev *vin);
-void rvin_v4l2_remove(struct rvin_dev *vin);
+int rvin_v4l2_register(struct rvin_dev *vin);
+void rvin_v4l2_unregister(struct rvin_dev *vin);
 
 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
 
-- 
2.15.0



[PATCH] kmstest.py: Update to th latest kmsxx Python bindings

2017-12-07 Thread Laurent Pinchart
Commit 706a44abb3aa ("Update to latest pybind11") of kmsxx broke the
test suite by changing the signature of the AtomicRequest::commit
function. Update the test suite accordingly.

Signed-off-by: Laurent Pinchart 
---
 tests/kmstest.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

The aforementioned commit also broke the test suite due to two other issues
that need to be fixed in kmsxx. Two patches have been submitted for upstream
inclusion, they can in the meantime be found at

git://git.ideasonboard.com/renesas/kmsxx.git master

diff --git a/tests/kmstest.py b/tests/kmstest.py
index 45d619c7a9be..7de785edd1e3 100755
--- a/tests/kmstest.py
+++ b/tests/kmstest.py
@@ -238,7 +238,7 @@ class KMSTest(object):
 if sync:
 return req.commit_sync(True)
 else:
-return req.commit(self, True)
+return req.commit(0, True)
 
 def atomic_crtc_mode_set(self, crtc, connector, mode, fb=None, sync=False):
 """Perform a mode set on the given connector and CRTC. The framebuffer,
@@ -268,7 +268,7 @@ class KMSTest(object):
 if sync:
 return req.commit_sync(True)
 else:
-return req.commit(self, True)
+return req.commit(0, True)
 
 def atomic_plane_set(self, plane, crtc, source, destination, fb, 
sync=False):
 req = pykms.AtomicReq(self.card)
@@ -287,7 +287,7 @@ class KMSTest(object):
 if sync:
 return req.commit_sync()
 else:
-return req.commit(self)
+return req.commit(0)
 
 def atomic_planes_disable(self, sync=True):
 req = pykms.AtomicReq(self.card)
@@ -297,7 +297,7 @@ class KMSTest(object):
 if sync:
 return req.commit_sync()
 else:
-return req.commit(self)
+return req.commit(0)
 
 def __handle_page_flip(self, frame, time):
 self.flips += 1
-- 
Regards,

Laurent Pinchart



Re: [PATCH v4.1] phylib: Add device reset GPIO support

2017-12-07 Thread Sergei Shtylyov

On 12/07/2017 08:20 PM, Sergei Shtylyov wrote:


The PHY devices sometimes do have their reset signal (maybe even power
supply?) tied to some GPIO and sometimes it also does happen that a boot
loader does not leave it deasserted. So far this issue has been attacked
from (as I believe) a wrong angle: by teaching the MAC driver to manipulate
the GPIO in question; that solution, when applied to the device trees, led
to adding the PHY reset GPIO properties to the MAC device node, with one
exception: Cadence MACB driver which could handle the "reset-gpios" prop
in a PHY device subnode. I believe that the correct approach is to teach
the 'phylib' to get the MDIO device reset GPIO from the device tree node
corresponding to this device -- which this patch is doing...

Note that I had to modify the AT803x PHY driver as it would stop working
otherwise -- it made use of the reset GPIO for its own purposes...

Signed-off-by: Sergei Shtylyov 
Acked-by: Rob Herring 
[geert: Propagate actual errors from fwnode_get_named_gpiod()]
[geert: Avoid destroying initial setup]
[geert: Consolidate GPIO descriptor acquiring code]
Signed-off-by: Geert Uytterhoeven 

[...]

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 2df7b62c1a36811e..8f8b7747c54bc478 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c

[...]

@@ -48,9 +49,26 @@
  int mdiobus_register_device(struct mdio_device *mdiodev)
  {
+struct gpio_desc *gpiod = NULL;
+
  if (mdiodev->bus->mdio_map[mdiodev->addr])
  return -EBUSY;
+/* Deassert the optional reset signal */


Umm, but why deassert it here for such a short time?


+if (mdiodev->dev.of_node)
+gpiod = fwnode_get_named_gpiod(>dev.of_node->fwnode,
+   "reset-gpios", 0, GPIOD_OUT_LOW,
+   "PHY reset");
+if (PTR_ERR(gpiod) == -ENOENT)
+gpiod = NULL;
+else if (IS_ERR(gpiod))
+return PTR_ERR(gpiod);


Hm, returning on error with reset deasserted?


   Oops, error means we couldn't drive the GPIO at all...
   The 1st question remains though...

[...]

MBR, Sergei


Re: [PATCH v4.1] phylib: Add device reset GPIO support

2017-12-07 Thread Sergei Shtylyov

Hello!

On 12/04/2017 03:35 PM, Geert Uytterhoeven wrote:


From: Sergei Shtylyov 

The PHY devices sometimes do have their reset signal (maybe even power
supply?) tied to some GPIO and sometimes it also does happen that a boot
loader does not leave it deasserted. So far this issue has been attacked
from (as I believe) a wrong angle: by teaching the MAC driver to manipulate
the GPIO in question; that solution, when applied to the device trees, led
to adding the PHY reset GPIO properties to the MAC device node, with one
exception: Cadence MACB driver which could handle the "reset-gpios" prop
in a PHY device subnode. I believe that the correct approach is to teach
the 'phylib' to get the MDIO device reset GPIO from the device tree node
corresponding to this device -- which this patch is doing...

Note that I had to modify the AT803x PHY driver as it would stop working
otherwise -- it made use of the reset GPIO for its own purposes...

Signed-off-by: Sergei Shtylyov 
Acked-by: Rob Herring 
[geert: Propagate actual errors from fwnode_get_named_gpiod()]
[geert: Avoid destroying initial setup]
[geert: Consolidate GPIO descriptor acquiring code]
Signed-off-by: Geert Uytterhoeven 

[...]

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 2df7b62c1a36811e..8f8b7747c54bc478 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c

[...]

@@ -48,9 +49,26 @@
  
  int mdiobus_register_device(struct mdio_device *mdiodev)

  {
+   struct gpio_desc *gpiod = NULL;
+
if (mdiodev->bus->mdio_map[mdiodev->addr])
return -EBUSY;
  
+	/* Deassert the optional reset signal */


   Umm, but why deassert it here for such a short time?


+   if (mdiodev->dev.of_node)
+   gpiod = fwnode_get_named_gpiod(>dev.of_node->fwnode,
+  "reset-gpios", 0, GPIOD_OUT_LOW,
+  "PHY reset");
+   if (PTR_ERR(gpiod) == -ENOENT)
+   gpiod = NULL;
+   else if (IS_ERR(gpiod))
+   return PTR_ERR(gpiod);


   Hm, returning on error with reset deasserted?


+
+   mdiodev->reset = gpiod;
+
+   /* Assert the reset signal again */
+   mdio_device_reset(mdiodev, 1);
+
mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;
  
  	return 0;

[...]

MBR, Sergei


Re: issue on rcar-du and/or vsp suspend-resume paths

2017-12-07 Thread Nikita Yushchenko

Hello Kieran.

Mayne thanks for that information.
It will save me a lot of time.

Nikita



Hello Nikita

On 07/12/17 08:48, Nikita Yushchenko wrote:

Hello.

Writing this mail to commiters to rcar-du and vsp1 drivers in kernel branch
v4.9/rcar-3.5.9 of
git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git - which
AFAIU is the latest BSP kernel for Renesas Gen3 SoCs.


Suspend resume is known not to work on this kernel version for VSP1 and rcar-du
on Gen3. You could potentially back-port the relevant patches, but I have not
looked at the dependencies required for this:


I believe the VSP1 was fixed with the following patch series:

[PATCH v5 0/2] v4l: vsp1: Fix suspend/resume and race on M2M pipelines
[PATCH v5 1/2] v4l: vsp1: Move vsp1_video_setup_pipeline()
[PATCH v5 2/2] v4l: vsp1: Repair suspend resume operations for video pipelines

And the RCar DU was fixed with the following patches:

[PATCH v2 0/3] drm/media: Implement DU Suspend and Resume on VSP pipelines
  (1/3 is v3 "media: vsp1" below)
[PATCH v2 2/3] drm: rcar-du: Add suspend resume helpers
[PATCH v2 3/3] drm: rcar-du: Remove unused CRTC suspend/resume functions

[PATCH v3] media: vsp1: Prevent suspending and resuming DRM pipelines

All of the above patches were posted to the linux-renesas-soc mailinglist, and
should be available in the archives.

The best source of the patches would be the tag:
   renesas-drivers-2017-11-28-v4.15-rc1
from
   git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git,

which should be functional for suspend/resume on both VSP1 and rcar-du.


I'm trying to make swsusp (i.e echo disk > /sys/power/state) working on
r8a7796-m3ulcb board.

I'm facing an issue with suspend/resume routines of rcar-du driver.

Currently, suspend-to-mem works on this target. I can run
# i2cset -f -y 7 0x30 0x20 0x0F
# echo mem > /sys/power/state
and target suspends. Then, I can press power button and target resumes,
including image on HDMI-connected display.

However, if I try

# echo devices > /sys/power/pm_test
# echo mem > /sys/power/state

which should terminate suspend process after calling drivers method and resume
immediately, rcar-du resume fails:

[   75.233956] [drm:drm_atomic_helper_wait_for_flip_done] *ERROR*
[CRTC:53:crtc-1] flip_done timed out
[   85.474009] [drm:drm_atomic_helper_commit_cleanup_done] *ERROR*
[CRTC:53:crtc-1] flip_done timed out


Yes, this looks like the expected errors.


Same will happen on any other variants of /sys/power/pm_test.
Resume of rcar-du will only succeed of CPU really goes sleep after suspend of
rcar-du.

I've tried a test that calls rcar-du's suspend method, sleeps a bit and calls
rcar-du's resume method - and that breaks display. In particular, VSP interrupts
no longer arrive. Although the VSP hardware programming sequence looks exactly
the same as on normal driver startup or on blank-unblank path.

For swsusp (and also for suspend-to-mem error paths) it is required that
driver's resume method undoes what driver's suspend method does, so this
behavior is definitely a bug.

Could you please help debugging this?


Backporting the patches, or moving to latest kernel versions would be the
resolution here.



Nikita Yushchenko,
system sw engineer at cogentembedded.com

--
Regards

Kieran



Applied "spi: rspi: Do not set SPCR_SPE in qspi_set_config_register()" to the spi tree

2017-12-07 Thread Mark Brown
The patch

   spi: rspi: Do not set SPCR_SPE in qspi_set_config_register()

has been applied to the spi tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From b458a3490e465b63f59b458c9b6d2284a63f Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven 
Date: Thu, 7 Dec 2017 11:09:21 +0100
Subject: [PATCH] spi: rspi: Do not set SPCR_SPE in qspi_set_config_register()

The R-Car Gen2 Hardware User Manual Rev. 2.00 states:

If the master/slave mode select bit (MSTR) is modified while the SPI
function enable bit (SPE) is set to 1 (that is, this module is
enabled), the subsequent operation cannot be guaranteed.

Hence do not set SPCR_SPE when setting SPCR_MSTR, just like the
.set_config_register() implementations for other RSPI variants do.

Note that when booted from QSPI, the boot loader will have set SPCR_MSTR
already, hence usually the bit is never modified by the Linux driver.

Reported-by: Yoshihiro Shimoda 
Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Mark Brown 
---
 drivers/spi/spi-rspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index 2ce875764ca6..0835a8d88fb8 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -377,8 +377,8 @@ static int qspi_set_config_register(struct rspi_data *rspi, 
int access_size)
/* Sets SPCMD */
rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);
 
-   /* Enables SPI function in master mode */
-   rspi_write8(rspi, SPCR_SPE | SPCR_MSTR, RSPI_SPCR);
+   /* Sets RSPI mode */
+   rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR);
 
return 0;
 }
-- 
2.15.0



Re: [PATCH 3/6] i2c: add 'set_sda' to bus_recovery_info

2017-12-07 Thread Wolfram Sang

> > Two statice inlines in 
> > named
> > 
> > int gpiod_is output()
> > int gpiod_is_input()
> > 
> > should conform to Rusty Russell's API hierarchy.
> 
> Yes, sounds good!
> 
> > Interested in fixing it, or should I?
> 
> Please do. I don't want to add magic numbers to the kernel ;)

OK?



signature.asc
Description: PGP signature


Re: [PATCH] i2c: imx: use proper GPIO directions for recovery

2017-12-07 Thread Wolfram Sang
On Mon, Dec 04, 2017 at 01:31:54PM +0100, Wolfram Sang wrote:
> When converting to GPIOD, the GPIO directions of SCL/SDA have been
> swapped. Fix it!
> 
> Fixes: ad36a27959cabb ("i2c: imx: switch to using gpiod for bus recovery 
> gpios")
> Cc: Clemens Gruber 
> Cc: Phil Reid 
> Cc: Andy Shevchenko 
> Signed-off-by: Wolfram Sang 

Applied to for-next, thanks!



signature.asc
Description: PGP signature


Re: [PATCH v5] v4l2-async: Match parent devices

2017-12-07 Thread Kieran Bingham
Hi Sakari,

On 07/12/17 07:41, Sakari Ailus wrote:
> On Wed, Dec 06, 2017 at 02:58:39PM +, Kieran Bingham wrote:
>> From: Kieran Bingham 
>>
>> Devices supporting multiple endpoints on a single device node must set
>> their subdevice fwnode to the endpoint to allow distinct comparisons.
>>
>> Adapt the match_fwnode call to compare against the provided fwnodes
>> first, but to also perform a cross reference comparison against the
>> parent fwnodes of each other.
>>
>> This allows notifiers to pass the endpoint for comparison and still
>> support existing subdevices which store their default parent device
>> node.
>>
>> Signed-off-by: Kieran Bingham 
>> Signed-off-by: Sakari Ailus 
>>
>> ---
>>
>> Hi Sakari,
>>
>> Since you signed-off on this patch - it has had to be reworked due to the
>> changes on the of_node_full_name() functionality.
>>
>> I believe it is correct now to *just* do the pointer matching, as that 
>> matches
>> the current implementation, and converting to device_nodes will be just as
>> equal as the fwnodes, as they are simply containers.
>>
>> Let me know if you are happy to maintain your SOB on this patch - and if we 
>> need
>> to work towards getting this integrated upstream, especially in light of 
>> your new
>> endpoint matching work.
> 
> I'd really want to avoid resorting to matching opportunistically --- please
> see my reply to Niklas on "[RFC 1/1] v4l: async: Use endpoint node, not
> device node, for fwnode match".

I agree here ... This patch is a workaround to support non-endpoint matching in
a transitioning world. Moving to full endpoint matching will support complex
devices and simple devices ...

If we can go straight to that - then that's fine too.
--
Kieran


Re: issue on rcar-du and/or vsp suspend-resume paths

2017-12-07 Thread Kieran Bingham
Hello Nikita

On 07/12/17 08:48, Nikita Yushchenko wrote:
> Hello.
> 
> Writing this mail to commiters to rcar-du and vsp1 drivers in kernel branch
> v4.9/rcar-3.5.9 of
> git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git - which
> AFAIU is the latest BSP kernel for Renesas Gen3 SoCs.

Suspend resume is known not to work on this kernel version for VSP1 and rcar-du
on Gen3. You could potentially back-port the relevant patches, but I have not
looked at the dependencies required for this:


I believe the VSP1 was fixed with the following patch series:

[PATCH v5 0/2] v4l: vsp1: Fix suspend/resume and race on M2M pipelines
[PATCH v5 1/2] v4l: vsp1: Move vsp1_video_setup_pipeline()
[PATCH v5 2/2] v4l: vsp1: Repair suspend resume operations for video pipelines

And the RCar DU was fixed with the following patches:

[PATCH v2 0/3] drm/media: Implement DU Suspend and Resume on VSP pipelines
 (1/3 is v3 "media: vsp1" below)
[PATCH v2 2/3] drm: rcar-du: Add suspend resume helpers
[PATCH v2 3/3] drm: rcar-du: Remove unused CRTC suspend/resume functions

[PATCH v3] media: vsp1: Prevent suspending and resuming DRM pipelines

All of the above patches were posted to the linux-renesas-soc mailinglist, and
should be available in the archives.

The best source of the patches would be the tag:
  renesas-drivers-2017-11-28-v4.15-rc1
from
  git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git,

which should be functional for suspend/resume on both VSP1 and rcar-du.

> I'm trying to make swsusp (i.e echo disk > /sys/power/state) working on
> r8a7796-m3ulcb board.
> 
> I'm facing an issue with suspend/resume routines of rcar-du driver.
> 
> Currently, suspend-to-mem works on this target. I can run
> # i2cset -f -y 7 0x30 0x20 0x0F
> # echo mem > /sys/power/state
> and target suspends. Then, I can press power button and target resumes,
> including image on HDMI-connected display.
> 
> However, if I try
> 
> # echo devices > /sys/power/pm_test
> # echo mem > /sys/power/state
> 
> which should terminate suspend process after calling drivers method and resume
> immediately, rcar-du resume fails:
> 
> [   75.233956] [drm:drm_atomic_helper_wait_for_flip_done] *ERROR*
> [CRTC:53:crtc-1] flip_done timed out
> [   85.474009] [drm:drm_atomic_helper_commit_cleanup_done] *ERROR*
> [CRTC:53:crtc-1] flip_done timed out

Yes, this looks like the expected errors.

> Same will happen on any other variants of /sys/power/pm_test.
> Resume of rcar-du will only succeed of CPU really goes sleep after suspend of
> rcar-du.
> 
> I've tried a test that calls rcar-du's suspend method, sleeps a bit and calls
> rcar-du's resume method - and that breaks display. In particular, VSP 
> interrupts
> no longer arrive. Although the VSP hardware programming sequence looks exactly
> the same as on normal driver startup or on blank-unblank path.
> 
> For swsusp (and also for suspend-to-mem error paths) it is required that
> driver's resume method undoes what driver's suspend method does, so this
> behavior is definitely a bug.
> 
> Could you please help debugging this?

Backporting the patches, or moving to latest kernel versions would be the
resolution here.


> Nikita Yushchenko,
> system sw engineer at cogentembedded.com
--
Regards

Kieran


Re: [PATCH 0/2] PCI: rcar: Misc error path fixes

2017-12-07 Thread Simon Horman
On Thu, Dec 07, 2017 at 11:15:18AM +0100, Geert Uytterhoeven wrote:
>   Hi Simon, Lorenzo, Bjorn,
> 
> This patch series fixes two issues in the error path for the R-Car PCIe
> host bridge driver.
> 
> The first issue is triggered easily by not having a PCIe card inserted,
> and may cause a crash.
> 
> Thanks!

Acked-by: Simon Horman 



Re: [PATCH] gpio: gpio-rcar: Support S2RAM

2017-12-07 Thread Simon Horman
On Thu, Dec 07, 2017 at 10:26:53AM +0100, Geert Uytterhoeven wrote:
> On Thu, Dec 7, 2017 at 10:21 AM, Geert Uytterhoeven
>  wrote:
> >>> >  struct gpio_rcar_priv {
> >>> > void __iomem *base;
> >>> > spinlock_t lock;
> >>> > @@ -41,6 +51,7 @@ struct gpio_rcar_priv {
> >>> > unsigned int irq_parent;
> >>> > bool has_both_edge_trigger;
> >>> > bool needs_clk;
> >>> > +   struct gpio_rcar_bank_info bank_info[32];
> >>>
> >>> That's 32 x 7 = 224 bytes in total.
> >>>
> >>> What about just using 7 u32s instead, one for each register to save?
> >>> That way you only need 7 x 4 = 28 bytes, and you can probably optimize
> >>> the code to just save/restore the whole register at once.
> >>
> >> So the suggestion is to use a u32 instead of struct gpio_rcar_bank_info,
> >> and for each field of struct gpio_rcar_bank_info use a bit in the u32?
> >>
> >> If so, probably one could go a step further and use a u8 as there are
> >> currently only 7 fields, thus using 32 x 1 = 32 bytes rather than
> >> 32 x 4 = 128 bytes.
> >
> > I think you misunderstood.
> > The patch has one gpio_rcar_bank_info for each GPIO.
> > Each bank has 7 bits (bools), one for each register.
> > Indexing is done through bank_info[]..
> > Saving/restoring bits requires converting from hardware register layout to
> > stored layout ("transposing a 32 x 7 matrix to a 7 x 32 matrix").
> >
> > I proposed 7 u32s, one for each register, storing the similar bits for all
> > 32 GPIOs.
> > So indexing is reversed, becoming regs[] & BIT(), which is
> > similar to how the data is stored in hardware registers.
> > Storing all bits related to a single register in a single u32 may allow to
> > save/restore all bits of the register in a single operation.
> 
> More clarification: it's the difference between "int array[7][32]" and
> "int array[32][7]".  Both store the same amount of data.
> But if the hardware uses the former organization, you want to
> save/restore using the same organization, else it requires an expensive
> transformation.

Thanks, you are correct that I misunderstood.
I understand now.

Kaneko-san, could you take a look at switching this around and posting an RFT?


[PATCH 1/2] ARM: dts: r8a7743: sort root sub-nodes alphabetically

2017-12-07 Thread Simon Horman
Sort root sub-nodes alphabetically for allow for easier maintenance
of this file.

Signed-off-by: Simon Horman 
---
 arch/arm/boot/dts/r8a7743.dtsi | 62 +-
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/arch/arm/boot/dts/r8a7743.dtsi b/arch/arm/boot/dts/r8a7743.dtsi
index c09c6672ca37..2fe852bb10cd 100644
--- a/arch/arm/boot/dts/r8a7743.dtsi
+++ b/arch/arm/boot/dts/r8a7743.dtsi
@@ -79,6 +79,37 @@
};
};
 
+   /* External CAN clock */
+   can_clk: can {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   /* This value must be overridden by the board. */
+   clock-frequency = <0>;
+   };
+
+   /* External root clock */
+   extal_clk: extal {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   /* This value must be overridden by the board. */
+   clock-frequency = <0>;
+   };
+
+   /* External PCIe clock - can be overridden by the board */
+   pcie_bus_clk: pcie_bus {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   };
+
+   /* External SCIF clock */
+   scif_clk: scif {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   /* This value must be overridden by the board. */
+   clock-frequency = <0>;
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -1230,41 +1261,10 @@
};
};
 
-   /* External root clock */
-   extal_clk: extal {
-   compatible = "fixed-clock";
-   #clock-cells = <0>;
-   /* This value must be overridden by the board. */
-   clock-frequency = <0>;
-   };
-
/* External USB clock - can be overridden by the board */
usb_extal_clk: usb_extal {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <4800>;
};
-
-   /* External CAN clock */
-   can_clk: can {
-   compatible = "fixed-clock";
-   #clock-cells = <0>;
-   /* This value must be overridden by the board. */
-   clock-frequency = <0>;
-   };
-
-   /* External PCIe clock - can be overridden by the board */
-   pcie_bus_clk: pcie_bus {
-   compatible = "fixed-clock";
-   #clock-cells = <0>;
-   clock-frequency = <0>;
-   };
-
-   /* External SCIF clock */
-   scif_clk: scif {
-   compatible = "fixed-clock";
-   #clock-cells = <0>;
-   /* This value must be overridden by the board. */
-   clock-frequency = <0>;
-   };
 };
-- 
2.11.0



[PATCH 2/2] ARM: dts: r8a7743: move timer node out of bus

2017-12-07 Thread Simon Horman
The timer node does not have any register properties and thus shouldn't be
placed on the bus.

This problem is flagged by the compiler as follows:
$ make
  DTC arch/arm/boot/dts/r8a7743-iwg20d-q7-dbcm-ca.dtb
arch/arm/boot/dts/r8a7743-iwg20d-q7.dtb: Warning (simple_bus_reg): Node 
/soc/timer missing or empty reg/ranges property
arch/arm/boot/dts/r8a7743-iwg20d-q7-dbcm-ca.dtb: Warning (simple_bus_reg): Node 
/soc/timer missing or empty reg/ranges property
  DTC arch/arm/boot/dts/r8a7743-sk-rzg1m.dtb
arch/arm/boot/dts/r8a7743-sk-rzg1m.dtb: Warning (simple_bus_reg): Node 
/soc/timer missing or empty reg/ranges property

Signed-off-by: Simon Horman 
---
 arch/arm/boot/dts/r8a7743.dtsi | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/arch/arm/boot/dts/r8a7743.dtsi b/arch/arm/boot/dts/r8a7743.dtsi
index 2fe852bb10cd..f1c77f0b5e69 100644
--- a/arch/arm/boot/dts/r8a7743.dtsi
+++ b/arch/arm/boot/dts/r8a7743.dtsi
@@ -281,18 +281,6 @@
resets = < 407>;
};
 
-   timer {
-   compatible = "arm,armv7-timer";
-   interrupts = ,
-,
-,
-;
-   };
-
cpg: clock-controller@e615 {
compatible = "renesas,r8a7743-cpg-mssr";
reg = <0 0xe615 0 0x1000>;
@@ -1261,6 +1249,22 @@
};
};
 
+   timer {
+   compatible = "arm,armv7-timer";
+   interrupts-extended = < GIC_PPI 13
+  (GIC_CPU_MASK_SIMPLE(2) |
+   IRQ_TYPE_LEVEL_LOW)>,
+ < GIC_PPI 14
+  (GIC_CPU_MASK_SIMPLE(2) |
+   IRQ_TYPE_LEVEL_LOW)>,
+ < GIC_PPI 11
+  (GIC_CPU_MASK_SIMPLE(2) |
+   IRQ_TYPE_LEVEL_LOW)>,
+ < GIC_PPI 10
+  (GIC_CPU_MASK_SIMPLE(2) |
+   IRQ_TYPE_LEVEL_LOW)>;
+   };
+
/* External USB clock - can be overridden by the board */
usb_extal_clk: usb_extal {
compatible = "fixed-clock";
-- 
2.11.0



[PATCH 0/2] ARM: dts: r8a7743: Timer node nodes out of bus

2017-12-07 Thread Simon Horman
Move the timer node, which have no reg property, out of the root node.
The nodes that have been moved do not have any register properties and thus
shouldn't be placed on the bus.

In preparation for the above sort nodes in the root node alphabetically.

Based on renesas-devel-20171207-v4.15-rc2

Simon Horman (2):
  ARM: dts: r8a7743: sort root sub-nodes alphabetically
  ARM: dts: r8a7743: move timer node out of bus

 arch/arm/boot/dts/r8a7743.dtsi | 86 ++
 1 file changed, 45 insertions(+), 41 deletions(-)

-- 
2.11.0



[PATCH 2/2] PCI: rcar: Handle rcar_pcie_parse_request_of_pci_ranges() failures

2017-12-07 Thread Geert Uytterhoeven
rcar_pcie_parse_request_of_pci_ranges() can fail and return an error
code, but this is not checked nor handled.

Fix this by adding the missing error handling.

Fixes: 5d2917d469faab72 ("PCI: rcar: Convert to DT resource parsing API")
Signed-off-by: Geert Uytterhoeven 
---
 drivers/pci/host/pcie-rcar.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 52ab3cb0a0bfe065..95ca4a1feba4b759 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -1123,7 +1123,9 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
INIT_LIST_HEAD(>resources);
 
-   rcar_pcie_parse_request_of_pci_ranges(pcie);
+   err = rcar_pcie_parse_request_of_pci_ranges(pcie);
+   if (err)
+   goto err_free_bridge;
 
err = rcar_pcie_get_resources(pcie);
if (err < 0) {
@@ -1178,6 +1180,7 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_free_resource_list:
pci_free_resource_list(>resources);
+err_free_bridge:
pci_free_host_bridge(bridge);
 
return err;
-- 
2.7.4



[PATCH 1/2] PCI: rcar: Fix use-after-free in probe error path

2017-12-07 Thread Geert Uytterhoeven
If CONFIG_DEBUG_SLAB=y, and no PCIe card is inserted, the kernel crashes
during probe on r8a7791/koelsch:

rcar-pcie fe00.pcie: PCIe link down
Unable to handle kernel paging request at virtual address 6b6b6b6b

(seeing this message requires earlycon and keep_bootcon).

Indeed, pci_free_host_bridge() frees the PCI host bridge, including the
embedded rcar_pcie object, so pci_free_resource_list() must not be
called afterwards.

To fix this, move the call to pci_free_resource_list() up, and update the
label name accordingly.

Fixes: ddd535f1ea3eb27e ("PCI: rcar: Fix memory leak when no PCIe card is 
inserted")
Signed-off-by: Geert Uytterhoeven 
---
 drivers/pci/host/pcie-rcar.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 12796eccb2befd91..52ab3cb0a0bfe065 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -1128,12 +1128,12 @@ static int rcar_pcie_probe(struct platform_device *pdev)
err = rcar_pcie_get_resources(pcie);
if (err < 0) {
dev_err(dev, "failed to request resources: %d\n", err);
-   goto err_free_bridge;
+   goto err_free_resource_list;
}
 
err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
if (err)
-   goto err_free_bridge;
+   goto err_free_resource_list;
 
pm_runtime_enable(dev);
err = pm_runtime_get_sync(dev);
@@ -1176,9 +1176,9 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 err_pm_disable:
pm_runtime_disable(dev);
 
-err_free_bridge:
-   pci_free_host_bridge(bridge);
+err_free_resource_list:
pci_free_resource_list(>resources);
+   pci_free_host_bridge(bridge);
 
return err;
 }
-- 
2.7.4



[PATCH 0/2] PCI: rcar: Misc error path fixes

2017-12-07 Thread Geert Uytterhoeven
Hi Simon, Lorenzo, Bjorn,

This patch series fixes two issues in the error path for the R-Car PCIe
host bridge driver.

The first issue is triggered easily by not having a PCIe card inserted,
and may cause a crash.

Thanks!

Geert Uytterhoeven (2):
  PCI: rcar: Fix use-after-free in probe error path
  PCI: rcar: Handle rcar_pcie_parse_request_of_pci_ranges() failures

 drivers/pci/host/pcie-rcar.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

-- 
2.7.4

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH] spi: rspi: Do not set SPCR_SPE in qspi_set_config_register()

2017-12-07 Thread Geert Uytterhoeven
The R-Car Gen2 Hardware User Manual Rev. 2.00 states:

If the master/slave mode select bit (MSTR) is modified while the SPI
function enable bit (SPE) is set to 1 (that is, this module is
enabled), the subsequent operation cannot be guaranteed.

Hence do not set SPCR_SPE when setting SPCR_MSTR, just like the
.set_config_register() implementations for other RSPI variants do.

Note that when booted from QSPI, the boot loader will have set SPCR_MSTR
already, hence usually the bit is never modified by the Linux driver.

Reported-by: Yoshihiro Shimoda 
Signed-off-by: Geert Uytterhoeven 
---
 drivers/spi/spi-rspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index c96eab723fd3fdb7..8ef05c9568ced5d7 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -377,8 +377,8 @@ static int qspi_set_config_register(struct rspi_data *rspi, 
int access_size)
/* Sets SPCMD */
rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);
 
-   /* Enables SPI function in master mode */
-   rspi_write8(rspi, SPCR_SPE | SPCR_MSTR, RSPI_SPCR);
+   /* Sets RSPI mode */
+   rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR);
 
return 0;
 }
-- 
2.7.4



Re: [PATCH v4] arm64: dts: renesas: r8a7795: Move nodes which have no reg property out of bus

2017-12-07 Thread Simon Horman
On Thu, Nov 30, 2017 at 11:25:39AM +0100, Simon Horman wrote:
> Move pmu_a5[73], timer and thermal-zones nodes from soc node to root node.
> The nodes that have been moved do not have any register properties and thus
> shouldn't be placed on the bus.
> 
> This problem is flagged by the compiler as follows:

...

> Signed-off-by: Simon Horman 
> ---
> v4
> * Use interrupts-extended rather than interrupt-parent + interrupts
>   in /pmu_* and /timer nodes as seems to be preferred.
> v3
> * Add interrupt-parent property to /pmu_* and /timer nodes as
>   it is no longer inherited from the parent node
> v2
> * Preserve alphabetical order of nodes present in root node.

I have applied this with Geert's review tag from v2.


[PATCH 3/4] arm64: dts: renesas: salvator-common: enable usb3_phy0 node

2017-12-07 Thread Yoshihiro Shimoda
This patch enables usb3_phy0 node for Salvator-X[S].

Signed-off-by: Yoshihiro Shimoda 
---
 arch/arm64/boot/dts/renesas/salvator-common.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/salvator-common.dtsi 
b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
index b9505a6..f7c8ced 100644
--- a/arch/arm64/boot/dts/renesas/salvator-common.dtsi
+++ b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
@@ -647,6 +647,10 @@
shared-pin;
 };
 
+_extal_clk {
+   clock-frequency = <5000>;
+};
+
 _phy0 {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
@@ -662,6 +666,14 @@
status = "okay";
 };
 
+_phy0 {
+   status = "okay";
+};
+
+_clk {
+   clock-frequency = <1>;
+};
+
  {
timeout-sec = <60>;
status = "okay";
-- 
1.9.1



[PATCH 2/4] arm64: dts: renesas: r8a7796: add usb3_phy node

2017-12-07 Thread Yoshihiro Shimoda
This patch adds USB3.0 PHY node for r8a7796.

Signed-off-by: Yoshihiro Shimoda 
---
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7796.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
index cc0cca7c..cee50e8 100644
--- a/arch/arm64/boot/dts/renesas/r8a7796.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
@@ -166,6 +166,19 @@
clock-frequency = <0>;
};
 
+   /* External USB clocks - can be overridden by the board */
+   usb3s0_clk: usb3s0 {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   };
+
+   usb_extal_clk: usb_extal {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -1419,6 +1432,19 @@
status = "disabled";
};
 
+   usb3_phy0: usb-phy@e65ee000 {
+   compatible = "renesas,r8a7796-usb3-phy",
+"renesas,rcar-gen3-usb3-phy";
+   reg = <0 0xe65ee000 0 0x90>;
+   clocks = < CPG_MOD 328>, <_clk>,
+<_extal_clk>;
+   clock-names = "usb3-if", "usb3s_clk", "usb_extal";
+   power-domains = < R8A7796_PD_ALWAYS_ON>;
+   resets = < 328>;
+   #phy-cells = <0>;
+   status = "disabled";
+   };
+
xhci0: usb@ee00 {
compatible = "renesas,xhci-r8a7796",
 "renesas,rcar-gen3-xhci";
-- 
1.9.1



[PATCH 4/4] arm64: dts: renesas: salvator-common: enable usb3_peri0

2017-12-07 Thread Yoshihiro Shimoda
This patch enables usb3_peri0 that uses usb3_phy0 to enable VBUS
detection for the USB3.0 peripheral.

The Salvator-X[S] has USB3.0 type-A connector and supplies VBUS
if USB3.0 host runs. So, you need a special cable for it, and
to stop the VBUS supplies from the board, after you installs
a gadget driver, you should run the following command to avoid
conflict VBUS supply:

# echo 1 > /sys/kernel/debug/ee02.usb/b_device

Signed-off-by: Yoshihiro Shimoda 
---
 arch/arm64/boot/dts/renesas/salvator-common.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/salvator-common.dtsi 
b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
index f7c8ced..8e01fb9 100644
--- a/arch/arm64/boot/dts/renesas/salvator-common.dtsi
+++ b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
@@ -666,6 +666,13 @@
status = "okay";
 };
 
+_peri0 {
+   phys = <_phy0>;
+   phy-names = "usb";
+
+   status = "okay";
+};
+
 _phy0 {
status = "okay";
 };
-- 
1.9.1



[PATCH 0/4] arm64: dts: renesas: r8a779[56] and salvator-common: add usb3_phy and enable usb3_peri0

2017-12-07 Thread Yoshihiro Shimoda
This patch set is based on the renesas.git / renesas-devel-20171205-v4.15-rc2
tag.

Yoshihiro Shimoda (4):
  arm64: dts: renesas: r8a7795: add usb3_phy node
  arm64: dts: renesas: r8a7796: add usb3_phy node
  arm64: dts: renesas: salvator-common: enable usb3_phy0 node
  arm64: dts: renesas: salvator-common: enable usb3_peri0

 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 26 
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 26 
 arch/arm64/boot/dts/renesas/salvator-common.dtsi | 19 +
 3 files changed, 71 insertions(+)

-- 
1.9.1



[PATCH 1/4] arm64: dts: renesas: r8a7795: add usb3_phy node

2017-12-07 Thread Yoshihiro Shimoda
This patch adds USB3.0 PHY node for r8a7795.

Signed-off-by: Yoshihiro Shimoda 
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 6db4f10..9710814 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -184,6 +184,19 @@
clock-frequency = <0>;
};
 
+   /* External USB clocks - can be overridden by the board */
+   usb3s0_clk: usb3s0 {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   };
+
+   usb_extal_clk: usb_extal {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   };
+
soc: soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -1643,6 +1656,19 @@
iommus = <_hc 2>;
};
 
+   usb3_phy0: usb-phy@e65ee000 {
+   compatible = "renesas,r8a7795-usb3-phy",
+"renesas,rcar-gen3-usb3-phy";
+   reg = <0 0xe65ee000 0 0x90>;
+   clocks = < CPG_MOD 328>, <_clk>,
+<_extal_clk>;
+   clock-names = "usb3-if", "usb3s_clk", "usb_extal";
+   power-domains = < R8A7795_PD_ALWAYS_ON>;
+   resets = < 328>;
+   #phy-cells = <0>;
+   status = "disabled";
+   };
+
xhci0: usb@ee00 {
compatible = "renesas,xhci-r8a7795", 
"renesas,rcar-gen3-xhci";
reg = <0 0xee00 0 0xc00>;
-- 
1.9.1



[PATCH 16/54] arm64: dts: renesas: ulcb-kf: add dr_mode property for USB2.0 channel 0

2017-12-07 Thread Simon Horman
From: Vladimir Barinov 

ULCB-KF has a USB2.0 dual-role channel (CN13).
This adds dr_mode property for USB2.0 channel 0 (EHCI/OHCI and HS-USB)
as "otg".

Signed-off-by: Vladimir Barinov 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi 
b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
index 48a2e8f48e3f..a4e715cbde87 100644
--- a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
+++ b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
@@ -29,6 +29,7 @@
 };
 
  {
+   dr_mode = "otg";
status = "okay";
 };
 
@@ -41,6 +42,7 @@
 };
 
  {
+   dr_mode = "otg";
status = "okay";
 };
 
@@ -133,6 +135,7 @@
 };
 
  {
+   dr_mode = "otg";
status = "okay";
 };
 
-- 
2.11.0



[PATCH 26/54] arm64: dts: renesas: r8a7795-es1: Point FDP1 via FCPF to IPMMU-VP0

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPF devices to allow use of FDP1 with IPMMU-VP0.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 6b4dfa42f5b2..736281335653 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -56,6 +56,7 @@
clocks = < CPG_MOD 613>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 613>;
+   iommus = <_vp0 2>;
};
 
vspi2: vsp@fe9c {
-- 
2.11.0



[PATCH 28/54] arm64: dts: renesas: r8a7795: Point VSPI via FCPVI to IPMMU-VP0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPVI devices to allow use of VSPI with
IPMMU-VP0 and IPMMU-VP1.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 4 
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 3d50627c0670..b2d2f04c5e1c 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -159,6 +159,10 @@
iommus = <_vp0 1>;
 };
 
+ {
+   iommus = <_vp0 9>;
+};
+
  {
iommus = <_vi0 10>;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 35efacd1ec21..10c7728d1b25 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -2120,6 +2120,7 @@
clocks = < CPG_MOD 611>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 611>;
+   iommus = <_vp0 8>;
};
 
vspi1: vsp@fe9b {
@@ -2139,6 +2140,7 @@
clocks = < CPG_MOD 610>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 610>;
+   iommus = <_vp1 9>;
};
 
vspd0: vsp@fea2 {
-- 
2.11.0



[PATCH 38/54] arm64: dts: renesas: r8a7795-salvator-xs: Add SoC name to file header

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Document clearly which SoC this DTS applies to, to distinguish from
Salvator-XS boards equipped with other SoCs.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a7795-salvator-xs.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-salvator-xs.dts 
b/arch/arm64/boot/dts/renesas/r8a7795-salvator-xs.dts
index 7675de5d4f2c..8b50ceb746e8 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-salvator-xs.dts
+++ b/arch/arm64/boot/dts/renesas/r8a7795-salvator-xs.dts
@@ -1,5 +1,5 @@
 /*
- * Device Tree Source for the Salvator-X 2nd version board
+ * Device Tree Source for the Salvator-X 2nd version board with R-Car H3 ES2.0
  *
  * Copyright (C) 2015-2017 Renesas Electronics Corp.
  *
-- 
2.11.0



[PATCH 22/54] arm64: dts: renesas: r8a7795: Tie Audio-DMAC to IPMMU-MP0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up r8a7795 ES2.0 Audio-DMAC nodes to the IPMMU-MP0.
Hook up r8a7795 ES1.x Audio-DMAC nodes to the IPMMU-MP1.

Signed-off-by: Magnus Damm 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 22 ++
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 16 
 2 files changed, 38 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 38b7cfb3b428..2dfe8108072c 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -127,6 +127,28 @@
renesas,ipmmu-main = <_mm 7>;
 };
 
+ {
+   iommus = <_mp1 0>, <_mp1 1>,
+  <_mp1 2>, <_mp1 3>,
+  <_mp1 4>, <_mp1 5>,
+  <_mp1 6>, <_mp1 7>,
+  <_mp1 8>, <_mp1 9>,
+  <_mp1 10>, <_mp1 11>,
+  <_mp1 12>, <_mp1 13>,
+  <_mp1 14>, <_mp1 15>;
+};
+
+ {
+   iommus = <_mp1 16>, <_mp1 17>,
+  <_mp1 18>, <_mp1 19>,
+  <_mp1 20>, <_mp1 21>,
+  <_mp1 22>, <_mp1 23>,
+  <_mp1 24>, <_mp1 25>,
+  <_mp1 26>, <_mp1 27>,
+  <_mp1 28>, <_mp1 29>,
+  <_mp1 30>, <_mp1 31>;
+};
+
  {
vsps = <   >;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index af200aa55fce..2ca746c304d5 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -724,6 +724,14 @@
resets = < 502>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_mp0 0>, <_mp0 1>,
+  <_mp0 2>, <_mp0 3>,
+  <_mp0 4>, <_mp0 5>,
+  <_mp0 6>, <_mp0 7>,
+  <_mp0 8>, <_mp0 9>,
+  <_mp0 10>, <_mp0 11>,
+  <_mp0 12>, <_mp0 13>,
+  <_mp0 14>, <_mp0 15>;
};
 
audma1: dma-controller@ec72 {
@@ -758,6 +766,14 @@
resets = < 501>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_mp0 16>, <_mp0 17>,
+  <_mp0 18>, <_mp0 19>,
+  <_mp0 20>, <_mp0 21>,
+  <_mp0 22>, <_mp0 23>,
+  <_mp0 24>, <_mp0 25>,
+  <_mp0 26>, <_mp0 27>,
+  <_mp0 28>, <_mp0 29>,
+  <_mp0 30>, <_mp0 31>;
};
 
avb: ethernet@e680 {
-- 
2.11.0



[PATCH 43/54] arm64: dts: renesas: r8a77970: sort includes

2017-12-07 Thread Simon Horman
Sort includes used in r8a77970 DTS to improve maintainability
and for consistency with other R-Car DTS files.

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 75d09f1724f0..8b97842aedb7 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -9,9 +9,9 @@
  * kind, whether express or implied.
  */
 
-#include 
-#include 
 #include 
+#include 
+#include 
 
 / {
compatible = "renesas,r8a77970";
-- 
2.11.0



[PATCH 17/54] arm64: dts: renesas: r8a77995: add SYS-DMAC nodes

2017-12-07 Thread Simon Horman
From: Ulrich Hecht 

Differs from other Gen3 SoCs in that each controller only supports eight
channels.

Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 72 +++
 1 file changed, 72 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index 788e3afae6e3..04a392a9d9de 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -155,6 +155,78 @@
resets = < 407>;
};
 
+   dmac0: dma-controller@e670 {
+   compatible = "renesas,dmac-r8a77995",
+"renesas,rcar-dmac";
+   reg = <0 0xe670 0 0x1>;
+   interrupts = ;
+   interrupt-names = "error",
+   "ch0", "ch1", "ch2", "ch3",
+   "ch4", "ch5", "ch6", "ch7";
+   clocks = < CPG_MOD 219>;
+   clock-names = "fck";
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 219>;
+   #dma-cells = <1>;
+   dma-channels = <8>;
+   };
+
+   dmac1: dma-controller@e730 {
+   compatible = "renesas,dmac-r8a77995",
+"renesas,rcar-dmac";
+   reg = <0 0xe730 0 0x1>;
+   interrupts = ;
+   interrupt-names = "error",
+   "ch0", "ch1", "ch2", "ch3",
+   "ch4", "ch5", "ch6", "ch7";
+   clocks = < CPG_MOD 218>;
+   clock-names = "fck";
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 218>;
+   #dma-cells = <1>;
+   dma-channels = <8>;
+   };
+
+   dmac2: dma-controller@e731 {
+   compatible = "renesas,dmac-r8a77995",
+"renesas,rcar-dmac";
+   reg = <0 0xe731 0 0x1>;
+   interrupts = ;
+   interrupt-names = "error",
+   "ch0", "ch1", "ch2", "ch3",
+   "ch4", "ch5", "ch6", "ch7";
+   clocks = < CPG_MOD 217>;
+   clock-names = "fck";
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 217>;
+   #dma-cells = <1>;
+   dma-channels = <8>;
+   };
+
gpio0: gpio@e605 {
compatible = "renesas,gpio-r8a77995",
 "renesas,rcar-gen3-gpio",
-- 
2.11.0



[PATCH 49/54] arm64: dts: renesas: r8a77995: Add IPMMU device nodes

2017-12-07 Thread Simon Horman
Add r8a77995 IPMMU nodes and keep all disabled by default.

Based on work for the r8a7795 and r8a7796 by Magnus Damm

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 82 +++
 1 file changed, 82 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index 21b832fb20b2..f02bf81e5a5a 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -115,6 +115,88 @@
interrupts = ;
};
 
+   ipmmu_vi0: mmu@febd {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xfebd 0 0x1000>;
+   renesas,ipmmu-main = <_mm 14>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vp0: mmu@fe99 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xfe99 0 0x1000>;
+   renesas,ipmmu-main = <_mm 16>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vc0: mmu@fe6b {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xfe6b 0 0x1000>;
+   renesas,ipmmu-main = <_mm 12>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_pv0: mmu@fd80 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xfd80 0 0x1000>;
+   renesas,ipmmu-main = <_mm 6>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_hc: mmu@e657 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xe657 0 0x1000>;
+   renesas,ipmmu-main = <_mm 2>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_rt: mmu@ffc8 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xffc8 0 0x1000>;
+   renesas,ipmmu-main = <_mm 10>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_mp: mmu@ec67 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xec67 0 0x1000>;
+   renesas,ipmmu-main = <_mm 4>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_ds0: mmu@e674 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xe674 0 0x1000>;
+   renesas,ipmmu-main = <_mm 0>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_ds1: mmu@e774 {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xe774 0 0x1000>;
+   renesas,ipmmu-main = <_mm 1>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_mm: mmu@e67b {
+   compatible = "renesas,ipmmu-r8a77995";
+   reg = <0 0xe67b 0 0x1000>;
+   interrupts = ,
+;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+
cpg: clock-controller@e615 {
compatible = "renesas,r8a77995-cpg-mssr";
reg = <0 0xe615 0 0x1000>;
-- 
2.11.0



[PATCH 25/54] arm64: dts: renesas: r8a7795: Point FDP1 via FCPF to IPMMU-VP0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPF devices to allow use of FDP1 with IPMMU-VP.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 4 
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 1eafa5382e86..6b4dfa42f5b2 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -150,6 +150,10 @@
   <_mp1 30>, <_mp1 31>;
 };
 
+ {
+   iommus = <_vp0 1>;
+};
+
  {
iommus = <_vi0 10>;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 6187e9c33e88..f7d7c98a7f73 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -2070,6 +2070,7 @@
clocks = < CPG_MOD 615>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 615>;
+   iommus = <_vp0 0>;
};
 
fcpf1: fcp@fe951000 {
@@ -2078,6 +2079,7 @@
clocks = < CPG_MOD 614>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 614>;
+   iommus = <_vp1 1>;
};
 
vspbd: vsp@fe96 {
-- 
2.11.0



[PATCH 29/54] arm64: dts: renesas: r8a7795-es1: Point VSPI via FCPVI to IPMMU-VP

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPVI devices to allow use of VSPI with IPMMU-VP.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index b2d2f04c5e1c..6713eeeab52a 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -76,6 +76,7 @@
clocks = < CPG_MOD 609>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 609>;
+   iommus = <_vp0 10>;
};
 
vspd3: vsp@fea38000 {
-- 
2.11.0



[PATCH 45/54] arm64: dts: renesas: r8a77970: Add IPMMU device nodes

2017-12-07 Thread Simon Horman
Add r8a77970 IPMMU nodes and keep all disabled by default.

Based on work for the r8a7796 by Magnus Damm

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 8b97842aedb7..5f73ee2dfd6d 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
compatible = "renesas,r8a77970";
@@ -134,6 +135,52 @@
#power-domain-cells = <1>;
};
 
+   ipmmu_vi0: mmu@febd {
+   compatible = "renesas,ipmmu-r8a77970";
+   reg = <0 0xfebd 0 0x1000>;
+   renesas,ipmmu-main = <_mm 9>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_ir: mmu@ff8b {
+   compatible = "renesas,ipmmu-r8a77970";
+   reg = <0 0xff8b 0 0x1000>;
+   renesas,ipmmu-main = <_mm 3>;
+   power-domains = < R8A77970_PD_A3IR>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_rt: mmu@ffc8 {
+   compatible = "renesas,ipmmu-r8a77970";
+   reg = <0 0xffc8 0 0x1000>;
+   renesas,ipmmu-main = <_mm 7>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_ds1: mmu@e774 {
+   compatible = "renesas,ipmmu-r8a77970";
+   reg = <0 0xe774 0 0x1000>;
+   renesas,ipmmu-main = <_mm 1>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_mm: mmu@e67b {
+   compatible = "renesas,ipmmu-r8a77970";
+   reg = <0 0xe67b 0 0x1000>;
+   interrupts = ,
+;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
intc_ex: interrupt-controller@e61c {
compatible = "renesas,intc-ex-r8a77970", "renesas,irqc";
#interrupt-cells = <2>;
-- 
2.11.0



[PATCH 10/54] arm64: dts: renesas: r8a7796: Tie Audio-DMAC to IPMMU-MP

2017-12-07 Thread Simon Horman
Hook up r8a7796 Audio-DMAC nodes to the IPMMU-MP.

Based on work for the r8a7795 by Magnus Damm.

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7796.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
index 84f38056f8e6..fd875b5ea861 100644
--- a/arch/arm64/boot/dts/renesas/r8a7796.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
@@ -1327,6 +1327,14 @@
resets = < 502>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_mp 0>, <_mp 1>,
+  <_mp 2>, <_mp 3>,
+  <_mp 4>, <_mp 5>,
+  <_mp 6>, <_mp 7>,
+  <_mp 8>, <_mp 9>,
+  <_mp 10>, <_mp 11>,
+  <_mp 12>, <_mp 13>,
+  <_mp 14>, <_mp 15>;
};
 
audma1: dma-controller@ec72 {
@@ -1361,6 +1369,14 @@
resets = < 501>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_mp 16>, <_mp 17>,
+  <_mp 18>, <_mp 19>,
+  <_mp 20>, <_mp 21>,
+  <_mp 22>, <_mp 23>,
+  <_mp 24>, <_mp 25>,
+  <_mp 26>, <_mp 27>,
+  <_mp 28>, <_mp 29>,
+  <_mp 30>, <_mp 31>;
};
 
usb_dmac0: dma-controller@e65a {
-- 
2.11.0



[PATCH 42/54] arm64: dts: renesas: r8a7795: Increase the number of GPIO bank 1 ports to 29

2017-12-07 Thread Simon Horman
From: Takeshi Kihara 

This patch changes the number of GPIO bank 1 ports to 29 because GP-1-28
port pin of R8A7795 ES2.0 SoC support was added.

Signed-off-by: Takeshi Kihara 
Fixes: 291e0c4994d0813f ("arm64: dts: r8a7795: Add support for R-Car H3 ES2.0")
[geert: Keep 28 GPIOs on H3 ES1.x after r8a7795.dtsi sharing]
Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 4 
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 29b52d89c78a..26769a11a190 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -109,6 +109,10 @@
};
 };
 
+ {
+   gpio-ranges = < 0 32 28>;
+};
+
 _vi0 {
renesas,ipmmu-main = <_mm 11>;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index a438d58f1b50..6db4f10376a1 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -240,7 +240,7 @@
interrupts = ;
#gpio-cells = <2>;
gpio-controller;
-   gpio-ranges = < 0 32 28>;
+   gpio-ranges = < 0 32 29>;
#interrupt-cells = <2>;
interrupt-controller;
clocks = < CPG_MOD 911>;
-- 
2.11.0



[PATCH 07/54] arm64: dts: renesas: Add support for Salvator-XS with R-Car M3-W

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Add initial support for the Renesas Salvator-XS (Salvator-X 2nd version)
development board equipped with an R-Car M3-W SiP.

Based on work for the Salvator-X and -XS boards with M3-W resp. H3 SiPs.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/Makefile   |  1 +
 .../arm64/boot/dts/renesas/r8a7796-salvator-xs.dts | 58 ++
 2 files changed, 59 insertions(+)
 create mode 100644 arch/arm64/boot/dts/renesas/r8a7796-salvator-xs.dts

diff --git a/arch/arm64/boot/dts/renesas/Makefile 
b/arch/arm64/boot/dts/renesas/Makefile
index 646198d82903..7f13e014d0aa 100644
--- a/arch/arm64/boot/dts/renesas/Makefile
+++ b/arch/arm64/boot/dts/renesas/Makefile
@@ -6,5 +6,6 @@ dtb-$(CONFIG_ARCH_R8A7795) += r8a7795-es1-salvator-x.dtb 
r8a7795-es1-h3ulcb.dtb
 dtb-$(CONFIG_ARCH_R8A7795) += r8a7795-es1-h3ulcb-kf.dtb
 dtb-$(CONFIG_ARCH_R8A7796) += r8a7796-salvator-x.dtb r8a7796-m3ulcb.dtb
 dtb-$(CONFIG_ARCH_R8A7796) += r8a7796-m3ulcb-kf.dtb
+dtb-$(CONFIG_ARCH_R8A7796) += r8a7796-salvator-xs.dtb
 dtb-$(CONFIG_ARCH_R8A77970) += r8a77970-eagle.dtb
 dtb-$(CONFIG_ARCH_R8A77995) += r8a77995-draak.dtb
diff --git a/arch/arm64/boot/dts/renesas/r8a7796-salvator-xs.dts 
b/arch/arm64/boot/dts/renesas/r8a7796-salvator-xs.dts
new file mode 100644
index ..2c37055efa94
--- /dev/null
+++ b/arch/arm64/boot/dts/renesas/r8a7796-salvator-xs.dts
@@ -0,0 +1,58 @@
+/*
+ * Device Tree Source for the Salvator-X 2nd version board with R-Car M3-W
+ *
+ * Copyright (C) 2015-2017 Renesas Electronics Corp.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2.  This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+/dts-v1/;
+#include "r8a7796.dtsi"
+#include "salvator-xs.dtsi"
+
+/ {
+   model = "Renesas Salvator-X 2nd version board based on r8a7796";
+   compatible = "renesas,salvator-xs", "renesas,r8a7796";
+
+   memory@4800 {
+   device_type = "memory";
+   /* first 128MB is reserved for secure area. */
+   reg = <0x0 0x4800 0x0 0x7800>;
+   };
+
+   memory@6 {
+   device_type = "memory";
+   reg = <0x6 0x 0x0 0x8000>;
+   };
+};
+
+ {
+   clocks = < CPG_MOD 724>,
+< CPG_MOD 723>,
+< CPG_MOD 722>,
+< CPG_MOD 727>,
+< 1>,
+<_clk>,
+< 2>;
+   clock-names = "du.0", "du.1", "du.2", "lvds.0",
+ "dclkin.0", "dclkin.1", "dclkin.2";
+};
+
+ {
+   status = "okay";
+
+   ports {
+   port@1 {
+   reg = <1>;
+   rcar_dw_hdmi0_out: endpoint {
+   remote-endpoint = <_con>;
+   };
+   };
+   };
+};
+
+_con {
+   remote-endpoint = <_dw_hdmi0_out>;
+};
-- 
2.11.0



[PATCH 27/54] arm64: dts: renesas: r8a7795: Point VSPBC/VSPBD via FCPVB to IPMMU-VP0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPVB devices to allow use of VSPBC/VSPBD with
IPMMU-VP0 and IPMMU-VP1.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 4 
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 736281335653..3d50627c0670 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -151,6 +151,10 @@
   <_mp1 30>, <_mp1 31>;
 };
 
+ {
+   iommus = <_vp0 7>;
+};
+
  {
iommus = <_vp0 1>;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index f7d7c98a7f73..35efacd1ec21 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -2062,6 +2062,7 @@
clocks = < CPG_MOD 606>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 606>;
+   iommus = <_vp1 7>;
};
 
fcpf0: fcp@fe95 {
@@ -2099,6 +2100,7 @@
clocks = < CPG_MOD 607>;
power-domains = < R8A7795_PD_A3VP>;
resets = < 607>;
+   iommus = <_vp0 5>;
};
 
vspi0: vsp@fe9a {
-- 
2.11.0



[PATCH 21/54] arm64: dts: renesas: r8a7795: Tie SYS-DMAC to IPMMU-DS0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up r8a7795 SYS-DMAC nodes to the IPMMUs. In particular SYS-DMAC0 gets
tied to IPMMU-DS0, and SYS-DMAC1 and SYS-DMAC2 get tied to IPMMU-DS1.

Signed-off-by: Magnus Damm 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 24 
 1 file changed, 24 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 1a091bb41b7f..af200aa55fce 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -598,6 +598,14 @@
resets = < 219>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_ds0 0>, <_ds0 1>,
+  <_ds0 2>, <_ds0 3>,
+  <_ds0 4>, <_ds0 5>,
+  <_ds0 6>, <_ds0 7>,
+  <_ds0 8>, <_ds0 9>,
+  <_ds0 10>, <_ds0 11>,
+  <_ds0 12>, <_ds0 13>,
+  <_ds0 14>, <_ds0 15>;
};
 
dmac1: dma-controller@e730 {
@@ -632,6 +640,14 @@
resets = < 218>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_ds1 0>, <_ds1 1>,
+  <_ds1 2>, <_ds1 3>,
+  <_ds1 4>, <_ds1 5>,
+  <_ds1 6>, <_ds1 7>,
+  <_ds1 8>, <_ds1 9>,
+  <_ds1 10>, <_ds1 11>,
+  <_ds1 12>, <_ds1 13>,
+  <_ds1 14>, <_ds1 15>;
};
 
dmac2: dma-controller@e731 {
@@ -666,6 +682,14 @@
resets = < 217>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_ds1 16>, <_ds1 17>,
+  <_ds1 18>, <_ds1 19>,
+  <_ds1 20>, <_ds1 21>,
+  <_ds1 22>, <_ds1 23>,
+  <_ds1 24>, <_ds1 25>,
+  <_ds1 26>, <_ds1 27>,
+  <_ds1 28>, <_ds1 29>,
+  <_ds1 30>, <_ds1 31>;
};
 
audma0: dma-controller@ec70 {
-- 
2.11.0



[PATCH 52/54] arm64: dts: renesas: v3msk: add EtherAVB support

2017-12-07 Thread Simon Horman
From: Sergei Shtylyov 

Define the V3M Starter Kit board dependent part of the EtherAVB
device node.

Based on the original (and large) patch by Vladimir Barinov.

Signed-off-by: Vladimir Barinov 
Signed-off-by: Sergei Shtylyov 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts 
b/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts
index 50f49212f54e..8624ca87d6b2 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts
+++ b/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts
@@ -31,6 +31,17 @@
};
 };
 
+ {
+   renesas,no-ether-link;
+   phy-handle = <>;
+   status = "okay";
+
+   phy0: ethernet-phy@0 {
+   rxc-skew-ps = <1500>;
+   reg = <0>;
+   };
+};
+
 _clk {
clock-frequency = <1666>;
 };
-- 
2.11.0



[PATCH 32/54] arm64: dts: renesas: r8a7795-es1: Enable IPMMU-MP1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Enable the r8a7795 ES1.x device node for IPMMU-MP1.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 6713eeeab52a..29b52d89c78a 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -31,7 +31,6 @@
reg = <0 0xec68 0 0x1000>;
renesas,ipmmu-main = <_mm 5>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_sy: mmu@e773 {
-- 
2.11.0



[PATCH 39/54] arm64: dts: renesas: r8a77995: Add CAN external clock support

2017-12-07 Thread Simon Horman
From: Ulrich Hecht 

Adds external CAN clock node for r8a77995. This clock can be used as
fCAN clock of CAN and CAN FD controller.

Based on a patch for r8a7796 by Chris Paterson.

Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index 98b70542b812..0f78592d993c 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -51,6 +51,13 @@
clock-frequency = <0>;
};
 
+   /* External CAN clock - to be overridden by boards that provide it */
+   can_clk: can {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   };
+
scif_clk: scif {
compatible = "fixed-clock";
#clock-cells = <0>;
-- 
2.11.0



[PATCH 24/54] arm64: dts: renesas: r8a7795-es1: Point DU/VSPD via FCPVD to IPMMU-VI0

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPVD devices to allow use of the VSP and DU
together with IPMMU-VI0.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 71499d193ddb..1eafa5382e86 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -94,6 +94,7 @@
clocks = < CPG_MOD 600>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
resets = < 600>;
+   iommus = <_vi0 11>;
};
 
fdp1@fe948000 {
-- 
2.11.0



[PATCH 30/54] arm64: dts: renesas: r8a7795: Connect Ethernet-AVB to IPMMU-DS0

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Add IPMMU-DS0 to the Ethernet-AVB device node.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 10c7728d1b25..f5ab1c3370e6 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -816,6 +816,7 @@
power-domains = < R8A7795_PD_ALWAYS_ON>;
resets = < 812>;
phy-mode = "rgmii-txid";
+   iommus = <_ds0 16>;
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
-- 
2.11.0



[PATCH 18/54] arm64: dts: renesas: r8a77995: Add SDHI (MMC) support

2017-12-07 Thread Simon Horman
From: Ulrich Hecht 

R-Car D3 has only one SDHI controller.

Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index 04a392a9d9de..98b70542b812 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -438,6 +438,18 @@
status = "disabled";
};
 
+   sdhi2: sd@ee14 {
+   compatible = "renesas,sdhi-r8a77995",
+"renesas,rcar-gen3-sdhi";
+   reg = <0 0xee14 0 0x2000>;
+   interrupts = ;
+   clocks = < CPG_MOD 312>;
+   max-frequency = <2>;
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 312>;
+   status = "disabled";
+   };
+
ehci0: usb@ee080100 {
compatible = "generic-ehci";
reg = <0 0xee080100 0 0x100>;
-- 
2.11.0



[PATCH 14/54] arm64: dts: renesas: r8a7796: Enable IPMMU-DS0, DS1, MP, VI0, VC0 and MM

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Enable the r8a7795 device nodes for IPMMU-DS0, IPMMU-DS1, IPMMU-MP,
IPMMU-VI0, IPMMU-VC0 and the shared IPMMU-MM device.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7796.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
index 7e5fef780786..cc0cca7c0494 100644
--- a/arch/arm64/boot/dts/renesas/r8a7796.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
@@ -363,7 +363,6 @@
renesas,ipmmu-main = <_mm 9>;
power-domains = < R8A7796_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_vc0: mmu@fe6b {
@@ -381,7 +380,6 @@
renesas,ipmmu-main = <_mm 5>;
power-domains = < R8A7796_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_pv1: mmu@fd95 {
@@ -426,7 +424,6 @@
renesas,ipmmu-main = <_mm 4>;
power-domains = < R8A7796_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_ds0: mmu@e674 {
@@ -435,7 +432,6 @@
renesas,ipmmu-main = <_mm 0>;
power-domains = < R8A7796_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_ds1: mmu@e774 {
@@ -444,7 +440,6 @@
renesas,ipmmu-main = <_mm 1>;
power-domains = < R8A7796_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_mm: mmu@e67b {
@@ -454,7 +449,6 @@
 ;
power-domains = < R8A7796_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
cpg: clock-controller@e615 {
-- 
2.11.0



[PATCH 48/54] arm64: dts: renesas: r8a77970: Enable IPMMU-DS1, RT and MM

2017-12-07 Thread Simon Horman
Enable the r8a77970 device nodes for IPMMU-DS1, IPMMU-RT
and the shared IPMMU-MM device.

Based on work for the r8a7796 by Magnus Damm.

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 0f93484e650a..636b57a2edde 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -159,7 +159,6 @@
renesas,ipmmu-main = <_mm 7>;
power-domains = < R8A77970_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_ds1: mmu@e774 {
@@ -168,7 +167,6 @@
renesas,ipmmu-main = <_mm 1>;
power-domains = < R8A77970_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_mm: mmu@e67b {
@@ -178,7 +176,6 @@
 ;
power-domains = < R8A77970_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
intc_ex: interrupt-controller@e61c {
-- 
2.11.0



[PATCH 51/54] arm64: dts: renesas: initial V3MSK board device tree

2017-12-07 Thread Simon Horman
From: Sergei Shtylyov 

Add the initial device  tree for the V3M Starter Kit board.
The board has 1 debug serial port (SCIF0); include support for it,
so that the serial console can work.

Based on the original (and large) patch by Vladimir Barinov.

Signed-off-by: Vladimir Barinov 
Signed-off-by: Sergei Shtylyov 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/Makefile   |  2 +-
 arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts | 44 ++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts

diff --git a/arch/arm64/boot/dts/renesas/Makefile 
b/arch/arm64/boot/dts/renesas/Makefile
index 7f13e014d0aa..2186d0193b73 100644
--- a/arch/arm64/boot/dts/renesas/Makefile
+++ b/arch/arm64/boot/dts/renesas/Makefile
@@ -7,5 +7,5 @@ dtb-$(CONFIG_ARCH_R8A7795) += r8a7795-es1-h3ulcb-kf.dtb
 dtb-$(CONFIG_ARCH_R8A7796) += r8a7796-salvator-x.dtb r8a7796-m3ulcb.dtb
 dtb-$(CONFIG_ARCH_R8A7796) += r8a7796-m3ulcb-kf.dtb
 dtb-$(CONFIG_ARCH_R8A7796) += r8a7796-salvator-xs.dtb
-dtb-$(CONFIG_ARCH_R8A77970) += r8a77970-eagle.dtb
+dtb-$(CONFIG_ARCH_R8A77970) += r8a77970-eagle.dtb r8a77970-v3msk.dtb
 dtb-$(CONFIG_ARCH_R8A77995) += r8a77995-draak.dtb
diff --git a/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts 
b/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts
new file mode 100644
index ..50f49212f54e
--- /dev/null
+++ b/arch/arm64/boot/dts/renesas/r8a77970-v3msk.dts
@@ -0,0 +1,44 @@
+/*
+ * Device Tree Source for the V3M Starter Kit board
+ *
+ * Copyright (C) 2017 Renesas Electronics Corp.
+ * Copyright (C) 2017 Cogent Embedded, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2.  This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+/dts-v1/;
+#include "r8a77970.dtsi"
+
+/ {
+   model = "Renesas V3M Starter Kit board";
+   compatible = "renesas,v3msk", "renesas,r8a77970";
+
+   aliases {
+   serial0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   memory@4800 {
+   device_type = "memory";
+   /* first 128MB is reserved for secure area. */
+   reg = <0x0 0x4800 0x0 0x3800>;
+   };
+};
+
+_clk {
+   clock-frequency = <1666>;
+};
+
+_clk {
+   clock-frequency = <32768>;
+};
+
+ {
+   status = "okay";
+};
-- 
2.11.0



[PATCH 20/54] arm64: dts: renesas: r8a7795-es1: Add IPMMU device nodes

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Add r8a7795 ES1.x IPMMU nodes and keep all disabled by default.

This is a follow-up to a patch that adds IPMMU device nodes that
are common to r8a7795 ES1.x and ES2.0

Power domains are omitted as they appear to be undocumented.

Signed-off-by: Magnus Damm 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 246323eacb56..38b7cfb3b428 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -26,6 +26,22 @@
/delete-node/ mmu@fd96;
/delete-node/ mmu@fd97;
 
+   ipmmu_mp1: mmu@ec68 {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xec68 0 0x1000>;
+   renesas,ipmmu-main = <_mm 5>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_sy: mmu@e773 {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xe773 0 0x1000>;
+   renesas,ipmmu-main = <_mm 8>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
/delete-node/ usb-phy@ee0e0200;
/delete-node/ usb@ee0e0100;
/delete-node/ usb@ee0e;
-- 
2.11.0



[PATCH 19/54] arm64: dts: renesas: r8a7795: Add IPMMU device nodes

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Add r8a7795 IPMMU nodes and keep all disabled by default.

This includes all IPMMU devices for r8a7795 ES2.0. Those
not present in r8a7795 ES1.x are removed from the DT for those
SoCs using delete-node. A follow-up patch will add IPMMU devices
to ES1.x which are not also present in ES2.0.

Signed-off-by: Magnus Damm 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi |  25 +
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 145 +++
 2 files changed, 170 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 655dd30639c5..246323eacb56 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -21,6 +21,11 @@
status = "disabled";
};
 
+   /delete-node/ mmu@febe;
+   /delete-node/ mmu@fe98;
+   /delete-node/ mmu@fd96;
+   /delete-node/ mmu@fd97;
+
/delete-node/ usb-phy@ee0e0200;
/delete-node/ usb@ee0e0100;
/delete-node/ usb@ee0e;
@@ -86,6 +91,26 @@
};
 };
 
+_vi0 {
+   renesas,ipmmu-main = <_mm 11>;
+};
+
+_vp0 {
+   renesas,ipmmu-main = <_mm 12>;
+};
+
+_vc0 {
+   renesas,ipmmu-main = <_mm 9>;
+};
+
+_vc1 {
+   renesas,ipmmu-main = <_mm 10>;
+};
+
+_rt {
+   renesas,ipmmu-main = <_mm 7>;
+};
+
  {
vsps = <   >;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 42c51f2ec30b..1a091bb41b7f 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -421,6 +421,151 @@
resets = < 407>;
};
 
+   ipmmu_vi0: mmu@febd {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfebd 0 0x1000>;
+   renesas,ipmmu-main = <_mm 14>;
+   power-domains = < R8A7795_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vi1: mmu@febe {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfebe 0 0x1000>;
+   renesas,ipmmu-main = <_mm 15>;
+   power-domains = < R8A7795_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vp0: mmu@fe99 {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfe99 0 0x1000>;
+   renesas,ipmmu-main = <_mm 16>;
+   power-domains = < R8A7795_PD_A3VP>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vp1: mmu@fe98 {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfe98 0 0x1000>;
+   renesas,ipmmu-main = <_mm 17>;
+   power-domains = < R8A7795_PD_A3VP>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vc0: mmu@fe6b {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfe6b 0 0x1000>;
+   renesas,ipmmu-main = <_mm 12>;
+   power-domains = < R8A7795_PD_A3VC>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_vc1: mmu@fe6f {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfe6f 0 0x1000>;
+   renesas,ipmmu-main = <_mm 13>;
+   power-domains = < R8A7795_PD_A3VC>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_pv0: mmu@fd80 {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfd80 0 0x1000>;
+   renesas,ipmmu-main = <_mm 6>;
+   power-domains = < R8A7795_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;
+   status = "disabled";
+   };
+
+   ipmmu_pv2: mmu@fd96 {
+   compatible = "renesas,ipmmu-r8a7795";
+   reg = <0 0xfd96 0 0x1000>;
+   renesas,ipmmu-main = <_mm 8>;
+   power-domains = < R8A7795_PD_ALWAYS_ON>;
+   #iommu-cells = <1>;

[PATCH 15/54] arm64: dts: renesas: ulcb-kf: enable USB2 PHY of channel 0

2017-12-07 Thread Simon Horman
From: Vladimir Barinov 

This supports USB2 PHY channel #0 on ULCB Kingfisher board

The dedicated USB0_PWEN pin is used to control CN13 VBUS source from U43
power supply.
MAX3355 can also provide VBUS, hence it should be disabled via OTG_OFFVBUSn
node coming from gpio expander TCA9539.
Set MAX3355 enabled using OTG_EXTLPn node to be able to read OTG ID of
CN13.

Signed-off-by: Vladimir Barinov 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi 
b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
index 657ad1041965..48a2e8f48e3f 100644
--- a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
+++ b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
@@ -67,6 +67,20 @@
output-high;
line-name = "HUB rst";
};
+
+   otg_offvbusn {
+   gpio-hog;
+   gpios = <8 GPIO_ACTIVE_HIGH>;
+   output-low;
+   line-name = "OTG OFFVBUSn";
+   };
+
+   otg_extlpn {
+   gpio-hog;
+   gpios = <9 GPIO_ACTIVE_HIGH>;
+   output-high;
+   line-name = "OTG EXTLPn";
+   };
};
 
gpio_exp_75: gpio@75 {
@@ -154,6 +168,11 @@
groups = "scif1_data_b", "scif1_ctrl";
function = "scif1";
};
+
+   usb0_pins: usb0 {
+   groups = "usb0";
+   function = "usb0";
+   };
 };
 
  {
@@ -164,6 +183,13 @@
status = "okay";
 };
 
+_phy0 {
+   pinctrl-0 = <_pins>;
+   pinctrl-names = "default";
+
+   status = "okay";
+};
+
  {
status = "okay";
 };
-- 
2.11.0



[PATCH 34/54] arm64: dts: renesas: salvator-common: Add BD9571 PMIC

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Add a device node for the ROHM BD9571MWV PMIC.

This was based on the example in the DT binding documentation, but using
IRQ0 instead of a GPIO interrupt, as that matches the schematics, and
because INTC-EX is a simpler block.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/salvator-common.dtsi | 29 
 1 file changed, 29 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/salvator-common.dtsi 
b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
index 24a32c63ce7c..b9505a65a793 100644
--- a/arch/arm64/boot/dts/renesas/salvator-common.dtsi
+++ b/arch/arm64/boot/dts/renesas/salvator-common.dtsi
@@ -355,6 +355,30 @@
 
 _dvfs {
status = "okay";
+
+   pmic: pmic@30 {
+   pinctrl-0 = <_pins>;
+   pinctrl-names = "default";
+
+   compatible = "rohm,bd9571mwv";
+   reg = <0x30>;
+   interrupt-parent = <_ex>;
+   interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   gpio-controller;
+   #gpio-cells = <2>;
+
+   regulators {
+   dvfs: dvfs {
+   regulator-name = "dvfs";
+   regulator-min-microvolt = <75>;
+   regulator-max-microvolt = <103>;
+   regulator-boot-on;
+   regulator-always-on;
+   };
+   };
+   };
 };
 
  {
@@ -410,6 +434,11 @@
function = "i2c2";
};
 
+   irq0_pins: irq0 {
+   groups = "intc_ex_irq0";
+   function = "intc_ex";
+   };
+
pwm1_pins: pwm1 {
groups = "pwm1_a";
function = "pwm1";
-- 
2.11.0



[PATCH 23/54] arm64: dts: renesas: r8a7795: Point DU/VSPD via FCPVD to IPMMU-VI0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up the FCPVD devices to allow use of the VSP and DU
together with IPMMU-VI1 and IPMMU-VI1.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi | 4 
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
index 2dfe8108072c..71499d193ddb 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1.dtsi
@@ -149,6 +149,10 @@
   <_mp1 30>, <_mp1 31>;
 };
 
+ {
+   iommus = <_vi0 10>;
+};
+
  {
vsps = <   >;
 };
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 2ca746c304d5..6187e9c33e88 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -2154,6 +2154,7 @@
clocks = < CPG_MOD 603>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
resets = < 603>;
+   iommus = <_vi0 8>;
};
 
vspd1: vsp@fea28000 {
@@ -2173,6 +2174,7 @@
clocks = < CPG_MOD 602>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
resets = < 602>;
+   iommus = <_vi0 9>;
};
 
vspd2: vsp@fea3 {
@@ -2192,6 +2194,7 @@
clocks = < CPG_MOD 601>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
resets = < 601>;
+   iommus = <_vi1 10>;
};
 
fdp1@fe94 {
-- 
2.11.0



[PATCH 41/54] arm64: dts: renesas: r8a77995: Add CAN FD support

2017-12-07 Thread Simon Horman
From: Ulrich Hecht 

Adds CAN FD controller node for r8a77995.

Based on a patch for r8a7796 by Chris Paterson.

Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 25 +
 1 file changed, 25 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index b2c8db15db53..73149c73ef87 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -378,6 +378,31 @@
status = "disabled";
};
 
+   canfd: can@e66c {
+   compatible = "renesas,r8a77995-canfd",
+"renesas,rcar-gen3-canfd";
+   reg = <0 0xe66c 0 0x8000>;
+   interrupts = ,
+  ;
+   clocks = < CPG_MOD 914>,
+  < CPG_CORE R8A77995_CLK_CANFD>,
+  <_clk>;
+   clock-names = "fck", "canfd", "can_clk";
+   assigned-clocks = < CPG_CORE R8A77995_CLK_CANFD>;
+   assigned-clock-rates = <4000>;
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 914>;
+   status = "disabled";
+
+   channel0 {
+   status = "disabled";
+   };
+
+   channel1 {
+   status = "disabled";
+   };
+   };
+
avb: ethernet@e680 {
compatible = "renesas,etheravb-r8a77995",
 "renesas,etheravb-rcar-gen3";
-- 
2.11.0



[PATCH 35/54] arm64: dts: renesas: r8a7795-es1-salvator-x: Add SoC name to file header

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Document clearly which SoC this DTS applies to, to distinguish from
Salvator-X boards equipped with other SoCs.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a7795-es1-salvator-x.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-es1-salvator-x.dts 
b/arch/arm64/boot/dts/renesas/r8a7795-es1-salvator-x.dts
index 3f7d5f51e428..7f2a3d923f21 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-es1-salvator-x.dts
+++ b/arch/arm64/boot/dts/renesas/r8a7795-es1-salvator-x.dts
@@ -1,5 +1,5 @@
 /*
- * Device Tree Source for the Salvator-X board
+ * Device Tree Source for the Salvator-X board with R-Car H3 ES1.x
  *
  * Copyright (C) 2015 Renesas Electronics Corp.
  *
-- 
2.11.0



[PATCH 47/54] arm64: dts: renesas: r8a77970: Connect Ethernet-AVB to IPMMU-RT

2017-12-07 Thread Simon Horman
Add IPMMU-RT to the Ethernet-AVB device node.

Based on work by Magnus Damm for the r8a7795.

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 108c6159c847..0f93484e650a 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -440,6 +440,7 @@
power-domains = < 32>;
resets = < 812>;
phy-mode = "rgmii-id";
+   iommus = <_rt 3>;
#address-cells = <1>;
#size-cells = <0>;
};
-- 
2.11.0



[PATCH 33/54] arm64: dts: renesas: r8a7795: Enable IPMMU-VI0, VP1, DS0, DS1 and MM

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Enable the r8a7795 device nodes for IPMMU-VI0, IPMMU-VP1, IPMMU-DS0,
IPMMU-DS1 and the shared IPMMU-MM device.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 5 -
 1 file changed, 5 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 08c125cfa5d6..a438d58f1b50 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -427,7 +427,6 @@
renesas,ipmmu-main = <_mm 14>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_vi1: mmu@febe {
@@ -454,7 +453,6 @@
renesas,ipmmu-main = <_mm 17>;
power-domains = < R8A7795_PD_A3VP>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_vc0: mmu@fe6b {
@@ -544,7 +542,6 @@
renesas,ipmmu-main = <_mm 0>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_ds1: mmu@e774 {
@@ -553,7 +550,6 @@
renesas,ipmmu-main = <_mm 1>;
power-domains = < R8A7795_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
ipmmu_mm: mmu@e67b {
@@ -563,7 +559,6 @@
 ;
power-domains = < R8A7795_PD_ALWAYS_ON>;
#iommu-cells = <1>;
-   status = "disabled";
};
 
dmac0: dma-controller@e670 {
-- 
2.11.0



[PATCH 44/54] arm64: dts: renesas: r8a77995: add DMA for SCIF2

2017-12-07 Thread Simon Horman
From: Ulrich Hecht 

Tested on Draak.

Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index 73149c73ef87..21b832fb20b2 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -457,6 +457,9 @@
 < CPG_CORE R8A77995_CLK_S3D1C>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
+   dmas = < 0x13>, < 0x12>,
+  < 0x13>, < 0x12>;
+   dma-names = "tx", "rx", "tx", "rx";
power-domains = < R8A77995_PD_ALWAYS_ON>;
resets = < 310>;
status = "disabled";
-- 
2.11.0



[PATCH 53/54] arm64: dts: renesas: r8a77970: use CPG core clock macros

2017-12-07 Thread Simon Horman
From: Sergei Shtylyov 

Now that the commit ecadea00f588 ("dt-bindings: clock: Add R8A77970 CPG
core clock definitions") has hit Linus' tree, we  can replace the bare
numbers (we had to use to avoid a cross tree dependency) with these macro
definitions...

Signed-off-by: Sergei Shtylyov 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 636b57a2edde..7bb224595c95 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -9,7 +9,7 @@
  * kind, whether express or implied.
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -32,7 +32,7 @@
device_type = "cpu";
compatible = "arm,cortex-a53", "arm,armv8";
reg = <0>;
-   clocks = < CPG_CORE 0>;
+   clocks = < CPG_CORE R8A77970_CLK_Z2>;
power-domains = < 5>;
next-level-cache = <_CA53>;
enable-method = "psci";
@@ -262,7 +262,7 @@
reg = <0 0xe654 0 96>;
interrupts = ;
clocks = < CPG_MOD 520>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x31>, < 0x30>,
@@ -280,7 +280,7 @@
reg = <0 0xe655 0 96>;
interrupts = ;
clocks = < CPG_MOD 519>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x33>, < 0x32>,
@@ -298,7 +298,7 @@
reg = <0 0xe656 0 96>;
interrupts = ;
clocks = < CPG_MOD 518>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x35>, < 0x34>,
@@ -315,7 +315,7 @@
reg = <0 0xe66a 0 96>;
interrupts = ;
clocks = < CPG_MOD 517>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x37>, < 0x36>,
@@ -333,7 +333,7 @@
reg = <0 0xe6e6 0 64>;
interrupts = ;
clocks = < CPG_MOD 207>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x51>, < 0x50>,
@@ -351,7 +351,7 @@
reg = <0 0xe6e68000 0 64>;
interrupts = ;
clocks = < CPG_MOD 206>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x53>, < 0x52>,
@@ -369,7 +369,7 @@
reg = <0 0xe6c5 0 64>;
interrupts = ;
clocks = < CPG_MOD 204>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x57>, < 0x56>,
@@ -386,7 +386,7 @@
reg = <0 0xe6c4 0 64>;
interrupts = ;
clocks = < CPG_MOD 203>,
-< CPG_CORE 9>,
+< CPG_CORE R8A77970_CLK_S2D1>,
 <_clk>;
clock-names = "fck", "brg_int", "scif_clk";
dmas = < 0x59>, < 0x58>,
-- 
2.11.0



[PATCH 36/54] arm64: dts: renesas: r8a7795-salvator-x: Add SoC name to file header

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Document clearly which SoC this DTS applies to, to distinguish from
Salvator-X boards equipped with other SoCs.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts 
b/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts
index 17953070f38d..af467419266a 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts
+++ b/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts
@@ -1,5 +1,5 @@
 /*
- * Device Tree Source for the Salvator-X board
+ * Device Tree Source for the Salvator-X board with R-Car H3 ES2.0
  *
  * Copyright (C) 2015 Renesas Electronics Corp.
  *
-- 
2.11.0



[PATCH 31/54] arm64: dts: renesas: r8a7795: Connect SATA to IPMMU-HC

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Add IPMMU-HC to the SATA device node.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index f5ab1c3370e6..08c125cfa5d6 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -1645,6 +1645,7 @@
power-domains = < R8A7795_PD_ALWAYS_ON>;
resets = < 815>;
status = "disabled";
+   iommus = <_hc 2>;
};
 
xhci0: usb@ee00 {
-- 
2.11.0



[PATCH 54/54] arm64: dts: renesas: r8a77970: use SYSC power domain macros

2017-12-07 Thread Simon Horman
From: Sergei Shtylyov 

Now that the commit 833bdb47c826 ("dt-bindings: power: add R8A77970 SYSC
power domain definitions") has hit Linus' tree, we can replace the  bare
numbers  (we had to use to avoid a cross tree dependency) with these macro
definitions...

Signed-off-by: Sergei Shtylyov 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 32 +++
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 7bb224595c95..c35a117fc447 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -33,14 +33,14 @@
compatible = "arm,cortex-a53", "arm,armv8";
reg = <0>;
clocks = < CPG_CORE R8A77970_CLK_Z2>;
-   power-domains = < 5>;
+   power-domains = < R8A77970_PD_CA53_CPU0>;
next-level-cache = <_CA53>;
enable-method = "psci";
};
 
L2_CA53: cache-controller {
compatible = "cache";
-   power-domains = < 21>;
+   power-domains = < R8A77970_PD_CA53_SCU>;
cache-unified;
cache-level = <2>;
};
@@ -88,7 +88,7 @@
  IRQ_TYPE_LEVEL_HIGH)>;
clocks = < CPG_MOD 408>;
clock-names = "clk";
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 408>;
};
 
@@ -109,7 +109,7 @@
 "renesas,rcar-gen3-wdt";
reg = <0 0xe602 0 0x0c>;
clocks = < CPG_MOD 402>;
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 402>;
status = "disabled";
};
@@ -190,7 +190,7 @@
  GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH
  GIC_SPI 161 IRQ_TYPE_LEVEL_HIGH>;
clocks = < CPG_MOD 407>;
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 407>;
};
 
@@ -217,7 +217,7 @@
  "ch4", "ch5", "ch6", "ch7";
clocks = < CPG_MOD 218>;
clock-names = "fck";
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 218>;
#dma-cells = <1>;
dma-channels = <8>;
@@ -245,7 +245,7 @@
  "ch4", "ch5", "ch6", "ch7";
clocks = < CPG_MOD 217>;
clock-names = "fck";
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 217>;
#dma-cells = <1>;
dma-channels = <8>;
@@ -268,7 +268,7 @@
dmas = < 0x31>, < 0x30>,
   < 0x31>, < 0x30>;
dma-names = "tx", "rx", "tx", "rx";
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 520>;
status = "disabled";
};
@@ -286,7 +286,7 @@
dmas = < 0x33>, < 0x32>,
   < 0x33>, < 0x32>;
dma-names = "tx", "rx", "tx", "rx";
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 519>;
status = "disabled";
};
@@ -304,7 +304,7 @@
dmas = < 0x35>, < 0x34>,
   < 0x35>, < 0x34>;
dma-names = "tx", "rx", "tx", "rx";
-   power-domains = < 32>;
+   power-domains = < R8A77970_PD_ALWAYS_ON>;
resets = < 518>;
status = "disabled";
};
@@ -321,7 +321,7 @@
dmas = < 0x37>, < 0x36>,
   < 0x37>, < 0x36>;
dma-names = "tx", "rx", "tx", "rx";
-   power-domains = < 32>;
+   

[PATCH 37/54] arm64: dts: renesas: r8a7796-salvator-x: Add SoC name to file header

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Document clearly which SoC this DTS applies to, to distinguish from
Salvator-X boards equipped with other SoCs.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a7796-salvator-x.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7796-salvator-x.dts 
b/arch/arm64/boot/dts/renesas/r8a7796-salvator-x.dts
index b317be03306e..498c9e807dc4 100644
--- a/arch/arm64/boot/dts/renesas/r8a7796-salvator-x.dts
+++ b/arch/arm64/boot/dts/renesas/r8a7796-salvator-x.dts
@@ -1,5 +1,5 @@
 /*
- * Device Tree Source for the Salvator-X board
+ * Device Tree Source for the Salvator-X board with R-Car M3-W
  *
  * Copyright (C) 2016 Renesas Electronics Corp.
  *
-- 
2.11.0



[PATCH 09/54] arm64: dts: renesas: r8a7796: Tie SYS-DMAC to IPMMU-DS0/1

2017-12-07 Thread Simon Horman
From: Magnus Damm 

Hook up r8a7796 DMAC nodes to the IPMMUs. In particular SYS-DMAC0
gets tied to IPMMU-DS0, and SYS-DMAC1 and SYS-DMAC2 get tied to IPMMU-DS1.

Signed-off-by: Magnus Damm 
Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 24 
 1 file changed, 24 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7796.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
index 9e7604108215..84f38056f8e6 100644
--- a/arch/arm64/boot/dts/renesas/r8a7796.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7796.dtsi
@@ -1201,6 +1201,14 @@
resets = < 219>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_ds0 0>, <_ds0 1>,
+  <_ds0 2>, <_ds0 3>,
+  <_ds0 4>, <_ds0 5>,
+  <_ds0 6>, <_ds0 7>,
+  <_ds0 8>, <_ds0 9>,
+  <_ds0 10>, <_ds0 11>,
+  <_ds0 12>, <_ds0 13>,
+  <_ds0 14>, <_ds0 15>;
};
 
dmac1: dma-controller@e730 {
@@ -1235,6 +1243,14 @@
resets = < 218>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_ds1 0>, <_ds1 1>,
+  <_ds1 2>, <_ds1 3>,
+  <_ds1 4>, <_ds1 5>,
+  <_ds1 6>, <_ds1 7>,
+  <_ds1 8>, <_ds1 9>,
+  <_ds1 10>, <_ds1 11>,
+  <_ds1 12>, <_ds1 13>,
+  <_ds1 14>, <_ds1 15>;
};
 
dmac2: dma-controller@e731 {
@@ -1269,6 +1285,14 @@
resets = < 217>;
#dma-cells = <1>;
dma-channels = <16>;
+   iommus = <_ds1 16>, <_ds1 17>,
+  <_ds1 18>, <_ds1 19>,
+  <_ds1 20>, <_ds1 21>,
+  <_ds1 22>, <_ds1 23>,
+  <_ds1 24>, <_ds1 25>,
+  <_ds1 26>, <_ds1 27>,
+  <_ds1 28>, <_ds1 29>,
+  <_ds1 30>, <_ds1 31>;
};
 
audma0: dma-controller@ec70 {
-- 
2.11.0



[PATCH 50/54] arm64: dts: renesas: r8a77995: Connect Ethernet-AVB to IPMMU-RT

2017-12-07 Thread Simon Horman
Add IPMMU-RT to the Ethernet-AVB device node.

Based on work by Magnus Damm for the r8a7795.

Signed-off-by: Simon Horman 
Reviewed-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index f02bf81e5a5a..cff42cd1a6c8 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -525,6 +525,7 @@
power-domains = < R8A77995_PD_ALWAYS_ON>;
resets = < 812>;
phy-mode = "rgmii-txid";
+   iommus = <_ds0 16>;
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
-- 
2.11.0



[PATCH 40/54] arm64: dts: renesas: r8a77995: Add CAN support

2017-12-07 Thread Simon Horman
From: Ulrich Hecht 

Adds CAN controller nodes for r8a77995.

Based on a patch for r8a7796 by Chris Paterson.

Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77995.dtsi | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77995.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
index 0f78592d993c..b2c8db15db53 100644
--- a/arch/arm64/boot/dts/renesas/r8a77995.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77995.dtsi
@@ -346,6 +346,38 @@
resets = < 906>;
};
 
+   can0: can@e6c3 {
+   compatible = "renesas,can-r8a77995",
+"renesas,rcar-gen3-can";
+   reg = <0 0xe6c3 0 0x1000>;
+   interrupts = ;
+   clocks = < CPG_MOD 916>,
+  < CPG_CORE R8A77995_CLK_CANFD>,
+  <_clk>;
+   clock-names = "clkp1", "clkp2", "can_clk";
+   assigned-clocks = < CPG_CORE R8A77995_CLK_CANFD>;
+   assigned-clock-rates = <4000>;
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 916>;
+   status = "disabled";
+   };
+
+   can1: can@e6c38000 {
+   compatible = "renesas,can-r8a77995",
+"renesas,rcar-gen3-can";
+   reg = <0 0xe6c38000 0 0x1000>;
+   interrupts = ;
+   clocks = < CPG_MOD 915>,
+  < CPG_CORE R8A77995_CLK_CANFD>,
+  <_clk>;
+   clock-names = "clkp1", "clkp2", "can_clk";
+   assigned-clocks = < CPG_CORE R8A77995_CLK_CANFD>;
+   assigned-clock-rates = <4000>;
+   power-domains = < R8A77995_PD_ALWAYS_ON>;
+   resets = < 915>;
+   status = "disabled";
+   };
+
avb: ethernet@e680 {
compatible = "renesas,etheravb-r8a77995",
 "renesas,etheravb-rcar-gen3";
-- 
2.11.0



[PATCH 04/54] arm64: dts: renesas: r8a77970: Add RWDT node

2017-12-07 Thread Simon Horman
From: Geert Uytterhoeven 

Add a device node for the Watchdog Timer (WDT) controller on the
Renesas R-Car V3M (r8a77970) SoC.

Signed-off-by: Geert Uytterhoeven 
Signed-off-by: Simon Horman 
---
 arch/arm64/boot/dts/renesas/r8a77970.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970.dtsi 
b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
index 97e6981938e7..75d09f1724f0 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a77970.dtsi
@@ -103,6 +103,16 @@
  IRQ_TYPE_LEVEL_LOW)>;
};
 
+   rwdt: watchdog@e602 {
+   compatible = "renesas,r8a77970-wdt",
+"renesas,rcar-gen3-wdt";
+   reg = <0 0xe602 0 0x0c>;
+   clocks = < CPG_MOD 402>;
+   power-domains = < 32>;
+   resets = < 402>;
+   status = "disabled";
+   };
+
cpg: clock-controller@e615 {
compatible = "renesas,r8a77970-cpg-mssr";
reg = <0 0xe615 0 0x1000>;
-- 
2.11.0



  1   2   >