vga_switcheroo.c 17.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (c) 2010 Red Hat Inc.
 * Author : Dave Airlie <airlied@redhat.com>
 *
 *
 * Licensed under GPLv2
 *
 * vga_switcheroo.c - Support for laptop with dual GPU using one set of outputs

 Switcher interface - methods require for ATPX and DCM
 - switchto - this throws the output MUX switch
 - discrete_set_power - sets the power state for the discrete card

 GPU driver interface
 - set_gpu_state - this should do the equiv of s/r for the card
		  - this should *not* set the discrete power state
 - switch_check  - check if the device is in a position to switch now
 */

#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/debugfs.h>
#include <linux/fb.h>

#include <linux/pci.h>
D
Dave Airlie 已提交
28
#include <linux/console.h>
29
#include <linux/vga_switcheroo.h>
30
#include <linux/pm_runtime.h>
31

32 33
#include <linux/vgaarb.h>

34 35 36 37
struct vga_switcheroo_client {
	struct pci_dev *pdev;
	struct fb_info *fb_info;
	int pwr_state;
38
	const struct vga_switcheroo_client_ops *ops;
39 40
	int id;
	bool active;
41
	bool driver_power_control;
42
	struct list_head list;
43 44 45 46 47 48 49 50 51 52 53 54 55 56
};

static DEFINE_MUTEX(vgasr_mutex);

struct vgasr_priv {

	bool active;
	bool delayed_switch_active;
	enum vga_switcheroo_client_id delayed_client_id;

	struct dentry *debugfs_root;
	struct dentry *switch_file;

	int registered_clients;
57
	struct list_head clients;
58 59 60 61

	struct vga_switcheroo_handler *handler;
};

62 63 64 65 66
#define ID_BIT_AUDIO		0x100
#define client_is_audio(c)	((c)->id & ID_BIT_AUDIO)
#define client_is_vga(c)	((c)->id == -1 || !client_is_audio(c))
#define client_id(c)		((c)->id & ~ID_BIT_AUDIO)

67 68 69 70
static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv);

/* only one switcheroo per system */
71 72 73
static struct vgasr_priv vgasr_priv = {
	.clients = LIST_HEAD_INIT(vgasr_priv.clients),
};
74

75
static bool vga_switcheroo_ready(void)
76
{
77 78 79
	/* we're ready if we get two clients + handler */
	return !vgasr_priv.active &&
	       vgasr_priv.registered_clients == 2 && vgasr_priv.handler;
80 81 82 83 84
}

static void vga_switcheroo_enable(void)
{
	int ret;
85 86
	struct vga_switcheroo_client *client;

87
	/* call the handler to init */
88 89
	if (vgasr_priv.handler->init)
		vgasr_priv.handler->init();
90

91
	list_for_each_entry(client, &vgasr_priv.clients, list) {
92 93
		if (client->id != -1)
			continue;
94
		ret = vgasr_priv.handler->get_client_id(client->pdev);
95 96 97
		if (ret < 0)
			return;

98
		client->id = ret;
99 100 101 102 103
	}
	vga_switcheroo_debugfs_init(&vgasr_priv);
	vgasr_priv.active = true;
}

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
{
	mutex_lock(&vgasr_mutex);
	if (vgasr_priv.handler) {
		mutex_unlock(&vgasr_mutex);
		return -EINVAL;
	}

	vgasr_priv.handler = handler;
	if (vga_switcheroo_ready()) {
		printk(KERN_INFO "vga_switcheroo: enabled\n");
		vga_switcheroo_enable();
	}
	mutex_unlock(&vgasr_mutex);
	return 0;
}
EXPORT_SYMBOL(vga_switcheroo_register_handler);

void vga_switcheroo_unregister_handler(void)
{
	mutex_lock(&vgasr_mutex);
	vgasr_priv.handler = NULL;
	if (vgasr_priv.active) {
		pr_info("vga_switcheroo: disabled\n");
		vga_switcheroo_debugfs_fini(&vgasr_priv);
		vgasr_priv.active = false;
	}
	mutex_unlock(&vgasr_mutex);
}
EXPORT_SYMBOL(vga_switcheroo_unregister_handler);

135 136
static int register_client(struct pci_dev *pdev,
			   const struct vga_switcheroo_client_ops *ops,
137
			   int id, bool active, bool driver_power_control)
138
{
139
	struct vga_switcheroo_client *client;
140

141 142 143 144 145 146
	client = kzalloc(sizeof(*client), GFP_KERNEL);
	if (!client)
		return -ENOMEM;

	client->pwr_state = VGA_SWITCHEROO_ON;
	client->pdev = pdev;
147
	client->ops = ops;
148 149
	client->id = id;
	client->active = active;
150
	client->driver_power_control = driver_power_control;
151

152 153
	mutex_lock(&vgasr_mutex);
	list_add_tail(&client->list, &vgasr_priv.clients);
154 155
	if (client_is_vga(client))
		vgasr_priv.registered_clients++;
156

157
	if (vga_switcheroo_ready()) {
158 159 160 161 162 163
		printk(KERN_INFO "vga_switcheroo: enabled\n");
		vga_switcheroo_enable();
	}
	mutex_unlock(&vgasr_mutex);
	return 0;
}
164 165

int vga_switcheroo_register_client(struct pci_dev *pdev,
166 167
				   const struct vga_switcheroo_client_ops *ops,
				   bool driver_power_control)
168 169
{
	return register_client(pdev, ops, -1,
170
			       pdev == vga_default_device(), driver_power_control);
171
}
172 173
EXPORT_SYMBOL(vga_switcheroo_register_client);

174 175 176 177
int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
					 const struct vga_switcheroo_client_ops *ops,
					 int id, bool active)
{
178
	return register_client(pdev, ops, id | ID_BIT_AUDIO, active, false);
179 180 181
}
EXPORT_SYMBOL(vga_switcheroo_register_audio_client);

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
static struct vga_switcheroo_client *
find_client_from_pci(struct list_head *head, struct pci_dev *pdev)
{
	struct vga_switcheroo_client *client;
	list_for_each_entry(client, head, list)
		if (client->pdev == pdev)
			return client;
	return NULL;
}

static struct vga_switcheroo_client *
find_client_from_id(struct list_head *head, int client_id)
{
	struct vga_switcheroo_client *client;
	list_for_each_entry(client, head, list)
		if (client->id == client_id)
			return client;
	return NULL;
}

static struct vga_switcheroo_client *
find_active_client(struct list_head *head)
{
	struct vga_switcheroo_client *client;
	list_for_each_entry(client, head, list)
207
		if (client->active && client_is_vga(client))
208 209 210 211
			return client;
	return NULL;
}

212 213 214 215 216 217 218 219 220 221 222 223 224
int vga_switcheroo_get_client_state(struct pci_dev *pdev)
{
	struct vga_switcheroo_client *client;

	client = find_client_from_pci(&vgasr_priv.clients, pdev);
	if (!client)
		return VGA_SWITCHEROO_NOT_FOUND;
	if (!vgasr_priv.active)
		return VGA_SWITCHEROO_INIT;
	return client->pwr_state;
}
EXPORT_SYMBOL(vga_switcheroo_get_client_state);

225 226
void vga_switcheroo_unregister_client(struct pci_dev *pdev)
{
227
	struct vga_switcheroo_client *client;
228 229

	mutex_lock(&vgasr_mutex);
230 231
	client = find_client_from_pci(&vgasr_priv.clients, pdev);
	if (client) {
232 233
		if (client_is_vga(client))
			vgasr_priv.registered_clients--;
234 235
		list_del(&client->list);
		kfree(client);
236
	}
237 238 239 240 241
	if (vgasr_priv.active && vgasr_priv.registered_clients < 2) {
		printk(KERN_INFO "vga_switcheroo: disabled\n");
		vga_switcheroo_debugfs_fini(&vgasr_priv);
		vgasr_priv.active = false;
	}
242 243 244 245 246 247 248
	mutex_unlock(&vgasr_mutex);
}
EXPORT_SYMBOL(vga_switcheroo_unregister_client);

void vga_switcheroo_client_fb_set(struct pci_dev *pdev,
				 struct fb_info *info)
{
249
	struct vga_switcheroo_client *client;
250 251

	mutex_lock(&vgasr_mutex);
252 253 254
	client = find_client_from_pci(&vgasr_priv.clients, pdev);
	if (client)
		client->fb_info = info;
255 256 257 258 259 260
	mutex_unlock(&vgasr_mutex);
}
EXPORT_SYMBOL(vga_switcheroo_client_fb_set);

static int vga_switcheroo_show(struct seq_file *m, void *v)
{
261 262
	struct vga_switcheroo_client *client;
	int i = 0;
263
	mutex_lock(&vgasr_mutex);
264
	list_for_each_entry(client, &vgasr_priv.clients, list) {
265
		seq_printf(m, "%d:%s%s:%c:%s%s:%s\n", i,
266 267
			   client_id(client) == VGA_SWITCHEROO_DIS ? "DIS" : "IGD",
			   client_is_vga(client) ? "" : "-Audio",
268
			   client->active ? '+' : ' ',
269
			   client->driver_power_control ? "Dyn" : "",
270 271 272
			   client->pwr_state ? "Pwr" : "Off",
			   pci_name(client->pdev));
		i++;
273 274 275 276 277 278 279 280 281 282 283 284
	}
	mutex_unlock(&vgasr_mutex);
	return 0;
}

static int vga_switcheroo_debugfs_open(struct inode *inode, struct file *file)
{
	return single_open(file, vga_switcheroo_show, NULL);
}

static int vga_switchon(struct vga_switcheroo_client *client)
{
285 286
	if (client->driver_power_control)
		return 0;
287 288
	if (vgasr_priv.handler->power_state)
		vgasr_priv.handler->power_state(client->id, VGA_SWITCHEROO_ON);
289
	/* call the driver callback to turn on device */
290
	client->ops->set_gpu_state(client->pdev, VGA_SWITCHEROO_ON);
291 292 293 294 295 296
	client->pwr_state = VGA_SWITCHEROO_ON;
	return 0;
}

static int vga_switchoff(struct vga_switcheroo_client *client)
{
297 298
	if (client->driver_power_control)
		return 0;
299
	/* call the driver callback to turn off device */
300
	client->ops->set_gpu_state(client->pdev, VGA_SWITCHEROO_OFF);
301 302
	if (vgasr_priv.handler->power_state)
		vgasr_priv.handler->power_state(client->id, VGA_SWITCHEROO_OFF);
303 304 305 306
	client->pwr_state = VGA_SWITCHEROO_OFF;
	return 0;
}

307 308 309 310 311 312 313 314 315 316 317
static void set_audio_state(int id, int state)
{
	struct vga_switcheroo_client *client;

	client = find_client_from_id(&vgasr_priv.clients, id | ID_BIT_AUDIO);
	if (client && client->pwr_state != state) {
		client->ops->set_gpu_state(client->pdev, state);
		client->pwr_state = state;
	}
}

318 319
/* stage one happens before delay */
static int vga_switchto_stage1(struct vga_switcheroo_client *new_client)
320
{
321
	struct vga_switcheroo_client *active;
322

323
	active = find_active_client(&vgasr_priv.clients);
324 325 326 327 328 329
	if (!active)
		return 0;

	if (new_client->pwr_state == VGA_SWITCHEROO_OFF)
		vga_switchon(new_client);

330
	vga_set_default_device(new_client->pdev);
331 332 333 334 335 336 337
	return 0;
}

/* post delay */
static int vga_switchto_stage2(struct vga_switcheroo_client *new_client)
{
	int ret;
338
	struct vga_switcheroo_client *active;
339

340
	active = find_active_client(&vgasr_priv.clients);
341 342 343 344
	if (!active)
		return 0;

	active->active = false;
345

346 347
	set_audio_state(active->id, VGA_SWITCHEROO_OFF);

348 349
	if (new_client->fb_info) {
		struct fb_event event;
D
Dave Airlie 已提交
350
		console_lock();
351 352
		event.info = new_client->fb_info;
		fb_notifier_call_chain(FB_EVENT_REMAP_ALL_CONSOLE, &event);
D
Dave Airlie 已提交
353
		console_unlock();
354 355 356 357 358 359
	}

	ret = vgasr_priv.handler->switchto(new_client->id);
	if (ret)
		return ret;

360 361
	if (new_client->ops->reprobe)
		new_client->ops->reprobe(new_client->pdev);
362

363 364 365
	if (active->pwr_state == VGA_SWITCHEROO_ON)
		vga_switchoff(active);

366 367
	set_audio_state(new_client->id, VGA_SWITCHEROO_ON);

368 369 370 371
	new_client->active = true;
	return 0;
}

372 373 374 375 376
static bool check_can_switch(void)
{
	struct vga_switcheroo_client *client;

	list_for_each_entry(client, &vgasr_priv.clients, list) {
377
		if (!client->ops->can_switch(client->pdev)) {
378 379 380 381 382 383 384
			printk(KERN_ERR "vga_switcheroo: client %x refused switch\n", client->id);
			return false;
		}
	}
	return true;
}

385 386 387 388 389
static ssize_t
vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
			     size_t cnt, loff_t *ppos)
{
	char usercmd[64];
390
	int ret;
391
	bool delay = false, can_switch;
392
	bool just_mux = false;
393 394 395 396 397 398 399 400 401 402 403
	int client_id = -1;
	struct vga_switcheroo_client *client = NULL;

	if (cnt > 63)
		cnt = 63;

	if (copy_from_user(usercmd, ubuf, cnt))
		return -EFAULT;

	mutex_lock(&vgasr_mutex);

404 405 406 407
	if (!vgasr_priv.active) {
		cnt = -EINVAL;
		goto out;
	}
408 409 410

	/* pwr off the device not in use */
	if (strncmp(usercmd, "OFF", 3) == 0) {
411
		list_for_each_entry(client, &vgasr_priv.clients, list) {
412
			if (client->active || client_is_audio(client))
413
				continue;
414 415
			if (client->driver_power_control)
				continue;
416
			set_audio_state(client->id, VGA_SWITCHEROO_OFF);
417 418
			if (client->pwr_state == VGA_SWITCHEROO_ON)
				vga_switchoff(client);
419 420 421 422 423
		}
		goto out;
	}
	/* pwr on the device not in use */
	if (strncmp(usercmd, "ON", 2) == 0) {
424
		list_for_each_entry(client, &vgasr_priv.clients, list) {
425
			if (client->active || client_is_audio(client))
426
				continue;
427 428
			if (client->driver_power_control)
				continue;
429 430
			if (client->pwr_state == VGA_SWITCHEROO_OFF)
				vga_switchon(client);
431
			set_audio_state(client->id, VGA_SWITCHEROO_ON);
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
		}
		goto out;
	}

	/* request a delayed switch - test can we switch now */
	if (strncmp(usercmd, "DIGD", 4) == 0) {
		client_id = VGA_SWITCHEROO_IGD;
		delay = true;
	}

	if (strncmp(usercmd, "DDIS", 4) == 0) {
		client_id = VGA_SWITCHEROO_DIS;
		delay = true;
	}

	if (strncmp(usercmd, "IGD", 3) == 0)
		client_id = VGA_SWITCHEROO_IGD;

	if (strncmp(usercmd, "DIS", 3) == 0)
		client_id = VGA_SWITCHEROO_DIS;

453
	if (strncmp(usercmd, "MIGD", 4) == 0) {
454 455 456
		just_mux = true;
		client_id = VGA_SWITCHEROO_IGD;
	}
457
	if (strncmp(usercmd, "MDIS", 4) == 0) {
458 459 460 461
		just_mux = true;
		client_id = VGA_SWITCHEROO_DIS;
	}

462 463
	if (client_id == -1)
		goto out;
464 465 466
	client = find_client_from_id(&vgasr_priv.clients, client_id);
	if (!client)
		goto out;
467 468

	vgasr_priv.delayed_switch_active = false;
469 470 471 472 473 474

	if (just_mux) {
		ret = vgasr_priv.handler->switchto(client_id);
		goto out;
	}

475
	if (client->active)
476 477
		goto out;

478
	/* okay we want a switch - test if devices are willing to switch */
479
	can_switch = check_can_switch();
480 481 482 483

	if (can_switch == false && delay == false)
		goto out;

484
	if (can_switch) {
485 486 487 488 489
		ret = vga_switchto_stage1(client);
		if (ret)
			printk(KERN_ERR "vga_switcheroo: switching failed stage 1 %d\n", ret);

		ret = vga_switchto_stage2(client);
490
		if (ret)
491 492
			printk(KERN_ERR "vga_switcheroo: switching failed stage 2 %d\n", ret);

493 494 495 496 497
	} else {
		printk(KERN_INFO "vga_switcheroo: setting delayed switch to client %d\n", client->id);
		vgasr_priv.delayed_switch_active = true;
		vgasr_priv.delayed_client_id = client_id;

498 499 500
		ret = vga_switchto_stage1(client);
		if (ret)
			printk(KERN_ERR "vga_switcheroo: delayed switching stage 1 failed %d\n", ret);
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
	}

out:
	mutex_unlock(&vgasr_mutex);
	return cnt;
}

static const struct file_operations vga_switcheroo_debugfs_fops = {
	.owner = THIS_MODULE,
	.open = vga_switcheroo_debugfs_open,
	.write = vga_switcheroo_debugfs_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
{
	if (priv->switch_file) {
		debugfs_remove(priv->switch_file);
		priv->switch_file = NULL;
	}
	if (priv->debugfs_root) {
		debugfs_remove(priv->debugfs_root);
		priv->debugfs_root = NULL;
	}
}

static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
{
	/* already initialised */
	if (priv->debugfs_root)
		return 0;
	priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);

	if (!priv->debugfs_root) {
		printk(KERN_ERR "vga_switcheroo: Cannot create /sys/kernel/debug/vgaswitcheroo\n");
		goto fail;
	}

	priv->switch_file = debugfs_create_file("switch", 0644,
						priv->debugfs_root, NULL, &vga_switcheroo_debugfs_fops);
	if (!priv->switch_file) {
		printk(KERN_ERR "vga_switcheroo: cannot create /sys/kernel/debug/vgaswitcheroo/switch\n");
		goto fail;
	}
	return 0;
fail:
	vga_switcheroo_debugfs_fini(priv);
	return -1;
}

int vga_switcheroo_process_delayed_switch(void)
{
555
	struct vga_switcheroo_client *client;
556 557 558 559 560 561 562 563 564
	int ret;
	int err = -EINVAL;

	mutex_lock(&vgasr_mutex);
	if (!vgasr_priv.delayed_switch_active)
		goto err;

	printk(KERN_INFO "vga_switcheroo: processing delayed switch to %d\n", vgasr_priv.delayed_client_id);

565 566 567
	client = find_client_from_id(&vgasr_priv.clients,
				     vgasr_priv.delayed_client_id);
	if (!client || !check_can_switch())
568 569
		goto err;

570
	ret = vga_switchto_stage2(client);
571
	if (ret)
572
		printk(KERN_ERR "vga_switcheroo: delayed switching failed stage 2 %d\n", ret);
573 574 575 576 577 578 579 580

	vgasr_priv.delayed_switch_active = false;
	err = 0;
err:
	mutex_unlock(&vgasr_mutex);
	return err;
}
EXPORT_SYMBOL(vga_switcheroo_process_delayed_switch);
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625

static void vga_switcheroo_power_switch(struct pci_dev *pdev, enum vga_switcheroo_state state)
{
	struct vga_switcheroo_client *client;

	if (!vgasr_priv.handler->power_state)
		return;

	client = find_client_from_pci(&vgasr_priv.clients, pdev);
	if (!client)
		return;

	if (!client->driver_power_control)
		return;

	vgasr_priv.handler->power_state(client->id, state);
}

/* force a PCI device to a certain state - mainly to turn off audio clients */

void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic)
{
	struct vga_switcheroo_client *client;

	client = find_client_from_pci(&vgasr_priv.clients, pdev);
	if (!client)
		return;

	if (!client->driver_power_control)
		return;

	client->pwr_state = dynamic;
	set_audio_state(client->id, dynamic);
}
EXPORT_SYMBOL(vga_switcheroo_set_dynamic_switch);

/* switcheroo power domain */
static int vga_switcheroo_runtime_suspend(struct device *dev)
{
	struct pci_dev *pdev = to_pci_dev(dev);
	int ret;

	ret = dev->bus->pm->runtime_suspend(dev);
	if (ret)
		return ret;
626 627
	if (vgasr_priv.handler->switchto)
		vgasr_priv.handler->switchto(VGA_SWITCHEROO_IGD);
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
	vga_switcheroo_power_switch(pdev, VGA_SWITCHEROO_OFF);
	return 0;
}

static int vga_switcheroo_runtime_resume(struct device *dev)
{
	struct pci_dev *pdev = to_pci_dev(dev);
	int ret;

	vga_switcheroo_power_switch(pdev, VGA_SWITCHEROO_ON);
	ret = dev->bus->pm->runtime_resume(dev);
	if (ret)
		return ret;

	return 0;
}

/* this version is for the case where the power switch is separate
   to the device being powered down. */
int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
{
	/* copy over all the bus versions */
	if (dev->bus && dev->bus->pm) {
		domain->ops = *dev->bus->pm;
		domain->ops.runtime_suspend = vga_switcheroo_runtime_suspend;
		domain->ops.runtime_resume = vga_switcheroo_runtime_resume;

		dev->pm_domain = domain;
		return 0;
	}
	dev->pm_domain = NULL;
	return -EINVAL;
}
EXPORT_SYMBOL(vga_switcheroo_init_domain_pm_ops);

static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
{
	struct pci_dev *pdev = to_pci_dev(dev);
	int ret;
	struct vga_switcheroo_client *client, *found = NULL;

	/* we need to check if we have to switch back on the video
	   device so the audio device can come back */
	list_for_each_entry(client, &vgasr_priv.clients, list) {
		if (PCI_SLOT(client->pdev->devfn) == PCI_SLOT(pdev->devfn) && client_is_vga(client)) {
			found = client;
			ret = pm_runtime_get_sync(&client->pdev->dev);
			if (ret) {
				if (ret != 1)
					return ret;
			}
			break;
		}
	}
	ret = dev->bus->pm->runtime_resume(dev);

	/* put the reference for the gpu */
	if (found) {
		pm_runtime_mark_last_busy(&found->pdev->dev);
		pm_runtime_put_autosuspend(&found->pdev->dev);
	}
	return ret;
}

int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
{
	/* copy over all the bus versions */
	if (dev->bus && dev->bus->pm) {
		domain->ops = *dev->bus->pm;
		domain->ops.runtime_resume = vga_switcheroo_runtime_resume_hdmi_audio;

		dev->pm_domain = domain;
		return 0;
	}
	dev->pm_domain = NULL;
	return -EINVAL;
}
EXPORT_SYMBOL(vga_switcheroo_init_domain_pm_optimus_hdmi_audio);