es7210.c 61 KB

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