twl4030.c 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375
  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. SND_SOC_DAPM_AIF_IN("VAIFIN", "Voice Playback", 0,
  1119. TWL4030_REG_VOICE_IF, 6, 0),
  1120. /* Analog bypasses */
  1121. SND_SOC_DAPM_SWITCH("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1122. &twl4030_dapm_abypassr1_control),
  1123. SND_SOC_DAPM_SWITCH("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1124. &twl4030_dapm_abypassl1_control),
  1125. SND_SOC_DAPM_SWITCH("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1126. &twl4030_dapm_abypassr2_control),
  1127. SND_SOC_DAPM_SWITCH("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0,
  1128. &twl4030_dapm_abypassl2_control),
  1129. SND_SOC_DAPM_SWITCH("Voice Analog Loopback", SND_SOC_NOPM, 0, 0,
  1130. &twl4030_dapm_abypassv_control),
  1131. /* Master analog loopback switch */
  1132. SND_SOC_DAPM_SUPPLY("FM Loop Enable", TWL4030_REG_MISC_SET_1, 5, 0,
  1133. NULL, 0),
  1134. /* Digital bypasses */
  1135. SND_SOC_DAPM_SWITCH("Left Digital Loopback", SND_SOC_NOPM, 0, 0,
  1136. &twl4030_dapm_dbypassl_control),
  1137. SND_SOC_DAPM_SWITCH("Right Digital Loopback", SND_SOC_NOPM, 0, 0,
  1138. &twl4030_dapm_dbypassr_control),
  1139. SND_SOC_DAPM_SWITCH("Voice Digital Loopback", SND_SOC_NOPM, 0, 0,
  1140. &twl4030_dapm_dbypassv_control),
  1141. /* Digital mixers, power control for the physical DACs */
  1142. SND_SOC_DAPM_MIXER("Digital R1 Playback Mixer",
  1143. TWL4030_REG_AVDAC_CTL, 0, 0, NULL, 0),
  1144. SND_SOC_DAPM_MIXER("Digital L1 Playback Mixer",
  1145. TWL4030_REG_AVDAC_CTL, 1, 0, NULL, 0),
  1146. SND_SOC_DAPM_MIXER("Digital R2 Playback Mixer",
  1147. TWL4030_REG_AVDAC_CTL, 2, 0, NULL, 0),
  1148. SND_SOC_DAPM_MIXER("Digital L2 Playback Mixer",
  1149. TWL4030_REG_AVDAC_CTL, 3, 0, NULL, 0),
  1150. SND_SOC_DAPM_MIXER("Digital Voice Playback Mixer",
  1151. TWL4030_REG_AVDAC_CTL, 4, 0, NULL, 0),
  1152. /* Analog mixers, power control for the physical PGAs */
  1153. SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer",
  1154. TWL4030_REG_ARXR1_APGA_CTL, 0, 0, NULL, 0),
  1155. SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer",
  1156. TWL4030_REG_ARXL1_APGA_CTL, 0, 0, NULL, 0),
  1157. SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer",
  1158. TWL4030_REG_ARXR2_APGA_CTL, 0, 0, NULL, 0),
  1159. SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer",
  1160. TWL4030_REG_ARXL2_APGA_CTL, 0, 0, NULL, 0),
  1161. SND_SOC_DAPM_MIXER("Analog Voice Playback Mixer",
  1162. TWL4030_REG_VDL_APGA_CTL, 0, 0, NULL, 0),
  1163. SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM, 0, 0, apll_event,
  1164. SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
  1165. SND_SOC_DAPM_SUPPLY("AIF Enable", SND_SOC_NOPM, 0, 0, aif_event,
  1166. SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
  1167. /* Output MIXER controls */
  1168. /* Earpiece */
  1169. SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0,
  1170. &twl4030_dapm_earpiece_controls[0],
  1171. ARRAY_SIZE(twl4030_dapm_earpiece_controls)),
  1172. SND_SOC_DAPM_PGA_E("Earpiece PGA", SND_SOC_NOPM,
  1173. 0, 0, NULL, 0, earpiecepga_event,
  1174. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1175. /* PreDrivL/R */
  1176. SND_SOC_DAPM_MIXER("PredriveL Mixer", SND_SOC_NOPM, 0, 0,
  1177. &twl4030_dapm_predrivel_controls[0],
  1178. ARRAY_SIZE(twl4030_dapm_predrivel_controls)),
  1179. SND_SOC_DAPM_PGA_E("PredriveL PGA", SND_SOC_NOPM,
  1180. 0, 0, NULL, 0, predrivelpga_event,
  1181. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1182. SND_SOC_DAPM_MIXER("PredriveR Mixer", SND_SOC_NOPM, 0, 0,
  1183. &twl4030_dapm_predriver_controls[0],
  1184. ARRAY_SIZE(twl4030_dapm_predriver_controls)),
  1185. SND_SOC_DAPM_PGA_E("PredriveR PGA", SND_SOC_NOPM,
  1186. 0, 0, NULL, 0, predriverpga_event,
  1187. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1188. /* HeadsetL/R */
  1189. SND_SOC_DAPM_MIXER("HeadsetL Mixer", SND_SOC_NOPM, 0, 0,
  1190. &twl4030_dapm_hsol_controls[0],
  1191. ARRAY_SIZE(twl4030_dapm_hsol_controls)),
  1192. SND_SOC_DAPM_PGA_E("HeadsetL PGA", SND_SOC_NOPM,
  1193. 0, 0, NULL, 0, headsetlpga_event,
  1194. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1195. SND_SOC_DAPM_MIXER("HeadsetR Mixer", SND_SOC_NOPM, 0, 0,
  1196. &twl4030_dapm_hsor_controls[0],
  1197. ARRAY_SIZE(twl4030_dapm_hsor_controls)),
  1198. SND_SOC_DAPM_PGA_E("HeadsetR PGA", SND_SOC_NOPM,
  1199. 0, 0, NULL, 0, headsetrpga_event,
  1200. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1201. /* CarkitL/R */
  1202. SND_SOC_DAPM_MIXER("CarkitL Mixer", SND_SOC_NOPM, 0, 0,
  1203. &twl4030_dapm_carkitl_controls[0],
  1204. ARRAY_SIZE(twl4030_dapm_carkitl_controls)),
  1205. SND_SOC_DAPM_PGA_E("CarkitL PGA", SND_SOC_NOPM,
  1206. 0, 0, NULL, 0, carkitlpga_event,
  1207. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1208. SND_SOC_DAPM_MIXER("CarkitR Mixer", SND_SOC_NOPM, 0, 0,
  1209. &twl4030_dapm_carkitr_controls[0],
  1210. ARRAY_SIZE(twl4030_dapm_carkitr_controls)),
  1211. SND_SOC_DAPM_PGA_E("CarkitR PGA", SND_SOC_NOPM,
  1212. 0, 0, NULL, 0, carkitrpga_event,
  1213. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1214. /* Output MUX controls */
  1215. /* HandsfreeL/R */
  1216. SND_SOC_DAPM_MUX("HandsfreeL Mux", SND_SOC_NOPM, 0, 0,
  1217. &twl4030_dapm_handsfreel_control),
  1218. SND_SOC_DAPM_SWITCH("HandsfreeL", SND_SOC_NOPM, 0, 0,
  1219. &twl4030_dapm_handsfreelmute_control),
  1220. SND_SOC_DAPM_PGA_E("HandsfreeL PGA", SND_SOC_NOPM,
  1221. 0, 0, NULL, 0, handsfreelpga_event,
  1222. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1223. SND_SOC_DAPM_MUX("HandsfreeR Mux", SND_SOC_NOPM, 5, 0,
  1224. &twl4030_dapm_handsfreer_control),
  1225. SND_SOC_DAPM_SWITCH("HandsfreeR", SND_SOC_NOPM, 0, 0,
  1226. &twl4030_dapm_handsfreermute_control),
  1227. SND_SOC_DAPM_PGA_E("HandsfreeR PGA", SND_SOC_NOPM,
  1228. 0, 0, NULL, 0, handsfreerpga_event,
  1229. SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
  1230. /* Vibra */
  1231. SND_SOC_DAPM_MUX_E("Vibra Mux", TWL4030_REG_VIBRA_CTL, 0, 0,
  1232. &twl4030_dapm_vibra_control, vibramux_event,
  1233. SND_SOC_DAPM_PRE_PMU),
  1234. SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM, 0, 0,
  1235. &twl4030_dapm_vibrapath_control),
  1236. /* Introducing four virtual ADC, since TWL4030 have four channel for
  1237. capture */
  1238. SND_SOC_DAPM_ADC("ADC Virtual Left1", NULL, SND_SOC_NOPM, 0, 0),
  1239. SND_SOC_DAPM_ADC("ADC Virtual Right1", NULL, SND_SOC_NOPM, 0, 0),
  1240. SND_SOC_DAPM_ADC("ADC Virtual Left2", NULL, SND_SOC_NOPM, 0, 0),
  1241. SND_SOC_DAPM_ADC("ADC Virtual Right2", NULL, SND_SOC_NOPM, 0, 0),
  1242. SND_SOC_DAPM_AIF_OUT("VAIFOUT", "Voice Capture", 0,
  1243. TWL4030_REG_VOICE_IF, 5, 0),
  1244. /* Analog/Digital mic path selection.
  1245. TX1 Left/Right: either analog Left/Right or Digimic0
  1246. TX2 Left/Right: either analog Left/Right or Digimic1 */
  1247. SND_SOC_DAPM_MUX("TX1 Capture Route", SND_SOC_NOPM, 0, 0,
  1248. &twl4030_dapm_micpathtx1_control),
  1249. SND_SOC_DAPM_MUX("TX2 Capture Route", SND_SOC_NOPM, 0, 0,
  1250. &twl4030_dapm_micpathtx2_control),
  1251. /* Analog input mixers for the capture amplifiers */
  1252. SND_SOC_DAPM_MIXER("Analog Left",
  1253. TWL4030_REG_ANAMICL, 4, 0,
  1254. &twl4030_dapm_analoglmic_controls[0],
  1255. ARRAY_SIZE(twl4030_dapm_analoglmic_controls)),
  1256. SND_SOC_DAPM_MIXER("Analog Right",
  1257. TWL4030_REG_ANAMICR, 4, 0,
  1258. &twl4030_dapm_analogrmic_controls[0],
  1259. ARRAY_SIZE(twl4030_dapm_analogrmic_controls)),
  1260. SND_SOC_DAPM_PGA("ADC Physical Left",
  1261. TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0),
  1262. SND_SOC_DAPM_PGA("ADC Physical Right",
  1263. TWL4030_REG_AVADC_CTL, 1, 0, NULL, 0),
  1264. SND_SOC_DAPM_PGA_E("Digimic0 Enable",
  1265. TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0,
  1266. digimic_event, SND_SOC_DAPM_POST_PMU),
  1267. SND_SOC_DAPM_PGA_E("Digimic1 Enable",
  1268. TWL4030_REG_ADCMICSEL, 3, 0, NULL, 0,
  1269. digimic_event, SND_SOC_DAPM_POST_PMU),
  1270. SND_SOC_DAPM_SUPPLY("micbias1 select", TWL4030_REG_MICBIAS_CTL, 5, 0,
  1271. NULL, 0),
  1272. SND_SOC_DAPM_SUPPLY("micbias2 select", TWL4030_REG_MICBIAS_CTL, 6, 0,
  1273. NULL, 0),
  1274. /* Microphone bias */
  1275. SND_SOC_DAPM_SUPPLY("Mic Bias 1",
  1276. TWL4030_REG_MICBIAS_CTL, 0, 0, NULL, 0),
  1277. SND_SOC_DAPM_SUPPLY("Mic Bias 2",
  1278. TWL4030_REG_MICBIAS_CTL, 1, 0, NULL, 0),
  1279. SND_SOC_DAPM_SUPPLY("Headset Mic Bias",
  1280. TWL4030_REG_MICBIAS_CTL, 2, 0, NULL, 0),
  1281. SND_SOC_DAPM_SUPPLY("VIF Enable", TWL4030_REG_VOICE_IF, 0, 0, NULL, 0),
  1282. };
  1283. static const struct snd_soc_dapm_route intercon[] = {
  1284. /* Stream -> DAC mapping */
  1285. {"DAC Right1", NULL, "HiFi Playback"},
  1286. {"DAC Left1", NULL, "HiFi Playback"},
  1287. {"DAC Right2", NULL, "HiFi Playback"},
  1288. {"DAC Left2", NULL, "HiFi Playback"},
  1289. {"DAC Voice", NULL, "VAIFIN"},
  1290. /* ADC -> Stream mapping */
  1291. {"HiFi Capture", NULL, "ADC Virtual Left1"},
  1292. {"HiFi Capture", NULL, "ADC Virtual Right1"},
  1293. {"HiFi Capture", NULL, "ADC Virtual Left2"},
  1294. {"HiFi Capture", NULL, "ADC Virtual Right2"},
  1295. {"VAIFOUT", NULL, "ADC Virtual Left2"},
  1296. {"VAIFOUT", NULL, "ADC Virtual Right2"},
  1297. {"VAIFOUT", NULL, "VIF Enable"},
  1298. {"Digital L1 Playback Mixer", NULL, "DAC Left1"},
  1299. {"Digital R1 Playback Mixer", NULL, "DAC Right1"},
  1300. {"Digital L2 Playback Mixer", NULL, "DAC Left2"},
  1301. {"Digital R2 Playback Mixer", NULL, "DAC Right2"},
  1302. {"Digital Voice Playback Mixer", NULL, "DAC Voice"},
  1303. /* Supply for the digital part (APLL) */
  1304. {"Digital Voice Playback Mixer", NULL, "APLL Enable"},
  1305. {"DAC Left1", NULL, "AIF Enable"},
  1306. {"DAC Right1", NULL, "AIF Enable"},
  1307. {"DAC Left2", NULL, "AIF Enable"},
  1308. {"DAC Right1", NULL, "AIF Enable"},
  1309. {"DAC Voice", NULL, "VIF Enable"},
  1310. {"Digital R2 Playback Mixer", NULL, "AIF Enable"},
  1311. {"Digital L2 Playback Mixer", NULL, "AIF Enable"},
  1312. {"Analog L1 Playback Mixer", NULL, "Digital L1 Playback Mixer"},
  1313. {"Analog R1 Playback Mixer", NULL, "Digital R1 Playback Mixer"},
  1314. {"Analog L2 Playback Mixer", NULL, "Digital L2 Playback Mixer"},
  1315. {"Analog R2 Playback Mixer", NULL, "Digital R2 Playback Mixer"},
  1316. {"Analog Voice Playback Mixer", NULL, "Digital Voice Playback Mixer"},
  1317. /* Internal playback routings */
  1318. /* Earpiece */
  1319. {"Earpiece Mixer", "Voice", "Analog Voice Playback Mixer"},
  1320. {"Earpiece Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1321. {"Earpiece Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1322. {"Earpiece Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1323. {"Earpiece PGA", NULL, "Earpiece Mixer"},
  1324. /* PreDrivL */
  1325. {"PredriveL Mixer", "Voice", "Analog Voice Playback Mixer"},
  1326. {"PredriveL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1327. {"PredriveL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1328. {"PredriveL Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1329. {"PredriveL PGA", NULL, "PredriveL Mixer"},
  1330. /* PreDrivR */
  1331. {"PredriveR Mixer", "Voice", "Analog Voice Playback Mixer"},
  1332. {"PredriveR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1333. {"PredriveR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1334. {"PredriveR Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1335. {"PredriveR PGA", NULL, "PredriveR Mixer"},
  1336. /* HeadsetL */
  1337. {"HeadsetL Mixer", "Voice", "Analog Voice Playback Mixer"},
  1338. {"HeadsetL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1339. {"HeadsetL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1340. {"HeadsetL PGA", NULL, "HeadsetL Mixer"},
  1341. /* HeadsetR */
  1342. {"HeadsetR Mixer", "Voice", "Analog Voice Playback Mixer"},
  1343. {"HeadsetR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1344. {"HeadsetR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1345. {"HeadsetR PGA", NULL, "HeadsetR Mixer"},
  1346. /* CarkitL */
  1347. {"CarkitL Mixer", "Voice", "Analog Voice Playback Mixer"},
  1348. {"CarkitL Mixer", "AudioL1", "Analog L1 Playback Mixer"},
  1349. {"CarkitL Mixer", "AudioL2", "Analog L2 Playback Mixer"},
  1350. {"CarkitL PGA", NULL, "CarkitL Mixer"},
  1351. /* CarkitR */
  1352. {"CarkitR Mixer", "Voice", "Analog Voice Playback Mixer"},
  1353. {"CarkitR Mixer", "AudioR1", "Analog R1 Playback Mixer"},
  1354. {"CarkitR Mixer", "AudioR2", "Analog R2 Playback Mixer"},
  1355. {"CarkitR PGA", NULL, "CarkitR Mixer"},
  1356. /* HandsfreeL */
  1357. {"HandsfreeL Mux", "Voice", "Analog Voice Playback Mixer"},
  1358. {"HandsfreeL Mux", "AudioL1", "Analog L1 Playback Mixer"},
  1359. {"HandsfreeL Mux", "AudioL2", "Analog L2 Playback Mixer"},
  1360. {"HandsfreeL Mux", "AudioR2", "Analog R2 Playback Mixer"},
  1361. {"HandsfreeL", "Switch", "HandsfreeL Mux"},
  1362. {"HandsfreeL PGA", NULL, "HandsfreeL"},
  1363. /* HandsfreeR */
  1364. {"HandsfreeR Mux", "Voice", "Analog Voice Playback Mixer"},
  1365. {"HandsfreeR Mux", "AudioR1", "Analog R1 Playback Mixer"},
  1366. {"HandsfreeR Mux", "AudioR2", "Analog R2 Playback Mixer"},
  1367. {"HandsfreeR Mux", "AudioL2", "Analog L2 Playback Mixer"},
  1368. {"HandsfreeR", "Switch", "HandsfreeR Mux"},
  1369. {"HandsfreeR PGA", NULL, "HandsfreeR"},
  1370. /* Vibra */
  1371. {"Vibra Mux", "AudioL1", "DAC Left1"},
  1372. {"Vibra Mux", "AudioR1", "DAC Right1"},
  1373. {"Vibra Mux", "AudioL2", "DAC Left2"},
  1374. {"Vibra Mux", "AudioR2", "DAC Right2"},
  1375. /* outputs */
  1376. /* Must be always connected (for AIF and APLL) */
  1377. {"Virtual HiFi OUT", NULL, "DAC Left1"},
  1378. {"Virtual HiFi OUT", NULL, "DAC Right1"},
  1379. {"Virtual HiFi OUT", NULL, "DAC Left2"},
  1380. {"Virtual HiFi OUT", NULL, "DAC Right2"},
  1381. /* Must be always connected (for APLL) */
  1382. {"Virtual Voice OUT", NULL, "Digital Voice Playback Mixer"},
  1383. /* Physical outputs */
  1384. {"EARPIECE", NULL, "Earpiece PGA"},
  1385. {"PREDRIVEL", NULL, "PredriveL PGA"},
  1386. {"PREDRIVER", NULL, "PredriveR PGA"},
  1387. {"HSOL", NULL, "HeadsetL PGA"},
  1388. {"HSOR", NULL, "HeadsetR PGA"},
  1389. {"CARKITL", NULL, "CarkitL PGA"},
  1390. {"CARKITR", NULL, "CarkitR PGA"},
  1391. {"HFL", NULL, "HandsfreeL PGA"},
  1392. {"HFR", NULL, "HandsfreeR PGA"},
  1393. {"Vibra Route", "Audio", "Vibra Mux"},
  1394. {"VIBRA", NULL, "Vibra Route"},
  1395. /* Capture path */
  1396. /* Must be always connected (for AIF and APLL) */
  1397. {"ADC Virtual Left1", NULL, "Virtual HiFi IN"},
  1398. {"ADC Virtual Right1", NULL, "Virtual HiFi IN"},
  1399. {"ADC Virtual Left2", NULL, "Virtual HiFi IN"},
  1400. {"ADC Virtual Right2", NULL, "Virtual HiFi IN"},
  1401. /* Physical inputs */
  1402. {"Analog Left", "Main Mic Capture Switch", "MAINMIC"},
  1403. {"Analog Left", "Headset Mic Capture Switch", "HSMIC"},
  1404. {"Analog Left", "AUXL Capture Switch", "AUXL"},
  1405. {"Analog Left", "Carkit Mic Capture Switch", "CARKITMIC"},
  1406. {"Analog Right", "Sub Mic Capture Switch", "SUBMIC"},
  1407. {"Analog Right", "AUXR Capture Switch", "AUXR"},
  1408. {"ADC Physical Left", NULL, "Analog Left"},
  1409. {"ADC Physical Right", NULL, "Analog Right"},
  1410. {"Digimic0 Enable", NULL, "DIGIMIC0"},
  1411. {"Digimic1 Enable", NULL, "DIGIMIC1"},
  1412. {"DIGIMIC0", NULL, "micbias1 select"},
  1413. {"DIGIMIC1", NULL, "micbias2 select"},
  1414. /* TX1 Left capture path */
  1415. {"TX1 Capture Route", "Analog", "ADC Physical Left"},
  1416. {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
  1417. /* TX1 Right capture path */
  1418. {"TX1 Capture Route", "Analog", "ADC Physical Right"},
  1419. {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
  1420. /* TX2 Left capture path */
  1421. {"TX2 Capture Route", "Analog", "ADC Physical Left"},
  1422. {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
  1423. /* TX2 Right capture path */
  1424. {"TX2 Capture Route", "Analog", "ADC Physical Right"},
  1425. {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
  1426. {"ADC Virtual Left1", NULL, "TX1 Capture Route"},
  1427. {"ADC Virtual Right1", NULL, "TX1 Capture Route"},
  1428. {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
  1429. {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
  1430. {"ADC Virtual Left1", NULL, "AIF Enable"},
  1431. {"ADC Virtual Right1", NULL, "AIF Enable"},
  1432. {"ADC Virtual Left2", NULL, "AIF Enable"},
  1433. {"ADC Virtual Right2", NULL, "AIF Enable"},
  1434. /* Analog bypass routes */
  1435. {"Right1 Analog Loopback", "Switch", "Analog Right"},
  1436. {"Left1 Analog Loopback", "Switch", "Analog Left"},
  1437. {"Right2 Analog Loopback", "Switch", "Analog Right"},
  1438. {"Left2 Analog Loopback", "Switch", "Analog Left"},
  1439. {"Voice Analog Loopback", "Switch", "Analog Left"},
  1440. /* Supply for the Analog loopbacks */
  1441. {"Right1 Analog Loopback", NULL, "FM Loop Enable"},
  1442. {"Left1 Analog Loopback", NULL, "FM Loop Enable"},
  1443. {"Right2 Analog Loopback", NULL, "FM Loop Enable"},
  1444. {"Left2 Analog Loopback", NULL, "FM Loop Enable"},
  1445. {"Voice Analog Loopback", NULL, "FM Loop Enable"},
  1446. {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"},
  1447. {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"},
  1448. {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"},
  1449. {"Analog L2 Playback Mixer", NULL, "Left2 Analog Loopback"},
  1450. {"Analog Voice Playback Mixer", NULL, "Voice Analog Loopback"},
  1451. /* Digital bypass routes */
  1452. {"Right Digital Loopback", "Volume", "TX1 Capture Route"},
  1453. {"Left Digital Loopback", "Volume", "TX1 Capture Route"},
  1454. {"Voice Digital Loopback", "Volume", "TX2 Capture Route"},
  1455. {"Digital R2 Playback Mixer", NULL, "Right Digital Loopback"},
  1456. {"Digital L2 Playback Mixer", NULL, "Left Digital Loopback"},
  1457. {"Digital Voice Playback Mixer", NULL, "Voice Digital Loopback"},
  1458. };
  1459. static int twl4030_set_bias_level(struct snd_soc_codec *codec,
  1460. enum snd_soc_bias_level level)
  1461. {
  1462. switch (level) {
  1463. case SND_SOC_BIAS_ON:
  1464. break;
  1465. case SND_SOC_BIAS_PREPARE:
  1466. break;
  1467. case SND_SOC_BIAS_STANDBY:
  1468. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
  1469. twl4030_codec_enable(codec, 1);
  1470. break;
  1471. case SND_SOC_BIAS_OFF:
  1472. twl4030_codec_enable(codec, 0);
  1473. break;
  1474. }
  1475. codec->dapm.bias_level = level;
  1476. return 0;
  1477. }
  1478. static void twl4030_constraints(struct twl4030_priv *twl4030,
  1479. struct snd_pcm_substream *mst_substream)
  1480. {
  1481. struct snd_pcm_substream *slv_substream;
  1482. /* Pick the stream, which need to be constrained */
  1483. if (mst_substream == twl4030->master_substream)
  1484. slv_substream = twl4030->slave_substream;
  1485. else if (mst_substream == twl4030->slave_substream)
  1486. slv_substream = twl4030->master_substream;
  1487. else /* This should not happen.. */
  1488. return;
  1489. /* Set the constraints according to the already configured stream */
  1490. snd_pcm_hw_constraint_minmax(slv_substream->runtime,
  1491. SNDRV_PCM_HW_PARAM_RATE,
  1492. twl4030->rate,
  1493. twl4030->rate);
  1494. snd_pcm_hw_constraint_minmax(slv_substream->runtime,
  1495. SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
  1496. twl4030->sample_bits,
  1497. twl4030->sample_bits);
  1498. snd_pcm_hw_constraint_minmax(slv_substream->runtime,
  1499. SNDRV_PCM_HW_PARAM_CHANNELS,
  1500. twl4030->channels,
  1501. twl4030->channels);
  1502. }
  1503. /* In case of 4 channel mode, the RX1 L/R for playback and the TX2 L/R for
  1504. * capture has to be enabled/disabled. */
  1505. static void twl4030_tdm_enable(struct snd_soc_codec *codec, int direction,
  1506. int enable)
  1507. {
  1508. u8 reg, mask;
  1509. reg = twl4030_read_reg_cache(codec, TWL4030_REG_OPTION);
  1510. if (direction == SNDRV_PCM_STREAM_PLAYBACK)
  1511. mask = TWL4030_ARXL1_VRX_EN | TWL4030_ARXR1_EN;
  1512. else
  1513. mask = TWL4030_ATXL2_VTXL_EN | TWL4030_ATXR2_VTXR_EN;
  1514. if (enable)
  1515. reg |= mask;
  1516. else
  1517. reg &= ~mask;
  1518. twl4030_write(codec, TWL4030_REG_OPTION, reg);
  1519. }
  1520. static int twl4030_startup(struct snd_pcm_substream *substream,
  1521. struct snd_soc_dai *dai)
  1522. {
  1523. struct snd_soc_codec *codec = dai->codec;
  1524. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1525. if (twl4030->master_substream) {
  1526. twl4030->slave_substream = substream;
  1527. /* The DAI has one configuration for playback and capture, so
  1528. * if the DAI has been already configured then constrain this
  1529. * substream to match it. */
  1530. if (twl4030->configured)
  1531. twl4030_constraints(twl4030, twl4030->master_substream);
  1532. } else {
  1533. if (!(twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE) &
  1534. TWL4030_OPTION_1)) {
  1535. /* In option2 4 channel is not supported, set the
  1536. * constraint for the first stream for channels, the
  1537. * second stream will 'inherit' this cosntraint */
  1538. snd_pcm_hw_constraint_minmax(substream->runtime,
  1539. SNDRV_PCM_HW_PARAM_CHANNELS,
  1540. 2, 2);
  1541. }
  1542. twl4030->master_substream = substream;
  1543. }
  1544. return 0;
  1545. }
  1546. static void twl4030_shutdown(struct snd_pcm_substream *substream,
  1547. struct snd_soc_dai *dai)
  1548. {
  1549. struct snd_soc_codec *codec = dai->codec;
  1550. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1551. if (twl4030->master_substream == substream)
  1552. twl4030->master_substream = twl4030->slave_substream;
  1553. twl4030->slave_substream = NULL;
  1554. /* If all streams are closed, or the remaining stream has not yet
  1555. * been configured than set the DAI as not configured. */
  1556. if (!twl4030->master_substream)
  1557. twl4030->configured = 0;
  1558. else if (!twl4030->master_substream->runtime->channels)
  1559. twl4030->configured = 0;
  1560. /* If the closing substream had 4 channel, do the necessary cleanup */
  1561. if (substream->runtime->channels == 4)
  1562. twl4030_tdm_enable(codec, substream->stream, 0);
  1563. }
  1564. static int twl4030_hw_params(struct snd_pcm_substream *substream,
  1565. struct snd_pcm_hw_params *params,
  1566. struct snd_soc_dai *dai)
  1567. {
  1568. struct snd_soc_codec *codec = dai->codec;
  1569. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1570. u8 mode, old_mode, format, old_format;
  1571. /* If the substream has 4 channel, do the necessary setup */
  1572. if (params_channels(params) == 4) {
  1573. format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1574. mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE);
  1575. /* Safety check: are we in the correct operating mode and
  1576. * the interface is in TDM mode? */
  1577. if ((mode & TWL4030_OPTION_1) &&
  1578. ((format & TWL4030_AIF_FORMAT) == TWL4030_AIF_FORMAT_TDM))
  1579. twl4030_tdm_enable(codec, substream->stream, 1);
  1580. else
  1581. return -EINVAL;
  1582. }
  1583. if (twl4030->configured)
  1584. /* Ignoring hw_params for already configured DAI */
  1585. return 0;
  1586. /* bit rate */
  1587. old_mode = twl4030_read_reg_cache(codec,
  1588. TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ;
  1589. mode = old_mode & ~TWL4030_APLL_RATE;
  1590. switch (params_rate(params)) {
  1591. case 8000:
  1592. mode |= TWL4030_APLL_RATE_8000;
  1593. break;
  1594. case 11025:
  1595. mode |= TWL4030_APLL_RATE_11025;
  1596. break;
  1597. case 12000:
  1598. mode |= TWL4030_APLL_RATE_12000;
  1599. break;
  1600. case 16000:
  1601. mode |= TWL4030_APLL_RATE_16000;
  1602. break;
  1603. case 22050:
  1604. mode |= TWL4030_APLL_RATE_22050;
  1605. break;
  1606. case 24000:
  1607. mode |= TWL4030_APLL_RATE_24000;
  1608. break;
  1609. case 32000:
  1610. mode |= TWL4030_APLL_RATE_32000;
  1611. break;
  1612. case 44100:
  1613. mode |= TWL4030_APLL_RATE_44100;
  1614. break;
  1615. case 48000:
  1616. mode |= TWL4030_APLL_RATE_48000;
  1617. break;
  1618. case 96000:
  1619. mode |= TWL4030_APLL_RATE_96000;
  1620. break;
  1621. default:
  1622. dev_err(codec->dev, "%s: unknown rate %d\n", __func__,
  1623. params_rate(params));
  1624. return -EINVAL;
  1625. }
  1626. /* sample size */
  1627. old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1628. format = old_format;
  1629. format &= ~TWL4030_DATA_WIDTH;
  1630. switch (params_format(params)) {
  1631. case SNDRV_PCM_FORMAT_S16_LE:
  1632. format |= TWL4030_DATA_WIDTH_16S_16W;
  1633. break;
  1634. case SNDRV_PCM_FORMAT_S32_LE:
  1635. format |= TWL4030_DATA_WIDTH_32S_24W;
  1636. break;
  1637. default:
  1638. dev_err(codec->dev, "%s: unknown format %d\n", __func__,
  1639. params_format(params));
  1640. return -EINVAL;
  1641. }
  1642. if (format != old_format || mode != old_mode) {
  1643. if (twl4030->codec_powered) {
  1644. /*
  1645. * If the codec is powered, than we need to toggle the
  1646. * codec power.
  1647. */
  1648. twl4030_codec_enable(codec, 0);
  1649. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1650. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1651. twl4030_codec_enable(codec, 1);
  1652. } else {
  1653. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1654. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1655. }
  1656. }
  1657. /* Store the important parameters for the DAI configuration and set
  1658. * the DAI as configured */
  1659. twl4030->configured = 1;
  1660. twl4030->rate = params_rate(params);
  1661. twl4030->sample_bits = hw_param_interval(params,
  1662. SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min;
  1663. twl4030->channels = params_channels(params);
  1664. /* If both playback and capture streams are open, and one of them
  1665. * is setting the hw parameters right now (since we are here), set
  1666. * constraints to the other stream to match the current one. */
  1667. if (twl4030->slave_substream)
  1668. twl4030_constraints(twl4030, substream);
  1669. return 0;
  1670. }
  1671. static int twl4030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1672. int clk_id, unsigned int freq, int dir)
  1673. {
  1674. struct snd_soc_codec *codec = codec_dai->codec;
  1675. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1676. switch (freq) {
  1677. case 19200000:
  1678. case 26000000:
  1679. case 38400000:
  1680. break;
  1681. default:
  1682. dev_err(codec->dev, "Unsupported HFCLKIN: %u\n", freq);
  1683. return -EINVAL;
  1684. }
  1685. if ((freq / 1000) != twl4030->sysclk) {
  1686. dev_err(codec->dev,
  1687. "Mismatch in HFCLKIN: %u (configured: %u)\n",
  1688. freq, twl4030->sysclk * 1000);
  1689. return -EINVAL;
  1690. }
  1691. return 0;
  1692. }
  1693. static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1694. unsigned int fmt)
  1695. {
  1696. struct snd_soc_codec *codec = codec_dai->codec;
  1697. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1698. u8 old_format, format;
  1699. /* get format */
  1700. old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1701. format = old_format;
  1702. /* set master/slave audio interface */
  1703. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1704. case SND_SOC_DAIFMT_CBM_CFM:
  1705. format &= ~(TWL4030_AIF_SLAVE_EN);
  1706. format &= ~(TWL4030_CLK256FS_EN);
  1707. break;
  1708. case SND_SOC_DAIFMT_CBS_CFS:
  1709. format |= TWL4030_AIF_SLAVE_EN;
  1710. format |= TWL4030_CLK256FS_EN;
  1711. break;
  1712. default:
  1713. return -EINVAL;
  1714. }
  1715. /* interface format */
  1716. format &= ~TWL4030_AIF_FORMAT;
  1717. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1718. case SND_SOC_DAIFMT_I2S:
  1719. format |= TWL4030_AIF_FORMAT_CODEC;
  1720. break;
  1721. case SND_SOC_DAIFMT_DSP_A:
  1722. format |= TWL4030_AIF_FORMAT_TDM;
  1723. break;
  1724. default:
  1725. return -EINVAL;
  1726. }
  1727. if (format != old_format) {
  1728. if (twl4030->codec_powered) {
  1729. /*
  1730. * If the codec is powered, than we need to toggle the
  1731. * codec power.
  1732. */
  1733. twl4030_codec_enable(codec, 0);
  1734. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1735. twl4030_codec_enable(codec, 1);
  1736. } else {
  1737. twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
  1738. }
  1739. }
  1740. return 0;
  1741. }
  1742. static int twl4030_set_tristate(struct snd_soc_dai *dai, int tristate)
  1743. {
  1744. struct snd_soc_codec *codec = dai->codec;
  1745. u8 reg = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF);
  1746. if (tristate)
  1747. reg |= TWL4030_AIF_TRI_EN;
  1748. else
  1749. reg &= ~TWL4030_AIF_TRI_EN;
  1750. return twl4030_write(codec, TWL4030_REG_AUDIO_IF, reg);
  1751. }
  1752. /* In case of voice mode, the RX1 L(VRX) for downlink and the TX2 L/R
  1753. * (VTXL, VTXR) for uplink has to be enabled/disabled. */
  1754. static void twl4030_voice_enable(struct snd_soc_codec *codec, int direction,
  1755. int enable)
  1756. {
  1757. u8 reg, mask;
  1758. reg = twl4030_read_reg_cache(codec, TWL4030_REG_OPTION);
  1759. if (direction == SNDRV_PCM_STREAM_PLAYBACK)
  1760. mask = TWL4030_ARXL1_VRX_EN;
  1761. else
  1762. mask = TWL4030_ATXL2_VTXL_EN | TWL4030_ATXR2_VTXR_EN;
  1763. if (enable)
  1764. reg |= mask;
  1765. else
  1766. reg &= ~mask;
  1767. twl4030_write(codec, TWL4030_REG_OPTION, reg);
  1768. }
  1769. static int twl4030_voice_startup(struct snd_pcm_substream *substream,
  1770. struct snd_soc_dai *dai)
  1771. {
  1772. struct snd_soc_codec *codec = dai->codec;
  1773. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1774. u8 mode;
  1775. /* If the system master clock is not 26MHz, the voice PCM interface is
  1776. * not available.
  1777. */
  1778. if (twl4030->sysclk != 26000) {
  1779. dev_err(codec->dev,
  1780. "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
  1781. __func__, twl4030->sysclk);
  1782. return -EINVAL;
  1783. }
  1784. /* If the codec mode is not option2, the voice PCM interface is not
  1785. * available.
  1786. */
  1787. mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE)
  1788. & TWL4030_OPT_MODE;
  1789. if (mode != TWL4030_OPTION_2) {
  1790. dev_err(codec->dev, "%s: the codec mode is not option2\n",
  1791. __func__);
  1792. return -EINVAL;
  1793. }
  1794. return 0;
  1795. }
  1796. static void twl4030_voice_shutdown(struct snd_pcm_substream *substream,
  1797. struct snd_soc_dai *dai)
  1798. {
  1799. struct snd_soc_codec *codec = dai->codec;
  1800. /* Enable voice digital filters */
  1801. twl4030_voice_enable(codec, substream->stream, 0);
  1802. }
  1803. static int twl4030_voice_hw_params(struct snd_pcm_substream *substream,
  1804. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  1805. {
  1806. struct snd_soc_codec *codec = dai->codec;
  1807. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1808. u8 old_mode, mode;
  1809. /* Enable voice digital filters */
  1810. twl4030_voice_enable(codec, substream->stream, 1);
  1811. /* bit rate */
  1812. old_mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE)
  1813. & ~(TWL4030_CODECPDZ);
  1814. mode = old_mode;
  1815. switch (params_rate(params)) {
  1816. case 8000:
  1817. mode &= ~(TWL4030_SEL_16K);
  1818. break;
  1819. case 16000:
  1820. mode |= TWL4030_SEL_16K;
  1821. break;
  1822. default:
  1823. dev_err(codec->dev, "%s: unknown rate %d\n", __func__,
  1824. params_rate(params));
  1825. return -EINVAL;
  1826. }
  1827. if (mode != old_mode) {
  1828. if (twl4030->codec_powered) {
  1829. /*
  1830. * If the codec is powered, than we need to toggle the
  1831. * codec power.
  1832. */
  1833. twl4030_codec_enable(codec, 0);
  1834. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1835. twl4030_codec_enable(codec, 1);
  1836. } else {
  1837. twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
  1838. }
  1839. }
  1840. return 0;
  1841. }
  1842. static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1843. int clk_id, unsigned int freq, int dir)
  1844. {
  1845. struct snd_soc_codec *codec = codec_dai->codec;
  1846. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1847. if (freq != 26000000) {
  1848. dev_err(codec->dev,
  1849. "%s: HFCLKIN is %u KHz, voice interface needs 26MHz\n",
  1850. __func__, freq / 1000);
  1851. return -EINVAL;
  1852. }
  1853. if ((freq / 1000) != twl4030->sysclk) {
  1854. dev_err(codec->dev,
  1855. "Mismatch in HFCLKIN: %u (configured: %u)\n",
  1856. freq, twl4030->sysclk * 1000);
  1857. return -EINVAL;
  1858. }
  1859. return 0;
  1860. }
  1861. static int twl4030_voice_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1862. unsigned int fmt)
  1863. {
  1864. struct snd_soc_codec *codec = codec_dai->codec;
  1865. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1866. u8 old_format, format;
  1867. /* get format */
  1868. old_format = twl4030_read_reg_cache(codec, TWL4030_REG_VOICE_IF);
  1869. format = old_format;
  1870. /* set master/slave audio interface */
  1871. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1872. case SND_SOC_DAIFMT_CBM_CFM:
  1873. format &= ~(TWL4030_VIF_SLAVE_EN);
  1874. break;
  1875. case SND_SOC_DAIFMT_CBS_CFS:
  1876. format |= TWL4030_VIF_SLAVE_EN;
  1877. break;
  1878. default:
  1879. return -EINVAL;
  1880. }
  1881. /* clock inversion */
  1882. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1883. case SND_SOC_DAIFMT_IB_NF:
  1884. format &= ~(TWL4030_VIF_FORMAT);
  1885. break;
  1886. case SND_SOC_DAIFMT_NB_IF:
  1887. format |= TWL4030_VIF_FORMAT;
  1888. break;
  1889. default:
  1890. return -EINVAL;
  1891. }
  1892. if (format != old_format) {
  1893. if (twl4030->codec_powered) {
  1894. /*
  1895. * If the codec is powered, than we need to toggle the
  1896. * codec power.
  1897. */
  1898. twl4030_codec_enable(codec, 0);
  1899. twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
  1900. twl4030_codec_enable(codec, 1);
  1901. } else {
  1902. twl4030_write(codec, TWL4030_REG_VOICE_IF, format);
  1903. }
  1904. }
  1905. return 0;
  1906. }
  1907. static int twl4030_voice_set_tristate(struct snd_soc_dai *dai, int tristate)
  1908. {
  1909. struct snd_soc_codec *codec = dai->codec;
  1910. u8 reg = twl4030_read_reg_cache(codec, TWL4030_REG_VOICE_IF);
  1911. if (tristate)
  1912. reg |= TWL4030_VIF_TRI_EN;
  1913. else
  1914. reg &= ~TWL4030_VIF_TRI_EN;
  1915. return twl4030_write(codec, TWL4030_REG_VOICE_IF, reg);
  1916. }
  1917. #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000)
  1918. #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1919. static const struct snd_soc_dai_ops twl4030_dai_hifi_ops = {
  1920. .startup = twl4030_startup,
  1921. .shutdown = twl4030_shutdown,
  1922. .hw_params = twl4030_hw_params,
  1923. .set_sysclk = twl4030_set_dai_sysclk,
  1924. .set_fmt = twl4030_set_dai_fmt,
  1925. .set_tristate = twl4030_set_tristate,
  1926. };
  1927. static const struct snd_soc_dai_ops twl4030_dai_voice_ops = {
  1928. .startup = twl4030_voice_startup,
  1929. .shutdown = twl4030_voice_shutdown,
  1930. .hw_params = twl4030_voice_hw_params,
  1931. .set_sysclk = twl4030_voice_set_dai_sysclk,
  1932. .set_fmt = twl4030_voice_set_dai_fmt,
  1933. .set_tristate = twl4030_voice_set_tristate,
  1934. };
  1935. static struct snd_soc_dai_driver twl4030_dai[] = {
  1936. {
  1937. .name = "twl4030-hifi",
  1938. .playback = {
  1939. .stream_name = "HiFi Playback",
  1940. .channels_min = 2,
  1941. .channels_max = 4,
  1942. .rates = TWL4030_RATES | SNDRV_PCM_RATE_96000,
  1943. .formats = TWL4030_FORMATS,
  1944. .sig_bits = 24,},
  1945. .capture = {
  1946. .stream_name = "HiFi Capture",
  1947. .channels_min = 2,
  1948. .channels_max = 4,
  1949. .rates = TWL4030_RATES,
  1950. .formats = TWL4030_FORMATS,
  1951. .sig_bits = 24,},
  1952. .ops = &twl4030_dai_hifi_ops,
  1953. },
  1954. {
  1955. .name = "twl4030-voice",
  1956. .playback = {
  1957. .stream_name = "Voice Playback",
  1958. .channels_min = 1,
  1959. .channels_max = 1,
  1960. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1961. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  1962. .capture = {
  1963. .stream_name = "Voice Capture",
  1964. .channels_min = 1,
  1965. .channels_max = 2,
  1966. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
  1967. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  1968. .ops = &twl4030_dai_voice_ops,
  1969. },
  1970. };
  1971. static int twl4030_soc_suspend(struct snd_soc_codec *codec)
  1972. {
  1973. twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1974. return 0;
  1975. }
  1976. static int twl4030_soc_resume(struct snd_soc_codec *codec)
  1977. {
  1978. twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1979. return 0;
  1980. }
  1981. static int twl4030_soc_probe(struct snd_soc_codec *codec)
  1982. {
  1983. struct twl4030_priv *twl4030;
  1984. twl4030 = devm_kzalloc(codec->dev, sizeof(struct twl4030_priv),
  1985. GFP_KERNEL);
  1986. if (twl4030 == NULL) {
  1987. dev_err(codec->dev, "Can not allocate memory\n");
  1988. return -ENOMEM;
  1989. }
  1990. snd_soc_codec_set_drvdata(codec, twl4030);
  1991. /* Set the defaults, and power up the codec */
  1992. twl4030->sysclk = twl4030_audio_get_mclk() / 1000;
  1993. twl4030_init_chip(codec);
  1994. return 0;
  1995. }
  1996. static int twl4030_soc_remove(struct snd_soc_codec *codec)
  1997. {
  1998. struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
  1999. struct twl4030_codec_data *pdata = twl4030->pdata;
  2000. /* Reset registers to their chip default before leaving */
  2001. twl4030_reset_registers(codec);
  2002. twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
  2003. if (pdata && pdata->hs_extmute && gpio_is_valid(pdata->hs_extmute_gpio))
  2004. gpio_free(pdata->hs_extmute_gpio);
  2005. return 0;
  2006. }
  2007. static struct snd_soc_codec_driver soc_codec_dev_twl4030 = {
  2008. .probe = twl4030_soc_probe,
  2009. .remove = twl4030_soc_remove,
  2010. .suspend = twl4030_soc_suspend,
  2011. .resume = twl4030_soc_resume,
  2012. .read = twl4030_read_reg_cache,
  2013. .write = twl4030_write,
  2014. .set_bias_level = twl4030_set_bias_level,
  2015. .idle_bias_off = true,
  2016. .reg_cache_size = sizeof(twl4030_reg),
  2017. .reg_word_size = sizeof(u8),
  2018. .reg_cache_default = twl4030_reg,
  2019. .controls = twl4030_snd_controls,
  2020. .num_controls = ARRAY_SIZE(twl4030_snd_controls),
  2021. .dapm_widgets = twl4030_dapm_widgets,
  2022. .num_dapm_widgets = ARRAY_SIZE(twl4030_dapm_widgets),
  2023. .dapm_routes = intercon,
  2024. .num_dapm_routes = ARRAY_SIZE(intercon),
  2025. };
  2026. static int twl4030_codec_probe(struct platform_device *pdev)
  2027. {
  2028. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl4030,
  2029. twl4030_dai, ARRAY_SIZE(twl4030_dai));
  2030. }
  2031. static int twl4030_codec_remove(struct platform_device *pdev)
  2032. {
  2033. snd_soc_unregister_codec(&pdev->dev);
  2034. return 0;
  2035. }
  2036. MODULE_ALIAS("platform:twl4030-codec");
  2037. static struct platform_driver twl4030_codec_driver = {
  2038. .probe = twl4030_codec_probe,
  2039. .remove = twl4030_codec_remove,
  2040. .driver = {
  2041. .name = "twl4030-codec",
  2042. .owner = THIS_MODULE,
  2043. },
  2044. };
  2045. module_platform_driver(twl4030_codec_driver);
  2046. MODULE_DESCRIPTION("ASoC TWL4030 codec driver");
  2047. MODULE_AUTHOR("Steve Sakoman");
  2048. MODULE_LICENSE("GPL");