Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Baruch Siach
Hi Jacob,

On Fri, Mar 09, 2018 at 01:05:28PM +0800, Jacob Chen wrote:
> 2018-03-09 12:09 GMT+08:00 Baruch Siach :
> > On Fri, Mar 09, 2018 at 08:53:57AM +0800, Jacob Chen wrote:
> >> 2018-03-08 20:02 GMT+08:00 Baruch Siach :
> >> > On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
> >> >> This patch series add a ISP(Camera) v4l2 driver for rockchip 
> >> >> rk3288/rk3399
> >> >> SoC.
> >> >>
> >> >> Wiki Pages:
> >> >> http://opensource.rock-chips.com/wiki_Rockchip-isp1
> >> >>
> >> >> The deprecated g_mbus_config op is not dropped in  V6 because i am 
> >> >> waiting
> >> >> tomasz's patches.
> >> >
> >> > Which tree is this series based on? On top of v4.16-rc4 I get the build
> >> > failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not 
> >> > even
> >> > in media_tree.git.
> >>
> >> This series is based on v4.16-rc4 with below patch.
> >> https://patchwork.kernel.org/patch/9792001/
> >
> > This patch does not apply on v4.16-rc4. I also tried v2 of this patch with 
> > the
> > same result:
> >
> >   https://patchwork.linuxtv.org/patch/44682/
> 
> It need resolve merge conflict.
> 
> > Can you push your series to a public git repo branch?
> 
> Sure, I have push it to my github.
> https://github.com/wzyy2/linux/tree/4.16-rc4
> 
> This commit might be a bit of a mess
> https://github.com/wzyy2/linux/commit/ff68323c4804adc10f64836ea1be172c54a9d6c6

Thanks. This is very helpful.

I'm mostly interested in the tinkerboard, so the DT bits in your tree are also 
useful.

baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -


Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
Hi Baruch,

2018-03-09 12:09 GMT+08:00 Baruch Siach :
> Hi Jacob,
>
> On Fri, Mar 09, 2018 at 08:53:57AM +0800, Jacob Chen wrote:
>> 2018-03-08 20:02 GMT+08:00 Baruch Siach :
>> > On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
>> >> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
>> >> SoC.
>> >>
>> >> Wiki Pages:
>> >> http://opensource.rock-chips.com/wiki_Rockchip-isp1
>> >>
>> >> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
>> >> tomasz's patches.
>> >
>> > Which tree is this series based on? On top of v4.16-rc4 I get the build
>> > failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not 
>> > even
>> > in media_tree.git.
>>
>> This series is based on v4.16-rc4 with below patch.
>> https://patchwork.kernel.org/patch/9792001/
>
> This patch does not apply on v4.16-rc4. I also tried v2 of this patch with the
> same result:
>
>   https://patchwork.linuxtv.org/patch/44682/

It need resolve merge conflict.

>
> Can you push your series to a public git repo branch?
>

Sure, I have push it to my github.
https://github.com/wzyy2/linux/tree/4.16-rc4

This commit might be a bit of a mess
https://github.com/wzyy2/linux/commit/ff68323c4804adc10f64836ea1be172c54a9d6c6

> Thanks,
> baruch
>
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
>> > you mean ‘vidioc_enum_fmt_meta_cap’?
>> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>> >^~~~
>> >vidioc_enum_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>> >   ^~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did 
>> > you mean ‘vidioc_g_fmt_meta_cap’?
>> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^
>> >vidioc_g_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did 
>> > you mean ‘vidioc_s_fmt_meta_cap’?
>> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^
>> >vidioc_s_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
>> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did 
>> > you mean ‘vidioc_try_fmt_meta_cap’?
>> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >^~~
>> >vidioc_try_fmt_meta_cap
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
>> > initialization from incompatible pointer type 
>> > [-Werror=incompatible-pointer-types]
>> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>> >  ^~~~
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
>> > initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
>> > drivers/media/platform/rockchip/isp1/isp_params.c: In function 
>> > ‘rkisp1_params_init_vb2_queue’:
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: error: 
>> > ‘V4L2_BUF_TYPE_META_OUTPUT’ undeclared (first use in this function); did 
>> > you mean ‘V4L2_BUF_TYPE_SDR_OUTPUT’?
>> >   q->type = V4L2_BUF_TYPE_META_OUTPUT;
>> > ^
>> > V4L2_BUF_TYPE_SDR_OUTPUT
>> > drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: note: each 
>> > undeclared identifier is reported only once for each function it appears in
>> >   CC  drivers/media/platform/rockchip/isp1/mipi_dphy_sy.o

cron job: media_tree daily build: ERRORS

2018-03-08 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Fri Mar  9 05:00:10 CET 2018
media-tree git hash:e68854a2588a923b31eebce348f8020374843f8e
media_build git hash:   992168cb60d578dfaf4859a70184fc71780e503d
v4l-utils git hash: 362241b6350b30238e7b45f79c5842b4d27e987b
gcc version:i686-linux-gcc (GCC) 7.3.0
sparse version: v0.5.0-3994-g45eb2282
smatch version: v0.5.0-3994-g45eb2282
host hardware:  x86_64
host os:4.14.0-3-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: WARNINGS
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-arm64: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: ERRORS
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.60-i686: ERRORS
linux-3.0.60-x86_64: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.1.10-x86_64: ERRORS
linux-3.2.98-i686: ERRORS
linux-3.2.98-x86_64: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.3.8-x86_64: ERRORS
linux-3.4.27-i686: ERRORS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.4-i686: ERRORS
linux-3.7.4-x86_64: ERRORS
linux-3.8-i686: ERRORS
linux-3.8-x86_64: ERRORS
linux-3.9.2-i686: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12.67-i686: WARNINGS
linux-3.12.67-x86_64: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.53-i686: WARNINGS
linux-3.16.53-x86_64: WARNINGS
linux-3.17.8-i686: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.93-i686: WARNINGS
linux-3.18.93-x86_64: WARNINGS
linux-3.19-i686: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0.9-i686: WARNINGS
linux-4.0.9-x86_64: WARNINGS
linux-4.1.49-i686: WARNINGS
linux-4.1.49-x86_64: WARNINGS
linux-4.2.8-i686: WARNINGS
linux-4.2.8-x86_64: WARNINGS
linux-4.3.6-i686: WARNINGS
linux-4.3.6-x86_64: WARNINGS
linux-4.4.115-i686: WARNINGS
linux-4.4.115-x86_64: WARNINGS
linux-4.5.7-i686: WARNINGS
linux-4.5.7-x86_64: WARNINGS
linux-4.6.7-i686: WARNINGS
linux-4.6.7-x86_64: WARNINGS
linux-4.7.5-i686: WARNINGS
linux-4.7.5-x86_64: WARNINGS
linux-4.8-i686: WARNINGS
linux-4.8-x86_64: WARNINGS
linux-4.9.80-i686: WARNINGS
linux-4.9.80-x86_64: WARNINGS
linux-4.10.14-i686: WARNINGS
linux-4.10.14-x86_64: WARNINGS
linux-4.11-i686: WARNINGS
linux-4.11-x86_64: WARNINGS
linux-4.12.1-i686: WARNINGS
linux-4.12.1-x86_64: WARNINGS
linux-4.13-i686: WARNINGS
linux-4.13-x86_64: WARNINGS
linux-4.14.17-i686: WARNINGS
linux-4.14.17-x86_64: WARNINGS
linux-4.15.2-i686: WARNINGS
linux-4.15.2-x86_64: WARNINGS
linux-4.16-rc1-i686: WARNINGS
linux-4.16-rc1-x86_64: WARNINGS
apps: WARNINGS
spec-git: OK
sparse: WARNINGS
smatch: OK

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Friday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Friday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Baruch Siach
Hi Jacob,

On Fri, Mar 09, 2018 at 08:53:57AM +0800, Jacob Chen wrote:
> 2018-03-08 20:02 GMT+08:00 Baruch Siach :
> > On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
> >> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
> >> SoC.
> >>
> >> Wiki Pages:
> >> http://opensource.rock-chips.com/wiki_Rockchip-isp1
> >>
> >> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
> >> tomasz's patches.
> >
> > Which tree is this series based on? On top of v4.16-rc4 I get the build
> > failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not even
> > in media_tree.git.
> 
> This series is based on v4.16-rc4 with below patch.
> https://patchwork.kernel.org/patch/9792001/

This patch does not apply on v4.16-rc4. I also tried v2 of this patch with the 
same result:

  https://patchwork.linuxtv.org/patch/44682/

Can you push your series to a public git repo branch?

Thanks,
baruch

> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
> > you mean ‘vidioc_enum_fmt_meta_cap’?
> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
> >^~~~
> >vidioc_enum_fmt_meta_cap
> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
> > initialization from incompatible pointer type 
> > [-Werror=incompatible-pointer-types]
> >   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
> >   ^~~
> > drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
> > initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did you 
> > mean ‘vidioc_g_fmt_meta_cap’?
> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> >^
> >vidioc_g_fmt_meta_cap
> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
> > initialization from incompatible pointer type 
> > [-Werror=incompatible-pointer-types]
> >   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> >^~~~
> > drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
> > initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did you 
> > mean ‘vidioc_s_fmt_meta_cap’?
> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> >^
> >vidioc_s_fmt_meta_cap
> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
> > initialization from incompatible pointer type 
> > [-Werror=incompatible-pointer-types]
> >   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> >^~~~
> > drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
> > initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
> > struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did 
> > you mean ‘vidioc_try_fmt_meta_cap’?
> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> >^~~
> >vidioc_try_fmt_meta_cap
> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
> > initialization from incompatible pointer type 
> > [-Werror=incompatible-pointer-types]
> >   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> >  ^~~~
> > drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
> > initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
> > drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> > ‘rkisp1_params_init_vb2_queue’:
> > drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: error: 
> > ‘V4L2_BUF_TYPE_META_OUTPUT’ undeclared (first use in this function); did 
> > you mean ‘V4L2_BUF_TYPE_SDR_OUTPUT’?
> >   q->type = V4L2_BUF_TYPE_META_OUTPUT;
> > ^
> > V4L2_BUF_TYPE_SDR_OUTPUT
> > drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: note: each 
> > undeclared identifier is reported only once for each function it appears in
> >   CC  drivers/media/platform/rockchip/isp1/mipi_dphy_sy.o
> > drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> > ‘rkisp1_register_params_vdev’:
> > drivers/media/platform/rockchip/isp1/isp_params.c:1507:43: error: 
> > ‘V4L2_CAP_META_OUTPUT’ undeclared (first use in this function); did you 
> > mean ‘V4L2_CAP_VBI_OUTPUT’?
> >   vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT;
> >

Re: [PATCH v9 2/2] media: V3s: Add support for Allwinner CSI.

2018-03-08 Thread Yong
Hi,

On Tue, 6 Mar 2018 17:14:18 +0200
Sakari Ailus  wrote:

> Hi Yong,
> 
> Thanks for the patchset; please see my comments below.
> 
> On Tue, Mar 06, 2018 at 10:16:02AM +0800, Yong Deng wrote:
> > Allwinner V3s SoC features two CSI module. CSI0 is used for MIPI CSI-2
> > interface and CSI1 is used for parallel interface. This is not
> > documented in datasheet but by test and guess.

...

> > +
> > +static const u32 supported_pixformats[] = {
> > +   V4L2_PIX_FMT_SBGGR8,
> > +   V4L2_PIX_FMT_SGBRG8,
> > +   V4L2_PIX_FMT_SGRBG8,
> > +   V4L2_PIX_FMT_SRGGB8,
> > +   V4L2_PIX_FMT_SBGGR10,
> > +   V4L2_PIX_FMT_SGBRG10,
> > +   V4L2_PIX_FMT_SGRBG10,
> > +   V4L2_PIX_FMT_SRGGB10,
> > +   V4L2_PIX_FMT_SBGGR12,
> > +   V4L2_PIX_FMT_SGBRG12,
> > +   V4L2_PIX_FMT_SGRBG12,
> > +   V4L2_PIX_FMT_SRGGB12,
> > +   V4L2_PIX_FMT_YUYV,
> > +   V4L2_PIX_FMT_YVYU,
> > +   V4L2_PIX_FMT_UYVY,
> > +   V4L2_PIX_FMT_VYUY,
> > +   V4L2_PIX_FMT_HM12,
> > +   V4L2_PIX_FMT_NV12,
> > +   V4L2_PIX_FMT_NV21,
> > +   V4L2_PIX_FMT_YUV420,
> > +   V4L2_PIX_FMT_YVU420,
> > +   V4L2_PIX_FMT_NV16,
> > +   V4L2_PIX_FMT_NV61,
> > +   V4L2_PIX_FMT_YUV422P,
> > +};
> 
> How about moving this where it's actually used? You'd also get rid of the
> function to obtain this list.

I think which formats are supported is determined by hardware (CSI).
And different SoCs may support different formats. The distinction will
be made in sun6i-csi.c.

> 
> > +
> > +static inline struct sun6i_csi_dev *sun6i_csi_to_dev(struct sun6i_csi *csi)
> > +{
> > +   return container_of(csi, struct sun6i_csi_dev, csi);
> > +}
> > +
> > +int sun6i_csi_get_supported_pixformats(struct sun6i_csi *csi,
> > +  const u32 **pixformats)
> > +{
> > +   if (pixformats != NULL)
> > +   *pixformats = supported_pixformats;
> > +
> > +   return ARRAY_SIZE(supported_pixformats);
> > +}
> > +
> > +/* TODO add 10&12 bit YUV, RGB support */
> > +bool sun6i_csi_is_format_support(struct sun6i_csi *csi,
> 
> s/support/supported/

OK.

> 
> > +u32 pixformat, u32 mbus_code)
> > +{
> > +   struct sun6i_csi_dev *sdev = sun6i_csi_to_dev(csi);
> > +
> > +   /*
> > +* Some video receivers have the ability to be compatible with
> > +* 8bit and 16bit bus width.
> > +* Identify the media bus format from device tree.
> > +*/
> > +   if ((sdev->csi.v4l2_ep.bus_type == V4L2_MBUS_PARALLEL
> > + || sdev->csi.v4l2_ep.bus_type == V4L2_MBUS_BT656)
> > +&& sdev->csi.v4l2_ep.bus.parallel.bus_width == 16) {
> > +   switch (pixformat) {
> > +   case V4L2_PIX_FMT_HM12:
> > +   case V4L2_PIX_FMT_NV12:
> > +   case V4L2_PIX_FMT_NV21:
> > +   case V4L2_PIX_FMT_NV16:
> > +   case V4L2_PIX_FMT_NV61:
> > +   case V4L2_PIX_FMT_YUV420:
> > +   case V4L2_PIX_FMT_YVU420:
> > +   case V4L2_PIX_FMT_YUV422P:
> > +   switch (mbus_code) {
> > +   case MEDIA_BUS_FMT_UYVY8_1X16:
> > +   case MEDIA_BUS_FMT_VYUY8_1X16:
> > +   case MEDIA_BUS_FMT_YUYV8_1X16:
> > +   case MEDIA_BUS_FMT_YVYU8_1X16:
> > +   return true;
> > +   default:
> > +   dev_dbg(sdev->dev, "Unsupported mbus code: 
> > 0x%x\n",
> > +   mbus_code);
> > +   break;
> > +   }
> > +   break;
> > +   default:
> > +   dev_dbg(sdev->dev, "Unsupported pixformat: 0x%x\n",
> > +   pixformat);
> > +   break;
> > +   }
> > +   return false;
> > +   }
> > +
> > +   switch (pixformat) {
> > +   case V4L2_PIX_FMT_SBGGR8:
> > +   return (mbus_code == MEDIA_BUS_FMT_SBGGR8_1X8);
> > +   case V4L2_PIX_FMT_SGBRG8:
> > +   return (mbus_code == MEDIA_BUS_FMT_SGBRG8_1X8);
> > +   case V4L2_PIX_FMT_SGRBG8:
> > +   return (mbus_code == MEDIA_BUS_FMT_SGRBG8_1X8);
> > +   case V4L2_PIX_FMT_SRGGB8:
> > +   return (mbus_code == MEDIA_BUS_FMT_SRGGB8_1X8);
> > +   case V4L2_PIX_FMT_SBGGR10:
> > +   return (mbus_code == MEDIA_BUS_FMT_SBGGR10_1X10);
> > +   case V4L2_PIX_FMT_SGBRG10:
> > +   return (mbus_code == MEDIA_BUS_FMT_SGBRG10_1X10);
> > +   case V4L2_PIX_FMT_SGRBG10:
> > +   return (mbus_code == MEDIA_BUS_FMT_SGRBG10_1X10);
> > +   case V4L2_PIX_FMT_SRGGB10:
> > +   return (mbus_code == MEDIA_BUS_FMT_SRGGB10_1X10);
> > +   case V4L2_PIX_FMT_SBGGR12:
> > +   return (mbus_code == MEDIA_BUS_FMT_SBGGR12_1X12);
> > +   case V4L2_PIX_FMT_SGBRG12:
> > +   return (mbus_code == MEDIA_BUS_FMT_SGBRG12_1X12);
> > +   case V4L2_PIX_FMT_SGRBG12:
> > +   return (mbus_code == MEDIA_BUS_FMT_SGRBG12_1X12);
> > +   case V4L2_PIX_FMT_SRGGB12:
> > +   return (mbus_code == MEDIA_BUS_FMT_SRGGB12_1X12);
> > +
> > +  

Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
Hi Baruch,

2018-03-08 20:02 GMT+08:00 Baruch Siach :
> Hi Jacob,
>
> On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
>> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399
>> SoC.
>>
>> Wiki Pages:
>> http://opensource.rock-chips.com/wiki_Rockchip-isp1
>>
>> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting
>> tomasz's patches.
>
> Which tree is this series based on? On top of v4.16-rc4 I get the build
> failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not even
> in media_tree.git.
>

This series is based on v4.16-rc4 with below patch.
https://patchwork.kernel.org/patch/9792001/


> drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did 
> you mean ‘vidioc_enum_fmt_meta_cap’?
>   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>^~~~
>vidioc_enum_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>   ^~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did you 
> mean ‘vidioc_g_fmt_meta_cap’?
>   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^
>vidioc_g_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did you 
> mean ‘vidioc_s_fmt_meta_cap’?
>   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^
>vidioc_s_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const 
> struct v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did you 
> mean ‘vidioc_try_fmt_meta_cap’?
>   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>^~~
>vidioc_try_fmt_meta_cap
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
> initialization from incompatible pointer type 
> [-Werror=incompatible-pointer-types]
>   .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
>  ^~~~
> drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
> initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
> drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> ‘rkisp1_params_init_vb2_queue’:
> drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: error: 
> ‘V4L2_BUF_TYPE_META_OUTPUT’ undeclared (first use in this function); did you 
> mean ‘V4L2_BUF_TYPE_SDR_OUTPUT’?
>   q->type = V4L2_BUF_TYPE_META_OUTPUT;
> ^
> V4L2_BUF_TYPE_SDR_OUTPUT
> drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: note: each 
> undeclared identifier is reported only once for each function it appears in
>   CC  drivers/media/platform/rockchip/isp1/mipi_dphy_sy.o
> drivers/media/platform/rockchip/isp1/isp_params.c: In function 
> ‘rkisp1_register_params_vdev’:
> drivers/media/platform/rockchip/isp1/isp_params.c:1507:43: error: 
> ‘V4L2_CAP_META_OUTPUT’ undeclared (first use in this function); did you mean 
> ‘V4L2_CAP_VBI_OUTPUT’?
>   vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT;
>^~~~
>V4L2_CAP_VBI_OUTPUT
>
> Thanks,
> baruch
>
>> Jacob Chen (12):
>>   media: doc: add document for rkisp1 meta buffer format
>>   media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
>>   media: rkisp1: add Rockchip ISP1 subdev driver
>>   media: rkisp1: add ISP1 statistics driver
>>   media: rkisp1: add ISP1 params driver
>>   media: rkisp1: add capture device driver
>>  

Re: [PATCH] dvb: Save port number and provide sysfs attributes to pass values to udev

2018-03-08 Thread David Howells
Mauro Carvalho Chehab  wrote:

> > +   dvb_class->dev_groups = dvb_class_groups,
> > dvb_class->dev_uevent = dvb_uevent;
> > dvb_class->devnode = dvb_devnode;
> > return 0;
> 
> The patch itself looks good, but I'm not seeing any documentation.

I should probably add something to Documentation/media/dvb-drivers/udev.rst

> You should likely add something to Documentation/ABI

Any suggestions as to where to add stuff in there?  The README there leaves
a lot to be desired as to how to name elements - for instance, DVB devices can
be seen through /sys/class/ and /sys/devices/.

I could put it in sys-class-dvb or sys-devices-dvb - or, arguably, both.

> and to the DVB uAPI (Documentation/media/uapi/dvb).

Likewise, any suggestion as to where in here?  As far as I can tell, the docs
here don't currently mention sysfs at all.  I'm guessing I'll need to create a
file specifically to talk about how to use this stuff with udev.

> > +   port->frontends.adapter.port_num = port->nr;
> > +
> 
> Doing it for each multi-adapter device is something that bothers
> me. The better would be if we could move this to the DVB Kernel,
> in order to not need to check/fix every driver.

I'm not sure how achievable that is: *port in this case is a private
cx23885-specific structure object.

> If, otherwise, this is not possible, then we need a patch fixing port_num
> for all drivers that support multiple adapters.
> 
> Also, the risk of forgetting it seems high. So, perhaps we should
> add a new parameter to some function (like at dvb_register_device
> or at dvb_register_frontend), in order to make the port number
> a mandatory attribute.

Hmmm...  The cx23885 driver doesn't call either of these functions as far as I
can tell - at least, not directly.  Maybe by vb2_dvb_register_bus()?

Note that these attribute files appear for the demux, dvr and net directories
as well as for the frontend.

Hmmm... further, the port number is no longer getting through and all adapters
are showing port 0.  The MAC address works, though.  Maybe I should drop the
port number.

David


[PATCH] media: dvb-usb-v2: stop using coherent memory for URBs

2018-03-08 Thread Mauro Carvalho Chehab
There's no need to use coherent buffers there. So, let the
DVB core do the allocation. That should give some performance
gain outside x86.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb-v2/usb_urb.c | 17 -
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/usb_urb.c 
b/drivers/media/usb/dvb-usb-v2/usb_urb.c
index dce2b97efce4..b0499f95ec45 100644
--- a/drivers/media/usb/dvb-usb-v2/usb_urb.c
+++ b/drivers/media/usb/dvb-usb-v2/usb_urb.c
@@ -155,8 +155,7 @@ static int usb_urb_alloc_bulk_urbs(struct usb_data_stream 
*stream)
stream->props.u.bulk.buffersize,
usb_urb_complete, stream);
 
-   stream->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
-   stream->urb_list[i]->transfer_dma = stream->dma_addr[i];
+   stream->urb_list[i]->transfer_flags = URB_FREE_BUFFER;
stream->urbs_initialized++;
}
return 0;
@@ -187,13 +186,12 @@ static int usb_urb_alloc_isoc_urbs(struct usb_data_stream 
*stream)
urb->complete = usb_urb_complete;
urb->pipe = usb_rcvisocpipe(stream->udev,
stream->props.endpoint);
-   urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+   urb->transfer_flags = URB_ISO_ASAP | URB_FREE_BUFFER;
urb->interval = stream->props.u.isoc.interval;
urb->number_of_packets = stream->props.u.isoc.framesperurb;
urb->transfer_buffer_length = stream->props.u.isoc.framesize *
stream->props.u.isoc.framesperurb;
urb->transfer_buffer = stream->buf_list[i];
-   urb->transfer_dma = stream->dma_addr[i];
 
for (j = 0; j < stream->props.u.isoc.framesperurb; j++) {
urb->iso_frame_desc[j].offset = frame_offset;
@@ -212,11 +210,7 @@ static int usb_free_stream_buffers(struct usb_data_stream 
*stream)
if (stream->state & USB_STATE_URB_BUF) {
while (stream->buf_num) {
stream->buf_num--;
-   dev_dbg(>udev->dev, "%s: free buf=%d\n",
-   __func__, stream->buf_num);
-   usb_free_coherent(stream->udev, stream->buf_size,
- stream->buf_list[stream->buf_num],
- stream->dma_addr[stream->buf_num]);
+   stream->buf_list[stream->buf_num] = NULL;
}
}
 
@@ -236,9 +230,7 @@ static int usb_alloc_stream_buffers(struct usb_data_stream 
*stream, int num,
__func__,  num * size);
 
for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) {
-   stream->buf_list[stream->buf_num] = usb_alloc_coherent(
-   stream->udev, size, GFP_ATOMIC,
-   >dma_addr[stream->buf_num]);
+   stream->buf_list[stream->buf_num] = kzalloc(size, GFP_ATOMIC);
if (!stream->buf_list[stream->buf_num]) {
dev_dbg(>udev->dev, "%s: alloc buf=%d failed\n",
__func__, stream->buf_num);
@@ -250,7 +242,6 @@ static int usb_alloc_stream_buffers(struct usb_data_stream 
*stream, int num,
__func__, stream->buf_num,
stream->buf_list[stream->buf_num],
(long long)stream->dma_addr[stream->buf_num]);
-   memset(stream->buf_list[stream->buf_num], 0, size);
stream->state |= USB_STATE_URB_BUF;
}
 
-- 
2.14.3



[PATCH 1/2] media: dvbsky: use the new dvb_module_probe() API

2018-03-08 Thread Mauro Carvalho Chehab
Instead of repeating countless times a complex logic, use
the new dvb_module_probe()/dvb_module_release(), simplifying
the module.

That reduced about 15% at the module's size:

   textdata bss dec hex filename
   70831108  128203200b 
old/drivers/media/usb/dvb-usb-v2/dvbsky.o
   58171108  1269371b19 
new/drivers/media/usb/dvb-usb-v2/dvbsky.o

Tested with a DVBSky S960C DVB-S2 tuner (0572:960c)

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 390 +++---
 1 file changed, 119 insertions(+), 271 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c 
b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index 43eb82884555..416231bf381f 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -290,61 +290,44 @@ static int dvbsky_usb_read_status(struct dvb_frontend *fe,
return ret;
 }
 
-static const struct m88ds3103_config dvbsky_s960_m88ds3103_config = {
-   .i2c_addr = 0x68,
-   .clock = 2700,
-   .i2c_wr_max = 33,
-   .clock_out = 0,
-   .ts_mode = M88DS3103_TS_CI,
-   .ts_clk = 16000,
-   .ts_clk_pol = 0,
-   .agc = 0x99,
-   .lnb_hv_pol = 1,
-   .lnb_en_pol = 1,
-};
-
 static int dvbsky_s960_attach(struct dvb_usb_adapter *adap)
 {
struct dvbsky_state *state = adap_to_priv(adap);
struct dvb_usb_device *d = adap_to_d(adap);
-   int ret = 0;
-   /* demod I2C adapter */
-   struct i2c_adapter *i2c_adapter = NULL;
-   struct i2c_client *client;
-   struct i2c_board_info info;
+   struct i2c_adapter *i2c_adapter;
+   struct m88ds3103_platform_data m88ds3103_pdata = {};
struct ts2020_config ts2020_config = {};
-   memset(, 0, sizeof(struct i2c_board_info));
 
/* attach demod */
-   adap->fe[0] = dvb_attach(m88ds3103_attach,
-   _s960_m88ds3103_config,
-   >i2c_adap,
-   _adapter);
-   if (!adap->fe[0]) {
-   dev_err(>udev->dev, "dvbsky_s960_attach fail.\n");
-   ret = -ENODEV;
-   goto fail_attach;
-   }
+   m88ds3103_pdata.clk = 2700;
+   m88ds3103_pdata.i2c_wr_max = 33;
+   m88ds3103_pdata.clk_out = 0;
+   m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
+   m88ds3103_pdata.ts_clk = 16000;
+   m88ds3103_pdata.ts_clk_pol = 0;
+   m88ds3103_pdata.agc = 0x99;
+   m88ds3103_pdata.lnb_hv_pol = 1,
+   m88ds3103_pdata.lnb_en_pol = 1,
+
+   state->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
+  >i2c_adap,
+  0x68, _pdata);
+   if (!state->i2c_client_demod)
+   return -ENODEV;
+
+   adap->fe[0] = m88ds3103_pdata.get_dvb_frontend(state->i2c_client_demod);
+   i2c_adapter = m88ds3103_pdata.get_i2c_adapter(state->i2c_client_demod);
 
/* attach tuner */
ts2020_config.fe = adap->fe[0];
ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
-   strlcpy(info.type, "ts2020", I2C_NAME_SIZE);
-   info.addr = 0x60;
-   info.platform_data = _config;
-   request_module("ts2020");
-   client = i2c_new_device(i2c_adapter, );
-   if (client == NULL || client->dev.driver == NULL) {
-   dvb_frontend_detach(adap->fe[0]);
-   ret = -ENODEV;
-   goto fail_attach;
-   }
 
-   if (!try_module_get(client->dev.driver->owner)) {
-   i2c_unregister_device(client);
-   dvb_frontend_detach(adap->fe[0]);
-   ret = -ENODEV;
-   goto fail_attach;
+   state->i2c_client_tuner = dvb_module_probe("ts2020", NULL,
+  i2c_adapter,
+  0x60, _config);
+   if (!state->i2c_client_tuner) {
+   dvb_module_release(state->i2c_client_demod);
+   return -ENODEV;
}
 
/* delegate signal strength measurement to tuner */
@@ -359,10 +342,7 @@ static int dvbsky_s960_attach(struct dvb_usb_adapter *adap)
state->fe_set_voltage = adap->fe[0]->ops.set_voltage;
adap->fe[0]->ops.set_voltage = dvbsky_usb_set_voltage;
 
-   state->i2c_client_tuner = client;
-
-fail_attach:
-   return ret;
+   return 0;
 }
 
 static int dvbsky_usb_ci_set_voltage(struct dvb_frontend *fe,
@@ -412,80 +392,60 @@ static int dvbsky_ci_ctrl(void *priv, u8 read, int addr,
return ret;
 }
 
-static const struct m88ds3103_config dvbsky_s960c_m88ds3103_config = {
-   .i2c_addr = 0x68,
-   .clock = 2700,
-   .i2c_wr_max = 33,
-   .clock_out = 0,
-   .ts_mode = M88DS3103_TS_CI,
-   .ts_clk = 1,
-   .ts_clk_pol = 1,
-   .agc = 0x99,
-   .lnb_hv_pol = 0,
-   .lnb_en_pol = 1,
-};
-
 static int 

[PATCH 2/2] media: dvbsky: fix driver unregister logic

2018-03-08 Thread Mauro Carvalho Chehab
There's an user-after-free there, if the frontend is attached
via the new I2C way:

[  112.539806] usbcore: deregistering interface driver dvb_usb_dvbsky
[  112.568489] 
==
[  112.568600] BUG: KASAN: use-after-free in dvb_unregister_frontend+0x18/0xb0 
[dvb_core]
[  112.568610] Read of size 8 at addr 8803a6f61530 by task rmmod/2246

[  112.568622] CPU: 0 PID: 2246 Comm: rmmod Not tainted 4.16.0-rc4+ #103
[  112.568624] Hardware name:  /NUC5i7RYB, BIOS 
RYBDWi35.86A.0364.2017.0511.0949 05/11/2017
[  112.568625] Call Trace:
[  112.568631]  dump_stack+0x5c/0x7c
[  112.568636]  print_address_description+0x6a/0x270
[  112.568640]  kasan_report+0x258/0x380
[  112.568657]  ? dvb_unregister_frontend+0x18/0xb0 [dvb_core]
[  112.568673]  dvb_unregister_frontend+0x18/0xb0 [dvb_core]
[  112.568681]  dvb_usbv2_exit+0x156/0x4a0 [dvb_usb_v2]
[  112.568689]  dvb_usbv2_disconnect+0xa0/0x140 [dvb_usb_v2]
[  112.568694]  usb_unbind_interface+0xd8/0x3f0
[  112.568700]  device_release_driver_internal+0x1ce/0x2f0
[  112.568705]  driver_detach+0x66/0xc0
[  112.568709]  bus_remove_driver+0x86/0x150
[  112.568713]  usb_deregister+0x90/0x180
[  112.568718]  SyS_delete_module+0x293/0x330
[  112.568721]  ? free_module+0x330/0x330
[  112.568725]  ? _cond_resched+0x16/0x50
[  112.568729]  ? task_work_run+0x7d/0xd0
[  112.568732]  ? mem_cgroup_handle_over_high+0x1c/0xc0
[  112.568736]  ? free_module+0x330/0x330
[  112.568740]  do_syscall_64+0xe7/0x250
[  112.568744]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
[  112.568747] RIP: 0033:0x7facafa272a7
[  112.568749] RSP: 002b:7fffdea14cc8 EFLAGS: 0206 ORIG_RAX: 
00b0
[  112.568753] RAX: ffda RBX: 7fffdea14d28 RCX: 7facafa272a7
[  112.568755] RDX: 000a RSI: 0800 RDI: 5599557337c8
[  112.568756] RBP: 559955733760 R08: 000a R09: 
[  112.568758] R10: 7facafaa0280 R11: 0206 R12: 7fffdea14ef0
[  112.568761] R13: 7fffdea16eac R14: 559955733260 R15: 559955733760

[  112.568808] Allocated by task 638:
[  112.568816]  kasan_kmalloc+0xa0/0xd0
[  112.568820]  kmem_cache_alloc_trace+0x114/0x230
[  112.568826]  m88ds3103_probe+0x9a/0x643 [m88ds3103]
[  112.568830]  i2c_device_probe+0x2e9/0x3c0
[  112.568833]  driver_probe_device+0x46e/0x6a0
[  112.568836]  bus_for_each_drv+0xd6/0x130
[  112.568838]  __device_attach+0x166/0x1f0
[  112.568841]  bus_probe_device+0xea/0x110
[  112.568844]  device_add+0x6a3/0x9f0
[  112.568847]  i2c_new_device+0x28f/0x5c0
[  112.568861]  dvb_module_probe+0x91/0x110 [dvb_core]
[  112.568867]  dvbsky_s960c_attach+0x1c4/0x460 [dvb_usb_dvbsky]
[  112.568873]  dvb_usbv2_probe+0x1191/0x1950 [dvb_usb_v2]
[  112.568877]  usb_probe_interface+0x1b3/0x430
[  112.568880]  driver_probe_device+0x46e/0x6a0
[  112.568882]  __driver_attach+0xeb/0x110
[  112.568885]  bus_for_each_dev+0xe4/0x140
[  112.56]  bus_add_driver+0x249/0x380
[  112.568891]  driver_register+0xc6/0x170
[  112.568893]  usb_register_driver+0xec/0x200
[  112.568896]  do_one_initcall+0x8f/0x1ee
[  112.568900]  do_init_module+0xde/0x320
[  112.568902]  load_module+0x3ed0/0x4850
[  112.568905]  SYSC_finit_module+0x192/0x1c0
[  112.568908]  do_syscall_64+0xe7/0x250
[  112.568911]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2

[  112.568916] Freed by task 2246:
[  112.568923]  __kasan_slab_free+0x136/0x180
[  112.568925]  kfree+0xa5/0x1e0
[  112.568931]  m88ds3103_remove+0x42/0x60 [m88ds3103]
[  112.568934]  i2c_device_remove+0x72/0xd0
[  112.568937]  device_release_driver_internal+0x1ce/0x2f0
[  112.568940]  bus_remove_device+0x197/0x270
[  112.568942]  device_del+0x239/0x550
[  112.568945]  device_unregister+0x16/0x70
[  112.568949]  dvbsky_exit+0x4c/0x70 [dvb_usb_dvbsky]
[  112.568955]  dvb_usbv2_disconnect+0x98/0x140 [dvb_usb_v2]
[  112.568958]  usb_unbind_interface+0xd8/0x3f0
[  112.568961]  device_release_driver_internal+0x1ce/0x2f0
[  112.568964]  driver_detach+0x66/0xc0
[  112.568967]  bus_remove_driver+0x86/0x150
[  112.568970]  usb_deregister+0x90/0x180
[  112.568973]  SyS_delete_module+0x293/0x330
[  112.568976]  do_syscall_64+0xe7/0x250
[  112.568979]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2

[  112.568985] The buggy address belongs to the object at 8803a6f61100
which belongs to the cache kmalloc-2048 of size 2048
[  112.568998] The buggy address is located 1072 bytes inside of
2048-byte region [8803a6f61100, 8803a6f61900)
[  112.569008] The buggy address belongs to the page:
[  112.569015] page:ea000e9bd800 count:1 mapcount:0 
mapping: index:0x0 compound_mapcount: 0
[  112.569025] flags: 0x17ffe08100(slab|head)
[  112.569034] raw: 0017ffe08100   
0001000f000f
[  112.569044] raw: ea000ee2d000 00050005 880407002a80 

[  112.569053] page dumped because: kasan: bad access detected

[  

[PATCH v5 2/2] media: video-i2c: add video-i2c driver

2018-03-08 Thread Matt Ranostay
There are several thermal sensors that only have a low-speed bus
interface but output valid video data. This patchset enables support
for the AMG88xx "Grid-Eye" sensor family.

Signed-off-by: Matt Ranostay 
---
 MAINTAINERS   |   6 +
 drivers/media/i2c/Kconfig |   9 +
 drivers/media/i2c/Makefile|   1 +
 drivers/media/i2c/video-i2c.c | 558 ++
 4 files changed, 574 insertions(+)
 create mode 100644 drivers/media/i2c/video-i2c.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e03a130902cd..4d794e78a5ce 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14876,6 +14876,12 @@ L: linux-media@vger.kernel.org
 S: Maintained
 F: drivers/media/platform/video-mux.c
 
+VIDEO I2C POLLING DRIVER
+M: Matt Ranostay 
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/i2c/video-i2c.c
+
 VIDEOBUF2 FRAMEWORK
 M: Pawel Osciak 
 M: Marek Szyprowski 
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index d7bba0e3f30e..22f7c1e40c4e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -963,6 +963,15 @@ config VIDEO_M52790
 
 To compile this driver as a module, choose M here: the
 module will be called m52790.
+
+config VIDEO_I2C
+   tristate "I2C transport video support"
+   depends on VIDEO_V4L2 && I2C
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enable the I2C transport video support which supports the
+ following:
+  * Panasonic AMG88xx Grid-Eye Sensors
 endmenu
 
 menu "Sensors used on soc_camera driver"
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index cc30178e3347..6cc5f0f7e4fc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_VIDEO_LM3646)+= lm3646.o
 obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
 obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
 obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
+obj-$(CONFIG_VIDEO_I2C)+= video-i2c.o
 obj-$(CONFIG_VIDEO_ML86V7667)  += ml86v7667.o
 obj-$(CONFIG_VIDEO_OV2659) += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
new file mode 100644
index ..a30f758f506b
--- /dev/null
+++ b/drivers/media/i2c/video-i2c.c
@@ -0,0 +1,558 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * video-i2c.c - Support for I2C transport video devices
+ *
+ * Copyright (C) 2018 Matt Ranostay 
+ *
+ * Supported:
+ * - Panasonic AMG88xx Grid-Eye Sensors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VIDEO_I2C_DRIVER   "video-i2c"
+#define MAX_BUFFER_SIZE128
+
+struct video_i2c_chip;
+
+struct video_i2c_buffer {
+   struct vb2_v4l2_buffer vb;
+   struct list_head list;
+};
+
+struct video_i2c_data {
+   struct i2c_client *client;
+   const struct video_i2c_chip *chip;
+   struct mutex lock;
+   spinlock_t slock;
+   struct mutex queue_lock;
+
+   struct v4l2_device v4l2_dev;
+   struct video_device vdev;
+   struct vb2_queue vb_vidq;
+
+   struct task_struct *kthread_vid_cap;
+   struct list_head vid_cap_active;
+};
+
+static struct v4l2_fmtdesc amg88xx_format = {
+   .pixelformat = V4L2_PIX_FMT_Y12,
+};
+
+static struct v4l2_frmsize_discrete amg88xx_size = {
+   .width = 8,
+   .height = 8,
+};
+
+struct video_i2c_chip {
+   /* video dimensions */
+   const struct v4l2_fmtdesc *format;
+   const struct v4l2_frmsize_discrete *size;
+
+   /* max frames per second */
+   unsigned int max_fps;
+
+   /* pixel buffer size */
+   unsigned int buffer_size;
+
+   /* pixel size in bits */
+   unsigned int bpp;
+
+   /* xfer function */
+   int (*xfer)(struct video_i2c_data *data, char *buf);
+};
+
+static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
+{
+   struct i2c_client *client = data->client;
+   struct i2c_msg msg[2];
+   u8 reg = 0x80;
+   int ret;
+
+   msg[0].addr = client->addr;
+   msg[0].flags = 0;
+   msg[0].len = 1;
+   msg[0].buf  = (char *) 
+
+   msg[1].addr = client->addr;
+   msg[1].flags = I2C_M_RD;
+   msg[1].len = data->chip->buffer_size;
+   msg[1].buf = (char *) buf;
+
+   ret = i2c_transfer(client->adapter, msg, 2);
+
+   return (ret == 2) ? 0 : -EIO;
+}
+
+#define AMG88XX0
+
+static const struct video_i2c_chip video_i2c_chip[] = {
+   [AMG88XX] = {
+   .size   = _size,
+   .format = _format,
+   .max_fps= 10,
+   .buffer_size= 128,
+   

[PATCH v5 1/2] media: dt-bindings: Add bindings for panasonic,amg88xx

2018-03-08 Thread Matt Ranostay
Define the device tree bindings for the panasonic,amg88xx i2c
video driver.

Cc: devicet...@vger.kernel.org
Reviewed-by: Rob Herring 
Signed-off-by: Matt Ranostay 
---
 .../bindings/media/i2c/panasonic,amg88xx.txt  | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt 
b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
new file mode 100644
index ..4a3181a3dd7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
@@ -0,0 +1,19 @@
+* Panasonic AMG88xx
+
+The Panasonic family of AMG88xx Grid-Eye sensors allow recording
+8x8 10Hz video which consists of thermal datapoints
+
+Required Properties:
+ - compatible : Must be "panasonic,amg88xx"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   amg88xx@69 {
+   compatible = "panasonic,amg88xx";
+   reg = <0x69>;
+   };
+   ...
+   };
-- 
2.14.1



[PATCH v5 0/2] media: video-i2c: add video-i2c driver support

2018-03-08 Thread Matt Ranostay
Add support for video-i2c polling driver

Changes from v1:
* Switch to SPDX tags versus GPLv2 license text
* Remove unneeded zeroing of data structures
* Add video_i2c_try_fmt_vid_cap call in video_i2c_s_fmt_vid_cap function

Changes from v2:
* Add missing linux/kthread.h include that broke x86_64 build

Changes from v3:
* Add devicetree binding documents
* snprintf check added
* switched to per chip support based on devicetree or i2c client id
* add VB2_DMABUF to io_modes
* added entry to MAINTAINERS file switched to per chip support based on 
devicetree or i2c client id

Changes from v4:
* convert pointer from of_device_get_match_data() to long instead of int to 
avoid compiler warning

Matt Ranostay (2):
  media: dt-bindings: Add bindings for panasonic,amg88xx
  media: video-i2c: add video-i2c driver

 .../bindings/media/i2c/panasonic,amg88xx.txt   |  19 +
 MAINTAINERS|   6 +
 drivers/media/i2c/Kconfig  |   9 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/video-i2c.c  | 558 +
 5 files changed, 593 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt
 create mode 100644 drivers/media/i2c/video-i2c.c

-- 
2.14.1



[GIT PULL FOR v4.17] RC imon and sunxi fixes

2018-03-08 Thread Sean Young
Hi Mauro,

There is a new driver for older, raw IR imon devices and a raw decoder for
the imon protocol for imon pad remotes.

Thanks,

Sean

The following changes since commit 50718972f555cc7a061162003f1bc59ef6635db1:

  media: em28xx-cards: fix em28xx_duplicate_dev() (2018-03-08 05:23:45 -0500)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.17c

for you to fetch changes up to f637937e5b05a9221deea488f2f329efcb8df59e:

  media: imon: rename protocol from other to imon (2018-03-08 11:22:53 +)


Philipp Rossak (2):
  media: rc: update sunxi-ir driver to get base clock frequency from 
devicetree
  media: dt: bindings: Update binding documentation for sunxi IR controller

Sean Young (6):
  Revert "[media] staging: lirc_imon: port remaining usb ids to imon and 
remove"
  media: rc: add keymap for iMON RSC remote
  media: rc: new driver for early iMon device
  media: rc: oops in ir_timer_keyup after device unplug
  media: rc: add new imon protocol decoder and encoder
  media: imon: rename protocol from other to imon

 .../devicetree/bindings/media/sunxi-ir.txt |   3 +
 MAINTAINERS|   7 +
 drivers/media/rc/Kconfig   |  21 +++
 drivers/media/rc/Makefile  |   2 +
 drivers/media/rc/imon.c| 170 +++---
 drivers/media/rc/imon_raw.c| 199 +
 drivers/media/rc/ir-imon-decoder.c | 193 
 drivers/media/rc/keymaps/Makefile  |   1 +
 drivers/media/rc/keymaps/rc-imon-pad.c |   3 +-
 drivers/media/rc/keymaps/rc-imon-rsc.c |  81 +
 drivers/media/rc/rc-core-priv.h|   6 +
 drivers/media/rc/rc-main.c |   9 +-
 drivers/media/rc/sunxi-cir.c   |  19 +-
 include/media/rc-map.h |   9 +-
 include/uapi/linux/lirc.h  |   2 +
 15 files changed, 568 insertions(+), 157 deletions(-)
 create mode 100644 drivers/media/rc/imon_raw.c
 create mode 100644 drivers/media/rc/ir-imon-decoder.c
 create mode 100644 drivers/media/rc/keymaps/rc-imon-rsc.c


[PATCH RESEND 2/2 v6] uvcvideo: handle control pipe protocol STALLs

2018-03-08 Thread Guennadi Liakhovetski
When a command ends up in a STALL on the control pipe, use the Request
Error Code control to provide a more precise error information to the
user.

Signed-off-by: Guennadi Liakhovetski 
---
 drivers/media/usb/uvc/uvc_video.c | 59 +++
 1 file changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c 
b/drivers/media/usb/uvc/uvc_video.c
index 2fc0bf2..cfcc4861 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -34,15 +34,59 @@ static int __uvc_query_ctrl(struct uvc_device *dev, __u8 
query, __u8 unit,
__u8 intfnum, __u8 cs, void *data, __u16 size,
int timeout)
 {
-   __u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
+   __u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE, tmp, error;
unsigned int pipe;
+   int ret;
 
pipe = (query & 0x80) ? usb_rcvctrlpipe(dev->udev, 0)
  : usb_sndctrlpipe(dev->udev, 0);
type |= (query & 0x80) ? USB_DIR_IN : USB_DIR_OUT;
 
-   return usb_control_msg(dev->udev, pipe, query, type, cs << 8,
+   ret = usb_control_msg(dev->udev, pipe, query, type, cs << 8,
unit << 8 | intfnum, data, size, timeout);
+
+   if (ret != -EPIPE)
+   return ret;
+
+   tmp = *(u8 *)data;
+
+   pipe = usb_rcvctrlpipe(dev->udev, 0);
+   type = USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN;
+   ret = usb_control_msg(dev->udev, pipe, UVC_GET_CUR, type,
+ UVC_VC_REQUEST_ERROR_CODE_CONTROL << 8,
+ unit << 8 | intfnum, data, 1, timeout);
+   error = *(u8 *)data;
+   *(u8 *)data = tmp;
+
+   if (ret < 0)
+   return ret;
+
+   if (!ret)
+   return -EINVAL;
+
+   uvc_trace(UVC_TRACE_CONTROL, "Control error %u\n", error);
+
+   switch (error) {
+   case 0:
+   /* Cannot happen - we received a STALL */
+   return -EPIPE;
+   case 1: /* Not ready */
+   return -EAGAIN;
+   case 2: /* Wrong state */
+   return -EILSEQ;
+   case 3: /* Power */
+   return -EREMOTE;
+   case 4: /* Out of range */
+   return -ERANGE;
+   case 5: /* Invalid unit */
+   case 6: /* Invalid control */
+   case 7: /* Invalid Request */
+   case 8: /* Invalid value within range */
+   default: /* reserved or unknown */
+   break;
+   }
+
+   return -EINVAL;
 }
 
 static const char *uvc_query_name(__u8 query)
@@ -80,7 +124,7 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 
unit,
uvc_printk(KERN_ERR, "Failed to query (%s) UVC control %u on "
"unit %u: %d (exp. %u).\n", uvc_query_name(query), cs,
unit, ret, size);
-   return -EIO;
+   return ret < 0 ? ret : -EIO;
}
 
return 0;
@@ -203,13 +247,15 @@ static int uvc_get_video_ctrl(struct uvc_streaming 
*stream,
uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non "
"compliance - GET_DEF(PROBE) not supported. "
"Enabling workaround.\n");
-   ret = -EIO;
+   if (ret >= 0)
+   ret = -EIO;
goto out;
} else if (ret != size) {
uvc_printk(KERN_ERR, "Failed to query (%u) UVC %s control : "
"%d (exp. %u).\n", query, probe ? "probe" : "commit",
ret, size);
-   ret = -EIO;
+   if (ret >= 0)
+   ret = -EIO;
goto out;
}
 
@@ -290,7 +336,8 @@ static int uvc_set_video_ctrl(struct uvc_streaming *stream,
uvc_printk(KERN_ERR, "Failed to set UVC %s control : "
"%d (exp. %u).\n", probe ? "probe" : "commit",
ret, size);
-   ret = -EIO;
+   if (ret >= 0)
+   ret = -EIO;
}
 
kfree(data);
-- 
1.9.3


[PATCH RESEND 1/2 v6] uvcvideo: send a control event when a Control Change interrupt arrives

2018-03-08 Thread Guennadi Liakhovetski
UVC defines a method of handling asynchronous controls, which sends a
USB packet over the interrupt pipe. This patch implements support for
such packets by sending a control event to the user. Since this can
involve USB traffic and, therefore, scheduling, this has to be done
in a work queue.

Signed-off-by: Guennadi Liakhovetski 
---
 drivers/media/usb/uvc/uvc_ctrl.c   | 166 +
 drivers/media/usb/uvc/uvc_status.c | 111 ++---
 drivers/media/usb/uvc/uvc_v4l2.c   |   4 +-
 drivers/media/usb/uvc/uvcvideo.h   |  15 +++-
 include/uapi/linux/uvcvideo.h  |   2 +
 5 files changed, 269 insertions(+), 29 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 20397ab..2a592c2 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1222,30 +1223,134 @@ static void uvc_ctrl_send_event(struct uvc_fh *handle,
 {
struct v4l2_subscribed_event *sev;
struct v4l2_event ev;
+   bool autoupdate;
 
if (list_empty(>ev_subs))
return;
 
+   if (!handle) {
+   autoupdate = true;
+   sev = list_first_entry(>ev_subs,
+  struct v4l2_subscribed_event, node);
+   handle = container_of(sev->fh, struct uvc_fh, vfh);
+   } else {
+   autoupdate = false;
+   }
+
uvc_ctrl_fill_event(handle->chain, , ctrl, mapping, value, changes);
 
list_for_each_entry(sev, >ev_subs, node) {
if (sev->fh && (sev->fh != >vfh ||
(sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK) ||
-   (changes & V4L2_EVENT_CTRL_CH_FLAGS)))
+   (changes & V4L2_EVENT_CTRL_CH_FLAGS) || autoupdate))
v4l2_event_queue_fh(sev->fh, );
}
 }
 
-static void uvc_ctrl_send_slave_event(struct uvc_fh *handle,
-   struct uvc_control *master, u32 slave_id,
-   const struct v4l2_ext_control *xctrls, unsigned int xctrls_count)
+static void __uvc_ctrl_send_slave_event(struct uvc_fh *handle,
+   struct uvc_control *master, u32 slave_id)
 {
struct uvc_control_mapping *mapping = NULL;
struct uvc_control *ctrl = NULL;
u32 changes = V4L2_EVENT_CTRL_CH_FLAGS;
-   unsigned int i;
s32 val = 0;
 
+   __uvc_find_control(master->entity, slave_id, , , 0);
+   if (ctrl == NULL)
+   return;
+
+   if (__uvc_ctrl_get(handle->chain, ctrl, mapping, ) == 0)
+   changes |= V4L2_EVENT_CTRL_CH_VALUE;
+
+   uvc_ctrl_send_event(handle, ctrl, mapping, val, changes);
+}
+
+static void uvc_ctrl_status_event_work(struct work_struct *work)
+{
+   struct uvc_device *dev = container_of(work, struct uvc_device,
+ async_ctrl.work);
+   struct uvc_video_chain *chain;
+   struct uvc_ctrl_work *w = >async_ctrl;
+   struct uvc_control_mapping *mapping;
+   struct uvc_control *ctrl;
+   struct uvc_fh *handle;
+   __u8 *data;
+   unsigned int i;
+
+   spin_lock_irq(>lock);
+   data = w->data;
+   w->data = NULL;
+   chain = w->chain;
+   ctrl = w->ctrl;
+   handle = ctrl->handle;
+   ctrl->handle = NULL;
+   spin_unlock_irq(>lock);
+
+   if (mutex_lock_interruptible(>ctrl_mutex))
+   goto free;
+
+   list_for_each_entry(mapping, >info.mappings, list) {
+   s32 value = mapping->get(mapping, UVC_GET_CUR, data);
+
+   for (i = 0; i < ARRAY_SIZE(mapping->slave_ids); ++i) {
+   if (!mapping->slave_ids[i])
+   break;
+
+   __uvc_ctrl_send_slave_event(handle, ctrl,
+   mapping->slave_ids[i]);
+   }
+
+   if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
+   struct uvc_menu_info *menu = mapping->menu_info;
+   unsigned int i;
+
+   for (i = 0; i < mapping->menu_count; ++i, ++menu)
+   if (menu->value == value) {
+   value = i;
+   break;
+   }
+   }
+
+   uvc_ctrl_send_event(handle, ctrl, mapping, value,
+   V4L2_EVENT_CTRL_CH_VALUE);
+   }
+
+   mutex_unlock(>ctrl_mutex);
+
+free:
+   kfree(data);
+}
+
+void uvc_ctrl_status_event(struct uvc_video_chain *chain,
+  struct uvc_control *ctrl, __u8 *data, size_t len)
+{
+   struct uvc_device *dev = chain->dev;
+   struct uvc_ctrl_work *w = >async_ctrl;
+
+   if (list_empty(>info.mappings))
+   return;
+

[PATCH RESEND 0/2 v6] uvcvideo: asynchronous controls

2018-03-08 Thread Guennadi Liakhovetski
This is an update of the two patches, adding asynchronous control
support to the uvcvideo driver. If a control is sent, while the camera
is still processing an earlier control, it will generate a protocol
STALL condition on the control pipe.

Thanks
Guennadi

Guennadi Liakhovetski (2):
  uvcvideo: send a control event when a Control Change interrupt arrives
  uvcvideo: handle control pipe protocol STALLs

 drivers/media/usb/uvc/uvc_ctrl.c   | 166 +
 drivers/media/usb/uvc/uvc_status.c | 111 ++---
 drivers/media/usb/uvc/uvc_v4l2.c   |   4 +-
 drivers/media/usb/uvc/uvc_video.c  |  59 +++--
 drivers/media/usb/uvc/uvcvideo.h   |  15 +++-
 include/uapi/linux/uvcvideo.h  |   2 +
 6 files changed, 322 insertions(+), 35 deletions(-)

-- 
1.9.3


Re: Patch review

2018-03-08 Thread Mauro Carvalho Chehab
Em Wed, 28 Feb 2018 17:21:27 +0200
Laurent Pinchart  escreveu:

> Hi Guennadi,
> 
> On Wednesday, 28 February 2018 17:07:00 EET Guennadi Liakhovetski wrote:
> > Hi,
> > 
> > I know the "development process and responsibilities" was the main topic
> > during the last media summit. Unfortunately I haven't attended it, from
> > the etherpad notes I also cannot quite conclude what decisions have been
> > made. Have any measures been discussed and agreed upon for cases, when
> > patches don't get reviewed for many months, adding up to more than a year
> > (in this specific case the first version submitted in June 2016)?  
> 
> I assume you're talking about the "[PATCH 0/2 v6] uvcvideo: asynchronous 
> controls" series, is that correct ?

What's the situation of such patch review? In case you doesn't have the
original e-mail anymore, I asked Guennadi on IRC to resubmit it, in order
to make easier for us to review/comment about any issues there, if any.

Regards,
Mauro

Thanks,
Mauro


Re: [PATCH] media: rc: meson-ir: add timeout on idle

2018-03-08 Thread Sean Young
Hi Matthias,

On Tue, Mar 06, 2018 at 06:41:22PM +0100, Matthias Reichl wrote:
> Meson doesn't seem to be able to generate timeout events
> in hardware. So install a software timer to generate the
> timeout events required by the decoders to prevent
> "ghost keypresses".
> 
> Signed-off-by: Matthias Reichl 
> ---
>  drivers/media/rc/meson-ir.c | 22 ++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c
> index f2204eb77e2a..f34c5836412b 100644
> --- a/drivers/media/rc/meson-ir.c
> +++ b/drivers/media/rc/meson-ir.c
> @@ -69,6 +69,7 @@ struct meson_ir {
>   void __iomem*reg;
>   struct rc_dev   *rc;
>   spinlock_t  lock;
> + struct timer_list timeout_timer;
>  };
>  
>  static void meson_ir_set_mask(struct meson_ir *ir, unsigned int reg,
> @@ -98,6 +99,10 @@ static irqreturn_t meson_ir_irq(int irqno, void *dev_id)
>   rawir.pulse = !!(status & STATUS_IR_DEC_IN);
>  
>   ir_raw_event_store(ir->rc, );
> +
> + mod_timer(>timeout_timer,
> + jiffies + nsecs_to_jiffies(ir->rc->timeout));
> +
>   ir_raw_event_handle(ir->rc);
>  
>   spin_unlock(>lock);
> @@ -105,6 +110,17 @@ static irqreturn_t meson_ir_irq(int irqno, void *dev_id)
>   return IRQ_HANDLED;
>  }
>  
> +static void meson_ir_timeout_timer(struct timer_list *t)
> +{
> + struct meson_ir *ir = from_timer(ir, t, timeout_timer);
> + DEFINE_IR_RAW_EVENT(rawir);
> +
> + rawir.timeout = true;
> + rawir.duration = ir->rc->timeout;
> + ir_raw_event_store(ir->rc, );
> + ir_raw_event_handle(ir->rc);
> +}

Now there can be concurrent access to the raw IR kfifo from the interrupt
handler and the timer. As there is a race condition between the timeout
timer and new IR arriving from the interrupt handler, the timeout could
end being generated after new IR and corrupting a message. There is very
similar functionality in rc-ir-raw.c (with a spinlock).

> +
>  static int meson_ir_probe(struct platform_device *pdev)
>  {
>   struct device *dev = >dev;
> @@ -145,7 +161,9 @@ static int meson_ir_probe(struct platform_device *pdev)
>   ir->rc->map_name = map_name ? map_name : RC_MAP_EMPTY;
>   ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
>   ir->rc->rx_resolution = US_TO_NS(MESON_TRATE);
> + ir->rc->min_timeout = 1;
>   ir->rc->timeout = MS_TO_NS(200);
> + ir->rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT;

Any idea why the default timeout is to 200ms? It seems very high.

>   ir->rc->driver_name = DRIVER_NAME;
>  
>   spin_lock_init(>lock);
> @@ -157,6 +175,8 @@ static int meson_ir_probe(struct platform_device *pdev)
>   return ret;
>   }
>  
> + timer_setup(>timeout_timer, meson_ir_timeout_timer, 0);
> +
>   ret = devm_request_irq(dev, irq, meson_ir_irq, 0, NULL, ir);
>   if (ret) {
>   dev_err(dev, "failed to request irq\n");
> @@ -198,6 +218,8 @@ static int meson_ir_remove(struct platform_device *pdev)
>   meson_ir_set_mask(ir, IR_DEC_REG1, REG1_ENABLE, 0);
>   spin_unlock_irqrestore(>lock, flags);
>  
> + del_timer_sync(>timeout_timer);
> +
>   return 0;
>  }
>  
> -- 
> 2.11.0

Would you mind trying this patch?

Thanks

Sean
---
>From f98f4fc05d743ac48a95694996985b2c1f0c4a4b Mon Sep 17 00:00:00 2001
From: Sean Young 
Date: Thu, 8 Mar 2018 14:42:44 +
Subject: [PATCH] media: rc: meson-ir: add timeout on idle

Meson doesn't seem to be able to generate timeout events in hardware. So
install a software timer to generate the timeout events required by the
decoders to prevent "ghost keypresses".

Signed-off-by: Sean Young 
---
 drivers/media/rc/meson-ir.c  |  3 +--
 drivers/media/rc/rc-ir-raw.c | 30 +++---
 include/media/rc-core.h  |  4 +++-
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c
index f2204eb77e2a..64b0aa4f4db7 100644
--- a/drivers/media/rc/meson-ir.c
+++ b/drivers/media/rc/meson-ir.c
@@ -97,8 +97,7 @@ static irqreturn_t meson_ir_irq(int irqno, void *dev_id)
status = readl_relaxed(ir->reg + IR_DEC_STATUS);
rawir.pulse = !!(status & STATUS_IR_DEC_IN);
 
-   ir_raw_event_store(ir->rc, );
-   ir_raw_event_handle(ir->rc);
+   ir_raw_event_store_with_timeout(ir->rc, );
 
spin_unlock(>lock);
 
diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
index 984bb82851f9..374f83105a23 100644
--- a/drivers/media/rc/rc-ir-raw.c
+++ b/drivers/media/rc/rc-ir-raw.c
@@ -92,7 +92,6 @@ int ir_raw_event_store_edge(struct rc_dev *dev, bool pulse)
 {
ktime_t now;
DEFINE_IR_RAW_EVENT(ev);
-   int rc = 0;
 
if (!dev->raw)
return -EINVAL;
@@ -101,8 +100,33 @@ int ir_raw_event_store_edge(struct rc_dev *dev, bool pulse)
ev.duration = 

[PATCH v8] media: imx258: Add imx258 camera sensor driver

2018-03-08 Thread Andy Yeh
Add a V4L2 sub-device driver for the Sony IMX258 image sensor.
This is a camera sensor using the I2C bus for control and the
CSI-2 bus for data.

Signed-off-by: Jason Chen 
Signed-off-by: Alan Chiang 
---
since v2:
-- Update the streaming function to remove SW_STANDBY in the beginning.
-- Adjust the delay time from 1ms to 12ms before set stream-on register.
since v3:
-- fix the sd.entity to make code be compiled on the mainline kernel.
since v4:
-- Enabled AG, DG, and Exposure time control correctly.
since v5:
-- Sensor vendor provided a new setting to fix different CLK issue
-- Add one more resolution for 1048x780, used for VGA streaming
since v6:
-- improve i2c write function to support writing 2 registers
-- Not Orring ret in update_digital_gain which lead to unintended error
since v7:
-- modified imx258_reg read / write function with a more portable way
-- arranged some format per suggestions


 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx258.c | 1324 
 4 files changed, 1343 insertions(+)
 create mode 100644 drivers/media/i2c/imx258.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a339bb5..9f75510 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12646,6 +12646,13 @@ S: Maintained
 F: drivers/ssb/
 F: include/linux/ssb/
 
+SONY IMX258 SENSOR DRIVER
+M: Sakari Ailus 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx258.c
+
 SONY IMX274 SENSOR DRIVER
 M: Leon Luo 
 L: linux-media@vger.kernel.org
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index fd01842..bcd4bf1 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -565,6 +565,17 @@ config VIDEO_APTINA_PLL
 config VIDEO_SMIAPP_PLL
tristate
 
+config VIDEO_IMX258
+   tristate "Sony IMX258 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the Sony
+ IMX258 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx258.
+
 config VIDEO_IMX274
tristate "Sony IMX274 sensor support"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 1b62639..4bf7d00 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -94,6 +94,7 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
 obj-$(CONFIG_VIDEO_ML86V7667)  += ml86v7667.o
 obj-$(CONFIG_VIDEO_OV2659) += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
+obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
new file mode 100644
index 000..814520f
--- /dev/null
+++ b/drivers/media/i2c/imx258.c
@@ -0,0 +1,1324 @@
+// Copyright (C) 2018 Intel Corporation
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX258_REG_VALUE_08BIT 1
+#define IMX258_REG_VALUE_16BIT 2
+#define IMX258_REG_VALUE_24BIT 3
+
+#define IMX258_REG_MODE_SELECT 0x0100
+#define IMX258_MODE_STANDBY0x00
+#define IMX258_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX258_REG_CHIP_ID 0x0016
+#define IMX258_CHIP_ID 0x0258
+
+/* V_TIMING internal */
+#define IMX258_REG_VTS 0x0340
+#define IMX258_VTS_30FPS   0x0c98
+#define IMX258_VTS_MAX 0x
+
+/*Frame Length Line*/
+#define IMX258_FLL_MIN 0x08a6
+#define IMX258_FLL_MAX 0x
+#define IMX258_FLL_STEP1
+#define IMX258_FLL_DEFAULT 0x0c98
+
+/* HBLANK control - read only */
+#define IMX258_PPL_DEFAULT 5352
+
+/* Exposure control */
+#define IMX258_REG_EXPOSURE0x0202
+#define IMX258_EXPOSURE_MIN4
+#define IMX258_EXPOSURE_STEP   1
+#define IMX258_EXPOSURE_DEFAULT0x640
+#define IMX258_EXPOSURE_MAX65535
+
+/* Analog gain control */
+#define IMX258_REG_ANALOG_GAIN 0x0204
+#define IMX258_ANA_GAIN_MIN0
+#define IMX258_ANA_GAIN_MAX0x1fff
+#define IMX258_ANA_GAIN_STEP   1
+#define IMX258_ANA_GAIN_DEFAULT0x0
+
+/* Digital gain control */
+#define IMX258_REG_GR_DIGITAL_GAIN 0x020e
+#define IMX258_REG_R_DIGITAL_GAIN  0x0210
+#define IMX258_REG_B_DIGITAL_GAIN  0x0212
+#define IMX258_REG_GB_DIGITAL_GAIN 0x0214
+#define IMX258_DGTL_GAIN_MIN   0
+#define 

Re: [PATCH] media: ov5640: fix frame interval enumeration

2018-03-08 Thread Hugues FRUCHET
Hi Mauro,

Thanks for review, I've just sent a v2 to rearrange code as per your 
suggestion and also add a NULL test case for mode even if this should 
not happen.

Best regards,
Hugues.

On 03/08/2018 11:46 AM, Mauro Carvalho Chehab wrote:
> Em Thu, 8 Mar 2018 07:39:09 -0300
> Mauro Carvalho Chehab  escreveu:
> 
>> Also, if this function starts returning NULL, I suspect that you also
>> need to change ov5640_s_frame_interval(), as currently it is called
>> at ov5640_s_frame_interval() as:
>>
>>  sensor->current_mode = ov5640_find_mode(sensor, frame_rate, mode->width,
>>  mode->height, true);
>>
>> without checking if the returned value is NULL. Setting
>> current_mode to NULL can cause oopses at ov5640_set_mode().
> 
> Actually, as ov5640_s_frame_interval() calls ov5640_try_fmt_internal()
> first. So, this should never happen.
> 
> 
> Thanks,
> Mauro
> 

[PATCH v2] media: ov5640: fix frame interval enumeration

2018-03-08 Thread Hugues Fruchet
Driver must reject frame interval enumeration of unsupported resolution.
This was detected by v4l2-compliance format ioctl test:
v4l2-compliance Format ioctls:
info: found 2 frameintervals for pixel format 4745504a and size 176x144
  fail: v4l2-test-formats.cpp(123):
   found frame intervals for invalid size 177x144
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL

Signed-off-by: Hugues Fruchet 
---
version 2:
  - revisit patch according to Mauro comments:
See https://www.mail-archive.com/linux-media@vger.kernel.org/msg127380.html

 drivers/media/i2c/ov5640.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 676f635..5c08124 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1397,8 +1397,12 @@ static int ov5640_set_virtual_channel(struct ov5640_dev 
*sensor)
break;
}
 
-   if (nearest && i < 0)
+   if (i < 0) {
+   /* no match */
+   if (!nearest)
+   return NULL;
mode = _mode_data[fr][0];
+   }
 
return mode;
 }
@@ -2381,8 +2385,14 @@ static int ov5640_s_frame_interval(struct v4l2_subdev 
*sd,
 
sensor->current_fr = frame_rate;
sensor->frame_interval = fi->interval;
-   sensor->current_mode = ov5640_find_mode(sensor, frame_rate, mode->width,
-   mode->height, true);
+   mode = ov5640_find_mode(sensor, frame_rate, mode->width,
+   mode->height, true);
+   if (!mode) {
+   ret = -EINVAL;
+   goto out;
+   }
+
+   sensor->current_mode = mode;
sensor->pending_mode_change = true;
 out:
mutex_unlock(>lock);
-- 
1.9.1



Re: [PATCH] media: em28xx-cards: fix em28xx_duplicate_dev()

2018-03-08 Thread Brad Love
Hi Dan,


On 2018-03-08 03:31, Dan Carpenter wrote:
> There is a double sizeof() typo here so we don't duplicate the struct
> properly.
>
> Fixes: be7fd3c3a8c5 ("media: em28xx: Hauppauge DualHD second tuner 
> functionality")
> Signed-off-by: Dan Carpenter 
>
> diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
> b/drivers/media/usb/em28xx/em28xx-cards.c
> index 6e8247849c4f..6e0e67d23876 100644
> --- a/drivers/media/usb/em28xx/em28xx-cards.c
> +++ b/drivers/media/usb/em28xx/em28xx-cards.c
> @@ -3515,7 +3515,7 @@ static int em28xx_duplicate_dev(struct em28xx *dev)
>   dev->dev_next = NULL;
>   return -ENOMEM;
>   }
> - memcpy(sec_dev, dev, sizeof(sizeof(*sec_dev)));
> + memcpy(sec_dev, dev, sizeof(*sec_dev));
>   /* Check to see next free device and mark as used */
>   do {
>   nr = find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS);


Ouch, good catch. Strangely everything still worked in 64bit builds, and
I've had no reports of wonky behaviour elsewhere.

Cheers,

Brad




Re: [RFCv4,13/21] media: videobuf2-v4l2: support for requests

2018-03-08 Thread Alexandre Courbot
On Thu, Mar 8, 2018 at 1:50 AM, Paul Kocialkowski
 wrote:
> Hi,
>
> On Tue, 2018-02-20 at 13:44 +0900, Alexandre Courbot wrote:
>> Add a new vb2_qbuf_request() (a request-aware version of vb2_qbuf())
>> that request-aware drivers can call to queue a buffer into a request
>> instead of directly into the vb2 queue if relevent.
>>
>> This function expects that drivers invoking it are using instances of
>> v4l2_request_entity and v4l2_request_entity_data to describe their
>> entity and entity data respectively.
>>
>> Also add the vb2_request_submit() helper function which drivers can
>> invoke in order to queue all the buffers previously queued into a
>> request into the regular vb2 queue.
>
> See a comment/proposal below about an issue I encountered when using
> multi-planar formats.
>
>> Signed-off-by: Alexandre Courbot 
>> ---
>>  .../media/common/videobuf2/videobuf2-v4l2.c   | 129
>> +-
>>  include/media/videobuf2-v4l2.h|  59 
>>  2 files changed, 187 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> b/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> index 6d4d184aa68e..0627c3339572 100644
>> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
>> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
>
> [...]
>
>> +#if IS_ENABLED(CONFIG_MEDIA_REQUEST_API)
>> +int vb2_qbuf_request(struct vb2_queue *q, struct v4l2_buffer *b,
>> +  struct media_request_entity *entity)
>> +{
>> + struct v4l2_request_entity_data *data;
>> + struct v4l2_vb2_request_buffer *qb;
>> + struct media_request *req;
>> + struct vb2_buffer *vb;
>> + int ret = 0;
>> +
>> + if (b->request_fd <= 0)
>> + return vb2_qbuf(q, b);
>> +
>> + if (!q->allow_requests)
>> + return -EINVAL;
>> +
>> + req = media_request_get_from_fd(b->request_fd);
>> + if (!req)
>> + return -EINVAL;
>> +
>> + data = to_v4l2_entity_data(media_request_get_entity_data(req,
>> entity));
>> + if (IS_ERR(data)) {
>> + ret = PTR_ERR(data);
>> + goto out;
>> + }
>> +
>> + mutex_lock(>lock);
>> +
>> + if (req->state != MEDIA_REQUEST_STATE_IDLE) {
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>> + ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
>> + if (ret)
>> + goto out;
>> +
>> + vb = q->bufs[b->index];
>> + switch (vb->state) {
>> + case VB2_BUF_STATE_DEQUEUED:
>> + break;
>> + case VB2_BUF_STATE_PREPARED:
>> + break;
>> + case VB2_BUF_STATE_PREPARING:
>> + dprintk(1, "buffer still being prepared\n");
>> + ret = -EINVAL;
>> + goto out;
>> + default:
>> + dprintk(1, "invalid buffer state %d\n", vb->state);
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>> + /* do we already have a buffer for this request in the queue?
>> */
>> + list_for_each_entry(qb, >queued_buffers, node) {
>> + if (qb->queue == q) {
>> + ret = -EBUSY;
>> + goto out;
>> + }
>> + }
>> +
>> + qb = kzalloc(sizeof(*qb), GFP_KERNEL);
>> + if (!qb) {
>> + ret = -ENOMEM;
>> + goto out;
>> + }
>> +
>> + /*
>> +  * TODO should be prepare the buffer here if needed, to
>> report errors
>> +  * early?
>> +  */
>> + qb->pre_req_state = vb->state;
>> + qb->queue = q;
>> + memcpy(>v4l2_buf, b, sizeof(*b));
>
> I am getting data corruption on qb->v4l2_buf.m.planes from this when
> using planar buffers, only after exiting the ioctl handler (i.e. when
> accessing this buffer later from the queue).
>
> I initially thought this was because the planes pointer was copied as-is
> from userspace, but Maxime Ripard suggested that this would have
> automatically triggered a visible fault in the kernel.
>
> Thus, my best guess is that the data is properly copied from userspace
> but freed when leaving the ioctl handler, which doesn't work our with
> the request API.
>
> A dirty fix that I came up with consists in re-allocating the planes
> buffer here and copying its contents from "b", so that it can live
> beyond the ioctl call.
>
> I am not too sure whether this should be fixed here or in the part of
> the v4l2 common code that frees this data. What do you think?

Oh, nice catch. Copying plane information indeed requires more work
than a dumb memcpy(). I suppose this should be handled here, but let
me come back to this after a good night of sleep. :)

Thanks! I will try to fix this tomorrow and push a temporary version
somewhere so you can move forward.

Alex.


Re: [RFCv4,19/21] media: vim2m: add request support

2018-03-08 Thread Alexandre Courbot
Hi Paul!

Thanks a lot for taking the time to try this! I am also working on
getting it to work with an actual driver, but you apparently found
rough edges that I missed.

On Thu, Mar 8, 2018 at 1:37 AM, Paul Kocialkowski
 wrote:
> Hi,
>
> First off, I'd like to take the occasion to say thank-you for your work.
> This is a major piece of plumbing that is required for me to add support
> for the Allwinner CedarX VPU hardware in upstream Linux. Other drivers,
> such as tegra-vde (that was recently merged in staging) are also badly
> in need of this API.
>
> I have a few comments based on my experience integrating this request
> API with the Cedrus VPU driver (and the associated libva backend), that
> also concern the vim2m driver.
>
> On Tue, 2018-02-20 at 13:44 +0900, Alexandre Courbot wrote:
>> Set the necessary ops for supporting requests in vim2m.
>>
>> Signed-off-by: Alexandre Courbot 
>> ---
>>  drivers/media/platform/Kconfig |  1 +
>>  drivers/media/platform/vim2m.c | 75
>> ++
>>  2 files changed, 76 insertions(+)
>>
>> diff --git a/drivers/media/platform/Kconfig
>> b/drivers/media/platform/Kconfig
>> index 614fbef08ddc..09be0b5f9afe 100644
>> --- a/drivers/media/platform/Kconfig
>> +++ b/drivers/media/platform/Kconfig
>
> [...]
>
>> +static int vim2m_request_submit(struct media_request *req,
>> + struct media_request_entity_data
>> *_data)
>> +{
>> + struct v4l2_request_entity_data *data;
>> +
>> + data = to_v4l2_entity_data(_data);
>
> We need to call v4l2_m2m_try_schedule here so that m2m scheduling can
> happen when only 2 buffers were queued and no other action was taken
> from usespace. In that scenario, m2m scheduling currently doesn't
> happen.

I don't think I understand the sequence of events that results in
v4l2_m2m_try_schedule() not being called. Do you mean something like:

*
* QBUF on output queue with request set
* QBUF on capture queue
* SUBMIT_REQUEST

?

The call to vb2_request_submit() right after should trigger
v4l2_m2m_try_schedule(), since the buffers associated to the request
will enter the vb2 queue and be passed to the m2m framework, which
will then call v4l2_m2m_try_schedule(). Or maybe you are thinking
about a different sequence of events?

>
> However, this requires access to the m2m context, which is not easy to
> get from req or _data. I'm not sure that some container_of magic would
> even do the trick here.

data_->entity will give you a pointer to the media_request_entity,
which is part of vim2m_ctx. You can thus get the m2m context by doing
container_of(data_->entity, struct vim2m_ctx, req_entity). See
vim2m_entity_data_alloc() for an example.

>
>> + return vb2_request_submit(data);
>
> vb2_request_submit does not lock the associated request mutex although
> it accesses the associated queued buffers list, which I believe this
> mutex is supposed to protect.

After a request is submitted, the data protected by the mutex can only
be accessed by the driver when it processes the request. It cannot be
modified concurrently, so I think we are safe here.

I am also wondering whether the ioctl locking doesn't make the request
locking redundant. Request information can only be modified and
accessed through ioctls until it is submitted, and after that there
are no concurrent accesses. I need to think a bit more about it
though.

Cheers,
Alex.

>
> We could either wrap this call with media_request_lock(req) and
> media_request_unlock(req) or have the lock in the function itself, which
> would require passing it the req pointer.
>
> The latter would probably be safer for future use of the function.
>
>> +}
>> +
>> +static const struct media_request_entity_ops vim2m_request_entity_ops
>> = {
>> + .data_alloc = vim2m_entity_data_alloc,
>> + .data_free  = v4l2_request_entity_data_free,
>> + .submit = vim2m_request_submit,
>> +};
>> +
>>  /*
>>   * File operations
>>   */
>> @@ -900,6 +967,9 @@ static int vim2m_open(struct file *file)
>>   ctx->dev = dev;
>>   hdl = >hdl;
>>   v4l2_ctrl_handler_init(hdl, 4);
>> + v4l2_request_entity_init(>req_entity,
>> _request_entity_ops,
>> +  >dev->vfd);
>> + ctx->fh.entity = >req_entity.base;
>>   v4l2_ctrl_new_std(hdl, _ctrl_ops, V4L2_CID_HFLIP, 0, 1,
>> 1, 0);
>>   v4l2_ctrl_new_std(hdl, _ctrl_ops, V4L2_CID_VFLIP, 0, 1,
>> 1, 0);
>>   v4l2_ctrl_new_custom(hdl, _ctrl_trans_time_msec, NULL);
>> @@ -999,6 +1069,9 @@ static int vim2m_probe(struct platform_device
>> *pdev)
>>   if (!dev)
>>   return -ENOMEM;
>>
>> + v4l2_request_mgr_init(>req_mgr, >vfd,
>> +   _request_ops);
>> +
>>   spin_lock_init(>irqlock);
>>
>>   ret = v4l2_device_register(>dev, >v4l2_dev);
>> @@ -1012,6 +1085,7 @@ static int vim2m_probe(struct platform_device
>> *pdev)
>>   vfd = >vfd;
>>   vfd->lock = 

[PATCH v2 2/3] media: vb2-core: document the REQUEUEING state

2018-03-08 Thread Luca Ceresoli
VB2_BUF_STATE_REQUEUEING is accepted by vb2_buffer_done() but not
documented, so add it along with notes about calls in interrupt
context.

Signed-off-by: Luca Ceresoli 
Cc: Laurent Pinchart 
Cc: Pawel Osciak 
Cc: Marek Szyprowski 
Cc: Kyungmin Park 
Cc: Mauro Carvalho Chehab 

---
Changes v1 -> v2: none.
---
 include/media/videobuf2-core.h | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index f1a479060f9e..f2887d3c 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -358,12 +358,12 @@ struct vb2_buffer {
  * driver can return an error if hardware fails, in that
  * case all buffers that have been already given by
  * the @buf_queue callback are to be returned by the driver
- * by calling vb2_buffer_done() with %VB2_BUF_STATE_QUEUED.
- * If you need a minimum number of buffers before you can
- * start streaming, then set
- * _queue->min_buffers_needed. If that is non-zero then
- * @start_streaming won't be called until at least that
- * many buffers have been queued up by userspace.
+ * by calling vb2_buffer_done() with %VB2_BUF_STATE_QUEUED
+ * or %VB2_BUF_STATE_REQUEUEING. If you need a minimum
+ * number of buffers before you can start streaming, then
+ * set _queue->min_buffers_needed. If that is non-zero
+ * then @start_streaming won't be called until at least
+ * that many buffers have been queued up by userspace.
  * @stop_streaming:called when 'streaming' state must be disabled; driver
  * should stop any DMA transactions or wait until they
  * finish and give back all buffers it got from _queue
@@ -601,8 +601,9 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int 
plane_no);
  * @state: state of the buffer, as defined by  vb2_buffer_state.
  * Either %VB2_BUF_STATE_DONE if the operation finished
  * successfully, %VB2_BUF_STATE_ERROR if the operation finished
- * with an error or %VB2_BUF_STATE_QUEUED if the driver wants to
- * requeue buffers.
+ * with an error or any of %VB2_BUF_STATE_QUEUED or
+ * %VB2_BUF_STATE_REQUEUEING if the driver wants to
+ * requeue buffers (see below).
  *
  * This function should be called by the driver after a hardware operation on
  * a buffer is finished and the buffer may be returned to userspace. The driver
@@ -613,7 +614,12 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int 
plane_no);
  * While streaming a buffer can only be returned in state DONE or ERROR.
  * The _ops->start_streaming op can also return them in case the DMA engine
  * cannot be started for some reason. In that case the buffers should be
- * returned with state QUEUED to put them back into the queue.
+ * returned with state QUEUED or REQUEUEING to put them back into the queue.
+ *
+ * %VB2_BUF_STATE_REQUEUEING is like %VB2_BUF_STATE_QUEUED, but it also calls
+ * _ops->buf_queue to queue buffers back to the driver. Note that calling
+ * vb2_buffer_done(..., VB2_BUF_STATE_REQUEUEING) from interrupt context will
+ * result in _ops->buf_queue being called in interrupt context as well.
  */
 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
 
-- 
2.7.4



[PATCH v2 1/3] media: vb2-core: vb2_buffer_done: consolidate docs

2018-03-08 Thread Luca Ceresoli
Documentation about what start_streaming() should do on failure are
scattered in two places and mostly duplicated, so consolidate them in
one of the two places.

Signed-off-by: Luca Ceresoli 
Cc: Laurent Pinchart 
Cc: Pawel Osciak 
Cc: Marek Szyprowski 
Cc: Kyungmin Park 
Cc: Mauro Carvalho Chehab 

---
Changes v1 -> v2: none.
---
 include/media/videobuf2-core.h | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 5b6c541e4e1b..f1a479060f9e 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -602,9 +602,7 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int 
plane_no);
  * Either %VB2_BUF_STATE_DONE if the operation finished
  * successfully, %VB2_BUF_STATE_ERROR if the operation finished
  * with an error or %VB2_BUF_STATE_QUEUED if the driver wants to
- * requeue buffers. If start_streaming fails then it should return
- * buffers with state %VB2_BUF_STATE_QUEUED to put them back into
- * the queue.
+ * requeue buffers.
  *
  * This function should be called by the driver after a hardware operation on
  * a buffer is finished and the buffer may be returned to userspace. The driver
@@ -613,9 +611,9 @@ void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int 
plane_no);
  * to the driver by _ops->buf_queue can be passed to this function.
  *
  * While streaming a buffer can only be returned in state DONE or ERROR.
- * The start_streaming op can also return them in case the DMA engine cannot
- * be started for some reason. In that case the buffers should be returned with
- * state QUEUED.
+ * The _ops->start_streaming op can also return them in case the DMA engine
+ * cannot be started for some reason. In that case the buffers should be
+ * returned with state QUEUED to put them back into the queue.
  */
 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
 
-- 
2.7.4



[PATCH v2 3/3] media: vb2-core: vb2_ops: document non-interrupt-context calling

2018-03-08 Thread Luca Ceresoli
Driver writers can benefit in knowing if/when callbacks are called in
interrupt context. But it is not completely obvious here, so document
it.

Signed-off-by: Luca Ceresoli 
Cc: Laurent Pinchart 
Cc: Pawel Osciak 
Cc: Marek Szyprowski 
Cc: Kyungmin Park 
Cc: Mauro Carvalho Chehab 

---
Changes v1 -> v2:
 - Fix typo in the title.
---
 include/media/videobuf2-core.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index f2887d3c..f6818f732f34 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -296,6 +296,9 @@ struct vb2_buffer {
 /**
  * struct vb2_ops - driver-specific callbacks.
  *
+ * These operations are not called from interrupt context except where
+ * mentioned specifically.
+ *
  * @queue_setup:   called from VIDIOC_REQBUFS() and VIDIOC_CREATE_BUFS()
  * handlers before memory allocation. It can be called
  * twice: if the original number of requested buffers
-- 
2.7.4



Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Baruch Siach
Hi Jacob,

On Thu, Mar 08, 2018 at 05:47:50PM +0800, Jacob Chen wrote:
> This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 
> SoC.
> 
> Wiki Pages:
> http://opensource.rock-chips.com/wiki_Rockchip-isp1
> 
> The deprecated g_mbus_config op is not dropped in  V6 because i am waiting 
> tomasz's patches.

Which tree is this series based on? On top of v4.16-rc4 I get the build 
failure below. The V4L2_BUF_TYPE_META_OUTPUT macro, for example, is not even 
in media_tree.git.

drivers/media/platform/rockchip/isp1/isp_params.c:1321:3: error: ‘const struct 
v4l2_ioctl_ops’ has no member named ‘vidioc_enum_fmt_meta_out’; did you mean 
‘vidioc_enum_fmt_meta_cap’?
  .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
   ^~~~
   vidioc_enum_fmt_meta_cap
drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: error: 
initialization from incompatible pointer type 
[-Werror=incompatible-pointer-types]
  .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
  ^~~
drivers/media/platform/rockchip/isp1/isp_params.c:1321:30: note: (near 
initialization for ‘rkisp1_params_ioctl.vidioc_g_std’)
drivers/media/platform/rockchip/isp1/isp_params.c:1322:3: error: ‘const struct 
v4l2_ioctl_ops’ has no member named ‘vidioc_g_fmt_meta_out’; did you mean 
‘vidioc_g_fmt_meta_cap’?
  .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
   ^
   vidioc_g_fmt_meta_cap
drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: error: 
initialization from incompatible pointer type 
[-Werror=incompatible-pointer-types]
  .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
   ^~~~
drivers/media/platform/rockchip/isp1/isp_params.c:1322:27: note: (near 
initialization for ‘rkisp1_params_ioctl.vidioc_s_std’)
drivers/media/platform/rockchip/isp1/isp_params.c:1323:3: error: ‘const struct 
v4l2_ioctl_ops’ has no member named ‘vidioc_s_fmt_meta_out’; did you mean 
‘vidioc_s_fmt_meta_cap’?
  .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
   ^
   vidioc_s_fmt_meta_cap
drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: error: 
initialization from incompatible pointer type 
[-Werror=incompatible-pointer-types]
  .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
   ^~~~
drivers/media/platform/rockchip/isp1/isp_params.c:1323:27: note: (near 
initialization for ‘rkisp1_params_ioctl.vidioc_querystd’)
drivers/media/platform/rockchip/isp1/isp_params.c:1324:3: error: ‘const struct 
v4l2_ioctl_ops’ has no member named ‘vidioc_try_fmt_meta_out’; did you mean 
‘vidioc_try_fmt_meta_cap’?
  .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
   ^~~
   vidioc_try_fmt_meta_cap
drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: error: 
initialization from incompatible pointer type 
[-Werror=incompatible-pointer-types]
  .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
 ^~~~
drivers/media/platform/rockchip/isp1/isp_params.c:1324:29: note: (near 
initialization for ‘rkisp1_params_ioctl.vidioc_enum_input’)
drivers/media/platform/rockchip/isp1/isp_params.c: In function 
‘rkisp1_params_init_vb2_queue’:
drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: error: 
‘V4L2_BUF_TYPE_META_OUTPUT’ undeclared (first use in this function); did you 
mean ‘V4L2_BUF_TYPE_SDR_OUTPUT’?
  q->type = V4L2_BUF_TYPE_META_OUTPUT;
^
V4L2_BUF_TYPE_SDR_OUTPUT
drivers/media/platform/rockchip/isp1/isp_params.c:1462:12: note: each 
undeclared identifier is reported only once for each function it appears in
  CC  drivers/media/platform/rockchip/isp1/mipi_dphy_sy.o
drivers/media/platform/rockchip/isp1/isp_params.c: In function 
‘rkisp1_register_params_vdev’:
drivers/media/platform/rockchip/isp1/isp_params.c:1507:43: error: 
‘V4L2_CAP_META_OUTPUT’ undeclared (first use in this function); did you mean 
‘V4L2_CAP_VBI_OUTPUT’?
  vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT;
   ^~~~
   V4L2_CAP_VBI_OUTPUT

Thanks,
baruch

> Jacob Chen (12):
>   media: doc: add document for rkisp1 meta buffer format
>   media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
>   media: rkisp1: add Rockchip ISP1 subdev driver
>   media: rkisp1: add ISP1 statistics driver
>   media: rkisp1: add ISP1 params driver
>   media: rkisp1: add capture device driver
>   media: rkisp1: add rockchip isp1 core driver
>   dt-bindings: Document the Rockchip ISP1 bindings
>   dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
>   ARM: dts: rockchip: add isp node for rk3288
>   ARM: dts: rockchip: add rx0 mipi-phy for rk3288
>   MAINTAINERS: add entry for Rockchip ISP1 driver
> 
> Jeffy Chen (1):
>   

[PATCH v2] media: rc: add new imon protocol decoder and encoder

2018-03-08 Thread Sean Young
This makes it possible to use the various iMON remotes with any raw IR
RC device.

Signed-off-by: Sean Young 
---
 drivers/media/rc/Kconfig   |   9 ++
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/ir-imon-decoder.c | 193 +
 drivers/media/rc/keymaps/rc-imon-pad.c |   3 +-
 drivers/media/rc/rc-core-priv.h|   6 +
 drivers/media/rc/rc-main.c |   3 +
 include/media/rc-map.h |   8 +-
 include/uapi/linux/lirc.h  |   2 +
 8 files changed, 220 insertions(+), 5 deletions(-)
 create mode 100644 drivers/media/rc/ir-imon-decoder.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 7ad05a6ef350..eb2c3b6eca7f 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -111,6 +111,15 @@ config IR_XMP_DECODER
---help---
   Enable this option if you have IR with XMP protocol, and
   if the IR is decoded in software
+
+config IR_IMON_DECODER
+   tristate "Enable IR raw decoder for the iMON protocol"
+   depends on RC_CORE
+   ---help---
+  Enable this option if you have iMON PAD or Antec Veris infrared
+  remote control and you would like to use it with a raw IR
+  receiver, or if you wish to use an encoder to transmit this IR.
+
 endif #RC_DECODERS
 
 menuconfig RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index e098e127b26a..2e1c87066f6c 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_IR_SANYO_DECODER) += ir-sanyo-decoder.o
 obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
 obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
 obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
+obj-$(CONFIG_IR_IMON_DECODER) += ir-imon-decoder.o
 
 # stand-alone IR receivers/transmitters
 obj-$(CONFIG_RC_ATI_REMOTE) += ati_remote.o
diff --git a/drivers/media/rc/ir-imon-decoder.c 
b/drivers/media/rc/ir-imon-decoder.c
new file mode 100644
index ..a1ff06a26542
--- /dev/null
+++ b/drivers/media/rc/ir-imon-decoder.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0+
+// ir-imon-decoder.c - handle iMon protocol
+//
+// Copyright (C) 2018 by Sean Young 
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include "rc-core-priv.h"
+
+#define IMON_UNIT  415662 /* ns */
+#define IMON_BITS  30
+#define IMON_CHKBITS   (BIT(30) | BIT(25) | BIT(24) | BIT(22) | \
+BIT(21) | BIT(20) | BIT(19) | BIT(18) | \
+BIT(17) | BIT(16) | BIT(14) | BIT(13) | \
+BIT(12) | BIT(11) | BIT(10) | BIT(9))
+
+/*
+ * This protocol has 30 bits. The format is one IMON_UNIT header pulse,
+ * followed by 30 bits. Each bit is one IMON_UNIT check field, and then
+ * one IMON_UNIT field with the actual bit (1=space, 0=pulse).
+ * The check field is always space for some bits, for others it is pulse if
+ * both the preceding and current bit are zero, else space. IMON_CHKBITS
+ * defines which bits are of type check.
+ *
+ * There is no way to distinguish an incomplete message from one where
+ * the lower bits are all set, iow. the last pulse is for the lowest
+ * bit which is 0.
+ */
+enum imon_state {
+   STATE_INACTIVE,
+   STATE_BIT_CHK,
+   STATE_BIT_START,
+   STATE_FINISHED
+};
+
+/**
+ * ir_imon_decode() - Decode one iMON pulse or space
+ * @dev:   the struct rc_dev descriptor of the device
+ * @ev:the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This function returns -EINVAL if the pulse violates the state machine
+ */
+static int ir_imon_decode(struct rc_dev *dev, struct ir_raw_event ev)
+{
+   struct imon_dec *data = >raw->imon;
+
+   if (!is_timing_event(ev)) {
+   if (ev.reset)
+   data->state = STATE_INACTIVE;
+   return 0;
+   }
+
+   dev_dbg(>dev,
+   "iMON decode started at state %d bitno %d (%uus %s)\n",
+   data->state, data->count, TO_US(ev.duration),
+   TO_STR(ev.pulse));
+
+   for (;;) {
+   if (!geq_margin(ev.duration, IMON_UNIT, IMON_UNIT / 2))
+   return 0;
+
+   decrease_duration(, IMON_UNIT);
+
+   switch (data->state) {
+   case STATE_INACTIVE:
+   if (ev.pulse) {
+   data->state = STATE_BIT_CHK;
+   data->bits = 0;
+   data->count = IMON_BITS;
+   }
+   break;
+   case STATE_BIT_CHK:
+   if (IMON_CHKBITS & BIT(data->count))
+   data->last_chk = ev.pulse;
+   else if (ev.pulse)
+   goto err_out;
+   

[PATCH v2] media: stm32-dcmi: rework overrun/error case

2018-03-08 Thread Hugues Fruchet
Do not stop/restart dma on overrun or errors.
Dma will be restarted on current frame transfer
completion. Frame transfer completion is ensured
even if overrun or error occurs by DCMI continuous
capture mode which restarts data transfer at next
frame sync.
Do no warn on overrun while in irq thread, this slows down
system and lead to more overrun errors. Use a counter
instead and log errors at stop streaming.

Signed-off-by: Hugues Fruchet 
---
version 2:
  - typo: remove blank line at the end of stop_streaming()

 drivers/media/platform/stm32/stm32-dcmi.c | 29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 37d82d3..95ace0f 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -160,6 +160,7 @@ struct stm32_dcmi {
dma_cookie_tdma_cookie;
u32 misr;
int errors_count;
+   int overrun_count;
int buffers_count;
 };
 
@@ -373,23 +374,9 @@ static irqreturn_t dcmi_irq_thread(int irq, void *arg)
}
 
if ((dcmi->misr & IT_OVR) || (dcmi->misr & IT_ERR)) {
-   /*
-* An overflow or an error has been detected,
-* stop current DMA transfert & restart it
-*/
-   dev_warn(dcmi->dev, "%s: Overflow or error detected\n",
-__func__);
-
dcmi->errors_count++;
-   dev_dbg(dcmi->dev, "Restarting capture after DCMI error\n");
-
-   spin_unlock_irq(>irqlock);
-   dmaengine_terminate_all(dcmi->dma_chan);
-
-   if (dcmi_start_capture(dcmi))
-   dev_err(dcmi->dev, "%s: Cannot restart capture on 
overflow or error\n",
-   __func__);
-   return IRQ_HANDLED;
+   if (dcmi->misr & IT_OVR)
+   dcmi->overrun_count++;
}
 
spin_unlock_irq(>irqlock);
@@ -572,6 +559,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 
dcmi->sequence = 0;
dcmi->errors_count = 0;
+   dcmi->overrun_count = 0;
dcmi->buffers_count = 0;
dcmi->active = NULL;
 
@@ -682,8 +670,13 @@ static void dcmi_stop_streaming(struct vb2_queue *vq)
 
clk_disable(dcmi->mclk);
 
-   dev_dbg(dcmi->dev, "Stop streaming, errors=%d buffers=%d\n",
-   dcmi->errors_count, dcmi->buffers_count);
+   if (dcmi->errors_count)
+   dev_warn(dcmi->dev, "Some errors found while streaming: 
errors=%d (overrun=%d), buffers=%d\n",
+dcmi->errors_count, dcmi->overrun_count,
+dcmi->buffers_count);
+   dev_dbg(dcmi->dev, "Stop streaming, errors=%d (overrun=%d), 
buffers=%d\n",
+   dcmi->errors_count, dcmi->overrun_count,
+   dcmi->buffers_count);
 }
 
 static const struct vb2_ops dcmi_video_qops = {
-- 
1.9.1



Re: [PATCH] media: ov5640: fix frame interval enumeration

2018-03-08 Thread Mauro Carvalho Chehab
Em Thu, 8 Mar 2018 07:39:09 -0300
Mauro Carvalho Chehab  escreveu:

> Also, if this function starts returning NULL, I suspect that you also
> need to change ov5640_s_frame_interval(), as currently it is called
> at ov5640_s_frame_interval() as:
> 
>   sensor->current_mode = ov5640_find_mode(sensor, frame_rate, mode->width,
>   mode->height, true);
> 
> without checking if the returned value is NULL. Setting
> current_mode to NULL can cause oopses at ov5640_set_mode().

Actually, as ov5640_s_frame_interval() calls ov5640_try_fmt_internal()
first. So, this should never happen.


Thanks,
Mauro


Re: [PATCH] media: ov5640: fix frame interval enumeration

2018-03-08 Thread Mauro Carvalho Chehab
Em Thu, 8 Mar 2018 10:01:59 +0100
Hugues Fruchet  escreveu:

> Driver must reject frame interval enumeration of unsupported resolution.
> This was detected by v4l2-compliance format ioctl test:
> v4l2-compliance Format ioctls:
>   info: found 2 frameintervals for pixel format 4745504a and size 176x144
>   fail: v4l2-test-formats.cpp(123):
>found frame intervals for invalid size 177x144
>   test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL
> 
> Signed-off-by: Hugues Fruchet 
> ---
>  drivers/media/i2c/ov5640.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
> index 676f635..28dc687 100644
> --- a/drivers/media/i2c/ov5640.c
> +++ b/drivers/media/i2c/ov5640.c
> @@ -1400,6 +1400,9 @@ static int ov5640_set_virtual_channel(struct ov5640_dev 
> *sensor)
>   if (nearest && i < 0)
>   mode = _mode_data[fr][0];
>  
> + if (!nearest && i < 0)
> + return NULL;
> +
>   return mode;
>  }


I didn't check the full logic here, nor if this patch makes sense, but
just looking at the above code, it looks ugly to fill "mode" var just
to discard it. I would code the above as:

if (i < 0) {
if (!nearest)
return NULL;
mode = _mode_data[fr][0];
}


Also, if this function starts returning NULL, I suspect that you also
need to change ov5640_s_frame_interval(), as currently it is called
at ov5640_s_frame_interval() as:

sensor->current_mode = ov5640_find_mode(sensor, frame_rate, mode->width,
mode->height, true);

without checking if the returned value is NULL. Setting
current_mode to NULL can cause oopses at ov5640_set_mode().

Regards,
Mauro


Re: [PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Tomasz Figa
On Thu, Mar 8, 2018 at 6:47 PM, Jacob Chen  wrote:
> From: Jacob Chen 
>
> changes in V6:
>   - add mipi txrx phy support
>   - remove bool and enum from uapi header
>   - add buf_prepare op
>   - correct some spelling problems
>   - return all queued buffers when starting stream failed

Thanks Jacob.

For anyone planning to review, especially Hans, who pointed it out in
previous version, g_mbus_config is still there and we're working on
replacing it with something less controversial.

Best regards,
Tomasz


Re: [PATCH v5 03/16] media: rkisp1: Add user space ABI definitions

2018-03-08 Thread Jacob Chen
Hi Hans,

2018-02-07 20:00 GMT+08:00 Hans Verkuil :
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jeffy Chen 
>>
>> Add the header for userspace
>
> General note: I saw four cases where this documentation referred to the
> datasheet. Three comments on that:
>
> 1) You don't say which datasheet.
> 2) I assume the datasheet is under NDA?

This datasheet can't be got by customers, even under NDA.

> 3) You do need to give enough information so a reasonable default can be
>used. I mentioned in an earlier review that creating an initial params
>struct that can be used as a templete would be helpful (or even
>required), and that would be a good place to put such defaults.
>

It don't need a default config
For applcation writers, they can just init it with zero data, and only
set value for the part they concerned.

As for ABI, i have checked there is no mismatches.
Those structures is 32 bit aligned both in 64bit/32bit env, since
there is no 64bit value.
"__attribute__ ((packed))" can avoid mismatches happen when we add a
64bit value to those structures.

As robin said, enums and bools are not guaranteed to be consistent
between different compiler, so it's a potential risk.
I have replace bools with unsigned char and enums with unsigned int.


> Regards,
>
> Hans


Re: [PATCH v5 02/16] media: doc: add document for rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
Hi Hans,

2018-02-06 22:27 GMT+08:00 Hans Verkuil :
> On 12/29/17 08:52, Shunqian Zheng wrote:
>> From: Jacob Chen 
>>
>> This commit add docuemnt for rkisp1 meta buffer format
>>
>> Signed-off-by: Jacob Chen 
>> ---
>>  Documentation/media/uapi/v4l/meta-formats.rst  |  2 ++
>>  .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst   | 17 
>> +
>>  .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 
>> ++
>>  3 files changed, 37 insertions(+)
>>  create mode 100644 
>> Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>>  create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>>
>> diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
>> b/Documentation/media/uapi/v4l/meta-formats.rst
>> index 01e24e3..1b82814 100644
>> --- a/Documentation/media/uapi/v4l/meta-formats.rst
>> +++ b/Documentation/media/uapi/v4l/meta-formats.rst
>> @@ -14,3 +14,5 @@ These formats are used for the :ref:`metadata` interface 
>> only.
>>
>>  pixfmt-meta-vsp1-hgo
>>  pixfmt-meta-vsp1-hgt
>> +pixfmt-meta-rkisp1-params
>> +pixfmt-meta-rkisp1-stat
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>> new file mode 100644
>> index 000..ed344d4
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
>> @@ -0,0 +1,17 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _v4l2-meta-fmt-rkisp1-params:
>> +
>> +***
>> +V4L2_META_FMT_RK_ISP1_PARAMS
>> +***
>> +
>> +Rockchip ISP1 Parameters Data
>> +
>> +Description
>> +===
>> +
>> +This format describes input parameters for the Rockchip ISP1.
>> +
>> +The data use c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
>> +the ``linux/rkisp1-config.h`` header file, See it for details.
>
> One more question: does the ISP produce a reasonable picture if it doesn't
> receive these params? If not (i.e. you always need to provide params), then
> I think you should provide a default rkisp1_isp_params_cfg struct that
> can be used as a template for application writers.
>
> Perhaps it can be part of the driver as the initial params config.
>
> I think even if the ISP does work without params it is still worthwhile
> doing this. The params are complex and having an example on how to initialize
> it would be helpful.
>

The ISP don't need a default rkisp1_isp_params_cfg to produce picture,
those params just effect image quality and stats data.

The params are not very complex.
They consist of multiple modules and each of modules can be
enabled/disable/updated individually.

> Regards,
>
> Hans
>
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>> new file mode 100644
>> index 000..5ecc403
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
>> @@ -0,0 +1,18 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _v4l2-meta-fmt-rkisp1-stat:
>> +
>> +***
>> +V4L2_META_FMT_RK_ISP1_STAT_3A
>> +***
>> +
>> +Rockchip ISP1 Statistics Data
>> +
>> +Description
>> +===
>> +
>> +This format describes image color statistics information generated by the 
>> Rockchip
>> +ISP1.
>> +
>> +The data use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
>> +the ``linux/cifisp_stat.h`` header file, See it for details.
>>
>


[PATCH v6 01/17] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng 

Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMS and metadata format
V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
Acked-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++
 include/uapi/linux/videodev2.h   | 4 
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 1be54429d601..bdd469290d66 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1257,6 +1257,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
case V4L2_META_FMT_UVC: descr = "UVC payload header metadata"; 
break;
+   case V4L2_META_FMT_RK_ISP1_PARAMS:  descr = "Rockchip ISP1 3A 
params"; break;
+   case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A 
statistics"; break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index e20d10df75c1..359ad8bbf9bf 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -698,6 +698,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC 
Payload Header metadata */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 params */
+#define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.16.1



[PATCH v6 04/17] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Tomasz Figa 
---
 .../media/platform/rockchip/isp1/mipi_dphy_sy.c| 868 +
 .../media/platform/rockchip/isp1/mipi_dphy_sy.h|  15 +
 2 files changed, 883 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
 create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.h

diff --git a/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c 
b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
new file mode 100644
index ..32140960557a
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
@@ -0,0 +1,868 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip MIPI Synopsys DPHY driver
+ *
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RK3288_GRF_SOC_CON60x025c
+#define RK3288_GRF_SOC_CON80x0264
+#define RK3288_GRF_SOC_CON90x0268
+#define RK3288_GRF_SOC_CON10   0x026c
+#define RK3288_GRF_SOC_CON14   0x027c
+#define RK3288_GRF_SOC_STATUS210x02d4
+#define RK3288_GRF_IO_VSEL 0x0380
+#define RK3288_GRF_SOC_CON15   0x03a4
+
+#define RK3399_GRF_SOC_CON90x6224
+#define RK3399_GRF_SOC_CON21   0x6254
+#define RK3399_GRF_SOC_CON22   0x6258
+#define RK3399_GRF_SOC_CON23   0x625c
+#define RK3399_GRF_SOC_CON24   0x6260
+#define RK3399_GRF_SOC_CON25   0x6264
+#define RK3399_GRF_SOC_STATUS1 0xe2a4
+
+#define CLOCK_LANE_HS_RX_CONTROL   0x34
+#define LANE0_HS_RX_CONTROL0x44
+#define LANE1_HS_RX_CONTROL0x54
+#define LANE2_HS_RX_CONTROL0x84
+#define LANE3_HS_RX_CONTROL0x94
+#define HS_RX_DATA_LANES_THS_SETTLE_CONTROL0x75
+
+/*
+ * CSI HOST
+ */
+#define CSIHOST_PHY_TEST_CTRL0 0x30
+#define CSIHOST_PHY_TEST_CTRL1 0x34
+#define CSIHOST_PHY_SHUTDOWNZ  0x08
+#define CSIHOST_DPHY_RSTZ  0x0c
+
+#define PHY_TESTEN_ADDR(0x1 << 16)
+#define PHY_TESTEN_DATA(0x0 << 16)
+#define PHY_TESTCLK(0x1 << 1)
+#define PHY_TESTCLR(0x1 << 0)
+#define THS_SETTLE_COUNTER_THRESHOLD   0x04
+
+#define HIWORD_UPDATE(val, mask, shift) \
+   ((val) << (shift) | (mask) << ((shift) + 16))
+
+enum mipi_dphy_sy_pads {
+   MIPI_DPHY_SY_PAD_SINK = 0,
+   MIPI_DPHY_SY_PAD_SOURCE,
+   MIPI_DPHY_SY_PADS_NUM,
+};
+
+enum dphy_reg_id {
+   GRF_DPHY_RX0_TURNDISABLE = 0,
+   GRF_DPHY_RX0_FORCERXMODE,
+   GRF_DPHY_RX0_FORCETXSTOPMODE,
+   GRF_DPHY_RX0_ENABLE,
+   GRF_DPHY_RX0_TESTCLR,
+   GRF_DPHY_RX0_TESTCLK,
+   GRF_DPHY_RX0_TESTEN,
+   GRF_DPHY_RX0_TESTDIN,
+   GRF_DPHY_RX0_TURNREQUEST,
+   GRF_DPHY_RX0_TESTDOUT,
+   GRF_DPHY_TX0_TURNDISABLE,
+   GRF_DPHY_TX0_FORCERXMODE,
+   GRF_DPHY_TX0_FORCETXSTOPMODE,
+   GRF_DPHY_TX0_TURNREQUEST,
+   GRF_DPHY_TX1RX1_TURNDISABLE,
+   GRF_DPHY_TX1RX1_FORCERXMODE,
+   GRF_DPHY_TX1RX1_FORCETXSTOPMODE,
+   GRF_DPHY_TX1RX1_ENABLE,
+   GRF_DPHY_TX1RX1_MASTERSLAVEZ,
+   GRF_DPHY_TX1RX1_BASEDIR,
+   GRF_DPHY_TX1RX1_ENABLECLK,
+   GRF_DPHY_TX1RX1_TURNREQUEST,
+   GRF_DPHY_RX1_SRC_SEL,
+   /* rk3288 only */
+   GRF_CON_DISABLE_ISP,
+   GRF_CON_ISP_DPHY_SEL,
+   GRF_DSI_CSI_TESTBUS_SEL,
+   GRF_DVP_V18SEL,
+   /* below is for rk3399 only */
+   GRF_DPHY_RX0_CLK_INV_SEL,
+   GRF_DPHY_RX1_CLK_INV_SEL,
+};
+
+struct dphy_reg {
+   u32 offset;
+   u32 mask;
+   u32 shift;
+};
+
+#define PHY_REG(_offset, _width, _shift) \
+   { .offset = _offset, .mask = BIT(_width) - 1, .shift = _shift, }
+
+static const struct dphy_reg rk3399_grf_dphy_regs[] = {
+   [GRF_DPHY_RX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON9, 4, 0),
+   [GRF_DPHY_RX0_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 10),
+   [GRF_DPHY_RX1_CLK_INV_SEL] = PHY_REG(RK3399_GRF_SOC_CON9, 1, 11),
+   [GRF_DPHY_RX0_ENABLE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 0),
+   [GRF_DPHY_RX0_FORCERXMODE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 4),
+   [GRF_DPHY_RX0_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 8),
+   [GRF_DPHY_RX0_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON21, 4, 12),
+   [GRF_DPHY_TX0_FORCERXMODE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 0),
+   [GRF_DPHY_TX0_FORCETXSTOPMODE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 4),
+   [GRF_DPHY_TX0_TURNDISABLE] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 8),
+   [GRF_DPHY_TX0_TURNREQUEST] = PHY_REG(RK3399_GRF_SOC_CON22, 4, 12),
+   [GRF_DPHY_TX1RX1_ENABLE] = PHY_REG(RK3399_GRF_SOC_CON23, 4, 

[PATCH v6 00/17] Rockchip ISP1 Driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

changes in V6:
  - add mipi txrx phy support
  - remove bool and enum from uapi header
  - add buf_prepare op
  - correct some spelling problems
  - return all queued buffers when starting stream failed

changes in V5: Sync with local changes,
  - fix the SP height limit
  - speed up the second stream capture
  - the second stream can't force sync for rsz when start/stop streaming
  - add frame id to param vb2 buf
  - enable luminance maximum threshold

changes in V4:
  - fix some bugs during development
  - move quantization settings to rkisp1 subdev
  - correct some spelling problems
  - describe ports in dt-binding documents

changes in V3:
  - add some comments
  - fix wrong use of v4l2_async_subdev_notifier_register
  - optimize two paths capture at a time
  - remove compose
  - re-struct headers
  - add a tmp wiki page: http://opensource.rock-chips.com/wiki_Rockchip-isp1

changes in V2:
  mipi-phy:
- use async probing
- make it be a child device of the GRF
  isp:
- add dummy buffer
- change the way to get bus configuration, which make it possible to
add parallel sensor support in the future(without mipi-phy driver).

This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.

Wiki Pages:
http://opensource.rock-chips.com/wiki_Rockchip-isp1

The deprecated g_mbus_config op is not dropped in  V6 because i am waiting 
tomasz's patches.

v4l2-compliance for V6(isp params/stats nodes are passed):

v4l2-compliance SHA   : 93dc5f20727fede5097d67f8b9adabe4b8046d5b

Compliance test for device /dev/video0:

Driver Info:
Driver name  : rkisp1
Card type: rkisp1
Bus info : platform:ff91.isp
Driver version   : 4.16.0
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Media Driver Info:
Driver name  : rkisp1
Model: rkisp1
Serial   : 
Bus info : 
Media version: 4.16.0
Hardware revision: 0x (0)
Driver version   : 4.16.0
Interface Info:
ID   : 0x0307
Type : V4L Video
Entity Info:
ID   : 0x0006 (6)
Name : rkisp1_selfpath
Function : V4L2 I/O
Pad 0x0109   : Sink
  Link 0x0221: from remote pad 0x104 of entity 
'rkisp1-isp-subdev': Data, Enabled

Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 9 Private Controls: 0

Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
fail: v4l2-test-formats.cpp(330): !colorspace
   

[PATCH v6 03/17] media: rkisp1: Add user space ABI definitions

2018-03-08 Thread Jacob Chen
From: Jeffy Chen 

Add the header for userspace

Signed-off-by: Jeffy Chen 
Signed-off-by: Jacob Chen 
---
 include/uapi/linux/rkisp1-config.h | 798 +
 1 file changed, 798 insertions(+)
 create mode 100644 include/uapi/linux/rkisp1-config.h

diff --git a/include/uapi/linux/rkisp1-config.h 
b/include/uapi/linux/rkisp1-config.h
new file mode 100644
index ..1284eb9fd09d
--- /dev/null
+++ b/include/uapi/linux/rkisp1-config.h
@@ -0,0 +1,798 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+/*
+ * References:
+ * REF_01 - ISP_user_manual, Rev 2.57
+ */
+
+#ifndef _UAPI_RKISP1_CONFIG_H
+#define _UAPI_RKISP1_CONFIG_H
+
+#include 
+#include 
+
+#define CIFISP_MODULE_DPCC  (1 << 0)
+#define CIFISP_MODULE_BLS   (1 << 1)
+#define CIFISP_MODULE_SDG   (1 << 2)
+#define CIFISP_MODULE_HST   (1 << 3)
+#define CIFISP_MODULE_LSC   (1 << 4)
+#define CIFISP_MODULE_AWB_GAIN  (1 << 5)
+#define CIFISP_MODULE_FLT   (1 << 6)
+#define CIFISP_MODULE_BDM   (1 << 7)
+#define CIFISP_MODULE_CTK   (1 << 8)
+#define CIFISP_MODULE_GOC   (1 << 9)
+#define CIFISP_MODULE_CPROC (1 << 10)
+#define CIFISP_MODULE_AFC   (1 << 11)
+#define CIFISP_MODULE_AWB   (1 << 12)
+#define CIFISP_MODULE_IE(1 << 13)
+#define CIFISP_MODULE_AEC   (1 << 14)
+#define CIFISP_MODULE_WDR   (1 << 15)
+#define CIFISP_MODULE_DPF   (1 << 16)
+#define CIFISP_MODULE_DPF_STRENGTH  (1 << 17)
+
+#define CIFISP_CTK_COEFF_MAX0x100
+#define CIFISP_CTK_OFFSET_MAX   0x800
+
+#define CIFISP_AE_MEAN_MAX  25
+#define CIFISP_HIST_BIN_N_MAX   16
+#define CIFISP_AFM_MAX_WINDOWS  3
+#define CIFISP_DEGAMMA_CURVE_SIZE   17
+
+#define CIFISP_BDM_MAX_TH   0xFF
+
+/*
+ * Black level compensation
+ */
+/* maximum value for horizontal start address */
+#define CIFISP_BLS_START_H_MAX 0x0FFF
+/* maximum value for horizontal stop address */
+#define CIFISP_BLS_STOP_H_MAX  0x0FFF
+/* maximum value for vertical start address */
+#define CIFISP_BLS_START_V_MAX 0x0FFF
+/* maximum value for vertical stop address */
+#define CIFISP_BLS_STOP_V_MAX  0x0FFF
+/* maximum is 2^18 = 262144*/
+#define CIFISP_BLS_SAMPLES_MAX 0x0012
+/* maximum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MAX 0x0FFF
+/* minimum value for fixed black level */
+#define CIFISP_BLS_FIX_SUB_MIN 0xF000
+/* 13 bit range (signed)*/
+#define CIFISP_BLS_FIX_MASK0x1FFF
+
+/*
+ * Automatic white balance measurments
+ */
+#define CIFISP_AWB_MAX_GRID1
+#define CIFISP_AWB_MAX_FRAMES  7
+
+/*
+ * Gamma out
+ */
+/* Maximum number of color samples supported */
+#define CIFISP_GAMMA_OUT_MAX_SAMPLES   17
+
+/*
+ * Lens shade correction
+ */
+#define CIFISP_LSC_GRAD_TBL_SIZE   8
+#define CIFISP_LSC_SIZE_TBL_SIZE   8
+/*
+ * The following matches the tuning process,
+ * not the max capabilities of the chip.
+ * Last value unused.
+ */
+#defineCIFISP_LSC_DATA_TBL_SIZE   290
+
+/*
+ * Histogram calculation
+ */
+/* Last 3 values unused. */
+#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28
+
+/*
+ * Defect Pixel Cluster Correction
+ */
+#define CIFISP_DPCC_METHODS_MAX   3
+
+/*
+ * Denoising pre filter
+ */
+#define CIFISP_DPF_MAX_NLF_COEFFS  17
+#define CIFISP_DPF_MAX_SPATIAL_COEFFS  6
+
+/*
+ * Measurement types
+ */
+#define CIFISP_STAT_AWB   (1 << 0)
+#define CIFISP_STAT_AUTOEXP   (1 << 1)
+#define CIFISP_STAT_AFM_FIN   (1 << 2)
+#define CIFISP_STAT_HIST  (1 << 3)
+
+enum cifisp_histogram_mode {
+   CIFISP_HISTOGRAM_MODE_DISABLE,
+   CIFISP_HISTOGRAM_MODE_RGB_COMBINED,
+   CIFISP_HISTOGRAM_MODE_R_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_G_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_B_HISTOGRAM,
+   CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM
+};
+
+enum cifisp_awb_mode_type {
+   CIFISP_AWB_MODE_MANUAL,
+   CIFISP_AWB_MODE_RGB,
+   CIFISP_AWB_MODE_YCBCR
+};
+
+enum cifisp_flt_mode {
+   CIFISP_FLT_STATIC_MODE,
+   CIFISP_FLT_DYNAMIC_MODE
+};
+
+/**
+ * enum cifisp_exp_ctrl_autostop - stop modes
+ * @CIFISP_EXP_CTRL_AUTOSTOP_0: continuous measurement
+ * @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
+ */
+enum cifisp_exp_ctrl_autostop {
+   CIFISP_EXP_CTRL_AUTOSTOP_0 = 0,
+   CIFISP_EXP_CTRL_AUTOSTOP_1 = 1,
+};
+
+/**
+ * enum cifisp_exp_meas_mode - Exposure measure mode
+ * @CIFISP_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B
+ * @CIFISP_EXP_MEASURING_MODE_1: Y = (R + G + 

[PATCH v6 06/17] media: rkisp1: add ISP1 statistics driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the capture video driver for rockchip isp1 statistics block.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/isp_stats.c | 508 +++
 drivers/media/platform/rockchip/isp1/isp_stats.h |  58 +++
 2 files changed, 566 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_stats.c 
b/drivers/media/platform/rockchip/isp1/isp_stats.c
new file mode 100644
index ..3ba86ccbc42d
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_stats.c
@@ -0,0 +1,508 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include/* for ISP statistics */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_STATS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_STATS_REQ_BUFS_MAX 8
+
+static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv,
+ struct v4l2_fmtdesc *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+
+   if (f->index > 0 || f->type != video->queue->type)
+   return -EINVAL;
+
+   f->pixelformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   return 0;
+}
+
+static int rkisp1_stats_g_fmt_meta_cap(struct file *file, void *priv,
+  struct v4l2_format *f)
+{
+   struct video_device *video = video_devdata(file);
+   struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
+   struct v4l2_meta_format *meta = >fmt.meta;
+
+   if (f->type != video->queue->type)
+   return -EINVAL;
+
+   memset(meta, 0, sizeof(*meta));
+   meta->dataformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
+   meta->buffersize = stats_vdev->vdev_fmt.fmt.meta.buffersize;
+
+   return 0;
+}
+
+static int rkisp1_stats_querycap(struct file *file,
+void *priv, struct v4l2_capability *cap)
+{
+   struct video_device *vdev = video_devdata(file);
+
+   strlcpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
+   strlcpy(cap->card, vdev->name, sizeof(cap->card));
+   strlcpy(cap->bus_info, "platform: " DRIVER_NAME, sizeof(cap->bus_info));
+
+   return 0;
+}
+
+/* ISP video device IOCTLs */
+static const struct v4l2_ioctl_ops rkisp1_stats_ioctl = {
+   .vidioc_reqbufs = vb2_ioctl_reqbufs,
+   .vidioc_querybuf = vb2_ioctl_querybuf,
+   .vidioc_create_bufs = vb2_ioctl_create_bufs,
+   .vidioc_qbuf = vb2_ioctl_qbuf,
+   .vidioc_dqbuf = vb2_ioctl_dqbuf,
+   .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+   .vidioc_expbuf = vb2_ioctl_expbuf,
+   .vidioc_streamon = vb2_ioctl_streamon,
+   .vidioc_streamoff = vb2_ioctl_streamoff,
+   .vidioc_enum_fmt_meta_cap = rkisp1_stats_enum_fmt_meta_cap,
+   .vidioc_g_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_s_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_try_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
+   .vidioc_querycap = rkisp1_stats_querycap,
+   .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+   .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+struct v4l2_file_operations rkisp1_stats_fops = {
+   .mmap = vb2_fop_mmap,
+   .unlocked_ioctl = video_ioctl2,
+   .poll = vb2_fop_poll,
+   .open = v4l2_fh_open,
+   .release = vb2_fop_release
+};
+
+static int rkisp1_stats_vb2_queue_setup(struct vb2_queue *vq,
+   unsigned int *num_buffers,
+   unsigned int *num_planes,
+   unsigned int sizes[],
+   struct device *alloc_devs[])
+{
+   struct rkisp1_isp_stats_vdev *stats_vdev = vq->drv_priv;
+
+   *num_planes = 1;
+
+   *num_buffers = clamp_t(u32, *num_buffers, RKISP1_ISP_STATS_REQ_BUFS_MIN,
+  RKISP1_ISP_STATS_REQ_BUFS_MAX);
+
+   sizes[0] = sizeof(struct rkisp1_stat_buffer);
+
+   INIT_LIST_HEAD(_vdev->stat);
+
+   return 0;
+}
+
+static void rkisp1_stats_vb2_buf_queue(struct vb2_buffer *vb)
+{
+   struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+   struct rkisp1_buffer *stats_buf = to_rkisp1_buffer(vbuf);
+   struct 

[PATCH v6 07/17] media: rkisp1: add ISP1 params driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the output video driver that accept params from userspace.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/isp_params.c | 1539 +
 drivers/media/platform/rockchip/isp1/isp_params.h |   49 +
 2 files changed, 1588 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c
 create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h

diff --git a/drivers/media/platform/rockchip/isp1/isp_params.c 
b/drivers/media/platform/rockchip/isp1/isp_params.c
new file mode 100644
index ..747108e02836
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/isp_params.c
@@ -0,0 +1,1539 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include/* for ISP params */
+#include "dev.h"
+#include "regs.h"
+
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2
+#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8
+
+#define BLS_START_H_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_H_MAX)
+#define BLS_STOP_H_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_H_MAX)
+
+#define BLS_START_V_MAX_IS_VALID(val)  ((val) < CIFISP_BLS_START_V_MAX)
+#define BLS_STOP_V_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_STOP_V_MAX)
+
+#define BLS_SAMPLE_MAX_IS_VALID(val)   ((val) < CIFISP_BLS_SAMPLES_MAX)
+
+#define BLS_FIX_SUB_IS_VALID(val)  \
+   ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX)
+
+#define RKISP1_ISP_DPCC_LINE_THRESH(n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_LINE_MAD_FAC(n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * 
(n))
+#define RKISP1_ISP_DPCC_PG_FAC(n)  (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RND_THRESH(n)  (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n))
+#define RKISP1_ISP_DPCC_RG_FAC(n)  (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n))
+#define RKISP1_ISP_CC_COEFF(n) (CIF_ISP_CC_COEFF_0 + (n) * 4)
+
+static inline void rkisp1_iowrite32(struct rkisp1_isp_params_vdev *params_vdev,
+   u32 value, u32 addr)
+{
+   iowrite32(value, params_vdev->dev->base_addr + addr);
+}
+
+static inline u32 rkisp1_ioread32(struct rkisp1_isp_params_vdev *params_vdev,
+ u32 addr)
+{
+   return ioread32(params_vdev->dev->base_addr + addr);
+}
+
+static inline void isp_param_set_bits(struct rkisp1_isp_params_vdev
+*params_vdev,
+ u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val | bit_mask, reg);
+}
+
+static inline void isp_param_clear_bits(struct rkisp1_isp_params_vdev
+  *params_vdev,
+   u32 reg, u32 bit_mask)
+{
+   u32 val;
+
+   val = rkisp1_ioread32(params_vdev, reg);
+   rkisp1_iowrite32(params_vdev, val & ~bit_mask, reg);
+}
+
+/* ISP BP interface function */
+static void dpcc_config(struct rkisp1_isp_params_vdev *params_vdev,
+   const struct cifisp_dpcc_config *arg)
+{
+   unsigned int i;
+
+   rkisp1_iowrite32(params_vdev, arg->mode, CIF_ISP_DPCC_MODE);
+   rkisp1_iowrite32(params_vdev, arg->output_mode,
+CIF_ISP_DPCC_OUTPUT_MODE);
+   rkisp1_iowrite32(params_vdev, arg->set_use, CIF_ISP_DPCC_SET_USE);
+
+   rkisp1_iowrite32(params_vdev, arg->methods[0].method,
+CIF_ISP_DPCC_METHODS_SET_1);
+   rkisp1_iowrite32(params_vdev, arg->methods[1].method,
+CIF_ISP_DPCC_METHODS_SET_2);
+   rkisp1_iowrite32(params_vdev, arg->methods[2].method,
+CIF_ISP_DPCC_METHODS_SET_3);
+   for (i = 0; i < CIFISP_DPCC_METHODS_MAX; i++) {
+   rkisp1_iowrite32(params_vdev, arg->methods[i].line_thresh,
+RKISP1_ISP_DPCC_LINE_THRESH(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].line_mad_fac,
+RKISP1_ISP_DPCC_LINE_MAD_FAC(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].pg_fac,
+RKISP1_ISP_DPCC_PG_FAC(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].rnd_thresh,
+RKISP1_ISP_DPCC_RND_THRESH(i));
+   rkisp1_iowrite32(params_vdev, arg->methods[i].rg_fac,
+

[PATCH v6 05/17] media: rkisp1: add Rockchip ISP1 subdev driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the subdev driver for rockchip isp1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/rkisp1.c | 1177 +
 drivers/media/platform/rockchip/isp1/rkisp1.h |  105 +++
 2 files changed, 1282 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c
 create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h

diff --git a/drivers/media/platform/rockchip/isp1/rkisp1.c 
b/drivers/media/platform/rockchip/isp1/rkisp1.c
new file mode 100644
index ..bb16c8118c16
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/rkisp1.c
@@ -0,0 +1,1177 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "common.h"
+#include "regs.h"
+
+#define CIF_ISP_INPUT_W_MAX4032
+#define CIF_ISP_INPUT_H_MAX3024
+#define CIF_ISP_INPUT_W_MIN32
+#define CIF_ISP_INPUT_H_MIN32
+#define CIF_ISP_OUTPUT_W_MAX   CIF_ISP_INPUT_W_MAX
+#define CIF_ISP_OUTPUT_H_MAX   CIF_ISP_INPUT_H_MAX
+#define CIF_ISP_OUTPUT_W_MIN   CIF_ISP_INPUT_W_MIN
+#define CIF_ISP_OUTPUT_H_MIN   CIF_ISP_INPUT_H_MIN
+
+/*
+ * NOTE: MIPI controller and input MUX are also configured in this file,
+ * because ISP Subdev is not only describe ISP submodule(input size,format, 
output size, format),
+ * but also a virtual route device.
+ */
+
+/*
+ * There are many variables named with format/frame in below code,
+ * please see here for their meaning.
+ *
+ * Cropping regions of ISP
+ *
+ * +-+
+ * | Sensor image|
+ * | +---+   |
+ * | | ISP_ACQ (for black level) |   |
+ * | | in_frm|   |
+ * | | ++|   |
+ * | | |ISP_OUT ||   |
+ * | | |in_crop ||   |
+ * | | |+-+ ||   |
+ * | | ||   ISP_IS| ||   |
+ * | | ||   rkisp1_isp_subdev: out_crop   | ||   |
+ * | | |+-+ ||   |
+ * | | ++|   |
+ * | +---+   |
+ * +-+
+ */
+
+static inline struct rkisp1_device *sd_to_isp_dev(struct v4l2_subdev *sd)
+{
+   return container_of(sd->v4l2_dev, struct rkisp1_device, v4l2_dev);
+}
+
+/* Get sensor by enabled media link */
+static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
+{
+   struct media_pad *local;
+   struct media_entity *sensor_me;
+
+   local = >entity.pads[RKISP1_ISP_PAD_SINK];
+   sensor_me = media_entity_remote_pad(local)->entity;
+
+   return media_entity_to_v4l2_subdev(sensor_me);
+}
+
+static struct rkisp1_sensor_info *sd_to_sensor(struct rkisp1_device *dev,
+  struct v4l2_subdev *sd)
+{
+   int i;
+
+   for (i = 0; i < dev->num_sensors; ++i)
+   if (dev->sensors[i].sd == sd)
+   return >sensors[i];
+
+   return NULL;
+}
+
+/  register operations /
+
+/*
+ * Image Stabilization.
+ * This should only be called when configuring CIF
+ * or at the frame end interrupt
+ */
+static void rkisp1_config_ism(struct rkisp1_device *dev)
+{
+   void __iomem *base = dev->base_addr;
+   struct v4l2_rect *out_crop = >isp_sdev.out_crop;
+   u32 val;
+
+   writel(0, base + CIF_ISP_IS_RECENTER);
+   writel(0, base + CIF_ISP_IS_MAX_DX);
+   writel(0, base + CIF_ISP_IS_MAX_DY);
+   writel(0, base + CIF_ISP_IS_DISPLACE);
+   writel(out_crop->left, base + CIF_ISP_IS_H_OFFS);
+   writel(out_crop->top, base + CIF_ISP_IS_V_OFFS);
+   writel(out_crop->width, base + CIF_ISP_IS_H_SIZE);
+   writel(out_crop->height, base + CIF_ISP_IS_V_SIZE);
+
+   /* IS(Image Stabilization) is always on, working as output crop */
+   writel(1, base + CIF_ISP_IS_CTRL);
+   val = readl(base + CIF_ISP_CTRL);
+   val |= CIF_ISP_CTRL_ISP_CFG_UPD;
+   writel(val, base + CIF_ISP_CTRL);
+}
+
+/*
+ * configure isp blocks with input format, 

[PATCH v6 09/17] media: rkisp1: add rockchip isp1 core driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add the core driver for rockchip isp1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/Kconfig|  10 +
 drivers/media/platform/Makefile   |   1 +
 drivers/media/platform/rockchip/isp1/Makefile |   8 +
 drivers/media/platform/rockchip/isp1/common.h | 110 +
 drivers/media/platform/rockchip/isp1/dev.c| 626 ++
 drivers/media/platform/rockchip/isp1/dev.h|  93 
 6 files changed, 848 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/Makefile
 create mode 100644 drivers/media/platform/rockchip/isp1/common.h
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.c
 create mode 100644 drivers/media/platform/rockchip/isp1/dev.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 614fbef08ddc..3dff763b731d 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS
select VIDEOBUF2_DMA_SG
select V4L2_FWNODE
 
+config VIDEO_ROCKCHIP_ISP1
+   tristate "Rockchip Image Signal Processing v1 Unit driver"
+   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_FWNODE
+   default n
+   ---help---
+ Support for ISP1 on the rockchip SoC.
+
 config VIDEO_S3C_CAMIF
tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 7f3080437be6..0d5e1b3e6f22 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1)  += rockchip/isp1/
 obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip/rga/
 
 obj-y  += omap/
diff --git a/drivers/media/platform/rockchip/isp1/Makefile 
b/drivers/media/platform/rockchip/isp1/Makefile
new file mode 100644
index ..18af64853734
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/Makefile
@@ -0,0 +1,8 @@
+obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) +=   video_rkisp1.o
+video_rkisp1-objs +=   rkisp1.o \
+   dev.o \
+   regs.o \
+   isp_stats.o \
+   isp_params.o \
+   mipi_dphy_sy.o \
+   capture.o
diff --git a/drivers/media/platform/rockchip/isp1/common.h 
b/drivers/media/platform/rockchip/isp1/common.h
new file mode 100644
index ..b58cdaf7da06
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/common.h
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef _RKISP1_COMMON_H
+#define _RKISP1_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RKISP1_DEFAULT_WIDTH   800
+#define RKISP1_DEFAULT_HEIGHT  600
+
+#define RKISP1_MAX_STREAM  2
+#define RKISP1_STREAM_SP   0
+#define RKISP1_STREAM_MP   1
+
+#define RKISP1_PLANE_Y 0
+#define RKISP1_PLANE_CB1
+#define RKISP1_PLANE_CR2
+
+enum rkisp1_sd_type {
+   RKISP1_SD_SENSOR,
+   RKISP1_SD_PHY_CSI,
+   RKISP1_SD_VCM,
+   RKISP1_SD_FLASH,
+   RKISP1_SD_MAX,
+};
+
+/* One structure per video node */
+struct rkisp1_vdev_node {
+   struct vb2_queue buf_queue;
+   /* vfd lock */
+   struct mutex vlock;
+   struct video_device vdev;
+   struct media_pad pad;
+};
+
+enum rkisp1_fmt_pix_type {
+   FMT_YUV,
+   FMT_RGB,
+   FMT_BAYER,
+   FMT_JPEG,
+   FMT_MAX
+};
+
+enum rkisp1_fmt_raw_pat_type {
+   RAW_RGGB = 0,
+   RAW_GRBG,
+   RAW_GBRG,
+   RAW_BGGR,
+};
+
+enum rkisp1_state {
+   /* path not yet opened: */
+   RKISP1_STATE_DISABLED,
+   /* path opened and configured, ready for streaming: */
+   RKISP1_STATE_READY,
+   /* path is streaming: */
+   RKISP1_STATE_STREAMING
+};
+
+struct rkisp1_buffer {
+   struct vb2_v4l2_buffer vb;
+   struct list_head queue;
+   union {
+   u32 buff_addr[VIDEO_MAX_PLANES];
+   void 

[PATCH v6 08/17] media: rkisp1: add capture device driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from ISP1.

Signed-off-by: Jacob Chen 
Signed-off-by: Shunqian Zheng 
Signed-off-by: Yichong Zhong 
Signed-off-by: Jacob Chen 
Signed-off-by: Eddie Cai 
Signed-off-by: Jeffy Chen 
Signed-off-by: Allon Huang 
Signed-off-by: Tomasz Figa 
---
 drivers/media/platform/rockchip/isp1/capture.c | 1751 
 drivers/media/platform/rockchip/isp1/capture.h |  167 +++
 drivers/media/platform/rockchip/isp1/regs.c|  239 
 drivers/media/platform/rockchip/isp1/regs.h| 1550 +
 4 files changed, 3707 insertions(+)
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.c
 create mode 100644 drivers/media/platform/rockchip/isp1/capture.h
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.c
 create mode 100644 drivers/media/platform/rockchip/isp1/regs.h

diff --git a/drivers/media/platform/rockchip/isp1/capture.c 
b/drivers/media/platform/rockchip/isp1/capture.c
new file mode 100644
index ..53484f882704
--- /dev/null
+++ b/drivers/media/platform/rockchip/isp1/capture.c
@@ -0,0 +1,1751 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Rockchip isp1 driver
+ *
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "dev.h"
+#include "regs.h"
+
+/*
+ * NOTE:
+ * 1. There are two capture video devices in rkisp1, selfpath and mainpath
+ * 2. Two capture device have separated memory-interface/crop/scale units.
+ * 3. Besides describing stream hardware, this file also contain entries
+ *for pipeline operations.
+ * 4. The register read/write operations in this file are put into regs.c.
+ */
+
+/*
+ * differences between selfpatch and mainpath
+ * available mp sink input: isp
+ * available sp sink input : isp, dma(TODO)
+ * available mp sink pad fmts: yuv422, raw
+ * available sp sink pad fmts: yuv422, yuv420..
+ * available mp source fmts: yuv, raw, jpeg(TODO)
+ * available sp source fmts: yuv, rgb
+ */
+
+#define CIF_ISP_REQ_BUFS_MIN 1
+#define CIF_ISP_REQ_BUFS_MAX 8
+
+#define STREAM_PAD_SINK0
+#define STREAM_PAD_SOURCE  1
+
+#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416
+#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT3312
+#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920
+#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT1920
+#define STREAM_MIN_RSZ_OUTPUT_WIDTH32
+#define STREAM_MIN_RSZ_OUTPUT_HEIGHT   16
+
+#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH
+#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT
+#define STREAM_MIN_MP_SP_INPUT_WIDTH   32
+#define STREAM_MIN_MP_SP_INPUT_HEIGHT  32
+
+/* Get xsubs and ysubs for fourcc formats
+ *
+ * @xsubs: horizontal color samples in a 4*4 matrix, for yuv
+ * @ysubs: vertical color samples in a 4*4 matrix, for yuv
+ */
+static int fcc_xysubs(u32 fcc, u32 *xsubs, u32 *ysubs)
+{
+   switch (fcc) {
+   case V4L2_PIX_FMT_GREY:
+   case V4L2_PIX_FMT_YUV444M:
+   *xsubs = 1;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_YUYV:
+   case V4L2_PIX_FMT_YVYU:
+   case V4L2_PIX_FMT_VYUY:
+   case V4L2_PIX_FMT_YUV422P:
+   case V4L2_PIX_FMT_NV16:
+   case V4L2_PIX_FMT_NV61:
+   case V4L2_PIX_FMT_YVU422M:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   case V4L2_PIX_FMT_NV21:
+   case V4L2_PIX_FMT_NV12:
+   case V4L2_PIX_FMT_NV21M:
+   case V4L2_PIX_FMT_NV12M:
+   case V4L2_PIX_FMT_YUV420:
+   case V4L2_PIX_FMT_YVU420:
+   *xsubs = 2;
+   *ysubs = 2;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int mbus_code_xysubs(u32 code, u32 *xsubs, u32 *ysubs)
+{
+   switch (code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   case MEDIA_BUS_FMT_YUYV8_1X16:
+   case MEDIA_BUS_FMT_YVYU8_1X16:
+   case MEDIA_BUS_FMT_UYVY8_1X16:
+   case MEDIA_BUS_FMT_VYUY8_1X16:
+   *xsubs = 2;
+   *ysubs = 1;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int mbus_code_sp_in_fmt(u32 code, u32 *format)
+{
+   switch (code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   *format = MI_CTRL_SP_INPUT_YUV422;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct capture_fmt mp_fmts[] = {
+   /* yuv422 */
+   {
+  

[PATCH v6 10/17] dt-bindings: Document the Rockchip ISP1 bindings

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip ISP1

Signed-off-by: Jacob Chen 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/media/rockchip-isp1.txt| 69 ++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-isp1.txt 
b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
new file mode 100644
index ..4631a4b7c88a
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-isp1.txt
@@ -0,0 +1,69 @@
+Rockchip SoC Image Signal Processing unit v1
+--
+
+Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs
+which contains image processing, scaling, and compression funcitons.
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-cif-isp";
+   "rockchip,rk3399-cif-isp";
+- reg : offset and length of the register set for the device.
+- interrupts: should contain ISP interrupt.
+- clocks: phandle to the required clocks.
+- clock-names: required clock name.
+- iommus: required a iommu node.
+
+port node
+---
+
+The device node should contain one 'port' child node with child 'endpoint'
+nodes, according to the bindings defined in Documentation/devicetree/bindings/
+media/video-interfaces.txt.
+
+- endpoint(parallel):
+   - remote-endpoint: Connecting to a sensor with a parallel video bus.
+   - parallel_bus properties: Refer to Documentation/devicetree/bindings/
+   media/video-interfaces.txt.
+- endpoint(mipi):
+   - remote-endpoint: Connecting to Rockchip MIPI-DPHY,
+   which is defined in rockchip-mipi-dphy.txt.
+
+The port node must contain at least one endpoint, either parallel or mipi.
+It could have multiple endpoints, but please note the hardware don't support
+two sensors work at a time, they are supposed to work asynchronously.
+
+Device node example
+---
+
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* mipi */
+   isp0_mipi_in: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_rx0_out>;
+   };
+
+   /* parallel */
+   isp0_parallel_in: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   bus-width = <8>;
+   };
+   };
+   };
-- 
2.16.1



[PATCH v6 12/17] ARM: dts: rockchip: add isp node for rk3288

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

rk3288 have a Embedded 13M ISP

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ad6bda85c85a..6c122aaf06a7 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -962,6 +962,23 @@
status = "disabled";
};
 
+   isp: isp@ff91 {
+   compatible = "rockchip,rk3288-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP>, < ACLK_ISP>,
+< HCLK_ISP>, < PCLK_ISP_IN>,
+< SCLK_ISP_JPE>;
+   clock-names = "clk_isp", "aclk_isp",
+ "hclk_isp", "pclk_isp_in",
+ "sclk_isp_jpe";
+   assigned-clocks = < SCLK_ISP>, < SCLK_ISP_JPE>;
+   assigned-clock-rates = <4>, <4>;
+   power-domains = < RK3288_PD_VIO>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.16.1



[PATCH v6 13/17] ARM: dts: rockchip: add rx0 mipi-phy for rk3288

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

It's a Designware MIPI D-PHY, used by ISP in rk3288.

Signed-off-by: Jacob Chen 
---
 arch/arm/boot/dts/rk3288.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6c122aaf06a7..3a530b72c057 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -864,6 +864,13 @@
status = "disabled";
};
 
+   mipi_phy_rx0: mipi-phy-rx0 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
io_domains: io-domains {
compatible = "rockchip,rk3288-io-voltage-domain";
status = "disabled";
-- 
2.16.1



[PATCH v6 15/17] arm64: dts: rockchip: add isp0 node for rk3399

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng 

rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 2605118d4b4c..14ed016f2fdd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1614,6 +1614,21 @@
status = "disabled";
};
 
+   isp0: isp0@ff91 {
+   compatible = "rockchip,rk3399-cif-isp";
+   reg = <0x0 0xff91 0x0 0x4000>;
+   interrupts = ;
+   clocks = < SCLK_ISP0>,
+< ACLK_ISP0>, < ACLK_ISP0_WRAPPER>,
+< HCLK_ISP0>, < HCLK_ISP0_WRAPPER>;
+   clock-names = "clk_isp",
+ "aclk_isp", "aclk_isp_wrap",
+ "hclk_isp", "hclk_isp_wrap";
+   power-domains = < RK3399_PD_ISP0>;
+   iommus = <_mmu>;
+   status = "disabled";
+   };
+
isp0_mmu: iommu@ff914000 {
compatible = "rockchip,iommu";
reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
-- 
2.16.1



[PATCH v6 11/17] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add DT bindings documentation for Rockchip MIPI D-PHY RX

Signed-off-by: Jacob Chen 
Reviewed-by: Rob Herring 
---
 .../bindings/media/rockchip-mipi-dphy.txt  | 90 ++
 1 file changed, 90 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt 
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
new file mode 100644
index ..d83700faf4c4
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
@@ -0,0 +1,90 @@
+Rockchip SoC MIPI RX D-PHY
+-
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-mipi-dphy"
+   "rockchip,rk3399-mipi-dphy"
+- clocks : list of clock specifiers, corresponding to entries in
+   clock-names property;
+- clock-names: required clock name.
+
+MIPI RX D-PHY use registers in "general register files", it
+should be a child of the GRF.
+MIPI TXRX D-PHY have its own registers, it must have a reg property.
+
+Optional properties:
+- reg: offset and length of the register set for the device.
+- rockchip,grf: MIPI TX1RX1 D-PHY not only has its own register but also
+   the GRF, so it is only necessary for MIPI TX1RX1 D-PHY.
+
+port node
+---
+
+The device node should contain two 'port' child nodes, according to the 
bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+The first port show the sensors connected in this mipi-dphy.
+- endpoint:
+   - remote-endpoint: Linked to a sensor with a MIPI CSI-2 video bus.
+   - data-lanes : (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; the
+   D-PHY can't reroute lanes, so the array's content should
+   be consecutive and only its length is meaningful.
+
+The port node must contain at least one endpoint. It could have multiple 
endpoints
+linked to different sensors, but please note that they are not supposed to be
+activated at the same time.
+
+The second port should be connected to isp node.
+- endpoint:
+   - remote-endpoint:  Linked to Rockchip ISP1, which is defined
+   in rockchip-isp1.txt.
+
+Device node example
+---
+
+grf: syscon@ff77 {
+   compatible = "rockchip,rk3288-grf", "syscon", "simple-mfd";
+
+...
+
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   mipi_in_wcam: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_out>;
+   data-lanes = <1 2>;
+   };
+   mipi_in_ucam: endpoint@1 {
+   reg = <1>;
+   remote-endpoint = <_out>;
+   data-lanes = <1>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   dphy_rx0_out: endpoint {
+   remote-endpoint = <_mipi_in>;
+   };
+   };
+   };
+   };
+};
-- 
2.16.1



[PATCH v6 14/17] ARM: dts: rockchip: Add dts mipi-dphy TXRX1 node for rk3288

2018-03-08 Thread Jacob Chen
From: Wen Nuan 

Change-Id: I0b6122b2b34ae0f24f0d4ac1bbe6018cac4e
Signed-off-by: Wen Nuan 
---
 arch/arm/boot/dts/rk3288.dtsi | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 3a530b72c057..ed05f3d77358 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -1164,6 +1164,15 @@
};
};
 
+   mipi_phy_tx1rx1: mipi-phy-tx1rx1@ff968000 {
+   compatible = "rockchip,rk3288-mipi-dphy";
+   reg = <0x0 0xff968000 0x0 0x4000>;
+   rockchip,grf = <>;
+   clocks = < SCLK_MIPIDSI_24M>, < PCLK_MIPI_CSI>;
+   clock-names = "dphy-ref", "pclk";
+   status = "disabled";
+   };
+
edp: dp@ff97 {
compatible = "rockchip,rk3288-dp";
reg = <0x0 0xff97 0x0 0x4000>;
-- 
2.16.1



[PATCH v6 16/17] arm64: dts: rockchip: add rx0 mipi-phy for rk3399

2018-03-08 Thread Jacob Chen
From: Shunqian Zheng 

It's a Designware MIPI D-PHY, used for ISP0 in rk3399.

Signed-off-by: Shunqian Zheng 
Signed-off-by: Jacob Chen 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 14ed016f2fdd..d18ab8f56ef2 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1308,6 +1308,16 @@
status = "disabled";
};
 
+   mipi_dphy_rx0: mipi-dphy-rx0 {
+   compatible = "rockchip,rk3399-mipi-dphy";
+   clocks = < SCLK_MIPIDPHY_REF>,
+   < SCLK_DPHY_RX0_CFG>,
+   < PCLK_VIO_GRF>;
+   clock-names = "dphy-ref", "dphy-cfg", "grf";
+   power-domains = < RK3399_PD_VIO>;
+   status = "disabled";
+   };
+
u2phy0: usb2-phy@e450 {
compatible = "rockchip,rk3399-usb2phy";
reg = <0xe450 0x10>;
-- 
2.16.1



[PATCH v6 17/17] MAINTAINERS: add entry for Rockchip ISP1 driver

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

Add MAINTAINERS entry for the rockchip isp1 driver.
This driver is maintained by rockchip officially and it
will be used for rockchip SoC on all linux-kernel based OS.

Signed-off-by: Jacob Chen 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4623caf8d72d..7a9ff4fa4592 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11852,6 +11852,16 @@ F: drivers/hid/hid-roccat*
 F: include/linux/hid-roccat*
 F: Documentation/ABI/*/sysfs-driver-hid-roccat*
 
+ROCKCHIP ISP V1 DRIVER
+M: Jacob chen 
+M: Shunqian Zheng 
+M: Yichong Zhong 
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/media/platform/rockchip/isp1/
+F: Documentation/devicetree/bindings/media/rockchip-isp1.txt
+F: Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
+
 ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER
 M: Jacob chen 
 L: linux-media@vger.kernel.org
-- 
2.16.1



[PATCH v6 02/17] media: doc: add document for rkisp1 meta buffer format

2018-03-08 Thread Jacob Chen
From: Jacob Chen 

This commit add docuemnt for rkisp1 meta buffer format

Signed-off-by: Jacob Chen 
Acked-by: Hans Verkuil 
---
 Documentation/media/uapi/v4l/meta-formats.rst|  2 ++
 .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst | 20 
 .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst   | 18 ++
 3 files changed, 40 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst

diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
b/Documentation/media/uapi/v4l/meta-formats.rst
index 0c4e1ecf5879..44e7edbf1dae 100644
--- a/Documentation/media/uapi/v4l/meta-formats.rst
+++ b/Documentation/media/uapi/v4l/meta-formats.rst
@@ -15,3 +15,5 @@ These formats are used for the :ref:`metadata` interface only.
 pixfmt-meta-uvc
 pixfmt-meta-vsp1-hgo
 pixfmt-meta-vsp1-hgt
+pixfmt-meta-rkisp1-params
+pixfmt-meta-rkisp1-stat
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
new file mode 100644
index ..2ff4f4309795
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst
@@ -0,0 +1,20 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-params:
+
+***
+V4L2_META_FMT_RK_ISP1_PARAMS
+***
+
+Rockchip ISP1 Parameters Data
+
+Description
+===
+
+This format describes input parameters for the Rockchip ISP1.
+
+It uses c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in
+the ``linux/rkisp1-config.h`` header file, see it for details.
+
+The parameters consist of multiple modules.
+The module won't be updated if the correspond bit was not set in 
module_*_update.
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
new file mode 100644
index ..dca8befe58f1
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
@@ -0,0 +1,18 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-rkisp1-stat:
+
+***
+V4L2_META_FMT_RK_ISP1_STAT_3A
+***
+
+Rockchip ISP1 Statistics Data
+
+Description
+===
+
+This format describes image color statistics information generated by the 
Rockchip
+ISP1.
+
+It use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in
+the ``linux/cifisp_stat.h`` header file, see it for details.
-- 
2.16.1



[PATCH] media: em28xx-cards: fix em28xx_duplicate_dev()

2018-03-08 Thread Dan Carpenter
There is a double sizeof() typo here so we don't duplicate the struct
properly.

Fixes: be7fd3c3a8c5 ("media: em28xx: Hauppauge DualHD second tuner 
functionality")
Signed-off-by: Dan Carpenter 

diff --git a/drivers/media/usb/em28xx/em28xx-cards.c 
b/drivers/media/usb/em28xx/em28xx-cards.c
index 6e8247849c4f..6e0e67d23876 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -3515,7 +3515,7 @@ static int em28xx_duplicate_dev(struct em28xx *dev)
dev->dev_next = NULL;
return -ENOMEM;
}
-   memcpy(sec_dev, dev, sizeof(sizeof(*sec_dev)));
+   memcpy(sec_dev, dev, sizeof(*sec_dev));
/* Check to see next free device and mark as used */
do {
nr = find_first_zero_bit(em28xx_devused, EM28XX_MAXBOARDS);


[PATCH] media: ov5640: fix frame interval enumeration

2018-03-08 Thread Hugues Fruchet
Driver must reject frame interval enumeration of unsupported resolution.
This was detected by v4l2-compliance format ioctl test:
v4l2-compliance Format ioctls:
  info: found 2 frameintervals for pixel format 4745504a and size 176x144
  fail: v4l2-test-formats.cpp(123):
   found frame intervals for invalid size 177x144
  test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: FAIL

Signed-off-by: Hugues Fruchet 
---
 drivers/media/i2c/ov5640.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 676f635..28dc687 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1400,6 +1400,9 @@ static int ov5640_set_virtual_channel(struct ov5640_dev 
*sensor)
if (nearest && i < 0)
mode = _mode_data[fr][0];
 
+   if (!nearest && i < 0)
+   return NULL;
+
return mode;
 }
 
-- 
1.9.1



Re: [PATCH] media: ov5640: fix get_/set_fmt colorspace related fields

2018-03-08 Thread Hugues FRUCHET
Hi Sakari,

This is the right one and it's OK to swap the lines for local variables, 
I'll keep this in mind for next changes.

Best regards,
Hugues.

On 03/07/2018 09:13 AM, Sakari Ailus wrote:
> Hi Hugues,
> 
> On Tue, Mar 06, 2018 at 06:04:39PM +0100, Hugues Fruchet wrote:
>> Fix set of missing colorspace related fields in get_/set_fmt.
>> Detected by v4l2-compliance tool.
>>
>> Signed-off-by: Hugues Fruchet 
> 
> Could you confirm this is the one you intended to send? There are two
> others with similar content.
> 
> ...
> 
>> @@ -2497,16 +2504,22 @@ static int ov5640_probe(struct i2c_client *client,
>>  struct fwnode_handle *endpoint;
>>  struct ov5640_dev *sensor;
>>  int ret;
>> +struct v4l2_mbus_framefmt *fmt;
> 
> This one I'd arrange before ret. The local variable declarations should
> generally look like a Christmas tree but upside down.
> 
> If you're happy with that, I can swap the two lines as well (no need for
> v2).
> 
>>   
>>  sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
>>  if (!sensor)
>>  return -ENOMEM;
>>   
>>  sensor->i2c_client = client;
>> -sensor->fmt.code = MEDIA_BUS_FMT_UYVY8_2X8;
>> -sensor->fmt.width = 640;
>> -sensor->fmt.height = 480;
>> -sensor->fmt.field = V4L2_FIELD_NONE;
>> +fmt = >fmt;
>> +fmt->code = ov5640_formats[0].code;
>> +fmt->colorspace = ov5640_formats[0].colorspace;
>> +fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace);
>> +fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
>> +fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace);
>> +fmt->width = 640;
>> +fmt->height = 480;
>> +fmt->field = V4L2_FIELD_NONE;
>>  sensor->frame_interval.numerator = 1;
>>  sensor->frame_interval.denominator = ov5640_framerates[OV5640_30_FPS];
>>  sensor->current_fr = OV5640_30_FPS;
> 

Re: [PATCH v2] i2c: adv748x: afe: fix sparse warning

2018-03-08 Thread Geert Uytterhoeven
On Thu, Mar 8, 2018 at 12:02 AM, Niklas Söderlund
 wrote:
> CC linux-media.
>
> It's linux-media@vger.kernel.org not linux-me...@vger.kernel.or, sorry
> for the noise.
>
> On 2018-03-07 23:58:16 +0100, Niklas Söderlund wrote:
>> This fixes the following sparse warning:
>>
>> drivers/media/i2c/adv748x/adv748x-afe.c:294:34:expected unsigned int 
>> [usertype] *signal
>> drivers/media/i2c/adv748x/adv748x-afe.c:294:34:got int *
>> drivers/media/i2c/adv748x/adv748x-afe.c:294:34: warning: incorrect type in 
>> argument 2 (different signedness)
>>
>> Signed-off-by: Niklas Söderlund 

Reviewed-by: Geert Uytterhoeven 

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