// 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 @try_warm is false the function issues49* cold reset followed by a warm reset. If @id is 0 any valid device ID50* will be accepted, otherwise only the ID that matches @id and @id_mask51* is accepted.52* Returns:53* * %1 - if warm reset is successful54* * %0 - if cold reset and warm reset is successful55* * %-ENODEV - if @id and @id_mask not matching56*/57int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,58unsigned int id_mask)59{60const struct snd_ac97_bus_ops *ops = ac97->bus->ops;6162if (try_warm && ops->warm_reset) {63ops->warm_reset(ac97);64if (snd_ac97_check_id(ac97, id, id_mask))65return 1;66}6768if (ops->reset)69ops->reset(ac97);70if (ops->warm_reset)71ops->warm_reset(ac97);7273if (snd_ac97_check_id(ac97, id, id_mask))74return 0;7576return -ENODEV;77}78EXPORT_SYMBOL_GPL(snd_ac97_reset);7980const struct bus_type ac97_bus_type = {81.name = "ac97",82};8384static int __init ac97_bus_init(void)85{86return bus_register(&ac97_bus_type);87}8889subsys_initcall(ac97_bus_init);9091static void __exit ac97_bus_exit(void)92{93bus_unregister(&ac97_bus_type);94}9596module_exit(ac97_bus_exit);9798EXPORT_SYMBOL(ac97_bus_type);99100MODULE_DESCRIPTION("Legacy AC97 bus interface");101MODULE_LICENSE("GPL");102103104