es7210.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906
  1. /*
  2. * ALSA SoC ES7210 adc driver
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Notes:
  9. * ES7210 is a 4-ch ADC of Everest
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/init.h>
  15. #include <linux/clk.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/i2c.h>
  19. #include <linux/slab.h>
  20. #include <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <sound/tlv.h>
  26. #include <sound/initval.h>
  27. #include <linux/regmap.h>
  28. #include "es7210.h"
  29. #define ARK1668E_KERNEL_VERSION_4_19
  30. #define ARK1668ED_DEMO_BOARD
  31. struct i2c_client *i2c_clt1[ADC_DEV_MAXNUM];
  32. /* codec private data */
  33. struct es7210_priv {
  34. struct regmap *regmap;
  35. struct i2c_client *i2c;
  36. unsigned int dmic_enable;
  37. unsigned int sysclk;
  38. struct clk *mclk;
  39. struct snd_pcm_hw_constraint_list *sysclk_constraints;
  40. unsigned int tdm_mode;
  41. struct delayed_work pcm_pop_work;
  42. };
  43. struct snd_soc_component *tron_codec1[ADC_DEV_MAXNUM];
  44. //static struct snd_soc_component *es7210_component;
  45. //#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  46. int es7210_init_reg = 0;
  47. static int es7210_codec_num = 0;
  48. /*
  49. * ES7210 register cache
  50. */
  51. static const u8 es7210_reg[] = {
  52. 0x32, 0x40, 0x02, 0x04, 0x01, 0x00, 0x00, 0x20, /* 0 - 7 */
  53. 0x10, 0x40, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00, /* 8 - F */
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10 - 17 */
  55. 0xf7, 0xf7, 0x00, 0xbf, 0xbf, 0xbf, 0xbf, 0x00, /* 18 - 1f */
  56. 0x26, 0x26, 0x06, 0x26, 0x00, 0x00, 0x00, 0x00, /* 20 - 27 */
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28 - 2f */
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 30 - 37 */
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x10, 0x00, /* 38 - 3f */
  60. 0x80, 0x71, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40 - 47 */
  61. 0x00, 0x00, 0x00, 0xff, 0xff, /* 48 - 4c */
  62. };
  63. static const struct reg_default es7210_reg_defaults[] = {
  64. { 0x00, 0x32 },
  65. { 0x01, 0x40 },
  66. { 0x02, 0x02 },
  67. { 0x03, 0x04 },
  68. { 0x04, 0x01 },
  69. { 0x05, 0x00 },
  70. { 0x06, 0x00 },
  71. { 0x07, 0x20 },
  72. { 0x08, 0x10 },
  73. { 0x09, 0x40 },
  74. { 0x0a, 0x40 },
  75. { 0x0b, 0x00 },
  76. { 0x0c, 0x00 },
  77. { 0x0d, 0x09 },
  78. { 0x0e, 0x00 },
  79. { 0x0f, 0x00 },
  80. { 0x10, 0x00 },
  81. { 0x11, 0x00 },
  82. { 0x12, 0x00 },
  83. { 0x13, 0x00 },
  84. { 0x14, 0x00 },
  85. { 0x15, 0x00 },
  86. { 0x16, 0x00 },
  87. { 0x17, 0x00 },
  88. { 0x18, 0xf7 },
  89. { 0x19, 0xf7 },
  90. { 0x1a, 0x00 },
  91. { 0x1b, 0xbf },
  92. { 0x1c, 0xbf },
  93. { 0x1d, 0xbf },
  94. { 0x1e, 0xbf },
  95. { 0x1f, 0x00 },
  96. { 0x20, 0x26 },
  97. { 0x21, 0x26 },
  98. { 0x22, 0x06 },
  99. { 0x23, 0x26 },
  100. { 0x3d, 0x72 },
  101. { 0x3e, 0x10 },
  102. { 0x3f, 0x00 },
  103. { 0x40, 0x80 },
  104. { 0x41, 0x71 },
  105. { 0x42, 0x71 },
  106. { 0x43, 0x00 },
  107. { 0x44, 0x00 },
  108. { 0x45, 0x00 },
  109. { 0x46, 0x00 },
  110. { 0x47, 0x00 },
  111. { 0x48, 0x00 },
  112. { 0x49, 0x00 },
  113. { 0x4a, 0x00 },
  114. { 0x4b, 0xff },
  115. { 0x4c, 0xff },
  116. };
  117. struct es7210_reg_config {
  118. unsigned char reg_addr;
  119. unsigned char reg_v;
  120. };
  121. //struct es7210_reg_config {
  122. // unsigned int reg_addr;
  123. // unsigned int reg_v;
  124. //};
  125. static const struct es7210_reg_config es7210_tdm_reg_common_cfg1[] = {
  126. //default
  127. // { 0x00, 0xFF },
  128. // { 0x00, 0x32 },
  129. // { 0x09, 0x30 },
  130. // { 0x0A, 0x30 },
  131. // { 0x23, 0x26 },
  132. // { 0x22, 0x06 },
  133. // { 0x21, 0x26 },
  134. // { 0x20, 0x06 },
  135. //ark1668e:add 20220318
  136. { 0x00, 0xFF },
  137. { 0x00, 0x32 },
  138. { 0x09, 0x30 },
  139. { 0x0A, 0x30 },
  140. { 0x23, 0x2A },
  141. { 0x22, 0x0A },
  142. { 0x21, 0x2A },
  143. { 0x20, 0x0A },
  144. };
  145. static const struct es7210_reg_config es7210_tdm_reg_fmt_cfg[] = {
  146. //default
  147. // { 0x11, 0x63 },
  148. // { 0x12, 0x01 },
  149. //ark1668e:add 20220318
  150. { 0x08, 0x40 },
  151. { 0x11, 0x60 },
  152. { 0x12, 0x07 },
  153. };
  154. static const struct es7210_reg_config es7210_tdm_reg_common_cfg2[] = {
  155. //default
  156. // { 0x40, 0xC3 },
  157. // { 0x41, 0x70 },
  158. // { 0x42, 0x70 },
  159. // { 0x43, 0x1E },
  160. // { 0x44, 0x1E },
  161. // { 0x45, 0x1E },
  162. // { 0x46, 0x1E },
  163. // { 0x47, 0x08 },
  164. // { 0x48, 0x08 },
  165. // { 0x49, 0x08 },
  166. // { 0x4A, 0x08 },
  167. // { 0x07, 0x20 },
  168. //ark1668e:add 20220318
  169. { 0x40, 0xC3 },
  170. { 0x41, 0x70 },
  171. { 0x42, 0x70 },
  172. { 0x43, 0x1A },//mic1 0x13
  173. { 0x44, 0x1A },//mic2 0x13
  174. { 0x45, 0x1A },//mic3 0x1a
  175. { 0x46, 0x1A },//mic4 0x1a
  176. { 0x47, 0x08 },
  177. { 0x48, 0x08 },
  178. { 0x49, 0x08 },
  179. { 0x4A, 0x08 },
  180. { 0x07, 0x20 },
  181. };
  182. static const struct es7210_reg_config es7210_tdm_reg_mclk_cfg[] = {
  183. //default
  184. // { 0x02, 0xC1 },
  185. //ark1668e:add 20220318
  186. { 0x02, 0xC1 },//
  187. };
  188. static const struct es7210_reg_config es7210_tdm_reg_common_cfg3[] = {
  189. //default
  190. // { 0x06, 0x04 },
  191. // { 0x4B, 0x0F },
  192. // { 0x4C, 0x0F },
  193. // { 0x00, 0x71 },
  194. // { 0x00, 0x41 },
  195. //ark1668e:add 20220318
  196. { 0x06, 0x04 },
  197. { 0x4B, 0x0F },
  198. { 0x4C, 0x0F },
  199. { 0x00, 0x71 },
  200. { 0x00, 0x41 },
  201. };
  202. static const struct regmap_config es7210_regmap_config = {
  203. .reg_bits = 8, //Number of bits in a register address
  204. .val_bits = 8, //Number of bits in a register value
  205. .reg_defaults = es7210_reg_defaults,
  206. .num_reg_defaults = ARRAY_SIZE(es7210_reg_defaults),
  207. };
  208. static int es7210_read(u8 reg, u8 *rt_value, struct i2c_client *client)
  209. {
  210. int ret;
  211. u8 read_cmd[3] = {0};
  212. u8 cmd_len = 0;
  213. read_cmd[0] = reg;
  214. cmd_len = 1;
  215. if (client->adapter == NULL)
  216. pr_err("es7210_read client->adapter==NULL\n");
  217. ret = i2c_master_send(client, read_cmd, cmd_len);
  218. if (ret != cmd_len) {
  219. pr_err("es7210_read error1\n");
  220. return -1;
  221. }
  222. ret = i2c_master_recv(client, rt_value, 1);
  223. if (ret != 1) {
  224. pr_err("es7210_read error2, ret = %d.\n", ret);
  225. return -1;
  226. }
  227. return 0;
  228. }
  229. static int es7210_write(u8 reg, unsigned char value, struct i2c_client *client)
  230. {
  231. int ret = 0;
  232. u8 write_cmd[2] = {0};
  233. write_cmd[0] = reg;
  234. write_cmd[1] = value;
  235. ret = i2c_master_send(client, write_cmd, 2);
  236. if (ret != 2) {
  237. pr_err("es7210_write error->[REG-0x%02x,val-0x%02x]\n", reg, value);
  238. return -1;
  239. }
  240. return 0;
  241. }
  242. #ifndef ARK1668ED_DEMO_BOARD
  243. static unsigned int es7210_read_index(struct snd_soc_component *component,
  244. unsigned int reg)
  245. {
  246. int val;
  247. val = snd_soc_component_read(component, reg);
  248. return val;
  249. }
  250. static unsigned int es7210_read_reg(struct snd_soc_component *component,
  251. unsigned int reg)
  252. {
  253. unsigned int value;
  254. value = snd_soc_component_read(component, reg);
  255. return value;
  256. }
  257. static void es7210_write_reg(struct snd_soc_component *component,
  258. unsigned int reg, unsigned int value)
  259. {
  260. snd_soc_component_write(component, reg, value);
  261. }
  262. #endif
  263. static int es7210_update_bits(u8 reg, u8 mask, u8 value, struct i2c_client *client)
  264. {
  265. u8 val_old, val_new;
  266. es7210_read(reg, &val_old, client);
  267. val_new = (val_old & ~mask) | (value & mask);
  268. if (val_new != val_old) {
  269. es7210_write(reg, val_new, client);
  270. }
  271. return 0;
  272. }
  273. /*
  274. static int es7210_multi_chips_read(u8 reg, unsigned char *rt_value)
  275. {
  276. u8 i;
  277. for(i=0; i< ADC_DEV_MAXNUM; i++){
  278. es7210_read(reg, rt_value++, i2c_clt1[i]);
  279. }
  280. return 0;
  281. }
  282. */
  283. //#ifdef ARK1668E_KERNEL_VERSION_4_19
  284. //static int es7210_multi_chips_write(unsigned int reg, unsigned int value)
  285. //{
  286. // u8 i;
  287. // for(i=0; i< ADC_DEV_MAXNUM; i++){
  288. // es7210_write_reg(tron_codec1[i],reg, value);
  289. // }
  290. // return 0;
  291. //}
  292. //#else
  293. static int es7210_multi_chips_write(u8 reg, unsigned char value)
  294. {
  295. u8 i;
  296. for (i = 0; i < ADC_DEV_MAXNUM; i++) {
  297. es7210_write(reg, value, i2c_clt1[i]);
  298. }
  299. return 0;
  300. }
  301. //#endif
  302. static int es7210_multi_chips_update_bits(u8 reg, u8 mask, u8 value)
  303. {
  304. u8 i;
  305. for (i = 0; i < ADC_DEV_MAXNUM; i++) {
  306. es7210_update_bits(reg, mask, value, i2c_clt1[i]);
  307. }
  308. return 0;
  309. }
  310. /*
  311. * Note that this should be called from init rather than from hw_params.
  312. */
  313. static int es7210_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  314. int clk_id, unsigned int freq, int dir)
  315. {
  316. return 0;
  317. }
  318. static int es7210_set_dai_fmt(struct snd_soc_dai *codec_dai,
  319. unsigned int fmt)
  320. {
  321. return 0;
  322. }
  323. /*
  324. * to initialize es7210 for tdm mode
  325. */
  326. static void es7210_tdm_init_codec(struct snd_soc_component *component, u8 mode)
  327. {
  328. int cnt, channel;
  329. //printk("begin->>>>>>>>>>%s,mode = %d\n", __func__, mode);
  330. for (cnt = 0; cnt < ARRAY_SIZE(es7210_tdm_reg_common_cfg1); cnt++) {
  331. es7210_multi_chips_write(es7210_tdm_reg_common_cfg1[cnt].reg_addr,
  332. es7210_tdm_reg_common_cfg1[cnt].reg_v);
  333. }
  334. switch (mode) {
  335. case ES7210_TDM_1LRCK_DSPA:
  336. /*
  337. * Here to set TDM format for DSP-A mode
  338. */
  339. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  340. es7210_write(ES7210_SDP_CFG1_REG11, 0x63, i2c_clt1[cnt]);
  341. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x63);
  342. }
  343. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  344. es7210_write(ES7210_SDP_CFG2_REG12, 0x01, i2c_clt1[cnt]);
  345. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x01);
  346. }
  347. break;
  348. case ES7210_TDM_1LRCK_DSPB:
  349. /*
  350. * Here to set TDM format for DSP-B mode
  351. */
  352. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  353. es7210_write(ES7210_SDP_CFG1_REG11, 0x73, i2c_clt1[cnt]);
  354. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x73);
  355. }
  356. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  357. es7210_write(ES7210_SDP_CFG2_REG12, 0x01, i2c_clt1[cnt]);
  358. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x01);
  359. }
  360. break;
  361. case ES7210_TDM_1LRCK_I2S:
  362. /*
  363. * Here to set TDM format for I2S mode
  364. */
  365. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  366. es7210_write(ES7210_SDP_CFG1_REG11, 0x60, i2c_clt1[cnt]);
  367. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x60);
  368. }
  369. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  370. es7210_write(ES7210_SDP_CFG2_REG12, 0x02, i2c_clt1[cnt]);
  371. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x02);
  372. }
  373. break;
  374. case ES7210_TDM_1LRCK_LJ:
  375. /*
  376. * Here to set TDM format for Left Justified mode
  377. */
  378. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  379. es7210_write(ES7210_SDP_CFG1_REG11, 0x61, i2c_clt1[cnt]);
  380. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x61);
  381. }
  382. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  383. es7210_write(ES7210_SDP_CFG2_REG12, 0x02, i2c_clt1[cnt]);
  384. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x02);
  385. }
  386. break;
  387. case ES7210_TDM_NLRCK_DSPA:
  388. /*
  389. * Here to set TDM format for DSP-A with multiple LRCK TDM mode
  390. */
  391. channel = ES7210_CHANNELS_MAX;
  392. /*
  393. * Set the microphone numbers in array
  394. */
  395. switch (channel) {
  396. case 2:
  397. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x10);
  398. break;
  399. case 4:
  400. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x20);
  401. break;
  402. case 6:
  403. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x30);
  404. break;
  405. case 8:
  406. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x40);
  407. break;
  408. case 10:
  409. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x50);
  410. break;
  411. case 12:
  412. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x60);
  413. break;
  414. case 14:
  415. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x70);
  416. break;
  417. case 16:
  418. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x80);
  419. break;
  420. default:
  421. break;
  422. }
  423. /*
  424. * set format, dsp-a with multiple LRCK tdm mode
  425. */
  426. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  427. es7210_write(ES7210_SDP_CFG1_REG11, 0x63, i2c_clt1[cnt]);
  428. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x63);
  429. }
  430. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  431. if (cnt == 0) {
  432. /*
  433. * set tdm flag in the interface chip
  434. */
  435. es7210_write(ES7210_SDP_CFG2_REG12, 0x07, i2c_clt1[cnt]);
  436. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x07);
  437. } else {
  438. es7210_write(ES7210_SDP_CFG2_REG12, 0x03, i2c_clt1[cnt]);
  439. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x03);
  440. }
  441. }
  442. break;
  443. case ES7210_TDM_NLRCK_DSPB:
  444. /*
  445. * Here to set TDM format for DSP-B with multiple LRCK TDM mode
  446. */
  447. channel = ES7210_CHANNELS_MAX;
  448. /*
  449. * Set the microphone numbers in array
  450. */
  451. switch (channel) {
  452. case 2:
  453. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x10);
  454. break;
  455. case 4:
  456. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x20);
  457. break;
  458. case 6:
  459. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x30);
  460. break;
  461. case 8:
  462. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x40);
  463. break;
  464. case 10:
  465. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x50);
  466. break;
  467. case 12:
  468. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x60);
  469. break;
  470. case 14:
  471. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x70);
  472. break;
  473. case 16:
  474. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x80);
  475. break;
  476. default:
  477. break;
  478. }
  479. /*
  480. * set format, dsp-b with multiple LRCK tdm mode
  481. */
  482. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  483. es7210_write(ES7210_SDP_CFG1_REG11, 0x73, i2c_clt1[cnt]);
  484. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x73);
  485. }
  486. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  487. if (cnt == 0) {
  488. /*
  489. * set tdm flag in the interface chip
  490. */
  491. es7210_write(ES7210_SDP_CFG2_REG12, 0x07, i2c_clt1[cnt]);
  492. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x07);
  493. } else {
  494. es7210_write(ES7210_SDP_CFG2_REG12, 0x03, i2c_clt1[cnt]);
  495. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x03);
  496. }
  497. }
  498. break;
  499. case ES7210_TDM_NLRCK_I2S:
  500. /*
  501. * Here to set TDM format for I2S with multiple LRCK TDM mode
  502. */
  503. channel = ES7210_CHANNELS_MAX;
  504. /*
  505. * Set the microphone numbers in array
  506. */
  507. switch (channel) {
  508. case 2:
  509. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x10);
  510. break;
  511. case 4:
  512. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x20);
  513. break;
  514. case 6:
  515. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x30);
  516. break;
  517. case 8:
  518. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x40);/*ark1668e:{ 0x08, 0x40 }*/
  519. break;
  520. case 10:
  521. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x50);
  522. break;
  523. case 12:
  524. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x60);
  525. break;
  526. case 14:
  527. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x70);
  528. break;
  529. case 16:
  530. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x80);
  531. break;
  532. default:
  533. break;
  534. }
  535. /*
  536. * set format, I2S with multiple LRCK tdm mode
  537. */
  538. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  539. es7210_write(ES7210_SDP_CFG1_REG11, 0x60, i2c_clt1[cnt]);
  540. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x60);/*ark1668e:{ 0x11, 0x60 },*/
  541. }
  542. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  543. if (cnt == 0) {
  544. /*
  545. * set tdm flag in the interface chip
  546. */
  547. es7210_write(ES7210_SDP_CFG2_REG12, 0x07, i2c_clt1[cnt]);/*ark1668e:{ 0x12, 0x07 },*/
  548. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x07);/*ark1668e:{ 0x12, 0x07 },*/
  549. } else {
  550. es7210_write(ES7210_SDP_CFG2_REG12, 0x03, i2c_clt1[cnt]);
  551. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x03);
  552. }
  553. }
  554. break;
  555. case ES7210_TDM_NLRCK_LJ:
  556. /*
  557. * Here to set TDM format for left justified with multiple LRCK TDM mode
  558. */
  559. channel = ES7210_CHANNELS_MAX;
  560. /*
  561. * Set the microphone numbers in array
  562. */
  563. switch (channel) {
  564. case 2:
  565. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x10);
  566. break;
  567. case 4:
  568. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x20);
  569. break;
  570. case 6:
  571. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x30);
  572. break;
  573. case 8:
  574. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x40);
  575. break;
  576. case 10:
  577. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x50);
  578. break;
  579. case 12:
  580. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x60);
  581. break;
  582. case 14:
  583. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x70);
  584. break;
  585. case 16:
  586. es7210_multi_chips_write(ES7210_MODE_CFG_REG08, 0x80);
  587. break;
  588. default:
  589. break;
  590. }
  591. /*
  592. * set format, left justified with multiple LRCK tdm mode
  593. */
  594. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  595. es7210_write(ES7210_SDP_CFG1_REG11, 0x61, i2c_clt1[cnt]);
  596. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG1_REG11, 0x61);
  597. }
  598. for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
  599. if (cnt == 0) {
  600. /*
  601. * set tdm flag in the interface chip
  602. */
  603. es7210_write(ES7210_SDP_CFG2_REG12, 0x07, i2c_clt1[cnt]);
  604. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x07);
  605. } else {
  606. es7210_write(ES7210_SDP_CFG2_REG12, 0x03, i2c_clt1[cnt]);
  607. //es7210_write_reg(tron_codec1[cnt],ES7210_SDP_CFG2_REG12, 0x03);
  608. }
  609. }
  610. break;
  611. default:
  612. /*
  613. * here to disable tdm and set i2s-16bit for normal mode
  614. */
  615. es7210_multi_chips_write(ES7210_SDP_CFG1_REG11, 0x60); //i2s-16bits
  616. es7210_multi_chips_write(ES7210_SDP_CFG2_REG12, 0x00); //disable tdm
  617. break;
  618. }
  619. for (cnt = 0; cnt < ARRAY_SIZE(es7210_tdm_reg_common_cfg2); cnt++) {
  620. es7210_multi_chips_write(es7210_tdm_reg_common_cfg2[cnt].reg_addr,
  621. es7210_tdm_reg_common_cfg2[cnt].reg_v);
  622. }
  623. switch (mode) {
  624. case ES7210_TDM_1LRCK_DSPA:
  625. case ES7210_TDM_1LRCK_DSPB:
  626. case ES7210_TDM_1LRCK_I2S:
  627. case ES7210_TDM_1LRCK_LJ:
  628. /*
  629. * to set internal mclk
  630. * here, we assume that cpu/soc always provides 256FS i2s clock to es7210.
  631. * dll bypassed, use clock doubler to get double frequency for internal modem which need
  632. * 512FS clock. the clk divider ratio is 1.
  633. * user must modify the setting of register0x02 according to FS ratio provided by CPU/SOC.
  634. */
  635. es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, 0xc1);
  636. break;
  637. case ES7210_TDM_NLRCK_DSPA:
  638. case ES7210_TDM_NLRCK_DSPB:
  639. case ES7210_TDM_NLRCK_I2S:
  640. case ES7210_TDM_NLRCK_LJ:
  641. /*
  642. * to set internal mclk
  643. * here, we assume that cpu/soc always provides 256FS i2s clock to es7210 and there is four
  644. * es7210 devices in tdm link. so the internal FS in es7210 is only FS/4;
  645. * dll bypassed, clock doubler bypassed. the clk divider ratio is 2. so the clock of internal
  646. * modem equals to (256FS / (FS/4) / 2) * FS = 512FS
  647. * user must modify the setting of register0x02 according to FS ratio provided by CPU/SOC.
  648. */
  649. es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, 0x81);/*default:{ 0x02, 0x82 } ark1668e:{ 0x02, 0x81 },*/
  650. break;
  651. default:
  652. /*
  653. * to set internal mclk for normal mode
  654. * here, we assume that cpu/soc always provides 256FS i2s clock to es7210.
  655. * dll bypassed, use clock doubler to get double frequency for internal modem which need
  656. * 512FS clock. the clk divider ratio is 1.
  657. * user must modify the setting of register0x02 according to FS ratio provided by CPU/SOC.
  658. */
  659. es7210_multi_chips_write(ES7210_MCLK_CTL_REG02, 0xc1);
  660. break;
  661. }
  662. for (cnt = 0; cnt < ARRAY_SIZE(es7210_tdm_reg_common_cfg3); cnt++) {
  663. es7210_multi_chips_write(es7210_tdm_reg_common_cfg3[cnt].reg_addr,
  664. es7210_tdm_reg_common_cfg3[cnt].reg_v);
  665. }
  666. /*
  667. * Mute All ADC
  668. */
  669. es7210_multi_chips_update_bits(ES7210_ADC34_MUTE_REG14, 0x03, 0x03);
  670. es7210_multi_chips_update_bits(ES7210_ADC12_MUTE_REG15, 0x03, 0x03);
  671. //printk("exit->>>>>>>>>>%s!\n", __func__);
  672. }
  673. static void es7210_unmute(void)
  674. {
  675. printk("enter into %s\n", __func__);
  676. es7210_multi_chips_update_bits(ES7210_ADC34_MUTE_REG14, 0x03, 0x00);
  677. es7210_multi_chips_update_bits(ES7210_ADC12_MUTE_REG15, 0x03, 0x00);
  678. }
  679. static void pcm_pop_work_events(struct work_struct *work)
  680. {
  681. printk("enter into %s\n", __func__);
  682. es7210_unmute();
  683. es7210_init_reg = 1;
  684. }
  685. #ifndef ARK1668ED_DEMO_BOARD
  686. static int es7210_mute(struct snd_soc_dai *dai, int mute)
  687. {
  688. //struct snd_soc_codec *codec = dai->codec;
  689. u8 i;
  690. printk("enter into %s, mute = %d\n", __func__, mute);
  691. for (i = 0; i < ADC_DEV_MAXNUM; i++) {
  692. if (mute) {
  693. es7210_multi_chips_update_bits(ES7210_ADC34_MUTE_REG14, 0x03, 0x03);
  694. es7210_multi_chips_update_bits(ES7210_ADC12_MUTE_REG15, 0x03, 0x03);
  695. } else {
  696. es7210_multi_chips_update_bits(ES7210_ADC34_MUTE_REG14, 0x03, 0x00);
  697. es7210_multi_chips_update_bits(ES7210_ADC12_MUTE_REG15, 0x03, 0x00);
  698. }
  699. }
  700. return 0;
  701. }
  702. #endif
  703. static int es7210_pcm_startup(struct snd_pcm_substream *substream,
  704. struct snd_soc_dai *dai)
  705. {
  706. //struct snd_soc_codec *codec = dai->codec;
  707. struct snd_soc_component *component = dai->component;
  708. struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component);
  709. if (es7210_init_reg == 0) {
  710. schedule_delayed_work(&es7210->pcm_pop_work, msecs_to_jiffies(100));
  711. }
  712. return 0;
  713. }
  714. static int es7210_pcm_hw_params(struct snd_pcm_substream *substream,
  715. struct snd_pcm_hw_params *params,
  716. struct snd_soc_dai *dai)
  717. {
  718. return 0;
  719. }
  720. #define es7210_RATES SNDRV_PCM_RATE_8000_96000
  721. #define es7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  722. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  723. static struct snd_soc_dai_ops es7210_ops = {
  724. .startup = es7210_pcm_startup,
  725. .hw_params = es7210_pcm_hw_params,
  726. .set_fmt = es7210_set_dai_fmt,
  727. .set_sysclk = es7210_set_dai_sysclk,
  728. //.digital_mute = es7210_mute,
  729. };
  730. #if ES7210_CHANNELS_MAX > 0
  731. static struct snd_soc_dai_driver es7210_dai0 = {
  732. .name = "ES7210 4CH ADC 0",
  733. .capture = {
  734. .stream_name = "Capture",
  735. .channels_min = 1,
  736. .channels_max = 4,
  737. .rates = es7210_RATES,
  738. .formats = es7210_FORMATS,
  739. },
  740. .ops = &es7210_ops,
  741. .symmetric_rate = 1,
  742. };
  743. #endif
  744. #if ES7210_CHANNELS_MAX > 4
  745. static struct snd_soc_dai_driver es7210_dai1 = {
  746. .name = "ES7210 4CH ADC 1",
  747. .capture = {
  748. .stream_name = "Capture",
  749. .channels_min = 1,
  750. .channels_max = 4,
  751. .rates = es7210_RATES,
  752. .formats = es7210_FORMATS,
  753. },
  754. .ops = &es7210_ops,
  755. .symmetric_rate = 1,
  756. };
  757. #endif
  758. #if ES7210_CHANNELS_MAX > 8
  759. static struct snd_soc_dai_driver es7210_dai2 = {
  760. .name = "ES7210 4CH ADC 2",
  761. .capture = {
  762. .stream_name = "Capture",
  763. .channels_min = 1,
  764. .channels_max = 4,
  765. .rates = es7210_RATES,
  766. .formats = es7210_FORMATS,
  767. },
  768. .ops = &es7210_ops,
  769. .symmetric_rate = 1,
  770. };
  771. #endif
  772. #if ES7210_CHANNELS_MAX > 12
  773. static struct snd_soc_dai_driver es7210_dai3 = {
  774. .name = "ES7210 4CH ADC 3",
  775. .capture = {
  776. .stream_name = "Capture",
  777. .channels_min = 1,
  778. .channels_max = 4,
  779. .rates = es7210_RATES,
  780. .formats = es7210_FORMATS,
  781. },
  782. .ops = &es7210_ops,
  783. .symmetric_rate = 1,
  784. };
  785. #endif
  786. static struct snd_soc_dai_driver *es7210_dai[] = {
  787. #if ES7210_CHANNELS_MAX > 0
  788. &es7210_dai0,
  789. #endif
  790. #if ES7210_CHANNELS_MAX > 4
  791. &es7210_dai1,
  792. #endif
  793. #if ES7210_CHANNELS_MAX > 8
  794. &es7210_dai2,
  795. #endif
  796. #if ES7210_CHANNELS_MAX > 12
  797. &es7210_dai3,
  798. #endif
  799. };
  800. static int es7210_suspend(struct snd_soc_component *component)
  801. {
  802. //struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component);
  803. return 0;
  804. }
  805. static int es7210_resume(struct snd_soc_component *component)
  806. {
  807. //snd_soc_cache_sync(codec);
  808. //struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component);
  809. return 0;
  810. }
  811. static int es7210_probe(struct snd_soc_component *component)
  812. {
  813. struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component);
  814. int ret = 0;
  815. //es7210_component = component;
  816. // es7210->mclk = devm_clk_get(component->dev, "mclk");
  817. // if (PTR_ERR(es7210->mclk) == -EPROBE_DEFER)
  818. // return -EPROBE_DEFER;
  819. // ret = clk_prepare_enable(es7210->mclk);
  820. // if (ret)
  821. // return ret;
  822. #if !ES7210_CODEC_RW_TEST_EN
  823. //ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);//8,8
  824. #else
  825. component->codec->control_data = devm_regmap_init_i2c(es7210->i2c, &es7210_regmap_config);
  826. ret = PTR_RET(component->codec->control_data);
  827. #endif
  828. if (ret < 0) {
  829. dev_err(component->dev, "Failed to set cache I/O: %d\n", ret);
  830. return ret;
  831. }
  832. printk("begin->>>>>>>>>>%s!\n", __func__);
  833. tron_codec1[es7210_codec_num++] = component;
  834. INIT_DELAYED_WORK(&es7210->pcm_pop_work, pcm_pop_work_events);
  835. es7210_tdm_init_codec(tron_codec1[es7210_codec_num], es7210->tdm_mode);
  836. return 0;
  837. }
  838. static void es7210_remove(struct snd_soc_component *component)
  839. {
  840. }
  841. static int es7210_set_bias_level(struct snd_soc_component *component,
  842. enum snd_soc_bias_level level)
  843. {
  844. struct es7210_priv *es7210 = snd_soc_component_get_drvdata(component);
  845. int ret;
  846. switch (level) {
  847. case SND_SOC_BIAS_ON:
  848. break;
  849. case SND_SOC_BIAS_PREPARE:
  850. if (IS_ERR(es7210->mclk))
  851. break;
  852. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
  853. clk_disable_unprepare(es7210->mclk);
  854. } else {
  855. ret = clk_prepare_enable(es7210->mclk);
  856. if (ret)
  857. return ret;
  858. }
  859. break;
  860. case SND_SOC_BIAS_STANDBY:
  861. break;
  862. case SND_SOC_BIAS_OFF:
  863. break;
  864. }
  865. return 0;
  866. }
  867. static const DECLARE_TLV_DB_SCALE(mic_boost_tlv, 0, 300, 0);
  868. #if ES7210_CHANNELS_MAX > 0
  869. static int es7210_micboost1_setting_set(struct snd_kcontrol *kcontrol,
  870. struct snd_ctl_elem_value *ucontrol)
  871. {
  872. es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[0]);
  873. return 0;
  874. }
  875. static int es7210_micboost1_setting_get(struct snd_kcontrol *kcontrol,
  876. struct snd_ctl_elem_value *ucontrol)
  877. {
  878. u8 val;
  879. es7210_read(0x43, &val, i2c_clt1[0]);
  880. ucontrol->value.integer.value[0] = val;
  881. return 0;
  882. }
  883. static int es7210_micboost2_setting_set(struct snd_kcontrol *kcontrol,
  884. struct snd_ctl_elem_value *ucontrol)
  885. {
  886. es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[0]);
  887. return 0;
  888. }
  889. static int es7210_micboost2_setting_get(struct snd_kcontrol *kcontrol,
  890. struct snd_ctl_elem_value *ucontrol)
  891. {
  892. u8 val;
  893. es7210_read(0x44, &val, i2c_clt1[0]);
  894. ucontrol->value.integer.value[0] = val;
  895. return 0;
  896. }
  897. static int es7210_micboost3_setting_set(struct snd_kcontrol *kcontrol,
  898. struct snd_ctl_elem_value *ucontrol)
  899. {
  900. es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[0]);
  901. return 0;
  902. }
  903. static int es7210_micboost3_setting_get(struct snd_kcontrol *kcontrol,
  904. struct snd_ctl_elem_value *ucontrol)
  905. {
  906. u8 val;
  907. es7210_read(0x45, &val, i2c_clt1[0]);
  908. ucontrol->value.integer.value[0] = val;
  909. return 0;
  910. }
  911. static int es7210_micboost4_setting_set(struct snd_kcontrol *kcontrol,
  912. struct snd_ctl_elem_value *ucontrol)
  913. {
  914. es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[0]);
  915. return 0;
  916. }
  917. static int es7210_micboost4_setting_get(struct snd_kcontrol *kcontrol,
  918. struct snd_ctl_elem_value *ucontrol)
  919. {
  920. u8 val;
  921. es7210_read(0x46, &val, i2c_clt1[0]);
  922. ucontrol->value.integer.value[0] = val;
  923. return 0;
  924. }
  925. static int es7210_adc1_mute_set(struct snd_kcontrol *kcontrol,
  926. struct snd_ctl_elem_value *ucontrol)
  927. {
  928. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01,
  929. ucontrol->value.integer.value[0], i2c_clt1[0]);
  930. return 0;
  931. }
  932. static int es7210_adc1_mute_get(struct snd_kcontrol *kcontrol,
  933. struct snd_ctl_elem_value *ucontrol)
  934. {
  935. u8 val;
  936. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[0]);
  937. ucontrol->value.integer.value[0] = val;
  938. return 0;
  939. }
  940. static int es7210_adc2_mute_set(struct snd_kcontrol *kcontrol,
  941. struct snd_ctl_elem_value *ucontrol)
  942. {
  943. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02,
  944. ucontrol->value.integer.value[0], i2c_clt1[0]);
  945. return 0;
  946. }
  947. static int es7210_adc2_mute_get(struct snd_kcontrol *kcontrol,
  948. struct snd_ctl_elem_value *ucontrol)
  949. {
  950. u8 val;
  951. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[0]);
  952. ucontrol->value.integer.value[0] = val;
  953. return 0;
  954. }
  955. static int es7210_adc3_mute_set(struct snd_kcontrol *kcontrol,
  956. struct snd_ctl_elem_value *ucontrol)
  957. {
  958. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01,
  959. ucontrol->value.integer.value[0], i2c_clt1[0]);
  960. return 0;
  961. }
  962. static int es7210_adc3_mute_get(struct snd_kcontrol *kcontrol,
  963. struct snd_ctl_elem_value *ucontrol)
  964. {
  965. u8 val;
  966. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[0]);
  967. ucontrol->value.integer.value[0] = val;
  968. return 0;
  969. }
  970. static int es7210_adc4_mute_set(struct snd_kcontrol *kcontrol,
  971. struct snd_ctl_elem_value *ucontrol)
  972. {
  973. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02,
  974. ucontrol->value.integer.value[0], i2c_clt1[0]);
  975. return 0;
  976. }
  977. static int es7210_adc4_mute_get(struct snd_kcontrol *kcontrol,
  978. struct snd_ctl_elem_value *ucontrol)
  979. {
  980. u8 val;
  981. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[0]);
  982. ucontrol->value.integer.value[0] = val;
  983. return 0;
  984. }
  985. #endif
  986. #if ES7210_CHANNELS_MAX > 4
  987. static int es7210_micboost5_setting_set(struct snd_kcontrol *kcontrol,
  988. struct snd_ctl_elem_value *ucontrol)
  989. {
  990. es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]);
  991. return 0;
  992. }
  993. static int es7210_micboost5_setting_get(struct snd_kcontrol *kcontrol,
  994. struct snd_ctl_elem_value *ucontrol)
  995. {
  996. u8 val;
  997. es7210_read(0x43, &val, i2c_clt1[1]);
  998. ucontrol->value.integer.value[0] = val;
  999. return 0;
  1000. }
  1001. static int es7210_micboost6_setting_set(struct snd_kcontrol *kcontrol,
  1002. struct snd_ctl_elem_value *ucontrol)
  1003. {
  1004. es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]);
  1005. return 0;
  1006. }
  1007. static int es7210_micboost6_setting_get(struct snd_kcontrol *kcontrol,
  1008. struct snd_ctl_elem_value *ucontrol)
  1009. {
  1010. u8 val;
  1011. es7210_read(0x44, &val, i2c_clt1[1]);
  1012. ucontrol->value.integer.value[0] = val;
  1013. return 0;
  1014. }
  1015. static int es7210_micboost7_setting_set(struct snd_kcontrol *kcontrol,
  1016. struct snd_ctl_elem_value *ucontrol)
  1017. {
  1018. es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]);
  1019. return 0;
  1020. }
  1021. static int es7210_micboost7_setting_get(struct snd_kcontrol *kcontrol,
  1022. struct snd_ctl_elem_value *ucontrol)
  1023. {
  1024. u8 val;
  1025. es7210_read(0x45, &val, i2c_clt1[1]);
  1026. ucontrol->value.integer.value[0] = val;
  1027. return 0;
  1028. }
  1029. static int es7210_micboost8_setting_set(struct snd_kcontrol *kcontrol,
  1030. struct snd_ctl_elem_value *ucontrol)
  1031. {
  1032. es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[1]);
  1033. return 0;
  1034. }
  1035. static int es7210_micboost8_setting_get(struct snd_kcontrol *kcontrol,
  1036. struct snd_ctl_elem_value *ucontrol)
  1037. {
  1038. u8 val;
  1039. es7210_read(0x46, &val, i2c_clt1[1]);
  1040. ucontrol->value.integer.value[0] = val;
  1041. return 0;
  1042. }
  1043. static int es7210_adc5_mute_set(struct snd_kcontrol *kcontrol,
  1044. struct snd_ctl_elem_value *ucontrol)
  1045. {
  1046. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01,
  1047. ucontrol->value.integer.value[0], i2c_clt1[1]);
  1048. return 0;
  1049. }
  1050. static int es7210_adc5_mute_get(struct snd_kcontrol *kcontrol,
  1051. struct snd_ctl_elem_value *ucontrol)
  1052. {
  1053. u8 val;
  1054. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[1]);
  1055. ucontrol->value.integer.value[0] = val;
  1056. return 0;
  1057. }
  1058. static int es7210_adc6_mute_set(struct snd_kcontrol *kcontrol,
  1059. struct snd_ctl_elem_value *ucontrol)
  1060. {
  1061. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02,
  1062. ucontrol->value.integer.value[0], i2c_clt1[1]);
  1063. return 0;
  1064. }
  1065. static int es7210_adc6_mute_get(struct snd_kcontrol *kcontrol,
  1066. struct snd_ctl_elem_value *ucontrol)
  1067. {
  1068. u8 val;
  1069. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[1]);
  1070. ucontrol->value.integer.value[0] = val;
  1071. return 0;
  1072. }
  1073. static int es7210_adc7_mute_set(struct snd_kcontrol *kcontrol,
  1074. struct snd_ctl_elem_value *ucontrol)
  1075. {
  1076. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01,
  1077. ucontrol->value.integer.value[0], i2c_clt1[1]);
  1078. return 0;
  1079. }
  1080. static int es7210_adc7_mute_get(struct snd_kcontrol *kcontrol,
  1081. struct snd_ctl_elem_value *ucontrol)
  1082. {
  1083. u8 val;
  1084. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[1]);
  1085. ucontrol->value.integer.value[0] = val;
  1086. return 0;
  1087. }
  1088. static int es7210_adc8_mute_set(struct snd_kcontrol *kcontrol,
  1089. struct snd_ctl_elem_value *ucontrol)
  1090. {
  1091. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02,
  1092. ucontrol->value.integer.value[0], i2c_clt1[1]);
  1093. return 0;
  1094. }
  1095. static int es7210_adc8_mute_get(struct snd_kcontrol *kcontrol,
  1096. struct snd_ctl_elem_value *ucontrol)
  1097. {
  1098. u8 val;
  1099. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[1]);
  1100. ucontrol->value.integer.value[0] = val;
  1101. return 0;
  1102. }
  1103. #endif
  1104. #if ES7210_CHANNELS_MAX > 8
  1105. static int es7210_micboost9_setting_set(struct snd_kcontrol *kcontrol,
  1106. struct snd_ctl_elem_value *ucontrol)
  1107. {
  1108. es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]);
  1109. return 0;
  1110. }
  1111. static int es7210_micboost9_setting_get(struct snd_kcontrol *kcontrol,
  1112. struct snd_ctl_elem_value *ucontrol)
  1113. {
  1114. u8 val;
  1115. es7210_read(0x43, &val, i2c_clt1[2]);
  1116. ucontrol->value.integer.value[0] = val;
  1117. return 0;
  1118. }
  1119. static int es7210_micboost10_setting_set(struct snd_kcontrol *kcontrol,
  1120. struct snd_ctl_elem_value *ucontrol)
  1121. {
  1122. es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]);
  1123. return 0;
  1124. }
  1125. static int es7210_micboost10_setting_get(struct snd_kcontrol *kcontrol,
  1126. struct snd_ctl_elem_value *ucontrol)
  1127. {
  1128. u8 val;
  1129. es7210_read(0x44, &val, i2c_clt1[2]);
  1130. ucontrol->value.integer.value[0] = val;
  1131. return 0;
  1132. }
  1133. static int es7210_micboost11_setting_set(struct snd_kcontrol *kcontrol,
  1134. struct snd_ctl_elem_value *ucontrol)
  1135. {
  1136. es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]);
  1137. return 0;
  1138. }
  1139. static int es7210_micboost11_setting_get(struct snd_kcontrol *kcontrol,
  1140. struct snd_ctl_elem_value *ucontrol)
  1141. {
  1142. u8 val;
  1143. es7210_read(0x45, &val, i2c_clt1[2]);
  1144. ucontrol->value.integer.value[0] = val;
  1145. return 0;
  1146. }
  1147. static int es7210_micboost12_setting_set(struct snd_kcontrol *kcontrol,
  1148. struct snd_ctl_elem_value *ucontrol)
  1149. {
  1150. es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[2]);
  1151. return 0;
  1152. }
  1153. static int es7210_micboost12_setting_get(struct snd_kcontrol *kcontrol,
  1154. struct snd_ctl_elem_value *ucontrol)
  1155. {
  1156. u8 val;
  1157. es7210_read(0x46, &val, i2c_clt1[2]);
  1158. ucontrol->value.integer.value[0] = val;
  1159. return 0;
  1160. }
  1161. static int es7210_adc9_mute_set(struct snd_kcontrol *kcontrol,
  1162. struct snd_ctl_elem_value *ucontrol)
  1163. {
  1164. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01,
  1165. ucontrol->value.integer.value[0], i2c_clt1[2]);
  1166. return 0;
  1167. }
  1168. static int es7210_adc9_mute_get(struct snd_kcontrol *kcontrol,
  1169. struct snd_ctl_elem_value *ucontrol)
  1170. {
  1171. u8 val;
  1172. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[2]);
  1173. ucontrol->value.integer.value[0] = val;
  1174. return 0;
  1175. }
  1176. static int es7210_adc10_mute_set(struct snd_kcontrol *kcontrol,
  1177. struct snd_ctl_elem_value *ucontrol)
  1178. {
  1179. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02,
  1180. ucontrol->value.integer.value[0], i2c_clt1[2]);
  1181. return 0;
  1182. }
  1183. static int es7210_adc10_mute_get(struct snd_kcontrol *kcontrol,
  1184. struct snd_ctl_elem_value *ucontrol)
  1185. {
  1186. u8 val;
  1187. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[2]);
  1188. ucontrol->value.integer.value[0] = val;
  1189. return 0;
  1190. }
  1191. static int es7210_adc11_mute_set(struct snd_kcontrol *kcontrol,
  1192. struct snd_ctl_elem_value *ucontrol)
  1193. {
  1194. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01,
  1195. ucontrol->value.integer.value[0], i2c_clt1[2]);
  1196. return 0;
  1197. }
  1198. static int es7210_adc11_mute_get(struct snd_kcontrol *kcontrol,
  1199. struct snd_ctl_elem_value *ucontrol)
  1200. {
  1201. u8 val;
  1202. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[2]);
  1203. ucontrol->value.integer.value[0] = val;
  1204. return 0;
  1205. }
  1206. static int es7210_adc12_mute_set(struct snd_kcontrol *kcontrol,
  1207. struct snd_ctl_elem_value *ucontrol)
  1208. {
  1209. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02,
  1210. ucontrol->value.integer.value[0], i2c_clt1[2]);
  1211. return 0;
  1212. }
  1213. static int es7210_adc12_mute_get(struct snd_kcontrol *kcontrol,
  1214. struct snd_ctl_elem_value *ucontrol)
  1215. {
  1216. u8 val;
  1217. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[2]);
  1218. ucontrol->value.integer.value[0] = val;
  1219. return 0;
  1220. }
  1221. #endif
  1222. #if ES7210_CHANNELS_MAX > 12
  1223. static int es7210_micboost13_setting_set(struct snd_kcontrol *kcontrol,
  1224. struct snd_ctl_elem_value *ucontrol)
  1225. {
  1226. es7210_update_bits(0x43, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]);
  1227. return 0;
  1228. }
  1229. static int es7210_micboost13_setting_get(struct snd_kcontrol *kcontrol,
  1230. struct snd_ctl_elem_value *ucontrol)
  1231. {
  1232. u8 val;
  1233. es7210_read(0x43, &val, i2c_clt1[3]);
  1234. ucontrol->value.integer.value[0] = val;
  1235. return 0;
  1236. }
  1237. static int es7210_micboost14_setting_set(struct snd_kcontrol *kcontrol,
  1238. struct snd_ctl_elem_value *ucontrol)
  1239. {
  1240. es7210_update_bits(0x44, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]);
  1241. return 0;
  1242. }
  1243. static int es7210_micboost14_setting_get(struct snd_kcontrol *kcontrol,
  1244. struct snd_ctl_elem_value *ucontrol)
  1245. {
  1246. u8 val;
  1247. es7210_read(0x44, &val, i2c_clt1[3]);
  1248. ucontrol->value.integer.value[0] = val;
  1249. return 0;
  1250. }
  1251. static int es7210_micboost15_setting_set(struct snd_kcontrol *kcontrol,
  1252. struct snd_ctl_elem_value *ucontrol)
  1253. {
  1254. es7210_update_bits(0x45, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]);
  1255. return 0;
  1256. }
  1257. static int es7210_micboost15_setting_get(struct snd_kcontrol *kcontrol,
  1258. struct snd_ctl_elem_value *ucontrol)
  1259. {
  1260. u8 val;
  1261. es7210_read(0x45, &val, i2c_clt1[3]);
  1262. ucontrol->value.integer.value[0] = val;
  1263. return 0;
  1264. }
  1265. static int es7210_micboost16_setting_set(struct snd_kcontrol *kcontrol,
  1266. struct snd_ctl_elem_value *ucontrol)
  1267. {
  1268. es7210_update_bits(0x46, 0x0F, ucontrol->value.integer.value[0], i2c_clt1[3]);
  1269. return 0;
  1270. }
  1271. static int es7210_micboost16_setting_get(struct snd_kcontrol *kcontrol,
  1272. struct snd_ctl_elem_value *ucontrol)
  1273. {
  1274. u8 val;
  1275. es7210_read(0x46, &val, i2c_clt1[3]);
  1276. ucontrol->value.integer.value[0] = val;
  1277. return 0;
  1278. }
  1279. static int es7210_adc13_mute_set(struct snd_kcontrol *kcontrol,
  1280. struct snd_ctl_elem_value *ucontrol)
  1281. {
  1282. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x01,
  1283. ucontrol->value.integer.value[0], i2c_clt1[3]);
  1284. return 0;
  1285. }
  1286. static int es7210_adc13_mute_get(struct snd_kcontrol *kcontrol,
  1287. struct snd_ctl_elem_value *ucontrol)
  1288. {
  1289. u8 val;
  1290. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[3]);
  1291. ucontrol->value.integer.value[0] = val;
  1292. return 0;
  1293. }
  1294. static int es7210_adc14_mute_set(struct snd_kcontrol *kcontrol,
  1295. struct snd_ctl_elem_value *ucontrol)
  1296. {
  1297. es7210_update_bits(ES7210_ADC12_MUTE_REG15, 0x02,
  1298. ucontrol->value.integer.value[0], i2c_clt1[3]);
  1299. return 0;
  1300. }
  1301. static int es7210_adc14_mute_get(struct snd_kcontrol *kcontrol,
  1302. struct snd_ctl_elem_value *ucontrol)
  1303. {
  1304. u8 val;
  1305. es7210_read(ES7210_ADC12_MUTE_REG15, &val, i2c_clt1[3]);
  1306. ucontrol->value.integer.value[0] = val;
  1307. return 0;
  1308. }
  1309. static int es7210_adc15_mute_set(struct snd_kcontrol *kcontrol,
  1310. struct snd_ctl_elem_value *ucontrol)
  1311. {
  1312. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x01,
  1313. ucontrol->value.integer.value[0], i2c_clt1[3]);
  1314. return 0;
  1315. }
  1316. static int es7210_adc15_mute_get(struct snd_kcontrol *kcontrol,
  1317. struct snd_ctl_elem_value *ucontrol)
  1318. {
  1319. u8 val;
  1320. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[3]);
  1321. ucontrol->value.integer.value[0] = val;
  1322. return 0;
  1323. }
  1324. static int es7210_adc16_mute_set(struct snd_kcontrol *kcontrol,
  1325. struct snd_ctl_elem_value *ucontrol)
  1326. {
  1327. es7210_update_bits(ES7210_ADC34_MUTE_REG14, 0x02,
  1328. ucontrol->value.integer.value[0], i2c_clt1[3]);
  1329. return 0;
  1330. }
  1331. static int es7210_adc16_mute_get(struct snd_kcontrol *kcontrol,
  1332. struct snd_ctl_elem_value *ucontrol)
  1333. {
  1334. u8 val;
  1335. es7210_read(ES7210_ADC34_MUTE_REG14, &val, i2c_clt1[3]);
  1336. ucontrol->value.integer.value[0] = val;
  1337. return 0;
  1338. }
  1339. #endif
  1340. static const struct snd_kcontrol_new es7210_snd_controls[] = {
  1341. #if ES7210_CHANNELS_MAX > 0
  1342. SOC_SINGLE_EXT_TLV("PGA1_setting",
  1343. 0x43, 0, 0x0F, 0,
  1344. es7210_micboost1_setting_get, es7210_micboost1_setting_set,
  1345. mic_boost_tlv),
  1346. SOC_SINGLE_EXT_TLV("PGA2_setting",
  1347. 0x44, 0, 0x0F, 0,
  1348. es7210_micboost2_setting_get, es7210_micboost2_setting_set,
  1349. mic_boost_tlv),
  1350. SOC_SINGLE_EXT_TLV("PGA3_setting",
  1351. 0x45, 0, 0x0F, 0,
  1352. es7210_micboost3_setting_get, es7210_micboost3_setting_set,
  1353. mic_boost_tlv),
  1354. SOC_SINGLE_EXT_TLV("PGA4_setting",
  1355. 0x46, 0, 0x0F, 0,
  1356. es7210_micboost4_setting_get, es7210_micboost4_setting_set,
  1357. mic_boost_tlv),
  1358. SOC_SINGLE_EXT("ADC1_MUTE", ES7210_ADC12_MUTE_REG15, 0, 1, 0,
  1359. es7210_adc1_mute_get, es7210_adc1_mute_set),
  1360. SOC_SINGLE_EXT("ADC2_MUTE", ES7210_ADC12_MUTE_REG15, 1, 1, 0,
  1361. es7210_adc2_mute_get, es7210_adc2_mute_set),
  1362. SOC_SINGLE_EXT("ADC3_MUTE", ES7210_ADC34_MUTE_REG14, 0, 1, 0,
  1363. es7210_adc3_mute_get, es7210_adc3_mute_set),
  1364. SOC_SINGLE_EXT("ADC4_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0,
  1365. es7210_adc4_mute_get, es7210_adc4_mute_set),
  1366. #endif
  1367. #if ES7210_CHANNELS_MAX > 4
  1368. SOC_SINGLE_EXT_TLV("PGA5_setting",
  1369. 0x43, 0, 0x0F, 0,
  1370. es7210_micboost5_setting_get, es7210_micboost5_setting_set,
  1371. mic_boost_tlv),
  1372. SOC_SINGLE_EXT_TLV("PGA6_setting",
  1373. 0x44, 0, 0x0F, 0,
  1374. es7210_micboost6_setting_get, es7210_micboost6_setting_set,
  1375. mic_boost_tlv),
  1376. SOC_SINGLE_EXT_TLV("PGA7_setting",
  1377. 0x45, 0, 0x0F, 0,
  1378. es7210_micboost7_setting_get, es7210_micboost7_setting_set,
  1379. mic_boost_tlv),
  1380. SOC_SINGLE_EXT_TLV("PGA8_setting",
  1381. 0x46, 0, 0x0F, 0,
  1382. es7210_micboost8_setting_get, es7210_micboost8_setting_set,
  1383. mic_boost_tlv),
  1384. SOC_SINGLE_EXT("ADC5_MUTE", ES7210_ADC12_MUTE_REG15, 0, 1, 0,
  1385. es7210_adc5_mute_get, es7210_adc5_mute_set),
  1386. SOC_SINGLE_EXT("ADC6_MUTE", ES7210_ADC12_MUTE_REG15, 1, 1, 0,
  1387. es7210_adc6_mute_get, es7210_adc6_mute_set),
  1388. SOC_SINGLE_EXT("ADC7_MUTE", ES7210_ADC34_MUTE_REG14, 0, 1, 0,
  1389. es7210_adc7_mute_get, es7210_adc7_mute_set),
  1390. SOC_SINGLE_EXT("ADC8_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0,
  1391. es7210_adc8_mute_get, es7210_adc8_mute_set),
  1392. #endif
  1393. #if ES7210_CHANNELS_MAX > 8
  1394. SOC_SINGLE_EXT_TLV("PGA9_setting",
  1395. 0x43, 0, 0x0F, 0,
  1396. es7210_micboost9_setting_get, es7210_micboost9_setting_set,
  1397. mic_boost_tlv),
  1398. SOC_SINGLE_EXT_TLV("PGA10_setting",
  1399. 0x44, 0, 0x0F, 0,
  1400. es7210_micboost10_setting_get, es7210_micboost10_setting_set,
  1401. mic_boost_tlv),
  1402. SOC_SINGLE_EXT_TLV("PGA11_setting",
  1403. 0x45, 0, 0x0F, 0,
  1404. es7210_micboost11_setting_get, es7210_micboost11_setting_set,
  1405. mic_boost_tlv),
  1406. SOC_SINGLE_EXT_TLV("PGA12_setting",
  1407. 0x46, 0, 0x0F, 0,
  1408. es7210_micboost12_setting_get, es7210_micboost12_setting_set,
  1409. mic_boost_tlv),
  1410. SOC_SINGLE_EXT("ADC9_MUTE", ES7210_ADC12_MUTE_REG15, 0, 1, 0,
  1411. es7210_adc9_mute_get, es7210_adc9_mute_set),
  1412. SOC_SINGLE_EXT("ADC10_MUTE", ES7210_ADC12_MUTE_REG15, 1, 1, 0,
  1413. es7210_adc10_mute_get, es7210_adc10_mute_set),
  1414. SOC_SINGLE_EXT("ADC11_MUTE", ES7210_ADC34_MUTE_REG14, 0, 1, 0,
  1415. es7210_adc11_mute_get, es7210_adc11_mute_set),
  1416. SOC_SINGLE_EXT("ADC12_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0,
  1417. es7210_adc12_mute_get, es7210_adc12_mute_set),
  1418. #endif
  1419. #if ES7210_CHANNELS_MAX > 12
  1420. SOC_SINGLE_EXT_TLV("PGA13_setting",
  1421. 0x43, 0, 0x0F, 0,
  1422. es7210_micboost13_setting_get, es7210_micboost13_setting_set,
  1423. mic_boost_tlv),
  1424. SOC_SINGLE_EXT_TLV("PGA14_setting",
  1425. 0x44, 0, 0x0F, 0,
  1426. es7210_micboost14_setting_get, es7210_micboost14_setting_set,
  1427. mic_boost_tlv),
  1428. SOC_SINGLE_EXT_TLV("PGA15_setting",
  1429. 0x45, 0, 0x0F, 0,
  1430. es7210_micboost15_setting_get, es7210_micboost15_setting_set,
  1431. mic_boost_tlv),
  1432. SOC_SINGLE_EXT_TLV("PGA16_setting",
  1433. 0x46, 0, 0x0F, 0,
  1434. es7210_micboost16_setting_get, es7210_micboost16_setting_set,
  1435. mic_boost_tlv),
  1436. SOC_SINGLE_EXT("ADC13_MUTE", ES7210_ADC12_MUTE_REG15, 0, 1, 0,
  1437. es7210_adc13_mute_get, es7210_adc13_mute_set),
  1438. SOC_SINGLE_EXT("ADC14_MUTE", ES7210_ADC12_MUTE_REG15, 1, 1, 0,
  1439. es7210_adc14_mute_get, es7210_adc14_mute_set),
  1440. SOC_SINGLE_EXT("ADC15_MUTE", ES7210_ADC34_MUTE_REG14, 0, 1, 0,
  1441. es7210_adc15_mute_get, es7210_adc15_mute_set),
  1442. SOC_SINGLE_EXT("ADC16_MUTE", ES7210_ADC34_MUTE_REG14, 1, 1, 0,
  1443. es7210_adc16_mute_get, es7210_adc16_mute_set),
  1444. #endif
  1445. };
  1446. static struct snd_soc_component_driver soc_component_dev_es7210 = {
  1447. .probe = es7210_probe,
  1448. .remove = es7210_remove,
  1449. .suspend = es7210_suspend,
  1450. .resume = es7210_resume,
  1451. .set_bias_level = es7210_set_bias_level,
  1452. //.idle_bias_off = true,
  1453. // .reg_word_size = sizeof(u8),
  1454. // .reg_cache_default = es7210_reg_defaults,
  1455. // .reg_cache_size = ARRAY_SIZE(es7210_reg_defaults),
  1456. .controls = es7210_snd_controls,
  1457. .num_controls = ARRAY_SIZE(es7210_snd_controls),
  1458. };
  1459. static ssize_t es7210_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1460. {
  1461. int val = 0, flag = 0;
  1462. u8 i = 0, reg, num, value_w, value_r;
  1463. struct es7210_priv *es7210 = dev_get_drvdata(dev);
  1464. val = simple_strtol(buf, NULL, 16);
  1465. flag = (val >> 16) & 0xFF;
  1466. if (flag) {
  1467. reg = (val >> 8) & 0xFF;
  1468. value_w = val & 0xFF;
  1469. printk("\nWrite: start REG:0x%02x,val:0x%02x,count:0x%02x\n", reg, value_w, flag);
  1470. while (flag--) {
  1471. es7210_write(reg, value_w, es7210->i2c);
  1472. printk("Write 0x%02x to REG:0x%02x\n", value_w, reg);
  1473. reg++;
  1474. }
  1475. } else {
  1476. reg = (val >> 8) & 0xFF;
  1477. num = val & 0xff;
  1478. printk("\nRead: start REG:0x%02x,count:0x%02x\n", reg, num);
  1479. do {
  1480. value_r = 0;
  1481. es7210_read(reg, &value_r, es7210->i2c);
  1482. printk("REG[0x%02x]: 0x%02x; ", reg, value_r);
  1483. reg++;
  1484. i++;
  1485. if ((i == num) || (i%4 == 0))
  1486. printk("\n");
  1487. } while (i < num);
  1488. }
  1489. return count;
  1490. }
  1491. static ssize_t es7210_show(struct device *dev, struct device_attribute *attr, char *buf)
  1492. {
  1493. printk("echo flag|reg|val > es7210\n");
  1494. printk("eg read star addres=0x06,count 0x10:echo 0610 >es7210\n");
  1495. printk("eg write star addres=0x90,value=0x3c,count=4:echo 4903c >es7210\n");
  1496. //printk("eg write value:0xfe to address:0x06 :echo 106fe > es7210\n");
  1497. return 0;
  1498. }
  1499. static DEVICE_ATTR(es7210, 0644, es7210_show, es7210_store);
  1500. static struct attribute *es7210_debug_attrs[] = {
  1501. &dev_attr_es7210.attr,
  1502. NULL,
  1503. };
  1504. static struct attribute_group es7210_debug_attr_group = {
  1505. .name = "es7210_debug",
  1506. .attrs = es7210_debug_attrs,
  1507. };
  1508. /*
  1509. * If the i2c layer weren't so broken, we could pass this kind of data
  1510. * around
  1511. */
  1512. static int es7210_i2c_probe(struct i2c_client *i2c)
  1513. {
  1514. struct es7210_priv *es7210;
  1515. int ret;
  1516. //printk("begin->>>>>>>>>>%s!\n", __func__);
  1517. es7210 = devm_kzalloc(&i2c->dev, sizeof(struct es7210_priv), GFP_KERNEL);
  1518. if (es7210 == NULL)
  1519. return -ENOMEM;
  1520. es7210->i2c = i2c;
  1521. es7210->tdm_mode = ES7210_WORK_MODE; //to set tdm mode or normal mode
  1522. dev_set_drvdata(&i2c->dev, es7210);
  1523. #if 0
  1524. if (i2c_id->driver_data < ADC_DEV_MAXNUM) {
  1525. i2c_clt1[i2c_id->driver_data] = i2c;
  1526. // ret = snd_soc_register_codec(&i2c->dev,&soc_component_dev_es7210,
  1527. // es7210_dai[i2c_id->driver_data], 1);
  1528. ret = devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_es7210,
  1529. es7210_dai[i2c_id->driver_data], 1);
  1530. if (ret < 0) {
  1531. kfree(es7210);
  1532. return ret;
  1533. }
  1534. }
  1535. #else
  1536. i2c_clt1[0] = i2c;
  1537. ret = devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_es7210,
  1538. es7210_dai[0], 1);
  1539. if (ret < 0) {
  1540. kfree(es7210);
  1541. dev_err(&i2c->dev, "failed to register codec: %d\n", ret);
  1542. return ret;
  1543. }
  1544. #endif
  1545. ret = sysfs_create_group(&i2c->dev.kobj, &es7210_debug_attr_group);
  1546. if (ret) {
  1547. pr_err("failed to create attr group\n");
  1548. }
  1549. //printk("%s sucess!\n", __func__);
  1550. return ret;
  1551. }
  1552. static int __exit es7210_i2c_remove(struct i2c_client *i2c)
  1553. {
  1554. //snd_soc_unregister_codec(&i2c->dev);
  1555. //kfree(i2c_get_clientdata(i2c));
  1556. return 0;
  1557. }
  1558. #if !ES7210_MATCH_DTS_EN
  1559. static int es7210_i2c_detect(struct i2c_client *client, struct i2c_board_info *info)
  1560. {
  1561. struct i2c_adapter *adapter = client->adapter;
  1562. if (adapter->nr == ES7210_I2C_BUS_NUM) {
  1563. if (client->addr == 0x40) {
  1564. strlcpy(info->type, "MicArray_0", I2C_NAME_SIZE);
  1565. return 0;
  1566. } else if (client->addr == 0x43) {
  1567. strlcpy(info->type, "MicArray_1", I2C_NAME_SIZE);
  1568. return 0;
  1569. } else if (client->addr == 0x42) {
  1570. strlcpy(info->type, "MicArray_2", I2C_NAME_SIZE);
  1571. return 0;
  1572. } else if (client->addr == 0x41) {
  1573. strlcpy(info->type, "MicArray_3", I2C_NAME_SIZE);
  1574. return 0;
  1575. }
  1576. }
  1577. return -ENODEV;
  1578. }
  1579. #endif
  1580. static const unsigned short es7210_i2c_addr[] = {
  1581. #if ES7210_CHANNELS_MAX > 0
  1582. 0x40,
  1583. #endif
  1584. #if ES7210_CHANNELS_MAX > 4
  1585. 0x43,
  1586. #endif
  1587. #if ES7210_CHANNELS_MAX > 8
  1588. 0x42,
  1589. #endif
  1590. #if ES7210_CHANNELS_MAX > 12
  1591. 0x41,
  1592. #endif
  1593. I2C_CLIENT_END,
  1594. };
  1595. #ifndef ARK1668ED_DEMO_BOARD
  1596. /*
  1597. * device tree source or i2c_board_info both use to transfer hardware information to linux kernel,
  1598. * use one of them wil be OK
  1599. */
  1600. static struct i2c_board_info es7210_i2c_board_info[] = {
  1601. #if ES7210_CHANNELS_MAX > 0
  1602. {I2C_BOARD_INFO("MicArray_0", 0x40),},//es7210_0
  1603. #endif
  1604. #if ES7210_CHANNELS_MAX > 4
  1605. {I2C_BOARD_INFO("MicArray_1", 0x43),},//es7210_1
  1606. #endif
  1607. #if ES7210_CHANNELS_MAX > 8
  1608. {I2C_BOARD_INFO("MicArray_2", 0x42),},//es7210_2
  1609. #endif
  1610. #if ES7210_CHANNELS_MAX > 12
  1611. {I2C_BOARD_INFO("MicArray_3", 0x41),},//es7210_3
  1612. #endif
  1613. };
  1614. #endif
  1615. static const struct i2c_device_id es7210_i2c_id[] = {
  1616. #if ES7210_CHANNELS_MAX > 0
  1617. //{ "MicArray_0", 0 },//es7210_0
  1618. { "es7210", 0 },//es7210
  1619. #endif
  1620. #if ES7210_CHANNELS_MAX > 4
  1621. { "MicArray_1", 1 },//es7210_1
  1622. #endif
  1623. #if ES7210_CHANNELS_MAX > 8
  1624. { "MicArray_2", 2 },//es7210_2
  1625. #endif
  1626. #if ES7210_CHANNELS_MAX > 12
  1627. { "MicArray_3", 3 },//es7210_3
  1628. #endif
  1629. { }
  1630. };
  1631. MODULE_DEVICE_TABLE(i2c, es7210_i2c_id);
  1632. static const struct of_device_id es7210_dt_ids[] = {
  1633. #if ES7210_CHANNELS_MAX > 0
  1634. { .compatible = "arkmicro,es7210"},//es7210
  1635. #endif
  1636. #if ES7210_CHANNELS_MAX > 4
  1637. { .compatible = "MicArray_1", },//es7210_1
  1638. #endif
  1639. #if ES7210_CHANNELS_MAX > 8
  1640. { .compatible = "MicArray_2", },//es7210_2
  1641. #endif
  1642. #if ES7210_CHANNELS_MAX > 12
  1643. { .compatible = "MicArray_3", },//es7210_3
  1644. #endif
  1645. };
  1646. MODULE_DEVICE_TABLE(of, es7210_dt_ids);
  1647. static struct i2c_driver es7210_i2c_driver = {
  1648. .driver = {
  1649. .name = "es7210",
  1650. .owner = THIS_MODULE,
  1651. #if ES7210_MATCH_DTS_EN
  1652. .of_match_table = es7210_dt_ids,
  1653. #endif
  1654. },
  1655. .probe = es7210_i2c_probe,
  1656. .remove = __exit_p(es7210_i2c_remove),
  1657. .class = I2C_CLASS_HWMON,
  1658. .id_table = es7210_i2c_id,
  1659. #if !ES7210_MATCH_DTS_EN
  1660. .address_list = es7210_i2c_addr,
  1661. .detect = es7210_i2c_detect,
  1662. #endif
  1663. };
  1664. static int __init es7210_modinit(void)
  1665. {
  1666. int ret;
  1667. struct i2c_adapter *adapter;
  1668. //struct i2c_client *client;
  1669. printk("%s enter es7210\n", __func__);
  1670. adapter = i2c_get_adapter(ES7210_I2C_BUS_NUM);
  1671. if (!adapter) {
  1672. printk("i2c_get_adapter() fail!\n");
  1673. return -ENODEV;
  1674. }
  1675. printk("%s() begin0000", __func__);
  1676. // for(i = 0; i < ADC_DEV_MAXNUM; i++) {
  1677. // client = i2c_new_device(adapter, &es7210_i2c_board_info[i]);
  1678. // printk("%s() i2c_new_device\n",__func__);
  1679. // if (!client)
  1680. // return -ENODEV;
  1681. // }
  1682. i2c_put_adapter(adapter);
  1683. ret = i2c_add_driver(&es7210_i2c_driver);
  1684. if (ret != 0)
  1685. pr_err("Failed to register es7210 i2c driver : %d\n", ret);
  1686. return ret;
  1687. }
  1688. module_init(es7210_modinit);
  1689. static void __exit es7210_exit(void)
  1690. {
  1691. i2c_del_driver(&es7210_i2c_driver);
  1692. }
  1693. module_exit(es7210_exit);
  1694. MODULE_DESCRIPTION("ASoC ES7210 audio adc driver");
  1695. MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com> / info@everest-semi.com");
  1696. MODULE_LICENSE("GPL v2");