xref: /openbmc/linux/drivers/gpu/drm/i915/display/dvo_ns2501.c (revision 976e3645923bdd2fe7893aae33fd7a21098bfb28)
1379bc100SJani Nikula /*
2379bc100SJani Nikula  *
3379bc100SJani Nikula  * Copyright (c) 2012 Gilles Dartiguelongue, Thomas Richter
4379bc100SJani Nikula  *
5379bc100SJani Nikula  * All Rights Reserved.
6379bc100SJani Nikula  *
7379bc100SJani Nikula  * Permission is hereby granted, free of charge, to any person obtaining a
8379bc100SJani Nikula  * copy of this software and associated documentation files (the
9379bc100SJani Nikula  * "Software"), to deal in the Software without restriction, including
10379bc100SJani Nikula  * without limitation the rights to use, copy, modify, merge, publish,
11379bc100SJani Nikula  * distribute, sub license, and/or sell copies of the Software, and to
12379bc100SJani Nikula  * permit persons to whom the Software is furnished to do so, subject to
13379bc100SJani Nikula  * the following conditions:
14379bc100SJani Nikula  *
15379bc100SJani Nikula  * The above copyright notice and this permission notice (including the
16379bc100SJani Nikula  * next paragraph) shall be included in all copies or substantial portions
17379bc100SJani Nikula  * of the Software.
18379bc100SJani Nikula  *
19379bc100SJani Nikula  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20379bc100SJani Nikula  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21379bc100SJani Nikula  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22379bc100SJani Nikula  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
23379bc100SJani Nikula  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24379bc100SJani Nikula  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25379bc100SJani Nikula  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26379bc100SJani Nikula  *
27379bc100SJani Nikula  */
28379bc100SJani Nikula 
29379bc100SJani Nikula #include "i915_drv.h"
30379bc100SJani Nikula #include "i915_reg.h"
31*1d455f8dSJani Nikula #include "intel_display_types.h"
32379bc100SJani Nikula #include "intel_dvo_dev.h"
33379bc100SJani Nikula 
34379bc100SJani Nikula #define NS2501_VID 0x1305
35379bc100SJani Nikula #define NS2501_DID 0x6726
36379bc100SJani Nikula 
37379bc100SJani Nikula #define NS2501_VID_LO 0x00
38379bc100SJani Nikula #define NS2501_VID_HI 0x01
39379bc100SJani Nikula #define NS2501_DID_LO 0x02
40379bc100SJani Nikula #define NS2501_DID_HI 0x03
41379bc100SJani Nikula #define NS2501_REV 0x04
42379bc100SJani Nikula #define NS2501_RSVD 0x05
43379bc100SJani Nikula #define NS2501_FREQ_LO 0x06
44379bc100SJani Nikula #define NS2501_FREQ_HI 0x07
45379bc100SJani Nikula 
46379bc100SJani Nikula #define NS2501_REG8 0x08
47379bc100SJani Nikula #define NS2501_8_VEN (1<<5)
48379bc100SJani Nikula #define NS2501_8_HEN (1<<4)
49379bc100SJani Nikula #define NS2501_8_DSEL (1<<3)
50379bc100SJani Nikula #define NS2501_8_BPAS (1<<2)
51379bc100SJani Nikula #define NS2501_8_RSVD (1<<1)
52379bc100SJani Nikula #define NS2501_8_PD (1<<0)
53379bc100SJani Nikula 
54379bc100SJani Nikula #define NS2501_REG9 0x09
55379bc100SJani Nikula #define NS2501_9_VLOW (1<<7)
56379bc100SJani Nikula #define NS2501_9_MSEL_MASK (0x7<<4)
57379bc100SJani Nikula #define NS2501_9_TSEL (1<<3)
58379bc100SJani Nikula #define NS2501_9_RSEN (1<<2)
59379bc100SJani Nikula #define NS2501_9_RSVD (1<<1)
60379bc100SJani Nikula #define NS2501_9_MDI (1<<0)
61379bc100SJani Nikula 
62379bc100SJani Nikula #define NS2501_REGC 0x0c
63379bc100SJani Nikula 
64379bc100SJani Nikula /*
65379bc100SJani Nikula  * The following registers are not part of the official datasheet
66379bc100SJani Nikula  * and are the result of reverse engineering.
67379bc100SJani Nikula  */
68379bc100SJani Nikula 
69379bc100SJani Nikula /*
70379bc100SJani Nikula  * Register c0 controls how the DVO synchronizes with
71379bc100SJani Nikula  * its input.
72379bc100SJani Nikula  */
73379bc100SJani Nikula #define NS2501_REGC0 0xc0
74379bc100SJani Nikula #define NS2501_C0_ENABLE (1<<0)	/* enable the DVO sync in general */
75379bc100SJani Nikula #define NS2501_C0_HSYNC (1<<1)	/* synchronize horizontal with input */
76379bc100SJani Nikula #define NS2501_C0_VSYNC (1<<2)	/* synchronize vertical with input */
77379bc100SJani Nikula #define NS2501_C0_RESET (1<<7)	/* reset the synchronization flip/flops */
78379bc100SJani Nikula 
79379bc100SJani Nikula /*
80379bc100SJani Nikula  * Register 41 is somehow related to the sync register and sync
81379bc100SJani Nikula  * configuration. It should be 0x32 whenever regC0 is 0x05 (hsync off)
82379bc100SJani Nikula  * and 0x00 otherwise.
83379bc100SJani Nikula  */
84379bc100SJani Nikula #define NS2501_REG41 0x41
85379bc100SJani Nikula 
86379bc100SJani Nikula /*
87379bc100SJani Nikula  * this register controls the dithering of the DVO
88379bc100SJani Nikula  * One bit enables it, the other define the dithering depth.
89379bc100SJani Nikula  * The higher the value, the lower the dithering depth.
90379bc100SJani Nikula  */
91379bc100SJani Nikula #define NS2501_F9_REG 0xf9
92379bc100SJani Nikula #define NS2501_F9_ENABLE (1<<0)		/* if set, dithering is enabled */
93379bc100SJani Nikula #define NS2501_F9_DITHER_MASK (0x7f<<1)	/* controls the dither depth */
94379bc100SJani Nikula #define NS2501_F9_DITHER_SHIFT 1	/* shifts the dither mask */
95379bc100SJani Nikula 
96379bc100SJani Nikula /*
97379bc100SJani Nikula  * PLL configuration register. This is a pair of registers,
98379bc100SJani Nikula  * one single byte register at 1B, and a pair at 1C,1D.
99379bc100SJani Nikula  * These registers are counters/dividers.
100379bc100SJani Nikula  */
101379bc100SJani Nikula #define NS2501_REG1B 0x1b /* one byte PLL control register */
102379bc100SJani Nikula #define NS2501_REG1C 0x1c /* low-part of the second register */
103379bc100SJani Nikula #define NS2501_REG1D 0x1d /* high-part of the second register */
104379bc100SJani Nikula 
105379bc100SJani Nikula /*
106379bc100SJani Nikula  * Scaler control registers. Horizontal at b8,b9,
107379bc100SJani Nikula  * vertical at 10,11. The scale factor is computed as
108379bc100SJani Nikula  * 2^16/control-value. The low-byte comes first.
109379bc100SJani Nikula  */
110379bc100SJani Nikula #define NS2501_REG10 0x10 /* low-byte vertical scaler */
111379bc100SJani Nikula #define NS2501_REG11 0x11 /* high-byte vertical scaler */
112379bc100SJani Nikula #define NS2501_REGB8 0xb8 /* low-byte horizontal scaler */
113379bc100SJani Nikula #define NS2501_REGB9 0xb9 /* high-byte horizontal scaler */
114379bc100SJani Nikula 
115379bc100SJani Nikula /*
116379bc100SJani Nikula  * Display window definition. This consists of four registers
117379bc100SJani Nikula  * per dimension. One register pair defines the start of the
118379bc100SJani Nikula  * display, one the end.
119379bc100SJani Nikula  * As far as I understand, this defines the window within which
120379bc100SJani Nikula  * the scaler samples the input.
121379bc100SJani Nikula  */
122379bc100SJani Nikula #define NS2501_REGC1 0xc1 /* low-byte horizontal display start */
123379bc100SJani Nikula #define NS2501_REGC2 0xc2 /* high-byte horizontal display start */
124379bc100SJani Nikula #define NS2501_REGC3 0xc3 /* low-byte horizontal display stop */
125379bc100SJani Nikula #define NS2501_REGC4 0xc4 /* high-byte horizontal display stop */
126379bc100SJani Nikula #define NS2501_REGC5 0xc5 /* low-byte vertical display start */
127379bc100SJani Nikula #define NS2501_REGC6 0xc6 /* high-byte vertical display start */
128379bc100SJani Nikula #define NS2501_REGC7 0xc7 /* low-byte vertical display stop */
129379bc100SJani Nikula #define NS2501_REGC8 0xc8 /* high-byte vertical display stop */
130379bc100SJani Nikula 
131379bc100SJani Nikula /*
132379bc100SJani Nikula  * The following register pair seems to define the start of
133379bc100SJani Nikula  * the vertical sync. If automatic syncing is enabled, and the
134379bc100SJani Nikula  * register value defines a sync pulse that is later than the
135379bc100SJani Nikula  * incoming sync, then the register value is ignored and the
136379bc100SJani Nikula  * external hsync triggers the synchronization.
137379bc100SJani Nikula  */
138379bc100SJani Nikula #define NS2501_REG80 0x80 /* low-byte vsync-start */
139379bc100SJani Nikula #define NS2501_REG81 0x81 /* high-byte vsync-start */
140379bc100SJani Nikula 
141379bc100SJani Nikula /*
142379bc100SJani Nikula  * The following register pair seems to define the total number
143379bc100SJani Nikula  * of lines created at the output side of the scaler.
144379bc100SJani Nikula  * This is again a low-high register pair.
145379bc100SJani Nikula  */
146379bc100SJani Nikula #define NS2501_REG82 0x82 /* output display height, low byte */
147379bc100SJani Nikula #define NS2501_REG83 0x83 /* output display height, high byte */
148379bc100SJani Nikula 
149379bc100SJani Nikula /*
150379bc100SJani Nikula  * The following registers define the end of the front-porch
151379bc100SJani Nikula  * in horizontal and vertical position and hence allow to shift
152379bc100SJani Nikula  * the image left/right or up/down.
153379bc100SJani Nikula  */
154379bc100SJani Nikula #define NS2501_REG98 0x98 /* horizontal start of display + 256, low */
155379bc100SJani Nikula #define NS2501_REG99 0x99 /* horizontal start of display + 256, high */
156379bc100SJani Nikula #define NS2501_REG8E 0x8e /* vertical start of the display, low byte */
157379bc100SJani Nikula #define NS2501_REG8F 0x8f /* vertical start of the display, high byte */
158379bc100SJani Nikula 
159379bc100SJani Nikula /*
160379bc100SJani Nikula  * The following register pair control the function of the
161379bc100SJani Nikula  * backlight and the DVO output. To enable the corresponding
162379bc100SJani Nikula  * function, the corresponding bit must be set in both registers.
163379bc100SJani Nikula  */
164379bc100SJani Nikula #define NS2501_REG34 0x34 /* DVO enable functions, first register */
165379bc100SJani Nikula #define NS2501_REG35 0x35 /* DVO enable functions, second register */
166379bc100SJani Nikula #define NS2501_34_ENABLE_OUTPUT (1<<0) /* enable DVO output */
167379bc100SJani Nikula #define NS2501_34_ENABLE_BACKLIGHT (1<<1) /* enable backlight */
168379bc100SJani Nikula 
169379bc100SJani Nikula /*
170379bc100SJani Nikula  * Registers 9C and 9D define the vertical output offset
171379bc100SJani Nikula  * of the visible region.
172379bc100SJani Nikula  */
173379bc100SJani Nikula #define NS2501_REG9C 0x9c
174379bc100SJani Nikula #define NS2501_REG9D 0x9d
175379bc100SJani Nikula 
176379bc100SJani Nikula /*
177379bc100SJani Nikula  * The register 9F defines the dithering. This requires the
178379bc100SJani Nikula  * scaler to be ON. Bit 0 enables dithering, the remaining
179379bc100SJani Nikula  * bits control the depth of the dither. The higher the value,
180379bc100SJani Nikula  * the LOWER the dithering amplitude. A good value seems to be
181379bc100SJani Nikula  * 15 (total register value).
182379bc100SJani Nikula  */
183379bc100SJani Nikula #define NS2501_REGF9 0xf9
184379bc100SJani Nikula #define NS2501_F9_ENABLE_DITHER (1<<0) /* enable dithering */
185379bc100SJani Nikula #define NS2501_F9_DITHER_MASK (0x7f<<1) /* dither masking */
186379bc100SJani Nikula #define NS2501_F9_DITHER_SHIFT 1	/* upshift of the dither mask */
187379bc100SJani Nikula 
188379bc100SJani Nikula enum {
189379bc100SJani Nikula 	MODE_640x480,
190379bc100SJani Nikula 	MODE_800x600,
191379bc100SJani Nikula 	MODE_1024x768,
192379bc100SJani Nikula };
193379bc100SJani Nikula 
194379bc100SJani Nikula struct ns2501_reg {
195379bc100SJani Nikula 	u8 offset;
196379bc100SJani Nikula 	u8 value;
197379bc100SJani Nikula };
198379bc100SJani Nikula 
199379bc100SJani Nikula /*
200379bc100SJani Nikula  * The following structure keeps the complete configuration of
201379bc100SJani Nikula  * the DVO, given a specific output configuration.
202379bc100SJani Nikula  * This is pretty much guess-work from reverse-engineering, so
203379bc100SJani Nikula  * read all this with a grain of salt.
204379bc100SJani Nikula  */
205379bc100SJani Nikula struct ns2501_configuration {
206379bc100SJani Nikula 	u8 sync;		/* configuration of the C0 register */
207379bc100SJani Nikula 	u8 conf;		/* configuration register 8 */
208379bc100SJani Nikula 	u8 syncb;		/* configuration register 41 */
209379bc100SJani Nikula 	u8 dither;		/* configuration of the dithering */
210379bc100SJani Nikula 	u8 pll_a;		/* PLL configuration, register A, 1B */
211379bc100SJani Nikula 	u16 pll_b;		/* PLL configuration, register B, 1C/1D */
212379bc100SJani Nikula 	u16 hstart;		/* horizontal start, registers C1/C2 */
213379bc100SJani Nikula 	u16 hstop;		/* horizontal total, registers C3/C4 */
214379bc100SJani Nikula 	u16 vstart;		/* vertical start, registers C5/C6 */
215379bc100SJani Nikula 	u16 vstop;		/* vertical total, registers C7/C8 */
216379bc100SJani Nikula 	u16 vsync;		/* manual vertical sync start, 80/81 */
217379bc100SJani Nikula 	u16 vtotal;		/* number of lines generated, 82/83 */
218379bc100SJani Nikula 	u16 hpos;		/* horizontal position + 256, 98/99  */
219379bc100SJani Nikula 	u16 vpos;		/* vertical position, 8e/8f */
220379bc100SJani Nikula 	u16 voffs;		/* vertical output offset, 9c/9d */
221379bc100SJani Nikula 	u16 hscale;		/* horizontal scaling factor, b8/b9 */
222379bc100SJani Nikula 	u16 vscale;		/* vertical scaling factor, 10/11 */
223379bc100SJani Nikula };
224379bc100SJani Nikula 
225379bc100SJani Nikula /*
226379bc100SJani Nikula  * DVO configuration values, partially based on what the BIOS
227379bc100SJani Nikula  * of the Fujitsu Lifebook S6010 writes into registers,
228379bc100SJani Nikula  * partially found by manual tweaking. These configurations assume
229379bc100SJani Nikula  * a 1024x768 panel.
230379bc100SJani Nikula  */
231379bc100SJani Nikula static const struct ns2501_configuration ns2501_modes[] = {
232379bc100SJani Nikula 	[MODE_640x480] = {
233379bc100SJani Nikula 		.sync	= NS2501_C0_ENABLE | NS2501_C0_VSYNC,
234379bc100SJani Nikula 		.conf	= NS2501_8_VEN | NS2501_8_HEN | NS2501_8_PD,
235379bc100SJani Nikula 		.syncb	= 0x32,
236379bc100SJani Nikula 		.dither	= 0x0f,
237379bc100SJani Nikula 		.pll_a	= 17,
238379bc100SJani Nikula 		.pll_b	= 852,
239379bc100SJani Nikula 		.hstart	= 144,
240379bc100SJani Nikula 		.hstop	= 783,
241379bc100SJani Nikula 		.vstart	= 22,
242379bc100SJani Nikula 		.vstop	= 514,
243379bc100SJani Nikula 		.vsync	= 2047, /* actually, ignored with this config */
244379bc100SJani Nikula 		.vtotal	= 1341,
245379bc100SJani Nikula 		.hpos	= 0,
246379bc100SJani Nikula 		.vpos	= 16,
247379bc100SJani Nikula 		.voffs	= 36,
248379bc100SJani Nikula 		.hscale	= 40960,
249379bc100SJani Nikula 		.vscale	= 40960
250379bc100SJani Nikula 	},
251379bc100SJani Nikula 	[MODE_800x600] = {
252379bc100SJani Nikula 		.sync	= NS2501_C0_ENABLE |
253379bc100SJani Nikula 			  NS2501_C0_HSYNC | NS2501_C0_VSYNC,
254379bc100SJani Nikula 		.conf   = NS2501_8_VEN | NS2501_8_HEN | NS2501_8_PD,
255379bc100SJani Nikula 		.syncb	= 0x00,
256379bc100SJani Nikula 		.dither	= 0x0f,
257379bc100SJani Nikula 		.pll_a	= 25,
258379bc100SJani Nikula 		.pll_b	= 612,
259379bc100SJani Nikula 		.hstart	= 215,
260379bc100SJani Nikula 		.hstop	= 1016,
261379bc100SJani Nikula 		.vstart	= 26,
262379bc100SJani Nikula 		.vstop	= 627,
263379bc100SJani Nikula 		.vsync	= 807,
264379bc100SJani Nikula 		.vtotal	= 1341,
265379bc100SJani Nikula 		.hpos	= 0,
266379bc100SJani Nikula 		.vpos	= 4,
267379bc100SJani Nikula 		.voffs	= 35,
268379bc100SJani Nikula 		.hscale	= 51248,
269379bc100SJani Nikula 		.vscale	= 51232
270379bc100SJani Nikula 	},
271379bc100SJani Nikula 	[MODE_1024x768] = {
272379bc100SJani Nikula 		.sync	= NS2501_C0_ENABLE | NS2501_C0_VSYNC,
273379bc100SJani Nikula 		.conf   = NS2501_8_VEN | NS2501_8_HEN | NS2501_8_PD,
274379bc100SJani Nikula 		.syncb	= 0x32,
275379bc100SJani Nikula 		.dither	= 0x0f,
276379bc100SJani Nikula 		.pll_a	= 11,
277379bc100SJani Nikula 		.pll_b	= 1350,
278379bc100SJani Nikula 		.hstart	= 276,
279379bc100SJani Nikula 		.hstop	= 1299,
280379bc100SJani Nikula 		.vstart	= 15,
281379bc100SJani Nikula 		.vstop	= 1056,
282379bc100SJani Nikula 		.vsync	= 2047,
283379bc100SJani Nikula 		.vtotal	= 1341,
284379bc100SJani Nikula 		.hpos	= 0,
285379bc100SJani Nikula 		.vpos	= 7,
286379bc100SJani Nikula 		.voffs	= 27,
287379bc100SJani Nikula 		.hscale	= 65535,
288379bc100SJani Nikula 		.vscale	= 65535
289379bc100SJani Nikula 	}
290379bc100SJani Nikula };
291379bc100SJani Nikula 
292379bc100SJani Nikula /*
293379bc100SJani Nikula  * Other configuration values left by the BIOS of the
294379bc100SJani Nikula  * Fujitsu S6010 in the DVO control registers. Their
295379bc100SJani Nikula  * value does not depend on the BIOS and their meaning
296379bc100SJani Nikula  * is unknown.
297379bc100SJani Nikula  */
298379bc100SJani Nikula 
299379bc100SJani Nikula static const struct ns2501_reg mode_agnostic_values[] = {
300379bc100SJani Nikula 	/* 08 is mode specific */
301379bc100SJani Nikula 	[0] = { .offset = 0x0a, .value = 0x81, },
302379bc100SJani Nikula 	/* 10,11 are part of the mode specific configuration */
303379bc100SJani Nikula 	[1] = { .offset = 0x12, .value = 0x02, },
304379bc100SJani Nikula 	[2] = { .offset = 0x18, .value = 0x07, },
305379bc100SJani Nikula 	[3] = { .offset = 0x19, .value = 0x00, },
306379bc100SJani Nikula 	[4] = { .offset = 0x1a, .value = 0x00, }, /* PLL?, ignored */
307379bc100SJani Nikula 	/* 1b,1c,1d are part of the mode specific configuration */
308379bc100SJani Nikula 	[5] = { .offset = 0x1e, .value = 0x02, },
309379bc100SJani Nikula 	[6] = { .offset = 0x1f, .value = 0x40, },
310379bc100SJani Nikula 	[7] = { .offset = 0x20, .value = 0x00, },
311379bc100SJani Nikula 	[8] = { .offset = 0x21, .value = 0x00, },
312379bc100SJani Nikula 	[9] = { .offset = 0x22, .value = 0x00, },
313379bc100SJani Nikula 	[10] = { .offset = 0x23, .value = 0x00, },
314379bc100SJani Nikula 	[11] = { .offset = 0x24, .value = 0x00, },
315379bc100SJani Nikula 	[12] = { .offset = 0x25, .value = 0x00, },
316379bc100SJani Nikula 	[13] = { .offset = 0x26, .value = 0x00, },
317379bc100SJani Nikula 	[14] = { .offset = 0x27, .value = 0x00, },
318379bc100SJani Nikula 	[15] = { .offset = 0x7e, .value = 0x18, },
319379bc100SJani Nikula 	/* 80-84 are part of the mode-specific configuration */
320379bc100SJani Nikula 	[16] = { .offset = 0x84, .value = 0x00, },
321379bc100SJani Nikula 	[17] = { .offset = 0x85, .value = 0x00, },
322379bc100SJani Nikula 	[18] = { .offset = 0x86, .value = 0x00, },
323379bc100SJani Nikula 	[19] = { .offset = 0x87, .value = 0x00, },
324379bc100SJani Nikula 	[20] = { .offset = 0x88, .value = 0x00, },
325379bc100SJani Nikula 	[21] = { .offset = 0x89, .value = 0x00, },
326379bc100SJani Nikula 	[22] = { .offset = 0x8a, .value = 0x00, },
327379bc100SJani Nikula 	[23] = { .offset = 0x8b, .value = 0x00, },
328379bc100SJani Nikula 	[24] = { .offset = 0x8c, .value = 0x10, },
329379bc100SJani Nikula 	[25] = { .offset = 0x8d, .value = 0x02, },
330379bc100SJani Nikula 	/* 8e,8f are part of the mode-specific configuration */
331379bc100SJani Nikula 	[26] = { .offset = 0x90, .value = 0xff, },
332379bc100SJani Nikula 	[27] = { .offset = 0x91, .value = 0x07, },
333379bc100SJani Nikula 	[28] = { .offset = 0x92, .value = 0xa0, },
334379bc100SJani Nikula 	[29] = { .offset = 0x93, .value = 0x02, },
335379bc100SJani Nikula 	[30] = { .offset = 0x94, .value = 0x00, },
336379bc100SJani Nikula 	[31] = { .offset = 0x95, .value = 0x00, },
337379bc100SJani Nikula 	[32] = { .offset = 0x96, .value = 0x05, },
338379bc100SJani Nikula 	[33] = { .offset = 0x97, .value = 0x00, },
339379bc100SJani Nikula 	/* 98,99 are part of the mode-specific configuration */
340379bc100SJani Nikula 	[34] = { .offset = 0x9a, .value = 0x88, },
341379bc100SJani Nikula 	[35] = { .offset = 0x9b, .value = 0x00, },
342379bc100SJani Nikula 	/* 9c,9d are part of the mode-specific configuration */
343379bc100SJani Nikula 	[36] = { .offset = 0x9e, .value = 0x25, },
344379bc100SJani Nikula 	[37] = { .offset = 0x9f, .value = 0x03, },
345379bc100SJani Nikula 	[38] = { .offset = 0xa0, .value = 0x28, },
346379bc100SJani Nikula 	[39] = { .offset = 0xa1, .value = 0x01, },
347379bc100SJani Nikula 	[40] = { .offset = 0xa2, .value = 0x28, },
348379bc100SJani Nikula 	[41] = { .offset = 0xa3, .value = 0x05, },
349379bc100SJani Nikula 	/* register 0xa4 is mode specific, but 0x80..0x84 works always */
350379bc100SJani Nikula 	[42] = { .offset = 0xa4, .value = 0x84, },
351379bc100SJani Nikula 	[43] = { .offset = 0xa5, .value = 0x00, },
352379bc100SJani Nikula 	[44] = { .offset = 0xa6, .value = 0x00, },
353379bc100SJani Nikula 	[45] = { .offset = 0xa7, .value = 0x00, },
354379bc100SJani Nikula 	[46] = { .offset = 0xa8, .value = 0x00, },
355379bc100SJani Nikula 	/* 0xa9 to 0xab are mode specific, but have no visible effect */
356379bc100SJani Nikula 	[47] = { .offset = 0xa9, .value = 0x04, },
357379bc100SJani Nikula 	[48] = { .offset = 0xaa, .value = 0x70, },
358379bc100SJani Nikula 	[49] = { .offset = 0xab, .value = 0x4f, },
359379bc100SJani Nikula 	[50] = { .offset = 0xac, .value = 0x00, },
360379bc100SJani Nikula 	[51] = { .offset = 0xad, .value = 0x00, },
361379bc100SJani Nikula 	[52] = { .offset = 0xb6, .value = 0x09, },
362379bc100SJani Nikula 	[53] = { .offset = 0xb7, .value = 0x03, },
363379bc100SJani Nikula 	/* b8,b9 are part of the mode-specific configuration */
364379bc100SJani Nikula 	[54] = { .offset = 0xba, .value = 0x00, },
365379bc100SJani Nikula 	[55] = { .offset = 0xbb, .value = 0x20, },
366379bc100SJani Nikula 	[56] = { .offset = 0xf3, .value = 0x90, },
367379bc100SJani Nikula 	[57] = { .offset = 0xf4, .value = 0x00, },
368379bc100SJani Nikula 	[58] = { .offset = 0xf7, .value = 0x88, },
369379bc100SJani Nikula 	/* f8 is mode specific, but the value does not matter */
370379bc100SJani Nikula 	[59] = { .offset = 0xf8, .value = 0x0a, },
371379bc100SJani Nikula 	[60] = { .offset = 0xf9, .value = 0x00, }
372379bc100SJani Nikula };
373379bc100SJani Nikula 
374379bc100SJani Nikula static const struct ns2501_reg regs_init[] = {
375379bc100SJani Nikula 	[0] = { .offset = 0x35, .value = 0xff, },
376379bc100SJani Nikula 	[1] = { .offset = 0x34, .value = 0x00, },
377379bc100SJani Nikula 	[2] = { .offset = 0x08, .value = 0x30, },
378379bc100SJani Nikula };
379379bc100SJani Nikula 
380379bc100SJani Nikula struct ns2501_priv {
381379bc100SJani Nikula 	bool quiet;
382379bc100SJani Nikula 	const struct ns2501_configuration *conf;
383379bc100SJani Nikula };
384379bc100SJani Nikula 
385379bc100SJani Nikula #define NSPTR(d) ((NS2501Ptr)(d->DriverPrivate.ptr))
386379bc100SJani Nikula 
387379bc100SJani Nikula /*
388379bc100SJani Nikula ** Read a register from the ns2501.
389379bc100SJani Nikula ** Returns true if successful, false otherwise.
390379bc100SJani Nikula ** If it returns false, it might be wise to enable the
391379bc100SJani Nikula ** DVO with the above function.
392379bc100SJani Nikula */
ns2501_readb(struct intel_dvo_device * dvo,int addr,u8 * ch)393379bc100SJani Nikula static bool ns2501_readb(struct intel_dvo_device *dvo, int addr, u8 *ch)
394379bc100SJani Nikula {
395379bc100SJani Nikula 	struct ns2501_priv *ns = dvo->dev_priv;
396379bc100SJani Nikula 	struct i2c_adapter *adapter = dvo->i2c_bus;
397379bc100SJani Nikula 	u8 out_buf[2];
398379bc100SJani Nikula 	u8 in_buf[2];
399379bc100SJani Nikula 
400379bc100SJani Nikula 	struct i2c_msg msgs[] = {
401379bc100SJani Nikula 		{
402379bc100SJani Nikula 		 .addr = dvo->slave_addr,
403379bc100SJani Nikula 		 .flags = 0,
404379bc100SJani Nikula 		 .len = 1,
405379bc100SJani Nikula 		 .buf = out_buf,
406379bc100SJani Nikula 		 },
407379bc100SJani Nikula 		{
408379bc100SJani Nikula 		 .addr = dvo->slave_addr,
409379bc100SJani Nikula 		 .flags = I2C_M_RD,
410379bc100SJani Nikula 		 .len = 1,
411379bc100SJani Nikula 		 .buf = in_buf,
412379bc100SJani Nikula 		 }
413379bc100SJani Nikula 	};
414379bc100SJani Nikula 
415379bc100SJani Nikula 	out_buf[0] = addr;
416379bc100SJani Nikula 	out_buf[1] = 0;
417379bc100SJani Nikula 
418379bc100SJani Nikula 	if (i2c_transfer(adapter, msgs, 2) == 2) {
419379bc100SJani Nikula 		*ch = in_buf[0];
420379bc100SJani Nikula 		return true;
421379bc100SJani Nikula 	}
422379bc100SJani Nikula 
423379bc100SJani Nikula 	if (!ns->quiet) {
424379bc100SJani Nikula 		DRM_DEBUG_KMS
425379bc100SJani Nikula 		    ("Unable to read register 0x%02x from %s:0x%02x.\n", addr,
426379bc100SJani Nikula 		     adapter->name, dvo->slave_addr);
427379bc100SJani Nikula 	}
428379bc100SJani Nikula 
429379bc100SJani Nikula 	return false;
430379bc100SJani Nikula }
431379bc100SJani Nikula 
432379bc100SJani Nikula /*
433379bc100SJani Nikula ** Write a register to the ns2501.
434379bc100SJani Nikula ** Returns true if successful, false otherwise.
435379bc100SJani Nikula ** If it returns false, it might be wise to enable the
436379bc100SJani Nikula ** DVO with the above function.
437379bc100SJani Nikula */
ns2501_writeb(struct intel_dvo_device * dvo,int addr,u8 ch)438379bc100SJani Nikula static bool ns2501_writeb(struct intel_dvo_device *dvo, int addr, u8 ch)
439379bc100SJani Nikula {
440379bc100SJani Nikula 	struct ns2501_priv *ns = dvo->dev_priv;
441379bc100SJani Nikula 	struct i2c_adapter *adapter = dvo->i2c_bus;
442379bc100SJani Nikula 	u8 out_buf[2];
443379bc100SJani Nikula 
444379bc100SJani Nikula 	struct i2c_msg msg = {
445379bc100SJani Nikula 		.addr = dvo->slave_addr,
446379bc100SJani Nikula 		.flags = 0,
447379bc100SJani Nikula 		.len = 2,
448379bc100SJani Nikula 		.buf = out_buf,
449379bc100SJani Nikula 	};
450379bc100SJani Nikula 
451379bc100SJani Nikula 	out_buf[0] = addr;
452379bc100SJani Nikula 	out_buf[1] = ch;
453379bc100SJani Nikula 
454379bc100SJani Nikula 	if (i2c_transfer(adapter, &msg, 1) == 1) {
455379bc100SJani Nikula 		return true;
456379bc100SJani Nikula 	}
457379bc100SJani Nikula 
458379bc100SJani Nikula 	if (!ns->quiet) {
459379bc100SJani Nikula 		DRM_DEBUG_KMS("Unable to write register 0x%02x to %s:%d\n",
460379bc100SJani Nikula 			      addr, adapter->name, dvo->slave_addr);
461379bc100SJani Nikula 	}
462379bc100SJani Nikula 
463379bc100SJani Nikula 	return false;
464379bc100SJani Nikula }
465379bc100SJani Nikula 
466379bc100SJani Nikula /* National Semiconductor 2501 driver for chip on i2c bus
467379bc100SJani Nikula  * scan for the chip on the bus.
468379bc100SJani Nikula  * Hope the VBIOS initialized the PLL correctly so we can
469379bc100SJani Nikula  * talk to it. If not, it will not be seen and not detected.
470379bc100SJani Nikula  * Bummer!
471379bc100SJani Nikula  */
ns2501_init(struct intel_dvo_device * dvo,struct i2c_adapter * adapter)472379bc100SJani Nikula static bool ns2501_init(struct intel_dvo_device *dvo,
473379bc100SJani Nikula 			struct i2c_adapter *adapter)
474379bc100SJani Nikula {
475379bc100SJani Nikula 	/* this will detect the NS2501 chip on the specified i2c bus */
476379bc100SJani Nikula 	struct ns2501_priv *ns;
477379bc100SJani Nikula 	unsigned char ch;
478379bc100SJani Nikula 
479379bc100SJani Nikula 	ns = kzalloc(sizeof(struct ns2501_priv), GFP_KERNEL);
480379bc100SJani Nikula 	if (ns == NULL)
481379bc100SJani Nikula 		return false;
482379bc100SJani Nikula 
483379bc100SJani Nikula 	dvo->i2c_bus = adapter;
484379bc100SJani Nikula 	dvo->dev_priv = ns;
485379bc100SJani Nikula 	ns->quiet = true;
486379bc100SJani Nikula 
487379bc100SJani Nikula 	if (!ns2501_readb(dvo, NS2501_VID_LO, &ch))
488379bc100SJani Nikula 		goto out;
489379bc100SJani Nikula 
490379bc100SJani Nikula 	if (ch != (NS2501_VID & 0xff)) {
491379bc100SJani Nikula 		DRM_DEBUG_KMS("ns2501 not detected got %d: from %s Slave %d.\n",
492379bc100SJani Nikula 			      ch, adapter->name, dvo->slave_addr);
493379bc100SJani Nikula 		goto out;
494379bc100SJani Nikula 	}
495379bc100SJani Nikula 
496379bc100SJani Nikula 	if (!ns2501_readb(dvo, NS2501_DID_LO, &ch))
497379bc100SJani Nikula 		goto out;
498379bc100SJani Nikula 
499379bc100SJani Nikula 	if (ch != (NS2501_DID & 0xff)) {
500379bc100SJani Nikula 		DRM_DEBUG_KMS("ns2501 not detected got %d: from %s Slave %d.\n",
501379bc100SJani Nikula 			      ch, adapter->name, dvo->slave_addr);
502379bc100SJani Nikula 		goto out;
503379bc100SJani Nikula 	}
504379bc100SJani Nikula 	ns->quiet = false;
505379bc100SJani Nikula 
506379bc100SJani Nikula 	DRM_DEBUG_KMS("init ns2501 dvo controller successfully!\n");
507379bc100SJani Nikula 
508379bc100SJani Nikula 	return true;
509379bc100SJani Nikula 
510379bc100SJani Nikula out:
511379bc100SJani Nikula 	kfree(ns);
512379bc100SJani Nikula 	return false;
513379bc100SJani Nikula }
514379bc100SJani Nikula 
ns2501_detect(struct intel_dvo_device * dvo)515379bc100SJani Nikula static enum drm_connector_status ns2501_detect(struct intel_dvo_device *dvo)
516379bc100SJani Nikula {
517379bc100SJani Nikula 	/*
518379bc100SJani Nikula 	 * This is a Laptop display, it doesn't have hotplugging.
519379bc100SJani Nikula 	 * Even if not, the detection bit of the 2501 is unreliable as
520379bc100SJani Nikula 	 * it only works for some display types.
521379bc100SJani Nikula 	 * It is even more unreliable as the PLL must be active for
522379bc100SJani Nikula 	 * allowing reading from the chiop.
523379bc100SJani Nikula 	 */
524379bc100SJani Nikula 	return connector_status_connected;
525379bc100SJani Nikula }
526379bc100SJani Nikula 
ns2501_mode_valid(struct intel_dvo_device * dvo,struct drm_display_mode * mode)527379bc100SJani Nikula static enum drm_mode_status ns2501_mode_valid(struct intel_dvo_device *dvo,
528379bc100SJani Nikula 					      struct drm_display_mode *mode)
529379bc100SJani Nikula {
530379bc100SJani Nikula 	DRM_DEBUG_KMS
531379bc100SJani Nikula 	    ("is mode valid (hdisplay=%d,htotal=%d,vdisplay=%d,vtotal=%d)\n",
532379bc100SJani Nikula 	     mode->hdisplay, mode->htotal, mode->vdisplay, mode->vtotal);
533379bc100SJani Nikula 
534379bc100SJani Nikula 	/*
535379bc100SJani Nikula 	 * Currently, these are all the modes I have data from.
536379bc100SJani Nikula 	 * More might exist. Unclear how to find the native resolution
537379bc100SJani Nikula 	 * of the panel in here so we could always accept it
538379bc100SJani Nikula 	 * by disabling the scaler.
539379bc100SJani Nikula 	 */
540379bc100SJani Nikula 	if ((mode->hdisplay == 640 && mode->vdisplay == 480 && mode->clock == 25175) ||
541379bc100SJani Nikula 	    (mode->hdisplay == 800 && mode->vdisplay == 600 && mode->clock == 40000) ||
542379bc100SJani Nikula 	    (mode->hdisplay == 1024 && mode->vdisplay == 768 && mode->clock == 65000)) {
543379bc100SJani Nikula 		return MODE_OK;
544379bc100SJani Nikula 	} else {
545379bc100SJani Nikula 		return MODE_ONE_SIZE;	/* Is this a reasonable error? */
546379bc100SJani Nikula 	}
547379bc100SJani Nikula }
548379bc100SJani Nikula 
ns2501_mode_set(struct intel_dvo_device * dvo,const struct drm_display_mode * mode,const struct drm_display_mode * adjusted_mode)549379bc100SJani Nikula static void ns2501_mode_set(struct intel_dvo_device *dvo,
550379bc100SJani Nikula 			    const struct drm_display_mode *mode,
551379bc100SJani Nikula 			    const struct drm_display_mode *adjusted_mode)
552379bc100SJani Nikula {
553379bc100SJani Nikula 	const struct ns2501_configuration *conf;
554379bc100SJani Nikula 	struct ns2501_priv *ns = (struct ns2501_priv *)(dvo->dev_priv);
555379bc100SJani Nikula 	int mode_idx, i;
556379bc100SJani Nikula 
557379bc100SJani Nikula 	DRM_DEBUG_KMS
558379bc100SJani Nikula 	    ("set mode (hdisplay=%d,htotal=%d,vdisplay=%d,vtotal=%d).\n",
559379bc100SJani Nikula 	     mode->hdisplay, mode->htotal, mode->vdisplay, mode->vtotal);
560379bc100SJani Nikula 
561379bc100SJani Nikula 	DRM_DEBUG_KMS("Detailed requested mode settings are:\n"
562379bc100SJani Nikula 			"clock		: %d kHz\n"
563379bc100SJani Nikula 			"hdisplay	: %d\n"
564379bc100SJani Nikula 			"hblank start	: %d\n"
565379bc100SJani Nikula 			"hblank end	: %d\n"
566379bc100SJani Nikula 			"hsync start	: %d\n"
567379bc100SJani Nikula 			"hsync end	: %d\n"
568379bc100SJani Nikula 			"htotal		: %d\n"
569379bc100SJani Nikula 			"hskew		: %d\n"
570379bc100SJani Nikula 			"vdisplay	: %d\n"
571379bc100SJani Nikula 			"vblank start	: %d\n"
572379bc100SJani Nikula 			"hblank end	: %d\n"
573379bc100SJani Nikula 			"vsync start	: %d\n"
574379bc100SJani Nikula 			"vsync end	: %d\n"
575379bc100SJani Nikula 			"vtotal		: %d\n",
576379bc100SJani Nikula 			adjusted_mode->crtc_clock,
577379bc100SJani Nikula 			adjusted_mode->crtc_hdisplay,
578379bc100SJani Nikula 			adjusted_mode->crtc_hblank_start,
579379bc100SJani Nikula 			adjusted_mode->crtc_hblank_end,
580379bc100SJani Nikula 			adjusted_mode->crtc_hsync_start,
581379bc100SJani Nikula 			adjusted_mode->crtc_hsync_end,
582379bc100SJani Nikula 			adjusted_mode->crtc_htotal,
583379bc100SJani Nikula 			adjusted_mode->crtc_hskew,
584379bc100SJani Nikula 			adjusted_mode->crtc_vdisplay,
585379bc100SJani Nikula 			adjusted_mode->crtc_vblank_start,
586379bc100SJani Nikula 			adjusted_mode->crtc_vblank_end,
587379bc100SJani Nikula 			adjusted_mode->crtc_vsync_start,
588379bc100SJani Nikula 			adjusted_mode->crtc_vsync_end,
589379bc100SJani Nikula 			adjusted_mode->crtc_vtotal);
590379bc100SJani Nikula 
591379bc100SJani Nikula 	if (mode->hdisplay == 640 && mode->vdisplay == 480)
592379bc100SJani Nikula 		mode_idx = MODE_640x480;
593379bc100SJani Nikula 	else if (mode->hdisplay == 800 && mode->vdisplay == 600)
594379bc100SJani Nikula 		mode_idx = MODE_800x600;
595379bc100SJani Nikula 	else if (mode->hdisplay == 1024 && mode->vdisplay == 768)
596379bc100SJani Nikula 		mode_idx = MODE_1024x768;
597379bc100SJani Nikula 	else
598379bc100SJani Nikula 		return;
599379bc100SJani Nikula 
600379bc100SJani Nikula 	/* Hopefully doing it every time won't hurt... */
601379bc100SJani Nikula 	for (i = 0; i < ARRAY_SIZE(regs_init); i++)
602379bc100SJani Nikula 		ns2501_writeb(dvo, regs_init[i].offset, regs_init[i].value);
603379bc100SJani Nikula 
604379bc100SJani Nikula 	/* Write the mode-agnostic values */
605379bc100SJani Nikula 	for (i = 0; i < ARRAY_SIZE(mode_agnostic_values); i++)
606379bc100SJani Nikula 		ns2501_writeb(dvo, mode_agnostic_values[i].offset,
607379bc100SJani Nikula 				mode_agnostic_values[i].value);
608379bc100SJani Nikula 
609379bc100SJani Nikula 	/* Write now the mode-specific configuration */
610379bc100SJani Nikula 	conf = ns2501_modes + mode_idx;
611379bc100SJani Nikula 	ns->conf = conf;
612379bc100SJani Nikula 
613379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG8, conf->conf);
614379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG1B, conf->pll_a);
615379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG1C, conf->pll_b & 0xff);
616379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG1D, conf->pll_b >> 8);
617379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC1, conf->hstart & 0xff);
618379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC2, conf->hstart >> 8);
619379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC3, conf->hstop & 0xff);
620379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC4, conf->hstop >> 8);
621379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC5, conf->vstart & 0xff);
622379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC6, conf->vstart >> 8);
623379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC7, conf->vstop & 0xff);
624379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC8, conf->vstop >> 8);
625379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG80, conf->vsync & 0xff);
626379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG81, conf->vsync >> 8);
627379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG82, conf->vtotal & 0xff);
628379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG83, conf->vtotal >> 8);
629379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG98, conf->hpos & 0xff);
630379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG99, conf->hpos >> 8);
631379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG8E, conf->vpos & 0xff);
632379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG8F, conf->vpos >> 8);
633379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG9C, conf->voffs & 0xff);
634379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG9D, conf->voffs >> 8);
635379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGB8, conf->hscale & 0xff);
636379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGB9, conf->hscale >> 8);
637379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG10, conf->vscale & 0xff);
638379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG11, conf->vscale >> 8);
639379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGF9, conf->dither);
640379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REG41, conf->syncb);
641379bc100SJani Nikula 	ns2501_writeb(dvo, NS2501_REGC0, conf->sync);
642379bc100SJani Nikula }
643379bc100SJani Nikula 
644379bc100SJani Nikula /* set the NS2501 power state */
ns2501_get_hw_state(struct intel_dvo_device * dvo)645379bc100SJani Nikula static bool ns2501_get_hw_state(struct intel_dvo_device *dvo)
646379bc100SJani Nikula {
647379bc100SJani Nikula 	unsigned char ch;
648379bc100SJani Nikula 
649379bc100SJani Nikula 	if (!ns2501_readb(dvo, NS2501_REG8, &ch))
650379bc100SJani Nikula 		return false;
651379bc100SJani Nikula 
652379bc100SJani Nikula 	return ch & NS2501_8_PD;
653379bc100SJani Nikula }
654379bc100SJani Nikula 
655379bc100SJani Nikula /* set the NS2501 power state */
ns2501_dpms(struct intel_dvo_device * dvo,bool enable)656379bc100SJani Nikula static void ns2501_dpms(struct intel_dvo_device *dvo, bool enable)
657379bc100SJani Nikula {
658379bc100SJani Nikula 	struct ns2501_priv *ns = (struct ns2501_priv *)(dvo->dev_priv);
659379bc100SJani Nikula 
660379bc100SJani Nikula 	DRM_DEBUG_KMS("Trying set the dpms of the DVO to %i\n", enable);
661379bc100SJani Nikula 
662379bc100SJani Nikula 	if (enable) {
663379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REGC0, ns->conf->sync | 0x08);
664379bc100SJani Nikula 
665379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG41, ns->conf->syncb);
666379bc100SJani Nikula 
667379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG34, NS2501_34_ENABLE_OUTPUT);
668379bc100SJani Nikula 		msleep(15);
669379bc100SJani Nikula 
670379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG8,
671379bc100SJani Nikula 				ns->conf->conf | NS2501_8_BPAS);
672379bc100SJani Nikula 		if (!(ns->conf->conf & NS2501_8_BPAS))
673379bc100SJani Nikula 			ns2501_writeb(dvo, NS2501_REG8, ns->conf->conf);
674379bc100SJani Nikula 		msleep(200);
675379bc100SJani Nikula 
676379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG34,
677379bc100SJani Nikula 			NS2501_34_ENABLE_OUTPUT | NS2501_34_ENABLE_BACKLIGHT);
678379bc100SJani Nikula 
679379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REGC0, ns->conf->sync);
680379bc100SJani Nikula 	} else {
681379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG34, NS2501_34_ENABLE_OUTPUT);
682379bc100SJani Nikula 		msleep(200);
683379bc100SJani Nikula 
684379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG8, NS2501_8_VEN | NS2501_8_HEN |
685379bc100SJani Nikula 				NS2501_8_BPAS);
686379bc100SJani Nikula 		msleep(15);
687379bc100SJani Nikula 
688379bc100SJani Nikula 		ns2501_writeb(dvo, NS2501_REG34, 0x00);
689379bc100SJani Nikula 	}
690379bc100SJani Nikula }
691379bc100SJani Nikula 
ns2501_destroy(struct intel_dvo_device * dvo)692379bc100SJani Nikula static void ns2501_destroy(struct intel_dvo_device *dvo)
693379bc100SJani Nikula {
694379bc100SJani Nikula 	struct ns2501_priv *ns = dvo->dev_priv;
695379bc100SJani Nikula 
696379bc100SJani Nikula 	if (ns) {
697379bc100SJani Nikula 		kfree(ns);
698379bc100SJani Nikula 		dvo->dev_priv = NULL;
699379bc100SJani Nikula 	}
700379bc100SJani Nikula }
701379bc100SJani Nikula 
702379bc100SJani Nikula const struct intel_dvo_dev_ops ns2501_ops = {
703379bc100SJani Nikula 	.init = ns2501_init,
704379bc100SJani Nikula 	.detect = ns2501_detect,
705379bc100SJani Nikula 	.mode_valid = ns2501_mode_valid,
706379bc100SJani Nikula 	.mode_set = ns2501_mode_set,
707379bc100SJani Nikula 	.dpms = ns2501_dpms,
708379bc100SJani Nikula 	.get_hw_state = ns2501_get_hw_state,
709379bc100SJani Nikula 	.destroy = ns2501_destroy,
710379bc100SJani Nikula };
711