wcd9xxx-core.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731
  1. /* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/of_device.h>
  15. #include <linux/slab.h>
  16. #include <linux/ratelimit.h>
  17. #include <linux/mfd/core.h>
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/i2c.h>
  22. #include <linux/regmap.h>
  23. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  24. #include <sound/soc.h>
  25. #include "core.h"
  26. #include "pdata.h"
  27. #include "msm-cdc-pinctrl.h"
  28. #include "msm-cdc-supply.h"
  29. #include "wcd9xxx-irq.h"
  30. #include "wcd9xxx-utils.h"
  31. #include "wcd9xxx-regmap.h"
  32. #include "wcd9xxx-slimslave.h"
  33. #define WCD9XXX_REGISTER_START_OFFSET 0x800
  34. #define WCD9XXX_SLIM_RW_MAX_TRIES 3
  35. #define SLIMBUS_PRESENT_TIMEOUT 100
  36. #define MAX_WCD9XXX_DEVICE 4
  37. #define WCD9XXX_I2C_GSBI_SLAVE_ID "3-000d"
  38. #define WCD9XXX_I2C_TOP_SLAVE_ADDR 0x0d
  39. #define WCD9XXX_ANALOG_I2C_SLAVE_ADDR 0x77
  40. #define WCD9XXX_DIGITAL1_I2C_SLAVE_ADDR 0x66
  41. #define WCD9XXX_DIGITAL2_I2C_SLAVE_ADDR 0x55
  42. #define WCD9XXX_I2C_TOP_LEVEL 0
  43. #define WCD9XXX_I2C_ANALOG 1
  44. #define WCD9XXX_I2C_DIGITAL_1 2
  45. #define WCD9XXX_I2C_DIGITAL_2 3
  46. /*
  47. * Number of return values needs to be checked for each
  48. * registration of Slimbus of I2C bus for each codec
  49. */
  50. #define NUM_WCD9XXX_REG_RET 4
  51. #define SLIM_USR_MC_REPEAT_CHANGE_VALUE 0x0
  52. #define SLIM_REPEAT_WRITE_MAX_SLICE 16
  53. #define REG_BYTES 2
  54. #define VAL_BYTES 1
  55. #define WCD9XXX_PAGE_NUM(reg) (((reg) >> 8) & 0xff)
  56. #define WCD9XXX_PAGE_SIZE 256
  57. struct wcd9xxx_i2c {
  58. struct i2c_client *client;
  59. struct i2c_msg xfer_msg[2];
  60. struct mutex xfer_lock;
  61. int mod_id;
  62. };
  63. static struct regmap_config wcd9xxx_base_regmap_config = {
  64. .reg_bits = 16,
  65. .val_bits = 8,
  66. .can_multi_write = true,
  67. };
  68. static struct regmap_config wcd9xxx_i2c_base_regmap_config = {
  69. .reg_bits = 16,
  70. .val_bits = 8,
  71. .can_multi_write = false,
  72. .use_single_rw = true,
  73. };
  74. static u8 wcd9xxx_pgd_la;
  75. static u8 wcd9xxx_inf_la;
  76. static const int wcd9xxx_cdc_types[] = {
  77. [WCD9XXX] = WCD9XXX,
  78. [WCD9330] = WCD9330,
  79. [WCD9335] = WCD9335,
  80. [WCD934X] = WCD934X,
  81. };
  82. static const struct of_device_id wcd9xxx_of_match[] = {
  83. { .compatible = "qcom,tasha-i2c-pgd",
  84. .data = (void *)&wcd9xxx_cdc_types[WCD9335]},
  85. { .compatible = "qcom,wcd9xxx-i2c",
  86. .data = (void *)&wcd9xxx_cdc_types[WCD9330]},
  87. { }
  88. };
  89. MODULE_DEVICE_TABLE(of, wcd9xxx_of_match);
  90. static int wcd9xxx_slim_device_up(struct slim_device *sldev);
  91. static int wcd9xxx_slim_device_down(struct slim_device *sldev);
  92. struct wcd9xxx_i2c wcd9xxx_modules[MAX_WCD9XXX_DEVICE];
  93. static int wcd9xxx_slim_multi_reg_write(struct wcd9xxx *wcd9xxx,
  94. const void *data, size_t count)
  95. {
  96. unsigned int reg;
  97. struct device *dev;
  98. u8 val[WCD9XXX_PAGE_SIZE];
  99. int ret = 0;
  100. int i = 0;
  101. int n = 0;
  102. unsigned int page_num;
  103. size_t num_regs = (count / (REG_BYTES + VAL_BYTES));
  104. struct wcd9xxx_reg_val *bulk_reg;
  105. u8 *buf;
  106. dev = wcd9xxx->dev;
  107. if (!data) {
  108. dev_err(dev, "%s: data is NULL\n", __func__);
  109. return -EINVAL;
  110. }
  111. if (num_regs == 0)
  112. return -EINVAL;
  113. bulk_reg = kzalloc(num_regs * (sizeof(struct wcd9xxx_reg_val)),
  114. GFP_KERNEL);
  115. if (!bulk_reg)
  116. return -ENOMEM;
  117. buf = (u8 *)data;
  118. reg = *(u16 *)buf;
  119. page_num = WCD9XXX_PAGE_NUM(reg);
  120. for (i = 0, n = 0; n < num_regs; i++, n++) {
  121. reg = *(u16 *)buf;
  122. if (page_num != WCD9XXX_PAGE_NUM(reg)) {
  123. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg,
  124. i, false);
  125. page_num = WCD9XXX_PAGE_NUM(reg);
  126. i = 0;
  127. }
  128. buf += REG_BYTES;
  129. val[i] = *buf;
  130. buf += VAL_BYTES;
  131. bulk_reg[i].reg = reg;
  132. bulk_reg[i].buf = &val[i];
  133. bulk_reg[i].bytes = 1;
  134. }
  135. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg,
  136. i, false);
  137. if (ret)
  138. dev_err(dev, "%s: error writing bulk regs\n",
  139. __func__);
  140. kfree(bulk_reg);
  141. return ret;
  142. }
  143. /*
  144. * wcd9xxx_interface_reg_read: Read slim interface registers
  145. *
  146. * @wcd9xxx: Pointer to wcd9xxx structure
  147. * @reg: register adderss
  148. *
  149. * Returns register value in success and negative error code in case of failure
  150. */
  151. int wcd9xxx_interface_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg)
  152. {
  153. u8 val;
  154. int ret;
  155. mutex_lock(&wcd9xxx->io_lock);
  156. ret = wcd9xxx->read_dev(wcd9xxx, reg, 1, (void *)&val,
  157. true);
  158. if (ret < 0)
  159. dev_err(wcd9xxx->dev, "%s: Codec read 0x%x failed\n",
  160. __func__, reg);
  161. else
  162. dev_dbg(wcd9xxx->dev, "%s: Read 0x%02x from 0x%x\n",
  163. __func__, val, reg);
  164. mutex_unlock(&wcd9xxx->io_lock);
  165. if (ret < 0)
  166. return ret;
  167. else
  168. return val;
  169. }
  170. EXPORT_SYMBOL(wcd9xxx_interface_reg_read);
  171. /*
  172. * wcd9xxx_interface_reg_write: Write slim interface registers
  173. *
  174. * @wcd9xxx: Pointer to wcd9xxx structure
  175. * @reg: register adderss
  176. * @val: value of the register to be written
  177. *
  178. * Returns 0 for success and negative error code in case of failure
  179. */
  180. int wcd9xxx_interface_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
  181. u8 val)
  182. {
  183. int ret;
  184. mutex_lock(&wcd9xxx->io_lock);
  185. ret = wcd9xxx->write_dev(wcd9xxx, reg, 1, (void *)&val, true);
  186. dev_dbg(wcd9xxx->dev, "%s: Write %02x to 0x%x ret(%d)\n",
  187. __func__, val, reg, ret);
  188. mutex_unlock(&wcd9xxx->io_lock);
  189. return ret;
  190. }
  191. EXPORT_SYMBOL(wcd9xxx_interface_reg_write);
  192. static int wcd9xxx_slim_read_device(struct wcd9xxx *wcd9xxx, unsigned short reg,
  193. int bytes, void *dest, bool interface)
  194. {
  195. int ret;
  196. struct slim_ele_access msg;
  197. int slim_read_tries = WCD9XXX_SLIM_RW_MAX_TRIES;
  198. msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg;
  199. msg.num_bytes = bytes;
  200. msg.comp = NULL;
  201. if (!wcd9xxx->dev_up) {
  202. dev_dbg_ratelimited(
  203. wcd9xxx->dev, "%s: No read allowed. dev_up = %lu\n",
  204. __func__, wcd9xxx->dev_up);
  205. return 0;
  206. }
  207. while (1) {
  208. mutex_lock(&wcd9xxx->xfer_lock);
  209. ret = slim_request_val_element(interface ?
  210. wcd9xxx->slim_slave : wcd9xxx->slim,
  211. &msg, dest, bytes);
  212. mutex_unlock(&wcd9xxx->xfer_lock);
  213. if (likely(ret == 0) || (--slim_read_tries == 0))
  214. break;
  215. usleep_range(5000, 5100);
  216. }
  217. if (ret)
  218. dev_err(wcd9xxx->dev, "%s: Error, Codec read failed (%d)\n",
  219. __func__, ret);
  220. return ret;
  221. }
  222. /*
  223. * Interface specifies whether the write is to the interface or general
  224. * registers.
  225. */
  226. static int wcd9xxx_slim_write_device(struct wcd9xxx *wcd9xxx,
  227. unsigned short reg, int bytes, void *src, bool interface)
  228. {
  229. int ret;
  230. struct slim_ele_access msg;
  231. int slim_write_tries = WCD9XXX_SLIM_RW_MAX_TRIES;
  232. msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg;
  233. msg.num_bytes = bytes;
  234. msg.comp = NULL;
  235. if (!wcd9xxx->dev_up) {
  236. dev_dbg_ratelimited(
  237. wcd9xxx->dev, "%s: No write allowed. dev_up = %lu\n",
  238. __func__, wcd9xxx->dev_up);
  239. return 0;
  240. }
  241. while (1) {
  242. mutex_lock(&wcd9xxx->xfer_lock);
  243. ret = slim_change_val_element(interface ?
  244. wcd9xxx->slim_slave : wcd9xxx->slim,
  245. &msg, src, bytes);
  246. mutex_unlock(&wcd9xxx->xfer_lock);
  247. if (likely(ret == 0) || (--slim_write_tries == 0))
  248. break;
  249. usleep_range(5000, 5100);
  250. }
  251. if (ret)
  252. pr_err("%s: Error, Codec write failed (%d)\n", __func__, ret);
  253. return ret;
  254. }
  255. static int wcd9xxx_slim_get_allowed_slice(struct wcd9xxx *wcd9xxx,
  256. int bytes)
  257. {
  258. int allowed_sz = bytes;
  259. if (likely(bytes == SLIM_REPEAT_WRITE_MAX_SLICE))
  260. allowed_sz = 16;
  261. else if (bytes >= 12)
  262. allowed_sz = 12;
  263. else if (bytes >= 8)
  264. allowed_sz = 8;
  265. else if (bytes >= 6)
  266. allowed_sz = 6;
  267. else if (bytes >= 4)
  268. allowed_sz = 4;
  269. else
  270. allowed_sz = bytes;
  271. return allowed_sz;
  272. }
  273. /*
  274. * wcd9xxx_slim_write_repeat: Write the same register with multiple values
  275. * @wcd9xxx: handle to wcd core
  276. * @reg: register to be written
  277. * @bytes: number of bytes to be written to reg
  278. * @src: buffer with data content to be written to reg
  279. * This API will write reg with bytes from src in a single slimbus
  280. * transaction. All values from 1 to 16 are supported by this API.
  281. */
  282. int wcd9xxx_slim_write_repeat(struct wcd9xxx *wcd9xxx, unsigned short reg,
  283. int bytes, void *src)
  284. {
  285. int ret = 0, bytes_to_write = bytes, bytes_allowed;
  286. struct slim_ele_access slim_msg;
  287. mutex_lock(&wcd9xxx->io_lock);
  288. if (wcd9xxx->type == WCD9335 || wcd9xxx->type == WCD934X) {
  289. ret = wcd9xxx_page_write(wcd9xxx, &reg);
  290. if (ret)
  291. goto done;
  292. }
  293. slim_msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg;
  294. slim_msg.comp = NULL;
  295. if (unlikely(bytes > SLIM_REPEAT_WRITE_MAX_SLICE)) {
  296. dev_err(wcd9xxx->dev, "%s: size %d not supported\n",
  297. __func__, bytes);
  298. ret = -EINVAL;
  299. goto done;
  300. }
  301. if (!wcd9xxx->dev_up) {
  302. dev_dbg_ratelimited(
  303. wcd9xxx->dev, "%s: No write allowed. dev_up = %lu\n",
  304. __func__, wcd9xxx->dev_up);
  305. ret = 0;
  306. goto done;
  307. }
  308. while (bytes_to_write > 0) {
  309. bytes_allowed = wcd9xxx_slim_get_allowed_slice(wcd9xxx,
  310. bytes_to_write);
  311. slim_msg.num_bytes = bytes_allowed;
  312. mutex_lock(&wcd9xxx->xfer_lock);
  313. ret = slim_user_msg(wcd9xxx->slim, wcd9xxx->slim->laddr,
  314. SLIM_MSG_MT_DEST_REFERRED_USER,
  315. SLIM_USR_MC_REPEAT_CHANGE_VALUE,
  316. &slim_msg, src, bytes_allowed);
  317. mutex_unlock(&wcd9xxx->xfer_lock);
  318. if (ret) {
  319. dev_err(wcd9xxx->dev, "%s: failed, ret = %d\n",
  320. __func__, ret);
  321. break;
  322. }
  323. bytes_to_write = bytes_to_write - bytes_allowed;
  324. src = ((u8 *)src) + bytes_allowed;
  325. }
  326. done:
  327. mutex_unlock(&wcd9xxx->io_lock);
  328. return ret;
  329. }
  330. EXPORT_SYMBOL(wcd9xxx_slim_write_repeat);
  331. /*
  332. * wcd9xxx_slim_reserve_bw: API to reserve the slimbus bandwidth
  333. * @wcd9xxx: Handle to the wcd9xxx core
  334. * @bw_ops: value of the bandwidth that is requested
  335. * @commit: Flag to indicate if bandwidth change is to be committed
  336. * right away
  337. */
  338. int wcd9xxx_slim_reserve_bw(struct wcd9xxx *wcd9xxx,
  339. u32 bw_ops, bool commit)
  340. {
  341. if (!wcd9xxx || !wcd9xxx->slim) {
  342. pr_err("%s: Invalid handle to %s\n",
  343. __func__,
  344. (!wcd9xxx) ? "wcd9xxx" : "slim_device");
  345. return -EINVAL;
  346. }
  347. return slim_reservemsg_bw(wcd9xxx->slim, bw_ops, commit);
  348. }
  349. EXPORT_SYMBOL(wcd9xxx_slim_reserve_bw);
  350. /*
  351. * wcd9xxx_slim_bulk_write: API to write multiple registers with one descriptor
  352. * @wcd9xxx: Handle to the wcd9xxx core
  353. * @wcd9xxx_reg_val: structure holding register and values to be written
  354. * @size: Indicates number of messages to be written with one descriptor
  355. * @is_interface: Indicates whether the register is for slim interface or for
  356. * general registers.
  357. * @return: returns 0 if success or error information to the caller in case
  358. * of failure.
  359. */
  360. int wcd9xxx_slim_bulk_write(struct wcd9xxx *wcd9xxx,
  361. struct wcd9xxx_reg_val *bulk_reg,
  362. unsigned int size, bool is_interface)
  363. {
  364. int ret, i;
  365. struct slim_val_inf *msgs;
  366. unsigned short reg;
  367. if (!bulk_reg || !size || !wcd9xxx) {
  368. pr_err("%s: Invalid parameters\n", __func__);
  369. return -EINVAL;
  370. }
  371. if (!wcd9xxx->dev_up) {
  372. dev_dbg_ratelimited(
  373. wcd9xxx->dev, "%s: No write allowed. dev_up = %lu\n",
  374. __func__, wcd9xxx->dev_up);
  375. return 0;
  376. }
  377. msgs = kzalloc(size * (sizeof(struct slim_val_inf)), GFP_KERNEL);
  378. if (!msgs) {
  379. ret = -ENOMEM;
  380. goto mem_fail;
  381. }
  382. mutex_lock(&wcd9xxx->io_lock);
  383. reg = bulk_reg->reg;
  384. for (i = 0; i < size; i++) {
  385. msgs[i].start_offset = WCD9XXX_REGISTER_START_OFFSET +
  386. (bulk_reg->reg & 0xFF);
  387. msgs[i].num_bytes = bulk_reg->bytes;
  388. msgs[i].wbuf = bulk_reg->buf;
  389. bulk_reg++;
  390. }
  391. ret = wcd9xxx_page_write(wcd9xxx, &reg);
  392. if (ret) {
  393. pr_err("%s: Page write error for reg: 0x%x\n",
  394. __func__, reg);
  395. goto err;
  396. }
  397. ret = slim_bulk_msg_write(is_interface ?
  398. wcd9xxx->slim_slave : wcd9xxx->slim,
  399. SLIM_MSG_MT_CORE,
  400. SLIM_MSG_MC_CHANGE_VALUE, msgs, size,
  401. NULL, NULL);
  402. if (ret)
  403. pr_err("%s: Error, Codec bulk write failed (%d)\n",
  404. __func__, ret);
  405. /* 100 usec sleep is needed as per HW requirement */
  406. usleep_range(100, 110);
  407. err:
  408. mutex_unlock(&wcd9xxx->io_lock);
  409. kfree(msgs);
  410. mem_fail:
  411. return ret;
  412. }
  413. EXPORT_SYMBOL(wcd9xxx_slim_bulk_write);
  414. static int wcd9xxx_num_irq_regs(const struct wcd9xxx *wcd9xxx)
  415. {
  416. return (wcd9xxx->codec_type->num_irqs / 8) +
  417. ((wcd9xxx->codec_type->num_irqs % 8) ? 1 : 0);
  418. }
  419. static int wcd9xxx_regmap_init_cache(struct wcd9xxx *wcd9xxx)
  420. {
  421. struct regmap_config *regmap_config;
  422. int rc;
  423. regmap_config = wcd9xxx_get_regmap_config(wcd9xxx->type);
  424. if (!regmap_config) {
  425. dev_err(wcd9xxx->dev, "regmap config is not defined\n");
  426. return -EINVAL;
  427. }
  428. rc = regmap_reinit_cache(wcd9xxx->regmap, regmap_config);
  429. if (rc != 0) {
  430. dev_err(wcd9xxx->dev, "%s:Failed to reinit register cache: %d\n",
  431. __func__, rc);
  432. }
  433. return rc;
  434. }
  435. static int wcd9xxx_device_init(struct wcd9xxx *wcd9xxx)
  436. {
  437. int ret = 0, i;
  438. struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
  439. regmap_patch_fptr regmap_apply_patch = NULL;
  440. mutex_init(&wcd9xxx->io_lock);
  441. mutex_init(&wcd9xxx->xfer_lock);
  442. mutex_init(&wcd9xxx->reset_lock);
  443. ret = wcd9xxx_bringup(wcd9xxx->dev);
  444. if (ret) {
  445. ret = -EPROBE_DEFER;
  446. goto err_bring_up;
  447. }
  448. wcd9xxx->codec_type = devm_kzalloc(wcd9xxx->dev,
  449. sizeof(struct wcd9xxx_codec_type), GFP_KERNEL);
  450. if (!wcd9xxx->codec_type) {
  451. ret = -ENOMEM;
  452. goto err_bring_up;
  453. }
  454. ret = wcd9xxx_get_codec_info(wcd9xxx->dev);
  455. if (ret) {
  456. ret = -EPROBE_DEFER;
  457. goto fail_cdc_fill;
  458. }
  459. wcd9xxx->version = wcd9xxx->codec_type->version;
  460. if (!wcd9xxx->codec_type->dev || !wcd9xxx->codec_type->size)
  461. goto fail_cdc_fill;
  462. core_res->parent = wcd9xxx;
  463. core_res->dev = wcd9xxx->dev;
  464. core_res->intr_table = wcd9xxx->codec_type->intr_tbl;
  465. core_res->intr_table_size = wcd9xxx->codec_type->intr_tbl_size;
  466. for (i = 0; i < WCD9XXX_INTR_REG_MAX; i++)
  467. wcd9xxx->core_res.intr_reg[i] =
  468. wcd9xxx->codec_type->intr_reg[i];
  469. wcd9xxx_core_res_init(&wcd9xxx->core_res,
  470. wcd9xxx->codec_type->num_irqs,
  471. wcd9xxx_num_irq_regs(wcd9xxx),
  472. wcd9xxx->regmap);
  473. if (wcd9xxx_core_irq_init(&wcd9xxx->core_res))
  474. goto err;
  475. ret = wcd9xxx_regmap_init_cache(wcd9xxx);
  476. if (ret)
  477. goto err_irq;
  478. regmap_apply_patch = wcd9xxx_get_regmap_reg_patch(
  479. wcd9xxx->type);
  480. if (regmap_apply_patch) {
  481. ret = regmap_apply_patch(wcd9xxx->regmap,
  482. wcd9xxx->version);
  483. if (ret)
  484. dev_err(wcd9xxx->dev,
  485. "Failed to register patch: %d\n", ret);
  486. }
  487. ret = mfd_add_devices(wcd9xxx->dev, -1, wcd9xxx->codec_type->dev,
  488. wcd9xxx->codec_type->size, NULL, 0, NULL);
  489. if (ret != 0) {
  490. dev_err(wcd9xxx->dev, "Failed to add children: %d\n", ret);
  491. goto err_irq;
  492. }
  493. ret = device_init_wakeup(wcd9xxx->dev, true);
  494. if (ret) {
  495. dev_err(wcd9xxx->dev, "Device wakeup init failed: %d\n", ret);
  496. goto err_irq;
  497. }
  498. return ret;
  499. err_irq:
  500. wcd9xxx_irq_exit(&wcd9xxx->core_res);
  501. fail_cdc_fill:
  502. devm_kfree(wcd9xxx->dev, wcd9xxx->codec_type);
  503. wcd9xxx->codec_type = NULL;
  504. err:
  505. wcd9xxx_bringdown(wcd9xxx->dev);
  506. wcd9xxx_core_res_deinit(&wcd9xxx->core_res);
  507. err_bring_up:
  508. mutex_destroy(&wcd9xxx->io_lock);
  509. mutex_destroy(&wcd9xxx->xfer_lock);
  510. mutex_destroy(&wcd9xxx->reset_lock);
  511. return ret;
  512. }
  513. static void wcd9xxx_device_exit(struct wcd9xxx *wcd9xxx)
  514. {
  515. device_init_wakeup(wcd9xxx->dev, false);
  516. wcd9xxx_irq_exit(&wcd9xxx->core_res);
  517. wcd9xxx_bringdown(wcd9xxx->dev);
  518. wcd9xxx_reset_low(wcd9xxx->dev);
  519. wcd9xxx_core_res_deinit(&wcd9xxx->core_res);
  520. mutex_destroy(&wcd9xxx->io_lock);
  521. mutex_destroy(&wcd9xxx->xfer_lock);
  522. mutex_destroy(&wcd9xxx->reset_lock);
  523. if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  524. slim_remove_device(wcd9xxx->slim_slave);
  525. }
  526. #ifdef CONFIG_DEBUG_FS
  527. struct wcd9xxx *debugCodec;
  528. static struct dentry *debugfs_wcd9xxx_dent;
  529. static struct dentry *debugfs_peek;
  530. static struct dentry *debugfs_poke;
  531. static struct dentry *debugfs_power_state;
  532. static struct dentry *debugfs_reg_dump;
  533. static unsigned char read_data;
  534. static int codec_debug_open(struct inode *inode, struct file *file)
  535. {
  536. file->private_data = inode->i_private;
  537. return 0;
  538. }
  539. static int get_parameters(char *buf, long int *param1, int num_of_par)
  540. {
  541. char *token;
  542. int base, cnt;
  543. token = strsep(&buf, " ");
  544. for (cnt = 0; cnt < num_of_par; cnt++) {
  545. if (token != NULL) {
  546. if ((token[1] == 'x') || (token[1] == 'X'))
  547. base = 16;
  548. else
  549. base = 10;
  550. if (kstrtoul(token, base, &param1[cnt]) != 0)
  551. return -EINVAL;
  552. token = strsep(&buf, " ");
  553. } else
  554. return -EINVAL;
  555. }
  556. return 0;
  557. }
  558. static ssize_t wcd9xxx_slimslave_reg_show(char __user *ubuf, size_t count,
  559. loff_t *ppos)
  560. {
  561. int i, reg_val, len;
  562. ssize_t total = 0;
  563. char tmp_buf[25]; /* each line is 12 bytes but 25 for margin of error */
  564. for (i = (int) *ppos / 12; i <= SLIM_MAX_REG_ADDR; i++) {
  565. reg_val = wcd9xxx_interface_reg_read(debugCodec, i);
  566. len = snprintf(tmp_buf, sizeof(tmp_buf),
  567. "0x%.3x: 0x%.2x\n", i, reg_val);
  568. if ((total + len) >= count - 1)
  569. break;
  570. if (copy_to_user((ubuf + total), tmp_buf, len)) {
  571. pr_err("%s: fail to copy reg dump\n", __func__);
  572. total = -EFAULT;
  573. goto copy_err;
  574. }
  575. *ppos += len;
  576. total += len;
  577. }
  578. copy_err:
  579. return total;
  580. }
  581. static ssize_t codec_debug_read(struct file *file, char __user *ubuf,
  582. size_t count, loff_t *ppos)
  583. {
  584. char lbuf[8];
  585. char *access_str = file->private_data;
  586. ssize_t ret_cnt;
  587. if (*ppos < 0 || !count)
  588. return -EINVAL;
  589. if (!strcmp(access_str, "slimslave_peek")) {
  590. snprintf(lbuf, sizeof(lbuf), "0x%x\n", read_data);
  591. ret_cnt = simple_read_from_buffer(ubuf, count, ppos, lbuf,
  592. strnlen(lbuf, 7));
  593. } else if (!strcmp(access_str, "slimslave_reg_dump")) {
  594. ret_cnt = wcd9xxx_slimslave_reg_show(ubuf, count, ppos);
  595. } else {
  596. pr_err("%s: %s not permitted to read\n", __func__, access_str);
  597. ret_cnt = -EPERM;
  598. }
  599. return ret_cnt;
  600. }
  601. static void wcd9xxx_set_reset_pin_state(struct wcd9xxx *wcd9xxx,
  602. struct wcd9xxx_pdata *pdata,
  603. bool active)
  604. {
  605. if (wcd9xxx->wcd_rst_np) {
  606. if (active)
  607. msm_cdc_pinctrl_select_active_state(
  608. wcd9xxx->wcd_rst_np);
  609. else
  610. msm_cdc_pinctrl_select_sleep_state(
  611. wcd9xxx->wcd_rst_np);
  612. return;
  613. } else if (gpio_is_valid(wcd9xxx->reset_gpio)) {
  614. gpio_direction_output(wcd9xxx->reset_gpio,
  615. (active == true ? 1 : 0));
  616. }
  617. }
  618. static int codec_debug_process_cdc_power(char *lbuf)
  619. {
  620. long int param;
  621. int rc;
  622. struct wcd9xxx_pdata *pdata;
  623. if (wcd9xxx_get_intf_type() != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  624. pr_err("%s: CODEC is not in SLIMBUS mode\n", __func__);
  625. rc = -EPERM;
  626. goto error_intf;
  627. }
  628. rc = get_parameters(lbuf, &param, 1);
  629. if (likely(!rc)) {
  630. pdata = debugCodec->slim->dev.platform_data;
  631. if (param == 0) {
  632. wcd9xxx_slim_device_down(debugCodec->slim);
  633. msm_cdc_disable_static_supplies(debugCodec->dev,
  634. debugCodec->supplies,
  635. pdata->regulator,
  636. pdata->num_supplies);
  637. wcd9xxx_set_reset_pin_state(debugCodec, pdata, false);
  638. } else if (param == 1) {
  639. msm_cdc_enable_static_supplies(debugCodec->dev,
  640. debugCodec->supplies,
  641. pdata->regulator,
  642. pdata->num_supplies);
  643. usleep_range(1000, 2000);
  644. wcd9xxx_set_reset_pin_state(debugCodec, pdata, false);
  645. usleep_range(1000, 2000);
  646. wcd9xxx_set_reset_pin_state(debugCodec, pdata, true);
  647. usleep_range(1000, 2000);
  648. wcd9xxx_slim_device_up(debugCodec->slim);
  649. } else {
  650. pr_err("%s: invalid command %ld\n", __func__, param);
  651. }
  652. }
  653. error_intf:
  654. return rc;
  655. }
  656. static ssize_t codec_debug_write(struct file *filp,
  657. const char __user *ubuf, size_t cnt, loff_t *ppos)
  658. {
  659. char *access_str = filp->private_data;
  660. char lbuf[32];
  661. int rc;
  662. long int param[5];
  663. if (cnt > sizeof(lbuf) - 1)
  664. return -EINVAL;
  665. rc = copy_from_user(lbuf, ubuf, cnt);
  666. if (rc)
  667. return -EFAULT;
  668. lbuf[cnt] = '\0';
  669. if (!strcmp(access_str, "slimslave_poke")) {
  670. /* write */
  671. rc = get_parameters(lbuf, param, 2);
  672. if ((param[0] <= 0x3FF) && (param[1] <= 0xFF) &&
  673. (rc == 0))
  674. wcd9xxx_interface_reg_write(debugCodec, param[0],
  675. param[1]);
  676. else
  677. rc = -EINVAL;
  678. } else if (!strcmp(access_str, "slimslave_peek")) {
  679. /* read */
  680. rc = get_parameters(lbuf, param, 1);
  681. if ((param[0] <= 0x3FF) && (rc == 0))
  682. read_data = wcd9xxx_interface_reg_read(debugCodec,
  683. param[0]);
  684. else
  685. rc = -EINVAL;
  686. } else if (!strcmp(access_str, "power_state")) {
  687. rc = codec_debug_process_cdc_power(lbuf);
  688. }
  689. if (rc == 0)
  690. rc = cnt;
  691. else
  692. pr_err("%s: rc = %d\n", __func__, rc);
  693. return rc;
  694. }
  695. static const struct file_operations codec_debug_ops = {
  696. .open = codec_debug_open,
  697. .write = codec_debug_write,
  698. .read = codec_debug_read
  699. };
  700. #endif
  701. static struct wcd9xxx_i2c *wcd9xxx_i2c_get_device_info(struct wcd9xxx *wcd9xxx,
  702. u16 reg)
  703. {
  704. u16 mask = 0x0f00;
  705. int value = 0;
  706. struct wcd9xxx_i2c *wcd9xxx_i2c = NULL;
  707. if (wcd9xxx->type == WCD9335) {
  708. wcd9xxx_i2c = &wcd9xxx_modules[0];
  709. } else {
  710. value = ((reg & mask) >> 8) & 0x000f;
  711. switch (value) {
  712. case 0:
  713. wcd9xxx_i2c = &wcd9xxx_modules[0];
  714. break;
  715. case 1:
  716. wcd9xxx_i2c = &wcd9xxx_modules[1];
  717. break;
  718. case 2:
  719. wcd9xxx_i2c = &wcd9xxx_modules[2];
  720. break;
  721. case 3:
  722. wcd9xxx_i2c = &wcd9xxx_modules[3];
  723. break;
  724. default:
  725. break;
  726. }
  727. }
  728. return wcd9xxx_i2c;
  729. }
  730. static int wcd9xxx_i2c_write_device(struct wcd9xxx *wcd9xxx, u16 reg, u8 *value,
  731. u32 bytes)
  732. {
  733. struct i2c_msg *msg;
  734. int ret = 0;
  735. u8 reg_addr = 0;
  736. u8 data[bytes + 1];
  737. struct wcd9xxx_i2c *wcd9xxx_i2c;
  738. wcd9xxx_i2c = wcd9xxx_i2c_get_device_info(wcd9xxx, reg);
  739. if (wcd9xxx_i2c == NULL || wcd9xxx_i2c->client == NULL) {
  740. pr_err("failed to get device info\n");
  741. return -ENODEV;
  742. }
  743. reg_addr = (u8)reg;
  744. msg = &wcd9xxx_i2c->xfer_msg[0];
  745. msg->addr = wcd9xxx_i2c->client->addr;
  746. msg->len = bytes + 1;
  747. msg->flags = 0;
  748. data[0] = reg;
  749. data[1] = *value;
  750. msg->buf = data;
  751. ret = i2c_transfer(wcd9xxx_i2c->client->adapter,
  752. wcd9xxx_i2c->xfer_msg, 1);
  753. /* Try again if the write fails */
  754. if (ret != 1) {
  755. ret = i2c_transfer(wcd9xxx_i2c->client->adapter,
  756. wcd9xxx_i2c->xfer_msg, 1);
  757. if (ret != 1) {
  758. pr_err("failed to write the device\n");
  759. return ret;
  760. }
  761. }
  762. pr_debug("write success register = %x val = %x\n", reg, data[1]);
  763. return 0;
  764. }
  765. static int wcd9xxx_i2c_read_device(struct wcd9xxx *wcd9xxx, unsigned short reg,
  766. int bytes, unsigned char *dest)
  767. {
  768. struct i2c_msg *msg;
  769. int ret = 0;
  770. u8 reg_addr = 0;
  771. struct wcd9xxx_i2c *wcd9xxx_i2c;
  772. u8 i = 0;
  773. wcd9xxx_i2c = wcd9xxx_i2c_get_device_info(wcd9xxx, reg);
  774. if (wcd9xxx_i2c == NULL || wcd9xxx_i2c->client == NULL) {
  775. pr_err("failed to get device info\n");
  776. return -ENODEV;
  777. }
  778. for (i = 0; i < bytes; i++) {
  779. reg_addr = (u8)reg++;
  780. msg = &wcd9xxx_i2c->xfer_msg[0];
  781. msg->addr = wcd9xxx_i2c->client->addr;
  782. msg->len = 1;
  783. msg->flags = 0;
  784. msg->buf = &reg_addr;
  785. msg = &wcd9xxx_i2c->xfer_msg[1];
  786. msg->addr = wcd9xxx_i2c->client->addr;
  787. msg->len = 1;
  788. msg->flags = I2C_M_RD;
  789. msg->buf = dest++;
  790. ret = i2c_transfer(wcd9xxx_i2c->client->adapter,
  791. wcd9xxx_i2c->xfer_msg, 2);
  792. /* Try again if read fails first time */
  793. if (ret != 2) {
  794. ret = i2c_transfer(wcd9xxx_i2c->client->adapter,
  795. wcd9xxx_i2c->xfer_msg, 2);
  796. if (ret != 2) {
  797. pr_err("failed to read wcd9xxx register\n");
  798. return ret;
  799. }
  800. }
  801. }
  802. return 0;
  803. }
  804. int wcd9xxx_i2c_read(struct wcd9xxx *wcd9xxx, unsigned short reg,
  805. int bytes, void *dest, bool interface_reg)
  806. {
  807. return wcd9xxx_i2c_read_device(wcd9xxx, reg, bytes, dest);
  808. }
  809. int wcd9xxx_i2c_write(struct wcd9xxx *wcd9xxx, unsigned short reg,
  810. int bytes, void *src, bool interface_reg)
  811. {
  812. return wcd9xxx_i2c_write_device(wcd9xxx, reg, src, bytes);
  813. }
  814. static int wcd9xxx_i2c_get_client_index(struct i2c_client *client,
  815. int *wcd9xx_index)
  816. {
  817. int ret = 0;
  818. switch (client->addr) {
  819. case WCD9XXX_I2C_TOP_SLAVE_ADDR:
  820. *wcd9xx_index = WCD9XXX_I2C_TOP_LEVEL;
  821. break;
  822. case WCD9XXX_ANALOG_I2C_SLAVE_ADDR:
  823. *wcd9xx_index = WCD9XXX_I2C_ANALOG;
  824. break;
  825. case WCD9XXX_DIGITAL1_I2C_SLAVE_ADDR:
  826. *wcd9xx_index = WCD9XXX_I2C_DIGITAL_1;
  827. break;
  828. case WCD9XXX_DIGITAL2_I2C_SLAVE_ADDR:
  829. *wcd9xx_index = WCD9XXX_I2C_DIGITAL_2;
  830. break;
  831. default:
  832. ret = -EINVAL;
  833. break;
  834. }
  835. return ret;
  836. }
  837. static int wcd9xxx_i2c_probe(struct i2c_client *client,
  838. const struct i2c_device_id *id)
  839. {
  840. struct wcd9xxx *wcd9xxx = NULL;
  841. struct wcd9xxx_pdata *pdata = NULL;
  842. int val = 0;
  843. int ret = 0;
  844. int wcd9xx_index = 0;
  845. struct device *dev;
  846. int intf_type;
  847. const struct of_device_id *of_id;
  848. intf_type = wcd9xxx_get_intf_type();
  849. pr_debug("%s: interface status %d\n", __func__, intf_type);
  850. if (intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  851. dev_dbg(&client->dev, "%s:Codec is detected in slimbus mode\n",
  852. __func__);
  853. return -ENODEV;
  854. } else if (intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  855. ret = wcd9xxx_i2c_get_client_index(client, &wcd9xx_index);
  856. if (ret != 0)
  857. dev_err(&client->dev, "%s: I2C set codec I2C\n"
  858. "client failed\n", __func__);
  859. else {
  860. dev_err(&client->dev, "%s:probe for other slaves\n"
  861. "devices of codec I2C slave Addr = %x\n",
  862. __func__, client->addr);
  863. wcd9xxx_modules[wcd9xx_index].client = client;
  864. }
  865. return ret;
  866. } else if (intf_type == WCD9XXX_INTERFACE_TYPE_PROBING) {
  867. dev = &client->dev;
  868. if (client->dev.of_node) {
  869. dev_dbg(&client->dev, "%s:Platform data\n"
  870. "from device tree\n", __func__);
  871. pdata = wcd9xxx_populate_dt_data(&client->dev);
  872. if (!pdata) {
  873. dev_err(&client->dev,
  874. "%s: Fail to obtain pdata from device tree\n",
  875. __func__);
  876. ret = -EINVAL;
  877. goto fail;
  878. }
  879. client->dev.platform_data = pdata;
  880. } else {
  881. dev_dbg(&client->dev, "%s:Platform data from\n"
  882. "board file\n", __func__);
  883. pdata = client->dev.platform_data;
  884. }
  885. wcd9xxx = devm_kzalloc(&client->dev, sizeof(struct wcd9xxx),
  886. GFP_KERNEL);
  887. if (!wcd9xxx) {
  888. ret = -ENOMEM;
  889. goto fail;
  890. }
  891. if (!pdata) {
  892. dev_dbg(&client->dev, "no platform data?\n");
  893. ret = -EINVAL;
  894. goto fail;
  895. }
  896. wcd9xxx->type = WCD9XXX;
  897. if (client->dev.of_node) {
  898. of_id = of_match_device(wcd9xxx_of_match, &client->dev);
  899. if (of_id) {
  900. wcd9xxx->type = *((int *)of_id->data);
  901. dev_info(&client->dev, "%s: codec type is %d\n",
  902. __func__, wcd9xxx->type);
  903. }
  904. } else {
  905. dev_info(&client->dev, "%s: dev.of_node is NULL, default to WCD9XXX\n",
  906. __func__);
  907. wcd9xxx->type = WCD9XXX;
  908. }
  909. wcd9xxx->regmap = wcd9xxx_regmap_init(&client->dev,
  910. &wcd9xxx_i2c_base_regmap_config);
  911. if (IS_ERR(wcd9xxx->regmap)) {
  912. ret = PTR_ERR(wcd9xxx->regmap);
  913. dev_err(&client->dev, "%s: Failed to allocate register map: %d\n",
  914. __func__, ret);
  915. goto err_codec;
  916. }
  917. wcd9xxx->reset_gpio = pdata->reset_gpio;
  918. wcd9xxx->wcd_rst_np = pdata->wcd_rst_np;
  919. if (!wcd9xxx->wcd_rst_np) {
  920. pdata->use_pinctrl = false;
  921. dev_err(&client->dev, "%s: pinctrl not used for rst_n\n",
  922. __func__);
  923. goto err_codec;
  924. }
  925. if (i2c_check_functionality(client->adapter,
  926. I2C_FUNC_I2C) == 0) {
  927. dev_dbg(&client->dev, "can't talk I2C?\n");
  928. ret = -EIO;
  929. goto fail;
  930. }
  931. dev_set_drvdata(&client->dev, wcd9xxx);
  932. wcd9xxx->dev = &client->dev;
  933. wcd9xxx->dev_up = true;
  934. if (client->dev.of_node)
  935. wcd9xxx->mclk_rate = pdata->mclk_rate;
  936. wcd9xxx->num_of_supplies = pdata->num_supplies;
  937. ret = msm_cdc_init_supplies(wcd9xxx->dev, &wcd9xxx->supplies,
  938. pdata->regulator,
  939. pdata->num_supplies);
  940. if (!wcd9xxx->supplies) {
  941. dev_err(wcd9xxx->dev, "%s: Cannot init wcd supplies\n",
  942. __func__);
  943. goto err_codec;
  944. }
  945. ret = msm_cdc_enable_static_supplies(wcd9xxx->dev,
  946. wcd9xxx->supplies,
  947. pdata->regulator,
  948. pdata->num_supplies);
  949. if (ret) {
  950. dev_err(wcd9xxx->dev, "%s: wcd static supply enable failed!\n",
  951. __func__);
  952. goto err_codec;
  953. }
  954. /* For WCD9335, it takes about 600us for the Vout_A and
  955. * Vout_D to be ready after BUCK_SIDO is powered up\
  956. * SYS_RST_N shouldn't be pulled high during this time
  957. */
  958. if (wcd9xxx->type == WCD9335)
  959. usleep_range(600, 650);
  960. else
  961. usleep_range(5, 10);
  962. ret = wcd9xxx_reset(wcd9xxx->dev);
  963. if (ret) {
  964. pr_err("%s: Resetting Codec failed\n", __func__);
  965. goto err_supplies;
  966. }
  967. ret = wcd9xxx_i2c_get_client_index(client, &wcd9xx_index);
  968. if (ret != 0) {
  969. pr_err("%s:Set codec I2C client failed\n", __func__);
  970. goto err_supplies;
  971. }
  972. wcd9xxx_modules[wcd9xx_index].client = client;
  973. wcd9xxx->read_dev = wcd9xxx_i2c_read;
  974. wcd9xxx->write_dev = wcd9xxx_i2c_write;
  975. if (!wcd9xxx->dev->of_node)
  976. wcd9xxx_assign_irq(&wcd9xxx->core_res,
  977. pdata->irq, pdata->irq_base);
  978. ret = wcd9xxx_device_init(wcd9xxx);
  979. if (ret) {
  980. pr_err("%s: error, initializing device failed (%d)\n",
  981. __func__, ret);
  982. goto err_device_init;
  983. }
  984. ret = wcd9xxx_i2c_read(wcd9xxx, WCD9XXX_A_CHIP_STATUS, 1,
  985. &val, 0);
  986. if (ret < 0)
  987. pr_err("%s: failed to read the wcd9xxx status (%d)\n",
  988. __func__, ret);
  989. if (val != wcd9xxx->codec_type->i2c_chip_status)
  990. pr_err("%s: unknown chip status 0x%x\n", __func__, val);
  991. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_I2C);
  992. return ret;
  993. }
  994. pr_err("%s: I2C probe in wrong state\n", __func__);
  995. err_device_init:
  996. wcd9xxx_reset_low(wcd9xxx->dev);
  997. err_supplies:
  998. msm_cdc_release_supplies(wcd9xxx->dev, wcd9xxx->supplies,
  999. pdata->regulator,
  1000. pdata->num_supplies);
  1001. pdata->regulator = NULL;
  1002. pdata->num_supplies = 0;
  1003. err_codec:
  1004. devm_kfree(&client->dev, wcd9xxx);
  1005. dev_set_drvdata(&client->dev, NULL);
  1006. fail:
  1007. return ret;
  1008. }
  1009. static int wcd9xxx_i2c_remove(struct i2c_client *client)
  1010. {
  1011. struct wcd9xxx *wcd9xxx;
  1012. struct wcd9xxx_pdata *pdata = client->dev.platform_data;
  1013. wcd9xxx = dev_get_drvdata(&client->dev);
  1014. msm_cdc_release_supplies(wcd9xxx->dev, wcd9xxx->supplies,
  1015. pdata->regulator,
  1016. pdata->num_supplies);
  1017. wcd9xxx_device_exit(wcd9xxx);
  1018. dev_set_drvdata(&client->dev, NULL);
  1019. return 0;
  1020. }
  1021. static int wcd9xxx_dt_parse_slim_interface_dev_info(struct device *dev,
  1022. struct slim_device *slim_ifd)
  1023. {
  1024. int ret = 0;
  1025. struct property *prop;
  1026. ret = of_property_read_string(dev->of_node, "qcom,cdc-slim-ifd",
  1027. &slim_ifd->name);
  1028. if (ret) {
  1029. dev_err(dev, "Looking up %s property in node %s failed",
  1030. "qcom,cdc-slim-ifd-dev", dev->of_node->full_name);
  1031. return -ENODEV;
  1032. }
  1033. prop = of_find_property(dev->of_node,
  1034. "qcom,cdc-slim-ifd-elemental-addr", NULL);
  1035. if (!prop) {
  1036. dev_err(dev, "Looking up %s property in node %s failed",
  1037. "qcom,cdc-slim-ifd-elemental-addr",
  1038. dev->of_node->full_name);
  1039. return -ENODEV;
  1040. } else if (prop->length != 6) {
  1041. dev_err(dev, "invalid codec slim ifd addr. addr length = %d\n",
  1042. prop->length);
  1043. return -ENODEV;
  1044. }
  1045. memcpy(slim_ifd->e_addr, prop->value, 6);
  1046. return 0;
  1047. }
  1048. static int wcd9xxx_slim_get_laddr(struct slim_device *sb,
  1049. const u8 *e_addr, u8 e_len, u8 *laddr)
  1050. {
  1051. int ret;
  1052. const unsigned long timeout = jiffies +
  1053. msecs_to_jiffies(SLIMBUS_PRESENT_TIMEOUT);
  1054. do {
  1055. ret = slim_get_logical_addr(sb, e_addr, e_len, laddr);
  1056. if (!ret)
  1057. break;
  1058. /* Give SLIMBUS time to report present and be ready. */
  1059. usleep_range(1000, 1100);
  1060. pr_debug_ratelimited("%s: retyring get logical addr\n",
  1061. __func__);
  1062. } while time_before(jiffies, timeout);
  1063. return ret;
  1064. }
  1065. static int wcd9xxx_slim_probe(struct slim_device *slim)
  1066. {
  1067. struct wcd9xxx *wcd9xxx;
  1068. struct wcd9xxx_pdata *pdata;
  1069. const struct slim_device_id *device_id;
  1070. int ret = 0;
  1071. int intf_type;
  1072. intf_type = wcd9xxx_get_intf_type();
  1073. wcd9xxx = devm_kzalloc(&slim->dev, sizeof(struct wcd9xxx),
  1074. GFP_KERNEL);
  1075. if (!wcd9xxx) {
  1076. ret = -ENOMEM;
  1077. goto err;
  1078. }
  1079. if (!slim) {
  1080. ret = -EINVAL;
  1081. goto err;
  1082. }
  1083. if (intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  1084. dev_dbg(&slim->dev, "%s:Codec is detected in I2C mode\n",
  1085. __func__);
  1086. ret = -ENODEV;
  1087. goto err;
  1088. }
  1089. if (slim->dev.of_node) {
  1090. dev_info(&slim->dev, "Platform data from device tree\n");
  1091. pdata = wcd9xxx_populate_dt_data(&slim->dev);
  1092. if (!pdata) {
  1093. dev_err(&slim->dev,
  1094. "%s: Fail to obtain pdata from device tree\n",
  1095. __func__);
  1096. ret = -EINVAL;
  1097. goto err;
  1098. }
  1099. ret = wcd9xxx_dt_parse_slim_interface_dev_info(&slim->dev,
  1100. &pdata->slimbus_slave_device);
  1101. if (ret) {
  1102. dev_err(&slim->dev, "Error, parsing slim interface\n");
  1103. devm_kfree(&slim->dev, pdata);
  1104. ret = -EINVAL;
  1105. goto err;
  1106. }
  1107. slim->dev.platform_data = pdata;
  1108. } else {
  1109. dev_info(&slim->dev, "Platform data from board file\n");
  1110. pdata = slim->dev.platform_data;
  1111. }
  1112. if (!pdata) {
  1113. dev_err(&slim->dev, "Error, no platform data\n");
  1114. ret = -EINVAL;
  1115. goto err;
  1116. }
  1117. if (!slim->ctrl) {
  1118. dev_err(&slim->dev, "%s: Error, no SLIMBUS control data\n",
  1119. __func__);
  1120. ret = -EINVAL;
  1121. goto err_codec;
  1122. }
  1123. device_id = slim_get_device_id(slim);
  1124. if (!device_id) {
  1125. dev_err(&slim->dev, "%s: Error, no device id\n", __func__);
  1126. ret = -EINVAL;
  1127. goto err;
  1128. }
  1129. wcd9xxx->type = device_id->driver_data;
  1130. dev_info(&slim->dev, "%s: probing for wcd type: %d, name: %s\n",
  1131. __func__, wcd9xxx->type, device_id->name);
  1132. /* wcd9xxx members init */
  1133. wcd9xxx->multi_reg_write = wcd9xxx_slim_multi_reg_write;
  1134. wcd9xxx->slim = slim;
  1135. slim_set_clientdata(slim, wcd9xxx);
  1136. wcd9xxx->reset_gpio = pdata->reset_gpio;
  1137. wcd9xxx->dev = &slim->dev;
  1138. wcd9xxx->mclk_rate = pdata->mclk_rate;
  1139. wcd9xxx->dev_up = true;
  1140. wcd9xxx->wcd_rst_np = pdata->wcd_rst_np;
  1141. wcd9xxx->regmap = wcd9xxx_regmap_init(&slim->dev,
  1142. &wcd9xxx_base_regmap_config);
  1143. if (IS_ERR(wcd9xxx->regmap)) {
  1144. ret = PTR_ERR(wcd9xxx->regmap);
  1145. dev_err(&slim->dev, "%s: Failed to allocate register map: %d\n",
  1146. __func__, ret);
  1147. goto err_codec;
  1148. }
  1149. if (!wcd9xxx->wcd_rst_np) {
  1150. pdata->use_pinctrl = false;
  1151. dev_err(&slim->dev, "%s: pinctrl not used for rst_n\n",
  1152. __func__);
  1153. goto err_codec;
  1154. }
  1155. wcd9xxx->num_of_supplies = pdata->num_supplies;
  1156. ret = msm_cdc_init_supplies(&slim->dev, &wcd9xxx->supplies,
  1157. pdata->regulator,
  1158. pdata->num_supplies);
  1159. if (!wcd9xxx->supplies) {
  1160. dev_err(wcd9xxx->dev, "%s: Cannot init wcd supplies\n",
  1161. __func__);
  1162. goto err_codec;
  1163. }
  1164. ret = msm_cdc_enable_static_supplies(wcd9xxx->dev,
  1165. wcd9xxx->supplies,
  1166. pdata->regulator,
  1167. pdata->num_supplies);
  1168. if (ret) {
  1169. dev_err(wcd9xxx->dev, "%s: wcd static supply enable failed!\n",
  1170. __func__);
  1171. goto err_codec;
  1172. }
  1173. /*
  1174. * For WCD9335, it takes about 600us for the Vout_A and
  1175. * Vout_D to be ready after BUCK_SIDO is powered up.
  1176. * SYS_RST_N shouldn't be pulled high during this time
  1177. */
  1178. if (wcd9xxx->type == WCD9335 || wcd9xxx->type == WCD934X)
  1179. usleep_range(600, 650);
  1180. else
  1181. usleep_range(5, 10);
  1182. ret = wcd9xxx_reset(&slim->dev);
  1183. if (ret) {
  1184. dev_err(&slim->dev, "%s: Resetting Codec failed\n", __func__);
  1185. goto err_supplies;
  1186. }
  1187. ret = wcd9xxx_slim_get_laddr(wcd9xxx->slim, wcd9xxx->slim->e_addr,
  1188. ARRAY_SIZE(wcd9xxx->slim->e_addr),
  1189. &wcd9xxx->slim->laddr);
  1190. if (ret) {
  1191. dev_err(&slim->dev, "%s: failed to get slimbus %s logical address: %d\n",
  1192. __func__, wcd9xxx->slim->name, ret);
  1193. goto err_reset;
  1194. }
  1195. wcd9xxx->read_dev = wcd9xxx_slim_read_device;
  1196. wcd9xxx->write_dev = wcd9xxx_slim_write_device;
  1197. wcd9xxx_pgd_la = wcd9xxx->slim->laddr;
  1198. wcd9xxx->slim_slave = &pdata->slimbus_slave_device;
  1199. if (!wcd9xxx->dev->of_node)
  1200. wcd9xxx_assign_irq(&wcd9xxx->core_res,
  1201. pdata->irq, pdata->irq_base);
  1202. ret = slim_add_device(slim->ctrl, wcd9xxx->slim_slave);
  1203. if (ret) {
  1204. dev_err(&slim->dev, "%s: error, adding SLIMBUS device failed\n",
  1205. __func__);
  1206. goto err_reset;
  1207. }
  1208. ret = wcd9xxx_slim_get_laddr(wcd9xxx->slim_slave,
  1209. wcd9xxx->slim_slave->e_addr,
  1210. ARRAY_SIZE(wcd9xxx->slim_slave->e_addr),
  1211. &wcd9xxx->slim_slave->laddr);
  1212. if (ret) {
  1213. dev_err(&slim->dev, "%s: failed to get slimbus %s logical address: %d\n",
  1214. __func__, wcd9xxx->slim->name, ret);
  1215. goto err_slim_add;
  1216. }
  1217. wcd9xxx_inf_la = wcd9xxx->slim_slave->laddr;
  1218. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_SLIMBUS);
  1219. ret = wcd9xxx_device_init(wcd9xxx);
  1220. if (ret) {
  1221. dev_err(&slim->dev, "%s: error, initializing device failed (%d)\n",
  1222. __func__, ret);
  1223. goto err_slim_add;
  1224. }
  1225. #ifdef CONFIG_DEBUG_FS
  1226. debugCodec = wcd9xxx;
  1227. debugfs_wcd9xxx_dent = debugfs_create_dir
  1228. ("wcd9xxx_core", 0);
  1229. if (!IS_ERR(debugfs_wcd9xxx_dent)) {
  1230. debugfs_peek = debugfs_create_file("slimslave_peek",
  1231. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1232. (void *) "slimslave_peek", &codec_debug_ops);
  1233. debugfs_poke = debugfs_create_file("slimslave_poke",
  1234. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1235. (void *) "slimslave_poke", &codec_debug_ops);
  1236. debugfs_power_state = debugfs_create_file("power_state",
  1237. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1238. (void *) "power_state", &codec_debug_ops);
  1239. debugfs_reg_dump = debugfs_create_file("slimslave_reg_dump",
  1240. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1241. (void *) "slimslave_reg_dump", &codec_debug_ops);
  1242. }
  1243. #endif
  1244. return ret;
  1245. err_slim_add:
  1246. slim_remove_device(wcd9xxx->slim_slave);
  1247. err_reset:
  1248. wcd9xxx_reset_low(wcd9xxx->dev);
  1249. err_supplies:
  1250. msm_cdc_release_supplies(wcd9xxx->dev, wcd9xxx->supplies,
  1251. pdata->regulator,
  1252. pdata->num_supplies);
  1253. err_codec:
  1254. slim_set_clientdata(slim, NULL);
  1255. err:
  1256. devm_kfree(&slim->dev, wcd9xxx);
  1257. return ret;
  1258. }
  1259. static int wcd9xxx_slim_remove(struct slim_device *pdev)
  1260. {
  1261. struct wcd9xxx *wcd9xxx;
  1262. struct wcd9xxx_pdata *pdata = pdev->dev.platform_data;
  1263. #ifdef CONFIG_DEBUG_FS
  1264. debugfs_remove_recursive(debugfs_wcd9xxx_dent);
  1265. #endif
  1266. wcd9xxx = slim_get_devicedata(pdev);
  1267. wcd9xxx_deinit_slimslave(wcd9xxx);
  1268. slim_remove_device(wcd9xxx->slim_slave);
  1269. msm_cdc_release_supplies(wcd9xxx->dev, wcd9xxx->supplies,
  1270. pdata->regulator,
  1271. pdata->num_supplies);
  1272. wcd9xxx_device_exit(wcd9xxx);
  1273. slim_set_clientdata(pdev, NULL);
  1274. return 0;
  1275. }
  1276. static int wcd9xxx_device_up(struct wcd9xxx *wcd9xxx)
  1277. {
  1278. int ret = 0;
  1279. struct wcd9xxx_core_resource *wcd9xxx_res = &wcd9xxx->core_res;
  1280. dev_info(wcd9xxx->dev, "%s: codec bring up\n", __func__);
  1281. wcd9xxx_bringup(wcd9xxx->dev);
  1282. ret = wcd9xxx_irq_init(wcd9xxx_res);
  1283. if (ret) {
  1284. pr_err("%s: wcd9xx_irq_init failed : %d\n", __func__, ret);
  1285. } else {
  1286. if (wcd9xxx->post_reset)
  1287. ret = wcd9xxx->post_reset(wcd9xxx);
  1288. }
  1289. return ret;
  1290. }
  1291. static int wcd9xxx_slim_device_reset(struct slim_device *sldev)
  1292. {
  1293. int ret;
  1294. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1295. if (!wcd9xxx) {
  1296. pr_err("%s: wcd9xxx is NULL\n", __func__);
  1297. return -EINVAL;
  1298. }
  1299. /*
  1300. * Wait for 500 ms for device down to complete. Observed delay
  1301. * of ~200ms for device down to complete after being called,
  1302. * due to context switch issue.
  1303. */
  1304. ret = wait_on_bit_timeout(&wcd9xxx->dev_up, 0,
  1305. TASK_INTERRUPTIBLE,
  1306. msecs_to_jiffies(500));
  1307. if (ret)
  1308. pr_err("%s: slim device down not complete in 500 msec\n",
  1309. __func__);
  1310. mutex_lock(&wcd9xxx->reset_lock);
  1311. dev_info(wcd9xxx->dev, "%s: device reset, dev_up = %lu\n",
  1312. __func__, wcd9xxx->dev_up);
  1313. if (wcd9xxx->dev_up) {
  1314. mutex_unlock(&wcd9xxx->reset_lock);
  1315. return 0;
  1316. }
  1317. ret = wcd9xxx_reset(wcd9xxx->dev);
  1318. if (ret)
  1319. dev_err(wcd9xxx->dev, "%s: Resetting Codec failed\n", __func__);
  1320. mutex_unlock(&wcd9xxx->reset_lock);
  1321. return ret;
  1322. }
  1323. static int wcd9xxx_slim_device_up(struct slim_device *sldev)
  1324. {
  1325. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1326. int ret = 0;
  1327. if (!wcd9xxx) {
  1328. pr_err("%s: wcd9xxx is NULL\n", __func__);
  1329. return -EINVAL;
  1330. }
  1331. dev_info(wcd9xxx->dev, "%s: slim device up, dev_up = %lu\n",
  1332. __func__, wcd9xxx->dev_up);
  1333. if (wcd9xxx->dev_up)
  1334. return 0;
  1335. wcd9xxx->dev_up = true;
  1336. mutex_lock(&wcd9xxx->reset_lock);
  1337. ret = wcd9xxx_device_up(wcd9xxx);
  1338. mutex_unlock(&wcd9xxx->reset_lock);
  1339. return ret;
  1340. }
  1341. static int wcd9xxx_slim_device_down(struct slim_device *sldev)
  1342. {
  1343. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1344. if (!wcd9xxx) {
  1345. pr_err("%s: wcd9xxx is NULL\n", __func__);
  1346. return -EINVAL;
  1347. }
  1348. mutex_lock(&wcd9xxx->reset_lock);
  1349. dev_info(wcd9xxx->dev, "%s: device down, dev_up = %lu\n",
  1350. __func__, wcd9xxx->dev_up);
  1351. if (!wcd9xxx->dev_up) {
  1352. mutex_unlock(&wcd9xxx->reset_lock);
  1353. return 0;
  1354. }
  1355. if (wcd9xxx->dev_down)
  1356. wcd9xxx->dev_down(wcd9xxx);
  1357. wcd9xxx_irq_exit(&wcd9xxx->core_res);
  1358. wcd9xxx_reset_low(wcd9xxx->dev);
  1359. wcd9xxx->dev_up = false;
  1360. mutex_unlock(&wcd9xxx->reset_lock);
  1361. return 0;
  1362. }
  1363. static int wcd9xxx_slim_resume(struct slim_device *sldev)
  1364. {
  1365. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1366. return wcd9xxx_core_res_resume(&wcd9xxx->core_res);
  1367. }
  1368. static int wcd9xxx_i2c_resume(struct device *dev)
  1369. {
  1370. struct wcd9xxx *wcd9xxx = dev_get_drvdata(dev);
  1371. if (wcd9xxx)
  1372. return wcd9xxx_core_res_resume(&wcd9xxx->core_res);
  1373. else
  1374. return 0;
  1375. }
  1376. static int wcd9xxx_slim_suspend(struct slim_device *sldev, pm_message_t pmesg)
  1377. {
  1378. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1379. return wcd9xxx_core_res_suspend(&wcd9xxx->core_res, pmesg);
  1380. }
  1381. static int wcd9xxx_i2c_suspend(struct device *dev)
  1382. {
  1383. struct wcd9xxx *wcd9xxx = dev_get_drvdata(dev);
  1384. pm_message_t pmesg = {0};
  1385. if (wcd9xxx)
  1386. return wcd9xxx_core_res_suspend(&wcd9xxx->core_res, pmesg);
  1387. else
  1388. return 0;
  1389. }
  1390. static const struct slim_device_id wcd_slim_device_id[] = {
  1391. {"sitar-slim", 0},
  1392. {"sitar1p1-slim", 0},
  1393. {"tabla-slim", 0},
  1394. {"tabla2x-slim", 0},
  1395. {"taiko-slim-pgd", 0},
  1396. {"tapan-slim-pgd", 0},
  1397. {"tomtom-slim-pgd", WCD9330},
  1398. {"tasha-slim-pgd", WCD9335},
  1399. {"tavil-slim-pgd", WCD934X},
  1400. {}
  1401. };
  1402. static struct slim_driver wcd_slim_driver = {
  1403. .driver = {
  1404. .name = "wcd-slim",
  1405. .owner = THIS_MODULE,
  1406. },
  1407. .probe = wcd9xxx_slim_probe,
  1408. .remove = wcd9xxx_slim_remove,
  1409. .id_table = wcd_slim_device_id,
  1410. .resume = wcd9xxx_slim_resume,
  1411. .suspend = wcd9xxx_slim_suspend,
  1412. .device_up = wcd9xxx_slim_device_up,
  1413. .reset_device = wcd9xxx_slim_device_reset,
  1414. .device_down = wcd9xxx_slim_device_down,
  1415. };
  1416. static struct i2c_device_id wcd9xxx_id_table[] = {
  1417. {"wcd9xxx-i2c", WCD9XXX_I2C_TOP_LEVEL},
  1418. {"wcd9xxx-i2c", WCD9XXX_I2C_ANALOG},
  1419. {"wcd9xxx-i2c", WCD9XXX_I2C_DIGITAL_1},
  1420. {"wcd9xxx-i2c", WCD9XXX_I2C_DIGITAL_2},
  1421. {}
  1422. };
  1423. static struct i2c_device_id tasha_id_table[] = {
  1424. {"tasha-i2c-pgd", WCD9XXX_I2C_TOP_LEVEL},
  1425. {}
  1426. };
  1427. static struct i2c_device_id tabla_id_table[] = {
  1428. {"tabla top level", WCD9XXX_I2C_TOP_LEVEL},
  1429. {"tabla analog", WCD9XXX_I2C_ANALOG},
  1430. {"tabla digital1", WCD9XXX_I2C_DIGITAL_1},
  1431. {"tabla digital2", WCD9XXX_I2C_DIGITAL_2},
  1432. {}
  1433. };
  1434. MODULE_DEVICE_TABLE(i2c, tabla_id_table);
  1435. static const struct dev_pm_ops wcd9xxx_i2c_pm_ops = {
  1436. .suspend = wcd9xxx_i2c_suspend,
  1437. .resume = wcd9xxx_i2c_resume,
  1438. };
  1439. static struct i2c_driver tabla_i2c_driver = {
  1440. .driver = {
  1441. .owner = THIS_MODULE,
  1442. .name = "tabla-i2c-core",
  1443. .pm = &wcd9xxx_i2c_pm_ops,
  1444. },
  1445. .id_table = tabla_id_table,
  1446. .probe = wcd9xxx_i2c_probe,
  1447. .remove = wcd9xxx_i2c_remove,
  1448. };
  1449. static struct i2c_driver wcd9xxx_i2c_driver = {
  1450. .driver = {
  1451. .owner = THIS_MODULE,
  1452. .name = "wcd9xxx-i2c-core",
  1453. .pm = &wcd9xxx_i2c_pm_ops,
  1454. },
  1455. .id_table = wcd9xxx_id_table,
  1456. .probe = wcd9xxx_i2c_probe,
  1457. .remove = wcd9xxx_i2c_remove,
  1458. };
  1459. static struct i2c_driver wcd9335_i2c_driver = {
  1460. .driver = {
  1461. .owner = THIS_MODULE,
  1462. .name = "tasha-i2c-core",
  1463. .pm = &wcd9xxx_i2c_pm_ops,
  1464. },
  1465. .id_table = tasha_id_table,
  1466. .probe = wcd9xxx_i2c_probe,
  1467. .remove = wcd9xxx_i2c_remove,
  1468. };
  1469. int wcd9xxx_init(void)
  1470. {
  1471. int ret[NUM_WCD9XXX_REG_RET] = {0};
  1472. int i = 0;
  1473. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_PROBING);
  1474. ret[0] = i2c_add_driver(&tabla_i2c_driver);
  1475. if (ret[0])
  1476. pr_err("%s: Failed to add the tabla2x I2C driver: %d\n",
  1477. __func__, ret[0]);
  1478. ret[1] = i2c_add_driver(&wcd9xxx_i2c_driver);
  1479. if (ret[1])
  1480. pr_err("%s: Failed to add the wcd9xxx I2C driver: %d\n",
  1481. __func__, ret[1]);
  1482. ret[2] = i2c_add_driver(&wcd9335_i2c_driver);
  1483. if (ret[2])
  1484. pr_err("%s: Failed to add the wcd9335 I2C driver: %d\n",
  1485. __func__, ret[2]);
  1486. ret[3] = slim_driver_register(&wcd_slim_driver);
  1487. if (ret[3])
  1488. pr_err("%s: Failed to register wcd SB driver: %d\n",
  1489. __func__, ret[3]);
  1490. for (i = 0; i < NUM_WCD9XXX_REG_RET; i++) {
  1491. if (ret[i])
  1492. return ret[i];
  1493. }
  1494. return 0;
  1495. }
  1496. void wcd9xxx_exit(void)
  1497. {
  1498. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_PROBING);
  1499. i2c_del_driver(&tabla_i2c_driver);
  1500. i2c_del_driver(&wcd9xxx_i2c_driver);
  1501. i2c_del_driver(&wcd9335_i2c_driver);
  1502. slim_driver_unregister(&wcd_slim_driver);
  1503. }
  1504. MODULE_DESCRIPTION("Codec core driver");
  1505. MODULE_LICENSE("GPL v2");