summaryrefslogtreecommitdiff
path: root/sound/hda/hdac_regmap.c
AgeCommit message (Collapse)Author
2023-07-18ALSA: hda: Use regcache_reg_cached() rather than open codingMark Brown
The HDA driver intentionally drops repeated writes to registers in some circumstances, beyond the suppression of noop writes that regmap does in regmap_update_bits(). It does this by checking if the register is cached before doing a regmap_update_bits(), now we have an API for querying this directly use it directly rather than trying a read in cache only mode making the code a little clearer. Reviewed-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20230717-regmap-cache-check-v1-3-73ef688afae3@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
2023-07-03ALSA: hda: fix a possible null-pointer dereference due to data race in ↵Tuo Li
snd_hdac_regmap_sync() The variable codec->regmap is often protected by the lock codec->regmap_lock when is accessed. However, it is accessed without holding the lock when is accessed in snd_hdac_regmap_sync(): if (codec->regmap) In my opinion, this may be a harmful race, because if codec->regmap is set to NULL right after the condition is checked, a null-pointer dereference can occur in the called function regcache_sync(): map->lock(map->lock_arg); --> Line 360 in drivers/base/regmap/regcache.c To fix this possible null-pointer dereference caused by data race, the mutex_lock coverage is extended to protect the if statement as well as the function call to regcache_sync(). [ Note: the lack of the regmap_lock itself is harmless for the current codec driver implementations, as snd_hdac_regmap_sync() is only for PM runtime resume that is prohibited during the codec probe. But the change makes the whole code more consistent, so it's merged as is -- tiwai ] Reported-by: BassCheck <bass@buaa.edu.cn> Signed-off-by: Tuo Li <islituo@gmail.com> Link: https://lore.kernel.org/r/20230703031016.1184711-1-islituo@gmail.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-06-26Merge tag 'asoc-v6.5' of ↵Takashi Iwai
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-linus ASoC: Updates for v6.5 A fairly quiet release from a core and framework point of view, but a very big one from the point of view of new drivers: - More refectoring from Morimoto-san, this time mainly around DAI links and how we control the ordering of trigger() callbacks. - Convert a lot of drivers to use maple tree based caches. - Lots of work on the x86 driver stack. - Compressed audio support for Qualcomm. - Support for AMD SoundWire, Analog Devices SSM3515, Google Chameleon, Ingenic X1000, Intel systems with various CODECs, Longsoon platforms, Maxim MAX98388, Mediatek MT8188, Nuvoton NAU8825C, NXP platforms with NAU8822, Qualcomm WSA884x, StarFive JH7110, Texas Instruments TAS2781.
2023-06-11ALSA: hda: Use maple tree register cacheMark Brown
HDA can only support single register read and write operations so does not benefit from block writes. This means it gets no benefit from using the rbtree register cache over the maple tree register cache so convert it to use maple trees instead, it is more modern. Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20230609-alsa-hda-maple-v1-1-a2b725c8b8f5@kernel.org Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-05-23ASoC: do not include pm_runtime.h if not usedClaudiu Beznea
Do not include pm_runtime.h header in files where APIs exported by pm_runtime.h are not used. Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com> # for omap-mcbsp-st.c Link: https://lore.kernel.org/r/20230517094903.2895238-2-claudiu.beznea@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
2021-03-02ALSA: hda: fix kernel-doc warningsPierre-Louis Bossart
v5.12-rc1 flags new warnings with make W=1, fix missing or broken function descriptors. sound/pci/hda/hda_codec.c:3492: warning: expecting prototype for snd_hda_input_mux_info_info(). Prototype was for snd_hda_input_mux_info() instead sound/pci/hda/hda_codec.c:3521: warning: expecting prototype for snd_hda_input_mux_info_put(). Prototype was for snd_hda_input_mux_put() instead sound/pci/hda/hda_codec.c:3958: warning: expecting prototype for _snd_hda_pin_ctl(). Prototype was for _snd_hda_set_pin_ctl() instead sound/pci/hda/hda_jack.c:223: warning: expecting prototype for snd_hda_set_dirty_all(). Prototype was for snd_hda_jack_set_dirty_all() instead sound/pci/hda/hda_jack.c:309: warning: expecting prototype for snd_hda_jack_detect_enable_mst(). Prototype was for snd_hda_jack_detect_enable_callback_mst() instead sound/pci/hda/hda_generic.c:3933: warning: expecting prototype for snd_dha_gen_add_mute_led_cdev(). Prototype was for snd_hda_gen_add_mute_led_cdev() instead sound/pci/hda/hda_generic.c:4093: warning: expecting prototype for snd_dha_gen_add_micmute_led_cdev(). Prototype was for snd_hda_gen_add_micmute_led_cdev() instead sound/pci/hda/patch_ca0132.c:2357: warning: expecting prototype for Prepare and send the SCP message to DSP(). Prototype was for dspio_scp() instead sound/pci/hda/patch_ca0132.c:2883: warning: expecting prototype for Allocate router ports(). Prototype was for dsp_allocate_router_ports() instead sound/pci/hda/patch_ca0132.c:3202: warning: expecting prototype for Write a block of data into DSP code or data RAM using pre(). Prototype was for dspxfr_one_seg() instead sound/pci/hda/patch_ca0132.c:3397: warning: expecting prototype for data overlay to DSP memories(). Prototype was for dspxfr_image() instead sound/hda/hdac_regmap.c:393: warning: expecting prototype for snd_hdac_regmap_init(). Prototype was for snd_hdac_regmap_exit() instead sound/hda/ext/hdac_ext_controller.c:142: warning: expecting prototype for snd_hdac_ext_bus_get_link_index(). Prototype was for snd_hdac_ext_bus_get_link() instead sound/hda/ext/hdac_ext_stream.c:140: warning: expecting prototype for snd_hdac_ext_linkstream_start(). Prototype was for snd_hdac_ext_link_stream_start() instead Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20210301174617.116960-1-pierre-louis.bossart@linux.intel.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-01-13ALSA: hda: Manage concurrent reg access more properlyTakashi Iwai
In the commit 8e85def5723e ("ALSA: hda: enable regmap internal locking"), we re-enabled the regmap lock due to the reported regression that showed the possible concurrent accesses. It was a temporary workaround, and there are still a few opened races even after the revert. In this patch, we cover those still opened windows with a proper mutex lock and disable the regmap internal lock again. First off, the patch introduces a new snd_hdac_device.regmap_lock mutex that is applied for each snd_hdac_regmap_*() call, including read, write and update helpers. The mutex is applied carefully so that it won't block the self-power-up procedure in the helper function. Also, this assures the protection for the accesses without regmap, too. The snd_hdac_regmap_update_raw() is refactored to use the standard regmap_update_bits_check() function instead of the open-code. The non-regmap case is still open-coded but it's an easy part. The all read and write operations are in the single mutex protection, so it's now race-free. In addition, a couple of new helper functions are added: snd_hdac_regmap_update_raw_once() and snd_hdac_regmap_sync(). Both are called from HD-audio legacy driver. The former is to initialize the given verb bits but only once when it's not initialized yet. Due to this condition, the function invokes regcache_cache_only(), and it's now performed inside the regmap_lock (formerly it was racy) too. The latter function is for simply invoking regcache_sync() inside the regmap_lock, which is called from the codec resume call path. Along with that, the HD-audio codec driver code is slightly modified / simplified to adapt those new functions. And finally, snd_hdac_regmap_read_raw(), *_write_raw(), etc are rewritten with the helper macro. It's just for simplification because the code logic is identical among all those functions. Tested-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Link: https://lore.kernel.org/r/20200109090104.26073-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-01-11Merge branch 'for-linus' into for-nextTakashi Iwai
Sync 5.5-devel branch once again for applying the HD-audio fixes. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-01-08ALSA: hda: enable regmap internal lockingKai Vehmanen
This reverts commit 42ec336f1f9d ("ALSA: hda: Disable regmap internal locking"). Without regmap locking, there is a race between snd_hda_codec_amp_init() and PM callbacks issuing regcache_sync(). This was caught by following kernel warning trace: <4> [358.080081] WARNING: CPU: 2 PID: 4157 at drivers/base/regmap/regcache.c:498 regcache_cache_only+0xf5/0x130 [...] <4> [358.080148] Call Trace: <4> [358.080158] snd_hda_codec_amp_init+0x4e/0x100 [snd_hda_codec] <4> [358.080169] snd_hda_codec_amp_init_stereo+0x40/0x80 [snd_hda_codec] Suggested-by: Takashi Iwai <tiwai@suse.de> BugLink: https://gitlab.freedesktop.org/drm/intel/issues/592 Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Link: https://lore.kernel.org/r/20200108180856.5194-1-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-01-08ALSA: hda: Fix a typo in commentsTakashi Iwai
Link: https://lore.kernel.org/r/20200108153430.31456-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-05ALSA: hda: Disable regmap internal lockingTakashi Iwai
Since we apply the own mutex (bus->cmd_mutex) in HDA core side, the internal locking in regmap is superfluous. This patch adds the flag to indicate that. Also, an infamous side-effect by this change is that it disables the regmap debugfs, too, and this is seen rather good; the regmap debugfs isn't quite useful for HD-audio as it provides the very sparse registers and its debugfs access tends to lead to the way too high resource usages or sometimes hang up. So it'd be rather safe to disable it altogether. Link: https://lore.kernel.org/r/2029139028.10333037.1572874551626.JavaMail.zimbra@redhat.com Link: https://lore.kernel.org/r/20191105081806.4896-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-08-14ALSA: hda: Unexport a few more stuffTakashi Iwai
Drop EXPORT_SYMBOL*() from a few more stuff in HD-audio core that aren't used outside. Particular the unsol event handler can be staticized now because the recent change removed all external callers. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-05-21treewide: Add SPDX license identifier for missed filesThomas Gleixner
Add SPDX license identifiers to all files which: - Have no license information of any form - Have EXPORT_.*_SYMBOL_GPL inside which was used in the initial scan/conversion to ignore the file These files fall under the project license, GPL v2 only. The resulting SPDX license identifier is: GPL-2.0-only Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-07regmap: split up regmap_config.use_single_rwDavid Frey
Split regmap_config.use_single_rw into use_single_read and use_single_write. This change enables drivers of devices which only support bulk operations in one direction to use the regmap_bulk_*() functions for both directions and have their bulk operation split into single operations only when necessary. Update all struct regmap_config instances where use_single_rw==true to instead set both use_single_read and use_single_write. No attempt was made to evaluate whether it is possible to set only one of use_single_read or use_single_write. Signed-off-by: David Frey <dpfrey@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2018-04-24ALSA: hda - Use a macro for snd_array iteration loopsTakashi Iwai
Introduce a new helper macro, snd_array_for_each(), to iterate for each snd_array element. It slightly improves the readability than lengthy open codes at each place. Along with it, add const prefix to some obvious places. There should be no functional changes by this. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-06-17ALSA: hdac_regmap - fix the register access for runtime PMJaroslav Kysela
Call path: 1) snd_hdac_power_up_pm() 2) snd_hdac_power_up() 3) pm_runtime_get_sync() 4) __pm_runtime_resume() 5) rpm_resume() The rpm_resume() returns 1 when the device is already active. Because the return value is unmodified, the hdac regmap read/write functions should allow this value for the retry I/O operation, too. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-04-21ALSA: hda - Fix possible race on regmap bypass flipTakashi Iwai
HD-audio driver uses regmap cache bypass feature for reading a raw value without the cache. But this is racy since both the cached and the uncached reads may occur concurrently. The former is done via the normal control API access while the latter comes from the proc file read. Even though the regmap itself has the protection against the concurrent accesses, the flag set/reset is done without the protection, so it may lead to inconsistent state of bypass flag that doesn't match with the current read and occasionally result in a kernel WARNING like: WARNING: CPU: 3 PID: 2731 at drivers/base/regmap/regcache.c:499 regcache_cache_only+0x78/0x93 One way to work around such a problem is to wrap with a mutex. But in this case, the solution is simpler: for the uncached read, we just skip the regmap and directly calls its accessor. The verb execution there is protected by itself, so basically it's safe to call individually. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=116171 Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-08ALSA: hda - Fix unexpected resume through regmap code pathTakashi Iwai
HD-audio driver has a mechanism to trigger the runtime resume automatically at accessing the verbs. This auto-resume, however, causes the mutex deadlock when invoked from the regmap handler since the regmap keeps the mutex while auto-resuming. For avoiding that, there is some tricky check in the HDA regmap handler to return -EAGAIN error to back-off when the codec is powered down. Then the caller of regmap r/w will retry after properly turning on the codec power. This works in most cases, but there seems a slight race between the codec power check and the actual on-demand auto-resume trigger. This resulted in the lockdep splat, eventually leading to a real deadlock. This patch tries to address the race window by getting the runtime PM refcount at the check time using pm_runtime_get_if_in_use(). With this call, we can keep the power on only when the codec has been already turned on, and back off if not. For keeping the code consistency, the code touching the runtime PM is stored in hdac_device.c although it's used only locally in hdac_regmap.c. Reported-by: Jiri Slaby <jslaby@suse.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-10-28ALSA: hda - Add / fix kernel doc commentsTakashi Iwai
Give some readable comment in kernel doc style for each exported function, as I promised in the previous meetings. While we're at it, fix the wrong comments, too. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-07-17ALSA: hda - Check the return value from pm_runtime_get/put*()Takashi Iwai
This patch changes the return type of snd_hdac_power_up/down() and variants to pass the error code from the underlying pm_runtime_get/put() calls. Currently they are ignored, but in most places, these should be handled properly. As an example, the regmap handler is updated to check the return value and accesses the register only when the wakeup succeeds. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-11ALSA: hda - Re-add the lost fake mute supportTakashi Iwai
Yet another regression by the transition to regmap cache; for better usability, we had the fake mute control using the zero amp value for Conexant codecs, and this was forgotten in the new hda core code. Since the bits 4-7 are unused for the amp registers (as we follow the syntax of AMP_GET verb), the bit 4 is now used to indicate the fake mute. For setting this flag, snd_hda_codec_amp_update() becomes a function from a simple macro. The bonus is that it gained a proper function description. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-06-10ALSA: hda - Don't actually write registers for caps overwritesTakashi Iwai
Along with the transition to regmap for managing the cached parameter reads, the caps overwrite was also moved to regmap cache. The cache change itself works, but it still tries to write the non-existing verb (the HDA parameter is read-only) wrongly. It's harmless in most cases, but some chips are picky and may result in the codec communication stall. This patch avoids it just by adding the missing flag check in reg_write ops. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-14ALSA: hda - set GET bit when adding a vendor verb to the codec regmapMengdong Lin
Some HD-A codecs may add their own vendor 'set' verb to the regmap, thru func snd_hdac_add_vendor_verb(). This patch sets the GET bit (bit 11) when adding the verb so that its peer vendor 'get' verb is actually added. This can avoid I/O error when writing the 'set' verb thru remap, since HD-A regmap internally looks up a writable vendor verb with GET bit set at first. Signed-off-by: Mengdong Lin <mengdong.lin@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-09ALSA: hda - Always allow access for POWER_STATE verbs via regmapTakashi Iwai
The hdac regmap code checks whether the codec is powered on while accessing, but there must be an exception -- the verbs to control the power state. Currently HD-audio driver doesn't access them via regmap, so this patch doesn't fix any current behavior, but it's just for future. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-08ALSA: hda - Work around races of power up/down with runtime PMTakashi Iwai
Currently, snd_hdac_power_up()/down() helpers checks whether the codec is being in pm (suspend/resume), and skips the call of runtime get/put during it. This is needed as there are lots of power up/down sequences called in the paths that are also used in the PM itself. An example is found in hda_codec.c::codec_exec_verb(), where this can power up the codec while it may be called again in its power up sequence, too. The above works in most cases, but sometimes we really want to wait for the real power up. For example, the control element get/put may want explicit power up so that the value change is assured to reach to the hardware. Using the current snd_hdac_power_up(), however, results in a race, e.g. when it's called during the runtime suspend is being performed. In the worst case, as found in patch_ca0132.c, it can even lead to the deadlock because the code assumes the power up while it was skipped due to the check above. For dealing with such cases, this patch makes snd_hdac_power_up() and _down() to two variants: with and without in_pm flag check. The version with pm flag check is named as snd_hdac_power_up_pm() while the version without pm flag check is still kept as snd_hdac_power_up(). (Just because the usage of the former is fewer.) Then finally, the patch replaces each call potentially done in PM with the new _pm() variant. In theory, we can implement a unified version -- if we can distinguish the current context whether it's in the pm path. But such an implementation is cumbersome, so leave the code like this a bit messy way for now... Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=96271 Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-27ALSA: hda - Set use_single_rw flag for regmapTakashi Iwai
HD-audio doesn't support the bulk access. Currently it works even without this flag as implicitly assumed, but it's safer to set explicitly. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-26ALSA: hda - Handle a few verbs as read-onlyTakashi Iwai
Although they can be written, handle a few verbs as read-only in regmap interface: CONFIG_DEFAULT, CONV and CVT_CHAN_COUNT. These are either updated in PCM or HDMI management code in a volatile manner, or just needed only as parameter, thus they don't need to be written at resume sync. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-23ALSA: hda - Add cache support for COEF read/writeTakashi Iwai
The 16bit COEF read/write is pretty standard for many codecs, and they can be cached in most cases -- more importantly, they need to be restored at resume. For making this easier, add the cache support to regmap. If the codec driver wants to cache the COEF access, set codec->cache_coef flag and issue AC_VERB_GET_PROC_COEF with the coef index in LSB 8 bits. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-23ALSA: hda - Handle get/set power verb symmetrically via regmapTakashi Iwai
HD-audio has quite a few asymmetrical ways of accessing verbs, and one of typical ones is GET/SET_POWER_STATE verbs. While it takes only the power state for setting, it returns a combination of states for getting. For making the state handling simpler, this patch adds a code to translate the value returned from GET_POWER_STATE to return only the actual state or -1 for error. In that way, the driver can simplify the power state management. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-23ALSA: hda - Add a fake stereo amp register supportTakashi Iwai
HD-audio spec is inconvenient regarding the handling of stereo volume controls. It can set and get only single channel at once (although there is a special option to set the same value to both channels). This patch provides a fake pseudo-register via the regmap access so that the stereo channels can be read and written by a single call. It'd be useful, for example, for implementing DAPM widgets. A stereo amp pseudo register consists of the encoding like the normal amp verbs but it has both SET_LEFT (bit 13) and SET_RIGHT (bit 12) bits set. The regmap reads and writes a 16bit value for this pseudo register where the upper 8bit is for the right chanel and the lower 8bit for the left channel. Note that the driver doesn't recognize conflicts when both stereo and mono channel registers are mixed. Mixing them would certainly confuse the operation. So, use carefully. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-23ALSA: hda - Allow driver to add vendor-specific verbs for regmapTakashi Iwai
Codecs may have own vendor-specific verbs, and we need to allow each driver to give such verbs for cached accesses. Here a verb can be put into a single array and looked through it at readable and writeable callbacks. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-23ALSA: hda - Use regmap for parameter caches, tooTakashi Iwai
The amp hash table was used for recording the cached reads of some capability values like pin caps or amp caps. Now all these are moved to regmap as well. One addition to the regmap helper is codec->caps_overwriting flag. This is set in snd_hdac_override_parm(), and the regmap helper accepts any register while this flag is set, so that it can overwrite even the read-only verb like AC_VERB_PARAMETERS. The flag is cleared immediately in snd_hdac_override_parm(), as it's a once-off flag. Along with these changes, the no longer needed amp hash and relevant fields are removed from hda_codec struct now. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-03-23ALSA: hda - Add regmap supportTakashi Iwai
This patch adds an infrastructure to support regmap-based verb accesses. Because o the asymmetric nature of HD-audio verbs, especially the amp verbs, we need to translate the verbs as a sort of pseudo registers to be mapped uniquely in regmap. In this patch, a pseudo register is built from the NID, the AC_VERB_GET_* and 8bit parameters, i.e. almost in the form to be sent to HD-audio bus but without codec address field. OTOH, for writing, the same pseudo register is translated to AC_VERB_SET_* automatically. The AC_VERB_SET_AMP_* verb is re-encoded from the corresponding AC_VERB_GET_AMP_* verb and parameter at writing. Some verbs has a single command for read but multiple for writes. A write for such a verb is split automatically to multiple verbs. The patch provides also a few handy helper functions. They are designed to be accessible even without regmap. When no regmap is set up (e.g. before the codec device instantiation), the direct hardware access is used. Also, it tries to avoid the unnecessary power-up. The power up/down sequence is performed only on demand. The codec driver needs to call snd_hdac_regmap_exit() and snd_hdac_regmap_exit() at probe and remove if it wants the regmap access. There is one flag added to hdac_device. When the flag lazy_cache is set, regmap helper ignores a write for a suspended device and returns as if it was actually written. It reduces the hardware access pretty much, e.g. when adjusting the mixer volume while in idle. This assumes that the driver will sync the cache later at resume properly, so use it carefully. Signed-off-by: Takashi Iwai <tiwai@suse.de>