diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-25 11:38:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-25 11:38:26 -0400 |
commit | 58823de9d2f1265030d0d06cb03cc2a551994398 (patch) | |
tree | 6b4f3e681f467e99758de61d6dd0c45a39e7d133 /sound | |
parent | 4b7eba49c5912cbd7c70bbebec38d8cd54c2ef85 (diff) | |
parent | 6091106297933c5cf0e4470df9a5f4e703674391 (diff) |
Merge tag 'hda-switcheroo' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull VGA-switcheroo audio client support for HD-audio from Takashi Iwai.
This depended on the recent drm pull.
* tag 'hda-switcheroo' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound:
ALSA: hda - unlock on error in azx_interrupt()
ALSA: hda - Support VGA-switcheroo
ALSA: hda - Export snd_hda_lock_devices()
ALSA: hda - Check the dead HDMI audio controller by vga-switcheroo
Diffstat (limited to 'sound')
-rw-r--r-- | sound/pci/hda/hda_codec.c | 66 | ||||
-rw-r--r-- | sound/pci/hda/hda_codec.h | 3 | ||||
-rw-r--r-- | sound/pci/hda/hda_intel.c | 314 |
3 files changed, 316 insertions, 67 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index eb09a3348325..41ca803a1fff 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -2239,24 +2239,50 @@ void snd_hda_ctls_clear(struct hda_codec *codec) | |||
2239 | /* pseudo device locking | 2239 | /* pseudo device locking |
2240 | * toggle card->shutdown to allow/disallow the device access (as a hack) | 2240 | * toggle card->shutdown to allow/disallow the device access (as a hack) |
2241 | */ | 2241 | */ |
2242 | static int hda_lock_devices(struct snd_card *card) | 2242 | int snd_hda_lock_devices(struct hda_bus *bus) |
2243 | { | 2243 | { |
2244 | struct snd_card *card = bus->card; | ||
2245 | struct hda_codec *codec; | ||
2246 | |||
2244 | spin_lock(&card->files_lock); | 2247 | spin_lock(&card->files_lock); |
2245 | if (card->shutdown) { | 2248 | if (card->shutdown) |
2246 | spin_unlock(&card->files_lock); | 2249 | goto err_unlock; |
2247 | return -EINVAL; | ||
2248 | } | ||
2249 | card->shutdown = 1; | 2250 | card->shutdown = 1; |
2251 | if (!list_empty(&card->ctl_files)) | ||
2252 | goto err_clear; | ||
2253 | |||
2254 | list_for_each_entry(codec, &bus->codec_list, list) { | ||
2255 | int pcm; | ||
2256 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { | ||
2257 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; | ||
2258 | if (!cpcm->pcm) | ||
2259 | continue; | ||
2260 | if (cpcm->pcm->streams[0].substream_opened || | ||
2261 | cpcm->pcm->streams[1].substream_opened) | ||
2262 | goto err_clear; | ||
2263 | } | ||
2264 | } | ||
2250 | spin_unlock(&card->files_lock); | 2265 | spin_unlock(&card->files_lock); |
2251 | return 0; | 2266 | return 0; |
2267 | |||
2268 | err_clear: | ||
2269 | card->shutdown = 0; | ||
2270 | err_unlock: | ||
2271 | spin_unlock(&card->files_lock); | ||
2272 | return -EINVAL; | ||
2252 | } | 2273 | } |
2274 | EXPORT_SYMBOL_HDA(snd_hda_lock_devices); | ||
2253 | 2275 | ||
2254 | static void hda_unlock_devices(struct snd_card *card) | 2276 | void snd_hda_unlock_devices(struct hda_bus *bus) |
2255 | { | 2277 | { |
2278 | struct snd_card *card = bus->card; | ||
2279 | |||
2280 | card = bus->card; | ||
2256 | spin_lock(&card->files_lock); | 2281 | spin_lock(&card->files_lock); |
2257 | card->shutdown = 0; | 2282 | card->shutdown = 0; |
2258 | spin_unlock(&card->files_lock); | 2283 | spin_unlock(&card->files_lock); |
2259 | } | 2284 | } |
2285 | EXPORT_SYMBOL_HDA(snd_hda_unlock_devices); | ||
2260 | 2286 | ||
2261 | /** | 2287 | /** |
2262 | * snd_hda_codec_reset - Clear all objects assigned to the codec | 2288 | * snd_hda_codec_reset - Clear all objects assigned to the codec |
@@ -2270,26 +2296,12 @@ static void hda_unlock_devices(struct snd_card *card) | |||
2270 | */ | 2296 | */ |
2271 | int snd_hda_codec_reset(struct hda_codec *codec) | 2297 | int snd_hda_codec_reset(struct hda_codec *codec) |
2272 | { | 2298 | { |
2273 | struct snd_card *card = codec->bus->card; | 2299 | struct hda_bus *bus = codec->bus; |
2274 | int i, pcm; | 2300 | struct snd_card *card = bus->card; |
2301 | int i; | ||
2275 | 2302 | ||
2276 | if (hda_lock_devices(card) < 0) | 2303 | if (snd_hda_lock_devices(bus) < 0) |
2277 | return -EBUSY; | ||
2278 | /* check whether the codec isn't used by any mixer or PCM streams */ | ||
2279 | if (!list_empty(&card->ctl_files)) { | ||
2280 | hda_unlock_devices(card); | ||
2281 | return -EBUSY; | 2304 | return -EBUSY; |
2282 | } | ||
2283 | for (pcm = 0; pcm < codec->num_pcms; pcm++) { | ||
2284 | struct hda_pcm *cpcm = &codec->pcm_info[pcm]; | ||
2285 | if (!cpcm->pcm) | ||
2286 | continue; | ||
2287 | if (cpcm->pcm->streams[0].substream_opened || | ||
2288 | cpcm->pcm->streams[1].substream_opened) { | ||
2289 | hda_unlock_devices(card); | ||
2290 | return -EBUSY; | ||
2291 | } | ||
2292 | } | ||
2293 | 2305 | ||
2294 | /* OK, let it free */ | 2306 | /* OK, let it free */ |
2295 | 2307 | ||
@@ -2298,7 +2310,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) | |||
2298 | codec->power_on = 0; | 2310 | codec->power_on = 0; |
2299 | codec->power_transition = 0; | 2311 | codec->power_transition = 0; |
2300 | codec->power_jiffies = jiffies; | 2312 | codec->power_jiffies = jiffies; |
2301 | flush_workqueue(codec->bus->workq); | 2313 | flush_workqueue(bus->workq); |
2302 | #endif | 2314 | #endif |
2303 | snd_hda_ctls_clear(codec); | 2315 | snd_hda_ctls_clear(codec); |
2304 | /* relase PCMs */ | 2316 | /* relase PCMs */ |
@@ -2306,7 +2318,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) | |||
2306 | if (codec->pcm_info[i].pcm) { | 2318 | if (codec->pcm_info[i].pcm) { |
2307 | snd_device_free(card, codec->pcm_info[i].pcm); | 2319 | snd_device_free(card, codec->pcm_info[i].pcm); |
2308 | clear_bit(codec->pcm_info[i].device, | 2320 | clear_bit(codec->pcm_info[i].device, |
2309 | codec->bus->pcm_dev_bits); | 2321 | bus->pcm_dev_bits); |
2310 | } | 2322 | } |
2311 | } | 2323 | } |
2312 | if (codec->patch_ops.free) | 2324 | if (codec->patch_ops.free) |
@@ -2331,7 +2343,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) | |||
2331 | codec->owner = NULL; | 2343 | codec->owner = NULL; |
2332 | 2344 | ||
2333 | /* allow device access again */ | 2345 | /* allow device access again */ |
2334 | hda_unlock_devices(card); | 2346 | snd_hda_unlock_devices(bus); |
2335 | return 0; | 2347 | return 0; |
2336 | } | 2348 | } |
2337 | 2349 | ||
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 54b52819fb47..4fc3960c8591 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h | |||
@@ -1023,6 +1023,9 @@ void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg, | |||
1023 | unsigned int power_state, | 1023 | unsigned int power_state, |
1024 | bool eapd_workaround); | 1024 | bool eapd_workaround); |
1025 | 1025 | ||
1026 | int snd_hda_lock_devices(struct hda_bus *bus); | ||
1027 | void snd_hda_unlock_devices(struct hda_bus *bus); | ||
1028 | |||
1026 | /* | 1029 | /* |
1027 | * power management | 1030 | * power management |
1028 | */ | 1031 | */ |
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 4ab8102f87ea..2b6392be451c 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -53,6 +53,8 @@ | |||
53 | #endif | 53 | #endif |
54 | #include <sound/core.h> | 54 | #include <sound/core.h> |
55 | #include <sound/initval.h> | 55 | #include <sound/initval.h> |
56 | #include <linux/vgaarb.h> | ||
57 | #include <linux/vga_switcheroo.h> | ||
56 | #include "hda_codec.h" | 58 | #include "hda_codec.h" |
57 | 59 | ||
58 | 60 | ||
@@ -175,6 +177,13 @@ MODULE_DESCRIPTION("Intel HDA driver"); | |||
175 | #define SFX "hda-intel: " | 177 | #define SFX "hda-intel: " |
176 | #endif | 178 | #endif |
177 | 179 | ||
180 | #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO) | ||
181 | #ifdef CONFIG_SND_HDA_CODEC_HDMI | ||
182 | #define SUPPORT_VGA_SWITCHEROO | ||
183 | #endif | ||
184 | #endif | ||
185 | |||
186 | |||
178 | /* | 187 | /* |
179 | * registers | 188 | * registers |
180 | */ | 189 | */ |
@@ -472,6 +481,12 @@ struct azx { | |||
472 | unsigned int probing :1; /* codec probing phase */ | 481 | unsigned int probing :1; /* codec probing phase */ |
473 | unsigned int snoop:1; | 482 | unsigned int snoop:1; |
474 | unsigned int align_buffer_size:1; | 483 | unsigned int align_buffer_size:1; |
484 | unsigned int region_requested:1; | ||
485 | |||
486 | /* VGA-switcheroo setup */ | ||
487 | unsigned int use_vga_switcheroo:1; | ||
488 | unsigned int init_failed:1; /* delayed init failed */ | ||
489 | unsigned int disabled:1; /* disabled by VGA-switcher */ | ||
475 | 490 | ||
476 | /* for debugging */ | 491 | /* for debugging */ |
477 | unsigned int last_cmd[AZX_MAX_CODECS]; | 492 | unsigned int last_cmd[AZX_MAX_CODECS]; |
@@ -538,7 +553,20 @@ enum { | |||
538 | #define AZX_DCAPS_PRESET_CTHDA \ | 553 | #define AZX_DCAPS_PRESET_CTHDA \ |
539 | (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) | 554 | (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) |
540 | 555 | ||
541 | static char *driver_short_names[] __devinitdata = { | 556 | /* |
557 | * VGA-switcher support | ||
558 | */ | ||
559 | #ifdef SUPPORT_VGA_SWITCHEROO | ||
560 | #define DELAYED_INIT_MARK | ||
561 | #define DELAYED_INITDATA_MARK | ||
562 | #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo) | ||
563 | #else | ||
564 | #define DELAYED_INIT_MARK __devinit | ||
565 | #define DELAYED_INITDATA_MARK __devinitdata | ||
566 | #define use_vga_switcheroo(chip) 0 | ||
567 | #endif | ||
568 | |||
569 | static char *driver_short_names[] DELAYED_INITDATA_MARK = { | ||
542 | [AZX_DRIVER_ICH] = "HDA Intel", | 570 | [AZX_DRIVER_ICH] = "HDA Intel", |
543 | [AZX_DRIVER_PCH] = "HDA Intel PCH", | 571 | [AZX_DRIVER_PCH] = "HDA Intel PCH", |
544 | [AZX_DRIVER_SCH] = "HDA Intel MID", | 572 | [AZX_DRIVER_SCH] = "HDA Intel MID", |
@@ -959,6 +987,8 @@ static int azx_send_cmd(struct hda_bus *bus, unsigned int val) | |||
959 | { | 987 | { |
960 | struct azx *chip = bus->private_data; | 988 | struct azx *chip = bus->private_data; |
961 | 989 | ||
990 | if (chip->disabled) | ||
991 | return 0; | ||
962 | chip->last_cmd[azx_command_addr(val)] = val; | 992 | chip->last_cmd[azx_command_addr(val)] = val; |
963 | if (chip->single_cmd) | 993 | if (chip->single_cmd) |
964 | return azx_single_send_cmd(bus, val); | 994 | return azx_single_send_cmd(bus, val); |
@@ -971,6 +1001,8 @@ static unsigned int azx_get_response(struct hda_bus *bus, | |||
971 | unsigned int addr) | 1001 | unsigned int addr) |
972 | { | 1002 | { |
973 | struct azx *chip = bus->private_data; | 1003 | struct azx *chip = bus->private_data; |
1004 | if (chip->disabled) | ||
1005 | return 0; | ||
974 | if (chip->single_cmd) | 1006 | if (chip->single_cmd) |
975 | return azx_single_get_response(bus, addr); | 1007 | return azx_single_get_response(bus, addr); |
976 | else | 1008 | else |
@@ -1236,6 +1268,11 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id) | |||
1236 | 1268 | ||
1237 | spin_lock(&chip->reg_lock); | 1269 | spin_lock(&chip->reg_lock); |
1238 | 1270 | ||
1271 | if (chip->disabled) { | ||
1272 | spin_unlock(&chip->reg_lock); | ||
1273 | return IRQ_NONE; | ||
1274 | } | ||
1275 | |||
1239 | status = azx_readl(chip, INTSTS); | 1276 | status = azx_readl(chip, INTSTS); |
1240 | if (status == 0) { | 1277 | if (status == 0) { |
1241 | spin_unlock(&chip->reg_lock); | 1278 | spin_unlock(&chip->reg_lock); |
@@ -1521,12 +1558,12 @@ static void azx_bus_reset(struct hda_bus *bus) | |||
1521 | */ | 1558 | */ |
1522 | 1559 | ||
1523 | /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ | 1560 | /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ |
1524 | static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = { | 1561 | static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] DELAYED_INITDATA_MARK = { |
1525 | [AZX_DRIVER_NVIDIA] = 8, | 1562 | [AZX_DRIVER_NVIDIA] = 8, |
1526 | [AZX_DRIVER_TERA] = 1, | 1563 | [AZX_DRIVER_TERA] = 1, |
1527 | }; | 1564 | }; |
1528 | 1565 | ||
1529 | static int __devinit azx_codec_create(struct azx *chip, const char *model) | 1566 | static int DELAYED_INIT_MARK azx_codec_create(struct azx *chip, const char *model) |
1530 | { | 1567 | { |
1531 | struct hda_bus_template bus_temp; | 1568 | struct hda_bus_template bus_temp; |
1532 | int c, codecs, err; | 1569 | int c, codecs, err; |
@@ -2444,6 +2481,105 @@ static void azx_notifier_unregister(struct azx *chip) | |||
2444 | unregister_reboot_notifier(&chip->reboot_notifier); | 2481 | unregister_reboot_notifier(&chip->reboot_notifier); |
2445 | } | 2482 | } |
2446 | 2483 | ||
2484 | static int DELAYED_INIT_MARK azx_first_init(struct azx *chip); | ||
2485 | static int DELAYED_INIT_MARK azx_probe_continue(struct azx *chip); | ||
2486 | |||
2487 | static struct pci_dev __devinit *get_bound_vga(struct pci_dev *pci); | ||
2488 | |||
2489 | #ifdef SUPPORT_VGA_SWITCHEROO | ||
2490 | static void azx_vs_set_state(struct pci_dev *pci, | ||
2491 | enum vga_switcheroo_state state) | ||
2492 | { | ||
2493 | struct snd_card *card = pci_get_drvdata(pci); | ||
2494 | struct azx *chip = card->private_data; | ||
2495 | bool disabled; | ||
2496 | |||
2497 | if (chip->init_failed) | ||
2498 | return; | ||
2499 | |||
2500 | disabled = (state == VGA_SWITCHEROO_OFF); | ||
2501 | if (chip->disabled == disabled) | ||
2502 | return; | ||
2503 | |||
2504 | if (!chip->bus) { | ||
2505 | chip->disabled = disabled; | ||
2506 | if (!disabled) { | ||
2507 | snd_printk(KERN_INFO SFX | ||
2508 | "%s: Start delayed initialization\n", | ||
2509 | pci_name(chip->pci)); | ||
2510 | if (azx_first_init(chip) < 0 || | ||
2511 | azx_probe_continue(chip) < 0) { | ||
2512 | snd_printk(KERN_ERR SFX | ||
2513 | "%s: initialization error\n", | ||
2514 | pci_name(chip->pci)); | ||
2515 | chip->init_failed = true; | ||
2516 | } | ||
2517 | } | ||
2518 | } else { | ||
2519 | snd_printk(KERN_INFO SFX | ||
2520 | "%s %s via VGA-switcheroo\n", | ||
2521 | disabled ? "Disabling" : "Enabling", | ||
2522 | pci_name(chip->pci)); | ||
2523 | if (disabled) { | ||
2524 | azx_suspend(pci, PMSG_FREEZE); | ||
2525 | chip->disabled = true; | ||
2526 | snd_hda_lock_devices(chip->bus); | ||
2527 | } else { | ||
2528 | snd_hda_unlock_devices(chip->bus); | ||
2529 | chip->disabled = false; | ||
2530 | azx_resume(pci); | ||
2531 | } | ||
2532 | } | ||
2533 | } | ||
2534 | |||
2535 | static bool azx_vs_can_switch(struct pci_dev *pci) | ||
2536 | { | ||
2537 | struct snd_card *card = pci_get_drvdata(pci); | ||
2538 | struct azx *chip = card->private_data; | ||
2539 | |||
2540 | if (chip->init_failed) | ||
2541 | return false; | ||
2542 | if (chip->disabled || !chip->bus) | ||
2543 | return true; | ||
2544 | if (snd_hda_lock_devices(chip->bus)) | ||
2545 | return false; | ||
2546 | snd_hda_unlock_devices(chip->bus); | ||
2547 | return true; | ||
2548 | } | ||
2549 | |||
2550 | static void __devinit init_vga_switcheroo(struct azx *chip) | ||
2551 | { | ||
2552 | struct pci_dev *p = get_bound_vga(chip->pci); | ||
2553 | if (p) { | ||
2554 | snd_printk(KERN_INFO SFX | ||
2555 | "%s: Handle VGA-switcheroo audio client\n", | ||
2556 | pci_name(chip->pci)); | ||
2557 | chip->use_vga_switcheroo = 1; | ||
2558 | pci_dev_put(p); | ||
2559 | } | ||
2560 | } | ||
2561 | |||
2562 | static const struct vga_switcheroo_client_ops azx_vs_ops = { | ||
2563 | .set_gpu_state = azx_vs_set_state, | ||
2564 | .can_switch = azx_vs_can_switch, | ||
2565 | }; | ||
2566 | |||
2567 | static int __devinit register_vga_switcheroo(struct azx *chip) | ||
2568 | { | ||
2569 | if (!chip->use_vga_switcheroo) | ||
2570 | return 0; | ||
2571 | /* FIXME: currently only handling DIS controller | ||
2572 | * is there any machine with two switchable HDMI audio controllers? | ||
2573 | */ | ||
2574 | return vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, | ||
2575 | VGA_SWITCHEROO_DIS, | ||
2576 | chip->bus != NULL); | ||
2577 | } | ||
2578 | #else | ||
2579 | #define init_vga_switcheroo(chip) /* NOP */ | ||
2580 | #define register_vga_switcheroo(chip) 0 | ||
2581 | #endif /* SUPPORT_VGA_SWITCHER */ | ||
2582 | |||
2447 | /* | 2583 | /* |
2448 | * destructor | 2584 | * destructor |
2449 | */ | 2585 | */ |
@@ -2453,6 +2589,12 @@ static int azx_free(struct azx *chip) | |||
2453 | 2589 | ||
2454 | azx_notifier_unregister(chip); | 2590 | azx_notifier_unregister(chip); |
2455 | 2591 | ||
2592 | if (use_vga_switcheroo(chip)) { | ||
2593 | if (chip->disabled && chip->bus) | ||
2594 | snd_hda_unlock_devices(chip->bus); | ||
2595 | vga_switcheroo_unregister_client(chip->pci); | ||
2596 | } | ||
2597 | |||
2456 | if (chip->initialized) { | 2598 | if (chip->initialized) { |
2457 | azx_clear_irq_pending(chip); | 2599 | azx_clear_irq_pending(chip); |
2458 | for (i = 0; i < chip->num_streams; i++) | 2600 | for (i = 0; i < chip->num_streams; i++) |
@@ -2482,7 +2624,8 @@ static int azx_free(struct azx *chip) | |||
2482 | mark_pages_wc(chip, &chip->posbuf, false); | 2624 | mark_pages_wc(chip, &chip->posbuf, false); |
2483 | snd_dma_free_pages(&chip->posbuf); | 2625 | snd_dma_free_pages(&chip->posbuf); |
2484 | } | 2626 | } |
2485 | pci_release_regions(chip->pci); | 2627 | if (chip->region_requested) |
2628 | pci_release_regions(chip->pci); | ||
2486 | pci_disable_device(chip->pci); | 2629 | pci_disable_device(chip->pci); |
2487 | kfree(chip->azx_dev); | 2630 | kfree(chip->azx_dev); |
2488 | kfree(chip); | 2631 | kfree(chip); |
@@ -2496,6 +2639,45 @@ static int azx_dev_free(struct snd_device *device) | |||
2496 | } | 2639 | } |
2497 | 2640 | ||
2498 | /* | 2641 | /* |
2642 | * Check of disabled HDMI controller by vga-switcheroo | ||
2643 | */ | ||
2644 | static struct pci_dev __devinit *get_bound_vga(struct pci_dev *pci) | ||
2645 | { | ||
2646 | struct pci_dev *p; | ||
2647 | |||
2648 | /* check only discrete GPU */ | ||
2649 | switch (pci->vendor) { | ||
2650 | case PCI_VENDOR_ID_ATI: | ||
2651 | case PCI_VENDOR_ID_AMD: | ||
2652 | case PCI_VENDOR_ID_NVIDIA: | ||
2653 | if (pci->devfn == 1) { | ||
2654 | p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus), | ||
2655 | pci->bus->number, 0); | ||
2656 | if (p) { | ||
2657 | if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA) | ||
2658 | return p; | ||
2659 | pci_dev_put(p); | ||
2660 | } | ||
2661 | } | ||
2662 | break; | ||
2663 | } | ||
2664 | return NULL; | ||
2665 | } | ||
2666 | |||
2667 | static bool __devinit check_hdmi_disabled(struct pci_dev *pci) | ||
2668 | { | ||
2669 | bool vga_inactive = false; | ||
2670 | struct pci_dev *p = get_bound_vga(pci); | ||
2671 | |||
2672 | if (p) { | ||
2673 | if (vga_default_device() && p != vga_default_device()) | ||
2674 | vga_inactive = true; | ||
2675 | pci_dev_put(p); | ||
2676 | } | ||
2677 | return vga_inactive; | ||
2678 | } | ||
2679 | |||
2680 | /* | ||
2499 | * white/black-listing for position_fix | 2681 | * white/black-listing for position_fix |
2500 | */ | 2682 | */ |
2501 | static struct snd_pci_quirk position_fix_list[] __devinitdata = { | 2683 | static struct snd_pci_quirk position_fix_list[] __devinitdata = { |
@@ -2672,12 +2854,11 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2672 | int dev, unsigned int driver_caps, | 2854 | int dev, unsigned int driver_caps, |
2673 | struct azx **rchip) | 2855 | struct azx **rchip) |
2674 | { | 2856 | { |
2675 | struct azx *chip; | ||
2676 | int i, err; | ||
2677 | unsigned short gcap; | ||
2678 | static struct snd_device_ops ops = { | 2857 | static struct snd_device_ops ops = { |
2679 | .dev_free = azx_dev_free, | 2858 | .dev_free = azx_dev_free, |
2680 | }; | 2859 | }; |
2860 | struct azx *chip; | ||
2861 | int err; | ||
2681 | 2862 | ||
2682 | *rchip = NULL; | 2863 | *rchip = NULL; |
2683 | 2864 | ||
@@ -2703,6 +2884,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2703 | chip->dev_index = dev; | 2884 | chip->dev_index = dev; |
2704 | INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); | 2885 | INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); |
2705 | INIT_LIST_HEAD(&chip->pcm_list); | 2886 | INIT_LIST_HEAD(&chip->pcm_list); |
2887 | init_vga_switcheroo(chip); | ||
2706 | 2888 | ||
2707 | chip->position_fix[0] = chip->position_fix[1] = | 2889 | chip->position_fix[0] = chip->position_fix[1] = |
2708 | check_position_fix(chip, position_fix[dev]); | 2890 | check_position_fix(chip, position_fix[dev]); |
@@ -2730,6 +2912,53 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2730 | } | 2912 | } |
2731 | } | 2913 | } |
2732 | 2914 | ||
2915 | if (check_hdmi_disabled(pci)) { | ||
2916 | snd_printk(KERN_INFO SFX "VGA controller for %s is disabled\n", | ||
2917 | pci_name(pci)); | ||
2918 | if (use_vga_switcheroo(chip)) { | ||
2919 | snd_printk(KERN_INFO SFX "Delaying initialization\n"); | ||
2920 | chip->disabled = true; | ||
2921 | goto ok; | ||
2922 | } | ||
2923 | kfree(chip); | ||
2924 | pci_disable_device(pci); | ||
2925 | return -ENXIO; | ||
2926 | } | ||
2927 | |||
2928 | err = azx_first_init(chip); | ||
2929 | if (err < 0) { | ||
2930 | azx_free(chip); | ||
2931 | return err; | ||
2932 | } | ||
2933 | |||
2934 | ok: | ||
2935 | err = register_vga_switcheroo(chip); | ||
2936 | if (err < 0) { | ||
2937 | snd_printk(KERN_ERR SFX | ||
2938 | "Error registering VGA-switcheroo client\n"); | ||
2939 | azx_free(chip); | ||
2940 | return err; | ||
2941 | } | ||
2942 | |||
2943 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); | ||
2944 | if (err < 0) { | ||
2945 | snd_printk(KERN_ERR SFX "Error creating device [card]!\n"); | ||
2946 | azx_free(chip); | ||
2947 | return err; | ||
2948 | } | ||
2949 | |||
2950 | *rchip = chip; | ||
2951 | return 0; | ||
2952 | } | ||
2953 | |||
2954 | static int DELAYED_INIT_MARK azx_first_init(struct azx *chip) | ||
2955 | { | ||
2956 | int dev = chip->dev_index; | ||
2957 | struct pci_dev *pci = chip->pci; | ||
2958 | struct snd_card *card = chip->card; | ||
2959 | int i, err; | ||
2960 | unsigned short gcap; | ||
2961 | |||
2733 | #if BITS_PER_LONG != 64 | 2962 | #if BITS_PER_LONG != 64 |
2734 | /* Fix up base address on ULI M5461 */ | 2963 | /* Fix up base address on ULI M5461 */ |
2735 | if (chip->driver_type == AZX_DRIVER_ULI) { | 2964 | if (chip->driver_type == AZX_DRIVER_ULI) { |
@@ -2741,28 +2970,23 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2741 | #endif | 2970 | #endif |
2742 | 2971 | ||
2743 | err = pci_request_regions(pci, "ICH HD audio"); | 2972 | err = pci_request_regions(pci, "ICH HD audio"); |
2744 | if (err < 0) { | 2973 | if (err < 0) |
2745 | kfree(chip); | ||
2746 | pci_disable_device(pci); | ||
2747 | return err; | 2974 | return err; |
2748 | } | 2975 | chip->region_requested = 1; |
2749 | 2976 | ||
2750 | chip->addr = pci_resource_start(pci, 0); | 2977 | chip->addr = pci_resource_start(pci, 0); |
2751 | chip->remap_addr = pci_ioremap_bar(pci, 0); | 2978 | chip->remap_addr = pci_ioremap_bar(pci, 0); |
2752 | if (chip->remap_addr == NULL) { | 2979 | if (chip->remap_addr == NULL) { |
2753 | snd_printk(KERN_ERR SFX "ioremap error\n"); | 2980 | snd_printk(KERN_ERR SFX "ioremap error\n"); |
2754 | err = -ENXIO; | 2981 | return -ENXIO; |
2755 | goto errout; | ||
2756 | } | 2982 | } |
2757 | 2983 | ||
2758 | if (chip->msi) | 2984 | if (chip->msi) |
2759 | if (pci_enable_msi(pci) < 0) | 2985 | if (pci_enable_msi(pci) < 0) |
2760 | chip->msi = 0; | 2986 | chip->msi = 0; |
2761 | 2987 | ||
2762 | if (azx_acquire_irq(chip, 0) < 0) { | 2988 | if (azx_acquire_irq(chip, 0) < 0) |
2763 | err = -EBUSY; | 2989 | return -EBUSY; |
2764 | goto errout; | ||
2765 | } | ||
2766 | 2990 | ||
2767 | pci_set_master(pci); | 2991 | pci_set_master(pci); |
2768 | synchronize_irq(chip->irq); | 2992 | synchronize_irq(chip->irq); |
@@ -2841,7 +3065,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2841 | GFP_KERNEL); | 3065 | GFP_KERNEL); |
2842 | if (!chip->azx_dev) { | 3066 | if (!chip->azx_dev) { |
2843 | snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n"); | 3067 | snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n"); |
2844 | goto errout; | 3068 | return -ENOMEM; |
2845 | } | 3069 | } |
2846 | 3070 | ||
2847 | for (i = 0; i < chip->num_streams; i++) { | 3071 | for (i = 0; i < chip->num_streams; i++) { |
@@ -2851,7 +3075,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2851 | BDL_SIZE, &chip->azx_dev[i].bdl); | 3075 | BDL_SIZE, &chip->azx_dev[i].bdl); |
2852 | if (err < 0) { | 3076 | if (err < 0) { |
2853 | snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); | 3077 | snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); |
2854 | goto errout; | 3078 | return -ENOMEM; |
2855 | } | 3079 | } |
2856 | mark_pages_wc(chip, &chip->azx_dev[i].bdl, true); | 3080 | mark_pages_wc(chip, &chip->azx_dev[i].bdl, true); |
2857 | } | 3081 | } |
@@ -2861,13 +3085,13 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2861 | chip->num_streams * 8, &chip->posbuf); | 3085 | chip->num_streams * 8, &chip->posbuf); |
2862 | if (err < 0) { | 3086 | if (err < 0) { |
2863 | snd_printk(KERN_ERR SFX "cannot allocate posbuf\n"); | 3087 | snd_printk(KERN_ERR SFX "cannot allocate posbuf\n"); |
2864 | goto errout; | 3088 | return -ENOMEM; |
2865 | } | 3089 | } |
2866 | mark_pages_wc(chip, &chip->posbuf, true); | 3090 | mark_pages_wc(chip, &chip->posbuf, true); |
2867 | /* allocate CORB/RIRB */ | 3091 | /* allocate CORB/RIRB */ |
2868 | err = azx_alloc_cmd_io(chip); | 3092 | err = azx_alloc_cmd_io(chip); |
2869 | if (err < 0) | 3093 | if (err < 0) |
2870 | goto errout; | 3094 | return err; |
2871 | 3095 | ||
2872 | /* initialize streams */ | 3096 | /* initialize streams */ |
2873 | azx_init_stream(chip); | 3097 | azx_init_stream(chip); |
@@ -2879,14 +3103,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2879 | /* codec detection */ | 3103 | /* codec detection */ |
2880 | if (!chip->codec_mask) { | 3104 | if (!chip->codec_mask) { |
2881 | snd_printk(KERN_ERR SFX "no codecs found!\n"); | 3105 | snd_printk(KERN_ERR SFX "no codecs found!\n"); |
2882 | err = -ENODEV; | 3106 | return -ENODEV; |
2883 | goto errout; | ||
2884 | } | ||
2885 | |||
2886 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); | ||
2887 | if (err <0) { | ||
2888 | snd_printk(KERN_ERR SFX "Error creating device [card]!\n"); | ||
2889 | goto errout; | ||
2890 | } | 3107 | } |
2891 | 3108 | ||
2892 | strcpy(card->driver, "HDA-Intel"); | 3109 | strcpy(card->driver, "HDA-Intel"); |
@@ -2896,12 +3113,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, | |||
2896 | "%s at 0x%lx irq %i", | 3113 | "%s at 0x%lx irq %i", |
2897 | card->shortname, chip->addr, chip->irq); | 3114 | card->shortname, chip->addr, chip->irq); |
2898 | 3115 | ||
2899 | *rchip = chip; | ||
2900 | return 0; | 3116 | return 0; |
2901 | |||
2902 | errout: | ||
2903 | azx_free(chip); | ||
2904 | return err; | ||
2905 | } | 3117 | } |
2906 | 3118 | ||
2907 | static void power_down_all_codecs(struct azx *chip) | 3119 | static void power_down_all_codecs(struct azx *chip) |
@@ -2946,6 +3158,27 @@ static int __devinit azx_probe(struct pci_dev *pci, | |||
2946 | goto out_free; | 3158 | goto out_free; |
2947 | card->private_data = chip; | 3159 | card->private_data = chip; |
2948 | 3160 | ||
3161 | if (!chip->disabled) { | ||
3162 | err = azx_probe_continue(chip); | ||
3163 | if (err < 0) | ||
3164 | goto out_free; | ||
3165 | } | ||
3166 | |||
3167 | pci_set_drvdata(pci, card); | ||
3168 | |||
3169 | dev++; | ||
3170 | return 0; | ||
3171 | |||
3172 | out_free: | ||
3173 | snd_card_free(card); | ||
3174 | return err; | ||
3175 | } | ||
3176 | |||
3177 | static int DELAYED_INIT_MARK azx_probe_continue(struct azx *chip) | ||
3178 | { | ||
3179 | int dev = chip->dev_index; | ||
3180 | int err; | ||
3181 | |||
2949 | #ifdef CONFIG_SND_HDA_INPUT_BEEP | 3182 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
2950 | chip->beep_mode = beep_mode[dev]; | 3183 | chip->beep_mode = beep_mode[dev]; |
2951 | #endif | 3184 | #endif |
@@ -2979,25 +3212,26 @@ static int __devinit azx_probe(struct pci_dev *pci, | |||
2979 | if (err < 0) | 3212 | if (err < 0) |
2980 | goto out_free; | 3213 | goto out_free; |
2981 | 3214 | ||
2982 | err = snd_card_register(card); | 3215 | err = snd_card_register(chip->card); |
2983 | if (err < 0) | 3216 | if (err < 0) |
2984 | goto out_free; | 3217 | goto out_free; |
2985 | 3218 | ||
2986 | pci_set_drvdata(pci, card); | ||
2987 | chip->running = 1; | 3219 | chip->running = 1; |
2988 | power_down_all_codecs(chip); | 3220 | power_down_all_codecs(chip); |
2989 | azx_notifier_register(chip); | 3221 | azx_notifier_register(chip); |
2990 | 3222 | ||
2991 | dev++; | 3223 | return 0; |
2992 | return err; | 3224 | |
2993 | out_free: | 3225 | out_free: |
2994 | snd_card_free(card); | 3226 | chip->init_failed = 1; |
2995 | return err; | 3227 | return err; |
2996 | } | 3228 | } |
2997 | 3229 | ||
2998 | static void __devexit azx_remove(struct pci_dev *pci) | 3230 | static void __devexit azx_remove(struct pci_dev *pci) |
2999 | { | 3231 | { |
3000 | snd_card_free(pci_get_drvdata(pci)); | 3232 | struct snd_card *card = pci_get_drvdata(pci); |
3233 | if (card) | ||
3234 | snd_card_free(card); | ||
3001 | pci_set_drvdata(pci, NULL); | 3235 | pci_set_drvdata(pci, NULL); |
3002 | } | 3236 | } |
3003 | 3237 | ||