media: atomisp: Fix probe()/remove() power-management
authorHans de Goede <hdegoede@redhat.com>
Wed, 27 Dec 2023 22:20:11 +0000 (23:20 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 1 Feb 2024 06:04:06 +0000 (07:04 +0100)
commit781bf4cee3c160a5ce97d86719675083a2f2a67c
treed4ef43dd2e3481c5c444ae7d9577bedbb1e3e423
parent3a9ceebd8ffb2d6dca14ddf58a21c98b124713f9
media: atomisp: Fix probe()/remove() power-management

Fix probe()/remove() power-management:

-Currently the driver uses pm_runtime_put_noidle() and relies on
 userspace to open + close the /dev/video# node at least once to
 actually turn the ISP off. Replace the pm_runtime_put_noidle()
 with pm_runtime_put_sync() to make sure that the device is turned
 off without relying on userspace for this.
 This also ensures that atomisp_css_init() is run (by atomisp_power_on())
 if the first userspace process opening /dev/video# wants to do more then
 just query the v4l2-caps.
 As part of this change move the pm setup code in probe() to just before
 calling v4l2_async_nf_register() which registers the /dev/* nodes, so
 that the device is left on for the entirety of the probe() function.

-Remove the turning off of the atomisp from the exit-error path,
 the PCI subsystem and subsequent probe() attempts expect the device
 to be in the on state when probe() fails.
 This also fixes the atomisp driver causing the system to hang / freeze
 when its firmware is missing. This freeze is caused by an unidentified
 bug in the power-off on exit-error code which is now removed.

-Make sure that remove() properly powers on the device by replacing
 pm_runtime_get_noresume() with pm_runtime_get_sync. The PCI subsystem
 and subsequent probe() attempts expect the device to be in the on state
 after unbinding the driver.

-Note this also swaps the order of put()/allow() and forbid()/get()
 so that the sync versions actually work by calling allow() before put()
 and forbid() after get()

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/atomisp/pci/atomisp_v4l2.c