diff --git a/drivers/media/platform/apple/isp/isp-cam-test.c b/drivers/media/platform/apple/isp/isp-cam-test.c index a98b38a16fd78..6048408b3707a 100644 --- a/drivers/media/platform/apple/isp/isp-cam-test.c +++ b/drivers/media/platform/apple/isp/isp-cam-test.c @@ -1008,6 +1008,45 @@ 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, 0x12, ISP_IMX558_1921_01 }, + { &hw_legacy, 0x558, 0x03, ISP_IMX558_1921_01 }, + { &hw_legacy, 0x558, 0x0f, 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, 0xb9, ISP_IMX958_2224_01 }, + { &hw_legacy, 0x364, 0x03, ISP_IMX364_8720_01 }, + { &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 +1066,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..295d48384075a 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,20 +98,36 @@ 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_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_IMX558_1922_02: + return ISP_IMX558_1921_01; + case ISP_IMX958_2226_01: + 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; @@ -149,6 +166,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; + /* M2 Air: measured better on 1922_02XX. */ + else if (platform == 0x0e) + id = ISP_IMX558_1922_02; else id = ISP_IMX558_1921_01; break; @@ -186,8 +206,11 @@ 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; + /* M5 Pro: measured better on 2226_01XX. */ + if (platform == 0xba) + id = ISP_IMX958_2226_01; + else + id = ISP_IMX958_2224_01; break; case 0xd56: id = ISP_VD56G0_6221_01; @@ -494,8 +517,9 @@ 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_IMX558_1925_03 && fmt->id != ISP_IMX364_8720_01 && - fmt->id != ISP_IMX958_2224_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_IMX958_2226_01)) { dev_err(isp->dev, "ch %d: unsupported sensor. Please file a bug report with hardware info & dmesg trace.\n", ch); @@ -809,7 +833,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 +842,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 +864,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..a6d1ab5431fa6 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -337,6 +337,7 @@ enum isp_sensor_id { ISP_IMX853_7622_01, ISP_IMX913_7523_01, ISP_IMX958_2224_01, + ISP_IMX958_2226_01, ISP_VD56G0_6221_01, ISP_VD56G0_6222_01, };