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
17 changes: 17 additions & 0 deletions Documentation/devicetree/bindings/media/apple,t8140-isp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,27 @@ properties:
camera streams whether or not the indicator is shown. The indicator is
software, not a privacy guarantee.

apple,module-tuning:
$ref: /schemas/types.yaml#/definitions/string
pattern: "^[0-9]{4}_[0-9]{2}$"
description:
Name of the camera module's own tuning (setfile), loaded in place of
the sensor's default one, e.g. "2226_02" for apple/isp_2226_02XX.dat.

sensor-presets:
type: object
description:
Sensor firmware presets and the host output geometry associated with them.
properties:
apple,lens-circle:
$ref: /schemas/types.yaml#/definitions/uint32
minimum: 1
maximum: 1000
description:
Radius of the image circle the lens draws on the sensor, in per mille
of each preset's input width, about the input's centre. Outside it
the picture is black, so each crop is scaled about its centre,
aspect kept, until its corners are inside.
patternProperties:
"^preset[0-9]+$":
type: object
Expand Down
6 changes: 6 additions & 0 deletions arch/arm64/boot/dts/apple/t8142-j813-isp.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@
* crops the driver derived in config 7, halved.
*/
sensor-presets {
/*
* Measured on a J815 (2026-11-21); the J813 is assumed to have the
* same ultra-wide lens.
*/
apple,lens-circle = <470>;

/* 1280x720 */
preset0 {
apple,config-index = <8>;
Expand Down
5 changes: 5 additions & 0 deletions arch/arm64/boot/dts/apple/t8142-j815.dts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
&isp {
/* J815 ADT /arm-io/isp sensor-type */
apple,platform-id = <0x72>;
/*
* The J815's IMX958 module tuning: with the sensor's default 2224_01 the
* corners read half the centre's brightness, with 2226_02 0.85.
*/
apple,module-tuning = "2226_02";
};

&aop_audio {
Expand Down
55 changes: 53 additions & 2 deletions drivers/media/platform/apple/isp/isp-cam-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ static void isp_test_temporal_filter_band0(struct kunit *test)
test->priv = trace;
KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0);
isp_test_expect_run(test, trace, run, ARRAY_SIZE(run));
/* The start record is (1, 0, 0) whatever the DT property says. */
/* The start record is (1, 1, 0) on band-0 setfiles, as macOS 27.2 sends it. */
i = isp_test_find(trace, 0xc100);
KUNIT_EXPECT_EQ(test, trace->word[i][0], 1);
KUNIT_EXPECT_EQ(test, trace->word[i][1], 0);
KUNIT_EXPECT_EQ(test, trace->word[i][1], 1);
KUNIT_EXPECT_EQ(test, trace->word[i][2], 0);
i = isp_test_find(trace, 0xc11d);
KUNIT_EXPECT_EQ(test, trace->word[i][0], 0x7800);
Expand Down Expand Up @@ -732,6 +732,55 @@ static void isp_test_sensor_names(struct kunit *test)
KUNIT_EXPECT_STREQ(test, apple_isp_sensor_name(isp), "imx958-uw");
}

static void isp_test_module_tuning(struct kunit *test)
{
struct apple_isp *isp = isp_test_capture_alloc(test);
static const char *const keep[] = {
"9999_99", /* no such setfile */
"7523_01", /* another sensor's */
"2224", /* not a whole name */
};

/* No property: the sensor's default. */
KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2224_01);
isp->module_tuning = "2226_02";
KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2226_02);
isp->module_tuning = "2226_01";
KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2226_01);
isp->module_tuning = "2224_01";
KUNIT_EXPECT_EQ(test, isp_module_tuning(isp, ISP_IMX958_2224_01), ISP_IMX958_2224_01);
for (unsigned int i = 0; i < ARRAY_SIZE(keep); i++) {
isp->module_tuning = keep[i];
KUNIT_EXPECT_EQ_MSG(test, isp_module_tuning(isp, ISP_IMX958_2224_01),
ISP_IMX958_2224_01, "%s", keep[i]);
}
}

/*
* A setfile missing from the system is replaced by its fallback after the
* size check against the data surface, so a fallback must be the same
* sensor, no larger, and final.
*/
static void isp_test_setfile_fallbacks(struct kunit *test)
{
unsigned int n = 0;

for (unsigned int i = 0; i < ARRAY_SIZE(isp_setfiles); i++) {
const struct isp_setfile *s = &isp_setfiles[i], *f = s->fallback;

if (!f)
continue;
n++;
KUNIT_EXPECT_EQ_MSG(test, f->version, s->version, "setfile %u", i);
KUNIT_EXPECT_LE_MSG(test, f->size, s->size, "setfile %u", i);
KUNIT_EXPECT_NULL_MSG(test, f->fallback, "setfile %u", i);
KUNIT_EXPECT_STRNEQ_MSG(test, f->path, s->path, "setfile %u", i);
}
KUNIT_EXPECT_EQ(test, n, 2);
KUNIT_EXPECT_PTR_EQ(test, isp_setfiles[ISP_IMX958_2226_02].fallback,
&isp_setfiles[ISP_IMX958_2224_01]);
}

static void isp_test_snf_flatten(u8 *snf)
{
int k;
Expand Down Expand Up @@ -1019,6 +1068,8 @@ static struct kunit_case isp_cam_test_cases[] = {
KUNIT_CASE(isp_test_stop_key_on_debug),
KUNIT_CASE(isp_test_sensor_geometry),
KUNIT_CASE(isp_test_sensor_names),
KUNIT_CASE(isp_test_module_tuning),
KUNIT_CASE(isp_test_setfile_fallbacks),
KUNIT_CASE(isp_test_sensor_config_list),
KUNIT_CASE(isp_test_sensor_config_failure),
KUNIT_CASE(isp_test_preview_stream),
Expand Down
99 changes: 93 additions & 6 deletions drivers/media/platform/apple/isp/isp-cam.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct isp_setfile {
* noise filter gains. The setfile does not carry it.
*/
int snf_centre_dy;
/* used instead when this file is not installed (module tunings missing from vendorfw) */
const struct isp_setfile *fallback;
};

// clang-format off
Expand Down Expand Up @@ -97,11 +99,76 @@ 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},
/*
* J815's own module tunings, H17-native (lens-shading records without
* the xx24 stride). The optical centre is 2224_01's: same sensor, not
* measured for this module.
*/
[ISP_IMX958_2226_01] = {0x958, "imx958-uw", 0x22260101, "apple/isp_2226_01XX.dat", 0x7040,
0, ISP_TEMPORAL_FILTER_BAND0, -156,
&isp_setfiles[ISP_IMX958_2224_01]},
[ISP_IMX958_2226_02] = {0x958, "imx958-uw", 0x22260201, "apple/isp_2226_02XX.dat", 0x7000,
0, ISP_TEMPORAL_FILTER_BAND0, -156,
&isp_setfiles[ISP_IMX958_2224_01]},
[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

/*
* What macOS 27.2 sends the same H17 firmware on the J815, from a hypervisor
* IPC trace (2026-11-20):
* - the green camera LED's brightness, 529 at each start in a lit room (only
* on T8142, where it was traced: hw->led_brightness). It is clamped to the
* range the firmware reports (CH_STATUS_LED_THR_GET, 204..1023 on the
* J815), so the privacy LED can never be set dark;
* - AE stability 16 / to-stable 8 (other firmware: 32 / 20) and an AE gain
* cap of 96.0;
* - on band-0 setfiles, TNR started with (1, 1, 0) and high strength on.
* macOS ramps the LED with ambient light; the driver keeps the start value.
*/

static void isp_ch_configure_led(struct apple_isp *isp, u32 ch)
{
u16 low, high, value;
int err;

if (!isp->hw->led_brightness)
return;
err = isp_cmd_ch_status_led_thr_get(isp, ch, &low, &high);
if (err || !low || high < low) {
dev_warn(isp->dev, "camera LED: no brightness range (%d, %u..%u): left as is\n",
err, low, high);
return;
}
value = clamp_t(unsigned int, isp->hw->led_brightness, low, high);
err = isp_cmd_ch_status_led_mbrightness_set(isp, ch, value);
dev_info(isp->dev, "camera LED brightness %u (range %u..%u)%s\n", value,
low, high, err ? ": firmware refused" : "");
}

/*
* The board's camera module tuning, named in the DT (apple,module-tuning,
* e.g. "2226_02"), in place of the sensor's default setfile. Unknown names
* and other sensors' setfiles keep the default.
*/
static enum isp_sensor_id isp_module_tuning(struct apple_isp *isp, enum isp_sensor_id def)
{
char path[48];
unsigned int i;

if (!isp->module_tuning)
return def;
snprintf(path, sizeof(path), "apple/isp_%sXX.dat", isp->module_tuning);
for (i = 0; i < ARRAY_SIZE(isp_setfiles); i++)
if (isp_setfiles[i].path && isp_setfiles[i].version == isp_setfiles[def].version &&
!strcmp(isp_setfiles[i].path, path))
return i;
dev_warn(isp->dev, "module tuning %s: no such setfile for sensor 0x%x, using %s\n",
isp->module_tuning, isp_setfiles[def].version, isp_setfiles[def].path);
return def;
}

static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch)
{
struct isp_format *fmt = isp_get_format(isp, ch);
Expand Down Expand Up @@ -187,7 +254,7 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch)
break;
case 0x958:
/* Section 0x50f of 2224 names sensor 0x958; 2924's names 0x614. */
id = ISP_IMX958_2224_01;
id = isp_module_tuning(isp, ISP_IMX958_2224_01);
break;
case 0xd56:
id = ISP_VD56G0_6221_01;
Expand Down Expand Up @@ -495,7 +562,8 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 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_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);
Expand Down Expand Up @@ -821,6 +889,13 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch)
return -ENOSPC;

err = firmware_request_nowarn(&fw, setfile->path, isp->dev);
if (err == -ENOENT && setfile->fallback) {
dev_info_once(isp->dev, "setfile '%s' not installed, using '%s'\n",
setfile->path, setfile->fallback->path);
setfile = setfile->fallback;
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,
Expand Down Expand Up @@ -929,11 +1004,12 @@ static int isp_ch_configure_temporal_filter(struct apple_isp *isp, u32 ch)
return isp_cmd_apple_ch_temporal_filter_stop(isp, ch);

case ISP_TEMPORAL_FILTER_BAND0:
err = isp_cmd_apple_ch_tnr_start_h17(isp, ch);
/* (1, 1, 0) and high strength, as macOS 27.2 */
err = isp_cmd_apple_ch_tnr_start_h17(isp, ch, true);
if (err)
return err;

err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, 0);
err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, true);
if (err)
return err;

Expand Down Expand Up @@ -1034,6 +1110,9 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch)
if (err)
return err;

if (!isp_is_p010(isp))
isp_ch_configure_led(isp, ch);

err = isp_cmd_ch_buffer_recycle_mode_set(
isp, ch, CISP_BUFFER_RECYCLE_MODE_EMPTY_ONLY);
if (err)
Expand Down Expand Up @@ -1105,14 +1184,22 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch)
if (err)
return err;

err = isp_cmd_ch_ae_stability_set(isp, ch, 32);
err = isp_cmd_ch_ae_stability_set(isp, ch, h17 ? 16 : 32);
if (err)
return err;

err = isp_cmd_ch_ae_stability_to_stable_set(isp, ch, 20);
err = isp_cmd_ch_ae_stability_to_stable_set(isp, ch,
h17 ? 8 : 20);
if (err)
return err;

/* 96.0 in 8.8 fixed point, the gain cap macOS sets */
if (h17) {
err = isp_cmd_ch_ae_gain_cap_set(isp, ch, 96 << 8);
if (err)
return err;
}

err = isp_cmd_ch_sif_pixel_format_set(isp, ch);
if (err)
return err;
Expand Down
41 changes: 40 additions & 1 deletion drivers/media/platform/apple/isp/isp-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,13 @@ int isp_cmd_apple_ch_temporal_filter_disable(struct apple_isp *isp, u32 chan)
return CISP_SEND_IN(isp, args);
}

int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan)
int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan, u32 unk_10)
{
struct cmd_apple_ch_temporal_filter_start_h17 args = {
.opcode = CISP_OPCODE(CISP_CMD_APPLE_CH_TEMPORAL_FILTER_START),
.chan = chan,
.unk_c = 1,
.unk_10 = unk_10, /* macOS 27.2 on the J815: 1 */
};
return CISP_SEND_IN(isp, args);
}
Expand Down Expand Up @@ -846,3 +847,41 @@ int isp_cmd_ch_property_read(struct apple_isp *isp, u32 chan, u32 prop, u32 *val

return ret;
}

int isp_cmd_ch_ae_gain_cap_set(struct apple_isp *isp, u32 chan, u32 gain)
{
struct cmd_ch_ae_gain_cap_set args = {
.opcode = CISP_OPCODE(CISP_CMD_CH_AE_GAIN_CAP_SET),
.chan = chan,
.gain = gain,
};
return CISP_SEND_IN(isp, args);
}

int isp_cmd_ch_status_led_mbrightness_set(struct apple_isp *isp, u32 chan,
u16 brightness)
{
struct cmd_ch_status_led_mbrightness_set args = {
.opcode = CISP_OPCODE(CISP_CMD_CH_STATUS_LED_MBRIGHTNESS_SET),
.chan = chan,
.brightness = brightness,
};
return CISP_SEND_IN(isp, args);
}

int isp_cmd_ch_status_led_thr_get(struct apple_isp *isp, u32 chan, u16 *low,
u16 *high)
{
struct cmd_ch_status_led_thr_get args = {
.opcode = CISP_OPCODE(CISP_CMD_CH_STATUS_LED_THR_GET),
.chan = chan,
};
int err = CISP_SEND_OUT(isp, &args);

if (err)
return err;
*low = args.low;
*high = args.high;
return 0;
}

Loading
Loading