88pm860x-codec.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * 88pm860x-codec.c -- 88PM860x ALSA SoC Audio Driver
  4. *
  5. * Copyright 2010 Marvell International Ltd.
  6. * Author: Haojian Zhuang <haojian.zhuang@marvell.com>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/i2c.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/mfd/88pm860x.h>
  13. #include <linux/slab.h>
  14. #include <linux/delay.h>
  15. #include <linux/regmap.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/pcm_params.h>
  19. #include <sound/soc.h>
  20. #include <sound/tlv.h>
  21. #include <sound/initval.h>
  22. #include <sound/jack.h>
  23. #include <trace/events/asoc.h>
  24. #include "88pm860x-codec.h"
  25. #define MAX_NAME_LEN 20
  26. #define REG_CACHE_SIZE 0x40
  27. #define REG_CACHE_BASE 0xb0
  28. /* Status Register 1 (0x01) */
  29. #define REG_STATUS_1 0x01
  30. #define MIC_STATUS (1 << 7)
  31. #define HOOK_STATUS (1 << 6)
  32. #define HEADSET_STATUS (1 << 5)
  33. /* Mic Detection Register (0x37) */
  34. #define REG_MIC_DET 0x37
  35. #define CONTINUOUS_POLLING (3 << 1)
  36. #define EN_MIC_DET (1 << 0)
  37. #define MICDET_MASK 0x07
  38. /* Headset Detection Register (0x38) */
  39. #define REG_HS_DET 0x38
  40. #define EN_HS_DET (1 << 0)
  41. /* Misc2 Register (0x42) */
  42. #define REG_MISC2 0x42
  43. #define AUDIO_PLL (1 << 5)
  44. #define AUDIO_SECTION_RESET (1 << 4)
  45. #define AUDIO_SECTION_ON (1 << 3)
  46. /* PCM Interface Register 2 (0xb1) */
  47. #define PCM_INF2_BCLK (1 << 6) /* Bit clock polarity */
  48. #define PCM_INF2_FS (1 << 5) /* Frame Sync polarity */
  49. #define PCM_INF2_MASTER (1 << 4) /* Master / Slave */
  50. #define PCM_INF2_18WL (1 << 3) /* 18 / 16 bits */
  51. #define PCM_GENERAL_I2S 0
  52. #define PCM_EXACT_I2S 1
  53. #define PCM_LEFT_I2S 2
  54. #define PCM_RIGHT_I2S 3
  55. #define PCM_SHORT_FS 4
  56. #define PCM_LONG_FS 5
  57. #define PCM_MODE_MASK 7
  58. /* I2S Interface Register 4 (0xbe) */
  59. #define I2S_EQU_BYP (1 << 6)
  60. /* DAC Offset Register (0xcb) */
  61. #define DAC_MUTE (1 << 7)
  62. #define MUTE_LEFT (1 << 6)
  63. #define MUTE_RIGHT (1 << 2)
  64. /* ADC Analog Register 1 (0xd0) */
  65. #define REG_ADC_ANA_1 0xd0
  66. #define MIC1BIAS_MASK 0x60
  67. /* Earpiece/Speaker Control Register 2 (0xda) */
  68. #define REG_EAR2 0xda
  69. #define RSYNC_CHANGE (1 << 2)
  70. /* Audio Supplies Register 2 (0xdc) */
  71. #define REG_SUPPLIES2 0xdc
  72. #define LDO15_READY (1 << 4)
  73. #define LDO15_EN (1 << 3)
  74. #define CPUMP_READY (1 << 2)
  75. #define CPUMP_EN (1 << 1)
  76. #define AUDIO_EN (1 << 0)
  77. #define SUPPLY_MASK (LDO15_EN | CPUMP_EN | AUDIO_EN)
  78. /* Audio Enable Register 1 (0xdd) */
  79. #define ADC_MOD_RIGHT (1 << 1)
  80. #define ADC_MOD_LEFT (1 << 0)
  81. /* Audio Enable Register 2 (0xde) */
  82. #define ADC_LEFT (1 << 5)
  83. #define ADC_RIGHT (1 << 4)
  84. /* DAC Enable Register 2 (0xe1) */
  85. #define DAC_LEFT (1 << 5)
  86. #define DAC_RIGHT (1 << 4)
  87. #define MODULATOR (1 << 3)
  88. /* Shorts Register (0xeb) */
  89. #define REG_SHORTS 0xeb
  90. #define CLR_SHORT_LO2 (1 << 7)
  91. #define SHORT_LO2 (1 << 6)
  92. #define CLR_SHORT_LO1 (1 << 5)
  93. #define SHORT_LO1 (1 << 4)
  94. #define CLR_SHORT_HS2 (1 << 3)
  95. #define SHORT_HS2 (1 << 2)
  96. #define CLR_SHORT_HS1 (1 << 1)
  97. #define SHORT_HS1 (1 << 0)
  98. /*
  99. * This widget should be just after DAC & PGA in DAPM power-on sequence and
  100. * before DAC & PGA in DAPM power-off sequence.
  101. */
  102. #define PM860X_DAPM_OUTPUT(wname, wevent) \
  103. SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, 0, 0, NULL, 0, wevent, \
  104. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD)
  105. struct pm860x_det {
  106. struct snd_soc_jack *hp_jack;
  107. struct snd_soc_jack *mic_jack;
  108. int hp_det;
  109. int mic_det;
  110. int hook_det;
  111. int hs_shrt;
  112. int lo_shrt;
  113. };
  114. struct pm860x_priv {
  115. unsigned int sysclk;
  116. unsigned int pcmclk;
  117. unsigned int dir;
  118. unsigned int filter;
  119. struct snd_soc_component *component;
  120. struct i2c_client *i2c;
  121. struct regmap *regmap;
  122. struct pm860x_chip *chip;
  123. struct pm860x_det det;
  124. int irq[4];
  125. unsigned char name[4][MAX_NAME_LEN+1];
  126. };
  127. /* -9450dB to 0dB in 150dB steps ( mute instead of -9450dB) */
  128. static const DECLARE_TLV_DB_SCALE(dpga_tlv, -9450, 150, 1);
  129. /* -9dB to 0db in 3dB steps */
  130. static const DECLARE_TLV_DB_SCALE(adc_tlv, -900, 300, 0);
  131. /* {-23, -17, -13.5, -11, -9, -6, -3, 0}dB */
  132. static const DECLARE_TLV_DB_RANGE(mic_tlv,
  133. 0, 0, TLV_DB_SCALE_ITEM(-2300, 0, 0),
  134. 1, 1, TLV_DB_SCALE_ITEM(-1700, 0, 0),
  135. 2, 2, TLV_DB_SCALE_ITEM(-1350, 0, 0),
  136. 3, 3, TLV_DB_SCALE_ITEM(-1100, 0, 0),
  137. 4, 7, TLV_DB_SCALE_ITEM(-900, 300, 0)
  138. );
  139. /* {0, 0, 0, -6, 0, 6, 12, 18}dB */
  140. static const DECLARE_TLV_DB_RANGE(aux_tlv,
  141. 0, 2, TLV_DB_SCALE_ITEM(0, 0, 0),
  142. 3, 7, TLV_DB_SCALE_ITEM(-600, 600, 0)
  143. );
  144. /* {-16, -13, -10, -7, -5.2, -3,3, -2.2, 0}dB, mute instead of -16dB */
  145. static const DECLARE_TLV_DB_RANGE(out_tlv,
  146. 0, 3, TLV_DB_SCALE_ITEM(-1600, 300, 1),
  147. 4, 4, TLV_DB_SCALE_ITEM(-520, 0, 0),
  148. 5, 5, TLV_DB_SCALE_ITEM(-330, 0, 0),
  149. 6, 7, TLV_DB_SCALE_ITEM(-220, 220, 0)
  150. );
  151. static const DECLARE_TLV_DB_RANGE(st_tlv,
  152. 0, 1, TLV_DB_SCALE_ITEM(-12041, 602, 0),
  153. 2, 3, TLV_DB_SCALE_ITEM(-11087, 250, 0),
  154. 4, 5, TLV_DB_SCALE_ITEM(-10643, 158, 0),
  155. 6, 7, TLV_DB_SCALE_ITEM(-10351, 116, 0),
  156. 8, 9, TLV_DB_SCALE_ITEM(-10133, 92, 0),
  157. 10, 13, TLV_DB_SCALE_ITEM(-9958, 70, 0),
  158. 14, 17, TLV_DB_SCALE_ITEM(-9689, 53, 0),
  159. 18, 271, TLV_DB_SCALE_ITEM(-9484, 37, 0)
  160. );
  161. /* Sidetone Gain = M * 2^(-5-N) */
  162. struct st_gain {
  163. unsigned int db;
  164. unsigned int m;
  165. unsigned int n;
  166. };
  167. static struct st_gain st_table[] = {
  168. {-12041, 1, 15}, {-11439, 1, 14}, {-11087, 3, 15}, {-10837, 1, 13},
  169. {-10643, 5, 15}, {-10485, 3, 14}, {-10351, 7, 15}, {-10235, 1, 12},
  170. {-10133, 9, 15}, {-10041, 5, 14}, { -9958, 11, 15}, { -9883, 3, 13},
  171. { -9813, 13, 15}, { -9749, 7, 14}, { -9689, 15, 15}, { -9633, 1, 11},
  172. { -9580, 17, 15}, { -9531, 9, 14}, { -9484, 19, 15}, { -9439, 5, 13},
  173. { -9397, 21, 15}, { -9356, 11, 14}, { -9318, 23, 15}, { -9281, 3, 12},
  174. { -9245, 25, 15}, { -9211, 13, 14}, { -9178, 27, 15}, { -9147, 7, 13},
  175. { -9116, 29, 15}, { -9087, 15, 14}, { -9058, 31, 15}, { -9031, 1, 10},
  176. { -8978, 17, 14}, { -8929, 9, 13}, { -8882, 19, 14}, { -8837, 5, 12},
  177. { -8795, 21, 14}, { -8754, 11, 13}, { -8716, 23, 14}, { -8679, 3, 11},
  178. { -8643, 25, 14}, { -8609, 13, 13}, { -8576, 27, 14}, { -8545, 7, 12},
  179. { -8514, 29, 14}, { -8485, 15, 13}, { -8456, 31, 14}, { -8429, 1, 9},
  180. { -8376, 17, 13}, { -8327, 9, 12}, { -8280, 19, 13}, { -8235, 5, 11},
  181. { -8193, 21, 13}, { -8152, 11, 12}, { -8114, 23, 13}, { -8077, 3, 10},
  182. { -8041, 25, 13}, { -8007, 13, 12}, { -7974, 27, 13}, { -7943, 7, 11},
  183. { -7912, 29, 13}, { -7883, 15, 12}, { -7854, 31, 13}, { -7827, 1, 8},
  184. { -7774, 17, 12}, { -7724, 9, 11}, { -7678, 19, 12}, { -7633, 5, 10},
  185. { -7591, 21, 12}, { -7550, 11, 11}, { -7512, 23, 12}, { -7475, 3, 9},
  186. { -7439, 25, 12}, { -7405, 13, 11}, { -7372, 27, 12}, { -7341, 7, 10},
  187. { -7310, 29, 12}, { -7281, 15, 11}, { -7252, 31, 12}, { -7225, 1, 7},
  188. { -7172, 17, 11}, { -7122, 9, 10}, { -7075, 19, 11}, { -7031, 5, 9},
  189. { -6989, 21, 11}, { -6948, 11, 10}, { -6910, 23, 11}, { -6873, 3, 8},
  190. { -6837, 25, 11}, { -6803, 13, 10}, { -6770, 27, 11}, { -6739, 7, 9},
  191. { -6708, 29, 11}, { -6679, 15, 10}, { -6650, 31, 11}, { -6623, 1, 6},
  192. { -6570, 17, 10}, { -6520, 9, 9}, { -6473, 19, 10}, { -6429, 5, 8},
  193. { -6386, 21, 10}, { -6346, 11, 9}, { -6307, 23, 10}, { -6270, 3, 7},
  194. { -6235, 25, 10}, { -6201, 13, 9}, { -6168, 27, 10}, { -6137, 7, 8},
  195. { -6106, 29, 10}, { -6077, 15, 9}, { -6048, 31, 10}, { -6021, 1, 5},
  196. { -5968, 17, 9}, { -5918, 9, 8}, { -5871, 19, 9}, { -5827, 5, 7},
  197. { -5784, 21, 9}, { -5744, 11, 8}, { -5705, 23, 9}, { -5668, 3, 6},
  198. { -5633, 25, 9}, { -5599, 13, 8}, { -5566, 27, 9}, { -5535, 7, 7},
  199. { -5504, 29, 9}, { -5475, 15, 8}, { -5446, 31, 9}, { -5419, 1, 4},
  200. { -5366, 17, 8}, { -5316, 9, 7}, { -5269, 19, 8}, { -5225, 5, 6},
  201. { -5182, 21, 8}, { -5142, 11, 7}, { -5103, 23, 8}, { -5066, 3, 5},
  202. { -5031, 25, 8}, { -4997, 13, 7}, { -4964, 27, 8}, { -4932, 7, 6},
  203. { -4902, 29, 8}, { -4873, 15, 7}, { -4844, 31, 8}, { -4816, 1, 3},
  204. { -4764, 17, 7}, { -4714, 9, 6}, { -4667, 19, 7}, { -4623, 5, 5},
  205. { -4580, 21, 7}, { -4540, 11, 6}, { -4501, 23, 7}, { -4464, 3, 4},
  206. { -4429, 25, 7}, { -4395, 13, 6}, { -4362, 27, 7}, { -4330, 7, 5},
  207. { -4300, 29, 7}, { -4270, 15, 6}, { -4242, 31, 7}, { -4214, 1, 2},
  208. { -4162, 17, 6}, { -4112, 9, 5}, { -4065, 19, 6}, { -4021, 5, 4},
  209. { -3978, 21, 6}, { -3938, 11, 5}, { -3899, 23, 6}, { -3862, 3, 3},
  210. { -3827, 25, 6}, { -3793, 13, 5}, { -3760, 27, 6}, { -3728, 7, 4},
  211. { -3698, 29, 6}, { -3668, 15, 5}, { -3640, 31, 6}, { -3612, 1, 1},
  212. { -3560, 17, 5}, { -3510, 9, 4}, { -3463, 19, 5}, { -3419, 5, 3},
  213. { -3376, 21, 5}, { -3336, 11, 4}, { -3297, 23, 5}, { -3260, 3, 2},
  214. { -3225, 25, 5}, { -3191, 13, 4}, { -3158, 27, 5}, { -3126, 7, 3},
  215. { -3096, 29, 5}, { -3066, 15, 4}, { -3038, 31, 5}, { -3010, 1, 0},
  216. { -2958, 17, 4}, { -2908, 9, 3}, { -2861, 19, 4}, { -2816, 5, 2},
  217. { -2774, 21, 4}, { -2734, 11, 3}, { -2695, 23, 4}, { -2658, 3, 1},
  218. { -2623, 25, 4}, { -2589, 13, 3}, { -2556, 27, 4}, { -2524, 7, 2},
  219. { -2494, 29, 4}, { -2464, 15, 3}, { -2436, 31, 4}, { -2408, 2, 0},
  220. { -2356, 17, 3}, { -2306, 9, 2}, { -2259, 19, 3}, { -2214, 5, 1},
  221. { -2172, 21, 3}, { -2132, 11, 2}, { -2093, 23, 3}, { -2056, 3, 0},
  222. { -2021, 25, 3}, { -1987, 13, 2}, { -1954, 27, 3}, { -1922, 7, 1},
  223. { -1892, 29, 3}, { -1862, 15, 2}, { -1834, 31, 3}, { -1806, 4, 0},
  224. { -1754, 17, 2}, { -1704, 9, 1}, { -1657, 19, 2}, { -1612, 5, 0},
  225. { -1570, 21, 2}, { -1530, 11, 1}, { -1491, 23, 2}, { -1454, 6, 0},
  226. { -1419, 25, 2}, { -1384, 13, 1}, { -1352, 27, 2}, { -1320, 7, 0},
  227. { -1290, 29, 2}, { -1260, 15, 1}, { -1232, 31, 2}, { -1204, 8, 0},
  228. { -1151, 17, 1}, { -1102, 9, 0}, { -1055, 19, 1}, { -1010, 10, 0},
  229. { -968, 21, 1}, { -928, 11, 0}, { -889, 23, 1}, { -852, 12, 0},
  230. { -816, 25, 1}, { -782, 13, 0}, { -750, 27, 1}, { -718, 14, 0},
  231. { -688, 29, 1}, { -658, 15, 0}, { -630, 31, 1}, { -602, 16, 0},
  232. { -549, 17, 0}, { -500, 18, 0}, { -453, 19, 0}, { -408, 20, 0},
  233. { -366, 21, 0}, { -325, 22, 0}, { -287, 23, 0}, { -250, 24, 0},
  234. { -214, 25, 0}, { -180, 26, 0}, { -148, 27, 0}, { -116, 28, 0},
  235. { -86, 29, 0}, { -56, 30, 0}, { -28, 31, 0}, { 0, 0, 0},
  236. };
  237. static int snd_soc_get_volsw_2r_st(struct snd_kcontrol *kcontrol,
  238. struct snd_ctl_elem_value *ucontrol)
  239. {
  240. struct soc_mixer_control *mc =
  241. (struct soc_mixer_control *)kcontrol->private_value;
  242. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  243. unsigned int reg = mc->reg;
  244. unsigned int reg2 = mc->rreg;
  245. int val[2], val2[2], i;
  246. val[0] = snd_soc_component_read(component, reg) & 0x3f;
  247. val[1] = (snd_soc_component_read(component, PM860X_SIDETONE_SHIFT) >> 4) & 0xf;
  248. val2[0] = snd_soc_component_read(component, reg2) & 0x3f;
  249. val2[1] = (snd_soc_component_read(component, PM860X_SIDETONE_SHIFT)) & 0xf;
  250. for (i = 0; i < ARRAY_SIZE(st_table); i++) {
  251. if ((st_table[i].m == val[0]) && (st_table[i].n == val[1]))
  252. ucontrol->value.integer.value[0] = i;
  253. if ((st_table[i].m == val2[0]) && (st_table[i].n == val2[1]))
  254. ucontrol->value.integer.value[1] = i;
  255. }
  256. return 0;
  257. }
  258. static int snd_soc_put_volsw_2r_st(struct snd_kcontrol *kcontrol,
  259. struct snd_ctl_elem_value *ucontrol)
  260. {
  261. struct soc_mixer_control *mc =
  262. (struct soc_mixer_control *)kcontrol->private_value;
  263. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  264. unsigned int reg = mc->reg;
  265. unsigned int reg2 = mc->rreg;
  266. int err;
  267. unsigned int val, val2;
  268. val = ucontrol->value.integer.value[0];
  269. val2 = ucontrol->value.integer.value[1];
  270. if (val >= ARRAY_SIZE(st_table) || val2 >= ARRAY_SIZE(st_table))
  271. return -EINVAL;
  272. err = snd_soc_component_update_bits(component, reg, 0x3f, st_table[val].m);
  273. if (err < 0)
  274. return err;
  275. err = snd_soc_component_update_bits(component, PM860X_SIDETONE_SHIFT, 0xf0,
  276. st_table[val].n << 4);
  277. if (err < 0)
  278. return err;
  279. err = snd_soc_component_update_bits(component, reg2, 0x3f, st_table[val2].m);
  280. if (err < 0)
  281. return err;
  282. err = snd_soc_component_update_bits(component, PM860X_SIDETONE_SHIFT, 0x0f,
  283. st_table[val2].n);
  284. return err;
  285. }
  286. static int snd_soc_get_volsw_2r_out(struct snd_kcontrol *kcontrol,
  287. struct snd_ctl_elem_value *ucontrol)
  288. {
  289. struct soc_mixer_control *mc =
  290. (struct soc_mixer_control *)kcontrol->private_value;
  291. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  292. unsigned int reg = mc->reg;
  293. unsigned int reg2 = mc->rreg;
  294. unsigned int shift = mc->shift;
  295. int max = mc->max, val, val2;
  296. unsigned int mask = (1 << fls(max)) - 1;
  297. val = snd_soc_component_read(component, reg) >> shift;
  298. val2 = snd_soc_component_read(component, reg2) >> shift;
  299. ucontrol->value.integer.value[0] = (max - val) & mask;
  300. ucontrol->value.integer.value[1] = (max - val2) & mask;
  301. return 0;
  302. }
  303. static int snd_soc_put_volsw_2r_out(struct snd_kcontrol *kcontrol,
  304. struct snd_ctl_elem_value *ucontrol)
  305. {
  306. struct soc_mixer_control *mc =
  307. (struct soc_mixer_control *)kcontrol->private_value;
  308. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  309. unsigned int reg = mc->reg;
  310. unsigned int reg2 = mc->rreg;
  311. unsigned int shift = mc->shift;
  312. int max = mc->max;
  313. unsigned int mask = (1 << fls(max)) - 1;
  314. int err;
  315. unsigned int val, val2, val_mask;
  316. val_mask = mask << shift;
  317. val = ((max - ucontrol->value.integer.value[0]) & mask);
  318. val2 = ((max - ucontrol->value.integer.value[1]) & mask);
  319. val = val << shift;
  320. val2 = val2 << shift;
  321. err = snd_soc_component_update_bits(component, reg, val_mask, val);
  322. if (err < 0)
  323. return err;
  324. err = snd_soc_component_update_bits(component, reg2, val_mask, val2);
  325. return err;
  326. }
  327. /* DAPM Widget Events */
  328. /*
  329. * A lot registers are belong to RSYNC domain. It requires enabling RSYNC bit
  330. * after updating these registers. Otherwise, these updated registers won't
  331. * be effective.
  332. */
  333. static int pm860x_rsync_event(struct snd_soc_dapm_widget *w,
  334. struct snd_kcontrol *kcontrol, int event)
  335. {
  336. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  337. /*
  338. * In order to avoid current on the load, mute power-on and power-off
  339. * should be transients.
  340. * Unmute by DAC_MUTE. It should be unmuted when DAPM sequence is
  341. * finished.
  342. */
  343. snd_soc_component_update_bits(component, PM860X_DAC_OFFSET, DAC_MUTE, 0);
  344. snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
  345. RSYNC_CHANGE, RSYNC_CHANGE);
  346. return 0;
  347. }
  348. static int pm860x_dac_event(struct snd_soc_dapm_widget *w,
  349. struct snd_kcontrol *kcontrol, int event)
  350. {
  351. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  352. unsigned int dac = 0;
  353. int data;
  354. if (!strcmp(w->name, "Left DAC"))
  355. dac = DAC_LEFT;
  356. if (!strcmp(w->name, "Right DAC"))
  357. dac = DAC_RIGHT;
  358. switch (event) {
  359. case SND_SOC_DAPM_PRE_PMU:
  360. if (dac) {
  361. /* Auto mute in power-on sequence. */
  362. dac |= MODULATOR;
  363. snd_soc_component_update_bits(component, PM860X_DAC_OFFSET,
  364. DAC_MUTE, DAC_MUTE);
  365. snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
  366. RSYNC_CHANGE, RSYNC_CHANGE);
  367. /* update dac */
  368. snd_soc_component_update_bits(component, PM860X_DAC_EN_2,
  369. dac, dac);
  370. }
  371. break;
  372. case SND_SOC_DAPM_PRE_PMD:
  373. if (dac) {
  374. /* Auto mute in power-off sequence. */
  375. snd_soc_component_update_bits(component, PM860X_DAC_OFFSET,
  376. DAC_MUTE, DAC_MUTE);
  377. snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
  378. RSYNC_CHANGE, RSYNC_CHANGE);
  379. /* update dac */
  380. data = snd_soc_component_read(component, PM860X_DAC_EN_2);
  381. data &= ~dac;
  382. if (!(data & (DAC_LEFT | DAC_RIGHT)))
  383. data &= ~MODULATOR;
  384. snd_soc_component_write(component, PM860X_DAC_EN_2, data);
  385. }
  386. break;
  387. }
  388. return 0;
  389. }
  390. static const char *pm860x_opamp_texts[] = {"-50%", "-25%", "0%", "75%"};
  391. static const char *pm860x_pa_texts[] = {"-33%", "0%", "33%", "66%"};
  392. static SOC_ENUM_SINGLE_DECL(pm860x_hs1_opamp_enum,
  393. PM860X_HS1_CTRL, 5, pm860x_opamp_texts);
  394. static SOC_ENUM_SINGLE_DECL(pm860x_hs2_opamp_enum,
  395. PM860X_HS2_CTRL, 5, pm860x_opamp_texts);
  396. static SOC_ENUM_SINGLE_DECL(pm860x_hs1_pa_enum,
  397. PM860X_HS1_CTRL, 3, pm860x_pa_texts);
  398. static SOC_ENUM_SINGLE_DECL(pm860x_hs2_pa_enum,
  399. PM860X_HS2_CTRL, 3, pm860x_pa_texts);
  400. static SOC_ENUM_SINGLE_DECL(pm860x_lo1_opamp_enum,
  401. PM860X_LO1_CTRL, 5, pm860x_opamp_texts);
  402. static SOC_ENUM_SINGLE_DECL(pm860x_lo2_opamp_enum,
  403. PM860X_LO2_CTRL, 5, pm860x_opamp_texts);
  404. static SOC_ENUM_SINGLE_DECL(pm860x_lo1_pa_enum,
  405. PM860X_LO1_CTRL, 3, pm860x_pa_texts);
  406. static SOC_ENUM_SINGLE_DECL(pm860x_lo2_pa_enum,
  407. PM860X_LO2_CTRL, 3, pm860x_pa_texts);
  408. static SOC_ENUM_SINGLE_DECL(pm860x_spk_pa_enum,
  409. PM860X_EAR_CTRL_1, 5, pm860x_pa_texts);
  410. static SOC_ENUM_SINGLE_DECL(pm860x_ear_pa_enum,
  411. PM860X_EAR_CTRL_2, 0, pm860x_pa_texts);
  412. static SOC_ENUM_SINGLE_DECL(pm860x_spk_ear_opamp_enum,
  413. PM860X_EAR_CTRL_1, 3, pm860x_opamp_texts);
  414. static const struct snd_kcontrol_new pm860x_snd_controls[] = {
  415. SOC_DOUBLE_R_TLV("ADC Capture Volume", PM860X_ADC_ANA_2,
  416. PM860X_ADC_ANA_3, 6, 3, 0, adc_tlv),
  417. SOC_DOUBLE_TLV("AUX Capture Volume", PM860X_ADC_ANA_3, 0, 3, 7, 0,
  418. aux_tlv),
  419. SOC_SINGLE_TLV("MIC1 Capture Volume", PM860X_ADC_ANA_2, 0, 7, 0,
  420. mic_tlv),
  421. SOC_SINGLE_TLV("MIC3 Capture Volume", PM860X_ADC_ANA_2, 3, 7, 0,
  422. mic_tlv),
  423. SOC_DOUBLE_R_EXT_TLV("Sidetone Volume", PM860X_SIDETONE_L_GAIN,
  424. PM860X_SIDETONE_R_GAIN, 0, ARRAY_SIZE(st_table)-1,
  425. 0, snd_soc_get_volsw_2r_st,
  426. snd_soc_put_volsw_2r_st, st_tlv),
  427. SOC_SINGLE_TLV("Speaker Playback Volume", PM860X_EAR_CTRL_1,
  428. 0, 7, 0, out_tlv),
  429. SOC_DOUBLE_R_TLV("Line Playback Volume", PM860X_LO1_CTRL,
  430. PM860X_LO2_CTRL, 0, 7, 0, out_tlv),
  431. SOC_DOUBLE_R_TLV("Headset Playback Volume", PM860X_HS1_CTRL,
  432. PM860X_HS2_CTRL, 0, 7, 0, out_tlv),
  433. SOC_DOUBLE_R_EXT_TLV("Hifi Left Playback Volume",
  434. PM860X_HIFIL_GAIN_LEFT,
  435. PM860X_HIFIL_GAIN_RIGHT, 0, 63, 0,
  436. snd_soc_get_volsw_2r_out,
  437. snd_soc_put_volsw_2r_out, dpga_tlv),
  438. SOC_DOUBLE_R_EXT_TLV("Hifi Right Playback Volume",
  439. PM860X_HIFIR_GAIN_LEFT,
  440. PM860X_HIFIR_GAIN_RIGHT, 0, 63, 0,
  441. snd_soc_get_volsw_2r_out,
  442. snd_soc_put_volsw_2r_out, dpga_tlv),
  443. SOC_DOUBLE_R_EXT_TLV("Lofi Playback Volume", PM860X_LOFI_GAIN_LEFT,
  444. PM860X_LOFI_GAIN_RIGHT, 0, 63, 0,
  445. snd_soc_get_volsw_2r_out,
  446. snd_soc_put_volsw_2r_out, dpga_tlv),
  447. SOC_ENUM("Headset1 Operational Amplifier Current",
  448. pm860x_hs1_opamp_enum),
  449. SOC_ENUM("Headset2 Operational Amplifier Current",
  450. pm860x_hs2_opamp_enum),
  451. SOC_ENUM("Headset1 Amplifier Current", pm860x_hs1_pa_enum),
  452. SOC_ENUM("Headset2 Amplifier Current", pm860x_hs2_pa_enum),
  453. SOC_ENUM("Lineout1 Operational Amplifier Current",
  454. pm860x_lo1_opamp_enum),
  455. SOC_ENUM("Lineout2 Operational Amplifier Current",
  456. pm860x_lo2_opamp_enum),
  457. SOC_ENUM("Lineout1 Amplifier Current", pm860x_lo1_pa_enum),
  458. SOC_ENUM("Lineout2 Amplifier Current", pm860x_lo2_pa_enum),
  459. SOC_ENUM("Speaker Operational Amplifier Current",
  460. pm860x_spk_ear_opamp_enum),
  461. SOC_ENUM("Speaker Amplifier Current", pm860x_spk_pa_enum),
  462. SOC_ENUM("Earpiece Amplifier Current", pm860x_ear_pa_enum),
  463. };
  464. /*
  465. * DAPM Controls
  466. */
  467. /* AUX1 Switch */
  468. static const struct snd_kcontrol_new aux1_switch_controls =
  469. SOC_DAPM_SINGLE("Switch", PM860X_ANA_TO_ANA, 4, 1, 0);
  470. /* AUX2 Switch */
  471. static const struct snd_kcontrol_new aux2_switch_controls =
  472. SOC_DAPM_SINGLE("Switch", PM860X_ANA_TO_ANA, 5, 1, 0);
  473. /* Left Ex. PA Switch */
  474. static const struct snd_kcontrol_new lepa_switch_controls =
  475. SOC_DAPM_SINGLE("Switch", PM860X_DAC_EN_2, 2, 1, 0);
  476. /* Right Ex. PA Switch */
  477. static const struct snd_kcontrol_new repa_switch_controls =
  478. SOC_DAPM_SINGLE("Switch", PM860X_DAC_EN_2, 1, 1, 0);
  479. /* I2S Mux / Mux9 */
  480. static const char *i2s_din_text[] = {
  481. "DIN", "DIN1",
  482. };
  483. static SOC_ENUM_SINGLE_DECL(i2s_din_enum,
  484. PM860X_I2S_IFACE_3, 1, i2s_din_text);
  485. static const struct snd_kcontrol_new i2s_din_mux =
  486. SOC_DAPM_ENUM("I2S DIN Mux", i2s_din_enum);
  487. /* I2S Mic Mux / Mux8 */
  488. static const char *i2s_mic_text[] = {
  489. "Ex PA", "ADC",
  490. };
  491. static SOC_ENUM_SINGLE_DECL(i2s_mic_enum,
  492. PM860X_I2S_IFACE_3, 4, i2s_mic_text);
  493. static const struct snd_kcontrol_new i2s_mic_mux =
  494. SOC_DAPM_ENUM("I2S Mic Mux", i2s_mic_enum);
  495. /* ADCL Mux / Mux2 */
  496. static const char *adcl_text[] = {
  497. "ADCR", "ADCL",
  498. };
  499. static SOC_ENUM_SINGLE_DECL(adcl_enum,
  500. PM860X_PCM_IFACE_3, 4, adcl_text);
  501. static const struct snd_kcontrol_new adcl_mux =
  502. SOC_DAPM_ENUM("ADC Left Mux", adcl_enum);
  503. /* ADCR Mux / Mux3 */
  504. static const char *adcr_text[] = {
  505. "ADCL", "ADCR",
  506. };
  507. static SOC_ENUM_SINGLE_DECL(adcr_enum,
  508. PM860X_PCM_IFACE_3, 2, adcr_text);
  509. static const struct snd_kcontrol_new adcr_mux =
  510. SOC_DAPM_ENUM("ADC Right Mux", adcr_enum);
  511. /* ADCR EC Mux / Mux6 */
  512. static const char *adcr_ec_text[] = {
  513. "ADCR", "EC",
  514. };
  515. static SOC_ENUM_SINGLE_DECL(adcr_ec_enum,
  516. PM860X_ADC_EN_2, 3, adcr_ec_text);
  517. static const struct snd_kcontrol_new adcr_ec_mux =
  518. SOC_DAPM_ENUM("ADCR EC Mux", adcr_ec_enum);
  519. /* EC Mux / Mux4 */
  520. static const char *ec_text[] = {
  521. "Left", "Right", "Left + Right",
  522. };
  523. static SOC_ENUM_SINGLE_DECL(ec_enum,
  524. PM860X_EC_PATH, 1, ec_text);
  525. static const struct snd_kcontrol_new ec_mux =
  526. SOC_DAPM_ENUM("EC Mux", ec_enum);
  527. static const char *dac_text[] = {
  528. "No input", "Right", "Left", "No input",
  529. };
  530. /* DAC Headset 1 Mux / Mux10 */
  531. static SOC_ENUM_SINGLE_DECL(dac_hs1_enum,
  532. PM860X_ANA_INPUT_SEL_1, 0, dac_text);
  533. static const struct snd_kcontrol_new dac_hs1_mux =
  534. SOC_DAPM_ENUM("DAC HS1 Mux", dac_hs1_enum);
  535. /* DAC Headset 2 Mux / Mux11 */
  536. static SOC_ENUM_SINGLE_DECL(dac_hs2_enum,
  537. PM860X_ANA_INPUT_SEL_1, 2, dac_text);
  538. static const struct snd_kcontrol_new dac_hs2_mux =
  539. SOC_DAPM_ENUM("DAC HS2 Mux", dac_hs2_enum);
  540. /* DAC Lineout 1 Mux / Mux12 */
  541. static SOC_ENUM_SINGLE_DECL(dac_lo1_enum,
  542. PM860X_ANA_INPUT_SEL_1, 4, dac_text);
  543. static const struct snd_kcontrol_new dac_lo1_mux =
  544. SOC_DAPM_ENUM("DAC LO1 Mux", dac_lo1_enum);
  545. /* DAC Lineout 2 Mux / Mux13 */
  546. static SOC_ENUM_SINGLE_DECL(dac_lo2_enum,
  547. PM860X_ANA_INPUT_SEL_1, 6, dac_text);
  548. static const struct snd_kcontrol_new dac_lo2_mux =
  549. SOC_DAPM_ENUM("DAC LO2 Mux", dac_lo2_enum);
  550. /* DAC Spearker Earphone Mux / Mux14 */
  551. static SOC_ENUM_SINGLE_DECL(dac_spk_ear_enum,
  552. PM860X_ANA_INPUT_SEL_2, 0, dac_text);
  553. static const struct snd_kcontrol_new dac_spk_ear_mux =
  554. SOC_DAPM_ENUM("DAC SP Mux", dac_spk_ear_enum);
  555. /* Headset 1 Mux / Mux15 */
  556. static const char *in_text[] = {
  557. "Digital", "Analog",
  558. };
  559. static SOC_ENUM_SINGLE_DECL(hs1_enum,
  560. PM860X_ANA_TO_ANA, 0, in_text);
  561. static const struct snd_kcontrol_new hs1_mux =
  562. SOC_DAPM_ENUM("Headset1 Mux", hs1_enum);
  563. /* Headset 2 Mux / Mux16 */
  564. static SOC_ENUM_SINGLE_DECL(hs2_enum,
  565. PM860X_ANA_TO_ANA, 1, in_text);
  566. static const struct snd_kcontrol_new hs2_mux =
  567. SOC_DAPM_ENUM("Headset2 Mux", hs2_enum);
  568. /* Lineout 1 Mux / Mux17 */
  569. static SOC_ENUM_SINGLE_DECL(lo1_enum,
  570. PM860X_ANA_TO_ANA, 2, in_text);
  571. static const struct snd_kcontrol_new lo1_mux =
  572. SOC_DAPM_ENUM("Lineout1 Mux", lo1_enum);
  573. /* Lineout 2 Mux / Mux18 */
  574. static SOC_ENUM_SINGLE_DECL(lo2_enum,
  575. PM860X_ANA_TO_ANA, 3, in_text);
  576. static const struct snd_kcontrol_new lo2_mux =
  577. SOC_DAPM_ENUM("Lineout2 Mux", lo2_enum);
  578. /* Speaker Earpiece Demux */
  579. static const char *spk_text[] = {
  580. "Earpiece", "Speaker",
  581. };
  582. static SOC_ENUM_SINGLE_DECL(spk_enum,
  583. PM860X_ANA_TO_ANA, 6, spk_text);
  584. static const struct snd_kcontrol_new spk_demux =
  585. SOC_DAPM_ENUM("Speaker Earpiece Demux", spk_enum);
  586. /* MIC Mux / Mux1 */
  587. static const char *mic_text[] = {
  588. "Mic 1", "Mic 2",
  589. };
  590. static SOC_ENUM_SINGLE_DECL(mic_enum,
  591. PM860X_ADC_ANA_4, 4, mic_text);
  592. static const struct snd_kcontrol_new mic_mux =
  593. SOC_DAPM_ENUM("MIC Mux", mic_enum);
  594. static const struct snd_soc_dapm_widget pm860x_dapm_widgets[] = {
  595. SND_SOC_DAPM_AIF_IN("PCM SDI", "PCM Playback", 0,
  596. PM860X_ADC_EN_2, 0, 0),
  597. SND_SOC_DAPM_AIF_OUT("PCM SDO", "PCM Capture", 0,
  598. PM860X_PCM_IFACE_3, 1, 1),
  599. SND_SOC_DAPM_AIF_IN("I2S DIN", "I2S Playback", 0,
  600. SND_SOC_NOPM, 0, 0),
  601. SND_SOC_DAPM_AIF_IN("I2S DIN1", "I2S Playback", 0,
  602. SND_SOC_NOPM, 0, 0),
  603. SND_SOC_DAPM_AIF_OUT("I2S DOUT", "I2S Capture", 0,
  604. PM860X_I2S_IFACE_3, 5, 1),
  605. SND_SOC_DAPM_SUPPLY("I2S CLK", PM860X_DAC_EN_2, 0, 0, NULL, 0),
  606. SND_SOC_DAPM_MUX("I2S Mic Mux", SND_SOC_NOPM, 0, 0, &i2s_mic_mux),
  607. SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM, 0, 0, &adcl_mux),
  608. SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM, 0, 0, &adcr_mux),
  609. SND_SOC_DAPM_MUX("EC Mux", SND_SOC_NOPM, 0, 0, &ec_mux),
  610. SND_SOC_DAPM_MUX("ADCR EC Mux", SND_SOC_NOPM, 0, 0, &adcr_ec_mux),
  611. SND_SOC_DAPM_SWITCH("Left EPA", SND_SOC_NOPM, 0, 0,
  612. &lepa_switch_controls),
  613. SND_SOC_DAPM_SWITCH("Right EPA", SND_SOC_NOPM, 0, 0,
  614. &repa_switch_controls),
  615. SND_SOC_DAPM_REG(snd_soc_dapm_supply, "Left ADC MOD", PM860X_ADC_EN_1,
  616. 0, 1, 1, 0),
  617. SND_SOC_DAPM_REG(snd_soc_dapm_supply, "Right ADC MOD", PM860X_ADC_EN_1,
  618. 1, 1, 1, 0),
  619. SND_SOC_DAPM_ADC("Left ADC", NULL, PM860X_ADC_EN_2, 5, 0),
  620. SND_SOC_DAPM_ADC("Right ADC", NULL, PM860X_ADC_EN_2, 4, 0),
  621. SND_SOC_DAPM_SWITCH("AUX1 Switch", SND_SOC_NOPM, 0, 0,
  622. &aux1_switch_controls),
  623. SND_SOC_DAPM_SWITCH("AUX2 Switch", SND_SOC_NOPM, 0, 0,
  624. &aux2_switch_controls),
  625. SND_SOC_DAPM_MUX("MIC Mux", SND_SOC_NOPM, 0, 0, &mic_mux),
  626. SND_SOC_DAPM_MICBIAS("Mic1 Bias", PM860X_ADC_ANA_1, 2, 0),
  627. SND_SOC_DAPM_MICBIAS("Mic3 Bias", PM860X_ADC_ANA_1, 7, 0),
  628. SND_SOC_DAPM_PGA("MIC1 Volume", PM860X_ADC_EN_1, 2, 0, NULL, 0),
  629. SND_SOC_DAPM_PGA("MIC3 Volume", PM860X_ADC_EN_1, 3, 0, NULL, 0),
  630. SND_SOC_DAPM_PGA("AUX1 Volume", PM860X_ADC_EN_1, 4, 0, NULL, 0),
  631. SND_SOC_DAPM_PGA("AUX2 Volume", PM860X_ADC_EN_1, 5, 0, NULL, 0),
  632. SND_SOC_DAPM_PGA("Sidetone PGA", PM860X_ADC_EN_2, 1, 0, NULL, 0),
  633. SND_SOC_DAPM_PGA("Lofi PGA", PM860X_ADC_EN_2, 2, 0, NULL, 0),
  634. SND_SOC_DAPM_INPUT("AUX1"),
  635. SND_SOC_DAPM_INPUT("AUX2"),
  636. SND_SOC_DAPM_INPUT("MIC1P"),
  637. SND_SOC_DAPM_INPUT("MIC1N"),
  638. SND_SOC_DAPM_INPUT("MIC2P"),
  639. SND_SOC_DAPM_INPUT("MIC2N"),
  640. SND_SOC_DAPM_INPUT("MIC3P"),
  641. SND_SOC_DAPM_INPUT("MIC3N"),
  642. SND_SOC_DAPM_DAC_E("Left DAC", NULL, SND_SOC_NOPM, 0, 0,
  643. pm860x_dac_event,
  644. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  645. SND_SOC_DAPM_DAC_E("Right DAC", NULL, SND_SOC_NOPM, 0, 0,
  646. pm860x_dac_event,
  647. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  648. SND_SOC_DAPM_MUX("I2S DIN Mux", SND_SOC_NOPM, 0, 0, &i2s_din_mux),
  649. SND_SOC_DAPM_MUX("DAC HS1 Mux", SND_SOC_NOPM, 0, 0, &dac_hs1_mux),
  650. SND_SOC_DAPM_MUX("DAC HS2 Mux", SND_SOC_NOPM, 0, 0, &dac_hs2_mux),
  651. SND_SOC_DAPM_MUX("DAC LO1 Mux", SND_SOC_NOPM, 0, 0, &dac_lo1_mux),
  652. SND_SOC_DAPM_MUX("DAC LO2 Mux", SND_SOC_NOPM, 0, 0, &dac_lo2_mux),
  653. SND_SOC_DAPM_MUX("DAC SP Mux", SND_SOC_NOPM, 0, 0, &dac_spk_ear_mux),
  654. SND_SOC_DAPM_MUX("Headset1 Mux", SND_SOC_NOPM, 0, 0, &hs1_mux),
  655. SND_SOC_DAPM_MUX("Headset2 Mux", SND_SOC_NOPM, 0, 0, &hs2_mux),
  656. SND_SOC_DAPM_MUX("Lineout1 Mux", SND_SOC_NOPM, 0, 0, &lo1_mux),
  657. SND_SOC_DAPM_MUX("Lineout2 Mux", SND_SOC_NOPM, 0, 0, &lo2_mux),
  658. SND_SOC_DAPM_MUX("Speaker Earpiece Demux", SND_SOC_NOPM, 0, 0,
  659. &spk_demux),
  660. SND_SOC_DAPM_PGA("Headset1 PGA", PM860X_DAC_EN_1, 0, 0, NULL, 0),
  661. SND_SOC_DAPM_PGA("Headset2 PGA", PM860X_DAC_EN_1, 1, 0, NULL, 0),
  662. SND_SOC_DAPM_OUTPUT("HS1"),
  663. SND_SOC_DAPM_OUTPUT("HS2"),
  664. SND_SOC_DAPM_PGA("Lineout1 PGA", PM860X_DAC_EN_1, 2, 0, NULL, 0),
  665. SND_SOC_DAPM_PGA("Lineout2 PGA", PM860X_DAC_EN_1, 3, 0, NULL, 0),
  666. SND_SOC_DAPM_OUTPUT("LINEOUT1"),
  667. SND_SOC_DAPM_OUTPUT("LINEOUT2"),
  668. SND_SOC_DAPM_PGA("Earpiece PGA", PM860X_DAC_EN_1, 4, 0, NULL, 0),
  669. SND_SOC_DAPM_OUTPUT("EARP"),
  670. SND_SOC_DAPM_OUTPUT("EARN"),
  671. SND_SOC_DAPM_PGA("Speaker PGA", PM860X_DAC_EN_1, 5, 0, NULL, 0),
  672. SND_SOC_DAPM_OUTPUT("LSP"),
  673. SND_SOC_DAPM_OUTPUT("LSN"),
  674. SND_SOC_DAPM_REG(snd_soc_dapm_supply, "VCODEC", PM860X_AUDIO_SUPPLIES_2,
  675. 0, SUPPLY_MASK, SUPPLY_MASK, 0),
  676. PM860X_DAPM_OUTPUT("RSYNC", pm860x_rsync_event),
  677. };
  678. static const struct snd_soc_dapm_route pm860x_dapm_routes[] = {
  679. /* supply */
  680. {"Left DAC", NULL, "VCODEC"},
  681. {"Right DAC", NULL, "VCODEC"},
  682. {"Left ADC", NULL, "VCODEC"},
  683. {"Right ADC", NULL, "VCODEC"},
  684. {"Left ADC", NULL, "Left ADC MOD"},
  685. {"Right ADC", NULL, "Right ADC MOD"},
  686. /* I2S Clock */
  687. {"I2S DIN", NULL, "I2S CLK"},
  688. {"I2S DIN1", NULL, "I2S CLK"},
  689. {"I2S DOUT", NULL, "I2S CLK"},
  690. /* PCM/AIF1 Inputs */
  691. {"PCM SDO", NULL, "ADC Left Mux"},
  692. {"PCM SDO", NULL, "ADCR EC Mux"},
  693. /* PCM/AFI2 Outputs */
  694. {"Lofi PGA", NULL, "PCM SDI"},
  695. {"Lofi PGA", NULL, "Sidetone PGA"},
  696. {"Left DAC", NULL, "Lofi PGA"},
  697. {"Right DAC", NULL, "Lofi PGA"},
  698. /* I2S/AIF2 Inputs */
  699. {"MIC Mux", "Mic 1", "MIC1P"},
  700. {"MIC Mux", "Mic 1", "MIC1N"},
  701. {"MIC Mux", "Mic 2", "MIC2P"},
  702. {"MIC Mux", "Mic 2", "MIC2N"},
  703. {"MIC1 Volume", NULL, "MIC Mux"},
  704. {"MIC3 Volume", NULL, "MIC3P"},
  705. {"MIC3 Volume", NULL, "MIC3N"},
  706. {"Left ADC", NULL, "MIC1 Volume"},
  707. {"Right ADC", NULL, "MIC3 Volume"},
  708. {"ADC Left Mux", "ADCR", "Right ADC"},
  709. {"ADC Left Mux", "ADCL", "Left ADC"},
  710. {"ADC Right Mux", "ADCL", "Left ADC"},
  711. {"ADC Right Mux", "ADCR", "Right ADC"},
  712. {"Left EPA", "Switch", "Left DAC"},
  713. {"Right EPA", "Switch", "Right DAC"},
  714. {"EC Mux", "Left", "Left DAC"},
  715. {"EC Mux", "Right", "Right DAC"},
  716. {"EC Mux", "Left + Right", "Left DAC"},
  717. {"EC Mux", "Left + Right", "Right DAC"},
  718. {"ADCR EC Mux", "ADCR", "ADC Right Mux"},
  719. {"ADCR EC Mux", "EC", "EC Mux"},
  720. {"I2S Mic Mux", "Ex PA", "Left EPA"},
  721. {"I2S Mic Mux", "Ex PA", "Right EPA"},
  722. {"I2S Mic Mux", "ADC", "ADC Left Mux"},
  723. {"I2S Mic Mux", "ADC", "ADCR EC Mux"},
  724. {"I2S DOUT", NULL, "I2S Mic Mux"},
  725. /* I2S/AIF2 Outputs */
  726. {"I2S DIN Mux", "DIN", "I2S DIN"},
  727. {"I2S DIN Mux", "DIN1", "I2S DIN1"},
  728. {"Left DAC", NULL, "I2S DIN Mux"},
  729. {"Right DAC", NULL, "I2S DIN Mux"},
  730. {"DAC HS1 Mux", "Left", "Left DAC"},
  731. {"DAC HS1 Mux", "Right", "Right DAC"},
  732. {"DAC HS2 Mux", "Left", "Left DAC"},
  733. {"DAC HS2 Mux", "Right", "Right DAC"},
  734. {"DAC LO1 Mux", "Left", "Left DAC"},
  735. {"DAC LO1 Mux", "Right", "Right DAC"},
  736. {"DAC LO2 Mux", "Left", "Left DAC"},
  737. {"DAC LO2 Mux", "Right", "Right DAC"},
  738. {"Headset1 Mux", "Digital", "DAC HS1 Mux"},
  739. {"Headset2 Mux", "Digital", "DAC HS2 Mux"},
  740. {"Lineout1 Mux", "Digital", "DAC LO1 Mux"},
  741. {"Lineout2 Mux", "Digital", "DAC LO2 Mux"},
  742. {"Headset1 PGA", NULL, "Headset1 Mux"},
  743. {"Headset2 PGA", NULL, "Headset2 Mux"},
  744. {"Lineout1 PGA", NULL, "Lineout1 Mux"},
  745. {"Lineout2 PGA", NULL, "Lineout2 Mux"},
  746. {"DAC SP Mux", "Left", "Left DAC"},
  747. {"DAC SP Mux", "Right", "Right DAC"},
  748. {"Speaker Earpiece Demux", "Speaker", "DAC SP Mux"},
  749. {"Speaker PGA", NULL, "Speaker Earpiece Demux"},
  750. {"Earpiece PGA", NULL, "Speaker Earpiece Demux"},
  751. {"RSYNC", NULL, "Headset1 PGA"},
  752. {"RSYNC", NULL, "Headset2 PGA"},
  753. {"RSYNC", NULL, "Lineout1 PGA"},
  754. {"RSYNC", NULL, "Lineout2 PGA"},
  755. {"RSYNC", NULL, "Speaker PGA"},
  756. {"RSYNC", NULL, "Speaker PGA"},
  757. {"RSYNC", NULL, "Earpiece PGA"},
  758. {"RSYNC", NULL, "Earpiece PGA"},
  759. {"HS1", NULL, "RSYNC"},
  760. {"HS2", NULL, "RSYNC"},
  761. {"LINEOUT1", NULL, "RSYNC"},
  762. {"LINEOUT2", NULL, "RSYNC"},
  763. {"LSP", NULL, "RSYNC"},
  764. {"LSN", NULL, "RSYNC"},
  765. {"EARP", NULL, "RSYNC"},
  766. {"EARN", NULL, "RSYNC"},
  767. };
  768. /*
  769. * Use MUTE_LEFT & MUTE_RIGHT to implement digital mute.
  770. * These bits can also be used to mute.
  771. */
  772. static int pm860x_mute_stream(struct snd_soc_dai *codec_dai, int mute, int direction)
  773. {
  774. struct snd_soc_component *component = codec_dai->component;
  775. int data = 0, mask = MUTE_LEFT | MUTE_RIGHT;
  776. if (mute)
  777. data = mask;
  778. snd_soc_component_update_bits(component, PM860X_DAC_OFFSET, mask, data);
  779. snd_soc_component_update_bits(component, PM860X_EAR_CTRL_2,
  780. RSYNC_CHANGE, RSYNC_CHANGE);
  781. return 0;
  782. }
  783. static int pm860x_pcm_hw_params(struct snd_pcm_substream *substream,
  784. struct snd_pcm_hw_params *params,
  785. struct snd_soc_dai *dai)
  786. {
  787. struct snd_soc_component *component = dai->component;
  788. unsigned char inf = 0, mask = 0;
  789. /* bit size */
  790. switch (params_width(params)) {
  791. case 16:
  792. inf &= ~PCM_INF2_18WL;
  793. break;
  794. case 18:
  795. inf |= PCM_INF2_18WL;
  796. break;
  797. default:
  798. return -EINVAL;
  799. }
  800. mask |= PCM_INF2_18WL;
  801. snd_soc_component_update_bits(component, PM860X_PCM_IFACE_2, mask, inf);
  802. /* sample rate */
  803. switch (params_rate(params)) {
  804. case 8000:
  805. inf = 0;
  806. break;
  807. case 16000:
  808. inf = 3;
  809. break;
  810. case 32000:
  811. inf = 6;
  812. break;
  813. case 48000:
  814. inf = 8;
  815. break;
  816. default:
  817. return -EINVAL;
  818. }
  819. snd_soc_component_update_bits(component, PM860X_PCM_RATE, 0x0f, inf);
  820. return 0;
  821. }
  822. static int pm860x_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai,
  823. unsigned int fmt)
  824. {
  825. struct snd_soc_component *component = codec_dai->component;
  826. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  827. unsigned char inf = 0, mask = 0;
  828. int ret = -EINVAL;
  829. mask |= PCM_INF2_BCLK | PCM_INF2_FS | PCM_INF2_MASTER;
  830. /* set master/slave audio interface */
  831. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  832. case SND_SOC_DAIFMT_CBM_CFM:
  833. case SND_SOC_DAIFMT_CBM_CFS:
  834. if (pm860x->dir == PM860X_CLK_DIR_OUT) {
  835. inf |= PCM_INF2_MASTER;
  836. ret = 0;
  837. }
  838. break;
  839. case SND_SOC_DAIFMT_CBS_CFS:
  840. if (pm860x->dir == PM860X_CLK_DIR_IN) {
  841. inf &= ~PCM_INF2_MASTER;
  842. ret = 0;
  843. }
  844. break;
  845. }
  846. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  847. case SND_SOC_DAIFMT_I2S:
  848. inf |= PCM_EXACT_I2S;
  849. ret = 0;
  850. break;
  851. }
  852. mask |= PCM_MODE_MASK;
  853. if (ret)
  854. return ret;
  855. snd_soc_component_update_bits(component, PM860X_PCM_IFACE_2, mask, inf);
  856. return 0;
  857. }
  858. static int pm860x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  859. int clk_id, unsigned int freq, int dir)
  860. {
  861. struct snd_soc_component *component = codec_dai->component;
  862. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  863. if (dir == PM860X_CLK_DIR_OUT)
  864. pm860x->dir = PM860X_CLK_DIR_OUT;
  865. else /* Slave mode is not supported */
  866. return -EINVAL;
  867. return 0;
  868. }
  869. static int pm860x_i2s_hw_params(struct snd_pcm_substream *substream,
  870. struct snd_pcm_hw_params *params,
  871. struct snd_soc_dai *dai)
  872. {
  873. struct snd_soc_component *component = dai->component;
  874. unsigned char inf;
  875. /* bit size */
  876. switch (params_width(params)) {
  877. case 16:
  878. inf = 0;
  879. break;
  880. case 18:
  881. inf = PCM_INF2_18WL;
  882. break;
  883. default:
  884. return -EINVAL;
  885. }
  886. snd_soc_component_update_bits(component, PM860X_I2S_IFACE_2, PCM_INF2_18WL, inf);
  887. /* sample rate */
  888. switch (params_rate(params)) {
  889. case 8000:
  890. inf = 0;
  891. break;
  892. case 11025:
  893. inf = 1;
  894. break;
  895. case 16000:
  896. inf = 3;
  897. break;
  898. case 22050:
  899. inf = 4;
  900. break;
  901. case 32000:
  902. inf = 6;
  903. break;
  904. case 44100:
  905. inf = 7;
  906. break;
  907. case 48000:
  908. inf = 8;
  909. break;
  910. default:
  911. return -EINVAL;
  912. }
  913. snd_soc_component_update_bits(component, PM860X_I2S_IFACE_4, 0xf, inf);
  914. return 0;
  915. }
  916. static int pm860x_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
  917. unsigned int fmt)
  918. {
  919. struct snd_soc_component *component = codec_dai->component;
  920. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  921. unsigned char inf = 0, mask = 0;
  922. mask |= PCM_INF2_BCLK | PCM_INF2_FS | PCM_INF2_MASTER;
  923. /* set master/slave audio interface */
  924. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  925. case SND_SOC_DAIFMT_CBM_CFM:
  926. if (pm860x->dir == PM860X_CLK_DIR_OUT)
  927. inf |= PCM_INF2_MASTER;
  928. else
  929. return -EINVAL;
  930. break;
  931. case SND_SOC_DAIFMT_CBS_CFS:
  932. if (pm860x->dir == PM860X_CLK_DIR_IN)
  933. inf &= ~PCM_INF2_MASTER;
  934. else
  935. return -EINVAL;
  936. break;
  937. default:
  938. return -EINVAL;
  939. }
  940. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  941. case SND_SOC_DAIFMT_I2S:
  942. inf |= PCM_EXACT_I2S;
  943. break;
  944. default:
  945. return -EINVAL;
  946. }
  947. mask |= PCM_MODE_MASK;
  948. snd_soc_component_update_bits(component, PM860X_I2S_IFACE_2, mask, inf);
  949. return 0;
  950. }
  951. static int pm860x_set_bias_level(struct snd_soc_component *component,
  952. enum snd_soc_bias_level level)
  953. {
  954. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  955. int data;
  956. switch (level) {
  957. case SND_SOC_BIAS_ON:
  958. break;
  959. case SND_SOC_BIAS_PREPARE:
  960. break;
  961. case SND_SOC_BIAS_STANDBY:
  962. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
  963. /* Enable Audio PLL & Audio section */
  964. data = AUDIO_PLL | AUDIO_SECTION_ON;
  965. pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
  966. udelay(300);
  967. data = AUDIO_PLL | AUDIO_SECTION_RESET
  968. | AUDIO_SECTION_ON;
  969. pm860x_reg_write(pm860x->i2c, REG_MISC2, data);
  970. }
  971. break;
  972. case SND_SOC_BIAS_OFF:
  973. data = AUDIO_PLL | AUDIO_SECTION_RESET | AUDIO_SECTION_ON;
  974. pm860x_set_bits(pm860x->i2c, REG_MISC2, data, 0);
  975. break;
  976. }
  977. return 0;
  978. }
  979. static const struct snd_soc_dai_ops pm860x_pcm_dai_ops = {
  980. .mute_stream = pm860x_mute_stream,
  981. .hw_params = pm860x_pcm_hw_params,
  982. .set_fmt = pm860x_pcm_set_dai_fmt,
  983. .set_sysclk = pm860x_set_dai_sysclk,
  984. .no_capture_mute = 1,
  985. };
  986. static const struct snd_soc_dai_ops pm860x_i2s_dai_ops = {
  987. .mute_stream = pm860x_mute_stream,
  988. .hw_params = pm860x_i2s_hw_params,
  989. .set_fmt = pm860x_i2s_set_dai_fmt,
  990. .set_sysclk = pm860x_set_dai_sysclk,
  991. .no_capture_mute = 1,
  992. };
  993. #define PM860X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | \
  994. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
  995. static struct snd_soc_dai_driver pm860x_dai[] = {
  996. {
  997. /* DAI PCM */
  998. .name = "88pm860x-pcm",
  999. .id = 1,
  1000. .playback = {
  1001. .stream_name = "PCM Playback",
  1002. .channels_min = 2,
  1003. .channels_max = 2,
  1004. .rates = PM860X_RATES,
  1005. .formats = SNDRV_PCM_FMTBIT_S16_LE | \
  1006. SNDRV_PCM_FMTBIT_S18_3LE,
  1007. },
  1008. .capture = {
  1009. .stream_name = "PCM Capture",
  1010. .channels_min = 2,
  1011. .channels_max = 2,
  1012. .rates = PM860X_RATES,
  1013. .formats = SNDRV_PCM_FMTBIT_S16_LE | \
  1014. SNDRV_PCM_FMTBIT_S18_3LE,
  1015. },
  1016. .ops = &pm860x_pcm_dai_ops,
  1017. }, {
  1018. /* DAI I2S */
  1019. .name = "88pm860x-i2s",
  1020. .id = 2,
  1021. .playback = {
  1022. .stream_name = "I2S Playback",
  1023. .channels_min = 2,
  1024. .channels_max = 2,
  1025. .rates = SNDRV_PCM_RATE_8000_48000,
  1026. .formats = SNDRV_PCM_FMTBIT_S16_LE | \
  1027. SNDRV_PCM_FMTBIT_S18_3LE,
  1028. },
  1029. .capture = {
  1030. .stream_name = "I2S Capture",
  1031. .channels_min = 2,
  1032. .channels_max = 2,
  1033. .rates = SNDRV_PCM_RATE_8000_48000,
  1034. .formats = SNDRV_PCM_FMTBIT_S16_LE | \
  1035. SNDRV_PCM_FMTBIT_S18_3LE,
  1036. },
  1037. .ops = &pm860x_i2s_dai_ops,
  1038. },
  1039. };
  1040. static irqreturn_t pm860x_component_handler(int irq, void *data)
  1041. {
  1042. struct pm860x_priv *pm860x = data;
  1043. int status, shrt, report = 0, mic_report = 0;
  1044. int mask;
  1045. status = pm860x_reg_read(pm860x->i2c, REG_STATUS_1);
  1046. shrt = pm860x_reg_read(pm860x->i2c, REG_SHORTS);
  1047. mask = pm860x->det.hs_shrt | pm860x->det.hook_det | pm860x->det.lo_shrt
  1048. | pm860x->det.hp_det;
  1049. #ifndef CONFIG_SND_SOC_88PM860X_MODULE
  1050. if (status & (HEADSET_STATUS | MIC_STATUS | SHORT_HS1 | SHORT_HS2 |
  1051. SHORT_LO1 | SHORT_LO2))
  1052. trace_snd_soc_jack_irq(dev_name(pm860x->component->dev));
  1053. #endif
  1054. if ((pm860x->det.hp_det & SND_JACK_HEADPHONE)
  1055. && (status & HEADSET_STATUS))
  1056. report |= SND_JACK_HEADPHONE;
  1057. if ((pm860x->det.mic_det & SND_JACK_MICROPHONE)
  1058. && (status & MIC_STATUS))
  1059. mic_report |= SND_JACK_MICROPHONE;
  1060. if (pm860x->det.hs_shrt && (shrt & (SHORT_HS1 | SHORT_HS2)))
  1061. report |= pm860x->det.hs_shrt;
  1062. if (pm860x->det.hook_det && (status & HOOK_STATUS))
  1063. report |= pm860x->det.hook_det;
  1064. if (pm860x->det.lo_shrt && (shrt & (SHORT_LO1 | SHORT_LO2)))
  1065. report |= pm860x->det.lo_shrt;
  1066. if (report)
  1067. snd_soc_jack_report(pm860x->det.hp_jack, report, mask);
  1068. if (mic_report)
  1069. snd_soc_jack_report(pm860x->det.mic_jack, SND_JACK_MICROPHONE,
  1070. SND_JACK_MICROPHONE);
  1071. dev_dbg(pm860x->component->dev, "headphone report:0x%x, mask:%x\n",
  1072. report, mask);
  1073. dev_dbg(pm860x->component->dev, "microphone report:0x%x\n", mic_report);
  1074. return IRQ_HANDLED;
  1075. }
  1076. int pm860x_hs_jack_detect(struct snd_soc_component *component,
  1077. struct snd_soc_jack *jack,
  1078. int det, int hook, int hs_shrt, int lo_shrt)
  1079. {
  1080. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  1081. int data;
  1082. pm860x->det.hp_jack = jack;
  1083. pm860x->det.hp_det = det;
  1084. pm860x->det.hook_det = hook;
  1085. pm860x->det.hs_shrt = hs_shrt;
  1086. pm860x->det.lo_shrt = lo_shrt;
  1087. if (det & SND_JACK_HEADPHONE)
  1088. pm860x_set_bits(pm860x->i2c, REG_HS_DET,
  1089. EN_HS_DET, EN_HS_DET);
  1090. /* headset short detect */
  1091. if (hs_shrt) {
  1092. data = CLR_SHORT_HS2 | CLR_SHORT_HS1;
  1093. pm860x_set_bits(pm860x->i2c, REG_SHORTS, data, data);
  1094. }
  1095. /* Lineout short detect */
  1096. if (lo_shrt) {
  1097. data = CLR_SHORT_LO2 | CLR_SHORT_LO1;
  1098. pm860x_set_bits(pm860x->i2c, REG_SHORTS, data, data);
  1099. }
  1100. /* sync status */
  1101. pm860x_component_handler(0, pm860x);
  1102. return 0;
  1103. }
  1104. EXPORT_SYMBOL_GPL(pm860x_hs_jack_detect);
  1105. int pm860x_mic_jack_detect(struct snd_soc_component *component,
  1106. struct snd_soc_jack *jack, int det)
  1107. {
  1108. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  1109. pm860x->det.mic_jack = jack;
  1110. pm860x->det.mic_det = det;
  1111. if (det & SND_JACK_MICROPHONE)
  1112. pm860x_set_bits(pm860x->i2c, REG_MIC_DET,
  1113. MICDET_MASK, MICDET_MASK);
  1114. /* sync status */
  1115. pm860x_component_handler(0, pm860x);
  1116. return 0;
  1117. }
  1118. EXPORT_SYMBOL_GPL(pm860x_mic_jack_detect);
  1119. static int pm860x_probe(struct snd_soc_component *component)
  1120. {
  1121. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  1122. int i, ret;
  1123. pm860x->component = component;
  1124. snd_soc_component_init_regmap(component, pm860x->regmap);
  1125. for (i = 0; i < 4; i++) {
  1126. ret = request_threaded_irq(pm860x->irq[i], NULL,
  1127. pm860x_component_handler, IRQF_ONESHOT,
  1128. pm860x->name[i], pm860x);
  1129. if (ret < 0) {
  1130. dev_err(component->dev, "Failed to request IRQ!\n");
  1131. goto out;
  1132. }
  1133. }
  1134. return 0;
  1135. out:
  1136. while (--i >= 0)
  1137. free_irq(pm860x->irq[i], pm860x);
  1138. return ret;
  1139. }
  1140. static void pm860x_remove(struct snd_soc_component *component)
  1141. {
  1142. struct pm860x_priv *pm860x = snd_soc_component_get_drvdata(component);
  1143. int i;
  1144. for (i = 3; i >= 0; i--)
  1145. free_irq(pm860x->irq[i], pm860x);
  1146. }
  1147. static const struct snd_soc_component_driver soc_component_dev_pm860x = {
  1148. .probe = pm860x_probe,
  1149. .remove = pm860x_remove,
  1150. .set_bias_level = pm860x_set_bias_level,
  1151. .controls = pm860x_snd_controls,
  1152. .num_controls = ARRAY_SIZE(pm860x_snd_controls),
  1153. .dapm_widgets = pm860x_dapm_widgets,
  1154. .num_dapm_widgets = ARRAY_SIZE(pm860x_dapm_widgets),
  1155. .dapm_routes = pm860x_dapm_routes,
  1156. .num_dapm_routes = ARRAY_SIZE(pm860x_dapm_routes),
  1157. .idle_bias_on = 1,
  1158. .use_pmdown_time = 1,
  1159. .endianness = 1,
  1160. .non_legacy_dai_naming = 1,
  1161. };
  1162. static int pm860x_codec_probe(struct platform_device *pdev)
  1163. {
  1164. struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
  1165. struct pm860x_priv *pm860x;
  1166. struct resource *res;
  1167. int i, ret;
  1168. pm860x = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_priv),
  1169. GFP_KERNEL);
  1170. if (pm860x == NULL)
  1171. return -ENOMEM;
  1172. pm860x->chip = chip;
  1173. pm860x->i2c = (chip->id == CHIP_PM8607) ? chip->client
  1174. : chip->companion;
  1175. pm860x->regmap = (chip->id == CHIP_PM8607) ? chip->regmap
  1176. : chip->regmap_companion;
  1177. platform_set_drvdata(pdev, pm860x);
  1178. for (i = 0; i < 4; i++) {
  1179. res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
  1180. if (!res) {
  1181. dev_err(&pdev->dev, "Failed to get IRQ resources\n");
  1182. return -EINVAL;
  1183. }
  1184. pm860x->irq[i] = res->start + chip->irq_base;
  1185. strncpy(pm860x->name[i], res->name, MAX_NAME_LEN);
  1186. }
  1187. ret = devm_snd_soc_register_component(&pdev->dev,
  1188. &soc_component_dev_pm860x,
  1189. pm860x_dai, ARRAY_SIZE(pm860x_dai));
  1190. if (ret) {
  1191. dev_err(&pdev->dev, "Failed to register component\n");
  1192. return -EINVAL;
  1193. }
  1194. return ret;
  1195. }
  1196. static int pm860x_codec_remove(struct platform_device *pdev)
  1197. {
  1198. return 0;
  1199. }
  1200. static struct platform_driver pm860x_codec_driver = {
  1201. .driver = {
  1202. .name = "88pm860x-codec",
  1203. },
  1204. .probe = pm860x_codec_probe,
  1205. .remove = pm860x_codec_remove,
  1206. };
  1207. module_platform_driver(pm860x_codec_driver);
  1208. MODULE_DESCRIPTION("ASoC 88PM860x driver");
  1209. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  1210. MODULE_LICENSE("GPL");
  1211. MODULE_ALIAS("platform:88pm860x-codec");