wsa883x.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/init.h>
  7. #include <linux/slab.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/device.h>
  10. #include <linux/printk.h>
  11. #include <linux/bitops.h>
  12. #include <linux/regulator/consumer.h>
  13. #include <linux/pm_runtime.h>
  14. #include <linux/delay.h>
  15. #include <linux/kernel.h>
  16. #include <linux/gpio.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/regmap.h>
  20. #include <linux/debugfs.h>
  21. #include <soc/soundwire.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include <sound/tlv.h>
  27. #include <asoc/msm-cdc-pinctrl.h>
  28. #include <asoc/msm-cdc-supply.h>
  29. #include "wsa883x-registers.h"
  30. #include "wsa883x.h"
  31. #include "internal.h"
  32. #include "asoc/bolero-slave-internal.h"
  33. #include <linux/qti-regmap-debugfs.h>
  34. #define T1_TEMP -10
  35. #define T2_TEMP 150
  36. #define LOW_TEMP_THRESHOLD 5
  37. #define HIGH_TEMP_THRESHOLD 45
  38. #define TEMP_INVALID 0xFFFF
  39. #define WSA883X_TEMP_RETRY 3
  40. #define MAX_NAME_LEN 40
  41. #define WSA883X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  42. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  43. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  44. SNDRV_PCM_RATE_384000)
  45. /* Fractional Rates */
  46. #define WSA883X_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  47. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  48. #define WSA883X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  49. SNDRV_PCM_FMTBIT_S24_LE |\
  50. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  51. enum {
  52. WSA_4OHMS =4,
  53. WSA_8OHMS = 8,
  54. WSA_16OHMS = 16,
  55. WSA_32OHMS = 32,
  56. };
  57. struct wsa_temp_register {
  58. u8 d1_msb;
  59. u8 d1_lsb;
  60. u8 d2_msb;
  61. u8 d2_lsb;
  62. u8 dmeas_msb;
  63. u8 dmeas_lsb;
  64. };
  65. enum {
  66. COMP_OFFSET0,
  67. COMP_OFFSET1,
  68. COMP_OFFSET2,
  69. COMP_OFFSET3,
  70. COMP_OFFSET4,
  71. };
  72. struct wsa_reg_mask_val {
  73. u16 reg;
  74. u8 mask;
  75. u8 val;
  76. };
  77. static const struct wsa_reg_mask_val reg_init[] = {
  78. {WSA883X_PA_FSM_BYP, 0x01, 0x00},
  79. {WSA883X_ISENSE2, 0xE0, 0x40},
  80. {WSA883X_ADC_6, 0x02, 0x02},
  81. {WSA883X_CDC_SPK_DSM_A2_0, 0xFF, 0x0A},
  82. {WSA883X_CDC_SPK_DSM_A2_1, 0x0F, 0x08},
  83. {WSA883X_CDC_SPK_DSM_A3_0, 0xFF, 0xF3},
  84. {WSA883X_CDC_SPK_DSM_A3_1, 0x07, 0x07},
  85. {WSA883X_CDC_SPK_DSM_A4_0, 0xFF, 0x79},
  86. {WSA883X_CDC_SPK_DSM_A4_1, 0x03, 0x02},
  87. {WSA883X_CDC_SPK_DSM_A5_0, 0xFF, 0x0B},
  88. {WSA883X_CDC_SPK_DSM_A5_1, 0x03, 0x02},
  89. {WSA883X_CDC_SPK_DSM_A6_0, 0xFF, 0x8A},
  90. {WSA883X_CDC_SPK_DSM_A7_0, 0xFF, 0x9B},
  91. {WSA883X_CDC_SPK_DSM_C_0, 0xFF, 0x68},
  92. {WSA883X_CDC_SPK_DSM_C_1, 0xFF, 0x54},
  93. {WSA883X_CDC_SPK_DSM_C_2, 0xFF, 0xF2},
  94. {WSA883X_CDC_SPK_DSM_C_3, 0x3F, 0x20},
  95. {WSA883X_CDC_SPK_DSM_R1, 0xFF, 0x83},
  96. {WSA883X_CDC_SPK_DSM_R2, 0xFF, 0x7F},
  97. {WSA883X_CDC_SPK_DSM_R3, 0xFF, 0x9D},
  98. {WSA883X_CDC_SPK_DSM_R4, 0xFF, 0x82},
  99. {WSA883X_CDC_SPK_DSM_R5, 0xFF, 0x8B},
  100. {WSA883X_CDC_SPK_DSM_R6, 0xFF, 0x9B},
  101. {WSA883X_CDC_SPK_DSM_R7, 0xFF, 0x3F},
  102. {WSA883X_VBAT_SNS, 0x60, 0x20},
  103. {WSA883X_DRE_CTL_0, 0xF0, 0x90},
  104. {WSA883X_DRE_IDLE_DET_CTL, 0x10, 0x00},
  105. {WSA883X_CURRENT_LIMIT, 0x78, 0x40},
  106. {WSA883X_DRE_CTL_0, 0x07, 0x02},
  107. {WSA883X_VAGC_TIME, 0x0F, 0x0F},
  108. {WSA883X_VAGC_ATTN_LVL_1_2, 0x77, 0x00},
  109. {WSA883X_VAGC_ATTN_LVL_3, 0x07, 0x01},
  110. {WSA883X_VAGC_CTL, 0x01, 0x01},
  111. {WSA883X_TAGC_CTL, 0x0E, 0x0A},
  112. {WSA883X_TAGC_TIME, 0x0C, 0x0C},
  113. {WSA883X_TAGC_E2E_GAIN, 0x1F, 0x02},
  114. {WSA883X_TEMP_CONFIG0, 0x07, 0x02},
  115. {WSA883X_TEMP_CONFIG1, 0x07, 0x02},
  116. {WSA883X_OTP_REG_1, 0xFF, 0x49},
  117. {WSA883X_OTP_REG_2, 0xC0, 0x80},
  118. {WSA883X_OTP_REG_3, 0xFF, 0xC9},
  119. {WSA883X_OTP_REG_4, 0xC0, 0x40},
  120. {WSA883X_TAGC_CTL, 0x01, 0x01},
  121. {WSA883X_ADC_2, 0x40, 0x00},
  122. {WSA883X_ADC_7, 0x04, 0x04},
  123. {WSA883X_ADC_7, 0x02, 0x02},
  124. {WSA883X_CKWD_CTL_0, 0x60, 0x00},
  125. {WSA883X_DRE_CTL_1, 0x3E, 0x20},
  126. {WSA883X_CKWD_CTL_1, 0x1F, 0x1B},
  127. {WSA883X_GMAMP_SUP1, 0x60, 0x60},
  128. };
  129. static int wsa883x_handle_post_irq(void *data);
  130. static int wsa883x_get_temperature(struct snd_soc_component *component,
  131. int *temp);
  132. enum {
  133. WSA8830 = 0,
  134. WSA8835,
  135. WSA8832,
  136. WSA8835_V2 = 5,
  137. };
  138. enum {
  139. SPKR_STATUS = 0,
  140. WSA_SUPPLIES_LPM_MODE,
  141. SPKR_ADIE_LB,
  142. };
  143. enum {
  144. WSA883X_IRQ_INT_SAF2WAR = 0,
  145. WSA883X_IRQ_INT_WAR2SAF,
  146. WSA883X_IRQ_INT_DISABLE,
  147. WSA883X_IRQ_INT_OCP,
  148. WSA883X_IRQ_INT_CLIP,
  149. WSA883X_IRQ_INT_PDM_WD,
  150. WSA883X_IRQ_INT_CLK_WD,
  151. WSA883X_IRQ_INT_INTR_PIN,
  152. WSA883X_IRQ_INT_UVLO,
  153. WSA883X_IRQ_INT_PA_ON_ERR,
  154. WSA883X_NUM_IRQS,
  155. };
  156. static const struct regmap_irq wsa883x_irqs[WSA883X_NUM_IRQS] = {
  157. REGMAP_IRQ_REG(WSA883X_IRQ_INT_SAF2WAR, 0, 0x01),
  158. REGMAP_IRQ_REG(WSA883X_IRQ_INT_WAR2SAF, 0, 0x02),
  159. REGMAP_IRQ_REG(WSA883X_IRQ_INT_DISABLE, 0, 0x04),
  160. REGMAP_IRQ_REG(WSA883X_IRQ_INT_OCP, 0, 0x08),
  161. REGMAP_IRQ_REG(WSA883X_IRQ_INT_CLIP, 0, 0x10),
  162. REGMAP_IRQ_REG(WSA883X_IRQ_INT_PDM_WD, 0, 0x20),
  163. REGMAP_IRQ_REG(WSA883X_IRQ_INT_CLK_WD, 0, 0x40),
  164. REGMAP_IRQ_REG(WSA883X_IRQ_INT_INTR_PIN, 0, 0x80),
  165. REGMAP_IRQ_REG(WSA883X_IRQ_INT_UVLO, 1, 0x01),
  166. REGMAP_IRQ_REG(WSA883X_IRQ_INT_PA_ON_ERR, 1, 0x02),
  167. };
  168. static struct regmap_irq_chip wsa883x_regmap_irq_chip = {
  169. .name = "wsa883x",
  170. .irqs = wsa883x_irqs,
  171. .num_irqs = ARRAY_SIZE(wsa883x_irqs),
  172. .num_regs = 2,
  173. .status_base = WSA883X_INTR_STATUS0,
  174. .mask_base = WSA883X_INTR_MASK0,
  175. .type_base = WSA883X_INTR_LEVEL0,
  176. .ack_base = WSA883X_INTR_CLEAR0,
  177. .use_ack = 1,
  178. .runtime_pm = false,
  179. .handle_post_irq = wsa883x_handle_post_irq,
  180. .irq_drv_data = NULL,
  181. };
  182. static int wsa883x_handle_post_irq(void *data)
  183. {
  184. struct wsa883x_priv *wsa883x = data;
  185. u32 sts1 = 0, sts2 = 0;
  186. regmap_read(wsa883x->regmap, WSA883X_INTR_STATUS0, &sts1);
  187. regmap_read(wsa883x->regmap, WSA883X_INTR_STATUS1, &sts2);
  188. wsa883x->swr_slave->slave_irq_pending =
  189. ((sts1 || sts2) ? true : false);
  190. return IRQ_HANDLED;
  191. }
  192. #ifdef CONFIG_DEBUG_FS
  193. static int codec_debug_open(struct inode *inode, struct file *file)
  194. {
  195. file->private_data = inode->i_private;
  196. return 0;
  197. }
  198. static int get_parameters(char *buf, u32 *param1, int num_of_par)
  199. {
  200. char *token;
  201. int base, cnt;
  202. token = strsep(&buf, " ");
  203. for (cnt = 0; cnt < num_of_par; cnt++) {
  204. if (token) {
  205. if ((token[1] == 'x') || (token[1] == 'X'))
  206. base = 16;
  207. else
  208. base = 10;
  209. if (kstrtou32(token, base, &param1[cnt]) != 0)
  210. return -EINVAL;
  211. token = strsep(&buf, " ");
  212. } else {
  213. return -EINVAL;
  214. }
  215. }
  216. return 0;
  217. }
  218. static bool is_swr_slave_reg_readable(int reg)
  219. {
  220. int ret = true;
  221. if (((reg > 0x46) && (reg < 0x4A)) ||
  222. ((reg > 0x4A) && (reg < 0x50)) ||
  223. ((reg > 0x55) && (reg < 0xD0)) ||
  224. ((reg > 0xD0) && (reg < 0xE0)) ||
  225. ((reg > 0xE0) && (reg < 0xF0)) ||
  226. ((reg > 0xF0) && (reg < 0x100)) ||
  227. ((reg > 0x105) && (reg < 0x120)) ||
  228. ((reg > 0x205) && (reg < 0x220)) ||
  229. ((reg > 0x305) && (reg < 0x320)) ||
  230. ((reg > 0x405) && (reg < 0x420)) ||
  231. ((reg > 0x128) && (reg < 0x130)) ||
  232. ((reg > 0x228) && (reg < 0x230)) ||
  233. ((reg > 0x328) && (reg < 0x330)) ||
  234. ((reg > 0x428) && (reg < 0x430)) ||
  235. ((reg > 0x138) && (reg < 0x205)) ||
  236. ((reg > 0x238) && (reg < 0x305)) ||
  237. ((reg > 0x338) && (reg < 0x405)) ||
  238. ((reg > 0x405) && (reg < 0xF00)) ||
  239. ((reg > 0xF05) && (reg < 0xF20)) ||
  240. ((reg > 0xF25) && (reg < 0xF30)) ||
  241. ((reg > 0xF35) && (reg < 0x2000)))
  242. ret = false;
  243. return ret;
  244. }
  245. static ssize_t swr_slave_reg_show(struct swr_device *pdev, char __user *ubuf,
  246. size_t count, loff_t *ppos)
  247. {
  248. int i, reg_val, len;
  249. ssize_t total = 0;
  250. char tmp_buf[SWR_SLV_MAX_BUF_LEN];
  251. if (!ubuf || !ppos)
  252. return 0;
  253. for (i = (((int) *ppos/BYTES_PER_LINE) + SWR_SLV_START_REG_ADDR);
  254. i <= SWR_SLV_MAX_REG_ADDR; i++) {
  255. if (!is_swr_slave_reg_readable(i))
  256. continue;
  257. swr_read(pdev, pdev->dev_num, i, &reg_val, 1);
  258. len = snprintf(tmp_buf, sizeof(tmp_buf), "0x%.3x: 0x%.2x\n", i,
  259. (reg_val & 0xFF));
  260. if (len < 0) {
  261. pr_err("%s: fail to fill the buffer\n", __func__);
  262. total = -EFAULT;
  263. goto copy_err;
  264. }
  265. if ((total + len) >= count - 1)
  266. break;
  267. if (copy_to_user((ubuf + total), tmp_buf, len)) {
  268. pr_err("%s: fail to copy reg dump\n", __func__);
  269. total = -EFAULT;
  270. goto copy_err;
  271. }
  272. total += len;
  273. *ppos += len;
  274. }
  275. copy_err:
  276. *ppos = SWR_SLV_MAX_REG_ADDR * BYTES_PER_LINE;
  277. return total;
  278. }
  279. static ssize_t codec_debug_dump(struct file *file, char __user *ubuf,
  280. size_t count, loff_t *ppos)
  281. {
  282. struct swr_device *pdev;
  283. if (!count || !file || !ppos || !ubuf)
  284. return -EINVAL;
  285. pdev = file->private_data;
  286. if (!pdev)
  287. return -EINVAL;
  288. if (*ppos < 0)
  289. return -EINVAL;
  290. return swr_slave_reg_show(pdev, ubuf, count, ppos);
  291. }
  292. static ssize_t codec_debug_read(struct file *file, char __user *ubuf,
  293. size_t count, loff_t *ppos)
  294. {
  295. char lbuf[SWR_SLV_RD_BUF_LEN];
  296. struct swr_device *pdev = NULL;
  297. struct wsa883x_priv *wsa883x = NULL;
  298. if (!count || !file || !ppos || !ubuf)
  299. return -EINVAL;
  300. pdev = file->private_data;
  301. if (!pdev)
  302. return -EINVAL;
  303. wsa883x = swr_get_dev_data(pdev);
  304. if (!wsa883x)
  305. return -EINVAL;
  306. if (*ppos < 0)
  307. return -EINVAL;
  308. snprintf(lbuf, sizeof(lbuf), "0x%x\n",
  309. (wsa883x->read_data & 0xFF));
  310. return simple_read_from_buffer(ubuf, count, ppos, lbuf,
  311. strnlen(lbuf, 7));
  312. }
  313. static ssize_t codec_debug_peek_write(struct file *file,
  314. const char __user *ubuf, size_t cnt, loff_t *ppos)
  315. {
  316. char lbuf[SWR_SLV_WR_BUF_LEN];
  317. int rc = 0;
  318. u32 param[5];
  319. struct swr_device *pdev = NULL;
  320. struct wsa883x_priv *wsa883x = NULL;
  321. if (!cnt || !file || !ppos || !ubuf)
  322. return -EINVAL;
  323. pdev = file->private_data;
  324. if (!pdev)
  325. return -EINVAL;
  326. wsa883x = swr_get_dev_data(pdev);
  327. if (!wsa883x)
  328. return -EINVAL;
  329. if (*ppos < 0)
  330. return -EINVAL;
  331. if (cnt > sizeof(lbuf) - 1)
  332. return -EINVAL;
  333. rc = copy_from_user(lbuf, ubuf, cnt);
  334. if (rc)
  335. return -EFAULT;
  336. lbuf[cnt] = '\0';
  337. rc = get_parameters(lbuf, param, 1);
  338. if (!((param[0] <= SWR_SLV_MAX_REG_ADDR) && (rc == 0)))
  339. return -EINVAL;
  340. swr_read(pdev, pdev->dev_num, param[0], &wsa883x->read_data, 1);
  341. if (rc == 0)
  342. rc = cnt;
  343. else
  344. pr_err("%s: rc = %d\n", __func__, rc);
  345. return rc;
  346. }
  347. static ssize_t codec_debug_write(struct file *file,
  348. const char __user *ubuf, size_t cnt, loff_t *ppos)
  349. {
  350. char lbuf[SWR_SLV_WR_BUF_LEN];
  351. int rc = 0;
  352. u32 param[5];
  353. struct swr_device *pdev;
  354. if (!file || !ppos || !ubuf)
  355. return -EINVAL;
  356. pdev = file->private_data;
  357. if (!pdev)
  358. return -EINVAL;
  359. if (cnt > sizeof(lbuf) - 1)
  360. return -EINVAL;
  361. rc = copy_from_user(lbuf, ubuf, cnt);
  362. if (rc)
  363. return -EFAULT;
  364. lbuf[cnt] = '\0';
  365. rc = get_parameters(lbuf, param, 2);
  366. if (!((param[0] <= SWR_SLV_MAX_REG_ADDR) &&
  367. (param[1] <= 0xFF) && (rc == 0)))
  368. return -EINVAL;
  369. swr_write(pdev, pdev->dev_num, param[0], &param[1]);
  370. if (rc == 0)
  371. rc = cnt;
  372. else
  373. pr_err("%s: rc = %d\n", __func__, rc);
  374. return rc;
  375. }
  376. static const struct file_operations codec_debug_write_ops = {
  377. .open = codec_debug_open,
  378. .write = codec_debug_write,
  379. };
  380. static const struct file_operations codec_debug_read_ops = {
  381. .open = codec_debug_open,
  382. .read = codec_debug_read,
  383. .write = codec_debug_peek_write,
  384. };
  385. static const struct file_operations codec_debug_dump_ops = {
  386. .open = codec_debug_open,
  387. .read = codec_debug_dump,
  388. };
  389. #endif
  390. static void wsa883x_regcache_sync(struct wsa883x_priv *wsa883x)
  391. {
  392. mutex_lock(&wsa883x->res_lock);
  393. regcache_mark_dirty(wsa883x->regmap);
  394. regcache_sync(wsa883x->regmap);
  395. mutex_unlock(&wsa883x->res_lock);
  396. }
  397. static irqreturn_t wsa883x_saf2war_handle_irq(int irq, void *data)
  398. {
  399. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  400. __func__, irq);
  401. return IRQ_HANDLED;
  402. }
  403. static irqreturn_t wsa883x_war2saf_handle_irq(int irq, void *data)
  404. {
  405. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  406. __func__, irq);
  407. return IRQ_HANDLED;
  408. }
  409. static irqreturn_t wsa883x_otp_handle_irq(int irq, void *data)
  410. {
  411. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  412. __func__, irq);
  413. return IRQ_HANDLED;
  414. }
  415. static irqreturn_t wsa883x_ocp_handle_irq(int irq, void *data)
  416. {
  417. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  418. __func__, irq);
  419. return IRQ_HANDLED;
  420. }
  421. static irqreturn_t wsa883x_clip_handle_irq(int irq, void *data)
  422. {
  423. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  424. __func__, irq);
  425. return IRQ_HANDLED;
  426. }
  427. static irqreturn_t wsa883x_pdm_wd_handle_irq(int irq, void *data)
  428. {
  429. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  430. __func__, irq);
  431. return IRQ_HANDLED;
  432. }
  433. static irqreturn_t wsa883x_clk_wd_handle_irq(int irq, void *data)
  434. {
  435. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  436. __func__, irq);
  437. return IRQ_HANDLED;
  438. }
  439. static irqreturn_t wsa883x_ext_int_handle_irq(int irq, void *data)
  440. {
  441. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  442. __func__, irq);
  443. return IRQ_HANDLED;
  444. }
  445. static irqreturn_t wsa883x_uvlo_handle_irq(int irq, void *data)
  446. {
  447. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  448. __func__, irq);
  449. return IRQ_HANDLED;
  450. }
  451. static irqreturn_t wsa883x_pa_on_err_handle_irq(int irq, void *data)
  452. {
  453. u8 pa_fsm_sta = 0, pa_fsm_err = 0;
  454. struct wsa883x_priv *wsa883x = data;
  455. struct snd_soc_component *component = NULL;
  456. if (!wsa883x)
  457. return IRQ_NONE;
  458. component = wsa883x->component;
  459. if (!component)
  460. return IRQ_NONE;
  461. pa_fsm_sta = (snd_soc_component_read(component, WSA883X_PA_FSM_STA)
  462. & 0x70);
  463. if (pa_fsm_sta)
  464. pa_fsm_err = snd_soc_component_read(component,
  465. WSA883X_PA_FSM_ERR_COND);
  466. pr_err_ratelimited("%s: interrupt for irq =%d triggered\n",
  467. __func__, irq);
  468. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  469. 0x10, 0x00);
  470. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  471. 0x10, 0x10);
  472. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  473. 0x10, 0x00);
  474. return IRQ_HANDLED;
  475. }
  476. static const char * const wsa_dev_mode_text[] = {
  477. "speaker", "receiver", "ultrasound"
  478. };
  479. enum {
  480. SPEAKER,
  481. RECEIVER,
  482. ULTRASOUND,
  483. };
  484. static const struct soc_enum wsa_dev_mode_enum =
  485. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa_dev_mode_text), wsa_dev_mode_text);
  486. static int wsa_dev_mode_get(struct snd_kcontrol *kcontrol,
  487. struct snd_ctl_elem_value *ucontrol)
  488. {
  489. struct snd_soc_component *component =
  490. snd_soc_kcontrol_component(kcontrol);
  491. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  492. ucontrol->value.integer.value[0] = wsa883x->dev_mode;
  493. dev_dbg(component->dev, "%s: mode = 0x%x\n", __func__,
  494. wsa883x->dev_mode);
  495. return 0;
  496. }
  497. static int wsa_dev_mode_put(struct snd_kcontrol *kcontrol,
  498. struct snd_ctl_elem_value *ucontrol)
  499. {
  500. struct snd_soc_component *component =
  501. snd_soc_kcontrol_component(kcontrol);
  502. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  503. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  504. __func__, ucontrol->value.integer.value[0]);
  505. wsa883x->dev_mode = ucontrol->value.integer.value[0];
  506. return 0;
  507. }
  508. static const char * const wsa_pa_gain_text[] = {
  509. "G_21_DB", "G_19P5_DB", "G_18_DB", "G_16P5_DB", "G_15_DB", "G_13P5_DB",
  510. "G_12_DB", "G_10P5_DB", "G_9_DB", "G_7P5_DB", "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB",
  511. "G_0_DB", "N_1P5_DB", "N_3_DB"
  512. };
  513. static const struct soc_enum wsa_pa_gain_enum =
  514. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa_pa_gain_text), wsa_pa_gain_text);
  515. static int wsa_pa_gain_get(struct snd_kcontrol *kcontrol,
  516. struct snd_ctl_elem_value *ucontrol)
  517. {
  518. struct snd_soc_component *component =
  519. snd_soc_kcontrol_component(kcontrol);
  520. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  521. ucontrol->value.integer.value[0] = wsa883x->pa_gain;
  522. dev_dbg(component->dev, "%s: PA gain = 0x%x\n", __func__,
  523. wsa883x->pa_gain);
  524. return 0;
  525. }
  526. static int wsa_pa_gain_put(struct snd_kcontrol *kcontrol,
  527. struct snd_ctl_elem_value *ucontrol)
  528. {
  529. struct snd_soc_component *component =
  530. snd_soc_kcontrol_component(kcontrol);
  531. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  532. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  533. __func__, ucontrol->value.integer.value[0]);
  534. wsa883x->pa_gain = ucontrol->value.integer.value[0];
  535. if (!wsa883x->comp_enable)
  536. snd_soc_component_update_bits(component,
  537. WSA883X_DRE_CTL_1,
  538. 0x3E, wsa883x->pa_gain << 1);
  539. return 0;
  540. }
  541. static int wsa883x_get_mute(struct snd_kcontrol *kcontrol,
  542. struct snd_ctl_elem_value *ucontrol)
  543. {
  544. struct snd_soc_component *component =
  545. snd_soc_kcontrol_component(kcontrol);
  546. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  547. ucontrol->value.integer.value[0] = wsa883x->pa_mute;
  548. return 0;
  549. }
  550. static int wsa883x_set_mute(struct snd_kcontrol *kcontrol,
  551. struct snd_ctl_elem_value *ucontrol)
  552. {
  553. struct snd_soc_component *component =
  554. snd_soc_kcontrol_component(kcontrol);
  555. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  556. int value = ucontrol->value.integer.value[0];
  557. dev_dbg(component->dev, "%s: mute current %d, new %d\n",
  558. __func__, wsa883x->pa_mute, value);
  559. wsa883x->pa_mute = value;
  560. return 0;
  561. }
  562. static int wsa_get_temp(struct snd_kcontrol *kcontrol,
  563. struct snd_ctl_elem_value *ucontrol)
  564. {
  565. struct snd_soc_component *component =
  566. snd_soc_kcontrol_component(kcontrol);
  567. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  568. int temp = 0;
  569. if (test_bit(SPKR_STATUS, &wsa883x->status_mask))
  570. temp = wsa883x->curr_temp;
  571. else
  572. wsa883x_get_temperature(component, &temp);
  573. ucontrol->value.integer.value[0] = temp;
  574. return 0;
  575. }
  576. static ssize_t wsa883x_codec_version_read(struct snd_info_entry *entry,
  577. void *file_private_data, struct file *file,
  578. char __user *buf, size_t count, loff_t pos)
  579. {
  580. struct wsa883x_priv *wsa883x;
  581. char buffer[WSA883X_VERSION_ENTRY_SIZE];
  582. int len = 0;
  583. wsa883x = (struct wsa883x_priv *) entry->private_data;
  584. if (!wsa883x) {
  585. pr_err("%s: wsa883x priv is null\n", __func__);
  586. return -EINVAL;
  587. }
  588. switch (wsa883x->version) {
  589. case WSA883X_VERSION_1_0:
  590. len = snprintf(buffer, sizeof(buffer), "WSA883X_1_0\n");
  591. break;
  592. case WSA883X_VERSION_1_1:
  593. len = snprintf(buffer, sizeof(buffer), "WSA883X_1_1\n");
  594. break;
  595. default:
  596. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  597. break;
  598. }
  599. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  600. }
  601. static struct snd_info_entry_ops wsa883x_codec_info_ops = {
  602. .read = wsa883x_codec_version_read,
  603. };
  604. static ssize_t wsa883x_variant_read(struct snd_info_entry *entry,
  605. void *file_private_data,
  606. struct file *file,
  607. char __user *buf, size_t count,
  608. loff_t pos)
  609. {
  610. struct wsa883x_priv *wsa883x;
  611. char buffer[WSA883X_VARIANT_ENTRY_SIZE];
  612. int len = 0;
  613. wsa883x = (struct wsa883x_priv *) entry->private_data;
  614. if (!wsa883x) {
  615. pr_err("%s: wsa883x priv is null\n", __func__);
  616. return -EINVAL;
  617. }
  618. switch (wsa883x->variant) {
  619. case WSA8830:
  620. len = snprintf(buffer, sizeof(buffer), "WSA8830\n");
  621. break;
  622. case WSA8835:
  623. case WSA8835_V2:
  624. len = snprintf(buffer, sizeof(buffer), "WSA8835\n");
  625. break;
  626. case WSA8832:
  627. len = snprintf(buffer, sizeof(buffer), "WSA8832\n");
  628. break;
  629. default:
  630. len = snprintf(buffer, sizeof(buffer), "UNDEFINED\n");
  631. break;
  632. }
  633. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  634. }
  635. static struct snd_info_entry_ops wsa883x_variant_ops = {
  636. .read = wsa883x_variant_read,
  637. };
  638. /*
  639. * wsa883x_codec_info_create_codec_entry - creates wsa883x module
  640. * @codec_root: The parent directory
  641. * @component: Codec instance
  642. *
  643. * Creates wsa883x module and version entry under the given
  644. * parent directory.
  645. *
  646. * Return: 0 on success or negative error code on failure.
  647. */
  648. int wsa883x_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  649. struct snd_soc_component *component)
  650. {
  651. struct snd_info_entry *version_entry;
  652. struct snd_info_entry *variant_entry;
  653. struct wsa883x_priv *wsa883x;
  654. struct snd_soc_card *card;
  655. char name[80];
  656. if (!codec_root || !component)
  657. return -EINVAL;
  658. wsa883x = snd_soc_component_get_drvdata(component);
  659. if (wsa883x->entry) {
  660. dev_dbg(wsa883x->dev,
  661. "%s:wsa883x module already created\n", __func__);
  662. return 0;
  663. }
  664. card = component->card;
  665. snprintf(name, sizeof(name), "%s.%llx", "wsa883x",
  666. wsa883x->swr_slave->addr);
  667. wsa883x->entry = snd_info_create_module_entry(codec_root->module,
  668. (const char *)name,
  669. codec_root);
  670. if (!wsa883x->entry) {
  671. dev_dbg(component->dev, "%s: failed to create wsa883x entry\n",
  672. __func__);
  673. return -ENOMEM;
  674. }
  675. wsa883x->entry->mode = S_IFDIR | 0555;
  676. if (snd_info_register(wsa883x->entry) < 0) {
  677. snd_info_free_entry(wsa883x->entry);
  678. return -ENOMEM;
  679. }
  680. version_entry = snd_info_create_card_entry(card->snd_card,
  681. "version",
  682. wsa883x->entry);
  683. if (!version_entry) {
  684. dev_dbg(component->dev, "%s: failed to create wsa883x version entry\n",
  685. __func__);
  686. snd_info_free_entry(wsa883x->entry);
  687. return -ENOMEM;
  688. }
  689. version_entry->private_data = wsa883x;
  690. version_entry->size = WSA883X_VERSION_ENTRY_SIZE;
  691. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  692. version_entry->c.ops = &wsa883x_codec_info_ops;
  693. if (snd_info_register(version_entry) < 0) {
  694. snd_info_free_entry(version_entry);
  695. snd_info_free_entry(wsa883x->entry);
  696. return -ENOMEM;
  697. }
  698. wsa883x->version_entry = version_entry;
  699. variant_entry = snd_info_create_card_entry(card->snd_card,
  700. "variant",
  701. wsa883x->entry);
  702. if (!variant_entry) {
  703. dev_dbg(component->dev,
  704. "%s: failed to create wsa883x variant entry\n",
  705. __func__);
  706. snd_info_free_entry(version_entry);
  707. snd_info_free_entry(wsa883x->entry);
  708. return -ENOMEM;
  709. }
  710. variant_entry->private_data = wsa883x;
  711. variant_entry->size = WSA883X_VARIANT_ENTRY_SIZE;
  712. variant_entry->content = SNDRV_INFO_CONTENT_DATA;
  713. variant_entry->c.ops = &wsa883x_variant_ops;
  714. if (snd_info_register(variant_entry) < 0) {
  715. snd_info_free_entry(variant_entry);
  716. snd_info_free_entry(version_entry);
  717. snd_info_free_entry(wsa883x->entry);
  718. return -ENOMEM;
  719. }
  720. wsa883x->variant_entry = variant_entry;
  721. return 0;
  722. }
  723. EXPORT_SYMBOL(wsa883x_codec_info_create_codec_entry);
  724. /*
  725. * wsa883x_codec_get_dev_num - returns swr device number
  726. * @component: Codec instance
  727. *
  728. * Return: swr device number on success or negative error
  729. * code on failure.
  730. */
  731. int wsa883x_codec_get_dev_num(struct snd_soc_component *component)
  732. {
  733. struct wsa883x_priv *wsa883x;
  734. if (!component)
  735. return -EINVAL;
  736. wsa883x = snd_soc_component_get_drvdata(component);
  737. if (!wsa883x) {
  738. pr_err("%s: wsa883x component is NULL\n", __func__);
  739. return -EINVAL;
  740. }
  741. return wsa883x->swr_slave->dev_num;
  742. }
  743. EXPORT_SYMBOL(wsa883x_codec_get_dev_num);
  744. static int wsa883x_get_dev_num(struct snd_kcontrol *kcontrol,
  745. struct snd_ctl_elem_value *ucontrol)
  746. {
  747. struct snd_soc_component *component =
  748. snd_soc_kcontrol_component(kcontrol);
  749. struct wsa883x_priv *wsa883x;
  750. if (!component)
  751. return -EINVAL;
  752. wsa883x = snd_soc_component_get_drvdata(component);
  753. if (!wsa883x) {
  754. pr_err("%s: wsa883x component is NULL\n", __func__);
  755. return -EINVAL;
  756. }
  757. ucontrol->value.integer.value[0] = wsa883x->swr_slave->dev_num;
  758. return 0;
  759. }
  760. static int wsa883x_get_compander(struct snd_kcontrol *kcontrol,
  761. struct snd_ctl_elem_value *ucontrol)
  762. {
  763. struct snd_soc_component *component =
  764. snd_soc_kcontrol_component(kcontrol);
  765. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  766. ucontrol->value.integer.value[0] = wsa883x->comp_enable;
  767. return 0;
  768. }
  769. static int wsa883x_set_compander(struct snd_kcontrol *kcontrol,
  770. struct snd_ctl_elem_value *ucontrol)
  771. {
  772. struct snd_soc_component *component =
  773. snd_soc_kcontrol_component(kcontrol);
  774. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  775. int value = ucontrol->value.integer.value[0];
  776. dev_dbg(component->dev, "%s: Compander enable current %d, new %d\n",
  777. __func__, wsa883x->comp_enable, value);
  778. wsa883x->comp_enable = value;
  779. return 0;
  780. }
  781. static int wsa883x_get_comp_offset(struct snd_kcontrol *kcontrol,
  782. struct snd_ctl_elem_value *ucontrol)
  783. {
  784. struct snd_soc_component *component =
  785. snd_soc_kcontrol_component(kcontrol);
  786. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  787. ucontrol->value.integer.value[0] = wsa883x->comp_offset;
  788. return 0;
  789. }
  790. static int wsa883x_set_comp_offset(struct snd_kcontrol *kcontrol,
  791. struct snd_ctl_elem_value *ucontrol)
  792. {
  793. struct snd_soc_component *component =
  794. snd_soc_kcontrol_component(kcontrol);
  795. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  796. int value = ucontrol->value.integer.value[0];
  797. dev_dbg(component->dev, "%s: comp_offset %d\n",
  798. __func__, wsa883x->comp_offset);
  799. wsa883x->comp_offset = value;
  800. return 0;
  801. }
  802. static int wsa883x_get_visense(struct snd_kcontrol *kcontrol,
  803. struct snd_ctl_elem_value *ucontrol)
  804. {
  805. struct snd_soc_component *component =
  806. snd_soc_kcontrol_component(kcontrol);
  807. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  808. ucontrol->value.integer.value[0] = wsa883x->visense_enable;
  809. return 0;
  810. }
  811. static int wsa883x_set_visense(struct snd_kcontrol *kcontrol,
  812. struct snd_ctl_elem_value *ucontrol)
  813. {
  814. struct snd_soc_component *component =
  815. snd_soc_kcontrol_component(kcontrol);
  816. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  817. int value = ucontrol->value.integer.value[0];
  818. dev_dbg(component->dev, "%s: VIsense enable current %d, new %d\n",
  819. __func__, wsa883x->visense_enable, value);
  820. wsa883x->visense_enable = value;
  821. return 0;
  822. }
  823. static int wsa883x_get_ext_vdd_spk(struct snd_kcontrol *kcontrol,
  824. struct snd_ctl_elem_value *ucontrol)
  825. {
  826. struct snd_soc_component *component =
  827. snd_soc_kcontrol_component(kcontrol);
  828. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  829. ucontrol->value.integer.value[0] = wsa883x->ext_vdd_spk;
  830. return 0;
  831. }
  832. static int wsa883x_put_ext_vdd_spk(struct snd_kcontrol *kcontrol,
  833. struct snd_ctl_elem_value *ucontrol)
  834. {
  835. struct snd_soc_component *component =
  836. snd_soc_kcontrol_component(kcontrol);
  837. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  838. int value = ucontrol->value.integer.value[0];
  839. dev_dbg(component->dev, "%s: Ext VDD SPK enable current %d, new %d\n",
  840. __func__, wsa883x->ext_vdd_spk, value);
  841. wsa883x->ext_vdd_spk = value;
  842. return 0;
  843. }
  844. static const struct snd_kcontrol_new wsa883x_snd_controls[] = {
  845. SOC_ENUM_EXT("WSA PA Gain", wsa_pa_gain_enum,
  846. wsa_pa_gain_get, wsa_pa_gain_put),
  847. SOC_SINGLE_EXT("WSA PA Mute", SND_SOC_NOPM, 0, 1, 0,
  848. wsa883x_get_mute, wsa883x_set_mute),
  849. SOC_SINGLE_EXT("WSA Temp", SND_SOC_NOPM, 0, UINT_MAX, 0,
  850. wsa_get_temp, NULL),
  851. SOC_SINGLE_EXT("WSA Get DevNum", SND_SOC_NOPM, 0, UINT_MAX, 0,
  852. wsa883x_get_dev_num, NULL),
  853. SOC_ENUM_EXT("WSA MODE", wsa_dev_mode_enum,
  854. wsa_dev_mode_get, wsa_dev_mode_put),
  855. SOC_SINGLE_EXT("COMP Offset", SND_SOC_NOPM, 0, 4, 0,
  856. wsa883x_get_comp_offset, wsa883x_set_comp_offset),
  857. SOC_SINGLE_EXT("COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  858. wsa883x_get_compander, wsa883x_set_compander),
  859. SOC_SINGLE_EXT("VISENSE Switch", SND_SOC_NOPM, 0, 1, 0,
  860. wsa883x_get_visense, wsa883x_set_visense),
  861. SOC_SINGLE_EXT("External VDD_SPK", SND_SOC_NOPM, 0, 1, 0,
  862. wsa883x_get_ext_vdd_spk, wsa883x_put_ext_vdd_spk),
  863. };
  864. static const struct snd_kcontrol_new swr_dac_port[] = {
  865. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  866. };
  867. static int wsa883x_set_port(struct snd_soc_component *component, int port_idx,
  868. u8 *port_id, u8 *num_ch, u8 *ch_mask, u32 *ch_rate,
  869. u8 *port_type)
  870. {
  871. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  872. *port_id = wsa883x->port[port_idx].port_id;
  873. *num_ch = wsa883x->port[port_idx].num_ch;
  874. *ch_mask = wsa883x->port[port_idx].ch_mask;
  875. *ch_rate = wsa883x->port[port_idx].ch_rate;
  876. *port_type = wsa883x->port[port_idx].port_type;
  877. return 0;
  878. }
  879. static int wsa883x_enable_swr_dac_port(struct snd_soc_dapm_widget *w,
  880. struct snd_kcontrol *kcontrol, int event)
  881. {
  882. struct snd_soc_component *component =
  883. snd_soc_dapm_to_component(w->dapm);
  884. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  885. u8 port_id[WSA883X_MAX_SWR_PORTS];
  886. u8 num_ch[WSA883X_MAX_SWR_PORTS];
  887. u8 ch_mask[WSA883X_MAX_SWR_PORTS];
  888. u32 ch_rate[WSA883X_MAX_SWR_PORTS];
  889. u8 port_type[WSA883X_MAX_SWR_PORTS];
  890. u8 num_port = 0;
  891. dev_dbg(component->dev, "%s: event %d name %s\n", __func__,
  892. event, w->name);
  893. if (wsa883x == NULL)
  894. return -EINVAL;
  895. switch (event) {
  896. case SND_SOC_DAPM_PRE_PMU:
  897. wsa883x_set_port(component, SWR_DAC_PORT,
  898. &port_id[num_port], &num_ch[num_port],
  899. &ch_mask[num_port], &ch_rate[num_port],
  900. &port_type[num_port]);
  901. if (wsa883x->dev_mode == RECEIVER)
  902. ch_rate[num_port] = SWR_CLK_RATE_4P8MHZ;
  903. ++num_port;
  904. if (wsa883x->comp_enable) {
  905. wsa883x_set_port(component, SWR_COMP_PORT,
  906. &port_id[num_port], &num_ch[num_port],
  907. &ch_mask[num_port], &ch_rate[num_port],
  908. &port_type[num_port]);
  909. ++num_port;
  910. }
  911. if (wsa883x->visense_enable) {
  912. wsa883x_set_port(component, SWR_VISENSE_PORT,
  913. &port_id[num_port], &num_ch[num_port],
  914. &ch_mask[num_port], &ch_rate[num_port],
  915. &port_type[num_port]);
  916. ++num_port;
  917. }
  918. swr_connect_port(wsa883x->swr_slave, &port_id[0], num_port,
  919. &ch_mask[0], &ch_rate[0], &num_ch[0],
  920. &port_type[0]);
  921. break;
  922. case SND_SOC_DAPM_POST_PMU:
  923. set_bit(SPKR_STATUS, &wsa883x->status_mask);
  924. break;
  925. case SND_SOC_DAPM_PRE_PMD:
  926. wsa883x_set_port(component, SWR_DAC_PORT,
  927. &port_id[num_port], &num_ch[num_port],
  928. &ch_mask[num_port], &ch_rate[num_port],
  929. &port_type[num_port]);
  930. ++num_port;
  931. if (wsa883x->comp_enable) {
  932. wsa883x_set_port(component, SWR_COMP_PORT,
  933. &port_id[num_port], &num_ch[num_port],
  934. &ch_mask[num_port], &ch_rate[num_port],
  935. &port_type[num_port]);
  936. ++num_port;
  937. }
  938. if (wsa883x->visense_enable) {
  939. wsa883x_set_port(component, SWR_VISENSE_PORT,
  940. &port_id[num_port], &num_ch[num_port],
  941. &ch_mask[num_port], &ch_rate[num_port],
  942. &port_type[num_port]);
  943. ++num_port;
  944. }
  945. swr_disconnect_port(wsa883x->swr_slave, &port_id[0], num_port,
  946. &ch_mask[0], &port_type[0]);
  947. break;
  948. case SND_SOC_DAPM_POST_PMD:
  949. if (swr_set_device_group(wsa883x->swr_slave, SWR_GROUP_NONE))
  950. dev_err(component->dev,
  951. "%s: set num ch failed\n", __func__);
  952. swr_slvdev_datapath_control(wsa883x->swr_slave,
  953. wsa883x->swr_slave->dev_num,
  954. false);
  955. break;
  956. default:
  957. break;
  958. }
  959. return 0;
  960. }
  961. static int wsa883x_spkr_event(struct snd_soc_dapm_widget *w,
  962. struct snd_kcontrol *kcontrol, int event)
  963. {
  964. struct snd_soc_component *component =
  965. snd_soc_dapm_to_component(w->dapm);
  966. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  967. dev_dbg(component->dev, "%s: %s %d\n", __func__, w->name, event);
  968. switch (event) {
  969. case SND_SOC_DAPM_POST_PMU:
  970. if (wsa883x->dev_mode == RECEIVER) {
  971. snd_soc_component_update_bits(component,
  972. WSA883X_CDC_PATH_MODE,
  973. 0x02, 0x02);
  974. snd_soc_component_update_bits(component,
  975. WSA883X_SPKR_PWM_CLK_CTL,
  976. 0x08, 0x08);
  977. snd_soc_component_update_bits(component,
  978. WSA883X_DRE_CTL_0,
  979. 0xF0, 0x00);
  980. } else if (wsa883x->dev_mode == SPEAKER) {
  981. snd_soc_component_update_bits(component,
  982. WSA883X_CDC_PATH_MODE,
  983. 0x02, 0x00);
  984. snd_soc_component_update_bits(component,
  985. WSA883X_SPKR_PWM_CLK_CTL,
  986. 0x08, 0x00);
  987. snd_soc_component_update_bits(component,
  988. WSA883X_DRE_CTL_0,
  989. 0xF0, 0x90);
  990. }
  991. swr_slvdev_datapath_control(wsa883x->swr_slave,
  992. wsa883x->swr_slave->dev_num,
  993. true);
  994. /* Added delay as per HW sequence */
  995. usleep_range(250, 300);
  996. snd_soc_component_update_bits(component,
  997. WSA883X_DRE_CTL_1,
  998. 0x01, 0x01);
  999. /* Added delay as per HW sequence */
  1000. usleep_range(250, 300);
  1001. /* Force remove group */
  1002. swr_remove_from_group(wsa883x->swr_slave,
  1003. wsa883x->swr_slave->dev_num);
  1004. if (wsa883x->comp_enable)
  1005. snd_soc_component_update_bits(component,
  1006. WSA883X_DRE_CTL_0,
  1007. 0x07,
  1008. wsa883x->comp_offset);
  1009. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PA_ON_ERR);
  1010. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_UVLO);
  1011. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_SAF2WAR);
  1012. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_WAR2SAF);
  1013. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_DISABLE);
  1014. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_OCP);
  1015. wcd_enable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLK_WD);
  1016. snd_soc_component_update_bits(component,
  1017. WSA883X_VBAT_ADC_FLT_CTL,
  1018. 0x0E, 0x06);
  1019. snd_soc_component_update_bits(component,
  1020. WSA883X_VBAT_ADC_FLT_CTL,
  1021. 0x01, 0x01);
  1022. if (test_bit(SPKR_ADIE_LB, &wsa883x->status_mask))
  1023. snd_soc_component_update_bits(component,
  1024. WSA883X_PA_FSM_CTL, 0x01, 0x01);
  1025. break;
  1026. case SND_SOC_DAPM_PRE_PMD:
  1027. if (!test_bit(SPKR_ADIE_LB, &wsa883x->status_mask))
  1028. wcd_disable_irq(&wsa883x->irq_info,
  1029. WSA883X_IRQ_INT_PDM_WD);
  1030. snd_soc_component_update_bits(component,
  1031. WSA883X_VBAT_ADC_FLT_CTL,
  1032. 0x01, 0x00);
  1033. snd_soc_component_update_bits(component,
  1034. WSA883X_VBAT_ADC_FLT_CTL,
  1035. 0x0E, 0x00);
  1036. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  1037. 0x01, 0x00);
  1038. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  1039. 0x10, 0x00);
  1040. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  1041. 0x10, 0x10);
  1042. snd_soc_component_update_bits(component, WSA883X_PA_FSM_CTL,
  1043. 0x10, 0x00);
  1044. snd_soc_component_update_bits(component, WSA883X_PDM_WD_CTL,
  1045. 0x01, 0x00);
  1046. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLK_WD);
  1047. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_OCP);
  1048. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_DISABLE);
  1049. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_WAR2SAF);
  1050. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_SAF2WAR);
  1051. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_UVLO);
  1052. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PA_ON_ERR);
  1053. clear_bit(SPKR_STATUS, &wsa883x->status_mask);
  1054. clear_bit(SPKR_ADIE_LB, &wsa883x->status_mask);
  1055. break;
  1056. }
  1057. return 0;
  1058. }
  1059. static const struct snd_soc_dapm_widget wsa883x_dapm_widgets[] = {
  1060. SND_SOC_DAPM_INPUT("IN"),
  1061. SND_SOC_DAPM_MIXER_E("SWR DAC_Port", SND_SOC_NOPM, 0, 0, swr_dac_port,
  1062. ARRAY_SIZE(swr_dac_port), wsa883x_enable_swr_dac_port,
  1063. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1064. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1065. SND_SOC_DAPM_SPK("SPKR", wsa883x_spkr_event),
  1066. };
  1067. static const struct snd_soc_dapm_route wsa883x_audio_map[] = {
  1068. {"SWR DAC_Port", "Switch", "IN"},
  1069. {"SPKR", NULL, "SWR DAC_Port"},
  1070. };
  1071. int wsa883x_set_channel_map(struct snd_soc_component *component, u8 *port,
  1072. u8 num_port, unsigned int *ch_mask,
  1073. unsigned int *ch_rate, u8 *port_type)
  1074. {
  1075. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1076. int i;
  1077. if (!port || !ch_mask || !ch_rate ||
  1078. (num_port > WSA883X_MAX_SWR_PORTS)) {
  1079. dev_err(component->dev,
  1080. "%s: Invalid port=%pK, ch_mask=%pK, ch_rate=%pK\n",
  1081. __func__, port, ch_mask, ch_rate);
  1082. return -EINVAL;
  1083. }
  1084. for (i = 0; i < num_port; i++) {
  1085. wsa883x->port[i].port_id = port[i];
  1086. wsa883x->port[i].ch_mask = ch_mask[i];
  1087. wsa883x->port[i].ch_rate = ch_rate[i];
  1088. wsa883x->port[i].num_ch = __sw_hweight8(ch_mask[i]);
  1089. if (port_type)
  1090. wsa883x->port[i].port_type = port_type[i];
  1091. }
  1092. return 0;
  1093. }
  1094. EXPORT_SYMBOL(wsa883x_set_channel_map);
  1095. static void wsa883x_codec_init(struct snd_soc_component *component)
  1096. {
  1097. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1098. int i;
  1099. if (!wsa883x)
  1100. return;
  1101. for (i = 0; i < ARRAY_SIZE(reg_init); i++)
  1102. snd_soc_component_update_bits(component, reg_init[i].reg,
  1103. reg_init[i].mask, reg_init[i].val);
  1104. if (wsa883x->variant == WSA8830 || wsa883x->variant == WSA8832) {
  1105. snd_soc_component_update_bits(component, WSA883X_DRE_CTL_0,
  1106. 0x07, 0x03);
  1107. wsa883x->comp_offset = COMP_OFFSET3;
  1108. }
  1109. }
  1110. static int32_t wsa883x_temp_reg_read(struct snd_soc_component *component,
  1111. struct wsa_temp_register *wsa_temp_reg)
  1112. {
  1113. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1114. if (!wsa883x) {
  1115. dev_err(component->dev, "%s: wsa883x is NULL\n", __func__);
  1116. return -EINVAL;
  1117. }
  1118. mutex_lock(&wsa883x->res_lock);
  1119. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1120. 0x01, 0x01);
  1121. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1122. 0x04, 0x04);
  1123. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1124. 0x02, 0x02);
  1125. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1126. 0x80, 0x80);
  1127. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1128. 0x20, 0x20);
  1129. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1130. 0x40, 0x40);
  1131. snd_soc_component_update_bits(component, WSA883X_TADC_VALUE_CTL,
  1132. 0x01, 0x00);
  1133. wsa_temp_reg->dmeas_msb = snd_soc_component_read(
  1134. component, WSA883X_TEMP_MSB);
  1135. wsa_temp_reg->dmeas_lsb = snd_soc_component_read(
  1136. component, WSA883X_TEMP_LSB);
  1137. snd_soc_component_update_bits(component, WSA883X_TADC_VALUE_CTL,
  1138. 0x01, 0x01);
  1139. wsa_temp_reg->d1_msb = snd_soc_component_read(
  1140. component, WSA883X_OTP_REG_1);
  1141. wsa_temp_reg->d1_lsb = snd_soc_component_read(
  1142. component, WSA883X_OTP_REG_2);
  1143. wsa_temp_reg->d2_msb = snd_soc_component_read(
  1144. component, WSA883X_OTP_REG_3);
  1145. wsa_temp_reg->d2_lsb = snd_soc_component_read(
  1146. component, WSA883X_OTP_REG_4);
  1147. snd_soc_component_update_bits(component, WSA883X_PA_FSM_BYP,
  1148. 0xE7, 0x00);
  1149. mutex_unlock(&wsa883x->res_lock);
  1150. return 0;
  1151. }
  1152. static int wsa883x_get_temperature(struct snd_soc_component *component,
  1153. int *temp)
  1154. {
  1155. struct wsa_temp_register reg;
  1156. int dmeas, d1, d2;
  1157. int ret = 0;
  1158. int temp_val = 0;
  1159. int t1 = T1_TEMP;
  1160. int t2 = T2_TEMP;
  1161. u8 retry = WSA883X_TEMP_RETRY;
  1162. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1163. if (!wsa883x)
  1164. return -EINVAL;
  1165. do {
  1166. ret = wsa883x_temp_reg_read(component, &reg);
  1167. if (ret) {
  1168. pr_err("%s: temp read failed: %d, current temp: %d\n",
  1169. __func__, ret, wsa883x->curr_temp);
  1170. if (temp)
  1171. *temp = wsa883x->curr_temp;
  1172. return 0;
  1173. }
  1174. /*
  1175. * Temperature register values are expected to be in the
  1176. * following range.
  1177. * d1_msb = 68 - 92 and d1_lsb = 0, 64, 128, 192
  1178. * d2_msb = 185 -218 and d2_lsb = 0, 64, 128, 192
  1179. */
  1180. if ((reg.d1_msb < 68 || reg.d1_msb > 92) ||
  1181. (!(reg.d1_lsb == 0 || reg.d1_lsb == 64 || reg.d1_lsb == 128 ||
  1182. reg.d1_lsb == 192)) ||
  1183. (reg.d2_msb < 185 || reg.d2_msb > 218) ||
  1184. (!(reg.d2_lsb == 0 || reg.d2_lsb == 64 || reg.d2_lsb == 128 ||
  1185. reg.d2_lsb == 192))) {
  1186. printk_ratelimited("%s: Temperature registers[%d %d %d %d] are out of range\n",
  1187. __func__, reg.d1_msb, reg.d1_lsb, reg.d2_msb,
  1188. reg.d2_lsb);
  1189. }
  1190. dmeas = ((reg.dmeas_msb << 0x8) | reg.dmeas_lsb) >> 0x6;
  1191. d1 = ((reg.d1_msb << 0x8) | reg.d1_lsb) >> 0x6;
  1192. d2 = ((reg.d2_msb << 0x8) | reg.d2_lsb) >> 0x6;
  1193. if (d1 == d2)
  1194. temp_val = TEMP_INVALID;
  1195. else
  1196. temp_val = t1 + (((dmeas - d1) * (t2 - t1))/(d2 - d1));
  1197. if (temp_val <= LOW_TEMP_THRESHOLD ||
  1198. temp_val >= HIGH_TEMP_THRESHOLD) {
  1199. pr_debug("%s: T0: %d is out of range[%d, %d]\n", __func__,
  1200. temp_val, LOW_TEMP_THRESHOLD, HIGH_TEMP_THRESHOLD);
  1201. if (retry--)
  1202. msleep(10);
  1203. } else {
  1204. break;
  1205. }
  1206. } while (retry);
  1207. wsa883x->curr_temp = temp_val;
  1208. if (temp)
  1209. *temp = temp_val;
  1210. pr_debug("%s: t0 measured: %d dmeas = %d, d1 = %d, d2 = %d\n",
  1211. __func__, temp_val, dmeas, d1, d2);
  1212. return ret;
  1213. }
  1214. static int wsa883x_codec_probe(struct snd_soc_component *component)
  1215. {
  1216. char w_name[MAX_NAME_LEN];
  1217. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1218. struct swr_device *dev;
  1219. int variant = 0, version = 0;
  1220. struct snd_soc_dapm_context *dapm =
  1221. snd_soc_component_get_dapm(component);
  1222. if (!wsa883x)
  1223. return -EINVAL;
  1224. if (!component->name_prefix)
  1225. return -EINVAL;
  1226. snd_soc_component_init_regmap(component, wsa883x->regmap);
  1227. dev = wsa883x->swr_slave;
  1228. wsa883x->component = component;
  1229. variant = (snd_soc_component_read(component, WSA883X_OTP_REG_0)
  1230. & 0x0F);
  1231. wsa883x->variant = variant;
  1232. version = (snd_soc_component_read(component, WSA883X_CHIP_ID0)
  1233. & 0xFF);
  1234. wsa883x->version = version;
  1235. wsa883x->comp_offset = COMP_OFFSET2;
  1236. wsa883x_codec_init(component);
  1237. wsa883x->global_pa_cnt = 0;
  1238. memset(w_name, 0, sizeof(w_name));
  1239. strlcpy(w_name, wsa883x->dai_driver->playback.stream_name,
  1240. sizeof(w_name));
  1241. snd_soc_dapm_ignore_suspend(dapm, w_name);
  1242. memset(w_name, 0, sizeof(w_name));
  1243. strlcpy(w_name, "IN", sizeof(w_name));
  1244. snd_soc_dapm_ignore_suspend(dapm, w_name);
  1245. memset(w_name, 0, sizeof(w_name));
  1246. strlcpy(w_name, "SWR DAC_Port", sizeof(w_name));
  1247. snd_soc_dapm_ignore_suspend(dapm, w_name);
  1248. memset(w_name, 0, sizeof(w_name));
  1249. strlcpy(w_name, "SPKR", sizeof(w_name));
  1250. snd_soc_dapm_ignore_suspend(dapm, w_name);
  1251. snd_soc_dapm_sync(dapm);
  1252. return 0;
  1253. }
  1254. static void wsa883x_codec_remove(struct snd_soc_component *component)
  1255. {
  1256. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1257. if (!wsa883x)
  1258. return;
  1259. snd_soc_component_exit_regmap(component);
  1260. return;
  1261. }
  1262. static int wsa883x_soc_codec_suspend(struct snd_soc_component *component)
  1263. {
  1264. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1265. if (!wsa883x)
  1266. return 0;
  1267. wsa883x->dapm_bias_off = true;
  1268. return 0;
  1269. }
  1270. static int wsa883x_soc_codec_resume(struct snd_soc_component *component)
  1271. {
  1272. struct wsa883x_priv *wsa883x = snd_soc_component_get_drvdata(component);
  1273. if (!wsa883x)
  1274. return 0;
  1275. wsa883x->dapm_bias_off = false;
  1276. return 0;
  1277. }
  1278. static const struct snd_soc_component_driver soc_codec_dev_wsa883x_wsa = {
  1279. .name = "",
  1280. .probe = wsa883x_codec_probe,
  1281. .remove = wsa883x_codec_remove,
  1282. .controls = wsa883x_snd_controls,
  1283. .num_controls = ARRAY_SIZE(wsa883x_snd_controls),
  1284. .dapm_widgets = wsa883x_dapm_widgets,
  1285. .num_dapm_widgets = ARRAY_SIZE(wsa883x_dapm_widgets),
  1286. .dapm_routes = wsa883x_audio_map,
  1287. .num_dapm_routes = ARRAY_SIZE(wsa883x_audio_map),
  1288. .suspend = wsa883x_soc_codec_suspend,
  1289. .resume = wsa883x_soc_codec_resume,
  1290. };
  1291. static int wsa883x_gpio_ctrl(struct wsa883x_priv *wsa883x, bool enable)
  1292. {
  1293. int ret = 0;
  1294. if (enable)
  1295. ret = msm_cdc_pinctrl_select_active_state(
  1296. wsa883x->wsa_rst_np);
  1297. else
  1298. ret = msm_cdc_pinctrl_select_sleep_state(
  1299. wsa883x->wsa_rst_np);
  1300. if (ret != 0)
  1301. dev_err(wsa883x->dev,
  1302. "%s: Failed to turn state %d; ret=%d\n",
  1303. __func__, enable, ret);
  1304. return ret;
  1305. }
  1306. static int wsa883x_swr_up(struct wsa883x_priv *wsa883x)
  1307. {
  1308. int ret;
  1309. ret = wsa883x_gpio_ctrl(wsa883x, true);
  1310. if (ret)
  1311. dev_err(wsa883x->dev, "%s: Failed to enable gpio\n", __func__);
  1312. return ret;
  1313. }
  1314. static int wsa883x_swr_down(struct wsa883x_priv *wsa883x)
  1315. {
  1316. int ret;
  1317. ret = wsa883x_gpio_ctrl(wsa883x, false);
  1318. if (ret)
  1319. dev_err(wsa883x->dev, "%s: Failed to disable gpio\n", __func__);
  1320. return ret;
  1321. }
  1322. static int wsa883x_swr_reset(struct wsa883x_priv *wsa883x)
  1323. {
  1324. u8 retry = WSA883X_NUM_RETRY;
  1325. u8 devnum = 0;
  1326. struct swr_device *pdev;
  1327. pdev = wsa883x->swr_slave;
  1328. while (swr_get_logical_dev_num(pdev, pdev->addr, &devnum) && retry--) {
  1329. /* Retry after 1 msec delay */
  1330. usleep_range(1000, 1100);
  1331. }
  1332. pdev->dev_num = devnum;
  1333. wsa883x_regcache_sync(wsa883x);
  1334. return 0;
  1335. }
  1336. static int wsa883x_event_notify(struct notifier_block *nb,
  1337. unsigned long val, void *ptr)
  1338. {
  1339. u16 event = (val & 0xffff);
  1340. struct wsa883x_priv *wsa883x = container_of(nb, struct wsa883x_priv,
  1341. parent_nblock);
  1342. if (!wsa883x)
  1343. return -EINVAL;
  1344. switch (event) {
  1345. case BOLERO_SLV_EVT_PA_OFF_PRE_SSR:
  1346. if (test_bit(SPKR_STATUS, &wsa883x->status_mask))
  1347. snd_soc_component_update_bits(wsa883x->component,
  1348. WSA883X_PA_FSM_CTL,
  1349. 0x01, 0x00);
  1350. wsa883x_swr_down(wsa883x);
  1351. break;
  1352. case BOLERO_SLV_EVT_SSR_UP:
  1353. wsa883x_swr_up(wsa883x);
  1354. /* Add delay to allow enumerate */
  1355. usleep_range(20000, 20010);
  1356. wsa883x_swr_reset(wsa883x);
  1357. break;
  1358. case BOLERO_SLV_EVT_PA_ON_POST_FSCLK:
  1359. if (test_bit(SPKR_STATUS, &wsa883x->status_mask)) {
  1360. snd_soc_component_update_bits(wsa883x->component,
  1361. WSA883X_PDM_WD_CTL,
  1362. 0x01, 0x01);
  1363. snd_soc_component_update_bits(wsa883x->component,
  1364. WSA883X_PA_FSM_CTL,
  1365. 0x01, 0x01);
  1366. wcd_enable_irq(&wsa883x->irq_info,
  1367. WSA883X_IRQ_INT_PDM_WD);
  1368. /* Added delay as per HW sequence */
  1369. usleep_range(3000, 3100);
  1370. if (wsa883x->comp_enable) {
  1371. snd_soc_component_update_bits(wsa883x->component,
  1372. WSA883X_DRE_CTL_1,
  1373. 0x01, 0x00);
  1374. /* Added delay as per HW sequence */
  1375. usleep_range(5000, 5050);
  1376. }
  1377. }
  1378. break;
  1379. case BOLERO_SLV_EVT_PA_ON_POST_FSCLK_ADIE_LB:
  1380. if (test_bit(SPKR_STATUS, &wsa883x->status_mask))
  1381. set_bit(SPKR_ADIE_LB, &wsa883x->status_mask);
  1382. break;
  1383. default:
  1384. dev_dbg(wsa883x->dev, "%s: unknown event %d\n",
  1385. __func__, event);
  1386. break;
  1387. }
  1388. return 0;
  1389. }
  1390. static int wsa883x_enable_supplies(struct device * dev,
  1391. struct wsa883x_priv *priv)
  1392. {
  1393. int ret = 0;
  1394. /* Parse power supplies */
  1395. msm_cdc_get_power_supplies(dev, &priv->regulator,
  1396. &priv->num_supplies);
  1397. if (!priv->regulator || (priv->num_supplies <= 0)) {
  1398. dev_err(dev, "%s: no power supplies defined\n", __func__);
  1399. return -EINVAL;
  1400. }
  1401. ret = msm_cdc_init_supplies(dev, &priv->supplies,
  1402. priv->regulator, priv->num_supplies);
  1403. if (!priv->supplies) {
  1404. dev_err(dev, "%s: Cannot init wsa supplies\n",
  1405. __func__);
  1406. return ret;
  1407. }
  1408. ret = msm_cdc_enable_static_supplies(dev, priv->supplies,
  1409. priv->regulator,
  1410. priv->num_supplies);
  1411. if (ret)
  1412. dev_err(dev, "%s: wsa static supply enable failed!\n",
  1413. __func__);
  1414. return ret;
  1415. }
  1416. static struct snd_soc_dai_driver wsa_dai[] = {
  1417. {
  1418. .name = "",
  1419. .playback = {
  1420. .stream_name = "",
  1421. .rates = WSA883X_RATES | WSA883X_FRAC_RATES,
  1422. .formats = WSA883X_FORMATS,
  1423. .rate_max = 192000,
  1424. .rate_min = 8000,
  1425. .channels_min = 1,
  1426. .channels_max = 2,
  1427. },
  1428. },
  1429. };
  1430. static int wsa883x_swr_probe(struct swr_device *pdev)
  1431. {
  1432. int ret = 0, i = 0;
  1433. struct wsa883x_priv *wsa883x;
  1434. u8 devnum = 0;
  1435. bool pin_state_current = false;
  1436. struct wsa_ctrl_platform_data *plat_data = NULL;
  1437. struct snd_soc_component *component;
  1438. char buffer[MAX_NAME_LEN];
  1439. int dev_index = 0;
  1440. struct regmap_irq_chip *wsa883x_sub_regmap_irq_chip = NULL;
  1441. wsa883x = devm_kzalloc(&pdev->dev, sizeof(struct wsa883x_priv),
  1442. GFP_KERNEL);
  1443. if (!wsa883x)
  1444. return -ENOMEM;
  1445. wsa883x_sub_regmap_irq_chip = devm_kzalloc(&pdev->dev, sizeof(struct regmap_irq_chip),
  1446. GFP_KERNEL);
  1447. if (!wsa883x_sub_regmap_irq_chip)
  1448. return -ENOMEM;
  1449. memcpy(wsa883x_sub_regmap_irq_chip, &wsa883x_regmap_irq_chip,
  1450. sizeof(struct regmap_irq_chip));
  1451. ret = wsa883x_enable_supplies(&pdev->dev, wsa883x);
  1452. if (ret) {
  1453. ret = -EPROBE_DEFER;
  1454. goto err;
  1455. }
  1456. wsa883x->wsa_rst_np = of_parse_phandle(pdev->dev.of_node,
  1457. "qcom,spkr-sd-n-node", 0);
  1458. if (!wsa883x->wsa_rst_np) {
  1459. dev_dbg(&pdev->dev, "%s: pinctrl not defined\n", __func__);
  1460. goto err_supply;
  1461. }
  1462. swr_set_dev_data(pdev, wsa883x);
  1463. wsa883x->swr_slave = pdev;
  1464. wsa883x->dev = &pdev->dev;
  1465. pin_state_current = msm_cdc_pinctrl_get_state(wsa883x->wsa_rst_np);
  1466. wsa883x_gpio_ctrl(wsa883x, true);
  1467. /*
  1468. * Add 5msec delay to provide sufficient time for
  1469. * soundwire auto enumeration of slave devices as
  1470. * as per HW requirement.
  1471. */
  1472. usleep_range(5000, 5010);
  1473. ret = swr_get_logical_dev_num(pdev, pdev->addr, &devnum);
  1474. if (ret) {
  1475. dev_dbg(&pdev->dev,
  1476. "%s get devnum %d for dev addr %lx failed\n",
  1477. __func__, devnum, pdev->addr);
  1478. ret = -EPROBE_DEFER;
  1479. goto err_supply;
  1480. }
  1481. pdev->dev_num = devnum;
  1482. wsa883x->regmap = devm_regmap_init_swr(pdev,
  1483. &wsa883x_regmap_config);
  1484. if (IS_ERR(wsa883x->regmap)) {
  1485. ret = PTR_ERR(wsa883x->regmap);
  1486. dev_err(&pdev->dev, "%s: regmap_init failed %d\n",
  1487. __func__, ret);
  1488. goto dev_err;
  1489. }
  1490. devm_regmap_qti_debugfs_register(&pdev->dev, wsa883x->regmap);
  1491. /* Set all interrupts as edge triggered */
  1492. for (i = 0; i < wsa883x_sub_regmap_irq_chip->num_regs; i++)
  1493. regmap_write(wsa883x->regmap, (WSA883X_INTR_LEVEL0 + i), 0);
  1494. wsa883x_sub_regmap_irq_chip->irq_drv_data = wsa883x;
  1495. wsa883x->irq_info.wcd_regmap_irq_chip = wsa883x_sub_regmap_irq_chip;
  1496. wsa883x->irq_info.codec_name = "WSA883X";
  1497. wsa883x->irq_info.regmap = wsa883x->regmap;
  1498. wsa883x->irq_info.dev = &pdev->dev;
  1499. ret = wcd_irq_init(&wsa883x->irq_info, &wsa883x->virq);
  1500. if (ret) {
  1501. dev_err(wsa883x->dev, "%s: IRQ init failed: %d\n",
  1502. __func__, ret);
  1503. goto dev_err;
  1504. }
  1505. wsa883x->swr_slave->slave_irq = wsa883x->virq;
  1506. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_SAF2WAR,
  1507. "WSA SAF2WAR", wsa883x_saf2war_handle_irq, wsa883x);
  1508. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_SAF2WAR);
  1509. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_WAR2SAF,
  1510. "WSA WAR2SAF", wsa883x_war2saf_handle_irq, wsa883x);
  1511. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_WAR2SAF);
  1512. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_DISABLE,
  1513. "WSA OTP", wsa883x_otp_handle_irq, wsa883x);
  1514. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_DISABLE);
  1515. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_OCP,
  1516. "WSA OCP", wsa883x_ocp_handle_irq, wsa883x);
  1517. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_OCP);
  1518. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLIP,
  1519. "WSA CLIP", wsa883x_clip_handle_irq, wsa883x);
  1520. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLIP);
  1521. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PDM_WD,
  1522. "WSA PDM WD", wsa883x_pdm_wd_handle_irq, wsa883x);
  1523. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PDM_WD);
  1524. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLK_WD,
  1525. "WSA CLK WD", wsa883x_clk_wd_handle_irq, wsa883x);
  1526. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLK_WD);
  1527. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_INTR_PIN,
  1528. "WSA EXT INT", wsa883x_ext_int_handle_irq, wsa883x);
  1529. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_INTR_PIN);
  1530. /* Under Voltage Lock out (UVLO) interrupt handle */
  1531. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_UVLO,
  1532. "WSA UVLO", wsa883x_uvlo_handle_irq, wsa883x);
  1533. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_UVLO);
  1534. wcd_request_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PA_ON_ERR,
  1535. "WSA PA ERR", wsa883x_pa_on_err_handle_irq, wsa883x);
  1536. wcd_disable_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PA_ON_ERR);
  1537. wsa883x->driver = devm_kzalloc(&pdev->dev,
  1538. sizeof(struct snd_soc_component_driver), GFP_KERNEL);
  1539. if (!wsa883x->driver) {
  1540. ret = -ENOMEM;
  1541. goto err_irq;
  1542. }
  1543. memcpy(wsa883x->driver, &soc_codec_dev_wsa883x_wsa,
  1544. sizeof(struct snd_soc_component_driver));
  1545. wsa883x->dai_driver = devm_kzalloc(&pdev->dev,
  1546. sizeof(struct snd_soc_dai_driver), GFP_KERNEL);
  1547. if (!wsa883x->dai_driver) {
  1548. ret = -ENOMEM;
  1549. goto err_mem;
  1550. }
  1551. memcpy(wsa883x->dai_driver, wsa_dai, sizeof(struct snd_soc_dai_driver));
  1552. /* Get last digit from HEX format */
  1553. dev_index = (int)((char)(pdev->addr & 0xF));
  1554. if (of_device_is_compatible(pdev->dev.of_node, "qcom,wsa883x_2"))
  1555. dev_index += 2;
  1556. snprintf(buffer, sizeof(buffer), "wsa-codec.%d", dev_index);
  1557. wsa883x->driver->name = kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1558. snprintf(buffer, sizeof(buffer), "wsa_rx%d", dev_index);
  1559. wsa883x->dai_driver->name =
  1560. kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1561. snprintf(buffer, sizeof(buffer), "WSA883X_AIF%d Playback", dev_index);
  1562. wsa883x->dai_driver->playback.stream_name =
  1563. kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1564. /* Number of DAI's used is 1 */
  1565. ret = snd_soc_register_component(&pdev->dev,
  1566. wsa883x->driver, wsa883x->dai_driver, 1);
  1567. component = snd_soc_lookup_component(&pdev->dev, wsa883x->driver->name);
  1568. if (!component) {
  1569. dev_err(&pdev->dev, "%s: component is NULL \n", __func__);
  1570. ret = -EINVAL;
  1571. goto err_mem;
  1572. }
  1573. wsa883x->parent_np = of_parse_phandle(pdev->dev.of_node,
  1574. "qcom,bolero-handle", 0);
  1575. if (!wsa883x->parent_np)
  1576. wsa883x->parent_np = of_parse_phandle(pdev->dev.of_node,
  1577. "qcom,lpass-cdc-handle", 0);
  1578. if (wsa883x->parent_np) {
  1579. wsa883x->parent_dev =
  1580. of_find_device_by_node(wsa883x->parent_np);
  1581. if (wsa883x->parent_dev) {
  1582. plat_data = dev_get_platdata(&wsa883x->parent_dev->dev);
  1583. if (plat_data) {
  1584. wsa883x->parent_nblock.notifier_call =
  1585. wsa883x_event_notify;
  1586. if (plat_data->register_notifier)
  1587. plat_data->register_notifier(
  1588. plat_data->handle,
  1589. &wsa883x->parent_nblock,
  1590. true);
  1591. wsa883x->register_notifier =
  1592. plat_data->register_notifier;
  1593. wsa883x->handle = plat_data->handle;
  1594. } else {
  1595. dev_err(&pdev->dev, "%s: plat data not found\n",
  1596. __func__);
  1597. }
  1598. } else {
  1599. dev_err(&pdev->dev, "%s: parent dev not found\n",
  1600. __func__);
  1601. }
  1602. } else {
  1603. dev_info(&pdev->dev, "%s: parent node not found\n", __func__);
  1604. }
  1605. mutex_init(&wsa883x->res_lock);
  1606. #ifdef CONFIG_DEBUG_FS
  1607. if (!wsa883x->debugfs_dent) {
  1608. wsa883x->debugfs_dent = debugfs_create_dir(
  1609. dev_name(&pdev->dev), 0);
  1610. if (!IS_ERR(wsa883x->debugfs_dent)) {
  1611. wsa883x->debugfs_peek =
  1612. debugfs_create_file("swrslave_peek",
  1613. S_IFREG | 0444,
  1614. wsa883x->debugfs_dent,
  1615. (void *) pdev,
  1616. &codec_debug_read_ops);
  1617. wsa883x->debugfs_poke =
  1618. debugfs_create_file("swrslave_poke",
  1619. S_IFREG | 0444,
  1620. wsa883x->debugfs_dent,
  1621. (void *) pdev,
  1622. &codec_debug_write_ops);
  1623. wsa883x->debugfs_reg_dump =
  1624. debugfs_create_file(
  1625. "swrslave_reg_dump",
  1626. S_IFREG | 0444,
  1627. wsa883x->debugfs_dent,
  1628. (void *) pdev,
  1629. &codec_debug_dump_ops);
  1630. }
  1631. }
  1632. #endif
  1633. return 0;
  1634. err_mem:
  1635. if (wsa883x->dai_driver) {
  1636. kfree(wsa883x->dai_driver->name);
  1637. kfree(wsa883x->dai_driver->playback.stream_name);
  1638. kfree(wsa883x->dai_driver);
  1639. }
  1640. if (wsa883x->driver) {
  1641. kfree(wsa883x->driver->name);
  1642. kfree(wsa883x->driver);
  1643. }
  1644. err_irq:
  1645. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_SAF2WAR, NULL);
  1646. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_WAR2SAF, NULL);
  1647. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_DISABLE, NULL);
  1648. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_OCP, NULL);
  1649. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLIP, NULL);
  1650. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PDM_WD, NULL);
  1651. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLK_WD, NULL);
  1652. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_INTR_PIN, NULL);
  1653. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_UVLO, NULL);
  1654. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PA_ON_ERR, NULL);
  1655. wcd_irq_exit(&wsa883x->irq_info, wsa883x->virq);
  1656. dev_err:
  1657. if (pin_state_current == false)
  1658. wsa883x_gpio_ctrl(wsa883x, false);
  1659. swr_remove_device(pdev);
  1660. err_supply:
  1661. msm_cdc_release_supplies(&pdev->dev, wsa883x->supplies,
  1662. wsa883x->regulator,
  1663. wsa883x->num_supplies);
  1664. err:
  1665. swr_set_dev_data(pdev, NULL);
  1666. return ret;
  1667. }
  1668. static int wsa883x_swr_remove(struct swr_device *pdev)
  1669. {
  1670. struct wsa883x_priv *wsa883x;
  1671. wsa883x = swr_get_dev_data(pdev);
  1672. if (!wsa883x) {
  1673. dev_err(&pdev->dev, "%s: wsa883x is NULL\n", __func__);
  1674. return -EINVAL;
  1675. }
  1676. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_SAF2WAR, NULL);
  1677. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_WAR2SAF, NULL);
  1678. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_DISABLE, NULL);
  1679. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_OCP, NULL);
  1680. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLIP, NULL);
  1681. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PDM_WD, NULL);
  1682. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_CLK_WD, NULL);
  1683. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_INTR_PIN, NULL);
  1684. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_UVLO, NULL);
  1685. wcd_free_irq(&wsa883x->irq_info, WSA883X_IRQ_INT_PA_ON_ERR, NULL);
  1686. if (wsa883x->register_notifier)
  1687. wsa883x->register_notifier(wsa883x->handle,
  1688. &wsa883x->parent_nblock, false);
  1689. #ifdef CONFIG_DEBUG_FS
  1690. debugfs_remove_recursive(wsa883x->debugfs_dent);
  1691. wsa883x->debugfs_dent = NULL;
  1692. #endif
  1693. mutex_destroy(&wsa883x->res_lock);
  1694. snd_soc_unregister_component(&pdev->dev);
  1695. if (wsa883x->dai_driver) {
  1696. kfree(wsa883x->dai_driver->name);
  1697. kfree(wsa883x->dai_driver->playback.stream_name);
  1698. kfree(wsa883x->dai_driver);
  1699. }
  1700. if (wsa883x->driver) {
  1701. kfree(wsa883x->driver->name);
  1702. kfree(wsa883x->driver);
  1703. }
  1704. msm_cdc_release_supplies(&pdev->dev, wsa883x->supplies,
  1705. wsa883x->regulator,
  1706. wsa883x->num_supplies);
  1707. swr_set_dev_data(pdev, NULL);
  1708. return 0;
  1709. }
  1710. #ifdef CONFIG_PM_SLEEP
  1711. static int wsa883x_swr_suspend(struct device *dev)
  1712. {
  1713. struct wsa883x_priv *wsa883x = swr_get_dev_data(to_swr_device(dev));
  1714. if (!wsa883x) {
  1715. dev_err(dev, "%s: wsa883x private data is NULL\n", __func__);
  1716. return -EINVAL;
  1717. }
  1718. dev_dbg(dev, "%s: system suspend\n", __func__);
  1719. if (wsa883x->dapm_bias_off) {
  1720. msm_cdc_set_supplies_lpm_mode(dev, wsa883x->supplies,
  1721. wsa883x->regulator,
  1722. wsa883x->num_supplies,
  1723. true);
  1724. set_bit(WSA_SUPPLIES_LPM_MODE, &wsa883x->status_mask);
  1725. }
  1726. return 0;
  1727. }
  1728. static int wsa883x_swr_resume(struct device *dev)
  1729. {
  1730. struct wsa883x_priv *wsa883x = swr_get_dev_data(to_swr_device(dev));
  1731. if (!wsa883x) {
  1732. dev_err(dev, "%s: wsa883x private data is NULL\n", __func__);
  1733. return -EINVAL;
  1734. }
  1735. if (test_bit(WSA_SUPPLIES_LPM_MODE, &wsa883x->status_mask)) {
  1736. msm_cdc_set_supplies_lpm_mode(dev, wsa883x->supplies,
  1737. wsa883x->regulator,
  1738. wsa883x->num_supplies,
  1739. false);
  1740. clear_bit(WSA_SUPPLIES_LPM_MODE, &wsa883x->status_mask);
  1741. }
  1742. dev_dbg(dev, "%s: system resume\n", __func__);
  1743. return 0;
  1744. }
  1745. #endif /* CONFIG_PM_SLEEP */
  1746. static const struct dev_pm_ops wsa883x_swr_pm_ops = {
  1747. .suspend_late = wsa883x_swr_suspend,
  1748. .resume_early = wsa883x_swr_resume,
  1749. };
  1750. static const struct swr_device_id wsa883x_swr_id[] = {
  1751. {"wsa883x", 0},
  1752. {"wsa883x_2", 0},
  1753. {}
  1754. };
  1755. static const struct of_device_id wsa883x_swr_dt_match[] = {
  1756. {
  1757. .compatible = "qcom,wsa883x",
  1758. },
  1759. {
  1760. .compatible = "qcom,wsa883x_2",
  1761. },
  1762. {}
  1763. };
  1764. static struct swr_driver wsa883x_swr_driver = {
  1765. .driver = {
  1766. .name = "wsa883x",
  1767. .owner = THIS_MODULE,
  1768. .pm = &wsa883x_swr_pm_ops,
  1769. .of_match_table = wsa883x_swr_dt_match,
  1770. },
  1771. .probe = wsa883x_swr_probe,
  1772. .remove = wsa883x_swr_remove,
  1773. .id_table = wsa883x_swr_id,
  1774. };
  1775. static int __init wsa883x_swr_init(void)
  1776. {
  1777. return swr_driver_register(&wsa883x_swr_driver);
  1778. }
  1779. static void __exit wsa883x_swr_exit(void)
  1780. {
  1781. swr_driver_unregister(&wsa883x_swr_driver);
  1782. }
  1783. module_init(wsa883x_swr_init);
  1784. module_exit(wsa883x_swr_exit);
  1785. MODULE_DESCRIPTION("WSA883x codec driver");
  1786. MODULE_LICENSE("GPL v2");