2 * Copyright (C) 2008 Maarten Maathuis.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nv50_kms_wrapper.h"
28 #include "drm_crtc_helper.h" /* be careful what you use from this */
30 /* This file serves as the interface between the common kernel modesetting code and the device dependent implementation. */
33 * Get private functions.
36 struct nv50_kms_priv *nv50_get_kms_priv(struct drm_device *dev)
38 struct drm_nouveau_private *dev_priv = dev->dev_private;
39 return dev_priv->kms_priv;
43 * Allocation functions.
46 static void *nv50_kms_alloc_crtc(struct drm_device *dev)
48 struct nv50_kms_priv *kms_priv = nv50_get_kms_priv(dev);
49 struct nv50_kms_crtc *crtc = kzalloc(sizeof(struct nv50_kms_crtc), GFP_KERNEL);
54 list_add_tail(&crtc->item, &kms_priv->crtcs);
59 static void *nv50_kms_alloc_output(struct drm_device *dev)
61 struct nv50_kms_priv *kms_priv = nv50_get_kms_priv(dev);
62 struct nv50_kms_encoder *encoder = kzalloc(sizeof(struct nv50_kms_encoder), GFP_KERNEL);
67 list_add_tail(&encoder->item, &kms_priv->encoders);
69 return &(encoder->priv);
72 static void *nv50_kms_alloc_connector(struct drm_device *dev)
74 struct nv50_kms_priv *kms_priv = nv50_get_kms_priv(dev);
75 struct nv50_kms_connector *connector = kzalloc(sizeof(struct nv50_kms_connector), GFP_KERNEL);
80 list_add_tail(&connector->item, &kms_priv->connectors);
82 return &(connector->priv);
85 static void nv50_kms_free_crtc(void *crtc)
87 struct nv50_kms_crtc *kms_crtc = from_nv50_crtc(crtc);
89 list_del(&kms_crtc->item);
94 static void nv50_kms_free_output(void *output)
96 struct nv50_kms_encoder *kms_encoder = from_nv50_output(output);
98 list_del(&kms_encoder->item);
103 static void nv50_kms_free_connector(void *connector)
105 struct nv50_kms_connector *kms_connector = from_nv50_connector(connector);
107 list_del(&kms_connector->item);
109 kfree(kms_connector);
113 * Mode conversion functions.
116 static struct nouveau_hw_mode *nv50_kms_to_hw_mode(struct drm_display_mode *mode)
118 struct nouveau_hw_mode *hw_mode = kzalloc(sizeof(struct nouveau_hw_mode), GFP_KERNEL);
122 /* create hw values. */
123 hw_mode->clock = mode->clock;
124 hw_mode->flags = hw_mode->flags;
126 hw_mode->hdisplay = mode->hdisplay;
127 hw_mode->hsync_start = mode->hsync_start;
128 hw_mode->hsync_end = mode->hsync_end;
129 hw_mode->htotal = mode->htotal;
131 hw_mode->hblank_start = mode->hdisplay + 1;
132 hw_mode->hblank_end = mode->htotal;
134 hw_mode->vdisplay = mode->vdisplay;
135 hw_mode->vsync_start = mode->vsync_start;
136 hw_mode->vsync_end = mode->vsync_end;
137 hw_mode->vtotal = mode->vtotal;
139 hw_mode->vblank_start = mode->vdisplay + 1;
140 hw_mode->vblank_end = mode->vtotal;
146 * State mirroring functions.
149 static void nv50_kms_mirror_routing(struct drm_device *dev)
151 struct nv50_display *display = nv50_get_display(dev);
152 struct nv50_crtc *crtc = NULL;
153 struct nv50_output *output = NULL;
154 struct nv50_connector *connector = NULL;
155 struct drm_connector *drm_connector = NULL;
157 /* Wipe all previous connections. */
158 list_for_each_entry(connector, &display->connectors, head) {
159 connector->output = NULL;
162 list_for_each_entry(output, &display->outputs, head) {
166 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
167 if (drm_connector->encoder) {
168 output = to_nv50_output(drm_connector->encoder);
169 connector = to_nv50_connector(drm_connector);
171 /* hook up output to connector. */
172 connector->output = output;
174 if (drm_connector->encoder->crtc) {
175 crtc = to_nv50_crtc(drm_connector->encoder->crtc);
177 /* hook up output to crtc. */
188 static void nv50_kms_framebuffer_destroy(struct drm_framebuffer *drm_framebuffer)
190 drm_framebuffer_cleanup(drm_framebuffer);
192 kfree(drm_framebuffer);
195 static const struct drm_framebuffer_funcs nv50_kms_fb_funcs = {
196 .destroy = nv50_kms_framebuffer_destroy,
200 * Mode config functions.
203 static struct drm_framebuffer *nv50_kms_framebuffer_create(struct drm_device *dev,
204 struct drm_file *file_priv, struct drm_mode_fb_cmd *mode_cmd)
206 struct drm_framebuffer *drm_framebuffer = kzalloc(sizeof(struct drm_framebuffer), GFP_KERNEL);
207 if (!drm_framebuffer)
210 drm_framebuffer_init(dev, drm_framebuffer, &nv50_kms_fb_funcs);
211 drm_helper_mode_fill_fb_struct(drm_framebuffer, mode_cmd);
213 return drm_framebuffer;
216 static int nv50_kms_fb_changed(struct drm_device *dev)
218 return 0; /* not needed until nouveaufb? */
221 static const struct drm_mode_config_funcs nv50_kms_mode_funcs = {
223 .fb_create = nv50_kms_framebuffer_create,
224 .fb_changed = nv50_kms_fb_changed,
231 static int nv50_kms_crtc_cursor_set(struct drm_crtc *drm_crtc, uint32_t buffer_handle,
232 uint32_t width, uint32_t height)
234 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
235 struct nv50_display *display = nv50_get_display(crtc->dev);
238 if (width != 64 || height != 64)
241 rval = crtc->cursor->set_bo(crtc, (drm_handle_t) buffer_handle);
246 /* in case this triggers any other cursor changes */
247 display->update(display);
252 static int nv50_kms_crtc_cursor_move(struct drm_crtc *drm_crtc, int x, int y)
254 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
256 return crtc->cursor->set_pos(crtc, x, y);
259 void nv50_kms_crtc_gamma_set(struct drm_crtc *drm_crtc, u16 *r, u16 *g, u16 *b,
262 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
267 crtc->lut->set(crtc, (uint16_t *)r, (uint16_t *)g, (uint16_t *)b);
270 int nv50_kms_crtc_set_config(struct drm_mode_set *set)
273 uint32_t crtc_mask = 0;
274 struct drm_device *dev = NULL;
275 struct drm_nouveau_private *dev_priv = NULL;
276 struct nv50_display *display = NULL;
277 struct drm_connector *drm_connector = NULL;
278 struct drm_encoder *drm_encoder = NULL;
279 struct drm_crtc *drm_crtc = NULL;
281 struct nv50_crtc *crtc = NULL;
282 struct nv50_output *output = NULL;
283 struct nv50_connector *connector = NULL;
284 struct nouveau_hw_mode *hw_mode = NULL;
285 struct nv50_fb_info fb_info;
288 bool switch_fb = false;
289 bool modeset = false;
294 * Supported operations:
296 * - Switch framebuffer.
300 /* Sanity checking */
302 NV50_DEBUG("Sanity check failed\n");
306 if (!set->crtc || !set->connectors) {
307 NV50_DEBUG("Sanity check failed\n");
313 if (!drm_mode_equal(set->mode, &set->crtc->mode))
316 if (set->fb != set->crtc->fb)
319 if (set->x != set->crtc->x || set->y != set->crtc->y)
326 if (!modeset && !switch_fb && !blank) {
327 DRM_ERROR("There is nothing to do, bad input.\n");
331 /* Basic variable setting */
332 dev = set->crtc->dev;
333 dev_priv = dev->dev_private;
334 display = nv50_get_display(dev);
335 crtc = to_nv50_crtc(set->crtc);
338 * Wiring up the encoders and connectors.
342 /* Mode validation */
343 hw_mode = nv50_kms_to_hw_mode(set->mode);
345 rval = crtc->validate_mode(crtc, hw_mode);
347 if (rval != MODE_OK) {
348 NV50_DEBUG("Mode not ok\n");
352 for (i = 0; i < set->num_connectors; i++) {
353 drm_connector = set->connectors[i];
354 if (!drm_connector) {
355 NV50_DEBUG("No connector\n");
358 connector = to_nv50_connector(drm_connector);
360 output = connector->to_output(connector, connector->digital);
362 NV50_DEBUG("No output\n");
366 rval = output->validate_mode(output, hw_mode);
367 if (rval != MODE_OK) {
368 NV50_DEBUG("Mode not ok\n");
373 /* Validation done, move on to cleaning of existing structures. */
375 /* find encoders that use this crtc. */
376 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
377 if (drm_encoder->crtc == set->crtc) {
378 /* find the connector that goes with it */
379 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
380 if (drm_connector->encoder == drm_encoder) {
381 drm_connector->encoder = NULL;
385 drm_encoder->crtc = NULL;
389 /* now find if our desired encoders or connectors are in use already. */
390 for (i = 0; i < set->num_connectors; i++) {
391 drm_connector = set->connectors[i];
392 if (!drm_connector) {
393 NV50_DEBUG("No connector\n");
397 if (!drm_connector->encoder)
400 drm_encoder = drm_connector->encoder;
401 drm_connector->encoder = NULL;
403 if (!drm_encoder->crtc)
406 drm_crtc = drm_encoder->crtc;
407 drm_encoder->crtc = NULL;
409 crtc = to_nv50_crtc(drm_crtc);
410 crtc->active = false;
411 drm_crtc->enabled = false;
414 /* Time to wire up the public encoder, the private one will be handled later. */
415 for (i = 0; i < set->num_connectors; i++) {
416 drm_connector = set->connectors[i];
417 if (!drm_connector) {
418 NV50_DEBUG("No connector\n");
422 output = connector->to_output(connector, connector->digital);
424 NV50_DEBUG("No output\n");
428 /* find the encoder public structure that matches out output structure. */
429 drm_encoder = to_nv50_kms_encoder(output);
432 NV50_DEBUG("No encoder\n");
436 drm_encoder->crtc = set->crtc;
437 drm_connector->encoder = drm_encoder;
442 * Unwire encoders and connectors, etc.
446 crtc = to_nv50_crtc(drm_crtc);
448 crtc->active = false;
449 set->crtc->enabled = false;
451 /* find encoders that use this crtc. */
452 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
453 if (drm_encoder->crtc == set->crtc) {
454 /* find the connector that goes with it */
455 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
456 if (drm_connector->encoder == drm_encoder) {
457 drm_connector->encoder = NULL;
461 drm_encoder->crtc = NULL;
467 * All state should now be updated, now onto the real work.
470 /* mirror everything to the private structs */
471 nv50_kms_mirror_routing(dev);
478 /* set framebuffer */
479 set->crtc->fb = set->fb;
481 /* set private framebuffer */
482 crtc = to_nv50_crtc(set->crtc);
483 fb_info.block = find_block_by_handle(dev_priv->fb_heap, set->fb->mm_handle);
484 fb_info.width = set->fb->width;
485 fb_info.height = set->fb->height;
486 fb_info.depth = set->fb->depth;
487 fb_info.bpp = set->fb->bits_per_pixel;
488 fb_info.pitch = set->fb->pitch;
492 rval = crtc->fb->bind(crtc, &fb_info);
494 NV50_DEBUG("fb_bind failed\n");
499 /* this is !cursor_show */
500 if (!crtc->cursor->enabled) {
501 rval = crtc->cursor->enable(crtc);
503 NV50_DEBUG("cursor_enable failed\n");
513 crtc = to_nv50_crtc(set->crtc);
515 rval = crtc->blank(crtc, TRUE);
517 DRM_ERROR("blanking failed\n");
523 * Change framebuffer, without changing mode.
526 if (switch_fb && !modeset) {
527 crtc = to_nv50_crtc(set->crtc);
529 rval = crtc->blank(crtc, TRUE);
531 DRM_ERROR("blanking failed\n");
535 rval = crtc->set_fb(crtc);
537 DRM_ERROR("set_fb failed\n");
541 /* this also sets the fb offset */
542 rval = crtc->blank(crtc, FALSE);
544 DRM_ERROR("unblanking failed\n");
550 * Normal modesetting.
554 /* disconnect unused outputs */
555 list_for_each_entry(output, &display->outputs, head) {
557 crtc_mask |= 1 << output->crtc->index;
559 output->execute_mode(output, TRUE);
562 rval = crtc->set_mode(crtc, hw_mode);
564 NV50_DEBUG("crtc mode set failed\n");
568 /* find native mode. */
569 list_for_each_entry(output, &display->outputs, head) {
570 if (output->crtc != crtc)
573 *crtc->native_mode = *output->native_mode;
574 list_for_each_entry(connector, &display->connectors, head) {
575 if (connector->output != output)
578 crtc->scaling_mode = connector->scaling_mode;
582 if (crtc->scaling_mode == SCALE_PANEL)
583 crtc->use_native_mode = false;
585 crtc->use_native_mode = true;
587 break; /* no use in finding more than one mode */
590 rval = crtc->execute_mode(crtc);
592 NV50_DEBUG("crtc execute mode failed\n");
596 list_for_each_entry(output, &display->outputs, head) {
597 if (output->crtc != crtc)
600 rval = output->execute_mode(output, FALSE);
602 NV50_DEBUG("output execute mode failed\n");
607 rval = crtc->set_scale(crtc);
609 NV50_DEBUG("crtc set scale failed\n");
613 /* next line changes crtc, so putting it here is important */
614 display->last_crtc = crtc->index;
616 /* blank any unused crtcs */
617 list_for_each_entry(crtc, &display->crtcs, head) {
618 if (!(crtc_mask & (1 << crtc->index)))
619 crtc->blank(crtc, TRUE);
623 display->update(display);
630 display->update(display);
640 static void nv50_kms_crtc_destroy(struct drm_crtc *drm_crtc)
642 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
644 drm_crtc_cleanup(drm_crtc);
646 /* this will even destroy the public structure. */
650 static const struct drm_crtc_funcs nv50_kms_crtc_funcs = {
653 .cursor_set = nv50_kms_crtc_cursor_set,
654 .cursor_move = nv50_kms_crtc_cursor_move,
655 .gamma_set = nv50_kms_crtc_gamma_set,
656 .set_config = nv50_kms_crtc_set_config,
657 .destroy = nv50_kms_crtc_destroy,
660 static int nv50_kms_crtcs_init(struct drm_device *dev)
662 struct nv50_display *display = nv50_get_display(dev);
663 struct nv50_crtc *crtc = NULL;
666 * This may look a bit confusing, but:
667 * The internal structure is already allocated and so is the public one.
668 * Just a matter of getting to the memory and register it.
670 list_for_each_entry(crtc, &display->crtcs, head) {
671 struct drm_crtc *drm_crtc = to_nv50_kms_crtc(crtc);
673 drm_crtc_init(dev, drm_crtc, &nv50_kms_crtc_funcs);
683 static void nv50_kms_encoder_destroy(struct drm_encoder *drm_encoder)
685 struct nv50_output *output = to_nv50_output(drm_encoder);
687 drm_encoder_cleanup(drm_encoder);
689 /* this will even destroy the public structure. */
690 output->destroy(output);
693 static const struct drm_encoder_funcs nv50_kms_encoder_funcs = {
694 .destroy = nv50_kms_encoder_destroy,
697 static int nv50_kms_encoders_init(struct drm_device *dev)
699 struct nv50_display *display = nv50_get_display(dev);
700 struct nv50_output *output = NULL;
702 list_for_each_entry(output, &display->outputs, head) {
703 struct drm_encoder *drm_encoder = to_nv50_kms_encoder(output);
704 uint32_t type = DRM_MODE_ENCODER_NONE;
706 switch (output->type) {
708 type = DRM_MODE_ENCODER_DAC;
711 type = DRM_MODE_ENCODER_TMDS;
714 type = DRM_MODE_ENCODER_LVDS;
717 type = DRM_MODE_ENCODER_TVDAC;
720 type = DRM_MODE_ENCODER_NONE;
724 if (type == DRM_MODE_ENCODER_NONE) {
725 DRM_ERROR("DRM_MODE_ENCODER_NONE encountered\n");
729 drm_encoder_init(dev, drm_encoder, &nv50_kms_encoder_funcs, type);
731 /* I've never seen possible crtc's restricted. */
732 drm_encoder->possible_crtcs = 3;
733 drm_encoder->possible_clones = 0;
740 * Connector functions
743 void nv50_kms_connector_detect_all(struct drm_device *dev)
745 struct drm_connector *drm_connector = NULL;
747 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
748 drm_connector->funcs->detect(drm_connector);
752 static enum drm_connector_status nv50_kms_connector_detect(struct drm_connector *drm_connector)
754 struct nv50_connector *connector = to_nv50_connector(drm_connector);
755 struct drm_device *dev = drm_connector->dev;
759 connected = connector->detect(connector);
761 old_status = drm_connector->status;
764 drm_connector->status = connector_status_connected;
766 drm_connector->status = connector_status_disconnected;
768 /* update our modes whenever there is reason to */
769 if (old_status != drm_connector->status) {
770 drm_connector->funcs->fill_modes(drm_connector, 0, 0);
771 /* notify fb of changes */
772 dev->mode_config.funcs->fb_changed(dev);
775 return drm_connector->status;
778 static void nv50_kms_connector_destroy(struct drm_connector *drm_connector)
780 struct nv50_connector *connector = to_nv50_connector(drm_connector);
782 drm_sysfs_connector_remove(drm_connector);
783 drm_connector_cleanup(drm_connector);
785 /* this will even destroy the public structure. */
786 connector->destroy(connector);
790 * Detailed mode info for a standard 640x480@60Hz monitor
792 static struct drm_display_mode std_mode[] = {
793 /*{ DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 25200, 640, 656,
794 752, 800, 0, 480, 490, 492, 525, 0,
795 V_NHSYNC | V_NVSYNC) },*/ /* 640x480@60Hz */
796 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DEFAULT, 135000, 1280, 1296,
797 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
798 V_PHSYNC | V_PVSYNC) }, /* 1280x1024@75Hz */
801 static void nv50_kms_connector_fill_modes(struct drm_connector *drm_connector, uint32_t maxX, uint32_t maxY)
803 struct nv50_connector *connector = to_nv50_connector(drm_connector);
806 struct drm_display_mode *mode, *t;
807 struct edid *edid = NULL;
809 NV50_DEBUG("%s\n", drm_get_connector_name(drm_connector));
810 /* set all modes to the unverified state */
811 list_for_each_entry_safe(mode, t, &drm_connector->modes, head)
812 mode->status = MODE_UNVERIFIED;
814 connected = connector->detect(connector);
817 drm_connector->status = connector_status_connected;
819 drm_connector->status = connector_status_disconnected;
822 NV50_DEBUG("%s is disconnected\n", drm_get_connector_name(drm_connector));
823 /* TODO set EDID to NULL */
827 /* Not all connnectors have an i2c channel. */
828 if (connector->i2c_chan)
829 edid = (struct edid *) drm_do_probe_ddc_edid(&connector->i2c_chan->adapter);
832 drm_mode_connector_update_edid_property(drm_connector, edid);
833 ret = drm_add_edid_modes(drm_connector, edid);
834 connector->digital = edid->digital; /* cache */
837 if (ret) /* number of modes > 1 */
838 drm_mode_connector_list_update(drm_connector);
841 drm_mode_validate_size(drm_connector->dev, &drm_connector->modes, maxX, maxY, 0);
843 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
844 if (mode->status == MODE_OK) {
845 struct nouveau_hw_mode *hw_mode = nv50_kms_to_hw_mode(mode);
846 struct nv50_output *output = connector->to_output(connector, connector->digital);
848 mode->status = output->validate_mode(output, hw_mode);
849 /* find native mode, TODO: also check if we actually found one */
850 if (mode->status == MODE_OK) {
851 if (mode->type & DRM_MODE_TYPE_PREFERRED)
852 *output->native_mode = *hw_mode;
858 /* revalidate now that we have native mode */
859 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
860 if (mode->status == MODE_OK) {
861 struct nouveau_hw_mode *hw_mode = nv50_kms_to_hw_mode(mode);
862 struct nv50_output *output = connector->to_output(connector, connector->digital);
864 mode->status = output->validate_mode(output, hw_mode);
869 drm_mode_prune_invalid(drm_connector->dev, &drm_connector->modes, TRUE);
871 if (list_empty(&drm_connector->modes)) {
872 struct drm_display_mode *stdmode;
873 struct nouveau_hw_mode *hw_mode;
874 struct nv50_output *output;
876 NV50_DEBUG("No valid modes on %s\n", drm_get_connector_name(drm_connector));
878 /* Should we do this here ???
879 * When no valid EDID modes are available we end up
880 * here and bailed in the past, now we add a standard
881 * 640x480@60Hz mode and carry on.
883 stdmode = drm_mode_duplicate(drm_connector->dev, &std_mode[0]);
884 drm_mode_probed_add(drm_connector, stdmode);
885 drm_mode_list_concat(&drm_connector->probed_modes,
886 &drm_connector->modes);
888 /* also add it as native mode */
889 hw_mode = nv50_kms_to_hw_mode(mode);
890 output = connector->to_output(connector, connector->digital);
893 *output->native_mode = *hw_mode;
895 DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n",
896 drm_get_connector_name(drm_connector));
899 drm_mode_sort(&drm_connector->modes);
901 NV50_DEBUG("Probed modes for %s\n", drm_get_connector_name(drm_connector));
903 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
904 mode->vrefresh = drm_mode_vrefresh(mode);
906 /* is this needed, as it's unused by the driver? */
907 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
908 drm_mode_debug_printmodeline(mode);
912 static const struct drm_connector_funcs nv50_kms_connector_funcs = {
915 .detect = nv50_kms_connector_detect,
916 .destroy = nv50_kms_connector_destroy,
917 .fill_modes = nv50_kms_connector_fill_modes,
920 static int nv50_kms_connectors_init(struct drm_device *dev)
922 struct nv50_display *display = nv50_get_display(dev);
923 struct nv50_connector *connector = NULL;
926 list_for_each_entry(connector, &display->connectors, head) {
927 struct drm_connector *drm_connector = to_nv50_kms_connector(connector);
928 uint32_t type = DRM_MODE_CONNECTOR_Unknown;
930 switch (connector->type) {
932 type = DRM_MODE_CONNECTOR_VGA;
934 case CONNECTOR_DVI_D:
935 type = DRM_MODE_CONNECTOR_DVID;
937 case CONNECTOR_DVI_I:
938 type = DRM_MODE_CONNECTOR_DVII;
941 type = DRM_MODE_CONNECTOR_LVDS;
944 type = DRM_MODE_CONNECTOR_SVIDEO;
947 type = DRM_MODE_CONNECTOR_Unknown;
951 if (type == DRM_MODE_CONNECTOR_Unknown) {
952 DRM_ERROR("DRM_MODE_CONNECTOR_Unknown encountered\n");
956 /* It should be allowed sometimes, but let's be safe for the moment. */
957 drm_connector->interlace_allowed = false;
958 drm_connector->doublescan_allowed = false;
960 drm_connector_init(dev, drm_connector, &nv50_kms_connector_funcs, type);
962 /* attach encoders, possibilities are analog + digital */
963 for (i = 0; i < 2; i++) {
964 struct drm_encoder *drm_encoder = NULL;
965 struct nv50_output *output = connector->to_output(connector, i);
969 drm_encoder = to_nv50_kms_encoder(output);
971 DRM_ERROR("No struct drm_connector to match struct nv50_output\n");
975 drm_mode_connector_attach_encoder(drm_connector, drm_encoder);
978 drm_sysfs_connector_add(drm_connector);
988 int nv50_kms_init(struct drm_device *dev)
990 struct drm_nouveau_private *dev_priv = dev->dev_private;
991 struct nv50_kms_priv *kms_priv = kzalloc(sizeof(struct nv50_kms_priv), GFP_KERNEL);
992 struct nv50_display *display = NULL;
998 dev_priv->kms_priv = kms_priv;
1000 /* function pointers */
1001 /* an allocation interface that deals with the outside world, without polluting the core. */
1002 dev_priv->alloc_crtc = nv50_kms_alloc_crtc;
1003 dev_priv->alloc_output = nv50_kms_alloc_output;
1004 dev_priv->alloc_connector = nv50_kms_alloc_connector;
1006 dev_priv->free_crtc = nv50_kms_free_crtc;
1007 dev_priv->free_output = nv50_kms_free_output;
1008 dev_priv->free_connector = nv50_kms_free_connector;
1010 /* bios is needed for tables. */
1011 rval = nouveau_parse_bios(dev);
1015 /* init basic kernel modesetting */
1016 drm_mode_config_init(dev);
1018 dev->mode_config.min_width = 0;
1019 dev->mode_config.min_height = 0;
1021 dev->mode_config.funcs = (void *)&nv50_kms_mode_funcs;
1023 dev->mode_config.max_width = 8192;
1024 dev->mode_config.max_height = 8192;
1026 dev->mode_config.fb_base = dev_priv->fb_phys;
1028 /* init kms lists */
1029 INIT_LIST_HEAD(&kms_priv->crtcs);
1030 INIT_LIST_HEAD(&kms_priv->encoders);
1031 INIT_LIST_HEAD(&kms_priv->connectors);
1033 /* init the internal core, must be done first. */
1034 rval = nv50_display_create(dev);
1038 display = nv50_get_display(dev);
1045 rval = display->pre_init(display);
1049 /* init external layer */
1050 rval = nv50_kms_crtcs_init(dev);
1054 rval = nv50_kms_encoders_init(dev);
1058 rval = nv50_kms_connectors_init(dev);
1062 /* init now, this'll kill the textmode */
1063 rval = display->init(display);
1067 /* process cmdbuffer */
1068 display->update(display);
1074 dev_priv->kms_priv = NULL;
1079 int nv50_kms_destroy(struct drm_device *dev)
1081 drm_mode_config_cleanup(dev);