twl4030.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  1. /*
  2. * ALSA SoC TWL4030 codec driver
  3. *
  4. * Author: Steve Sakoman, <steve@sakoman.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/i2c.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/of.h>
  29. #include <linux/of_gpio.h>
  30. #include <linux/i2c/twl.h>
  31. #include <linux/slab.h>
  32. #include <linux/gpio.h>
  33. #include <sound/core.h>
  34. #include <sound/pcm.h>
  35. #include <sound/pcm_params.h>
  36. #include <sound/soc.h>
  37. #include <sound/initval.h>
  38. #include <sound/tlv.h>
  39. /* Register descriptions are here */
  40. #include <linux/mfd/twl4030-audio.h>
  41. /* Shadow register used by the audio driver */
  42. #define TWL4030_REG_SW_SHADOW 0x4A
  43. #define TWL4030_CACHEREGNUM (TWL4030_REG_SW_SHADOW + 1)
  44. /* TWL4030_REG_SW_SHADOW (0x4A) Fields */
  45. #define TWL4030_HFL_EN 0x01
  46. #define TWL4030_HFR_EN 0x02
  47. /*
  48. * twl4030 register cache & default register settings
  49. */
  50. static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
  51. 0x00, /* this register not used */
  52. 0x00, /* REG_CODEC_MODE (0x1) */
  53. 0x00, /* REG_OPTION (0x2) */
  54. 0x00, /* REG_UNKNOWN (0x3) */
  55. 0x00, /* REG_MICBIAS_CTL (0x4) */
  56. 0x00, /* REG_ANAMICL (0x5) */
  57. 0x00, /* REG_ANAMICR (0x6) */
  58. 0x00, /* REG_AVADC_CTL (0x7) */
  59. 0x00, /* REG_ADCMICSEL (0x8) */
  60. 0x00, /* REG_DIGMIXING (0x9) */
  61. 0x0f, /* REG_ATXL1PGA (0xA) */
  62. 0x0f, /* REG_ATXR1PGA (0xB) */
  63. 0x0f, /* REG_AVTXL2PGA (0xC) */
  64. 0x0f, /* REG_AVTXR2PGA (0xD) */
  65. 0x00, /* REG_AUDIO_IF (0xE) */
  66. 0x00, /* REG_VOICE_IF (0xF) */
  67. 0x3f, /* REG_ARXR1PGA (0x10) */
  68. 0x3f, /* REG_ARXL1PGA (0x11) */
  69. 0x3f, /* REG_ARXR2PGA (0x12) */
  70. 0x3f, /* REG_ARXL2PGA (0x13) */
  71. 0x25, /* REG_VRXPGA (0x14) */
  72. 0x00, /* REG_VSTPGA (0x15) */
  73. 0x00, /* REG_VRX2ARXPGA (0x16) */
  74. 0x00, /* REG_AVDAC_CTL (0x17) */
  75. 0x00, /* REG_ARX2VTXPGA (0x18) */
  76. 0x32, /* REG_ARXL1_APGA_CTL (0x19) */
  77. 0x32, /* REG_ARXR1_APGA_CTL (0x1A) */
  78. 0x32, /* REG_ARXL2_APGA_CTL (0x1B) */
  79. 0x32, /* REG_ARXR2_APGA_CTL (0x1C) */
  80. 0x00, /* REG_ATX2ARXPGA (0x1D) */
  81. 0x00, /* REG_BT_IF (0x1E) */
  82. 0x55, /* REG_BTPGA (0x1F) */
  83. 0x00, /* REG_BTSTPGA (0x20) */
  84. 0x00, /* REG_EAR_CTL (0x21) */
  85. 0x00, /* REG_HS_SEL (0x22) */
  86. 0x00, /* REG_HS_GAIN_SET (0x23) */
  87. 0x00, /* REG_HS_POPN_SET (0x24) */
  88. 0x00, /* REG_PREDL_CTL (0x25) */
  89. 0x00, /* REG_PREDR_CTL (0x26) */
  90. 0x00, /* REG_PRECKL_CTL (0x27) */
  91. 0x00, /* REG_PRECKR_CTL (0x28) */
  92. 0x00, /* REG_HFL_CTL (0x29) */
  93. 0x00, /* REG_HFR_CTL (0x2A) */
  94. 0x05, /* REG_ALC_CTL (0x2B) */
  95. 0x00, /* REG_ALC_SET1 (0x2C) */
  96. 0x00, /* REG_ALC_SET2 (0x2D) */
  97. 0x00, /* REG_BOOST_CTL (0x2E) */
  98. 0x00, /* REG_SOFTVOL_CTL (0x2F) */
  99. 0x13, /* REG_DTMF_FREQSEL (0x30) */
  100. 0x00, /* REG_DTMF_TONEXT1H (0x31) */
  101. 0x00, /* REG_DTMF_TONEXT1L (0x32) */
  102. 0x00, /* REG_DTMF_TONEXT2H (0x33) */
  103. 0x00, /* REG_DTMF_TONEXT2L (0x34) */
  104. 0x79, /* REG_DTMF_TONOFF (0x35) */
  105. 0x11, /* REG_DTMF_WANONOFF (0x36) */
  106. 0x00, /* REG_I2S_RX_SCRAMBLE_H (0x37) */
  107. 0x00, /* REG_I2S_RX_SCRAMBLE_M (0x38) */
  108. 0x00, /* REG_I2S_RX_SCRAMBLE_L (0x39) */
  109. 0x06, /* REG_APLL_CTL (0x3A) */
  110. 0x00, /* REG_DTMF_CTL (0x3B) */
  111. 0x44, /* REG_DTMF_PGA_CTL2 (0x3C) */
  112. 0x69, /* REG_DTMF_PGA_CTL1 (0x3D) */
  113. 0x00, /* REG_MISC_SET_1 (0x3E) */
  114. 0x00, /* REG_PCMBTMUX (0x3F) */
  115. 0x00, /* not used (0x40) */
  116. 0x00, /* not used (0x41) */
  117. 0x00, /* not used (0x42) */
  118. 0x00, /* REG_RX_PATH_SEL (0x43) */
  119. 0x32, /* REG_VDL_APGA_CTL (0x44) */
  120. 0x00, /* REG_VIBRA_CTL (0x45) */
  121. 0x00, /* REG_VIBRA_SET (0x46) */
  122. 0x00, /* REG_VIBRA_PWM_SET (0x47) */
  123. 0x00, /* REG_ANAMIC_GAIN (0x48) */
  124. 0x00, /* REG_MISC_SET_2 (0x49) */
  125. 0x00, /* REG_SW_SHADOW (0x4A) - Shadow, non HW register */
  126. };
  127. /* codec private data */
  128. struct twl4030_priv {
  129. struct snd_soc_codec codec;
  130. unsigned int codec_powered;
  131. /* reference counts of AIF/APLL users */
  132. unsigned int apll_enabled;
  133. struct snd_pcm_substream *master_substream;
  134. struct snd_pcm_substream *slave_substream;
  135. unsigned int configured;
  136. unsigned int rate;
  137. unsigned int sample_bits;
  138. unsigned int channels;
  139. unsigned int sysclk;
  140. /* Output (with associated amp) states */
  141. u8 hsl_enabled, hsr_enabled;
  142. u8 earpiece_enabled;
  143. u8 predrivel_enabled, predriver_enabled;
  144. u8 carkitl_enabled, carkitr_enabled;
  145. struct twl4030_codec_data *pdata;
  146. };
  147. /*
  148. * read twl4030 register cache
  149. */
  150. static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec,
  151. unsigned int reg)
  152. {
  153. u8 *cache = codec->reg_cache;
  154. if (reg >= TWL4030_CACHEREGNUM)
  155. return -EIO;
  156. return cache[reg];
  157. }
  158. /*
  159. * write twl4030 register cache
  160. */
  161. static inline void twl4030_write_reg_cache(struct snd_soc_codec *codec,
  162. u8 reg, u8 value)
  163. {
  164. u8 *cache = codec->reg_cache;
  165. if (reg >= TWL4030_CACHEREGNUM)
  166. return;
  167. cache[reg] = value;
  168. }
  169. /*
  170. * write to the twl4030 register space
  171. */
  172. static int twl4030_write(struct snd_soc_codec *codec,
  173. unsigned int reg, unsigned int value)
  174. {
  175. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  176. int write_to_reg = 0;
  177. twl4030_write_reg_cache(codec, reg, value);
  178. if (likely(reg < TWL4030_REG_SW_SHADOW)) {
  179. /* Decide if the given register can be written */
  180. switch (reg) {
  181. case TWL4030_REG_EAR_CTL:
  182. if (twl4030->earpiece_enabled)
  183. write_to_reg = 1;
  184. break;
  185. case TWL4030_REG_PREDL_CTL:
  186. if (twl4030->predrivel_enabled)
  187. write_to_reg = 1;
  188. break;
  189. case TWL4030_REG_PREDR_CTL:
  190. if (twl4030->predriver_enabled)
  191. write_to_reg = 1;
  192. break;
  193. case TWL4030_REG_PRECKL_CTL:
  194. if (twl4030->carkitl_enabled)
  195. write_to_reg = 1;
  196. break;
  197. case TWL4030_REG_PRECKR_CTL:
  198. if (twl4030->carkitr_enabled)
  199. write_to_reg = 1;
  200. break;
  201. case TWL4030_REG_HS_GAIN_SET:
  202. if (twl4030->hsl_enabled || twl4030->hsr_enabled)
  203. write_to_reg = 1;
  204. break;
  205. default:
  206. /* All other register can be written */
  207. write_to_reg = 1;
  208. break;
  209. }
  210. if (write_to_reg)
  211. return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
  212. value, reg);
  213. }
  214. return 0;
  215. }
  216. static inline void twl4030_wait_ms(int time)
  217. {
  218. if (time < 60) {
  219. time *= 1000;
  220. usleep_range(time, time + 500);
  221. } else {
  222. msleep(time);
  223. }
  224. }
  225. static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
  226. {
  227. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  228. int mode;
  229. if (enable == twl4030->codec_powered)
  230. return;
  231. if (enable)
  232. mode = twl4030_audio_enable_resource(TWL4030_AUDIO_RES_POWER);
  233. else
  234. mode = twl4030_audio_disable_resource(TWL4030_AUDIO_RES_POWER);
  235. if (mode >= 0) {
  236. twl4030_write_reg_cache(codec, TWL4030_REG_CODEC_MODE, mode);
  237. twl4030->codec_powered = enable;
  238. }
  239. /* REVISIT: this delay is present in TI sample drivers */
  240. /* but there seems to be no TRM requirement for it */
  241. udelay(10);
  242. }
  243. static inline void twl4030_check_defaults(struct snd_soc_codec *codec)
  244. {
  245. int i, difference = 0;
  246. u8 val;
  247. dev_dbg(codec->dev, "Checking TWL audio default configuration\n");
  248. for (i = 1; i <= TWL4030_REG_MISC_SET_2; i++) {
  249. twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val, i);
  250. if (val != twl4030_reg[i]) {
  251. difference++;
  252. dev_dbg(codec->dev,
  253. "Reg 0x%02x: chip: 0x%02x driver: 0x%02x\n",
  254. i, val, twl4030_reg[i]);
  255. }
  256. }
  257. dev_dbg(codec->dev, "Found %d non-matching registers. %s\n",
  258. difference, difference ? "Not OK" : "OK");
  259. }
  260. static inline void twl4030_reset_registers(struct snd_soc_codec *codec)
  261. {
  262. int i;
  263. /* set all audio section registers to reasonable defaults */
  264. for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++)
  265. if (i != TWL4030_REG_APLL_CTL)
  266. twl4030_write(codec, i, twl4030_reg[i]);
  267. }
  268. static void twl4030_setup_pdata_of(struct twl4030_codec_data *pdata,
  269. struct device_node *node)
  270. {
  271. int value;
  272. of_property_read_u32(node, "ti,digimic_delay",
  273. &pdata->digimic_delay);
  274. of_property_read_u32(node, "ti,ramp_delay_value",
  275. &pdata->ramp_delay_value);
  276. of_property_read_u32(node, "ti,offset_cncl_path",
  277. &pdata->offset_cncl_path);
  278. if (!of_property_read_u32(node, "ti,hs_extmute", &value))
  279. pdata->hs_extmute = value;
  280. pdata->hs_extmute_gpio = of_get_named_gpio(node,
  281. "ti,hs_extmute_gpio", 0);
  282. if (gpio_is_valid(pdata->hs_extmute_gpio))
  283. pdata->hs_extmute = 1;
  284. }
  285. static struct twl4030_codec_data *twl4030_get_pdata(struct snd_soc_codec *codec)
  286. {
  287. struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev);
  288. struct device_node *twl4030_codec_node = NULL;
  289. twl4030_codec_node = of_find_node_by_name(codec->dev->parent->of_node,
  290. "codec");
  291. if (!pdata && twl4030_codec_node) {
  292. pdata = devm_kzalloc(codec->dev,
  293. sizeof(struct twl4030_codec_data),
  294. GFP_KERNEL);
  295. if (!pdata) {
  296. dev_err(codec->dev, "Can not allocate memory\n");
  297. return NULL;
  298. }
  299. twl4030_setup_pdata_of(pdata, twl4030_codec_node);
  300. }
  301. return pdata;
  302. }
  303. static void twl4030_init_chip(struct snd_soc_codec *codec)
  304. {
  305. struct twl4030_codec_data *pdata;
  306. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  307. u8 reg, byte;
  308. int i = 0;
  309. pdata = twl4030_get_pdata(codec);
  310. if (pdata && pdata->hs_extmute &&
  311. gpio_is_valid(pdata->hs_extmute_gpio)) {
  312. int ret;
  313. if (!pdata->hs_extmute_gpio)
  314. dev_warn(codec->dev,
  315. "Extmute GPIO is 0 is this correct?\n");
  316. ret = gpio_request_one(pdata->hs_extmute_gpio,
  317. GPIOF_OUT_INIT_LOW, "hs_extmute");
  318. if (ret) {
  319. dev_err(codec->dev, "Failed to get hs_extmute GPIO\n");
  320. pdata->hs_extmute_gpio = -1;
  321. }
  322. }
  323. /* Check defaults, if instructed before anything else */
  324. if (pdata && pdata->check_defaults)
  325. twl4030_check_defaults(codec);
  326. /* Reset registers, if no setup data or if instructed to do so */
  327. if (!pdata || (pdata && pdata->reset_registers))
  328. twl4030_reset_registers(codec);
  329. /* Refresh APLL_CTL register from HW */
  330. twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
  331. TWL4030_REG_APLL_CTL);
  332. twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, byte);
  333. /* anti-pop when changing analog gain */
  334. reg = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1);
  335. twl4030_write(codec, TWL4030_REG_MISC_SET_1,
  336. reg | TWL4030_SMOOTH_ANAVOL_EN);
  337. twl4030_write(codec, TWL4030_REG_OPTION,
  338. TWL4030_ATXL1_EN | TWL4030_ATXR1_EN |
  339. TWL4030_ARXL2_EN | TWL4030_ARXR2_EN);
  340. /* REG_ARXR2_APGA_CTL reset according to the TRM: 0dB, DA_EN */
  341. twl4030_write(codec, TWL4030_REG_ARXR2_APGA_CTL, 0x32);
  342. /* Machine dependent setup */
  343. if (!pdata)
  344. return;
  345. twl4030->pdata = pdata;
  346. reg = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
  347. reg &= ~TWL4030_RAMP_DELAY;
  348. reg |= (pdata->ramp_delay_value << 2);
  349. twl4030_write_reg_cache(codec, TWL4030_REG_HS_POPN_SET, reg);
  350. /* initiate offset cancellation */
  351. twl4030_codec_enable(codec, 1);
  352. reg = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL);
  353. reg &= ~TWL4030_OFFSET_CNCL_SEL;
  354. reg |= pdata->offset_cncl_path;
  355. twl4030_write(codec, TWL4030_REG_ANAMICL,
  356. reg | TWL4030_CNCL_OFFSET_START);
  357. /*
  358. * Wait for offset cancellation to complete.
  359. * Since this takes a while, do not slam the i2c.
  360. * Start polling the status after ~20ms.
  361. */
  362. msleep(20);
  363. do {
  364. usleep_range(1000, 2000);
  365. twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
  366. TWL4030_REG_ANAMICL);
  367. } while ((i++ < 100) &&
  368. ((byte & TWL4030_CNCL_OFFSET_START) ==
  369. TWL4030_CNCL_OFFSET_START));
  370. /* Make sure that the reg_cache has the same value as the HW */
  371. twl4030_write_reg_cache(codec, TWL4030_REG_ANAMICL, byte);
  372. twl4030_codec_enable(codec, 0);
  373. }
  374. static void twl4030_apll_enable(struct snd_soc_codec *codec, int enable)
  375. {
  376. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  377. int status = -1;
  378. if (enable) {
  379. twl4030->apll_enabled++;
  380. if (twl4030->apll_enabled == 1)
  381. status = twl4030_audio_enable_resource(
  382. TWL4030_AUDIO_RES_APLL);
  383. } else {
  384. twl4030->apll_enabled--;
  385. if (!twl4030->apll_enabled)
  386. status = twl4030_audio_disable_resource(
  387. TWL4030_AUDIO_RES_APLL);
  388. }
  389. if (status >= 0)
  390. twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, status);
  391. }
  392. /* Earpiece */
  393. static const struct snd_kcontrol_new twl4030_dapm_earpiece_controls[] = {
  394. SOC_DAPM_SINGLE("Voice", TWL4030_REG_EAR_CTL, 0, 1, 0),
  395. SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_EAR_CTL, 1, 1, 0),
  396. SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_EAR_CTL, 2, 1, 0),
  397. SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_EAR_CTL, 3, 1, 0),
  398. };
  399. /* PreDrive Left */
  400. static const struct snd_kcontrol_new twl4030_dapm_predrivel_controls[] = {
  401. SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDL_CTL, 0, 1, 0),
  402. SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PREDL_CTL, 1, 1, 0),
  403. SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDL_CTL, 2, 1, 0),
  404. SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDL_CTL, 3, 1, 0),
  405. };
  406. /* PreDrive Right */
  407. static const struct snd_kcontrol_new twl4030_dapm_predriver_controls[] = {
  408. SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDR_CTL, 0, 1, 0),
  409. SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PREDR_CTL, 1, 1, 0),
  410. SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDR_CTL, 2, 1, 0),
  411. SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDR_CTL, 3, 1, 0),
  412. };
  413. /* Headset Left */
  414. static const struct snd_kcontrol_new twl4030_dapm_hsol_controls[] = {
  415. SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL, 0, 1, 0),
  416. SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_HS_SEL, 1, 1, 0),
  417. SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_HS_SEL, 2, 1, 0),
  418. };
  419. /* Headset Right */
  420. static const struct snd_kcontrol_new twl4030_dapm_hsor_controls[] = {
  421. SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL, 3, 1, 0),
  422. SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_HS_SEL, 4, 1, 0),
  423. SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_HS_SEL, 5, 1, 0),
  424. };
  425. /* Carkit Left */
  426. static const struct snd_kcontrol_new twl4030_dapm_carkitl_controls[] = {
  427. SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKL_CTL, 0, 1, 0),
  428. SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PRECKL_CTL, 1, 1, 0),
  429. SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PRECKL_CTL, 2, 1, 0),
  430. };
  431. /* Carkit Right */
  432. static const struct snd_kcontrol_new twl4030_dapm_carkitr_controls[] = {
  433. SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKR_CTL, 0, 1, 0),
  434. SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PRECKR_CTL, 1, 1, 0),
  435. SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PRECKR_CTL, 2, 1, 0),
  436. };
  437. /* Handsfree Left */
  438. static const char *twl4030_handsfreel_texts[] =
  439. {"Voice", "AudioL1", "AudioL2", "AudioR2"};
  440. static const struct soc_enum twl4030_handsfreel_enum =
  441. SOC_ENUM_SINGLE(TWL4030_REG_HFL_CTL, 0,
  442. ARRAY_SIZE(twl4030_handsfreel_texts),
  443. twl4030_handsfreel_texts);
  444. static const struct snd_kcontrol_new twl4030_dapm_handsfreel_control =
  445. SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum);
  446. /* Handsfree Left virtual mute */
  447. static const struct snd_kcontrol_new twl4030_dapm_handsfreelmute_control =
  448. SOC_DAPM_SINGLE("Switch", TWL4030_REG_SW_SHADOW, 0, 1, 0);
  449. /* Handsfree Right */
  450. static const char *twl4030_handsfreer_texts[] =
  451. {"Voice", "AudioR1", "AudioR2", "AudioL2"};
  452. static const struct soc_enum twl4030_handsfreer_enum =
  453. SOC_ENUM_SINGLE(TWL4030_REG_HFR_CTL, 0,
  454. ARRAY_SIZE(twl4030_handsfreer_texts),
  455. twl4030_handsfreer_texts);
  456. static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control =
  457. SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum);
  458. /* Handsfree Right virtual mute */
  459. static const struct snd_kcontrol_new twl4030_dapm_handsfreermute_control =
  460. SOC_DAPM_SINGLE("Switch", TWL4030_REG_SW_SHADOW, 1, 1, 0);
  461. /* Vibra */
  462. /* Vibra audio path selection */
  463. static const char *twl4030_vibra_texts[] =
  464. {"AudioL1", "AudioR1", "AudioL2", "AudioR2"};
  465. static const struct soc_enum twl4030_vibra_enum =
  466. SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 2,
  467. ARRAY_SIZE(twl4030_vibra_texts),
  468. twl4030_vibra_texts);
  469. static const struct snd_kcontrol_new twl4030_dapm_vibra_control =
  470. SOC_DAPM_ENUM("Route", twl4030_vibra_enum);
  471. /* Vibra path selection: local vibrator (PWM) or audio driven */
  472. static const char *twl4030_vibrapath_texts[] =
  473. {"Local vibrator", "Audio"};
  474. static const struct soc_enum twl4030_vibrapath_enum =
  475. SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 4,
  476. ARRAY_SIZE(twl4030_vibrapath_texts),
  477. twl4030_vibrapath_texts);
  478. static const struct snd_kcontrol_new twl4030_dapm_vibrapath_control =
  479. SOC_DAPM_ENUM("Route", twl4030_vibrapath_enum);
  480. /* Left analog microphone selection */
  481. static const struct snd_kcontrol_new twl4030_dapm_analoglmic_controls[] = {
  482. SOC_DAPM_SINGLE("Main Mic Capture Switch",
  483. TWL4030_REG_ANAMICL, 0, 1, 0),
  484. SOC_DAPM_SINGLE("Headset Mic Capture Switch",
  485. TWL4030_REG_ANAMICL, 1, 1, 0),
  486. SOC_DAPM_SINGLE("AUXL Capture Switch",
  487. TWL4030_REG_ANAMICL, 2, 1, 0),
  488. SOC_DAPM_SINGLE("Carkit Mic Capture Switch",
  489. TWL4030_REG_ANAMICL, 3, 1, 0),
  490. };
  491. /* Right analog microphone selection */
  492. static const struct snd_kcontrol_new twl4030_dapm_analogrmic_controls[] = {
  493. SOC_DAPM_SINGLE("Sub Mic Capture Switch", TWL4030_REG_ANAMICR, 0, 1, 0),
  494. SOC_DAPM_SINGLE("AUXR Capture Switch", TWL4030_REG_ANAMICR, 2, 1, 0),
  495. };
  496. /* TX1 L/R Analog/Digital microphone selection */
  497. static const char *twl4030_micpathtx1_texts[] =
  498. {"Analog", "Digimic0"};
  499. static const struct soc_enum twl4030_micpathtx1_enum =
  500. SOC_ENUM_SINGLE(TWL4030_REG_ADCMICSEL, 0,
  501. ARRAY_SIZE(twl4030_micpathtx1_texts),
  502. twl4030_micpathtx1_texts);
  503. static const struct snd_kcontrol_new twl4030_dapm_micpathtx1_control =
  504. SOC_DAPM_ENUM("Route", twl4030_micpathtx1_enum);
  505. /* TX2 L/R Analog/Digital microphone selection */
  506. static const char *twl4030_micpathtx2_texts[] =
  507. {"Analog", "Digimic1"};
  508. static const struct soc_enum twl4030_micpathtx2_enum =
  509. SOC_ENUM_SINGLE(TWL4030_REG_ADCMICSEL, 2,
  510. ARRAY_SIZE(twl4030_micpathtx2_texts),
  511. twl4030_micpathtx2_texts);
  512. static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control =
  513. SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum);
  514. /* Analog bypass for AudioR1 */
  515. static const struct snd_kcontrol_new twl4030_dapm_abypassr1_control =
  516. SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR1_APGA_CTL, 2, 1, 0);
  517. /* Analog bypass for AudioL1 */
  518. static const struct snd_kcontrol_new twl4030_dapm_abypassl1_control =
  519. SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL1_APGA_CTL, 2, 1, 0);
  520. /* Analog bypass for AudioR2 */
  521. static const struct snd_kcontrol_new twl4030_dapm_abypassr2_control =
  522. SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR2_APGA_CTL, 2, 1, 0);
  523. /* Analog bypass for AudioL2 */
  524. static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control =
  525. SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL, 2, 1, 0);
  526. /* Analog bypass for Voice */
  527. static const struct snd_kcontrol_new twl4030_dapm_abypassv_control =
  528. SOC_DAPM_SINGLE("Switch", TWL4030_REG_VDL_APGA_CTL, 2, 1, 0);
  529. /* Digital bypass gain, mute instead of -30dB */
  530. static const unsigned int twl4030_dapm_dbypass_tlv[] = {
  531. TLV_DB_RANGE_HEAD(3),
  532. 0, 1, TLV_DB_SCALE_ITEM(-3000, 600, 1),
  533. 2, 3, TLV_DB_SCALE_ITEM(-2400, 0, 0),
  534. 4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0),
  535. };
  536. /* Digital bypass left (TX1L -> RX2L) */
  537. static const struct snd_kcontrol_new twl4030_dapm_dbypassl_control =
  538. SOC_DAPM_SINGLE_TLV("Volume",
  539. TWL4030_REG_ATX2ARXPGA, 3, 7, 0,
  540. twl4030_dapm_dbypass_tlv);
  541. /* Digital bypass right (TX1R -> RX2R) */
  542. static const struct snd_kcontrol_new twl4030_dapm_dbypassr_control =
  543. SOC_DAPM_SINGLE_TLV("Volume",
  544. TWL4030_REG_ATX2ARXPGA, 0, 7, 0,
  545. twl4030_dapm_dbypass_tlv);
  546. /*
  547. * Voice Sidetone GAIN volume control:
  548. * from -51 to -10 dB in 1 dB steps (mute instead of -51 dB)
  549. */
  550. static DECLARE_TLV_DB_SCALE(twl4030_dapm_dbypassv_tlv, -5100, 100, 1);
  551. /* Digital bypass voice: sidetone (VUL -> VDL)*/
  552. static const struct snd_kcontrol_new twl4030_dapm_dbypassv_control =
  553. SOC_DAPM_SINGLE_TLV("Volume",
  554. TWL4030_REG_VSTPGA, 0, 0x29, 0,
  555. twl4030_dapm_dbypassv_tlv);
  556. /*
  557. * Output PGA builder:
  558. * Handle the muting and unmuting of the given output (turning off the
  559. * amplifier associated with the output pin)
  560. * On mute bypass the reg_cache and write 0 to the register
  561. * On unmute: restore the register content from the reg_cache
  562. * Outputs handled in this way: Earpiece, PreDrivL/R, CarkitL/R
  563. */
  564. #define TWL4030_OUTPUT_PGA(pin_name, reg, mask) \
  565. static int pin_name##pga_event(struct snd_soc_dapm_widget *w, \
  566. struct snd_kcontrol *kcontrol, int event) \
  567. { \
  568. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \
  569. \
  570. switch (event) { \
  571. case SND_SOC_DAPM_POST_PMU: \
  572. twl4030->pin_name##_enabled = 1; \
  573. twl4030_write(w->codec, reg, \
  574. twl4030_read_reg_cache(w->codec, reg)); \
  575. break; \
  576. case SND_SOC_DAPM_POST_PMD: \
  577. twl4030->pin_name##_enabled = 0; \
  578. twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, \
  579. 0, reg); \
  580. break; \
  581. } \
  582. return 0; \
  583. }
  584. TWL4030_OUTPUT_PGA(earpiece, TWL4030_REG_EAR_CTL, TWL4030_EAR_GAIN);
  585. TWL4030_OUTPUT_PGA(predrivel, TWL4030_REG_PREDL_CTL, TWL4030_PREDL_GAIN);
  586. TWL4030_OUTPUT_PGA(predriver, TWL4030_REG_PREDR_CTL, TWL4030_PREDR_GAIN);
  587. TWL4030_OUTPUT_PGA(carkitl, TWL4030_REG_PRECKL_CTL, TWL4030_PRECKL_GAIN);
  588. TWL4030_OUTPUT_PGA(carkitr, TWL4030_REG_PRECKR_CTL, TWL4030_PRECKR_GAIN);
  589. static void handsfree_ramp(struct snd_soc_codec *codec, int reg, int ramp)
  590. {
  591. unsigned char hs_ctl;
  592. hs_ctl = twl4030_read_reg_cache(codec, reg);
  593. if (ramp) {
  594. /* HF ramp-up */
  595. hs_ctl |= TWL4030_HF_CTL_REF_EN;
  596. twl4030_write(codec, reg, hs_ctl);
  597. udelay(10);
  598. hs_ctl |= TWL4030_HF_CTL_RAMP_EN;
  599. twl4030_write(codec, reg, hs_ctl);
  600. udelay(40);
  601. hs_ctl |= TWL4030_HF_CTL_LOOP_EN;
  602. hs_ctl |= TWL4030_HF_CTL_HB_EN;
  603. twl4030_write(codec, reg, hs_ctl);
  604. } else {
  605. /* HF ramp-down */
  606. hs_ctl &= ~TWL4030_HF_CTL_LOOP_EN;
  607. hs_ctl &= ~TWL4030_HF_CTL_HB_EN;
  608. twl4030_write(codec, reg, hs_ctl);
  609. hs_ctl &= ~TWL4030_HF_CTL_RAMP_EN;
  610. twl4030_write(codec, reg, hs_ctl);
  611. udelay(40);
  612. hs_ctl &= ~TWL4030_HF_CTL_REF_EN;
  613. twl4030_write(codec, reg, hs_ctl);
  614. }
  615. }
  616. static int handsfreelpga_event(struct snd_soc_dapm_widget *w,
  617. struct snd_kcontrol *kcontrol, int event)
  618. {
  619. switch (event) {
  620. case SND_SOC_DAPM_POST_PMU:
  621. handsfree_ramp(w->codec, TWL4030_REG_HFL_CTL, 1);
  622. break;
  623. case SND_SOC_DAPM_POST_PMD:
  624. handsfree_ramp(w->codec, TWL4030_REG_HFL_CTL, 0);
  625. break;
  626. }
  627. return 0;
  628. }
  629. static int handsfreerpga_event(struct snd_soc_dapm_widget *w,
  630. struct snd_kcontrol *kcontrol, int event)
  631. {
  632. switch (event) {
  633. case SND_SOC_DAPM_POST_PMU:
  634. handsfree_ramp(w->codec, TWL4030_REG_HFR_CTL, 1);
  635. break;
  636. case SND_SOC_DAPM_POST_PMD:
  637. handsfree_ramp(w->codec, TWL4030_REG_HFR_CTL, 0);
  638. break;
  639. }
  640. return 0;
  641. }
  642. static int vibramux_event(struct snd_soc_dapm_widget *w,
  643. struct snd_kcontrol *kcontrol, int event)
  644. {
  645. twl4030_write(w->codec, TWL4030_REG_VIBRA_SET, 0xff);
  646. return 0;
  647. }
  648. static int apll_event(struct snd_soc_dapm_widget *w,
  649. struct snd_kcontrol *kcontrol, int event)
  650. {
  651. switch (event) {
  652. case SND_SOC_DAPM_PRE_PMU:
  653. twl4030_apll_enable(w->codec, 1);
  654. break;
  655. case SND_SOC_DAPM_POST_PMD:
  656. twl4030_apll_enable(w->codec, 0);
  657. break;
  658. }
  659. return 0;
  660. }
  661. static int aif_event(struct snd_soc_dapm_widget *w,
  662. struct snd_kcontrol *kcontrol, int event)
  663. {
  664. u8 audio_if;
  665. audio_if = twl4030_read_reg_cache(w->codec, TWL4030_REG_AUDIO_IF);
  666. switch (event) {
  667. case SND_SOC_DAPM_PRE_PMU:
  668. /* Enable AIF */
  669. /* enable the PLL before we use it to clock the DAI */
  670. twl4030_apll_enable(w->codec, 1);
  671. twl4030_write(w->codec, TWL4030_REG_AUDIO_IF,
  672. audio_if | TWL4030_AIF_EN);
  673. break;
  674. case SND_SOC_DAPM_POST_PMD:
  675. /* disable the DAI before we stop it's source PLL */
  676. twl4030_write(w->codec, TWL4030_REG_AUDIO_IF,
  677. audio_if & ~TWL4030_AIF_EN);
  678. twl4030_apll_enable(w->codec, 0);
  679. break;
  680. }
  681. return 0;
  682. }
  683. static void headset_ramp(struct snd_soc_codec *codec, int ramp)
  684. {
  685. unsigned char hs_gain, hs_pop;
  686. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  687. struct twl4030_codec_data *pdata = twl4030->pdata;
  688. /* Base values for ramp delay calculation: 2^19 - 2^26 */
  689. unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
  690. 8388608, 16777216, 33554432, 67108864};
  691. unsigned int delay;
  692. hs_gain = twl4030_read_reg_cache(codec, TWL4030_REG_HS_GAIN_SET);
  693. hs_pop = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
  694. delay = (ramp_base[(hs_pop & TWL4030_RAMP_DELAY) >> 2] /
  695. twl4030->sysclk) + 1;
  696. /* Enable external mute control, this dramatically reduces
  697. * the pop-noise */
  698. if (pdata && pdata->hs_extmute) {
  699. if (gpio_is_valid(pdata->hs_extmute_gpio)) {
  700. gpio_set_value(pdata->hs_extmute_gpio, 1);
  701. } else {
  702. hs_pop |= TWL4030_EXTMUTE;
  703. twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
  704. }
  705. }
  706. if (ramp) {
  707. /* Headset ramp-up according to the TRM */
  708. hs_pop |= TWL4030_VMID_EN;
  709. twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
  710. /* Actually write to the register */
  711. twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
  712. hs_gain,
  713. TWL4030_REG_HS_GAIN_SET);
  714. hs_pop |= TWL4030_RAMP_EN;
  715. twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
  716. /* Wait ramp delay time + 1, so the VMID can settle */
  717. twl4030_wait_ms(delay);
  718. } else {
  719. /* Headset ramp-down _not_ according to
  720. * the TRM, but in a way that it is working */
  721. hs_pop &= ~TWL4030_RAMP_EN;
  722. twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
  723. /* Wait ramp delay time + 1, so the VMID can settle */
  724. twl4030_wait_ms(delay);
  725. /* Bypass the reg_cache to mute the headset */
  726. twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
  727. hs_gain & (~0x0f),
  728. TWL4030_REG_HS_GAIN_SET);
  729. hs_pop &= ~TWL4030_VMID_EN;
  730. twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
  731. }
  732. /* Disable external mute */
  733. if (pdata && pdata->hs_extmute) {
  734. if (gpio_is_valid(pdata->hs_extmute_gpio)) {
  735. gpio_set_value(pdata->hs_extmute_gpio, 0);
  736. } else {
  737. hs_pop &= ~TWL4030_EXTMUTE;
  738. twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
  739. }
  740. }
  741. }
  742. static int headsetlpga_event(struct snd_soc_dapm_widget *w,
  743. struct snd_kcontrol *kcontrol, int event)
  744. {
  745. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
  746. switch (event) {
  747. case SND_SOC_DAPM_POST_PMU:
  748. /* Do the ramp-up only once */
  749. if (!twl4030->hsr_enabled)
  750. headset_ramp(w->codec, 1);
  751. twl4030->hsl_enabled = 1;
  752. break;
  753. case SND_SOC_DAPM_POST_PMD:
  754. /* Do the ramp-down only if both headsetL/R is disabled */
  755. if (!twl4030->hsr_enabled)
  756. headset_ramp(w->codec, 0);
  757. twl4030->hsl_enabled = 0;
  758. break;
  759. }
  760. return 0;
  761. }
  762. static int headsetrpga_event(struct snd_soc_dapm_widget *w,
  763. struct snd_kcontrol *kcontrol, int event)
  764. {
  765. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
  766. switch (event) {
  767. case SND_SOC_DAPM_POST_PMU:
  768. /* Do the ramp-up only once */
  769. if (!twl4030->hsl_enabled)
  770. headset_ramp(w->codec, 1);
  771. twl4030->hsr_enabled = 1;
  772. break;
  773. case SND_SOC_DAPM_POST_PMD:
  774. /* Do the ramp-down only if both headsetL/R is disabled */
  775. if (!twl4030->hsl_enabled)
  776. headset_ramp(w->codec, 0);
  777. twl4030->hsr_enabled = 0;
  778. break;
  779. }
  780. return 0;
  781. }
  782. static int digimic_event(struct snd_soc_dapm_widget *w,
  783. struct snd_kcontrol *kcontrol, int event)
  784. {
  785. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
  786. struct twl4030_codec_data *pdata = twl4030->pdata;
  787. if (pdata && pdata->digimic_delay)
  788. twl4030_wait_ms(pdata->digimic_delay);
  789. return 0;
  790. }
  791. /*
  792. * Some of the gain controls in TWL (mostly those which are associated with
  793. * the outputs) are implemented in an interesting way:
  794. * 0x0 : Power down (mute)
  795. * 0x1 : 6dB
  796. * 0x2 : 0 dB
  797. * 0x3 : -6 dB
  798. * Inverting not going to help with these.
  799. * Custom volsw and volsw_2r get/put functions to handle these gain bits.
  800. */
  801. static int snd_soc_get_volsw_twl4030(struct snd_kcontrol *kcontrol,
  802. struct snd_ctl_elem_value *ucontrol)
  803. {
  804. struct soc_mixer_control *mc =
  805. (struct soc_mixer_control *)kcontrol->private_value;
  806. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  807. unsigned int reg = mc->reg;
  808. unsigned int shift = mc->shift;
  809. unsigned int rshift = mc->rshift;
  810. int max = mc->max;
  811. int mask = (1 << fls(max)) - 1;
  812. ucontrol->value.integer.value[0] =
  813. (snd_soc_read(codec, reg) >> shift) & mask;
  814. if (ucontrol->value.integer.value[0])
  815. ucontrol->value.integer.value[0] =
  816. max + 1 - ucontrol->value.integer.value[0];
  817. if (shift != rshift) {
  818. ucontrol->value.integer.value[1] =
  819. (snd_soc_read(codec, reg) >> rshift) & mask;
  820. if (ucontrol->value.integer.value[1])
  821. ucontrol->value.integer.value[1] =
  822. max + 1 - ucontrol->value.integer.value[1];
  823. }
  824. return 0;
  825. }
  826. static int snd_soc_put_volsw_twl4030(struct snd_kcontrol *kcontrol,
  827. struct snd_ctl_elem_value *ucontrol)
  828. {
  829. struct soc_mixer_control *mc =
  830. (struct soc_mixer_control *)kcontrol->private_value;
  831. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  832. unsigned int reg = mc->reg;
  833. unsigned int shift = mc->shift;
  834. unsigned int rshift = mc->rshift;
  835. int max = mc->max;
  836. int mask = (1 << fls(max)) - 1;
  837. unsigned short val, val2, val_mask;
  838. val = (ucontrol->value.integer.value[0] & mask);
  839. val_mask = mask << shift;
  840. if (val)
  841. val = max + 1 - val;
  842. val = val << shift;
  843. if (shift != rshift) {
  844. val2 = (ucontrol->value.integer.value[1] & mask);
  845. val_mask |= mask << rshift;
  846. if (val2)
  847. val2 = max + 1 - val2;
  848. val |= val2 << rshift;
  849. }
  850. return snd_soc_update_bits(codec, reg, val_mask, val);
  851. }
  852. static int snd_soc_get_volsw_r2_twl4030(struct snd_kcontrol *kcontrol,
  853. struct snd_ctl_elem_value *ucontrol)
  854. {
  855. struct soc_mixer_control *mc =
  856. (struct soc_mixer_control *)kcontrol->private_value;
  857. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  858. unsigned int reg = mc->reg;
  859. unsigned int reg2 = mc->rreg;
  860. unsigned int shift = mc->shift;
  861. int max = mc->max;
  862. int mask = (1<<fls(max))-1;
  863. ucontrol->value.integer.value[0] =
  864. (snd_soc_read(codec, reg) >> shift) & mask;
  865. ucontrol->value.integer.value[1] =
  866. (snd_soc_read(codec, reg2) >> shift) & mask;
  867. if (ucontrol->value.integer.value[0])
  868. ucontrol->value.integer.value[0] =
  869. max + 1 - ucontrol->value.integer.value[0];
  870. if (ucontrol->value.integer.value[1])
  871. ucontrol->value.integer.value[1] =
  872. max + 1 - ucontrol->value.integer.value[1];
  873. return 0;
  874. }
  875. static int snd_soc_put_volsw_r2_twl4030(struct snd_kcontrol *kcontrol,
  876. struct snd_ctl_elem_value *ucontrol)
  877. {
  878. struct soc_mixer_control *mc =
  879. (struct soc_mixer_control *)kcontrol->private_value;
  880. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  881. unsigned int reg = mc->reg;
  882. unsigned int reg2 = mc->rreg;
  883. unsigned int shift = mc->shift;
  884. int max = mc->max;
  885. int mask = (1 << fls(max)) - 1;
  886. int err;
  887. unsigned short val, val2, val_mask;
  888. val_mask = mask << shift;
  889. val = (ucontrol->value.integer.value[0] & mask);
  890. val2 = (ucontrol->value.integer.value[1] & mask);
  891. if (val)
  892. val = max + 1 - val;
  893. if (val2)
  894. val2 = max + 1 - val2;
  895. val = val << shift;
  896. val2 = val2 << shift;
  897. err = snd_soc_update_bits(codec, reg, val_mask, val);
  898. if (err < 0)
  899. return err;
  900. err = snd_soc_update_bits(codec, reg2, val_mask, val2);
  901. return err;
  902. }
  903. /* Codec operation modes */
  904. static const char *twl4030_op_modes_texts[] = {
  905. "Option 2 (voice/audio)", "Option 1 (audio)"
  906. };
  907. static const struct soc_enum twl4030_op_modes_enum =
  908. SOC_ENUM_SINGLE(TWL4030_REG_CODEC_MODE, 0,
  909. ARRAY_SIZE(twl4030_op_modes_texts),
  910. twl4030_op_modes_texts);
  911. static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
  912. struct snd_ctl_elem_value *ucontrol)
  913. {
  914. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  915. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  916. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  917. unsigned short val;
  918. unsigned short mask;
  919. if (twl4030->configured) {
  920. dev_err(codec->dev,
  921. "operation mode cannot be changed on-the-fly\n");
  922. return -EBUSY;
  923. }
  924. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  925. return -EINVAL;
  926. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  927. mask = e->mask << e->shift_l;
  928. if (e->shift_l != e->shift_r) {
  929. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  930. return -EINVAL;
  931. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  932. mask |= e->mask << e->shift_r;
  933. }
  934. return snd_soc_update_bits(codec, e->reg, mask, val);
  935. }
  936. /*
  937. * FGAIN volume control:
  938. * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB)
  939. */
  940. static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1);
  941. /*
  942. * CGAIN volume control:
  943. * 0 dB to 12 dB in 6 dB steps
  944. * value 2 and 3 means 12 dB
  945. */
  946. static DECLARE_TLV_DB_SCALE(digital_coarse_tlv, 0, 600, 0);
  947. /*
  948. * Voice Downlink GAIN volume control:
  949. * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB)
  950. */
  951. static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv, -3700, 100, 1);
  952. /*
  953. * Analog playback gain
  954. * -24 dB to 12 dB in 2 dB steps
  955. */
  956. static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0);
  957. /*
  958. * Gain controls tied to outputs
  959. * -6 dB to 6 dB in 6 dB steps (mute instead of -12)
  960. */
  961. static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1);
  962. /*
  963. * Gain control for earpiece amplifier
  964. * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
  965. */
  966. static DECLARE_TLV_DB_SCALE(output_ear_tvl, -600, 600, 1);
  967. /*
  968. * Capture gain after the ADCs
  969. * from 0 dB to 31 dB in 1 dB steps
  970. */
  971. static DECLARE_TLV_DB_SCALE(digital_capture_tlv, 0, 100, 0);
  972. /*
  973. * Gain control for input amplifiers
  974. * 0 dB to 30 dB in 6 dB steps
  975. */
  976. static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0);
  977. /* AVADC clock priority */
  978. static const char *twl4030_avadc_clk_priority_texts[] = {
  979. "Voice high priority", "HiFi high priority"
  980. };
  981. static const struct soc_enum twl4030_avadc_clk_priority_enum =
  982. SOC_ENUM_SINGLE(TWL4030_REG_AVADC_CTL, 2,
  983. ARRAY_SIZE(twl4030_avadc_clk_priority_texts),
  984. twl4030_avadc_clk_priority_texts);
  985. static const char *twl4030_rampdelay_texts[] = {
  986. "27/20/14 ms", "55/40/27 ms", "109/81/55 ms", "218/161/109 ms",
  987. "437/323/218 ms", "874/645/437 ms", "1748/1291/874 ms",
  988. "3495/2581/1748 ms"
  989. };
  990. static const struct soc_enum twl4030_rampdelay_enum =
  991. SOC_ENUM_SINGLE(TWL4030_REG_HS_POPN_SET, 2,
  992. ARRAY_SIZE(twl4030_rampdelay_texts),
  993. twl4030_rampdelay_texts);
  994. /* Vibra H-bridge direction mode */
  995. static const char *twl4030_vibradirmode_texts[] = {
  996. "Vibra H-bridge direction", "Audio data MSB",
  997. };
  998. static const struct soc_enum twl4030_vibradirmode_enum =
  999. SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 5,
  1000. ARRAY_SIZE(twl4030_vibradirmode_texts),
  1001. twl4030_vibradirmode_texts);
  1002. /* Vibra H-bridge direction */
  1003. static const char *twl4030_vibradir_texts[] = {
  1004. "Positive polarity", "Negative polarity",
  1005. };
  1006. static const struct soc_enum twl4030_vibradir_enum =
  1007. SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 1,
  1008. ARRAY_SIZE(twl4030_vibradir_texts),
  1009. twl4030_vibradir_texts);
  1010. /* Digimic Left and right swapping */
  1011. static const char *twl4030_digimicswap_texts[] = {
  1012. "Not swapped", "Swapped",
  1013. };
  1014. static const struct soc_enum twl4030_digimicswap_enum =
  1015. SOC_ENUM_SINGLE(TWL4030_REG_MISC_SET_1, 0,
  1016. ARRAY_SIZE(twl4030_digimicswap_texts),
  1017. twl4030_digimicswap_texts);
  1018. static const struct snd_kcontrol_new twl4030_snd_controls[] = {
  1019. /* Codec operation mode control */
  1020. SOC_ENUM_EXT("Codec Operation Mode", twl4030_op_modes_enum,
  1021. snd_soc_get_enum_double,
  1022. snd_soc_put_twl4030_opmode_enum_double),
  1023. /* Common playback gain controls */
  1024. SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume",
  1025. TWL4030_REG_ARXL1PGA, TWL4030_REG_ARXR1PGA,
  1026. 0, 0x3f, 0, digital_fine_tlv),
  1027. SOC_DOUBLE_R_TLV("DAC2 Digital Fine Playback Volume",
  1028. TWL4030_REG_ARXL2PGA, TWL4030_REG_ARXR2PGA,
  1029. 0, 0x3f, 0, digital_fine_tlv),
  1030. SOC_DOUBLE_R_TLV("DAC1 Digital Coarse Playback Volume",
  1031. TWL4030_REG_ARXL1PGA, TWL4030_REG_ARXR1PGA,
  1032. 6, 0x2, 0, digital_coarse_tlv),
  1033. SOC_DOUBLE_R_TLV("DAC2 Digital Coarse Playback Volume",
  1034. TWL4030_REG_ARXL2PGA, TWL4030_REG_ARXR2PGA,
  1035. 6, 0x2, 0, digital_coarse_tlv),
  1036. SOC_DOUBLE_R_TLV("DAC1 Analog Playback Volume",
  1037. TWL4030_REG_ARXL1_APGA_CTL, TWL4030_REG_ARXR1_APGA_CTL,
  1038. 3, 0x12, 1, analog_tlv),
  1039. SOC_DOUBLE_R_TLV("DAC2 Analog Playback Volume",
  1040. TWL4030_REG_ARXL2_APGA_CTL, TWL4030_REG_ARXR2_APGA_CTL,
  1041. 3, 0x12, 1, analog_tlv),
  1042. SOC_DOUBLE_R("DAC1 Analog Playback Switch",
  1043. TWL4030_REG_ARXL1_APGA_CTL, TWL4030_REG_ARXR1_APGA_CTL,
  1044. 1, 1, 0),
  1045. SOC_DOUBLE_R("DAC2 Analog Playback Switch",
  1046. TWL4030_REG_ARXL2_APGA_CTL, TWL4030_REG_ARXR2_APGA_CTL,
  1047. 1, 1, 0),
  1048. /* Common voice downlink gain controls */
  1049. SOC_SINGLE_TLV("DAC Voice Digital Downlink Volume",
  1050. TWL4030_REG_VRXPGA, 0, 0x31, 0, digital_voice_downlink_tlv),
  1051. SOC_SINGLE_TLV("DAC Voice Analog Downlink Volume",
  1052. TWL4030_REG_VDL_APGA_CTL, 3, 0x12, 1, analog_tlv),
  1053. SOC_SINGLE("DAC Voice Analog Downlink Switch",
  1054. TWL4030_REG_VDL_APGA_CTL, 1, 1, 0),
  1055. /* Separate output gain controls */
  1056. SOC_DOUBLE_R_EXT_TLV("PreDriv Playback Volume",
  1057. TWL4030_REG_PREDL_CTL, TWL4030_REG_PREDR_CTL,
  1058. 4, 3, 0, snd_soc_get_volsw_r2_twl4030,
  1059. snd_soc_put_volsw_r2_twl4030, output_tvl),
  1060. SOC_DOUBLE_EXT_TLV("Headset Playback Volume",
  1061. TWL4030_REG_HS_GAIN_SET, 0, 2, 3, 0, snd_soc_get_volsw_twl4030,
  1062. snd_soc_put_volsw_twl4030, output_tvl),
  1063. SOC_DOUBLE_R_EXT_TLV("Carkit Playback Volume",
  1064. TWL4030_REG_PRECKL_CTL, TWL4030_REG_PRECKR_CTL,
  1065. 4, 3, 0, snd_soc_get_volsw_r2_twl4030,
  1066. snd_soc_put_volsw_r2_twl4030, output_tvl),
  1067. SOC_SINGLE_EXT_TLV("Earpiece Playback Volume",
  1068. TWL4030_REG_EAR_CTL, 4, 3, 0, snd_soc_get_volsw_twl4030,
  1069. snd_soc_put_volsw_twl4030, output_ear_tvl),
  1070. /* Common capture gain controls */
  1071. SOC_DOUBLE_R_TLV("TX1 Digital Capture Volume",
  1072. TWL4030_REG_ATXL1PGA, TWL4030_REG_ATXR1PGA,
  1073. 0, 0x1f, 0, digital_capture_tlv),
  1074. SOC_DOUBLE_R_TLV("TX2 Digital Capture Volume",
  1075. TWL4030_REG_AVTXL2PGA, TWL4030_REG_AVTXR2PGA,
  1076. 0, 0x1f, 0, digital_capture_tlv),
  1077. SOC_DOUBLE_TLV("Analog Capture Volume", TWL4030_REG_ANAMIC_GAIN,
  1078. 0, 3, 5, 0, input_gain_tlv),
  1079. SOC_ENUM("AVADC Clock Priority", twl4030_avadc_clk_priority_enum),
  1080. SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum),
  1081. SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum),
  1082. SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum),
  1083. SOC_ENUM("Digimic LR Swap", twl4030_digimicswap_enum),
  1084. };
  1085. static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
  1086. /* Left channel inputs */
  1087. SND_SOC_DAPM_INPUT("MAINMIC"),
  1088. SND_SOC_DAPM_INPUT("HSMIC"),
  1089. SND_SOC_DAPM_INPUT("AUXL"),
  1090. SND_SOC_DAPM_INPUT("CARKITMIC"),
  1091. /* Right channel inputs */
  1092. SND_SOC_DAPM_INPUT("SUBMIC"),
  1093. SND_SOC_DAPM_INPUT("AUXR"),
  1094. /* Digital microphones (Stereo) */
  1095. SND_SOC_DAPM_INPUT("DIGIMIC0"),
  1096. SND_SOC_DAPM_INPUT("DIGIMIC1"),
  1097. /* Outputs */
  1098. SND_SOC_DAPM_OUTPUT("EARPIECE"),
  1099. SND_SOC_DAPM_OUTPUT("PREDRIVEL"),
  1100. SND_SOC_DAPM_OUTPUT("PREDRIVER"),
  1101. SND_SOC_DAPM_OUTPUT("HSOL"),
  1102. SND_SOC_DAPM_OUTPUT("HSOR"),
  1103. SND_SOC_DAPM_OUTPUT("CARKITL"),
  1104. SND_SOC_DAPM_OUTPUT("CARKITR"),
  1105. SND_SOC_DAPM_OUTPUT("HFL"),
  1106. SND_SOC_DAPM_OUTPUT("HFR"),
  1107. SND_SOC_DAPM_OUTPUT("VIBRA"),
  1108. /* AIF and APLL clocks for running DAIs (including loopback) */
  1109. SND_SOC_DAPM_OUTPUT("Virtual HiFi OUT"),
  1110. SND_SOC_DAPM_INPUT("Virtual HiFi IN"),
  1111. SND_SOC_DAPM_OUTPUT("Virtual Voice OUT"),
  1112. /* DACs */
  1113. SND_SOC_DAPM_DAC("DAC Right1", NULL, SND_SOC_NOPM, 0, 0),
  1114. SND_SOC_DAPM_DAC("DAC Left1", NULL, SND_SOC_NOPM, 0, 0),
  1115. SND_SOC_DAPM_DAC("DAC Right2", NULL, SND_SOC_NOPM, 0, 0),
  1116. SND_SOC_DAPM_DAC("DAC Left2", NULL, SND_SOC_NOPM, 0, 0),
  1117. SND_SOC_DAPM_DAC("DAC Voice", NULL, SND_SOC_NOPM, 0, 0),
  1118. /* Analog bypasses */
  1119. SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1120. &twl4030_dapm_abypassr1_control),
  1121. SND_SOC_DAPM_SWITCH("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1122. &twl4030_dapm_abypassl1_control),
  1123. SND_SOC_DAPM_SWITCH("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1124. &twl4030_dapm_abypassr2_control),
  1125. SND_SOC_DAPM_SWITCH("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1126. &twl4030_dapm_abypassl2_control),
  1127. SND_SOC_DAPM_SWITCH("Voice Analog Loopback", SND_SOC_NOPM, 0, 0,
  1128. &twl4030_dapm_abypassv_control),
  1129. /* Master analog loopback switch */
  1130. SND_SOC_DAPM_SUPPLY("FM Loop Enable", TWL4030_REG_MISC_SET_1, 5, 0,
  1131. NULL, 0),
  1132. /* Digital bypasses */
  1133. SND_SOC_DAPM_SWITCH("Left Digital Loopback", SND_SOC_NOPM, 0, 0,
  1134. &twl4030_dapm_dbypassl_control),
  1135. SND_SOC_DAPM_SWITCH("Right Digital Loopback", SND_SOC_NOPM, 0, 0,
  1136. &twl4030_dapm_dbypassr_control),
  1137. SND_SOC_DAPM_SWITCH("Voice Digital Loopback", SND_SOC_NOPM, 0, 0,
  1138. &twl4030_dapm_dbypassv_control),
  1139. /* Digital mixers, power control for the physical DACs */
  1140. SND_SOC_DAPM_MIXER("Digital R1 Playback Mixer",
  1141. TWL4030_REG_AVDAC_CTL, 0, 0, NULL, 0),
  1142. SND_SOC_DAPM_MIXER("Digital L1 Playback Mixer",
  1143. TWL4030_REG_AVDAC_CTL, 1, 0, NULL, 0),
  1144. SND_SOC_DAPM_MIXER("Digital R2 Playback Mixer",
  1145. TWL4030_REG_AVDAC_CTL, 2, 0, NULL, 0),
  1146. SND_SOC_DAPM_MIXER("Digital L2 Playback Mixer",
  1147. TWL4030_REG_AVDAC_CTL, 3, 0, NULL, 0),
  1148. SND_SOC_DAPM_MIXER("Digital Voice Playback Mixer",
  1149. TWL4030_REG_AVDAC_CTL, 4, 0, NULL, 0),
  1150. /* Analog mixers, power control for the physical PGAs */
  1151. SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer",
  1152. TWL4030_REG_ARXR1_APGA_CTL, 0, 0, NULL, 0),
  1153. SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer",
  1154. TWL4030_REG_ARXL1_APGA_CTL, 0, 0, NULL, 0),
  1155. SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer",
  1156. TWL4030_REG_ARXR2_APGA_CTL, 0, 0, NULL, 0),
  1157. SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer",
  1158. TWL4030_REG_ARXL2_APGA_CTL, 0, 0, NULL, 0),
  1159. SND_SOC_DAPM_MIXER("Analog Voice Playback Mixer",
  1160. TWL4030_REG_VDL_APGA_CTL, 0, 0, NULL, 0),
  1161. SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM, 0, 0, apll_event,
  1162. SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
  1163. SND_SOC_DAPM_SUPPLY("AIF Enable", SND_SOC_NOPM, 0, 0, aif_event,
  1164. SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
  1165. /* Output MIXER controls */
  1166. /* Earpiece */
  1167. SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
  1168. &twl4030_dapm_earpiece_controls[0],
  1169. ARRAY_SIZE(twl4030_dapm_earpiece_controls)),
  1170. SND_SOC_DAPM_PGA_E("Earpiece PGA", SND_SOC_NOPM,
  1171. 0, 0, NULL, 0, earpiecepga_event,
  1172. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1173. /* PreDrivL/R */
  1174. SND_SOC_DAPM_MIXER("PredriveL Mixer", SND_SOC_NOPM, 0, 0,
  1175. &twl4030_dapm_predrivel_controls[0],
  1176. ARRAY_SIZE(twl4030_dapm_predrivel_controls)),
  1177. SND_SOC_DAPM_PGA_E("PredriveL PGA", SND_SOC_NOPM,
  1178. 0, 0, NULL, 0, predrivelpga_event,
  1179. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1180. SND_SOC_DAPM_MIXER("PredriveR Mixer", SND_SOC_NOPM, 0, 0,
  1181. &twl4030_dapm_predriver_controls[0],
  1182. ARRAY_SIZE(twl4030_dapm_predriver_controls)),
  1183. SND_SOC_DAPM_PGA_E("PredriveR PGA", SND_SOC_NOPM,
  1184. 0, 0, NULL, 0, predriverpga_event,
  1185. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1186. /* HeadsetL/R */
  1187. SND_SOC_DAPM_MIXER("HeadsetL Mixer", SND_SOC_NOPM, 0, 0,
  1188. &twl4030_dapm_hsol_controls[0],
  1189. ARRAY_SIZE(twl4030_dapm_hsol_controls)),
  1190. SND_SOC_DAPM_PGA_E("HeadsetL PGA", SND_SOC_NOPM,
  1191. 0, 0, NULL, 0, headsetlpga_event,
  1192. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1193. SND_SOC_DAPM_MIXER("HeadsetR Mixer", SND_SOC_NOPM, 0, 0,
  1194. &twl4030_dapm_hsor_controls[0],
  1195. ARRAY_SIZE(twl4030_dapm_hsor_controls)),
  1196. SND_SOC_DAPM_PGA_E("HeadsetR PGA", SND_SOC_NOPM,
  1197. 0, 0, NULL, 0, headsetrpga_event,
  1198. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1199. /* CarkitL/R */
  1200. SND_SOC_DAPM_MIXER("CarkitL Mixer", SND_SOC_NOPM, 0, 0,
  1201. &twl4030_dapm_carkitl_controls[0],
  1202. ARRAY_SIZE(twl4030_dapm_carkitl_controls)),
  1203. SND_SOC_DAPM_PGA_E("CarkitL PGA", SND_SOC_NOPM,
  1204. 0, 0, NULL, 0, carkitlpga_event,
  1205. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1206. SND_SOC_DAPM_MIXER("CarkitR Mixer", SND_SOC_NOPM, 0, 0,
  1207. &twl4030_dapm_carkitr_controls[0],
  1208. ARRAY_SIZE(twl4030_dapm_carkitr_controls)),
  1209. SND_SOC_DAPM_PGA_E("CarkitR PGA", SND_SOC_NOPM,
  1210. 0, 0, NULL, 0, carkitrpga_event,
  1211. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1212. /* Output MUX controls */
  1213. /* HandsfreeL/R */
  1214. SND_SOC_DAPM_MUX("HandsfreeL Mux", SND_SOC_NOPM, 0, 0,
  1215. &twl4030_dapm_handsfreel_control),
  1216. SND_SOC_DAPM_SWITCH("HandsfreeL", SND_SOC_NOPM, 0, 0,
  1217. &twl4030_dapm_handsfreelmute_control),
  1218. SND_SOC_DAPM_PGA_E("HandsfreeL PGA", SND_SOC_NOPM,
  1219. 0, 0, NULL, 0, handsfreelpga_event,
  1220. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1221. SND_SOC_DAPM_MUX("HandsfreeR Mux", SND_SOC_NOPM, 5, 0,
  1222. &twl4030_dapm_handsfreer_control),
  1223. SND_SOC_DAPM_SWITCH("HandsfreeR", SND_SOC_NOPM, 0, 0,
  1224. &twl4030_dapm_handsfreermute_control),
  1225. SND_SOC_DAPM_PGA_E("HandsfreeR PGA", SND_SOC_NOPM,
  1226. 0, 0, NULL, 0, handsfreerpga_event,
  1227. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1228. /* Vibra */
  1229. SND_SOC_DAPM_MUX_E("Vibra Mux", TWL4030_REG_VIBRA_CTL, 0, 0,
  1230. &twl4030_dapm_vibra_control, vibramux_event,
  1231. SND_SOC_DAPM_PRE_PMU),
  1232. SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM, 0, 0,
  1233. &twl4030_dapm_vibrapath_control),
  1234. /* Introducing four virtual ADC, since TWL4030 have four channel for
  1235. capture */
  1236. SND_SOC_DAPM_ADC("ADC Virtual Left1", NULL, SND_SOC_NOPM, 0, 0),
  1237. SND_SOC_DAPM_ADC("ADC Virtual Right1", NULL, SND_SOC_NOPM, 0, 0),
  1238. SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL, SND_SOC_NOPM, 0, 0),
  1239. SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL, SND_SOC_NOPM, 0, 0),
  1240. /* Analog/Digital mic path selection.
  1241. TX1 Left/Right: either analog Left/Right or Digimic0
  1242. TX2 Left/Right: either analog Left/Right or Digimic1 */
  1243. SND_SOC_DAPM_MUX("TX1 Capture Route", SND_SOC_NOPM, 0, 0,
  1244. &twl4030_dapm_micpathtx1_control),
  1245. SND_SOC_DAPM_MUX("TX2 Capture Route", SND_SOC_NOPM, 0, 0,
  1246. &twl4030_dapm_micpathtx2_control),
  1247. /* Analog input mixers for the capture amplifiers */
  1248. SND_SOC_DAPM_MIXER("Analog Left",
  1249. TWL4030_REG_ANAMICL, 4, 0,
  1250. &twl4030_dapm_analoglmic_controls[0],
  1251. ARRAY_SIZE(twl4030_dapm_analoglmic_controls)),
  1252. SND_SOC_DAPM_MIXER("Analog Right",
  1253. TWL4030_REG_ANAMICR, 4, 0,
  1254. &twl4030_dapm_analogrmic_controls[0],
  1255. ARRAY_SIZE(twl4030_dapm_analogrmic_controls)),
  1256. SND_SOC_DAPM_PGA("ADC Physical Left",
  1257. TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0),
  1258. SND_SOC_DAPM_PGA("ADC Physical Right",
  1259. TWL4030_REG_AVADC_CTL, 1, 0, NULL, 0),
  1260. SND_SOC_DAPM_PGA_E("Digimic0 Enable",
  1261. TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0,
  1262. digimic_event, SND_SOC_DAPM_POST_PMU),
  1263. SND_SOC_DAPM_PGA_E("Digimic1 Enable",
  1264. TWL4030_REG_ADCMICSEL, 3, 0, NULL, 0,
  1265. digimic_event, SND_SOC_DAPM_POST_PMU),
  1266. SND_SOC_DAPM_SUPPLY("micbias1 select", TWL4030_REG_MICBIAS_CTL, 5, 0,
  1267. NULL, 0),
  1268. SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL, 6, 0,
  1269. NULL, 0),
  1270. SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0),
  1271. SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0),
  1272. SND_SOC_DAPM_MICBIAS("Headset Mic Bias", TWL4030_REG_MICBIAS_CTL, 2, 0),
  1273. };
  1274. static const struct snd_soc_dapm_route intercon[] = {
  1275. /* Stream -> DAC mapping */
  1276. {"DAC Right1", NULL, "HiFi Playback"},
  1277. {"DAC Left1", NULL, "HiFi Playback"},
  1278. {"DAC Right2", NULL, "HiFi Playback"},
  1279. {"DAC Left2", NULL, "HiFi Playback"},
  1280. {"DAC Voice", NULL, "Voice Playback"},
  1281. /* ADC -> Stream mapping */
  1282. {"HiFi Capture", NULL, "ADC Virtual Left1"},
  1283. {"HiFi Capture", NULL, "ADC Virtual Right1"},
  1284. {"HiFi Capture", NULL, "ADC Virtual Left2"},
  1285. {"HiFi Capture", NULL, "ADC Virtual Right2"},
  1286. {"Voice Capture", NULL, "ADC Virtual Left1"},
  1287. {"Voice Capture", NULL, "ADC Virtual Right1"},
  1288. {"Voice Capture", NULL, "ADC Virtual Left2"},
  1289. {"Voice Capture", NULL, "ADC Virtual Right2"},
  1290. {"Digital L1 Playback Mixer", NULL, "DAC Left1"},
  1291. {"Digital R1 Playback Mixer", NULL, "DAC Right1"},
  1292. {"Digital L2 Playback Mixer", NULL, "DAC Left2"},
  1293. {"Digital R2 Playback Mixer", NULL, "DAC Right2"},
  1294. {"Digital Voice Playback Mixer", NULL, "DAC Voice"},
  1295. /* Supply for the digital part (APLL) */
  1296. {"Digital Voice Playback Mixer", NULL, "APLL Enable"},
  1297. {"DAC Left1", NULL, "AIF Enable"},
  1298. {"DAC Right1", NULL, "AIF Enable"},
  1299. {"DAC Left2", NULL, "AIF Enable"},
  1300. {"DAC Right1", NULL, "AIF Enable"},
  1301. {"Digital R2 Playback Mixer", NULL, "AIF Enable"},
  1302. {"Digital L2 Playback Mixer", NULL, "AIF Enable"},
  1303. {"Analog L1 Playback Mixer", NULL, "Digital L1 Playback Mixer"},
  1304. {"Analog R1 Playback Mixer", NULL, "Digital R1 Playback Mixer"},
  1305. {"Analog L2 Playback Mixer", NULL, "Digital L2 Playback Mixer"},
  1306. {"Analog R2 Playback Mixer", NULL, "Digital R2 Playback Mixer"},
  1307. {"Analog Voice Playback Mixer", NULL, "Digital Voice Playback Mixer"},
  1308. /* Internal playback routings */
  1309. /* Earpiece */
  1310. {"Earpiece Mixer", "Voice", "Analog Voice Playback Mixer"},
  1311. {"Earpiece Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1312. {"Earpiece Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1313. {"Earpiece Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1314. {"Earpiece PGA", NULL, "Earpiece Mixer"},
  1315. /* PreDrivL */
  1316. {"PredriveL Mixer", "Voice", "Analog Voice Playback Mixer"},
  1317. {"PredriveL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1318. {"PredriveL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1319. {"PredriveL Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1320. {"PredriveL PGA", NULL, "PredriveL Mixer"},
  1321. /* PreDrivR */
  1322. {"PredriveR Mixer", "Voice", "Analog Voice Playback Mixer"},
  1323. {"PredriveR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1324. {"PredriveR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1325. {"PredriveR Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1326. {"PredriveR PGA", NULL, "PredriveR Mixer"},
  1327. /* HeadsetL */
  1328. {"HeadsetL Mixer", "Voice", "Analog Voice Playback Mixer"},
  1329. {"HeadsetL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1330. {"HeadsetL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1331. {"HeadsetL PGA", NULL, "HeadsetL Mixer"},
  1332. /* HeadsetR */
  1333. {"HeadsetR Mixer", "Voice", "Analog Voice Playback Mixer"},
  1334. {"HeadsetR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1335. {"HeadsetR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1336. {"HeadsetR PGA", NULL, "HeadsetR Mixer"},
  1337. /* CarkitL */
  1338. {"CarkitL Mixer", "Voice", "Analog Voice Playback Mixer"},
  1339. {"CarkitL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1340. {"CarkitL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1341. {"CarkitL PGA", NULL, "CarkitL Mixer"},
  1342. /* CarkitR */
  1343. {"CarkitR Mixer", "Voice", "Analog Voice Playback Mixer"},
  1344. {"CarkitR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1345. {"CarkitR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1346. {"CarkitR PGA", NULL, "CarkitR Mixer"},
  1347. /* HandsfreeL */
  1348. {"HandsfreeL Mux", "Voice", "Analog Voice Playback Mixer"},
  1349. {"HandsfreeL Mux", "AudioL1", "Analog L1 Playback Mixer"},
  1350. {"HandsfreeL Mux", "AudioL2", "Analog L2 Playback Mixer"},
  1351. {"HandsfreeL Mux", "AudioR2", "Analog R2 Playback Mixer"},
  1352. {"HandsfreeL", "Switch", "HandsfreeL Mux"},
  1353. {"HandsfreeL PGA", NULL, "HandsfreeL"},
  1354. /* HandsfreeR */
  1355. {"HandsfreeR Mux", "Voice", "Analog Voice Playback Mixer"},
  1356. {"HandsfreeR Mux", "AudioR1", "Analog R1 Playback Mixer"},
  1357. {"HandsfreeR Mux", "AudioR2", "Analog R2 Playback Mixer"},
  1358. {"HandsfreeR Mux", "AudioL2", "Analog L2 Playback Mixer"},
  1359. {"HandsfreeR", "Switch", "HandsfreeR Mux"},
  1360. {"HandsfreeR PGA", NULL, "HandsfreeR"},
  1361. /* Vibra */
  1362. {"Vibra Mux", "AudioL1", "DAC Left1"},
  1363. {"Vibra Mux", "AudioR1", "DAC Right1"},
  1364. {"Vibra Mux", "AudioL2", "DAC Left2"},
  1365. {"Vibra Mux", "AudioR2", "DAC Right2"},
  1366. /* outputs */
  1367. /* Must be always connected (for AIF and APLL) */
  1368. {"Virtual HiFi OUT", NULL, "DAC Left1"},
  1369. {"Virtual HiFi OUT", NULL, "DAC Right1"},
  1370. {"Virtual HiFi OUT", NULL, "DAC Left2"},
  1371. {"Virtual HiFi OUT", NULL, "DAC Right2"},
  1372. /* Must be always connected (for APLL) */
  1373. {"Virtual Voice OUT", NULL, "Digital Voice Playback Mixer"},
  1374. /* Physical outputs */
  1375. {"EARPIECE", NULL, "Earpiece PGA"},
  1376. {"PREDRIVEL", NULL, "PredriveL PGA"},
  1377. {"PREDRIVER", NULL, "PredriveR PGA"},
  1378. {"HSOL", NULL, "HeadsetL PGA"},
  1379. {"HSOR", NULL, "HeadsetR PGA"},
  1380. {"CARKITL", NULL, "CarkitL PGA"},
  1381. {"CARKITR", NULL, "CarkitR PGA"},
  1382. {"HFL", NULL, "HandsfreeL PGA"},
  1383. {"HFR", NULL, "HandsfreeR PGA"},
  1384. {"Vibra Route", "Audio", "Vibra Mux"},
  1385. {"VIBRA", NULL, "Vibra Route"},
  1386. /* Capture path */
  1387. /* Must be always connected (for AIF and APLL) */
  1388. {"ADC Virtual Left1", NULL, "Virtual HiFi IN"},
  1389. {"ADC Virtual Right1", NULL, "Virtual HiFi IN"},
  1390. {"ADC Virtual Left2", NULL, "Virtual HiFi IN"},
  1391. {"ADC Virtual Right2", NULL, "Virtual HiFi IN"},
  1392. /* Physical inputs */
  1393. {"Analog Left", "Main Mic Capture Switch", "MAINMIC"},
  1394. {"Analog Left", "Headset Mic Capture Switch", "HSMIC"},
  1395. {"Analog Left", "AUXL Capture Switch", "AUXL"},
  1396. {"Analog Left", "Carkit Mic Capture Switch", "CARKITMIC"},
  1397. {"Analog Right", "Sub Mic Capture Switch", "SUBMIC"},
  1398. {"Analog Right", "AUXR Capture Switch", "AUXR"},
  1399. {"ADC Physical Left", NULL, "Analog Left"},
  1400. {"ADC Physical Right", NULL, "Analog Right"},
  1401. {"Digimic0 Enable", NULL, "DIGIMIC0"},
  1402. {"Digimic1 Enable", NULL, "DIGIMIC1"},
  1403. {"DIGIMIC0", NULL, "micbias1 select"},
  1404. {"DIGIMIC1", NULL, "micbias2 select"},
  1405. /* TX1 Left capture path */
  1406. {"TX1 Capture Route", "Analog", "ADC Physical Left"},
  1407. {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
  1408. /* TX1 Right capture path */
  1409. {"TX1 Capture Route", "Analog", "ADC Physical Right"},
  1410. {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
  1411. /* TX2 Left capture path */
  1412. {"TX2 Capture Route", "Analog", "ADC Physical Left"},
  1413. {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
  1414. /* TX2 Right capture path */
  1415. {"TX2 Capture Route", "Analog", "ADC Physical Right"},
  1416. {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
  1417. {"ADC Virtual Left1", NULL, "TX1 Capture Route"},
  1418. {"ADC Virtual Right1", NULL, "TX1 Capture Route"},
  1419. {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
  1420. {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
  1421. {"ADC Virtual Left1", NULL, "AIF Enable"},
  1422. {"ADC Virtual Right1", NULL, "AIF Enable"},
  1423. {"ADC Virtual Left2", NULL, "AIF Enable"},
  1424. {"ADC Virtual Right2", NULL, "AIF Enable"},
  1425. /* Analog bypass routes */
  1426. {"Right1 Analog Loopback", "Switch", "Analog Right"},
  1427. {"Left1 Analog Loopback", "Switch", "Analog Left"},
  1428. {"Right2 Analog Loopback", "Switch", "Analog Right"},
  1429. {"Left2 Analog Loopback", "Switch", "Analog Left"},
  1430. {"Voice Analog Loopback", "Switch", "Analog Left"},
  1431. /* Supply for the Analog loopbacks */
  1432. {"Right1 Analog Loopback", NULL, "FM Loop Enable"},
  1433. {"Left1 Analog Loopback", NULL, "FM Loop Enable"},
  1434. {"Right2 Analog Loopback", NULL, "FM Loop Enable"},
  1435. {"Left2 Analog Loopback", NULL, "FM Loop Enable"},
  1436. {"Voice Analog Loopback", NULL, "FM Loop Enable"},
  1437. {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"},
  1438. {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"},
  1439. {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"},
  1440. {"Analog L2 Playback Mixer", NULL, "Left2 Analog Loopback"},
  1441. {"Analog Voice Playback Mixer", NULL, "Voice Analog Loopback"},
  1442. /* Digital bypass routes */
  1443. {"Right Digital Loopback", "Volume", "TX1 Capture Route"},
  1444. {"Left Digital Loopback", "Volume", "TX1 Capture Route"},
  1445. {"Voice Digital Loopback", "Volume", "TX2 Capture Route"},
  1446. {"Digital R2 Playback Mixer", NULL, "Right Digital Loopback"},
  1447. {"Digital L2 Playback Mixer", NULL, "Left Digital Loopback"},
  1448. {"Digital Voice Playback Mixer", NULL, "Voice Digital Loopback"},
  1449. };
  1450. static int twl4030_set_bias_level(struct snd_soc_codec *codec,
  1451. enum snd_soc_bias_level level)
  1452. {
  1453. switch (level) {
  1454. case SND_SOC_BIAS_ON:
  1455. break;
  1456. case SND_SOC_BIAS_PREPARE:
  1457. break;
  1458. case SND_SOC_BIAS_STANDBY:
  1459. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
  1460. twl4030_codec_enable(codec, 1);
  1461. break;
  1462. case SND_SOC_BIAS_OFF:
  1463. twl4030_codec_enable(codec, 0);
  1464. break;
  1465. }
  1466. codec->dapm.bias_level = level;
  1467. return 0;
  1468. }
  1469. static void twl4030_constraints(struct twl4030_priv *twl4030,
  1470. struct snd_pcm_substream *mst_substream)
  1471. {
  1472. struct snd_pcm_substream *slv_substream;
  1473. /* Pick the stream, which need to be constrained */
  1474. if (mst_substream == twl4030->master_substream)
  1475. slv_substream = twl4030->slave_substream;
  1476. else if (mst_substream == twl4030->slave_substream)
  1477. slv_substream = twl4030->master_substream;
  1478. else /* This should not happen.. */
  1479. return;
  1480. /* Set the constraints according to the already configured stream */
  1481. snd_pcm_hw_constraint_minmax(slv_substream->runtime,
  1482. SNDRV_PCM_HW_PARAM_RATE,
  1483. twl4030->rate,
  1484. twl4030->rate);
  1485. snd_pcm_hw_constraint_minmax(slv_substream->runtime,
  1486. SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
  1487. twl4030->sample_bits,
  1488. twl4030->sample_bits);
  1489. snd_pcm_hw_constraint_minmax(slv_substream->runtime,
  1490. SNDRV_PCM_HW_PARAM_CHANNELS,
  1491. twl4030->channels,
  1492. twl4030->channels);
  1493. }
  1494. /* In case of 4 channel mode, the RX1 L/R for playback and the TX2 L/R for
  1495. * capture has to be enabled/disabled. */
  1496. static void twl4030_tdm_enable(struct snd_soc_codec *codec, int direction,
  1497. int enable)
  1498. {
  1499. u8 reg, mask;
  1500. reg = twl4030_read_reg_cache(codec, TWL4030_REG_OPTION);
  1501. if (direction == SNDRV_PCM_STREAM_PLAYBACK)
  1502. mask = TWL4030_ARXL1_VRX_EN | TWL4030_ARXR1_EN;
  1503. else
  1504. mask = TWL4030_ATXL2_VTXL_EN | TWL4030_ATXR2_VTXR_EN;
  1505. if (enable)
  1506. reg |= mask;
  1507. else
  1508. reg &= ~mask;
  1509. twl4030_write(codec, TWL4030_REG_OPTION, reg);
  1510. }
  1511. static int twl4030_startup(struct snd_pcm_substream *substream,
  1512. struct snd_soc_dai *dai)
  1513. {
  1514. struct snd_soc_codec *codec = dai->codec;
  1515. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1516. if (twl4030->master_substream) {
  1517. twl4030->slave_substream = substream;
  1518. /* The DAI has one configuration for playback and capture, so
  1519. * if the DAI has been already configured then constrain this
  1520. * substream to match it. */
  1521. if (twl4030->configured)
  1522. twl4030_constraints(twl4030, twl4030->master_substream);
  1523. } else {
  1524. if (!(twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE) &
  1525. TWL4030_OPTION_1)) {
  1526. /* In option2 4 channel is not supported, set the
  1527. * constraint for the first stream for channels, the
  1528. * second stream will 'inherit' this cosntraint */
  1529. snd_pcm_hw_constraint_minmax(substream->runtime,
  1530. SNDRV_PCM_HW_PARAM_CHANNELS,
  1531. 2, 2);
  1532. }
  1533. twl4030->master_substream = substream;
  1534. }
  1535. return 0;
  1536. }
  1537. static void twl4030_shutdown(struct snd_pcm_substream *substream,
  1538. struct snd_soc_dai *dai)
  1539. {
  1540. struct snd_soc_codec *codec = dai->codec;
  1541. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1542. if (twl4030->master_substream == substream)
  1543. twl4030->master_substream = twl4030->slave_substream;
  1544. twl4030->slave_substream = NULL;
  1545. /* If all streams are closed, or the remaining stream has not yet
  1546. * been configured than set the DAI as not configured. */
  1547. if (!twl4030->master_substream)
  1548. twl4030->configured = 0;
  1549. else if (!twl4030->master_substream->runtime->channels)
  1550. twl4030->configured = 0;
  1551. /* If the closing substream had 4 channel, do the necessary cleanup */
  1552. if (substream->runtime->channels == 4)
  1553. twl4030_tdm_enable(codec, substream->stream, 0);
  1554. }
  1555. static int twl4030_hw_params(struct snd_pcm_substream *substream,
  1556. struct snd_pcm_hw_params *params,
  1557. struct snd_soc_dai *dai)
  1558. {
  1559. struct snd_soc_codec *codec = dai->codec;
  1560. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1561. u8 mode, old_mode, format, old_format;
  1562. /* If the substream has 4 channel, do the necessary setup */
  1563. if (params_channels(params) == 4) {
  1564. format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1565. mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE);
  1566. /* Safety check: are we in the correct operating mode and
  1567. * the interface is in TDM mode? */
  1568. if ((mode & TWL4030_OPTION_1) &&
  1569. ((format & TWL4030_AIF_FORMAT) == TWL4030_AIF_FORMAT_TDM))
  1570. twl4030_tdm_enable(codec, substream->stream, 1);
  1571. else
  1572. return -EINVAL;
  1573. }
  1574. if (twl4030->configured)
  1575. /* Ignoring hw_params for already configured DAI */
  1576. return 0;
  1577. /* bit rate */
  1578. old_mode = twl4030_read_reg_cache(codec,
  1579. TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ;
  1580. mode = old_mode & ~TWL4030_APLL_RATE;
  1581. switch (params_rate(params)) {
  1582. case 8000:
  1583. mode |= TWL4030_APLL_RATE_8000;
  1584. break;
  1585. case 11025:
  1586. mode |= TWL4030_APLL_RATE_11025;
  1587. break;
  1588. case 12000:
  1589. mode |= TWL4030_APLL_RATE_12000;
  1590. break;
  1591. case 16000:
  1592. mode |= TWL4030_APLL_RATE_16000;
  1593. break;
  1594. case 22050:
  1595. mode |= TWL4030_APLL_RATE_22050;
  1596. break;
  1597. case 24000:
  1598. mode |= TWL4030_APLL_RATE_24000;
  1599. break;
  1600. case 32000:
  1601. mode |= TWL4030_APLL_RATE_32000;
  1602. break;
  1603. case 44100:
  1604. mode |= TWL4030_APLL_RATE_44100;
  1605. break;
  1606. case 48000:
  1607. mode |= TWL4030_APLL_RATE_48000;
  1608. break;
  1609. case 96000:
  1610. mode |= TWL4030_APLL_RATE_96000;
  1611. break;
  1612. default:
  1613. dev_err(codec->dev, "%s: unknown rate %d\n", __func__,
  1614. params_rate(params));
  1615. return -EINVAL;
  1616. }
  1617. /* sample size */
  1618. old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1619. format = old_format;
  1620. format &= ~TWL4030_DATA_WIDTH;
  1621. switch (params_format(params)) {
  1622. case SNDRV_PCM_FORMAT_S16_LE:
  1623. format |= TWL4030_DATA_WIDTH_16S_16W;
  1624. break;
  1625. case SNDRV_PCM_FORMAT_S32_LE:
  1626. format |= TWL4030_DATA_WIDTH_32S_24W;
  1627. break;
  1628. default:
  1629. dev_err(codec->dev, "%s: unknown format %d\n", __func__,
  1630. params_format(params));
  1631. return -EINVAL;
  1632. }
  1633. if (format != old_format || mode != old_mode) {
  1634. if (twl4030->codec_powered) {
  1635. /*
  1636. * If the codec is powered, than we need to toggle the
  1637. * codec power.
  1638. */
  1639. twl4030_codec_enable(codec, 0);
  1640. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1641. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1642. twl4030_codec_enable(codec, 1);
  1643. } else {
  1644. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1645. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1646. }
  1647. }
  1648. /* Store the important parameters for the DAI configuration and set
  1649. * the DAI as configured */
  1650. twl4030->configured = 1;
  1651. twl4030->rate = params_rate(params);
  1652. twl4030->sample_bits = hw_param_interval(params,
  1653. SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min;
  1654. twl4030->channels = params_channels(params);
  1655. /* If both playback and capture streams are open, and one of them
  1656. * is setting the hw parameters right now (since we are here), set
  1657. * constraints to the other stream to match the current one. */
  1658. if (twl4030->slave_substream)
  1659. twl4030_constraints(twl4030, substream);
  1660. return 0;
  1661. }
  1662. static int twl4030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1663. int clk_id, unsigned int freq, int dir)
  1664. {
  1665. struct snd_soc_codec *codec = codec_dai->codec;
  1666. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1667. switch (freq) {
  1668. case 19200000:
  1669. case 26000000:
  1670. case 38400000:
  1671. break;
  1672. default:
  1673. dev_err(codec->dev, "Unsupported HFCLKIN: %u\n", freq);
  1674. return -EINVAL;
  1675. }
  1676. if ((freq / 1000) != twl4030->sysclk) {
  1677. dev_err(codec->dev,
  1678. "Mismatch in HFCLKIN: %u (configured: %u)\n",
  1679. freq, twl4030->sysclk * 1000);
  1680. return -EINVAL;
  1681. }
  1682. return 0;
  1683. }
  1684. static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1685. unsigned int fmt)
  1686. {
  1687. struct snd_soc_codec *codec = codec_dai->codec;
  1688. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1689. u8 old_format, format;
  1690. /* get format */
  1691. old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1692. format = old_format;
  1693. /* set master/slave audio interface */
  1694. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1695. case SND_SOC_DAIFMT_CBM_CFM:
  1696. format &= ~(TWL4030_AIF_SLAVE_EN);
  1697. format &= ~(TWL4030_CLK256FS_EN);
  1698. break;
  1699. case SND_SOC_DAIFMT_CBS_CFS:
  1700. format |= TWL4030_AIF_SLAVE_EN;
  1701. format |= TWL4030_CLK256FS_EN;
  1702. break;
  1703. default:
  1704. return -EINVAL;
  1705. }
  1706. /* interface format */
  1707. format &= ~TWL4030_AIF_FORMAT;
  1708. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1709. case SND_SOC_DAIFMT_I2S:
  1710. format |= TWL4030_AIF_FORMAT_CODEC;
  1711. break;
  1712. case SND_SOC_DAIFMT_DSP_A:
  1713. format |= TWL4030_AIF_FORMAT_TDM;
  1714. break;
  1715. default:
  1716. return -EINVAL;
  1717. }
  1718. if (format != old_format) {
  1719. if (twl4030->codec_powered) {
  1720. /*
  1721. * If the codec is powered, than we need to toggle the
  1722. * codec power.
  1723. */
  1724. twl4030_codec_enable(codec, 0);
  1725. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1726. twl4030_codec_enable(codec, 1);
  1727. } else {
  1728. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1729. }
  1730. }
  1731. return 0;
  1732. }
  1733. static int twl4030_set_tristate(struct snd_soc_dai *dai, int tristate)
  1734. {
  1735. struct snd_soc_codec *codec = dai->codec;
  1736. u8 reg = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1737. if (tristate)
  1738. reg |= TWL4030_AIF_TRI_EN;
  1739. else
  1740. reg &= ~TWL4030_AIF_TRI_EN;
  1741. return twl4030_write(codec, TWL4030_REG_AUDIO_IF, reg);
  1742. }
  1743. /* In case of voice mode, the RX1 L(VRX) for downlink and the TX2 L/R
  1744. * (VTXL, VTXR) for uplink has to be enabled/disabled. */
  1745. static void twl4030_voice_enable(struct snd_soc_codec *codec, int direction,
  1746. int enable)
  1747. {
  1748. u8 reg, mask;
  1749. reg = twl4030_read_reg_cache(codec, TWL4030_REG_OPTION);
  1750. if (direction == SNDRV_PCM_STREAM_PLAYBACK)
  1751. mask = TWL4030_ARXL1_VRX_EN;
  1752. else
  1753. mask = TWL4030_ATXL2_VTXL_EN | TWL4030_ATXR2_VTXR_EN;
  1754. if (enable)
  1755. reg |= mask;
  1756. else
  1757. reg &= ~mask;
  1758. twl4030_write(codec, TWL4030_REG_OPTION, reg);
  1759. }
  1760. static int twl4030_voice_startup(struct snd_pcm_substream *substream,
  1761. struct snd_soc_dai *dai)
  1762. {
  1763. struct snd_soc_codec *codec = dai->codec;
  1764. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1765. u8 mode;
  1766. /* If the system master clock is not 26MHz, the voice PCM interface is
  1767. * not available.
  1768. */
  1769. if (twl4030->sysclk != 26000) {
  1770. dev_err(codec->dev,
  1771. "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
  1772. __func__, twl4030->sysclk);
  1773. return -EINVAL;
  1774. }
  1775. /* If the codec mode is not option2, the voice PCM interface is not
  1776. * available.
  1777. */
  1778. mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE)
  1779. & TWL4030_OPT_MODE;
  1780. if (mode != TWL4030_OPTION_2) {
  1781. dev_err(codec->dev, "%s: the codec mode is not option2\n",
  1782. __func__);
  1783. return -EINVAL;
  1784. }
  1785. return 0;
  1786. }
  1787. static void twl4030_voice_shutdown(struct snd_pcm_substream *substream,
  1788. struct snd_soc_dai *dai)
  1789. {
  1790. struct snd_soc_codec *codec = dai->codec;
  1791. /* Enable voice digital filters */
  1792. twl4030_voice_enable(codec, substream->stream, 0);
  1793. }
  1794. static int twl4030_voice_hw_params(struct snd_pcm_substream *substream,
  1795. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  1796. {
  1797. struct snd_soc_codec *codec = dai->codec;
  1798. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1799. u8 old_mode, mode;
  1800. /* Enable voice digital filters */
  1801. twl4030_voice_enable(codec, substream->stream, 1);
  1802. /* bit rate */
  1803. old_mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE)
  1804. & ~(TWL4030_CODECPDZ);
  1805. mode = old_mode;
  1806. switch (params_rate(params)) {
  1807. case 8000:
  1808. mode &= ~(TWL4030_SEL_16K);
  1809. break;
  1810. case 16000:
  1811. mode |= TWL4030_SEL_16K;
  1812. break;
  1813. default:
  1814. dev_err(codec->dev, "%s: unknown rate %d\n", __func__,
  1815. params_rate(params));
  1816. return -EINVAL;
  1817. }
  1818. if (mode != old_mode) {
  1819. if (twl4030->codec_powered) {
  1820. /*
  1821. * If the codec is powered, than we need to toggle the
  1822. * codec power.
  1823. */
  1824. twl4030_codec_enable(codec, 0);
  1825. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1826. twl4030_codec_enable(codec, 1);
  1827. } else {
  1828. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1829. }
  1830. }
  1831. return 0;
  1832. }
  1833. static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1834. int clk_id, unsigned int freq, int dir)
  1835. {
  1836. struct snd_soc_codec *codec = codec_dai->codec;
  1837. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1838. if (freq != 26000000) {
  1839. dev_err(codec->dev,
  1840. "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
  1841. __func__, freq / 1000);
  1842. return -EINVAL;
  1843. }
  1844. if ((freq / 1000) != twl4030->sysclk) {
  1845. dev_err(codec->dev,
  1846. "Mismatch in HFCLKIN: %u (configured: %u)\n",
  1847. freq, twl4030->sysclk * 1000);
  1848. return -EINVAL;
  1849. }
  1850. return 0;
  1851. }
  1852. static int twl4030_voice_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1853. unsigned int fmt)
  1854. {
  1855. struct snd_soc_codec *codec = codec_dai->codec;
  1856. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1857. u8 old_format, format;
  1858. /* get format */
  1859. old_format = twl4030_read_reg_cache(codec, TWL4030_REG_VOICE_IF);
  1860. format = old_format;
  1861. /* set master/slave audio interface */
  1862. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1863. case SND_SOC_DAIFMT_CBM_CFM:
  1864. format &= ~(TWL4030_VIF_SLAVE_EN);
  1865. break;
  1866. case SND_SOC_DAIFMT_CBS_CFS:
  1867. format |= TWL4030_VIF_SLAVE_EN;
  1868. break;
  1869. default:
  1870. return -EINVAL;
  1871. }
  1872. /* clock inversion */
  1873. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1874. case SND_SOC_DAIFMT_IB_NF:
  1875. format &= ~(TWL4030_VIF_FORMAT);
  1876. break;
  1877. case SND_SOC_DAIFMT_NB_IF:
  1878. format |= TWL4030_VIF_FORMAT;
  1879. break;
  1880. default:
  1881. return -EINVAL;
  1882. }
  1883. if (format != old_format) {
  1884. if (twl4030->codec_powered) {
  1885. /*
  1886. * If the codec is powered, than we need to toggle the
  1887. * codec power.
  1888. */
  1889. twl4030_codec_enable(codec, 0);
  1890. twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
  1891. twl4030_codec_enable(codec, 1);
  1892. } else {
  1893. twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
  1894. }
  1895. }
  1896. return 0;
  1897. }
  1898. static int twl4030_voice_set_tristate(struct snd_soc_dai *dai, int tristate)
  1899. {
  1900. struct snd_soc_codec *codec = dai->codec;
  1901. u8 reg = twl4030_read_reg_cache(codec, TWL4030_REG_VOICE_IF);
  1902. if (tristate)
  1903. reg |= TWL4030_VIF_TRI_EN;
  1904. else
  1905. reg &= ~TWL4030_VIF_TRI_EN;
  1906. return twl4030_write(codec, TWL4030_REG_VOICE_IF, reg);
  1907. }
  1908. #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000)
  1909. #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1910. static const struct snd_soc_dai_ops twl4030_dai_hifi_ops = {
  1911. .startup = twl4030_startup,
  1912. .shutdown = twl4030_shutdown,
  1913. .hw_params = twl4030_hw_params,
  1914. .set_sysclk = twl4030_set_dai_sysclk,
  1915. .set_fmt = twl4030_set_dai_fmt,
  1916. .set_tristate = twl4030_set_tristate,
  1917. };
  1918. static const struct snd_soc_dai_ops twl4030_dai_voice_ops = {
  1919. .startup = twl4030_voice_startup,
  1920. .shutdown = twl4030_voice_shutdown,
  1921. .hw_params = twl4030_voice_hw_params,
  1922. .set_sysclk = twl4030_voice_set_dai_sysclk,
  1923. .set_fmt = twl4030_voice_set_dai_fmt,
  1924. .set_tristate = twl4030_voice_set_tristate,
  1925. };
  1926. static struct snd_soc_dai_driver twl4030_dai[] = {
  1927. {
  1928. .name = "twl4030-hifi",
  1929. .playback = {
  1930. .stream_name = "HiFi Playback",
  1931. .channels_min = 2,
  1932. .channels_max = 4,
  1933. .rates = TWL4030_RATES | SNDRV_PCM_RATE_96000,
  1934. .formats = TWL4030_FORMATS,
  1935. .sig_bits = 24,},
  1936. .capture = {
  1937. .stream_name = "HiFi Capture",
  1938. .channels_min = 2,
  1939. .channels_max = 4,
  1940. .rates = TWL4030_RATES,
  1941. .formats = TWL4030_FORMATS,
  1942. .sig_bits = 24,},
  1943. .ops = &twl4030_dai_hifi_ops,
  1944. },
  1945. {
  1946. .name = "twl4030-voice",
  1947. .playback = {
  1948. .stream_name = "Voice Playback",
  1949. .channels_min = 1,
  1950. .channels_max = 1,
  1951. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1952. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  1953. .capture = {
  1954. .stream_name = "Voice Capture",
  1955. .channels_min = 1,
  1956. .channels_max = 2,
  1957. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1958. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  1959. .ops = &twl4030_dai_voice_ops,
  1960. },
  1961. };
  1962. static int twl4030_soc_suspend(struct snd_soc_codec *codec)
  1963. {
  1964. twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1965. return 0;
  1966. }
  1967. static int twl4030_soc_resume(struct snd_soc_codec *codec)
  1968. {
  1969. twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1970. return 0;
  1971. }
  1972. static int twl4030_soc_probe(struct snd_soc_codec *codec)
  1973. {
  1974. struct twl4030_priv *twl4030;
  1975. twl4030 = devm_kzalloc(codec->dev, sizeof(struct twl4030_priv),
  1976. GFP_KERNEL);
  1977. if (twl4030 == NULL) {
  1978. dev_err(codec->dev, "Can not allocate memory\n");
  1979. return -ENOMEM;
  1980. }
  1981. snd_soc_codec_set_drvdata(codec, twl4030);
  1982. /* Set the defaults, and power up the codec */
  1983. twl4030->sysclk = twl4030_audio_get_mclk() / 1000;
  1984. twl4030_init_chip(codec);
  1985. return 0;
  1986. }
  1987. static int twl4030_soc_remove(struct snd_soc_codec *codec)
  1988. {
  1989. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1990. struct twl4030_codec_data *pdata = twl4030->pdata;
  1991. /* Reset registers to their chip default before leaving */
  1992. twl4030_reset_registers(codec);
  1993. twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1994. if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio))
  1995. gpio_free(pdata->hs_extmute_gpio);
  1996. return 0;
  1997. }
  1998. static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
  1999. .probe = twl4030_soc_probe,
  2000. .remove = twl4030_soc_remove,
  2001. .suspend = twl4030_soc_suspend,
  2002. .resume = twl4030_soc_resume,
  2003. .read = twl4030_read_reg_cache,
  2004. .write = twl4030_write,
  2005. .set_bias_level = twl4030_set_bias_level,
  2006. .idle_bias_off = true,
  2007. .reg_cache_size = sizeof(twl4030_reg),
  2008. .reg_word_size = sizeof(u8),
  2009. .reg_cache_default = twl4030_reg,
  2010. .controls = twl4030_snd_controls,
  2011. .num_controls = ARRAY_SIZE(twl4030_snd_controls),
  2012. .dapm_widgets = twl4030_dapm_widgets,
  2013. .num_dapm_widgets = ARRAY_SIZE(twl4030_dapm_widgets),
  2014. .dapm_routes = intercon,
  2015. .num_dapm_routes = ARRAY_SIZE(intercon),
  2016. };
  2017. static int twl4030_codec_probe(struct platform_device *pdev)
  2018. {
  2019. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030,
  2020. twl4030_dai, ARRAY_SIZE(twl4030_dai));
  2021. }
  2022. static int twl4030_codec_remove(struct platform_device *pdev)
  2023. {
  2024. snd_soc_unregister_codec(&pdev->dev);
  2025. return 0;
  2026. }
  2027. MODULE_ALIAS("platform:twl4030-codec");
  2028. static struct platform_driver twl4030_codec_driver = {
  2029. .probe = twl4030_codec_probe,
  2030. .remove = twl4030_codec_remove,
  2031. .driver = {
  2032. .name = "twl4030-codec",
  2033. .owner = THIS_MODULE,
  2034. },
  2035. };
  2036. module_platform_driver(twl4030_codec_driver);
  2037. MODULE_DESCRIPTION("ASoC TWL4030 codec driver");
  2038. MODULE_AUTHOR("Steve Sakoman");
  2039. MODULE_LICENSE("GPL");