summaryrefslogtreecommitdiff
path: root/tests/ttmtest/src/xf86dri.h
blob: 8fb78968e4b0a1b6d10306b40a98a439c8c75e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.8 2002/10/30 12:51:25 alanh Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
Copyright 2000 VA Linux Systems, Inc.
All Rights Reserved.

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 PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.

**************************************************************************/

/**
 * \file xf86dri.h
 * Protocol numbers and function prototypes for DRI X protocol.
 *
 * \author Kevin E. Martin <martin@valinux.com>
 * \author Jens Owen <jens@tungstengraphics.com>
 * \author Rickard E. (Rik) Faith <faith@valinux.com>
 */

#ifndef _XF86DRI_H_
#define _XF86DRI_H_

#include <X11/Xfuncproto.h>
#include <drm/drm.h>

#define X_XF86DRIQueryVersion			0
#define X_XF86DRIQueryDirectRenderingCapable	1
#define X_XF86DRIOpenConnection			2
#define X_XF86DRICloseConnection		3
#define X_XF86DRIGetClientDriverName		4
#define X_XF86DRICreateContext			5
#define X_XF86DRIDestroyContext			6
#define X_XF86DRICreateDrawable			7
#define X_XF86DRIDestroyDrawable		8
#define X_XF86DRIGetDrawableInfo		9
#define X_XF86DRIGetDeviceInfo			10
#define X_XF86DRIAuthConnection                 11
#define X_XF86DRIOpenFullScreen                 12	/* Deprecated */
#define X_XF86DRICloseFullScreen                13	/* Deprecated */

#define XF86DRINumberEvents		0

#define XF86DRIClientNotLocal		0
#define XF86DRIOperationNotSupported	1
#define XF86DRINumberErrors		(XF86DRIOperationNotSupported + 1)

#ifndef _XF86DRI_SERVER_

_XFUNCPROTOBEGIN
    Bool uniDRIQueryExtension(Display * dpy, int *event_base,
    int *error_base);

Bool uniDRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
    int *patchVersion);

Bool uniDRIQueryDirectRenderingCapable(Display * dpy, int screen,
    Bool * isCapable);

Bool uniDRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
    char **busIDString);

Bool uniDRIAuthConnection(Display * dpy, int screen, drm_magic_t magic);

Bool uniDRICloseConnection(Display * dpy, int screen);

Bool uniDRIGetClientDriverName(Display * dpy, int screen,
    int *ddxDriverMajorVersion, int *ddxDriverMinorVersion,
    int *ddxDriverPatchVersion, char **clientDriverName);

Bool uniDRICreateContext(Display * dpy, int screen, Visual * visual,
    XID * ptr_to_returned_context_id, drm_context_t * hHWContext);

Bool uniDRICreateContextWithConfig(Display * dpy, int screen, int configID,
    XID * ptr_to_returned_context_id, drm_context_t * hHWContext);

extern Bool uniDRIDestroyContext(Display * dpy, int screen, XID context_id);

extern Bool uniDRICreateDrawable(Display * dpy, int screen,
    Drawable drawable, drm_drawable_t * hHWDrawable);

extern Bool uniDRIDestroyDrawable(Display * dpy, int screen,
    Drawable drawable);

Bool uniDRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
    unsigned int *index, unsigned int *stamp,
    int *X, int *Y, int *W, int *H,
    int *numClipRects, drm_clip_rect_t ** pClipRects,
    int *backX, int *backY,
    int *numBackClipRects, drm_clip_rect_t ** pBackClipRects);

Bool uniDRIGetDeviceInfo(Display * dpy, int screen,
    drm_handle_t * hFrameBuffer, int *fbOrigin, int *fbSize,
    int *fbStride, int *devPrivateSize, void **pDevPrivate);

_XFUNCPROTOEND
#endif /* _XF86DRI_SERVER_ */
#endif /* _XF86DRI_H_ */
0x35 #define CH7xxx_TLPF 0x36 #define CH7xxx_TCT 0x37 #define CH7301_TEST_PATTERN 0x48 #define CH7xxx_PM 0x49 #define CH7xxx_PM_FPD (1<<0) #define CH7301_PM_DACPD0 (1<<1) #define CH7301_PM_DACPD1 (1<<2) #define CH7301_PM_DACPD2 (1<<3) #define CH7xxx_PM_DVIL (1<<6) #define CH7xxx_PM_DVIP (1<<7) #define CH7301_SYNC_POLARITY 0x56 #define CH7301_SYNC_RGB_YUV (1<<0) #define CH7301_SYNC_POL_DVI (1<<5) /** @file * driver for the Chrontel 7xxx DVI chip over DVO. */ static struct ch7xxx_id_struct { uint8_t vid; char *name; } ch7xxx_ids[] = { { CH7011_VID, "CH7011" }, { CH7009A_VID, "CH7009A" }, { CH7009B_VID, "CH7009B" }, { CH7301_VID, "CH7301" }, }; struct ch7xxx_reg_state { uint8_t regs[CH7xxx_NUM_REGS]; }; struct ch7xxx_priv { bool quiet; struct ch7xxx_reg_state save_reg; struct ch7xxx_reg_state mode_reg; uint8_t save_TCTL, save_TPCP, save_TPD, save_TPVT; uint8_t save_TLPF, save_TCT, save_PM, save_IDF; }; static void ch7xxx_save(struct intel_dvo_device *dvo); static char *ch7xxx_get_id(uint8_t vid) { int i; for (i = 0; i < ARRAY_SIZE(ch7xxx_ids); i++) { if (ch7xxx_ids[i].vid == vid) return ch7xxx_ids[i].name; } return NULL; } /** Reads an 8 bit register */ static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) { struct ch7xxx_priv *ch7xxx= dvo->dev_priv; struct intel_i2c_chan *i2cbus = dvo->i2c_bus; u8 out_buf[2]; u8 in_buf[2]; struct i2c_msg msgs[] = { { .addr = i2cbus->slave_addr, .flags = 0, .len = 1, .buf = out_buf, }, { .addr = i2cbus->slave_addr, .flags = I2C_M_RD, .len = 1, .buf = in_buf, } }; out_buf[0] = addr; out_buf[1] = 0; if (i2c_transfer(&i2cbus->adapter, msgs, 2) == 2) { *ch = in_buf[0]; return true; }; if (!ch7xxx->quiet) { DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", addr, i2cbus->adapter.name, i2cbus->slave_addr); } return false; } /** Writes an 8 bit register */ static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) { struct ch7xxx_priv *ch7xxx = dvo->dev_priv; struct intel_i2c_chan *i2cbus = dvo->i2c_bus; uint8_t out_buf[2]; struct i2c_msg msg = { .addr = i2cbus->slave_addr, .flags = 0, .len = 2, .buf = out_buf, }; out_buf[0] = addr; out_buf[1] = ch; if (i2c_transfer(&i2cbus->adapter, &msg, 1) == 1) return true; if (!ch7xxx->quiet) { DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", addr, i2cbus->adapter.name, i2cbus->slave_addr); } return false; } static bool ch7xxx_init(struct intel_dvo_device *dvo, struct intel_i2c_chan *i2cbus) { /* this will detect the CH7xxx chip on the specified i2c bus */ struct ch7xxx_priv *ch7xxx; uint8_t vendor, device; char *name; ch7xxx = kzalloc(sizeof(struct ch7xxx_priv), GFP_KERNEL); if (ch7xxx == NULL) return false; dvo->i2c_bus = i2cbus; dvo->i2c_bus->slave_addr = dvo->slave_addr; dvo->dev_priv = ch7xxx; ch7xxx->quiet = true; if (!ch7xxx_readb(dvo, CH7xxx_REG_VID, &vendor)) goto out; name = ch7xxx_get_id(vendor); if (!name) { DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n", vendor, i2cbus->adapter.name, i2cbus->slave_addr); goto out; } if (!ch7xxx_readb(dvo, CH7xxx_REG_DID, &device)) goto out; if (device != CH7xxx_DID) { DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n", vendor, i2cbus->adapter.name, i2cbus->slave_addr); goto out; } ch7xxx->quiet = false; DRM_DEBUG("Detected %s chipset, vendor/device ID 0x%02x/0x%02x\n", name, vendor, device); return true; out: kfree(ch7xxx); return false; } static enum drm_connector_status ch7xxx_detect(struct intel_dvo_device *dvo) { uint8_t cdet, orig_pm, pm; ch7xxx_readb(dvo, CH7xxx_PM, &orig_pm); pm = orig_pm; pm &= ~CH7xxx_PM_FPD; pm |= CH7xxx_PM_DVIL | CH7xxx_PM_DVIP; ch7xxx_writeb(dvo, CH7xxx_PM, pm); ch7xxx_readb(dvo, CH7xxx_CONNECTION_DETECT, &cdet); ch7xxx_writeb(dvo, CH7xxx_PM, orig_pm); if (cdet & CH7xxx_CDET_DVI) return connector_status_connected; return connector_status_disconnected; } static enum drm_mode_status ch7xxx_mode_valid(struct intel_dvo_device *dvo, struct drm_display_mode *mode) { if (mode->clock > 165000) return MODE_CLOCK_HIGH; return MODE_OK; } static void ch7xxx_mode_set(struct intel_dvo_device *dvo, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { uint8_t tvco, tpcp, tpd, tlpf, idf; if (mode->clock <= 65000) { tvco = 0x23; tpcp = 0x08; tpd = 0x16; tlpf = 0x60; } else { tvco = 0x2d; tpcp = 0x06; tpd = 0x26; tlpf = 0xa0; } ch7xxx_writeb(dvo, CH7xxx_TCTL, 0x00); ch7xxx_writeb(dvo, CH7xxx_TVCO, tvco); ch7xxx_writeb(dvo, CH7xxx_TPCP, tpcp); ch7xxx_writeb(dvo, CH7xxx_TPD, tpd); ch7xxx_writeb(dvo, CH7xxx_TPVT, 0x30); ch7xxx_writeb(dvo, CH7xxx_TLPF, tlpf); ch7xxx_writeb(dvo, CH7xxx_TCT, 0x00); ch7xxx_readb(dvo, CH7xxx_IDF, &idf); idf &= ~(CH7xxx_IDF_HSP | CH7xxx_IDF_VSP); if (mode->flags & DRM_MODE_FLAG_PHSYNC) idf |= CH7xxx_IDF_HSP; if (mode->flags & DRM_MODE_FLAG_PVSYNC) idf |= CH7xxx_IDF_HSP; ch7xxx_writeb(dvo, CH7xxx_IDF, idf); } /* set the CH7xxx power state */ static void ch7xxx_dpms(struct intel_dvo_device *dvo, int mode) { if (mode == DRM_MODE_DPMS_ON) ch7xxx_writeb(dvo, CH7xxx_PM, CH7xxx_PM_DVIL | CH7xxx_PM_DVIP); else ch7xxx_writeb(dvo, CH7xxx_PM, CH7xxx_PM_FPD); } static void ch7xxx_dump_regs(struct intel_dvo_device *dvo) { struct ch7xxx_priv *ch7xxx = dvo->dev_priv; int i; for (i = 0; i < CH7xxx_NUM_REGS; i++) { if ((i % 8) == 0 ) DRM_DEBUG("\n %02X: ", i); DRM_DEBUG("%02X ", ch7xxx->mode_reg.regs[i]); } } static void ch7xxx_save(struct intel_dvo_device *dvo) { struct ch7xxx_priv *ch7xxx= dvo->dev_priv; ch7xxx_readb(dvo, CH7xxx_TCTL, &ch7xxx->save_TCTL); ch7xxx_readb(dvo, CH7xxx_TPCP, &ch7xxx->save_TPCP); ch7xxx_readb(dvo, CH7xxx_TPD, &ch7xxx->save_TPD); ch7xxx_readb(dvo, CH7xxx_TPVT, &ch7xxx->save_TPVT); ch7xxx_readb(dvo, CH7xxx_TLPF, &ch7xxx->save_TLPF); ch7xxx_readb(dvo, CH7xxx_PM, &ch7xxx->save_PM); ch7xxx_readb(dvo, CH7xxx_IDF, &ch7xxx->save_IDF); } static void ch7xxx_restore(struct intel_dvo_device *dvo) { struct ch7xxx_priv *ch7xxx = dvo->dev_priv; ch7xxx_writeb(dvo, CH7xxx_TCTL, ch7xxx->save_TCTL); ch7xxx_writeb(dvo, CH7xxx_TPCP, ch7xxx->save_TPCP); ch7xxx_writeb(dvo, CH7xxx_TPD, ch7xxx->save_TPD); ch7xxx_writeb(dvo, CH7xxx_TPVT, ch7xxx->save_TPVT); ch7xxx_writeb(dvo, CH7xxx_TLPF, ch7xxx->save_TLPF); ch7xxx_writeb(dvo, CH7xxx_IDF, ch7xxx->save_IDF); ch7xxx_writeb(dvo, CH7xxx_PM, ch7xxx->save_PM); } static void ch7xxx_destroy(struct intel_dvo_device *dvo) { struct ch7xxx_priv *ch7xxx = dvo->dev_priv; if (ch7xxx) { kfree(ch7xxx); dvo->dev_priv = NULL; } } struct intel_dvo_dev_ops ch7xxx_ops = { .init = ch7xxx_init, .detect = ch7xxx_detect, .mode_valid = ch7xxx_mode_valid, .mode_set = ch7xxx_mode_set, .dpms = ch7xxx_dpms, .dump_regs = ch7xxx_dump_regs, .save = ch7xxx_save, .restore = ch7xxx_restore, .destroy = ch7xxx_destroy, };