Merge pull request #218 from saper/build-fixes
[envytools.git] / include / nouveau_pms.h
bloba9418a4f847ce7b10d1697b3ffbb3e94557ad496
1 /*
2 * Copyright 2010 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors: Ben Skeggs
26 #ifndef NOUVEAU_PMS_H
27 #define NOUVEAU_PMS_H
29 struct pms_ucode {
30 u8 data[256];
31 union {
32 u8 *u08;
33 u16 *u16;
34 u32 *u32;
35 } ptr;
36 u16 len;
38 u32 reg;
39 u32 val;
42 static inline void
43 pms_init(struct pms_ucode *pms)
45 pms->ptr.u08 = pms->data;
46 pms->reg = 0xffffffff;
47 pms->val = 0xffffffff;
50 static inline void
51 pms_fini(struct pms_ucode *pms)
53 do {
54 *pms->ptr.u08++ = 0x7f;
55 pms->len = pms->ptr.u08 - pms->data;
56 } while (pms->len & 3);
57 pms->ptr.u08 = pms->data;
60 static inline void
61 pms_unkn(struct pms_ucode *pms, u8 v0)
63 *pms->ptr.u08++ = v0;
66 static inline void
67 pms_op5f(struct pms_ucode *pms, u8 v0, u8 v1)
69 *pms->ptr.u08++ = 0x5f;
70 *pms->ptr.u08++ = v0;
71 *pms->ptr.u08++ = v1;
74 static inline void
75 pms_wr32(struct pms_ucode *pms, u32 reg, u32 val)
77 if (val != pms->val) {
78 if ((val & 0xffff0000) == (pms->val & 0xffff0000)) {
79 *pms->ptr.u08++ = 0x42;
80 *pms->ptr.u16++ = (val & 0x0000ffff);
81 } else {
82 *pms->ptr.u08++ = 0xe2;
83 *pms->ptr.u32++ = val;
86 pms->val = val;
89 if ((reg & 0xffff0000) == (pms->reg & 0xffff0000)) {
90 *pms->ptr.u08++ = 0x40;
91 *pms->ptr.u16++ = (reg & 0x0000ffff);
92 } else {
93 *pms->ptr.u08++ = 0xe0;
94 *pms->ptr.u32++ = reg;
96 pms->reg = reg;
99 #endif