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 | 2538a4f | 2014-02-28 15:41:12 -0800 | [diff] [blame] | 66 | #include "hda_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 69 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 70 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 71 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 72 | static char *model[SNDRV_CARDS]; |
Takashi Iwai | 1dac669 | 2012-09-13 14:59:47 +0200 | [diff] [blame] | 73 | static int position_fix[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 74 | static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 75 | static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1}; |
Takashi Iwai | d4d9cd03 | 2008-12-19 15:19:11 +0100 | [diff] [blame] | 76 | static int probe_only[SNDRV_CARDS]; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 77 | static int jackpoll_ms[SNDRV_CARDS]; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 78 | static bool single_cmd; |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 79 | static int enable_msi = -1; |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 80 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 81 | static char *patch[SNDRV_CARDS]; |
| 82 | #endif |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 83 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 0920c9b | 2012-07-03 16:58:48 +0200 | [diff] [blame] | 84 | static bool beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 85 | CONFIG_SND_HDA_INPUT_BEEP_MODE}; |
| 86 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 88 | module_param_array(index, int, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 90 | module_param_array(id, charp, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | MODULE_PARM_DESC(id, "ID string for Intel HD audio interface."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 92 | module_param_array(enable, bool, NULL, 0444); |
| 93 | MODULE_PARM_DESC(enable, "Enable Intel HD audio interface."); |
| 94 | module_param_array(model, charp, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | MODULE_PARM_DESC(model, "Use the given board model."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 96 | module_param_array(position_fix, int, NULL, 0444); |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 97 | MODULE_PARM_DESC(position_fix, "DMA pointer read method." |
Takashi Iwai | 1dac669 | 2012-09-13 14:59:47 +0200 | [diff] [blame] | 98 | "(-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] | 99 | module_param_array(bdl_pos_adj, int, NULL, 0644); |
| 100 | MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 101 | module_param_array(probe_mask, int, NULL, 0444); |
Takashi Iwai | 606ad75 | 2005-11-24 16:03:40 +0100 | [diff] [blame] | 102 | MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1)."); |
Jaroslav Kysela | 079e683 | 2010-03-26 11:16:59 +0100 | [diff] [blame] | 103 | module_param_array(probe_only, int, NULL, 0444); |
Takashi Iwai | d4d9cd03 | 2008-12-19 15:19:11 +0100 | [diff] [blame] | 104 | MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization."); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 105 | module_param_array(jackpoll_ms, int, NULL, 0444); |
| 106 | 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] | 107 | module_param(single_cmd, bool, 0444); |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 108 | MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " |
| 109 | "(for debugging only)."); |
Takashi Iwai | ac9ef6c | 2012-01-20 12:08:44 +0100 | [diff] [blame] | 110 | module_param(enable_msi, bint, 0444); |
Takashi Iwai | 134a11f | 2006-11-10 12:08:37 +0100 | [diff] [blame] | 111 | MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 112 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 113 | module_param_array(patch, charp, NULL, 0444); |
| 114 | MODULE_PARM_DESC(patch, "Patch file for Intel HD audio interface."); |
| 115 | #endif |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 116 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | 0920c9b | 2012-07-03 16:58:48 +0200 | [diff] [blame] | 117 | module_param_array(beep_mode, bool, NULL, 0444); |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 118 | MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode " |
Takashi Iwai | 0920c9b | 2012-07-03 16:58:48 +0200 | [diff] [blame] | 119 | "(0=off, 1=on) (default=1)."); |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 120 | #endif |
Takashi Iwai | 606ad75 | 2005-11-24 16:03:40 +0100 | [diff] [blame] | 121 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 122 | #ifdef CONFIG_PM |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 123 | static int param_set_xint(const char *val, const struct kernel_param *kp); |
| 124 | static struct kernel_param_ops param_ops_xint = { |
| 125 | .set = param_set_xint, |
| 126 | .get = param_get_int, |
| 127 | }; |
| 128 | #define param_check_xint param_check_int |
| 129 | |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 130 | static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame^] | 131 | static int *power_save_addr = &power_save; |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 132 | module_param(power_save, xint, 0644); |
Takashi Iwai | fee2fba | 2008-11-27 12:43:28 +0100 | [diff] [blame] | 133 | MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " |
| 134 | "(in second, 0 = disable)."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Takashi Iwai | dee1b66 | 2007-08-13 16:10:30 +0200 | [diff] [blame] | 136 | /* reset the HD-audio controller in power save mode. |
| 137 | * this may give more power-saving, but will take longer time to |
| 138 | * wake up. |
| 139 | */ |
Takashi Iwai | 8fc2442 | 2013-04-04 15:35:24 +0200 | [diff] [blame] | 140 | static bool power_save_controller = 1; |
| 141 | module_param(power_save_controller, bool, 0644); |
Takashi Iwai | dee1b66 | 2007-08-13 16:10:30 +0200 | [diff] [blame] | 142 | MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame^] | 143 | #else |
| 144 | static int *power_save_addr; |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 145 | #endif /* CONFIG_PM */ |
Takashi Iwai | dee1b66 | 2007-08-13 16:10:30 +0200 | [diff] [blame] | 146 | |
Takashi Iwai | 7bfe059 | 2012-01-23 17:53:39 +0100 | [diff] [blame] | 147 | static int align_buffer_size = -1; |
| 148 | module_param(align_buffer_size, bint, 0644); |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 149 | MODULE_PARM_DESC(align_buffer_size, |
| 150 | "Force buffer and period sizes to be multiple of 128 bytes."); |
| 151 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 152 | #ifdef CONFIG_X86 |
| 153 | static bool hda_snoop = true; |
| 154 | module_param_named(snoop, hda_snoop, bool, 0444); |
| 155 | MODULE_PARM_DESC(snoop, "Enable/disable snooping"); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 156 | #else |
| 157 | #define hda_snoop true |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 158 | #endif |
| 159 | |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | MODULE_LICENSE("GPL"); |
| 162 | MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," |
| 163 | "{Intel, ICH6M}," |
Jason Gaston | 2f1b381 | 2005-05-01 08:58:50 -0700 | [diff] [blame] | 164 | "{Intel, ICH7}," |
Frederick Li | f5d40b3 | 2005-05-12 14:55:20 +0200 | [diff] [blame] | 165 | "{Intel, ESB2}," |
Jason Gaston | d298139 | 2006-01-10 11:07:37 +0100 | [diff] [blame] | 166 | "{Intel, ICH8}," |
Jason Gaston | f9cc8a8 | 2006-11-22 11:53:52 +0100 | [diff] [blame] | 167 | "{Intel, ICH9}," |
Jason Gaston | c34f5a0 | 2008-01-29 12:38:49 +0100 | [diff] [blame] | 168 | "{Intel, ICH10}," |
Seth Heasley | b29c236 | 2008-08-08 15:56:39 -0700 | [diff] [blame] | 169 | "{Intel, PCH}," |
Seth Heasley | d2f2fcd | 2010-01-12 17:03:35 -0800 | [diff] [blame] | 170 | "{Intel, CPT}," |
Seth Heasley | d2edeb7 | 2011-04-20 10:59:57 -0700 | [diff] [blame] | 171 | "{Intel, PPT}," |
Seth Heasley | 8bc039a | 2012-01-23 16:24:31 -0800 | [diff] [blame] | 172 | "{Intel, LPT}," |
James Ralston | 144dad9 | 2012-08-09 09:38:59 -0700 | [diff] [blame] | 173 | "{Intel, LPT_LP}," |
James Ralston | 4eeca49 | 2013-11-04 09:27:45 -0800 | [diff] [blame] | 174 | "{Intel, WPT_LP}," |
Wang Xingchao | e926f2c | 2012-06-13 10:23:51 +0800 | [diff] [blame] | 175 | "{Intel, HPT}," |
Seth Heasley | cea310e | 2010-09-10 16:29:56 -0700 | [diff] [blame] | 176 | "{Intel, PBG}," |
Tobin Davis | 4979bca | 2008-01-30 08:13:55 +0100 | [diff] [blame] | 177 | "{Intel, SCH}," |
Takashi Iwai | fc20a56 | 2005-05-12 15:00:41 +0200 | [diff] [blame] | 178 | "{ATI, SB450}," |
Felix Kuehling | 89be83f | 2006-03-31 12:33:59 +0200 | [diff] [blame] | 179 | "{ATI, SB600}," |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 180 | "{ATI, RS600}," |
Felix Kuehling | 5b15c95 | 2006-10-16 12:49:47 +0200 | [diff] [blame] | 181 | "{ATI, RS690}," |
Wolke Liu | e6db111 | 2007-04-27 12:20:57 +0200 | [diff] [blame] | 182 | "{ATI, RS780}," |
| 183 | "{ATI, R600}," |
Herton Ronaldo Krzesinski | 2797f72 | 2007-11-05 18:21:56 +0100 | [diff] [blame] | 184 | "{ATI, RV630}," |
| 185 | "{ATI, RV610}," |
Wolke Liu | 27da183 | 2007-11-16 11:06:30 +0100 | [diff] [blame] | 186 | "{ATI, RV670}," |
| 187 | "{ATI, RV635}," |
| 188 | "{ATI, RV620}," |
| 189 | "{ATI, RV770}," |
Takashi Iwai | fc20a56 | 2005-05-12 15:00:41 +0200 | [diff] [blame] | 190 | "{VIA, VT8251}," |
Takashi Iwai | 4767231 | 2005-08-12 16:44:04 +0200 | [diff] [blame] | 191 | "{VIA, VT8237A}," |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 192 | "{SiS, SIS966}," |
| 193 | "{ULI, M5461}}"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | MODULE_DESCRIPTION("Intel HDA driver"); |
| 195 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 196 | #if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO) |
Takashi Iwai | f8f1bec | 2014-02-06 18:14:03 +0100 | [diff] [blame] | 197 | #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 198 | #define SUPPORT_VGA_SWITCHEROO |
| 199 | #endif |
| 200 | #endif |
| 201 | |
| 202 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 203 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 206 | /* DSP lock helpers */ |
| 207 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 208 | #define dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex) |
| 209 | #define dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex) |
| 210 | #define dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex) |
| 211 | #define dsp_is_locked(dev) ((dev)->locked) |
| 212 | #else |
| 213 | #define dsp_lock_init(dev) do {} while (0) |
| 214 | #define dsp_lock(dev) do {} while (0) |
| 215 | #define dsp_unlock(dev) do {} while (0) |
| 216 | #define dsp_is_locked(dev) 0 |
| 217 | #endif |
| 218 | |
Takashi Iwai | 1a8506d | 2012-10-16 15:10:08 +0200 | [diff] [blame] | 219 | #define CREATE_TRACE_POINTS |
| 220 | #include "hda_intel_trace.h" |
| 221 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 222 | /* driver types */ |
| 223 | enum { |
| 224 | AZX_DRIVER_ICH, |
Seth Heasley | 32679f9 | 2010-02-22 17:31:09 -0800 | [diff] [blame] | 225 | AZX_DRIVER_PCH, |
Tobin Davis | 4979bca | 2008-01-30 08:13:55 +0100 | [diff] [blame] | 226 | AZX_DRIVER_SCH, |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 227 | AZX_DRIVER_HDMI, |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 228 | AZX_DRIVER_ATI, |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 229 | AZX_DRIVER_ATIHDMI, |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 230 | AZX_DRIVER_ATIHDMI_NS, |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 231 | AZX_DRIVER_VIA, |
| 232 | AZX_DRIVER_SIS, |
| 233 | AZX_DRIVER_ULI, |
Vinod G | da3fca2 | 2005-09-13 18:49:12 +0200 | [diff] [blame] | 234 | AZX_DRIVER_NVIDIA, |
Kailang Yang | f269002 | 2008-05-27 11:44:55 +0200 | [diff] [blame] | 235 | AZX_DRIVER_TERA, |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 236 | AZX_DRIVER_CTX, |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 237 | AZX_DRIVER_CTHDA, |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 238 | AZX_DRIVER_GENERIC, |
Takashi Iwai | 2f5983f | 2008-09-03 16:00:44 +0200 | [diff] [blame] | 239 | AZX_NUM_DRIVERS, /* keep this as last entry */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 240 | }; |
| 241 | |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 242 | /* quirks for Intel PCH */ |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 243 | #define AZX_DCAPS_INTEL_PCH_NOPM \ |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 244 | (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \ |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 245 | AZX_DCAPS_COUNT_LPIB_DELAY) |
| 246 | |
| 247 | #define AZX_DCAPS_INTEL_PCH \ |
| 248 | (AZX_DCAPS_INTEL_PCH_NOPM | AZX_DCAPS_PM_RUNTIME) |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 249 | |
Takashi Iwai | 33499a1 | 2013-11-05 17:34:46 +0100 | [diff] [blame] | 250 | #define AZX_DCAPS_INTEL_HASWELL \ |
| 251 | (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_ALIGN_BUFSIZE | \ |
| 252 | AZX_DCAPS_COUNT_LPIB_DELAY | AZX_DCAPS_PM_RUNTIME | \ |
| 253 | AZX_DCAPS_I915_POWERWELL) |
| 254 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 255 | /* quirks for ATI SB / AMD Hudson */ |
| 256 | #define AZX_DCAPS_PRESET_ATI_SB \ |
| 257 | (AZX_DCAPS_ATI_SNOOP | AZX_DCAPS_NO_TCSEL | \ |
| 258 | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB) |
| 259 | |
| 260 | /* quirks for ATI/AMD HDMI */ |
| 261 | #define AZX_DCAPS_PRESET_ATI_HDMI \ |
| 262 | (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB) |
| 263 | |
| 264 | /* quirks for Nvidia */ |
| 265 | #define AZX_DCAPS_PRESET_NVIDIA \ |
Takashi Iwai | 7bfe059 | 2012-01-23 17:53:39 +0100 | [diff] [blame] | 266 | (AZX_DCAPS_NVIDIA_SNOOP | AZX_DCAPS_RIRB_DELAY | AZX_DCAPS_NO_MSI |\ |
Mike Travis | 49d9e77 | 2013-05-01 14:04:08 -0500 | [diff] [blame] | 267 | AZX_DCAPS_ALIGN_BUFSIZE | AZX_DCAPS_NO_64BIT) |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 268 | |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 269 | #define AZX_DCAPS_PRESET_CTHDA \ |
| 270 | (AZX_DCAPS_NO_MSI | AZX_DCAPS_POSFIX_LPIB | AZX_DCAPS_4K_BDLE_BOUNDARY) |
| 271 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 272 | /* |
| 273 | * VGA-switcher support |
| 274 | */ |
| 275 | #ifdef SUPPORT_VGA_SWITCHEROO |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 276 | #define use_vga_switcheroo(chip) ((chip)->use_vga_switcheroo) |
| 277 | #else |
| 278 | #define use_vga_switcheroo(chip) 0 |
| 279 | #endif |
| 280 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 281 | static char *driver_short_names[] = { |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 282 | [AZX_DRIVER_ICH] = "HDA Intel", |
Seth Heasley | 32679f9 | 2010-02-22 17:31:09 -0800 | [diff] [blame] | 283 | [AZX_DRIVER_PCH] = "HDA Intel PCH", |
Tobin Davis | 4979bca | 2008-01-30 08:13:55 +0100 | [diff] [blame] | 284 | [AZX_DRIVER_SCH] = "HDA Intel MID", |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 285 | [AZX_DRIVER_HDMI] = "HDA Intel HDMI", |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 286 | [AZX_DRIVER_ATI] = "HDA ATI SB", |
Felix Kuehling | 778b6e1 | 2006-05-17 11:22:21 +0200 | [diff] [blame] | 287 | [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI", |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 288 | [AZX_DRIVER_ATIHDMI_NS] = "HDA ATI HDMI", |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 289 | [AZX_DRIVER_VIA] = "HDA VIA VT82xx", |
| 290 | [AZX_DRIVER_SIS] = "HDA SIS966", |
Vinod G | da3fca2 | 2005-09-13 18:49:12 +0200 | [diff] [blame] | 291 | [AZX_DRIVER_ULI] = "HDA ULI M5461", |
| 292 | [AZX_DRIVER_NVIDIA] = "HDA NVidia", |
Kailang Yang | f269002 | 2008-05-27 11:44:55 +0200 | [diff] [blame] | 293 | [AZX_DRIVER_TERA] = "HDA Teradici", |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 294 | [AZX_DRIVER_CTX] = "HDA Creative", |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 295 | [AZX_DRIVER_CTHDA] = "HDA Creative", |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 296 | [AZX_DRIVER_GENERIC] = "HD-Audio Generic", |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 297 | }; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* for pcm support */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 300 | #define get_azx_dev(substream) (substream->runtime->private_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 302 | #ifdef CONFIG_X86 |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 303 | 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] | 304 | { |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 305 | int pages; |
| 306 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 307 | if (azx_snoop(chip)) |
| 308 | return; |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 309 | if (!dmab || !dmab->area || !dmab->bytes) |
| 310 | return; |
| 311 | |
| 312 | #ifdef CONFIG_SND_DMA_SGBUF |
| 313 | if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) { |
| 314 | struct snd_sg_buf *sgbuf = dmab->private_data; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 315 | if (on) |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 316 | set_pages_array_wc(sgbuf->page_table, sgbuf->pages); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 317 | else |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 318 | set_pages_array_wb(sgbuf->page_table, sgbuf->pages); |
| 319 | return; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 320 | } |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 321 | #endif |
| 322 | |
| 323 | pages = (dmab->bytes + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 324 | if (on) |
| 325 | set_memory_wc((unsigned long)dmab->area, pages); |
| 326 | else |
| 327 | set_memory_wb((unsigned long)dmab->area, pages); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf, |
| 331 | bool on) |
| 332 | { |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 333 | __mark_pages_wc(chip, buf, on); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 334 | } |
| 335 | 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] | 336 | struct snd_pcm_substream *substream, bool on) |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 337 | { |
| 338 | if (azx_dev->wc_marked != on) { |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 339 | __mark_pages_wc(chip, snd_pcm_get_dma_buf(substream), on); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 340 | azx_dev->wc_marked = on; |
| 341 | } |
| 342 | } |
| 343 | #else |
| 344 | /* NOP for other archs */ |
| 345 | static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf, |
| 346 | bool on) |
| 347 | { |
| 348 | } |
| 349 | 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] | 350 | struct snd_pcm_substream *substream, bool on) |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 351 | { |
| 352 | } |
| 353 | #endif |
| 354 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 355 | static int azx_acquire_irq(struct azx *chip, int do_disconnect); |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 356 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* |
| 358 | * Interface for HD codec |
| 359 | */ |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | /* |
| 362 | * CORB / RIRB interface |
| 363 | */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 364 | static int azx_alloc_cmd_io(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
| 366 | int err; |
| 367 | |
| 368 | /* single page (at least 4096 bytes) must suffice for both ringbuffes */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 369 | err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 370 | chip->card->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | PAGE_SIZE, &chip->rb); |
| 372 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 373 | dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | return err; |
| 375 | } |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 376 | mark_pages_wc(chip, &chip->rb, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 380 | static void azx_init_cmd_io(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 382 | int timeout; |
| 383 | |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 384 | spin_lock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* CORB set up */ |
| 386 | chip->corb.addr = chip->rb.addr; |
| 387 | chip->corb.buf = (u32 *)chip->rb.area; |
| 388 | azx_writel(chip, CORBLBASE, (u32)chip->corb.addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 389 | azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 391 | /* set the corb size to 256 entries (ULI requires explicitly) */ |
| 392 | azx_writeb(chip, CORBSIZE, 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* set the corb write pointer to 0 */ |
| 394 | azx_writew(chip, CORBWP, 0); |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /* reset the corb hw read pointer */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 397 | azx_writew(chip, CORBRP, ICH6_CORBRP_RST); |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 398 | for (timeout = 1000; timeout > 0; timeout--) { |
| 399 | if ((azx_readw(chip, CORBRP) & ICH6_CORBRP_RST) == ICH6_CORBRP_RST) |
| 400 | break; |
| 401 | udelay(1); |
| 402 | } |
| 403 | if (timeout <= 0) |
| 404 | dev_err(chip->card->dev, "CORB reset timeout#1, CORBRP = %d\n", |
| 405 | azx_readw(chip, CORBRP)); |
| 406 | |
| 407 | azx_writew(chip, CORBRP, 0); |
| 408 | for (timeout = 1000; timeout > 0; timeout--) { |
| 409 | if (azx_readw(chip, CORBRP) == 0) |
| 410 | break; |
| 411 | udelay(1); |
| 412 | } |
| 413 | if (timeout <= 0) |
| 414 | dev_err(chip->card->dev, "CORB reset timeout#2, CORBRP = %d\n", |
| 415 | azx_readw(chip, CORBRP)); |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | /* enable corb dma */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 418 | azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | /* RIRB set up */ |
| 421 | chip->rirb.addr = chip->rb.addr + 2048; |
| 422 | chip->rirb.buf = (u32 *)(chip->rb.area + 2048); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 423 | chip->rirb.wp = chip->rirb.rp = 0; |
| 424 | memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 426 | azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 428 | /* set the rirb size to 256 entries (ULI requires explicitly) */ |
| 429 | azx_writeb(chip, RIRBSIZE, 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | /* reset the rirb hw write pointer */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 431 | azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* set N=1, get RIRB response interrupt for new entry */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 433 | if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 434 | azx_writew(chip, RINTCNT, 0xc0); |
| 435 | else |
| 436 | azx_writew(chip, RINTCNT, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | /* enable rirb dma and response irq */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN); |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 439 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 442 | static void azx_free_cmd_io(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 444 | spin_lock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | /* disable ringbuffer DMAs */ |
| 446 | azx_writeb(chip, RIRBCTL, 0); |
| 447 | azx_writeb(chip, CORBCTL, 0); |
Wu Fengguang | cdb1fbf | 2009-08-01 18:47:41 +0800 | [diff] [blame] | 448 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 451 | static unsigned int azx_command_addr(u32 cmd) |
| 452 | { |
| 453 | unsigned int addr = cmd >> 28; |
| 454 | |
| 455 | if (addr >= AZX_MAX_CODECS) { |
| 456 | snd_BUG(); |
| 457 | addr = 0; |
| 458 | } |
| 459 | |
| 460 | return addr; |
| 461 | } |
| 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* send a command */ |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 464 | static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 466 | struct azx *chip = bus->private_data; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 467 | unsigned int addr = azx_command_addr(val); |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 468 | unsigned int wp, rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Wu Fengguang | c32649f | 2009-08-01 18:48:12 +0800 | [diff] [blame] | 470 | spin_lock_irq(&chip->reg_lock); |
| 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | /* add command to corb */ |
Takashi Iwai | cc5ede3 | 2012-12-12 11:10:49 +0100 | [diff] [blame] | 473 | wp = azx_readw(chip, CORBWP); |
| 474 | if (wp == 0xffff) { |
| 475 | /* something wrong, controller likely turned to D3 */ |
| 476 | spin_unlock_irq(&chip->reg_lock); |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 477 | return -EIO; |
Takashi Iwai | cc5ede3 | 2012-12-12 11:10:49 +0100 | [diff] [blame] | 478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | wp++; |
| 480 | wp %= ICH6_MAX_CORB_ENTRIES; |
| 481 | |
Takashi Iwai | 3bcce5c | 2012-12-20 11:17:17 +0100 | [diff] [blame] | 482 | rp = azx_readw(chip, CORBRP); |
| 483 | if (wp == rp) { |
| 484 | /* oops, it's full */ |
| 485 | spin_unlock_irq(&chip->reg_lock); |
| 486 | return -EAGAIN; |
| 487 | } |
| 488 | |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 489 | chip->rirb.cmds[addr]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | chip->corb.buf[wp] = cpu_to_le32(val); |
David Henningsson | ca460f8 | 2014-02-28 07:56:58 +0100 | [diff] [blame] | 491 | azx_writew(chip, CORBWP, wp); |
Wu Fengguang | c32649f | 2009-08-01 18:48:12 +0800 | [diff] [blame] | 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | spin_unlock_irq(&chip->reg_lock); |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | #define ICH6_RIRB_EX_UNSOL_EV (1<<4) |
| 499 | |
| 500 | /* retrieve RIRB entry - called from interrupt handler */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 501 | static void azx_update_rirb(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | unsigned int rp, wp; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 504 | unsigned int addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | u32 res, res_ex; |
| 506 | |
Takashi Iwai | cc5ede3 | 2012-12-12 11:10:49 +0100 | [diff] [blame] | 507 | wp = azx_readw(chip, RIRBWP); |
| 508 | if (wp == 0xffff) { |
| 509 | /* something wrong, controller likely turned to D3 */ |
| 510 | return; |
| 511 | } |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (wp == chip->rirb.wp) |
| 514 | return; |
| 515 | chip->rirb.wp = wp; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | while (chip->rirb.rp != wp) { |
| 518 | chip->rirb.rp++; |
| 519 | chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES; |
| 520 | |
| 521 | rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ |
| 522 | res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); |
| 523 | res = le32_to_cpu(chip->rirb.buf[rp]); |
David Henningsson | 3d69245 | 2014-01-29 13:12:31 +0100 | [diff] [blame] | 524 | addr = res_ex & 0xf; |
| 525 | if ((addr >= AZX_MAX_CODECS) || !(chip->codec_mask & (1 << addr))) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 526 | dev_err(chip->card->dev, "spurious response %#x:%#x, rp = %d, wp = %d", |
| 527 | res, res_ex, |
| 528 | chip->rirb.rp, wp); |
David Henningsson | 3d69245 | 2014-01-29 13:12:31 +0100 | [diff] [blame] | 529 | snd_BUG(); |
| 530 | } |
| 531 | else if (res_ex & ICH6_RIRB_EX_UNSOL_EV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | snd_hda_queue_unsol_event(chip->bus, res, res_ex); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 533 | else if (chip->rirb.cmds[addr]) { |
| 534 | chip->rirb.res[addr] = res; |
Takashi Iwai | 2add9b9 | 2008-03-18 09:47:06 +0100 | [diff] [blame] | 535 | smp_wmb(); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 536 | chip->rirb.cmds[addr]--; |
Joe Perches | 3b70a67 | 2013-11-07 11:55:15 -0800 | [diff] [blame] | 537 | } else if (printk_ratelimit()) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 538 | dev_err(chip->card->dev, "spurious response %#x:%#x, last cmd=%#08x\n", |
| 539 | res, res_ex, |
| 540 | chip->last_cmd[addr]); |
Joe Perches | 3b70a67 | 2013-11-07 11:55:15 -0800 | [diff] [blame] | 541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
| 545 | /* receive a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 546 | static unsigned int azx_rirb_get_response(struct hda_bus *bus, |
| 547 | unsigned int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 549 | struct azx *chip = bus->private_data; |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 550 | unsigned long timeout; |
David Henningsson | 32cf402 | 2012-05-04 11:05:55 +0200 | [diff] [blame] | 551 | unsigned long loopcounter; |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 552 | int do_poll = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 554 | again: |
| 555 | timeout = jiffies + msecs_to_jiffies(1000); |
David Henningsson | 32cf402 | 2012-05-04 11:05:55 +0200 | [diff] [blame] | 556 | |
| 557 | for (loopcounter = 0;; loopcounter++) { |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 558 | if (chip->polling_mode || do_poll) { |
Takashi Iwai | e96224a | 2006-08-21 17:57:44 +0200 | [diff] [blame] | 559 | spin_lock_irq(&chip->reg_lock); |
| 560 | azx_update_rirb(chip); |
| 561 | spin_unlock_irq(&chip->reg_lock); |
| 562 | } |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 563 | if (!chip->rirb.cmds[addr]) { |
Takashi Iwai | 2add9b9 | 2008-03-18 09:47:06 +0100 | [diff] [blame] | 564 | smp_rmb(); |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 565 | bus->rirb_error = 0; |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 566 | |
| 567 | if (!do_poll) |
| 568 | chip->poll_count = 0; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 569 | return chip->rirb.res[addr]; /* the last value */ |
Takashi Iwai | 2add9b9 | 2008-03-18 09:47:06 +0100 | [diff] [blame] | 570 | } |
Takashi Iwai | 28a0d9d | 2008-01-18 15:32:32 +0100 | [diff] [blame] | 571 | if (time_after(jiffies, timeout)) |
| 572 | break; |
David Henningsson | 32cf402 | 2012-05-04 11:05:55 +0200 | [diff] [blame] | 573 | if (bus->needs_damn_long_delay || loopcounter > 3000) |
Takashi Iwai | 5298765 | 2008-01-16 16:09:47 +0100 | [diff] [blame] | 574 | msleep(2); /* temporary workaround */ |
| 575 | else { |
| 576 | udelay(10); |
| 577 | cond_resched(); |
| 578 | } |
Takashi Iwai | 28a0d9d | 2008-01-18 15:32:32 +0100 | [diff] [blame] | 579 | } |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 580 | |
Takashi Iwai | 63e51fd | 2013-06-06 14:20:19 +0200 | [diff] [blame] | 581 | if (!bus->no_response_fallback) |
| 582 | return -1; |
| 583 | |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 584 | if (!chip->polling_mode && chip->poll_count < 2) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 585 | dev_dbg(chip->card->dev, |
| 586 | "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n", |
| 587 | chip->last_cmd[addr]); |
Maxim Levitsky | 1eb6dc7 | 2010-02-04 22:21:47 +0200 | [diff] [blame] | 588 | do_poll = 1; |
| 589 | chip->poll_count++; |
| 590 | goto again; |
| 591 | } |
| 592 | |
| 593 | |
Takashi Iwai | 23c4a88 | 2009-10-30 13:21:49 +0100 | [diff] [blame] | 594 | if (!chip->polling_mode) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 595 | dev_warn(chip->card->dev, |
| 596 | "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n", |
| 597 | chip->last_cmd[addr]); |
Takashi Iwai | 23c4a88 | 2009-10-30 13:21:49 +0100 | [diff] [blame] | 598 | chip->polling_mode = 1; |
| 599 | goto again; |
| 600 | } |
| 601 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 602 | if (chip->msi) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 603 | dev_warn(chip->card->dev, |
| 604 | "No response from codec, disabling MSI: last cmd=0x%08x\n", |
| 605 | chip->last_cmd[addr]); |
Dylan Reid | f46ea60 | 2014-02-28 15:41:16 -0800 | [diff] [blame] | 606 | if (chip->ops->disable_msi_reset_irq && |
| 607 | chip->ops->disable_msi_reset_irq(chip) < 0) { |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 608 | bus->rirb_error = 1; |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 609 | return -1; |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 610 | } |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 611 | goto again; |
| 612 | } |
| 613 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 614 | if (chip->probing) { |
| 615 | /* If this critical timeout happens during the codec probing |
| 616 | * phase, this is likely an access to a non-existing codec |
| 617 | * slot. Better to return an error and reset the system. |
| 618 | */ |
| 619 | return -1; |
| 620 | } |
| 621 | |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 622 | /* a fatal communication error; need either to reset or to fallback |
| 623 | * to the single_cmd mode |
| 624 | */ |
Takashi Iwai | b613291 | 2009-03-24 07:36:09 +0100 | [diff] [blame] | 625 | bus->rirb_error = 1; |
Takashi Iwai | b20f3b8 | 2009-06-02 01:20:22 +0200 | [diff] [blame] | 626 | if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) { |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 627 | bus->response_reset = 1; |
| 628 | return -1; /* give a chance to retry */ |
| 629 | } |
| 630 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 631 | dev_err(chip->card->dev, |
| 632 | "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n", |
| 633 | chip->last_cmd[addr]); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 634 | chip->single_cmd = 1; |
| 635 | bus->response_reset = 0; |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 636 | /* release CORB/RIRB */ |
Takashi Iwai | 4fcd392 | 2009-05-25 18:34:52 +0200 | [diff] [blame] | 637 | azx_free_cmd_io(chip); |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 638 | /* disable unsolicited responses */ |
| 639 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL); |
Takashi Iwai | 5c79b1f | 2006-09-21 13:34:13 +0200 | [diff] [blame] | 640 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /* |
| 644 | * Use the single immediate command instead of CORB/RIRB for simplicity |
| 645 | * |
| 646 | * Note: according to Intel, this is not preferred use. The command was |
| 647 | * intended for the BIOS only, and may get confused with unsolicited |
| 648 | * responses. So, we shouldn't use it for normal operation from the |
| 649 | * driver. |
| 650 | * I left the codes, however, for debugging/testing purposes. |
| 651 | */ |
| 652 | |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 653 | /* receive a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 654 | 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] | 655 | { |
| 656 | int timeout = 50; |
| 657 | |
| 658 | while (timeout--) { |
| 659 | /* check IRV busy bit */ |
| 660 | if (azx_readw(chip, IRS) & ICH6_IRS_VALID) { |
| 661 | /* reuse rirb.res as the response return value */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 662 | chip->rirb.res[addr] = azx_readl(chip, IR); |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 663 | return 0; |
| 664 | } |
| 665 | udelay(1); |
| 666 | } |
| 667 | if (printk_ratelimit()) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 668 | dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n", |
| 669 | azx_readw(chip, IRS)); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 670 | chip->rirb.res[addr] = -1; |
Takashi Iwai | b05a7d4 | 2009-05-28 11:59:12 +0200 | [diff] [blame] | 671 | return -EIO; |
| 672 | } |
| 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | /* send a command */ |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 675 | static int azx_single_send_cmd(struct hda_bus *bus, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 677 | struct azx *chip = bus->private_data; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 678 | unsigned int addr = azx_command_addr(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | int timeout = 50; |
| 680 | |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 681 | bus->rirb_error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | while (timeout--) { |
| 683 | /* check ICB busy bit */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 684 | if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | /* Clear IRV valid bit */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 686 | azx_writew(chip, IRS, azx_readw(chip, IRS) | |
| 687 | ICH6_IRS_VALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | azx_writel(chip, IC, val); |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 689 | azx_writew(chip, IRS, azx_readw(chip, IRS) | |
| 690 | ICH6_IRS_BUSY); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 691 | return azx_single_wait_for_response(chip, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | udelay(1); |
| 694 | } |
Marc Boucher | 1cfd52b | 2008-01-22 15:29:26 +0100 | [diff] [blame] | 695 | if (printk_ratelimit()) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 696 | dev_dbg(chip->card->dev, |
| 697 | "send_cmd timeout: IRS=0x%x, val=0x%x\n", |
| 698 | azx_readw(chip, IRS), val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return -EIO; |
| 700 | } |
| 701 | |
| 702 | /* receive a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 703 | static unsigned int azx_single_get_response(struct hda_bus *bus, |
| 704 | unsigned int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 706 | struct azx *chip = bus->private_data; |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 707 | return chip->rirb.res[addr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 710 | /* |
| 711 | * The below are the main callbacks from hda_codec. |
| 712 | * |
| 713 | * They are just the skeleton to call sub-callbacks according to the |
| 714 | * current setting of chip->single_cmd. |
| 715 | */ |
| 716 | |
| 717 | /* send a command */ |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 718 | static int azx_send_cmd(struct hda_bus *bus, unsigned int val) |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 719 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 720 | struct azx *chip = bus->private_data; |
Takashi Iwai | 43bbb6c | 2007-07-06 20:22:05 +0200 | [diff] [blame] | 721 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 722 | if (chip->disabled) |
| 723 | return 0; |
Wu Fengguang | feb2734 | 2009-08-01 19:17:14 +0800 | [diff] [blame] | 724 | chip->last_cmd[azx_command_addr(val)] = val; |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 725 | if (chip->single_cmd) |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 726 | return azx_single_send_cmd(bus, val); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 727 | else |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 728 | return azx_corb_send_cmd(bus, val); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /* get a response */ |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 732 | static unsigned int azx_get_response(struct hda_bus *bus, |
| 733 | unsigned int addr) |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 734 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 735 | struct azx *chip = bus->private_data; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 736 | if (chip->disabled) |
| 737 | return 0; |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 738 | if (chip->single_cmd) |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 739 | return azx_single_get_response(bus, addr); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 740 | else |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 741 | return azx_rirb_get_response(bus, addr); |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 744 | #ifdef CONFIG_PM |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 745 | static void azx_power_notify(struct hda_bus *bus, bool power_up); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 746 | #endif |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 747 | |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 748 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 749 | static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, |
| 750 | unsigned int byte_size, |
| 751 | struct snd_dma_buffer *bufp); |
| 752 | static void azx_load_dsp_trigger(struct hda_bus *bus, bool start); |
| 753 | static void azx_load_dsp_cleanup(struct hda_bus *bus, |
| 754 | struct snd_dma_buffer *dmab); |
| 755 | #endif |
| 756 | |
Mengdong Lin | 3af3f35 | 2013-06-24 10:18:54 -0400 | [diff] [blame] | 757 | /* enter link reset */ |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 758 | static void azx_enter_link_reset(struct azx *chip) |
Mengdong Lin | 3af3f35 | 2013-06-24 10:18:54 -0400 | [diff] [blame] | 759 | { |
| 760 | unsigned long timeout; |
| 761 | |
| 762 | /* reset controller */ |
| 763 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET); |
| 764 | |
| 765 | timeout = jiffies + msecs_to_jiffies(100); |
| 766 | while ((azx_readb(chip, GCTL) & ICH6_GCTL_RESET) && |
| 767 | time_before(jiffies, timeout)) |
| 768 | usleep_range(500, 1000); |
| 769 | } |
| 770 | |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 771 | /* exit link reset */ |
| 772 | static void azx_exit_link_reset(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
Mengdong Lin | fa348da | 2012-12-12 09:16:15 -0500 | [diff] [blame] | 774 | unsigned long timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 776 | azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET); |
| 777 | |
| 778 | timeout = jiffies + msecs_to_jiffies(100); |
| 779 | while (!azx_readb(chip, GCTL) && |
| 780 | time_before(jiffies, timeout)) |
| 781 | usleep_range(500, 1000); |
| 782 | } |
| 783 | |
| 784 | /* reset codec link */ |
| 785 | static int azx_reset(struct azx *chip, int full_reset) |
| 786 | { |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 787 | if (!full_reset) |
| 788 | goto __skip; |
| 789 | |
Danny Tholen | e8a7f13 | 2007-09-11 21:41:56 +0200 | [diff] [blame] | 790 | /* clear STATESTS */ |
Wang Xingchao | da7db6a | 2013-07-22 03:19:18 -0400 | [diff] [blame] | 791 | azx_writew(chip, STATESTS, STATESTS_INT_MASK); |
Danny Tholen | e8a7f13 | 2007-09-11 21:41:56 +0200 | [diff] [blame] | 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* reset controller */ |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 794 | azx_enter_link_reset(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* delay for >= 100us for codec PLL to settle per spec |
| 797 | * Rev 0.9 section 5.5.1 |
| 798 | */ |
Mengdong Lin | fa348da | 2012-12-12 09:16:15 -0500 | [diff] [blame] | 799 | usleep_range(500, 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
| 801 | /* Bring controller out of reset */ |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 802 | azx_exit_link_reset(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 804 | /* Brent Chartrand said to wait >= 540us for codecs to initialize */ |
Mengdong Lin | fa348da | 2012-12-12 09:16:15 -0500 | [diff] [blame] | 805 | usleep_range(1000, 1200); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 807 | __skip: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | /* check to see if controller is ready */ |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 809 | if (!azx_readb(chip, GCTL)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 810 | dev_dbg(chip->card->dev, "azx_reset: controller not ready!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | return -EBUSY; |
| 812 | } |
| 813 | |
Matt | 41e2fce | 2005-07-04 17:49:55 +0200 | [diff] [blame] | 814 | /* Accept unsolicited responses */ |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 815 | if (!chip->single_cmd) |
| 816 | azx_writel(chip, GCTL, azx_readl(chip, GCTL) | |
| 817 | ICH6_GCTL_UNSOL); |
Matt | 41e2fce | 2005-07-04 17:49:55 +0200 | [diff] [blame] | 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | /* detect codecs */ |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 820 | if (!chip->codec_mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | chip->codec_mask = azx_readw(chip, STATESTS); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 822 | dev_dbg(chip->card->dev, "codec_mask = 0x%x\n", |
| 823 | chip->codec_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | |
| 830 | /* |
| 831 | * Lowlevel interface |
| 832 | */ |
| 833 | |
| 834 | /* enable interrupts */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 835 | static void azx_int_enable(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | { |
| 837 | /* enable controller CIE and GIE */ |
| 838 | azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) | |
| 839 | ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN); |
| 840 | } |
| 841 | |
| 842 | /* disable interrupts */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 843 | static void azx_int_disable(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | { |
| 845 | int i; |
| 846 | |
| 847 | /* disable interrupts in stream descriptor */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 848 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 849 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 850 | azx_sd_writeb(chip, azx_dev, SD_CTL, |
| 851 | azx_sd_readb(chip, azx_dev, SD_CTL) & |
| 852 | ~SD_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /* disable SIE for all streams */ |
| 856 | azx_writeb(chip, INTCTL, 0); |
| 857 | |
| 858 | /* disable controller CIE and GIE */ |
| 859 | azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) & |
| 860 | ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN)); |
| 861 | } |
| 862 | |
| 863 | /* clear interrupts */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 864 | static void azx_int_clear(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
| 866 | int i; |
| 867 | |
| 868 | /* clear stream status */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 869 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 870 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 871 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* clear STATESTS */ |
Wang Xingchao | da7db6a | 2013-07-22 03:19:18 -0400 | [diff] [blame] | 875 | azx_writew(chip, STATESTS, STATESTS_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
| 877 | /* clear rirb status */ |
| 878 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); |
| 879 | |
| 880 | /* clear int status */ |
| 881 | azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM); |
| 882 | } |
| 883 | |
| 884 | /* start a stream */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 885 | static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
Joseph Chan | 0e15347 | 2008-08-26 14:38:03 +0200 | [diff] [blame] | 887 | /* |
| 888 | * Before stream start, initialize parameter |
| 889 | */ |
| 890 | azx_dev->insufficient = 1; |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | /* enable SIE */ |
Wei Ni | ccc5df0 | 2010-01-26 15:59:33 +0800 | [diff] [blame] | 893 | azx_writel(chip, INTCTL, |
| 894 | azx_readl(chip, INTCTL) | (1 << azx_dev->index)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | /* set DMA start and interrupt mask */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 896 | azx_sd_writeb(chip, azx_dev, SD_CTL, |
| 897 | azx_sd_readb(chip, azx_dev, SD_CTL) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | SD_CTL_DMA_START | SD_INT_MASK); |
| 899 | } |
| 900 | |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 901 | /* stop DMA */ |
| 902 | static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 904 | azx_sd_writeb(chip, azx_dev, SD_CTL, |
| 905 | azx_sd_readb(chip, azx_dev, SD_CTL) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | ~(SD_CTL_DMA_START | SD_INT_MASK)); |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 907 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); /* to be sure */ |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* stop a stream */ |
| 911 | static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev) |
| 912 | { |
| 913 | azx_stream_clear(chip, azx_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | /* disable SIE */ |
Wei Ni | ccc5df0 | 2010-01-26 15:59:33 +0800 | [diff] [blame] | 915 | azx_writel(chip, INTCTL, |
| 916 | azx_readl(chip, INTCTL) & ~(1 << azx_dev->index)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
| 920 | /* |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 921 | * reset and start the controller registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | */ |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 923 | static void azx_init_chip(struct azx *chip, int full_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 925 | if (chip->initialized) |
| 926 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | /* reset controller */ |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 929 | azx_reset(chip, full_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | /* initialize interrupts */ |
| 932 | azx_int_clear(chip); |
| 933 | azx_int_enable(chip); |
| 934 | |
| 935 | /* initialize the codec command I/O */ |
Takashi Iwai | 1a69697 | 2009-11-07 09:49:04 +0100 | [diff] [blame] | 936 | if (!chip->single_cmd) |
| 937 | azx_init_cmd_io(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
Takashi Iwai | 0be3b5d | 2005-09-05 17:11:40 +0200 | [diff] [blame] | 939 | /* program the position buffer */ |
| 940 | azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 941 | azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr)); |
Frederick Li | f5d40b3 | 2005-05-12 14:55:20 +0200 | [diff] [blame] | 942 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 943 | chip->initialized = 1; |
| 944 | } |
| 945 | |
| 946 | /* |
| 947 | * initialize the PCI registers |
| 948 | */ |
| 949 | /* update bits in a PCI register byte */ |
| 950 | static void update_pci_byte(struct pci_dev *pci, unsigned int reg, |
| 951 | unsigned char mask, unsigned char val) |
| 952 | { |
| 953 | unsigned char data; |
| 954 | |
| 955 | pci_read_config_byte(pci, reg, &data); |
| 956 | data &= ~mask; |
| 957 | data |= (val & mask); |
| 958 | pci_write_config_byte(pci, reg, data); |
| 959 | } |
| 960 | |
| 961 | static void azx_init_pci(struct azx *chip) |
| 962 | { |
| 963 | /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) |
| 964 | * TCSEL == Traffic Class Select Register, which sets PCI express QOS |
| 965 | * Ensuring these bits are 0 clears playback static on some HD Audio |
Adam Lackorzynski | a09e89f | 2011-03-10 17:41:56 +0100 | [diff] [blame] | 966 | * codecs. |
| 967 | * The PCI register TCSEL is defined in the Intel manuals. |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 968 | */ |
Linus Torvalds | 46f2cc8 | 2011-05-27 19:45:28 -0700 | [diff] [blame] | 969 | if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 970 | dev_dbg(chip->card->dev, "Clearing TCSEL\n"); |
Adam Lackorzynski | a09e89f | 2011-03-10 17:41:56 +0100 | [diff] [blame] | 971 | update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 972 | } |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 973 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 974 | /* For ATI SB450/600/700/800/900 and AMD Hudson azalia HD audio, |
| 975 | * we need to enable snoop. |
| 976 | */ |
| 977 | if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 978 | dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n", |
| 979 | azx_snoop(chip)); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 980 | update_pci_byte(chip->pci, |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 981 | ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07, |
| 982 | azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /* For NVIDIA HDA, enable snoop */ |
| 986 | if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 987 | dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n", |
| 988 | azx_snoop(chip)); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 989 | update_pci_byte(chip->pci, |
| 990 | NVIDIA_HDA_TRANSREG_ADDR, |
| 991 | 0x0f, NVIDIA_HDA_ENABLE_COHBITS); |
Peer Chen | 320dcc3 | 2008-08-20 16:43:24 -0700 | [diff] [blame] | 992 | update_pci_byte(chip->pci, |
| 993 | NVIDIA_HDA_ISTRM_COH, |
| 994 | 0x01, NVIDIA_HDA_ENABLE_COHBIT); |
| 995 | update_pci_byte(chip->pci, |
| 996 | NVIDIA_HDA_OSTRM_COH, |
| 997 | 0x01, NVIDIA_HDA_ENABLE_COHBIT); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /* Enable SCH/PCH snoop if needed */ |
| 1001 | if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) { |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1002 | unsigned short snoop; |
Takashi Iwai | 90a5ad5 | 2008-02-22 18:36:22 +0100 | [diff] [blame] | 1003 | pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1004 | if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) || |
| 1005 | (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) { |
| 1006 | snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP; |
| 1007 | if (!azx_snoop(chip)) |
| 1008 | snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP; |
| 1009 | pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop); |
Takashi Iwai | 90a5ad5 | 2008-02-22 18:36:22 +0100 | [diff] [blame] | 1010 | pci_read_config_word(chip->pci, |
| 1011 | INTEL_SCH_HDA_DEVC, &snoop); |
Takashi Iwai | 90a5ad5 | 2008-02-22 18:36:22 +0100 | [diff] [blame] | 1012 | } |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1013 | dev_dbg(chip->card->dev, "SCH snoop: %s\n", |
| 1014 | (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ? |
| 1015 | "Disabled" : "Enabled"); |
Vinod G | da3fca2 | 2005-09-13 18:49:12 +0200 | [diff] [blame] | 1016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1020 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev); |
| 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | /* |
| 1023 | * interrupt handler |
| 1024 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1025 | static irqreturn_t azx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1027 | struct azx *chip = dev_id; |
| 1028 | struct azx_dev *azx_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | u32 status; |
Clemens Ladisch | 9ef0406 | 2010-05-25 09:03:40 +0200 | [diff] [blame] | 1030 | u8 sd_status; |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1031 | int i, ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1033 | #ifdef CONFIG_PM_RUNTIME |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1034 | if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME) |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 1035 | if (chip->card->dev->power.runtime_status != RPM_ACTIVE) |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1036 | return IRQ_NONE; |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 1037 | #endif |
| 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | spin_lock(&chip->reg_lock); |
| 1040 | |
Dan Carpenter | 6091106 | 2012-05-18 10:36:11 +0300 | [diff] [blame] | 1041 | if (chip->disabled) { |
| 1042 | spin_unlock(&chip->reg_lock); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1043 | return IRQ_NONE; |
Dan Carpenter | 6091106 | 2012-05-18 10:36:11 +0300 | [diff] [blame] | 1044 | } |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | status = azx_readl(chip, INTSTS); |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 1047 | if (status == 0 || status == 0xffffffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | spin_unlock(&chip->reg_lock); |
| 1049 | return IRQ_NONE; |
| 1050 | } |
| 1051 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 1052 | for (i = 0; i < chip->num_streams; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | azx_dev = &chip->azx_dev[i]; |
| 1054 | if (status & azx_dev->sd_int_sta_mask) { |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1055 | sd_status = azx_sd_readb(chip, azx_dev, SD_STS); |
| 1056 | azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); |
Clemens Ladisch | 9ef0406 | 2010-05-25 09:03:40 +0200 | [diff] [blame] | 1057 | if (!azx_dev->substream || !azx_dev->running || |
| 1058 | !(sd_status & SD_INT_COMPLETE)) |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1059 | continue; |
| 1060 | /* check whether this IRQ is really acceptable */ |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1061 | ok = azx_position_ok(chip, azx_dev); |
| 1062 | if (ok == 1) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1063 | azx_dev->irq_pending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | spin_unlock(&chip->reg_lock); |
| 1065 | snd_pcm_period_elapsed(azx_dev->substream); |
| 1066 | spin_lock(&chip->reg_lock); |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1067 | } else if (ok == 0 && chip->bus && chip->bus->workq) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 1068 | /* bogus IRQ, process it later */ |
| 1069 | azx_dev->irq_pending = 1; |
Takashi Iwai | 6acaed3 | 2009-01-12 10:09:24 +0100 | [diff] [blame] | 1070 | queue_work(chip->bus->workq, |
| 1071 | &chip->irq_pending_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | /* clear rirb int */ |
| 1077 | status = azx_readb(chip, RIRBSTS); |
| 1078 | if (status & RIRB_INT_MASK) { |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 1079 | if (status & RIRB_INT_RESPONSE) { |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1080 | if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY) |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 1081 | udelay(80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | azx_update_rirb(chip); |
Takashi Iwai | 14d34f1 | 2010-10-21 09:03:25 +0200 | [diff] [blame] | 1083 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); |
| 1085 | } |
| 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | spin_unlock(&chip->reg_lock); |
| 1088 | |
| 1089 | return IRQ_HANDLED; |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | /* |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1094 | * set up a BDL entry |
| 1095 | */ |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 1096 | static int setup_bdle(struct azx *chip, |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1097 | struct snd_dma_buffer *dmab, |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1098 | struct azx_dev *azx_dev, u32 **bdlp, |
| 1099 | int ofs, int size, int with_ioc) |
| 1100 | { |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1101 | u32 *bdl = *bdlp; |
| 1102 | |
| 1103 | while (size > 0) { |
| 1104 | dma_addr_t addr; |
| 1105 | int chunk; |
| 1106 | |
| 1107 | if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) |
| 1108 | return -EINVAL; |
| 1109 | |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1110 | addr = snd_sgbuf_get_addr(dmab, ofs); |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1111 | /* program the address field of the BDL entry */ |
| 1112 | bdl[0] = cpu_to_le32((u32)addr); |
Takashi Iwai | 766979e | 2008-06-13 20:53:56 +0200 | [diff] [blame] | 1113 | bdl[1] = cpu_to_le32(upper_32_bits(addr)); |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1114 | /* program the size field of the BDL entry */ |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1115 | chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size); |
Takashi Iwai | 5ae763b | 2012-05-08 10:34:08 +0200 | [diff] [blame] | 1116 | /* one BDLE cannot cross 4K boundary on CTHDA chips */ |
| 1117 | if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) { |
| 1118 | u32 remain = 0x1000 - (ofs & 0xfff); |
| 1119 | if (chunk > remain) |
| 1120 | chunk = remain; |
| 1121 | } |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1122 | bdl[2] = cpu_to_le32(chunk); |
| 1123 | /* program the IOC to enable interrupt |
| 1124 | * only when the whole fragment is processed |
| 1125 | */ |
| 1126 | size -= chunk; |
| 1127 | bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01); |
| 1128 | bdl += 4; |
| 1129 | azx_dev->frags++; |
| 1130 | ofs += chunk; |
| 1131 | } |
| 1132 | *bdlp = bdl; |
| 1133 | return ofs; |
| 1134 | } |
| 1135 | |
| 1136 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | * set up BDL entries |
| 1138 | */ |
Takashi Iwai | 555e219 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 1139 | static int azx_setup_periods(struct azx *chip, |
| 1140 | struct snd_pcm_substream *substream, |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1141 | struct azx_dev *azx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | { |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1143 | u32 *bdl; |
| 1144 | int i, ofs, periods, period_bytes; |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 1145 | int pos_adj = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | |
| 1147 | /* reset BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1148 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); |
| 1149 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1151 | period_bytes = azx_dev->period_bytes; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1152 | periods = azx_dev->bufsize / period_bytes; |
| 1153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | /* program the initial BDL entries */ |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1155 | bdl = (u32 *)azx_dev->bdl.area; |
| 1156 | ofs = 0; |
| 1157 | azx_dev->frags = 0; |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 1158 | |
| 1159 | if (chip->bdl_pos_adj) |
| 1160 | pos_adj = chip->bdl_pos_adj[chip->dev_index]; |
Takashi Iwai | 915bf29 | 2012-09-11 15:19:10 +0200 | [diff] [blame] | 1161 | if (!azx_dev->no_period_wakeup && pos_adj > 0) { |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1162 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | e785d3d | 2008-07-15 16:28:43 +0200 | [diff] [blame] | 1163 | int pos_align = pos_adj; |
Takashi Iwai | 555e219 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 1164 | pos_adj = (pos_adj * runtime->rate + 47999) / 48000; |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1165 | if (!pos_adj) |
Takashi Iwai | e785d3d | 2008-07-15 16:28:43 +0200 | [diff] [blame] | 1166 | pos_adj = pos_align; |
| 1167 | else |
| 1168 | pos_adj = ((pos_adj + pos_align - 1) / pos_align) * |
| 1169 | pos_align; |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1170 | pos_adj = frames_to_bytes(runtime, pos_adj); |
| 1171 | if (pos_adj >= period_bytes) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1172 | dev_warn(chip->card->dev,"Too big adjustment %d\n", |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 1173 | pos_adj); |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1174 | pos_adj = 0; |
| 1175 | } else { |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1176 | ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream), |
| 1177 | azx_dev, |
Takashi Iwai | 915bf29 | 2012-09-11 15:19:10 +0200 | [diff] [blame] | 1178 | &bdl, ofs, pos_adj, true); |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1179 | if (ofs < 0) |
| 1180 | goto error; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1181 | } |
Takashi Iwai | 555e219 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 1182 | } else |
| 1183 | pos_adj = 0; |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 1184 | |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1185 | for (i = 0; i < periods; i++) { |
| 1186 | if (i == periods - 1 && pos_adj) |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1187 | ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream), |
| 1188 | azx_dev, &bdl, ofs, |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1189 | period_bytes - pos_adj, 0); |
| 1190 | else |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1191 | ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream), |
| 1192 | azx_dev, &bdl, ofs, |
Clemens Ladisch | 7bb8fb7 | 2010-11-15 10:49:47 +0100 | [diff] [blame] | 1193 | period_bytes, |
Takashi Iwai | 915bf29 | 2012-09-11 15:19:10 +0200 | [diff] [blame] | 1194 | !azx_dev->no_period_wakeup); |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1195 | if (ofs < 0) |
| 1196 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | } |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 1198 | return 0; |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1199 | |
| 1200 | error: |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1201 | dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n", |
| 1202 | azx_dev->bufsize, period_bytes); |
Takashi Iwai | 675f25d | 2008-06-10 17:53:20 +0200 | [diff] [blame] | 1203 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 1206 | /* reset stream */ |
| 1207 | static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | { |
| 1209 | unsigned char val; |
| 1210 | int timeout; |
| 1211 | |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 1212 | azx_stream_clear(chip, azx_dev); |
| 1213 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1214 | azx_sd_writeb(chip, azx_dev, SD_CTL, |
| 1215 | azx_sd_readb(chip, azx_dev, SD_CTL) | |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1216 | SD_CTL_STREAM_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | udelay(3); |
| 1218 | timeout = 300; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1219 | while (!((val = azx_sd_readb(chip, azx_dev, SD_CTL)) & |
| 1220 | SD_CTL_STREAM_RESET) && --timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | ; |
| 1222 | val &= ~SD_CTL_STREAM_RESET; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1223 | azx_sd_writeb(chip, azx_dev, SD_CTL, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | udelay(3); |
| 1225 | |
| 1226 | timeout = 300; |
| 1227 | /* waiting for hardware to report that the stream is out of reset */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1228 | while (((val = azx_sd_readb(chip, azx_dev, SD_CTL)) & |
| 1229 | SD_CTL_STREAM_RESET) && --timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | ; |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1231 | |
| 1232 | /* reset first position - may not be synced with hw at this time */ |
| 1233 | *azx_dev->posbuf = 0; |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 1234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 1236 | /* |
| 1237 | * set up the SD for streaming |
| 1238 | */ |
| 1239 | static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) |
| 1240 | { |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1241 | unsigned int val; |
Takashi Iwai | 1dddab4 | 2009-03-18 15:15:37 +0100 | [diff] [blame] | 1242 | /* make sure the run bit is zero for SD */ |
| 1243 | azx_stream_clear(chip, azx_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | /* program the stream_tag */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1245 | val = azx_sd_readl(chip, azx_dev, SD_CTL); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1246 | val = (val & ~SD_CTL_STREAM_TAG_MASK) | |
| 1247 | (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT); |
| 1248 | if (!azx_snoop(chip)) |
| 1249 | val |= SD_CTL_TRAFFIC_PRIO; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1250 | azx_sd_writel(chip, azx_dev, SD_CTL, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
| 1252 | /* program the length of samples in cyclic buffer */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1253 | azx_sd_writel(chip, azx_dev, SD_CBL, azx_dev->bufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | /* program the stream format */ |
| 1256 | /* this value needs to be the same as the one programmed */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1257 | azx_sd_writew(chip, azx_dev, SD_FORMAT, azx_dev->format_val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
| 1259 | /* program the stream LVI (last valid index) of the BDL */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1260 | azx_sd_writew(chip, azx_dev, SD_LVI, azx_dev->frags - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
| 1262 | /* program the BDL address */ |
| 1263 | /* lower BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1264 | azx_sd_writel(chip, azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | /* upper BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1266 | azx_sd_writel(chip, azx_dev, SD_BDLPU, |
| 1267 | upper_32_bits(azx_dev->bdl.addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Takashi Iwai | 0be3b5d | 2005-09-05 17:11:40 +0200 | [diff] [blame] | 1269 | /* enable the position buffer */ |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 1270 | if (chip->position_fix[0] != POS_FIX_LPIB || |
| 1271 | chip->position_fix[1] != POS_FIX_LPIB) { |
Takashi Iwai | ee9d6b9 | 2008-03-14 15:52:20 +0100 | [diff] [blame] | 1272 | if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) |
| 1273 | azx_writel(chip, DPLBASE, |
| 1274 | (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE); |
| 1275 | } |
Takashi Iwai | c74db86 | 2005-05-12 14:26:27 +0200 | [diff] [blame] | 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | /* set the interrupt enable bits in the descriptor control register */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1278 | azx_sd_writel(chip, azx_dev, SD_CTL, |
| 1279 | azx_sd_readl(chip, azx_dev, SD_CTL) | SD_INT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1284 | /* |
| 1285 | * Probe the given codec address |
| 1286 | */ |
| 1287 | static int probe_codec(struct azx *chip, int addr) |
| 1288 | { |
| 1289 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | |
| 1290 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; |
| 1291 | unsigned int res; |
| 1292 | |
Wu Fengguang | a678cde | 2009-08-01 18:46:46 +0800 | [diff] [blame] | 1293 | mutex_lock(&chip->bus->cmd_mutex); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1294 | chip->probing = 1; |
| 1295 | azx_send_cmd(chip->bus, cmd); |
Wu Fengguang | deadff1 | 2009-08-01 18:45:16 +0800 | [diff] [blame] | 1296 | res = azx_get_response(chip->bus, addr); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1297 | chip->probing = 0; |
Wu Fengguang | a678cde | 2009-08-01 18:46:46 +0800 | [diff] [blame] | 1298 | mutex_unlock(&chip->bus->cmd_mutex); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1299 | if (res == -1) |
| 1300 | return -EIO; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1301 | dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 1305 | static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, |
| 1306 | struct hda_pcm *cpcm); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1307 | static void azx_stop_chip(struct azx *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1309 | static void azx_bus_reset(struct hda_bus *bus) |
| 1310 | { |
| 1311 | struct azx *chip = bus->private_data; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1312 | |
| 1313 | bus->in_reset = 1; |
| 1314 | azx_stop_chip(chip); |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 1315 | azx_init_chip(chip, 1); |
Alexander Beregalov | 65f7598 | 2009-06-04 13:46:16 +0400 | [diff] [blame] | 1316 | #ifdef CONFIG_PM |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1317 | if (chip->initialized) { |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 1318 | struct azx_pcm *p; |
| 1319 | list_for_each_entry(p, &chip->pcm_list, list) |
| 1320 | snd_pcm_suspend_all(p->pcm); |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1321 | snd_hda_suspend(chip->bus); |
| 1322 | snd_hda_resume(chip->bus); |
| 1323 | } |
Alexander Beregalov | 65f7598 | 2009-06-04 13:46:16 +0400 | [diff] [blame] | 1324 | #endif |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1325 | bus->in_reset = 0; |
| 1326 | } |
| 1327 | |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1328 | static int get_jackpoll_interval(struct azx *chip) |
| 1329 | { |
Dylan Reid | 749ee28 | 2014-02-28 15:41:18 -0800 | [diff] [blame] | 1330 | int i; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1331 | unsigned int j; |
Dylan Reid | 749ee28 | 2014-02-28 15:41:18 -0800 | [diff] [blame] | 1332 | |
| 1333 | if (!chip->jackpoll_ms) |
| 1334 | return 0; |
| 1335 | |
| 1336 | i = chip->jackpoll_ms[chip->dev_index]; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1337 | if (i == 0) |
| 1338 | return 0; |
| 1339 | if (i < 50 || i > 60000) |
| 1340 | j = 0; |
| 1341 | else |
| 1342 | j = msecs_to_jiffies(i); |
| 1343 | if (j == 0) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1344 | dev_warn(chip->card->dev, |
| 1345 | "jackpoll_ms value out of range: %d\n", i); |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1346 | return j; |
| 1347 | } |
| 1348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | /* |
| 1350 | * Codec initialization |
| 1351 | */ |
| 1352 | |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame^] | 1353 | static int azx_codec_create(struct azx *chip, const char *model, |
| 1354 | unsigned int max_slots, |
| 1355 | int *power_save_to) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | { |
| 1357 | struct hda_bus_template bus_temp; |
Takashi Iwai | 34c2535 | 2008-10-28 11:38:58 +0100 | [diff] [blame] | 1358 | int c, codecs, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
| 1360 | memset(&bus_temp, 0, sizeof(bus_temp)); |
| 1361 | bus_temp.private_data = chip; |
| 1362 | bus_temp.modelname = model; |
| 1363 | bus_temp.pci = chip->pci; |
Takashi Iwai | 111d3af | 2006-02-16 18:17:58 +0100 | [diff] [blame] | 1364 | bus_temp.ops.command = azx_send_cmd; |
| 1365 | bus_temp.ops.get_response = azx_get_response; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1366 | bus_temp.ops.attach_pcm = azx_attach_pcm_stream; |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 1367 | bus_temp.ops.bus_reset = azx_bus_reset; |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 1368 | #ifdef CONFIG_PM |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame^] | 1369 | bus_temp.power_save = power_save_to; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1370 | bus_temp.ops.pm_notify = azx_power_notify; |
| 1371 | #endif |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 1372 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 1373 | bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare; |
| 1374 | bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger; |
| 1375 | bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup; |
| 1376 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1378 | err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); |
| 1379 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | return err; |
| 1381 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1382 | if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1383 | dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n"); |
Wei Ni | dc9c8e2 | 2008-09-26 13:55:56 +0800 | [diff] [blame] | 1384 | chip->bus->needs_damn_long_delay = 1; |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1385 | } |
Wei Ni | dc9c8e2 | 2008-09-26 13:55:56 +0800 | [diff] [blame] | 1386 | |
Takashi Iwai | 34c2535 | 2008-10-28 11:38:58 +0100 | [diff] [blame] | 1387 | codecs = 0; |
Takashi Iwai | 2f5983f | 2008-09-03 16:00:44 +0200 | [diff] [blame] | 1388 | if (!max_slots) |
Wei Ni | 7445dfc | 2010-03-03 15:05:53 +0800 | [diff] [blame] | 1389 | max_slots = AZX_DEFAULT_CODECS; |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1390 | |
| 1391 | /* First try to probe all given codec slots */ |
| 1392 | for (c = 0; c < max_slots; c++) { |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 1393 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1394 | if (probe_codec(chip, c) < 0) { |
| 1395 | /* Some BIOSen give you wrong codec addresses |
| 1396 | * that don't exist |
| 1397 | */ |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1398 | dev_warn(chip->card->dev, |
| 1399 | "Codec #%d probe error; disabling it...\n", c); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1400 | chip->codec_mask &= ~(1 << c); |
| 1401 | /* More badly, accessing to a non-existing |
| 1402 | * codec often screws up the controller chip, |
Paul Menzel | 2448158 | 2010-02-08 20:37:26 +0100 | [diff] [blame] | 1403 | * and disturbs the further communications. |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1404 | * Thus if an error occurs during probing, |
| 1405 | * better to reset the controller chip to |
| 1406 | * get back to the sanity state. |
| 1407 | */ |
| 1408 | azx_stop_chip(chip); |
Jaroslav Kysela | cd508fe | 2010-03-26 10:28:46 +0100 | [diff] [blame] | 1409 | azx_init_chip(chip, 1); |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1410 | } |
| 1411 | } |
| 1412 | } |
| 1413 | |
Takashi Iwai | d507cd6 | 2011-04-26 15:25:02 +0200 | [diff] [blame] | 1414 | /* AMD chipsets often cause the communication stalls upon certain |
| 1415 | * sequence like the pin-detection. It seems that forcing the synced |
| 1416 | * access works around the stall. Grrr... |
| 1417 | */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1418 | if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1419 | dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n"); |
Takashi Iwai | d507cd6 | 2011-04-26 15:25:02 +0200 | [diff] [blame] | 1420 | chip->bus->sync_write = 1; |
| 1421 | chip->bus->allow_bus_reset = 1; |
| 1422 | } |
| 1423 | |
Takashi Iwai | 6ce4a3b | 2008-11-06 17:11:10 +0100 | [diff] [blame] | 1424 | /* Then create codec instances */ |
Takashi Iwai | 34c2535 | 2008-10-28 11:38:58 +0100 | [diff] [blame] | 1425 | for (c = 0; c < max_slots; c++) { |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 1426 | if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { |
Takashi Iwai | bccad14 | 2007-04-24 12:23:53 +0200 | [diff] [blame] | 1427 | struct hda_codec *codec; |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1428 | err = snd_hda_codec_new(chip->bus, c, &codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | if (err < 0) |
| 1430 | continue; |
David Henningsson | 26a6cb6 | 2012-10-09 15:04:21 +0200 | [diff] [blame] | 1431 | codec->jackpoll_interval = get_jackpoll_interval(chip); |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 1432 | codec->beep_mode = chip->beep_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | codecs++; |
Takashi Iwai | 19a982b | 2007-03-21 15:14:35 +0100 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | if (!codecs) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1437 | dev_err(chip->card->dev, "no codecs initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | return -ENXIO; |
| 1439 | } |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1443 | /* configure each codec instance */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1444 | static int azx_codec_configure(struct azx *chip) |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 1445 | { |
| 1446 | struct hda_codec *codec; |
| 1447 | list_for_each_entry(codec, &chip->bus->codec_list, list) { |
| 1448 | snd_hda_codec_configure(codec); |
| 1449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | /* |
| 1455 | * PCM support |
| 1456 | */ |
| 1457 | |
| 1458 | /* assign a stream for the PCM */ |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1459 | static inline struct azx_dev * |
| 1460 | azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | { |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 1462 | int dev, i, nums; |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1463 | struct azx_dev *res = NULL; |
Takashi Iwai | d5cf991 | 2011-10-06 10:07:58 +0200 | [diff] [blame] | 1464 | /* make a non-zero unique key for the substream */ |
| 1465 | int key = (substream->pcm->device << 16) | (substream->number << 2) | |
| 1466 | (substream->stream + 1); |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1467 | |
| 1468 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 1469 | dev = chip->playback_index_offset; |
| 1470 | nums = chip->playback_streams; |
| 1471 | } else { |
| 1472 | dev = chip->capture_index_offset; |
| 1473 | nums = chip->capture_streams; |
| 1474 | } |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1475 | for (i = 0; i < nums; i++, dev++) { |
| 1476 | struct azx_dev *azx_dev = &chip->azx_dev[dev]; |
| 1477 | dsp_lock(azx_dev); |
| 1478 | if (!azx_dev->opened && !dsp_is_locked(azx_dev)) { |
| 1479 | res = azx_dev; |
| 1480 | if (res->assigned_key == key) { |
| 1481 | res->opened = 1; |
| 1482 | res->assigned_key = key; |
| 1483 | dsp_unlock(azx_dev); |
| 1484 | return azx_dev; |
| 1485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | } |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1487 | dsp_unlock(azx_dev); |
| 1488 | } |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1489 | if (res) { |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1490 | dsp_lock(res); |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1491 | res->opened = 1; |
Takashi Iwai | d5cf991 | 2011-10-06 10:07:58 +0200 | [diff] [blame] | 1492 | res->assigned_key = key; |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1493 | dsp_unlock(res); |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1494 | } |
| 1495 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /* release the assigned stream */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1499 | static inline void azx_release_device(struct azx_dev *azx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | { |
| 1501 | azx_dev->opened = 0; |
| 1502 | } |
| 1503 | |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1504 | static cycle_t azx_cc_read(const struct cyclecounter *cc) |
| 1505 | { |
| 1506 | struct azx_dev *azx_dev = container_of(cc, struct azx_dev, azx_cc); |
| 1507 | struct snd_pcm_substream *substream = azx_dev->substream; |
| 1508 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 1509 | struct azx *chip = apcm->chip; |
| 1510 | |
| 1511 | return azx_readl(chip, WALLCLK); |
| 1512 | } |
| 1513 | |
| 1514 | static void azx_timecounter_init(struct snd_pcm_substream *substream, |
| 1515 | bool force, cycle_t last) |
| 1516 | { |
| 1517 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 1518 | struct timecounter *tc = &azx_dev->azx_tc; |
| 1519 | struct cyclecounter *cc = &azx_dev->azx_cc; |
| 1520 | u64 nsec; |
| 1521 | |
| 1522 | cc->read = azx_cc_read; |
| 1523 | cc->mask = CLOCKSOURCE_MASK(32); |
| 1524 | |
| 1525 | /* |
| 1526 | * Converting from 24 MHz to ns means applying a 125/3 factor. |
| 1527 | * To avoid any saturation issues in intermediate operations, |
| 1528 | * the 125 factor is applied first. The division is applied |
| 1529 | * last after reading the timecounter value. |
| 1530 | * Applying the 1/3 factor as part of the multiplication |
| 1531 | * requires at least 20 bits for a decent precision, however |
| 1532 | * overflows occur after about 4 hours or less, not a option. |
| 1533 | */ |
| 1534 | |
| 1535 | cc->mult = 125; /* saturation after 195 years */ |
| 1536 | cc->shift = 0; |
| 1537 | |
| 1538 | nsec = 0; /* audio time is elapsed time since trigger */ |
| 1539 | timecounter_init(tc, cc, nsec); |
| 1540 | if (force) |
| 1541 | /* |
| 1542 | * force timecounter to use predefined value, |
| 1543 | * used for synchronized starts |
| 1544 | */ |
| 1545 | tc->cycle_last = last; |
| 1546 | } |
| 1547 | |
Dylan Reid | ae03bbb | 2013-04-15 11:57:05 -0700 | [diff] [blame] | 1548 | static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream, |
Dylan Reid | 78daea2 | 2013-04-08 18:20:30 -0700 | [diff] [blame] | 1549 | u64 nsec) |
| 1550 | { |
| 1551 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 1552 | struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; |
| 1553 | u64 codec_frames, codec_nsecs; |
| 1554 | |
| 1555 | if (!hinfo->ops.get_delay) |
| 1556 | return nsec; |
| 1557 | |
| 1558 | codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream); |
| 1559 | codec_nsecs = div_u64(codec_frames * 1000000000LL, |
| 1560 | substream->runtime->rate); |
| 1561 | |
Dylan Reid | ae03bbb | 2013-04-15 11:57:05 -0700 | [diff] [blame] | 1562 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 1563 | return nsec + codec_nsecs; |
| 1564 | |
Dylan Reid | 78daea2 | 2013-04-08 18:20:30 -0700 | [diff] [blame] | 1565 | return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; |
| 1566 | } |
| 1567 | |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1568 | static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, |
| 1569 | struct timespec *ts) |
| 1570 | { |
| 1571 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 1572 | u64 nsec; |
| 1573 | |
| 1574 | nsec = timecounter_read(&azx_dev->azx_tc); |
| 1575 | nsec = div_u64(nsec, 3); /* can be optimized */ |
Dylan Reid | ae03bbb | 2013-04-15 11:57:05 -0700 | [diff] [blame] | 1576 | nsec = azx_adjust_codec_delay(substream, nsec); |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1577 | |
| 1578 | *ts = ns_to_timespec(nsec); |
| 1579 | |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1583 | static struct snd_pcm_hardware azx_pcm_hw = { |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1584 | .info = (SNDRV_PCM_INFO_MMAP | |
| 1585 | SNDRV_PCM_INFO_INTERLEAVED | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1587 | SNDRV_PCM_INFO_MMAP_VALID | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 1588 | /* No full-resume yet implemented */ |
| 1589 | /* SNDRV_PCM_INFO_RESUME |*/ |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1590 | SNDRV_PCM_INFO_PAUSE | |
Clemens Ladisch | 7bb8fb7 | 2010-11-15 10:49:47 +0100 | [diff] [blame] | 1591 | SNDRV_PCM_INFO_SYNC_START | |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1592 | SNDRV_PCM_INFO_HAS_WALL_CLOCK | |
Clemens Ladisch | 7bb8fb7 | 2010-11-15 10:49:47 +0100 | [diff] [blame] | 1593 | SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1595 | .rates = SNDRV_PCM_RATE_48000, |
| 1596 | .rate_min = 48000, |
| 1597 | .rate_max = 48000, |
| 1598 | .channels_min = 2, |
| 1599 | .channels_max = 2, |
| 1600 | .buffer_bytes_max = AZX_MAX_BUF_SIZE, |
| 1601 | .period_bytes_min = 128, |
| 1602 | .period_bytes_max = AZX_MAX_BUF_SIZE / 2, |
| 1603 | .periods_min = 2, |
| 1604 | .periods_max = AZX_MAX_FRAG, |
| 1605 | .fifo_size = 0, |
| 1606 | }; |
| 1607 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1608 | static int azx_pcm_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | { |
| 1610 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 1611 | struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1612 | struct azx *chip = apcm->chip; |
| 1613 | struct azx_dev *azx_dev; |
| 1614 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | unsigned long flags; |
| 1616 | int err; |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 1617 | int buff_step; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1619 | mutex_lock(&chip->open_mutex); |
Wu Fengguang | ef18bed | 2009-12-25 13:14:27 +0800 | [diff] [blame] | 1620 | azx_dev = azx_assign_device(chip, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | if (azx_dev == NULL) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1622 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | return -EBUSY; |
| 1624 | } |
| 1625 | runtime->hw = azx_pcm_hw; |
| 1626 | runtime->hw.channels_min = hinfo->channels_min; |
| 1627 | runtime->hw.channels_max = hinfo->channels_max; |
| 1628 | runtime->hw.formats = hinfo->formats; |
| 1629 | runtime->hw.rates = hinfo->rates; |
| 1630 | snd_pcm_limit_hw_rates(runtime); |
| 1631 | snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1632 | |
| 1633 | /* avoid wrap-around with wall-clock */ |
| 1634 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME, |
| 1635 | 20, |
| 1636 | 178000000); |
| 1637 | |
Takashi Iwai | 52409aa | 2012-01-23 17:10:24 +0100 | [diff] [blame] | 1638 | if (chip->align_buffer_size) |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 1639 | /* constrain buffer sizes to be multiple of 128 |
| 1640 | bytes. This is more efficient in terms of memory |
| 1641 | access but isn't required by the HDA spec and |
| 1642 | prevents users from specifying exact period/buffer |
| 1643 | sizes. For example for 44.1kHz, a period size set |
| 1644 | to 20ms will be rounded to 19.59ms. */ |
| 1645 | buff_step = 128; |
| 1646 | else |
| 1647 | /* Don't enforce steps on buffer sizes, still need to |
| 1648 | be multiple of 4 bytes (HDA spec). Tested on Intel |
| 1649 | HDA controllers, may not work on all devices where |
| 1650 | option needs to be disabled */ |
| 1651 | buff_step = 4; |
| 1652 | |
Joachim Deguara | 5f1545b | 2007-03-16 15:01:36 +0100 | [diff] [blame] | 1653 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 1654 | buff_step); |
Joachim Deguara | 5f1545b | 2007-03-16 15:01:36 +0100 | [diff] [blame] | 1655 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 1656 | buff_step); |
Dylan Reid | b4a91cf | 2012-06-15 19:36:23 -0700 | [diff] [blame] | 1657 | snd_hda_power_up_d3wait(apcm->codec); |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1658 | err = hinfo->ops.open(hinfo, apcm->codec, substream); |
| 1659 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | azx_release_device(azx_dev); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1661 | snd_hda_power_down(apcm->codec); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1662 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | return err; |
| 1664 | } |
Takashi Iwai | 70d321e | 2009-07-03 23:06:45 +0200 | [diff] [blame] | 1665 | snd_pcm_limit_hw_rates(runtime); |
Takashi Iwai | aba6653 | 2009-07-05 11:44:46 +0200 | [diff] [blame] | 1666 | /* sanity check */ |
| 1667 | if (snd_BUG_ON(!runtime->hw.channels_min) || |
| 1668 | snd_BUG_ON(!runtime->hw.channels_max) || |
| 1669 | snd_BUG_ON(!runtime->hw.formats) || |
| 1670 | snd_BUG_ON(!runtime->hw.rates)) { |
| 1671 | azx_release_device(azx_dev); |
| 1672 | hinfo->ops.close(hinfo, apcm->codec, substream); |
| 1673 | snd_hda_power_down(apcm->codec); |
| 1674 | mutex_unlock(&chip->open_mutex); |
| 1675 | return -EINVAL; |
| 1676 | } |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1677 | |
| 1678 | /* disable WALLCLOCK timestamps for capture streams |
| 1679 | until we figure out how to handle digital inputs */ |
| 1680 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 1681 | runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; |
| 1682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1684 | azx_dev->substream = substream; |
| 1685 | azx_dev->running = 0; |
| 1686 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1687 | |
| 1688 | runtime->private_data = azx_dev; |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1689 | snd_pcm_set_sync(substream); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1690 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | return 0; |
| 1692 | } |
| 1693 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1694 | static int azx_pcm_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | { |
| 1696 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 1697 | struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1698 | struct azx *chip = apcm->chip; |
| 1699 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | unsigned long flags; |
| 1701 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1702 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1704 | azx_dev->substream = NULL; |
| 1705 | azx_dev->running = 0; |
| 1706 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1707 | azx_release_device(azx_dev); |
| 1708 | hinfo->ops.close(hinfo, apcm->codec, substream); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1709 | snd_hda_power_down(apcm->codec); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1710 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | return 0; |
| 1712 | } |
| 1713 | |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1714 | static int azx_pcm_hw_params(struct snd_pcm_substream *substream, |
| 1715 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | { |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1717 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 1718 | struct azx *chip = apcm->chip; |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1719 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1720 | int ret; |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1721 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1722 | dsp_lock(azx_dev); |
| 1723 | if (dsp_is_locked(azx_dev)) { |
| 1724 | ret = -EBUSY; |
| 1725 | goto unlock; |
| 1726 | } |
| 1727 | |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 1728 | mark_runtime_wc(chip, azx_dev, substream, false); |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1729 | azx_dev->bufsize = 0; |
| 1730 | azx_dev->period_bytes = 0; |
| 1731 | azx_dev->format_val = 0; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1732 | ret = snd_pcm_lib_malloc_pages(substream, |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 1733 | params_buffer_bytes(hw_params)); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1734 | if (ret < 0) |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1735 | goto unlock; |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 1736 | mark_runtime_wc(chip, azx_dev, substream, true); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1737 | unlock: |
| 1738 | dsp_unlock(azx_dev); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1739 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1742 | static int azx_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | { |
| 1744 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1745 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 1746 | struct azx *chip = apcm->chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; |
| 1748 | |
| 1749 | /* reset BDL address */ |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1750 | dsp_lock(azx_dev); |
| 1751 | if (!dsp_is_locked(azx_dev)) { |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1752 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); |
| 1753 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); |
| 1754 | azx_sd_writel(chip, azx_dev, SD_CTL, 0); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1755 | azx_dev->bufsize = 0; |
| 1756 | azx_dev->period_bytes = 0; |
| 1757 | azx_dev->format_val = 0; |
| 1758 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1760 | snd_hda_codec_cleanup(apcm->codec, hinfo, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
Takashi Iwai | 9ddf1ae | 2013-01-29 18:07:22 +0100 | [diff] [blame] | 1762 | mark_runtime_wc(chip, azx_dev, substream, false); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1763 | azx_dev->prepared = 0; |
| 1764 | dsp_unlock(azx_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | return snd_pcm_lib_free_pages(substream); |
| 1766 | } |
| 1767 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1768 | static int azx_pcm_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | { |
| 1770 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1771 | struct azx *chip = apcm->chip; |
| 1772 | struct azx_dev *azx_dev = get_azx_dev(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1774 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 62b7e5e | 2010-10-22 17:15:47 +0200 | [diff] [blame] | 1775 | unsigned int bufsize, period_bytes, format_val, stream_tag; |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1776 | int err; |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1777 | struct hda_spdif_out *spdif = |
| 1778 | snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid); |
| 1779 | unsigned short ctls = spdif ? spdif->ctls : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1781 | dsp_lock(azx_dev); |
| 1782 | if (dsp_is_locked(azx_dev)) { |
| 1783 | err = -EBUSY; |
| 1784 | goto unlock; |
| 1785 | } |
| 1786 | |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1787 | azx_stream_reset(chip, azx_dev); |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1788 | format_val = snd_hda_calc_stream_format(runtime->rate, |
| 1789 | runtime->channels, |
| 1790 | runtime->format, |
Anssi Hannula | 32c168c | 2010-08-03 13:28:57 +0300 | [diff] [blame] | 1791 | hinfo->maxbps, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1792 | ctls); |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1793 | if (!format_val) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1794 | dev_err(chip->card->dev, |
| 1795 | "invalid format_val, rate=%d, ch=%d, format=%d\n", |
| 1796 | runtime->rate, runtime->channels, runtime->format); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1797 | err = -EINVAL; |
| 1798 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1801 | bufsize = snd_pcm_lib_buffer_bytes(substream); |
| 1802 | period_bytes = snd_pcm_lib_period_bytes(substream); |
| 1803 | |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 1804 | dev_dbg(chip->card->dev, "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n", |
| 1805 | bufsize, format_val); |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1806 | |
| 1807 | if (bufsize != azx_dev->bufsize || |
| 1808 | period_bytes != azx_dev->period_bytes || |
Takashi Iwai | 915bf29 | 2012-09-11 15:19:10 +0200 | [diff] [blame] | 1809 | format_val != azx_dev->format_val || |
| 1810 | runtime->no_period_wakeup != azx_dev->no_period_wakeup) { |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1811 | azx_dev->bufsize = bufsize; |
| 1812 | azx_dev->period_bytes = period_bytes; |
| 1813 | azx_dev->format_val = format_val; |
Takashi Iwai | 915bf29 | 2012-09-11 15:19:10 +0200 | [diff] [blame] | 1814 | azx_dev->no_period_wakeup = runtime->no_period_wakeup; |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1815 | err = azx_setup_periods(chip, substream, azx_dev); |
| 1816 | if (err < 0) |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1817 | goto unlock; |
Takashi Iwai | 97b71c9 | 2009-03-18 15:09:13 +0100 | [diff] [blame] | 1818 | } |
| 1819 | |
Takashi Iwai | e8648e5 | 2013-12-06 17:15:01 +0100 | [diff] [blame] | 1820 | /* when LPIB delay correction gives a small negative value, |
| 1821 | * we ignore it; currently set the threshold statically to |
| 1822 | * 64 frames |
| 1823 | */ |
| 1824 | if (runtime->period_size > 64) |
| 1825 | azx_dev->delay_negative_threshold = -frames_to_bytes(runtime, 64); |
| 1826 | else |
| 1827 | azx_dev->delay_negative_threshold = 0; |
| 1828 | |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1829 | /* wallclk has 24Mhz clock source */ |
| 1830 | azx_dev->period_wallclk = (((runtime->period_size * 24000) / |
| 1831 | runtime->rate) * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | azx_setup_controller(chip, azx_dev); |
| 1833 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1834 | azx_dev->fifo_size = |
| 1835 | azx_sd_readw(chip, azx_dev, SD_FIFOSIZE) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | else |
| 1837 | azx_dev->fifo_size = 0; |
| 1838 | |
Takashi Iwai | 62b7e5e | 2010-10-22 17:15:47 +0200 | [diff] [blame] | 1839 | stream_tag = azx_dev->stream_tag; |
| 1840 | /* CA-IBG chips need the playback stream starting from 1 */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 1841 | if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) && |
Takashi Iwai | 62b7e5e | 2010-10-22 17:15:47 +0200 | [diff] [blame] | 1842 | stream_tag > chip->capture_streams) |
| 1843 | stream_tag -= chip->capture_streams; |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1844 | err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, |
Takashi Iwai | eb54133 | 2010-08-06 13:48:11 +0200 | [diff] [blame] | 1845 | azx_dev->format_val, substream); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1846 | |
| 1847 | unlock: |
| 1848 | if (!err) |
| 1849 | azx_dev->prepared = 1; |
| 1850 | dsp_unlock(azx_dev); |
| 1851 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1854 | static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | { |
| 1856 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 1857 | struct azx *chip = apcm->chip; |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1858 | struct azx_dev *azx_dev; |
| 1859 | struct snd_pcm_substream *s; |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1860 | int rstart = 0, start, nsync = 0, sbits = 0; |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1861 | int nwait, timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Takashi Iwai | 1a8506d | 2012-10-16 15:10:08 +0200 | [diff] [blame] | 1863 | azx_dev = get_azx_dev(substream); |
| 1864 | trace_azx_pcm_trigger(chip, azx_dev, cmd); |
| 1865 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 1866 | if (dsp_is_locked(azx_dev) || !azx_dev->prepared) |
| 1867 | return -EPIPE; |
| 1868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | switch (cmd) { |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 1870 | case SNDRV_PCM_TRIGGER_START: |
| 1871 | rstart = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1873 | case SNDRV_PCM_TRIGGER_RESUME: |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1874 | start = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | break; |
| 1876 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Jaroslav Kysela | 4712319 | 2005-08-15 20:53:07 +0200 | [diff] [blame] | 1877 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | case SNDRV_PCM_TRIGGER_STOP: |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1879 | start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | break; |
| 1881 | default: |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1882 | return -EINVAL; |
| 1883 | } |
| 1884 | |
| 1885 | snd_pcm_group_for_each_entry(s, substream) { |
| 1886 | if (s->pcm->card != substream->pcm->card) |
| 1887 | continue; |
| 1888 | azx_dev = get_azx_dev(s); |
| 1889 | sbits |= 1 << azx_dev->index; |
| 1890 | nsync++; |
| 1891 | snd_pcm_trigger_done(s, substream); |
| 1892 | } |
| 1893 | |
| 1894 | spin_lock(&chip->reg_lock); |
Pierre-Louis Bossart | 172d3b2 | 2012-09-21 18:39:05 -0500 | [diff] [blame] | 1895 | |
| 1896 | /* first, set SYNC bits of corresponding streams */ |
| 1897 | if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) |
| 1898 | azx_writel(chip, OLD_SSYNC, |
| 1899 | azx_readl(chip, OLD_SSYNC) | sbits); |
| 1900 | else |
| 1901 | azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) | sbits); |
| 1902 | |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1903 | snd_pcm_group_for_each_entry(s, substream) { |
| 1904 | if (s->pcm->card != substream->pcm->card) |
| 1905 | continue; |
| 1906 | azx_dev = get_azx_dev(s); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1907 | if (start) { |
| 1908 | azx_dev->start_wallclk = azx_readl(chip, WALLCLK); |
| 1909 | if (!rstart) |
| 1910 | azx_dev->start_wallclk -= |
| 1911 | azx_dev->period_wallclk; |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1912 | azx_stream_start(chip, azx_dev); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1913 | } else { |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1914 | azx_stream_stop(chip, azx_dev); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 1915 | } |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1916 | azx_dev->running = start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
| 1918 | spin_unlock(&chip->reg_lock); |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1919 | if (start) { |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1920 | /* wait until all FIFOs get ready */ |
| 1921 | for (timeout = 5000; timeout; timeout--) { |
| 1922 | nwait = 0; |
| 1923 | snd_pcm_group_for_each_entry(s, substream) { |
| 1924 | if (s->pcm->card != substream->pcm->card) |
| 1925 | continue; |
| 1926 | azx_dev = get_azx_dev(s); |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1927 | if (!(azx_sd_readb(chip, azx_dev, SD_STS) & |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1928 | SD_STS_FIFO_READY)) |
| 1929 | nwait++; |
| 1930 | } |
| 1931 | if (!nwait) |
| 1932 | break; |
| 1933 | cpu_relax(); |
| 1934 | } |
| 1935 | } else { |
| 1936 | /* wait until all RUN bits are cleared */ |
| 1937 | for (timeout = 5000; timeout; timeout--) { |
| 1938 | nwait = 0; |
| 1939 | snd_pcm_group_for_each_entry(s, substream) { |
| 1940 | if (s->pcm->card != substream->pcm->card) |
| 1941 | continue; |
| 1942 | azx_dev = get_azx_dev(s); |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1943 | if (azx_sd_readb(chip, azx_dev, SD_CTL) & |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1944 | SD_CTL_DMA_START) |
| 1945 | nwait++; |
| 1946 | } |
| 1947 | if (!nwait) |
| 1948 | break; |
| 1949 | cpu_relax(); |
| 1950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | } |
Pierre-Louis Bossart | 172d3b2 | 2012-09-21 18:39:05 -0500 | [diff] [blame] | 1952 | spin_lock(&chip->reg_lock); |
| 1953 | /* reset SYNC bits */ |
| 1954 | if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC) |
| 1955 | azx_writel(chip, OLD_SSYNC, |
| 1956 | azx_readl(chip, OLD_SSYNC) & ~sbits); |
| 1957 | else |
| 1958 | azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) & ~sbits); |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 1959 | if (start) { |
| 1960 | azx_timecounter_init(substream, 0, 0); |
| 1961 | if (nsync > 1) { |
| 1962 | cycle_t cycle_last; |
| 1963 | |
| 1964 | /* same start cycle for master and group */ |
| 1965 | azx_dev = get_azx_dev(substream); |
| 1966 | cycle_last = azx_dev->azx_tc.cycle_last; |
| 1967 | |
| 1968 | snd_pcm_group_for_each_entry(s, substream) { |
| 1969 | if (s->pcm->card != substream->pcm->card) |
| 1970 | continue; |
| 1971 | azx_timecounter_init(s, 1, cycle_last); |
| 1972 | } |
| 1973 | } |
| 1974 | } |
Pierre-Louis Bossart | 172d3b2 | 2012-09-21 18:39:05 -0500 | [diff] [blame] | 1975 | spin_unlock(&chip->reg_lock); |
Takashi Iwai | 850f0e5 | 2008-03-18 17:11:05 +0100 | [diff] [blame] | 1976 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
Joseph Chan | 0e15347 | 2008-08-26 14:38:03 +0200 | [diff] [blame] | 1979 | /* get the current DMA position with correction on VIA chips */ |
| 1980 | static unsigned int azx_via_get_position(struct azx *chip, |
| 1981 | struct azx_dev *azx_dev) |
| 1982 | { |
| 1983 | unsigned int link_pos, mini_pos, bound_pos; |
| 1984 | unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos; |
| 1985 | unsigned int fifo_size; |
| 1986 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 1987 | link_pos = azx_sd_readl(chip, azx_dev, SD_LPIB); |
Takashi Iwai | b4a655e | 2011-06-07 12:26:56 +0200 | [diff] [blame] | 1988 | if (azx_dev->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Joseph Chan | 0e15347 | 2008-08-26 14:38:03 +0200 | [diff] [blame] | 1989 | /* Playback, no problem using link position */ |
| 1990 | return link_pos; |
| 1991 | } |
| 1992 | |
| 1993 | /* Capture */ |
| 1994 | /* For new chipset, |
| 1995 | * use mod to get the DMA position just like old chipset |
| 1996 | */ |
| 1997 | mod_dma_pos = le32_to_cpu(*azx_dev->posbuf); |
| 1998 | mod_dma_pos %= azx_dev->period_bytes; |
| 1999 | |
| 2000 | /* azx_dev->fifo_size can't get FIFO size of in stream. |
| 2001 | * Get from base address + offset. |
| 2002 | */ |
| 2003 | fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET); |
| 2004 | |
| 2005 | if (azx_dev->insufficient) { |
| 2006 | /* Link position never gather than FIFO size */ |
| 2007 | if (link_pos <= fifo_size) |
| 2008 | return 0; |
| 2009 | |
| 2010 | azx_dev->insufficient = 0; |
| 2011 | } |
| 2012 | |
| 2013 | if (link_pos <= fifo_size) |
| 2014 | mini_pos = azx_dev->bufsize + link_pos - fifo_size; |
| 2015 | else |
| 2016 | mini_pos = link_pos - fifo_size; |
| 2017 | |
| 2018 | /* Find nearest previous boudary */ |
| 2019 | mod_mini_pos = mini_pos % azx_dev->period_bytes; |
| 2020 | mod_link_pos = link_pos % azx_dev->period_bytes; |
| 2021 | if (mod_link_pos >= fifo_size) |
| 2022 | bound_pos = link_pos - mod_link_pos; |
| 2023 | else if (mod_dma_pos >= mod_mini_pos) |
| 2024 | bound_pos = mini_pos - mod_mini_pos; |
| 2025 | else { |
| 2026 | bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes; |
| 2027 | if (bound_pos >= azx_dev->bufsize) |
| 2028 | bound_pos = 0; |
| 2029 | } |
| 2030 | |
| 2031 | /* Calculate real DMA position we want */ |
| 2032 | return bound_pos + mod_dma_pos; |
| 2033 | } |
| 2034 | |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2035 | static unsigned int azx_get_position(struct azx *chip, |
Takashi Iwai | 798cb7e | 2011-09-30 08:52:26 +0200 | [diff] [blame] | 2036 | struct azx_dev *azx_dev, |
| 2037 | bool with_check) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | { |
Takashi Iwai | 2122961 | 2013-04-05 07:27:45 +0200 | [diff] [blame] | 2039 | struct snd_pcm_substream *substream = azx_dev->substream; |
| 2040 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | unsigned int pos; |
Takashi Iwai | 2122961 | 2013-04-05 07:27:45 +0200 | [diff] [blame] | 2042 | int stream = substream->stream; |
| 2043 | struct hda_pcm_stream *hinfo = apcm->hinfo[stream]; |
Takashi Iwai | 1a8506d | 2012-10-16 15:10:08 +0200 | [diff] [blame] | 2044 | int delay = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 2046 | switch (chip->position_fix[stream]) { |
| 2047 | case POS_FIX_LPIB: |
| 2048 | /* read LPIB */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2049 | pos = azx_sd_readl(chip, azx_dev, SD_LPIB); |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 2050 | break; |
| 2051 | case POS_FIX_VIACOMBO: |
Joseph Chan | 0e15347 | 2008-08-26 14:38:03 +0200 | [diff] [blame] | 2052 | pos = azx_via_get_position(chip, azx_dev); |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 2053 | break; |
| 2054 | default: |
| 2055 | /* use the position buffer */ |
| 2056 | pos = le32_to_cpu(*azx_dev->posbuf); |
Takashi Iwai | 798cb7e | 2011-09-30 08:52:26 +0200 | [diff] [blame] | 2057 | if (with_check && chip->position_fix[stream] == POS_FIX_AUTO) { |
Takashi Iwai | a810364 | 2011-06-07 12:23:23 +0200 | [diff] [blame] | 2058 | if (!pos || pos == (u32)-1) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2059 | dev_info(chip->card->dev, |
| 2060 | "Invalid position buffer, using LPIB read method instead.\n"); |
Takashi Iwai | a810364 | 2011-06-07 12:23:23 +0200 | [diff] [blame] | 2061 | chip->position_fix[stream] = POS_FIX_LPIB; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2062 | pos = azx_sd_readl(chip, azx_dev, SD_LPIB); |
Takashi Iwai | a810364 | 2011-06-07 12:23:23 +0200 | [diff] [blame] | 2063 | } else |
| 2064 | chip->position_fix[stream] = POS_FIX_POSBUF; |
| 2065 | } |
| 2066 | break; |
Takashi Iwai | c74db86 | 2005-05-12 14:26:27 +0200 | [diff] [blame] | 2067 | } |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 2068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | if (pos >= azx_dev->bufsize) |
| 2070 | pos = 0; |
Pierre-Louis Bossart | 90accc5 | 2012-09-21 18:39:06 -0500 | [diff] [blame] | 2071 | |
| 2072 | /* calculate runtime delay from LPIB */ |
Takashi Iwai | 2122961 | 2013-04-05 07:27:45 +0200 | [diff] [blame] | 2073 | if (substream->runtime && |
Pierre-Louis Bossart | 90accc5 | 2012-09-21 18:39:06 -0500 | [diff] [blame] | 2074 | chip->position_fix[stream] == POS_FIX_POSBUF && |
| 2075 | (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) { |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2076 | unsigned int lpib_pos = azx_sd_readl(chip, azx_dev, SD_LPIB); |
Pierre-Louis Bossart | 90accc5 | 2012-09-21 18:39:06 -0500 | [diff] [blame] | 2077 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 2078 | delay = pos - lpib_pos; |
| 2079 | else |
| 2080 | delay = lpib_pos - pos; |
Takashi Iwai | e8648e5 | 2013-12-06 17:15:01 +0100 | [diff] [blame] | 2081 | if (delay < 0) { |
| 2082 | if (delay >= azx_dev->delay_negative_threshold) |
| 2083 | delay = 0; |
| 2084 | else |
| 2085 | delay += azx_dev->bufsize; |
| 2086 | } |
Pierre-Louis Bossart | 90accc5 | 2012-09-21 18:39:06 -0500 | [diff] [blame] | 2087 | if (delay >= azx_dev->period_bytes) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2088 | dev_info(chip->card->dev, |
| 2089 | "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n", |
| 2090 | delay, azx_dev->period_bytes); |
Takashi Iwai | 1f04661 | 2012-10-16 16:52:26 +0200 | [diff] [blame] | 2091 | delay = 0; |
| 2092 | chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY; |
Pierre-Louis Bossart | 90accc5 | 2012-09-21 18:39:06 -0500 | [diff] [blame] | 2093 | } |
Takashi Iwai | 2122961 | 2013-04-05 07:27:45 +0200 | [diff] [blame] | 2094 | delay = bytes_to_frames(substream->runtime, delay); |
Pierre-Louis Bossart | 90accc5 | 2012-09-21 18:39:06 -0500 | [diff] [blame] | 2095 | } |
Takashi Iwai | 2122961 | 2013-04-05 07:27:45 +0200 | [diff] [blame] | 2096 | |
| 2097 | if (substream->runtime) { |
| 2098 | if (hinfo->ops.get_delay) |
| 2099 | delay += hinfo->ops.get_delay(hinfo, apcm->codec, |
| 2100 | substream); |
| 2101 | substream->runtime->delay = delay; |
| 2102 | } |
| 2103 | |
Takashi Iwai | 1a8506d | 2012-10-16 15:10:08 +0200 | [diff] [blame] | 2104 | trace_azx_get_position(chip, azx_dev, pos, delay); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2105 | return pos; |
| 2106 | } |
| 2107 | |
| 2108 | static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) |
| 2109 | { |
| 2110 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 2111 | struct azx *chip = apcm->chip; |
| 2112 | struct azx_dev *azx_dev = get_azx_dev(substream); |
| 2113 | return bytes_to_frames(substream->runtime, |
Takashi Iwai | 798cb7e | 2011-09-30 08:52:26 +0200 | [diff] [blame] | 2114 | azx_get_position(chip, azx_dev, false)); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | /* |
| 2118 | * Check whether the current DMA position is acceptable for updating |
| 2119 | * periods. Returns non-zero if it's OK. |
| 2120 | * |
| 2121 | * Many HD-audio controllers appear pretty inaccurate about |
| 2122 | * the update-IRQ timing. The IRQ is issued before actually the |
| 2123 | * data is processed. So, we need to process it afterwords in a |
| 2124 | * workqueue. |
| 2125 | */ |
| 2126 | static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) |
| 2127 | { |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 2128 | u32 wallclk; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2129 | unsigned int pos; |
| 2130 | |
Jaroslav Kysela | f48f606 | 2010-05-11 12:10:47 +0200 | [diff] [blame] | 2131 | wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk; |
| 2132 | if (wallclk < (azx_dev->period_wallclk * 2) / 3) |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 2133 | return -1; /* bogus (too early) interrupt */ |
Jaroslav Kysela | fa00e04 | 2009-04-10 12:20:45 +0200 | [diff] [blame] | 2134 | |
Takashi Iwai | 798cb7e | 2011-09-30 08:52:26 +0200 | [diff] [blame] | 2135 | pos = azx_get_position(chip, azx_dev, true); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2136 | |
Takashi Iwai | d6d8bf5 | 2010-02-12 18:17:06 +0100 | [diff] [blame] | 2137 | if (WARN_ONCE(!azx_dev->period_bytes, |
| 2138 | "hda-intel: zero azx_dev->period_bytes")) |
Jaroslav Kysela | f48f606 | 2010-05-11 12:10:47 +0200 | [diff] [blame] | 2139 | return -1; /* this shouldn't happen! */ |
Jaroslav Kysela | edb3993 | 2010-06-02 13:29:17 +0200 | [diff] [blame] | 2140 | if (wallclk < (azx_dev->period_wallclk * 5) / 4 && |
Jaroslav Kysela | f48f606 | 2010-05-11 12:10:47 +0200 | [diff] [blame] | 2141 | pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) |
| 2142 | /* NG - it's below the first next period boundary */ |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 2143 | return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1; |
Jaroslav Kysela | edb3993 | 2010-06-02 13:29:17 +0200 | [diff] [blame] | 2144 | azx_dev->start_wallclk += wallclk; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2145 | return 1; /* OK, it's fine */ |
| 2146 | } |
| 2147 | |
| 2148 | /* |
| 2149 | * The work for pending PCM period updates. |
| 2150 | */ |
| 2151 | static void azx_irq_pending_work(struct work_struct *work) |
| 2152 | { |
| 2153 | struct azx *chip = container_of(work, struct azx, irq_pending_work); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 2154 | int i, pending, ok; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2155 | |
Takashi Iwai | a6a950a | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 2156 | if (!chip->irq_pending_warned) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2157 | dev_info(chip->card->dev, |
| 2158 | "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n", |
| 2159 | chip->card->number); |
Takashi Iwai | a6a950a | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 2160 | chip->irq_pending_warned = 1; |
| 2161 | } |
| 2162 | |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2163 | for (;;) { |
| 2164 | pending = 0; |
| 2165 | spin_lock_irq(&chip->reg_lock); |
| 2166 | for (i = 0; i < chip->num_streams; i++) { |
| 2167 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
| 2168 | if (!azx_dev->irq_pending || |
| 2169 | !azx_dev->substream || |
| 2170 | !azx_dev->running) |
| 2171 | continue; |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 2172 | ok = azx_position_ok(chip, azx_dev); |
| 2173 | if (ok > 0) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2174 | azx_dev->irq_pending = 0; |
| 2175 | spin_unlock(&chip->reg_lock); |
| 2176 | snd_pcm_period_elapsed(azx_dev->substream); |
| 2177 | spin_lock(&chip->reg_lock); |
Jaroslav Kysela | e546372 | 2010-05-11 10:21:46 +0200 | [diff] [blame] | 2178 | } else if (ok < 0) { |
| 2179 | pending = 0; /* too early */ |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2180 | } else |
| 2181 | pending++; |
| 2182 | } |
| 2183 | spin_unlock_irq(&chip->reg_lock); |
| 2184 | if (!pending) |
| 2185 | return; |
Takashi Iwai | 08af495 | 2010-08-03 14:39:04 +0200 | [diff] [blame] | 2186 | msleep(1); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | /* clear irq_pending flags and assure no on-going workq */ |
| 2191 | static void azx_clear_irq_pending(struct azx *chip) |
| 2192 | { |
| 2193 | int i; |
| 2194 | |
| 2195 | spin_lock_irq(&chip->reg_lock); |
| 2196 | for (i = 0; i < chip->num_streams; i++) |
| 2197 | chip->azx_dev[i].irq_pending = 0; |
| 2198 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2201 | #ifdef CONFIG_X86 |
| 2202 | static int azx_pcm_mmap(struct snd_pcm_substream *substream, |
| 2203 | struct vm_area_struct *area) |
| 2204 | { |
| 2205 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); |
| 2206 | struct azx *chip = apcm->chip; |
| 2207 | if (!azx_snoop(chip)) |
| 2208 | area->vm_page_prot = pgprot_writecombine(area->vm_page_prot); |
| 2209 | return snd_pcm_lib_default_mmap(substream, area); |
| 2210 | } |
| 2211 | #else |
| 2212 | #define azx_pcm_mmap NULL |
| 2213 | #endif |
| 2214 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2215 | static struct snd_pcm_ops azx_pcm_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | .open = azx_pcm_open, |
| 2217 | .close = azx_pcm_close, |
| 2218 | .ioctl = snd_pcm_lib_ioctl, |
| 2219 | .hw_params = azx_pcm_hw_params, |
| 2220 | .hw_free = azx_pcm_hw_free, |
| 2221 | .prepare = azx_pcm_prepare, |
| 2222 | .trigger = azx_pcm_trigger, |
| 2223 | .pointer = azx_pcm_pointer, |
Pierre-Louis Bossart | 5d890f5 | 2012-10-22 16:42:16 -0500 | [diff] [blame] | 2224 | .wall_clock = azx_get_wallclock_tstamp, |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2225 | .mmap = azx_pcm_mmap, |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2226 | .page = snd_pcm_sgbuf_ops_page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | }; |
| 2228 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2229 | static void azx_pcm_free(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | { |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2231 | struct azx_pcm *apcm = pcm->private_data; |
| 2232 | if (apcm) { |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2233 | list_del(&apcm->list); |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2234 | kfree(apcm); |
| 2235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Takashi Iwai | acfa634 | 2011-07-12 17:27:46 +0200 | [diff] [blame] | 2238 | #define MAX_PREALLOC_SIZE (32 * 1024 * 1024) |
| 2239 | |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2240 | static int |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 2241 | azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, |
| 2242 | struct hda_pcm *cpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 2244 | struct azx *chip = bus->private_data; |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2245 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | struct azx_pcm *apcm; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2247 | int pcm_dev = cpcm->device; |
Takashi Iwai | acfa634 | 2011-07-12 17:27:46 +0200 | [diff] [blame] | 2248 | unsigned int size; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2249 | int s, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2251 | list_for_each_entry(apcm, &chip->pcm_list, list) { |
| 2252 | if (apcm->pcm->device == pcm_dev) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2253 | dev_err(chip->card->dev, "PCM %d already exists\n", |
| 2254 | pcm_dev); |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2255 | return -EBUSY; |
| 2256 | } |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2257 | } |
| 2258 | err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, |
| 2259 | cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams, |
| 2260 | cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | &pcm); |
| 2262 | if (err < 0) |
| 2263 | return err; |
Takashi Iwai | 18cb710 | 2009-04-16 10:22:24 +0200 | [diff] [blame] | 2264 | strlcpy(pcm->name, cpcm->name, sizeof(pcm->name)); |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2265 | apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | if (apcm == NULL) |
| 2267 | return -ENOMEM; |
| 2268 | apcm->chip = chip; |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2269 | apcm->pcm = pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | apcm->codec = codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | pcm->private_data = apcm; |
| 2272 | pcm->private_free = azx_pcm_free; |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2273 | if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) |
| 2274 | pcm->dev_class = SNDRV_PCM_CLASS_MODEM; |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2275 | list_add_tail(&apcm->list, &chip->pcm_list); |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2276 | cpcm->pcm = pcm; |
| 2277 | for (s = 0; s < 2; s++) { |
| 2278 | apcm->hinfo[s] = &cpcm->stream[s]; |
| 2279 | if (cpcm->stream[s].substreams) |
| 2280 | snd_pcm_set_ops(pcm, s, &azx_pcm_ops); |
| 2281 | } |
| 2282 | /* buffer pre-allocation */ |
Takashi Iwai | acfa634 | 2011-07-12 17:27:46 +0200 | [diff] [blame] | 2283 | size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024; |
| 2284 | if (size > MAX_PREALLOC_SIZE) |
| 2285 | size = MAX_PREALLOC_SIZE; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2286 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2287 | chip->card->dev, |
Takashi Iwai | acfa634 | 2011-07-12 17:27:46 +0200 | [diff] [blame] | 2288 | size, MAX_PREALLOC_SIZE); |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 2289 | /* link to codec */ |
| 2290 | pcm->dev = &codec->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | return 0; |
| 2292 | } |
| 2293 | |
| 2294 | /* |
| 2295 | * mixer creation - all stuff is implemented in hda module |
| 2296 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2297 | static int azx_mixer_create(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | { |
| 2299 | return snd_hda_build_controls(chip->bus); |
| 2300 | } |
| 2301 | |
| 2302 | |
| 2303 | /* |
| 2304 | * initialize SD streams |
| 2305 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2306 | static int azx_init_stream(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | { |
| 2308 | int i; |
| 2309 | |
| 2310 | /* initialize each stream (aka device) |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 2311 | * assign the starting bdl address to each stream (device) |
| 2312 | * and initialize |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | */ |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2314 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2315 | struct azx_dev *azx_dev = &chip->azx_dev[i]; |
Takashi Iwai | 929861c | 2006-08-31 16:55:40 +0200 | [diff] [blame] | 2316 | azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ |
| 2318 | azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); |
| 2319 | /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ |
| 2320 | azx_dev->sd_int_sta_mask = 1 << i; |
| 2321 | /* stream tag: must be non-zero and unique */ |
| 2322 | azx_dev->index = i; |
| 2323 | azx_dev->stream_tag = i + 1; |
| 2324 | } |
| 2325 | |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2329 | static int azx_acquire_irq(struct azx *chip, int do_disconnect) |
| 2330 | { |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 2331 | if (request_irq(chip->pci->irq, azx_interrupt, |
| 2332 | chip->msi ? 0 : IRQF_SHARED, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 2333 | KBUILD_MODNAME, chip)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2334 | dev_err(chip->card->dev, |
| 2335 | "unable to grab IRQ %d, disabling device\n", |
| 2336 | chip->pci->irq); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2337 | if (do_disconnect) |
| 2338 | snd_card_disconnect(chip->card); |
| 2339 | return -1; |
| 2340 | } |
| 2341 | chip->irq = chip->pci->irq; |
Takashi Iwai | 69e1341 | 2006-11-21 12:10:55 +0100 | [diff] [blame] | 2342 | pci_intx(chip->pci, !chip->msi); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2343 | return 0; |
| 2344 | } |
| 2345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2347 | static void azx_stop_chip(struct azx *chip) |
| 2348 | { |
Takashi Iwai | 95e99fd | 2007-08-13 15:29:04 +0200 | [diff] [blame] | 2349 | if (!chip->initialized) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2350 | return; |
| 2351 | |
| 2352 | /* disable interrupts */ |
| 2353 | azx_int_disable(chip); |
| 2354 | azx_int_clear(chip); |
| 2355 | |
| 2356 | /* disable CORB/RIRB */ |
| 2357 | azx_free_cmd_io(chip); |
| 2358 | |
| 2359 | /* disable position buffer */ |
| 2360 | azx_writel(chip, DPLBASE, 0); |
| 2361 | azx_writel(chip, DPUBASE, 0); |
| 2362 | |
| 2363 | chip->initialized = 0; |
| 2364 | } |
| 2365 | |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2366 | #ifdef CONFIG_SND_HDA_DSP_LOADER |
| 2367 | /* |
| 2368 | * DSP loading code (e.g. for CA0132) |
| 2369 | */ |
| 2370 | |
| 2371 | /* use the first stream for loading DSP */ |
| 2372 | static struct azx_dev * |
| 2373 | azx_get_dsp_loader_dev(struct azx *chip) |
| 2374 | { |
| 2375 | return &chip->azx_dev[chip->playback_index_offset]; |
| 2376 | } |
| 2377 | |
| 2378 | static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format, |
| 2379 | unsigned int byte_size, |
| 2380 | struct snd_dma_buffer *bufp) |
| 2381 | { |
| 2382 | u32 *bdl; |
| 2383 | struct azx *chip = bus->private_data; |
| 2384 | struct azx_dev *azx_dev; |
| 2385 | int err; |
| 2386 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2387 | azx_dev = azx_get_dsp_loader_dev(chip); |
| 2388 | |
| 2389 | dsp_lock(azx_dev); |
| 2390 | spin_lock_irq(&chip->reg_lock); |
| 2391 | if (azx_dev->running || azx_dev->locked) { |
| 2392 | spin_unlock_irq(&chip->reg_lock); |
| 2393 | err = -EBUSY; |
| 2394 | goto unlock; |
| 2395 | } |
| 2396 | azx_dev->prepared = 0; |
| 2397 | chip->saved_azx_dev = *azx_dev; |
| 2398 | azx_dev->locked = 1; |
| 2399 | spin_unlock_irq(&chip->reg_lock); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2400 | |
| 2401 | err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2402 | chip->card->dev, |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2403 | byte_size, bufp); |
| 2404 | if (err < 0) |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2405 | goto err_alloc; |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2406 | |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 2407 | mark_pages_wc(chip, bufp, true); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2408 | azx_dev->bufsize = byte_size; |
| 2409 | azx_dev->period_bytes = byte_size; |
| 2410 | azx_dev->format_val = format; |
| 2411 | |
| 2412 | azx_stream_reset(chip, azx_dev); |
| 2413 | |
| 2414 | /* reset BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2415 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); |
| 2416 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2417 | |
| 2418 | azx_dev->frags = 0; |
| 2419 | bdl = (u32 *)azx_dev->bdl.area; |
| 2420 | err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0); |
| 2421 | if (err < 0) |
| 2422 | goto error; |
| 2423 | |
| 2424 | azx_setup_controller(chip, azx_dev); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2425 | dsp_unlock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2426 | return azx_dev->stream_tag; |
| 2427 | |
| 2428 | error: |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 2429 | mark_pages_wc(chip, bufp, false); |
| 2430 | snd_dma_free_pages(bufp); |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2431 | err_alloc: |
| 2432 | spin_lock_irq(&chip->reg_lock); |
| 2433 | if (azx_dev->opened) |
| 2434 | *azx_dev = chip->saved_azx_dev; |
| 2435 | azx_dev->locked = 0; |
| 2436 | spin_unlock_irq(&chip->reg_lock); |
| 2437 | unlock: |
| 2438 | dsp_unlock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2439 | return err; |
| 2440 | } |
| 2441 | |
| 2442 | static void azx_load_dsp_trigger(struct hda_bus *bus, bool start) |
| 2443 | { |
| 2444 | struct azx *chip = bus->private_data; |
| 2445 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
| 2446 | |
| 2447 | if (start) |
| 2448 | azx_stream_start(chip, azx_dev); |
| 2449 | else |
| 2450 | azx_stream_stop(chip, azx_dev); |
| 2451 | azx_dev->running = start; |
| 2452 | } |
| 2453 | |
| 2454 | static void azx_load_dsp_cleanup(struct hda_bus *bus, |
| 2455 | struct snd_dma_buffer *dmab) |
| 2456 | { |
| 2457 | struct azx *chip = bus->private_data; |
| 2458 | struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip); |
| 2459 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2460 | if (!dmab->area || !azx_dev->locked) |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 2461 | return; |
| 2462 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2463 | dsp_lock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2464 | /* reset BDL address */ |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 2465 | azx_sd_writel(chip, azx_dev, SD_BDLPL, 0); |
| 2466 | azx_sd_writel(chip, azx_dev, SD_BDLPU, 0); |
| 2467 | azx_sd_writel(chip, azx_dev, SD_CTL, 0); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2468 | azx_dev->bufsize = 0; |
| 2469 | azx_dev->period_bytes = 0; |
| 2470 | azx_dev->format_val = 0; |
| 2471 | |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 2472 | mark_pages_wc(chip, dmab, false); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2473 | snd_dma_free_pages(dmab); |
Takashi Iwai | b3667bd | 2013-02-10 11:58:40 +0100 | [diff] [blame] | 2474 | dmab->area = NULL; |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2475 | |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 2476 | spin_lock_irq(&chip->reg_lock); |
| 2477 | if (azx_dev->opened) |
| 2478 | *azx_dev = chip->saved_azx_dev; |
| 2479 | azx_dev->locked = 0; |
| 2480 | spin_unlock_irq(&chip->reg_lock); |
| 2481 | dsp_unlock(azx_dev); |
Takashi Iwai | 1d1a456 | 2012-09-20 20:29:13 -0700 | [diff] [blame] | 2482 | } |
| 2483 | #endif /* CONFIG_SND_HDA_DSP_LOADER */ |
| 2484 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 2485 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2486 | /* power-up/down the controller */ |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 2487 | static void azx_power_notify(struct hda_bus *bus, bool power_up) |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2488 | { |
Takashi Iwai | 33fa35e | 2008-11-06 16:50:40 +0100 | [diff] [blame] | 2489 | struct azx *chip = bus->private_data; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2490 | |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 2491 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 2492 | return; |
| 2493 | |
Takashi Iwai | 68467f5 | 2012-08-28 09:14:29 -0700 | [diff] [blame] | 2494 | if (power_up) |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2495 | pm_runtime_get_sync(chip->card->dev); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2496 | else |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2497 | pm_runtime_put_sync(chip->card->dev); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2498 | } |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 2499 | |
| 2500 | static DEFINE_MUTEX(card_list_lock); |
| 2501 | static LIST_HEAD(card_list); |
| 2502 | |
| 2503 | static void azx_add_card_list(struct azx *chip) |
| 2504 | { |
| 2505 | mutex_lock(&card_list_lock); |
| 2506 | list_add(&chip->list, &card_list); |
| 2507 | mutex_unlock(&card_list_lock); |
| 2508 | } |
| 2509 | |
| 2510 | static void azx_del_card_list(struct azx *chip) |
| 2511 | { |
| 2512 | mutex_lock(&card_list_lock); |
| 2513 | list_del_init(&chip->list); |
| 2514 | mutex_unlock(&card_list_lock); |
| 2515 | } |
| 2516 | |
| 2517 | /* trigger power-save check at writing parameter */ |
| 2518 | static int param_set_xint(const char *val, const struct kernel_param *kp) |
| 2519 | { |
| 2520 | struct azx *chip; |
| 2521 | struct hda_codec *c; |
| 2522 | int prev = power_save; |
| 2523 | int ret = param_set_int(val, kp); |
| 2524 | |
| 2525 | if (ret || prev == power_save) |
| 2526 | return ret; |
| 2527 | |
| 2528 | mutex_lock(&card_list_lock); |
| 2529 | list_for_each_entry(chip, &card_list, list) { |
| 2530 | if (!chip->bus || chip->disabled) |
| 2531 | continue; |
| 2532 | list_for_each_entry(c, &chip->bus->codec_list, list) |
| 2533 | snd_hda_power_sync(c); |
| 2534 | } |
| 2535 | mutex_unlock(&card_list_lock); |
| 2536 | return 0; |
| 2537 | } |
| 2538 | #else |
| 2539 | #define azx_add_card_list(chip) /* NOP */ |
| 2540 | #define azx_del_card_list(chip) /* NOP */ |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 2541 | #endif /* CONFIG_PM */ |
Takashi Iwai | 5c0b9be | 2008-12-11 11:47:17 +0100 | [diff] [blame] | 2542 | |
Takashi Iwai | 7ccbde5 | 2012-08-14 18:10:09 +0200 | [diff] [blame] | 2543 | #if defined(CONFIG_PM_SLEEP) || defined(SUPPORT_VGA_SWITCHEROO) |
Takashi Iwai | 5c0b9be | 2008-12-11 11:47:17 +0100 | [diff] [blame] | 2544 | /* |
| 2545 | * power management |
| 2546 | */ |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2547 | static int azx_suspend(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2549 | struct pci_dev *pci = to_pci_dev(dev); |
| 2550 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 2551 | struct azx *chip = card->private_data; |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2552 | struct azx_pcm *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | |
Takashi Iwai | c5c2152 | 2012-12-04 17:01:25 +0100 | [diff] [blame] | 2554 | if (chip->disabled) |
| 2555 | return 0; |
| 2556 | |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 2557 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2558 | azx_clear_irq_pending(chip); |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 2559 | list_for_each_entry(p, &chip->pcm_list, list) |
| 2560 | snd_pcm_suspend_all(p->pcm); |
Takashi Iwai | 0b7a2e9 | 2007-08-14 15:18:26 +0200 | [diff] [blame] | 2561 | if (chip->initialized) |
Takashi Iwai | 8dd7833 | 2009-06-02 01:16:07 +0200 | [diff] [blame] | 2562 | snd_hda_suspend(chip->bus); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2563 | azx_stop_chip(chip); |
Mengdong Lin | 7295b26 | 2013-06-25 05:58:49 -0400 | [diff] [blame] | 2564 | azx_enter_link_reset(chip); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2565 | if (chip->irq >= 0) { |
Takashi Iwai | 43001c9 | 2006-09-08 12:30:03 +0200 | [diff] [blame] | 2566 | free_irq(chip->irq, chip); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2567 | chip->irq = -1; |
| 2568 | } |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2569 | if (chip->msi) |
Takashi Iwai | 43001c9 | 2006-09-08 12:30:03 +0200 | [diff] [blame] | 2570 | pci_disable_msi(chip->pci); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 2571 | pci_disable_device(pci); |
| 2572 | pci_save_state(pci); |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2573 | pci_set_power_state(pci, PCI_D3hot); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2574 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 2575 | hda_display_power(false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | return 0; |
| 2577 | } |
| 2578 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2579 | static int azx_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2581 | struct pci_dev *pci = to_pci_dev(dev); |
| 2582 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 2583 | struct azx *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | |
Takashi Iwai | c5c2152 | 2012-12-04 17:01:25 +0100 | [diff] [blame] | 2585 | if (chip->disabled) |
| 2586 | return 0; |
| 2587 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2588 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 2589 | hda_display_power(true); |
Takashi Iwai | d14a7e0 | 2009-02-16 10:13:03 +0100 | [diff] [blame] | 2590 | pci_set_power_state(pci, PCI_D0); |
| 2591 | pci_restore_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2592 | if (pci_enable_device(pci) < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2593 | dev_err(chip->card->dev, |
| 2594 | "pci_enable_device failed, disabling device\n"); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2595 | snd_card_disconnect(card); |
| 2596 | return -EIO; |
| 2597 | } |
| 2598 | pci_set_master(pci); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2599 | if (chip->msi) |
| 2600 | if (pci_enable_msi(pci) < 0) |
| 2601 | chip->msi = 0; |
| 2602 | if (azx_acquire_irq(chip, 1) < 0) |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2603 | return -EIO; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2604 | azx_init_pci(chip); |
Maxim Levitsky | d804ad9 | 2007-09-03 15:28:04 +0200 | [diff] [blame] | 2605 | |
Takashi Iwai | 7f30830 | 2012-05-08 16:52:23 +0200 | [diff] [blame] | 2606 | azx_init_chip(chip, 1); |
Maxim Levitsky | d804ad9 | 2007-09-03 15:28:04 +0200 | [diff] [blame] | 2607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | snd_hda_resume(chip->bus); |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 2609 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | return 0; |
| 2611 | } |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2612 | #endif /* CONFIG_PM_SLEEP || SUPPORT_VGA_SWITCHEROO */ |
| 2613 | |
| 2614 | #ifdef CONFIG_PM_RUNTIME |
| 2615 | static int azx_runtime_suspend(struct device *dev) |
| 2616 | { |
| 2617 | struct snd_card *card = dev_get_drvdata(dev); |
| 2618 | struct azx *chip = card->private_data; |
| 2619 | |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 2620 | if (chip->disabled) |
| 2621 | return 0; |
| 2622 | |
| 2623 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 2624 | return 0; |
| 2625 | |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 2626 | /* enable controller wake up event */ |
| 2627 | azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) | |
| 2628 | STATESTS_INT_MASK); |
| 2629 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2630 | azx_stop_chip(chip); |
Takashi Iwai | 873ce8a | 2013-11-26 11:58:40 +0100 | [diff] [blame] | 2631 | azx_enter_link_reset(chip); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2632 | azx_clear_irq_pending(chip); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2633 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 2634 | hda_display_power(false); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2635 | return 0; |
| 2636 | } |
| 2637 | |
| 2638 | static int azx_runtime_resume(struct device *dev) |
| 2639 | { |
| 2640 | struct snd_card *card = dev_get_drvdata(dev); |
| 2641 | struct azx *chip = card->private_data; |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 2642 | struct hda_bus *bus; |
| 2643 | struct hda_codec *codec; |
| 2644 | int status; |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2645 | |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 2646 | if (chip->disabled) |
| 2647 | return 0; |
| 2648 | |
| 2649 | if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 2650 | return 0; |
| 2651 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2652 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
| 2653 | hda_display_power(true); |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 2654 | |
| 2655 | /* Read STATESTS before controller reset */ |
| 2656 | status = azx_readw(chip, STATESTS); |
| 2657 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2658 | azx_init_pci(chip); |
| 2659 | azx_init_chip(chip, 1); |
Wang Xingchao | 7d4f606 | 2013-07-25 23:34:46 -0400 | [diff] [blame] | 2660 | |
| 2661 | bus = chip->bus; |
| 2662 | if (status && bus) { |
| 2663 | list_for_each_entry(codec, &bus->codec_list, list) |
| 2664 | if (status & (1 << codec->addr)) |
| 2665 | queue_delayed_work(codec->bus->workq, |
| 2666 | &codec->jackpoll_work, codec->jackpoll_interval); |
| 2667 | } |
| 2668 | |
| 2669 | /* disable controller Wake Up event*/ |
| 2670 | azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & |
| 2671 | ~STATESTS_INT_MASK); |
| 2672 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2673 | return 0; |
| 2674 | } |
Takashi Iwai | 6eb827d | 2012-12-12 11:50:12 +0100 | [diff] [blame] | 2675 | |
| 2676 | static int azx_runtime_idle(struct device *dev) |
| 2677 | { |
| 2678 | struct snd_card *card = dev_get_drvdata(dev); |
| 2679 | struct azx *chip = card->private_data; |
| 2680 | |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 2681 | if (chip->disabled) |
| 2682 | return 0; |
| 2683 | |
Takashi Iwai | 6eb827d | 2012-12-12 11:50:12 +0100 | [diff] [blame] | 2684 | if (!power_save_controller || |
| 2685 | !(chip->driver_caps & AZX_DCAPS_PM_RUNTIME)) |
| 2686 | return -EBUSY; |
| 2687 | |
| 2688 | return 0; |
| 2689 | } |
| 2690 | |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2691 | #endif /* CONFIG_PM_RUNTIME */ |
| 2692 | |
| 2693 | #ifdef CONFIG_PM |
| 2694 | static const struct dev_pm_ops azx_pm = { |
| 2695 | SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) |
Takashi Iwai | 6eb827d | 2012-12-12 11:50:12 +0100 | [diff] [blame] | 2696 | 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] | 2697 | }; |
| 2698 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2699 | #define AZX_PM_OPS &azx_pm |
| 2700 | #else |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 2701 | #define AZX_PM_OPS NULL |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 2702 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | |
| 2704 | |
| 2705 | /* |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 2706 | * reboot notifier for hang-up problem at power-down |
| 2707 | */ |
| 2708 | static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) |
| 2709 | { |
| 2710 | struct azx *chip = container_of(nb, struct azx, reboot_notifier); |
Takashi Iwai | fb8d1a3 | 2009-11-10 16:02:29 +0100 | [diff] [blame] | 2711 | snd_hda_bus_reboot_notify(chip->bus); |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 2712 | azx_stop_chip(chip); |
| 2713 | return NOTIFY_OK; |
| 2714 | } |
| 2715 | |
| 2716 | static void azx_notifier_register(struct azx *chip) |
| 2717 | { |
| 2718 | chip->reboot_notifier.notifier_call = azx_halt; |
| 2719 | register_reboot_notifier(&chip->reboot_notifier); |
| 2720 | } |
| 2721 | |
| 2722 | static void azx_notifier_unregister(struct azx *chip) |
| 2723 | { |
| 2724 | if (chip->reboot_notifier.notifier_call) |
| 2725 | unregister_reboot_notifier(&chip->reboot_notifier); |
| 2726 | } |
| 2727 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 2728 | static int azx_probe_continue(struct azx *chip); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2729 | |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 2730 | #ifdef SUPPORT_VGA_SWITCHEROO |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2731 | static struct pci_dev *get_bound_vga(struct pci_dev *pci); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2732 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2733 | static void azx_vs_set_state(struct pci_dev *pci, |
| 2734 | enum vga_switcheroo_state state) |
| 2735 | { |
| 2736 | struct snd_card *card = pci_get_drvdata(pci); |
| 2737 | struct azx *chip = card->private_data; |
| 2738 | bool disabled; |
| 2739 | |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2740 | wait_for_completion(&chip->probe_wait); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2741 | if (chip->init_failed) |
| 2742 | return; |
| 2743 | |
| 2744 | disabled = (state == VGA_SWITCHEROO_OFF); |
| 2745 | if (chip->disabled == disabled) |
| 2746 | return; |
| 2747 | |
| 2748 | if (!chip->bus) { |
| 2749 | chip->disabled = disabled; |
| 2750 | if (!disabled) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2751 | dev_info(chip->card->dev, |
| 2752 | "Start delayed initialization\n"); |
Takashi Iwai | 5c90680 | 2013-05-30 22:07:09 +0800 | [diff] [blame] | 2753 | if (azx_probe_continue(chip) < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2754 | dev_err(chip->card->dev, "initialization error\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2755 | chip->init_failed = true; |
| 2756 | } |
| 2757 | } |
| 2758 | } else { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2759 | dev_info(chip->card->dev, "%s via VGA-switcheroo\n", |
| 2760 | disabled ? "Disabling" : "Enabling"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2761 | if (disabled) { |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2762 | pm_runtime_put_sync_suspend(card->dev); |
| 2763 | azx_suspend(card->dev); |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 2764 | /* when we get suspended by vga switcheroo we end up in D3cold, |
| 2765 | * however we have no ACPI handle, so pci/acpi can't put us there, |
| 2766 | * put ourselves there */ |
| 2767 | pci->current_state = PCI_D3cold; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2768 | chip->disabled = true; |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 2769 | if (snd_hda_lock_devices(chip->bus)) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2770 | dev_warn(chip->card->dev, |
| 2771 | "Cannot lock devices!\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2772 | } else { |
| 2773 | snd_hda_unlock_devices(chip->bus); |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2774 | pm_runtime_get_noresume(card->dev); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2775 | chip->disabled = false; |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2776 | azx_resume(card->dev); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | static bool azx_vs_can_switch(struct pci_dev *pci) |
| 2782 | { |
| 2783 | struct snd_card *card = pci_get_drvdata(pci); |
| 2784 | struct azx *chip = card->private_data; |
| 2785 | |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2786 | wait_for_completion(&chip->probe_wait); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2787 | if (chip->init_failed) |
| 2788 | return false; |
| 2789 | if (chip->disabled || !chip->bus) |
| 2790 | return true; |
| 2791 | if (snd_hda_lock_devices(chip->bus)) |
| 2792 | return false; |
| 2793 | snd_hda_unlock_devices(chip->bus); |
| 2794 | return true; |
| 2795 | } |
| 2796 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2797 | static void init_vga_switcheroo(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2798 | { |
| 2799 | struct pci_dev *p = get_bound_vga(chip->pci); |
| 2800 | if (p) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2801 | dev_info(chip->card->dev, |
| 2802 | "Handle VGA-switcheroo audio client\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2803 | chip->use_vga_switcheroo = 1; |
| 2804 | pci_dev_put(p); |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | static const struct vga_switcheroo_client_ops azx_vs_ops = { |
| 2809 | .set_gpu_state = azx_vs_set_state, |
| 2810 | .can_switch = azx_vs_can_switch, |
| 2811 | }; |
| 2812 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2813 | static int register_vga_switcheroo(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2814 | { |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 2815 | int err; |
| 2816 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2817 | if (!chip->use_vga_switcheroo) |
| 2818 | return 0; |
| 2819 | /* FIXME: currently only handling DIS controller |
| 2820 | * is there any machine with two switchable HDMI audio controllers? |
| 2821 | */ |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 2822 | err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2823 | VGA_SWITCHEROO_DIS, |
| 2824 | chip->bus != NULL); |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 2825 | if (err < 0) |
| 2826 | return err; |
| 2827 | chip->vga_switcheroo_registered = 1; |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 2828 | |
| 2829 | /* register as an optimus hdmi audio power domain */ |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 2830 | vga_switcheroo_init_domain_pm_optimus_hdmi_audio(chip->card->dev, |
| 2831 | &chip->hdmi_pm_domain); |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 2832 | return 0; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2833 | } |
| 2834 | #else |
| 2835 | #define init_vga_switcheroo(chip) /* NOP */ |
| 2836 | #define register_vga_switcheroo(chip) 0 |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 2837 | #define check_hdmi_disabled(pci) false |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2838 | #endif /* SUPPORT_VGA_SWITCHER */ |
| 2839 | |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 2840 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | * destructor |
| 2842 | */ |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2843 | static int azx_free(struct azx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | { |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 2845 | struct pci_dev *pci = chip->pci; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2846 | int i; |
| 2847 | |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 2848 | if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) |
| 2849 | && chip->running) |
| 2850 | pm_runtime_get_noresume(&pci->dev); |
| 2851 | |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 2852 | azx_del_card_list(chip); |
| 2853 | |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 2854 | azx_notifier_unregister(chip); |
| 2855 | |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2856 | chip->init_failed = 1; /* to be sure */ |
Daniel J Blueman | 44728e9 | 2012-12-18 23:59:33 +0800 | [diff] [blame] | 2857 | complete_all(&chip->probe_wait); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 2858 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2859 | if (use_vga_switcheroo(chip)) { |
| 2860 | if (chip->disabled && chip->bus) |
| 2861 | snd_hda_unlock_devices(chip->bus); |
Takashi Iwai | 128960a | 2012-10-12 17:28:18 +0200 | [diff] [blame] | 2862 | if (chip->vga_switcheroo_registered) |
| 2863 | vga_switcheroo_unregister_client(chip->pci); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2864 | } |
| 2865 | |
Takashi Iwai | ce43fba | 2005-05-30 20:33:44 +0200 | [diff] [blame] | 2866 | if (chip->initialized) { |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 2867 | azx_clear_irq_pending(chip); |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2868 | for (i = 0; i < chip->num_streams; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | azx_stream_stop(chip, &chip->azx_dev[i]); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2870 | azx_stop_chip(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
Jeff Garzik | f000fd8 | 2008-04-22 13:50:34 +0200 | [diff] [blame] | 2873 | if (chip->irq >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | free_irq(chip->irq, (void*)chip); |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 2875 | if (chip->msi) |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2876 | pci_disable_msi(chip->pci); |
Takashi Iwai | f079c25 | 2006-06-01 11:42:14 +0200 | [diff] [blame] | 2877 | if (chip->remap_addr) |
| 2878 | iounmap(chip->remap_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2880 | if (chip->azx_dev) { |
| 2881 | for (i = 0; i < chip->num_streams; i++) |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2882 | if (chip->azx_dev[i].bdl.area) { |
| 2883 | mark_pages_wc(chip, &chip->azx_dev[i].bdl, false); |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2884 | snd_dma_free_pages(&chip->azx_dev[i].bdl); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2885 | } |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 2886 | } |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2887 | if (chip->rb.area) { |
| 2888 | mark_pages_wc(chip, &chip->rb, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | snd_dma_free_pages(&chip->rb); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2890 | } |
| 2891 | if (chip->posbuf.area) { |
| 2892 | mark_pages_wc(chip, &chip->posbuf, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | snd_dma_free_pages(&chip->posbuf); |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 2894 | } |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 2895 | if (chip->region_requested) |
| 2896 | pci_release_regions(chip->pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | pci_disable_device(chip->pci); |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 2898 | kfree(chip->azx_dev); |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 2899 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 2900 | if (chip->fw) |
| 2901 | release_firmware(chip->fw); |
| 2902 | #endif |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 2903 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
| 2904 | hda_display_power(false); |
| 2905 | hda_i915_exit(); |
| 2906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | kfree(chip); |
| 2908 | |
| 2909 | return 0; |
| 2910 | } |
| 2911 | |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 2912 | static int azx_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | { |
| 2914 | return azx_free(device->device_data); |
| 2915 | } |
| 2916 | |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 2917 | #ifdef SUPPORT_VGA_SWITCHEROO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | /* |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2919 | * Check of disabled HDMI controller by vga-switcheroo |
| 2920 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2921 | static struct pci_dev *get_bound_vga(struct pci_dev *pci) |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2922 | { |
| 2923 | struct pci_dev *p; |
| 2924 | |
| 2925 | /* check only discrete GPU */ |
| 2926 | switch (pci->vendor) { |
| 2927 | case PCI_VENDOR_ID_ATI: |
| 2928 | case PCI_VENDOR_ID_AMD: |
| 2929 | case PCI_VENDOR_ID_NVIDIA: |
| 2930 | if (pci->devfn == 1) { |
| 2931 | p = pci_get_domain_bus_and_slot(pci_domain_nr(pci->bus), |
| 2932 | pci->bus->number, 0); |
| 2933 | if (p) { |
| 2934 | if ((p->class >> 8) == PCI_CLASS_DISPLAY_VGA) |
| 2935 | return p; |
| 2936 | pci_dev_put(p); |
| 2937 | } |
| 2938 | } |
| 2939 | break; |
| 2940 | } |
| 2941 | return NULL; |
| 2942 | } |
| 2943 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2944 | static bool check_hdmi_disabled(struct pci_dev *pci) |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2945 | { |
| 2946 | bool vga_inactive = false; |
| 2947 | struct pci_dev *p = get_bound_vga(pci); |
| 2948 | |
| 2949 | if (p) { |
Takashi Iwai | 12b78a7 | 2012-06-07 12:15:16 +0200 | [diff] [blame] | 2950 | if (vga_switcheroo_get_client_state(p) == VGA_SWITCHEROO_OFF) |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2951 | vga_inactive = true; |
| 2952 | pci_dev_put(p); |
| 2953 | } |
| 2954 | return vga_inactive; |
| 2955 | } |
Steven Newbury | 8393ec4a | 2012-06-08 13:06:29 +0200 | [diff] [blame] | 2956 | #endif /* SUPPORT_VGA_SWITCHEROO */ |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 2957 | |
| 2958 | /* |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 2959 | * white/black-listing for position_fix |
| 2960 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2961 | static struct snd_pci_quirk position_fix_list[] = { |
Takashi Iwai | d2e1c97 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 2962 | SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), |
| 2963 | SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), |
Takashi Iwai | 2f703e7 | 2009-12-01 14:17:37 +0100 | [diff] [blame] | 2964 | SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB), |
Takashi Iwai | d2e1c97 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 2965 | SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), |
Daniel T Chen | dd37f8e | 2010-05-30 01:17:03 -0400 | [diff] [blame] | 2966 | SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB), |
Daniel T Chen | 9f75c1b | 2010-05-30 13:08:41 -0400 | [diff] [blame] | 2967 | SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB), |
Daniel T Chen | e96d312 | 2010-05-27 18:32:18 -0400 | [diff] [blame] | 2968 | SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB), |
David Henningsson | b01de4f | 2012-01-12 16:31:14 +0100 | [diff] [blame] | 2969 | 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] | 2970 | SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB), |
Daniel T Chen | 9ec8dda | 2010-03-28 02:34:40 -0400 | [diff] [blame] | 2971 | SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB), |
Takashi Iwai | 45d4ebf | 2009-11-30 11:58:30 +0100 | [diff] [blame] | 2972 | SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB), |
Takashi Iwai | 8815cd0 | 2010-04-15 09:02:41 +0200 | [diff] [blame] | 2973 | SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB), |
Daniel T Chen | b90c076 | 2010-05-30 19:31:41 -0400 | [diff] [blame] | 2974 | SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB), |
Daniel T Chen | 0e0280d | 2010-04-21 19:55:43 -0400 | [diff] [blame] | 2975 | SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB), |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 2976 | {} |
| 2977 | }; |
| 2978 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2979 | static int check_position_fix(struct azx *chip, int fix) |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 2980 | { |
| 2981 | const struct snd_pci_quirk *q; |
| 2982 | |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 2983 | switch (fix) { |
Takashi Iwai | 1dac669 | 2012-09-13 14:59:47 +0200 | [diff] [blame] | 2984 | case POS_FIX_AUTO: |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 2985 | case POS_FIX_LPIB: |
| 2986 | case POS_FIX_POSBUF: |
David Henningsson | 4cb3631 | 2010-09-30 10:12:50 +0200 | [diff] [blame] | 2987 | case POS_FIX_VIACOMBO: |
Takashi Iwai | a6f2fd5 | 2012-02-28 11:58:40 +0100 | [diff] [blame] | 2988 | case POS_FIX_COMBO: |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 2989 | return fix; |
| 2990 | } |
| 2991 | |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 2992 | q = snd_pci_quirk_lookup(chip->pci, position_fix_list); |
| 2993 | if (q) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 2994 | dev_info(chip->card->dev, |
| 2995 | "position_fix set to %d for device %04x:%04x\n", |
| 2996 | q->value, q->subvendor, q->subdevice); |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 2997 | return q->value; |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 2998 | } |
David Henningsson | bdd9ef2 | 2010-10-04 12:02:14 +0200 | [diff] [blame] | 2999 | |
| 3000 | /* Check VIA/ATI HD Audio Controller exist */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3001 | if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3002 | dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n"); |
David Henningsson | bdd9ef2 | 2010-10-04 12:02:14 +0200 | [diff] [blame] | 3003 | return POS_FIX_VIACOMBO; |
| 3004 | } |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3005 | if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3006 | dev_dbg(chip->card->dev, "Using LPIB position fix\n"); |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3007 | return POS_FIX_LPIB; |
| 3008 | } |
Takashi Iwai | c673ba1 | 2009-03-17 07:49:14 +0100 | [diff] [blame] | 3009 | return POS_FIX_AUTO; |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | /* |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3013 | * black-lists for probe_mask |
| 3014 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3015 | static struct snd_pci_quirk probe_mask_list[] = { |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3016 | /* Thinkpad often breaks the controller communication when accessing |
| 3017 | * to the non-working (or non-existing) modem codec slot. |
| 3018 | */ |
| 3019 | SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01), |
| 3020 | SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01), |
| 3021 | SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01), |
Takashi Iwai | 0edb945 | 2008-11-07 14:53:09 +0100 | [diff] [blame] | 3022 | /* broken BIOS */ |
| 3023 | SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01), |
Takashi Iwai | ef1681d | 2008-11-24 17:29:28 +0100 | [diff] [blame] | 3024 | /* including bogus ALC268 in slot#2 that conflicts with ALC888 */ |
| 3025 | SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01), |
Takashi Iwai | 20db7cb | 2009-02-13 08:18:48 +0100 | [diff] [blame] | 3026 | /* forced codec slots */ |
Ozan Çağlayan | 9357484 | 2009-05-23 15:00:04 +0300 | [diff] [blame] | 3027 | SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), |
Takashi Iwai | 20db7cb | 2009-02-13 08:18:48 +0100 | [diff] [blame] | 3028 | SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), |
Jaroslav Kysela | f3af905 | 2012-04-26 17:52:35 +0200 | [diff] [blame] | 3029 | /* WinFast VP200 H (Teradici) user reported broken communication */ |
| 3030 | SND_PCI_QUIRK(0x3a21, 0x040d, "WinFast VP200 H", 0x101), |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3031 | {} |
| 3032 | }; |
| 3033 | |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 3034 | #define AZX_FORCE_CODEC_MASK 0x100 |
| 3035 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3036 | static void check_probe_mask(struct azx *chip, int dev) |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3037 | { |
| 3038 | const struct snd_pci_quirk *q; |
| 3039 | |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 3040 | chip->codec_probe_mask = probe_mask[dev]; |
| 3041 | if (chip->codec_probe_mask == -1) { |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3042 | q = snd_pci_quirk_lookup(chip->pci, probe_mask_list); |
| 3043 | if (q) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3044 | dev_info(chip->card->dev, |
| 3045 | "probe_mask set to 0x%x for device %04x:%04x\n", |
| 3046 | q->value, q->subvendor, q->subdevice); |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 3047 | chip->codec_probe_mask = q->value; |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3048 | } |
| 3049 | } |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 3050 | |
| 3051 | /* check forced option */ |
| 3052 | if (chip->codec_probe_mask != -1 && |
| 3053 | (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { |
| 3054 | chip->codec_mask = chip->codec_probe_mask & 0xff; |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3055 | dev_info(chip->card->dev, "codec_mask forced to 0x%x\n", |
| 3056 | chip->codec_mask); |
Takashi Iwai | f1eaaee | 2009-02-13 08:16:55 +0100 | [diff] [blame] | 3057 | } |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3058 | } |
| 3059 | |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3060 | /* |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 3061 | * white/black-list for enable_msi |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3062 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3063 | static struct snd_pci_quirk msi_black_list[] = { |
David Henningsson | 693e0cb | 2013-12-12 09:52:03 +0100 | [diff] [blame] | 3064 | SND_PCI_QUIRK(0x103c, 0x2191, "HP", 0), /* AMD Hudson */ |
| 3065 | SND_PCI_QUIRK(0x103c, 0x2192, "HP", 0), /* AMD Hudson */ |
| 3066 | SND_PCI_QUIRK(0x103c, 0x21f7, "HP", 0), /* AMD Hudson */ |
| 3067 | SND_PCI_QUIRK(0x103c, 0x21fa, "HP", 0), /* AMD Hudson */ |
Takashi Iwai | 9dc8398 | 2009-12-22 08:15:01 +0100 | [diff] [blame] | 3068 | SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */ |
Takashi Iwai | 0a27fcf | 2010-02-15 17:05:28 +0100 | [diff] [blame] | 3069 | SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */ |
Ralf Gerbig | ecd2162 | 2010-03-09 18:25:47 +0100 | [diff] [blame] | 3070 | SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */ |
Takashi Iwai | 83f7215 | 2013-09-09 10:20:48 +0200 | [diff] [blame] | 3071 | SND_PCI_QUIRK(0x1179, 0xfb44, "Toshiba Satellite C870", 0), /* AMD Hudson */ |
Michele Ballabio | 4193d13 | 2010-03-06 21:06:46 +0100 | [diff] [blame] | 3072 | SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */ |
Takashi Iwai | 3815595 | 2010-04-04 12:14:03 +0200 | [diff] [blame] | 3073 | SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */ |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3074 | {} |
| 3075 | }; |
| 3076 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3077 | static void check_msi(struct azx *chip) |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3078 | { |
| 3079 | const struct snd_pci_quirk *q; |
| 3080 | |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 3081 | if (enable_msi >= 0) { |
| 3082 | chip->msi = !!enable_msi; |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3083 | return; |
Takashi Iwai | 71623855 | 2009-09-28 13:14:04 +0200 | [diff] [blame] | 3084 | } |
| 3085 | chip->msi = 1; /* enable MSI as default */ |
| 3086 | q = snd_pci_quirk_lookup(chip->pci, msi_black_list); |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3087 | if (q) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3088 | dev_info(chip->card->dev, |
| 3089 | "msi for device %04x:%04x set to %d\n", |
| 3090 | q->subvendor, q->subdevice, q->value); |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3091 | chip->msi = q->value; |
Takashi Iwai | 80c43ed | 2010-03-15 15:51:53 +0100 | [diff] [blame] | 3092 | return; |
| 3093 | } |
| 3094 | |
| 3095 | /* NVidia chipsets seem to cause troubles with MSI */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3096 | if (chip->driver_caps & AZX_DCAPS_NO_MSI) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3097 | dev_info(chip->card->dev, "Disabling MSI\n"); |
Takashi Iwai | 80c43ed | 2010-03-15 15:51:53 +0100 | [diff] [blame] | 3098 | chip->msi = 0; |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 3102 | /* check the snoop mode availability */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3103 | static void azx_check_snoop_available(struct azx *chip) |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 3104 | { |
| 3105 | bool snoop = chip->snoop; |
| 3106 | |
| 3107 | switch (chip->driver_type) { |
| 3108 | case AZX_DRIVER_VIA: |
| 3109 | /* force to non-snoop mode for a new VIA controller |
| 3110 | * when BIOS is set |
| 3111 | */ |
| 3112 | if (snoop) { |
| 3113 | u8 val; |
| 3114 | pci_read_config_byte(chip->pci, 0x42, &val); |
| 3115 | if (!(val & 0x80) && chip->pci->revision == 0x30) |
| 3116 | snoop = false; |
| 3117 | } |
| 3118 | break; |
| 3119 | case AZX_DRIVER_ATIHDMI_NS: |
| 3120 | /* new ATI HDMI requires non-snoop */ |
| 3121 | snoop = false; |
| 3122 | break; |
Takashi Iwai | c1279f8 | 2013-02-07 17:36:22 +0100 | [diff] [blame] | 3123 | case AZX_DRIVER_CTHDA: |
| 3124 | snoop = false; |
| 3125 | break; |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | if (snoop != chip->snoop) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3129 | dev_info(chip->card->dev, "Force to %s mode\n", |
| 3130 | snoop ? "snoop" : "non-snoop"); |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 3131 | chip->snoop = snoop; |
| 3132 | } |
| 3133 | } |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3134 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3135 | static void azx_probe_work(struct work_struct *work) |
| 3136 | { |
| 3137 | azx_probe_continue(container_of(work, struct azx, probe_work)); |
| 3138 | } |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3139 | |
Takashi Iwai | 669ba27 | 2007-08-17 09:17:36 +0200 | [diff] [blame] | 3140 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | * constructor |
| 3142 | */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3143 | static int azx_create(struct snd_card *card, struct pci_dev *pci, |
| 3144 | int dev, unsigned int driver_caps, |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 3145 | const struct hda_controller_ops *hda_ops, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3146 | struct azx **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | { |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 3148 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | .dev_free = azx_dev_free, |
| 3150 | }; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3151 | struct azx *chip; |
| 3152 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | |
| 3154 | *rchip = NULL; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3155 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3156 | err = pci_enable_device(pci); |
| 3157 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | return err; |
| 3159 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 3160 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3161 | if (!chip) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3162 | dev_err(card->dev, "Cannot allocate chip\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | pci_disable_device(pci); |
| 3164 | return -ENOMEM; |
| 3165 | } |
| 3166 | |
| 3167 | spin_lock_init(&chip->reg_lock); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 3168 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | chip->card = card; |
| 3170 | chip->pci = pci; |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 3171 | chip->ops = hda_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | chip->irq = -1; |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3173 | chip->driver_caps = driver_caps; |
| 3174 | chip->driver_type = driver_caps & 0xff; |
Takashi Iwai | 4d8e22e | 2009-08-11 14:21:26 +0200 | [diff] [blame] | 3175 | check_msi(chip); |
Takashi Iwai | 555e219 | 2008-06-10 17:53:34 +0200 | [diff] [blame] | 3176 | chip->dev_index = dev; |
Dylan Reid | 749ee28 | 2014-02-28 15:41:18 -0800 | [diff] [blame] | 3177 | chip->jackpoll_ms = jackpoll_ms; |
Takashi Iwai | 9ad593f | 2008-05-16 12:34:47 +0200 | [diff] [blame] | 3178 | INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); |
Takashi Iwai | 01b65bf | 2011-11-24 14:31:46 +0100 | [diff] [blame] | 3179 | INIT_LIST_HEAD(&chip->pcm_list); |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 3180 | INIT_LIST_HEAD(&chip->list); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3181 | init_vga_switcheroo(chip); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 3182 | init_completion(&chip->probe_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | |
Shahin Ghazinouri | beaffc3 | 2010-05-11 08:19:55 +0200 | [diff] [blame] | 3184 | chip->position_fix[0] = chip->position_fix[1] = |
| 3185 | check_position_fix(chip, position_fix[dev]); |
Takashi Iwai | a6f2fd5 | 2012-02-28 11:58:40 +0100 | [diff] [blame] | 3186 | /* combo mode uses LPIB for playback */ |
| 3187 | if (chip->position_fix[0] == POS_FIX_COMBO) { |
| 3188 | chip->position_fix[0] = POS_FIX_LPIB; |
| 3189 | chip->position_fix[1] = POS_FIX_AUTO; |
| 3190 | } |
| 3191 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 3192 | check_probe_mask(chip, dev); |
Takashi Iwai | 3372a15 | 2007-02-01 15:46:50 +0100 | [diff] [blame] | 3193 | |
Takashi Iwai | 2734616 | 2006-01-12 18:28:44 +0100 | [diff] [blame] | 3194 | chip->single_cmd = single_cmd; |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 3195 | chip->snoop = hda_snoop; |
Takashi Iwai | a1585d7 | 2011-12-14 09:27:04 +0100 | [diff] [blame] | 3196 | azx_check_snoop_available(chip); |
Takashi Iwai | c74db86 | 2005-05-12 14:26:27 +0200 | [diff] [blame] | 3197 | |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 3198 | if (bdl_pos_adj[dev] < 0) { |
| 3199 | switch (chip->driver_type) { |
Takashi Iwai | 0c6341a | 2008-06-13 20:50:27 +0200 | [diff] [blame] | 3200 | case AZX_DRIVER_ICH: |
Seth Heasley | 32679f9 | 2010-02-22 17:31:09 -0800 | [diff] [blame] | 3201 | case AZX_DRIVER_PCH: |
Takashi Iwai | 0c6341a | 2008-06-13 20:50:27 +0200 | [diff] [blame] | 3202 | bdl_pos_adj[dev] = 1; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 3203 | break; |
| 3204 | default: |
Takashi Iwai | 0c6341a | 2008-06-13 20:50:27 +0200 | [diff] [blame] | 3205 | bdl_pos_adj[dev] = 32; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 3206 | break; |
| 3207 | } |
| 3208 | } |
Dylan Reid | 9cdc011 | 2014-02-28 15:41:14 -0800 | [diff] [blame] | 3209 | chip->bdl_pos_adj = bdl_pos_adj; |
Takashi Iwai | 5c0d7bc | 2008-06-10 17:53:35 +0200 | [diff] [blame] | 3210 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3211 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
| 3212 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3213 | dev_err(card->dev, "Error creating device [card]!\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3214 | azx_free(chip); |
| 3215 | return err; |
| 3216 | } |
| 3217 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3218 | /* continue probing in work context as may trigger request module */ |
| 3219 | INIT_WORK(&chip->probe_work, azx_probe_work); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3220 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3221 | *rchip = chip; |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3222 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3223 | return 0; |
| 3224 | } |
| 3225 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 3226 | static int azx_first_init(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3227 | { |
| 3228 | int dev = chip->dev_index; |
| 3229 | struct pci_dev *pci = chip->pci; |
| 3230 | struct snd_card *card = chip->card; |
| 3231 | int i, err; |
| 3232 | unsigned short gcap; |
| 3233 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 3234 | #if BITS_PER_LONG != 64 |
| 3235 | /* Fix up base address on ULI M5461 */ |
| 3236 | if (chip->driver_type == AZX_DRIVER_ULI) { |
| 3237 | u16 tmp3; |
| 3238 | pci_read_config_word(pci, 0x40, &tmp3); |
| 3239 | pci_write_config_word(pci, 0x40, tmp3 | 0x10); |
| 3240 | pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0); |
| 3241 | } |
| 3242 | #endif |
| 3243 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3244 | err = pci_request_regions(pci, "ICH HD audio"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3245 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | return err; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3247 | chip->region_requested = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3249 | chip->addr = pci_resource_start(pci, 0); |
Arjan van de Ven | 2f5ad54 | 2008-09-28 16:20:09 -0700 | [diff] [blame] | 3250 | chip->remap_addr = pci_ioremap_bar(pci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | if (chip->remap_addr == NULL) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3252 | dev_err(card->dev, "ioremap error\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3253 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
Takashi Iwai | 68e7fff | 2006-10-23 13:40:59 +0200 | [diff] [blame] | 3256 | if (chip->msi) |
| 3257 | if (pci_enable_msi(pci) < 0) |
| 3258 | chip->msi = 0; |
Stephen Hemminger | 7376d01 | 2006-08-21 19:17:46 +0200 | [diff] [blame] | 3259 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3260 | if (azx_acquire_irq(chip, 0) < 0) |
| 3261 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | |
| 3263 | pci_set_master(pci); |
| 3264 | synchronize_irq(chip->irq); |
| 3265 | |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3266 | gcap = azx_readw(chip, GCAP); |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3267 | dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3268 | |
Andiry Brienza | dc4c2e6 | 2009-07-08 13:55:31 +0800 | [diff] [blame] | 3269 | /* disable SB600 64bit support for safety */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3270 | if (chip->pci->vendor == PCI_VENDOR_ID_ATI) { |
Andiry Brienza | dc4c2e6 | 2009-07-08 13:55:31 +0800 | [diff] [blame] | 3271 | struct pci_dev *p_smbus; |
| 3272 | p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, |
| 3273 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, |
| 3274 | NULL); |
| 3275 | if (p_smbus) { |
| 3276 | if (p_smbus->revision < 0x30) |
| 3277 | gcap &= ~ICH6_GCAP_64OK; |
| 3278 | pci_dev_put(p_smbus); |
| 3279 | } |
| 3280 | } |
Takashi Iwai | 09240cf | 2009-03-17 07:47:18 +0100 | [diff] [blame] | 3281 | |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3282 | /* disable 64bit DMA address on some devices */ |
| 3283 | if (chip->driver_caps & AZX_DCAPS_NO_64BIT) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3284 | dev_dbg(card->dev, "Disabling 64bit DMA\n"); |
Jaroslav Kysela | 396087e | 2009-12-09 10:44:47 +0100 | [diff] [blame] | 3285 | gcap &= ~ICH6_GCAP_64OK; |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3286 | } |
Jaroslav Kysela | 396087e | 2009-12-09 10:44:47 +0100 | [diff] [blame] | 3287 | |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3288 | /* disable buffer size rounding to 128-byte multiples if supported */ |
Takashi Iwai | 7bfe059 | 2012-01-23 17:53:39 +0100 | [diff] [blame] | 3289 | if (align_buffer_size >= 0) |
| 3290 | chip->align_buffer_size = !!align_buffer_size; |
| 3291 | else { |
| 3292 | if (chip->driver_caps & AZX_DCAPS_BUFSIZE) |
| 3293 | chip->align_buffer_size = 0; |
| 3294 | else if (chip->driver_caps & AZX_DCAPS_ALIGN_BUFSIZE) |
| 3295 | chip->align_buffer_size = 1; |
| 3296 | else |
| 3297 | chip->align_buffer_size = 1; |
| 3298 | } |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3299 | |
Takashi Iwai | cf7aaca | 2008-02-06 15:05:57 +0100 | [diff] [blame] | 3300 | /* allow 64bit DMA address if supported by H/W */ |
Takashi Iwai | b21fadb | 2009-05-28 12:26:15 +0200 | [diff] [blame] | 3301 | 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] | 3302 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); |
Takashi Iwai | 09240cf | 2009-03-17 07:47:18 +0100 | [diff] [blame] | 3303 | else { |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 3304 | pci_set_dma_mask(pci, DMA_BIT_MASK(32)); |
| 3305 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)); |
Takashi Iwai | 09240cf | 2009-03-17 07:47:18 +0100 | [diff] [blame] | 3306 | } |
Takashi Iwai | cf7aaca | 2008-02-06 15:05:57 +0100 | [diff] [blame] | 3307 | |
Takashi Iwai | 8b6ed8e | 2008-02-19 11:36:35 +0100 | [diff] [blame] | 3308 | /* read number of streams from GCAP register instead of using |
| 3309 | * hardcoded value |
| 3310 | */ |
| 3311 | chip->capture_streams = (gcap >> 8) & 0x0f; |
| 3312 | chip->playback_streams = (gcap >> 12) & 0x0f; |
| 3313 | if (!chip->playback_streams && !chip->capture_streams) { |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3314 | /* gcap didn't give any info, switching to old method */ |
| 3315 | |
| 3316 | switch (chip->driver_type) { |
| 3317 | case AZX_DRIVER_ULI: |
| 3318 | chip->playback_streams = ULI_NUM_PLAYBACK; |
| 3319 | chip->capture_streams = ULI_NUM_CAPTURE; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3320 | break; |
| 3321 | case AZX_DRIVER_ATIHDMI: |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 3322 | case AZX_DRIVER_ATIHDMI_NS: |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3323 | chip->playback_streams = ATIHDMI_NUM_PLAYBACK; |
| 3324 | chip->capture_streams = ATIHDMI_NUM_CAPTURE; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3325 | break; |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 3326 | case AZX_DRIVER_GENERIC: |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3327 | default: |
| 3328 | chip->playback_streams = ICH6_NUM_PLAYBACK; |
| 3329 | chip->capture_streams = ICH6_NUM_CAPTURE; |
Tobin Davis | bcd7200 | 2008-01-15 11:23:55 +0100 | [diff] [blame] | 3330 | break; |
| 3331 | } |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 3332 | } |
Takashi Iwai | 8b6ed8e | 2008-02-19 11:36:35 +0100 | [diff] [blame] | 3333 | chip->capture_index_offset = 0; |
| 3334 | chip->playback_index_offset = chip->capture_streams; |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 3335 | chip->num_streams = chip->playback_streams + chip->capture_streams; |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 3336 | chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), |
| 3337 | GFP_KERNEL); |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3338 | if (!chip->azx_dev) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3339 | dev_err(card->dev, "cannot malloc azx_dev\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3340 | return -ENOMEM; |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 3341 | } |
| 3342 | |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 3343 | for (i = 0; i < chip->num_streams; i++) { |
Takashi Iwai | eb49faa | 2013-03-15 09:19:11 +0100 | [diff] [blame] | 3344 | dsp_lock_init(&chip->azx_dev[i]); |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 3345 | /* allocate memory for the BDL for each stream */ |
| 3346 | err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 3347 | chip->card->dev, |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 3348 | BDL_SIZE, &chip->azx_dev[i].bdl); |
| 3349 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3350 | dev_err(card->dev, "cannot allocate BDL\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3351 | return -ENOMEM; |
Takashi Iwai | 4ce107b | 2008-02-06 14:50:19 +0100 | [diff] [blame] | 3352 | } |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 3353 | mark_pages_wc(chip, &chip->azx_dev[i].bdl, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | } |
Takashi Iwai | 0be3b5d | 2005-09-05 17:11:40 +0200 | [diff] [blame] | 3355 | /* allocate memory for the position buffer */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 3356 | err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, |
Dylan Reid | 8928756 | 2014-02-28 15:41:15 -0800 | [diff] [blame] | 3357 | chip->card->dev, |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 3358 | chip->num_streams * 8, &chip->posbuf); |
| 3359 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3360 | dev_err(card->dev, "cannot allocate posbuf\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3361 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | } |
Takashi Iwai | 27fe48d9 | 2011-09-28 17:16:09 +0200 | [diff] [blame] | 3363 | mark_pages_wc(chip, &chip->posbuf, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | /* allocate CORB/RIRB */ |
Takashi Iwai | 81740861 | 2009-05-26 15:22:00 +0200 | [diff] [blame] | 3365 | err = azx_alloc_cmd_io(chip); |
| 3366 | if (err < 0) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3367 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | |
| 3369 | /* initialize streams */ |
| 3370 | azx_init_stream(chip); |
| 3371 | |
| 3372 | /* initialize chip */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3373 | azx_init_pci(chip); |
Jaroslav Kysela | 10e77dd | 2010-03-26 11:04:38 +0100 | [diff] [blame] | 3374 | azx_init_chip(chip, (probe_only[dev] & 2) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | |
| 3376 | /* codec detection */ |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3377 | if (!chip->codec_mask) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3378 | dev_err(card->dev, "no codecs found!\n"); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3379 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 3382 | strcpy(card->driver, "HDA-Intel"); |
Takashi Iwai | 18cb710 | 2009-04-16 10:22:24 +0200 | [diff] [blame] | 3383 | strlcpy(card->shortname, driver_short_names[chip->driver_type], |
| 3384 | sizeof(card->shortname)); |
| 3385 | snprintf(card->longname, sizeof(card->longname), |
| 3386 | "%s at 0x%lx irq %i", |
| 3387 | card->shortname, chip->addr, chip->irq); |
Takashi Iwai | 07e4ca5 | 2005-08-24 14:14:57 +0200 | [diff] [blame] | 3388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3392 | static void power_down_all_codecs(struct azx *chip) |
| 3393 | { |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 3394 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3395 | /* The codecs were powered up in snd_hda_codec_new(). |
| 3396 | * Now all initialization done, so turn them down if possible |
| 3397 | */ |
| 3398 | struct hda_codec *codec; |
| 3399 | list_for_each_entry(codec, &chip->bus->codec_list, list) { |
| 3400 | snd_hda_power_down(codec); |
| 3401 | } |
| 3402 | #endif |
| 3403 | } |
| 3404 | |
Takashi Iwai | 97c6a3d | 2012-08-09 17:40:46 +0200 | [diff] [blame] | 3405 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 3406 | /* callback from request_firmware_nowait() */ |
| 3407 | static void azx_firmware_cb(const struct firmware *fw, void *context) |
| 3408 | { |
| 3409 | struct snd_card *card = context; |
| 3410 | struct azx *chip = card->private_data; |
| 3411 | struct pci_dev *pci = chip->pci; |
| 3412 | |
| 3413 | if (!fw) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3414 | dev_err(card->dev, "Cannot load firmware, aborting\n"); |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 3415 | goto error; |
| 3416 | } |
| 3417 | |
| 3418 | chip->fw = fw; |
| 3419 | if (!chip->disabled) { |
| 3420 | /* continue probing */ |
| 3421 | if (azx_probe_continue(chip)) |
| 3422 | goto error; |
| 3423 | } |
| 3424 | return; /* OK */ |
| 3425 | |
| 3426 | error: |
| 3427 | snd_card_free(card); |
| 3428 | pci_set_drvdata(pci, NULL); |
| 3429 | } |
Takashi Iwai | 97c6a3d | 2012-08-09 17:40:46 +0200 | [diff] [blame] | 3430 | #endif |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 3431 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 3432 | /* |
| 3433 | * HDA controller ops. |
| 3434 | */ |
| 3435 | |
| 3436 | /* PCI register access. */ |
| 3437 | static void pci_azx_writel(u32 value, u32 *addr) |
| 3438 | { |
| 3439 | writel(value, addr); |
| 3440 | } |
| 3441 | |
| 3442 | static u32 pci_azx_readl(u32 *addr) |
| 3443 | { |
| 3444 | return readl(addr); |
| 3445 | } |
| 3446 | |
| 3447 | static void pci_azx_writew(u16 value, u16 *addr) |
| 3448 | { |
| 3449 | writew(value, addr); |
| 3450 | } |
| 3451 | |
| 3452 | static u16 pci_azx_readw(u16 *addr) |
| 3453 | { |
| 3454 | return readw(addr); |
| 3455 | } |
| 3456 | |
| 3457 | static void pci_azx_writeb(u8 value, u8 *addr) |
| 3458 | { |
| 3459 | writeb(value, addr); |
| 3460 | } |
| 3461 | |
| 3462 | static u8 pci_azx_readb(u8 *addr) |
| 3463 | { |
| 3464 | return readb(addr); |
| 3465 | } |
| 3466 | |
Dylan Reid | f46ea60 | 2014-02-28 15:41:16 -0800 | [diff] [blame] | 3467 | static int disable_msi_reset_irq(struct azx *chip) |
| 3468 | { |
| 3469 | int err; |
| 3470 | |
| 3471 | free_irq(chip->irq, chip); |
| 3472 | chip->irq = -1; |
| 3473 | pci_disable_msi(chip->pci); |
| 3474 | chip->msi = 0; |
| 3475 | err = azx_acquire_irq(chip, 1); |
| 3476 | if (err < 0) |
| 3477 | return err; |
| 3478 | |
| 3479 | return 0; |
| 3480 | } |
| 3481 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 3482 | static const struct hda_controller_ops pci_hda_ops = { |
| 3483 | .writel = pci_azx_writel, |
| 3484 | .readl = pci_azx_readl, |
| 3485 | .writew = pci_azx_writew, |
| 3486 | .readw = pci_azx_readw, |
| 3487 | .writeb = pci_azx_writeb, |
| 3488 | .readb = pci_azx_readb, |
Dylan Reid | f46ea60 | 2014-02-28 15:41:16 -0800 | [diff] [blame] | 3489 | .disable_msi_reset_irq = disable_msi_reset_irq, |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 3490 | }; |
| 3491 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3492 | static int azx_probe(struct pci_dev *pci, |
| 3493 | const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | { |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 3495 | static int dev; |
Takashi Iwai | a98f90f | 2005-11-17 14:59:02 +0100 | [diff] [blame] | 3496 | struct snd_card *card; |
| 3497 | struct azx *chip; |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 3498 | bool schedule_probe; |
Pavel Machek | 927fc86 | 2006-08-31 17:03:43 +0200 | [diff] [blame] | 3499 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | |
Takashi Iwai | 5aba4f8 | 2008-01-07 15:16:37 +0100 | [diff] [blame] | 3501 | if (dev >= SNDRV_CARDS) |
| 3502 | return -ENODEV; |
| 3503 | if (!enable[dev]) { |
| 3504 | dev++; |
| 3505 | return -ENOENT; |
| 3506 | } |
| 3507 | |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 3508 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 3509 | 0, &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 3510 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3511 | dev_err(&pci->dev, "Error creating card!\n"); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 3512 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
Dylan Reid | 4083081 | 2014-02-28 15:41:13 -0800 | [diff] [blame] | 3515 | err = azx_create(card, pci, dev, pci_id->driver_data, |
| 3516 | &pci_hda_ops, &chip); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3517 | if (err < 0) |
| 3518 | goto out_free; |
Takashi Iwai | 421a125 | 2005-11-17 16:11:09 +0100 | [diff] [blame] | 3519 | card->private_data = chip; |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 3520 | |
| 3521 | pci_set_drvdata(pci, card); |
| 3522 | |
| 3523 | err = register_vga_switcheroo(chip); |
| 3524 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3525 | dev_err(card->dev, "Error registering VGA-switcheroo client\n"); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 3526 | goto out_free; |
| 3527 | } |
| 3528 | |
| 3529 | if (check_hdmi_disabled(pci)) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3530 | dev_info(card->dev, "VGA controller is disabled\n"); |
| 3531 | dev_info(card->dev, "Delaying initialization\n"); |
Takashi Iwai | f4c482a | 2012-12-04 15:09:23 +0100 | [diff] [blame] | 3532 | chip->disabled = true; |
| 3533 | } |
| 3534 | |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 3535 | schedule_probe = !chip->disabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 3537 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
| 3538 | if (patch[dev] && *patch[dev]) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3539 | dev_info(card->dev, "Applying patch firmware '%s'\n", |
| 3540 | patch[dev]); |
Takashi Iwai | 5cb543d | 2012-08-09 13:49:23 +0200 | [diff] [blame] | 3541 | err = request_firmware_nowait(THIS_MODULE, true, patch[dev], |
| 3542 | &pci->dev, GFP_KERNEL, card, |
| 3543 | azx_firmware_cb); |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 3544 | if (err < 0) |
| 3545 | goto out_free; |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 3546 | schedule_probe = false; /* continued in azx_firmware_cb() */ |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 3547 | } |
| 3548 | #endif /* CONFIG_SND_HDA_PATCH_LOADER */ |
| 3549 | |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 3550 | #ifndef CONFIG_SND_HDA_I915 |
| 3551 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3552 | 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] | 3553 | #endif |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3554 | |
Takashi Iwai | aad730d | 2013-12-02 13:33:57 +0100 | [diff] [blame] | 3555 | if (schedule_probe) |
| 3556 | schedule_work(&chip->probe_work); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3557 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3558 | dev++; |
Takashi Iwai | 88d071f | 2013-12-02 11:12:28 +0100 | [diff] [blame] | 3559 | if (chip->disabled) |
| 3560 | complete_all(&chip->probe_wait); |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3561 | return 0; |
| 3562 | |
| 3563 | out_free: |
| 3564 | snd_card_free(card); |
| 3565 | return err; |
| 3566 | } |
| 3567 | |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame^] | 3568 | /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ |
| 3569 | static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = { |
| 3570 | [AZX_DRIVER_NVIDIA] = 8, |
| 3571 | [AZX_DRIVER_TERA] = 1, |
| 3572 | }; |
| 3573 | |
Takashi Iwai | 48c8b0e | 2012-12-07 07:40:35 +0100 | [diff] [blame] | 3574 | static int azx_probe_continue(struct azx *chip) |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3575 | { |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 3576 | struct pci_dev *pci = chip->pci; |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3577 | int dev = chip->dev_index; |
| 3578 | int err; |
| 3579 | |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3580 | /* Request power well for Haswell HDA controller and codec */ |
| 3581 | if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { |
David Henningsson | c841ad2 | 2013-08-19 13:32:30 +0200 | [diff] [blame] | 3582 | #ifdef CONFIG_SND_HDA_I915 |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3583 | err = hda_i915_init(); |
| 3584 | if (err < 0) { |
Takashi Iwai | 4e76a88 | 2014-02-25 12:21:03 +0100 | [diff] [blame] | 3585 | dev_err(chip->card->dev, |
| 3586 | "Error request power-well from i915\n"); |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3587 | goto out_free; |
| 3588 | } |
David Henningsson | c841ad2 | 2013-08-19 13:32:30 +0200 | [diff] [blame] | 3589 | #endif |
Wang Xingchao | 99a2008 | 2013-05-30 22:07:10 +0800 | [diff] [blame] | 3590 | hda_display_power(true); |
| 3591 | } |
| 3592 | |
Takashi Iwai | 5c90680 | 2013-05-30 22:07:09 +0800 | [diff] [blame] | 3593 | err = azx_first_init(chip); |
| 3594 | if (err < 0) |
| 3595 | goto out_free; |
| 3596 | |
Jaroslav Kysela | 2dca0bb | 2009-11-13 18:41:52 +0100 | [diff] [blame] | 3597 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 3598 | chip->beep_mode = beep_mode[dev]; |
| 3599 | #endif |
| 3600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | /* create codec instances */ |
Dylan Reid | e62a42a | 2014-02-28 15:41:19 -0800 | [diff] [blame^] | 3602 | err = azx_codec_create(chip, model[dev], |
| 3603 | azx_max_codecs[chip->driver_type], |
| 3604 | power_save_addr); |
| 3605 | |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3606 | if (err < 0) |
| 3607 | goto out_free; |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 3608 | #ifdef CONFIG_SND_HDA_PATCH_LOADER |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 3609 | if (chip->fw) { |
| 3610 | err = snd_hda_load_patch(chip->bus, chip->fw->size, |
| 3611 | chip->fw->data); |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 3612 | if (err < 0) |
| 3613 | goto out_free; |
Takashi Iwai | e39ae85 | 2012-11-22 16:18:13 +0100 | [diff] [blame] | 3614 | #ifndef CONFIG_PM |
Takashi Iwai | 4918cda | 2012-08-09 12:33:28 +0200 | [diff] [blame] | 3615 | release_firmware(chip->fw); /* no longer needed */ |
| 3616 | chip->fw = NULL; |
Takashi Iwai | e39ae85 | 2012-11-22 16:18:13 +0100 | [diff] [blame] | 3617 | #endif |
Takashi Iwai | 4ea6fbc | 2009-06-17 09:52:54 +0200 | [diff] [blame] | 3618 | } |
| 3619 | #endif |
Jaroslav Kysela | 10e77dd | 2010-03-26 11:04:38 +0100 | [diff] [blame] | 3620 | if ((probe_only[dev] & 1) == 0) { |
Takashi Iwai | a1e21c9 | 2009-06-17 09:33:52 +0200 | [diff] [blame] | 3621 | err = azx_codec_configure(chip); |
| 3622 | if (err < 0) |
| 3623 | goto out_free; |
| 3624 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | |
| 3626 | /* create PCM streams */ |
Takashi Iwai | 176d533 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3627 | err = snd_hda_build_pcms(chip->bus); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3628 | if (err < 0) |
| 3629 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | |
| 3631 | /* create mixer controls */ |
Takashi Iwai | d01ce99 | 2007-07-27 16:52:19 +0200 | [diff] [blame] | 3632 | err = azx_mixer_create(chip); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3633 | if (err < 0) |
| 3634 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | |
Takashi Iwai | a82d51e | 2012-04-26 12:23:42 +0200 | [diff] [blame] | 3636 | err = snd_card_register(chip->card); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3637 | if (err < 0) |
| 3638 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3640 | chip->running = 1; |
| 3641 | power_down_all_codecs(chip); |
Takashi Iwai | 0cbf009 | 2008-10-29 16:18:25 +0100 | [diff] [blame] | 3642 | azx_notifier_register(chip); |
Takashi Iwai | 65fcd41 | 2012-08-14 17:13:32 +0200 | [diff] [blame] | 3643 | azx_add_card_list(chip); |
Dave Airlie | 246efa4 | 2013-07-29 15:19:29 +1000 | [diff] [blame] | 3644 | if ((chip->driver_caps & AZX_DCAPS_PM_RUNTIME) || chip->use_vga_switcheroo) |
Wang Xingchao | c67e222 | 2013-05-30 22:07:08 +0800 | [diff] [blame] | 3645 | pm_runtime_put_noidle(&pci->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3647 | out_free: |
Takashi Iwai | 88d071f | 2013-12-02 11:12:28 +0100 | [diff] [blame] | 3648 | if (err < 0) |
| 3649 | chip->init_failed = 1; |
| 3650 | complete_all(&chip->probe_wait); |
Wu Fengguang | 41dda0f | 2008-11-20 09:24:52 +0800 | [diff] [blame] | 3651 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3654 | static void azx_remove(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | { |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 3656 | struct snd_card *card = pci_get_drvdata(pci); |
Mengdong Lin | b8dfc462 | 2012-08-23 17:32:30 +0800 | [diff] [blame] | 3657 | |
Takashi Iwai | 9121947 | 2012-04-26 12:13:25 +0200 | [diff] [blame] | 3658 | if (card) |
| 3659 | snd_card_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | /* PCI IDs */ |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 3663 | static DEFINE_PCI_DEVICE_TABLE(azx_ids) = { |
Seth Heasley | d2f2fcd | 2010-01-12 17:03:35 -0800 | [diff] [blame] | 3664 | /* CPT */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3665 | { PCI_DEVICE(0x8086, 0x1c20), |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 3666 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Seth Heasley | cea310e | 2010-09-10 16:29:56 -0700 | [diff] [blame] | 3667 | /* PBG */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3668 | { PCI_DEVICE(0x8086, 0x1d20), |
Takashi Iwai | d7dab4d | 2013-01-08 13:51:30 +0100 | [diff] [blame] | 3669 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Seth Heasley | d2edeb7 | 2011-04-20 10:59:57 -0700 | [diff] [blame] | 3670 | /* Panther Point */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3671 | { PCI_DEVICE(0x8086, 0x1e20), |
Takashi Iwai | b1920c2 | 2013-11-22 12:43:25 +0100 | [diff] [blame] | 3672 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
Seth Heasley | 8bc039a | 2012-01-23 16:24:31 -0800 | [diff] [blame] | 3673 | /* Lynx Point */ |
| 3674 | { PCI_DEVICE(0x8086, 0x8c20), |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 3675 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 884b088 | 2013-02-08 17:29:40 -0800 | [diff] [blame] | 3676 | /* Wellsburg */ |
| 3677 | { PCI_DEVICE(0x8086, 0x8d20), |
| 3678 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
| 3679 | { PCI_DEVICE(0x8086, 0x8d21), |
| 3680 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 144dad9 | 2012-08-09 09:38:59 -0700 | [diff] [blame] | 3681 | /* Lynx Point-LP */ |
| 3682 | { PCI_DEVICE(0x8086, 0x9c20), |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 3683 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 144dad9 | 2012-08-09 09:38:59 -0700 | [diff] [blame] | 3684 | /* Lynx Point-LP */ |
| 3685 | { PCI_DEVICE(0x8086, 0x9c21), |
Takashi Iwai | 2ea3c6a | 2012-11-19 20:03:37 +0100 | [diff] [blame] | 3686 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
James Ralston | 4eeca49 | 2013-11-04 09:27:45 -0800 | [diff] [blame] | 3687 | /* Wildcat Point-LP */ |
| 3688 | { PCI_DEVICE(0x8086, 0x9ca0), |
| 3689 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, |
Wang Xingchao | e926f2c | 2012-06-13 10:23:51 +0800 | [diff] [blame] | 3690 | /* Haswell */ |
Wang Xingchao | 4a7c516 | 2013-02-01 22:42:19 +0800 | [diff] [blame] | 3691 | { PCI_DEVICE(0x8086, 0x0a0c), |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 3692 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Wang Xingchao | e926f2c | 2012-06-13 10:23:51 +0800 | [diff] [blame] | 3693 | { PCI_DEVICE(0x8086, 0x0c0c), |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 3694 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Wang Xingchao | d279fae | 2012-09-17 13:10:23 +0800 | [diff] [blame] | 3695 | { PCI_DEVICE(0x8086, 0x0d0c), |
Takashi Iwai | fab1285 | 2013-11-05 17:54:05 +0100 | [diff] [blame] | 3696 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Mengdong Lin | 862d761 | 2014-01-08 15:55:14 -0500 | [diff] [blame] | 3697 | /* Broadwell */ |
| 3698 | { PCI_DEVICE(0x8086, 0x160c), |
| 3699 | .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, |
Pierre-Louis Bossart | 99df18b | 2012-09-21 18:39:07 -0500 | [diff] [blame] | 3700 | /* 5 Series/3400 */ |
| 3701 | { PCI_DEVICE(0x8086, 0x3b56), |
Takashi Iwai | 2c1350f | 2013-02-14 09:44:55 +0100 | [diff] [blame] | 3702 | .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Takashi Iwai | f748abc | 2013-01-29 10:12:23 +0100 | [diff] [blame] | 3703 | /* Poulsbo */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3704 | { PCI_DEVICE(0x8086, 0x811b), |
Takashi Iwai | f748abc | 2013-01-29 10:12:23 +0100 | [diff] [blame] | 3705 | .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
| 3706 | /* Oaktrail */ |
Li Peng | 09904b9 | 2011-12-28 15:17:26 +0000 | [diff] [blame] | 3707 | { PCI_DEVICE(0x8086, 0x080a), |
Takashi Iwai | f748abc | 2013-01-29 10:12:23 +0100 | [diff] [blame] | 3708 | .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
Chew, Chiau Ee | e44007e | 2013-05-16 15:36:12 +0800 | [diff] [blame] | 3709 | /* BayTrail */ |
| 3710 | { PCI_DEVICE(0x8086, 0x0f04), |
| 3711 | .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH_NOPM }, |
David Henningsson | 645e903 | 2011-12-14 15:52:30 +0800 | [diff] [blame] | 3712 | /* ICH */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3713 | { PCI_DEVICE(0x8086, 0x2668), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3714 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3715 | AZX_DCAPS_BUFSIZE }, /* ICH6 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3716 | { PCI_DEVICE(0x8086, 0x27d8), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3717 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3718 | AZX_DCAPS_BUFSIZE }, /* ICH7 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3719 | { PCI_DEVICE(0x8086, 0x269a), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3720 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3721 | AZX_DCAPS_BUFSIZE }, /* ESB2 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3722 | { PCI_DEVICE(0x8086, 0x284b), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3723 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3724 | AZX_DCAPS_BUFSIZE }, /* ICH8 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3725 | { PCI_DEVICE(0x8086, 0x293e), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3726 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3727 | AZX_DCAPS_BUFSIZE }, /* ICH9 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3728 | { PCI_DEVICE(0x8086, 0x293f), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3729 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3730 | AZX_DCAPS_BUFSIZE }, /* ICH9 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3731 | { PCI_DEVICE(0x8086, 0x3a3e), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3732 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3733 | AZX_DCAPS_BUFSIZE }, /* ICH10 */ |
Takashi Iwai | 8b0bd22 | 2011-06-10 14:56:26 +0200 | [diff] [blame] | 3734 | { PCI_DEVICE(0x8086, 0x3a6e), |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3735 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC | |
| 3736 | AZX_DCAPS_BUFSIZE }, /* ICH10 */ |
Takashi Iwai | b686453 | 2010-09-15 10:17:26 +0200 | [diff] [blame] | 3737 | /* Generic Intel */ |
| 3738 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID), |
| 3739 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 3740 | .class_mask = 0xffffff, |
Pierre-Louis Bossart | 2ae66c2 | 2011-08-04 10:12:56 -0500 | [diff] [blame] | 3741 | .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_BUFSIZE }, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3742 | /* ATI SB 450/600/700/800/900 */ |
| 3743 | { PCI_DEVICE(0x1002, 0x437b), |
| 3744 | .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB }, |
| 3745 | { PCI_DEVICE(0x1002, 0x4383), |
| 3746 | .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB }, |
| 3747 | /* AMD Hudson */ |
| 3748 | { PCI_DEVICE(0x1022, 0x780d), |
| 3749 | .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_SB }, |
Takashi Iwai | 87218e9 | 2008-02-21 08:13:11 +0100 | [diff] [blame] | 3750 | /* ATI HDMI */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3751 | { PCI_DEVICE(0x1002, 0x793b), |
| 3752 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3753 | { PCI_DEVICE(0x1002, 0x7919), |
| 3754 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3755 | { PCI_DEVICE(0x1002, 0x960f), |
| 3756 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3757 | { PCI_DEVICE(0x1002, 0x970f), |
| 3758 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3759 | { PCI_DEVICE(0x1002, 0xaa00), |
| 3760 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3761 | { PCI_DEVICE(0x1002, 0xaa08), |
| 3762 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3763 | { PCI_DEVICE(0x1002, 0xaa10), |
| 3764 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3765 | { PCI_DEVICE(0x1002, 0xaa18), |
| 3766 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3767 | { PCI_DEVICE(0x1002, 0xaa20), |
| 3768 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3769 | { PCI_DEVICE(0x1002, 0xaa28), |
| 3770 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3771 | { PCI_DEVICE(0x1002, 0xaa30), |
| 3772 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3773 | { PCI_DEVICE(0x1002, 0xaa38), |
| 3774 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3775 | { PCI_DEVICE(0x1002, 0xaa40), |
| 3776 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3777 | { PCI_DEVICE(0x1002, 0xaa48), |
| 3778 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
Clemens Ladisch | bbaa0d6 | 2013-11-05 09:27:10 +0100 | [diff] [blame] | 3779 | { PCI_DEVICE(0x1002, 0xaa50), |
| 3780 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3781 | { PCI_DEVICE(0x1002, 0xaa58), |
| 3782 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3783 | { PCI_DEVICE(0x1002, 0xaa60), |
| 3784 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3785 | { PCI_DEVICE(0x1002, 0xaa68), |
| 3786 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3787 | { PCI_DEVICE(0x1002, 0xaa80), |
| 3788 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3789 | { PCI_DEVICE(0x1002, 0xaa88), |
| 3790 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3791 | { PCI_DEVICE(0x1002, 0xaa90), |
| 3792 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3793 | { PCI_DEVICE(0x1002, 0xaa98), |
| 3794 | .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, |
Andiry Xu | 1815b34 | 2011-12-14 16:10:27 +0800 | [diff] [blame] | 3795 | { PCI_DEVICE(0x1002, 0x9902), |
| 3796 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3797 | { PCI_DEVICE(0x1002, 0xaaa0), |
| 3798 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3799 | { PCI_DEVICE(0x1002, 0xaaa8), |
| 3800 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
| 3801 | { PCI_DEVICE(0x1002, 0xaab0), |
| 3802 | .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI }, |
Takashi Iwai | 87218e9 | 2008-02-21 08:13:11 +0100 | [diff] [blame] | 3803 | /* VIA VT8251/VT8237A */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3804 | { PCI_DEVICE(0x1106, 0x3288), |
| 3805 | .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA }, |
Annie Liu | 754fdff | 2012-06-08 19:18:39 +0800 | [diff] [blame] | 3806 | /* VIA GFX VT7122/VX900 */ |
| 3807 | { PCI_DEVICE(0x1106, 0x9170), .driver_data = AZX_DRIVER_GENERIC }, |
| 3808 | /* VIA GFX VT6122/VX11 */ |
| 3809 | { PCI_DEVICE(0x1106, 0x9140), .driver_data = AZX_DRIVER_GENERIC }, |
Takashi Iwai | 87218e9 | 2008-02-21 08:13:11 +0100 | [diff] [blame] | 3810 | /* SIS966 */ |
| 3811 | { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS }, |
| 3812 | /* ULI M5461 */ |
| 3813 | { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI }, |
| 3814 | /* NVIDIA MCP */ |
Takashi Iwai | 0c2fd1bf4 | 2009-12-18 16:41:39 +0100 | [diff] [blame] | 3815 | { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), |
| 3816 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 3817 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3818 | .driver_data = AZX_DRIVER_NVIDIA | AZX_DCAPS_PRESET_NVIDIA }, |
Kailang Yang | f269002 | 2008-05-27 11:44:55 +0200 | [diff] [blame] | 3819 | /* Teradici */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3820 | { PCI_DEVICE(0x6549, 0x1200), |
| 3821 | .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT }, |
Lars R. Damerow | f0b3da9 | 2012-11-02 13:10:39 -0700 | [diff] [blame] | 3822 | { PCI_DEVICE(0x6549, 0x2200), |
| 3823 | .driver_data = AZX_DRIVER_TERA | AZX_DCAPS_NO_64BIT }, |
Takashi Iwai | 4e01f54 | 2009-04-16 08:53:34 +0200 | [diff] [blame] | 3824 | /* Creative X-Fi (CA0110-IBG) */ |
Takashi Iwai | f2a8eca | 2012-06-11 15:51:54 +0200 | [diff] [blame] | 3825 | /* CTHDA chips */ |
| 3826 | { PCI_DEVICE(0x1102, 0x0010), |
| 3827 | .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, |
| 3828 | { PCI_DEVICE(0x1102, 0x0012), |
| 3829 | .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, |
Takashi Iwai | 8eeaa2f | 2014-02-10 09:48:47 +0100 | [diff] [blame] | 3830 | #if !IS_ENABLED(CONFIG_SND_CTXFI) |
Takashi Iwai | 313f6e2 | 2009-05-18 12:40:52 +0200 | [diff] [blame] | 3831 | /* the following entry conflicts with snd-ctxfi driver, |
| 3832 | * as ctxfi driver mutates from HD-audio to native mode with |
| 3833 | * a special command sequence. |
| 3834 | */ |
Takashi Iwai | 4e01f54 | 2009-04-16 08:53:34 +0200 | [diff] [blame] | 3835 | { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID), |
| 3836 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 3837 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3838 | .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | |
Takashi Iwai | 69f9ba9 | 2011-11-06 13:49:13 +0100 | [diff] [blame] | 3839 | AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, |
Takashi Iwai | 313f6e2 | 2009-05-18 12:40:52 +0200 | [diff] [blame] | 3840 | #else |
| 3841 | /* this entry seems still valid -- i.e. without emu20kx chip */ |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3842 | { PCI_DEVICE(0x1102, 0x0009), |
| 3843 | .driver_data = AZX_DRIVER_CTX | AZX_DCAPS_CTX_WORKAROUND | |
Takashi Iwai | 69f9ba9 | 2011-11-06 13:49:13 +0100 | [diff] [blame] | 3844 | AZX_DCAPS_RIRB_PRE_DELAY | AZX_DCAPS_POSFIX_LPIB }, |
Takashi Iwai | 313f6e2 | 2009-05-18 12:40:52 +0200 | [diff] [blame] | 3845 | #endif |
Otavio Salvador | e35d4b1 | 2010-09-26 23:35:06 -0300 | [diff] [blame] | 3846 | /* Vortex86MX */ |
| 3847 | { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, |
Bankim Bhavsar | 0f0714c5 | 2011-01-17 15:23:21 +0100 | [diff] [blame] | 3848 | /* VMware HDAudio */ |
| 3849 | { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC }, |
Andiry Brienza | 9176b67 | 2009-07-17 11:32:32 +0800 | [diff] [blame] | 3850 | /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */ |
Yang, Libin | c4da29c | 2008-11-13 11:07:07 +0100 | [diff] [blame] | 3851 | { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID), |
| 3852 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 3853 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3854 | .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI }, |
Andiry Brienza | 9176b67 | 2009-07-17 11:32:32 +0800 | [diff] [blame] | 3855 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID), |
| 3856 | .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, |
| 3857 | .class_mask = 0xffffff, |
Takashi Iwai | 9477c58 | 2011-05-25 09:11:37 +0200 | [diff] [blame] | 3858 | .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | { 0, } |
| 3860 | }; |
| 3861 | MODULE_DEVICE_TABLE(pci, azx_ids); |
| 3862 | |
| 3863 | /* pci_driver definition */ |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 3864 | static struct pci_driver azx_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 3865 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | .id_table = azx_ids, |
| 3867 | .probe = azx_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3868 | .remove = azx_remove, |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 3869 | .driver = { |
| 3870 | .pm = AZX_PM_OPS, |
| 3871 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | }; |
| 3873 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 3874 | module_pci_driver(azx_driver); |