On the Apple GPUs handled by nv04_dfp_update_backlight(), the panel
backlight PWM lives in NV_PBUS_DEBUG_DUALHEAD_CTL. Open Firmware sets
it up and nouveau only toggles bit 31.

nouveau runs the VBIOS init tables on every resume, whether or not the
GPU lost power, and on the iMac G4 (PowerMac6,1, NV34M 10de:0329) they
write 0x7fff to that register. It reads 0x83e60535 at boot and
0x80007fff after waking from PMU sleep: backlight enabled at zero
brightness, so the panel stays dark although the display is otherwise
working.

Save the register when suspending and restore it on resume.

Fixes: 6ee738610f41 ("drm/nouveau: Add DRM driver for NVIDIA GPUs")
Signed-off-by: Matt Turner <[email protected]>
---
 drivers/gpu/drm/nouveau/dispnv04/dfp.c  |  6 +-----
 drivers/gpu/drm/nouveau/dispnv04/disp.c | 27 +++++++++++++++++++++++++++
 drivers/gpu/drm/nouveau/dispnv04/disp.h |  2 ++
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/dfp.c 
b/drivers/gpu/drm/nouveau/dispnv04/dfp.c
index 00eb2aacbe93..33b5a3398460 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/dfp.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/dfp.c
@@ -485,16 +485,13 @@ static void nv04_dfp_commit(struct drm_encoder *encoder)
 
 static void nv04_dfp_update_backlight(struct drm_encoder *encoder, int mode)
 {
-#ifdef __powerpc__
        struct drm_device *dev = encoder->dev;
        struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
-       struct pci_dev *pdev = to_pci_dev(dev->dev);
 
        /* BIOS scripts usually take care of the backlight, thanks
         * Apple for your consistency.
         */
-       if (pdev->device == 0x0174 || pdev->device == 0x0179 ||
-           pdev->device == 0x0189 || pdev->device == 0x0329) {
+       if (nv04_display_has_apple_backlight(dev)) {
                if (mode == DRM_MODE_DPMS_ON) {
                        nvif_mask(device, NV_PBUS_DEBUG_DUALHEAD_CTL, 1 << 31, 
1 << 31);
                        nvif_mask(device, NV_PCRTC_GPIO_EXT, 3, 1);
@@ -503,7 +500,6 @@ static void nv04_dfp_update_backlight(struct drm_encoder 
*encoder, int mode)
                        nvif_mask(device, NV_PCRTC_GPIO_EXT, 3, 0);
                }
        }
-#endif
 }
 
 static inline bool is_powersaving_dpms(int mode)
diff --git a/drivers/gpu/drm/nouveau/dispnv04/disp.c 
b/drivers/gpu/drm/nouveau/dispnv04/disp.c
index f71199a39bc4..7d44d18e1b88 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/disp.c
@@ -35,6 +35,20 @@
 
 #include <nvif/if0004.h>
 
+/* Apple GPUs whose panel backlight is a PWM in NV_PBUS_DEBUG_DUALHEAD_CTL. */
+bool
+nv04_display_has_apple_backlight(struct drm_device *dev)
+{
+#ifdef __powerpc__
+       struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+       return pdev->device == 0x0174 || pdev->device == 0x0179 ||
+              pdev->device == 0x0189 || pdev->device == 0x0329;
+#else
+       return false;
+#endif
+}
+
 struct nouveau_connector *
 nv04_encoder_get_connector(struct nouveau_encoder *encoder)
 {
@@ -74,6 +88,15 @@ nv04_display_fini(struct drm_device *dev, bool runtime, bool 
suspend)
        if (!suspend)
                return;
 
+       /*
+        * The VBIOS init tables, which run on resume, reset the backlight
+        * PWM that Open Firmware programmed. Save it to restore on resume.
+        */
+       if (nv04_display_has_apple_backlight(dev))
+               disp->saved_backlight_pwm =
+                       nvif_rd32(&drm->client.device.object,
+                                 NV_PBUS_DEBUG_DUALHEAD_CTL);
+
        /* Un-pin FB and cursors so they'll be evicted to system memory. */
        list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
                struct drm_framebuffer *fb = crtc->primary->fb;
@@ -126,6 +149,10 @@ nv04_display_init(struct drm_device *dev, bool resume, 
bool runtime)
        if (!resume)
                return 0;
 
+       if (nv04_display_has_apple_backlight(dev))
+               nvif_wr32(&drm->client.device.object, 
NV_PBUS_DEBUG_DUALHEAD_CTL,
+                         disp->saved_backlight_pwm);
+
        /* Re-pin FB/cursors. */
        list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
                struct drm_framebuffer *fb = crtc->primary->fb;
diff --git a/drivers/gpu/drm/nouveau/dispnv04/disp.h 
b/drivers/gpu/drm/nouveau/dispnv04/disp.h
index 85ec0f534392..2f84287a3521 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/disp.h
+++ b/drivers/gpu/drm/nouveau/dispnv04/disp.h
@@ -88,6 +88,7 @@ struct nv04_display {
        struct nouveau_bo *image[2];
        struct nvif_event flip;
        struct nouveau_drm *drm;
+       u32 saved_backlight_pwm;
 };
 
 static inline struct nv04_display *
@@ -98,6 +99,7 @@ nv04_display(struct drm_device *dev)
 
 /* nv04_display.c */
 int nv04_display_create(struct drm_device *);
+bool nv04_display_has_apple_backlight(struct drm_device *dev);
 struct nouveau_connector *
 nv04_encoder_get_connector(struct nouveau_encoder *nv_encoder);
 

-- 
2.56.1


Reply via email to