twl6040.c 44 KB

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