2 * Copyright 2003 NVIDIA, Corporation
3 * Copyright 2006 Dave Airlie
4 * Copyright 2007 Maarten Maathuis
5 * Copyright 2007-2009 Stuart Bennett
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #include <drm/drm_crtc_helper.h>
29 #include "nouveau_drv.h"
30 #include "nouveau_encoder.h"
31 #include "nouveau_connector.h"
32 #include "nouveau_crtc.h"
36 #include <subdev/bios/gpio.h>
37 #include <subdev/gpio.h>
38 #include <subdev/timer.h>
40 int nv04_dac_output_offset(struct drm_encoder
*encoder
)
42 struct dcb_output
*dcb
= nouveau_encoder(encoder
)->dcb
;
45 if (dcb
->or & (8 | DCB_OUTPUT_C
))
47 if (dcb
->or & (8 | DCB_OUTPUT_B
))
54 * arbitrary limit to number of sense oscillations tolerated in one sample
55 * period (observed to be at least 13 in "nvidia")
57 #define MAX_HBLANK_OSC 20
60 * arbitrary limit to number of conflicting sample pairs to tolerate at a
61 * voltage step (observed to be at least 5 in "nvidia")
63 #define MAX_SAMPLE_PAIRS 10
65 static int sample_load_twice(struct drm_device
*dev
, bool sense
[2])
67 struct nouveau_drm
*drm
= nouveau_drm(dev
);
68 struct nvif_object
*device
= &drm
->client
.device
.object
;
71 for (i
= 0; i
< 2; i
++) {
72 bool sense_a
, sense_b
, sense_b_prime
;
76 * wait for bit 0 clear -- out of hblank -- (say reg value 0x4),
77 * then wait for transition 0x4->0x5->0x4: enter hblank, leave
79 * use a 10ms timeout (guards against crtc being inactive, in
80 * which case blank state would never change)
82 if (nvif_msec(&drm
->client
.device
, 10,
83 if (!(nvif_rd32(device
, NV_PRMCIO_INP0__COLOR
) & 1))
88 if (nvif_msec(&drm
->client
.device
, 10,
89 if ( (nvif_rd32(device
, NV_PRMCIO_INP0__COLOR
) & 1))
94 if (nvif_msec(&drm
->client
.device
, 10,
95 if (!(nvif_rd32(device
, NV_PRMCIO_INP0__COLOR
) & 1))
101 /* when level triggers, sense is _LO_ */
102 sense_a
= nvif_rd08(device
, NV_PRMCIO_INP0
) & 0x10;
104 /* take another reading until it agrees with sense_a... */
107 sense_b
= nvif_rd08(device
, NV_PRMCIO_INP0
) & 0x10;
108 if (sense_a
!= sense_b
) {
110 nvif_rd08(device
, NV_PRMCIO_INP0
) & 0x10;
111 if (sense_b
== sense_b_prime
) {
112 /* ... unless two consecutive subsequent
113 * samples agree; sense_a is replaced */
115 /* force mis-match so we loop */
119 } while ((sense_a
!= sense_b
) && ++j
< MAX_HBLANK_OSC
);
121 if (j
== MAX_HBLANK_OSC
)
122 /* with so much oscillation, default to sense:LO */
131 static enum drm_connector_status
nv04_dac_detect(struct drm_encoder
*encoder
,
132 struct drm_connector
*connector
)
134 struct drm_device
*dev
= encoder
->dev
;
135 struct nvif_object
*device
= &nouveau_drm(dev
)->client
.device
.object
;
136 struct nouveau_drm
*drm
= nouveau_drm(dev
);
137 uint8_t saved_seq1
, saved_pi
, saved_rpc1
, saved_cr_mode
;
138 uint8_t saved_palette0
[3], saved_palette_mask
;
139 uint32_t saved_rtest_ctrl
, saved_rgen_ctrl
;
145 * for this detection to work, there needs to be a mode set up on the
146 * CRTC. this is presumed to be the case
149 if (nv_two_heads(dev
))
150 /* only implemented for head A for now */
153 saved_cr_mode
= NVReadVgaCrtc(dev
, 0, NV_CIO_CR_MODE_INDEX
);
154 NVWriteVgaCrtc(dev
, 0, NV_CIO_CR_MODE_INDEX
, saved_cr_mode
| 0x80);
156 saved_seq1
= NVReadVgaSeq(dev
, 0, NV_VIO_SR_CLOCK_INDEX
);
157 NVWriteVgaSeq(dev
, 0, NV_VIO_SR_CLOCK_INDEX
, saved_seq1
& ~0x20);
159 saved_rtest_ctrl
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
);
160 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
,
161 saved_rtest_ctrl
& ~NV_PRAMDAC_TEST_CONTROL_PWRDWN_DAC_OFF
);
165 saved_pi
= NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_PIXEL_INDEX
);
166 NVWriteVgaCrtc(dev
, 0, NV_CIO_CRE_PIXEL_INDEX
,
167 saved_pi
& ~(0x80 | MASK(NV_CIO_CRE_PIXEL_FORMAT
)));
168 saved_rpc1
= NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_RPC1_INDEX
);
169 NVWriteVgaCrtc(dev
, 0, NV_CIO_CRE_RPC1_INDEX
, saved_rpc1
& ~0xc0);
171 nvif_wr08(device
, NV_PRMDIO_READ_MODE_ADDRESS
, 0x0);
172 for (i
= 0; i
< 3; i
++)
173 saved_palette0
[i
] = nvif_rd08(device
, NV_PRMDIO_PALETTE_DATA
);
174 saved_palette_mask
= nvif_rd08(device
, NV_PRMDIO_PIXEL_MASK
);
175 nvif_wr08(device
, NV_PRMDIO_PIXEL_MASK
, 0);
177 saved_rgen_ctrl
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_GENERAL_CONTROL
);
178 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_GENERAL_CONTROL
,
179 (saved_rgen_ctrl
& ~(NV_PRAMDAC_GENERAL_CONTROL_BPC_8BITS
|
180 NV_PRAMDAC_GENERAL_CONTROL_TERMINATION_75OHM
)) |
181 NV_PRAMDAC_GENERAL_CONTROL_PIXMIX_ON
);
183 blue
= 8; /* start of test range */
188 nvif_wr08(device
, NV_PRMDIO_WRITE_MODE_ADDRESS
, 0);
189 nvif_wr08(device
, NV_PRMDIO_PALETTE_DATA
, 0);
190 nvif_wr08(device
, NV_PRMDIO_PALETTE_DATA
, 0);
191 /* testing blue won't find monochrome monitors. I don't care */
192 nvif_wr08(device
, NV_PRMDIO_PALETTE_DATA
, blue
);
195 /* take sample pairs until both samples in the pair agree */
197 if (sample_load_twice(dev
, sense_pair
))
199 } while ((sense_pair
[0] != sense_pair
[1]) &&
200 ++i
< MAX_SAMPLE_PAIRS
);
202 if (i
== MAX_SAMPLE_PAIRS
)
203 /* too much oscillation defaults to LO */
206 sense
= sense_pair
[0];
209 * if sense goes LO before blue ramps to 0x18, monitor is not connected.
210 * ergo, if blue gets to 0x18, monitor must be connected
212 } while (++blue
< 0x18 && sense
);
215 nvif_wr08(device
, NV_PRMDIO_PIXEL_MASK
, saved_palette_mask
);
216 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_GENERAL_CONTROL
, saved_rgen_ctrl
);
217 nvif_wr08(device
, NV_PRMDIO_WRITE_MODE_ADDRESS
, 0);
218 for (i
= 0; i
< 3; i
++)
219 nvif_wr08(device
, NV_PRMDIO_PALETTE_DATA
, saved_palette0
[i
]);
220 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
, saved_rtest_ctrl
);
221 NVWriteVgaCrtc(dev
, 0, NV_CIO_CRE_PIXEL_INDEX
, saved_pi
);
222 NVWriteVgaCrtc(dev
, 0, NV_CIO_CRE_RPC1_INDEX
, saved_rpc1
);
223 NVWriteVgaSeq(dev
, 0, NV_VIO_SR_CLOCK_INDEX
, saved_seq1
);
224 NVWriteVgaCrtc(dev
, 0, NV_CIO_CR_MODE_INDEX
, saved_cr_mode
);
227 NV_DEBUG(drm
, "Load detected on head A\n");
228 return connector_status_connected
;
231 return connector_status_disconnected
;
234 uint32_t nv17_dac_sample_load(struct drm_encoder
*encoder
)
236 struct drm_device
*dev
= encoder
->dev
;
237 struct nouveau_drm
*drm
= nouveau_drm(dev
);
238 struct nvif_object
*device
= &nouveau_drm(dev
)->client
.device
.object
;
239 struct nvkm_gpio
*gpio
= nvxx_gpio(&drm
->client
.device
);
240 struct dcb_output
*dcb
= nouveau_encoder(encoder
)->dcb
;
241 uint32_t sample
, testval
, regoffset
= nv04_dac_output_offset(encoder
);
242 uint32_t saved_powerctrl_2
= 0, saved_powerctrl_4
= 0, saved_routput
,
243 saved_rtest_ctrl
, saved_gpio0
= 0, saved_gpio1
= 0, temp
, routput
;
246 #define RGB_TEST_DATA(r, g, b) (r << 0 | g << 10 | b << 20)
247 if (dcb
->type
== DCB_OUTPUT_TV
) {
248 testval
= RGB_TEST_DATA(0xa0, 0xa0, 0xa0);
250 if (drm
->vbios
.tvdactestval
)
251 testval
= drm
->vbios
.tvdactestval
;
253 testval
= RGB_TEST_DATA(0x140, 0x140, 0x140); /* 0x94050140 */
255 if (drm
->vbios
.dactestval
)
256 testval
= drm
->vbios
.dactestval
;
259 saved_rtest_ctrl
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ regoffset
);
260 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ regoffset
,
261 saved_rtest_ctrl
& ~NV_PRAMDAC_TEST_CONTROL_PWRDWN_DAC_OFF
);
263 saved_powerctrl_2
= nvif_rd32(device
, NV_PBUS_POWERCTRL_2
);
265 nvif_wr32(device
, NV_PBUS_POWERCTRL_2
, saved_powerctrl_2
& 0xd7ffffff);
266 if (regoffset
== 0x68) {
267 saved_powerctrl_4
= nvif_rd32(device
, NV_PBUS_POWERCTRL_4
);
268 nvif_wr32(device
, NV_PBUS_POWERCTRL_4
, saved_powerctrl_4
& 0xffffffcf);
272 saved_gpio1
= nvkm_gpio_get(gpio
, 0, DCB_GPIO_TVDAC1
, 0xff);
273 saved_gpio0
= nvkm_gpio_get(gpio
, 0, DCB_GPIO_TVDAC0
, 0xff);
274 nvkm_gpio_set(gpio
, 0, DCB_GPIO_TVDAC1
, 0xff, dcb
->type
== DCB_OUTPUT_TV
);
275 nvkm_gpio_set(gpio
, 0, DCB_GPIO_TVDAC0
, 0xff, dcb
->type
== DCB_OUTPUT_TV
);
280 saved_routput
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ regoffset
);
281 head
= (saved_routput
& 0x100) >> 8;
283 /* if there's a spare crtc, using it will minimise flicker */
284 if (!(NVReadVgaCrtc(dev
, head
, NV_CIO_CRE_RPC1_INDEX
) & 0xC0))
287 /* nv driver and nv31 use 0xfffffeee, nv34 and 6600 use 0xfffffece */
288 routput
= (saved_routput
& 0xfffffece) | head
<< 8;
290 if (drm
->client
.device
.info
.family
>= NV_DEVICE_INFO_V0_CURIE
) {
291 if (dcb
->type
== DCB_OUTPUT_TV
)
292 routput
|= 0x1a << 16;
294 routput
&= ~(0x1a << 16);
297 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ regoffset
, routput
);
300 temp
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ regoffset
);
301 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ regoffset
, temp
| 1);
303 NVWriteRAMDAC(dev
, head
, NV_PRAMDAC_TESTPOINT_DATA
,
304 NV_PRAMDAC_TESTPOINT_DATA_NOTBLANK
| testval
);
305 temp
= NVReadRAMDAC(dev
, head
, NV_PRAMDAC_TEST_CONTROL
);
306 NVWriteRAMDAC(dev
, head
, NV_PRAMDAC_TEST_CONTROL
,
307 temp
| NV_PRAMDAC_TEST_CONTROL_TP_INS_EN_ASSERTED
);
310 sample
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ regoffset
);
311 /* do it again just in case it's a residual current */
312 sample
&= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ regoffset
);
314 temp
= NVReadRAMDAC(dev
, head
, NV_PRAMDAC_TEST_CONTROL
);
315 NVWriteRAMDAC(dev
, head
, NV_PRAMDAC_TEST_CONTROL
,
316 temp
& ~NV_PRAMDAC_TEST_CONTROL_TP_INS_EN_ASSERTED
);
317 NVWriteRAMDAC(dev
, head
, NV_PRAMDAC_TESTPOINT_DATA
, 0);
319 /* bios does something more complex for restoring, but I think this is good enough */
320 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ regoffset
, saved_routput
);
321 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ regoffset
, saved_rtest_ctrl
);
322 if (regoffset
== 0x68)
323 nvif_wr32(device
, NV_PBUS_POWERCTRL_4
, saved_powerctrl_4
);
324 nvif_wr32(device
, NV_PBUS_POWERCTRL_2
, saved_powerctrl_2
);
327 nvkm_gpio_set(gpio
, 0, DCB_GPIO_TVDAC1
, 0xff, saved_gpio1
);
328 nvkm_gpio_set(gpio
, 0, DCB_GPIO_TVDAC0
, 0xff, saved_gpio0
);
334 static enum drm_connector_status
335 nv17_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
337 struct nouveau_drm
*drm
= nouveau_drm(encoder
->dev
);
338 struct dcb_output
*dcb
= nouveau_encoder(encoder
)->dcb
;
340 if (nv04_dac_in_use(encoder
))
341 return connector_status_disconnected
;
343 if (nv17_dac_sample_load(encoder
) &
344 NV_PRAMDAC_TEST_CONTROL_SENSEB_ALLHI
) {
345 NV_DEBUG(drm
, "Load detected on output %c\n",
347 return connector_status_connected
;
349 return connector_status_disconnected
;
353 static bool nv04_dac_mode_fixup(struct drm_encoder
*encoder
,
354 const struct drm_display_mode
*mode
,
355 struct drm_display_mode
*adjusted_mode
)
357 if (nv04_dac_in_use(encoder
))
363 static void nv04_dac_prepare(struct drm_encoder
*encoder
)
365 const struct drm_encoder_helper_funcs
*helper
= encoder
->helper_private
;
366 struct drm_device
*dev
= encoder
->dev
;
367 int head
= nouveau_crtc(encoder
->crtc
)->index
;
369 helper
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
371 nv04_dfp_disable(dev
, head
);
374 static void nv04_dac_mode_set(struct drm_encoder
*encoder
,
375 struct drm_display_mode
*mode
,
376 struct drm_display_mode
*adjusted_mode
)
378 struct drm_device
*dev
= encoder
->dev
;
379 struct nouveau_drm
*drm
= nouveau_drm(dev
);
380 int head
= nouveau_crtc(encoder
->crtc
)->index
;
382 if (nv_gf4_disp_arch(dev
)) {
383 struct drm_encoder
*rebind
;
384 uint32_t dac_offset
= nv04_dac_output_offset(encoder
);
387 /* bit 16-19 are bits that are set on some G70 cards,
388 * but don't seem to have much effect */
389 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ dac_offset
,
390 head
<< 8 | NV_PRAMDAC_DACCLK_SEL_DACCLK
);
391 /* force any other vga encoders to bind to the other crtc */
392 list_for_each_entry(rebind
, &dev
->mode_config
.encoder_list
, head
) {
393 if (rebind
== encoder
394 || nouveau_encoder(rebind
)->dcb
->type
!= DCB_OUTPUT_ANALOG
)
397 dac_offset
= nv04_dac_output_offset(rebind
);
398 otherdac
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ dac_offset
);
399 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ dac_offset
,
400 (otherdac
& ~0x0100) | (head
^ 1) << 8);
404 /* This could use refinement for flatpanels, but it should work this way */
405 if (drm
->client
.device
.info
.chipset
< 0x44)
406 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ nv04_dac_output_offset(encoder
), 0xf0000000);
408 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_TEST_CONTROL
+ nv04_dac_output_offset(encoder
), 0x00100000);
411 static void nv04_dac_commit(struct drm_encoder
*encoder
)
413 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
414 struct nouveau_drm
*drm
= nouveau_drm(encoder
->dev
);
415 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
416 const struct drm_encoder_helper_funcs
*helper
= encoder
->helper_private
;
418 helper
->dpms(encoder
, DRM_MODE_DPMS_ON
);
420 NV_DEBUG(drm
, "Output %s is running on CRTC %d using output %c\n",
421 nouveau_encoder_connector_get(nv_encoder
)->base
.name
,
422 nv_crtc
->index
, '@' + ffs(nv_encoder
->dcb
->or));
425 void nv04_dac_update_dacclk(struct drm_encoder
*encoder
, bool enable
)
427 struct drm_device
*dev
= encoder
->dev
;
428 struct dcb_output
*dcb
= nouveau_encoder(encoder
)->dcb
;
430 if (nv_gf4_disp_arch(dev
)) {
431 uint32_t *dac_users
= &nv04_display(dev
)->dac_users
[ffs(dcb
->or) - 1];
432 int dacclk_off
= NV_PRAMDAC_DACCLK
+ nv04_dac_output_offset(encoder
);
433 uint32_t dacclk
= NVReadRAMDAC(dev
, 0, dacclk_off
);
436 *dac_users
|= 1 << dcb
->index
;
437 NVWriteRAMDAC(dev
, 0, dacclk_off
, dacclk
| NV_PRAMDAC_DACCLK_SEL_DACCLK
);
440 *dac_users
&= ~(1 << dcb
->index
);
442 NVWriteRAMDAC(dev
, 0, dacclk_off
,
443 dacclk
& ~NV_PRAMDAC_DACCLK_SEL_DACCLK
);
448 /* Check if the DAC corresponding to 'encoder' is being used by
450 bool nv04_dac_in_use(struct drm_encoder
*encoder
)
452 struct drm_device
*dev
= encoder
->dev
;
453 struct dcb_output
*dcb
= nouveau_encoder(encoder
)->dcb
;
455 return nv_gf4_disp_arch(encoder
->dev
) &&
456 (nv04_display(dev
)->dac_users
[ffs(dcb
->or) - 1] & ~(1 << dcb
->index
));
459 static void nv04_dac_dpms(struct drm_encoder
*encoder
, int mode
)
461 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
462 struct nouveau_drm
*drm
= nouveau_drm(encoder
->dev
);
464 if (nv_encoder
->last_dpms
== mode
)
466 nv_encoder
->last_dpms
= mode
;
468 NV_DEBUG(drm
, "Setting dpms mode %d on vga encoder (output %d)\n",
469 mode
, nv_encoder
->dcb
->index
);
471 nv04_dac_update_dacclk(encoder
, mode
== DRM_MODE_DPMS_ON
);
474 static void nv04_dac_save(struct drm_encoder
*encoder
)
476 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
477 struct drm_device
*dev
= encoder
->dev
;
479 if (nv_gf4_disp_arch(dev
))
480 nv_encoder
->restore
.output
= NVReadRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+
481 nv04_dac_output_offset(encoder
));
484 static void nv04_dac_restore(struct drm_encoder
*encoder
)
486 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
487 struct drm_device
*dev
= encoder
->dev
;
489 if (nv_gf4_disp_arch(dev
))
490 NVWriteRAMDAC(dev
, 0, NV_PRAMDAC_DACCLK
+ nv04_dac_output_offset(encoder
),
491 nv_encoder
->restore
.output
);
493 nv_encoder
->last_dpms
= NV_DPMS_CLEARED
;
496 static void nv04_dac_destroy(struct drm_encoder
*encoder
)
498 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
500 drm_encoder_cleanup(encoder
);
504 static const struct drm_encoder_helper_funcs nv04_dac_helper_funcs
= {
505 .dpms
= nv04_dac_dpms
,
506 .mode_fixup
= nv04_dac_mode_fixup
,
507 .prepare
= nv04_dac_prepare
,
508 .commit
= nv04_dac_commit
,
509 .mode_set
= nv04_dac_mode_set
,
510 .detect
= nv04_dac_detect
513 static const struct drm_encoder_helper_funcs nv17_dac_helper_funcs
= {
514 .dpms
= nv04_dac_dpms
,
515 .mode_fixup
= nv04_dac_mode_fixup
,
516 .prepare
= nv04_dac_prepare
,
517 .commit
= nv04_dac_commit
,
518 .mode_set
= nv04_dac_mode_set
,
519 .detect
= nv17_dac_detect
522 static const struct drm_encoder_funcs nv04_dac_funcs
= {
523 .destroy
= nv04_dac_destroy
,
527 nv04_dac_create(struct drm_connector
*connector
, struct dcb_output
*entry
)
529 const struct drm_encoder_helper_funcs
*helper
;
530 struct nouveau_encoder
*nv_encoder
= NULL
;
531 struct drm_device
*dev
= connector
->dev
;
532 struct drm_encoder
*encoder
;
534 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
538 encoder
= to_drm_encoder(nv_encoder
);
540 nv_encoder
->dcb
= entry
;
541 nv_encoder
->or = ffs(entry
->or) - 1;
543 nv_encoder
->enc_save
= nv04_dac_save
;
544 nv_encoder
->enc_restore
= nv04_dac_restore
;
546 if (nv_gf4_disp_arch(dev
))
547 helper
= &nv17_dac_helper_funcs
;
549 helper
= &nv04_dac_helper_funcs
;
551 drm_encoder_init(dev
, encoder
, &nv04_dac_funcs
, DRM_MODE_ENCODER_DAC
,
553 drm_encoder_helper_add(encoder
, helper
);
555 encoder
->possible_crtcs
= entry
->heads
;
556 encoder
->possible_clones
= 0;
558 drm_connector_attach_encoder(connector
, encoder
);