wcd9xxx-core.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  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. if (pdata->has_buck_vsel_gpio)
  1124. msm_cdc_pinctrl_select_active_state(pdata->buck_vsel_ctl_np);
  1125. device_id = slim_get_device_id(slim);
  1126. if (!device_id) {
  1127. dev_err(&slim->dev, "%s: Error, no device id\n", __func__);
  1128. ret = -EINVAL;
  1129. goto err;
  1130. }
  1131. wcd9xxx->type = device_id->driver_data;
  1132. dev_info(&slim->dev, "%s: probing for wcd type: %d, name: %s\n",
  1133. __func__, wcd9xxx->type, device_id->name);
  1134. /* wcd9xxx members init */
  1135. wcd9xxx->multi_reg_write = wcd9xxx_slim_multi_reg_write;
  1136. wcd9xxx->slim = slim;
  1137. slim_set_clientdata(slim, wcd9xxx);
  1138. wcd9xxx->reset_gpio = pdata->reset_gpio;
  1139. wcd9xxx->dev = &slim->dev;
  1140. wcd9xxx->mclk_rate = pdata->mclk_rate;
  1141. wcd9xxx->dev_up = true;
  1142. wcd9xxx->wcd_rst_np = pdata->wcd_rst_np;
  1143. wcd9xxx->regmap = wcd9xxx_regmap_init(&slim->dev,
  1144. &wcd9xxx_base_regmap_config);
  1145. if (IS_ERR(wcd9xxx->regmap)) {
  1146. ret = PTR_ERR(wcd9xxx->regmap);
  1147. dev_err(&slim->dev, "%s: Failed to allocate register map: %d\n",
  1148. __func__, ret);
  1149. goto err_codec;
  1150. }
  1151. if (!wcd9xxx->wcd_rst_np) {
  1152. pdata->use_pinctrl = false;
  1153. dev_err(&slim->dev, "%s: pinctrl not used for rst_n\n",
  1154. __func__);
  1155. goto err_codec;
  1156. }
  1157. wcd9xxx->num_of_supplies = pdata->num_supplies;
  1158. ret = msm_cdc_init_supplies(&slim->dev, &wcd9xxx->supplies,
  1159. pdata->regulator,
  1160. pdata->num_supplies);
  1161. if (!wcd9xxx->supplies) {
  1162. dev_err(wcd9xxx->dev, "%s: Cannot init wcd supplies\n",
  1163. __func__);
  1164. goto err_codec;
  1165. }
  1166. ret = msm_cdc_enable_static_supplies(wcd9xxx->dev,
  1167. wcd9xxx->supplies,
  1168. pdata->regulator,
  1169. pdata->num_supplies);
  1170. if (ret) {
  1171. dev_err(wcd9xxx->dev, "%s: wcd static supply enable failed!\n",
  1172. __func__);
  1173. goto err_codec;
  1174. }
  1175. /*
  1176. * For WCD9335, it takes about 600us for the Vout_A and
  1177. * Vout_D to be ready after BUCK_SIDO is powered up.
  1178. * SYS_RST_N shouldn't be pulled high during this time
  1179. */
  1180. if (wcd9xxx->type == WCD9335 || wcd9xxx->type == WCD934X)
  1181. usleep_range(600, 650);
  1182. else
  1183. usleep_range(5, 10);
  1184. ret = wcd9xxx_reset(&slim->dev);
  1185. if (ret) {
  1186. dev_err(&slim->dev, "%s: Resetting Codec failed\n", __func__);
  1187. goto err_supplies;
  1188. }
  1189. ret = wcd9xxx_slim_get_laddr(wcd9xxx->slim, wcd9xxx->slim->e_addr,
  1190. ARRAY_SIZE(wcd9xxx->slim->e_addr),
  1191. &wcd9xxx->slim->laddr);
  1192. if (ret) {
  1193. dev_err(&slim->dev, "%s: failed to get slimbus %s logical address: %d\n",
  1194. __func__, wcd9xxx->slim->name, ret);
  1195. goto err_reset;
  1196. }
  1197. wcd9xxx->read_dev = wcd9xxx_slim_read_device;
  1198. wcd9xxx->write_dev = wcd9xxx_slim_write_device;
  1199. wcd9xxx_pgd_la = wcd9xxx->slim->laddr;
  1200. wcd9xxx->slim_slave = &pdata->slimbus_slave_device;
  1201. if (!wcd9xxx->dev->of_node)
  1202. wcd9xxx_assign_irq(&wcd9xxx->core_res,
  1203. pdata->irq, pdata->irq_base);
  1204. ret = slim_add_device(slim->ctrl, wcd9xxx->slim_slave);
  1205. if (ret) {
  1206. dev_err(&slim->dev, "%s: error, adding SLIMBUS device failed\n",
  1207. __func__);
  1208. goto err_reset;
  1209. }
  1210. ret = wcd9xxx_slim_get_laddr(wcd9xxx->slim_slave,
  1211. wcd9xxx->slim_slave->e_addr,
  1212. ARRAY_SIZE(wcd9xxx->slim_slave->e_addr),
  1213. &wcd9xxx->slim_slave->laddr);
  1214. if (ret) {
  1215. dev_err(&slim->dev, "%s: failed to get slimbus %s logical address: %d\n",
  1216. __func__, wcd9xxx->slim->name, ret);
  1217. goto err_slim_add;
  1218. }
  1219. wcd9xxx_inf_la = wcd9xxx->slim_slave->laddr;
  1220. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_SLIMBUS);
  1221. ret = wcd9xxx_device_init(wcd9xxx);
  1222. if (ret) {
  1223. dev_err(&slim->dev, "%s: error, initializing device failed (%d)\n",
  1224. __func__, ret);
  1225. goto err_slim_add;
  1226. }
  1227. #ifdef CONFIG_DEBUG_FS
  1228. debugCodec = wcd9xxx;
  1229. debugfs_wcd9xxx_dent = debugfs_create_dir
  1230. ("wcd9xxx_core", 0);
  1231. if (!IS_ERR(debugfs_wcd9xxx_dent)) {
  1232. debugfs_peek = debugfs_create_file("slimslave_peek",
  1233. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1234. (void *) "slimslave_peek", &codec_debug_ops);
  1235. debugfs_poke = debugfs_create_file("slimslave_poke",
  1236. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1237. (void *) "slimslave_poke", &codec_debug_ops);
  1238. debugfs_power_state = debugfs_create_file("power_state",
  1239. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1240. (void *) "power_state", &codec_debug_ops);
  1241. debugfs_reg_dump = debugfs_create_file("slimslave_reg_dump",
  1242. S_IFREG | 0444, debugfs_wcd9xxx_dent,
  1243. (void *) "slimslave_reg_dump", &codec_debug_ops);
  1244. }
  1245. #endif
  1246. return ret;
  1247. err_slim_add:
  1248. slim_remove_device(wcd9xxx->slim_slave);
  1249. err_reset:
  1250. wcd9xxx_reset_low(wcd9xxx->dev);
  1251. err_supplies:
  1252. msm_cdc_release_supplies(wcd9xxx->dev, wcd9xxx->supplies,
  1253. pdata->regulator,
  1254. pdata->num_supplies);
  1255. err_codec:
  1256. slim_set_clientdata(slim, NULL);
  1257. err:
  1258. devm_kfree(&slim->dev, wcd9xxx);
  1259. return ret;
  1260. }
  1261. static int wcd9xxx_slim_remove(struct slim_device *pdev)
  1262. {
  1263. struct wcd9xxx *wcd9xxx;
  1264. struct wcd9xxx_pdata *pdata = pdev->dev.platform_data;
  1265. #ifdef CONFIG_DEBUG_FS
  1266. debugfs_remove_recursive(debugfs_wcd9xxx_dent);
  1267. #endif
  1268. wcd9xxx = slim_get_devicedata(pdev);
  1269. wcd9xxx_deinit_slimslave(wcd9xxx);
  1270. slim_remove_device(wcd9xxx->slim_slave);
  1271. msm_cdc_release_supplies(wcd9xxx->dev, wcd9xxx->supplies,
  1272. pdata->regulator,
  1273. pdata->num_supplies);
  1274. wcd9xxx_device_exit(wcd9xxx);
  1275. slim_set_clientdata(pdev, NULL);
  1276. return 0;
  1277. }
  1278. static int wcd9xxx_device_up(struct wcd9xxx *wcd9xxx)
  1279. {
  1280. int ret = 0;
  1281. struct wcd9xxx_core_resource *wcd9xxx_res = &wcd9xxx->core_res;
  1282. dev_info(wcd9xxx->dev, "%s: codec bring up\n", __func__);
  1283. wcd9xxx_bringup(wcd9xxx->dev);
  1284. ret = wcd9xxx_irq_init(wcd9xxx_res);
  1285. if (ret) {
  1286. pr_err("%s: wcd9xx_irq_init failed : %d\n", __func__, ret);
  1287. } else {
  1288. if (wcd9xxx->post_reset)
  1289. ret = wcd9xxx->post_reset(wcd9xxx);
  1290. }
  1291. return ret;
  1292. }
  1293. static int wcd9xxx_slim_device_reset(struct slim_device *sldev)
  1294. {
  1295. int ret;
  1296. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1297. if (!wcd9xxx) {
  1298. pr_err("%s: wcd9xxx is NULL\n", __func__);
  1299. return -EINVAL;
  1300. }
  1301. /*
  1302. * Wait for 500 ms for device down to complete. Observed delay
  1303. * of ~200ms for device down to complete after being called,
  1304. * due to context switch issue.
  1305. */
  1306. ret = wait_on_bit_timeout(&wcd9xxx->dev_up, 0,
  1307. TASK_INTERRUPTIBLE,
  1308. msecs_to_jiffies(500));
  1309. if (ret)
  1310. pr_err("%s: slim device down not complete in 500 msec\n",
  1311. __func__);
  1312. mutex_lock(&wcd9xxx->reset_lock);
  1313. dev_info(wcd9xxx->dev, "%s: device reset, dev_up = %lu\n",
  1314. __func__, wcd9xxx->dev_up);
  1315. if (wcd9xxx->dev_up) {
  1316. mutex_unlock(&wcd9xxx->reset_lock);
  1317. return 0;
  1318. }
  1319. ret = wcd9xxx_reset(wcd9xxx->dev);
  1320. if (ret)
  1321. dev_err(wcd9xxx->dev, "%s: Resetting Codec failed\n", __func__);
  1322. mutex_unlock(&wcd9xxx->reset_lock);
  1323. return ret;
  1324. }
  1325. static int wcd9xxx_slim_device_up(struct slim_device *sldev)
  1326. {
  1327. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1328. int ret = 0;
  1329. if (!wcd9xxx) {
  1330. pr_err("%s: wcd9xxx is NULL\n", __func__);
  1331. return -EINVAL;
  1332. }
  1333. dev_info(wcd9xxx->dev, "%s: slim device up, dev_up = %lu\n",
  1334. __func__, wcd9xxx->dev_up);
  1335. if (wcd9xxx->dev_up)
  1336. return 0;
  1337. wcd9xxx->dev_up = true;
  1338. mutex_lock(&wcd9xxx->reset_lock);
  1339. ret = wcd9xxx_device_up(wcd9xxx);
  1340. mutex_unlock(&wcd9xxx->reset_lock);
  1341. return ret;
  1342. }
  1343. static int wcd9xxx_slim_device_down(struct slim_device *sldev)
  1344. {
  1345. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1346. if (!wcd9xxx) {
  1347. pr_err("%s: wcd9xxx is NULL\n", __func__);
  1348. return -EINVAL;
  1349. }
  1350. mutex_lock(&wcd9xxx->reset_lock);
  1351. dev_info(wcd9xxx->dev, "%s: device down, dev_up = %lu\n",
  1352. __func__, wcd9xxx->dev_up);
  1353. if (!wcd9xxx->dev_up) {
  1354. mutex_unlock(&wcd9xxx->reset_lock);
  1355. return 0;
  1356. }
  1357. if (wcd9xxx->dev_down)
  1358. wcd9xxx->dev_down(wcd9xxx);
  1359. wcd9xxx_irq_exit(&wcd9xxx->core_res);
  1360. wcd9xxx_reset_low(wcd9xxx->dev);
  1361. wcd9xxx->dev_up = false;
  1362. mutex_unlock(&wcd9xxx->reset_lock);
  1363. return 0;
  1364. }
  1365. static int wcd9xxx_slim_resume(struct slim_device *sldev)
  1366. {
  1367. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1368. return wcd9xxx_core_res_resume(&wcd9xxx->core_res);
  1369. }
  1370. static int wcd9xxx_i2c_resume(struct device *dev)
  1371. {
  1372. struct wcd9xxx *wcd9xxx = dev_get_drvdata(dev);
  1373. if (wcd9xxx)
  1374. return wcd9xxx_core_res_resume(&wcd9xxx->core_res);
  1375. else
  1376. return 0;
  1377. }
  1378. static int wcd9xxx_slim_suspend(struct slim_device *sldev, pm_message_t pmesg)
  1379. {
  1380. struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev);
  1381. return wcd9xxx_core_res_suspend(&wcd9xxx->core_res, pmesg);
  1382. }
  1383. static int wcd9xxx_i2c_suspend(struct device *dev)
  1384. {
  1385. struct wcd9xxx *wcd9xxx = dev_get_drvdata(dev);
  1386. pm_message_t pmesg = {0};
  1387. if (wcd9xxx)
  1388. return wcd9xxx_core_res_suspend(&wcd9xxx->core_res, pmesg);
  1389. else
  1390. return 0;
  1391. }
  1392. static const struct slim_device_id wcd_slim_device_id[] = {
  1393. {"sitar-slim", 0},
  1394. {"sitar1p1-slim", 0},
  1395. {"tabla-slim", 0},
  1396. {"tabla2x-slim", 0},
  1397. {"taiko-slim-pgd", 0},
  1398. {"tapan-slim-pgd", 0},
  1399. {"tomtom-slim-pgd", WCD9330},
  1400. {"tasha-slim-pgd", WCD9335},
  1401. {"tavil-slim-pgd", WCD934X},
  1402. {}
  1403. };
  1404. static struct slim_driver wcd_slim_driver = {
  1405. .driver = {
  1406. .name = "wcd-slim",
  1407. .owner = THIS_MODULE,
  1408. },
  1409. .probe = wcd9xxx_slim_probe,
  1410. .remove = wcd9xxx_slim_remove,
  1411. .id_table = wcd_slim_device_id,
  1412. .resume = wcd9xxx_slim_resume,
  1413. .suspend = wcd9xxx_slim_suspend,
  1414. .device_up = wcd9xxx_slim_device_up,
  1415. .reset_device = wcd9xxx_slim_device_reset,
  1416. .device_down = wcd9xxx_slim_device_down,
  1417. };
  1418. static struct i2c_device_id wcd9xxx_id_table[] = {
  1419. {"wcd9xxx-i2c", WCD9XXX_I2C_TOP_LEVEL},
  1420. {"wcd9xxx-i2c", WCD9XXX_I2C_ANALOG},
  1421. {"wcd9xxx-i2c", WCD9XXX_I2C_DIGITAL_1},
  1422. {"wcd9xxx-i2c", WCD9XXX_I2C_DIGITAL_2},
  1423. {}
  1424. };
  1425. static struct i2c_device_id tasha_id_table[] = {
  1426. {"tasha-i2c-pgd", WCD9XXX_I2C_TOP_LEVEL},
  1427. {}
  1428. };
  1429. static struct i2c_device_id tabla_id_table[] = {
  1430. {"tabla top level", WCD9XXX_I2C_TOP_LEVEL},
  1431. {"tabla analog", WCD9XXX_I2C_ANALOG},
  1432. {"tabla digital1", WCD9XXX_I2C_DIGITAL_1},
  1433. {"tabla digital2", WCD9XXX_I2C_DIGITAL_2},
  1434. {}
  1435. };
  1436. MODULE_DEVICE_TABLE(i2c, tabla_id_table);
  1437. static const struct dev_pm_ops wcd9xxx_i2c_pm_ops = {
  1438. .suspend = wcd9xxx_i2c_suspend,
  1439. .resume = wcd9xxx_i2c_resume,
  1440. };
  1441. static struct i2c_driver tabla_i2c_driver = {
  1442. .driver = {
  1443. .owner = THIS_MODULE,
  1444. .name = "tabla-i2c-core",
  1445. .pm = &wcd9xxx_i2c_pm_ops,
  1446. },
  1447. .id_table = tabla_id_table,
  1448. .probe = wcd9xxx_i2c_probe,
  1449. .remove = wcd9xxx_i2c_remove,
  1450. };
  1451. static struct i2c_driver wcd9xxx_i2c_driver = {
  1452. .driver = {
  1453. .owner = THIS_MODULE,
  1454. .name = "wcd9xxx-i2c-core",
  1455. .pm = &wcd9xxx_i2c_pm_ops,
  1456. },
  1457. .id_table = wcd9xxx_id_table,
  1458. .probe = wcd9xxx_i2c_probe,
  1459. .remove = wcd9xxx_i2c_remove,
  1460. };
  1461. static struct i2c_driver wcd9335_i2c_driver = {
  1462. .driver = {
  1463. .owner = THIS_MODULE,
  1464. .name = "tasha-i2c-core",
  1465. .pm = &wcd9xxx_i2c_pm_ops,
  1466. },
  1467. .id_table = tasha_id_table,
  1468. .probe = wcd9xxx_i2c_probe,
  1469. .remove = wcd9xxx_i2c_remove,
  1470. };
  1471. int wcd9xxx_init(void)
  1472. {
  1473. int ret[NUM_WCD9XXX_REG_RET] = {0};
  1474. int i = 0;
  1475. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_PROBING);
  1476. ret[0] = i2c_add_driver(&tabla_i2c_driver);
  1477. if (ret[0])
  1478. pr_err("%s: Failed to add the tabla2x I2C driver: %d\n",
  1479. __func__, ret[0]);
  1480. ret[1] = i2c_add_driver(&wcd9xxx_i2c_driver);
  1481. if (ret[1])
  1482. pr_err("%s: Failed to add the wcd9xxx I2C driver: %d\n",
  1483. __func__, ret[1]);
  1484. ret[2] = i2c_add_driver(&wcd9335_i2c_driver);
  1485. if (ret[2])
  1486. pr_err("%s: Failed to add the wcd9335 I2C driver: %d\n",
  1487. __func__, ret[2]);
  1488. ret[3] = slim_driver_register(&wcd_slim_driver);
  1489. if (ret[3])
  1490. pr_err("%s: Failed to register wcd SB driver: %d\n",
  1491. __func__, ret[3]);
  1492. for (i = 0; i < NUM_WCD9XXX_REG_RET; i++) {
  1493. if (ret[i])
  1494. return ret[i];
  1495. }
  1496. return 0;
  1497. }
  1498. void wcd9xxx_exit(void)
  1499. {
  1500. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_PROBING);
  1501. i2c_del_driver(&tabla_i2c_driver);
  1502. i2c_del_driver(&wcd9xxx_i2c_driver);
  1503. i2c_del_driver(&wcd9335_i2c_driver);
  1504. slim_driver_unregister(&wcd_slim_driver);
  1505. }
  1506. MODULE_DESCRIPTION("Codec core driver");
  1507. MODULE_LICENSE("GPL v2");