wsa881x-analog.c 45 KB

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