wcd9xxx-core.c 43 KB

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