xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/i915/display/dvo_ns2501.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright (c) 2012 Gilles Dartiguelongue, Thomas Richter
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * All Rights Reserved.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
8*4882a593Smuzhiyun  * copy of this software and associated documentation files (the
9*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
10*4882a593Smuzhiyun  * without limitation the rights to use, copy, modify, merge, publish,
11*4882a593Smuzhiyun  * distribute, sub license, and/or sell copies of the Software, and to
12*4882a593Smuzhiyun  * permit persons to whom the Software is furnished to do so, subject to
13*4882a593Smuzhiyun  * the following conditions:
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
16*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial portions
17*4882a593Smuzhiyun  * of the Software.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20*4882a593Smuzhiyun  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22*4882a593Smuzhiyun  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
23*4882a593Smuzhiyun  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24*4882a593Smuzhiyun  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25*4882a593Smuzhiyun  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #include "i915_drv.h"
30*4882a593Smuzhiyun #include "i915_reg.h"
31*4882a593Smuzhiyun #include "intel_display_types.h"
32*4882a593Smuzhiyun #include "intel_dvo_dev.h"
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #define NS2501_VID 0x1305
35*4882a593Smuzhiyun #define NS2501_DID 0x6726
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #define NS2501_VID_LO 0x00
38*4882a593Smuzhiyun #define NS2501_VID_HI 0x01
39*4882a593Smuzhiyun #define NS2501_DID_LO 0x02
40*4882a593Smuzhiyun #define NS2501_DID_HI 0x03
41*4882a593Smuzhiyun #define NS2501_REV 0x04
42*4882a593Smuzhiyun #define NS2501_RSVD 0x05
43*4882a593Smuzhiyun #define NS2501_FREQ_LO 0x06
44*4882a593Smuzhiyun #define NS2501_FREQ_HI 0x07
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define NS2501_REG8 0x08
47*4882a593Smuzhiyun #define NS2501_8_VEN (1<<5)
48*4882a593Smuzhiyun #define NS2501_8_HEN (1<<4)
49*4882a593Smuzhiyun #define NS2501_8_DSEL (1<<3)
50*4882a593Smuzhiyun #define NS2501_8_BPAS (1<<2)
51*4882a593Smuzhiyun #define NS2501_8_RSVD (1<<1)
52*4882a593Smuzhiyun #define NS2501_8_PD (1<<0)
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #define NS2501_REG9 0x09
55*4882a593Smuzhiyun #define NS2501_9_VLOW (1<<7)
56*4882a593Smuzhiyun #define NS2501_9_MSEL_MASK (0x7<<4)
57*4882a593Smuzhiyun #define NS2501_9_TSEL (1<<3)
58*4882a593Smuzhiyun #define NS2501_9_RSEN (1<<2)
59*4882a593Smuzhiyun #define NS2501_9_RSVD (1<<1)
60*4882a593Smuzhiyun #define NS2501_9_MDI (1<<0)
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun #define NS2501_REGC 0x0c
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /*
65*4882a593Smuzhiyun  * The following registers are not part of the official datasheet
66*4882a593Smuzhiyun  * and are the result of reverse engineering.
67*4882a593Smuzhiyun  */
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun  * Register c0 controls how the DVO synchronizes with
71*4882a593Smuzhiyun  * its input.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun #define NS2501_REGC0 0xc0
74*4882a593Smuzhiyun #define NS2501_C0_ENABLE (1<<0)	/* enable the DVO sync in general */
75*4882a593Smuzhiyun #define NS2501_C0_HSYNC (1<<1)	/* synchronize horizontal with input */
76*4882a593Smuzhiyun #define NS2501_C0_VSYNC (1<<2)	/* synchronize vertical with input */
77*4882a593Smuzhiyun #define NS2501_C0_RESET (1<<7)	/* reset the synchronization flip/flops */
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /*
80*4882a593Smuzhiyun  * Register 41 is somehow related to the sync register and sync
81*4882a593Smuzhiyun  * configuration. It should be 0x32 whenever regC0 is 0x05 (hsync off)
82*4882a593Smuzhiyun  * and 0x00 otherwise.
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun #define NS2501_REG41 0x41
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /*
87*4882a593Smuzhiyun  * this register controls the dithering of the DVO
88*4882a593Smuzhiyun  * One bit enables it, the other define the dithering depth.
89*4882a593Smuzhiyun  * The higher the value, the lower the dithering depth.
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun #define NS2501_F9_REG 0xf9
92*4882a593Smuzhiyun #define NS2501_F9_ENABLE (1<<0)		/* if set, dithering is enabled */
93*4882a593Smuzhiyun #define NS2501_F9_DITHER_MASK (0x7f<<1)	/* controls the dither depth */
94*4882a593Smuzhiyun #define NS2501_F9_DITHER_SHIFT 1	/* shifts the dither mask */
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /*
97*4882a593Smuzhiyun  * PLL configuration register. This is a pair of registers,
98*4882a593Smuzhiyun  * one single byte register at 1B, and a pair at 1C,1D.
99*4882a593Smuzhiyun  * These registers are counters/dividers.
100*4882a593Smuzhiyun  */
101*4882a593Smuzhiyun #define NS2501_REG1B 0x1b /* one byte PLL control register */
102*4882a593Smuzhiyun #define NS2501_REG1C 0x1c /* low-part of the second register */
103*4882a593Smuzhiyun #define NS2501_REG1D 0x1d /* high-part of the second register */
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun  * Scaler control registers. Horizontal at b8,b9,
107*4882a593Smuzhiyun  * vertical at 10,11. The scale factor is computed as
108*4882a593Smuzhiyun  * 2^16/control-value. The low-byte comes first.
109*4882a593Smuzhiyun  */
110*4882a593Smuzhiyun #define NS2501_REG10 0x10 /* low-byte vertical scaler */
111*4882a593Smuzhiyun #define NS2501_REG11 0x11 /* high-byte vertical scaler */
112*4882a593Smuzhiyun #define NS2501_REGB8 0xb8 /* low-byte horizontal scaler */
113*4882a593Smuzhiyun #define NS2501_REGB9 0xb9 /* high-byte horizontal scaler */
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /*
116*4882a593Smuzhiyun  * Display window definition. This consists of four registers
117*4882a593Smuzhiyun  * per dimension. One register pair defines the start of the
118*4882a593Smuzhiyun  * display, one the end.
119*4882a593Smuzhiyun  * As far as I understand, this defines the window within which
120*4882a593Smuzhiyun  * the scaler samples the input.
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun #define NS2501_REGC1 0xc1 /* low-byte horizontal display start */
123*4882a593Smuzhiyun #define NS2501_REGC2 0xc2 /* high-byte horizontal display start */
124*4882a593Smuzhiyun #define NS2501_REGC3 0xc3 /* low-byte horizontal display stop */
125*4882a593Smuzhiyun #define NS2501_REGC4 0xc4 /* high-byte horizontal display stop */
126*4882a593Smuzhiyun #define NS2501_REGC5 0xc5 /* low-byte vertical display start */
127*4882a593Smuzhiyun #define NS2501_REGC6 0xc6 /* high-byte vertical display start */
128*4882a593Smuzhiyun #define NS2501_REGC7 0xc7 /* low-byte vertical display stop */
129*4882a593Smuzhiyun #define NS2501_REGC8 0xc8 /* high-byte vertical display stop */
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /*
132*4882a593Smuzhiyun  * The following register pair seems to define the start of
133*4882a593Smuzhiyun  * the vertical sync. If automatic syncing is enabled, and the
134*4882a593Smuzhiyun  * register value defines a sync pulse that is later than the
135*4882a593Smuzhiyun  * incoming sync, then the register value is ignored and the
136*4882a593Smuzhiyun  * external hsync triggers the synchronization.
137*4882a593Smuzhiyun  */
138*4882a593Smuzhiyun #define NS2501_REG80 0x80 /* low-byte vsync-start */
139*4882a593Smuzhiyun #define NS2501_REG81 0x81 /* high-byte vsync-start */
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /*
142*4882a593Smuzhiyun  * The following register pair seems to define the total number
143*4882a593Smuzhiyun  * of lines created at the output side of the scaler.
144*4882a593Smuzhiyun  * This is again a low-high register pair.
145*4882a593Smuzhiyun  */
146*4882a593Smuzhiyun #define NS2501_REG82 0x82 /* output display height, low byte */
147*4882a593Smuzhiyun #define NS2501_REG83 0x83 /* output display height, high byte */
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /*
150*4882a593Smuzhiyun  * The following registers define the end of the front-porch
151*4882a593Smuzhiyun  * in horizontal and vertical position and hence allow to shift
152*4882a593Smuzhiyun  * the image left/right or up/down.
153*4882a593Smuzhiyun  */
154*4882a593Smuzhiyun #define NS2501_REG98 0x98 /* horizontal start of display + 256, low */
155*4882a593Smuzhiyun #define NS2501_REG99 0x99 /* horizontal start of display + 256, high */
156*4882a593Smuzhiyun #define NS2501_REG8E 0x8e /* vertical start of the display, low byte */
157*4882a593Smuzhiyun #define NS2501_REG8F 0x8f /* vertical start of the display, high byte */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /*
160*4882a593Smuzhiyun  * The following register pair control the function of the
161*4882a593Smuzhiyun  * backlight and the DVO output. To enable the corresponding
162*4882a593Smuzhiyun  * function, the corresponding bit must be set in both registers.
163*4882a593Smuzhiyun  */
164*4882a593Smuzhiyun #define NS2501_REG34 0x34 /* DVO enable functions, first register */
165*4882a593Smuzhiyun #define NS2501_REG35 0x35 /* DVO enable functions, second register */
166*4882a593Smuzhiyun #define NS2501_34_ENABLE_OUTPUT (1<<0) /* enable DVO output */
167*4882a593Smuzhiyun #define NS2501_34_ENABLE_BACKLIGHT (1<<1) /* enable backlight */
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /*
170*4882a593Smuzhiyun  * Registers 9C and 9D define the vertical output offset
171*4882a593Smuzhiyun  * of the visible region.
172*4882a593Smuzhiyun  */
173*4882a593Smuzhiyun #define NS2501_REG9C 0x9c
174*4882a593Smuzhiyun #define NS2501_REG9D 0x9d
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun /*
177*4882a593Smuzhiyun  * The register 9F defines the dithering. This requires the
178*4882a593Smuzhiyun  * scaler to be ON. Bit 0 enables dithering, the remaining
179*4882a593Smuzhiyun  * bits control the depth of the dither. The higher the value,
180*4882a593Smuzhiyun  * the LOWER the dithering amplitude. A good value seems to be
181*4882a593Smuzhiyun  * 15 (total register value).
182*4882a593Smuzhiyun  */
183*4882a593Smuzhiyun #define NS2501_REGF9 0xf9
184*4882a593Smuzhiyun #define NS2501_F9_ENABLE_DITHER (1<<0) /* enable dithering */
185*4882a593Smuzhiyun #define NS2501_F9_DITHER_MASK (0x7f<<1) /* dither masking */
186*4882a593Smuzhiyun #define NS2501_F9_DITHER_SHIFT 1	/* upshift of the dither mask */
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun enum {
189*4882a593Smuzhiyun 	MODE_640x480,
190*4882a593Smuzhiyun 	MODE_800x600,
191*4882a593Smuzhiyun 	MODE_1024x768,
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun struct ns2501_reg {
195*4882a593Smuzhiyun 	u8 offset;
196*4882a593Smuzhiyun 	u8 value;
197*4882a593Smuzhiyun };
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun /*
200*4882a593Smuzhiyun  * The following structure keeps the complete configuration of
201*4882a593Smuzhiyun  * the DVO, given a specific output configuration.
202*4882a593Smuzhiyun  * This is pretty much guess-work from reverse-engineering, so
203*4882a593Smuzhiyun  * read all this with a grain of salt.
204*4882a593Smuzhiyun  */
205*4882a593Smuzhiyun struct ns2501_configuration {
206*4882a593Smuzhiyun 	u8 sync;		/* configuration of the C0 register */
207*4882a593Smuzhiyun 	u8 conf;		/* configuration register 8 */
208*4882a593Smuzhiyun 	u8 syncb;		/* configuration register 41 */
209*4882a593Smuzhiyun 	u8 dither;		/* configuration of the dithering */
210*4882a593Smuzhiyun 	u8 pll_a;		/* PLL configuration, register A, 1B */
211*4882a593Smuzhiyun 	u16 pll_b;		/* PLL configuration, register B, 1C/1D */
212*4882a593Smuzhiyun 	u16 hstart;		/* horizontal start, registers C1/C2 */
213*4882a593Smuzhiyun 	u16 hstop;		/* horizontal total, registers C3/C4 */
214*4882a593Smuzhiyun 	u16 vstart;		/* vertical start, registers C5/C6 */
215*4882a593Smuzhiyun 	u16 vstop;		/* vertical total, registers C7/C8 */
216*4882a593Smuzhiyun 	u16 vsync;		/* manual vertical sync start, 80/81 */
217*4882a593Smuzhiyun 	u16 vtotal;		/* number of lines generated, 82/83 */
218*4882a593Smuzhiyun 	u16 hpos;		/* horizontal position + 256, 98/99  */
219*4882a593Smuzhiyun 	u16 vpos;		/* vertical position, 8e/8f */
220*4882a593Smuzhiyun 	u16 voffs;		/* vertical output offset, 9c/9d */
221*4882a593Smuzhiyun 	u16 hscale;		/* horizontal scaling factor, b8/b9 */
222*4882a593Smuzhiyun 	u16 vscale;		/* vertical scaling factor, 10/11 */
223*4882a593Smuzhiyun };
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun /*
226*4882a593Smuzhiyun  * DVO configuration values, partially based on what the BIOS
227*4882a593Smuzhiyun  * of the Fujitsu Lifebook S6010 writes into registers,
228*4882a593Smuzhiyun  * partially found by manual tweaking. These configurations assume
229*4882a593Smuzhiyun  * a 1024x768 panel.
230*4882a593Smuzhiyun  */
231*4882a593Smuzhiyun static const struct ns2501_configuration ns2501_modes[] = {
232*4882a593Smuzhiyun 	[MODE_640x480] = {
233*4882a593Smuzhiyun 		.sync	= NS2501_C0_ENABLE | NS2501_C0_VSYNC,
234*4882a593Smuzhiyun 		.conf	= NS2501_8_VEN | NS2501_8_HEN | NS2501_8_PD,
235*4882a593Smuzhiyun 		.syncb	= 0x32,
236*4882a593Smuzhiyun 		.dither	= 0x0f,
237*4882a593Smuzhiyun 		.pll_a	= 17,
238*4882a593Smuzhiyun 		.pll_b	= 852,
239*4882a593Smuzhiyun 		.hstart	= 144,
240*4882a593Smuzhiyun 		.hstop	= 783,
241*4882a593Smuzhiyun 		.vstart	= 22,
242*4882a593Smuzhiyun 		.vstop	= 514,
243*4882a593Smuzhiyun 		.vsync	= 2047, /* actually, ignored with this config */
244*4882a593Smuzhiyun 		.vtotal	= 1341,
245*4882a593Smuzhiyun 		.hpos	= 0,
246*4882a593Smuzhiyun 		.vpos	= 16,
247*4882a593Smuzhiyun 		.voffs	= 36,
248*4882a593Smuzhiyun 		.hscale	= 40960,
249*4882a593Smuzhiyun 		.vscale	= 40960
250*4882a593Smuzhiyun 	},
251*4882a593Smuzhiyun 	[MODE_800x600] = {
252*4882a593Smuzhiyun 		.sync	= NS2501_C0_ENABLE |
253*4882a593Smuzhiyun 			  NS2501_C0_HSYNC | NS2501_C0_VSYNC,
254*4882a593Smuzhiyun 		.conf   = NS2501_8_VEN | NS2501_8_HEN | NS2501_8_PD,
255*4882a593Smuzhiyun 		.syncb	= 0x00,
256*4882a593Smuzhiyun 		.dither	= 0x0f,
257*4882a593Smuzhiyun 		.pll_a	= 25,
258*4882a593Smuzhiyun 		.pll_b	= 612,
259*4882a593Smuzhiyun 		.hstart	= 215,
260*4882a593Smuzhiyun 		.hstop	= 1016,
261*4882a593Smuzhiyun 		.vstart	= 26,
262*4882a593Smuzhiyun 		.vstop	= 627,
263*4882a593Smuzhiyun 		.vsync	= 807,
264*4882a593Smuzhiyun 		.vtotal	= 1341,
265*4882a593Smuzhiyun 		.hpos	= 0,
266*4882a593Smuzhiyun 		.vpos	= 4,
267*4882a593Smuzhiyun 		.voffs	= 35,
268*4882a593Smuzhiyun 		.hscale	= 51248,
269*4882a593Smuzhiyun 		.vscale	= 51232
270*4882a593Smuzhiyun 	},
271*4882a593Smuzhiyun 	[MODE_1024x768] = {
272*4882a593Smuzhiyun 		.sync	= NS2501_C0_ENABLE | NS2501_C0_VSYNC,
273*4882a593Smuzhiyun 		.conf   = NS2501_8_VEN | NS2501_8_HEN | NS2501_8_PD,
274*4882a593Smuzhiyun 		.syncb	= 0x32,
275*4882a593Smuzhiyun 		.dither	= 0x0f,
276*4882a593Smuzhiyun 		.pll_a	= 11,
277*4882a593Smuzhiyun 		.pll_b	= 1350,
278*4882a593Smuzhiyun 		.hstart	= 276,
279*4882a593Smuzhiyun 		.hstop	= 1299,
280*4882a593Smuzhiyun 		.vstart	= 15,
281*4882a593Smuzhiyun 		.vstop	= 1056,
282*4882a593Smuzhiyun 		.vsync	= 2047,
283*4882a593Smuzhiyun 		.vtotal	= 1341,
284*4882a593Smuzhiyun 		.hpos	= 0,
285*4882a593Smuzhiyun 		.vpos	= 7,
286*4882a593Smuzhiyun 		.voffs	= 27,
287*4882a593Smuzhiyun 		.hscale	= 65535,
288*4882a593Smuzhiyun 		.vscale	= 65535
289*4882a593Smuzhiyun 	}
290*4882a593Smuzhiyun };
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun /*
293*4882a593Smuzhiyun  * Other configuration values left by the BIOS of the
294*4882a593Smuzhiyun  * Fujitsu S6010 in the DVO control registers. Their
295*4882a593Smuzhiyun  * value does not depend on the BIOS and their meaning
296*4882a593Smuzhiyun  * is unknown.
297*4882a593Smuzhiyun  */
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun static const struct ns2501_reg mode_agnostic_values[] = {
300*4882a593Smuzhiyun 	/* 08 is mode specific */
301*4882a593Smuzhiyun 	[0] = { .offset = 0x0a, .value = 0x81, },
302*4882a593Smuzhiyun 	/* 10,11 are part of the mode specific configuration */
303*4882a593Smuzhiyun 	[1] = { .offset = 0x12, .value = 0x02, },
304*4882a593Smuzhiyun 	[2] = { .offset = 0x18, .value = 0x07, },
305*4882a593Smuzhiyun 	[3] = { .offset = 0x19, .value = 0x00, },
306*4882a593Smuzhiyun 	[4] = { .offset = 0x1a, .value = 0x00, }, /* PLL?, ignored */
307*4882a593Smuzhiyun 	/* 1b,1c,1d are part of the mode specific configuration */
308*4882a593Smuzhiyun 	[5] = { .offset = 0x1e, .value = 0x02, },
309*4882a593Smuzhiyun 	[6] = { .offset = 0x1f, .value = 0x40, },
310*4882a593Smuzhiyun 	[7] = { .offset = 0x20, .value = 0x00, },
311*4882a593Smuzhiyun 	[8] = { .offset = 0x21, .value = 0x00, },
312*4882a593Smuzhiyun 	[9] = { .offset = 0x22, .value = 0x00, },
313*4882a593Smuzhiyun 	[10] = { .offset = 0x23, .value = 0x00, },
314*4882a593Smuzhiyun 	[11] = { .offset = 0x24, .value = 0x00, },
315*4882a593Smuzhiyun 	[12] = { .offset = 0x25, .value = 0x00, },
316*4882a593Smuzhiyun 	[13] = { .offset = 0x26, .value = 0x00, },
317*4882a593Smuzhiyun 	[14] = { .offset = 0x27, .value = 0x00, },
318*4882a593Smuzhiyun 	[15] = { .offset = 0x7e, .value = 0x18, },
319*4882a593Smuzhiyun 	/* 80-84 are part of the mode-specific configuration */
320*4882a593Smuzhiyun 	[16] = { .offset = 0x84, .value = 0x00, },
321*4882a593Smuzhiyun 	[17] = { .offset = 0x85, .value = 0x00, },
322*4882a593Smuzhiyun 	[18] = { .offset = 0x86, .value = 0x00, },
323*4882a593Smuzhiyun 	[19] = { .offset = 0x87, .value = 0x00, },
324*4882a593Smuzhiyun 	[20] = { .offset = 0x88, .value = 0x00, },
325*4882a593Smuzhiyun 	[21] = { .offset = 0x89, .value = 0x00, },
326*4882a593Smuzhiyun 	[22] = { .offset = 0x8a, .value = 0x00, },
327*4882a593Smuzhiyun 	[23] = { .offset = 0x8b, .value = 0x00, },
328*4882a593Smuzhiyun 	[24] = { .offset = 0x8c, .value = 0x10, },
329*4882a593Smuzhiyun 	[25] = { .offset = 0x8d, .value = 0x02, },
330*4882a593Smuzhiyun 	/* 8e,8f are part of the mode-specific configuration */
331*4882a593Smuzhiyun 	[26] = { .offset = 0x90, .value = 0xff, },
332*4882a593Smuzhiyun 	[27] = { .offset = 0x91, .value = 0x07, },
333*4882a593Smuzhiyun 	[28] = { .offset = 0x92, .value = 0xa0, },
334*4882a593Smuzhiyun 	[29] = { .offset = 0x93, .value = 0x02, },
335*4882a593Smuzhiyun 	[30] = { .offset = 0x94, .value = 0x00, },
336*4882a593Smuzhiyun 	[31] = { .offset = 0x95, .value = 0x00, },
337*4882a593Smuzhiyun 	[32] = { .offset = 0x96, .value = 0x05, },
338*4882a593Smuzhiyun 	[33] = { .offset = 0x97, .value = 0x00, },
339*4882a593Smuzhiyun 	/* 98,99 are part of the mode-specific configuration */
340*4882a593Smuzhiyun 	[34] = { .offset = 0x9a, .value = 0x88, },
341*4882a593Smuzhiyun 	[35] = { .offset = 0x9b, .value = 0x00, },
342*4882a593Smuzhiyun 	/* 9c,9d are part of the mode-specific configuration */
343*4882a593Smuzhiyun 	[36] = { .offset = 0x9e, .value = 0x25, },
344*4882a593Smuzhiyun 	[37] = { .offset = 0x9f, .value = 0x03, },
345*4882a593Smuzhiyun 	[38] = { .offset = 0xa0, .value = 0x28, },
346*4882a593Smuzhiyun 	[39] = { .offset = 0xa1, .value = 0x01, },
347*4882a593Smuzhiyun 	[40] = { .offset = 0xa2, .value = 0x28, },
348*4882a593Smuzhiyun 	[41] = { .offset = 0xa3, .value = 0x05, },
349*4882a593Smuzhiyun 	/* register 0xa4 is mode specific, but 0x80..0x84 works always */
350*4882a593Smuzhiyun 	[42] = { .offset = 0xa4, .value = 0x84, },
351*4882a593Smuzhiyun 	[43] = { .offset = 0xa5, .value = 0x00, },
352*4882a593Smuzhiyun 	[44] = { .offset = 0xa6, .value = 0x00, },
353*4882a593Smuzhiyun 	[45] = { .offset = 0xa7, .value = 0x00, },
354*4882a593Smuzhiyun 	[46] = { .offset = 0xa8, .value = 0x00, },
355*4882a593Smuzhiyun 	/* 0xa9 to 0xab are mode specific, but have no visible effect */
356*4882a593Smuzhiyun 	[47] = { .offset = 0xa9, .value = 0x04, },
357*4882a593Smuzhiyun 	[48] = { .offset = 0xaa, .value = 0x70, },
358*4882a593Smuzhiyun 	[49] = { .offset = 0xab, .value = 0x4f, },
359*4882a593Smuzhiyun 	[50] = { .offset = 0xac, .value = 0x00, },
360*4882a593Smuzhiyun 	[51] = { .offset = 0xad, .value = 0x00, },
361*4882a593Smuzhiyun 	[52] = { .offset = 0xb6, .value = 0x09, },
362*4882a593Smuzhiyun 	[53] = { .offset = 0xb7, .value = 0x03, },
363*4882a593Smuzhiyun 	/* b8,b9 are part of the mode-specific configuration */
364*4882a593Smuzhiyun 	[54] = { .offset = 0xba, .value = 0x00, },
365*4882a593Smuzhiyun 	[55] = { .offset = 0xbb, .value = 0x20, },
366*4882a593Smuzhiyun 	[56] = { .offset = 0xf3, .value = 0x90, },
367*4882a593Smuzhiyun 	[57] = { .offset = 0xf4, .value = 0x00, },
368*4882a593Smuzhiyun 	[58] = { .offset = 0xf7, .value = 0x88, },
369*4882a593Smuzhiyun 	/* f8 is mode specific, but the value does not matter */
370*4882a593Smuzhiyun 	[59] = { .offset = 0xf8, .value = 0x0a, },
371*4882a593Smuzhiyun 	[60] = { .offset = 0xf9, .value = 0x00, }
372*4882a593Smuzhiyun };
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun static const struct ns2501_reg regs_init[] = {
375*4882a593Smuzhiyun 	[0] = { .offset = 0x35, .value = 0xff, },
376*4882a593Smuzhiyun 	[1] = { .offset = 0x34, .value = 0x00, },
377*4882a593Smuzhiyun 	[2] = { .offset = 0x08, .value = 0x30, },
378*4882a593Smuzhiyun };
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun struct ns2501_priv {
381*4882a593Smuzhiyun 	bool quiet;
382*4882a593Smuzhiyun 	const struct ns2501_configuration *conf;
383*4882a593Smuzhiyun };
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun #define NSPTR(d) ((NS2501Ptr)(d->DriverPrivate.ptr))
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun /*
388*4882a593Smuzhiyun ** Read a register from the ns2501.
389*4882a593Smuzhiyun ** Returns true if successful, false otherwise.
390*4882a593Smuzhiyun ** If it returns false, it might be wise to enable the
391*4882a593Smuzhiyun ** DVO with the above function.
392*4882a593Smuzhiyun */
ns2501_readb(struct intel_dvo_device * dvo,int addr,u8 * ch)393*4882a593Smuzhiyun static bool ns2501_readb(struct intel_dvo_device *dvo, int addr, u8 *ch)
394*4882a593Smuzhiyun {
395*4882a593Smuzhiyun 	struct ns2501_priv *ns = dvo->dev_priv;
396*4882a593Smuzhiyun 	struct i2c_adapter *adapter = dvo->i2c_bus;
397*4882a593Smuzhiyun 	u8 out_buf[2];
398*4882a593Smuzhiyun 	u8 in_buf[2];
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun 	struct i2c_msg msgs[] = {
401*4882a593Smuzhiyun 		{
402*4882a593Smuzhiyun 		 .addr = dvo->slave_addr,
403*4882a593Smuzhiyun 		 .flags = 0,
404*4882a593Smuzhiyun 		 .len = 1,
405*4882a593Smuzhiyun 		 .buf = out_buf,
406*4882a593Smuzhiyun 		 },
407*4882a593Smuzhiyun 		{
408*4882a593Smuzhiyun 		 .addr = dvo->slave_addr,
409*4882a593Smuzhiyun 		 .flags = I2C_M_RD,
410*4882a593Smuzhiyun 		 .len = 1,
411*4882a593Smuzhiyun 		 .buf = in_buf,
412*4882a593Smuzhiyun 		 }
413*4882a593Smuzhiyun 	};
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun 	out_buf[0] = addr;
416*4882a593Smuzhiyun 	out_buf[1] = 0;
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun 	if (i2c_transfer(adapter, msgs, 2) == 2) {
419*4882a593Smuzhiyun 		*ch = in_buf[0];
420*4882a593Smuzhiyun 		return true;
421*4882a593Smuzhiyun 	}
422*4882a593Smuzhiyun 
423*4882a593Smuzhiyun 	if (!ns->quiet) {
424*4882a593Smuzhiyun 		DRM_DEBUG_KMS
425*4882a593Smuzhiyun 		    ("Unable to read register 0x%02x from %s:0x%02x.\n", addr,
426*4882a593Smuzhiyun 		     adapter->name, dvo->slave_addr);
427*4882a593Smuzhiyun 	}
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	return false;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun /*
433*4882a593Smuzhiyun ** Write a register to the ns2501.
434*4882a593Smuzhiyun ** Returns true if successful, false otherwise.
435*4882a593Smuzhiyun ** If it returns false, it might be wise to enable the
436*4882a593Smuzhiyun ** DVO with the above function.
437*4882a593Smuzhiyun */
ns2501_writeb(struct intel_dvo_device * dvo,int addr,u8 ch)438*4882a593Smuzhiyun static bool ns2501_writeb(struct intel_dvo_device *dvo, int addr, u8 ch)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun 	struct ns2501_priv *ns = dvo->dev_priv;
441*4882a593Smuzhiyun 	struct i2c_adapter *adapter = dvo->i2c_bus;
442*4882a593Smuzhiyun 	u8 out_buf[2];
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun 	struct i2c_msg msg = {
445*4882a593Smuzhiyun 		.addr = dvo->slave_addr,
446*4882a593Smuzhiyun 		.flags = 0,
447*4882a593Smuzhiyun 		.len = 2,
448*4882a593Smuzhiyun 		.buf = out_buf,
449*4882a593Smuzhiyun 	};
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun 	out_buf[0] = addr;
452*4882a593Smuzhiyun 	out_buf[1] = ch;
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun 	if (i2c_transfer(adapter, &msg, 1) == 1) {
455*4882a593Smuzhiyun 		return true;
456*4882a593Smuzhiyun 	}
457*4882a593Smuzhiyun 
458*4882a593Smuzhiyun 	if (!ns->quiet) {
459*4882a593Smuzhiyun 		DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d\n",
460*4882a593Smuzhiyun 			      addr, adapter->name, dvo->slave_addr);
461*4882a593Smuzhiyun 	}
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun 	return false;
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun /* National Semiconductor 2501 driver for chip on i2c bus
467*4882a593Smuzhiyun  * scan for the chip on the bus.
468*4882a593Smuzhiyun  * Hope the VBIOS initialized the PLL correctly so we can
469*4882a593Smuzhiyun  * talk to it. If not, it will not be seen and not detected.
470*4882a593Smuzhiyun  * Bummer!
471*4882a593Smuzhiyun  */
ns2501_init(struct intel_dvo_device * dvo,struct i2c_adapter * adapter)472*4882a593Smuzhiyun static bool ns2501_init(struct intel_dvo_device *dvo,
473*4882a593Smuzhiyun 			struct i2c_adapter *adapter)
474*4882a593Smuzhiyun {
475*4882a593Smuzhiyun 	/* this will detect the NS2501 chip on the specified i2c bus */
476*4882a593Smuzhiyun 	struct ns2501_priv *ns;
477*4882a593Smuzhiyun 	unsigned char ch;
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun 	ns = kzalloc(sizeof(struct ns2501_priv), GFP_KERNEL);
480*4882a593Smuzhiyun 	if (ns == NULL)
481*4882a593Smuzhiyun 		return false;
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun 	dvo->i2c_bus = adapter;
484*4882a593Smuzhiyun 	dvo->dev_priv = ns;
485*4882a593Smuzhiyun 	ns->quiet = true;
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun 	if (!ns2501_readb(dvo, NS2501_VID_LO, &ch))
488*4882a593Smuzhiyun 		goto out;
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun 	if (ch != (NS2501_VID & 0xff)) {
491*4882a593Smuzhiyun 		DRM_DEBUG_KMS("ns2501 not detected got %d: from %s Slave %d.\n",
492*4882a593Smuzhiyun 			      ch, adapter->name, dvo->slave_addr);
493*4882a593Smuzhiyun 		goto out;
494*4882a593Smuzhiyun 	}
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun 	if (!ns2501_readb(dvo, NS2501_DID_LO, &ch))
497*4882a593Smuzhiyun 		goto out;
498*4882a593Smuzhiyun 
499*4882a593Smuzhiyun 	if (ch != (NS2501_DID & 0xff)) {
500*4882a593Smuzhiyun 		DRM_DEBUG_KMS("ns2501 not detected got %d: from %s Slave %d.\n",
501*4882a593Smuzhiyun 			      ch, adapter->name, dvo->slave_addr);
502*4882a593Smuzhiyun 		goto out;
503*4882a593Smuzhiyun 	}
504*4882a593Smuzhiyun 	ns->quiet = false;
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun 	DRM_DEBUG_KMS("init ns2501 dvo controller successfully!\n");
507*4882a593Smuzhiyun 
508*4882a593Smuzhiyun 	return true;
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun out:
511*4882a593Smuzhiyun 	kfree(ns);
512*4882a593Smuzhiyun 	return false;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun 
ns2501_detect(struct intel_dvo_device * dvo)515*4882a593Smuzhiyun static enum drm_connector_status ns2501_detect(struct intel_dvo_device *dvo)
516*4882a593Smuzhiyun {
517*4882a593Smuzhiyun 	/*
518*4882a593Smuzhiyun 	 * This is a Laptop display, it doesn't have hotplugging.
519*4882a593Smuzhiyun 	 * Even if not, the detection bit of the 2501 is unreliable as
520*4882a593Smuzhiyun 	 * it only works for some display types.
521*4882a593Smuzhiyun 	 * It is even more unreliable as the PLL must be active for
522*4882a593Smuzhiyun 	 * allowing reading from the chiop.
523*4882a593Smuzhiyun 	 */
524*4882a593Smuzhiyun 	return connector_status_connected;
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun 
ns2501_mode_valid(struct intel_dvo_device * dvo,struct drm_display_mode * mode)527*4882a593Smuzhiyun static enum drm_mode_status ns2501_mode_valid(struct intel_dvo_device *dvo,
528*4882a593Smuzhiyun 					      struct drm_display_mode *mode)
529*4882a593Smuzhiyun {
530*4882a593Smuzhiyun 	DRM_DEBUG_KMS
531*4882a593Smuzhiyun 	    ("is mode valid (hdisplay=%d,htotal=%d,vdisplay=%d,vtotal=%d)\n",
532*4882a593Smuzhiyun 	     mode->hdisplay, mode->htotal, mode->vdisplay, mode->vtotal);
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun 	/*
535*4882a593Smuzhiyun 	 * Currently, these are all the modes I have data from.
536*4882a593Smuzhiyun 	 * More might exist. Unclear how to find the native resolution
537*4882a593Smuzhiyun 	 * of the panel in here so we could always accept it
538*4882a593Smuzhiyun 	 * by disabling the scaler.
539*4882a593Smuzhiyun 	 */
540*4882a593Smuzhiyun 	if ((mode->hdisplay == 640 && mode->vdisplay == 480 && mode->clock == 25175) ||
541*4882a593Smuzhiyun 	    (mode->hdisplay == 800 && mode->vdisplay == 600 && mode->clock == 40000) ||
542*4882a593Smuzhiyun 	    (mode->hdisplay == 1024 && mode->vdisplay == 768 && mode->clock == 65000)) {
543*4882a593Smuzhiyun 		return MODE_OK;
544*4882a593Smuzhiyun 	} else {
545*4882a593Smuzhiyun 		return MODE_ONE_SIZE;	/* Is this a reasonable error? */
546*4882a593Smuzhiyun 	}
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun 
ns2501_mode_set(struct intel_dvo_device * dvo,const struct drm_display_mode * mode,const struct drm_display_mode * adjusted_mode)549*4882a593Smuzhiyun static void ns2501_mode_set(struct intel_dvo_device *dvo,
550*4882a593Smuzhiyun 			    const struct drm_display_mode *mode,
551*4882a593Smuzhiyun 			    const struct drm_display_mode *adjusted_mode)
552*4882a593Smuzhiyun {
553*4882a593Smuzhiyun 	const struct ns2501_configuration *conf;
554*4882a593Smuzhiyun 	struct ns2501_priv *ns = (struct ns2501_priv *)(dvo->dev_priv);
555*4882a593Smuzhiyun 	int mode_idx, i;
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	DRM_DEBUG_KMS
558*4882a593Smuzhiyun 	    ("set mode (hdisplay=%d,htotal=%d,vdisplay=%d,vtotal=%d).\n",
559*4882a593Smuzhiyun 	     mode->hdisplay, mode->htotal, mode->vdisplay, mode->vtotal);
560*4882a593Smuzhiyun 
561*4882a593Smuzhiyun 	DRM_DEBUG_KMS("Detailed requested mode settings are:\n"
562*4882a593Smuzhiyun 			"clock		: %d kHz\n"
563*4882a593Smuzhiyun 			"hdisplay	: %d\n"
564*4882a593Smuzhiyun 			"hblank start	: %d\n"
565*4882a593Smuzhiyun 			"hblank end	: %d\n"
566*4882a593Smuzhiyun 			"hsync start	: %d\n"
567*4882a593Smuzhiyun 			"hsync end	: %d\n"
568*4882a593Smuzhiyun 			"htotal		: %d\n"
569*4882a593Smuzhiyun 			"hskew		: %d\n"
570*4882a593Smuzhiyun 			"vdisplay	: %d\n"
571*4882a593Smuzhiyun 			"vblank start	: %d\n"
572*4882a593Smuzhiyun 			"hblank end	: %d\n"
573*4882a593Smuzhiyun 			"vsync start	: %d\n"
574*4882a593Smuzhiyun 			"vsync end	: %d\n"
575*4882a593Smuzhiyun 			"vtotal		: %d\n",
576*4882a593Smuzhiyun 			adjusted_mode->crtc_clock,
577*4882a593Smuzhiyun 			adjusted_mode->crtc_hdisplay,
578*4882a593Smuzhiyun 			adjusted_mode->crtc_hblank_start,
579*4882a593Smuzhiyun 			adjusted_mode->crtc_hblank_end,
580*4882a593Smuzhiyun 			adjusted_mode->crtc_hsync_start,
581*4882a593Smuzhiyun 			adjusted_mode->crtc_hsync_end,
582*4882a593Smuzhiyun 			adjusted_mode->crtc_htotal,
583*4882a593Smuzhiyun 			adjusted_mode->crtc_hskew,
584*4882a593Smuzhiyun 			adjusted_mode->crtc_vdisplay,
585*4882a593Smuzhiyun 			adjusted_mode->crtc_vblank_start,
586*4882a593Smuzhiyun 			adjusted_mode->crtc_vblank_end,
587*4882a593Smuzhiyun 			adjusted_mode->crtc_vsync_start,
588*4882a593Smuzhiyun 			adjusted_mode->crtc_vsync_end,
589*4882a593Smuzhiyun 			adjusted_mode->crtc_vtotal);
590*4882a593Smuzhiyun 
591*4882a593Smuzhiyun 	if (mode->hdisplay == 640 && mode->vdisplay == 480)
592*4882a593Smuzhiyun 		mode_idx = MODE_640x480;
593*4882a593Smuzhiyun 	else if (mode->hdisplay == 800 && mode->vdisplay == 600)
594*4882a593Smuzhiyun 		mode_idx = MODE_800x600;
595*4882a593Smuzhiyun 	else if (mode->hdisplay == 1024 && mode->vdisplay == 768)
596*4882a593Smuzhiyun 		mode_idx = MODE_1024x768;
597*4882a593Smuzhiyun 	else
598*4882a593Smuzhiyun 		return;
599*4882a593Smuzhiyun 
600*4882a593Smuzhiyun 	/* Hopefully doing it every time won't hurt... */
601*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(regs_init); i++)
602*4882a593Smuzhiyun 		ns2501_writeb(dvo, regs_init[i].offset, regs_init[i].value);
603*4882a593Smuzhiyun 
604*4882a593Smuzhiyun 	/* Write the mode-agnostic values */
605*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(mode_agnostic_values); i++)
606*4882a593Smuzhiyun 		ns2501_writeb(dvo, mode_agnostic_values[i].offset,
607*4882a593Smuzhiyun 				mode_agnostic_values[i].value);
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun 	/* Write now the mode-specific configuration */
610*4882a593Smuzhiyun 	conf = ns2501_modes + mode_idx;
611*4882a593Smuzhiyun 	ns->conf = conf;
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG8, conf->conf);
614*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG1B, conf->pll_a);
615*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG1C, conf->pll_b & 0xff);
616*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG1D, conf->pll_b >> 8);
617*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC1, conf->hstart & 0xff);
618*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC2, conf->hstart >> 8);
619*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC3, conf->hstop & 0xff);
620*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC4, conf->hstop >> 8);
621*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC5, conf->vstart & 0xff);
622*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC6, conf->vstart >> 8);
623*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC7, conf->vstop & 0xff);
624*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC8, conf->vstop >> 8);
625*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG80, conf->vsync & 0xff);
626*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG81, conf->vsync >> 8);
627*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG82, conf->vtotal & 0xff);
628*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG83, conf->vtotal >> 8);
629*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG98, conf->hpos & 0xff);
630*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG99, conf->hpos >> 8);
631*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG8E, conf->vpos & 0xff);
632*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG8F, conf->vpos >> 8);
633*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG9C, conf->voffs & 0xff);
634*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG9D, conf->voffs >> 8);
635*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGB8, conf->hscale & 0xff);
636*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGB9, conf->hscale >> 8);
637*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG10, conf->vscale & 0xff);
638*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG11, conf->vscale >> 8);
639*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGF9, conf->dither);
640*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REG41, conf->syncb);
641*4882a593Smuzhiyun 	ns2501_writeb(dvo, NS2501_REGC0, conf->sync);
642*4882a593Smuzhiyun }
643*4882a593Smuzhiyun 
644*4882a593Smuzhiyun /* set the NS2501 power state */
ns2501_get_hw_state(struct intel_dvo_device * dvo)645*4882a593Smuzhiyun static bool ns2501_get_hw_state(struct intel_dvo_device *dvo)
646*4882a593Smuzhiyun {
647*4882a593Smuzhiyun 	unsigned char ch;
648*4882a593Smuzhiyun 
649*4882a593Smuzhiyun 	if (!ns2501_readb(dvo, NS2501_REG8, &ch))
650*4882a593Smuzhiyun 		return false;
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun 	return ch & NS2501_8_PD;
653*4882a593Smuzhiyun }
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun /* set the NS2501 power state */
ns2501_dpms(struct intel_dvo_device * dvo,bool enable)656*4882a593Smuzhiyun static void ns2501_dpms(struct intel_dvo_device *dvo, bool enable)
657*4882a593Smuzhiyun {
658*4882a593Smuzhiyun 	struct ns2501_priv *ns = (struct ns2501_priv *)(dvo->dev_priv);
659*4882a593Smuzhiyun 
660*4882a593Smuzhiyun 	DRM_DEBUG_KMS("Trying set the dpms of the DVO to %i\n", enable);
661*4882a593Smuzhiyun 
662*4882a593Smuzhiyun 	if (enable) {
663*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REGC0, ns->conf->sync | 0x08);
664*4882a593Smuzhiyun 
665*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG41, ns->conf->syncb);
666*4882a593Smuzhiyun 
667*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG34, NS2501_34_ENABLE_OUTPUT);
668*4882a593Smuzhiyun 		msleep(15);
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG8,
671*4882a593Smuzhiyun 				ns->conf->conf | NS2501_8_BPAS);
672*4882a593Smuzhiyun 		if (!(ns->conf->conf & NS2501_8_BPAS))
673*4882a593Smuzhiyun 			ns2501_writeb(dvo, NS2501_REG8, ns->conf->conf);
674*4882a593Smuzhiyun 		msleep(200);
675*4882a593Smuzhiyun 
676*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG34,
677*4882a593Smuzhiyun 			NS2501_34_ENABLE_OUTPUT | NS2501_34_ENABLE_BACKLIGHT);
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REGC0, ns->conf->sync);
680*4882a593Smuzhiyun 	} else {
681*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG34, NS2501_34_ENABLE_OUTPUT);
682*4882a593Smuzhiyun 		msleep(200);
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG8, NS2501_8_VEN | NS2501_8_HEN |
685*4882a593Smuzhiyun 				NS2501_8_BPAS);
686*4882a593Smuzhiyun 		msleep(15);
687*4882a593Smuzhiyun 
688*4882a593Smuzhiyun 		ns2501_writeb(dvo, NS2501_REG34, 0x00);
689*4882a593Smuzhiyun 	}
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun 
ns2501_destroy(struct intel_dvo_device * dvo)692*4882a593Smuzhiyun static void ns2501_destroy(struct intel_dvo_device *dvo)
693*4882a593Smuzhiyun {
694*4882a593Smuzhiyun 	struct ns2501_priv *ns = dvo->dev_priv;
695*4882a593Smuzhiyun 
696*4882a593Smuzhiyun 	if (ns) {
697*4882a593Smuzhiyun 		kfree(ns);
698*4882a593Smuzhiyun 		dvo->dev_priv = NULL;
699*4882a593Smuzhiyun 	}
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun const struct intel_dvo_dev_ops ns2501_ops = {
703*4882a593Smuzhiyun 	.init = ns2501_init,
704*4882a593Smuzhiyun 	.detect = ns2501_detect,
705*4882a593Smuzhiyun 	.mode_valid = ns2501_mode_valid,
706*4882a593Smuzhiyun 	.mode_set = ns2501_mode_set,
707*4882a593Smuzhiyun 	.dpms = ns2501_dpms,
708*4882a593Smuzhiyun 	.get_hw_state = ns2501_get_hw_state,
709*4882a593Smuzhiyun 	.destroy = ns2501_destroy,
710*4882a593Smuzhiyun };
711