xref: /linux/drivers/gpu/drm/i915/display/i9xx_display_sr.c (revision e814f3fd16acfb7f9966773953de8f740a1e3202)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2024 Intel Corporation
4  */
5 
6 #include <drm/drm_device.h>
7 
8 #include "i915_reg.h"
9 #include "i9xx_display_sr.h"
10 #include "i9xx_wm_regs.h"
11 #include "intel_de.h"
12 #include "intel_gmbus.h"
13 #include "intel_pci_config.h"
14 
15 static void i9xx_display_save_swf(struct intel_display *display)
16 {
17 	int i;
18 
19 	/* Scratch space */
20 	if (DISPLAY_VER(display) == 2 && display->platform.mobile) {
21 		for (i = 0; i < 7; i++) {
22 			display->restore.saveSWF0[i] = intel_de_read(display, SWF0(display, i));
23 			display->restore.saveSWF1[i] = intel_de_read(display, SWF1(display, i));
24 		}
25 		for (i = 0; i < 3; i++)
26 			display->restore.saveSWF3[i] = intel_de_read(display, SWF3(display, i));
27 	} else if (DISPLAY_VER(display) == 2) {
28 		for (i = 0; i < 7; i++)
29 			display->restore.saveSWF1[i] = intel_de_read(display, SWF1(display, i));
30 	} else if (HAS_GMCH(display)) {
31 		for (i = 0; i < 16; i++) {
32 			display->restore.saveSWF0[i] = intel_de_read(display, SWF0(display, i));
33 			display->restore.saveSWF1[i] = intel_de_read(display, SWF1(display, i));
34 		}
35 		for (i = 0; i < 3; i++)
36 			display->restore.saveSWF3[i] = intel_de_read(display, SWF3(display, i));
37 	}
38 }
39 
40 static void i9xx_display_restore_swf(struct intel_display *display)
41 {
42 	int i;
43 
44 	/* Scratch space */
45 	if (DISPLAY_VER(display) == 2 && display->platform.mobile) {
46 		for (i = 0; i < 7; i++) {
47 			intel_de_write(display, SWF0(display, i), display->restore.saveSWF0[i]);
48 			intel_de_write(display, SWF1(display, i), display->restore.saveSWF1[i]);
49 		}
50 		for (i = 0; i < 3; i++)
51 			intel_de_write(display, SWF3(display, i), display->restore.saveSWF3[i]);
52 	} else if (DISPLAY_VER(display) == 2) {
53 		for (i = 0; i < 7; i++)
54 			intel_de_write(display, SWF1(display, i), display->restore.saveSWF1[i]);
55 	} else if (HAS_GMCH(display)) {
56 		for (i = 0; i < 16; i++) {
57 			intel_de_write(display, SWF0(display, i), display->restore.saveSWF0[i]);
58 			intel_de_write(display, SWF1(display, i), display->restore.saveSWF1[i]);
59 		}
60 		for (i = 0; i < 3; i++)
61 			intel_de_write(display, SWF3(display, i), display->restore.saveSWF3[i]);
62 	}
63 }
64 
65 void i9xx_display_sr_save(struct intel_display *display)
66 {
67 	struct pci_dev *pdev = to_pci_dev(display->drm->dev);
68 
69 	if (!HAS_DISPLAY(display))
70 		return;
71 
72 	/* Display arbitration control */
73 	if (DISPLAY_VER(display) <= 4)
74 		display->restore.saveDSPARB = intel_de_read(display, DSPARB(display));
75 
76 	if (DISPLAY_VER(display) == 4)
77 		pci_read_config_word(pdev, GCDGMBUS, &display->restore.saveGCDGMBUS);
78 
79 	i9xx_display_save_swf(display);
80 }
81 
82 void i9xx_display_sr_restore(struct intel_display *display)
83 {
84 	struct pci_dev *pdev = to_pci_dev(display->drm->dev);
85 
86 	if (!HAS_DISPLAY(display))
87 		return;
88 
89 	i9xx_display_restore_swf(display);
90 
91 	if (DISPLAY_VER(display) == 4)
92 		pci_write_config_word(pdev, GCDGMBUS, display->restore.saveGCDGMBUS);
93 
94 	/* Display arbitration */
95 	if (DISPLAY_VER(display) <= 4)
96 		intel_de_write(display, DSPARB(display), display->restore.saveDSPARB);
97 }
98