kona.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/slab.h>
  11. #include <linux/io.h>
  12. #include <linux/module.h>
  13. #include <linux/input.h>
  14. #include <linux/of_device.h>
  15. #include <linux/soc/qcom/fsa4480-i2c.h>
  16. #include <sound/core.h>
  17. #include <sound/soc.h>
  18. #include <sound/soc-dapm.h>
  19. #include <sound/pcm.h>
  20. #include <sound/pcm_params.h>
  21. #include <sound/info.h>
  22. #include <soc/snd_event.h>
  23. #include <dsp/audio_prm.h>
  24. #include <soc/swr-common.h>
  25. #include "device_event.h"
  26. #include "asoc/msm-cdc-pinctrl.h"
  27. #include "asoc/wcd-mbhc-v2.h"
  28. #include "codecs/wcd938x/wcd938x-mbhc.h"
  29. #include "codecs/wsa881x.h"
  30. #include "codecs/wcd938x/wcd938x.h"
  31. #include "codecs/bolero/bolero-cdc.h"
  32. #include <dt-bindings/sound/audio-codec-port-types.h>
  33. #include "codecs/bolero/wsa-macro.h"
  34. #include "kona-port-config.h"
  35. #include "msm-audio-defs.h"
  36. #define DRV_NAME "kona-asoc-snd"
  37. #define __CHIPSET__ "KONA "
  38. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  39. #define SAMPLING_RATE_8KHZ 8000
  40. #define SAMPLING_RATE_11P025KHZ 11025
  41. #define SAMPLING_RATE_16KHZ 16000
  42. #define SAMPLING_RATE_22P05KHZ 22050
  43. #define SAMPLING_RATE_32KHZ 32000
  44. #define SAMPLING_RATE_44P1KHZ 44100
  45. #define SAMPLING_RATE_48KHZ 48000
  46. #define SAMPLING_RATE_88P2KHZ 88200
  47. #define SAMPLING_RATE_96KHZ 96000
  48. #define SAMPLING_RATE_176P4KHZ 176400
  49. #define SAMPLING_RATE_192KHZ 192000
  50. #define SAMPLING_RATE_352P8KHZ 352800
  51. #define SAMPLING_RATE_384KHZ 384000
  52. #define WCD9XXX_MBHC_DEF_RLOADS 5
  53. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  54. #define CODEC_EXT_CLK_RATE 9600000
  55. #define ADSP_STATE_READY_TIMEOUT_MS 3000
  56. #define DEV_NAME_STR_LEN 32
  57. #define WCD_MBHC_HS_V_MAX 1600
  58. #define TDM_CHANNEL_MAX 8
  59. #define DEV_NAME_STR_LEN 32
  60. #define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
  61. #define ADSP_STATE_READY_TIMEOUT_MS 3000
  62. #define WSA8810_NAME_1 "wsa881x.20170211"
  63. #define WSA8810_NAME_2 "wsa881x.20170212"
  64. #define WCN_CDC_SLIM_RX_CH_MAX 2
  65. #define WCN_CDC_SLIM_TX_CH_MAX 2
  66. #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
  67. enum {
  68. RX_PATH = 0,
  69. TX_PATH,
  70. MAX_PATH,
  71. };
  72. enum {
  73. TDM_0 = 0,
  74. TDM_1,
  75. TDM_2,
  76. TDM_3,
  77. TDM_4,
  78. TDM_5,
  79. TDM_6,
  80. TDM_7,
  81. TDM_PORT_MAX,
  82. };
  83. #define TDM_MAX_SLOTS 8
  84. #define TDM_SLOT_WIDTH_BITS 32
  85. enum {
  86. TDM_PRI = 0,
  87. TDM_SEC,
  88. TDM_TERT,
  89. TDM_QUAT,
  90. TDM_QUIN,
  91. TDM_SEN,
  92. TDM_INTERFACE_MAX,
  93. };
  94. enum {
  95. PRIM_AUX_PCM = 0,
  96. SEC_AUX_PCM,
  97. TERT_AUX_PCM,
  98. QUAT_AUX_PCM,
  99. QUIN_AUX_PCM,
  100. SEN_AUX_PCM,
  101. AUX_PCM_MAX,
  102. };
  103. enum {
  104. PRIM_MI2S = 0,
  105. SEC_MI2S,
  106. TERT_MI2S,
  107. QUAT_MI2S,
  108. QUIN_MI2S,
  109. SEN_MI2S,
  110. MI2S_MAX,
  111. };
  112. enum {
  113. WSA_CDC_DMA_RX_0 = 0,
  114. WSA_CDC_DMA_RX_1,
  115. RX_CDC_DMA_RX_0,
  116. RX_CDC_DMA_RX_1,
  117. RX_CDC_DMA_RX_2,
  118. RX_CDC_DMA_RX_3,
  119. RX_CDC_DMA_RX_5,
  120. CDC_DMA_RX_MAX,
  121. };
  122. enum {
  123. WSA_CDC_DMA_TX_0 = 0,
  124. WSA_CDC_DMA_TX_1,
  125. WSA_CDC_DMA_TX_2,
  126. TX_CDC_DMA_TX_0,
  127. TX_CDC_DMA_TX_3,
  128. TX_CDC_DMA_TX_4,
  129. VA_CDC_DMA_TX_0,
  130. VA_CDC_DMA_TX_1,
  131. VA_CDC_DMA_TX_2,
  132. CDC_DMA_TX_MAX,
  133. };
  134. enum {
  135. SLIM_RX_7 = 0,
  136. SLIM_RX_MAX,
  137. };
  138. enum {
  139. SLIM_TX_7 = 0,
  140. SLIM_TX_8,
  141. SLIM_TX_MAX,
  142. };
  143. enum {
  144. AFE_LOOPBACK_TX_IDX = 0,
  145. AFE_LOOPBACK_TX_IDX_MAX,
  146. };
  147. struct msm_asoc_mach_data {
  148. struct snd_info_entry *codec_root;
  149. int usbc_en2_gpio; /* used by gpio driver API */
  150. int lito_v2_enabled;
  151. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  152. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  153. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  154. struct device_node *mi2s_gpio_p[MI2S_MAX]; /* used by pinctrl API */
  155. atomic_t mi2s_gpio_ref_count[MI2S_MAX]; /* used by pinctrl API */
  156. struct device_node *us_euro_gpio_p; /* used by pinctrl API */
  157. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  158. struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
  159. struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
  160. bool is_afe_config_done;
  161. struct device_node *fsa_handle;
  162. };
  163. struct tdm_port {
  164. u32 mode;
  165. u32 channel;
  166. };
  167. struct tdm_dev_config {
  168. unsigned int tdm_slot_offset[TDM_MAX_SLOTS];
  169. };
  170. enum {
  171. EXT_DISP_RX_IDX_DP = 0,
  172. EXT_DISP_RX_IDX_DP1,
  173. EXT_DISP_RX_IDX_MAX,
  174. };
  175. struct msm_wsa881x_dev_info {
  176. struct device_node *of_node;
  177. u32 index;
  178. };
  179. struct aux_codec_dev_info {
  180. struct device_node *of_node;
  181. u32 index;
  182. };
  183. struct dev_config {
  184. u32 sample_rate;
  185. u32 bit_format;
  186. u32 channels;
  187. };
  188. struct mi2s_conf {
  189. struct mutex lock;
  190. u32 ref_cnt;
  191. u32 msm_is_mi2s_master;
  192. };
  193. static const char *const vi_feed_ch_text[] = {"One", "Two"};
  194. static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE",
  195. "S32_LE"};
  196. static char const *cdc80_bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE"};
  197. static const char *const cdc_dma_rx_ch_text[] = {"One", "Two"};
  198. static const char *const cdc_dma_tx_ch_text[] = {"One", "Two", "Three", "Four",
  199. "Five", "Six", "Seven",
  200. "Eight"};
  201. static char const *cdc_dma_sample_rate_text[] = {"KHZ_8", "KHZ_11P025",
  202. "KHZ_16", "KHZ_22P05",
  203. "KHZ_32", "KHZ_44P1", "KHZ_48",
  204. "KHZ_88P2", "KHZ_96",
  205. "KHZ_176P4", "KHZ_192",
  206. "KHZ_352P8", "KHZ_384"};
  207. static char const *cdc80_dma_sample_rate_text[] = {"KHZ_8", "KHZ_11P025",
  208. "KHZ_16", "KHZ_22P05",
  209. "KHZ_32", "KHZ_44P1", "KHZ_48",
  210. "KHZ_88P2", "KHZ_96",
  211. "KHZ_176P4", "KHZ_192"};
  212. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_0_chs, cdc_dma_rx_ch_text);
  213. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_1_chs, cdc_dma_rx_ch_text);
  214. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_0_chs, cdc_dma_rx_ch_text);
  215. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_1_chs, cdc_dma_rx_ch_text);
  216. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_2_chs, cdc_dma_rx_ch_text);
  217. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_3_chs, cdc_dma_rx_ch_text);
  218. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc_dma_rx_5_chs, cdc_dma_rx_ch_text);
  219. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_0_chs, cdc_dma_tx_ch_text);
  220. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_1_chs, cdc_dma_tx_ch_text);
  221. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_2_chs, cdc_dma_tx_ch_text);
  222. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_0_chs, cdc_dma_tx_ch_text);
  223. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_3_chs, cdc_dma_tx_ch_text);
  224. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_4_chs, cdc_dma_tx_ch_text);
  225. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_0_chs, cdc_dma_tx_ch_text);
  226. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_1_chs, cdc_dma_tx_ch_text);
  227. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_2_chs, cdc_dma_tx_ch_text);
  228. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_0_format, bit_format_text);
  229. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_1_format, bit_format_text);
  230. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_1_format, bit_format_text);
  231. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_2_format, bit_format_text);
  232. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_0_format, bit_format_text);
  233. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_3_format, bit_format_text);
  234. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_4_format, bit_format_text);
  235. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_0_format, bit_format_text);
  236. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_1_format, bit_format_text);
  237. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_2_format, bit_format_text);
  238. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_0_sample_rate,
  239. cdc_dma_sample_rate_text);
  240. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_rx_1_sample_rate,
  241. cdc_dma_sample_rate_text);
  242. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_0_sample_rate,
  243. cdc_dma_sample_rate_text);
  244. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_1_sample_rate,
  245. cdc_dma_sample_rate_text);
  246. static SOC_ENUM_SINGLE_EXT_DECL(wsa_cdc_dma_tx_2_sample_rate,
  247. cdc_dma_sample_rate_text);
  248. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_0_sample_rate,
  249. cdc_dma_sample_rate_text);
  250. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_3_sample_rate,
  251. cdc_dma_sample_rate_text);
  252. static SOC_ENUM_SINGLE_EXT_DECL(tx_cdc_dma_tx_4_sample_rate,
  253. cdc_dma_sample_rate_text);
  254. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_0_sample_rate,
  255. cdc_dma_sample_rate_text);
  256. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_1_sample_rate,
  257. cdc_dma_sample_rate_text);
  258. static SOC_ENUM_SINGLE_EXT_DECL(va_cdc_dma_tx_2_sample_rate,
  259. cdc_dma_sample_rate_text);
  260. /* WCD9380 */
  261. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_0_format, cdc80_bit_format_text);
  262. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_1_format, cdc80_bit_format_text);
  263. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_2_format, cdc80_bit_format_text);
  264. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_3_format, cdc80_bit_format_text);
  265. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_5_format, cdc80_bit_format_text);
  266. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_0_sample_rate,
  267. cdc80_dma_sample_rate_text);
  268. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_1_sample_rate,
  269. cdc80_dma_sample_rate_text);
  270. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_2_sample_rate,
  271. cdc80_dma_sample_rate_text);
  272. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_3_sample_rate,
  273. cdc80_dma_sample_rate_text);
  274. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc80_dma_rx_5_sample_rate,
  275. cdc80_dma_sample_rate_text);
  276. /* WCD9385 */
  277. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_0_format, bit_format_text);
  278. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_1_format, bit_format_text);
  279. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_2_format, bit_format_text);
  280. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_3_format, bit_format_text);
  281. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_5_format, bit_format_text);
  282. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_0_sample_rate,
  283. cdc_dma_sample_rate_text);
  284. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_1_sample_rate,
  285. cdc_dma_sample_rate_text);
  286. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_2_sample_rate,
  287. cdc_dma_sample_rate_text);
  288. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_3_sample_rate,
  289. cdc_dma_sample_rate_text);
  290. static SOC_ENUM_SINGLE_EXT_DECL(rx_cdc85_dma_rx_5_sample_rate,
  291. cdc_dma_sample_rate_text);
  292. static bool is_initial_boot;
  293. static bool codec_reg_done;
  294. static struct snd_soc_aux_dev *msm_aux_dev;
  295. static struct snd_soc_codec_conf *msm_codec_conf;
  296. static struct snd_soc_card snd_soc_card_kona_msm;
  297. static int dmic_0_1_gpio_cnt;
  298. static int dmic_2_3_gpio_cnt;
  299. static int dmic_4_5_gpio_cnt;
  300. static void *def_wcd_mbhc_cal(void);
  301. /*
  302. * Need to report LINEIN
  303. * if R/L channel impedance is larger than 5K ohm
  304. */
  305. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  306. .read_fw_bin = false,
  307. .calibration = NULL,
  308. .detect_extn_cable = true,
  309. .mono_stero_detection = false,
  310. .swap_gnd_mic = NULL,
  311. .hs_ext_micbias = true,
  312. .key_code[0] = KEY_MEDIA,
  313. .key_code[1] = KEY_VOICECOMMAND,
  314. .key_code[2] = KEY_VOLUMEUP,
  315. .key_code[3] = KEY_VOLUMEDOWN,
  316. .key_code[4] = 0,
  317. .key_code[5] = 0,
  318. .key_code[6] = 0,
  319. .key_code[7] = 0,
  320. .linein_th = 5000,
  321. .moisture_en = false,
  322. .mbhc_micbias = MIC_BIAS_2,
  323. .anc_micbias = MIC_BIAS_2,
  324. .enable_anc_mic_detect = false,
  325. .moisture_duty_cycle_en = true,
  326. };
  327. static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  328. struct snd_pcm_hw_params *params)
  329. {
  330. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  331. int rc = 0;
  332. pr_debug("%s: dai_id= %d, format = %d, rate = %d\n",
  333. __func__, dai_link->id, params_format(params),
  334. params_rate(params));
  335. return rc;
  336. }
  337. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  338. {
  339. struct snd_soc_card *card = component->card;
  340. struct msm_asoc_mach_data *pdata =
  341. snd_soc_card_get_drvdata(card);
  342. if (!pdata->fsa_handle)
  343. return false;
  344. return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  345. }
  346. static bool msm_swap_gnd_mic(struct snd_soc_component *component, bool active)
  347. {
  348. int value = 0;
  349. bool ret = false;
  350. struct snd_soc_card *card;
  351. struct msm_asoc_mach_data *pdata;
  352. if (!component) {
  353. pr_err("%s component is NULL\n", __func__);
  354. return false;
  355. }
  356. card = component->card;
  357. pdata = snd_soc_card_get_drvdata(card);
  358. if (!pdata)
  359. return false;
  360. if (wcd_mbhc_cfg.enable_usbc_analog)
  361. return msm_usbc_swap_gnd_mic(component, active);
  362. /* if usbc is not defined, swap using us_euro_gpio_p */
  363. if (pdata->us_euro_gpio_p) {
  364. value = msm_cdc_pinctrl_get_state(
  365. pdata->us_euro_gpio_p);
  366. if (value)
  367. msm_cdc_pinctrl_select_sleep_state(
  368. pdata->us_euro_gpio_p);
  369. else
  370. msm_cdc_pinctrl_select_active_state(
  371. pdata->us_euro_gpio_p);
  372. dev_dbg(component->dev, "%s: swap select switch %d to %d\n",
  373. __func__, value, !value);
  374. ret = true;
  375. }
  376. return ret;
  377. }
  378. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  379. struct snd_kcontrol *kcontrol, int event)
  380. {
  381. struct msm_asoc_mach_data *pdata = NULL;
  382. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  383. int ret = 0;
  384. u32 dmic_idx;
  385. int *dmic_gpio_cnt;
  386. struct device_node *dmic_gpio;
  387. char *wname;
  388. wname = strpbrk(w->name, "012345");
  389. if (!wname) {
  390. dev_err(component->dev, "%s: widget not found\n", __func__);
  391. return -EINVAL;
  392. }
  393. ret = kstrtouint(wname, 10, &dmic_idx);
  394. if (ret < 0) {
  395. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  396. __func__);
  397. return -EINVAL;
  398. }
  399. pdata = snd_soc_card_get_drvdata(component->card);
  400. switch (dmic_idx) {
  401. case 0:
  402. case 1:
  403. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  404. dmic_gpio = pdata->dmic01_gpio_p;
  405. break;
  406. case 2:
  407. case 3:
  408. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  409. dmic_gpio = pdata->dmic23_gpio_p;
  410. break;
  411. case 4:
  412. case 5:
  413. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  414. dmic_gpio = pdata->dmic45_gpio_p;
  415. break;
  416. default:
  417. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  418. __func__);
  419. return -EINVAL;
  420. }
  421. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  422. __func__, event, dmic_idx, *dmic_gpio_cnt);
  423. switch (event) {
  424. case SND_SOC_DAPM_PRE_PMU:
  425. (*dmic_gpio_cnt)++;
  426. if (*dmic_gpio_cnt == 1) {
  427. ret = msm_cdc_pinctrl_select_active_state(
  428. dmic_gpio);
  429. if (ret < 0) {
  430. pr_err("%s: gpio set cannot be activated %sd",
  431. __func__, "dmic_gpio");
  432. return ret;
  433. }
  434. }
  435. break;
  436. case SND_SOC_DAPM_POST_PMD:
  437. (*dmic_gpio_cnt)--;
  438. if (*dmic_gpio_cnt == 0) {
  439. ret = msm_cdc_pinctrl_select_sleep_state(
  440. dmic_gpio);
  441. if (ret < 0) {
  442. pr_err("%s: gpio set cannot be de-activated %sd",
  443. __func__, "dmic_gpio");
  444. return ret;
  445. }
  446. }
  447. break;
  448. default:
  449. pr_err("%s: invalid DAPM event %d\n", __func__, event);
  450. return -EINVAL;
  451. }
  452. return 0;
  453. }
  454. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  455. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  456. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  457. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  458. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  459. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  460. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  461. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  462. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  463. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  464. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  465. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  466. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  467. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  468. };
  469. static int msm_int_audrx_init(struct snd_soc_pcm_runtime *rtd)
  470. {
  471. int ret = 0;
  472. struct snd_soc_component *component;
  473. struct snd_soc_dapm_context *dapm;
  474. struct snd_card *card;
  475. struct snd_info_entry *entry;
  476. struct snd_soc_component *aux_comp;
  477. struct msm_asoc_mach_data *pdata =
  478. snd_soc_card_get_drvdata(rtd->card);
  479. component = snd_soc_rtdcom_lookup(rtd, "bolero_codec");
  480. if (!component) {
  481. ret = -EINVAL;
  482. pr_err("%s: could not find component for bolero_codec\n",
  483. __func__);
  484. return ret;
  485. }
  486. dapm = snd_soc_component_get_dapm(component);
  487. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  488. ARRAY_SIZE(msm_int_dapm_widgets));
  489. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  490. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  491. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  492. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  493. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  494. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  495. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  496. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  497. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  498. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  499. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  500. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  501. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  502. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
  503. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
  504. snd_soc_dapm_ignore_suspend(dapm, "WSA AIF VI");
  505. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
  506. snd_soc_dapm_sync(dapm);
  507. /*
  508. * Send speaker configuration only for WSA8810.
  509. * Default configuration is for WSA8815.
  510. */
  511. dev_dbg(component->dev, "%s: Number of aux devices: %d\n",
  512. __func__, rtd->card->num_aux_devs);
  513. if (rtd->card->num_aux_devs &&
  514. !list_empty(&rtd->card->component_dev_list)) {
  515. list_for_each_entry(aux_comp,
  516. &rtd->card->aux_comp_list,
  517. card_aux_list) {
  518. if (aux_comp->name != NULL && (
  519. !strcmp(aux_comp->name, WSA8810_NAME_1) ||
  520. !strcmp(aux_comp->name, WSA8810_NAME_2))) {
  521. wsa_macro_set_spkr_mode(component,
  522. WSA_MACRO_SPKR_MODE_1);
  523. wsa_macro_set_spkr_gain_offset(component,
  524. WSA_MACRO_GAIN_OFFSET_M1P5_DB);
  525. }
  526. }
  527. if (pdata->lito_v2_enabled) {
  528. /*
  529. * Enable tx data line3 for saipan version v2 amd
  530. * write corresponding lpi register.
  531. */
  532. bolero_set_port_map(component, ARRAY_SIZE(sm_port_map_v2),
  533. sm_port_map_v2);
  534. } else {
  535. bolero_set_port_map(component, ARRAY_SIZE(sm_port_map),
  536. sm_port_map);
  537. }
  538. }
  539. card = rtd->card->snd_card;
  540. if (!pdata->codec_root) {
  541. entry = snd_info_create_subdir(card->module, "codecs",
  542. card->proc_root);
  543. if (!entry) {
  544. pr_debug("%s: Cannot create codecs module entry\n",
  545. __func__);
  546. ret = 0;
  547. goto err;
  548. }
  549. pdata->codec_root = entry;
  550. }
  551. bolero_info_create_codec_entry(pdata->codec_root, component);
  552. bolero_register_wake_irq(component, false);
  553. codec_reg_done = true;
  554. return 0;
  555. err:
  556. return ret;
  557. }
  558. static void *def_wcd_mbhc_cal(void)
  559. {
  560. void *wcd_mbhc_cal;
  561. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  562. u16 *btn_high;
  563. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  564. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  565. if (!wcd_mbhc_cal)
  566. return NULL;
  567. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  568. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  569. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  570. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  571. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  572. btn_high[0] = 75;
  573. btn_high[1] = 150;
  574. btn_high[2] = 237;
  575. btn_high[3] = 500;
  576. btn_high[4] = 500;
  577. btn_high[5] = 500;
  578. btn_high[6] = 500;
  579. btn_high[7] = 500;
  580. return wcd_mbhc_cal;
  581. }
  582. /* Digital audio interface glue - connects codec <---> CPU */
  583. static struct snd_soc_dai_link msm_common_dai_links[] = {
  584. {
  585. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  586. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  587. .cpu_dai_name = "snd-soc-dummy-dai",
  588. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  589. .dpcm_playback = 1,
  590. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  591. SND_SOC_DPCM_TRIGGER_POST},
  592. .codec_dai_name = "wsa_macro_rx1",
  593. .codec_name = "bolero_codec",
  594. .init = &msm_int_audrx_init,
  595. .be_hw_params_fixup = msm_be_hw_params_fixup,
  596. .ignore_suspend = 1,
  597. /* this dainlink has playback support */
  598. .ignore_pmdown_time = 1,
  599. },
  600. {
  601. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  602. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  603. .cpu_dai_name = "snd-soc-dummy-dai",
  604. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  605. .dpcm_playback = 1,
  606. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  607. SND_SOC_DPCM_TRIGGER_POST},
  608. .codec_dai_name = "wsa_macro_rx_mix",
  609. .codec_name = "bolero_codec",
  610. .be_hw_params_fixup = msm_be_hw_params_fixup,
  611. .ignore_suspend = 1,
  612. /* this dainlink has playback support */
  613. .ignore_pmdown_time = 1,
  614. },
  615. {
  616. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  617. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  618. .cpu_dai_name = "snd-soc-dummy-dai",
  619. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  620. .dpcm_capture = 1,
  621. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  622. SND_SOC_DPCM_TRIGGER_POST},
  623. .codec_dai_name = "wsa_macro_echo",
  624. .codec_name = "bolero_codec",
  625. .be_hw_params_fixup = msm_be_hw_params_fixup,
  626. .ignore_suspend = 1,
  627. /* this dainlink has playback support */
  628. .ignore_pmdown_time = 1,
  629. },
  630. {
  631. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  632. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  633. .cpu_dai_name = "snd-soc-dummy-dai",
  634. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  635. .dpcm_playback = 1,
  636. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  637. SND_SOC_DPCM_TRIGGER_POST},
  638. .codec_dai_name = "rx_macro_rx1",
  639. .codec_name = "bolero_codec",
  640. .be_hw_params_fixup = msm_be_hw_params_fixup,
  641. .ignore_suspend = 1,
  642. /* this dainlink has playback support */
  643. .ignore_pmdown_time = 1,
  644. },
  645. {
  646. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  647. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  648. .cpu_dai_name = "snd-soc-dummy-dai",
  649. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  650. .dpcm_playback = 1,
  651. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  652. SND_SOC_DPCM_TRIGGER_POST},
  653. .codec_dai_name = "rx_macro_rx2",
  654. .codec_name = "bolero_codec",
  655. .be_hw_params_fixup = msm_be_hw_params_fixup,
  656. .ignore_suspend = 1,
  657. /* this dainlink has playback support */
  658. .ignore_pmdown_time = 1,
  659. },
  660. {
  661. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  662. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  663. .cpu_dai_name = "snd-soc-dummy-dai",
  664. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  665. .dpcm_playback = 1,
  666. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  667. SND_SOC_DPCM_TRIGGER_POST},
  668. .codec_dai_name = "rx_macro_rx3",
  669. .codec_name = "bolero_codec",
  670. .be_hw_params_fixup = msm_be_hw_params_fixup,
  671. .ignore_suspend = 1,
  672. /* this dainlink has playback support */
  673. .ignore_pmdown_time = 1,
  674. },
  675. {
  676. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  677. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  678. .cpu_dai_name = "snd-soc-dummy-dai",
  679. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  680. .dpcm_playback = 1,
  681. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  682. SND_SOC_DPCM_TRIGGER_POST},
  683. .codec_dai_name = "rx_macro_rx4",
  684. .codec_name = "bolero_codec",
  685. .be_hw_params_fixup = msm_be_hw_params_fixup,
  686. .ignore_suspend = 1,
  687. /* this dainlink has playback support */
  688. .ignore_pmdown_time = 1,
  689. },
  690. {
  691. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  692. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  693. .cpu_dai_name = "snd-soc-dummy-dai",
  694. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  695. .dpcm_capture = 1,
  696. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  697. SND_SOC_DPCM_TRIGGER_POST},
  698. .codec_dai_name = "tx_macro_tx1",
  699. .codec_name = "bolero_codec",
  700. .be_hw_params_fixup = msm_be_hw_params_fixup,
  701. .ignore_suspend = 1,
  702. /* this dainlink has playback support */
  703. .ignore_pmdown_time = 1,
  704. },
  705. {
  706. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  707. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  708. .cpu_dai_name = "snd-soc-dummy-dai",
  709. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  710. .dpcm_capture = 1,
  711. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  712. SND_SOC_DPCM_TRIGGER_POST},
  713. .codec_dai_name = "tx_macro_tx2",
  714. .codec_name = "bolero_codec",
  715. .be_hw_params_fixup = msm_be_hw_params_fixup,
  716. .ignore_suspend = 1,
  717. /* this dainlink has playback support */
  718. .ignore_pmdown_time = 1,
  719. },
  720. {
  721. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  722. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  723. .cpu_dai_name = "snd-soc-dummy-dai",
  724. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  725. .dpcm_capture = 1,
  726. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  727. SND_SOC_DPCM_TRIGGER_POST},
  728. .codec_dai_name = "va_macro_tx1",
  729. .codec_name = "bolero_codec",
  730. .be_hw_params_fixup = msm_be_hw_params_fixup,
  731. .ignore_suspend = 1,
  732. /* this dainlink has playback support */
  733. .ignore_pmdown_time = 1,
  734. },
  735. {
  736. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  737. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  738. .cpu_dai_name = "snd-soc-dummy-dai",
  739. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  740. .dpcm_capture = 1,
  741. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  742. SND_SOC_DPCM_TRIGGER_POST},
  743. .codec_dai_name = "va_macro_tx2",
  744. .codec_name = "bolero_codec",
  745. .be_hw_params_fixup = msm_be_hw_params_fixup,
  746. .ignore_suspend = 1,
  747. /* this dainlink has playback support */
  748. .ignore_pmdown_time = 1,
  749. },
  750. {
  751. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  752. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  753. .cpu_dai_name = "snd-soc-dummy-dai",
  754. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  755. .dpcm_capture = 1,
  756. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  757. SND_SOC_DPCM_TRIGGER_POST},
  758. .codec_dai_name = "va_macro_tx3",
  759. .codec_name = "bolero_codec",
  760. .be_hw_params_fixup = msm_be_hw_params_fixup,
  761. .ignore_suspend = 1,
  762. /* this dainlink has playback support */
  763. .ignore_pmdown_time = 1,
  764. },
  765. };
  766. static struct snd_soc_dai_link msm_kona_dai_links[
  767. ARRAY_SIZE(msm_common_dai_links)];
  768. static int msm_populate_dai_link_component_of_node(
  769. struct snd_soc_card *card)
  770. {
  771. int i, index, ret = 0;
  772. struct device *cdev = card->dev;
  773. struct snd_soc_dai_link *dai_link = card->dai_link;
  774. struct device_node *np;
  775. if (!cdev) {
  776. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  777. return -ENODEV;
  778. }
  779. for (i = 0; i < card->num_links; i++) {
  780. if (dai_link[i].platform_of_node && dai_link[i].cpu_of_node)
  781. continue;
  782. /* populate platform_of_node for snd card dai links */
  783. if (dai_link[i].platform_name &&
  784. !dai_link[i].platform_of_node) {
  785. index = of_property_match_string(cdev->of_node,
  786. "asoc-platform-names",
  787. dai_link[i].platform_name);
  788. if (index < 0) {
  789. dev_err(cdev, "%s: No match found for platform name: %s\n",
  790. __func__, dai_link[i].platform_name);
  791. ret = index;
  792. goto err;
  793. }
  794. np = of_parse_phandle(cdev->of_node, "asoc-platform",
  795. index);
  796. if (!np) {
  797. dev_err(cdev, "%s: retrieving phandle for platform %s, index %d failed\n",
  798. __func__, dai_link[i].platform_name,
  799. index);
  800. ret = -ENODEV;
  801. goto err;
  802. }
  803. dai_link[i].platform_of_node = np;
  804. dai_link[i].platform_name = NULL;
  805. }
  806. /* populate cpu_of_node for snd card dai links */
  807. if (dai_link[i].cpu_dai_name && !dai_link[i].cpu_of_node) {
  808. index = of_property_match_string(cdev->of_node,
  809. "asoc-cpu-names",
  810. dai_link[i].cpu_dai_name);
  811. if (index >= 0) {
  812. np = of_parse_phandle(cdev->of_node, "asoc-cpu",
  813. index);
  814. if (!np) {
  815. dev_err(cdev, "%s: retrieving phandle for cpu dai %s failed\n",
  816. __func__,
  817. dai_link[i].cpu_dai_name);
  818. ret = -ENODEV;
  819. goto err;
  820. }
  821. dai_link[i].cpu_of_node = np;
  822. dai_link[i].cpu_dai_name = NULL;
  823. }
  824. }
  825. /* populate codec_of_node for snd card dai links */
  826. if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
  827. index = of_property_match_string(cdev->of_node,
  828. "asoc-codec-names",
  829. dai_link[i].codec_name);
  830. if (index < 0)
  831. continue;
  832. np = of_parse_phandle(cdev->of_node, "asoc-codec",
  833. index);
  834. if (!np) {
  835. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  836. __func__, dai_link[i].codec_name);
  837. ret = -ENODEV;
  838. goto err;
  839. }
  840. dai_link[i].codec_of_node = np;
  841. dai_link[i].codec_name = NULL;
  842. }
  843. }
  844. err:
  845. return ret;
  846. }
  847. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  848. {
  849. return 0;
  850. }
  851. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  852. struct snd_pcm_hw_params *params)
  853. {
  854. return 0;
  855. }
  856. static struct snd_soc_ops msm_stub_be_ops = {
  857. .hw_params = msm_snd_stub_hw_params,
  858. };
  859. struct snd_soc_card snd_soc_card_stub_msm = {
  860. .name = "kona-stub-snd-card",
  861. };
  862. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  863. /* Backend DAI Links */
  864. {
  865. .name = LPASS_BE_PRI_AUXPCM_RX,
  866. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  867. .cpu_dai_name = "snd-soc-dummy-dai",
  868. .codec_name = "msm-stub-codec.1",
  869. .codec_dai_name = "msm-stub-rx",
  870. .dpcm_playback = 1,
  871. .init = &msm_audrx_stub_init,
  872. .be_hw_params_fixup = msm_be_hw_params_fixup,
  873. .ignore_pmdown_time = 1,
  874. .ignore_suspend = 1,
  875. .ops = &msm_stub_be_ops,
  876. },
  877. {
  878. .name = LPASS_BE_PRI_AUXPCM_TX,
  879. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  880. .cpu_dai_name = "snd-soc-dummy-dai",
  881. .codec_name = "msm-stub-codec.1",
  882. .codec_dai_name = "msm-stub-tx",
  883. .dpcm_capture = 1,
  884. .be_hw_params_fixup = msm_be_hw_params_fixup,
  885. .ignore_suspend = 1,
  886. .ops = &msm_stub_be_ops,
  887. },
  888. };
  889. static struct snd_soc_dai_link msm_stub_dai_links[
  890. ARRAY_SIZE(msm_stub_be_dai_links)];
  891. static const struct of_device_id kona_asoc_machine_of_match[] = {
  892. { .compatible = "qcom,kona-asoc-snd",
  893. .data = "codec"},
  894. { .compatible = "qcom,kona-asoc-snd-stub",
  895. .data = "stub_codec"},
  896. {},
  897. };
  898. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  899. {
  900. struct snd_soc_card *card = NULL;
  901. struct snd_soc_dai_link *dailink = NULL;
  902. int total_links = 0;
  903. const struct of_device_id *match;
  904. match = of_match_node(kona_asoc_machine_of_match, dev->of_node);
  905. if (!match) {
  906. dev_err(dev, "%s: No DT match found for sound card\n",
  907. __func__);
  908. return NULL;
  909. }
  910. if (!strcmp(match->data, "codec")) {
  911. card = &snd_soc_card_kona_msm;
  912. memcpy(msm_kona_dai_links,
  913. msm_common_dai_links,
  914. sizeof(msm_common_dai_links));
  915. total_links += ARRAY_SIZE(msm_common_dai_links);
  916. dailink = msm_kona_dai_links;
  917. } else if(!strcmp(match->data, "stub_codec")) {
  918. card = &snd_soc_card_stub_msm;
  919. memcpy(msm_stub_dai_links,
  920. msm_stub_be_dai_links,
  921. sizeof(msm_stub_be_dai_links));
  922. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  923. dailink = msm_stub_dai_links;
  924. }
  925. if (card) {
  926. card->dai_link = dailink;
  927. card->num_links = total_links;
  928. }
  929. return card;
  930. }
  931. static int msm_wsa881x_init(struct snd_soc_component *component)
  932. {
  933. u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  934. u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  935. u8 spkleft_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  936. SPKR_L_BOOST, SPKR_L_VI};
  937. u8 spkright_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  938. SPKR_R_BOOST, SPKR_R_VI};
  939. unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {2400, 600, 300, 1200};
  940. unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  941. struct msm_asoc_mach_data *pdata;
  942. struct snd_soc_dapm_context *dapm;
  943. struct snd_card *card;
  944. struct snd_info_entry *entry;
  945. int ret = 0;
  946. if (!component) {
  947. pr_err("%s component is NULL\n", __func__);
  948. return -EINVAL;
  949. }
  950. card = component->card->snd_card;
  951. dapm = snd_soc_component_get_dapm(component);
  952. if (!strcmp(component->name_prefix, "SpkrLeft")) {
  953. dev_dbg(component->dev, "%s: setting left ch map to codec %s\n",
  954. __func__, component->name);
  955. wsa881x_set_channel_map(component, &spkleft_ports[0],
  956. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  957. &ch_rate[0], &spkleft_port_types[0]);
  958. if (dapm->component) {
  959. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft IN");
  960. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft SPKR");
  961. }
  962. } else if (!strcmp(component->name_prefix, "SpkrRight")) {
  963. dev_dbg(component->dev, "%s: setting right ch map to codec %s\n",
  964. __func__, component->name);
  965. wsa881x_set_channel_map(component, &spkright_ports[0],
  966. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  967. &ch_rate[0], &spkright_port_types[0]);
  968. if (dapm->component) {
  969. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight IN");
  970. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight SPKR");
  971. }
  972. } else {
  973. dev_err(component->dev, "%s: wrong codec name %s\n", __func__,
  974. component->name);
  975. ret = -EINVAL;
  976. goto err;
  977. }
  978. pdata = snd_soc_card_get_drvdata(component->card);
  979. if (!pdata->codec_root) {
  980. entry = snd_info_create_subdir(card->module, "codecs",
  981. card->proc_root);
  982. if (!entry) {
  983. pr_err("%s: Cannot create codecs module entry\n",
  984. __func__);
  985. ret = 0;
  986. goto err;
  987. }
  988. pdata->codec_root = entry;
  989. }
  990. wsa881x_codec_info_create_codec_entry(pdata->codec_root,
  991. component);
  992. err:
  993. return ret;
  994. }
  995. static int msm_aux_codec_init(struct snd_soc_component *component)
  996. {
  997. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
  998. int ret = 0;
  999. int codec_variant = -1;
  1000. void *mbhc_calibration;
  1001. struct snd_info_entry *entry;
  1002. struct snd_card *card = component->card->snd_card;
  1003. struct msm_asoc_mach_data *pdata;
  1004. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1005. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1006. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1007. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1008. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1009. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1010. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1011. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1012. snd_soc_dapm_sync(dapm);
  1013. pdata = snd_soc_card_get_drvdata(component->card);
  1014. if (!pdata->codec_root) {
  1015. entry = snd_info_create_subdir(card->module, "codecs",
  1016. card->proc_root);
  1017. if (!entry) {
  1018. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1019. __func__);
  1020. ret = 0;
  1021. goto mbhc_cfg_cal;
  1022. }
  1023. pdata->codec_root = entry;
  1024. }
  1025. wcd938x_info_create_codec_entry(pdata->codec_root, component);
  1026. codec_variant = wcd938x_get_codec_variant(component);
  1027. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1028. mbhc_cfg_cal:
  1029. mbhc_calibration = def_wcd_mbhc_cal();
  1030. if (!mbhc_calibration)
  1031. return -ENOMEM;
  1032. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1033. ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1034. if (ret) {
  1035. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1036. __func__, ret);
  1037. goto err_hs_detect;
  1038. }
  1039. return 0;
  1040. err_hs_detect:
  1041. kfree(mbhc_calibration);
  1042. return ret;
  1043. }
  1044. static int msm_init_aux_dev(struct platform_device *pdev,
  1045. struct snd_soc_card *card)
  1046. {
  1047. struct device_node *wsa_of_node;
  1048. struct device_node *aux_codec_of_node;
  1049. u32 wsa_max_devs;
  1050. u32 wsa_dev_cnt;
  1051. u32 codec_max_aux_devs = 0;
  1052. u32 codec_aux_dev_cnt = 0;
  1053. int i;
  1054. struct msm_wsa881x_dev_info *wsa881x_dev_info;
  1055. struct aux_codec_dev_info *aux_cdc_dev_info;
  1056. const char *auxdev_name_prefix[1];
  1057. char *dev_name_str = NULL;
  1058. int found = 0;
  1059. int codecs_found = 0;
  1060. int ret = 0;
  1061. /* Get maximum WSA device count for this platform */
  1062. ret = of_property_read_u32(pdev->dev.of_node,
  1063. "qcom,wsa-max-devs", &wsa_max_devs);
  1064. if (ret) {
  1065. dev_info(&pdev->dev,
  1066. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1067. __func__, pdev->dev.of_node->full_name, ret);
  1068. wsa_max_devs = 0;
  1069. goto codec_aux_dev;
  1070. }
  1071. if (wsa_max_devs == 0) {
  1072. dev_warn(&pdev->dev,
  1073. "%s: Max WSA devices is 0 for this target?\n",
  1074. __func__);
  1075. goto codec_aux_dev;
  1076. }
  1077. /* Get count of WSA device phandles for this platform */
  1078. wsa_dev_cnt = of_count_phandle_with_args(pdev->dev.of_node,
  1079. "qcom,wsa-devs", NULL);
  1080. if (wsa_dev_cnt == -ENOENT) {
  1081. dev_warn(&pdev->dev, "%s: No wsa device defined in DT.\n",
  1082. __func__);
  1083. goto err;
  1084. } else if (wsa_dev_cnt <= 0) {
  1085. dev_err(&pdev->dev,
  1086. "%s: Error reading wsa device from DT. wsa_dev_cnt = %d\n",
  1087. __func__, wsa_dev_cnt);
  1088. ret = -EINVAL;
  1089. goto err;
  1090. }
  1091. /*
  1092. * Expect total phandles count to be NOT less than maximum possible
  1093. * WSA count. However, if it is less, then assign same value to
  1094. * max count as well.
  1095. */
  1096. if (wsa_dev_cnt < wsa_max_devs) {
  1097. dev_dbg(&pdev->dev,
  1098. "%s: wsa_max_devs = %d cannot exceed wsa_dev_cnt = %d\n",
  1099. __func__, wsa_max_devs, wsa_dev_cnt);
  1100. wsa_max_devs = wsa_dev_cnt;
  1101. }
  1102. /* Make sure prefix string passed for each WSA device */
  1103. ret = of_property_count_strings(pdev->dev.of_node,
  1104. "qcom,wsa-aux-dev-prefix");
  1105. if (ret != wsa_dev_cnt) {
  1106. dev_err(&pdev->dev,
  1107. "%s: expecting %d wsa prefix. Defined only %d in DT\n",
  1108. __func__, wsa_dev_cnt, ret);
  1109. ret = -EINVAL;
  1110. goto err;
  1111. }
  1112. /*
  1113. * Alloc mem to store phandle and index info of WSA device, if already
  1114. * registered with ALSA core
  1115. */
  1116. wsa881x_dev_info = devm_kcalloc(&pdev->dev, wsa_max_devs,
  1117. sizeof(struct msm_wsa881x_dev_info),
  1118. GFP_KERNEL);
  1119. if (!wsa881x_dev_info) {
  1120. ret = -ENOMEM;
  1121. goto err;
  1122. }
  1123. /*
  1124. * search and check whether all WSA devices are already
  1125. * registered with ALSA core or not. If found a node, store
  1126. * the node and the index in a local array of struct for later
  1127. * use.
  1128. */
  1129. for (i = 0; i < wsa_dev_cnt; i++) {
  1130. wsa_of_node = of_parse_phandle(pdev->dev.of_node,
  1131. "qcom,wsa-devs", i);
  1132. if (unlikely(!wsa_of_node)) {
  1133. /* we should not be here */
  1134. dev_err(&pdev->dev,
  1135. "%s: wsa dev node is not present\n",
  1136. __func__);
  1137. ret = -EINVAL;
  1138. goto err;
  1139. }
  1140. if (soc_find_component(wsa_of_node, NULL)) {
  1141. /* WSA device registered with ALSA core */
  1142. wsa881x_dev_info[found].of_node = wsa_of_node;
  1143. wsa881x_dev_info[found].index = i;
  1144. found++;
  1145. if (found == wsa_max_devs)
  1146. break;
  1147. }
  1148. }
  1149. if (found < wsa_max_devs) {
  1150. dev_dbg(&pdev->dev,
  1151. "%s: failed to find %d components. Found only %d\n",
  1152. __func__, wsa_max_devs, found);
  1153. return -EPROBE_DEFER;
  1154. }
  1155. dev_info(&pdev->dev,
  1156. "%s: found %d wsa881x devices registered with ALSA core\n",
  1157. __func__, found);
  1158. codec_aux_dev:
  1159. /* Get maximum aux codec device count for this platform */
  1160. ret = of_property_read_u32(pdev->dev.of_node,
  1161. "qcom,codec-max-aux-devs",
  1162. &codec_max_aux_devs);
  1163. if (ret) {
  1164. dev_err(&pdev->dev,
  1165. "%s: codec-max-aux-devs property missing in DT %s, ret = %d\n",
  1166. __func__, pdev->dev.of_node->full_name, ret);
  1167. codec_max_aux_devs = 0;
  1168. goto aux_dev_register;
  1169. }
  1170. if (codec_max_aux_devs == 0) {
  1171. dev_dbg(&pdev->dev,
  1172. "%s: Max aux codec devices is 0 for this target?\n",
  1173. __func__);
  1174. goto aux_dev_register;
  1175. }
  1176. /* Get count of aux codec device phandles for this platform */
  1177. codec_aux_dev_cnt = of_count_phandle_with_args(
  1178. pdev->dev.of_node,
  1179. "qcom,codec-aux-devs", NULL);
  1180. if (codec_aux_dev_cnt == -ENOENT) {
  1181. dev_warn(&pdev->dev, "%s: No aux codec defined in DT.\n",
  1182. __func__);
  1183. goto err;
  1184. } else if (codec_aux_dev_cnt <= 0) {
  1185. dev_err(&pdev->dev,
  1186. "%s: Error reading aux codec device from DT, dev_cnt=%d\n",
  1187. __func__, codec_aux_dev_cnt);
  1188. ret = -EINVAL;
  1189. goto err;
  1190. }
  1191. /*
  1192. * Expect total phandles count to be NOT less than maximum possible
  1193. * AUX device count. However, if it is less, then assign same value to
  1194. * max count as well.
  1195. */
  1196. if (codec_aux_dev_cnt < codec_max_aux_devs) {
  1197. dev_dbg(&pdev->dev,
  1198. "%s: codec_max_aux_devs = %d cannot exceed codec_aux_dev_cnt = %d\n",
  1199. __func__, codec_max_aux_devs,
  1200. codec_aux_dev_cnt);
  1201. codec_max_aux_devs = codec_aux_dev_cnt;
  1202. }
  1203. /*
  1204. * Alloc mem to store phandle and index info of aux codec
  1205. * if already registered with ALSA core
  1206. */
  1207. aux_cdc_dev_info = devm_kcalloc(&pdev->dev, codec_aux_dev_cnt,
  1208. sizeof(struct aux_codec_dev_info),
  1209. GFP_KERNEL);
  1210. if (!aux_cdc_dev_info) {
  1211. ret = -ENOMEM;
  1212. goto err;
  1213. }
  1214. /*
  1215. * search and check whether all aux codecs are already
  1216. * registered with ALSA core or not. If found a node, store
  1217. * the node and the index in a local array of struct for later
  1218. * use.
  1219. */
  1220. for (i = 0; i < codec_aux_dev_cnt; i++) {
  1221. aux_codec_of_node = of_parse_phandle(pdev->dev.of_node,
  1222. "qcom,codec-aux-devs", i);
  1223. if (unlikely(!aux_codec_of_node)) {
  1224. /* we should not be here */
  1225. dev_err(&pdev->dev,
  1226. "%s: aux codec dev node is not present\n",
  1227. __func__);
  1228. ret = -EINVAL;
  1229. goto err;
  1230. }
  1231. if (soc_find_component(aux_codec_of_node, NULL)) {
  1232. /* AUX codec registered with ALSA core */
  1233. aux_cdc_dev_info[codecs_found].of_node =
  1234. aux_codec_of_node;
  1235. aux_cdc_dev_info[codecs_found].index = i;
  1236. codecs_found++;
  1237. }
  1238. }
  1239. if (codecs_found < codec_aux_dev_cnt) {
  1240. dev_dbg(&pdev->dev,
  1241. "%s: failed to find %d components. Found only %d\n",
  1242. __func__, codec_aux_dev_cnt, codecs_found);
  1243. return -EPROBE_DEFER;
  1244. }
  1245. dev_info(&pdev->dev,
  1246. "%s: found %d AUX codecs registered with ALSA core\n",
  1247. __func__, codecs_found);
  1248. aux_dev_register:
  1249. card->num_aux_devs = wsa_max_devs + codec_aux_dev_cnt;
  1250. card->num_configs = wsa_max_devs + codec_aux_dev_cnt;
  1251. /* Alloc array of AUX devs struct */
  1252. msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs,
  1253. sizeof(struct snd_soc_aux_dev),
  1254. GFP_KERNEL);
  1255. if (!msm_aux_dev) {
  1256. ret = -ENOMEM;
  1257. goto err;
  1258. }
  1259. /* Alloc array of codec conf struct */
  1260. msm_codec_conf = devm_kcalloc(&pdev->dev, card->num_configs,
  1261. sizeof(struct snd_soc_codec_conf),
  1262. GFP_KERNEL);
  1263. if (!msm_codec_conf) {
  1264. ret = -ENOMEM;
  1265. goto err;
  1266. }
  1267. for (i = 0; i < wsa_max_devs; i++) {
  1268. dev_name_str = devm_kzalloc(&pdev->dev, DEV_NAME_STR_LEN,
  1269. GFP_KERNEL);
  1270. if (!dev_name_str) {
  1271. ret = -ENOMEM;
  1272. goto err;
  1273. }
  1274. ret = of_property_read_string_index(pdev->dev.of_node,
  1275. "qcom,wsa-aux-dev-prefix",
  1276. wsa881x_dev_info[i].index,
  1277. auxdev_name_prefix);
  1278. if (ret) {
  1279. dev_err(&pdev->dev,
  1280. "%s: failed to read wsa aux dev prefix, ret = %d\n",
  1281. __func__, ret);
  1282. ret = -EINVAL;
  1283. goto err;
  1284. }
  1285. snprintf(dev_name_str, strlen("wsa881x.%d"), "wsa881x.%d", i);
  1286. msm_aux_dev[i].name = dev_name_str;
  1287. msm_aux_dev[i].codec_name = NULL;
  1288. msm_aux_dev[i].codec_of_node =
  1289. wsa881x_dev_info[i].of_node;
  1290. msm_aux_dev[i].init = msm_wsa881x_init;
  1291. msm_codec_conf[i].dev_name = NULL;
  1292. msm_codec_conf[i].name_prefix = auxdev_name_prefix[0];
  1293. msm_codec_conf[i].of_node =
  1294. wsa881x_dev_info[i].of_node;
  1295. }
  1296. for (i = 0; i < codec_aux_dev_cnt; i++) {
  1297. msm_aux_dev[wsa_max_devs + i].name = NULL;
  1298. msm_aux_dev[wsa_max_devs + i].codec_name = NULL;
  1299. msm_aux_dev[wsa_max_devs + i].codec_of_node =
  1300. aux_cdc_dev_info[i].of_node;
  1301. msm_aux_dev[wsa_max_devs + i].init = msm_aux_codec_init;
  1302. msm_codec_conf[wsa_max_devs + i].dev_name = NULL;
  1303. msm_codec_conf[wsa_max_devs + i].name_prefix =
  1304. NULL;
  1305. msm_codec_conf[wsa_max_devs + i].of_node =
  1306. aux_cdc_dev_info[i].of_node;
  1307. }
  1308. card->codec_conf = msm_codec_conf;
  1309. card->aux_dev = msm_aux_dev;
  1310. err:
  1311. return ret;
  1312. }
  1313. static int kona_ssr_enable(struct device *dev, void *data)
  1314. {
  1315. struct platform_device *pdev = to_platform_device(dev);
  1316. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1317. int ret = 0;
  1318. if (!card) {
  1319. dev_err(dev, "%s: card is NULL\n", __func__);
  1320. ret = -EINVAL;
  1321. goto err;
  1322. }
  1323. if (!strcmp(card->name, "kona-stub-snd-card")) {
  1324. /* TODO */
  1325. dev_dbg(dev, "%s: TODO \n", __func__);
  1326. }
  1327. snd_soc_card_change_online_state(card, 1);
  1328. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1329. err:
  1330. return ret;
  1331. }
  1332. static void kona_ssr_disable(struct device *dev, void *data)
  1333. {
  1334. struct platform_device *pdev = to_platform_device(dev);
  1335. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1336. if (!card) {
  1337. dev_err(dev, "%s: card is NULL\n", __func__);
  1338. return;
  1339. }
  1340. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1341. snd_soc_card_change_online_state(card, 0);
  1342. if (!strcmp(card->name, "kona-stub-snd-card")) {
  1343. /* TODO */
  1344. dev_dbg(dev, "%s: TODO \n", __func__);
  1345. }
  1346. }
  1347. static const struct snd_event_ops kona_ssr_ops = {
  1348. .enable = kona_ssr_enable,
  1349. .disable = kona_ssr_disable,
  1350. };
  1351. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1352. {
  1353. struct device_node *node = data;
  1354. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1355. __func__, dev->of_node, node);
  1356. return (dev->of_node && dev->of_node == node);
  1357. }
  1358. static int msm_audio_ssr_register(struct device *dev)
  1359. {
  1360. struct device_node *np = dev->of_node;
  1361. struct snd_event_clients *ssr_clients = NULL;
  1362. struct device_node *node = NULL;
  1363. int ret = 0;
  1364. int i = 0;
  1365. for (i = 0; ; i++) {
  1366. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1367. if (!node)
  1368. break;
  1369. snd_event_mstr_add_client(&ssr_clients,
  1370. msm_audio_ssr_compare, node);
  1371. }
  1372. ret = snd_event_master_register(dev, &kona_ssr_ops,
  1373. ssr_clients, NULL);
  1374. if (!ret)
  1375. snd_event_notify(dev, SND_EVENT_UP);
  1376. return ret;
  1377. }
  1378. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1379. {
  1380. struct snd_soc_card *card = NULL;
  1381. struct msm_asoc_mach_data *pdata = NULL;
  1382. const char *mbhc_audio_jack_type = NULL;
  1383. int ret = 0;
  1384. uint index = 0;
  1385. if (!pdev->dev.of_node) {
  1386. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1387. return -EINVAL;
  1388. }
  1389. pdata = devm_kzalloc(&pdev->dev,
  1390. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1391. if (!pdata)
  1392. return -ENOMEM;
  1393. of_property_read_u32(pdev->dev.of_node,
  1394. "qcom,lito-is-v2-enabled",
  1395. &pdata->lito_v2_enabled);
  1396. card = populate_snd_card_dailinks(&pdev->dev);
  1397. if (!card) {
  1398. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1399. ret = -EINVAL;
  1400. goto err;
  1401. }
  1402. card->dev = &pdev->dev;
  1403. platform_set_drvdata(pdev, card);
  1404. snd_soc_card_set_drvdata(card, pdata);
  1405. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1406. if (ret) {
  1407. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1408. __func__, ret);
  1409. goto err;
  1410. }
  1411. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1412. if (ret) {
  1413. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1414. __func__, ret);
  1415. goto err;
  1416. }
  1417. ret = msm_populate_dai_link_component_of_node(card);
  1418. if (ret) {
  1419. ret = -EPROBE_DEFER;
  1420. goto err;
  1421. }
  1422. ret = msm_init_aux_dev(pdev, card);
  1423. if (ret)
  1424. goto err;
  1425. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1426. if (ret == -EPROBE_DEFER) {
  1427. if (codec_reg_done)
  1428. ret = -EINVAL;
  1429. goto err;
  1430. } else if (ret) {
  1431. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1432. __func__, ret);
  1433. goto err;
  1434. }
  1435. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1436. __func__, card->name);
  1437. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1438. "qcom,hph-en1-gpio", 0);
  1439. if (!pdata->hph_en1_gpio_p) {
  1440. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1441. __func__, "qcom,hph-en1-gpio",
  1442. pdev->dev.of_node->full_name);
  1443. }
  1444. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1445. "qcom,hph-en0-gpio", 0);
  1446. if (!pdata->hph_en0_gpio_p) {
  1447. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1448. __func__, "qcom,hph-en0-gpio",
  1449. pdev->dev.of_node->full_name);
  1450. }
  1451. ret = of_property_read_string(pdev->dev.of_node,
  1452. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  1453. if (ret) {
  1454. dev_dbg(&pdev->dev, "%s: Looking up %s property in node %s failed\n",
  1455. __func__, "qcom,mbhc-audio-jack-type",
  1456. pdev->dev.of_node->full_name);
  1457. dev_dbg(&pdev->dev, "Jack type properties set to default\n");
  1458. } else {
  1459. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  1460. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1461. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  1462. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  1463. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1464. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  1465. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  1466. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1467. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  1468. } else {
  1469. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1470. dev_dbg(&pdev->dev, "Unknown value, set to default\n");
  1471. }
  1472. }
  1473. /*
  1474. * Parse US-Euro gpio info from DT. Report no error if us-euro
  1475. * entry is not found in DT file as some targets do not support
  1476. * US-Euro detection
  1477. */
  1478. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1479. "qcom,us-euro-gpios", 0);
  1480. if (!pdata->us_euro_gpio_p) {
  1481. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  1482. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  1483. } else {
  1484. dev_dbg(&pdev->dev, "%s detected\n",
  1485. "qcom,us-euro-gpios");
  1486. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  1487. }
  1488. if (wcd_mbhc_cfg.enable_usbc_analog)
  1489. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1490. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1491. "fsa4480-i2c-handle", 0);
  1492. if (!pdata->fsa_handle)
  1493. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1494. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1495. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1496. "qcom,cdc-dmic01-gpios",
  1497. 0);
  1498. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1499. "qcom,cdc-dmic23-gpios",
  1500. 0);
  1501. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1502. "qcom,cdc-dmic45-gpios",
  1503. 0);
  1504. if (pdata->dmic01_gpio_p)
  1505. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1506. if (pdata->dmic23_gpio_p)
  1507. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1508. if (pdata->dmic45_gpio_p)
  1509. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1510. pdata->mi2s_gpio_p[PRIM_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1511. "qcom,pri-mi2s-gpios", 0);
  1512. pdata->mi2s_gpio_p[SEC_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1513. "qcom,sec-mi2s-gpios", 0);
  1514. pdata->mi2s_gpio_p[TERT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1515. "qcom,tert-mi2s-gpios", 0);
  1516. pdata->mi2s_gpio_p[QUAT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1517. "qcom,quat-mi2s-gpios", 0);
  1518. pdata->mi2s_gpio_p[QUIN_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1519. "qcom,quin-mi2s-gpios", 0);
  1520. pdata->mi2s_gpio_p[SEN_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1521. "qcom,sen-mi2s-gpios", 0);
  1522. for (index = PRIM_MI2S; index < MI2S_MAX; index++)
  1523. atomic_set(&(pdata->mi2s_gpio_ref_count[index]), 0);
  1524. ret = msm_audio_ssr_register(&pdev->dev);
  1525. if (ret)
  1526. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1527. __func__, ret);
  1528. is_initial_boot = true;
  1529. return 0;
  1530. err:
  1531. devm_kfree(&pdev->dev, pdata);
  1532. return ret;
  1533. }
  1534. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1535. {
  1536. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1537. snd_event_master_deregister(&pdev->dev);
  1538. snd_soc_unregister_card(card);
  1539. return 0;
  1540. }
  1541. static struct platform_driver kona_asoc_machine_driver = {
  1542. .driver = {
  1543. .name = DRV_NAME,
  1544. .owner = THIS_MODULE,
  1545. .pm = &snd_soc_pm_ops,
  1546. .of_match_table = kona_asoc_machine_of_match,
  1547. .suppress_bind_attrs = true,
  1548. },
  1549. .probe = msm_asoc_machine_probe,
  1550. .remove = msm_asoc_machine_remove,
  1551. };
  1552. module_platform_driver(kona_asoc_machine_driver);
  1553. MODULE_DESCRIPTION("ALSA SoC msm");
  1554. MODULE_LICENSE("GPL v2");
  1555. MODULE_ALIAS("platform:" DRV_NAME);
  1556. MODULE_DEVICE_TABLE(of, kona_asoc_machine_of_match);