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;
156 struct drm_crtc *drm_crtc = NULL;
158 /* Wipe all previous connections. */
159 list_for_each_entry(connector, &display->connectors, item) {
160 connector->output = NULL;
163 list_for_each_entry(output, &display->outputs, item) {
167 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
168 if (drm_connector->encoder) {
169 output = to_nv50_output(drm_connector->encoder);
170 connector = to_nv50_connector(drm_connector);
172 /* hook up output to connector. */
173 connector->output = output;
175 if (drm_connector->encoder->crtc) {
176 crtc = to_nv50_crtc(drm_connector->encoder->crtc);
178 /* hook up output to crtc. */
184 /* mirror crtc active state */
185 list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
186 crtc = to_nv50_crtc(drm_crtc);
188 crtc->active = drm_crtc->enabled;
196 static void nv50_kms_framebuffer_destroy(struct drm_framebuffer *drm_framebuffer)
198 drm_framebuffer_cleanup(drm_framebuffer);
200 kfree(drm_framebuffer);
203 static const struct drm_framebuffer_funcs nv50_kms_fb_funcs = {
204 .destroy = nv50_kms_framebuffer_destroy,
208 * Mode config functions.
211 static struct drm_framebuffer *nv50_kms_framebuffer_create(struct drm_device *dev,
212 struct drm_file *file_priv, struct drm_mode_fb_cmd *mode_cmd)
214 struct drm_framebuffer *drm_framebuffer = kzalloc(sizeof(struct drm_framebuffer), GFP_KERNEL);
215 if (!drm_framebuffer)
218 drm_framebuffer_init(dev, drm_framebuffer, &nv50_kms_fb_funcs);
219 drm_helper_mode_fill_fb_struct(drm_framebuffer, mode_cmd);
221 return drm_framebuffer;
224 static int nv50_kms_fb_changed(struct drm_device *dev)
226 return 0; /* not needed until nouveaufb? */
229 static const struct drm_mode_config_funcs nv50_kms_mode_funcs = {
231 .fb_create = nv50_kms_framebuffer_create,
232 .fb_changed = nv50_kms_fb_changed,
239 static int nv50_kms_crtc_cursor_set(struct drm_crtc *drm_crtc, uint32_t buffer_handle,
240 uint32_t width, uint32_t height)
242 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
243 struct nv50_display *display = nv50_get_display(crtc->dev);
246 if (width != 64 || height != 64)
249 /* set bo before doing show cursor */
251 rval = crtc->cursor->set_bo(crtc, (drm_handle_t) buffer_handle);
256 crtc->cursor->visible = buffer_handle ? true : false;
259 rval = crtc->cursor->show(crtc);
262 } else { /* no handle implies hiding the cursor */
263 rval = crtc->cursor->hide(crtc);
271 /* in case this triggers any other cursor changes */
272 display->update(display);
277 static int nv50_kms_crtc_cursor_move(struct drm_crtc *drm_crtc, int x, int y)
279 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
281 return crtc->cursor->set_pos(crtc, x, y);
284 void nv50_kms_crtc_gamma_set(struct drm_crtc *drm_crtc, u16 *r, u16 *g, u16 *b,
287 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
292 crtc->lut->set(crtc, (uint16_t *)r, (uint16_t *)g, (uint16_t *)b);
295 int nv50_kms_crtc_set_config(struct drm_mode_set *set)
298 uint32_t crtc_mask = 0;
299 struct drm_device *dev = NULL;
300 struct drm_nouveau_private *dev_priv = NULL;
301 struct nv50_display *display = NULL;
302 struct drm_connector *drm_connector = NULL;
303 struct drm_encoder *drm_encoder = NULL;
304 struct drm_crtc *drm_crtc = NULL;
306 struct nv50_crtc *crtc = NULL;
307 struct nv50_output *output = NULL;
308 struct nv50_connector *connector = NULL;
309 struct nouveau_hw_mode *hw_mode = NULL;
310 struct nv50_fb_info fb_info;
313 bool switch_fb = false;
314 bool modeset = false;
319 * Supported operations:
321 * - Switch framebuffer.
325 /* Sanity checking */
327 DRM_ERROR("Sanity check failed\n");
332 DRM_ERROR("Sanity check failed\n");
338 if (!drm_mode_equal(set->mode, &set->crtc->mode))
341 if (set->fb != set->crtc->fb)
344 if (set->x != set->crtc->x || set->y != set->crtc->y)
351 if (!set->connectors && modeset) {
352 DRM_ERROR("Sanity check failed\n");
356 if (!modeset && !switch_fb && !blank) {
357 DRM_ERROR("There is nothing to do, bad input.\n");
361 /* Basic variable setting */
362 dev = set->crtc->dev;
363 dev_priv = dev->dev_private;
364 display = nv50_get_display(dev);
365 crtc = to_nv50_crtc(set->crtc);
368 * Wiring up the encoders and connectors.
372 /* Mode validation */
373 hw_mode = nv50_kms_to_hw_mode(set->mode);
375 rval = crtc->validate_mode(crtc, hw_mode);
377 if (rval != MODE_OK) {
378 DRM_ERROR("Mode not ok\n");
382 for (i = 0; i < set->num_connectors; i++) {
383 drm_connector = set->connectors[i];
384 if (!drm_connector) {
385 DRM_ERROR("No connector\n");
388 connector = to_nv50_connector(drm_connector);
390 output = connector->to_output(connector, connector->digital);
392 DRM_ERROR("No output\n");
396 rval = output->validate_mode(output, hw_mode);
397 if (rval != MODE_OK) {
398 DRM_ERROR("Mode not ok\n");
403 /* Validation done, move on to cleaning of existing structures. */
405 /* find encoders that use this crtc. */
406 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
407 if (drm_encoder->crtc == set->crtc) {
408 /* find the connector that goes with it */
409 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
410 if (drm_connector->encoder == drm_encoder) {
411 drm_connector->encoder = NULL;
415 drm_encoder->crtc = NULL;
419 /* now find if our desired encoders or connectors are in use already. */
420 for (i = 0; i < set->num_connectors; i++) {
421 drm_connector = set->connectors[i];
422 if (!drm_connector) {
423 DRM_ERROR("No connector\n");
427 if (!drm_connector->encoder)
430 drm_encoder = drm_connector->encoder;
431 drm_connector->encoder = NULL;
433 if (!drm_encoder->crtc)
436 drm_crtc = drm_encoder->crtc;
437 drm_encoder->crtc = NULL;
439 drm_crtc->enabled = false;
442 /* Time to wire up the public encoder, the private one will be handled later. */
443 for (i = 0; i < set->num_connectors; i++) {
444 drm_connector = set->connectors[i];
445 if (!drm_connector) {
446 DRM_ERROR("No connector\n");
450 output = connector->to_output(connector, connector->digital);
452 DRM_ERROR("No output\n");
456 /* find the encoder public structure that matches out output structure. */
457 drm_encoder = to_nv50_kms_encoder(output);
460 DRM_ERROR("No encoder\n");
464 drm_encoder->crtc = set->crtc;
465 set->crtc->enabled = true;
466 drm_connector->encoder = drm_encoder;
475 crtc = to_nv50_crtc(set->crtc);
477 /* keeping the encoders and connectors attached, so they can be tracked */
478 set->crtc->enabled = false;
482 * All state should now be updated, now onto the real work.
485 /* mirror everything to the private structs */
486 nv50_kms_mirror_routing(dev);
493 crtc = to_nv50_crtc(set->crtc);
495 /* set framebuffer */
496 set->crtc->fb = set->fb;
498 /* set private framebuffer */
499 crtc = to_nv50_crtc(set->crtc);
500 fb_info.block = find_block_by_handle(dev_priv->fb_heap, set->fb->mm_handle);
501 fb_info.width = set->fb->width;
502 fb_info.height = set->fb->height;
503 fb_info.depth = set->fb->depth;
504 fb_info.bpp = set->fb->bits_per_pixel;
505 fb_info.pitch = set->fb->pitch;
509 rval = crtc->fb->bind(crtc, &fb_info);
511 DRM_ERROR("fb_bind failed\n");
516 /* this is !cursor_show */
517 if (!crtc->cursor->enabled) {
518 rval = crtc->cursor->enable(crtc);
520 DRM_ERROR("cursor_enable failed\n");
530 crtc = to_nv50_crtc(set->crtc);
532 rval = crtc->blank(crtc, TRUE);
534 DRM_ERROR("blanking failed\n");
538 /* detach any outputs that are currently running on this crtc */
539 list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) {
540 if (drm_encoder->crtc == set->crtc) {
541 output = to_nv50_output(drm_encoder);
543 rval = output->execute_mode(output, TRUE);
545 DRM_ERROR("detaching output failed\n");
553 * Change framebuffer, without changing mode.
556 if (switch_fb && !modeset && !blank) {
557 crtc = to_nv50_crtc(set->crtc);
559 rval = crtc->blank(crtc, TRUE);
561 DRM_ERROR("blanking failed\n");
565 rval = crtc->set_fb(crtc);
567 DRM_ERROR("set_fb failed\n");
571 /* this also sets the fb offset */
572 rval = crtc->blank(crtc, FALSE);
574 DRM_ERROR("unblanking failed\n");
580 * Normal modesetting.
584 crtc = to_nv50_crtc(set->crtc);
586 /* disconnect unused outputs */
587 list_for_each_entry(output, &display->outputs, item) {
589 crtc_mask |= 1 << output->crtc->index;
591 rval = output->execute_mode(output, TRUE);
593 DRM_ERROR("detaching output failed\n");
599 /* blank any unused crtcs */
600 list_for_each_entry(crtc, &display->crtcs, item) {
601 if (!(crtc_mask & (1 << crtc->index)))
602 crtc->blank(crtc, TRUE);
605 crtc = to_nv50_crtc(set->crtc);
607 rval = crtc->set_mode(crtc, hw_mode);
609 DRM_ERROR("crtc mode set failed\n");
613 /* find native mode. */
614 list_for_each_entry(output, &display->outputs, item) {
615 if (output->crtc != crtc)
618 *crtc->native_mode = *output->native_mode;
619 list_for_each_entry(connector, &display->connectors, item) {
620 if (connector->output != output)
623 crtc->scaling_mode = connector->scaling_mode;
627 if (crtc->scaling_mode == SCALE_PANEL)
628 crtc->use_native_mode = false;
630 crtc->use_native_mode = true;
632 break; /* no use in finding more than one mode */
635 rval = crtc->execute_mode(crtc);
637 DRM_ERROR("crtc execute mode failed\n");
641 list_for_each_entry(output, &display->outputs, item) {
642 if (output->crtc != crtc)
645 rval = output->execute_mode(output, FALSE);
647 DRM_ERROR("output execute mode failed\n");
652 rval = crtc->set_scale(crtc);
654 DRM_ERROR("crtc set scale failed\n");
658 /* next line changes crtc, so putting it here is important */
659 display->last_crtc = crtc->index;
661 /* this is executed immediately */
662 list_for_each_entry(output, &display->outputs, item) {
663 if (output->crtc != crtc)
666 rval = output->set_power_mode(output, DPMSModeOn);
668 DRM_ERROR("output set power mode failed\n");
673 /* update dpms state to DPMSModeOn */
674 for (i = 0; i < set->num_connectors; i++) {
675 drm_connector = set->connectors[i];
676 if (!drm_connector) {
677 DRM_ERROR("No connector\n");
681 rval = drm_connector_property_set_value(drm_connector,
682 dev->mode_config.dpms_property,
685 DRM_ERROR("failed to update dpms state\n");
691 display->update(display);
706 static void nv50_kms_crtc_destroy(struct drm_crtc *drm_crtc)
708 struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc);
710 drm_crtc_cleanup(drm_crtc);
712 /* this will even destroy the public structure. */
716 static const struct drm_crtc_funcs nv50_kms_crtc_funcs = {
719 .cursor_set = nv50_kms_crtc_cursor_set,
720 .cursor_move = nv50_kms_crtc_cursor_move,
721 .gamma_set = nv50_kms_crtc_gamma_set,
722 .set_config = nv50_kms_crtc_set_config,
723 .destroy = nv50_kms_crtc_destroy,
726 static int nv50_kms_crtcs_init(struct drm_device *dev)
728 struct nv50_display *display = nv50_get_display(dev);
729 struct nv50_crtc *crtc = NULL;
732 * This may look a bit confusing, but:
733 * The internal structure is already allocated and so is the public one.
734 * Just a matter of getting to the memory and register it.
736 list_for_each_entry(crtc, &display->crtcs, item) {
737 struct drm_crtc *drm_crtc = to_nv50_kms_crtc(crtc);
739 drm_crtc_init(dev, drm_crtc, &nv50_kms_crtc_funcs);
749 static void nv50_kms_encoder_destroy(struct drm_encoder *drm_encoder)
751 struct nv50_output *output = to_nv50_output(drm_encoder);
753 drm_encoder_cleanup(drm_encoder);
755 /* this will even destroy the public structure. */
756 output->destroy(output);
759 static const struct drm_encoder_funcs nv50_kms_encoder_funcs = {
760 .destroy = nv50_kms_encoder_destroy,
763 static int nv50_kms_encoders_init(struct drm_device *dev)
765 struct nv50_display *display = nv50_get_display(dev);
766 struct nv50_output *output = NULL;
768 list_for_each_entry(output, &display->outputs, item) {
769 struct drm_encoder *drm_encoder = to_nv50_kms_encoder(output);
770 uint32_t type = DRM_MODE_ENCODER_NONE;
772 switch (output->type) {
774 type = DRM_MODE_ENCODER_DAC;
777 type = DRM_MODE_ENCODER_TMDS;
780 type = DRM_MODE_ENCODER_LVDS;
783 type = DRM_MODE_ENCODER_TVDAC;
786 type = DRM_MODE_ENCODER_NONE;
790 if (type == DRM_MODE_ENCODER_NONE) {
791 DRM_ERROR("DRM_MODE_ENCODER_NONE encountered\n");
795 drm_encoder_init(dev, drm_encoder, &nv50_kms_encoder_funcs, type);
797 /* I've never seen possible crtc's restricted. */
798 drm_encoder->possible_crtcs = 3;
799 drm_encoder->possible_clones = 0;
806 * Connector functions
809 void nv50_kms_connector_detect_all(struct drm_device *dev)
811 struct drm_connector *drm_connector = NULL;
813 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) {
814 drm_connector->funcs->detect(drm_connector);
818 static enum drm_connector_status nv50_kms_connector_detect(struct drm_connector *drm_connector)
820 struct nv50_connector *connector = to_nv50_connector(drm_connector);
821 struct drm_device *dev = drm_connector->dev;
825 connected = connector->detect(connector);
827 old_status = drm_connector->status;
830 drm_connector->status = connector_status_connected;
832 drm_connector->status = connector_status_disconnected;
834 /* update our modes whenever there is reason to */
835 if (old_status != drm_connector->status) {
836 drm_connector->funcs->fill_modes(drm_connector, 0, 0);
837 /* notify fb of changes */
838 dev->mode_config.funcs->fb_changed(dev);
841 return drm_connector->status;
844 static void nv50_kms_connector_destroy(struct drm_connector *drm_connector)
846 struct nv50_connector *connector = to_nv50_connector(drm_connector);
848 drm_sysfs_connector_remove(drm_connector);
849 drm_connector_cleanup(drm_connector);
851 /* this will even destroy the public structure. */
852 connector->destroy(connector);
856 * Detailed mode info for a standard 640x480@60Hz monitor
858 static struct drm_display_mode std_mode[] = {
859 /*{ DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 25200, 640, 656,
860 752, 800, 0, 480, 490, 492, 525, 0,
861 V_NHSYNC | V_NVSYNC) },*/ /* 640x480@60Hz */
862 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DEFAULT, 135000, 1280, 1296,
863 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
864 V_PHSYNC | V_PVSYNC) }, /* 1280x1024@75Hz */
867 static void nv50_kms_connector_fill_modes(struct drm_connector *drm_connector, uint32_t maxX, uint32_t maxY)
869 struct nv50_connector *connector = to_nv50_connector(drm_connector);
872 struct drm_display_mode *mode, *t;
873 struct edid *edid = NULL;
875 NV50_DEBUG("%s\n", drm_get_connector_name(drm_connector));
876 /* set all modes to the unverified state */
877 list_for_each_entry_safe(mode, t, &drm_connector->modes, head)
878 mode->status = MODE_UNVERIFIED;
880 connected = connector->detect(connector);
883 drm_connector->status = connector_status_connected;
885 drm_connector->status = connector_status_disconnected;
888 NV50_DEBUG("%s is disconnected\n", drm_get_connector_name(drm_connector));
889 /* TODO set EDID to NULL */
893 /* Not all connnectors have an i2c channel. */
894 if (connector->i2c_chan)
895 edid = (struct edid *) drm_do_probe_ddc_edid(&connector->i2c_chan->adapter);
898 drm_mode_connector_update_edid_property(drm_connector, edid);
899 ret = drm_add_edid_modes(drm_connector, edid);
900 connector->digital = edid->digital; /* cache */
904 if (ret) /* number of modes > 1 */
905 drm_mode_connector_list_update(drm_connector);
908 drm_mode_validate_size(drm_connector->dev, &drm_connector->modes, maxX, maxY, 0);
910 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
911 if (mode->status == MODE_OK) {
912 struct nouveau_hw_mode *hw_mode = nv50_kms_to_hw_mode(mode);
913 struct nv50_output *output = connector->to_output(connector, connector->digital);
915 mode->status = output->validate_mode(output, hw_mode);
916 /* find native mode, TODO: also check if we actually found one */
917 if (mode->status == MODE_OK) {
918 if (mode->type & DRM_MODE_TYPE_PREFERRED)
919 *output->native_mode = *hw_mode;
925 /* revalidate now that we have native mode */
926 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
927 if (mode->status == MODE_OK) {
928 struct nouveau_hw_mode *hw_mode = nv50_kms_to_hw_mode(mode);
929 struct nv50_output *output = connector->to_output(connector, connector->digital);
931 mode->status = output->validate_mode(output, hw_mode);
936 drm_mode_prune_invalid(drm_connector->dev, &drm_connector->modes, TRUE);
938 if (list_empty(&drm_connector->modes)) {
939 struct drm_display_mode *stdmode;
940 struct nouveau_hw_mode *hw_mode;
941 struct nv50_output *output;
943 NV50_DEBUG("No valid modes on %s\n", drm_get_connector_name(drm_connector));
945 /* Should we do this here ???
946 * When no valid EDID modes are available we end up
947 * here and bailed in the past, now we add a standard
948 * 640x480@60Hz mode and carry on.
950 stdmode = drm_mode_duplicate(drm_connector->dev, &std_mode[0]);
951 drm_mode_probed_add(drm_connector, stdmode);
952 drm_mode_list_concat(&drm_connector->probed_modes,
953 &drm_connector->modes);
955 /* also add it as native mode */
956 hw_mode = nv50_kms_to_hw_mode(mode);
957 output = connector->to_output(connector, connector->digital);
960 *output->native_mode = *hw_mode;
962 DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n",
963 drm_get_connector_name(drm_connector));
966 drm_mode_sort(&drm_connector->modes);
968 NV50_DEBUG("Probed modes for %s\n", drm_get_connector_name(drm_connector));
970 list_for_each_entry_safe(mode, t, &drm_connector->modes, head) {
971 mode->vrefresh = drm_mode_vrefresh(mode);
973 /* is this needed, as it's unused by the driver? */
974 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
975 drm_mode_debug_printmodeline(mode);
979 static bool nv50_kms_connector_set_property(struct drm_connector *connector,
980 struct drm_property *property,
983 struct drm_device *dev = connector->dev;
985 if (property == dev->mode_config.dpms_property && connector->encoder) {
986 struct nv50_output *output = to_nv50_output(connector->encoder);
988 if (!output->set_power_mode(output, (int) value))
997 static const struct drm_connector_funcs nv50_kms_connector_funcs = {
1000 .detect = nv50_kms_connector_detect,
1001 .destroy = nv50_kms_connector_destroy,
1002 .fill_modes = nv50_kms_connector_fill_modes,
1003 .set_property = nv50_kms_connector_set_property
1006 static int nv50_kms_connectors_init(struct drm_device *dev)
1008 struct nv50_display *display = nv50_get_display(dev);
1009 struct nv50_connector *connector = NULL;
1012 list_for_each_entry(connector, &display->connectors, item) {
1013 struct drm_connector *drm_connector = to_nv50_kms_connector(connector);
1014 uint32_t type = DRM_MODE_CONNECTOR_Unknown;
1016 switch (connector->type) {
1018 type = DRM_MODE_CONNECTOR_VGA;
1020 case CONNECTOR_DVI_D:
1021 type = DRM_MODE_CONNECTOR_DVID;
1023 case CONNECTOR_DVI_I:
1024 type = DRM_MODE_CONNECTOR_DVII;
1026 case CONNECTOR_LVDS:
1027 type = DRM_MODE_CONNECTOR_LVDS;
1030 type = DRM_MODE_CONNECTOR_SVIDEO;
1033 type = DRM_MODE_CONNECTOR_Unknown;
1037 if (type == DRM_MODE_CONNECTOR_Unknown) {
1038 DRM_ERROR("DRM_MODE_CONNECTOR_Unknown encountered\n");
1042 /* It should be allowed sometimes, but let's be safe for the moment. */
1043 drm_connector->interlace_allowed = false;
1044 drm_connector->doublescan_allowed = false;
1046 drm_connector_init(dev, drm_connector, &nv50_kms_connector_funcs, type);
1048 /* attach encoders, possibilities are analog + digital */
1049 for (i = 0; i < 2; i++) {
1050 struct drm_encoder *drm_encoder = NULL;
1051 struct nv50_output *output = connector->to_output(connector, i);
1055 drm_encoder = to_nv50_kms_encoder(output);
1057 DRM_ERROR("No struct drm_connector to match struct nv50_output\n");
1061 drm_mode_connector_attach_encoder(drm_connector, drm_encoder);
1064 drm_sysfs_connector_add(drm_connector);
1074 int nv50_kms_init(struct drm_device *dev)
1076 struct drm_nouveau_private *dev_priv = dev->dev_private;
1077 struct nv50_kms_priv *kms_priv = kzalloc(sizeof(struct nv50_kms_priv), GFP_KERNEL);
1078 struct nv50_display *display = NULL;
1084 dev_priv->kms_priv = kms_priv;
1086 /* function pointers */
1087 /* an allocation interface that deals with the outside world, without polluting the core. */
1088 dev_priv->alloc_crtc = nv50_kms_alloc_crtc;
1089 dev_priv->alloc_output = nv50_kms_alloc_output;
1090 dev_priv->alloc_connector = nv50_kms_alloc_connector;
1092 dev_priv->free_crtc = nv50_kms_free_crtc;
1093 dev_priv->free_output = nv50_kms_free_output;
1094 dev_priv->free_connector = nv50_kms_free_connector;
1096 /* bios is needed for tables. */
1097 rval = nouveau_parse_bios(dev);
1101 /* init basic kernel modesetting */
1102 drm_mode_config_init(dev);
1104 dev->mode_config.min_width = 0;
1105 dev->mode_config.min_height = 0;
1107 dev->mode_config.funcs = (void *)&nv50_kms_mode_funcs;
1109 dev->mode_config.max_width = 8192;
1110 dev->mode_config.max_height = 8192;
1112 dev->mode_config.fb_base = dev_priv->fb_phys;
1114 /* init kms lists */
1115 INIT_LIST_HEAD(&kms_priv->crtcs);
1116 INIT_LIST_HEAD(&kms_priv->encoders);
1117 INIT_LIST_HEAD(&kms_priv->connectors);
1119 /* init the internal core, must be done first. */
1120 rval = nv50_display_create(dev);
1124 display = nv50_get_display(dev);
1131 rval = display->pre_init(display);
1135 /* init external layer */
1136 rval = nv50_kms_crtcs_init(dev);
1140 rval = nv50_kms_encoders_init(dev);
1144 rval = nv50_kms_connectors_init(dev);
1148 /* init now, this'll kill the textmode */
1149 rval = display->init(display);
1153 /* process cmdbuffer */
1154 display->update(display);
1160 dev_priv->kms_priv = NULL;
1165 int nv50_kms_destroy(struct drm_device *dev)
1167 drm_mode_config_cleanup(dev);