twl6040.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  1. /*
  2. * ALSA SoC TWL6040 codec driver
  3. *
  4. * Author: Misael Lopez Cruz <x0052729@ti.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/pm.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/slab.h>
  28. #include <linux/i2c/twl.h>
  29. #include <linux/mfd/twl6040.h>
  30. #include <sound/core.h>
  31. #include <sound/pcm.h>
  32. #include <sound/pcm_params.h>
  33. #include <sound/soc.h>
  34. #include <sound/initval.h>
  35. #include <sound/tlv.h>
  36. #include "twl6040.h"
  37. #define TWL6040_RATES SNDRV_PCM_RATE_8000_96000
  38. #define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
  39. #define TWL6040_OUTHS_0dB 0x00
  40. #define TWL6040_OUTHS_M30dB 0x0F
  41. #define TWL6040_OUTHF_0dB 0x03
  42. #define TWL6040_OUTHF_M52dB 0x1D
  43. #define TWL6040_RAMP_NONE 0
  44. #define TWL6040_RAMP_UP 1
  45. #define TWL6040_RAMP_DOWN 2
  46. #define TWL6040_HSL_VOL_MASK 0x0F
  47. #define TWL6040_HSL_VOL_SHIFT 0
  48. #define TWL6040_HSR_VOL_MASK 0xF0
  49. #define TWL6040_HSR_VOL_SHIFT 4
  50. #define TWL6040_HF_VOL_MASK 0x1F
  51. #define TWL6040_HF_VOL_SHIFT 0
  52. struct twl6040_output {
  53. u16 active;
  54. u16 left_vol;
  55. u16 right_vol;
  56. u16 left_step;
  57. u16 right_step;
  58. unsigned int step_delay;
  59. u16 ramp;
  60. u16 mute;
  61. struct completion ramp_done;
  62. };
  63. struct twl6040_jack_data {
  64. struct snd_soc_jack *jack;
  65. int report;
  66. };
  67. /* codec private data */
  68. struct twl6040_data {
  69. int plug_irq;
  70. int codec_powered;
  71. int pll;
  72. int non_lp;
  73. int pll_power_mode;
  74. int hs_power_mode;
  75. int hs_power_mode_locked;
  76. unsigned int clk_in;
  77. unsigned int sysclk;
  78. u16 hs_left_step;
  79. u16 hs_right_step;
  80. u16 hf_left_step;
  81. u16 hf_right_step;
  82. struct twl6040_jack_data hs_jack;
  83. struct snd_soc_codec *codec;
  84. struct workqueue_struct *workqueue;
  85. struct delayed_work delayed_work;
  86. struct mutex mutex;
  87. struct twl6040_output headset;
  88. struct twl6040_output handsfree;
  89. struct workqueue_struct *hf_workqueue;
  90. struct workqueue_struct *hs_workqueue;
  91. struct delayed_work hs_delayed_work;
  92. struct delayed_work hf_delayed_work;
  93. };
  94. /*
  95. * twl6040 register cache & default register settings
  96. */
  97. static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
  98. 0x00, /* not used 0x00 */
  99. 0x4B, /* TWL6040_ASICID (ro) 0x01 */
  100. 0x00, /* TWL6040_ASICREV (ro) 0x02 */
  101. 0x00, /* TWL6040_INTID 0x03 */
  102. 0x00, /* TWL6040_INTMR 0x04 */
  103. 0x00, /* TWL6040_NCPCTRL 0x05 */
  104. 0x00, /* TWL6040_LDOCTL 0x06 */
  105. 0x60, /* TWL6040_HPPLLCTL 0x07 */
  106. 0x00, /* TWL6040_LPPLLCTL 0x08 */
  107. 0x4A, /* TWL6040_LPPLLDIV 0x09 */
  108. 0x00, /* TWL6040_AMICBCTL 0x0A */
  109. 0x00, /* TWL6040_DMICBCTL 0x0B */
  110. 0x18, /* TWL6040_MICLCTL 0x0C - No input selected on Left Mic */
  111. 0x18, /* TWL6040_MICRCTL 0x0D - No input selected on Right Mic */
  112. 0x00, /* TWL6040_MICGAIN 0x0E */
  113. 0x1B, /* TWL6040_LINEGAIN 0x0F */
  114. 0x00, /* TWL6040_HSLCTL 0x10 */
  115. 0x00, /* TWL6040_HSRCTL 0x11 */
  116. 0x00, /* TWL6040_HSGAIN 0x12 */
  117. 0x00, /* TWL6040_EARCTL 0x13 */
  118. 0x00, /* TWL6040_HFLCTL 0x14 */
  119. 0x00, /* TWL6040_HFLGAIN 0x15 */
  120. 0x00, /* TWL6040_HFRCTL 0x16 */
  121. 0x00, /* TWL6040_HFRGAIN 0x17 */
  122. 0x00, /* TWL6040_VIBCTLL 0x18 */
  123. 0x00, /* TWL6040_VIBDATL 0x19 */
  124. 0x00, /* TWL6040_VIBCTLR 0x1A */
  125. 0x00, /* TWL6040_VIBDATR 0x1B */
  126. 0x00, /* TWL6040_HKCTL1 0x1C */
  127. 0x00, /* TWL6040_HKCTL2 0x1D */
  128. 0x00, /* TWL6040_GPOCTL 0x1E */
  129. 0x00, /* TWL6040_ALB 0x1F */
  130. 0x00, /* TWL6040_DLB 0x20 */
  131. 0x00, /* not used 0x21 */
  132. 0x00, /* not used 0x22 */
  133. 0x00, /* not used 0x23 */
  134. 0x00, /* not used 0x24 */
  135. 0x00, /* not used 0x25 */
  136. 0x00, /* not used 0x26 */
  137. 0x00, /* not used 0x27 */
  138. 0x00, /* TWL6040_TRIM1 0x28 */
  139. 0x00, /* TWL6040_TRIM2 0x29 */
  140. 0x00, /* TWL6040_TRIM3 0x2A */
  141. 0x00, /* TWL6040_HSOTRIM 0x2B */
  142. 0x00, /* TWL6040_HFOTRIM 0x2C */
  143. 0x09, /* TWL6040_ACCCTL 0x2D */
  144. 0x00, /* TWL6040_STATUS (ro) 0x2E */
  145. };
  146. /*
  147. * twl6040 vio/gnd registers:
  148. * registers under vio/gnd supply can be accessed
  149. * before the power-up sequence, after NRESPWRON goes high
  150. */
  151. static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = {
  152. TWL6040_REG_ASICID,
  153. TWL6040_REG_ASICREV,
  154. TWL6040_REG_INTID,
  155. TWL6040_REG_INTMR,
  156. TWL6040_REG_NCPCTL,
  157. TWL6040_REG_LDOCTL,
  158. TWL6040_REG_AMICBCTL,
  159. TWL6040_REG_DMICBCTL,
  160. TWL6040_REG_HKCTL1,
  161. TWL6040_REG_HKCTL2,
  162. TWL6040_REG_GPOCTL,
  163. TWL6040_REG_TRIM1,
  164. TWL6040_REG_TRIM2,
  165. TWL6040_REG_TRIM3,
  166. TWL6040_REG_HSOTRIM,
  167. TWL6040_REG_HFOTRIM,
  168. TWL6040_REG_ACCCTL,
  169. TWL6040_REG_STATUS,
  170. };
  171. /*
  172. * twl6040 vdd/vss registers:
  173. * registers under vdd/vss supplies can only be accessed
  174. * after the power-up sequence
  175. */
  176. static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = {
  177. TWL6040_REG_HPPLLCTL,
  178. TWL6040_REG_LPPLLCTL,
  179. TWL6040_REG_LPPLLDIV,
  180. TWL6040_REG_MICLCTL,
  181. TWL6040_REG_MICRCTL,
  182. TWL6040_REG_MICGAIN,
  183. TWL6040_REG_LINEGAIN,
  184. TWL6040_REG_HSLCTL,
  185. TWL6040_REG_HSRCTL,
  186. TWL6040_REG_HSGAIN,
  187. TWL6040_REG_EARCTL,
  188. TWL6040_REG_HFLCTL,
  189. TWL6040_REG_HFLGAIN,
  190. TWL6040_REG_HFRCTL,
  191. TWL6040_REG_HFRGAIN,
  192. TWL6040_REG_VIBCTLL,
  193. TWL6040_REG_VIBDATL,
  194. TWL6040_REG_VIBCTLR,
  195. TWL6040_REG_VIBDATR,
  196. TWL6040_REG_ALB,
  197. TWL6040_REG_DLB,
  198. };
  199. /* set of rates for each pll: low-power and high-performance */
  200. static unsigned int lp_rates[] = {
  201. 8000,
  202. 11250,
  203. 16000,
  204. 22500,
  205. 32000,
  206. 44100,
  207. 48000,
  208. 88200,
  209. 96000,
  210. };
  211. static unsigned int hp_rates[] = {
  212. 8000,
  213. 16000,
  214. 32000,
  215. 48000,
  216. 96000,
  217. };
  218. static struct snd_pcm_hw_constraint_list sysclk_constraints[] = {
  219. { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, },
  220. { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, },
  221. };
  222. /*
  223. * read twl6040 register cache
  224. */
  225. static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec,
  226. unsigned int reg)
  227. {
  228. u8 *cache = codec->reg_cache;
  229. if (reg >= TWL6040_CACHEREGNUM)
  230. return -EIO;
  231. return cache[reg];
  232. }
  233. /*
  234. * write twl6040 register cache
  235. */
  236. static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec,
  237. u8 reg, u8 value)
  238. {
  239. u8 *cache = codec->reg_cache;
  240. if (reg >= TWL6040_CACHEREGNUM)
  241. return;
  242. cache[reg] = value;
  243. }
  244. /*
  245. * read from twl6040 hardware register
  246. */
  247. static int twl6040_read_reg_volatile(struct snd_soc_codec *codec,
  248. unsigned int reg)
  249. {
  250. struct twl6040 *twl6040 = codec->control_data;
  251. u8 value;
  252. if (reg >= TWL6040_CACHEREGNUM)
  253. return -EIO;
  254. value = twl6040_reg_read(twl6040, reg);
  255. twl6040_write_reg_cache(codec, reg, value);
  256. return value;
  257. }
  258. /*
  259. * write to the twl6040 register space
  260. */
  261. static int twl6040_write(struct snd_soc_codec *codec,
  262. unsigned int reg, unsigned int value)
  263. {
  264. struct twl6040 *twl6040 = codec->control_data;
  265. if (reg >= TWL6040_CACHEREGNUM)
  266. return -EIO;
  267. twl6040_write_reg_cache(codec, reg, value);
  268. return twl6040_reg_write(twl6040, reg, value);
  269. }
  270. static void twl6040_init_vio_regs(struct snd_soc_codec *codec)
  271. {
  272. u8 *cache = codec->reg_cache;
  273. int reg, i;
  274. for (i = 0; i < TWL6040_VIOREGNUM; i++) {
  275. reg = twl6040_vio_reg[i];
  276. /*
  277. * skip read-only registers (ASICID, ASICREV, STATUS)
  278. * and registers shared among MFD children
  279. */
  280. switch (reg) {
  281. case TWL6040_REG_ASICID:
  282. case TWL6040_REG_ASICREV:
  283. case TWL6040_REG_INTID:
  284. case TWL6040_REG_INTMR:
  285. case TWL6040_REG_NCPCTL:
  286. case TWL6040_REG_LDOCTL:
  287. case TWL6040_REG_GPOCTL:
  288. case TWL6040_REG_ACCCTL:
  289. case TWL6040_REG_STATUS:
  290. continue;
  291. default:
  292. break;
  293. }
  294. twl6040_write(codec, reg, cache[reg]);
  295. }
  296. }
  297. static void twl6040_init_vdd_regs(struct snd_soc_codec *codec)
  298. {
  299. u8 *cache = codec->reg_cache;
  300. int reg, i;
  301. for (i = 0; i < TWL6040_VDDREGNUM; i++) {
  302. reg = twl6040_vdd_reg[i];
  303. /* skip vibra and PLL registers */
  304. switch (reg) {
  305. case TWL6040_REG_VIBCTLL:
  306. case TWL6040_REG_VIBDATL:
  307. case TWL6040_REG_VIBCTLR:
  308. case TWL6040_REG_VIBDATR:
  309. case TWL6040_REG_HPPLLCTL:
  310. case TWL6040_REG_LPPLLCTL:
  311. case TWL6040_REG_LPPLLDIV:
  312. continue;
  313. default:
  314. break;
  315. }
  316. twl6040_write(codec, reg, cache[reg]);
  317. }
  318. }
  319. /*
  320. * Ramp HS PGA volume to minimise pops at stream startup and shutdown.
  321. */
  322. static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
  323. unsigned int left_step, unsigned int right_step)
  324. {
  325. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  326. struct twl6040_output *headset = &priv->headset;
  327. int left_complete = 0, right_complete = 0;
  328. u8 reg, val;
  329. /* left channel */
  330. left_step = (left_step > 0xF) ? 0xF : left_step;
  331. reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN);
  332. val = (~reg & TWL6040_HSL_VOL_MASK);
  333. if (headset->ramp == TWL6040_RAMP_UP) {
  334. /* ramp step up */
  335. if (val < headset->left_vol) {
  336. if (val + left_step > headset->left_vol)
  337. val = headset->left_vol;
  338. else
  339. val += left_step;
  340. reg &= ~TWL6040_HSL_VOL_MASK;
  341. twl6040_write(codec, TWL6040_REG_HSGAIN,
  342. (reg | (~val & TWL6040_HSL_VOL_MASK)));
  343. } else {
  344. left_complete = 1;
  345. }
  346. } else if (headset->ramp == TWL6040_RAMP_DOWN) {
  347. /* ramp step down */
  348. if (val > 0x0) {
  349. if ((int)val - (int)left_step < 0)
  350. val = 0;
  351. else
  352. val -= left_step;
  353. reg &= ~TWL6040_HSL_VOL_MASK;
  354. twl6040_write(codec, TWL6040_REG_HSGAIN, reg |
  355. (~val & TWL6040_HSL_VOL_MASK));
  356. } else {
  357. left_complete = 1;
  358. }
  359. }
  360. /* right channel */
  361. right_step = (right_step > 0xF) ? 0xF : right_step;
  362. reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN);
  363. val = (~reg & TWL6040_HSR_VOL_MASK) >> TWL6040_HSR_VOL_SHIFT;
  364. if (headset->ramp == TWL6040_RAMP_UP) {
  365. /* ramp step up */
  366. if (val < headset->right_vol) {
  367. if (val + right_step > headset->right_vol)
  368. val = headset->right_vol;
  369. else
  370. val += right_step;
  371. reg &= ~TWL6040_HSR_VOL_MASK;
  372. twl6040_write(codec, TWL6040_REG_HSGAIN,
  373. (reg | (~val << TWL6040_HSR_VOL_SHIFT)));
  374. } else {
  375. right_complete = 1;
  376. }
  377. } else if (headset->ramp == TWL6040_RAMP_DOWN) {
  378. /* ramp step down */
  379. if (val > 0x0) {
  380. if ((int)val - (int)right_step < 0)
  381. val = 0;
  382. else
  383. val -= right_step;
  384. reg &= ~TWL6040_HSR_VOL_MASK;
  385. twl6040_write(codec, TWL6040_REG_HSGAIN,
  386. reg | (~val << TWL6040_HSR_VOL_SHIFT));
  387. } else {
  388. right_complete = 1;
  389. }
  390. }
  391. return left_complete & right_complete;
  392. }
  393. /*
  394. * Ramp HF PGA volume to minimise pops at stream startup and shutdown.
  395. */
  396. static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
  397. unsigned int left_step, unsigned int right_step)
  398. {
  399. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  400. struct twl6040_output *handsfree = &priv->handsfree;
  401. int left_complete = 0, right_complete = 0;
  402. u16 reg, val;
  403. /* left channel */
  404. left_step = (left_step > 0x1D) ? 0x1D : left_step;
  405. reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFLGAIN);
  406. reg = 0x1D - reg;
  407. val = (reg & TWL6040_HF_VOL_MASK);
  408. if (handsfree->ramp == TWL6040_RAMP_UP) {
  409. /* ramp step up */
  410. if (val < handsfree->left_vol) {
  411. if (val + left_step > handsfree->left_vol)
  412. val = handsfree->left_vol;
  413. else
  414. val += left_step;
  415. reg &= ~TWL6040_HF_VOL_MASK;
  416. twl6040_write(codec, TWL6040_REG_HFLGAIN,
  417. reg | (0x1D - val));
  418. } else {
  419. left_complete = 1;
  420. }
  421. } else if (handsfree->ramp == TWL6040_RAMP_DOWN) {
  422. /* ramp step down */
  423. if (val > 0) {
  424. if ((int)val - (int)left_step < 0)
  425. val = 0;
  426. else
  427. val -= left_step;
  428. reg &= ~TWL6040_HF_VOL_MASK;
  429. twl6040_write(codec, TWL6040_REG_HFLGAIN,
  430. reg | (0x1D - val));
  431. } else {
  432. left_complete = 1;
  433. }
  434. }
  435. /* right channel */
  436. right_step = (right_step > 0x1D) ? 0x1D : right_step;
  437. reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFRGAIN);
  438. reg = 0x1D - reg;
  439. val = (reg & TWL6040_HF_VOL_MASK);
  440. if (handsfree->ramp == TWL6040_RAMP_UP) {
  441. /* ramp step up */
  442. if (val < handsfree->right_vol) {
  443. if (val + right_step > handsfree->right_vol)
  444. val = handsfree->right_vol;
  445. else
  446. val += right_step;
  447. reg &= ~TWL6040_HF_VOL_MASK;
  448. twl6040_write(codec, TWL6040_REG_HFRGAIN,
  449. reg | (0x1D - val));
  450. } else {
  451. right_complete = 1;
  452. }
  453. } else if (handsfree->ramp == TWL6040_RAMP_DOWN) {
  454. /* ramp step down */
  455. if (val > 0) {
  456. if ((int)val - (int)right_step < 0)
  457. val = 0;
  458. else
  459. val -= right_step;
  460. reg &= ~TWL6040_HF_VOL_MASK;
  461. twl6040_write(codec, TWL6040_REG_HFRGAIN,
  462. reg | (0x1D - val));
  463. }
  464. }
  465. return left_complete & right_complete;
  466. }
  467. /*
  468. * This work ramps both output PGAs at stream start/stop time to
  469. * minimise pop associated with DAPM power switching.
  470. */
  471. static void twl6040_pga_hs_work(struct work_struct *work)
  472. {
  473. struct twl6040_data *priv =
  474. container_of(work, struct twl6040_data, hs_delayed_work.work);
  475. struct snd_soc_codec *codec = priv->codec;
  476. struct twl6040_output *headset = &priv->headset;
  477. unsigned int delay = headset->step_delay;
  478. int i, headset_complete;
  479. /* do we need to ramp at all ? */
  480. if (headset->ramp == TWL6040_RAMP_NONE)
  481. return;
  482. /* HS PGA volumes have 4 bits of resolution to ramp */
  483. for (i = 0; i <= 16; i++) {
  484. headset_complete = twl6040_hs_ramp_step(codec,
  485. headset->left_step,
  486. headset->right_step);
  487. /* ramp finished ? */
  488. if (headset_complete)
  489. break;
  490. /*
  491. * TODO: tune: delay is longer over 0dB
  492. * as increases are larger.
  493. */
  494. if (i >= 8)
  495. schedule_timeout_interruptible(msecs_to_jiffies(delay +
  496. (delay >> 1)));
  497. else
  498. schedule_timeout_interruptible(msecs_to_jiffies(delay));
  499. }
  500. if (headset->ramp == TWL6040_RAMP_DOWN) {
  501. headset->active = 0;
  502. complete(&headset->ramp_done);
  503. } else {
  504. headset->active = 1;
  505. }
  506. headset->ramp = TWL6040_RAMP_NONE;
  507. }
  508. static void twl6040_pga_hf_work(struct work_struct *work)
  509. {
  510. struct twl6040_data *priv =
  511. container_of(work, struct twl6040_data, hf_delayed_work.work);
  512. struct snd_soc_codec *codec = priv->codec;
  513. struct twl6040_output *handsfree = &priv->handsfree;
  514. unsigned int delay = handsfree->step_delay;
  515. int i, handsfree_complete;
  516. /* do we need to ramp at all ? */
  517. if (handsfree->ramp == TWL6040_RAMP_NONE)
  518. return;
  519. /* HF PGA volumes have 5 bits of resolution to ramp */
  520. for (i = 0; i <= 32; i++) {
  521. handsfree_complete = twl6040_hf_ramp_step(codec,
  522. handsfree->left_step,
  523. handsfree->right_step);
  524. /* ramp finished ? */
  525. if (handsfree_complete)
  526. break;
  527. /*
  528. * TODO: tune: delay is longer over 0dB
  529. * as increases are larger.
  530. */
  531. if (i >= 16)
  532. schedule_timeout_interruptible(msecs_to_jiffies(delay +
  533. (delay >> 1)));
  534. else
  535. schedule_timeout_interruptible(msecs_to_jiffies(delay));
  536. }
  537. if (handsfree->ramp == TWL6040_RAMP_DOWN) {
  538. handsfree->active = 0;
  539. complete(&handsfree->ramp_done);
  540. } else
  541. handsfree->active = 1;
  542. handsfree->ramp = TWL6040_RAMP_NONE;
  543. }
  544. static int pga_event(struct snd_soc_dapm_widget *w,
  545. struct snd_kcontrol *kcontrol, int event)
  546. {
  547. struct snd_soc_codec *codec = w->codec;
  548. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  549. struct twl6040_output *out;
  550. struct delayed_work *work;
  551. struct workqueue_struct *queue;
  552. switch (w->shift) {
  553. case 2:
  554. case 3:
  555. out = &priv->headset;
  556. work = &priv->hs_delayed_work;
  557. queue = priv->hs_workqueue;
  558. out->left_step = priv->hs_left_step;
  559. out->right_step = priv->hs_right_step;
  560. out->step_delay = 5; /* 5 ms between volume ramp steps */
  561. break;
  562. case 4:
  563. out = &priv->handsfree;
  564. work = &priv->hf_delayed_work;
  565. queue = priv->hf_workqueue;
  566. out->left_step = priv->hf_left_step;
  567. out->right_step = priv->hf_right_step;
  568. out->step_delay = 5; /* 5 ms between volume ramp steps */
  569. if (SND_SOC_DAPM_EVENT_ON(event))
  570. priv->non_lp++;
  571. else
  572. priv->non_lp--;
  573. break;
  574. default:
  575. return -1;
  576. }
  577. switch (event) {
  578. case SND_SOC_DAPM_POST_PMU:
  579. if (out->active)
  580. break;
  581. /* don't use volume ramp for power-up */
  582. out->left_step = out->left_vol;
  583. out->right_step = out->right_vol;
  584. if (!delayed_work_pending(work)) {
  585. out->ramp = TWL6040_RAMP_UP;
  586. queue_delayed_work(queue, work,
  587. msecs_to_jiffies(1));
  588. }
  589. break;
  590. case SND_SOC_DAPM_PRE_PMD:
  591. if (!out->active)
  592. break;
  593. if (!delayed_work_pending(work)) {
  594. /* use volume ramp for power-down */
  595. out->ramp = TWL6040_RAMP_DOWN;
  596. INIT_COMPLETION(out->ramp_done);
  597. queue_delayed_work(queue, work,
  598. msecs_to_jiffies(1));
  599. wait_for_completion_timeout(&out->ramp_done,
  600. msecs_to_jiffies(2000));
  601. }
  602. break;
  603. }
  604. return 0;
  605. }
  606. /* set headset dac and driver power mode */
  607. static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
  608. {
  609. int hslctl, hsrctl;
  610. int mask = TWL6040_HSDRVMODEL | TWL6040_HSDACMODEL;
  611. hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
  612. hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
  613. if (high_perf) {
  614. hslctl &= ~mask;
  615. hsrctl &= ~mask;
  616. } else {
  617. hslctl |= mask;
  618. hsrctl |= mask;
  619. }
  620. twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
  621. twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
  622. return 0;
  623. }
  624. static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
  625. struct snd_kcontrol *kcontrol, int event)
  626. {
  627. msleep(1);
  628. return 0;
  629. }
  630. static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
  631. struct snd_kcontrol *kcontrol, int event)
  632. {
  633. struct snd_soc_codec *codec = w->codec;
  634. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  635. int ret = 0;
  636. if (SND_SOC_DAPM_EVENT_ON(event)) {
  637. priv->non_lp++;
  638. if (!strcmp(w->name, "Earphone Driver")) {
  639. /* Earphone doesn't support low power mode */
  640. priv->hs_power_mode_locked = 1;
  641. ret = headset_power_mode(codec, 1);
  642. }
  643. } else {
  644. priv->non_lp--;
  645. if (!strcmp(w->name, "Earphone Driver")) {
  646. priv->hs_power_mode_locked = 0;
  647. ret = headset_power_mode(codec, priv->hs_power_mode);
  648. }
  649. }
  650. msleep(1);
  651. return ret;
  652. }
  653. static void twl6040_hs_jack_report(struct snd_soc_codec *codec,
  654. struct snd_soc_jack *jack, int report)
  655. {
  656. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  657. int status;
  658. mutex_lock(&priv->mutex);
  659. /* Sync status */
  660. status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS);
  661. if (status & TWL6040_PLUGCOMP)
  662. snd_soc_jack_report(jack, report, report);
  663. else
  664. snd_soc_jack_report(jack, 0, report);
  665. mutex_unlock(&priv->mutex);
  666. }
  667. void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
  668. struct snd_soc_jack *jack, int report)
  669. {
  670. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  671. struct twl6040_jack_data *hs_jack = &priv->hs_jack;
  672. hs_jack->jack = jack;
  673. hs_jack->report = report;
  674. twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
  675. }
  676. EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect);
  677. static void twl6040_accessory_work(struct work_struct *work)
  678. {
  679. struct twl6040_data *priv = container_of(work,
  680. struct twl6040_data, delayed_work.work);
  681. struct snd_soc_codec *codec = priv->codec;
  682. struct twl6040_jack_data *hs_jack = &priv->hs_jack;
  683. twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
  684. }
  685. /* audio interrupt handler */
  686. static irqreturn_t twl6040_audio_handler(int irq, void *data)
  687. {
  688. struct snd_soc_codec *codec = data;
  689. struct twl6040 *twl6040 = codec->control_data;
  690. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  691. u8 intid;
  692. intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
  693. if ((intid & TWL6040_PLUGINT) || (intid & TWL6040_UNPLUGINT))
  694. queue_delayed_work(priv->workqueue, &priv->delayed_work,
  695. msecs_to_jiffies(200));
  696. return IRQ_HANDLED;
  697. }
  698. static int twl6040_put_volsw(struct snd_kcontrol *kcontrol,
  699. struct snd_ctl_elem_value *ucontrol)
  700. {
  701. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  702. struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
  703. struct twl6040_output *out = NULL;
  704. struct soc_mixer_control *mc =
  705. (struct soc_mixer_control *)kcontrol->private_value;
  706. int ret;
  707. unsigned int reg = mc->reg;
  708. /* For HS and HF we shadow the values and only actually write
  709. * them out when active in order to ensure the amplifier comes on
  710. * as quietly as possible. */
  711. switch (reg) {
  712. case TWL6040_REG_HSGAIN:
  713. out = &twl6040_priv->headset;
  714. break;
  715. default:
  716. break;
  717. }
  718. if (out) {
  719. out->left_vol = ucontrol->value.integer.value[0];
  720. out->right_vol = ucontrol->value.integer.value[1];
  721. if (!out->active)
  722. return 1;
  723. }
  724. ret = snd_soc_put_volsw(kcontrol, ucontrol);
  725. if (ret < 0)
  726. return ret;
  727. return 1;
  728. }
  729. static int twl6040_get_volsw(struct snd_kcontrol *kcontrol,
  730. struct snd_ctl_elem_value *ucontrol)
  731. {
  732. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  733. struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
  734. struct twl6040_output *out = &twl6040_priv->headset;
  735. struct soc_mixer_control *mc =
  736. (struct soc_mixer_control *)kcontrol->private_value;
  737. unsigned int reg = mc->reg;
  738. switch (reg) {
  739. case TWL6040_REG_HSGAIN:
  740. out = &twl6040_priv->headset;
  741. ucontrol->value.integer.value[0] = out->left_vol;
  742. ucontrol->value.integer.value[1] = out->right_vol;
  743. return 0;
  744. default:
  745. break;
  746. }
  747. return snd_soc_get_volsw(kcontrol, ucontrol);
  748. }
  749. static int twl6040_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
  750. struct snd_ctl_elem_value *ucontrol)
  751. {
  752. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  753. struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
  754. struct twl6040_output *out = NULL;
  755. struct soc_mixer_control *mc =
  756. (struct soc_mixer_control *)kcontrol->private_value;
  757. int ret;
  758. unsigned int reg = mc->reg;
  759. /* For HS and HF we shadow the values and only actually write
  760. * them out when active in order to ensure the amplifier comes on
  761. * as quietly as possible. */
  762. switch (reg) {
  763. case TWL6040_REG_HFLGAIN:
  764. case TWL6040_REG_HFRGAIN:
  765. out = &twl6040_priv->handsfree;
  766. break;
  767. default:
  768. break;
  769. }
  770. if (out) {
  771. out->left_vol = ucontrol->value.integer.value[0];
  772. out->right_vol = ucontrol->value.integer.value[1];
  773. if (!out->active)
  774. return 1;
  775. }
  776. ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
  777. if (ret < 0)
  778. return ret;
  779. return 1;
  780. }
  781. static int twl6040_get_volsw_2r(struct snd_kcontrol *kcontrol,
  782. struct snd_ctl_elem_value *ucontrol)
  783. {
  784. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  785. struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
  786. struct twl6040_output *out = &twl6040_priv->handsfree;
  787. struct soc_mixer_control *mc =
  788. (struct soc_mixer_control *)kcontrol->private_value;
  789. unsigned int reg = mc->reg;
  790. /* If these are cached registers use the cache */
  791. switch (reg) {
  792. case TWL6040_REG_HFLGAIN:
  793. case TWL6040_REG_HFRGAIN:
  794. out = &twl6040_priv->handsfree;
  795. ucontrol->value.integer.value[0] = out->left_vol;
  796. ucontrol->value.integer.value[1] = out->right_vol;
  797. return 0;
  798. default:
  799. break;
  800. }
  801. return snd_soc_get_volsw_2r(kcontrol, ucontrol);
  802. }
  803. /* double control with volume update */
  804. #define SOC_TWL6040_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax,\
  805. xinvert, tlv_array)\
  806. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  807. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  808. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  809. .tlv.p = (tlv_array), \
  810. .info = snd_soc_info_volsw, .get = twl6040_get_volsw, \
  811. .put = twl6040_put_volsw, \
  812. .private_value = (unsigned long)&(struct soc_mixer_control) \
  813. {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
  814. .max = xmax, .platform_max = xmax, .invert = xinvert} }
  815. /* double control with volume update */
  816. #define SOC_TWL6040_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax,\
  817. xinvert, tlv_array)\
  818. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  819. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  820. SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  821. SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
  822. .tlv.p = (tlv_array), \
  823. .info = snd_soc_info_volsw_2r, \
  824. .get = twl6040_get_volsw_2r, .put = twl6040_put_volsw_2r_vu, \
  825. .private_value = (unsigned long)&(struct soc_mixer_control) \
  826. {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
  827. .rshift = xshift, .max = xmax, .invert = xinvert}, }
  828. /*
  829. * MICATT volume control:
  830. * from -6 to 0 dB in 6 dB steps
  831. */
  832. static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0);
  833. /*
  834. * MICGAIN volume control:
  835. * from 6 to 30 dB in 6 dB steps
  836. */
  837. static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0);
  838. /*
  839. * AFMGAIN volume control:
  840. * from -18 to 24 dB in 6 dB steps
  841. */
  842. static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0);
  843. /*
  844. * HSGAIN volume control:
  845. * from -30 to 0 dB in 2 dB steps
  846. */
  847. static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0);
  848. /*
  849. * HFGAIN volume control:
  850. * from -52 to 6 dB in 2 dB steps
  851. */
  852. static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0);
  853. /*
  854. * EPGAIN volume control:
  855. * from -24 to 6 dB in 2 dB steps
  856. */
  857. static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0);
  858. /* Left analog microphone selection */
  859. static const char *twl6040_amicl_texts[] =
  860. {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"};
  861. /* Right analog microphone selection */
  862. static const char *twl6040_amicr_texts[] =
  863. {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
  864. static const struct soc_enum twl6040_enum[] = {
  865. SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts),
  866. SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts),
  867. };
  868. static const char *twl6040_hs_texts[] = {
  869. "Off", "HS DAC", "Line-In amp"
  870. };
  871. static const struct soc_enum twl6040_hs_enum[] = {
  872. SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
  873. twl6040_hs_texts),
  874. SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
  875. twl6040_hs_texts),
  876. };
  877. static const char *twl6040_hf_texts[] = {
  878. "Off", "HF DAC", "Line-In amp"
  879. };
  880. static const struct soc_enum twl6040_hf_enum[] = {
  881. SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
  882. twl6040_hf_texts),
  883. SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
  884. twl6040_hf_texts),
  885. };
  886. static const struct snd_kcontrol_new amicl_control =
  887. SOC_DAPM_ENUM("Route", twl6040_enum[0]);
  888. static const struct snd_kcontrol_new amicr_control =
  889. SOC_DAPM_ENUM("Route", twl6040_enum[1]);
  890. /* Headset DAC playback switches */
  891. static const struct snd_kcontrol_new hsl_mux_controls =
  892. SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]);
  893. static const struct snd_kcontrol_new hsr_mux_controls =
  894. SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]);
  895. /* Handsfree DAC playback switches */
  896. static const struct snd_kcontrol_new hfl_mux_controls =
  897. SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]);
  898. static const struct snd_kcontrol_new hfr_mux_controls =
  899. SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
  900. static const struct snd_kcontrol_new ep_driver_switch_controls =
  901. SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0);
  902. /* Headset power mode */
  903. static const char *twl6040_power_mode_texts[] = {
  904. "Low-Power", "High-Perfomance",
  905. };
  906. static const struct soc_enum twl6040_power_mode_enum =
  907. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts),
  908. twl6040_power_mode_texts);
  909. static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol,
  910. struct snd_ctl_elem_value *ucontrol)
  911. {
  912. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  913. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  914. ucontrol->value.enumerated.item[0] = priv->hs_power_mode;
  915. return 0;
  916. }
  917. static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol,
  918. struct snd_ctl_elem_value *ucontrol)
  919. {
  920. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  921. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  922. int high_perf = ucontrol->value.enumerated.item[0];
  923. int ret = 0;
  924. if (!priv->hs_power_mode_locked)
  925. ret = headset_power_mode(codec, high_perf);
  926. if (!ret)
  927. priv->hs_power_mode = high_perf;
  928. return ret;
  929. }
  930. static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol,
  931. struct snd_ctl_elem_value *ucontrol)
  932. {
  933. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  934. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  935. ucontrol->value.enumerated.item[0] = priv->pll_power_mode;
  936. return 0;
  937. }
  938. static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol,
  939. struct snd_ctl_elem_value *ucontrol)
  940. {
  941. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  942. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  943. priv->pll_power_mode = ucontrol->value.enumerated.item[0];
  944. return 0;
  945. }
  946. int twl6040_get_clk_id(struct snd_soc_codec *codec)
  947. {
  948. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  949. return priv->pll_power_mode;
  950. }
  951. EXPORT_SYMBOL_GPL(twl6040_get_clk_id);
  952. static const struct snd_kcontrol_new twl6040_snd_controls[] = {
  953. /* Capture gains */
  954. SOC_DOUBLE_TLV("Capture Preamplifier Volume",
  955. TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv),
  956. SOC_DOUBLE_TLV("Capture Volume",
  957. TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv),
  958. /* AFM gains */
  959. SOC_DOUBLE_TLV("Aux FM Volume",
  960. TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv),
  961. /* Playback gains */
  962. SOC_TWL6040_DOUBLE_TLV("Headset Playback Volume",
  963. TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
  964. SOC_TWL6040_DOUBLE_R_TLV("Handsfree Playback Volume",
  965. TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
  966. SOC_SINGLE_TLV("Earphone Playback Volume",
  967. TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
  968. SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum,
  969. twl6040_headset_power_get_enum,
  970. twl6040_headset_power_put_enum),
  971. SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum,
  972. twl6040_pll_get_enum, twl6040_pll_put_enum),
  973. };
  974. static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
  975. /* Inputs */
  976. SND_SOC_DAPM_INPUT("MAINMIC"),
  977. SND_SOC_DAPM_INPUT("HSMIC"),
  978. SND_SOC_DAPM_INPUT("SUBMIC"),
  979. SND_SOC_DAPM_INPUT("AFML"),
  980. SND_SOC_DAPM_INPUT("AFMR"),
  981. /* Outputs */
  982. SND_SOC_DAPM_OUTPUT("HSOL"),
  983. SND_SOC_DAPM_OUTPUT("HSOR"),
  984. SND_SOC_DAPM_OUTPUT("HFL"),
  985. SND_SOC_DAPM_OUTPUT("HFR"),
  986. SND_SOC_DAPM_OUTPUT("EP"),
  987. /* Analog input muxes for the capture amplifiers */
  988. SND_SOC_DAPM_MUX("Analog Left Capture Route",
  989. SND_SOC_NOPM, 0, 0, &amicl_control),
  990. SND_SOC_DAPM_MUX("Analog Right Capture Route",
  991. SND_SOC_NOPM, 0, 0, &amicr_control),
  992. /* Analog capture PGAs */
  993. SND_SOC_DAPM_PGA("MicAmpL",
  994. TWL6040_REG_MICLCTL, 0, 0, NULL, 0),
  995. SND_SOC_DAPM_PGA("MicAmpR",
  996. TWL6040_REG_MICRCTL, 0, 0, NULL, 0),
  997. /* Auxiliary FM PGAs */
  998. SND_SOC_DAPM_PGA("AFMAmpL",
  999. TWL6040_REG_MICLCTL, 1, 0, NULL, 0),
  1000. SND_SOC_DAPM_PGA("AFMAmpR",
  1001. TWL6040_REG_MICRCTL, 1, 0, NULL, 0),
  1002. /* ADCs */
  1003. SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture",
  1004. TWL6040_REG_MICLCTL, 2, 0),
  1005. SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture",
  1006. TWL6040_REG_MICRCTL, 2, 0),
  1007. /* Microphone bias */
  1008. SND_SOC_DAPM_MICBIAS("Headset Mic Bias",
  1009. TWL6040_REG_AMICBCTL, 0, 0),
  1010. SND_SOC_DAPM_MICBIAS("Main Mic Bias",
  1011. TWL6040_REG_AMICBCTL, 4, 0),
  1012. SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias",
  1013. TWL6040_REG_DMICBCTL, 0, 0),
  1014. SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias",
  1015. TWL6040_REG_DMICBCTL, 4, 0),
  1016. /* DACs */
  1017. SND_SOC_DAPM_DAC_E("HSDAC Left", "Headset Playback",
  1018. TWL6040_REG_HSLCTL, 0, 0,
  1019. twl6040_hs_dac_event,
  1020. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1021. SND_SOC_DAPM_DAC_E("HSDAC Right", "Headset Playback",
  1022. TWL6040_REG_HSRCTL, 0, 0,
  1023. twl6040_hs_dac_event,
  1024. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1025. SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback",
  1026. TWL6040_REG_HFLCTL, 0, 0,
  1027. twl6040_power_mode_event,
  1028. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1029. SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback",
  1030. TWL6040_REG_HFRCTL, 0, 0,
  1031. twl6040_power_mode_event,
  1032. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1033. SND_SOC_DAPM_MUX("HF Left Playback",
  1034. SND_SOC_NOPM, 0, 0, &hfl_mux_controls),
  1035. SND_SOC_DAPM_MUX("HF Right Playback",
  1036. SND_SOC_NOPM, 0, 0, &hfr_mux_controls),
  1037. /* Analog playback Muxes */
  1038. SND_SOC_DAPM_MUX("HS Left Playback",
  1039. SND_SOC_NOPM, 0, 0, &hsl_mux_controls),
  1040. SND_SOC_DAPM_MUX("HS Right Playback",
  1041. SND_SOC_NOPM, 0, 0, &hsr_mux_controls),
  1042. /* Analog playback drivers */
  1043. SND_SOC_DAPM_OUT_DRV_E("Handsfree Left Driver",
  1044. TWL6040_REG_HFLCTL, 4, 0, NULL, 0,
  1045. pga_event,
  1046. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1047. SND_SOC_DAPM_OUT_DRV_E("Handsfree Right Driver",
  1048. TWL6040_REG_HFRCTL, 4, 0, NULL, 0,
  1049. pga_event,
  1050. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1051. SND_SOC_DAPM_OUT_DRV_E("Headset Left Driver",
  1052. TWL6040_REG_HSLCTL, 2, 0, NULL, 0,
  1053. pga_event,
  1054. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1055. SND_SOC_DAPM_OUT_DRV_E("Headset Right Driver",
  1056. TWL6040_REG_HSRCTL, 2, 0, NULL, 0,
  1057. pga_event,
  1058. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1059. SND_SOC_DAPM_SWITCH_E("Earphone Driver",
  1060. SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls,
  1061. twl6040_power_mode_event,
  1062. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1063. /* Analog playback PGAs */
  1064. SND_SOC_DAPM_PGA("HFDAC Left PGA",
  1065. TWL6040_REG_HFLCTL, 1, 0, NULL, 0),
  1066. SND_SOC_DAPM_PGA("HFDAC Right PGA",
  1067. TWL6040_REG_HFRCTL, 1, 0, NULL, 0),
  1068. };
  1069. static const struct snd_soc_dapm_route intercon[] = {
  1070. /* Capture path */
  1071. {"Analog Left Capture Route", "Headset Mic", "HSMIC"},
  1072. {"Analog Left Capture Route", "Main Mic", "MAINMIC"},
  1073. {"Analog Left Capture Route", "Aux/FM Left", "AFML"},
  1074. {"Analog Right Capture Route", "Headset Mic", "HSMIC"},
  1075. {"Analog Right Capture Route", "Sub Mic", "SUBMIC"},
  1076. {"Analog Right Capture Route", "Aux/FM Right", "AFMR"},
  1077. {"MicAmpL", NULL, "Analog Left Capture Route"},
  1078. {"MicAmpR", NULL, "Analog Right Capture Route"},
  1079. {"ADC Left", NULL, "MicAmpL"},
  1080. {"ADC Right", NULL, "MicAmpR"},
  1081. /* AFM path */
  1082. {"AFMAmpL", "NULL", "AFML"},
  1083. {"AFMAmpR", "NULL", "AFMR"},
  1084. {"HS Left Playback", "HS DAC", "HSDAC Left"},
  1085. {"HS Left Playback", "Line-In amp", "AFMAmpL"},
  1086. {"HS Right Playback", "HS DAC", "HSDAC Right"},
  1087. {"HS Right Playback", "Line-In amp", "AFMAmpR"},
  1088. {"Headset Left Driver", "NULL", "HS Left Playback"},
  1089. {"Headset Right Driver", "NULL", "HS Right Playback"},
  1090. {"HSOL", NULL, "Headset Left Driver"},
  1091. {"HSOR", NULL, "Headset Right Driver"},
  1092. /* Earphone playback path */
  1093. {"Earphone Driver", "Switch", "HSDAC Left"},
  1094. {"EP", NULL, "Earphone Driver"},
  1095. {"HF Left Playback", "HF DAC", "HFDAC Left"},
  1096. {"HF Left Playback", "Line-In amp", "AFMAmpL"},
  1097. {"HF Right Playback", "HF DAC", "HFDAC Right"},
  1098. {"HF Right Playback", "Line-In amp", "AFMAmpR"},
  1099. {"HFDAC Left PGA", NULL, "HF Left Playback"},
  1100. {"HFDAC Right PGA", NULL, "HF Right Playback"},
  1101. {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"},
  1102. {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"},
  1103. {"HFL", NULL, "Handsfree Left Driver"},
  1104. {"HFR", NULL, "Handsfree Right Driver"},
  1105. };
  1106. static int twl6040_add_widgets(struct snd_soc_codec *codec)
  1107. {
  1108. struct snd_soc_dapm_context *dapm = &codec->dapm;
  1109. snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets,
  1110. ARRAY_SIZE(twl6040_dapm_widgets));
  1111. snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
  1112. snd_soc_dapm_new_widgets(dapm);
  1113. return 0;
  1114. }
  1115. static int twl6040_set_bias_level(struct snd_soc_codec *codec,
  1116. enum snd_soc_bias_level level)
  1117. {
  1118. struct twl6040 *twl6040 = codec->control_data;
  1119. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  1120. int ret;
  1121. switch (level) {
  1122. case SND_SOC_BIAS_ON:
  1123. break;
  1124. case SND_SOC_BIAS_PREPARE:
  1125. break;
  1126. case SND_SOC_BIAS_STANDBY:
  1127. if (priv->codec_powered)
  1128. break;
  1129. ret = twl6040_power(twl6040, 1);
  1130. if (ret)
  1131. return ret;
  1132. priv->codec_powered = 1;
  1133. /* initialize vdd/vss registers with reg_cache */
  1134. twl6040_init_vdd_regs(codec);
  1135. /* Set external boost GPO */
  1136. twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02);
  1137. break;
  1138. case SND_SOC_BIAS_OFF:
  1139. if (!priv->codec_powered)
  1140. break;
  1141. twl6040_power(twl6040, 0);
  1142. priv->codec_powered = 0;
  1143. break;
  1144. }
  1145. codec->dapm.bias_level = level;
  1146. return 0;
  1147. }
  1148. static int twl6040_startup(struct snd_pcm_substream *substream,
  1149. struct snd_soc_dai *dai)
  1150. {
  1151. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1152. struct snd_soc_codec *codec = rtd->codec;
  1153. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  1154. snd_pcm_hw_constraint_list(substream->runtime, 0,
  1155. SNDRV_PCM_HW_PARAM_RATE,
  1156. &sysclk_constraints[priv->pll_power_mode]);
  1157. return 0;
  1158. }
  1159. static int twl6040_hw_params(struct snd_pcm_substream *substream,
  1160. struct snd_pcm_hw_params *params,
  1161. struct snd_soc_dai *dai)
  1162. {
  1163. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1164. struct snd_soc_codec *codec = rtd->codec;
  1165. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  1166. int rate;
  1167. rate = params_rate(params);
  1168. switch (rate) {
  1169. case 11250:
  1170. case 22500:
  1171. case 44100:
  1172. case 88200:
  1173. /* These rates are not supported when HPPLL is in use */
  1174. if (unlikely(priv->pll == TWL6040_SYSCLK_SEL_HPPLL)) {
  1175. dev_err(codec->dev, "HPPLL does not support rate %d\n",
  1176. rate);
  1177. return -EINVAL;
  1178. }
  1179. /* Capture is not supported with 17.64MHz sysclk */
  1180. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  1181. dev_err(codec->dev,
  1182. "capture mode is not supported at %dHz\n",
  1183. rate);
  1184. return -EINVAL;
  1185. }
  1186. priv->sysclk = 17640000;
  1187. break;
  1188. case 8000:
  1189. case 16000:
  1190. case 32000:
  1191. case 48000:
  1192. case 96000:
  1193. priv->sysclk = 19200000;
  1194. break;
  1195. default:
  1196. dev_err(codec->dev, "unsupported rate %d\n", rate);
  1197. return -EINVAL;
  1198. }
  1199. return 0;
  1200. }
  1201. static int twl6040_prepare(struct snd_pcm_substream *substream,
  1202. struct snd_soc_dai *dai)
  1203. {
  1204. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1205. struct snd_soc_codec *codec = rtd->codec;
  1206. struct twl6040 *twl6040 = codec->control_data;
  1207. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  1208. int ret;
  1209. if (!priv->sysclk) {
  1210. dev_err(codec->dev,
  1211. "no mclk configured, call set_sysclk() on init\n");
  1212. return -EINVAL;
  1213. }
  1214. if ((priv->sysclk == 17640000) && priv->non_lp) {
  1215. dev_err(codec->dev,
  1216. "some enabled paths aren't supported at %dHz\n",
  1217. priv->sysclk);
  1218. return -EPERM;
  1219. }
  1220. ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk);
  1221. if (ret) {
  1222. dev_err(codec->dev, "Can not set PLL (%d)\n", ret);
  1223. return -EPERM;
  1224. }
  1225. return 0;
  1226. }
  1227. static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1228. int clk_id, unsigned int freq, int dir)
  1229. {
  1230. struct snd_soc_codec *codec = codec_dai->codec;
  1231. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  1232. switch (clk_id) {
  1233. case TWL6040_SYSCLK_SEL_LPPLL:
  1234. case TWL6040_SYSCLK_SEL_HPPLL:
  1235. priv->pll = clk_id;
  1236. priv->clk_in = freq;
  1237. break;
  1238. default:
  1239. dev_err(codec->dev, "unknown clk_id %d\n", clk_id);
  1240. return -EINVAL;
  1241. }
  1242. return 0;
  1243. }
  1244. static struct snd_soc_dai_ops twl6040_dai_ops = {
  1245. .startup = twl6040_startup,
  1246. .hw_params = twl6040_hw_params,
  1247. .prepare = twl6040_prepare,
  1248. .set_sysclk = twl6040_set_dai_sysclk,
  1249. };
  1250. static struct snd_soc_dai_driver twl6040_dai[] = {
  1251. {
  1252. .name = "twl6040-hifi",
  1253. .playback = {
  1254. .stream_name = "Playback",
  1255. .channels_min = 1,
  1256. .channels_max = 2,
  1257. .rates = TWL6040_RATES,
  1258. .formats = TWL6040_FORMATS,
  1259. },
  1260. .capture = {
  1261. .stream_name = "Capture",
  1262. .channels_min = 1,
  1263. .channels_max = 2,
  1264. .rates = TWL6040_RATES,
  1265. .formats = TWL6040_FORMATS,
  1266. },
  1267. .ops = &twl6040_dai_ops,
  1268. },
  1269. {
  1270. .name = "twl6040-ul",
  1271. .capture = {
  1272. .stream_name = "Capture",
  1273. .channels_min = 1,
  1274. .channels_max = 2,
  1275. .rates = TWL6040_RATES,
  1276. .formats = TWL6040_FORMATS,
  1277. },
  1278. .ops = &twl6040_dai_ops,
  1279. },
  1280. {
  1281. .name = "twl6040-dl1",
  1282. .playback = {
  1283. .stream_name = "Headset Playback",
  1284. .channels_min = 1,
  1285. .channels_max = 2,
  1286. .rates = TWL6040_RATES,
  1287. .formats = TWL6040_FORMATS,
  1288. },
  1289. .ops = &twl6040_dai_ops,
  1290. },
  1291. {
  1292. .name = "twl6040-dl2",
  1293. .playback = {
  1294. .stream_name = "Handsfree Playback",
  1295. .channels_min = 1,
  1296. .channels_max = 2,
  1297. .rates = TWL6040_RATES,
  1298. .formats = TWL6040_FORMATS,
  1299. },
  1300. .ops = &twl6040_dai_ops,
  1301. },
  1302. {
  1303. .name = "twl6040-vib",
  1304. .playback = {
  1305. .stream_name = "Vibra Playback",
  1306. .channels_min = 2,
  1307. .channels_max = 2,
  1308. .rates = SNDRV_PCM_RATE_CONTINUOUS,
  1309. .formats = TWL6040_FORMATS,
  1310. },
  1311. .ops = &twl6040_dai_ops,
  1312. },
  1313. };
  1314. #ifdef CONFIG_PM
  1315. static int twl6040_suspend(struct snd_soc_codec *codec, pm_message_t state)
  1316. {
  1317. twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1318. return 0;
  1319. }
  1320. static int twl6040_resume(struct snd_soc_codec *codec)
  1321. {
  1322. twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1323. twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level);
  1324. return 0;
  1325. }
  1326. #else
  1327. #define twl6040_suspend NULL
  1328. #define twl6040_resume NULL
  1329. #endif
  1330. static int twl6040_probe(struct snd_soc_codec *codec)
  1331. {
  1332. struct twl6040_data *priv;
  1333. struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev);
  1334. struct platform_device *pdev = container_of(codec->dev,
  1335. struct platform_device, dev);
  1336. int ret = 0;
  1337. priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL);
  1338. if (priv == NULL)
  1339. return -ENOMEM;
  1340. snd_soc_codec_set_drvdata(codec, priv);
  1341. priv->codec = codec;
  1342. codec->control_data = dev_get_drvdata(codec->dev->parent);
  1343. if (pdata && pdata->hs_left_step && pdata->hs_right_step) {
  1344. priv->hs_left_step = pdata->hs_left_step;
  1345. priv->hs_right_step = pdata->hs_right_step;
  1346. } else {
  1347. priv->hs_left_step = 1;
  1348. priv->hs_right_step = 1;
  1349. }
  1350. if (pdata && pdata->hf_left_step && pdata->hf_right_step) {
  1351. priv->hf_left_step = pdata->hf_left_step;
  1352. priv->hf_right_step = pdata->hf_right_step;
  1353. } else {
  1354. priv->hf_left_step = 1;
  1355. priv->hf_right_step = 1;
  1356. }
  1357. priv->plug_irq = platform_get_irq(pdev, 0);
  1358. if (priv->plug_irq < 0) {
  1359. dev_err(codec->dev, "invalid irq\n");
  1360. ret = -EINVAL;
  1361. goto work_err;
  1362. }
  1363. priv->workqueue = create_singlethread_workqueue("twl6040-codec");
  1364. if (!priv->workqueue) {
  1365. ret = -ENOMEM;
  1366. goto work_err;
  1367. }
  1368. INIT_DELAYED_WORK(&priv->delayed_work, twl6040_accessory_work);
  1369. mutex_init(&priv->mutex);
  1370. init_completion(&priv->headset.ramp_done);
  1371. init_completion(&priv->handsfree.ramp_done);
  1372. priv->hf_workqueue = create_singlethread_workqueue("twl6040-hf");
  1373. if (priv->hf_workqueue == NULL) {
  1374. ret = -ENOMEM;
  1375. goto hfwq_err;
  1376. }
  1377. priv->hs_workqueue = create_singlethread_workqueue("twl6040-hs");
  1378. if (priv->hs_workqueue == NULL) {
  1379. ret = -ENOMEM;
  1380. goto hswq_err;
  1381. }
  1382. INIT_DELAYED_WORK(&priv->hs_delayed_work, twl6040_pga_hs_work);
  1383. INIT_DELAYED_WORK(&priv->hf_delayed_work, twl6040_pga_hf_work);
  1384. ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler,
  1385. 0, "twl6040_irq_plug", codec);
  1386. if (ret) {
  1387. dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret);
  1388. goto plugirq_err;
  1389. }
  1390. /* init vio registers */
  1391. twl6040_init_vio_regs(codec);
  1392. /* power on device */
  1393. ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1394. if (ret)
  1395. goto bias_err;
  1396. snd_soc_add_controls(codec, twl6040_snd_controls,
  1397. ARRAY_SIZE(twl6040_snd_controls));
  1398. twl6040_add_widgets(codec);
  1399. return 0;
  1400. bias_err:
  1401. free_irq(priv->plug_irq, codec);
  1402. plugirq_err:
  1403. destroy_workqueue(priv->hs_workqueue);
  1404. hswq_err:
  1405. destroy_workqueue(priv->hf_workqueue);
  1406. hfwq_err:
  1407. destroy_workqueue(priv->workqueue);
  1408. work_err:
  1409. kfree(priv);
  1410. return ret;
  1411. }
  1412. static int twl6040_remove(struct snd_soc_codec *codec)
  1413. {
  1414. struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
  1415. twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1416. free_irq(priv->plug_irq, codec);
  1417. destroy_workqueue(priv->workqueue);
  1418. destroy_workqueue(priv->hf_workqueue);
  1419. destroy_workqueue(priv->hs_workqueue);
  1420. kfree(priv);
  1421. return 0;
  1422. }
  1423. static struct snd_soc_codec_driver soc_codec_dev_twl6040 = {
  1424. .probe = twl6040_probe,
  1425. .remove = twl6040_remove,
  1426. .suspend = twl6040_suspend,
  1427. .resume = twl6040_resume,
  1428. .read = twl6040_read_reg_cache,
  1429. .write = twl6040_write,
  1430. .set_bias_level = twl6040_set_bias_level,
  1431. .reg_cache_size = ARRAY_SIZE(twl6040_reg),
  1432. .reg_word_size = sizeof(u8),
  1433. .reg_cache_default = twl6040_reg,
  1434. };
  1435. static int __devinit twl6040_codec_probe(struct platform_device *pdev)
  1436. {
  1437. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040,
  1438. twl6040_dai, ARRAY_SIZE(twl6040_dai));
  1439. }
  1440. static int __devexit twl6040_codec_remove(struct platform_device *pdev)
  1441. {
  1442. snd_soc_unregister_codec(&pdev->dev);
  1443. return 0;
  1444. }
  1445. static struct platform_driver twl6040_codec_driver = {
  1446. .driver = {
  1447. .name = "twl6040-codec",
  1448. .owner = THIS_MODULE,
  1449. },
  1450. .probe = twl6040_codec_probe,
  1451. .remove = __devexit_p(twl6040_codec_remove),
  1452. };
  1453. static int __init twl6040_codec_init(void)
  1454. {
  1455. return platform_driver_register(&twl6040_codec_driver);
  1456. }
  1457. module_init(twl6040_codec_init);
  1458. static void __exit twl6040_codec_exit(void)
  1459. {
  1460. platform_driver_unregister(&twl6040_codec_driver);
  1461. }
  1462. module_exit(twl6040_codec_exit);
  1463. MODULE_DESCRIPTION("ASoC TWL6040 codec driver");
  1464. MODULE_AUTHOR("Misael Lopez Cruz");
  1465. MODULE_LICENSE("GPL");