2019-06-04 01:11:33 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-10-05 07:52:45 -07:00
|
|
|
/*
|
2017-06-16 12:45:33 -07:00
|
|
|
* V4L2 subdevice driver for OmniVision OV6650 Camera Sensor
|
2010-10-05 07:52:45 -07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
|
|
|
|
*
|
|
|
|
* Based on OmniVision OV96xx Camera Driver
|
|
|
|
* Copyright (C) 2009 Marek Vasut <marek.vasut@gmail.com>
|
|
|
|
*
|
|
|
|
* Based on ov772x camera driver:
|
|
|
|
* Copyright (C) 2008 Renesas Solutions Corp.
|
|
|
|
* Kuninori Morimoto <morimoto.kuninori@renesas.com>
|
|
|
|
*
|
|
|
|
* Based on ov7670 and soc_camera_platform driver,
|
|
|
|
* Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
|
|
|
|
* Copyright (C) 2008 Magnus Damm
|
|
|
|
* Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
|
|
|
|
*
|
2019-02-18 12:28:58 -07:00
|
|
|
* Hardware specific bits initially based on former work by Matt Callow
|
2010-10-05 07:52:45 -07:00
|
|
|
* drivers/media/video/omap/sensor_ov6650.c
|
|
|
|
* Copyright (C) 2006 Matt Callow
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
2021-01-12 12:49:18 -07:00
|
|
|
#include <linux/clk.h>
|
2010-10-05 07:52:45 -07:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/slab.h>
|
2011-09-09 09:56:04 -07:00
|
|
|
#include <linux/v4l2-mediabus.h>
|
2011-07-03 11:03:12 -07:00
|
|
|
#include <linux/module.h>
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2011-09-12 05:52:01 -07:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2017-06-16 12:45:33 -07:00
|
|
|
#include <media/v4l2-device.h>
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
/* Register definitions */
|
|
|
|
#define REG_GAIN 0x00 /* range 00 - 3F */
|
|
|
|
#define REG_BLUE 0x01
|
|
|
|
#define REG_RED 0x02
|
|
|
|
#define REG_SAT 0x03 /* [7:4] saturation [0:3] reserved */
|
|
|
|
#define REG_HUE 0x04 /* [7:6] rsrvd [5] hue en [4:0] hue */
|
|
|
|
|
|
|
|
#define REG_BRT 0x06
|
|
|
|
|
|
|
|
#define REG_PIDH 0x0a
|
|
|
|
#define REG_PIDL 0x0b
|
|
|
|
|
|
|
|
#define REG_AECH 0x10
|
|
|
|
#define REG_CLKRC 0x11 /* Data Format and Internal Clock */
|
|
|
|
/* [7:6] Input system clock (MHz)*/
|
|
|
|
/* 00=8, 01=12, 10=16, 11=24 */
|
|
|
|
/* [5:0]: Internal Clock Pre-Scaler */
|
|
|
|
#define REG_COMA 0x12 /* [7] Reset */
|
|
|
|
#define REG_COMB 0x13
|
|
|
|
#define REG_COMC 0x14
|
|
|
|
#define REG_COMD 0x15
|
|
|
|
#define REG_COML 0x16
|
|
|
|
#define REG_HSTRT 0x17
|
|
|
|
#define REG_HSTOP 0x18
|
|
|
|
#define REG_VSTRT 0x19
|
|
|
|
#define REG_VSTOP 0x1a
|
|
|
|
#define REG_PSHFT 0x1b
|
|
|
|
#define REG_MIDH 0x1c
|
|
|
|
#define REG_MIDL 0x1d
|
|
|
|
#define REG_HSYNS 0x1e
|
|
|
|
#define REG_HSYNE 0x1f
|
|
|
|
#define REG_COME 0x20
|
|
|
|
#define REG_YOFF 0x21
|
|
|
|
#define REG_UOFF 0x22
|
|
|
|
#define REG_VOFF 0x23
|
|
|
|
#define REG_AEW 0x24
|
|
|
|
#define REG_AEB 0x25
|
|
|
|
#define REG_COMF 0x26
|
|
|
|
#define REG_COMG 0x27
|
|
|
|
#define REG_COMH 0x28
|
|
|
|
#define REG_COMI 0x29
|
|
|
|
|
|
|
|
#define REG_FRARL 0x2b
|
|
|
|
#define REG_COMJ 0x2c
|
|
|
|
#define REG_COMK 0x2d
|
|
|
|
#define REG_AVGY 0x2e
|
|
|
|
#define REG_REF0 0x2f
|
|
|
|
#define REG_REF1 0x30
|
|
|
|
#define REG_REF2 0x31
|
|
|
|
#define REG_FRAJH 0x32
|
|
|
|
#define REG_FRAJL 0x33
|
|
|
|
#define REG_FACT 0x34
|
|
|
|
#define REG_L1AEC 0x35
|
|
|
|
#define REG_AVGU 0x36
|
|
|
|
#define REG_AVGV 0x37
|
|
|
|
|
|
|
|
#define REG_SPCB 0x60
|
|
|
|
#define REG_SPCC 0x61
|
|
|
|
#define REG_GAM1 0x62
|
|
|
|
#define REG_GAM2 0x63
|
|
|
|
#define REG_GAM3 0x64
|
|
|
|
#define REG_SPCD 0x65
|
|
|
|
|
|
|
|
#define REG_SPCE 0x68
|
|
|
|
#define REG_ADCL 0x69
|
|
|
|
|
|
|
|
#define REG_RMCO 0x6c
|
|
|
|
#define REG_GMCO 0x6d
|
|
|
|
#define REG_BMCO 0x6e
|
|
|
|
|
|
|
|
|
|
|
|
/* Register bits, values, etc. */
|
|
|
|
#define OV6650_PIDH 0x66 /* high byte of product ID number */
|
|
|
|
#define OV6650_PIDL 0x50 /* low byte of product ID number */
|
|
|
|
#define OV6650_MIDH 0x7F /* high byte of mfg ID */
|
|
|
|
#define OV6650_MIDL 0xA2 /* low byte of mfg ID */
|
|
|
|
|
|
|
|
#define DEF_GAIN 0x00
|
|
|
|
#define DEF_BLUE 0x80
|
|
|
|
#define DEF_RED 0x80
|
|
|
|
|
|
|
|
#define SAT_SHIFT 4
|
|
|
|
#define SAT_MASK (0xf << SAT_SHIFT)
|
|
|
|
#define SET_SAT(x) (((x) << SAT_SHIFT) & SAT_MASK)
|
|
|
|
|
|
|
|
#define HUE_EN BIT(5)
|
|
|
|
#define HUE_MASK 0x1f
|
|
|
|
#define DEF_HUE 0x10
|
|
|
|
#define SET_HUE(x) (HUE_EN | ((x) & HUE_MASK))
|
|
|
|
|
|
|
|
#define DEF_AECH 0x4D
|
|
|
|
|
2019-10-13 05:50:50 -07:00
|
|
|
#define CLKRC_8MHz 0x00
|
2010-10-05 07:52:45 -07:00
|
|
|
#define CLKRC_12MHz 0x40
|
|
|
|
#define CLKRC_16MHz 0x80
|
|
|
|
#define CLKRC_24MHz 0xc0
|
|
|
|
#define CLKRC_DIV_MASK 0x3f
|
|
|
|
#define GET_CLKRC_DIV(x) (((x) & CLKRC_DIV_MASK) + 1)
|
2019-10-13 05:50:45 -07:00
|
|
|
#define DEF_CLKRC 0x00
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
#define COMA_RESET BIT(7)
|
|
|
|
#define COMA_QCIF BIT(5)
|
|
|
|
#define COMA_RAW_RGB BIT(4)
|
|
|
|
#define COMA_RGB BIT(3)
|
|
|
|
#define COMA_BW BIT(2)
|
|
|
|
#define COMA_WORD_SWAP BIT(1)
|
|
|
|
#define COMA_BYTE_SWAP BIT(0)
|
|
|
|
#define DEF_COMA 0x00
|
|
|
|
|
|
|
|
#define COMB_FLIP_V BIT(7)
|
|
|
|
#define COMB_FLIP_H BIT(5)
|
|
|
|
#define COMB_BAND_FILTER BIT(4)
|
|
|
|
#define COMB_AWB BIT(2)
|
|
|
|
#define COMB_AGC BIT(1)
|
|
|
|
#define COMB_AEC BIT(0)
|
|
|
|
#define DEF_COMB 0x5f
|
|
|
|
|
|
|
|
#define COML_ONE_CHANNEL BIT(7)
|
|
|
|
|
|
|
|
#define DEF_HSTRT 0x24
|
|
|
|
#define DEF_HSTOP 0xd4
|
|
|
|
#define DEF_VSTRT 0x04
|
|
|
|
#define DEF_VSTOP 0x94
|
|
|
|
|
|
|
|
#define COMF_HREF_LOW BIT(4)
|
|
|
|
|
|
|
|
#define COMJ_PCLK_RISING BIT(4)
|
|
|
|
#define COMJ_VSYNC_HIGH BIT(0)
|
|
|
|
|
|
|
|
/* supported resolutions */
|
|
|
|
#define W_QCIF (DEF_HSTOP - DEF_HSTRT)
|
|
|
|
#define W_CIF (W_QCIF << 1)
|
|
|
|
#define H_QCIF (DEF_VSTOP - DEF_VSTRT)
|
|
|
|
#define H_CIF (H_QCIF << 1)
|
|
|
|
|
|
|
|
#define FRAME_RATE_MAX 30
|
|
|
|
|
|
|
|
|
|
|
|
struct ov6650_reg {
|
|
|
|
u8 reg;
|
|
|
|
u8 val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ov6650 {
|
|
|
|
struct v4l2_subdev subdev;
|
2011-09-12 05:52:01 -07:00
|
|
|
struct v4l2_ctrl_handler hdl;
|
|
|
|
struct {
|
|
|
|
/* exposure/autoexposure cluster */
|
|
|
|
struct v4l2_ctrl *autoexposure;
|
|
|
|
struct v4l2_ctrl *exposure;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
/* gain/autogain cluster */
|
|
|
|
struct v4l2_ctrl *autogain;
|
|
|
|
struct v4l2_ctrl *gain;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
/* blue/red/autowhitebalance cluster */
|
|
|
|
struct v4l2_ctrl *autowb;
|
|
|
|
struct v4l2_ctrl *blue;
|
|
|
|
struct v4l2_ctrl *red;
|
|
|
|
};
|
2021-01-12 12:49:18 -07:00
|
|
|
struct clk *clk;
|
2010-10-05 07:52:45 -07:00
|
|
|
bool half_scale; /* scale down output by 2 */
|
|
|
|
struct v4l2_rect rect; /* sensor cropping window */
|
2023-12-13 08:00:04 -07:00
|
|
|
struct v4l2_fract tpf; /* as requested with set_frame_interval */
|
2014-11-10 10:28:29 -07:00
|
|
|
u32 code;
|
2010-10-05 07:52:45 -07:00
|
|
|
};
|
|
|
|
|
2019-10-13 05:50:50 -07:00
|
|
|
struct ov6650_xclk {
|
|
|
|
unsigned long rate;
|
|
|
|
u8 clkrc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ov6650_xclk ov6650_xclk[] = {
|
|
|
|
{
|
|
|
|
.rate = 8000000,
|
|
|
|
.clkrc = CLKRC_8MHz,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.rate = 12000000,
|
|
|
|
.clkrc = CLKRC_12MHz,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.rate = 16000000,
|
|
|
|
.clkrc = CLKRC_16MHz,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.rate = 24000000,
|
|
|
|
.clkrc = CLKRC_24MHz,
|
|
|
|
},
|
|
|
|
};
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2014-11-10 10:28:29 -07:00
|
|
|
static u32 ov6650_codes[] = {
|
|
|
|
MEDIA_BUS_FMT_YUYV8_2X8,
|
|
|
|
MEDIA_BUS_FMT_UYVY8_2X8,
|
|
|
|
MEDIA_BUS_FMT_YVYU8_2X8,
|
|
|
|
MEDIA_BUS_FMT_VYUY8_2X8,
|
|
|
|
MEDIA_BUS_FMT_SBGGR8_1X8,
|
|
|
|
MEDIA_BUS_FMT_Y8_1X8,
|
2010-10-05 07:52:45 -07:00
|
|
|
};
|
|
|
|
|
media: ov6650: Fix some format attributes not under control
User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values. The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support"). Fix it.
Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with resulting
pad config format code and frame size.
Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-09-03 13:11:40 -07:00
|
|
|
static const struct v4l2_mbus_framefmt ov6650_def_fmt = {
|
|
|
|
.width = W_CIF,
|
|
|
|
.height = H_CIF,
|
|
|
|
.code = MEDIA_BUS_FMT_SBGGR8_1X8,
|
|
|
|
.colorspace = V4L2_COLORSPACE_SRGB,
|
|
|
|
.field = V4L2_FIELD_NONE,
|
|
|
|
.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT,
|
|
|
|
.quantization = V4L2_QUANTIZATION_DEFAULT,
|
|
|
|
.xfer_func = V4L2_XFER_FUNC_DEFAULT,
|
|
|
|
};
|
|
|
|
|
2010-10-05 07:52:45 -07:00
|
|
|
/* read a register */
|
|
|
|
static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 data = reg;
|
|
|
|
struct i2c_msg msg = {
|
|
|
|
.addr = client->addr,
|
|
|
|
.flags = 0,
|
|
|
|
.len = 1,
|
|
|
|
.buf = &data,
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = i2c_transfer(client->adapter, &msg, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
msg.flags = I2C_M_RD;
|
|
|
|
ret = i2c_transfer(client->adapter, &msg, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
*val = data;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
dev_err(&client->dev, "Failed reading register 0x%02x!\n", reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write a register */
|
|
|
|
static int ov6650_reg_write(struct i2c_client *client, u8 reg, u8 val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned char data[2] = { reg, val };
|
|
|
|
struct i2c_msg msg = {
|
|
|
|
.addr = client->addr,
|
|
|
|
.flags = 0,
|
|
|
|
.len = 2,
|
|
|
|
.buf = data,
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = i2c_transfer(client->adapter, &msg, 1);
|
|
|
|
udelay(100);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "Failed writing register 0x%02x!\n", reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read a register, alter its bits, write it back */
|
|
|
|
static int ov6650_reg_rmw(struct i2c_client *client, u8 reg, u8 set, u8 mask)
|
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ov6650_reg_read(client, reg, &val);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&client->dev,
|
|
|
|
"[Read]-Modify-Write of register 0x%02x failed!\n",
|
|
|
|
reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
val &= ~mask;
|
|
|
|
val |= set;
|
|
|
|
|
|
|
|
ret = ov6650_reg_write(client, reg, val);
|
|
|
|
if (ret)
|
|
|
|
dev_err(&client->dev,
|
|
|
|
"Read-Modify-[Write] of register 0x%02x failed!\n",
|
|
|
|
reg);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ov6650 *to_ov6650(const struct i2c_client *client)
|
|
|
|
{
|
|
|
|
return container_of(i2c_get_clientdata(client), struct ov6650, subdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start/Stop streaming from the device */
|
|
|
|
static int ov6650_s_stream(struct v4l2_subdev *sd, int enable)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get status of additional camera capabilities */
|
2011-09-12 05:52:01 -07:00
|
|
|
static int ov6550_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
2011-09-12 05:52:01 -07:00
|
|
|
struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
|
|
|
|
struct v4l2_subdev *sd = &priv->subdev;
|
2010-10-05 07:52:45 -07:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
2011-09-12 05:52:01 -07:00
|
|
|
uint8_t reg, reg2;
|
2011-09-12 04:25:25 -07:00
|
|
|
int ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_AUTOGAIN:
|
2011-09-12 05:52:01 -07:00
|
|
|
ret = ov6650_reg_read(client, REG_GAIN, ®);
|
|
|
|
if (!ret)
|
|
|
|
priv->gain->val = reg;
|
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_AUTO_WHITE_BALANCE:
|
2011-09-12 05:52:01 -07:00
|
|
|
ret = ov6650_reg_read(client, REG_BLUE, ®);
|
|
|
|
if (!ret)
|
|
|
|
ret = ov6650_reg_read(client, REG_RED, ®2);
|
|
|
|
if (!ret) {
|
|
|
|
priv->blue->val = reg;
|
|
|
|
priv->red->val = reg2;
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
2011-09-12 05:52:01 -07:00
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_EXPOSURE_AUTO:
|
2011-09-12 05:52:01 -07:00
|
|
|
ret = ov6650_reg_read(client, REG_AECH, ®);
|
|
|
|
if (!ret)
|
|
|
|
priv->exposure->val = reg;
|
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
2011-09-12 05:52:01 -07:00
|
|
|
return -EINVAL;
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set status of additional camera capabilities */
|
2011-09-12 05:52:01 -07:00
|
|
|
static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
2011-09-12 05:52:01 -07:00
|
|
|
struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
|
|
|
|
struct v4l2_subdev *sd = &priv->subdev;
|
2010-10-05 07:52:45 -07:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
2011-09-12 04:25:25 -07:00
|
|
|
int ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_AUTOGAIN:
|
|
|
|
ret = ov6650_reg_rmw(client, REG_COMB,
|
2011-09-12 05:52:01 -07:00
|
|
|
ctrl->val ? COMB_AGC : 0, COMB_AGC);
|
|
|
|
if (!ret && !ctrl->val)
|
|
|
|
ret = ov6650_reg_write(client, REG_GAIN, priv->gain->val);
|
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_AUTO_WHITE_BALANCE:
|
|
|
|
ret = ov6650_reg_rmw(client, REG_COMB,
|
2011-09-12 05:52:01 -07:00
|
|
|
ctrl->val ? COMB_AWB : 0, COMB_AWB);
|
|
|
|
if (!ret && !ctrl->val) {
|
|
|
|
ret = ov6650_reg_write(client, REG_BLUE, priv->blue->val);
|
|
|
|
if (!ret)
|
|
|
|
ret = ov6650_reg_write(client, REG_RED,
|
|
|
|
priv->red->val);
|
|
|
|
}
|
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_SATURATION:
|
2011-09-12 05:52:01 -07:00
|
|
|
return ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->val),
|
2010-10-05 07:52:45 -07:00
|
|
|
SAT_MASK);
|
|
|
|
case V4L2_CID_HUE:
|
2011-09-12 05:52:01 -07:00
|
|
|
return ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->val),
|
2010-10-05 07:52:45 -07:00
|
|
|
HUE_MASK);
|
|
|
|
case V4L2_CID_BRIGHTNESS:
|
2011-09-12 05:52:01 -07:00
|
|
|
return ov6650_reg_write(client, REG_BRT, ctrl->val);
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_EXPOSURE_AUTO:
|
2011-09-12 04:25:25 -07:00
|
|
|
ret = ov6650_reg_rmw(client, REG_COMB, ctrl->val ==
|
|
|
|
V4L2_EXPOSURE_AUTO ? COMB_AEC : 0, COMB_AEC);
|
2011-09-12 05:52:01 -07:00
|
|
|
if (!ret && ctrl->val == V4L2_EXPOSURE_MANUAL)
|
|
|
|
ret = ov6650_reg_write(client, REG_AECH,
|
|
|
|
priv->exposure->val);
|
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_GAMMA:
|
2011-09-12 05:52:01 -07:00
|
|
|
return ov6650_reg_write(client, REG_GAM1, ctrl->val);
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_VFLIP:
|
2011-09-12 05:52:01 -07:00
|
|
|
return ov6650_reg_rmw(client, REG_COMB,
|
|
|
|
ctrl->val ? COMB_FLIP_V : 0, COMB_FLIP_V);
|
2010-10-05 07:52:45 -07:00
|
|
|
case V4L2_CID_HFLIP:
|
2011-09-12 05:52:01 -07:00
|
|
|
return ov6650_reg_rmw(client, REG_COMB,
|
|
|
|
ctrl->val ? COMB_FLIP_H : 0, COMB_FLIP_H);
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
2011-09-12 05:52:01 -07:00
|
|
|
return -EINVAL;
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_VIDEO_ADV_DEBUG
|
|
|
|
static int ov6650_get_register(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_dbg_register *reg)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
int ret;
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
if (reg->reg & ~0xff)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
reg->size = 1;
|
|
|
|
|
|
|
|
ret = ov6650_reg_read(client, reg->reg, &val);
|
|
|
|
if (!ret)
|
|
|
|
reg->val = (__u64)val;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ov6650_set_register(struct v4l2_subdev *sd,
|
2013-03-24 04:28:46 -07:00
|
|
|
const struct v4l2_dbg_register *reg)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
|
|
|
|
if (reg->reg & ~0xff || reg->val & ~0xff)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ov6650_reg_write(client, reg->reg, reg->val);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-20 06:19:50 -07:00
|
|
|
static int ov6650_s_power(struct v4l2_subdev *sd, int on)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
2012-12-21 09:01:55 -07:00
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
2017-06-16 12:45:33 -07:00
|
|
|
int ret = 0;
|
2012-07-20 06:19:50 -07:00
|
|
|
|
2017-06-16 12:45:33 -07:00
|
|
|
if (on)
|
2021-01-12 12:49:18 -07:00
|
|
|
ret = clk_prepare_enable(priv->clk);
|
2017-06-16 12:45:33 -07:00
|
|
|
else
|
2021-01-12 12:49:18 -07:00
|
|
|
clk_disable_unprepare(priv->clk);
|
2017-06-16 12:45:33 -07:00
|
|
|
|
|
|
|
return ret;
|
2012-07-20 06:19:50 -07:00
|
|
|
}
|
|
|
|
|
2015-12-14 03:25:32 -07:00
|
|
|
static int ov6650_get_selection(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 07:55:58 -07:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2015-12-14 03:25:32 -07:00
|
|
|
struct v4l2_subdev_selection *sel)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
2020-05-03 15:06:17 -07:00
|
|
|
struct v4l2_rect *rect;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2020-05-03 15:06:17 -07:00
|
|
|
if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
|
|
|
|
/* pre-select try crop rectangle */
|
media: v4l: subdev: Switch to stream-aware state functions
Switch all drivers accessing sub-device state to use the stream-aware
functions. We will soon remove the old ones.
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
---------8<------------
Additionally drivers/media/i2c/s5k5baf.c and
drivers/media/platform/samsung/s3c-camif/camif-capture.c have been
manually changed as Coccinelle didn't. Further local variables have been
removed as they became unused as a result of the other changes.
Also Coccinelle introduced indentation by space in files
drivers/media/i2c/st-mipid02.c and
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c. This has been also
corrected.
The diff from Coccinelle-generated changes are:
> diff --git b/drivers/media/i2c/imx319.c a/drivers/media/i2c/imx319.c
> index e549692ff478..420984382173 100644
> --- b/drivers/media/i2c/imx319.c
> +++ a/drivers/media/i2c/imx319.c
> @@ -2001,7 +2001,6 @@ static int imx319_do_get_pad_format(struct imx319 *imx319,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx319->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/imx355.c a/drivers/media/i2c/imx355.c
> index 96bdde685d65..e1b1d2fc79dd 100644
> --- b/drivers/media/i2c/imx355.c
> +++ a/drivers/media/i2c/imx355.c
> @@ -1299,7 +1299,6 @@ static int imx355_do_get_pad_format(struct imx355 *imx355,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx355->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov08x40.c a/drivers/media/i2c/ov08x40.c
> index ca799bbcfdb7..abbb0b774d43 100644
> --- b/drivers/media/i2c/ov08x40.c
> +++ a/drivers/media/i2c/ov08x40.c
> @@ -2774,7 +2774,6 @@ static int ov08x40_do_get_pad_format(struct ov08x40 *ov08x,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov08x->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13858.c a/drivers/media/i2c/ov13858.c
> index 7816d9787c61..09387e335d80 100644
> --- b/drivers/media/i2c/ov13858.c
> +++ a/drivers/media/i2c/ov13858.c
> @@ -1316,7 +1316,6 @@ static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13858->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13b10.c a/drivers/media/i2c/ov13b10.c
> index 268cd4b03f9c..c06411d5ee2b 100644
> --- b/drivers/media/i2c/ov13b10.c
> +++ a/drivers/media/i2c/ov13b10.c
> @@ -1001,7 +1001,6 @@ static int ov13b10_do_get_pad_format(struct ov13b10 *ov13b,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13b->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/s5c73m3/s5c73m3-core.c a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> index 47605e36bc60..8f9b5713daf7 100644
> --- b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -819,7 +819,6 @@ static void s5c73m3_oif_try_format(struct s5c73m3 *state,
> struct v4l2_subdev_format *fmt,
> const struct s5c73m3_frame_size **fs)
> {
> - struct v4l2_subdev *sd = &state->sensor_sd;
> u32 code;
>
> switch (fmt->pad) {
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 67da2045f543..03ccfb0e1e11 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1472,14 +1472,11 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
>
> if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> rects = (struct v4l2_rect * []) {
> - &s5k5baf_cis_rect,
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_compose(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_OUT)
> - };
> + &s5k5baf_cis_rect,
> + v4l2_subdev_state_get_crop(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_compose(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_crop(sd_state, PAD_OUT)
> + };
> s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
> return 0;
> }
> diff --git b/drivers/media/platform/samsung/s3c-camif/camif-capture.c a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 295e083f38e8..be58260ea67e 100644
> --- b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1216,7 +1216,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
> struct v4l2_mbus_framefmt *mf = &fmt->format;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> fmt->format = *mf;
> return 0;
> }
> @@ -1305,7 +1305,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
> __camif_subdev_try_format(camif, mf, fmt->pad);
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> *mf = fmt->format;
> mutex_unlock(&camif->lock);
> return 0;
> diff --git b/drivers/media/platform/ti/cal/cal-camerarx.c a/drivers/media/platform/ti/cal/cal-camerarx.c
> index cea454ed9c20..61433744c6c4 100644
> --- b/drivers/media/platform/ti/cal/cal-camerarx.c
> +++ a/drivers/media/platform/ti/cal/cal-camerarx.c
> @@ -621,8 +621,6 @@ static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *state,
> struct v4l2_subdev_mbus_code_enum *code)
> {
> - struct cal_camerarx *phy = to_cal_camerarx(sd);
> -
> /* No transcoding, source and sink codes must match. */
> if (cal_rx_pad_is_source(code->pad)) {
> struct v4l2_mbus_framefmt *fmt;
> diff --git b/drivers/staging/media/imx/imx-ic-prp.c a/drivers/staging/media/imx/imx-ic-prp.c
> index dd558fac6477..61d69f19657e 100644
> --- b/drivers/staging/media/imx/imx-ic-prp.c
> +++ a/drivers/staging/media/imx/imx-ic-prp.c
> @@ -82,8 +82,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git b/drivers/staging/media/imx/imx-ic-prpencvf.c a/drivers/staging/media/imx/imx-ic-prpencvf.c
> index 02db7dbb884b..ec73c901079e 100644
> --- b/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ a/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -790,8 +790,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 9c9361354c00..b08a249b5fdd 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -751,7 +751,7 @@ static void mipid02_set_fmt_source(struct v4l2_subdev *sd,
> format->format = bridge->fmt;
> else
> format->format = *v4l2_subdev_state_get_format(sd_state,
> - MIPID02_SINK_0);
> + MIPID02_SINK_0);
>
> /* but code may need to be converted */
> format->format.code = serial_to_parallel_code(format->format.code);
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> index 117912d3bfbd..96353648c032 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> @@ -319,7 +319,7 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
> rkisp1_write(rkisp1, RKISP1_CIF_ISP_CTRL, val);
>
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_info = rkisp1_mbus_info_get_by_code(src_fmt->code);
>
> if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER)
> @@ -475,9 +475,9 @@ static void rkisp1_isp_set_src_fmt(struct rkisp1_isp *isp,
> sink_fmt = v4l2_subdev_state_get_format(sd_state,
> RKISP1_ISP_PAD_SINK_VIDEO);
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_crop = v4l2_subdev_state_get_crop(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
>
> /*
> * Media bus code. The ISP can operate in pass-through mode (Bayer in,
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-10-13 00:37:10 -07:00
|
|
|
rect = v4l2_subdev_state_get_crop(sd_state, 0);
|
2020-05-03 15:06:17 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* pre-select active crop rectangle */
|
|
|
|
rect = &priv->rect;
|
|
|
|
}
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2015-12-14 03:25:32 -07:00
|
|
|
switch (sel->target) {
|
|
|
|
case V4L2_SEL_TGT_CROP_BOUNDS:
|
|
|
|
sel->r.left = DEF_HSTRT << 1;
|
|
|
|
sel->r.top = DEF_VSTRT << 1;
|
|
|
|
sel->r.width = W_CIF;
|
|
|
|
sel->r.height = H_CIF;
|
|
|
|
return 0;
|
2020-05-03 15:06:17 -07:00
|
|
|
|
2015-12-14 03:25:32 -07:00
|
|
|
case V4L2_SEL_TGT_CROP:
|
2020-05-03 15:06:17 -07:00
|
|
|
/* use selected crop rectangle */
|
|
|
|
sel->r = *rect;
|
2015-12-14 03:25:32 -07:00
|
|
|
return 0;
|
2020-05-03 15:06:17 -07:00
|
|
|
|
2015-12-14 03:25:32 -07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
2020-05-03 15:06:17 -07:00
|
|
|
static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect)
|
|
|
|
{
|
|
|
|
return width > rect->width >> 1 || height > rect->height >> 1;
|
|
|
|
}
|
|
|
|
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
static void ov6650_bind_align_crop_rectangle(struct v4l2_rect *rect)
|
|
|
|
{
|
|
|
|
v4l_bound_align_image(&rect->width, 2, W_CIF, 1,
|
|
|
|
&rect->height, 2, H_CIF, 1, 0);
|
|
|
|
v4l_bound_align_image(&rect->left, DEF_HSTRT << 1,
|
|
|
|
(DEF_HSTRT << 1) + W_CIF - (__s32)rect->width, 1,
|
|
|
|
&rect->top, DEF_VSTRT << 1,
|
|
|
|
(DEF_VSTRT << 1) + H_CIF - (__s32)rect->height,
|
|
|
|
1, 0);
|
|
|
|
}
|
|
|
|
|
2015-12-14 03:25:32 -07:00
|
|
|
static int ov6650_set_selection(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 07:55:58 -07:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2015-12-14 03:25:32 -07:00
|
|
|
struct v4l2_subdev_selection *sel)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
int ret;
|
|
|
|
|
2020-05-03 15:06:17 -07:00
|
|
|
if (sel->target != V4L2_SEL_TGT_CROP)
|
2010-10-05 07:52:45 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
ov6650_bind_align_crop_rectangle(&sel->r);
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2020-05-03 15:06:17 -07:00
|
|
|
if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
|
2023-10-23 14:40:10 -07:00
|
|
|
struct v4l2_rect *crop =
|
media: v4l: subdev: Switch to stream-aware state functions
Switch all drivers accessing sub-device state to use the stream-aware
functions. We will soon remove the old ones.
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
---------8<------------
Additionally drivers/media/i2c/s5k5baf.c and
drivers/media/platform/samsung/s3c-camif/camif-capture.c have been
manually changed as Coccinelle didn't. Further local variables have been
removed as they became unused as a result of the other changes.
Also Coccinelle introduced indentation by space in files
drivers/media/i2c/st-mipid02.c and
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c. This has been also
corrected.
The diff from Coccinelle-generated changes are:
> diff --git b/drivers/media/i2c/imx319.c a/drivers/media/i2c/imx319.c
> index e549692ff478..420984382173 100644
> --- b/drivers/media/i2c/imx319.c
> +++ a/drivers/media/i2c/imx319.c
> @@ -2001,7 +2001,6 @@ static int imx319_do_get_pad_format(struct imx319 *imx319,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx319->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/imx355.c a/drivers/media/i2c/imx355.c
> index 96bdde685d65..e1b1d2fc79dd 100644
> --- b/drivers/media/i2c/imx355.c
> +++ a/drivers/media/i2c/imx355.c
> @@ -1299,7 +1299,6 @@ static int imx355_do_get_pad_format(struct imx355 *imx355,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx355->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov08x40.c a/drivers/media/i2c/ov08x40.c
> index ca799bbcfdb7..abbb0b774d43 100644
> --- b/drivers/media/i2c/ov08x40.c
> +++ a/drivers/media/i2c/ov08x40.c
> @@ -2774,7 +2774,6 @@ static int ov08x40_do_get_pad_format(struct ov08x40 *ov08x,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov08x->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13858.c a/drivers/media/i2c/ov13858.c
> index 7816d9787c61..09387e335d80 100644
> --- b/drivers/media/i2c/ov13858.c
> +++ a/drivers/media/i2c/ov13858.c
> @@ -1316,7 +1316,6 @@ static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13858->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13b10.c a/drivers/media/i2c/ov13b10.c
> index 268cd4b03f9c..c06411d5ee2b 100644
> --- b/drivers/media/i2c/ov13b10.c
> +++ a/drivers/media/i2c/ov13b10.c
> @@ -1001,7 +1001,6 @@ static int ov13b10_do_get_pad_format(struct ov13b10 *ov13b,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13b->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/s5c73m3/s5c73m3-core.c a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> index 47605e36bc60..8f9b5713daf7 100644
> --- b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -819,7 +819,6 @@ static void s5c73m3_oif_try_format(struct s5c73m3 *state,
> struct v4l2_subdev_format *fmt,
> const struct s5c73m3_frame_size **fs)
> {
> - struct v4l2_subdev *sd = &state->sensor_sd;
> u32 code;
>
> switch (fmt->pad) {
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 67da2045f543..03ccfb0e1e11 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1472,14 +1472,11 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
>
> if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> rects = (struct v4l2_rect * []) {
> - &s5k5baf_cis_rect,
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_compose(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_OUT)
> - };
> + &s5k5baf_cis_rect,
> + v4l2_subdev_state_get_crop(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_compose(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_crop(sd_state, PAD_OUT)
> + };
> s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
> return 0;
> }
> diff --git b/drivers/media/platform/samsung/s3c-camif/camif-capture.c a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 295e083f38e8..be58260ea67e 100644
> --- b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1216,7 +1216,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
> struct v4l2_mbus_framefmt *mf = &fmt->format;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> fmt->format = *mf;
> return 0;
> }
> @@ -1305,7 +1305,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
> __camif_subdev_try_format(camif, mf, fmt->pad);
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> *mf = fmt->format;
> mutex_unlock(&camif->lock);
> return 0;
> diff --git b/drivers/media/platform/ti/cal/cal-camerarx.c a/drivers/media/platform/ti/cal/cal-camerarx.c
> index cea454ed9c20..61433744c6c4 100644
> --- b/drivers/media/platform/ti/cal/cal-camerarx.c
> +++ a/drivers/media/platform/ti/cal/cal-camerarx.c
> @@ -621,8 +621,6 @@ static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *state,
> struct v4l2_subdev_mbus_code_enum *code)
> {
> - struct cal_camerarx *phy = to_cal_camerarx(sd);
> -
> /* No transcoding, source and sink codes must match. */
> if (cal_rx_pad_is_source(code->pad)) {
> struct v4l2_mbus_framefmt *fmt;
> diff --git b/drivers/staging/media/imx/imx-ic-prp.c a/drivers/staging/media/imx/imx-ic-prp.c
> index dd558fac6477..61d69f19657e 100644
> --- b/drivers/staging/media/imx/imx-ic-prp.c
> +++ a/drivers/staging/media/imx/imx-ic-prp.c
> @@ -82,8 +82,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git b/drivers/staging/media/imx/imx-ic-prpencvf.c a/drivers/staging/media/imx/imx-ic-prpencvf.c
> index 02db7dbb884b..ec73c901079e 100644
> --- b/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ a/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -790,8 +790,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 9c9361354c00..b08a249b5fdd 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -751,7 +751,7 @@ static void mipid02_set_fmt_source(struct v4l2_subdev *sd,
> format->format = bridge->fmt;
> else
> format->format = *v4l2_subdev_state_get_format(sd_state,
> - MIPID02_SINK_0);
> + MIPID02_SINK_0);
>
> /* but code may need to be converted */
> format->format.code = serial_to_parallel_code(format->format.code);
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> index 117912d3bfbd..96353648c032 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> @@ -319,7 +319,7 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
> rkisp1_write(rkisp1, RKISP1_CIF_ISP_CTRL, val);
>
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_info = rkisp1_mbus_info_get_by_code(src_fmt->code);
>
> if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER)
> @@ -475,9 +475,9 @@ static void rkisp1_isp_set_src_fmt(struct rkisp1_isp *isp,
> sink_fmt = v4l2_subdev_state_get_format(sd_state,
> RKISP1_ISP_PAD_SINK_VIDEO);
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_crop = v4l2_subdev_state_get_crop(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
>
> /*
> * Media bus code. The ISP can operate in pass-through mode (Bayer in,
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-10-13 00:37:10 -07:00
|
|
|
v4l2_subdev_state_get_crop(sd_state, 0);
|
2023-10-23 14:40:10 -07:00
|
|
|
struct v4l2_mbus_framefmt *mf =
|
media: v4l: subdev: Switch to stream-aware state functions
Switch all drivers accessing sub-device state to use the stream-aware
functions. We will soon remove the old ones.
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
---------8<------------
Additionally drivers/media/i2c/s5k5baf.c and
drivers/media/platform/samsung/s3c-camif/camif-capture.c have been
manually changed as Coccinelle didn't. Further local variables have been
removed as they became unused as a result of the other changes.
Also Coccinelle introduced indentation by space in files
drivers/media/i2c/st-mipid02.c and
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c. This has been also
corrected.
The diff from Coccinelle-generated changes are:
> diff --git b/drivers/media/i2c/imx319.c a/drivers/media/i2c/imx319.c
> index e549692ff478..420984382173 100644
> --- b/drivers/media/i2c/imx319.c
> +++ a/drivers/media/i2c/imx319.c
> @@ -2001,7 +2001,6 @@ static int imx319_do_get_pad_format(struct imx319 *imx319,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx319->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/imx355.c a/drivers/media/i2c/imx355.c
> index 96bdde685d65..e1b1d2fc79dd 100644
> --- b/drivers/media/i2c/imx355.c
> +++ a/drivers/media/i2c/imx355.c
> @@ -1299,7 +1299,6 @@ static int imx355_do_get_pad_format(struct imx355 *imx355,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx355->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov08x40.c a/drivers/media/i2c/ov08x40.c
> index ca799bbcfdb7..abbb0b774d43 100644
> --- b/drivers/media/i2c/ov08x40.c
> +++ a/drivers/media/i2c/ov08x40.c
> @@ -2774,7 +2774,6 @@ static int ov08x40_do_get_pad_format(struct ov08x40 *ov08x,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov08x->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13858.c a/drivers/media/i2c/ov13858.c
> index 7816d9787c61..09387e335d80 100644
> --- b/drivers/media/i2c/ov13858.c
> +++ a/drivers/media/i2c/ov13858.c
> @@ -1316,7 +1316,6 @@ static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13858->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13b10.c a/drivers/media/i2c/ov13b10.c
> index 268cd4b03f9c..c06411d5ee2b 100644
> --- b/drivers/media/i2c/ov13b10.c
> +++ a/drivers/media/i2c/ov13b10.c
> @@ -1001,7 +1001,6 @@ static int ov13b10_do_get_pad_format(struct ov13b10 *ov13b,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13b->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/s5c73m3/s5c73m3-core.c a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> index 47605e36bc60..8f9b5713daf7 100644
> --- b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -819,7 +819,6 @@ static void s5c73m3_oif_try_format(struct s5c73m3 *state,
> struct v4l2_subdev_format *fmt,
> const struct s5c73m3_frame_size **fs)
> {
> - struct v4l2_subdev *sd = &state->sensor_sd;
> u32 code;
>
> switch (fmt->pad) {
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 67da2045f543..03ccfb0e1e11 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1472,14 +1472,11 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
>
> if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> rects = (struct v4l2_rect * []) {
> - &s5k5baf_cis_rect,
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_compose(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_OUT)
> - };
> + &s5k5baf_cis_rect,
> + v4l2_subdev_state_get_crop(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_compose(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_crop(sd_state, PAD_OUT)
> + };
> s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
> return 0;
> }
> diff --git b/drivers/media/platform/samsung/s3c-camif/camif-capture.c a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 295e083f38e8..be58260ea67e 100644
> --- b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1216,7 +1216,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
> struct v4l2_mbus_framefmt *mf = &fmt->format;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> fmt->format = *mf;
> return 0;
> }
> @@ -1305,7 +1305,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
> __camif_subdev_try_format(camif, mf, fmt->pad);
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> *mf = fmt->format;
> mutex_unlock(&camif->lock);
> return 0;
> diff --git b/drivers/media/platform/ti/cal/cal-camerarx.c a/drivers/media/platform/ti/cal/cal-camerarx.c
> index cea454ed9c20..61433744c6c4 100644
> --- b/drivers/media/platform/ti/cal/cal-camerarx.c
> +++ a/drivers/media/platform/ti/cal/cal-camerarx.c
> @@ -621,8 +621,6 @@ static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *state,
> struct v4l2_subdev_mbus_code_enum *code)
> {
> - struct cal_camerarx *phy = to_cal_camerarx(sd);
> -
> /* No transcoding, source and sink codes must match. */
> if (cal_rx_pad_is_source(code->pad)) {
> struct v4l2_mbus_framefmt *fmt;
> diff --git b/drivers/staging/media/imx/imx-ic-prp.c a/drivers/staging/media/imx/imx-ic-prp.c
> index dd558fac6477..61d69f19657e 100644
> --- b/drivers/staging/media/imx/imx-ic-prp.c
> +++ a/drivers/staging/media/imx/imx-ic-prp.c
> @@ -82,8 +82,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git b/drivers/staging/media/imx/imx-ic-prpencvf.c a/drivers/staging/media/imx/imx-ic-prpencvf.c
> index 02db7dbb884b..ec73c901079e 100644
> --- b/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ a/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -790,8 +790,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 9c9361354c00..b08a249b5fdd 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -751,7 +751,7 @@ static void mipid02_set_fmt_source(struct v4l2_subdev *sd,
> format->format = bridge->fmt;
> else
> format->format = *v4l2_subdev_state_get_format(sd_state,
> - MIPID02_SINK_0);
> + MIPID02_SINK_0);
>
> /* but code may need to be converted */
> format->format.code = serial_to_parallel_code(format->format.code);
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> index 117912d3bfbd..96353648c032 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> @@ -319,7 +319,7 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
> rkisp1_write(rkisp1, RKISP1_CIF_ISP_CTRL, val);
>
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_info = rkisp1_mbus_info_get_by_code(src_fmt->code);
>
> if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER)
> @@ -475,9 +475,9 @@ static void rkisp1_isp_set_src_fmt(struct rkisp1_isp *isp,
> sink_fmt = v4l2_subdev_state_get_format(sd_state,
> RKISP1_ISP_PAD_SINK_VIDEO);
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_crop = v4l2_subdev_state_get_crop(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
>
> /*
> * Media bus code. The ISP can operate in pass-through mode (Bayer in,
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-10-13 00:37:10 -07:00
|
|
|
v4l2_subdev_state_get_format(sd_state, 0);
|
2020-05-03 15:06:17 -07:00
|
|
|
/* detect current pad config scaling factor */
|
|
|
|
bool half_scale = !is_unscaled_ok(mf->width, mf->height, crop);
|
|
|
|
|
|
|
|
/* store new crop rectangle */
|
|
|
|
*crop = sel->r;
|
|
|
|
|
|
|
|
/* adjust frame size */
|
|
|
|
mf->width = crop->width >> half_scale;
|
|
|
|
mf->height = crop->height >> half_scale;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* V4L2_SUBDEV_FORMAT_ACTIVE */
|
|
|
|
|
|
|
|
/* apply new crop rectangle */
|
2019-09-03 13:11:38 -07:00
|
|
|
ret = ov6650_reg_write(client, REG_HSTRT, sel->r.left >> 1);
|
2010-10-05 07:52:45 -07:00
|
|
|
if (!ret) {
|
2019-09-03 13:11:44 -07:00
|
|
|
priv->rect.width += priv->rect.left - sel->r.left;
|
2019-09-03 13:11:38 -07:00
|
|
|
priv->rect.left = sel->r.left;
|
2010-10-05 07:52:45 -07:00
|
|
|
ret = ov6650_reg_write(client, REG_HSTOP,
|
2019-09-03 13:11:38 -07:00
|
|
|
(sel->r.left + sel->r.width) >> 1);
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
if (!ret) {
|
2019-09-03 13:11:38 -07:00
|
|
|
priv->rect.width = sel->r.width;
|
|
|
|
ret = ov6650_reg_write(client, REG_VSTRT, sel->r.top >> 1);
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
if (!ret) {
|
2019-09-03 13:11:44 -07:00
|
|
|
priv->rect.height += priv->rect.top - sel->r.top;
|
2019-09-03 13:11:38 -07:00
|
|
|
priv->rect.top = sel->r.top;
|
2010-10-05 07:52:45 -07:00
|
|
|
ret = ov6650_reg_write(client, REG_VSTOP,
|
2019-09-03 13:11:38 -07:00
|
|
|
(sel->r.top + sel->r.height) >> 1);
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
if (!ret)
|
2019-09-03 13:11:38 -07:00
|
|
|
priv->rect.height = sel->r.height;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-09 00:02:34 -07:00
|
|
|
static int ov6650_get_fmt(struct v4l2_subdev *sd,
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 07:55:58 -07:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2015-04-09 00:02:34 -07:00
|
|
|
struct v4l2_subdev_format *format)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
2015-04-09 00:02:34 -07:00
|
|
|
struct v4l2_mbus_framefmt *mf = &format->format;
|
2010-10-05 07:52:45 -07:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
|
2015-04-09 00:02:34 -07:00
|
|
|
if (format->pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
media: ov6650: Fix some format attributes not under control
User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values. The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support"). Fix it.
Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with resulting
pad config format code and frame size.
Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-09-03 13:11:40 -07:00
|
|
|
/* initialize response with default media bus frame format */
|
|
|
|
*mf = ov6650_def_fmt;
|
|
|
|
|
|
|
|
/* update media bus format code and frame size */
|
2019-09-03 13:11:41 -07:00
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
|
2023-10-23 14:40:10 -07:00
|
|
|
struct v4l2_mbus_framefmt *try_fmt =
|
media: v4l: subdev: Switch to stream-aware state functions
Switch all drivers accessing sub-device state to use the stream-aware
functions. We will soon remove the old ones.
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
---------8<------------
Additionally drivers/media/i2c/s5k5baf.c and
drivers/media/platform/samsung/s3c-camif/camif-capture.c have been
manually changed as Coccinelle didn't. Further local variables have been
removed as they became unused as a result of the other changes.
Also Coccinelle introduced indentation by space in files
drivers/media/i2c/st-mipid02.c and
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c. This has been also
corrected.
The diff from Coccinelle-generated changes are:
> diff --git b/drivers/media/i2c/imx319.c a/drivers/media/i2c/imx319.c
> index e549692ff478..420984382173 100644
> --- b/drivers/media/i2c/imx319.c
> +++ a/drivers/media/i2c/imx319.c
> @@ -2001,7 +2001,6 @@ static int imx319_do_get_pad_format(struct imx319 *imx319,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx319->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/imx355.c a/drivers/media/i2c/imx355.c
> index 96bdde685d65..e1b1d2fc79dd 100644
> --- b/drivers/media/i2c/imx355.c
> +++ a/drivers/media/i2c/imx355.c
> @@ -1299,7 +1299,6 @@ static int imx355_do_get_pad_format(struct imx355 *imx355,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx355->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov08x40.c a/drivers/media/i2c/ov08x40.c
> index ca799bbcfdb7..abbb0b774d43 100644
> --- b/drivers/media/i2c/ov08x40.c
> +++ a/drivers/media/i2c/ov08x40.c
> @@ -2774,7 +2774,6 @@ static int ov08x40_do_get_pad_format(struct ov08x40 *ov08x,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov08x->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13858.c a/drivers/media/i2c/ov13858.c
> index 7816d9787c61..09387e335d80 100644
> --- b/drivers/media/i2c/ov13858.c
> +++ a/drivers/media/i2c/ov13858.c
> @@ -1316,7 +1316,6 @@ static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13858->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13b10.c a/drivers/media/i2c/ov13b10.c
> index 268cd4b03f9c..c06411d5ee2b 100644
> --- b/drivers/media/i2c/ov13b10.c
> +++ a/drivers/media/i2c/ov13b10.c
> @@ -1001,7 +1001,6 @@ static int ov13b10_do_get_pad_format(struct ov13b10 *ov13b,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13b->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/s5c73m3/s5c73m3-core.c a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> index 47605e36bc60..8f9b5713daf7 100644
> --- b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -819,7 +819,6 @@ static void s5c73m3_oif_try_format(struct s5c73m3 *state,
> struct v4l2_subdev_format *fmt,
> const struct s5c73m3_frame_size **fs)
> {
> - struct v4l2_subdev *sd = &state->sensor_sd;
> u32 code;
>
> switch (fmt->pad) {
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 67da2045f543..03ccfb0e1e11 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1472,14 +1472,11 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
>
> if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> rects = (struct v4l2_rect * []) {
> - &s5k5baf_cis_rect,
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_compose(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_OUT)
> - };
> + &s5k5baf_cis_rect,
> + v4l2_subdev_state_get_crop(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_compose(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_crop(sd_state, PAD_OUT)
> + };
> s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
> return 0;
> }
> diff --git b/drivers/media/platform/samsung/s3c-camif/camif-capture.c a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 295e083f38e8..be58260ea67e 100644
> --- b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1216,7 +1216,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
> struct v4l2_mbus_framefmt *mf = &fmt->format;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> fmt->format = *mf;
> return 0;
> }
> @@ -1305,7 +1305,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
> __camif_subdev_try_format(camif, mf, fmt->pad);
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> *mf = fmt->format;
> mutex_unlock(&camif->lock);
> return 0;
> diff --git b/drivers/media/platform/ti/cal/cal-camerarx.c a/drivers/media/platform/ti/cal/cal-camerarx.c
> index cea454ed9c20..61433744c6c4 100644
> --- b/drivers/media/platform/ti/cal/cal-camerarx.c
> +++ a/drivers/media/platform/ti/cal/cal-camerarx.c
> @@ -621,8 +621,6 @@ static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *state,
> struct v4l2_subdev_mbus_code_enum *code)
> {
> - struct cal_camerarx *phy = to_cal_camerarx(sd);
> -
> /* No transcoding, source and sink codes must match. */
> if (cal_rx_pad_is_source(code->pad)) {
> struct v4l2_mbus_framefmt *fmt;
> diff --git b/drivers/staging/media/imx/imx-ic-prp.c a/drivers/staging/media/imx/imx-ic-prp.c
> index dd558fac6477..61d69f19657e 100644
> --- b/drivers/staging/media/imx/imx-ic-prp.c
> +++ a/drivers/staging/media/imx/imx-ic-prp.c
> @@ -82,8 +82,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git b/drivers/staging/media/imx/imx-ic-prpencvf.c a/drivers/staging/media/imx/imx-ic-prpencvf.c
> index 02db7dbb884b..ec73c901079e 100644
> --- b/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ a/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -790,8 +790,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 9c9361354c00..b08a249b5fdd 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -751,7 +751,7 @@ static void mipid02_set_fmt_source(struct v4l2_subdev *sd,
> format->format = bridge->fmt;
> else
> format->format = *v4l2_subdev_state_get_format(sd_state,
> - MIPID02_SINK_0);
> + MIPID02_SINK_0);
>
> /* but code may need to be converted */
> format->format.code = serial_to_parallel_code(format->format.code);
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> index 117912d3bfbd..96353648c032 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> @@ -319,7 +319,7 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
> rkisp1_write(rkisp1, RKISP1_CIF_ISP_CTRL, val);
>
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_info = rkisp1_mbus_info_get_by_code(src_fmt->code);
>
> if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER)
> @@ -475,9 +475,9 @@ static void rkisp1_isp_set_src_fmt(struct rkisp1_isp *isp,
> sink_fmt = v4l2_subdev_state_get_format(sd_state,
> RKISP1_ISP_PAD_SINK_VIDEO);
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_crop = v4l2_subdev_state_get_crop(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
>
> /*
> * Media bus code. The ISP can operate in pass-through mode (Bayer in,
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-10-13 00:37:10 -07:00
|
|
|
v4l2_subdev_state_get_format(sd_state, 0);
|
2023-10-23 14:40:10 -07:00
|
|
|
|
|
|
|
mf->width = try_fmt->width;
|
|
|
|
mf->height = try_fmt->height;
|
|
|
|
mf->code = try_fmt->code;
|
2019-09-03 13:11:41 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
mf->width = priv->rect.width >> priv->half_scale;
|
|
|
|
mf->height = priv->rect.height >> priv->half_scale;
|
|
|
|
mf->code = priv->code;
|
|
|
|
}
|
2010-10-05 07:52:45 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-13 05:50:47 -07:00
|
|
|
#define to_clkrc(div) ((div) - 1)
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
/* set the format we will capture in */
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
static int ov6650_s_fmt(struct v4l2_subdev *sd, u32 code, bool half_scale)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
2019-10-13 05:50:48 -07:00
|
|
|
u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask;
|
2010-10-05 07:52:45 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* select color matrix configuration for given color encoding */
|
|
|
|
switch (code) {
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_Y8_1X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
dev_dbg(&client->dev, "pixel format GREY8_1X8\n");
|
|
|
|
coma_mask |= COMA_RGB | COMA_WORD_SWAP | COMA_BYTE_SWAP;
|
|
|
|
coma_set |= COMA_BW;
|
|
|
|
break;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_YUYV8_2X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
dev_dbg(&client->dev, "pixel format YUYV8_2X8_LE\n");
|
|
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_BYTE_SWAP;
|
|
|
|
coma_set |= COMA_WORD_SWAP;
|
|
|
|
break;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_YVYU8_2X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
dev_dbg(&client->dev, "pixel format YVYU8_2X8_LE (untested)\n");
|
|
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP |
|
|
|
|
COMA_BYTE_SWAP;
|
|
|
|
break;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_UYVY8_2X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
dev_dbg(&client->dev, "pixel format YUYV8_2X8_BE\n");
|
|
|
|
if (half_scale) {
|
|
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP;
|
|
|
|
coma_set |= COMA_BYTE_SWAP;
|
|
|
|
} else {
|
|
|
|
coma_mask |= COMA_RGB | COMA_BW;
|
|
|
|
coma_set |= COMA_BYTE_SWAP | COMA_WORD_SWAP;
|
|
|
|
}
|
|
|
|
break;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_VYUY8_2X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
dev_dbg(&client->dev, "pixel format YVYU8_2X8_BE (untested)\n");
|
|
|
|
if (half_scale) {
|
|
|
|
coma_mask |= COMA_RGB | COMA_BW;
|
|
|
|
coma_set |= COMA_BYTE_SWAP | COMA_WORD_SWAP;
|
|
|
|
} else {
|
|
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP;
|
|
|
|
coma_set |= COMA_BYTE_SWAP;
|
|
|
|
}
|
|
|
|
break;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_SBGGR8_1X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
dev_dbg(&client->dev, "pixel format SBGGR8_1X8 (untested)\n");
|
|
|
|
coma_mask |= COMA_BW | COMA_BYTE_SWAP | COMA_WORD_SWAP;
|
|
|
|
coma_set |= COMA_RAW_RGB | COMA_RGB;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-11-10 10:28:29 -07:00
|
|
|
if (code == MEDIA_BUS_FMT_Y8_1X8 ||
|
|
|
|
code == MEDIA_BUS_FMT_SBGGR8_1X8) {
|
2010-10-05 07:52:45 -07:00
|
|
|
coml_mask = COML_ONE_CHANNEL;
|
|
|
|
coml_set = 0;
|
|
|
|
} else {
|
|
|
|
coml_mask = 0;
|
|
|
|
coml_set = COML_ONE_CHANNEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (half_scale) {
|
|
|
|
dev_dbg(&client->dev, "max resolution: QCIF\n");
|
|
|
|
coma_set |= COMA_QCIF;
|
|
|
|
} else {
|
|
|
|
dev_dbg(&client->dev, "max resolution: CIF\n");
|
|
|
|
coma_mask |= COMA_QCIF;
|
|
|
|
}
|
|
|
|
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask);
|
2019-09-03 13:11:43 -07:00
|
|
|
if (!ret) {
|
|
|
|
priv->half_scale = half_scale;
|
|
|
|
|
2010-10-05 07:52:45 -07:00
|
|
|
ret = ov6650_reg_rmw(client, REG_COML, coml_set, coml_mask);
|
2019-09-03 13:11:43 -07:00
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
priv->code = code;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-09 02:24:36 -07:00
|
|
|
static int ov6650_set_fmt(struct v4l2_subdev *sd,
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 07:55:58 -07:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2015-04-09 02:24:36 -07:00
|
|
|
struct v4l2_subdev_format *format)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
2015-04-09 02:24:36 -07:00
|
|
|
struct v4l2_mbus_framefmt *mf = &format->format;
|
2010-10-05 07:52:45 -07:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
2020-05-03 15:06:18 -07:00
|
|
|
struct v4l2_rect *crop;
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
bool half_scale;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2015-04-09 02:24:36 -07:00
|
|
|
if (format->pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-05 07:52:45 -07:00
|
|
|
switch (mf->code) {
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_Y10_1X10:
|
|
|
|
mf->code = MEDIA_BUS_FMT_Y8_1X8;
|
2020-07-24 15:10:14 -07:00
|
|
|
fallthrough;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_Y8_1X8:
|
|
|
|
case MEDIA_BUS_FMT_YVYU8_2X8:
|
|
|
|
case MEDIA_BUS_FMT_YUYV8_2X8:
|
|
|
|
case MEDIA_BUS_FMT_VYUY8_2X8:
|
|
|
|
case MEDIA_BUS_FMT_UYVY8_2X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
break;
|
|
|
|
default:
|
2014-11-10 10:28:29 -07:00
|
|
|
mf->code = MEDIA_BUS_FMT_SBGGR8_1X8;
|
2020-07-24 15:10:14 -07:00
|
|
|
fallthrough;
|
2014-11-10 10:28:29 -07:00
|
|
|
case MEDIA_BUS_FMT_SBGGR8_1X8:
|
2010-10-05 07:52:45 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:06:17 -07:00
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY)
|
media: v4l: subdev: Switch to stream-aware state functions
Switch all drivers accessing sub-device state to use the stream-aware
functions. We will soon remove the old ones.
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
---------8<------------
Additionally drivers/media/i2c/s5k5baf.c and
drivers/media/platform/samsung/s3c-camif/camif-capture.c have been
manually changed as Coccinelle didn't. Further local variables have been
removed as they became unused as a result of the other changes.
Also Coccinelle introduced indentation by space in files
drivers/media/i2c/st-mipid02.c and
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c. This has been also
corrected.
The diff from Coccinelle-generated changes are:
> diff --git b/drivers/media/i2c/imx319.c a/drivers/media/i2c/imx319.c
> index e549692ff478..420984382173 100644
> --- b/drivers/media/i2c/imx319.c
> +++ a/drivers/media/i2c/imx319.c
> @@ -2001,7 +2001,6 @@ static int imx319_do_get_pad_format(struct imx319 *imx319,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx319->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/imx355.c a/drivers/media/i2c/imx355.c
> index 96bdde685d65..e1b1d2fc79dd 100644
> --- b/drivers/media/i2c/imx355.c
> +++ a/drivers/media/i2c/imx355.c
> @@ -1299,7 +1299,6 @@ static int imx355_do_get_pad_format(struct imx355 *imx355,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx355->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov08x40.c a/drivers/media/i2c/ov08x40.c
> index ca799bbcfdb7..abbb0b774d43 100644
> --- b/drivers/media/i2c/ov08x40.c
> +++ a/drivers/media/i2c/ov08x40.c
> @@ -2774,7 +2774,6 @@ static int ov08x40_do_get_pad_format(struct ov08x40 *ov08x,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov08x->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13858.c a/drivers/media/i2c/ov13858.c
> index 7816d9787c61..09387e335d80 100644
> --- b/drivers/media/i2c/ov13858.c
> +++ a/drivers/media/i2c/ov13858.c
> @@ -1316,7 +1316,6 @@ static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13858->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13b10.c a/drivers/media/i2c/ov13b10.c
> index 268cd4b03f9c..c06411d5ee2b 100644
> --- b/drivers/media/i2c/ov13b10.c
> +++ a/drivers/media/i2c/ov13b10.c
> @@ -1001,7 +1001,6 @@ static int ov13b10_do_get_pad_format(struct ov13b10 *ov13b,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13b->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/s5c73m3/s5c73m3-core.c a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> index 47605e36bc60..8f9b5713daf7 100644
> --- b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -819,7 +819,6 @@ static void s5c73m3_oif_try_format(struct s5c73m3 *state,
> struct v4l2_subdev_format *fmt,
> const struct s5c73m3_frame_size **fs)
> {
> - struct v4l2_subdev *sd = &state->sensor_sd;
> u32 code;
>
> switch (fmt->pad) {
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 67da2045f543..03ccfb0e1e11 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1472,14 +1472,11 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
>
> if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> rects = (struct v4l2_rect * []) {
> - &s5k5baf_cis_rect,
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_compose(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_OUT)
> - };
> + &s5k5baf_cis_rect,
> + v4l2_subdev_state_get_crop(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_compose(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_crop(sd_state, PAD_OUT)
> + };
> s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
> return 0;
> }
> diff --git b/drivers/media/platform/samsung/s3c-camif/camif-capture.c a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 295e083f38e8..be58260ea67e 100644
> --- b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1216,7 +1216,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
> struct v4l2_mbus_framefmt *mf = &fmt->format;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> fmt->format = *mf;
> return 0;
> }
> @@ -1305,7 +1305,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
> __camif_subdev_try_format(camif, mf, fmt->pad);
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> *mf = fmt->format;
> mutex_unlock(&camif->lock);
> return 0;
> diff --git b/drivers/media/platform/ti/cal/cal-camerarx.c a/drivers/media/platform/ti/cal/cal-camerarx.c
> index cea454ed9c20..61433744c6c4 100644
> --- b/drivers/media/platform/ti/cal/cal-camerarx.c
> +++ a/drivers/media/platform/ti/cal/cal-camerarx.c
> @@ -621,8 +621,6 @@ static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *state,
> struct v4l2_subdev_mbus_code_enum *code)
> {
> - struct cal_camerarx *phy = to_cal_camerarx(sd);
> -
> /* No transcoding, source and sink codes must match. */
> if (cal_rx_pad_is_source(code->pad)) {
> struct v4l2_mbus_framefmt *fmt;
> diff --git b/drivers/staging/media/imx/imx-ic-prp.c a/drivers/staging/media/imx/imx-ic-prp.c
> index dd558fac6477..61d69f19657e 100644
> --- b/drivers/staging/media/imx/imx-ic-prp.c
> +++ a/drivers/staging/media/imx/imx-ic-prp.c
> @@ -82,8 +82,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git b/drivers/staging/media/imx/imx-ic-prpencvf.c a/drivers/staging/media/imx/imx-ic-prpencvf.c
> index 02db7dbb884b..ec73c901079e 100644
> --- b/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ a/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -790,8 +790,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 9c9361354c00..b08a249b5fdd 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -751,7 +751,7 @@ static void mipid02_set_fmt_source(struct v4l2_subdev *sd,
> format->format = bridge->fmt;
> else
> format->format = *v4l2_subdev_state_get_format(sd_state,
> - MIPID02_SINK_0);
> + MIPID02_SINK_0);
>
> /* but code may need to be converted */
> format->format.code = serial_to_parallel_code(format->format.code);
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> index 117912d3bfbd..96353648c032 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> @@ -319,7 +319,7 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
> rkisp1_write(rkisp1, RKISP1_CIF_ISP_CTRL, val);
>
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_info = rkisp1_mbus_info_get_by_code(src_fmt->code);
>
> if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER)
> @@ -475,9 +475,9 @@ static void rkisp1_isp_set_src_fmt(struct rkisp1_isp *isp,
> sink_fmt = v4l2_subdev_state_get_format(sd_state,
> RKISP1_ISP_PAD_SINK_VIDEO);
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_crop = v4l2_subdev_state_get_crop(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
>
> /*
> * Media bus code. The ISP can operate in pass-through mode (Bayer in,
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-10-13 00:37:10 -07:00
|
|
|
crop = v4l2_subdev_state_get_crop(sd_state, 0);
|
2020-05-03 15:06:17 -07:00
|
|
|
else
|
2020-05-03 15:06:18 -07:00
|
|
|
crop = &priv->rect;
|
2020-05-03 15:06:17 -07:00
|
|
|
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
half_scale = !is_unscaled_ok(mf->width, mf->height, crop);
|
|
|
|
|
media: ov6650: Fix some format attributes not under control
User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values. The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support"). Fix it.
Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with resulting
pad config format code and frame size.
Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-09-03 13:11:40 -07:00
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
|
2023-10-23 14:40:10 -07:00
|
|
|
struct v4l2_mbus_framefmt *try_fmt =
|
media: v4l: subdev: Switch to stream-aware state functions
Switch all drivers accessing sub-device state to use the stream-aware
functions. We will soon remove the old ones.
This patch has been generated using the following Coccinelle script:
---------8<------------
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_pad_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_format(E1, E2, E3)
+ v4l2_subdev_state_get_format(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_crop(E1, E2, E3)
+ v4l2_subdev_state_get_crop(E2, E3)
@@
expression E1, E2, E3;
@@
- v4l2_subdev_get_try_compose(E1, E2, E3)
+ v4l2_subdev_state_get_compose(E2, E3)
---------8<------------
Additionally drivers/media/i2c/s5k5baf.c and
drivers/media/platform/samsung/s3c-camif/camif-capture.c have been
manually changed as Coccinelle didn't. Further local variables have been
removed as they became unused as a result of the other changes.
Also Coccinelle introduced indentation by space in files
drivers/media/i2c/st-mipid02.c and
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c. This has been also
corrected.
The diff from Coccinelle-generated changes are:
> diff --git b/drivers/media/i2c/imx319.c a/drivers/media/i2c/imx319.c
> index e549692ff478..420984382173 100644
> --- b/drivers/media/i2c/imx319.c
> +++ a/drivers/media/i2c/imx319.c
> @@ -2001,7 +2001,6 @@ static int imx319_do_get_pad_format(struct imx319 *imx319,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx319->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/imx355.c a/drivers/media/i2c/imx355.c
> index 96bdde685d65..e1b1d2fc79dd 100644
> --- b/drivers/media/i2c/imx355.c
> +++ a/drivers/media/i2c/imx355.c
> @@ -1299,7 +1299,6 @@ static int imx355_do_get_pad_format(struct imx355 *imx355,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &imx355->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov08x40.c a/drivers/media/i2c/ov08x40.c
> index ca799bbcfdb7..abbb0b774d43 100644
> --- b/drivers/media/i2c/ov08x40.c
> +++ a/drivers/media/i2c/ov08x40.c
> @@ -2774,7 +2774,6 @@ static int ov08x40_do_get_pad_format(struct ov08x40 *ov08x,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov08x->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13858.c a/drivers/media/i2c/ov13858.c
> index 7816d9787c61..09387e335d80 100644
> --- b/drivers/media/i2c/ov13858.c
> +++ a/drivers/media/i2c/ov13858.c
> @@ -1316,7 +1316,6 @@ static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13858->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/ov13b10.c a/drivers/media/i2c/ov13b10.c
> index 268cd4b03f9c..c06411d5ee2b 100644
> --- b/drivers/media/i2c/ov13b10.c
> +++ a/drivers/media/i2c/ov13b10.c
> @@ -1001,7 +1001,6 @@ static int ov13b10_do_get_pad_format(struct ov13b10 *ov13b,
> struct v4l2_subdev_format *fmt)
> {
> struct v4l2_mbus_framefmt *framefmt;
> - struct v4l2_subdev *sd = &ov13b->sd;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> framefmt = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> diff --git b/drivers/media/i2c/s5c73m3/s5c73m3-core.c a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> index 47605e36bc60..8f9b5713daf7 100644
> --- b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> +++ a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
> @@ -819,7 +819,6 @@ static void s5c73m3_oif_try_format(struct s5c73m3 *state,
> struct v4l2_subdev_format *fmt,
> const struct s5c73m3_frame_size **fs)
> {
> - struct v4l2_subdev *sd = &state->sensor_sd;
> u32 code;
>
> switch (fmt->pad) {
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 67da2045f543..03ccfb0e1e11 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1472,14 +1472,11 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
>
> if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> rects = (struct v4l2_rect * []) {
> - &s5k5baf_cis_rect,
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_compose(sd, sd_state,
> - PAD_CIS),
> - v4l2_subdev_get_try_crop(sd, sd_state,
> - PAD_OUT)
> - };
> + &s5k5baf_cis_rect,
> + v4l2_subdev_state_get_crop(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_compose(sd_state, PAD_CIS),
> + v4l2_subdev_state_get_crop(sd_state, PAD_OUT)
> + };
> s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
> return 0;
> }
> diff --git b/drivers/media/platform/samsung/s3c-camif/camif-capture.c a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 295e083f38e8..be58260ea67e 100644
> --- b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1216,7 +1216,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
> struct v4l2_mbus_framefmt *mf = &fmt->format;
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> fmt->format = *mf;
> return 0;
> }
> @@ -1305,7 +1305,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
> __camif_subdev_try_format(camif, mf, fmt->pad);
>
> if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> - mf = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
> + mf = v4l2_subdev_state_get_format(sd_state, fmt->pad);
> *mf = fmt->format;
> mutex_unlock(&camif->lock);
> return 0;
> diff --git b/drivers/media/platform/ti/cal/cal-camerarx.c a/drivers/media/platform/ti/cal/cal-camerarx.c
> index cea454ed9c20..61433744c6c4 100644
> --- b/drivers/media/platform/ti/cal/cal-camerarx.c
> +++ a/drivers/media/platform/ti/cal/cal-camerarx.c
> @@ -621,8 +621,6 @@ static int cal_camerarx_sd_enum_mbus_code(struct v4l2_subdev *sd,
> struct v4l2_subdev_state *state,
> struct v4l2_subdev_mbus_code_enum *code)
> {
> - struct cal_camerarx *phy = to_cal_camerarx(sd);
> -
> /* No transcoding, source and sink codes must match. */
> if (cal_rx_pad_is_source(code->pad)) {
> struct v4l2_mbus_framefmt *fmt;
> diff --git b/drivers/staging/media/imx/imx-ic-prp.c a/drivers/staging/media/imx/imx-ic-prp.c
> index dd558fac6477..61d69f19657e 100644
> --- b/drivers/staging/media/imx/imx-ic-prp.c
> +++ a/drivers/staging/media/imx/imx-ic-prp.c
> @@ -82,8 +82,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git b/drivers/staging/media/imx/imx-ic-prpencvf.c a/drivers/staging/media/imx/imx-ic-prpencvf.c
> index 02db7dbb884b..ec73c901079e 100644
> --- b/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ a/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -790,8 +790,6 @@ static struct v4l2_mbus_framefmt *
> __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_state *sd_state,
> unsigned int pad, enum v4l2_subdev_format_whence which)
> {
> - struct imx_ic_priv *ic_priv = priv->ic_priv;
> -
> if (which == V4L2_SUBDEV_FORMAT_TRY)
> return v4l2_subdev_state_get_format(sd_state, pad);
> else
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 9c9361354c00..b08a249b5fdd 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -751,7 +751,7 @@ static void mipid02_set_fmt_source(struct v4l2_subdev *sd,
> format->format = bridge->fmt;
> else
> format->format = *v4l2_subdev_state_get_format(sd_state,
> - MIPID02_SINK_0);
> + MIPID02_SINK_0);
>
> /* but code may need to be converted */
> format->format.code = serial_to_parallel_code(format->format.code);
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> index 117912d3bfbd..96353648c032 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
> @@ -319,7 +319,7 @@ static void rkisp1_isp_start(struct rkisp1_isp *isp,
> rkisp1_write(rkisp1, RKISP1_CIF_ISP_CTRL, val);
>
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_info = rkisp1_mbus_info_get_by_code(src_fmt->code);
>
> if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER)
> @@ -475,9 +475,9 @@ static void rkisp1_isp_set_src_fmt(struct rkisp1_isp *isp,
> sink_fmt = v4l2_subdev_state_get_format(sd_state,
> RKISP1_ISP_PAD_SINK_VIDEO);
> src_fmt = v4l2_subdev_state_get_format(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
> src_crop = v4l2_subdev_state_get_crop(sd_state,
> - RKISP1_ISP_PAD_SOURCE_VIDEO);
> + RKISP1_ISP_PAD_SOURCE_VIDEO);
>
> /*
> * Media bus code. The ISP can operate in pass-through mode (Bayer in,
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-10-13 00:37:10 -07:00
|
|
|
v4l2_subdev_state_get_format(sd_state, 0);
|
2023-10-23 14:40:10 -07:00
|
|
|
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
/* store new mbus frame format code and size in pad config */
|
2023-10-23 14:40:10 -07:00
|
|
|
try_fmt->width = crop->width >> half_scale;
|
|
|
|
try_fmt->height = crop->height >> half_scale;
|
|
|
|
try_fmt->code = mf->code;
|
2015-04-09 02:24:36 -07:00
|
|
|
|
media: ov6650: Fix some format attributes not under control
User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values. The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support"). Fix it.
Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with resulting
pad config format code and frame size.
Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-09-03 13:11:40 -07:00
|
|
|
/* return default mbus frame format updated with pad config */
|
|
|
|
*mf = ov6650_def_fmt;
|
2023-10-23 14:40:10 -07:00
|
|
|
mf->width = try_fmt->width;
|
|
|
|
mf->height = try_fmt->height;
|
|
|
|
mf->code = try_fmt->code;
|
media: ov6650: Fix some format attributes not under control
User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values. The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support"). Fix it.
Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with resulting
pad config format code and frame size.
Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-09-03 13:11:40 -07:00
|
|
|
|
|
|
|
} else {
|
2020-05-03 15:06:18 -07:00
|
|
|
int ret = 0;
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
|
|
|
|
/* apply new media bus frame format and scaling if changed */
|
|
|
|
if (mf->code != priv->code || half_scale != priv->half_scale)
|
|
|
|
ret = ov6650_s_fmt(sd, mf->code, half_scale);
|
media: ov6650: Fix some format attributes not under control
User arguments passed to .get/set_fmt() pad operation callbacks may
contain unsupported values. The driver takes control over frame size
and pixel code as well as colorspace and field attributes but has never
cared for remainig format attributes, i.e., ycbcr_enc, quantization
and xfer_func, introduced by commit 11ff030c7365 ("[media]
v4l2-mediabus: improve colorspace support"). Fix it.
Set up a static v4l2_mbus_framefmt structure with attributes
initialized to reasonable defaults and use it for updating content of
user provided arguments. In case of V4L2_SUBDEV_FORMAT_ACTIVE,
postpone frame size update, now performed from inside ov6650_s_fmt()
helper, util the user argument is first updated in ov6650_set_fmt() with
default frame format content. For V4L2_SUBDEV_FORMAT_TRY, don't copy
all attributes to pad config, only those handled by the driver, then
fill the response with the default frame format updated with resulting
pad config format code and frame size.
Fixes: 11ff030c7365 ("[media] v4l2-mediabus: improve colorspace support")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-09-03 13:11:40 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* return default format updated with active size and code */
|
|
|
|
*mf = ov6650_def_fmt;
|
|
|
|
mf->width = priv->rect.width >> priv->half_scale;
|
|
|
|
mf->height = priv->rect.height >> priv->half_scale;
|
|
|
|
mf->code = priv->code;
|
|
|
|
}
|
2010-10-05 07:52:45 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 00:01:33 -07:00
|
|
|
static int ov6650_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 07:55:58 -07:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2015-04-09 00:01:33 -07:00
|
|
|
struct v4l2_subdev_mbus_code_enum *code)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
2015-04-09 00:01:33 -07:00
|
|
|
if (code->pad || code->index >= ARRAY_SIZE(ov6650_codes))
|
2010-10-05 07:52:45 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2015-04-09 00:01:33 -07:00
|
|
|
code->code = ov6650_codes[code->index];
|
2010-10-05 07:52:45 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-04 10:10:12 -07:00
|
|
|
static int ov6650_enum_frame_interval(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_frame_interval_enum *fie)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* enumerate supported frame intervals not exceeding 1 second */
|
|
|
|
if (fie->index > CLKRC_DIV_MASK ||
|
|
|
|
GET_CLKRC_DIV(fie->index) > FRAME_RATE_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ov6650_codes); i++)
|
|
|
|
if (fie->code == ov6650_codes[i])
|
|
|
|
break;
|
|
|
|
if (i == ARRAY_SIZE(ov6650_codes))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!fie->width || fie->width > W_CIF ||
|
|
|
|
!fie->height || fie->height > H_CIF)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
fie->interval.numerator = GET_CLKRC_DIV(fie->index);
|
|
|
|
fie->interval.denominator = FRAME_RATE_MAX;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-12-13 08:00:04 -07:00
|
|
|
static int ov6650_get_frame_interval(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_frame_interval *ival)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
|
2023-12-13 08:00:05 -07:00
|
|
|
/*
|
|
|
|
* FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
|
|
|
|
* subdev active state API.
|
|
|
|
*/
|
|
|
|
if (ival->which != V4L2_SUBDEV_FORMAT_ACTIVE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-10-13 05:50:47 -07:00
|
|
|
ival->interval = priv->tpf;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev, "Frame interval: %u/%u s\n",
|
2018-01-22 02:00:45 -07:00
|
|
|
ival->interval.numerator, ival->interval.denominator);
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-12-13 08:00:04 -07:00
|
|
|
static int ov6650_set_frame_interval(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_frame_interval *ival)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
2018-01-22 02:00:45 -07:00
|
|
|
struct v4l2_fract *tpf = &ival->interval;
|
2010-10-05 07:52:45 -07:00
|
|
|
int div, ret;
|
|
|
|
|
2023-12-13 08:00:05 -07:00
|
|
|
/*
|
|
|
|
* FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2
|
|
|
|
* subdev active state API.
|
|
|
|
*/
|
|
|
|
if (ival->which != V4L2_SUBDEV_FORMAT_ACTIVE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-05 07:52:45 -07:00
|
|
|
if (tpf->numerator == 0 || tpf->denominator == 0)
|
|
|
|
div = 1; /* Reset to full rate */
|
|
|
|
else
|
|
|
|
div = (tpf->numerator * FRAME_RATE_MAX) / tpf->denominator;
|
|
|
|
|
|
|
|
if (div == 0)
|
|
|
|
div = 1;
|
|
|
|
else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK))
|
|
|
|
div = GET_CLKRC_DIV(CLKRC_DIV_MASK);
|
|
|
|
|
2019-10-13 05:50:47 -07:00
|
|
|
ret = ov6650_reg_rmw(client, REG_CLKRC, to_clkrc(div), CLKRC_DIV_MASK);
|
2010-10-05 07:52:45 -07:00
|
|
|
if (!ret) {
|
2019-10-13 05:50:47 -07:00
|
|
|
priv->tpf.numerator = div;
|
2019-10-13 05:50:45 -07:00
|
|
|
priv->tpf.denominator = FRAME_RATE_MAX;
|
|
|
|
|
|
|
|
*tpf = priv->tpf;
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Soft reset the camera. This has nothing to do with the RESET pin! */
|
|
|
|
static int ov6650_reset(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "reset\n");
|
|
|
|
|
|
|
|
ret = ov6650_reg_rmw(client, REG_COMA, COMA_RESET, 0);
|
|
|
|
if (ret)
|
|
|
|
dev_err(&client->dev,
|
2011-03-30 18:57:33 -07:00
|
|
|
"An error occurred while entering soft reset!\n");
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* program default register values */
|
2019-10-13 05:50:50 -07:00
|
|
|
static int ov6650_prog_dflt(struct i2c_client *client, u8 clkrc)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "initializing\n");
|
|
|
|
|
|
|
|
ret = ov6650_reg_write(client, REG_COMA, 0); /* ~COMA_RESET */
|
2019-10-13 05:50:48 -07:00
|
|
|
if (!ret)
|
2019-10-13 05:50:50 -07:00
|
|
|
ret = ov6650_reg_write(client, REG_CLKRC, clkrc);
|
2010-10-05 07:52:45 -07:00
|
|
|
if (!ret)
|
|
|
|
ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_BAND_FILTER);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-29 18:06:10 -07:00
|
|
|
static int ov6650_video_probe(struct v4l2_subdev *sd)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
2019-03-29 18:06:10 -07:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
2012-07-18 06:54:04 -07:00
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
2019-10-13 05:50:50 -07:00
|
|
|
const struct ov6650_xclk *xclk = NULL;
|
|
|
|
unsigned long rate;
|
|
|
|
u8 pidh, pidl, midh, midl;
|
2019-11-03 04:23:37 -07:00
|
|
|
int i, ret = 0;
|
2012-07-18 06:54:04 -07:00
|
|
|
|
2021-01-12 12:49:18 -07:00
|
|
|
priv->clk = devm_clk_get(&client->dev, NULL);
|
2019-03-29 18:06:09 -07:00
|
|
|
if (IS_ERR(priv->clk)) {
|
|
|
|
ret = PTR_ERR(priv->clk);
|
2021-01-12 12:49:18 -07:00
|
|
|
dev_err(&client->dev, "clk request err: %d\n", ret);
|
2019-03-29 18:06:09 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-12 12:49:18 -07:00
|
|
|
rate = clk_get_rate(priv->clk);
|
2019-10-13 05:50:50 -07:00
|
|
|
for (i = 0; rate && i < ARRAY_SIZE(ov6650_xclk); i++) {
|
|
|
|
if (rate != ov6650_xclk[i].rate)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
xclk = &ov6650_xclk[i];
|
|
|
|
dev_info(&client->dev, "using host default clock rate %lukHz\n",
|
|
|
|
rate / 1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; !xclk && i < ARRAY_SIZE(ov6650_xclk); i++) {
|
2021-01-12 12:49:18 -07:00
|
|
|
ret = clk_set_rate(priv->clk, ov6650_xclk[i].rate);
|
|
|
|
if (ret || clk_get_rate(priv->clk) != ov6650_xclk[i].rate)
|
2019-10-13 05:50:50 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
xclk = &ov6650_xclk[i];
|
|
|
|
dev_info(&client->dev, "using negotiated clock rate %lukHz\n",
|
|
|
|
xclk->rate / 1000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!xclk) {
|
|
|
|
dev_err(&client->dev, "unable to get supported clock rate\n");
|
|
|
|
if (!ret)
|
|
|
|
ret = -EINVAL;
|
2021-01-12 12:49:18 -07:00
|
|
|
return ret;
|
2019-10-13 05:50:50 -07:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:06:10 -07:00
|
|
|
ret = ov6650_s_power(sd, 1);
|
2012-07-18 06:54:04 -07:00
|
|
|
if (ret < 0)
|
2021-01-12 12:49:18 -07:00
|
|
|
return ret;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2019-03-24 17:21:12 -07:00
|
|
|
msleep(20);
|
|
|
|
|
2010-10-05 07:52:45 -07:00
|
|
|
/*
|
|
|
|
* check and show product ID and manufacturer ID
|
|
|
|
*/
|
|
|
|
ret = ov6650_reg_read(client, REG_PIDH, &pidh);
|
|
|
|
if (!ret)
|
|
|
|
ret = ov6650_reg_read(client, REG_PIDL, &pidl);
|
|
|
|
if (!ret)
|
|
|
|
ret = ov6650_reg_read(client, REG_MIDH, &midh);
|
|
|
|
if (!ret)
|
|
|
|
ret = ov6650_reg_read(client, REG_MIDL, &midl);
|
|
|
|
|
|
|
|
if (ret)
|
2012-07-18 06:54:04 -07:00
|
|
|
goto done;
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
if ((pidh != OV6650_PIDH) || (pidl != OV6650_PIDL)) {
|
|
|
|
dev_err(&client->dev, "Product ID error 0x%02x:0x%02x\n",
|
|
|
|
pidh, pidl);
|
2012-07-18 06:54:04 -07:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(&client->dev,
|
|
|
|
"ov6650 Product ID 0x%02x:0x%02x Manufacturer ID 0x%02x:0x%02x\n",
|
|
|
|
pidh, pidl, midh, midl);
|
|
|
|
|
|
|
|
ret = ov6650_reset(client);
|
|
|
|
if (!ret)
|
2019-10-13 05:50:50 -07:00
|
|
|
ret = ov6650_prog_dflt(client, xclk->clkrc);
|
2019-09-03 13:11:42 -07:00
|
|
|
if (!ret) {
|
media: ov6650: Fix set format try processing path
According to subdevice interface specification found in V4L2 API
documentation, set format pad operations should not affect image
geometry set in preceding image processing steps. Unfortunately, that
requirement is not respected by the driver implementation of set format
as it was not the case when that code was still implementing a pair of
now obsolete .s_mbus_fmt() / .try_mbus_fmt() video operations before
they have been merged and reused as an implementation of .set_fmt() pad
operation by commit 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt
by set_fmt").
In case of set format active processing path the issue can be fixed
easily by excluding a call to set active selection from that path. That
will effectively limit frame size processing to optimal frame scaling
against active crop rectangle without touching it. Users can just call
set active selection themselves to obtain desired frame size. However,
set format try processing path needs more work.
First of all, the driver should be extended with set try selection
support. Lack of it constraints video device drivers to not use
subdevice cropping at all while processing user requested active frame
size, otherwise their set try format results might differ from active.
Next, set format try processing path should use pad config crop
rectangle as a reference, not the active one as it does now. That
issue can be resolved easily as soon as set try selection support is
added to the driver so pad config crop rectangle can be maintained by
users via selection API.
Last, set format try processing path should give the same results as
active in respect to active vs. pad config crop rectangle geometry.
Both rectangles should be either not touched by set format (that's what
we are going to achieve) or modified the same way, otherwise users
won't be able to obtain equal results from both paths while iterating
through set format and set selection operations in order to obtain
desired frame size.
We can't begin with modifying set format pad operation as not to touch
crop rectangle since that depends on availability of set try selection
for symmetry. Neither can we begin with adding set try selection since
that in turn depends on equal handling of active and pad config crop
rectangles by set format. We can either implement all required
modifications in a single patch, or begin with fixing current set
format try processing path to appropriately handle pad config crop
rectangle. This patch implements the latter approach as believed to
be more readable.
Move crop rectangle adjustments code from a helper (the former
implementation of .s_fmt(), now called from set format active
processing path) to the body of set format pad operation function
where it can be also used for processing try requests for symmetry with
active ones. As the helper no longer processes frame geometry, only
frame format and half scaling, simplify its API accordingly and update
its users.
Moreover, extract code that applies crop rectangle hardware limits
(now a part of .set_selection() operation which is called from set
format active processing path) to a new helper and call that helper
from set format try processing path as well for symmetry with active.
[Sakari Ailus: Rebase on subdev state patches]
Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt")
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2020-05-03 15:06:16 -07:00
|
|
|
/* driver default frame format, no scaling */
|
|
|
|
ret = ov6650_s_fmt(sd, ov6650_def_fmt.code, false);
|
2019-09-03 13:11:42 -07:00
|
|
|
}
|
2012-07-18 06:54:04 -07:00
|
|
|
if (!ret)
|
|
|
|
ret = v4l2_ctrl_handler_setup(&priv->hdl);
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2012-07-18 06:54:04 -07:00
|
|
|
done:
|
2019-03-29 18:06:10 -07:00
|
|
|
ov6650_s_power(sd, 0);
|
2010-10-05 07:52:45 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-12 05:52:01 -07:00
|
|
|
static const struct v4l2_ctrl_ops ov6550_ctrl_ops = {
|
|
|
|
.g_volatile_ctrl = ov6550_g_volatile_ctrl,
|
|
|
|
.s_ctrl = ov6550_s_ctrl,
|
2010-10-05 07:52:45 -07:00
|
|
|
};
|
|
|
|
|
2016-12-12 06:59:42 -07:00
|
|
|
static const struct v4l2_subdev_core_ops ov6650_core_ops = {
|
2010-10-05 07:52:45 -07:00
|
|
|
#ifdef CONFIG_VIDEO_ADV_DEBUG
|
|
|
|
.g_register = ov6650_get_register,
|
|
|
|
.s_register = ov6650_set_register,
|
|
|
|
#endif
|
2012-07-20 06:19:50 -07:00
|
|
|
.s_power = ov6650_s_power,
|
2010-10-05 07:52:45 -07:00
|
|
|
};
|
|
|
|
|
2011-07-28 10:42:25 -07:00
|
|
|
/* Request bus settings on camera side */
|
2020-07-21 00:53:17 -07:00
|
|
|
static int ov6650_get_mbus_config(struct v4l2_subdev *sd,
|
|
|
|
unsigned int pad,
|
|
|
|
struct v4l2_mbus_config *cfg)
|
2011-07-26 08:02:00 -07:00
|
|
|
{
|
2020-07-21 00:53:17 -07:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
u8 comj, comf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ov6650_reg_read(client, REG_COMJ, &comj);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-07-26 08:02:00 -07:00
|
|
|
|
2020-07-21 00:53:17 -07:00
|
|
|
ret = ov6650_reg_read(client, REG_COMF, &comf);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-07-26 08:02:00 -07:00
|
|
|
cfg->type = V4L2_MBUS_PARALLEL;
|
|
|
|
|
2022-01-03 09:24:11 -07:00
|
|
|
cfg->bus.parallel.flags = V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH
|
|
|
|
| ((comj & COMJ_VSYNC_HIGH) ? V4L2_MBUS_VSYNC_ACTIVE_HIGH
|
|
|
|
: V4L2_MBUS_VSYNC_ACTIVE_LOW)
|
|
|
|
| ((comf & COMF_HREF_LOW) ? V4L2_MBUS_HSYNC_ACTIVE_LOW
|
|
|
|
: V4L2_MBUS_HSYNC_ACTIVE_HIGH)
|
|
|
|
| ((comj & COMJ_PCLK_RISING) ? V4L2_MBUS_PCLK_SAMPLE_RISING
|
|
|
|
: V4L2_MBUS_PCLK_SAMPLE_FALLING);
|
2011-07-26 08:02:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-12 06:59:42 -07:00
|
|
|
static const struct v4l2_subdev_video_ops ov6650_video_ops = {
|
2010-10-05 07:52:45 -07:00
|
|
|
.s_stream = ov6650_s_stream,
|
|
|
|
};
|
|
|
|
|
2015-04-09 00:01:33 -07:00
|
|
|
static const struct v4l2_subdev_pad_ops ov6650_pad_ops = {
|
2020-05-04 10:10:12 -07:00
|
|
|
.enum_mbus_code = ov6650_enum_mbus_code,
|
|
|
|
.enum_frame_interval = ov6650_enum_frame_interval,
|
|
|
|
.get_selection = ov6650_get_selection,
|
|
|
|
.set_selection = ov6650_set_selection,
|
|
|
|
.get_fmt = ov6650_get_fmt,
|
|
|
|
.set_fmt = ov6650_set_fmt,
|
2023-12-13 08:00:04 -07:00
|
|
|
.get_frame_interval = ov6650_get_frame_interval,
|
|
|
|
.set_frame_interval = ov6650_set_frame_interval,
|
2020-05-04 10:10:12 -07:00
|
|
|
.get_mbus_config = ov6650_get_mbus_config,
|
2015-04-09 00:01:33 -07:00
|
|
|
};
|
|
|
|
|
2016-12-12 06:59:42 -07:00
|
|
|
static const struct v4l2_subdev_ops ov6650_subdev_ops = {
|
2010-10-05 07:52:45 -07:00
|
|
|
.core = &ov6650_core_ops,
|
|
|
|
.video = &ov6650_video_ops,
|
2015-04-09 00:01:33 -07:00
|
|
|
.pad = &ov6650_pad_ops,
|
2010-10-05 07:52:45 -07:00
|
|
|
};
|
|
|
|
|
2019-03-29 18:06:10 -07:00
|
|
|
static const struct v4l2_subdev_internal_ops ov6650_internal_ops = {
|
|
|
|
.registered = ov6650_video_probe,
|
|
|
|
};
|
|
|
|
|
2010-10-05 07:52:45 -07:00
|
|
|
/*
|
|
|
|
* i2c_driver function
|
|
|
|
*/
|
2022-11-18 15:41:32 -07:00
|
|
|
static int ov6650_probe(struct i2c_client *client)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct ov6650 *priv;
|
|
|
|
int ret;
|
|
|
|
|
2012-12-21 06:28:43 -07:00
|
|
|
priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
|
2017-09-02 07:07:31 -07:00
|
|
|
if (!priv)
|
2010-10-05 07:52:45 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops);
|
2011-09-12 05:52:01 -07:00
|
|
|
v4l2_ctrl_handler_init(&priv->hdl, 13);
|
|
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_VFLIP, 0, 1, 1, 0);
|
|
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_HFLIP, 0, 1, 1, 0);
|
|
|
|
priv->autogain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
|
|
|
|
priv->gain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_GAIN, 0, 0x3f, 1, DEF_GAIN);
|
|
|
|
priv->autowb = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
|
|
|
|
priv->blue = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_BLUE_BALANCE, 0, 0xff, 1, DEF_BLUE);
|
|
|
|
priv->red = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_RED_BALANCE, 0, 0xff, 1, DEF_RED);
|
|
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_SATURATION, 0, 0xf, 1, 0x8);
|
|
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_HUE, 0, HUE_MASK, 1, DEF_HUE);
|
|
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_BRIGHTNESS, 0, 0xff, 1, 0x80);
|
|
|
|
priv->autoexposure = v4l2_ctrl_new_std_menu(&priv->hdl,
|
2011-09-12 04:25:25 -07:00
|
|
|
&ov6550_ctrl_ops, V4L2_CID_EXPOSURE_AUTO,
|
|
|
|
V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
|
2011-09-12 05:52:01 -07:00
|
|
|
priv->exposure = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_EXPOSURE, 0, 0xff, 1, DEF_AECH);
|
|
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
|
|
V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
|
|
|
|
|
|
|
|
priv->subdev.ctrl_handler = &priv->hdl;
|
2019-09-03 13:11:37 -07:00
|
|
|
if (priv->hdl.error) {
|
|
|
|
ret = priv->hdl.error;
|
|
|
|
goto ectlhdlfree;
|
|
|
|
}
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2011-09-12 05:52:01 -07:00
|
|
|
v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
|
|
|
|
v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
|
|
|
|
v4l2_ctrl_auto_cluster(2, &priv->autoexposure,
|
|
|
|
V4L2_EXPOSURE_MANUAL, true);
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
priv->rect.left = DEF_HSTRT << 1;
|
|
|
|
priv->rect.top = DEF_VSTRT << 1;
|
|
|
|
priv->rect.width = W_CIF;
|
|
|
|
priv->rect.height = H_CIF;
|
|
|
|
|
2019-10-13 05:50:45 -07:00
|
|
|
/* Hardware default frame interval */
|
|
|
|
priv->tpf.numerator = GET_CLKRC_DIV(DEF_CLKRC);
|
|
|
|
priv->tpf.denominator = FRAME_RATE_MAX;
|
|
|
|
|
2019-03-29 18:06:10 -07:00
|
|
|
priv->subdev.internal_ops = &ov6650_internal_ops;
|
|
|
|
|
|
|
|
ret = v4l2_async_register_subdev(&priv->subdev);
|
2019-09-03 13:11:37 -07:00
|
|
|
if (!ret)
|
|
|
|
return 0;
|
|
|
|
ectlhdlfree:
|
|
|
|
v4l2_ctrl_handler_free(&priv->hdl);
|
2010-10-05 07:52:45 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-15 01:02:30 -07:00
|
|
|
static void ov6650_remove(struct i2c_client *client)
|
2010-10-05 07:52:45 -07:00
|
|
|
{
|
|
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
|
2019-03-29 18:06:10 -07:00
|
|
|
v4l2_async_unregister_subdev(&priv->subdev);
|
2011-09-12 05:52:01 -07:00
|
|
|
v4l2_ctrl_handler_free(&priv->hdl);
|
2010-10-05 07:52:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id ov6650_id[] = {
|
2024-05-08 06:20:42 -07:00
|
|
|
{ "ov6650" },
|
2010-10-05 07:52:45 -07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, ov6650_id);
|
|
|
|
|
|
|
|
static struct i2c_driver ov6650_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ov6650",
|
|
|
|
},
|
2023-05-14 05:04:07 -07:00
|
|
|
.probe = ov6650_probe,
|
2010-10-05 07:52:45 -07:00
|
|
|
.remove = ov6650_remove,
|
|
|
|
.id_table = ov6650_id,
|
|
|
|
};
|
|
|
|
|
2012-02-12 02:56:32 -07:00
|
|
|
module_i2c_driver(ov6650_i2c_driver);
|
2010-10-05 07:52:45 -07:00
|
|
|
|
2019-09-03 13:11:36 -07:00
|
|
|
MODULE_DESCRIPTION("V4L2 subdevice driver for OmniVision OV6650 camera sensor");
|
|
|
|
MODULE_AUTHOR("Janusz Krzysztofik <jmkrzyszt@gmail.com");
|
2010-10-05 07:52:45 -07:00
|
|
|
MODULE_LICENSE("GPL v2");
|