Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions drivers/media/platform/apple/isp/isp-cam-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
83 changes: 83 additions & 0 deletions drivers/media/platform/apple/isp/isp-cam.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,42 @@ static int isp_add_call_sizes(struct apple_isp *isp)
return 0;
}

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;
u16 data_size;
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 READ_ONCE(isp->ipc_error);
}

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 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)
{
struct isp_format *fmt = isp_get_format(isp, ch);
Expand Down Expand Up @@ -513,6 +549,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)
err = isp_ch_cache_permodule_lsc(isp, ch);

exit:
kfree(args);
Expand Down Expand Up @@ -806,10 +844,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;
Expand Down Expand Up @@ -850,6 +923,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);
Expand Down
Loading
Loading