Re: [PATCH v2 6/7] [media] vimc: deb: Add debayer filter

2017-05-08 Thread Hans Verkuil
On 04/08/2017 12:37 AM, Helen Koike wrote:
> Implement the debayer filter and integrate it with the core
> 
> Signed-off-by: Helen Koike 
> 
> ---
> 
> Changes in v2:
> [media] vimc: deb: Add debayer filter
>   - Using MEDIA_ENT_F_ATV_DECODER in function
>   - remove v4l2_dev and dev from vimc_deb_device struct
>   - src fmt propagates from the sink
>   - coding style
>   - remove redundant else if statements
>   - check end of enum and remove BUG_ON
>   - enum frame size with min and max values
>   - set/try fmt
>   - remove unecessary include freezer.h
>   - check pad types on create
>   - return EBUSY when trying to set the format while stream is on
>   - remove vsd struct
>   - add IS_SRC and IS_SINK macros
>   - add deb_mean_win_size as a parameter of the module
>   - check set_fmt default parameters for quantization, colorspace ...
>   - add more dev_dbg
> 
> 
> ---
>  drivers/media/platform/vimc/Makefile   |   2 +-
>  drivers/media/platform/vimc/vimc-core.c|   6 +-
>  drivers/media/platform/vimc/vimc-core.h|   2 +
>  drivers/media/platform/vimc/vimc-debayer.c | 573 
> +
>  drivers/media/platform/vimc/vimc-debayer.h |  28 ++
>  5 files changed, 609 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/media/platform/vimc/vimc-debayer.c
>  create mode 100644 drivers/media/platform/vimc/vimc-debayer.h
> 
> diff --git a/drivers/media/platform/vimc/Makefile 
> b/drivers/media/platform/vimc/Makefile
> index c45195e..a6708f9 100644
> --- a/drivers/media/platform/vimc/Makefile
> +++ b/drivers/media/platform/vimc/Makefile
> @@ -1,3 +1,3 @@
> -vimc-objs := vimc-core.o vimc-capture.o vimc-sensor.o
> +vimc-objs := vimc-core.o vimc-capture.o vimc-debayer.o vimc-sensor.o
>  
>  obj-$(CONFIG_VIDEO_VIMC) += vimc.o
> diff --git a/drivers/media/platform/vimc/vimc-core.c 
> b/drivers/media/platform/vimc/vimc-core.c
> index bc4b1bb..51cbbf6 100644
> --- a/drivers/media/platform/vimc/vimc-core.c
> +++ b/drivers/media/platform/vimc/vimc-core.c
> @@ -23,6 +23,7 @@
>  
>  #include "vimc-capture.h"
>  #include "vimc-core.h"
> +#include "vimc-debayer.h"
>  #include "vimc-sensor.h"
>  
>  #define VIMC_PDEV_NAME "vimc"
> @@ -637,9 +638,12 @@ static int vimc_device_register(struct vimc_device *vimc)
>   create_func = vimc_cap_create;
>   break;
>  
> + case VIMC_ENT_NODE_DEBAYER:
> + create_func = vimc_deb_create;
> + break;
> +
>   /* TODO: Instantiate the specific topology node */
>   case VIMC_ENT_NODE_INPUT:
> - case VIMC_ENT_NODE_DEBAYER:
>   case VIMC_ENT_NODE_SCALER:
>   default:
>   /*
> diff --git a/drivers/media/platform/vimc/vimc-core.h 
> b/drivers/media/platform/vimc/vimc-core.h
> index 2146672..2e621fe 100644
> --- a/drivers/media/platform/vimc/vimc-core.h
> +++ b/drivers/media/platform/vimc/vimc-core.h
> @@ -26,6 +26,8 @@
>  #define VIMC_FRAME_MIN_WIDTH 16
>  #define VIMC_FRAME_MIN_HEIGHT 16
>  
> +#define VIMC_FRAME_INDEX(lin, col, width, bpp) ((lin * width + col) * bpp)
> +
>  /**
>   * struct vimc_pix_map - maps media bus code with v4l2 pixel format
>   *
> diff --git a/drivers/media/platform/vimc/vimc-debayer.c 
> b/drivers/media/platform/vimc/vimc-debayer.c
> new file mode 100644
> index 000..24e5952
> --- /dev/null
> +++ b/drivers/media/platform/vimc/vimc-debayer.c
> @@ -0,0 +1,573 @@
> +/*
> + * vimc-debayer.c Virtual Media Controller Driver
> + *
> + * Copyright (C) 2015-2017 Helen Koike 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "vimc-debayer.h"
> +
> +static unsigned int deb_mean_win_size = 3;
> +module_param(deb_mean_win_size, uint, );
> +MODULE_PARM_DESC(deb_mean_win_size, " the window size to calculate the 
> mean.\n"
> + "NOTE: the window size need to be an odd number, as the main pixel "
> + "stays in the center of the window, otherwise the next odd number "
> + "is considered");
> +
> +#define IS_SINK(pad) (!pad)
> +#define IS_SRC(pad)  (pad)
> +
> +enum vimc_deb_rgb_colors {
> + VIMC_DEB_RED = 0,
> + VIMC_DEB_GREEN = 1,
> + VIMC_DEB_BLUE = 2,
> +};
> +
> +struct vimc_deb_pix_map {
> + u32 code;
> + enum vimc_deb_rgb_colors order[2][2];
> +};
> +
> +struct 

[PATCH v2 6/7] [media] vimc: deb: Add debayer filter

2017-04-07 Thread Helen Koike
Implement the debayer filter and integrate it with the core

Signed-off-by: Helen Koike 

---

Changes in v2:
[media] vimc: deb: Add debayer filter
- Using MEDIA_ENT_F_ATV_DECODER in function
- remove v4l2_dev and dev from vimc_deb_device struct
- src fmt propagates from the sink
- coding style
- remove redundant else if statements
- check end of enum and remove BUG_ON
- enum frame size with min and max values
- set/try fmt
- remove unecessary include freezer.h
- check pad types on create
- return EBUSY when trying to set the format while stream is on
- remove vsd struct
- add IS_SRC and IS_SINK macros
- add deb_mean_win_size as a parameter of the module
- check set_fmt default parameters for quantization, colorspace ...
- add more dev_dbg


---
 drivers/media/platform/vimc/Makefile   |   2 +-
 drivers/media/platform/vimc/vimc-core.c|   6 +-
 drivers/media/platform/vimc/vimc-core.h|   2 +
 drivers/media/platform/vimc/vimc-debayer.c | 573 +
 drivers/media/platform/vimc/vimc-debayer.h |  28 ++
 5 files changed, 609 insertions(+), 2 deletions(-)
 create mode 100644 drivers/media/platform/vimc/vimc-debayer.c
 create mode 100644 drivers/media/platform/vimc/vimc-debayer.h

diff --git a/drivers/media/platform/vimc/Makefile 
b/drivers/media/platform/vimc/Makefile
index c45195e..a6708f9 100644
--- a/drivers/media/platform/vimc/Makefile
+++ b/drivers/media/platform/vimc/Makefile
@@ -1,3 +1,3 @@
-vimc-objs := vimc-core.o vimc-capture.o vimc-sensor.o
+vimc-objs := vimc-core.o vimc-capture.o vimc-debayer.o vimc-sensor.o
 
 obj-$(CONFIG_VIDEO_VIMC) += vimc.o
diff --git a/drivers/media/platform/vimc/vimc-core.c 
b/drivers/media/platform/vimc/vimc-core.c
index bc4b1bb..51cbbf6 100644
--- a/drivers/media/platform/vimc/vimc-core.c
+++ b/drivers/media/platform/vimc/vimc-core.c
@@ -23,6 +23,7 @@
 
 #include "vimc-capture.h"
 #include "vimc-core.h"
+#include "vimc-debayer.h"
 #include "vimc-sensor.h"
 
 #define VIMC_PDEV_NAME "vimc"
@@ -637,9 +638,12 @@ static int vimc_device_register(struct vimc_device *vimc)
create_func = vimc_cap_create;
break;
 
+   case VIMC_ENT_NODE_DEBAYER:
+   create_func = vimc_deb_create;
+   break;
+
/* TODO: Instantiate the specific topology node */
case VIMC_ENT_NODE_INPUT:
-   case VIMC_ENT_NODE_DEBAYER:
case VIMC_ENT_NODE_SCALER:
default:
/*
diff --git a/drivers/media/platform/vimc/vimc-core.h 
b/drivers/media/platform/vimc/vimc-core.h
index 2146672..2e621fe 100644
--- a/drivers/media/platform/vimc/vimc-core.h
+++ b/drivers/media/platform/vimc/vimc-core.h
@@ -26,6 +26,8 @@
 #define VIMC_FRAME_MIN_WIDTH 16
 #define VIMC_FRAME_MIN_HEIGHT 16
 
+#define VIMC_FRAME_INDEX(lin, col, width, bpp) ((lin * width + col) * bpp)
+
 /**
  * struct vimc_pix_map - maps media bus code with v4l2 pixel format
  *
diff --git a/drivers/media/platform/vimc/vimc-debayer.c 
b/drivers/media/platform/vimc/vimc-debayer.c
new file mode 100644
index 000..24e5952
--- /dev/null
+++ b/drivers/media/platform/vimc/vimc-debayer.c
@@ -0,0 +1,573 @@
+/*
+ * vimc-debayer.c Virtual Media Controller Driver
+ *
+ * Copyright (C) 2015-2017 Helen Koike 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "vimc-debayer.h"
+
+static unsigned int deb_mean_win_size = 3;
+module_param(deb_mean_win_size, uint, );
+MODULE_PARM_DESC(deb_mean_win_size, " the window size to calculate the mean.\n"
+   "NOTE: the window size need to be an odd number, as the main pixel "
+   "stays in the center of the window, otherwise the next odd number "
+   "is considered");
+
+#define IS_SINK(pad) (!pad)
+#define IS_SRC(pad)  (pad)
+
+enum vimc_deb_rgb_colors {
+   VIMC_DEB_RED = 0,
+   VIMC_DEB_GREEN = 1,
+   VIMC_DEB_BLUE = 2,
+};
+
+struct vimc_deb_pix_map {
+   u32 code;
+   enum vimc_deb_rgb_colors order[2][2];
+};
+
+struct vimc_deb_device {
+   struct vimc_ent_device ved;
+   struct v4l2_subdev sd;
+   /* The active format */
+   struct v4l2_mbus_framefmt sink_fmt;
+   u32 src_code;
+   void (*set_rgb_src)(struct vimc_deb_device *vdeb, unsigned int lin,
+