Add tw9910 driver
PATCH v6 1/1 Add tw9910 driver
This patch adds tw9910 driver that use soc_camera framework. It was tested on SH Migo-r board and mplayer.
---
v5 -> v6
o change calculation mothod of select_norm
o change dev_info -> dev_dbg in start_capture
o add i2c_set_clientdata(client, NULL) in remove
o add SOCAM_DATA_ACTIVE_HIGH on query_bus_param
drivers/media/video/Kconfig | 6 + drivers/media/video/Makefile | 1 + drivers/media/video/tw9910.c | 941 +++++++++++++++++++++++++++++++++++++++ include/media/tw9910.h | 39 ++ include/media/v4l2-chip-ident.h | 3 + 5 files changed, 990 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/tw9910.c create mode 100644 include/media/tw9910.h
drivers/media/video/Kconfig +6 -0
@@ -750,6 +750,12 @@ config MT9V022_PCA9536_SWITCH Select this if your MT9V022 camera uses a PCA9536 I2C GPIO extender to switch between 8 and 10 bit datawidth modes +config SOC_CAMERA_TW9910 + tristate "tw9910 support" + depends on SOC_CAMERA && I2C + help + This is a tw9910 video driver + config SOC_CAMERA_PLATFORM tristate "platform camera support" depends on SOC_CAMERA
drivers/media/video/Makefile +1 -0
@@ -136,6 +136,7 @@ obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o obj-$(CONFIG_SOC_CAMERA_OV772X) += ov772x.o obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o +obj-$(CONFIG_SOC_CAMERA_TW9910) += tw9910.o obj-$(CONFIG_VIDEO_AU0828) += au0828/
drivers/media/video/tw9910.c new file +941 -0
941 lines not on this page · raw message
include/media/tw9910.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* tw9910 Driver header +* +* Copyright (C) 2008 Renesas Solutions Corp. +* Kuninori Morimoto <[email protected]> +* +* Based on ov772x.h +* +* Copyright (C) Kuninori Morimoto <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __TW9910_H__ +#define __TW9910_H__ + +#include <media/soc_camera.h> + +enum MPOUT_pin { +MPO_VLOSS , +MPO_HLOCK , +MPO_SLOCK , +MPO_VLOCK , +MPO_MONO , +MPO_DET50 , +MPO_FIELD , +MPO_RTCO , +}; + +struct tw9910_video_info { +unsigned long buswidth; +enum MPOUT_pin mpout; +struct soc_camera_link link; +}; + + +#endif /* __TW9910_H__ */
include/media/v4l2-chip-ident.h +3 -0
@@ -84,6 +84,9 @@ enum {/* module wm8775: just ident 8775 */ V4L2_IDENT_WM8775 =8775 , +/* module tw9910: just ident 9910 */ +V4L2_IDENT_TW9910 =9910 , +/* module cs53132a: just ident 53132 */ V4L2_IDENT_CS53l32A = 53132,
Signature · 6 lines
1.5.6.3 -- video4linux-list mailing list Unsubscribe mailto:[email protected]?subject=unsubscribe https://www.redhat.com/mailman/listinfo/video4linux-list
Quoted 4 lines · Kuninori Morimoto
This patch adds tw9910 driver that use
soc_cameraframework. It was tested on SH Migo-r board and mplayer.Signed-off-by Kuninori Morimoto <[email protected]>
Ok, let's do it this way. We take this version as a basis, but I only commit it after I get an incremental improvement patch from you:
Quoted 11 lines
drivers/media/video/tw9910.c new file +11
-0+static const struct tw9910_scale_ctrl * +tw9910_select_norm (struct soc_camera_device *icd,struct v4l2_pix_format *pix) +{ +const struct tw9910_scale_ctrl *scale; +const struct tw9910_scale_ctrl *ret; +v4l2_std_id norm = icd->vdev->current_norm; +int size; +int diff, tmp; +int i; + +if (norm &V4L2_STD_NTSC ) {
drivers/media/video/tw9910.c line 496
Quoted 10 lines
drivers/media/video/tw9910.c new file +10
-0+ scale = tw9910_ntsc_scales; + size =ARRAY_SIZE (tw9910_ntsc_scales); + }else if (norm &V4L2_STD_PAL ) { + scale = tw9910_pal_scales; + size =ARRAY_SIZE (tw9910_pal_scales); + }else { +return NULL ; + } + + diff = icd->width_max + icd->height_max;
Here diff = 768 + 576 = 1344. Now if anyone requests something big like 2048x1536 you don't find any scale for it. Then pix->width and pix->height are of type __u32. Then if anyone sets them to 0xffffffff (maybe to get the maximum possible picture) you get a problem with your int diff, tmp. Better
+ __u32 diff = 0xffffffff, tmp;
Quoted 13 lines
drivers/media/video/tw9910.c new file +13
-0+ ret =NULL ; + +for (i =0 ; i < size; i++) { + tmp =abs (pix->width - scale[i].width) + +abs (pix->height - scale[i].height); +if (tmp < diff) { + diff = tmp; + ret = scale + i; + } + } + +return ret; +}
[snip]
Quoted 12 lines
drivers/media/video/tw9910.c new file +12
-0+static int tw9910_start_capture (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); + +if (!priv->scale) { +dev_err (&icd->dev,"norm select error\n" ); +return -EPERM ; + } + + dev_dbg(&icd->dev, "%s %dx%d\n", + priv->scale->name, + priv->scale->width,
drivers/media/video/tw9910.c line 563
Quoted 10 lines
drivers/media/video/tw9910.c new file +10
-0+ priv->scale->height); + +return 0 ; +} + +static int tw9910_stop_capture (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); + + priv->scale =NULL ;
This is wrong. If someone does
S_FMT
STREAMON
STREAMOFF
STREAMON
you fail.
drivers/media/video/tw9910.c line 566
Quoted 3 lines
drivers/media/video/tw9910.c new file +3
-0+ icd->vdev->current_norm =V4L2_STD_NTSC ; + +tw9910_reset (priv->client);
I think, you should leave your driver and the chip configured, so, both of these should go.
Quoted 25 lines
drivers/media/video/tw9910.c new file +25
-0+return 0 ; +} + +static int tw9910_set_bus_param (struct soc_camera_device *icd, +unsigned long flags) +{ +return 0 ; +} + +static unsigned long tw9910_query_bus_param (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); +struct soc_camera_link *icl = priv->client->dev.platform_data; +unsigned long flags =SOCAM_PCLK_SAMPLE_RISING |SOCAM_MASTER | +SOCAM_VSYNC_ACTIVE_HIGH |SOCAM_HSYNC_ACTIVE_HIGH | +SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth; + +return soc_camera_apply_sensor_flags (icl, flags); +} + +static int tw9910_get_chip_id (struct soc_camera_device *icd, +struct v4l2_chip_ident *id) +{ + id->ident =V4L2_IDENT_TW9910 ; + id->revision =0 ;
drivers/media/video/tw9910.c line 601
Quoted 10 lines
drivers/media/video/tw9910.c new file +10
-0+ +return 0 ; +} + +static int tw9910_set_std (struct soc_camera_device *icd, +v4l2_std_id *a) +{ +int ret = -EINVAL ; + +if (*a &V4L2_STD_NTSC || *a &V4L2_STD_PAL )
+ if (*a & (V4L2_STD_NTSC | V4L2_STD_PAL))
would be enough
[snip]
Quoted 79 lines
drivers/media/video/tw9910.c new file +79
-0+static int tw9910_set_fmt (struct soc_camera_device *icd,__u32 pixfmt, +struct v4l2_rect *rect) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); +int ret = -EINVAL ; +u8 val; + +/* +* reset hardware +*/ +tw9910_reset (priv->client); + ret =tw9910_write_array (priv->client, tw9910_default_regs); +if (ret <0 ) +return ret; +/* +* set bus width +*/ + val =0x00 ; +if (SOCAM_DATAWIDTH_16 == priv->info->buswidth) + val =LEN ; + + ret =tw9910_mask_set (priv->client,OPFORM ,LEN , val); +if (ret <0 ) +return ret; + +/* +* select MPOUT behavior +*/ +switch (priv->info->mpout) { +case MPO_VLOSS : + val =RTSEL_VLOSS ;break ; +case MPO_HLOCK : + val =RTSEL_HLOCK ;break ; +case MPO_SLOCK : + val =RTSEL_SLOCK ;break ; +case MPO_VLOCK : + val =RTSEL_VLOCK ;break ; +case MPO_MONO : + val =RTSEL_MONO ;break ; +case MPO_DET50 : + val =RTSEL_DET50 ;break ; +case MPO_FIELD : + val =RTSEL_FIELD ;break ; +case MPO_RTCO : + val =RTSEL_RTCO ;break ; +default : + val =0 ; + } + + ret =tw9910_mask_set (priv->client,VBICNTL ,RTSEL_MASK , val); +if (ret <0 ) +return ret; + +/* +* set scale +*/ + ret =tw9910_set_scale (priv->client, priv->scale); +if (ret <0 ) +return ret; + +/* +* set cropping +*/ + ret =tw9910_set_cropping (priv->client, &tw9910_cropping_ctrl); +if (ret <0 ) +return ret; + +/* +* set hsync +*/ + ret =tw9910_set_hsync (priv->client, &tw9910_hsync_ctrl); + +return ret; +} + +static int tw9910_try_fmt (struct soc_camera_device *icd, +struct v4l2_format *f) +{ +struct v4l2_pix_format *pix = &f->fmt.pix;
drivers/media/video/tw9910.c line 740
Quoted 10 lines
drivers/media/video/tw9910.c new file +10
-0+ struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); + +if (V4L2_FIELD_ANY == pix->field) { + pix->field =V4L2_FIELD_INTERLACED ; + }else if (V4L2_FIELD_INTERLACED != pix->field) { +dev_err (&icd->dev,"Field type invalid.\n" ); +return -EINVAL ; + } + + priv->scale =tw9910_select_norm (icd, pix);
This is wrong too. According to the API TRY_FMT may be called at any time (also during a running streaming) and should _not_ change driver's state. And as you can see in soc_camera.c::soc_camera_s_fmt_vid_cap() we're not holding the mutex while calling soc_camera_try_fmt_vid_cap(), so, you have no guarantee in your set_fmt, that your try_fmt was last called from soc_camera_s_fmt_vid_cap() or even worse that it's not being called concurrently. Therefore, you have to call tw9910_select_norm() once more in your set_fmt, and in try_fmt you only verify if a suitable norm can be found and set pix->height and pix->width accordingly.
include/media/tw9910.h line 30
Quoted 10 lines
include/media/tw9910.h new file +10
-0+enum MPOUT_pin { +MPO_VLOSS , +MPO_HLOCK , +MPO_SLOCK , +MPO_VLOCK , +MPO_MONO , +MPO_DET50 , +MPO_FIELD , +MPO_RTCO , +};
This is an exported enum, so, please make it
enum tw9910_mpout_pin {
TW9910_MPO_VLOSS,
...Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Dear Guennadi
Thank you for checking patch.
Quoted 2 lines
Ok, let's do it this way. We take this version as a basis, but I only commit it after I get an incremental improvement patch from you:
v7 patch ?
Quoted 11 lines
drivers/media/video/tw9910.c line 566
Quoted 8 lines
drivers/media/video/tw9910.c new file +8
-0+static int tw9910_stop_capture (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); + + priv->scale =NULL ; + icd->vdev->current_norm =V4L2_STD_NTSC ; + +tw9910_reset (priv->client);I think, you should leave your driver and the chip configured, so, both of these should go.
sorry. I can not understand about this.
Do you say that it is better ?
--------------------
static int tw9910_stop_capture(struct soc_camera_device *icd)
{
struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd);
tw9910_reset(priv->client);
return 0;
}--------------------
Quoted 10 lines
drivers/media/video/tw9910.c line 585
Quoted 10 lines
drivers/media/video/tw9910.c new file +10
-0+static unsigned long tw9910_query_bus_param (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); +struct soc_camera_link *icl = priv->client->dev.platform_data; +unsigned long flags =SOCAM_PCLK_SAMPLE_RISING |SOCAM_MASTER | +SOCAM_VSYNC_ACTIVE_HIGH |SOCAM_HSYNC_ACTIVE_HIGH | +SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth; + +return soc_camera_apply_sensor_flags (icl, flags); +}
In current git (2008-12-19), ${LINUX}/include/media/soc_camera.h :: soc_camera_bus_param_compatible doesn't check SOCAM_DATA_ACTIVE_XXX.
So I think SOCAM_DATA_ACTIVE_HIGH is not needed here.
But should I add it ? or not ?
Quoted 8 lines
This is wrong too. According to the API
TRY_FMTmay be called at any time (also during a running streaming) and should _not_ change driver's state. And as you can see insoc_camera.c::soc_camera_s_fmt_vid_cap()we're not holding the mutex while callingsoc_camera_try_fmt_vid_cap(), so, you have no guarantee in yourset_fmt, that yourtry_fmtwas last called fromsoc_camera_s_fmt_vid_cap()or even worse that it's not being called concurrently. Therefore, you have to calltw9910_select_norm()once more in yourset_fmt,
OK. I could understand.
Quoted 2 lines
and in
try_fmtyou only verify if a suitable norm can be found and setpix->heightandpix->widthaccordingly.
So I think set_fmt and try_fmt will be like this.
It's OK ?
--------------------
static const struct tw9910_scale_ctrl* tw9910_select_norm(struct soc_camera_device *icd, struct v4l2_rect *rect) {
...
}
static int tw9910_set_fmt( xxx )
{
...
/*
* select suitable norm
*/
priv->scale = tw9910_select_norm(icd, rect);
if (!priv->scale)
return ret;
....
}static int tw9910_try_fmt( xxx )
{
struct v4l2_rect rect;
...
/*
* check pix->field is ANY or INTERLACED
*/
....
/*
* select suitable norm
*/
rect.width = pix->width;
rect.height = pix->height;
scale = tw9910_select_norm(icd, &rect);
if (!scale)
return -EINVAL;
pix->width = scale->width;
pix->height = scale->height;
return 0;
}--------------------
Best regards
--
Kuninori Morimoto
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Quoted 4 lines · On Wed, 24 Dec 2008, [email protected] wrote:
Quoted 2 lines
Ok, let's do it this way. We take this version as a basis, but I only commit it after I get an incremental improvement patch from you:
v7 patch ?
You may choose - what's easier for you. Either you make a v7, or we keep v6, and you make an _incremental_ (i.e., based on v6) patch to address issues that I point out here. If you decide to make an incremental patch, I think, I might merge it with v6, show it to you once more for confirmation and commit that in one go. But just please choose what's easier for you.
Quoted 16 lines
Quoted 11 lines
drivers/media/video/tw9910.c line 566
Quoted 8 lines
drivers/media/video/tw9910.c new file +8
-0+static int tw9910_stop_capture (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); + + priv->scale =NULL ; + icd->vdev->current_norm =V4L2_STD_NTSC ; + +tw9910_reset (priv->client);I think, you should leave your driver and the chip configured, so, both of these should go.
sorry. I can not understand about this.
Do you say that it is better ?
Quoted 8 lines
--------------------
static inttw9910_stop_capture(struct soc_camera_device *icd){ struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); tw9910_reset(priv->client); return 0; }--------------------
No, not quite. Here's what I've written last time:
Quoted 4 lines
Quoted 4 lines
S_FMT-set_fmt
STREAMON -start_capture
STREAMOFF -stop_capture
STREAMON -start_capture
i.e., you should be prepared to restart capture after a stop_capture with the same configuration. By setting
icd->vdev->current_norm = V4L2_STD_NTSC;
you change driver's configuration, and by calling
tw9910_reset(priv->client);
you change chip's configuration (I assume). So, re-starting capture after this might be problematic. The only thing one should do in stop_capture is tell the sensor to stop the scan - if it supports it. Not all chips do. With one of my drivers I switch it to snapshot mode, in which case it stops scanning and waits for a trigger. See if your chip supports anything similar, or just do nothing.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/media/video/tw9910.c new file +8
-0+static unsigned long tw9910_query_bus_param (struct soc_camera_device *icd) +{ + struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); +struct soc_camera_link *icl = priv->client->dev.platform_data; +unsigned long flags =SOCAM_PCLK_SAMPLE_RISING |SOCAM_MASTER | +SOCAM_VSYNC_ACTIVE_HIGH |SOCAM_HSYNC_ACTIVE_HIGH | +SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth; +
Quoted 8 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return soc_camera_apply_sensor_flags(icl, flags); +}In current git (2008-12-19),
${LINUX}/include/media/soc_camera.h::soc_camera_bus_param_compatibledoesn't checkSOCAM_DATA_ACTIVE_XXX.
So I thinkSOCAM_DATA_ACTIVE_HIGHis not needed here.
But should I add it ? or not ?
Well, this is the query() method, it just tells your capabilities. Currently we don't check for SOCAM_DATA_ACTIVE_* in soc_camera_bus_param_compatible(), that's correct, but it is good to have your driver ready for the time when we do this. With a later patch we're going to update camera host drivers and camera device, and after that we'll update soc_camera_bus_param_compatible(). So, it is good that you already have it.
Quoted 63 lines
Quoted 8 lines
This is wrong too. According to the API
TRY_FMTmay be called at any time (also during a running streaming) and should _not_ change driver's state. And as you can see insoc_camera.c::soc_camera_s_fmt_vid_cap()we're not holding the mutex while callingsoc_camera_try_fmt_vid_cap(), so, you have no guarantee in yourset_fmt, that yourtry_fmtwas last called fromsoc_camera_s_fmt_vid_cap()or even worse that it's not being called concurrently. Therefore, you have to calltw9910_select_norm()once more in yourset_fmt,OK. I could understand.
Quoted 2 lines
and in
try_fmtyou only verify if a suitable norm can be found and setpix->heightandpix->widthaccordingly.So I think
set_fmtandtry_fmtwill be like this.
It's OK ?--------------------
static const struct tw9910_scale_ctrl*tw9910_select_norm(struct soc_camera_device *icd, struct v4l2_rect *rect){
...
}static int
tw9910_set_fmt( xxx ){ ... /* * select suitable norm */ priv->scale = tw9910_select_norm(icd, rect); if (!priv->scale) return ret; .... }static int
tw9910_try_fmt( xxx ){ struct v4l2_rect rect; ... /* * check pix->field is ANY or INTERLACED */ .... /* * select suitable norm */ rect.width = pix->width; rect.height = pix->height; scale = tw9910_select_norm(icd, &rect); if (!scale) return -EINVAL; pix->width = scale->width; pix->height = scale->height; return 0; }
Quoted 1 line
--------------------
Yes, this looks good as far as I can see.
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Dear Guennadi
Thank you for some comments.
And I'm sorry about my stupid question.
Quoted 6 lines
You may choose - what's easier for you. Either you make a v7, or we keep v6, and you make an _incremental_ (i.e., based on v6) patch to address issues that I point out here. If you decide to make an incremental patch, I think, I might merge it with v6, show it to you once more for confirmation and commit that in one go. But just please choose what's easier for you.
OK. I will create v7 patch.
After re-send patch,
please teach me which one will be applied. v6 or v7
Quoted 7 lines
i.e., you should be prepared to restart capture after a
stop_capturewith the same configuration. By settingicd->vdev->current_norm = V4L2_STD_NTSC;you change driver's configuration, and by calling
Quoted 8 lines
tw9910_reset(priv->client);you change chip's configuration (I assume). So, re-starting capture after this might be problematic. The only thing one should do in
stop_captureis tell the sensor to stop the scan - if it supports it. Not all chips do. With one of my drivers I switch it to snapshot mode, in which case it stops scanning and waits for a trigger. See if your chip supports anything similar, or just do nothing.
Hmm. I was misunderstanding about it.
In v1 patch, you gave me some comments about stop_capture funtion. So, I added reset method in it.
OK. I think tw9910 can not stop scanning by itself. It might be possible, but I don't know how to do it. If I found it, I will send patch. OK ?
In v7 patch, it will do nothing
Quoted 7 lines
Well, this is the
query()method, it just tells your capabilities. Currently we don't check for SOCAM_DATA_ACTIVE_* insoc_camera_bus_param_compatible(), that's correct, but it is good to have your driver ready for the time when we do this. With a later patch we're going to update camera host drivers and camera device, and after that we'll updatesoc_camera_bus_param_compatible(). So, it is good that you already have it.
OK. v7 patch have it.
Best regards
--
Kuninori Morimoto
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list