From 18de246fd3e6ebcbae929c603b1380f008272a41 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 19:36:45 +1100 Subject: [PATCH 1/2] media: apple: isp: query per-module lens shading calibration from sensor NVM Add IPC commands and caching for per-module lens shading calibration stored in the camera module's NVM: - Add isp_cmd_send_data() to send commands whose payload exceeds the IPC command area over isp->data_surf. - Implement CISP_CMD_CH_SENSOR_PERMODULE_LSC_INFO_GET (0x0507) and CISP_CMD_CH_SENSOR_PERMODULE_LSC_GRID_GET (0x0511) for both legacy (0x10/0xb0 header, 8-bit grid) and H17 (0x14/0x114 header, 8..16-bit grid) firmware ABIs, caching the validated grid during sensor detection. - Implement CISP_CMD_CH_LSC_IDEAL_PCT_SET (0x0a4e) and send the sensor's target corner illumination percentage before loading the setfile. Add KUnit wire-layout tests covering both legacy and H17 ABI command sizes and reply parsing. --- .../media/platform/apple/isp/isp-cam-test.c | 108 +++++++++++++ drivers/media/platform/apple/isp/isp-cam.c | 79 ++++++++++ drivers/media/platform/apple/isp/isp-cmd.c | 146 +++++++++++++++++- drivers/media/platform/apple/isp/isp-cmd.h | 59 +++++++ drivers/media/platform/apple/isp/isp-drv.h | 19 +++ 5 files changed, 404 insertions(+), 7 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..ffa7c9f1ad490 100644 --- a/drivers/media/platform/apple/isp/isp-cam-test.c +++ b/drivers/media/platform/apple/isp/isp-cam-test.c @@ -1008,6 +1008,113 @@ static void isp_test_failed_fw_stop_lights_off(struct kunit *test) KUNIT_EXPECT_EQ(test, trace.set_off_at, 1); } +struct isp_test_lsc_wire { + bool h17; + u8 info_calls; + u8 grid_calls; +}; + +static int isp_test_lsc_info_stub(struct apple_isp *isp, void *args, + u32 insize, u32 outsize, int timeout) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_lsc_wire *w = test->priv; + + w->info_calls++; + if (w->h17) { + struct cmd_ch_sensor_lsc_info_h17 *r = isp->cmd_virt; + + KUNIT_EXPECT_EQ(test, insize, 0x14); + KUNIT_EXPECT_EQ(test, outsize, 0x14); + memcpy(r, args, sizeof(*r)); + r->num_x = 3; + r->num_y = 3; + r->bit_depth = 10; + r->data_size = 3 * 3 * 4 * 2; + } else { + struct cmd_ch_sensor_lsc_info_legacy *r = isp->cmd_virt; + + KUNIT_EXPECT_EQ(test, insize, 0x10); + KUNIT_EXPECT_EQ(test, outsize, 0x10); + memcpy(r, args, sizeof(*r)); + r->num_x = 3; + r->num_y = 3; + r->data_size = 3 * 3 * 4; + } + return 0; +} + +static int isp_test_lsc_grid_stub(struct apple_isp *isp, void *args, + u32 insize, u32 outsize, int timeout) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_lsc_wire *w = test->priv; + + w->grid_calls++; + if (w->h17) { + struct cmd_ch_sensor_lsc_grid_h17 *h = args; + + KUNIT_EXPECT_EQ(test, insize, 0x114 + 72); + h->valid = 1; + h->x_coords[0] = 0x00000000; + h->x_coords[1] = 0x3f000000; + h->x_coords[2] = 0x3f800000; + h->y_coords[0] = 0x00000000; + h->y_coords[1] = 0x3f000000; + h->y_coords[2] = 0x3f800000; + memset((u8 *)args + sizeof(*h), 0x42, 72); + } else { + struct cmd_ch_sensor_lsc_grid_legacy *h = args; + + KUNIT_EXPECT_EQ(test, insize, 0xb0 + 36); + h->valid = 1; + h->x_coords[0] = 0x00000000; + h->x_coords[1] = 0x3f000000; + h->x_coords[2] = 0x3f800000; + h->y_coords[0] = 0x00000000; + h->y_coords[1] = 0x3f000000; + h->y_coords[2] = 0x3f800000; + memset((u8 *)args + sizeof(*h), 0x55, 36); + } + return 0; +} + +static void isp_test_permodule_lsc_wire(struct kunit *test) +{ + static const struct apple_isp_hw hw_legacy = { + .gen = ISP_GEN_T8112, .fw_abi = ISP_FW_ABI_LEGACY, + }; + static const struct apple_isp_hw hw_h17 = { + .gen = ISP_GEN_T6040, .fw_abi = ISP_FW_ABI_H17, + }; + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_test_lsc_wire w = {}; + + isp->cmd_virt = kunit_kzalloc(test, 0x40, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp->cmd_virt); + test->priv = &w; + kunit_activate_static_stub(test, isp_cmd_send, isp_test_lsc_info_stub); + kunit_activate_static_stub(test, isp_cmd_send_data, isp_test_lsc_grid_stub); + + isp->hw = &hw_legacy; + w.h17 = false; + isp_ch_cache_permodule_lsc(isp, 0); + KUNIT_EXPECT_TRUE(test, isp->lsc.valid); + KUNIT_EXPECT_EQ(test, isp->lsc.bit_depth, 8); + KUNIT_EXPECT_EQ(test, isp->lsc.data_size, 36); + KUNIT_EXPECT_EQ(test, isp->lsc.data[0], 0x55); + + isp->hw = &hw_h17; + w.h17 = true; + isp_ch_cache_permodule_lsc(isp, 0); + KUNIT_EXPECT_TRUE(test, isp->lsc.valid); + KUNIT_EXPECT_EQ(test, isp->lsc.bit_depth, 10); + KUNIT_EXPECT_EQ(test, isp->lsc.data_size, 72); + KUNIT_EXPECT_EQ(test, isp->lsc.data[0], 0x42); + KUNIT_EXPECT_EQ(test, w.info_calls, 2); + KUNIT_EXPECT_EQ(test, w.grid_calls, 2); +} + static struct kunit_case isp_cam_test_cases[] = { KUNIT_CASE(isp_test_call_crop), KUNIT_CASE(isp_test_call_crop_bounds), @@ -1027,6 +1134,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_permodule_lsc_wire), 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..71781b0a09157 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -457,6 +457,38 @@ static int isp_add_call_sizes(struct apple_isp *isp) return 0; } +static void isp_ch_cache_permodule_lsc(struct apple_isp *isp, u32 ch) +{ + struct isp_permodule_lsc *lsc = &isp->lsc; + u8 num_x, num_y, bit_depth; + u16 data_size; + int err; + + lsc->valid = false; + err = isp_cmd_ch_sensor_lsc_info_get(isp, ch, &num_x, &num_y, + &data_size, &bit_depth); + if (err) { + dev_dbg(isp->dev, "ch %u: no per-module LSC info (%d)\n", + ch, err); + return; + } + + lsc->num_x = num_x; + lsc->num_y = num_y; + lsc->data_size = data_size; + lsc->bit_depth = bit_depth; + + err = isp_cmd_ch_sensor_lsc_grid_get(isp, ch, lsc); + if (err) { + dev_dbg(isp->dev, "ch %u: per-module LSC grid unavailable (%d)\n", + ch, err); + return; + } + + dev_info(isp->dev, "ch %u: per-module LSC %ux%u (%u-bit)\n", + ch, lsc->num_x, lsc->num_y, lsc->bit_depth); +} + static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); @@ -513,6 +545,8 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) err = isp_ch_cache_sensor_configs(isp, ch, args->num_presets); if (!err) err = isp_add_call_sizes(isp); + if (!err) + isp_ch_cache_permodule_lsc(isp, ch); exit: kfree(args); @@ -806,10 +840,45 @@ static void isp_setfile_snf_radial(struct apple_isp *isp, void *data, dev_warn_once(isp->dev, "setfile: noise filter gains not computed, keeping the stock ones\n"); } +struct isp_lsc_params { + u16 ideal_pct; + u16 max_gain; + bool flip_permodule; + bool avg_green; +}; + +static struct isp_lsc_params isp_sensor_lsc_params(const struct apple_isp *isp, + u32 sensor_version) +{ + struct isp_lsc_params p = { + .max_gain = U16_MAX, + .avg_green = isp->hw->fw_abi == ISP_FW_ABI_LEGACY, + }; + + switch (sensor_version) { + case 0x364: + if (isp->platform_id == 0x0a) + p.ideal_pct = 90; + break; + case 0x558: + p.ideal_pct = 84; + p.flip_permodule = isp->platform_id != 0x70; + break; + case 0x958: + p.ideal_pct = 84; + p.max_gain = 0x4fff; + break; + default: + break; + } + return p; +} + 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]; + struct isp_lsc_params lsc_params = isp_sensor_lsc_params(isp, fmt->version); size_t len = setfile->file_size ?: setfile->size; const struct firmware *fw; u32 magic; @@ -850,6 +919,16 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) memcpy(isp->data_surf->virt, fw->data, len); memset(isp->data_surf->virt + len, 0, setfile->size - len); release_firmware(fw); + + if (lsc_params.ideal_pct) { + int pct_err = isp_cmd_ch_lsc_ideal_pct_set(isp, ch, + lsc_params.ideal_pct); + if (pct_err) + dev_dbg(isp->dev, + "ch %u: ideal LSC percent %u rejected (%d), continuing\n", + ch, lsc_params.ideal_pct, pct_err); + } + /* Seen on T6040 only; T8140 runs its setfiles as they are. */ if (isp->hw->gen == ISP_GEN_T6040 || isp->hw->setfile_stride_fixup) isp_setfile_fixup_h17(isp->data_surf->virt, len); diff --git a/drivers/media/platform/apple/isp/isp-cmd.c b/drivers/media/platform/apple/isp/isp-cmd.c index 7fb5203e71aea..8f837937142d9 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.c +++ b/drivers/media/platform/apple/isp/isp-cmd.c @@ -21,10 +21,10 @@ #define CISP_POST_IN(x, a) (isp_cmd_send((x), &(a), sizeof(a), 0, 0)) #define CISP_POST_INOUT(x, a) (isp_cmd_send((x), &(a), sizeof(a), sizeof(a), 0)) -/* Send through the command area on a command channel. */ -static int isp_cmd_send_chan(struct apple_isp *isp, struct isp_channel *chan, - void *args, u32 insize, u32 outsize, - unsigned long timeout) +/* Send through a caller-supplied DMA command buffer on a command channel. */ +static int isp_cmd_send_buf(struct apple_isp *isp, struct isp_channel *chan, + dma_addr_t iova, void *virt, void *args, + u32 insize, u32 outsize, unsigned long timeout) { struct isp_message *req; int err; @@ -39,11 +39,11 @@ static int isp_cmd_send_chan(struct apple_isp *isp, struct isp_channel *chan, return err; req = &chan->req; - req->arg0 = isp->cmd_iova; + req->arg0 = iova; req->arg1 = insize; req->arg2 = outsize; - memcpy(isp->cmd_virt, args, insize); + memcpy(virt, args, insize); err = ipc_chan_send(isp, chan, timeout); /* * An answered request leaves the ring in step, so a malformed answer @@ -55,7 +55,7 @@ static int isp_cmd_send_chan(struct apple_isp *isp, struct isp_channel *chan, if (!err && timeout && (rsp->arg1 != outsize || rsp->arg2 || rsp->arg3 || rsp->arg4 || rsp->arg5 || rsp->arg6 || rsp->arg7 || - get_unaligned_le64(isp->cmd_virt) != get_unaligned_le64(args))) + get_unaligned_le64(virt) != get_unaligned_le64(args))) err = -EIO; } if (err) { @@ -70,6 +70,15 @@ static int isp_cmd_send_chan(struct apple_isp *isp, struct isp_channel *chan, return err; } +/* Send through the command area on a command channel. */ +static int isp_cmd_send_chan(struct apple_isp *isp, struct isp_channel *chan, + void *args, u32 insize, u32 outsize, + unsigned long timeout) +{ + return isp_cmd_send_buf(isp, chan, isp->cmd_iova, isp->cmd_virt, args, + insize, outsize, timeout); +} + int isp_cmd_send(struct apple_isp *isp, void *args, u32 insize, u32 outsize, int timeout) { if (READ_ONCE(isp->ipc_error)) @@ -80,6 +89,33 @@ int isp_cmd_send(struct apple_isp *isp, void *args, u32 insize, u32 outsize, int timeout); } +/* + * Send a command whose payload exceeds the IPC command area through the + * data surface, copying the reply back into @args. Callers must not overlap + * another user of @isp->data_surf. + */ +int isp_cmd_send_data(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout) +{ + int err; + + if (READ_ONCE(isp->ipc_error)) + return READ_ONCE(isp->ipc_error); + + KUNIT_STATIC_STUB_REDIRECT(isp_cmd_send_data, isp, args, insize, + outsize, timeout); + if (!isp->data_surf || insize > isp->data_surf->size || + outsize > isp->data_surf->size) + return -ENOSPC; + + err = isp_cmd_send_buf(isp, isp->chan_io, isp->data_surf->iova, + isp->data_surf->virt, args, insize, outsize, + timeout); + if (!err && outsize) + memcpy(args, isp->data_surf->virt, outsize); + return err; +} + static int cisp_send_read(struct apple_isp *isp, void *args, u32 insize, u32 outsize) { @@ -846,3 +882,99 @@ int isp_cmd_ch_property_read(struct apple_isp *isp, u32 chan, u32 prop, u32 *val return ret; } + +int isp_cmd_ch_lsc_ideal_pct_set(struct apple_isp *isp, u32 chan, + u16 ideal_pct) +{ + struct cmd_ch_lsc_ideal_pct_set args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_LSC_IDEAL_PCT_SET), + .chan = chan, + .ideal_pct = ideal_pct, + }; + + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_ch_sensor_lsc_info_get(struct apple_isp *isp, u32 chan, + u8 *num_x, u8 *num_y, u16 *data_size, + u8 *bit_depth) +{ + bool h17 = isp->hw->fw_abi == ISP_FW_ABI_H17; + struct cmd_ch_sensor_lsc_info_h17 args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_SENSOR_PERMODULE_LSC_INFO_GET), + .chan = chan, + }; + u32 wire_size = h17 ? sizeof(struct cmd_ch_sensor_lsc_info_h17) : + sizeof(struct cmd_ch_sensor_lsc_info_legacy); + u8 max_x = h17 ? ISP_LSC_MAX_GRID_X : ISP_LSC_LEGACY_MAX_GRID_X; + u8 max_y = h17 ? ISP_LSC_MAX_GRID_Y : ISP_LSC_LEGACY_MAX_GRID_Y; + u16 max_sz = h17 ? ISP_LSC_MAX_DATA_SIZE : ISP_LSC_LEGACY_MAX_DATA_SIZE; + u8 bd; + int err; + + err = cisp_send_read(isp, &args, wire_size, wire_size); + if (err) + return err; + + bd = h17 ? args.bit_depth : 8; + if (args.num_x < 2 || args.num_x > max_x || + args.num_y < 2 || args.num_y > max_y || + bd < 8 || bd > 16 || args.data_size > max_sz || + args.data_size < (size_t)args.num_x * args.num_y * 4 * (bd >= 9 ? 2 : 1)) + return -EINVAL; + + *num_x = args.num_x; + *num_y = args.num_y; + *data_size = args.data_size; + *bit_depth = bd; + return 0; +} + +int isp_cmd_ch_sensor_lsc_grid_get(struct apple_isp *isp, u32 chan, + struct isp_permodule_lsc *lsc) +{ + bool h17 = isp->hw->fw_abi == ISP_FW_ABI_H17; + size_t hdr_size = h17 ? sizeof(struct cmd_ch_sensor_lsc_grid_h17) : + sizeof(struct cmd_ch_sensor_lsc_grid_legacy); + size_t cmd_size = hdr_size + lsc->data_size; + struct cmd_ch_sensor_lsc_grid_legacy *leg; + struct cmd_ch_sensor_lsc_grid_h17 *ext; + void *buf; + u8 *data; + int err; + + buf = kzalloc(cmd_size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + leg = buf; + ext = buf; + leg->opcode = CISP_OPCODE(CISP_CMD_CH_SENSOR_PERMODULE_LSC_GRID_GET); + leg->chan = chan; + + err = isp_cmd_send_data(isp, buf, cmd_size, cmd_size, CISP_TIMEOUT); + if (err) + goto out; + + if (!leg->valid) { + err = -ENODATA; + goto out; + } + + data = devm_kmemdup(isp->dev, buf + hdr_size, lsc->data_size, GFP_KERNEL); + if (!data) { + err = -ENOMEM; + goto out; + } + + memcpy(lsc->x_coords, h17 ? ext->x_coords : leg->x_coords, + lsc->num_x * sizeof(u32)); + memcpy(lsc->y_coords, h17 ? ext->y_coords : leg->y_coords, + lsc->num_y * sizeof(u32)); + lsc->data = data; + lsc->valid = true; + +out: + kfree(buf); + return err; +} diff --git a/drivers/media/platform/apple/isp/isp-cmd.h b/drivers/media/platform/apple/isp/isp-cmd.h index ab98f3447d6f7..a9c8d08f93fae 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.h +++ b/drivers/media/platform/apple/isp/isp-cmd.h @@ -70,6 +70,7 @@ #define CISP_CMD_CH_ALS_DISABLE 0x0a1d #define CISP_CMD_CH_CNR_START 0x0a2f #define CISP_CMD_CH_MBNR_ENABLE 0x0a3a +#define CISP_CMD_CH_LSC_IDEAL_PCT_SET 0x0a4e #define CISP_CMD_CH_OUTPUT_CONFIG_SET 0x0b01 #define CISP_CMD_CH_OUTPUT_CONFIG_SCL1_SET 0x0b09 #define CISP_CMD_CH_PREVIEW_STREAM_SET 0x0b0d @@ -277,6 +278,8 @@ static_assert(sizeof(struct cmd_flicker_sensor_set) == 0xc); int isp_cmd_send(struct apple_isp *isp, void *args, u32 insize, u32 outsize, int timeout); +int isp_cmd_send_data(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout); int isp_cmd_start(struct apple_isp *isp, u32 mode); int isp_cmd_stop(struct apple_isp *isp, u32 mode); int isp_cmd_stop_cold(struct apple_isp *isp, u32 mode); @@ -831,4 +834,60 @@ 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); +struct cmd_ch_lsc_ideal_pct_set { + u64 opcode; + u32 chan; + u16 ideal_pct; + u16 pad_e; +} __packed; +static_assert(sizeof(struct cmd_ch_lsc_ideal_pct_set) == 0x10); + +struct cmd_ch_sensor_lsc_info_legacy { + u64 opcode; + u32 chan; + u8 num_x; + u8 num_y; + u16 data_size; +} __packed; +static_assert(sizeof(struct cmd_ch_sensor_lsc_info_legacy) == 0x10); + +struct cmd_ch_sensor_lsc_info_h17 { + u64 opcode; + u32 chan; + u8 num_x; + u8 num_y; + u16 data_size; + u8 bit_depth; + u8 pad_11[3]; +} __packed; +static_assert(sizeof(struct cmd_ch_sensor_lsc_info_h17) == 0x14); + +struct cmd_ch_sensor_lsc_grid_legacy { + u64 opcode; + u32 chan; + u8 valid; + u8 pad_d[3]; + u32 x_coords[ISP_LSC_LEGACY_MAX_GRID_X]; + u32 y_coords[ISP_LSC_LEGACY_MAX_GRID_Y]; +} __packed; +static_assert(sizeof(struct cmd_ch_sensor_lsc_grid_legacy) == 0xb0); + +struct cmd_ch_sensor_lsc_grid_h17 { + u64 opcode; + u32 chan; + u8 valid; + u8 pad_d[3]; + u32 x_coords[ISP_LSC_MAX_GRID_X]; + u32 y_coords[ISP_LSC_MAX_GRID_Y]; +} __packed; +static_assert(sizeof(struct cmd_ch_sensor_lsc_grid_h17) == 0x114); + +int isp_cmd_ch_lsc_ideal_pct_set(struct apple_isp *isp, u32 chan, + u16 ideal_pct); +int isp_cmd_ch_sensor_lsc_info_get(struct apple_isp *isp, u32 chan, + u8 *num_x, u8 *num_y, u16 *data_size, + u8 *bit_depth); +int isp_cmd_ch_sensor_lsc_grid_get(struct apple_isp *isp, u32 chan, + struct isp_permodule_lsc *lsc); + #endif /* __ISP_CMD_H__ */ diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index b3dccaf9a7508..fc16196ed5a99 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -360,6 +360,24 @@ struct isp_format { size_t total_size; }; +#define ISP_LSC_LEGACY_MAX_GRID_X 23 +#define ISP_LSC_LEGACY_MAX_GRID_Y 17 +#define ISP_LSC_LEGACY_MAX_DATA_SIZE 1564 +#define ISP_LSC_MAX_GRID_X 27 +#define ISP_LSC_MAX_GRID_Y 38 +#define ISP_LSC_MAX_DATA_SIZE 0x2010 + +struct isp_permodule_lsc { + bool valid; + u8 num_x; + u8 num_y; + u8 bit_depth; + u16 data_size; + u32 x_coords[ISP_LSC_MAX_GRID_X]; + u32 y_coords[ISP_LSC_MAX_GRID_Y]; + u8 *data; +}; + struct apple_isp { struct device *dev; const struct apple_isp_hw *hw; @@ -381,6 +399,7 @@ struct apple_isp { int num_channels; struct isp_format fmts[ISP_MAX_CHANNELS]; + struct isp_permodule_lsc lsc; unsigned int current_ch; struct video_device vdev; From 8b5758f345c1d93da9118d82323128180e9cdeca Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 20:56:13 +1100 Subject: [PATCH 2/2] media: apple: isp: propagate IPC transport errors when caching LSC Return READ_ONCE(isp->ipc_error) from isp_ch_cache_permodule_lsc() when a query fails due to a poisoned IPC transport (e.g. timeout), while keeping missing/unpopulated NVM responses non-fatal. Free any prior cached buffer via devm_kfree() before re-querying. --- drivers/media/platform/apple/isp/isp-cam.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index 71781b0a09157..6505791b863b2 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -457,7 +457,7 @@ static int isp_add_call_sizes(struct apple_isp *isp) return 0; } -static void isp_ch_cache_permodule_lsc(struct apple_isp *isp, u32 ch) +static int isp_ch_cache_permodule_lsc(struct apple_isp *isp, u32 ch) { struct isp_permodule_lsc *lsc = &isp->lsc; u8 num_x, num_y, bit_depth; @@ -465,12 +465,15 @@ static void isp_ch_cache_permodule_lsc(struct apple_isp *isp, u32 ch) int err; lsc->valid = false; + devm_kfree(isp->dev, lsc->data); + lsc->data = NULL; + err = isp_cmd_ch_sensor_lsc_info_get(isp, ch, &num_x, &num_y, &data_size, &bit_depth); if (err) { dev_dbg(isp->dev, "ch %u: no per-module LSC info (%d)\n", ch, err); - return; + return READ_ONCE(isp->ipc_error); } lsc->num_x = num_x; @@ -482,11 +485,12 @@ static void isp_ch_cache_permodule_lsc(struct apple_isp *isp, u32 ch) if (err) { dev_dbg(isp->dev, "ch %u: per-module LSC grid unavailable (%d)\n", ch, err); - return; + return READ_ONCE(isp->ipc_error); } dev_info(isp->dev, "ch %u: per-module LSC %ux%u (%u-bit)\n", ch, lsc->num_x, lsc->num_y, lsc->bit_depth); + return 0; } static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) @@ -546,7 +550,7 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) if (!err) err = isp_add_call_sizes(isp); if (!err) - isp_ch_cache_permodule_lsc(isp, ch); + err = isp_ch_cache_permodule_lsc(isp, ch); exit: kfree(args);