diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index f0410cea88b5f..dc854d6f087e6 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -1290,6 +1290,8 @@ static const struct apple_isp_hw apple_isp_hw_t8132 = { .shared_size = 0xdec00000, .fw_restore = true, .deferred_start = true, + /* macOS never writes its coprocessor control word 0 at power-down */ + .macos_stop = true, }; /* diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index 3551018baf174..2ca9f4704b69c 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -277,6 +277,9 @@ struct apple_isp_hw { * reopen the camera, does not wait for another firmware start. */ unsigned int fw_idle_ms; + + /* Power down as macOS does: the coprocessor control word is left as it is */ + bool macos_stop; }; enum isp_sensor_id { @@ -503,6 +506,8 @@ struct apple_isp { * resident firmware cannot be started again before the next boot. */ bool ipc_failed; + /* The last power-down left the coprocessor control word as it was */ + bool macos_stopped; }; struct isp_chan_ops { diff --git a/drivers/media/platform/apple/isp/isp-fw.c b/drivers/media/platform/apple/isp/isp-fw.c index 09b6912286505..d7c94fc03dbd9 100644 --- a/drivers/media/platform/apple/isp/isp-fw.c +++ b/drivers/media/platform/apple/isp/isp-fw.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,15 @@ #include "isp-iommu.h" #include "isp-ipc.h" #include "isp-regs.h" + +/* + * macOS powers the T8132 ISP down without writing the coprocessor control + * word 0. macos_stop=N writes it again, as before. + */ +static bool macos_stop = true; +module_param(macos_stop, bool, 0644); +MODULE_PARM_DESC(macos_stop, + "Power the ISP down as macOS does where known, e.g. T8132: leave the control word alone (default: on)"); #include "isp-v4l2.h" #define ISP_FIRMWARE_POLL_US 1000 @@ -356,7 +366,11 @@ static int isp_check_coproc_t6040(struct apple_isp *isp) u32 control = isp_coproc_read32(isp, isp_coproc_control(isp)); u64 rvbar = readq(isp->coproc + ISP_COPROC_RVBAR); - if (control) { + /* + * A macOS-style power-down leaves the start word (0x10) where the + * domain kept it; the boot writes 0 then 0x10 as for a fresh start. + */ + if (control && !(isp->macos_stopped && control == 0x10)) { isp_err(isp, "coprocessor already started (control 0x%x)\n", control); return -EBUSY; @@ -477,6 +491,7 @@ static void isp_firmware_shutdown_stage1(struct apple_isp *isp) /* Only a coprocessor that was started has to settle and quiesce */ bool started = isp->hw->coproc_quiesce && isp_coproc_read32(isp, isp_coproc_control(isp)); + bool macos = READ_ONCE(macos_stop) && isp->hw->macos_stop; u32 val; /* A coprocessor that powered down waits in WFI */ @@ -491,7 +506,7 @@ static void isp_firmware_shutdown_stage1(struct apple_isp *isp) * engine's own restore of the ISP in a wake that kept DRAM up depends on it: * with the bit cleared that wake stalls until the SoC's watchdog resets it. */ - if (isp->hw->gen != ISP_GEN_T8140) + if (isp->hw->gen != ISP_GEN_T8140 && !macos) isp_coproc_write32(isp, isp_coproc_control(isp), 0x0); if (started) { @@ -503,6 +518,7 @@ static void isp_firmware_shutdown_stage1(struct apple_isp *isp) } apple_isp_power_down_domains(isp); + isp->macos_stopped = macos; } static int isp_firmware_boot_stage1(struct apple_isp *isp)