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 /* set bo before doing show cursor */
243 rval = crtc->cursor->set_bo(crtc, (drm_handle_t) buffer_handle);
248 crtc->cursor->visible = buffer_handle ? true : false;
251 rval = crtc->cursor->show(crtc);
254 } else { /* no handle implies hiding the cursor */
255 rval = crtc->cursor->hide(crtc);
263 /* in case this triggers any other cursor changes */
264 display->update(display);
269 static int nv50_kms_crtc_cursor_move(struct drm_crtc *drm_crtc, int x, int y)
271 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
273 return crtc->cursor->set_pos(crtc, x, y);
276 void nv50_kms_crtc_gamma_set(struct drm_crtc *drm_crtc, u16 *r, u16 *g, u16 *b,
279 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
284 crtc->lut->set(crtc, (uint16_t *)r, (uint16_t *)g, (uint16_t *)b);
287 int nv50_kms_crtc_set_config(struct drm_mode_set *set)
290 uint32_t crtc_mask = 0;
291 struct drm_device *dev = NULL;
292 struct drm_nouveau_private *dev_priv = NULL;
293 struct nv50_display *display = NULL;
294 struct drm_connector *drm_connector = NULL;
295 struct drm_encoder *drm_encoder = NULL;
296 struct drm_crtc *drm_crtc = NULL;
298 struct nv50_crtc *crtc = NULL;
299 struct nv50_output *output = NULL;
300 struct nv50_connector *connector = NULL;
301 struct nouveau_hw_mode *hw_mode = NULL;
302 struct nv50_fb_info fb_info;
305 bool switch_fb = false;
306 bool modeset = false;
311 * Supported operations:
313 * - Switch framebuffer.
317 /* Sanity checking */
319 DRM_ERROR("Sanity check failed\n");
324 DRM_ERROR("Sanity check failed\n");
330 if (!drm_mode_equal(set->mode, &set->crtc->mode))
333 if (set->fb != set->crtc->fb)
336 if (set->x != set->crtc->x || set->y != set->crtc->y)
343 if (!set->connectors && modeset) {
344 DRM_ERROR("Sanity check failed\n");
348 if (!modeset && !switch_fb && !blank) {
349 DRM_ERROR("There is nothing to do, bad input.\n");
353 /* Basic variable setting */
354 dev = set->crtc->dev;
355 dev_priv = dev->dev_private;
356 display = nv50_get_display(dev);
357 crtc = to_nv50_crtc(set->crtc);
360 * Wiring up the encoders and connectors.
364 /* Mode validation */
365 hw_mode = nv50_kms_to_hw_mode(set->mode);
367 rval = crtc->validate_mode(crtc, hw_mode);
369 if (rval != MODE_OK) {
370 DRM_ERROR("Mode not ok\n");
374 for (i = 0; i < set->num_connectors; i++) {
375 drm_connector = set->connectors[i];
376 if (!drm_connector) {
377 DRM_ERROR("No connector\n");
380 connector = to_nv50_connector(drm_connector);
382 output = connector->to_output(connector, connector->digital);
384 DRM_ERROR("No output\n");
388 rval = output->validate_mode(output, hw_mode);
389 if (rval != MODE_OK) {
390 DRM_ERROR("Mode not ok\n");
395 /* Validation done, move on to cleaning of existing structures. */
397 /* find encoders that use this crtc. */
398 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
399 if (drm_encoder->crtc == set->crtc) {
400 /* find the connector that goes with it */
401 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
402 if (drm_connector->encoder == drm_encoder) {
403 drm_connector->encoder = NULL;
407 drm_encoder->crtc = NULL;
411 /* now find if our desired encoders or connectors are in use already. */
412 for (i = 0; i < set->num_connectors; i++) {
413 drm_connector = set->connectors[i];
414 if (!drm_connector) {
415 DRM_ERROR("No connector\n");
419 if (!drm_connector->encoder)
422 drm_encoder = drm_connector->encoder;
423 drm_connector->encoder = NULL;
425 if (!drm_encoder->crtc)
428 drm_crtc = drm_encoder->crtc;
429 drm_encoder->crtc = NULL;
431 crtc = to_nv50_crtc(drm_crtc);
432 crtc->active = false;
433 drm_crtc->enabled = false;
436 /* Time to wire up the public encoder, the private one will be handled later. */
437 for (i = 0; i < set->num_connectors; i++) {
438 drm_connector = set->connectors[i];
439 if (!drm_connector) {
440 DRM_ERROR("No connector\n");
444 output = connector->to_output(connector, connector->digital);
446 DRM_ERROR("No output\n");
450 /* find the encoder public structure that matches out output structure. */
451 drm_encoder = to_nv50_kms_encoder(output);
454 DRM_ERROR("No encoder\n");
458 drm_encoder->crtc = set->crtc;
459 drm_connector->encoder = drm_encoder;
468 crtc = to_nv50_crtc(set->crtc);
470 /* keeping the encoders and connectors attached, so they can be tracked */
471 crtc->active = false;
472 set->crtc->enabled = false;
476 * All state should now be updated, now onto the real work.
479 /* mirror everything to the private structs */
480 nv50_kms_mirror_routing(dev);
487 /* set framebuffer */
488 set->crtc->fb = set->fb;
490 /* set private framebuffer */
491 crtc = to_nv50_crtc(set->crtc);
492 fb_info.block = find_block_by_handle(dev_priv->fb_heap, set->fb->mm_handle);
493 fb_info.width = set->fb->width;
494 fb_info.height = set->fb->height;
495 fb_info.depth = set->fb->depth;
496 fb_info.bpp = set->fb->bits_per_pixel;
497 fb_info.pitch = set->fb->pitch;
501 rval = crtc->fb->bind(crtc, &fb_info);
503 DRM_ERROR("fb_bind failed\n");
508 /* this is !cursor_show */
509 if (!crtc->cursor->enabled) {
510 rval = crtc->cursor->enable(crtc);
512 DRM_ERROR("cursor_enable failed\n");
522 crtc = to_nv50_crtc(set->crtc);
524 rval = crtc->blank(crtc, TRUE);
526 DRM_ERROR("blanking failed\n");
530 /* detach any outputs that are currently running on this crtc */
531 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
532 if (drm_encoder->crtc == set->crtc) {
533 output = to_nv50_output(drm_encoder);
535 rval = output->execute_mode(output, TRUE);
537 DRM_ERROR("detaching output failed\n");
545 * Change framebuffer, without changing mode.
548 if (switch_fb && !modeset && !blank) {
549 crtc = to_nv50_crtc(set->crtc);
551 rval = crtc->blank(crtc, TRUE);
553 DRM_ERROR("blanking failed\n");
557 rval = crtc->set_fb(crtc);
559 DRM_ERROR("set_fb failed\n");
563 /* this also sets the fb offset */
564 rval = crtc->blank(crtc, FALSE);
566 DRM_ERROR("unblanking failed\n");
572 * Normal modesetting.
576 /* disconnect unused outputs */
577 list_for_each_entry(output, &display->outputs, head) {
579 crtc_mask |= 1 << output->crtc->index;
581 rval = output->execute_mode(output, TRUE);
583 DRM_ERROR("detaching output failed\n");
589 rval = crtc->set_mode(crtc, hw_mode);
591 DRM_ERROR("crtc mode set failed\n");
595 /* find native mode. */
596 list_for_each_entry(output, &display->outputs, head) {
597 if (output->crtc != crtc)
600 *crtc->native_mode = *output->native_mode;
601 list_for_each_entry(connector, &display->connectors, head) {
602 if (connector->output != output)
605 crtc->scaling_mode = connector->scaling_mode;
609 if (crtc->scaling_mode == SCALE_PANEL)
610 crtc->use_native_mode = false;
612 crtc->use_native_mode = true;
614 break; /* no use in finding more than one mode */
617 rval = crtc->execute_mode(crtc);
619 DRM_ERROR("crtc execute mode failed\n");
623 list_for_each_entry(output, &display->outputs, head) {
624 if (output->crtc != crtc)
627 rval = output->execute_mode(output, FALSE);
629 DRM_ERROR("output execute mode failed\n");
634 rval = crtc->set_scale(crtc);
636 DRM_ERROR("crtc set scale failed\n");
640 /* next line changes crtc, so putting it here is important */
641 display->last_crtc = crtc->index;
643 /* blank any unused crtcs */
644 list_for_each_entry(crtc, &display->crtcs, head) {
645 if (!(crtc_mask & (1 << crtc->index)))
646 crtc->blank(crtc, TRUE);
650 display->update(display);
658 display->update(display);
668 static void nv50_kms_crtc_destroy(struct drm_crtc *drm_crtc)
670 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
672 drm_crtc_cleanup(drm_crtc);
674 /* this will even destroy the public structure. */
678 static const struct drm_crtc_funcs nv50_kms_crtc_funcs = {
681 .cursor_set = nv50_kms_crtc_cursor_set,
682 .cursor_move = nv50_kms_crtc_cursor_move,
683 .gamma_set = nv50_kms_crtc_gamma_set,
684 .set_config = nv50_kms_crtc_set_config,
685 .destroy = nv50_kms_crtc_destroy,
688 static int nv50_kms_crtcs_init(struct drm_device *dev)
690 struct nv50_display *display = nv50_get_display(dev);
691 struct nv50_crtc *crtc = NULL;
694 * This may look a bit confusing, but:
695 * The internal structure is already allocated and so is the public one.
696 * Just a matter of getting to the memory and register it.
698 list_for_each_entry(crtc, &display->crtcs, head) {
699 struct drm_crtc *drm_crtc = to_nv50_kms_crtc(crtc);
701 drm_crtc_init(dev, drm_crtc, &nv50_kms_crtc_funcs);
711 static void nv50_kms_encoder_destroy(struct drm_encoder *drm_encoder)
713 struct nv50_output *output = to_nv50_output(drm_encoder);
715 drm_encoder_cleanup(drm_encoder);
717 /* this will even destroy the public structure. */
718 output->destroy(output);
721 static const struct drm_encoder_funcs nv50_kms_encoder_funcs = {
722 .destroy = nv50_kms_encoder_destroy,
725 static int nv50_kms_encoders_init(struct drm_device *dev)
727 struct nv50_display *display = nv50_get_display(dev);
728 struct nv50_output *output = NULL;
730 list_for_each_entry(output, &display->outputs, head) {
731 struct drm_encoder *drm_encoder = to_nv50_kms_encoder(output);
732 uint32_t type = DRM_MODE_ENCODER_NONE;
734 switch (output->type) {
736 type = DRM_MODE_ENCODER_DAC;
739 type = DRM_MODE_ENCODER_TMDS;
742 type = DRM_MODE_ENCODER_LVDS;
745 type = DRM_MODE_ENCODER_TVDAC;
748 type = DRM_MODE_ENCODER_NONE;
752 if (type == DRM_MODE_ENCODER_NONE) {
753 DRM_ERROR("DRM_MODE_ENCODER_NONE encountered\n");
757 drm_encoder_init(dev, drm_encoder, &nv50_kms_encoder_funcs, type);
759 /* I've never seen possible crtc's restricted. */
760 drm_encoder->possible_crtcs = 3;
761 drm_encoder->possible_clones = 0;
768 * Connector functions
771 void nv50_kms_connector_detect_all(struct drm_device *dev)
773 struct drm_connector *drm_connector = NULL;
775 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
776 drm_connector->funcs->detect(drm_connector);
780 static enum drm_connector_status nv50_kms_connector_detect(struct drm_connector *drm_connector)
782 struct nv50_connector *connector = to_nv50_connector(drm_connector);
783 struct drm_device *dev = drm_connector->dev;
787 connected = connector->detect(connector);
789 old_status = drm_connector->status;
792 drm_connector->status = connector_status_connected;
794 drm_connector->status = connector_status_disconnected;
796 /* update our modes whenever there is reason to */
797 if (old_status != drm_connector->status) {
798 drm_connector->funcs->fill_modes(drm_connector, 0, 0);
799 /* notify fb of changes */
800 dev->mode_config.funcs->fb_changed(dev);
803 return drm_connector->status;
806 static void nv50_kms_connector_destroy(struct drm_connector *drm_connector)
808 struct nv50_connector *connector = to_nv50_connector(drm_connector);
810 drm_sysfs_connector_remove(drm_connector);
811 drm_connector_cleanup(drm_connector);
813 /* this will even destroy the public structure. */
814 connector->destroy(connector);
818 * Detailed mode info for a standard 640x480@60Hz monitor
820 static struct drm_display_mode std_mode[] = {
821 /*{ DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 25200, 640, 656,
822 752, 800, 0, 480, 490, 492, 525, 0,
823 V_NHSYNC | V_NVSYNC) },*/ /* 640x480@60Hz */
824 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DEFAULT, 135000, 1280, 1296,
825 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
826 V_PHSYNC | V_PVSYNC) }, /* 1280x1024@75Hz */
829 static void nv50_kms_connector_fill_modes(struct drm_connector *drm_connector, uint32_t maxX, uint32_t maxY)
831 struct nv50_connector *connector = to_nv50_connector(drm_connector);
834 struct drm_display_mode *mode, *t;
835 struct edid *edid = NULL;
837 NV50_DEBUG("%s\n", drm_get_connector_name(drm_connector));
838 /* set all modes to the unverified state */
839 list_for_each_entry_safe(mode, t, &drm_connector->modes, head)
840 mode->status = MODE_UNVERIFIED;
842 connected = connector->detect(connector);
845 drm_connector->status = connector_status_connected;
847 drm_connector->status = connector_status_disconnected;
850 NV50_DEBUG("%s is disconnected\n", drm_get_connector_name(drm_connector));
851 /* TODO set EDID to NULL */
855 /* Not all connnectors have an i2c channel. */
856 if (connector->i2c_chan)
857 edid = (struct edid *) drm_do_probe_ddc_edid(&connector->i2c_chan->adapter);
860 drm_mode_connector_update_edid_property(drm_connector, edid);
861 ret = drm_add_edid_modes(drm_connector, edid);
862 connector->digital = edid->digital; /* cache */
866 if (ret) /* number of modes > 1 */
867 drm_mode_connector_list_update(drm_connector);
870 drm_mode_validate_size(drm_connector->dev, &drm_connector->modes, maxX, maxY, 0);
872 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
873 if (mode->status == MODE_OK) {
874 struct nouveau_hw_mode *hw_mode = nv50_kms_to_hw_mode(mode);
875 struct nv50_output *output = connector->to_output(connector, connector->digital);
877 mode->status = output->validate_mode(output, hw_mode);
878 /* find native mode, TODO: also check if we actually found one */
879 if (mode->status == MODE_OK) {
880 if (mode->type & DRM_MODE_TYPE_PREFERRED)
881 *output->native_mode = *hw_mode;
887 /* revalidate now that we have native mode */
888 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
889 if (mode->status == MODE_OK) {
890 struct nouveau_hw_mode *hw_mode = nv50_kms_to_hw_mode(mode);
891 struct nv50_output *output = connector->to_output(connector, connector->digital);
893 mode->status = output->validate_mode(output, hw_mode);
898 drm_mode_prune_invalid(drm_connector->dev, &drm_connector->modes, TRUE);
900 if (list_empty(&drm_connector->modes)) {
901 struct drm_display_mode *stdmode;
902 struct nouveau_hw_mode *hw_mode;
903 struct nv50_output *output;
905 NV50_DEBUG("No valid modes on %s\n", drm_get_connector_name(drm_connector));
907 /* Should we do this here ???
908 * When no valid EDID modes are available we end up
909 * here and bailed in the past, now we add a standard
910 * 640x480@60Hz mode and carry on.
912 stdmode = drm_mode_duplicate(drm_connector->dev, &std_mode[0]);
913 drm_mode_probed_add(drm_connector, stdmode);
914 drm_mode_list_concat(&drm_connector->probed_modes,
915 &drm_connector->modes);
917 /* also add it as native mode */
918 hw_mode = nv50_kms_to_hw_mode(mode);
919 output = connector->to_output(connector, connector->digital);
922 *output->native_mode = *hw_mode;
924 DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n",
925 drm_get_connector_name(drm_connector));
928 drm_mode_sort(&drm_connector->modes);
930 NV50_DEBUG("Probed modes for %s\n", drm_get_connector_name(drm_connector));
932 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
933 mode->vrefresh = drm_mode_vrefresh(mode);
935 /* is this needed, as it's unused by the driver? */
936 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
937 drm_mode_debug_printmodeline(mode);
941 static const struct drm_connector_funcs nv50_kms_connector_funcs = {
944 .detect = nv50_kms_connector_detect,
945 .destroy = nv50_kms_connector_destroy,
946 .fill_modes = nv50_kms_connector_fill_modes,
949 static int nv50_kms_connectors_init(struct drm_device *dev)
951 struct nv50_display *display = nv50_get_display(dev);
952 struct nv50_connector *connector = NULL;
955 list_for_each_entry(connector, &display->connectors, head) {
956 struct drm_connector *drm_connector = to_nv50_kms_connector(connector);
957 uint32_t type = DRM_MODE_CONNECTOR_Unknown;
959 switch (connector->type) {
961 type = DRM_MODE_CONNECTOR_VGA;
963 case CONNECTOR_DVI_D:
964 type = DRM_MODE_CONNECTOR_DVID;
966 case CONNECTOR_DVI_I:
967 type = DRM_MODE_CONNECTOR_DVII;
970 type = DRM_MODE_CONNECTOR_LVDS;
973 type = DRM_MODE_CONNECTOR_SVIDEO;
976 type = DRM_MODE_CONNECTOR_Unknown;
980 if (type == DRM_MODE_CONNECTOR_Unknown) {
981 DRM_ERROR("DRM_MODE_CONNECTOR_Unknown encountered\n");
985 /* It should be allowed sometimes, but let's be safe for the moment. */
986 drm_connector->interlace_allowed = false;
987 drm_connector->doublescan_allowed = false;
989 drm_connector_init(dev, drm_connector, &nv50_kms_connector_funcs, type);
991 /* attach encoders, possibilities are analog + digital */
992 for (i = 0; i < 2; i++) {
993 struct drm_encoder *drm_encoder = NULL;
994 struct nv50_output *output = connector->to_output(connector, i);
998 drm_encoder = to_nv50_kms_encoder(output);
1000 DRM_ERROR("No struct drm_connector to match struct nv50_output\n");
1004 drm_mode_connector_attach_encoder(drm_connector, drm_encoder);
1007 drm_sysfs_connector_add(drm_connector);
1017 int nv50_kms_init(struct drm_device *dev)
1019 struct drm_nouveau_private *dev_priv = dev->dev_private;
1020 struct nv50_kms_priv *kms_priv = kzalloc(sizeof(struct nv50_kms_priv), GFP_KERNEL);
1021 struct nv50_display *display = NULL;
1027 dev_priv->kms_priv = kms_priv;
1029 /* function pointers */
1030 /* an allocation interface that deals with the outside world, without polluting the core. */
1031 dev_priv->alloc_crtc = nv50_kms_alloc_crtc;
1032 dev_priv->alloc_output = nv50_kms_alloc_output;
1033 dev_priv->alloc_connector = nv50_kms_alloc_connector;
1035 dev_priv->free_crtc = nv50_kms_free_crtc;
1036 dev_priv->free_output = nv50_kms_free_output;
1037 dev_priv->free_connector = nv50_kms_free_connector;
1039 /* bios is needed for tables. */
1040 rval = nouveau_parse_bios(dev);
1044 /* init basic kernel modesetting */
1045 drm_mode_config_init(dev);
1047 dev->mode_config.min_width = 0;
1048 dev->mode_config.min_height = 0;
1050 dev->mode_config.funcs = (void *)&nv50_kms_mode_funcs;
1052 dev->mode_config.max_width = 8192;
1053 dev->mode_config.max_height = 8192;
1055 dev->mode_config.fb_base = dev_priv->fb_phys;
1057 /* init kms lists */
1058 INIT_LIST_HEAD(&kms_priv->crtcs);
1059 INIT_LIST_HEAD(&kms_priv->encoders);
1060 INIT_LIST_HEAD(&kms_priv->connectors);
1062 /* init the internal core, must be done first. */
1063 rval = nv50_display_create(dev);
1067 display = nv50_get_display(dev);
1074 rval = display->pre_init(display);
1078 /* init external layer */
1079 rval = nv50_kms_crtcs_init(dev);
1083 rval = nv50_kms_encoders_init(dev);
1087 rval = nv50_kms_connectors_init(dev);
1091 /* init now, this'll kill the textmode */
1092 rval = display->init(display);
1096 /* process cmdbuffer */
1097 display->update(display);
1103 dev_priv->kms_priv = NULL;
1108 int nv50_kms_destroy(struct drm_device *dev)
1110 drm_mode_config_cleanup(dev);