wcd9xxx-core.c 43 KB

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