From: Kevin Brace <kevinbrace@gmx.com>
To: dri-devel@lists.freedesktop.org
Cc: Kevin Brace <kevinbrace@bracecomputerlab.com>
Subject: [PATCH v3 21/32] drm/via: Add via_pm.c
Date: Mon, 25 Jul 2022 16:53:48 -0700 [thread overview]
Message-ID: <20220725235359.20516-2-kevinbrace@gmx.com> (raw)
In-Reply-To: <20220725235359.20516-1-kevinbrace@gmx.com>
From: Kevin Brace <kevinbrace@bracecomputerlab.com>
Signed-off-by: Kevin Brace <kevinbrace@bracecomputerlab.com>
---
drivers/gpu/drm/via/via_pm.c | 187 +++++++++++++++++++++++++++++++++++
1 file changed, 187 insertions(+)
create mode 100644 drivers/gpu/drm/via/via_pm.c
diff --git a/drivers/gpu/drm/via/via_pm.c b/drivers/gpu/drm/via/via_pm.c
new file mode 100644
index 000000000000..5fad01447eed
--- /dev/null
+++ b/drivers/gpu/drm/via/via_pm.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright © 2017-2020 Kevin Brace.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author(s):
+ * Kevin Brace <kevinbrace@bracecomputerlab.com>
+ */
+
+
+#include <linux/console.h>
+#include <linux/pci.h>
+
+#include "via_drv.h"
+
+
+int via_dev_pm_ops_suspend(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct drm_device *drm_dev = pci_get_drvdata(pdev);
+ struct via_drm_priv *dev_priv = to_via_drm_priv(drm_dev);
+ int ret = 0;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ console_lock();
+
+ /*
+ * Frame Buffer Size Control register (SR14) and GTI registers
+ * (SR66 through SR6F) need to be saved and restored upon standby
+ * resume or can lead to a display corruption issue. These registers
+ * are only available on VX800, VX855, and VX900 chipsets. This bug
+ * was observed on VIA Embedded EPIA-M830 mainboard.
+ */
+ if ((pdev->device == PCI_DEVICE_ID_VIA_CHROME9_HC3) ||
+ (pdev->device == PCI_DEVICE_ID_VIA_CHROME9_HCM) ||
+ (pdev->device == PCI_DEVICE_ID_VIA_CHROME9_HD)) {
+ dev_priv->saved_sr14 = vga_rseq(VGABASE, 0x14);
+
+ dev_priv->saved_sr66 = vga_rseq(VGABASE, 0x66);
+ dev_priv->saved_sr67 = vga_rseq(VGABASE, 0x67);
+ dev_priv->saved_sr68 = vga_rseq(VGABASE, 0x68);
+ dev_priv->saved_sr69 = vga_rseq(VGABASE, 0x69);
+ dev_priv->saved_sr6a = vga_rseq(VGABASE, 0x6a);
+ dev_priv->saved_sr6b = vga_rseq(VGABASE, 0x6b);
+ dev_priv->saved_sr6c = vga_rseq(VGABASE, 0x6c);
+ dev_priv->saved_sr6d = vga_rseq(VGABASE, 0x6d);
+ dev_priv->saved_sr6e = vga_rseq(VGABASE, 0x6e);
+ dev_priv->saved_sr6f = vga_rseq(VGABASE, 0x6f);
+ }
+
+ /*
+ * 3X5.3B through 3X5.3F are scratch pad registers.
+ * They are important for FP detection.
+ * Their values need to be saved because they get lost
+ * when resuming from standby.
+ */
+ dev_priv->saved_cr3b = vga_rcrt(VGABASE, 0x3b);
+ dev_priv->saved_cr3c = vga_rcrt(VGABASE, 0x3c);
+ dev_priv->saved_cr3d = vga_rcrt(VGABASE, 0x3d);
+ dev_priv->saved_cr3e = vga_rcrt(VGABASE, 0x3e);
+ dev_priv->saved_cr3f = vga_rcrt(VGABASE, 0x3f);
+
+ console_unlock();
+
+ ret = drm_mode_config_helper_suspend(drm_dev);
+ if (ret) {
+ DRM_ERROR("Failed to prepare for suspend.\n");
+ goto exit;
+ }
+
+ pci_save_state(pdev);
+ pci_disable_device(pdev);
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return ret;
+}
+
+int via_dev_pm_ops_resume(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct drm_device *drm_dev = pci_get_drvdata(pdev);
+ struct via_drm_priv *dev_priv = to_via_drm_priv(drm_dev);
+ void __iomem *regs = ioport_map(0x3c0, 100);
+ u8 val;
+ int ret = 0;
+
+ DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+ if (pci_enable_device(pdev)) {
+ DRM_ERROR("Failed to initialize a PCI "
+ "after resume.\n");
+ ret = -EIO;
+ goto exit;
+ }
+
+ console_lock();
+
+ val = ioread8(regs + 0x03);
+ iowrite8(val | 0x1, regs + 0x03);
+ val = ioread8(regs + 0x0C);
+ iowrite8(val | 0x1, regs + 0x02);
+
+ /*
+ * Unlock Extended IO Space.
+ */
+ iowrite8(0x10, regs + 0x04);
+ iowrite8(0x01, regs + 0x05);
+
+ /*
+ * Unlock CRTC register protect.
+ */
+ iowrite8(0x47, regs + 0x14);
+
+ /*
+ * Enable MMIO.
+ */
+ iowrite8(0x1a, regs + 0x04);
+ val = ioread8(regs + 0x05);
+ iowrite8(val | 0x38, regs + 0x05);
+
+ /*
+ * Frame Buffer Size Control register (SR14) and GTI registers
+ * (SR66 through SR6F) need to be saved and restored upon standby
+ * resume or can lead to a display corruption issue. These registers
+ * are only available on VX800, VX855, and VX900 chipsets. This bug
+ * was observed on VIA Embedded EPIA-M830 mainboard.
+ */
+ if ((pdev->device == PCI_DEVICE_ID_VIA_CHROME9_HC3) ||
+ (pdev->device == PCI_DEVICE_ID_VIA_CHROME9_HCM) ||
+ (pdev->device == PCI_DEVICE_ID_VIA_CHROME9_HD)) {
+ vga_wseq(VGABASE, 0x14, dev_priv->saved_sr14);
+
+ vga_wseq(VGABASE, 0x66, dev_priv->saved_sr66);
+ vga_wseq(VGABASE, 0x67, dev_priv->saved_sr67);
+ vga_wseq(VGABASE, 0x68, dev_priv->saved_sr68);
+ vga_wseq(VGABASE, 0x69, dev_priv->saved_sr69);
+ vga_wseq(VGABASE, 0x6a, dev_priv->saved_sr6a);
+ vga_wseq(VGABASE, 0x6b, dev_priv->saved_sr6b);
+ vga_wseq(VGABASE, 0x6c, dev_priv->saved_sr6c);
+ vga_wseq(VGABASE, 0x6d, dev_priv->saved_sr6d);
+ vga_wseq(VGABASE, 0x6e, dev_priv->saved_sr6e);
+ vga_wseq(VGABASE, 0x6f, dev_priv->saved_sr6f);
+ }
+
+ /*
+ * 3X5.3B through 3X5.3F are scratch pad registers.
+ * They are important for FP detection.
+ * Their values need to be restored because they are undefined
+ * after resuming from standby.
+ */
+ vga_wcrt(VGABASE, 0x3b, dev_priv->saved_cr3b);
+ vga_wcrt(VGABASE, 0x3c, dev_priv->saved_cr3c);
+ vga_wcrt(VGABASE, 0x3d, dev_priv->saved_cr3d);
+ vga_wcrt(VGABASE, 0x3e, dev_priv->saved_cr3e);
+ vga_wcrt(VGABASE, 0x3f, dev_priv->saved_cr3f);
+
+ console_unlock();
+
+ ret = drm_mode_config_helper_resume(drm_dev);
+ if (ret) {
+ DRM_ERROR("Failed to perform a modeset "
+ "after resume.\n");
+ goto exit;
+ }
+
+exit:
+ DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+ return ret;
+}
--
2.35.1
next prev parent reply other threads:[~2022-07-25 23:55 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 23:53 [PATCH v3 20/32] drm/via: Add via_pll.c Kevin Brace
2022-07-25 23:53 ` Kevin Brace [this message]
2022-07-25 23:53 ` [PATCH v3 22/32] drm/via: Add via_sii164.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 23/32] drm/via: Add via_tmds.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 24/32] drm/via: Add via_ttm.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 25/32] drm/via: Add via_vt1632.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 26/32] drm/via: Add via_drm.h Kevin Brace
2022-07-26 17:41 ` Sam Ravnborg
2022-07-26 18:18 ` Thomas Zimmermann
2022-07-26 20:20 ` Dave Airlie
2022-07-27 7:36 ` Thomas Zimmermann
2022-07-29 1:06 ` Kevin Brace
2022-07-31 2:14 ` Kevin Brace
2022-07-26 18:24 ` Thomas Zimmermann
2022-07-30 22:48 ` Kevin Brace
2022-08-01 14:40 ` Sam Ravnborg
2022-08-02 0:10 ` Kevin Brace
2022-08-02 11:09 ` Sam Ravnborg
2022-08-02 18:12 ` Kevin Brace
2022-08-01 18:49 ` Thomas Zimmermann
2022-08-02 3:45 ` Kevin Brace
2022-08-02 11:38 ` Thomas Zimmermann
2022-08-03 1:49 ` Kevin Brace
2022-08-04 12:20 ` Thomas Zimmermann
2022-08-04 15:09 ` Sam Ravnborg
2022-07-25 23:53 ` [PATCH v3 27/32] drm/via: Add new VIA Technologies Chrome supporting PCI IDs to DRM Kevin Brace
2022-07-25 23:53 ` [PATCH v3 28/32] drm/via: Zero out chip type field Kevin Brace
2022-07-25 23:53 ` [PATCH v3 29/32] drm/via: Add new VIA Technologies PCI device IDs related to graphics Kevin Brace
2022-07-25 23:53 ` [PATCH v3 30/32] drm/via: Add Kconfig Kevin Brace
2022-07-26 7:28 ` Thomas Zimmermann
2022-07-31 1:49 ` Kevin Brace
2022-08-01 10:36 ` Thomas Zimmermann
2022-07-25 23:53 ` [PATCH v3 31/32] drm/via: Add Makefile Kevin Brace
2022-07-26 7:29 ` Thomas Zimmermann
2022-07-31 1:55 ` Kevin Brace
2022-07-25 23:53 ` [PATCH v3 32/32] drm/via: Modify DRM core to be able to build OpenChrome DRM Kevin Brace
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220725235359.20516-2-kevinbrace@gmx.com \
--to=kevinbrace@gmx.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kevinbrace@bracecomputerlab.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).