msm_sdw_cdc.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/module.h>
  14. #include <linux/io.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/printk.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/bitops.h>
  20. #include <linux/regmap.h>
  21. #include <linux/delay.h>
  22. #include <linux/kernel.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/soc.h>
  26. #include <sound/soc-dapm.h>
  27. #include <sound/tlv.h>
  28. #include <ipc/apr.h>
  29. #include <soc/swr-wcd.h>
  30. #include <dsp/audio_notifier.h>
  31. #include <dsp/apr_audio-v2.h>
  32. #include <dsp/q6core.h>
  33. #include "msm_sdw.h"
  34. #include "msm_sdw_registers.h"
  35. #include "../msm-cdc-pinctrl.h"
  36. #define MSM_SDW_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  37. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
  38. #define MSM_SDW_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  39. SNDRV_PCM_FMTBIT_S24_LE |\
  40. SNDRV_PCM_FMTBIT_S24_3LE)
  41. #define MSM_SDW_STRING_LEN 80
  42. #define INT_MCLK1_FREQ 9600000
  43. #define SDW_NPL_FREQ 153600000
  44. #define MSM_SDW_VERSION_1_0 0x0001
  45. #define MSM_SDW_VERSION_ENTRY_SIZE 32
  46. /*
  47. * 200 Milliseconds sufficient for DSP bring up in the modem
  48. * after Sub System Restart
  49. */
  50. #define ADSP_STATE_READY_TIMEOUT_MS 200
  51. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  52. static struct snd_soc_dai_driver msm_sdw_dai[];
  53. static bool skip_irq = true;
  54. static int msm_sdw_config_ear_spkr_gain(struct snd_soc_codec *codec,
  55. int event, int gain_reg);
  56. static int msm_sdw_config_compander(struct snd_soc_codec *, int, int);
  57. static int msm_sdw_mclk_enable(struct msm_sdw_priv *msm_sdw,
  58. int mclk_enable, bool dapm);
  59. static int msm_int_enable_sdw_cdc_clk(struct msm_sdw_priv *msm_sdw,
  60. int enable, bool dapm);
  61. enum {
  62. VI_SENSE_1,
  63. VI_SENSE_2,
  64. };
  65. enum {
  66. AIF1_SDW_PB = 0,
  67. AIF1_SDW_VIFEED,
  68. NUM_CODEC_DAIS,
  69. };
  70. static const struct msm_sdw_reg_mask_val msm_sdw_spkr_default[] = {
  71. {MSM_SDW_COMPANDER7_CTL3, 0x80, 0x80},
  72. {MSM_SDW_COMPANDER8_CTL3, 0x80, 0x80},
  73. {MSM_SDW_COMPANDER7_CTL7, 0x01, 0x01},
  74. {MSM_SDW_COMPANDER8_CTL7, 0x01, 0x01},
  75. {MSM_SDW_BOOST0_BOOST_CTL, 0x7C, 0x50},
  76. {MSM_SDW_BOOST1_BOOST_CTL, 0x7C, 0x50},
  77. };
  78. static const struct msm_sdw_reg_mask_val msm_sdw_spkr_mode1[] = {
  79. {MSM_SDW_COMPANDER7_CTL3, 0x80, 0x00},
  80. {MSM_SDW_COMPANDER8_CTL3, 0x80, 0x00},
  81. {MSM_SDW_COMPANDER7_CTL7, 0x01, 0x00},
  82. {MSM_SDW_COMPANDER8_CTL7, 0x01, 0x00},
  83. {MSM_SDW_BOOST0_BOOST_CTL, 0x7C, 0x44},
  84. {MSM_SDW_BOOST1_BOOST_CTL, 0x7C, 0x44},
  85. };
  86. /**
  87. * msm_sdw_set_spkr_gain_offset - offset the speaker path
  88. * gain with the given offset value.
  89. *
  90. * @codec: codec instance
  91. * @offset: Indicates speaker path gain offset value.
  92. *
  93. * Returns 0 on success or -EINVAL on error.
  94. */
  95. int msm_sdw_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset)
  96. {
  97. struct msm_sdw_priv *priv;
  98. if (!codec) {
  99. pr_err("%s: NULL codec pointer!\n", __func__);
  100. return -EINVAL;
  101. }
  102. priv = snd_soc_codec_get_drvdata(codec);
  103. if (!priv)
  104. return -EINVAL;
  105. priv->spkr_gain_offset = offset;
  106. return 0;
  107. }
  108. EXPORT_SYMBOL(msm_sdw_set_spkr_gain_offset);
  109. /**
  110. * msm_sdw_set_spkr_mode - Configures speaker compander and smartboost
  111. * settings based on speaker mode.
  112. *
  113. * @codec: codec instance
  114. * @mode: Indicates speaker configuration mode.
  115. *
  116. * Returns 0 on success or -EINVAL on error.
  117. */
  118. int msm_sdw_set_spkr_mode(struct snd_soc_codec *codec, int mode)
  119. {
  120. struct msm_sdw_priv *priv;
  121. int i;
  122. const struct msm_sdw_reg_mask_val *regs;
  123. int size;
  124. if (!codec) {
  125. pr_err("%s: NULL codec pointer!\n", __func__);
  126. return -EINVAL;
  127. }
  128. priv = snd_soc_codec_get_drvdata(codec);
  129. if (!priv)
  130. return -EINVAL;
  131. switch (mode) {
  132. case SPKR_MODE_1:
  133. regs = msm_sdw_spkr_mode1;
  134. size = ARRAY_SIZE(msm_sdw_spkr_mode1);
  135. break;
  136. default:
  137. regs = msm_sdw_spkr_default;
  138. size = ARRAY_SIZE(msm_sdw_spkr_default);
  139. break;
  140. }
  141. priv->spkr_mode = mode;
  142. for (i = 0; i < size; i++)
  143. snd_soc_update_bits(codec, regs[i].reg,
  144. regs[i].mask, regs[i].val);
  145. return 0;
  146. }
  147. EXPORT_SYMBOL(msm_sdw_set_spkr_mode);
  148. static int msm_enable_sdw_npl_clk(struct msm_sdw_priv *msm_sdw, int enable)
  149. {
  150. int ret = 0;
  151. dev_dbg(msm_sdw->dev, "%s: enable %d\n", __func__, enable);
  152. mutex_lock(&msm_sdw->sdw_npl_clk_mutex);
  153. if (enable) {
  154. if (msm_sdw->sdw_npl_clk_enabled == false) {
  155. msm_sdw->sdw_npl_clk.enable = 1;
  156. ret = afe_set_lpass_clock_v2(
  157. AFE_PORT_ID_INT4_MI2S_RX,
  158. &msm_sdw->sdw_npl_clk);
  159. if (ret < 0) {
  160. dev_err(msm_sdw->dev,
  161. "%s: failed to enable SDW NPL CLK\n",
  162. __func__);
  163. mutex_unlock(&msm_sdw->sdw_npl_clk_mutex);
  164. return ret;
  165. }
  166. dev_dbg(msm_sdw->dev, "enabled sdw npl clk\n");
  167. msm_sdw->sdw_npl_clk_enabled = true;
  168. }
  169. } else {
  170. if (msm_sdw->sdw_npl_clk_enabled == true) {
  171. msm_sdw->sdw_npl_clk.enable = 0;
  172. ret = afe_set_lpass_clock_v2(
  173. AFE_PORT_ID_INT4_MI2S_RX,
  174. &msm_sdw->sdw_npl_clk);
  175. if (ret < 0)
  176. dev_err(msm_sdw->dev,
  177. "%s: failed to disable SDW NPL CLK\n",
  178. __func__);
  179. msm_sdw->sdw_npl_clk_enabled = false;
  180. }
  181. }
  182. mutex_unlock(&msm_sdw->sdw_npl_clk_mutex);
  183. return ret;
  184. }
  185. static int msm_int_enable_sdw_cdc_clk(struct msm_sdw_priv *msm_sdw,
  186. int enable, bool dapm)
  187. {
  188. int ret = 0;
  189. mutex_lock(&msm_sdw->cdc_int_mclk1_mutex);
  190. dev_dbg(msm_sdw->dev, "%s: enable %d mclk1 ref counter %d\n",
  191. __func__, enable, msm_sdw->int_mclk1_rsc_ref);
  192. if (enable) {
  193. if (msm_sdw->int_mclk1_rsc_ref == 0) {
  194. cancel_delayed_work_sync(
  195. &msm_sdw->disable_int_mclk1_work);
  196. if (msm_sdw->int_mclk1_enabled == false) {
  197. msm_sdw->sdw_cdc_core_clk.enable = 1;
  198. ret = afe_set_lpass_clock_v2(
  199. AFE_PORT_ID_INT4_MI2S_RX,
  200. &msm_sdw->sdw_cdc_core_clk);
  201. if (ret < 0) {
  202. dev_err(msm_sdw->dev,
  203. "%s: failed to enable SDW MCLK\n",
  204. __func__);
  205. goto rtn;
  206. }
  207. dev_dbg(msm_sdw->dev,
  208. "enabled sdw codec core mclk\n");
  209. msm_sdw->int_mclk1_enabled = true;
  210. }
  211. }
  212. msm_sdw->int_mclk1_rsc_ref++;
  213. } else {
  214. cancel_delayed_work_sync(&msm_sdw->disable_int_mclk1_work);
  215. if (msm_sdw->int_mclk1_rsc_ref > 0) {
  216. msm_sdw->int_mclk1_rsc_ref--;
  217. dev_dbg(msm_sdw->dev,
  218. "%s: decrementing mclk_res_ref %d\n",
  219. __func__, msm_sdw->int_mclk1_rsc_ref);
  220. }
  221. if (msm_sdw->int_mclk1_enabled == true &&
  222. msm_sdw->int_mclk1_rsc_ref == 0) {
  223. msm_sdw->sdw_cdc_core_clk.enable = 0;
  224. ret = afe_set_lpass_clock_v2(
  225. AFE_PORT_ID_INT4_MI2S_RX,
  226. &msm_sdw->sdw_cdc_core_clk);
  227. if (ret < 0)
  228. dev_err(msm_sdw->dev,
  229. "%s: failed to disable SDW MCLK\n",
  230. __func__);
  231. msm_sdw->int_mclk1_enabled = false;
  232. }
  233. }
  234. mutex_unlock(&msm_sdw->cdc_int_mclk1_mutex);
  235. rtn:
  236. return ret;
  237. }
  238. EXPORT_SYMBOL(msm_int_enable_sdw_cdc_clk);
  239. static void msm_disable_int_mclk1(struct work_struct *work)
  240. {
  241. struct msm_sdw_priv *msm_sdw = NULL;
  242. struct delayed_work *dwork;
  243. int ret = 0;
  244. dwork = to_delayed_work(work);
  245. msm_sdw = container_of(dwork, struct msm_sdw_priv,
  246. disable_int_mclk1_work);
  247. mutex_lock(&msm_sdw->cdc_int_mclk1_mutex);
  248. dev_dbg(msm_sdw->dev, "%s: mclk1_enabled %d mclk1_rsc_ref %d\n",
  249. __func__, msm_sdw->int_mclk1_enabled,
  250. msm_sdw->int_mclk1_rsc_ref);
  251. if (msm_sdw->int_mclk1_enabled == true
  252. && msm_sdw->int_mclk1_rsc_ref == 0) {
  253. dev_dbg(msm_sdw->dev, "Disable the mclk1\n");
  254. msm_sdw->sdw_cdc_core_clk.enable = 0;
  255. ret = afe_set_lpass_clock_v2(
  256. AFE_PORT_ID_INT4_MI2S_RX,
  257. &msm_sdw->sdw_cdc_core_clk);
  258. if (ret < 0)
  259. dev_err(msm_sdw->dev,
  260. "%s failed to disable the MCLK1\n",
  261. __func__);
  262. msm_sdw->int_mclk1_enabled = false;
  263. }
  264. mutex_unlock(&msm_sdw->cdc_int_mclk1_mutex);
  265. }
  266. static int msm_int_mclk1_event(struct snd_soc_dapm_widget *w,
  267. struct snd_kcontrol *kcontrol, int event)
  268. {
  269. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  270. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  271. int ret = 0;
  272. dev_dbg(msm_sdw->dev, "%s: event = %d\n", __func__, event);
  273. switch (event) {
  274. case SND_SOC_DAPM_PRE_PMU:
  275. /* enable the codec mclk config */
  276. msm_int_enable_sdw_cdc_clk(msm_sdw, 1, true);
  277. msm_sdw_mclk_enable(msm_sdw, 1, true);
  278. break;
  279. case SND_SOC_DAPM_POST_PMD:
  280. /* disable the codec mclk config */
  281. msm_sdw_mclk_enable(msm_sdw, 0, true);
  282. msm_int_enable_sdw_cdc_clk(msm_sdw, 0, true);
  283. break;
  284. default:
  285. dev_err(msm_sdw->dev,
  286. "%s: invalid DAPM event %d\n", __func__, event);
  287. ret = -EINVAL;
  288. }
  289. return ret;
  290. }
  291. static int msm_sdw_ahb_write_device(struct msm_sdw_priv *msm_sdw,
  292. u16 reg, u8 *value)
  293. {
  294. u32 temp = (u32)(*value) & 0x000000FF;
  295. if (!msm_sdw->dev_up) {
  296. dev_err_ratelimited(msm_sdw->dev, "%s: q6 not ready\n",
  297. __func__);
  298. return 0;
  299. }
  300. iowrite32(temp, msm_sdw->sdw_base + reg);
  301. return 0;
  302. }
  303. static int msm_sdw_ahb_read_device(struct msm_sdw_priv *msm_sdw,
  304. u16 reg, u8 *value)
  305. {
  306. u32 temp;
  307. if (!msm_sdw->dev_up) {
  308. dev_err_ratelimited(msm_sdw->dev, "%s: q6 not ready\n",
  309. __func__);
  310. return 0;
  311. }
  312. temp = ioread32(msm_sdw->sdw_base + reg);
  313. *value = (u8)temp;
  314. return 0;
  315. }
  316. static int __msm_sdw_reg_read(struct msm_sdw_priv *msm_sdw, unsigned short reg,
  317. int bytes, void *dest)
  318. {
  319. int ret = -EINVAL, i;
  320. u8 temp = 0;
  321. dev_dbg(msm_sdw->dev, "%s reg = %x\n", __func__, reg);
  322. mutex_lock(&msm_sdw->cdc_int_mclk1_mutex);
  323. if (msm_sdw->int_mclk1_enabled == false) {
  324. msm_sdw->sdw_cdc_core_clk.enable = 1;
  325. ret = afe_set_lpass_clock_v2(
  326. AFE_PORT_ID_INT4_MI2S_RX,
  327. &msm_sdw->sdw_cdc_core_clk);
  328. if (ret < 0) {
  329. dev_err(msm_sdw->dev,
  330. "%s:failed to enable the INT_MCLK1\n",
  331. __func__);
  332. goto unlock_exit;
  333. }
  334. dev_dbg(msm_sdw->dev, "%s:enabled sdw codec core clk\n",
  335. __func__);
  336. for (i = 0; i < bytes; i++) {
  337. ret = msm_sdw_ahb_read_device(
  338. msm_sdw, reg + (4 * i), &temp);
  339. ((u8 *)dest)[i] = temp;
  340. }
  341. msm_sdw->int_mclk1_enabled = true;
  342. schedule_delayed_work(&msm_sdw->disable_int_mclk1_work, 50);
  343. goto unlock_exit;
  344. }
  345. for (i = 0; i < bytes; i++) {
  346. ret = msm_sdw_ahb_read_device(
  347. msm_sdw, reg + (4 * i), &temp);
  348. ((u8 *)dest)[i] = temp;
  349. }
  350. unlock_exit:
  351. mutex_unlock(&msm_sdw->cdc_int_mclk1_mutex);
  352. if (ret < 0) {
  353. dev_err_ratelimited(msm_sdw->dev,
  354. "%s: codec read failed for reg 0x%x\n",
  355. __func__, reg);
  356. return ret;
  357. }
  358. dev_dbg(msm_sdw->dev, "Read 0x%02x from 0x%x\n", temp, reg);
  359. return 0;
  360. }
  361. static int __msm_sdw_reg_write(struct msm_sdw_priv *msm_sdw, unsigned short reg,
  362. int bytes, void *src)
  363. {
  364. int ret = -EINVAL, i;
  365. mutex_lock(&msm_sdw->cdc_int_mclk1_mutex);
  366. if (msm_sdw->int_mclk1_enabled == false) {
  367. msm_sdw->sdw_cdc_core_clk.enable = 1;
  368. ret = afe_set_lpass_clock_v2(AFE_PORT_ID_INT4_MI2S_RX,
  369. &msm_sdw->sdw_cdc_core_clk);
  370. if (ret < 0) {
  371. dev_err(msm_sdw->dev,
  372. "%s: failed to enable the INT_MCLK1\n",
  373. __func__);
  374. ret = 0;
  375. goto unlock_exit;
  376. }
  377. dev_dbg(msm_sdw->dev, "%s: enabled INT_MCLK1\n", __func__);
  378. for (i = 0; i < bytes; i++)
  379. ret = msm_sdw_ahb_write_device(msm_sdw, reg + (4 * i),
  380. &((u8 *)src)[i]);
  381. msm_sdw->int_mclk1_enabled = true;
  382. schedule_delayed_work(&msm_sdw->disable_int_mclk1_work, 50);
  383. goto unlock_exit;
  384. }
  385. for (i = 0; i < bytes; i++)
  386. ret = msm_sdw_ahb_write_device(msm_sdw, reg + (4 * i),
  387. &((u8 *)src)[i]);
  388. unlock_exit:
  389. mutex_unlock(&msm_sdw->cdc_int_mclk1_mutex);
  390. dev_dbg(msm_sdw->dev, "Write 0x%x val 0x%02x\n",
  391. reg, (u32)(*(u32 *)src));
  392. return ret;
  393. }
  394. static int msm_sdw_codec_enable_vi_feedback(struct snd_soc_dapm_widget *w,
  395. struct snd_kcontrol *kcontrol,
  396. int event)
  397. {
  398. struct snd_soc_codec *codec = NULL;
  399. struct msm_sdw_priv *msm_sdw_p = NULL;
  400. int ret = 0;
  401. if (!w) {
  402. pr_err("%s invalid params\n", __func__);
  403. return -EINVAL;
  404. }
  405. codec = snd_soc_dapm_to_codec(w->dapm);
  406. msm_sdw_p = snd_soc_codec_get_drvdata(codec);
  407. dev_dbg(codec->dev, "%s: num_dai %d stream name %s\n",
  408. __func__, codec->component.num_dai, w->sname);
  409. dev_dbg(codec->dev, "%s(): w->name %s event %d w->shift %d\n",
  410. __func__, w->name, event, w->shift);
  411. if (w->shift != AIF1_SDW_VIFEED) {
  412. dev_err(codec->dev,
  413. "%s:Error in enabling the vi feedback path\n",
  414. __func__);
  415. ret = -EINVAL;
  416. goto out_vi;
  417. }
  418. switch (event) {
  419. case SND_SOC_DAPM_POST_PMU:
  420. if (test_bit(VI_SENSE_1, &msm_sdw_p->status_mask)) {
  421. dev_dbg(codec->dev, "%s: spkr1 enabled\n", __func__);
  422. /* Enable V&I sensing */
  423. snd_soc_update_bits(codec,
  424. MSM_SDW_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  425. snd_soc_update_bits(codec,
  426. MSM_SDW_TX10_SPKR_PROT_PATH_CTL, 0x20,
  427. 0x20);
  428. snd_soc_update_bits(codec,
  429. MSM_SDW_TX9_SPKR_PROT_PATH_CTL, 0x0F, 0x04);
  430. snd_soc_update_bits(codec,
  431. MSM_SDW_TX10_SPKR_PROT_PATH_CTL, 0x0F, 0x04);
  432. snd_soc_update_bits(codec,
  433. MSM_SDW_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x10);
  434. snd_soc_update_bits(codec,
  435. MSM_SDW_TX10_SPKR_PROT_PATH_CTL, 0x10,
  436. 0x10);
  437. snd_soc_update_bits(codec,
  438. MSM_SDW_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x00);
  439. snd_soc_update_bits(codec,
  440. MSM_SDW_TX10_SPKR_PROT_PATH_CTL, 0x20,
  441. 0x00);
  442. }
  443. if (test_bit(VI_SENSE_2, &msm_sdw_p->status_mask)) {
  444. dev_dbg(codec->dev, "%s: spkr2 enabled\n", __func__);
  445. /* Enable V&I sensing */
  446. snd_soc_update_bits(codec,
  447. MSM_SDW_TX11_SPKR_PROT_PATH_CTL, 0x20,
  448. 0x20);
  449. snd_soc_update_bits(codec,
  450. MSM_SDW_TX12_SPKR_PROT_PATH_CTL, 0x20,
  451. 0x20);
  452. snd_soc_update_bits(codec,
  453. MSM_SDW_TX11_SPKR_PROT_PATH_CTL, 0x0F,
  454. 0x04);
  455. snd_soc_update_bits(codec,
  456. MSM_SDW_TX12_SPKR_PROT_PATH_CTL, 0x0F,
  457. 0x04);
  458. snd_soc_update_bits(codec,
  459. MSM_SDW_TX11_SPKR_PROT_PATH_CTL, 0x10,
  460. 0x10);
  461. snd_soc_update_bits(codec,
  462. MSM_SDW_TX12_SPKR_PROT_PATH_CTL, 0x10,
  463. 0x10);
  464. snd_soc_update_bits(codec,
  465. MSM_SDW_TX11_SPKR_PROT_PATH_CTL, 0x20,
  466. 0x00);
  467. snd_soc_update_bits(codec,
  468. MSM_SDW_TX12_SPKR_PROT_PATH_CTL, 0x20,
  469. 0x00);
  470. }
  471. break;
  472. case SND_SOC_DAPM_POST_PMD:
  473. if (test_bit(VI_SENSE_1, &msm_sdw_p->status_mask)) {
  474. /* Disable V&I sensing */
  475. dev_dbg(codec->dev, "%s: spkr1 disabled\n", __func__);
  476. snd_soc_update_bits(codec,
  477. MSM_SDW_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  478. snd_soc_update_bits(codec,
  479. MSM_SDW_TX10_SPKR_PROT_PATH_CTL, 0x20,
  480. 0x20);
  481. snd_soc_update_bits(codec,
  482. MSM_SDW_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x00);
  483. snd_soc_update_bits(codec,
  484. MSM_SDW_TX10_SPKR_PROT_PATH_CTL, 0x10,
  485. 0x00);
  486. }
  487. if (test_bit(VI_SENSE_2, &msm_sdw_p->status_mask)) {
  488. /* Disable V&I sensing */
  489. dev_dbg(codec->dev, "%s: spkr2 disabled\n", __func__);
  490. snd_soc_update_bits(codec,
  491. MSM_SDW_TX11_SPKR_PROT_PATH_CTL, 0x20,
  492. 0x20);
  493. snd_soc_update_bits(codec,
  494. MSM_SDW_TX12_SPKR_PROT_PATH_CTL, 0x20,
  495. 0x20);
  496. snd_soc_update_bits(codec,
  497. MSM_SDW_TX11_SPKR_PROT_PATH_CTL, 0x10,
  498. 0x00);
  499. snd_soc_update_bits(codec,
  500. MSM_SDW_TX12_SPKR_PROT_PATH_CTL, 0x10,
  501. 0x00);
  502. }
  503. break;
  504. }
  505. out_vi:
  506. return ret;
  507. }
  508. static int msm_sdwm_handle_irq(void *handle,
  509. irqreturn_t (*swrm_irq_handler)(int irq,
  510. void *data),
  511. void *swrm_handle,
  512. int action)
  513. {
  514. struct msm_sdw_priv *msm_sdw;
  515. int ret = 0;
  516. if (!handle) {
  517. pr_err("%s: null handle received\n", __func__);
  518. return -EINVAL;
  519. }
  520. msm_sdw = (struct msm_sdw_priv *) handle;
  521. if (skip_irq)
  522. return ret;
  523. if (action) {
  524. ret = request_threaded_irq(msm_sdw->sdw_irq, NULL,
  525. swrm_irq_handler,
  526. IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  527. "swr_master_irq", swrm_handle);
  528. if (ret)
  529. dev_err(msm_sdw->dev, "%s: Failed to request irq %d\n",
  530. __func__, ret);
  531. } else
  532. free_irq(msm_sdw->sdw_irq, swrm_handle);
  533. return ret;
  534. }
  535. static void msm_sdw_codec_hd2_control(struct snd_soc_codec *codec,
  536. u16 reg, int event)
  537. {
  538. u16 hd2_scale_reg;
  539. u16 hd2_enable_reg = 0;
  540. if (reg == MSM_SDW_RX7_RX_PATH_CTL) {
  541. hd2_scale_reg = MSM_SDW_RX7_RX_PATH_SEC3;
  542. hd2_enable_reg = MSM_SDW_RX7_RX_PATH_CFG0;
  543. }
  544. if (reg == MSM_SDW_RX8_RX_PATH_CTL) {
  545. hd2_scale_reg = MSM_SDW_RX8_RX_PATH_SEC3;
  546. hd2_enable_reg = MSM_SDW_RX8_RX_PATH_CFG0;
  547. }
  548. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  549. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x10);
  550. snd_soc_update_bits(codec, hd2_scale_reg, 0x03, 0x01);
  551. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  552. }
  553. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  554. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  555. snd_soc_update_bits(codec, hd2_scale_reg, 0x03, 0x00);
  556. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  557. }
  558. }
  559. static int msm_sdw_enable_swr(struct snd_soc_dapm_widget *w,
  560. struct snd_kcontrol *kcontrol, int event)
  561. {
  562. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  563. struct msm_sdw_priv *msm_sdw;
  564. int i, ch_cnt;
  565. msm_sdw = snd_soc_codec_get_drvdata(codec);
  566. if (!msm_sdw->nr)
  567. return 0;
  568. switch (event) {
  569. case SND_SOC_DAPM_PRE_PMU:
  570. if (!(strnstr(w->name, "RX4", sizeof("RX4 MIX"))) &&
  571. !msm_sdw->rx_4_count)
  572. msm_sdw->rx_4_count++;
  573. if (!(strnstr(w->name, "RX5", sizeof("RX5 MIX"))) &&
  574. !msm_sdw->rx_5_count)
  575. msm_sdw->rx_5_count++;
  576. ch_cnt = msm_sdw->rx_4_count + msm_sdw->rx_5_count;
  577. for (i = 0; i < msm_sdw->nr; i++) {
  578. swrm_wcd_notify(msm_sdw->sdw_ctrl_data[i].sdw_pdev,
  579. SWR_DEVICE_UP, NULL);
  580. swrm_wcd_notify(msm_sdw->sdw_ctrl_data[i].sdw_pdev,
  581. SWR_SET_NUM_RX_CH, &ch_cnt);
  582. }
  583. break;
  584. case SND_SOC_DAPM_POST_PMD:
  585. if (!(strnstr(w->name, "RX4", sizeof("RX4 MIX"))) &&
  586. msm_sdw->rx_4_count)
  587. msm_sdw->rx_4_count--;
  588. if (!(strnstr(w->name, "RX5", sizeof("RX5 MIX"))) &&
  589. msm_sdw->rx_5_count)
  590. msm_sdw->rx_5_count--;
  591. ch_cnt = msm_sdw->rx_4_count + msm_sdw->rx_5_count;
  592. for (i = 0; i < msm_sdw->nr; i++)
  593. swrm_wcd_notify(msm_sdw->sdw_ctrl_data[i].sdw_pdev,
  594. SWR_SET_NUM_RX_CH, &ch_cnt);
  595. break;
  596. }
  597. dev_dbg(msm_sdw->dev, "%s: current swr ch cnt: %d\n",
  598. __func__, msm_sdw->rx_4_count + msm_sdw->rx_5_count);
  599. return 0;
  600. }
  601. static int msm_sdw_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
  602. struct snd_kcontrol *kcontrol,
  603. int event)
  604. {
  605. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  606. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  607. u16 gain_reg;
  608. u16 reg;
  609. int val;
  610. int offset_val = 0;
  611. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  612. if (!(strcmp(w->name, "RX INT4 INTERP"))) {
  613. reg = MSM_SDW_RX7_RX_PATH_CTL;
  614. gain_reg = MSM_SDW_RX7_RX_VOL_CTL;
  615. } else if (!(strcmp(w->name, "RX INT5 INTERP"))) {
  616. reg = MSM_SDW_RX8_RX_PATH_CTL;
  617. gain_reg = MSM_SDW_RX8_RX_VOL_CTL;
  618. } else {
  619. dev_err(codec->dev, "%s: Interpolator reg not found\n",
  620. __func__);
  621. return -EINVAL;
  622. }
  623. switch (event) {
  624. case SND_SOC_DAPM_PRE_PMU:
  625. snd_soc_update_bits(codec, reg, 0x10, 0x10);
  626. msm_sdw_codec_hd2_control(codec, reg, event);
  627. snd_soc_update_bits(codec, reg, 1 << 0x5, 1 << 0x5);
  628. break;
  629. case SND_SOC_DAPM_POST_PMU:
  630. msm_sdw_config_compander(codec, w->shift, event);
  631. /* apply gain after int clk is enabled */
  632. if ((msm_sdw->spkr_gain_offset == RX_GAIN_OFFSET_M1P5_DB) &&
  633. (msm_sdw->comp_enabled[COMP1] ||
  634. msm_sdw->comp_enabled[COMP2]) &&
  635. (gain_reg == MSM_SDW_RX7_RX_VOL_CTL ||
  636. gain_reg == MSM_SDW_RX8_RX_VOL_CTL)) {
  637. snd_soc_update_bits(codec, MSM_SDW_RX7_RX_PATH_SEC1,
  638. 0x01, 0x01);
  639. snd_soc_update_bits(codec,
  640. MSM_SDW_RX7_RX_PATH_MIX_SEC0,
  641. 0x01, 0x01);
  642. snd_soc_update_bits(codec, MSM_SDW_RX8_RX_PATH_SEC1,
  643. 0x01, 0x01);
  644. snd_soc_update_bits(codec,
  645. MSM_SDW_RX8_RX_PATH_MIX_SEC0,
  646. 0x01, 0x01);
  647. offset_val = -2;
  648. }
  649. val = snd_soc_read(codec, gain_reg);
  650. val += offset_val;
  651. snd_soc_write(codec, gain_reg, val);
  652. msm_sdw_config_ear_spkr_gain(codec, event, gain_reg);
  653. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  654. break;
  655. case SND_SOC_DAPM_POST_PMD:
  656. snd_soc_update_bits(codec, reg, 1 << 0x5, 0 << 0x5);
  657. snd_soc_update_bits(codec, reg, 0x40, 0x40);
  658. snd_soc_update_bits(codec, reg, 0x40, 0x00);
  659. msm_sdw_codec_hd2_control(codec, reg, event);
  660. msm_sdw_config_compander(codec, w->shift, event);
  661. if ((msm_sdw->spkr_gain_offset == RX_GAIN_OFFSET_M1P5_DB) &&
  662. (msm_sdw->comp_enabled[COMP1] ||
  663. msm_sdw->comp_enabled[COMP2]) &&
  664. (gain_reg == MSM_SDW_RX7_RX_VOL_CTL ||
  665. gain_reg == MSM_SDW_RX8_RX_VOL_CTL)) {
  666. snd_soc_update_bits(codec, MSM_SDW_RX7_RX_PATH_SEC1,
  667. 0x01, 0x00);
  668. snd_soc_update_bits(codec,
  669. MSM_SDW_RX7_RX_PATH_MIX_SEC0,
  670. 0x01, 0x00);
  671. snd_soc_update_bits(codec, MSM_SDW_RX8_RX_PATH_SEC1,
  672. 0x01, 0x00);
  673. snd_soc_update_bits(codec,
  674. MSM_SDW_RX8_RX_PATH_MIX_SEC0,
  675. 0x01, 0x00);
  676. offset_val = 2;
  677. val = snd_soc_read(codec, gain_reg);
  678. val += offset_val;
  679. snd_soc_write(codec, gain_reg, val);
  680. }
  681. msm_sdw_config_ear_spkr_gain(codec, event, gain_reg);
  682. break;
  683. };
  684. return 0;
  685. }
  686. static int msm_sdw_config_ear_spkr_gain(struct snd_soc_codec *codec,
  687. int event, int gain_reg)
  688. {
  689. int comp_gain_offset, val;
  690. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  691. switch (msm_sdw->spkr_mode) {
  692. /* Compander gain in SPKR_MODE1 case is 12 dB */
  693. case SPKR_MODE_1:
  694. comp_gain_offset = -12;
  695. break;
  696. /* Default case compander gain is 15 dB */
  697. default:
  698. comp_gain_offset = -15;
  699. break;
  700. }
  701. switch (event) {
  702. case SND_SOC_DAPM_POST_PMU:
  703. /* Apply ear spkr gain only if compander is enabled */
  704. if (msm_sdw->comp_enabled[COMP1] &&
  705. (gain_reg == MSM_SDW_RX7_RX_VOL_CTL) &&
  706. (msm_sdw->ear_spkr_gain != 0)) {
  707. /* For example, val is -8(-12+5-1) for 4dB of gain */
  708. val = comp_gain_offset + msm_sdw->ear_spkr_gain - 1;
  709. snd_soc_write(codec, gain_reg, val);
  710. dev_dbg(codec->dev, "%s: RX4 Volume %d dB\n",
  711. __func__, val);
  712. }
  713. break;
  714. case SND_SOC_DAPM_POST_PMD:
  715. /*
  716. * Reset RX4 volume to 0 dB if compander is enabled and
  717. * ear_spkr_gain is non-zero.
  718. */
  719. if (msm_sdw->comp_enabled[COMP1] &&
  720. (gain_reg == MSM_SDW_RX7_RX_VOL_CTL) &&
  721. (msm_sdw->ear_spkr_gain != 0)) {
  722. snd_soc_write(codec, gain_reg, 0x0);
  723. dev_dbg(codec->dev, "%s: Reset RX4 Volume to 0 dB\n",
  724. __func__);
  725. }
  726. break;
  727. }
  728. return 0;
  729. }
  730. static int msm_sdw_codec_spk_boost_event(struct snd_soc_dapm_widget *w,
  731. struct snd_kcontrol *kcontrol,
  732. int event)
  733. {
  734. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  735. u16 boost_path_ctl, boost_path_cfg1;
  736. u16 reg;
  737. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  738. if (!strcmp(w->name, "RX INT4 CHAIN")) {
  739. boost_path_ctl = MSM_SDW_BOOST0_BOOST_PATH_CTL;
  740. boost_path_cfg1 = MSM_SDW_RX7_RX_PATH_CFG1;
  741. reg = MSM_SDW_RX7_RX_PATH_CTL;
  742. } else if (!strcmp(w->name, "RX INT5 CHAIN")) {
  743. boost_path_ctl = MSM_SDW_BOOST1_BOOST_PATH_CTL;
  744. boost_path_cfg1 = MSM_SDW_RX8_RX_PATH_CFG1;
  745. reg = MSM_SDW_RX8_RX_PATH_CTL;
  746. } else {
  747. dev_err(codec->dev, "%s: boost reg not found\n",
  748. __func__);
  749. return -EINVAL;
  750. }
  751. switch (event) {
  752. case SND_SOC_DAPM_PRE_PMU:
  753. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x10);
  754. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x01);
  755. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  756. break;
  757. case SND_SOC_DAPM_POST_PMD:
  758. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x00);
  759. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x00);
  760. break;
  761. };
  762. return 0;
  763. }
  764. static int msm_sdw_config_compander(struct snd_soc_codec *codec, int comp,
  765. int event)
  766. {
  767. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  768. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  769. if (comp < COMP1 || comp >= COMP_MAX)
  770. return 0;
  771. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  772. __func__, event, comp + 1, msm_sdw->comp_enabled[comp]);
  773. if (!msm_sdw->comp_enabled[comp])
  774. return 0;
  775. comp_ctl0_reg = MSM_SDW_COMPANDER7_CTL0 + (comp * 0x20);
  776. rx_path_cfg0_reg = MSM_SDW_RX7_RX_PATH_CFG0 + (comp * 0x1E0);
  777. if (SND_SOC_DAPM_EVENT_ON(event)) {
  778. /* Enable Compander Clock */
  779. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  780. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  781. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  782. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  783. }
  784. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  785. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  786. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  787. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  788. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  789. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  790. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  791. }
  792. return 0;
  793. }
  794. static int msm_sdw_get_compander(struct snd_kcontrol *kcontrol,
  795. struct snd_ctl_elem_value *ucontrol)
  796. {
  797. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  798. int comp = ((struct soc_multi_mixer_control *)
  799. kcontrol->private_value)->shift;
  800. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  801. ucontrol->value.integer.value[0] = msm_sdw->comp_enabled[comp];
  802. return 0;
  803. }
  804. static int msm_sdw_set_compander(struct snd_kcontrol *kcontrol,
  805. struct snd_ctl_elem_value *ucontrol)
  806. {
  807. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  808. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  809. int comp = ((struct soc_multi_mixer_control *)
  810. kcontrol->private_value)->shift;
  811. int value = ucontrol->value.integer.value[0];
  812. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  813. __func__, comp + 1, msm_sdw->comp_enabled[comp], value);
  814. msm_sdw->comp_enabled[comp] = value;
  815. return 0;
  816. }
  817. static int msm_sdw_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
  818. struct snd_ctl_elem_value *ucontrol)
  819. {
  820. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  821. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  822. ucontrol->value.integer.value[0] = msm_sdw->ear_spkr_gain;
  823. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  824. __func__, ucontrol->value.integer.value[0]);
  825. return 0;
  826. }
  827. static int msm_sdw_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
  828. struct snd_ctl_elem_value *ucontrol)
  829. {
  830. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  831. struct msm_sdw_priv *msm_sdw = snd_soc_codec_get_drvdata(codec);
  832. msm_sdw->ear_spkr_gain = ucontrol->value.integer.value[0];
  833. dev_dbg(codec->dev, "%s: gain = %d\n", __func__,
  834. msm_sdw->ear_spkr_gain);
  835. return 0;
  836. }
  837. static int msm_sdw_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  838. struct snd_ctl_elem_value *ucontrol)
  839. {
  840. struct snd_soc_dapm_widget *widget =
  841. snd_soc_dapm_kcontrol_widget(kcontrol);
  842. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  843. struct msm_sdw_priv *msm_sdw_p = snd_soc_codec_get_drvdata(codec);
  844. ucontrol->value.integer.value[0] = msm_sdw_p->vi_feed_value;
  845. return 0;
  846. }
  847. static int msm_sdw_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  848. struct snd_ctl_elem_value *ucontrol)
  849. {
  850. struct snd_soc_dapm_widget *widget =
  851. snd_soc_dapm_kcontrol_widget(kcontrol);
  852. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  853. struct msm_sdw_priv *msm_sdw_p = snd_soc_codec_get_drvdata(codec);
  854. struct soc_multi_mixer_control *mixer =
  855. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  856. u32 dai_id = widget->shift;
  857. u32 port_id = mixer->shift;
  858. u32 enable = ucontrol->value.integer.value[0];
  859. dev_dbg(codec->dev, "%s: enable: %d, port_id:%d, dai_id: %d\n",
  860. __func__, enable, port_id, dai_id);
  861. msm_sdw_p->vi_feed_value = ucontrol->value.integer.value[0];
  862. mutex_lock(&msm_sdw_p->codec_mutex);
  863. if (enable) {
  864. if (port_id == MSM_SDW_TX0 && !test_bit(VI_SENSE_1,
  865. &msm_sdw_p->status_mask))
  866. set_bit(VI_SENSE_1, &msm_sdw_p->status_mask);
  867. if (port_id == MSM_SDW_TX1 && !test_bit(VI_SENSE_2,
  868. &msm_sdw_p->status_mask))
  869. set_bit(VI_SENSE_2, &msm_sdw_p->status_mask);
  870. } else {
  871. if (port_id == MSM_SDW_TX0 && test_bit(VI_SENSE_1,
  872. &msm_sdw_p->status_mask))
  873. clear_bit(VI_SENSE_1, &msm_sdw_p->status_mask);
  874. if (port_id == MSM_SDW_TX1 && test_bit(VI_SENSE_2,
  875. &msm_sdw_p->status_mask))
  876. clear_bit(VI_SENSE_2, &msm_sdw_p->status_mask);
  877. }
  878. mutex_unlock(&msm_sdw_p->codec_mutex);
  879. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  880. return 0;
  881. }
  882. static int msm_sdw_mclk_enable(struct msm_sdw_priv *msm_sdw,
  883. int mclk_enable, bool dapm)
  884. {
  885. dev_dbg(msm_sdw->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  886. __func__, mclk_enable, dapm, msm_sdw->sdw_mclk_users);
  887. if (mclk_enable) {
  888. msm_sdw->sdw_mclk_users++;
  889. if (msm_sdw->sdw_mclk_users == 1) {
  890. regmap_update_bits(msm_sdw->regmap,
  891. MSM_SDW_CLK_RST_CTRL_FS_CNT_CONTROL,
  892. 0x01, 0x01);
  893. regmap_update_bits(msm_sdw->regmap,
  894. MSM_SDW_CLK_RST_CTRL_MCLK_CONTROL,
  895. 0x01, 0x01);
  896. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  897. regmap_update_bits(msm_sdw->regmap,
  898. MSM_SDW_TOP_FREQ_MCLK, 0x01, 0x01);
  899. }
  900. } else {
  901. msm_sdw->sdw_mclk_users--;
  902. if (msm_sdw->sdw_mclk_users == 0) {
  903. regmap_update_bits(msm_sdw->regmap,
  904. MSM_SDW_CLK_RST_CTRL_FS_CNT_CONTROL,
  905. 0x01, 0x00);
  906. regmap_update_bits(msm_sdw->regmap,
  907. MSM_SDW_CLK_RST_CTRL_MCLK_CONTROL,
  908. 0x01, 0x00);
  909. }
  910. }
  911. return 0;
  912. }
  913. EXPORT_SYMBOL(msm_sdw_mclk_enable);
  914. static int msm_sdw_swrm_read(void *handle, int reg)
  915. {
  916. struct msm_sdw_priv *msm_sdw;
  917. unsigned short sdw_rd_addr_base;
  918. unsigned short sdw_rd_data_base;
  919. int val, ret;
  920. if (!handle) {
  921. pr_err("%s: NULL handle\n", __func__);
  922. return -EINVAL;
  923. }
  924. msm_sdw = (struct msm_sdw_priv *)handle;
  925. dev_dbg(msm_sdw->dev, "%s: Reading soundwire register, 0x%x\n",
  926. __func__, reg);
  927. sdw_rd_addr_base = MSM_SDW_AHB_BRIDGE_RD_ADDR_0;
  928. sdw_rd_data_base = MSM_SDW_AHB_BRIDGE_RD_DATA_0;
  929. /*
  930. * Add sleep as SWR slave access read takes time.
  931. * Allow for RD_DONE to complete for previous register if any.
  932. */
  933. usleep_range(100, 105);
  934. /* read_lock */
  935. mutex_lock(&msm_sdw->sdw_read_lock);
  936. ret = regmap_bulk_write(msm_sdw->regmap, sdw_rd_addr_base,
  937. (u8 *)&reg, 4);
  938. if (ret < 0) {
  939. dev_err(msm_sdw->dev, "%s: RD Addr Failure\n", __func__);
  940. goto err;
  941. }
  942. /* Add sleep for SWR register read value to get updated. */
  943. usleep_range(100, 105);
  944. /* Check for RD value */
  945. ret = regmap_bulk_read(msm_sdw->regmap, sdw_rd_data_base,
  946. (u8 *)&val, 4);
  947. if (ret < 0) {
  948. dev_err(msm_sdw->dev, "%s: RD Data Failure\n", __func__);
  949. goto err;
  950. }
  951. ret = val;
  952. err:
  953. /* read_unlock */
  954. mutex_unlock(&msm_sdw->sdw_read_lock);
  955. return ret;
  956. }
  957. static int msm_sdw_bulk_write(struct msm_sdw_priv *msm_sdw,
  958. struct msm_sdw_reg_val *bulk_reg,
  959. size_t len)
  960. {
  961. int i, ret = 0;
  962. unsigned short sdw_wr_addr_base;
  963. unsigned short sdw_wr_data_base;
  964. sdw_wr_addr_base = MSM_SDW_AHB_BRIDGE_WR_ADDR_0;
  965. sdw_wr_data_base = MSM_SDW_AHB_BRIDGE_WR_DATA_0;
  966. for (i = 0; i < len; i += 2) {
  967. /*
  968. * Add sleep as SWR slave write takes time.
  969. * Allow for any previous pending write to complete.
  970. */
  971. usleep_range(100, 105);
  972. /* First Write the Data to register */
  973. ret = regmap_bulk_write(msm_sdw->regmap,
  974. sdw_wr_data_base, bulk_reg[i].buf, 4);
  975. if (ret < 0) {
  976. dev_err(msm_sdw->dev, "%s: WR Data Failure\n",
  977. __func__);
  978. break;
  979. }
  980. /* Next Write Address */
  981. ret = regmap_bulk_write(msm_sdw->regmap,
  982. sdw_wr_addr_base, bulk_reg[i+1].buf, 4);
  983. if (ret < 0) {
  984. dev_err(msm_sdw->dev,
  985. "%s: WR Addr Failure: 0x%x\n",
  986. __func__, (u32)(bulk_reg[i+1].buf[0]));
  987. break;
  988. }
  989. }
  990. return ret;
  991. }
  992. static int msm_sdw_swrm_bulk_write(void *handle, u32 *reg, u32 *val, size_t len)
  993. {
  994. struct msm_sdw_priv *msm_sdw;
  995. struct msm_sdw_reg_val *bulk_reg;
  996. unsigned short sdw_wr_addr_base;
  997. unsigned short sdw_wr_data_base;
  998. int i, j, ret;
  999. if (!handle) {
  1000. pr_err("%s: NULL handle\n", __func__);
  1001. return -EINVAL;
  1002. }
  1003. msm_sdw = (struct msm_sdw_priv *)handle;
  1004. if (len <= 0) {
  1005. dev_err(msm_sdw->dev,
  1006. "%s: Invalid size: %zu\n", __func__, len);
  1007. return -EINVAL;
  1008. }
  1009. sdw_wr_addr_base = MSM_SDW_AHB_BRIDGE_WR_ADDR_0;
  1010. sdw_wr_data_base = MSM_SDW_AHB_BRIDGE_WR_DATA_0;
  1011. bulk_reg = kzalloc((2 * len * sizeof(struct msm_sdw_reg_val)),
  1012. GFP_KERNEL);
  1013. if (!bulk_reg)
  1014. return -ENOMEM;
  1015. for (i = 0, j = 0; i < (len * 2); i += 2, j++) {
  1016. bulk_reg[i].reg = sdw_wr_data_base;
  1017. bulk_reg[i].buf = (u8 *)(&val[j]);
  1018. bulk_reg[i].bytes = 4;
  1019. bulk_reg[i+1].reg = sdw_wr_addr_base;
  1020. bulk_reg[i+1].buf = (u8 *)(&reg[j]);
  1021. bulk_reg[i+1].bytes = 4;
  1022. }
  1023. mutex_lock(&msm_sdw->sdw_write_lock);
  1024. ret = msm_sdw_bulk_write(msm_sdw, bulk_reg, (len * 2));
  1025. if (ret)
  1026. dev_err(msm_sdw->dev, "%s: swrm bulk write failed, ret: %d\n",
  1027. __func__, ret);
  1028. mutex_unlock(&msm_sdw->sdw_write_lock);
  1029. kfree(bulk_reg);
  1030. return ret;
  1031. }
  1032. static int msm_sdw_swrm_write(void *handle, int reg, int val)
  1033. {
  1034. struct msm_sdw_priv *msm_sdw;
  1035. unsigned short sdw_wr_addr_base;
  1036. unsigned short sdw_wr_data_base;
  1037. struct msm_sdw_reg_val bulk_reg[2];
  1038. int ret;
  1039. if (!handle) {
  1040. pr_err("%s: NULL handle\n", __func__);
  1041. return -EINVAL;
  1042. }
  1043. msm_sdw = (struct msm_sdw_priv *)handle;
  1044. sdw_wr_addr_base = MSM_SDW_AHB_BRIDGE_WR_ADDR_0;
  1045. sdw_wr_data_base = MSM_SDW_AHB_BRIDGE_WR_DATA_0;
  1046. /* First Write the Data to register */
  1047. bulk_reg[0].reg = sdw_wr_data_base;
  1048. bulk_reg[0].buf = (u8 *)(&val);
  1049. bulk_reg[0].bytes = 4;
  1050. bulk_reg[1].reg = sdw_wr_addr_base;
  1051. bulk_reg[1].buf = (u8 *)(&reg);
  1052. bulk_reg[1].bytes = 4;
  1053. mutex_lock(&msm_sdw->sdw_write_lock);
  1054. ret = msm_sdw_bulk_write(msm_sdw, bulk_reg, 2);
  1055. if (ret < 0)
  1056. dev_err(msm_sdw->dev, "%s: WR Data Failure\n", __func__);
  1057. mutex_unlock(&msm_sdw->sdw_write_lock);
  1058. return ret;
  1059. }
  1060. static int msm_sdw_swrm_clock(void *handle, bool enable)
  1061. {
  1062. struct msm_sdw_priv *msm_sdw = (struct msm_sdw_priv *) handle;
  1063. mutex_lock(&msm_sdw->sdw_clk_lock);
  1064. dev_dbg(msm_sdw->dev, "%s: swrm clock %s\n",
  1065. __func__, (enable ? "enable" : "disable"));
  1066. if (enable) {
  1067. msm_sdw->sdw_clk_users++;
  1068. if (msm_sdw->sdw_clk_users == 1) {
  1069. msm_int_enable_sdw_cdc_clk(msm_sdw, 1, true);
  1070. msm_sdw_mclk_enable(msm_sdw, 1, true);
  1071. regmap_update_bits(msm_sdw->regmap,
  1072. MSM_SDW_CLK_RST_CTRL_SWR_CONTROL, 0x01, 0x01);
  1073. msm_enable_sdw_npl_clk(msm_sdw, true);
  1074. msm_cdc_pinctrl_select_active_state(
  1075. msm_sdw->sdw_gpio_p);
  1076. }
  1077. } else {
  1078. msm_sdw->sdw_clk_users--;
  1079. if (msm_sdw->sdw_clk_users == 0) {
  1080. regmap_update_bits(msm_sdw->regmap,
  1081. MSM_SDW_CLK_RST_CTRL_SWR_CONTROL,
  1082. 0x01, 0x00);
  1083. msm_sdw_mclk_enable(msm_sdw, 0, true);
  1084. msm_int_enable_sdw_cdc_clk(msm_sdw, 0, true);
  1085. msm_enable_sdw_npl_clk(msm_sdw, false);
  1086. msm_cdc_pinctrl_select_sleep_state(msm_sdw->sdw_gpio_p);
  1087. }
  1088. }
  1089. dev_dbg(msm_sdw->dev, "%s: swrm clock users %d\n",
  1090. __func__, msm_sdw->sdw_clk_users);
  1091. mutex_unlock(&msm_sdw->sdw_clk_lock);
  1092. return 0;
  1093. }
  1094. static int msm_sdw_startup(struct snd_pcm_substream *substream,
  1095. struct snd_soc_dai *dai)
  1096. {
  1097. dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
  1098. __func__,
  1099. substream->name, substream->stream);
  1100. return 0;
  1101. }
  1102. static int msm_sdw_hw_params(struct snd_pcm_substream *substream,
  1103. struct snd_pcm_hw_params *params,
  1104. struct snd_soc_dai *dai)
  1105. {
  1106. u8 clk_fs_rate, fs_rate;
  1107. dev_dbg(dai->codec->dev,
  1108. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d format %d\n",
  1109. __func__, dai->name, dai->id, params_rate(params),
  1110. params_channels(params), params_format(params));
  1111. switch (params_rate(params)) {
  1112. case 8000:
  1113. clk_fs_rate = 0x00;
  1114. fs_rate = 0x00;
  1115. break;
  1116. case 16000:
  1117. clk_fs_rate = 0x01;
  1118. fs_rate = 0x01;
  1119. break;
  1120. case 32000:
  1121. clk_fs_rate = 0x02;
  1122. fs_rate = 0x03;
  1123. break;
  1124. case 48000:
  1125. clk_fs_rate = 0x03;
  1126. fs_rate = 0x04;
  1127. break;
  1128. case 96000:
  1129. clk_fs_rate = 0x04;
  1130. fs_rate = 0x05;
  1131. break;
  1132. case 192000:
  1133. clk_fs_rate = 0x05;
  1134. fs_rate = 0x06;
  1135. break;
  1136. default:
  1137. dev_err(dai->codec->dev,
  1138. "%s: Invalid sampling rate %d\n", __func__,
  1139. params_rate(params));
  1140. return -EINVAL;
  1141. }
  1142. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  1143. snd_soc_update_bits(dai->codec,
  1144. MSM_SDW_TOP_TX_I2S_CTL, 0x1C,
  1145. (clk_fs_rate << 2));
  1146. } else {
  1147. snd_soc_update_bits(dai->codec,
  1148. MSM_SDW_TOP_RX_I2S_CTL, 0x1C,
  1149. (clk_fs_rate << 2));
  1150. snd_soc_update_bits(dai->codec,
  1151. MSM_SDW_RX7_RX_PATH_CTL, 0x0F,
  1152. fs_rate);
  1153. snd_soc_update_bits(dai->codec,
  1154. MSM_SDW_RX8_RX_PATH_CTL, 0x0F,
  1155. fs_rate);
  1156. }
  1157. switch (params_format(params)) {
  1158. case SNDRV_PCM_FORMAT_S16_LE:
  1159. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  1160. snd_soc_update_bits(dai->codec,
  1161. MSM_SDW_TOP_TX_I2S_CTL, 0x20, 0x20);
  1162. else
  1163. snd_soc_update_bits(dai->codec,
  1164. MSM_SDW_TOP_RX_I2S_CTL, 0x20, 0x20);
  1165. break;
  1166. case SNDRV_PCM_FORMAT_S24_LE:
  1167. case SNDRV_PCM_FORMAT_S24_3LE:
  1168. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  1169. snd_soc_update_bits(dai->codec,
  1170. MSM_SDW_TOP_TX_I2S_CTL, 0x20, 0x00);
  1171. else
  1172. snd_soc_update_bits(dai->codec,
  1173. MSM_SDW_TOP_RX_I2S_CTL, 0x20, 0x00);
  1174. break;
  1175. default:
  1176. dev_err(dai->codec->dev, "%s: wrong format selected\n",
  1177. __func__);
  1178. return -EINVAL;
  1179. }
  1180. return 0;
  1181. }
  1182. static void msm_sdw_shutdown(struct snd_pcm_substream *substream,
  1183. struct snd_soc_dai *dai)
  1184. {
  1185. dev_dbg(dai->codec->dev,
  1186. "%s(): substream = %s stream = %d\n", __func__,
  1187. substream->name, substream->stream);
  1188. }
  1189. static ssize_t msm_sdw_codec_version_read(struct snd_info_entry *entry,
  1190. void *file_private_data,
  1191. struct file *file,
  1192. char __user *buf, size_t count,
  1193. loff_t pos)
  1194. {
  1195. struct msm_sdw_priv *msm_sdw;
  1196. char buffer[MSM_SDW_VERSION_ENTRY_SIZE];
  1197. int len = 0;
  1198. msm_sdw = (struct msm_sdw_priv *) entry->private_data;
  1199. if (!msm_sdw) {
  1200. pr_err("%s: msm_sdw priv is null\n", __func__);
  1201. return -EINVAL;
  1202. }
  1203. switch (msm_sdw->version) {
  1204. case MSM_SDW_VERSION_1_0:
  1205. len = snprintf(buffer, sizeof(buffer), "SDW-CDC_1_0\n");
  1206. break;
  1207. default:
  1208. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  1209. }
  1210. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  1211. }
  1212. static struct snd_info_entry_ops msm_sdw_codec_info_ops = {
  1213. .read = msm_sdw_codec_version_read,
  1214. };
  1215. /*
  1216. * msm_sdw_codec_info_create_codec_entry - creates msm_sdw module
  1217. * @codec_root: The parent directory
  1218. * @codec: Codec instance
  1219. *
  1220. * Creates msm_sdw module and version entry under the given
  1221. * parent directory.
  1222. *
  1223. * Return: 0 on success or negative error code on failure.
  1224. */
  1225. int msm_sdw_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  1226. struct snd_soc_codec *codec)
  1227. {
  1228. struct snd_info_entry *version_entry;
  1229. struct msm_sdw_priv *msm_sdw;
  1230. struct snd_soc_card *card;
  1231. if (!codec_root || !codec)
  1232. return -EINVAL;
  1233. msm_sdw = snd_soc_codec_get_drvdata(codec);
  1234. card = codec->component.card;
  1235. msm_sdw->entry = snd_info_create_subdir(codec_root->module,
  1236. "152c1000.msm-sdw-codec",
  1237. codec_root);
  1238. if (!msm_sdw->entry) {
  1239. dev_err(codec->dev, "%s: failed to create msm_sdw entry\n",
  1240. __func__);
  1241. return -ENOMEM;
  1242. }
  1243. version_entry = snd_info_create_card_entry(card->snd_card,
  1244. "version",
  1245. msm_sdw->entry);
  1246. if (!version_entry) {
  1247. dev_err(codec->dev, "%s: failed to create msm_sdw version entry\n",
  1248. __func__);
  1249. return -ENOMEM;
  1250. }
  1251. version_entry->private_data = msm_sdw;
  1252. version_entry->size = MSM_SDW_VERSION_ENTRY_SIZE;
  1253. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  1254. version_entry->c.ops = &msm_sdw_codec_info_ops;
  1255. if (snd_info_register(version_entry) < 0) {
  1256. snd_info_free_entry(version_entry);
  1257. return -ENOMEM;
  1258. }
  1259. msm_sdw->version_entry = version_entry;
  1260. return 0;
  1261. }
  1262. EXPORT_SYMBOL(msm_sdw_codec_info_create_codec_entry);
  1263. static struct snd_soc_dai_ops msm_sdw_dai_ops = {
  1264. .startup = msm_sdw_startup,
  1265. .shutdown = msm_sdw_shutdown,
  1266. .hw_params = msm_sdw_hw_params,
  1267. };
  1268. static struct snd_soc_dai_driver msm_sdw_dai[] = {
  1269. {
  1270. .name = "msm_sdw_i2s_rx1",
  1271. .id = AIF1_SDW_PB,
  1272. .playback = {
  1273. .stream_name = "AIF1_SDW Playback",
  1274. .rates = MSM_SDW_RATES,
  1275. .formats = MSM_SDW_FORMATS,
  1276. .rate_max = 192000,
  1277. .rate_min = 8000,
  1278. .channels_min = 1,
  1279. .channels_max = 4,
  1280. },
  1281. .ops = &msm_sdw_dai_ops,
  1282. },
  1283. {
  1284. .name = "msm_sdw_vifeedback",
  1285. .id = AIF1_SDW_VIFEED,
  1286. .capture = {
  1287. .stream_name = "VIfeed_SDW",
  1288. .rates = MSM_SDW_RATES,
  1289. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1290. .rate_max = 48000,
  1291. .rate_min = 8000,
  1292. .channels_min = 2,
  1293. .channels_max = 4,
  1294. },
  1295. .ops = &msm_sdw_dai_ops,
  1296. },
  1297. };
  1298. static const char * const rx_mix1_text[] = {
  1299. "ZERO", "RX4", "RX5"
  1300. };
  1301. static const char * const msm_sdw_ear_spkr_pa_gain_text[] = {
  1302. "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
  1303. "G_4_DB", "G_5_DB", "G_6_DB"
  1304. };
  1305. static SOC_ENUM_SINGLE_EXT_DECL(msm_sdw_ear_spkr_pa_gain_enum,
  1306. msm_sdw_ear_spkr_pa_gain_text);
  1307. /* RX4 MIX1 */
  1308. static const struct soc_enum rx4_mix1_inp1_chain_enum =
  1309. SOC_ENUM_SINGLE(MSM_SDW_TOP_RX7_PATH_INPUT0_MUX,
  1310. 0, 3, rx_mix1_text);
  1311. static const struct soc_enum rx4_mix1_inp2_chain_enum =
  1312. SOC_ENUM_SINGLE(MSM_SDW_TOP_RX7_PATH_INPUT1_MUX,
  1313. 0, 3, rx_mix1_text);
  1314. /* RX5 MIX1 */
  1315. static const struct soc_enum rx5_mix1_inp1_chain_enum =
  1316. SOC_ENUM_SINGLE(MSM_SDW_TOP_RX8_PATH_INPUT0_MUX,
  1317. 0, 3, rx_mix1_text);
  1318. static const struct soc_enum rx5_mix1_inp2_chain_enum =
  1319. SOC_ENUM_SINGLE(MSM_SDW_TOP_RX8_PATH_INPUT1_MUX,
  1320. 0, 3, rx_mix1_text);
  1321. static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
  1322. SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
  1323. static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
  1324. SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
  1325. static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
  1326. SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
  1327. static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
  1328. SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
  1329. static const struct snd_kcontrol_new aif1_vi_mixer[] = {
  1330. SOC_SINGLE_EXT("SPKR_VI_1", SND_SOC_NOPM, MSM_SDW_TX0, 1, 0,
  1331. msm_sdw_vi_feed_mixer_get, msm_sdw_vi_feed_mixer_put),
  1332. SOC_SINGLE_EXT("SPKR_VI_2", SND_SOC_NOPM, MSM_SDW_TX1, 1, 0,
  1333. msm_sdw_vi_feed_mixer_get, msm_sdw_vi_feed_mixer_put),
  1334. };
  1335. static const struct snd_soc_dapm_widget msm_sdw_dapm_widgets[] = {
  1336. SND_SOC_DAPM_AIF_IN("I2S RX4", "AIF1_SDW Playback", 0,
  1337. SND_SOC_NOPM, 0, 0),
  1338. SND_SOC_DAPM_AIF_IN("I2S RX5", "AIF1_SDW Playback", 0,
  1339. SND_SOC_NOPM, 0, 0),
  1340. SND_SOC_DAPM_AIF_OUT_E("AIF1_SDW VI", "VIfeed_SDW", 0, SND_SOC_NOPM,
  1341. AIF1_SDW_VIFEED, 0, msm_sdw_codec_enable_vi_feedback,
  1342. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1343. SND_SOC_DAPM_MIXER("AIF1_VI_SDW Mixer", SND_SOC_NOPM, AIF1_SDW_VIFEED,
  1344. 0, aif1_vi_mixer, ARRAY_SIZE(aif1_vi_mixer)),
  1345. SND_SOC_DAPM_MUX_E("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  1346. &rx4_mix1_inp1_mux, msm_sdw_enable_swr,
  1347. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1348. SND_SOC_DAPM_MUX_E("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  1349. &rx4_mix1_inp2_mux, msm_sdw_enable_swr,
  1350. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1351. SND_SOC_DAPM_MUX_E("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  1352. &rx5_mix1_inp1_mux, msm_sdw_enable_swr,
  1353. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1354. SND_SOC_DAPM_MUX_E("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  1355. &rx5_mix1_inp2_mux, msm_sdw_enable_swr,
  1356. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1357. SND_SOC_DAPM_MIXER("RX4 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1358. SND_SOC_DAPM_MIXER("RX5 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1359. SND_SOC_DAPM_MIXER_E("RX INT4 INTERP", SND_SOC_NOPM,
  1360. COMP1, 0, NULL, 0, msm_sdw_codec_enable_interpolator,
  1361. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1362. SND_SOC_DAPM_POST_PMD),
  1363. SND_SOC_DAPM_MIXER_E("RX INT5 INTERP", SND_SOC_NOPM,
  1364. COMP2, 0, NULL, 0, msm_sdw_codec_enable_interpolator,
  1365. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1366. SND_SOC_DAPM_POST_PMD),
  1367. SND_SOC_DAPM_MIXER_E("RX INT4 CHAIN", SND_SOC_NOPM, 0, 0,
  1368. NULL, 0, msm_sdw_codec_spk_boost_event,
  1369. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1370. SND_SOC_DAPM_MIXER_E("RX INT5 CHAIN", SND_SOC_NOPM, 0, 0,
  1371. NULL, 0, msm_sdw_codec_spk_boost_event,
  1372. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1373. SND_SOC_DAPM_INPUT("VIINPUT_SDW"),
  1374. SND_SOC_DAPM_OUTPUT("SPK1 OUT"),
  1375. SND_SOC_DAPM_OUTPUT("SPK2 OUT"),
  1376. SND_SOC_DAPM_SUPPLY_S("SDW_CONN", -1, MSM_SDW_TOP_I2S_CLK,
  1377. 0, 0, NULL, 0),
  1378. SND_SOC_DAPM_SUPPLY_S("INT_MCLK1", -2, SND_SOC_NOPM, 0, 0,
  1379. msm_int_mclk1_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1380. SND_SOC_DAPM_SUPPLY("SDW_RX_I2S_CLK",
  1381. MSM_SDW_TOP_RX_I2S_CTL, 0, 0, NULL, 0),
  1382. SND_SOC_DAPM_SUPPLY("SDW_TX_I2S_CLK",
  1383. MSM_SDW_TOP_TX_I2S_CTL, 0, 0, NULL, 0),
  1384. };
  1385. static const struct snd_kcontrol_new msm_sdw_snd_controls[] = {
  1386. SOC_ENUM_EXT("EAR SPKR PA Gain", msm_sdw_ear_spkr_pa_gain_enum,
  1387. msm_sdw_ear_spkr_pa_gain_get,
  1388. msm_sdw_ear_spkr_pa_gain_put),
  1389. SOC_SINGLE_SX_TLV("RX4 Digital Volume", MSM_SDW_RX7_RX_VOL_CTL,
  1390. 0, -84, 40, digital_gain),
  1391. SOC_SINGLE_SX_TLV("RX5 Digital Volume", MSM_SDW_RX8_RX_VOL_CTL,
  1392. 0, -84, 40, digital_gain),
  1393. SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMP1, 1, 0,
  1394. msm_sdw_get_compander, msm_sdw_set_compander),
  1395. SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMP2, 1, 0,
  1396. msm_sdw_get_compander, msm_sdw_set_compander),
  1397. };
  1398. static const struct snd_soc_dapm_route audio_map[] = {
  1399. {"AIF1_SDW VI", NULL, "SDW_TX_I2S_CLK"},
  1400. {"SDW_TX_I2S_CLK", NULL, "INT_MCLK1"},
  1401. {"SDW_TX_I2S_CLK", NULL, "SDW_CONN"},
  1402. /* VI Feedback */
  1403. {"AIF1_VI_SDW Mixer", "SPKR_VI_1", "VIINPUT_SDW"},
  1404. {"AIF1_VI_SDW Mixer", "SPKR_VI_2", "VIINPUT_SDW"},
  1405. {"AIF1_SDW VI", NULL, "AIF1_VI_SDW Mixer"},
  1406. {"SDW_RX_I2S_CLK", NULL, "INT_MCLK1"},
  1407. {"SDW_RX_I2S_CLK", NULL, "SDW_CONN"},
  1408. {"I2S RX4", NULL, "SDW_RX_I2S_CLK"},
  1409. {"I2S RX5", NULL, "SDW_RX_I2S_CLK"},
  1410. {"RX4 MIX1 INP1", "RX4", "I2S RX4"},
  1411. {"RX4 MIX1 INP1", "RX5", "I2S RX5"},
  1412. {"RX4 MIX1 INP2", "RX4", "I2S RX4"},
  1413. {"RX4 MIX1 INP2", "RX5", "I2S RX5"},
  1414. {"RX5 MIX1 INP1", "RX4", "I2S RX4"},
  1415. {"RX5 MIX1 INP1", "RX5", "I2S RX5"},
  1416. {"RX5 MIX1 INP2", "RX4", "I2S RX4"},
  1417. {"RX5 MIX1 INP2", "RX5", "I2S RX5"},
  1418. {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
  1419. {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
  1420. {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
  1421. {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
  1422. {"RX INT4 INTERP", NULL, "RX4 MIX1"},
  1423. {"RX INT4 CHAIN", NULL, "RX INT4 INTERP"},
  1424. {"SPK1 OUT", NULL, "RX INT4 CHAIN"},
  1425. {"RX INT5 INTERP", NULL, "RX5 MIX1"},
  1426. {"RX INT5 CHAIN", NULL, "RX INT5 INTERP"},
  1427. {"SPK2 OUT", NULL, "RX INT5 CHAIN"},
  1428. };
  1429. static const struct msm_sdw_reg_mask_val msm_sdw_reg_init[] = {
  1430. {MSM_SDW_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  1431. {MSM_SDW_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  1432. {MSM_SDW_COMPANDER7_CTL7, 0x1E, 0x18},
  1433. {MSM_SDW_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  1434. {MSM_SDW_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  1435. {MSM_SDW_COMPANDER8_CTL7, 0x1E, 0x18},
  1436. {MSM_SDW_BOOST0_BOOST_CTL, 0x70, 0x50},
  1437. {MSM_SDW_BOOST1_BOOST_CTL, 0x70, 0x50},
  1438. {MSM_SDW_RX7_RX_PATH_CFG1, 0x08, 0x08},
  1439. {MSM_SDW_RX8_RX_PATH_CFG1, 0x08, 0x08},
  1440. {MSM_SDW_TOP_TOP_CFG1, 0x02, 0x02},
  1441. {MSM_SDW_TOP_TOP_CFG1, 0x01, 0x01},
  1442. {MSM_SDW_TX9_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1443. {MSM_SDW_TX10_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1444. {MSM_SDW_TX11_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1445. {MSM_SDW_TX12_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1446. {MSM_SDW_COMPANDER7_CTL3, 0x80, 0x80},
  1447. {MSM_SDW_COMPANDER8_CTL3, 0x80, 0x80},
  1448. {MSM_SDW_COMPANDER7_CTL7, 0x01, 0x01},
  1449. {MSM_SDW_COMPANDER8_CTL7, 0x01, 0x01},
  1450. {MSM_SDW_RX7_RX_PATH_CFG0, 0x01, 0x01},
  1451. {MSM_SDW_RX8_RX_PATH_CFG0, 0x01, 0x01},
  1452. {MSM_SDW_RX7_RX_PATH_MIX_CFG, 0x01, 0x01},
  1453. {MSM_SDW_RX8_RX_PATH_MIX_CFG, 0x01, 0x01},
  1454. };
  1455. static void msm_sdw_init_reg(struct snd_soc_codec *codec)
  1456. {
  1457. int i;
  1458. for (i = 0; i < ARRAY_SIZE(msm_sdw_reg_init); i++)
  1459. snd_soc_update_bits(codec,
  1460. msm_sdw_reg_init[i].reg,
  1461. msm_sdw_reg_init[i].mask,
  1462. msm_sdw_reg_init[i].val);
  1463. }
  1464. static int msm_sdw_notifier_service_cb(struct notifier_block *nb,
  1465. unsigned long opcode, void *ptr)
  1466. {
  1467. int i;
  1468. struct msm_sdw_priv *msm_sdw = container_of(nb,
  1469. struct msm_sdw_priv,
  1470. service_nb);
  1471. bool adsp_ready = false;
  1472. unsigned long timeout;
  1473. static bool initial_boot = true;
  1474. pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode);
  1475. mutex_lock(&msm_sdw->codec_mutex);
  1476. switch (opcode) {
  1477. case AUDIO_NOTIFIER_SERVICE_DOWN:
  1478. if (initial_boot) {
  1479. initial_boot = false;
  1480. break;
  1481. }
  1482. msm_sdw->int_mclk1_enabled = false;
  1483. msm_sdw->dev_up = false;
  1484. for (i = 0; i < msm_sdw->nr; i++)
  1485. swrm_wcd_notify(msm_sdw->sdw_ctrl_data[i].sdw_pdev,
  1486. SWR_DEVICE_DOWN, NULL);
  1487. break;
  1488. case AUDIO_NOTIFIER_SERVICE_UP:
  1489. if (initial_boot)
  1490. initial_boot = false;
  1491. if (!q6core_is_adsp_ready()) {
  1492. dev_dbg(msm_sdw->dev, "ADSP isn't ready\n");
  1493. timeout = jiffies +
  1494. msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
  1495. while (!time_after(jiffies, timeout)) {
  1496. if (!q6core_is_adsp_ready()) {
  1497. dev_dbg(msm_sdw->dev,
  1498. "ADSP isn't ready\n");
  1499. } else {
  1500. dev_dbg(msm_sdw->dev,
  1501. "ADSP is ready\n");
  1502. adsp_ready = true;
  1503. goto powerup;
  1504. }
  1505. }
  1506. } else {
  1507. adsp_ready = true;
  1508. dev_dbg(msm_sdw->dev, "%s: DSP is ready\n", __func__);
  1509. }
  1510. powerup:
  1511. if (adsp_ready) {
  1512. msm_sdw->dev_up = true;
  1513. msm_sdw_init_reg(msm_sdw->codec);
  1514. regcache_mark_dirty(msm_sdw->regmap);
  1515. regcache_sync(msm_sdw->regmap);
  1516. msm_sdw_set_spkr_mode(msm_sdw->codec,
  1517. msm_sdw->spkr_mode);
  1518. }
  1519. break;
  1520. default:
  1521. break;
  1522. }
  1523. mutex_unlock(&msm_sdw->codec_mutex);
  1524. return NOTIFY_OK;
  1525. }
  1526. static int msm_sdw_codec_probe(struct snd_soc_codec *codec)
  1527. {
  1528. struct msm_sdw_priv *msm_sdw;
  1529. int i, ret;
  1530. msm_sdw = snd_soc_codec_get_drvdata(codec);
  1531. if (!msm_sdw) {
  1532. pr_err("%s:SDW priv data null\n", __func__);
  1533. return -EINVAL;
  1534. }
  1535. msm_sdw->codec = codec;
  1536. for (i = 0; i < COMP_MAX; i++)
  1537. msm_sdw->comp_enabled[i] = 0;
  1538. msm_sdw->spkr_gain_offset = RX_GAIN_OFFSET_0_DB;
  1539. msm_sdw_init_reg(codec);
  1540. msm_sdw->version = MSM_SDW_VERSION_1_0;
  1541. msm_sdw->service_nb.notifier_call = msm_sdw_notifier_service_cb;
  1542. ret = audio_notifier_register("msm_sdw",
  1543. AUDIO_NOTIFIER_ADSP_DOMAIN,
  1544. &msm_sdw->service_nb);
  1545. if (ret < 0)
  1546. dev_err(msm_sdw->dev,
  1547. "%s: Audio notifier register failed ret = %d\n",
  1548. __func__, ret);
  1549. return 0;
  1550. }
  1551. static int msm_sdw_codec_remove(struct snd_soc_codec *codec)
  1552. {
  1553. return 0;
  1554. }
  1555. static struct regmap *msm_sdw_get_regmap(struct device *dev)
  1556. {
  1557. struct msm_sdw_priv *msm_sdw = dev_get_drvdata(dev);
  1558. return msm_sdw->regmap;
  1559. }
  1560. static struct snd_soc_codec_driver soc_codec_dev_msm_sdw = {
  1561. .probe = msm_sdw_codec_probe,
  1562. .remove = msm_sdw_codec_remove,
  1563. .get_regmap = msm_sdw_get_regmap,
  1564. .component_driver = {
  1565. .controls = msm_sdw_snd_controls,
  1566. .num_controls = ARRAY_SIZE(msm_sdw_snd_controls),
  1567. .dapm_widgets = msm_sdw_dapm_widgets,
  1568. .num_dapm_widgets = ARRAY_SIZE(msm_sdw_dapm_widgets),
  1569. .dapm_routes = audio_map,
  1570. .num_dapm_routes = ARRAY_SIZE(audio_map),
  1571. },
  1572. };
  1573. static void msm_sdw_add_child_devices(struct work_struct *work)
  1574. {
  1575. struct msm_sdw_priv *msm_sdw;
  1576. struct platform_device *pdev;
  1577. struct device_node *node;
  1578. struct msm_sdw_ctrl_data *sdw_ctrl_data = NULL, *temp;
  1579. int ret, ctrl_num = 0;
  1580. struct wcd_sdw_ctrl_platform_data *platdata;
  1581. char plat_dev_name[MSM_SDW_STRING_LEN];
  1582. msm_sdw = container_of(work, struct msm_sdw_priv,
  1583. msm_sdw_add_child_devices_work);
  1584. if (!msm_sdw) {
  1585. pr_err("%s: Memory for msm_sdw does not exist\n",
  1586. __func__);
  1587. return;
  1588. }
  1589. if (!msm_sdw->dev->of_node) {
  1590. dev_err(msm_sdw->dev,
  1591. "%s: DT node for msm_sdw does not exist\n", __func__);
  1592. return;
  1593. }
  1594. platdata = &msm_sdw->sdw_plat_data;
  1595. for_each_available_child_of_node(msm_sdw->dev->of_node, node) {
  1596. if (!strcmp(node->name, "swr_master"))
  1597. strlcpy(plat_dev_name, "msm_sdw_swr_ctrl",
  1598. (MSM_SDW_STRING_LEN - 1));
  1599. else if (strnstr(node->name, "msm_cdc_pinctrl",
  1600. strlen("msm_cdc_pinctrl")) != NULL)
  1601. strlcpy(plat_dev_name, node->name,
  1602. (MSM_SDW_STRING_LEN - 1));
  1603. else
  1604. continue;
  1605. pdev = platform_device_alloc(plat_dev_name, -1);
  1606. if (!pdev) {
  1607. dev_err(msm_sdw->dev, "%s: pdev memory alloc failed\n",
  1608. __func__);
  1609. ret = -ENOMEM;
  1610. goto err;
  1611. }
  1612. pdev->dev.parent = msm_sdw->dev;
  1613. pdev->dev.of_node = node;
  1614. if (!strcmp(node->name, "swr_master")) {
  1615. ret = platform_device_add_data(pdev, platdata,
  1616. sizeof(*platdata));
  1617. if (ret) {
  1618. dev_err(&pdev->dev,
  1619. "%s: cannot add plat data ctrl:%d\n",
  1620. __func__, ctrl_num);
  1621. goto fail_pdev_add;
  1622. }
  1623. }
  1624. ret = platform_device_add(pdev);
  1625. if (ret) {
  1626. dev_err(&pdev->dev,
  1627. "%s: Cannot add platform device\n",
  1628. __func__);
  1629. goto fail_pdev_add;
  1630. }
  1631. if (!strcmp(node->name, "swr_master")) {
  1632. temp = krealloc(sdw_ctrl_data,
  1633. (ctrl_num + 1) * sizeof(
  1634. struct msm_sdw_ctrl_data),
  1635. GFP_KERNEL);
  1636. if (!temp) {
  1637. dev_err(&pdev->dev, "out of memory\n");
  1638. ret = -ENOMEM;
  1639. goto err;
  1640. }
  1641. sdw_ctrl_data = temp;
  1642. sdw_ctrl_data[ctrl_num].sdw_pdev = pdev;
  1643. ctrl_num++;
  1644. dev_dbg(&pdev->dev,
  1645. "%s: Added soundwire ctrl device(s)\n",
  1646. __func__);
  1647. msm_sdw->nr = ctrl_num;
  1648. msm_sdw->sdw_ctrl_data = sdw_ctrl_data;
  1649. }
  1650. }
  1651. return;
  1652. fail_pdev_add:
  1653. platform_device_put(pdev);
  1654. err:
  1655. return;
  1656. }
  1657. static int msm_sdw_probe(struct platform_device *pdev)
  1658. {
  1659. int ret = 0;
  1660. struct msm_sdw_priv *msm_sdw;
  1661. int adsp_state;
  1662. adsp_state = apr_get_subsys_state();
  1663. if (adsp_state != APR_SUBSYS_LOADED) {
  1664. dev_err(&pdev->dev, "Adsp is not loaded yet %d\n",
  1665. adsp_state);
  1666. return -EPROBE_DEFER;
  1667. }
  1668. msm_sdw = devm_kzalloc(&pdev->dev, sizeof(struct msm_sdw_priv),
  1669. GFP_KERNEL);
  1670. if (!msm_sdw)
  1671. return -ENOMEM;
  1672. dev_set_drvdata(&pdev->dev, msm_sdw);
  1673. msm_sdw->dev_up = true;
  1674. msm_sdw->dev = &pdev->dev;
  1675. INIT_WORK(&msm_sdw->msm_sdw_add_child_devices_work,
  1676. msm_sdw_add_child_devices);
  1677. msm_sdw->sdw_plat_data.handle = (void *) msm_sdw;
  1678. msm_sdw->sdw_plat_data.read = msm_sdw_swrm_read;
  1679. msm_sdw->sdw_plat_data.write = msm_sdw_swrm_write;
  1680. msm_sdw->sdw_plat_data.bulk_write = msm_sdw_swrm_bulk_write;
  1681. msm_sdw->sdw_plat_data.clk = msm_sdw_swrm_clock;
  1682. msm_sdw->sdw_plat_data.handle_irq = msm_sdwm_handle_irq;
  1683. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1684. &msm_sdw->sdw_base_addr);
  1685. if (ret) {
  1686. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1687. __func__, "reg");
  1688. goto err_sdw_cdc;
  1689. }
  1690. msm_sdw->sdw_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1691. "qcom,cdc-sdw-gpios", 0);
  1692. msm_sdw->sdw_base = ioremap(msm_sdw->sdw_base_addr,
  1693. MSM_SDW_MAX_REGISTER);
  1694. msm_sdw->read_dev = __msm_sdw_reg_read;
  1695. msm_sdw->write_dev = __msm_sdw_reg_write;
  1696. msm_sdw->regmap = msm_sdw_regmap_init(msm_sdw->dev,
  1697. &msm_sdw_regmap_config);
  1698. msm_sdw->sdw_irq = platform_get_irq_byname(pdev, "swr_master_irq");
  1699. if (msm_sdw->sdw_irq < 0) {
  1700. dev_err(msm_sdw->dev, "%s() error getting irq handle: %d\n",
  1701. __func__, msm_sdw->sdw_irq);
  1702. ret = -ENODEV;
  1703. goto err_sdw_cdc;
  1704. }
  1705. ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_msm_sdw,
  1706. msm_sdw_dai, ARRAY_SIZE(msm_sdw_dai));
  1707. if (ret) {
  1708. dev_err(&pdev->dev, "%s: Codec registration failed, ret = %d\n",
  1709. __func__, ret);
  1710. goto err_sdw_cdc;
  1711. }
  1712. /* initialize the int_mclk1 */
  1713. msm_sdw->sdw_cdc_core_clk.clk_set_minor_version =
  1714. AFE_API_VERSION_I2S_CONFIG;
  1715. msm_sdw->sdw_cdc_core_clk.clk_id =
  1716. Q6AFE_LPASS_CLK_ID_INT_MCLK_1;
  1717. msm_sdw->sdw_cdc_core_clk.clk_freq_in_hz =
  1718. INT_MCLK1_FREQ;
  1719. msm_sdw->sdw_cdc_core_clk.clk_attri =
  1720. Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO;
  1721. msm_sdw->sdw_cdc_core_clk.clk_root =
  1722. Q6AFE_LPASS_CLK_ROOT_DEFAULT;
  1723. msm_sdw->sdw_cdc_core_clk.enable = 0;
  1724. /* initialize the sdw_npl_clk */
  1725. msm_sdw->sdw_npl_clk.clk_set_minor_version =
  1726. AFE_API_VERSION_I2S_CONFIG;
  1727. msm_sdw->sdw_npl_clk.clk_id =
  1728. AFE_CLOCK_SET_CLOCK_ID_SWR_NPL_CLK;
  1729. msm_sdw->sdw_npl_clk.clk_freq_in_hz = SDW_NPL_FREQ;
  1730. msm_sdw->sdw_npl_clk.clk_attri =
  1731. Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO;
  1732. msm_sdw->sdw_npl_clk.clk_root =
  1733. Q6AFE_LPASS_CLK_ROOT_DEFAULT;
  1734. msm_sdw->sdw_npl_clk.enable = 0;
  1735. INIT_DELAYED_WORK(&msm_sdw->disable_int_mclk1_work,
  1736. msm_disable_int_mclk1);
  1737. mutex_init(&msm_sdw->cdc_int_mclk1_mutex);
  1738. mutex_init(&msm_sdw->sdw_npl_clk_mutex);
  1739. mutex_init(&msm_sdw->io_lock);
  1740. mutex_init(&msm_sdw->sdw_read_lock);
  1741. mutex_init(&msm_sdw->sdw_write_lock);
  1742. mutex_init(&msm_sdw->sdw_clk_lock);
  1743. mutex_init(&msm_sdw->codec_mutex);
  1744. schedule_work(&msm_sdw->msm_sdw_add_child_devices_work);
  1745. dev_dbg(&pdev->dev, "%s: msm_sdw driver probe done\n", __func__);
  1746. return ret;
  1747. err_sdw_cdc:
  1748. devm_kfree(&pdev->dev, msm_sdw);
  1749. return ret;
  1750. }
  1751. static int msm_sdw_remove(struct platform_device *pdev)
  1752. {
  1753. struct msm_sdw_priv *msm_sdw;
  1754. msm_sdw = dev_get_drvdata(&pdev->dev);
  1755. mutex_destroy(&msm_sdw->io_lock);
  1756. mutex_destroy(&msm_sdw->sdw_read_lock);
  1757. mutex_destroy(&msm_sdw->sdw_write_lock);
  1758. mutex_destroy(&msm_sdw->sdw_clk_lock);
  1759. mutex_destroy(&msm_sdw->codec_mutex);
  1760. mutex_destroy(&msm_sdw->cdc_int_mclk1_mutex);
  1761. devm_kfree(&pdev->dev, msm_sdw);
  1762. snd_soc_unregister_codec(&pdev->dev);
  1763. return 0;
  1764. }
  1765. static const struct of_device_id msm_sdw_codec_dt_match[] = {
  1766. { .compatible = "qcom,msm-sdw-codec", },
  1767. {}
  1768. };
  1769. static struct platform_driver msm_sdw_codec_driver = {
  1770. .probe = msm_sdw_probe,
  1771. .remove = msm_sdw_remove,
  1772. .driver = {
  1773. .name = "msm_sdw_codec",
  1774. .owner = THIS_MODULE,
  1775. .of_match_table = msm_sdw_codec_dt_match,
  1776. },
  1777. };
  1778. module_platform_driver(msm_sdw_codec_driver);
  1779. MODULE_DESCRIPTION("MSM Soundwire Codec driver");
  1780. MODULE_LICENSE("GPL v2");