Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Linux driver model AC97 bus interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author:	Nicolas Pitre
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Created:	Jan 14, 2005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright:	(C) MontaVista Software Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <sound/ac97_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * snd_ac97_check_id() - Reads and checks the vendor ID of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * @ac97: The AC97 device to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * @id: The ID to compare to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * @id_mask: Mask that is applied to the device ID before comparing to @id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * If @id is 0 this function returns true if the read device vendor ID is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * a valid ID. If @id is non 0 this functions returns true if @id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * matches the read vendor ID. Otherwise the function returns false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static bool snd_ac97_check_id(struct snd_ac97 *ac97, unsigned int id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	unsigned int id_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	ac97->id = ac97->bus->ops->read(ac97, AC97_VENDOR_ID1) << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	ac97->id |= ac97->bus->ops->read(ac97, AC97_VENDOR_ID2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (ac97->id == 0x0 || ac97->id == 0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (id != 0 && id != (ac97->id & id_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * snd_ac97_reset() - Reset AC'97 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * @ac97: The AC'97 device to reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * @try_warm: Try a warm reset first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @id: Expected device vendor ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @id_mask: Mask that is applied to the device ID before comparing to @id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * This function resets the AC'97 device. If @try_warm is true the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * first performs a warm reset. If the warm reset is successful the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * returns 1. Otherwise or if @try_warm is false the function issues cold reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * followed by a warm reset. If this is successful the function returns 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * otherwise a negative error code. If @id is 0 any valid device ID will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * accepted, otherwise only the ID that matches @id and @id_mask is accepted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	unsigned int id_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	const struct snd_ac97_bus_ops *ops = ac97->bus->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (try_warm && ops->warm_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		ops->warm_reset(ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		if (snd_ac97_check_id(ac97, id, id_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (ops->reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		ops->reset(ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (ops->warm_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		ops->warm_reset(ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (snd_ac97_check_id(ac97, id, id_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) EXPORT_SYMBOL_GPL(snd_ac97_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * Let drivers decide whether they want to support given codec from their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * probe method. Drivers have direct access to the struct snd_ac97
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * structure and may  decide based on the id field amongst other things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int ac97_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) struct bus_type ac97_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.name		= "ac97",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.match		= ac97_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int __init ac97_bus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return bus_register(&ac97_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) subsys_initcall(ac97_bus_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void __exit ac97_bus_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	bus_unregister(&ac97_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) module_exit(ac97_bus_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) EXPORT_SYMBOL(ac97_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) MODULE_LICENSE("GPL");