aqt1000-regmap.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/regmap.h>
  13. #include <linux/device.h>
  14. #include "aqt1000-registers.h"
  15. #include "aqt1000-reg-defaults.h"
  16. #include "aqt1000-internal.h"
  17. static bool aqt1000_is_readable_register(struct device *dev, unsigned int reg)
  18. {
  19. u8 pg_num, reg_offset;
  20. const u8 *reg_tbl = NULL;
  21. /*
  22. * Get the page number from MSB of codec register. If its 0x80, assign
  23. * the corresponding page index PAGE_0x80.
  24. */
  25. pg_num = reg >> 0x8;
  26. if (pg_num == 0x80)
  27. pg_num = AQT1000_PAGE_128;
  28. else if (pg_num > 15)
  29. return false;
  30. reg_tbl = aqt1000_reg[pg_num];
  31. reg_offset = reg & 0xFF;
  32. if (reg_tbl && reg_tbl[reg_offset])
  33. return true;
  34. else
  35. return false;
  36. }
  37. static bool aqt1000_is_volatile_register(struct device *dev, unsigned int reg)
  38. {
  39. u8 pg_num, reg_offset;
  40. const u8 *reg_tbl = NULL;
  41. pg_num = reg >> 0x8;
  42. if (pg_num == 0x80)
  43. pg_num = AQT1000_PAGE_128;
  44. else if (pg_num > 15)
  45. return false;
  46. reg_tbl = aqt1000_reg[pg_num];
  47. reg_offset = reg & 0xFF;
  48. if (reg_tbl && reg_tbl[reg_offset] == AQT1000_RO)
  49. return true;
  50. /* IIR Coeff registers are not cacheable */
  51. if ((reg >= AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL) &&
  52. (reg <= AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL))
  53. return true;
  54. if ((reg >= AQT1000_CDC_ANC0_IIR_COEFF_1_CTL) &&
  55. (reg <= AQT1000_CDC_ANC0_FB_GAIN_CTL))
  56. return true;
  57. if ((reg >= AQT1000_CDC_ANC1_IIR_COEFF_1_CTL) &&
  58. (reg <= AQT1000_CDC_ANC1_FB_GAIN_CTL))
  59. return true;
  60. /*
  61. * Need to mark volatile for registers that are writable but
  62. * only few bits are read-only
  63. */
  64. switch (reg) {
  65. case AQT1000_BUCK_5V_CTRL_CCL_1:
  66. case AQT1000_BIAS_CCOMP_FINE_ADJ:
  67. case AQT1000_ANA_BIAS:
  68. case AQT1000_BUCK_5V_IBIAS_CTL_4:
  69. case AQT1000_BUCK_5V_CTRL_CCL_2:
  70. case AQT1000_CHIP_CFG0_RST_CTL:
  71. case AQT1000_CHIP_CFG0_CLK_CTL_CDC_DIG:
  72. case AQT1000_CHIP_CFG0_CLK_CFG_MCLK:
  73. case AQT1000_CHIP_CFG0_EFUSE_CTL:
  74. case AQT1000_CDC_CLK_RST_CTRL_FS_CNT_CONTROL:
  75. case AQT1000_CDC_CLK_RST_CTRL_MCLK_CONTROL:
  76. case AQT1000_ANA_RX_SUPPLIES:
  77. case AQT1000_ANA_MBHC_MECH:
  78. case AQT1000_ANA_MBHC_ELECT:
  79. case AQT1000_ANA_MBHC_ZDET:
  80. case AQT1000_ANA_MICB1:
  81. case AQT1000_BUCK_5V_EN_CTL:
  82. return true;
  83. }
  84. return false;
  85. }
  86. struct regmap_config aqt1000_regmap_config = {
  87. .reg_bits = 16,
  88. .val_bits = 8,
  89. .cache_type = REGCACHE_RBTREE,
  90. .reg_defaults = aqt1000_defaults,
  91. .num_reg_defaults = ARRAY_SIZE(aqt1000_defaults),
  92. .max_register = AQT1000_MAX_REGISTER,
  93. .volatile_reg = aqt1000_is_volatile_register,
  94. .readable_reg = aqt1000_is_readable_register,
  95. };