lpass-cdc-comp.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  3. */
  4. #include "lpass-cdc-comp.h"
  5. int lpass_cdc_load_compander_coeff(struct snd_soc_component *component,
  6. u16 lsb_reg, u16 msb_reg,
  7. struct comp_coeff_val *comp_coeff_table,
  8. u16 arr_size)
  9. {
  10. int i = 0;
  11. /* Load Compander Coeff */
  12. for (i = 0; i < arr_size; i++) {
  13. snd_soc_component_write(component, lsb_reg,
  14. comp_coeff_table[i].lsb);
  15. snd_soc_component_write(component, msb_reg,
  16. comp_coeff_table[i].msb);
  17. }
  18. return 0;
  19. }
  20. EXPORT_SYMBOL(lpass_cdc_load_compander_coeff);
  21. int lpass_cdc_update_compander_setting(struct snd_soc_component *component,
  22. u16 start_addr,
  23. struct lpass_cdc_comp_setting *comp_setting)
  24. {
  25. int zone2_rms, zone3_rms, zone4_rms, zone5_rms, zone6_rms;
  26. int path_gain;
  27. int max_attn;
  28. int zone1_rms = 6;
  29. int upper_gain_int = comp_setting->upper_gain_int;
  30. int lower_gain_int = comp_setting->lower_gain_int;
  31. int ana_addr_map = comp_setting->ana_addr_map;
  32. int upper_gain_dig_int = upper_gain_int - lower_gain_int;
  33. /* skip comp_ctl8, comp_ctl9 default settings is fine */
  34. /* apply zone settings */
  35. snd_soc_component_write(component,
  36. start_addr + 8,
  37. zone1_rms);
  38. if (upper_gain_dig_int >= 24)
  39. zone2_rms = 18;
  40. else if (upper_gain_dig_int >= 18)
  41. zone2_rms = 12;
  42. else
  43. zone2_rms = upper_gain_dig_int;
  44. snd_soc_component_write(component,
  45. start_addr + 0xC,
  46. zone2_rms);
  47. if (upper_gain_dig_int >= 66)
  48. zone3_rms = 33;
  49. else if (upper_gain_dig_int >= 36)
  50. zone3_rms = 30;
  51. else if (upper_gain_dig_int >= 30)
  52. zone3_rms = 24;
  53. else
  54. zone3_rms = upper_gain_dig_int;
  55. snd_soc_component_write(component,
  56. start_addr + 0x10,
  57. zone3_rms);
  58. if (upper_gain_dig_int >= 66)
  59. zone4_rms = 48;
  60. else if (upper_gain_dig_int >= 48)
  61. zone4_rms = 42;
  62. else if (upper_gain_dig_int >= 42)
  63. zone4_rms = 36;
  64. else
  65. zone4_rms = upper_gain_dig_int;
  66. snd_soc_component_write(component,
  67. start_addr + 0x14,
  68. zone4_rms);
  69. if (upper_gain_dig_int >= 69)
  70. zone5_rms = 63;
  71. else if (upper_gain_dig_int >= 66)
  72. zone5_rms = 60;
  73. else if (upper_gain_dig_int >= 60)
  74. zone5_rms = 54;
  75. else if (upper_gain_dig_int >= 54)
  76. zone5_rms = 48;
  77. else
  78. zone5_rms = upper_gain_dig_int;
  79. snd_soc_component_write(component,
  80. start_addr + 0x18,
  81. zone5_rms);
  82. zone6_rms = upper_gain_dig_int;
  83. snd_soc_component_write(component,
  84. start_addr + 0x1C,
  85. zone6_rms);
  86. if (lower_gain_int < 0)
  87. max_attn = 256 + lower_gain_int;
  88. else
  89. max_attn = lower_gain_int;
  90. snd_soc_component_write(component,
  91. start_addr + 0x20,
  92. max_attn);
  93. path_gain = zone6_rms - abs(lower_gain_int);
  94. snd_soc_component_write(component,
  95. start_addr + 0x24,
  96. path_gain);
  97. snd_soc_component_write(component,
  98. start_addr + 0x28,
  99. ana_addr_map);
  100. return 0;
  101. }
  102. EXPORT_SYMBOL(lpass_cdc_update_compander_setting);