// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Linux driver model AC97 bus interface3*4* Author: Nicolas Pitre5* Created: Jan 14, 20056* Copyright: (C) MontaVista Software Inc.7*/89#include <linux/module.h>10#include <linux/init.h>11#include <linux/device.h>12#include <linux/string.h>13#include <sound/ac97_codec.h>1415/*16* snd_ac97_check_id() - Reads and checks the vendor ID of the device17* @ac97: The AC97 device to check18* @id: The ID to compare to19* @id_mask: Mask that is applied to the device ID before comparing to @id20*21* If @id is 0 this function returns true if the read device vendor ID is22* a valid ID. If @id is non 0 this functions returns true if @id23* matches the read vendor ID. Otherwise the function returns false.24*/25static bool snd_ac97_check_id(struct snd_ac97 *ac97, unsigned int id,26unsigned int id_mask)27{28ac97->id = ac97->bus->ops->read(ac97, AC97_VENDOR_ID1) << 16;29ac97->id |= ac97->bus->ops->read(ac97, AC97_VENDOR_ID2);3031if (ac97->id == 0x0 || ac97->id == 0xffffffff)32return false;3334if (id != 0 && id != (ac97->id & id_mask))35return false;3637return true;38}3940/**41* snd_ac97_reset() - Reset AC'97 device42* @ac97: The AC'97 device to reset43* @try_warm: Try a warm reset first44* @id: Expected device vendor ID45* @id_mask: Mask that is applied to the device ID before comparing to @id46*47* This function resets the AC'97 device. If @try_warm is true the function48* first performs a warm reset. If the warm reset is successful the function49* returns 1. Otherwise or if @try_warm is false the function issues cold reset50* followed by a warm reset. If this is successful the function returns 0,51* otherwise a negative error code. If @id is 0 any valid device ID will be52* accepted, otherwise only the ID that matches @id and @id_mask is accepted.53*/54int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,55unsigned int id_mask)56{57const struct snd_ac97_bus_ops *ops = ac97->bus->ops;5859if (try_warm && ops->warm_reset) {60ops->warm_reset(ac97);61if (snd_ac97_check_id(ac97, id, id_mask))62return 1;63}6465if (ops->reset)66ops->reset(ac97);67if (ops->warm_reset)68ops->warm_reset(ac97);6970if (snd_ac97_check_id(ac97, id, id_mask))71return 0;7273return -ENODEV;74}75EXPORT_SYMBOL_GPL(snd_ac97_reset);7677const struct bus_type ac97_bus_type = {78.name = "ac97",79};8081static int __init ac97_bus_init(void)82{83return bus_register(&ac97_bus_type);84}8586subsys_initcall(ac97_bus_init);8788static void __exit ac97_bus_exit(void)89{90bus_unregister(&ac97_bus_type);91}9293module_exit(ac97_bus_exit);9495EXPORT_SYMBOL(ac97_bus_type);9697MODULE_DESCRIPTION("Legacy AC97 bus interface");98MODULE_LICENSE("GPL");99100101