From 60f97f8177c4bfc85ceb54e85238d28062f792f1 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:49:24 -0647 Subject: [PATCH 01/14] dt-bindings: phy: google,gs201-mipi-dcphy-rx: Add zumapro The Tensor G4 (zumapro) camera front end has the same Samsung DC-PHY receiver with nine slaves for its twelve CSIS links, the clock lane first on each and one reset bit per slave. Add its compatible; the PHY cell is the CSIS link. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../bindings/phy/google,gs201-mipi-dcphy-rx.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml b/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml index 9e50ca4c6f..28a20e5b56 100644 --- a/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml +++ b/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/phy/google,gs201-mipi-dcphy-rx.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 MIPI DC-PHY receiver +title: Google gs201 and zumapro MIPI DC-PHY receiver maintainers: - Derek Ross @@ -17,11 +17,15 @@ description: one PMU isolation control. The PHY cell selects the link. Each slave receives D-PHY or C-PHY (up to three trios on links 0 and 1, two on the others); the consumer selects the mode at run time, from its endpoint's - bus type. + bus type. zumapro (Tensor G4) has nine slaves for twelve CSIS links, the + clock lane first on each, and one reset bit per slave; the PHY cell is + the CSIS link. properties: compatible: - const: google,gs201-mipi-dcphy-rx + enum: + - google,gs201-mipi-dcphy-rx + - google,zumapro-mipi-dcphy-rx reg: maxItems: 1 @@ -42,7 +46,7 @@ properties: items: - items: - description: the camera block's system registers - - description: offset of the per-slave reset register (bit = link) + - description: offset of the per-slave reset register (bit = slave) description: The register that holds each DC-PHY slave in reset (bit clear) or releases it (bit set). From d2d149d5303163385152e568026f007ecc0c23f6 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:49:24 -0647 Subject: [PATCH 02/14] phy: samsung: gs201-mipi-dcphy-rx: Add the zumapro receiver zumapro's DC-PHY slaves sit at 0x1c100000 with the bias block at +0x1000 as on gs201, but every slave has its clock lane first and up to four data lanes (three C-PHY trios) after it, and three slaves are a clock lane only, which links 4 and 6 enable next to their own in four-lane D-PHY mode. The layout comes from the Pixel 9a camera HAL's register table and Google's GPL zuma DT; the reset bits are one per slave in the ISP-FE system registers at +0x500. Make the link layout per SoC with the reset bits and the partner clock lane in it, and add zumapro's four-lane links (0, 1, 2, 4 and 6). The data file format is unchanged. On the Pixel 9a, link 1 (the ultrawide IMX712, four lanes at 1105.92 Mbps) powers on with settle 55, and the CSIS link receives about 30 frames a second with no SOT, CRC or ECC errors. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c | 104 ++++++++++++++---- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c b/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c index 06b8bd15c5..ed3dacc7f9 100644 --- a/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c +++ b/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c @@ -37,6 +37,15 @@ * data in the Omarchy Mobile project), named by the firmware-name property and * loaded when a link first powers on. Without the file no link powers on. * + * zumapro (Tensor G4) has nine slaves for twelve CSIS links, all with the + * clock lane first and up to four data lanes (three C-PHY trios) after it; + * three are a clock lane only, which links 4, 6 and 9 enable next to their + * own in four-lane D-PHY mode. The shared bias block, the PMU isolation word + * and the data file are as on gs201; the reset bits are one per slave (the + * layout from the camera HAL's register table and Google's GPL zuma DT). + * Only the four-lane links are described; the two-lane and single-trio + * splits (links 3, 5, 7, 8, 10, 11) and link 9 are not. + * * C-PHY (Google's GPL code leaves it unimplemented): a consumer selects it * with phy_set_mode_ext(PHY_MODE_MIPI_DPHY, PHY_TYPE_CPHY), and the lanes * of phy_configure() are then trios and hs_clk_rate the symbol rate. Each @@ -78,7 +87,7 @@ #include -#define DCPHY_NUM_LINKS 8 +#define DCPHY_MAX_LINKS 12 #define DCPHY_BIAS_BASE 0x1000 #define DCPHY_M_BIAS_CON0 0x00 @@ -176,6 +185,8 @@ struct gs201_dcphy_link { unsigned int max_lanes; bool data_first; /* odd two-lane links: data, data, clock */ bool can_pair; /* even two-lane link: takes the next one's lanes */ + u32 partner_clk; /* zumapro: a clock-only slave enabled with this one */ + u32 reset_bits; /* the slaves' reset bits */ bool cphy; /* selected by the consumer with phy_set_mode_ext() */ u32 settle; /* TIME_CON0 settle count as last powered on */ unsigned int lanes; /* data lanes, or trios in C-PHY mode */ @@ -197,21 +208,52 @@ struct gs201_dcphy { const char *fw_name; bool loaded; struct gs201_dcphy_settings settings[DCPHY_NUM_MODES]; - struct gs201_dcphy_link links[DCPHY_NUM_LINKS]; + unsigned int num_links; + struct gs201_dcphy_link links[DCPHY_MAX_LINKS]; struct dentry *debugfs; }; -/* Offset of each link's lane block and its layout (Google's GPL DT) */ -static const struct { +/* Offset of each link's lane block and its layout */ +struct gs201_dcphy_layout { u32 offset; - unsigned int max_lanes; + unsigned int max_lanes; /* 0: not described */ bool data_first; bool can_pair; -} gs201_dcphy_layout[DCPHY_NUM_LINKS] = { - { 0x1300, 4, false, false }, { 0x1b00, 4, false, false }, - { 0x2300, 2, false, true }, { 0x2600, 2, true, false }, - { 0x2b00, 2, false, true }, { 0x2e00, 2, true, false }, - { 0x3300, 2, false, true }, { 0x3600, 2, true, false }, + u32 partner_clk; + u32 reset_bits; +}; + +struct gs201_dcphy_soc { + const struct gs201_dcphy_layout *layout; + unsigned int num_links; +}; + +/* gs201 (Google's GPL DT) */ +static const struct gs201_dcphy_layout gs201_dcphy_layout[] = { + { 0x1300, 4, false, false, 0, BIT(0) }, { 0x1b00, 4, false, false, 0, BIT(1) }, + { 0x2300, 2, false, true, 0, BIT(2) }, { 0x2600, 2, true, false, 0, BIT(3) }, + { 0x2b00, 2, false, true, 0, BIT(4) }, { 0x2e00, 2, true, false, 0, BIT(5) }, + { 0x3300, 2, false, true, 0, BIT(6) }, { 0x3600, 2, true, false, 0, BIT(7) }, +}; + +static const struct gs201_dcphy_soc gs201_dcphy_gs201 = { + .layout = gs201_dcphy_layout, + .num_links = ARRAY_SIZE(gs201_dcphy_layout), +}; + +/* zumapro: link n's clock lane, and the clock-only partner of links 4 and 6 */ +static const struct gs201_dcphy_layout zumapro_dcphy_layout[] = { + [0] = { 0x1200, 4, false, false, 0, BIT(0) }, + [1] = { 0x1700, 4, false, false, 0, BIT(1) }, + [2] = { 0x2200, 4, false, false, 0, BIT(2) }, + [4] = { 0x2700, 4, false, false, 0x2c00, BIT(3) | BIT(4) }, + [6] = { 0x3100, 4, false, false, 0x3600, BIT(5) | BIT(6) }, + [11] = { }, +}; + +static const struct gs201_dcphy_soc gs201_dcphy_zumapro = { + .layout = zumapro_dcphy_layout, + .num_links = ARRAY_SIZE(zumapro_dcphy_layout), }; #define DCPHY_PAIR_LANES 4 @@ -225,8 +267,9 @@ static unsigned int gs201_dcphy_nr_lanes(struct gs201_dcphy_link *link) /* Reset bits of the slaves the link uses */ static u32 gs201_dcphy_reset_mask(struct gs201_dcphy_link *link) { - return link->paired ? BIT(link->index) | BIT(link->index + 1) : - BIT(link->index); + return link->paired ? link->reset_bits | + link->dcphy->links[link->index + 1].reset_bits : + link->reset_bits; } static int gs201_dcphy_reset(struct gs201_dcphy_link *link, bool release) @@ -278,6 +321,8 @@ static void gs201_dcphy_lanes_off(struct gs201_dcphy_link *link) unsigned int i; writel(0, gs201_dcphy_clk_lane(link) + DCPHY_GNR_CON0); + if (link->partner_clk) + writel(0, link->dcphy->base + link->partner_clk + DCPHY_GNR_CON0); for (i = 0; i < gs201_dcphy_nr_lanes(link); i++) writel(0, gs201_dcphy_data_lane(link, i) + DCPHY_GNR_CON0); } @@ -511,9 +556,14 @@ static int gs201_dcphy_lanes_on(struct gs201_dcphy_link *link) gs201_dcphy_run_block(set, cols, DCPHY_BLOCK_BIAS, dcphy->base + DCPHY_BIAS_BASE); - if (!link->cphy) + if (!link->cphy) { gs201_dcphy_run_block(set, cols, DCPHY_BLOCK_CLOCK, gs201_dcphy_clk_lane(link)); + /* zumapro four-lane D-PHY: the partner's clock enable, as the link's */ + if (link->partner_clk && link->lanes > 2) + writel(readl(gs201_dcphy_clk_lane(link) + DCPHY_GNR_CON0), + dcphy->base + link->partner_clk + DCPHY_GNR_CON0); + } for (i = 0; i < link->lanes; i++) gs201_dcphy_run_block(set, cols, DCPHY_BLOCK_LANE, gs201_dcphy_data_lane(link, i)); @@ -728,7 +778,7 @@ static int gs201_dcphy_regs_show(struct seq_file *s, void *unused) seq_printf(s, " %08x", readl(dcphy->base + DCPHY_BIAS_BASE + off)); seq_putc(s, '\n'); - for (i = 0; i < DCPHY_NUM_LINKS; i++) { + for (i = 0; i < dcphy->num_links; i++) { struct gs201_dcphy_link *link = &dcphy->links[i]; if (!link->powered) @@ -752,7 +802,8 @@ static struct phy *gs201_dcphy_xlate(struct device *dev, { struct gs201_dcphy *dcphy = dev_get_drvdata(dev); - if (args->args[0] >= DCPHY_NUM_LINKS) + if (args->args[0] >= dcphy->num_links || + !dcphy->links[args->args[0]].phy) return ERR_PTR(-ENODEV); return dcphy->links[args->args[0]].phy; @@ -762,10 +813,15 @@ static int gs201_dcphy_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct phy_provider *provider; + const struct gs201_dcphy_soc *soc; struct gs201_dcphy *dcphy; unsigned int i; int ret; + soc = of_device_get_match_data(dev); + if (!soc || soc->num_links > DCPHY_MAX_LINKS) + return -ENODEV; + dcphy = devm_kzalloc(dev, sizeof(*dcphy), GFP_KERNEL); if (!dcphy) return -ENOMEM; @@ -802,15 +858,20 @@ static int gs201_dcphy_probe(struct platform_device *pdev) /* The settings file; without it, no link powers on (says so then). */ of_property_read_string(dev->of_node, "firmware-name", &dcphy->fw_name); - for (i = 0; i < DCPHY_NUM_LINKS; i++) { + dcphy->num_links = soc->num_links; + for (i = 0; i < dcphy->num_links; i++) { struct gs201_dcphy_link *link = &dcphy->links[i]; link->dcphy = dcphy; link->index = i; - link->offset = gs201_dcphy_layout[i].offset; - link->max_lanes = gs201_dcphy_layout[i].max_lanes; - link->data_first = gs201_dcphy_layout[i].data_first; - link->can_pair = gs201_dcphy_layout[i].can_pair; + link->offset = soc->layout[i].offset; + link->max_lanes = soc->layout[i].max_lanes; + link->data_first = soc->layout[i].data_first; + link->can_pair = soc->layout[i].can_pair; + link->partner_clk = soc->layout[i].partner_clk; + link->reset_bits = soc->layout[i].reset_bits; + if (!link->max_lanes) + continue; link->phy = devm_phy_create(dev, NULL, &gs201_dcphy_ops); if (IS_ERR(link->phy)) @@ -837,7 +898,8 @@ static void gs201_dcphy_remove(struct platform_device *pdev) } static const struct of_device_id gs201_dcphy_of_match[] = { - { .compatible = "google,gs201-mipi-dcphy-rx" }, + { .compatible = "google,gs201-mipi-dcphy-rx", .data = &gs201_dcphy_gs201 }, + { .compatible = "google,zumapro-mipi-dcphy-rx", .data = &gs201_dcphy_zumapro }, { } }; MODULE_DEVICE_TABLE(of, gs201_dcphy_of_match); From 95c4ef87add8852a62f2623baab39d7b28b4e726 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:49:24 -0647 Subject: [PATCH 03/14] dt-bindings: media: google,gs201-csis: Add zumapro zumapro has the same CSIS link (version 0x08010000 against gs201's 0x05040000, the same register layout) with twelve link contexts, but a different DMA path. Add its compatible with the link registers and the link interrupt only. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../bindings/media/google,gs201-csis.yaml | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml index 7859baca69..352a7230d2 100644 --- a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml +++ b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/media/google,gs201-csis.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 CSIS camera receiver link and CSIS WDMA +title: Google gs201 and zumapro CSIS camera receiver link and CSIS WDMA maintainers: - Derek Ross @@ -13,13 +13,17 @@ description: The camera block of Google's gs201 SoC has eight MIPI CSI-2 receiver links (CSIS) and a DMA block whose CSIS WDMA contexts write a link's frames to memory. One node describes one link and the WDMA context it feeds. + zumapro (Tensor G4) has the same receiver link in its ISP front end, with + twelve link contexts; its DMA path is different and not described here. properties: compatible: - const: google,gs201-csis + enum: + - google,gs201-csis + - google,zumapro-csis reg: - minItems: 3 + minItems: 1 items: - description: the CSIS link registers - description: the CSIS DMA block's common page (shared by all links) @@ -29,7 +33,7 @@ properties: way to the WDMA reg-names: - minItems: 3 + minItems: 1 items: - const: link - const: dma @@ -37,11 +41,13 @@ properties: - const: ebuf interrupts: + minItems: 1 items: - description: link interrupt - description: WDMA context interrupt interrupt-names: + minItems: 1 items: - const: link - const: wdma @@ -62,8 +68,8 @@ properties: google,csis-link: $ref: /schemas/types.yaml#/definitions/uint32 - maximum: 7 - description: Index of the CSIS link. + maximum: 11 + description: Index of the CSIS link (0-7 on gs201). google,wdma-context: $ref: /schemas/types.yaml#/definitions/uint32 @@ -132,10 +138,42 @@ required: - interrupt-names - phys - google,csis-link - - google,wdma-context - - google,csis-sysreg - port +allOf: + - if: + properties: + compatible: + const: google,gs201-csis + then: + properties: + reg: + minItems: 3 + reg-names: + minItems: 3 + interrupts: + minItems: 2 + interrupt-names: + minItems: 2 + google,csis-link: + maximum: 7 + required: + - google,wdma-context + - google,csis-sysreg + else: + properties: + reg: + maxItems: 1 + reg-names: + maxItems: 1 + interrupts: + maxItems: 1 + interrupt-names: + maxItems: 1 + google,wdma-context: false + google,csis-sysreg: false + google,ebuf: false + additionalProperties: false examples: From aa01517dd83c653cda518b38634240aa283b0f73 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:49:24 -0647 Subject: [PATCH 04/14] media: gs201-csis: Add a link-only zumapro variant zumapro's CSIS link has gs201's layout, but its frames reach memory through the ISP front end's CSIS core, which this driver doesn't drive yet. Add a zumapro match that maps the link only and always runs as link_only does: PHY, link and sensor, counting frames, with no WDMA, no routing and none of gs201's CSIS sysreg accesses (an unknown sysreg word aborted gs201). Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../platform/samsung/gs201-csis/gs201-csis.c | 80 ++++++++++++++----- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c index f342302c0c..1fc5f3ebc9 100644 --- a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c +++ b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c @@ -76,6 +76,17 @@ #define CSIS_MIN_LANE_RATE 80000000ULL #define CSIS_MAX_LANE_RATE 6500000000ULL +/* + * zumapro (Tensor G4) has the same CSI-2 link (version 0x08010000 against + * gs201's 0x05040000, same layout) but a different DMA path, which this + * driver doesn't drive yet: there it runs the PHY, the link and the sensor + * only (as link_only), to count frames. + */ +struct gs201_csis_soc { + bool wdma; /* gs201's CSIS WDMA, routing and CSIS sysreg */ + unsigned int num_links; +}; + struct gs201_csis_format { u32 code; u32 fourcc; @@ -132,6 +143,7 @@ struct gs201_csis_stats { }; struct gs201_csis { + const struct gs201_csis_soc *soc; struct device *dev; void __iomem *link; void __iomem *dma; @@ -1087,7 +1099,7 @@ static int gs201_csis_enable_streams(struct v4l2_subdev *sd, if (lanes < 0) return lanes; - { + if (csis->sysreg) { unsigned int sel = 0, rst = 0; regmap_read(csis->sysreg, CSIS_SYSREG_LINK_SEL, &sel); @@ -1122,7 +1134,7 @@ static int gs201_csis_enable_streams(struct v4l2_subdev *sd, goto err_link; /* Bring-up: what each part looks like right after the start. */ - { + if (csis->sysreg) { unsigned int sel = 0, rst = 0; regmap_read(csis->sysreg, CSIS_SYSREG_LINK_SEL, &sel); @@ -1165,7 +1177,7 @@ static int gs201_csis_disable_streams(struct v4l2_subdev *sd, v4l2_subdev_disable_streams(csis->source.sd, csis->source.pad->index, BIT(0)); - if (link_sel_bits) + if (link_sel_bits && csis->sysreg) regmap_write(csis->sysreg, CSIS_SYSREG_LINK_SEL, csis->link_sel_saved); gs201_csis_link_stop(csis); phy_power_off(csis->phy); @@ -1588,7 +1600,7 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) csis->sequence = 0; memset(&csis->stats, 0, sizeof(csis->stats)); csis->wdma_err_logged = false; - csis->dma_on = !link_only; + csis->dma_on = !link_only && csis->soc->wdma; spin_lock_irqsave(&csis->slock, flags); if (!csis->next) @@ -1758,10 +1770,10 @@ static int gs201_csis_regs_show(struct seq_file *s, void *unused) for (i = 0; i < ARRAY_SIZE(link_regs); i++) seq_printf(s, "link 0x%03x = 0x%08x\n", link_regs[i], link_read(csis, link_regs[i])); - for (i = 0; i < ARRAY_SIZE(wdma_regs); i++) + for (i = 0; csis->wdma && i < ARRAY_SIZE(wdma_regs); i++) seq_printf(s, "wdma 0x%03x = 0x%08x\n", wdma_regs[i], wdma_read(csis, wdma_regs[i])); - for (i = 0; i < ARRAY_SIZE(ch_regs); i++) { + for (i = 0; csis->wdma && i < ARRAY_SIZE(ch_regs); i++) { u32 r = CSIS_WDMA_CH(csis->wdma_ch, ch_regs[i]); seq_printf(s, "wdma 0x%03x = 0x%08x\n", r, wdma_read(csis, r)); @@ -1806,7 +1818,7 @@ static int gs201_csis_scan_show(struct seq_file *s, void *unused) seq_printf(s, "link%u+0x%03x = 0x%08x\n", csis->link_id, off, link_read(csis, off)); - for (i = 0; i < ARRAY_SIZE(sysreg_regs); i++) { + for (i = 0; csis->sysreg && i < ARRAY_SIZE(sysreg_regs); i++) { if (regmap_read(csis->sysreg, sysreg_regs[i], &val)) continue; seq_printf(s, "sysreg+0x%03x = 0x%08x\n", sysreg_regs[i], val); @@ -2060,10 +2072,17 @@ static int gs201_csis_probe(struct platform_device *pdev) INIT_LIST_HEAD(&csis->pending); platform_set_drvdata(pdev, csis); + csis->soc = of_device_get_match_data(dev); + if (!csis->soc) + return -ENODEV; + csis->link = devm_platform_ioremap_resource_byname(pdev, "link"); if (IS_ERR(csis->link)) return PTR_ERR(csis->link); + if (!csis->soc->wdma) + goto no_wdma; + /* The DMA common page is shared by all instances: map, don't claim. */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); if (!res) @@ -2088,6 +2107,7 @@ static int gs201_csis_probe(struct platform_device *pdev) return -ENOMEM; } +no_wdma: csis->cam_clk = devm_clk_get_optional(dev, "cam"); if (IS_ERR(csis->cam_clk)) return dev_err_probe(dev, PTR_ERR(csis->cam_clk), "CAM clock\n"); @@ -2096,10 +2116,10 @@ static int gs201_csis_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(csis->int_clk), "INT clock\n"); ret = device_property_read_u32(dev, "google,csis-link", &csis->link_id); - if (ret || csis->link_id > 7) + if (ret || csis->link_id >= csis->soc->num_links) return dev_err_probe(dev, -EINVAL, "bad google,csis-link\n"); ret = device_property_read_u32(dev, "google,wdma-context", &csis->ctx_id); - if (ret || csis->ctx_id > 3) + if (csis->soc->wdma && (ret || csis->ctx_id > 3)) return dev_err_probe(dev, -EINVAL, "bad google,wdma-context\n"); csis->ebuf = csis->ctx_id; @@ -2110,10 +2130,13 @@ static int gs201_csis_probe(struct platform_device *pdev) csis->lrte_epd = device_property_read_bool(dev, "google,lrte-packet-delimiters"); - csis->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node, - "google,csis-sysreg"); - if (IS_ERR(csis->sysreg)) - return dev_err_probe(dev, PTR_ERR(csis->sysreg), "no CSIS sysreg\n"); + if (csis->soc->wdma) { + csis->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node, + "google,csis-sysreg"); + if (IS_ERR(csis->sysreg)) + return dev_err_probe(dev, PTR_ERR(csis->sysreg), + "no CSIS sysreg\n"); + } csis->phy = devm_phy_get(dev, NULL); if (IS_ERR(csis->phy)) @@ -2137,15 +2160,17 @@ static int gs201_csis_probe(struct platform_device *pdev) if (ret) goto err_mem; - irq = platform_get_irq_byname(pdev, "wdma"); - if (irq < 0) { - ret = irq; - goto err_mem; + if (csis->soc->wdma) { + irq = platform_get_irq_byname(pdev, "wdma"); + if (irq < 0) { + ret = irq; + goto err_mem; + } + ret = devm_request_irq(dev, irq, gs201_csis_wdma_irq, IRQF_SHARED, + dev_name(dev), csis); + if (ret) + goto err_mem; } - ret = devm_request_irq(dev, irq, gs201_csis_wdma_irq, IRQF_SHARED, - dev_name(dev), csis); - if (ret) - goto err_mem; csis->fmt = &gs201_csis_formats[0]; csis->pix.width = CSIS_DEF_WIDTH; @@ -2194,8 +2219,19 @@ static void gs201_csis_remove(struct platform_device *pdev) of_reserved_mem_device_release(&pdev->dev); } +static const struct gs201_csis_soc gs201_csis_gs201 = { + .wdma = true, + .num_links = 8, +}; + +/* Links 0-11 have contexts and interrupts; stock wires sensors to 0-8. */ +static const struct gs201_csis_soc gs201_csis_zumapro = { + .num_links = 12, +}; + static const struct of_device_id gs201_csis_of_match[] = { - { .compatible = "google,gs201-csis" }, + { .compatible = "google,gs201-csis", .data = &gs201_csis_gs201 }, + { .compatible = "google,zumapro-csis", .data = &gs201_csis_zumapro }, { } }; MODULE_DEVICE_TABLE(of, gs201_csis_of_match); From b8642798cc46117acef33e7ba1818d666c68e638 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:49:44 -0647 Subject: [PATCH 05/14] dt-bindings: media: google,gs201-csis: Add the zumapro CSIS core On zumapro a link's frames reach memory through the ISP front end's CSIS core, one page shared by all links, with one interrupt for all of them. Describe it as an optional second register range and interrupt of a zumapro link, with the image logical channel the link writes through. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../bindings/media/google,gs201-csis.yaml | 71 ++++++++++++------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml index 352a7230d2..ad4220e787 100644 --- a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml +++ b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml @@ -24,33 +24,19 @@ properties: reg: minItems: 1 - items: - - description: the CSIS link registers - - description: the CSIS DMA block's common page (shared by all links) - - description: the CSIS WDMA context (links may share one; they then - stream one at a time) - - description: the EBUF control (shared by all links), bypassed on the - way to the WDMA + maxItems: 4 reg-names: minItems: 1 - items: - - const: link - - const: dma - - const: wdma - - const: ebuf + maxItems: 4 interrupts: minItems: 1 - items: - - description: link interrupt - - description: WDMA context interrupt + maxItems: 2 interrupt-names: minItems: 1 - items: - - const: link - - const: wdma + maxItems: 2 clocks: items: @@ -88,6 +74,13 @@ properties: description: WDMA input slot the link is routed to; defaults to the context index. + google,image-loch: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 6 + description: + zumapro only. The CSIS core's image logical channel the link writes + its frames through; defaults to 0. + google,lrte-packet-delimiters: type: boolean description: @@ -149,27 +142,57 @@ allOf: properties: reg: minItems: 3 + items: + - description: the CSIS link registers + - description: the CSIS DMA block's common page (shared by all links) + - description: the CSIS WDMA context (links may share one; they + then stream one at a time) + - description: the EBUF control (shared by all links), bypassed on + the way to the WDMA reg-names: minItems: 3 + items: + - const: link + - const: dma + - const: wdma + - const: ebuf interrupts: - minItems: 2 + items: + - description: link interrupt + - description: WDMA context interrupt interrupt-names: - minItems: 2 + items: + - const: link + - const: wdma google,csis-link: maximum: 7 + google,image-loch: false required: - google,wdma-context - google,csis-sysreg else: properties: reg: - maxItems: 1 + minItems: 1 + items: + - description: the CSIS link registers + - description: the ISP front end's CSIS core page, shared by all + links; without it the link runs without DMA reg-names: - maxItems: 1 + minItems: 1 + items: + - const: link + - const: core interrupts: - maxItems: 1 + minItems: 1 + items: + - description: link interrupt + - description: CSIS core interrupt, shared by all links interrupt-names: - maxItems: 1 + minItems: 1 + items: + - const: link + - const: core google,wdma-context: false google,csis-sysreg: false google,ebuf: false From 120c4215dd9753259986b737c47d2dc1ff31fb24 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:49:45 -0647 Subject: [PATCH 06/14] media: gs201-csis: Write zumapro frames through the CSIS core zumapro's CSIS core takes a link's data type on one virtual channel into an image logical channel (LoCH) and writes it to memory through its Bayer WDMA. The register layout and fields come from the Pixel 9a camera HAL's register table and value packers and, for the interrupt bits, Google's GPL zuma ISP event description. Route the link's channel 0 into a LoCH, write packed RAW10 (or RAW8) at the stride the video node set, and program the batch slot at each start of frame only: a configuration written during a frame is a late config and stops the LoCH, so frames with no queued buffer go to a scratch buffer. A status queue page takes the LoCH's per-frame record. The link differs from gs201 in three bits the zumapro HAL sets or clears: pixel mode 3, CMN_CTRL bit 12, and DBG_OPTION_SUITE cleared. gs201 sets DBG_OPTION_SUITE bit 23, and with it the link hands out unpacked 16-bit words, which gs201's WDMA expects; zumapro's core reads them as packed RAW10 and scrambles every pixel. On the Pixel 9a the ultrawide's solid colour test pattern (R 1023, Gr 0, B 341, Gb 682) reads back exactly in RAW10 and RAW16, and libcamera's simple pipeline streams it at 30 fps. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../platform/samsung/gs201-csis/gs201-csis.c | 383 +++++++++++++++++- .../samsung/gs201-csis/zumapro-csis-core.h | 93 +++++ 2 files changed, 457 insertions(+), 19 deletions(-) create mode 100644 drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h diff --git a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c index 1fc5f3ebc9..c6412ec4a0 100644 --- a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c +++ b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c @@ -58,6 +58,7 @@ #include #include "gs201-csis-regs.h" +#include "zumapro-csis-core.h" #define CSIS_DRIVER_NAME "gs201-csis" @@ -78,13 +79,24 @@ /* * zumapro (Tensor G4) has the same CSI-2 link (version 0x08010000 against - * gs201's 0x05040000, same layout) but a different DMA path, which this - * driver doesn't drive yet: there it runs the PHY, the link and the sensor - * only (as link_only), to count frames. + * gs201's 0x05040000, same layout) but a different DMA path: the ISP front + * end's CSIS core, whose image logical channel (LoCH) takes a link's data + * type on one virtual channel and writes it to memory through its Bayer + * WDMA (zumapro-csis-core.h). Without the core's registers in the device + * tree the link runs alone (as link_only), counting frames. */ struct gs201_csis_soc { bool wdma; /* gs201's CSIS WDMA, routing and CSIS sysreg */ unsigned int num_links; + u32 cmn_ctrl_extra; /* CMN_CTRL bits the SoC's camera software sets */ + unsigned int pixel_mode; /* the link channel's, unless overridden */ + unsigned int dma_bits; + /* + * DBG_OPTION_SUITE bit 23: gs201's camera software sets it, and the link + * then hands out unpacked 16-bit words, which gs201's WDMA expects. + * zumapro's clears it: its CSIS core unpacks the packed CSI-2 stream. + */ + bool dbg_bit23; }; struct gs201_csis_format { @@ -144,6 +156,13 @@ struct gs201_csis_stats { struct gs201_csis { const struct gs201_csis_soc *soc; + void __iomem *core; /* zumapro: the CSIS core page, or NULL */ + unsigned int loch; /* zumapro: the image LoCH this link writes through */ + void *sq_buf; /* zumapro: the LoCH's status queue */ + dma_addr_t sq_dma; + void *scratch; /* zumapro: frames with no buffer go here */ + dma_addr_t scratch_dma; + size_t scratch_size; struct device *dev; void __iomem *link; void __iomem *dma; @@ -316,9 +335,26 @@ MODULE_PARM_DESC(wdma_line_irq, "Count WDMA line ends per channel (bring-up; man * stock uses quad, 2), to try how a C-PHY link hands its lines to the * WDMA. */ -static unsigned int pixel_mode = CSIS_ISPCFG_PIXEL_MODE_QUAD; -module_param(pixel_mode, uint, 0644); -MODULE_PARM_DESC(pixel_mode, "Link channel pixel mode, 0-3 (bring-up; default 2, quad)"); +/* zumapro bring-up: the CSIS core's memory format and the link's parallel mode */ +static int zp_mem_fmt = -1; +module_param(zp_mem_fmt, int, 0644); +MODULE_PARM_DESC(zp_mem_fmt, "zumapro Bayer WDMA memory format (bring-up; default RAW10 packed 4, 2 RAW16)"); + +static int cmn_ctrl_extra = -1; +module_param(cmn_ctrl_extra, int, 0644); +MODULE_PARM_DESC(cmn_ctrl_extra, "Extra link CMN_CTRL bits (bring-up; default the SoC's)"); + +static int zp_dt = -1; +module_param(zp_dt, int, 0644); +MODULE_PARM_DESC(zp_dt, "zumapro LoCH data type code (bring-up; default from the CSI-2 data type)"); + +static int parallel_mode = -1; +module_param(parallel_mode, int, 0644); +MODULE_PARM_DESC(parallel_mode, "Link channel parallel mode, ISP_CONFIG bits 15:14 (bring-up; default left 0)"); + +static int pixel_mode = -1; +module_param(pixel_mode, int, 0644); +MODULE_PARM_DESC(pixel_mode, "Link channel pixel mode, 0-3 (bring-up; default the SoC's: gs201 2, quad; zumapro 3)"); /* * Bring-up: start the WDMA channel only at the link's Nth frame end after @@ -580,8 +616,11 @@ static void gs201_csis_link_start(struct gs201_csis *csis, CSIS_ISPCFG_VC); } - link_write(csis, CSIS_DBG_OPTION_SUITE, - link_read(csis, CSIS_DBG_OPTION_SUITE) | CSIS_DBG_OPTION_BIT23); + if (csis->soc->dbg_bit23) + link_write(csis, CSIS_DBG_OPTION_SUITE, + link_read(csis, CSIS_DBG_OPTION_SUITE) | CSIS_DBG_OPTION_BIT23); + else + link_write(csis, CSIS_DBG_OPTION_SUITE, 0); link_write(csis, CSIS_INT_SRC0, ~0u); link_write(csis, CSIS_INT_SRC1, ~0u); @@ -597,7 +636,9 @@ static void gs201_csis_link_start(struct gs201_csis *csis, link_write(csis, CSIS_ISP_CONFIG_CH(ch), cfg_keep[ch] | FIELD_PREP(CSIS_ISPCFG_DATAFORMAT, dt) | - FIELD_PREP(CSIS_ISPCFG_PIXEL_MODE, pixel_mode & 3) | + FIELD_PREP(CSIS_ISPCFG_PIXEL_MODE, + (pixel_mode >= 0 ? pixel_mode : csis->soc->pixel_mode) & 3) | + (parallel_mode >= 0 ? FIELD_PREP(GENMASK(15, 14), parallel_mode & 3) : 0) | FIELD_PREP(CSIS_ISPCFG_VC, vc)); link_write(csis, CSIS_ISP_RESOL_CH(ch), !used ? 0 : FIELD_PREP(CSIS_ISP_RESOL_V, mf->height) | @@ -623,9 +664,144 @@ static void gs201_csis_link_start(struct gs201_csis *csis, FIELD_PREP(CSIS_CMN_CTRL_LANE_NUMBER, lanes - 1) | FIELD_PREP(CSIS_CMN_CTRL_INTERLEAVE, 3) | FIELD_PREP(CSIS_CMN_CTRL_F13, 2) | + (cmn_ctrl_extra >= 0 ? cmn_ctrl_extra : csis->soc->cmn_ctrl_extra) | (csis->cphy ? CSIS_CMN_CTRL_CPHY : 0)); } +/* ----------------------------------------------------------------------------- + * Hardware: the zumapro CSIS core's image LoCH + */ + +static inline u32 core_read(struct gs201_csis *csis, u32 reg) +{ + return readl(csis->core + reg); +} + +static inline void core_write(struct gs201_csis *csis, u32 reg, u32 val) +{ + writel(val, csis->core + reg); +} + +static inline u32 img_read(struct gs201_csis *csis, u32 reg) +{ + return core_read(csis, ZP_IMG(csis->loch, reg)); +} + +static inline void img_write(struct gs201_csis *csis, u32 reg, u32 val) +{ + core_write(csis, ZP_IMG(csis->loch, reg), val); +} + +static u32 zp_core_dt(u8 data_type) +{ + switch (data_type) { + case MIPI_CSI2_DT_RAW8: + return ZP_DT_RAW8; + case MIPI_CSI2_DT_RAW12: + return ZP_DT_RAW12; + case MIPI_CSI2_DT_RAW14: + return ZP_DT_RAW14; + default: + return ZP_DT_RAW10; + } +} + +static void zp_core_set_addr(struct gs201_csis *csis, dma_addr_t addr) +{ + /* one batch slot; the configuration takes effect at the next frame */ + img_write(csis, ZP_IMG_BATCH_ADDR_LSB(0), + lower_32_bits(addr) & ZP_IMG_ADDR_LSB_MASK); + img_write(csis, ZP_IMG_BATCH_ADDR_MSB(0), + upper_32_bits(addr) & ZP_IMG_ADDR_MSB_MASK); + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 1); +} + +/* The LoCH takes the link's channel 0 (VC 0) data type, as the HAL routes it. */ +static void zp_core_route(struct gs201_csis *csis) +{ + core_write(csis, ZP_FRAME_ID_CLR, BIT(csis->loch)); + img_write(csis, ZP_IMG_AUTO_REC_SYNC_INTV0, 0); + img_write(csis, ZP_IMG_AUTO_REC_SYNC_INTV1, 0); + img_write(csis, ZP_IMG_BATCH_INT_MSK_SOF, 1); + img_write(csis, ZP_IMG_BATCH_INT_MSK_EOF, 1); + img_write(csis, ZP_IMG_BATCH_INT_MSK_DMA_DONE, 1); + img_write(csis, ZP_IMG_BATCH_INT_MSK_FRAME_DONE, 1); + img_write(csis, ZP_IMG_CTL, + FIELD_PREP(ZP_IMG_CTL_LINK, csis->link_id) | + FIELD_PREP(ZP_IMG_CTL_LINK_CH, 0) | + FIELD_PREP(ZP_IMG_CTL_DT, zp_dt >= 0 ? zp_dt : + zp_core_dt(csis->fmt->data_type))); + img_write(csis, ZP_IMG_BATCH_CTL, 0); + img_write(csis, ZP_IMG_ISP_RESOL, + FIELD_PREP(ZP_IMG_ISP_RESOL_H, csis->pix.height) | + FIELD_PREP(ZP_IMG_ISP_RESOL_W, csis->pix.width)); + img_write(csis, ZP_IMG_PROC_IER, ZP_IMG_PROC_SOF | ZP_IMG_PROC_EOF | + ZP_IMG_PROC_SHADOW_UPDATE | ZP_IMG_PROC_DMA_DONE); +} + +static void zp_core_unroute(struct gs201_csis *csis) +{ + core_write(csis, ZP_LOCH_EN_CLR, BIT(csis->loch)); + img_write(csis, ZP_IMG_CTL, 0); +} + +static void zp_core_wdma_start(struct gs201_csis *csis) +{ + u32 fmt = zp_mem_fmt >= 0 ? zp_mem_fmt : + csis->fmt->bpp == 8 ? ZP_MEM_FMT_8BIT : ZP_MEM_FMT_RAW10_PACKED; + + img_write(csis, ZP_IMG_BAYER_MEM_FORMAT, fmt); + img_write(csis, ZP_IMG_BAYER_STRIDE, csis->pix.bytesperline); + img_write(csis, ZP_IMG_BAYER_CROP_EN, 0); + img_write(csis, ZP_IMG_BAYER_ENABLE, BIT(0)); + img_write(csis, ZP_IMG_SQ_CONFIG_ID_LSB, 0); + img_write(csis, ZP_IMG_SQ_CONFIG_ID_MSB, 0); + img_write(csis, ZP_IMG_SQ_BASE_ADDR_LSB, lower_32_bits(csis->sq_dma)); + img_write(csis, ZP_IMG_SQ_BASE_ADDR_MSB, upper_32_bits(csis->sq_dma)); + + img_write(csis, ZP_IMG_PROC_ISR, img_read(csis, ZP_IMG_PROC_ISR)); + img_write(csis, ZP_IMG_ERR_ISR, img_read(csis, ZP_IMG_ERR_ISR)); + img_write(csis, ZP_IMG_WDMA_CONFIG_MISS, 1); + img_write(csis, ZP_IMG_PROC_IMR, ZP_IMG_PROC_SOF | ZP_IMG_PROC_EOF | + ZP_IMG_PROC_DMA_DONE | ZP_IMG_PROC_FRAME_DONE); + img_write(csis, ZP_IMG_ERR_IMR, ZP_IMG_ERRORS); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); + core_write(csis, ZP_LOCH_INT_IMR, + core_read(csis, ZP_LOCH_INT_IMR) | BIT(csis->loch)); + + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 1); + img_write(csis, ZP_IMG_WDMA_CONTEXT_ENABLE, 1); + core_write(csis, ZP_LOCH_EN_SET, BIT(csis->loch)); + + dev_info(csis->dev, "LoCH %u on: link %u, CTL 0x%08x RESOL 0x%08x, %u bytes a line, format %u, slot 0 0x%x:%08x; LOCH_EN 0x%08x\n", + csis->loch, csis->link_id, img_read(csis, ZP_IMG_CTL), + img_read(csis, ZP_IMG_ISP_RESOL), csis->pix.bytesperline, fmt, + img_read(csis, ZP_IMG_BATCH_ADDR_MSB(0)), + img_read(csis, ZP_IMG_BATCH_ADDR_LSB(0)), + core_read(csis, ZP_LOCH_EN)); +} + +static void zp_core_wdma_stop(struct gs201_csis *csis) +{ + u32 val; + + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 0); + img_write(csis, ZP_IMG_WDMA_CONTEXT_ENABLE, 0); + core_write(csis, ZP_LOCH_EN_CLR, BIT(csis->loch)); + core_write(csis, ZP_LOCH_ABORT, BIT(csis->loch)); + if (readl_poll_timeout(csis->core + ZP_IMG(csis->loch, ZP_IMG_ABORT_DONE_ISR), + val, val & ZP_IMG_ABORT_DONE, 100, 50000)) + dev_dbg(csis->dev, "LoCH %u: no abort-done\n", csis->loch); + img_write(csis, ZP_IMG_ABORT_DONE_ISR, val); + core_write(csis, ZP_LOCH_INT_IMR, + core_read(csis, ZP_LOCH_INT_IMR) & ~BIT(csis->loch)); + img_write(csis, ZP_IMG_PROC_IMR, 0); + img_write(csis, ZP_IMG_ERR_IMR, 0); + img_write(csis, ZP_IMG_PROC_ISR, img_read(csis, ZP_IMG_PROC_ISR)); + img_write(csis, ZP_IMG_ERR_ISR, img_read(csis, ZP_IMG_ERR_ISR)); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); +} + static void gs201_csis_link_stop(struct gs201_csis *csis) { link_write(csis, CSIS_INT_MSK0, 0); @@ -877,7 +1053,9 @@ static void gs201_csis_next_buffer(struct gs201_csis *csis) struct gs201_csis_buffer, list); if (csis->next) { list_del(&csis->next->list); - if (csis->dma_on) + if (csis->dma_on && csis->core) + zp_core_set_addr(csis, csis->next->addr); + else if (csis->dma_on) gs201_csis_wdma_set_addr(csis, csis->next->addr); } } @@ -1010,6 +1188,104 @@ static irqreturn_t gs201_csis_wdma_irq(int irq, void *data) return IRQ_HANDLED; } +/* + * zumapro: the CSIS core's interrupt is shared by every LoCH. Start of frame + * latched the slot address: that buffer becomes active and the next is + * programmed; DMA done completes it. + */ +static irqreturn_t zp_core_irq(int irq, void *data) +{ + struct gs201_csis *csis = data; + struct gs201_csis_buffer *done = NULL, *failed = NULL; + u32 agg, proc, err; + + if (READ_ONCE(gs201_csis_owner) != csis) + return IRQ_NONE; + + agg = core_read(csis, ZP_LOCH_INT_ISR); + if (!(agg & BIT(csis->loch))) + return IRQ_NONE; + proc = img_read(csis, ZP_IMG_PROC_ISR); + err = img_read(csis, ZP_IMG_ERR_ISR) & ZP_IMG_ERRORS; + img_write(csis, ZP_IMG_PROC_ISR, proc); + if (err) + img_write(csis, ZP_IMG_ERR_ISR, err); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); + + spin_lock(&csis->slock); + csis->stats.wdma_fs[0] += !!(proc & ZP_IMG_PROC_SOF); + csis->stats.wdma_fe[0] += !!(proc & ZP_IMG_PROC_EOF); + csis->stats.wdma_le[0] += !!(proc & ZP_IMG_PROC_FRAME_DONE); + if (err) { + unsigned long be = err; + unsigned int bit; + + csis->stats.wdma_errors++; + csis->stats.last_wdma_err = err; + for_each_set_bit(bit, &be, 32) + csis->stats.wdma_bits[bit]++; + if (!csis->wdma_err_logged) { + csis->wdma_err_logged = true; + dev_warn(csis->dev, "LoCH %u error 0x%04x (proc 0x%02x): CTL 0x%08x RESOL 0x%08x STRIDE %u, slot 0 0x%x:%08x, activity 0x%08x, WDMA debug 0x%08x, AXI response errors 0x%08x, config miss 0x%x\n", + csis->loch, err, proc, img_read(csis, ZP_IMG_CTL), + img_read(csis, ZP_IMG_ISP_RESOL), + img_read(csis, ZP_IMG_BAYER_STRIDE), + img_read(csis, ZP_IMG_BATCH_ADDR_MSB(0)), + img_read(csis, ZP_IMG_BATCH_ADDR_LSB(0)), + img_read(csis, ZP_IMG_ACTIVITY_STATUS), + img_read(csis, ZP_IMG_WDMA_DBG_INFO), + img_read(csis, ZP_IMG_AXI_RESP_ERR_STATUS), + img_read(csis, ZP_IMG_WDMA_CONFIG_MISS)); + } + } + + /* + * Each frame start latches the slot programmed before it, so the slot + * is reprogrammed only here, never mid-frame (a configuration written + * during a frame is a "late config" and stops the LoCH): the next + * queued buffer, or the scratch buffer. + */ + if (proc & ZP_IMG_PROC_SOF) { + if (csis->active) { + failed = csis->active; + csis->active = NULL; + csis->stats.missed_fe++; + } + csis->active = csis->next; + csis->next = NULL; + if (!list_empty(&csis->pending)) { + gs201_csis_next_buffer(csis); + } else { + zp_core_set_addr(csis, csis->scratch_dma); + csis->stats.dropped++; + } + } + + if ((proc & ZP_IMG_PROC_DMA_DONE) && csis->active) { + done = csis->active; + csis->active = NULL; + csis->stats.wdma_done++; + } + spin_unlock(&csis->slock); + + if (failed) { + failed->vb.vb2_buf.timestamp = ktime_get_ns(); + failed->vb.sequence = csis->sequence++; + failed->vb.field = V4L2_FIELD_NONE; + vb2_buffer_done(&failed->vb.vb2_buf, keep_failed ? + VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR); + } + if (done) { + done->vb.vb2_buf.timestamp = ktime_get_ns(); + done->vb.sequence = csis->sequence++; + done->vb.field = V4L2_FIELD_NONE; + vb2_buffer_done(&done->vb.vb2_buf, err && !keep_failed ? + VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); + } + + return IRQ_HANDLED; +} + /* ----------------------------------------------------------------------------- * Streaming */ @@ -1125,7 +1401,7 @@ static int gs201_csis_enable_streams(struct v4l2_subdev *sd, goto err_dvfs; gs201_csis_link_start(csis, mf, f, lanes); - if (csis->dma_on && wdma_after_link) + if (csis->dma_on && wdma_after_link && !csis->core) gs201_csis_wdma_start(csis); ret = v4l2_subdev_enable_streams(csis->source.sd, @@ -1558,7 +1834,9 @@ static void gs201_csis_buf_queue(struct vb2_buffer *vb) spin_lock_irqsave(&csis->slock, flags); list_add_tail(&buf->list, &csis->pending); - if (!csis->next && vb2_start_streaming_called(vb->vb2_queue)) + /* zumapro programs the slot at frame start only */ + if (!csis->next && vb2_start_streaming_called(vb->vb2_queue) && + !csis->core) gs201_csis_next_buffer(csis); spin_unlock_irqrestore(&csis->slock, flags); } @@ -1600,14 +1878,26 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) csis->sequence = 0; memset(&csis->stats, 0, sizeof(csis->stats)); csis->wdma_err_logged = false; - csis->dma_on = !link_only && csis->soc->wdma; + csis->dma_on = !link_only && (csis->soc->wdma || csis->core); spin_lock_irqsave(&csis->slock, flags); if (!csis->next) gs201_csis_next_buffer(csis); spin_unlock_irqrestore(&csis->slock, flags); - if (csis->dma_on) { + if (csis->dma_on && csis->core) { + csis->scratch_size = csis->pix.sizeimage; + csis->scratch = dma_alloc_coherent(csis->dev, csis->scratch_size, + &csis->scratch_dma, GFP_KERNEL); + if (!csis->scratch) { + ret = -ENOMEM; + goto err_pipeline; + } + if (!csis->next) + zp_core_set_addr(csis, csis->scratch_dma); + zp_core_route(csis); + zp_core_wdma_start(csis); + } else if (csis->dma_on) { ret = gs201_csis_route(csis); if (ret) goto err_pipeline; @@ -1624,7 +1914,13 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) return 0; err_wdma: - if (csis->dma_on) { + if (csis->dma_on && csis->core) { + zp_core_wdma_stop(csis); + zp_core_unroute(csis); + dma_free_coherent(csis->dev, csis->scratch_size, csis->scratch, + csis->scratch_dma); + csis->scratch = NULL; + } else if (csis->dma_on) { gs201_csis_wdma_stop(csis); gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); gs201_csis_unroute(csis); @@ -1668,7 +1964,19 @@ static void gs201_csis_stop_streaming(struct vb2_queue *vq) csis->wdma_arm = 0; spin_unlock_irqrestore(&csis->slock, flags); v4l2_subdev_disable_streams(&csis->sd, CSIS_PAD_SOURCE, BIT(0)); - if (csis->dma_on) { + if (csis->dma_on && csis->core) { + dev_info(csis->dev, "LoCH %u at stop: frame %u, done frame %u, activity 0x%08x, WDMA debug 0x%08x, AXI response errors 0x%08x\n", + csis->loch, img_read(csis, ZP_IMG_FRAME_ID), + img_read(csis, ZP_IMG_DONE_FRAME_ID), + img_read(csis, ZP_IMG_ACTIVITY_STATUS), + img_read(csis, ZP_IMG_WDMA_DBG_INFO), + img_read(csis, ZP_IMG_AXI_RESP_ERR_STATUS)); + zp_core_wdma_stop(csis); + zp_core_unroute(csis); + dma_free_coherent(csis->dev, csis->scratch_size, csis->scratch, + csis->scratch_dma); + csis->scratch = NULL; + } else if (csis->dma_on) { gs201_csis_wdma_stop(csis); gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); gs201_csis_unroute(csis); @@ -1683,7 +1991,7 @@ static void gs201_csis_stop_streaming(struct vb2_queue *vq) csis->stats.wdma_done, csis->stats.wdma_errors, csis->stats.last_wdma_err, csis->stats.dropped, csis->stats.missed_fe); - if (csis->dma_on) + if (csis->dma_on && csis->dma) dev_info(csis->dev, "WDMA debug at stop: frames 0x%08x, lines/data 0x%08x\n", readl(csis->dma + CSIS_DMA_CMN_DBG_VCNT(csis->ctx_id)), readl(csis->dma + CSIS_DMA_CMN_DBG_HDCNT(csis->ctx_id))); @@ -2080,8 +2388,19 @@ static int gs201_csis_probe(struct platform_device *pdev) if (IS_ERR(csis->link)) return PTR_ERR(csis->link); - if (!csis->soc->wdma) + if (!csis->soc->wdma) { + /* zumapro: the CSIS core page, optional (without it, link only) */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (res) { + csis->core = devm_ioremap(dev, res->start, resource_size(res)); + if (!csis->core) + return -ENOMEM; + } + device_property_read_u32(dev, "google,image-loch", &csis->loch); + if (csis->loch > 6) + return dev_err_probe(dev, -EINVAL, "bad google,image-loch\n"); goto no_wdma; + } /* The DMA common page is shared by all instances: map, don't claim. */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); @@ -2146,10 +2465,29 @@ static int gs201_csis_probe(struct platform_device *pdev) if (ret && ret != -ENODEV) return dev_err_probe(dev, ret, "memory region\n"); - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(CSIS_WDMA_ADDR_BITS)); + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(csis->soc->dma_bits)); if (ret) goto err_mem; + if (csis->core) { + /* the LoCH writes a status record per frame: give it a page */ + csis->sq_buf = dmam_alloc_coherent(dev, PAGE_SIZE, &csis->sq_dma, + GFP_KERNEL); + if (!csis->sq_buf) { + ret = -ENOMEM; + goto err_mem; + } + irq = platform_get_irq_byname(pdev, "core"); + if (irq < 0) { + ret = irq; + goto err_mem; + } + ret = devm_request_irq(dev, irq, zp_core_irq, IRQF_SHARED, + dev_name(dev), csis); + if (ret) + goto err_mem; + } + irq = platform_get_irq_byname(pdev, "link"); if (irq < 0) { ret = irq; @@ -2222,11 +2560,18 @@ static void gs201_csis_remove(struct platform_device *pdev) static const struct gs201_csis_soc gs201_csis_gs201 = { .wdma = true, .num_links = 8, + .pixel_mode = CSIS_ISPCFG_PIXEL_MODE_QUAD, + .dma_bits = CSIS_WDMA_ADDR_BITS, + .dbg_bit23 = true, }; /* Links 0-11 have contexts and interrupts; stock wires sensors to 0-8. */ static const struct gs201_csis_soc gs201_csis_zumapro = { .num_links = 12, + /* the zumapro HAL's CMN_CTRL bits 15:12 are 5, gs201's 4 */ + .cmn_ctrl_extra = ZP_LINK_CMN_CTRL_F12, + .pixel_mode = ZP_LINK_PIXEL_MODE, + .dma_bits = ZP_ADDR_BITS, }; static const struct of_device_id gs201_csis_of_match[] = { diff --git a/drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h b/drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h new file mode 100644 index 0000000000..1382040bd1 --- /dev/null +++ b/drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * zumapro (Tensor G4) CSIS core: the image logical channel (LoCH) path that + * writes a CSI-2 link's frames to memory. Offsets are from the ISP front + * end's CSIS core page (isp-fe 0x1c300000 + 0x20000). Names follow the + * Pixel 9a camera HAL's register table; the fields come from the HAL's own + * value packers and, for the interrupt bits, Google's GPL + * zuma-isp-event-info.dtsi and dt-bindings/lwis/platform/zuma/isp_fe.h. + */ +#ifndef ZUMAPRO_CSIS_CORE_H +#define ZUMAPRO_CSIS_CORE_H + +#include + +/* common page */ +#define ZP_LOCH_INT_ISR 0x008c /* bit n = LoCH n */ +#define ZP_LOCH_INT_IMR 0x0094 /* 1 passes the LoCH's interrupt */ +#define ZP_LOCH_EN 0x009c +#define ZP_LOCH_EN_SET 0x00a0 +#define ZP_LOCH_EN_CLR 0x00a4 +#define ZP_LOCH_ABORT 0x00ac +#define ZP_FRAME_ID_CLR 0x00b0 + +/* image LoCH n (0-6) */ +#define ZP_IMG(n, r) (0x0400 + 0x400 * (n) + (r)) +#define ZP_IMG_ABORT_DONE_ISR 0x004 +#define ZP_IMG_ABORT_DONE BIT(0) +#define ZP_IMG_WDMA_CONTEXT_ENABLE 0x018 +#define ZP_IMG_WDMA_CONFIG_ENABLE 0x01c +#define ZP_IMG_WDMA_CONFIG_MISS 0x020 +#define ZP_IMG_PROC_ISR 0x024 +#define ZP_IMG_PROC_IER 0x02c +#define ZP_IMG_PROC_IMR 0x030 +#define ZP_IMG_PROC_SOF BIT(0) +#define ZP_IMG_PROC_EOF BIT(1) +#define ZP_IMG_PROC_SHADOW_UPDATE BIT(3) +#define ZP_IMG_PROC_DMA_DONE BIT(4) +#define ZP_IMG_PROC_FRAME_DONE BIT(5) +#define ZP_IMG_ERR_ISR 0x038 +#define ZP_IMG_ERR_IMR 0x044 +#define ZP_IMG_ERRORS GENMASK(13, 0) +#define ZP_IMG_BATCH_INT_MSK_SOF 0x060 +#define ZP_IMG_BATCH_INT_MSK_EOF 0x064 +#define ZP_IMG_BATCH_INT_MSK_DMA_DONE 0x06c +#define ZP_IMG_BATCH_INT_MSK_FRAME_DONE 0x070 +#define ZP_IMG_ISP_RESOL 0x074 +#define ZP_IMG_ISP_RESOL_W GENMASK(15, 0) +#define ZP_IMG_ISP_RESOL_H GENMASK(31, 16) +#define ZP_IMG_AUTO_REC_SYNC_INTV0 0x078 +#define ZP_IMG_AUTO_REC_SYNC_INTV1 0x07c +#define ZP_IMG_BATCH_CTL 0x088 +#define ZP_IMG_CTL 0x08c +#define ZP_IMG_CTL_DT GENMASK(11, 8) +#define ZP_IMG_CTL_LINK_CH GENMASK(15, 12) +#define ZP_IMG_CTL_LINK GENMASK(27, 24) +#define ZP_IMG_FRAME_ID 0x09c +#define ZP_IMG_SQ_CONFIG_ID_LSB 0x108 +#define ZP_IMG_SQ_CONFIG_ID_MSB 0x10c +#define ZP_IMG_SQ_BASE_ADDR_LSB 0x110 +#define ZP_IMG_SQ_BASE_ADDR_MSB 0x114 +#define ZP_IMG_BAYER_ENABLE 0x140 +#define ZP_IMG_BAYER_CROP_EN 0x144 +#define ZP_IMG_BAYER_MEM_FORMAT 0x150 +#define ZP_IMG_BAYER_STRIDE 0x154 +#define ZP_IMG_BATCH_ADDR_LSB(i) (0x1c0 + 8 * (i)) +#define ZP_IMG_BATCH_ADDR_MSB(i) (0x1c4 + 8 * (i)) +#define ZP_IMG_ADDR_LSB_MASK GENMASK(31, 5) +#define ZP_IMG_ADDR_MSB_MASK GENMASK(3, 0) +#define ZP_IMG_WDMA_DBG_INFO 0x2d0 +#define ZP_IMG_AXI_RESP_ERR_STATUS 0x2d4 +#define ZP_IMG_ACTIVITY_STATUS 0x2e4 +#define ZP_IMG_DONE_FRAME_ID 0x2f0 + +/* ZP_IMG_CTL_DT, from the CSI-2 data type */ +#define ZP_DT_RAW8 0 +#define ZP_DT_RAW10 2 +#define ZP_DT_RAW12 4 +#define ZP_DT_RAW14 6 + +/* ZP_IMG_BAYER_MEM_FORMAT */ +#define ZP_MEM_FMT_8BIT 0 +#define ZP_MEM_FMT_RAW16 2 +#define ZP_MEM_FMT_RAW10_PACKED 4 /* as on the CSI-2 bus: 4 pixels in 5 bytes */ +#define ZP_MEM_FMT_RAW12_PACKED 5 + +#define ZP_ADDR_BITS 36 +#define ZP_STRIDE_ALIGN 32 + +/* the link's CMN_CTRL bits 15:12, as the zumapro HAL writes them */ +#define ZP_LINK_CMN_CTRL_F12 BIT(12) +#define ZP_LINK_PIXEL_MODE 3 + +#endif From 57bbdd436b9ea68518fb8a4808d6f61e8967a75e Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:49:59 -0647 Subject: [PATCH 07/14] dt-bindings: media: i2c: samsung,s5kgn1: Add the S5KGN8 The Pixel 9a main camera is a Samsung part with model ID 0x08e8 that takes the GN1's register layout and data file, with a second auxiliary supply and its digital supply switched by the board. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../bindings/media/i2c/samsung,s5kgn1.yaml | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml b/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml index 3325351f95..031f08548d 100644 --- a/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml +++ b/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml @@ -13,7 +13,8 @@ description: Samsung Bayer CMOS sensors with a MIPI CSI-2 C-PHY or D-PHY output, controlled over I2C - the S5KGN1 (ISOCELL GN1, 50 MP, dual-pixel phase detection), the S5K3J1 (10.5 MP, dual-pixel phase detection) and the - S5KGM5 (ISOCELL GM5, 48 MP). Their initialisation and readout modes are + S5KGM5 (ISOCELL GM5, 48 MP), and the S5KGN8 (model 0x08e8, the Pixel 9a + main camera). Their initialisation and readout modes are loaded from a data file named by firmware-name. allOf: @@ -21,7 +22,9 @@ allOf: - if: properties: compatible: - const: samsung,s5kgn1 + enum: + - samsung,s5kgn1 + - samsung,s5kgn8 then: required: - vaux-supply @@ -29,6 +32,19 @@ allOf: else: properties: vaux-supply: false + - if: + properties: + compatible: + const: samsung,s5kgn8 + then: + required: + - vaux2-supply + - vdig-supply + properties: + vsw-supply: false + else: + properties: + vaux2-supply: false - if: properties: compatible: @@ -52,6 +68,7 @@ properties: - samsung,s5k3j1 - samsung,s5kgm5 - samsung,s5kgn1 + - samsung,s5kgn8 reg: maxItems: 1 @@ -71,6 +88,11 @@ properties: The module's auxiliary supply (2.9 V on the Pixel 7 Pro, shared with its focus actuator), switched on right after the interface supply. + vaux2-supply: + description: + A second auxiliary supply (2.9 V on the Pixel 9a, shared with the + module's focus actuator and EEPROM), switched on after vaux-supply. + vsw-supply: description: A switched module supply, on before the core supplies (S5KGN1) or From 0a4543c4f0d4e66ff60d341a9d76c5c61c088bf3 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:49:45 -0647 Subject: [PATCH 08/14] media: i2c: s5kgn1: Add the S5KGN8 The Pixel 9a main camera (model 0x08e8) powers up as stock's module power sequence has it: the interface supply, two 2.9 V auxiliary supplies, the analog and the digital supply, reset released, then the clock and 10 ms. Its soft reset goes through the direct page, its standard registers too, and its horizontal addresses count pixels. Its initialisation and modes come from the data file, as for the other parts. On the Pixel 9a it identifies at 0x56 and streams 2000x1128 over three C-PHY trios. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- drivers/media/i2c/s5kgn1.c | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/s5kgn1.c b/drivers/media/i2c/s5kgn1.c index df7561e8be..1573dfa2a1 100644 --- a/drivers/media/i2c/s5kgn1.c +++ b/drivers/media/i2c/s5kgn1.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Samsung S5KGN1, S5K3J1 and S5KGM5 image sensor driver + * Samsung S5KGN1, S5K3J1, S5KGM5 and S5KGN8 image sensor driver * * The S5KGN1 (ISOCELL GN1) is a 50 MP Samsung Bayer sensor with dual-pixel * phase detection and a MIPI CSI-2 C-PHY or D-PHY output; the S5K3J1 a @@ -243,6 +243,41 @@ static const struct s5kgn1_variant s5kgm5_variant = { .crop_x_div = 1, }; +/* + * GN8, the Pixel 9a main camera, in stock's power-up order: pp3200_bb, + * pp1350, s2mpg15_ldo12 (I/O), slg51002 ldo5 (2.9 V), ldo4 (2.9 V), ldo1 + * (2.25 V, analog), the digital supply's enable, reset released, the clock; + * 1 ms after each, 10 ms after the clock. Its soft reset goes through the + * direct page (0xfcfc = 0x4000, 0x6010 = 1), 10 ms, and nothing enables a + * clock after it; standard registers in the direct page. Horizontal + * addresses count pixels, one per column (80..8142 for a 2x2-binned 4000). + * + * [I] ldo5/ldo4 roles: both 2.9 V and shared by the sensor, EEPROM, AF and + * OIS nodes, so which one the sensor itself needs isn't known; both stay + * required here. The driver has one supply delay (after delay_supply), so + * stock's 1 ms between ldo5, ldo4, ldo1 and vdig is left out unless the + * driver grows a per-supply step. + */ +static const char * const s5kgn8_supplies[] = { + "vbb", "vbuck", "vio", "vaux", "vaux2", "vana", "vdig", +}; + +static const struct s5kgn1_variant s5kgn8_variant = { + .name = "S5KGN8", + .model = "s5kgn8", + .chip_id = 0x08e8, + .supplies = s5kgn8_supplies, + .num_supplies = ARRAY_SIZE(s5kgn8_supplies), + .optional = BIT(0) | BIT(1), + .delay_supply = 2, /* 1 ms after vio */ + .delays_us = { 1000, 1000, 1000, 10000 }, + .reset_before_clock = true, /* reset, 1 ms, clock, 10 ms */ + .direct_page = true, + .clock_enable = false, + .soft_reset_us = 10000, + .crop_x_div = 1, +}; + static const u32 s5kgn1_mbus_codes[] = { MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10, @@ -1325,6 +1360,7 @@ static const struct of_device_id s5kgn1_of_match[] = { { .compatible = "samsung,s5k3j1", .data = &s5k3j1_variant }, { .compatible = "samsung,s5kgm5", .data = &s5kgm5_variant }, { .compatible = "samsung,s5kgn1", .data = &s5kgn1_variant }, + { .compatible = "samsung,s5kgn8", .data = &s5kgn8_variant }, { } }; MODULE_DEVICE_TABLE(of, s5kgn1_of_match); @@ -1340,5 +1376,5 @@ static struct i2c_driver s5kgn1_driver = { }; module_i2c_driver(s5kgn1_driver); -MODULE_DESCRIPTION("Samsung S5KGN1, S5K3J1 and S5KGM5 sensor driver"); +MODULE_DESCRIPTION("Samsung S5KGN1, S5K3J1, S5KGM5 and S5KGN8 sensor driver"); MODULE_LICENSE("GPL"); From 763c3b1188924c121baa5e2b3e37182cca9fc393 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:56:56 -0647 Subject: [PATCH 09/14] media: gs201-csis: Reset the zumapro LoCH before each stream All zumapro links write through image LoCH 0, so a stream that stopped with the LoCH in error (the main camera's first C-PHY attempts) left it taking a few frames and then nothing for the next link. Disable, abort and clear the LoCH before routing it. Count the core interrupts each link handles in debugfs, with the last aggregate and processing sources. Bring-up parameters for the link and the core (pixel and parallel mode, CMN_CTRL bits, LoCH data type and memory format) stay for the C-PHY work. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../platform/samsung/gs201-csis/gs201-csis.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c index c6412ec4a0..998b71c88a 100644 --- a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c +++ b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c @@ -139,6 +139,9 @@ struct gs201_csis_stats { u32 dropped; u32 missed_fe; u32 link_irqs; + u32 core_irqs; /* zumapro: core interrupts this link handled */ + u32 core_last_agg; + u32 core_last_proc; u32 wdma_started_at; /* the link frame end the WDMA started at */ u32 wdma_restarts; /* wdma_recover restarts */ u32 wdma_lines; /* line ends since the channel's last frame start */ @@ -719,6 +722,21 @@ static void zp_core_set_addr(struct gs201_csis *csis, dma_addr_t addr) /* The LoCH takes the link's channel 0 (VC 0) data type, as the HAL routes it. */ static void zp_core_route(struct gs201_csis *csis) { + u32 val; + + /* a LoCH a previous stream left running or in error starts clean */ + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 0); + img_write(csis, ZP_IMG_WDMA_CONTEXT_ENABLE, 0); + core_write(csis, ZP_LOCH_EN_CLR, BIT(csis->loch)); + core_write(csis, ZP_LOCH_ABORT, BIT(csis->loch)); + if (readl_poll_timeout(csis->core + ZP_IMG(csis->loch, ZP_IMG_ABORT_DONE_ISR), + val, val & ZP_IMG_ABORT_DONE, 100, 20000)) + dev_dbg(csis->dev, "LoCH %u: no abort-done at start\n", csis->loch); + img_write(csis, ZP_IMG_ABORT_DONE_ISR, val); + img_write(csis, ZP_IMG_PROC_ISR, img_read(csis, ZP_IMG_PROC_ISR)); + img_write(csis, ZP_IMG_ERR_ISR, img_read(csis, ZP_IMG_ERR_ISR)); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); + core_write(csis, ZP_FRAME_ID_CLR, BIT(csis->loch)); img_write(csis, ZP_IMG_AUTO_REC_SYNC_INTV0, 0); img_write(csis, ZP_IMG_AUTO_REC_SYNC_INTV1, 0); @@ -1203,9 +1221,12 @@ static irqreturn_t zp_core_irq(int irq, void *data) return IRQ_NONE; agg = core_read(csis, ZP_LOCH_INT_ISR); + csis->stats.core_last_agg = agg; if (!(agg & BIT(csis->loch))) return IRQ_NONE; proc = img_read(csis, ZP_IMG_PROC_ISR); + csis->stats.core_irqs++; + csis->stats.core_last_proc = proc; err = img_read(csis, ZP_IMG_ERR_ISR) & ZP_IMG_ERRORS; img_write(csis, ZP_IMG_PROC_ISR, proc); if (err) @@ -2035,6 +2056,8 @@ static int gs201_csis_stats_show(struct seq_file *s, void *unused) seq_printf(s, "wdma_done %u\nwdma_errors %u\nlast_wdma_err 0x%08x\ndropped %u\nmissed_fe %u\nlink_irqs %u\n", st.wdma_done, st.wdma_errors, st.last_wdma_err, st.dropped, st.missed_fe, st.link_irqs); + seq_printf(s, "core_irqs %u\ncore_last_agg 0x%08x\ncore_last_proc 0x%08x\n", + st.core_irqs, st.core_last_agg, st.core_last_proc); gs201_csis_print_bits(s, NULL, "int0", st.int0_bits, 32); gs201_csis_print_bits(s, NULL, "int1", st.int1_bits, 8); gs201_csis_print_bits(s, NULL, "wdma", st.wdma_bits, 32); From 74ef7c65516dbf7a53393b38c2b2907d22e901c3 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:05:09 -0647 Subject: [PATCH 10/14] media: gs201-csis: Leave PHY_CMN_CTRL alone on zumapro zumapro's camera software never writes the link's PHY_CMN_CTRL: its PHY lanes are enabled in the DC-PHY transaction. Write it on gs201 only. The ultrawide and front cameras stream as before without it. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- drivers/media/platform/samsung/gs201-csis/gs201-csis.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c index 998b71c88a..2525b7f811 100644 --- a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c +++ b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c @@ -97,6 +97,8 @@ struct gs201_csis_soc { * zumapro's clears it: its CSIS core unpacks the packed CSI-2 stream. */ bool dbg_bit23; + /* PHY_CMN_CTRL lane enables: gs201 sets them; zumapro never writes it */ + bool phy_cmn_ctrl; }; struct gs201_csis_format { @@ -657,7 +659,8 @@ static void gs201_csis_link_start(struct gs201_csis *csis, csis->lrte_epd ? CSIS_LRTE_EPD_EN | CSIS_LRTE_SPACERS_RESET : CSIS_LRTE_DEFAULT); link_write(csis, CSIS_UPD_SDW, CSIS_UPD_SDW_ALL); - link_write(csis, CSIS_PHY_CMN_CTRL, CSIS_PHY_CMN_CTRL_ENABLE); + if (csis->soc->phy_cmn_ctrl) + link_write(csis, CSIS_PHY_CMN_CTRL, CSIS_PHY_CMN_CTRL_ENABLE); link_write(csis, CSIS_INT_MSK0, int0_mask & CSIS_INT0_ERRORS); link_write(csis, CSIS_INT_MSK1, CSIS_INT1_FRAME_START | @@ -826,7 +829,8 @@ static void gs201_csis_link_stop(struct gs201_csis *csis) link_write(csis, CSIS_INT_MSK1, 0); link_write(csis, CSIS_CMN_CTRL, link_read(csis, CSIS_CMN_CTRL) & ~CSIS_CMN_CTRL_CSI_EN); - link_write(csis, CSIS_PHY_CMN_CTRL, 0); + if (csis->soc->phy_cmn_ctrl) + link_write(csis, CSIS_PHY_CMN_CTRL, 0); } /* ----------------------------------------------------------------------------- @@ -2586,6 +2590,7 @@ static const struct gs201_csis_soc gs201_csis_gs201 = { .pixel_mode = CSIS_ISPCFG_PIXEL_MODE_QUAD, .dma_bits = CSIS_WDMA_ADDR_BITS, .dbg_bit23 = true, + .phy_cmn_ctrl = true, }; /* Links 0-11 have contexts and interrupts; stock wires sensors to 0-8. */ From a153db0651bd617a6f3f7d1c5575ca0b34f3904d Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:39:58 -0647 Subject: [PATCH 11/14] dt-bindings: media: google,gs201-csis: Add zumapro's ISP front end clocks A zumapro link takes the INT DVFS domain, the rail of the ISP front end's NOC clock, and that clock, as "int" and "fe". gs201 keeps its "cam" and "int" DVFS domains. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../bindings/media/google,gs201-csis.yaml | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml index ad4220e787..cae6c53cc1 100644 --- a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml +++ b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml @@ -39,14 +39,10 @@ properties: maxItems: 2 clocks: - items: - - description: the camera block's DVFS domain - - description: the bus (INT) DVFS domain + maxItems: 2 clock-names: - items: - - const: cam - - const: int + maxItems: 2 phys: maxItems: 1 @@ -164,6 +160,14 @@ allOf: items: - const: link - const: wdma + clocks: + items: + - description: the camera block's DVFS domain + - description: the bus (INT) DVFS domain + clock-names: + items: + - const: cam + - const: int google,csis-link: maximum: 7 google,image-loch: false @@ -193,6 +197,14 @@ allOf: items: - const: link - const: core + clocks: + items: + - description: the INT DVFS domain, the ISP front end clock's rail + - description: the ISP front end's NOC clock + clock-names: + items: + - const: int + - const: fe google,wdma-context: false google,csis-sysreg: false google,ebuf: false From 8a266a5daa1aa68664b8b43615cfe2c39e6b2502 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:39:58 -0647 Subject: [PATCH 12/14] media: gs201-csis: Raise zumapro's ISP front end clock while streaming ABL leaves the ISP front end's NOC clock at a sixth of SHARED3 (111 MHz). The Pixel 9a main camera's three C-PHY trios at 2740 Msps (18.8 Gbps) overrun the front end at that rate: the link reports ERR_DESKEW_OVER and the LoCH a size mismatch and stream error, with a few hundred bytes of each frame in memory. At 332 MHz every frame lands whole. Take the INT DVFS domain (the clock's rail, through ACPM) and the front end clock as "int" and "fe", and raise both while a link streams, the rail first, restoring them in reverse afterwards. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../platform/samsung/gs201-csis/gs201-csis.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c index 2525b7f811..3dc18d2fe8 100644 --- a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c +++ b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c @@ -165,6 +165,8 @@ struct gs201_csis { unsigned int loch; /* zumapro: the image LoCH this link writes through */ void *sq_buf; /* zumapro: the LoCH's status queue */ dma_addr_t sq_dma; + struct clk *fe_clk; /* zumapro: the ISP front end's NOC clock */ + unsigned long fe_rate_old; void *scratch; /* zumapro: frames with no buffer go here */ dma_addr_t scratch_dma; size_t scratch_size; @@ -345,6 +347,20 @@ static int zp_mem_fmt = -1; module_param(zp_mem_fmt, int, 0644); MODULE_PARM_DESC(zp_mem_fmt, "zumapro Bayer WDMA memory format (bring-up; default RAW10 packed 4, 2 RAW16)"); +/* + * zumapro: ABL leaves the front end's NOC clock at a sixth of SHARED3 + * (111 MHz); the main camera's C-PHY link (18.8 Gbps) then overruns the + * front end (link ERR_DESKEW_OVER, short frames). While a link streams, the + * INT DVFS domain (the clock's rail) goes up first, then the clock. + */ +static unsigned int fe_khz = 331776; +module_param(fe_khz, uint, 0644); +MODULE_PARM_DESC(fe_khz, "zumapro ISP-FE NOC clock in kHz while streaming (0: leave it)"); + +static unsigned int fe_int_khz = 533000; +module_param(fe_int_khz, uint, 0644); +MODULE_PARM_DESC(fe_int_khz, "zumapro INT DVFS rate in kHz while streaming, before the ISP-FE clock (0: leave it)"); + static int cmn_ctrl_extra = -1; module_param(cmn_ctrl_extra, int, 0644); MODULE_PARM_DESC(cmn_ctrl_extra, "Extra link CMN_CTRL bits (bring-up; default the SoC's)"); @@ -1911,10 +1927,16 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) spin_unlock_irqrestore(&csis->slock, flags); if (csis->dma_on && csis->core) { + gs201_csis_dvfs_vote(csis, csis->int_clk, "INT", fe_int_khz, + &csis->int_rate_old); + gs201_csis_dvfs_vote(csis, csis->fe_clk, "ISP-FE", fe_khz, + &csis->fe_rate_old); csis->scratch_size = csis->pix.sizeimage; csis->scratch = dma_alloc_coherent(csis->dev, csis->scratch_size, &csis->scratch_dma, GFP_KERNEL); if (!csis->scratch) { + gs201_csis_dvfs_restore(csis->fe_clk, &csis->fe_rate_old); + gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); ret = -ENOMEM; goto err_pipeline; } @@ -1945,6 +1967,8 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) dma_free_coherent(csis->dev, csis->scratch_size, csis->scratch, csis->scratch_dma); csis->scratch = NULL; + gs201_csis_dvfs_restore(csis->fe_clk, &csis->fe_rate_old); + gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); } else if (csis->dma_on) { gs201_csis_wdma_stop(csis); gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); @@ -2001,6 +2025,8 @@ static void gs201_csis_stop_streaming(struct vb2_queue *vq) dma_free_coherent(csis->dev, csis->scratch_size, csis->scratch, csis->scratch_dma); csis->scratch = NULL; + gs201_csis_dvfs_restore(csis->fe_clk, &csis->fe_rate_old); + gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); } else if (csis->dma_on) { gs201_csis_wdma_stop(csis); gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); @@ -2424,6 +2450,9 @@ static int gs201_csis_probe(struct platform_device *pdev) return -ENOMEM; } device_property_read_u32(dev, "google,image-loch", &csis->loch); + csis->fe_clk = devm_clk_get_optional(dev, "fe"); + if (IS_ERR(csis->fe_clk)) + return dev_err_probe(dev, PTR_ERR(csis->fe_clk), "ISP-FE clock\n"); if (csis->loch > 6) return dev_err_probe(dev, -EINVAL, "bad google,image-loch\n"); goto no_wdma; From 3de34753bae1054b5b308f84754032406452d7d6 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:42:38 -0647 Subject: [PATCH 13/14] dt-bindings: media: i2c: sony,imx386: Add the IMX712 The Pixel 9a's ultrawide and front cameras are Sony IMX712s (model 0x0712), with the IMX386's register map and their own initialisation and modes in the data file. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../devicetree/bindings/media/i2c/sony,imx386.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml b/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml index 43d08cf600..5452de0770 100644 --- a/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml +++ b/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml @@ -4,22 +4,25 @@ $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 IMX712 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 IMX712 (the Pixel 9a's ultrawide and front + cameras), which has 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# properties: compatible: - const: sony,imx386 + enum: + - sony,imx386 + - sony,imx712 reg: maxItems: 1 From 654639ec73268fba90948c192f21e262789e8515 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:42:38 -0647 Subject: [PATCH 14/14] media: i2c: imx386: Add the IMX712 The Pixel 9a's ultrawide and front cameras answer with model 0x0712 at the IMX386's chip ID register and take the same CCS-style register map. Take the expected model ID from the compatible, for the probe's check and the data file's header. Both cameras stream 4208x3072 RAW10 on four D-PHY lanes on the palmtop with their data file from the 9a's camera HAL. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- drivers/media/i2c/imx386.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx386.c b/drivers/media/i2c/imx386.c index 28ef2934f4..c82b51addf 100644 --- a/drivers/media/i2c/imx386.c +++ b/drivers/media/i2c/imx386.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ #define IMX386_REG_FRAME_COUNT CCI_REG8(0x0005) #define IMX386_REG_CHIP_ID CCI_REG16(0x0016) #define IMX386_CHIP_ID 0x0386 +#define IMX712_CHIP_ID 0x0712 #define IMX386_REG_EXPOSURE CCI_REG16(0x0202) #define IMX386_REG_ANALOG_GAIN CCI_REG16(0x0204) /* per colour channel: Gr, R, B, Gb (CCS) */ @@ -152,6 +154,7 @@ struct imx386 { struct clk *mclk; struct gpio_desc *reset; + u16 chip_id; /* IMX386 (Pixel 7 Pro) or IMX712 (Pixel 9a), from the compatible */ struct regulator *supplies[IMX386_NUM_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 +300,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); @@ -897,10 +900,10 @@ 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); @@ -919,6 +922,7 @@ static int imx386_probe(struct i2c_client *client) return -ENOMEM; s->dev = dev; + s->chip_id = (uintptr_t)device_get_match_data(dev) ?: IMX386_CHIP_ID; v4l2_i2c_subdev_init(&s->sd, client, &imx386_subdev_ops); s->sd.internal_ops = &imx386_internal_ops; @@ -1042,7 +1046,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 = (void *)IMX386_CHIP_ID }, + /* Pixel 9a ultrawide: same CCS-style register map, own init and modes in its data file */ + { .compatible = "sony,imx712", .data = (void *)IMX712_CHIP_ID }, { } }; MODULE_DEVICE_TABLE(of, imx386_of_match); @@ -1058,5 +1064,5 @@ static struct i2c_driver imx386_driver = { }; module_i2c_driver(imx386_driver); -MODULE_DESCRIPTION("Sony IMX386 sensor driver"); +MODULE_DESCRIPTION("Sony IMX386 and IMX712 sensor driver"); MODULE_LICENSE("GPL");