wsa881x-analog.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2016, 2018-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/clk-provider.h>
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <linux/of_gpio.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/device.h>
  14. #include <linux/printk.h>
  15. #include <linux/bitops.h>
  16. #include <linux/regulator/consumer.h>
  17. #include <linux/pm_runtime.h>
  18. #include <soc/soundwire.h>
  19. #include <sound/pcm.h>
  20. #include <sound/pcm_params.h>
  21. #include <sound/soc.h>
  22. #include <sound/soc-dapm.h>
  23. #include <sound/tlv.h>
  24. #include <linux/delay.h>
  25. #include <linux/i2c.h>
  26. #include <linux/kernel.h>
  27. #include <linux/gpio.h>
  28. #include <soc/internal.h>
  29. #include <linux/regmap.h>
  30. #include <asoc/msm-cdc-pinctrl.h>
  31. #include "wsa881x-analog.h"
  32. #include "wsa881x-temp-sensor.h"
  33. #define SPK_GAIN_12DB 4
  34. #define WIDGET_NAME_MAX_SIZE 80
  35. #define REGMAP_REGISTER_CHECK_RETRY 30
  36. #define MAX_NAME_LEN 30
  37. #define WSA881X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  38. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  39. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  40. SNDRV_PCM_RATE_384000)
  41. /* Fractional Rates */
  42. #define WSA881X_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  43. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  44. #define WSA881X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  45. SNDRV_PCM_FMTBIT_S24_LE |\
  46. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  47. /*
  48. * Private data Structure for wsa881x. All parameters related to
  49. * WSA881X codec needs to be defined here.
  50. */
  51. struct wsa881x_pdata {
  52. struct regmap *regmap[2];
  53. struct i2c_client *client[2];
  54. struct snd_soc_component *component;
  55. /* track wsa881x status during probe */
  56. int status;
  57. bool boost_enable;
  58. bool visense_enable;
  59. int spk_pa_gain;
  60. struct i2c_msg xfer_msg[2];
  61. struct mutex xfer_lock;
  62. bool regmap_flag;
  63. bool wsa_active;
  64. int index;
  65. struct wsa881x_tz_priv tz_pdata;
  66. struct clk *wsa_mclk;
  67. int bg_cnt;
  68. int clk_cnt;
  69. int enable_cnt;
  70. int version;
  71. struct mutex bg_lock;
  72. struct mutex res_lock;
  73. struct delayed_work ocp_ctl_work;
  74. struct device_node *wsa_vi_gpio_p;
  75. struct device_node *wsa_clk_gpio_p;
  76. struct device_node *wsa_reset_gpio_p;
  77. char *wsa881x_name_prefix;
  78. struct snd_soc_dai_driver *dai_driver;
  79. struct snd_soc_component_driver *driver;
  80. };
  81. enum {
  82. WSA881X_STATUS_PROBING,
  83. WSA881X_STATUS_I2C,
  84. };
  85. #define WSA881X_OCP_CTL_TIMER_SEC 2
  86. #define WSA881X_OCP_CTL_TEMP_CELSIUS 25
  87. #define WSA881X_OCP_CTL_POLL_TIMER_SEC 60
  88. static int wsa881x_ocp_poll_timer_sec = WSA881X_OCP_CTL_POLL_TIMER_SEC;
  89. module_param(wsa881x_ocp_poll_timer_sec, int, 0664);
  90. MODULE_PARM_DESC(wsa881x_ocp_poll_timer_sec, "timer for ocp ctl polling");
  91. static int32_t wsa881x_resource_acquire(struct snd_soc_component *component,
  92. bool enable);
  93. const char *wsa_tz_names[] = {"wsa881x.0e", "wsa881x.0f"};
  94. static struct wsa881x_pdata wsa_pdata[MAX_WSA881X_DEVICE];
  95. static bool pinctrl_init;
  96. static int wsa881x_populate_dt_pdata(struct device *dev, int wsa881x_index);
  97. static int wsa881x_reset(struct wsa881x_pdata *pdata, bool enable);
  98. static int wsa881x_startup(struct wsa881x_pdata *pdata);
  99. static int wsa881x_shutdown(struct wsa881x_pdata *pdata);
  100. static int delay_array_msec[] = {10, 20, 30, 40, 50};
  101. static int wsa881x_i2c_addr = -1;
  102. static int wsa881x_probing_count;
  103. static int wsa881x_presence_count;
  104. static const char * const wsa881x_spk_pa_gain_text[] = {
  105. "POS_13P5_DB", "POS_12_DB", "POS_10P5_DB", "POS_9_DB", "POS_7P5_DB",
  106. "POS_6_DB", "POS_4P5_DB", "POS_3_DB", "POS_1P5_DB", "POS_0_DB"};
  107. static const struct soc_enum wsa881x_spk_pa_gain_enum[] = {
  108. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wsa881x_spk_pa_gain_text),
  109. wsa881x_spk_pa_gain_text),
  110. };
  111. static int wsa881x_spk_pa_gain_get(struct snd_kcontrol *kcontrol,
  112. struct snd_ctl_elem_value *ucontrol)
  113. {
  114. struct snd_soc_component *component =
  115. snd_soc_kcontrol_component(kcontrol);
  116. struct wsa881x_pdata *wsa881x =
  117. snd_soc_component_get_drvdata(component);
  118. ucontrol->value.integer.value[0] = wsa881x->spk_pa_gain;
  119. dev_dbg(component->dev, "%s: spk_pa_gain = %ld\n", __func__,
  120. ucontrol->value.integer.value[0]);
  121. return 0;
  122. }
  123. static int wsa881x_spk_pa_gain_put(struct snd_kcontrol *kcontrol,
  124. struct snd_ctl_elem_value *ucontrol)
  125. {
  126. struct snd_soc_component *component =
  127. snd_soc_kcontrol_component(kcontrol);
  128. struct wsa881x_pdata *wsa881x =
  129. snd_soc_component_get_drvdata(component);
  130. if (ucontrol->value.integer.value[0] < 0 ||
  131. ucontrol->value.integer.value[0] > 0xC) {
  132. dev_err(component->dev, "%s: Unsupported gain val %ld\n",
  133. __func__, ucontrol->value.integer.value[0]);
  134. return -EINVAL;
  135. }
  136. wsa881x->spk_pa_gain = ucontrol->value.integer.value[0];
  137. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  138. __func__, ucontrol->value.integer.value[0]);
  139. return 0;
  140. }
  141. static int get_i2c_wsa881x_device_index(u16 reg)
  142. {
  143. u16 mask = 0x0f00;
  144. int value = 0;
  145. value = ((reg & mask) >> 8) & 0x000f;
  146. switch (value) {
  147. case 0:
  148. return 0;
  149. case 1:
  150. return 1;
  151. default:
  152. break;
  153. }
  154. return -EINVAL;
  155. }
  156. static int wsa881x_i2c_write_device(struct wsa881x_pdata *wsa881x,
  157. unsigned int reg, unsigned int val)
  158. {
  159. int i = 0, rc = 0;
  160. int wsa881x_index;
  161. struct i2c_msg *msg;
  162. int ret = 0;
  163. int bytes = 1;
  164. u8 reg_addr = 0;
  165. u8 data[2];
  166. wsa881x_index = get_i2c_wsa881x_device_index(reg);
  167. if (wsa881x_index < 0) {
  168. pr_err_ratelimited("%s:invalid register to write\n", __func__);
  169. return -EINVAL;
  170. }
  171. if (wsa881x->regmap_flag) {
  172. rc = regmap_write(wsa881x->regmap[wsa881x_index], reg, val);
  173. for (i = 0; rc && i < ARRAY_SIZE(delay_array_msec); i++) {
  174. pr_err_ratelimited("Failed writing reg=%u-retry(%d)\n",
  175. reg, i);
  176. /* retry after delay of increasing order */
  177. msleep(delay_array_msec[i]);
  178. rc = regmap_write(wsa881x->regmap[wsa881x_index],
  179. reg, val);
  180. }
  181. if (rc)
  182. pr_err_ratelimited("Failed writing reg=%u rc=%d\n",
  183. reg, rc);
  184. else
  185. pr_debug("write success register = %x val = %x\n",
  186. reg, val);
  187. } else {
  188. reg_addr = (u8)reg;
  189. msg = &wsa881x->xfer_msg[0];
  190. msg->addr = wsa881x->client[wsa881x_index]->addr;
  191. msg->len = bytes + 1;
  192. msg->flags = 0;
  193. data[0] = reg;
  194. data[1] = (u8)val;
  195. msg->buf = data;
  196. ret = i2c_transfer(wsa881x->client[wsa881x_index]->adapter,
  197. wsa881x->xfer_msg, 1);
  198. /* Try again if the write fails */
  199. if (ret != 1) {
  200. ret = i2c_transfer(
  201. wsa881x->client[wsa881x_index]->adapter,
  202. wsa881x->xfer_msg, 1);
  203. if (ret != 1) {
  204. pr_err_ratelimited("failed to write the device\n");
  205. return ret;
  206. }
  207. }
  208. pr_debug("write success reg = %x val = %x\n", reg, data[1]);
  209. }
  210. return rc;
  211. }
  212. static int wsa881x_i2c_read_device(struct wsa881x_pdata *wsa881x,
  213. unsigned int reg)
  214. {
  215. int wsa881x_index;
  216. int i = 0, rc = 0;
  217. unsigned int val;
  218. struct i2c_msg *msg;
  219. int ret = 0;
  220. u8 reg_addr = 0;
  221. u8 dest[5] = {0};
  222. wsa881x_index = get_i2c_wsa881x_device_index(reg);
  223. if (wsa881x_index < 0) {
  224. pr_err_ratelimited("%s:invalid register to read\n", __func__);
  225. return -EINVAL;
  226. }
  227. if (wsa881x->regmap_flag) {
  228. rc = regmap_read(wsa881x->regmap[wsa881x_index], reg, &val);
  229. for (i = 0; rc && i < ARRAY_SIZE(delay_array_msec); i++) {
  230. pr_err_ratelimited("Failed reading reg=%u - retry(%d)\n",
  231. reg, i);
  232. /* retry after delay of increasing order */
  233. msleep(delay_array_msec[i]);
  234. rc = regmap_read(wsa881x->regmap[wsa881x_index],
  235. reg, &val);
  236. }
  237. if (rc) {
  238. pr_err_ratelimited("Failed reading reg=%u rc=%d\n",
  239. reg, rc);
  240. return rc;
  241. }
  242. pr_debug("read success reg = %x val = %x\n",
  243. reg, val);
  244. } else {
  245. reg_addr = (u8)reg;
  246. msg = &wsa881x->xfer_msg[0];
  247. msg->addr = wsa881x->client[wsa881x_index]->addr;
  248. msg->len = 1;
  249. msg->flags = 0;
  250. msg->buf = &reg_addr;
  251. msg = &wsa881x->xfer_msg[1];
  252. msg->addr = wsa881x->client[wsa881x_index]->addr;
  253. msg->len = 1;
  254. msg->flags = I2C_M_RD;
  255. msg->buf = dest;
  256. ret = i2c_transfer(wsa881x->client[wsa881x_index]->adapter,
  257. wsa881x->xfer_msg, 2);
  258. /* Try again if read fails first time */
  259. if (ret != 2) {
  260. ret = i2c_transfer(
  261. wsa881x->client[wsa881x_index]->adapter,
  262. wsa881x->xfer_msg, 2);
  263. if (ret != 2) {
  264. pr_err_ratelimited("failed to read wsa register:%d\n",
  265. reg);
  266. return ret;
  267. }
  268. }
  269. val = dest[0];
  270. }
  271. return val;
  272. }
  273. static unsigned int wsa881x_i2c_read(struct snd_soc_component *component,
  274. unsigned int reg)
  275. {
  276. struct wsa881x_pdata *wsa881x;
  277. int wsa881x_index;
  278. if (component == NULL) {
  279. pr_err_ratelimited("%s: invalid component\n", __func__);
  280. return -EINVAL;
  281. }
  282. wsa881x = snd_soc_component_get_drvdata(component);
  283. if (!wsa881x->wsa_active)
  284. return 0;
  285. wsa881x_index = get_i2c_wsa881x_device_index(reg);
  286. if (wsa881x_index < 0) {
  287. pr_err_ratelimited("%s:invalid register to read\n", __func__);
  288. return -EINVAL;
  289. }
  290. return wsa881x_i2c_read_device(wsa881x, reg);
  291. }
  292. static int wsa881x_i2c_write(struct snd_soc_component *component,
  293. unsigned int reg,
  294. unsigned int val)
  295. {
  296. struct wsa881x_pdata *wsa881x;
  297. int wsa881x_index;
  298. if (component == NULL) {
  299. pr_err_ratelimited("%s: invalid component\n", __func__);
  300. return -EINVAL;
  301. }
  302. wsa881x = snd_soc_component_get_drvdata(component);
  303. if (!wsa881x->wsa_active)
  304. return 0;
  305. wsa881x_index = get_i2c_wsa881x_device_index(reg);
  306. if (wsa881x_index < 0) {
  307. pr_err_ratelimited("%s:invalid register to read\n", __func__);
  308. return -EINVAL;
  309. }
  310. return wsa881x_i2c_write_device(wsa881x, reg, val);
  311. }
  312. static int wsa881x_i2c_get_client_index(struct i2c_client *client,
  313. int *wsa881x_index)
  314. {
  315. int ret = 0;
  316. switch (client->addr) {
  317. case WSA881X_I2C_SPK0_SLAVE0_ADDR:
  318. case WSA881X_I2C_SPK0_SLAVE1_ADDR:
  319. *wsa881x_index = WSA881X_I2C_SPK0_SLAVE0;
  320. break;
  321. case WSA881X_I2C_SPK1_SLAVE0_ADDR:
  322. case WSA881X_I2C_SPK1_SLAVE1_ADDR:
  323. *wsa881x_index = WSA881X_I2C_SPK1_SLAVE0;
  324. break;
  325. default:
  326. ret = -EINVAL;
  327. break;
  328. }
  329. return ret;
  330. }
  331. static int wsa881x_boost_ctrl(struct snd_soc_component *component, bool enable)
  332. {
  333. struct wsa881x_pdata *wsa881x =
  334. snd_soc_component_get_drvdata(component);
  335. pr_debug("%s: enable:%d\n", __func__, enable);
  336. if (enable) {
  337. if (!WSA881X_IS_2_0(wsa881x->version)) {
  338. snd_soc_component_update_bits(component,
  339. WSA881X_ANA_CTL, 0x01, 0x01);
  340. snd_soc_component_update_bits(component,
  341. WSA881X_ANA_CTL, 0x04, 0x04);
  342. snd_soc_component_update_bits(component,
  343. WSA881X_BOOST_PS_CTL,
  344. 0x40, 0x00);
  345. snd_soc_component_update_bits(component,
  346. WSA881X_BOOST_PRESET_OUT1,
  347. 0xF0, 0xB0);
  348. snd_soc_component_update_bits(component,
  349. WSA881X_BOOST_ZX_CTL,
  350. 0x20, 0x00);
  351. snd_soc_component_update_bits(component,
  352. WSA881X_BOOST_EN_CTL,
  353. 0x80, 0x80);
  354. } else {
  355. snd_soc_component_update_bits(component,
  356. WSA881X_BOOST_LOOP_STABILITY,
  357. 0x03, 0x03);
  358. snd_soc_component_update_bits(component,
  359. WSA881X_BOOST_MISC2_CTL,
  360. 0xFF, 0x14);
  361. snd_soc_component_update_bits(component,
  362. WSA881X_BOOST_START_CTL,
  363. 0x80, 0x80);
  364. snd_soc_component_update_bits(component,
  365. WSA881X_BOOST_START_CTL,
  366. 0x03, 0x00);
  367. snd_soc_component_update_bits(component,
  368. WSA881X_BOOST_SLOPE_COMP_ISENSE_FB,
  369. 0x0C, 0x04);
  370. snd_soc_component_update_bits(component,
  371. WSA881X_BOOST_SLOPE_COMP_ISENSE_FB,
  372. 0x03, 0x00);
  373. if (snd_soc_component_read(component, WSA881X_OTP_REG_0))
  374. snd_soc_component_update_bits(component,
  375. WSA881X_BOOST_PRESET_OUT1,
  376. 0xF0, 0x70);
  377. else
  378. snd_soc_component_update_bits(component,
  379. WSA881X_BOOST_PRESET_OUT1,
  380. 0xF0, 0xB0);
  381. snd_soc_component_update_bits(component,
  382. WSA881X_ANA_CTL, 0x03, 0x01);
  383. snd_soc_component_update_bits(component,
  384. WSA881X_SPKR_DRV_EN,
  385. 0x08, 0x08);
  386. snd_soc_component_update_bits(component,
  387. WSA881X_ANA_CTL, 0x04, 0x04);
  388. snd_soc_component_update_bits(component,
  389. WSA881X_BOOST_CURRENT_LIMIT,
  390. 0x0F, 0x08);
  391. snd_soc_component_update_bits(component,
  392. WSA881X_BOOST_EN_CTL,
  393. 0x80, 0x80);
  394. }
  395. /* For WSA8810, start-up time is 1500us as per qcrg sequence */
  396. usleep_range(1500, 1510);
  397. } else {
  398. /* ENSURE: Class-D amp is shutdown. CLK is still on */
  399. snd_soc_component_update_bits(component,
  400. WSA881X_BOOST_EN_CTL, 0x80, 0x00);
  401. /* boost settle time is 1500us as per qcrg sequence */
  402. usleep_range(1500, 1510);
  403. }
  404. return 0;
  405. }
  406. static int wsa881x_visense_txfe_ctrl(struct snd_soc_component *component,
  407. bool enable,
  408. u8 isense1_gain, u8 isense2_gain,
  409. u8 vsense_gain)
  410. {
  411. u8 value = 0;
  412. struct wsa881x_pdata *wsa881x =
  413. snd_soc_component_get_drvdata(component);
  414. pr_debug("%s: enable:%d\n", __func__, enable);
  415. if (enable) {
  416. if (WSA881X_IS_2_0(wsa881x->version)) {
  417. snd_soc_component_update_bits(component,
  418. WSA881X_OTP_REG_28,
  419. 0x3F, 0x3A);
  420. snd_soc_component_update_bits(component,
  421. WSA881X_BONGO_RESRV_REG1,
  422. 0xFF, 0xB2);
  423. snd_soc_component_update_bits(component,
  424. WSA881X_BONGO_RESRV_REG2,
  425. 0xFF, 0x05);
  426. }
  427. snd_soc_component_update_bits(component,
  428. WSA881X_SPKR_PROT_FE_VSENSE_VCM,
  429. 0x08, 0x00);
  430. if (WSA881X_IS_2_0(wsa881x->version)) {
  431. snd_soc_component_update_bits(component,
  432. WSA881X_SPKR_PROT_ATEST2,
  433. 0x1C, 0x04);
  434. } else {
  435. snd_soc_component_update_bits(component,
  436. WSA881X_SPKR_PROT_ATEST2,
  437. 0x08, 0x08);
  438. snd_soc_component_update_bits(component,
  439. WSA881X_SPKR_PROT_ATEST2,
  440. 0x02, 0x02);
  441. }
  442. value = ((isense2_gain << 6) | (isense1_gain << 4) |
  443. (vsense_gain << 3));
  444. snd_soc_component_update_bits(component,
  445. WSA881X_SPKR_PROT_FE_GAIN,
  446. 0xF8, value);
  447. snd_soc_component_update_bits(component,
  448. WSA881X_SPKR_PROT_FE_GAIN,
  449. 0x01, 0x01);
  450. } else {
  451. if (WSA881X_IS_2_0(wsa881x->version))
  452. snd_soc_component_update_bits(component,
  453. WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x10, 0x10);
  454. else
  455. snd_soc_component_update_bits(component,
  456. WSA881X_SPKR_PROT_FE_VSENSE_VCM, 0x08, 0x08);
  457. /*
  458. * 200us sleep is needed after visense txfe disable as per
  459. * HW requirement.
  460. */
  461. usleep_range(200, 210);
  462. snd_soc_component_update_bits(component,
  463. WSA881X_SPKR_PROT_FE_GAIN,
  464. 0x01, 0x00);
  465. }
  466. return 0;
  467. }
  468. static int wsa881x_visense_adc_ctrl(struct snd_soc_component *component,
  469. bool enable)
  470. {
  471. struct wsa881x_pdata *wsa881x =
  472. snd_soc_component_get_drvdata(component);
  473. pr_debug("%s: enable:%d\n", __func__, enable);
  474. if (enable) {
  475. if (!WSA881X_IS_2_0(wsa881x->version))
  476. snd_soc_component_update_bits(component,
  477. WSA881X_ADC_SEL_IBIAS,
  478. 0x70, 0x40);
  479. snd_soc_component_update_bits(component,
  480. WSA881X_ADC_EN_SEL_IBIAS,
  481. 0x07, 0x04);
  482. snd_soc_component_update_bits(component,
  483. WSA881X_ADC_EN_MODU_V, 0x80, 0x80);
  484. snd_soc_component_update_bits(component,
  485. WSA881X_ADC_EN_MODU_I, 0x80, 0x80);
  486. } else {
  487. /* Ensure: Speaker Protection has been stopped */
  488. snd_soc_component_update_bits(component,
  489. WSA881X_ADC_EN_MODU_V, 0x80, 0x00);
  490. snd_soc_component_update_bits(component,
  491. WSA881X_ADC_EN_MODU_I, 0x80, 0x00);
  492. }
  493. return 0;
  494. }
  495. static void wsa881x_bandgap_ctrl(struct snd_soc_component *component,
  496. bool enable)
  497. {
  498. struct wsa881x_pdata *wsa881x =
  499. snd_soc_component_get_drvdata(component);
  500. dev_dbg(component->dev, "%s: enable:%d, bg_count:%d\n", __func__,
  501. enable, wsa881x->bg_cnt);
  502. mutex_lock(&wsa881x->bg_lock);
  503. if (enable) {
  504. ++wsa881x->bg_cnt;
  505. if (wsa881x->bg_cnt == 1) {
  506. snd_soc_component_update_bits(component,
  507. WSA881X_TEMP_OP, 0x08, 0x08);
  508. /* 400usec sleep is needed as per HW requirement */
  509. usleep_range(400, 410);
  510. snd_soc_component_update_bits(component,
  511. WSA881X_TEMP_OP, 0x04, 0x04);
  512. }
  513. } else {
  514. --wsa881x->bg_cnt;
  515. if (wsa881x->bg_cnt <= 0) {
  516. wsa881x->bg_cnt = 0;
  517. snd_soc_component_update_bits(component,
  518. WSA881X_TEMP_OP, 0x04, 0x00);
  519. snd_soc_component_update_bits(component,
  520. WSA881X_TEMP_OP, 0x08, 0x00);
  521. }
  522. }
  523. mutex_unlock(&wsa881x->bg_lock);
  524. }
  525. static void wsa881x_clk_ctrl(struct snd_soc_component *component, bool enable)
  526. {
  527. struct wsa881x_pdata *wsa881x =
  528. snd_soc_component_get_drvdata(component);
  529. dev_dbg(component->dev, "%s:ss enable:%d, clk_count:%d\n", __func__,
  530. enable, wsa881x->clk_cnt);
  531. mutex_lock(&wsa881x->res_lock);
  532. if (enable) {
  533. ++wsa881x->clk_cnt;
  534. if (wsa881x->clk_cnt == 1) {
  535. snd_soc_component_write(component,
  536. WSA881X_CDC_RST_CTL, 0x02);
  537. snd_soc_component_write(component,
  538. WSA881X_CDC_RST_CTL, 0x03);
  539. snd_soc_component_write(component,
  540. WSA881X_CLOCK_CONFIG, 0x01);
  541. snd_soc_component_write(component,
  542. WSA881X_CDC_DIG_CLK_CTL, 0x01);
  543. snd_soc_component_write(component,
  544. WSA881X_CDC_ANA_CLK_CTL, 0x01);
  545. }
  546. } else {
  547. --wsa881x->clk_cnt;
  548. if (wsa881x->clk_cnt <= 0) {
  549. wsa881x->clk_cnt = 0;
  550. snd_soc_component_write(component,
  551. WSA881X_CDC_ANA_CLK_CTL, 0x00);
  552. snd_soc_component_write(component,
  553. WSA881X_CDC_DIG_CLK_CTL, 0x00);
  554. if (WSA881X_IS_2_0(wsa881x->version))
  555. snd_soc_component_update_bits(component,
  556. WSA881X_CDC_TOP_CLK_CTL, 0x01, 0x00);
  557. }
  558. }
  559. mutex_unlock(&wsa881x->res_lock);
  560. }
  561. static int wsa881x_rdac_ctrl(struct snd_soc_component *component, bool enable)
  562. {
  563. struct wsa881x_pdata *wsa881x =
  564. snd_soc_component_get_drvdata(component);
  565. pr_debug("%s: enable:%d\n", __func__, enable);
  566. if (enable) {
  567. snd_soc_component_update_bits(component,
  568. WSA881X_ANA_CTL, 0x08, 0x00);
  569. snd_soc_component_update_bits(component,
  570. WSA881X_SPKR_DRV_GAIN, 0x08, 0x08);
  571. snd_soc_component_update_bits(component,
  572. WSA881X_SPKR_DAC_CTL, 0x20, 0x20);
  573. snd_soc_component_update_bits(component,
  574. WSA881X_SPKR_DAC_CTL, 0x20, 0x00);
  575. snd_soc_component_update_bits(component,
  576. WSA881X_SPKR_DAC_CTL, 0x40, 0x40);
  577. snd_soc_component_update_bits(component,
  578. WSA881X_SPKR_DAC_CTL, 0x80, 0x80);
  579. if (WSA881X_IS_2_0(wsa881x->version)) {
  580. snd_soc_component_update_bits(component,
  581. WSA881X_SPKR_BIAS_CAL, 0x01, 0x01);
  582. snd_soc_component_update_bits(component,
  583. WSA881X_SPKR_OCP_CTL, 0x30, 0x30);
  584. snd_soc_component_update_bits(component,
  585. WSA881X_SPKR_OCP_CTL, 0x0C, 0x00);
  586. }
  587. snd_soc_component_update_bits(component,
  588. WSA881X_SPKR_DRV_GAIN, 0xF0, 0x40);
  589. snd_soc_component_update_bits(component,
  590. WSA881X_SPKR_MISC_CTL1, 0x01, 0x01);
  591. } else {
  592. /* Ensure class-D amp is off */
  593. snd_soc_component_update_bits(component,
  594. WSA881X_SPKR_DAC_CTL, 0x80, 0x00);
  595. }
  596. return 0;
  597. }
  598. static int wsa881x_spkr_pa_ctrl(struct snd_soc_component *component,
  599. bool enable)
  600. {
  601. int ret = 0;
  602. struct wsa881x_pdata *wsa881x =
  603. snd_soc_component_get_drvdata(component);
  604. pr_debug("%s: enable:%d\n", __func__, enable);
  605. if (enable) {
  606. /*
  607. * Ensure: Boost is enabled and stable, Analog input is up
  608. * and outputting silence
  609. */
  610. if (!WSA881X_IS_2_0(wsa881x->version)) {
  611. snd_soc_component_update_bits(component,
  612. WSA881X_ADC_EN_DET_TEST_I,
  613. 0xFF, 0x01);
  614. snd_soc_component_update_bits(component,
  615. WSA881X_ADC_EN_MODU_V,
  616. 0x02, 0x02);
  617. snd_soc_component_update_bits(component,
  618. WSA881X_ADC_EN_DET_TEST_V,
  619. 0xFF, 0x10);
  620. snd_soc_component_update_bits(component,
  621. WSA881X_SPKR_PWRSTG_DBG,
  622. 0xA0, 0xA0);
  623. snd_soc_component_update_bits(component,
  624. WSA881X_SPKR_DRV_EN,
  625. 0x80, 0x80);
  626. usleep_range(700, 710);
  627. snd_soc_component_update_bits(component,
  628. WSA881X_SPKR_PWRSTG_DBG,
  629. 0x00, 0x00);
  630. snd_soc_component_update_bits(component,
  631. WSA881X_ADC_EN_DET_TEST_V,
  632. 0xFF, 0x00);
  633. snd_soc_component_update_bits(component,
  634. WSA881X_ADC_EN_MODU_V,
  635. 0x02, 0x00);
  636. snd_soc_component_update_bits(component,
  637. WSA881X_ADC_EN_DET_TEST_I,
  638. 0xFF, 0x00);
  639. } else
  640. snd_soc_component_update_bits(component,
  641. WSA881X_SPKR_DRV_EN, 0x80, 0x80);
  642. /* add 1000us delay as per qcrg */
  643. usleep_range(1000, 1010);
  644. snd_soc_component_update_bits(component,
  645. WSA881X_SPKR_DRV_EN, 0x01, 0x01);
  646. if (WSA881X_IS_2_0(wsa881x->version))
  647. snd_soc_component_update_bits(component,
  648. WSA881X_SPKR_BIAS_CAL,
  649. 0x01, 0x00);
  650. usleep_range(1000, 1010);
  651. snd_soc_component_update_bits(component,
  652. WSA881X_SPKR_DRV_GAIN,
  653. 0xF0, (wsa881x->spk_pa_gain << 4));
  654. if (wsa881x->visense_enable) {
  655. ret = msm_cdc_pinctrl_select_active_state(
  656. wsa881x->wsa_vi_gpio_p);
  657. if (ret) {
  658. pr_err("%s: gpio set cannot be activated %s\n",
  659. __func__, "wsa_vi");
  660. return ret;
  661. }
  662. wsa881x_visense_txfe_ctrl(component, true,
  663. 0x00, 0x01, 0x00);
  664. wsa881x_visense_adc_ctrl(component, true);
  665. }
  666. } else {
  667. /*
  668. * Ensure: Boost is still on, Stream from Analog input and
  669. * Speaker Protection has been stopped and input is at 0V
  670. */
  671. if (WSA881X_IS_2_0(wsa881x->version)) {
  672. snd_soc_component_update_bits(component,
  673. WSA881X_SPKR_BIAS_CAL,
  674. 0x01, 0x01);
  675. usleep_range(1000, 1010);
  676. snd_soc_component_update_bits(component,
  677. WSA881X_SPKR_BIAS_CAL,
  678. 0x01, 0x00);
  679. msleep(20);
  680. snd_soc_component_update_bits(component,
  681. WSA881X_ANA_CTL, 0x03, 0x00);
  682. usleep_range(200, 210);
  683. }
  684. snd_soc_component_update_bits(component,
  685. WSA881X_SPKR_DRV_EN, 0x80, 0x00);
  686. }
  687. return 0;
  688. }
  689. static int wsa881x_get_boost(struct snd_kcontrol *kcontrol,
  690. struct snd_ctl_elem_value *ucontrol)
  691. {
  692. struct snd_soc_component *component =
  693. snd_soc_kcontrol_component(kcontrol);
  694. struct wsa881x_pdata *wsa881x =
  695. snd_soc_component_get_drvdata(component);
  696. ucontrol->value.integer.value[0] = wsa881x->boost_enable;
  697. return 0;
  698. }
  699. static int wsa881x_set_boost(struct snd_kcontrol *kcontrol,
  700. struct snd_ctl_elem_value *ucontrol)
  701. {
  702. struct snd_soc_component *component =
  703. snd_soc_kcontrol_component(kcontrol);
  704. struct wsa881x_pdata *wsa881x =
  705. snd_soc_component_get_drvdata(component);
  706. int value = ucontrol->value.integer.value[0];
  707. dev_dbg(component->dev, "%s: Boost enable current %d, new %d\n",
  708. __func__, wsa881x->boost_enable, value);
  709. wsa881x->boost_enable = value;
  710. return 0;
  711. }
  712. static int wsa881x_get_visense(struct snd_kcontrol *kcontrol,
  713. struct snd_ctl_elem_value *ucontrol)
  714. {
  715. struct snd_soc_component *component =
  716. snd_soc_kcontrol_component(kcontrol);
  717. struct wsa881x_pdata *wsa881x =
  718. snd_soc_component_get_drvdata(component);
  719. ucontrol->value.integer.value[0] = wsa881x->visense_enable;
  720. return 0;
  721. }
  722. static int wsa881x_set_visense(struct snd_kcontrol *kcontrol,
  723. struct snd_ctl_elem_value *ucontrol)
  724. {
  725. struct snd_soc_component *component =
  726. snd_soc_kcontrol_component(kcontrol);
  727. struct wsa881x_pdata *wsa881x =
  728. snd_soc_component_get_drvdata(component);
  729. int value = ucontrol->value.integer.value[0];
  730. dev_dbg(component->dev, "%s: VIsense enable current %d, new %d\n",
  731. __func__, wsa881x->visense_enable, value);
  732. wsa881x->visense_enable = value;
  733. return 0;
  734. }
  735. static const struct snd_kcontrol_new wsa881x_snd_controls[] = {
  736. SOC_SINGLE_EXT("BOOST Switch", SND_SOC_NOPM, 0, 1, 0,
  737. wsa881x_get_boost, wsa881x_set_boost),
  738. SOC_SINGLE_EXT("VISENSE Switch", SND_SOC_NOPM, 0, 1, 0,
  739. wsa881x_get_visense, wsa881x_set_visense),
  740. SOC_ENUM_EXT("WSA_SPK PA Gain", wsa881x_spk_pa_gain_enum[0],
  741. wsa881x_spk_pa_gain_get, wsa881x_spk_pa_gain_put),
  742. };
  743. static const char * const rdac_text[] = {
  744. "ZERO", "Switch",
  745. };
  746. static const struct soc_enum rdac_enum =
  747. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(rdac_text), rdac_text);
  748. static const struct snd_kcontrol_new rdac_mux[] = {
  749. SOC_DAPM_ENUM("RDAC", rdac_enum)
  750. };
  751. static int wsa881x_rdac_event(struct snd_soc_dapm_widget *w,
  752. struct snd_kcontrol *kcontrol, int event)
  753. {
  754. struct snd_soc_component *component =
  755. snd_soc_dapm_to_component(w->dapm);
  756. struct wsa881x_pdata *wsa881x =
  757. snd_soc_component_get_drvdata(component);
  758. int ret = 0;
  759. dev_dbg(component->dev, "%s: %s %d boost %d visense %d\n",
  760. __func__, w->name, event,
  761. wsa881x->boost_enable, wsa881x->visense_enable);
  762. switch (event) {
  763. case SND_SOC_DAPM_PRE_PMU:
  764. ret = wsa881x_startup(wsa881x);
  765. if (ret) {
  766. pr_err("%s: wsa startup failed ret: %d", __func__, ret);
  767. return ret;
  768. }
  769. wsa881x_clk_ctrl(component, true);
  770. snd_soc_component_update_bits(component,
  771. WSA881X_SPKR_DAC_CTL, 0x02, 0x02);
  772. if (!WSA881X_IS_2_0(wsa881x->version))
  773. snd_soc_component_update_bits(component,
  774. WSA881X_BIAS_REF_CTRL,
  775. 0x0F, 0x08);
  776. wsa881x_bandgap_ctrl(component, true);
  777. if (!WSA881X_IS_2_0(wsa881x->version))
  778. snd_soc_component_update_bits(component,
  779. WSA881X_SPKR_BBM_CTL,
  780. 0x02, 0x02);
  781. snd_soc_component_update_bits(component,
  782. WSA881X_SPKR_MISC_CTL1, 0xC0, 0x80);
  783. snd_soc_component_update_bits(component,
  784. WSA881X_SPKR_MISC_CTL1, 0x06, 0x06);
  785. if (!WSA881X_IS_2_0(wsa881x->version)) {
  786. snd_soc_component_update_bits(component,
  787. WSA881X_SPKR_MISC_CTL2,
  788. 0x04, 0x04);
  789. snd_soc_component_update_bits(component,
  790. WSA881X_SPKR_BIAS_INT,
  791. 0x09, 0x09);
  792. }
  793. snd_soc_component_update_bits(component,
  794. WSA881X_SPKR_PA_INT, 0xF0, 0x20);
  795. if (WSA881X_IS_2_0(wsa881x->version))
  796. snd_soc_component_update_bits(component,
  797. WSA881X_SPKR_PA_INT,
  798. 0x0E, 0x0E);
  799. if (wsa881x->boost_enable)
  800. wsa881x_boost_ctrl(component, true);
  801. break;
  802. case SND_SOC_DAPM_POST_PMU:
  803. wsa881x_rdac_ctrl(component, true);
  804. break;
  805. case SND_SOC_DAPM_PRE_PMD:
  806. wsa881x_rdac_ctrl(component, false);
  807. if (wsa881x->visense_enable) {
  808. wsa881x_visense_adc_ctrl(component, false);
  809. wsa881x_visense_txfe_ctrl(component, false,
  810. 0x00, 0x01, 0x00);
  811. ret = msm_cdc_pinctrl_select_sleep_state(
  812. wsa881x->wsa_vi_gpio_p);
  813. if (ret) {
  814. pr_err("%s: gpio set cannot be suspended %s\n",
  815. __func__, "wsa_vi");
  816. return ret;
  817. }
  818. }
  819. break;
  820. case SND_SOC_DAPM_POST_PMD:
  821. if (wsa881x->boost_enable)
  822. wsa881x_boost_ctrl(component, false);
  823. wsa881x_clk_ctrl(component, false);
  824. wsa881x_bandgap_ctrl(component, false);
  825. ret = wsa881x_shutdown(wsa881x);
  826. if (ret < 0) {
  827. pr_err("%s: wsa shutdown failed ret: %d",
  828. __func__, ret);
  829. return ret;
  830. }
  831. break;
  832. default:
  833. pr_err("%s: invalid event:%d\n", __func__, event);
  834. return -EINVAL;
  835. }
  836. return 0;
  837. }
  838. static void wsa881x_ocp_ctl_work(struct work_struct *work)
  839. {
  840. struct wsa881x_pdata *wsa881x;
  841. struct delayed_work *dwork;
  842. struct snd_soc_component *component;
  843. int temp_val;
  844. dwork = to_delayed_work(work);
  845. wsa881x = container_of(dwork, struct wsa881x_pdata, ocp_ctl_work);
  846. if (!wsa881x)
  847. return;
  848. component = wsa881x->component;
  849. wsa881x_get_temp(wsa881x->tz_pdata.tz_dev, &temp_val);
  850. dev_dbg(component->dev, " temp = %d\n", temp_val);
  851. if (temp_val <= WSA881X_OCP_CTL_TEMP_CELSIUS)
  852. snd_soc_component_update_bits(component,
  853. WSA881X_SPKR_OCP_CTL, 0xC0, 0x00);
  854. else
  855. snd_soc_component_update_bits(component,
  856. WSA881X_SPKR_OCP_CTL, 0xC0, 0xC0);
  857. schedule_delayed_work(&wsa881x->ocp_ctl_work,
  858. msecs_to_jiffies(wsa881x_ocp_poll_timer_sec * 1000));
  859. }
  860. static int wsa881x_spkr_pa_event(struct snd_soc_dapm_widget *w,
  861. struct snd_kcontrol *kcontrol, int event)
  862. {
  863. struct snd_soc_component *component =
  864. snd_soc_dapm_to_component(w->dapm);
  865. struct wsa881x_pdata *wsa881x =
  866. snd_soc_component_get_drvdata(component);
  867. pr_debug("%s: %s %d\n", __func__, w->name, event);
  868. switch (event) {
  869. case SND_SOC_DAPM_PRE_PMU:
  870. snd_soc_component_update_bits(component,
  871. WSA881X_SPKR_OCP_CTL, 0xC0, 0x80);
  872. break;
  873. case SND_SOC_DAPM_POST_PMU:
  874. wsa881x_spkr_pa_ctrl(component, true);
  875. schedule_delayed_work(&wsa881x->ocp_ctl_work,
  876. msecs_to_jiffies(WSA881X_OCP_CTL_TIMER_SEC * 1000));
  877. break;
  878. case SND_SOC_DAPM_PRE_PMD:
  879. wsa881x_spkr_pa_ctrl(component, false);
  880. break;
  881. case SND_SOC_DAPM_POST_PMD:
  882. cancel_delayed_work_sync(&wsa881x->ocp_ctl_work);
  883. snd_soc_component_update_bits(component,
  884. WSA881X_SPKR_OCP_CTL, 0xC0, 0xC0);
  885. break;
  886. default:
  887. pr_err("%s: invalid event:%d\n", __func__, event);
  888. return -EINVAL;
  889. }
  890. return 0;
  891. }
  892. static const struct snd_soc_dapm_widget wsa881x_dapm_widgets[] = {
  893. SND_SOC_DAPM_INPUT("WSA_IN"),
  894. SND_SOC_DAPM_DAC_E("RDAC Analog", NULL, SND_SOC_NOPM, 0, 0,
  895. wsa881x_rdac_event,
  896. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  897. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  898. SND_SOC_DAPM_MUX("WSA_RDAC", SND_SOC_NOPM, 0, 0,
  899. rdac_mux),
  900. SND_SOC_DAPM_PGA_S("WSA_SPKR PGA", 1, SND_SOC_NOPM, 0, 0,
  901. wsa881x_spkr_pa_event,
  902. SND_SOC_DAPM_PRE_PMU |
  903. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
  904. SND_SOC_DAPM_POST_PMD),
  905. SND_SOC_DAPM_OUTPUT("WSA_SPKR"),
  906. };
  907. static const struct snd_soc_dapm_route wsa881x_audio_map[] = {
  908. {"WSA_RDAC", "Switch", "WSA_IN"},
  909. {"RDAC Analog", NULL, "WSA_RDAC"},
  910. {"WSA_SPKR PGA", NULL, "RDAC Analog"},
  911. {"WSA_SPKR", NULL, "WSA_SPKR PGA"},
  912. };
  913. static int wsa881x_startup(struct wsa881x_pdata *pdata)
  914. {
  915. int ret = 0;
  916. pr_debug("%s(): wsa startup, enable_cnt:%d\n", __func__,
  917. pdata->enable_cnt);
  918. if (pdata->enable_cnt++ > 0)
  919. return 0;
  920. ret = msm_cdc_pinctrl_select_active_state(pdata->wsa_clk_gpio_p);
  921. if (ret) {
  922. pr_err("%s: gpio set cannot be activated %s\n",
  923. __func__, "wsa_clk");
  924. return ret;
  925. }
  926. ret = clk_prepare_enable(pdata->wsa_mclk);
  927. if (ret) {
  928. pr_err("%s: WSA MCLK enable failed\n",
  929. __func__);
  930. return ret;
  931. }
  932. ret = wsa881x_reset(pdata, true);
  933. return ret;
  934. }
  935. static int wsa881x_shutdown(struct wsa881x_pdata *pdata)
  936. {
  937. int ret = 0;
  938. pr_debug("%s(): wsa shutdown, enable_cnt:%d\n", __func__,
  939. pdata->enable_cnt);
  940. if (--pdata->enable_cnt > 0)
  941. return 0;
  942. ret = wsa881x_reset(pdata, false);
  943. if (ret) {
  944. pr_err("%s: wsa reset failed suspend %d\n",
  945. __func__, ret);
  946. return ret;
  947. }
  948. if (__clk_is_enabled(pdata->wsa_mclk))
  949. clk_disable_unprepare(pdata->wsa_mclk);
  950. ret = msm_cdc_pinctrl_select_sleep_state(pdata->wsa_clk_gpio_p);
  951. if (ret) {
  952. pr_err("%s: gpio set cannot be suspended %s\n",
  953. __func__, "wsa_clk");
  954. return ret;
  955. }
  956. return 0;
  957. }
  958. static int32_t wsa881x_resource_acquire(struct snd_soc_component *component,
  959. bool enable)
  960. {
  961. int ret = 0;
  962. struct wsa881x_pdata *wsa881x =
  963. snd_soc_component_get_drvdata(component);
  964. if (enable) {
  965. ret = wsa881x_startup(wsa881x);
  966. if (ret < 0) {
  967. dev_err_ratelimited(component->dev,
  968. "%s: failed to startup\n", __func__);
  969. return ret;
  970. }
  971. }
  972. wsa881x_clk_ctrl(component, enable);
  973. wsa881x_bandgap_ctrl(component, enable);
  974. if (!enable) {
  975. ret = wsa881x_shutdown(wsa881x);
  976. if (ret < 0)
  977. dev_err_ratelimited(component->dev,
  978. "%s: failed to shutdown\n", __func__);
  979. }
  980. return ret;
  981. }
  982. static int32_t wsa881x_temp_reg_read(struct snd_soc_component *component,
  983. struct wsa_temp_register *wsa_temp_reg)
  984. {
  985. struct wsa881x_pdata *wsa881x =
  986. snd_soc_component_get_drvdata(component);
  987. int ret = 0;
  988. if (!wsa881x) {
  989. dev_err(component->dev, "%s: wsa881x is NULL\n", __func__);
  990. return -EINVAL;
  991. }
  992. ret = wsa881x_resource_acquire(component, true);
  993. if (ret) {
  994. dev_err_ratelimited(component->dev,
  995. "%s: resource acquire fail\n", __func__);
  996. return ret;
  997. }
  998. if (WSA881X_IS_2_0(wsa881x->version)) {
  999. snd_soc_component_update_bits(component,
  1000. WSA881X_TADC_VALUE_CTL, 0x01, 0x00);
  1001. wsa_temp_reg->dmeas_msb =
  1002. snd_soc_component_read(component,
  1003. WSA881X_TEMP_MSB);
  1004. wsa_temp_reg->dmeas_lsb =
  1005. snd_soc_component_read(component,
  1006. WSA881X_TEMP_LSB);
  1007. snd_soc_component_update_bits(component,
  1008. WSA881X_TADC_VALUE_CTL, 0x01, 0x01);
  1009. } else {
  1010. wsa_temp_reg->dmeas_msb = snd_soc_component_read(component,
  1011. WSA881X_TEMP_DOUT_MSB);
  1012. wsa_temp_reg->dmeas_lsb = snd_soc_component_read(component,
  1013. WSA881X_TEMP_DOUT_LSB);
  1014. }
  1015. wsa_temp_reg->d1_msb = snd_soc_component_read(component,
  1016. WSA881X_OTP_REG_1);
  1017. wsa_temp_reg->d1_lsb = snd_soc_component_read(component,
  1018. WSA881X_OTP_REG_2);
  1019. wsa_temp_reg->d2_msb = snd_soc_component_read(component,
  1020. WSA881X_OTP_REG_3);
  1021. wsa_temp_reg->d2_lsb = snd_soc_component_read(component,
  1022. WSA881X_OTP_REG_4);
  1023. ret = wsa881x_resource_acquire(component, false);
  1024. if (ret)
  1025. dev_err_ratelimited(component->dev,
  1026. "%s: resource release fail\n", __func__);
  1027. return ret;
  1028. }
  1029. static int wsa881x_probe(struct snd_soc_component *component)
  1030. {
  1031. struct i2c_client *client;
  1032. int ret = 0;
  1033. int retry = REGMAP_REGISTER_CHECK_RETRY;
  1034. int wsa881x_index = 0;
  1035. struct snd_soc_dapm_context *dapm =
  1036. snd_soc_component_get_dapm(component);
  1037. char *widget_name = NULL;
  1038. client = dev_get_drvdata(component->dev);
  1039. ret = wsa881x_i2c_get_client_index(client, &wsa881x_index);
  1040. if (ret != 0) {
  1041. dev_err(&client->dev, "%s: I2C get codec I2C\n"
  1042. "client failed\n", __func__);
  1043. return ret;
  1044. }
  1045. mutex_init(&wsa_pdata[wsa881x_index].bg_lock);
  1046. mutex_init(&wsa_pdata[wsa881x_index].res_lock);
  1047. snprintf(wsa_pdata[wsa881x_index].tz_pdata.name, 100, "%s",
  1048. wsa_tz_names[wsa881x_index]);
  1049. wsa_pdata[wsa881x_index].component = component;
  1050. wsa_pdata[wsa881x_index].spk_pa_gain = SPK_GAIN_12DB;
  1051. wsa_pdata[wsa881x_index].component = component;
  1052. wsa_pdata[wsa881x_index].tz_pdata.component = component;
  1053. wsa_pdata[wsa881x_index].tz_pdata.wsa_temp_reg_read =
  1054. wsa881x_temp_reg_read;
  1055. snd_soc_component_set_drvdata(component, &wsa_pdata[wsa881x_index]);
  1056. while (retry) {
  1057. if (wsa_pdata[wsa881x_index].regmap[WSA881X_ANALOG_SLAVE]
  1058. != NULL)
  1059. break;
  1060. msleep(100);
  1061. retry--;
  1062. }
  1063. if (!retry)
  1064. dev_err(&client->dev, "%s: max retry expired and regmap of\n"
  1065. "analog slave not initilized\n", __func__);
  1066. wsa881x_init_thermal(&wsa_pdata[wsa881x_index].tz_pdata);
  1067. INIT_DELAYED_WORK(&wsa_pdata[wsa881x_index].ocp_ctl_work,
  1068. wsa881x_ocp_ctl_work);
  1069. if (component->name_prefix) {
  1070. widget_name = kcalloc(WIDGET_NAME_MAX_SIZE, sizeof(char),
  1071. GFP_KERNEL);
  1072. if (!widget_name)
  1073. return -ENOMEM;
  1074. snprintf(widget_name, WIDGET_NAME_MAX_SIZE,
  1075. "%s WSA_SPKR", component->name_prefix);
  1076. snd_soc_dapm_ignore_suspend(dapm, widget_name);
  1077. snprintf(widget_name, WIDGET_NAME_MAX_SIZE,
  1078. "%s WSA_IN", component->name_prefix);
  1079. snd_soc_dapm_ignore_suspend(dapm, widget_name);
  1080. kfree(widget_name);
  1081. } else {
  1082. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPKR");
  1083. snd_soc_dapm_ignore_suspend(dapm, "WSA_IN");
  1084. }
  1085. snd_soc_dapm_sync(dapm);
  1086. return 0;
  1087. }
  1088. static void wsa881x_remove(struct snd_soc_component *component)
  1089. {
  1090. struct wsa881x_pdata *wsa881x =
  1091. snd_soc_component_get_drvdata(component);
  1092. if (wsa881x->tz_pdata.tz_dev)
  1093. wsa881x_deinit_thermal(wsa881x->tz_pdata.tz_dev);
  1094. mutex_destroy(&wsa881x->bg_lock);
  1095. mutex_destroy(&wsa881x->res_lock);
  1096. }
  1097. static const struct snd_soc_component_driver soc_codec_dev_wsa881x = {
  1098. .name = "",
  1099. .probe = wsa881x_probe,
  1100. .remove = wsa881x_remove,
  1101. .read = wsa881x_i2c_read,
  1102. .write = wsa881x_i2c_write,
  1103. .controls = wsa881x_snd_controls,
  1104. .num_controls = ARRAY_SIZE(wsa881x_snd_controls),
  1105. .dapm_widgets = wsa881x_dapm_widgets,
  1106. .num_dapm_widgets = ARRAY_SIZE(wsa881x_dapm_widgets),
  1107. .dapm_routes = wsa881x_audio_map,
  1108. .num_dapm_routes = ARRAY_SIZE(wsa881x_audio_map),
  1109. };
  1110. static struct snd_soc_dai_driver wsa_dai[] = {
  1111. {
  1112. .name = "",
  1113. .playback = {
  1114. .stream_name = "",
  1115. .rates = WSA881X_RATES | WSA881X_FRAC_RATES,
  1116. .formats = WSA881X_FORMATS,
  1117. .rate_max = 192000,
  1118. .rate_min = 8000,
  1119. .channels_min = 1,
  1120. .channels_max = 2,
  1121. },
  1122. },
  1123. };
  1124. static int wsa881x_reset(struct wsa881x_pdata *pdata, bool enable)
  1125. {
  1126. int ret = 0;
  1127. /*
  1128. * shutdown the GPIOs WSA_EN, WSA_MCLK, regulators
  1129. * and restore defaults in soc cache when shutdown.
  1130. * Enable regulators, GPIOs WSA_MCLK, WSA_EN when powerup.
  1131. */
  1132. if (enable) {
  1133. if (pdata->wsa_active)
  1134. return 0;
  1135. ret = msm_cdc_pinctrl_select_active_state(
  1136. pdata->wsa_reset_gpio_p);
  1137. if (ret) {
  1138. pr_err("%s: gpio set cannot be activated %s\n",
  1139. __func__, "wsa_reset");
  1140. return ret;
  1141. }
  1142. ret = msm_cdc_pinctrl_select_sleep_state(
  1143. pdata->wsa_reset_gpio_p);
  1144. if (ret) {
  1145. pr_err("%s: gpio set cannot be suspended(powerup) %s\n",
  1146. __func__, "wsa_reset");
  1147. return ret;
  1148. }
  1149. ret = msm_cdc_pinctrl_select_active_state(
  1150. pdata->wsa_reset_gpio_p);
  1151. if (ret) {
  1152. pr_err("%s: gpio set cannot be activated %s\n",
  1153. __func__, "wsa_reset");
  1154. return ret;
  1155. }
  1156. pdata->wsa_active = true;
  1157. } else {
  1158. if (!pdata->wsa_active)
  1159. return 0;
  1160. ret = msm_cdc_pinctrl_select_sleep_state(
  1161. pdata->wsa_reset_gpio_p);
  1162. if (ret) {
  1163. pr_err("%s: gpio set cannot be suspended %s\n",
  1164. __func__, "wsa_reset");
  1165. return ret;
  1166. }
  1167. pdata->wsa_active = false;
  1168. }
  1169. return ret;
  1170. }
  1171. int wsa881x_get_client_index(void)
  1172. {
  1173. return wsa881x_i2c_addr;
  1174. }
  1175. EXPORT_SYMBOL(wsa881x_get_client_index);
  1176. int wsa881x_get_probing_count(void)
  1177. {
  1178. return wsa881x_probing_count;
  1179. }
  1180. EXPORT_SYMBOL(wsa881x_get_probing_count);
  1181. int wsa881x_get_presence_count(void)
  1182. {
  1183. return wsa881x_presence_count;
  1184. }
  1185. EXPORT_SYMBOL(wsa881x_get_presence_count);
  1186. static int check_wsa881x_presence(struct i2c_client *client)
  1187. {
  1188. int ret = 0;
  1189. int wsa881x_index = 0;
  1190. ret = wsa881x_i2c_get_client_index(client, &wsa881x_index);
  1191. if (ret != 0) {
  1192. dev_err(&client->dev, "%s: I2C get codec I2C\n"
  1193. "client failed\n", __func__);
  1194. return ret;
  1195. }
  1196. ret = wsa881x_i2c_read_device(&wsa_pdata[wsa881x_index],
  1197. WSA881X_CDC_RST_CTL);
  1198. if (ret < 0) {
  1199. dev_err(&client->dev, "failed to read wsa881x with addr %x\n",
  1200. client->addr);
  1201. return ret;
  1202. }
  1203. ret = wsa881x_i2c_write_device(&wsa_pdata[wsa881x_index],
  1204. WSA881X_CDC_RST_CTL, 0x01);
  1205. if (ret < 0) {
  1206. dev_err(&client->dev, "failed write addr %x reg:0x5 val:0x1\n",
  1207. client->addr);
  1208. return ret;
  1209. }
  1210. /* allow 20ms before trigger next write to verify wsa881x presence */
  1211. msleep(20);
  1212. ret = wsa881x_i2c_write_device(&wsa_pdata[wsa881x_index],
  1213. WSA881X_CDC_RST_CTL, 0x00);
  1214. if (ret < 0) {
  1215. dev_err(&client->dev, "failed write addr %x reg:0x5 val:0x0\n",
  1216. client->addr);
  1217. return ret;
  1218. }
  1219. return ret;
  1220. }
  1221. static int wsa881x_populate_dt_pdata(struct device *dev, int wsa881x_index)
  1222. {
  1223. int ret = 0;
  1224. struct wsa881x_pdata *pdata = &wsa_pdata[wsa881x_index];
  1225. /* reading the gpio configurations from dtsi file */
  1226. pdata->wsa_vi_gpio_p = of_parse_phandle(dev->of_node,
  1227. "qcom,wsa-analog-vi-gpio", 0);
  1228. pdata->wsa_clk_gpio_p = of_parse_phandle(dev->of_node,
  1229. "qcom,wsa-analog-clk-gpio", 0);
  1230. pdata->wsa_reset_gpio_p = of_parse_phandle(dev->of_node,
  1231. "qcom,wsa-analog-reset-gpio", 0);
  1232. pinctrl_init = true;
  1233. return ret;
  1234. }
  1235. static int wsa881x_i2c_probe(struct i2c_client *client,
  1236. const struct i2c_device_id *id)
  1237. {
  1238. int ret = 0;
  1239. int wsa881x_index = 0;
  1240. struct wsa881x_pdata *pdata = NULL;
  1241. struct clk *wsa_mclk = NULL;
  1242. char buffer[MAX_NAME_LEN];
  1243. const char *wsa881x_name_prefix_of = NULL;
  1244. struct snd_soc_component *component;
  1245. ret = wsa881x_i2c_get_client_index(client, &wsa881x_index);
  1246. if (ret != 0) {
  1247. dev_err(&client->dev, "%s: I2C get codec I2C\n"
  1248. "client failed\n", __func__);
  1249. return ret;
  1250. }
  1251. pdata = &wsa_pdata[wsa881x_index];
  1252. if ((client->addr == WSA881X_I2C_SPK0_SLAVE1_ADDR ||
  1253. client->addr == WSA881X_I2C_SPK1_SLAVE1_ADDR) &&
  1254. (pdata->status == WSA881X_STATUS_PROBING)) {
  1255. wsa881x_probing_count++;
  1256. return -EPROBE_DEFER;
  1257. }
  1258. if (pdata->status == WSA881X_STATUS_I2C) {
  1259. dev_info(&client->dev, "%s:probe for other slaves\n"
  1260. "devices of codec I2C slave Addr = %x wsa_idx = %d\n",
  1261. __func__, client->addr, wsa881x_index);
  1262. dev_dbg(&client->dev, "%s:wsa_idx = %d SLAVE = %d\n",
  1263. __func__, wsa881x_index, WSA881X_ANALOG_SLAVE);
  1264. pdata->regmap[WSA881X_ANALOG_SLAVE] =
  1265. devm_regmap_init_i2c(
  1266. client,
  1267. &wsa881x_ana_regmap_config[WSA881X_ANALOG_SLAVE]);
  1268. regcache_cache_bypass(pdata->regmap[WSA881X_ANALOG_SLAVE],
  1269. true);
  1270. if (IS_ERR(pdata->regmap[WSA881X_ANALOG_SLAVE])) {
  1271. ret = PTR_ERR(pdata->regmap[WSA881X_ANALOG_SLAVE]);
  1272. dev_err(&client->dev,
  1273. "%s: regmap_init failed %d\n",
  1274. __func__, ret);
  1275. }
  1276. client->dev.platform_data = pdata;
  1277. i2c_set_clientdata(client, pdata);
  1278. pdata->client[WSA881X_ANALOG_SLAVE] = client;
  1279. pdata->regmap_flag = true;
  1280. if (pdata->version == WSA881X_2_0)
  1281. wsa881x_update_regmap_2_0(
  1282. pdata->regmap[WSA881X_ANALOG_SLAVE],
  1283. WSA881X_ANALOG_SLAVE);
  1284. wsa881x_probing_count++;
  1285. return ret;
  1286. } else if (pdata->status == WSA881X_STATUS_PROBING) {
  1287. pdata->index = wsa881x_index;
  1288. if (client->dev.of_node) {
  1289. dev_dbg(&client->dev, "%s:Platform data\n"
  1290. "from device tree\n", __func__);
  1291. ret = wsa881x_populate_dt_pdata(
  1292. &client->dev, wsa881x_index);
  1293. if (ret < 0) {
  1294. dev_err(&client->dev,
  1295. "%s: Fail to obtain pdata from device tree\n",
  1296. __func__);
  1297. ret = -EINVAL;
  1298. goto err;
  1299. }
  1300. client->dev.platform_data = pdata;
  1301. } else {
  1302. dev_dbg(&client->dev, "%s:Platform data from\n"
  1303. "board file\n", __func__);
  1304. pdata = client->dev.platform_data;
  1305. }
  1306. if (!pdata) {
  1307. dev_dbg(&client->dev, "no platform data?\n");
  1308. ret = -EINVAL;
  1309. goto err;
  1310. }
  1311. wsa_mclk = devm_clk_get(&client->dev, "wsa_mclk");
  1312. if (IS_ERR(wsa_mclk)) {
  1313. ret = PTR_ERR(wsa_mclk);
  1314. dev_dbg(&client->dev, "%s: clk get %s failed %d\n",
  1315. __func__, "wsa_mclk", ret);
  1316. wsa_mclk = NULL;
  1317. goto err;
  1318. }
  1319. pdata->wsa_mclk = wsa_mclk;
  1320. dev_set_drvdata(&client->dev, client);
  1321. pdata->regmap[WSA881X_DIGITAL_SLAVE] =
  1322. devm_regmap_init_i2c(
  1323. client,
  1324. &wsa881x_ana_regmap_config[WSA881X_DIGITAL_SLAVE]);
  1325. regcache_cache_bypass(pdata->regmap[WSA881X_DIGITAL_SLAVE],
  1326. true);
  1327. if (IS_ERR(pdata->regmap[WSA881X_DIGITAL_SLAVE])) {
  1328. ret = PTR_ERR(pdata->regmap[WSA881X_DIGITAL_SLAVE]);
  1329. dev_err(&client->dev, "%s: regmap_init failed %d\n",
  1330. __func__, ret);
  1331. goto err;
  1332. }
  1333. /* bus reset sequence */
  1334. ret = wsa881x_reset(pdata, true);
  1335. if (ret < 0) {
  1336. wsa881x_probing_count++;
  1337. dev_err(&client->dev, "%s: WSA enable Failed %d\n",
  1338. __func__, ret);
  1339. goto err;
  1340. }
  1341. pdata->client[WSA881X_DIGITAL_SLAVE] = client;
  1342. ret = check_wsa881x_presence(client);
  1343. if (ret < 0) {
  1344. dev_err(&client->dev,
  1345. "failed to ping wsa with addr:%x, ret = %d\n",
  1346. client->addr, ret);
  1347. wsa881x_probing_count++;
  1348. goto err1;
  1349. }
  1350. pdata->version = wsa881x_i2c_read_device(pdata,
  1351. WSA881X_CHIP_ID1);
  1352. pr_debug("%s: wsa881x version: %d\n", __func__, pdata->version);
  1353. if (pdata->version == WSA881X_2_0) {
  1354. wsa881x_update_reg_defaults_2_0();
  1355. wsa881x_update_regmap_2_0(
  1356. pdata->regmap[WSA881X_DIGITAL_SLAVE],
  1357. WSA881X_DIGITAL_SLAVE);
  1358. }
  1359. wsa881x_presence_count++;
  1360. wsa881x_probing_count++;
  1361. ret = of_property_read_string(client->dev.of_node,
  1362. "qcom,wsa-prefix", &wsa881x_name_prefix_of);
  1363. if (ret) {
  1364. dev_err(&client->dev,
  1365. "%s: Looking up %s property in node %s failed\n",
  1366. __func__, "qcom,wsa-prefix",
  1367. client->dev.of_node->full_name);
  1368. goto err1;
  1369. }
  1370. pdata->driver = devm_kzalloc(&client->dev,
  1371. sizeof(struct snd_soc_component_driver),
  1372. GFP_KERNEL);
  1373. if (!pdata->driver) {
  1374. ret = -ENOMEM;
  1375. goto err1;
  1376. }
  1377. memcpy(pdata->driver, &soc_codec_dev_wsa881x,
  1378. sizeof(struct snd_soc_component_driver));
  1379. pdata->dai_driver = devm_kzalloc(&client->dev,
  1380. sizeof(struct snd_soc_dai_driver),
  1381. GFP_KERNEL);
  1382. if (!pdata->dai_driver) {
  1383. ret = -ENOMEM;
  1384. goto err_mem;
  1385. }
  1386. memcpy(pdata->dai_driver, wsa_dai,
  1387. sizeof(struct snd_soc_dai_driver));
  1388. snprintf(buffer, sizeof(buffer), "wsa-codec%d", wsa881x_index);
  1389. pdata->driver->name = kstrndup(buffer,
  1390. strlen(buffer), GFP_KERNEL);
  1391. snprintf(buffer, sizeof(buffer), "wsa_rx%d", wsa881x_index);
  1392. pdata->dai_driver->name =
  1393. kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1394. snprintf(buffer, sizeof(buffer),
  1395. "WSA881X_AIF%d Playback", wsa881x_index);
  1396. pdata->dai_driver->playback.stream_name =
  1397. kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1398. /* Number of DAI's used is 1 */
  1399. ret = snd_soc_register_component(&client->dev,
  1400. pdata->driver, pdata->dai_driver, 1);
  1401. pdata->wsa881x_name_prefix = kstrndup(wsa881x_name_prefix_of,
  1402. strlen(wsa881x_name_prefix_of), GFP_KERNEL);
  1403. component = snd_soc_lookup_component(&client->dev, pdata->driver->name);
  1404. if (!component) {
  1405. dev_err(&client->dev, "%s: component is NULL \n", __func__);
  1406. ret = -EINVAL;
  1407. goto err_mem;
  1408. }
  1409. component->name_prefix = pdata->wsa881x_name_prefix;
  1410. pdata->status = WSA881X_STATUS_I2C;
  1411. dev_info(&client->dev, "%s:pdata status changed to I2C\n",
  1412. __func__);
  1413. goto err1;
  1414. }
  1415. err_mem:
  1416. kfree(pdata->wsa881x_name_prefix);
  1417. if (pdata->dai_driver) {
  1418. kfree(pdata->dai_driver->name);
  1419. kfree(pdata->dai_driver->playback.stream_name);
  1420. kfree(pdata->dai_driver);
  1421. }
  1422. if (pdata->driver) {
  1423. kfree(pdata->driver->name);
  1424. kfree(pdata->driver);
  1425. }
  1426. err1:
  1427. wsa881x_reset(pdata, false);
  1428. err:
  1429. return ret;
  1430. }
  1431. static int wsa881x_i2c_remove(struct i2c_client *client)
  1432. {
  1433. struct wsa881x_pdata *wsa881x = client->dev.platform_data;
  1434. snd_soc_unregister_component(&client->dev);
  1435. kfree(wsa881x->wsa881x_name_prefix);
  1436. if (wsa881x->dai_driver) {
  1437. kfree(wsa881x->dai_driver->name);
  1438. kfree(wsa881x->dai_driver->playback.stream_name);
  1439. kfree(wsa881x->dai_driver);
  1440. }
  1441. if (wsa881x->driver) {
  1442. kfree(wsa881x->driver->name);
  1443. kfree(wsa881x->driver);
  1444. }
  1445. i2c_set_clientdata(client, NULL);
  1446. kfree(wsa881x);
  1447. return 0;
  1448. }
  1449. #ifdef CONFIG_PM_SLEEP
  1450. static int wsa881x_i2c_suspend(struct device *dev)
  1451. {
  1452. pr_debug("%s: system suspend\n", __func__);
  1453. return 0;
  1454. }
  1455. static int wsa881x_i2c_resume(struct device *dev)
  1456. {
  1457. pr_debug("%s: system resume\n", __func__);
  1458. return 0;
  1459. }
  1460. static const struct dev_pm_ops wsa881x_i2c_pm_ops = {
  1461. SET_SYSTEM_SLEEP_PM_OPS(wsa881x_i2c_suspend, wsa881x_i2c_resume)
  1462. };
  1463. #endif /* CONFIG_PM_SLEEP */
  1464. static const struct i2c_device_id wsa881x_i2c_id[] = {
  1465. {"wsa881x-i2c-dev", WSA881X_I2C_SPK0_SLAVE0_ADDR},
  1466. {"wsa881x-i2c-dev", WSA881X_I2C_SPK0_SLAVE1_ADDR},
  1467. {"wsa881x-i2c-dev", WSA881X_I2C_SPK1_SLAVE0_ADDR},
  1468. {"wsa881x-i2c-dev", WSA881X_I2C_SPK1_SLAVE1_ADDR},
  1469. {}
  1470. };
  1471. MODULE_DEVICE_TABLE(i2c, wsa881x_i2c_id);
  1472. static const struct of_device_id msm_match_table[] = {
  1473. {.compatible = "qcom,wsa881x-i2c-codec"},
  1474. {}
  1475. };
  1476. MODULE_DEVICE_TABLE(of, msm_match_table);
  1477. static struct i2c_driver wsa881x_codec_driver = {
  1478. .driver = {
  1479. .name = "wsa881x-i2c-codec",
  1480. .owner = THIS_MODULE,
  1481. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1482. #ifdef CONFIG_PM_SLEEP
  1483. .pm = &wsa881x_i2c_pm_ops,
  1484. #endif
  1485. .of_match_table = msm_match_table,
  1486. },
  1487. .id_table = wsa881x_i2c_id,
  1488. .probe = wsa881x_i2c_probe,
  1489. .remove = wsa881x_i2c_remove,
  1490. };
  1491. static int __init wsa881x_codec_init(void)
  1492. {
  1493. int i = 0;
  1494. for (i = 0; i < MAX_WSA881X_DEVICE; i++)
  1495. wsa_pdata[i].status = WSA881X_STATUS_PROBING;
  1496. return i2c_add_driver(&wsa881x_codec_driver);
  1497. }
  1498. module_init(wsa881x_codec_init);
  1499. static void __exit wsa881x_codec_exit(void)
  1500. {
  1501. i2c_del_driver(&wsa881x_codec_driver);
  1502. }
  1503. module_exit(wsa881x_codec_exit);
  1504. MODULE_DESCRIPTION("WSA881x Codec driver");
  1505. MODULE_LICENSE("GPL v2");