2019-10-05 00:05:25 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Sony IMX290 CMOS Image Sensor Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 FRAMOS GmbH.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Linaro Ltd.
|
|
|
|
* Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/module.h>
|
2023-07-15 01:47:08 +08:00
|
|
|
#include <linux/of.h>
|
2019-10-05 00:05:25 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/regulator/consumer.h>
|
2023-02-10 06:12:05 +08:00
|
|
|
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
#include <media/media-entity.h>
|
2023-06-27 20:51:06 +08:00
|
|
|
#include <media/v4l2-cci.h>
|
2019-10-05 00:05:25 +08:00
|
|
|
#include <media/v4l2-ctrls.h>
|
|
|
|
#include <media/v4l2-device.h>
|
2023-02-16 06:29:53 +08:00
|
|
|
#include <media/v4l2-event.h>
|
2019-10-05 00:05:25 +08:00
|
|
|
#include <media/v4l2-fwnode.h>
|
|
|
|
#include <media/v4l2-subdev.h>
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_STANDBY CCI_REG8(0x3000)
|
|
|
|
#define IMX290_REGHOLD CCI_REG8(0x3001)
|
|
|
|
#define IMX290_XMSTA CCI_REG8(0x3002)
|
|
|
|
#define IMX290_ADBIT CCI_REG8(0x3005)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_ADBIT_10BIT (0 << 0)
|
|
|
|
#define IMX290_ADBIT_12BIT (1 << 0)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_CTRL_07 CCI_REG8(0x3007)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_VREVERSE BIT(0)
|
|
|
|
#define IMX290_HREVERSE BIT(1)
|
|
|
|
#define IMX290_WINMODE_1080P (0 << 4)
|
|
|
|
#define IMX290_WINMODE_720P (1 << 4)
|
|
|
|
#define IMX290_WINMODE_CROP (4 << 4)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_FR_FDG_SEL CCI_REG8(0x3009)
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_BLKLEVEL CCI_REG16_LE(0x300a)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_GAIN CCI_REG8(0x3014)
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_VMAX CCI_REG24_LE(0x3018)
|
2023-02-16 06:29:58 +08:00
|
|
|
#define IMX290_VMAX_MAX 0x3ffff
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_HMAX CCI_REG16_LE(0x301c)
|
2023-02-16 06:29:57 +08:00
|
|
|
#define IMX290_HMAX_MAX 0xffff
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_SHS1 CCI_REG24_LE(0x3020)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_WINWV_OB CCI_REG8(0x303a)
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_WINPV CCI_REG16_LE(0x303c)
|
|
|
|
#define IMX290_WINWV CCI_REG16_LE(0x303e)
|
|
|
|
#define IMX290_WINPH CCI_REG16_LE(0x3040)
|
|
|
|
#define IMX290_WINWH CCI_REG16_LE(0x3042)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_OUT_CTRL CCI_REG8(0x3046)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_ODBIT_10BIT (0 << 0)
|
|
|
|
#define IMX290_ODBIT_12BIT (1 << 0)
|
|
|
|
#define IMX290_OPORTSEL_PARALLEL (0x0 << 4)
|
|
|
|
#define IMX290_OPORTSEL_LVDS_2CH (0xd << 4)
|
|
|
|
#define IMX290_OPORTSEL_LVDS_4CH (0xe << 4)
|
|
|
|
#define IMX290_OPORTSEL_LVDS_8CH (0xf << 4)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_XSOUTSEL CCI_REG8(0x304b)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_XSOUTSEL_XVSOUTSEL_HIGH (0 << 0)
|
|
|
|
#define IMX290_XSOUTSEL_XVSOUTSEL_VSYNC (2 << 0)
|
|
|
|
#define IMX290_XSOUTSEL_XHSOUTSEL_HIGH (0 << 2)
|
|
|
|
#define IMX290_XSOUTSEL_XHSOUTSEL_HSYNC (2 << 2)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_INCKSEL1 CCI_REG8(0x305c)
|
|
|
|
#define IMX290_INCKSEL2 CCI_REG8(0x305d)
|
|
|
|
#define IMX290_INCKSEL3 CCI_REG8(0x305e)
|
|
|
|
#define IMX290_INCKSEL4 CCI_REG8(0x305f)
|
|
|
|
#define IMX290_PGCTRL CCI_REG8(0x308c)
|
|
|
|
#define IMX290_ADBIT1 CCI_REG8(0x3129)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_ADBIT1_10BIT 0x1d
|
|
|
|
#define IMX290_ADBIT1_12BIT 0x00
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_INCKSEL5 CCI_REG8(0x315e)
|
|
|
|
#define IMX290_INCKSEL6 CCI_REG8(0x3164)
|
|
|
|
#define IMX290_ADBIT2 CCI_REG8(0x317c)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_ADBIT2_10BIT 0x12
|
|
|
|
#define IMX290_ADBIT2_12BIT 0x00
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_CHIP_ID CCI_REG16_LE(0x319a)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_ADBIT3 CCI_REG8(0x31ec)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_ADBIT3_10BIT 0x37
|
|
|
|
#define IMX290_ADBIT3_12BIT 0x0e
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_REPETITION CCI_REG8(0x3405)
|
|
|
|
#define IMX290_PHY_LANE_NUM CCI_REG8(0x3407)
|
|
|
|
#define IMX290_OPB_SIZE_V CCI_REG8(0x3414)
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_Y_OUT_SIZE CCI_REG16_LE(0x3418)
|
|
|
|
#define IMX290_CSI_DT_FMT CCI_REG16_LE(0x3441)
|
2022-10-17 16:35:45 +08:00
|
|
|
#define IMX290_CSI_DT_FMT_RAW10 0x0a0a
|
|
|
|
#define IMX290_CSI_DT_FMT_RAW12 0x0c0c
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_CSI_LANE_MODE CCI_REG8(0x3443)
|
2023-11-02 17:50:48 +08:00
|
|
|
#define IMX290_EXTCK_FREQ CCI_REG16_LE(0x3444)
|
|
|
|
#define IMX290_TCLKPOST CCI_REG16_LE(0x3446)
|
|
|
|
#define IMX290_THSZERO CCI_REG16_LE(0x3448)
|
|
|
|
#define IMX290_THSPREPARE CCI_REG16_LE(0x344a)
|
|
|
|
#define IMX290_TCLKTRAIL CCI_REG16_LE(0x344c)
|
|
|
|
#define IMX290_THSTRAIL CCI_REG16_LE(0x344e)
|
|
|
|
#define IMX290_TCLKZERO CCI_REG16_LE(0x3450)
|
|
|
|
#define IMX290_TCLKPREPARE CCI_REG16_LE(0x3452)
|
|
|
|
#define IMX290_TLPX CCI_REG16_LE(0x3454)
|
|
|
|
#define IMX290_X_OUT_SIZE CCI_REG16_LE(0x3472)
|
2023-06-27 20:51:06 +08:00
|
|
|
#define IMX290_INCKSEL7 CCI_REG8(0x3480)
|
2022-10-16 14:15:11 +08:00
|
|
|
|
|
|
|
#define IMX290_PGCTRL_REGEN BIT(0)
|
|
|
|
#define IMX290_PGCTRL_THRU BIT(1)
|
|
|
|
#define IMX290_PGCTRL_MODE(n) ((n) << 4)
|
2020-06-12 21:53:51 +08:00
|
|
|
|
2023-02-16 06:29:58 +08:00
|
|
|
/* Number of lines by which exposure must be less than VMAX */
|
|
|
|
#define IMX290_EXPOSURE_OFFSET 2
|
|
|
|
|
2023-02-16 06:29:54 +08:00
|
|
|
#define IMX290_PIXEL_RATE 148500000
|
|
|
|
|
2022-10-16 14:15:22 +08:00
|
|
|
/*
|
|
|
|
* The IMX290 pixel array is organized as follows:
|
|
|
|
*
|
|
|
|
* +------------------------------------+
|
|
|
|
* | Optical Black | } Vertical effective optical black (10)
|
|
|
|
* +---+------------------------------------+---+
|
|
|
|
* | | | | } Effective top margin (8)
|
|
|
|
* | | +----------------------------+ | | \
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | Recording Pixel Area | | | | Recommended height (1080)
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | | | |
|
|
|
|
* | | +----------------------------+ | | /
|
|
|
|
* | | | | } Effective bottom margin (9)
|
|
|
|
* +---+------------------------------------+---+
|
|
|
|
* <-> <-> <--------------------------> <-> <->
|
|
|
|
* \---- Ignored right margin (4)
|
|
|
|
* \-------- Effective right margin (9)
|
|
|
|
* \------------------------- Recommended width (1920)
|
|
|
|
* \----------------------------------------- Effective left margin (8)
|
|
|
|
* \--------------------------------------------- Ignored left margin (4)
|
|
|
|
*
|
|
|
|
* The optical black lines are output over CSI-2 with a separate data type.
|
|
|
|
*
|
|
|
|
* The pixel array is meant to have 1920x1080 usable pixels after image
|
|
|
|
* processing in an ISP. It has 8 (9) extra active pixels usable for color
|
|
|
|
* processing in the ISP on the top and left (bottom and right) sides of the
|
|
|
|
* image. In addition, 4 additional pixels are present on the left and right
|
|
|
|
* sides of the image, documented as "ignored area".
|
|
|
|
*
|
|
|
|
* As far as is understood, all pixels of the pixel array (ignored area, color
|
|
|
|
* processing margins and recording area) can be output by the sensor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IMX290_PIXEL_ARRAY_WIDTH 1945
|
|
|
|
#define IMX290_PIXEL_ARRAY_HEIGHT 1097
|
2024-02-21 15:15:50 +08:00
|
|
|
#define IMX290_PIXEL_ARRAY_MARGIN_LEFT 12
|
|
|
|
#define IMX290_PIXEL_ARRAY_MARGIN_RIGHT 13
|
|
|
|
#define IMX290_PIXEL_ARRAY_MARGIN_TOP 8
|
|
|
|
#define IMX290_PIXEL_ARRAY_MARGIN_BOTTOM 9
|
2022-10-16 14:15:22 +08:00
|
|
|
#define IMX290_PIXEL_ARRAY_RECORDING_WIDTH 1920
|
|
|
|
#define IMX290_PIXEL_ARRAY_RECORDING_HEIGHT 1080
|
|
|
|
|
2023-01-16 22:44:44 +08:00
|
|
|
/* Equivalent value for 16bpp */
|
|
|
|
#define IMX290_BLACK_LEVEL_DEFAULT 3840
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
#define IMX290_NUM_SUPPLIES 3
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
enum imx290_colour_variant {
|
|
|
|
IMX290_VARIANT_COLOUR,
|
|
|
|
IMX290_VARIANT_MONO,
|
|
|
|
IMX290_VARIANT_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum imx290_model {
|
|
|
|
IMX290_MODEL_IMX290LQR,
|
|
|
|
IMX290_MODEL_IMX290LLR,
|
2023-02-17 17:52:21 +08:00
|
|
|
IMX290_MODEL_IMX327LQR,
|
2023-02-16 06:29:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct imx290_model_info {
|
|
|
|
enum imx290_colour_variant colour_variant;
|
2023-06-27 20:51:06 +08:00
|
|
|
const struct cci_reg_sequence *init_regs;
|
2023-02-17 17:52:21 +08:00
|
|
|
size_t init_regs_num;
|
|
|
|
const char *name;
|
2023-02-16 06:29:50 +08:00
|
|
|
};
|
|
|
|
|
2023-02-16 06:30:01 +08:00
|
|
|
enum imx290_clk_freq {
|
|
|
|
IMX290_CLK_37_125,
|
|
|
|
IMX290_CLK_74_25,
|
|
|
|
IMX290_NUM_CLK
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clock configuration for registers INCKSEL1 to INCKSEL6.
|
|
|
|
*/
|
|
|
|
struct imx290_clk_cfg {
|
|
|
|
u8 incksel1;
|
|
|
|
u8 incksel2;
|
|
|
|
u8 incksel3;
|
|
|
|
u8 incksel4;
|
|
|
|
u8 incksel5;
|
|
|
|
u8 incksel6;
|
|
|
|
};
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
struct imx290_mode {
|
|
|
|
u32 width;
|
|
|
|
u32 height;
|
2023-02-16 06:29:57 +08:00
|
|
|
u32 hmax_min;
|
2023-02-16 06:29:59 +08:00
|
|
|
u32 vmax_min;
|
2020-06-12 21:53:50 +08:00
|
|
|
u8 link_freq_index;
|
2023-02-16 06:30:02 +08:00
|
|
|
u8 ctrl_07;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
const struct cci_reg_sequence *data;
|
2019-10-05 00:05:25 +08:00
|
|
|
u32 data_size;
|
2023-02-16 06:30:01 +08:00
|
|
|
|
|
|
|
const struct imx290_clk_cfg *clk_cfg;
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-02-16 06:29:56 +08:00
|
|
|
struct imx290_csi_cfg {
|
|
|
|
u16 repetition;
|
|
|
|
u16 tclkpost;
|
|
|
|
u16 thszero;
|
|
|
|
u16 thsprepare;
|
|
|
|
u16 tclktrail;
|
|
|
|
u16 thstrail;
|
|
|
|
u16 tclkzero;
|
|
|
|
u16 tclkprepare;
|
|
|
|
u16 tlpx;
|
|
|
|
};
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
struct imx290 {
|
|
|
|
struct device *dev;
|
|
|
|
struct clk *xclk;
|
|
|
|
struct regmap *regmap;
|
2023-02-16 06:30:01 +08:00
|
|
|
enum imx290_clk_freq xclk_idx;
|
2020-06-12 21:53:49 +08:00
|
|
|
u8 nlanes;
|
2023-02-16 06:29:50 +08:00
|
|
|
const struct imx290_model_info *model;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
struct v4l2_subdev sd;
|
|
|
|
struct media_pad pad;
|
2022-10-17 18:44:27 +08:00
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
const struct imx290_mode *current_mode;
|
|
|
|
|
|
|
|
struct regulator_bulk_data supplies[IMX290_NUM_SUPPLIES];
|
|
|
|
struct gpio_desc *rst_gpio;
|
|
|
|
|
|
|
|
struct v4l2_ctrl_handler ctrls;
|
|
|
|
struct v4l2_ctrl *link_freq;
|
2022-10-16 14:15:18 +08:00
|
|
|
struct v4l2_ctrl *hblank;
|
|
|
|
struct v4l2_ctrl *vblank;
|
2023-02-16 06:29:58 +08:00
|
|
|
struct v4l2_ctrl *exposure;
|
2023-02-16 06:30:02 +08:00
|
|
|
struct {
|
|
|
|
struct v4l2_ctrl *hflip;
|
|
|
|
struct v4l2_ctrl *vflip;
|
|
|
|
};
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd)
|
|
|
|
{
|
|
|
|
return container_of(_sd, struct imx290, sd);
|
|
|
|
}
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Modes and formats
|
|
|
|
*/
|
2020-06-12 21:53:51 +08:00
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_global_init_settings[] = {
|
2022-10-17 16:35:45 +08:00
|
|
|
{ IMX290_WINWV_OB, 12 },
|
|
|
|
{ IMX290_WINPH, 0 },
|
|
|
|
{ IMX290_WINPV, 0 },
|
|
|
|
{ IMX290_WINWH, 1948 },
|
|
|
|
{ IMX290_WINWV, 1097 },
|
|
|
|
{ IMX290_XSOUTSEL, IMX290_XSOUTSEL_XVSOUTSEL_VSYNC |
|
|
|
|
IMX290_XSOUTSEL_XHSOUTSEL_HSYNC },
|
2023-06-27 20:51:06 +08:00
|
|
|
{ CCI_REG8(0x3011), 0x02 },
|
|
|
|
{ CCI_REG8(0x3012), 0x64 },
|
|
|
|
{ CCI_REG8(0x3013), 0x00 },
|
2023-02-17 17:52:21 +08:00
|
|
|
};
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_global_init_settings_290[] = {
|
|
|
|
{ CCI_REG8(0x300f), 0x00 },
|
|
|
|
{ CCI_REG8(0x3010), 0x21 },
|
|
|
|
{ CCI_REG8(0x3016), 0x09 },
|
|
|
|
{ CCI_REG8(0x3070), 0x02 },
|
|
|
|
{ CCI_REG8(0x3071), 0x11 },
|
|
|
|
{ CCI_REG8(0x309b), 0x10 },
|
|
|
|
{ CCI_REG8(0x309c), 0x22 },
|
|
|
|
{ CCI_REG8(0x30a2), 0x02 },
|
|
|
|
{ CCI_REG8(0x30a6), 0x20 },
|
|
|
|
{ CCI_REG8(0x30a8), 0x20 },
|
|
|
|
{ CCI_REG8(0x30aa), 0x20 },
|
|
|
|
{ CCI_REG8(0x30ac), 0x20 },
|
|
|
|
{ CCI_REG8(0x30b0), 0x43 },
|
|
|
|
{ CCI_REG8(0x3119), 0x9e },
|
|
|
|
{ CCI_REG8(0x311c), 0x1e },
|
|
|
|
{ CCI_REG8(0x311e), 0x08 },
|
|
|
|
{ CCI_REG8(0x3128), 0x05 },
|
|
|
|
{ CCI_REG8(0x313d), 0x83 },
|
|
|
|
{ CCI_REG8(0x3150), 0x03 },
|
|
|
|
{ CCI_REG8(0x317e), 0x00 },
|
|
|
|
{ CCI_REG8(0x32b8), 0x50 },
|
|
|
|
{ CCI_REG8(0x32b9), 0x10 },
|
|
|
|
{ CCI_REG8(0x32ba), 0x00 },
|
|
|
|
{ CCI_REG8(0x32bb), 0x04 },
|
|
|
|
{ CCI_REG8(0x32c8), 0x50 },
|
|
|
|
{ CCI_REG8(0x32c9), 0x10 },
|
|
|
|
{ CCI_REG8(0x32ca), 0x00 },
|
|
|
|
{ CCI_REG8(0x32cb), 0x04 },
|
|
|
|
{ CCI_REG8(0x332c), 0xd3 },
|
|
|
|
{ CCI_REG8(0x332d), 0x10 },
|
|
|
|
{ CCI_REG8(0x332e), 0x0d },
|
|
|
|
{ CCI_REG8(0x3358), 0x06 },
|
|
|
|
{ CCI_REG8(0x3359), 0xe1 },
|
|
|
|
{ CCI_REG8(0x335a), 0x11 },
|
|
|
|
{ CCI_REG8(0x3360), 0x1e },
|
|
|
|
{ CCI_REG8(0x3361), 0x61 },
|
|
|
|
{ CCI_REG8(0x3362), 0x10 },
|
|
|
|
{ CCI_REG8(0x33b0), 0x50 },
|
|
|
|
{ CCI_REG8(0x33b2), 0x1a },
|
|
|
|
{ CCI_REG8(0x33b3), 0x04 },
|
2023-02-16 06:30:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define IMX290_NUM_CLK_REGS 2
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence xclk_regs[][IMX290_NUM_CLK_REGS] = {
|
2023-02-16 06:30:01 +08:00
|
|
|
[IMX290_CLK_37_125] = {
|
|
|
|
{ IMX290_EXTCK_FREQ, (37125 * 256) / 1000 },
|
|
|
|
{ IMX290_INCKSEL7, 0x49 },
|
|
|
|
},
|
|
|
|
[IMX290_CLK_74_25] = {
|
|
|
|
{ IMX290_EXTCK_FREQ, (74250 * 256) / 1000 },
|
|
|
|
{ IMX290_INCKSEL7, 0x92 },
|
|
|
|
},
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_global_init_settings_327[] = {
|
|
|
|
{ CCI_REG8(0x309e), 0x4A },
|
|
|
|
{ CCI_REG8(0x309f), 0x4A },
|
|
|
|
{ CCI_REG8(0x313b), 0x61 },
|
2023-02-17 17:52:21 +08:00
|
|
|
};
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_1080p_settings[] = {
|
2019-10-05 00:05:25 +08:00
|
|
|
/* mode settings */
|
2022-10-17 16:35:45 +08:00
|
|
|
{ IMX290_WINWV_OB, 12 },
|
|
|
|
{ IMX290_OPB_SIZE_V, 10 },
|
|
|
|
{ IMX290_X_OUT_SIZE, 1920 },
|
|
|
|
{ IMX290_Y_OUT_SIZE, 1080 },
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_720p_settings[] = {
|
2019-10-05 00:05:25 +08:00
|
|
|
/* mode settings */
|
2022-10-17 16:35:45 +08:00
|
|
|
{ IMX290_WINWV_OB, 6 },
|
|
|
|
{ IMX290_OPB_SIZE_V, 4 },
|
|
|
|
{ IMX290_X_OUT_SIZE, 1280 },
|
|
|
|
{ IMX290_Y_OUT_SIZE, 720 },
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_10bit_settings[] = {
|
2022-10-17 16:35:45 +08:00
|
|
|
{ IMX290_ADBIT, IMX290_ADBIT_10BIT },
|
|
|
|
{ IMX290_OUT_CTRL, IMX290_ODBIT_10BIT },
|
|
|
|
{ IMX290_ADBIT1, IMX290_ADBIT1_10BIT },
|
|
|
|
{ IMX290_ADBIT2, IMX290_ADBIT2_10BIT },
|
|
|
|
{ IMX290_ADBIT3, IMX290_ADBIT3_10BIT },
|
|
|
|
{ IMX290_CSI_DT_FMT, IMX290_CSI_DT_FMT_RAW10 },
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
static const struct cci_reg_sequence imx290_12bit_settings[] = {
|
2022-10-17 16:35:45 +08:00
|
|
|
{ IMX290_ADBIT, IMX290_ADBIT_12BIT },
|
|
|
|
{ IMX290_OUT_CTRL, IMX290_ODBIT_12BIT },
|
|
|
|
{ IMX290_ADBIT1, IMX290_ADBIT1_12BIT },
|
|
|
|
{ IMX290_ADBIT2, IMX290_ADBIT2_12BIT },
|
|
|
|
{ IMX290_ADBIT3, IMX290_ADBIT3_12BIT },
|
|
|
|
{ IMX290_CSI_DT_FMT, IMX290_CSI_DT_FMT_RAW12 },
|
2020-06-12 21:53:52 +08:00
|
|
|
};
|
|
|
|
|
2023-02-16 06:29:56 +08:00
|
|
|
static const struct imx290_csi_cfg imx290_csi_222_75mhz = {
|
|
|
|
/* 222.75MHz or 445.5Mbit/s per lane */
|
|
|
|
.repetition = 0x10,
|
|
|
|
.tclkpost = 87,
|
|
|
|
.thszero = 55,
|
|
|
|
.thsprepare = 31,
|
|
|
|
.tclktrail = 31,
|
|
|
|
.thstrail = 31,
|
|
|
|
.tclkzero = 119,
|
|
|
|
.tclkprepare = 31,
|
|
|
|
.tlpx = 23,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct imx290_csi_cfg imx290_csi_445_5mhz = {
|
|
|
|
/* 445.5MHz or 891Mbit/s per lane */
|
|
|
|
.repetition = 0x00,
|
|
|
|
.tclkpost = 119,
|
|
|
|
.thszero = 103,
|
|
|
|
.thsprepare = 71,
|
|
|
|
.tclktrail = 55,
|
|
|
|
.thstrail = 63,
|
|
|
|
.tclkzero = 255,
|
|
|
|
.tclkprepare = 63,
|
|
|
|
.tlpx = 55,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct imx290_csi_cfg imx290_csi_148_5mhz = {
|
|
|
|
/* 148.5MHz or 297Mbit/s per lane */
|
|
|
|
.repetition = 0x10,
|
|
|
|
.tclkpost = 79,
|
|
|
|
.thszero = 47,
|
|
|
|
.thsprepare = 23,
|
|
|
|
.tclktrail = 23,
|
|
|
|
.thstrail = 23,
|
|
|
|
.tclkzero = 87,
|
|
|
|
.tclkprepare = 23,
|
|
|
|
.tlpx = 23,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct imx290_csi_cfg imx290_csi_297mhz = {
|
|
|
|
/* 297MHz or 594Mbit/s per lane */
|
|
|
|
.repetition = 0x00,
|
|
|
|
.tclkpost = 103,
|
|
|
|
.thszero = 87,
|
|
|
|
.thsprepare = 47,
|
|
|
|
.tclktrail = 39,
|
|
|
|
.thstrail = 47,
|
|
|
|
.tclkzero = 191,
|
|
|
|
.tclkprepare = 47,
|
|
|
|
.tlpx = 39,
|
|
|
|
};
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
/* supported link frequencies */
|
2020-06-12 21:53:50 +08:00
|
|
|
#define FREQ_INDEX_1080P 0
|
|
|
|
#define FREQ_INDEX_720P 1
|
|
|
|
static const s64 imx290_link_freq_2lanes[] = {
|
|
|
|
[FREQ_INDEX_1080P] = 445500000,
|
|
|
|
[FREQ_INDEX_720P] = 297000000,
|
|
|
|
};
|
2023-02-16 06:29:51 +08:00
|
|
|
|
2020-06-12 21:53:50 +08:00
|
|
|
static const s64 imx290_link_freq_4lanes[] = {
|
|
|
|
[FREQ_INDEX_1080P] = 222750000,
|
|
|
|
[FREQ_INDEX_720P] = 148500000,
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2020-06-12 21:53:50 +08:00
|
|
|
/*
|
|
|
|
* In this function and in the similar ones below We rely on imx290_probe()
|
|
|
|
* to ensure that nlanes is either 2 or 4.
|
|
|
|
*/
|
|
|
|
static inline const s64 *imx290_link_freqs_ptr(const struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
if (imx290->nlanes == 2)
|
|
|
|
return imx290_link_freq_2lanes;
|
|
|
|
else
|
|
|
|
return imx290_link_freq_4lanes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int imx290_link_freqs_num(const struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
if (imx290->nlanes == 2)
|
|
|
|
return ARRAY_SIZE(imx290_link_freq_2lanes);
|
|
|
|
else
|
|
|
|
return ARRAY_SIZE(imx290_link_freq_4lanes);
|
|
|
|
}
|
|
|
|
|
2023-02-16 06:30:01 +08:00
|
|
|
static const struct imx290_clk_cfg imx290_1080p_clock_config[] = {
|
|
|
|
[IMX290_CLK_37_125] = {
|
|
|
|
/* 37.125MHz clock config */
|
|
|
|
.incksel1 = 0x18,
|
|
|
|
.incksel2 = 0x03,
|
|
|
|
.incksel3 = 0x20,
|
|
|
|
.incksel4 = 0x01,
|
|
|
|
.incksel5 = 0x1a,
|
|
|
|
.incksel6 = 0x1a,
|
|
|
|
},
|
|
|
|
[IMX290_CLK_74_25] = {
|
|
|
|
/* 74.25MHz clock config */
|
|
|
|
.incksel1 = 0x0c,
|
|
|
|
.incksel2 = 0x03,
|
|
|
|
.incksel3 = 0x10,
|
|
|
|
.incksel4 = 0x01,
|
|
|
|
.incksel5 = 0x1b,
|
|
|
|
.incksel6 = 0x1b,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct imx290_clk_cfg imx290_720p_clock_config[] = {
|
|
|
|
[IMX290_CLK_37_125] = {
|
|
|
|
/* 37.125MHz clock config */
|
|
|
|
.incksel1 = 0x20,
|
|
|
|
.incksel2 = 0x00,
|
|
|
|
.incksel3 = 0x20,
|
|
|
|
.incksel4 = 0x01,
|
|
|
|
.incksel5 = 0x1a,
|
|
|
|
.incksel6 = 0x1a,
|
|
|
|
},
|
|
|
|
[IMX290_CLK_74_25] = {
|
|
|
|
/* 74.25MHz clock config */
|
|
|
|
.incksel1 = 0x10,
|
|
|
|
.incksel2 = 0x00,
|
|
|
|
.incksel3 = 0x10,
|
|
|
|
.incksel4 = 0x01,
|
|
|
|
.incksel5 = 0x1b,
|
|
|
|
.incksel6 = 0x1b,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
/* Mode configs */
|
2020-06-12 21:53:49 +08:00
|
|
|
static const struct imx290_mode imx290_modes_2lanes[] = {
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
|
|
|
.width = 1920,
|
|
|
|
.height = 1080,
|
2023-02-16 06:29:57 +08:00
|
|
|
.hmax_min = 2200,
|
2023-02-16 06:29:59 +08:00
|
|
|
.vmax_min = 1125,
|
2020-06-12 21:53:50 +08:00
|
|
|
.link_freq_index = FREQ_INDEX_1080P,
|
2023-02-16 06:30:02 +08:00
|
|
|
.ctrl_07 = IMX290_WINMODE_1080P,
|
2019-10-05 00:05:25 +08:00
|
|
|
.data = imx290_1080p_settings,
|
|
|
|
.data_size = ARRAY_SIZE(imx290_1080p_settings),
|
2023-02-16 06:30:01 +08:00
|
|
|
.clk_cfg = imx290_1080p_clock_config,
|
2019-10-05 00:05:25 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.width = 1280,
|
|
|
|
.height = 720,
|
2023-02-16 06:29:57 +08:00
|
|
|
.hmax_min = 3300,
|
2023-02-16 06:29:59 +08:00
|
|
|
.vmax_min = 750,
|
2020-06-12 21:53:50 +08:00
|
|
|
.link_freq_index = FREQ_INDEX_720P,
|
2023-02-16 06:30:02 +08:00
|
|
|
.ctrl_07 = IMX290_WINMODE_720P,
|
2019-10-05 00:05:25 +08:00
|
|
|
.data = imx290_720p_settings,
|
|
|
|
.data_size = ARRAY_SIZE(imx290_720p_settings),
|
2023-02-16 06:30:01 +08:00
|
|
|
.clk_cfg = imx290_720p_clock_config,
|
2019-10-05 00:05:25 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-06-12 21:53:49 +08:00
|
|
|
static const struct imx290_mode imx290_modes_4lanes[] = {
|
|
|
|
{
|
|
|
|
.width = 1920,
|
|
|
|
.height = 1080,
|
2023-02-16 06:29:57 +08:00
|
|
|
.hmax_min = 2200,
|
2023-02-16 06:29:59 +08:00
|
|
|
.vmax_min = 1125,
|
2020-06-12 21:53:50 +08:00
|
|
|
.link_freq_index = FREQ_INDEX_1080P,
|
2023-02-16 06:30:02 +08:00
|
|
|
.ctrl_07 = IMX290_WINMODE_1080P,
|
2020-06-12 21:53:49 +08:00
|
|
|
.data = imx290_1080p_settings,
|
|
|
|
.data_size = ARRAY_SIZE(imx290_1080p_settings),
|
2023-02-16 06:30:01 +08:00
|
|
|
.clk_cfg = imx290_1080p_clock_config,
|
2020-06-12 21:53:49 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.width = 1280,
|
|
|
|
.height = 720,
|
2023-02-16 06:29:57 +08:00
|
|
|
.hmax_min = 3300,
|
2023-02-16 06:29:59 +08:00
|
|
|
.vmax_min = 750,
|
2020-06-12 21:53:50 +08:00
|
|
|
.link_freq_index = FREQ_INDEX_720P,
|
2023-02-16 06:30:02 +08:00
|
|
|
.ctrl_07 = IMX290_WINMODE_720P,
|
2020-06-12 21:53:49 +08:00
|
|
|
.data = imx290_720p_settings,
|
|
|
|
.data_size = ARRAY_SIZE(imx290_720p_settings),
|
2023-02-16 06:30:01 +08:00
|
|
|
.clk_cfg = imx290_720p_clock_config,
|
2020-06-12 21:53:49 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const struct imx290_mode *imx290_modes_ptr(const struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
if (imx290->nlanes == 2)
|
|
|
|
return imx290_modes_2lanes;
|
|
|
|
else
|
|
|
|
return imx290_modes_4lanes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int imx290_modes_num(const struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
if (imx290->nlanes == 2)
|
|
|
|
return ARRAY_SIZE(imx290_modes_2lanes);
|
|
|
|
else
|
|
|
|
return ARRAY_SIZE(imx290_modes_4lanes);
|
|
|
|
}
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
struct imx290_format_info {
|
2023-02-16 06:29:50 +08:00
|
|
|
u32 code[IMX290_VARIANT_MAX];
|
2023-01-16 22:44:38 +08:00
|
|
|
u8 bpp;
|
2023-06-27 20:51:06 +08:00
|
|
|
const struct cci_reg_sequence *regs;
|
2022-10-17 18:44:27 +08:00
|
|
|
unsigned int num_regs;
|
2023-01-16 22:44:38 +08:00
|
|
|
};
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
static const struct imx290_format_info imx290_formats[] = {
|
|
|
|
{
|
2023-02-16 06:29:50 +08:00
|
|
|
.code = {
|
|
|
|
[IMX290_VARIANT_COLOUR] = MEDIA_BUS_FMT_SRGGB10_1X10,
|
|
|
|
[IMX290_VARIANT_MONO] = MEDIA_BUS_FMT_Y10_1X10
|
|
|
|
},
|
2022-10-17 18:44:27 +08:00
|
|
|
.bpp = 10,
|
|
|
|
.regs = imx290_10bit_settings,
|
|
|
|
.num_regs = ARRAY_SIZE(imx290_10bit_settings),
|
|
|
|
}, {
|
2023-02-16 06:29:50 +08:00
|
|
|
.code = {
|
|
|
|
[IMX290_VARIANT_COLOUR] = MEDIA_BUS_FMT_SRGGB12_1X12,
|
|
|
|
[IMX290_VARIANT_MONO] = MEDIA_BUS_FMT_Y12_1X12
|
|
|
|
},
|
2022-10-17 18:44:27 +08:00
|
|
|
.bpp = 12,
|
|
|
|
.regs = imx290_12bit_settings,
|
|
|
|
.num_regs = ARRAY_SIZE(imx290_12bit_settings),
|
|
|
|
}
|
2023-01-16 22:44:38 +08:00
|
|
|
};
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
static const struct imx290_format_info *
|
|
|
|
imx290_format_info(const struct imx290 *imx290, u32 code)
|
2022-10-17 18:44:27 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(imx290_formats); ++i) {
|
|
|
|
const struct imx290_format_info *info = &imx290_formats[i];
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
if (info->code[imx290->model->colour_variant] == code)
|
2022-10-17 18:44:27 +08:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
static int imx290_set_register_array(struct imx290 *imx290,
|
2023-06-27 20:51:06 +08:00
|
|
|
const struct cci_reg_sequence *settings,
|
2019-10-05 00:05:25 +08:00
|
|
|
unsigned int num_settings)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
ret = cci_multi_reg_write(imx290->regmap, settings, num_settings, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2020-06-12 21:53:54 +08:00
|
|
|
/* Provide 10ms settle time */
|
2020-06-24 00:52:26 +08:00
|
|
|
usleep_range(10000, 11000);
|
2020-06-12 21:53:54 +08:00
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-16 06:30:01 +08:00
|
|
|
static int imx290_set_clock(struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
const struct imx290_mode *mode = imx290->current_mode;
|
|
|
|
enum imx290_clk_freq clk_idx = imx290->xclk_idx;
|
|
|
|
const struct imx290_clk_cfg *clk_cfg = &mode->clk_cfg[clk_idx];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = imx290_set_register_array(imx290, xclk_regs[clk_idx],
|
|
|
|
IMX290_NUM_CLK_REGS);
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_INCKSEL1, clk_cfg->incksel1, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_INCKSEL2, clk_cfg->incksel2, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_INCKSEL3, clk_cfg->incksel3, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_INCKSEL4, clk_cfg->incksel4, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_INCKSEL5, clk_cfg->incksel5, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_INCKSEL6, clk_cfg->incksel6, &ret);
|
2023-02-16 06:30:01 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static int imx290_set_data_lanes(struct imx290 *imx290)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
2023-01-16 22:44:53 +08:00
|
|
|
int ret = 0;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_PHY_LANE_NUM, imx290->nlanes - 1,
|
|
|
|
&ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_CSI_LANE_MODE, imx290->nlanes - 1,
|
|
|
|
&ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_FR_FDG_SEL, 0x01, &ret);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:44 +08:00
|
|
|
static int imx290_set_black_level(struct imx290 *imx290,
|
2022-10-17 18:44:27 +08:00
|
|
|
const struct v4l2_mbus_framefmt *format,
|
2023-01-16 22:44:44 +08:00
|
|
|
unsigned int black_level, int *err)
|
|
|
|
{
|
2023-02-16 06:29:50 +08:00
|
|
|
unsigned int bpp = imx290_format_info(imx290, format->code)->bpp;
|
2022-10-17 18:44:27 +08:00
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
return cci_write(imx290->regmap, IMX290_BLKLEVEL,
|
|
|
|
black_level >> (16 - bpp), err);
|
2023-01-16 22:44:44 +08:00
|
|
|
}
|
|
|
|
|
2023-02-16 06:29:56 +08:00
|
|
|
static int imx290_set_csi_config(struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
const s64 *link_freqs = imx290_link_freqs_ptr(imx290);
|
|
|
|
const struct imx290_csi_cfg *csi_cfg;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (link_freqs[imx290->current_mode->link_freq_index]) {
|
|
|
|
case 445500000:
|
|
|
|
csi_cfg = &imx290_csi_445_5mhz;
|
|
|
|
break;
|
|
|
|
case 297000000:
|
|
|
|
csi_cfg = &imx290_csi_297mhz;
|
|
|
|
break;
|
|
|
|
case 222750000:
|
|
|
|
csi_cfg = &imx290_csi_222_75mhz;
|
|
|
|
break;
|
|
|
|
case 148500000:
|
|
|
|
csi_cfg = &imx290_csi_148_5mhz;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_REPETITION, csi_cfg->repetition, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_TCLKPOST, csi_cfg->tclkpost, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_THSZERO, csi_cfg->thszero, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_THSPREPARE, csi_cfg->thsprepare, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_TCLKTRAIL, csi_cfg->tclktrail, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_THSTRAIL, csi_cfg->thstrail, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_TCLKZERO, csi_cfg->tclkzero, &ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_TCLKPREPARE, csi_cfg->tclkprepare,
|
|
|
|
&ret);
|
|
|
|
cci_write(imx290->regmap, IMX290_TLPX, csi_cfg->tlpx, &ret);
|
2023-02-16 06:29:56 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
static int imx290_setup_format(struct imx290 *imx290,
|
|
|
|
const struct v4l2_mbus_framefmt *format)
|
2023-01-16 22:44:38 +08:00
|
|
|
{
|
2022-10-17 18:44:27 +08:00
|
|
|
const struct imx290_format_info *info;
|
2023-01-16 22:44:38 +08:00
|
|
|
int ret;
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
info = imx290_format_info(imx290, format->code);
|
2023-01-16 22:44:38 +08:00
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
ret = imx290_set_register_array(imx290, info->regs, info->num_regs);
|
2023-01-16 22:44:44 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imx290->dev, "Could not set format registers\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
return imx290_set_black_level(imx290, format,
|
|
|
|
IMX290_BLACK_LEVEL_DEFAULT, &ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Controls
|
|
|
|
*/
|
2023-02-16 06:29:58 +08:00
|
|
|
static void imx290_exposure_update(struct imx290 *imx290,
|
|
|
|
const struct imx290_mode *mode)
|
|
|
|
{
|
|
|
|
unsigned int exposure_max;
|
|
|
|
|
|
|
|
exposure_max = imx290->vblank->val + mode->height -
|
|
|
|
IMX290_EXPOSURE_OFFSET;
|
|
|
|
__v4l2_ctrl_modify_range(imx290->exposure, 1, exposure_max, 1,
|
|
|
|
exposure_max);
|
|
|
|
}
|
2023-01-16 22:44:38 +08:00
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
static int imx290_set_ctrl(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
struct imx290 *imx290 = container_of(ctrl->handler,
|
|
|
|
struct imx290, ctrls);
|
2022-10-17 18:44:27 +08:00
|
|
|
const struct v4l2_mbus_framefmt *format;
|
|
|
|
struct v4l2_subdev_state *state;
|
2023-02-16 06:29:58 +08:00
|
|
|
int ret = 0, vmax;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
/*
|
|
|
|
* Return immediately for controls that don't need to be applied to the
|
2023-01-16 22:44:51 +08:00
|
|
|
* device.
|
2022-10-17 18:44:27 +08:00
|
|
|
*/
|
|
|
|
if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
|
|
|
|
return 0;
|
|
|
|
|
2023-02-16 06:29:58 +08:00
|
|
|
if (ctrl->id == V4L2_CID_VBLANK) {
|
|
|
|
/* Changing vblank changes the allowed range for exposure. */
|
|
|
|
imx290_exposure_update(imx290, imx290->current_mode);
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
/* V4L2 controls values will be applied only when power is already up */
|
|
|
|
if (!pm_runtime_get_if_in_use(imx290->dev))
|
|
|
|
return 0;
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
state = v4l2_subdev_get_locked_active_state(&imx290->sd);
|
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 15:37:10 +08:00
|
|
|
format = v4l2_subdev_state_get_format(state, 0);
|
2022-10-17 18:44:27 +08:00
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
switch (ctrl->id) {
|
2022-10-16 14:15:23 +08:00
|
|
|
case V4L2_CID_ANALOGUE_GAIN:
|
2023-06-27 20:51:06 +08:00
|
|
|
ret = cci_write(imx290->regmap, IMX290_GAIN, ctrl->val, NULL);
|
2019-10-05 00:05:25 +08:00
|
|
|
break;
|
2022-10-16 14:15:15 +08:00
|
|
|
|
2023-02-16 06:29:58 +08:00
|
|
|
case V4L2_CID_VBLANK:
|
2023-06-27 20:51:06 +08:00
|
|
|
ret = cci_write(imx290->regmap, IMX290_VMAX,
|
|
|
|
ctrl->val + imx290->current_mode->height, NULL);
|
2023-02-16 06:29:58 +08:00
|
|
|
/*
|
|
|
|
* Due to the way that exposure is programmed in this sensor in
|
|
|
|
* relation to VMAX, we have to reprogramme it whenever VMAX is
|
|
|
|
* changed.
|
|
|
|
* Update ctrl so that the V4L2_CID_EXPOSURE case can refer to
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
ctrl = imx290->exposure;
|
|
|
|
fallthrough;
|
2022-10-16 14:15:15 +08:00
|
|
|
case V4L2_CID_EXPOSURE:
|
2023-02-16 06:29:58 +08:00
|
|
|
vmax = imx290->vblank->val + imx290->current_mode->height;
|
2023-06-27 20:51:06 +08:00
|
|
|
ret = cci_write(imx290->regmap, IMX290_SHS1,
|
|
|
|
vmax - ctrl->val - 1, NULL);
|
2022-10-16 14:15:15 +08:00
|
|
|
break;
|
|
|
|
|
2020-06-12 21:53:51 +08:00
|
|
|
case V4L2_CID_TEST_PATTERN:
|
|
|
|
if (ctrl->val) {
|
2022-10-17 18:44:27 +08:00
|
|
|
imx290_set_black_level(imx290, format, 0, &ret);
|
2020-06-24 00:52:26 +08:00
|
|
|
usleep_range(10000, 11000);
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_PGCTRL,
|
|
|
|
(u8)(IMX290_PGCTRL_REGEN |
|
|
|
|
IMX290_PGCTRL_THRU |
|
|
|
|
IMX290_PGCTRL_MODE(ctrl->val)), &ret);
|
2020-06-12 21:53:51 +08:00
|
|
|
} else {
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_PGCTRL, 0x00, &ret);
|
2020-06-24 00:52:26 +08:00
|
|
|
usleep_range(10000, 11000);
|
2022-10-17 18:44:27 +08:00
|
|
|
imx290_set_black_level(imx290, format,
|
|
|
|
IMX290_BLACK_LEVEL_DEFAULT, &ret);
|
2020-06-12 21:53:51 +08:00
|
|
|
}
|
|
|
|
break;
|
2022-10-17 18:44:27 +08:00
|
|
|
|
2023-02-16 06:29:57 +08:00
|
|
|
case V4L2_CID_HBLANK:
|
2023-06-27 20:51:06 +08:00
|
|
|
ret = cci_write(imx290->regmap, IMX290_HMAX,
|
|
|
|
ctrl->val + imx290->current_mode->width, NULL);
|
2023-02-16 06:29:57 +08:00
|
|
|
break;
|
|
|
|
|
2023-02-16 06:30:02 +08:00
|
|
|
case V4L2_CID_HFLIP:
|
|
|
|
case V4L2_CID_VFLIP:
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
reg = imx290->current_mode->ctrl_07;
|
|
|
|
if (imx290->hflip->val)
|
|
|
|
reg |= IMX290_HREVERSE;
|
|
|
|
if (imx290->vflip->val)
|
|
|
|
reg |= IMX290_VREVERSE;
|
2023-06-27 20:51:06 +08:00
|
|
|
ret = cci_write(imx290->regmap, IMX290_CTRL_07, reg, NULL);
|
2023-02-16 06:30:02 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:50 +08:00
|
|
|
pm_runtime_mark_last_busy(imx290->dev);
|
|
|
|
pm_runtime_put_autosuspend(imx290->dev);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct v4l2_ctrl_ops imx290_ctrl_ops = {
|
|
|
|
.s_ctrl = imx290_set_ctrl,
|
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static const char * const imx290_test_pattern_menu[] = {
|
|
|
|
"Disabled",
|
|
|
|
"Sequence Pattern 1",
|
|
|
|
"Horizontal Color-bar Chart",
|
|
|
|
"Vertical Color-bar Chart",
|
|
|
|
"Sequence Pattern 2",
|
|
|
|
"Gradation Pattern 1",
|
|
|
|
"Gradation Pattern 2",
|
|
|
|
"000/555h Toggle Pattern",
|
|
|
|
};
|
2022-10-16 14:15:21 +08:00
|
|
|
|
2023-01-16 22:44:40 +08:00
|
|
|
static void imx290_ctrl_update(struct imx290 *imx290,
|
|
|
|
const struct imx290_mode *mode)
|
|
|
|
{
|
2023-02-16 06:29:57 +08:00
|
|
|
unsigned int hblank_min = mode->hmax_min - mode->width;
|
|
|
|
unsigned int hblank_max = IMX290_HMAX_MAX - mode->width;
|
2023-02-16 06:29:59 +08:00
|
|
|
unsigned int vblank_min = mode->vmax_min - mode->height;
|
2023-02-16 06:29:58 +08:00
|
|
|
unsigned int vblank_max = IMX290_VMAX_MAX - mode->height;
|
2023-01-16 22:44:43 +08:00
|
|
|
|
2023-01-16 22:44:41 +08:00
|
|
|
__v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index);
|
2023-01-16 22:44:40 +08:00
|
|
|
|
2023-02-16 06:29:57 +08:00
|
|
|
__v4l2_ctrl_modify_range(imx290->hblank, hblank_min, hblank_max, 1,
|
|
|
|
hblank_min);
|
2023-02-16 06:29:58 +08:00
|
|
|
__v4l2_ctrl_modify_range(imx290->vblank, vblank_min, vblank_max, 1,
|
|
|
|
vblank_min);
|
2023-01-16 22:44:40 +08:00
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static int imx290_ctrl_init(struct imx290 *imx290)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
2023-01-16 22:44:38 +08:00
|
|
|
struct v4l2_fwnode_device_properties props;
|
|
|
|
int ret;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
ret = v4l2_fwnode_device_parse(imx290->dev, &props);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-02-16 06:30:02 +08:00
|
|
|
v4l2_ctrl_handler_init(&imx290->ctrls, 11);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/*
|
|
|
|
* The sensor has an analog gain and a digital gain, both controlled
|
|
|
|
* through a single gain value, expressed in 0.3dB increments. Values
|
|
|
|
* from 0.0dB (0) to 30.0dB (100) apply analog gain only, higher values
|
|
|
|
* up to 72.0dB (240) add further digital gain. Limit the range to
|
|
|
|
* analog gain only, support for digital gain can be added separately
|
|
|
|
* if needed.
|
|
|
|
*
|
|
|
|
* The IMX327 and IMX462 are largely compatible with the IMX290, but
|
|
|
|
* have an analog gain range of 0.0dB to 29.4dB and 42dB of digital
|
|
|
|
* gain. When support for those sensors gets added to the driver, the
|
|
|
|
* gain control should be adjusted accordingly.
|
|
|
|
*/
|
|
|
|
v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
V4L2_CID_ANALOGUE_GAIN, 0, 100, 1, 0);
|
2020-06-12 21:53:53 +08:00
|
|
|
|
2023-02-16 06:29:58 +08:00
|
|
|
/*
|
|
|
|
* Correct range will be determined through imx290_ctrl_update setting
|
|
|
|
* V4L2_CID_VBLANK.
|
|
|
|
*/
|
|
|
|
imx290->exposure = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
V4L2_CID_EXPOSURE, 1, 65535, 1,
|
|
|
|
65535);
|
2020-06-12 21:53:53 +08:00
|
|
|
|
2023-01-16 22:44:43 +08:00
|
|
|
/*
|
|
|
|
* Set the link frequency, pixel rate, horizontal blanking and vertical
|
|
|
|
* blanking to hardcoded values, they will be updated by
|
|
|
|
* imx290_ctrl_update().
|
|
|
|
*/
|
2023-01-16 22:44:38 +08:00
|
|
|
imx290->link_freq =
|
|
|
|
v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
V4L2_CID_LINK_FREQ,
|
|
|
|
imx290_link_freqs_num(imx290) - 1, 0,
|
|
|
|
imx290_link_freqs_ptr(imx290));
|
|
|
|
if (imx290->link_freq)
|
|
|
|
imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
|
2020-06-12 21:53:53 +08:00
|
|
|
|
2023-02-16 06:29:54 +08:00
|
|
|
v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_PIXEL_RATE,
|
|
|
|
IMX290_PIXEL_RATE, IMX290_PIXEL_RATE, 1,
|
|
|
|
IMX290_PIXEL_RATE);
|
2020-06-12 21:53:53 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
V4L2_CID_TEST_PATTERN,
|
|
|
|
ARRAY_SIZE(imx290_test_pattern_menu) - 1,
|
|
|
|
0, 0, imx290_test_pattern_menu);
|
2020-06-12 21:53:53 +08:00
|
|
|
|
2023-02-16 06:29:57 +08:00
|
|
|
/*
|
|
|
|
* Actual range will be set from imx290_ctrl_update later in the probe.
|
|
|
|
*/
|
2023-01-16 22:44:38 +08:00
|
|
|
imx290->hblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
|
2023-01-16 22:44:43 +08:00
|
|
|
V4L2_CID_HBLANK, 1, 1, 1, 1);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
|
2023-01-16 22:44:43 +08:00
|
|
|
V4L2_CID_VBLANK, 1, 1, 1, 1);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-02-16 06:30:02 +08:00
|
|
|
imx290->hflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
V4L2_CID_HFLIP, 0, 1, 1, 0);
|
|
|
|
imx290->vflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
V4L2_CID_VFLIP, 0, 1, 1, 0);
|
|
|
|
v4l2_ctrl_cluster(2, &imx290->hflip);
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
v4l2_ctrl_new_fwnode_properties(&imx290->ctrls, &imx290_ctrl_ops,
|
|
|
|
&props);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
imx290->sd.ctrl_handler = &imx290->ctrls;
|
|
|
|
|
|
|
|
if (imx290->ctrls.error) {
|
|
|
|
ret = imx290->ctrls.error;
|
|
|
|
v4l2_ctrl_handler_free(&imx290->ctrls);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Subdev operations
|
|
|
|
*/
|
2020-06-12 21:53:50 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* Start streaming */
|
2022-10-17 18:44:27 +08:00
|
|
|
static int imx290_start_streaming(struct imx290 *imx290,
|
|
|
|
struct v4l2_subdev_state *state)
|
2020-06-12 21:53:50 +08:00
|
|
|
{
|
2022-10-17 18:44:27 +08:00
|
|
|
const struct v4l2_mbus_framefmt *format;
|
2023-01-16 22:44:38 +08:00
|
|
|
int ret;
|
2020-06-12 21:53:50 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* Set init register settings */
|
|
|
|
ret = imx290_set_register_array(imx290, imx290_global_init_settings,
|
2023-02-16 06:29:51 +08:00
|
|
|
ARRAY_SIZE(imx290_global_init_settings));
|
2023-01-16 22:44:38 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imx290->dev, "Could not set init registers\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-17 17:52:21 +08:00
|
|
|
/* Set mdel specific init register settings */
|
|
|
|
ret = imx290_set_register_array(imx290, imx290->model->init_regs,
|
|
|
|
imx290->model->init_regs_num);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imx290->dev, "Could not set model specific init registers\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-16 06:30:01 +08:00
|
|
|
/* Set clock parameters based on mode and xclk */
|
|
|
|
ret = imx290_set_clock(imx290);
|
|
|
|
if (ret < 0) {
|
2023-02-16 06:30:03 +08:00
|
|
|
dev_err(imx290->dev, "Could not set clocks - %d\n", ret);
|
2023-02-16 06:30:01 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:52 +08:00
|
|
|
/* Set data lane count */
|
2023-01-16 22:44:54 +08:00
|
|
|
ret = imx290_set_data_lanes(imx290);
|
|
|
|
if (ret < 0) {
|
2023-02-16 06:30:03 +08:00
|
|
|
dev_err(imx290->dev, "Could not set data lanes - %d\n", ret);
|
2023-01-16 22:44:54 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2023-01-16 22:44:52 +08:00
|
|
|
|
2023-02-16 06:29:56 +08:00
|
|
|
ret = imx290_set_csi_config(imx290);
|
|
|
|
if (ret < 0) {
|
2023-02-16 06:30:03 +08:00
|
|
|
dev_err(imx290->dev, "Could not set csi cfg - %d\n", ret);
|
2023-02-16 06:29:56 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* Apply the register values related to current frame format */
|
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 15:37:10 +08:00
|
|
|
format = v4l2_subdev_state_get_format(state, 0);
|
2022-10-17 18:44:27 +08:00
|
|
|
ret = imx290_setup_format(imx290, format);
|
2023-01-16 22:44:38 +08:00
|
|
|
if (ret < 0) {
|
2023-02-16 06:30:03 +08:00
|
|
|
dev_err(imx290->dev, "Could not set frame format - %d\n", ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply default values of current mode */
|
|
|
|
ret = imx290_set_register_array(imx290, imx290->current_mode->data,
|
|
|
|
imx290->current_mode->data_size);
|
|
|
|
if (ret < 0) {
|
2023-02-16 06:30:03 +08:00
|
|
|
dev_err(imx290->dev, "Could not set current mode - %d\n", ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply customized values from user */
|
2022-10-17 18:44:27 +08:00
|
|
|
ret = __v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler);
|
2023-01-16 22:44:38 +08:00
|
|
|
if (ret) {
|
2023-02-16 06:30:03 +08:00
|
|
|
dev_err(imx290->dev, "Could not sync v4l2 controls - %d\n", ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_STANDBY, 0x00, &ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
|
|
|
|
msleep(30);
|
|
|
|
|
|
|
|
/* Start streaming */
|
2023-06-27 20:51:06 +08:00
|
|
|
return cci_write(imx290->regmap, IMX290_XMSTA, 0x00, &ret);
|
2020-06-12 21:53:50 +08:00
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* Stop streaming */
|
|
|
|
static int imx290_stop_streaming(struct imx290 *imx290)
|
2020-06-12 21:53:50 +08:00
|
|
|
{
|
2023-01-16 22:44:38 +08:00
|
|
|
int ret = 0;
|
2020-06-12 21:53:50 +08:00
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
cci_write(imx290->regmap, IMX290_STANDBY, 0x01, &ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
|
|
|
|
msleep(30);
|
|
|
|
|
2023-06-27 20:51:06 +08:00
|
|
|
return cci_write(imx290->regmap, IMX290_XMSTA, 0x01, &ret);
|
2023-01-16 22:44:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imx290_set_stream(struct v4l2_subdev *sd, int enable)
|
|
|
|
{
|
|
|
|
struct imx290 *imx290 = to_imx290(sd);
|
2022-10-17 18:44:27 +08:00
|
|
|
struct v4l2_subdev_state *state;
|
2023-01-16 22:44:38 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
state = v4l2_subdev_lock_and_get_active_state(sd);
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
if (enable) {
|
|
|
|
ret = pm_runtime_resume_and_get(imx290->dev);
|
|
|
|
if (ret < 0)
|
2022-10-17 18:44:27 +08:00
|
|
|
goto unlock;
|
2023-01-16 22:44:38 +08:00
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
ret = imx290_start_streaming(imx290, state);
|
2023-01-16 22:44:38 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(imx290->dev, "Start stream failed\n");
|
2023-01-16 22:44:50 +08:00
|
|
|
pm_runtime_put_sync(imx290->dev);
|
2022-10-17 18:44:27 +08:00
|
|
|
goto unlock;
|
2023-01-16 22:44:38 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
imx290_stop_streaming(imx290);
|
2023-01-16 22:44:50 +08:00
|
|
|
pm_runtime_mark_last_busy(imx290->dev);
|
|
|
|
pm_runtime_put_autosuspend(imx290->dev);
|
2023-01-16 22:44:38 +08:00
|
|
|
}
|
|
|
|
|
2023-02-16 06:30:02 +08:00
|
|
|
/*
|
|
|
|
* vflip and hflip should not be changed during streaming as the sensor
|
|
|
|
* will produce an invalid frame.
|
|
|
|
*/
|
|
|
|
__v4l2_ctrl_grab(imx290->vflip, enable);
|
|
|
|
__v4l2_ctrl_grab(imx290->hflip, enable);
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
unlock:
|
|
|
|
v4l2_subdev_unlock_state(state);
|
2023-01-16 22:44:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx290_enum_mbus_code(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_mbus_code_enum *code)
|
|
|
|
{
|
2023-02-16 06:29:50 +08:00
|
|
|
const struct imx290 *imx290 = to_imx290(sd);
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
if (code->index >= ARRAY_SIZE(imx290_formats))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
code->code = imx290_formats[code->index].code[imx290->model->colour_variant];
|
2023-01-16 22:44:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx290_enum_frame_size(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_frame_size_enum *fse)
|
|
|
|
{
|
|
|
|
const struct imx290 *imx290 = to_imx290(sd);
|
|
|
|
const struct imx290_mode *imx290_modes = imx290_modes_ptr(imx290);
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
if (!imx290_format_info(imx290, fse->code))
|
2023-01-16 22:44:38 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (fse->index >= imx290_modes_num(imx290))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
fse->min_width = imx290_modes[fse->index].width;
|
|
|
|
fse->max_width = imx290_modes[fse->index].width;
|
|
|
|
fse->min_height = imx290_modes[fse->index].height;
|
|
|
|
fse->max_height = imx290_modes[fse->index].height;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:05:25 +08:00
|
|
|
static int imx290_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 22:55:58 +08:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_format *fmt)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
|
|
|
struct imx290 *imx290 = to_imx290(sd);
|
|
|
|
const struct imx290_mode *mode;
|
|
|
|
struct v4l2_mbus_framefmt *format;
|
|
|
|
|
2020-06-12 21:53:49 +08:00
|
|
|
mode = v4l2_find_nearest_size(imx290_modes_ptr(imx290),
|
|
|
|
imx290_modes_num(imx290), width, height,
|
2019-10-05 00:05:25 +08:00
|
|
|
fmt->format.width, fmt->format.height);
|
|
|
|
|
|
|
|
fmt->format.width = mode->width;
|
|
|
|
fmt->format.height = mode->height;
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
if (!imx290_format_info(imx290, fmt->format.code))
|
|
|
|
fmt->format.code = imx290_formats[0].code[imx290->model->colour_variant];
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
fmt->format.field = V4L2_FIELD_NONE;
|
2023-02-16 06:29:52 +08:00
|
|
|
fmt->format.colorspace = V4L2_COLORSPACE_RAW;
|
|
|
|
fmt->format.ycbcr_enc = V4L2_YCBCR_ENC_601;
|
|
|
|
fmt->format.quantization = V4L2_QUANTIZATION_FULL_RANGE;
|
|
|
|
fmt->format.xfer_func = V4L2_XFER_FUNC_NONE;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
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 15:37:10 +08:00
|
|
|
format = v4l2_subdev_state_get_format(sd_state, 0);
|
2022-10-16 14:15:21 +08:00
|
|
|
|
|
|
|
if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
|
2019-10-05 00:05:25 +08:00
|
|
|
imx290->current_mode = mode;
|
2020-06-12 21:53:50 +08:00
|
|
|
|
2023-06-13 16:07:34 +08:00
|
|
|
imx290_ctrl_update(imx290, mode);
|
2023-02-16 06:29:58 +08:00
|
|
|
imx290_exposure_update(imx290, mode);
|
2019-10-05 00:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*format = fmt->format;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-16 14:15:22 +08:00
|
|
|
static int imx290_get_selection(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
struct v4l2_subdev_selection *sel)
|
|
|
|
{
|
2023-02-16 06:30:02 +08:00
|
|
|
struct imx290 *imx290 = to_imx290(sd);
|
2022-10-16 14:15:22 +08:00
|
|
|
struct v4l2_mbus_framefmt *format;
|
|
|
|
|
|
|
|
switch (sel->target) {
|
|
|
|
case V4L2_SEL_TGT_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 15:37:10 +08:00
|
|
|
format = v4l2_subdev_state_get_format(sd_state, 0);
|
2022-10-16 14:15:22 +08:00
|
|
|
|
2023-02-16 06:30:02 +08:00
|
|
|
/*
|
|
|
|
* The sensor moves the readout by 1 pixel based on flips to
|
|
|
|
* keep the Bayer order the same.
|
|
|
|
*/
|
2024-02-21 15:15:50 +08:00
|
|
|
sel->r.top = IMX290_PIXEL_ARRAY_MARGIN_TOP
|
2023-02-16 06:30:02 +08:00
|
|
|
+ (IMX290_PIXEL_ARRAY_RECORDING_HEIGHT - format->height) / 2
|
|
|
|
+ imx290->vflip->val;
|
2024-02-21 15:15:50 +08:00
|
|
|
sel->r.left = IMX290_PIXEL_ARRAY_MARGIN_LEFT
|
2023-02-16 06:30:02 +08:00
|
|
|
+ (IMX290_PIXEL_ARRAY_RECORDING_WIDTH - format->width) / 2
|
|
|
|
+ imx290->hflip->val;
|
2022-10-16 14:15:22 +08:00
|
|
|
sel->r.width = format->width;
|
|
|
|
sel->r.height = format->height;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case V4L2_SEL_TGT_NATIVE_SIZE:
|
|
|
|
case V4L2_SEL_TGT_CROP_BOUNDS:
|
|
|
|
sel->r.top = 0;
|
|
|
|
sel->r.left = 0;
|
|
|
|
sel->r.width = IMX290_PIXEL_ARRAY_WIDTH;
|
|
|
|
sel->r.height = IMX290_PIXEL_ARRAY_HEIGHT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case V4L2_SEL_TGT_CROP_DEFAULT:
|
2024-02-21 15:15:50 +08:00
|
|
|
sel->r.top = IMX290_PIXEL_ARRAY_MARGIN_TOP;
|
|
|
|
sel->r.left = IMX290_PIXEL_ARRAY_MARGIN_LEFT;
|
2022-10-16 14:15:22 +08:00
|
|
|
sel->r.width = IMX290_PIXEL_ARRAY_RECORDING_WIDTH;
|
|
|
|
sel->r.height = IMX290_PIXEL_ARRAY_RECORDING_HEIGHT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 17:07:44 +08:00
|
|
|
static int imx290_entity_init_state(struct v4l2_subdev *subdev,
|
|
|
|
struct v4l2_subdev_state *sd_state)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
2022-10-17 18:44:27 +08:00
|
|
|
struct v4l2_subdev_format fmt = {
|
|
|
|
.which = V4L2_SUBDEV_FORMAT_TRY,
|
|
|
|
.format = {
|
|
|
|
.width = 1920,
|
|
|
|
.height = 1080,
|
|
|
|
},
|
|
|
|
};
|
2019-10-05 00:05:25 +08:00
|
|
|
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 22:55:58 +08:00
|
|
|
imx290_set_fmt(subdev, sd_state, &fmt);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-16 06:29:53 +08:00
|
|
|
static const struct v4l2_subdev_core_ops imx290_core_ops = {
|
|
|
|
.subscribe_event = v4l2_ctrl_subdev_subscribe_event,
|
|
|
|
.unsubscribe_event = v4l2_event_subdev_unsubscribe,
|
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static const struct v4l2_subdev_video_ops imx290_video_ops = {
|
|
|
|
.s_stream = imx290_set_stream,
|
|
|
|
};
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static const struct v4l2_subdev_pad_ops imx290_pad_ops = {
|
|
|
|
.enum_mbus_code = imx290_enum_mbus_code,
|
|
|
|
.enum_frame_size = imx290_enum_frame_size,
|
2022-10-17 18:44:27 +08:00
|
|
|
.get_fmt = v4l2_subdev_get_fmt,
|
2023-01-16 22:44:38 +08:00
|
|
|
.set_fmt = imx290_set_fmt,
|
|
|
|
.get_selection = imx290_get_selection,
|
|
|
|
};
|
2020-06-12 21:53:49 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static const struct v4l2_subdev_ops imx290_subdev_ops = {
|
2023-02-16 06:29:53 +08:00
|
|
|
.core = &imx290_core_ops,
|
2023-01-16 22:44:38 +08:00
|
|
|
.video = &imx290_video_ops,
|
|
|
|
.pad = &imx290_pad_ops,
|
|
|
|
};
|
2020-06-12 21:53:49 +08:00
|
|
|
|
2023-11-27 17:07:44 +08:00
|
|
|
static const struct v4l2_subdev_internal_ops imx290_internal_ops = {
|
|
|
|
.init_state = imx290_entity_init_state,
|
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static const struct media_entity_operations imx290_subdev_entity_ops = {
|
|
|
|
.link_validate = v4l2_subdev_link_validate,
|
|
|
|
};
|
2020-06-12 21:53:49 +08:00
|
|
|
|
2023-01-16 22:44:39 +08:00
|
|
|
static int imx290_subdev_init(struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(imx290->dev);
|
2022-10-17 18:44:27 +08:00
|
|
|
struct v4l2_subdev_state *state;
|
2023-01-16 22:44:39 +08:00
|
|
|
int ret;
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
imx290->current_mode = &imx290_modes_ptr(imx290)[0];
|
2023-01-16 22:44:39 +08:00
|
|
|
|
|
|
|
v4l2_i2c_subdev_init(&imx290->sd, client, &imx290_subdev_ops);
|
2023-11-27 17:07:44 +08:00
|
|
|
imx290->sd.internal_ops = &imx290_internal_ops;
|
2023-02-16 06:29:53 +08:00
|
|
|
imx290->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
|
|
|
|
V4L2_SUBDEV_FL_HAS_EVENTS;
|
2023-01-16 22:44:39 +08:00
|
|
|
imx290->sd.dev = imx290->dev;
|
|
|
|
imx290->sd.entity.ops = &imx290_subdev_entity_ops;
|
|
|
|
imx290->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
|
|
|
|
|
|
|
|
imx290->pad.flags = MEDIA_PAD_FL_SOURCE;
|
|
|
|
ret = media_entity_pads_init(&imx290->sd.entity, 1, &imx290->pad);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imx290->dev, "Could not register media entity\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
ret = imx290_ctrl_init(imx290);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imx290->dev, "Control initialization error %d\n", ret);
|
|
|
|
goto err_media;
|
|
|
|
}
|
|
|
|
|
|
|
|
imx290->sd.state_lock = imx290->ctrls.lock;
|
|
|
|
|
|
|
|
ret = v4l2_subdev_init_finalize(&imx290->sd);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(imx290->dev, "subdev initialization error %d\n", ret);
|
|
|
|
goto err_ctrls;
|
|
|
|
}
|
|
|
|
|
2022-10-17 18:44:27 +08:00
|
|
|
state = v4l2_subdev_lock_and_get_active_state(&imx290->sd);
|
2023-06-13 16:07:34 +08:00
|
|
|
imx290_ctrl_update(imx290, imx290->current_mode);
|
2022-10-17 18:44:27 +08:00
|
|
|
v4l2_subdev_unlock_state(state);
|
2022-10-17 18:44:27 +08:00
|
|
|
|
2023-01-16 22:44:39 +08:00
|
|
|
return 0;
|
2022-10-17 18:44:27 +08:00
|
|
|
|
|
|
|
err_ctrls:
|
|
|
|
v4l2_ctrl_handler_free(&imx290->ctrls);
|
|
|
|
err_media:
|
|
|
|
media_entity_cleanup(&imx290->sd.entity);
|
|
|
|
return ret;
|
2023-01-16 22:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imx290_subdev_cleanup(struct imx290 *imx290)
|
|
|
|
{
|
2022-10-17 18:44:27 +08:00
|
|
|
v4l2_subdev_cleanup(&imx290->sd);
|
2023-01-16 22:44:39 +08:00
|
|
|
media_entity_cleanup(&imx290->sd.entity);
|
|
|
|
v4l2_ctrl_handler_free(&imx290->ctrls);
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Power management
|
|
|
|
*/
|
2020-06-12 21:53:49 +08:00
|
|
|
|
2023-01-16 22:44:51 +08:00
|
|
|
static int imx290_power_on(struct imx290 *imx290)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(imx290->xclk);
|
|
|
|
if (ret) {
|
2023-01-16 22:44:51 +08:00
|
|
|
dev_err(imx290->dev, "Failed to enable clock\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-16 14:15:07 +08:00
|
|
|
ret = regulator_bulk_enable(ARRAY_SIZE(imx290->supplies),
|
|
|
|
imx290->supplies);
|
2019-10-05 00:05:25 +08:00
|
|
|
if (ret) {
|
2023-01-16 22:44:51 +08:00
|
|
|
dev_err(imx290->dev, "Failed to enable regulators\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
clk_disable_unprepare(imx290->xclk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
usleep_range(1, 2);
|
2020-06-12 21:53:48 +08:00
|
|
|
gpiod_set_value_cansleep(imx290->rst_gpio, 0);
|
2019-10-05 00:05:25 +08:00
|
|
|
usleep_range(30000, 31000);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:51 +08:00
|
|
|
static void imx290_power_off(struct imx290 *imx290)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
|
|
|
clk_disable_unprepare(imx290->xclk);
|
2020-06-12 21:53:48 +08:00
|
|
|
gpiod_set_value_cansleep(imx290->rst_gpio, 1);
|
2022-10-16 14:15:07 +08:00
|
|
|
regulator_bulk_disable(ARRAY_SIZE(imx290->supplies), imx290->supplies);
|
2023-01-16 22:44:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int imx290_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = dev_get_drvdata(dev);
|
|
|
|
struct imx290 *imx290 = to_imx290(sd);
|
|
|
|
|
|
|
|
return imx290_power_on(imx290);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx290_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = dev_get_drvdata(dev);
|
|
|
|
struct imx290 *imx290 = to_imx290(sd);
|
|
|
|
|
|
|
|
imx290_power_off(imx290);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dev_pm_ops imx290_pm_ops = {
|
2023-02-08 00:13:12 +08:00
|
|
|
RUNTIME_PM_OPS(imx290_runtime_suspend, imx290_runtime_resume, NULL)
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Probe & remove
|
|
|
|
*/
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static const char * const imx290_supply_name[IMX290_NUM_SUPPLIES] = {
|
|
|
|
"vdda",
|
|
|
|
"vddd",
|
|
|
|
"vdddo",
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
static int imx290_get_regulators(struct device *dev, struct imx290 *imx290)
|
2022-10-16 14:15:17 +08:00
|
|
|
{
|
2023-01-16 22:44:38 +08:00
|
|
|
unsigned int i;
|
2022-10-16 14:15:17 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(imx290->supplies); i++)
|
|
|
|
imx290->supplies[i].supply = imx290_supply_name[i];
|
2022-10-16 14:15:17 +08:00
|
|
|
|
2023-01-16 22:44:38 +08:00
|
|
|
return devm_regulator_bulk_get(dev, ARRAY_SIZE(imx290->supplies),
|
|
|
|
imx290->supplies);
|
2022-10-16 14:15:17 +08:00
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:47 +08:00
|
|
|
static int imx290_init_clk(struct imx290 *imx290)
|
|
|
|
{
|
|
|
|
u32 xclk_freq;
|
|
|
|
int ret;
|
|
|
|
|
2023-02-10 06:09:54 +08:00
|
|
|
ret = device_property_read_u32(imx290->dev, "clock-frequency",
|
|
|
|
&xclk_freq);
|
2023-01-16 22:44:47 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(imx290->dev, "Could not get xclk frequency\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-16 06:30:01 +08:00
|
|
|
/* external clock must be 37.125 MHz or 74.25MHz */
|
|
|
|
switch (xclk_freq) {
|
|
|
|
case 37125000:
|
|
|
|
imx290->xclk_idx = IMX290_CLK_37_125;
|
|
|
|
break;
|
|
|
|
case 74250000:
|
|
|
|
imx290->xclk_idx = IMX290_CLK_74_25;
|
|
|
|
break;
|
|
|
|
default:
|
2023-01-16 22:44:47 +08:00
|
|
|
dev_err(imx290->dev, "External clock frequency %u is not supported\n",
|
|
|
|
xclk_freq);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_set_rate(imx290->xclk, xclk_freq);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(imx290->dev, "Could not set xclk frequency\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-12 21:53:50 +08:00
|
|
|
/*
|
|
|
|
* Returns 0 if all link frequencies used by the driver for the given number
|
|
|
|
* of MIPI data lanes are mentioned in the device tree, or the value of the
|
|
|
|
* first missing frequency otherwise.
|
|
|
|
*/
|
2020-06-12 21:53:55 +08:00
|
|
|
static s64 imx290_check_link_freqs(const struct imx290 *imx290,
|
|
|
|
const struct v4l2_fwnode_endpoint *ep)
|
2020-06-12 21:53:50 +08:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
const s64 *freqs = imx290_link_freqs_ptr(imx290);
|
|
|
|
int freqs_count = imx290_link_freqs_num(imx290);
|
|
|
|
|
|
|
|
for (i = 0; i < freqs_count; i++) {
|
2020-06-12 21:53:55 +08:00
|
|
|
for (j = 0; j < ep->nr_of_link_frequencies; j++)
|
|
|
|
if (freqs[i] == ep->link_frequencies[j])
|
2020-06-12 21:53:50 +08:00
|
|
|
break;
|
2020-06-12 21:53:55 +08:00
|
|
|
if (j == ep->nr_of_link_frequencies)
|
2020-06-12 21:53:50 +08:00
|
|
|
return freqs[i];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
static const struct imx290_model_info imx290_models[] = {
|
|
|
|
[IMX290_MODEL_IMX290LQR] = {
|
|
|
|
.colour_variant = IMX290_VARIANT_COLOUR,
|
2023-02-17 17:52:21 +08:00
|
|
|
.init_regs = imx290_global_init_settings_290,
|
|
|
|
.init_regs_num = ARRAY_SIZE(imx290_global_init_settings_290),
|
|
|
|
.name = "imx290",
|
2023-02-16 06:29:50 +08:00
|
|
|
},
|
|
|
|
[IMX290_MODEL_IMX290LLR] = {
|
|
|
|
.colour_variant = IMX290_VARIANT_MONO,
|
2023-02-17 17:52:21 +08:00
|
|
|
.init_regs = imx290_global_init_settings_290,
|
|
|
|
.init_regs_num = ARRAY_SIZE(imx290_global_init_settings_290),
|
|
|
|
.name = "imx290",
|
|
|
|
},
|
|
|
|
[IMX290_MODEL_IMX327LQR] = {
|
|
|
|
.colour_variant = IMX290_VARIANT_COLOUR,
|
|
|
|
.init_regs = imx290_global_init_settings_327,
|
|
|
|
.init_regs_num = ARRAY_SIZE(imx290_global_init_settings_327),
|
|
|
|
.name = "imx327",
|
2023-02-16 06:29:50 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-01-16 22:44:45 +08:00
|
|
|
static int imx290_parse_dt(struct imx290 *imx290)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
2020-06-12 21:53:55 +08:00
|
|
|
/* Only CSI2 is supported for now: */
|
|
|
|
struct v4l2_fwnode_endpoint ep = {
|
|
|
|
.bus_type = V4L2_MBUS_CSI2_DPHY
|
|
|
|
};
|
2023-01-16 22:44:45 +08:00
|
|
|
struct fwnode_handle *endpoint;
|
2019-10-05 00:05:25 +08:00
|
|
|
int ret;
|
2023-01-16 22:44:45 +08:00
|
|
|
s64 fq;
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-02-16 06:29:50 +08:00
|
|
|
imx290->model = of_device_get_match_data(imx290->dev);
|
|
|
|
|
2023-01-16 22:44:45 +08:00
|
|
|
endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(imx290->dev), NULL);
|
2019-10-05 00:05:25 +08:00
|
|
|
if (!endpoint) {
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_err(imx290->dev, "Endpoint node not found\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-06-12 21:53:55 +08:00
|
|
|
ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep);
|
2019-10-05 00:05:25 +08:00
|
|
|
fwnode_handle_put(endpoint);
|
2020-06-12 21:53:55 +08:00
|
|
|
if (ret == -ENXIO) {
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_err(imx290->dev, "Unsupported bus type, should be CSI2\n");
|
|
|
|
goto done;
|
2020-06-12 21:53:55 +08:00
|
|
|
} else if (ret) {
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_err(imx290->dev, "Parsing endpoint node failed\n");
|
|
|
|
goto done;
|
2019-10-05 00:05:25 +08:00
|
|
|
}
|
|
|
|
|
2020-06-12 21:53:49 +08:00
|
|
|
/* Get number of data lanes */
|
2020-06-12 21:53:55 +08:00
|
|
|
imx290->nlanes = ep.bus.mipi_csi2.num_data_lanes;
|
2020-06-12 21:53:49 +08:00
|
|
|
if (imx290->nlanes != 2 && imx290->nlanes != 4) {
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_err(imx290->dev, "Invalid data lanes: %d\n", imx290->nlanes);
|
2020-06-12 21:53:49 +08:00
|
|
|
ret = -EINVAL;
|
2023-01-16 22:44:45 +08:00
|
|
|
goto done;
|
2020-06-12 21:53:49 +08:00
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_dbg(imx290->dev, "Using %u data lanes\n", imx290->nlanes);
|
2020-06-12 21:53:49 +08:00
|
|
|
|
2020-06-12 21:53:55 +08:00
|
|
|
if (!ep.nr_of_link_frequencies) {
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_err(imx290->dev, "link-frequency property not found in DT\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
ret = -EINVAL;
|
2023-01-16 22:44:45 +08:00
|
|
|
goto done;
|
2019-10-05 00:05:25 +08:00
|
|
|
}
|
|
|
|
|
2020-06-12 21:53:50 +08:00
|
|
|
/* Check that link frequences for all the modes are in device tree */
|
2020-06-12 21:53:55 +08:00
|
|
|
fq = imx290_check_link_freqs(imx290, &ep);
|
2020-06-12 21:53:50 +08:00
|
|
|
if (fq) {
|
2023-01-16 22:44:45 +08:00
|
|
|
dev_err(imx290->dev, "Link frequency of %lld is not supported\n",
|
|
|
|
fq);
|
2019-10-05 00:05:25 +08:00
|
|
|
ret = -EINVAL;
|
2023-01-16 22:44:45 +08:00
|
|
|
goto done;
|
2019-10-05 00:05:25 +08:00
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:45 +08:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
v4l2_fwnode_endpoint_free(&ep);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx290_probe(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct device *dev = &client->dev;
|
|
|
|
struct imx290 *imx290;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
imx290 = devm_kzalloc(dev, sizeof(*imx290), GFP_KERNEL);
|
|
|
|
if (!imx290)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
imx290->dev = dev;
|
2023-06-27 20:51:06 +08:00
|
|
|
imx290->regmap = devm_cci_regmap_init_i2c(client, 16);
|
2023-01-16 22:44:45 +08:00
|
|
|
if (IS_ERR(imx290->regmap)) {
|
|
|
|
dev_err(dev, "Unable to initialize I2C\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = imx290_parse_dt(imx290);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2023-01-16 22:44:47 +08:00
|
|
|
/* Acquire resources. */
|
2019-10-05 00:05:25 +08:00
|
|
|
imx290->xclk = devm_clk_get(dev, "xclk");
|
2023-01-16 22:44:46 +08:00
|
|
|
if (IS_ERR(imx290->xclk))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(imx290->xclk),
|
2023-04-06 17:55:51 +08:00
|
|
|
"Could not get xclk\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
ret = imx290_get_regulators(dev, imx290);
|
2023-01-16 22:44:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return dev_err_probe(dev, ret, "Cannot get regulators\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2020-06-12 21:53:48 +08:00
|
|
|
imx290->rst_gpio = devm_gpiod_get_optional(dev, "reset",
|
|
|
|
GPIOD_OUT_HIGH);
|
2023-01-16 22:44:46 +08:00
|
|
|
if (IS_ERR(imx290->rst_gpio))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(imx290->rst_gpio),
|
|
|
|
"Cannot get reset gpio\n");
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:47 +08:00
|
|
|
/* Initialize external clock frequency. */
|
|
|
|
ret = imx290_init_clk(imx290);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2023-01-16 22:44:50 +08:00
|
|
|
/*
|
|
|
|
* Enable power management. The driver supports runtime PM, but needs to
|
|
|
|
* work when runtime PM is disabled in the kernel. To that end, power
|
|
|
|
* the sensor on manually here.
|
|
|
|
*/
|
2023-01-16 22:44:51 +08:00
|
|
|
ret = imx290_power_on(imx290);
|
2019-10-05 00:05:25 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "Could not power on the device\n");
|
2023-01-16 22:44:51 +08:00
|
|
|
return ret;
|
2019-10-05 00:05:25 +08:00
|
|
|
}
|
|
|
|
|
2023-01-16 22:44:50 +08:00
|
|
|
/*
|
|
|
|
* Enable runtime PM with autosuspend. As the device has been powered
|
|
|
|
* manually, mark it as active, and increase the usage count without
|
|
|
|
* resuming the device.
|
|
|
|
*/
|
2019-10-05 00:05:25 +08:00
|
|
|
pm_runtime_set_active(dev);
|
2023-01-16 22:44:50 +08:00
|
|
|
pm_runtime_get_noresume(dev);
|
2019-10-05 00:05:25 +08:00
|
|
|
pm_runtime_enable(dev);
|
2023-01-16 22:44:50 +08:00
|
|
|
pm_runtime_set_autosuspend_delay(dev, 1000);
|
|
|
|
pm_runtime_use_autosuspend(dev);
|
|
|
|
|
2023-01-16 22:44:51 +08:00
|
|
|
/* Initialize the V4L2 subdev. */
|
|
|
|
ret = imx290_subdev_init(imx290);
|
|
|
|
if (ret)
|
|
|
|
goto err_pm;
|
|
|
|
|
2023-02-17 17:52:21 +08:00
|
|
|
v4l2_i2c_subdev_set_name(&imx290->sd, client,
|
|
|
|
imx290->model->name, NULL);
|
|
|
|
|
2023-01-16 22:44:50 +08:00
|
|
|
/*
|
|
|
|
* Finally, register the V4L2 subdev. This must be done after
|
|
|
|
* initializing everything as the subdev can be used immediately after
|
|
|
|
* being registered.
|
|
|
|
*/
|
|
|
|
ret = v4l2_async_register_subdev(&imx290->sd);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "Could not register v4l2 device\n");
|
2023-01-16 22:44:51 +08:00
|
|
|
goto err_subdev;
|
2023-01-16 22:44:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decrease the PM usage count. The device will get suspended after the
|
|
|
|
* autosuspend delay, turning the power off.
|
|
|
|
*/
|
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
pm_runtime_put_autosuspend(dev);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2023-01-16 22:44:51 +08:00
|
|
|
err_subdev:
|
|
|
|
imx290_subdev_cleanup(imx290);
|
2023-01-16 22:44:50 +08:00
|
|
|
err_pm:
|
|
|
|
pm_runtime_disable(dev);
|
|
|
|
pm_runtime_put_noidle(dev);
|
2023-01-16 22:44:51 +08:00
|
|
|
imx290_power_off(imx290);
|
2019-10-05 00:05:25 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:02:30 +08:00
|
|
|
static void imx290_remove(struct i2c_client *client)
|
2019-10-05 00:05:25 +08:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
|
|
|
struct imx290 *imx290 = to_imx290(sd);
|
|
|
|
|
|
|
|
v4l2_async_unregister_subdev(sd);
|
2023-01-16 22:44:39 +08:00
|
|
|
imx290_subdev_cleanup(imx290);
|
2019-10-05 00:05:25 +08:00
|
|
|
|
2023-01-16 22:44:50 +08:00
|
|
|
/*
|
|
|
|
* Disable runtime PM. In case runtime PM is disabled in the kernel,
|
|
|
|
* make sure to turn power off manually.
|
|
|
|
*/
|
2019-10-05 00:05:25 +08:00
|
|
|
pm_runtime_disable(imx290->dev);
|
|
|
|
if (!pm_runtime_status_suspended(imx290->dev))
|
2023-01-16 22:44:51 +08:00
|
|
|
imx290_power_off(imx290);
|
2019-10-05 00:05:25 +08:00
|
|
|
pm_runtime_set_suspended(imx290->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id imx290_of_match[] = {
|
2023-02-16 06:29:50 +08:00
|
|
|
{
|
|
|
|
/* Deprecated - synonym for "sony,imx290lqr" */
|
|
|
|
.compatible = "sony,imx290",
|
|
|
|
.data = &imx290_models[IMX290_MODEL_IMX290LQR],
|
|
|
|
}, {
|
|
|
|
.compatible = "sony,imx290lqr",
|
|
|
|
.data = &imx290_models[IMX290_MODEL_IMX290LQR],
|
|
|
|
}, {
|
|
|
|
.compatible = "sony,imx290llr",
|
|
|
|
.data = &imx290_models[IMX290_MODEL_IMX290LLR],
|
2023-02-17 17:52:21 +08:00
|
|
|
}, {
|
|
|
|
.compatible = "sony,imx327lqr",
|
|
|
|
.data = &imx290_models[IMX290_MODEL_IMX327LQR],
|
2023-02-16 06:29:50 +08:00
|
|
|
},
|
|
|
|
{ /* sentinel */ },
|
2019-10-05 00:05:25 +08:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, imx290_of_match);
|
|
|
|
|
|
|
|
static struct i2c_driver imx290_i2c_driver = {
|
2023-05-14 20:04:07 +08:00
|
|
|
.probe = imx290_probe,
|
2019-10-05 00:05:25 +08:00
|
|
|
.remove = imx290_remove,
|
|
|
|
.driver = {
|
2023-05-14 20:04:07 +08:00
|
|
|
.name = "imx290",
|
2023-02-08 00:13:12 +08:00
|
|
|
.pm = pm_ptr(&imx290_pm_ops),
|
|
|
|
.of_match_table = imx290_of_match,
|
2019-10-05 00:05:25 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(imx290_i2c_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Sony IMX290 CMOS Image Sensor Driver");
|
|
|
|
MODULE_AUTHOR("FRAMOS GmbH");
|
|
|
|
MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|