From 5d17f9afea37dd1330eb2c2baf68f27aedeb60e2 Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Fri, 4 Dec 2026 23:14:44 +0000 Subject: [PATCH 1/3] media: apple: t8010-isp: Add the A9's torch The A9 cameras had no controls, so the 6s Plus's rear flash could not be used as a torch. Its firmware has the A10's torch commands: the command table names CH_LED_TORCH_OFF 0x602 and CH_LED_TORCH_ON 0x603, and the handler for 0x603 passes the u32 at +0xc on to the strobe task, as the A10's does with the level. The flash driver sits on the firmware's own I2C; the kernel only raises its enable (the strobe GPIO, ADT function-torch_enable) at power-on, which the A9 path already does. On the A9 the level is not the A10's 1-255 of 50 mA per driver. The flash driver's torch method writes the module's calibrated torch code as it is for level 6 and above, and scales it for levels 1-5: the level is in sixths of the module's calibrated current. Read back with CH_LED_TORCH_CURRENTS_GET on an N66, levels 1 to 6 give 22, 22, 46, 46, 68 and 94 mA in all: the drivers' current only changes at 1, 3, 5 and 6. Split the torch from the A10-only controls with its top level in the match data, 255 on the A10 (unchanged) and 4 on the A9, plus a table of the firmware's level per step (1, 3, 5, 6) on the A9. The camera with the torch flag gets the V4L2_CID_FLASH_LED_MODE and V4L2_CID_FLASH_TORCH_INTENSITY controls (1 to the top level, its middle as the default) and the "white:flash" LED is registered with the same max_brightness, both through the existing isp_set_torch(). Tested on an N66 (Samsung): the rear node gets led_mode and intensity_torch_mode and the white:flash LED registers; the control reads 1-4, default 2, each step lights the rear LED brighter than the one before, and led_mode=0 turns it off, with no firmware errors. [Orchard: rebased onto the per-camera table (#157), keyed on its torch flag instead of camera index 0, and squashed the three commits of the pull request (torch, six levels, four steps) into one] Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> Assisted-by: LLM --- drivers/media/platform/apple/isp/t8010_isp.c | 72 ++++++++++++++------ 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/drivers/media/platform/apple/isp/t8010_isp.c b/drivers/media/platform/apple/isp/t8010_isp.c index ac3612b8f00cc6..2401bde45f08f2 100644 --- a/drivers/media/platform/apple/isp/t8010_isp.c +++ b/drivers/media/platform/apple/isp/t8010_isp.c @@ -31,8 +31,8 @@ * reference clocks and three rails, and it needs three writes before its * CPU starts. Its buffer pools follow the A8's numbering, per channel, and * it streams with the A8's setup. Its cameras (rear channel 0, front - * channel 1) are V4L2 devices too, NV12 at the firmware's rate and without - * controls or set-files so far; debugfs is s8000-isp/. + * channel 1) are V4L2 devices too, NV12 at the firmware's rate, with the + * rear's torch as the only controls; debugfs is s8000-isp/. */ #include @@ -212,10 +212,14 @@ struct isp_soc { const struct isp_cam *cams; /* in video node order */ unsigned int n_cams; /* - * What is known on the A10 only: 3A, frame-rate and torch controls - * (with the torch LED), set-files, the metadata's layout, YUYV output + * What is known on the A10 only: 3A and frame-rate controls, + * set-files, the metadata's layout, YUYV output */ bool controls; + /* the torch's top level (the rear's flash controls, the torch LED); 0: none */ + u32 torch_max; + /* the firmware's level for each step 1..torch_max; NULL: the step itself */ + const u32 *torch_levels; /* * The A8's stream setup (A9): buffer recycling and the crop, output * range 1, SIF format {3, 1}, the buffers queued before CH_START @@ -3027,8 +3031,19 @@ static const struct v4l2_file_operations isp_fops = { * LM3566 drivers over its own I2C, so it runs while the torch is on, streaming * or not. @level 1-255 of the firmware's 50 mA per driver (255: 98 mA in all, * by CH_LED_TORCH_CURRENTS_GET), 0 off. From the rear camera's flash controls - * and the "white:flash" LED. + * and the "white:flash" LED. The A9's firmware takes the same commands, the + * level at +0xc too, but in sixths of the module's calibrated torch current: + * levels 1-5 scale it, 6 and above give all of it. Its flash driver's enable + * is the strobe GPIO. */ + +/* + * The A9's torch steps: the drivers' current only changes at levels 1, 3, 5 + * and 6 (22, 46, 68 and 94 mA in all, by CH_LED_TORCH_CURRENTS_GET on an N66); + * 2 and 4 give the same current as the level below them. + */ +static const u32 isp_s8000_torch_levels[] = { 1, 3, 5, 6 }; + static int isp_set_torch(struct t8010_isp *isp, u32 level) { u32 was; @@ -3044,10 +3059,13 @@ static int isp_set_torch(struct t8010_isp *isp, u32 level) goto out; } mutex_lock(&isp->lock); - if (level) - ret = isp_ch_cmd(isp, 0, CMD_CH_TORCH_ON, 0x10, &level, 1); - else + if (level) { + u32 fw = isp->soc->torch_levels ? isp->soc->torch_levels[level - 1] : level; + + ret = isp_ch_cmd(isp, 0, CMD_CH_TORCH_ON, 0x10, &fw, 1); + } else { isp_ch_cmd(isp, 0, CMD_CH_TORCH_OFF, 0xc, NULL, 0); + } mutex_unlock(&isp->lock); if (ret) { if (!was) @@ -3234,6 +3252,19 @@ static const struct v4l2_ctrl_config isp_hfr_ctrl = { .min = 0, .max = 1, .step = 1, .def = 0, }; +/* the rear camera's torch: TORCH turns it on, at the intensity (1 to the SoC's top) */ +static void isp_torch_ctrls(struct isp_video *v) +{ + u32 max = v->isp->soc->torch_max; + + v->led_mode = v4l2_ctrl_new_std_menu(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FLASH_LED_MODE, + V4L2_FLASH_LED_MODE_TORCH, + BIT(V4L2_FLASH_LED_MODE_FLASH), + V4L2_FLASH_LED_MODE_NONE); + v->torch = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FLASH_TORCH_INTENSITY, + 1, max, 1, DIV_ROUND_UP(max, 2)); +} + /* the A10's controls: sensor rotation, 3A, the rear's focus and torch, sizes and rates */ static int isp_video_ctrls(struct isp_video *v) { @@ -3277,13 +3308,7 @@ static int isp_video_ctrls(struct isp_video *v) V4L2_AUTO_FOCUS_STATUS_FAILED, 0, 0); } if (cam->torch) { /* the rear camera: the flash, high frame rates */ - v->led_mode = v4l2_ctrl_new_std_menu(&v->ctrls, &isp_ctrl_ops, - V4L2_CID_FLASH_LED_MODE, - V4L2_FLASH_LED_MODE_TORCH, - BIT(V4L2_FLASH_LED_MODE_FLASH), - V4L2_FLASH_LED_MODE_NONE); - v->torch = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, - V4L2_CID_FLASH_TORCH_INTENSITY, 1, 255, 1, 128); + isp_torch_ctrls(v); v4l2_ctrl_new_custom(&v->ctrls, &isp_hfr_ctrl, NULL); } v4l2_ctrl_new_custom(&v->ctrls, &isp_uhd_ctrl, NULL); @@ -3349,7 +3374,13 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i, V4L2_CAMERA_ORIENTATION_EXTERNAL, 0, cam->front ? V4L2_CAMERA_ORIENTATION_FRONT : V4L2_CAMERA_ORIENTATION_BACK); - ret = isp->soc->controls ? isp_video_ctrls(v) : v->ctrls.error; + if (isp->soc->controls) { + ret = isp_video_ctrls(v); + } else { + if (cam->torch && isp->soc->torch_max) /* the A9: the torch only */ + isp_torch_ctrls(v); + ret = v->ctrls.error; + } if (ret) return ret; @@ -3973,10 +4004,10 @@ static int isp_probe(struct platform_device *pdev) } /* desktop torch toggles look for a "*:flash" LED */ isp->torch_led.name = "white:flash"; - isp->torch_led.max_brightness = 255; + isp->torch_led.max_brightness = isp->soc->torch_max; isp->torch_led.brightness_set_blocking = isp_torch_led_set; isp->torch_led.flags = LED_CORE_SUSPENDRESUME; - ret = isp->soc->controls ? led_classdev_register(dev, &isp->torch_led) : 0; + ret = isp->soc->torch_max ? led_classdev_register(dev, &isp->torch_led) : 0; if (ret) goto err_cameras; dev_info(dev, "%u power domains, platform %#x; debugfs %s/\n", @@ -3999,7 +4030,7 @@ static void isp_remove(struct platform_device *pdev) struct t8010_isp *isp = platform_get_drvdata(pdev); unsigned int i; - if (isp->soc->controls) { + if (isp->soc->torch_max) { led_classdev_unregister(&isp->torch_led); /* turns the torch off */ isp_set_torch(isp, 0); } @@ -4073,6 +4104,7 @@ static const struct isp_soc isp_t8010 = { .cams = isp_t8010_cams, .n_cams = ARRAY_SIZE(isp_t8010_cams), .controls = true, + .torch_max = 255, }; /* the A8's layout: 0x24-0x40 and 0x48-0x64, busy at 0x44 and 0x68 */ @@ -4117,6 +4149,8 @@ static const struct isp_soc isp_s8000 = { .cams = isp_s8000_cams, .n_cams = ARRAY_SIZE(isp_s8000_cams), .a8_stream = true, + .torch_max = ARRAY_SIZE(isp_s8000_torch_levels), + .torch_levels = isp_s8000_torch_levels, /* the 6s: pools 1 and 2 on channel 0, 16 and 17 on channel 1 */ .chan_pools = 15, .meta_pool = 1, From d0921889d6beed4ed2164d7495405449d1f0cdb2 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 09:26:58 +0800 Subject: [PATCH 2/3] media: apple: t8010-isp: Register the torch only on boards with a flash The torch controls and the "white:flash" LED were registered on every board that runs the ISP, flash or not. The iPads with these ISPs (the A10 iPads, and the A9's) have no flash, so desktop torch toggles found an LED that lights nothing. Only the boards with a flash wire its enable, strobe-gpios: the iPhone 6s and 6s Plus (s800x-6s.dtsi) and the iPhone 7 and 7 Plus (t8010-7.dtsi). Register the torch only when the DT has it. Assisted-by: LLM Signed-off-by: Henrik Klee --- drivers/media/platform/apple/isp/t8010_isp.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/apple/isp/t8010_isp.c b/drivers/media/platform/apple/isp/t8010_isp.c index 2401bde45f08f2..d4ff5b3ce511e4 100644 --- a/drivers/media/platform/apple/isp/t8010_isp.c +++ b/drivers/media/platform/apple/isp/t8010_isp.c @@ -3044,6 +3044,15 @@ static const struct v4l2_file_operations isp_fops = { */ static const u32 isp_s8000_torch_levels[] = { 1, 3, 5, 6 }; +/* + * Only a board with a flash has the torch: its DT wires the flash's enable + * (strobe-gpios). The iPads with these ISPs have no flash and no torch. + */ +static bool isp_has_torch(struct t8010_isp *isp) +{ + return isp->soc->torch_max && isp->strobe; +} + static int isp_set_torch(struct t8010_isp *isp, u32 level) { u32 was; @@ -3308,7 +3317,8 @@ static int isp_video_ctrls(struct isp_video *v) V4L2_AUTO_FOCUS_STATUS_FAILED, 0, 0); } if (cam->torch) { /* the rear camera: the flash, high frame rates */ - isp_torch_ctrls(v); + if (isp_has_torch(v->isp)) + isp_torch_ctrls(v); v4l2_ctrl_new_custom(&v->ctrls, &isp_hfr_ctrl, NULL); } v4l2_ctrl_new_custom(&v->ctrls, &isp_uhd_ctrl, NULL); @@ -3377,7 +3387,7 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i, if (isp->soc->controls) { ret = isp_video_ctrls(v); } else { - if (cam->torch && isp->soc->torch_max) /* the A9: the torch only */ + if (cam->torch && isp_has_torch(isp)) /* the A9: the torch only */ isp_torch_ctrls(v); ret = v->ctrls.error; } @@ -4007,7 +4017,7 @@ static int isp_probe(struct platform_device *pdev) isp->torch_led.max_brightness = isp->soc->torch_max; isp->torch_led.brightness_set_blocking = isp_torch_led_set; isp->torch_led.flags = LED_CORE_SUSPENDRESUME; - ret = isp->soc->torch_max ? led_classdev_register(dev, &isp->torch_led) : 0; + ret = isp_has_torch(isp) ? led_classdev_register(dev, &isp->torch_led) : 0; if (ret) goto err_cameras; dev_info(dev, "%u power domains, platform %#x; debugfs %s/\n", @@ -4030,7 +4040,7 @@ static void isp_remove(struct platform_device *pdev) struct t8010_isp *isp = platform_get_drvdata(pdev); unsigned int i; - if (isp->soc->torch_max) { + if (isp_has_torch(isp)) { led_classdev_unregister(&isp->torch_led); /* turns the torch off */ isp_set_torch(isp, 0); } From c368421caad656ba0339088e7210fe27e36fa12c Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 09:26:58 +0800 Subject: [PATCH 3/3] dt-bindings: media: apple,t8010-isp: Tie the torch to strobe-gpios Say that strobe-gpios is present only on the boards with a flash, and that the driver offers the torch only with it. Assisted-by: LLM Signed-off-by: Henrik Klee --- Documentation/devicetree/bindings/media/apple,t8010-isp.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml b/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml index 4a49731333b35e..cbd976f80bf2e1 100644 --- a/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml +++ b/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml @@ -77,7 +77,8 @@ properties: strobe-gpios: maxItems: 1 - description: the flash's supply enable + description: the flash's supply enable, on the boards that have a flash + (the iPhones) only; the torch exists only with it apple,platform-id: $ref: /schemas/types.yaml#/definitions/uint32