@@ -18,6 +18,8 @@
- can_switch - check if the device is in a position to switch now
*/
+#include <drm/drm_crtc_helper.h>
+
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
@@ -35,6 +37,7 @@
struct vga_switcheroo_client {
struct pci_dev *pdev;
struct fb_info *fb_info;
+ struct work_struct reprobe_work;
int pwr_state;
const struct vga_switcheroo_client_ops *ops;
int id;
@@ -106,6 +109,30 @@ static void vga_switcheroo_enable(void)
vgasr_priv.active = true;
}
+static void vga_switcheroo_reprobe_client(struct work_struct *work)
+{
+ struct vga_switcheroo_client *client =
+ container_of(work, struct vga_switcheroo_client, reprobe_work);
+ void (*generate_hotplug_event)(struct drm_device *);
+
+ generate_hotplug_event = symbol_get(drm_kms_helper_hotplug_event);
+ if (!generate_hotplug_event)
+ return;
+
+ generate_hotplug_event(pci_get_drvdata(client->pdev));
+}
+
+static void vga_switcheroo_reprobe_inactive_clients(void)
+{
+ struct vga_switcheroo_client *client;
+
+ list_for_each_entry(client, &vgasr_priv.clients, list)
+ if (!client->active && client_is_vga(client)) {
+ cancel_work_sync(&client->reprobe_work);
+ schedule_work(&client->reprobe_work);
+ }
+}
+
int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
{
mutex_lock(&vgasr_mutex);
@@ -115,11 +142,17 @@ int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
}
vgasr_priv.handler = handler;
+
if (vga_switcheroo_ready()) {
printk(KERN_INFO "vga_switcheroo: enabled\n");
vga_switcheroo_enable();
}
mutex_unlock(&vgasr_mutex);
+
+ /* clients which registered before the handler must reprobe */
+ if (vgasr_priv.handler->switch_ddc)
+ vga_switcheroo_reprobe_inactive_clients();
+
return 0;
}
EXPORT_SYMBOL(vga_switcheroo_register_handler);
@@ -153,6 +186,7 @@ static int register_client(struct pci_dev *pdev,
client->id = id;
client->active = active;
client->driver_power_control = driver_power_control;
+ INIT_WORK(&client->reprobe_work, vga_switcheroo_reprobe_client);
mutex_lock(&vgasr_mutex);
list_add_tail(&client->list, &vgasr_priv.clients);