2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-12-22 03:14:04 +08:00
|
|
|
/* Texas Instruments Triple 8-/10-BIT 165-/110-MSPS Video and Graphics
|
|
|
|
* Digitizer with Horizontal PLL registers
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Texas Instruments Inc
|
|
|
|
* Author: Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>
|
|
|
|
*
|
|
|
|
* This code is partially based upon the TVP5150 driver
|
MAINTAINERS & files: Canonize the e-mails I use at files
From now on, I'll start using my @kernel.org as my development e-mail.
As such, let's remove the entries that point to the old
mchehab@s-opensource.com at MAINTAINERS file.
For the files written with a copyright with mchehab@s-opensource,
let's keep Samsung on their names, using mchehab+samsung@kernel.org,
in order to keep pointing to my employer, with sponsors the work.
For the files written before I join Samsung (on July, 4 2013),
let's just use mchehab@kernel.org.
For bug reports, we can simply point to just kernel.org, as
this will reach my mchehab+samsung inbox anyway.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Brian Warner <brian.warner@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-04-25 17:34:48 +08:00
|
|
|
* written by Mauro Carvalho Chehab <mchehab@kernel.org>,
|
2009-12-22 03:14:04 +08:00
|
|
|
* the TVP514x driver written by Vaibhav Hiremath <hvaibhav@ti.com>
|
|
|
|
* and the TVP7002 driver in the TI LSP 2.10.00.14. Revisions by
|
|
|
|
* Muralidharan Karicheri and Snehaprabha Narnakaje (TI).
|
|
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-12-22 03:14:04 +08:00
|
|
|
#include <linux/videodev2.h>
|
2011-07-04 02:03:12 +08:00
|
|
|
#include <linux/module.h>
|
2013-10-18 11:07:14 +08:00
|
|
|
#include <linux/of.h>
|
2014-02-11 05:01:48 +08:00
|
|
|
#include <linux/of_graph.h>
|
2012-05-15 19:07:24 +08:00
|
|
|
#include <linux/v4l2-dv-timings.h>
|
2015-11-10 22:01:44 +08:00
|
|
|
#include <media/i2c/tvp7002.h>
|
2013-06-23 00:44:14 +08:00
|
|
|
#include <media/v4l2-async.h>
|
2009-12-22 03:14:04 +08:00
|
|
|
#include <media/v4l2-device.h>
|
|
|
|
#include <media/v4l2-common.h>
|
2010-12-12 19:46:15 +08:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2016-08-27 07:17:25 +08:00
|
|
|
#include <media/v4l2-fwnode.h>
|
2013-08-11 13:25:21 +08:00
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
#include "tvp7002_reg.h"
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("TI TVP7002 Video and Graphics Digitizer driver");
|
|
|
|
MODULE_AUTHOR("Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/* I2C retry attempts */
|
|
|
|
#define I2C_RETRY_COUNT (5)
|
|
|
|
|
|
|
|
/* End of registers */
|
|
|
|
#define TVP7002_EOR 0x5c
|
|
|
|
|
|
|
|
/* Read write definition for registers */
|
|
|
|
#define TVP7002_READ 0
|
|
|
|
#define TVP7002_WRITE 1
|
|
|
|
#define TVP7002_RESERVED 2
|
|
|
|
|
|
|
|
/* Interlaced vs progressive mask and shift */
|
|
|
|
#define TVP7002_IP_SHIFT 5
|
|
|
|
#define TVP7002_INPR_MASK (0x01 << TVP7002_IP_SHIFT)
|
|
|
|
|
|
|
|
/* Shift for CPL and LPF registers */
|
|
|
|
#define TVP7002_CL_SHIFT 8
|
|
|
|
#define TVP7002_CL_MASK 0x0f
|
|
|
|
|
|
|
|
/* Debug functions */
|
2012-01-13 07:02:20 +08:00
|
|
|
static bool debug;
|
2009-12-22 03:14:04 +08:00
|
|
|
module_param(debug, bool, 0644);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug level (0-2)");
|
|
|
|
|
|
|
|
/* Structure for register values */
|
|
|
|
struct i2c_reg_value {
|
|
|
|
u8 reg;
|
|
|
|
u8 value;
|
|
|
|
u8 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register default values (according to tvp7002 datasheet)
|
|
|
|
* In the case of read-only registers, the value (0xff) is
|
|
|
|
* never written. R/W functionality is controlled by the
|
|
|
|
* writable bit in the register struct definition.
|
|
|
|
*/
|
|
|
|
static const struct i2c_reg_value tvp7002_init_default[] = {
|
|
|
|
{ TVP7002_CHIP_REV, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PHASE_SEL, 0x80, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HSYNC_OUT_W, 0x60, TVP7002_WRITE },
|
|
|
|
{ TVP7002_B_FINE_GAIN, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_G_FINE_GAIN, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_R_FINE_GAIN, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_B_FINE_OFF_MSBS, 0x80, TVP7002_WRITE },
|
|
|
|
{ TVP7002_G_FINE_OFF_MSBS, 0x80, TVP7002_WRITE },
|
|
|
|
{ TVP7002_R_FINE_OFF_MSBS, 0x80, TVP7002_WRITE },
|
|
|
|
{ TVP7002_SYNC_CTL_1, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_AND_CLAMP_CTL, 0x2e, TVP7002_WRITE },
|
|
|
|
{ TVP7002_SYNC_ON_G_THRS, 0x5d, TVP7002_WRITE },
|
|
|
|
{ TVP7002_SYNC_SEPARATOR_THRS, 0x47, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_SYNC_DETECT_STAT, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_OUT_FORMATTER, 0x47, TVP7002_WRITE },
|
|
|
|
{ TVP7002_MISC_CTL_1, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_MISC_CTL_2, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_MISC_CTL_3, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_IN_MUX_SEL_1, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_IN_MUX_SEL_2, 0x67, TVP7002_WRITE },
|
|
|
|
{ TVP7002_B_AND_G_COARSE_GAIN, 0x77, TVP7002_WRITE },
|
|
|
|
{ TVP7002_R_COARSE_GAIN, 0x07, TVP7002_WRITE },
|
|
|
|
{ TVP7002_FINE_OFF_LSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_B_COARSE_OFF, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_G_COARSE_OFF, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_R_COARSE_OFF, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HSOUT_OUT_START, 0x08, TVP7002_WRITE },
|
|
|
|
{ TVP7002_MISC_CTL_4, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_B_DGTL_ALC_OUT_LSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_G_DGTL_ALC_OUT_LSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_R_DGTL_ALC_OUT_LSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_AUTO_LVL_CTL_ENABLE, 0x80, TVP7002_WRITE },
|
|
|
|
{ TVP7002_DGTL_ALC_OUT_MSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_AUTO_LVL_CTL_FILTER, 0x53, TVP7002_WRITE },
|
|
|
|
{ 0x29, 0x08, TVP7002_RESERVED },
|
|
|
|
{ TVP7002_FINE_CLAMP_CTL, 0x07, TVP7002_WRITE },
|
|
|
|
/* PWR_CTL is controlled only by the probe and reset functions */
|
|
|
|
{ TVP7002_PWR_CTL, 0x00, TVP7002_RESERVED },
|
|
|
|
{ TVP7002_ADC_SETUP, 0x50, TVP7002_WRITE },
|
|
|
|
{ TVP7002_COARSE_CLAMP_CTL, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_SOG_CLAMP, 0x80, TVP7002_WRITE },
|
2010-08-03 15:18:04 +08:00
|
|
|
{ TVP7002_RGB_COARSE_CLAMP_CTL, 0x8c, TVP7002_WRITE },
|
2009-12-22 03:14:04 +08:00
|
|
|
{ TVP7002_SOG_COARSE_CLAMP_CTL, 0x04, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
|
|
|
|
{ 0x32, 0x18, TVP7002_RESERVED },
|
|
|
|
{ 0x33, 0x60, TVP7002_RESERVED },
|
|
|
|
{ TVP7002_MVIS_STRIPPER_W, 0xff, TVP7002_RESERVED },
|
|
|
|
{ TVP7002_VSYNC_ALGN, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_SYNC_BYPASS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_L_FRAME_STAT_LSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_L_FRAME_STAT_MSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_CLK_L_STAT_LSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_CLK_L_STAT_MSBS, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_HSYNC_W, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_VSYNC_W, 0xff, TVP7002_READ },
|
|
|
|
{ TVP7002_L_LENGTH_TOL, 0x03, TVP7002_WRITE },
|
|
|
|
{ 0x3e, 0x60, TVP7002_RESERVED },
|
|
|
|
{ TVP7002_VIDEO_BWTH_CTL, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x2c, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x2c, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x05, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x1e, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_FBIT_F_0_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_FBIT_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_Y_G_COEF_LSBS, 0xe3, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_Y_G_COEF_MSBS, 0x16, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_Y_B_COEF_LSBS, 0x4f, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_Y_B_COEF_MSBS, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_Y_R_COEF_LSBS, 0xce, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_Y_R_COEF_MSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_U_G_COEF_LSBS, 0xab, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_U_G_COEF_MSBS, 0xf3, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_U_B_COEF_LSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_U_B_COEF_MSBS, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_U_R_COEF_LSBS, 0x55, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_U_R_COEF_MSBS, 0xfc, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_V_G_COEF_LSBS, 0x78, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_V_G_COEF_MSBS, 0xf1, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_V_B_COEF_LSBS, 0x88, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_V_B_COEF_MSBS, 0xfe, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_V_R_COEF_LSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_YUV_V_R_COEF_MSBS, 0x10, TVP7002_WRITE },
|
|
|
|
/* This signals end of register values */
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 480P */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_480P[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x35, TVP7002_WRITE },
|
2010-07-28 16:47:48 +08:00
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0xa0, TVP7002_WRITE },
|
2009-12-22 03:14:04 +08:00
|
|
|
{ TVP7002_HPLL_CRTL, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x91, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x0B, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x03, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x13, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x13, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x18, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x03, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x03, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 576P */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_576P[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x36, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_CRTL, 0x18, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x9B, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x0F, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x2D, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x18, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x10, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x03, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x03, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 1080I60 */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_1080I60[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
|
2010-07-28 16:47:48 +08:00
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0x80, TVP7002_WRITE },
|
2009-12-22 03:14:04 +08:00
|
|
|
{ TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x08, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x16, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x17, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 1080P60 */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_1080P60[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
|
2010-07-28 16:47:48 +08:00
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0x80, TVP7002_WRITE },
|
2009-12-22 03:14:04 +08:00
|
|
|
{ TVP7002_HPLL_CRTL, 0xE0, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x08, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x16, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x17, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 1080I50 */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_1080I50[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0xa5, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x08, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x02, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x16, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x17, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 720P60 */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_720P60[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE },
|
2010-07-28 16:47:48 +08:00
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0x20, TVP7002_WRITE },
|
2009-12-22 03:14:04 +08:00
|
|
|
{ TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x4B, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x05, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x2D, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register parameters for 720P50 */
|
|
|
|
static const struct i2c_reg_value tvp7002_parms_720P50[] = {
|
|
|
|
{ TVP7002_HPLL_FDBK_DIV_MSBS, 0x7b, TVP7002_WRITE },
|
2010-07-28 16:47:48 +08:00
|
|
|
{ TVP7002_HPLL_FDBK_DIV_LSBS, 0xc0, TVP7002_WRITE },
|
2009-12-22 03:14:04 +08:00
|
|
|
{ TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_LSBS, 0x4B, TVP7002_WRITE },
|
|
|
|
{ TVP7002_AVID_STOP_PIXEL_MSBS, 0x06, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_START_L_OFF, 0x05, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_0_DURATION, 0x2D, TVP7002_WRITE },
|
|
|
|
{ TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
|
|
|
|
{ TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
|
|
|
|
{ TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
|
|
|
|
{ TVP7002_EOR, 0xff, TVP7002_RESERVED }
|
|
|
|
};
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
/* Timings definition for handling device operation */
|
|
|
|
struct tvp7002_timings_definition {
|
2012-05-15 19:07:24 +08:00
|
|
|
struct v4l2_dv_timings timings;
|
2009-12-22 03:14:04 +08:00
|
|
|
const struct i2c_reg_value *p_settings;
|
|
|
|
enum v4l2_colorspace color_space;
|
|
|
|
enum v4l2_field scanmode;
|
|
|
|
u16 progressive;
|
|
|
|
u16 lines_per_frame;
|
|
|
|
u16 cpl_min;
|
|
|
|
u16 cpl_max;
|
|
|
|
};
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
/* Struct list for digital video timings */
|
|
|
|
static const struct tvp7002_timings_definition tvp7002_timings[] = {
|
2009-12-22 03:14:04 +08:00
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_1280X720P60,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_720P60,
|
|
|
|
V4L2_COLORSPACE_REC709,
|
|
|
|
V4L2_FIELD_NONE,
|
|
|
|
1,
|
|
|
|
0x2EE,
|
|
|
|
135,
|
|
|
|
153
|
|
|
|
},
|
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_1920X1080I60,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_1080I60,
|
|
|
|
V4L2_COLORSPACE_REC709,
|
|
|
|
V4L2_FIELD_INTERLACED,
|
|
|
|
0,
|
|
|
|
0x465,
|
|
|
|
181,
|
|
|
|
205
|
|
|
|
},
|
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_1920X1080I50,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_1080I50,
|
|
|
|
V4L2_COLORSPACE_REC709,
|
|
|
|
V4L2_FIELD_INTERLACED,
|
|
|
|
0,
|
|
|
|
0x465,
|
|
|
|
217,
|
|
|
|
245
|
|
|
|
},
|
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_1280X720P50,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_720P50,
|
|
|
|
V4L2_COLORSPACE_REC709,
|
|
|
|
V4L2_FIELD_NONE,
|
|
|
|
1,
|
|
|
|
0x2EE,
|
|
|
|
163,
|
|
|
|
183
|
|
|
|
},
|
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_1920X1080P60,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_1080P60,
|
|
|
|
V4L2_COLORSPACE_REC709,
|
|
|
|
V4L2_FIELD_NONE,
|
|
|
|
1,
|
|
|
|
0x465,
|
|
|
|
90,
|
|
|
|
102
|
|
|
|
},
|
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_720X480P59_94,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_480P,
|
|
|
|
V4L2_COLORSPACE_SMPTE170M,
|
|
|
|
V4L2_FIELD_NONE,
|
|
|
|
1,
|
|
|
|
0x20D,
|
|
|
|
0xffff,
|
|
|
|
0xffff
|
|
|
|
},
|
|
|
|
{
|
2012-05-15 19:07:24 +08:00
|
|
|
V4L2_DV_BT_CEA_720X576P50,
|
2009-12-22 03:14:04 +08:00
|
|
|
tvp7002_parms_576P,
|
|
|
|
V4L2_COLORSPACE_SMPTE170M,
|
|
|
|
V4L2_FIELD_NONE,
|
|
|
|
1,
|
|
|
|
0x271,
|
|
|
|
0xffff,
|
|
|
|
0xffff
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
#define NUM_TIMINGS ARRAY_SIZE(tvp7002_timings)
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
/* Device definition */
|
|
|
|
struct tvp7002 {
|
|
|
|
struct v4l2_subdev sd;
|
2010-12-12 19:46:15 +08:00
|
|
|
struct v4l2_ctrl_handler hdl;
|
2009-12-22 03:14:04 +08:00
|
|
|
const struct tvp7002_config *pdata;
|
|
|
|
|
|
|
|
int ver;
|
|
|
|
int streaming;
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
const struct tvp7002_timings_definition *current_timings;
|
2013-05-03 15:17:19 +08:00
|
|
|
struct media_pad pad;
|
2009-12-22 03:14:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* to_tvp7002 - Obtain device handler TVP7002
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
|
|
|
*
|
|
|
|
* Returns device handler tvp7002.
|
|
|
|
*/
|
|
|
|
static inline struct tvp7002 *to_tvp7002(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
return container_of(sd, struct tvp7002, sd);
|
|
|
|
}
|
|
|
|
|
2010-12-12 19:46:15 +08:00
|
|
|
static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
return &container_of(ctrl->handler, struct tvp7002, hdl)->sd;
|
|
|
|
}
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/*
|
|
|
|
* tvp7002_read - Read a value from a register in an TVP7002
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
2010-05-05 18:50:38 +08:00
|
|
|
* @addr: TVP7002 register address
|
2009-12-22 03:14:04 +08:00
|
|
|
* @dst: pointer to 8-bit destination
|
|
|
|
*
|
|
|
|
* Returns value read if successful, or non-zero (-1) otherwise.
|
|
|
|
*/
|
|
|
|
static int tvp7002_read(struct v4l2_subdev *sd, u8 addr, u8 *dst)
|
|
|
|
{
|
|
|
|
struct i2c_client *c = v4l2_get_subdevdata(sd);
|
|
|
|
int retry;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
for (retry = 0; retry < I2C_RETRY_COUNT; retry++) {
|
|
|
|
error = i2c_smbus_read_byte_data(c, addr);
|
|
|
|
|
|
|
|
if (error >= 0) {
|
|
|
|
*dst = (u8)error;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
msleep_interruptible(10);
|
|
|
|
}
|
|
|
|
v4l2_err(sd, "TVP7002 read error %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_read_err() - Read a register value with error code
|
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
|
|
|
* @reg: destination register
|
|
|
|
* @val: value to be read
|
2010-05-05 18:50:38 +08:00
|
|
|
* @err: pointer to error value
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
|
|
|
* Read a value in a register and save error value in pointer.
|
|
|
|
* Also update the register table if successful
|
|
|
|
*/
|
|
|
|
static inline void tvp7002_read_err(struct v4l2_subdev *sd, u8 reg,
|
|
|
|
u8 *dst, int *err)
|
|
|
|
{
|
|
|
|
if (!*err)
|
|
|
|
*err = tvp7002_read(sd, reg, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_write() - Write a value to a register in TVP7002
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
|
|
|
* @addr: TVP7002 register address
|
|
|
|
* @value: value to be written to the register
|
|
|
|
*
|
|
|
|
* Write a value to a register in an TVP7002 decoder device.
|
|
|
|
* Returns zero if successful, or non-zero otherwise.
|
|
|
|
*/
|
|
|
|
static int tvp7002_write(struct v4l2_subdev *sd, u8 addr, u8 value)
|
|
|
|
{
|
|
|
|
struct i2c_client *c;
|
|
|
|
int retry;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
c = v4l2_get_subdevdata(sd);
|
|
|
|
|
|
|
|
for (retry = 0; retry < I2C_RETRY_COUNT; retry++) {
|
|
|
|
error = i2c_smbus_write_byte_data(c, addr, value);
|
|
|
|
|
|
|
|
if (error >= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
v4l2_warn(sd, "Write: retry ... %d\n", retry);
|
|
|
|
msleep_interruptible(10);
|
|
|
|
}
|
|
|
|
v4l2_err(sd, "TVP7002 write error %d\n", error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_write_err() - Write a register value with error code
|
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
|
|
|
* @reg: destination register
|
|
|
|
* @val: value to be written
|
2010-05-05 18:50:38 +08:00
|
|
|
* @err: pointer to error value
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
|
|
|
* Write a value in a register and save error value in pointer.
|
|
|
|
* Also update the register table if successful
|
|
|
|
*/
|
|
|
|
static inline void tvp7002_write_err(struct v4l2_subdev *sd, u8 reg,
|
|
|
|
u8 val, int *err)
|
|
|
|
{
|
|
|
|
if (!*err)
|
|
|
|
*err = tvp7002_write(sd, reg, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_write_inittab() - Write initialization values
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
|
|
|
* @regs: ptr to i2c_reg_value struct
|
|
|
|
*
|
|
|
|
* Write initialization values.
|
|
|
|
* Returns zero or -EINVAL if read operation fails.
|
|
|
|
*/
|
|
|
|
static int tvp7002_write_inittab(struct v4l2_subdev *sd,
|
|
|
|
const struct i2c_reg_value *regs)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
/* Initialize the first (defined) registers */
|
|
|
|
while (TVP7002_EOR != regs->reg) {
|
|
|
|
if (TVP7002_WRITE == regs->type)
|
|
|
|
tvp7002_write_err(sd, regs->reg, regs->value, &error);
|
|
|
|
regs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2024-04-05 22:14:05 +08:00
|
|
|
static int tvp7002_s_dv_timings(struct v4l2_subdev *sd, unsigned int pad,
|
|
|
|
struct v4l2_dv_timings *dv_timings)
|
2012-05-15 19:07:24 +08:00
|
|
|
{
|
|
|
|
struct tvp7002 *device = to_tvp7002(sd);
|
|
|
|
const struct v4l2_bt_timings *bt = &dv_timings->bt;
|
|
|
|
int i;
|
|
|
|
|
2024-04-05 22:14:05 +08:00
|
|
|
if (pad != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-05-15 19:07:24 +08:00
|
|
|
if (dv_timings->type != V4L2_DV_BT_656_1120)
|
|
|
|
return -EINVAL;
|
2013-02-16 01:33:51 +08:00
|
|
|
for (i = 0; i < NUM_TIMINGS; i++) {
|
|
|
|
const struct v4l2_bt_timings *t = &tvp7002_timings[i].timings.bt;
|
2012-05-15 19:07:24 +08:00
|
|
|
|
|
|
|
if (!memcmp(bt, t, &bt->standards - &bt->width)) {
|
2013-02-16 01:33:51 +08:00
|
|
|
device->current_timings = &tvp7002_timings[i];
|
|
|
|
return tvp7002_write_inittab(sd, tvp7002_timings[i].p_settings);
|
2012-05-15 19:07:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-04-05 22:14:05 +08:00
|
|
|
static int tvp7002_g_dv_timings(struct v4l2_subdev *sd, unsigned int pad,
|
|
|
|
struct v4l2_dv_timings *dv_timings)
|
2012-05-15 19:07:24 +08:00
|
|
|
{
|
|
|
|
struct tvp7002 *device = to_tvp7002(sd);
|
|
|
|
|
2024-04-05 22:14:05 +08:00
|
|
|
if (pad != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
*dv_timings = device->current_timings->timings;
|
2012-05-15 19:07:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/*
|
|
|
|
* tvp7002_s_ctrl() - Set a control
|
2010-12-12 19:46:15 +08:00
|
|
|
* @ctrl: ptr to v4l2_ctrl struct
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
|
|
|
* Set a control in TVP7002 decoder device.
|
|
|
|
* Returns zero when successful or -EINVAL if register access fails.
|
|
|
|
*/
|
2010-12-12 19:46:15 +08:00
|
|
|
static int tvp7002_s_ctrl(struct v4l2_ctrl *ctrl)
|
2009-12-22 03:14:04 +08:00
|
|
|
{
|
2010-12-12 19:46:15 +08:00
|
|
|
struct v4l2_subdev *sd = to_sd(ctrl);
|
2009-12-22 03:14:04 +08:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_GAIN:
|
2010-12-12 19:46:15 +08:00
|
|
|
tvp7002_write_err(sd, TVP7002_R_FINE_GAIN, ctrl->val, &error);
|
|
|
|
tvp7002_write_err(sd, TVP7002_G_FINE_GAIN, ctrl->val, &error);
|
|
|
|
tvp7002_write_err(sd, TVP7002_B_FINE_GAIN, ctrl->val, &error);
|
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
2010-12-12 19:46:15 +08:00
|
|
|
return -EINVAL;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-02-16 01:33:51 +08:00
|
|
|
* tvp7002_query_dv() - query DV timings
|
2009-12-22 03:14:04 +08:00
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
2013-02-16 01:33:51 +08:00
|
|
|
* @index: index into the tvp7002_timings array
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
2013-02-16 01:33:51 +08:00
|
|
|
* Returns the current DV timings detected by TVP7002. If no active input is
|
2009-12-22 03:14:04 +08:00
|
|
|
* detected, returns -EINVAL
|
|
|
|
*/
|
2012-05-15 19:07:24 +08:00
|
|
|
static int tvp7002_query_dv(struct v4l2_subdev *sd, int *index)
|
2009-12-22 03:14:04 +08:00
|
|
|
{
|
2013-02-16 01:33:51 +08:00
|
|
|
const struct tvp7002_timings_definition *timings = tvp7002_timings;
|
2009-12-22 03:14:04 +08:00
|
|
|
u8 progressive;
|
|
|
|
u32 lpfr;
|
|
|
|
u32 cpln;
|
|
|
|
int error = 0;
|
|
|
|
u8 lpf_lsb;
|
|
|
|
u8 lpf_msb;
|
|
|
|
u8 cpl_lsb;
|
|
|
|
u8 cpl_msb;
|
|
|
|
|
2012-05-15 19:07:24 +08:00
|
|
|
/* Return invalid index if no active input is detected */
|
2013-02-16 01:33:51 +08:00
|
|
|
*index = NUM_TIMINGS;
|
2010-08-03 15:18:03 +08:00
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/* Read standards from device registers */
|
|
|
|
tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_LSBS, &lpf_lsb, &error);
|
|
|
|
tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_MSBS, &lpf_msb, &error);
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
tvp7002_read_err(sd, TVP7002_CLK_L_STAT_LSBS, &cpl_lsb, &error);
|
|
|
|
tvp7002_read_err(sd, TVP7002_CLK_L_STAT_MSBS, &cpl_msb, &error);
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Get lines per frame, clocks per line and interlaced/progresive */
|
|
|
|
lpfr = lpf_lsb | ((TVP7002_CL_MASK & lpf_msb) << TVP7002_CL_SHIFT);
|
|
|
|
cpln = cpl_lsb | ((TVP7002_CL_MASK & cpl_msb) << TVP7002_CL_SHIFT);
|
|
|
|
progressive = (lpf_msb & TVP7002_INPR_MASK) >> TVP7002_IP_SHIFT;
|
|
|
|
|
|
|
|
/* Do checking of video modes */
|
2013-02-16 01:33:51 +08:00
|
|
|
for (*index = 0; *index < NUM_TIMINGS; (*index)++, timings++)
|
|
|
|
if (lpfr == timings->lines_per_frame &&
|
|
|
|
progressive == timings->progressive) {
|
|
|
|
if (timings->cpl_min == 0xffff)
|
2009-12-22 03:14:04 +08:00
|
|
|
break;
|
2013-02-16 01:33:51 +08:00
|
|
|
if (cpln >= timings->cpl_min && cpln <= timings->cpl_max)
|
2009-12-22 03:14:04 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
if (*index == NUM_TIMINGS) {
|
2010-05-01 19:23:07 +08:00
|
|
|
v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n",
|
2009-12-22 03:14:04 +08:00
|
|
|
lpfr, cpln);
|
2012-05-15 19:07:24 +08:00
|
|
|
return -ENOLINK;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update lines per frame and clocks per line info */
|
2013-02-16 01:33:51 +08:00
|
|
|
v4l2_dbg(1, debug, sd, "detected timings: %d\n", *index);
|
2012-05-15 19:07:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-04-05 22:14:05 +08:00
|
|
|
static int tvp7002_query_dv_timings(struct v4l2_subdev *sd, unsigned int pad,
|
|
|
|
struct v4l2_dv_timings *timings)
|
2012-05-15 19:07:24 +08:00
|
|
|
{
|
|
|
|
int index;
|
2024-04-05 22:14:05 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (pad != 0)
|
|
|
|
return -EINVAL;
|
2012-05-15 19:07:24 +08:00
|
|
|
|
2024-04-05 22:14:05 +08:00
|
|
|
err = tvp7002_query_dv(sd, &index);
|
2012-05-15 19:07:24 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2013-02-16 01:33:51 +08:00
|
|
|
*timings = tvp7002_timings[index].timings;
|
2009-12-22 03:14:04 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_VIDEO_ADV_DEBUG
|
|
|
|
/*
|
|
|
|
* tvp7002_g_register() - Get the value of a register
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
2010-05-05 18:50:38 +08:00
|
|
|
* @reg: ptr to v4l2_dbg_register struct
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
|
|
|
* Get the value of a TVP7002 decoder device register.
|
|
|
|
* Returns zero when successful, -EINVAL if register read fails or
|
2013-05-14 12:45:14 +08:00
|
|
|
* access to I2C client fails.
|
2009-12-22 03:14:04 +08:00
|
|
|
*/
|
|
|
|
static int tvp7002_g_register(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_dbg_register *reg)
|
|
|
|
{
|
2010-02-26 04:34:09 +08:00
|
|
|
u8 val;
|
|
|
|
int ret;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
2010-02-26 04:34:09 +08:00
|
|
|
ret = tvp7002_read(sd, reg->reg & 0xff, &val);
|
2020-10-08 19:59:12 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-02-26 04:34:09 +08:00
|
|
|
reg->val = val;
|
2013-05-29 18:00:07 +08:00
|
|
|
reg->size = 1;
|
2020-10-08 19:59:12 +08:00
|
|
|
return 0;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_s_register() - set a control
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
2010-05-05 18:50:38 +08:00
|
|
|
* @reg: ptr to v4l2_dbg_register struct
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
|
|
|
* Get the value of a TVP7002 decoder device register.
|
2013-05-14 12:45:14 +08:00
|
|
|
* Returns zero when successful, -EINVAL if register read fails.
|
2009-12-22 03:14:04 +08:00
|
|
|
*/
|
|
|
|
static int tvp7002_s_register(struct v4l2_subdev *sd,
|
2013-03-24 19:28:46 +08:00
|
|
|
const struct v4l2_dbg_register *reg)
|
2009-12-22 03:14:04 +08:00
|
|
|
{
|
2010-02-26 04:34:09 +08:00
|
|
|
return tvp7002_write(sd, reg->reg & 0xff, reg->val & 0xff);
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_s_stream() - V4L2 decoder i/f handler for s_stream
|
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
|
|
|
* @enable: streaming enable or disable
|
|
|
|
*
|
|
|
|
* Sets streaming to enable or disable, if possible.
|
|
|
|
*/
|
|
|
|
static int tvp7002_s_stream(struct v4l2_subdev *sd, int enable)
|
|
|
|
{
|
|
|
|
struct tvp7002 *device = to_tvp7002(sd);
|
2014-08-16 14:57:30 +08:00
|
|
|
int error;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
if (device->streaming == enable)
|
|
|
|
return 0;
|
|
|
|
|
2014-08-16 14:57:30 +08:00
|
|
|
/* low impedance: on, high impedance: off */
|
|
|
|
error = tvp7002_write(sd, TVP7002_MISC_CTL_2, enable ? 0x00 : 0x03);
|
|
|
|
if (error) {
|
|
|
|
v4l2_dbg(1, debug, sd, "Fail to set streaming\n");
|
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
2014-08-16 14:57:30 +08:00
|
|
|
device->streaming = enable;
|
|
|
|
return 0;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_log_status() - Print information about register settings
|
|
|
|
* @sd: ptr to v4l2_subdev struct
|
|
|
|
*
|
|
|
|
* Log register values of a TVP7002 decoder device.
|
|
|
|
* Returns zero or -EINVAL if read operation fails.
|
|
|
|
*/
|
|
|
|
static int tvp7002_log_status(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
struct tvp7002 *device = to_tvp7002(sd);
|
2013-02-16 01:46:40 +08:00
|
|
|
const struct v4l2_bt_timings *bt;
|
|
|
|
int detected;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
2013-02-16 01:46:40 +08:00
|
|
|
/* Find my current timings */
|
|
|
|
tvp7002_query_dv(sd, &detected);
|
2009-12-22 03:14:04 +08:00
|
|
|
|
2013-02-16 01:46:40 +08:00
|
|
|
bt = &device->current_timings->timings.bt;
|
|
|
|
v4l2_info(sd, "Selected DV Timings: %ux%u\n", bt->width, bt->height);
|
|
|
|
if (detected == NUM_TIMINGS) {
|
|
|
|
v4l2_info(sd, "Detected DV Timings: None\n");
|
2009-12-22 03:14:04 +08:00
|
|
|
} else {
|
2013-02-16 01:46:40 +08:00
|
|
|
bt = &tvp7002_timings[detected].timings.bt;
|
|
|
|
v4l2_info(sd, "Detected DV Timings: %ux%u\n",
|
|
|
|
bt->width, bt->height);
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
v4l2_info(sd, "Streaming enabled: %s\n",
|
|
|
|
device->streaming ? "yes" : "no");
|
|
|
|
|
|
|
|
/* Print the current value of the gain control */
|
2010-12-12 19:46:15 +08:00
|
|
|
v4l2_ctrl_handler_log_status(&device->hdl, sd->name);
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-15 19:07:24 +08:00
|
|
|
static int tvp7002_enum_dv_timings(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_enum_dv_timings *timings)
|
|
|
|
{
|
2014-01-31 19:51:18 +08:00
|
|
|
if (timings->pad != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-05-15 19:07:24 +08:00
|
|
|
/* Check requested format index is within range */
|
2013-02-16 01:33:51 +08:00
|
|
|
if (timings->index >= NUM_TIMINGS)
|
2012-05-15 19:07:24 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-02-16 01:33:51 +08:00
|
|
|
timings->timings = tvp7002_timings[timings->index].timings;
|
2012-05-15 19:07:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-12 19:46:15 +08:00
|
|
|
static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = {
|
|
|
|
.s_ctrl = tvp7002_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2013-05-03 15:17:19 +08:00
|
|
|
/*
|
|
|
|
* tvp7002_enum_mbus_code() - Enum supported digital video format on pad
|
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
2023-10-27 17:58:52 +08:00
|
|
|
* @sd_state: V4L2 subdev state
|
2013-05-03 15:17:19 +08:00
|
|
|
* @code: pointer to subdev enum mbus code struct
|
|
|
|
*
|
|
|
|
* Enumerate supported digital video formats for pad.
|
|
|
|
*/
|
|
|
|
static int
|
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 22:55:58 +08:00
|
|
|
tvp7002_enum_mbus_code(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
2013-05-03 15:17:19 +08:00
|
|
|
struct v4l2_subdev_mbus_code_enum *code)
|
|
|
|
{
|
|
|
|
/* Check requested format index is within range */
|
|
|
|
if (code->index != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-11-11 01:28:29 +08:00
|
|
|
code->code = MEDIA_BUS_FMT_YUYV10_1X20;
|
2013-05-03 15:17:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_get_pad_format() - get video format on pad
|
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
2023-10-27 17:58:52 +08:00
|
|
|
* @sd_state: V4L2 subdev state
|
2013-05-03 15:17:19 +08:00
|
|
|
* @fmt: pointer to subdev format struct
|
|
|
|
*
|
|
|
|
* get video format for pad.
|
|
|
|
*/
|
|
|
|
static int
|
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 22:55:58 +08:00
|
|
|
tvp7002_get_pad_format(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
2013-05-03 15:17:19 +08:00
|
|
|
struct v4l2_subdev_format *fmt)
|
|
|
|
{
|
|
|
|
struct tvp7002 *tvp7002 = to_tvp7002(sd);
|
|
|
|
|
2014-11-11 01:28:29 +08:00
|
|
|
fmt->format.code = MEDIA_BUS_FMT_YUYV10_1X20;
|
2013-05-03 15:17:19 +08:00
|
|
|
fmt->format.width = tvp7002->current_timings->timings.bt.width;
|
|
|
|
fmt->format.height = tvp7002->current_timings->timings.bt.height;
|
|
|
|
fmt->format.field = tvp7002->current_timings->scanmode;
|
|
|
|
fmt->format.colorspace = tvp7002->current_timings->color_space;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_set_pad_format() - set video format on pad
|
|
|
|
* @sd: pointer to standard V4L2 sub-device structure
|
2023-10-27 17:58:52 +08:00
|
|
|
* @sd_state: V4L2 subdev state
|
2013-05-03 15:17:19 +08:00
|
|
|
* @fmt: pointer to subdev format struct
|
|
|
|
*
|
|
|
|
* set video format for pad.
|
|
|
|
*/
|
|
|
|
static int
|
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 22:55:58 +08:00
|
|
|
tvp7002_set_pad_format(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
2013-05-03 15:17:19 +08:00
|
|
|
struct v4l2_subdev_format *fmt)
|
|
|
|
{
|
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 22:55:58 +08:00
|
|
|
return tvp7002_get_pad_format(sd, sd_state, fmt);
|
2013-05-03 15:17:19 +08:00
|
|
|
}
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/* V4L2 core operation handlers */
|
|
|
|
static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
|
|
|
|
.log_status = tvp7002_log_status,
|
|
|
|
#ifdef CONFIG_VIDEO_ADV_DEBUG
|
|
|
|
.g_register = tvp7002_g_register,
|
|
|
|
.s_register = tvp7002_s_register,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Specific video subsystem operation handlers */
|
|
|
|
static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
|
|
|
|
.s_stream = tvp7002_s_stream,
|
|
|
|
};
|
|
|
|
|
2013-05-03 15:17:19 +08:00
|
|
|
/* media pad related operation handlers */
|
|
|
|
static const struct v4l2_subdev_pad_ops tvp7002_pad_ops = {
|
|
|
|
.enum_mbus_code = tvp7002_enum_mbus_code,
|
|
|
|
.get_fmt = tvp7002_get_pad_format,
|
|
|
|
.set_fmt = tvp7002_set_pad_format,
|
2024-04-05 22:14:05 +08:00
|
|
|
.g_dv_timings = tvp7002_g_dv_timings,
|
|
|
|
.s_dv_timings = tvp7002_s_dv_timings,
|
|
|
|
.query_dv_timings = tvp7002_query_dv_timings,
|
2014-01-31 19:51:18 +08:00
|
|
|
.enum_dv_timings = tvp7002_enum_dv_timings,
|
2013-05-03 15:17:19 +08:00
|
|
|
};
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/* V4L2 top level operation handlers */
|
|
|
|
static const struct v4l2_subdev_ops tvp7002_ops = {
|
|
|
|
.core = &tvp7002_core_ops,
|
|
|
|
.video = &tvp7002_video_ops,
|
2013-05-03 15:17:19 +08:00
|
|
|
.pad = &tvp7002_pad_ops,
|
2009-12-22 03:14:04 +08:00
|
|
|
};
|
|
|
|
|
2013-08-11 13:25:21 +08:00
|
|
|
static struct tvp7002_config *
|
|
|
|
tvp7002_get_pdata(struct i2c_client *client)
|
|
|
|
{
|
2018-07-31 17:15:50 +08:00
|
|
|
struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
|
2016-01-12 00:47:14 +08:00
|
|
|
struct tvp7002_config *pdata = NULL;
|
2013-08-11 13:25:21 +08:00
|
|
|
struct device_node *endpoint;
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
|
|
|
|
return client->dev.platform_data;
|
|
|
|
|
2024-02-20 09:16:21 +08:00
|
|
|
endpoint = of_graph_get_endpoint_by_regs(client->dev.of_node, 0, -1);
|
2013-08-11 13:25:21 +08:00
|
|
|
if (!endpoint)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-27 07:17:25 +08:00
|
|
|
if (v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint), &bus_cfg))
|
2016-01-12 00:47:14 +08:00
|
|
|
goto done;
|
|
|
|
|
2013-08-11 13:25:21 +08:00
|
|
|
pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
flags = bus_cfg.bus.parallel.flags;
|
|
|
|
|
|
|
|
if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
|
|
|
|
pdata->hs_polarity = 1;
|
|
|
|
|
|
|
|
if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
|
|
|
|
pdata->vs_polarity = 1;
|
|
|
|
|
|
|
|
if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
|
|
|
|
pdata->clk_polarity = 1;
|
|
|
|
|
|
|
|
if (flags & V4L2_MBUS_FIELD_EVEN_HIGH)
|
|
|
|
pdata->fid_polarity = 1;
|
|
|
|
|
|
|
|
if (flags & V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH)
|
|
|
|
pdata->sog_polarity = 1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
of_node_put(endpoint);
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/*
|
|
|
|
* tvp7002_probe - Probe a TVP7002 device
|
2010-05-05 18:50:38 +08:00
|
|
|
* @c: ptr to i2c_client struct
|
|
|
|
* @id: ptr to i2c_device_id struct
|
2009-12-22 03:14:04 +08:00
|
|
|
*
|
|
|
|
* Initialize the TVP7002 device
|
|
|
|
* Returns zero when successful, -EINVAL if register read fails or
|
|
|
|
* -EIO if i2c access is not available.
|
|
|
|
*/
|
2019-07-11 05:51:49 +08:00
|
|
|
static int tvp7002_probe(struct i2c_client *c)
|
2009-12-22 03:14:04 +08:00
|
|
|
{
|
2013-08-11 13:25:21 +08:00
|
|
|
struct tvp7002_config *pdata = tvp7002_get_pdata(c);
|
2009-12-22 03:14:04 +08:00
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
struct tvp7002 *device;
|
2013-02-16 01:46:40 +08:00
|
|
|
struct v4l2_dv_timings timings;
|
2009-12-22 03:14:04 +08:00
|
|
|
int polarity_a;
|
|
|
|
int polarity_b;
|
|
|
|
u8 revision;
|
|
|
|
int error;
|
|
|
|
|
2013-08-11 13:25:21 +08:00
|
|
|
if (pdata == NULL) {
|
|
|
|
dev_err(&c->dev, "No platform data\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/* Check if the adapter supports the needed features */
|
|
|
|
if (!i2c_check_functionality(c->adapter,
|
|
|
|
I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
|
|
|
|
return -EIO;
|
|
|
|
|
2013-01-03 20:46:43 +08:00
|
|
|
device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL);
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
if (!device)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sd = &device->sd;
|
2013-08-11 13:25:21 +08:00
|
|
|
device->pdata = pdata;
|
2013-02-16 01:33:51 +08:00
|
|
|
device->current_timings = tvp7002_timings;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
/* Tell v4l2 the device is ready */
|
|
|
|
v4l2_i2c_subdev_init(sd, c, &tvp7002_ops);
|
|
|
|
v4l_info(c, "tvp7002 found @ 0x%02x (%s)\n",
|
|
|
|
c->addr, c->adapter->name);
|
|
|
|
|
|
|
|
error = tvp7002_read(sd, TVP7002_CHIP_REV, &revision);
|
|
|
|
if (error < 0)
|
2013-01-03 20:46:43 +08:00
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
/* Get revision number */
|
|
|
|
v4l2_info(sd, "Rev. %02x detected.\n", revision);
|
|
|
|
if (revision != 0x02)
|
|
|
|
v4l2_info(sd, "Unknown revision detected.\n");
|
|
|
|
|
|
|
|
/* Initializes TVP7002 to its default values */
|
|
|
|
error = tvp7002_write_inittab(sd, tvp7002_init_default);
|
|
|
|
|
|
|
|
if (error < 0)
|
2013-01-03 20:46:43 +08:00
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
/* Set polarity information after registers have been set */
|
|
|
|
polarity_a = 0x20 | device->pdata->hs_polarity << 5
|
|
|
|
| device->pdata->vs_polarity << 2;
|
|
|
|
error = tvp7002_write(sd, TVP7002_SYNC_CTL_1, polarity_a);
|
|
|
|
if (error < 0)
|
2013-01-03 20:46:43 +08:00
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
polarity_b = 0x01 | device->pdata->fid_polarity << 2
|
|
|
|
| device->pdata->sog_polarity << 1
|
|
|
|
| device->pdata->clk_polarity;
|
|
|
|
error = tvp7002_write(sd, TVP7002_MISC_CTL_3, polarity_b);
|
|
|
|
if (error < 0)
|
2013-01-03 20:46:43 +08:00
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
|
|
|
|
/* Set registers according to default video mode */
|
2013-02-16 01:46:40 +08:00
|
|
|
timings = device->current_timings->timings;
|
2024-04-05 22:14:05 +08:00
|
|
|
error = tvp7002_s_dv_timings(sd, 0, &timings);
|
2009-12-22 03:14:04 +08:00
|
|
|
|
2013-05-03 15:17:19 +08:00
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER)
|
|
|
|
device->pad.flags = MEDIA_PAD_FL_SOURCE;
|
|
|
|
device->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
|
2018-06-18 17:09:45 +08:00
|
|
|
device->sd.entity.function = MEDIA_ENT_F_ATV_DECODER;
|
2013-05-03 15:17:19 +08:00
|
|
|
|
2015-12-11 17:44:40 +08:00
|
|
|
error = media_entity_pads_init(&device->sd.entity, 1, &device->pad);
|
2013-05-03 15:17:19 +08:00
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
#endif
|
|
|
|
|
2010-12-12 19:46:15 +08:00
|
|
|
v4l2_ctrl_handler_init(&device->hdl, 1);
|
|
|
|
v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
|
|
|
|
V4L2_CID_GAIN, 0, 255, 1, 0);
|
|
|
|
sd->ctrl_handler = &device->hdl;
|
|
|
|
if (device->hdl.error) {
|
2013-05-03 15:17:19 +08:00
|
|
|
error = device->hdl.error;
|
|
|
|
goto error;
|
2010-12-12 19:46:15 +08:00
|
|
|
}
|
|
|
|
v4l2_ctrl_handler_setup(&device->hdl);
|
|
|
|
|
2013-06-23 00:44:14 +08:00
|
|
|
error = v4l2_async_register_subdev(&device->sd);
|
|
|
|
if (error)
|
|
|
|
goto error;
|
|
|
|
|
2013-01-03 20:46:43 +08:00
|
|
|
return 0;
|
2013-05-03 15:17:19 +08:00
|
|
|
|
|
|
|
error:
|
|
|
|
v4l2_ctrl_handler_free(&device->hdl);
|
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER)
|
|
|
|
media_entity_cleanup(&device->sd.entity);
|
|
|
|
#endif
|
|
|
|
return error;
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tvp7002_remove - Remove TVP7002 device support
|
|
|
|
* @c: ptr to i2c_client struct
|
|
|
|
*
|
|
|
|
* Reset the TVP7002 device
|
|
|
|
* Returns zero.
|
|
|
|
*/
|
2022-08-15 16:02:30 +08:00
|
|
|
static void tvp7002_remove(struct i2c_client *c)
|
2009-12-22 03:14:04 +08:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(c);
|
|
|
|
struct tvp7002 *device = to_tvp7002(sd);
|
|
|
|
|
|
|
|
v4l2_dbg(1, debug, sd, "Removing tvp7002 adapter"
|
|
|
|
"on address 0x%x\n", c->addr);
|
2013-06-23 00:44:14 +08:00
|
|
|
v4l2_async_unregister_subdev(&device->sd);
|
2013-05-03 15:17:19 +08:00
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER)
|
|
|
|
media_entity_cleanup(&device->sd.entity);
|
|
|
|
#endif
|
2010-12-12 19:46:15 +08:00
|
|
|
v4l2_ctrl_handler_free(&device->hdl);
|
2009-12-22 03:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* I2C Device ID table */
|
|
|
|
static const struct i2c_device_id tvp7002_id[] = {
|
|
|
|
{ "tvp7002", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, tvp7002_id);
|
|
|
|
|
2013-08-11 13:25:21 +08:00
|
|
|
#if IS_ENABLED(CONFIG_OF)
|
|
|
|
static const struct of_device_id tvp7002_of_match[] = {
|
|
|
|
{ .compatible = "ti,tvp7002", },
|
|
|
|
{ /* sentinel */ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, tvp7002_of_match);
|
|
|
|
#endif
|
|
|
|
|
2009-12-22 03:14:04 +08:00
|
|
|
/* I2C driver data */
|
|
|
|
static struct i2c_driver tvp7002_driver = {
|
|
|
|
.driver = {
|
2013-08-11 13:25:21 +08:00
|
|
|
.of_match_table = of_match_ptr(tvp7002_of_match),
|
2009-12-22 03:14:04 +08:00
|
|
|
.name = TVP7002_MODULE_NAME,
|
|
|
|
},
|
2023-05-14 20:04:07 +08:00
|
|
|
.probe = tvp7002_probe,
|
2009-12-22 03:14:04 +08:00
|
|
|
.remove = tvp7002_remove,
|
|
|
|
.id_table = tvp7002_id,
|
|
|
|
};
|
|
|
|
|
2012-02-12 17:56:32 +08:00
|
|
|
module_i2c_driver(tvp7002_driver);
|