From 8bcc7ba937611f3230a6a2c644f14d5b57b8d735 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:22 +0000 Subject: [PATCH 1/4] dt-bindings: media: sony,imx386: Describe the IMX787 variant The Pixel 9 Pro Fold's main camera is a Sony IMX787: the IMX386's register map behind a MIPI CSI-2 C-PHY output, in a module whose AF/OIS controller shares the sensor's XCLR line and adds its own supplies. Add the sony,imx787 compatible, its vaux, vaux2 and vana2 supplies (rejected for the IMX386), and a bus-type that allows C-PHY, with data-lanes then counting trios. The IMX386's properties and requirements are unchanged. Assisted-by: LLM Signed-off-by: Nate Crawford --- .../bindings/media/i2c/sony,imx386.yaml | 76 +++++++++++++++++-- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml b/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml index 43d08cf600..207e16df24 100644 --- a/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml +++ b/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml @@ -4,22 +4,37 @@ $id: http://devicetree.org/schemas/media/i2c/sony,imx386.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Sony IMX386 image sensor +title: Sony IMX386 and IMX787 image sensors maintainers: - Derek Ross description: Sony IMX386 12 MP Bayer CMOS sensor with a MIPI CSI-2 D-PHY output, - controlled over I2C. Its initialisation and readout modes are loaded from - a data file named by firmware-name. + controlled over I2C, and the IMX787 (the Pixel 9 Pro Fold's main camera), + which uses a MIPI CSI-2 C-PHY output and the same register map. + Their initialisation and readout modes are loaded from a data file named + by firmware-name. allOf: - $ref: /schemas/media/video-interface-devices.yaml# + - if: + properties: + compatible: + not: + contains: + const: sony,imx787 + then: + properties: + vaux-supply: false + vaux2-supply: false + vana2-supply: false properties: compatible: - const: sony,imx386 + enum: + - sony,imx386 + - sony,imx787 reg: maxItems: 1 @@ -29,7 +44,9 @@ properties: reset-gpios: maxItems: 1 - description: XCLR, active low. + description: + XCLR, active low. On the IMX787 the line may be shared with the + module's AF/OIS controller. vif-supply: description: Interface (1.8 V) supply. @@ -40,6 +57,18 @@ properties: vana-supply: description: Analog supply. + vana2-supply: + description: Second analog supply (IMX787), on after vana-supply. + + vaux-supply: + description: + The module's AF/OIS controller's analog supply (IMX787), which the + module's power-up order switches on before the sensor's own. + + vaux2-supply: + description: + The module's AF/OIS actuator supply (IMX787), on after vaux-supply. + vbb-supply: description: Board supply feeding the module's analog regulator, to be switched on @@ -79,7 +108,12 @@ properties: unevaluatedProperties: false properties: + bus-type: + enum: + - 1 # MEDIA_BUS_TYPE_CSI2_CPHY (IMX787) + - 4 # MEDIA_BUS_TYPE_CSI2_DPHY data-lanes: + description: D-PHY data lanes, or C-PHY trios. minItems: 2 maxItems: 4 link-frequencies: true @@ -129,3 +163,35 @@ examples: }; }; }; + + - | + #include + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera@1a { + compatible = "sony,imx787"; + reg = <0x1a>; + clocks = <&mclk>; + reset-gpios = <&gpp10 2 GPIO_ACTIVE_LOW>; + vif-supply = <&vddio_cam>; + vaux-supply = <&afois_vana>; + vaux2-supply = <&afois_vm>; + vana-supply = <&main_avdd1>; + vana2-supply = <&main_avdd2>; + vdig-supply = <&main_dvdd>; + firmware-name = "omamobile/camera/imx787-main.bin"; + orientation = <1>; + + port { + endpoint { + remote-endpoint = <&csis1_in>; + bus-type = ; + data-lanes = <1 2 3>; + link-frequencies = /bits/ 64 <691200000>; + }; + }; + }; + }; From fb68344b51b362e0ef3fd1d8b3c535be52796936 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:22 +0000 Subject: [PATCH 2/4] media: i2c: imx386: Add the IMX787 C-PHY variant The Pixel 9 Pro Fold's main camera is a Sony IMX787. It reports model 0x0787 at 0x0016 and has the IMX386's CCS-style register map, so the mode, exposure and gain registers this driver writes apply unchanged; its initialisation and readout tables come from the data file, as the IMX386's do. Three things differ: - the module has eight supplies, powered in the order of Google's GPL zuma-comet-camera.dtsi (rear_main_camera_power_seq): the board's vbb and vbuck, then vif, the AF/OIS controller's vaux and vaux2, vana, vana2 and vdig. The AF/OIS and board supplies are optional; - its XCLR reset line is shared with that AF/OIS controller, so it is taken through the reset framework as a shared reset, not as a GPIO; - it sends over a three-trio MIPI CSI-2 C-PHY link. Make the supplies, chip ID, reset sharing and subdev name per variant (libcamera picks its sensor helper by name, so the IMX787 registers as imx787), and check the data file against the matched chip ID. Pass the matched variant's bus type to the endpoint parser: D-PHY for IMX386 and C-PHY for IMX787. The parser rejects an explicitly mismatched type. Without a data file, power up the IMX787, read and log its model ID, power it down and fail the probe. A board can check its wiring with no data file and without writing to the sensor. The IMX386 keeps its existing D-PHY parse and missing-data behavior. Tested on a Pixel 9 Pro Fold with a v7.3-rc6 based kernel: without a data file the sensor identifies as 0x0787 and the probe stops there; with one it streams 4000x3000 RAW10 over the C-PHY link into the CSIS receiver, and libcamera's simple pipeline gives correct images (the gain range is fixed in the next patch). The explicit endpoint type is part of this revision. Assisted-by: LLM Signed-off-by: Nate Crawford --- drivers/media/i2c/imx386.c | 149 +++++++++++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 22 deletions(-) diff --git a/drivers/media/i2c/imx386.c b/drivers/media/i2c/imx386.c index 28ef2934f4..36e5f8f30a 100644 --- a/drivers/media/i2c/imx386.c +++ b/drivers/media/i2c/imx386.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Sony IMX386 image sensor driver + * Sony IMX386 and IMX787 image sensor driver * * The IMX386 is a 12 MP Sony Bayer sensor with an SMIA++/CCS-style register * map (16-bit addresses, 8-bit values). The standard registers - mode @@ -22,8 +22,11 @@ #include #include #include +#include #include +#include #include +#include #include #include @@ -40,6 +43,7 @@ #define IMX386_REG_FRAME_COUNT CCI_REG8(0x0005) #define IMX386_REG_CHIP_ID CCI_REG16(0x0016) #define IMX386_CHIP_ID 0x0386 +#define IMX787_CHIP_ID 0x0787 #define IMX386_REG_EXPOSURE CCI_REG16(0x0202) #define IMX386_REG_ANALOG_GAIN CCI_REG16(0x0204) /* per colour channel: Gr, R, B, Gb (CCS) */ @@ -126,13 +130,61 @@ struct imx386_mode { unsigned int num_regs; }; +#define IMX386_MAX_SUPPLIES 8 + +/* + * A part: its chip ID, its supplies in power-up order (the board supplies + * vbb and vbuck first, then the module's), which of them are optional, and + * whether its reset line is shared with another device of the module. + */ +struct imx386_variant { + enum v4l2_mbus_type bus_type; + u16 chip_id; + const char * const *supplies; + unsigned int num_supplies; + u32 optional; /* bit per supply */ + bool shared_reset; + bool identify_only; /* without a data file, check the ID */ + const char *model; /* subdev name, if not "imx386" */ +}; + static const char * const imx386_supply_names[] = { /* board supplies feeding the module's regulators, first (optional) */ "vbb", "vbuck", "vif", "vdig", "vana", }; -#define IMX386_NUM_SUPPLIES ARRAY_SIZE(imx386_supply_names) +static const struct imx386_variant imx386_variant = { + .bus_type = V4L2_MBUS_CSI2_DPHY, + .chip_id = IMX386_CHIP_ID, + .supplies = imx386_supply_names, + .num_supplies = ARRAY_SIZE(imx386_supply_names), + .optional = BIT(0) | BIT(1), +}; + +/* + * IMX787, the Pixel 9 Pro Fold's main camera, in stock's module order + * (rear_main_camera_power_seq in Google's GPL zuma-comet-camera.dtsi): the + * I/O supply, the AF/OIS controller's analog and actuator supplies, the + * two analog supplies, the digital supply, then the clock and reset. The + * module's AF/OIS controller shares the sensor's reset line (stock gives + * both the same reset-gpios), so the line is a shared reset. The AF/OIS + * supplies are optional for boards without that controller. + */ +static const char * const imx787_supply_names[] = { + "vbb", "vbuck", "vif", "vaux", "vaux2", "vana", "vana2", "vdig", +}; + +static const struct imx386_variant imx787_variant = { + .bus_type = V4L2_MBUS_CSI2_CPHY, + .chip_id = IMX787_CHIP_ID, + .supplies = imx787_supply_names, + .num_supplies = ARRAY_SIZE(imx787_supply_names), + .optional = BIT(0) | BIT(1) | BIT(3) | BIT(4) | BIT(6), + .shared_reset = true, + .identify_only = true, + .model = "imx787", +}; static const u32 imx386_mbus_codes[] = { MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10, @@ -152,7 +204,10 @@ struct imx386 { struct clk *mclk; struct gpio_desc *reset; - struct regulator *supplies[IMX386_NUM_SUPPLIES]; + struct reset_control *rstc; /* instead of reset, when shared */ + const struct imx386_variant *var; + u16 chip_id; /* from the compatible */ + struct regulator *supplies[IMX386_MAX_SUPPLIES]; u32 delays_us[3]; /* after the last supply, after MCLK, after reset */ u32 max_line_mbps; /* receiver's line throughput, MB/s; 0: none */ @@ -297,7 +352,7 @@ static int imx386_load_data(struct imx386 *s) h = (const void *)s->fw->data; if (le32_to_cpu(h->magic) != IMX386_FW_MAGIC || le16_to_cpu(h->version) != IMX386_FW_VERSION || - le16_to_cpu(h->chip_id) != IMX386_CHIP_ID) + le16_to_cpu(h->chip_id) != s->chip_id) goto bad; s->num_modes = le16_to_cpu(h->num_modes); @@ -361,7 +416,7 @@ static int imx386_load_data(struct imx386 *s) static int imx386_check_link_freqs(struct imx386 *s) { struct fwnode_handle *ep; - struct v4l2_fwnode_endpoint bus = { .bus_type = V4L2_MBUS_CSI2_DPHY }; + struct v4l2_fwnode_endpoint bus = { .bus_type = s->var->bus_type }; unsigned int i, j; int ret; @@ -373,7 +428,6 @@ static int imx386_check_link_freqs(struct imx386 *s) fwnode_handle_put(ep); if (ret) return ret; - /* Only modes whose link frequency the board allows are offered. */ for (i = 0; i < s->num_modes; i++) { for (j = 0; j < bus.nr_of_link_frequencies; j++) @@ -447,7 +501,7 @@ static int imx386_power_on(struct device *dev) gpiod_set_value_cansleep(s->reset, 1); - for (i = 0; i < IMX386_NUM_SUPPLIES; i++) { + for (i = 0; i < s->var->num_supplies; i++) { if (!s->supplies[i]) continue; ret = regulator_enable(s->supplies[i]); @@ -461,6 +515,13 @@ static int imx386_power_on(struct device *dev) goto err_supplies; fsleep(s->delays_us[1]); + if (s->rstc) { + ret = reset_control_deassert(s->rstc); + if (ret) { + clk_disable_unprepare(s->mclk); + goto err_supplies; + } + } gpiod_set_value_cansleep(s->reset, 0); fsleep(s->delays_us[2]); @@ -480,11 +541,13 @@ static int imx386_power_off(struct device *dev) int i; gpiod_set_value_cansleep(s->reset, 1); + if (s->rstc) + reset_control_assert(s->rstc); fsleep(1000); clk_disable_unprepare(s->mclk); fsleep(1000); - for (i = IMX386_NUM_SUPPLIES - 1; i >= 0; i--) + for (i = s->var->num_supplies - 1; i >= 0; i--) if (s->supplies[i]) regulator_disable(s->supplies[i]); @@ -897,16 +960,39 @@ static int imx386_identify(struct imx386 *s) if (ret) return dev_err_probe(s->dev, ret, "chip ID read failed\n"); - if (id != IMX386_CHIP_ID) + if (id != s->chip_id) return dev_err_probe(s->dev, -ENODEV, "chip ID 0x%04llx, expected 0x%04x\n", - id, IMX386_CHIP_ID); + id, s->chip_id); dev_info(s->dev, "model 0x%04llx\n", id); return 0; } +/* + * Without its data file a part that allows it is only identified: powered + * up, its model ID read once and powered down again. Nothing is written to + * the sensor, and the probe fails with the result logged, so a first + * bring-up boot can check the wiring before any data file exists. + */ +static int imx386_identify_only(struct imx386 *s) +{ + int ret; + + ret = imx386_power_on(s->dev); + if (ret) + return dev_err_probe(s->dev, ret, "power up\n"); + + ret = imx386_identify(s); + imx386_power_off(s->dev); + if (ret) + return ret; + + dev_info(s->dev, "identified, but no data file: not registered\n"); + return -ENODEV; +} + static int imx386_probe(struct i2c_client *client) { struct device *dev = &client->dev; @@ -919,29 +1005,33 @@ static int imx386_probe(struct i2c_client *client) return -ENOMEM; s->dev = dev; + s->var = device_get_match_data(dev) ?: &imx386_variant; + s->chip_id = s->var->chip_id; v4l2_i2c_subdev_init(&s->sd, client, &imx386_subdev_ops); + if (s->var->model) + v4l2_i2c_subdev_set_name(&s->sd, client, s->var->model, NULL); s->sd.internal_ops = &imx386_internal_ops; s->regmap = devm_cci_regmap_init_i2c(client, 16); if (IS_ERR(s->regmap)) return PTR_ERR(s->regmap); - for (i = 0; i < IMX386_NUM_SUPPLIES; i++) { - const char *name = imx386_supply_names[i]; + for (i = 0; i < s->var->num_supplies; i++) { + const char *name = s->var->supplies[i]; + bool optional = s->var->optional & BIT(i); - /* vbb and vbuck are optional; the module's own are not */ - if (i < 2) + /* the board supplies are optional, and some of the module's */ + if (optional) s->supplies[i] = devm_regulator_get_optional(dev, name); else s->supplies[i] = devm_regulator_get(dev, name); if (IS_ERR(s->supplies[i])) { ret = PTR_ERR(s->supplies[i]); - if (i < 2 && ret == -ENODEV) { + if (optional && ret == -ENODEV) { s->supplies[i] = NULL; continue; } - return dev_err_probe(dev, ret, "%s supply\n", - imx386_supply_names[i]); + return dev_err_probe(dev, ret, "%s supply\n", name); } } @@ -957,11 +1047,24 @@ static int imx386_probe(struct i2c_client *client) if (IS_ERR(s->mclk)) return dev_err_probe(dev, PTR_ERR(s->mclk), "mclk\n"); - s->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(s->reset)) - return dev_err_probe(dev, PTR_ERR(s->reset), "reset\n"); + /* + * A shared reset goes through the reset framework, which makes a + * reset-gpio device for reset-gpios and holds the line asserted until + * the first consumer releases it. + */ + if (s->var->shared_reset) { + s->rstc = devm_reset_control_get_shared(dev, NULL); + if (IS_ERR(s->rstc)) + return dev_err_probe(dev, PTR_ERR(s->rstc), "reset\n"); + } else { + s->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(s->reset)) + return dev_err_probe(dev, PTR_ERR(s->reset), "reset\n"); + } ret = imx386_load_data(s); + if (ret == -ENOENT && s->var->identify_only) + return imx386_identify_only(s); if (ret) return ret; @@ -1042,7 +1145,9 @@ static DEFINE_RUNTIME_DEV_PM_OPS(imx386_pm_ops, imx386_power_off, imx386_power_on, NULL); static const struct of_device_id imx386_of_match[] = { - { .compatible = "sony,imx386" }, + { .compatible = "sony,imx386", .data = &imx386_variant }, + /* Pixel 9 Pro Fold main camera: the same, on C-PHY */ + { .compatible = "sony,imx787", .data = &imx787_variant }, { } }; MODULE_DEVICE_TABLE(of, imx386_of_match); @@ -1058,5 +1163,5 @@ static struct i2c_driver imx386_driver = { }; module_i2c_driver(imx386_driver); -MODULE_DESCRIPTION("Sony IMX386 sensor driver"); +MODULE_DESCRIPTION("Sony IMX386 and IMX787 sensor driver"); MODULE_LICENSE("GPL"); From 9f2e8b2707dfe509cc0ff753652c4b3e074a4bff Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:23 +0000 Subject: [PATCH 3/4] media: i2c: imx386: Give the IMX787 its own analogue gain range The driver caps the analogue gain control at code 480, the IMX386's 16x under its 512 / (512 - code) curve, and every variant shares that cap. The IMX787 follows another curve. On a Pixel 9 Pro Fold, raw frames of a fixed scene at fixed exposure, with the black level of 64 subtracted (it matched a minimum-exposure frame), measure 1.14x, 1.29x, 1.53x, 1.67x and 1.86x at codes 120, 240, 360, 420 and 480. Codes written to 0x0204 past the control's limit read back as written and give 3.2x, 5.3x and 15.1x at 720, 840 and 960. That is 1024 / (1024 - code): the register holds 10 bits and 960 is 16x. Capped at 480, the main camera never got more than 1.88x and stayed dark indoors. Let a variant set its own maximum code, and give the IMX787 960. The data file's again_max still bounds the control, as before. Tested on a Pixel 9 Pro Fold with a v7.3-rc6 based kernel, a data file allowing 960 and libcamera's gain helper on the same curve: the control runs 0-960, auto exposure in a dim room settles at a real 15.75x instead of the 1.88x it was held to, and the mean of the same scene rose from 28/34/31 to 91/94/95 (B/G/R) without clipping. Assisted-by: LLM Signed-off-by: Nate Crawford --- drivers/media/i2c/imx386.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/imx386.c b/drivers/media/i2c/imx386.c index 36e5f8f30a..20cfaf8cb8 100644 --- a/drivers/media/i2c/imx386.c +++ b/drivers/media/i2c/imx386.c @@ -72,7 +72,7 @@ /* * Analogue gain = 512 / (512 - code), 1x to 16x at 0-480: measured on the * phone (CAMERA-PLAN.md CAM4.3c). The register holds 9 bits; codes from - * 512 wrap around. + * 512 wrap around. Variants with another curve set their own maximum. */ #define IMX386_AGAIN_MAX 480 /* Default frame rate: a longer frame leaves room for indoor exposures */ @@ -146,6 +146,7 @@ struct imx386_variant { bool shared_reset; bool identify_only; /* without a data file, check the ID */ const char *model; /* subdev name, if not "imx386" */ + u16 again_max; /* 16x gain code, if not IMX386_AGAIN_MAX */ }; static const char * const imx386_supply_names[] = { @@ -184,6 +185,11 @@ static const struct imx386_variant imx787_variant = { .shared_reset = true, .identify_only = true, .model = "imx787", + /* + * Analogue gain = 1024 / (1024 - code): 10 bits, 16x at 960. At 480 + * (the IMX386's 16x) the IMX787 gives 1.88x, measured on raw frames. + */ + .again_max = 960, }; static const u32 imx386_mbus_codes[] = { @@ -694,7 +700,8 @@ static int imx386_init_controls(struct imx386 *s) m->frame_length / 2); v4l2_ctrl_new_std(hdl, &imx386_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, le16_to_cpu(h->again_min), - min_t(u16, le16_to_cpu(h->again_max), IMX386_AGAIN_MAX), + min_t(u16, le16_to_cpu(h->again_max), + s->var->again_max ?: IMX386_AGAIN_MAX), 1, le16_to_cpu(h->again_min)); v4l2_ctrl_new_std(hdl, &imx386_ctrl_ops, V4L2_CID_DIGITAL_GAIN, IMX386_DGTL_GAIN_MIN, IMX386_DGTL_GAIN_MAX, 1, From 2884aa5975575e1ef38744f39f4808a4a86e0f83 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:19 +0000 Subject: [PATCH 4/4] media: i2c: ak7375: Wait a control step after leaving standby On the Pixel 9 Pro Fold's ultrawide (an AK73xx-family actuator at 0x0c, driven as ak7375), every power-up logged "ak7375_vcm_resume I2C failure: -6": the mode write that leaves standby is accepted, but the position write that follows at once is refused, so the actuator kept its reset position (0xfffc) instead of the control's value until userspace moved it again. Later position writes land exactly (a set of 300 reads back as 0x12c0). Wait one control step (ctrl_delay_us, 1 ms) between the mode write and the first position write for every ak7375. On a Pixel 7 Pro, both lenses logged the same position-loop error on a resume on November 15, 2026, with a kernel that already retries the standby mode write. Tested on a Pixel 9 Pro Fold with a v7.3-rc6 based kernel: three power cycles with no I2C error, and after each power-up the position registers hold the control's last value (0x0000, 0x0c80, 0x1900). Assisted-by: LLM Signed-off-by: Nate Crawford --- drivers/media/i2c/ak7375.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c index 669aee3c0c..d4d8c67a5d 100644 --- a/drivers/media/i2c/ak7375.c +++ b/drivers/media/i2c/ak7375.c @@ -350,6 +350,13 @@ static int __maybe_unused ak7375_vcm_resume(struct device *dev) if (tries) dev_info(dev, "answered after %u retries\n", tries); + /* + * The first position write right after leaving standby can be + * refused (NAK): seen on comet's ultrawide actuator, which then + * kept its reset position. Give it one control step's time. + */ + usleep_range(cdef->ctrl_delay_us, cdef->ctrl_delay_us + 10); + for (val = ak7375_dev->focus->val % cdef->ctrl_steps; val <= ak7375_dev->focus->val; val += cdef->ctrl_steps) {