Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/anholt...
[pandora-kernel.git] / drivers / gpu / drm / nouveau / nouveau_connector.c
index d2f6335..14afe1e 100644 (file)
@@ -218,7 +218,7 @@ nouveau_connector_set_encoder(struct drm_connector *connector,
                        connector->interlace_allowed = true;
        }
 
-       if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
+       if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
                drm_connector_property_set_value(connector,
                        dev->mode_config.dvi_i_subconnector_property,
                        nv_encoder->dcb->type == OUTPUT_TMDS ?
@@ -236,15 +236,17 @@ nouveau_connector_detect(struct drm_connector *connector)
        struct nouveau_i2c_chan *i2c;
        int type, flags;
 
-       if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
+       if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS)
                nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS);
        if (nv_encoder && nv_connector->native_mode) {
+               unsigned status = connector_status_connected;
+
 #ifdef CONFIG_ACPI
                if (!nouveau_ignorelid && !acpi_lid_open())
-                       return connector_status_disconnected;
+                       status = connector_status_unknown;
 #endif
                nouveau_connector_set_encoder(connector, nv_encoder);
-               return connector_status_connected;
+               return status;
        }
 
        /* Cleanup the previous EDID block. */
@@ -279,7 +281,7 @@ nouveau_connector_detect(struct drm_connector *connector)
                 * same i2c channel so the value returned from ddc_detect
                 * isn't necessarily correct.
                 */
-               if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
+               if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
                        if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
                                type = OUTPUT_TMDS;
                        else
@@ -300,7 +302,7 @@ nouveau_connector_detect(struct drm_connector *connector)
 
 detect_analog:
        nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG);
-       if (!nv_encoder)
+       if (!nv_encoder && !nouveau_tv_disable)
                nv_encoder = find_encoder_by_type(connector, OUTPUT_TV);
        if (nv_encoder) {
                struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
@@ -321,11 +323,11 @@ detect_analog:
 static void
 nouveau_connector_force(struct drm_connector *connector)
 {
-       struct drm_device *dev = connector->dev;
+       struct nouveau_connector *nv_connector = nouveau_connector(connector);
        struct nouveau_encoder *nv_encoder;
        int type;
 
-       if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
+       if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) {
                if (connector->force == DRM_FORCE_ON_DIGITAL)
                        type = OUTPUT_TMDS;
                else
@@ -335,7 +337,7 @@ nouveau_connector_force(struct drm_connector *connector)
 
        nv_encoder = find_encoder_by_type(connector, type);
        if (!nv_encoder) {
-               NV_ERROR(dev, "can't find encoder to force %s on!\n",
+               NV_ERROR(connector->dev, "can't find encoder to force %s on!\n",
                         drm_get_connector_name(connector));
                connector->status = connector_status_disconnected;
                return;
@@ -369,7 +371,7 @@ nouveau_connector_set_property(struct drm_connector *connector,
                }
 
                /* LVDS always needs gpu scaling */
-               if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS &&
+               if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS &&
                    value == DRM_MODE_SCALE_NONE)
                        return -EINVAL;
 
@@ -535,7 +537,7 @@ nouveau_connector_get_modes(struct drm_connector *connector)
        /* If we're not LVDS, destroy the previous native mode, the attached
         * monitor could have changed.
         */
-       if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS &&
+       if (nv_connector->dcb->type != DCB_CONNECTOR_LVDS &&
            nv_connector->native_mode) {
                drm_mode_destroy(dev, nv_connector->native_mode);
                nv_connector->native_mode = NULL;
@@ -563,7 +565,7 @@ nouveau_connector_get_modes(struct drm_connector *connector)
                ret = get_slave_funcs(nv_encoder)->
                        get_modes(to_drm_encoder(nv_encoder), connector);
 
-       if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
+       if (nv_encoder->dcb->type == OUTPUT_LVDS)
                ret += nouveau_connector_scaler_modes_add(connector);
 
        return ret;
@@ -613,6 +615,9 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
 
                clock *= 3;
                break;
+       default:
+               BUG_ON(1);
+               return MODE_BAD;
        }
 
        if (clock < min_clock)
@@ -680,7 +685,7 @@ nouveau_connector_create_lvds(struct drm_device *dev,
        /* Firstly try getting EDID over DDC, if allowed and I2C channel
         * is available.
         */
-       if (!dev_priv->VBIOS.pub.fp_no_ddc && nv_encoder->dcb->i2c_index < 0xf)
+       if (!dev_priv->vbios.fp_no_ddc && nv_encoder->dcb->i2c_index < 0xf)
                i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index);
 
        if (i2c) {
@@ -695,7 +700,7 @@ nouveau_connector_create_lvds(struct drm_device *dev,
         */
        if (!nv_connector->edid && nouveau_bios_fp_mode(dev, &native) &&
             (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
-             dev_priv->VBIOS.pub.fp_no_ddc)) {
+             dev_priv->vbios.fp_no_ddc)) {
                nv_connector->native_mode = drm_mode_duplicate(dev, &native);
                goto out;
        }
@@ -704,7 +709,7 @@ nouveau_connector_create_lvds(struct drm_device *dev,
         * stored for the panel stored in them.
         */
        if (!nv_connector->edid && !nv_connector->native_mode &&
-           !dev_priv->VBIOS.pub.fp_no_ddc) {
+           !dev_priv->vbios.fp_no_ddc) {
                struct edid *edid =
                        (struct edid *)nouveau_bios_embedded_edid(dev);
                if (edid) {
@@ -739,46 +744,66 @@ out:
 }
 
 int
-nouveau_connector_create(struct drm_device *dev, int index, int type)
+nouveau_connector_create(struct drm_device *dev,
+                        struct dcb_connector_table_entry *dcb)
 {
        struct drm_nouveau_private *dev_priv = dev->dev_private;
        struct nouveau_connector *nv_connector = NULL;
        struct drm_connector *connector;
        struct drm_encoder *encoder;
-       int ret;
+       int ret, type;
 
        NV_DEBUG_KMS(dev, "\n");
 
-       nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
-       if (!nv_connector)
-               return -ENOMEM;
-       nv_connector->dcb = nouveau_bios_connector_entry(dev, index);
-       connector = &nv_connector->base;
-
-       switch (type) {
-       case DRM_MODE_CONNECTOR_VGA:
+       switch (dcb->type) {
+       case DCB_CONNECTOR_NONE:
+               return 0;
+       case DCB_CONNECTOR_VGA:
                NV_INFO(dev, "Detected a VGA connector\n");
+               type = DRM_MODE_CONNECTOR_VGA;
                break;
-       case DRM_MODE_CONNECTOR_DVID:
-               NV_INFO(dev, "Detected a DVI-D connector\n");
+       case DCB_CONNECTOR_TV_0:
+       case DCB_CONNECTOR_TV_1:
+       case DCB_CONNECTOR_TV_3:
+               NV_INFO(dev, "Detected a TV connector\n");
+               type = DRM_MODE_CONNECTOR_TV;
                break;
-       case DRM_MODE_CONNECTOR_DVII:
+       case DCB_CONNECTOR_DVI_I:
                NV_INFO(dev, "Detected a DVI-I connector\n");
+               type = DRM_MODE_CONNECTOR_DVII;
                break;
-       case DRM_MODE_CONNECTOR_LVDS:
-               NV_INFO(dev, "Detected a LVDS connector\n");
+       case DCB_CONNECTOR_DVI_D:
+               NV_INFO(dev, "Detected a DVI-D connector\n");
+               type = DRM_MODE_CONNECTOR_DVID;
                break;
-       case DRM_MODE_CONNECTOR_TV:
-               NV_INFO(dev, "Detected a TV connector\n");
+       case DCB_CONNECTOR_HDMI_0:
+       case DCB_CONNECTOR_HDMI_1:
+               NV_INFO(dev, "Detected a HDMI connector\n");
+               type = DRM_MODE_CONNECTOR_HDMIA;
+               break;
+       case DCB_CONNECTOR_LVDS:
+               NV_INFO(dev, "Detected a LVDS connector\n");
+               type = DRM_MODE_CONNECTOR_LVDS;
                break;
-       case DRM_MODE_CONNECTOR_DisplayPort:
+       case DCB_CONNECTOR_DP:
                NV_INFO(dev, "Detected a DisplayPort connector\n");
+               type = DRM_MODE_CONNECTOR_DisplayPort;
                break;
-       default:
-               NV_ERROR(dev, "Unknown connector, this is not good.\n");
+       case DCB_CONNECTOR_eDP:
+               NV_INFO(dev, "Detected an eDP connector\n");
+               type = DRM_MODE_CONNECTOR_eDP;
                break;
+       default:
+               NV_ERROR(dev, "unknown connector type: 0x%02x!!\n", dcb->type);
+               return -EINVAL;
        }
 
+       nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL);
+       if (!nv_connector)
+               return -ENOMEM;
+       nv_connector->dcb = dcb;
+       connector = &nv_connector->base;
+
        /* defaults, will get overridden in detect() */
        connector->interlace_allowed = false;
        connector->doublescan_allowed = false;
@@ -786,55 +811,65 @@ nouveau_connector_create(struct drm_device *dev, int index, int type)
        drm_connector_init(dev, connector, &nouveau_connector_funcs, type);
        drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
 
+       /* attach encoders */
+       list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
+               struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+
+               if (nv_encoder->dcb->connector != dcb->index)
+                       continue;
+
+               if (get_slave_funcs(nv_encoder))
+                       get_slave_funcs(nv_encoder)->create_resources(encoder, connector);
+
+               drm_mode_connector_attach_encoder(connector, encoder);
+       }
+
+       if (!connector->encoder_ids[0]) {
+               NV_WARN(dev, "  no encoders, ignoring\n");
+               drm_connector_cleanup(connector);
+               kfree(connector);
+               return 0;
+       }
+
        /* Init DVI-I specific properties */
-       if (type == DRM_MODE_CONNECTOR_DVII) {
+       if (dcb->type == DCB_CONNECTOR_DVI_I) {
                drm_mode_create_dvi_i_properties(dev);
                drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0);
                drm_connector_attach_property(connector, dev->mode_config.dvi_i_select_subconnector_property, 0);
        }
 
-       if (type != DRM_MODE_CONNECTOR_LVDS)
+       if (dcb->type != DCB_CONNECTOR_LVDS)
                nv_connector->use_dithering = false;
 
-       if (type == DRM_MODE_CONNECTOR_DVID ||
-           type == DRM_MODE_CONNECTOR_DVII ||
-           type == DRM_MODE_CONNECTOR_LVDS ||
-           type == DRM_MODE_CONNECTOR_DisplayPort) {
-               nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
-
-               drm_connector_attach_property(connector, dev->mode_config.scaling_mode_property,
-                                             nv_connector->scaling_mode);
-               drm_connector_attach_property(connector, dev->mode_config.dithering_mode_property,
-                                             nv_connector->use_dithering ? DRM_MODE_DITHERING_ON
-                                             : DRM_MODE_DITHERING_OFF);
-
-       } else {
-               nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
-
-               if (type == DRM_MODE_CONNECTOR_VGA  &&
-                               dev_priv->card_type >= NV_50) {
+       switch (dcb->type) {
+       case DCB_CONNECTOR_VGA:
+               if (dev_priv->card_type >= NV_50) {
                        drm_connector_attach_property(connector,
                                        dev->mode_config.scaling_mode_property,
                                        nv_connector->scaling_mode);
                }
-       }
-
-       /* attach encoders */
-       list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
-               struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-
-               if (nv_encoder->dcb->connector != index)
-                       continue;
-
-               if (get_slave_funcs(nv_encoder))
-                       get_slave_funcs(nv_encoder)->create_resources(encoder, connector);
+               /* fall-through */
+       case DCB_CONNECTOR_TV_0:
+       case DCB_CONNECTOR_TV_1:
+       case DCB_CONNECTOR_TV_3:
+               nv_connector->scaling_mode = DRM_MODE_SCALE_NONE;
+               break;
+       default:
+               nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN;
 
-               drm_mode_connector_attach_encoder(connector, encoder);
+               drm_connector_attach_property(connector,
+                               dev->mode_config.scaling_mode_property,
+                               nv_connector->scaling_mode);
+               drm_connector_attach_property(connector,
+                               dev->mode_config.dithering_mode_property,
+                               nv_connector->use_dithering ?
+                               DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF);
+               break;
        }
 
        drm_sysfs_connector_add(connector);
 
-       if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
+       if (dcb->type == DCB_CONNECTOR_LVDS) {
                ret = nouveau_connector_create_lvds(dev, connector);
                if (ret) {
                        connector->funcs->destroy(connector);