wsa881x-analog.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  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-2023 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 <linux/regmap.h>
  29. #include <asoc/msm-cdc-pinctrl.h>
  30. #include "wsa881x-analog.h"
  31. #include "wsa881x-temp-sensor.h"
  32. #define SPK_GAIN_12DB 4
  33. #define WIDGET_NAME_MAX_SIZE 80
  34. #define REGMAP_REGISTER_CHECK_RETRY 30
  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. static 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_read(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_read(component,
  1002. WSA881X_TEMP_MSB);
  1003. wsa_temp_reg->dmeas_lsb =
  1004. snd_soc_component_read(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_read(component,
  1010. WSA881X_TEMP_DOUT_MSB);
  1011. wsa_temp_reg->dmeas_lsb = snd_soc_component_read(component,
  1012. WSA881X_TEMP_DOUT_LSB);
  1013. }
  1014. wsa_temp_reg->d1_msb = snd_soc_component_read(component,
  1015. WSA881X_OTP_REG_1);
  1016. wsa_temp_reg->d1_lsb = snd_soc_component_read(component,
  1017. WSA881X_OTP_REG_2);
  1018. wsa_temp_reg->d2_msb = snd_soc_component_read(component,
  1019. WSA881X_OTP_REG_3);
  1020. wsa_temp_reg->d2_lsb = snd_soc_component_read(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 retry = REGMAP_REGISTER_CHECK_RETRY;
  1033. int wsa881x_index = 0;
  1034. struct snd_soc_dapm_context *dapm =
  1035. snd_soc_component_get_dapm(component);
  1036. char *widget_name = NULL;
  1037. client = dev_get_drvdata(component->dev);
  1038. ret = wsa881x_i2c_get_client_index(client, &wsa881x_index);
  1039. if (ret != 0) {
  1040. dev_err(&client->dev, "%s: I2C get codec I2C\n"
  1041. "client failed\n", __func__);
  1042. return ret;
  1043. }
  1044. mutex_init(&wsa_pdata[wsa881x_index].bg_lock);
  1045. mutex_init(&wsa_pdata[wsa881x_index].res_lock);
  1046. snprintf(wsa_pdata[wsa881x_index].tz_pdata.name, 100, "%s",
  1047. wsa_tz_names[wsa881x_index]);
  1048. wsa_pdata[wsa881x_index].component = component;
  1049. wsa_pdata[wsa881x_index].spk_pa_gain = SPK_GAIN_12DB;
  1050. wsa_pdata[wsa881x_index].component = component;
  1051. wsa_pdata[wsa881x_index].tz_pdata.component = component;
  1052. wsa_pdata[wsa881x_index].tz_pdata.wsa_temp_reg_read =
  1053. wsa881x_temp_reg_read;
  1054. snd_soc_component_set_drvdata(component, &wsa_pdata[wsa881x_index]);
  1055. while (retry) {
  1056. if (wsa_pdata[wsa881x_index].regmap[WSA881X_ANALOG_SLAVE]
  1057. != NULL)
  1058. break;
  1059. msleep(100);
  1060. retry--;
  1061. }
  1062. if (!retry)
  1063. dev_err(&client->dev, "%s: max retry expired and regmap of\n"
  1064. "analog slave not initilized\n", __func__);
  1065. wsa881x_init_thermal(&wsa_pdata[wsa881x_index].tz_pdata);
  1066. INIT_DELAYED_WORK(&wsa_pdata[wsa881x_index].ocp_ctl_work,
  1067. wsa881x_ocp_ctl_work);
  1068. if (component->name_prefix) {
  1069. widget_name = kcalloc(WIDGET_NAME_MAX_SIZE, sizeof(char),
  1070. GFP_KERNEL);
  1071. if (!widget_name)
  1072. return -ENOMEM;
  1073. snprintf(widget_name, WIDGET_NAME_MAX_SIZE,
  1074. "%s WSA_SPKR", component->name_prefix);
  1075. snd_soc_dapm_ignore_suspend(dapm, widget_name);
  1076. snprintf(widget_name, WIDGET_NAME_MAX_SIZE,
  1077. "%s WSA_IN", component->name_prefix);
  1078. snd_soc_dapm_ignore_suspend(dapm, widget_name);
  1079. kfree(widget_name);
  1080. } else {
  1081. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPKR");
  1082. snd_soc_dapm_ignore_suspend(dapm, "WSA_IN");
  1083. }
  1084. snd_soc_dapm_sync(dapm);
  1085. return 0;
  1086. }
  1087. static void wsa881x_remove(struct snd_soc_component *component)
  1088. {
  1089. struct wsa881x_pdata *wsa881x =
  1090. snd_soc_component_get_drvdata(component);
  1091. if (wsa881x->tz_pdata.tz_dev)
  1092. wsa881x_deinit_thermal(wsa881x->tz_pdata.tz_dev);
  1093. mutex_destroy(&wsa881x->bg_lock);
  1094. mutex_destroy(&wsa881x->res_lock);
  1095. }
  1096. static const struct snd_soc_component_driver soc_codec_dev_wsa881x = {
  1097. .name = "",
  1098. .probe = wsa881x_probe,
  1099. .remove = wsa881x_remove,
  1100. .read = wsa881x_i2c_read,
  1101. .write = wsa881x_i2c_write,
  1102. .controls = wsa881x_snd_controls,
  1103. .num_controls = ARRAY_SIZE(wsa881x_snd_controls),
  1104. .dapm_widgets = wsa881x_dapm_widgets,
  1105. .num_dapm_widgets = ARRAY_SIZE(wsa881x_dapm_widgets),
  1106. .dapm_routes = wsa881x_audio_map,
  1107. .num_dapm_routes = ARRAY_SIZE(wsa881x_audio_map),
  1108. };
  1109. static struct snd_soc_dai_driver wsa_dai[] = {
  1110. {
  1111. .name = "wsa_rx0",
  1112. .playback = {
  1113. .stream_name = "",
  1114. .rates = WSA881X_RATES | WSA881X_FRAC_RATES,
  1115. .formats = WSA881X_FORMATS,
  1116. .rate_max = 384000,
  1117. .rate_min = 8000,
  1118. .channels_min = 1,
  1119. .channels_max = 2,
  1120. },
  1121. },
  1122. };
  1123. static int wsa881x_reset(struct wsa881x_pdata *pdata, bool enable)
  1124. {
  1125. int ret = 0;
  1126. /*
  1127. * shutdown the GPIOs WSA_EN, WSA_MCLK, regulators
  1128. * and restore defaults in soc cache when shutdown.
  1129. * Enable regulators, GPIOs WSA_MCLK, WSA_EN when powerup.
  1130. */
  1131. if (enable) {
  1132. if (pdata->wsa_active)
  1133. return 0;
  1134. ret = msm_cdc_pinctrl_select_active_state(
  1135. pdata->wsa_reset_gpio_p);
  1136. if (ret) {
  1137. pr_err("%s: gpio set cannot be activated %s\n",
  1138. __func__, "wsa_reset");
  1139. return ret;
  1140. }
  1141. ret = msm_cdc_pinctrl_select_sleep_state(
  1142. pdata->wsa_reset_gpio_p);
  1143. if (ret) {
  1144. pr_err("%s: gpio set cannot be suspended(powerup) %s\n",
  1145. __func__, "wsa_reset");
  1146. return ret;
  1147. }
  1148. ret = msm_cdc_pinctrl_select_active_state(
  1149. pdata->wsa_reset_gpio_p);
  1150. if (ret) {
  1151. pr_err("%s: gpio set cannot be activated %s\n",
  1152. __func__, "wsa_reset");
  1153. return ret;
  1154. }
  1155. pdata->wsa_active = true;
  1156. } else {
  1157. if (!pdata->wsa_active)
  1158. return 0;
  1159. ret = msm_cdc_pinctrl_select_sleep_state(
  1160. pdata->wsa_reset_gpio_p);
  1161. if (ret) {
  1162. pr_err("%s: gpio set cannot be suspended %s\n",
  1163. __func__, "wsa_reset");
  1164. return ret;
  1165. }
  1166. pdata->wsa_active = false;
  1167. }
  1168. return ret;
  1169. }
  1170. int wsa881x_get_client_index(void)
  1171. {
  1172. return wsa881x_i2c_addr;
  1173. }
  1174. EXPORT_SYMBOL(wsa881x_get_client_index);
  1175. int wsa881x_get_probing_count(void)
  1176. {
  1177. return wsa881x_probing_count;
  1178. }
  1179. EXPORT_SYMBOL(wsa881x_get_probing_count);
  1180. int wsa881x_get_presence_count(void)
  1181. {
  1182. return wsa881x_presence_count;
  1183. }
  1184. EXPORT_SYMBOL(wsa881x_get_presence_count);
  1185. static int check_wsa881x_presence(struct i2c_client *client)
  1186. {
  1187. int ret = 0;
  1188. int wsa881x_index = 0;
  1189. ret = wsa881x_i2c_get_client_index(client, &wsa881x_index);
  1190. if (ret != 0) {
  1191. dev_err(&client->dev, "%s: I2C get codec I2C\n"
  1192. "client failed\n", __func__);
  1193. return ret;
  1194. }
  1195. ret = wsa881x_i2c_read_device(&wsa_pdata[wsa881x_index],
  1196. WSA881X_CDC_RST_CTL);
  1197. if (ret < 0) {
  1198. dev_err(&client->dev, "failed to read wsa881x with addr %x\n",
  1199. client->addr);
  1200. return ret;
  1201. }
  1202. ret = wsa881x_i2c_write_device(&wsa_pdata[wsa881x_index],
  1203. WSA881X_CDC_RST_CTL, 0x01);
  1204. if (ret < 0) {
  1205. dev_err(&client->dev, "failed write addr %x reg:0x5 val:0x1\n",
  1206. client->addr);
  1207. return ret;
  1208. }
  1209. /* allow 20ms before trigger next write to verify wsa881x presence */
  1210. msleep(20);
  1211. ret = wsa881x_i2c_write_device(&wsa_pdata[wsa881x_index],
  1212. WSA881X_CDC_RST_CTL, 0x00);
  1213. if (ret < 0) {
  1214. dev_err(&client->dev, "failed write addr %x reg:0x5 val:0x0\n",
  1215. client->addr);
  1216. return ret;
  1217. }
  1218. return ret;
  1219. }
  1220. static int wsa881x_populate_dt_pdata(struct device *dev, int wsa881x_index)
  1221. {
  1222. int ret = 0;
  1223. struct wsa881x_pdata *pdata = &wsa_pdata[wsa881x_index];
  1224. /* reading the gpio configurations from dtsi file */
  1225. pdata->wsa_vi_gpio_p = of_parse_phandle(dev->of_node,
  1226. "qcom,wsa-analog-vi-gpio", 0);
  1227. pdata->wsa_clk_gpio_p = of_parse_phandle(dev->of_node,
  1228. "qcom,wsa-analog-clk-gpio", 0);
  1229. pdata->wsa_reset_gpio_p = of_parse_phandle(dev->of_node,
  1230. "qcom,wsa-analog-reset-gpio", 0);
  1231. pinctrl_init = true;
  1232. return ret;
  1233. }
  1234. static int wsa881x_i2c_probe(struct i2c_client *client,
  1235. const struct i2c_device_id *id)
  1236. {
  1237. int ret = 0;
  1238. int wsa881x_index = 0;
  1239. struct wsa881x_pdata *pdata = NULL;
  1240. struct clk *wsa_mclk = NULL;
  1241. char buffer[MAX_NAME_LEN];
  1242. const char *wsa881x_name_prefix_of = NULL;
  1243. struct snd_soc_component *component;
  1244. ret = wsa881x_i2c_get_client_index(client, &wsa881x_index);
  1245. if (ret != 0) {
  1246. dev_err(&client->dev, "%s: I2C get codec I2C\n"
  1247. "client failed\n", __func__);
  1248. return ret;
  1249. }
  1250. pdata = &wsa_pdata[wsa881x_index];
  1251. if ((client->addr == WSA881X_I2C_SPK0_SLAVE1_ADDR ||
  1252. client->addr == WSA881X_I2C_SPK1_SLAVE1_ADDR) &&
  1253. (pdata->status == WSA881X_STATUS_PROBING)) {
  1254. wsa881x_probing_count++;
  1255. return -EPROBE_DEFER;
  1256. }
  1257. if (pdata->status == WSA881X_STATUS_I2C) {
  1258. dev_info(&client->dev, "%s:probe for other slaves\n"
  1259. "devices of codec I2C slave Addr = %x wsa_idx = %d\n",
  1260. __func__, client->addr, wsa881x_index);
  1261. dev_dbg(&client->dev, "%s:wsa_idx = %d SLAVE = %d\n",
  1262. __func__, wsa881x_index, WSA881X_ANALOG_SLAVE);
  1263. pdata->regmap[WSA881X_ANALOG_SLAVE] =
  1264. devm_regmap_init_i2c(
  1265. client,
  1266. &wsa881x_ana_regmap_config[WSA881X_ANALOG_SLAVE]);
  1267. regcache_cache_bypass(pdata->regmap[WSA881X_ANALOG_SLAVE],
  1268. true);
  1269. if (IS_ERR(pdata->regmap[WSA881X_ANALOG_SLAVE])) {
  1270. ret = PTR_ERR(pdata->regmap[WSA881X_ANALOG_SLAVE]);
  1271. dev_err(&client->dev,
  1272. "%s: regmap_init failed %d\n",
  1273. __func__, ret);
  1274. }
  1275. client->dev.platform_data = pdata;
  1276. i2c_set_clientdata(client, pdata);
  1277. pdata->client[WSA881X_ANALOG_SLAVE] = client;
  1278. pdata->regmap_flag = true;
  1279. if (pdata->version == WSA881X_2_0)
  1280. wsa881x_update_regmap_2_0(
  1281. pdata->regmap[WSA881X_ANALOG_SLAVE],
  1282. WSA881X_ANALOG_SLAVE);
  1283. wsa881x_probing_count++;
  1284. return ret;
  1285. } else if (pdata->status == WSA881X_STATUS_PROBING) {
  1286. pdata->index = wsa881x_index;
  1287. if (client->dev.of_node) {
  1288. dev_dbg(&client->dev, "%s:Platform data\n"
  1289. "from device tree\n", __func__);
  1290. ret = wsa881x_populate_dt_pdata(
  1291. &client->dev, wsa881x_index);
  1292. if (ret < 0) {
  1293. dev_err(&client->dev,
  1294. "%s: Fail to obtain pdata from device tree\n",
  1295. __func__);
  1296. ret = -EINVAL;
  1297. goto err;
  1298. }
  1299. client->dev.platform_data = pdata;
  1300. } else {
  1301. dev_dbg(&client->dev, "%s:Platform data from\n"
  1302. "board file\n", __func__);
  1303. pdata = client->dev.platform_data;
  1304. }
  1305. if (!pdata) {
  1306. dev_dbg(&client->dev, "no platform data?\n");
  1307. ret = -EINVAL;
  1308. goto err;
  1309. }
  1310. wsa_mclk = devm_clk_get(&client->dev, "wsa_mclk");
  1311. if (IS_ERR(wsa_mclk)) {
  1312. ret = PTR_ERR(wsa_mclk);
  1313. dev_dbg(&client->dev, "%s: clk get %s failed %d\n",
  1314. __func__, "wsa_mclk", ret);
  1315. wsa_mclk = NULL;
  1316. goto err;
  1317. }
  1318. pdata->wsa_mclk = wsa_mclk;
  1319. dev_set_drvdata(&client->dev, client);
  1320. pdata->regmap[WSA881X_DIGITAL_SLAVE] =
  1321. devm_regmap_init_i2c(
  1322. client,
  1323. &wsa881x_ana_regmap_config[WSA881X_DIGITAL_SLAVE]);
  1324. regcache_cache_bypass(pdata->regmap[WSA881X_DIGITAL_SLAVE],
  1325. true);
  1326. if (IS_ERR(pdata->regmap[WSA881X_DIGITAL_SLAVE])) {
  1327. ret = PTR_ERR(pdata->regmap[WSA881X_DIGITAL_SLAVE]);
  1328. dev_err(&client->dev, "%s: regmap_init failed %d\n",
  1329. __func__, ret);
  1330. goto err;
  1331. }
  1332. /* bus reset sequence */
  1333. ret = wsa881x_reset(pdata, true);
  1334. if (ret < 0) {
  1335. wsa881x_probing_count++;
  1336. dev_err(&client->dev, "%s: WSA enable Failed %d\n",
  1337. __func__, ret);
  1338. goto err;
  1339. }
  1340. pdata->client[WSA881X_DIGITAL_SLAVE] = client;
  1341. ret = check_wsa881x_presence(client);
  1342. if (ret < 0) {
  1343. dev_err(&client->dev,
  1344. "failed to ping wsa with addr:%x, ret = %d\n",
  1345. client->addr, ret);
  1346. wsa881x_probing_count++;
  1347. goto err1;
  1348. }
  1349. pdata->version = wsa881x_i2c_read_device(pdata,
  1350. WSA881X_CHIP_ID1);
  1351. pr_debug("%s: wsa881x version: %d\n", __func__, pdata->version);
  1352. if (pdata->version == WSA881X_2_0) {
  1353. wsa881x_update_reg_defaults_2_0();
  1354. wsa881x_update_regmap_2_0(
  1355. pdata->regmap[WSA881X_DIGITAL_SLAVE],
  1356. WSA881X_DIGITAL_SLAVE);
  1357. }
  1358. wsa881x_presence_count++;
  1359. wsa881x_probing_count++;
  1360. ret = of_property_read_string(client->dev.of_node,
  1361. "qcom,wsa-prefix", &wsa881x_name_prefix_of);
  1362. if (ret) {
  1363. dev_err(&client->dev,
  1364. "%s: Looking up %s property in node %s failed\n",
  1365. __func__, "qcom,wsa-prefix",
  1366. client->dev.of_node->full_name);
  1367. goto err1;
  1368. }
  1369. pdata->driver = devm_kzalloc(&client->dev,
  1370. sizeof(struct snd_soc_component_driver),
  1371. GFP_KERNEL);
  1372. if (!pdata->driver) {
  1373. ret = -ENOMEM;
  1374. goto err1;
  1375. }
  1376. memcpy(pdata->driver, &soc_codec_dev_wsa881x,
  1377. sizeof(struct snd_soc_component_driver));
  1378. pdata->dai_driver = devm_kzalloc(&client->dev,
  1379. sizeof(struct snd_soc_dai_driver),
  1380. GFP_KERNEL);
  1381. if (!pdata->dai_driver) {
  1382. ret = -ENOMEM;
  1383. goto err_mem;
  1384. }
  1385. memcpy(pdata->dai_driver, wsa_dai,
  1386. sizeof(struct snd_soc_dai_driver));
  1387. snprintf(buffer, sizeof(buffer), "wsa-codec%d", wsa881x_index);
  1388. pdata->driver->name = kstrndup(buffer,
  1389. strlen(buffer), GFP_KERNEL);
  1390. snprintf(buffer, sizeof(buffer), "wsa_rx%d", wsa881x_index);
  1391. pdata->dai_driver->name =
  1392. kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1393. snprintf(buffer, sizeof(buffer),
  1394. "WSA881X_AIF%d Playback", wsa881x_index);
  1395. pdata->dai_driver->playback.stream_name =
  1396. kstrndup(buffer, strlen(buffer), GFP_KERNEL);
  1397. /* Number of DAI's used is 1 */
  1398. ret = snd_soc_register_component(&client->dev,
  1399. pdata->driver, pdata->dai_driver, 1);
  1400. pdata->wsa881x_name_prefix = kstrndup(wsa881x_name_prefix_of,
  1401. strlen(wsa881x_name_prefix_of), GFP_KERNEL);
  1402. component = snd_soc_lookup_component(&client->dev, pdata->driver->name);
  1403. if (!component) {
  1404. dev_err(&client->dev, "%s: component is NULL \n", __func__);
  1405. ret = -EINVAL;
  1406. goto err_mem;
  1407. }
  1408. component->name_prefix = pdata->wsa881x_name_prefix;
  1409. pdata->status = WSA881X_STATUS_I2C;
  1410. dev_info(&client->dev, "%s:pdata status changed to I2C\n",
  1411. __func__);
  1412. goto err1;
  1413. }
  1414. err_mem:
  1415. kfree(pdata->wsa881x_name_prefix);
  1416. if (pdata->dai_driver) {
  1417. kfree(pdata->dai_driver->name);
  1418. kfree(pdata->dai_driver->playback.stream_name);
  1419. kfree(pdata->dai_driver);
  1420. }
  1421. if (pdata->driver) {
  1422. kfree(pdata->driver->name);
  1423. kfree(pdata->driver);
  1424. }
  1425. err1:
  1426. wsa881x_reset(pdata, false);
  1427. err:
  1428. return ret;
  1429. }
  1430. static void wsa881x_i2c_remove(struct i2c_client *client)
  1431. {
  1432. struct wsa881x_pdata *wsa881x = client->dev.platform_data;
  1433. snd_soc_unregister_component(&client->dev);
  1434. kfree(wsa881x->wsa881x_name_prefix);
  1435. if (wsa881x->dai_driver) {
  1436. kfree(wsa881x->dai_driver->name);
  1437. kfree(wsa881x->dai_driver->playback.stream_name);
  1438. kfree(wsa881x->dai_driver);
  1439. }
  1440. if (wsa881x->driver) {
  1441. kfree(wsa881x->driver->name);
  1442. kfree(wsa881x->driver);
  1443. }
  1444. i2c_set_clientdata(client, NULL);
  1445. kfree(wsa881x);
  1446. }
  1447. #ifdef CONFIG_PM_SLEEP
  1448. static int wsa881x_i2c_suspend(struct device *dev)
  1449. {
  1450. pr_debug("%s: system suspend\n", __func__);
  1451. return 0;
  1452. }
  1453. static int wsa881x_i2c_resume(struct device *dev)
  1454. {
  1455. pr_debug("%s: system resume\n", __func__);
  1456. return 0;
  1457. }
  1458. static const struct dev_pm_ops wsa881x_i2c_pm_ops = {
  1459. SET_SYSTEM_SLEEP_PM_OPS(wsa881x_i2c_suspend, wsa881x_i2c_resume)
  1460. };
  1461. #endif /* CONFIG_PM_SLEEP */
  1462. static const struct i2c_device_id wsa881x_i2c_id[] = {
  1463. {"wsa881x-i2c-dev", WSA881X_I2C_SPK0_SLAVE0_ADDR},
  1464. {"wsa881x-i2c-dev", WSA881X_I2C_SPK0_SLAVE1_ADDR},
  1465. {"wsa881x-i2c-dev", WSA881X_I2C_SPK1_SLAVE0_ADDR},
  1466. {"wsa881x-i2c-dev", WSA881X_I2C_SPK1_SLAVE1_ADDR},
  1467. {}
  1468. };
  1469. MODULE_DEVICE_TABLE(i2c, wsa881x_i2c_id);
  1470. static const struct of_device_id msm_match_table[] = {
  1471. {.compatible = "qcom,wsa881x-i2c-codec"},
  1472. {}
  1473. };
  1474. MODULE_DEVICE_TABLE(of, msm_match_table);
  1475. static struct i2c_driver wsa881x_codec_driver = {
  1476. .driver = {
  1477. .name = "wsa881x-i2c-codec",
  1478. .owner = THIS_MODULE,
  1479. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1480. #ifdef CONFIG_PM_SLEEP
  1481. .pm = &wsa881x_i2c_pm_ops,
  1482. #endif
  1483. .of_match_table = msm_match_table,
  1484. },
  1485. .id_table = wsa881x_i2c_id,
  1486. .probe = wsa881x_i2c_probe,
  1487. .remove = wsa881x_i2c_remove,
  1488. };
  1489. static int __init wsa881x_codec_init(void)
  1490. {
  1491. int i = 0;
  1492. for (i = 0; i < MAX_WSA881X_DEVICE; i++)
  1493. wsa_pdata[i].status = WSA881X_STATUS_PROBING;
  1494. return i2c_add_driver(&wsa881x_codec_driver);
  1495. }
  1496. module_init(wsa881x_codec_init);
  1497. static void __exit wsa881x_codec_exit(void)
  1498. {
  1499. i2c_del_driver(&wsa881x_codec_driver);
  1500. }
  1501. module_exit(wsa881x_codec_exit);
  1502. MODULE_DESCRIPTION("WSA881x Codec driver");
  1503. MODULE_LICENSE("GPL v2");