From 6eb385bef5e1fa50604e9fe3be29f58064811819 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 19 Nov 2026 21:40:08 +0700 Subject: [PATCH 01/12] dt-bindings: media: apple,t8140-isp: Add apple,module-tuning Some Macs pair a sensor with a camera module that has its own tuning file. Let the ISP node name it, e.g. "2226_02" for the J815's IMX958. Signed-off-by: Nick --- .../devicetree/bindings/media/apple,t8140-isp.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml b/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml index f06c6998e2dc5..10e3c723fdb8c 100644 --- a/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml +++ b/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml @@ -98,6 +98,13 @@ properties: camera streams whether or not the indicator is shown. The indicator is software, not a privacy guarantee. + apple,module-tuning: + $ref: /schemas/types.yaml#/definitions/string + pattern: "^[0-9]{4}_[0-9]{2}$" + description: + Name of the camera module's own tuning (setfile), loaded in place of + the sensor's default one, e.g. "2226_02" for apple/isp_2226_02XX.dat. + sensor-presets: type: object description: From 6ad6ac690de951b66aed310201bb8ef3cdd54f0c Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 19 Nov 2026 21:40:15 +0700 Subject: [PATCH 02/12] media: apple: isp: Load the camera module tuning the DT names The J813 and the J815 (MacBook Air 13" and 15" M5) both have an IMX958 sensor, and both have run its default 2224_01 setfile. The J815's camera module has its own tunings, 2226_01 and 2226_02, in the H17-native form (lens-shading records without the xx24 stride). With 2224_01 the J815's raw picture is dark in the corners. Corner/centre brightness on one J815, raw camera, same scene, each file loaded into a freshly started firmware: 2224_01 0.50 2226_01 0.63 2226_02 0.85 Load the tuning the ISP node's apple,module-tuning names. A board without the property, or with a name that is not a setfile of its sensor, keeps the sensor's default. The 2226 files are not in every vendor firmware set yet, so a missing one falls back to 2224_01 instead of leaving the camera untuned. Tested on J815, with the file picked by a module parameter at the time: all three files load and stream (no command timeouts), 2226_02 also across several camera restarts. KUnit: isp_test_module_tuning (match, another sensor, unknown names) and isp_test_setfile_fallbacks (each fallback is the same sensor, no larger, and final). Signed-off-by: Nick --- .../media/platform/apple/isp/isp-cam-test.c | 51 +++++++++++++++++++ drivers/media/platform/apple/isp/isp-cam.c | 47 ++++++++++++++++- drivers/media/platform/apple/isp/isp-drv.c | 4 ++ drivers/media/platform/apple/isp/isp-drv.h | 4 ++ 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-cam-test.c b/drivers/media/platform/apple/isp/isp-cam-test.c index a98b38a16fd78..fdc367dc93c93 100644 --- a/drivers/media/platform/apple/isp/isp-cam-test.c +++ b/drivers/media/platform/apple/isp/isp-cam-test.c @@ -732,6 +732,55 @@ static void isp_test_sensor_names(struct kunit *test) KUNIT_EXPECT_STREQ(test, apple_isp_sensor_name(isp), "imx958-uw"); } +static void isp_test_module_tuning(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + static const char *const keep[] = { + "9999_99", /* no such setfile */ + "7523_01", /* another sensor's */ + "2224", /* not a whole name */ + }; + + /* No property: the sensor's default. */ + KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2224_01); + isp->module_tuning = "2226_02"; + KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2226_02); + isp->module_tuning = "2226_01"; + KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2226_01); + isp->module_tuning = "2224_01"; + KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2224_01); + for (unsigned int i = 0; i < ARRAY_SIZE(keep); i++) { + isp->module_tuning = keep[i]; + KUNIT_EXPECT_EQ_MSG(test, isp_module_tuning(isp, ISP_IMX958_2224_01), + ISP_IMX958_2224_01, "%s", keep[i]); + } +} + +/* + * A setfile missing from the system is replaced by its fallback after the + * size check against the data surface, so a fallback must be the same + * sensor, no larger, and final. + */ +static void isp_test_setfile_fallbacks(struct kunit *test) +{ + unsigned int n = 0; + + for (unsigned int i = 0; i < ARRAY_SIZE(isp_setfiles); i++) { + const struct isp_setfile *s = &isp_setfiles[i], *f = s->fallback; + + if (!f) + continue; + n++; + KUNIT_EXPECT_EQ_MSG(test, f->version, s->version, "setfile %u", i); + KUNIT_EXPECT_LE_MSG(test, f->size, s->size, "setfile %u", i); + KUNIT_EXPECT_NULL_MSG(test, f->fallback, "setfile %u", i); + KUNIT_EXPECT_STRNEQ_MSG(test, f->path, s->path, "setfile %u", i); + } + KUNIT_EXPECT_EQ(test, n, 2); + KUNIT_EXPECT_PTR_EQ(test, isp_setfiles[ISP_IMX958_2226_02].fallback, + &isp_setfiles[ISP_IMX958_2224_01]); +} + static void isp_test_snf_flatten(u8 *snf) { int k; @@ -1019,6 +1068,8 @@ static struct kunit_case isp_cam_test_cases[] = { KUNIT_CASE(isp_test_stop_key_on_debug), KUNIT_CASE(isp_test_sensor_geometry), KUNIT_CASE(isp_test_sensor_names), + KUNIT_CASE(isp_test_module_tuning), + KUNIT_CASE(isp_test_setfile_fallbacks), KUNIT_CASE(isp_test_sensor_config_list), KUNIT_CASE(isp_test_sensor_config_failure), KUNIT_CASE(isp_test_preview_stream), diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index 544a347c7c90a..3805714cf2bcd 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -41,6 +41,8 @@ struct isp_setfile { * noise filter gains. The setfile does not carry it. */ int snf_centre_dy; + /* used instead when this file is not installed (module tunings missing from vendorfw) */ + const struct isp_setfile *fallback; }; // clang-format off @@ -97,11 +99,44 @@ static const struct isp_setfile isp_setfiles[] = { [ISP_IMX913_7523_01] = {0x913, "imx913", 0x75230107, "apple/isp_7523_01XX.dat", 0x247f8}, [ISP_IMX958_2224_01] = {0x958, "imx958-uw", 0x22240106, "apple/isp_2224_01XX.dat", 0x6ff4, 0, ISP_TEMPORAL_FILTER_BAND0, -156}, + /* + * J815's own module tunings, H17-native (lens-shading records without + * the xx24 stride). The optical centre is 2224_01's: same sensor, not + * measured for this module. + */ + [ISP_IMX958_2226_01] = {0x958, "imx958-uw", 0x22260101, "apple/isp_2226_01XX.dat", 0x7040, + 0, ISP_TEMPORAL_FILTER_BAND0, -156, + &isp_setfiles[ISP_IMX958_2224_01]}, + [ISP_IMX958_2226_02] = {0x958, "imx958-uw", 0x22260201, "apple/isp_2226_02XX.dat", 0x7000, + 0, ISP_TEMPORAL_FILTER_BAND0, -156, + &isp_setfiles[ISP_IMX958_2224_01]}, [ISP_VD56G0_6221_01] = {0xd56, "vd56g0", 0x62210102, "apple/isp_6221_01XX.dat", 0x1b80}, [ISP_VD56G0_6222_01] = {0xd56, "vd56g0", 0x62220102, "apple/isp_6222_01XX.dat", 0x1b80}, }; // clang-format on +/* + * The board's camera module tuning, named in the DT (apple,module-tuning, + * e.g. "2226_02"), in place of the sensor's default setfile. Unknown names + * and other sensors' setfiles keep the default. + */ +static enum isp_sensor_id isp_module_tuning(struct apple_isp *isp, enum isp_sensor_id def) +{ + char path[48]; + unsigned int i; + + if (!isp->module_tuning) + return def; + snprintf(path, sizeof(path), "apple/isp_%sXX.dat", isp->module_tuning); + for (i = 0; i < ARRAY_SIZE(isp_setfiles); i++) + if (isp_setfiles[i].path && isp_setfiles[i].version == isp_setfiles[def].version && + !strcmp(isp_setfiles[i].path, path)) + return i; + dev_warn(isp->dev, "module tuning %s: no such setfile for sensor 0x%x, using %s\n", + isp->module_tuning, isp_setfiles[def].version, isp_setfiles[def].path); + return def; +} + static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); @@ -187,7 +222,7 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) break; case 0x958: /* Section 0x50f of 2224 names sensor 0x958; 2924's names 0x614. */ - id = ISP_IMX958_2224_01; + id = isp_module_tuning(isp, ISP_IMX958_2224_01); break; case 0xd56: id = ISP_VD56G0_6221_01; @@ -495,7 +530,8 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) if (err || (fmt->id != ISP_IMX248_1820_01 && fmt->id != ISP_IMX558_1921_01 && fmt->id != ISP_IMX558_1925_03 && fmt->id != ISP_IMX364_8720_01 && - fmt->id != ISP_IMX958_2224_01)) { + fmt->id != ISP_IMX958_2224_01 && fmt->id != ISP_IMX958_2226_01 && + fmt->id != ISP_IMX958_2226_02)) { dev_err(isp->dev, "ch %d: unsupported sensor. Please file a bug report with hardware info & dmesg trace.\n", ch); @@ -821,6 +857,13 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) return -ENOSPC; err = firmware_request_nowarn(&fw, setfile->path, isp->dev); + if (err == -ENOENT && setfile->fallback) { + dev_info_once(isp->dev, "setfile '%s' not installed, using '%s'\n", + setfile->path, setfile->fallback->path); + setfile = setfile->fallback; + len = setfile->file_size ?: setfile->size; + err = firmware_request_nowarn(&fw, setfile->path, isp->dev); + } if (err) { if (err == -ENOENT) dev_warn_once(isp->dev, diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index 758200422d68d..f5a89f085ecf6 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -876,6 +876,10 @@ static int apple_isp_probe(struct platform_device *pdev) if (err) isp->temporal_filter = 0; + /* the camera module's own tuning, where the board names one */ + of_property_read_string(dev->of_node, "apple,module-tuning", + &isp->module_tuning); + /* the sensor connection layout, for firmware that takes it at boot */ of_property_read_u32(dev->of_node, "apple,cam-connections-scheme", &isp->cam_connections_scheme); diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index 411041d8e82fc..9d881571e987a 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -334,6 +334,8 @@ enum isp_sensor_id { ISP_IMX853_7622_01, ISP_IMX913_7523_01, ISP_IMX958_2224_01, + ISP_IMX958_2226_01, /* the J815's macOS module tunings */ + ISP_IMX958_2226_02, ISP_VD56G0_6221_01, ISP_VD56G0_6222_01, }; @@ -369,6 +371,8 @@ struct apple_isp { enum isp_firmware_version fw_compat; u32 platform_id; u32 temporal_filter; + /* setfile name of the board's camera module (DT apple,module-tuning), or NULL */ + const char *module_tuning; u32 cam_connections_scheme; struct isp_preset *presets; int num_presets; From 988af2c78212f7e06eff3b13af72474952719a1c Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 19 Nov 2026 21:40:15 +0700 Subject: [PATCH 03/12] arm64: dts: apple: t8142-j815: Name the camera module's tuning The J815's IMX958 module runs 2226_02: with the sensor's default 2224_01 its corners read half the centre's brightness, with 2226_02 0.85 of it. Signed-off-by: Nick --- arch/arm64/boot/dts/apple/t8142-j815.dts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j815.dts b/arch/arm64/boot/dts/apple/t8142-j815.dts index 82e73d6dafc2b..7a8a7ead3692c 100644 --- a/arch/arm64/boot/dts/apple/t8142-j815.dts +++ b/arch/arm64/boot/dts/apple/t8142-j815.dts @@ -154,6 +154,11 @@ &isp { /* J815 ADT /arm-io/isp sensor-type */ apple,platform-id = <0x72>; + /* + * The J815's IMX958 module tuning: with the sensor's default 2224_01 the + * corners read half the centre's brightness, with 2226_02 0.85. + */ + apple,module-tuning = "2226_02"; }; &aop_audio { From 52da9a9dcabdbcdceddd2bedadd942e03e9cd573 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 07:24:33 +0700 Subject: [PATCH 04/12] media: apple: isp: macOS's stream-start commands, as test knobs Add the ISP commands macOS 27.2 sends at a J815 stream start (from a hypervisor IPC trace) and test parameters that send them, for an A/B on the J815: binned SIFR with highlight recovery (config 9), the AE and gain settings, and the camera status LED. A later commit in this series makes the useful ones fixed behaviour and drops the parameters. Signed-off-by: Nick --- drivers/media/platform/apple/isp/isp-cam.c | 134 ++++++++++++++++++++- drivers/media/platform/apple/isp/isp-cmd.c | 74 +++++++++++- drivers/media/platform/apple/isp/isp-cmd.h | 74 +++++++++++- drivers/media/platform/apple/isp/isp-drv.c | 40 ++++++ drivers/media/platform/apple/isp/isp-drv.h | 2 + 5 files changed, 317 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index 3805714cf2bcd..e4022a54658ce 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -115,6 +115,103 @@ static const struct isp_setfile isp_setfiles[] = { }; // clang-format on +/* + * TEST knobs (J815, WIP): what macOS 27.2 sends the same firmware, + * from the hypervisor IPC trace of 2026-11-20 (notes/camera-isp-run-2026-11-20.md + * in the J815 workspace). One knob per behaviour, read at each stream start. + * + * hr: in a SIFR sensor config (one that reports twice its frame height: the + * sensor sends a short exposure with every frame, sensor_config=6), macOS + * sets the SIFR skip interval to 1 and turns highlight recovery on. The + * firmware refuses HR in other configs, so nothing is sent there. + */ +static bool isp_hr = true; +module_param_named(hr, isp_hr, bool, 0644); +MODULE_PARM_DESC(hr, "TEST: highlight recovery in SIFR sensor configs, as macOS (default: true)"); + +/* + * led_brightness: the green camera LED's brightness. The firmware lights it + * whenever the sensor runs; macOS sets the brightness at each start (529 in a + * lit room, 204 with the lens covered) and ramps it with ambient light. 0 + * leaves the firmware's own level. Any other value is clamped to the range + * the firmware reports (CH_STATUS_LED_THR_GET, 204..1023 on the J815), so the + * privacy LED can never be set dark from here. + */ +static unsigned int isp_led_brightness; +module_param_named(led_brightness, isp_led_brightness, uint, 0644); +MODULE_PARM_DESC(led_brightness, "TEST: camera LED brightness, clamped to the firmware's range; 0 = firmware default"); + +/* + * macos_tune: auto-exposure and temporal-filter arguments as macOS sends + * them: AE stability 16 / to-stable 8 (the driver's own: 32 / 20), an AE + * gain cap of 96.0, and on band-0 setfiles TNR started with (1, 1, 0) and + * high strength on (the driver's own: (1, 0, 0), off). + */ +static bool isp_macos_tune = true; +module_param_named(macos_tune, isp_macos_tune, bool, 0644); +MODULE_PARM_DESC(macos_tune, "TEST: AE stability, AE gain cap and TNR strength as macOS (default: true)"); + +/* + * lpdp_macos: the sensor link receiver tuning as macOS sends it on the J815, + * a 0x18-byte command (2, 0x17, 0x10), instead of the driver's 0x14-byte + * (1, 15). Off by default: the link works as it is; this is for the A/B. + */ +static bool isp_lpdp_macos; +module_param_named(lpdp_macos, isp_lpdp_macos, bool, 0644); +MODULE_PARM_DESC(lpdp_macos, "TEST: LPDP receiver tuning as macOS, (2, 0x17, 0x10) (default: false)"); + +/* + * A SIFR config carries a second, short exposure in its frame: the IMX958 + * reports twice the frame height. Full resolution (config 6): input + * 3040x5760 for a 3040x2880 second size pair. Binned (config 9): input + * 1520x2880, half the width and the full height of the 3040x2880 pair. + */ +static bool isp_ch_config_is_sifr(struct apple_isp *isp, u32 ch, u32 index) +{ + struct cmd_ch_camera_config_h17 args; + struct cmd_ch_camera_config *config = &args.config; + + if (isp_cmd_ch_camera_config_get(isp, ch, index, &args)) + return false; + if (config->preset != index || !config->in_width2 || !config->in_height2) + return false; + return (config->in_width == config->in_width2 && + config->in_height == 2 * config->in_height2) || + (2 * config->in_width == config->in_width2 && + config->in_height == config->in_height2); +} + +static void isp_ch_configure_led(struct apple_isp *isp, u32 ch) +{ + u16 low, high, value; + int err; + + if (!isp_led_brightness) + return; + err = isp_cmd_ch_status_led_thr_get(isp, ch, &low, &high); + if (err || !low || high < low) { + dev_warn(isp->dev, "camera LED: no brightness range (%d, %u..%u): left as is\n", + err, low, high); + return; + } + value = clamp_t(unsigned int, isp_led_brightness, low, high); + err = isp_cmd_ch_status_led_mbrightness_set(isp, ch, value); + dev_info(isp->dev, "camera LED brightness %u (range %u..%u)%s\n", value, + low, high, err ? ": firmware refused" : ""); +} + +/* Best effort: without these the SIFR config still streams from its long exposure. */ +static void isp_ch_configure_sifr(struct apple_isp *isp, u32 ch, u32 index) +{ + int err, err_hr; + + err = isp_cmd_ch_sifr_skip_interval_set(isp, ch, 1); + err_hr = isp_cmd_ch_hr_enable(isp, ch, isp_hr); + dev_info(isp->dev, "sensor config %u is SIFR: skip interval 1%s, highlight recovery %s%s\n", + index, err ? " (refused)" : "", isp_hr ? "on" : "off", + err_hr ? " (refused)" : ""); +} + /* * The board's camera module tuning, named in the DT (apple,module-tuning, * e.g. "2226_02"), in place of the sensor's default setfile. Unknown names @@ -972,11 +1069,13 @@ static int isp_ch_configure_temporal_filter(struct apple_isp *isp, u32 ch) return isp_cmd_apple_ch_temporal_filter_stop(isp, ch); case ISP_TEMPORAL_FILTER_BAND0: - err = isp_cmd_apple_ch_tnr_start_h17(isp, ch); + err = isp_cmd_apple_ch_tnr_start_h17(isp, ch, isp_macos_tune); if (err) return err; - err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, 0); + /* macOS 27.2 sends 1 (macos_tune) */ + err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, + isp_macos_tune); if (err) return err; @@ -1039,6 +1138,7 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); bool h17 = isp->hw->fw_abi == ISP_FW_ABI_H17; + bool sifr; int err; err = isp_cmd_flicker_sensor_set(isp, 0); @@ -1059,7 +1159,11 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) return err; if (isp->hw->lpdp) { - err = isp_cmd_ch_lpdp_hs_receiver_tuning_set(isp, ch, 1, 15); + if (isp_lpdp_macos) + err = isp_cmd_ch_lpdp_hs_receiver_tuning_set3(isp, ch, 2, + 0x17, 0x10); + else + err = isp_cmd_ch_lpdp_hs_receiver_tuning_set(isp, ch, 1, 15); if (err) return err; } @@ -1073,10 +1177,22 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) if (err) return err; + /* + * Only presets the sensor_config knob moved are queried, before the + * select (as macOS queries), so the DT presets send what they always did. + */ + sifr = fmt->preset->remapped && !isp_is_p010(isp) && + isp_ch_config_is_sifr(isp, ch, fmt->preset->index); + err = isp_cmd_ch_camera_config_select(isp, ch, fmt->preset->index); if (err) return err; + if (!isp_is_p010(isp)) + isp_ch_configure_led(isp, ch); + if (sifr) + isp_ch_configure_sifr(isp, ch, fmt->preset->index); + err = isp_cmd_ch_buffer_recycle_mode_set( isp, ch, CISP_BUFFER_RECYCLE_MODE_EMPTY_ONLY); if (err) @@ -1148,14 +1264,22 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) if (err) return err; - err = isp_cmd_ch_ae_stability_set(isp, ch, 32); + err = isp_cmd_ch_ae_stability_set(isp, ch, isp_macos_tune ? 16 : 32); if (err) return err; - err = isp_cmd_ch_ae_stability_to_stable_set(isp, ch, 20); + err = isp_cmd_ch_ae_stability_to_stable_set(isp, ch, + isp_macos_tune ? 8 : 20); if (err) return err; + /* 96.0 in 8.8 fixed point, the gain cap macOS sets */ + if (isp_macos_tune && h17) { + err = isp_cmd_ch_ae_gain_cap_set(isp, ch, 96 << 8); + if (err) + return err; + } + err = isp_cmd_ch_sif_pixel_format_set(isp, ch); if (err) return err; diff --git a/drivers/media/platform/apple/isp/isp-cmd.c b/drivers/media/platform/apple/isp/isp-cmd.c index 7fb5203e71aea..62f39501965b9 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.c +++ b/drivers/media/platform/apple/isp/isp-cmd.c @@ -655,12 +655,13 @@ int isp_cmd_apple_ch_temporal_filter_disable(struct apple_isp *isp, u32 chan) return CISP_SEND_IN(isp, args); } -int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan) +int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan, u32 unk_10) { struct cmd_apple_ch_temporal_filter_start_h17 args = { .opcode = CISP_OPCODE(CISP_CMD_APPLE_CH_TEMPORAL_FILTER_START), .chan = chan, .unk_c = 1, + .unk_10 = unk_10, /* macOS 27.2 on the J815: 1 */ }; return CISP_SEND_IN(isp, args); } @@ -846,3 +847,74 @@ int isp_cmd_ch_property_read(struct apple_isp *isp, u32 chan, u32 prop, u32 *val return ret; } + +int isp_cmd_ch_ae_gain_cap_set(struct apple_isp *isp, u32 chan, u32 gain) +{ + struct cmd_ch_ae_gain_cap_set args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_AE_GAIN_CAP_SET), + .chan = chan, + .gain = gain, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_ch_status_led_mbrightness_set(struct apple_isp *isp, u32 chan, + u16 brightness) +{ + struct cmd_ch_status_led_mbrightness_set args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_STATUS_LED_MBRIGHTNESS_SET), + .chan = chan, + .brightness = brightness, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_ch_status_led_thr_get(struct apple_isp *isp, u32 chan, u16 *low, + u16 *high) +{ + struct cmd_ch_status_led_thr_get args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_STATUS_LED_THR_GET), + .chan = chan, + }; + int err = CISP_SEND_OUT(isp, &args); + + if (err) + return err; + *low = args.low; + *high = args.high; + return 0; +} + +int isp_cmd_ch_hr_enable(struct apple_isp *isp, u32 chan, u32 enable) +{ + struct cmd_ch_hr_enable args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_HR_ENABLE), + .chan = chan, + .enable = enable, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_ch_sifr_skip_interval_set(struct apple_isp *isp, u32 chan, + u32 interval) +{ + struct cmd_ch_sifr_skip_interval_set args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_SIFR_SKIP_INTERVAL_SET), + .chan = chan, + .interval = interval, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_ch_lpdp_hs_receiver_tuning_set3(struct apple_isp *isp, u32 chan, + u32 unk1, u32 unk2, u32 unk3) +{ + struct cmd_ch_lpdp_hs_receiver_tuning_set3 args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_LPDP_HS_RECEIVER_TUNING_SET), + .chan = chan, + .unk1 = unk1, + .unk2 = unk2, + .unk3 = unk3, + }; + return CISP_SEND_IN(isp, args); +} diff --git a/drivers/media/platform/apple/isp/isp-cmd.h b/drivers/media/platform/apple/isp/isp-cmd.h index ab98f3447d6f7..e10dc46dc7cf4 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.h +++ b/drivers/media/platform/apple/isp/isp-cmd.h @@ -55,10 +55,13 @@ #define CISP_CMD_CH_AE_FRAME_RATE_MIN_SET 0x020a #define CISP_CMD_CH_AE_STABILITY_SET 0x021a #define CISP_CMD_CH_AE_STABILITY_TO_STABLE_SET 0x0229 +#define CISP_CMD_CH_AE_GAIN_CAP_SET 0x020c #define CISP_CMD_CH_SENSOR_NVM_GET 0x0501 #define CISP_CMD_CH_SENSOR_PERMODULE_LSC_INFO_GET 0x0507 #define CISP_CMD_CH_SENSOR_PERMODULE_LSC_GRID_GET 0x0511 #define CISP_CMD_CH_LPDP_HS_RECEIVER_TUNING_SET 0x051b +#define CISP_CMD_CH_STATUS_LED_MBRIGHTNESS_SET 0x060f +#define CISP_CMD_CH_STATUS_LED_THR_GET 0x0632 #define CISP_CMD_CH_FOCUS_LIMITS_GET 0x0701 #define CISP_CMD_CH_CROP_GET 0x0800 #define CISP_CMD_CH_CROP_SET 0x0801 @@ -81,6 +84,8 @@ #define CISP_CMD_CH_FACE_DETECTION_CONFIG_SET 0x0d03 #define CISP_CMD_CH_FACE_DETECTION_DISABLE 0x0d04 #define CISP_CMD_CH_FACE_DETECTION_ENABLE 0x0d05 +#define CISP_CMD_CH_HR_ENABLE 0x1005 +#define CISP_CMD_CH_SIFR_SKIP_INTERVAL_SET 0x1008 #define CISP_CMD_CH_FID_START 0x3000 #define CISP_CMD_CH_FID_STOP 0x3001 #define CISP_CMD_IPC_ENDPOINT_SET2 0x300c @@ -726,7 +731,7 @@ int isp_cmd_apple_ch_motion_history_start(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_motion_history_stop(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_temporal_filter_enable(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_temporal_filter_disable(struct apple_isp *isp, u32 chan); -int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan); +int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan, u32 unk_10); int isp_cmd_apple_ch_tnr_high_strength_set(struct apple_isp *isp, u32 chan, u32 enable); int isp_cmd_apple_ch_tnr_band0_mod_set(struct apple_isp *isp, u32 chan, @@ -831,4 +836,71 @@ int isp_cmd_ch_semantic_video_enable(struct apple_isp *isp, u32 chan, u32 enable); int isp_cmd_ch_semantic_awb_enable(struct apple_isp *isp, u32 chan, u32 enable); +/* + * Commands macOS 27.2 sends on the J815 (IMX958), named as the firmware + * prints them in its log when it receives them; layouts from the payloads + * in the hypervisor trace of 2026-11-20. + */ +struct cmd_ch_ae_gain_cap_set { + u64 opcode; + u32 chan; + u32 gain; /* 8.8 fixed point; macOS: 96.0 */ +} __packed; +static_assert(sizeof(struct cmd_ch_ae_gain_cap_set) == 0x10); + +/* The firmware reads the value as a u16 at 0xc. */ +struct cmd_ch_status_led_mbrightness_set { + u64 opcode; + u32 chan; + u16 brightness; + u16 reserved; +} __packed; +static_assert(sizeof(struct cmd_ch_status_led_mbrightness_set) == 0x10); + +/* Reply: the range the brightness may take (J815: 204..1023). */ +struct cmd_ch_status_led_thr_get { + u64 opcode; + u32 chan; + u16 low; + u16 high; +} __packed; +static_assert(sizeof(struct cmd_ch_status_led_thr_get) == 0x10); + +/* Highlight recovery from the short exposure of a SIFR sensor config. */ +struct cmd_ch_hr_enable { + u64 opcode; + u32 chan; + u32 unk_c; /* 0 in every macOS call */ + u32 enable; +} __packed; +static_assert(sizeof(struct cmd_ch_hr_enable) == 0x14); + +/* The 0x18-byte form macOS 27.2 sends on the J815: (2, 0x17, 0x10). */ +struct cmd_ch_lpdp_hs_receiver_tuning_set3 { + u64 opcode; + u32 chan; + u32 unk1; + u32 unk2; + u32 unk3; +} __packed; +static_assert(sizeof(struct cmd_ch_lpdp_hs_receiver_tuning_set3) == 0x18); + +struct cmd_ch_sifr_skip_interval_set { + u64 opcode; + u32 chan; + u32 interval; /* macOS: 1 */ +} __packed; +static_assert(sizeof(struct cmd_ch_sifr_skip_interval_set) == 0x10); + +int isp_cmd_ch_ae_gain_cap_set(struct apple_isp *isp, u32 chan, u32 gain); +int isp_cmd_ch_status_led_mbrightness_set(struct apple_isp *isp, u32 chan, + u16 brightness); +int isp_cmd_ch_status_led_thr_get(struct apple_isp *isp, u32 chan, u16 *low, + u16 *high); +int isp_cmd_ch_hr_enable(struct apple_isp *isp, u32 chan, u32 enable); +int isp_cmd_ch_lpdp_hs_receiver_tuning_set3(struct apple_isp *isp, u32 chan, + u32 unk1, u32 unk2, u32 unk3); +int isp_cmd_ch_sifr_skip_interval_set(struct apple_isp *isp, u32 chan, + u32 interval); + #endif /* __ISP_CMD_H__ */ diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index f5a89f085ecf6..bbebf4494d982 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -627,6 +627,28 @@ static int isp_of_read_coord(struct device *dev, struct device_node *np, return 0; } +/* + * TEST knobs (J815, WIP). The J813/J815 DT presets run + * from the binned IMX958 mode, config 8 (1520x1440). These knobs move them to + * a full-resolution mode instead, with the crops doubled: + * sensor_config=7: 3040x2880 (as before #2237), + * sensor_config=6: 3040x2880 with SIFR, the mode macOS 27.2 streams (the + * firmware reports it as 3040x5760: a short exposure rides along with each + * frame, which highlight recovery uses; see the hr knob in isp-cam.c), + * sensor_config=9: the binned 1520x1440 frame with SIFR (reported as + * 1520x2880): binning's lower noise plus highlight recovery, crops as in 8, + * sensor_config=8 or 0: the DT presets unchanged. + * presets_full=1 is the old spelling of sensor_config=7 (the bench uses it). + * modprobe -r apple_isp; modprobe apple_isp sensor_config=N + */ +static bool presets_full; +module_param(presets_full, bool, 0444); +MODULE_PARM_DESC(presets_full, "TEST: same as sensor_config=7 (default: false)"); + +static int sensor_config = 6; +module_param(sensor_config, int, 0444); +MODULE_PARM_DESC(sensor_config, "TEST: IMX958 sensor mode for the binned DT presets: 6 = full res + SIFR (macOS, default), 7 = full res, 9 = binned + SIFR, 8/0 = binned (DT)"); + static int apple_isp_init_presets(struct apple_isp *isp) { struct device *dev = isp->dev; @@ -681,6 +703,24 @@ static int apple_isp_init_presets(struct apple_isp *isp) preset->crop_size.x = xywh[2]; preset->crop_size.y = xywh[3]; + if (!presets_full && sensor_config == 9 && preset->index == 8 && + preset->input_dim.x == 1520 && preset->input_dim.y == 1440) { + /* the same binned frame, with its SIFR exposure: crops unchanged */ + preset->index = 9; + preset->remapped = true; + } else if ((presets_full || sensor_config == 6 || sensor_config == 7) && + preset->index == 8 && + preset->input_dim.x == 1520 && preset->input_dim.y == 1440) { + preset->index = presets_full ? 7 : sensor_config; + preset->remapped = true; + preset->input_dim.x *= 2; + preset->input_dim.y *= 2; + preset->crop_offset.x *= 2; + preset->crop_offset.y *= 2; + preset->crop_size.x *= 2; + preset->crop_size.y *= 2; + } + preset++; } diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index 9d881571e987a..d1e7529e612ca 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -157,6 +157,8 @@ struct isp_preset { struct coord crop_size; /* Processed P010 geometry established by preview or a config reply. */ bool p010; + /* TEST: moved off its DT sensor config by the sensor_config knob */ + bool remapped; }; struct apple_isp_hw { From f67041100655862933f9eb8b7fa93a101e1f3ec5 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 08:16:11 +0700 Subject: [PATCH 05/12] media: apple: isp: crop the IMX958 presets inside the lens circle, binned SIFR default The J813/J815 ultra-wide lens draws an image circle smaller than the sensor; the DT crops take the full sensor width and show black corners (measured on a J815: the 16:9 crop goes dark at 0.855-0.96 of its half-diagonal). lens_circle (per mille of the input width, default 470) and lens_center_y scale a crop about its centre until its corners are inside the circle: 1920x1080 and 1280x720 crop 1242x700 of the binned 1520x1440 frame instead of 1520x856 (1.22x). sensor_config now defaults to 9 (binned + SIFR + highlight recovery): config 6 measured 2.4x the centre luma noise of the binned modes. Signed-off-by: Nick --- drivers/media/platform/apple/isp/isp-drv.c | 79 +++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index bbebf4494d982..03a78bef713cb 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -645,9 +645,83 @@ static bool presets_full; module_param(presets_full, bool, 0444); MODULE_PARM_DESC(presets_full, "TEST: same as sensor_config=7 (default: false)"); -static int sensor_config = 6; +/* + * Default 9: on the J815 A/B of 2026-11-21 (1920x1080, frame-to-frame noise) + * config 6 had 2.4x the centre luma noise of the binned modes without + * Apple's ANE denoiser (MLVNR), and 9 + HR matched 8 with highlight recovery. + */ +static int sensor_config = 9; module_param(sensor_config, int, 0444); -MODULE_PARM_DESC(sensor_config, "TEST: IMX958 sensor mode for the binned DT presets: 6 = full res + SIFR (macOS, default), 7 = full res, 9 = binned + SIFR, 8/0 = binned (DT)"); +MODULE_PARM_DESC(sensor_config, "TEST: IMX958 sensor mode for the binned DT presets: 9 = binned + SIFR (default), 6 = full res + SIFR (macOS), 7 = full res, 8/0 = binned (DT)"); + +/* + * The IMX958's ultra-wide lens draws an image circle smaller than the + * sensor: outside it the picture is black. macOS never shows that part (it + * frames a 1.5x zoom and dewarps); the DT crops take the full sensor width + * and so show black corners. On a J815 (config 8 frames, 2026-11-21) the + * 1520x856 16:9 crop went dark at 0.855 and 0.895 of its half-diagonal at + * the bottom corners and 0.96 at the top: the circle's centre sits about + * 5 % of the height above the sensor's, radius ~0.53 of the width. + * + * lens_circle: the usable radius in per mille of the input width, about the + * input centre moved down by lens_center_y per mille of the input height + * (negative = up). A crop whose corners leave the circle is scaled about + * its centre, aspect kept, until they fit. The default fits the worst + * (bottom-left) corner with a margin and no shift, so it holds for a lens + * centred differently. 0 = the DT crops. + */ +static unsigned int lens_circle = 470; +module_param(lens_circle, uint, 0444); +MODULE_PARM_DESC(lens_circle, "IMX958: usable lens circle radius, per mille of the input width (default 470; 0 = DT crops)"); + +static int lens_center_y; +module_param(lens_center_y, int, 0444); +MODULE_PARM_DESC(lens_center_y, "IMX958: lens circle centre below the input centre, per mille of the input height (default 0)"); + +static bool isp_crop_in_circle(s64 ox, s64 oy, u32 w, u32 h, s64 r) +{ + s64 dx = abs(ox) + w / 2, dy = abs(oy) + h / 2; + + return dx * dx + dy * dy <= r * r; +} + +static void isp_preset_fit_lens(struct device *dev, struct isp_preset *p) +{ + u32 in_w = p->input_dim.x, in_h = p->input_dim.y; + u32 w = p->crop_size.x, h = p->crop_size.y, lo = 0, hi = 1024, s, nw, nh; + s64 r, ccx, ccy, ox, oy; + + if (!lens_circle || p->index < 6 || p->index > 9 || + !((in_w == 1520 && in_h == 1440) || (in_w == 3040 && in_h == 2880))) + return; + r = (s64)lens_circle * in_w / 1000; + ccx = in_w / 2; + ccy = in_h / 2 + (s64)lens_center_y * in_h / 1000; + /* crop centre relative to the circle's, doubled to stay integer */ + ox = 2 * (s64)p->crop_offset.x + w - 2 * ccx; + oy = 2 * (s64)p->crop_offset.y + h - 2 * ccy; + if (isp_crop_in_circle(ox, oy, 2 * w, 2 * h, 2 * r)) + return; + /* largest scale s/1024 of the crop whose corners are inside */ + while (hi - lo > 1) { + s = (lo + hi) / 2; + if (isp_crop_in_circle(ox, oy, 2 * w * s / 1024, 2 * h * s / 1024, 2 * r)) + lo = s; + else + hi = s; + } + nw = round_down(w * lo / 1024, 2); + nh = round_down(h * lo / 1024, 2); + if (nw < 64 || nh < 64) + return; + dev_dbg(dev, "%ux%u preset: crop %ux%u+%u+%u -> %ux%u (lens circle)\n", + p->output_dim.x, p->output_dim.y, w, h, p->crop_offset.x, + p->crop_offset.y, nw, nh); + p->crop_offset.x = round_down(p->crop_offset.x + (w - nw) / 2, 2); + p->crop_offset.y = round_down(p->crop_offset.y + (h - nh) / 2, 2); + p->crop_size.x = nw; + p->crop_size.y = nh; +} static int apple_isp_init_presets(struct apple_isp *isp) { @@ -720,6 +794,7 @@ static int apple_isp_init_presets(struct apple_isp *isp) preset->crop_size.x *= 2; preset->crop_size.y *= 2; } + isp_preset_fit_lens(dev, preset); preset++; } From 81878d47939b03a4b001e4897d7f8b4696c4213f Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 08:33:58 +0700 Subject: [PATCH 06/12] media: apple: isp: binned config 8 by default, log the lens-circle crops Config 9 + HR measured 1.52 centre luma noise against 1.29 for config 8 on the J815 A/B; for a grain complaint keep the DT's binned mode and leave 9 as a knob. Log each crop the lens circle changes, so a run shows that it applied. Signed-off-by: Nick --- drivers/media/platform/apple/isp/isp-drv.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index 03a78bef713cb..f9ce225852685 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -646,13 +646,14 @@ module_param(presets_full, bool, 0444); MODULE_PARM_DESC(presets_full, "TEST: same as sensor_config=7 (default: false)"); /* - * Default 9: on the J815 A/B of 2026-11-21 (1920x1080, frame-to-frame noise) - * config 6 had 2.4x the centre luma noise of the binned modes without - * Apple's ANE denoiser (MLVNR), and 9 + HR matched 8 with highlight recovery. + * Default 8 (the DT): on the J815 A/B of 2026-11-21 (1920x1080, frame-to- + * frame centre luma noise) config 8 had 1.29, 9 + HR 1.52 (brighter, with + * highlight recovery) and 6/7 about 3.0: full resolution needs Apple's ANE + * denoiser (MLVNR), which Linux does not run yet. */ -static int sensor_config = 9; +static int sensor_config = 8; module_param(sensor_config, int, 0444); -MODULE_PARM_DESC(sensor_config, "TEST: IMX958 sensor mode for the binned DT presets: 9 = binned + SIFR (default), 6 = full res + SIFR (macOS), 7 = full res, 8/0 = binned (DT)"); +MODULE_PARM_DESC(sensor_config, "TEST: IMX958 sensor mode for the binned DT presets: 8/0 = binned (DT, default), 9 = binned + SIFR, 6 = full res + SIFR (macOS), 7 = full res"); /* * The IMX958's ultra-wide lens draws an image circle smaller than the @@ -714,9 +715,9 @@ static void isp_preset_fit_lens(struct device *dev, struct isp_preset *p) nh = round_down(h * lo / 1024, 2); if (nw < 64 || nh < 64) return; - dev_dbg(dev, "%ux%u preset: crop %ux%u+%u+%u -> %ux%u (lens circle)\n", - p->output_dim.x, p->output_dim.y, w, h, p->crop_offset.x, - p->crop_offset.y, nw, nh); + dev_info(dev, "%ux%u preset: crop %ux%u+%u+%u -> %ux%u (inside the lens circle)\n", + p->output_dim.x, p->output_dim.y, w, h, p->crop_offset.x, + p->crop_offset.y, nw, nh); p->crop_offset.x = round_down(p->crop_offset.x + (w - nw) / 2, 2); p->crop_offset.y = round_down(p->crop_offset.y + (h - nh) / 2, 2); p->crop_size.x = nw; From 69dc771e49a78d8289892fcc85135bb28d71870e Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 13:21:49 +0700 Subject: [PATCH 07/12] media: apple: isp: power the camera down after a firmware crash A crashed firmware is forced off: the stop command times out ("coproc not in WFI"), so the firmware never sends the camera module its power-down. The sensor stays powered, and its green status light stays on until the next camera use. Seen on J815 (2026-11-21) after an ISP firmware assert. On hardware whose firmware starts again (hw->fw_restart), a halt after an IPC error now schedules fw_recover_work. It boots the firmware once more and stops it the normal way, which powers the module down. It runs once: a second crash is left as it is. On J815 the light went off after the crash, and the log said "crashed firmware: restarted and stopped it to power the camera down". Signed-off-by: Nick --- drivers/media/platform/apple/isp/isp-drv.h | 6 ++++ drivers/media/platform/apple/isp/isp-fw.c | 41 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index d1e7529e612ca..157ed27dc3a91 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -445,6 +445,12 @@ struct apple_isp { /* firmware that starts again, idling until fw_idle_work stops it */ bool fw_idle; struct delayed_work fw_idle_work; + /* + * Firmware that crashed cannot power the camera module down (its + * status light stays on): it is started once more and stopped cleanly. + */ + struct delayed_work fw_recover_work; + bool fw_recovering; /* the camera was detected; until then a deferred start is pending */ bool camera_detected; /* configurations the firmware has, once a deferred start detected them */ diff --git a/drivers/media/platform/apple/isp/isp-fw.c b/drivers/media/platform/apple/isp/isp-fw.c index c9f65aeb10105..8bba35d530829 100644 --- a/drivers/media/platform/apple/isp/isp-fw.c +++ b/drivers/media/platform/apple/isp/isp-fw.c @@ -1424,14 +1424,46 @@ static void apple_isp_fw_idle_work(struct work_struct *work) mutex_unlock(&isp->video_lock); } +/* + * A crashed firmware was forced off (an ISP assert, 2026-11-21: the stop + * command timed out, "coproc not in WFI"), so it never sent the camera module + * its power-down: the sensor stayed powered and its green light on until the + * next camera use. Firmware that starts again (hw->fw_restart) is booted once + * more and stopped the normal way, which powers the module down. Only once: + * a second crash is left as it is. + */ +static void apple_isp_fw_recover_work(struct work_struct *work) +{ + struct apple_isp *isp = container_of(to_delayed_work(work), + struct apple_isp, fw_recover_work); + int err; + + mutex_lock(&isp->video_lock); + if (isp->fw_state == ISP_FW_OFF) { + isp->fw_recovering = true; + err = apple_isp_firmware_boot(isp); + if (!err) + apple_isp_firmware_halt(isp); + isp->fw_recovering = false; + if (err) + dev_warn(isp->dev, "crashed firmware: restart to power the camera down failed (%d); the camera light may stay on until the next camera start\n", + err); + else + dev_info(isp->dev, "crashed firmware: restarted and stopped it to power the camera down\n"); + } + mutex_unlock(&isp->video_lock); +} + void apple_isp_firmware_init(struct apple_isp *isp) { INIT_DELAYED_WORK(&isp->fw_idle_work, apple_isp_fw_idle_work); + INIT_DELAYED_WORK(&isp->fw_recover_work, apple_isp_fw_recover_work); } /* Stop idling firmware now, and wait for a stop that was due. */ void apple_isp_firmware_flush(struct apple_isp *isp) { + cancel_delayed_work_sync(&isp->fw_recover_work); if (!isp->hw->fw_idle_ms) return; @@ -1445,16 +1477,25 @@ void apple_isp_firmware_flush(struct apple_isp *isp) /* Stop the firmware; resident firmware without hw->fw_restart stays down. */ void apple_isp_firmware_halt(struct apple_isp *isp) { + bool crashed; + /* Only a capture services the watchdog, but be sure. */ apple_isp_wdt_stop(isp); if (isp->fw_state != ISP_FW_RUNNING) return; + /* Before the shutdown, which marks every stopped firmware as failed. */ + crashed = READ_ONCE(isp->ipc_error) && isp->hw->fw_restart && + !isp->fw_recovering; + isp_firmware_shutdown(isp); pm_runtime_put_sync(isp->dev); isp->ipc_stale = NULL; isp->fw_idle = false; isp->fw_state = isp->hw->resident_fw && !isp->hw->fw_restart ? ISP_FW_DEAD : ISP_FW_OFF; + if (crashed) + mod_delayed_work(system_dfl_wq, &isp->fw_recover_work, + msecs_to_jiffies(500)); } From b095664b43f5bc21390f57456b5cae8ae3bcb6f6 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 23 Nov 2026 00:35:59 +0700 Subject: [PATCH 08/12] tools/asahi: isp: stub the camera knobs and crash recovery The host tests compile driver functions against fake boundaries, so they stopped building with this series: - isp-preview-flow-tests: isp_ch_configure_capture() now reads the knobs that match macOS (isp_lpdp_macos, isp_macos_tune) and the remapped preset flag, and calls the SIFR and camera LED helpers. They get inert stubs; the order this test checks is unchanged. - isp-tests session: the firmware paths read the crash recovery work and flag. The fixtures have no fw_restart firmware, so recovery is never scheduled and the idle-work check stays as strict as before. Signed-off-by: Nick --- tools/asahi/isp-preview-flow-tests.py | 10 ++++++++-- tools/asahi/isp/session.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/asahi/isp-preview-flow-tests.py b/tools/asahi/isp-preview-flow-tests.py index 4e06b21f67d32..e9d8285565a9b 100644 --- a/tools/asahi/isp-preview-flow-tests.py +++ b/tools/asahi/isp-preview-flow-tests.py @@ -15,10 +15,10 @@ #include typedef unsigned int u32; struct coord {int x,y;}; -struct preset {int index;struct coord crop_offset,crop_size,output_dim;}; +struct preset {int index;bool remapped;struct coord crop_offset,crop_size,output_dim;}; struct isp_format {struct preset *preset;int strides[2];}; struct hw {int fw_abi;bool lpdp;}; -struct apple_isp {struct hw *hw;int temporal_filter;}; +struct apple_isp {void *dev;struct hw *hw;int temporal_filter;}; static struct preset preset; static struct isp_format fmt={.preset=&preset}; static struct isp_format *isp_get_format(struct apple_isp *i,u32 ch){return &fmt;} @@ -35,6 +35,12 @@ effect={'isp_cmd_apple_ch_temporal_filter_start':'temporal_start++;','isp_cmd_apple_ch_motion_history_start':'history++;','isp_cmd_apple_ch_temporal_filter_enable':'enable++;','isp_cmd_apple_ch_temporal_filter_disable':'disable++;if(fail_disable)return -EIO;','isp_ch_configure_pools':'pools++;'}.get(name,'') code+='static int '+name+'(struct apple_isp *i,...){'+effect+'return 0;}\n' code += 'static bool isp_is_p010(struct apple_isp *i){return false;}\n' +# Knobs and helpers outside the order checked here (macOS stream settings, SIFR, camera LED). +code += 'static bool isp_lpdp_macos, isp_macos_tune;\n' +code += 'static bool isp_ch_config_is_sifr(struct apple_isp *i,u32 ch,int index){return false;}\n' +code += 'static void isp_ch_configure_led(struct apple_isp *i,u32 ch){}\n' +code += 'static void isp_ch_configure_sifr(struct apple_isp *i,u32 ch,int index){}\n' +code += '#define dev_warn(dev, ...) ((void)(dev))\n' code += 'static int isp_ch_configure_temporal_filter(struct apple_isp *i,u32 ch){temporal_start++;history++;enable++;return 0;}\n' code+=body+r''' int main(void){ diff --git a/tools/asahi/isp/session.c b/tools/asahi/isp/session.c index ddf524257c135..1c2005438f1bc 100644 --- a/tools/asahi/isp/session.c +++ b/tools/asahi/isp/session.c @@ -69,6 +69,9 @@ struct apple_isp { bool ipc_quiescing; bool fw_idle; struct delayed_work fw_idle_work; + /* Restart after a firmware crash (only with fw_restart; never here). */ + struct delayed_work fw_recover_work; + bool fw_recovering; struct isp_channel *chan_io, *chan_sm, *chan_tm, *chan_bt; struct isp_channel *ipc_stale; bool ipc_failed; @@ -317,6 +320,7 @@ static unsigned int idle_schedules; static unsigned int msecs_to_jiffies(unsigned int ms) { return ms; } static bool mod_delayed_work(void *wq, struct delayed_work *work, unsigned int delay) { + /* The crash recovery is scheduled only for fw_restart firmware. */ CHECK(wq == system_dfl_wq && delay == 1000); CHECK(!irq_disabled && !synchronizing->ipc_quiescing); work->scheduled++; From c68edc73dfebb7a8df5dcc56fe751945a5bed287 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 23 Nov 2026 00:36:11 +0700 Subject: [PATCH 09/12] dt-bindings: media: apple,t8140-isp: Add the lens circle An optional property of the sensor-presets node, for what belongs to the camera module rather than to the driver: apple,lens-circle, the radius of the image circle the lens draws on the sensor, per mille of each preset's input width. The J813/J815 ultra-wide lens is black outside it, so the crops are kept inside. Signed-off-by: Nick --- .../devicetree/bindings/media/apple,t8140-isp.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml b/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml index 10e3c723fdb8c..f66d9145a2574 100644 --- a/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml +++ b/Documentation/devicetree/bindings/media/apple,t8140-isp.yaml @@ -109,6 +109,16 @@ properties: type: object description: Sensor firmware presets and the host output geometry associated with them. + properties: + apple,lens-circle: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 1000 + description: + Radius of the image circle the lens draws on the sensor, in per mille + of each preset's input width, about the input's centre. Outside it + the picture is black, so each crop is scaled about its centre, + aspect kept, until its corners are inside. patternProperties: "^preset[0-9]+$": type: object From f4366f78929bf50bdcc7a11ebde62e4771bd0808 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 23 Nov 2026 00:37:37 +0700 Subject: [PATCH 10/12] media: apple: isp: fixed macOS behaviour instead of the TEST knobs Ryan Murray's review: merged code picks its behaviour itself, and what belongs to the sensor or the lens goes in the camera's DT node. So the TEST module parameters go: - macos_tune, led_brightness: what macOS 27.2 sends the H17 firmware on the J815 is now fixed behaviour on H17: AE stability 16/8 and an AE gain cap of 96.0; TNR (1, 1, 0) with high strength on band-0 setfiles; and the camera LED at macOS's start brightness, 529. The LED value is still clamped to the range the firmware reports, so the privacy indicator can never be set dark. Other firmware keeps its old values. isp_test_temporal_filter_band0 now expects (1, 1, 0). - hr: highlight recovery needs a SIFR sensor mode, and the presets stay in the DT's binned mode, which is not one. HR, the SIFR skip interval and their two commands go until a full-resolution mode is used. - lpdp_macos: the 0x18-byte LPDP tuning made no measurable difference in the J815 A/B, so it goes with its command; the driver's (1, 15) stays. - sensor_config, presets_full: the presets keep the DT's binned mode (config 8): in the J815 A/B its noise was 1.29 against about 3.0 at full resolution. Configs 7 and 9 were bench modes only and go. - lens_circle, lens_center_y: the radius comes from apple,lens-circle. The centre shift was never used and goes. Signed-off-by: Nick --- .../media/platform/apple/isp/isp-cam-test.c | 4 +- drivers/media/platform/apple/isp/isp-cam.c | 118 +++--------------- drivers/media/platform/apple/isp/isp-cmd.c | 33 ----- drivers/media/platform/apple/isp/isp-cmd.h | 33 ----- drivers/media/platform/apple/isp/isp-drv.c | 91 +++----------- drivers/media/platform/apple/isp/isp-drv.h | 4 +- tools/asahi/isp-preview-flow-tests.py | 7 +- 7 files changed, 45 insertions(+), 245 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-cam-test.c b/drivers/media/platform/apple/isp/isp-cam-test.c index fdc367dc93c93..fd0ffa53b7320 100644 --- a/drivers/media/platform/apple/isp/isp-cam-test.c +++ b/drivers/media/platform/apple/isp/isp-cam-test.c @@ -312,10 +312,10 @@ static void isp_test_temporal_filter_band0(struct kunit *test) test->priv = trace; KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0); isp_test_expect_run(test, trace, run, ARRAY_SIZE(run)); - /* The start record is (1, 0, 0) whatever the DT property says. */ + /* The start record is (1, 1, 0) on band-0 setfiles, as macOS 27.2 sends it. */ i = isp_test_find(trace, 0xc100); KUNIT_EXPECT_EQ(test, trace->word[i][0], 1); - KUNIT_EXPECT_EQ(test, trace->word[i][1], 0); + KUNIT_EXPECT_EQ(test, trace->word[i][1], 1); KUNIT_EXPECT_EQ(test, trace->word[i][2], 0); i = isp_test_find(trace, 0xc11d); KUNIT_EXPECT_EQ(test, trace->word[i][0], 0x7800); diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index e4022a54658ce..c4dd123766f4d 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -116,77 +116,24 @@ static const struct isp_setfile isp_setfiles[] = { // clang-format on /* - * TEST knobs (J815, WIP): what macOS 27.2 sends the same firmware, - * from the hypervisor IPC trace of 2026-11-20 (notes/camera-isp-run-2026-11-20.md - * in the J815 workspace). One knob per behaviour, read at each stream start. - * - * hr: in a SIFR sensor config (one that reports twice its frame height: the - * sensor sends a short exposure with every frame, sensor_config=6), macOS - * sets the SIFR skip interval to 1 and turns highlight recovery on. The - * firmware refuses HR in other configs, so nothing is sent there. - */ -static bool isp_hr = true; -module_param_named(hr, isp_hr, bool, 0644); -MODULE_PARM_DESC(hr, "TEST: highlight recovery in SIFR sensor configs, as macOS (default: true)"); - -/* - * led_brightness: the green camera LED's brightness. The firmware lights it - * whenever the sensor runs; macOS sets the brightness at each start (529 in a - * lit room, 204 with the lens covered) and ramps it with ambient light. 0 - * leaves the firmware's own level. Any other value is clamped to the range - * the firmware reports (CH_STATUS_LED_THR_GET, 204..1023 on the J815), so the - * privacy LED can never be set dark from here. + * What macOS 27.2 sends the same H17 firmware on the J815, from a hypervisor + * IPC trace (2026-11-20): + * - the green camera LED's brightness, 529 at each start in a lit room. It is + * clamped to the range the firmware reports (CH_STATUS_LED_THR_GET, + * 204..1023 on the J815), so the privacy LED can never be set dark; + * - AE stability 16 / to-stable 8 (other firmware: 32 / 20) and an AE gain + * cap of 96.0; + * - on band-0 setfiles, TNR started with (1, 1, 0) and high strength on. + * macOS ramps the LED with ambient light; the driver keeps the start value. */ -static unsigned int isp_led_brightness; -module_param_named(led_brightness, isp_led_brightness, uint, 0644); -MODULE_PARM_DESC(led_brightness, "TEST: camera LED brightness, clamped to the firmware's range; 0 = firmware default"); - -/* - * macos_tune: auto-exposure and temporal-filter arguments as macOS sends - * them: AE stability 16 / to-stable 8 (the driver's own: 32 / 20), an AE - * gain cap of 96.0, and on band-0 setfiles TNR started with (1, 1, 0) and - * high strength on (the driver's own: (1, 0, 0), off). - */ -static bool isp_macos_tune = true; -module_param_named(macos_tune, isp_macos_tune, bool, 0644); -MODULE_PARM_DESC(macos_tune, "TEST: AE stability, AE gain cap and TNR strength as macOS (default: true)"); - -/* - * lpdp_macos: the sensor link receiver tuning as macOS sends it on the J815, - * a 0x18-byte command (2, 0x17, 0x10), instead of the driver's 0x14-byte - * (1, 15). Off by default: the link works as it is; this is for the A/B. - */ -static bool isp_lpdp_macos; -module_param_named(lpdp_macos, isp_lpdp_macos, bool, 0644); -MODULE_PARM_DESC(lpdp_macos, "TEST: LPDP receiver tuning as macOS, (2, 0x17, 0x10) (default: false)"); - -/* - * A SIFR config carries a second, short exposure in its frame: the IMX958 - * reports twice the frame height. Full resolution (config 6): input - * 3040x5760 for a 3040x2880 second size pair. Binned (config 9): input - * 1520x2880, half the width and the full height of the 3040x2880 pair. - */ -static bool isp_ch_config_is_sifr(struct apple_isp *isp, u32 ch, u32 index) -{ - struct cmd_ch_camera_config_h17 args; - struct cmd_ch_camera_config *config = &args.config; - - if (isp_cmd_ch_camera_config_get(isp, ch, index, &args)) - return false; - if (config->preset != index || !config->in_width2 || !config->in_height2) - return false; - return (config->in_width == config->in_width2 && - config->in_height == 2 * config->in_height2) || - (2 * config->in_width == config->in_width2 && - config->in_height == config->in_height2); -} +#define ISP_H17_LED_BRIGHTNESS 529 static void isp_ch_configure_led(struct apple_isp *isp, u32 ch) { u16 low, high, value; int err; - if (!isp_led_brightness) + if (isp->hw->fw_abi != ISP_FW_ABI_H17) return; err = isp_cmd_ch_status_led_thr_get(isp, ch, &low, &high); if (err || !low || high < low) { @@ -194,24 +141,12 @@ static void isp_ch_configure_led(struct apple_isp *isp, u32 ch) err, low, high); return; } - value = clamp_t(unsigned int, isp_led_brightness, low, high); + value = clamp_t(unsigned int, ISP_H17_LED_BRIGHTNESS, low, high); err = isp_cmd_ch_status_led_mbrightness_set(isp, ch, value); dev_info(isp->dev, "camera LED brightness %u (range %u..%u)%s\n", value, low, high, err ? ": firmware refused" : ""); } -/* Best effort: without these the SIFR config still streams from its long exposure. */ -static void isp_ch_configure_sifr(struct apple_isp *isp, u32 ch, u32 index) -{ - int err, err_hr; - - err = isp_cmd_ch_sifr_skip_interval_set(isp, ch, 1); - err_hr = isp_cmd_ch_hr_enable(isp, ch, isp_hr); - dev_info(isp->dev, "sensor config %u is SIFR: skip interval 1%s, highlight recovery %s%s\n", - index, err ? " (refused)" : "", isp_hr ? "on" : "off", - err_hr ? " (refused)" : ""); -} - /* * The board's camera module tuning, named in the DT (apple,module-tuning, * e.g. "2226_02"), in place of the sensor's default setfile. Unknown names @@ -1069,13 +1004,12 @@ static int isp_ch_configure_temporal_filter(struct apple_isp *isp, u32 ch) return isp_cmd_apple_ch_temporal_filter_stop(isp, ch); case ISP_TEMPORAL_FILTER_BAND0: - err = isp_cmd_apple_ch_tnr_start_h17(isp, ch, isp_macos_tune); + /* (1, 1, 0) and high strength, as macOS 27.2 */ + err = isp_cmd_apple_ch_tnr_start_h17(isp, ch, true); if (err) return err; - /* macOS 27.2 sends 1 (macos_tune) */ - err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, - isp_macos_tune); + err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, true); if (err) return err; @@ -1138,7 +1072,6 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); bool h17 = isp->hw->fw_abi == ISP_FW_ABI_H17; - bool sifr; int err; err = isp_cmd_flicker_sensor_set(isp, 0); @@ -1159,11 +1092,7 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) return err; if (isp->hw->lpdp) { - if (isp_lpdp_macos) - err = isp_cmd_ch_lpdp_hs_receiver_tuning_set3(isp, ch, 2, - 0x17, 0x10); - else - err = isp_cmd_ch_lpdp_hs_receiver_tuning_set(isp, ch, 1, 15); + err = isp_cmd_ch_lpdp_hs_receiver_tuning_set(isp, ch, 1, 15); if (err) return err; } @@ -1177,21 +1106,12 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) if (err) return err; - /* - * Only presets the sensor_config knob moved are queried, before the - * select (as macOS queries), so the DT presets send what they always did. - */ - sifr = fmt->preset->remapped && !isp_is_p010(isp) && - isp_ch_config_is_sifr(isp, ch, fmt->preset->index); - err = isp_cmd_ch_camera_config_select(isp, ch, fmt->preset->index); if (err) return err; if (!isp_is_p010(isp)) isp_ch_configure_led(isp, ch); - if (sifr) - isp_ch_configure_sifr(isp, ch, fmt->preset->index); err = isp_cmd_ch_buffer_recycle_mode_set( isp, ch, CISP_BUFFER_RECYCLE_MODE_EMPTY_ONLY); @@ -1264,17 +1184,17 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) if (err) return err; - err = isp_cmd_ch_ae_stability_set(isp, ch, isp_macos_tune ? 16 : 32); + err = isp_cmd_ch_ae_stability_set(isp, ch, h17 ? 16 : 32); if (err) return err; err = isp_cmd_ch_ae_stability_to_stable_set(isp, ch, - isp_macos_tune ? 8 : 20); + h17 ? 8 : 20); if (err) return err; /* 96.0 in 8.8 fixed point, the gain cap macOS sets */ - if (isp_macos_tune && h17) { + if (h17) { err = isp_cmd_ch_ae_gain_cap_set(isp, ch, 96 << 8); if (err) return err; diff --git a/drivers/media/platform/apple/isp/isp-cmd.c b/drivers/media/platform/apple/isp/isp-cmd.c index 62f39501965b9..1e1436057a8b3 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.c +++ b/drivers/media/platform/apple/isp/isp-cmd.c @@ -885,36 +885,3 @@ int isp_cmd_ch_status_led_thr_get(struct apple_isp *isp, u32 chan, u16 *low, return 0; } -int isp_cmd_ch_hr_enable(struct apple_isp *isp, u32 chan, u32 enable) -{ - struct cmd_ch_hr_enable args = { - .opcode = CISP_OPCODE(CISP_CMD_CH_HR_ENABLE), - .chan = chan, - .enable = enable, - }; - return CISP_SEND_IN(isp, args); -} - -int isp_cmd_ch_sifr_skip_interval_set(struct apple_isp *isp, u32 chan, - u32 interval) -{ - struct cmd_ch_sifr_skip_interval_set args = { - .opcode = CISP_OPCODE(CISP_CMD_CH_SIFR_SKIP_INTERVAL_SET), - .chan = chan, - .interval = interval, - }; - return CISP_SEND_IN(isp, args); -} - -int isp_cmd_ch_lpdp_hs_receiver_tuning_set3(struct apple_isp *isp, u32 chan, - u32 unk1, u32 unk2, u32 unk3) -{ - struct cmd_ch_lpdp_hs_receiver_tuning_set3 args = { - .opcode = CISP_OPCODE(CISP_CMD_CH_LPDP_HS_RECEIVER_TUNING_SET), - .chan = chan, - .unk1 = unk1, - .unk2 = unk2, - .unk3 = unk3, - }; - return CISP_SEND_IN(isp, args); -} diff --git a/drivers/media/platform/apple/isp/isp-cmd.h b/drivers/media/platform/apple/isp/isp-cmd.h index e10dc46dc7cf4..414725b04df91 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.h +++ b/drivers/media/platform/apple/isp/isp-cmd.h @@ -84,8 +84,6 @@ #define CISP_CMD_CH_FACE_DETECTION_CONFIG_SET 0x0d03 #define CISP_CMD_CH_FACE_DETECTION_DISABLE 0x0d04 #define CISP_CMD_CH_FACE_DETECTION_ENABLE 0x0d05 -#define CISP_CMD_CH_HR_ENABLE 0x1005 -#define CISP_CMD_CH_SIFR_SKIP_INTERVAL_SET 0x1008 #define CISP_CMD_CH_FID_START 0x3000 #define CISP_CMD_CH_FID_STOP 0x3001 #define CISP_CMD_IPC_ENDPOINT_SET2 0x300c @@ -866,41 +864,10 @@ struct cmd_ch_status_led_thr_get { } __packed; static_assert(sizeof(struct cmd_ch_status_led_thr_get) == 0x10); -/* Highlight recovery from the short exposure of a SIFR sensor config. */ -struct cmd_ch_hr_enable { - u64 opcode; - u32 chan; - u32 unk_c; /* 0 in every macOS call */ - u32 enable; -} __packed; -static_assert(sizeof(struct cmd_ch_hr_enable) == 0x14); - -/* The 0x18-byte form macOS 27.2 sends on the J815: (2, 0x17, 0x10). */ -struct cmd_ch_lpdp_hs_receiver_tuning_set3 { - u64 opcode; - u32 chan; - u32 unk1; - u32 unk2; - u32 unk3; -} __packed; -static_assert(sizeof(struct cmd_ch_lpdp_hs_receiver_tuning_set3) == 0x18); - -struct cmd_ch_sifr_skip_interval_set { - u64 opcode; - u32 chan; - u32 interval; /* macOS: 1 */ -} __packed; -static_assert(sizeof(struct cmd_ch_sifr_skip_interval_set) == 0x10); - int isp_cmd_ch_ae_gain_cap_set(struct apple_isp *isp, u32 chan, u32 gain); int isp_cmd_ch_status_led_mbrightness_set(struct apple_isp *isp, u32 chan, u16 brightness); int isp_cmd_ch_status_led_thr_get(struct apple_isp *isp, u32 chan, u16 *low, u16 *high); -int isp_cmd_ch_hr_enable(struct apple_isp *isp, u32 chan, u32 enable); -int isp_cmd_ch_lpdp_hs_receiver_tuning_set3(struct apple_isp *isp, u32 chan, - u32 unk1, u32 unk2, u32 unk3); -int isp_cmd_ch_sifr_skip_interval_set(struct apple_isp *isp, u32 chan, - u32 interval); #endif /* __ISP_CMD_H__ */ diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index f9ce225852685..cc20c6160874b 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -628,57 +628,20 @@ static int isp_of_read_coord(struct device *dev, struct device_node *np, } /* - * TEST knobs (J815, WIP). The J813/J815 DT presets run - * from the binned IMX958 mode, config 8 (1520x1440). These knobs move them to - * a full-resolution mode instead, with the crops doubled: - * sensor_config=7: 3040x2880 (as before #2237), - * sensor_config=6: 3040x2880 with SIFR, the mode macOS 27.2 streams (the - * firmware reports it as 3040x5760: a short exposure rides along with each - * frame, which highlight recovery uses; see the hr knob in isp-cam.c), - * sensor_config=9: the binned 1520x1440 frame with SIFR (reported as - * 1520x2880): binning's lower noise plus highlight recovery, crops as in 8, - * sensor_config=8 or 0: the DT presets unchanged. - * presets_full=1 is the old spelling of sensor_config=7 (the bench uses it). - * modprobe -r apple_isp; modprobe apple_isp sensor_config=N - */ -static bool presets_full; -module_param(presets_full, bool, 0444); -MODULE_PARM_DESC(presets_full, "TEST: same as sensor_config=7 (default: false)"); - -/* - * Default 8 (the DT): on the J815 A/B of 2026-11-21 (1920x1080, frame-to- - * frame centre luma noise) config 8 had 1.29, 9 + HR 1.52 (brighter, with - * highlight recovery) and 6/7 about 3.0: full resolution needs Apple's ANE - * denoiser (MLVNR), which Linux does not run yet. - */ -static int sensor_config = 8; -module_param(sensor_config, int, 0444); -MODULE_PARM_DESC(sensor_config, "TEST: IMX958 sensor mode for the binned DT presets: 8/0 = binned (DT, default), 9 = binned + SIFR, 6 = full res + SIFR (macOS), 7 = full res"); - -/* - * The IMX958's ultra-wide lens draws an image circle smaller than the - * sensor: outside it the picture is black. macOS never shows that part (it - * frames a 1.5x zoom and dewarps); the DT crops take the full sensor width - * and so show black corners. On a J815 (config 8 frames, 2026-11-21) the - * 1520x856 16:9 crop went dark at 0.855 and 0.895 of its half-diagonal at - * the bottom corners and 0.96 at the top: the circle's centre sits about - * 5 % of the height above the sensor's, radius ~0.53 of the width. + * A camera property of the sensor-presets node (DT), optional. The presets + * keep the DT's binned mode: on the J815 its noise was 1.29 against about + * 3.0 for full resolution (2026-11-21). * - * lens_circle: the usable radius in per mille of the input width, about the - * input centre moved down by lens_center_y per mille of the input height - * (negative = up). A crop whose corners leave the circle is scaled about - * its centre, aspect kept, until they fit. The default fits the worst - * (bottom-left) corner with a margin and no shift, so it holds for a lens - * centred differently. 0 = the DT crops. + * apple,lens-circle = : the lens draws an image circle smaller than + * the sensor, black outside. macOS never shows that part (it frames a 1.5x + * zoom and dewarps); crops that take the full sensor width show black + * corners. On a J815 (config 8 frames, 2026-11-21) the 1520x856 16:9 crop + * went dark at 0.855 and 0.895 of its half-diagonal at the bottom corners and + * 0.96 at the top: the circle's centre sits about 5 % of the height above + * the sensor's, radius ~0.53 of the width. The radius is per mille of the + * input width, about the input's centre. A crop whose corners leave the + * circle is scaled about its centre, aspect kept, until they fit. */ -static unsigned int lens_circle = 470; -module_param(lens_circle, uint, 0444); -MODULE_PARM_DESC(lens_circle, "IMX958: usable lens circle radius, per mille of the input width (default 470; 0 = DT crops)"); - -static int lens_center_y; -module_param(lens_center_y, int, 0444); -MODULE_PARM_DESC(lens_center_y, "IMX958: lens circle centre below the input centre, per mille of the input height (default 0)"); - static bool isp_crop_in_circle(s64 ox, s64 oy, u32 w, u32 h, s64 r) { s64 dx = abs(ox) + w / 2, dy = abs(oy) + h / 2; @@ -686,18 +649,17 @@ static bool isp_crop_in_circle(s64 ox, s64 oy, u32 w, u32 h, s64 r) return dx * dx + dy * dy <= r * r; } -static void isp_preset_fit_lens(struct device *dev, struct isp_preset *p) +static void isp_preset_fit_lens(struct device *dev, struct isp_preset *p, u32 lens_circle) { u32 in_w = p->input_dim.x, in_h = p->input_dim.y; u32 w = p->crop_size.x, h = p->crop_size.y, lo = 0, hi = 1024, s, nw, nh; s64 r, ccx, ccy, ox, oy; - if (!lens_circle || p->index < 6 || p->index > 9 || - !((in_w == 1520 && in_h == 1440) || (in_w == 3040 && in_h == 2880))) + if (!lens_circle) return; r = (s64)lens_circle * in_w / 1000; ccx = in_w / 2; - ccy = in_h / 2 + (s64)lens_center_y * in_h / 1000; + ccy = in_h / 2; /* crop centre relative to the circle's, doubled to stay integer */ ox = 2 * (s64)p->crop_offset.x + w - 2 * ccx; oy = 2 * (s64)p->crop_offset.y + h - 2 * ccy; @@ -728,6 +690,7 @@ static int apple_isp_init_presets(struct apple_isp *isp) { struct device *dev = isp->dev; struct isp_preset *preset; + u32 lens_circle; int err = 0; struct device_node *np __free(device_node) = @@ -748,6 +711,9 @@ static int apple_isp_init_presets(struct apple_isp *isp) if (!isp->presets) return -ENOMEM; + if (of_property_read_u32(np, "apple,lens-circle", &lens_circle)) + lens_circle = 0; + preset = isp->presets; for_each_child_of_node_scoped(np, child) { u32 xywh[4]; @@ -778,24 +744,7 @@ static int apple_isp_init_presets(struct apple_isp *isp) preset->crop_size.x = xywh[2]; preset->crop_size.y = xywh[3]; - if (!presets_full && sensor_config == 9 && preset->index == 8 && - preset->input_dim.x == 1520 && preset->input_dim.y == 1440) { - /* the same binned frame, with its SIFR exposure: crops unchanged */ - preset->index = 9; - preset->remapped = true; - } else if ((presets_full || sensor_config == 6 || sensor_config == 7) && - preset->index == 8 && - preset->input_dim.x == 1520 && preset->input_dim.y == 1440) { - preset->index = presets_full ? 7 : sensor_config; - preset->remapped = true; - preset->input_dim.x *= 2; - preset->input_dim.y *= 2; - preset->crop_offset.x *= 2; - preset->crop_offset.y *= 2; - preset->crop_size.x *= 2; - preset->crop_size.y *= 2; - } - isp_preset_fit_lens(dev, preset); + isp_preset_fit_lens(dev, preset, lens_circle); preset++; } diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index 157ed27dc3a91..d56c9b1b6eb4c 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -157,8 +157,6 @@ struct isp_preset { struct coord crop_size; /* Processed P010 geometry established by preview or a config reply. */ bool p010; - /* TEST: moved off its DT sensor config by the sensor_config knob */ - bool remapped; }; struct apple_isp_hw { @@ -361,6 +359,8 @@ struct isp_format { size_t total_size; }; +struct dentry; + struct apple_isp { struct device *dev; const struct apple_isp_hw *hw; diff --git a/tools/asahi/isp-preview-flow-tests.py b/tools/asahi/isp-preview-flow-tests.py index e9d8285565a9b..1ea0bc2d93d82 100644 --- a/tools/asahi/isp-preview-flow-tests.py +++ b/tools/asahi/isp-preview-flow-tests.py @@ -15,7 +15,7 @@ #include typedef unsigned int u32; struct coord {int x,y;}; -struct preset {int index;bool remapped;struct coord crop_offset,crop_size,output_dim;}; +struct preset {int index;struct coord crop_offset,crop_size,output_dim;}; struct isp_format {struct preset *preset;int strides[2];}; struct hw {int fw_abi;bool lpdp;}; struct apple_isp {void *dev;struct hw *hw;int temporal_filter;}; @@ -35,11 +35,8 @@ effect={'isp_cmd_apple_ch_temporal_filter_start':'temporal_start++;','isp_cmd_apple_ch_motion_history_start':'history++;','isp_cmd_apple_ch_temporal_filter_enable':'enable++;','isp_cmd_apple_ch_temporal_filter_disable':'disable++;if(fail_disable)return -EIO;','isp_ch_configure_pools':'pools++;'}.get(name,'') code+='static int '+name+'(struct apple_isp *i,...){'+effect+'return 0;}\n' code += 'static bool isp_is_p010(struct apple_isp *i){return false;}\n' -# Knobs and helpers outside the order checked here (macOS stream settings, SIFR, camera LED). -code += 'static bool isp_lpdp_macos, isp_macos_tune;\n' -code += 'static bool isp_ch_config_is_sifr(struct apple_isp *i,u32 ch,int index){return false;}\n' +# Knobs and helpers outside the order checked here (macOS stream settings, camera LED). code += 'static void isp_ch_configure_led(struct apple_isp *i,u32 ch){}\n' -code += 'static void isp_ch_configure_sifr(struct apple_isp *i,u32 ch,int index){}\n' code += '#define dev_warn(dev, ...) ((void)(dev))\n' code += 'static int isp_ch_configure_temporal_filter(struct apple_isp *i,u32 ch){temporal_start++;history++;enable++;return 0;}\n' code+=body+r''' From 1e18af37d3b405384b5251f0a8de11d71bf9fbc4 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 23 Nov 2026 00:37:51 +0700 Subject: [PATCH 11/12] arm64: dts: apple: t8142-j813/j815: Add the camera's lens circle The ultra-wide IMX958 module's lens draws an image circle of radius 0.47 of the sensor width (measured on a J815; the J813 is assumed to have the same lens). Signed-off-by: Nick --- arch/arm64/boot/dts/apple/t8142-j813-isp.dtsi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813-isp.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-isp.dtsi index 44d4d1eabeef5..f573edc9c2147 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-isp.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-isp.dtsi @@ -228,6 +228,12 @@ * crops the driver derived in config 7, halved. */ sensor-presets { + /* + * Measured on a J815 (2026-11-21); the J813 is assumed to have the + * same ultra-wide lens. + */ + apple,lens-circle = <470>; + /* 1280x720 */ preset0 { apple,config-index = <8>; From 8424337131c0c68905ff5d934eca7b765da5597d Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 18:19:16 +0700 Subject: [PATCH 12/12] media: apple: isp: set the camera LED brightness only on T8142 macOS's start brightness (529) was traced on the J815 only. Other H17 firmware keeps its own default until it is measured there: a per-SoC hw->led_brightness, set for T8142, replaces the H17-wide check. Signed-off-by: Nick --- drivers/media/platform/apple/isp/isp-cam.c | 12 ++++++------ drivers/media/platform/apple/isp/isp-drv.c | 1 + drivers/media/platform/apple/isp/isp-drv.h | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index c4dd123766f4d..a6ea3dec8d3b8 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -118,22 +118,22 @@ static const struct isp_setfile isp_setfiles[] = { /* * What macOS 27.2 sends the same H17 firmware on the J815, from a hypervisor * IPC trace (2026-11-20): - * - the green camera LED's brightness, 529 at each start in a lit room. It is - * clamped to the range the firmware reports (CH_STATUS_LED_THR_GET, - * 204..1023 on the J815), so the privacy LED can never be set dark; + * - the green camera LED's brightness, 529 at each start in a lit room (only + * on T8142, where it was traced: hw->led_brightness). It is clamped to the + * range the firmware reports (CH_STATUS_LED_THR_GET, 204..1023 on the + * J815), so the privacy LED can never be set dark; * - AE stability 16 / to-stable 8 (other firmware: 32 / 20) and an AE gain * cap of 96.0; * - on band-0 setfiles, TNR started with (1, 1, 0) and high strength on. * macOS ramps the LED with ambient light; the driver keeps the start value. */ -#define ISP_H17_LED_BRIGHTNESS 529 static void isp_ch_configure_led(struct apple_isp *isp, u32 ch) { u16 low, high, value; int err; - if (isp->hw->fw_abi != ISP_FW_ABI_H17) + if (!isp->hw->led_brightness) return; err = isp_cmd_ch_status_led_thr_get(isp, ch, &low, &high); if (err || !low || high < low) { @@ -141,7 +141,7 @@ static void isp_ch_configure_led(struct apple_isp *isp, u32 ch) err, low, high); return; } - value = clamp_t(unsigned int, ISP_H17_LED_BRIGHTNESS, low, high); + value = clamp_t(unsigned int, isp->hw->led_brightness, low, high); err = isp_cmd_ch_status_led_mbrightness_set(isp, ch, value); dev_info(isp->dev, "camera LED brightness %u (range %u..%u)%s\n", value, low, high, err ? ": firmware refused" : ""); diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index cc20c6160874b..0d98b44c574f6 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -1599,6 +1599,7 @@ static const struct apple_isp_hw apple_isp_hw_t8142 = { .coproc_quiesce = ISP_COPROC_QUIESCE_T8140, .fw_mmio = apple_isp_fw_mmio_t8142, .num_fw_mmio = ARRAY_SIZE(apple_isp_fw_mmio_t8142), + .led_brightness = 529, .boot_mode = 1, .capture_meta_size = ISP_CAPTURE_META_SIZE_T8140, .resident_fw = true, diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index d56c9b1b6eb4c..652412132a240 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -161,6 +161,8 @@ struct isp_preset { struct apple_isp_hw { enum isp_generation gen; + /* camera LED brightness at each start (macOS's value), 0 = firmware default */ + u16 led_brightness; enum isp_fw_abi fw_abi; u64 pmu_base;