wcd9xxx-core.c 44 KB

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