/*1* Misc and compatibility things2* Copyright (c) by Jaroslav Kysela <[email protected]>3*4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*19*/2021#include <linux/init.h>22#include <linux/time.h>23#include <linux/slab.h>24#include <linux/ioport.h>25#include <sound/core.h>2627#ifdef CONFIG_SND_DEBUG2829#ifdef CONFIG_SND_DEBUG_VERBOSE30#define DEFAULT_DEBUG_LEVEL 231#else32#define DEFAULT_DEBUG_LEVEL 133#endif3435static int debug = DEFAULT_DEBUG_LEVEL;36module_param(debug, int, 0644);37MODULE_PARM_DESC(debug, "Debug level (0 = disable)");3839#endif /* CONFIG_SND_DEBUG */4041void release_and_free_resource(struct resource *res)42{43if (res) {44release_resource(res);45kfree(res);46}47}4849EXPORT_SYMBOL(release_and_free_resource);5051#ifdef CONFIG_SND_VERBOSE_PRINTK52/* strip the leading path if the given path is absolute */53static const char *sanity_file_name(const char *path)54{55if (*path == '/')56return strrchr(path, '/') + 1;57else58return path;59}60#endif6162#if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)63void __snd_printk(unsigned int level, const char *path, int line,64const char *format, ...)65{66va_list args;67#ifdef CONFIG_SND_VERBOSE_PRINTK68struct va_format vaf;69char verbose_fmt[] = KERN_DEFAULT "ALSA %s:%d %pV";70#endif7172#ifdef CONFIG_SND_DEBUG73if (debug < level)74return;75#endif7677va_start(args, format);78#ifdef CONFIG_SND_VERBOSE_PRINTK79vaf.fmt = format;80vaf.va = &args;81if (format[0] == '<' && format[2] == '>') {82memcpy(verbose_fmt, format, 3);83vaf.fmt = format + 3;84} else if (level)85memcpy(verbose_fmt, KERN_DEBUG, 3);86printk(verbose_fmt, sanity_file_name(path), line, &vaf);87#else88vprintk(format, args);89#endif90va_end(args);91}92EXPORT_SYMBOL_GPL(__snd_printk);93#endif9495#ifdef CONFIG_PCI96#include <linux/pci.h>97/**98* snd_pci_quirk_lookup_id - look up a PCI SSID quirk list99* @vendor: PCI SSV id100* @device: PCI SSD id101* @list: quirk list, terminated by a null entry102*103* Look through the given quirk list and finds a matching entry104* with the same PCI SSID. When subdevice is 0, all subdevice105* values may match.106*107* Returns the matched entry pointer, or NULL if nothing matched.108*/109const struct snd_pci_quirk *110snd_pci_quirk_lookup_id(u16 vendor, u16 device,111const struct snd_pci_quirk *list)112{113const struct snd_pci_quirk *q;114115for (q = list; q->subvendor; q++) {116if (q->subvendor != vendor)117continue;118if (!q->subdevice ||119(device & q->subdevice_mask) == q->subdevice)120return q;121}122return NULL;123}124EXPORT_SYMBOL(snd_pci_quirk_lookup_id);125126/**127* snd_pci_quirk_lookup - look up a PCI SSID quirk list128* @pci: pci_dev handle129* @list: quirk list, terminated by a null entry130*131* Look through the given quirk list and finds a matching entry132* with the same PCI SSID. When subdevice is 0, all subdevice133* values may match.134*135* Returns the matched entry pointer, or NULL if nothing matched.136*/137const struct snd_pci_quirk *138snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)139{140return snd_pci_quirk_lookup_id(pci->subsystem_vendor,141pci->subsystem_device,142list);143}144EXPORT_SYMBOL(snd_pci_quirk_lookup);145#endif146147148