summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2009-02-19 17:51:00 +0100
committerLars-Peter Clausen <lars@metafoo.de>2009-02-19 17:51:00 +0100
commit0b537b064c59af7eff9a73f0bdc8fa58c93a4047 (patch)
tree17f63ae5e0e2f9386632447b09ea10afde714798
parent8062d7aa7bac7e06c1a00bd88ca78098550606ed (diff)
Add basic RandR 1.2 support.
-rw-r--r--src/Makefile.am4
-rw-r--r--src/glamo-cmdq.c2
-rw-r--r--src/glamo-display.c215
-rw-r--r--src/glamo-driver.c335
-rw-r--r--src/glamo-output.c142
-rw-r--r--src/glamo.h22
6 files changed, 483 insertions, 237 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b85ebb2..7bfdc12 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,5 +33,7 @@ glamo_drv_la_SOURCES = \
glamo.h \
glamo-cmdq.c \
glamo-funcs.c \
- glamo-draw.c
+ glamo-draw.c \
+ glamo-display.c \
+ glamo-output.c
diff --git a/src/glamo-cmdq.c b/src/glamo-cmdq.c
index a678d01..8053867 100644
--- a/src/glamo-cmdq.c
+++ b/src/glamo-cmdq.c
@@ -40,7 +40,7 @@ static void GLAMODumpRegs(GlamoPtr pGlamo, CARD16 from, CARD16 to);
#define CQ_MASKL (CQ_MASK & 0xffff)
#define CQ_MASKH (CQ_MASK >> 16)
-#ifndef NDEBUG
+#if 0
static void
GLAMODebugFifo(GlamoPtr pGlamo)
{
diff --git a/src/glamo-display.c b/src/glamo-display.c
new file mode 100644
index 0000000..dd98a26
--- /dev/null
+++ b/src/glamo-display.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright © 2009 Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "xf86i2c.h"
+#include "xf86Crtc.h"
+
+#include "fbdevhw.h"
+#include <linux/fb.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+#include "glamo.h"
+#include "glamo-regs.h"
+
+static void GlamoCrtcDPMS(xf86CrtcPtr crtc, int mode);
+static void GlamoCrtcGammaSet(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green,
+ CARD16 *blue, int size);
+static void GlamoCrtcDestroy(xf86CrtcPtr crtc);
+
+static Bool
+GlamoSetModeMajor(xf86CrtcPtr crtc, DisplayModePtr mode,
+ Rotation rotation, int x, int y);
+
+static const xf86CrtcFuncsRec glamo_crtc_funcs = {
+ .dpms = GlamoCrtcDPMS,
+ .save = NULL,
+ .restore = NULL,
+ .lock = NULL,
+ .unlock = NULL,
+ .mode_fixup = NULL,
+ .prepare = NULL,
+ .mode_set = NULL,
+ .commit = NULL,
+ .gamma_set = GlamoCrtcGammaSet,
+ .shadow_allocate = NULL,
+ .shadow_create = NULL,
+ .shadow_destroy = NULL,
+ .set_cursor_colors = NULL,
+ .set_cursor_position = NULL,
+ .show_cursor = NULL,
+ .hide_cursor = NULL,
+ .load_cursor_image = NULL,
+ .load_cursor_argb = NULL,
+ .destroy = GlamoCrtcDestroy,
+ .set_mode_major = GlamoSetModeMajor
+};
+
+static void
+ConvertModeXfreeToFb(DisplayModePtr mode, Rotation *rotation, struct fb_var_screeninfo *var) {
+ Rotation rot;
+ if (rotation)
+ rot = *rotation;
+ else
+ rot = RR_Rotate_0;
+
+ var->xres = mode->HDisplay;
+ var->yres = mode->VDisplay;
+ var->xres_virtual = mode->HDisplay;
+ var->yres_virtual = mode->VDisplay;
+ var->xoffset = 0;
+ var->yoffset = 0;
+
+ var->pixclock = mode->Clock ? 1000000000 / mode->Clock : 0;
+ var->left_margin = mode->HTotal - mode->HSyncEnd;
+ var->right_margin = mode->HSyncStart - mode->HDisplay;
+ var->hsync_len = mode->HSyncEnd - mode->HSyncStart;
+ var->upper_margin = mode->VTotal - mode->VSyncEnd;
+ var->lower_margin = mode->VSyncStart - mode->VDisplay;
+ var->vsync_len = mode->VSyncEnd - mode->VSyncStart;
+
+ var->sync = 0;
+ var->vmode = 0;
+ if (rot) {
+ switch (*rotation) {
+ case RR_Rotate_0:
+ var->rotate = FB_ROTATE_UR;
+ break;
+ case RR_Rotate_90:
+ var->rotate = FB_ROTATE_CW;
+ break;
+ case RR_Rotate_180:
+ var->rotate = FB_ROTATE_UD;
+ break;
+ case RR_Rotate_270:
+ var->rotate = FB_ROTATE_CCW;
+ break;
+ }
+ }
+}
+
+Bool
+GlamoCrtcInit(ScrnInfoPtr pScrn) {
+ return xf86CrtcCreate(pScrn, &glamo_crtc_funcs) != NULL;
+}
+
+static void
+GlamoCrtcDPMS(xf86CrtcPtr crtc, int mode) {
+ fbdevHWDPMSSet(crtc->scrn, mode, 0);
+}
+
+static void GlamoCrtcGammaSet(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green,
+ CARD16 *blue, int size) {
+}
+
+static void GlamoCrtcDestroy(xf86CrtcPtr crtc) {
+}
+
+static Bool
+GlamoSetModeMajor(xf86CrtcPtr crtc, DisplayModePtr mode,
+ Rotation rotation, int x, int y) {
+ ScrnInfoPtr scrn = crtc->scrn;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ DisplayModeRec saved_mode;
+ int saved_x, saved_y;
+ Rotation saved_rotation;
+ GlamoPtr pGlamo = GlamoPTR(crtc->scrn);
+ Bool ret = FALSE;
+ int i;
+
+ struct fb_var_screeninfo var = pGlamo->fb_var;
+
+ crtc->enabled = xf86CrtcInUse (crtc);
+
+ if (!crtc->enabled)
+ return TRUE;
+
+ saved_mode = crtc->mode;
+ saved_x = crtc->x;
+ saved_y = crtc->y;
+ saved_rotation = crtc->rotation;
+
+ crtc->mode = *mode;
+ crtc->x = x;
+ crtc->y = y;
+ crtc->rotation = rotation;
+
+ crtc->funcs->dpms(crtc, DPMSModeOff);
+ for (i = 0; i < xf86_config->num_output; i++) {
+ xf86OutputPtr output = xf86_config->output[i];
+
+ if (output->crtc != crtc)
+ continue;
+
+ output->funcs->prepare(output);
+ }
+
+ ConvertModeXfreeToFb(mode, &rotation, &var);
+ /* FIXME: Shouldn't the kernel take care of this? */
+ if (rotation == RR_Rotate_90 || rotation == RR_Rotate_270) {
+ var.pixclock *= 2;
+ }
+
+ if (ioctl(pGlamo->fb_fd, FBIOPUT_VSCREENINFO, (void*)&var) != 0) {
+ goto done;
+ }
+
+ crtc->funcs->dpms (crtc, DPMSModeOn);
+ for (i = 0; i < xf86_config->num_output; i++)
+ {
+ xf86OutputPtr output = xf86_config->output[i];
+ if (output->crtc == crtc)
+ {
+ output->funcs->commit(output);
+#ifdef RANDR_12_INTERFACE
+ if (output->randr_output)
+ RRPostPendingProperties (output->randr_output);
+#endif
+ }
+ }
+
+ ret = TRUE;
+ if (scrn->pScreen)
+ xf86CrtcSetScreenSubpixelOrder (scrn->pScreen);
+
+done:
+ if (!ret) {
+ crtc->x = saved_x;
+ crtc->y = saved_y;
+ crtc->rotation = saved_rotation;
+ crtc->mode = saved_mode;
+ }
+
+ return ret;
+}
diff --git a/src/glamo-driver.c b/src/glamo-driver.c
index 787c6ab..c1db064 100644
--- a/src/glamo-driver.c
+++ b/src/glamo-driver.c
@@ -30,8 +30,17 @@
#include "xf86xv.h"
+#include "xf86i2c.h"
+#include "xf86Modes.h"
+#include "xf86Crtc.h"
+#include "xf86RandR12.h"
+
#include "glamo.h"
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
static Bool debug = 0;
#define TRACE_ENTER(str) \
@@ -51,18 +60,16 @@ static Bool GlamoPreInit(ScrnInfoPtr pScrn, int flags);
static Bool GlamoScreenInit(int Index, ScreenPtr pScreen, int argc,
char **argv);
static Bool GlamoCloseScreen(int scrnIndex, ScreenPtr pScreen);
-/*static void * GlamoWindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
- CARD32 *size, void *closure);*/
-static void GlamoPointerMoved(int index, int x, int y);
-static Bool GlamoDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op,
- pointer ptr);
-
-
-enum { Glamo_ROTATE_NONE=0, Glamo_ROTATE_CW=270, Glamo_ROTATE_UD=180, Glamo_ROTATE_CCW=90 };
-
-
+static Bool
+GlamoCrtcResize(ScrnInfoPtr scrn, int width, int height);
+static Bool
+GlamoInitFramebufferDevice(GlamoPtr pGlamo, const char *fb_device);
/* -------------------------------------------------------------------- */
+static const xf86CrtcConfigFuncsRec glamo_crtc_config_funcs = {
+ .resize = GlamoCrtcResize
+};
+
#define GLAMO_VERSION 1000
#define GLAMO_NAME "Glamo"
#define GLAMO_DRIVER_NAME "Glamo"
@@ -78,8 +85,7 @@ _X_EXPORT DriverRec Glamo = {
GlamoAvailableOptions,
NULL,
0,
- GlamoDriverFunc
-
+ NULL
};
/* Supported "chipsets" */
@@ -91,13 +97,11 @@ static SymTabRec GlamoChipsets[] = {
/* Supported options */
typedef enum {
OPTION_SHADOW_FB,
- OPTION_ROTATE,
OPTION_DEBUG
} GlamoOpts;
static const OptionInfoRec GlamoOptions[] = {
{ OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
- { OPTION_ROTATE, "Rotate", OPTV_STRING, {0}, FALSE },
{ OPTION_DEBUG, "debug", OPTV_BOOLEAN, {0}, FALSE },
{ -1, NULL, OPTV_NONE, {0}, FALSE }
};
@@ -124,8 +128,6 @@ static const char *shadowSymbols[] = {
static const char *fbdevHWSymbols[] = {
"fbdevHWInit",
"fbdevHWProbe",
- "fbdevHWSetVideoModes",
- "fbdevHWUseBuildinMode",
"fbdevHWGetDepth",
"fbdevHWGetLineLength",
@@ -145,12 +147,10 @@ static const char *fbdevHWSymbols[] = {
"fbdevHWAdjustFrameWeak",
"fbdevHWEnterVTWeak",
"fbdevHWLeaveVTWeak",
- "fbdevHWModeInit",
"fbdevHWRestore",
"fbdevHWSave",
"fbdevHWSaveScreen",
"fbdevHWSaveScreenWeak",
- "fbdevHWSwitchModeWeak",
"fbdevHWValidModeWeak",
"fbdevHWDPMSSet",
@@ -194,7 +194,7 @@ GlamoSetup(pointer module, pointer opts, int *errmaj, int *errmin)
if (!setupDone) {
setupDone = TRUE;
- xf86AddDriver(&Glamo, module, HaveDriverFuncs);
+ xf86AddDriver(&Glamo, module, 0);
LoaderRefSymLists(fbSymbols,
shadowSymbols, fbdevHWSymbols, exaSymbols, NULL);
return (pointer)1;
@@ -226,6 +226,20 @@ GlamoFreeRec(ScrnInfoPtr pScrn)
}
/* -------------------------------------------------------------------- */
+static Bool
+GlamoSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) {
+ ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+ xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR (pScrn);
+ xf86OutputPtr output = config->output[config->compat_output];
+ Rotation rotation;
+
+ if (output && output->crtc)
+ rotation = output->crtc->rotation;
+ else
+ rotation = RR_Rotate_0;
+
+ return xf86SetSingleMode(pScrn, mode, rotation);
+}
static const OptionInfoRec *
GlamoAvailableOptions(int chipid, int busid)
@@ -282,7 +296,7 @@ GlamoProbe(DriverPtr drv, int flags)
pScrn->Probe = GlamoProbe;
pScrn->PreInit = GlamoPreInit;
pScrn->ScreenInit = GlamoScreenInit;
- pScrn->SwitchMode = fbdevHWSwitchModeWeak();
+ pScrn->SwitchMode = GlamoSwitchMode;
pScrn->AdjustFrame = fbdevHWAdjustFrameWeak();
pScrn->EnterVT = fbdevHWEnterVTWeak();
pScrn->LeaveVT = fbdevHWLeaveVTWeak();
@@ -303,7 +317,7 @@ GlamoPreInit(ScrnInfoPtr pScrn, int flags)
{
GlamoPtr fPtr;
int default_depth, fbbpp;
- const char *s;
+ /*const char *s;*/
rgb weight_defaults = { 0, 0, 0 };
Gamma gamma_defaults = {0.0, 0.0, 0.0};
@@ -330,10 +344,14 @@ GlamoPreInit(ScrnInfoPtr pScrn, int flags)
if (!fbdevHWInit(pScrn,NULL,xf86FindOptionValue(fPtr->pEnt->device->options,"Glamo")))
return FALSE;
+ /* FIXME: Replace all fbdev functionality with our own code, so we only have
+ * to open the fb devic only once. */
+ if (!GlamoInitFramebufferDevice(fPtr, xf86FindOptionValue(fPtr->pEnt->device->options,"Glamo")))
+ return FALSE;
+
default_depth = fbdevHWGetDepth(pScrn,&fbbpp);
- if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp,
- Support24bppFb | Support32bppFb | SupportConvert32to24 | SupportConvert24to32))
+ if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp, 0))
return FALSE;
xf86PrintDepthBpp(pScrn);
@@ -358,6 +376,16 @@ GlamoPreInit(ScrnInfoPtr pScrn, int flags)
return FALSE;
}
+ xf86CrtcConfigInit(pScrn, &glamo_crtc_config_funcs);
+ xf86CrtcSetSizeRange(pScrn, 240, 320, 480, 640);
+ GlamoCrtcInit(pScrn);
+ GlamoOutputInit(pScrn);
+
+ if (!xf86InitialConfiguration(pScrn, TRUE)) {
+ xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
+ return FALSE;
+ }
+
pScrn->progClock = TRUE;
pScrn->chipset = "Glamo";
pScrn->videoRam = fbdevHWGetVidmem(pScrn);
@@ -377,61 +405,6 @@ GlamoPreInit(ScrnInfoPtr pScrn, int flags)
debug = xf86ReturnOptValBool(fPtr->Options, OPTION_DEBUG, FALSE);
- /* rotation */
- fPtr->rotate = Glamo_ROTATE_NONE;
- if ((s = xf86GetOptValString(fPtr->Options, OPTION_ROTATE)))
- {
- if(!xf86NameCmp(s, "CW"))
- {
- fPtr->shadowFB = TRUE;
- fPtr->rotate = Glamo_ROTATE_CW;
- xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
- "rotating screen clockwise\n");
- }
- else if(!xf86NameCmp(s, "CCW"))
- {
- fPtr->shadowFB = TRUE;
- fPtr->rotate = Glamo_ROTATE_CCW;
- xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
- "rotating screen counter-clockwise\n");
- }
- else if(!xf86NameCmp(s, "UD"))
- {
- fPtr->shadowFB = TRUE;
- fPtr->rotate = Glamo_ROTATE_UD;
- xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
- "rotating screen upside-down\n");
- }
- else
- {
- xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
- "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
- xf86DrvMsg(pScrn->scrnIndex, X_INFO,
- "valid options are \"CW\", \"CCW\" and \"UD\"\n");
- }
- }
-
- /* select video modes */
-
- xf86DrvMsg(pScrn->scrnIndex, X_INFO, "checking modes against framebuffer device...\n");
- fbdevHWSetVideoModes(pScrn);
-
- xf86DrvMsg(pScrn->scrnIndex, X_INFO, "checking modes against monitor...\n");
- {
- DisplayModePtr mode, first = mode = pScrn->modes;
-
- if (mode != NULL) do {
- mode->status = xf86CheckModeForMonitor(mode, pScrn->monitor);
- mode = mode->next;
- } while (mode != NULL && mode != first);
-
- xf86PruneDriverModes(pScrn);
- }
-
- if (NULL == pScrn->modes)
- fbdevHWUseBuildinMode(pScrn);
- pScrn->currentMode = pScrn->modes;
-
/* First approximation, may be refined in ScreenInit */
pScrn->displayWidth = pScrn->virtualX;
@@ -450,13 +423,13 @@ GlamoPreInit(ScrnInfoPtr pScrn, int flags)
return TRUE;
}
+
static Bool
GlamoScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
GlamoPtr fPtr = GlamoPTR(pScrn);
VisualPtr visual;
- int init_picture = 0;
int ret, flags;
TRACE_ENTER("GlamoScreenInit");
@@ -479,11 +452,6 @@ GlamoScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
fPtr->fboff = fbdevHWLinearOffset(pScrn);
fbdevHWSave(pScrn);
-
- if (!fbdevHWModeInit(pScrn, pScrn->currentMode)) {
- xf86DrvMsg(scrnIndex,X_ERROR,"mode initialization failed\n");
- return FALSE;
- }
fbdevHWSaveScreen(pScreen, SCREEN_SAVER_ON);
fbdevHWAdjustFrame(scrnIndex,0,0,0);
@@ -500,37 +468,15 @@ GlamoScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
return FALSE;
}
- if(fPtr->rotate==Glamo_ROTATE_CW || fPtr->rotate==Glamo_ROTATE_CCW)
- {
- int tmp = pScrn->virtualX;
- pScrn->virtualX = pScrn->displayWidth = pScrn->virtualY;
- pScrn->virtualY = tmp;
- } else {
- /* FIXME: this doesn't work for all cases, e.g. when each scanline
- has a padding which is independent from the depth (controlfb) */
- pScrn->displayWidth = fbdevHWGetLineLength(pScrn) /
+ pScrn->displayWidth = fbdevHWGetLineLength(pScrn) /
(pScrn->bitsPerPixel / 8);
- if (pScrn->displayWidth != pScrn->virtualX) {
- xf86DrvMsg(scrnIndex, X_INFO,
- "Pitch updated to %d after ModeInit\n",
- pScrn->displayWidth);
- }
- }
-
- if(fPtr->rotate && !fPtr->PointerMoved) {
- fPtr->PointerMoved = pScrn->PointerMoved;
- pScrn->PointerMoved = GlamoPointerMoved;
- }
-
fPtr->fbstart = fPtr->fbmem + fPtr->fboff;
ret = fbScreenInit(pScreen, fPtr->fbstart, pScrn->virtualX,
pScrn->virtualY, pScrn->xDpi,
pScrn->yDpi, pScrn->displayWidth,
pScrn->bitsPerPixel);
- init_picture = 1;
-
if (!ret)
return FALSE;
@@ -548,16 +494,10 @@ GlamoScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
}
/* must be after RGB ordering fixed */
- if (init_picture && !fbPictureInit(pScreen, NULL, 0))
+ if (!fbPictureInit(pScreen, NULL, 0))
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Render extension initialisation failed\n");
- if (fPtr->rotate) {
- xf86DrvMsg(scrnIndex, X_INFO, "using driver rotation; disabling "
- "XRandR\n");
- xf86DisableRandR();
- }
-
/* map in the registers */
fPtr->reg_base = xf86MapVidMem(pScreen->myNum, VIDMEM_MMIO, 0x8000000, 0x2400);
@@ -598,22 +538,19 @@ GlamoScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
NULL, flags))
return FALSE;
- xf86DPMSInit(pScreen, fbdevHWDPMSSetWeak(), 0);
- pScreen->SaveScreen = fbdevHWSaveScreenWeak();
+ xf86CrtcScreenInit(pScreen);
+ xf86RandR12SetRotations(pScreen, RR_Rotate_0 | RR_Rotate_90 |
+ RR_Rotate_180 | RR_Rotate_270);
- /* Wrap the current CloseScreen function */
- fPtr->CloseScreen = pScreen->CloseScreen;
- pScreen->CloseScreen = GlamoCloseScreen;
+ xf86DPMSInit(pScreen, xf86DPMSSet, 0);
- {
- XF86VideoAdaptorPtr *ptr;
+ pScreen->SaveScreen = xf86SaveScreen;
- int n = xf86XVListGenericAdaptors(pScrn,&ptr);
- if (n) {
- xf86XVScreenInit(pScreen,ptr,n);
- }
- }
+ xf86SetDesiredModes(pScrn);
+ /* Wrap the current CloseScreen function */
+ fPtr->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = GlamoCloseScreen;
TRACE_EXIT("GlamoScreenInit");
@@ -639,119 +576,57 @@ GlamoCloseScreen(int scrnIndex, ScreenPtr pScreen)
return (*pScreen->CloseScreen)(scrnIndex, pScreen);
}
-
-
-/***********************************************************************
- * Shadow stuff
- ***********************************************************************/
-#if 0
-static void *
-GlamoWindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
- CARD32 *size, void *closure)
-{
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- GlamoPtr fPtr = GlamoPTR(pScrn);
-
- if (!pScrn->vtSema)
- return NULL;
-
- if (fPtr->lineLength)
- *size = fPtr->lineLength;
- else
- *size = fPtr->lineLength = fbdevHWGetLineLength(pScrn);
-
- return ((CARD8 *)fPtr->fbstart + row * fPtr->lineLength + offset);
-}
-#endif
-static void
-GlamoPointerMoved(int index, int x, int y)
-{
- ScrnInfoPtr pScrn = xf86Screens[index];
- GlamoPtr fPtr = GlamoPTR(pScrn);
- int newX, newY;
-
- switch (fPtr->rotate)
- {
- case Glamo_ROTATE_CW:
- /* 90 degrees CW rotation. */
- newX = pScrn->pScreen->height - y - 1;
- newY = x;
- break;
-
- case Glamo_ROTATE_CCW:
- /* 90 degrees CCW rotation. */
- newX = y;
- newY = pScrn->pScreen->width - x - 1;
- break;
-
- case Glamo_ROTATE_UD:
- /* 180 degrees UD rotation. */
- newX = pScrn->pScreen->width - x - 1;
- newY = pScrn->pScreen->height - y - 1;
- break;
-
- default:
- /* No rotation. */
- newX = x;
- newY = y;
- break;
- }
-
- /* Pass adjusted pointer coordinates to wrapped PointerMoved function. */
- (*fPtr->PointerMoved)(index, newX, newY);
-}
-
static Bool
-GlamoRandRGetInfo(ScrnInfoPtr pScrn, Rotation *rotations)
-{
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "GlamoRandRGetInfo got here!\n");
-
- *rotations = RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_270;
+GlamoCrtcResize(ScrnInfoPtr pScrn, int width, int height) {
+ pScrn->virtualX = width;
+ pScrn->virtualY = height;
+ pScrn->displayWidth = width * (pScrn->bitsPerPixel / 8);
+ pScrn->pScreen->GetScreenPixmap(pScrn->pScreen)->devKind = pScrn->displayWidth;
return TRUE;
}
-static Bool
-GlamoRandRSetConfig(ScrnInfoPtr pScrn, xorgRRConfig *config)
-{
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "GlamoRandRSetConfig got here!\n");
-
- switch(config->rotation) {
- case RR_Rotate_0:
- break;
-
- case RR_Rotate_90:
- break;
- case RR_Rotate_270:
- break;
+static Bool
+GlamoInitFramebufferDevice(GlamoPtr pGlamo, const char *fb_device) {
+ if(fb_device) {
+ pGlamo->fb_fd = open(fb_device, O_RDWR, 0);
+ if (pGlamo->fb_fd == -1) {
+ ErrorF("Failed to open framebuffer device\n");
+ goto fail2;
+ }
+ } else {
+ fb_device = getenv("FRAMEBUFFER");
+ if (fb_device != NULL) {
+ pGlamo->fb_fd = open(fb_device, O_RDWR, 0);
+ if (pGlamo->fb_fd != -1)
+ fb_device = NULL;
+ }
+ if (fb_device == NULL) {
+ fb_device = "/dev/fb0";
+ pGlamo->fb_fd = open(fb_device, O_RDWR, 0);
+ if (pGlamo->fb_fd == -1) {
+ ErrorF("Failed to open framebuffer device\n");
+ goto fail2;
+ }
+ }
+ }
- default:
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "Unexpected rotation in GlamoRandRSetConfig!\n");
- return FALSE;
+ /* retrive current setting */
+ if (ioctl(pGlamo->fb_fd, FBIOGET_FSCREENINFO, (void*)(&pGlamo->fb_fix)) == -1) {
+ ErrorF("FBIOGET_FSCREENINFO\n");
+ goto fail1;
}
+ if (ioctl(pGlamo->fb_fd, FBIOGET_VSCREENINFO, (void*)(&pGlamo->fb_var)) == -1) {
+ ErrorF("FBIOGET_VSCREENINFO\n");
+ goto fail1;
+ }
return TRUE;
+fail1:
+ close(pGlamo->fb_fd);
+ pGlamo->fb_fd = -1;
+fail2:
+ return FALSE;
}
-static Bool
-GlamoDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr)
-{
- xorgHWFlags *flag;
-
- switch (op) {
- case GET_REQUIRED_HW_INTERFACES:
- flag = (CARD32*)ptr;
- (*flag) = 0;
- return TRUE;
- case RR_GET_INFO:
- return GlamoRandRGetInfo(pScrn, (Rotation*)ptr);
- case RR_SET_CONFIG:
- return GlamoRandRSetConfig(pScrn, (xorgRRConfig*)ptr);
- default:
- return FALSE;
- }
-}
diff --git a/src/glamo-output.c b/src/glamo-output.c
new file mode 100644
index 0000000..5a09ee0
--- /dev/null
+++ b/src/glamo-output.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2009 Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "xf86i2c.h"
+#include "xf86Crtc.h"
+
+#include "fbdevhw.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "glamo.h"
+
+static const char *display_state_switch_path = "/sys/bus/spi/devices/spi2.0/state";
+static const char *display_state_vga = "normal";
+static const char *display_state_qvga = "qvga-normal";
+
+static void GlamoOutputDPMS(xf86OutputPtr output, int mode) {}
+static xf86OutputStatus GlamoOutputDetect(xf86OutputPtr output);
+static Bool GlamoOutputModeFixup(xf86OutputPtr output, DisplayModePtr mode,
+ DisplayModePtr mode_adjusted);
+static void GlamoOutputPrepare(xf86OutputPtr output);
+static void GlamoOutputModeSet(xf86OutputPtr output, DisplayModePtr mode,
+ DisplayModePtr adjusted_mode);
+static int GlamoOutputModeValid(xf86OutputPtr output, DisplayModePtr mode);
+static Bool GlamoOutputModeFixup(xf86OutputPtr output, DisplayModePtr mode,
+ DisplayModePtr mode_adjusted);
+static void GlamoOutputPrepare(xf86OutputPtr output);
+static void GlamoOutputModeSet(xf86OutputPtr output, DisplayModePtr mode,
+ DisplayModePtr adjusted_mode);
+static void GlamoOutputCommit(xf86OutputPtr output);
+static void GlamoOutputDestroy(xf86OutputPtr output);
+static DisplayModePtr GlamoOutputGetModes(xf86OutputPtr output);
+
+static const xf86OutputFuncsRec glamo_output_funcs = {
+ .create_resources = NULL,
+ .dpms = GlamoOutputDPMS,
+ .save = NULL,
+ .restore = NULL,
+ .mode_valid = GlamoOutputModeValid,
+ .mode_fixup = GlamoOutputModeFixup,
+ .prepare = GlamoOutputPrepare,
+ .commit = GlamoOutputCommit,
+ .mode_set = GlamoOutputModeSet,
+ .detect = GlamoOutputDetect,
+ .get_modes = GlamoOutputGetModes,
+#ifdef RANDR_12_INTERFACE
+ .set_property = NULL,
+#endif
+ .destroy = GlamoOutputDestroy
+};
+
+void
+GlamoOutputInit(ScrnInfoPtr pScrn) {
+ xf86OutputPtr output;
+ output = xf86OutputCreate(pScrn, &glamo_output_funcs, "LCD");
+ output->possible_crtcs = 1;
+ output->possible_clones = 0;
+}
+
+static xf86OutputStatus
+GlamoOutputDetect(xf86OutputPtr output) {
+ return XF86OutputStatusConnected;
+}
+
+static int
+GlamoOutputModeValid(xf86OutputPtr output, DisplayModePtr mode) {
+ return MODE_OK;
+ /*return fbdevHWValidMode(output->scrn->scrnIndex, mode, FALSE, 0);*/
+}
+
+static Bool
+GlamoOutputModeFixup(xf86OutputPtr output, DisplayModePtr mode,
+ DisplayModePtr mode_adjusted) {
+ return TRUE;
+}
+
+static void
+GlamoOutputPrepare(xf86OutputPtr output) {
+}
+
+static void
+GlamoOutputModeSet(xf86OutputPtr output, DisplayModePtr mode,
+ DisplayModePtr adjusted_mode) {
+}
+
+static void
+GlamoOutputCommit(xf86OutputPtr output) {
+ int fd = open(display_state_switch_path, O_WRONLY);
+ if (fd != -1) {
+ if(output->crtc->mode.HDisplay == 240 && output->crtc->mode.VDisplay == 320)
+ write(fd, display_state_qvga, strlen(display_state_qvga));
+ else
+ write(fd, display_state_vga, strlen(display_state_vga));
+ close(fd);
+ } else {
+ xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+ "Couldn't open %s to change display resolution: %s\n",
+ display_state_switch_path, strerror(errno));
+ }
+}
+
+static void GlamoOutputDestroy(xf86OutputPtr output) {
+}
+
+static DisplayModePtr GlamoOutputGetModes(xf86OutputPtr output) {
+ GlamoPtr pGlamo = GlamoPTR(output->scrn);
+
+ output->mm_width = pGlamo->fb_var.width;
+ output->mm_height = pGlamo->fb_var.height;
+
+ return NULL;
+ /*return fbdevHWGetBuildinMode(output->scrn);*/
+}
+
diff --git a/src/glamo.h b/src/glamo.h
index d65019b..a8807d5 100644
--- a/src/glamo.h
+++ b/src/glamo.h
@@ -35,6 +35,7 @@
#include "xf86.h"
#include "exa.h"
+#include <linux/fb.h>
#define GLAMO_REG_BASE(c) ((c)->attr.address[0])
#define GLAMO_REG_SIZE(c) (0x2400)
@@ -108,11 +109,6 @@ typedef struct _MemBuf {
} MemBuf;
typedef struct {
- unsigned char* fbstart;
- unsigned char* fbmem;
- int fboff;
- int lineLength;
- int rotate;
Bool shadowFB;
void *shadow;
CloseScreenProcPtr CloseScreen;
@@ -155,6 +151,14 @@ typedef struct {
CARD32 crtc_pitch;
CARD32 crtc2_pitch;
+ /* linux framebuffer */
+ int fb_fd;
+ struct fb_var_screeninfo fb_var;
+ struct fb_fix_screeninfo fb_fix;
+ unsigned char *fbstart;
+ unsigned char *fbmem;
+ int fboff;
+ int lineLength;
} GlamoRec, *GlamoPtr;
#define GlamoPTR(p) ((GlamoPtr)((p)->driverPrivate))
@@ -195,4 +199,12 @@ GLAMORecolorCursor(ScreenPtr pScreen, int ndef, xColorItem *pdef);
Bool
GLAMODrawExaInit(ScreenPtr pScreen, ScrnInfoPtr pScrn);
+/* glamo-display.h */
+Bool
+GlamoCrtcInit(ScrnInfoPtr pScrn);
+
+/* glamo-output.h */
+void
+GlamoOutputInit(ScrnInfoPtr pScrn);
+
#endif /* _GLAMO_H_ */