Skip to content

Commit

Permalink
gxfb: add power management functionality
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andres Salomon authored and Linus Torvalds committed Apr 28, 2008
1 parent d1b4cc3 commit 46fb6f1
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/video/geode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ obj-$(CONFIG_FB_GEODE_GX) += gxfb.o
obj-$(CONFIG_FB_GEODE_LX) += lxfb.o

gx1fb-objs := gx1fb_core.o display_gx1.o video_cs5530.o
gxfb-objs := gxfb_core.o display_gx.o video_gx.o
gxfb-objs := gxfb_core.o display_gx.o video_gx.o suspend_gx.o
lxfb-objs := lxfb_core.o lxfb_ops.o
72 changes: 71 additions & 1 deletion drivers/video/geode/gxfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,34 @@

#include <linux/io.h>

#define GP_REG_COUNT (0x50 / 4)
#define DC_REG_COUNT (0x90 / 4)
#define VP_REG_COUNT (0x138 / 8)
#define FP_REG_COUNT (0x68 / 8)

#define DC_PAL_COUNT 0x104

struct gxfb_par {
int enable_crt;
void __iomem *dc_regs;
void __iomem *vid_regs;
void __iomem *gp_regs;
#ifdef CONFIG_PM
int powered_down;

/* register state, for power management functionality */
struct {
uint64_t padsel;
uint64_t dotpll;
} msr;

uint32_t gp[GP_REG_COUNT];
uint32_t dc[DC_REG_COUNT];
uint64_t vp[VP_REG_COUNT];
uint64_t fp[FP_REG_COUNT];

uint32_t pal[DC_PAL_COUNT];
#endif
};

unsigned int gx_frame_buffer_size(void);
Expand All @@ -29,6 +53,43 @@ void gx_set_dclk_frequency(struct fb_info *info);
void gx_configure_display(struct fb_info *info);
int gx_blank_display(struct fb_info *info, int blank_mode);

#ifdef CONFIG_PM
int gx_powerdown(struct fb_info *info);
int gx_powerup(struct fb_info *info);
#endif


/* Graphics Processor registers (table 6-23 from the data book) */
enum gp_registers {
GP_DST_OFFSET = 0,
GP_SRC_OFFSET,
GP_STRIDE,
GP_WID_HEIGHT,

GP_SRC_COLOR_FG,
GP_SRC_COLOR_BG,
GP_PAT_COLOR_0,
GP_PAT_COLOR_1,

GP_PAT_COLOR_2,
GP_PAT_COLOR_3,
GP_PAT_COLOR_4,
GP_PAT_COLOR_5,

GP_PAT_DATA_0,
GP_PAT_DATA_1,
GP_RASTER_MODE,
GP_VECTOR_MODE,

GP_BLT_MODE,
GP_BLT_STATUS,
GP_HST_SRC,
GP_BASE_OFFSET, /* 0x4c */
};

#define GP_BLT_STATUS_BLT_PENDING (1 << 2)
#define GP_BLT_STATUS_BLT_BUSY (1 << 0)


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

/* register access functions */

static inline uint32_t read_gp(struct gxfb_par *par, int reg)
{
return readl(par->gp_regs + 4*reg);
}

static inline void write_gp(struct gxfb_par *par, int reg, uint32_t val)
{
writel(val, par->gp_regs + 4*reg);
}

static inline uint32_t read_dc(struct gxfb_par *par, int reg)
{
return readl(par->dc_regs + 4*reg);
Expand All @@ -248,7 +319,6 @@ static inline void write_dc(struct gxfb_par *par, int reg, uint32_t val)
writel(val, par->dc_regs + 4*reg);
}


static inline uint32_t read_vp(struct gxfb_par *par, int reg)
{
return readl(par->vid_regs + 8*reg);
Expand Down
57 changes: 57 additions & 0 deletions drivers/video/geode/gxfb_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/console.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <asm/geode.h>
Expand Down Expand Up @@ -222,6 +223,15 @@ static int __init gxfb_map_video_memory(struct fb_info *info, struct pci_dev *de
if (!par->dc_regs)
return -ENOMEM;

ret = pci_request_region(dev, 1, "gxfb (graphics processor)");
if (ret < 0)
return ret;
par->gp_regs = ioremap(pci_resource_start(dev, 1),
pci_resource_len(dev, 1));

if (!par->gp_regs)
return -ENOMEM;

ret = pci_request_region(dev, 0, "gxfb (framebuffer)");
if (ret < 0)
return ret;
Expand Down Expand Up @@ -295,6 +305,42 @@ static struct fb_info * __init gxfb_init_fbinfo(struct device *dev)
return info;
}

#ifdef CONFIG_PM
static int gxfb_suspend(struct pci_dev *pdev, pm_message_t state)
{
struct fb_info *info = pci_get_drvdata(pdev);

if (state.event == PM_EVENT_SUSPEND) {
acquire_console_sem();
gx_powerdown(info);
fb_set_suspend(info, 1);
release_console_sem();
}

/* there's no point in setting PCI states; we emulate PCI, so
* we don't end up getting power savings anyways */

return 0;
}

static int gxfb_resume(struct pci_dev *pdev)
{
struct fb_info *info = pci_get_drvdata(pdev);
int ret;

acquire_console_sem();
ret = gx_powerup(info);
if (ret) {
printk(KERN_ERR "gxfb: power up failed!\n");
return ret;
}

fb_set_suspend(info, 0);
release_console_sem();
return 0;
}
#endif

static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct gxfb_par *par;
Expand Down Expand Up @@ -357,6 +403,10 @@ static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *i
iounmap(par->dc_regs);
pci_release_region(pdev, 2);
}
if (par->gp_regs) {
iounmap(par->gp_regs);
pci_release_region(pdev, 1);
}

if (info)
framebuffer_release(info);
Expand All @@ -379,6 +429,9 @@ static void gxfb_remove(struct pci_dev *pdev)
iounmap(par->dc_regs);
pci_release_region(pdev, 2);

iounmap(par->gp_regs);
pci_release_region(pdev, 1);

pci_set_drvdata(pdev, NULL);

framebuffer_release(info);
Expand All @@ -396,6 +449,10 @@ static struct pci_driver gxfb_driver = {
.id_table = gxfb_id_table,
.probe = gxfb_probe,
.remove = gxfb_remove,
#ifdef CONFIG_PM
.suspend = gxfb_suspend,
.resume = gxfb_resume,
#endif
};

#ifndef MODULE
Expand Down
Loading

0 comments on commit 46fb6f1

Please sign in to comment.