/sound/core/misc.c

https://bitbucket.org/Don2x/mod-kernel-m7-sources · C · 124 lines · 90 code · 14 blank · 20 comment · 16 complexity · 2c1bd42d5171f850c5214245f67ca44e MD5 · raw file

  1. /*
  2. * Misc and compatibility things
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/init.h>
  22. #include <linux/export.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/time.h>
  25. #include <linux/slab.h>
  26. #include <linux/ioport.h>
  27. #include <sound/core.h>
  28. #ifdef CONFIG_SND_DEBUG
  29. #ifdef CONFIG_SND_DEBUG_VERBOSE
  30. #define DEFAULT_DEBUG_LEVEL 2
  31. #else
  32. #define DEFAULT_DEBUG_LEVEL 1
  33. #endif
  34. static int debug = DEFAULT_DEBUG_LEVEL;
  35. module_param(debug, int, 0644);
  36. MODULE_PARM_DESC(debug, "Debug level (0 = disable)");
  37. #endif
  38. void release_and_free_resource(struct resource *res)
  39. {
  40. if (res) {
  41. release_resource(res);
  42. kfree(res);
  43. }
  44. }
  45. EXPORT_SYMBOL(release_and_free_resource);
  46. #ifdef CONFIG_SND_VERBOSE_PRINTK
  47. static const char *sanity_file_name(const char *path)
  48. {
  49. if (*path == '/')
  50. return strrchr(path, '/') + 1;
  51. else
  52. return path;
  53. }
  54. #endif
  55. #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
  56. void __snd_printk(unsigned int level, const char *path, int line,
  57. const char *format, ...)
  58. {
  59. va_list args;
  60. #ifdef CONFIG_SND_VERBOSE_PRINTK
  61. struct va_format vaf;
  62. char verbose_fmt[] = KERN_DEFAULT "ALSA %s:%d %pV";
  63. #endif
  64. #ifdef CONFIG_SND_DEBUG
  65. if (debug < level)
  66. return;
  67. #endif
  68. va_start(args, format);
  69. #ifdef CONFIG_SND_VERBOSE_PRINTK
  70. vaf.fmt = format;
  71. vaf.va = &args;
  72. if (format[0] == '<' && format[2] == '>') {
  73. memcpy(verbose_fmt, format, 3);
  74. vaf.fmt = format + 3;
  75. } else if (level)
  76. memcpy(verbose_fmt, KERN_DEBUG, 3);
  77. printk(verbose_fmt, sanity_file_name(path), line, &vaf);
  78. #else
  79. vprintk(format, args);
  80. #endif
  81. va_end(args);
  82. }
  83. EXPORT_SYMBOL_GPL(__snd_printk);
  84. #endif
  85. #ifdef CONFIG_PCI
  86. #include <linux/pci.h>
  87. const struct snd_pci_quirk *
  88. snd_pci_quirk_lookup_id(u16 vendor, u16 device,
  89. const struct snd_pci_quirk *list)
  90. {
  91. const struct snd_pci_quirk *q;
  92. for (q = list; q->subvendor; q++) {
  93. if (q->subvendor != vendor)
  94. continue;
  95. if (!q->subdevice ||
  96. (device & q->subdevice_mask) == q->subdevice)
  97. return q;
  98. }
  99. return NULL;
  100. }
  101. EXPORT_SYMBOL(snd_pci_quirk_lookup_id);
  102. const struct snd_pci_quirk *
  103. snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
  104. {
  105. return snd_pci_quirk_lookup_id(pci->subsystem_vendor,
  106. pci->subsystem_device,
  107. list);
  108. }
  109. EXPORT_SYMBOL(snd_pci_quirk_lookup);
  110. #endif