@@ -32,6 +32,7 @@
#include <linux/hdmi.h>
#include <linux/i2c.h>
#include <linux/module.h>
+#include <linux/vga_switcheroo.h>
#include <drm/drmP.h>
#include <drm/drm_edid.h>
#include <drm/drm_displayid.h>
@@ -87,6 +88,8 @@ struct detailed_mode_closure {
#define LEVEL_GTF2 2
#define LEVEL_CVT 3
+static DEFINE_MUTEX(drm_edid_mutex);
+
static struct edid_quirk {
char vendor[4];
int product_id;
@@ -1377,6 +1380,16 @@ struct edid *drm_get_edid(struct drm_connector *connector,
struct i2c_adapter *adapter)
{
struct edid *edid;
+ struct pci_dev *pdev = connector->dev->pdev;
+ struct pci_dev *active_pdev = NULL;
+
+ mutex_lock(&drm_edid_mutex);
+
+ if (pdev) {
+ active_pdev = vga_switcheroo_get_active_client();
+ if (active_pdev != pdev)
+ vga_switcheroo_switch_ddc(pdev);
+ }
if (!drm_probe_ddc(adapter))
return NULL;
@@ -1384,6 +1397,11 @@ struct edid *drm_get_edid(struct drm_connector *connector,
edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
if (edid)
drm_get_displayid(connector, edid);
+
+ if (active_pdev && active_pdev != pdev)
+ vga_switcheroo_switch_ddc(active_pdev);
+
+ mutex_unlock(&drm_edid_mutex);
return edid;
}
EXPORT_SYMBOL(drm_get_edid);