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

ASoC: stac9766: Use core reset helper

Use the new snd_ac97_reset() helper and the reset functionality provided by
snd_soc_new_ac97_codec() to perform the device reset rather than
open-coding it.

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
017e800a 3ab3dbdf

+7 -50
+7 -50
sound/soc/codecs/stac9766.c
··· 28 28 29 29 #include "stac9766.h" 30 30 31 + #define STAC9766_VENDOR_ID 0x83847666 32 + #define STAC9766_VENDOR_ID_MASK 0xffffffff 33 + 31 34 /* 32 35 * STAC9766 register cache 33 36 */ ··· 242 239 return 0; 243 240 } 244 241 245 - static int stac9766_reset(struct snd_soc_codec *codec, int try_warm) 246 - { 247 - struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 248 - 249 - if (try_warm && soc_ac97_ops->warm_reset) { 250 - soc_ac97_ops->warm_reset(ac97); 251 - if (stac9766_ac97_read(codec, 0) == stac9766_reg[0]) 252 - return 1; 253 - } 254 - 255 - soc_ac97_ops->reset(ac97); 256 - if (soc_ac97_ops->warm_reset) 257 - soc_ac97_ops->warm_reset(ac97); 258 - if (stac9766_ac97_read(codec, 0) != stac9766_reg[0]) 259 - return -EIO; 260 - return 0; 261 - } 262 - 263 242 static int stac9766_codec_resume(struct snd_soc_codec *codec) 264 243 { 265 244 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 266 - u16 id, reset; 267 245 268 - reset = 0; 269 - /* give the codec an AC97 warm reset to start the link */ 270 - reset: 271 - if (reset > 5) { 272 - dev_err(codec->dev, "Failed to resume\n"); 273 - return -EIO; 274 - } 275 - ac97->bus->ops->warm_reset(ac97); 276 - id = soc_ac97_ops->read(ac97, AC97_VENDOR_ID2); 277 - if (id != 0x4c13) { 278 - stac9766_reset(codec, 0); 279 - reset++; 280 - goto reset; 281 - } 282 - 283 - return 0; 246 + return snd_ac97_reset(ac97, true, STAC9766_VENDOR_ID, 247 + STAC9766_VENDOR_ID_MASK); 284 248 } 285 249 286 250 static const struct snd_soc_dai_ops stac9766_dai_ops_analog = { ··· 300 330 static int stac9766_codec_probe(struct snd_soc_codec *codec) 301 331 { 302 332 struct snd_ac97 *ac97; 303 - int ret = 0; 304 333 305 - ac97 = snd_soc_new_ac97_codec(codec, 0, 0); 334 + ac97 = snd_soc_new_ac97_codec(codec, STAC9766_VENDOR_ID, 335 + STAC9766_VENDOR_ID_MASK); 306 336 if (IS_ERR(ac97)) 307 337 return PTR_ERR(ac97); 308 338 309 339 snd_soc_codec_set_drvdata(codec, ac97); 310 340 311 - /* do a cold reset for the controller and then try 312 - * a warm reset followed by an optional cold reset for codec */ 313 - stac9766_reset(codec, 0); 314 - ret = stac9766_reset(codec, 1); 315 - if (ret < 0) { 316 - dev_err(codec->dev, "Failed to reset: AC97 link error\n"); 317 - goto codec_err; 318 - } 319 - 320 341 return 0; 321 - 322 - codec_err: 323 - snd_soc_free_ac97_codec(ac97); 324 - return ret; 325 342 } 326 343 327 344 static int stac9766_codec_remove(struct snd_soc_codec *codec)