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
110 changes: 110 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,115 @@ 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_permodule_lsc_math(struct kunit *test)
{
/* IEEE-754 binary32 coordinates: 0.0, 0.25, 0.5, 0.75, 1.0 */
static const u32 coords[5] = {
0x00000000, 0x3e800000, 0x3f000000, 0x3f400000, 0x3f800000,
};
enum { GW = 5, GH = 5, LSC = 0x54 + 4 * GW * GH * 2, FLAG = 8 };
struct apple_isp *isp = isp_test_capture_alloc(test);
size_t len = 0x14 + 12 + LSC + 12 + LSC + 12 + FLAG;
u8 *data = kunit_kzalloc(test, len, GFP_KERNEL);
u8 *lsc_sec, *dsc_sec, *flag_sec;
u8 nvm8[4 * 25];
__le16 nvm10[4 * 25];
struct isp_permodule_lsc lsc = {};
struct isp_lsc_params p = {
.ideal_pct = 84, .max_gain = U16_MAX,
.flip_permodule = false, .avg_green = true,
};

KUNIT_ASSERT_NOT_NULL(test, data);
KUNIT_EXPECT_EQ(test, isp_f32_to_q24(0x00000000), 0);
KUNIT_EXPECT_EQ(test, isp_f32_to_q24(0x3f000000), LSC_ONE >> 1);
KUNIT_EXPECT_EQ(test, isp_f32_to_q24(0x3f800000), LSC_ONE);
KUNIT_EXPECT_LT(test, isp_f32_to_q24(0xbf000000), 0);
KUNIT_EXPECT_LT(test, isp_f32_to_q24(0x3fc00000), 0);
KUNIT_EXPECT_LT(test, isp_f32_to_q24(0x7fc00000), 0);

lsc_sec = data + 0x14 + 12;
dsc_sec = lsc_sec + LSC + 12;
flag_sec = dsc_sec + LSC + 12;
put_unaligned_le32(8 + LSC, lsc_sec - 12);
put_unaligned_le32(0xc003, lsc_sec - 4);
put_unaligned_le32(8 + LSC, dsc_sec - 12);
put_unaligned_le32(0xc021, dsc_sec - 4);
put_unaligned_le32(8 + FLAG, flag_sec - 12);
put_unaligned_le32(0x0a2a, flag_sec - 4);
put_unaligned_le16(1024, lsc_sec + 6);
put_unaligned_le16(1024, lsc_sec + 8);
put_unaligned_le16(4 * GW * GH, lsc_sec + 0x52);
put_unaligned_le16(4 * GW * GH, dsc_sec + 0x52);
for (int t = 0; t < 4; t++) {
u8 *rec = lsc_sec + 0xa + 18 * t;

put_unaligned_le16(128, rec + 2);
put_unaligned_le16(128, rec + 4);
put_unaligned_le16(t * GW * GH, rec + 6);
put_unaligned_le16(GW, rec + 14);
put_unaligned_le16(GH, rec + 16);
}
for (int i = 0; i < 4 * GW * GH; i++)
put_unaligned_le16(SNF_ONE + 1024, dsc_sec + 0x54 + 2 * i);

/* 8-bit asymmetric vignetting: plane 0 darker than plane 3 at corner (0,0). */
for (int t = 0; t < 4; t++) {
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
int r2 = (x - 2) * (x - 2) + (y - 2) * (y - 2);
int v = 250 - r2 * (15 + 3 * t);

nvm8[t * 25 + y * 5 + x] = max(v, 50);
nvm10[t * 25 + y * 5 + x] = cpu_to_le16(max(v, 50) * 4);
}
}
}

lsc.valid = true;
lsc.num_x = 5;
lsc.num_y = 5;
lsc.bit_depth = 8;
lsc.data_size = sizeof(nvm8);
lsc.data = nvm8;
memcpy(lsc.x_coords, coords, sizeof(coords));
memcpy(lsc.y_coords, coords, sizeof(coords));

KUNIT_EXPECT_TRUE(test, isp_setfile_apply_lsc(isp, data, len, &lsc, &p, 0));
KUNIT_EXPECT_EQ(test, flag_sec[4], 1);
/* Center (2,2) has measured=1.0 and ideal=1.0 -> gain ~4096. */
KUNIT_EXPECT_EQ(test, get_unaligned_le16(lsc_sec + 0x54 + 2 * 12), 4096);
/* Legacy green averaging makes ch 0 (Gr) and ch 3 (Gb) match. */
KUNIT_EXPECT_EQ(test, get_unaligned_le16(lsc_sec + 0x54),
get_unaligned_le16(lsc_sec + 0x54 + 2 * (3 * 25)));
/* Corners get boost > 1.0x and max_gain recorded in channel header. */
KUNIT_EXPECT_GT(test, get_unaligned_le16(lsc_sec + 0x54), 5000);
KUNIT_EXPECT_GE(test, get_unaligned_le16(lsc_sec + 0xa),
get_unaligned_le16(lsc_sec + 0x54));

/* 10-bit H17 path without green averaging, clamped to 0x4fff, then DSC *1.25. */
lsc.bit_depth = 10;
lsc.data_size = sizeof(nvm10);
lsc.data = (u8 *)nvm10;
p.avg_green = false;
p.max_gain = 0x4fff;
KUNIT_EXPECT_TRUE(test, isp_setfile_apply_lsc(isp, data, len, &lsc, &p, -156));
KUNIT_EXPECT_NE(test, get_unaligned_le16(lsc_sec + 0x54),
get_unaligned_le16(lsc_sec + 0x54 + 2 * (3 * 25)));
{
u16 before = get_unaligned_le16(lsc_sec + 0x54 + 2 * 12);

isp_setfile_apply_dsc(data, len);
KUNIT_EXPECT_EQ(test, get_unaligned_le16(lsc_sec + 0x54 + 2 * 12),
DIV_ROUND_CLOSEST((u32)before * (SNF_ONE + 1024),
SNF_ONE));
}

/* Non-monotonic coordinates are rejected cleanly. */
lsc.x_coords[2] = lsc.x_coords[1];
KUNIT_EXPECT_FALSE(test, isp_setfile_apply_lsc(isp, data, len, &lsc, &p, 0));
}

struct isp_test_lsc_wire {
bool h17;
u8 info_calls;
Expand Down Expand Up @@ -1134,6 +1243,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_math),
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),
Expand Down
Loading
Loading