88pm860x-codec.c 43 KB

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