wsa883x.c 47 KB

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