Skip to content

Commit 46fb6f1

Browse files
dilingertorvalds
authored andcommitted
gxfb: add power management functionality
This adds the ability to suspend/resume the gxfb driver, which includes: - The addition of a Graphics Processor register table in gxfb.h, and associated GP handling. - Register and palette saving code; registers are stored in gxfb_par. A few MSR values are saved as well. - gx_powerup and gx_powerdown functions which restore/save registers and enable/disable graphic engines. - gxfb_suspend/gxfb_resume Originally based on a patch by Jordan Crouse. Signed-off-by: Andres Salomon <dilinger@debian.org> Cc: Jordan Crouse <jordan.crouse@amd.com> Cc: "Antonino A. Daplas" <adaplas@pol.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d1b4cc3 commit 46fb6f1

4 files changed

Lines changed: 396 additions & 2 deletions

File tree

‎drivers/video/geode/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ obj-$(CONFIG_FB_GEODE_GX) += gxfb.o
55
obj-$(CONFIG_FB_GEODE_LX) += lxfb.o
66

77
gx1fb-objs := gx1fb_core.o display_gx1.o video_cs5530.o
8-
gxfb-objs := gxfb_core.o display_gx.o video_gx.o
8+
gxfb-objs := gxfb_core.o display_gx.o video_gx.o suspend_gx.o
99
lxfb-objs := lxfb_core.o lxfb_ops.o

‎drivers/video/geode/gxfb.h‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,34 @@
1313

1414
#include <linux/io.h>
1515

16+
#define GP_REG_COUNT (0x50 / 4)
17+
#define DC_REG_COUNT (0x90 / 4)
18+
#define VP_REG_COUNT (0x138 / 8)
19+
#define FP_REG_COUNT (0x68 / 8)
20+
21+
#define DC_PAL_COUNT 0x104
22+
1623
struct gxfb_par {
1724
int enable_crt;
1825
void __iomem *dc_regs;
1926
void __iomem *vid_regs;
27+
void __iomem *gp_regs;
28+
#ifdef CONFIG_PM
29+
int powered_down;
30+
31+
/* register state, for power management functionality */
32+
struct {
33+
uint64_t padsel;
34+
uint64_t dotpll;
35+
} msr;
36+
37+
uint32_t gp[GP_REG_COUNT];
38+
uint32_t dc[DC_REG_COUNT];
39+
uint64_t vp[VP_REG_COUNT];
40+
uint64_t fp[FP_REG_COUNT];
41+
42+
uint32_t pal[DC_PAL_COUNT];
43+
#endif
2044
};
2145

2246
unsigned int gx_frame_buffer_size(void);
@@ -29,6 +53,43 @@ void gx_set_dclk_frequency(struct fb_info *info);
2953
void gx_configure_display(struct fb_info *info);
3054
int gx_blank_display(struct fb_info *info, int blank_mode);
3155

56+
#ifdef CONFIG_PM
57+
int gx_powerdown(struct fb_info *info);
58+
int gx_powerup(struct fb_info *info);
59+
#endif
60+
61+
62+
/* Graphics Processor registers (table 6-23 from the data book) */
63+
enum gp_registers {
64+
GP_DST_OFFSET = 0,
65+
GP_SRC_OFFSET,
66+
GP_STRIDE,
67+
GP_WID_HEIGHT,
68+
69+
GP_SRC_COLOR_FG,
70+
GP_SRC_COLOR_BG,
71+
GP_PAT_COLOR_0,
72+
GP_PAT_COLOR_1,
73+
74+
GP_PAT_COLOR_2,
75+
GP_PAT_COLOR_3,
76+
GP_PAT_COLOR_4,
77+
GP_PAT_COLOR_5,
78+
79+
GP_PAT_DATA_0,
80+
GP_PAT_DATA_1,
81+
GP_RASTER_MODE,
82+
GP_VECTOR_MODE,
83+
84+
GP_BLT_MODE,
85+
GP_BLT_STATUS,
86+
GP_HST_SRC,
87+
GP_BASE_OFFSET, /* 0x4c */
88+
};
89+
90+
#define GP_BLT_STATUS_BLT_PENDING (1 << 2)
91+
#define GP_BLT_STATUS_BLT_BUSY (1 << 0)
92+
3293

3394
/* Display Controller registers (table 6-38 from the data book) */
3495
enum dc_registers {
@@ -238,6 +299,16 @@ enum fp_registers {
238299

239300
/* register access functions */
240301

302+
static inline uint32_t read_gp(struct gxfb_par *par, int reg)
303+
{
304+
return readl(par->gp_regs + 4*reg);
305+
}
306+
307+
static inline void write_gp(struct gxfb_par *par, int reg, uint32_t val)
308+
{
309+
writel(val, par->gp_regs + 4*reg);
310+
}
311+
241312
static inline uint32_t read_dc(struct gxfb_par *par, int reg)
242313
{
243314
return readl(par->dc_regs + 4*reg);
@@ -248,7 +319,6 @@ static inline void write_dc(struct gxfb_par *par, int reg, uint32_t val)
248319
writel(val, par->dc_regs + 4*reg);
249320
}
250321

251-
252322
static inline uint32_t read_vp(struct gxfb_par *par, int reg)
253323
{
254324
return readl(par->vid_regs + 8*reg);

‎drivers/video/geode/gxfb_core.c‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/slab.h>
2929
#include <linux/delay.h>
3030
#include <linux/fb.h>
31+
#include <linux/console.h>
3132
#include <linux/init.h>
3233
#include <linux/pci.h>
3334
#include <asm/geode.h>
@@ -222,6 +223,15 @@ static int __init gxfb_map_video_memory(struct fb_info *info, struct pci_dev *de
222223
if (!par->dc_regs)
223224
return -ENOMEM;
224225

226+
ret = pci_request_region(dev, 1, "gxfb (graphics processor)");
227+
if (ret < 0)
228+
return ret;
229+
par->gp_regs = ioremap(pci_resource_start(dev, 1),
230+
pci_resource_len(dev, 1));
231+
232+
if (!par->gp_regs)
233+
return -ENOMEM;
234+
225235
ret = pci_request_region(dev, 0, "gxfb (framebuffer)");
226236
if (ret < 0)
227237
return ret;
@@ -295,6 +305,42 @@ static struct fb_info * __init gxfb_init_fbinfo(struct device *dev)
295305
return info;
296306
}
297307

308+
#ifdef CONFIG_PM
309+
static int gxfb_suspend(struct pci_dev *pdev, pm_message_t state)
310+
{
311+
struct fb_info *info = pci_get_drvdata(pdev);
312+
313+
if (state.event == PM_EVENT_SUSPEND) {
314+
acquire_console_sem();
315+
gx_powerdown(info);
316+
fb_set_suspend(info, 1);
317+
release_console_sem();
318+
}
319+
320+
/* there's no point in setting PCI states; we emulate PCI, so
321+
* we don't end up getting power savings anyways */
322+
323+
return 0;
324+
}
325+
326+
static int gxfb_resume(struct pci_dev *pdev)
327+
{
328+
struct fb_info *info = pci_get_drvdata(pdev);
329+
int ret;
330+
331+
acquire_console_sem();
332+
ret = gx_powerup(info);
333+
if (ret) {
334+
printk(KERN_ERR "gxfb: power up failed!\n");
335+
return ret;
336+
}
337+
338+
fb_set_suspend(info, 0);
339+
release_console_sem();
340+
return 0;
341+
}
342+
#endif
343+
298344
static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
299345
{
300346
struct gxfb_par *par;
@@ -357,6 +403,10 @@ static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *i
357403
iounmap(par->dc_regs);
358404
pci_release_region(pdev, 2);
359405
}
406+
if (par->gp_regs) {
407+
iounmap(par->gp_regs);
408+
pci_release_region(pdev, 1);
409+
}
360410

361411
if (info)
362412
framebuffer_release(info);
@@ -379,6 +429,9 @@ static void gxfb_remove(struct pci_dev *pdev)
379429
iounmap(par->dc_regs);
380430
pci_release_region(pdev, 2);
381431

432+
iounmap(par->gp_regs);
433+
pci_release_region(pdev, 1);
434+
382435
pci_set_drvdata(pdev, NULL);
383436

384437
framebuffer_release(info);
@@ -396,6 +449,10 @@ static struct pci_driver gxfb_driver = {
396449
.id_table = gxfb_id_table,
397450
.probe = gxfb_probe,
398451
.remove = gxfb_remove,
452+
#ifdef CONFIG_PM
453+
.suspend = gxfb_suspend,
454+
.resume = gxfb_resume,
455+
#endif
399456
};
400457

401458
#ifndef MODULE

0 commit comments

Comments
 (0)