es8316.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. /*
  2. * es8316.c -- es8316 ALSA SoC audio driver
  3. * Copyright Everest Semiconductor Co.,Ltd
  4. *
  5. * Author: David Yang <yangxiaohua@everest-semi.com>
  6. *
  7. * Based on es8316.c
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/i2c.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/slab.h>
  22. #include <linux/of_gpio.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/pcm_params.h>
  26. #include <sound/tlv.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <sound/initval.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/gpio.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/irq.h>
  34. #include <linux/regmap.h>
  35. #include "es8316.h"
  36. #define INVALID_GPIO -1
  37. #define GPIO_LOW 0
  38. #define GPIO_HIGH 1
  39. #define es8316_DEF_VOL 0x1e
  40. static struct snd_soc_component *es8316_component;
  41. static const struct reg_default es8316_reg_defaults[] = {
  42. {0x00, 0x03}, {0x01, 0x03}, {0x02, 0x00}, {0x03, 0x20},
  43. {0x04, 0x11}, {0x05, 0x00}, {0x06, 0x11}, {0x07, 0x00},
  44. {0x08, 0x00}, {0x09, 0x01}, {0x0a, 0x00}, {0x0b, 0x00},
  45. {0x0c, 0xf8}, {0x0d, 0x3f}, {0x0e, 0x00}, {0x0f, 0x00},
  46. {0x10, 0x01}, {0x11, 0xfc}, {0x12, 0x28}, {0x13, 0x00},
  47. {0x14, 0x00}, {0x15, 0x33}, {0x16, 0x00}, {0x17, 0x00},
  48. {0x18, 0x88}, {0x19, 0x06}, {0x1a, 0x22}, {0x1b, 0x03},
  49. {0x1c, 0x0f}, {0x1d, 0x00}, {0x1e, 0x80}, {0x1f, 0x80},
  50. {0x20, 0x00}, {0x21, 0x00}, {0x22, 0xc0}, {0x23, 0x00},
  51. {0x24, 0x01}, {0x25, 0x08}, {0x26, 0x10}, {0x27, 0xc0},
  52. {0x28, 0x00}, {0x29, 0x1c}, {0x2a, 0x00}, {0x2b, 0xb0},
  53. {0x2c, 0x32}, {0x2d, 0x03}, {0x2e, 0x00}, {0x2f, 0x11},
  54. {0x30, 0x10}, {0x31, 0x00}, {0x32, 0x00}, {0x33, 0xc0},
  55. {0x34, 0xc0}, {0x35, 0x1f}, {0x36, 0xf7}, {0x37, 0xfd},
  56. {0x38, 0xff}, {0x39, 0x1f}, {0x3a, 0xf7}, {0x3b, 0xfd},
  57. {0x3c, 0xff}, {0x3d, 0x1f}, {0x3e, 0xf7}, {0x3f, 0xfd},
  58. {0x40, 0xff}, {0x41, 0x1f}, {0x42, 0xf7}, {0x43, 0xfd},
  59. {0x44, 0xff}, {0x45, 0x1f}, {0x46, 0xf7}, {0x47, 0xfd},
  60. {0x48, 0xff}, {0x49, 0x1f}, {0x4a, 0xf7}, {0x4b, 0xfd},
  61. {0x4c, 0xff}, {0x4d, 0x00}, {0x4e, 0x00}, {0x4f, 0xff},
  62. {0x50, 0x00}, {0x51, 0x00}, {0x52, 0x00}, {0x53, 0x00},
  63. };
  64. /* codec private data */
  65. struct es8316_priv {
  66. struct regmap *regmap;
  67. unsigned int dmic_amic;
  68. unsigned int sysclk;
  69. struct snd_pcm_hw_constraint_list *sysclk_constraints;
  70. struct clk *mclk;
  71. int debounce_time;
  72. int hp_det_invert;
  73. struct delayed_work work;
  74. int spk_ctl_gpio;
  75. int hp_det_gpio;
  76. bool muted;
  77. bool hp_inserted;
  78. bool spk_active_level;
  79. int pwr_count;
  80. };
  81. /*
  82. * es8316_reset
  83. * write value 0xff to reg0x00, the chip will be in reset mode
  84. * then, writer 0x00 to reg0x00, unreset the chip
  85. */
  86. static int es8316_reset(struct snd_soc_component *component)
  87. {
  88. snd_soc_component_write(component, ES8316_RESET_REG00, 0x3F);
  89. usleep_range(5000, 5500);
  90. return snd_soc_component_write(component, ES8316_RESET_REG00, 0x03);
  91. }
  92. static void es8316_enable_spk(struct es8316_priv *es8316, bool enable)
  93. {
  94. bool level;
  95. level = enable ? es8316->spk_active_level : !es8316->spk_active_level;
  96. gpio_set_value(es8316->spk_ctl_gpio, level);
  97. }
  98. static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -9600, 50, 1);
  99. static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -9600, 50, 1);
  100. static const DECLARE_TLV_DB_SCALE(hpmixer_gain_tlv, -1200, 150, 0);
  101. static const DECLARE_TLV_DB_SCALE(mic_bst_tlv, 0, 1200, 0);
  102. static unsigned int linin_pga_tlv[] = {
  103. TLV_DB_RANGE_HEAD(9),
  104. 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
  105. 1, 1, TLV_DB_SCALE_ITEM(300, 0, 0),
  106. 2, 2, TLV_DB_SCALE_ITEM(600, 0, 0),
  107. 3, 3, TLV_DB_SCALE_ITEM(900, 0, 0),
  108. 4, 4, TLV_DB_SCALE_ITEM(1200, 0, 0),
  109. 5, 5, TLV_DB_SCALE_ITEM(1500, 0, 0),
  110. 6, 6, TLV_DB_SCALE_ITEM(1800, 0, 0),
  111. 7, 7, TLV_DB_SCALE_ITEM(2100, 0, 0),
  112. 8, 8, TLV_DB_SCALE_ITEM(2400, 0, 0),
  113. };
  114. static unsigned int hpout_vol_tlv[] = {
  115. TLV_DB_RANGE_HEAD(1),
  116. 0, 3, TLV_DB_SCALE_ITEM(-4800, 1200, 0),
  117. };
  118. static const char *const alc_func_txt[] = { "Off", "On" };
  119. static const struct soc_enum alc_func =
  120. SOC_ENUM_SINGLE(ES8316_ADC_ALC1_REG29, 6, 2, alc_func_txt);
  121. static const char *const ng_type_txt[] = {
  122. "Constant PGA Gain", "Mute ADC Output" };
  123. static const struct soc_enum ng_type =
  124. SOC_ENUM_SINGLE(ES8316_ADC_ALC6_REG2E, 6, 2, ng_type_txt);
  125. static const char *const adcpol_txt[] = { "Normal", "Invert" };
  126. static const struct soc_enum adcpol =
  127. SOC_ENUM_SINGLE(ES8316_ADC_MUTE_REG26, 1, 2, adcpol_txt);
  128. static const char *const dacpol_txt[] = {
  129. "Normal", "R Invert", "L Invert", "L + R Invert" };
  130. static const struct soc_enum dacpol =
  131. SOC_ENUM_SINGLE(ES8316_DAC_SET1_REG30, 0, 4, dacpol_txt);
  132. static const struct snd_kcontrol_new es8316_snd_controls[] = {
  133. /* HP OUT VOLUME */
  134. SOC_DOUBLE_TLV("HP Playback Volume", ES8316_CPHP_ICAL_VOL_REG18,
  135. 4, 0, 4, 1, hpout_vol_tlv),
  136. /* HPMIXER VOLUME Control */
  137. SOC_DOUBLE_TLV("HPMixer Gain", ES8316_HPMIX_VOL_REG16,
  138. 0, 4, 7, 0, hpmixer_gain_tlv),
  139. /* DAC Digital controls */
  140. SOC_DOUBLE_R_TLV("DAC Playback Volume", ES8316_DAC_VOLL_REG33,
  141. ES8316_DAC_VOLR_REG34, 0, 0xC0, 1, dac_vol_tlv),
  142. SOC_SINGLE("Enable DAC Soft Ramp", ES8316_DAC_SET1_REG30, 4, 1, 1),
  143. SOC_SINGLE("DAC Soft Ramp Rate", ES8316_DAC_SET1_REG30, 2, 4, 0),
  144. SOC_ENUM("Playback Polarity", dacpol),
  145. SOC_SINGLE("DAC Notch Filter", ES8316_DAC_SET2_REG31, 6, 1, 0),
  146. SOC_SINGLE("DAC Double Fs Mode", ES8316_DAC_SET2_REG31, 7, 1, 0),
  147. SOC_SINGLE("DAC Volume Control-LeR", ES8316_DAC_SET2_REG31, 2, 1, 0),
  148. SOC_SINGLE("DAC Stereo Enhancement", ES8316_DAC_SET3_REG32, 0, 7, 0),
  149. /* +20dB D2SE PGA Control */
  150. SOC_SINGLE_TLV("MIC Boost", ES8316_ADC_D2SEPGA_REG24,
  151. 0, 1, 0, mic_bst_tlv),
  152. /* 0-+24dB Lineinput PGA Control */
  153. SOC_SINGLE_TLV("Input PGA", ES8316_ADC_PGAGAIN_REG23,
  154. 4, 8, 0, linin_pga_tlv),
  155. /* ADC Digital Control */
  156. SOC_SINGLE_TLV("ADC Capture Volume", ES8316_ADC_VOLUME_REG27,
  157. 0, 0xC0, 1, adc_vol_tlv),
  158. SOC_SINGLE("ADC Soft Ramp", ES8316_ADC_MUTE_REG26, 4, 1, 0),
  159. SOC_ENUM("Capture Polarity", adcpol),
  160. SOC_SINGLE("ADC Double FS Mode", ES8316_ADC_DMIC_REG25, 4, 1, 0),
  161. /* ADC ALC Control */
  162. SOC_SINGLE("ALC Capture Target Volume",
  163. ES8316_ADC_ALC3_REG2B, 4, 10, 0),
  164. SOC_SINGLE("ALC Capture Max PGA", ES8316_ADC_ALC1_REG29, 0, 28, 0),
  165. SOC_SINGLE("ALC Capture Min PGA", ES8316_ADC_ALC2_REG2A, 0, 28, 0),
  166. SOC_ENUM("ALC Capture Function", alc_func),
  167. SOC_SINGLE("ALC Capture Hold Time", ES8316_ADC_ALC3_REG2B, 0, 10, 0),
  168. SOC_SINGLE("ALC Capture Decay Time", ES8316_ADC_ALC4_REG2C, 4, 10, 0),
  169. SOC_SINGLE("ALC Capture Attack Time", ES8316_ADC_ALC4_REG2C, 0, 10, 0),
  170. SOC_SINGLE("ALC Capture NG Threshold", ES8316_ADC_ALC6_REG2E, 0, 31, 0),
  171. SOC_ENUM("ALC Capture NG Type", ng_type),
  172. SOC_SINGLE("ALC Capture NG Switch", ES8316_ADC_ALC6_REG2E, 5, 1, 0),
  173. };
  174. /* Analog Input MUX */
  175. static const char * const es8316_analog_in_txt[] = {
  176. "lin1-rin1",
  177. "lin2-rin2",
  178. "lin1-rin1 with 20db Boost",
  179. "lin2-rin2 with 20db Boost"
  180. };
  181. static const unsigned int es8316_analog_in_values[] = { 0, 1, 2, 3 };
  182. static const struct soc_enum es8316_analog_input_enum =
  183. SOC_VALUE_ENUM_SINGLE(ES8316_ADC_PDN_LINSEL_REG22, 4, 3,
  184. ARRAY_SIZE(es8316_analog_in_txt),
  185. es8316_analog_in_txt,
  186. es8316_analog_in_values);
  187. static const struct snd_kcontrol_new es8316_analog_in_mux_controls =
  188. SOC_DAPM_ENUM("Route", es8316_analog_input_enum);
  189. /* Dmic MUX */
  190. static const char * const es8316_dmic_txt[] = {
  191. "dmic disable",
  192. "dmic data at high level",
  193. "dmic data at low level",
  194. };
  195. static const unsigned int es8316_dmic_values[] = { 0, 1, 2 };
  196. static const struct soc_enum es8316_dmic_src_enum =
  197. SOC_VALUE_ENUM_SINGLE(ES8316_ADC_DMIC_REG25, 0, 3,
  198. ARRAY_SIZE(es8316_dmic_txt),
  199. es8316_dmic_txt,
  200. es8316_dmic_values);
  201. static const struct snd_kcontrol_new es8316_dmic_src_controls =
  202. SOC_DAPM_ENUM("Route", es8316_dmic_src_enum);
  203. /* hp mixer mux */
  204. static const char *const es8316_hpmux_texts[] = {
  205. "lin1-rin1",
  206. "lin2-rin2",
  207. "lin-rin with Boost",
  208. "lin-rin with Boost and PGA"
  209. };
  210. static const unsigned int es8316_hpmux_values[] = { 0, 1, 2, 3 };
  211. static const struct soc_enum es8316_left_hpmux_enum =
  212. SOC_VALUE_ENUM_SINGLE(ES8316_HPMIX_SEL_REG13, 4, 7,
  213. ARRAY_SIZE(es8316_hpmux_texts),
  214. es8316_hpmux_texts,
  215. es8316_hpmux_values);
  216. static const struct snd_kcontrol_new es8316_left_hpmux_controls =
  217. SOC_DAPM_ENUM("Route", es8316_left_hpmux_enum);
  218. static const struct soc_enum es8316_right_hpmux_enum =
  219. SOC_VALUE_ENUM_SINGLE(ES8316_HPMIX_SEL_REG13, 0, 7,
  220. ARRAY_SIZE(es8316_hpmux_texts),
  221. es8316_hpmux_texts,
  222. es8316_hpmux_values);
  223. static const struct snd_kcontrol_new es8316_right_hpmux_controls =
  224. SOC_DAPM_ENUM("Route", es8316_right_hpmux_enum);
  225. /* headphone Output Mixer */
  226. static const struct snd_kcontrol_new es8316_out_left_mix[] = {
  227. SOC_DAPM_SINGLE("LLIN Switch", ES8316_HPMIX_SWITCH_REG14,
  228. 6, 1, 0),
  229. SOC_DAPM_SINGLE("Left DAC Switch", ES8316_HPMIX_SWITCH_REG14,
  230. 7, 1, 0),
  231. };
  232. static const struct snd_kcontrol_new es8316_out_right_mix[] = {
  233. SOC_DAPM_SINGLE("RLIN Switch", ES8316_HPMIX_SWITCH_REG14,
  234. 2, 1, 0),
  235. SOC_DAPM_SINGLE("Right DAC Switch", ES8316_HPMIX_SWITCH_REG14,
  236. 3, 1, 0),
  237. };
  238. /* DAC data source mux */
  239. static const char * const es8316_dacsrc_texts[] = {
  240. "LDATA TO LDAC, RDATA TO RDAC",
  241. "LDATA TO LDAC, LDATA TO RDAC",
  242. "RDATA TO LDAC, RDATA TO RDAC",
  243. "RDATA TO LDAC, LDATA TO RDAC",
  244. };
  245. static const unsigned int es8316_dacsrc_values[] = { 0, 1, 2, 3 };
  246. static const struct soc_enum es8316_dacsrc_mux_enum =
  247. SOC_VALUE_ENUM_SINGLE(ES8316_DAC_SET1_REG30, 6, 4,
  248. ARRAY_SIZE(es8316_dacsrc_texts),
  249. es8316_dacsrc_texts,
  250. es8316_dacsrc_values);
  251. static const struct snd_kcontrol_new es8316_dacsrc_mux_controls =
  252. SOC_DAPM_ENUM("Route", es8316_dacsrc_mux_enum);
  253. static const struct snd_soc_dapm_widget es8316_dapm_widgets[] = {
  254. /* Input Lines */
  255. SND_SOC_DAPM_INPUT("DMIC"),
  256. SND_SOC_DAPM_INPUT("MIC1"),
  257. SND_SOC_DAPM_INPUT("MIC2"),
  258. SND_SOC_DAPM_MICBIAS("micbias", SND_SOC_NOPM,
  259. 0, 0),
  260. /* Input MUX */
  261. SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0,
  262. &es8316_analog_in_mux_controls),
  263. SND_SOC_DAPM_PGA("Line input PGA", ES8316_ADC_PDN_LINSEL_REG22,
  264. 7, 1, NULL, 0),
  265. /* ADCs */
  266. SND_SOC_DAPM_ADC("Mono ADC", NULL, ES8316_ADC_PDN_LINSEL_REG22, 6, 1),
  267. /* Dmic MUX */
  268. SND_SOC_DAPM_MUX("Digital Mic Mux", SND_SOC_NOPM, 0, 0,
  269. &es8316_dmic_src_controls),
  270. /* Digital Interface */
  271. SND_SOC_DAPM_AIF_OUT("I2S OUT", "I2S1 Capture", 1,
  272. ES8316_SDP_ADCFMT_REG0A, 6, 0),
  273. SND_SOC_DAPM_AIF_IN("I2S IN", "I2S1 Playback", 0,
  274. SND_SOC_NOPM, 0, 0),
  275. /* DACs DATA SRC MUX */
  276. SND_SOC_DAPM_MUX("DAC SRC Mux", SND_SOC_NOPM, 0, 0,
  277. &es8316_dacsrc_mux_controls),
  278. /* DACs */
  279. SND_SOC_DAPM_DAC("Right DAC", NULL, ES8316_DAC_PDN_REG2F, 0, 1),
  280. SND_SOC_DAPM_DAC("Left DAC", NULL, ES8316_DAC_PDN_REG2F, 4, 1),
  281. /* Headphone Output Side */
  282. /* hpmux for hp mixer */
  283. SND_SOC_DAPM_MUX("Left Hp mux", SND_SOC_NOPM, 0, 0,
  284. &es8316_left_hpmux_controls),
  285. SND_SOC_DAPM_MUX("Right Hp mux", SND_SOC_NOPM, 0, 0,
  286. &es8316_right_hpmux_controls),
  287. /* Output mixer */
  288. SND_SOC_DAPM_MIXER("Left Hp mixer", ES8316_HPMIX_PDN_REG15,
  289. 4, 1, &es8316_out_left_mix[0],
  290. ARRAY_SIZE(es8316_out_left_mix)),
  291. SND_SOC_DAPM_MIXER("Right Hp mixer", ES8316_HPMIX_PDN_REG15,
  292. 0, 1, &es8316_out_right_mix[0],
  293. ARRAY_SIZE(es8316_out_right_mix)),
  294. SND_SOC_DAPM_MIXER("Left Hp mixer", SND_SOC_NOPM,
  295. 4, 1, &es8316_out_left_mix[0],
  296. ARRAY_SIZE(es8316_out_left_mix)),
  297. SND_SOC_DAPM_MIXER("Right Hp mixer", SND_SOC_NOPM,
  298. 0, 1, &es8316_out_right_mix[0],
  299. ARRAY_SIZE(es8316_out_right_mix)),
  300. /* Output charge pump */
  301. SND_SOC_DAPM_PGA("HPCP L", SND_SOC_NOPM,
  302. 0, 0, NULL, 0),
  303. SND_SOC_DAPM_PGA("HPCP R", SND_SOC_NOPM,
  304. 0, 0, NULL, 0),
  305. SND_SOC_DAPM_PGA("HPCP L", ES8316_CPHP_OUTEN_REG17,
  306. 6, 0, NULL, 0),
  307. SND_SOC_DAPM_PGA("HPCP R", ES8316_CPHP_OUTEN_REG17,
  308. 2, 0, NULL, 0),
  309. /* Output Driver */
  310. SND_SOC_DAPM_PGA("HPVOL L", SND_SOC_NOPM,
  311. 0, 0, NULL, 0),
  312. SND_SOC_DAPM_PGA("HPVOL R", SND_SOC_NOPM,
  313. 0, 0, NULL, 0),
  314. /* Output Driver */
  315. SND_SOC_DAPM_PGA("HPVOL L", ES8316_CPHP_OUTEN_REG17,
  316. 5, 0, NULL, 0),
  317. SND_SOC_DAPM_PGA("HPVOL R", ES8316_CPHP_OUTEN_REG17,
  318. 1, 0, NULL, 0),
  319. /* Output Lines */
  320. SND_SOC_DAPM_OUTPUT("HPOL"),
  321. SND_SOC_DAPM_OUTPUT("HPOR"),
  322. };
  323. static const struct snd_soc_dapm_route es8316_dapm_routes[] = {
  324. /*
  325. * record route map
  326. */
  327. {"MIC1", NULL, "micbias"},
  328. {"MIC2", NULL, "micbias"},
  329. {"DMIC", NULL, "micbias"},
  330. {"Differential Mux", "lin1-rin1", "MIC1"},
  331. {"Differential Mux", "lin2-rin2", "MIC2"},
  332. {"Line input PGA", NULL, "Differential Mux"},
  333. {"Mono ADC", NULL, "Line input PGA"},
  334. {"Digital Mic Mux", "dmic disable", "Mono ADC"},
  335. {"Digital Mic Mux", "dmic data at high level", "DMIC"},
  336. {"Digital Mic Mux", "dmic data at low level", "DMIC"},
  337. {"I2S OUT", NULL, "Digital Mic Mux"},
  338. /*
  339. * playback route map
  340. */
  341. {"DAC SRC Mux", "LDATA TO LDAC, RDATA TO RDAC", "I2S IN"},
  342. {"DAC SRC Mux", "LDATA TO LDAC, LDATA TO RDAC", "I2S IN"},
  343. {"DAC SRC Mux", "RDATA TO LDAC, RDATA TO RDAC", "I2S IN"},
  344. {"DAC SRC Mux", "RDATA TO LDAC, LDATA TO RDAC", "I2S IN"},
  345. {"Left DAC", NULL, "DAC SRC Mux"},
  346. {"Right DAC", NULL, "DAC SRC Mux"},
  347. {"Left Hp mux", "lin1-rin1", "MIC1"},
  348. {"Left Hp mux", "lin2-rin2", "MIC2"},
  349. {"Left Hp mux", "lin-rin with Boost", "Differential Mux"},
  350. {"Left Hp mux", "lin-rin with Boost and PGA", "Line input PGA"},
  351. {"Right Hp mux", "lin1-rin1", "MIC1"},
  352. {"Right Hp mux", "lin2-rin2", "MIC2"},
  353. {"Right Hp mux", "lin-rin with Boost", "Differential Mux"},
  354. {"Right Hp mux", "lin-rin with Boost and PGA", "Line input PGA"},
  355. {"Left Hp mixer", "LLIN Switch", "Left Hp mux"},
  356. {"Left Hp mixer", "Left DAC Switch", "Left DAC"},
  357. {"Right Hp mixer", "RLIN Switch", "Right Hp mux"},
  358. {"Right Hp mixer", "Right DAC Switch", "Right DAC"},
  359. {"HPCP L", NULL, "Left Hp mixer"},
  360. {"HPCP R", NULL, "Right Hp mixer"},
  361. {"HPVOL L", NULL, "HPCP L"},
  362. {"HPVOL R", NULL, "HPCP R"},
  363. {"HPOL", NULL, "HPVOL L"},
  364. {"HPOR", NULL, "HPVOL R"},
  365. };
  366. struct _coeff_div {
  367. u32 mclk; /*mclk frequency*/
  368. u32 rate; /*sample rate*/
  369. u8 div; /*adcclk and dacclk divider*/
  370. u8 lrck_h; /*adclrck divider and daclrck divider*/
  371. u8 lrck_l;
  372. u8 sr; /*sclk divider*/
  373. u8 osr; /*adc osr*/
  374. };
  375. /* codec hifi mclk clock divider coefficients */
  376. static const struct _coeff_div coeff_div[] = {
  377. /* 8k */
  378. { 12288000, 8000, 6, 0x06, 0x00, 21, 32 },
  379. { 11289600, 8000, 6, 0x05, 0x83, 20, 29 },
  380. { 18432000, 8000, 9, 0x09, 0x00, 27, 32 },
  381. { 16934400, 8000, 8, 0x08, 0x44, 25, 33 },
  382. { 12000000, 8000, 7, 0x05, 0xdc, 21, 25 },
  383. { 19200000, 8000, 12, 0x09, 0x60, 27, 25 },
  384. /* 11.025k */
  385. { 11289600, 11025, 4, 0x04, 0x00, 16, 32 },
  386. { 16934400, 11025, 6, 0x06, 0x00, 21, 32 },
  387. { 12000000, 11025, 4, 0x04, 0x40, 17, 34 },
  388. /* 16k */
  389. { 12288000, 16000, 3, 0x03, 0x00, 12, 32 },
  390. { 18432000, 16000, 5, 0x04, 0x80, 18, 25 },
  391. { 12000000, 16000, 3, 0x02, 0xee, 12, 31 },
  392. { 19200000, 16000, 6, 0x04, 0xb0, 18, 25 },
  393. /* 22.05k */
  394. { 11289600, 22050, 2, 0x02, 0x00, 8, 32 },
  395. { 16934400, 22050, 3, 0x03, 0x00, 12, 32 },
  396. { 12000000, 22050, 2, 0x02, 0x20, 8, 34 },
  397. /* 32k */
  398. { 12288000, 32000, 1, 0x01, 0x80, 6, 48 },
  399. { 18432000, 32000, 2, 0x02, 0x40, 9, 32 },
  400. { 12000000, 32000, 1, 0x01, 0x77, 6, 31 },
  401. { 19200000, 32000, 3, 0x02, 0x58, 10, 25 },
  402. /* 44.1k */
  403. { 11289600, 44100, 1, 0x01, 0x00, 4, 32 },
  404. { 16934400, 44100, 1, 0x01, 0x80, 6, 32 },
  405. { 12000000, 44100, 1, 0x01, 0x10, 4, 34 },
  406. /* 48k */
  407. { 12288000, 48000, 1, 0x01, 0x00, 4, 32 },
  408. { 18432000, 48000, 1, 0x01, 0x80, 6, 32 },
  409. { 12000000, 48000, 1, 0x00, 0xfa, 4, 31 },
  410. { 19200000, 48000, 2, 0x01, 0x90, 6, 25 },
  411. /* 88.2k */
  412. { 11289600, 88200, 1, 0x00, 0x80, 2, 32 },
  413. { 16934400, 88200, 1, 0x00, 0xc0, 3, 48 },
  414. { 12000000, 88200, 1, 0x00, 0x88, 2, 34 },
  415. /* 96k */
  416. { 12288000, 96000, 1, 0x00, 0x80, 2, 32 },
  417. { 18432000, 96000, 1, 0x00, 0xc0, 3, 48 },
  418. { 12000000, 96000, 1, 0x00, 0x7d, 1, 31 },
  419. { 19200000, 96000, 1, 0x00, 0xc8, 3, 25 },
  420. };
  421. static inline int get_coeff(int mclk, int rate)
  422. {
  423. int i;
  424. for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
  425. if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
  426. return i;
  427. }
  428. return -EINVAL;
  429. }
  430. /* The set of rates we can generate from the above for each SYSCLK */
  431. static unsigned int rates_12288[] = {
  432. 8000, 12000, 16000, 24000, 24000, 32000, 48000, 96000,
  433. };
  434. static struct snd_pcm_hw_constraint_list constraints_12288 = {
  435. .count = ARRAY_SIZE(rates_12288),
  436. .list = rates_12288,
  437. };
  438. static unsigned int rates_112896[] = {
  439. 8000, 11025, 22050, 44100,
  440. };
  441. static struct snd_pcm_hw_constraint_list constraints_112896 = {
  442. .count = ARRAY_SIZE(rates_112896),
  443. .list = rates_112896,
  444. };
  445. static unsigned int rates_12[] = {
  446. 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
  447. 48000, 88235, 96000,
  448. };
  449. static struct snd_pcm_hw_constraint_list constraints_12 = {
  450. .count = ARRAY_SIZE(rates_12),
  451. .list = rates_12,
  452. };
  453. //static int es8316_read(u8 reg, u8 *rt_value, struct i2c_client *client)
  454. //{
  455. // int ret;
  456. // u8 read_cmd[3] = {0};
  457. // u8 cmd_len = 0;
  458. //
  459. // read_cmd[0] = reg;
  460. // cmd_len = 1;
  461. //
  462. // if (client->adapter == NULL)
  463. // pr_err("es8316_read client->adapter==NULL\n");
  464. //
  465. // ret = i2c_master_send(client, read_cmd, cmd_len);
  466. // if (ret != cmd_len) {
  467. // pr_err("es8316_read error1\n");
  468. // return -1;
  469. // }
  470. //
  471. // ret = i2c_master_recv(client, rt_value, 1);
  472. // if (ret != 1) {
  473. // pr_err("es8316_read error2, ret = %d.\n", ret);
  474. // return -1;
  475. // }
  476. //
  477. // return 0;
  478. //}
  479. //static int es8316_write(u8 reg, unsigned char value, struct i2c_client *client)
  480. //{
  481. // int ret = 0;
  482. // u8 write_cmd[2] = {0};
  483. //
  484. // write_cmd[0] = reg;
  485. // write_cmd[1] = value;
  486. //
  487. // ret = i2c_master_send(client, write_cmd, 2);
  488. // if (ret != 2) {
  489. // pr_err("es8316_write error->[REG-0x%02x,val-0x%02x]\n",reg,value);
  490. // return -1;
  491. // }
  492. // return 0;
  493. //}
  494. static unsigned int es8316_read(struct snd_soc_component *component,
  495. unsigned int reg, unsigned int *val)
  496. {
  497. int ret;
  498. ret = snd_soc_component_read(component,reg,val);
  499. if (ret < 0)
  500. return ret;
  501. return 0;
  502. }
  503. static void es8316_write(struct snd_soc_component *component,
  504. unsigned int reg, unsigned int value)
  505. {
  506. snd_soc_component_write(component, reg, value);
  507. }
  508. /*
  509. * Note that this should be called from init rather than from hw_params.
  510. */
  511. static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  512. int clk_id, unsigned int freq, int dir)
  513. {
  514. struct snd_soc_component *component = codec_dai->component;
  515. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  516. switch (freq) {
  517. case 11289600:
  518. case 18432000:
  519. case 22579200:
  520. case 36864000:
  521. es8316->sysclk_constraints = &constraints_112896;
  522. es8316->sysclk = freq;
  523. return 0;
  524. case 12288000:
  525. case 19200000:
  526. case 16934400:
  527. case 24576000:
  528. case 33868800:
  529. es8316->sysclk_constraints = &constraints_12288;
  530. es8316->sysclk = freq;
  531. return 0;
  532. case 12000000:
  533. case 24000000:
  534. es8316->sysclk_constraints = &constraints_12;
  535. es8316->sysclk = freq;
  536. return 0;
  537. }
  538. return 0;
  539. }
  540. static int es8316_set_dai_fmt(struct snd_soc_dai *codec_dai,
  541. unsigned int fmt)
  542. {
  543. struct snd_soc_component *component = codec_dai->component;
  544. u8 iface = 0;
  545. u8 adciface = 0;
  546. u8 daciface = 0;
  547. iface = snd_soc_component_read32(component, ES8316_IFACE);
  548. adciface = snd_soc_component_read32(component, ES8316_ADC_IFACE);
  549. daciface = snd_soc_component_read32(component, ES8316_DAC_IFACE);
  550. /* set master/slave audio interface */
  551. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  552. case SND_SOC_DAIFMT_CBM_CFM:
  553. iface |= 0x80;
  554. break;
  555. case SND_SOC_DAIFMT_CBS_CFS:
  556. iface &= 0x7F;
  557. break;
  558. default:
  559. return -EINVAL;
  560. }
  561. /* interface format */
  562. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  563. case SND_SOC_DAIFMT_I2S:
  564. adciface &= 0xFC;
  565. daciface &= 0xFC;
  566. break;
  567. case SND_SOC_DAIFMT_RIGHT_J:
  568. return -EINVAL;
  569. case SND_SOC_DAIFMT_LEFT_J:
  570. adciface &= 0xFC;
  571. daciface &= 0xFC;
  572. adciface |= 0x01;
  573. daciface |= 0x01;
  574. break;
  575. case SND_SOC_DAIFMT_DSP_A:
  576. adciface &= 0xDC;
  577. daciface &= 0xDC;
  578. adciface |= 0x03;
  579. daciface |= 0x03;
  580. break;
  581. case SND_SOC_DAIFMT_DSP_B:
  582. adciface &= 0xDC;
  583. daciface &= 0xDC;
  584. adciface |= 0x23;
  585. daciface |= 0x23;
  586. break;
  587. default:
  588. return -EINVAL;
  589. }
  590. /* clock inversion */
  591. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  592. case SND_SOC_DAIFMT_NB_NF:
  593. iface &= 0xDF;
  594. adciface &= 0xDF;
  595. daciface &= 0xDF;
  596. break;
  597. case SND_SOC_DAIFMT_IB_IF:
  598. iface |= 0x20;
  599. adciface |= 0x20;
  600. daciface |= 0x20;
  601. break;
  602. case SND_SOC_DAIFMT_IB_NF:
  603. iface |= 0x20;
  604. adciface &= 0xDF;
  605. daciface &= 0xDF;
  606. break;
  607. case SND_SOC_DAIFMT_NB_IF:
  608. iface &= 0xDF;
  609. adciface |= 0x20;
  610. daciface |= 0x20;
  611. break;
  612. default:
  613. return -EINVAL;
  614. }
  615. snd_soc_component_write(component, ES8316_IFACE, iface);
  616. snd_soc_component_write(component, ES8316_ADC_IFACE, adciface);
  617. snd_soc_component_write(component, ES8316_DAC_IFACE, daciface);
  618. return 0;
  619. }
  620. static int es8316_pcm_startup(struct snd_pcm_substream *substream,
  621. struct snd_soc_dai *dai)
  622. {
  623. struct snd_soc_component *component = dai->component;
  624. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  625. bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  626. snd_soc_component_write(component, ES8316_RESET_REG00, 0xC0);
  627. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x00);
  628. /* es8316: both playback and capture need dac mclk */
  629. snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW_REG01,
  630. ES8316_CLKMGR_MCLK_DIV_MASK |
  631. ES8316_CLKMGR_DAC_MCLK_MASK,
  632. ES8316_CLKMGR_MCLK_DIV_NML |
  633. ES8316_CLKMGR_DAC_MCLK_EN);
  634. es8316->pwr_count++;
  635. if (playback) {//printk("startup:>>>>>>>>>>>>>>>>>>SNDRV_PCM_STREAM_PLAYBACK\n");
  636. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0x3F);
  637. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0x1F);
  638. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x88);
  639. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x88);//default:0x00 new:0x88
  640. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0xBB);
  641. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x10);
  642. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x30);
  643. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x02);
  644. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x00);
  645. snd_soc_component_write(component, ES8316_CPHP_OUTEN_REG17, 0x66);
  646. snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW_REG01,
  647. ES8316_CLKMGR_DAC_MCLK_MASK |
  648. ES8316_CLKMGR_DAC_ANALOG_MASK,
  649. ES8316_CLKMGR_DAC_MCLK_EN |
  650. ES8316_CLKMGR_DAC_ANALOG_EN);
  651. msleep(50);
  652. } else {//printk("startup:>>>>>>>>>>>>>>>>>>SNDRV_PCM_STREAM_CAPTURE\n");
  653. snd_soc_component_update_bits(component,
  654. ES8316_ADC_PDN_LINSEL_REG22, 0xC0, 0x20);
  655. snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW_REG01,
  656. ES8316_CLKMGR_ADC_MCLK_MASK |
  657. ES8316_CLKMGR_ADC_ANALOG_MASK,
  658. ES8316_CLKMGR_ADC_MCLK_EN |
  659. ES8316_CLKMGR_ADC_ANALOG_EN);
  660. }
  661. return 0;
  662. }
  663. static void es8316_pcm_shutdown(struct snd_pcm_substream *substream,
  664. struct snd_soc_dai *dai)
  665. {
  666. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  667. struct snd_soc_component *component = dai->component;
  668. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  669. bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
  670. if (playback) {//printk("shutdown:>>>>>>>>>>>>>>>>>>SNDRV_PCM_STREAM_PLAYBACK\n");
  671. snd_soc_component_write(component, ES8316_CPHP_OUTEN_REG17, 0x66);//default:0x00 new:0x66
  672. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x11);
  673. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x03);
  674. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x22);
  675. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x06);
  676. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x00);
  677. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x33);
  678. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0x00);
  679. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x00);
  680. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0xFF);
  681. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0xFF);
  682. snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW_REG01,
  683. ES8316_CLKMGR_DAC_ANALOG_MASK,
  684. ES8316_CLKMGR_DAC_ANALOG_DIS);
  685. } else {//printk("shutdown:>>>>>>>>>>>>>>>>>>SNDRV_PCM_STREAM_CAPTURE\n");
  686. snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0xc0);
  687. snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW_REG01,
  688. ES8316_CLKMGR_ADC_MCLK_MASK |
  689. ES8316_CLKMGR_ADC_ANALOG_MASK,
  690. ES8316_CLKMGR_ADC_MCLK_DIS |
  691. ES8316_CLKMGR_ADC_ANALOG_DIS);
  692. }
  693. if (--es8316->pwr_count == 0) {
  694. if (!es8316->hp_inserted)
  695. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x3F);
  696. snd_soc_component_write(component, ES8316_CLKMGR_CLKSW_REG01, 0xF3);
  697. }
  698. }
  699. static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
  700. struct snd_pcm_hw_params *params,
  701. struct snd_soc_dai *dai)
  702. {
  703. struct snd_soc_component *component = dai->component;
  704. int val = 0;
  705. //snd_pcm_format_t format;
  706. //unsigned int rate;
  707. //rate = params_rate(params);
  708. //format = params_format(params);
  709. //printk("==============[%s]:[ %d] rate = %d\n", __FUNCTION__, __LINE__,rate);
  710. switch (params_format(params)) {
  711. case SNDRV_PCM_FORMAT_S16_LE:
  712. val = ES8316_DACWL_16;
  713. break;
  714. case SNDRV_PCM_FORMAT_S20_3LE:
  715. val = ES8316_DACWL_20;
  716. break;
  717. case SNDRV_PCM_FORMAT_S24_LE:
  718. val = ES8316_DACWL_24;
  719. break;
  720. case SNDRV_PCM_FORMAT_S32_LE:
  721. val = ES8316_DACWL_32;
  722. break;
  723. default:
  724. val = ES8316_DACWL_16;
  725. break;
  726. }
  727. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  728. snd_soc_component_update_bits(component, ES8316_SDP_DACFMT_REG0B,
  729. ES8316_DACWL_MASK, val);
  730. else
  731. snd_soc_component_update_bits(component, ES8316_SDP_ADCFMT_REG0A,
  732. ES8316_ADCWL_MASK, val);
  733. return 0;
  734. }
  735. static int es8316_mute(struct snd_soc_dai *dai, int mute)
  736. {
  737. struct snd_soc_component *component = dai->component;
  738. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  739. es8316->muted = mute;
  740. if (mute) {
  741. es8316_enable_spk(es8316, false);
  742. msleep(100);
  743. snd_soc_component_write(component, ES8316_DAC_SET1_REG30, 0x20);
  744. } else if (dai->playback_active) {
  745. snd_soc_component_write(component, ES8316_DAC_SET1_REG30, 0x00);
  746. msleep(130);
  747. if (!es8316->hp_inserted)
  748. es8316_enable_spk(es8316, true);
  749. }
  750. return 0;
  751. }
  752. static int es8316_set_bias_level(struct snd_soc_component *component,
  753. enum snd_soc_bias_level level)
  754. {
  755. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  756. int ret;
  757. switch (level) {
  758. case SND_SOC_BIAS_ON:
  759. break;
  760. case SND_SOC_BIAS_PREPARE:
  761. if (IS_ERR(es8316->mclk))
  762. break;
  763. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
  764. clk_disable_unprepare(es8316->mclk);
  765. } else {
  766. ret = clk_prepare_enable(es8316->mclk);
  767. if (ret)
  768. return ret;
  769. }
  770. break;
  771. case SND_SOC_BIAS_STANDBY:
  772. break;
  773. case SND_SOC_BIAS_OFF:
  774. snd_soc_component_write(component, ES8316_CPHP_OUTEN_REG17, 0x00);//0x00 add:20220401
  775. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x11);
  776. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x03);
  777. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x22);
  778. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x06);
  779. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x00);
  780. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x33);
  781. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0x00);
  782. snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0xC0);
  783. if (!es8316->hp_inserted)
  784. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x3F);
  785. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0x3F);
  786. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0x1F);
  787. snd_soc_component_write(component, ES8316_RESET_REG00, 0x00);
  788. break;
  789. }
  790. return 0;
  791. }
  792. #define es8316_RATES SNDRV_PCM_RATE_8000_96000
  793. #define es8316_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  794. SNDRV_PCM_FMTBIT_S24_LE)
  795. static struct snd_soc_dai_ops es8316_ops = {
  796. .startup = es8316_pcm_startup,
  797. .hw_params = es8316_pcm_hw_params,
  798. .set_fmt = es8316_set_dai_fmt,
  799. .set_sysclk = es8316_set_dai_sysclk,
  800. .digital_mute = es8316_mute,
  801. .shutdown = es8316_pcm_shutdown,
  802. };
  803. static struct snd_soc_dai_driver es8316_dai = {
  804. .name = "es8316-hifi",
  805. .playback = {
  806. .stream_name = "Playback",
  807. .channels_min = 1,
  808. .channels_max = 2,
  809. .rates = es8316_RATES,
  810. .formats = es8316_FORMATS,
  811. },
  812. .capture = {
  813. .stream_name = "Capture",
  814. .channels_min = 1,
  815. .channels_max = 2,
  816. .rates = es8316_RATES,
  817. .formats = es8316_FORMATS,
  818. },
  819. .ops = &es8316_ops,
  820. .symmetric_rates = 1,
  821. };
  822. static int es8316_init_regs(struct snd_soc_component *component)
  823. {
  824. #if 0
  825. //add 20220311
  826. snd_soc_component_write(component, ES8316_RESET_REG00, 0x3f);
  827. usleep_range(5000, 5500);
  828. snd_soc_component_write(component, ES8316_RESET_REG00, 0x00);
  829. snd_soc_component_write(component, ES8316_SYS_VMIDSEL_REG0C, 0xFF);
  830. snd_soc_component_write(component, ES8316_RESET_REG00, 0x30);
  831. msleep(30);
  832. snd_soc_component_write(component, ES8316_CLKMGR_CLKSEL_REG02, 0x09);//
  833. snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR_REG03, 0x20);
  834. snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV1_REG04, 0x11);
  835. snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV2_REG05, 0x00);
  836. snd_soc_component_write(component, ES8316_CLKMGR_DACDIV1_REG06, 0x11);
  837. snd_soc_component_write(component, ES8316_CLKMGR_DACDIV2_REG07, 0x00);
  838. snd_soc_component_write(component, ES8316_CLKMGR_CPDIV_REG08, 0x00);
  839. snd_soc_component_write(component, ES8316_SDP_MS_BCKDIV_REG09, 0x04);
  840. snd_soc_component_write(component, ES8316_CLKMGR_CLKSW_REG01, 0x7F);
  841. snd_soc_component_write(component, ES8316_CAL_TYPE_REG1C, 0x0F);
  842. snd_soc_component_write(component, ES8316_CAL_HPLIV_REG1E, 0x90);
  843. snd_soc_component_write(component, ES8316_CAL_HPRIV_REG1F, 0x90);
  844. snd_soc_component_write(component, ES8316_ADC_VOLUME_REG27, 0x00);//
  845. snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0x20);//LIN2MIC
  846. snd_soc_component_write(component, ES8316_ADC_PGAGAIN_REG23, 0xaa);
  847. snd_soc_component_write(component, ES8316_ADC_D2SEPGA_REG24, 0x01);//
  848. snd_soc_component_write(component, ES8316_ADC_DMIC_REG25, 0x08);
  849. snd_soc_component_write(component, ES8316_ADC_MUTE_REG26, 0x20);
  850. snd_soc_component_write(component, ES8316_DAC_SET2_REG31, 0x00);//
  851. snd_soc_component_write(component, ES8316_DAC_SET3_REG32, 0x00);
  852. snd_soc_component_write(component, ES8316_DAC_VOLL_REG33, 0x00);
  853. snd_soc_component_write(component, ES8316_DAC_VOLR_REG34, 0x00);
  854. snd_soc_component_write(component, ES8316_SDP_ADCFMT_REG0A, 0x0c);//
  855. snd_soc_component_write(component, ES8316_SDP_DACFMT_REG0B, 0x0c);//
  856. snd_soc_component_write(component, ES8316_SYS_VMIDLOW_REG10, 0x11);
  857. snd_soc_component_write(component, ES8316_SYS_VSEL_REG11, 0xFC);
  858. snd_soc_component_write(component, ES8316_SYS_REF_REG12, 0x28);
  859. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x1f);
  860. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0xff);
  861. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0xff);
  862. snd_soc_component_write(component, ES8316_RESET_REG00, 0xC0);
  863. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x00);
  864. snd_soc_component_write(component, ES8316_HPMIX_SEL_REG13, 0x00);
  865. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x88);
  866. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x88);
  867. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0xBB);
  868. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x10);
  869. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x30);
  870. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x02);
  871. snd_soc_component_write(component, ES8316_CPHP_ICAL_VOL_REG18, 0x00);
  872. snd_soc_component_write(component, ES8316_GPIO_SEL_REG4D, 0x00);
  873. snd_soc_component_write(component, ES8316_GPIO_DEBUNCE_INT_REG4E, 0x02);
  874. snd_soc_component_write(component, ES8316_TESTMODE_REG50, 0xA0);
  875. snd_soc_component_write(component, ES8316_TEST1_REG51, 0x00);
  876. snd_soc_component_write(component, ES8316_TEST2_REG52, 0x00);
  877. snd_soc_component_write(component, ES8316_ADC_MUTE_REG26, 0x00);
  878. snd_soc_component_write(component, ES8316_RESET_REG00, 0x30);
  879. snd_soc_component_write(component, ES8316_CPHP_OUTEN_REG17, 0x66);
  880. #else
  881. //update 20220330(ADC and DAC support)
  882. snd_soc_component_write(component, ES8316_RESET_REG00, 0x3f);
  883. usleep_range(5000, 5500);
  884. snd_soc_component_write(component, ES8316_RESET_REG00, 0x00);
  885. snd_soc_component_write(component, ES8316_SYS_VMIDSEL_REG0C, 0xFF);
  886. msleep(30);
  887. snd_soc_component_write(component, ES8316_CLKMGR_CLKSEL_REG02, 0x08);
  888. snd_soc_component_write(component, ES8316_CLKMGR_ADCOSR_REG03, 0x20);
  889. snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV1_REG04, 0x11);
  890. snd_soc_component_write(component, ES8316_CLKMGR_ADCDIV2_REG05, 0x00);
  891. snd_soc_component_write(component, ES8316_CLKMGR_DACDIV1_REG06, 0x11);
  892. snd_soc_component_write(component, ES8316_CLKMGR_DACDIV2_REG07, 0x00);
  893. snd_soc_component_write(component, ES8316_CLKMGR_CPDIV_REG08, 0x00);
  894. snd_soc_component_write(component, ES8316_SDP_MS_BCKDIV_REG09, 0x04);
  895. snd_soc_component_write(component, ES8316_CLKMGR_CLKSW_REG01, 0x7F);
  896. snd_soc_component_write(component, ES8316_CAL_TYPE_REG1C, 0x0F);
  897. snd_soc_component_write(component, ES8316_CAL_HPLIV_REG1E, 0x90);
  898. snd_soc_component_write(component, ES8316_CAL_HPRIV_REG1F, 0x90);
  899. snd_soc_component_write(component, ES8316_ADC_VOLUME_REG27, 0x11);//
  900. snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0x20);//LIN2MIC
  901. snd_soc_component_write(component, ES8316_ADC_D2SEPGA_REG24, 0x00);
  902. snd_soc_component_write(component, ES8316_ADC_DMIC_REG25, 0x08);
  903. snd_soc_component_write(component, ES8316_DAC_SET2_REG31, 0x20);
  904. snd_soc_component_write(component, ES8316_DAC_SET3_REG32, 0x00);
  905. snd_soc_component_write(component, ES8316_DAC_VOLL_REG33, 0x00);
  906. snd_soc_component_write(component, ES8316_DAC_VOLR_REG34, 0x00);
  907. snd_soc_component_write(component, ES8316_SDP_ADCFMT_REG0A, 0x00);
  908. snd_soc_component_write(component, ES8316_SDP_DACFMT_REG0B, 0x00);//0x01
  909. snd_soc_component_write(component, ES8316_SYS_VMIDLOW_REG10, 0x11);
  910. snd_soc_component_write(component, ES8316_SYS_VSEL_REG11, 0xFC);
  911. snd_soc_component_write(component, ES8316_SYS_REF_REG12, 0x28);
  912. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0x04);
  913. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0x0C);
  914. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x00);//0x11
  915. snd_soc_component_write(component, ES8316_HPMIX_SEL_REG13, 0x00);
  916. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x88);
  917. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x00);
  918. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0xBB);
  919. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x10);
  920. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x30);
  921. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x02);
  922. snd_soc_component_write(component, ES8316_CPHP_ICAL_VOL_REG18, 0x00);
  923. snd_soc_component_write(component, ES8316_GPIO_SEL_REG4D, 0x00);
  924. snd_soc_component_write(component, ES8316_GPIO_DEBUNCE_INT_REG4E, 0x02);
  925. snd_soc_component_write(component, ES8316_TESTMODE_REG50, 0xA0);
  926. snd_soc_component_write(component, ES8316_TEST1_REG51, 0x00);
  927. snd_soc_component_write(component, ES8316_TEST2_REG52, 0x00);
  928. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x00);
  929. snd_soc_component_write(component, ES8316_RESET_REG00, 0xC0);
  930. msleep(50);
  931. snd_soc_component_write(component, ES8316_ADC_PGAGAIN_REG23, 0x60);
  932. snd_soc_component_write(component, ES8316_ADC_D2SEPGA_REG24, 0x01);
  933. /* adc ds mode, HPF enable */
  934. snd_soc_component_write(component, ES8316_ADC_DMIC_REG25, 0x08);
  935. snd_soc_component_write(component, ES8316_ADC_ALC1_REG29, 0xcd);
  936. snd_soc_component_write(component, ES8316_ADC_ALC2_REG2A, 0x08);
  937. snd_soc_component_write(component, ES8316_ADC_ALC3_REG2B, 0xa0);
  938. snd_soc_component_write(component, ES8316_ADC_ALC4_REG2C, 0x05);
  939. snd_soc_component_write(component, ES8316_ADC_ALC5_REG2D, 0x06);
  940. snd_soc_component_write(component, ES8316_ADC_ALC6_REG2E, 0x61);
  941. #endif
  942. return 0;
  943. }
  944. static int es8316_suspend(struct snd_soc_component *component)
  945. {
  946. return 0;
  947. }
  948. static int es8316_resume(struct snd_soc_component *component)
  949. {
  950. printk("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
  951. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  952. int ret;
  953. es8316_reset(component); /* UPDATED BY DAVID,15-3-5 */
  954. ret = snd_soc_component_read32(component, ES8316_CLKMGR_ADCDIV2_REG05);
  955. if (!ret) {
  956. es8316_init_regs(component);
  957. snd_soc_component_write(component, ES8316_GPIO_SEL_REG4D, 0x00);
  958. /* max debance time, enable interrupt, low active */
  959. snd_soc_component_write(component, ES8316_GPIO_DEBUNCE_INT_REG4E, 0xf3);
  960. /* es8316_set_bias_level(component, SND_SOC_BIAS_OFF); */
  961. snd_soc_component_write(component, ES8316_CPHP_OUTEN_REG17, 0x66);//0x00
  962. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x11);
  963. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x03);
  964. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x22);
  965. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x06);
  966. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x00);
  967. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x33);
  968. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0x00);
  969. if (!es8316->hp_inserted)
  970. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D, 0x3F);
  971. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0xFF);
  972. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0xFF);
  973. snd_soc_component_write(component, ES8316_CLKMGR_CLKSW_REG01, 0xF3);
  974. snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0xc0);
  975. }
  976. return 0;
  977. }
  978. /*
  979. static irqreturn_t es8316_irq_handler(int irq, void *data)
  980. {
  981. struct es8316_priv *es8316 = data;
  982. queue_delayed_work(system_power_efficient_wq, &es8316->work,
  983. msecs_to_jiffies(es8316->debounce_time));
  984. return IRQ_HANDLED;
  985. }
  986. */
  987. /*
  988. * Call from rk_headset_irq_hook_adc.c
  989. *
  990. * Enable micbias for HOOK detection and disable external Amplifier
  991. * when jack insertion.
  992. */
  993. int es8316_headset_detect(int jack_insert)
  994. {
  995. struct es8316_priv *es8316;
  996. if (!es8316_component)
  997. return -1;
  998. es8316 = snd_soc_component_get_drvdata(es8316_component);
  999. es8316->hp_inserted = jack_insert;
  1000. /*enable micbias and disable PA*/
  1001. if (jack_insert) {
  1002. snd_soc_component_update_bits(es8316_component,
  1003. ES8316_SYS_PDN_REG0D, 0x3f, 0);
  1004. es8316_enable_spk(es8316, false);
  1005. }
  1006. return 0;
  1007. }
  1008. EXPORT_SYMBOL(es8316_headset_detect);
  1009. /*
  1010. static void hp_work(struct work_struct *work)
  1011. {
  1012. struct es8316_priv *es8316;
  1013. int enable;
  1014. es8316 = container_of(work, struct es8316_priv, work.work);
  1015. enable = gpio_get_value(es8316->hp_det_gpio);
  1016. if (es8316->hp_det_invert)
  1017. enable = !enable;
  1018. es8316->hp_inserted = enable ? true : false;
  1019. if (!es8316->muted) {
  1020. if (es8316->hp_inserted)
  1021. es8316_enable_spk(es8316, false);
  1022. else
  1023. es8316_enable_spk(es8316, true);
  1024. }
  1025. }
  1026. */
  1027. static int es8316_probe(struct snd_soc_component *component)
  1028. {
  1029. struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
  1030. int ret = 0;
  1031. es8316_component = component;
  1032. es8316->mclk = devm_clk_get(component->dev, "mclk");
  1033. if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER)
  1034. return -EPROBE_DEFER;
  1035. ret = clk_prepare_enable(es8316->mclk);
  1036. if (ret)
  1037. return ret;
  1038. ret = snd_soc_component_read32(component, ES8316_CLKMGR_ADCDIV2_REG05);
  1039. if (!ret) {
  1040. es8316_reset(component); /* UPDATED BY DAVID,15-3-5 */
  1041. ret = snd_soc_component_read32(component, ES8316_CLKMGR_ADCDIV2_REG05);
  1042. if (!ret) {
  1043. //printk("start-----------------init regs\n");
  1044. es8316_init_regs(component);
  1045. snd_soc_component_write(component, ES8316_GPIO_SEL_REG4D, 0x00);
  1046. /* max debance time, enable interrupt, low active */
  1047. snd_soc_component_write(component,
  1048. ES8316_GPIO_DEBUNCE_INT_REG4E, 0xf3);
  1049. /* es8316_set_bias_level(component, SND_SOC_BIAS_OFF); */
  1050. snd_soc_component_write(component, ES8316_CPHP_OUTEN_REG17, 0x66);//default:0x00 new:0x66
  1051. snd_soc_component_write(component, ES8316_DAC_PDN_REG2F, 0x00);//default:0x11 new:0x00
  1052. snd_soc_component_write(component, ES8316_CPHP_LDOCTL_REG1B, 0x30);//default:0x03 new:0x30
  1053. snd_soc_component_write(component, ES8316_CPHP_PDN2_REG1A, 0x10);//default:0x22 new:0x10
  1054. snd_soc_component_write(component, ES8316_CPHP_PDN1_REG19, 0x02);//default:0x06 new:0x02
  1055. snd_soc_component_write(component, ES8316_HPMIX_SWITCH_REG14, 0x88);//default:0x00 new:0x88
  1056. snd_soc_component_write(component, ES8316_HPMIX_PDN_REG15, 0x88);//default:0x33 new:0x88 0x00
  1057. snd_soc_component_write(component, ES8316_HPMIX_VOL_REG16, 0xBB);//default:0x00 new:0xBB
  1058. if (!es8316->hp_inserted)
  1059. snd_soc_component_write(component, ES8316_SYS_PDN_REG0D,
  1060. 0x1F);//default:0x3F new:0x1F
  1061. snd_soc_component_write(component, ES8316_SYS_LP1_REG0E, 0x3F);//default:0xFF new:0x3F
  1062. snd_soc_component_write(component, ES8316_SYS_LP2_REG0F, 0x1F);//default:0xFF new:0x1F
  1063. snd_soc_component_write(component, ES8316_CLKMGR_CLKSW_REG01, 0x7F);//default:0xF3 new:0x7F
  1064. snd_soc_component_write(component, ES8316_ADC_PDN_LINSEL_REG22, 0x20);//default:0xc0 new:0x20
  1065. //printk("end-----------------init regs\n");
  1066. }
  1067. }
  1068. return ret;
  1069. }
  1070. static void es8316_remove(struct snd_soc_component *component)
  1071. {
  1072. es8316_set_bias_level(component, SND_SOC_BIAS_OFF);
  1073. }
  1074. const struct regmap_config es8316_regmap_config = {
  1075. .reg_bits = 8,
  1076. .val_bits = 8,
  1077. .max_register = ES8316_TEST3_REG53,
  1078. .cache_type = REGCACHE_RBTREE,
  1079. .reg_defaults = es8316_reg_defaults,
  1080. .num_reg_defaults = ARRAY_SIZE(es8316_reg_defaults),
  1081. };
  1082. static const struct snd_soc_component_driver soc_component_dev_es8316 = {
  1083. .probe = es8316_probe,
  1084. .remove = es8316_remove,
  1085. .suspend = es8316_suspend,
  1086. .resume = es8316_resume,
  1087. .set_bias_level = es8316_set_bias_level,
  1088. .controls = es8316_snd_controls,
  1089. .num_controls = ARRAY_SIZE(es8316_snd_controls),
  1090. .dapm_widgets = es8316_dapm_widgets,
  1091. .num_dapm_widgets = ARRAY_SIZE(es8316_dapm_widgets),
  1092. .dapm_routes = es8316_dapm_routes,
  1093. .num_dapm_routes = ARRAY_SIZE(es8316_dapm_routes),
  1094. };
  1095. static ssize_t es8316_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1096. {
  1097. int val=0, flag=0;
  1098. u8 i=0, reg, num, value_w;
  1099. int value_r;
  1100. struct es8316_priv *es8316 = dev_get_drvdata(dev);;
  1101. val = simple_strtol(buf, NULL, 16);
  1102. flag = (val >> 16) & 0xFF;
  1103. if (flag) {
  1104. reg = (val >> 8) & 0xFF;
  1105. value_w = val & 0xFF;
  1106. printk("\nWrite: start REG:0x%02x,val:0x%02x,count:0x%02x\n", reg, value_w, flag);
  1107. while(flag--) {
  1108. es8316_write(es8316_component,reg, value_w);
  1109. printk("Write 0x%02x to REG:0x%02x\n", value_w, reg);
  1110. reg++;
  1111. }
  1112. } else {
  1113. reg = (val >> 8) & 0xFF;
  1114. num = val & 0xff;
  1115. printk("\nRead: start REG:0x%02x,count:0x%02x\n", reg, num);
  1116. do {
  1117. value_r = 0;
  1118. es8316_read(es8316_component,reg, &value_r);
  1119. printk("REG[0x%02x]: 0x%02x; ", reg, value_r);
  1120. reg++;
  1121. i++;
  1122. if ((i==num) || (i%4==0)) printk("\n");
  1123. } while (i<num);
  1124. }
  1125. return count;
  1126. }
  1127. static ssize_t es8316_show(struct device *dev, struct device_attribute *attr, char *buf)
  1128. {
  1129. printk("echo flag|reg|val > es8316\n");
  1130. printk("eg read star addres=0x06,count 0x10:echo 0610 >es8316\n");
  1131. printk("eg write star addres=0x90,value=0x3c,count=4:echo 4903c >es8316\n");
  1132. //printk("eg write value:0xfe to address:0x06 :echo 106fe > es7243\n");
  1133. return 0;
  1134. }
  1135. static DEVICE_ATTR(es8316, 0644, es8316_show, es8316_store);
  1136. static struct attribute *es8316_debug_attrs[] = {
  1137. &dev_attr_es8316.attr,
  1138. NULL,
  1139. };
  1140. static struct attribute_group es8316_debug_attr_group = {
  1141. .name = "es8316_debug",
  1142. .attrs = es8316_debug_attrs,
  1143. };
  1144. static int es8316_i2c_probe(struct i2c_client *i2c,
  1145. const struct i2c_device_id *id)
  1146. {
  1147. struct es8316_priv *es8316;
  1148. int ret = -1;
  1149. //int hp_irq;
  1150. //enum of_gpio_flags flags;
  1151. //struct device_node *np = i2c->dev.of_node;
  1152. printk("begin->>>>>>>>>>%s!\n",__func__);
  1153. es8316 = devm_kzalloc(&i2c->dev, sizeof(*es8316), GFP_KERNEL);
  1154. if (!es8316)
  1155. return -ENOMEM;
  1156. es8316->debounce_time = 200;
  1157. es8316->hp_det_invert = 0;
  1158. es8316->pwr_count = 0;
  1159. es8316->hp_inserted = false;
  1160. es8316->muted = true;
  1161. es8316->regmap = devm_regmap_init_i2c(i2c, &es8316_regmap_config);
  1162. if (IS_ERR(es8316->regmap)) {
  1163. ret = PTR_ERR(es8316->regmap);
  1164. dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret);
  1165. return ret;
  1166. }
  1167. i2c_set_clientdata(i2c, es8316);
  1168. /*****
  1169. es8316->spk_ctl_gpio = of_get_named_gpio_flags(np,
  1170. "spk-con-gpio",
  1171. 0,
  1172. &flags);
  1173. if (es8316->spk_ctl_gpio < 0) {
  1174. dev_info(&i2c->dev, "Can not read property spk_ctl_gpio\n");
  1175. es8316->spk_ctl_gpio = INVALID_GPIO;
  1176. } else {
  1177. es8316->spk_active_level = !(flags & OF_GPIO_ACTIVE_LOW);
  1178. ret = devm_gpio_request_one(&i2c->dev, es8316->spk_ctl_gpio,
  1179. GPIOF_DIR_OUT, NULL);
  1180. if (ret) {
  1181. dev_err(&i2c->dev, "Failed to request spk_ctl_gpio\n");
  1182. return ret;
  1183. }
  1184. es8316_enable_spk(es8316, false);
  1185. }
  1186. es8316->hp_det_gpio = of_get_named_gpio_flags(np,
  1187. "hp-det-gpio",
  1188. 0,
  1189. &flags);
  1190. if (es8316->hp_det_gpio < 0) {
  1191. dev_info(&i2c->dev, "Can not read property hp_det_gpio\n");
  1192. es8316->hp_det_gpio = INVALID_GPIO;
  1193. } else {
  1194. INIT_DELAYED_WORK(&es8316->work, hp_work);
  1195. es8316->hp_det_invert = !!(flags & OF_GPIO_ACTIVE_LOW);
  1196. ret = devm_gpio_request_one(&i2c->dev, es8316->hp_det_gpio,
  1197. GPIOF_IN, "hp det");
  1198. if (ret < 0)
  1199. return ret;
  1200. hp_irq = gpio_to_irq(es8316->hp_det_gpio);
  1201. ret = devm_request_threaded_irq(&i2c->dev, hp_irq, NULL,
  1202. es8316_irq_handler,
  1203. IRQF_TRIGGER_FALLING |
  1204. IRQF_TRIGGER_RISING |
  1205. IRQF_ONESHOT,
  1206. "es8316_interrupt", es8316);
  1207. if (ret < 0) {
  1208. dev_err(&i2c->dev, "request_irq failed: %d\n", ret);
  1209. return ret;
  1210. }
  1211. schedule_delayed_work(&es8316->work,
  1212. msecs_to_jiffies(es8316->debounce_time));
  1213. }
  1214. *****/
  1215. ret = devm_snd_soc_register_component(&i2c->dev,
  1216. &soc_component_dev_es8316,
  1217. &es8316_dai, 1);
  1218. ret = sysfs_create_group(&i2c->dev.kobj, &es8316_debug_attr_group);
  1219. if (ret) {
  1220. pr_err("failed to create attr group\n");
  1221. }
  1222. printk("%s sucess!\n",__func__);
  1223. return ret;
  1224. }
  1225. static int es8316_i2c_remove(struct i2c_client *client)
  1226. {
  1227. return 0;
  1228. }
  1229. static void es8316_i2c_shutdown(struct i2c_client *client)
  1230. {
  1231. struct es8316_priv *es8316 = i2c_get_clientdata(client);
  1232. if (es8316_component != NULL) {
  1233. es8316_enable_spk(es8316, false);
  1234. msleep(20);
  1235. es8316_set_bias_level(es8316_component, SND_SOC_BIAS_OFF);
  1236. }
  1237. }
  1238. static const struct i2c_device_id es8316_i2c_id[] = {
  1239. {"es8316", 0},
  1240. {"10ES8316:00", 0},
  1241. {"10ES8316", 0},
  1242. { }
  1243. };
  1244. MODULE_DEVICE_TABLE(i2c, es8316_i2c_id);
  1245. static const struct of_device_id es8316_of_match[] = {
  1246. //{ .compatible = "everest,es8316", },
  1247. { .compatible = "arkmicro,es8316", },
  1248. { }
  1249. };
  1250. MODULE_DEVICE_TABLE(of, es8316_of_match);
  1251. static struct i2c_driver es8316_i2c_driver = {
  1252. .driver = {
  1253. .name = "es8316",
  1254. .of_match_table = es8316_of_match,
  1255. },
  1256. .probe = es8316_i2c_probe,
  1257. .remove = es8316_i2c_remove,
  1258. .shutdown = es8316_i2c_shutdown,
  1259. .id_table = es8316_i2c_id,
  1260. };
  1261. module_i2c_driver(es8316_i2c_driver);
  1262. MODULE_DESCRIPTION("ASoC es8316 driver");
  1263. MODULE_AUTHOR("Will <will@everset-semi.com>");
  1264. MODULE_LICENSE("GPL");