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