2019-05-27 09:55:01 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2013-05-29 21:52:28 +04:00
/*
* OKI Semiconductor ML86V7667 video decoder driver
*
* Author : Vladimir Barinov < source @ cogentembedded . com >
* Copyright ( C ) 2013 Cogent Embedded , Inc .
* Copyright ( C ) 2013 Renesas Solutions Corp .
*/
# include <linux/init.h>
# include <linux/module.h>
# include <linux/i2c.h>
# include <linux/slab.h>
# include <linux/videodev2.h>
# include <media/v4l2-subdev.h>
# include <media/v4l2-device.h>
# include <media/v4l2-ioctl.h>
# include <media/v4l2-ctrls.h>
# define DRV_NAME "ml86v7667"
/* Subaddresses */
# define MRA_REG 0x00 /* Mode Register A */
# define MRC_REG 0x02 /* Mode Register C */
# define LUMC_REG 0x0C /* Luminance Control */
# define CLC_REG 0x10 /* Contrast level control */
# define SSEPL_REG 0x11 /* Sync separation level */
# define CHRCA_REG 0x12 /* Chrominance Control A */
# define ACCC_REG 0x14 /* ACC Loop filter & Chrominance control */
# define ACCRC_REG 0x15 /* ACC Reference level control */
# define HUE_REG 0x16 /* Hue control */
# define ADC2_REG 0x1F /* ADC Register 2 */
# define PLLR1_REG 0x20 /* PLL Register 1 */
# define STATUS_REG 0x2C /* STATUS Register */
/* Mode Register A register bits */
# define MRA_OUTPUT_MODE_MASK (3 << 6)
# define MRA_ITUR_BT601 (1 << 6)
# define MRA_ITUR_BT656 (0 << 6)
# define MRA_INPUT_MODE_MASK (7 << 3)
# define MRA_PAL_BT601 (4 << 3)
# define MRA_NTSC_BT601 (0 << 3)
# define MRA_REGISTER_MODE (1 << 0)
/* Mode Register C register bits */
# define MRC_AUTOSELECT (1 << 7)
/* Luminance Control register bits */
# define LUMC_ONOFF_SHIFT 7
# define LUMC_ONOFF_MASK (1 << 7)
/* Contrast level control register bits */
# define CLC_CONTRAST_ONOFF (1 << 7)
# define CLC_CONTRAST_MASK 0x0F
/* Sync separation level register bits */
# define SSEPL_LUMINANCE_ONOFF (1 << 7)
# define SSEPL_LUMINANCE_MASK 0x7F
/* Chrominance Control A register bits */
# define CHRCA_MODE_SHIFT 6
# define CHRCA_MODE_MASK (1 << 6)
/* ACC Loop filter & Chrominance control register bits */
# define ACCC_CHROMA_CR_SHIFT 3
# define ACCC_CHROMA_CR_MASK (7 << 3)
# define ACCC_CHROMA_CB_SHIFT 0
# define ACCC_CHROMA_CB_MASK (7 << 0)
/* ACC Reference level control register bits */
# define ACCRC_CHROMA_MASK 0xfc
# define ACCRC_CHROMA_SHIFT 2
/* ADC Register 2 register bits */
# define ADC2_CLAMP_VOLTAGE_MASK (7 << 1)
# define ADC2_CLAMP_VOLTAGE(n) ((n & 7) << 1)
/* PLL Register 1 register bits */
# define PLLR1_FIXED_CLOCK (1 << 7)
/* STATUS Register register bits */
# define STATUS_HLOCK_DETECT (1 << 3)
# define STATUS_NTSCPAL (1 << 2)
struct ml86v7667_priv {
struct v4l2_subdev sd ;
struct v4l2_ctrl_handler hdl ;
v4l2_std_id std ;
} ;
static inline struct ml86v7667_priv * to_ml86v7667 ( struct v4l2_subdev * subdev )
{
return container_of ( subdev , struct ml86v7667_priv , sd ) ;
}
static inline struct v4l2_subdev * to_sd ( struct v4l2_ctrl * ctrl )
{
return & container_of ( ctrl - > handler , struct ml86v7667_priv , hdl ) - > sd ;
}
static int ml86v7667_mask_set ( struct i2c_client * client , const u8 reg ,
const u8 mask , const u8 data )
{
int val = i2c_smbus_read_byte_data ( client , reg ) ;
if ( val < 0 )
return val ;
val = ( val & ~ mask ) | ( data & mask ) ;
return i2c_smbus_write_byte_data ( client , reg , val ) ;
}
static int ml86v7667_s_ctrl ( struct v4l2_ctrl * ctrl )
{
struct v4l2_subdev * sd = to_sd ( ctrl ) ;
struct i2c_client * client = v4l2_get_subdevdata ( sd ) ;
2013-06-30 11:40:32 +04:00
int ret = - EINVAL ;
2013-05-29 21:52:28 +04:00
switch ( ctrl - > id ) {
case V4L2_CID_BRIGHTNESS :
ret = ml86v7667_mask_set ( client , SSEPL_REG ,
SSEPL_LUMINANCE_MASK , ctrl - > val ) ;
break ;
case V4L2_CID_CONTRAST :
ret = ml86v7667_mask_set ( client , CLC_REG ,
CLC_CONTRAST_MASK , ctrl - > val ) ;
break ;
case V4L2_CID_CHROMA_GAIN :
ret = ml86v7667_mask_set ( client , ACCRC_REG , ACCRC_CHROMA_MASK ,
ctrl - > val < < ACCRC_CHROMA_SHIFT ) ;
break ;
case V4L2_CID_HUE :
ret = ml86v7667_mask_set ( client , HUE_REG , ~ 0 , ctrl - > val ) ;
break ;
case V4L2_CID_RED_BALANCE :
ret = ml86v7667_mask_set ( client , ACCC_REG ,
ACCC_CHROMA_CR_MASK ,
ctrl - > val < < ACCC_CHROMA_CR_SHIFT ) ;
break ;
case V4L2_CID_BLUE_BALANCE :
ret = ml86v7667_mask_set ( client , ACCC_REG ,
ACCC_CHROMA_CB_MASK ,
ctrl - > val < < ACCC_CHROMA_CB_SHIFT ) ;
break ;
case V4L2_CID_SHARPNESS :
ret = ml86v7667_mask_set ( client , LUMC_REG ,
LUMC_ONOFF_MASK ,
ctrl - > val < < LUMC_ONOFF_SHIFT ) ;
break ;
case V4L2_CID_COLOR_KILLER :
ret = ml86v7667_mask_set ( client , CHRCA_REG ,
CHRCA_MODE_MASK ,
ctrl - > val < < CHRCA_MODE_SHIFT ) ;
break ;
}
2013-06-30 11:40:32 +04:00
return ret ;
2013-05-29 21:52:28 +04:00
}
static int ml86v7667_querystd ( struct v4l2_subdev * sd , v4l2_std_id * std )
{
struct i2c_client * client = v4l2_get_subdevdata ( sd ) ;
int status ;
status = i2c_smbus_read_byte_data ( client , STATUS_REG ) ;
if ( status < 0 )
return status ;
2013-05-31 12:15:17 +04:00
if ( status & STATUS_HLOCK_DETECT )
* std & = status & STATUS_NTSCPAL ? V4L2_STD_625_50 : V4L2_STD_525_60 ;
else
* std = V4L2_STD_UNKNOWN ;
2013-05-29 21:52:28 +04:00
return 0 ;
}
static int ml86v7667_g_input_status ( struct v4l2_subdev * sd , u32 * status )
{
struct i2c_client * client = v4l2_get_subdevdata ( sd ) ;
int status_reg ;
status_reg = i2c_smbus_read_byte_data ( client , STATUS_REG ) ;
if ( status_reg < 0 )
return status_reg ;
* status = status_reg & STATUS_HLOCK_DETECT ? 0 : V4L2_IN_ST_NO_SIGNAL ;
return 0 ;
}
2015-04-09 10:01:33 +03:00
static int ml86v7667_enum_mbus_code ( struct v4l2_subdev * sd ,
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
struct v4l2_subdev_state * sd_state ,
2015-04-09 10:01:33 +03:00
struct v4l2_subdev_mbus_code_enum * code )
2013-05-29 21:52:28 +04:00
{
2015-04-09 10:01:33 +03:00
if ( code - > pad | | code - > index > 0 )
2013-05-29 21:52:28 +04:00
return - EINVAL ;
2015-04-09 10:01:33 +03:00
code - > code = MEDIA_BUS_FMT_YUYV8_2X8 ;
2013-05-29 21:52:28 +04:00
return 0 ;
}
2015-04-09 10:02:34 +03:00
static int ml86v7667_fill_fmt ( struct v4l2_subdev * sd ,
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
struct v4l2_subdev_state * sd_state ,
2015-04-09 10:02:34 +03:00
struct v4l2_subdev_format * format )
2013-05-29 21:52:28 +04:00
{
struct ml86v7667_priv * priv = to_ml86v7667 ( sd ) ;
2015-04-09 10:02:34 +03:00
struct v4l2_mbus_framefmt * fmt = & format - > format ;
if ( format - > pad )
return - EINVAL ;
2013-05-29 21:52:28 +04:00
2014-11-10 20:28:29 +03:00
fmt - > code = MEDIA_BUS_FMT_YUYV8_2X8 ;
2013-05-29 21:52:28 +04:00
fmt - > colorspace = V4L2_COLORSPACE_SMPTE170M ;
2013-07-15 22:12:21 +04:00
/* The top field is always transferred first by the chip */
fmt - > field = V4L2_FIELD_INTERLACED_TB ;
2013-05-29 21:52:28 +04:00
fmt - > width = 720 ;
fmt - > height = priv - > std & V4L2_STD_525_60 ? 480 : 576 ;
return 0 ;
}
2020-07-17 17:53:16 +03:00
static int ml86v7667_get_mbus_config ( struct v4l2_subdev * sd ,
unsigned int pad ,
struct v4l2_mbus_config * cfg )
2013-05-29 21:52:28 +04:00
{
cfg - > type = V4L2_MBUS_BT656 ;
2022-01-03 19:24:11 +03:00
cfg - > bus . parallel . flags = V4L2_MBUS_MASTER |
V4L2_MBUS_PCLK_SAMPLE_RISING |
V4L2_MBUS_DATA_ACTIVE_HIGH ;
2013-05-29 21:52:28 +04:00
return 0 ;
}
2015-09-04 02:16:34 +03:00
static int ml86v7667_g_std ( struct v4l2_subdev * sd , v4l2_std_id * std )
{
struct ml86v7667_priv * priv = to_ml86v7667 ( sd ) ;
* std = priv - > std ;
return 0 ;
}
2013-05-29 21:52:28 +04:00
static int ml86v7667_s_std ( struct v4l2_subdev * sd , v4l2_std_id std )
{
struct ml86v7667_priv * priv = to_ml86v7667 ( sd ) ;
struct i2c_client * client = v4l2_get_subdevdata ( & priv - > sd ) ;
int ret ;
u8 mode ;
/* PAL/NTSC ITU-R BT.601 input mode */
mode = std & V4L2_STD_525_60 ? MRA_NTSC_BT601 : MRA_PAL_BT601 ;
ret = ml86v7667_mask_set ( client , MRA_REG , MRA_INPUT_MODE_MASK , mode ) ;
if ( ret < 0 )
return ret ;
priv - > std = std ;
return 0 ;
}
# ifdef CONFIG_VIDEO_ADV_DEBUG
static int ml86v7667_g_register ( struct v4l2_subdev * sd ,
struct v4l2_dbg_register * reg )
{
struct i2c_client * client = v4l2_get_subdevdata ( sd ) ;
int ret ;
ret = i2c_smbus_read_byte_data ( client , ( u8 ) reg - > reg ) ;
if ( ret < 0 )
return ret ;
reg - > val = ret ;
reg - > size = sizeof ( u8 ) ;
return 0 ;
}
static int ml86v7667_s_register ( struct v4l2_subdev * sd ,
const struct v4l2_dbg_register * reg )
{
struct i2c_client * client = v4l2_get_subdevdata ( sd ) ;
return i2c_smbus_write_byte_data ( client , ( u8 ) reg - > reg , ( u8 ) reg - > val ) ;
}
# endif
static const struct v4l2_ctrl_ops ml86v7667_ctrl_ops = {
. s_ctrl = ml86v7667_s_ctrl ,
} ;
2016-12-13 20:31:45 +03:00
static const struct v4l2_subdev_video_ops ml86v7667_subdev_video_ops = {
2015-09-04 02:16:34 +03:00
. g_std = ml86v7667_g_std ,
2014-04-28 23:53:01 +04:00
. s_std = ml86v7667_s_std ,
2013-05-29 21:52:28 +04:00
. querystd = ml86v7667_querystd ,
. g_input_status = ml86v7667_g_input_status ,
} ;
2015-04-09 10:01:33 +03:00
static const struct v4l2_subdev_pad_ops ml86v7667_subdev_pad_ops = {
. enum_mbus_code = ml86v7667_enum_mbus_code ,
2015-04-09 10:02:34 +03:00
. get_fmt = ml86v7667_fill_fmt ,
. set_fmt = ml86v7667_fill_fmt ,
2020-07-17 17:53:16 +03:00
. get_mbus_config = ml86v7667_get_mbus_config ,
2015-04-09 10:01:33 +03:00
} ;
2016-12-13 20:31:45 +03:00
static const struct v4l2_subdev_core_ops ml86v7667_subdev_core_ops = {
2013-05-29 21:52:28 +04:00
# ifdef CONFIG_VIDEO_ADV_DEBUG
. g_register = ml86v7667_g_register ,
. s_register = ml86v7667_s_register ,
# endif
} ;
2016-12-13 20:31:45 +03:00
static const struct v4l2_subdev_ops ml86v7667_subdev_ops = {
2013-05-29 21:52:28 +04:00
. core = & ml86v7667_subdev_core_ops ,
. video = & ml86v7667_subdev_video_ops ,
2015-04-09 10:01:33 +03:00
. pad = & ml86v7667_subdev_pad_ops ,
2013-05-29 21:52:28 +04:00
} ;
static int ml86v7667_init ( struct ml86v7667_priv * priv )
{
struct i2c_client * client = v4l2_get_subdevdata ( & priv - > sd ) ;
int val ;
int ret ;
/* BT.656-4 output mode, register mode */
ret = ml86v7667_mask_set ( client , MRA_REG ,
MRA_OUTPUT_MODE_MASK | MRA_REGISTER_MODE ,
MRA_ITUR_BT656 | MRA_REGISTER_MODE ) ;
/* PLL circuit fixed clock, 32MHz */
ret | = ml86v7667_mask_set ( client , PLLR1_REG , PLLR1_FIXED_CLOCK ,
PLLR1_FIXED_CLOCK ) ;
/* ADC2 clamping voltage maximum */
ret | = ml86v7667_mask_set ( client , ADC2_REG , ADC2_CLAMP_VOLTAGE_MASK ,
ADC2_CLAMP_VOLTAGE ( 7 ) ) ;
/* enable luminance function */
ret | = ml86v7667_mask_set ( client , SSEPL_REG , SSEPL_LUMINANCE_ONOFF ,
SSEPL_LUMINANCE_ONOFF ) ;
/* enable contrast function */
ret | = ml86v7667_mask_set ( client , CLC_REG , CLC_CONTRAST_ONOFF , 0 ) ;
/*
* PAL / NTSC autodetection is enabled after reset ,
* set the autodetected std in manual std mode and
* disable autodetection
*/
val = i2c_smbus_read_byte_data ( client , STATUS_REG ) ;
if ( val < 0 )
return val ;
priv - > std = val & STATUS_NTSCPAL ? V4L2_STD_625_50 : V4L2_STD_525_60 ;
ret | = ml86v7667_mask_set ( client , MRC_REG , MRC_AUTOSELECT , 0 ) ;
val = priv - > std & V4L2_STD_525_60 ? MRA_NTSC_BT601 : MRA_PAL_BT601 ;
ret | = ml86v7667_mask_set ( client , MRA_REG , MRA_INPUT_MODE_MASK , val ) ;
return ret ;
}
static int ml86v7667_probe ( struct i2c_client * client ,
const struct i2c_device_id * did )
{
struct ml86v7667_priv * priv ;
int ret ;
if ( ! i2c_check_functionality ( client - > adapter , I2C_FUNC_SMBUS_BYTE_DATA ) )
return - EIO ;
priv = devm_kzalloc ( & client - > dev , sizeof ( * priv ) , GFP_KERNEL ) ;
if ( ! priv )
return - ENOMEM ;
v4l2_i2c_subdev_init ( & priv - > sd , client , & ml86v7667_subdev_ops ) ;
v4l2_ctrl_handler_init ( & priv - > hdl , 8 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_BRIGHTNESS , - 64 , 63 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_CONTRAST , - 8 , 7 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_CHROMA_GAIN , - 32 , 31 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_HUE , - 128 , 127 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_RED_BALANCE , - 4 , 3 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_BLUE_BALANCE , - 4 , 3 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_SHARPNESS , 0 , 1 , 1 , 0 ) ;
v4l2_ctrl_new_std ( & priv - > hdl , & ml86v7667_ctrl_ops ,
V4L2_CID_COLOR_KILLER , 0 , 1 , 1 , 0 ) ;
priv - > sd . ctrl_handler = & priv - > hdl ;
ret = priv - > hdl . error ;
if ( ret )
goto cleanup ;
v4l2_ctrl_handler_setup ( & priv - > hdl ) ;
ret = ml86v7667_init ( priv ) ;
if ( ret )
goto cleanup ;
v4l_info ( client , " chip found @ 0x%02x (%s) \n " ,
client - > addr , client - > adapter - > name ) ;
return 0 ;
cleanup :
v4l2_ctrl_handler_free ( & priv - > hdl ) ;
v4l2_device_unregister_subdev ( & priv - > sd ) ;
v4l_err ( client , " failed to probe @ 0x%02x (%s) \n " ,
client - > addr , client - > adapter - > name ) ;
return ret ;
}
2022-08-15 11:02:30 +03:00
static void ml86v7667_remove ( struct i2c_client * client )
2013-05-29 21:52:28 +04:00
{
struct v4l2_subdev * sd = i2c_get_clientdata ( client ) ;
struct ml86v7667_priv * priv = to_ml86v7667 ( sd ) ;
v4l2_ctrl_handler_free ( & priv - > hdl ) ;
v4l2_device_unregister_subdev ( & priv - > sd ) ;
}
static const struct i2c_device_id ml86v7667_id [ ] = {
{ DRV_NAME , 0 } ,
{ } ,
} ;
MODULE_DEVICE_TABLE ( i2c , ml86v7667_id ) ;
static struct i2c_driver ml86v7667_i2c_driver = {
. driver = {
. name = DRV_NAME ,
} ,
. probe = ml86v7667_probe ,
. remove = ml86v7667_remove ,
. id_table = ml86v7667_id ,
} ;
module_i2c_driver ( ml86v7667_i2c_driver ) ;
MODULE_DESCRIPTION ( " OKI Semiconductor ML86V7667 video decoder driver " ) ;
MODULE_AUTHOR ( " Vladimir Barinov " ) ;
MODULE_LICENSE ( " GPL " ) ;