From 7b47514b6e2f86e2c9a40217fe8db98923f1682b Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 14:56:09 +0100 Subject: [PATCH 1/8] drivers: media: imx708: Increase usable link frequencies Add support for three different usable link frequencies (default 450Mhz, 447Mhz, and 453MHz) for the IMX708 camera sensor. The choice of frequency is handled thorugh the "link-frequency" overlay parameter. Signed-off-by: Naushir Patuck --- drivers/media/i2c/imx708.c | 94 +++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/imx708.c b/drivers/media/i2c/imx708.c index 7f5f07e4e16e54..7b6983c31cd5e4 100644 --- a/drivers/media/i2c/imx708.c +++ b/drivers/media/i2c/imx708.c @@ -35,8 +35,6 @@ #define IMX708_XCLK_FREQ 24000000 -#define IMX708_DEFAULT_LINK_FREQ 450000000 - /* Default initial pixel rate, will get updated for each mode. */ #define IMX708_INITIAL_PIXEL_RATE 590000000 @@ -181,6 +179,50 @@ static const u8 pdaf_gains[2][9] = { { 0x35, 0x35, 0x35, 0x38, 0x3e, 0x46, 0x4c, 0x4c, 0x4c } }; +/* Link frequency setup */ +enum { + IMX708_LINK_FREQ_450MHZ, + IMX708_LINK_FREQ_447MHZ, + IMX708_LINK_FREQ_453MHZ, +}; + +static const s64 link_freqs[] = { + [IMX708_LINK_FREQ_450MHZ] = 450000000, + [IMX708_LINK_FREQ_447MHZ] = 447000000, + [IMX708_LINK_FREQ_453MHZ] = 453000000, +}; + +/* 450MHz is the nominal "default" link frequency */ +static const struct imx708_reg link_450Mhz_regs[] = { + {0x030E, 0x01}, + {0x030F, 0x2c}, +}; + +static const struct imx708_reg link_447Mhz_regs[] = { + {0x030E, 0x01}, + {0x030F, 0x2a}, +}; + +static const struct imx708_reg link_453Mhz_regs[] = { + {0x030E, 0x01}, + {0x030F, 0x2e}, +}; + +static const struct imx708_reg_list link_freq_regs[] = { + [IMX708_LINK_FREQ_450MHZ] = { + .regs = link_450Mhz_regs, + .num_of_regs = ARRAY_SIZE(link_450Mhz_regs) + }, + [IMX708_LINK_FREQ_447MHZ] = { + .regs = link_447Mhz_regs, + .num_of_regs = ARRAY_SIZE(link_447Mhz_regs) + }, + [IMX708_LINK_FREQ_453MHZ] = { + .regs = link_453Mhz_regs, + .num_of_regs = ARRAY_SIZE(link_453Mhz_regs) + }, +}; + static const struct imx708_reg mode_common_regs[] = { {0x0100, 0x00}, {0x0136, 0x18}, @@ -278,8 +320,6 @@ static const struct imx708_reg mode_4608x2592_regs[] = { {0x0307, 0x7C}, {0x030B, 0x02}, {0x030D, 0x04}, - {0x030E, 0x01}, - {0x030F, 0x2C}, {0x0310, 0x01}, {0x3CA0, 0x00}, {0x3CA1, 0x64}, @@ -376,8 +416,6 @@ static const struct imx708_reg mode_2x2binned_regs[] = { {0x0307, 0x7A}, {0x030B, 0x02}, {0x030D, 0x04}, - {0x030E, 0x01}, - {0x030F, 0x2C}, {0x0310, 0x01}, {0x3CA0, 0x00}, {0x3CA1, 0x3C}, @@ -472,8 +510,6 @@ static const struct imx708_reg mode_2x2binned_720p_regs[] = { {0x0307, 0x76}, {0x030B, 0x02}, {0x030D, 0x04}, - {0x030E, 0x01}, - {0x030F, 0x2C}, {0x0310, 0x01}, {0x3CA0, 0x00}, {0x3CA1, 0x3C}, @@ -568,8 +604,6 @@ static const struct imx708_reg mode_hdr_regs[] = { {0x0307, 0xA2}, {0x030B, 0x02}, {0x030D, 0x04}, - {0x030E, 0x01}, - {0x030F, 0x2C}, {0x0310, 0x01}, {0x3CA0, 0x00}, {0x3CA1, 0x00}, @@ -795,6 +829,7 @@ struct imx708 { struct v4l2_ctrl *blue_balance; struct v4l2_ctrl *notify_gains; struct v4l2_ctrl *hdr_mode; + struct v4l2_ctrl *link_freq; /* Current mode */ const struct imx708_mode *mode; @@ -813,6 +848,8 @@ struct imx708 { /* Current long exposure factor in use. Set through V4L2_CID_VBLANK */ unsigned int long_exp_shift; + + unsigned int link_freq_idx; }; static inline struct imx708 *to_imx708(struct v4l2_subdev *_sd) @@ -1428,7 +1465,7 @@ static int imx708_get_selection(struct v4l2_subdev *sd, static int imx708_start_streaming(struct imx708 *imx708) { struct i2c_client *client = v4l2_get_subdevdata(&imx708->sd); - const struct imx708_reg_list *reg_list; + const struct imx708_reg_list *reg_list, *freq_regs; int i, ret; u32 val; @@ -1474,6 +1511,16 @@ static int imx708_start_streaming(struct imx708 *imx708) return ret; } + /* Update the link frequency registers */ + freq_regs = &link_freq_regs[imx708->link_freq_idx]; + ret = imx708_write_regs(imx708, freq_regs->regs, + freq_regs->num_of_regs); + if (ret) { + dev_err(&client->dev, "%s failed to set link frequency registers\n", + __func__); + return ret; + } + /* Apply customized values from user */ ret = __v4l2_ctrl_handler_setup(imx708->sd.ctrl_handler); if (ret) @@ -1720,6 +1767,7 @@ static int imx708_init_controls(struct imx708 *imx708) struct v4l2_ctrl_handler *ctrl_hdlr; struct i2c_client *client = v4l2_get_subdevdata(&imx708->sd); struct v4l2_fwnode_device_properties props; + struct v4l2_ctrl *ctrl; unsigned int i; int ret; @@ -1738,6 +1786,12 @@ static int imx708_init_controls(struct imx708 *imx708) IMX708_INITIAL_PIXEL_RATE, 1, IMX708_INITIAL_PIXEL_RATE); + ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr, &imx708_ctrl_ops, + V4L2_CID_LINK_FREQ, 0, 0, + &link_freqs[imx708->link_freq_idx]); + if (ctrl) + ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + /* * Create the controls here, but mode specific limits are setup * in the imx708_set_framing_limits() call below. @@ -1833,13 +1887,14 @@ static void imx708_free_controls(struct imx708 *imx708) mutex_destroy(&imx708->mutex); } -static int imx708_check_hwcfg(struct device *dev) +static int imx708_check_hwcfg(struct device *dev, struct imx708 *imx708) { struct fwnode_handle *endpoint; struct v4l2_fwnode_endpoint ep_cfg = { .bus_type = V4L2_MBUS_CSI2_DPHY }; int ret = -EINVAL; + int i; endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL); if (!endpoint) { @@ -1864,11 +1919,18 @@ static int imx708_check_hwcfg(struct device *dev) goto error_out; } - if (ep_cfg.nr_of_link_frequencies != 1 || - ep_cfg.link_frequencies[0] != IMX708_DEFAULT_LINK_FREQ) { + for (i = 0; i < ARRAY_SIZE(link_freqs); i++) { + if (link_freqs[i] == ep_cfg.link_frequencies[0]) { + imx708->link_freq_idx = i; + break; + } + } + + if (i == ARRAY_SIZE(link_freqs)) { dev_err(dev, "Link frequency not supported: %lld\n", ep_cfg.link_frequencies[0]); - goto error_out; + ret = -EINVAL; + goto error_out; } ret = 0; @@ -1893,7 +1955,7 @@ static int imx708_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&imx708->sd, client, &imx708_subdev_ops); /* Check the hardware configuration in device tree */ - if (imx708_check_hwcfg(dev)) + if (imx708_check_hwcfg(dev, imx708)) return -EINVAL; /* Get system clock (xclk) */ From dc08e77e54810755b1d2803f675c74dd25ad9434 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 14:56:49 +0100 Subject: [PATCH 2/8] dtoverlays: Add link-frequency parameter for the Sony IMX708 sensor Add a parameter to change the sensor device CSI-2 link frequency to one of the following values: 450Mhz (default), 447Mhz, or 453Mhz. Signed-off-by: Naushir Patuck --- arch/arm/boot/dts/overlays/README | 2 ++ arch/arm/boot/dts/overlays/imx708-overlay.dts | 1 + 2 files changed, 3 insertions(+) diff --git a/arch/arm/boot/dts/overlays/README b/arch/arm/boot/dts/overlays/README index 50f14e009d2fa5..875b58ab172371 100644 --- a/arch/arm/boot/dts/overlays/README +++ b/arch/arm/boot/dts/overlays/README @@ -2417,6 +2417,8 @@ Params: rotation Mounting rotation of the camera sensor (0 or configuring the sensor (default on) cam0 Adopt the default configuration for CAM0 on a Compute Module (CSI0, i2c_vc, and cam0_reg). + link-frequency Allowable link frequency values to use in Hz: + 450000000 (default), 447000000, 453000000. Name: iqaudio-codec diff --git a/arch/arm/boot/dts/overlays/imx708-overlay.dts b/arch/arm/boot/dts/overlays/imx708-overlay.dts index 9107e985c2a8f2..6efbe0943211e3 100644 --- a/arch/arm/boot/dts/overlays/imx708-overlay.dts +++ b/arch/arm/boot/dts/overlays/imx708-overlay.dts @@ -88,6 +88,7 @@ <&vcm_node>, "VDD-supply:0=",<&cam0_reg>; vcm = <&vcm_node>, "status", <0>, "=4"; + link-frequency = <&cam_endpoint>,"link-frequencies#0"; }; }; From 5e935c63359efdd4e4f2c95cf0b6ed5236f2ad93 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 10:07:26 +0100 Subject: [PATCH 3/8] drivers: media: imx708: Remove unused control fields Remove unused and redundant control fields from the state structure. Signed-off-by: Naushir Patuck --- drivers/media/i2c/imx708.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/imx708.c b/drivers/media/i2c/imx708.c index 7b6983c31cd5e4..6811e80307b950 100644 --- a/drivers/media/i2c/imx708.c +++ b/drivers/media/i2c/imx708.c @@ -825,9 +825,6 @@ struct imx708 { struct v4l2_ctrl *hflip; struct v4l2_ctrl *vblank; struct v4l2_ctrl *hblank; - struct v4l2_ctrl *red_balance; - struct v4l2_ctrl *blue_balance; - struct v4l2_ctrl *notify_gains; struct v4l2_ctrl *hdr_mode; struct v4l2_ctrl *link_freq; @@ -1205,12 +1202,12 @@ static int imx708_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_NOTIFY_GAINS: ret = imx708_write_reg(imx708, IMX708_REG_COLOUR_BALANCE_BLUE, IMX708_REG_VALUE_16BIT, - imx708->notify_gains->p_new.p_u32[0]); + ctrl->p_new.p_u32[0]); if (ret) break; ret = imx708_write_reg(imx708, IMX708_REG_COLOUR_BALANCE_RED, IMX708_REG_VALUE_16BIT, - imx708->notify_gains->p_new.p_u32[3]); + ctrl->p_new.p_u32[3]); break; case V4L2_CID_WIDE_DYNAMIC_RANGE: /* Already handled above. */ @@ -1842,8 +1839,7 @@ static int imx708_init_controls(struct imx708 *imx708) /* The "Solid color" pattern is white by default */ } - imx708->notify_gains = v4l2_ctrl_new_custom(ctrl_hdlr, - &imx708_notify_gains_ctrl, NULL); + v4l2_ctrl_new_custom(ctrl_hdlr, &imx708_notify_gains_ctrl, NULL); imx708->hdr_mode = v4l2_ctrl_new_std(ctrl_hdlr, &imx708_ctrl_ops, V4L2_CID_WIDE_DYNAMIC_RANGE, From 73d6ede1009447189ba3d68d0ae62a7c26e963a8 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 10:33:51 +0100 Subject: [PATCH 4/8] drivers: media: imx708: Tidy-ups to address upstream review comments This commit addresses vaious tidy-ups requesed for upstreaming the IMX708 driver. Notably: - Remove #define IMX708_NUM_SUPPLIES and use ARRAY_SIZE() directly - Use dev_err_probe where possible in imx708_probe() - Fix error handling paths in imx708_probe() Signed-off-by: Naushir Patuck --- drivers/media/i2c/imx708.c | 61 +++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/drivers/media/i2c/imx708.c b/drivers/media/i2c/imx708.c index 6811e80307b950..f5b8cc8e084041 100644 --- a/drivers/media/i2c/imx708.c +++ b/drivers/media/i2c/imx708.c @@ -792,8 +792,6 @@ static const char * const imx708_supply_name[] = { "VDDL", /* IF (1.8V) supply */ }; -#define IMX708_NUM_SUPPLIES ARRAY_SIZE(imx708_supply_name) - /* * Initialisation delay between XCLR low->high and the moment when the sensor * can start capture (i.e. can leave software standby), given by T7 in the @@ -815,7 +813,7 @@ struct imx708 { u32 xclk_freq; struct gpio_desc *reset_gpio; - struct regulator_bulk_data supplies[IMX708_NUM_SUPPLIES]; + struct regulator_bulk_data supplies[ARRAY_SIZE(imx708_supply_name)]; struct v4l2_ctrl_handler ctrl_handler; /* V4L2 Controls */ @@ -935,9 +933,10 @@ static int imx708_write_regs(struct imx708 *imx708, { struct i2c_client *client = v4l2_get_subdevdata(&imx708->sd); unsigned int i; - int ret; for (i = 0; i < len; i++) { + int ret; + ret = imx708_write_reg(imx708, regs[i].address, 1, regs[i].val); if (ret) { dev_err_ratelimited(&client->dev, @@ -1025,8 +1024,6 @@ static int imx708_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) static int imx708_set_exposure(struct imx708 *imx708, unsigned int val) { - int ret; - val = max(val, imx708->mode->exposure_lines_min); val -= val % imx708->mode->exposure_lines_step; @@ -1034,11 +1031,9 @@ static int imx708_set_exposure(struct imx708 *imx708, unsigned int val) * In HDR mode this will set the longest exposure. The sensor * will automatically divide the medium and short ones by 4,16. */ - ret = imx708_write_reg(imx708, IMX708_REG_EXPOSURE, - IMX708_REG_VALUE_16BIT, - val >> imx708->long_exp_shift); - - return ret; + return imx708_write_reg(imx708, IMX708_REG_EXPOSURE, + IMX708_REG_VALUE_16BIT, + val >> imx708->long_exp_shift); } static void imx708_adjust_exposure_range(struct imx708 *imx708, @@ -1071,7 +1066,7 @@ static int imx708_set_analogue_gain(struct imx708 *imx708, unsigned int val) static int imx708_set_frame_length(struct imx708 *imx708, unsigned int val) { - int ret = 0; + int ret; imx708->long_exp_shift = 0; @@ -1091,8 +1086,8 @@ static int imx708_set_frame_length(struct imx708 *imx708, unsigned int val) static void imx708_set_framing_limits(struct imx708 *imx708) { - unsigned int hblank; const struct imx708_mode *mode = imx708->mode; + unsigned int hblank; __v4l2_ctrl_modify_range(imx708->pixel_rate, mode->pixel_rate, mode->pixel_rate, @@ -1599,7 +1594,7 @@ static int imx708_power_on(struct device *dev) struct imx708 *imx708 = to_imx708(sd); int ret; - ret = regulator_bulk_enable(IMX708_NUM_SUPPLIES, + ret = regulator_bulk_enable(ARRAY_SIZE(imx708_supply_name), imx708->supplies); if (ret) { dev_err(&client->dev, "%s: failed to enable regulators\n", @@ -1621,7 +1616,8 @@ static int imx708_power_on(struct device *dev) return 0; reg_off: - regulator_bulk_disable(IMX708_NUM_SUPPLIES, imx708->supplies); + regulator_bulk_disable(ARRAY_SIZE(imx708_supply_name), + imx708->supplies); return ret; } @@ -1632,7 +1628,8 @@ static int imx708_power_off(struct device *dev) struct imx708 *imx708 = to_imx708(sd); gpiod_set_value_cansleep(imx708->reset_gpio, 0); - regulator_bulk_disable(IMX708_NUM_SUPPLIES, imx708->supplies); + regulator_bulk_disable(ARRAY_SIZE(imx708_supply_name), + imx708->supplies); clk_disable_unprepare(imx708->xclk); /* Force reprogramming of the common registers when powered up again. */ @@ -1679,11 +1676,11 @@ static int imx708_get_regulators(struct imx708 *imx708) struct i2c_client *client = v4l2_get_subdevdata(&imx708->sd); unsigned int i; - for (i = 0; i < IMX708_NUM_SUPPLIES; i++) + for (i = 0; i < ARRAY_SIZE(imx708_supply_name); i++) imx708->supplies[i].supply = imx708_supply_name[i]; return devm_regulator_bulk_get(&client->dev, - IMX708_NUM_SUPPLIES, + ARRAY_SIZE(imx708_supply_name), imx708->supplies); } @@ -1956,23 +1953,19 @@ static int imx708_probe(struct i2c_client *client) /* Get system clock (xclk) */ imx708->xclk = devm_clk_get(dev, NULL); - if (IS_ERR(imx708->xclk)) { - dev_err(dev, "failed to get xclk\n"); - return PTR_ERR(imx708->xclk); - } + if (IS_ERR(imx708->xclk)) + return dev_err_probe(dev, PTR_ERR(imx708->xclk), + "failed to get xclk\n"); imx708->xclk_freq = clk_get_rate(imx708->xclk); - if (imx708->xclk_freq != IMX708_XCLK_FREQ) { - dev_err(dev, "xclk frequency not supported: %d Hz\n", - imx708->xclk_freq); - return -EINVAL; - } + if (imx708->xclk_freq != IMX708_XCLK_FREQ) + return dev_err_probe(dev, -EINVAL, + "xclk frequency not supported: %d Hz\n", + imx708->xclk_freq); ret = imx708_get_regulators(imx708); - if (ret) { - dev_err(dev, "failed to get regulators\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); /* Request optional enable pin */ imx708->reset_gpio = devm_gpiod_get_optional(dev, "reset", @@ -2001,7 +1994,7 @@ static int imx708_probe(struct i2c_client *client) /* This needs the pm runtime to be registered. */ ret = imx708_init_controls(imx708); if (ret) - goto error_power_off; + goto error_pm_runtime; /* Initialize subdev */ imx708->sd.internal_ops = &imx708_internal_ops; @@ -2033,9 +2026,11 @@ static int imx708_probe(struct i2c_client *client) error_handler_free: imx708_free_controls(imx708); -error_power_off: +error_pm_runtime: pm_runtime_disable(&client->dev); pm_runtime_set_suspended(&client->dev); + +error_power_off: imx708_power_off(&client->dev); return ret; From c656fbc93bbf477a059e88165b48519e147e5276 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 11:52:25 +0100 Subject: [PATCH 5/8] dt-bindings: media: i2c: Replace IMX708 sensor binding documentation file Replace the existing imx708.yaml file with sony,imx708.yaml that follows the latest devicetree conventions for camera sensors. Signed-off-by: Naushir Patuck --- .../devicetree/bindings/media/i2c/imx708.yaml | 119 ---------------- .../bindings/media/i2c/sony,imx708.yaml | 128 ++++++++++++++++++ MAINTAINERS | 2 +- 3 files changed, 129 insertions(+), 120 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/i2c/imx708.yaml create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx708.yaml diff --git a/Documentation/devicetree/bindings/media/i2c/imx708.yaml b/Documentation/devicetree/bindings/media/i2c/imx708.yaml deleted file mode 100644 index 4b8645f6880c5f..00000000000000 --- a/Documentation/devicetree/bindings/media/i2c/imx708.yaml +++ /dev/null @@ -1,119 +0,0 @@ -# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/media/i2c/imx708.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Sony 1/2.3-Inch 12Mpixel CMOS Digital Image Sensor - -maintainers: - - Naushir Patuck - -description: |- - The Sony IMX708 is a 1/2.3-inch CMOS active pixel digital image sensor - with an active array size of 4608H x 2592V. It is programmable through - I2C interface. The I2C address is fixed to 0x1A as per sensor data sheet. - Image data is sent through MIPI CSI-2, which is configured as either 2 or - 4 data lanes. - -properties: - compatible: - const: sony,imx708 - - reg: - description: I2C device address - maxItems: 1 - - clocks: - maxItems: 1 - - VDIG-supply: - description: - Digital I/O voltage supply, 1.1 volts - - VANA1-supply: - description: - Analog1 voltage supply, 2.8 volts - - VANA2-supply: - description: - Analog2 voltage supply, 1.8 volts - - VDDL-supply: - description: - Digital core voltage supply, 1.8 volts - - reset-gpios: - description: |- - Reference to the GPIO connected to the xclr pin, if any. - Must be released (set high) after all supplies and INCK are applied. - - # See ../video-interfaces.txt for more details - port: - type: object - properties: - endpoint: - type: object - properties: - data-lanes: - description: |- - The sensor supports either two-lane, or four-lane operation. - For two-lane operation the property must be set to <1 2>. - items: - - const: 1 - - const: 2 - - clock-noncontinuous: - type: boolean - description: |- - MIPI CSI-2 clock is non-continuous if this property is present, - otherwise it's continuous. - - link-frequencies: - allOf: - - $ref: /schemas/types.yaml#/definitions/uint64-array - description: - Allowed data bus frequencies. - - required: - - link-frequencies - -required: - - compatible - - reg - - clocks - - VANA1-supply - - VANA2-supply - - VDIG-supply - - VDDL-supply - - port - -additionalProperties: false - -examples: - - | - i2c0 { - #address-cells = <1>; - #size-cells = <0>; - - imx708: sensor@1a { - compatible = "sony,imx708"; - reg = <0x1a>; - clocks = <&imx708_clk>; - VANA1-supply = <&imx708_vana1>; /* 1.8v */ - VANA2-supply = <&imx708_vana2>; /* 2.8v */ - VDIG-supply = <&imx708_vdig>; /* 1.1v */ - VDDL-supply = <&imx708_vddl>; /* 1.8v */ - - port { - imx708_0: endpoint { - remote-endpoint = <&csi1_ep>; - data-lanes = <1 2>; - clock-noncontinuous; - link-frequencies = /bits/ 64 <450000000>; - }; - }; - }; - }; - -... diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx708.yaml b/Documentation/devicetree/bindings/media/i2c/sony,imx708.yaml new file mode 100644 index 00000000000000..286aad2e8c697c --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/sony,imx708.yaml @@ -0,0 +1,128 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/sony,imx708.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sony 1/2.3-Inch 12Mpixel CMOS Digital Image Sensor + +maintainers: + - Raspberry Pi Kernel Maintenance + +description: |- + The Sony IMX708 is a 1/2.3-inch CMOS active pixel digital image sensor + with an active array size of 4608H x 2592V. It is programmable through + I2C interface. The I2C address is fixed to 0x1A as per sensor data sheet. + Image data is sent through MIPI CSI-2, which is configured as either 2 or + 4 data lanes. + +properties: + compatible: + const: sony,imx708 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + description: Input clock (6 to 27 MHz) + items: + - const: inck + + vdig-supply: + description: + Digital I/O voltage supply, 1.1 volts + + vana1-supply: + description: + Analog1 voltage supply, 2.8 volts + + vana2-supply: + description: + Analog2 voltage supply, 1.8 volts + + vddl-supply: + description: + Digital core voltage supply, 1.8 volts + + reset-gpios: + description: Sensor reset (XCLR) GPIO + maxItems: 1 + + port: + $ref: /schemas/graph.yaml#/$defs/port-base + description: | + Video output port + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + anyOf: + - items: + - const: 1 + - const: 2 + - items: + - const: 1 + - const: 2 + - const: 3 + - const: 4 + + link-frequencies: true + + required: + - data-lanes + - link-frequencies + + additionalProperties: false + +required: + - compatible + - reg + - clocks + - clock-names + - vdig-supply + - vana1-supply + - vana2-supply + - vddl-supply + - port + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + imx708: camera-sensor@1a { + compatible = "sony,imx708"; + reg = <0x1a>; + + clocks = <&clk 90>; + clock-names = "inck"; + + vdig-supply = <&camera_vdig>; + vana1-supply = <&camera_vana1>; + vana2-supply = <&camera_vana2>; + vddl-supply = <&camera_vddl>; + + reset-gpios = <&gpio 35 GPIO_ACTIVE_LOW>; + + port { + imx708_ep: endpoint { + data-lanes = <1 2>; + link-frequencies = /bits/ 64 <450000000>; + remote-endpoint = <&csi_ep>; + }; + }; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index 548ca27e4565fb..b6a1211560275f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19330,7 +19330,7 @@ M: Raspberry Pi Kernel Maintenance L: linux-media@vger.kernel.org S: Maintained T: git git://linuxtv.org/media_tree.git -F: Documentation/devicetree/bindings/media/i2c/imx708.yaml +F: Documentation/devicetree/bindings/media/i2c/sony,imx708.yaml F: drivers/media/i2c/imx708.c SONY MEMORYSTICK SUBSYSTEM From ef74ecc3ed15fe5a652f8a6de5e82c5fab7c44fa Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 15:08:10 +0100 Subject: [PATCH 6/8] dtoverlays: Follow the standard devicetree labels for IMX708 Switch the system clock name from "xclk" to "inclk". Use lower case lables for all regulator names. Signed-off-by: Naushir Patuck --- arch/arm/boot/dts/overlays/imx708.dtsi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm/boot/dts/overlays/imx708.dtsi b/arch/arm/boot/dts/overlays/imx708.dtsi index 1381caf226681d..1558458d58ecbb 100644 --- a/arch/arm/boot/dts/overlays/imx708.dtsi +++ b/arch/arm/boot/dts/overlays/imx708.dtsi @@ -6,12 +6,12 @@ cam_node: imx708@1a { status = "disabled"; clocks = <&cam1_clk>; - clock-names = "xclk"; + clock-names = "inclk"; - VANA1-supply = <&cam1_reg>; /* 2.8v */ - VANA2-supply = <&cam_dummy_reg>;/* 1.8v */ - VDIG-supply = <&cam_dummy_reg>; /* 1.1v */ - VDDL-supply = <&cam_dummy_reg>; /* 1.8v */ + vana1-supply = <&cam1_reg>; /* 2.8v */ + vana2-supply = <&cam_dummy_reg>;/* 1.8v */ + vdig-supply = <&cam_dummy_reg>; /* 1.1v */ + vddl-supply = <&cam_dummy_reg>; /* 1.8v */ rotation = <180>; orientation = <2>; From fefeb7b1e0f64a9b0eadd7472690b0057442ccfc Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 15:05:33 +0100 Subject: [PATCH 7/8] drivers: media: imx708: Follow the standard devicetree labels Switch the system clock name from "xclk" to "inclk". Use lower case lables for all regulator names. Signed-off-by: Naushir Patuck --- drivers/media/i2c/imx708.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/imx708.c b/drivers/media/i2c/imx708.c index f5b8cc8e084041..39d46be4917289 100644 --- a/drivers/media/i2c/imx708.c +++ b/drivers/media/i2c/imx708.c @@ -33,7 +33,7 @@ #define IMX708_REG_ORIENTATION 0x101 -#define IMX708_XCLK_FREQ 24000000 +#define IMX708_INCLK_FREQ 24000000 /* Default initial pixel rate, will get updated for each mode. */ #define IMX708_INITIAL_PIXEL_RATE 590000000 @@ -786,10 +786,10 @@ static const int imx708_test_pattern_val[] = { /* regulator supplies */ static const char * const imx708_supply_name[] = { /* Supplies can be enabled in any order */ - "VANA1", /* Analog1 (2.8V) supply */ - "VANA2", /* Analog2 (1.8V) supply */ - "VDIG", /* Digital Core (1.1V) supply */ - "VDDL", /* IF (1.8V) supply */ + "vana1", /* Analog1 (2.8V) supply */ + "vana2", /* Analog2 (1.8V) supply */ + "vdig", /* Digital Core (1.1V) supply */ + "vddl", /* IF (1.8V) supply */ }; /* @@ -809,8 +809,8 @@ struct imx708 { struct v4l2_mbus_framefmt fmt; - struct clk *xclk; - u32 xclk_freq; + struct clk *inclk; + u32 inclk_freq; struct gpio_desc *reset_gpio; struct regulator_bulk_data supplies[ARRAY_SIZE(imx708_supply_name)]; @@ -1602,7 +1602,7 @@ static int imx708_power_on(struct device *dev) return ret; } - ret = clk_prepare_enable(imx708->xclk); + ret = clk_prepare_enable(imx708->inclk); if (ret) { dev_err(&client->dev, "%s: failed to enable clock\n", __func__); @@ -1630,7 +1630,7 @@ static int imx708_power_off(struct device *dev) gpiod_set_value_cansleep(imx708->reset_gpio, 0); regulator_bulk_disable(ARRAY_SIZE(imx708_supply_name), imx708->supplies); - clk_disable_unprepare(imx708->xclk); + clk_disable_unprepare(imx708->inclk); /* Force reprogramming of the common registers when powered up again. */ imx708->common_regs_written = false; @@ -1951,17 +1951,17 @@ static int imx708_probe(struct i2c_client *client) if (imx708_check_hwcfg(dev, imx708)) return -EINVAL; - /* Get system clock (xclk) */ - imx708->xclk = devm_clk_get(dev, NULL); - if (IS_ERR(imx708->xclk)) - return dev_err_probe(dev, PTR_ERR(imx708->xclk), - "failed to get xclk\n"); + /* Get system clock (inclk) */ + imx708->inclk = devm_clk_get(dev, "inclk"); + if (IS_ERR(imx708->inclk)) + return dev_err_probe(dev, PTR_ERR(imx708->inclk), + "failed to get inclk\n"); - imx708->xclk_freq = clk_get_rate(imx708->xclk); - if (imx708->xclk_freq != IMX708_XCLK_FREQ) + imx708->inclk_freq = clk_get_rate(imx708->inclk); + if (imx708->inclk_freq != IMX708_INCLK_FREQ) return dev_err_probe(dev, -EINVAL, - "xclk frequency not supported: %d Hz\n", - imx708->xclk_freq); + "inclk frequency not supported: %d Hz\n", + imx708->inclk_freq); ret = imx708_get_regulators(imx708); if (ret) From e7f32387575b26f00c2d7bda30b2f21d30a9693c Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Fri, 31 Mar 2023 12:02:09 +0100 Subject: [PATCH 8/8] drives: media: imx708: Put HFLIP and VFLIP controls in a cluster Create a cluster for the HVLIP and VFLIP controls so they are treated as a single composite control. Signed-off-by: Naushir Patuck --- drivers/media/i2c/imx708.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/imx708.c b/drivers/media/i2c/imx708.c index 39d46be4917289..2453923a4ae3b5 100644 --- a/drivers/media/i2c/imx708.c +++ b/drivers/media/i2c/imx708.c @@ -819,12 +819,14 @@ struct imx708 { /* V4L2 Controls */ struct v4l2_ctrl *pixel_rate; struct v4l2_ctrl *exposure; - struct v4l2_ctrl *vflip; - struct v4l2_ctrl *hflip; struct v4l2_ctrl *vblank; struct v4l2_ctrl *hblank; struct v4l2_ctrl *hdr_mode; struct v4l2_ctrl *link_freq; + struct { + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; + }; /* Current mode */ const struct imx708_mode *mode; @@ -1815,6 +1817,7 @@ static int imx708_init_controls(struct imx708 *imx708) imx708->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx708_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_cluster(2, &imx708->hflip); v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx708_ctrl_ops, V4L2_CID_TEST_PATTERN,