LCOV - code coverage report
Current view: top level - dev/pci/drm/radeon - radeon_connectors.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 1326 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 42 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2007-8 Advanced Micro Devices, Inc.
       3             :  * Copyright 2008 Red Hat Inc.
       4             :  *
       5             :  * Permission is hereby granted, free of charge, to any person obtaining a
       6             :  * copy of this software and associated documentation files (the "Software"),
       7             :  * to deal in the Software without restriction, including without limitation
       8             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
       9             :  * and/or sell copies of the Software, and to permit persons to whom the
      10             :  * Software is furnished to do so, subject to the following conditions:
      11             :  *
      12             :  * The above copyright notice and this permission notice shall be included in
      13             :  * all copies or substantial portions of the Software.
      14             :  *
      15             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
      18             :  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
      19             :  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      20             :  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
      21             :  * OTHER DEALINGS IN THE SOFTWARE.
      22             :  *
      23             :  * Authors: Dave Airlie
      24             :  *          Alex Deucher
      25             :  */
      26             : #include <dev/pci/drm/drmP.h>
      27             : #include <dev/pci/drm/drm_edid.h>
      28             : #include <dev/pci/drm/drm_crtc_helper.h>
      29             : #include <dev/pci/drm/drm_fb_helper.h>
      30             : #include <dev/pci/drm/drm_dp_mst_helper.h>
      31             : #include <dev/pci/drm/radeon_drm.h>
      32             : #include "radeon.h"
      33             : #include "radeon_audio.h"
      34             : #include "atom.h"
      35             : 
      36             : 
      37           0 : static int radeon_dp_handle_hpd(struct drm_connector *connector)
      38             : {
      39           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
      40             :         int ret;
      41             : 
      42           0 :         ret = radeon_dp_mst_check_status(radeon_connector);
      43           0 :         if (ret == -EINVAL)
      44           0 :                 return 1;
      45           0 :         return 0;
      46           0 : }
      47           0 : void radeon_connector_hotplug(struct drm_connector *connector)
      48             : {
      49           0 :         struct drm_device *dev = connector->dev;
      50           0 :         struct radeon_device *rdev = dev->dev_private;
      51           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
      52             : 
      53           0 :         if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
      54             :                 struct radeon_connector_atom_dig *dig_connector =
      55           0 :                         radeon_connector->con_priv;
      56             : 
      57           0 :                 if (radeon_connector->is_mst_connector)
      58           0 :                         return;
      59           0 :                 if (dig_connector->is_mst) {
      60           0 :                         radeon_dp_handle_hpd(connector);
      61           0 :                         return;
      62             :                 }
      63           0 :         }
      64             :         /* bail if the connector does not have hpd pin, e.g.,
      65             :          * VGA, TV, etc.
      66             :          */
      67           0 :         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE)
      68           0 :                 return;
      69             : 
      70           0 :         radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
      71             : 
      72             :         /* if the connector is already off, don't turn it back on */
      73             :         /* FIXME: This access isn't protected by any locks. */
      74           0 :         if (connector->dpms != DRM_MODE_DPMS_ON)
      75           0 :                 return;
      76             : 
      77             :         /* just deal with DP (not eDP) here. */
      78           0 :         if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
      79             :                 struct radeon_connector_atom_dig *dig_connector =
      80           0 :                         radeon_connector->con_priv;
      81             : 
      82             :                 /* if existing sink type was not DP no need to retrain */
      83           0 :                 if (dig_connector->dp_sink_type != CONNECTOR_OBJECT_ID_DISPLAYPORT)
      84           0 :                         return;
      85             : 
      86             :                 /* first get sink type as it may be reset after (un)plug */
      87           0 :                 dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
      88             :                 /* don't do anything if sink is not display port, i.e.,
      89             :                  * passive dp->(dvi|hdmi) adaptor
      90             :                  */
      91           0 :                 if (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT &&
      92           0 :                     radeon_hpd_sense(rdev, radeon_connector->hpd.hpd) &&
      93           0 :                     radeon_dp_needs_link_train(radeon_connector)) {
      94             :                         /* Don't start link training before we have the DPCD */
      95           0 :                         if (!radeon_dp_getdpcd(radeon_connector))
      96           0 :                                 return;
      97             : 
      98             :                         /* Turn the connector off and back on immediately, which
      99             :                          * will trigger link training
     100             :                          */
     101           0 :                         drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
     102           0 :                         drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
     103           0 :                 }
     104           0 :         }
     105           0 : }
     106             : 
     107           0 : static void radeon_property_change_mode(struct drm_encoder *encoder)
     108             : {
     109           0 :         struct drm_crtc *crtc = encoder->crtc;
     110             : 
     111           0 :         if (crtc && crtc->enabled) {
     112           0 :                 drm_crtc_helper_set_mode(crtc, &crtc->mode,
     113           0 :                                          crtc->x, crtc->y, crtc->primary->fb);
     114           0 :         }
     115           0 : }
     116             : 
     117           0 : int radeon_get_monitor_bpc(struct drm_connector *connector)
     118             : {
     119           0 :         struct drm_device *dev = connector->dev;
     120           0 :         struct radeon_device *rdev = dev->dev_private;
     121           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     122             :         struct radeon_connector_atom_dig *dig_connector;
     123             :         int bpc = 8;
     124             :         int mode_clock, max_tmds_clock;
     125             : 
     126           0 :         switch (connector->connector_type) {
     127             :         case DRM_MODE_CONNECTOR_DVII:
     128             :         case DRM_MODE_CONNECTOR_HDMIB:
     129           0 :                 if (radeon_connector->use_digital) {
     130           0 :                         if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
     131           0 :                                 if (connector->display_info.bpc)
     132           0 :                                         bpc = connector->display_info.bpc;
     133             :                         }
     134             :                 }
     135             :                 break;
     136             :         case DRM_MODE_CONNECTOR_DVID:
     137             :         case DRM_MODE_CONNECTOR_HDMIA:
     138           0 :                 if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
     139           0 :                         if (connector->display_info.bpc)
     140           0 :                                 bpc = connector->display_info.bpc;
     141             :                 }
     142             :                 break;
     143             :         case DRM_MODE_CONNECTOR_DisplayPort:
     144           0 :                 dig_connector = radeon_connector->con_priv;
     145           0 :                 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
     146           0 :                     (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) ||
     147           0 :                     drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
     148           0 :                         if (connector->display_info.bpc)
     149           0 :                                 bpc = connector->display_info.bpc;
     150             :                 }
     151             :                 break;
     152             :         case DRM_MODE_CONNECTOR_eDP:
     153             :         case DRM_MODE_CONNECTOR_LVDS:
     154           0 :                 if (connector->display_info.bpc)
     155           0 :                         bpc = connector->display_info.bpc;
     156           0 :                 else if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
     157             :                         const struct drm_connector_helper_funcs *connector_funcs =
     158           0 :                                 connector->helper_private;
     159           0 :                         struct drm_encoder *encoder = connector_funcs->best_encoder(connector);
     160           0 :                         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
     161           0 :                         struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
     162             : 
     163           0 :                         if (dig->lcd_misc & ATOM_PANEL_MISC_V13_6BIT_PER_COLOR)
     164           0 :                                 bpc = 6;
     165           0 :                         else if (dig->lcd_misc & ATOM_PANEL_MISC_V13_8BIT_PER_COLOR)
     166           0 :                                 bpc = 8;
     167           0 :                 }
     168             :                 break;
     169             :         }
     170             : 
     171           0 :         if (drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
     172             :                 /* hdmi deep color only implemented on DCE4+ */
     173           0 :                 if ((bpc > 8) && !ASIC_IS_DCE4(rdev)) {
     174             :                         DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 8 bpc.\n",
     175             :                                           connector->name, bpc);
     176             :                         bpc = 8;
     177           0 :                 }
     178             : 
     179             :                 /*
     180             :                  * Pre DCE-8 hw can't handle > 12 bpc, and more than 12 bpc doesn't make
     181             :                  * much sense without support for > 12 bpc framebuffers. RGB 4:4:4 at
     182             :                  * 12 bpc is always supported on hdmi deep color sinks, as this is
     183             :                  * required by the HDMI-1.3 spec. Clamp to a safe 12 bpc maximum.
     184             :                  */
     185           0 :                 if (bpc > 12) {
     186             :                         DRM_DEBUG("%s: HDMI deep color %d bpc unsupported. Using 12 bpc.\n",
     187             :                                           connector->name, bpc);
     188             :                         bpc = 12;
     189           0 :                 }
     190             : 
     191             :                 /* Any defined maximum tmds clock limit we must not exceed? */
     192           0 :                 if (connector->max_tmds_clock > 0) {
     193             :                         /* mode_clock is clock in kHz for mode to be modeset on this connector */
     194           0 :                         mode_clock = radeon_connector->pixelclock_for_modeset;
     195             : 
     196             :                         /* Maximum allowable input clock in kHz */
     197           0 :                         max_tmds_clock = connector->max_tmds_clock * 1000;
     198             : 
     199             :                         DRM_DEBUG("%s: hdmi mode dotclock %d kHz, max tmds input clock %d kHz.\n",
     200             :                                           connector->name, mode_clock, max_tmds_clock);
     201             : 
     202             :                         /* Check if bpc is within clock limit. Try to degrade gracefully otherwise */
     203           0 :                         if ((bpc == 12) && (mode_clock * 3/2 > max_tmds_clock)) {
     204           0 :                                 if ((connector->display_info.edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_30) &&
     205           0 :                                         (mode_clock * 5/4 <= max_tmds_clock))
     206           0 :                                         bpc = 10;
     207             :                                 else
     208             :                                         bpc = 8;
     209             : 
     210             :                                 DRM_DEBUG("%s: HDMI deep color 12 bpc exceeds max tmds clock. Using %d bpc.\n",
     211             :                                                   connector->name, bpc);
     212             :                         }
     213             : 
     214           0 :                         if ((bpc == 10) && (mode_clock * 5/4 > max_tmds_clock)) {
     215             :                                 bpc = 8;
     216             :                                 DRM_DEBUG("%s: HDMI deep color 10 bpc exceeds max tmds clock. Using %d bpc.\n",
     217             :                                                   connector->name, bpc);
     218           0 :                         }
     219             :                 }
     220           0 :                 else if (bpc > 8) {
     221             :                         /* max_tmds_clock missing, but hdmi spec mandates it for deep color. */
     222             :                         DRM_DEBUG("%s: Required max tmds clock for HDMI deep color missing. Using 8 bpc.\n",
     223             :                                           connector->name);
     224             :                         bpc = 8;
     225           0 :                 }
     226             :         }
     227             : 
     228           0 :         if ((radeon_deep_color == 0) && (bpc > 8)) {
     229             :                 DRM_DEBUG("%s: Deep color disabled. Set radeon module param deep_color=1 to enable.\n",
     230             :                                   connector->name);
     231             :                 bpc = 8;
     232           0 :         }
     233             : 
     234             :         DRM_DEBUG("%s: Display bpc=%d, returned bpc=%d\n",
     235             :                           connector->name, connector->display_info.bpc, bpc);
     236             : 
     237           0 :         return bpc;
     238             : }
     239             : 
     240             : static void
     241           0 : radeon_connector_update_scratch_regs(struct drm_connector *connector, enum drm_connector_status status)
     242             : {
     243           0 :         struct drm_device *dev = connector->dev;
     244           0 :         struct radeon_device *rdev = dev->dev_private;
     245             :         struct drm_encoder *best_encoder = NULL;
     246             :         struct drm_encoder *encoder = NULL;
     247           0 :         const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
     248             :         bool connected;
     249             :         int i;
     250             : 
     251           0 :         best_encoder = connector_funcs->best_encoder(connector);
     252             : 
     253           0 :         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
     254           0 :                 if (connector->encoder_ids[i] == 0)
     255             :                         break;
     256             : 
     257           0 :                 encoder = drm_encoder_find(connector->dev,
     258             :                                            connector->encoder_ids[i]);
     259           0 :                 if (!encoder)
     260             :                         continue;
     261             : 
     262           0 :                 if ((encoder == best_encoder) && (status == connector_status_connected))
     263           0 :                         connected = true;
     264             :                 else
     265             :                         connected = false;
     266             : 
     267           0 :                 if (rdev->is_atom_bios)
     268           0 :                         radeon_atombios_connected_scratch_regs(connector, encoder, connected);
     269             :                 else
     270           0 :                         radeon_combios_connected_scratch_regs(connector, encoder, connected);
     271             : 
     272             :         }
     273           0 : }
     274             : 
     275           0 : static struct drm_encoder *radeon_find_encoder(struct drm_connector *connector, int encoder_type)
     276             : {
     277             :         struct drm_encoder *encoder;
     278             :         int i;
     279             : 
     280           0 :         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
     281           0 :                 if (connector->encoder_ids[i] == 0)
     282             :                         break;
     283             : 
     284           0 :                 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
     285           0 :                 if (!encoder)
     286             :                         continue;
     287             : 
     288           0 :                 if (encoder->encoder_type == encoder_type)
     289           0 :                         return encoder;
     290             :         }
     291           0 :         return NULL;
     292           0 : }
     293             : 
     294           0 : struct edid *radeon_connector_edid(struct drm_connector *connector)
     295             : {
     296           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     297           0 :         struct drm_property_blob *edid_blob = connector->edid_blob_ptr;
     298             : 
     299           0 :         if (radeon_connector->edid) {
     300           0 :                 return radeon_connector->edid;
     301           0 :         } else if (edid_blob) {
     302           0 :                 struct edid *edid = kmemdup(edid_blob->data, edid_blob->length, GFP_KERNEL);
     303           0 :                 if (edid)
     304           0 :                         radeon_connector->edid = edid;
     305           0 :         }
     306           0 :         return radeon_connector->edid;
     307           0 : }
     308             : 
     309           0 : static void radeon_connector_get_edid(struct drm_connector *connector)
     310             : {
     311           0 :         struct drm_device *dev = connector->dev;
     312           0 :         struct radeon_device *rdev = dev->dev_private;
     313           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     314             : 
     315           0 :         if (radeon_connector->edid)
     316           0 :                 return;
     317             : 
     318             :         /* on hw with routers, select right port */
     319           0 :         if (radeon_connector->router.ddc_valid)
     320           0 :                 radeon_router_select_ddc_port(radeon_connector);
     321             : 
     322           0 :         if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
     323           0 :              ENCODER_OBJECT_ID_NONE) &&
     324           0 :             radeon_connector->ddc_bus->has_aux) {
     325           0 :                 radeon_connector->edid = drm_get_edid(connector,
     326           0 :                                                       &radeon_connector->ddc_bus->aux.ddc);
     327           0 :         } else if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
     328           0 :                    (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
     329           0 :                 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
     330             : 
     331           0 :                 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
     332           0 :                      dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) &&
     333           0 :                     radeon_connector->ddc_bus->has_aux)
     334           0 :                         radeon_connector->edid = drm_get_edid(&radeon_connector->base,
     335           0 :                                                               &radeon_connector->ddc_bus->aux.ddc);
     336           0 :                 else if (radeon_connector->ddc_bus)
     337           0 :                         radeon_connector->edid = drm_get_edid(&radeon_connector->base,
     338           0 :                                                               &radeon_connector->ddc_bus->adapter);
     339           0 :         } else if (radeon_connector->ddc_bus) {
     340           0 :                 radeon_connector->edid = drm_get_edid(&radeon_connector->base,
     341           0 :                                                       &radeon_connector->ddc_bus->adapter);
     342           0 :         }
     343             : 
     344           0 :         if (!radeon_connector->edid) {
     345             :                 /* don't fetch the edid from the vbios if ddc fails and runpm is
     346             :                  * enabled so we report disconnected.
     347             :                  */
     348           0 :                 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
     349           0 :                         return;
     350             : 
     351           0 :                 if (rdev->is_atom_bios) {
     352             :                         /* some laptops provide a hardcoded edid in rom for LCDs */
     353           0 :                         if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
     354           0 :                              (connector->connector_type == DRM_MODE_CONNECTOR_eDP)))
     355           0 :                                 radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
     356             :                 } else {
     357             :                         /* some servers provide a hardcoded edid in rom for KVMs */
     358           0 :                         radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
     359             :                 }
     360             :         }
     361           0 : }
     362             : 
     363           0 : static void radeon_connector_free_edid(struct drm_connector *connector)
     364             : {
     365           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     366             : 
     367           0 :         if (radeon_connector->edid) {
     368           0 :                 kfree(radeon_connector->edid);
     369           0 :                 radeon_connector->edid = NULL;
     370           0 :         }
     371           0 : }
     372             : 
     373           0 : static int radeon_ddc_get_modes(struct drm_connector *connector)
     374             : {
     375           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     376             :         int ret;
     377             : 
     378           0 :         if (radeon_connector->edid) {
     379           0 :                 drm_mode_connector_update_edid_property(connector, radeon_connector->edid);
     380           0 :                 ret = drm_add_edid_modes(connector, radeon_connector->edid);
     381           0 :                 drm_edid_to_eld(connector, radeon_connector->edid);
     382           0 :                 return ret;
     383             :         }
     384           0 :         drm_mode_connector_update_edid_property(connector, NULL);
     385           0 :         return 0;
     386           0 : }
     387             : 
     388           0 : static struct drm_encoder *radeon_best_single_encoder(struct drm_connector *connector)
     389             : {
     390           0 :         int enc_id = connector->encoder_ids[0];
     391             :         /* pick the encoder ids */
     392           0 :         if (enc_id)
     393           0 :                 return drm_encoder_find(connector->dev, enc_id);
     394           0 :         return NULL;
     395           0 : }
     396             : 
     397           0 : static void radeon_get_native_mode(struct drm_connector *connector)
     398             : {
     399           0 :         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
     400             :         struct radeon_encoder *radeon_encoder;
     401             : 
     402           0 :         if (encoder == NULL)
     403           0 :                 return;
     404             : 
     405           0 :         radeon_encoder = to_radeon_encoder(encoder);
     406             : 
     407           0 :         if (!list_empty(&connector->probed_modes)) {
     408             :                 struct drm_display_mode *preferred_mode =
     409           0 :                         list_first_entry(&connector->probed_modes,
     410             :                                          struct drm_display_mode, head);
     411             : 
     412           0 :                 radeon_encoder->native_mode = *preferred_mode;
     413           0 :         } else {
     414           0 :                 radeon_encoder->native_mode.clock = 0;
     415             :         }
     416           0 : }
     417             : 
     418             : /*
     419             :  * radeon_connector_analog_encoder_conflict_solve
     420             :  * - search for other connectors sharing this encoder
     421             :  *   if priority is true, then set them disconnected if this is connected
     422             :  *   if priority is false, set us disconnected if they are connected
     423             :  */
     424             : static enum drm_connector_status
     425           0 : radeon_connector_analog_encoder_conflict_solve(struct drm_connector *connector,
     426             :                                                struct drm_encoder *encoder,
     427             :                                                enum drm_connector_status current_status,
     428             :                                                bool priority)
     429             : {
     430           0 :         struct drm_device *dev = connector->dev;
     431             :         struct drm_connector *conflict;
     432             :         struct radeon_connector *radeon_conflict;
     433             :         int i;
     434             : 
     435           0 :         list_for_each_entry(conflict, &dev->mode_config.connector_list, head) {
     436           0 :                 if (conflict == connector)
     437             :                         continue;
     438             : 
     439           0 :                 radeon_conflict = to_radeon_connector(conflict);
     440           0 :                 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
     441           0 :                         if (conflict->encoder_ids[i] == 0)
     442             :                                 break;
     443             : 
     444             :                         /* if the IDs match */
     445           0 :                         if (conflict->encoder_ids[i] == encoder->base.id) {
     446           0 :                                 if (conflict->status != connector_status_connected)
     447             :                                         continue;
     448             : 
     449           0 :                                 if (radeon_conflict->use_digital)
     450             :                                         continue;
     451             : 
     452           0 :                                 if (priority == true) {
     453             :                                         DRM_DEBUG_KMS("1: conflicting encoders switching off %s\n",
     454             :                                                       conflict->name);
     455             :                                         DRM_DEBUG_KMS("in favor of %s\n",
     456             :                                                       connector->name);
     457           0 :                                         conflict->status = connector_status_disconnected;
     458           0 :                                         radeon_connector_update_scratch_regs(conflict, connector_status_disconnected);
     459           0 :                                 } else {
     460             :                                         DRM_DEBUG_KMS("2: conflicting encoders switching off %s\n",
     461             :                                                       connector->name);
     462             :                                         DRM_DEBUG_KMS("in favor of %s\n",
     463             :                                                       conflict->name);
     464             :                                         current_status = connector_status_disconnected;
     465             :                                 }
     466             :                                 break;
     467             :                         }
     468             :                 }
     469             :         }
     470           0 :         return current_status;
     471             : 
     472             : }
     473             : 
     474           0 : static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encoder)
     475             : {
     476           0 :         struct drm_device *dev = encoder->dev;
     477           0 :         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
     478             :         struct drm_display_mode *mode = NULL;
     479           0 :         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
     480             : 
     481           0 :         if (native_mode->hdisplay != 0 &&
     482           0 :             native_mode->vdisplay != 0 &&
     483           0 :             native_mode->clock != 0) {
     484           0 :                 mode = drm_mode_duplicate(dev, native_mode);
     485           0 :                 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
     486           0 :                 drm_mode_set_name(mode);
     487             : 
     488             :                 DRM_DEBUG_KMS("Adding native panel mode %s\n", mode->name);
     489           0 :         } else if (native_mode->hdisplay != 0 &&
     490           0 :                    native_mode->vdisplay != 0) {
     491             :                 /* mac laptops without an edid */
     492             :                 /* Note that this is not necessarily the exact panel mode,
     493             :                  * but an approximation based on the cvt formula.  For these
     494             :                  * systems we should ideally read the mode info out of the
     495             :                  * registers or add a mode table, but this works and is much
     496             :                  * simpler.
     497             :                  */
     498           0 :                 mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false);
     499           0 :                 mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
     500             :                 DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name);
     501           0 :         }
     502           0 :         return mode;
     503             : }
     504             : 
     505           0 : static void radeon_add_common_modes(struct drm_encoder *encoder, struct drm_connector *connector)
     506             : {
     507           0 :         struct drm_device *dev = encoder->dev;
     508           0 :         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
     509             :         struct drm_display_mode *mode = NULL;
     510           0 :         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
     511             :         int i;
     512           0 :         struct mode_size {
     513             :                 int w;
     514             :                 int h;
     515           0 :         } common_modes[17] = {
     516             :                 { 640,  480},
     517             :                 { 720,  480},
     518             :                 { 800,  600},
     519             :                 { 848,  480},
     520             :                 {1024,  768},
     521             :                 {1152,  768},
     522             :                 {1280,  720},
     523             :                 {1280,  800},
     524             :                 {1280,  854},
     525             :                 {1280,  960},
     526             :                 {1280, 1024},
     527             :                 {1440,  900},
     528             :                 {1400, 1050},
     529             :                 {1680, 1050},
     530             :                 {1600, 1200},
     531             :                 {1920, 1080},
     532             :                 {1920, 1200}
     533             :         };
     534             : 
     535           0 :         for (i = 0; i < 17; i++) {
     536           0 :                 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT)) {
     537           0 :                         if (common_modes[i].w > 1024 ||
     538           0 :                             common_modes[i].h > 768)
     539             :                                 continue;
     540             :                 }
     541           0 :                 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
     542           0 :                         if (common_modes[i].w > native_mode->hdisplay ||
     543           0 :                             common_modes[i].h > native_mode->vdisplay ||
     544           0 :                             (common_modes[i].w == native_mode->hdisplay &&
     545           0 :                              common_modes[i].h == native_mode->vdisplay))
     546             :                                 continue;
     547             :                 }
     548           0 :                 if (common_modes[i].w < 320 || common_modes[i].h < 200)
     549             :                         continue;
     550             : 
     551           0 :                 mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false);
     552           0 :                 drm_mode_probed_add(connector, mode);
     553           0 :         }
     554           0 : }
     555             : 
     556           0 : static int radeon_connector_set_property(struct drm_connector *connector, struct drm_property *property,
     557             :                                   uint64_t val)
     558             : {
     559           0 :         struct drm_device *dev = connector->dev;
     560           0 :         struct radeon_device *rdev = dev->dev_private;
     561             :         struct drm_encoder *encoder;
     562             :         struct radeon_encoder *radeon_encoder;
     563             : 
     564           0 :         if (property == rdev->mode_info.coherent_mode_property) {
     565             :                 struct radeon_encoder_atom_dig *dig;
     566             :                 bool new_coherent_mode;
     567             : 
     568             :                 /* need to find digital encoder on connector */
     569           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     570           0 :                 if (!encoder)
     571           0 :                         return 0;
     572             : 
     573           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     574             : 
     575           0 :                 if (!radeon_encoder->enc_priv)
     576           0 :                         return 0;
     577             : 
     578           0 :                 dig = radeon_encoder->enc_priv;
     579           0 :                 new_coherent_mode = val ? true : false;
     580           0 :                 if (dig->coherent_mode != new_coherent_mode) {
     581           0 :                         dig->coherent_mode = new_coherent_mode;
     582           0 :                         radeon_property_change_mode(&radeon_encoder->base);
     583           0 :                 }
     584           0 :         }
     585             : 
     586           0 :         if (property == rdev->mode_info.audio_property) {
     587           0 :                 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     588             :                 /* need to find digital encoder on connector */
     589           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     590           0 :                 if (!encoder)
     591           0 :                         return 0;
     592             : 
     593           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     594             : 
     595           0 :                 if (radeon_connector->audio != val) {
     596           0 :                         radeon_connector->audio = val;
     597           0 :                         radeon_property_change_mode(&radeon_encoder->base);
     598           0 :                 }
     599           0 :         }
     600             : 
     601           0 :         if (property == rdev->mode_info.dither_property) {
     602           0 :                 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     603             :                 /* need to find digital encoder on connector */
     604           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     605           0 :                 if (!encoder)
     606           0 :                         return 0;
     607             : 
     608           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     609             : 
     610           0 :                 if (radeon_connector->dither != val) {
     611           0 :                         radeon_connector->dither = val;
     612           0 :                         radeon_property_change_mode(&radeon_encoder->base);
     613           0 :                 }
     614           0 :         }
     615             : 
     616           0 :         if (property == rdev->mode_info.underscan_property) {
     617             :                 /* need to find digital encoder on connector */
     618           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     619           0 :                 if (!encoder)
     620           0 :                         return 0;
     621             : 
     622           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     623             : 
     624           0 :                 if (radeon_encoder->underscan_type != val) {
     625           0 :                         radeon_encoder->underscan_type = val;
     626           0 :                         radeon_property_change_mode(&radeon_encoder->base);
     627           0 :                 }
     628             :         }
     629             : 
     630           0 :         if (property == rdev->mode_info.underscan_hborder_property) {
     631             :                 /* need to find digital encoder on connector */
     632           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     633           0 :                 if (!encoder)
     634           0 :                         return 0;
     635             : 
     636           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     637             : 
     638           0 :                 if (radeon_encoder->underscan_hborder != val) {
     639           0 :                         radeon_encoder->underscan_hborder = val;
     640           0 :                         radeon_property_change_mode(&radeon_encoder->base);
     641           0 :                 }
     642             :         }
     643             : 
     644           0 :         if (property == rdev->mode_info.underscan_vborder_property) {
     645             :                 /* need to find digital encoder on connector */
     646           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     647           0 :                 if (!encoder)
     648           0 :                         return 0;
     649             : 
     650           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     651             : 
     652           0 :                 if (radeon_encoder->underscan_vborder != val) {
     653           0 :                         radeon_encoder->underscan_vborder = val;
     654           0 :                         radeon_property_change_mode(&radeon_encoder->base);
     655           0 :                 }
     656             :         }
     657             : 
     658           0 :         if (property == rdev->mode_info.tv_std_property) {
     659           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TVDAC);
     660           0 :                 if (!encoder) {
     661           0 :                         encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_DAC);
     662           0 :                 }
     663             : 
     664           0 :                 if (!encoder)
     665           0 :                         return 0;
     666             : 
     667           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     668           0 :                 if (!radeon_encoder->enc_priv)
     669           0 :                         return 0;
     670           0 :                 if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) {
     671             :                         struct radeon_encoder_atom_dac *dac_int;
     672           0 :                         dac_int = radeon_encoder->enc_priv;
     673           0 :                         dac_int->tv_std = val;
     674           0 :                 } else {
     675             :                         struct radeon_encoder_tv_dac *dac_int;
     676           0 :                         dac_int = radeon_encoder->enc_priv;
     677           0 :                         dac_int->tv_std = val;
     678             :                 }
     679           0 :                 radeon_property_change_mode(&radeon_encoder->base);
     680           0 :         }
     681             : 
     682           0 :         if (property == rdev->mode_info.load_detect_property) {
     683             :                 struct radeon_connector *radeon_connector =
     684           0 :                         to_radeon_connector(connector);
     685             : 
     686           0 :                 if (val == 0)
     687           0 :                         radeon_connector->dac_load_detect = false;
     688             :                 else
     689           0 :                         radeon_connector->dac_load_detect = true;
     690           0 :         }
     691             : 
     692           0 :         if (property == rdev->mode_info.tmds_pll_property) {
     693             :                 struct radeon_encoder_int_tmds *tmds = NULL;
     694             :                 bool ret = false;
     695             :                 /* need to find digital encoder on connector */
     696           0 :                 encoder = radeon_find_encoder(connector, DRM_MODE_ENCODER_TMDS);
     697           0 :                 if (!encoder)
     698           0 :                         return 0;
     699             : 
     700           0 :                 radeon_encoder = to_radeon_encoder(encoder);
     701             : 
     702           0 :                 tmds = radeon_encoder->enc_priv;
     703           0 :                 if (!tmds)
     704           0 :                         return 0;
     705             : 
     706           0 :                 if (val == 0) {
     707           0 :                         if (rdev->is_atom_bios)
     708           0 :                                 ret = radeon_atombios_get_tmds_info(radeon_encoder, tmds);
     709             :                         else
     710           0 :                                 ret = radeon_legacy_get_tmds_info_from_combios(radeon_encoder, tmds);
     711             :                 }
     712           0 :                 if (val == 1 || ret == false) {
     713           0 :                         radeon_legacy_get_tmds_info_from_table(radeon_encoder, tmds);
     714           0 :                 }
     715           0 :                 radeon_property_change_mode(&radeon_encoder->base);
     716           0 :         }
     717             : 
     718           0 :         if (property == dev->mode_config.scaling_mode_property) {
     719             :                 enum radeon_rmx_type rmx_type;
     720             : 
     721           0 :                 if (connector->encoder)
     722           0 :                         radeon_encoder = to_radeon_encoder(connector->encoder);
     723             :                 else {
     724           0 :                         const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
     725           0 :                         radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
     726             :                 }
     727             : 
     728           0 :                 switch (val) {
     729             :                 default:
     730           0 :                 case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
     731           0 :                 case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
     732           0 :                 case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
     733           0 :                 case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
     734             :                 }
     735           0 :                 if (radeon_encoder->rmx_type == rmx_type)
     736           0 :                         return 0;
     737             : 
     738           0 :                 if ((rmx_type != DRM_MODE_SCALE_NONE) &&
     739           0 :                     (radeon_encoder->native_mode.clock == 0))
     740           0 :                         return 0;
     741             : 
     742           0 :                 radeon_encoder->rmx_type = rmx_type;
     743             : 
     744           0 :                 radeon_property_change_mode(&radeon_encoder->base);
     745           0 :         }
     746             : 
     747           0 :         if (property == rdev->mode_info.output_csc_property) {
     748           0 :                 if (connector->encoder)
     749           0 :                         radeon_encoder = to_radeon_encoder(connector->encoder);
     750             :                 else {
     751           0 :                         const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
     752           0 :                         radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
     753             :                 }
     754             : 
     755           0 :                 if (radeon_encoder->output_csc == val)
     756           0 :                         return 0;
     757             : 
     758           0 :                 radeon_encoder->output_csc = val;
     759             : 
     760           0 :                 if (connector->encoder->crtc) {
     761             :                         struct drm_crtc *crtc  = connector->encoder->crtc;
     762           0 :                         const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
     763           0 :                         struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
     764             : 
     765           0 :                         radeon_crtc->output_csc = radeon_encoder->output_csc;
     766             : 
     767           0 :                         (*crtc_funcs->load_lut)(crtc);
     768           0 :                 }
     769             :         }
     770             : 
     771           0 :         return 0;
     772           0 : }
     773             : 
     774           0 : static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
     775             :                                           struct drm_connector *connector)
     776             : {
     777           0 :         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
     778           0 :         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
     779             :         struct drm_display_mode *t, *mode;
     780             : 
     781             :         /* If the EDID preferred mode doesn't match the native mode, use it */
     782           0 :         list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
     783           0 :                 if (mode->type & DRM_MODE_TYPE_PREFERRED) {
     784           0 :                         if (mode->hdisplay != native_mode->hdisplay ||
     785           0 :                             mode->vdisplay != native_mode->vdisplay)
     786           0 :                                 memcpy(native_mode, mode, sizeof(*mode));
     787             :                 }
     788             :         }
     789             : 
     790             :         /* Try to get native mode details from EDID if necessary */
     791           0 :         if (!native_mode->clock) {
     792           0 :                 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
     793           0 :                         if (mode->hdisplay == native_mode->hdisplay &&
     794           0 :                             mode->vdisplay == native_mode->vdisplay) {
     795           0 :                                 *native_mode = *mode;
     796           0 :                                 drm_mode_set_crtcinfo(native_mode, CRTC_INTERLACE_HALVE_V);
     797             :                                 DRM_DEBUG_KMS("Determined LVDS native mode details from EDID\n");
     798           0 :                                 break;
     799             :                         }
     800             :                 }
     801             :         }
     802             : 
     803           0 :         if (!native_mode->clock) {
     804             :                 DRM_DEBUG_KMS("No LVDS native mode details, disabling RMX\n");
     805           0 :                 radeon_encoder->rmx_type = RMX_OFF;
     806           0 :         }
     807           0 : }
     808             : 
     809           0 : static int radeon_lvds_get_modes(struct drm_connector *connector)
     810             : {
     811             :         struct drm_encoder *encoder;
     812             :         int ret = 0;
     813             :         struct drm_display_mode *mode;
     814             : 
     815           0 :         radeon_connector_get_edid(connector);
     816           0 :         ret = radeon_ddc_get_modes(connector);
     817           0 :         if (ret > 0) {
     818             :                 encoder = radeon_best_single_encoder(connector);
     819           0 :                 if (encoder) {
     820           0 :                         radeon_fixup_lvds_native_mode(encoder, connector);
     821             :                         /* add scaled modes */
     822           0 :                         radeon_add_common_modes(encoder, connector);
     823           0 :                 }
     824           0 :                 return ret;
     825             :         }
     826             : 
     827             :         encoder = radeon_best_single_encoder(connector);
     828           0 :         if (!encoder)
     829           0 :                 return 0;
     830             : 
     831             :         /* we have no EDID modes */
     832           0 :         mode = radeon_fp_native_mode(encoder);
     833           0 :         if (mode) {
     834             :                 ret = 1;
     835           0 :                 drm_mode_probed_add(connector, mode);
     836             :                 /* add the width/height from vbios tables if available */
     837           0 :                 connector->display_info.width_mm = mode->width_mm;
     838           0 :                 connector->display_info.height_mm = mode->height_mm;
     839             :                 /* add scaled modes */
     840           0 :                 radeon_add_common_modes(encoder, connector);
     841           0 :         }
     842             : 
     843           0 :         return ret;
     844           0 : }
     845             : 
     846           0 : static enum drm_mode_status radeon_lvds_mode_valid(struct drm_connector *connector,
     847             :                                   struct drm_display_mode *mode)
     848             : {
     849           0 :         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
     850             : 
     851           0 :         if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
     852           0 :                 return MODE_PANEL;
     853             : 
     854           0 :         if (encoder) {
     855           0 :                 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
     856           0 :                 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
     857             : 
     858             :                 /* AVIVO hardware supports downscaling modes larger than the panel
     859             :                  * to the panel size, but I'm not sure this is desirable.
     860             :                  */
     861           0 :                 if ((mode->hdisplay > native_mode->hdisplay) ||
     862           0 :                     (mode->vdisplay > native_mode->vdisplay))
     863           0 :                         return MODE_PANEL;
     864             : 
     865             :                 /* if scaling is disabled, block non-native modes */
     866           0 :                 if (radeon_encoder->rmx_type == RMX_OFF) {
     867           0 :                         if ((mode->hdisplay != native_mode->hdisplay) ||
     868           0 :                             (mode->vdisplay != native_mode->vdisplay))
     869           0 :                                 return MODE_PANEL;
     870             :                 }
     871           0 :         }
     872             : 
     873           0 :         return MODE_OK;
     874           0 : }
     875             : 
     876             : static enum drm_connector_status
     877           0 : radeon_lvds_detect(struct drm_connector *connector, bool force)
     878             : {
     879           0 :         struct drm_device *dev = connector->dev;
     880           0 :         struct radeon_device *rdev = dev->dev_private;
     881           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     882           0 :         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
     883             :         enum drm_connector_status ret = connector_status_disconnected;
     884             :         int r;
     885             : 
     886           0 :         r = pm_runtime_get_sync(connector->dev->dev);
     887           0 :         if (r < 0)
     888           0 :                 return connector_status_disconnected;
     889             : 
     890           0 :         if (encoder) {
     891           0 :                 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
     892           0 :                 struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
     893             : 
     894             :                 /* check if panel is valid */
     895           0 :                 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
     896           0 :                         ret = connector_status_connected;
     897             :                 /* don't fetch the edid from the vbios if ddc fails and runpm is
     898             :                  * enabled so we report disconnected.
     899             :                  */
     900           0 :                 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
     901           0 :                         ret = connector_status_disconnected;
     902           0 :         }
     903             : 
     904             :         /* check for edid as well */
     905           0 :         radeon_connector_get_edid(connector);
     906           0 :         if (radeon_connector->edid)
     907           0 :                 ret = connector_status_connected;
     908             :         /* check acpi lid status ??? */
     909             : 
     910           0 :         radeon_connector_update_scratch_regs(connector, ret);
     911             :         pm_runtime_mark_last_busy(connector->dev->dev);
     912             :         pm_runtime_put_autosuspend(connector->dev->dev);
     913           0 :         return ret;
     914           0 : }
     915             : 
     916           0 : static void radeon_connector_destroy(struct drm_connector *connector)
     917             : {
     918           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
     919             : 
     920           0 :         radeon_connector_free_edid(connector);
     921           0 :         kfree(radeon_connector->con_priv);
     922           0 :         drm_connector_unregister(connector);
     923           0 :         drm_connector_cleanup(connector);
     924           0 :         kfree(connector);
     925           0 : }
     926             : 
     927           0 : static int radeon_lvds_set_property(struct drm_connector *connector,
     928             :                                     struct drm_property *property,
     929             :                                     uint64_t value)
     930             : {
     931           0 :         struct drm_device *dev = connector->dev;
     932             :         struct radeon_encoder *radeon_encoder;
     933             :         enum radeon_rmx_type rmx_type;
     934             : 
     935             :         DRM_DEBUG_KMS("\n");
     936           0 :         if (property != dev->mode_config.scaling_mode_property)
     937           0 :                 return 0;
     938             : 
     939           0 :         if (connector->encoder)
     940           0 :                 radeon_encoder = to_radeon_encoder(connector->encoder);
     941             :         else {
     942           0 :                 const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private;
     943           0 :                 radeon_encoder = to_radeon_encoder(connector_funcs->best_encoder(connector));
     944             :         }
     945             : 
     946           0 :         switch (value) {
     947           0 :         case DRM_MODE_SCALE_NONE: rmx_type = RMX_OFF; break;
     948           0 :         case DRM_MODE_SCALE_CENTER: rmx_type = RMX_CENTER; break;
     949           0 :         case DRM_MODE_SCALE_ASPECT: rmx_type = RMX_ASPECT; break;
     950             :         default:
     951           0 :         case DRM_MODE_SCALE_FULLSCREEN: rmx_type = RMX_FULL; break;
     952             :         }
     953           0 :         if (radeon_encoder->rmx_type == rmx_type)
     954           0 :                 return 0;
     955             : 
     956           0 :         radeon_encoder->rmx_type = rmx_type;
     957             : 
     958           0 :         radeon_property_change_mode(&radeon_encoder->base);
     959           0 :         return 0;
     960           0 : }
     961             : 
     962             : 
     963             : static const struct drm_connector_helper_funcs radeon_lvds_connector_helper_funcs = {
     964             :         .get_modes = radeon_lvds_get_modes,
     965             :         .mode_valid = radeon_lvds_mode_valid,
     966             :         .best_encoder = radeon_best_single_encoder,
     967             : };
     968             : 
     969             : static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
     970             :         .dpms = drm_helper_connector_dpms,
     971             :         .detect = radeon_lvds_detect,
     972             :         .fill_modes = drm_helper_probe_single_connector_modes,
     973             :         .destroy = radeon_connector_destroy,
     974             :         .set_property = radeon_lvds_set_property,
     975             : };
     976             : 
     977           0 : static int radeon_vga_get_modes(struct drm_connector *connector)
     978             : {
     979             :         int ret;
     980             : 
     981           0 :         radeon_connector_get_edid(connector);
     982           0 :         ret = radeon_ddc_get_modes(connector);
     983             : 
     984           0 :         radeon_get_native_mode(connector);
     985             : 
     986           0 :         return ret;
     987             : }
     988             : 
     989           0 : static enum drm_mode_status radeon_vga_mode_valid(struct drm_connector *connector,
     990             :                                   struct drm_display_mode *mode)
     991             : {
     992           0 :         struct drm_device *dev = connector->dev;
     993           0 :         struct radeon_device *rdev = dev->dev_private;
     994             : 
     995             :         /* XXX check mode bandwidth */
     996             : 
     997           0 :         if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
     998           0 :                 return MODE_CLOCK_HIGH;
     999             : 
    1000           0 :         return MODE_OK;
    1001           0 : }
    1002             : 
    1003             : static enum drm_connector_status
    1004           0 : radeon_vga_detect(struct drm_connector *connector, bool force)
    1005             : {
    1006           0 :         struct drm_device *dev = connector->dev;
    1007           0 :         struct radeon_device *rdev = dev->dev_private;
    1008           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1009             :         struct drm_encoder *encoder;
    1010             :         const struct drm_encoder_helper_funcs *encoder_funcs;
    1011             :         bool dret = false;
    1012             :         enum drm_connector_status ret = connector_status_disconnected;
    1013             :         int r;
    1014             : 
    1015           0 :         r = pm_runtime_get_sync(connector->dev->dev);
    1016           0 :         if (r < 0)
    1017           0 :                 return connector_status_disconnected;
    1018             : 
    1019           0 :         encoder = radeon_best_single_encoder(connector);
    1020           0 :         if (!encoder)
    1021           0 :                 ret = connector_status_disconnected;
    1022             : 
    1023           0 :         if (radeon_connector->ddc_bus)
    1024           0 :                 dret = radeon_ddc_probe(radeon_connector, false);
    1025           0 :         if (dret) {
    1026           0 :                 radeon_connector->detected_by_load = false;
    1027           0 :                 radeon_connector_free_edid(connector);
    1028           0 :                 radeon_connector_get_edid(connector);
    1029             : 
    1030           0 :                 if (!radeon_connector->edid) {
    1031           0 :                         DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
    1032             :                                         connector->name);
    1033             :                         ret = connector_status_connected;
    1034           0 :                 } else {
    1035           0 :                         radeon_connector->use_digital =
    1036           0 :                                 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
    1037             : 
    1038             :                         /* some oems have boards with separate digital and analog connectors
    1039             :                          * with a shared ddc line (often vga + hdmi)
    1040             :                          */
    1041           0 :                         if (radeon_connector->use_digital && radeon_connector->shared_ddc) {
    1042           0 :                                 radeon_connector_free_edid(connector);
    1043             :                                 ret = connector_status_disconnected;
    1044           0 :                         } else {
    1045             :                                 ret = connector_status_connected;
    1046             :                         }
    1047             :                 }
    1048             :         } else {
    1049             : 
    1050             :                 /* if we aren't forcing don't do destructive polling */
    1051           0 :                 if (!force) {
    1052             :                         /* only return the previous status if we last
    1053             :                          * detected a monitor via load.
    1054             :                          */
    1055           0 :                         if (radeon_connector->detected_by_load)
    1056           0 :                                 ret = connector->status;
    1057             :                         goto out;
    1058             :                 }
    1059             : 
    1060           0 :                 if (radeon_connector->dac_load_detect && encoder) {
    1061           0 :                         encoder_funcs = encoder->helper_private;
    1062           0 :                         ret = encoder_funcs->detect(encoder, connector);
    1063           0 :                         if (ret != connector_status_disconnected)
    1064           0 :                                 radeon_connector->detected_by_load = true;
    1065             :                 }
    1066             :         }
    1067             : 
    1068           0 :         if (ret == connector_status_connected)
    1069           0 :                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
    1070             : 
    1071             :         /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
    1072             :          * vbios to deal with KVMs. If we have one and are not able to detect a monitor
    1073             :          * by other means, assume the CRT is connected and use that EDID.
    1074             :          */
    1075           0 :         if ((!rdev->is_atom_bios) &&
    1076           0 :             (ret == connector_status_disconnected) &&
    1077           0 :             rdev->mode_info.bios_hardcoded_edid_size) {
    1078             :                 ret = connector_status_connected;
    1079           0 :         }
    1080             : 
    1081           0 :         radeon_connector_update_scratch_regs(connector, ret);
    1082             : 
    1083             : out:
    1084             :         pm_runtime_mark_last_busy(connector->dev->dev);
    1085             :         pm_runtime_put_autosuspend(connector->dev->dev);
    1086             : 
    1087           0 :         return ret;
    1088           0 : }
    1089             : 
    1090             : static const struct drm_connector_helper_funcs radeon_vga_connector_helper_funcs = {
    1091             :         .get_modes = radeon_vga_get_modes,
    1092             :         .mode_valid = radeon_vga_mode_valid,
    1093             :         .best_encoder = radeon_best_single_encoder,
    1094             : };
    1095             : 
    1096             : static const struct drm_connector_funcs radeon_vga_connector_funcs = {
    1097             :         .dpms = drm_helper_connector_dpms,
    1098             :         .detect = radeon_vga_detect,
    1099             :         .fill_modes = drm_helper_probe_single_connector_modes,
    1100             :         .destroy = radeon_connector_destroy,
    1101             :         .set_property = radeon_connector_set_property,
    1102             : };
    1103             : 
    1104           0 : static int radeon_tv_get_modes(struct drm_connector *connector)
    1105             : {
    1106           0 :         struct drm_device *dev = connector->dev;
    1107           0 :         struct radeon_device *rdev = dev->dev_private;
    1108             :         struct drm_display_mode *tv_mode;
    1109             :         struct drm_encoder *encoder;
    1110             : 
    1111           0 :         encoder = radeon_best_single_encoder(connector);
    1112           0 :         if (!encoder)
    1113           0 :                 return 0;
    1114             : 
    1115             :         /* avivo chips can scale any mode */
    1116           0 :         if (rdev->family >= CHIP_RS600)
    1117             :                 /* add scaled modes */
    1118           0 :                 radeon_add_common_modes(encoder, connector);
    1119             :         else {
    1120             :                 /* only 800x600 is supported right now on pre-avivo chips */
    1121           0 :                 tv_mode = drm_cvt_mode(dev, 800, 600, 60, false, false, false);
    1122           0 :                 tv_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
    1123           0 :                 drm_mode_probed_add(connector, tv_mode);
    1124             :         }
    1125           0 :         return 1;
    1126           0 : }
    1127             : 
    1128           0 : static enum drm_mode_status radeon_tv_mode_valid(struct drm_connector *connector,
    1129             :                                 struct drm_display_mode *mode)
    1130             : {
    1131           0 :         if ((mode->hdisplay > 1024) || (mode->vdisplay > 768))
    1132           0 :                 return MODE_CLOCK_RANGE;
    1133           0 :         return MODE_OK;
    1134           0 : }
    1135             : 
    1136             : static enum drm_connector_status
    1137           0 : radeon_tv_detect(struct drm_connector *connector, bool force)
    1138             : {
    1139             :         struct drm_encoder *encoder;
    1140             :         const struct drm_encoder_helper_funcs *encoder_funcs;
    1141           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1142             :         enum drm_connector_status ret = connector_status_disconnected;
    1143             :         int r;
    1144             : 
    1145           0 :         if (!radeon_connector->dac_load_detect)
    1146           0 :                 return ret;
    1147             : 
    1148           0 :         r = pm_runtime_get_sync(connector->dev->dev);
    1149           0 :         if (r < 0)
    1150           0 :                 return connector_status_disconnected;
    1151             : 
    1152           0 :         encoder = radeon_best_single_encoder(connector);
    1153           0 :         if (!encoder)
    1154           0 :                 ret = connector_status_disconnected;
    1155             :         else {
    1156           0 :                 encoder_funcs = encoder->helper_private;
    1157           0 :                 ret = encoder_funcs->detect(encoder, connector);
    1158             :         }
    1159           0 :         if (ret == connector_status_connected)
    1160           0 :                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
    1161           0 :         radeon_connector_update_scratch_regs(connector, ret);
    1162             :         pm_runtime_mark_last_busy(connector->dev->dev);
    1163             :         pm_runtime_put_autosuspend(connector->dev->dev);
    1164           0 :         return ret;
    1165           0 : }
    1166             : 
    1167             : static const struct drm_connector_helper_funcs radeon_tv_connector_helper_funcs = {
    1168             :         .get_modes = radeon_tv_get_modes,
    1169             :         .mode_valid = radeon_tv_mode_valid,
    1170             :         .best_encoder = radeon_best_single_encoder,
    1171             : };
    1172             : 
    1173             : static const struct drm_connector_funcs radeon_tv_connector_funcs = {
    1174             :         .dpms = drm_helper_connector_dpms,
    1175             :         .detect = radeon_tv_detect,
    1176             :         .fill_modes = drm_helper_probe_single_connector_modes,
    1177             :         .destroy = radeon_connector_destroy,
    1178             :         .set_property = radeon_connector_set_property,
    1179             : };
    1180             : 
    1181           0 : static bool radeon_check_hpd_status_unchanged(struct drm_connector *connector)
    1182             : {
    1183           0 :         struct drm_device *dev = connector->dev;
    1184           0 :         struct radeon_device *rdev = dev->dev_private;
    1185           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1186             :         enum drm_connector_status status;
    1187             : 
    1188             :         /* We only trust HPD on R600 and newer ASICS. */
    1189           0 :         if (rdev->family >= CHIP_R600
    1190           0 :           && radeon_connector->hpd.hpd != RADEON_HPD_NONE) {
    1191           0 :                 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
    1192           0 :                         status = connector_status_connected;
    1193             :                 else
    1194             :                         status = connector_status_disconnected;
    1195           0 :                 if (connector->status == status)
    1196           0 :                         return true;
    1197             :         }
    1198             : 
    1199           0 :         return false;
    1200           0 : }
    1201             : 
    1202             : /*
    1203             :  * DVI is complicated
    1204             :  * Do a DDC probe, if DDC probe passes, get the full EDID so
    1205             :  * we can do analog/digital monitor detection at this point.
    1206             :  * If the monitor is an analog monitor or we got no DDC,
    1207             :  * we need to find the DAC encoder object for this connector.
    1208             :  * If we got no DDC, we do load detection on the DAC encoder object.
    1209             :  * If we got analog DDC or load detection passes on the DAC encoder
    1210             :  * we have to check if this analog encoder is shared with anyone else (TV)
    1211             :  * if its shared we have to set the other connector to disconnected.
    1212             :  */
    1213             : static enum drm_connector_status
    1214           0 : radeon_dvi_detect(struct drm_connector *connector, bool force)
    1215             : {
    1216           0 :         struct drm_device *dev = connector->dev;
    1217           0 :         struct radeon_device *rdev = dev->dev_private;
    1218           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1219             :         struct drm_encoder *encoder = NULL;
    1220             :         const struct drm_encoder_helper_funcs *encoder_funcs;
    1221             :         int i, r;
    1222             :         enum drm_connector_status ret = connector_status_disconnected;
    1223             :         bool dret = false, broken_edid = false;
    1224             : 
    1225           0 :         r = pm_runtime_get_sync(connector->dev->dev);
    1226           0 :         if (r < 0)
    1227           0 :                 return connector_status_disconnected;
    1228             : 
    1229           0 :         if (radeon_connector->detected_hpd_without_ddc) {
    1230             :                 force = true;
    1231           0 :                 radeon_connector->detected_hpd_without_ddc = false;
    1232           0 :         }
    1233             : 
    1234           0 :         if (!force && radeon_check_hpd_status_unchanged(connector)) {
    1235           0 :                 ret = connector->status;
    1236           0 :                 goto exit;
    1237             :         }
    1238             : 
    1239           0 :         if (radeon_connector->ddc_bus) {
    1240           0 :                 dret = radeon_ddc_probe(radeon_connector, false);
    1241             : 
    1242             :                 /* Sometimes the pins required for the DDC probe on DVI
    1243             :                  * connectors don't make contact at the same time that the ones
    1244             :                  * for HPD do. If the DDC probe fails even though we had an HPD
    1245             :                  * signal, try again later */
    1246           0 :                 if (!dret && !force &&
    1247           0 :                     connector->status != connector_status_connected) {
    1248             :                         DRM_DEBUG_KMS("hpd detected without ddc, retrying in 1 second\n");
    1249           0 :                         radeon_connector->detected_hpd_without_ddc = true;
    1250           0 :                         schedule_delayed_work(&rdev->hotplug_work,
    1251           0 :                                               msecs_to_jiffies(1000));
    1252           0 :                         goto exit;
    1253             :                 }
    1254             :         }
    1255           0 :         if (dret) {
    1256           0 :                 radeon_connector->detected_by_load = false;
    1257           0 :                 radeon_connector_free_edid(connector);
    1258           0 :                 radeon_connector_get_edid(connector);
    1259             : 
    1260           0 :                 if (!radeon_connector->edid) {
    1261           0 :                         DRM_ERROR("%s: probed a monitor but no|invalid EDID\n",
    1262             :                                         connector->name);
    1263             :                         /* rs690 seems to have a problem with connectors not existing and always
    1264             :                          * return a block of 0's. If we see this just stop polling on this output */
    1265           0 :                         if ((rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) &&
    1266           0 :                             radeon_connector->base.null_edid_counter) {
    1267             :                                 ret = connector_status_disconnected;
    1268           0 :                                 DRM_ERROR("%s: detected RS690 floating bus bug, stopping ddc detect\n",
    1269             :                                           connector->name);
    1270           0 :                                 radeon_connector->ddc_bus = NULL;
    1271           0 :                         } else {
    1272             :                                 ret = connector_status_connected;
    1273             :                                 broken_edid = true; /* defer use_digital to later */
    1274             :                         }
    1275             :                 } else {
    1276           0 :                         radeon_connector->use_digital =
    1277           0 :                                 !!(radeon_connector->edid->input & DRM_EDID_INPUT_DIGITAL);
    1278             : 
    1279             :                         /* some oems have boards with separate digital and analog connectors
    1280             :                          * with a shared ddc line (often vga + hdmi)
    1281             :                          */
    1282           0 :                         if ((!radeon_connector->use_digital) && radeon_connector->shared_ddc) {
    1283           0 :                                 radeon_connector_free_edid(connector);
    1284             :                                 ret = connector_status_disconnected;
    1285           0 :                         } else {
    1286             :                                 ret = connector_status_connected;
    1287             :                         }
    1288             :                         /* This gets complicated.  We have boards with VGA + HDMI with a
    1289             :                          * shared DDC line and we have boards with DVI-D + HDMI with a shared
    1290             :                          * DDC line.  The latter is more complex because with DVI<->HDMI adapters
    1291             :                          * you don't really know what's connected to which port as both are digital.
    1292             :                          */
    1293           0 :                         if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
    1294             :                                 struct drm_connector *list_connector;
    1295             :                                 struct radeon_connector *list_radeon_connector;
    1296           0 :                                 list_for_each_entry(list_connector, &dev->mode_config.connector_list, head) {
    1297           0 :                                         if (connector == list_connector)
    1298             :                                                 continue;
    1299           0 :                                         list_radeon_connector = to_radeon_connector(list_connector);
    1300           0 :                                         if (list_radeon_connector->shared_ddc &&
    1301           0 :                                             (list_radeon_connector->ddc_bus->rec.i2c_id ==
    1302           0 :                                              radeon_connector->ddc_bus->rec.i2c_id)) {
    1303             :                                                 /* cases where both connectors are digital */
    1304           0 :                                                 if (list_connector->connector_type != DRM_MODE_CONNECTOR_VGA) {
    1305             :                                                         /* hpd is our only option in this case */
    1306           0 :                                                         if (!radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
    1307           0 :                                                                 radeon_connector_free_edid(connector);
    1308             :                                                                 ret = connector_status_disconnected;
    1309           0 :                                                         }
    1310             :                                                 }
    1311             :                                         }
    1312             :                                 }
    1313           0 :                         }
    1314             :                 }
    1315             :         }
    1316             : 
    1317           0 :         if ((ret == connector_status_connected) && (radeon_connector->use_digital == true))
    1318             :                 goto out;
    1319             : 
    1320             :         /* DVI-D and HDMI-A are digital only */
    1321           0 :         if ((connector->connector_type == DRM_MODE_CONNECTOR_DVID) ||
    1322           0 :             (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))
    1323             :                 goto out;
    1324             : 
    1325             :         /* if we aren't forcing don't do destructive polling */
    1326           0 :         if (!force) {
    1327             :                 /* only return the previous status if we last
    1328             :                  * detected a monitor via load.
    1329             :                  */
    1330           0 :                 if (radeon_connector->detected_by_load)
    1331           0 :                         ret = connector->status;
    1332             :                 goto out;
    1333             :         }
    1334             : 
    1335             :         /* find analog encoder */
    1336           0 :         if (radeon_connector->dac_load_detect) {
    1337           0 :                 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
    1338           0 :                         if (connector->encoder_ids[i] == 0)
    1339             :                                 break;
    1340             : 
    1341           0 :                         encoder = drm_encoder_find(connector->dev,
    1342             :                                                    connector->encoder_ids[i]);
    1343           0 :                         if (!encoder)
    1344             :                                 continue;
    1345             : 
    1346           0 :                         if (encoder->encoder_type != DRM_MODE_ENCODER_DAC &&
    1347           0 :                             encoder->encoder_type != DRM_MODE_ENCODER_TVDAC)
    1348             :                                 continue;
    1349             : 
    1350           0 :                         encoder_funcs = encoder->helper_private;
    1351           0 :                         if (encoder_funcs->detect) {
    1352           0 :                                 if (!broken_edid) {
    1353           0 :                                         if (ret != connector_status_connected) {
    1354             :                                                 /* deal with analog monitors without DDC */
    1355           0 :                                                 ret = encoder_funcs->detect(encoder, connector);
    1356           0 :                                                 if (ret == connector_status_connected) {
    1357           0 :                                                         radeon_connector->use_digital = false;
    1358           0 :                                                 }
    1359           0 :                                                 if (ret != connector_status_disconnected)
    1360           0 :                                                         radeon_connector->detected_by_load = true;
    1361             :                                         }
    1362             :                                 } else {
    1363             :                                         enum drm_connector_status lret;
    1364             :                                         /* assume digital unless load detected otherwise */
    1365           0 :                                         radeon_connector->use_digital = true;
    1366           0 :                                         lret = encoder_funcs->detect(encoder, connector);
    1367             :                                         DRM_DEBUG_KMS("load_detect %x returned: %x\n",encoder->encoder_type,lret);
    1368           0 :                                         if (lret == connector_status_connected)
    1369           0 :                                                 radeon_connector->use_digital = false;
    1370             :                                 }
    1371             :                                 break;
    1372             :                         }
    1373             :                 }
    1374             :         }
    1375             : 
    1376           0 :         if ((ret == connector_status_connected) && (radeon_connector->use_digital == false) &&
    1377           0 :             encoder) {
    1378           0 :                 ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, true);
    1379           0 :         }
    1380             : 
    1381             :         /* RN50 and some RV100 asics in servers often have a hardcoded EDID in the
    1382             :          * vbios to deal with KVMs. If we have one and are not able to detect a monitor
    1383             :          * by other means, assume the DFP is connected and use that EDID.  In most
    1384             :          * cases the DVI port is actually a virtual KVM port connected to the service
    1385             :          * processor.
    1386             :          */
    1387             : out:
    1388           0 :         if ((!rdev->is_atom_bios) &&
    1389           0 :             (ret == connector_status_disconnected) &&
    1390           0 :             rdev->mode_info.bios_hardcoded_edid_size) {
    1391           0 :                 radeon_connector->use_digital = true;
    1392             :                 ret = connector_status_connected;
    1393           0 :         }
    1394             : 
    1395             :         /* updated in get modes as well since we need to know if it's analog or digital */
    1396           0 :         radeon_connector_update_scratch_regs(connector, ret);
    1397             : 
    1398           0 :         if ((radeon_audio != 0) && radeon_connector->use_digital) {
    1399             :                 const struct drm_connector_helper_funcs *connector_funcs =
    1400           0 :                         connector->helper_private;
    1401             : 
    1402           0 :                 encoder = connector_funcs->best_encoder(connector);
    1403           0 :                 if (encoder && (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)) {
    1404           0 :                         radeon_connector_get_edid(connector);
    1405           0 :                         radeon_audio_detect(connector, encoder, ret);
    1406           0 :                 }
    1407           0 :         }
    1408             : 
    1409             : exit:
    1410             :         pm_runtime_mark_last_busy(connector->dev->dev);
    1411             :         pm_runtime_put_autosuspend(connector->dev->dev);
    1412             : 
    1413           0 :         return ret;
    1414           0 : }
    1415             : 
    1416             : /* okay need to be smart in here about which encoder to pick */
    1417           0 : static struct drm_encoder *radeon_dvi_encoder(struct drm_connector *connector)
    1418             : {
    1419           0 :         int enc_id = connector->encoder_ids[0];
    1420           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1421             :         struct drm_encoder *encoder;
    1422             :         int i;
    1423           0 :         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
    1424           0 :                 if (connector->encoder_ids[i] == 0)
    1425             :                         break;
    1426             : 
    1427           0 :                 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
    1428           0 :                 if (!encoder)
    1429             :                         continue;
    1430             : 
    1431           0 :                 if (radeon_connector->use_digital == true) {
    1432           0 :                         if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
    1433           0 :                                 return encoder;
    1434             :                 } else {
    1435           0 :                         if (encoder->encoder_type == DRM_MODE_ENCODER_DAC ||
    1436           0 :                             encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
    1437           0 :                                 return encoder;
    1438             :                 }
    1439             :         }
    1440             : 
    1441             :         /* see if we have a default encoder  TODO */
    1442             : 
    1443             :         /* then check use digitial */
    1444             :         /* pick the first one */
    1445           0 :         if (enc_id)
    1446           0 :                 return drm_encoder_find(connector->dev, enc_id);
    1447           0 :         return NULL;
    1448           0 : }
    1449             : 
    1450           0 : static void radeon_dvi_force(struct drm_connector *connector)
    1451             : {
    1452           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1453           0 :         if (connector->force == DRM_FORCE_ON)
    1454           0 :                 radeon_connector->use_digital = false;
    1455           0 :         if (connector->force == DRM_FORCE_ON_DIGITAL)
    1456           0 :                 radeon_connector->use_digital = true;
    1457           0 : }
    1458             : 
    1459           0 : static enum drm_mode_status radeon_dvi_mode_valid(struct drm_connector *connector,
    1460             :                                   struct drm_display_mode *mode)
    1461             : {
    1462           0 :         struct drm_device *dev = connector->dev;
    1463           0 :         struct radeon_device *rdev = dev->dev_private;
    1464           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1465             : 
    1466             :         /* XXX check mode bandwidth */
    1467             : 
    1468             :         /* clocks over 135 MHz have heat issues with DVI on RV100 */
    1469           0 :         if (radeon_connector->use_digital &&
    1470           0 :             (rdev->family == CHIP_RV100) &&
    1471           0 :             (mode->clock > 135000))
    1472           0 :                 return MODE_CLOCK_HIGH;
    1473             : 
    1474           0 :         if (radeon_connector->use_digital && (mode->clock > 165000)) {
    1475           0 :                 if ((radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I) ||
    1476           0 :                     (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D) ||
    1477           0 :                     (radeon_connector->connector_object_id == CONNECTOR_OBJECT_ID_HDMI_TYPE_B))
    1478           0 :                         return MODE_OK;
    1479           0 :                 else if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
    1480             :                         /* HDMI 1.3+ supports max clock of 340 Mhz */
    1481           0 :                         if (mode->clock > 340000)
    1482           0 :                                 return MODE_CLOCK_HIGH;
    1483             :                         else
    1484           0 :                                 return MODE_OK;
    1485             :                 } else {
    1486           0 :                         return MODE_CLOCK_HIGH;
    1487             :                 }
    1488             :         }
    1489             : 
    1490             :         /* check against the max pixel clock */
    1491           0 :         if ((mode->clock / 10) > rdev->clock.max_pixel_clock)
    1492           0 :                 return MODE_CLOCK_HIGH;
    1493             : 
    1494           0 :         return MODE_OK;
    1495           0 : }
    1496             : 
    1497             : static const struct drm_connector_helper_funcs radeon_dvi_connector_helper_funcs = {
    1498             :         .get_modes = radeon_vga_get_modes,
    1499             :         .mode_valid = radeon_dvi_mode_valid,
    1500             :         .best_encoder = radeon_dvi_encoder,
    1501             : };
    1502             : 
    1503             : static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
    1504             :         .dpms = drm_helper_connector_dpms,
    1505             :         .detect = radeon_dvi_detect,
    1506             :         .fill_modes = drm_helper_probe_single_connector_modes,
    1507             :         .set_property = radeon_connector_set_property,
    1508             :         .destroy = radeon_connector_destroy,
    1509             :         .force = radeon_dvi_force,
    1510             : };
    1511             : 
    1512           0 : static int radeon_dp_get_modes(struct drm_connector *connector)
    1513             : {
    1514           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1515           0 :         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
    1516           0 :         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
    1517             :         int ret;
    1518             : 
    1519           0 :         if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
    1520           0 :             (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
    1521             :                 struct drm_display_mode *mode;
    1522             : 
    1523           0 :                 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
    1524           0 :                         if (!radeon_dig_connector->edp_on)
    1525           0 :                                 atombios_set_edp_panel_power(connector,
    1526             :                                                              ATOM_TRANSMITTER_ACTION_POWER_ON);
    1527           0 :                         radeon_connector_get_edid(connector);
    1528           0 :                         ret = radeon_ddc_get_modes(connector);
    1529           0 :                         if (!radeon_dig_connector->edp_on)
    1530           0 :                                 atombios_set_edp_panel_power(connector,
    1531             :                                                              ATOM_TRANSMITTER_ACTION_POWER_OFF);
    1532             :                 } else {
    1533             :                         /* need to setup ddc on the bridge */
    1534           0 :                         if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
    1535             :                             ENCODER_OBJECT_ID_NONE) {
    1536           0 :                                 if (encoder)
    1537           0 :                                         radeon_atom_ext_encoder_setup_ddc(encoder);
    1538             :                         }
    1539           0 :                         radeon_connector_get_edid(connector);
    1540           0 :                         ret = radeon_ddc_get_modes(connector);
    1541             :                 }
    1542             : 
    1543           0 :                 if (ret > 0) {
    1544           0 :                         if (encoder) {
    1545           0 :                                 radeon_fixup_lvds_native_mode(encoder, connector);
    1546             :                                 /* add scaled modes */
    1547           0 :                                 radeon_add_common_modes(encoder, connector);
    1548           0 :                         }
    1549           0 :                         return ret;
    1550             :                 }
    1551             : 
    1552           0 :                 if (!encoder)
    1553           0 :                         return 0;
    1554             : 
    1555             :                 /* we have no EDID modes */
    1556           0 :                 mode = radeon_fp_native_mode(encoder);
    1557           0 :                 if (mode) {
    1558             :                         ret = 1;
    1559           0 :                         drm_mode_probed_add(connector, mode);
    1560             :                         /* add the width/height from vbios tables if available */
    1561           0 :                         connector->display_info.width_mm = mode->width_mm;
    1562           0 :                         connector->display_info.height_mm = mode->height_mm;
    1563             :                         /* add scaled modes */
    1564           0 :                         radeon_add_common_modes(encoder, connector);
    1565           0 :                 }
    1566           0 :         } else {
    1567             :                 /* need to setup ddc on the bridge */
    1568           0 :                 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
    1569             :                         ENCODER_OBJECT_ID_NONE) {
    1570           0 :                         if (encoder)
    1571           0 :                                 radeon_atom_ext_encoder_setup_ddc(encoder);
    1572             :                 }
    1573           0 :                 radeon_connector_get_edid(connector);
    1574           0 :                 ret = radeon_ddc_get_modes(connector);
    1575             : 
    1576           0 :                 radeon_get_native_mode(connector);
    1577             :         }
    1578             : 
    1579           0 :         return ret;
    1580           0 : }
    1581             : 
    1582           0 : u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
    1583             : {
    1584             :         struct drm_encoder *encoder;
    1585             :         struct radeon_encoder *radeon_encoder;
    1586             :         int i;
    1587             : 
    1588           0 :         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
    1589           0 :                 if (connector->encoder_ids[i] == 0)
    1590             :                         break;
    1591             : 
    1592           0 :                 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
    1593           0 :                 if (!encoder)
    1594             :                         continue;
    1595             : 
    1596           0 :                 radeon_encoder = to_radeon_encoder(encoder);
    1597             : 
    1598           0 :                 switch (radeon_encoder->encoder_id) {
    1599             :                 case ENCODER_OBJECT_ID_TRAVIS:
    1600             :                 case ENCODER_OBJECT_ID_NUTMEG:
    1601           0 :                         return radeon_encoder->encoder_id;
    1602             :                 default:
    1603             :                         break;
    1604             :                 }
    1605             :         }
    1606             : 
    1607           0 :         return ENCODER_OBJECT_ID_NONE;
    1608           0 : }
    1609             : 
    1610           0 : static bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
    1611             : {
    1612             :         struct drm_encoder *encoder;
    1613             :         struct radeon_encoder *radeon_encoder;
    1614             :         int i;
    1615             :         bool found = false;
    1616             : 
    1617           0 :         for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
    1618           0 :                 if (connector->encoder_ids[i] == 0)
    1619             :                         break;
    1620             : 
    1621           0 :                 encoder = drm_encoder_find(connector->dev, connector->encoder_ids[i]);
    1622           0 :                 if (!encoder)
    1623             :                         continue;
    1624             : 
    1625           0 :                 radeon_encoder = to_radeon_encoder(encoder);
    1626           0 :                 if (radeon_encoder->caps & ATOM_ENCODER_CAP_RECORD_HBR2)
    1627           0 :                         found = true;
    1628             :         }
    1629             : 
    1630           0 :         return found;
    1631             : }
    1632             : 
    1633           0 : bool radeon_connector_is_dp12_capable(struct drm_connector *connector)
    1634             : {
    1635           0 :         struct drm_device *dev = connector->dev;
    1636           0 :         struct radeon_device *rdev = dev->dev_private;
    1637             : 
    1638           0 :         if (ASIC_IS_DCE5(rdev) &&
    1639           0 :             (rdev->clock.default_dispclk >= 53900) &&
    1640           0 :             radeon_connector_encoder_is_hbr2(connector)) {
    1641           0 :                 return true;
    1642             :         }
    1643             : 
    1644           0 :         return false;
    1645           0 : }
    1646             : 
    1647             : static enum drm_connector_status
    1648           0 : radeon_dp_detect(struct drm_connector *connector, bool force)
    1649             : {
    1650           0 :         struct drm_device *dev = connector->dev;
    1651           0 :         struct radeon_device *rdev = dev->dev_private;
    1652           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1653             :         enum drm_connector_status ret = connector_status_disconnected;
    1654           0 :         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
    1655           0 :         struct drm_encoder *encoder = radeon_best_single_encoder(connector);
    1656             :         int r;
    1657             : 
    1658           0 :         if (radeon_dig_connector->is_mst)
    1659           0 :                 return connector_status_disconnected;
    1660             : 
    1661           0 :         r = pm_runtime_get_sync(connector->dev->dev);
    1662           0 :         if (r < 0)
    1663           0 :                 return connector_status_disconnected;
    1664             : 
    1665           0 :         if (!force && radeon_check_hpd_status_unchanged(connector)) {
    1666           0 :                 ret = connector->status;
    1667           0 :                 goto out;
    1668             :         }
    1669             : 
    1670           0 :         radeon_connector_free_edid(connector);
    1671             : 
    1672           0 :         if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
    1673           0 :             (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
    1674           0 :                 if (encoder) {
    1675           0 :                         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
    1676           0 :                         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
    1677             : 
    1678             :                         /* check if panel is valid */
    1679           0 :                         if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
    1680           0 :                                 ret = connector_status_connected;
    1681             :                         /* don't fetch the edid from the vbios if ddc fails and runpm is
    1682             :                          * enabled so we report disconnected.
    1683             :                          */
    1684           0 :                         if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
    1685           0 :                                 ret = connector_status_disconnected;
    1686           0 :                 }
    1687             :                 /* eDP is always DP */
    1688           0 :                 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
    1689           0 :                 if (!radeon_dig_connector->edp_on)
    1690           0 :                         atombios_set_edp_panel_power(connector,
    1691             :                                                      ATOM_TRANSMITTER_ACTION_POWER_ON);
    1692           0 :                 if (radeon_dp_getdpcd(radeon_connector))
    1693           0 :                         ret = connector_status_connected;
    1694           0 :                 if (!radeon_dig_connector->edp_on)
    1695           0 :                         atombios_set_edp_panel_power(connector,
    1696             :                                                      ATOM_TRANSMITTER_ACTION_POWER_OFF);
    1697           0 :         } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
    1698             :                    ENCODER_OBJECT_ID_NONE) {
    1699             :                 /* DP bridges are always DP */
    1700           0 :                 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
    1701             :                 /* get the DPCD from the bridge */
    1702           0 :                 radeon_dp_getdpcd(radeon_connector);
    1703             : 
    1704           0 :                 if (encoder) {
    1705             :                         /* setup ddc on the bridge */
    1706           0 :                         radeon_atom_ext_encoder_setup_ddc(encoder);
    1707             :                         /* bridge chips are always aux */
    1708           0 :                         if (radeon_ddc_probe(radeon_connector, true)) /* try DDC */
    1709           0 :                                 ret = connector_status_connected;
    1710           0 :                         else if (radeon_connector->dac_load_detect) { /* try load detection */
    1711           0 :                                 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
    1712           0 :                                 ret = encoder_funcs->detect(encoder, connector);
    1713           0 :                         }
    1714             :                 }
    1715             :         } else {
    1716           0 :                 radeon_dig_connector->dp_sink_type = radeon_dp_getsinktype(radeon_connector);
    1717           0 :                 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) {
    1718             :                         ret = connector_status_connected;
    1719           0 :                         if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
    1720           0 :                                 radeon_dp_getdpcd(radeon_connector);
    1721           0 :                                 r = radeon_dp_mst_probe(radeon_connector);
    1722           0 :                                 if (r == 1)
    1723           0 :                                         ret = connector_status_disconnected;
    1724             :                         }
    1725             :                 } else {
    1726           0 :                         if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) {
    1727           0 :                                 if (radeon_dp_getdpcd(radeon_connector)) {
    1728           0 :                                         r = radeon_dp_mst_probe(radeon_connector);
    1729           0 :                                         if (r == 1)
    1730           0 :                                                 ret = connector_status_disconnected;
    1731             :                                         else
    1732             :                                                 ret = connector_status_connected;
    1733             :                                 }
    1734             :                         } else {
    1735             :                                 /* try non-aux ddc (DP to DVI/HDMI/etc. adapter) */
    1736           0 :                                 if (radeon_ddc_probe(radeon_connector, false))
    1737           0 :                                         ret = connector_status_connected;
    1738             :                         }
    1739             :                 }
    1740             :         }
    1741             : 
    1742           0 :         radeon_connector_update_scratch_regs(connector, ret);
    1743             : 
    1744           0 :         if ((radeon_audio != 0) && encoder) {
    1745           0 :                 radeon_connector_get_edid(connector);
    1746           0 :                 radeon_audio_detect(connector, encoder, ret);
    1747           0 :         }
    1748             : 
    1749             : out:
    1750             :         pm_runtime_mark_last_busy(connector->dev->dev);
    1751             :         pm_runtime_put_autosuspend(connector->dev->dev);
    1752             : 
    1753           0 :         return ret;
    1754           0 : }
    1755             : 
    1756           0 : static enum drm_mode_status radeon_dp_mode_valid(struct drm_connector *connector,
    1757             :                                   struct drm_display_mode *mode)
    1758             : {
    1759           0 :         struct drm_device *dev = connector->dev;
    1760           0 :         struct radeon_device *rdev = dev->dev_private;
    1761           0 :         struct radeon_connector *radeon_connector = to_radeon_connector(connector);
    1762           0 :         struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
    1763             : 
    1764             :         /* XXX check mode bandwidth */
    1765             : 
    1766           0 :         if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) ||
    1767           0 :             (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)) {
    1768           0 :                 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
    1769             : 
    1770           0 :                 if ((mode->hdisplay < 320) || (mode->vdisplay < 240))
    1771           0 :                         return MODE_PANEL;
    1772             : 
    1773           0 :                 if (encoder) {
    1774           0 :                         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
    1775           0 :                         struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
    1776             : 
    1777             :                         /* AVIVO hardware supports downscaling modes larger than the panel
    1778             :                          * to the panel size, but I'm not sure this is desirable.
    1779             :                          */
    1780           0 :                         if ((mode->hdisplay > native_mode->hdisplay) ||
    1781           0 :                             (mode->vdisplay > native_mode->vdisplay))
    1782           0 :                                 return MODE_PANEL;
    1783             : 
    1784             :                         /* if scaling is disabled, block non-native modes */
    1785           0 :                         if (radeon_encoder->rmx_type == RMX_OFF) {
    1786           0 :                                 if ((mode->hdisplay != native_mode->hdisplay) ||
    1787           0 :                                     (mode->vdisplay != native_mode->vdisplay))
    1788           0 :                                         return MODE_PANEL;
    1789             :                         }
    1790           0 :                 }
    1791           0 :         } else {
    1792           0 :                 if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
    1793           0 :                     (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
    1794           0 :                         return radeon_dp_mode_valid_helper(connector, mode);
    1795             :                 } else {
    1796           0 :                         if (ASIC_IS_DCE6(rdev) && drm_detect_hdmi_monitor(radeon_connector_edid(connector))) {
    1797             :                                 /* HDMI 1.3+ supports max clock of 340 Mhz */
    1798           0 :                                 if (mode->clock > 340000)
    1799           0 :                                         return MODE_CLOCK_HIGH;
    1800             :                         } else {
    1801           0 :                                 if (mode->clock > 165000)
    1802           0 :                                         return MODE_CLOCK_HIGH;
    1803             :                         }
    1804             :                 }
    1805             :         }
    1806             : 
    1807           0 :         return MODE_OK;
    1808           0 : }
    1809             : 
    1810             : static const struct drm_connector_helper_funcs radeon_dp_connector_helper_funcs = {
    1811             :         .get_modes = radeon_dp_get_modes,
    1812             :         .mode_valid = radeon_dp_mode_valid,
    1813             :         .best_encoder = radeon_dvi_encoder,
    1814             : };
    1815             : 
    1816             : static const struct drm_connector_funcs radeon_dp_connector_funcs = {
    1817             :         .dpms = drm_helper_connector_dpms,
    1818             :         .detect = radeon_dp_detect,
    1819             :         .fill_modes = drm_helper_probe_single_connector_modes,
    1820             :         .set_property = radeon_connector_set_property,
    1821             :         .destroy = radeon_connector_destroy,
    1822             :         .force = radeon_dvi_force,
    1823             : };
    1824             : 
    1825             : static const struct drm_connector_funcs radeon_edp_connector_funcs = {
    1826             :         .dpms = drm_helper_connector_dpms,
    1827             :         .detect = radeon_dp_detect,
    1828             :         .fill_modes = drm_helper_probe_single_connector_modes,
    1829             :         .set_property = radeon_lvds_set_property,
    1830             :         .destroy = radeon_connector_destroy,
    1831             :         .force = radeon_dvi_force,
    1832             : };
    1833             : 
    1834             : static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
    1835             :         .dpms = drm_helper_connector_dpms,
    1836             :         .detect = radeon_dp_detect,
    1837             :         .fill_modes = drm_helper_probe_single_connector_modes,
    1838             :         .set_property = radeon_lvds_set_property,
    1839             :         .destroy = radeon_connector_destroy,
    1840             :         .force = radeon_dvi_force,
    1841             : };
    1842             : 
    1843             : void
    1844           0 : radeon_add_atom_connector(struct drm_device *dev,
    1845             :                           uint32_t connector_id,
    1846             :                           uint32_t supported_device,
    1847             :                           int connector_type,
    1848             :                           struct radeon_i2c_bus_rec *i2c_bus,
    1849             :                           uint32_t igp_lane_info,
    1850             :                           uint16_t connector_object_id,
    1851             :                           struct radeon_hpd *hpd,
    1852             :                           struct radeon_router *router)
    1853             : {
    1854           0 :         struct radeon_device *rdev = dev->dev_private;
    1855             :         struct drm_connector *connector;
    1856             :         struct radeon_connector *radeon_connector;
    1857             :         struct radeon_connector_atom_dig *radeon_dig_connector;
    1858             :         struct drm_encoder *encoder;
    1859             :         struct radeon_encoder *radeon_encoder;
    1860             :         uint32_t subpixel_order = SubPixelNone;
    1861             :         bool shared_ddc = false;
    1862             :         bool is_dp_bridge = false;
    1863             :         bool has_aux = false;
    1864             : 
    1865           0 :         if (connector_type == DRM_MODE_CONNECTOR_Unknown)
    1866           0 :                 return;
    1867             : 
    1868             :         /* if the user selected tv=0 don't try and add the connector */
    1869           0 :         if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
    1870           0 :              (connector_type == DRM_MODE_CONNECTOR_Composite) ||
    1871           0 :              (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
    1872           0 :             (radeon_tv == 0))
    1873           0 :                 return;
    1874             : 
    1875             :         /* see if we already added it */
    1876           0 :         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
    1877           0 :                 radeon_connector = to_radeon_connector(connector);
    1878           0 :                 if (radeon_connector->connector_id == connector_id) {
    1879           0 :                         radeon_connector->devices |= supported_device;
    1880           0 :                         return;
    1881             :                 }
    1882           0 :                 if (radeon_connector->ddc_bus && i2c_bus->valid) {
    1883           0 :                         if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
    1884           0 :                                 radeon_connector->shared_ddc = true;
    1885             :                                 shared_ddc = true;
    1886           0 :                         }
    1887           0 :                         if (radeon_connector->router_bus && router->ddc_valid &&
    1888           0 :                             (radeon_connector->router.router_id == router->router_id)) {
    1889           0 :                                 radeon_connector->shared_ddc = false;
    1890             :                                 shared_ddc = false;
    1891           0 :                         }
    1892             :                 }
    1893             :         }
    1894             : 
    1895             :         /* check if it's a dp bridge */
    1896           0 :         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
    1897           0 :                 radeon_encoder = to_radeon_encoder(encoder);
    1898           0 :                 if (radeon_encoder->devices & supported_device) {
    1899           0 :                         switch (radeon_encoder->encoder_id) {
    1900             :                         case ENCODER_OBJECT_ID_TRAVIS:
    1901             :                         case ENCODER_OBJECT_ID_NUTMEG:
    1902             :                                 is_dp_bridge = true;
    1903           0 :                                 break;
    1904             :                         default:
    1905             :                                 break;
    1906             :                         }
    1907             :                 }
    1908             :         }
    1909             : 
    1910           0 :         radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
    1911           0 :         if (!radeon_connector)
    1912           0 :                 return;
    1913             : 
    1914           0 :         connector = &radeon_connector->base;
    1915             : 
    1916           0 :         radeon_connector->connector_id = connector_id;
    1917           0 :         radeon_connector->devices = supported_device;
    1918           0 :         radeon_connector->shared_ddc = shared_ddc;
    1919           0 :         radeon_connector->connector_object_id = connector_object_id;
    1920           0 :         radeon_connector->hpd = *hpd;
    1921             : 
    1922           0 :         radeon_connector->router = *router;
    1923           0 :         if (router->ddc_valid || router->cd_valid) {
    1924           0 :                 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
    1925           0 :                 if (!radeon_connector->router_bus)
    1926           0 :                         DRM_ERROR("Failed to assign router i2c bus! Check dmesg for i2c errors.\n");
    1927             :         }
    1928             : 
    1929           0 :         if (is_dp_bridge) {
    1930           0 :                 radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
    1931           0 :                 if (!radeon_dig_connector)
    1932             :                         goto failed;
    1933           0 :                 radeon_dig_connector->igp_lane_info = igp_lane_info;
    1934           0 :                 radeon_connector->con_priv = radeon_dig_connector;
    1935           0 :                 if (i2c_bus->valid) {
    1936           0 :                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    1937           0 :                         if (radeon_connector->ddc_bus)
    1938           0 :                                 has_aux = true;
    1939             :                         else
    1940           0 :                                 DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    1941             :                 }
    1942           0 :                 switch (connector_type) {
    1943             :                 case DRM_MODE_CONNECTOR_VGA:
    1944             :                 case DRM_MODE_CONNECTOR_DVIA:
    1945             :                 default:
    1946           0 :                         drm_connector_init(dev, &radeon_connector->base,
    1947             :                                            &radeon_dp_connector_funcs, connector_type);
    1948           0 :                         drm_connector_helper_add(&radeon_connector->base,
    1949             :                                                  &radeon_dp_connector_helper_funcs);
    1950           0 :                         connector->interlace_allowed = true;
    1951           0 :                         connector->doublescan_allowed = true;
    1952           0 :                         radeon_connector->dac_load_detect = true;
    1953           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1954           0 :                                                       rdev->mode_info.load_detect_property,
    1955             :                                                       1);
    1956           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1957           0 :                                                    dev->mode_config.scaling_mode_property,
    1958             :                                                    DRM_MODE_SCALE_NONE);
    1959           0 :                         if (ASIC_IS_DCE5(rdev))
    1960           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    1961           0 :                                                            rdev->mode_info.output_csc_property,
    1962             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    1963             :                         break;
    1964             :                 case DRM_MODE_CONNECTOR_DVII:
    1965             :                 case DRM_MODE_CONNECTOR_DVID:
    1966             :                 case DRM_MODE_CONNECTOR_HDMIA:
    1967             :                 case DRM_MODE_CONNECTOR_HDMIB:
    1968             :                 case DRM_MODE_CONNECTOR_DisplayPort:
    1969           0 :                         drm_connector_init(dev, &radeon_connector->base,
    1970             :                                            &radeon_dp_connector_funcs, connector_type);
    1971           0 :                         drm_connector_helper_add(&radeon_connector->base,
    1972             :                                                  &radeon_dp_connector_helper_funcs);
    1973           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1974           0 :                                                       rdev->mode_info.underscan_property,
    1975             :                                                       UNDERSCAN_OFF);
    1976           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1977           0 :                                                       rdev->mode_info.underscan_hborder_property,
    1978             :                                                       0);
    1979           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1980           0 :                                                       rdev->mode_info.underscan_vborder_property,
    1981             :                                                       0);
    1982             : 
    1983           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1984           0 :                                                       dev->mode_config.scaling_mode_property,
    1985             :                                                       DRM_MODE_SCALE_NONE);
    1986             : 
    1987           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    1988           0 :                                                    rdev->mode_info.dither_property,
    1989             :                                                    RADEON_FMT_DITHER_DISABLE);
    1990             : 
    1991           0 :                         if (radeon_audio != 0) {
    1992           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    1993           0 :                                                            rdev->mode_info.audio_property,
    1994             :                                                            RADEON_AUDIO_AUTO);
    1995           0 :                                 radeon_connector->audio = RADEON_AUDIO_AUTO;
    1996           0 :                         }
    1997           0 :                         if (ASIC_IS_DCE5(rdev))
    1998           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    1999           0 :                                                            rdev->mode_info.output_csc_property,
    2000             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    2001             : 
    2002             :                         subpixel_order = SubPixelHorizontalRGB;
    2003           0 :                         connector->interlace_allowed = true;
    2004           0 :                         if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
    2005           0 :                                 connector->doublescan_allowed = true;
    2006             :                         else
    2007           0 :                                 connector->doublescan_allowed = false;
    2008           0 :                         if (connector_type == DRM_MODE_CONNECTOR_DVII) {
    2009           0 :                                 radeon_connector->dac_load_detect = true;
    2010           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2011           0 :                                                               rdev->mode_info.load_detect_property,
    2012             :                                                               1);
    2013           0 :                         }
    2014             :                         break;
    2015             :                 case DRM_MODE_CONNECTOR_LVDS:
    2016             :                 case DRM_MODE_CONNECTOR_eDP:
    2017           0 :                         drm_connector_init(dev, &radeon_connector->base,
    2018             :                                            &radeon_lvds_bridge_connector_funcs, connector_type);
    2019           0 :                         drm_connector_helper_add(&radeon_connector->base,
    2020             :                                                  &radeon_dp_connector_helper_funcs);
    2021           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2022           0 :                                                       dev->mode_config.scaling_mode_property,
    2023             :                                                       DRM_MODE_SCALE_FULLSCREEN);
    2024             :                         subpixel_order = SubPixelHorizontalRGB;
    2025           0 :                         connector->interlace_allowed = false;
    2026           0 :                         connector->doublescan_allowed = false;
    2027           0 :                         break;
    2028             :                 }
    2029             :         } else {
    2030           0 :                 switch (connector_type) {
    2031             :                 case DRM_MODE_CONNECTOR_VGA:
    2032           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
    2033           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
    2034           0 :                         if (i2c_bus->valid) {
    2035           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2036           0 :                                 if (!radeon_connector->ddc_bus)
    2037           0 :                                         DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2038             :                         }
    2039           0 :                         radeon_connector->dac_load_detect = true;
    2040           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2041           0 :                                                       rdev->mode_info.load_detect_property,
    2042             :                                                       1);
    2043           0 :                         if (ASIC_IS_AVIVO(rdev))
    2044           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2045           0 :                                                            dev->mode_config.scaling_mode_property,
    2046             :                                                            DRM_MODE_SCALE_NONE);
    2047           0 :                         if (ASIC_IS_DCE5(rdev))
    2048           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2049           0 :                                                            rdev->mode_info.output_csc_property,
    2050             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    2051             :                         /* no HPD on analog connectors */
    2052           0 :                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
    2053           0 :                         connector->interlace_allowed = true;
    2054           0 :                         connector->doublescan_allowed = true;
    2055           0 :                         break;
    2056             :                 case DRM_MODE_CONNECTOR_DVIA:
    2057           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
    2058           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
    2059           0 :                         if (i2c_bus->valid) {
    2060           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2061           0 :                                 if (!radeon_connector->ddc_bus)
    2062           0 :                                         DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2063             :                         }
    2064           0 :                         radeon_connector->dac_load_detect = true;
    2065           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2066           0 :                                                       rdev->mode_info.load_detect_property,
    2067             :                                                       1);
    2068           0 :                         if (ASIC_IS_AVIVO(rdev))
    2069           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2070           0 :                                                            dev->mode_config.scaling_mode_property,
    2071             :                                                            DRM_MODE_SCALE_NONE);
    2072           0 :                         if (ASIC_IS_DCE5(rdev))
    2073           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2074           0 :                                                            rdev->mode_info.output_csc_property,
    2075             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    2076             :                         /* no HPD on analog connectors */
    2077           0 :                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
    2078           0 :                         connector->interlace_allowed = true;
    2079           0 :                         connector->doublescan_allowed = true;
    2080           0 :                         break;
    2081             :                 case DRM_MODE_CONNECTOR_DVII:
    2082             :                 case DRM_MODE_CONNECTOR_DVID:
    2083           0 :                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
    2084           0 :                         if (!radeon_dig_connector)
    2085             :                                 goto failed;
    2086           0 :                         radeon_dig_connector->igp_lane_info = igp_lane_info;
    2087           0 :                         radeon_connector->con_priv = radeon_dig_connector;
    2088           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
    2089           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
    2090           0 :                         if (i2c_bus->valid) {
    2091           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2092           0 :                                 if (!radeon_connector->ddc_bus)
    2093           0 :                                         DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2094             :                         }
    2095             :                         subpixel_order = SubPixelHorizontalRGB;
    2096           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2097           0 :                                                       rdev->mode_info.coherent_mode_property,
    2098             :                                                       1);
    2099           0 :                         if (ASIC_IS_AVIVO(rdev)) {
    2100           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2101           0 :                                                               rdev->mode_info.underscan_property,
    2102             :                                                               UNDERSCAN_OFF);
    2103           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2104           0 :                                                               rdev->mode_info.underscan_hborder_property,
    2105             :                                                               0);
    2106           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2107           0 :                                                               rdev->mode_info.underscan_vborder_property,
    2108             :                                                               0);
    2109           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2110           0 :                                                            rdev->mode_info.dither_property,
    2111             :                                                            RADEON_FMT_DITHER_DISABLE);
    2112           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2113           0 :                                                            dev->mode_config.scaling_mode_property,
    2114             :                                                            DRM_MODE_SCALE_NONE);
    2115           0 :                         }
    2116           0 :                         if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
    2117           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2118           0 :                                                            rdev->mode_info.audio_property,
    2119             :                                                            RADEON_AUDIO_AUTO);
    2120           0 :                                 radeon_connector->audio = RADEON_AUDIO_AUTO;
    2121           0 :                         }
    2122           0 :                         if (connector_type == DRM_MODE_CONNECTOR_DVII) {
    2123           0 :                                 radeon_connector->dac_load_detect = true;
    2124           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2125           0 :                                                               rdev->mode_info.load_detect_property,
    2126             :                                                               1);
    2127           0 :                         }
    2128           0 :                         if (ASIC_IS_DCE5(rdev))
    2129           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2130           0 :                                                            rdev->mode_info.output_csc_property,
    2131             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    2132           0 :                         connector->interlace_allowed = true;
    2133           0 :                         if (connector_type == DRM_MODE_CONNECTOR_DVII)
    2134           0 :                                 connector->doublescan_allowed = true;
    2135             :                         else
    2136           0 :                                 connector->doublescan_allowed = false;
    2137             :                         break;
    2138             :                 case DRM_MODE_CONNECTOR_HDMIA:
    2139             :                 case DRM_MODE_CONNECTOR_HDMIB:
    2140           0 :                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
    2141           0 :                         if (!radeon_dig_connector)
    2142             :                                 goto failed;
    2143           0 :                         radeon_dig_connector->igp_lane_info = igp_lane_info;
    2144           0 :                         radeon_connector->con_priv = radeon_dig_connector;
    2145           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
    2146           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
    2147           0 :                         if (i2c_bus->valid) {
    2148           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2149           0 :                                 if (!radeon_connector->ddc_bus)
    2150           0 :                                         DRM_ERROR("HDMI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2151             :                         }
    2152           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2153           0 :                                                       rdev->mode_info.coherent_mode_property,
    2154             :                                                       1);
    2155           0 :                         if (ASIC_IS_AVIVO(rdev)) {
    2156           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2157           0 :                                                               rdev->mode_info.underscan_property,
    2158             :                                                               UNDERSCAN_OFF);
    2159           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2160           0 :                                                               rdev->mode_info.underscan_hborder_property,
    2161             :                                                               0);
    2162           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2163           0 :                                                               rdev->mode_info.underscan_vborder_property,
    2164             :                                                               0);
    2165           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2166           0 :                                                            rdev->mode_info.dither_property,
    2167             :                                                            RADEON_FMT_DITHER_DISABLE);
    2168           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2169           0 :                                                            dev->mode_config.scaling_mode_property,
    2170             :                                                            DRM_MODE_SCALE_NONE);
    2171           0 :                         }
    2172           0 :                         if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
    2173           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2174           0 :                                                            rdev->mode_info.audio_property,
    2175             :                                                            RADEON_AUDIO_AUTO);
    2176           0 :                                 radeon_connector->audio = RADEON_AUDIO_AUTO;
    2177           0 :                         }
    2178           0 :                         if (ASIC_IS_DCE5(rdev))
    2179           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2180           0 :                                                            rdev->mode_info.output_csc_property,
    2181             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    2182             :                         subpixel_order = SubPixelHorizontalRGB;
    2183           0 :                         connector->interlace_allowed = true;
    2184           0 :                         if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
    2185           0 :                                 connector->doublescan_allowed = true;
    2186             :                         else
    2187           0 :                                 connector->doublescan_allowed = false;
    2188             :                         break;
    2189             :                 case DRM_MODE_CONNECTOR_DisplayPort:
    2190           0 :                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
    2191           0 :                         if (!radeon_dig_connector)
    2192             :                                 goto failed;
    2193           0 :                         radeon_dig_connector->igp_lane_info = igp_lane_info;
    2194           0 :                         radeon_connector->con_priv = radeon_dig_connector;
    2195           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_dp_connector_funcs, connector_type);
    2196           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
    2197           0 :                         if (i2c_bus->valid) {
    2198           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2199           0 :                                 if (radeon_connector->ddc_bus)
    2200           0 :                                         has_aux = true;
    2201             :                                 else
    2202           0 :                                         DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2203             :                         }
    2204             :                         subpixel_order = SubPixelHorizontalRGB;
    2205           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2206           0 :                                                       rdev->mode_info.coherent_mode_property,
    2207             :                                                       1);
    2208           0 :                         if (ASIC_IS_AVIVO(rdev)) {
    2209           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2210           0 :                                                               rdev->mode_info.underscan_property,
    2211             :                                                               UNDERSCAN_OFF);
    2212           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2213           0 :                                                               rdev->mode_info.underscan_hborder_property,
    2214             :                                                               0);
    2215           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2216           0 :                                                               rdev->mode_info.underscan_vborder_property,
    2217             :                                                               0);
    2218           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2219           0 :                                                            rdev->mode_info.dither_property,
    2220             :                                                            RADEON_FMT_DITHER_DISABLE);
    2221           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2222           0 :                                                            dev->mode_config.scaling_mode_property,
    2223             :                                                            DRM_MODE_SCALE_NONE);
    2224           0 :                         }
    2225           0 :                         if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
    2226           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2227           0 :                                                            rdev->mode_info.audio_property,
    2228             :                                                            RADEON_AUDIO_AUTO);
    2229           0 :                                 radeon_connector->audio = RADEON_AUDIO_AUTO;
    2230           0 :                         }
    2231           0 :                         if (ASIC_IS_DCE5(rdev))
    2232           0 :                                 drm_object_attach_property(&radeon_connector->base.base,
    2233           0 :                                                            rdev->mode_info.output_csc_property,
    2234             :                                                            RADEON_OUTPUT_CSC_BYPASS);
    2235           0 :                         connector->interlace_allowed = true;
    2236             :                         /* in theory with a DP to VGA converter... */
    2237           0 :                         connector->doublescan_allowed = false;
    2238           0 :                         break;
    2239             :                 case DRM_MODE_CONNECTOR_eDP:
    2240           0 :                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
    2241           0 :                         if (!radeon_dig_connector)
    2242             :                                 goto failed;
    2243           0 :                         radeon_dig_connector->igp_lane_info = igp_lane_info;
    2244           0 :                         radeon_connector->con_priv = radeon_dig_connector;
    2245           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_edp_connector_funcs, connector_type);
    2246           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_dp_connector_helper_funcs);
    2247           0 :                         if (i2c_bus->valid) {
    2248           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2249           0 :                                 if (radeon_connector->ddc_bus)
    2250           0 :                                         has_aux = true;
    2251             :                                 else
    2252           0 :                                         DRM_ERROR("DP: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2253             :                         }
    2254           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2255           0 :                                                       dev->mode_config.scaling_mode_property,
    2256             :                                                       DRM_MODE_SCALE_FULLSCREEN);
    2257             :                         subpixel_order = SubPixelHorizontalRGB;
    2258           0 :                         connector->interlace_allowed = false;
    2259           0 :                         connector->doublescan_allowed = false;
    2260           0 :                         break;
    2261             :                 case DRM_MODE_CONNECTOR_SVIDEO:
    2262             :                 case DRM_MODE_CONNECTOR_Composite:
    2263             :                 case DRM_MODE_CONNECTOR_9PinDIN:
    2264           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
    2265           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
    2266           0 :                         radeon_connector->dac_load_detect = true;
    2267           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2268           0 :                                                       rdev->mode_info.load_detect_property,
    2269             :                                                       1);
    2270           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2271           0 :                                                       rdev->mode_info.tv_std_property,
    2272           0 :                                                       radeon_atombios_get_tv_info(rdev));
    2273             :                         /* no HPD on analog connectors */
    2274           0 :                         radeon_connector->hpd.hpd = RADEON_HPD_NONE;
    2275           0 :                         connector->interlace_allowed = false;
    2276           0 :                         connector->doublescan_allowed = false;
    2277           0 :                         break;
    2278             :                 case DRM_MODE_CONNECTOR_LVDS:
    2279           0 :                         radeon_dig_connector = kzalloc(sizeof(struct radeon_connector_atom_dig), GFP_KERNEL);
    2280           0 :                         if (!radeon_dig_connector)
    2281             :                                 goto failed;
    2282           0 :                         radeon_dig_connector->igp_lane_info = igp_lane_info;
    2283           0 :                         radeon_connector->con_priv = radeon_dig_connector;
    2284           0 :                         drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
    2285           0 :                         drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
    2286           0 :                         if (i2c_bus->valid) {
    2287           0 :                                 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2288           0 :                                 if (!radeon_connector->ddc_bus)
    2289           0 :                                         DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2290             :                         }
    2291           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2292           0 :                                                       dev->mode_config.scaling_mode_property,
    2293             :                                                       DRM_MODE_SCALE_FULLSCREEN);
    2294             :                         subpixel_order = SubPixelHorizontalRGB;
    2295           0 :                         connector->interlace_allowed = false;
    2296           0 :                         connector->doublescan_allowed = false;
    2297           0 :                         break;
    2298             :                 }
    2299             :         }
    2300             : 
    2301           0 :         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
    2302           0 :                 if (i2c_bus->valid) {
    2303           0 :                         connector->polled = DRM_CONNECTOR_POLL_CONNECT |
    2304             :                                             DRM_CONNECTOR_POLL_DISCONNECT;
    2305           0 :                 }
    2306             :         } else
    2307           0 :                 connector->polled = DRM_CONNECTOR_POLL_HPD;
    2308             : 
    2309           0 :         connector->display_info.subpixel_order = subpixel_order;
    2310           0 :         drm_connector_register(connector);
    2311             : 
    2312           0 :         if (has_aux)
    2313           0 :                 radeon_dp_aux_init(radeon_connector);
    2314             : 
    2315           0 :         return;
    2316             : 
    2317             : failed:
    2318           0 :         drm_connector_cleanup(connector);
    2319           0 :         kfree(connector);
    2320           0 : }
    2321             : 
    2322             : void
    2323           0 : radeon_add_legacy_connector(struct drm_device *dev,
    2324             :                             uint32_t connector_id,
    2325             :                             uint32_t supported_device,
    2326             :                             int connector_type,
    2327             :                             struct radeon_i2c_bus_rec *i2c_bus,
    2328             :                             uint16_t connector_object_id,
    2329             :                             struct radeon_hpd *hpd)
    2330             : {
    2331           0 :         struct radeon_device *rdev = dev->dev_private;
    2332             :         struct drm_connector *connector;
    2333             :         struct radeon_connector *radeon_connector;
    2334             :         uint32_t subpixel_order = SubPixelNone;
    2335             : 
    2336           0 :         if (connector_type == DRM_MODE_CONNECTOR_Unknown)
    2337           0 :                 return;
    2338             : 
    2339             :         /* if the user selected tv=0 don't try and add the connector */
    2340           0 :         if (((connector_type == DRM_MODE_CONNECTOR_SVIDEO) ||
    2341           0 :              (connector_type == DRM_MODE_CONNECTOR_Composite) ||
    2342           0 :              (connector_type == DRM_MODE_CONNECTOR_9PinDIN)) &&
    2343           0 :             (radeon_tv == 0))
    2344           0 :                 return;
    2345             : 
    2346             :         /* see if we already added it */
    2347           0 :         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
    2348           0 :                 radeon_connector = to_radeon_connector(connector);
    2349           0 :                 if (radeon_connector->connector_id == connector_id) {
    2350           0 :                         radeon_connector->devices |= supported_device;
    2351           0 :                         return;
    2352             :                 }
    2353             :         }
    2354             : 
    2355           0 :         radeon_connector = kzalloc(sizeof(struct radeon_connector), GFP_KERNEL);
    2356           0 :         if (!radeon_connector)
    2357           0 :                 return;
    2358             : 
    2359           0 :         connector = &radeon_connector->base;
    2360             : 
    2361           0 :         radeon_connector->connector_id = connector_id;
    2362           0 :         radeon_connector->devices = supported_device;
    2363           0 :         radeon_connector->connector_object_id = connector_object_id;
    2364           0 :         radeon_connector->hpd = *hpd;
    2365             : 
    2366           0 :         switch (connector_type) {
    2367             :         case DRM_MODE_CONNECTOR_VGA:
    2368           0 :                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
    2369           0 :                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
    2370           0 :                 if (i2c_bus->valid) {
    2371           0 :                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2372           0 :                         if (!radeon_connector->ddc_bus)
    2373           0 :                                 DRM_ERROR("VGA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2374             :                 }
    2375           0 :                 radeon_connector->dac_load_detect = true;
    2376           0 :                 drm_object_attach_property(&radeon_connector->base.base,
    2377           0 :                                               rdev->mode_info.load_detect_property,
    2378             :                                               1);
    2379             :                 /* no HPD on analog connectors */
    2380           0 :                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
    2381           0 :                 connector->interlace_allowed = true;
    2382           0 :                 connector->doublescan_allowed = true;
    2383           0 :                 break;
    2384             :         case DRM_MODE_CONNECTOR_DVIA:
    2385           0 :                 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
    2386           0 :                 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
    2387           0 :                 if (i2c_bus->valid) {
    2388           0 :                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2389           0 :                         if (!radeon_connector->ddc_bus)
    2390           0 :                                 DRM_ERROR("DVIA: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2391             :                 }
    2392           0 :                 radeon_connector->dac_load_detect = true;
    2393           0 :                 drm_object_attach_property(&radeon_connector->base.base,
    2394           0 :                                               rdev->mode_info.load_detect_property,
    2395             :                                               1);
    2396             :                 /* no HPD on analog connectors */
    2397           0 :                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
    2398           0 :                 connector->interlace_allowed = true;
    2399           0 :                 connector->doublescan_allowed = true;
    2400           0 :                 break;
    2401             :         case DRM_MODE_CONNECTOR_DVII:
    2402             :         case DRM_MODE_CONNECTOR_DVID:
    2403           0 :                 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
    2404           0 :                 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
    2405           0 :                 if (i2c_bus->valid) {
    2406           0 :                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2407           0 :                         if (!radeon_connector->ddc_bus)
    2408           0 :                                 DRM_ERROR("DVI: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2409             :                 }
    2410           0 :                 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
    2411           0 :                         radeon_connector->dac_load_detect = true;
    2412           0 :                         drm_object_attach_property(&radeon_connector->base.base,
    2413           0 :                                                       rdev->mode_info.load_detect_property,
    2414             :                                                       1);
    2415           0 :                 }
    2416             :                 subpixel_order = SubPixelHorizontalRGB;
    2417           0 :                 connector->interlace_allowed = true;
    2418           0 :                 if (connector_type == DRM_MODE_CONNECTOR_DVII)
    2419           0 :                         connector->doublescan_allowed = true;
    2420             :                 else
    2421           0 :                         connector->doublescan_allowed = false;
    2422             :                 break;
    2423             :         case DRM_MODE_CONNECTOR_SVIDEO:
    2424             :         case DRM_MODE_CONNECTOR_Composite:
    2425             :         case DRM_MODE_CONNECTOR_9PinDIN:
    2426           0 :                 drm_connector_init(dev, &radeon_connector->base, &radeon_tv_connector_funcs, connector_type);
    2427           0 :                 drm_connector_helper_add(&radeon_connector->base, &radeon_tv_connector_helper_funcs);
    2428           0 :                 radeon_connector->dac_load_detect = true;
    2429             :                 /* RS400,RC410,RS480 chipset seems to report a lot
    2430             :                  * of false positive on load detect, we haven't yet
    2431             :                  * found a way to make load detect reliable on those
    2432             :                  * chipset, thus just disable it for TV.
    2433             :                  */
    2434           0 :                 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480)
    2435           0 :                         radeon_connector->dac_load_detect = false;
    2436           0 :                 drm_object_attach_property(&radeon_connector->base.base,
    2437           0 :                                               rdev->mode_info.load_detect_property,
    2438           0 :                                               radeon_connector->dac_load_detect);
    2439           0 :                 drm_object_attach_property(&radeon_connector->base.base,
    2440           0 :                                               rdev->mode_info.tv_std_property,
    2441           0 :                                               radeon_combios_get_tv_info(rdev));
    2442             :                 /* no HPD on analog connectors */
    2443           0 :                 radeon_connector->hpd.hpd = RADEON_HPD_NONE;
    2444           0 :                 connector->interlace_allowed = false;
    2445           0 :                 connector->doublescan_allowed = false;
    2446           0 :                 break;
    2447             :         case DRM_MODE_CONNECTOR_LVDS:
    2448           0 :                 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
    2449           0 :                 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
    2450           0 :                 if (i2c_bus->valid) {
    2451           0 :                         radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
    2452           0 :                         if (!radeon_connector->ddc_bus)
    2453           0 :                                 DRM_ERROR("LVDS: Failed to assign ddc bus! Check dmesg for i2c errors.\n");
    2454             :                 }
    2455           0 :                 drm_object_attach_property(&radeon_connector->base.base,
    2456           0 :                                               dev->mode_config.scaling_mode_property,
    2457             :                                               DRM_MODE_SCALE_FULLSCREEN);
    2458             :                 subpixel_order = SubPixelHorizontalRGB;
    2459           0 :                 connector->interlace_allowed = false;
    2460           0 :                 connector->doublescan_allowed = false;
    2461           0 :                 break;
    2462             :         }
    2463             : 
    2464           0 :         if (radeon_connector->hpd.hpd == RADEON_HPD_NONE) {
    2465           0 :                 if (i2c_bus->valid) {
    2466           0 :                         connector->polled = DRM_CONNECTOR_POLL_CONNECT |
    2467             :                                             DRM_CONNECTOR_POLL_DISCONNECT;
    2468           0 :                 }
    2469             :         } else
    2470           0 :                 connector->polled = DRM_CONNECTOR_POLL_HPD;
    2471             : 
    2472           0 :         connector->display_info.subpixel_order = subpixel_order;
    2473           0 :         drm_connector_register(connector);
    2474           0 : }
    2475             : 
    2476           0 : void radeon_setup_mst_connector(struct drm_device *dev)
    2477             : {
    2478           0 :         struct radeon_device *rdev = dev->dev_private;
    2479             :         struct drm_connector *connector;
    2480             :         struct radeon_connector *radeon_connector;
    2481             : 
    2482           0 :         if (!ASIC_IS_DCE5(rdev))
    2483           0 :                 return;
    2484             : 
    2485           0 :         if (radeon_mst == 0)
    2486           0 :                 return;
    2487             : 
    2488           0 :         list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
    2489             :                 int ret;
    2490             : 
    2491           0 :                 radeon_connector = to_radeon_connector(connector);
    2492             : 
    2493           0 :                 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
    2494           0 :                         continue;
    2495             : 
    2496           0 :                 ret = radeon_dp_mst_init(radeon_connector);
    2497           0 :         }
    2498           0 : }

Generated by: LCOV version 1.13