From ea4d298798263dcfc4e2c64ac270fdc0dc5bd613 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 19:29:19 +1100 Subject: [PATCH] media: apple: isp: select sensor setfiles by platform ID Select platform-specific ISP sensor tuning setfiles using the platform ID from the device tree rather than defaulting every board to the earliest setfile variant for a sensor: - IMX558 (legacy ABI): select isp_1922_02XX.dat on platforms 0x0e, 0x0f, and 0x12 (with temporal filter off), keeping isp_1921_01XX.dat on older platforms and isp_1925_03XX.dat on H17. - IMX958: add isp_2226_01XX.dat (platforms 0xb9..0xbc) and isp_2226_02XX.dat (platforms 0x78, 0x85, 0x86), keeping isp_2224_01XX.dat for earlier platforms. - IMX364: select isp_8723_01XX.dat on platform 0x0a. - IMX248: select isp_1822_02XX.dat on platform 0x06. If a platform-specific setfile is absent from an older firmware extraction on disk (-ENOENT), fall back once to the base sensor setfile so existing installations keep streaming. Add a KUnit test covering platform-ID setfile selection across legacy and H17 firmware ABIs. --- .../media/platform/apple/isp/isp-cam-test.c | 42 +++++++++++ drivers/media/platform/apple/isp/isp-cam.c | 75 +++++++++++++++---- drivers/media/platform/apple/isp/isp-drv.h | 2 + 3 files changed, 105 insertions(+), 14 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..3f7af5fb11c12 100644 --- a/drivers/media/platform/apple/isp/isp-cam-test.c +++ b/drivers/media/platform/apple/isp/isp-cam-test.c @@ -1008,6 +1008,47 @@ static void isp_test_failed_fw_stop_lights_off(struct kunit *test) KUNIT_EXPECT_EQ(test, trace.set_off_at, 1); } +static void isp_test_setfile_platform_select(struct kunit *test) +{ + static const struct apple_isp_hw hw_legacy = { + .fw_abi = ISP_FW_ABI_LEGACY, + }; + static const struct apple_isp_hw hw_h17 = { + .fw_abi = ISP_FW_ABI_H17, + }; + static const struct { + const struct apple_isp_hw *hw; + u32 version; + u32 platform; + enum isp_sensor_id expected; + } cases[] = { + { &hw_legacy, 0x558, 0x0e, ISP_IMX558_1922_02 }, + { &hw_legacy, 0x558, 0x0f, ISP_IMX558_1922_02 }, + { &hw_legacy, 0x558, 0x12, ISP_IMX558_1922_02 }, + { &hw_legacy, 0x558, 0x03, ISP_IMX558_1921_01 }, + { &hw_h17, 0x558, 0x70, ISP_IMX558_1925_03 }, + { &hw_h17, 0x558, 0x00, ISP_IMX558_1925_03 }, + { &hw_h17, 0x958, 0x05, ISP_IMX958_2224_01 }, + { &hw_h17, 0x958, 0x17, ISP_IMX958_2224_01 }, + { &hw_h17, 0x958, 0xba, ISP_IMX958_2226_01 }, + { &hw_h17, 0x958, 0x78, ISP_IMX958_2226_02 }, + { &hw_legacy, 0x364, 0x0a, ISP_IMX364_8723_01 }, + { &hw_legacy, 0x364, 0x03, ISP_IMX364_8720_01 }, + { &hw_legacy, 0x248, 0x06, ISP_IMX248_1822_02 }, + { &hw_legacy, 0x248, 0x01, ISP_IMX248_1820_01 }, + }; + struct apple_isp *isp = isp_test_capture_alloc(test); + + for (unsigned int i = 0; i < ARRAY_SIZE(cases); i++) { + isp->hw = cases[i].hw; + isp->platform_id = cases[i].platform; + isp_get_format(isp, 0)->version = cases[i].version; + KUNIT_EXPECT_EQ(test, isp_ch_get_sensor_id(isp, 0), 0); + KUNIT_EXPECT_EQ(test, isp_get_format(isp, 0)->id, + cases[i].expected); + } +} + static struct kunit_case isp_cam_test_cases[] = { KUNIT_CASE(isp_test_call_crop), KUNIT_CASE(isp_test_call_crop_bounds), @@ -1027,6 +1068,7 @@ static struct kunit_case isp_cam_test_cases[] = { KUNIT_CASE(isp_test_temporal_filter_off), KUNIT_CASE(isp_test_power_line_frequency), KUNIT_CASE(isp_test_snf_radial), + KUNIT_CASE(isp_test_setfile_platform_select), KUNIT_CASE(isp_test_indicator_set_fails_still_streams), KUNIT_CASE(isp_test_dcp_bound_at_stream_start), KUNIT_CASE(isp_test_no_indicator_still_streams), diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index 544a347c7c90a..2ca6085bcce21 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -70,7 +70,8 @@ static const struct isp_setfile isp_setfiles[] = { [ISP_IMX514_2820_04] = {0x514, "imx514", 0x28200405, "apple/isp_2820_04XX.dat", 0xa198}, [ISP_IMX558_1921_01] = {0x558, "imx558", 0x19210106, "apple/isp_1921_01XX.dat", 0xad40, 0, ISP_TEMPORAL_FILTER_OFF}, - [ISP_IMX558_1922_02] = {0x558, "imx558", 0x19220201, "apple/isp_1922_02XX.dat", 0xad40}, + [ISP_IMX558_1922_02] = {0x558, "imx558", 0x19220201, "apple/isp_1922_02XX.dat", 0xad40, + 0, ISP_TEMPORAL_FILTER_OFF}, [ISP_IMX558_1925_03] = {0x558, "imx558", 0x19250306, "apple/isp_1925_03XX.dat", 0xcbc0, 0xcba6, ISP_TEMPORAL_FILTER_OFF}, [ISP_IMX603_7920_01] = {0x603, "imx603", 0x79200109, "apple/isp_7920_01XX.dat", 0xad2c}, @@ -97,23 +98,46 @@ 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}, + [ISP_IMX958_2226_01] = {0x958, "imx958-uw", 0x22260101, "apple/isp_2226_01XX.dat", 0x7024, + 0, ISP_TEMPORAL_FILTER_BAND0, -156}, + [ISP_IMX958_2226_02] = {0x958, "imx958-uw", 0x22260201, "apple/isp_2226_02XX.dat", 0x6ff4, + 0, ISP_TEMPORAL_FILTER_BAND0, -156}, [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 +/* + * Base setfile to try when a platform-specific variant is absent from an + * older firmware extraction on disk. + */ +static enum isp_sensor_id isp_setfile_fallback(enum isp_sensor_id id) +{ + switch (id) { + case ISP_IMX248_1822_02: + return ISP_IMX248_1820_01; + case ISP_IMX364_8723_01: + return ISP_IMX364_8720_01; + case ISP_IMX558_1922_02: + return ISP_IMX558_1921_01; + case ISP_IMX958_2226_01: + case ISP_IMX958_2226_02: + return ISP_IMX958_2224_01; + default: + return id; + } +} + static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); + u32 platform = isp->platform_id; enum isp_sensor_id id; int err = 0; - /* TODO need more datapoints to figure out the sub-versions - * Defaulting to 1st release for now, the calib files aren't too different. - */ switch (fmt->version) { case 0x248: - id = ISP_IMX248_1820_01; + id = platform == 0x06 ? ISP_IMX248_1822_02 : ISP_IMX248_1820_01; break; case 0x343: id = ISP_IMX343_5221_02; @@ -125,7 +149,7 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) id = ISP_IMX356_4820_01; break; case 0x364: - id = ISP_IMX364_8720_01; + id = platform == 0x0a ? ISP_IMX364_8723_01 : ISP_IMX364_8720_01; break; case 0x372: id = ISP_IMX372_3820_01; @@ -149,6 +173,9 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) /* The H17 firmware only parses header version 0x21 setfiles. */ if (isp->hw->fw_abi == ISP_FW_ABI_H17) id = ISP_IMX558_1925_03; + else if (platform == 0x0e || platform == 0x0f || + platform == 0x12) + id = ISP_IMX558_1922_02; else id = ISP_IMX558_1921_01; break; @@ -186,8 +213,13 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) id = ISP_IMX913_7523_01; break; case 0x958: - /* Section 0x50f of 2224 names sensor 0x958; 2924's names 0x614. */ - id = ISP_IMX958_2224_01; + if (platform >= 0xb9 && platform <= 0xbc) + id = ISP_IMX958_2226_01; + else if (platform == 0x78 || platform == 0x85 || + platform == 0x86) + id = ISP_IMX958_2226_02; + else + id = ISP_IMX958_2224_01; break; case 0xd56: id = ISP_VD56G0_6221_01; @@ -493,9 +525,11 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) err = isp_ch_get_sensor_id(isp, ch); if (err || - (fmt->id != ISP_IMX248_1820_01 && fmt->id != ISP_IMX558_1921_01 && + (fmt->id != ISP_IMX248_1820_01 && fmt->id != ISP_IMX248_1822_02 && + fmt->id != ISP_IMX558_1921_01 && fmt->id != ISP_IMX558_1922_02 && fmt->id != ISP_IMX558_1925_03 && fmt->id != ISP_IMX364_8720_01 && - fmt->id != ISP_IMX958_2224_01)) { + fmt->id != ISP_IMX364_8723_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); @@ -809,7 +843,8 @@ static void isp_setfile_snf_radial(struct apple_isp *isp, void *data, static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); - const struct isp_setfile *setfile = &isp_setfiles[fmt->id]; + enum isp_sensor_id id = fmt->id; + const struct isp_setfile *setfile = &isp_setfiles[id]; size_t len = setfile->file_size ?: setfile->size; const struct firmware *fw; u32 magic; @@ -817,10 +852,17 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) KUNIT_STATIC_STUB_REDIRECT(isp_ch_load_setfile, isp, ch); - if (WARN_ON_ONCE(setfile->size > isp->data_surf->size)) - return -ENOSPC; - err = firmware_request_nowarn(&fw, setfile->path, isp->dev); + if (err == -ENOENT && isp_setfile_fallback(id) != id) { + enum isp_sensor_id fb = isp_setfile_fallback(id); + + dev_warn_once(isp->dev, + "setfile '%s' missing, falling back to '%s'\n", + setfile->path, isp_setfiles[fb].path); + setfile = &isp_setfiles[fb]; + 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, @@ -832,6 +874,11 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) return err; } + if (WARN_ON_ONCE(setfile->size > isp->data_surf->size)) { + release_firmware(fw); + return -ENOSPC; + } + if (fw->size < len) { dev_err(isp->dev, "setfile '%s' too small (0x%zx/0x%zx)\n", setfile->path, fw->size, len); diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index b3dccaf9a7508..a863fee068c95 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -337,6 +337,8 @@ enum isp_sensor_id { ISP_IMX853_7622_01, ISP_IMX913_7523_01, ISP_IMX958_2224_01, + ISP_IMX958_2226_01, + ISP_IMX958_2226_02, ISP_VD56G0_6221_01, ISP_VD56G0_6222_01, };