Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: ac97: Add helper function to reset the AC97 device

There is currently a lot of code duplication in ASoC drivers regarding the
reset handling of devices. This patch introduces a new generic reset
function in the generic AC'97 framework that can be used to replace most
the custom reset functions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Lars-Peter Clausen and committed by
Mark Brown
5f1d980e bc0195aa

+64
+2
include/sound/ac97_codec.h
··· 584 584 void snd_ac97_suspend(struct snd_ac97 *ac97); 585 585 void snd_ac97_resume(struct snd_ac97 *ac97); 586 586 #endif 587 + int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id, 588 + unsigned int id_mask); 587 589 588 590 /* quirk types */ 589 591 enum {
+62
sound/ac97_bus.c
··· 18 18 #include <sound/ac97_codec.h> 19 19 20 20 /* 21 + * snd_ac97_check_id() - Reads and checks the vendor ID of the device 22 + * @ac97: The AC97 device to check 23 + * @id: The ID to compare to 24 + * @id_mask: Mask that is applied to the device ID before comparing to @id 25 + * 26 + * If @id is 0 this function returns true if the read device vendor ID is 27 + * a valid ID. If @id is non 0 this functions returns true if @id 28 + * matches the read vendor ID. Otherwise the function returns false. 29 + */ 30 + static bool snd_ac97_check_id(struct snd_ac97 *ac97, unsigned int id, 31 + unsigned int id_mask) 32 + { 33 + ac97->id = ac97->bus->ops->read(ac97, AC97_VENDOR_ID1) << 16; 34 + ac97->id |= ac97->bus->ops->read(ac97, AC97_VENDOR_ID2); 35 + 36 + if (ac97->id == 0x0 || ac97->id == 0xffffffff) 37 + return false; 38 + 39 + if (id != 0 && id != (ac97->id & id_mask)) 40 + return false; 41 + 42 + return true; 43 + } 44 + 45 + /** 46 + * snd_ac97_reset() - Reset AC'97 device 47 + * @ac97: The AC'97 device to reset 48 + * @try_warm: Try a warm reset first 49 + * @id: Expected device vendor ID 50 + * @id_mask: Mask that is applied to the device ID before comparing to @id 51 + * 52 + * This function resets the AC'97 device. If @try_warm is true the function 53 + * first performs a warm reset. If the warm reset is successful the function 54 + * returns 1. Otherwise or if @try_warm is false the function issues cold reset 55 + * followed by a warm reset. If this is successful the function returns 0, 56 + * otherwise a negative error code. If @id is 0 any valid device ID will be 57 + * accepted, otherwise only the ID that matches @id and @id_mask is accepted. 58 + */ 59 + int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id, 60 + unsigned int id_mask) 61 + { 62 + struct snd_ac97_bus_ops *ops = ac97->bus->ops; 63 + 64 + if (try_warm && ops->warm_reset) { 65 + ops->warm_reset(ac97); 66 + if (snd_ac97_check_id(ac97, id, id_mask)) 67 + return 1; 68 + } 69 + 70 + if (ops->reset) 71 + ops->reset(ac97); 72 + if (ops->warm_reset) 73 + ops->warm_reset(ac97); 74 + 75 + if (snd_ac97_check_id(ac97, id, id_mask)) 76 + return 0; 77 + 78 + return -ENODEV; 79 + } 80 + EXPORT_SYMBOL_GPL(snd_ac97_reset); 81 + 82 + /* 21 83 * Let drivers decide whether they want to support given codec from their 22 84 * probe method. Drivers have direct access to the struct snd_ac97 23 85 * structure and may decide based on the id field amongst other things.