[PATCH v6 03/25] rcar-vin: move chip information to own struct

2017-08-22 Thread Niklas Söderlund
When Gen3 support is added to the driver more then chip id will be
different for the different Soc. To avoid a lot of if statements in the
code create a struct chip_info to contain this information.

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

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index aefbe8e3ccddb3e4..dae38de706b66b64 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -277,14 +277,47 @@ 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-r8a7794",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7793",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7791",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7790",
+   .data = _info_gen2,
+   },
+   {
+   .compatible = "renesas,vin-r8a7779",
+   .data = _info_h1,
+   },
+   {
+   .compatible = "renesas,vin-r8a7778",
+   .data = _info_m1,
+   },
+   {
+   .compatible = "renesas,rcar-gen2-vin",
+   .data = _info_gen2,
+   },
{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
@@ -305,7 +338,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
return -ENODEV;
 
vin->dev = >dev;
-   vin->chip = (enum chip_id)match->data;
+   vin->info = match->data;
 
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 81ff59c3b4744075..02a08cf5acfce1ce 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 9d0d4a5001b6ccd8..13466dfd72292fc0 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
  *
  * @vdev:  V4L2 video device associated with VIN
  * @v4l2_dev:  V4L2 device
@@ -120,7 +128,7 @@ struct rvin_graph_entity {
 struct rvin_dev {
struct device *dev;
void __iomem *base;
-   enum chip_id chip;
+   const struct rvin_info *info;
 
struct video_device vdev;
struct v4l2_device v4l2_dev;
-- 
2.14.0



[PATCH v6 08/25] rcar-vin: do not reset crop and compose when setting format

2017-08-22 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 
---
 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 affdc128a75e502e..421820caf275b066 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;
-}
-
 int rvin_reset_format(struct rvin_dev *vin)
 {
struct v4l2_subdev_format fmt = {
@@ -147,7 +136,13 @@ 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.14.0



[PATCH v6 25/25] rcar-vin: enable support for r8a7796

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

Signed-off-by: Niklas Söderlund 
---
 .../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 be38ad89d71ad05d..767358f39512aa17 100644
--- a/Documentation/devicetree/bindings/media/rcar_vin.txt
+++ b/Documentation/devicetree/bindings/media/rcar_vin.txt
@@ -10,6 +10,7 @@ always slaves and support multiple input channels which can 
be either RGB,
 YUVU, BT656 or CSI-2.
 
  - compatible: Must be one or more of the following
+   - "renesas,vin-r8a7796" for the R8A7796 device
- "renesas,vin-r8a7795" for the R8A7795 device
- "renesas,vin-r8a7794" for the R8A7794 device
- "renesas,vin-r8a7793" for the R8A7793 device
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 58d903ab9fb83faf..e01edd5f5925d26c 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -1116,7 +1116,71 @@ 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-r8a7796",
+   .data = _info_r8a7796,
+   },
{
.compatible = "renesas,vin-r8a7795",
.data = _info_r8a7795,
-- 
2.14.0



[PATCH v6 24/25] rcar-vin: enable support for r8a7795

2017-08-22 Thread Niklas Söderlund
Add the SoC specific information for Renesas r8a7795.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/Kconfig |   2 +-
 drivers/media/platform/rcar-vin/rcar-core.c | 145 
 2 files changed, 146 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 dec91e2f3ccdbd93..58d903ab9fb83faf 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 
 
@@ -987,7 +988,139 @@ 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, .chan = 1 },
+   { .csi = RVIN_CSI21, .chan = 1 },
+

[PATCH v6 17/25] rcar-vin: use different v4l2 operations in media controller mode

2017-08-22 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 
---
 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 6206fab7b6cdc55a..de1486ee2786b499 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 f71dea8d5d40323a..9d540644bbe446f6 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,
+};
+
 /* 
-
  * File 

[PATCH v6 19/25] rcar-vin: add group allocator functions

2017-08-22 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 a 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 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 179 +++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  38 ++
 2 files changed, 216 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index dd0525f2ba336bc2..4218a73eb6885486 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -20,11 +20,170 @@
 #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, "%s: No renesas,id property found\n",
+   of_node_full_name(np));
+   return -EINVAL;
+   }
+
+   if (val >= RCAR_VIN_NUM) {
+   vin_err(vin, "%s: Invalid renesas,id '%u'\n",
+   of_node_full_name(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 its 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));
+   strlcpy(mdev->bus_info, of_node_full_name(vin->dev->of_node),
+   sizeof(mdev->bus_info));
+   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 

[PATCH v6 04/25] rcar-vin: move max width and height information to chip information

2017-08-22 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 
---
 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 dae38de706b66b64..4dc148e7835439ab 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -279,14 +279,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 02a08cf5acfce1ce..3c4dd08261a0d3f5 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 13466dfd72292fc0..2d8b362012ea46a3 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.14.0



[PATCH v6 09/25] rcar-vin: do not allow changing scaling and composing while streaming

2017-08-22 Thread Niklas Söderlund
It is possible on Gen2 to change the registers controlling composing and
scaling while the stream is running. Is however not a good idea to do so
and could result in trouble. There are also no good reason 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 
---
 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 5f9674dc898305ba..6cc880e5ef7e0718 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 421820caf275b066..305a74d033b2d9c5 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 b2bac06c0a3cfcb7..fc70ded462ed3244 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -176,7 +176,4 @@ int rvin_reset_format(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.14.0



[PATCH v6 06/25] rcar-vin: move functions regarding scaling

2017-08-22 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 
---
 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 b136844499f677cf..03a79de197d19e43 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 output use the same colorspace, use bypass mode */
-   

[PATCH v6 15/25] rcar-vin: add flag to switch to media controller mode

2017-08-22 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_graph_entity which will control which mode to use.

Signed-off-by: Niklas Söderlund 
---
 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 65f01b6781c0aefd..fbbb22924cf3a045 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -279,18 +279,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,
 };
@@ -387,7 +390,8 @@ static int rcar_vin_remove(struct platform_device *pdev)
v4l2_async_notifier_unregister(>notifier);
 
/* Checks internaly if handlers have been init or not */
-   v4l2_ctrl_handler_free(>ctrl_handler);
+   if (!vin->info->use_mc)
+   v4l2_ctrl_handler_free(>ctrl_handler);
 
rvin_v4l2_remove(vin);
 
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 94c606f2b8f2f246..819d9c04ed8ffb36 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.14.0



[PATCH v6 16/25] rcar-vin: break out format alignment and checking

2017-08-22 Thread Niklas Söderlund
Part of the format aliment and checking can be shared with the Gen3
format handling. Break that part out to it's own function. While doing
this clean up the checking and add more checks.

Signed-off-by: Niklas Söderlund 
---
 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 fb9f802e553e9b80..f71dea8d5d40323a 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 resonable, 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, pix->sizeimage);
-
-   return 0;
+   return 

[PATCH v6 21/25] rcar-vin: parse Gen3 OF and setup media graph

2017-08-22 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 subdevice is 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 fist 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 creates the
media controller links between all entities in the graph.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 296 +++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |   7 +-
 2 files changed, 301 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 4218a73eb6885486..2aba442a0750e91a 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -440,10 +440,268 @@ 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, chsel, csi;
+   u32 flags;
int ret;
 
+   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;
+
+   chsel = rvin_get_chsel(master);
+
+   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;
+   flags = i == chsel ? MEDIA_LNK_FL_ENABLED : 0;
+
+   ret = rvin_group_add_link(vin, source, idx, sink, 0,
+ flags);
+   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);
+   int ret;
+
+   ret = v4l2_device_register_subdev_nodes(>v4l2_dev);
+   if (ret) {
+   vin_err(vin, "Failed to register subdev nodes\n");
+   return ret;
+   }
+
+   return rvin_group_update_links(vin);
+}
+
+static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier,
+struct v4l2_subdev *subdev,
+struct v4l2_async_subdev *asd)
+{
+   struct rvin_dev *vin = notifier_to_vin(notifier);
+   struct rvin_graph_entity *csi = to_rvin_graph_entity(asd);
+
+   mutex_lock(>group->lock);
+   csi->subdev = NULL;
+   mutex_unlock(>group->lock);
+}
+

[PATCH v6 10/25] rcar-vin: read subdevice format for crop only when needed

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

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

Signed-off-by: Niklas Söderlund 
---
 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 305a74d033b2d9c5..c8c764188b85a926 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
  */
 
-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;
+}
+
+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 @@ 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 @@ 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,
  struct v4l2_format *f)
 {
struct rvin_dev *vin = 

[PATCH v6 20/25] rcar-vin: add chsel information to rvin_info

2017-08-22 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 
---
 drivers/media/platform/rcar-vin/rcar-vin.h | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h 
b/drivers/media/platform/rcar-vin/rcar-vin.h
index 88683aaee3b6acd5..617f254b52fe106d 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,19 @@ struct rvin_graph_entity {
 
 struct rvin_group;
 
+
+/** struct rvin_group_chsel - Map a CSI2 device and channel for a CHSEL value
+ * @csi:   VIN internal number for CSI2 device
+ * @chan:  CSI-2 channel number on remote. Note that channel
+ * is not the same as VC. The CSI-2 hardware have 4
+ * channels it can output on but which VC is outputted
+ * on which channel is configurable inside the CSI-2.
+ */
+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 +114,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 +124,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.14.0



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

2017-08-22 Thread Niklas Söderlund
The procedure to start or stop streaming using the none MC single
subdevice and the MC graph and multiple subdevices are quiet 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 
---
 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 de1486ee2786b499..499253f94390f43e 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;
+
+   /* Not 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) {
+   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 nativly */
+   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);
+   } else {
+   media_pipeline_stop(>vdev.entity);
+   ret = v4l2_subdev_call(sd, video, s_stream, 0);
+   }
+
+   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 

[PATCH v6 12/25] rcar-vin: move media bus configuration to struct rvin_info

2017-08-22 Thread Niklas Söderlund
Bus configuration will once the driver is extended to 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 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 14 +++---
 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, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 4dc148e7835439ab..65f01b6781c0aefd 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -45,15 +45,15 @@ static int rvin_find_pad(struct v4l2_subdev *sd, int 
direction)
return -EINVAL;
 }
 
-static bool rvin_mbus_supported(struct rvin_graph_entity *entity)
+static bool rvin_mbus_supported(struct rvin_dev *vin)
 {
-   struct v4l2_subdev *sd = entity->subdev;
+   struct v4l2_subdev *sd = vin->digital.subdev;
struct v4l2_subdev_mbus_code_enum code = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
};
 
code.index = 0;
-   code.pad = entity->source_pad;
+   code.pad = vin->digital.source_pad;
while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, )) {
code.index++;
switch (code.code) {
@@ -61,7 +61,7 @@ static bool rvin_mbus_supported(struct rvin_graph_entity 
*entity)
case MEDIA_BUS_FMT_UYVY8_2X8:
case MEDIA_BUS_FMT_UYVY10_2X10:
case MEDIA_BUS_FMT_RGB888_1X24:
-   entity->code = code.code;
+   vin->code = code.code;
return true;
default:
break;
@@ -78,14 +78,14 @@ static int rvin_digital_notify_complete(struct 
v4l2_async_notifier *notifier)
int ret;
 
/* Verify subdevices mbus format */
-   if (!rvin_mbus_supported(>digital)) {
+   if (!rvin_mbus_supported(vin)) {
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);
+   vin->digital.subdev->name, vin->code);
 
ret = v4l2_device_register_subdev_nodes(>v4l2_dev);
if (ret < 0) {
@@ -219,7 +219,7 @@ static int rvin_digital_graph_parse(struct rvin_dev *vin)
}
of_node_put(np);
 
-   ret = rvin_digitial_parse_v4l2(vin, ep, >digital.mbus_cfg);
+   ret = rvin_digitial_parse_v4l2(vin, ep, >mbus_cfg);
of_node_put(ep);
if (ret)
return ret;
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index f22bec062db31772..9362e7dba5e3ba95 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 Select */
-   if (!(vin->digital.mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
+   if (!(vin->mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
dmr2 |= VNDMR2_VPS;
 
  

[PATCH v6 22/25] rcar-vin: add link notify for Gen3

2017-08-22 Thread Niklas Söderlund
Add the ability to process media device link change request. Link
enablement are a bit complicated on Gen3, if it's possible to enable a
link depends on what other links already are enabled. On Gen3 the 8 VIN
are split into two subgroups (VIN0-3 and VIN4-7) and from a routing
perspective these two groups are independent of each other. Each
subgroups 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 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 203 
 1 file changed, 203 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 2aba442a0750e91a..dec91e2f3ccdbd93 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -26,6 +26,207 @@
 
 #include "rcar-vin.h"
 
+/* 
-
+ * Media Controller link notification
+ */
+
+static unsigned int rvin_group_csi_pad_to_chan(unsigned int pad)
+{
+   /*
+* The CSI2 driver is rcar-csi2 and we know it's pad layout are
+* 0: Source 1-4: Sinks so if we remove one from the pad we
+* get the rcar-vin internal CSI2 channel 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 match requested link */
+   sel = >vin[start]->info->chsels[start + n][i];
+   if (map[n].csi != sel->csi ||
+   map[n].chan != sel->chan) {
+   chsel = -1;
+   break;
+   }
+   }

[PATCH v6 18/25] rcar-vin: prepare for media controller mode initialization

2017-08-22 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 
---
 drivers/media/platform/rcar-vin/rcar-core.c | 23 ++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  4 
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index fbbb22924cf3a045..dd0525f2ba336bc2 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -45,6 +45,10 @@ static int rvin_find_pad(struct v4l2_subdev *sd, int 
direction)
return -EINVAL;
 }
 
+/* 
-
+ * Digital async notifier
+ */
+
 static bool rvin_mbus_supported(struct rvin_dev *vin)
 {
struct v4l2_subdev *sd = vin->digital.subdev;
@@ -273,6 +277,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
  */
@@ -365,7 +383,10 @@ static int rcar_vin_probe(struct platform_device *pdev)
if (ret)
return ret;
 
-   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 12daff804bb6f77f..9c47669669c0469c 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.14.0



[PATCH v6 13/25] rcar-vin: enable Gen3 hardware configuration

2017-08-22 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 
---
 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 9362e7dba5e3ba95..c4f8e81e88c99e28 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 */
ys = 0;
if (vin->crop.height != 

[PATCH v6 11/25] rcar-vin: fix handling of single field frames (top, bottom and alternate fields)

2017-08-22 Thread Niklas Söderlund
It 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
constrains 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 it's 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 
---
 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 6cc880e5ef7e0718..f22bec062db31772 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 c8c764188b85a926..9f0aac9c3398d613 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 @@ 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 V4L2_FIELD_INTERLACED:
-   break;
-   default:
-  

[PATCH v6 07/25] rcar-vin: all Gen2 boards can scale simplify logic

2017-08-22 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 hight when interacting with the
subdevice much like the field is preserved simplifies the logic quiet a
bit.

Signed-off-by: Niklas Söderlund 
---
 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 03a79de197d19e43..5f9674dc898305ba 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 ba88774bd5379a98..affdc128a75e502e 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 2d8b362012ea46a3..b2bac06c0a3cfcb7 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -177,8 +177,6 @@ int rvin_reset_format(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.14.0



[PATCH v6 01/25] rcar-vin: add Gen3 devicetree bindings documentation

2017-08-22 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 
---
 .../devicetree/bindings/media/rcar_vin.txt | 106 +++--
 1 file changed, 96 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt 
b/Documentation/devicetree/bindings/media/rcar_vin.txt
index 6e4ef8caf759e5d3..be38ad89d71ad05d 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.
+
+On Gen2 the current blocks are always slaves and support one input channel
+which can be either RGB, YUYV or BT656. On Gen3 the current blocks are
+always slaves and support multiple input channels which can be either RGB,
+YUVU, BT656 or CSI-2.
 
  - compatible: Must be one or more of the following
- "renesas,vin-r8a7795" for the R8A7795 device
@@ -28,7 +32,7 @@ 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.
@@ -36,13 +40,21 @@ The per-board settings:
These settings are used to work out video input format and widths
into the system.
 
+The per-board settings Gen3:
+- renesas,id - ID number of the VIN
+- Port 0 - Digital video source (same as port node on Gen2)
+- Port 1 - CSI-2 video sources
+- 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
 
-Device node example

+Device node example Gen2
+
 
-   aliases {
-  vin0 = 
-   };
+aliases {
+vin0 = 
+};
 
 vin0: vin@0xe6ef {
 compatible = "renesas,vin-r8a7790", "renesas,rcar-gen2-vin";
@@ -52,8 +64,8 @@ Device node example
 status = "disabled";
 };
 
-Board setup example (vin1 composite video input)
-
+Board setup example Gen2 (vin1 composite video input)
+-
 
{
 status = "ok";
@@ -92,6 +104,80 @@ 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>;
+status = "disabled";
+
+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>;
+remote-endpoint= <>;
+};
+vin0csi40: endpoint@2 {
+reg = <2>;
+remote-endpoint= <>;
+};
+};
+};
+};
+
+csi20: csi2@fea8 {
+compatible = "renesas,r8a7795-csi2", "renesas,rcar-gen3-csi2";
+reg = <0 0xfea8 0 0x1>;
+interrupts = ;
+clocks = < CPG_MOD 714>;
+  

[PATCH v6 00/25] rcar-vin: Add Gen3 with media controller

2017-08-22 Thread Niklas Söderlund
Hi,

This series adds Gen3 VIN support to rcar-vin driver for Renesas r8a7795 
and r8a7796. It is based on the media-tree.

The driver is tested on both Renesas H3 (r8a7795, ES1.x + ES2.0) and 
M3-W (r8a7796) together with the rcar-csi2 driver (posted separately and 
not yet upstream) and the Salvator-X onboard 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 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 probe time.
- Add H3 ES2.0 support.
- Fix handling of single field formats (top, bottom, alternate) as this 
  was obviously wrong before but hidden by the Gen2 scaler support.
- Added review tags from Kieran.

* Changes since v4 (Not posted to ML)
- Updated to the new fwnode functions.
- Moved the registration of the video devices to the async notification 
  callback.

* Changes since v3
- Only add neighboring subdevices to the async notifier. Instead of 
  parsing the whole OF graph depend on incremental async subnotifier to
  discover the whole pipeline. This is needed to support arbitrarily
  long graphs and support the new ADV7482 prototype driver which Kieran
  is working on.
- Fix warning from lockdep, reported by Kieran.
- Fix commit messages from feedback from Sergei, thanks.
- Fix chip info an OF device ids sorting order, thanks Geert.
- Use subdev->of_node instead of subdev->dev->of_node, thanks Kieran.

* Changes since v2
- Do not try to control the subdevices in the media graph from the rcar-vin
  driver. Have user-space configure to format in the pipeline instead.
- Add link validation before starting the stream.
- Rework on how the subdevices are and the video node behave by defining
  specific V4L2 operations for the MC mode of operation, this simplified the
  driver quit a bit, thanks Laurent!
- Add a new 'renesas,id' DT property which is needed to to be able to keep the
  VIN to CSI-2 routing table inside the driver. Previously this information was
  taken from the CSI-2 DT node which is obviusly the wrong way to do things.
  Thanks Laurent for pointing this out.
- Fixed a memory leek in the group allocator function.
- Return -EMLINK instead of -EBUSY if a MC link is not possible given the
  current routing setup.
- Add comments to clarify that the 4 channels from the CSI-2 node is not
  directly related to CSI-2 virtual channels, the CSI-2 node can output any VC
  on any of its output channels.

* Changes since v1
- Remove unneeded casts as pointed out by Geert.
- Fix spelling and DT documentation as pointed out by Geert and Sergei, thanks!
- Refresh patch 2/32 with an updated version, thanks Sakari for pointing this
  out.
- Add Sakaris Ack to patch 1/32.
- Rebase on top of v4.9-rc1 instead of v4.9-rc3 to ease integration testing
  together with renesas-drivers tree.


Niklas Söderlund (25):
  rcar-vin: add Gen3 devicetree bindings documentation
  rcar-vin: register the video device at probe time
  rcar-vin: move chip information to own struct
  rcar-vin: move max width and height information to chip information
  rcar-vin: change name of video device
  rcar-vin: move functions regarding scaling
  rcar-vin: all Gen2 boards can scale simplify logic
  rcar-vin: do not reset crop and compose when setting format
  rcar-vin: do not allow changing scaling and composing while streaming
  rcar-vin: read subdevice format for crop only when needed
  rcar-vin: fix handling of single field frames (top, bottom and
alternate fields)
  rcar-vin: move media bus configuration to struct rvin_info
  rcar-vin: enable Gen3 hardware configuration
  rcar-vin: add functions to manipulate Gen3 CHSEL value
  rcar-vin: add flag to switch to media controller mode
  rcar-vin: break out format alignment and checking
  rcar-vin: use different v4l2 operations in media controller mode
  rcar-vin: prepare for media controller mode initialization
  rcar-vin: add group allocator functions
  rcar-vin: add chsel information 

Re: [PATCH 0/2] net: Fix crashes due to activity during suspend

2017-08-22 Thread Geert Uytterhoeven
Hi Florian,

On Tue, Aug 22, 2017 at 8:49 PM, Florian Fainelli  wrote:
> On 08/22/2017 11:37 AM, Geert Uytterhoeven wrote:
>> If an Ethernet device is used while the device is suspended, the system may
>> crash.
>>
>> E.g. on sh73a0/kzm9g and r8a73a4/ape6evm, the external Ethernet chip is
>> driven by a PM controlled clock.  If the Ethernet registers are accessed
>> while the clock is not running, the system will crash with an imprecise
>> external abort.
>>
>> This patch series fixes two of such crashes:
>>   1. The first patch prevents the PHY polling state machine from accessing
>>  PHY registers while a device is suspended,
>>   2. The second patch prevents the net core from trying to transmit packets
>>  when an smsc911x device is suspended.
>>
>> Both crashes can be reproduced on sh73a0/kzm9g and r8a73a4/ape6evm during
>> s2ram (rarely), or by using pm_test (more likely to trigger):
>>
>> # echo 0 > /sys/module/printk/parameters/console_suspend
>> # echo platform > /sys/power/pm_test
>> # echo mem > /sys/power/state
>>
>> With this series applied, my test systems survive a loop of 100 test
>> suspends.
>
> It seems to me like part, if not the entire problem is that smsc91xx's
> suspend and resume functions are way too simplistic and absolutely do
> not manage the PHY during suspend/resume, the PHY state machine is not
> even stopped, so of course, this will cause bus errors if you access
> those registers.
>
> You are addressing this as part of patch 2, but this seems to me like
> this is still a bit incomplete and you'd need at least phy_stop() and/or
> phy_suspend() (does a power down of the PHY) and phy_start() and/or
> phy_resume() calls to complete the PHY state machine shutdown during
> suspend.
>
> Have you tried that?

Thank you, I will give that a try!

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


Re: [PATCH 2/2] net: smsc911x: Quiten netif during suspend

2017-08-22 Thread Andrew Lunn
On Tue, Aug 22, 2017 at 08:37:26PM +0200, Geert Uytterhoeven wrote:

Hi Geert

quieten. Has an E in the middle.

Otherwise this patch looks reasonable.

  Andrew


Re: [PATCH v2] device property: preserve usecount for node passed to of_fwnode_graph_get_port_parent()

2017-08-22 Thread Rob Herring
On Tue, Aug 22, 2017 at 10:00 AM, Niklas Söderlund
 wrote:
> Hi Rob,
>
> On 2017-08-22 09:49:35 -0500, Rob Herring wrote:
>> On Mon, Aug 21, 2017 at 7:19 PM, Niklas Söderlund
>>  wrote:
>> > Using CONFIG_OF_DYNAMIC=y uncovered an imbalance in the usecount of the
>> > node being passed to of_fwnode_graph_get_port_parent(). Preserve the
>> > usecount by using of_get_parent() instead of of_get_next_parent() which
>> > don't decrement the usecount of the node passed to it.
>> >
>> > Fixes: 3b27d00e7b6d7c88 ("device property: Move fwnode graph ops to 
>> > firmware specific locations")
>> > Signed-off-by: Niklas Söderlund 
>> > Acked-by: Sakari Ailus 
>> > ---
>> >  drivers/of/property.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> Isn't this already fixed with this fix:
>>
>> commit c0a480d1acf7dc184f9f3e7cf724483b0d28dc2e
>> Author: Tony Lindgren 
>> Date:   Fri Jul 28 01:23:15 2017 -0700
>>
>> device property: Fix usecount for of_graph_get_port_parent()
>
> No, that commit fixes it for of_graph_get_port_parent() while this
> commit fixes it for of_fwnode_graph_get_port_parent(). But in essence it
> is the same issue but needs two separate fixes.

Ah, because one takes the port node and one takes the endpoint node.
That won't confuse anyone.

Can we please align this mess. I've tried to make the graph parsing
not a free for all, open coded mess. There's no reason to have the
port node handle and then need the parent device. Either you started
with the parent device to parse local ports and endpoints or you got
the remote endpoint with .graph_get_remote_endpoint(). Most of the
time you don't even need the endpoint node handles. You really just
need to know what is the remote device connected to port X, endpoint Y
of my local device.

Rob


Re: adv7281m and rcar-vin problem

2017-08-22 Thread Niklas Söderlund
Hi Naman,

On 2017-08-23 00:15:41 +0530, Naman Jain wrote:
> Hi Niklas,
> 
> adv7281m driver powers up the CSI transmitter in s_power(), which is
> called before setting up of D-PHY layer of R-Car CSI-2 Receiver.
> I shifted the part of code which enables CSI transmitter in adv7281m
> (Low Power state to High Speed state) to s_stream() -
> 
> if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
>if (on) {
> adv7180_csi_write(state, 0xDE, 0x02);
> adv7180_csi_write(state, 0xD2, 0xF7);
> adv7180_csi_write(state, 0xD8, 0x65);
> adv7180_csi_write(state, 0xE0, 0x09);
> adv7180_csi_write(state, 0x2C, 0x00);
>if (state->field == V4L2_FIELD_NONE)
>adv7180_csi_write(state, 0x1D, 0x80);
> adv7180_csi_write(state, 0x00, 0x00);
>  } else {
> adv7180_csi_write(state, 0x00, 0x80);
>   }
> }
> 
> After this change, i am not getting timeout of reading the phy clock
> lane and capture starts but nothing is displayed on the screen.

I know nothing about the adv7281m driver, but if you define DEBUG in the 
rcar-vin and rcar-csi2 drivers it will provide you with a lot more 
information about how they behave and maybe it can help you in your 
troubleshooting. If you enable this and send me a console log of what 
happens when you try to start a stream I can try and help you.

> 
> On Wed, Jul 26, 2017 at 2:08 PM, Niklas Söderlund
>  wrote:
> > Hi Naman,
> >
> > On 2017-07-24 22:43:06 +0530, Naman Jain wrote:
> >> On Mon, Jul 24, 2017 at 3:11 PM, Niklas Söderlund
> >>  wrote:
> >> > Hi Naman,
> >> >
> >> > On 2017-07-24 14:30:52 +0530, Naman Jain wrote:
> >> >> i am using renesas soc with video decoder adv7281m
> >> >> i have done thr device tree configuration by following dt bindings
> >> >> i am getting timeout of reading the phy clock lane, after i start 
> >> >> streaming
> >> >> and nothing is displayed on the screen
> >> >> kindly help me in configuration
> >> >
> >> > To be able to try and help you I would need a lot more information. For
> >> > starters:
> >> >
> >> > - Which kernel version are you using?
> >> >
> >> > - How dose the device tree nodes for VIN and ADV7281m look like?
> >> >
> >> > --
> >> > Regards,
> >> > Niklas Söderlund
> >>
> >> Hi Niklas,
> >>
> >> I am using kernel version  - 4.9
> >
> > The VIN driver which supports CSI-2 and the R-Car CSI-2 driver is not a
> > part of the upstream kernel yet, and the latest patches with contains
> > the most fixes are based on newer kernels then v4.9. So I assume you are
> > using a BSP of some sort, if possible could you tell me which one?
> >
> > If you want to try with later increments of the VIN and CSI-2 patches
> > please see:
> >
> > http://elinux.org/R-Car/Tests:rcar-vin
> >
> >
> 
> Soc version is rcar-h3 (r8a7795).
> Can tell me dependency patches required?

The dependencies are documented in the wiki page mentioned above, you 
can also use the latest renesas-drivers master branch

git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git

> 
> >>
> >> following is the device tree configuration :
> >>
> >>  {
> >> status = "okay";
> >> clock-frequency = <40>;
> >> adv7281m@21{
> >>compatible = "adi,adv7281-m";
> >>reg = <0x20>;
> >>interrupt-parent = <>;
> >>interrupts = <4 IRQ_TYPE_LEVEL_LOW>
> >>adv7281m_out: endpoint {
> >> clock-lanes = <0>;
> >> data-lanes = <1>;
> >> remote-endpoint = <_in>;
> >>  };
> >>};
> >>
> >> }
> >>
> >>  {
> >>   status = "okay";
> >>   ports {
> >>  #address-cells = <1>;
> >>  #size-cells = <0>;
> >>
> >>  port@0 {
> >> reg = <0>;
> >> csi20_in: endpoint {
> >>clock-lanes = <0>;
> >>data-lanes = <1>;
> >> 
> >> virtual-channel-number=<0>;
> >
> > This is interesting for me, I have not worked with any driver for the
> > R-Car CSI-2 driver which understands the virtual-channel-number
> > property.
> >
> >>remote-endpoint =
> >> <_out>;
> >> };
> >>};
> >> };
> >> };
> >>
> >>  {
> >> status = "okay";
> >> };
> >>
> >>  {
> >> status = "okay";
> >> };
> >>
> >>  {
> >> status = "okay";
> >> };
> >>
> >>  {
> >> status = "okay";
> >> };
> >>
> >>  {
> >> status = "okay";
> 

Re: [PATCH 0/2] net: Fix crashes due to activity during suspend

2017-08-22 Thread Florian Fainelli
On 08/22/2017 11:37 AM, Geert Uytterhoeven wrote:
>   Hi all,
> 
> If an Ethernet device is used while the device is suspended, the system may
> crash.
> 
> E.g. on sh73a0/kzm9g and r8a73a4/ape6evm, the external Ethernet chip is
> driven by a PM controlled clock.  If the Ethernet registers are accessed
> while the clock is not running, the system will crash with an imprecise
> external abort.
> 
> This patch series fixes two of such crashes:
>   1. The first patch prevents the PHY polling state machine from accessing
>  PHY registers while a device is suspended,
>   2. The second patch prevents the net core from trying to transmit packets
>  when an smsc911x device is suspended.
> 
> Both crashes can be reproduced on sh73a0/kzm9g and r8a73a4/ape6evm during
> s2ram (rarely), or by using pm_test (more likely to trigger):
> 
> # echo 0 > /sys/module/printk/parameters/console_suspend
> # echo platform > /sys/power/pm_test
> # echo mem > /sys/power/state
> 
> With this series applied, my test systems survive a loop of 100 test
> suspends.

It seems to me like part, if not the entire problem is that smsc91xx's
suspend and resume functions are way too simplistic and absolutely do
not manage the PHY during suspend/resume, the PHY state machine is not
even stopped, so of course, this will cause bus errors if you access
those registers.

You are addressing this as part of patch 2, but this seems to me like
this is still a bit incomplete and you'd need at least phy_stop() and/or
phy_suspend() (does a power down of the PHY) and phy_start() and/or
phy_resume() calls to complete the PHY state machine shutdown during
suspend.

Have you tried that?
-- 
Florian


Re: adv7281m and rcar-vin problem

2017-08-22 Thread Naman Jain
Hi Niklas,

adv7281m driver powers up the CSI transmitter in s_power(), which is
called before setting up of D-PHY layer of R-Car CSI-2 Receiver.
I shifted the part of code which enables CSI transmitter in adv7281m
(Low Power state to High Speed state) to s_stream() -

if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
   if (on) {
adv7180_csi_write(state, 0xDE, 0x02);
adv7180_csi_write(state, 0xD2, 0xF7);
adv7180_csi_write(state, 0xD8, 0x65);
adv7180_csi_write(state, 0xE0, 0x09);
adv7180_csi_write(state, 0x2C, 0x00);
   if (state->field == V4L2_FIELD_NONE)
   adv7180_csi_write(state, 0x1D, 0x80);
adv7180_csi_write(state, 0x00, 0x00);
 } else {
adv7180_csi_write(state, 0x00, 0x80);
  }
}

After this change, i am not getting timeout of reading the phy clock
lane and capture starts but nothing is displayed on the screen.

On Wed, Jul 26, 2017 at 2:08 PM, Niklas Söderlund
 wrote:
> Hi Naman,
>
> On 2017-07-24 22:43:06 +0530, Naman Jain wrote:
>> On Mon, Jul 24, 2017 at 3:11 PM, Niklas Söderlund
>>  wrote:
>> > Hi Naman,
>> >
>> > On 2017-07-24 14:30:52 +0530, Naman Jain wrote:
>> >> i am using renesas soc with video decoder adv7281m
>> >> i have done thr device tree configuration by following dt bindings
>> >> i am getting timeout of reading the phy clock lane, after i start 
>> >> streaming
>> >> and nothing is displayed on the screen
>> >> kindly help me in configuration
>> >
>> > To be able to try and help you I would need a lot more information. For
>> > starters:
>> >
>> > - Which kernel version are you using?
>> >
>> > - How dose the device tree nodes for VIN and ADV7281m look like?
>> >
>> > --
>> > Regards,
>> > Niklas Söderlund
>>
>> Hi Niklas,
>>
>> I am using kernel version  - 4.9
>
> The VIN driver which supports CSI-2 and the R-Car CSI-2 driver is not a
> part of the upstream kernel yet, and the latest patches with contains
> the most fixes are based on newer kernels then v4.9. So I assume you are
> using a BSP of some sort, if possible could you tell me which one?
>
> If you want to try with later increments of the VIN and CSI-2 patches
> please see:
>
> http://elinux.org/R-Car/Tests:rcar-vin
>
>

Soc version is rcar-h3 (r8a7795).
Can tell me dependency patches required?

>>
>> following is the device tree configuration :
>>
>>  {
>> status = "okay";
>> clock-frequency = <40>;
>> adv7281m@21{
>>compatible = "adi,adv7281-m";
>>reg = <0x20>;
>>interrupt-parent = <>;
>>interrupts = <4 IRQ_TYPE_LEVEL_LOW>
>>adv7281m_out: endpoint {
>> clock-lanes = <0>;
>> data-lanes = <1>;
>> remote-endpoint = <_in>;
>>  };
>>};
>>
>> }
>>
>>  {
>>   status = "okay";
>>   ports {
>>  #address-cells = <1>;
>>  #size-cells = <0>;
>>
>>  port@0 {
>> reg = <0>;
>> csi20_in: endpoint {
>>clock-lanes = <0>;
>>data-lanes = <1>;
>> 
>> virtual-channel-number=<0>;
>
> This is interesting for me, I have not worked with any driver for the
> R-Car CSI-2 driver which understands the virtual-channel-number
> property.
>
>>remote-endpoint =
>> <_out>;
>> };
>>};
>> };
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>>
>>  {
>> status = "okay";
>> };
>
> --
> Regards,
> Niklas Söderlund


[PATCH 1/2] net: phy: Freeze PHY polling before suspending devices

2017-08-22 Thread Geert Uytterhoeven
During system resume, the PHY state machine may be run from the
workqueue while the Ethernet device (and its PHY) are still suspended,
which may lead to a system crash.

E.g. on sh73a0/kzm9g and r8a73a4/ape6evm, the external Ethernet chip is
driven by a PM controlled clock.  If the Ethernet registers are accessed
while the clock is not running, the system will crash with an imprecise
external abort.

As this is a race condition with a small time window, it is not so easy
to trigger at will.  Using pm_test may increase your chances:

# echo 0 > /sys/module/printk/parameters/console_suspend
# echo platform > /sys/power/pm_test
# echo mem > /sys/power/state

However, since commit 7ad813f208533ceb ("net: phy: Correctly process
PHY_HALTED in phy_stop_machine()"), this is much more likely to happen,
presumably due to the new sync point where phy_state_machine() calls
queue_delayed_work() just before entering system suspend.

To fix this, move PHY polling from the non-freezable to the freezable
power efficient work queue.  This is similar to what was done in commit
ea00353f36b64375 ("PCI: Freeze PME scan before suspending devices").

Stacktrace for posterity:

PM: Syncing filesystems ... done.
Freezing user space processes ... (elapsed 0.001 seconds) done.
OOM killer disabled.
Freezing remaining freezable tasks ... (elapsed 0.000 seconds) done.
PM: suspend devices took 0.010 seconds
Disabling non-boot CPUs ...
Enabling non-boot CPUs ...
Unhandled fault: imprecise external abort (0x1406) at 0x000cf6c8
pgd = c0004000
[000cf6c8] *pgd=
Internal error: : 1406 [#1] SMP ARM
Modules linked in:
CPU: 0 PID: 57 Comm: kworker/0:2 Not tainted 
4.13.0-rc5-kzm9g-04113-g3a897d275111fd6c #903
Hardware name: Generic SH73A0 (Flattened Device Tree)
Workqueue: events_power_efficient phy_state_machine
task: df6b4800 task.stack: df796000
PC is at __smsc911x_reg_read+0x1c/0x60
LR is at smsc911x_mac_read+0x4c/0x118
pc : []lr : []psr: 200d0093
sp : df797e98  ip :   fp : 0001
r10:   r9 : df70e380  r8 : 800d0093
r7 : df631de8  r6 : 0006  r5 : df631e08  r4 : df631dc0
r3 : e0903000  r2 :   r1 : e09030a4  r0 : 
Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: 5ee1404a  DAC: 0051
Process kworker/0:2 (pid: 57, stack limit = 0xdf796210)
Stack: (0xdf797e98 to 0xdf798000)
7e80:   df631dc0 
0001
7ea0: 0001 df631de8 600d0013 c03c8df4 df70e400 0001 0001 
df70e458
7ec0: df70e000 c03c7104 c03c6170 df70e000 df70e000 dfbc7bc0 df797f30 
c03c6138
7ee0: df77d900 c03c617c df77d900 df70e32c dfbc7bc0 c03c4218 df77d900 
df70e32c
7f00: dfbc7bc0 df797f30 dfbcb200   c013aa0c 0001 

7f20: c013a994    c1117f70   
c07420ec
7f40: c0904900 df77d900 dfbc7bc0 dfbc7bc0 df796000 dfbc7bf4 c0904900 
df77d918
7f60: 0008 c013b1e0 df6b4800 df75b500 df77e5c0  df44dea8 
df77d900
7f80: c013af28 df75b538  c0140584 df77e5c0 c0140460  

7fa0:    c0106ef0    

7fc0:        

7fe0:     0013   

[] (__smsc911x_reg_read) from [] 
(smsc911x_mac_read+0x4c/0x118)
[] (smsc911x_mac_read) from [] 
(smsc911x_mii_read+0x2c/0xa4)
[] (smsc911x_mii_read) from [] (mdiobus_read+0x58/0x70)
[] (mdiobus_read) from [] (genphy_update_link+0x18/0x50)
[] (genphy_update_link) from [] 
(genphy_read_status+0xc/0x1cc)
[] (genphy_read_status) from [] 
(phy_state_machine+0xa8/0x3dc)
[] (phy_state_machine) from [] 
(process_one_work+0x240/0x3fc)
[] (process_one_work) from [] 
(worker_thread+0x2b8/0x3f4)
[] (worker_thread) from [] (kthread+0x124/0x144)
[] (kthread) from [] (ret_from_fork+0x14/0x24)
Code: e5903000 e0831001 e591 f57ff04f (e12fff1e)

Signed-off-by: Geert Uytterhoeven 
---
 drivers/net/phy/phy.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index dae13f028c84ee17..2055165ca6349ee5 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -554,7 +554,8 @@ EXPORT_SYMBOL(phy_start_aneg);
  */
 void phy_start_machine(struct phy_device *phydev)
 {
-   queue_delayed_work(system_power_efficient_wq, >state_queue, HZ);
+   queue_delayed_work(system_freezable_power_efficient_wq,
+  >state_queue, HZ);
 }
 EXPORT_SYMBOL_GPL(phy_start_machine);
 
@@ -574,7 +575,8 @@ void phy_trigger_machine(struct phy_device *phydev, bool 
sync)
cancel_delayed_work_sync(>state_queue);
else

[PATCH 0/2] net: Fix crashes due to activity during suspend

2017-08-22 Thread Geert Uytterhoeven
Hi all,

If an Ethernet device is used while the device is suspended, the system may
crash.

E.g. on sh73a0/kzm9g and r8a73a4/ape6evm, the external Ethernet chip is
driven by a PM controlled clock.  If the Ethernet registers are accessed
while the clock is not running, the system will crash with an imprecise
external abort.

This patch series fixes two of such crashes:
  1. The first patch prevents the PHY polling state machine from accessing
 PHY registers while a device is suspended,
  2. The second patch prevents the net core from trying to transmit packets
 when an smsc911x device is suspended.

Both crashes can be reproduced on sh73a0/kzm9g and r8a73a4/ape6evm during
s2ram (rarely), or by using pm_test (more likely to trigger):

# echo 0 > /sys/module/printk/parameters/console_suspend
# echo platform > /sys/power/pm_test
# echo mem > /sys/power/state

With this series applied, my test systems survive a loop of 100 test
suspends.

Thanks for your comments!

Geert Uytterhoeven (2):
  net: phy: Freeze PHY polling before suspending devices
  net: smsc911x: Quiten netif during suspend

 drivers/net/ethernet/smsc/smsc911x.c | 15 ++-
 drivers/net/phy/phy.c| 12 +++-
 2 files changed, 21 insertions(+), 6 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 2/2] net: smsc911x: Quiten netif during suspend

2017-08-22 Thread Geert Uytterhoeven
If the network interface is kept running during suspend, the net core
may call net_device_ops.ndo_start_xmit() while the Ethernet device is
still suspended, which may lead to a system crash.

E.g. on sh73a0/kzm9g and r8a73a4/ape6evm, the external Ethernet chip is
driven by a PM controlled clock.  If the Ethernet registers are accessed
while the clock is not running, the system will crash with an imprecise
external abort.

As this is a race condition with a small time window, it is not so easy
to trigger at will.  Using pm_test may increase your chances:

# echo 0 > /sys/module/printk/parameters/console_suspend
# echo platform > /sys/power/pm_test
# echo mem > /sys/power/state

To fix this, make sure the network interface is quitened during suspend.

Signed-off-by: Geert Uytterhoeven 
---
No stacktrace is provided, as the imprecise external abort is usually
reported from an innocent looking and unrelated function like
__loop_delay(), cpu_idle_poll(), or arch_timer_read_counter_long().
---
 drivers/net/ethernet/smsc/smsc911x.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/smsc/smsc911x.c 
b/drivers/net/ethernet/smsc/smsc911x.c
index 0b6a39b003a4e188..012fb66eed8dd618 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -2595,6 +2595,11 @@ static int smsc911x_suspend(struct device *dev)
struct net_device *ndev = dev_get_drvdata(dev);
struct smsc911x_data *pdata = netdev_priv(ndev);
 
+   if (netif_running(ndev)) {
+   netif_stop_queue(ndev);
+   netif_device_detach(ndev);
+   }
+
/* enable wake on LAN, energy detection and the external PME
 * signal. */
smsc911x_reg_write(pdata, PMT_CTRL,
@@ -2628,7 +2633,15 @@ static int smsc911x_resume(struct device *dev)
while (!(smsc911x_reg_read(pdata, PMT_CTRL) & PMT_CTRL_READY_) && --to)
udelay(1000);
 
-   return (to == 0) ? -EIO : 0;
+   if (to == 0)
+   return -EIO;
+
+   if (netif_running(ndev)) {
+   netif_device_attach(ndev);
+   netif_start_queue(ndev);
+   }
+
+   return 0;
 }
 
 static const struct dev_pm_ops smsc911x_pm_ops = {
-- 
2.7.4



[PATCH] ARM: dtsi: iwg22m: Add RTC support

2017-08-22 Thread Fabrizio Castro
Add support for the bq32000 RTC to the iwg22m device tree.

Signed-off-by: Fabrizio Castro 
---

 This patch has some dependency:
 * [1/2] ARM: dts: iwg22m: Add iWave RZG1E SODIMM SOM - 
https://patchwork.kernel.org/patch/9901619/
 * [2/2] ARM: dts: iwg22d-sodimm: Add support for iWave G22D-SODIMM board - 
https://patchwork.kernel.org/patch/9901623/
 * ARM: dtsi: r8a7745: Add I2C DT support - 
https://patchwork.kernel.org/patch/9915525/
 * [1/2] ARM: dts: r8a7745: Add MMC interface support - 
https://patchwork.kernel.org/patch/9906803/
 * [2/2] ARM: dtsi: iwg22m: Add eMMC support - 
https://patchwork.kernel.org/patch/9906805/

 arch/arm/boot/dts/r8a7745-iwg22m.dtsi | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/r8a7745-iwg22m.dtsi 
b/arch/arm/boot/dts/r8a7745-iwg22m.dtsi
index afb1148..e306e7c 100644
--- a/arch/arm/boot/dts/r8a7745-iwg22m.dtsi
+++ b/arch/arm/boot/dts/r8a7745-iwg22m.dtsi
@@ -37,6 +37,11 @@
groups = "mmc_data8", "mmc_ctrl";
function = "mmc";
};
+
+   i2c3_pins: i2c3 {
+   groups = "i2c3_b";
+   function = "i2c3";
+   };
 };
 
  {
@@ -48,3 +53,16 @@
non-removable;
status = "okay";
 };
+
+ {
+   pinctrl-0 = <_pins>;
+   pinctrl-names = "default";
+
+   status = "okay";
+   clock-frequency = <40>;
+
+   rtc@68 {
+   compatible = "ti,bq32000";
+   reg = <0x68>;
+   };
+};
-- 
2.7.4



RE: [PATCH 0/2] ARM: dts: Add iWave RZ/G1E board support

2017-08-22 Thread Chris Paterson
Hello Simon,

> From: Biju Das [mailto:biju@bp.renesas.com]
> Sent: 15 August 2017 11:54
> 
> Hello,
> 
> This series aims to add iWave RZ/G1E (R8A7745) based RainboW-G22M-SM
> SODIMM SoM and RainboW-G22D board support.
> 
> This series has been tested against linux-next tag next-20170815 as well as
> renesas-dev tag 20170814-v4.13-rc5
> 
> This patch has documentation dependency on below patches

The below patches are now in your v4.14 branch. Does this mean that this DT 
series can now be accepted?

Thanks, Chris


> 
> [repost,1/2] ARM: shmobile: document iW-RainboW-G22M-SM SODIMM
> System on Module https://patchwork.kernel.org/patch/9890389/
> [repost, 2/2] ARM: shmobile: document iW-RainboW-G22D SODIMM SOM
> Development Platform https://patchwork.kernel.org/patch/9890391/
> 
> 
> Regards,
> 
> Biju Das (2):
>   ARM: dts: iwg22m: Add iWave RZG1E SODIMM SOM
>   ARM: dts: iwg22d-sodimm: Add support for iWave G22D-SODIMM board
> 
>  arch/arm/boot/dts/Makefile  |  1 +
>  arch/arm/boot/dts/r8a7745-iwg22d-sodimm.dts | 29
> +
>  arch/arm/boot/dts/r8a7745-iwg22m.dtsi   | 24
> 
>  3 files changed, 54 insertions(+)
>  create mode 100644 arch/arm/boot/dts/r8a7745-iwg22d-sodimm.dts
>  create mode 100644 arch/arm/boot/dts/r8a7745-iwg22m.dtsi
> 
> --
> 1.9.1



[PATCH] ARM: dtsi: r8a7745: Add I2C DT support

2017-08-22 Thread Fabrizio Castro
Add I2C[0-5] devices to the r8a7745 device tree.

Signed-off-by: Fabrizio Castro 
---
 arch/arm/boot/dts/r8a7745.dtsi | 93 ++
 1 file changed, 93 insertions(+)

diff --git a/arch/arm/boot/dts/r8a7745.dtsi b/arch/arm/boot/dts/r8a7745.dtsi
index 18ca7ae..2fa989f 100644
--- a/arch/arm/boot/dts/r8a7745.dtsi
+++ b/arch/arm/boot/dts/r8a7745.dtsi
@@ -18,6 +18,15 @@
#address-cells = <2>;
#size-cells = <2>;
 
+   aliases {
+   i2c0 = 
+   i2c1 = 
+   i2c2 = 
+   i2c3 = 
+   i2c4 = 
+   i2c5 = 
+   };
+
cpus {
#address-cells = <1>;
#size-cells = <0>;
@@ -613,6 +622,90 @@
#size-cells = <0>;
status = "disabled";
};
+
+   i2c0: i2c@e6508000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "renesas,i2c-r8a7745",
+"renesas,rcar-gen2-i2c";
+   reg = <0 0xe6508000 0 0x40>;
+   interrupts = ;
+   clocks = < CPG_MOD 931>;
+   power-domains = < R8A7745_PD_ALWAYS_ON>;
+   resets = < 931>;
+   i2c-scl-internal-delay-ns = <6>;
+   status = "disabled";
+   };
+
+   i2c1: i2c@e6518000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "renesas,i2c-r8a7745",
+"renesas,rcar-gen2-i2c";
+   reg = <0 0xe6518000 0 0x40>;
+   interrupts = ;
+   clocks = < CPG_MOD 930>;
+   power-domains = < R8A7745_PD_ALWAYS_ON>;
+   resets = < 930>;
+   i2c-scl-internal-delay-ns = <6>;
+   status = "disabled";
+   };
+
+   i2c2: i2c@e653 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "renesas,i2c-r8a7745",
+"renesas,rcar-gen2-i2c";
+   reg = <0 0xe653 0 0x40>;
+   interrupts = ;
+   clocks = < CPG_MOD 929>;
+   power-domains = < R8A7745_PD_ALWAYS_ON>;
+   resets = < 929>;
+   i2c-scl-internal-delay-ns = <6>;
+   status = "disabled";
+   };
+
+   i2c3: i2c@e654 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "renesas,i2c-r8a7745",
+"renesas,rcar-gen2-i2c";
+   reg = <0 0xe654 0 0x40>;
+   interrupts = ;
+   clocks = < CPG_MOD 928>;
+   power-domains = < R8A7745_PD_ALWAYS_ON>;
+   resets = < 928>;
+   i2c-scl-internal-delay-ns = <6>;
+   status = "disabled";
+   };
+
+   i2c4: i2c@e652 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "renesas,i2c-r8a7745",
+"renesas,rcar-gen2-i2c";
+   reg = <0 0xe652 0 0x40>;
+   interrupts = ;
+   clocks = < CPG_MOD 927>;
+   power-domains = < R8A7745_PD_ALWAYS_ON>;
+   resets = < 927>;
+   i2c-scl-internal-delay-ns = <6>;
+   status = "disabled";
+   };
+
+   i2c5: i2c@e6528000 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "renesas,i2c-r8a7745",
+"renesas,rcar-gen2-i2c";
+   reg = <0 0xe6528000 0 0x40>;
+   interrupts = ;
+   clocks = < CPG_MOD 925>;
+   power-domains = < R8A7745_PD_ALWAYS_ON>;
+   resets = < 925>;
+   i2c-scl-internal-delay-ns = <6>;
+   status = "disabled";
+   };
};
 
/* External root clock */
-- 
2.7.4



Re: [PATCH v2] device property: preserve usecount for node passed to of_fwnode_graph_get_port_parent()

2017-08-22 Thread Niklas Söderlund
Hi Rob,

On 2017-08-22 09:49:35 -0500, Rob Herring wrote:
> On Mon, Aug 21, 2017 at 7:19 PM, Niklas Söderlund
>  wrote:
> > Using CONFIG_OF_DYNAMIC=y uncovered an imbalance in the usecount of the
> > node being passed to of_fwnode_graph_get_port_parent(). Preserve the
> > usecount by using of_get_parent() instead of of_get_next_parent() which
> > don't decrement the usecount of the node passed to it.
> >
> > Fixes: 3b27d00e7b6d7c88 ("device property: Move fwnode graph ops to 
> > firmware specific locations")
> > Signed-off-by: Niklas Söderlund 
> > Acked-by: Sakari Ailus 
> > ---
> >  drivers/of/property.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Isn't this already fixed with this fix:
> 
> commit c0a480d1acf7dc184f9f3e7cf724483b0d28dc2e
> Author: Tony Lindgren 
> Date:   Fri Jul 28 01:23:15 2017 -0700
> 
> device property: Fix usecount for of_graph_get_port_parent()

No, that commit fixes it for of_graph_get_port_parent() while this 
commit fixes it for of_fwnode_graph_get_port_parent(). But in essence it 
is the same issue but needs two separate fixes.

-- 
Regards,
Niklas Söderlund


Re: [PATCH v2] device property: preserve usecount for node passed to of_fwnode_graph_get_port_parent()

2017-08-22 Thread Geert Uytterhoeven
Hi Rob,

On Tue, Aug 22, 2017 at 4:49 PM, Rob Herring  wrote:
> On Mon, Aug 21, 2017 at 7:19 PM, Niklas Söderlund
>  wrote:
>> Using CONFIG_OF_DYNAMIC=y uncovered an imbalance in the usecount of the
>> node being passed to of_fwnode_graph_get_port_parent(). Preserve the
>> usecount by using of_get_parent() instead of of_get_next_parent() which
>> don't decrement the usecount of the node passed to it.
>>
>> Fixes: 3b27d00e7b6d7c88 ("device property: Move fwnode graph ops to firmware 
>> specific locations")
>> Signed-off-by: Niklas Söderlund 
>> Acked-by: Sakari Ailus 
>> ---
>>  drivers/of/property.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> Isn't this already fixed with this fix:
>
> commit c0a480d1acf7dc184f9f3e7cf724483b0d28dc2e
> Author: Tony Lindgren 
> Date:   Fri Jul 28 01:23:15 2017 -0700
>
> device property: Fix usecount for of_graph_get_port_parent()

No, this one is for of_fwnode_graph_get_port_parent().

You're letting too many similarly-named new functions through ;-)

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


Re: [PATCH v2] device property: preserve usecount for node passed to of_fwnode_graph_get_port_parent()

2017-08-22 Thread Rob Herring
On Mon, Aug 21, 2017 at 7:19 PM, Niklas Söderlund
 wrote:
> Using CONFIG_OF_DYNAMIC=y uncovered an imbalance in the usecount of the
> node being passed to of_fwnode_graph_get_port_parent(). Preserve the
> usecount by using of_get_parent() instead of of_get_next_parent() which
> don't decrement the usecount of the node passed to it.
>
> Fixes: 3b27d00e7b6d7c88 ("device property: Move fwnode graph ops to firmware 
> specific locations")
> Signed-off-by: Niklas Söderlund 
> Acked-by: Sakari Ailus 
> ---
>  drivers/of/property.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Isn't this already fixed with this fix:

commit c0a480d1acf7dc184f9f3e7cf724483b0d28dc2e
Author: Tony Lindgren 
Date:   Fri Jul 28 01:23:15 2017 -0700

device property: Fix usecount for of_graph_get_port_parent()


[PATCH] arm64: dts: ulcb: Enable display output

2017-08-22 Thread Laurent Pinchart
The DU is already wired up to the HDMI encoder, all we need to do is
enable it.

Signed-off-by: Laurent Pinchart 
---
 arch/arm64/boot/dts/renesas/ulcb.dtsi | 4 
 1 file changed, 4 insertions(+)

This patch has been tested on the M3-W ULCB in Magnus' board farm. As no
display is connected to the HDMI output testing was limited, to probing the
device and verifying that it can be accessed from userspace.

Tests on the H3 ES1.1 and H3 ES2.0 ULCBs were less successful as I couldn't
get the boards to boot properly, but they failed without this patch as well,
so I don't think it should be a blocker.

diff --git a/arch/arm64/boot/dts/renesas/ulcb.dtsi 
b/arch/arm64/boot/dts/renesas/ulcb.dtsi
index 1b868df2393f..dfec9072718b 100644
--- a/arch/arm64/boot/dts/renesas/ulcb.dtsi
+++ b/arch/arm64/boot/dts/renesas/ulcb.dtsi
@@ -157,6 +157,10 @@
};
 };
 
+ {
+   status = "okay";
+};
+
  {
status = "okay";
 };
-- 
Regards,

Laurent Pinchart



Re: [PATCH] iommu/ipmmu-vmsa: Use iommu_device_sysfs_add()/remove()

2017-08-22 Thread Joerg Roedel
On Mon, Aug 21, 2017 at 02:53:35PM +0900, Magnus Damm wrote:
> From: Magnus Damm 
> 
> Extend the driver to make use of iommu_device_sysfs_add()/remove()
> functions to hook up initial sysfs support.
> 
> Suggested-by: Joerg Roedel 
> Signed-off-by: Magnus Damm 

Applied, thanks.



[PATCH] dt-bindings: apmu: Document r8a7745 support

2017-08-22 Thread Fabrizio Castro
Document APMU and SMP enable method for RZ/G1E (also known as
r8a7745) SoC.

Signed-off-by: Fabrizio Castro 
---
 Documentation/devicetree/bindings/power/renesas,apmu.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/power/renesas,apmu.txt 
b/Documentation/devicetree/bindings/power/renesas,apmu.txt
index af21502..f747f95 100644
--- a/Documentation/devicetree/bindings/power/renesas,apmu.txt
+++ b/Documentation/devicetree/bindings/power/renesas,apmu.txt
@@ -8,6 +8,7 @@ Required properties:
 - compatible: Should be "renesas,-apmu", "renesas,apmu" as fallback.
  Examples with soctypes are:
- "renesas,r8a7743-apmu" (RZ/G1M)
+   - "renesas,r8a7745-apmu" (RZ/G1E)
- "renesas,r8a7790-apmu" (R-Car H2)
- "renesas,r8a7791-apmu" (R-Car M2-W)
- "renesas,r8a7792-apmu" (R-Car V2H)
-- 
2.7.4



Re: [PATCH ] gpio: rcar: Add r8a7745 (RZ/G1E) support

2017-08-22 Thread Linus Walleij
On Wed, Aug 16, 2017 at 1:12 PM, Biju Das  wrote:

> Renesas RZ/G1E (R8A7745) SoC GPIO blocks are identical to the R-Car Gen2
> family. Add support for its GPIO controllers.
>
> Signed-off-by: Biju Das 

Patch applied with the ACKs

Yours,
Linus Walleij


Re: [PATCH] cpufreq: dt: Add r8a7796 support to to use generic cpufreq driver

2017-08-22 Thread Rafael J. Wysocki
On Wednesday, August 16, 2017 5:25:18 AM CEST Viresh Kumar wrote:
> On 11-08-17, 17:36, Simon Horman wrote:
> > From: Khiem Nguyen 
> > 
> > This patch adds the r8a7796 support the generic cpufreq driver
> > by adding an appropriate compat string. This is in keeping
> > with support for other Renesas ARM and arm64 based SoCs.
> > 
> > Signed-off-by: Khiem Nguyen 
> > [simon: new changelog]
> > Signed-off-by: Simon Horman 
> > ---
> >  drivers/cpufreq/cpufreq-dt-platdev.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > This is a follow-up for a similar change that has already been accepted
> > for the r8a7795.
> > 
> > 
> > I have provided an integration branch that includes with this patch, those
> > DTS updates that make use of opp-v2 bindings that depend on this change,
> > and Renesas clock updates also depended on by the DTS changes.  The result
> > is working CPUFreq for the r8a7796 (R-Car M3-W).
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git 
> > topic/r8a7796-cpufreq
> > 
> > A description of steps taken to lightly exercise the same feature for the
> > r88a7795 the above can be found at the link below. The results are the same
> > for the r8a7796 with the exception that it has two active CPU cores rather
> > than four.
> > 
> > http://elinux.org/Tests:R-CAR-GEN3-CPUFreq
> > 
> > diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c 
> > b/drivers/cpufreq/cpufreq-dt-platdev.c
> > index bcee384b3251..233e18ad3948 100644
> > --- a/drivers/cpufreq/cpufreq-dt-platdev.c
> > +++ b/drivers/cpufreq/cpufreq-dt-platdev.c
> > @@ -68,6 +68,7 @@ static const struct of_device_id machines[] __initconst = 
> > {
> > { .compatible = "renesas,r8a7793", },
> > { .compatible = "renesas,r8a7794", },
> > { .compatible = "renesas,r8a7795", },
> > +   { .compatible = "renesas,r8a7796", },
> > { .compatible = "renesas,sh73a0", },
> >  
> > { .compatible = "rockchip,rk2928", },
> 
> Acked-by: Viresh Kumar 
> 
> 

Applied, thanks!



Re: [git pull] pinctrl: sh-pfc: Updates for v4.14

2017-08-22 Thread Linus Walleij
On Thu, Aug 17, 2017 at 11:30 AM, Geert Uytterhoeven
 wrote:

> Hi Linus,
>
> The following changes since commit 5771a8c08880cdca3bfb4a3fc6d309d6bba20877:
>
>   Linux v4.13-rc1 (2017-07-15 15:22:10 -0700)
>
> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git 
> tags/sh-pfc-for-v4.14-tag1
>
> for you to fetch changes up to 56d57391ab6720c4b7bbc0a0cbc079c7b7d653fb:
>
>   pinctrl: sh-pfc: r8a77995: Add voltage switch operations for MMC 
> (2017-08-16 14:26:32 +0200)

Pulled into my devel branch for v4.14, excellent work as usual!

Yours,
Linus Walleij


Re: [PATCH v2] ARM: dts: r8a7743: add IIC cores to dtsi

2017-08-22 Thread Sergei Shtylyov

On 08/22/2017 12:10 PM, Chris Paterson wrote:


From: Biju Das [mailto:biju@bp.renesas.com]
Sent: 14 August 2017 10:53

Signed-off-by: Biju Das 
---
v1-->v2
Corrected the resets property for i2c6 device node.


Are you happy with this version of the patch?

Or is the discussion for moving to 'iic' still alive?


   Yes, appears so. I'd like the labels to be named iic.


Thanks, Chris


MBR, Sergei


Re: [PATCH 2/2] ARM: dts: r8a7743: Add IIC cores to dtsi

2017-08-22 Thread Sergei Shtylyov

Hello!

On 08/14/2017 05:15 PM, Geert Uytterhoeven wrote:


From: Wolfram Sang [mailto:w...@the-dreams.de]
Sent: 10 August 2017 12:24



+i2c6: i2c@e60b {


I'd use iic0 as the label.


Sergei: I assume you meant "iic3"? ;-)


   After having a look at the manual, yes. :-)

[...]


Gr{oetje,eeting}s,

 Geert


MBR, Sergei


Re: [PATCH v3] mmc: renesas_sdhi: Add r8a7743/5 support

2017-08-22 Thread Ulf Hansson
On 21 August 2017 at 14:25, Biju Das  wrote:
> Add support for r8a7743/5 SoC. Renesas RZ/G1[ME] (R8A7743/5) SDHI
> is identical to the R-Car Gen2 family.
>
> Signed-off-by: Biju Das 

Thanks, applied for next!

Kind regards
Uffe

> ---
> v1->v2
> - Modified the listing SoC's description related to SoC
>   with 1 Clock and 2 Clocks
> v2->v3
> - Fixed the trailing double quote.
> - Updated listing SoC's description.
>
> This patch is compiled and tested against linux next tag
> next-20170817.
>
>  Documentation/devicetree/bindings/mmc/tmio_mmc.txt | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/mmc/tmio_mmc.txt 
> b/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
> index 4fd8b7a..54ef642 100644
> --- a/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
> +++ b/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
> @@ -15,6 +15,8 @@ Required properties:
> "renesas,sdhi-r7s72100" - SDHI IP on R7S72100 SoC
> "renesas,sdhi-r8a73a4" - SDHI IP on R8A73A4 SoC
> "renesas,sdhi-r8a7740" - SDHI IP on R8A7740 SoC
> +   "renesas,sdhi-r8a7743" - SDHI IP on R8A7743 SoC
> +   "renesas,sdhi-r8a7745" - SDHI IP on R8A7745 SoC
> "renesas,sdhi-r8a7778" - SDHI IP on R8A7778 SoC
> "renesas,sdhi-r8a7779" - SDHI IP on R8A7779 SoC
> "renesas,sdhi-r8a7790" - SDHI IP on R8A7790 SoC
> @@ -33,10 +35,8 @@ Required properties:
>   If 2 clocks are specified by the hardware, you must name them as
>   "core" and "cd". If the controller only has 1 clock, naming is not
>   required.
> - Below is the number clocks for each supported SoC:
> -  1: SH73A0, R8A73A4, R8A7740, R8A7778, R8A7779, R8A7790
> - R8A7791, R8A7792, R8A7793, R8A7794, R8A7795, R8A7796
> -  2: R7S72100
> + Devices which have more than 1 clock are listed below:
> + 2: R7S72100
>
>  Optional properties:
>  - toshiba,mmc-wrprotect-disable: write-protect detection is unavailable
> --
> 1.9.1
>


RE: [PATCH ] ARM: dts: iwg20d-q7: Add chosen node

2017-08-22 Thread Biju Das


> -Original Message-
> From: Simon Horman [mailto:ho...@verge.net.au]
> Sent: 22 August 2017 09:08
> To: Biju Das 
> Cc: Rob Herring ; Mark Rutland
> ; Magnus Damm ;
> Russell King ; Chris Paterson
> ; Fabrizio Castro
> ; devicet...@vger.kernel.org; linux-renesas-
> s...@vger.kernel.org; linux-arm-ker...@lists.infradead.org
> Subject: Re: [PATCH ] ARM: dts: iwg20d-q7: Add chosen node
>
> On Fri, Aug 18, 2017 at 05:58:08PM +0100, Biju Das wrote:
> > Signed-off-by: Biju Das 
> > ---
> > This patch tested against renesas-dev tag
> > renesas-devel-20170815-v4.13-rc5
>
> Thanks, I have applied this for v4.15.
>
> There was some fuzz when applying this patch.
> Please check that it is correct when I have pushed today's devel tag to the
> renesas tree.

Thanks. I guess it may be related to the below RTC patch.
[v2] ARM: dts: iwg20d-q7: Add RTC support
https://patchwork.kernel.org/patch/9903327/

> >
> >  arch/arm/boot/dts/r8a7743-iwg20d-q7.dts | 5 +
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> > b/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> > index 081af01..305a6a1 100644
> > --- a/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> > +++ b/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> > @@ -19,6 +19,11 @@
> >  serial0 = 
> >  ethernet0 = 
> >  };
> > +
> > +chosen {
> > +bootargs = "ignore_loglevel rw root=/dev/nfs ip=dhcp";
> > +stdout-path = "serial0:115200n8";
> > +};
> >  };
> >
> >   {
> > --
> > 1.9.1
> >



Renesas Electronics Europe Ltd, Dukes Meadow, Millboard Road, Bourne End, 
Buckinghamshire, SL8 5FH, UK. Registered in England & Wales under Registered 
No. 04586709.


RE: [PATCH 0/3] Add SDHI Support

2017-08-22 Thread Biju Das


> -Original Message-
> From: Simon Horman [mailto:ho...@verge.net.au]
> Sent: 22 August 2017 09:03
> To: Biju Das 
> Cc: Rob Herring ; Mark Rutland
> ; Magnus Damm ;
> Chris Paterson ; Wolfram Sang
> ; devicet...@vger.kernel.org; linux-
> renesas-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org
> Subject: Re: [PATCH 0/3] Add SDHI Support
>
> On Mon, Aug 14, 2017 at 12:49:46PM +0100, Biju Das wrote:
> > This series aims to add SDHI support for r8a7743 SoC.
> >
> > This series has been compiled and tested against renesas-dev tag
> > renesas-devel-20170814-v4.13-rc5.
> >
> > There is no compile time dependencies.It has run time dependency on
> > [PATCH ] mmc: renesas_sdhi: Add r8a7743/5 support.
> > https://patchwork.kernel.org/patch/9898611/
> >
> > Biju Das (3):
> >   ARM: dts: r8a7743: Add SDHI controllers
> >   ARM: dts: iwg20m: Enable SDHI0 controller
> >   ARM: dts: iwg20d-q7: Add SDHI1 support
>
> Thanks, applied for v4.15 with Wolfram's tags.
>
> There was some fuzz when applying the last patch.
> Please check that is is correct once I push today's devel tag to the renesas 
> tree.

Thanks. I will check and let you know if there is any issues.




Renesas Electronics Europe Ltd, Dukes Meadow, Millboard Road, Bourne End, 
Buckinghamshire, SL8 5FH, UK. Registered in England & Wales under Registered 
No. 04586709.


[PATCH] ravb: make mdiobb_ops const

2017-08-22 Thread Bhumika Goyal
Make these const as they are only stored in a const field of a
mdiobb_ctrl structure.

Signed-off-by: Bhumika Goyal 
---
 drivers/net/ethernet/renesas/ravb_main.c | 2 +-
 drivers/net/ethernet/renesas/sh_eth.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c 
b/drivers/net/ethernet/renesas/ravb_main.c
index fdf30bf..6ffd9e4 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -172,7 +172,7 @@ static int ravb_get_mdio_data(struct mdiobb_ctrl *ctrl)
 }
 
 /* MDIO bus control struct */
-static struct mdiobb_ops bb_ops = {
+static const struct mdiobb_ops bb_ops = {
.owner = THIS_MODULE,
.set_mdc = ravb_set_mdc,
.set_mdio_dir = ravb_set_mdio_dir,
diff --git a/drivers/net/ethernet/renesas/sh_eth.c 
b/drivers/net/ethernet/renesas/sh_eth.c
index d2e88a3..8af353f 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1119,7 +1119,7 @@ static void sh_mdc_ctrl(struct mdiobb_ctrl *ctrl, int bit)
 }
 
 /* mdio bus control struct */
-static struct mdiobb_ops bb_ops = {
+static const struct mdiobb_ops bb_ops = {
.owner = THIS_MODULE,
.set_mdc = sh_mdc_ctrl,
.set_mdio_dir = sh_mmd_ctrl,
-- 
1.9.1



Re: [PATCH ] ARM: dts: iwg20d-q7: Add chosen node

2017-08-22 Thread Simon Horman
On Fri, Aug 18, 2017 at 05:58:08PM +0100, Biju Das wrote:
> Signed-off-by: Biju Das 
> ---
> This patch tested against renesas-dev tag renesas-devel-20170815-v4.13-rc5

Thanks, I have applied this for v4.15.

There was some fuzz when applying this patch.
Please check that it is correct when I have pushed today's devel tag to
the renesas tree.

> 
>  arch/arm/boot/dts/r8a7743-iwg20d-q7.dts | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts 
> b/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> index 081af01..305a6a1 100644
> --- a/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> +++ b/arch/arm/boot/dts/r8a7743-iwg20d-q7.dts
> @@ -19,6 +19,11 @@
>   serial0 = 
>   ethernet0 = 
>   };
> +
> + chosen {
> + bootargs = "ignore_loglevel rw root=/dev/nfs ip=dhcp";
> + stdout-path = "serial0:115200n8";
> + };
>  };
>  
>   {
> -- 
> 1.9.1
> 


Re: [PATCH ] ARM: dts: r8a7745: Add GPIO support

2017-08-22 Thread Simon Horman
On Fri, Aug 18, 2017 at 03:56:01PM +0100, Biju Das wrote:
> Describe GPIO blocks in the R8A7745 device tree.
> 
> Signed-off-by: Biju Das 
> ---
> This patch has run time dependency on the below patch
> [PATCH/RFC] gpio: rcar: add gen[123] fallback compatibility strings
> https://patchwork.kernel.org/patch/9834611/

Thanks, applied for v4.15.


Re: [PATCH 0/3] Add SDHI Support

2017-08-22 Thread Simon Horman
On Mon, Aug 14, 2017 at 12:49:46PM +0100, Biju Das wrote:
> This series aims to add SDHI support for r8a7743 SoC.
> 
> This series has been compiled and tested against renesas-dev tag
> renesas-devel-20170814-v4.13-rc5.
> 
> There is no compile time dependencies.It has run time dependency on
> [PATCH ] mmc: renesas_sdhi: Add r8a7743/5 support.
> https://patchwork.kernel.org/patch/9898611/ 
> 
> Biju Das (3):
>   ARM: dts: r8a7743: Add SDHI controllers
>   ARM: dts: iwg20m: Enable SDHI0 controller
>   ARM: dts: iwg20d-q7: Add SDHI1 support

Thanks, applied for v4.15 with Wolfram's tags.

There was some fuzz when applying the last patch.
Please check that is is correct once I push today's devel tag
to the renesas tree.


Re: [PATCH v3] mmc: renesas_sdhi: Add r8a7743/5 support

2017-08-22 Thread Simon Horman
On Mon, Aug 21, 2017 at 02:43:05PM +0200, Wolfram Sang wrote:
> On Mon, Aug 21, 2017 at 01:25:11PM +0100, Biju Das wrote:
> > Add support for r8a7743/5 SoC. Renesas RZ/G1[ME] (R8A7743/5) SDHI
> > is identical to the R-Car Gen2 family.
> > 
> > Signed-off-by: Biju Das 
> 
> Reviewed-by: Wolfram Sang 

Its probably time for some fallback compatibility strings but
I think that should be done as follow-up (likely by me) in a considered
way. So this patch is fine in my books.

Acked-by: Simon Horman 




Re: [PATCH v2] arm64: dts: renesas: r8a7796: Add FDP1 instance

2017-08-22 Thread Simon Horman
On Mon, Aug 21, 2017 at 12:25:21PM +0300, Laurent Pinchart wrote:
> Hi Simon,
> 
> On Thursday, 13 July 2017 14:21:10 EEST Laurent Pinchart wrote:
> > The r8a7796 has a single FDP1 instance.
> > 
> > Signed-off-by: Laurent Pinchart 
> > Reviewed-by: Kieran Bingham 
> > Reviewed-by: Geert Uytterhoeven 
> 
> Could you pick this up ?

Sorry for letting this slip through.
I have applied it for v4.15.


Re: [PATCH 4/4] clk: renesas: r8a7795: Add Z2 clock

2017-08-22 Thread Simon Horman
On Fri, Aug 04, 2017 at 03:23:00PM +0200, Simon Horman wrote:
> From: Takeshi Kihara 
> 
> This patch adds Z2 clock for r8a7795 SoC.
> 
> Signed-off-by: Takeshi Kihara 

It seems that this is missing:

Signed-off-by: Simon Horman 

> ---
>  drivers/clk/renesas/r8a7795-cpg-mssr.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/clk/renesas/r8a7795-cpg-mssr.c 
> b/drivers/clk/renesas/r8a7795-cpg-mssr.c
> index 084ccf01fae6..b0266a4b0852 100644
> --- a/drivers/clk/renesas/r8a7795-cpg-mssr.c
> +++ b/drivers/clk/renesas/r8a7795-cpg-mssr.c
> @@ -75,6 +75,7 @@ static struct cpg_core_clk r8a7795_core_clks[] __initdata = 
> {
>  
>   /* Core Clock Outputs */
>   DEF_BASE("z",   R8A7795_CLK_Z, CLK_TYPE_GEN3_Z, CLK_PLL0),
> + DEF_BASE("z2",  R8A7795_CLK_Z2,CLK_TYPE_GEN3_Z2, CLK_PLL2),
>   DEF_FIXED("ztr",R8A7795_CLK_ZTR,   CLK_PLL1_DIV2,  6, 1),
>   DEF_FIXED("ztrd2",  R8A7795_CLK_ZTRD2, CLK_PLL1_DIV2, 12, 1),
>   DEF_FIXED("zt", R8A7795_CLK_ZT,CLK_PLL1_DIV2,  4, 1),
> -- 
> 2.1.4
> 


Re: Status of r8a7795 SDHI support?

2017-08-22 Thread Wolfram Sang

> Btw, whats about HS400 support for the eMMC? As the eMMC is often the 'mass
> storage' device for the rootfs, the eMMC performance will have a direct
> influence to the overall system performance.

Sure, I know. We finally have Gen3 SDHI DMA upstream and SDR104 seems to
be stable as well (we are still testing corner cases, though). HS400
would obviously be next.



signature.asc
Description: PGP signature


Re: Status of r8a7795 SDHI support?

2017-08-22 Thread Dirk Behme

On 22.08.2017 08:56, Wolfram Sang wrote:



I'm not an expert on this, does SDR104 need 1.8V?

To my understanding, sd-uhs-sdr50 is the max speed for 3.3V?


Nope, everything with SDR* needs 1.8V. So, classic "highspeed" is the
maximum for your slot.


I ask because on my custom board the hardware guys gave us 3.3V, only, for
the SD slot :(


Pity, in deed.



Yes, indeed :(

Btw, whats about HS400 support for the eMMC? As the eMMC is often the 
'mass storage' device for the rootfs, the eMMC performance will have a 
direct influence to the overall system performance.


Dirk


[PATCH v2] pinctrl: sh-pfc: r8a7795: Add SDHIx support

2017-08-22 Thread Dirk Behme
Add SDHIx support for ES2.0. Taken from the Renesas BSP

https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git/tree/drivers/pinctrl/sh-pfc/pfc-r8a7795.c

Signed-off-by: Dirk Behme 
---
Note: Patch is generated against renesas-drivers-2017-08-16-v4.13-rc5

Changes in v2: Fix a typo found by Kuninori Morimoto, thanks!

drivers/pinctrl/sh-pfc/pfc-r8a7795.c | 275 +++
 1 file changed, 275 insertions(+)

diff --git a/drivers/pinctrl/sh-pfc/pfc-r8a7795.c 
b/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
index 8b35772cda98..b225bc2f9bea 100644
--- a/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
+++ b/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
@@ -2734,6 +2734,213 @@ static const unsigned int scif5_clk_b_mux[] = {
SCK5_B_MARK,
 };
 
+/* - SDHI0 -- 
*/
+static const unsigned int sdhi0_data1_pins[] = {
+   /* D0 */
+   RCAR_GP_PIN(3, 2),
+};
+static const unsigned int sdhi0_data1_mux[] = {
+   SD0_DAT0_MARK,
+};
+static const unsigned int sdhi0_data4_pins[] = {
+   /* D[0:3] */
+   RCAR_GP_PIN(3, 2), RCAR_GP_PIN(3, 3),
+   RCAR_GP_PIN(3, 4), RCAR_GP_PIN(3, 5),
+};
+static const unsigned int sdhi0_data4_mux[] = {
+   SD0_DAT0_MARK, SD0_DAT1_MARK,
+   SD0_DAT2_MARK, SD0_DAT3_MARK,
+};
+static const unsigned int sdhi0_ctrl_pins[] = {
+   /* CLK, CMD */
+   RCAR_GP_PIN(3, 0), RCAR_GP_PIN(3, 1),
+};
+static const unsigned int sdhi0_ctrl_mux[] = {
+   SD0_CLK_MARK, SD0_CMD_MARK,
+};
+static const unsigned int sdhi0_cd_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(3, 12),
+};
+static const unsigned int sdhi0_cd_mux[] = {
+   SD0_CD_MARK,
+};
+static const unsigned int sdhi0_wp_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(3, 13),
+};
+static const unsigned int sdhi0_wp_mux[] = {
+   SD0_WP_MARK,
+};
+/* - SDHI1 -- 
*/
+static const unsigned int sdhi1_data1_pins[] = {
+   /* D0 */
+   RCAR_GP_PIN(3, 8),
+};
+static const unsigned int sdhi1_data1_mux[] = {
+   SD1_DAT0_MARK,
+};
+static const unsigned int sdhi1_data4_pins[] = {
+   /* D[0:3] */
+   RCAR_GP_PIN(3, 8),  RCAR_GP_PIN(3, 9),
+   RCAR_GP_PIN(3, 10), RCAR_GP_PIN(3, 11),
+};
+static const unsigned int sdhi1_data4_mux[] = {
+   SD1_DAT0_MARK, SD1_DAT1_MARK,
+   SD1_DAT2_MARK, SD1_DAT3_MARK,
+};
+static const unsigned int sdhi1_ctrl_pins[] = {
+   /* CLK, CMD */
+   RCAR_GP_PIN(3, 6), RCAR_GP_PIN(3, 7),
+};
+static const unsigned int sdhi1_ctrl_mux[] = {
+   SD1_CLK_MARK, SD1_CMD_MARK,
+};
+static const unsigned int sdhi1_cd_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(3, 14),
+};
+static const unsigned int sdhi1_cd_mux[] = {
+   SD1_CD_MARK,
+};
+static const unsigned int sdhi1_wp_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(3, 15),
+};
+static const unsigned int sdhi1_wp_mux[] = {
+   SD1_WP_MARK,
+};
+/* - SDHI2 -- 
*/
+static const unsigned int sdhi2_data1_pins[] = {
+   /* D0 */
+   RCAR_GP_PIN(4, 2),
+};
+static const unsigned int sdhi2_data1_mux[] = {
+   SD2_DAT0_MARK,
+};
+static const unsigned int sdhi2_data4_pins[] = {
+   /* D[0:3] */
+   RCAR_GP_PIN(4, 2), RCAR_GP_PIN(4, 3),
+   RCAR_GP_PIN(4, 4), RCAR_GP_PIN(4, 5),
+};
+static const unsigned int sdhi2_data4_mux[] = {
+   SD2_DAT0_MARK, SD2_DAT1_MARK,
+   SD2_DAT2_MARK, SD2_DAT3_MARK,
+};
+static const unsigned int sdhi2_data8_pins[] = {
+   /* D[0:7] */
+   RCAR_GP_PIN(4, 2),  RCAR_GP_PIN(4, 3),
+   RCAR_GP_PIN(4, 4),  RCAR_GP_PIN(4, 5),
+   RCAR_GP_PIN(3, 8),  RCAR_GP_PIN(3, 9),
+   RCAR_GP_PIN(3, 10), RCAR_GP_PIN(3, 11),
+};
+static const unsigned int sdhi2_data8_mux[] = {
+   SD2_DAT0_MARK, SD2_DAT1_MARK,
+   SD2_DAT2_MARK, SD2_DAT3_MARK,
+   SD2_DAT4_MARK, SD2_DAT5_MARK,
+   SD2_DAT6_MARK, SD2_DAT7_MARK,
+};
+static const unsigned int sdhi2_ctrl_pins[] = {
+   /* CLK, CMD */
+   RCAR_GP_PIN(4, 0), RCAR_GP_PIN(4, 1),
+};
+static const unsigned int sdhi2_ctrl_mux[] = {
+   SD2_CLK_MARK, SD2_CMD_MARK,
+};
+static const unsigned int sdhi2_cd_a_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(4, 13),
+};
+static const unsigned int sdhi2_cd_a_mux[] = {
+   SD2_CD_A_MARK,
+};
+static const unsigned int sdhi2_cd_b_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(5, 10),
+};
+static const unsigned int sdhi2_cd_b_mux[] = {
+   SD2_CD_B_MARK,
+};
+static const unsigned int sdhi2_wp_a_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(4, 14),
+};
+static const unsigned int sdhi2_wp_a_mux[] = {
+   SD2_WP_A_MARK,
+};
+static const unsigned int sdhi2_wp_b_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(5, 11),
+};
+static const unsigned int sdhi2_wp_b_mux[] = {
+   SD2_WP_B_MARK,
+};
+static const unsigned int sdhi2_ds_pins[] = {
+   /* DS */
+   RCAR_GP_PIN(4, 

Re: Status of r8a7795 SDHI support?

2017-08-22 Thread Wolfram Sang

> I'm not an expert on this, does SDR104 need 1.8V?
> 
> To my understanding, sd-uhs-sdr50 is the max speed for 3.3V?

Nope, everything with SDR* needs 1.8V. So, classic "highspeed" is the
maximum for your slot.

> I ask because on my custom board the hardware guys gave us 3.3V, only, for
> the SD slot :(

Pity, in deed.



signature.asc
Description: PGP signature


Re: [PATCH] pinctrl: sh-pfc: r8a7795: Add SDHIx support

2017-08-22 Thread Kuninori Morimoto

Hi Dirk

> Add SDHIx support for ES2.0. Taken from the Renesas BSP
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git/tree/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
> 
> Signed-off-by: Dirk Behme 
> ---
(snip)
> @@ -3182,7 +3453,7 @@ static const char * const usb2_groups[] = {
>  
>  static const char * const usb2_ch3_groups[] = {
>   "usb2_ch3",
> -};
> +}

I think this patch is not related to usb2,
and ";" is needed here ?

Best regards
---
Kuninori Morimoto


Re: Status of r8a7795 SDHI support?

2017-08-22 Thread Dirk Behme

On 21.08.2017 15:47, Wolfram Sang wrote:



It works, now :)


Great!


tmio_mmc_init_ocr()

fails (silently!). And with this the whole RCar3 SDHI, without any error
message.


I'll check next week about an error message there.


Many thanks for your help!


You're welcome. If you want, you can even test SDR104 by applying this
patch:

[RFT] arm64: dts: renesas: salvator-common: enable SDR104 for SD cards

It works fine here for SD cards. My SDIO card makes problems, but that
might be the line length is just too long. We are currently evaluating
that. So, testing SDR104 on various boards would be very helpful!



I'm not an expert on this, does SDR104 need 1.8V?

To my understanding, sd-uhs-sdr50 is the max speed for 3.3V?

I ask because on my custom board the hardware guys gave us 3.3V, only, 
for the SD slot :(




P.S.: Will try to send the pin mux patch tomorrow.


Thanks, I'll have a look at it next week then, too.



Patch sent.

Best regards

Dirk


[PATCH] pinctrl: sh-pfc: r8a7795: Add SDHIx support

2017-08-22 Thread Dirk Behme
Add SDHIx support for ES2.0. Taken from the Renesas BSP

https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git/tree/drivers/pinctrl/sh-pfc/pfc-r8a7795.c

Signed-off-by: Dirk Behme 
---

Note: Patch is generated against renesas-drivers-2017-08-16-v4.13-rc5

 drivers/pinctrl/sh-pfc/pfc-r8a7795.c | 277 ++-
 1 file changed, 276 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/sh-pfc/pfc-r8a7795.c 
b/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
index 8b35772cda98..324d8ce8cdb4 100644
--- a/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
+++ b/drivers/pinctrl/sh-pfc/pfc-r8a7795.c
@@ -2734,6 +2734,213 @@ static const unsigned int scif5_clk_b_mux[] = {
SCK5_B_MARK,
 };
 
+/* - SDHI0 -- 
*/
+static const unsigned int sdhi0_data1_pins[] = {
+   /* D0 */
+   RCAR_GP_PIN(3, 2),
+};
+static const unsigned int sdhi0_data1_mux[] = {
+   SD0_DAT0_MARK,
+};
+static const unsigned int sdhi0_data4_pins[] = {
+   /* D[0:3] */
+   RCAR_GP_PIN(3, 2), RCAR_GP_PIN(3, 3),
+   RCAR_GP_PIN(3, 4), RCAR_GP_PIN(3, 5),
+};
+static const unsigned int sdhi0_data4_mux[] = {
+   SD0_DAT0_MARK, SD0_DAT1_MARK,
+   SD0_DAT2_MARK, SD0_DAT3_MARK,
+};
+static const unsigned int sdhi0_ctrl_pins[] = {
+   /* CLK, CMD */
+   RCAR_GP_PIN(3, 0), RCAR_GP_PIN(3, 1),
+};
+static const unsigned int sdhi0_ctrl_mux[] = {
+   SD0_CLK_MARK, SD0_CMD_MARK,
+};
+static const unsigned int sdhi0_cd_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(3, 12),
+};
+static const unsigned int sdhi0_cd_mux[] = {
+   SD0_CD_MARK,
+};
+static const unsigned int sdhi0_wp_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(3, 13),
+};
+static const unsigned int sdhi0_wp_mux[] = {
+   SD0_WP_MARK,
+};
+/* - SDHI1 -- 
*/
+static const unsigned int sdhi1_data1_pins[] = {
+   /* D0 */
+   RCAR_GP_PIN(3, 8),
+};
+static const unsigned int sdhi1_data1_mux[] = {
+   SD1_DAT0_MARK,
+};
+static const unsigned int sdhi1_data4_pins[] = {
+   /* D[0:3] */
+   RCAR_GP_PIN(3, 8),  RCAR_GP_PIN(3, 9),
+   RCAR_GP_PIN(3, 10), RCAR_GP_PIN(3, 11),
+};
+static const unsigned int sdhi1_data4_mux[] = {
+   SD1_DAT0_MARK, SD1_DAT1_MARK,
+   SD1_DAT2_MARK, SD1_DAT3_MARK,
+};
+static const unsigned int sdhi1_ctrl_pins[] = {
+   /* CLK, CMD */
+   RCAR_GP_PIN(3, 6), RCAR_GP_PIN(3, 7),
+};
+static const unsigned int sdhi1_ctrl_mux[] = {
+   SD1_CLK_MARK, SD1_CMD_MARK,
+};
+static const unsigned int sdhi1_cd_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(3, 14),
+};
+static const unsigned int sdhi1_cd_mux[] = {
+   SD1_CD_MARK,
+};
+static const unsigned int sdhi1_wp_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(3, 15),
+};
+static const unsigned int sdhi1_wp_mux[] = {
+   SD1_WP_MARK,
+};
+/* - SDHI2 -- 
*/
+static const unsigned int sdhi2_data1_pins[] = {
+   /* D0 */
+   RCAR_GP_PIN(4, 2),
+};
+static const unsigned int sdhi2_data1_mux[] = {
+   SD2_DAT0_MARK,
+};
+static const unsigned int sdhi2_data4_pins[] = {
+   /* D[0:3] */
+   RCAR_GP_PIN(4, 2), RCAR_GP_PIN(4, 3),
+   RCAR_GP_PIN(4, 4), RCAR_GP_PIN(4, 5),
+};
+static const unsigned int sdhi2_data4_mux[] = {
+   SD2_DAT0_MARK, SD2_DAT1_MARK,
+   SD2_DAT2_MARK, SD2_DAT3_MARK,
+};
+static const unsigned int sdhi2_data8_pins[] = {
+   /* D[0:7] */
+   RCAR_GP_PIN(4, 2),  RCAR_GP_PIN(4, 3),
+   RCAR_GP_PIN(4, 4),  RCAR_GP_PIN(4, 5),
+   RCAR_GP_PIN(3, 8),  RCAR_GP_PIN(3, 9),
+   RCAR_GP_PIN(3, 10), RCAR_GP_PIN(3, 11),
+};
+static const unsigned int sdhi2_data8_mux[] = {
+   SD2_DAT0_MARK, SD2_DAT1_MARK,
+   SD2_DAT2_MARK, SD2_DAT3_MARK,
+   SD2_DAT4_MARK, SD2_DAT5_MARK,
+   SD2_DAT6_MARK, SD2_DAT7_MARK,
+};
+static const unsigned int sdhi2_ctrl_pins[] = {
+   /* CLK, CMD */
+   RCAR_GP_PIN(4, 0), RCAR_GP_PIN(4, 1),
+};
+static const unsigned int sdhi2_ctrl_mux[] = {
+   SD2_CLK_MARK, SD2_CMD_MARK,
+};
+static const unsigned int sdhi2_cd_a_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(4, 13),
+};
+static const unsigned int sdhi2_cd_a_mux[] = {
+   SD2_CD_A_MARK,
+};
+static const unsigned int sdhi2_cd_b_pins[] = {
+   /* CD */
+   RCAR_GP_PIN(5, 10),
+};
+static const unsigned int sdhi2_cd_b_mux[] = {
+   SD2_CD_B_MARK,
+};
+static const unsigned int sdhi2_wp_a_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(4, 14),
+};
+static const unsigned int sdhi2_wp_a_mux[] = {
+   SD2_WP_A_MARK,
+};
+static const unsigned int sdhi2_wp_b_pins[] = {
+   /* WP */
+   RCAR_GP_PIN(5, 11),
+};
+static const unsigned int sdhi2_wp_b_mux[] = {
+   SD2_WP_B_MARK,
+};
+static const unsigned int sdhi2_ds_pins[] = {
+   /* DS */
+   RCAR_GP_PIN(4, 6),
+};
+static const unsigned int