Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 3 | * hda_intel.c - Implementation of primary alsa driver code base |
| 4 | * for Intel HD Audio. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright(c) 2004 Intel Corporation. All rights reserved. |
| 7 | * |
| 8 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> |
| 9 | * PeiSen Hou <pshou@realtek.com.tw> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the Free |
| 13 | * Software Foundation; either version 2 of the License, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 19 | * more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 23 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | * CONTACTS: |
| 26 | * |
| 27 | * Matt Jared matt.jared@intel.com |
| 28 | * Andy Kopp andy.kopp@intel.com |
| 29 | * Dan Kogan dan.d.kogan@intel.com |
| 30 | * |
| 31 | * CHANGES: |
| 32 | * |
| 33 | * 2004.12.01 Major rewrite by tiwai, merged the work of pshou |
| 34 | * |
| 35 | */ |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/delay.h> |
| 38 | #include <linux/interrupt.h> |
Randy Dunlap | 362775e | 2005-11-07 14:43:23 +0100 | [diff] [blame] | 39 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/module.h> |
Andrew Morton | 24982c5 | 2008-03-04 10:08:58 +0100 | [diff] [blame] | 41 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/moduleparam.h> |
| 43 | #include <linux/init.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/pci.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 46 | #include <linux/mutex.h> |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 47 | #include <linux/reboot.h> |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 48 | #include <linux/io.h> |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 49 | #include <linux/pm_runtime.h> |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 50 | #include <linux/clocksource.h> |
| 51 | #include <linux/time.h> |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 52 | #include <linux/completion.h> |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 53 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_X86 |
| 55 | /* for snoop control */ |
| 56 | #include <asm/pgtable.h> |
| 57 | #include <asm/cacheflush.h> |
| 58 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include <sound/core.h> |
| 60 | #include <sound/initval.h> |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 61 | #include <linux/vgaarb.h> |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 62 | #include <linux/vga_switcheroo.h> |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 63 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include "hda_codec.h" |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 65 | #include "hda_i915.h" |
Dylan Reid | 05e8487 | 2014-02-28 15:41:22 -0800 | [diff] [blame^] | 66 | #include "hda_controller.h" |
Dylan Reid | 2538a4f | 2014-02-28 15:41:12 -0800 | [diff] [blame] | 67 | #include "hda_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 70 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 71 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 72 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 73 | static char *model[SNDRV_CARDS]; |
Takashi Iwai | 1dac669 | 2012-09-13 14:59:47 +0200 | [diff] [blame] | 74 | static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 75 | static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 76 | static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
Takashi Iwai | d4d9cd03 | 2008-12-19 15:19:11 +0100 | [diff] [blame] | 77 | static int probe_only[SNDRV_CARDS]; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 78 | static int jackpoll_ms[SNDRV_CARDS]; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 79 | static bool single_cmd; |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 80 | static int enable_msi = -1; |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 81 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 82 | static char *patch[SNDRV_CARDS]; |
| 83 | #endif |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 84 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 0920c9b | 2012-07-03 16:58:48 +0200 | [diff] [blame] | 85 | static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 86 | CONFIG_SND_HDA_INPUT_BEEP_MODE}; |
| 87 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 89 | module_param_array(index, int, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 91 | module_param_array(id, charp, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | MODULE_PARM_DESC(id, "ID string for Intel HD audio interface."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 93 | module_param_array(enable, bool, NULL, 0444); |
| 94 | MODULE_PARM_DESC(enable, "Enable Intel HD audio interface."); |
| 95 | module_param_array(model, charp, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | MODULE_PARM_DESC(model, "Use the given board model."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 97 | module_param_array(position_fix, int, NULL, 0444); |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 98 | MODULE_PARM_DESC(position_fix, "DMA pointer read method." |
Takashi Iwai | 1dac669 | 2012-09-13 14:59:47 +0200 | [diff] [blame] | 99 | "(-1 = system default, 0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO, 4 = COMBO)."); |
Takashi Iwai | 555e219 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 100 | module_param_array(bdl_pos_adj, int, NULL, 0644); |
| 101 | MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 102 | module_param_array(probe_mask, int, NULL, 0444); |
Takashi Iwai | 606ad75 | 2005-11-24 16:03:40 +0100 | [diff] [blame] | 103 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); |
Jaroslav Kysela | 079e683 | 2010-03-26 11:16:59 +0100 | [diff] [blame] | 104 | module_param_array(probe_only, int, NULL, 0444); |
Takashi Iwai | d4d9cd03 | 2008-12-19 15:19:11 +0100 | [diff] [blame] | 105 | MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization."); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 106 | module_param_array(jackpoll_ms, int, NULL, 0444); |
| 107 | MODULE_PARM_DESC(jackpoll_ms, "Ms between polling for jack events (default = 0, using unsol events only)"); |
Takashi Iwai | 2734616 | 2006-01-12 18:28:44 +0100 | [diff] [blame] | 108 | module_param(single_cmd, bool, 0444); |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 109 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " |
| 110 | "(for debugging only)."); |
Takashi Iwai | ac9ef6c | 2012-01-20 12:08:44 +0100 | [diff] [blame] | 111 | module_param(enable_msi, bint, 0444); |
Takashi Iwai | 134a11f | 2006-11-10 12:08:37 +0100 | [diff] [blame] | 112 | MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 113 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 114 | module_param_array(patch, charp, NULL, 0444); |
| 115 | MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface."); |
| 116 | #endif |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 0920c9b | 2012-07-03 16:58:48 +0200 | [diff] [blame] | 118 | module_param_array(beep_mode, bool, NULL, 0444); |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 119 | MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode " |
Takashi Iwai | 0920c9b | 2012-07-03 16:58:48 +0200 | [diff] [blame] | 120 | "(0=off, 1=on) (default=1)."); |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 121 | #endif |
Takashi Iwai | 606ad75 | 2005-11-24 16:03:40 +0100 | [diff] [blame] | 122 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 123 | #ifdef CONFIG_PM |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 124 | static int param_set_xint(const char *val, const struct kernel_param *kp); |
| 125 | static struct kernel_param_ops param_ops_xint = { |
| 126 | .set = param_set_xint, |
| 127 | .get = param_get_int, |
| 128 | }; |
| 129 | #define param_check_xint param_check_int |
| 130 | |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 131 | static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame] | 132 | static int *power_save_addr = &power_save; |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 133 | module_param(power_save, xint, 0644); |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 134 | MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " |
| 135 | "(in second, 0 = disable)."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Takashi Iwai | dee1b66 | 2007-08-13 16:10:30 +0200 | [diff] [blame] | 137 | /* reset the HD-audio controller in power save mode. |
| 138 | * this may give more power-saving, but will take longer time to |
| 139 | * wake up. |
| 140 | */ |
Takashi Iwai | 8fc2442 | 2013-04-04 15:35:24 +0200 | [diff] [blame] | 141 | static bool power_save_controller = 1; |
| 142 | module_param(power_save_controller, bool, 0644); |
Takashi Iwai | dee1b66 | 2007-08-13 16:10:30 +0200 | [diff] [blame] | 143 | MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame] | 144 | #else |
| 145 | static int *power_save_addr; |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 146 | #endif /* CONFIG_PM */ |
Takashi Iwai | dee1b66 | 2007-08-13 16:10:30 +0200 | [diff] [blame] | 147 | |
Takashi Iwai | 7bfe059 | 2012-01-23 17:53:39 +0100 | [diff] [blame] | 148 | static int align_buffer_size = -1; |
| 149 | module_param(align_buffer_size, bint, 0644); |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 150 | MODULE_PARM_DESC(align_buffer_size, |
| 151 | "Force buffer and period sizes to be multiple of 128 bytes."); |
| 152 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 153 | #ifdef CONFIG_X86 |
| 154 | static bool hda_snoop = true; |
| 155 | module_param_named(snoop, hda_snoop, bool, 0444); |
| 156 | MODULE_PARM_DESC(snoop, "Enable/disable snooping"); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 157 | #else |
| 158 | #define hda_snoop true |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 159 | #endif |
| 160 | |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | MODULE_LICENSE("GPL"); |
| 163 | MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," |
| 164 | "{Intel, ICH6M}," |
Jason Gaston | 2f1b381 | 2005-05-01 08:58:50 -0700 | [diff] [blame] | 165 | "{Intel, ICH7}," |
Frederick Li | f5d40b3 | 2005-05-12 14:55:20 +0200 | [diff] [blame] | 166 | "{Intel, ESB2}," |
Jason Gaston | d298139 | 2006-01-10 11:07:37 +0100 | [diff] [blame] | 167 | "{Intel, ICH8}," |
Jason Gaston | f9cc8a8 | 2006-11-22 11:53:52 +0100 | [diff] [blame] | 168 | "{Intel, ICH9}," |
Jason Gaston | c34f5a0 | 2008-01-29 12:38:49 +0100 | [diff] [blame] | 169 | "{Intel, ICH10}," |
Seth Heasley | b29c236 | 2008-08-08 15:56:39 -0700 | [diff] [blame] | 170 | "{Intel, PCH}," |
Seth Heasley | d2f2fcd | 2010-01-12 17:03:35 -0800 | [diff] [blame] | 171 | "{Intel, CPT}," |
Seth Heasley | d2edeb7 | 2011-04-20 10:59:57 -0700 | [diff] [blame] | 172 | "{Intel, PPT}," |
Seth Heasley | 8bc039a | 2012-01-23 16:24:31 -0800 | [diff] [blame] | 173 | "{Intel, LPT}," |
James Ralston | 144dad9 | 2012-08-09 09:38:59 -0700 | [diff] [blame] | 174 | "{Intel, LPT_LP}," |
James Ralston | 4eeca49 | 2013-11-04 09:27:45 -0800 | [diff] [blame] | 175 | "{Intel, WPT_LP}," |
Wang Xingchao | e926f2c | 2012-06-13 10:23:51 +0800 | [diff] [blame] | 176 | "{Intel, HPT}," |
Seth Heasley | cea310e | 2010-09-10 16:29:56 -0700 | [diff] [blame] | 177 | "{Intel, PBG}," |
Tobin Davis | 4979bca | 2008-01-30 08:13:55 +0100 | [diff] [blame] | 178 | "{Intel, SCH}," |
Takashi Iwai | fc20a56 | 2005-05-12 15:00:41 +0200 | [diff] [blame] | 179 | "{ATI, SB450}," |
Felix Kuehling | 89be83f | 2006-03-31 12:33:59 +0200 | [diff] [blame] | 180 | "{ATI, SB600}," |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 181 | "{ATI, RS600}," |
Felix Kuehling | 5b15c95 | 2006-10-16 12:49:47 +0200 | [diff] [blame] | 182 | "{ATI, RS690}," |
Wolke Liu | e6db111 | 2007-04-27 12:20:57 +0200 | [diff] [blame] | 183 | "{ATI, RS780}," |
| 184 | "{ATI, R600}," |
Herton Ronaldo Krzesinski | 2797f72 | 2007-11-05 18:21:56 +0100 | [diff] [blame] | 185 | "{ATI, RV630}," |
| 186 | "{ATI, RV610}," |
Wolke Liu | 27da183 | 2007-11-16 11:06:30 +0100 | [diff] [blame] | 187 | "{ATI, RV670}," |
| 188 | "{ATI, RV635}," |
| 189 | "{ATI, RV620}," |
| 190 | "{ATI, RV770}," |
Takashi Iwai | fc20a56 | 2005-05-12 15:00:41 +0200 | [diff] [blame] | 191 | "{VIA, VT8251}," |
Takashi Iwai | 4767231 | 2005-08-12 16:44:04 +0200 | [diff] [blame] | 192 | "{VIA, VT8237A}," |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 193 | "{SiS, SIS966}," |
| 194 | "{ULI, M5461}}"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | MODULE_DESCRIPTION("Intel HDA driver"); |
| 196 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 197 | #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO) |
Takashi Iwai | f8f1bec | 2014-02-06 18:14:03 +0100 | [diff] [blame] | 198 | #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 199 | #define SUPPORT_VGA_SWITCHEROO |
| 200 | #endif |
| 201 | #endif |
| 202 | |
| 203 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 204 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 207 | /* driver types */ |
| 208 | enum { |
| 209 | AZX_DRIVER_ICH, |
Seth Heasley | 32679f9 | 2010-02-22 17:31:09 -0800 | [diff] [blame] | 210 | AZX_DRIVER_PCH, |
Tobin Davis | 4979bca | 2008-01-30 08:13:55 +0100 | [diff] [blame] | 211 | AZX_DRIVER_SCH, |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 212 | AZX_DRIVER_HDMI, |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 213 | AZX_DRIVER_ATI, |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 214 | AZX_DRIVER_ATIHDMI, |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 215 | AZX_DRIVER_ATIHDMI_NS, |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 216 | AZX_DRIVER_VIA, |
| 217 | AZX_DRIVER_SIS, |
| 218 | AZX_DRIVER_ULI, |
Vinod G | da3fca2 | 2005-09-13 18:49:12 +0200 | [diff] [blame] | 219 | AZX_DRIVER_NVIDIA, |
Kailang Yang | f269002 | 2008-05-27 11:44:55 +0200 | [diff] [blame] | 220 | AZX_DRIVER_TERA, |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 221 | AZX_DRIVER_CTX, |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 222 | AZX_DRIVER_CTHDA, |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 223 | AZX_DRIVER_GENERIC, |
Takashi Iwai | 2f5983f | 2008-09-03 16:00:44 +0200 | [diff] [blame] | 224 | AZX_NUM_DRIVERS, /* keep this as last entry */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 225 | }; |
| 226 | |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 227 | /* quirks for Intel PCH */ |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 228 | #define AZX_DCAPS_INTEL_PCH_NOPM \ |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 229 | (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \ |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 230 | AZX_DCAPS_COUNT_LPIB_DELAY) |
| 231 | |
| 232 | #define AZX_DCAPS_INTEL_PCH \ |
| 233 | (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME) |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 234 | |
Takashi Iwai | 33499a1 | 2013-11-05 17:34:46 +0100 | [diff] [blame] | 235 | #define AZX_DCAPS_INTEL_HASWELL \ |
| 236 | (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_ALIGN_BUFSIZE | \ |
| 237 | AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_PM_RUNTIME | \ |
| 238 | AZX_DCAPS_I915_POWERWELL) |
| 239 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 240 | /* quirks for ATI SB / AMD Hudson */ |
| 241 | #define AZX_DCAPS_PRESET_ATI_SB \ |
| 242 | (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \ |
| 243 | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB) |
| 244 | |
| 245 | /* quirks for ATI/AMD HDMI */ |
| 246 | #define AZX_DCAPS_PRESET_ATI_HDMI \ |
| 247 | (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB) |
| 248 | |
| 249 | /* quirks for Nvidia */ |
| 250 | #define AZX_DCAPS_PRESET_NVIDIA \ |
Takashi Iwai | 7bfe059 | 2012-01-23 17:53:39 +0100 | [diff] [blame] | 251 | (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ |
Mike Travis | 49d9e77 | 2013-05-01 14:04:08 -0500 | [diff] [blame] | 252 | AZX_DCAPS_ALIGN_BUFSIZE | AZX_DCAPS_NO_64BIT) |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 253 | |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 254 | #define AZX_DCAPS_PRESET_CTHDA \ |
| 255 | (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) |
| 256 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 257 | /* |
| 258 | * VGA-switcher support |
| 259 | */ |
| 260 | #ifdef SUPPORT_VGA_SWITCHEROO |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 261 | #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo) |
| 262 | #else |
| 263 | #define use_vga_switcheroo(chip) 0 |
| 264 | #endif |
| 265 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 266 | static char *driver_short_names[] = { |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 267 | [AZX_DRIVER_ICH] = "HDA Intel", |
Seth Heasley | 32679f9 | 2010-02-22 17:31:09 -0800 | [diff] [blame] | 268 | [AZX_DRIVER_PCH] = "HDA Intel PCH", |
Tobin Davis | 4979bca | 2008-01-30 08:13:55 +0100 | [diff] [blame] | 269 | [AZX_DRIVER_SCH] = "HDA Intel MID", |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 270 | [AZX_DRIVER_HDMI] = "HDA Intel HDMI", |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 271 | [AZX_DRIVER_ATI] = "HDA ATI SB", |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 272 | [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI", |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 273 | [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI", |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 274 | [AZX_DRIVER_VIA] = "HDA VIA VT82xx", |
| 275 | [AZX_DRIVER_SIS] = "HDA SIS966", |
Vinod G | da3fca2 | 2005-09-13 18:49:12 +0200 | [diff] [blame] | 276 | [AZX_DRIVER_ULI] = "HDA ULI M5461", |
| 277 | [AZX_DRIVER_NVIDIA] = "HDA NVidia", |
Kailang Yang | f269002 | 2008-05-27 11:44:55 +0200 | [diff] [blame] | 278 | [AZX_DRIVER_TERA] = "HDA Teradici", |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 279 | [AZX_DRIVER_CTX] = "HDA Creative", |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 280 | [AZX_DRIVER_CTHDA] = "HDA Creative", |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 281 | [AZX_DRIVER_GENERIC] = "HD-Audio Generic", |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 282 | }; |
| 283 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 284 | #ifdef CONFIG_X86 |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 285 | static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on) |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 286 | { |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 287 | int pages; |
| 288 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 289 | if (azx_snoop(chip)) |
| 290 | return; |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 291 | if (!dmab || !dmab->area || !dmab->bytes) |
| 292 | return; |
| 293 | |
| 294 | #ifdef CONFIG_SND_DMA_SGBUF |
| 295 | if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) { |
| 296 | struct snd_sg_buf *sgbuf = dmab->private_data; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 297 | if (on) |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 298 | set_pages_array_wc(sgbuf->page_table, sgbuf->pages); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 299 | else |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 300 | set_pages_array_wb(sgbuf->page_table, sgbuf->pages); |
| 301 | return; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 302 | } |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 303 | #endif |
| 304 | |
| 305 | pages = (dmab->bytes + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 306 | if (on) |
| 307 | set_memory_wc((unsigned long)dmab->area, pages); |
| 308 | else |
| 309 | set_memory_wb((unsigned long)dmab->area, pages); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf, |
| 313 | bool on) |
| 314 | { |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 315 | __mark_pages_wc(chip, buf, on); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 316 | } |
| 317 | static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev, |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 318 | struct snd_pcm_substream *substream, bool on) |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 319 | { |
| 320 | if (azx_dev->wc_marked != on) { |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 321 | __mark_pages_wc(chip, snd_pcm_get_dma_buf(substream), on); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 322 | azx_dev->wc_marked = on; |
| 323 | } |
| 324 | } |
| 325 | #else |
| 326 | /* NOP for other archs */ |
| 327 | static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf, |
| 328 | bool on) |
| 329 | { |
| 330 | } |
| 331 | static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev, |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 332 | struct snd_pcm_substream *substream, bool on) |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 333 | { |
| 334 | } |
| 335 | #endif |
| 336 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 337 | static int azx_acquire_irq(struct azx *chip, int do_disconnect); |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 338 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* |
| 340 | * Interface for HD codec |
| 341 | */ |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* |
| 344 | * CORB / RIRB interface |
| 345 | */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 346 | static int azx_alloc_cmd_io(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
| 348 | int err; |
| 349 | |
| 350 | /* single page (at least 4096 bytes) must suffice for both ringbuffes */ |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 351 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, |
| 352 | PAGE_SIZE, &chip->rb); |
| 353 | if (err < 0) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 354 | dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n"); |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 355 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 358 | static void azx_init_cmd_io(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 360 | int timeout; |
| 361 | |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 362 | spin_lock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | /* CORB set up */ |
| 364 | chip->corb.addr = chip->rb.addr; |
| 365 | chip->corb.buf = (u32 *)chip->rb.area; |
| 366 | azx_writel(chip, CORBLBASE, (u32)chip->corb.addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 367 | azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 369 | /* set the corb size to 256 entries (ULI requires explicitly) */ |
| 370 | azx_writeb(chip, CORBSIZE, 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* set the corb write pointer to 0 */ |
| 372 | azx_writew(chip, CORBWP, 0); |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* reset the corb hw read pointer */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 375 | azx_writew(chip, CORBRP, ICH6_CORBRP_RST); |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 376 | for (timeout = 1000; timeout > 0; timeout--) { |
| 377 | if ((azx_readw(chip, CORBRP) & ICH6_CORBRP_RST) == ICH6_CORBRP_RST) |
| 378 | break; |
| 379 | udelay(1); |
| 380 | } |
| 381 | if (timeout <= 0) |
| 382 | dev_err(chip->card->dev, "CORB reset timeout#1, CORBRP = %d\n", |
| 383 | azx_readw(chip, CORBRP)); |
| 384 | |
| 385 | azx_writew(chip, CORBRP, 0); |
| 386 | for (timeout = 1000; timeout > 0; timeout--) { |
| 387 | if (azx_readw(chip, CORBRP) == 0) |
| 388 | break; |
| 389 | udelay(1); |
| 390 | } |
| 391 | if (timeout <= 0) |
| 392 | dev_err(chip->card->dev, "CORB reset timeout#2, CORBRP = %d\n", |
| 393 | azx_readw(chip, CORBRP)); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* enable corb dma */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 396 | azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | /* RIRB set up */ |
| 399 | chip->rirb.addr = chip->rb.addr + 2048; |
| 400 | chip->rirb.buf = (u32 *)(chip->rb.area + 2048); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 401 | chip->rirb.wp = chip->rirb.rp = 0; |
| 402 | memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 404 | azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 406 | /* set the rirb size to 256 entries (ULI requires explicitly) */ |
| 407 | azx_writeb(chip, RIRBSIZE, 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* reset the rirb hw write pointer */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 409 | azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* set N=1, get RIRB response interrupt for new entry */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 411 | if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 412 | azx_writew(chip, RINTCNT, 0xc0); |
| 413 | else |
| 414 | azx_writew(chip, RINTCNT, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /* enable rirb dma and response irq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN); |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 417 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 420 | static void azx_free_cmd_io(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 422 | spin_lock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* disable ringbuffer DMAs */ |
| 424 | azx_writeb(chip, RIRBCTL, 0); |
| 425 | azx_writeb(chip, CORBCTL, 0); |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 426 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 429 | static unsigned int azx_command_addr(u32 cmd) |
| 430 | { |
| 431 | unsigned int addr = cmd >> 28; |
| 432 | |
| 433 | if (addr >= AZX_MAX_CODECS) { |
| 434 | snd_BUG(); |
| 435 | addr = 0; |
| 436 | } |
| 437 | |
| 438 | return addr; |
| 439 | } |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | /* send a command */ |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 442 | static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 444 | struct azx *chip = bus->private_data; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 445 | unsigned int addr = azx_command_addr(val); |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 446 | unsigned int wp, rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Wu Fengguang | c32649f | 2009-08-01 18:48:12 +0800 | [diff] [blame] | 448 | spin_lock_irq(&chip->reg_lock); |
| 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* add command to corb */ |
Takashi Iwai | cc5ede3 | 2012-12-12 11:10:49 +0100 | [diff] [blame] | 451 | wp = azx_readw(chip, CORBWP); |
| 452 | if (wp == 0xffff) { |
| 453 | /* something wrong, controller likely turned to D3 */ |
| 454 | spin_unlock_irq(&chip->reg_lock); |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 455 | return -EIO; |
Takashi Iwai | cc5ede3 | 2012-12-12 11:10:49 +0100 | [diff] [blame] | 456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | wp++; |
| 458 | wp %= ICH6_MAX_CORB_ENTRIES; |
| 459 | |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 460 | rp = azx_readw(chip, CORBRP); |
| 461 | if (wp == rp) { |
| 462 | /* oops, it's full */ |
| 463 | spin_unlock_irq(&chip->reg_lock); |
| 464 | return -EAGAIN; |
| 465 | } |
| 466 | |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 467 | chip->rirb.cmds[addr]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | chip->corb.buf[wp] = cpu_to_le32(val); |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 469 | azx_writew(chip, CORBWP, wp); |
Wu Fengguang | c32649f | 2009-08-01 18:48:12 +0800 | [diff] [blame] | 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | spin_unlock_irq(&chip->reg_lock); |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | #define ICH6_RIRB_EX_UNSOL_EV (1<<4) |
| 477 | |
| 478 | /* retrieve RIRB entry - called from interrupt handler */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 479 | static void azx_update_rirb(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
| 481 | unsigned int rp, wp; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 482 | unsigned int addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | u32 res, res_ex; |
| 484 | |
Takashi Iwai | cc5ede3 | 2012-12-12 11:10:49 +0100 | [diff] [blame] | 485 | wp = azx_readw(chip, RIRBWP); |
| 486 | if (wp == 0xffff) { |
| 487 | /* something wrong, controller likely turned to D3 */ |
| 488 | return; |
| 489 | } |
| 490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | if (wp == chip->rirb.wp) |
| 492 | return; |
| 493 | chip->rirb.wp = wp; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | while (chip->rirb.rp != wp) { |
| 496 | chip->rirb.rp++; |
| 497 | chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES; |
| 498 | |
| 499 | rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ |
| 500 | res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); |
| 501 | res = le32_to_cpu(chip->rirb.buf[rp]); |
David Henningsson | 3d69245 | 2014-01-29 13:12:31 +0100 | [diff] [blame] | 502 | addr = res_ex & 0xf; |
| 503 | if ((addr >= AZX_MAX_CODECS) || !(chip->codec_mask & (1 << addr))) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 504 | dev_err(chip->card->dev, "spurious response %#x:%#x, rp = %d, wp = %d", |
| 505 | res, res_ex, |
| 506 | chip->rirb.rp, wp); |
David Henningsson | 3d69245 | 2014-01-29 13:12:31 +0100 | [diff] [blame] | 507 | snd_BUG(); |
| 508 | } |
| 509 | else if (res_ex & ICH6_RIRB_EX_UNSOL_EV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | snd_hda_queue_unsol_event(chip->bus, res, res_ex); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 511 | else if (chip->rirb.cmds[addr]) { |
| 512 | chip->rirb.res[addr] = res; |
Takashi Iwai | 2add9b9 | 2008-03-18 09:47:06 +0100 | [diff] [blame] | 513 | smp_wmb(); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 514 | chip->rirb.cmds[addr]--; |
Joe Perches | 3b70a67 | 2013-11-07 11:55:15 -0800 | [diff] [blame] | 515 | } else if (printk_ratelimit()) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 516 | dev_err(chip->card->dev, "spurious response %#x:%#x, last cmd=%#08x\n", |
| 517 | res, res_ex, |
| 518 | chip->last_cmd[addr]); |
Joe Perches | 3b70a67 | 2013-11-07 11:55:15 -0800 | [diff] [blame] | 519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
| 523 | /* receive a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 524 | static unsigned int azx_rirb_get_response(struct hda_bus *bus, |
| 525 | unsigned int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 527 | struct azx *chip = bus->private_data; |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 528 | unsigned long timeout; |
David Henningsson | 32cf402 | 2012-05-04 11:05:55 +0200 | [diff] [blame] | 529 | unsigned long loopcounter; |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 530 | int do_poll = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 532 | again: |
| 533 | timeout = jiffies + msecs_to_jiffies(1000); |
David Henningsson | 32cf402 | 2012-05-04 11:05:55 +0200 | [diff] [blame] | 534 | |
| 535 | for (loopcounter = 0;; loopcounter++) { |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 536 | if (chip->polling_mode || do_poll) { |
Takashi Iwai | e96224a | 2006-08-21 17:57:44 +0200 | [diff] [blame] | 537 | spin_lock_irq(&chip->reg_lock); |
| 538 | azx_update_rirb(chip); |
| 539 | spin_unlock_irq(&chip->reg_lock); |
| 540 | } |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 541 | if (!chip->rirb.cmds[addr]) { |
Takashi Iwai | 2add9b9 | 2008-03-18 09:47:06 +0100 | [diff] [blame] | 542 | smp_rmb(); |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 543 | bus->rirb_error = 0; |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 544 | |
| 545 | if (!do_poll) |
| 546 | chip->poll_count = 0; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 547 | return chip->rirb.res[addr]; /* the last value */ |
Takashi Iwai | 2add9b9 | 2008-03-18 09:47:06 +0100 | [diff] [blame] | 548 | } |
Takashi Iwai | 28a0d9d | 2008-01-18 15:32:32 +0100 | [diff] [blame] | 549 | if (time_after(jiffies, timeout)) |
| 550 | break; |
David Henningsson | 32cf402 | 2012-05-04 11:05:55 +0200 | [diff] [blame] | 551 | if (bus->needs_damn_long_delay || loopcounter > 3000) |
Takashi Iwai | 5298765 | 2008-01-16 16:09:47 +0100 | [diff] [blame] | 552 | msleep(2); /* temporary workaround */ |
| 553 | else { |
| 554 | udelay(10); |
| 555 | cond_resched(); |
| 556 | } |
Takashi Iwai | 28a0d9d | 2008-01-18 15:32:32 +0100 | [diff] [blame] | 557 | } |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 558 | |
Takashi Iwai | 63e51fd | 2013-06-06 14:20:19 +0200 | [diff] [blame] | 559 | if (!bus->no_response_fallback) |
| 560 | return -1; |
| 561 | |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 562 | if (!chip->polling_mode && chip->poll_count < 2) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 563 | dev_dbg(chip->card->dev, |
| 564 | "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n", |
| 565 | chip->last_cmd[addr]); |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 566 | do_poll = 1; |
| 567 | chip->poll_count++; |
| 568 | goto again; |
| 569 | } |
| 570 | |
| 571 | |
Takashi Iwai | 23c4a88 | 2009-10-30 13:21:49 +0100 | [diff] [blame] | 572 | if (!chip->polling_mode) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 573 | dev_warn(chip->card->dev, |
| 574 | "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n", |
| 575 | chip->last_cmd[addr]); |
Takashi Iwai | 23c4a88 | 2009-10-30 13:21:49 +0100 | [diff] [blame] | 576 | chip->polling_mode = 1; |
| 577 | goto again; |
| 578 | } |
| 579 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 580 | if (chip->msi) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 581 | dev_warn(chip->card->dev, |
| 582 | "No response from codec, disabling MSI: last cmd=0x%08x\n", |
| 583 | chip->last_cmd[addr]); |
Dylan Reid | f46ea60 | 2014-02-28 15:41:16 -0800 | [diff] [blame] | 584 | if (chip->ops->disable_msi_reset_irq && |
| 585 | chip->ops->disable_msi_reset_irq(chip) < 0) { |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 586 | bus->rirb_error = 1; |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 587 | return -1; |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 588 | } |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 589 | goto again; |
| 590 | } |
| 591 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 592 | if (chip->probing) { |
| 593 | /* If this critical timeout happens during the codec probing |
| 594 | * phase, this is likely an access to a non-existing codec |
| 595 | * slot. Better to return an error and reset the system. |
| 596 | */ |
| 597 | return -1; |
| 598 | } |
| 599 | |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 600 | /* a fatal communication error; need either to reset or to fallback |
| 601 | * to the single_cmd mode |
| 602 | */ |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 603 | bus->rirb_error = 1; |
Takashi Iwai | b20f3b8 | 2009-06-02 01:20:22 +0200 | [diff] [blame] | 604 | if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) { |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 605 | bus->response_reset = 1; |
| 606 | return -1; /* give a chance to retry */ |
| 607 | } |
| 608 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 609 | dev_err(chip->card->dev, |
| 610 | "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n", |
| 611 | chip->last_cmd[addr]); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 612 | chip->single_cmd = 1; |
| 613 | bus->response_reset = 0; |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 614 | /* release CORB/RIRB */ |
Takashi Iwai | 4fcd392 | 2009-05-25 18:34:52 +0200 | [diff] [blame] | 615 | azx_free_cmd_io(chip); |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 616 | /* disable unsolicited responses */ |
| 617 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL); |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 618 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | /* |
| 622 | * Use the single immediate command instead of CORB/RIRB for simplicity |
| 623 | * |
| 624 | * Note: according to Intel, this is not preferred use. The command was |
| 625 | * intended for the BIOS only, and may get confused with unsolicited |
| 626 | * responses. So, we shouldn't use it for normal operation from the |
| 627 | * driver. |
| 628 | * I left the codes, however, for debugging/testing purposes. |
| 629 | */ |
| 630 | |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 631 | /* receive a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 632 | static int azx_single_wait_for_response(struct azx *chip, unsigned int addr) |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 633 | { |
| 634 | int timeout = 50; |
| 635 | |
| 636 | while (timeout--) { |
| 637 | /* check IRV busy bit */ |
| 638 | if (azx_readw(chip, IRS) & ICH6_IRS_VALID) { |
| 639 | /* reuse rirb.res as the response return value */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 640 | chip->rirb.res[addr] = azx_readl(chip, IR); |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | udelay(1); |
| 644 | } |
| 645 | if (printk_ratelimit()) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 646 | dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", |
| 647 | azx_readw(chip, IRS)); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 648 | chip->rirb.res[addr] = -1; |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 649 | return -EIO; |
| 650 | } |
| 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | /* send a command */ |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 653 | static int azx_single_send_cmd(struct hda_bus *bus, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 655 | struct azx *chip = bus->private_data; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 656 | unsigned int addr = azx_command_addr(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | int timeout = 50; |
| 658 | |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 659 | bus->rirb_error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | while (timeout--) { |
| 661 | /* check ICB busy bit */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 662 | if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | /* Clear IRV valid bit */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 664 | azx_writew(chip, IRS, azx_readw(chip, IRS) | |
| 665 | ICH6_IRS_VALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | azx_writel(chip, IC, val); |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 667 | azx_writew(chip, IRS, azx_readw(chip, IRS) | |
| 668 | ICH6_IRS_BUSY); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 669 | return azx_single_wait_for_response(chip, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | udelay(1); |
| 672 | } |
Marc Boucher | 1cfd52b | 2008-01-22 15:29:26 +0100 | [diff] [blame] | 673 | if (printk_ratelimit()) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 674 | dev_dbg(chip->card->dev, |
| 675 | "send_cmd timeout: IRS=0x%x, val=0x%x\n", |
| 676 | azx_readw(chip, IRS), val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return -EIO; |
| 678 | } |
| 679 | |
| 680 | /* receive a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 681 | static unsigned int azx_single_get_response(struct hda_bus *bus, |
| 682 | unsigned int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 684 | struct azx *chip = bus->private_data; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 685 | return chip->rirb.res[addr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 688 | /* |
| 689 | * The below are the main callbacks from hda_codec. |
| 690 | * |
| 691 | * They are just the skeleton to call sub-callbacks according to the |
| 692 | * current setting of chip->single_cmd. |
| 693 | */ |
| 694 | |
| 695 | /* send a command */ |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 696 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val) |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 697 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 698 | struct azx *chip = bus->private_data; |
Takashi Iwai | 43bbb6c | 2007-07-06 20:22:05 +0200 | [diff] [blame] | 699 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 700 | if (chip->disabled) |
| 701 | return 0; |
Wu Fengguang | feb2734 | 2009-08-01 19:17:14 +0800 | [diff] [blame] | 702 | chip->last_cmd[azx_command_addr(val)] = val; |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 703 | if (chip->single_cmd) |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 704 | return azx_single_send_cmd(bus, val); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 705 | else |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 706 | return azx_corb_send_cmd(bus, val); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /* get a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 710 | static unsigned int azx_get_response(struct hda_bus *bus, |
| 711 | unsigned int addr) |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 712 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 713 | struct azx *chip = bus->private_data; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 714 | if (chip->disabled) |
| 715 | return 0; |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 716 | if (chip->single_cmd) |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 717 | return azx_single_get_response(bus, addr); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 718 | else |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 719 | return azx_rirb_get_response(bus, addr); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 722 | #ifdef CONFIG_PM |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 723 | static void azx_power_notify(struct hda_bus *bus, bool power_up); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 724 | #endif |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 725 | |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 726 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 727 | static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, |
| 728 | unsigned int byte_size, |
| 729 | struct snd_dma_buffer *bufp); |
| 730 | static void azx_load_dsp_trigger(struct hda_bus *bus, bool start); |
| 731 | static void azx_load_dsp_cleanup(struct hda_bus *bus, |
| 732 | struct snd_dma_buffer *dmab); |
| 733 | #endif |
| 734 | |
Mengdong Lin | 3af3f35 | 2013-06-24 10:18:54 -0400 | [diff] [blame] | 735 | /* enter link reset */ |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 736 | static void azx_enter_link_reset(struct azx *chip) |
Mengdong Lin | 3af3f35 | 2013-06-24 10:18:54 -0400 | [diff] [blame] | 737 | { |
| 738 | unsigned long timeout; |
| 739 | |
| 740 | /* reset controller */ |
| 741 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET); |
| 742 | |
| 743 | timeout = jiffies + msecs_to_jiffies(100); |
| 744 | while ((azx_readb(chip, GCTL) & ICH6_GCTL_RESET) && |
| 745 | time_before(jiffies, timeout)) |
| 746 | usleep_range(500, 1000); |
| 747 | } |
| 748 | |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 749 | /* exit link reset */ |
| 750 | static void azx_exit_link_reset(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Mengdong Lin | fa348da | 2012-12-12 09:16:15 -0500 | [diff] [blame] | 752 | unsigned long timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 754 | azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET); |
| 755 | |
| 756 | timeout = jiffies + msecs_to_jiffies(100); |
| 757 | while (!azx_readb(chip, GCTL) && |
| 758 | time_before(jiffies, timeout)) |
| 759 | usleep_range(500, 1000); |
| 760 | } |
| 761 | |
| 762 | /* reset codec link */ |
| 763 | static int azx_reset(struct azx *chip, int full_reset) |
| 764 | { |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 765 | if (!full_reset) |
| 766 | goto __skip; |
| 767 | |
Danny Tholen | e8a7f13 | 2007-09-11 21:41:56 +0200 | [diff] [blame] | 768 | /* clear STATESTS */ |
Wang Xingchao | da7db6a | 2013-07-22 03:19:18 -0400 | [diff] [blame] | 769 | azx_writew(chip, STATESTS, STATESTS_INT_MASK); |
Danny Tholen | e8a7f13 | 2007-09-11 21:41:56 +0200 | [diff] [blame] | 770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | /* reset controller */ |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 772 | azx_enter_link_reset(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | /* delay for >= 100us for codec PLL to settle per spec |
| 775 | * Rev 0.9 section 5.5.1 |
| 776 | */ |
Mengdong Lin | fa348da | 2012-12-12 09:16:15 -0500 | [diff] [blame] | 777 | usleep_range(500, 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | /* Bring controller out of reset */ |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 780 | azx_exit_link_reset(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 782 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ |
Mengdong Lin | fa348da | 2012-12-12 09:16:15 -0500 | [diff] [blame] | 783 | usleep_range(1000, 1200); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 785 | __skip: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | /* check to see if controller is ready */ |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 787 | if (!azx_readb(chip, GCTL)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 788 | dev_dbg(chip->card->dev, "azx_reset: controller not ready!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | return -EBUSY; |
| 790 | } |
| 791 | |
Matt | 41e2fce | 2005-07-04 17:49:55 +0200 | [diff] [blame] | 792 | /* Accept unsolicited responses */ |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 793 | if (!chip->single_cmd) |
| 794 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) | |
| 795 | ICH6_GCTL_UNSOL); |
Matt | 41e2fce | 2005-07-04 17:49:55 +0200 | [diff] [blame] | 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | /* detect codecs */ |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 798 | if (!chip->codec_mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | chip->codec_mask = azx_readw(chip, STATESTS); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 800 | dev_dbg(chip->card->dev, "codec_mask = 0x%x\n", |
| 801 | chip->codec_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | |
| 808 | /* |
| 809 | * Lowlevel interface |
| 810 | */ |
| 811 | |
| 812 | /* enable interrupts */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 813 | static void azx_int_enable(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
| 815 | /* enable controller CIE and GIE */ |
| 816 | azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) | |
| 817 | ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN); |
| 818 | } |
| 819 | |
| 820 | /* disable interrupts */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 821 | static void azx_int_disable(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
| 823 | int i; |
| 824 | |
| 825 | /* disable interrupts in stream descriptor */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 826 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 827 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 828 | azx_sd_writeb(chip, azx_dev, SD_CTL, |
| 829 | azx_sd_readb(chip, azx_dev, SD_CTL) & |
| 830 | ~SD_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* disable SIE for all streams */ |
| 834 | azx_writeb(chip, INTCTL, 0); |
| 835 | |
| 836 | /* disable controller CIE and GIE */ |
| 837 | azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) & |
| 838 | ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN)); |
| 839 | } |
| 840 | |
| 841 | /* clear interrupts */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 842 | static void azx_int_clear(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | { |
| 844 | int i; |
| 845 | |
| 846 | /* clear stream status */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 847 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 848 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 849 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /* clear STATESTS */ |
Wang Xingchao | da7db6a | 2013-07-22 03:19:18 -0400 | [diff] [blame] | 853 | azx_writew(chip, STATESTS, STATESTS_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
| 855 | /* clear rirb status */ |
| 856 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); |
| 857 | |
| 858 | /* clear int status */ |
| 859 | azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM); |
| 860 | } |
| 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | /* |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 863 | * reset and start the controller registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | */ |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 865 | static void azx_init_chip(struct azx *chip, int full_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 867 | if (chip->initialized) |
| 868 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | /* reset controller */ |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 871 | azx_reset(chip, full_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | /* initialize interrupts */ |
| 874 | azx_int_clear(chip); |
| 875 | azx_int_enable(chip); |
| 876 | |
| 877 | /* initialize the codec command I/O */ |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 878 | if (!chip->single_cmd) |
| 879 | azx_init_cmd_io(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Takashi Iwai | 0be3b5d | 2005-09-05 17:11:40 +0200 | [diff] [blame] | 881 | /* program the position buffer */ |
| 882 | azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 883 | azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr)); |
Frederick Li | f5d40b3 | 2005-05-12 14:55:20 +0200 | [diff] [blame] | 884 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 885 | chip->initialized = 1; |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | * initialize the PCI registers |
| 890 | */ |
| 891 | /* update bits in a PCI register byte */ |
| 892 | static void update_pci_byte(struct pci_dev *pci, unsigned int reg, |
| 893 | unsigned char mask, unsigned char val) |
| 894 | { |
| 895 | unsigned char data; |
| 896 | |
| 897 | pci_read_config_byte(pci, reg, &data); |
| 898 | data &= ~mask; |
| 899 | data |= (val & mask); |
| 900 | pci_write_config_byte(pci, reg, data); |
| 901 | } |
| 902 | |
| 903 | static void azx_init_pci(struct azx *chip) |
| 904 | { |
| 905 | /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) |
| 906 | * TCSEL == Traffic Class Select Register, which sets PCI express QOS |
| 907 | * Ensuring these bits are 0 clears playback static on some HD Audio |
Adam Lackorzynski | a09e89f | 2011-03-10 17:41:56 +0100 | [diff] [blame] | 908 | * codecs. |
| 909 | * The PCI register TCSEL is defined in the Intel manuals. |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 910 | */ |
Linus Torvalds | 46f2cc8 | 2011-05-27 19:45:28 -0700 | [diff] [blame] | 911 | if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 912 | dev_dbg(chip->card->dev, "Clearing TCSEL\n"); |
Adam Lackorzynski | a09e89f | 2011-03-10 17:41:56 +0100 | [diff] [blame] | 913 | update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 914 | } |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 915 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 916 | /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio, |
| 917 | * we need to enable snoop. |
| 918 | */ |
| 919 | if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 920 | dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n", |
| 921 | azx_snoop(chip)); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 922 | update_pci_byte(chip->pci, |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 923 | ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07, |
| 924 | azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /* For NVIDIA HDA, enable snoop */ |
| 928 | if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 929 | dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n", |
| 930 | azx_snoop(chip)); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 931 | update_pci_byte(chip->pci, |
| 932 | NVIDIA_HDA_TRANSREG_ADDR, |
| 933 | 0x0f, NVIDIA_HDA_ENABLE_COHBITS); |
Peer Chen | 320dcc3 | 2008-08-20 16:43:24 -0700 | [diff] [blame] | 934 | update_pci_byte(chip->pci, |
| 935 | NVIDIA_HDA_ISTRM_COH, |
| 936 | 0x01, NVIDIA_HDA_ENABLE_COHBIT); |
| 937 | update_pci_byte(chip->pci, |
| 938 | NVIDIA_HDA_OSTRM_COH, |
| 939 | 0x01, NVIDIA_HDA_ENABLE_COHBIT); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /* Enable SCH/PCH snoop if needed */ |
| 943 | if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) { |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 944 | unsigned short snoop; |
Takashi Iwai | 90a5ad5 | 2008-02-22 18:36:22 +0100 | [diff] [blame] | 945 | pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 946 | if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) || |
| 947 | (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) { |
| 948 | snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP; |
| 949 | if (!azx_snoop(chip)) |
| 950 | snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP; |
| 951 | pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop); |
Takashi Iwai | 90a5ad5 | 2008-02-22 18:36:22 +0100 | [diff] [blame] | 952 | pci_read_config_word(chip->pci, |
| 953 | INTEL_SCH_HDA_DEVC, &snoop); |
Takashi Iwai | 90a5ad5 | 2008-02-22 18:36:22 +0100 | [diff] [blame] | 954 | } |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 955 | dev_dbg(chip->card->dev, "SCH snoop: %s\n", |
| 956 | (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ? |
| 957 | "Disabled" : "Enabled"); |
Vinod G | da3fca2 | 2005-09-13 18:49:12 +0200 | [diff] [blame] | 958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 962 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev); |
| 963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | /* |
| 965 | * interrupt handler |
| 966 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 967 | static irqreturn_t azx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 969 | struct azx *chip = dev_id; |
| 970 | struct azx_dev *azx_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | u32 status; |
Clemens Ladisch | 9ef0406 | 2010-05-25 09:03:40 +0200 | [diff] [blame] | 972 | u8 sd_status; |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 973 | int i, ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 975 | #ifdef CONFIG_PM_RUNTIME |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 976 | if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME) |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 977 | if (chip->card->dev->power.runtime_status != RPM_ACTIVE) |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 978 | return IRQ_NONE; |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 979 | #endif |
| 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | spin_lock(&chip->reg_lock); |
| 982 | |
Dan Carpenter | 6091106 | 2012-05-18 10:36:11 +0300 | [diff] [blame] | 983 | if (chip->disabled) { |
| 984 | spin_unlock(&chip->reg_lock); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 985 | return IRQ_NONE; |
Dan Carpenter | 6091106 | 2012-05-18 10:36:11 +0300 | [diff] [blame] | 986 | } |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | status = azx_readl(chip, INTSTS); |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 989 | if (status == 0 || status == 0xffffffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | spin_unlock(&chip->reg_lock); |
| 991 | return IRQ_NONE; |
| 992 | } |
| 993 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 994 | for (i = 0; i < chip->num_streams; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | azx_dev = &chip->azx_dev[i]; |
| 996 | if (status & azx_dev->sd_int_sta_mask) { |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 997 | sd_status = azx_sd_readb(chip, azx_dev, SD_STS); |
| 998 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); |
Clemens Ladisch | 9ef0406 | 2010-05-25 09:03:40 +0200 | [diff] [blame] | 999 | if (!azx_dev->substream || !azx_dev->running || |
| 1000 | !(sd_status & SD_INT_COMPLETE)) |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1001 | continue; |
| 1002 | /* check whether this IRQ is really acceptable */ |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1003 | ok = azx_position_ok(chip, azx_dev); |
| 1004 | if (ok == 1) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1005 | azx_dev->irq_pending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | spin_unlock(&chip->reg_lock); |
| 1007 | snd_pcm_period_elapsed(azx_dev->substream); |
| 1008 | spin_lock(&chip->reg_lock); |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1009 | } else if (ok == 0 && chip->bus && chip->bus->workq) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1010 | /* bogus IRQ, process it later */ |
| 1011 | azx_dev->irq_pending = 1; |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 1012 | queue_work(chip->bus->workq, |
| 1013 | &chip->irq_pending_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | /* clear rirb int */ |
| 1019 | status = azx_readb(chip, RIRBSTS); |
| 1020 | if (status & RIRB_INT_MASK) { |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 1021 | if (status & RIRB_INT_RESPONSE) { |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1022 | if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY) |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 1023 | udelay(80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | azx_update_rirb(chip); |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 1025 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); |
| 1027 | } |
| 1028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | spin_unlock(&chip->reg_lock); |
| 1030 | |
| 1031 | return IRQ_HANDLED; |
| 1032 | } |
| 1033 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1034 | /* |
| 1035 | * Probe the given codec address |
| 1036 | */ |
| 1037 | static int probe_codec(struct azx *chip, int addr) |
| 1038 | { |
| 1039 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | |
| 1040 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; |
| 1041 | unsigned int res; |
| 1042 | |
Wu Fengguang | a678cde | 2009-08-01 18:46:46 +0800 | [diff] [blame] | 1043 | mutex_lock(&chip->bus->cmd_mutex); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1044 | chip->probing = 1; |
| 1045 | azx_send_cmd(chip->bus, cmd); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 1046 | res = azx_get_response(chip->bus, addr); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1047 | chip->probing = 0; |
Wu Fengguang | a678cde | 2009-08-01 18:46:46 +0800 | [diff] [blame] | 1048 | mutex_unlock(&chip->bus->cmd_mutex); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1049 | if (res == -1) |
| 1050 | return -EIO; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1051 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1052 | return 0; |
| 1053 | } |
| 1054 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1055 | static void azx_stop_chip(struct azx *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1057 | static void azx_bus_reset(struct hda_bus *bus) |
| 1058 | { |
| 1059 | struct azx *chip = bus->private_data; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1060 | |
| 1061 | bus->in_reset = 1; |
| 1062 | azx_stop_chip(chip); |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 1063 | azx_init_chip(chip, 1); |
Alexander Beregalov | 65f7598 | 2009-06-04 13:46:16 +0400 | [diff] [blame] | 1064 | #ifdef CONFIG_PM |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1065 | if (chip->initialized) { |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 1066 | struct azx_pcm *p; |
| 1067 | list_for_each_entry(p, &chip->pcm_list, list) |
| 1068 | snd_pcm_suspend_all(p->pcm); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1069 | snd_hda_suspend(chip->bus); |
| 1070 | snd_hda_resume(chip->bus); |
| 1071 | } |
Alexander Beregalov | 65f7598 | 2009-06-04 13:46:16 +0400 | [diff] [blame] | 1072 | #endif |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1073 | bus->in_reset = 0; |
| 1074 | } |
| 1075 | |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1076 | static int get_jackpoll_interval(struct azx *chip) |
| 1077 | { |
Dylan Reid | 749ee28 | 2014-02-28 15:41:18 -0800 | [diff] [blame] | 1078 | int i; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1079 | unsigned int j; |
Dylan Reid | 749ee28 | 2014-02-28 15:41:18 -0800 | [diff] [blame] | 1080 | |
| 1081 | if (!chip->jackpoll_ms) |
| 1082 | return 0; |
| 1083 | |
| 1084 | i = chip->jackpoll_ms[chip->dev_index]; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1085 | if (i == 0) |
| 1086 | return 0; |
| 1087 | if (i < 50 || i > 60000) |
| 1088 | j = 0; |
| 1089 | else |
| 1090 | j = msecs_to_jiffies(i); |
| 1091 | if (j == 0) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1092 | dev_warn(chip->card->dev, |
| 1093 | "jackpoll_ms value out of range: %d\n", i); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1094 | return j; |
| 1095 | } |
| 1096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | /* |
| 1098 | * Codec initialization |
| 1099 | */ |
| 1100 | |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame] | 1101 | static int azx_codec_create(struct azx *chip, const char *model, |
| 1102 | unsigned int max_slots, |
| 1103 | int *power_save_to) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | { |
| 1105 | struct hda_bus_template bus_temp; |
Takashi Iwai | 34c2535 | 2008-10-28 11:38:58 +0100 | [diff] [blame] | 1106 | int c, codecs, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
| 1108 | memset(&bus_temp, 0, sizeof(bus_temp)); |
| 1109 | bus_temp.private_data = chip; |
| 1110 | bus_temp.modelname = model; |
| 1111 | bus_temp.pci = chip->pci; |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 1112 | bus_temp.ops.command = azx_send_cmd; |
| 1113 | bus_temp.ops.get_response = azx_get_response; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1114 | bus_temp.ops.attach_pcm = azx_attach_pcm_stream; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1115 | bus_temp.ops.bus_reset = azx_bus_reset; |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1116 | #ifdef CONFIG_PM |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame] | 1117 | bus_temp.power_save = power_save_to; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1118 | bus_temp.ops.pm_notify = azx_power_notify; |
| 1119 | #endif |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1120 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 1121 | bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; |
| 1122 | bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; |
| 1123 | bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; |
| 1124 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1126 | err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); |
| 1127 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | return err; |
| 1129 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1130 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1131 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); |
Wei Ni | dc9c8e2 | 2008-09-26 13:55:56 +0800 | [diff] [blame] | 1132 | chip->bus->needs_damn_long_delay = 1; |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1133 | } |
Wei Ni | dc9c8e2 | 2008-09-26 13:55:56 +0800 | [diff] [blame] | 1134 | |
Takashi Iwai | 34c2535 | 2008-10-28 11:38:58 +0100 | [diff] [blame] | 1135 | codecs = 0; |
Takashi Iwai | 2f5983f | 2008-09-03 16:00:44 +0200 | [diff] [blame] | 1136 | if (!max_slots) |
Wei Ni | 7445dfc | 2010-03-03 15:05:53 +0800 | [diff] [blame] | 1137 | max_slots = AZX_DEFAULT_CODECS; |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1138 | |
| 1139 | /* First try to probe all given codec slots */ |
| 1140 | for (c = 0; c < max_slots; c++) { |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 1141 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1142 | if (probe_codec(chip, c) < 0) { |
| 1143 | /* Some BIOSen give you wrong codec addresses |
| 1144 | * that don't exist |
| 1145 | */ |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1146 | dev_warn(chip->card->dev, |
| 1147 | "Codec #%d probe error; disabling it...\n", c); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1148 | chip->codec_mask &= ~(1 << c); |
| 1149 | /* More badly, accessing to a non-existing |
| 1150 | * codec often screws up the controller chip, |
Paul Menzel | 2448158 | 2010-02-08 20:37:26 +0100 | [diff] [blame] | 1151 | * and disturbs the further communications. |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1152 | * Thus if an error occurs during probing, |
| 1153 | * better to reset the controller chip to |
| 1154 | * get back to the sanity state. |
| 1155 | */ |
| 1156 | azx_stop_chip(chip); |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 1157 | azx_init_chip(chip, 1); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
Takashi Iwai | d507cd6 | 2011-04-26 15:25:02 +0200 | [diff] [blame] | 1162 | /* AMD chipsets often cause the communication stalls upon certain |
| 1163 | * sequence like the pin-detection. It seems that forcing the synced |
| 1164 | * access works around the stall. Grrr... |
| 1165 | */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1166 | if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1167 | dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); |
Takashi Iwai | d507cd6 | 2011-04-26 15:25:02 +0200 | [diff] [blame] | 1168 | chip->bus->sync_write = 1; |
| 1169 | chip->bus->allow_bus_reset = 1; |
| 1170 | } |
| 1171 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1172 | /* Then create codec instances */ |
Takashi Iwai | 34c2535 | 2008-10-28 11:38:58 +0100 | [diff] [blame] | 1173 | for (c = 0; c < max_slots; c++) { |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 1174 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
Takashi Iwai | bccad14 | 2007-04-24 12:23:53 +0200 | [diff] [blame] | 1175 | struct hda_codec *codec; |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1176 | err = snd_hda_codec_new(chip->bus, c, &codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | if (err < 0) |
| 1178 | continue; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1179 | codec->jackpoll_interval = get_jackpoll_interval(chip); |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 1180 | codec->beep_mode = chip->beep_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | codecs++; |
Takashi Iwai | 19a982b | 2007-03-21 15:14:35 +0100 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | if (!codecs) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1185 | dev_err(chip->card->dev, "no codecs initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | return -ENXIO; |
| 1187 | } |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1191 | /* configure each codec instance */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1192 | static int azx_codec_configure(struct azx *chip) |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1193 | { |
| 1194 | struct hda_codec *codec; |
| 1195 | list_for_each_entry(codec, &chip->bus->codec_list, list) { |
| 1196 | snd_hda_codec_configure(codec); |
| 1197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1201 | /* |
| 1202 | * Check whether the current DMA position is acceptable for updating |
| 1203 | * periods. Returns non-zero if it's OK. |
| 1204 | * |
| 1205 | * Many HD-audio controllers appear pretty inaccurate about |
| 1206 | * the update-IRQ timing. The IRQ is issued before actually the |
| 1207 | * data is processed. So, we need to process it afterwords in a |
| 1208 | * workqueue. |
| 1209 | */ |
| 1210 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) |
| 1211 | { |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1212 | u32 wallclk; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1213 | unsigned int pos; |
| 1214 | |
Jaroslav Kysela | f48f606 | 2010-05-11 12:10:47 +0200 | [diff] [blame] | 1215 | wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk; |
| 1216 | if (wallclk < (azx_dev->period_wallclk * 2) / 3) |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1217 | return -1; /* bogus (too early) interrupt */ |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1218 | |
Takashi Iwai | 798cb7e | 2011-09-30 08:52:26 +0200 | [diff] [blame] | 1219 | pos = azx_get_position(chip, azx_dev, true); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1220 | |
Takashi Iwai | d6d8bf5 | 2010-02-12 18:17:06 +0100 | [diff] [blame] | 1221 | if (WARN_ONCE(!azx_dev->period_bytes, |
| 1222 | "hda-intel: zero azx_dev->period_bytes")) |
Jaroslav Kysela | f48f606 | 2010-05-11 12:10:47 +0200 | [diff] [blame] | 1223 | return -1; /* this shouldn't happen! */ |
Jaroslav Kysela | edb3993 | 2010-06-02 13:29:17 +0200 | [diff] [blame] | 1224 | if (wallclk < (azx_dev->period_wallclk * 5) / 4 && |
Jaroslav Kysela | f48f606 | 2010-05-11 12:10:47 +0200 | [diff] [blame] | 1225 | pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) |
| 1226 | /* NG - it's below the first next period boundary */ |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 1227 | return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1; |
Jaroslav Kysela | edb3993 | 2010-06-02 13:29:17 +0200 | [diff] [blame] | 1228 | azx_dev->start_wallclk += wallclk; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1229 | return 1; /* OK, it's fine */ |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * The work for pending PCM period updates. |
| 1234 | */ |
| 1235 | static void azx_irq_pending_work(struct work_struct *work) |
| 1236 | { |
| 1237 | struct azx *chip = container_of(work, struct azx, irq_pending_work); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1238 | int i, pending, ok; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1239 | |
Takashi Iwai | a6a950a | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 1240 | if (!chip->irq_pending_warned) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1241 | dev_info(chip->card->dev, |
| 1242 | "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n", |
| 1243 | chip->card->number); |
Takashi Iwai | a6a950a | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 1244 | chip->irq_pending_warned = 1; |
| 1245 | } |
| 1246 | |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1247 | for (;;) { |
| 1248 | pending = 0; |
| 1249 | spin_lock_irq(&chip->reg_lock); |
| 1250 | for (i = 0; i < chip->num_streams; i++) { |
| 1251 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
| 1252 | if (!azx_dev->irq_pending || |
| 1253 | !azx_dev->substream || |
| 1254 | !azx_dev->running) |
| 1255 | continue; |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1256 | ok = azx_position_ok(chip, azx_dev); |
| 1257 | if (ok > 0) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1258 | azx_dev->irq_pending = 0; |
| 1259 | spin_unlock(&chip->reg_lock); |
| 1260 | snd_pcm_period_elapsed(azx_dev->substream); |
| 1261 | spin_lock(&chip->reg_lock); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1262 | } else if (ok < 0) { |
| 1263 | pending = 0; /* too early */ |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1264 | } else |
| 1265 | pending++; |
| 1266 | } |
| 1267 | spin_unlock_irq(&chip->reg_lock); |
| 1268 | if (!pending) |
| 1269 | return; |
Takashi Iwai | 08af495 | 2010-08-03 14:39:04 +0200 | [diff] [blame] | 1270 | msleep(1); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /* clear irq_pending flags and assure no on-going workq */ |
| 1275 | static void azx_clear_irq_pending(struct azx *chip) |
| 1276 | { |
| 1277 | int i; |
| 1278 | |
| 1279 | spin_lock_irq(&chip->reg_lock); |
| 1280 | for (i = 0; i < chip->num_streams; i++) |
| 1281 | chip->azx_dev[i].irq_pending = 0; |
| 1282 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | /* |
| 1286 | * mixer creation - all stuff is implemented in hda module |
| 1287 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1288 | static int azx_mixer_create(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | { |
| 1290 | return snd_hda_build_controls(chip->bus); |
| 1291 | } |
| 1292 | |
| 1293 | |
| 1294 | /* |
| 1295 | * initialize SD streams |
| 1296 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1297 | static int azx_init_stream(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | { |
| 1299 | int i; |
| 1300 | |
| 1301 | /* initialize each stream (aka device) |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1302 | * assign the starting bdl address to each stream (device) |
| 1303 | * and initialize |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 1305 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1306 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
Takashi Iwai | 929861c | 2006-08-31 16:55:40 +0200 | [diff] [blame] | 1307 | azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ |
| 1309 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); |
| 1310 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ |
| 1311 | azx_dev->sd_int_sta_mask = 1 << i; |
| 1312 | /* stream tag: must be non-zero and unique */ |
| 1313 | azx_dev->index = i; |
| 1314 | azx_dev->stream_tag = i + 1; |
| 1315 | } |
| 1316 | |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 1320 | static int azx_acquire_irq(struct azx *chip, int do_disconnect) |
| 1321 | { |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 1322 | if (request_irq(chip->pci->irq, azx_interrupt, |
| 1323 | chip->msi ? 0 : IRQF_SHARED, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 1324 | KBUILD_MODNAME, chip)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1325 | dev_err(chip->card->dev, |
| 1326 | "unable to grab IRQ %d, disabling device\n", |
| 1327 | chip->pci->irq); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 1328 | if (do_disconnect) |
| 1329 | snd_card_disconnect(chip->card); |
| 1330 | return -1; |
| 1331 | } |
| 1332 | chip->irq = chip->pci->irq; |
Takashi Iwai | 69e1341 | 2006-11-21 12:10:55 +0100 | [diff] [blame] | 1333 | pci_intx(chip->pci, !chip->msi); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 1334 | return 0; |
| 1335 | } |
| 1336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1338 | static void azx_stop_chip(struct azx *chip) |
| 1339 | { |
Takashi Iwai | 95e99fd | 2007-08-13 15:29:04 +0200 | [diff] [blame] | 1340 | if (!chip->initialized) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1341 | return; |
| 1342 | |
| 1343 | /* disable interrupts */ |
| 1344 | azx_int_disable(chip); |
| 1345 | azx_int_clear(chip); |
| 1346 | |
| 1347 | /* disable CORB/RIRB */ |
| 1348 | azx_free_cmd_io(chip); |
| 1349 | |
| 1350 | /* disable position buffer */ |
| 1351 | azx_writel(chip, DPLBASE, 0); |
| 1352 | azx_writel(chip, DPUBASE, 0); |
| 1353 | |
| 1354 | chip->initialized = 0; |
| 1355 | } |
| 1356 | |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1357 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 1358 | /* |
| 1359 | * DSP loading code (e.g. for CA0132) |
| 1360 | */ |
| 1361 | |
| 1362 | /* use the first stream for loading DSP */ |
| 1363 | static struct azx_dev * |
| 1364 | azx_get_dsp_loader_dev(struct azx *chip) |
| 1365 | { |
| 1366 | return &chip->azx_dev[chip->playback_index_offset]; |
| 1367 | } |
| 1368 | |
| 1369 | static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, |
| 1370 | unsigned int byte_size, |
| 1371 | struct snd_dma_buffer *bufp) |
| 1372 | { |
| 1373 | u32 *bdl; |
| 1374 | struct azx *chip = bus->private_data; |
| 1375 | struct azx_dev *azx_dev; |
| 1376 | int err; |
| 1377 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1378 | azx_dev = azx_get_dsp_loader_dev(chip); |
| 1379 | |
| 1380 | dsp_lock(azx_dev); |
| 1381 | spin_lock_irq(&chip->reg_lock); |
| 1382 | if (azx_dev->running || azx_dev->locked) { |
| 1383 | spin_unlock_irq(&chip->reg_lock); |
| 1384 | err = -EBUSY; |
| 1385 | goto unlock; |
| 1386 | } |
| 1387 | azx_dev->prepared = 0; |
| 1388 | chip->saved_azx_dev = *azx_dev; |
| 1389 | azx_dev->locked = 1; |
| 1390 | spin_unlock_irq(&chip->reg_lock); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1391 | |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 1392 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV_SG, |
| 1393 | byte_size, bufp); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1394 | if (err < 0) |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1395 | goto err_alloc; |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1396 | |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1397 | azx_dev->bufsize = byte_size; |
| 1398 | azx_dev->period_bytes = byte_size; |
| 1399 | azx_dev->format_val = format; |
| 1400 | |
| 1401 | azx_stream_reset(chip, azx_dev); |
| 1402 | |
| 1403 | /* reset BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1404 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); |
| 1405 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1406 | |
| 1407 | azx_dev->frags = 0; |
| 1408 | bdl = (u32 *)azx_dev->bdl.area; |
| 1409 | err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0); |
| 1410 | if (err < 0) |
| 1411 | goto error; |
| 1412 | |
| 1413 | azx_setup_controller(chip, azx_dev); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1414 | dsp_unlock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1415 | return azx_dev->stream_tag; |
| 1416 | |
| 1417 | error: |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 1418 | chip->ops->dma_free_pages(chip, bufp); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1419 | err_alloc: |
| 1420 | spin_lock_irq(&chip->reg_lock); |
| 1421 | if (azx_dev->opened) |
| 1422 | *azx_dev = chip->saved_azx_dev; |
| 1423 | azx_dev->locked = 0; |
| 1424 | spin_unlock_irq(&chip->reg_lock); |
| 1425 | unlock: |
| 1426 | dsp_unlock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1427 | return err; |
| 1428 | } |
| 1429 | |
| 1430 | static void azx_load_dsp_trigger(struct hda_bus *bus, bool start) |
| 1431 | { |
| 1432 | struct azx *chip = bus->private_data; |
| 1433 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
| 1434 | |
| 1435 | if (start) |
| 1436 | azx_stream_start(chip, azx_dev); |
| 1437 | else |
| 1438 | azx_stream_stop(chip, azx_dev); |
| 1439 | azx_dev->running = start; |
| 1440 | } |
| 1441 | |
| 1442 | static void azx_load_dsp_cleanup(struct hda_bus *bus, |
| 1443 | struct snd_dma_buffer *dmab) |
| 1444 | { |
| 1445 | struct azx *chip = bus->private_data; |
| 1446 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
| 1447 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1448 | if (!dmab->area || !azx_dev->locked) |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 1449 | return; |
| 1450 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1451 | dsp_lock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1452 | /* reset BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1453 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); |
| 1454 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); |
| 1455 | azx_sd_writel(chip, azx_dev, SD_CTL, 0); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1456 | azx_dev->bufsize = 0; |
| 1457 | azx_dev->period_bytes = 0; |
| 1458 | azx_dev->format_val = 0; |
| 1459 | |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 1460 | chip->ops->dma_free_pages(chip, dmab); |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 1461 | dmab->area = NULL; |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1462 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1463 | spin_lock_irq(&chip->reg_lock); |
| 1464 | if (azx_dev->opened) |
| 1465 | *azx_dev = chip->saved_azx_dev; |
| 1466 | azx_dev->locked = 0; |
| 1467 | spin_unlock_irq(&chip->reg_lock); |
| 1468 | dsp_unlock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1469 | } |
| 1470 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ |
| 1471 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1472 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1473 | /* power-up/down the controller */ |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 1474 | static void azx_power_notify(struct hda_bus *bus, bool power_up) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1475 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 1476 | struct azx *chip = bus->private_data; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1477 | |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 1478 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 1479 | return; |
| 1480 | |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 1481 | if (power_up) |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1482 | pm_runtime_get_sync(chip->card->dev); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1483 | else |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1484 | pm_runtime_put_sync(chip->card->dev); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1485 | } |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 1486 | |
| 1487 | static DEFINE_MUTEX(card_list_lock); |
| 1488 | static LIST_HEAD(card_list); |
| 1489 | |
| 1490 | static void azx_add_card_list(struct azx *chip) |
| 1491 | { |
| 1492 | mutex_lock(&card_list_lock); |
| 1493 | list_add(&chip->list, &card_list); |
| 1494 | mutex_unlock(&card_list_lock); |
| 1495 | } |
| 1496 | |
| 1497 | static void azx_del_card_list(struct azx *chip) |
| 1498 | { |
| 1499 | mutex_lock(&card_list_lock); |
| 1500 | list_del_init(&chip->list); |
| 1501 | mutex_unlock(&card_list_lock); |
| 1502 | } |
| 1503 | |
| 1504 | /* trigger power-save check at writing parameter */ |
| 1505 | static int param_set_xint(const char *val, const struct kernel_param *kp) |
| 1506 | { |
| 1507 | struct azx *chip; |
| 1508 | struct hda_codec *c; |
| 1509 | int prev = power_save; |
| 1510 | int ret = param_set_int(val, kp); |
| 1511 | |
| 1512 | if (ret || prev == power_save) |
| 1513 | return ret; |
| 1514 | |
| 1515 | mutex_lock(&card_list_lock); |
| 1516 | list_for_each_entry(chip, &card_list, list) { |
| 1517 | if (!chip->bus || chip->disabled) |
| 1518 | continue; |
| 1519 | list_for_each_entry(c, &chip->bus->codec_list, list) |
| 1520 | snd_hda_power_sync(c); |
| 1521 | } |
| 1522 | mutex_unlock(&card_list_lock); |
| 1523 | return 0; |
| 1524 | } |
| 1525 | #else |
| 1526 | #define azx_add_card_list(chip) /* NOP */ |
| 1527 | #define azx_del_card_list(chip) /* NOP */ |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1528 | #endif /* CONFIG_PM */ |
Takashi Iwai | 5c0b9be | 2008-12-11 11:47:17 +0100 | [diff] [blame] | 1529 | |
Takashi Iwai | 7ccbde5 | 2012-08-14 18:10:09 +0200 | [diff] [blame] | 1530 | #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO) |
Takashi Iwai | 5c0b9be | 2008-12-11 11:47:17 +0100 | [diff] [blame] | 1531 | /* |
| 1532 | * power management |
| 1533 | */ |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1534 | static int azx_suspend(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1536 | struct pci_dev *pci = to_pci_dev(dev); |
| 1537 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 1538 | struct azx *chip = card->private_data; |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 1539 | struct azx_pcm *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Takashi Iwai | c5c2152 | 2012-12-04 17:01:25 +0100 | [diff] [blame] | 1541 | if (chip->disabled) |
| 1542 | return 0; |
| 1543 | |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 1544 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1545 | azx_clear_irq_pending(chip); |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 1546 | list_for_each_entry(p, &chip->pcm_list, list) |
| 1547 | snd_pcm_suspend_all(p->pcm); |
Takashi Iwai | 0b7a2e9 | 2007-08-14 15:18:26 +0200 | [diff] [blame] | 1548 | if (chip->initialized) |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1549 | snd_hda_suspend(chip->bus); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1550 | azx_stop_chip(chip); |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 1551 | azx_enter_link_reset(chip); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1552 | if (chip->irq >= 0) { |
Takashi Iwai | 43001c9 | 2006-09-08 12:30:03 +0200 | [diff] [blame] | 1553 | free_irq(chip->irq, chip); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1554 | chip->irq = -1; |
| 1555 | } |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 1556 | if (chip->msi) |
Takashi Iwai | 43001c9 | 2006-09-08 12:30:03 +0200 | [diff] [blame] | 1557 | pci_disable_msi(chip->pci); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 1558 | pci_disable_device(pci); |
| 1559 | pci_save_state(pci); |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1560 | pci_set_power_state(pci, PCI_D3hot); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 1561 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 1562 | hda_display_power(false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | return 0; |
| 1564 | } |
| 1565 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1566 | static int azx_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1568 | struct pci_dev *pci = to_pci_dev(dev); |
| 1569 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 1570 | struct azx *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Takashi Iwai | c5c2152 | 2012-12-04 17:01:25 +0100 | [diff] [blame] | 1572 | if (chip->disabled) |
| 1573 | return 0; |
| 1574 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 1575 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 1576 | hda_display_power(true); |
Takashi Iwai | d14a7e0 | 2009-02-16 10:13:03 +0100 | [diff] [blame] | 1577 | pci_set_power_state(pci, PCI_D0); |
| 1578 | pci_restore_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1579 | if (pci_enable_device(pci) < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1580 | dev_err(chip->card->dev, |
| 1581 | "pci_enable_device failed, disabling device\n"); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1582 | snd_card_disconnect(card); |
| 1583 | return -EIO; |
| 1584 | } |
| 1585 | pci_set_master(pci); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 1586 | if (chip->msi) |
| 1587 | if (pci_enable_msi(pci) < 0) |
| 1588 | chip->msi = 0; |
| 1589 | if (azx_acquire_irq(chip, 1) < 0) |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1590 | return -EIO; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1591 | azx_init_pci(chip); |
Maxim Levitsky | d804ad9 | 2007-09-03 15:28:04 +0200 | [diff] [blame] | 1592 | |
Takashi Iwai | 7f30830 | 2012-05-08 16:52:23 +0200 | [diff] [blame] | 1593 | azx_init_chip(chip, 1); |
Maxim Levitsky | d804ad9 | 2007-09-03 15:28:04 +0200 | [diff] [blame] | 1594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | snd_hda_resume(chip->bus); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 1596 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | return 0; |
| 1598 | } |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1599 | #endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */ |
| 1600 | |
| 1601 | #ifdef CONFIG_PM_RUNTIME |
| 1602 | static int azx_runtime_suspend(struct device *dev) |
| 1603 | { |
| 1604 | struct snd_card *card = dev_get_drvdata(dev); |
| 1605 | struct azx *chip = card->private_data; |
| 1606 | |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1607 | if (chip->disabled) |
| 1608 | return 0; |
| 1609 | |
| 1610 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 1611 | return 0; |
| 1612 | |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 1613 | /* enable controller wake up event */ |
| 1614 | azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) | |
| 1615 | STATESTS_INT_MASK); |
| 1616 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1617 | azx_stop_chip(chip); |
Takashi Iwai | 873ce8a | 2013-11-26 11:58:40 +0100 | [diff] [blame] | 1618 | azx_enter_link_reset(chip); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1619 | azx_clear_irq_pending(chip); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 1620 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 1621 | hda_display_power(false); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1622 | return 0; |
| 1623 | } |
| 1624 | |
| 1625 | static int azx_runtime_resume(struct device *dev) |
| 1626 | { |
| 1627 | struct snd_card *card = dev_get_drvdata(dev); |
| 1628 | struct azx *chip = card->private_data; |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 1629 | struct hda_bus *bus; |
| 1630 | struct hda_codec *codec; |
| 1631 | int status; |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1632 | |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1633 | if (chip->disabled) |
| 1634 | return 0; |
| 1635 | |
| 1636 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 1637 | return 0; |
| 1638 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 1639 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 1640 | hda_display_power(true); |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 1641 | |
| 1642 | /* Read STATESTS before controller reset */ |
| 1643 | status = azx_readw(chip, STATESTS); |
| 1644 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1645 | azx_init_pci(chip); |
| 1646 | azx_init_chip(chip, 1); |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 1647 | |
| 1648 | bus = chip->bus; |
| 1649 | if (status && bus) { |
| 1650 | list_for_each_entry(codec, &bus->codec_list, list) |
| 1651 | if (status & (1 << codec->addr)) |
| 1652 | queue_delayed_work(codec->bus->workq, |
| 1653 | &codec->jackpoll_work, codec->jackpoll_interval); |
| 1654 | } |
| 1655 | |
| 1656 | /* disable controller Wake Up event*/ |
| 1657 | azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & |
| 1658 | ~STATESTS_INT_MASK); |
| 1659 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1660 | return 0; |
| 1661 | } |
Takashi Iwai | 6eb827d | 2012-12-12 11:50:12 +0100 | [diff] [blame] | 1662 | |
| 1663 | static int azx_runtime_idle(struct device *dev) |
| 1664 | { |
| 1665 | struct snd_card *card = dev_get_drvdata(dev); |
| 1666 | struct azx *chip = card->private_data; |
| 1667 | |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1668 | if (chip->disabled) |
| 1669 | return 0; |
| 1670 | |
Takashi Iwai | 6eb827d | 2012-12-12 11:50:12 +0100 | [diff] [blame] | 1671 | if (!power_save_controller || |
| 1672 | !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 1673 | return -EBUSY; |
| 1674 | |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1678 | #endif /* CONFIG_PM_RUNTIME */ |
| 1679 | |
| 1680 | #ifdef CONFIG_PM |
| 1681 | static const struct dev_pm_ops azx_pm = { |
| 1682 | SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) |
Takashi Iwai | 6eb827d | 2012-12-12 11:50:12 +0100 | [diff] [blame] | 1683 | SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle) |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1684 | }; |
| 1685 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1686 | #define AZX_PM_OPS &azx_pm |
| 1687 | #else |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 1688 | #define AZX_PM_OPS NULL |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1689 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
| 1691 | |
| 1692 | /* |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 1693 | * reboot notifier for hang-up problem at power-down |
| 1694 | */ |
| 1695 | static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) |
| 1696 | { |
| 1697 | struct azx *chip = container_of(nb, struct azx, reboot_notifier); |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 1698 | snd_hda_bus_reboot_notify(chip->bus); |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 1699 | azx_stop_chip(chip); |
| 1700 | return NOTIFY_OK; |
| 1701 | } |
| 1702 | |
| 1703 | static void azx_notifier_register(struct azx *chip) |
| 1704 | { |
| 1705 | chip->reboot_notifier.notifier_call = azx_halt; |
| 1706 | register_reboot_notifier(&chip->reboot_notifier); |
| 1707 | } |
| 1708 | |
| 1709 | static void azx_notifier_unregister(struct azx *chip) |
| 1710 | { |
| 1711 | if (chip->reboot_notifier.notifier_call) |
| 1712 | unregister_reboot_notifier(&chip->reboot_notifier); |
| 1713 | } |
| 1714 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 1715 | static int azx_probe_continue(struct azx *chip); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1716 | |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 1717 | #ifdef SUPPORT_VGA_SWITCHEROO |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1718 | static struct pci_dev *get_bound_vga(struct pci_dev *pci); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1719 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1720 | static void azx_vs_set_state(struct pci_dev *pci, |
| 1721 | enum vga_switcheroo_state state) |
| 1722 | { |
| 1723 | struct snd_card *card = pci_get_drvdata(pci); |
| 1724 | struct azx *chip = card->private_data; |
| 1725 | bool disabled; |
| 1726 | |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 1727 | wait_for_completion(&chip->probe_wait); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1728 | if (chip->init_failed) |
| 1729 | return; |
| 1730 | |
| 1731 | disabled = (state == VGA_SWITCHEROO_OFF); |
| 1732 | if (chip->disabled == disabled) |
| 1733 | return; |
| 1734 | |
| 1735 | if (!chip->bus) { |
| 1736 | chip->disabled = disabled; |
| 1737 | if (!disabled) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1738 | dev_info(chip->card->dev, |
| 1739 | "Start delayed initialization\n"); |
Takashi Iwai | 5c90680 | 2013-05-30 22:07:09 +0800 | [diff] [blame] | 1740 | if (azx_probe_continue(chip) < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1741 | dev_err(chip->card->dev, "initialization error\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1742 | chip->init_failed = true; |
| 1743 | } |
| 1744 | } |
| 1745 | } else { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1746 | dev_info(chip->card->dev, "%s via VGA-switcheroo\n", |
| 1747 | disabled ? "Disabling" : "Enabling"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1748 | if (disabled) { |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1749 | pm_runtime_put_sync_suspend(card->dev); |
| 1750 | azx_suspend(card->dev); |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1751 | /* when we get suspended by vga switcheroo we end up in D3cold, |
| 1752 | * however we have no ACPI handle, so pci/acpi can't put us there, |
| 1753 | * put ourselves there */ |
| 1754 | pci->current_state = PCI_D3cold; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1755 | chip->disabled = true; |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 1756 | if (snd_hda_lock_devices(chip->bus)) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1757 | dev_warn(chip->card->dev, |
| 1758 | "Cannot lock devices!\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1759 | } else { |
| 1760 | snd_hda_unlock_devices(chip->bus); |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1761 | pm_runtime_get_noresume(card->dev); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1762 | chip->disabled = false; |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1763 | azx_resume(card->dev); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | static bool azx_vs_can_switch(struct pci_dev *pci) |
| 1769 | { |
| 1770 | struct snd_card *card = pci_get_drvdata(pci); |
| 1771 | struct azx *chip = card->private_data; |
| 1772 | |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 1773 | wait_for_completion(&chip->probe_wait); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1774 | if (chip->init_failed) |
| 1775 | return false; |
| 1776 | if (chip->disabled || !chip->bus) |
| 1777 | return true; |
| 1778 | if (snd_hda_lock_devices(chip->bus)) |
| 1779 | return false; |
| 1780 | snd_hda_unlock_devices(chip->bus); |
| 1781 | return true; |
| 1782 | } |
| 1783 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1784 | static void init_vga_switcheroo(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1785 | { |
| 1786 | struct pci_dev *p = get_bound_vga(chip->pci); |
| 1787 | if (p) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1788 | dev_info(chip->card->dev, |
| 1789 | "Handle VGA-switcheroo audio client\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1790 | chip->use_vga_switcheroo = 1; |
| 1791 | pci_dev_put(p); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | static const struct vga_switcheroo_client_ops azx_vs_ops = { |
| 1796 | .set_gpu_state = azx_vs_set_state, |
| 1797 | .can_switch = azx_vs_can_switch, |
| 1798 | }; |
| 1799 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1800 | static int register_vga_switcheroo(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1801 | { |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 1802 | int err; |
| 1803 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1804 | if (!chip->use_vga_switcheroo) |
| 1805 | return 0; |
| 1806 | /* FIXME: currently only handling DIS controller |
| 1807 | * is there any machine with two switchable HDMI audio controllers? |
| 1808 | */ |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 1809 | err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1810 | VGA_SWITCHEROO_DIS, |
| 1811 | chip->bus != NULL); |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 1812 | if (err < 0) |
| 1813 | return err; |
| 1814 | chip->vga_switcheroo_registered = 1; |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1815 | |
| 1816 | /* register as an optimus hdmi audio power domain */ |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1817 | vga_switcheroo_init_domain_pm_optimus_hdmi_audio(chip->card->dev, |
| 1818 | &chip->hdmi_pm_domain); |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 1819 | return 0; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1820 | } |
| 1821 | #else |
| 1822 | #define init_vga_switcheroo(chip) /* NOP */ |
| 1823 | #define register_vga_switcheroo(chip) 0 |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 1824 | #define check_hdmi_disabled(pci) false |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1825 | #endif /* SUPPORT_VGA_SWITCHER */ |
| 1826 | |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 1827 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | * destructor |
| 1829 | */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1830 | static int azx_free(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | { |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 1832 | struct pci_dev *pci = chip->pci; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1833 | int i; |
| 1834 | |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 1835 | if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) |
| 1836 | && chip->running) |
| 1837 | pm_runtime_get_noresume(&pci->dev); |
| 1838 | |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 1839 | azx_del_card_list(chip); |
| 1840 | |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 1841 | azx_notifier_unregister(chip); |
| 1842 | |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 1843 | chip->init_failed = 1; /* to be sure */ |
Daniel J Blueman | 44728e9 | 2012-12-18 23:59:33 +0800 | [diff] [blame] | 1844 | complete_all(&chip->probe_wait); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 1845 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1846 | if (use_vga_switcheroo(chip)) { |
| 1847 | if (chip->disabled && chip->bus) |
| 1848 | snd_hda_unlock_devices(chip->bus); |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 1849 | if (chip->vga_switcheroo_registered) |
| 1850 | vga_switcheroo_unregister_client(chip->pci); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1851 | } |
| 1852 | |
Takashi Iwai | ce43fba | 2005-05-30 20:33:44 +0200 | [diff] [blame] | 1853 | if (chip->initialized) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1854 | azx_clear_irq_pending(chip); |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 1855 | for (i = 0; i < chip->num_streams; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | azx_stream_stop(chip, &chip->azx_dev[i]); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1857 | azx_stop_chip(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Jeff Garzik | f000fd8 | 2008-04-22 13:50:34 +0200 | [diff] [blame] | 1860 | if (chip->irq >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | free_irq(chip->irq, (void*)chip); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 1862 | if (chip->msi) |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1863 | pci_disable_msi(chip->pci); |
Takashi Iwai | f079c25 | 2006-06-01 11:42:14 +0200 | [diff] [blame] | 1864 | if (chip->remap_addr) |
| 1865 | iounmap(chip->remap_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1867 | if (chip->azx_dev) { |
| 1868 | for (i = 0; i < chip->num_streams; i++) |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 1869 | if (chip->azx_dev[i].bdl.area) |
| 1870 | chip->ops->dma_free_pages( |
| 1871 | chip, &chip->azx_dev[i].bdl); |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1872 | } |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 1873 | if (chip->rb.area) |
| 1874 | chip->ops->dma_free_pages(chip, &chip->rb); |
| 1875 | if (chip->posbuf.area) |
| 1876 | chip->ops->dma_free_pages(chip, &chip->posbuf); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1877 | if (chip->region_requested) |
| 1878 | pci_release_regions(chip->pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | pci_disable_device(chip->pci); |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 1880 | kfree(chip->azx_dev); |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 1881 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 1882 | if (chip->fw) |
| 1883 | release_firmware(chip->fw); |
| 1884 | #endif |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 1885 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
| 1886 | hda_display_power(false); |
| 1887 | hda_i915_exit(); |
| 1888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | kfree(chip); |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1894 | static int azx_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | { |
| 1896 | return azx_free(device->device_data); |
| 1897 | } |
| 1898 | |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 1899 | #ifdef SUPPORT_VGA_SWITCHEROO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | /* |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 1901 | * Check of disabled HDMI controller by vga-switcheroo |
| 1902 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1903 | static struct pci_dev *get_bound_vga(struct pci_dev *pci) |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 1904 | { |
| 1905 | struct pci_dev *p; |
| 1906 | |
| 1907 | /* check only discrete GPU */ |
| 1908 | switch (pci->vendor) { |
| 1909 | case PCI_VENDOR_ID_ATI: |
| 1910 | case PCI_VENDOR_ID_AMD: |
| 1911 | case PCI_VENDOR_ID_NVIDIA: |
| 1912 | if (pci->devfn == 1) { |
| 1913 | p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus), |
| 1914 | pci->bus->number, 0); |
| 1915 | if (p) { |
| 1916 | if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA) |
| 1917 | return p; |
| 1918 | pci_dev_put(p); |
| 1919 | } |
| 1920 | } |
| 1921 | break; |
| 1922 | } |
| 1923 | return NULL; |
| 1924 | } |
| 1925 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1926 | static bool check_hdmi_disabled(struct pci_dev *pci) |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 1927 | { |
| 1928 | bool vga_inactive = false; |
| 1929 | struct pci_dev *p = get_bound_vga(pci); |
| 1930 | |
| 1931 | if (p) { |
Takashi Iwai | 12b78a7 | 2012-06-07 12:15:16 +0200 | [diff] [blame] | 1932 | if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF) |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 1933 | vga_inactive = true; |
| 1934 | pci_dev_put(p); |
| 1935 | } |
| 1936 | return vga_inactive; |
| 1937 | } |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 1938 | #endif /* SUPPORT_VGA_SWITCHEROO */ |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 1939 | |
| 1940 | /* |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 1941 | * white/black-listing for position_fix |
| 1942 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1943 | static struct snd_pci_quirk position_fix_list[] = { |
Takashi Iwai | d2e1c97 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 1944 | SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), |
| 1945 | SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), |
Takashi Iwai | 2f703e7 | 2009-12-01 14:17:37 +0100 | [diff] [blame] | 1946 | SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB), |
Takashi Iwai | d2e1c97 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 1947 | SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), |
Daniel T Chen | dd37f8e | 2010-05-30 01:17:03 -0400 | [diff] [blame] | 1948 | SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB), |
Daniel T Chen | 9f75c1b | 2010-05-30 13:08:41 -0400 | [diff] [blame] | 1949 | SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB), |
Daniel T Chen | e96d312 | 2010-05-27 18:32:18 -0400 | [diff] [blame] | 1950 | SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB), |
David Henningsson | b01de4f | 2012-01-12 16:31:14 +0100 | [diff] [blame] | 1951 | SND_PCI_QUIRK(0x10de, 0xcb89, "Macbook Pro 7,1", POS_FIX_LPIB), |
Daniel T Chen | 61bb42c | 2010-05-29 11:04:11 -0400 | [diff] [blame] | 1952 | SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB), |
Daniel T Chen | 9ec8dda | 2010-03-28 02:34:40 -0400 | [diff] [blame] | 1953 | SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB), |
Takashi Iwai | 45d4ebf | 2009-11-30 11:58:30 +0100 | [diff] [blame] | 1954 | SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB), |
Takashi Iwai | 8815cd0 | 2010-04-15 09:02:41 +0200 | [diff] [blame] | 1955 | SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB), |
Daniel T Chen | b90c076 | 2010-05-30 19:31:41 -0400 | [diff] [blame] | 1956 | SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB), |
Daniel T Chen | 0e0280d | 2010-04-21 19:55:43 -0400 | [diff] [blame] | 1957 | SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB), |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 1958 | {} |
| 1959 | }; |
| 1960 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1961 | static int check_position_fix(struct azx *chip, int fix) |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 1962 | { |
| 1963 | const struct snd_pci_quirk *q; |
| 1964 | |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 1965 | switch (fix) { |
Takashi Iwai | 1dac669 | 2012-09-13 14:59:47 +0200 | [diff] [blame] | 1966 | case POS_FIX_AUTO: |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 1967 | case POS_FIX_LPIB: |
| 1968 | case POS_FIX_POSBUF: |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 1969 | case POS_FIX_VIACOMBO: |
Takashi Iwai | a6f2fd5 | 2012-02-28 11:58:40 +0100 | [diff] [blame] | 1970 | case POS_FIX_COMBO: |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 1971 | return fix; |
| 1972 | } |
| 1973 | |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 1974 | q = snd_pci_quirk_lookup(chip->pci, position_fix_list); |
| 1975 | if (q) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1976 | dev_info(chip->card->dev, |
| 1977 | "position_fix set to %d for device %04x:%04x\n", |
| 1978 | q->value, q->subvendor, q->subdevice); |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 1979 | return q->value; |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 1980 | } |
David Henningsson | bdd9ef2 | 2010-10-04 12:02:14 +0200 | [diff] [blame] | 1981 | |
| 1982 | /* Check VIA/ATI HD Audio Controller exist */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1983 | if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1984 | dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n"); |
David Henningsson | bdd9ef2 | 2010-10-04 12:02:14 +0200 | [diff] [blame] | 1985 | return POS_FIX_VIACOMBO; |
| 1986 | } |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1987 | if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1988 | dev_dbg(chip->card->dev, "Using LPIB position fix\n"); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1989 | return POS_FIX_LPIB; |
| 1990 | } |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 1991 | return POS_FIX_AUTO; |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /* |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 1995 | * black-lists for probe_mask |
| 1996 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1997 | static struct snd_pci_quirk probe_mask_list[] = { |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 1998 | /* Thinkpad often breaks the controller communication when accessing |
| 1999 | * to the non-working (or non-existing) modem codec slot. |
| 2000 | */ |
| 2001 | SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01), |
| 2002 | SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01), |
| 2003 | SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01), |
Takashi Iwai | 0edb945 | 2008-11-07 14:53:09 +0100 | [diff] [blame] | 2004 | /* broken BIOS */ |
| 2005 | SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01), |
Takashi Iwai | ef1681d | 2008-11-24 17:29:28 +0100 | [diff] [blame] | 2006 | /* including bogus ALC268 in slot#2 that conflicts with ALC888 */ |
| 2007 | SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01), |
Takashi Iwai | 20db7cb | 2009-02-13 08:18:48 +0100 | [diff] [blame] | 2008 | /* forced codec slots */ |
Ozan Çağlayan | 9357484 | 2009-05-23 15:00:04 +0300 | [diff] [blame] | 2009 | SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), |
Takashi Iwai | 20db7cb | 2009-02-13 08:18:48 +0100 | [diff] [blame] | 2010 | SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), |
Jaroslav Kysela | f3af905 | 2012-04-26 17:52:35 +0200 | [diff] [blame] | 2011 | /* WinFast VP200 H (Teradici) user reported broken communication */ |
| 2012 | SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101), |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2013 | {} |
| 2014 | }; |
| 2015 | |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 2016 | #define AZX_FORCE_CODEC_MASK 0x100 |
| 2017 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2018 | static void check_probe_mask(struct azx *chip, int dev) |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2019 | { |
| 2020 | const struct snd_pci_quirk *q; |
| 2021 | |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 2022 | chip->codec_probe_mask = probe_mask[dev]; |
| 2023 | if (chip->codec_probe_mask == -1) { |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2024 | q = snd_pci_quirk_lookup(chip->pci, probe_mask_list); |
| 2025 | if (q) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2026 | dev_info(chip->card->dev, |
| 2027 | "probe_mask set to 0x%x for device %04x:%04x\n", |
| 2028 | q->value, q->subvendor, q->subdevice); |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 2029 | chip->codec_probe_mask = q->value; |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2030 | } |
| 2031 | } |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 2032 | |
| 2033 | /* check forced option */ |
| 2034 | if (chip->codec_probe_mask != -1 && |
| 2035 | (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { |
| 2036 | chip->codec_mask = chip->codec_probe_mask & 0xff; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2037 | dev_info(chip->card->dev, "codec_mask forced to 0x%x\n", |
| 2038 | chip->codec_mask); |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 2039 | } |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2040 | } |
| 2041 | |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2042 | /* |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 2043 | * white/black-list for enable_msi |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2044 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2045 | static struct snd_pci_quirk msi_black_list[] = { |
David Henningsson | 693e0cb | 2013-12-12 09:52:03 +0100 | [diff] [blame] | 2046 | SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */ |
| 2047 | SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */ |
| 2048 | SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */ |
| 2049 | SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */ |
Takashi Iwai | 9dc8398 | 2009-12-22 08:15:01 +0100 | [diff] [blame] | 2050 | SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */ |
Takashi Iwai | 0a27fcf | 2010-02-15 17:05:28 +0100 | [diff] [blame] | 2051 | SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */ |
Ralf Gerbig | ecd2162 | 2010-03-09 18:25:47 +0100 | [diff] [blame] | 2052 | SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */ |
Takashi Iwai | 83f7215 | 2013-09-09 10:20:48 +0200 | [diff] [blame] | 2053 | SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */ |
Michele Ballabio | 4193d13 | 2010-03-06 21:06:46 +0100 | [diff] [blame] | 2054 | SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */ |
Takashi Iwai | 3815595 | 2010-04-04 12:14:03 +0200 | [diff] [blame] | 2055 | SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */ |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2056 | {} |
| 2057 | }; |
| 2058 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2059 | static void check_msi(struct azx *chip) |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2060 | { |
| 2061 | const struct snd_pci_quirk *q; |
| 2062 | |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 2063 | if (enable_msi >= 0) { |
| 2064 | chip->msi = !!enable_msi; |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2065 | return; |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 2066 | } |
| 2067 | chip->msi = 1; /* enable MSI as default */ |
| 2068 | q = snd_pci_quirk_lookup(chip->pci, msi_black_list); |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2069 | if (q) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2070 | dev_info(chip->card->dev, |
| 2071 | "msi for device %04x:%04x set to %d\n", |
| 2072 | q->subvendor, q->subdevice, q->value); |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2073 | chip->msi = q->value; |
Takashi Iwai | 80c43ed | 2010-03-15 15:51:53 +0100 | [diff] [blame] | 2074 | return; |
| 2075 | } |
| 2076 | |
| 2077 | /* NVidia chipsets seem to cause troubles with MSI */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2078 | if (chip->driver_caps & AZX_DCAPS_NO_MSI) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2079 | dev_info(chip->card->dev, "Disabling MSI\n"); |
Takashi Iwai | 80c43ed | 2010-03-15 15:51:53 +0100 | [diff] [blame] | 2080 | chip->msi = 0; |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 2084 | /* check the snoop mode availability */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2085 | static void azx_check_snoop_available(struct azx *chip) |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 2086 | { |
| 2087 | bool snoop = chip->snoop; |
| 2088 | |
| 2089 | switch (chip->driver_type) { |
| 2090 | case AZX_DRIVER_VIA: |
| 2091 | /* force to non-snoop mode for a new VIA controller |
| 2092 | * when BIOS is set |
| 2093 | */ |
| 2094 | if (snoop) { |
| 2095 | u8 val; |
| 2096 | pci_read_config_byte(chip->pci, 0x42, &val); |
| 2097 | if (!(val & 0x80) && chip->pci->revision == 0x30) |
| 2098 | snoop = false; |
| 2099 | } |
| 2100 | break; |
| 2101 | case AZX_DRIVER_ATIHDMI_NS: |
| 2102 | /* new ATI HDMI requires non-snoop */ |
| 2103 | snoop = false; |
| 2104 | break; |
Takashi Iwai | c1279f8 | 2013-02-07 17:36:22 +0100 | [diff] [blame] | 2105 | case AZX_DRIVER_CTHDA: |
| 2106 | snoop = false; |
| 2107 | break; |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | if (snoop != chip->snoop) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2111 | dev_info(chip->card->dev, "Force to %s mode\n", |
| 2112 | snoop ? "snoop" : "non-snoop"); |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 2113 | chip->snoop = snoop; |
| 2114 | } |
| 2115 | } |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2116 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2117 | static void azx_probe_work(struct work_struct *work) |
| 2118 | { |
| 2119 | azx_probe_continue(container_of(work, struct azx, probe_work)); |
| 2120 | } |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2121 | |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 2122 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | * constructor |
| 2124 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2125 | static int azx_create(struct snd_card *card, struct pci_dev *pci, |
| 2126 | int dev, unsigned int driver_caps, |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2127 | const struct hda_controller_ops *hda_ops, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2128 | struct azx **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2130 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | .dev_free = azx_dev_free, |
| 2132 | }; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2133 | struct azx *chip; |
| 2134 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | |
| 2136 | *rchip = NULL; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2137 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2138 | err = pci_enable_device(pci); |
| 2139 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | return err; |
| 2141 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 2142 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2143 | if (!chip) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2144 | dev_err(card->dev, "Cannot allocate chip\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | pci_disable_device(pci); |
| 2146 | return -ENOMEM; |
| 2147 | } |
| 2148 | |
| 2149 | spin_lock_init(&chip->reg_lock); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2150 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | chip->card = card; |
| 2152 | chip->pci = pci; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2153 | chip->ops = hda_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | chip->irq = -1; |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2155 | chip->driver_caps = driver_caps; |
| 2156 | chip->driver_type = driver_caps & 0xff; |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 2157 | check_msi(chip); |
Takashi Iwai | 555e219 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 2158 | chip->dev_index = dev; |
Dylan Reid | 749ee28 | 2014-02-28 15:41:18 -0800 | [diff] [blame] | 2159 | chip->jackpoll_ms = jackpoll_ms; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2160 | INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2161 | INIT_LIST_HEAD(&chip->pcm_list); |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 2162 | INIT_LIST_HEAD(&chip->list); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2163 | init_vga_switcheroo(chip); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2164 | init_completion(&chip->probe_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | |
Shahin Ghazinouri | beaffc3 | 2010-05-11 08:19:55 +0200 | [diff] [blame] | 2166 | chip->position_fix[0] = chip->position_fix[1] = |
| 2167 | check_position_fix(chip, position_fix[dev]); |
Takashi Iwai | a6f2fd5 | 2012-02-28 11:58:40 +0100 | [diff] [blame] | 2168 | /* combo mode uses LPIB for playback */ |
| 2169 | if (chip->position_fix[0] == POS_FIX_COMBO) { |
| 2170 | chip->position_fix[0] = POS_FIX_LPIB; |
| 2171 | chip->position_fix[1] = POS_FIX_AUTO; |
| 2172 | } |
| 2173 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 2174 | check_probe_mask(chip, dev); |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 2175 | |
Takashi Iwai | 2734616 | 2006-01-12 18:28:44 +0100 | [diff] [blame] | 2176 | chip->single_cmd = single_cmd; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2177 | chip->snoop = hda_snoop; |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 2178 | azx_check_snoop_available(chip); |
Takashi Iwai | c74db86 | 2005-05-12 14:26:27 +0200 | [diff] [blame] | 2179 | |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 2180 | if (bdl_pos_adj[dev] < 0) { |
| 2181 | switch (chip->driver_type) { |
Takashi Iwai | 0c6341a | 2008-06-13 20:50:27 +0200 | [diff] [blame] | 2182 | case AZX_DRIVER_ICH: |
Seth Heasley | 32679f9 | 2010-02-22 17:31:09 -0800 | [diff] [blame] | 2183 | case AZX_DRIVER_PCH: |
Takashi Iwai | 0c6341a | 2008-06-13 20:50:27 +0200 | [diff] [blame] | 2184 | bdl_pos_adj[dev] = 1; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 2185 | break; |
| 2186 | default: |
Takashi Iwai | 0c6341a | 2008-06-13 20:50:27 +0200 | [diff] [blame] | 2187 | bdl_pos_adj[dev] = 32; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 2188 | break; |
| 2189 | } |
| 2190 | } |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 2191 | chip->bdl_pos_adj = bdl_pos_adj; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 2192 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2193 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
| 2194 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2195 | dev_err(card->dev, "Error creating device [card]!\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2196 | azx_free(chip); |
| 2197 | return err; |
| 2198 | } |
| 2199 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2200 | /* continue probing in work context as may trigger request module */ |
| 2201 | INIT_WORK(&chip->probe_work, azx_probe_work); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2202 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2203 | *rchip = chip; |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2204 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2205 | return 0; |
| 2206 | } |
| 2207 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 2208 | static int azx_first_init(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2209 | { |
| 2210 | int dev = chip->dev_index; |
| 2211 | struct pci_dev *pci = chip->pci; |
| 2212 | struct snd_card *card = chip->card; |
| 2213 | int i, err; |
| 2214 | unsigned short gcap; |
| 2215 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2216 | #if BITS_PER_LONG != 64 |
| 2217 | /* Fix up base address on ULI M5461 */ |
| 2218 | if (chip->driver_type == AZX_DRIVER_ULI) { |
| 2219 | u16 tmp3; |
| 2220 | pci_read_config_word(pci, 0x40, &tmp3); |
| 2221 | pci_write_config_word(pci, 0x40, tmp3 | 0x10); |
| 2222 | pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0); |
| 2223 | } |
| 2224 | #endif |
| 2225 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2226 | err = pci_request_regions(pci, "ICH HD audio"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2227 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | return err; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2229 | chip->region_requested = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2231 | chip->addr = pci_resource_start(pci, 0); |
Arjan van de Ven | 2f5ad54 | 2008-09-28 16:20:09 -0700 | [diff] [blame] | 2232 | chip->remap_addr = pci_ioremap_bar(pci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | if (chip->remap_addr == NULL) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2234 | dev_err(card->dev, "ioremap error\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2235 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2238 | if (chip->msi) |
| 2239 | if (pci_enable_msi(pci) < 0) |
| 2240 | chip->msi = 0; |
Stephen Hemminger | 7376d01 | 2006-08-21 19:17:46 +0200 | [diff] [blame] | 2241 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2242 | if (azx_acquire_irq(chip, 0) < 0) |
| 2243 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | |
| 2245 | pci_set_master(pci); |
| 2246 | synchronize_irq(chip->irq); |
| 2247 | |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2248 | gcap = azx_readw(chip, GCAP); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2249 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2250 | |
Andiry Brienza | dc4c2e6 | 2009-07-08 13:55:31 +0800 | [diff] [blame] | 2251 | /* disable SB600 64bit support for safety */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2252 | if (chip->pci->vendor == PCI_VENDOR_ID_ATI) { |
Andiry Brienza | dc4c2e6 | 2009-07-08 13:55:31 +0800 | [diff] [blame] | 2253 | struct pci_dev *p_smbus; |
| 2254 | p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, |
| 2255 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, |
| 2256 | NULL); |
| 2257 | if (p_smbus) { |
| 2258 | if (p_smbus->revision < 0x30) |
| 2259 | gcap &= ~ICH6_GCAP_64OK; |
| 2260 | pci_dev_put(p_smbus); |
| 2261 | } |
| 2262 | } |
Takashi Iwai | 09240cf | 2009-03-17 07:47:18 +0100 | [diff] [blame] | 2263 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2264 | /* disable 64bit DMA address on some devices */ |
| 2265 | if (chip->driver_caps & AZX_DCAPS_NO_64BIT) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2266 | dev_dbg(card->dev, "Disabling 64bit DMA\n"); |
Jaroslav Kysela | 396087e | 2009-12-09 10:44:47 +0100 | [diff] [blame] | 2267 | gcap &= ~ICH6_GCAP_64OK; |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2268 | } |
Jaroslav Kysela | 396087e | 2009-12-09 10:44:47 +0100 | [diff] [blame] | 2269 | |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2270 | /* disable buffer size rounding to 128-byte multiples if supported */ |
Takashi Iwai | 7bfe059 | 2012-01-23 17:53:39 +0100 | [diff] [blame] | 2271 | if (align_buffer_size >= 0) |
| 2272 | chip->align_buffer_size = !!align_buffer_size; |
| 2273 | else { |
| 2274 | if (chip->driver_caps & AZX_DCAPS_BUFSIZE) |
| 2275 | chip->align_buffer_size = 0; |
| 2276 | else if (chip->driver_caps & AZX_DCAPS_ALIGN_BUFSIZE) |
| 2277 | chip->align_buffer_size = 1; |
| 2278 | else |
| 2279 | chip->align_buffer_size = 1; |
| 2280 | } |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2281 | |
Takashi Iwai | cf7aaca | 2008-02-06 15:05:57 +0100 | [diff] [blame] | 2282 | /* allow 64bit DMA address if supported by H/W */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 2283 | if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2284 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); |
Takashi Iwai | 09240cf | 2009-03-17 07:47:18 +0100 | [diff] [blame] | 2285 | else { |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 2286 | pci_set_dma_mask(pci, DMA_BIT_MASK(32)); |
| 2287 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)); |
Takashi Iwai | 09240cf | 2009-03-17 07:47:18 +0100 | [diff] [blame] | 2288 | } |
Takashi Iwai | cf7aaca | 2008-02-06 15:05:57 +0100 | [diff] [blame] | 2289 | |
Takashi Iwai | 8b6ed8e | 2008-02-19 11:36:35 +0100 | [diff] [blame] | 2290 | /* read number of streams from GCAP register instead of using |
| 2291 | * hardcoded value |
| 2292 | */ |
| 2293 | chip->capture_streams = (gcap >> 8) & 0x0f; |
| 2294 | chip->playback_streams = (gcap >> 12) & 0x0f; |
| 2295 | if (!chip->playback_streams && !chip->capture_streams) { |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2296 | /* gcap didn't give any info, switching to old method */ |
| 2297 | |
| 2298 | switch (chip->driver_type) { |
| 2299 | case AZX_DRIVER_ULI: |
| 2300 | chip->playback_streams = ULI_NUM_PLAYBACK; |
| 2301 | chip->capture_streams = ULI_NUM_CAPTURE; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2302 | break; |
| 2303 | case AZX_DRIVER_ATIHDMI: |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 2304 | case AZX_DRIVER_ATIHDMI_NS: |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2305 | chip->playback_streams = ATIHDMI_NUM_PLAYBACK; |
| 2306 | chip->capture_streams = ATIHDMI_NUM_CAPTURE; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2307 | break; |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 2308 | case AZX_DRIVER_GENERIC: |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2309 | default: |
| 2310 | chip->playback_streams = ICH6_NUM_PLAYBACK; |
| 2311 | chip->capture_streams = ICH6_NUM_CAPTURE; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 2312 | break; |
| 2313 | } |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2314 | } |
Takashi Iwai | 8b6ed8e | 2008-02-19 11:36:35 +0100 | [diff] [blame] | 2315 | chip->capture_index_offset = 0; |
| 2316 | chip->playback_index_offset = chip->capture_streams; |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2317 | chip->num_streams = chip->playback_streams + chip->capture_streams; |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 2318 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), |
| 2319 | GFP_KERNEL); |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2320 | if (!chip->azx_dev) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2321 | dev_err(card->dev, "cannot malloc azx_dev\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2322 | return -ENOMEM; |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2323 | } |
| 2324 | |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2325 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2326 | dsp_lock_init(&chip->azx_dev[i]); |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2327 | /* allocate memory for the BDL for each stream */ |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 2328 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, |
| 2329 | BDL_SIZE, |
| 2330 | &chip->azx_dev[i].bdl); |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2331 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2332 | dev_err(card->dev, "cannot allocate BDL\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2333 | return -ENOMEM; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2334 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | } |
Takashi Iwai | 0be3b5d | 2005-09-05 17:11:40 +0200 | [diff] [blame] | 2336 | /* allocate memory for the position buffer */ |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 2337 | err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV, |
| 2338 | chip->num_streams * 8, &chip->posbuf); |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 2339 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2340 | dev_err(card->dev, "cannot allocate posbuf\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2341 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | /* allocate CORB/RIRB */ |
Takashi Iwai | 8174086 | 2009-05-26 15:22:00 +0200 | [diff] [blame] | 2344 | err = azx_alloc_cmd_io(chip); |
| 2345 | if (err < 0) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2346 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | |
| 2348 | /* initialize streams */ |
| 2349 | azx_init_stream(chip); |
| 2350 | |
| 2351 | /* initialize chip */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2352 | azx_init_pci(chip); |
Jaroslav Kysela | 10e77dd | 2010-03-26 11:04:38 +0100 | [diff] [blame] | 2353 | azx_init_chip(chip, (probe_only[dev] & 2) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | |
| 2355 | /* codec detection */ |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2356 | if (!chip->codec_mask) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2357 | dev_err(card->dev, "no codecs found!\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2358 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2361 | strcpy(card->driver, "HDA-Intel"); |
Takashi Iwai | 18cb710 | 2009-04-16 10:22:24 +0200 | [diff] [blame] | 2362 | strlcpy(card->shortname, driver_short_names[chip->driver_type], |
| 2363 | sizeof(card->shortname)); |
| 2364 | snprintf(card->longname, sizeof(card->longname), |
| 2365 | "%s at 0x%lx irq %i", |
| 2366 | card->shortname, chip->addr, chip->irq); |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2371 | static void power_down_all_codecs(struct azx *chip) |
| 2372 | { |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 2373 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2374 | /* The codecs were powered up in snd_hda_codec_new(). |
| 2375 | * Now all initialization done, so turn them down if possible |
| 2376 | */ |
| 2377 | struct hda_codec *codec; |
| 2378 | list_for_each_entry(codec, &chip->bus->codec_list, list) { |
| 2379 | snd_hda_power_down(codec); |
| 2380 | } |
| 2381 | #endif |
| 2382 | } |
| 2383 | |
Takashi Iwai | 97c6a3d | 2012-08-09 17:40:46 +0200 | [diff] [blame] | 2384 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 2385 | /* callback from request_firmware_nowait() */ |
| 2386 | static void azx_firmware_cb(const struct firmware *fw, void *context) |
| 2387 | { |
| 2388 | struct snd_card *card = context; |
| 2389 | struct azx *chip = card->private_data; |
| 2390 | struct pci_dev *pci = chip->pci; |
| 2391 | |
| 2392 | if (!fw) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2393 | dev_err(card->dev, "Cannot load firmware, aborting\n"); |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 2394 | goto error; |
| 2395 | } |
| 2396 | |
| 2397 | chip->fw = fw; |
| 2398 | if (!chip->disabled) { |
| 2399 | /* continue probing */ |
| 2400 | if (azx_probe_continue(chip)) |
| 2401 | goto error; |
| 2402 | } |
| 2403 | return; /* OK */ |
| 2404 | |
| 2405 | error: |
| 2406 | snd_card_free(card); |
| 2407 | pci_set_drvdata(pci, NULL); |
| 2408 | } |
Takashi Iwai | 97c6a3d | 2012-08-09 17:40:46 +0200 | [diff] [blame] | 2409 | #endif |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 2410 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2411 | /* |
| 2412 | * HDA controller ops. |
| 2413 | */ |
| 2414 | |
| 2415 | /* PCI register access. */ |
| 2416 | static void pci_azx_writel(u32 value, u32 *addr) |
| 2417 | { |
| 2418 | writel(value, addr); |
| 2419 | } |
| 2420 | |
| 2421 | static u32 pci_azx_readl(u32 *addr) |
| 2422 | { |
| 2423 | return readl(addr); |
| 2424 | } |
| 2425 | |
| 2426 | static void pci_azx_writew(u16 value, u16 *addr) |
| 2427 | { |
| 2428 | writew(value, addr); |
| 2429 | } |
| 2430 | |
| 2431 | static u16 pci_azx_readw(u16 *addr) |
| 2432 | { |
| 2433 | return readw(addr); |
| 2434 | } |
| 2435 | |
| 2436 | static void pci_azx_writeb(u8 value, u8 *addr) |
| 2437 | { |
| 2438 | writeb(value, addr); |
| 2439 | } |
| 2440 | |
| 2441 | static u8 pci_azx_readb(u8 *addr) |
| 2442 | { |
| 2443 | return readb(addr); |
| 2444 | } |
| 2445 | |
Dylan Reid | f46ea60 | 2014-02-28 15:41:16 -0800 | [diff] [blame] | 2446 | static int disable_msi_reset_irq(struct azx *chip) |
| 2447 | { |
| 2448 | int err; |
| 2449 | |
| 2450 | free_irq(chip->irq, chip); |
| 2451 | chip->irq = -1; |
| 2452 | pci_disable_msi(chip->pci); |
| 2453 | chip->msi = 0; |
| 2454 | err = azx_acquire_irq(chip, 1); |
| 2455 | if (err < 0) |
| 2456 | return err; |
| 2457 | |
| 2458 | return 0; |
| 2459 | } |
| 2460 | |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 2461 | /* DMA page allocation helpers. */ |
| 2462 | static int dma_alloc_pages(struct azx *chip, |
| 2463 | int type, |
| 2464 | size_t size, |
| 2465 | struct snd_dma_buffer *buf) |
| 2466 | { |
| 2467 | int err; |
| 2468 | |
| 2469 | err = snd_dma_alloc_pages(type, |
| 2470 | chip->card->dev, |
| 2471 | size, buf); |
| 2472 | if (err < 0) |
| 2473 | return err; |
| 2474 | mark_pages_wc(chip, buf, true); |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
| 2478 | static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf) |
| 2479 | { |
| 2480 | mark_pages_wc(chip, buf, false); |
| 2481 | snd_dma_free_pages(buf); |
| 2482 | } |
| 2483 | |
| 2484 | static int substream_alloc_pages(struct azx *chip, |
| 2485 | struct snd_pcm_substream *substream, |
| 2486 | size_t size) |
| 2487 | { |
| 2488 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 2489 | int ret; |
| 2490 | |
| 2491 | mark_runtime_wc(chip, azx_dev, substream, false); |
| 2492 | azx_dev->bufsize = 0; |
| 2493 | azx_dev->period_bytes = 0; |
| 2494 | azx_dev->format_val = 0; |
| 2495 | ret = snd_pcm_lib_malloc_pages(substream, size); |
| 2496 | if (ret < 0) |
| 2497 | return ret; |
| 2498 | mark_runtime_wc(chip, azx_dev, substream, true); |
| 2499 | return 0; |
| 2500 | } |
| 2501 | |
| 2502 | static int substream_free_pages(struct azx *chip, |
| 2503 | struct snd_pcm_substream *substream) |
| 2504 | { |
| 2505 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 2506 | mark_runtime_wc(chip, azx_dev, substream, false); |
| 2507 | return snd_pcm_lib_free_pages(substream); |
| 2508 | } |
| 2509 | |
Dylan Reid | 8769b278 | 2014-02-28 15:41:21 -0800 | [diff] [blame] | 2510 | static void pcm_mmap_prepare(struct snd_pcm_substream *substream, |
| 2511 | struct vm_area_struct *area) |
| 2512 | { |
| 2513 | #ifdef CONFIG_X86 |
| 2514 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 2515 | struct azx *chip = apcm->chip; |
| 2516 | if (!azx_snoop(chip)) |
| 2517 | area->vm_page_prot = pgprot_writecombine(area->vm_page_prot); |
| 2518 | #endif |
| 2519 | } |
| 2520 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2521 | static const struct hda_controller_ops pci_hda_ops = { |
| 2522 | .writel = pci_azx_writel, |
| 2523 | .readl = pci_azx_readl, |
| 2524 | .writew = pci_azx_writew, |
| 2525 | .readw = pci_azx_readw, |
| 2526 | .writeb = pci_azx_writeb, |
| 2527 | .readb = pci_azx_readb, |
Dylan Reid | f46ea60 | 2014-02-28 15:41:16 -0800 | [diff] [blame] | 2528 | .disable_msi_reset_irq = disable_msi_reset_irq, |
Dylan Reid | b419b35 | 2014-02-28 15:41:20 -0800 | [diff] [blame] | 2529 | .dma_alloc_pages = dma_alloc_pages, |
| 2530 | .dma_free_pages = dma_free_pages, |
| 2531 | .substream_alloc_pages = substream_alloc_pages, |
| 2532 | .substream_free_pages = substream_free_pages, |
Dylan Reid | 8769b278 | 2014-02-28 15:41:21 -0800 | [diff] [blame] | 2533 | .pcm_mmap_prepare = pcm_mmap_prepare, |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2534 | }; |
| 2535 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2536 | static int azx_probe(struct pci_dev *pci, |
| 2537 | const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | { |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 2539 | static int dev; |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2540 | struct snd_card *card; |
| 2541 | struct azx *chip; |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 2542 | bool schedule_probe; |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 2543 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 2545 | if (dev >= SNDRV_CARDS) |
| 2546 | return -ENODEV; |
| 2547 | if (!enable[dev]) { |
| 2548 | dev++; |
| 2549 | return -ENOENT; |
| 2550 | } |
| 2551 | |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 2552 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 2553 | 0, &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 2554 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2555 | dev_err(&pci->dev, "Error creating card!\n"); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 2556 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2559 | err = azx_create(card, pci, dev, pci_id->driver_data, |
| 2560 | &pci_hda_ops, &chip); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2561 | if (err < 0) |
| 2562 | goto out_free; |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 2563 | card->private_data = chip; |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2564 | |
| 2565 | pci_set_drvdata(pci, card); |
| 2566 | |
| 2567 | err = register_vga_switcheroo(chip); |
| 2568 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2569 | dev_err(card->dev, "Error registering VGA-switcheroo client\n"); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2570 | goto out_free; |
| 2571 | } |
| 2572 | |
| 2573 | if (check_hdmi_disabled(pci)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2574 | dev_info(card->dev, "VGA controller is disabled\n"); |
| 2575 | dev_info(card->dev, "Delaying initialization\n"); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2576 | chip->disabled = true; |
| 2577 | } |
| 2578 | |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 2579 | schedule_probe = !chip->disabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 2581 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 2582 | if (patch[dev] && *patch[dev]) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2583 | dev_info(card->dev, "Applying patch firmware '%s'\n", |
| 2584 | patch[dev]); |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 2585 | err = request_firmware_nowait(THIS_MODULE, true, patch[dev], |
| 2586 | &pci->dev, GFP_KERNEL, card, |
| 2587 | azx_firmware_cb); |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 2588 | if (err < 0) |
| 2589 | goto out_free; |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 2590 | schedule_probe = false; /* continued in azx_firmware_cb() */ |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 2591 | } |
| 2592 | #endif /* CONFIG_SND_HDA_PATCH_LOADER */ |
| 2593 | |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 2594 | #ifndef CONFIG_SND_HDA_I915 |
| 2595 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2596 | dev_err(card->dev, "Haswell must build in CONFIG_SND_HDA_I915\n"); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2597 | #endif |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2598 | |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 2599 | if (schedule_probe) |
| 2600 | schedule_work(&chip->probe_work); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2601 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2602 | dev++; |
Takashi Iwai | 88d071f | 2013-12-02 11:12:28 +0100 | [diff] [blame] | 2603 | if (chip->disabled) |
| 2604 | complete_all(&chip->probe_wait); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2605 | return 0; |
| 2606 | |
| 2607 | out_free: |
| 2608 | snd_card_free(card); |
| 2609 | return err; |
| 2610 | } |
| 2611 | |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame] | 2612 | /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ |
| 2613 | static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = { |
| 2614 | [AZX_DRIVER_NVIDIA] = 8, |
| 2615 | [AZX_DRIVER_TERA] = 1, |
| 2616 | }; |
| 2617 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 2618 | static int azx_probe_continue(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2619 | { |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 2620 | struct pci_dev *pci = chip->pci; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2621 | int dev = chip->dev_index; |
| 2622 | int err; |
| 2623 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2624 | /* Request power well for Haswell HDA controller and codec */ |
| 2625 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
David Henningsson | c841ad2 | 2013-08-19 13:32:30 +0200 | [diff] [blame] | 2626 | #ifdef CONFIG_SND_HDA_I915 |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2627 | err = hda_i915_init(); |
| 2628 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2629 | dev_err(chip->card->dev, |
| 2630 | "Error request power-well from i915\n"); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2631 | goto out_free; |
| 2632 | } |
David Henningsson | c841ad2 | 2013-08-19 13:32:30 +0200 | [diff] [blame] | 2633 | #endif |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2634 | hda_display_power(true); |
| 2635 | } |
| 2636 | |
Takashi Iwai | 5c90680 | 2013-05-30 22:07:09 +0800 | [diff] [blame] | 2637 | err = azx_first_init(chip); |
| 2638 | if (err < 0) |
| 2639 | goto out_free; |
| 2640 | |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 2641 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 2642 | chip->beep_mode = beep_mode[dev]; |
| 2643 | #endif |
| 2644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | /* create codec instances */ |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame] | 2646 | err = azx_codec_create(chip, model[dev], |
| 2647 | azx_max_codecs[chip->driver_type], |
| 2648 | power_save_addr); |
| 2649 | |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2650 | if (err < 0) |
| 2651 | goto out_free; |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 2652 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 2653 | if (chip->fw) { |
| 2654 | err = snd_hda_load_patch(chip->bus, chip->fw->size, |
| 2655 | chip->fw->data); |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 2656 | if (err < 0) |
| 2657 | goto out_free; |
Takashi Iwai | e39ae85 | 2012-11-22 16:18:13 +0100 | [diff] [blame] | 2658 | #ifndef CONFIG_PM |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 2659 | release_firmware(chip->fw); /* no longer needed */ |
| 2660 | chip->fw = NULL; |
Takashi Iwai | e39ae85 | 2012-11-22 16:18:13 +0100 | [diff] [blame] | 2661 | #endif |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 2662 | } |
| 2663 | #endif |
Jaroslav Kysela | 10e77dd | 2010-03-26 11:04:38 +0100 | [diff] [blame] | 2664 | if ((probe_only[dev] & 1) == 0) { |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 2665 | err = azx_codec_configure(chip); |
| 2666 | if (err < 0) |
| 2667 | goto out_free; |
| 2668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | |
| 2670 | /* create PCM streams */ |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2671 | err = snd_hda_build_pcms(chip->bus); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2672 | if (err < 0) |
| 2673 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | |
| 2675 | /* create mixer controls */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 2676 | err = azx_mixer_create(chip); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2677 | if (err < 0) |
| 2678 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2680 | err = snd_card_register(chip->card); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2681 | if (err < 0) |
| 2682 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2684 | chip->running = 1; |
| 2685 | power_down_all_codecs(chip); |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 2686 | azx_notifier_register(chip); |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 2687 | azx_add_card_list(chip); |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 2688 | if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || chip->use_vga_switcheroo) |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 2689 | pm_runtime_put_noidle(&pci->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2691 | out_free: |
Takashi Iwai | 88d071f | 2013-12-02 11:12:28 +0100 | [diff] [blame] | 2692 | if (err < 0) |
| 2693 | chip->init_failed = 1; |
| 2694 | complete_all(&chip->probe_wait); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 2695 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2698 | static void azx_remove(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | { |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2700 | struct snd_card *card = pci_get_drvdata(pci); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2701 | |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2702 | if (card) |
| 2703 | snd_card_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | /* PCI IDs */ |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 2707 | static DEFINE_PCI_DEVICE_TABLE(azx_ids) = { |
Seth Heasley | d2f2fcd | 2010-01-12 17:03:35 -0800 | [diff] [blame] | 2708 | /* CPT */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2709 | { PCI_DEVICE(0x8086, 0x1c20), |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 2710 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Seth Heasley | cea310e | 2010-09-10 16:29:56 -0700 | [diff] [blame] | 2711 | /* PBG */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2712 | { PCI_DEVICE(0x8086, 0x1d20), |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 2713 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Seth Heasley | d2edeb7 | 2011-04-20 10:59:57 -0700 | [diff] [blame] | 2714 | /* Panther Point */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2715 | { PCI_DEVICE(0x8086, 0x1e20), |
Takashi Iwai | b1920c2 | 2013-11-22 12:43:25 +0100 | [diff] [blame] | 2716 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
Seth Heasley | 8bc039a | 2012-01-23 16:24:31 -0800 | [diff] [blame] | 2717 | /* Lynx Point */ |
| 2718 | { PCI_DEVICE(0x8086, 0x8c20), |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 2719 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 884b088 | 2013-02-08 17:29:40 -0800 | [diff] [blame] | 2720 | /* Wellsburg */ |
| 2721 | { PCI_DEVICE(0x8086, 0x8d20), |
| 2722 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
| 2723 | { PCI_DEVICE(0x8086, 0x8d21), |
| 2724 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 144dad9 | 2012-08-09 09:38:59 -0700 | [diff] [blame] | 2725 | /* Lynx Point-LP */ |
| 2726 | { PCI_DEVICE(0x8086, 0x9c20), |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 2727 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 144dad9 | 2012-08-09 09:38:59 -0700 | [diff] [blame] | 2728 | /* Lynx Point-LP */ |
| 2729 | { PCI_DEVICE(0x8086, 0x9c21), |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 2730 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 4eeca49 | 2013-11-04 09:27:45 -0800 | [diff] [blame] | 2731 | /* Wildcat Point-LP */ |
| 2732 | { PCI_DEVICE(0x8086, 0x9ca0), |
| 2733 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
Wang Xingchao | e926f2c | 2012-06-13 10:23:51 +0800 | [diff] [blame] | 2734 | /* Haswell */ |
Wang Xingchao | 4a7c516 | 2013-02-01 22:42:19 +0800 | [diff] [blame] | 2735 | { PCI_DEVICE(0x8086, 0x0a0c), |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 2736 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Wang Xingchao | e926f2c | 2012-06-13 10:23:51 +0800 | [diff] [blame] | 2737 | { PCI_DEVICE(0x8086, 0x0c0c), |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 2738 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Wang Xingchao | d279fae | 2012-09-17 13:10:23 +0800 | [diff] [blame] | 2739 | { PCI_DEVICE(0x8086, 0x0d0c), |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 2740 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Mengdong Lin | 862d761 | 2014-01-08 15:55:14 -0500 | [diff] [blame] | 2741 | /* Broadwell */ |
| 2742 | { PCI_DEVICE(0x8086, 0x160c), |
| 2743 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Pierre-Louis Bossart | 99df18b | 2012-09-21 18:39:07 -0500 | [diff] [blame] | 2744 | /* 5 Series/3400 */ |
| 2745 | { PCI_DEVICE(0x8086, 0x3b56), |
Takashi Iwai | 2c1350f | 2013-02-14 09:44:55 +0100 | [diff] [blame] | 2746 | .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Takashi Iwai | f748abc | 2013-01-29 10:12:23 +0100 | [diff] [blame] | 2747 | /* Poulsbo */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2748 | { PCI_DEVICE(0x8086, 0x811b), |
Takashi Iwai | f748abc | 2013-01-29 10:12:23 +0100 | [diff] [blame] | 2749 | .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
| 2750 | /* Oaktrail */ |
Li Peng | 09904b9 | 2011-12-28 15:17:26 +0000 | [diff] [blame] | 2751 | { PCI_DEVICE(0x8086, 0x080a), |
Takashi Iwai | f748abc | 2013-01-29 10:12:23 +0100 | [diff] [blame] | 2752 | .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Chew, Chiau Ee | e44007e | 2013-05-16 15:36:12 +0800 | [diff] [blame] | 2753 | /* BayTrail */ |
| 2754 | { PCI_DEVICE(0x8086, 0x0f04), |
| 2755 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
David Henningsson | 645e903 | 2011-12-14 15:52:30 +0800 | [diff] [blame] | 2756 | /* ICH */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2757 | { PCI_DEVICE(0x8086, 0x2668), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2758 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2759 | AZX_DCAPS_BUFSIZE }, /* ICH6 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2760 | { PCI_DEVICE(0x8086, 0x27d8), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2761 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2762 | AZX_DCAPS_BUFSIZE }, /* ICH7 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2763 | { PCI_DEVICE(0x8086, 0x269a), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2764 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2765 | AZX_DCAPS_BUFSIZE }, /* ESB2 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2766 | { PCI_DEVICE(0x8086, 0x284b), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2767 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2768 | AZX_DCAPS_BUFSIZE }, /* ICH8 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2769 | { PCI_DEVICE(0x8086, 0x293e), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2770 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2771 | AZX_DCAPS_BUFSIZE }, /* ICH9 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2772 | { PCI_DEVICE(0x8086, 0x293f), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2773 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2774 | AZX_DCAPS_BUFSIZE }, /* ICH9 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2775 | { PCI_DEVICE(0x8086, 0x3a3e), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2776 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2777 | AZX_DCAPS_BUFSIZE }, /* ICH10 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 2778 | { PCI_DEVICE(0x8086, 0x3a6e), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2779 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 2780 | AZX_DCAPS_BUFSIZE }, /* ICH10 */ |
Takashi Iwai | b686453 | 2010-09-15 10:17:26 +0200 | [diff] [blame] | 2781 | /* Generic Intel */ |
| 2782 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID), |
| 2783 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 2784 | .class_mask = 0xffffff, |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 2785 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_BUFSIZE }, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2786 | /* ATI SB 450/600/700/800/900 */ |
| 2787 | { PCI_DEVICE(0x1002, 0x437b), |
| 2788 | .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB }, |
| 2789 | { PCI_DEVICE(0x1002, 0x4383), |
| 2790 | .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB }, |
| 2791 | /* AMD Hudson */ |
| 2792 | { PCI_DEVICE(0x1022, 0x780d), |
| 2793 | .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB }, |
Takashi Iwai | 87218e9 | 2008-02-21 08:13:11 +0100 | [diff] [blame] | 2794 | /* ATI HDMI */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2795 | { PCI_DEVICE(0x1002, 0x793b), |
| 2796 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2797 | { PCI_DEVICE(0x1002, 0x7919), |
| 2798 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2799 | { PCI_DEVICE(0x1002, 0x960f), |
| 2800 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2801 | { PCI_DEVICE(0x1002, 0x970f), |
| 2802 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2803 | { PCI_DEVICE(0x1002, 0xaa00), |
| 2804 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2805 | { PCI_DEVICE(0x1002, 0xaa08), |
| 2806 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2807 | { PCI_DEVICE(0x1002, 0xaa10), |
| 2808 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2809 | { PCI_DEVICE(0x1002, 0xaa18), |
| 2810 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2811 | { PCI_DEVICE(0x1002, 0xaa20), |
| 2812 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2813 | { PCI_DEVICE(0x1002, 0xaa28), |
| 2814 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2815 | { PCI_DEVICE(0x1002, 0xaa30), |
| 2816 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2817 | { PCI_DEVICE(0x1002, 0xaa38), |
| 2818 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2819 | { PCI_DEVICE(0x1002, 0xaa40), |
| 2820 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2821 | { PCI_DEVICE(0x1002, 0xaa48), |
| 2822 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
Clemens Ladisch | bbaa0d6 | 2013-11-05 09:27:10 +0100 | [diff] [blame] | 2823 | { PCI_DEVICE(0x1002, 0xaa50), |
| 2824 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2825 | { PCI_DEVICE(0x1002, 0xaa58), |
| 2826 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2827 | { PCI_DEVICE(0x1002, 0xaa60), |
| 2828 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2829 | { PCI_DEVICE(0x1002, 0xaa68), |
| 2830 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2831 | { PCI_DEVICE(0x1002, 0xaa80), |
| 2832 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2833 | { PCI_DEVICE(0x1002, 0xaa88), |
| 2834 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2835 | { PCI_DEVICE(0x1002, 0xaa90), |
| 2836 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2837 | { PCI_DEVICE(0x1002, 0xaa98), |
| 2838 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 2839 | { PCI_DEVICE(0x1002, 0x9902), |
| 2840 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2841 | { PCI_DEVICE(0x1002, 0xaaa0), |
| 2842 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2843 | { PCI_DEVICE(0x1002, 0xaaa8), |
| 2844 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 2845 | { PCI_DEVICE(0x1002, 0xaab0), |
| 2846 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
Takashi Iwai | 87218e9 | 2008-02-21 08:13:11 +0100 | [diff] [blame] | 2847 | /* VIA VT8251/VT8237A */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2848 | { PCI_DEVICE(0x1106, 0x3288), |
| 2849 | .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA }, |
Annie Liu | 754fdff | 2012-06-08 19:18:39 +0800 | [diff] [blame] | 2850 | /* VIA GFX VT7122/VX900 */ |
| 2851 | { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC }, |
| 2852 | /* VIA GFX VT6122/VX11 */ |
| 2853 | { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC }, |
Takashi Iwai | 87218e9 | 2008-02-21 08:13:11 +0100 | [diff] [blame] | 2854 | /* SIS966 */ |
| 2855 | { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS }, |
| 2856 | /* ULI M5461 */ |
| 2857 | { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI }, |
| 2858 | /* NVIDIA MCP */ |
Takashi Iwai | 0c2fd1bf4 | 2009-12-18 16:41:39 +0100 | [diff] [blame] | 2859 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), |
| 2860 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 2861 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2862 | .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA }, |
Kailang Yang | f269002 | 2008-05-27 11:44:55 +0200 | [diff] [blame] | 2863 | /* Teradici */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2864 | { PCI_DEVICE(0x6549, 0x1200), |
| 2865 | .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT }, |
Lars R. Damerow | f0b3da9 | 2012-11-02 13:10:39 -0700 | [diff] [blame] | 2866 | { PCI_DEVICE(0x6549, 0x2200), |
| 2867 | .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT }, |
Takashi Iwai | 4e01f54 | 2009-04-16 08:53:34 +0200 | [diff] [blame] | 2868 | /* Creative X-Fi (CA0110-IBG) */ |
Takashi Iwai | f2a8eca | 2012-06-11 15:51:54 +0200 | [diff] [blame] | 2869 | /* CTHDA chips */ |
| 2870 | { PCI_DEVICE(0x1102, 0x0010), |
| 2871 | .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, |
| 2872 | { PCI_DEVICE(0x1102, 0x0012), |
| 2873 | .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, |
Takashi Iwai | 8eeaa2f | 2014-02-10 09:48:47 +0100 | [diff] [blame] | 2874 | #if !IS_ENABLED(CONFIG_SND_CTXFI) |
Takashi Iwai | 313f6e2 | 2009-05-18 12:40:52 +0200 | [diff] [blame] | 2875 | /* the following entry conflicts with snd-ctxfi driver, |
| 2876 | * as ctxfi driver mutates from HD-audio to native mode with |
| 2877 | * a special command sequence. |
| 2878 | */ |
Takashi Iwai | 4e01f54 | 2009-04-16 08:53:34 +0200 | [diff] [blame] | 2879 | { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID), |
| 2880 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 2881 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2882 | .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | |
Takashi Iwai | 69f9ba9 | 2011-11-06 13:49:13 +0100 | [diff] [blame] | 2883 | AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, |
Takashi Iwai | 313f6e2 | 2009-05-18 12:40:52 +0200 | [diff] [blame] | 2884 | #else |
| 2885 | /* this entry seems still valid -- i.e. without emu20kx chip */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2886 | { PCI_DEVICE(0x1102, 0x0009), |
| 2887 | .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | |
Takashi Iwai | 69f9ba9 | 2011-11-06 13:49:13 +0100 | [diff] [blame] | 2888 | AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, |
Takashi Iwai | 313f6e2 | 2009-05-18 12:40:52 +0200 | [diff] [blame] | 2889 | #endif |
Otavio Salvador | e35d4b1 | 2010-09-26 23:35:06 -0300 | [diff] [blame] | 2890 | /* Vortex86MX */ |
| 2891 | { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, |
Bankim Bhavsar | 0f0714c5 | 2011-01-17 15:23:21 +0100 | [diff] [blame] | 2892 | /* VMware HDAudio */ |
| 2893 | { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC }, |
Andiry Brienza | 9176b67 | 2009-07-17 11:32:32 +0800 | [diff] [blame] | 2894 | /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */ |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 2895 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID), |
| 2896 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 2897 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2898 | .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI }, |
Andiry Brienza | 9176b67 | 2009-07-17 11:32:32 +0800 | [diff] [blame] | 2899 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID), |
| 2900 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 2901 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 2902 | .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | { 0, } |
| 2904 | }; |
| 2905 | MODULE_DEVICE_TABLE(pci, azx_ids); |
| 2906 | |
| 2907 | /* pci_driver definition */ |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 2908 | static struct pci_driver azx_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 2909 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | .id_table = azx_ids, |
| 2911 | .probe = azx_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2912 | .remove = azx_remove, |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2913 | .driver = { |
| 2914 | .pm = AZX_PM_OPS, |
| 2915 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | }; |
| 2917 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 2918 | module_pci_driver(azx_driver); |