Skip to content
37 changes: 37 additions & 0 deletions arch/arm64/boot/dts/apple/t6040-j616s.dts
Original file line number Diff line number Diff line change
Expand Up @@ -4512,6 +4512,43 @@
};
};

/* The video encoder, its DARTs and its power domains. */
&ps_venc0_sys {
status = "okay";
};

&ps_venc0_dma {
status = "okay";
};

&ps_venc0_pipe4 {
status = "okay";
};

&ps_venc0_pipe5 {
status = "okay";
};

&ps_venc0_me0 {
status = "okay";
};

&ps_venc0_me1 {
status = "okay";
};

&ave0_dart0 {
status = "okay";
};

&ave0_dart1 {
status = "okay";
};

&ave {
status = "okay";
};

#include "t6040-j616s-usb3.dtsi"

/* External display chain, all disabled: the gate in drivers/soc/apple/display-gate.c enables it. */
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/boot/dts/apple/t6040.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@
compatible = "apple,t6041-dart", "apple,t8110-dart";
reg = <0x2 0x83080000 0x0 0xc000>;
#iommu-cells = <1>;
apple,dma-range = <0x100 0x0 0x300 0x0>;
apple,dma-range = <0x100 0x00004000 0x0 0xffffc000>;
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 1461 IRQ_TYPE_LEVEL_HIGH>;
power-domains = <&ps_venc0_sys>;
Expand All @@ -1896,7 +1896,7 @@
compatible = "apple,t6041-dart", "apple,t8110-dart";
reg = <0x2 0x830a0000 0x0 0xc000>;
#iommu-cells = <1>;
apple,dma-range = <0x100 0x0 0x300 0x0>;
apple,dma-range = <0x100 0x00004000 0x0 0xffffc000>;
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 1461 IRQ_TYPE_LEVEL_HIGH>;
power-domains = <&ps_venc0_sys>;
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/boot/dts/apple/t8140.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@
interrupts = <AIC_IRQ 955 IRQ_TYPE_LEVEL_HIGH>;
power-domains = <&ps_venc0_sys>;
#iommu-cells = <1>;
apple,dma-range = <0x100 0x00004000 0 0x0fffc000>;
apple,dma-range = <0x100 0x00004000 0 0xffffc000>;
status = "disabled";
};

Expand All @@ -993,7 +993,7 @@
interrupts = <AIC_IRQ 955 IRQ_TYPE_LEVEL_HIGH>;
power-domains = <&ps_venc0_sys>;
#iommu-cells = <1>;
apple,dma-range = <0x100 0x00004000 0 0x0fffc000>;
apple,dma-range = <0x100 0x00004000 0 0xffffc000>;
status = "disabled";
};

Expand Down
14 changes: 13 additions & 1 deletion drivers/media/platform/apple/ave/ave-drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,23 @@ const struct ave_variant ave_t8112 = {
.boot_qualified = true,
};

/* CRC, boot-config words and coprocessor start registers remain unqualified. */
/*
* The M4 Pro (T6040 in the ADT, apple,t6041 in the DT) starts its encoder
* like the A18 Pro: same coprocessor registers and boot sequence, its own
* device ID and type.
*/
static const struct ave_variant ave_t6041 = {
.regs = &ave_coproc_v40,
.fw_text_size = 0x14c000,
.fw_data_size = 0x12c000,
.boot_device_id = 27,
.boot_arg_value = AVE_COPROC_BOOT_ARG_VALUE,
.timebase_multiplier = 1,
.vcbar_mask = U64_MAX,
.vcbar_flags = AVE_COPROC_VCBAR_VALID,
.device_type = 25,
.lfs_ref_scale = 2,
.boot_qualified = true,
};

static const struct ave_variant ave_t8140 = {
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/apple/ave/ave-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
static const u32 ave_known_text_crc[] = {
0x2ce7359e, /* AppleAVE2FW 9003.78.0 */
0x69c54454, /* AppleAVE2FW 9003.78.0 (macOS 26.0.x) */
AVE_FW_TEXT_CRC_T6040_25G83, /* AppleAVE2FW 9003.78.0 / T6040 */
0x460c7a7c, /* AppleAVE2FW 6070.11.1 / T6000 */
0x25bfd039, /* AppleAVE2FW 6070.11.1 / T8112 */
};
Expand Down
8 changes: 6 additions & 2 deletions drivers/media/platform/apple/ave/ave-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const struct ave_fw_layout ave_layout_9003_78_0 = {
.bytes = { { 0x3180, 0x63d8 }, { 0x13f28, 0xb1c0 } },
.hdr_bytes = 0x12c000,
.meta_bytes = 0xc000,
.process_timeout_us = 94400000,
.process_timeout_us = 46400000,
.process_subtype = 0x15,
.max_slots = 5,
.mcc_dsid = 0x12,
Expand Down Expand Up @@ -529,7 +529,11 @@ const struct ave_fw_layout ave_layout_6070_11_1 = {

const struct ave_fw_layout *ave_layout_for_crc(u32 crc)
{
if (crc == AVE_FW_TEXT_CRC_9003_78_0)
/*
* The M4 Pro gets the same 25G83 firmware build as the A18 Pro, built
* for its own chip, and speaks the same command layout.
*/
if (crc == AVE_FW_TEXT_CRC_9003_78_0 || crc == AVE_FW_TEXT_CRC_T6040_25G83)
return &ave_layout_9003_78_0;
if (crc == 0x460c7a7c || crc == 0x25bfd039)
return &ave_layout_6070_11_1;
Expand Down
10 changes: 5 additions & 5 deletions drivers/media/platform/apple/ave/ave-sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
#define AVE_SHDR_ENTRY_BYTES 0x400
#define AVE_CODED_MIN 0x3c000

/* H.264 per-frame buffer (Process +0x58c8): unused in bit-rate modes */
#define AVE_H264_FRAME_BUF SZ_16K

/* Level limits: max frame size, max rate, max bit rate (kbit/s, Main). */
struct ave_level {
u32 max_fs;
Expand Down Expand Up @@ -276,7 +273,10 @@ static int ave_sess_alloc(struct ave_dev *ave, struct ave_session *sess)
if (fw->counted && p->rc_mode == 3)
for (unsigned int i = 0; i < 2; i++)
ave_req(r, &n, &sess->mb_extra[i], ALIGN(82 * p->mbs, SZ_16K), 0, nomap);
ave_req(r, &n, &sess->row_a, hevc ? SZ_16K : ALIGN(256 * w16, SZ_16K), 0, nomap);
/* HEVC: one 0x180-byte neighbour record per 64 pixels, at least 16 KiB. */
ave_req(r, &n, &sess->row_a,
ALIGN(hevc ? max_t(u32, 0x180 * DIV_ROUND_UP(w, 64), SZ_16K) : 256 * w16, SZ_16K),
0, nomap);
ave_req(r, &n, &sess->row_b, ALIGN(hevc ? 768 * w32 : 1024 * w16, SZ_16K), 0, nomap);
ave_req(r, &n, &sess->fixed, SZ_16K, 0, nomap);
for (unsigned int i = 0; i < (hevc ? 4 : AVE_TILE_BUFS); i++) {
Expand All @@ -297,7 +297,7 @@ static int ave_sess_alloc(struct ave_dev *ave, struct ave_session *sess)
ALIGN(432 * p->mbs, SZ_16K), 0, nomap);
} else {
ave_req(r, &n, &sess->slot[s].aux,
hevc ? AVE_SHDR_BYTES : AVE_H264_FRAME_BUF, 0,
hevc ? AVE_SHDR_BYTES : ALIGN(432 * p->mbs, SZ_16K), 0,
hevc ? 0 : nomap);
}
}
Expand Down
17 changes: 9 additions & 8 deletions drivers/media/platform/apple/ave/ave-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@
*/
#define AVE_MIN_W 320
#define AVE_MIN_H 240
#define AVE_MAX_W 2560
#define AVE_MAX_H 1600
#define AVE_MAX_W 4096
#define AVE_MAX_H 2304
#define AVE_STEP 16
#define AVE_STRIDE_ALIGN 64
#define AVE_DEFAULT_W 1920
#define AVE_DEFAULT_H 1080
/*
* Buffer counts are limited so a full set fits the encoder's 256 MiB DART
* window next to a session: each queue may use this much, counting every
* buffer at the power-of-two size the DMA layer maps it with.
* Buffer counts are limited so the queues of a few concurrent sessions fit
* the encoder's 4 GiB DART window next to their session buffers: each queue
* may use this much, counting every buffer at the power-of-two size the DMA
* layer maps it with. That is 16 OUTPUT frames at 3840x2160.
*/
#define AVE_OUTPUT_BUDGET (80 * SZ_1M)
#define AVE_CAPTURE_BUDGET (40 * SZ_1M)
#define AVE_OUTPUT_BUDGET (256 * SZ_1M)
#define AVE_CAPTURE_BUDGET (128 * SZ_1M)
#define AVE_MAX_QUEUE_BUFS 16
#define AVE_RESTART_TRIES 10
#define AVE_RESTART_WAIT_MS 100
Expand Down Expand Up @@ -544,7 +545,7 @@ static int ave_queue_setup(struct vb2_queue *vq, unsigned int *nbufs, unsigned i
/* Frames stay with the firmware until encoded; keep one spare. */
if (V4L2_TYPE_IS_OUTPUT(vq->type) && have + *nbufs < AVE_MAX_SLOTS + 1)
*nbufs = AVE_MAX_SLOTS + 1 - have;
/* A full set of both queues must fit the encoder's 256 MiB DART window. */
/* A full set of both queues must fit the budget for the DART window. */
if (have >= max) {
dev_dbg(ctx->ave->dev, "%s queue already has its %u buffers\n",
V4L2_TYPE_IS_OUTPUT(vq->type) ? "OUTPUT" : "CAPTURE", max);
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/platform/apple/ave/ave.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ enum ave_opcode {

/* The firmware build whose command layouts the driver generates */
#define AVE_FW_TEXT_CRC_9003_78_0 0x69c54454
/* The M4 Pro (T6040) build of the same 25G83 firmware. */
#define AVE_FW_TEXT_CRC_T6040_25G83 0x68d5f9f6

struct ave_ctx;

Expand Down