regmap-ac97.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Register map access API - AC'97 support
  3. *
  4. * Copyright 2013 Linaro Ltd. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/io.h>
  22. #include <linux/module.h>
  23. #include <linux/regmap.h>
  24. #include <linux/slab.h>
  25. #include <sound/ac97_codec.h>
  26. bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg)
  27. {
  28. switch (reg) {
  29. case AC97_RESET:
  30. case AC97_POWERDOWN:
  31. case AC97_INT_PAGING:
  32. case AC97_EXTENDED_ID:
  33. case AC97_EXTENDED_STATUS:
  34. case AC97_EXTENDED_MID:
  35. case AC97_EXTENDED_MSTATUS:
  36. case AC97_GPIO_STATUS:
  37. case AC97_MISC_AFE:
  38. case AC97_VENDOR_ID1:
  39. case AC97_VENDOR_ID2:
  40. case AC97_CODEC_CLASS_REV:
  41. case AC97_PCI_SVID:
  42. case AC97_PCI_SID:
  43. case AC97_FUNC_SELECT:
  44. case AC97_FUNC_INFO:
  45. case AC97_SENSE_INFO:
  46. return true;
  47. default:
  48. return false;
  49. }
  50. }
  51. EXPORT_SYMBOL_GPL(regmap_ac97_default_volatile);
  52. static int regmap_ac97_reg_read(void *context, unsigned int reg,
  53. unsigned int *val)
  54. {
  55. struct snd_ac97 *ac97 = context;
  56. *val = ac97->bus->ops->read(ac97, reg);
  57. return 0;
  58. }
  59. static int regmap_ac97_reg_write(void *context, unsigned int reg,
  60. unsigned int val)
  61. {
  62. struct snd_ac97 *ac97 = context;
  63. ac97->bus->ops->write(ac97, reg, val);
  64. return 0;
  65. }
  66. static const struct regmap_bus ac97_regmap_bus = {
  67. .reg_write = regmap_ac97_reg_write,
  68. .reg_read = regmap_ac97_reg_read,
  69. };
  70. /**
  71. * regmap_init_ac97(): Initialise AC'97 register map
  72. *
  73. * @ac97: Device that will be interacted with
  74. * @config: Configuration for register map
  75. *
  76. * The return value will be an ERR_PTR() on error or a valid pointer to
  77. * a struct regmap.
  78. */
  79. struct regmap *regmap_init_ac97(struct snd_ac97 *ac97,
  80. const struct regmap_config *config)
  81. {
  82. return regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config);
  83. }
  84. EXPORT_SYMBOL_GPL(regmap_init_ac97);
  85. /**
  86. * devm_regmap_init_ac97(): Initialise AC'97 register map
  87. *
  88. * @ac97: Device that will be interacted with
  89. * @config: Configuration for register map
  90. *
  91. * The return value will be an ERR_PTR() on error or a valid pointer
  92. * to a struct regmap. The regmap will be automatically freed by the
  93. * device management code.
  94. */
  95. struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97,
  96. const struct regmap_config *config)
  97. {
  98. return devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config);
  99. }
  100. EXPORT_SYMBOL_GPL(devm_regmap_init_ac97);
  101. MODULE_LICENSE("GPL v2");