wsa881x.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, 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 "wsa881x.h"
  29. #include "wsa881x-temp-sensor.h"
  30. #define DRV_NAME "wsa-codec"
  31. #define WSA881X_NUM_RETRY 5
  32. enum {
  33. G_18DB = 0,
  34. G_16P5DB,
  35. G_15DB,
  36. G_13P5DB,
  37. G_12DB,
  38. G_10P5DB,
  39. G_9DB,
  40. G_7P5DB,
  41. G_6DB,
  42. G_4P5DB,
  43. G_3DB,
  44. G_1P5DB,
  45. G_0DB,
  46. };
  47. enum {
  48. DISABLE = 0,
  49. ENABLE,
  50. };
  51. enum {
  52. SWR_DAC_PORT,
  53. SWR_COMP_PORT,
  54. SWR_BOOST_PORT,
  55. SWR_VISENSE_PORT,
  56. };
  57. struct swr_port {
  58. u8 port_id;
  59. u8 ch_mask;
  60. u32 ch_rate;
  61. u8 num_ch;
  62. u8 port_type;
  63. };
  64. enum {
  65. WSA881X_DEV_DOWN,
  66. WSA881X_DEV_UP,
  67. WSA881X_DEV_READY,
  68. };
  69. /*
  70. * Private data Structure for wsa881x. All parameters related to
  71. * WSA881X codec needs to be defined here.
  72. */
  73. struct wsa881x_priv {
  74. struct regmap *regmap;
  75. struct device *dev;
  76. struct swr_device *swr_slave;
  77. struct snd_soc_component *component;
  78. bool comp_enable;
  79. bool boost_enable;
  80. bool visense_enable;
  81. u8 pa_gain;
  82. struct swr_port port[WSA881X_MAX_SWR_PORTS];
  83. int pd_gpio;
  84. struct wsa881x_tz_priv tz_pdata;
  85. int bg_cnt;
  86. int clk_cnt;
  87. int version;
  88. struct mutex bg_lock;
  89. struct mutex res_lock;
  90. struct mutex temp_lock;
  91. struct snd_info_entry *entry;
  92. struct snd_info_entry *version_entry;
  93. int state;
  94. struct delayed_work ocp_ctl_work;
  95. struct device_node *wsa_rst_np;
  96. int pa_mute;
  97. struct device_node *bolero_np;
  98. struct platform_device* bolero_dev;
  99. struct notifier_block bolero_nblock;
  100. void *handle;
  101. int (*register_notifier)(void *handle,
  102. struct notifier_block *nblock,
  103. bool enable);
  104. };
  105. /* from bolero to WSA events */
  106. enum {
  107. BOLERO_WSA_EVT_TX_CH_HOLD_CLEAR = 1,
  108. BOLERO_WSA_EVT_PA_OFF_PRE_SSR,
  109. BOLERO_WSA_EVT_SSR_DOWN,
  110. BOLERO_WSA_EVT_SSR_UP,
  111. };
  112. struct wsa_ctrl_platform_data {
  113. void *handle;
  114. int (*update_wsa_event)(void *handle, u16 event, u32 data);
  115. int (*register_notifier)(void *handle,
  116. struct notifier_block *nblock,
  117. bool enable);
  118. };
  119. #define SWR_SLV_MAX_REG_ADDR 0x390
  120. #define SWR_SLV_START_REG_ADDR 0x40
  121. #define SWR_SLV_MAX_BUF_LEN 25
  122. #define BYTES_PER_LINE 12
  123. #define SWR_SLV_RD_BUF_LEN 8
  124. #define SWR_SLV_WR_BUF_LEN 32
  125. #define SWR_SLV_MAX_DEVICES 2
  126. #define WSA881X_VERSION_ENTRY_SIZE 27
  127. #define WSA881X_OCP_CTL_TIMER_SEC 2
  128. #define WSA881X_OCP_CTL_TEMP_CELSIUS 25
  129. #define WSA881X_OCP_CTL_POLL_TIMER_SEC 60
  130. static int wsa881x_ocp_poll_timer_sec = WSA881X_OCP_CTL_POLL_TIMER_SEC;
  131. module_param(wsa881x_ocp_poll_timer_sec, int, 0664);
  132. MODULE_PARM_DESC(wsa881x_ocp_poll_timer_sec, "timer for ocp ctl polling");
  133. static struct wsa881x_priv *dbgwsa881x;
  134. static struct dentry *debugfs_wsa881x_dent;
  135. static struct dentry *debugfs_peek;
  136. static struct dentry *debugfs_poke;
  137. static struct dentry *debugfs_reg_dump;
  138. static unsigned int read_data;
  139. static unsigned int devnum;
  140. static int32_t wsa881x_resource_acquire(struct snd_soc_component *component,
  141. bool enable);
  142. static const char * const wsa_pa_gain_text[] = {
  143. "G_18_DB", "G_16P5_DB", "G_15_DB", "G_13P5_DB", "G_12_DB", "G_10P5_DB",
  144. "G_9_DB", "G_7P5_DB", "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB",
  145. "G_0_DB"
  146. };
  147. static const struct soc_enum wsa_pa_gain_enum =
  148. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa_pa_gain_text), wsa_pa_gain_text);
  149. static int wsa_pa_gain_get(struct snd_kcontrol *kcontrol,
  150. struct snd_ctl_elem_value *ucontrol)
  151. {
  152. struct snd_soc_component *component =
  153. snd_soc_kcontrol_component(kcontrol);
  154. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  155. ucontrol->value.integer.value[0] = wsa881x->pa_gain;
  156. dev_dbg(component->dev, "%s: PA gain = 0x%x\n", __func__,
  157. wsa881x->pa_gain);
  158. return 0;
  159. }
  160. static int wsa_pa_gain_put(struct snd_kcontrol *kcontrol,
  161. struct snd_ctl_elem_value *ucontrol)
  162. {
  163. struct snd_soc_component *component =
  164. snd_soc_kcontrol_component(kcontrol);
  165. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  166. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  167. __func__, ucontrol->value.integer.value[0]);
  168. wsa881x->pa_gain = ucontrol->value.integer.value[0];
  169. return 0;
  170. }
  171. static int wsa881x_get_mute(struct snd_kcontrol *kcontrol,
  172. struct snd_ctl_elem_value *ucontrol)
  173. {
  174. struct snd_soc_component *component =
  175. snd_soc_kcontrol_component(kcontrol);
  176. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  177. ucontrol->value.integer.value[0] = wsa881x->pa_mute;
  178. return 0;
  179. }
  180. static int wsa881x_set_mute(struct snd_kcontrol *kcontrol,
  181. struct snd_ctl_elem_value *ucontrol)
  182. {
  183. struct snd_soc_component *component =
  184. snd_soc_kcontrol_component(kcontrol);
  185. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  186. int value = ucontrol->value.integer.value[0];
  187. dev_dbg(component->dev, "%s: mute current %d, new %d\n",
  188. __func__, wsa881x->pa_mute, value);
  189. if (value)
  190. snd_soc_component_update_bits(component, WSA881X_SPKR_DRV_EN,
  191. 0x80, 0x00);
  192. wsa881x->pa_mute = value;
  193. return 0;
  194. }
  195. static int wsa881x_get_t0_init(struct snd_kcontrol *kcontrol,
  196. struct snd_ctl_elem_value *ucontrol)
  197. {
  198. struct snd_soc_component *component =
  199. snd_soc_kcontrol_component(kcontrol);
  200. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  201. struct wsa881x_tz_priv *pdata = &wsa881x->tz_pdata;
  202. ucontrol->value.integer.value[0] = pdata->t0_init;
  203. dev_dbg(component->dev, "%s: t0 init %d\n", __func__, pdata->t0_init);
  204. return 0;
  205. }
  206. static int wsa881x_set_t0_init(struct snd_kcontrol *kcontrol,
  207. struct snd_ctl_elem_value *ucontrol)
  208. {
  209. struct snd_soc_component *component =
  210. snd_soc_kcontrol_component(kcontrol);
  211. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  212. struct wsa881x_tz_priv *pdata = &wsa881x->tz_pdata;
  213. pdata->t0_init = ucontrol->value.integer.value[0];
  214. dev_dbg(component->dev, "%s: t0 init %d\n", __func__, pdata->t0_init);
  215. return 0;
  216. }
  217. static const struct snd_kcontrol_new wsa_snd_controls[] = {
  218. SOC_ENUM_EXT("WSA PA Gain", wsa_pa_gain_enum,
  219. wsa_pa_gain_get, wsa_pa_gain_put),
  220. SOC_SINGLE_EXT("WSA PA Mute", SND_SOC_NOPM, 0, 1, 0,
  221. wsa881x_get_mute, wsa881x_set_mute),
  222. SOC_SINGLE_EXT("WSA T0 Init", SND_SOC_NOPM, 0, 1, 0,
  223. wsa881x_get_t0_init, wsa881x_set_t0_init),
  224. };
  225. static int codec_debug_open(struct inode *inode, struct file *file)
  226. {
  227. file->private_data = inode->i_private;
  228. return 0;
  229. }
  230. static int get_parameters(char *buf, u32 *param1, int num_of_par)
  231. {
  232. char *token;
  233. int base, cnt;
  234. token = strsep(&buf, " ");
  235. for (cnt = 0; cnt < num_of_par; cnt++) {
  236. if (token) {
  237. if ((token[1] == 'x') || (token[1] == 'X'))
  238. base = 16;
  239. else
  240. base = 10;
  241. if (kstrtou32(token, base, &param1[cnt]) != 0)
  242. return -EINVAL;
  243. token = strsep(&buf, " ");
  244. } else
  245. return -EINVAL;
  246. }
  247. return 0;
  248. }
  249. static ssize_t wsa881x_codec_version_read(struct snd_info_entry *entry,
  250. void *file_private_data, struct file *file,
  251. char __user *buf, size_t count, loff_t pos)
  252. {
  253. struct wsa881x_priv *wsa881x;
  254. char buffer[WSA881X_VERSION_ENTRY_SIZE];
  255. int len;
  256. wsa881x = (struct wsa881x_priv *) entry->private_data;
  257. if (!wsa881x) {
  258. pr_err("%s: wsa881x priv is null\n", __func__);
  259. return -EINVAL;
  260. }
  261. len = snprintf(buffer, sizeof(buffer), "WSA881X-SOUNDWIRE_2_0\n");
  262. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  263. }
  264. static struct snd_info_entry_ops wsa881x_codec_info_ops = {
  265. .read = wsa881x_codec_version_read,
  266. };
  267. /*
  268. * wsa881x_codec_info_create_codec_entry - creates wsa881x module
  269. * @codec_root: The parent directory
  270. * @component: Codec instance
  271. *
  272. * Creates wsa881x module and version entry under the given
  273. * parent directory.
  274. *
  275. * Return: 0 on success or negative error code on failure.
  276. */
  277. int wsa881x_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  278. struct snd_soc_component *component)
  279. {
  280. struct snd_info_entry *version_entry;
  281. struct wsa881x_priv *wsa881x;
  282. struct snd_soc_card *card;
  283. char name[80];
  284. if (!codec_root || !component)
  285. return -EINVAL;
  286. wsa881x = snd_soc_component_get_drvdata(component);
  287. card = component->card;
  288. snprintf(name, sizeof(name), "%s.%x", "wsa881x",
  289. (u32)wsa881x->swr_slave->addr);
  290. wsa881x->entry = snd_info_create_subdir(codec_root->module,
  291. (const char *)name,
  292. codec_root);
  293. if (!wsa881x->entry) {
  294. dev_dbg(component->dev, "%s: failed to create wsa881x entry\n",
  295. __func__);
  296. return -ENOMEM;
  297. }
  298. version_entry = snd_info_create_card_entry(card->snd_card,
  299. "version",
  300. wsa881x->entry);
  301. if (!version_entry) {
  302. dev_dbg(component->dev, "%s: failed to create wsa881x version entry\n",
  303. __func__);
  304. return -ENOMEM;
  305. }
  306. version_entry->private_data = wsa881x;
  307. version_entry->size = WSA881X_VERSION_ENTRY_SIZE;
  308. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  309. version_entry->c.ops = &wsa881x_codec_info_ops;
  310. if (snd_info_register(version_entry) < 0) {
  311. snd_info_free_entry(version_entry);
  312. return -ENOMEM;
  313. }
  314. wsa881x->version_entry = version_entry;
  315. return 0;
  316. }
  317. EXPORT_SYMBOL(wsa881x_codec_info_create_codec_entry);
  318. static bool is_swr_slv_reg_readable(int reg)
  319. {
  320. bool ret = true;
  321. if (((reg > 0x46) && (reg < 0x4A)) ||
  322. ((reg > 0x4A) && (reg < 0x50)) ||
  323. ((reg > 0x55) && (reg < 0xE0)) ||
  324. ((reg > 0xE0) && (reg < 0xF0)) ||
  325. ((reg > 0xF0) && (reg < 0x100)) ||
  326. ((reg > 0x105) && (reg < 0x120)) ||
  327. ((reg > 0x128) && (reg < 0x130)) ||
  328. ((reg > 0x138) && (reg < 0x200)) ||
  329. ((reg > 0x205) && (reg < 0x220)) ||
  330. ((reg > 0x228) && (reg < 0x230)) ||
  331. ((reg > 0x238) && (reg < 0x300)) ||
  332. ((reg > 0x305) && (reg < 0x320)) ||
  333. ((reg > 0x328) && (reg < 0x330)) ||
  334. ((reg > 0x338) && (reg < 0x400)) ||
  335. ((reg > 0x405) && (reg < 0x420)))
  336. ret = false;
  337. return ret;
  338. }
  339. static ssize_t wsa881x_swrslave_reg_show(char __user *ubuf, size_t count,
  340. loff_t *ppos)
  341. {
  342. int i, reg_val, len;
  343. ssize_t total = 0;
  344. char tmp_buf[SWR_SLV_MAX_BUF_LEN];
  345. if (!ubuf || !ppos || (devnum == 0))
  346. return 0;
  347. for (i = (((int) *ppos / BYTES_PER_LINE) + SWR_SLV_START_REG_ADDR);
  348. i <= SWR_SLV_MAX_REG_ADDR; i++) {
  349. if (!is_swr_slv_reg_readable(i))
  350. continue;
  351. swr_read(dbgwsa881x->swr_slave, devnum,
  352. i, &reg_val, 1);
  353. len = snprintf(tmp_buf, 25, "0x%.3x: 0x%.2x\n", i,
  354. (reg_val & 0xFF));
  355. if (len < 0) {
  356. pr_err("%s: fail to fill the buffer\n", __func__);
  357. total = -EFAULT;
  358. goto copy_err;
  359. }
  360. if ((total + len) >= count - 1)
  361. break;
  362. if (copy_to_user((ubuf + total), tmp_buf, len)) {
  363. pr_err("%s: fail to copy reg dump\n", __func__);
  364. total = -EFAULT;
  365. goto copy_err;
  366. }
  367. *ppos += len;
  368. total += len;
  369. }
  370. copy_err:
  371. return total;
  372. }
  373. static ssize_t codec_debug_read(struct file *file, char __user *ubuf,
  374. size_t count, loff_t *ppos)
  375. {
  376. char lbuf[SWR_SLV_RD_BUF_LEN];
  377. char *access_str;
  378. ssize_t ret_cnt;
  379. if (!count || !file || !ppos || !ubuf)
  380. return -EINVAL;
  381. access_str = file->private_data;
  382. if (*ppos < 0)
  383. return -EINVAL;
  384. if (!strcmp(access_str, "swrslave_peek")) {
  385. snprintf(lbuf, sizeof(lbuf), "0x%x\n", (read_data & 0xFF));
  386. ret_cnt = simple_read_from_buffer(ubuf, count, ppos, lbuf,
  387. strnlen(lbuf, 7));
  388. } else if (!strcmp(access_str, "swrslave_reg_dump")) {
  389. ret_cnt = wsa881x_swrslave_reg_show(ubuf, count, ppos);
  390. } else {
  391. pr_err("%s: %s not permitted to read\n", __func__, access_str);
  392. ret_cnt = -EPERM;
  393. }
  394. return ret_cnt;
  395. }
  396. static ssize_t codec_debug_write(struct file *filp,
  397. const char __user *ubuf, size_t cnt, loff_t *ppos)
  398. {
  399. char lbuf[SWR_SLV_WR_BUF_LEN];
  400. int rc;
  401. u32 param[5];
  402. char *access_str;
  403. if (!filp || !ppos || !ubuf)
  404. return -EINVAL;
  405. access_str = filp->private_data;
  406. if (cnt > sizeof(lbuf) - 1)
  407. return -EINVAL;
  408. rc = copy_from_user(lbuf, ubuf, cnt);
  409. if (rc)
  410. return -EFAULT;
  411. lbuf[cnt] = '\0';
  412. if (!strcmp(access_str, "swrslave_poke")) {
  413. /* write */
  414. rc = get_parameters(lbuf, param, 3);
  415. if ((param[0] <= SWR_SLV_MAX_REG_ADDR) && (param[1] <= 0xFF) &&
  416. (rc == 0))
  417. swr_write(dbgwsa881x->swr_slave, param[2],
  418. param[0], &param[1]);
  419. else
  420. rc = -EINVAL;
  421. } else if (!strcmp(access_str, "swrslave_peek")) {
  422. /* read */
  423. rc = get_parameters(lbuf, param, 2);
  424. if ((param[0] <= SWR_SLV_MAX_REG_ADDR) && (rc == 0))
  425. swr_read(dbgwsa881x->swr_slave, param[1],
  426. param[0], &read_data, 1);
  427. else
  428. rc = -EINVAL;
  429. } else if (!strcmp(access_str, "swrslave_reg_dump")) {
  430. /* reg dump */
  431. rc = get_parameters(lbuf, param, 1);
  432. if ((rc == 0) && (param[0] > 0) &&
  433. (param[0] <= SWR_SLV_MAX_DEVICES))
  434. devnum = param[0];
  435. else
  436. rc = -EINVAL;
  437. }
  438. if (rc == 0)
  439. rc = cnt;
  440. else
  441. pr_err("%s: rc = %d\n", __func__, rc);
  442. return rc;
  443. }
  444. static const struct file_operations codec_debug_ops = {
  445. .open = codec_debug_open,
  446. .write = codec_debug_write,
  447. .read = codec_debug_read,
  448. };
  449. static void wsa881x_regcache_sync(struct wsa881x_priv *wsa881x)
  450. {
  451. mutex_lock(&wsa881x->res_lock);
  452. if (wsa881x->state != WSA881X_DEV_READY) {
  453. regcache_mark_dirty(wsa881x->regmap);
  454. regcache_sync(wsa881x->regmap);
  455. wsa881x->state = WSA881X_DEV_READY;
  456. }
  457. mutex_unlock(&wsa881x->res_lock);
  458. }
  459. static const struct reg_sequence wsa881x_pre_pmu_pa[] = {
  460. {WSA881X_SPKR_DRV_GAIN, 0x41, 0},
  461. {WSA881X_SPKR_MISC_CTL1, 0x01, 0},
  462. {WSA881X_ADC_EN_DET_TEST_I, 0x01, 0},
  463. {WSA881X_ADC_EN_MODU_V, 0x02, 0},
  464. {WSA881X_ADC_EN_DET_TEST_V, 0x10, 0},
  465. {WSA881X_SPKR_PWRSTG_DBG, 0xA0, 0},
  466. };
  467. static const struct reg_sequence wsa881x_pre_pmu_pa_2_0[] = {
  468. {WSA881X_SPKR_DRV_GAIN, 0x41, 0},
  469. {WSA881X_SPKR_MISC_CTL1, 0x87, 0},
  470. };
  471. static const struct reg_sequence wsa881x_post_pmu_pa[] = {
  472. {WSA881X_SPKR_PWRSTG_DBG, 0x00, 0},
  473. {WSA881X_ADC_EN_DET_TEST_V, 0x00, 0},
  474. {WSA881X_ADC_EN_MODU_V, 0x00, 0},
  475. {WSA881X_ADC_EN_DET_TEST_I, 0x00, 0},
  476. };
  477. static const struct reg_sequence wsa881x_vi_txfe_en[] = {
  478. {WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x85, 0},
  479. {WSA881X_SPKR_PROT_ATEST2, 0x0A, 0},
  480. {WSA881X_SPKR_PROT_FE_GAIN, 0xCF, 0},
  481. };
  482. static const struct reg_sequence wsa881x_vi_txfe_en_2_0[] = {
  483. {WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x85, 0},
  484. {WSA881X_SPKR_PROT_ATEST2, 0x0A, 0},
  485. {WSA881X_SPKR_PROT_FE_GAIN, 0x47, 0},
  486. };
  487. static int wsa881x_boost_ctrl(struct snd_soc_component *component, bool enable)
  488. {
  489. dev_dbg(component->dev, "%s: enable:%d\n", __func__, enable);
  490. if (enable)
  491. snd_soc_component_update_bits(component, WSA881X_BOOST_EN_CTL,
  492. 0x80, 0x80);
  493. else
  494. snd_soc_component_update_bits(component, WSA881X_BOOST_EN_CTL,
  495. 0x80, 0x00);
  496. /*
  497. * 1.5ms sleep is needed after boost enable/disable as per
  498. * HW requirement
  499. */
  500. usleep_range(1500, 1510);
  501. return 0;
  502. }
  503. static int wsa881x_visense_txfe_ctrl(struct snd_soc_component *component,
  504. bool enable, u8 isense1_gain,
  505. u8 isense2_gain, u8 vsense_gain)
  506. {
  507. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  508. dev_dbg(component->dev,
  509. "%s: enable:%d, isense1 gain: %d, isense2 gain: %d, vsense_gain %d\n",
  510. __func__, enable, isense1_gain, isense2_gain, vsense_gain);
  511. if (enable) {
  512. regmap_multi_reg_write(wsa881x->regmap,
  513. wsa881x_vi_txfe_en_2_0,
  514. ARRAY_SIZE(wsa881x_vi_txfe_en_2_0));
  515. } else {
  516. snd_soc_component_update_bits(component,
  517. WSA881X_SPKR_PROT_FE_VSENSE_VCM,
  518. 0x08, 0x08);
  519. /*
  520. * 200us sleep is needed after visense txfe disable as per
  521. * HW requirement.
  522. */
  523. usleep_range(200, 210);
  524. snd_soc_component_update_bits(component,
  525. WSA881X_SPKR_PROT_FE_GAIN,
  526. 0x01, 0x00);
  527. }
  528. return 0;
  529. }
  530. static int wsa881x_visense_adc_ctrl(struct snd_soc_component *component,
  531. bool enable)
  532. {
  533. dev_dbg(component->dev, "%s: enable:%d\n", __func__, enable);
  534. snd_soc_component_update_bits(component, WSA881X_ADC_EN_MODU_V,
  535. (0x01 << 7), (enable << 7));
  536. snd_soc_component_update_bits(component, WSA881X_ADC_EN_MODU_I,
  537. (0x01 << 7), (enable << 7));
  538. return 0;
  539. }
  540. static void wsa881x_bandgap_ctrl(struct snd_soc_component *component,
  541. bool enable)
  542. {
  543. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  544. dev_dbg(component->dev, "%s: enable:%d, bg_count:%d\n", __func__,
  545. enable, wsa881x->bg_cnt);
  546. mutex_lock(&wsa881x->bg_lock);
  547. if (enable) {
  548. ++wsa881x->bg_cnt;
  549. if (wsa881x->bg_cnt == 1) {
  550. snd_soc_component_update_bits(component,
  551. WSA881X_TEMP_OP,
  552. 0x08, 0x08);
  553. /* 400usec sleep is needed as per HW requirement */
  554. usleep_range(400, 410);
  555. snd_soc_component_update_bits(component,
  556. WSA881X_TEMP_OP,
  557. 0x04, 0x04);
  558. }
  559. } else {
  560. --wsa881x->bg_cnt;
  561. if (wsa881x->bg_cnt <= 0) {
  562. WARN_ON(wsa881x->bg_cnt < 0);
  563. wsa881x->bg_cnt = 0;
  564. snd_soc_component_update_bits(component,
  565. WSA881X_TEMP_OP, 0x04, 0x00);
  566. snd_soc_component_update_bits(component,
  567. WSA881X_TEMP_OP, 0x08, 0x00);
  568. }
  569. }
  570. mutex_unlock(&wsa881x->bg_lock);
  571. }
  572. static void wsa881x_clk_ctrl(struct snd_soc_component *component, bool enable)
  573. {
  574. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  575. dev_dbg(component->dev, "%s: enable:%d, clk_count:%d\n", __func__,
  576. enable, wsa881x->clk_cnt);
  577. mutex_lock(&wsa881x->res_lock);
  578. if (enable) {
  579. ++wsa881x->clk_cnt;
  580. if (wsa881x->clk_cnt == 1) {
  581. snd_soc_component_write(component,
  582. WSA881X_CDC_DIG_CLK_CTL, 0x01);
  583. snd_soc_component_write(component,
  584. WSA881X_CDC_ANA_CLK_CTL, 0x01);
  585. }
  586. } else {
  587. --wsa881x->clk_cnt;
  588. if (wsa881x->clk_cnt <= 0) {
  589. WARN_ON(wsa881x->clk_cnt < 0);
  590. wsa881x->clk_cnt = 0;
  591. snd_soc_component_write(component,
  592. WSA881X_CDC_DIG_CLK_CTL, 0x00);
  593. snd_soc_component_write(component,
  594. WSA881X_CDC_ANA_CLK_CTL, 0x00);
  595. }
  596. }
  597. mutex_unlock(&wsa881x->res_lock);
  598. }
  599. static int wsa881x_get_compander(struct snd_kcontrol *kcontrol,
  600. struct snd_ctl_elem_value *ucontrol)
  601. {
  602. struct snd_soc_component *component =
  603. snd_soc_kcontrol_component(kcontrol);
  604. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  605. ucontrol->value.integer.value[0] = wsa881x->comp_enable;
  606. return 0;
  607. }
  608. static int wsa881x_set_compander(struct snd_kcontrol *kcontrol,
  609. struct snd_ctl_elem_value *ucontrol)
  610. {
  611. struct snd_soc_component *component =
  612. snd_soc_kcontrol_component(kcontrol);
  613. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  614. int value = ucontrol->value.integer.value[0];
  615. dev_dbg(component->dev, "%s: Compander enable current %d, new %d\n",
  616. __func__, wsa881x->comp_enable, value);
  617. wsa881x->comp_enable = value;
  618. return 0;
  619. }
  620. static int wsa881x_get_boost(struct snd_kcontrol *kcontrol,
  621. struct snd_ctl_elem_value *ucontrol)
  622. {
  623. struct snd_soc_component *component =
  624. snd_soc_kcontrol_component(kcontrol);
  625. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  626. ucontrol->value.integer.value[0] = wsa881x->boost_enable;
  627. return 0;
  628. }
  629. static int wsa881x_set_boost(struct snd_kcontrol *kcontrol,
  630. struct snd_ctl_elem_value *ucontrol)
  631. {
  632. struct snd_soc_component *component =
  633. snd_soc_kcontrol_component(kcontrol);
  634. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  635. int value = ucontrol->value.integer.value[0];
  636. dev_dbg(component->dev, "%s: Boost enable current %d, new %d\n",
  637. __func__, wsa881x->boost_enable, value);
  638. wsa881x->boost_enable = value;
  639. return 0;
  640. }
  641. static int wsa881x_get_visense(struct snd_kcontrol *kcontrol,
  642. struct snd_ctl_elem_value *ucontrol)
  643. {
  644. struct snd_soc_component *component =
  645. snd_soc_kcontrol_component(kcontrol);
  646. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  647. ucontrol->value.integer.value[0] = wsa881x->visense_enable;
  648. return 0;
  649. }
  650. static int wsa881x_set_visense(struct snd_kcontrol *kcontrol,
  651. struct snd_ctl_elem_value *ucontrol)
  652. {
  653. struct snd_soc_component *component =
  654. snd_soc_kcontrol_component(kcontrol);
  655. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  656. int value = ucontrol->value.integer.value[0];
  657. dev_dbg(component->dev, "%s: VIsense enable current %d, new %d\n",
  658. __func__, wsa881x->visense_enable, value);
  659. wsa881x->visense_enable = value;
  660. return 0;
  661. }
  662. static int wsa881x_set_boost_level(struct snd_kcontrol *kcontrol,
  663. struct snd_ctl_elem_value *ucontrol)
  664. {
  665. struct snd_soc_component *component =
  666. snd_soc_kcontrol_component(kcontrol);
  667. u8 wsa_boost_level = 0;
  668. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  669. __func__, ucontrol->value.integer.value[0]);
  670. wsa_boost_level = ucontrol->value.integer.value[0];
  671. snd_soc_component_update_bits(component, WSA881X_BOOST_PRESET_OUT1,
  672. 0xff, wsa_boost_level);
  673. return 0;
  674. }
  675. static int wsa881x_get_boost_level(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. u8 wsa_boost_level = 0;
  681. wsa_boost_level = snd_soc_component_read32(component,
  682. WSA881X_BOOST_PRESET_OUT1);
  683. ucontrol->value.integer.value[0] = wsa_boost_level;
  684. dev_dbg(component->dev, "%s: boost level = 0x%x\n", __func__,
  685. wsa_boost_level);
  686. return 0;
  687. }
  688. static const struct snd_kcontrol_new wsa881x_snd_controls[] = {
  689. SOC_SINGLE_EXT("COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  690. wsa881x_get_compander, wsa881x_set_compander),
  691. SOC_SINGLE_EXT("BOOST Switch", SND_SOC_NOPM, 0, 1, 0,
  692. wsa881x_get_boost, wsa881x_set_boost),
  693. SOC_SINGLE_EXT("VISENSE Switch", SND_SOC_NOPM, 0, 1, 0,
  694. wsa881x_get_visense, wsa881x_set_visense),
  695. SOC_SINGLE_EXT("Boost Level", SND_SOC_NOPM, 0, 0xff, 0,
  696. wsa881x_get_boost_level, wsa881x_set_boost_level),
  697. };
  698. static const struct snd_kcontrol_new swr_dac_port[] = {
  699. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  700. };
  701. static int wsa881x_set_port(struct snd_soc_component *component, int port_idx,
  702. u8 *port_id, u8 *num_ch, u8 *ch_mask, u32 *ch_rate,
  703. u8 *port_type)
  704. {
  705. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  706. *port_id = wsa881x->port[port_idx].port_id;
  707. *num_ch = wsa881x->port[port_idx].num_ch;
  708. *ch_mask = wsa881x->port[port_idx].ch_mask;
  709. *ch_rate = wsa881x->port[port_idx].ch_rate;
  710. *port_type = wsa881x->port[port_idx].port_type;
  711. return 0;
  712. }
  713. static int wsa881x_enable_swr_dac_port(struct snd_soc_dapm_widget *w,
  714. struct snd_kcontrol *kcontrol, int event)
  715. {
  716. struct snd_soc_component *component =
  717. snd_soc_dapm_to_component(w->dapm);
  718. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  719. u8 port_id[WSA881X_MAX_SWR_PORTS];
  720. u8 num_ch[WSA881X_MAX_SWR_PORTS];
  721. u8 ch_mask[WSA881X_MAX_SWR_PORTS];
  722. u32 ch_rate[WSA881X_MAX_SWR_PORTS];
  723. u8 port_type[WSA881X_MAX_SWR_PORTS];
  724. u8 num_port = 0;
  725. dev_dbg(component->dev, "%s: event %d name %s\n", __func__,
  726. event, w->name);
  727. if (wsa881x == NULL)
  728. return -EINVAL;
  729. switch (event) {
  730. case SND_SOC_DAPM_PRE_PMU:
  731. wsa881x_set_port(component, SWR_DAC_PORT,
  732. &port_id[num_port], &num_ch[num_port],
  733. &ch_mask[num_port], &ch_rate[num_port],
  734. &port_type[num_port]);
  735. ++num_port;
  736. if (wsa881x->comp_enable) {
  737. wsa881x_set_port(component, SWR_COMP_PORT,
  738. &port_id[num_port], &num_ch[num_port],
  739. &ch_mask[num_port], &ch_rate[num_port],
  740. &port_type[num_port]);
  741. ++num_port;
  742. }
  743. if (wsa881x->boost_enable) {
  744. wsa881x_set_port(component, SWR_BOOST_PORT,
  745. &port_id[num_port], &num_ch[num_port],
  746. &ch_mask[num_port], &ch_rate[num_port],
  747. &port_type[num_port]);
  748. ++num_port;
  749. }
  750. if (wsa881x->visense_enable) {
  751. wsa881x_set_port(component, SWR_VISENSE_PORT,
  752. &port_id[num_port], &num_ch[num_port],
  753. &ch_mask[num_port], &ch_rate[num_port],
  754. &port_type[num_port]);
  755. ++num_port;
  756. }
  757. swr_connect_port(wsa881x->swr_slave, &port_id[0], num_port,
  758. &ch_mask[0], &ch_rate[0], &num_ch[0],
  759. &port_type[0]);
  760. break;
  761. case SND_SOC_DAPM_POST_PMU:
  762. break;
  763. case SND_SOC_DAPM_PRE_PMD:
  764. break;
  765. case SND_SOC_DAPM_POST_PMD:
  766. wsa881x_set_port(component, SWR_DAC_PORT,
  767. &port_id[num_port], &num_ch[num_port],
  768. &ch_mask[num_port], &ch_rate[num_port],
  769. &port_type[num_port]);
  770. ++num_port;
  771. if (wsa881x->comp_enable) {
  772. wsa881x_set_port(component, SWR_COMP_PORT,
  773. &port_id[num_port], &num_ch[num_port],
  774. &ch_mask[num_port], &ch_rate[num_port],
  775. &port_type[num_port]);
  776. ++num_port;
  777. }
  778. if (wsa881x->boost_enable) {
  779. wsa881x_set_port(component, SWR_BOOST_PORT,
  780. &port_id[num_port], &num_ch[num_port],
  781. &ch_mask[num_port], &ch_rate[num_port],
  782. &port_type[num_port]);
  783. ++num_port;
  784. }
  785. if (wsa881x->visense_enable) {
  786. wsa881x_set_port(component, SWR_VISENSE_PORT,
  787. &port_id[num_port], &num_ch[num_port],
  788. &ch_mask[num_port], &ch_rate[num_port],
  789. &port_type[num_port]);
  790. ++num_port;
  791. }
  792. swr_disconnect_port(wsa881x->swr_slave, &port_id[0], num_port,
  793. &ch_mask[0], &port_type[0]);
  794. break;
  795. default:
  796. break;
  797. }
  798. return 0;
  799. }
  800. static int wsa881x_rdac_event(struct snd_soc_dapm_widget *w,
  801. struct snd_kcontrol *kcontrol, int event)
  802. {
  803. struct snd_soc_component *component =
  804. snd_soc_dapm_to_component(w->dapm);
  805. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  806. dev_dbg(component->dev, "%s: %s %d boost %d visense %d\n", __func__,
  807. w->name, event, wsa881x->boost_enable,
  808. wsa881x->visense_enable);
  809. switch (event) {
  810. case SND_SOC_DAPM_PRE_PMU:
  811. mutex_lock(&wsa881x->temp_lock);
  812. wsa881x_resource_acquire(component, ENABLE);
  813. mutex_unlock(&wsa881x->temp_lock);
  814. wsa881x_boost_ctrl(component, ENABLE);
  815. break;
  816. case SND_SOC_DAPM_POST_PMD:
  817. swr_slvdev_datapath_control(wsa881x->swr_slave,
  818. wsa881x->swr_slave->dev_num,
  819. false);
  820. wsa881x_boost_ctrl(component, DISABLE);
  821. mutex_lock(&wsa881x->temp_lock);
  822. wsa881x_resource_acquire(component, DISABLE);
  823. mutex_unlock(&wsa881x->temp_lock);
  824. break;
  825. }
  826. return 0;
  827. }
  828. static int wsa881x_ramp_pa_gain(struct snd_soc_component *component,
  829. int min_gain, int max_gain, int udelay)
  830. {
  831. int val;
  832. for (val = min_gain; max_gain <= val; val--) {
  833. snd_soc_component_update_bits(component, WSA881X_SPKR_DRV_GAIN,
  834. 0xF0, val << 4);
  835. /*
  836. * 1ms delay is needed for every step change in gain as per
  837. * HW requirement.
  838. */
  839. usleep_range(udelay, udelay+10);
  840. }
  841. return 0;
  842. }
  843. static void wsa881x_ocp_ctl_work(struct work_struct *work)
  844. {
  845. struct wsa881x_priv *wsa881x;
  846. struct delayed_work *dwork;
  847. struct snd_soc_component *component;
  848. int temp_val;
  849. dwork = to_delayed_work(work);
  850. wsa881x = container_of(dwork, struct wsa881x_priv, ocp_ctl_work);
  851. component = wsa881x->component;
  852. wsa881x_get_temp(wsa881x->tz_pdata.tz_dev, &temp_val);
  853. dev_dbg(component->dev, " temp = %d\n", temp_val);
  854. if (temp_val <= WSA881X_OCP_CTL_TEMP_CELSIUS)
  855. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  856. 0xC0, 0x00);
  857. else
  858. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  859. 0xC0, 0xC0);
  860. schedule_delayed_work(&wsa881x->ocp_ctl_work,
  861. msecs_to_jiffies(wsa881x_ocp_poll_timer_sec * 1000));
  862. }
  863. static int wsa881x_spkr_pa_event(struct snd_soc_dapm_widget *w,
  864. struct snd_kcontrol *kcontrol, int event)
  865. {
  866. struct snd_soc_component *component =
  867. snd_soc_dapm_to_component(w->dapm);
  868. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  869. int min_gain, max_gain;
  870. dev_dbg(component->dev, "%s: %s %d\n", __func__, w->name, event);
  871. switch (event) {
  872. case SND_SOC_DAPM_PRE_PMU:
  873. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  874. 0xC0, 0x80);
  875. regmap_multi_reg_write(wsa881x->regmap,
  876. wsa881x_pre_pmu_pa_2_0,
  877. ARRAY_SIZE(wsa881x_pre_pmu_pa_2_0));
  878. swr_slvdev_datapath_control(wsa881x->swr_slave,
  879. wsa881x->swr_slave->dev_num,
  880. true);
  881. /* Set register mode if compander is not enabled */
  882. if (!wsa881x->comp_enable)
  883. snd_soc_component_update_bits(component,
  884. WSA881X_SPKR_DRV_GAIN,
  885. 0x08, 0x08);
  886. else
  887. snd_soc_component_update_bits(component,
  888. WSA881X_SPKR_DRV_GAIN,
  889. 0x08, 0x00);
  890. break;
  891. case SND_SOC_DAPM_POST_PMU:
  892. if (!wsa881x->comp_enable) {
  893. max_gain = wsa881x->pa_gain;
  894. /*
  895. * Gain has to set incrementally in 4 steps
  896. * as per HW sequence
  897. */
  898. if (max_gain > G_4P5DB)
  899. min_gain = G_0DB;
  900. else
  901. min_gain = max_gain + 3;
  902. /*
  903. * 1ms delay is needed before change in gain
  904. * as per HW requirement.
  905. */
  906. usleep_range(1000, 1010);
  907. wsa881x_ramp_pa_gain(component, min_gain, max_gain,
  908. 1000);
  909. }
  910. if (wsa881x->visense_enable) {
  911. wsa881x_visense_txfe_ctrl(component, ENABLE,
  912. 0x00, 0x03, 0x01);
  913. snd_soc_component_update_bits(component,
  914. WSA881X_ADC_EN_SEL_IBAIS,
  915. 0x07, 0x01);
  916. wsa881x_visense_adc_ctrl(component, ENABLE);
  917. }
  918. schedule_delayed_work(&wsa881x->ocp_ctl_work,
  919. msecs_to_jiffies(WSA881X_OCP_CTL_TIMER_SEC * 1000));
  920. /* Force remove group */
  921. swr_remove_from_group(wsa881x->swr_slave,
  922. wsa881x->swr_slave->dev_num);
  923. break;
  924. case SND_SOC_DAPM_POST_PMD:
  925. if (wsa881x->visense_enable) {
  926. wsa881x_visense_adc_ctrl(component, DISABLE);
  927. wsa881x_visense_txfe_ctrl(component, DISABLE,
  928. 0x00, 0x01, 0x01);
  929. }
  930. cancel_delayed_work_sync(&wsa881x->ocp_ctl_work);
  931. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  932. 0xC0, 0xC0);
  933. break;
  934. }
  935. return 0;
  936. }
  937. static const struct snd_soc_dapm_widget wsa881x_dapm_widgets[] = {
  938. SND_SOC_DAPM_INPUT("IN"),
  939. SND_SOC_DAPM_MIXER_E("SWR DAC_Port", SND_SOC_NOPM, 0, 0, swr_dac_port,
  940. ARRAY_SIZE(swr_dac_port), wsa881x_enable_swr_dac_port,
  941. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  942. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  943. SND_SOC_DAPM_DAC_E("RDAC", NULL, WSA881X_SPKR_DAC_CTL, 7, 0,
  944. wsa881x_rdac_event,
  945. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  946. SND_SOC_DAPM_PGA_E("SPKR PGA", WSA881X_SPKR_DRV_EN, 7, 0, NULL, 0,
  947. wsa881x_spkr_pa_event, SND_SOC_DAPM_PRE_PMU |
  948. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  949. SND_SOC_DAPM_OUTPUT("SPKR"),
  950. };
  951. static const struct snd_soc_dapm_route wsa881x_audio_map[] = {
  952. {"SWR DAC_Port", "Switch", "IN"},
  953. {"RDAC", NULL, "SWR DAC_Port"},
  954. {"SPKR PGA", NULL, "RDAC"},
  955. {"SPKR", NULL, "SPKR PGA"},
  956. };
  957. int wsa881x_set_channel_map(struct snd_soc_component *component, u8 *port,
  958. u8 num_port, unsigned int *ch_mask,
  959. unsigned int *ch_rate, u8 *port_type)
  960. {
  961. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  962. int i;
  963. if (!port || !ch_mask || !ch_rate ||
  964. (num_port > WSA881X_MAX_SWR_PORTS)) {
  965. dev_err(component->dev,
  966. "%s: Invalid port=%pK, ch_mask=%pK, ch_rate=%pK\n",
  967. __func__, port, ch_mask, ch_rate);
  968. return -EINVAL;
  969. }
  970. for (i = 0; i < num_port; i++) {
  971. wsa881x->port[i].port_id = port[i];
  972. wsa881x->port[i].ch_mask = ch_mask[i];
  973. wsa881x->port[i].ch_rate = ch_rate[i];
  974. wsa881x->port[i].num_ch = __sw_hweight8(ch_mask[i]);
  975. if (port_type)
  976. wsa881x->port[i].port_type = port_type[i];
  977. }
  978. return 0;
  979. }
  980. EXPORT_SYMBOL(wsa881x_set_channel_map);
  981. static void wsa881x_init(struct snd_soc_component *component)
  982. {
  983. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  984. wsa881x->version =
  985. snd_soc_component_read32(component, WSA881X_CHIP_ID1);
  986. wsa881x_regmap_defaults(wsa881x->regmap, wsa881x->version);
  987. /* Enable software reset output from soundwire slave */
  988. snd_soc_component_update_bits(component, WSA881X_SWR_RESET_EN,
  989. 0x07, 0x07);
  990. /* Bring out of analog reset */
  991. snd_soc_component_update_bits(component, WSA881X_CDC_RST_CTL,
  992. 0x02, 0x02);
  993. /* Bring out of digital reset */
  994. snd_soc_component_update_bits(component, WSA881X_CDC_RST_CTL,
  995. 0x01, 0x01);
  996. snd_soc_component_update_bits(component, WSA881X_CLOCK_CONFIG,
  997. 0x10, 0x10);
  998. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  999. 0x02, 0x02);
  1000. snd_soc_component_update_bits(component, WSA881X_SPKR_MISC_CTL1,
  1001. 0xC0, 0x80);
  1002. snd_soc_component_update_bits(component, WSA881X_SPKR_MISC_CTL1,
  1003. 0x06, 0x06);
  1004. snd_soc_component_update_bits(component, WSA881X_SPKR_BIAS_INT,
  1005. 0xFF, 0x00);
  1006. snd_soc_component_update_bits(component, WSA881X_SPKR_PA_INT,
  1007. 0xF0, 0x40);
  1008. snd_soc_component_update_bits(component, WSA881X_SPKR_PA_INT,
  1009. 0x0E, 0x0E);
  1010. snd_soc_component_update_bits(component, WSA881X_BOOST_LOOP_STABILITY,
  1011. 0x03, 0x03);
  1012. snd_soc_component_update_bits(component, WSA881X_BOOST_MISC2_CTL,
  1013. 0xFF, 0x14);
  1014. snd_soc_component_update_bits(component, WSA881X_BOOST_START_CTL,
  1015. 0x80, 0x80);
  1016. snd_soc_component_update_bits(component, WSA881X_BOOST_START_CTL,
  1017. 0x03, 0x00);
  1018. snd_soc_component_update_bits(component,
  1019. WSA881X_BOOST_SLOPE_COMP_ISENSE_FB,
  1020. 0x0C, 0x04);
  1021. snd_soc_component_update_bits(component,
  1022. WSA881X_BOOST_SLOPE_COMP_ISENSE_FB,
  1023. 0x03, 0x00);
  1024. if (snd_soc_component_read32(component, WSA881X_OTP_REG_0))
  1025. snd_soc_component_update_bits(component,
  1026. WSA881X_BOOST_PRESET_OUT1,
  1027. 0xF0, 0x70);
  1028. snd_soc_component_update_bits(component, WSA881X_BOOST_PRESET_OUT2,
  1029. 0xF0, 0x30);
  1030. snd_soc_component_update_bits(component, WSA881X_SPKR_DRV_EN,
  1031. 0x08, 0x08);
  1032. snd_soc_component_update_bits(component, WSA881X_BOOST_CURRENT_LIMIT,
  1033. 0x0F, 0x08);
  1034. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  1035. 0x30, 0x30);
  1036. snd_soc_component_update_bits(component, WSA881X_SPKR_OCP_CTL,
  1037. 0x0C, 0x00);
  1038. snd_soc_component_update_bits(component, WSA881X_OTP_REG_28,
  1039. 0x3F, 0x3A);
  1040. snd_soc_component_update_bits(component, WSA881X_BONGO_RESRV_REG1,
  1041. 0xFF, 0xB2);
  1042. snd_soc_component_update_bits(component, WSA881X_BONGO_RESRV_REG2,
  1043. 0xFF, 0x05);
  1044. }
  1045. static int32_t wsa881x_resource_acquire(struct snd_soc_component *component,
  1046. bool enable)
  1047. {
  1048. wsa881x_clk_ctrl(component, enable);
  1049. wsa881x_bandgap_ctrl(component, enable);
  1050. return 0;
  1051. }
  1052. static int32_t wsa881x_temp_reg_read(struct snd_soc_component *component,
  1053. struct wsa_temp_register *wsa_temp_reg)
  1054. {
  1055. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  1056. struct swr_device *dev;
  1057. u8 retry = WSA881X_NUM_RETRY;
  1058. u8 devnum = 0;
  1059. if (!wsa881x) {
  1060. dev_err(component->dev, "%s: wsa881x is NULL\n", __func__);
  1061. return -EINVAL;
  1062. }
  1063. dev = wsa881x->swr_slave;
  1064. if (dev && (wsa881x->state == WSA881X_DEV_DOWN)) {
  1065. while (swr_get_logical_dev_num(dev, dev->addr, &devnum) &&
  1066. retry--) {
  1067. /* Retry after 1 msec delay */
  1068. usleep_range(1000, 1100);
  1069. }
  1070. if (retry == 0) {
  1071. dev_err(component->dev,
  1072. "%s get devnum %d for dev addr %lx failed\n",
  1073. __func__, devnum, dev->addr);
  1074. return -EINVAL;
  1075. }
  1076. }
  1077. wsa881x_regcache_sync(wsa881x);
  1078. mutex_lock(&wsa881x->temp_lock);
  1079. wsa881x_resource_acquire(component, ENABLE);
  1080. snd_soc_component_update_bits(component, WSA881X_TADC_VALUE_CTL,
  1081. 0x01, 0x00);
  1082. wsa_temp_reg->dmeas_msb = snd_soc_component_read32(
  1083. component, WSA881X_TEMP_MSB);
  1084. wsa_temp_reg->dmeas_lsb = snd_soc_component_read32(
  1085. component, WSA881X_TEMP_LSB);
  1086. snd_soc_component_update_bits(component, WSA881X_TADC_VALUE_CTL,
  1087. 0x01, 0x01);
  1088. wsa_temp_reg->d1_msb = snd_soc_component_read32(
  1089. component, WSA881X_OTP_REG_1);
  1090. wsa_temp_reg->d1_lsb = snd_soc_component_read32(
  1091. component, WSA881X_OTP_REG_2);
  1092. wsa_temp_reg->d2_msb = snd_soc_component_read32(
  1093. component, WSA881X_OTP_REG_3);
  1094. wsa_temp_reg->d2_lsb = snd_soc_component_read32(
  1095. component, WSA881X_OTP_REG_4);
  1096. wsa881x_resource_acquire(component, DISABLE);
  1097. mutex_unlock(&wsa881x->temp_lock);
  1098. return 0;
  1099. }
  1100. static int wsa881x_probe(struct snd_soc_component *component)
  1101. {
  1102. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  1103. struct swr_device *dev;
  1104. if (!wsa881x)
  1105. return -EINVAL;
  1106. snd_soc_component_init_regmap(component, wsa881x->regmap);
  1107. dev = wsa881x->swr_slave;
  1108. wsa881x->component = component;
  1109. mutex_init(&wsa881x->bg_lock);
  1110. wsa881x_init(component);
  1111. snprintf(wsa881x->tz_pdata.name, sizeof(wsa881x->tz_pdata.name),
  1112. "%s.%x", "wsatz", (u8)dev->addr);
  1113. wsa881x->bg_cnt = 0;
  1114. wsa881x->clk_cnt = 0;
  1115. wsa881x->tz_pdata.component = component;
  1116. wsa881x->tz_pdata.wsa_temp_reg_read = wsa881x_temp_reg_read;
  1117. wsa881x_init_thermal(&wsa881x->tz_pdata);
  1118. snd_soc_add_component_controls(component, wsa_snd_controls,
  1119. ARRAY_SIZE(wsa_snd_controls));
  1120. INIT_DELAYED_WORK(&wsa881x->ocp_ctl_work, wsa881x_ocp_ctl_work);
  1121. return 0;
  1122. }
  1123. static void wsa881x_remove(struct snd_soc_component *component)
  1124. {
  1125. struct wsa881x_priv *wsa881x = snd_soc_component_get_drvdata(component);
  1126. if (wsa881x->tz_pdata.tz_dev)
  1127. wsa881x_deinit_thermal(wsa881x->tz_pdata.tz_dev);
  1128. mutex_destroy(&wsa881x->bg_lock);
  1129. return;
  1130. }
  1131. static const struct snd_soc_component_driver soc_codec_dev_wsa881x = {
  1132. .name = DRV_NAME,
  1133. .probe = wsa881x_probe,
  1134. .remove = wsa881x_remove,
  1135. .controls = wsa881x_snd_controls,
  1136. .num_controls = ARRAY_SIZE(wsa881x_snd_controls),
  1137. .dapm_widgets = wsa881x_dapm_widgets,
  1138. .num_dapm_widgets = ARRAY_SIZE(wsa881x_dapm_widgets),
  1139. .dapm_routes = wsa881x_audio_map,
  1140. .num_dapm_routes = ARRAY_SIZE(wsa881x_audio_map),
  1141. };
  1142. static int wsa881x_gpio_ctrl(struct wsa881x_priv *wsa881x, bool enable)
  1143. {
  1144. int ret = 0;
  1145. if (wsa881x->pd_gpio < 0) {
  1146. dev_err(wsa881x->dev, "%s: gpio is not valid %d\n",
  1147. __func__, wsa881x->pd_gpio);
  1148. return -EINVAL;
  1149. }
  1150. if (wsa881x->wsa_rst_np) {
  1151. if (enable)
  1152. ret = msm_cdc_pinctrl_select_active_state(
  1153. wsa881x->wsa_rst_np);
  1154. else
  1155. ret = msm_cdc_pinctrl_select_sleep_state(
  1156. wsa881x->wsa_rst_np);
  1157. if (ret != 0)
  1158. dev_err(wsa881x->dev,
  1159. "%s: Failed to turn state %d; ret=%d\n",
  1160. __func__, enable, ret);
  1161. } else {
  1162. if (gpio_is_valid(wsa881x->pd_gpio))
  1163. gpio_direction_output(wsa881x->pd_gpio, enable);
  1164. }
  1165. return ret;
  1166. }
  1167. static int wsa881x_gpio_init(struct swr_device *pdev)
  1168. {
  1169. int ret = 0;
  1170. struct wsa881x_priv *wsa881x;
  1171. wsa881x = swr_get_dev_data(pdev);
  1172. if (!wsa881x) {
  1173. dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__);
  1174. return -EINVAL;
  1175. }
  1176. dev_dbg(&pdev->dev, "%s: gpio %d request with name %s\n",
  1177. __func__, wsa881x->pd_gpio, dev_name(&pdev->dev));
  1178. ret = gpio_request(wsa881x->pd_gpio, dev_name(&pdev->dev));
  1179. if (ret) {
  1180. if (ret == -EBUSY) {
  1181. /* GPIO was already requested */
  1182. dev_dbg(&pdev->dev,
  1183. "%s: gpio %d is already set to high\n",
  1184. __func__, wsa881x->pd_gpio);
  1185. ret = 0;
  1186. } else {
  1187. dev_err(&pdev->dev, "%s: Failed to request gpio %d, err: %d\n",
  1188. __func__, wsa881x->pd_gpio, ret);
  1189. }
  1190. }
  1191. return ret;
  1192. }
  1193. static int wsa881x_event_notify(struct notifier_block *nb,
  1194. unsigned long val, void *ptr)
  1195. {
  1196. u16 event = (val & 0xffff);
  1197. struct wsa881x_priv *wsa881x = container_of(nb, struct wsa881x_priv,
  1198. bolero_nblock);
  1199. if (!wsa881x)
  1200. return -EINVAL;
  1201. switch (event) {
  1202. case BOLERO_WSA_EVT_PA_OFF_PRE_SSR:
  1203. snd_soc_component_update_bits(wsa881x->component,
  1204. WSA881X_SPKR_DRV_GAIN,
  1205. 0xF0, 0xC0);
  1206. snd_soc_component_update_bits(wsa881x->component,
  1207. WSA881X_SPKR_DRV_EN,
  1208. 0x80, 0x00);
  1209. break;
  1210. default:
  1211. break;
  1212. }
  1213. return 0;
  1214. }
  1215. static int wsa881x_swr_probe(struct swr_device *pdev)
  1216. {
  1217. int ret = 0;
  1218. struct wsa881x_priv *wsa881x;
  1219. u8 devnum = 0;
  1220. bool pin_state_current = false;
  1221. struct wsa_ctrl_platform_data *plat_data = NULL;
  1222. wsa881x = devm_kzalloc(&pdev->dev, sizeof(struct wsa881x_priv),
  1223. GFP_KERNEL);
  1224. if (!wsa881x)
  1225. return -ENOMEM;
  1226. wsa881x->wsa_rst_np = of_parse_phandle(pdev->dev.of_node,
  1227. "qcom,spkr-sd-n-node", 0);
  1228. if (!wsa881x->wsa_rst_np) {
  1229. dev_dbg(&pdev->dev, "%s: Not using pinctrl, fallback to gpio\n",
  1230. __func__);
  1231. wsa881x->pd_gpio = of_get_named_gpio(pdev->dev.of_node,
  1232. "qcom,spkr-sd-n-gpio", 0);
  1233. if (wsa881x->pd_gpio < 0) {
  1234. dev_err(&pdev->dev, "%s: %s property is not found %d\n",
  1235. __func__, "qcom,spkr-sd-n-gpio",
  1236. wsa881x->pd_gpio);
  1237. goto err;
  1238. }
  1239. dev_dbg(&pdev->dev, "%s: reset gpio %d\n", __func__,
  1240. wsa881x->pd_gpio);
  1241. }
  1242. swr_set_dev_data(pdev, wsa881x);
  1243. wsa881x->swr_slave = pdev;
  1244. if (!wsa881x->wsa_rst_np) {
  1245. ret = wsa881x_gpio_init(pdev);
  1246. if (ret)
  1247. goto err;
  1248. }
  1249. if (wsa881x->wsa_rst_np)
  1250. pin_state_current = msm_cdc_pinctrl_get_state(
  1251. wsa881x->wsa_rst_np);
  1252. wsa881x_gpio_ctrl(wsa881x, true);
  1253. wsa881x->state = WSA881X_DEV_UP;
  1254. if (!debugfs_wsa881x_dent) {
  1255. dbgwsa881x = wsa881x;
  1256. debugfs_wsa881x_dent = debugfs_create_dir(
  1257. "wsa881x_swr_slave", 0);
  1258. if (!IS_ERR(debugfs_wsa881x_dent)) {
  1259. debugfs_peek = debugfs_create_file("swrslave_peek",
  1260. S_IFREG | 0444, debugfs_wsa881x_dent,
  1261. (void *) "swrslave_peek",
  1262. &codec_debug_ops);
  1263. debugfs_poke = debugfs_create_file("swrslave_poke",
  1264. S_IFREG | 0444, debugfs_wsa881x_dent,
  1265. (void *) "swrslave_poke",
  1266. &codec_debug_ops);
  1267. debugfs_reg_dump = debugfs_create_file(
  1268. "swrslave_reg_dump",
  1269. S_IFREG | 0444,
  1270. debugfs_wsa881x_dent,
  1271. (void *) "swrslave_reg_dump",
  1272. &codec_debug_ops);
  1273. }
  1274. }
  1275. /*
  1276. * Add 5msec delay to provide sufficient time for
  1277. * soundwire auto enumeration of slave devices as
  1278. * as per HW requirement.
  1279. */
  1280. usleep_range(5000, 5010);
  1281. ret = swr_get_logical_dev_num(pdev, pdev->addr, &devnum);
  1282. if (ret) {
  1283. dev_dbg(&pdev->dev,
  1284. "%s get devnum %d for dev addr %lx failed\n",
  1285. __func__, devnum, pdev->addr);
  1286. goto dev_err;
  1287. }
  1288. pdev->dev_num = devnum;
  1289. wsa881x->regmap = devm_regmap_init_swr(pdev,
  1290. &wsa881x_regmap_config);
  1291. if (IS_ERR(wsa881x->regmap)) {
  1292. ret = PTR_ERR(wsa881x->regmap);
  1293. dev_err(&pdev->dev, "%s: regmap_init failed %d\n",
  1294. __func__, ret);
  1295. goto dev_err;
  1296. }
  1297. ret = snd_soc_register_component(&pdev->dev, &soc_codec_dev_wsa881x,
  1298. NULL, 0);
  1299. if (ret) {
  1300. dev_err(&pdev->dev, "%s: Codec registration failed\n",
  1301. __func__);
  1302. goto dev_err;
  1303. }
  1304. wsa881x->bolero_np = of_parse_phandle(pdev->dev.of_node,
  1305. "qcom,bolero-handle", 0);
  1306. if (wsa881x->bolero_np) {
  1307. wsa881x->bolero_dev =
  1308. of_find_device_by_node(wsa881x->bolero_np);
  1309. if (wsa881x->bolero_dev) {
  1310. plat_data = dev_get_platdata(&wsa881x->bolero_dev->dev);
  1311. if (plat_data) {
  1312. wsa881x->bolero_nblock.notifier_call =
  1313. wsa881x_event_notify;
  1314. if (plat_data->register_notifier)
  1315. plat_data->register_notifier(
  1316. plat_data->handle,
  1317. &wsa881x->bolero_nblock,
  1318. true);
  1319. wsa881x->register_notifier =
  1320. plat_data->register_notifier;
  1321. wsa881x->handle = plat_data->handle;
  1322. } else {
  1323. dev_err(&pdev->dev, "%s: plat data not found\n",
  1324. __func__);
  1325. }
  1326. } else {
  1327. dev_err(&pdev->dev, "%s: bolero dev not found\n",
  1328. __func__);
  1329. }
  1330. } else {
  1331. dev_info(&pdev->dev, "%s: bolero node not found\n", __func__);
  1332. }
  1333. mutex_init(&wsa881x->res_lock);
  1334. mutex_init(&wsa881x->temp_lock);
  1335. return 0;
  1336. dev_err:
  1337. if (pin_state_current == false)
  1338. wsa881x_gpio_ctrl(wsa881x, false);
  1339. swr_remove_device(pdev);
  1340. err:
  1341. return ret;
  1342. }
  1343. static int wsa881x_swr_remove(struct swr_device *pdev)
  1344. {
  1345. struct wsa881x_priv *wsa881x;
  1346. wsa881x = swr_get_dev_data(pdev);
  1347. if (!wsa881x) {
  1348. dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__);
  1349. return -EINVAL;
  1350. }
  1351. if (wsa881x->register_notifier)
  1352. wsa881x->register_notifier(wsa881x->handle,
  1353. &wsa881x->bolero_nblock, false);
  1354. debugfs_remove_recursive(debugfs_wsa881x_dent);
  1355. debugfs_wsa881x_dent = NULL;
  1356. mutex_destroy(&wsa881x->res_lock);
  1357. mutex_destroy(&wsa881x->temp_lock);
  1358. snd_soc_unregister_component(&pdev->dev);
  1359. if (wsa881x->pd_gpio)
  1360. gpio_free(wsa881x->pd_gpio);
  1361. swr_set_dev_data(pdev, NULL);
  1362. return 0;
  1363. }
  1364. static int wsa881x_swr_up(struct swr_device *pdev)
  1365. {
  1366. int ret;
  1367. struct wsa881x_priv *wsa881x;
  1368. wsa881x = swr_get_dev_data(pdev);
  1369. if (!wsa881x) {
  1370. dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__);
  1371. return -EINVAL;
  1372. }
  1373. ret = wsa881x_gpio_ctrl(wsa881x, true);
  1374. if (ret)
  1375. dev_err(&pdev->dev, "%s: Failed to enable gpio\n", __func__);
  1376. else
  1377. wsa881x->state = WSA881X_DEV_UP;
  1378. return ret;
  1379. }
  1380. static int wsa881x_swr_down(struct swr_device *pdev)
  1381. {
  1382. struct wsa881x_priv *wsa881x;
  1383. int ret;
  1384. wsa881x = swr_get_dev_data(pdev);
  1385. if (!wsa881x) {
  1386. dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__);
  1387. return -EINVAL;
  1388. }
  1389. if (delayed_work_pending(&wsa881x->ocp_ctl_work))
  1390. cancel_delayed_work_sync(&wsa881x->ocp_ctl_work);
  1391. ret = wsa881x_gpio_ctrl(wsa881x, false);
  1392. if (ret)
  1393. dev_err(&pdev->dev, "%s: Failed to disable gpio\n", __func__);
  1394. else
  1395. wsa881x->state = WSA881X_DEV_DOWN;
  1396. return ret;
  1397. }
  1398. static int wsa881x_swr_reset(struct swr_device *pdev)
  1399. {
  1400. struct wsa881x_priv *wsa881x;
  1401. u8 retry = WSA881X_NUM_RETRY;
  1402. u8 devnum = 0;
  1403. wsa881x = swr_get_dev_data(pdev);
  1404. if (!wsa881x) {
  1405. dev_err(&pdev->dev, "%s: wsa881x is NULL\n", __func__);
  1406. return -EINVAL;
  1407. }
  1408. if (wsa881x->state == WSA881X_DEV_READY) {
  1409. dev_dbg(&pdev->dev, "%s: device already active\n", __func__);
  1410. return 0;
  1411. }
  1412. wsa881x->bg_cnt = 0;
  1413. wsa881x->clk_cnt = 0;
  1414. while (swr_get_logical_dev_num(pdev, pdev->addr, &devnum) && retry--) {
  1415. /* Retry after 1 msec delay */
  1416. usleep_range(1000, 1100);
  1417. }
  1418. pdev->dev_num = devnum;
  1419. wsa881x_regcache_sync(wsa881x);
  1420. return 0;
  1421. }
  1422. #ifdef CONFIG_PM_SLEEP
  1423. static int wsa881x_swr_suspend(struct device *dev)
  1424. {
  1425. dev_dbg(dev, "%s: system suspend\n", __func__);
  1426. return 0;
  1427. }
  1428. static int wsa881x_swr_resume(struct device *dev)
  1429. {
  1430. struct wsa881x_priv *wsa881x = swr_get_dev_data(to_swr_device(dev));
  1431. if (!wsa881x) {
  1432. dev_err(dev, "%s: wsa881x private data is NULL\n", __func__);
  1433. return -EINVAL;
  1434. }
  1435. dev_dbg(dev, "%s: system resume\n", __func__);
  1436. return 0;
  1437. }
  1438. #endif /* CONFIG_PM_SLEEP */
  1439. static const struct dev_pm_ops wsa881x_swr_pm_ops = {
  1440. SET_SYSTEM_SLEEP_PM_OPS(wsa881x_swr_suspend, wsa881x_swr_resume)
  1441. };
  1442. static const struct swr_device_id wsa881x_swr_id[] = {
  1443. {"wsa881x", 0},
  1444. {}
  1445. };
  1446. static const struct of_device_id wsa881x_swr_dt_match[] = {
  1447. {
  1448. .compatible = "qcom,wsa881x",
  1449. },
  1450. {}
  1451. };
  1452. static struct swr_driver wsa881x_codec_driver = {
  1453. .driver = {
  1454. .name = "wsa881x",
  1455. .owner = THIS_MODULE,
  1456. .pm = &wsa881x_swr_pm_ops,
  1457. .of_match_table = wsa881x_swr_dt_match,
  1458. },
  1459. .probe = wsa881x_swr_probe,
  1460. .remove = wsa881x_swr_remove,
  1461. .id_table = wsa881x_swr_id,
  1462. .device_up = wsa881x_swr_up,
  1463. .device_down = wsa881x_swr_down,
  1464. .reset_device = wsa881x_swr_reset,
  1465. };
  1466. static int __init wsa881x_codec_init(void)
  1467. {
  1468. return swr_driver_register(&wsa881x_codec_driver);
  1469. }
  1470. static void __exit wsa881x_codec_exit(void)
  1471. {
  1472. swr_driver_unregister(&wsa881x_codec_driver);
  1473. }
  1474. module_init(wsa881x_codec_init);
  1475. module_exit(wsa881x_codec_exit);
  1476. MODULE_DESCRIPTION("WSA881x Codec driver");
  1477. MODULE_LICENSE("GPL v2");