wcd9xxx-core.c 44 KB

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