cs35l41_hda_property.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // CS35L41 ALSA HDA Property driver
  4. //
  5. // Copyright 2023 Cirrus Logic, Inc.
  6. //
  7. // Author: Stefan Binding <sbinding@opensource.cirrus.com>
  8. #include <linux/acpi.h>
  9. #include <linux/gpio/consumer.h>
  10. #include <linux/string.h>
  11. #include "cs35l41_hda_property.h"
  12. #include <linux/spi/spi.h>
  13. #define MAX_AMPS 4
  14. struct cs35l41_config {
  15. const char *ssid;
  16. int num_amps;
  17. enum {
  18. INTERNAL,
  19. EXTERNAL
  20. } boost_type;
  21. u8 channel[MAX_AMPS];
  22. int reset_gpio_index; /* -1 if no reset gpio */
  23. int spkid_gpio_index; /* -1 if no spkid gpio */
  24. int cs_gpio_index; /* -1 if no cs gpio, or cs-gpios already exists, max num amps == 2 */
  25. int boost_ind_nanohenry; /* Required if boost_type == Internal */
  26. int boost_peak_milliamp; /* Required if boost_type == Internal */
  27. int boost_cap_microfarad; /* Required if boost_type == Internal */
  28. };
  29. static const struct cs35l41_config cs35l41_config_table[] = {
  30. { "10251826", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  31. { "1025182C", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  32. { "10251844", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  33. { "10280B27", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  34. { "10280B28", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  35. { "10280BEB", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 0, 0, 0 },
  36. { "10280C4D", 4, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT }, 0, 1, -1, 1000, 4500, 24 },
  37. /*
  38. * Device 103C89C6 does have _DSD, however it is setup to use the wrong boost type.
  39. * We can override the _DSD to correct the boost type here.
  40. * Since this laptop has valid ACPI, we do not need to handle cs-gpios, since that already exists
  41. * in the ACPI. The Reset GPIO is also valid, so we can use the Reset defined in _DSD.
  42. */
  43. { "103C89C6", 2, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, -1, -1, -1, 1000, 4500, 24 },
  44. { "103C8A28", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  45. { "103C8A29", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  46. { "103C8A2A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  47. { "103C8A2B", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  48. { "103C8A2C", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  49. { "103C8A2D", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  50. { "103C8A2E", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  51. { "103C8A30", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  52. { "103C8A31", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  53. { "103C8A6E", 4, EXTERNAL, { CS35L41_LEFT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_RIGHT }, 0, -1, -1, 0, 0, 0 },
  54. { "103C8BB3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  55. { "103C8BB4", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  56. { "103C8BDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  57. { "103C8BDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  58. { "103C8BDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  59. { "103C8BE0", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  60. { "103C8BE1", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  61. { "103C8BE2", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  62. { "103C8BE3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  63. { "103C8BE5", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  64. { "103C8BE6", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  65. { "103C8BE7", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  66. { "103C8BE8", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  67. { "103C8BE9", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  68. { "103C8B3A", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  69. { "103C8C15", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 },
  70. { "103C8C16", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 },
  71. { "103C8C17", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4000, 24 },
  72. { "103C8C4D", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  73. { "103C8C4E", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  74. { "103C8C4F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  75. { "103C8C50", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  76. { "103C8C51", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  77. { "103C8CDD", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4100, 24 },
  78. { "103C8CDE", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 3900, 24 },
  79. { "104312AF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  80. { "10431433", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  81. { "10431463", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  82. { "10431473", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
  83. { "10431483", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
  84. { "10431493", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  85. { "104314D3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  86. { "104314E3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  87. { "10431503", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  88. { "10431533", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  89. { "10431573", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  90. { "10431663", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 1000, 4500, 24 },
  91. { "10431683", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  92. { "104316A3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
  93. { "104316D3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
  94. { "104316F3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
  95. { "104317F3", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  96. { "10431863", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  97. { "104318D3", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  98. { "10431A83", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  99. { "10431B93", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  100. { "10431C9F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  101. { "10431CAF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  102. { "10431CCF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  103. { "10431CDF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  104. { "10431CEF", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  105. { "10431D1F", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  106. { "10431DA2", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
  107. { "10431E02", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
  108. { "10431E12", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  109. { "10431EE2", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  110. { "10431F12", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 1000, 4500, 24 },
  111. { "10431F1F", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, -1, 0, 0, 0, 0 },
  112. { "10431F62", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 0, 0, 0 },
  113. { "10433A20", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  114. { "10433A30", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  115. { "10433A40", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  116. { "10433A50", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  117. { "10433A60", 2, INTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 1, 2, 0, 1000, 4500, 24 },
  118. { "17AA3865", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  119. { "17AA3866", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  120. { "17AA386E", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 2, -1, 0, 0, 0 },
  121. { "17AA386F", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  122. { "17AA3877", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  123. { "17AA3878", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, -1, -1, 0, 0, 0 },
  124. { "17AA38A9", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 2, -1, 0, 0, 0 },
  125. { "17AA38AB", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 2, -1, 0, 0, 0 },
  126. { "17AA38B4", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  127. { "17AA38B5", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  128. { "17AA38B6", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  129. { "17AA38B7", 2, EXTERNAL, { CS35L41_LEFT, CS35L41_RIGHT, 0, 0 }, 0, 1, -1, 0, 0, 0 },
  130. { "17AA38C7", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },
  131. { "17AA38C8", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },
  132. { "17AA38F9", 2, EXTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, 0, 2, -1, 0, 0, 0 },
  133. { "17AA38FA", 2, EXTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, 0, 0 }, 0, 2, -1, 0, 0, 0 },
  134. { "17AA3929", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },
  135. { "17AA392B", 4, INTERNAL, { CS35L41_RIGHT, CS35L41_LEFT, CS35L41_RIGHT, CS35L41_LEFT }, 0, 2, -1, 1000, 4500, 24 },
  136. {}
  137. };
  138. static int cs35l41_add_gpios(struct cs35l41_hda *cs35l41, struct device *physdev, int reset_gpio,
  139. int spkid_gpio, int cs_gpio_index, int num_amps)
  140. {
  141. struct acpi_gpio_mapping *gpio_mapping = NULL;
  142. struct acpi_gpio_params *reset_gpio_params = NULL;
  143. struct acpi_gpio_params *spkid_gpio_params = NULL;
  144. struct acpi_gpio_params *cs_gpio_params = NULL;
  145. unsigned int num_entries = 0;
  146. unsigned int reset_index, spkid_index, csgpio_index;
  147. int i;
  148. /*
  149. * GPIO Mapping only needs to be done once, since it would be available for subsequent amps
  150. */
  151. if (cs35l41->dacpi->driver_gpios)
  152. return 0;
  153. if (reset_gpio >= 0) {
  154. reset_index = num_entries;
  155. num_entries++;
  156. }
  157. if (spkid_gpio >= 0) {
  158. spkid_index = num_entries;
  159. num_entries++;
  160. }
  161. if ((cs_gpio_index >= 0) && (num_amps == 2)) {
  162. csgpio_index = num_entries;
  163. num_entries++;
  164. }
  165. if (!num_entries)
  166. return 0;
  167. /* must include termination entry */
  168. num_entries++;
  169. gpio_mapping = devm_kcalloc(physdev, num_entries, sizeof(struct acpi_gpio_mapping),
  170. GFP_KERNEL);
  171. if (!gpio_mapping)
  172. goto err;
  173. if (reset_gpio >= 0) {
  174. gpio_mapping[reset_index].name = "reset-gpios";
  175. reset_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),
  176. GFP_KERNEL);
  177. if (!reset_gpio_params)
  178. goto err;
  179. for (i = 0; i < num_amps; i++)
  180. reset_gpio_params[i].crs_entry_index = reset_gpio;
  181. gpio_mapping[reset_index].data = reset_gpio_params;
  182. gpio_mapping[reset_index].size = num_amps;
  183. }
  184. if (spkid_gpio >= 0) {
  185. gpio_mapping[spkid_index].name = "spk-id-gpios";
  186. spkid_gpio_params = devm_kcalloc(physdev, num_amps, sizeof(struct acpi_gpio_params),
  187. GFP_KERNEL);
  188. if (!spkid_gpio_params)
  189. goto err;
  190. for (i = 0; i < num_amps; i++)
  191. spkid_gpio_params[i].crs_entry_index = spkid_gpio;
  192. gpio_mapping[spkid_index].data = spkid_gpio_params;
  193. gpio_mapping[spkid_index].size = num_amps;
  194. }
  195. if ((cs_gpio_index >= 0) && (num_amps == 2)) {
  196. gpio_mapping[csgpio_index].name = "cs-gpios";
  197. /* only one GPIO CS is supported without using _DSD, obtained using index 0 */
  198. cs_gpio_params = devm_kzalloc(physdev, sizeof(struct acpi_gpio_params), GFP_KERNEL);
  199. if (!cs_gpio_params)
  200. goto err;
  201. cs_gpio_params->crs_entry_index = cs_gpio_index;
  202. gpio_mapping[csgpio_index].data = cs_gpio_params;
  203. gpio_mapping[csgpio_index].size = 1;
  204. }
  205. return devm_acpi_dev_add_driver_gpios(physdev, gpio_mapping);
  206. err:
  207. devm_kfree(physdev, gpio_mapping);
  208. devm_kfree(physdev, reset_gpio_params);
  209. devm_kfree(physdev, spkid_gpio_params);
  210. devm_kfree(physdev, cs_gpio_params);
  211. return -ENOMEM;
  212. }
  213. static int generic_dsd_config(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
  214. const char *hid)
  215. {
  216. struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
  217. const struct cs35l41_config *cfg;
  218. struct gpio_desc *cs_gpiod;
  219. struct spi_device *spi;
  220. bool dsd_found;
  221. int ret;
  222. int i;
  223. for (cfg = cs35l41_config_table; cfg->ssid; cfg++) {
  224. if (!strcasecmp(cfg->ssid, cs35l41->acpi_subsystem_id))
  225. break;
  226. }
  227. if (!cfg->ssid)
  228. return -ENOENT;
  229. if (!cs35l41->dacpi || cs35l41->dacpi != ACPI_COMPANION(physdev)) {
  230. dev_err(cs35l41->dev, "ACPI Device does not match, cannot override _DSD.\n");
  231. return -ENODEV;
  232. }
  233. dev_info(cs35l41->dev, "Adding DSD properties for %s\n", cs35l41->acpi_subsystem_id);
  234. dsd_found = acpi_dev_has_props(cs35l41->dacpi);
  235. if (!dsd_found) {
  236. ret = cs35l41_add_gpios(cs35l41, physdev, cfg->reset_gpio_index,
  237. cfg->spkid_gpio_index, cfg->cs_gpio_index,
  238. cfg->num_amps);
  239. if (ret) {
  240. dev_err(cs35l41->dev, "Error adding GPIO mapping: %d\n", ret);
  241. return ret;
  242. }
  243. } else if (cfg->reset_gpio_index >= 0 || cfg->spkid_gpio_index >= 0) {
  244. dev_warn(cs35l41->dev, "Cannot add Reset/Speaker ID/SPI CS GPIO Mapping, "
  245. "_DSD already exists.\n");
  246. }
  247. if (cs35l41->control_bus == SPI) {
  248. cs35l41->index = id;
  249. /*
  250. * Manually set the Chip Select for the second amp <cs_gpio_index> in the node.
  251. * This is only supported for systems with 2 amps, since we cannot expand the
  252. * default number of chip selects without using cs-gpios
  253. * The CS GPIO must be set high prior to communicating with the first amp (which
  254. * uses a native chip select), to ensure the second amp does not clash with the
  255. * first.
  256. */
  257. if (IS_ENABLED(CONFIG_SPI) && cfg->cs_gpio_index >= 0) {
  258. spi = to_spi_device(cs35l41->dev);
  259. if (cfg->num_amps != 2) {
  260. dev_warn(cs35l41->dev,
  261. "Cannot update SPI CS, Number of Amps (%d) != 2\n",
  262. cfg->num_amps);
  263. } else if (dsd_found) {
  264. dev_warn(cs35l41->dev,
  265. "Cannot update SPI CS, _DSD already exists.\n");
  266. } else {
  267. /*
  268. * This is obtained using driver_gpios, since only one GPIO for CS
  269. * exists, this can be obtained using index 0.
  270. */
  271. cs_gpiod = gpiod_get_index(physdev, "cs", 0, GPIOD_OUT_LOW);
  272. if (IS_ERR(cs_gpiod)) {
  273. dev_err(cs35l41->dev,
  274. "Unable to get Chip Select GPIO descriptor\n");
  275. return PTR_ERR(cs_gpiod);
  276. }
  277. if (id == 1) {
  278. spi_set_csgpiod(spi, 0, cs_gpiod);
  279. cs35l41->cs_gpio = cs_gpiod;
  280. } else {
  281. gpiod_set_value_cansleep(cs_gpiod, true);
  282. gpiod_put(cs_gpiod);
  283. }
  284. spi_setup(spi);
  285. }
  286. }
  287. } else {
  288. if (cfg->num_amps > 2)
  289. /*
  290. * i2c addresses for 3/4 amps are used in order: 0x40, 0x41, 0x42, 0x43,
  291. * subtracting 0x40 would give zero-based index
  292. */
  293. cs35l41->index = id - 0x40;
  294. else
  295. /* i2c addr 0x40 for first amp (always), 0x41/0x42 for 2nd amp */
  296. cs35l41->index = id == 0x40 ? 0 : 1;
  297. }
  298. cs35l41->reset_gpio = fwnode_gpiod_get_index(acpi_fwnode_handle(cs35l41->dacpi), "reset",
  299. cs35l41->index, GPIOD_OUT_LOW,
  300. "cs35l41-reset");
  301. cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, cfg->num_amps, -1);
  302. hw_cfg->spk_pos = cfg->channel[cs35l41->index];
  303. cs35l41->channel_index = 0;
  304. for (i = 0; i < cs35l41->index; i++)
  305. if (cfg->channel[i] == hw_cfg->spk_pos)
  306. cs35l41->channel_index++;
  307. if (cfg->boost_type == INTERNAL) {
  308. hw_cfg->bst_type = CS35L41_INT_BOOST;
  309. hw_cfg->bst_ind = cfg->boost_ind_nanohenry;
  310. hw_cfg->bst_ipk = cfg->boost_peak_milliamp;
  311. hw_cfg->bst_cap = cfg->boost_cap_microfarad;
  312. hw_cfg->gpio1.func = CS35L41_NOT_USED;
  313. hw_cfg->gpio1.valid = true;
  314. } else {
  315. hw_cfg->bst_type = CS35L41_EXT_BOOST;
  316. hw_cfg->bst_ind = -1;
  317. hw_cfg->bst_ipk = -1;
  318. hw_cfg->bst_cap = -1;
  319. hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;
  320. hw_cfg->gpio1.valid = true;
  321. }
  322. hw_cfg->gpio2.func = CS35L41_INTERRUPT;
  323. hw_cfg->gpio2.valid = true;
  324. hw_cfg->valid = true;
  325. return 0;
  326. }
  327. /*
  328. * Systems 103C8C66, 103C8C67, 103C8C68, 103C8C6A use a dual speaker id system - each speaker has
  329. * its own speaker id.
  330. */
  331. static int hp_i2c_int_2amp_dual_spkid(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
  332. const char *hid)
  333. {
  334. struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
  335. /* If _DSD exists for this laptop, we cannot support it through here */
  336. if (acpi_dev_has_props(cs35l41->dacpi))
  337. return -ENOENT;
  338. /* check I2C address to assign the index */
  339. cs35l41->index = id == 0x40 ? 0 : 1;
  340. cs35l41->channel_index = 0;
  341. cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
  342. if (cs35l41->index == 0)
  343. cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 1);
  344. else
  345. cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);
  346. hw_cfg->spk_pos = cs35l41->index;
  347. hw_cfg->gpio2.func = CS35L41_INTERRUPT;
  348. hw_cfg->gpio2.valid = true;
  349. hw_cfg->valid = true;
  350. hw_cfg->bst_type = CS35L41_INT_BOOST;
  351. hw_cfg->bst_ind = 1000;
  352. hw_cfg->bst_ipk = 4100;
  353. hw_cfg->bst_cap = 24;
  354. hw_cfg->gpio1.func = CS35L41_NOT_USED;
  355. hw_cfg->gpio1.valid = true;
  356. return 0;
  357. }
  358. /*
  359. * Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work.
  360. * And devices created by serial-multi-instantiate don't have their device struct
  361. * pointing to the correct fwnode, so acpi_dev must be used here.
  362. * And devm functions expect that the device requesting the resource has the correct
  363. * fwnode.
  364. */
  365. static int lenovo_legion_no_acpi(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
  366. const char *hid)
  367. {
  368. struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg;
  369. /* check I2C address to assign the index */
  370. cs35l41->index = id == 0x40 ? 0 : 1;
  371. cs35l41->channel_index = 0;
  372. cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
  373. cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2);
  374. hw_cfg->spk_pos = cs35l41->index;
  375. hw_cfg->gpio2.func = CS35L41_INTERRUPT;
  376. hw_cfg->gpio2.valid = true;
  377. hw_cfg->valid = true;
  378. if (strcmp(hid, "CLSA0100") == 0) {
  379. hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH;
  380. } else if (strcmp(hid, "CLSA0101") == 0) {
  381. hw_cfg->bst_type = CS35L41_EXT_BOOST;
  382. hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH;
  383. hw_cfg->gpio1.valid = true;
  384. }
  385. return 0;
  386. }
  387. static int missing_speaker_id_gpio2(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
  388. const char *hid)
  389. {
  390. int ret;
  391. ret = cs35l41_add_gpios(cs35l41, physdev, -1, 2, -1, 2);
  392. if (ret) {
  393. dev_err(cs35l41->dev, "Error adding GPIO mapping: %d\n", ret);
  394. return ret;
  395. }
  396. return cs35l41_hda_parse_acpi(cs35l41, physdev, id);
  397. }
  398. struct cs35l41_prop_model {
  399. const char *hid;
  400. const char *ssid;
  401. int (*add_prop)(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
  402. const char *hid);
  403. };
  404. static const struct cs35l41_prop_model cs35l41_prop_model_table[] = {
  405. { "CLSA0100", NULL, lenovo_legion_no_acpi },
  406. { "CLSA0101", NULL, lenovo_legion_no_acpi },
  407. { "CSC3551", "10251826", generic_dsd_config },
  408. { "CSC3551", "1025182C", generic_dsd_config },
  409. { "CSC3551", "10251844", generic_dsd_config },
  410. { "CSC3551", "10280B27", generic_dsd_config },
  411. { "CSC3551", "10280B28", generic_dsd_config },
  412. { "CSC3551", "10280BEB", generic_dsd_config },
  413. { "CSC3551", "10280C4D", generic_dsd_config },
  414. { "CSC3551", "103C89C6", generic_dsd_config },
  415. { "CSC3551", "103C8A28", generic_dsd_config },
  416. { "CSC3551", "103C8A29", generic_dsd_config },
  417. { "CSC3551", "103C8A2A", generic_dsd_config },
  418. { "CSC3551", "103C8A2B", generic_dsd_config },
  419. { "CSC3551", "103C8A2C", generic_dsd_config },
  420. { "CSC3551", "103C8A2D", generic_dsd_config },
  421. { "CSC3551", "103C8A2E", generic_dsd_config },
  422. { "CSC3551", "103C8A30", generic_dsd_config },
  423. { "CSC3551", "103C8A31", generic_dsd_config },
  424. { "CSC3551", "103C8A6E", generic_dsd_config },
  425. { "CSC3551", "103C8BB3", generic_dsd_config },
  426. { "CSC3551", "103C8BB4", generic_dsd_config },
  427. { "CSC3551", "103C8BDD", generic_dsd_config },
  428. { "CSC3551", "103C8BDE", generic_dsd_config },
  429. { "CSC3551", "103C8BDF", generic_dsd_config },
  430. { "CSC3551", "103C8BE0", generic_dsd_config },
  431. { "CSC3551", "103C8BE1", generic_dsd_config },
  432. { "CSC3551", "103C8BE2", generic_dsd_config },
  433. { "CSC3551", "103C8BE3", generic_dsd_config },
  434. { "CSC3551", "103C8BE5", generic_dsd_config },
  435. { "CSC3551", "103C8BE6", generic_dsd_config },
  436. { "CSC3551", "103C8BE7", generic_dsd_config },
  437. { "CSC3551", "103C8BE8", generic_dsd_config },
  438. { "CSC3551", "103C8BE9", generic_dsd_config },
  439. { "CSC3551", "103C8B3A", generic_dsd_config },
  440. { "CSC3551", "103C8C15", generic_dsd_config },
  441. { "CSC3551", "103C8C16", generic_dsd_config },
  442. { "CSC3551", "103C8C17", generic_dsd_config },
  443. { "CSC3551", "103C8C4D", generic_dsd_config },
  444. { "CSC3551", "103C8C4E", generic_dsd_config },
  445. { "CSC3551", "103C8C4F", generic_dsd_config },
  446. { "CSC3551", "103C8C50", generic_dsd_config },
  447. { "CSC3551", "103C8C51", generic_dsd_config },
  448. { "CSC3551", "103C8C66", hp_i2c_int_2amp_dual_spkid },
  449. { "CSC3551", "103C8C67", hp_i2c_int_2amp_dual_spkid },
  450. { "CSC3551", "103C8C68", hp_i2c_int_2amp_dual_spkid },
  451. { "CSC3551", "103C8C6A", hp_i2c_int_2amp_dual_spkid },
  452. { "CSC3551", "103C8CDD", generic_dsd_config },
  453. { "CSC3551", "103C8CDE", generic_dsd_config },
  454. { "CSC3551", "104312AF", generic_dsd_config },
  455. { "CSC3551", "10431433", generic_dsd_config },
  456. { "CSC3551", "10431463", generic_dsd_config },
  457. { "CSC3551", "10431473", generic_dsd_config },
  458. { "CSC3551", "10431483", generic_dsd_config },
  459. { "CSC3551", "10431493", generic_dsd_config },
  460. { "CSC3551", "104314D3", generic_dsd_config },
  461. { "CSC3551", "104314E3", generic_dsd_config },
  462. { "CSC3551", "10431503", generic_dsd_config },
  463. { "CSC3551", "10431533", generic_dsd_config },
  464. { "CSC3551", "10431573", generic_dsd_config },
  465. { "CSC3551", "10431663", generic_dsd_config },
  466. { "CSC3551", "10431683", generic_dsd_config },
  467. { "CSC3551", "104316A3", generic_dsd_config },
  468. { "CSC3551", "104316D3", generic_dsd_config },
  469. { "CSC3551", "104316F3", generic_dsd_config },
  470. { "CSC3551", "104317F3", generic_dsd_config },
  471. { "CSC3551", "10431863", generic_dsd_config },
  472. { "CSC3551", "104318D3", generic_dsd_config },
  473. { "CSC3551", "10431A63", missing_speaker_id_gpio2 },
  474. { "CSC3551", "10431A83", generic_dsd_config },
  475. { "CSC3551", "10431B93", generic_dsd_config },
  476. { "CSC3551", "10431C9F", generic_dsd_config },
  477. { "CSC3551", "10431CAF", generic_dsd_config },
  478. { "CSC3551", "10431CCF", generic_dsd_config },
  479. { "CSC3551", "10431CDF", generic_dsd_config },
  480. { "CSC3551", "10431CEF", generic_dsd_config },
  481. { "CSC3551", "10431D1F", generic_dsd_config },
  482. { "CSC3551", "10431DA2", generic_dsd_config },
  483. { "CSC3551", "10431E02", generic_dsd_config },
  484. { "CSC3551", "10431E12", generic_dsd_config },
  485. { "CSC3551", "10431EE2", generic_dsd_config },
  486. { "CSC3551", "10431F12", generic_dsd_config },
  487. { "CSC3551", "10431F1F", generic_dsd_config },
  488. { "CSC3551", "10431F62", generic_dsd_config },
  489. { "CSC3551", "10433A20", generic_dsd_config },
  490. { "CSC3551", "10433A30", generic_dsd_config },
  491. { "CSC3551", "10433A40", generic_dsd_config },
  492. { "CSC3551", "10433A50", generic_dsd_config },
  493. { "CSC3551", "10433A60", generic_dsd_config },
  494. { "CSC3551", "17AA3865", generic_dsd_config },
  495. { "CSC3551", "17AA3866", generic_dsd_config },
  496. { "CSC3551", "17AA386E", generic_dsd_config },
  497. { "CSC3551", "17AA386F", generic_dsd_config },
  498. { "CSC3551", "17AA3877", generic_dsd_config },
  499. { "CSC3551", "17AA3878", generic_dsd_config },
  500. { "CSC3551", "17AA38A9", generic_dsd_config },
  501. { "CSC3551", "17AA38AB", generic_dsd_config },
  502. { "CSC3551", "17AA38B4", generic_dsd_config },
  503. { "CSC3551", "17AA38B5", generic_dsd_config },
  504. { "CSC3551", "17AA38B6", generic_dsd_config },
  505. { "CSC3551", "17AA38B7", generic_dsd_config },
  506. { "CSC3551", "17AA38C7", generic_dsd_config },
  507. { "CSC3551", "17AA38C8", generic_dsd_config },
  508. { "CSC3551", "17AA38F9", generic_dsd_config },
  509. { "CSC3551", "17AA38FA", generic_dsd_config },
  510. { "CSC3551", "17AA3929", generic_dsd_config },
  511. { "CSC3551", "17AA392B", generic_dsd_config },
  512. {}
  513. };
  514. int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physdev, int id,
  515. const char *hid)
  516. {
  517. const struct cs35l41_prop_model *model;
  518. for (model = cs35l41_prop_model_table; model->hid; model++) {
  519. if (!strcmp(model->hid, hid) &&
  520. (!model->ssid ||
  521. (cs35l41->acpi_subsystem_id &&
  522. !strcasecmp(model->ssid, cs35l41->acpi_subsystem_id))))
  523. return model->add_prop(cs35l41, physdev, id, hid);
  524. }
  525. return -ENOENT;
  526. }