2018-08-06 06:17:30 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-09-19 04:17:20 +04:00
|
|
|
/*
|
|
|
|
* adv7180.c Analog Devices ADV7180 video decoder driver
|
|
|
|
* Copyright (c) 2009 Intel Corporation
|
2013-05-29 21:50:57 +04:00
|
|
|
* Copyright (C) 2013 Cogent Embedded, Inc.
|
|
|
|
* Copyright (C) 2013 Renesas Solutions Corp.
|
2009-09-19 04:17:20 +04:00
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/interrupt.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 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2015-06-03 16:59:50 +03:00
|
|
|
#include <linux/of.h>
|
2016-07-20 03:03:32 +03:00
|
|
|
#include <linux/gpio/consumer.h>
|
2009-09-19 04:17:20 +04:00
|
|
|
#include <linux/videodev2.h>
|
2016-04-22 16:03:37 +03:00
|
|
|
#include <media/v4l2-ioctl.h>
|
|
|
|
#include <media/v4l2-event.h>
|
2009-09-19 04:17:20 +04:00
|
|
|
#include <media/v4l2-device.h>
|
2012-07-11 18:29:33 +04:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2009-09-22 13:07:06 +04:00
|
|
|
#include <linux/mutex.h>
|
2015-01-23 18:52:25 +03:00
|
|
|
#include <linux/delay.h>
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
#define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM 0x0
|
|
|
|
#define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM_PED 0x1
|
|
|
|
#define ADV7180_STD_AD_PAL_N_NTSC_J_SECAM 0x2
|
|
|
|
#define ADV7180_STD_AD_PAL_N_NTSC_M_SECAM 0x3
|
|
|
|
#define ADV7180_STD_NTSC_J 0x4
|
|
|
|
#define ADV7180_STD_NTSC_M 0x5
|
|
|
|
#define ADV7180_STD_PAL60 0x6
|
|
|
|
#define ADV7180_STD_NTSC_443 0x7
|
|
|
|
#define ADV7180_STD_PAL_BG 0x8
|
|
|
|
#define ADV7180_STD_PAL_N 0x9
|
|
|
|
#define ADV7180_STD_PAL_M 0xa
|
|
|
|
#define ADV7180_STD_PAL_M_PED 0xb
|
|
|
|
#define ADV7180_STD_PAL_COMB_N 0xc
|
|
|
|
#define ADV7180_STD_PAL_COMB_N_PED 0xd
|
|
|
|
#define ADV7180_STD_PAL_SECAM 0xe
|
|
|
|
#define ADV7180_STD_PAL_SECAM_PED 0xf
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_INPUT_CONTROL 0x0000
|
2012-04-12 19:39:36 +04:00
|
|
|
#define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f
|
2009-09-22 13:05:42 +04:00
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
#define ADV7182_REG_INPUT_VIDSEL 0x0002
|
|
|
|
|
2016-07-20 03:03:30 +03:00
|
|
|
#define ADV7180_REG_OUTPUT_CONTROL 0x0003
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_EXTENDED_OUTPUT_CONTROL 0x0004
|
2009-09-22 13:07:06 +04:00
|
|
|
#define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2016-07-20 03:03:30 +03:00
|
|
|
#define ADV7180_REG_AUTODETECT_ENABLE 0x0007
|
2009-09-22 13:07:06 +04:00
|
|
|
#define ADV7180_AUTODETECT_DEFAULT 0x7f
|
2012-07-11 18:29:33 +04:00
|
|
|
/* Contrast */
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_CON 0x0008 /*Unsigned */
|
2012-07-11 18:29:33 +04:00
|
|
|
#define ADV7180_CON_MIN 0
|
|
|
|
#define ADV7180_CON_DEF 128
|
|
|
|
#define ADV7180_CON_MAX 255
|
|
|
|
/* Brightness*/
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_BRI 0x000a /*Signed */
|
2012-07-11 18:29:33 +04:00
|
|
|
#define ADV7180_BRI_MIN -128
|
|
|
|
#define ADV7180_BRI_DEF 0
|
|
|
|
#define ADV7180_BRI_MAX 127
|
|
|
|
/* Hue */
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_HUE 0x000b /*Signed, inverted */
|
2012-07-11 18:29:33 +04:00
|
|
|
#define ADV7180_HUE_MIN -127
|
|
|
|
#define ADV7180_HUE_DEF 0
|
|
|
|
#define ADV7180_HUE_MAX 128
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_CTRL 0x000e
|
2015-01-23 18:52:23 +03:00
|
|
|
#define ADV7180_CTRL_IRQ_SPACE 0x20
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2015-01-23 18:52:23 +03:00
|
|
|
#define ADV7180_REG_PWR_MAN 0x0f
|
2012-04-12 19:39:36 +04:00
|
|
|
#define ADV7180_PWR_MAN_ON 0x04
|
|
|
|
#define ADV7180_PWR_MAN_OFF 0x24
|
|
|
|
#define ADV7180_PWR_MAN_RES 0x80
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_STATUS1 0x0010
|
2009-09-22 13:05:42 +04:00
|
|
|
#define ADV7180_STATUS1_IN_LOCK 0x01
|
|
|
|
#define ADV7180_STATUS1_AUTOD_MASK 0x70
|
2009-09-19 04:17:20 +04:00
|
|
|
#define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00
|
|
|
|
#define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_M 0x20
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_60 0x30
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_B_G 0x40
|
|
|
|
#define ADV7180_STATUS1_AUTOD_SECAM 0x50
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60
|
|
|
|
#define ADV7180_STATUS1_AUTOD_SECAM_525 0x70
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_IDENT 0x0011
|
2009-09-19 04:17:20 +04:00
|
|
|
#define ADV7180_ID_7180 0x18
|
|
|
|
|
2016-07-20 03:03:30 +03:00
|
|
|
#define ADV7180_REG_STATUS3 0x0013
|
|
|
|
#define ADV7180_REG_ANALOG_CLAMP_CTL 0x0014
|
|
|
|
#define ADV7180_REG_SHAP_FILTER_CTL_1 0x0017
|
|
|
|
#define ADV7180_REG_CTRL_2 0x001d
|
|
|
|
#define ADV7180_REG_VSYNC_FIELD_CTL_1 0x0031
|
2021-06-05 00:22:17 +03:00
|
|
|
#define ADV7180_VSYNC_FIELD_CTL_1_NEWAV 0x12
|
2016-07-20 03:03:30 +03:00
|
|
|
#define ADV7180_REG_MANUAL_WIN_CTL_1 0x003d
|
|
|
|
#define ADV7180_REG_MANUAL_WIN_CTL_2 0x003e
|
|
|
|
#define ADV7180_REG_MANUAL_WIN_CTL_3 0x003f
|
|
|
|
#define ADV7180_REG_LOCK_CNT 0x0051
|
|
|
|
#define ADV7180_REG_CVBS_TRIM 0x0052
|
|
|
|
#define ADV7180_REG_CLAMP_ADJ 0x005a
|
|
|
|
#define ADV7180_REG_RES_CIR 0x005f
|
|
|
|
#define ADV7180_REG_DIFF_MODE 0x0060
|
|
|
|
|
2016-07-20 03:03:29 +03:00
|
|
|
#define ADV7180_REG_ICONF1 0x2040
|
2009-09-22 13:07:06 +04:00
|
|
|
#define ADV7180_ICONF1_ACTIVE_LOW 0x01
|
|
|
|
#define ADV7180_ICONF1_PSYNC_ONLY 0x10
|
|
|
|
#define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0
|
2012-07-11 18:29:33 +04:00
|
|
|
/* Saturation */
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_SD_SAT_CB 0x00e3 /*Unsigned */
|
|
|
|
#define ADV7180_REG_SD_SAT_CR 0x00e4 /*Unsigned */
|
2012-07-11 18:29:33 +04:00
|
|
|
#define ADV7180_SAT_MIN 0
|
|
|
|
#define ADV7180_SAT_DEF 128
|
|
|
|
#define ADV7180_SAT_MAX 255
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2009-09-22 13:07:06 +04:00
|
|
|
#define ADV7180_IRQ1_LOCK 0x01
|
|
|
|
#define ADV7180_IRQ1_UNLOCK 0x02
|
2016-07-20 03:03:29 +03:00
|
|
|
#define ADV7180_REG_ISR1 0x2042
|
|
|
|
#define ADV7180_REG_ICR1 0x2043
|
|
|
|
#define ADV7180_REG_IMR1 0x2044
|
|
|
|
#define ADV7180_REG_IMR2 0x2048
|
2009-09-22 13:07:06 +04:00
|
|
|
#define ADV7180_IRQ3_AD_CHANGE 0x08
|
2016-07-20 03:03:29 +03:00
|
|
|
#define ADV7180_REG_ISR3 0x204A
|
|
|
|
#define ADV7180_REG_ICR3 0x204B
|
|
|
|
#define ADV7180_REG_IMR3 0x204C
|
|
|
|
#define ADV7180_REG_IMR4 0x2050
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
#define ADV7180_REG_NTSC_V_BIT_END 0x00E6
|
2012-04-12 19:39:36 +04:00
|
|
|
#define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F
|
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
#define ADV7180_REG_VPP_SLAVE_ADDR 0xFD
|
2015-01-23 18:52:31 +03:00
|
|
|
#define ADV7180_REG_CSI_SLAVE_ADDR 0xFE
|
|
|
|
|
2016-07-20 03:03:30 +03:00
|
|
|
#define ADV7180_REG_ACE_CTRL1 0x4080
|
|
|
|
#define ADV7180_REG_ACE_CTRL5 0x4084
|
|
|
|
#define ADV7180_REG_FLCONTROL 0x40e0
|
2015-01-23 18:52:33 +03:00
|
|
|
#define ADV7180_FLCONTROL_FL_ENABLE 0x1
|
|
|
|
|
2016-07-20 03:03:30 +03:00
|
|
|
#define ADV7180_REG_RST_CLAMP 0x809c
|
|
|
|
#define ADV7180_REG_AGC_ADJ1 0x80b6
|
|
|
|
#define ADV7180_REG_AGC_ADJ2 0x80c0
|
|
|
|
|
2015-01-23 18:52:31 +03:00
|
|
|
#define ADV7180_CSI_REG_PWRDN 0x00
|
|
|
|
#define ADV7180_CSI_PWRDN 0x80
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
#define ADV7180_INPUT_CVBS_AIN1 0x00
|
|
|
|
#define ADV7180_INPUT_CVBS_AIN2 0x01
|
|
|
|
#define ADV7180_INPUT_CVBS_AIN3 0x02
|
|
|
|
#define ADV7180_INPUT_CVBS_AIN4 0x03
|
|
|
|
#define ADV7180_INPUT_CVBS_AIN5 0x04
|
|
|
|
#define ADV7180_INPUT_CVBS_AIN6 0x05
|
|
|
|
#define ADV7180_INPUT_SVIDEO_AIN1_AIN2 0x06
|
|
|
|
#define ADV7180_INPUT_SVIDEO_AIN3_AIN4 0x07
|
|
|
|
#define ADV7180_INPUT_SVIDEO_AIN5_AIN6 0x08
|
|
|
|
#define ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3 0x09
|
|
|
|
#define ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0a
|
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
#define ADV7182_INPUT_CVBS_AIN1 0x00
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN2 0x01
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN3 0x02
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN4 0x03
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN5 0x04
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN6 0x05
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN7 0x06
|
|
|
|
#define ADV7182_INPUT_CVBS_AIN8 0x07
|
|
|
|
#define ADV7182_INPUT_SVIDEO_AIN1_AIN2 0x08
|
|
|
|
#define ADV7182_INPUT_SVIDEO_AIN3_AIN4 0x09
|
|
|
|
#define ADV7182_INPUT_SVIDEO_AIN5_AIN6 0x0a
|
|
|
|
#define ADV7182_INPUT_SVIDEO_AIN7_AIN8 0x0b
|
|
|
|
#define ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3 0x0c
|
|
|
|
#define ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0d
|
|
|
|
#define ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2 0x0e
|
|
|
|
#define ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4 0x0f
|
|
|
|
#define ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6 0x10
|
|
|
|
#define ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8 0x11
|
|
|
|
|
2015-01-23 18:52:31 +03:00
|
|
|
#define ADV7180_DEFAULT_CSI_I2C_ADDR 0x44
|
2015-01-23 18:52:32 +03:00
|
|
|
#define ADV7180_DEFAULT_VPP_I2C_ADDR 0x42
|
2015-01-23 18:52:31 +03:00
|
|
|
|
2015-01-23 18:52:33 +03:00
|
|
|
#define V4L2_CID_ADV_FAST_SWITCH (V4L2_CID_USER_ADV7180_BASE + 0x00)
|
|
|
|
|
2018-10-24 23:25:51 +03:00
|
|
|
/* Initial number of frames to skip to avoid possible garbage */
|
|
|
|
#define ADV7180_NUM_OF_SKIP_FRAMES 2
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
struct adv7180_state;
|
|
|
|
|
|
|
|
#define ADV7180_FLAG_RESET_POWERED BIT(0)
|
2015-01-23 18:52:30 +03:00
|
|
|
#define ADV7180_FLAG_V2 BIT(1)
|
2015-01-23 18:52:31 +03:00
|
|
|
#define ADV7180_FLAG_MIPI_CSI2 BIT(2)
|
2015-01-23 18:52:32 +03:00
|
|
|
#define ADV7180_FLAG_I2P BIT(3)
|
2015-01-23 18:52:28 +03:00
|
|
|
|
|
|
|
struct adv7180_chip_info {
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int valid_input_mask;
|
|
|
|
int (*set_std)(struct adv7180_state *st, unsigned int std);
|
|
|
|
int (*select_input)(struct adv7180_state *st, unsigned int input);
|
|
|
|
int (*init)(struct adv7180_state *state);
|
|
|
|
};
|
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
struct adv7180_state {
|
2012-07-11 18:29:33 +04:00
|
|
|
struct v4l2_ctrl_handler ctrl_hdl;
|
2009-09-22 13:06:34 +04:00
|
|
|
struct v4l2_subdev sd;
|
2015-01-23 18:52:26 +03:00
|
|
|
struct media_pad pad;
|
2009-09-22 13:07:06 +04:00
|
|
|
struct mutex mutex; /* mutual excl. when accessing chip */
|
|
|
|
int irq;
|
2016-07-20 03:03:32 +03:00
|
|
|
struct gpio_desc *pwdn_gpio;
|
2021-05-31 14:22:36 +03:00
|
|
|
struct gpio_desc *rst_gpio;
|
2009-09-22 13:06:34 +04:00
|
|
|
v4l2_std_id curr_norm;
|
2014-03-10 21:05:39 +04:00
|
|
|
bool powered;
|
2016-04-22 16:03:37 +03:00
|
|
|
bool streaming;
|
2012-04-12 19:39:36 +04:00
|
|
|
u8 input;
|
2015-01-23 18:52:24 +03:00
|
|
|
|
|
|
|
struct i2c_client *client;
|
|
|
|
unsigned int register_page;
|
2015-01-23 18:52:31 +03:00
|
|
|
struct i2c_client *csi_client;
|
2015-01-23 18:52:32 +03:00
|
|
|
struct i2c_client *vpp_client;
|
2015-01-23 18:52:28 +03:00
|
|
|
const struct adv7180_chip_info *chip_info;
|
2015-01-23 18:52:32 +03:00
|
|
|
enum v4l2_field field;
|
2021-06-05 00:22:17 +03:00
|
|
|
bool force_bt656_4;
|
2009-09-19 04:17:20 +04:00
|
|
|
};
|
2012-07-11 18:29:33 +04:00
|
|
|
#define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
|
|
|
|
struct adv7180_state, \
|
|
|
|
ctrl_hdl)->sd)
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
static int adv7180_select_page(struct adv7180_state *state, unsigned int page)
|
|
|
|
{
|
|
|
|
if (state->register_page != page) {
|
|
|
|
i2c_smbus_write_byte_data(state->client, ADV7180_REG_CTRL,
|
|
|
|
page);
|
|
|
|
state->register_page = page;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_write(struct adv7180_state *state, unsigned int reg,
|
|
|
|
unsigned int value)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&state->mutex);
|
|
|
|
adv7180_select_page(state, reg >> 8);
|
|
|
|
return i2c_smbus_write_byte_data(state->client, reg & 0xff, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_read(struct adv7180_state *state, unsigned int reg)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&state->mutex);
|
|
|
|
adv7180_select_page(state, reg >> 8);
|
|
|
|
return i2c_smbus_read_byte_data(state->client, reg & 0xff);
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:31 +03:00
|
|
|
static int adv7180_csi_write(struct adv7180_state *state, unsigned int reg,
|
|
|
|
unsigned int value)
|
|
|
|
{
|
|
|
|
return i2c_smbus_write_byte_data(state->csi_client, reg, value);
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
static int adv7180_set_video_standard(struct adv7180_state *state,
|
|
|
|
unsigned int std)
|
|
|
|
{
|
|
|
|
return state->chip_info->set_std(state, std);
|
|
|
|
}
|
2015-01-23 18:52:24 +03:00
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
static int adv7180_vpp_write(struct adv7180_state *state, unsigned int reg,
|
|
|
|
unsigned int value)
|
|
|
|
{
|
|
|
|
return i2c_smbus_write_byte_data(state->vpp_client, reg, value);
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:05:42 +04:00
|
|
|
static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
|
2009-09-19 04:17:20 +04:00
|
|
|
{
|
2013-04-12 01:06:46 +04:00
|
|
|
/* in case V4L2_IN_ST_NO_SIGNAL */
|
|
|
|
if (!(status1 & ADV7180_STATUS1_IN_LOCK))
|
|
|
|
return V4L2_STD_UNKNOWN;
|
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
switch (status1 & ADV7180_STATUS1_AUTOD_MASK) {
|
|
|
|
case ADV7180_STATUS1_AUTOD_NTSM_M_J:
|
2009-09-22 13:05:42 +04:00
|
|
|
return V4L2_STD_NTSC;
|
2009-09-19 04:17:20 +04:00
|
|
|
case ADV7180_STATUS1_AUTOD_NTSC_4_43:
|
|
|
|
return V4L2_STD_NTSC_443;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_M:
|
|
|
|
return V4L2_STD_PAL_M;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_60:
|
|
|
|
return V4L2_STD_PAL_60;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_B_G:
|
|
|
|
return V4L2_STD_PAL;
|
|
|
|
case ADV7180_STATUS1_AUTOD_SECAM:
|
|
|
|
return V4L2_STD_SECAM;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_COMB:
|
|
|
|
return V4L2_STD_PAL_Nc | V4L2_STD_PAL_N;
|
|
|
|
case ADV7180_STATUS1_AUTOD_SECAM_525:
|
|
|
|
return V4L2_STD_SECAM;
|
|
|
|
default:
|
|
|
|
return V4L2_STD_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:06:34 +04:00
|
|
|
static int v4l2_std_to_adv7180(v4l2_std_id std)
|
|
|
|
{
|
|
|
|
if (std == V4L2_STD_PAL_60)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_PAL60;
|
2009-09-22 13:06:34 +04:00
|
|
|
if (std == V4L2_STD_NTSC_443)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_NTSC_443;
|
2009-09-22 13:06:34 +04:00
|
|
|
if (std == V4L2_STD_PAL_N)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_PAL_N;
|
2009-09-22 13:06:34 +04:00
|
|
|
if (std == V4L2_STD_PAL_M)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_PAL_M;
|
2009-09-22 13:06:34 +04:00
|
|
|
if (std == V4L2_STD_PAL_Nc)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_PAL_COMB_N;
|
2009-09-22 13:06:34 +04:00
|
|
|
|
|
|
|
if (std & V4L2_STD_PAL)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_PAL_BG;
|
2009-09-22 13:06:34 +04:00
|
|
|
if (std & V4L2_STD_NTSC)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_NTSC_M;
|
2009-09-22 13:06:34 +04:00
|
|
|
if (std & V4L2_STD_SECAM)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ADV7180_STD_PAL_SECAM;
|
2009-09-22 13:06:34 +04:00
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:05:42 +04:00
|
|
|
static u32 adv7180_status_to_v4l2(u8 status1)
|
|
|
|
{
|
|
|
|
if (!(status1 & ADV7180_STATUS1_IN_LOCK))
|
|
|
|
return V4L2_IN_ST_NO_SIGNAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
static int __adv7180_status(struct adv7180_state *state, u32 *status,
|
2012-04-12 19:39:36 +04:00
|
|
|
v4l2_std_id *std)
|
2009-09-22 13:05:42 +04:00
|
|
|
{
|
2015-01-23 18:52:24 +03:00
|
|
|
int status1 = adv7180_read(state, ADV7180_REG_STATUS1);
|
2009-09-22 13:05:42 +04:00
|
|
|
|
|
|
|
if (status1 < 0)
|
|
|
|
return status1;
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
*status = adv7180_status_to_v4l2(status1);
|
|
|
|
if (std)
|
|
|
|
*std = adv7180_std_to_v4l2(status1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
static inline struct adv7180_state *to_state(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
return container_of(sd, struct adv7180_state, sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
|
|
|
|
{
|
2009-09-22 13:06:34 +04:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
2009-09-22 13:07:06 +04:00
|
|
|
int err = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2009-09-22 13:06:34 +04:00
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
if (state->streaming) {
|
|
|
|
err = -EBUSY;
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = adv7180_set_video_standard(state,
|
|
|
|
ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM);
|
|
|
|
if (err)
|
|
|
|
goto unlock;
|
2009-09-22 13:06:34 +04:00
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
msleep(100);
|
|
|
|
__adv7180_status(state, NULL, std);
|
|
|
|
|
|
|
|
err = v4l2_std_to_adv7180(state->curr_norm);
|
|
|
|
if (err < 0)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
err = adv7180_set_video_standard(state, err);
|
|
|
|
|
|
|
|
unlock:
|
2009-09-22 13:07:06 +04:00
|
|
|
mutex_unlock(&state->mutex);
|
2009-09-22 13:06:34 +04:00
|
|
|
return err;
|
2009-09-22 13:05:42 +04:00
|
|
|
}
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2012-04-12 19:39:36 +04:00
|
|
|
static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input,
|
|
|
|
u32 output, u32 config)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
if (input > 31 || !(BIT(input) & state->chip_info->valid_input_mask)) {
|
|
|
|
ret = -EINVAL;
|
2012-04-12 19:39:36 +04:00
|
|
|
goto out;
|
2015-01-23 18:52:28 +03:00
|
|
|
}
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
ret = state->chip_info->select_input(state, input);
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
if (ret == 0)
|
|
|
|
state->input = input;
|
2012-04-12 19:39:36 +04:00
|
|
|
out:
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:05:42 +04:00
|
|
|
static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
|
|
|
|
{
|
2009-09-22 13:07:06 +04:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = __adv7180_status(state, status, NULL);
|
2009-09-22 13:07:06 +04:00
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
2009-09-19 04:17:20 +04:00
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:27 +03:00
|
|
|
static int adv7180_program_std(struct adv7180_state *state)
|
2009-09-22 13:06:34 +04:00
|
|
|
{
|
2015-01-23 18:52:27 +03:00
|
|
|
int ret;
|
2009-09-22 13:06:34 +04:00
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
ret = v4l2_std_to_adv7180(state->curr_norm);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-01-23 18:52:27 +03:00
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
ret = adv7180_set_video_standard(state, ret);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-01-23 18:52:27 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
/* Make sure we can support this std */
|
|
|
|
ret = v4l2_std_to_adv7180(std);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-09-22 13:06:34 +04:00
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
state->curr_norm = std;
|
2015-01-23 18:52:27 +03:00
|
|
|
|
|
|
|
ret = adv7180_program_std(state);
|
2009-09-22 13:06:34 +04:00
|
|
|
out:
|
2009-09-22 13:07:06 +04:00
|
|
|
mutex_unlock(&state->mutex);
|
2009-09-22 13:06:34 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-02 20:42:18 +03:00
|
|
|
static int adv7180_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
|
|
|
*norm = state->curr_norm;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-26 13:27:16 +03:00
|
|
|
static int adv7180_g_frame_interval(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_frame_interval *fi)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
|
|
|
if (state->curr_norm & V4L2_STD_525_60) {
|
|
|
|
fi->interval.numerator = 1001;
|
|
|
|
fi->interval.denominator = 30000;
|
|
|
|
} else {
|
|
|
|
fi->interval.numerator = 1;
|
|
|
|
fi->interval.denominator = 25;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-20 03:03:32 +03:00
|
|
|
static void adv7180_set_power_pin(struct adv7180_state *state, bool on)
|
|
|
|
{
|
|
|
|
if (!state->pwdn_gpio)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
gpiod_set_value_cansleep(state->pwdn_gpio, 0);
|
|
|
|
usleep_range(5000, 10000);
|
|
|
|
} else {
|
|
|
|
gpiod_set_value_cansleep(state->pwdn_gpio, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 14:22:36 +03:00
|
|
|
static void adv7180_set_reset_pin(struct adv7180_state *state, bool on)
|
|
|
|
{
|
|
|
|
if (!state->rst_gpio)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
gpiod_set_value_cansleep(state->rst_gpio, 1);
|
|
|
|
} else {
|
|
|
|
gpiod_set_value_cansleep(state->rst_gpio, 0);
|
|
|
|
usleep_range(5000, 10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
static int adv7180_set_power(struct adv7180_state *state, bool on)
|
2014-03-10 21:05:39 +04:00
|
|
|
{
|
|
|
|
u8 val;
|
2015-01-23 18:52:31 +03:00
|
|
|
int ret;
|
2014-03-10 21:05:39 +04:00
|
|
|
|
|
|
|
if (on)
|
|
|
|
val = ADV7180_PWR_MAN_ON;
|
|
|
|
else
|
|
|
|
val = ADV7180_PWR_MAN_OFF;
|
|
|
|
|
2015-01-23 18:52:31 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_PWR_MAN, val);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
|
|
|
|
if (on) {
|
|
|
|
adv7180_csi_write(state, 0xDE, 0x02);
|
|
|
|
adv7180_csi_write(state, 0xD2, 0xF7);
|
|
|
|
adv7180_csi_write(state, 0xD8, 0x65);
|
|
|
|
adv7180_csi_write(state, 0xE0, 0x09);
|
|
|
|
adv7180_csi_write(state, 0x2C, 0x00);
|
2015-01-23 18:52:32 +03:00
|
|
|
if (state->field == V4L2_FIELD_NONE)
|
|
|
|
adv7180_csi_write(state, 0x1D, 0x80);
|
2015-01-23 18:52:31 +03:00
|
|
|
adv7180_csi_write(state, 0x00, 0x00);
|
|
|
|
} else {
|
|
|
|
adv7180_csi_write(state, 0x00, 0x80);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-03-10 21:05:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_s_power(struct v4l2_subdev *sd, int on)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_set_power(state, on);
|
2014-03-10 21:05:39 +04:00
|
|
|
if (ret == 0)
|
|
|
|
state->powered = on;
|
|
|
|
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-11 18:29:33 +04:00
|
|
|
static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
|
2012-04-12 19:39:36 +04:00
|
|
|
{
|
2012-07-11 18:29:33 +04:00
|
|
|
struct v4l2_subdev *sd = to_adv7180_sd(ctrl);
|
2012-04-12 19:39:36 +04:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
2012-07-11 18:29:33 +04:00
|
|
|
int val;
|
|
|
|
|
2012-04-12 19:39:36 +04:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-07-11 18:29:33 +04:00
|
|
|
val = ctrl->val;
|
2012-04-12 19:39:36 +04:00
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_BRIGHTNESS:
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_BRI, val);
|
2012-04-12 19:39:36 +04:00
|
|
|
break;
|
|
|
|
case V4L2_CID_HUE:
|
|
|
|
/*Hue is inverted according to HSL chart */
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_HUE, -val);
|
2012-04-12 19:39:36 +04:00
|
|
|
break;
|
|
|
|
case V4L2_CID_CONTRAST:
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_CON, val);
|
2012-04-12 19:39:36 +04:00
|
|
|
break;
|
|
|
|
case V4L2_CID_SATURATION:
|
|
|
|
/*
|
|
|
|
*This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE
|
|
|
|
*Let's not confuse the user, everybody understands saturation
|
|
|
|
*/
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_SD_SAT_CB, val);
|
2012-04-12 19:39:36 +04:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_SD_SAT_CR, val);
|
2012-04-12 19:39:36 +04:00
|
|
|
break;
|
2015-01-23 18:52:33 +03:00
|
|
|
case V4L2_CID_ADV_FAST_SWITCH:
|
|
|
|
if (ctrl->val) {
|
|
|
|
/* ADI required write */
|
|
|
|
adv7180_write(state, 0x80d9, 0x44);
|
|
|
|
adv7180_write(state, ADV7180_REG_FLCONTROL,
|
|
|
|
ADV7180_FLCONTROL_FL_ENABLE);
|
|
|
|
} else {
|
|
|
|
/* ADI required write */
|
|
|
|
adv7180_write(state, 0x80d9, 0xc4);
|
|
|
|
adv7180_write(state, ADV7180_REG_FLCONTROL, 0x00);
|
|
|
|
}
|
|
|
|
break;
|
2012-04-12 19:39:36 +04:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-11 18:29:33 +04:00
|
|
|
static const struct v4l2_ctrl_ops adv7180_ctrl_ops = {
|
|
|
|
.s_ctrl = adv7180_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:33 +03:00
|
|
|
static const struct v4l2_ctrl_config adv7180_ctrl_fast_switch = {
|
|
|
|
.ops = &adv7180_ctrl_ops,
|
|
|
|
.id = V4L2_CID_ADV_FAST_SWITCH,
|
|
|
|
.name = "Fast Switching",
|
|
|
|
.type = V4L2_CTRL_TYPE_BOOLEAN,
|
|
|
|
.min = 0,
|
|
|
|
.max = 1,
|
|
|
|
.step = 1,
|
|
|
|
};
|
|
|
|
|
2012-07-11 18:29:33 +04:00
|
|
|
static int adv7180_init_controls(struct adv7180_state *state)
|
|
|
|
{
|
|
|
|
v4l2_ctrl_handler_init(&state->ctrl_hdl, 4);
|
|
|
|
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_BRIGHTNESS, ADV7180_BRI_MIN,
|
|
|
|
ADV7180_BRI_MAX, 1, ADV7180_BRI_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_CONTRAST, ADV7180_CON_MIN,
|
|
|
|
ADV7180_CON_MAX, 1, ADV7180_CON_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_SATURATION, ADV7180_SAT_MIN,
|
|
|
|
ADV7180_SAT_MAX, 1, ADV7180_SAT_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_HUE, ADV7180_HUE_MIN,
|
|
|
|
ADV7180_HUE_MAX, 1, ADV7180_HUE_DEF);
|
2015-01-23 18:52:33 +03:00
|
|
|
v4l2_ctrl_new_custom(&state->ctrl_hdl, &adv7180_ctrl_fast_switch, NULL);
|
|
|
|
|
2012-07-11 18:29:33 +04:00
|
|
|
state->sd.ctrl_handler = &state->ctrl_hdl;
|
|
|
|
if (state->ctrl_hdl.error) {
|
|
|
|
int err = state->ctrl_hdl.error;
|
|
|
|
|
|
|
|
v4l2_ctrl_handler_free(&state->ctrl_hdl);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
v4l2_ctrl_handler_setup(&state->ctrl_hdl);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static void adv7180_exit_controls(struct adv7180_state *state)
|
|
|
|
{
|
|
|
|
v4l2_ctrl_handler_free(&state->ctrl_hdl);
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:26 +03:00
|
|
|
static int adv7180_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-01-23 18:52:26 +03:00
|
|
|
struct v4l2_subdev_mbus_code_enum *code)
|
2013-05-29 21:50:57 +04:00
|
|
|
{
|
2015-01-23 18:52:26 +03:00
|
|
|
if (code->index != 0)
|
2013-05-29 21:50:57 +04:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-09-02 18:37:06 +03:00
|
|
|
code->code = MEDIA_BUS_FMT_UYVY8_2X8;
|
2013-05-29 21:50:57 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_mbus_fmt(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_mbus_framefmt *fmt)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
2016-09-02 18:37:06 +03:00
|
|
|
fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
|
2013-05-29 21:50:57 +04:00
|
|
|
fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
fmt->width = 720;
|
|
|
|
fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
|
|
|
|
|
2018-07-26 13:27:15 +03:00
|
|
|
if (state->field == V4L2_FIELD_ALTERNATE)
|
|
|
|
fmt->height /= 2;
|
|
|
|
|
2013-05-29 21:50:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
static int adv7180_set_field_mode(struct adv7180_state *state)
|
|
|
|
{
|
|
|
|
if (!(state->chip_info->flags & ADV7180_FLAG_I2P))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (state->field == V4L2_FIELD_NONE) {
|
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
|
|
|
|
adv7180_csi_write(state, 0x01, 0x20);
|
|
|
|
adv7180_csi_write(state, 0x02, 0x28);
|
|
|
|
adv7180_csi_write(state, 0x03, 0x38);
|
|
|
|
adv7180_csi_write(state, 0x04, 0x30);
|
|
|
|
adv7180_csi_write(state, 0x05, 0x30);
|
|
|
|
adv7180_csi_write(state, 0x06, 0x80);
|
|
|
|
adv7180_csi_write(state, 0x07, 0x70);
|
|
|
|
adv7180_csi_write(state, 0x08, 0x50);
|
|
|
|
}
|
|
|
|
adv7180_vpp_write(state, 0xa3, 0x00);
|
|
|
|
adv7180_vpp_write(state, 0x5b, 0x00);
|
|
|
|
adv7180_vpp_write(state, 0x55, 0x80);
|
|
|
|
} else {
|
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
|
|
|
|
adv7180_csi_write(state, 0x01, 0x18);
|
|
|
|
adv7180_csi_write(state, 0x02, 0x18);
|
|
|
|
adv7180_csi_write(state, 0x03, 0x30);
|
|
|
|
adv7180_csi_write(state, 0x04, 0x20);
|
|
|
|
adv7180_csi_write(state, 0x05, 0x28);
|
|
|
|
adv7180_csi_write(state, 0x06, 0x40);
|
|
|
|
adv7180_csi_write(state, 0x07, 0x58);
|
|
|
|
adv7180_csi_write(state, 0x08, 0x30);
|
|
|
|
}
|
|
|
|
adv7180_vpp_write(state, 0xa3, 0x70);
|
|
|
|
adv7180_vpp_write(state, 0x5b, 0x80);
|
|
|
|
adv7180_vpp_write(state, 0x55, 0x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:26 +03:00
|
|
|
static int adv7180_get_pad_format(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-01-23 18:52:26 +03:00
|
|
|
struct v4l2_subdev_format *format)
|
|
|
|
{
|
2015-01-23 18:52:32 +03:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
|
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
|
|
|
format->format = *v4l2_subdev_get_try_format(sd, sd_state, 0);
|
2015-01-23 18:52:32 +03:00
|
|
|
} else {
|
|
|
|
adv7180_mbus_fmt(sd, &format->format);
|
|
|
|
format->format.field = state->field;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-01-23 18:52:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_set_pad_format(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-01-23 18:52:26 +03:00
|
|
|
struct v4l2_subdev_format *format)
|
|
|
|
{
|
2015-01-23 18:52:32 +03:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
struct v4l2_mbus_framefmt *framefmt;
|
2016-09-02 19:44:56 +03:00
|
|
|
int ret;
|
2015-01-23 18:52:32 +03:00
|
|
|
|
|
|
|
switch (format->format.field) {
|
|
|
|
case V4L2_FIELD_NONE:
|
2018-07-26 13:27:15 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_I2P)
|
|
|
|
break;
|
2020-07-25 01:10:14 +03:00
|
|
|
fallthrough;
|
2015-01-23 18:52:32 +03:00
|
|
|
default:
|
2018-07-26 13:27:15 +03:00
|
|
|
format->format.field = V4L2_FIELD_ALTERNATE;
|
2015-01-23 18:52:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-02 19:44:56 +03:00
|
|
|
ret = adv7180_mbus_fmt(sd, &format->format);
|
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
|
|
|
|
if (state->field != format->format.field) {
|
|
|
|
state->field = format->format.field;
|
|
|
|
adv7180_set_power(state, false);
|
|
|
|
adv7180_set_field_mode(state);
|
|
|
|
adv7180_set_power(state, true);
|
|
|
|
}
|
|
|
|
} else {
|
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
|
|
|
framefmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
|
2015-01-23 18:52:32 +03:00
|
|
|
*framefmt = format->format;
|
|
|
|
}
|
|
|
|
|
2016-09-02 19:44:56 +03:00
|
|
|
return ret;
|
2015-01-23 18:52:26 +03:00
|
|
|
}
|
|
|
|
|
2020-01-15 22:27:19 +03:00
|
|
|
static int adv7180_init_cfg(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)
|
2020-01-15 22:27:19 +03: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 17:55:58 +03:00
|
|
|
.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY
|
|
|
|
: V4L2_SUBDEV_FORMAT_ACTIVE,
|
2020-01-15 22:27:19 +03:00
|
|
|
};
|
|
|
|
|
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
|
|
|
return adv7180_set_pad_format(sd, sd_state, &fmt);
|
2020-01-15 22:27:19 +03:00
|
|
|
}
|
|
|
|
|
2020-07-17 17:53:16 +03:00
|
|
|
static int adv7180_get_mbus_config(struct v4l2_subdev *sd,
|
|
|
|
unsigned int pad,
|
|
|
|
struct v4l2_mbus_config *cfg)
|
2013-05-29 21:50:57 +04:00
|
|
|
{
|
2015-01-23 18:52:31 +03:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
|
2018-07-04 00:19:27 +03:00
|
|
|
cfg->type = V4L2_MBUS_CSI2_DPHY;
|
2015-01-23 18:52:31 +03:00
|
|
|
cfg->flags = V4L2_MBUS_CSI2_1_LANE |
|
|
|
|
V4L2_MBUS_CSI2_CHANNEL_0 |
|
|
|
|
V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The ADV7180 sensor supports BT.601/656 output modes.
|
|
|
|
* The BT.656 is default and not yet configurable by s/w.
|
|
|
|
*/
|
|
|
|
cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
|
|
|
|
V4L2_MBUS_DATA_ACTIVE_HIGH;
|
|
|
|
cfg->type = V4L2_MBUS_BT656;
|
|
|
|
}
|
2013-05-29 21:50:57 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-24 23:25:51 +03:00
|
|
|
static int adv7180_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
|
|
|
|
{
|
|
|
|
*frames = ADV7180_NUM_OF_SKIP_FRAMES;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:08:01 +03:00
|
|
|
static int adv7180_g_pixelaspect(struct v4l2_subdev *sd, struct v4l2_fract *aspect)
|
2016-04-02 20:42:19 +03:00
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
|
|
|
if (state->curr_norm & V4L2_STD_525_60) {
|
2016-07-04 11:08:01 +03:00
|
|
|
aspect->numerator = 11;
|
|
|
|
aspect->denominator = 10;
|
2016-04-02 20:42:19 +03:00
|
|
|
} else {
|
2016-07-04 11:08:01 +03:00
|
|
|
aspect->numerator = 54;
|
|
|
|
aspect->denominator = 59;
|
2016-04-02 20:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-02 20:42:20 +03:00
|
|
|
static int adv7180_g_tvnorms(struct v4l2_subdev *sd, v4l2_std_id *norm)
|
|
|
|
{
|
|
|
|
*norm = V4L2_STD_ALL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
static int adv7180_s_stream(struct v4l2_subdev *sd, int enable)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* It's always safe to stop streaming, no need to take the lock */
|
|
|
|
if (!enable) {
|
|
|
|
state->streaming = enable;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must wait until querystd released the lock */
|
|
|
|
ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
state->streaming = enable;
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_subscribe_event(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_fh *fh,
|
|
|
|
struct v4l2_event_subscription *sub)
|
|
|
|
{
|
|
|
|
switch (sub->type) {
|
|
|
|
case V4L2_EVENT_SOURCE_CHANGE:
|
|
|
|
return v4l2_src_change_event_subdev_subscribe(sd, fh, sub);
|
|
|
|
case V4L2_EVENT_CTRL:
|
|
|
|
return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
static const struct v4l2_subdev_video_ops adv7180_video_ops = {
|
2014-04-28 23:53:01 +04:00
|
|
|
.s_std = adv7180_s_std,
|
2016-04-02 20:42:18 +03:00
|
|
|
.g_std = adv7180_g_std,
|
2018-07-26 13:27:16 +03:00
|
|
|
.g_frame_interval = adv7180_g_frame_interval,
|
2009-09-19 04:17:20 +04:00
|
|
|
.querystd = adv7180_querystd,
|
2009-09-22 13:05:42 +04:00
|
|
|
.g_input_status = adv7180_g_input_status,
|
2012-04-12 19:39:36 +04:00
|
|
|
.s_routing = adv7180_s_routing,
|
2016-07-04 11:08:01 +03:00
|
|
|
.g_pixelaspect = adv7180_g_pixelaspect,
|
2016-04-02 20:42:20 +03:00
|
|
|
.g_tvnorms = adv7180_g_tvnorms,
|
2016-04-22 16:03:37 +03:00
|
|
|
.s_stream = adv7180_s_stream,
|
2009-09-19 04:17:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_subdev_core_ops adv7180_core_ops = {
|
2014-03-10 21:05:39 +04:00
|
|
|
.s_power = adv7180_s_power,
|
2016-04-22 16:03:37 +03:00
|
|
|
.subscribe_event = adv7180_subscribe_event,
|
|
|
|
.unsubscribe_event = v4l2_event_subdev_unsubscribe,
|
2009-09-19 04:17:20 +04:00
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:26 +03:00
|
|
|
static const struct v4l2_subdev_pad_ops adv7180_pad_ops = {
|
2020-01-15 22:27:19 +03:00
|
|
|
.init_cfg = adv7180_init_cfg,
|
2015-01-23 18:52:26 +03:00
|
|
|
.enum_mbus_code = adv7180_enum_mbus_code,
|
|
|
|
.set_fmt = adv7180_set_pad_format,
|
|
|
|
.get_fmt = adv7180_get_pad_format,
|
2020-07-17 17:53:16 +03:00
|
|
|
.get_mbus_config = adv7180_get_mbus_config,
|
2015-01-23 18:52:26 +03:00
|
|
|
};
|
|
|
|
|
2018-10-24 23:25:51 +03:00
|
|
|
static const struct v4l2_subdev_sensor_ops adv7180_sensor_ops = {
|
|
|
|
.g_skip_frames = adv7180_get_skip_frames,
|
|
|
|
};
|
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
static const struct v4l2_subdev_ops adv7180_ops = {
|
|
|
|
.core = &adv7180_core_ops,
|
|
|
|
.video = &adv7180_video_ops,
|
2015-01-23 18:52:26 +03:00
|
|
|
.pad = &adv7180_pad_ops,
|
2018-10-24 23:25:51 +03:00
|
|
|
.sensor = &adv7180_sensor_ops,
|
2009-09-19 04:17:20 +04:00
|
|
|
};
|
|
|
|
|
2014-03-07 20:14:31 +04:00
|
|
|
static irqreturn_t adv7180_irq(int irq, void *devid)
|
2009-09-22 13:07:06 +04:00
|
|
|
{
|
2014-03-07 20:14:31 +04:00
|
|
|
struct adv7180_state *state = devid;
|
2009-09-22 13:07:06 +04:00
|
|
|
u8 isr3;
|
|
|
|
|
|
|
|
mutex_lock(&state->mutex);
|
2015-01-23 18:52:24 +03:00
|
|
|
isr3 = adv7180_read(state, ADV7180_REG_ISR3);
|
2009-09-22 13:07:06 +04:00
|
|
|
/* clear */
|
2015-01-23 18:52:24 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_ICR3, isr3);
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2016-04-22 16:03:37 +03:00
|
|
|
if (isr3 & ADV7180_IRQ3_AD_CHANGE) {
|
|
|
|
static const struct v4l2_event src_ch = {
|
|
|
|
.type = V4L2_EVENT_SOURCE_CHANGE,
|
|
|
|
.u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
|
|
|
|
};
|
|
|
|
|
|
|
|
v4l2_subdev_notify_event(&state->sd, &src_ch);
|
|
|
|
}
|
2009-09-22 13:07:06 +04:00
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
static int adv7180_init(struct adv7180_state *state)
|
2009-09-19 04:17:20 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-09-22 13:07:06 +04:00
|
|
|
/* ITU-R BT.656-4 compatible */
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
|
2012-04-12 19:39:36 +04:00
|
|
|
ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);
|
2009-09-22 13:07:06 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ret;
|
2012-04-12 19:39:36 +04:00
|
|
|
|
|
|
|
/* Manually set V bit end position in NTSC mode */
|
2015-01-23 18:52:28 +03:00
|
|
|
return adv7180_write(state, ADV7180_REG_NTSC_V_BIT_END,
|
2012-04-12 19:39:36 +04:00
|
|
|
ADV7180_NTSC_V_BIT_END_MANUAL_NVEND);
|
2015-01-23 18:52:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_set_std(struct adv7180_state *state, unsigned int std)
|
|
|
|
{
|
|
|
|
return adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
|
|
|
|
(std << 4) | state->input);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_select_input(struct adv7180_state *state, unsigned int input)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = adv7180_read(state, ADV7180_REG_INPUT_CONTROL);
|
2012-04-12 19:39:36 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:28 +03:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK;
|
|
|
|
ret |= input;
|
|
|
|
return adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ret);
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
static int adv7182_init(struct adv7180_state *state)
|
|
|
|
{
|
2015-01-23 18:52:31 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
|
|
|
|
adv7180_write(state, ADV7180_REG_CSI_SLAVE_ADDR,
|
|
|
|
ADV7180_DEFAULT_CSI_I2C_ADDR << 1);
|
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_I2P)
|
|
|
|
adv7180_write(state, ADV7180_REG_VPP_SLAVE_ADDR,
|
|
|
|
ADV7180_DEFAULT_VPP_I2C_ADDR << 1);
|
|
|
|
|
2015-01-23 18:52:30 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_V2) {
|
|
|
|
/* ADI recommended writes for improved video quality */
|
|
|
|
adv7180_write(state, 0x0080, 0x51);
|
|
|
|
adv7180_write(state, 0x0081, 0x51);
|
|
|
|
adv7180_write(state, 0x0082, 0x68);
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
/* ADI required writes */
|
2015-01-23 18:52:31 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_OUTPUT_CONTROL, 0x4e);
|
|
|
|
adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL, 0x57);
|
|
|
|
adv7180_write(state, ADV7180_REG_CTRL_2, 0xc0);
|
2015-01-23 18:52:31 +03:00
|
|
|
} else {
|
2021-06-05 00:22:17 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_V2) {
|
|
|
|
if (state->force_bt656_4) {
|
|
|
|
/* ITU-R BT.656-4 compatible */
|
|
|
|
adv7180_write(state,
|
|
|
|
ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
|
|
|
|
ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);
|
|
|
|
/* Manually set NEWAVMODE */
|
|
|
|
adv7180_write(state,
|
|
|
|
ADV7180_REG_VSYNC_FIELD_CTL_1,
|
|
|
|
ADV7180_VSYNC_FIELD_CTL_1_NEWAV);
|
|
|
|
/* Manually set V bit end position in NTSC mode */
|
|
|
|
adv7180_write(state,
|
|
|
|
ADV7180_REG_NTSC_V_BIT_END,
|
|
|
|
ADV7180_NTSC_V_BIT_END_MANUAL_NVEND);
|
|
|
|
} else {
|
|
|
|
adv7180_write(state,
|
|
|
|
ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
|
|
|
|
0x17);
|
|
|
|
}
|
|
|
|
}
|
2015-01-23 18:52:31 +03:00
|
|
|
else
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state,
|
|
|
|
ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
|
|
|
|
0x07);
|
|
|
|
adv7180_write(state, ADV7180_REG_OUTPUT_CONTROL, 0x0c);
|
|
|
|
adv7180_write(state, ADV7180_REG_CTRL_2, 0x40);
|
2015-01-23 18:52:31 +03:00
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
adv7180_write(state, 0x0013, 0x00);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7182_set_std(struct adv7180_state *state, unsigned int std)
|
|
|
|
{
|
|
|
|
return adv7180_write(state, ADV7182_REG_INPUT_VIDSEL, std << 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum adv7182_input_type {
|
|
|
|
ADV7182_INPUT_TYPE_CVBS,
|
|
|
|
ADV7182_INPUT_TYPE_DIFF_CVBS,
|
|
|
|
ADV7182_INPUT_TYPE_SVIDEO,
|
|
|
|
ADV7182_INPUT_TYPE_YPBPR,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum adv7182_input_type adv7182_get_input_type(unsigned int input)
|
|
|
|
{
|
|
|
|
switch (input) {
|
|
|
|
case ADV7182_INPUT_CVBS_AIN1:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN2:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN3:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN4:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN5:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN6:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN7:
|
|
|
|
case ADV7182_INPUT_CVBS_AIN8:
|
|
|
|
return ADV7182_INPUT_TYPE_CVBS;
|
|
|
|
case ADV7182_INPUT_SVIDEO_AIN1_AIN2:
|
|
|
|
case ADV7182_INPUT_SVIDEO_AIN3_AIN4:
|
|
|
|
case ADV7182_INPUT_SVIDEO_AIN5_AIN6:
|
|
|
|
case ADV7182_INPUT_SVIDEO_AIN7_AIN8:
|
|
|
|
return ADV7182_INPUT_TYPE_SVIDEO;
|
|
|
|
case ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3:
|
|
|
|
case ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6:
|
|
|
|
return ADV7182_INPUT_TYPE_YPBPR;
|
|
|
|
case ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2:
|
|
|
|
case ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4:
|
|
|
|
case ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6:
|
|
|
|
case ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8:
|
|
|
|
return ADV7182_INPUT_TYPE_DIFF_CVBS;
|
|
|
|
default: /* Will never happen */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ADI recommended writes to registers 0x52, 0x53, 0x54 */
|
|
|
|
static unsigned int adv7182_lbias_settings[][3] = {
|
|
|
|
[ADV7182_INPUT_TYPE_CVBS] = { 0xCB, 0x4E, 0x80 },
|
|
|
|
[ADV7182_INPUT_TYPE_DIFF_CVBS] = { 0xC0, 0x4E, 0x80 },
|
|
|
|
[ADV7182_INPUT_TYPE_SVIDEO] = { 0x0B, 0xCE, 0x80 },
|
|
|
|
[ADV7182_INPUT_TYPE_YPBPR] = { 0x0B, 0x4E, 0xC0 },
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:30 +03:00
|
|
|
static unsigned int adv7280_lbias_settings[][3] = {
|
|
|
|
[ADV7182_INPUT_TYPE_CVBS] = { 0xCD, 0x4E, 0x80 },
|
|
|
|
[ADV7182_INPUT_TYPE_DIFF_CVBS] = { 0xC0, 0x4E, 0x80 },
|
|
|
|
[ADV7182_INPUT_TYPE_SVIDEO] = { 0x0B, 0xCE, 0x80 },
|
|
|
|
[ADV7182_INPUT_TYPE_YPBPR] = { 0x0B, 0x4E, 0xC0 },
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
static int adv7182_select_input(struct adv7180_state *state, unsigned int input)
|
|
|
|
{
|
|
|
|
enum adv7182_input_type input_type;
|
|
|
|
unsigned int *lbias;
|
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, input);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Reset clamp circuitry - ADI recommended writes */
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_RST_CLAMP, 0x00);
|
|
|
|
adv7180_write(state, ADV7180_REG_RST_CLAMP, 0xff);
|
2015-01-23 18:52:29 +03:00
|
|
|
|
|
|
|
input_type = adv7182_get_input_type(input);
|
|
|
|
|
|
|
|
switch (input_type) {
|
|
|
|
case ADV7182_INPUT_TYPE_CVBS:
|
|
|
|
case ADV7182_INPUT_TYPE_DIFF_CVBS:
|
|
|
|
/* ADI recommends to use the SH1 filter */
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_SHAP_FILTER_CTL_1, 0x41);
|
2015-01-23 18:52:29 +03:00
|
|
|
break;
|
|
|
|
default:
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_SHAP_FILTER_CTL_1, 0x01);
|
2015-01-23 18:52:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:30 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_V2)
|
|
|
|
lbias = adv7280_lbias_settings[input_type];
|
|
|
|
else
|
|
|
|
lbias = adv7182_lbias_settings[input_type];
|
2015-01-23 18:52:29 +03:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(adv7182_lbias_settings[0]); i++)
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_CVBS_TRIM + i, lbias[i]);
|
2015-01-23 18:52:29 +03:00
|
|
|
|
|
|
|
if (input_type == ADV7182_INPUT_TYPE_DIFF_CVBS) {
|
|
|
|
/* ADI required writes to make differential CVBS work */
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_RES_CIR, 0xa8);
|
|
|
|
adv7180_write(state, ADV7180_REG_CLAMP_ADJ, 0x90);
|
|
|
|
adv7180_write(state, ADV7180_REG_DIFF_MODE, 0xb0);
|
|
|
|
adv7180_write(state, ADV7180_REG_AGC_ADJ1, 0x08);
|
|
|
|
adv7180_write(state, ADV7180_REG_AGC_ADJ2, 0xa0);
|
2015-01-23 18:52:29 +03:00
|
|
|
} else {
|
2016-07-20 03:03:30 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_RES_CIR, 0xf0);
|
|
|
|
adv7180_write(state, ADV7180_REG_CLAMP_ADJ, 0xd0);
|
|
|
|
adv7180_write(state, ADV7180_REG_DIFF_MODE, 0x10);
|
|
|
|
adv7180_write(state, ADV7180_REG_AGC_ADJ1, 0x9c);
|
|
|
|
adv7180_write(state, ADV7180_REG_AGC_ADJ2, 0x00);
|
2015-01-23 18:52:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
static const struct adv7180_chip_info adv7180_info = {
|
|
|
|
.flags = ADV7180_FLAG_RESET_POWERED,
|
|
|
|
/* We cannot discriminate between LQFP and 40-pin LFCSP, so accept
|
|
|
|
* all inputs and let the card driver take care of validation
|
|
|
|
*/
|
|
|
|
.valid_input_mask = BIT(ADV7180_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7180_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7180_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7180_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7180_INPUT_CVBS_AIN5) |
|
|
|
|
BIT(ADV7180_INPUT_CVBS_AIN6) |
|
|
|
|
BIT(ADV7180_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7180_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7180_INPUT_SVIDEO_AIN5_AIN6) |
|
|
|
|
BIT(ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3) |
|
|
|
|
BIT(ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6),
|
|
|
|
.init = adv7180_init,
|
|
|
|
.set_std = adv7180_set_std,
|
|
|
|
.select_input = adv7180_select_input,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:29 +03:00
|
|
|
static const struct adv7180_chip_info adv7182_info = {
|
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:30 +03:00
|
|
|
static const struct adv7180_chip_info adv7280_info = {
|
2015-01-23 18:52:32 +03:00
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_I2P,
|
2015-01-23 18:52:30 +03:00
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:31 +03:00
|
|
|
static const struct adv7180_chip_info adv7280_m_info = {
|
2015-01-23 18:52:32 +03:00
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2 | ADV7180_FLAG_I2P,
|
2015-01-23 18:52:31 +03:00
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN5) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN6) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN7) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:30 +03:00
|
|
|
static const struct adv7180_chip_info adv7281_info = {
|
2015-01-23 18:52:31 +03:00
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2,
|
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN7) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct adv7180_chip_info adv7281_m_info = {
|
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2,
|
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN7) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct adv7180_chip_info adv7281_ma_info = {
|
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2,
|
2015-01-23 18:52:30 +03:00
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
2015-01-23 18:52:31 +03:00
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN5) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN6) |
|
2015-01-23 18:52:30 +03:00
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN7) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
2015-01-23 18:52:31 +03:00
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6) |
|
2015-01-23 18:52:30 +03:00
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
|
2015-01-23 18:52:31 +03:00
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6) |
|
2015-01-23 18:52:30 +03:00
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
|
2015-01-23 18:52:31 +03:00
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6) |
|
2015-01-23 18:52:30 +03:00
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
static const struct adv7180_chip_info adv7282_info = {
|
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_I2P,
|
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN7) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct adv7180_chip_info adv7282_m_info = {
|
|
|
|
.flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2 | ADV7180_FLAG_I2P,
|
|
|
|
.valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN3) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN7) |
|
|
|
|
BIT(ADV7182_INPUT_CVBS_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) |
|
|
|
|
BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
|
|
|
|
.init = adv7182_init,
|
|
|
|
.set_std = adv7182_set_std,
|
|
|
|
.select_input = adv7182_select_input,
|
|
|
|
};
|
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
static int init_device(struct adv7180_state *state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&state->mutex);
|
|
|
|
|
2016-07-20 03:03:32 +03:00
|
|
|
adv7180_set_power_pin(state, true);
|
2021-05-31 14:22:36 +03:00
|
|
|
adv7180_set_reset_pin(state, false);
|
2016-07-20 03:03:32 +03:00
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
|
2015-11-10 16:39:00 +03:00
|
|
|
usleep_range(5000, 10000);
|
2015-01-23 18:52:28 +03:00
|
|
|
|
|
|
|
ret = state->chip_info->init(state);
|
|
|
|
if (ret)
|
2015-01-23 18:52:24 +03:00
|
|
|
goto out_unlock;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2015-01-23 18:52:28 +03:00
|
|
|
ret = adv7180_program_std(state);
|
|
|
|
if (ret)
|
|
|
|
goto out_unlock;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
adv7180_set_field_mode(state);
|
|
|
|
|
2009-09-22 13:07:06 +04:00
|
|
|
/* register for interrupts */
|
|
|
|
if (state->irq > 0) {
|
|
|
|
/* config the Interrupt pin to be active low */
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_ICONF1,
|
2012-04-12 19:39:36 +04:00
|
|
|
ADV7180_ICONF1_ACTIVE_LOW |
|
|
|
|
ADV7180_ICONF1_PSYNC_ONLY);
|
2009-09-22 13:07:06 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:24 +03:00
|
|
|
goto out_unlock;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR1, 0);
|
2009-09-22 13:07:06 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:24 +03:00
|
|
|
goto out_unlock;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR2, 0);
|
2009-09-22 13:07:06 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:24 +03:00
|
|
|
goto out_unlock;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
|
|
|
/* enable AD change interrupts interrupts */
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR3,
|
2012-04-12 19:39:36 +04:00
|
|
|
ADV7180_IRQ3_AD_CHANGE);
|
2009-09-22 13:07:06 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:24 +03:00
|
|
|
goto out_unlock;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR4, 0);
|
2009-09-22 13:07:06 +04:00
|
|
|
if (ret < 0)
|
2015-01-23 18:52:24 +03:00
|
|
|
goto out_unlock;
|
2009-09-19 04:17:20 +04:00
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&state->mutex);
|
2014-03-15 01:04:03 +04:00
|
|
|
|
|
|
|
return ret;
|
2012-04-12 19:39:36 +04:00
|
|
|
}
|
|
|
|
|
2012-12-22 01:17:53 +04:00
|
|
|
static int adv7180_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
2012-04-12 19:39:36 +04:00
|
|
|
{
|
2021-06-05 00:22:17 +03:00
|
|
|
struct device_node *np = client->dev.of_node;
|
2012-04-12 19:39:36 +04:00
|
|
|
struct adv7180_state *state;
|
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Check if the adapter supports the needed features */
|
|
|
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
|
|
|
return -EIO;
|
|
|
|
|
2013-05-02 15:29:43 +04:00
|
|
|
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
|
2014-12-16 19:49:07 +03:00
|
|
|
if (state == NULL)
|
|
|
|
return -ENOMEM;
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
state->client = client;
|
2018-07-26 13:27:15 +03:00
|
|
|
state->field = V4L2_FIELD_ALTERNATE;
|
2015-01-23 18:52:28 +03:00
|
|
|
state->chip_info = (struct adv7180_chip_info *)id->driver_data;
|
2015-01-23 18:52:24 +03:00
|
|
|
|
2016-07-20 03:03:32 +03:00
|
|
|
state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
|
|
|
|
GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(state->pwdn_gpio)) {
|
|
|
|
ret = PTR_ERR(state->pwdn_gpio);
|
|
|
|
v4l_err(client, "request for power pin failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-05-31 14:22:36 +03:00
|
|
|
state->rst_gpio = devm_gpiod_get_optional(&client->dev, "reset",
|
|
|
|
GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(state->rst_gpio)) {
|
|
|
|
ret = PTR_ERR(state->rst_gpio);
|
|
|
|
v4l_err(client, "request for reset pin failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-06-05 00:22:17 +03:00
|
|
|
if (of_property_read_bool(np, "adv,force-bt656-4"))
|
|
|
|
state->force_bt656_4 = true;
|
|
|
|
|
2015-01-23 18:52:31 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
|
2019-07-22 20:26:00 +03:00
|
|
|
state->csi_client = i2c_new_dummy_device(client->adapter,
|
2015-01-23 18:52:31 +03:00
|
|
|
ADV7180_DEFAULT_CSI_I2C_ADDR);
|
2019-07-22 20:26:00 +03:00
|
|
|
if (IS_ERR(state->csi_client))
|
|
|
|
return PTR_ERR(state->csi_client);
|
2015-01-23 18:52:31 +03:00
|
|
|
}
|
|
|
|
|
2015-01-23 18:52:32 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_I2P) {
|
2019-07-22 20:26:00 +03:00
|
|
|
state->vpp_client = i2c_new_dummy_device(client->adapter,
|
2015-01-23 18:52:32 +03:00
|
|
|
ADV7180_DEFAULT_VPP_I2C_ADDR);
|
2019-07-22 20:26:00 +03:00
|
|
|
if (IS_ERR(state->vpp_client)) {
|
|
|
|
ret = PTR_ERR(state->vpp_client);
|
2015-01-23 18:52:32 +03:00
|
|
|
goto err_unregister_csi_client;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:39:36 +04:00
|
|
|
state->irq = client->irq;
|
|
|
|
mutex_init(&state->mutex);
|
2016-04-22 16:03:37 +03:00
|
|
|
state->curr_norm = V4L2_STD_NTSC;
|
2015-01-23 18:52:28 +03:00
|
|
|
if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED)
|
|
|
|
state->powered = true;
|
|
|
|
else
|
|
|
|
state->powered = false;
|
2012-04-12 19:39:36 +04:00
|
|
|
state->input = 0;
|
|
|
|
sd = &state->sd;
|
|
|
|
v4l2_i2c_subdev_init(sd, client, &adv7180_ops);
|
2017-10-19 19:31:20 +03:00
|
|
|
sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2012-07-11 18:29:33 +04:00
|
|
|
ret = adv7180_init_controls(state);
|
|
|
|
if (ret)
|
2015-01-23 18:52:32 +03:00
|
|
|
goto err_unregister_vpp_client;
|
2015-01-23 18:52:26 +03:00
|
|
|
|
|
|
|
state->pad.flags = MEDIA_PAD_FL_SOURCE;
|
2018-06-18 12:09:45 +03:00
|
|
|
sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
|
2015-12-11 12:44:40 +03:00
|
|
|
ret = media_entity_pads_init(&sd->entity, 1, &state->pad);
|
2012-07-11 18:29:33 +04:00
|
|
|
if (ret)
|
|
|
|
goto err_free_ctrl;
|
2014-03-07 20:14:32 +04:00
|
|
|
|
2015-01-23 18:52:26 +03:00
|
|
|
ret = init_device(state);
|
|
|
|
if (ret)
|
|
|
|
goto err_media_entity_cleanup;
|
|
|
|
|
2015-01-23 18:52:20 +03:00
|
|
|
if (state->irq) {
|
|
|
|
ret = request_threaded_irq(client->irq, NULL, adv7180_irq,
|
2015-01-23 18:52:21 +03:00
|
|
|
IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
|
|
|
|
KBUILD_MODNAME, state);
|
2015-01-23 18:52:20 +03:00
|
|
|
if (ret)
|
2015-01-23 18:52:26 +03:00
|
|
|
goto err_media_entity_cleanup;
|
2015-01-23 18:52:20 +03:00
|
|
|
}
|
|
|
|
|
2014-03-07 20:14:32 +04:00
|
|
|
ret = v4l2_async_register_subdev(sd);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_irq;
|
|
|
|
|
2021-05-31 14:22:37 +03:00
|
|
|
mutex_lock(&state->mutex);
|
|
|
|
ret = adv7180_read(state, ADV7180_REG_IDENT);
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_v4l2_async_unregister;
|
|
|
|
|
|
|
|
v4l_info(client, "chip id 0x%x found @ 0x%02x (%s)\n",
|
|
|
|
ret, client->addr, client->adapter->name);
|
2019-10-11 13:49:19 +03:00
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
return 0;
|
2009-09-22 13:07:06 +04:00
|
|
|
|
2021-05-31 14:22:37 +03:00
|
|
|
err_v4l2_async_unregister:
|
|
|
|
v4l2_async_unregister_subdev(sd);
|
2014-03-07 20:14:32 +04:00
|
|
|
err_free_irq:
|
|
|
|
if (state->irq > 0)
|
|
|
|
free_irq(client->irq, state);
|
2015-01-23 18:52:26 +03:00
|
|
|
err_media_entity_cleanup:
|
|
|
|
media_entity_cleanup(&sd->entity);
|
2012-07-11 18:29:33 +04:00
|
|
|
err_free_ctrl:
|
|
|
|
adv7180_exit_controls(state);
|
2015-01-23 18:52:32 +03:00
|
|
|
err_unregister_vpp_client:
|
2017-10-31 17:21:48 +03:00
|
|
|
i2c_unregister_device(state->vpp_client);
|
2015-01-23 18:52:31 +03:00
|
|
|
err_unregister_csi_client:
|
2017-10-31 17:21:48 +03:00
|
|
|
i2c_unregister_device(state->csi_client);
|
2014-03-07 20:14:27 +04:00
|
|
|
mutex_destroy(&state->mutex);
|
2009-09-22 13:07:06 +04:00
|
|
|
return ret;
|
2009-09-19 04:17:20 +04:00
|
|
|
}
|
|
|
|
|
2012-12-22 01:17:53 +04:00
|
|
|
static int adv7180_remove(struct i2c_client *client)
|
2009-09-19 04:17:20 +04:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
2009-09-22 13:07:06 +04:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
2014-03-07 20:14:32 +04:00
|
|
|
v4l2_async_unregister_subdev(sd);
|
|
|
|
|
2014-03-07 20:14:31 +04:00
|
|
|
if (state->irq > 0)
|
2009-09-22 13:07:06 +04:00
|
|
|
free_irq(client->irq, state);
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2015-01-23 18:52:26 +03:00
|
|
|
media_entity_cleanup(&sd->entity);
|
2014-03-07 20:14:28 +04:00
|
|
|
adv7180_exit_controls(state);
|
2015-01-23 18:52:31 +03:00
|
|
|
|
2017-10-31 17:21:48 +03:00
|
|
|
i2c_unregister_device(state->vpp_client);
|
|
|
|
i2c_unregister_device(state->csi_client);
|
2015-01-23 18:52:31 +03:00
|
|
|
|
2021-05-31 14:22:36 +03:00
|
|
|
adv7180_set_reset_pin(state, true);
|
2016-07-20 03:03:32 +03:00
|
|
|
adv7180_set_power_pin(state, false);
|
|
|
|
|
2014-03-07 20:14:27 +04:00
|
|
|
mutex_destroy(&state->mutex);
|
2015-01-23 18:52:31 +03:00
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id adv7180_id[] = {
|
2015-01-23 18:52:28 +03:00
|
|
|
{ "adv7180", (kernel_ulong_t)&adv7180_info },
|
2017-07-03 11:43:33 +03:00
|
|
|
{ "adv7180cp", (kernel_ulong_t)&adv7180_info },
|
|
|
|
{ "adv7180st", (kernel_ulong_t)&adv7180_info },
|
2015-01-23 18:52:29 +03:00
|
|
|
{ "adv7182", (kernel_ulong_t)&adv7182_info },
|
2015-01-23 18:52:30 +03:00
|
|
|
{ "adv7280", (kernel_ulong_t)&adv7280_info },
|
2015-01-23 18:52:31 +03:00
|
|
|
{ "adv7280-m", (kernel_ulong_t)&adv7280_m_info },
|
2015-01-23 18:52:30 +03:00
|
|
|
{ "adv7281", (kernel_ulong_t)&adv7281_info },
|
2015-01-23 18:52:31 +03:00
|
|
|
{ "adv7281-m", (kernel_ulong_t)&adv7281_m_info },
|
|
|
|
{ "adv7281-ma", (kernel_ulong_t)&adv7281_ma_info },
|
2015-01-23 18:52:32 +03:00
|
|
|
{ "adv7282", (kernel_ulong_t)&adv7282_info },
|
|
|
|
{ "adv7282-m", (kernel_ulong_t)&adv7282_m_info },
|
2009-09-19 04:17:20 +04:00
|
|
|
{},
|
|
|
|
};
|
2015-01-23 18:52:28 +03:00
|
|
|
MODULE_DEVICE_TABLE(i2c, adv7180_id);
|
2009-09-19 04:17:20 +04:00
|
|
|
|
2013-04-13 12:25:59 +04:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int adv7180_suspend(struct device *dev)
|
2012-04-12 19:39:36 +04:00
|
|
|
{
|
2020-09-21 19:23:27 +03:00
|
|
|
struct v4l2_subdev *sd = dev_get_drvdata(dev);
|
2014-03-10 21:05:39 +04:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
2012-04-12 19:39:36 +04:00
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
return adv7180_set_power(state, false);
|
2012-04-12 19:39:36 +04:00
|
|
|
}
|
|
|
|
|
2013-04-13 12:25:59 +04:00
|
|
|
static int adv7180_resume(struct device *dev)
|
2012-04-12 19:39:36 +04:00
|
|
|
{
|
2020-09-21 19:23:27 +03:00
|
|
|
struct v4l2_subdev *sd = dev_get_drvdata(dev);
|
2012-04-12 19:39:36 +04:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret;
|
|
|
|
|
2015-01-23 18:52:24 +03:00
|
|
|
ret = init_device(state);
|
2012-04-12 19:39:36 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-01-23 18:52:25 +03:00
|
|
|
|
|
|
|
ret = adv7180_set_power(state, state->powered);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2012-04-12 19:39:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-13 12:25:59 +04:00
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(adv7180_pm_ops, adv7180_suspend, adv7180_resume);
|
|
|
|
#define ADV7180_PM_OPS (&adv7180_pm_ops)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define ADV7180_PM_OPS NULL
|
2012-04-12 19:39:36 +04:00
|
|
|
#endif
|
|
|
|
|
2015-06-03 16:59:50 +03:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id adv7180_of_id[] = {
|
|
|
|
{ .compatible = "adi,adv7180", },
|
2017-05-19 16:07:02 +03:00
|
|
|
{ .compatible = "adi,adv7180cp", },
|
|
|
|
{ .compatible = "adi,adv7180st", },
|
2016-02-24 00:11:21 +03:00
|
|
|
{ .compatible = "adi,adv7182", },
|
|
|
|
{ .compatible = "adi,adv7280", },
|
|
|
|
{ .compatible = "adi,adv7280-m", },
|
|
|
|
{ .compatible = "adi,adv7281", },
|
|
|
|
{ .compatible = "adi,adv7281-m", },
|
|
|
|
{ .compatible = "adi,adv7281-ma", },
|
|
|
|
{ .compatible = "adi,adv7282", },
|
|
|
|
{ .compatible = "adi,adv7282-m", },
|
2015-06-03 16:59:50 +03:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, adv7180_of_id);
|
|
|
|
#endif
|
|
|
|
|
2009-09-19 04:17:20 +04:00
|
|
|
static struct i2c_driver adv7180_driver = {
|
|
|
|
.driver = {
|
2012-07-11 18:29:33 +04:00
|
|
|
.name = KBUILD_MODNAME,
|
2013-04-13 12:25:59 +04:00
|
|
|
.pm = ADV7180_PM_OPS,
|
2015-06-03 16:59:50 +03:00
|
|
|
.of_match_table = of_match_ptr(adv7180_of_id),
|
2012-04-12 19:39:36 +04:00
|
|
|
},
|
|
|
|
.probe = adv7180_probe,
|
2012-12-22 01:17:53 +04:00
|
|
|
.remove = adv7180_remove,
|
2012-04-12 19:39:36 +04:00
|
|
|
.id_table = adv7180_id,
|
2009-09-19 04:17:20 +04:00
|
|
|
};
|
|
|
|
|
2012-02-12 13:56:32 +04:00
|
|
|
module_i2c_driver(adv7180_driver);
|
2009-09-19 04:17:20 +04:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver");
|
|
|
|
MODULE_AUTHOR("Mocean Laboratories");
|
|
|
|
MODULE_LICENSE("GPL v2");
|