Back to home page

LXR

 
 

    


0001 /*
0002  * Linux driver model AC97 bus interface
0003  *
0004  * Author:  Nicolas Pitre
0005  * Created: Jan 14, 2005
0006  * Copyright:   (C) MontaVista Software Inc.
0007  *
0008  * This program is free software; you can redistribute it and/or modify
0009  * it under the terms of the GNU General Public License as published by
0010  * the Free Software Foundation; either version 2 of the License, or
0011  * (at your option) any later version.
0012  */
0013 
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/device.h>
0017 #include <linux/string.h>
0018 #include <sound/ac97_codec.h>
0019 
0020 /*
0021  * snd_ac97_check_id() - Reads and checks the vendor ID of the device
0022  * @ac97: The AC97 device to check
0023  * @id: The ID to compare to
0024  * @id_mask: Mask that is applied to the device ID before comparing to @id
0025  *
0026  * If @id is 0 this function returns true if the read device vendor ID is
0027  * a valid ID. If @id is non 0 this functions returns true if @id
0028  * matches the read vendor ID. Otherwise the function returns false.
0029  */
0030 static bool snd_ac97_check_id(struct snd_ac97 *ac97, unsigned int id,
0031     unsigned int id_mask)
0032 {
0033     ac97->id = ac97->bus->ops->read(ac97, AC97_VENDOR_ID1) << 16;
0034     ac97->id |= ac97->bus->ops->read(ac97, AC97_VENDOR_ID2);
0035 
0036     if (ac97->id == 0x0 || ac97->id == 0xffffffff)
0037         return false;
0038 
0039     if (id != 0 && id != (ac97->id & id_mask))
0040         return false;
0041 
0042     return true;
0043 }
0044 
0045 /**
0046  * snd_ac97_reset() - Reset AC'97 device
0047  * @ac97: The AC'97 device to reset
0048  * @try_warm: Try a warm reset first
0049  * @id: Expected device vendor ID
0050  * @id_mask: Mask that is applied to the device ID before comparing to @id
0051  *
0052  * This function resets the AC'97 device. If @try_warm is true the function
0053  * first performs a warm reset. If the warm reset is successful the function
0054  * returns 1. Otherwise or if @try_warm is false the function issues cold reset
0055  * followed by a warm reset. If this is successful the function returns 0,
0056  * otherwise a negative error code. If @id is 0 any valid device ID will be
0057  * accepted, otherwise only the ID that matches @id and @id_mask is accepted.
0058  */
0059 int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
0060     unsigned int id_mask)
0061 {
0062     struct snd_ac97_bus_ops *ops = ac97->bus->ops;
0063 
0064     if (try_warm && ops->warm_reset) {
0065         ops->warm_reset(ac97);
0066         if (snd_ac97_check_id(ac97, id, id_mask))
0067             return 1;
0068     }
0069 
0070     if (ops->reset)
0071         ops->reset(ac97);
0072     if (ops->warm_reset)
0073         ops->warm_reset(ac97);
0074 
0075     if (snd_ac97_check_id(ac97, id, id_mask))
0076         return 0;
0077 
0078     return -ENODEV;
0079 }
0080 EXPORT_SYMBOL_GPL(snd_ac97_reset);
0081 
0082 /*
0083  * Let drivers decide whether they want to support given codec from their
0084  * probe method. Drivers have direct access to the struct snd_ac97
0085  * structure and may  decide based on the id field amongst other things.
0086  */
0087 static int ac97_bus_match(struct device *dev, struct device_driver *drv)
0088 {
0089     return 1;
0090 }
0091 
0092 struct bus_type ac97_bus_type = {
0093     .name       = "ac97",
0094     .match      = ac97_bus_match,
0095 };
0096 
0097 static int __init ac97_bus_init(void)
0098 {
0099     return bus_register(&ac97_bus_type);
0100 }
0101 
0102 subsys_initcall(ac97_bus_init);
0103 
0104 static void __exit ac97_bus_exit(void)
0105 {
0106     bus_unregister(&ac97_bus_type);
0107 }
0108 
0109 module_exit(ac97_bus_exit);
0110 
0111 EXPORT_SYMBOL(ac97_bus_type);
0112 
0113 MODULE_LICENSE("GPL");