ab8500-codec.c 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2012
  3. *
  4. * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
  5. * Kristoffer Karlsson <kristoffer.karlsson@stericsson.com>,
  6. * Roger Nilsson <roger.xr.nilsson@stericsson.com>,
  7. * for ST-Ericsson.
  8. *
  9. * Based on the early work done by:
  10. * Mikko J. Lehto <mikko.lehto@symbio.com>,
  11. * Mikko Sarmanne <mikko.sarmanne@symbio.com>,
  12. * Jarmo K. Kuronen <jarmo.kuronen@symbio.com>,
  13. * for ST-Ericsson.
  14. *
  15. * License terms:
  16. *
  17. * This program is free software; you can redistribute it and/or modify it
  18. * under the terms of the GNU General Public License version 2 as published
  19. * by the Free Software Foundation.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/device.h>
  24. #include <linux/slab.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/mutex.h>
  31. #include <linux/mfd/abx500/ab8500.h>
  32. #include <linux/mfd/abx500.h>
  33. #include <linux/mfd/abx500/ab8500-sysctrl.h>
  34. #include <linux/mfd/abx500/ab8500-codec.h>
  35. #include <linux/regulator/consumer.h>
  36. #include <linux/of.h>
  37. #include <sound/core.h>
  38. #include <sound/pcm.h>
  39. #include <sound/pcm_params.h>
  40. #include <sound/initval.h>
  41. #include <sound/soc.h>
  42. #include <sound/soc-dapm.h>
  43. #include <sound/tlv.h>
  44. #include "ab8500-codec.h"
  45. /* Macrocell value definitions */
  46. #define CLK_32K_OUT2_DISABLE 0x01
  47. #define INACTIVE_RESET_AUDIO 0x02
  48. #define ENABLE_AUDIO_CLK_TO_AUDIO_BLK 0x10
  49. #define ENABLE_VINTCORE12_SUPPLY 0x04
  50. #define GPIO27_DIR_OUTPUT 0x04
  51. #define GPIO29_DIR_OUTPUT 0x10
  52. #define GPIO31_DIR_OUTPUT 0x40
  53. /* Macrocell register definitions */
  54. #define AB8500_GPIO_DIR4_REG 0x13 /* Bank AB8500_MISC */
  55. /* Nr of FIR/IIR-coeff banks in ANC-block */
  56. #define AB8500_NR_OF_ANC_COEFF_BANKS 2
  57. /* Minimum duration to keep ANC IIR Init bit high or
  58. low before proceeding with the configuration sequence */
  59. #define AB8500_ANC_SM_DELAY 2000
  60. #define AB8500_FILTER_CONTROL(xname, xcount, xmin, xmax) \
  61. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  62. .info = filter_control_info, \
  63. .get = filter_control_get, .put = filter_control_put, \
  64. .private_value = (unsigned long)&(struct filter_control) \
  65. {.count = xcount, .min = xmin, .max = xmax} }
  66. struct filter_control {
  67. long min, max;
  68. unsigned int count;
  69. long value[128];
  70. };
  71. /* Sidetone states */
  72. static const char * const enum_sid_state[] = {
  73. "Unconfigured",
  74. "Apply FIR",
  75. "FIR is configured",
  76. };
  77. enum sid_state {
  78. SID_UNCONFIGURED = 0,
  79. SID_APPLY_FIR = 1,
  80. SID_FIR_CONFIGURED = 2,
  81. };
  82. static const char * const enum_anc_state[] = {
  83. "Unconfigured",
  84. "Apply FIR and IIR",
  85. "FIR and IIR are configured",
  86. "Apply FIR",
  87. "FIR is configured",
  88. "Apply IIR",
  89. "IIR is configured"
  90. };
  91. enum anc_state {
  92. ANC_UNCONFIGURED = 0,
  93. ANC_APPLY_FIR_IIR = 1,
  94. ANC_FIR_IIR_CONFIGURED = 2,
  95. ANC_APPLY_FIR = 3,
  96. ANC_FIR_CONFIGURED = 4,
  97. ANC_APPLY_IIR = 5,
  98. ANC_IIR_CONFIGURED = 6
  99. };
  100. /* Analog microphones */
  101. enum amic_idx {
  102. AMIC_IDX_1A,
  103. AMIC_IDX_1B,
  104. AMIC_IDX_2
  105. };
  106. struct ab8500_codec_drvdata_dbg {
  107. struct regulator *vaud;
  108. struct regulator *vamic1;
  109. struct regulator *vamic2;
  110. struct regulator *vdmic;
  111. };
  112. /* Private data for AB8500 device-driver */
  113. struct ab8500_codec_drvdata {
  114. struct regmap *regmap;
  115. struct mutex ctrl_lock;
  116. /* Sidetone */
  117. long *sid_fir_values;
  118. enum sid_state sid_status;
  119. /* ANC */
  120. long *anc_fir_values;
  121. long *anc_iir_values;
  122. enum anc_state anc_status;
  123. };
  124. static inline const char *amic_micbias_str(enum amic_micbias micbias)
  125. {
  126. switch (micbias) {
  127. case AMIC_MICBIAS_VAMIC1:
  128. return "VAMIC1";
  129. case AMIC_MICBIAS_VAMIC2:
  130. return "VAMIC2";
  131. default:
  132. return "Unknown";
  133. }
  134. }
  135. static inline const char *amic_type_str(enum amic_type type)
  136. {
  137. switch (type) {
  138. case AMIC_TYPE_DIFFERENTIAL:
  139. return "DIFFERENTIAL";
  140. case AMIC_TYPE_SINGLE_ENDED:
  141. return "SINGLE ENDED";
  142. default:
  143. return "Unknown";
  144. }
  145. }
  146. /*
  147. * Read'n'write functions
  148. */
  149. /* Read a register from the audio-bank of AB8500 */
  150. static int ab8500_codec_read_reg(void *context, unsigned int reg,
  151. unsigned int *value)
  152. {
  153. struct device *dev = context;
  154. int status;
  155. u8 value8;
  156. status = abx500_get_register_interruptible(dev, AB8500_AUDIO,
  157. reg, &value8);
  158. *value = (unsigned int)value8;
  159. return status;
  160. }
  161. /* Write to a register in the audio-bank of AB8500 */
  162. static int ab8500_codec_write_reg(void *context, unsigned int reg,
  163. unsigned int value)
  164. {
  165. struct device *dev = context;
  166. return abx500_set_register_interruptible(dev, AB8500_AUDIO,
  167. reg, value);
  168. }
  169. static const struct regmap_config ab8500_codec_regmap = {
  170. .reg_read = ab8500_codec_read_reg,
  171. .reg_write = ab8500_codec_write_reg,
  172. };
  173. /*
  174. * Controls - DAPM
  175. */
  176. /* Earpiece */
  177. /* Earpiece source selector */
  178. static const char * const enum_ear_lineout_source[] = {"Headset Left",
  179. "Speaker Left"};
  180. static SOC_ENUM_SINGLE_DECL(dapm_enum_ear_lineout_source, AB8500_DMICFILTCONF,
  181. AB8500_DMICFILTCONF_DA3TOEAR, enum_ear_lineout_source);
  182. static const struct snd_kcontrol_new dapm_ear_lineout_source =
  183. SOC_DAPM_ENUM("Earpiece or LineOut Mono Source",
  184. dapm_enum_ear_lineout_source);
  185. /* LineOut */
  186. /* LineOut source selector */
  187. static const char * const enum_lineout_source[] = {"Mono Path", "Stereo Path"};
  188. static SOC_ENUM_DOUBLE_DECL(dapm_enum_lineout_source, AB8500_ANACONF5,
  189. AB8500_ANACONF5_HSLDACTOLOL,
  190. AB8500_ANACONF5_HSRDACTOLOR, enum_lineout_source);
  191. static const struct snd_kcontrol_new dapm_lineout_source[] = {
  192. SOC_DAPM_ENUM("LineOut Source", dapm_enum_lineout_source),
  193. };
  194. /* Handsfree */
  195. /* Speaker Left - ANC selector */
  196. static const char * const enum_HFx_sel[] = {"Audio Path", "ANC"};
  197. static SOC_ENUM_SINGLE_DECL(dapm_enum_HFl_sel, AB8500_DIGMULTCONF2,
  198. AB8500_DIGMULTCONF2_HFLSEL, enum_HFx_sel);
  199. static const struct snd_kcontrol_new dapm_HFl_select[] = {
  200. SOC_DAPM_ENUM("Speaker Left Source", dapm_enum_HFl_sel),
  201. };
  202. /* Speaker Right - ANC selector */
  203. static SOC_ENUM_SINGLE_DECL(dapm_enum_HFr_sel, AB8500_DIGMULTCONF2,
  204. AB8500_DIGMULTCONF2_HFRSEL, enum_HFx_sel);
  205. static const struct snd_kcontrol_new dapm_HFr_select[] = {
  206. SOC_DAPM_ENUM("Speaker Right Source", dapm_enum_HFr_sel),
  207. };
  208. /* Mic 1 */
  209. /* Mic 1 - Mic 1a or 1b selector */
  210. static const char * const enum_mic1ab_sel[] = {"Mic 1b", "Mic 1a"};
  211. static SOC_ENUM_SINGLE_DECL(dapm_enum_mic1ab_sel, AB8500_ANACONF3,
  212. AB8500_ANACONF3_MIC1SEL, enum_mic1ab_sel);
  213. static const struct snd_kcontrol_new dapm_mic1ab_mux[] = {
  214. SOC_DAPM_ENUM("Mic 1a or 1b Select", dapm_enum_mic1ab_sel),
  215. };
  216. /* Mic 1 - AD3 - Mic 1 or DMic 3 selector */
  217. static const char * const enum_ad3_sel[] = {"Mic 1", "DMic 3"};
  218. static SOC_ENUM_SINGLE_DECL(dapm_enum_ad3_sel, AB8500_DIGMULTCONF1,
  219. AB8500_DIGMULTCONF1_AD3SEL, enum_ad3_sel);
  220. static const struct snd_kcontrol_new dapm_ad3_select[] = {
  221. SOC_DAPM_ENUM("AD3 Source Select", dapm_enum_ad3_sel),
  222. };
  223. /* Mic 1 - AD6 - Mic 1 or DMic 6 selector */
  224. static const char * const enum_ad6_sel[] = {"Mic 1", "DMic 6"};
  225. static SOC_ENUM_SINGLE_DECL(dapm_enum_ad6_sel, AB8500_DIGMULTCONF1,
  226. AB8500_DIGMULTCONF1_AD6SEL, enum_ad6_sel);
  227. static const struct snd_kcontrol_new dapm_ad6_select[] = {
  228. SOC_DAPM_ENUM("AD6 Source Select", dapm_enum_ad6_sel),
  229. };
  230. /* Mic 2 */
  231. /* Mic 2 - AD5 - Mic 2 or DMic 5 selector */
  232. static const char * const enum_ad5_sel[] = {"Mic 2", "DMic 5"};
  233. static SOC_ENUM_SINGLE_DECL(dapm_enum_ad5_sel, AB8500_DIGMULTCONF1,
  234. AB8500_DIGMULTCONF1_AD5SEL, enum_ad5_sel);
  235. static const struct snd_kcontrol_new dapm_ad5_select[] = {
  236. SOC_DAPM_ENUM("AD5 Source Select", dapm_enum_ad5_sel),
  237. };
  238. /* LineIn */
  239. /* LineIn left - AD1 - LineIn Left or DMic 1 selector */
  240. static const char * const enum_ad1_sel[] = {"LineIn Left", "DMic 1"};
  241. static SOC_ENUM_SINGLE_DECL(dapm_enum_ad1_sel, AB8500_DIGMULTCONF1,
  242. AB8500_DIGMULTCONF1_AD1SEL, enum_ad1_sel);
  243. static const struct snd_kcontrol_new dapm_ad1_select[] = {
  244. SOC_DAPM_ENUM("AD1 Source Select", dapm_enum_ad1_sel),
  245. };
  246. /* LineIn right - Mic 2 or LineIn Right selector */
  247. static const char * const enum_mic2lr_sel[] = {"Mic 2", "LineIn Right"};
  248. static SOC_ENUM_SINGLE_DECL(dapm_enum_mic2lr_sel, AB8500_ANACONF3,
  249. AB8500_ANACONF3_LINRSEL, enum_mic2lr_sel);
  250. static const struct snd_kcontrol_new dapm_mic2lr_select[] = {
  251. SOC_DAPM_ENUM("Mic 2 or LINR Select", dapm_enum_mic2lr_sel),
  252. };
  253. /* LineIn right - AD2 - LineIn Right or DMic2 selector */
  254. static const char * const enum_ad2_sel[] = {"LineIn Right", "DMic 2"};
  255. static SOC_ENUM_SINGLE_DECL(dapm_enum_ad2_sel, AB8500_DIGMULTCONF1,
  256. AB8500_DIGMULTCONF1_AD2SEL, enum_ad2_sel);
  257. static const struct snd_kcontrol_new dapm_ad2_select[] = {
  258. SOC_DAPM_ENUM("AD2 Source Select", dapm_enum_ad2_sel),
  259. };
  260. /* ANC */
  261. static const char * const enum_anc_in_sel[] = {"Mic 1 / DMic 6",
  262. "Mic 2 / DMic 5"};
  263. static SOC_ENUM_SINGLE_DECL(dapm_enum_anc_in_sel, AB8500_DMICFILTCONF,
  264. AB8500_DMICFILTCONF_ANCINSEL, enum_anc_in_sel);
  265. static const struct snd_kcontrol_new dapm_anc_in_select[] = {
  266. SOC_DAPM_ENUM("ANC Source", dapm_enum_anc_in_sel),
  267. };
  268. /* ANC - Enable/Disable */
  269. static const struct snd_kcontrol_new dapm_anc_enable[] = {
  270. SOC_DAPM_SINGLE("Switch", AB8500_ANCCONF1,
  271. AB8500_ANCCONF1_ENANC, 0, 0),
  272. };
  273. /* ANC to Earpiece - Mute */
  274. static const struct snd_kcontrol_new dapm_anc_ear_mute[] = {
  275. SOC_DAPM_SINGLE("Switch", AB8500_DIGMULTCONF1,
  276. AB8500_DIGMULTCONF1_ANCSEL, 1, 0),
  277. };
  278. /* Sidetone left */
  279. /* Sidetone left - Input selector */
  280. static const char * const enum_stfir1_in_sel[] = {
  281. "LineIn Left", "LineIn Right", "Mic 1", "Headset Left"
  282. };
  283. static SOC_ENUM_SINGLE_DECL(dapm_enum_stfir1_in_sel, AB8500_DIGMULTCONF2,
  284. AB8500_DIGMULTCONF2_FIRSID1SEL, enum_stfir1_in_sel);
  285. static const struct snd_kcontrol_new dapm_stfir1_in_select[] = {
  286. SOC_DAPM_ENUM("Sidetone Left Source", dapm_enum_stfir1_in_sel),
  287. };
  288. /* Sidetone right path */
  289. /* Sidetone right - Input selector */
  290. static const char * const enum_stfir2_in_sel[] = {
  291. "LineIn Right", "Mic 1", "DMic 4", "Headset Right"
  292. };
  293. static SOC_ENUM_SINGLE_DECL(dapm_enum_stfir2_in_sel, AB8500_DIGMULTCONF2,
  294. AB8500_DIGMULTCONF2_FIRSID2SEL, enum_stfir2_in_sel);
  295. static const struct snd_kcontrol_new dapm_stfir2_in_select[] = {
  296. SOC_DAPM_ENUM("Sidetone Right Source", dapm_enum_stfir2_in_sel),
  297. };
  298. /* Vibra */
  299. static const char * const enum_pwm2vibx[] = {"Audio Path", "PWM Generator"};
  300. static SOC_ENUM_SINGLE_DECL(dapm_enum_pwm2vib1, AB8500_PWMGENCONF1,
  301. AB8500_PWMGENCONF1_PWMTOVIB1, enum_pwm2vibx);
  302. static const struct snd_kcontrol_new dapm_pwm2vib1[] = {
  303. SOC_DAPM_ENUM("Vibra 1 Controller", dapm_enum_pwm2vib1),
  304. };
  305. static SOC_ENUM_SINGLE_DECL(dapm_enum_pwm2vib2, AB8500_PWMGENCONF1,
  306. AB8500_PWMGENCONF1_PWMTOVIB2, enum_pwm2vibx);
  307. static const struct snd_kcontrol_new dapm_pwm2vib2[] = {
  308. SOC_DAPM_ENUM("Vibra 2 Controller", dapm_enum_pwm2vib2),
  309. };
  310. /*
  311. * DAPM-widgets
  312. */
  313. static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
  314. /* Clocks */
  315. SND_SOC_DAPM_CLOCK_SUPPLY("audioclk"),
  316. /* Regulators */
  317. SND_SOC_DAPM_REGULATOR_SUPPLY("V-AUD", 0, 0),
  318. SND_SOC_DAPM_REGULATOR_SUPPLY("V-AMIC1", 0, 0),
  319. SND_SOC_DAPM_REGULATOR_SUPPLY("V-AMIC2", 0, 0),
  320. SND_SOC_DAPM_REGULATOR_SUPPLY("V-DMIC", 0, 0),
  321. /* Power */
  322. SND_SOC_DAPM_SUPPLY("Audio Power",
  323. AB8500_POWERUP, AB8500_POWERUP_POWERUP, 0,
  324. NULL, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  325. SND_SOC_DAPM_SUPPLY("Audio Analog Power",
  326. AB8500_POWERUP, AB8500_POWERUP_ENANA, 0,
  327. NULL, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  328. /* Main supply node */
  329. SND_SOC_DAPM_SUPPLY("Main Supply", SND_SOC_NOPM, 0, 0,
  330. NULL, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  331. /* DA/AD */
  332. SND_SOC_DAPM_INPUT("ADC Input"),
  333. SND_SOC_DAPM_ADC("ADC", "ab8500_0c", SND_SOC_NOPM, 0, 0),
  334. SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
  335. SND_SOC_DAPM_OUTPUT("DAC Output"),
  336. SND_SOC_DAPM_AIF_IN("DA_IN1", NULL, 0, SND_SOC_NOPM, 0, 0),
  337. SND_SOC_DAPM_AIF_IN("DA_IN2", NULL, 0, SND_SOC_NOPM, 0, 0),
  338. SND_SOC_DAPM_AIF_IN("DA_IN3", NULL, 0, SND_SOC_NOPM, 0, 0),
  339. SND_SOC_DAPM_AIF_IN("DA_IN4", NULL, 0, SND_SOC_NOPM, 0, 0),
  340. SND_SOC_DAPM_AIF_IN("DA_IN5", NULL, 0, SND_SOC_NOPM, 0, 0),
  341. SND_SOC_DAPM_AIF_IN("DA_IN6", NULL, 0, SND_SOC_NOPM, 0, 0),
  342. SND_SOC_DAPM_AIF_OUT("AD_OUT1", NULL, 0, SND_SOC_NOPM, 0, 0),
  343. SND_SOC_DAPM_AIF_OUT("AD_OUT2", NULL, 0, SND_SOC_NOPM, 0, 0),
  344. SND_SOC_DAPM_AIF_OUT("AD_OUT3", NULL, 0, SND_SOC_NOPM, 0, 0),
  345. SND_SOC_DAPM_AIF_OUT("AD_OUT4", NULL, 0, SND_SOC_NOPM, 0, 0),
  346. SND_SOC_DAPM_AIF_OUT("AD_OUT57", NULL, 0, SND_SOC_NOPM, 0, 0),
  347. SND_SOC_DAPM_AIF_OUT("AD_OUT68", NULL, 0, SND_SOC_NOPM, 0, 0),
  348. /* Headset path */
  349. SND_SOC_DAPM_SUPPLY("Charge Pump", AB8500_ANACONF5,
  350. AB8500_ANACONF5_ENCPHS, 0, NULL, 0),
  351. SND_SOC_DAPM_DAC("DA1 Enable", "ab8500_0p",
  352. AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA1, 0),
  353. SND_SOC_DAPM_DAC("DA2 Enable", "ab8500_0p",
  354. AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA2, 0),
  355. SND_SOC_DAPM_PGA("HSL Digital Volume", SND_SOC_NOPM, 0, 0,
  356. NULL, 0),
  357. SND_SOC_DAPM_PGA("HSR Digital Volume", SND_SOC_NOPM, 0, 0,
  358. NULL, 0),
  359. SND_SOC_DAPM_DAC("HSL DAC", "ab8500_0p",
  360. AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACHSL, 0),
  361. SND_SOC_DAPM_DAC("HSR DAC", "ab8500_0p",
  362. AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACHSR, 0),
  363. SND_SOC_DAPM_MIXER("HSL DAC Mute", AB8500_MUTECONF,
  364. AB8500_MUTECONF_MUTDACHSL, 1,
  365. NULL, 0),
  366. SND_SOC_DAPM_MIXER("HSR DAC Mute", AB8500_MUTECONF,
  367. AB8500_MUTECONF_MUTDACHSR, 1,
  368. NULL, 0),
  369. SND_SOC_DAPM_DAC("HSL DAC Driver", "ab8500_0p",
  370. AB8500_ANACONF3, AB8500_ANACONF3_ENDRVHSL, 0),
  371. SND_SOC_DAPM_DAC("HSR DAC Driver", "ab8500_0p",
  372. AB8500_ANACONF3, AB8500_ANACONF3_ENDRVHSR, 0),
  373. SND_SOC_DAPM_MIXER("HSL Mute",
  374. AB8500_MUTECONF, AB8500_MUTECONF_MUTHSL, 1,
  375. NULL, 0),
  376. SND_SOC_DAPM_MIXER("HSR Mute",
  377. AB8500_MUTECONF, AB8500_MUTECONF_MUTHSR, 1,
  378. NULL, 0),
  379. SND_SOC_DAPM_MIXER("HSL Enable",
  380. AB8500_ANACONF4, AB8500_ANACONF4_ENHSL, 0,
  381. NULL, 0),
  382. SND_SOC_DAPM_MIXER("HSR Enable",
  383. AB8500_ANACONF4, AB8500_ANACONF4_ENHSR, 0,
  384. NULL, 0),
  385. SND_SOC_DAPM_PGA("HSL Volume",
  386. SND_SOC_NOPM, 0, 0,
  387. NULL, 0),
  388. SND_SOC_DAPM_PGA("HSR Volume",
  389. SND_SOC_NOPM, 0, 0,
  390. NULL, 0),
  391. SND_SOC_DAPM_OUTPUT("Headset Left"),
  392. SND_SOC_DAPM_OUTPUT("Headset Right"),
  393. /* LineOut path */
  394. SND_SOC_DAPM_MUX("LineOut Source",
  395. SND_SOC_NOPM, 0, 0, dapm_lineout_source),
  396. SND_SOC_DAPM_MIXER("LOL Disable HFL",
  397. AB8500_ANACONF4, AB8500_ANACONF4_ENHFL, 1,
  398. NULL, 0),
  399. SND_SOC_DAPM_MIXER("LOR Disable HFR",
  400. AB8500_ANACONF4, AB8500_ANACONF4_ENHFR, 1,
  401. NULL, 0),
  402. SND_SOC_DAPM_MIXER("LOL Enable",
  403. AB8500_ANACONF5, AB8500_ANACONF5_ENLOL, 0,
  404. NULL, 0),
  405. SND_SOC_DAPM_MIXER("LOR Enable",
  406. AB8500_ANACONF5, AB8500_ANACONF5_ENLOR, 0,
  407. NULL, 0),
  408. SND_SOC_DAPM_OUTPUT("LineOut Left"),
  409. SND_SOC_DAPM_OUTPUT("LineOut Right"),
  410. /* Earpiece path */
  411. SND_SOC_DAPM_MUX("Earpiece or LineOut Mono Source",
  412. SND_SOC_NOPM, 0, 0, &dapm_ear_lineout_source),
  413. SND_SOC_DAPM_MIXER("EAR DAC",
  414. AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACEAR, 0,
  415. NULL, 0),
  416. SND_SOC_DAPM_MIXER("EAR Mute",
  417. AB8500_MUTECONF, AB8500_MUTECONF_MUTEAR, 1,
  418. NULL, 0),
  419. SND_SOC_DAPM_MIXER("EAR Enable",
  420. AB8500_ANACONF4, AB8500_ANACONF4_ENEAR, 0,
  421. NULL, 0),
  422. SND_SOC_DAPM_OUTPUT("Earpiece"),
  423. /* Handsfree path */
  424. SND_SOC_DAPM_MIXER("DA3 Channel Volume",
  425. AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA3, 0,
  426. NULL, 0),
  427. SND_SOC_DAPM_MIXER("DA4 Channel Volume",
  428. AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA4, 0,
  429. NULL, 0),
  430. SND_SOC_DAPM_MUX("Speaker Left Source",
  431. SND_SOC_NOPM, 0, 0, dapm_HFl_select),
  432. SND_SOC_DAPM_MUX("Speaker Right Source",
  433. SND_SOC_NOPM, 0, 0, dapm_HFr_select),
  434. SND_SOC_DAPM_MIXER("HFL DAC", AB8500_DAPATHCONF,
  435. AB8500_DAPATHCONF_ENDACHFL, 0,
  436. NULL, 0),
  437. SND_SOC_DAPM_MIXER("HFR DAC",
  438. AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACHFR, 0,
  439. NULL, 0),
  440. SND_SOC_DAPM_MIXER("DA4 or ANC path to HfR",
  441. AB8500_DIGMULTCONF2, AB8500_DIGMULTCONF2_DATOHFREN, 0,
  442. NULL, 0),
  443. SND_SOC_DAPM_MIXER("DA3 or ANC path to HfL",
  444. AB8500_DIGMULTCONF2, AB8500_DIGMULTCONF2_DATOHFLEN, 0,
  445. NULL, 0),
  446. SND_SOC_DAPM_MIXER("HFL Enable",
  447. AB8500_ANACONF4, AB8500_ANACONF4_ENHFL, 0,
  448. NULL, 0),
  449. SND_SOC_DAPM_MIXER("HFR Enable",
  450. AB8500_ANACONF4, AB8500_ANACONF4_ENHFR, 0,
  451. NULL, 0),
  452. SND_SOC_DAPM_OUTPUT("Speaker Left"),
  453. SND_SOC_DAPM_OUTPUT("Speaker Right"),
  454. /* Vibrator path */
  455. SND_SOC_DAPM_INPUT("PWMGEN1"),
  456. SND_SOC_DAPM_INPUT("PWMGEN2"),
  457. SND_SOC_DAPM_MIXER("DA5 Channel Volume",
  458. AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA5, 0,
  459. NULL, 0),
  460. SND_SOC_DAPM_MIXER("DA6 Channel Volume",
  461. AB8500_DAPATHENA, AB8500_DAPATHENA_ENDA6, 0,
  462. NULL, 0),
  463. SND_SOC_DAPM_MIXER("VIB1 DAC",
  464. AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACVIB1, 0,
  465. NULL, 0),
  466. SND_SOC_DAPM_MIXER("VIB2 DAC",
  467. AB8500_DAPATHCONF, AB8500_DAPATHCONF_ENDACVIB2, 0,
  468. NULL, 0),
  469. SND_SOC_DAPM_MUX("Vibra 1 Controller",
  470. SND_SOC_NOPM, 0, 0, dapm_pwm2vib1),
  471. SND_SOC_DAPM_MUX("Vibra 2 Controller",
  472. SND_SOC_NOPM, 0, 0, dapm_pwm2vib2),
  473. SND_SOC_DAPM_MIXER("VIB1 Enable",
  474. AB8500_ANACONF4, AB8500_ANACONF4_ENVIB1, 0,
  475. NULL, 0),
  476. SND_SOC_DAPM_MIXER("VIB2 Enable",
  477. AB8500_ANACONF4, AB8500_ANACONF4_ENVIB2, 0,
  478. NULL, 0),
  479. SND_SOC_DAPM_OUTPUT("Vibra 1"),
  480. SND_SOC_DAPM_OUTPUT("Vibra 2"),
  481. /* Mic 1 */
  482. SND_SOC_DAPM_INPUT("Mic 1"),
  483. SND_SOC_DAPM_MUX("Mic 1a or 1b Select",
  484. SND_SOC_NOPM, 0, 0, dapm_mic1ab_mux),
  485. SND_SOC_DAPM_MIXER("MIC1 Mute",
  486. AB8500_ANACONF2, AB8500_ANACONF2_MUTMIC1, 1,
  487. NULL, 0),
  488. SND_SOC_DAPM_MIXER("MIC1A V-AMICx Enable",
  489. AB8500_ANACONF2, AB8500_ANACONF2_ENMIC1, 0,
  490. NULL, 0),
  491. SND_SOC_DAPM_MIXER("MIC1B V-AMICx Enable",
  492. AB8500_ANACONF2, AB8500_ANACONF2_ENMIC1, 0,
  493. NULL, 0),
  494. SND_SOC_DAPM_MIXER("MIC1 ADC",
  495. AB8500_ANACONF3, AB8500_ANACONF3_ENADCMIC, 0,
  496. NULL, 0),
  497. SND_SOC_DAPM_MUX("AD3 Source Select",
  498. SND_SOC_NOPM, 0, 0, dapm_ad3_select),
  499. SND_SOC_DAPM_MIXER("AD3 Channel Volume",
  500. SND_SOC_NOPM, 0, 0,
  501. NULL, 0),
  502. SND_SOC_DAPM_MIXER("AD3 Enable",
  503. AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD34, 0,
  504. NULL, 0),
  505. /* Mic 2 */
  506. SND_SOC_DAPM_INPUT("Mic 2"),
  507. SND_SOC_DAPM_MIXER("MIC2 Mute",
  508. AB8500_ANACONF2, AB8500_ANACONF2_MUTMIC2, 1,
  509. NULL, 0),
  510. SND_SOC_DAPM_MIXER("MIC2 V-AMICx Enable", AB8500_ANACONF2,
  511. AB8500_ANACONF2_ENMIC2, 0,
  512. NULL, 0),
  513. /* LineIn */
  514. SND_SOC_DAPM_INPUT("LineIn Left"),
  515. SND_SOC_DAPM_INPUT("LineIn Right"),
  516. SND_SOC_DAPM_MIXER("LINL Mute",
  517. AB8500_ANACONF2, AB8500_ANACONF2_MUTLINL, 1,
  518. NULL, 0),
  519. SND_SOC_DAPM_MIXER("LINR Mute",
  520. AB8500_ANACONF2, AB8500_ANACONF2_MUTLINR, 1,
  521. NULL, 0),
  522. SND_SOC_DAPM_MIXER("LINL Enable", AB8500_ANACONF2,
  523. AB8500_ANACONF2_ENLINL, 0,
  524. NULL, 0),
  525. SND_SOC_DAPM_MIXER("LINR Enable", AB8500_ANACONF2,
  526. AB8500_ANACONF2_ENLINR, 0,
  527. NULL, 0),
  528. /* LineIn Bypass path */
  529. SND_SOC_DAPM_MIXER("LINL to HSL Volume",
  530. SND_SOC_NOPM, 0, 0,
  531. NULL, 0),
  532. SND_SOC_DAPM_MIXER("LINR to HSR Volume",
  533. SND_SOC_NOPM, 0, 0,
  534. NULL, 0),
  535. /* LineIn, Mic 2 */
  536. SND_SOC_DAPM_MUX("Mic 2 or LINR Select",
  537. SND_SOC_NOPM, 0, 0, dapm_mic2lr_select),
  538. SND_SOC_DAPM_MIXER("LINL ADC", AB8500_ANACONF3,
  539. AB8500_ANACONF3_ENADCLINL, 0,
  540. NULL, 0),
  541. SND_SOC_DAPM_MIXER("LINR ADC", AB8500_ANACONF3,
  542. AB8500_ANACONF3_ENADCLINR, 0,
  543. NULL, 0),
  544. SND_SOC_DAPM_MUX("AD1 Source Select",
  545. SND_SOC_NOPM, 0, 0, dapm_ad1_select),
  546. SND_SOC_DAPM_MUX("AD2 Source Select",
  547. SND_SOC_NOPM, 0, 0, dapm_ad2_select),
  548. SND_SOC_DAPM_MIXER("AD1 Channel Volume",
  549. SND_SOC_NOPM, 0, 0,
  550. NULL, 0),
  551. SND_SOC_DAPM_MIXER("AD2 Channel Volume",
  552. SND_SOC_NOPM, 0, 0,
  553. NULL, 0),
  554. SND_SOC_DAPM_MIXER("AD12 Enable",
  555. AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD12, 0,
  556. NULL, 0),
  557. /* HD Capture path */
  558. SND_SOC_DAPM_MUX("AD5 Source Select",
  559. SND_SOC_NOPM, 0, 0, dapm_ad5_select),
  560. SND_SOC_DAPM_MUX("AD6 Source Select",
  561. SND_SOC_NOPM, 0, 0, dapm_ad6_select),
  562. SND_SOC_DAPM_MIXER("AD5 Channel Volume",
  563. SND_SOC_NOPM, 0, 0,
  564. NULL, 0),
  565. SND_SOC_DAPM_MIXER("AD6 Channel Volume",
  566. SND_SOC_NOPM, 0, 0,
  567. NULL, 0),
  568. SND_SOC_DAPM_MIXER("AD57 Enable",
  569. AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD5768, 0,
  570. NULL, 0),
  571. SND_SOC_DAPM_MIXER("AD68 Enable",
  572. AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD5768, 0,
  573. NULL, 0),
  574. /* Digital Microphone path */
  575. SND_SOC_DAPM_INPUT("DMic 1"),
  576. SND_SOC_DAPM_INPUT("DMic 2"),
  577. SND_SOC_DAPM_INPUT("DMic 3"),
  578. SND_SOC_DAPM_INPUT("DMic 4"),
  579. SND_SOC_DAPM_INPUT("DMic 5"),
  580. SND_SOC_DAPM_INPUT("DMic 6"),
  581. SND_SOC_DAPM_MIXER("DMIC1",
  582. AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC1, 0,
  583. NULL, 0),
  584. SND_SOC_DAPM_MIXER("DMIC2",
  585. AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC2, 0,
  586. NULL, 0),
  587. SND_SOC_DAPM_MIXER("DMIC3",
  588. AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC3, 0,
  589. NULL, 0),
  590. SND_SOC_DAPM_MIXER("DMIC4",
  591. AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC4, 0,
  592. NULL, 0),
  593. SND_SOC_DAPM_MIXER("DMIC5",
  594. AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC5, 0,
  595. NULL, 0),
  596. SND_SOC_DAPM_MIXER("DMIC6",
  597. AB8500_DIGMICCONF, AB8500_DIGMICCONF_ENDMIC6, 0,
  598. NULL, 0),
  599. SND_SOC_DAPM_MIXER("AD4 Channel Volume",
  600. SND_SOC_NOPM, 0, 0,
  601. NULL, 0),
  602. SND_SOC_DAPM_MIXER("AD4 Enable",
  603. AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD34,
  604. 0, NULL, 0),
  605. /* Acoustical Noise Cancellation path */
  606. SND_SOC_DAPM_INPUT("ANC Configure Input"),
  607. SND_SOC_DAPM_OUTPUT("ANC Configure Output"),
  608. SND_SOC_DAPM_MUX("ANC Source",
  609. SND_SOC_NOPM, 0, 0,
  610. dapm_anc_in_select),
  611. SND_SOC_DAPM_SWITCH("ANC",
  612. SND_SOC_NOPM, 0, 0,
  613. dapm_anc_enable),
  614. SND_SOC_DAPM_SWITCH("ANC to Earpiece",
  615. SND_SOC_NOPM, 0, 0,
  616. dapm_anc_ear_mute),
  617. /* Sidetone Filter path */
  618. SND_SOC_DAPM_MUX("Sidetone Left Source",
  619. SND_SOC_NOPM, 0, 0,
  620. dapm_stfir1_in_select),
  621. SND_SOC_DAPM_MUX("Sidetone Right Source",
  622. SND_SOC_NOPM, 0, 0,
  623. dapm_stfir2_in_select),
  624. SND_SOC_DAPM_MIXER("STFIR1 Control",
  625. SND_SOC_NOPM, 0, 0,
  626. NULL, 0),
  627. SND_SOC_DAPM_MIXER("STFIR2 Control",
  628. SND_SOC_NOPM, 0, 0,
  629. NULL, 0),
  630. SND_SOC_DAPM_MIXER("STFIR1 Volume",
  631. SND_SOC_NOPM, 0, 0,
  632. NULL, 0),
  633. SND_SOC_DAPM_MIXER("STFIR2 Volume",
  634. SND_SOC_NOPM, 0, 0,
  635. NULL, 0),
  636. };
  637. /*
  638. * DAPM-routes
  639. */
  640. static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
  641. /* Power AB8500 audio-block when AD/DA is active */
  642. {"Main Supply", NULL, "V-AUD"},
  643. {"Main Supply", NULL, "audioclk"},
  644. {"Main Supply", NULL, "Audio Power"},
  645. {"Main Supply", NULL, "Audio Analog Power"},
  646. {"DAC", NULL, "ab8500_0p"},
  647. {"DAC", NULL, "Main Supply"},
  648. {"ADC", NULL, "ab8500_0c"},
  649. {"ADC", NULL, "Main Supply"},
  650. /* ANC Configure */
  651. {"ANC Configure Input", NULL, "Main Supply"},
  652. {"ANC Configure Output", NULL, "ANC Configure Input"},
  653. /* AD/DA */
  654. {"ADC", NULL, "ADC Input"},
  655. {"DAC Output", NULL, "DAC"},
  656. /* Powerup charge pump if DA1/2 is in use */
  657. {"DA_IN1", NULL, "ab8500_0p"},
  658. {"DA_IN1", NULL, "Charge Pump"},
  659. {"DA_IN2", NULL, "ab8500_0p"},
  660. {"DA_IN2", NULL, "Charge Pump"},
  661. /* Headset path */
  662. {"DA1 Enable", NULL, "DA_IN1"},
  663. {"DA2 Enable", NULL, "DA_IN2"},
  664. {"HSL Digital Volume", NULL, "DA1 Enable"},
  665. {"HSR Digital Volume", NULL, "DA2 Enable"},
  666. {"HSL DAC", NULL, "HSL Digital Volume"},
  667. {"HSR DAC", NULL, "HSR Digital Volume"},
  668. {"HSL DAC Mute", NULL, "HSL DAC"},
  669. {"HSR DAC Mute", NULL, "HSR DAC"},
  670. {"HSL DAC Driver", NULL, "HSL DAC Mute"},
  671. {"HSR DAC Driver", NULL, "HSR DAC Mute"},
  672. {"HSL Mute", NULL, "HSL DAC Driver"},
  673. {"HSR Mute", NULL, "HSR DAC Driver"},
  674. {"HSL Enable", NULL, "HSL Mute"},
  675. {"HSR Enable", NULL, "HSR Mute"},
  676. {"HSL Volume", NULL, "HSL Enable"},
  677. {"HSR Volume", NULL, "HSR Enable"},
  678. {"Headset Left", NULL, "HSL Volume"},
  679. {"Headset Right", NULL, "HSR Volume"},
  680. /* HF or LineOut path */
  681. {"DA_IN3", NULL, "ab8500_0p"},
  682. {"DA3 Channel Volume", NULL, "DA_IN3"},
  683. {"DA_IN4", NULL, "ab8500_0p"},
  684. {"DA4 Channel Volume", NULL, "DA_IN4"},
  685. {"Speaker Left Source", "Audio Path", "DA3 Channel Volume"},
  686. {"Speaker Right Source", "Audio Path", "DA4 Channel Volume"},
  687. {"DA3 or ANC path to HfL", NULL, "Speaker Left Source"},
  688. {"DA4 or ANC path to HfR", NULL, "Speaker Right Source"},
  689. /* HF path */
  690. {"HFL DAC", NULL, "DA3 or ANC path to HfL"},
  691. {"HFR DAC", NULL, "DA4 or ANC path to HfR"},
  692. {"HFL Enable", NULL, "HFL DAC"},
  693. {"HFR Enable", NULL, "HFR DAC"},
  694. {"Speaker Left", NULL, "HFL Enable"},
  695. {"Speaker Right", NULL, "HFR Enable"},
  696. /* Earpiece path */
  697. {"Earpiece or LineOut Mono Source", "Headset Left",
  698. "HSL Digital Volume"},
  699. {"Earpiece or LineOut Mono Source", "Speaker Left",
  700. "DA3 or ANC path to HfL"},
  701. {"EAR DAC", NULL, "Earpiece or LineOut Mono Source"},
  702. {"EAR Mute", NULL, "EAR DAC"},
  703. {"EAR Enable", NULL, "EAR Mute"},
  704. {"Earpiece", NULL, "EAR Enable"},
  705. /* LineOut path stereo */
  706. {"LineOut Source", "Stereo Path", "HSL DAC Driver"},
  707. {"LineOut Source", "Stereo Path", "HSR DAC Driver"},
  708. /* LineOut path mono */
  709. {"LineOut Source", "Mono Path", "EAR DAC"},
  710. /* LineOut path */
  711. {"LOL Disable HFL", NULL, "LineOut Source"},
  712. {"LOR Disable HFR", NULL, "LineOut Source"},
  713. {"LOL Enable", NULL, "LOL Disable HFL"},
  714. {"LOR Enable", NULL, "LOR Disable HFR"},
  715. {"LineOut Left", NULL, "LOL Enable"},
  716. {"LineOut Right", NULL, "LOR Enable"},
  717. /* Vibrator path */
  718. {"DA_IN5", NULL, "ab8500_0p"},
  719. {"DA5 Channel Volume", NULL, "DA_IN5"},
  720. {"DA_IN6", NULL, "ab8500_0p"},
  721. {"DA6 Channel Volume", NULL, "DA_IN6"},
  722. {"VIB1 DAC", NULL, "DA5 Channel Volume"},
  723. {"VIB2 DAC", NULL, "DA6 Channel Volume"},
  724. {"Vibra 1 Controller", "Audio Path", "VIB1 DAC"},
  725. {"Vibra 2 Controller", "Audio Path", "VIB2 DAC"},
  726. {"Vibra 1 Controller", "PWM Generator", "PWMGEN1"},
  727. {"Vibra 2 Controller", "PWM Generator", "PWMGEN2"},
  728. {"VIB1 Enable", NULL, "Vibra 1 Controller"},
  729. {"VIB2 Enable", NULL, "Vibra 2 Controller"},
  730. {"Vibra 1", NULL, "VIB1 Enable"},
  731. {"Vibra 2", NULL, "VIB2 Enable"},
  732. /* Mic 2 */
  733. {"MIC2 V-AMICx Enable", NULL, "Mic 2"},
  734. /* LineIn */
  735. {"LINL Mute", NULL, "LineIn Left"},
  736. {"LINR Mute", NULL, "LineIn Right"},
  737. {"LINL Enable", NULL, "LINL Mute"},
  738. {"LINR Enable", NULL, "LINR Mute"},
  739. /* LineIn, Mic 2 */
  740. {"Mic 2 or LINR Select", "LineIn Right", "LINR Enable"},
  741. {"Mic 2 or LINR Select", "Mic 2", "MIC2 V-AMICx Enable"},
  742. {"LINL ADC", NULL, "LINL Enable"},
  743. {"LINR ADC", NULL, "Mic 2 or LINR Select"},
  744. {"AD1 Source Select", "LineIn Left", "LINL ADC"},
  745. {"AD2 Source Select", "LineIn Right", "LINR ADC"},
  746. {"AD1 Channel Volume", NULL, "AD1 Source Select"},
  747. {"AD2 Channel Volume", NULL, "AD2 Source Select"},
  748. {"AD12 Enable", NULL, "AD1 Channel Volume"},
  749. {"AD12 Enable", NULL, "AD2 Channel Volume"},
  750. {"AD_OUT1", NULL, "ab8500_0c"},
  751. {"AD_OUT1", NULL, "AD12 Enable"},
  752. {"AD_OUT2", NULL, "ab8500_0c"},
  753. {"AD_OUT2", NULL, "AD12 Enable"},
  754. /* Mic 1 */
  755. {"MIC1 Mute", NULL, "Mic 1"},
  756. {"MIC1A V-AMICx Enable", NULL, "MIC1 Mute"},
  757. {"MIC1B V-AMICx Enable", NULL, "MIC1 Mute"},
  758. {"Mic 1a or 1b Select", "Mic 1a", "MIC1A V-AMICx Enable"},
  759. {"Mic 1a or 1b Select", "Mic 1b", "MIC1B V-AMICx Enable"},
  760. {"MIC1 ADC", NULL, "Mic 1a or 1b Select"},
  761. {"AD3 Source Select", "Mic 1", "MIC1 ADC"},
  762. {"AD3 Channel Volume", NULL, "AD3 Source Select"},
  763. {"AD3 Enable", NULL, "AD3 Channel Volume"},
  764. {"AD_OUT3", NULL, "ab8500_0c"},
  765. {"AD_OUT3", NULL, "AD3 Enable"},
  766. /* HD Capture path */
  767. {"AD5 Source Select", "Mic 2", "LINR ADC"},
  768. {"AD6 Source Select", "Mic 1", "MIC1 ADC"},
  769. {"AD5 Channel Volume", NULL, "AD5 Source Select"},
  770. {"AD6 Channel Volume", NULL, "AD6 Source Select"},
  771. {"AD57 Enable", NULL, "AD5 Channel Volume"},
  772. {"AD68 Enable", NULL, "AD6 Channel Volume"},
  773. {"AD_OUT57", NULL, "ab8500_0c"},
  774. {"AD_OUT57", NULL, "AD57 Enable"},
  775. {"AD_OUT68", NULL, "ab8500_0c"},
  776. {"AD_OUT68", NULL, "AD68 Enable"},
  777. /* Digital Microphone path */
  778. {"DMic 1", NULL, "V-DMIC"},
  779. {"DMic 2", NULL, "V-DMIC"},
  780. {"DMic 3", NULL, "V-DMIC"},
  781. {"DMic 4", NULL, "V-DMIC"},
  782. {"DMic 5", NULL, "V-DMIC"},
  783. {"DMic 6", NULL, "V-DMIC"},
  784. {"AD1 Source Select", NULL, "DMic 1"},
  785. {"AD2 Source Select", NULL, "DMic 2"},
  786. {"AD3 Source Select", NULL, "DMic 3"},
  787. {"AD5 Source Select", NULL, "DMic 5"},
  788. {"AD6 Source Select", NULL, "DMic 6"},
  789. {"AD4 Channel Volume", NULL, "DMic 4"},
  790. {"AD4 Enable", NULL, "AD4 Channel Volume"},
  791. {"AD_OUT4", NULL, "ab8500_0c"},
  792. {"AD_OUT4", NULL, "AD4 Enable"},
  793. /* LineIn Bypass path */
  794. {"LINL to HSL Volume", NULL, "LINL Enable"},
  795. {"LINR to HSR Volume", NULL, "LINR Enable"},
  796. {"HSL DAC Driver", NULL, "LINL to HSL Volume"},
  797. {"HSR DAC Driver", NULL, "LINR to HSR Volume"},
  798. /* ANC path (Acoustic Noise Cancellation) */
  799. {"ANC Source", "Mic 2 / DMic 5", "AD5 Channel Volume"},
  800. {"ANC Source", "Mic 1 / DMic 6", "AD6 Channel Volume"},
  801. {"ANC", "Switch", "ANC Source"},
  802. {"Speaker Left Source", "ANC", "ANC"},
  803. {"Speaker Right Source", "ANC", "ANC"},
  804. {"ANC to Earpiece", "Switch", "ANC"},
  805. {"HSL Digital Volume", NULL, "ANC to Earpiece"},
  806. /* Sidetone Filter path */
  807. {"Sidetone Left Source", "LineIn Left", "AD12 Enable"},
  808. {"Sidetone Left Source", "LineIn Right", "AD12 Enable"},
  809. {"Sidetone Left Source", "Mic 1", "AD3 Enable"},
  810. {"Sidetone Left Source", "Headset Left", "DA_IN1"},
  811. {"Sidetone Right Source", "LineIn Right", "AD12 Enable"},
  812. {"Sidetone Right Source", "Mic 1", "AD3 Enable"},
  813. {"Sidetone Right Source", "DMic 4", "AD4 Enable"},
  814. {"Sidetone Right Source", "Headset Right", "DA_IN2"},
  815. {"STFIR1 Control", NULL, "Sidetone Left Source"},
  816. {"STFIR2 Control", NULL, "Sidetone Right Source"},
  817. {"STFIR1 Volume", NULL, "STFIR1 Control"},
  818. {"STFIR2 Volume", NULL, "STFIR2 Control"},
  819. {"DA1 Enable", NULL, "STFIR1 Volume"},
  820. {"DA2 Enable", NULL, "STFIR2 Volume"},
  821. };
  822. static const struct snd_soc_dapm_route ab8500_dapm_routes_mic1a_vamicx[] = {
  823. {"MIC1A V-AMICx Enable", NULL, "V-AMIC1"},
  824. {"MIC1A V-AMICx Enable", NULL, "V-AMIC2"},
  825. };
  826. static const struct snd_soc_dapm_route ab8500_dapm_routes_mic1b_vamicx[] = {
  827. {"MIC1B V-AMICx Enable", NULL, "V-AMIC1"},
  828. {"MIC1B V-AMICx Enable", NULL, "V-AMIC2"},
  829. };
  830. static const struct snd_soc_dapm_route ab8500_dapm_routes_mic2_vamicx[] = {
  831. {"MIC2 V-AMICx Enable", NULL, "V-AMIC1"},
  832. {"MIC2 V-AMICx Enable", NULL, "V-AMIC2"},
  833. };
  834. /* ANC FIR-coefficients configuration sequence */
  835. static void anc_fir(struct snd_soc_codec *codec,
  836. unsigned int bnk, unsigned int par, unsigned int val)
  837. {
  838. if (par == 0 && bnk == 0)
  839. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  840. BIT(AB8500_ANCCONF1_ANCFIRUPDATE),
  841. BIT(AB8500_ANCCONF1_ANCFIRUPDATE));
  842. snd_soc_write(codec, AB8500_ANCCONF5, val >> 8 & 0xff);
  843. snd_soc_write(codec, AB8500_ANCCONF6, val & 0xff);
  844. if (par == AB8500_ANC_FIR_COEFFS - 1 && bnk == 1)
  845. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  846. BIT(AB8500_ANCCONF1_ANCFIRUPDATE), 0);
  847. }
  848. /* ANC IIR-coefficients configuration sequence */
  849. static void anc_iir(struct snd_soc_codec *codec, unsigned int bnk,
  850. unsigned int par, unsigned int val)
  851. {
  852. if (par == 0) {
  853. if (bnk == 0) {
  854. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  855. BIT(AB8500_ANCCONF1_ANCIIRINIT),
  856. BIT(AB8500_ANCCONF1_ANCIIRINIT));
  857. usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY);
  858. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  859. BIT(AB8500_ANCCONF1_ANCIIRINIT), 0);
  860. usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY);
  861. } else {
  862. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  863. BIT(AB8500_ANCCONF1_ANCIIRUPDATE),
  864. BIT(AB8500_ANCCONF1_ANCIIRUPDATE));
  865. }
  866. } else if (par > 3) {
  867. snd_soc_write(codec, AB8500_ANCCONF7, 0);
  868. snd_soc_write(codec, AB8500_ANCCONF8, val >> 16 & 0xff);
  869. }
  870. snd_soc_write(codec, AB8500_ANCCONF7, val >> 8 & 0xff);
  871. snd_soc_write(codec, AB8500_ANCCONF8, val & 0xff);
  872. if (par == AB8500_ANC_IIR_COEFFS - 1 && bnk == 1)
  873. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  874. BIT(AB8500_ANCCONF1_ANCIIRUPDATE), 0);
  875. }
  876. /* ANC IIR-/FIR-coefficients configuration sequence */
  877. static void anc_configure(struct snd_soc_codec *codec,
  878. bool apply_fir, bool apply_iir)
  879. {
  880. struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
  881. unsigned int bnk, par, val;
  882. dev_dbg(codec->dev, "%s: Enter.\n", __func__);
  883. if (apply_fir)
  884. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  885. BIT(AB8500_ANCCONF1_ENANC), 0);
  886. snd_soc_update_bits(codec, AB8500_ANCCONF1,
  887. BIT(AB8500_ANCCONF1_ENANC), BIT(AB8500_ANCCONF1_ENANC));
  888. if (apply_fir)
  889. for (bnk = 0; bnk < AB8500_NR_OF_ANC_COEFF_BANKS; bnk++)
  890. for (par = 0; par < AB8500_ANC_FIR_COEFFS; par++) {
  891. val = snd_soc_read(codec,
  892. drvdata->anc_fir_values[par]);
  893. anc_fir(codec, bnk, par, val);
  894. }
  895. if (apply_iir)
  896. for (bnk = 0; bnk < AB8500_NR_OF_ANC_COEFF_BANKS; bnk++)
  897. for (par = 0; par < AB8500_ANC_IIR_COEFFS; par++) {
  898. val = snd_soc_read(codec,
  899. drvdata->anc_iir_values[par]);
  900. anc_iir(codec, bnk, par, val);
  901. }
  902. dev_dbg(codec->dev, "%s: Exit.\n", __func__);
  903. }
  904. /*
  905. * Control-events
  906. */
  907. static int sid_status_control_get(struct snd_kcontrol *kcontrol,
  908. struct snd_ctl_elem_value *ucontrol)
  909. {
  910. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  911. struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
  912. mutex_lock(&drvdata->ctrl_lock);
  913. ucontrol->value.enumerated.item[0] = drvdata->sid_status;
  914. mutex_unlock(&drvdata->ctrl_lock);
  915. return 0;
  916. }
  917. /* Write sidetone FIR-coefficients configuration sequence */
  918. static int sid_status_control_put(struct snd_kcontrol *kcontrol,
  919. struct snd_ctl_elem_value *ucontrol)
  920. {
  921. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  922. struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
  923. unsigned int param, sidconf, val;
  924. int status = 1;
  925. dev_dbg(codec->dev, "%s: Enter\n", __func__);
  926. if (ucontrol->value.enumerated.item[0] != SID_APPLY_FIR) {
  927. dev_err(codec->dev,
  928. "%s: ERROR: This control supports '%s' only!\n",
  929. __func__, enum_sid_state[SID_APPLY_FIR]);
  930. return -EIO;
  931. }
  932. mutex_lock(&drvdata->ctrl_lock);
  933. sidconf = snd_soc_read(codec, AB8500_SIDFIRCONF);
  934. if (((sidconf & BIT(AB8500_SIDFIRCONF_FIRSIDBUSY)) != 0)) {
  935. if ((sidconf & BIT(AB8500_SIDFIRCONF_ENFIRSIDS)) == 0) {
  936. dev_err(codec->dev, "%s: Sidetone busy while off!\n",
  937. __func__);
  938. status = -EPERM;
  939. } else {
  940. status = -EBUSY;
  941. }
  942. goto out;
  943. }
  944. snd_soc_write(codec, AB8500_SIDFIRADR, 0);
  945. for (param = 0; param < AB8500_SID_FIR_COEFFS; param++) {
  946. val = snd_soc_read(codec, drvdata->sid_fir_values[param]);
  947. snd_soc_write(codec, AB8500_SIDFIRCOEF1, val >> 8 & 0xff);
  948. snd_soc_write(codec, AB8500_SIDFIRCOEF2, val & 0xff);
  949. }
  950. snd_soc_update_bits(codec, AB8500_SIDFIRADR,
  951. BIT(AB8500_SIDFIRADR_FIRSIDSET),
  952. BIT(AB8500_SIDFIRADR_FIRSIDSET));
  953. snd_soc_update_bits(codec, AB8500_SIDFIRADR,
  954. BIT(AB8500_SIDFIRADR_FIRSIDSET), 0);
  955. drvdata->sid_status = SID_FIR_CONFIGURED;
  956. out:
  957. mutex_unlock(&drvdata->ctrl_lock);
  958. dev_dbg(codec->dev, "%s: Exit\n", __func__);
  959. return status;
  960. }
  961. static int anc_status_control_get(struct snd_kcontrol *kcontrol,
  962. struct snd_ctl_elem_value *ucontrol)
  963. {
  964. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  965. struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
  966. mutex_lock(&drvdata->ctrl_lock);
  967. ucontrol->value.enumerated.item[0] = drvdata->anc_status;
  968. mutex_unlock(&drvdata->ctrl_lock);
  969. return 0;
  970. }
  971. static int anc_status_control_put(struct snd_kcontrol *kcontrol,
  972. struct snd_ctl_elem_value *ucontrol)
  973. {
  974. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  975. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  976. struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(codec->dev);
  977. struct device *dev = codec->dev;
  978. bool apply_fir, apply_iir;
  979. unsigned int req;
  980. int status;
  981. dev_dbg(dev, "%s: Enter.\n", __func__);
  982. mutex_lock(&drvdata->ctrl_lock);
  983. req = ucontrol->value.enumerated.item[0];
  984. if (req >= ARRAY_SIZE(enum_anc_state)) {
  985. status = -EINVAL;
  986. goto cleanup;
  987. }
  988. if (req != ANC_APPLY_FIR_IIR && req != ANC_APPLY_FIR &&
  989. req != ANC_APPLY_IIR) {
  990. dev_err(dev, "%s: ERROR: Unsupported status to set '%s'!\n",
  991. __func__, enum_anc_state[req]);
  992. status = -EINVAL;
  993. goto cleanup;
  994. }
  995. apply_fir = req == ANC_APPLY_FIR || req == ANC_APPLY_FIR_IIR;
  996. apply_iir = req == ANC_APPLY_IIR || req == ANC_APPLY_FIR_IIR;
  997. status = snd_soc_dapm_force_enable_pin(dapm, "ANC Configure Input");
  998. if (status < 0) {
  999. dev_err(dev,
  1000. "%s: ERROR: Failed to enable power (status = %d)!\n",
  1001. __func__, status);
  1002. goto cleanup;
  1003. }
  1004. snd_soc_dapm_sync(dapm);
  1005. anc_configure(codec, apply_fir, apply_iir);
  1006. if (apply_fir) {
  1007. if (drvdata->anc_status == ANC_IIR_CONFIGURED)
  1008. drvdata->anc_status = ANC_FIR_IIR_CONFIGURED;
  1009. else if (drvdata->anc_status != ANC_FIR_IIR_CONFIGURED)
  1010. drvdata->anc_status = ANC_FIR_CONFIGURED;
  1011. }
  1012. if (apply_iir) {
  1013. if (drvdata->anc_status == ANC_FIR_CONFIGURED)
  1014. drvdata->anc_status = ANC_FIR_IIR_CONFIGURED;
  1015. else if (drvdata->anc_status != ANC_FIR_IIR_CONFIGURED)
  1016. drvdata->anc_status = ANC_IIR_CONFIGURED;
  1017. }
  1018. status = snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
  1019. snd_soc_dapm_sync(dapm);
  1020. cleanup:
  1021. mutex_unlock(&drvdata->ctrl_lock);
  1022. if (status < 0)
  1023. dev_err(dev, "%s: Unable to configure ANC! (status = %d)\n",
  1024. __func__, status);
  1025. dev_dbg(dev, "%s: Exit.\n", __func__);
  1026. return (status < 0) ? status : 1;
  1027. }
  1028. static int filter_control_info(struct snd_kcontrol *kcontrol,
  1029. struct snd_ctl_elem_info *uinfo)
  1030. {
  1031. struct filter_control *fc =
  1032. (struct filter_control *)kcontrol->private_value;
  1033. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1034. uinfo->count = fc->count;
  1035. uinfo->value.integer.min = fc->min;
  1036. uinfo->value.integer.max = fc->max;
  1037. return 0;
  1038. }
  1039. static int filter_control_get(struct snd_kcontrol *kcontrol,
  1040. struct snd_ctl_elem_value *ucontrol)
  1041. {
  1042. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1043. struct ab8500_codec_drvdata *drvdata = snd_soc_codec_get_drvdata(codec);
  1044. struct filter_control *fc =
  1045. (struct filter_control *)kcontrol->private_value;
  1046. unsigned int i;
  1047. mutex_lock(&drvdata->ctrl_lock);
  1048. for (i = 0; i < fc->count; i++)
  1049. ucontrol->value.integer.value[i] = fc->value[i];
  1050. mutex_unlock(&drvdata->ctrl_lock);
  1051. return 0;
  1052. }
  1053. static int filter_control_put(struct snd_kcontrol *kcontrol,
  1054. struct snd_ctl_elem_value *ucontrol)
  1055. {
  1056. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1057. struct ab8500_codec_drvdata *drvdata = snd_soc_codec_get_drvdata(codec);
  1058. struct filter_control *fc =
  1059. (struct filter_control *)kcontrol->private_value;
  1060. unsigned int i;
  1061. mutex_lock(&drvdata->ctrl_lock);
  1062. for (i = 0; i < fc->count; i++)
  1063. fc->value[i] = ucontrol->value.integer.value[i];
  1064. mutex_unlock(&drvdata->ctrl_lock);
  1065. return 0;
  1066. }
  1067. /*
  1068. * Controls - Non-DAPM ASoC
  1069. */
  1070. static DECLARE_TLV_DB_SCALE(adx_dig_gain_tlv, -3200, 100, 1);
  1071. /* -32dB = Mute */
  1072. static DECLARE_TLV_DB_SCALE(dax_dig_gain_tlv, -6300, 100, 1);
  1073. /* -63dB = Mute */
  1074. static DECLARE_TLV_DB_SCALE(hs_ear_dig_gain_tlv, -100, 100, 1);
  1075. /* -1dB = Mute */
  1076. static const DECLARE_TLV_DB_RANGE(hs_gain_tlv,
  1077. 0, 3, TLV_DB_SCALE_ITEM(-3200, 400, 0),
  1078. 4, 15, TLV_DB_SCALE_ITEM(-1800, 200, 0)
  1079. );
  1080. static DECLARE_TLV_DB_SCALE(mic_gain_tlv, 0, 100, 0);
  1081. static DECLARE_TLV_DB_SCALE(lin_gain_tlv, -1000, 200, 0);
  1082. static DECLARE_TLV_DB_SCALE(lin2hs_gain_tlv, -3800, 200, 1);
  1083. /* -38dB = Mute */
  1084. static const char * const enum_hsfadspeed[] = {"2ms", "0.5ms", "10.6ms",
  1085. "5ms"};
  1086. static SOC_ENUM_SINGLE_DECL(soc_enum_hsfadspeed,
  1087. AB8500_DIGMICCONF, AB8500_DIGMICCONF_HSFADSPEED, enum_hsfadspeed);
  1088. static const char * const enum_envdetthre[] = {
  1089. "250mV", "300mV", "350mV", "400mV",
  1090. "450mV", "500mV", "550mV", "600mV",
  1091. "650mV", "700mV", "750mV", "800mV",
  1092. "850mV", "900mV", "950mV", "1.00V" };
  1093. static SOC_ENUM_SINGLE_DECL(soc_enum_envdeththre,
  1094. AB8500_ENVCPCONF, AB8500_ENVCPCONF_ENVDETHTHRE, enum_envdetthre);
  1095. static SOC_ENUM_SINGLE_DECL(soc_enum_envdetlthre,
  1096. AB8500_ENVCPCONF, AB8500_ENVCPCONF_ENVDETLTHRE, enum_envdetthre);
  1097. static const char * const enum_envdettime[] = {
  1098. "26.6us", "53.2us", "106us", "213us",
  1099. "426us", "851us", "1.70ms", "3.40ms",
  1100. "6.81ms", "13.6ms", "27.2ms", "54.5ms",
  1101. "109ms", "218ms", "436ms", "872ms" };
  1102. static SOC_ENUM_SINGLE_DECL(soc_enum_envdettime,
  1103. AB8500_SIGENVCONF, AB8500_SIGENVCONF_ENVDETTIME, enum_envdettime);
  1104. static const char * const enum_sinc31[] = {"Sinc 3", "Sinc 1"};
  1105. static SOC_ENUM_SINGLE_DECL(soc_enum_hsesinc, AB8500_HSLEARDIGGAIN,
  1106. AB8500_HSLEARDIGGAIN_HSSINC1, enum_sinc31);
  1107. static const char * const enum_fadespeed[] = {"1ms", "4ms", "8ms", "16ms"};
  1108. static SOC_ENUM_SINGLE_DECL(soc_enum_fadespeed, AB8500_HSRDIGGAIN,
  1109. AB8500_HSRDIGGAIN_FADESPEED, enum_fadespeed);
  1110. /* Earpiece */
  1111. static const char * const enum_lowpow[] = {"Normal", "Low Power"};
  1112. static SOC_ENUM_SINGLE_DECL(soc_enum_eardaclowpow, AB8500_ANACONF1,
  1113. AB8500_ANACONF1_EARDACLOWPOW, enum_lowpow);
  1114. static SOC_ENUM_SINGLE_DECL(soc_enum_eardrvlowpow, AB8500_ANACONF1,
  1115. AB8500_ANACONF1_EARDRVLOWPOW, enum_lowpow);
  1116. static const char * const enum_av_mode[] = {"Audio", "Voice"};
  1117. static SOC_ENUM_DOUBLE_DECL(soc_enum_ad12voice, AB8500_ADFILTCONF,
  1118. AB8500_ADFILTCONF_AD1VOICE, AB8500_ADFILTCONF_AD2VOICE, enum_av_mode);
  1119. static SOC_ENUM_DOUBLE_DECL(soc_enum_ad34voice, AB8500_ADFILTCONF,
  1120. AB8500_ADFILTCONF_AD3VOICE, AB8500_ADFILTCONF_AD4VOICE, enum_av_mode);
  1121. /* DA */
  1122. static SOC_ENUM_SINGLE_DECL(soc_enum_da12voice,
  1123. AB8500_DASLOTCONF1, AB8500_DASLOTCONF1_DA12VOICE,
  1124. enum_av_mode);
  1125. static SOC_ENUM_SINGLE_DECL(soc_enum_da34voice,
  1126. AB8500_DASLOTCONF3, AB8500_DASLOTCONF3_DA34VOICE,
  1127. enum_av_mode);
  1128. static SOC_ENUM_SINGLE_DECL(soc_enum_da56voice,
  1129. AB8500_DASLOTCONF5, AB8500_DASLOTCONF5_DA56VOICE,
  1130. enum_av_mode);
  1131. static const char * const enum_da2hslr[] = {"Sidetone", "Audio Path"};
  1132. static SOC_ENUM_DOUBLE_DECL(soc_enum_da2hslr, AB8500_DIGMULTCONF1,
  1133. AB8500_DIGMULTCONF1_DATOHSLEN,
  1134. AB8500_DIGMULTCONF1_DATOHSREN, enum_da2hslr);
  1135. static const char * const enum_sinc53[] = {"Sinc 5", "Sinc 3"};
  1136. static SOC_ENUM_DOUBLE_DECL(soc_enum_dmic12sinc, AB8500_DMICFILTCONF,
  1137. AB8500_DMICFILTCONF_DMIC1SINC3,
  1138. AB8500_DMICFILTCONF_DMIC2SINC3, enum_sinc53);
  1139. static SOC_ENUM_DOUBLE_DECL(soc_enum_dmic34sinc, AB8500_DMICFILTCONF,
  1140. AB8500_DMICFILTCONF_DMIC3SINC3,
  1141. AB8500_DMICFILTCONF_DMIC4SINC3, enum_sinc53);
  1142. static SOC_ENUM_DOUBLE_DECL(soc_enum_dmic56sinc, AB8500_DMICFILTCONF,
  1143. AB8500_DMICFILTCONF_DMIC5SINC3,
  1144. AB8500_DMICFILTCONF_DMIC6SINC3, enum_sinc53);
  1145. /* Digital interface - DA from slot mapping */
  1146. static const char * const enum_da_from_slot_map[] = {"SLOT0",
  1147. "SLOT1",
  1148. "SLOT2",
  1149. "SLOT3",
  1150. "SLOT4",
  1151. "SLOT5",
  1152. "SLOT6",
  1153. "SLOT7",
  1154. "SLOT8",
  1155. "SLOT9",
  1156. "SLOT10",
  1157. "SLOT11",
  1158. "SLOT12",
  1159. "SLOT13",
  1160. "SLOT14",
  1161. "SLOT15",
  1162. "SLOT16",
  1163. "SLOT17",
  1164. "SLOT18",
  1165. "SLOT19",
  1166. "SLOT20",
  1167. "SLOT21",
  1168. "SLOT22",
  1169. "SLOT23",
  1170. "SLOT24",
  1171. "SLOT25",
  1172. "SLOT26",
  1173. "SLOT27",
  1174. "SLOT28",
  1175. "SLOT29",
  1176. "SLOT30",
  1177. "SLOT31"};
  1178. static SOC_ENUM_SINGLE_DECL(soc_enum_da1slotmap,
  1179. AB8500_DASLOTCONF1, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1180. enum_da_from_slot_map);
  1181. static SOC_ENUM_SINGLE_DECL(soc_enum_da2slotmap,
  1182. AB8500_DASLOTCONF2, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1183. enum_da_from_slot_map);
  1184. static SOC_ENUM_SINGLE_DECL(soc_enum_da3slotmap,
  1185. AB8500_DASLOTCONF3, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1186. enum_da_from_slot_map);
  1187. static SOC_ENUM_SINGLE_DECL(soc_enum_da4slotmap,
  1188. AB8500_DASLOTCONF4, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1189. enum_da_from_slot_map);
  1190. static SOC_ENUM_SINGLE_DECL(soc_enum_da5slotmap,
  1191. AB8500_DASLOTCONF5, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1192. enum_da_from_slot_map);
  1193. static SOC_ENUM_SINGLE_DECL(soc_enum_da6slotmap,
  1194. AB8500_DASLOTCONF6, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1195. enum_da_from_slot_map);
  1196. static SOC_ENUM_SINGLE_DECL(soc_enum_da7slotmap,
  1197. AB8500_DASLOTCONF7, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1198. enum_da_from_slot_map);
  1199. static SOC_ENUM_SINGLE_DECL(soc_enum_da8slotmap,
  1200. AB8500_DASLOTCONF8, AB8500_DASLOTCONFX_SLTODAX_SHIFT,
  1201. enum_da_from_slot_map);
  1202. /* Digital interface - AD to slot mapping */
  1203. static const char * const enum_ad_to_slot_map[] = {"AD_OUT1",
  1204. "AD_OUT2",
  1205. "AD_OUT3",
  1206. "AD_OUT4",
  1207. "AD_OUT5",
  1208. "AD_OUT6",
  1209. "AD_OUT7",
  1210. "AD_OUT8",
  1211. "zeroes",
  1212. "zeroes",
  1213. "zeroes",
  1214. "zeroes",
  1215. "tristate",
  1216. "tristate",
  1217. "tristate",
  1218. "tristate"};
  1219. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot0map,
  1220. AB8500_ADSLOTSEL1, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1221. enum_ad_to_slot_map);
  1222. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot1map,
  1223. AB8500_ADSLOTSEL1, AB8500_ADSLOTSELX_ODD_SHIFT,
  1224. enum_ad_to_slot_map);
  1225. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot2map,
  1226. AB8500_ADSLOTSEL2, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1227. enum_ad_to_slot_map);
  1228. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot3map,
  1229. AB8500_ADSLOTSEL2, AB8500_ADSLOTSELX_ODD_SHIFT,
  1230. enum_ad_to_slot_map);
  1231. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot4map,
  1232. AB8500_ADSLOTSEL3, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1233. enum_ad_to_slot_map);
  1234. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot5map,
  1235. AB8500_ADSLOTSEL3, AB8500_ADSLOTSELX_ODD_SHIFT,
  1236. enum_ad_to_slot_map);
  1237. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot6map,
  1238. AB8500_ADSLOTSEL4, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1239. enum_ad_to_slot_map);
  1240. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot7map,
  1241. AB8500_ADSLOTSEL4, AB8500_ADSLOTSELX_ODD_SHIFT,
  1242. enum_ad_to_slot_map);
  1243. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot8map,
  1244. AB8500_ADSLOTSEL5, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1245. enum_ad_to_slot_map);
  1246. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot9map,
  1247. AB8500_ADSLOTSEL5, AB8500_ADSLOTSELX_ODD_SHIFT,
  1248. enum_ad_to_slot_map);
  1249. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot10map,
  1250. AB8500_ADSLOTSEL6, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1251. enum_ad_to_slot_map);
  1252. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot11map,
  1253. AB8500_ADSLOTSEL6, AB8500_ADSLOTSELX_ODD_SHIFT,
  1254. enum_ad_to_slot_map);
  1255. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot12map,
  1256. AB8500_ADSLOTSEL7, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1257. enum_ad_to_slot_map);
  1258. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot13map,
  1259. AB8500_ADSLOTSEL7, AB8500_ADSLOTSELX_ODD_SHIFT,
  1260. enum_ad_to_slot_map);
  1261. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot14map,
  1262. AB8500_ADSLOTSEL8, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1263. enum_ad_to_slot_map);
  1264. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot15map,
  1265. AB8500_ADSLOTSEL8, AB8500_ADSLOTSELX_ODD_SHIFT,
  1266. enum_ad_to_slot_map);
  1267. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot16map,
  1268. AB8500_ADSLOTSEL9, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1269. enum_ad_to_slot_map);
  1270. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot17map,
  1271. AB8500_ADSLOTSEL9, AB8500_ADSLOTSELX_ODD_SHIFT,
  1272. enum_ad_to_slot_map);
  1273. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot18map,
  1274. AB8500_ADSLOTSEL10, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1275. enum_ad_to_slot_map);
  1276. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot19map,
  1277. AB8500_ADSLOTSEL10, AB8500_ADSLOTSELX_ODD_SHIFT,
  1278. enum_ad_to_slot_map);
  1279. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot20map,
  1280. AB8500_ADSLOTSEL11, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1281. enum_ad_to_slot_map);
  1282. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot21map,
  1283. AB8500_ADSLOTSEL11, AB8500_ADSLOTSELX_ODD_SHIFT,
  1284. enum_ad_to_slot_map);
  1285. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot22map,
  1286. AB8500_ADSLOTSEL12, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1287. enum_ad_to_slot_map);
  1288. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot23map,
  1289. AB8500_ADSLOTSEL12, AB8500_ADSLOTSELX_ODD_SHIFT,
  1290. enum_ad_to_slot_map);
  1291. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot24map,
  1292. AB8500_ADSLOTSEL13, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1293. enum_ad_to_slot_map);
  1294. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot25map,
  1295. AB8500_ADSLOTSEL13, AB8500_ADSLOTSELX_ODD_SHIFT,
  1296. enum_ad_to_slot_map);
  1297. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot26map,
  1298. AB8500_ADSLOTSEL14, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1299. enum_ad_to_slot_map);
  1300. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot27map,
  1301. AB8500_ADSLOTSEL14, AB8500_ADSLOTSELX_ODD_SHIFT,
  1302. enum_ad_to_slot_map);
  1303. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot28map,
  1304. AB8500_ADSLOTSEL15, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1305. enum_ad_to_slot_map);
  1306. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot29map,
  1307. AB8500_ADSLOTSEL15, AB8500_ADSLOTSELX_ODD_SHIFT,
  1308. enum_ad_to_slot_map);
  1309. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot30map,
  1310. AB8500_ADSLOTSEL16, AB8500_ADSLOTSELX_EVEN_SHIFT,
  1311. enum_ad_to_slot_map);
  1312. static SOC_ENUM_SINGLE_DECL(soc_enum_adslot31map,
  1313. AB8500_ADSLOTSEL16, AB8500_ADSLOTSELX_ODD_SHIFT,
  1314. enum_ad_to_slot_map);
  1315. /* Digital interface - Burst mode */
  1316. static const char * const enum_mask[] = {"Unmasked", "Masked"};
  1317. static SOC_ENUM_SINGLE_DECL(soc_enum_bfifomask,
  1318. AB8500_FIFOCONF1, AB8500_FIFOCONF1_BFIFOMASK,
  1319. enum_mask);
  1320. static const char * const enum_bitclk0[] = {"19_2_MHz", "38_4_MHz"};
  1321. static SOC_ENUM_SINGLE_DECL(soc_enum_bfifo19m2,
  1322. AB8500_FIFOCONF1, AB8500_FIFOCONF1_BFIFO19M2,
  1323. enum_bitclk0);
  1324. static const char * const enum_slavemaster[] = {"Slave", "Master"};
  1325. static SOC_ENUM_SINGLE_DECL(soc_enum_bfifomast,
  1326. AB8500_FIFOCONF3, AB8500_FIFOCONF3_BFIFOMAST_SHIFT,
  1327. enum_slavemaster);
  1328. /* Sidetone */
  1329. static SOC_ENUM_SINGLE_EXT_DECL(soc_enum_sidstate, enum_sid_state);
  1330. /* ANC */
  1331. static SOC_ENUM_SINGLE_EXT_DECL(soc_enum_ancstate, enum_anc_state);
  1332. static struct snd_kcontrol_new ab8500_ctrls[] = {
  1333. /* Charge pump */
  1334. SOC_ENUM("Charge Pump High Threshold For Low Voltage",
  1335. soc_enum_envdeththre),
  1336. SOC_ENUM("Charge Pump Low Threshold For Low Voltage",
  1337. soc_enum_envdetlthre),
  1338. SOC_SINGLE("Charge Pump Envelope Detection Switch",
  1339. AB8500_SIGENVCONF, AB8500_SIGENVCONF_ENVDETCPEN,
  1340. 1, 0),
  1341. SOC_ENUM("Charge Pump Envelope Detection Decay Time",
  1342. soc_enum_envdettime),
  1343. /* Headset */
  1344. SOC_ENUM("Headset Mode", soc_enum_da12voice),
  1345. SOC_SINGLE("Headset High Pass Switch",
  1346. AB8500_ANACONF1, AB8500_ANACONF1_HSHPEN,
  1347. 1, 0),
  1348. SOC_SINGLE("Headset Low Power Switch",
  1349. AB8500_ANACONF1, AB8500_ANACONF1_HSLOWPOW,
  1350. 1, 0),
  1351. SOC_SINGLE("Headset DAC Low Power Switch",
  1352. AB8500_ANACONF1, AB8500_ANACONF1_DACLOWPOW1,
  1353. 1, 0),
  1354. SOC_SINGLE("Headset DAC Drv Low Power Switch",
  1355. AB8500_ANACONF1, AB8500_ANACONF1_DACLOWPOW0,
  1356. 1, 0),
  1357. SOC_ENUM("Headset Fade Speed", soc_enum_hsfadspeed),
  1358. SOC_ENUM("Headset Source", soc_enum_da2hslr),
  1359. SOC_ENUM("Headset Filter", soc_enum_hsesinc),
  1360. SOC_DOUBLE_R_TLV("Headset Master Volume",
  1361. AB8500_DADIGGAIN1, AB8500_DADIGGAIN2,
  1362. 0, AB8500_DADIGGAINX_DAXGAIN_MAX, 1, dax_dig_gain_tlv),
  1363. SOC_DOUBLE_R_TLV("Headset Digital Volume",
  1364. AB8500_HSLEARDIGGAIN, AB8500_HSRDIGGAIN,
  1365. 0, AB8500_HSLEARDIGGAIN_HSLDGAIN_MAX, 1, hs_ear_dig_gain_tlv),
  1366. SOC_DOUBLE_TLV("Headset Volume",
  1367. AB8500_ANAGAIN3,
  1368. AB8500_ANAGAIN3_HSLGAIN, AB8500_ANAGAIN3_HSRGAIN,
  1369. AB8500_ANAGAIN3_HSXGAIN_MAX, 1, hs_gain_tlv),
  1370. /* Earpiece */
  1371. SOC_ENUM("Earpiece DAC Mode",
  1372. soc_enum_eardaclowpow),
  1373. SOC_ENUM("Earpiece DAC Drv Mode",
  1374. soc_enum_eardrvlowpow),
  1375. /* HandsFree */
  1376. SOC_ENUM("HF Mode", soc_enum_da34voice),
  1377. SOC_SINGLE("HF and Headset Swap Switch",
  1378. AB8500_DASLOTCONF1, AB8500_DASLOTCONF1_SWAPDA12_34,
  1379. 1, 0),
  1380. SOC_DOUBLE("HF Low EMI Mode Switch",
  1381. AB8500_CLASSDCONF1,
  1382. AB8500_CLASSDCONF1_HFLSWAPEN, AB8500_CLASSDCONF1_HFRSWAPEN,
  1383. 1, 0),
  1384. SOC_DOUBLE("HF FIR Bypass Switch",
  1385. AB8500_CLASSDCONF2,
  1386. AB8500_CLASSDCONF2_FIRBYP0, AB8500_CLASSDCONF2_FIRBYP1,
  1387. 1, 0),
  1388. SOC_DOUBLE("HF High Volume Switch",
  1389. AB8500_CLASSDCONF2,
  1390. AB8500_CLASSDCONF2_HIGHVOLEN0, AB8500_CLASSDCONF2_HIGHVOLEN1,
  1391. 1, 0),
  1392. SOC_SINGLE("HF L and R Bridge Switch",
  1393. AB8500_CLASSDCONF1, AB8500_CLASSDCONF1_PARLHF,
  1394. 1, 0),
  1395. SOC_DOUBLE_R_TLV("HF Master Volume",
  1396. AB8500_DADIGGAIN3, AB8500_DADIGGAIN4,
  1397. 0, AB8500_DADIGGAINX_DAXGAIN_MAX, 1, dax_dig_gain_tlv),
  1398. /* Vibra */
  1399. SOC_DOUBLE("Vibra High Volume Switch",
  1400. AB8500_CLASSDCONF2,
  1401. AB8500_CLASSDCONF2_HIGHVOLEN2, AB8500_CLASSDCONF2_HIGHVOLEN3,
  1402. 1, 0),
  1403. SOC_DOUBLE("Vibra Low EMI Mode Switch",
  1404. AB8500_CLASSDCONF1,
  1405. AB8500_CLASSDCONF1_VIB1SWAPEN, AB8500_CLASSDCONF1_VIB2SWAPEN,
  1406. 1, 0),
  1407. SOC_DOUBLE("Vibra FIR Bypass Switch",
  1408. AB8500_CLASSDCONF2,
  1409. AB8500_CLASSDCONF2_FIRBYP2, AB8500_CLASSDCONF2_FIRBYP3,
  1410. 1, 0),
  1411. SOC_ENUM("Vibra Mode", soc_enum_da56voice),
  1412. SOC_DOUBLE_R("Vibra PWM Duty Cycle N",
  1413. AB8500_PWMGENCONF3, AB8500_PWMGENCONF5,
  1414. AB8500_PWMGENCONFX_PWMVIBXDUTCYC,
  1415. AB8500_PWMGENCONFX_PWMVIBXDUTCYC_MAX, 0),
  1416. SOC_DOUBLE_R("Vibra PWM Duty Cycle P",
  1417. AB8500_PWMGENCONF2, AB8500_PWMGENCONF4,
  1418. AB8500_PWMGENCONFX_PWMVIBXDUTCYC,
  1419. AB8500_PWMGENCONFX_PWMVIBXDUTCYC_MAX, 0),
  1420. SOC_SINGLE("Vibra 1 and 2 Bridge Switch",
  1421. AB8500_CLASSDCONF1, AB8500_CLASSDCONF1_PARLVIB,
  1422. 1, 0),
  1423. SOC_DOUBLE_R_TLV("Vibra Master Volume",
  1424. AB8500_DADIGGAIN5, AB8500_DADIGGAIN6,
  1425. 0, AB8500_DADIGGAINX_DAXGAIN_MAX, 1, dax_dig_gain_tlv),
  1426. /* HandsFree, Vibra */
  1427. SOC_SINGLE("ClassD High Pass Volume",
  1428. AB8500_CLASSDCONF3, AB8500_CLASSDCONF3_DITHHPGAIN,
  1429. AB8500_CLASSDCONF3_DITHHPGAIN_MAX, 0),
  1430. SOC_SINGLE("ClassD White Volume",
  1431. AB8500_CLASSDCONF3, AB8500_CLASSDCONF3_DITHWGAIN,
  1432. AB8500_CLASSDCONF3_DITHWGAIN_MAX, 0),
  1433. /* Mic 1, Mic 2, LineIn */
  1434. SOC_DOUBLE_R_TLV("Mic Master Volume",
  1435. AB8500_ADDIGGAIN3, AB8500_ADDIGGAIN4,
  1436. 0, AB8500_ADDIGGAINX_ADXGAIN_MAX, 1, adx_dig_gain_tlv),
  1437. /* Mic 1 */
  1438. SOC_SINGLE_TLV("Mic 1",
  1439. AB8500_ANAGAIN1,
  1440. AB8500_ANAGAINX_MICXGAIN,
  1441. AB8500_ANAGAINX_MICXGAIN_MAX, 0, mic_gain_tlv),
  1442. SOC_SINGLE("Mic 1 Low Power Switch",
  1443. AB8500_ANAGAIN1, AB8500_ANAGAINX_LOWPOWMICX,
  1444. 1, 0),
  1445. /* Mic 2 */
  1446. SOC_DOUBLE("Mic High Pass Switch",
  1447. AB8500_ADFILTCONF,
  1448. AB8500_ADFILTCONF_AD3NH, AB8500_ADFILTCONF_AD4NH,
  1449. 1, 1),
  1450. SOC_ENUM("Mic Mode", soc_enum_ad34voice),
  1451. SOC_ENUM("Mic Filter", soc_enum_dmic34sinc),
  1452. SOC_SINGLE_TLV("Mic 2",
  1453. AB8500_ANAGAIN2,
  1454. AB8500_ANAGAINX_MICXGAIN,
  1455. AB8500_ANAGAINX_MICXGAIN_MAX, 0, mic_gain_tlv),
  1456. SOC_SINGLE("Mic 2 Low Power Switch",
  1457. AB8500_ANAGAIN2, AB8500_ANAGAINX_LOWPOWMICX,
  1458. 1, 0),
  1459. /* LineIn */
  1460. SOC_DOUBLE("LineIn High Pass Switch",
  1461. AB8500_ADFILTCONF,
  1462. AB8500_ADFILTCONF_AD1NH, AB8500_ADFILTCONF_AD2NH,
  1463. 1, 1),
  1464. SOC_ENUM("LineIn Filter", soc_enum_dmic12sinc),
  1465. SOC_ENUM("LineIn Mode", soc_enum_ad12voice),
  1466. SOC_DOUBLE_R_TLV("LineIn Master Volume",
  1467. AB8500_ADDIGGAIN1, AB8500_ADDIGGAIN2,
  1468. 0, AB8500_ADDIGGAINX_ADXGAIN_MAX, 1, adx_dig_gain_tlv),
  1469. SOC_DOUBLE_TLV("LineIn",
  1470. AB8500_ANAGAIN4,
  1471. AB8500_ANAGAIN4_LINLGAIN, AB8500_ANAGAIN4_LINRGAIN,
  1472. AB8500_ANAGAIN4_LINXGAIN_MAX, 0, lin_gain_tlv),
  1473. SOC_DOUBLE_R_TLV("LineIn to Headset Volume",
  1474. AB8500_DIGLINHSLGAIN, AB8500_DIGLINHSRGAIN,
  1475. AB8500_DIGLINHSXGAIN_LINTOHSXGAIN,
  1476. AB8500_DIGLINHSXGAIN_LINTOHSXGAIN_MAX,
  1477. 1, lin2hs_gain_tlv),
  1478. /* DMic */
  1479. SOC_ENUM("DMic Filter", soc_enum_dmic56sinc),
  1480. SOC_DOUBLE_R_TLV("DMic Master Volume",
  1481. AB8500_ADDIGGAIN5, AB8500_ADDIGGAIN6,
  1482. 0, AB8500_ADDIGGAINX_ADXGAIN_MAX, 1, adx_dig_gain_tlv),
  1483. /* Digital gains */
  1484. SOC_ENUM("Digital Gain Fade Speed", soc_enum_fadespeed),
  1485. /* Analog loopback */
  1486. SOC_DOUBLE_R_TLV("Analog Loopback Volume",
  1487. AB8500_ADDIGLOOPGAIN1, AB8500_ADDIGLOOPGAIN2,
  1488. 0, AB8500_ADDIGLOOPGAINX_ADXLBGAIN_MAX, 1, dax_dig_gain_tlv),
  1489. /* Digital interface - DA from slot mapping */
  1490. SOC_ENUM("Digital Interface DA 1 From Slot Map", soc_enum_da1slotmap),
  1491. SOC_ENUM("Digital Interface DA 2 From Slot Map", soc_enum_da2slotmap),
  1492. SOC_ENUM("Digital Interface DA 3 From Slot Map", soc_enum_da3slotmap),
  1493. SOC_ENUM("Digital Interface DA 4 From Slot Map", soc_enum_da4slotmap),
  1494. SOC_ENUM("Digital Interface DA 5 From Slot Map", soc_enum_da5slotmap),
  1495. SOC_ENUM("Digital Interface DA 6 From Slot Map", soc_enum_da6slotmap),
  1496. SOC_ENUM("Digital Interface DA 7 From Slot Map", soc_enum_da7slotmap),
  1497. SOC_ENUM("Digital Interface DA 8 From Slot Map", soc_enum_da8slotmap),
  1498. /* Digital interface - AD to slot mapping */
  1499. SOC_ENUM("Digital Interface AD To Slot 0 Map", soc_enum_adslot0map),
  1500. SOC_ENUM("Digital Interface AD To Slot 1 Map", soc_enum_adslot1map),
  1501. SOC_ENUM("Digital Interface AD To Slot 2 Map", soc_enum_adslot2map),
  1502. SOC_ENUM("Digital Interface AD To Slot 3 Map", soc_enum_adslot3map),
  1503. SOC_ENUM("Digital Interface AD To Slot 4 Map", soc_enum_adslot4map),
  1504. SOC_ENUM("Digital Interface AD To Slot 5 Map", soc_enum_adslot5map),
  1505. SOC_ENUM("Digital Interface AD To Slot 6 Map", soc_enum_adslot6map),
  1506. SOC_ENUM("Digital Interface AD To Slot 7 Map", soc_enum_adslot7map),
  1507. SOC_ENUM("Digital Interface AD To Slot 8 Map", soc_enum_adslot8map),
  1508. SOC_ENUM("Digital Interface AD To Slot 9 Map", soc_enum_adslot9map),
  1509. SOC_ENUM("Digital Interface AD To Slot 10 Map", soc_enum_adslot10map),
  1510. SOC_ENUM("Digital Interface AD To Slot 11 Map", soc_enum_adslot11map),
  1511. SOC_ENUM("Digital Interface AD To Slot 12 Map", soc_enum_adslot12map),
  1512. SOC_ENUM("Digital Interface AD To Slot 13 Map", soc_enum_adslot13map),
  1513. SOC_ENUM("Digital Interface AD To Slot 14 Map", soc_enum_adslot14map),
  1514. SOC_ENUM("Digital Interface AD To Slot 15 Map", soc_enum_adslot15map),
  1515. SOC_ENUM("Digital Interface AD To Slot 16 Map", soc_enum_adslot16map),
  1516. SOC_ENUM("Digital Interface AD To Slot 17 Map", soc_enum_adslot17map),
  1517. SOC_ENUM("Digital Interface AD To Slot 18 Map", soc_enum_adslot18map),
  1518. SOC_ENUM("Digital Interface AD To Slot 19 Map", soc_enum_adslot19map),
  1519. SOC_ENUM("Digital Interface AD To Slot 20 Map", soc_enum_adslot20map),
  1520. SOC_ENUM("Digital Interface AD To Slot 21 Map", soc_enum_adslot21map),
  1521. SOC_ENUM("Digital Interface AD To Slot 22 Map", soc_enum_adslot22map),
  1522. SOC_ENUM("Digital Interface AD To Slot 23 Map", soc_enum_adslot23map),
  1523. SOC_ENUM("Digital Interface AD To Slot 24 Map", soc_enum_adslot24map),
  1524. SOC_ENUM("Digital Interface AD To Slot 25 Map", soc_enum_adslot25map),
  1525. SOC_ENUM("Digital Interface AD To Slot 26 Map", soc_enum_adslot26map),
  1526. SOC_ENUM("Digital Interface AD To Slot 27 Map", soc_enum_adslot27map),
  1527. SOC_ENUM("Digital Interface AD To Slot 28 Map", soc_enum_adslot28map),
  1528. SOC_ENUM("Digital Interface AD To Slot 29 Map", soc_enum_adslot29map),
  1529. SOC_ENUM("Digital Interface AD To Slot 30 Map", soc_enum_adslot30map),
  1530. SOC_ENUM("Digital Interface AD To Slot 31 Map", soc_enum_adslot31map),
  1531. /* Digital interface - Loopback */
  1532. SOC_SINGLE("Digital Interface AD 1 Loopback Switch",
  1533. AB8500_DASLOTCONF1, AB8500_DASLOTCONF1_DAI7TOADO1,
  1534. 1, 0),
  1535. SOC_SINGLE("Digital Interface AD 2 Loopback Switch",
  1536. AB8500_DASLOTCONF2, AB8500_DASLOTCONF2_DAI8TOADO2,
  1537. 1, 0),
  1538. SOC_SINGLE("Digital Interface AD 3 Loopback Switch",
  1539. AB8500_DASLOTCONF3, AB8500_DASLOTCONF3_DAI7TOADO3,
  1540. 1, 0),
  1541. SOC_SINGLE("Digital Interface AD 4 Loopback Switch",
  1542. AB8500_DASLOTCONF4, AB8500_DASLOTCONF4_DAI8TOADO4,
  1543. 1, 0),
  1544. SOC_SINGLE("Digital Interface AD 5 Loopback Switch",
  1545. AB8500_DASLOTCONF5, AB8500_DASLOTCONF5_DAI7TOADO5,
  1546. 1, 0),
  1547. SOC_SINGLE("Digital Interface AD 6 Loopback Switch",
  1548. AB8500_DASLOTCONF6, AB8500_DASLOTCONF6_DAI8TOADO6,
  1549. 1, 0),
  1550. SOC_SINGLE("Digital Interface AD 7 Loopback Switch",
  1551. AB8500_DASLOTCONF7, AB8500_DASLOTCONF7_DAI8TOADO7,
  1552. 1, 0),
  1553. SOC_SINGLE("Digital Interface AD 8 Loopback Switch",
  1554. AB8500_DASLOTCONF8, AB8500_DASLOTCONF8_DAI7TOADO8,
  1555. 1, 0),
  1556. /* Digital interface - Burst FIFO */
  1557. SOC_SINGLE("Digital Interface 0 FIFO Enable Switch",
  1558. AB8500_DIGIFCONF3, AB8500_DIGIFCONF3_IF0BFIFOEN,
  1559. 1, 0),
  1560. SOC_ENUM("Burst FIFO Mask", soc_enum_bfifomask),
  1561. SOC_ENUM("Burst FIFO Bit-clock Frequency", soc_enum_bfifo19m2),
  1562. SOC_SINGLE("Burst FIFO Threshold",
  1563. AB8500_FIFOCONF1, AB8500_FIFOCONF1_BFIFOINT_SHIFT,
  1564. AB8500_FIFOCONF1_BFIFOINT_MAX, 0),
  1565. SOC_SINGLE("Burst FIFO Length",
  1566. AB8500_FIFOCONF2, AB8500_FIFOCONF2_BFIFOTX_SHIFT,
  1567. AB8500_FIFOCONF2_BFIFOTX_MAX, 0),
  1568. SOC_SINGLE("Burst FIFO EOS Extra Slots",
  1569. AB8500_FIFOCONF3, AB8500_FIFOCONF3_BFIFOEXSL_SHIFT,
  1570. AB8500_FIFOCONF3_BFIFOEXSL_MAX, 0),
  1571. SOC_SINGLE("Burst FIFO FS Extra Bit-clocks",
  1572. AB8500_FIFOCONF3, AB8500_FIFOCONF3_PREBITCLK0_SHIFT,
  1573. AB8500_FIFOCONF3_PREBITCLK0_MAX, 0),
  1574. SOC_ENUM("Burst FIFO Interface Mode", soc_enum_bfifomast),
  1575. SOC_SINGLE("Burst FIFO Interface Switch",
  1576. AB8500_FIFOCONF3, AB8500_FIFOCONF3_BFIFORUN_SHIFT,
  1577. 1, 0),
  1578. SOC_SINGLE("Burst FIFO Switch Frame Number",
  1579. AB8500_FIFOCONF4, AB8500_FIFOCONF4_BFIFOFRAMSW_SHIFT,
  1580. AB8500_FIFOCONF4_BFIFOFRAMSW_MAX, 0),
  1581. SOC_SINGLE("Burst FIFO Wake Up Delay",
  1582. AB8500_FIFOCONF5, AB8500_FIFOCONF5_BFIFOWAKEUP_SHIFT,
  1583. AB8500_FIFOCONF5_BFIFOWAKEUP_MAX, 0),
  1584. SOC_SINGLE("Burst FIFO Samples In FIFO",
  1585. AB8500_FIFOCONF6, AB8500_FIFOCONF6_BFIFOSAMPLE_SHIFT,
  1586. AB8500_FIFOCONF6_BFIFOSAMPLE_MAX, 0),
  1587. /* ANC */
  1588. SOC_ENUM_EXT("ANC Status", soc_enum_ancstate,
  1589. anc_status_control_get, anc_status_control_put),
  1590. SOC_SINGLE_XR_SX("ANC Warp Delay Shift",
  1591. AB8500_ANCCONF2, 1, AB8500_ANCCONF2_SHIFT,
  1592. AB8500_ANCCONF2_MIN, AB8500_ANCCONF2_MAX, 0),
  1593. SOC_SINGLE_XR_SX("ANC FIR Output Shift",
  1594. AB8500_ANCCONF3, 1, AB8500_ANCCONF3_SHIFT,
  1595. AB8500_ANCCONF3_MIN, AB8500_ANCCONF3_MAX, 0),
  1596. SOC_SINGLE_XR_SX("ANC IIR Output Shift",
  1597. AB8500_ANCCONF4, 1, AB8500_ANCCONF4_SHIFT,
  1598. AB8500_ANCCONF4_MIN, AB8500_ANCCONF4_MAX, 0),
  1599. SOC_SINGLE_XR_SX("ANC Warp Delay",
  1600. AB8500_ANCCONF9, 2, AB8500_ANC_WARP_DELAY_SHIFT,
  1601. AB8500_ANC_WARP_DELAY_MIN, AB8500_ANC_WARP_DELAY_MAX, 0),
  1602. /* Sidetone */
  1603. SOC_ENUM_EXT("Sidetone Status", soc_enum_sidstate,
  1604. sid_status_control_get, sid_status_control_put),
  1605. SOC_SINGLE_STROBE("Sidetone Reset",
  1606. AB8500_SIDFIRADR, AB8500_SIDFIRADR_FIRSIDSET, 0),
  1607. };
  1608. static struct snd_kcontrol_new ab8500_filter_controls[] = {
  1609. AB8500_FILTER_CONTROL("ANC FIR Coefficients", AB8500_ANC_FIR_COEFFS,
  1610. AB8500_ANC_FIR_COEFF_MIN, AB8500_ANC_FIR_COEFF_MAX),
  1611. AB8500_FILTER_CONTROL("ANC IIR Coefficients", AB8500_ANC_IIR_COEFFS,
  1612. AB8500_ANC_IIR_COEFF_MIN, AB8500_ANC_IIR_COEFF_MAX),
  1613. AB8500_FILTER_CONTROL("Sidetone FIR Coefficients",
  1614. AB8500_SID_FIR_COEFFS, AB8500_SID_FIR_COEFF_MIN,
  1615. AB8500_SID_FIR_COEFF_MAX)
  1616. };
  1617. enum ab8500_filter {
  1618. AB8500_FILTER_ANC_FIR = 0,
  1619. AB8500_FILTER_ANC_IIR = 1,
  1620. AB8500_FILTER_SID_FIR = 2,
  1621. };
  1622. /*
  1623. * Extended interface for codec-driver
  1624. */
  1625. static int ab8500_audio_init_audioblock(struct snd_soc_codec *codec)
  1626. {
  1627. int status;
  1628. dev_dbg(codec->dev, "%s: Enter.\n", __func__);
  1629. /* Reset audio-registers and disable 32kHz-clock output 2 */
  1630. status = ab8500_sysctrl_write(AB8500_STW4500CTRL3,
  1631. AB8500_STW4500CTRL3_CLK32KOUT2DIS |
  1632. AB8500_STW4500CTRL3_RESETAUDN,
  1633. AB8500_STW4500CTRL3_RESETAUDN);
  1634. if (status < 0)
  1635. return status;
  1636. return 0;
  1637. }
  1638. static int ab8500_audio_setup_mics(struct snd_soc_codec *codec,
  1639. struct amic_settings *amics)
  1640. {
  1641. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1642. u8 value8;
  1643. unsigned int value;
  1644. int status;
  1645. const struct snd_soc_dapm_route *route;
  1646. dev_dbg(codec->dev, "%s: Enter.\n", __func__);
  1647. /* Set DMic-clocks to outputs */
  1648. status = abx500_get_register_interruptible(codec->dev, AB8500_MISC,
  1649. AB8500_GPIO_DIR4_REG,
  1650. &value8);
  1651. if (status < 0)
  1652. return status;
  1653. value = value8 | GPIO27_DIR_OUTPUT | GPIO29_DIR_OUTPUT |
  1654. GPIO31_DIR_OUTPUT;
  1655. status = abx500_set_register_interruptible(codec->dev,
  1656. AB8500_MISC,
  1657. AB8500_GPIO_DIR4_REG,
  1658. value);
  1659. if (status < 0)
  1660. return status;
  1661. /* Attach regulators to AMic DAPM-paths */
  1662. dev_dbg(codec->dev, "%s: Mic 1a regulator: %s\n", __func__,
  1663. amic_micbias_str(amics->mic1a_micbias));
  1664. route = &ab8500_dapm_routes_mic1a_vamicx[amics->mic1a_micbias];
  1665. status = snd_soc_dapm_add_routes(dapm, route, 1);
  1666. dev_dbg(codec->dev, "%s: Mic 1b regulator: %s\n", __func__,
  1667. amic_micbias_str(amics->mic1b_micbias));
  1668. route = &ab8500_dapm_routes_mic1b_vamicx[amics->mic1b_micbias];
  1669. status |= snd_soc_dapm_add_routes(dapm, route, 1);
  1670. dev_dbg(codec->dev, "%s: Mic 2 regulator: %s\n", __func__,
  1671. amic_micbias_str(amics->mic2_micbias));
  1672. route = &ab8500_dapm_routes_mic2_vamicx[amics->mic2_micbias];
  1673. status |= snd_soc_dapm_add_routes(dapm, route, 1);
  1674. if (status < 0) {
  1675. dev_err(codec->dev,
  1676. "%s: Failed to add AMic-regulator DAPM-routes (%d).\n",
  1677. __func__, status);
  1678. return status;
  1679. }
  1680. /* Set AMic-configuration */
  1681. dev_dbg(codec->dev, "%s: Mic 1 mic-type: %s\n", __func__,
  1682. amic_type_str(amics->mic1_type));
  1683. snd_soc_update_bits(codec, AB8500_ANAGAIN1, AB8500_ANAGAINX_ENSEMICX,
  1684. amics->mic1_type == AMIC_TYPE_DIFFERENTIAL ?
  1685. 0 : AB8500_ANAGAINX_ENSEMICX);
  1686. dev_dbg(codec->dev, "%s: Mic 2 mic-type: %s\n", __func__,
  1687. amic_type_str(amics->mic2_type));
  1688. snd_soc_update_bits(codec, AB8500_ANAGAIN2, AB8500_ANAGAINX_ENSEMICX,
  1689. amics->mic2_type == AMIC_TYPE_DIFFERENTIAL ?
  1690. 0 : AB8500_ANAGAINX_ENSEMICX);
  1691. return 0;
  1692. }
  1693. static int ab8500_audio_set_ear_cmv(struct snd_soc_codec *codec,
  1694. enum ear_cm_voltage ear_cmv)
  1695. {
  1696. char *cmv_str;
  1697. switch (ear_cmv) {
  1698. case EAR_CMV_0_95V:
  1699. cmv_str = "0.95V";
  1700. break;
  1701. case EAR_CMV_1_10V:
  1702. cmv_str = "1.10V";
  1703. break;
  1704. case EAR_CMV_1_27V:
  1705. cmv_str = "1.27V";
  1706. break;
  1707. case EAR_CMV_1_58V:
  1708. cmv_str = "1.58V";
  1709. break;
  1710. default:
  1711. dev_err(codec->dev,
  1712. "%s: Unknown earpiece CM-voltage (%d)!\n",
  1713. __func__, (int)ear_cmv);
  1714. return -EINVAL;
  1715. }
  1716. dev_dbg(codec->dev, "%s: Earpiece CM-voltage: %s\n", __func__,
  1717. cmv_str);
  1718. snd_soc_update_bits(codec, AB8500_ANACONF1, AB8500_ANACONF1_EARSELCM,
  1719. ear_cmv);
  1720. return 0;
  1721. }
  1722. static int ab8500_audio_set_bit_delay(struct snd_soc_dai *dai,
  1723. unsigned int delay)
  1724. {
  1725. unsigned int mask, val;
  1726. struct snd_soc_codec *codec = dai->codec;
  1727. mask = BIT(AB8500_DIGIFCONF2_IF0DEL);
  1728. val = 0;
  1729. switch (delay) {
  1730. case 0:
  1731. break;
  1732. case 1:
  1733. val |= BIT(AB8500_DIGIFCONF2_IF0DEL);
  1734. break;
  1735. default:
  1736. dev_err(dai->codec->dev,
  1737. "%s: ERROR: Unsupported bit-delay (0x%x)!\n",
  1738. __func__, delay);
  1739. return -EINVAL;
  1740. }
  1741. dev_dbg(dai->codec->dev, "%s: IF0 Bit-delay: %d bits.\n",
  1742. __func__, delay);
  1743. snd_soc_update_bits(codec, AB8500_DIGIFCONF2, mask, val);
  1744. return 0;
  1745. }
  1746. /* Gates clocking according format mask */
  1747. static int ab8500_codec_set_dai_clock_gate(struct snd_soc_codec *codec,
  1748. unsigned int fmt)
  1749. {
  1750. unsigned int mask;
  1751. unsigned int val;
  1752. mask = BIT(AB8500_DIGIFCONF1_ENMASTGEN) |
  1753. BIT(AB8500_DIGIFCONF1_ENFSBITCLK0);
  1754. val = BIT(AB8500_DIGIFCONF1_ENMASTGEN);
  1755. switch (fmt & SND_SOC_DAIFMT_CLOCK_MASK) {
  1756. case SND_SOC_DAIFMT_CONT: /* continuous clock */
  1757. dev_dbg(codec->dev, "%s: IF0 Clock is continuous.\n",
  1758. __func__);
  1759. val |= BIT(AB8500_DIGIFCONF1_ENFSBITCLK0);
  1760. break;
  1761. case SND_SOC_DAIFMT_GATED: /* clock is gated */
  1762. dev_dbg(codec->dev, "%s: IF0 Clock is gated.\n",
  1763. __func__);
  1764. break;
  1765. default:
  1766. dev_err(codec->dev,
  1767. "%s: ERROR: Unsupported clock mask (0x%x)!\n",
  1768. __func__, fmt & SND_SOC_DAIFMT_CLOCK_MASK);
  1769. return -EINVAL;
  1770. }
  1771. snd_soc_update_bits(codec, AB8500_DIGIFCONF1, mask, val);
  1772. return 0;
  1773. }
  1774. static int ab8500_codec_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1775. {
  1776. unsigned int mask;
  1777. unsigned int val;
  1778. struct snd_soc_codec *codec = dai->codec;
  1779. int status;
  1780. dev_dbg(codec->dev, "%s: Enter (fmt = 0x%x)\n", __func__, fmt);
  1781. mask = BIT(AB8500_DIGIFCONF3_IF1DATOIF0AD) |
  1782. BIT(AB8500_DIGIFCONF3_IF1CLKTOIF0CLK) |
  1783. BIT(AB8500_DIGIFCONF3_IF0BFIFOEN) |
  1784. BIT(AB8500_DIGIFCONF3_IF0MASTER);
  1785. val = 0;
  1786. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1787. case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & FRM master */
  1788. dev_dbg(dai->codec->dev,
  1789. "%s: IF0 Master-mode: AB8500 master.\n", __func__);
  1790. val |= BIT(AB8500_DIGIFCONF3_IF0MASTER);
  1791. break;
  1792. case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & FRM slave */
  1793. dev_dbg(dai->codec->dev,
  1794. "%s: IF0 Master-mode: AB8500 slave.\n", __func__);
  1795. break;
  1796. case SND_SOC_DAIFMT_CBS_CFM: /* codec clk slave & FRM master */
  1797. case SND_SOC_DAIFMT_CBM_CFS: /* codec clk master & frame slave */
  1798. dev_err(dai->codec->dev,
  1799. "%s: ERROR: The device is either a master or a slave.\n",
  1800. __func__);
  1801. default:
  1802. dev_err(dai->codec->dev,
  1803. "%s: ERROR: Unsupporter master mask 0x%x\n",
  1804. __func__, fmt & SND_SOC_DAIFMT_MASTER_MASK);
  1805. return -EINVAL;
  1806. }
  1807. snd_soc_update_bits(codec, AB8500_DIGIFCONF3, mask, val);
  1808. /* Set clock gating */
  1809. status = ab8500_codec_set_dai_clock_gate(codec, fmt);
  1810. if (status) {
  1811. dev_err(dai->codec->dev,
  1812. "%s: ERROR: Failed to set clock gate (%d).\n",
  1813. __func__, status);
  1814. return status;
  1815. }
  1816. /* Setting data transfer format */
  1817. mask = BIT(AB8500_DIGIFCONF2_IF0FORMAT0) |
  1818. BIT(AB8500_DIGIFCONF2_IF0FORMAT1) |
  1819. BIT(AB8500_DIGIFCONF2_FSYNC0P) |
  1820. BIT(AB8500_DIGIFCONF2_BITCLK0P);
  1821. val = 0;
  1822. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1823. case SND_SOC_DAIFMT_I2S: /* I2S mode */
  1824. dev_dbg(dai->codec->dev, "%s: IF0 Protocol: I2S\n", __func__);
  1825. val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT1);
  1826. ab8500_audio_set_bit_delay(dai, 0);
  1827. break;
  1828. case SND_SOC_DAIFMT_DSP_A: /* L data MSB after FRM LRC */
  1829. dev_dbg(dai->codec->dev,
  1830. "%s: IF0 Protocol: DSP A (TDM)\n", __func__);
  1831. val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT0);
  1832. ab8500_audio_set_bit_delay(dai, 1);
  1833. break;
  1834. case SND_SOC_DAIFMT_DSP_B: /* L data MSB during FRM LRC */
  1835. dev_dbg(dai->codec->dev,
  1836. "%s: IF0 Protocol: DSP B (TDM)\n", __func__);
  1837. val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT0);
  1838. ab8500_audio_set_bit_delay(dai, 0);
  1839. break;
  1840. default:
  1841. dev_err(dai->codec->dev,
  1842. "%s: ERROR: Unsupported format (0x%x)!\n",
  1843. __func__, fmt & SND_SOC_DAIFMT_FORMAT_MASK);
  1844. return -EINVAL;
  1845. }
  1846. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1847. case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */
  1848. dev_dbg(dai->codec->dev,
  1849. "%s: IF0: Normal bit clock, normal frame\n",
  1850. __func__);
  1851. break;
  1852. case SND_SOC_DAIFMT_NB_IF: /* normal BCLK + inv FRM */
  1853. dev_dbg(dai->codec->dev,
  1854. "%s: IF0: Normal bit clock, inverted frame\n",
  1855. __func__);
  1856. val |= BIT(AB8500_DIGIFCONF2_FSYNC0P);
  1857. break;
  1858. case SND_SOC_DAIFMT_IB_NF: /* invert BCLK + nor FRM */
  1859. dev_dbg(dai->codec->dev,
  1860. "%s: IF0: Inverted bit clock, normal frame\n",
  1861. __func__);
  1862. val |= BIT(AB8500_DIGIFCONF2_BITCLK0P);
  1863. break;
  1864. case SND_SOC_DAIFMT_IB_IF: /* invert BCLK + FRM */
  1865. dev_dbg(dai->codec->dev,
  1866. "%s: IF0: Inverted bit clock, inverted frame\n",
  1867. __func__);
  1868. val |= BIT(AB8500_DIGIFCONF2_FSYNC0P);
  1869. val |= BIT(AB8500_DIGIFCONF2_BITCLK0P);
  1870. break;
  1871. default:
  1872. dev_err(dai->codec->dev,
  1873. "%s: ERROR: Unsupported INV mask 0x%x\n",
  1874. __func__, fmt & SND_SOC_DAIFMT_INV_MASK);
  1875. return -EINVAL;
  1876. }
  1877. snd_soc_update_bits(codec, AB8500_DIGIFCONF2, mask, val);
  1878. return 0;
  1879. }
  1880. static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
  1881. unsigned int tx_mask, unsigned int rx_mask,
  1882. int slots, int slot_width)
  1883. {
  1884. struct snd_soc_codec *codec = dai->codec;
  1885. unsigned int val, mask, slot, slots_active;
  1886. mask = BIT(AB8500_DIGIFCONF2_IF0WL0) |
  1887. BIT(AB8500_DIGIFCONF2_IF0WL1);
  1888. val = 0;
  1889. switch (slot_width) {
  1890. case 16:
  1891. break;
  1892. case 20:
  1893. val |= BIT(AB8500_DIGIFCONF2_IF0WL0);
  1894. break;
  1895. case 24:
  1896. val |= BIT(AB8500_DIGIFCONF2_IF0WL1);
  1897. break;
  1898. case 32:
  1899. val |= BIT(AB8500_DIGIFCONF2_IF0WL1) |
  1900. BIT(AB8500_DIGIFCONF2_IF0WL0);
  1901. break;
  1902. default:
  1903. dev_err(dai->codec->dev, "%s: Unsupported slot-width 0x%x\n",
  1904. __func__, slot_width);
  1905. return -EINVAL;
  1906. }
  1907. dev_dbg(dai->codec->dev, "%s: IF0 slot-width: %d bits.\n",
  1908. __func__, slot_width);
  1909. snd_soc_update_bits(codec, AB8500_DIGIFCONF2, mask, val);
  1910. /* Setup TDM clocking according to slot count */
  1911. dev_dbg(dai->codec->dev, "%s: Slots, total: %d\n", __func__, slots);
  1912. mask = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0) |
  1913. BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
  1914. switch (slots) {
  1915. case 2:
  1916. val = AB8500_MASK_NONE;
  1917. break;
  1918. case 4:
  1919. val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0);
  1920. break;
  1921. case 8:
  1922. val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
  1923. break;
  1924. case 16:
  1925. val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0) |
  1926. BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
  1927. break;
  1928. default:
  1929. dev_err(dai->codec->dev,
  1930. "%s: ERROR: Unsupported number of slots (%d)!\n",
  1931. __func__, slots);
  1932. return -EINVAL;
  1933. }
  1934. snd_soc_update_bits(codec, AB8500_DIGIFCONF1, mask, val);
  1935. /* Setup TDM DA according to active tx slots */
  1936. if (tx_mask & ~0xff)
  1937. return -EINVAL;
  1938. mask = AB8500_DASLOTCONFX_SLTODAX_MASK;
  1939. tx_mask = tx_mask << AB8500_DA_DATA0_OFFSET;
  1940. slots_active = hweight32(tx_mask);
  1941. dev_dbg(dai->codec->dev, "%s: Slots, active, TX: %d\n", __func__,
  1942. slots_active);
  1943. switch (slots_active) {
  1944. case 0:
  1945. break;
  1946. case 1:
  1947. slot = ffs(tx_mask);
  1948. snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot);
  1949. snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot);
  1950. snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot);
  1951. snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot);
  1952. break;
  1953. case 2:
  1954. slot = ffs(tx_mask);
  1955. snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot);
  1956. snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot);
  1957. slot = fls(tx_mask);
  1958. snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot);
  1959. snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot);
  1960. break;
  1961. case 8:
  1962. dev_dbg(dai->codec->dev,
  1963. "%s: In 8-channel mode DA-from-slot mapping is set manually.",
  1964. __func__);
  1965. break;
  1966. default:
  1967. dev_err(dai->codec->dev,
  1968. "%s: Unsupported number of active TX-slots (%d)!\n",
  1969. __func__, slots_active);
  1970. return -EINVAL;
  1971. }
  1972. /* Setup TDM AD according to active RX-slots */
  1973. if (rx_mask & ~0xff)
  1974. return -EINVAL;
  1975. rx_mask = rx_mask << AB8500_AD_DATA0_OFFSET;
  1976. slots_active = hweight32(rx_mask);
  1977. dev_dbg(dai->codec->dev, "%s: Slots, active, RX: %d\n", __func__,
  1978. slots_active);
  1979. switch (slots_active) {
  1980. case 0:
  1981. break;
  1982. case 1:
  1983. slot = ffs(rx_mask);
  1984. snd_soc_update_bits(codec, AB8500_ADSLOTSEL(slot),
  1985. AB8500_MASK_SLOT(slot),
  1986. AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
  1987. break;
  1988. case 2:
  1989. slot = ffs(rx_mask);
  1990. snd_soc_update_bits(codec,
  1991. AB8500_ADSLOTSEL(slot),
  1992. AB8500_MASK_SLOT(slot),
  1993. AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
  1994. slot = fls(rx_mask);
  1995. snd_soc_update_bits(codec,
  1996. AB8500_ADSLOTSEL(slot),
  1997. AB8500_MASK_SLOT(slot),
  1998. AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT2, slot));
  1999. break;
  2000. case 8:
  2001. dev_dbg(dai->codec->dev,
  2002. "%s: In 8-channel mode AD-to-slot mapping is set manually.",
  2003. __func__);
  2004. break;
  2005. default:
  2006. dev_err(dai->codec->dev,
  2007. "%s: Unsupported number of active RX-slots (%d)!\n",
  2008. __func__, slots_active);
  2009. return -EINVAL;
  2010. }
  2011. return 0;
  2012. }
  2013. static const struct snd_soc_dai_ops ab8500_codec_ops = {
  2014. .set_fmt = ab8500_codec_set_dai_fmt,
  2015. .set_tdm_slot = ab8500_codec_set_dai_tdm_slot,
  2016. };
  2017. static struct snd_soc_dai_driver ab8500_codec_dai[] = {
  2018. {
  2019. .name = "ab8500-codec-dai.0",
  2020. .id = 0,
  2021. .playback = {
  2022. .stream_name = "ab8500_0p",
  2023. .channels_min = 1,
  2024. .channels_max = 8,
  2025. .rates = AB8500_SUPPORTED_RATE,
  2026. .formats = AB8500_SUPPORTED_FMT,
  2027. },
  2028. .ops = &ab8500_codec_ops,
  2029. .symmetric_rates = 1
  2030. },
  2031. {
  2032. .name = "ab8500-codec-dai.1",
  2033. .id = 1,
  2034. .capture = {
  2035. .stream_name = "ab8500_0c",
  2036. .channels_min = 1,
  2037. .channels_max = 8,
  2038. .rates = AB8500_SUPPORTED_RATE,
  2039. .formats = AB8500_SUPPORTED_FMT,
  2040. },
  2041. .ops = &ab8500_codec_ops,
  2042. .symmetric_rates = 1
  2043. }
  2044. };
  2045. static void ab8500_codec_of_probe(struct device *dev, struct device_node *np,
  2046. struct ab8500_codec_platform_data *codec)
  2047. {
  2048. u32 value;
  2049. if (of_property_read_bool(np, "stericsson,amic1-type-single-ended"))
  2050. codec->amics.mic1_type = AMIC_TYPE_SINGLE_ENDED;
  2051. else
  2052. codec->amics.mic1_type = AMIC_TYPE_DIFFERENTIAL;
  2053. if (of_property_read_bool(np, "stericsson,amic2-type-single-ended"))
  2054. codec->amics.mic2_type = AMIC_TYPE_SINGLE_ENDED;
  2055. else
  2056. codec->amics.mic2_type = AMIC_TYPE_DIFFERENTIAL;
  2057. /* Has a non-standard Vamic been requested? */
  2058. if (of_property_read_bool(np, "stericsson,amic1a-bias-vamic2"))
  2059. codec->amics.mic1a_micbias = AMIC_MICBIAS_VAMIC2;
  2060. else
  2061. codec->amics.mic1a_micbias = AMIC_MICBIAS_VAMIC1;
  2062. if (of_property_read_bool(np, "stericsson,amic1b-bias-vamic2"))
  2063. codec->amics.mic1b_micbias = AMIC_MICBIAS_VAMIC2;
  2064. else
  2065. codec->amics.mic1b_micbias = AMIC_MICBIAS_VAMIC1;
  2066. if (of_property_read_bool(np, "stericsson,amic2-bias-vamic1"))
  2067. codec->amics.mic2_micbias = AMIC_MICBIAS_VAMIC1;
  2068. else
  2069. codec->amics.mic2_micbias = AMIC_MICBIAS_VAMIC2;
  2070. if (!of_property_read_u32(np, "stericsson,earpeice-cmv", &value)) {
  2071. switch (value) {
  2072. case 950 :
  2073. codec->ear_cmv = EAR_CMV_0_95V;
  2074. break;
  2075. case 1100 :
  2076. codec->ear_cmv = EAR_CMV_1_10V;
  2077. break;
  2078. case 1270 :
  2079. codec->ear_cmv = EAR_CMV_1_27V;
  2080. break;
  2081. case 1580 :
  2082. codec->ear_cmv = EAR_CMV_1_58V;
  2083. break;
  2084. default :
  2085. codec->ear_cmv = EAR_CMV_UNKNOWN;
  2086. dev_err(dev, "Unsuitable earpiece voltage found in DT\n");
  2087. }
  2088. } else {
  2089. dev_warn(dev, "No earpiece voltage found in DT - using default\n");
  2090. codec->ear_cmv = EAR_CMV_0_95V;
  2091. }
  2092. }
  2093. static int ab8500_codec_probe(struct snd_soc_codec *codec)
  2094. {
  2095. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2096. struct device *dev = codec->dev;
  2097. struct device_node *np = dev->of_node;
  2098. struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev);
  2099. struct ab8500_codec_platform_data codec_pdata;
  2100. struct filter_control *fc;
  2101. int status;
  2102. dev_dbg(dev, "%s: Enter.\n", __func__);
  2103. ab8500_codec_of_probe(dev, np, &codec_pdata);
  2104. status = ab8500_audio_setup_mics(codec, &codec_pdata.amics);
  2105. if (status < 0) {
  2106. pr_err("%s: Failed to setup mics (%d)!\n", __func__, status);
  2107. return status;
  2108. }
  2109. status = ab8500_audio_set_ear_cmv(codec, codec_pdata.ear_cmv);
  2110. if (status < 0) {
  2111. pr_err("%s: Failed to set earpiece CM-voltage (%d)!\n",
  2112. __func__, status);
  2113. return status;
  2114. }
  2115. status = ab8500_audio_init_audioblock(codec);
  2116. if (status < 0) {
  2117. dev_err(dev, "%s: failed to init audio-block (%d)!\n",
  2118. __func__, status);
  2119. return status;
  2120. }
  2121. /* Override HW-defaults */
  2122. snd_soc_write(codec, AB8500_ANACONF5,
  2123. BIT(AB8500_ANACONF5_HSAUTOEN));
  2124. snd_soc_write(codec, AB8500_SHORTCIRCONF,
  2125. BIT(AB8500_SHORTCIRCONF_HSZCDDIS));
  2126. /* Add filter controls */
  2127. status = snd_soc_add_codec_controls(codec, ab8500_filter_controls,
  2128. ARRAY_SIZE(ab8500_filter_controls));
  2129. if (status < 0) {
  2130. dev_err(dev,
  2131. "%s: failed to add ab8500 filter controls (%d).\n",
  2132. __func__, status);
  2133. return status;
  2134. }
  2135. fc = (struct filter_control *)
  2136. &ab8500_filter_controls[AB8500_FILTER_ANC_FIR].private_value;
  2137. drvdata->anc_fir_values = (long *)fc->value;
  2138. fc = (struct filter_control *)
  2139. &ab8500_filter_controls[AB8500_FILTER_ANC_IIR].private_value;
  2140. drvdata->anc_iir_values = (long *)fc->value;
  2141. fc = (struct filter_control *)
  2142. &ab8500_filter_controls[AB8500_FILTER_SID_FIR].private_value;
  2143. drvdata->sid_fir_values = (long *)fc->value;
  2144. snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
  2145. mutex_init(&drvdata->ctrl_lock);
  2146. return status;
  2147. }
  2148. static struct snd_soc_codec_driver ab8500_codec_driver = {
  2149. .probe = ab8500_codec_probe,
  2150. .component_driver = {
  2151. .controls = ab8500_ctrls,
  2152. .num_controls = ARRAY_SIZE(ab8500_ctrls),
  2153. .dapm_widgets = ab8500_dapm_widgets,
  2154. .num_dapm_widgets = ARRAY_SIZE(ab8500_dapm_widgets),
  2155. .dapm_routes = ab8500_dapm_routes,
  2156. .num_dapm_routes = ARRAY_SIZE(ab8500_dapm_routes),
  2157. },
  2158. };
  2159. static int ab8500_codec_driver_probe(struct platform_device *pdev)
  2160. {
  2161. int status;
  2162. struct ab8500_codec_drvdata *drvdata;
  2163. dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
  2164. /* Create driver private-data struct */
  2165. drvdata = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_codec_drvdata),
  2166. GFP_KERNEL);
  2167. if (!drvdata)
  2168. return -ENOMEM;
  2169. drvdata->sid_status = SID_UNCONFIGURED;
  2170. drvdata->anc_status = ANC_UNCONFIGURED;
  2171. dev_set_drvdata(&pdev->dev, drvdata);
  2172. drvdata->regmap = devm_regmap_init(&pdev->dev, NULL, &pdev->dev,
  2173. &ab8500_codec_regmap);
  2174. if (IS_ERR(drvdata->regmap)) {
  2175. status = PTR_ERR(drvdata->regmap);
  2176. dev_err(&pdev->dev, "%s: Failed to allocate regmap: %d\n",
  2177. __func__, status);
  2178. return status;
  2179. }
  2180. dev_dbg(&pdev->dev, "%s: Register codec.\n", __func__);
  2181. status = snd_soc_register_codec(&pdev->dev, &ab8500_codec_driver,
  2182. ab8500_codec_dai,
  2183. ARRAY_SIZE(ab8500_codec_dai));
  2184. if (status < 0)
  2185. dev_err(&pdev->dev,
  2186. "%s: Error: Failed to register codec (%d).\n",
  2187. __func__, status);
  2188. return status;
  2189. }
  2190. static int ab8500_codec_driver_remove(struct platform_device *pdev)
  2191. {
  2192. dev_dbg(&pdev->dev, "%s Enter.\n", __func__);
  2193. snd_soc_unregister_codec(&pdev->dev);
  2194. return 0;
  2195. }
  2196. static struct platform_driver ab8500_codec_platform_driver = {
  2197. .driver = {
  2198. .name = "ab8500-codec",
  2199. },
  2200. .probe = ab8500_codec_driver_probe,
  2201. .remove = ab8500_codec_driver_remove,
  2202. .suspend = NULL,
  2203. .resume = NULL,
  2204. };
  2205. module_platform_driver(ab8500_codec_platform_driver);
  2206. MODULE_LICENSE("GPL v2");