Skip to content
Merged
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
41 changes: 28 additions & 13 deletions drivers/media/platform/apple/isp/isp-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,35 @@ static int isp_check_coproc_t6040(struct apple_isp *isp)
return 0;
}

/*
* The reset of the ISPs before T8140 and T6040 reads two words until they are
* 0, at most this many times each with no wait between reads, and goes on
* whatever they read. A word that is still set after the last read is not a
* fault: on M1 Pro the first word and on M2 the second one stays set on every
* boot and the camera works. The WFI poll that follows is the check that
* fails the reset. The reads, their offsets and this bound come from the
* original driver and have no known source (aurora-silicon/linux#2318), so
* each word's last value and number of reads are reported at debug level.
*/
#define ISP_COPROC_DRAIN_READS 128

static void isp_drain_coproc_word(struct apple_isp *isp, u32 reg)
{
unsigned int reads = 0;
u32 val;

do {
val = isp_coproc_read32(isp, reg);
reads++;
} while (val && reads < ISP_COPROC_DRAIN_READS);

isp_dbg(isp, "coprocessor word %#x read %#x after %u reads\n", reg, val,
reads);
}

static int isp_reset_coproc(struct apple_isp *isp)
{
int retries;
u32 status;
u32 val;

if (isp->hw->gen == ISP_GEN_T8140)
return isp_reset_coproc_t8140(isp);
Expand All @@ -403,17 +427,8 @@ static int isp_reset_coproc(struct apple_isp *isp)
isp_coproc_write32(isp, ISP_COPROC_IRQ_MASK_4, 0xffffffff);
isp_coproc_write32(isp, ISP_COPROC_IRQ_MASK_5, 0xffffffff);

for (retries = 0; retries < 128; retries++) {
val = isp_coproc_read32(isp, 0x818);
if (val == 0)
break;
}

for (retries = 0; retries < 128; retries++) {
val = isp_coproc_read32(isp, 0x81c);
if (val == 0)
break;
}
isp_drain_coproc_word(isp, ISP_COPROC_DRAIN_0);
isp_drain_coproc_word(isp, ISP_COPROC_DRAIN_1);

if (readl_poll_timeout(isp->coproc + ISP_COPROC_STATUS, status,
status & ISP_COPROC_IN_WFI,
Expand Down
8 changes: 8 additions & 0 deletions drivers/media/platform/apple/isp/isp-regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
#define ISP_COPROC_IRQ_MASK_4 0x1400a10
#define ISP_COPROC_IRQ_MASK_5 0x1400a14

/*
* Two words the reset before T8140 reads until they are 0. What they are is
* not known; the T8140 reset reads its acknowledge words at 0x1600818 and
* 0x160081c instead.
*/
#define ISP_COPROC_DRAIN_0 0x818
#define ISP_COPROC_DRAIN_1 0x81c

#define ISP_COPROC_CONTROL_T8140 0x1600044
#define ISP_COPROC_STATUS_T8140 0x1600048
#define ISP_COPROC_QUIESCE_T8140 0x1600040
Expand Down
Loading