rt1011.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * rt1011.c -- rt1011 ALSA SoC amplifier component driver
  4. *
  5. * Copyright(c) 2019 Realtek Semiconductor Corp.
  6. *
  7. * Author: Shuming Fan <[email protected]>
  8. *
  9. */
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/init.h>
  13. #include <linux/delay.h>
  14. #include <linux/pm.h>
  15. #include <linux/gpio.h>
  16. #include <linux/i2c.h>
  17. #include <linux/acpi.h>
  18. #include <linux/regmap.h>
  19. #include <linux/of_gpio.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/firmware.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/soc.h>
  26. #include <sound/soc-dapm.h>
  27. #include <sound/initval.h>
  28. #include <sound/tlv.h>
  29. #include "rl6231.h"
  30. #include "rt1011.h"
  31. static int rt1011_calibrate(struct rt1011_priv *rt1011,
  32. unsigned char cali_flag);
  33. static const struct reg_sequence init_list[] = {
  34. { RT1011_POWER_9, 0xa840 },
  35. { RT1011_ADC_SET_5, 0x0a20 },
  36. { RT1011_DAC_SET_2, 0xa032 },
  37. { RT1011_SPK_PRO_DC_DET_1, 0xb00c },
  38. { RT1011_SPK_PRO_DC_DET_2, 0xcccc },
  39. { RT1011_A_TIMING_1, 0x6054 },
  40. { RT1011_POWER_7, 0x3e55 },
  41. { RT1011_POWER_8, 0x0520 },
  42. { RT1011_BOOST_CON_1, 0xe188 },
  43. { RT1011_POWER_4, 0x16f2 },
  44. { RT1011_CROSS_BQ_SET_1, 0x0004 },
  45. { RT1011_SIL_DET, 0xc313 },
  46. { RT1011_SINE_GEN_REG_1, 0x0707 },
  47. { RT1011_DC_CALIB_CLASSD_3, 0xcb00 },
  48. { RT1011_DAC_SET_1, 0xe702 },
  49. { RT1011_DAC_SET_3, 0x2004 },
  50. };
  51. static const struct reg_default rt1011_reg[] = {
  52. {0x0000, 0x0000},
  53. {0x0002, 0x0000},
  54. {0x0004, 0xa000},
  55. {0x0006, 0x0000},
  56. {0x0008, 0x0003},
  57. {0x000a, 0x087e},
  58. {0x000c, 0x0020},
  59. {0x000e, 0x9002},
  60. {0x0010, 0x0000},
  61. {0x0012, 0x0000},
  62. {0x0020, 0x0c40},
  63. {0x0022, 0x4313},
  64. {0x0076, 0x0000},
  65. {0x0078, 0x0000},
  66. {0x007a, 0x0000},
  67. {0x007c, 0x10ec},
  68. {0x007d, 0x1011},
  69. {0x00f0, 0x5000},
  70. {0x00f2, 0x0374},
  71. {0x00f3, 0x0000},
  72. {0x00f4, 0x0000},
  73. {0x0100, 0x0038},
  74. {0x0102, 0xff02},
  75. {0x0104, 0x0232},
  76. {0x0106, 0x200c},
  77. {0x0107, 0x0000},
  78. {0x0108, 0x2f2f},
  79. {0x010a, 0x2f2f},
  80. {0x010c, 0x002f},
  81. {0x010e, 0xe000},
  82. {0x0110, 0x0820},
  83. {0x0111, 0x4010},
  84. {0x0112, 0x0000},
  85. {0x0114, 0x0000},
  86. {0x0116, 0x0000},
  87. {0x0118, 0x0000},
  88. {0x011a, 0x0101},
  89. {0x011c, 0x4567},
  90. {0x011e, 0x0000},
  91. {0x0120, 0x0000},
  92. {0x0122, 0x0000},
  93. {0x0124, 0x0123},
  94. {0x0126, 0x4567},
  95. {0x0200, 0x0000},
  96. {0x0300, 0xffdd},
  97. {0x0302, 0x001e},
  98. {0x0311, 0x0000},
  99. {0x0313, 0x5254},
  100. {0x0314, 0x0062},
  101. {0x0316, 0x7f40},
  102. {0x0319, 0x000f},
  103. {0x031a, 0xffff},
  104. {0x031b, 0x0000},
  105. {0x031c, 0x009f},
  106. {0x031d, 0xffff},
  107. {0x031e, 0x0000},
  108. {0x031f, 0x0000},
  109. {0x0320, 0xe31c},
  110. {0x0321, 0x0000},
  111. {0x0322, 0x0000},
  112. {0x0324, 0x0000},
  113. {0x0326, 0x0002},
  114. {0x0328, 0x20b2},
  115. {0x0329, 0x0175},
  116. {0x032a, 0x32ad},
  117. {0x032b, 0x3455},
  118. {0x032c, 0x0528},
  119. {0x032d, 0xa800},
  120. {0x032e, 0x030e},
  121. {0x0330, 0x2080},
  122. {0x0332, 0x0034},
  123. {0x0334, 0x0000},
  124. {0x0508, 0x0010},
  125. {0x050a, 0x0018},
  126. {0x050c, 0x0000},
  127. {0x050d, 0xffff},
  128. {0x050e, 0x1f1f},
  129. {0x050f, 0x04ff},
  130. {0x0510, 0x4020},
  131. {0x0511, 0x01f0},
  132. {0x0512, 0x0702},
  133. {0x0516, 0xbb80},
  134. {0x0517, 0xffff},
  135. {0x0518, 0xffff},
  136. {0x0519, 0x307f},
  137. {0x051a, 0xffff},
  138. {0x051b, 0x0000},
  139. {0x051c, 0x0000},
  140. {0x051d, 0x2000},
  141. {0x051e, 0x0000},
  142. {0x051f, 0x0000},
  143. {0x0520, 0x0000},
  144. {0x0521, 0x1001},
  145. {0x0522, 0x7fff},
  146. {0x0524, 0x7fff},
  147. {0x0526, 0x0000},
  148. {0x0528, 0x0000},
  149. {0x052a, 0x0000},
  150. {0x0530, 0x0401},
  151. {0x0532, 0x3000},
  152. {0x0534, 0x0000},
  153. {0x0535, 0xffff},
  154. {0x0536, 0x101c},
  155. {0x0538, 0x1814},
  156. {0x053a, 0x100c},
  157. {0x053c, 0x0804},
  158. {0x053d, 0x0000},
  159. {0x053e, 0x0000},
  160. {0x053f, 0x0000},
  161. {0x0540, 0x0000},
  162. {0x0541, 0x0000},
  163. {0x0542, 0x0000},
  164. {0x0543, 0x0000},
  165. {0x0544, 0x001c},
  166. {0x0545, 0x1814},
  167. {0x0546, 0x100c},
  168. {0x0547, 0x0804},
  169. {0x0548, 0x0000},
  170. {0x0549, 0x0000},
  171. {0x054a, 0x0000},
  172. {0x054b, 0x0000},
  173. {0x054c, 0x0000},
  174. {0x054d, 0x0000},
  175. {0x054e, 0x0000},
  176. {0x054f, 0x0000},
  177. {0x0566, 0x0000},
  178. {0x0568, 0x20f1},
  179. {0x056a, 0x0007},
  180. {0x0600, 0x9d00},
  181. {0x0611, 0x2000},
  182. {0x0612, 0x505f},
  183. {0x0613, 0x0444},
  184. {0x0614, 0x4000},
  185. {0x0615, 0x4004},
  186. {0x0616, 0x0606},
  187. {0x0617, 0x8904},
  188. {0x0618, 0xe021},
  189. {0x0621, 0x2000},
  190. {0x0622, 0x505f},
  191. {0x0623, 0x0444},
  192. {0x0624, 0x4000},
  193. {0x0625, 0x4004},
  194. {0x0626, 0x0606},
  195. {0x0627, 0x8704},
  196. {0x0628, 0xe021},
  197. {0x0631, 0x2000},
  198. {0x0632, 0x517f},
  199. {0x0633, 0x0440},
  200. {0x0634, 0x4000},
  201. {0x0635, 0x4104},
  202. {0x0636, 0x0306},
  203. {0x0637, 0x8904},
  204. {0x0638, 0xe021},
  205. {0x0702, 0x0014},
  206. {0x0704, 0x0000},
  207. {0x0706, 0x0014},
  208. {0x0708, 0x0000},
  209. {0x070a, 0x0000},
  210. {0x0710, 0x0200},
  211. {0x0711, 0x0000},
  212. {0x0712, 0x0200},
  213. {0x0713, 0x0000},
  214. {0x0720, 0x0200},
  215. {0x0721, 0x0000},
  216. {0x0722, 0x0000},
  217. {0x0723, 0x0000},
  218. {0x0724, 0x0000},
  219. {0x0725, 0x0000},
  220. {0x0726, 0x0000},
  221. {0x0727, 0x0000},
  222. {0x0728, 0x0000},
  223. {0x0729, 0x0000},
  224. {0x0730, 0x0200},
  225. {0x0731, 0x0000},
  226. {0x0732, 0x0000},
  227. {0x0733, 0x0000},
  228. {0x0734, 0x0000},
  229. {0x0735, 0x0000},
  230. {0x0736, 0x0000},
  231. {0x0737, 0x0000},
  232. {0x0738, 0x0000},
  233. {0x0739, 0x0000},
  234. {0x0740, 0x0200},
  235. {0x0741, 0x0000},
  236. {0x0742, 0x0000},
  237. {0x0743, 0x0000},
  238. {0x0744, 0x0000},
  239. {0x0745, 0x0000},
  240. {0x0746, 0x0000},
  241. {0x0747, 0x0000},
  242. {0x0748, 0x0000},
  243. {0x0749, 0x0000},
  244. {0x0750, 0x0200},
  245. {0x0751, 0x0000},
  246. {0x0752, 0x0000},
  247. {0x0753, 0x0000},
  248. {0x0754, 0x0000},
  249. {0x0755, 0x0000},
  250. {0x0756, 0x0000},
  251. {0x0757, 0x0000},
  252. {0x0758, 0x0000},
  253. {0x0759, 0x0000},
  254. {0x0760, 0x0200},
  255. {0x0761, 0x0000},
  256. {0x0762, 0x0000},
  257. {0x0763, 0x0000},
  258. {0x0764, 0x0000},
  259. {0x0765, 0x0000},
  260. {0x0766, 0x0000},
  261. {0x0767, 0x0000},
  262. {0x0768, 0x0000},
  263. {0x0769, 0x0000},
  264. {0x0770, 0x0200},
  265. {0x0771, 0x0000},
  266. {0x0772, 0x0000},
  267. {0x0773, 0x0000},
  268. {0x0774, 0x0000},
  269. {0x0775, 0x0000},
  270. {0x0776, 0x0000},
  271. {0x0777, 0x0000},
  272. {0x0778, 0x0000},
  273. {0x0779, 0x0000},
  274. {0x0780, 0x0200},
  275. {0x0781, 0x0000},
  276. {0x0782, 0x0000},
  277. {0x0783, 0x0000},
  278. {0x0784, 0x0000},
  279. {0x0785, 0x0000},
  280. {0x0786, 0x0000},
  281. {0x0787, 0x0000},
  282. {0x0788, 0x0000},
  283. {0x0789, 0x0000},
  284. {0x0790, 0x0200},
  285. {0x0791, 0x0000},
  286. {0x0792, 0x0000},
  287. {0x0793, 0x0000},
  288. {0x0794, 0x0000},
  289. {0x0795, 0x0000},
  290. {0x0796, 0x0000},
  291. {0x0797, 0x0000},
  292. {0x0798, 0x0000},
  293. {0x0799, 0x0000},
  294. {0x07a0, 0x0200},
  295. {0x07a1, 0x0000},
  296. {0x07a2, 0x0000},
  297. {0x07a3, 0x0000},
  298. {0x07a4, 0x0000},
  299. {0x07a5, 0x0000},
  300. {0x07a6, 0x0000},
  301. {0x07a7, 0x0000},
  302. {0x07a8, 0x0000},
  303. {0x07a9, 0x0000},
  304. {0x07b0, 0x0200},
  305. {0x07b1, 0x0000},
  306. {0x07b2, 0x0000},
  307. {0x07b3, 0x0000},
  308. {0x07b4, 0x0000},
  309. {0x07b5, 0x0000},
  310. {0x07b6, 0x0000},
  311. {0x07b7, 0x0000},
  312. {0x07b8, 0x0000},
  313. {0x07b9, 0x0000},
  314. {0x07c0, 0x0200},
  315. {0x07c1, 0x0000},
  316. {0x07c2, 0x0000},
  317. {0x07c3, 0x0000},
  318. {0x07c4, 0x0000},
  319. {0x07c5, 0x0000},
  320. {0x07c6, 0x0000},
  321. {0x07c7, 0x0000},
  322. {0x07c8, 0x0000},
  323. {0x07c9, 0x0000},
  324. {0x1000, 0x4040},
  325. {0x1002, 0x6505},
  326. {0x1004, 0x5405},
  327. {0x1006, 0x5555},
  328. {0x1007, 0x003f},
  329. {0x1008, 0x7fd7},
  330. {0x1009, 0x770f},
  331. {0x100a, 0xfffe},
  332. {0x100b, 0xe000},
  333. {0x100c, 0x0000},
  334. {0x100d, 0x0007},
  335. {0x1010, 0xa433},
  336. {0x1020, 0x0000},
  337. {0x1022, 0x0000},
  338. {0x1024, 0x0000},
  339. {0x1200, 0x5a01},
  340. {0x1202, 0x6324},
  341. {0x1204, 0x0b00},
  342. {0x1206, 0x0000},
  343. {0x1208, 0x0000},
  344. {0x120a, 0x0024},
  345. {0x120c, 0x0000},
  346. {0x120e, 0x000e},
  347. {0x1210, 0x0000},
  348. {0x1212, 0x0000},
  349. {0x1300, 0x0701},
  350. {0x1302, 0x12f9},
  351. {0x1304, 0x3405},
  352. {0x1305, 0x0844},
  353. {0x1306, 0x5611},
  354. {0x1308, 0x555e},
  355. {0x130a, 0xa605},
  356. {0x130c, 0x2000},
  357. {0x130e, 0x0000},
  358. {0x130f, 0x0001},
  359. {0x1310, 0xaa48},
  360. {0x1312, 0x0285},
  361. {0x1314, 0xaaaa},
  362. {0x1316, 0xaaa0},
  363. {0x1318, 0x2aaa},
  364. {0x131a, 0xaa07},
  365. {0x1322, 0x0029},
  366. {0x1323, 0x4a52},
  367. {0x1324, 0x002c},
  368. {0x1325, 0x0b02},
  369. {0x1326, 0x002d},
  370. {0x1327, 0x6b5a},
  371. {0x1328, 0x002e},
  372. {0x1329, 0xcbb2},
  373. {0x132a, 0x0030},
  374. {0x132b, 0x2c0b},
  375. {0x1330, 0x0031},
  376. {0x1331, 0x8c63},
  377. {0x1332, 0x0032},
  378. {0x1333, 0xecbb},
  379. {0x1334, 0x0034},
  380. {0x1335, 0x4d13},
  381. {0x1336, 0x0037},
  382. {0x1337, 0x0dc3},
  383. {0x1338, 0x003d},
  384. {0x1339, 0xef7b},
  385. {0x133a, 0x0044},
  386. {0x133b, 0xd134},
  387. {0x133c, 0x0047},
  388. {0x133d, 0x91e4},
  389. {0x133e, 0x004d},
  390. {0x133f, 0xc370},
  391. {0x1340, 0x0053},
  392. {0x1341, 0xf4fd},
  393. {0x1342, 0x0060},
  394. {0x1343, 0x5816},
  395. {0x1344, 0x006c},
  396. {0x1345, 0xbb2e},
  397. {0x1346, 0x0072},
  398. {0x1347, 0xecbb},
  399. {0x1348, 0x0076},
  400. {0x1349, 0x5d97},
  401. {0x1500, 0x0702},
  402. {0x1502, 0x002f},
  403. {0x1504, 0x0000},
  404. {0x1510, 0x0064},
  405. {0x1512, 0x0000},
  406. {0x1514, 0xdf47},
  407. {0x1516, 0x079c},
  408. {0x1518, 0xfbf5},
  409. {0x151a, 0x00bc},
  410. {0x151c, 0x3b85},
  411. {0x151e, 0x02b3},
  412. {0x1520, 0x3333},
  413. {0x1522, 0x0000},
  414. {0x1524, 0x4000},
  415. {0x1528, 0x0064},
  416. {0x152a, 0x0000},
  417. {0x152c, 0x0000},
  418. {0x152e, 0x0000},
  419. {0x1530, 0x0000},
  420. {0x1532, 0x0000},
  421. {0x1534, 0x0000},
  422. {0x1536, 0x0000},
  423. {0x1538, 0x0040},
  424. {0x1539, 0x0000},
  425. {0x153a, 0x0040},
  426. {0x153b, 0x0000},
  427. {0x153c, 0x0064},
  428. {0x153e, 0x0bf9},
  429. {0x1540, 0xb2a9},
  430. {0x1544, 0x0200},
  431. {0x1546, 0x0000},
  432. {0x1548, 0x00ca},
  433. {0x1552, 0x03ff},
  434. {0x1554, 0x017f},
  435. {0x1556, 0x017f},
  436. {0x155a, 0x0000},
  437. {0x155c, 0x0000},
  438. {0x1560, 0x0040},
  439. {0x1562, 0x0000},
  440. {0x1570, 0x03ff},
  441. {0x1571, 0xdcff},
  442. {0x1572, 0x1e00},
  443. {0x1573, 0x224f},
  444. {0x1574, 0x0000},
  445. {0x1575, 0x0000},
  446. {0x1576, 0x1e00},
  447. {0x1577, 0x0000},
  448. {0x1578, 0x0000},
  449. {0x1579, 0x1128},
  450. {0x157a, 0x03ff},
  451. {0x157b, 0xdcff},
  452. {0x157c, 0x1e00},
  453. {0x157d, 0x224f},
  454. {0x157e, 0x0000},
  455. {0x157f, 0x0000},
  456. {0x1580, 0x1e00},
  457. {0x1581, 0x0000},
  458. {0x1582, 0x0000},
  459. {0x1583, 0x1128},
  460. {0x1590, 0x03ff},
  461. {0x1591, 0xdcff},
  462. {0x1592, 0x1e00},
  463. {0x1593, 0x224f},
  464. {0x1594, 0x0000},
  465. {0x1595, 0x0000},
  466. {0x1596, 0x1e00},
  467. {0x1597, 0x0000},
  468. {0x1598, 0x0000},
  469. {0x1599, 0x1128},
  470. {0x159a, 0x03ff},
  471. {0x159b, 0xdcff},
  472. {0x159c, 0x1e00},
  473. {0x159d, 0x224f},
  474. {0x159e, 0x0000},
  475. {0x159f, 0x0000},
  476. {0x15a0, 0x1e00},
  477. {0x15a1, 0x0000},
  478. {0x15a2, 0x0000},
  479. {0x15a3, 0x1128},
  480. {0x15b0, 0x007f},
  481. {0x15b1, 0xffff},
  482. {0x15b2, 0x007f},
  483. {0x15b3, 0xffff},
  484. {0x15b4, 0x007f},
  485. {0x15b5, 0xffff},
  486. {0x15b8, 0x007f},
  487. {0x15b9, 0xffff},
  488. {0x15bc, 0x0000},
  489. {0x15bd, 0x0000},
  490. {0x15be, 0xff00},
  491. {0x15bf, 0x0000},
  492. {0x15c0, 0xff00},
  493. {0x15c1, 0x0000},
  494. {0x15c3, 0xfc00},
  495. {0x15c4, 0xbb80},
  496. {0x15d0, 0x0000},
  497. {0x15d1, 0x0000},
  498. {0x15d2, 0x0000},
  499. {0x15d3, 0x0000},
  500. {0x15d4, 0x0000},
  501. {0x15d5, 0x0000},
  502. {0x15d6, 0x0000},
  503. {0x15d7, 0x0000},
  504. {0x15d8, 0x0200},
  505. {0x15d9, 0x0000},
  506. {0x15da, 0x0000},
  507. {0x15db, 0x0000},
  508. {0x15dc, 0x0000},
  509. {0x15dd, 0x0000},
  510. {0x15de, 0x0000},
  511. {0x15df, 0x0000},
  512. {0x15e0, 0x0000},
  513. {0x15e1, 0x0000},
  514. {0x15e2, 0x0200},
  515. {0x15e3, 0x0000},
  516. {0x15e4, 0x0000},
  517. {0x15e5, 0x0000},
  518. {0x15e6, 0x0000},
  519. {0x15e7, 0x0000},
  520. {0x15e8, 0x0000},
  521. {0x15e9, 0x0000},
  522. {0x15ea, 0x0000},
  523. {0x15eb, 0x0000},
  524. {0x15ec, 0x0200},
  525. {0x15ed, 0x0000},
  526. {0x15ee, 0x0000},
  527. {0x15ef, 0x0000},
  528. {0x15f0, 0x0000},
  529. {0x15f1, 0x0000},
  530. {0x15f2, 0x0000},
  531. {0x15f3, 0x0000},
  532. {0x15f4, 0x0000},
  533. {0x15f5, 0x0000},
  534. {0x15f6, 0x0200},
  535. {0x15f7, 0x0200},
  536. {0x15f8, 0x8200},
  537. {0x15f9, 0x0000},
  538. {0x1600, 0x007d},
  539. {0x1601, 0xa178},
  540. {0x1602, 0x00c2},
  541. {0x1603, 0x5383},
  542. {0x1604, 0x0000},
  543. {0x1605, 0x02c1},
  544. {0x1606, 0x007d},
  545. {0x1607, 0xa178},
  546. {0x1608, 0x00c2},
  547. {0x1609, 0x5383},
  548. {0x160a, 0x003e},
  549. {0x160b, 0xd37d},
  550. {0x1611, 0x3210},
  551. {0x1612, 0x7418},
  552. {0x1613, 0xc0ff},
  553. {0x1614, 0x0000},
  554. {0x1615, 0x00ff},
  555. {0x1616, 0x0000},
  556. {0x1617, 0x0000},
  557. {0x1621, 0x6210},
  558. {0x1622, 0x7418},
  559. {0x1623, 0xc0ff},
  560. {0x1624, 0x0000},
  561. {0x1625, 0x00ff},
  562. {0x1626, 0x0000},
  563. {0x1627, 0x0000},
  564. {0x1631, 0x3a14},
  565. {0x1632, 0x7418},
  566. {0x1633, 0xc3ff},
  567. {0x1634, 0x0000},
  568. {0x1635, 0x00ff},
  569. {0x1636, 0x0000},
  570. {0x1637, 0x0000},
  571. {0x1638, 0x0000},
  572. {0x163a, 0x0000},
  573. {0x163c, 0x0000},
  574. {0x163e, 0x0000},
  575. {0x1640, 0x0000},
  576. {0x1642, 0x0000},
  577. {0x1644, 0x0000},
  578. {0x1646, 0x0000},
  579. {0x1648, 0x0000},
  580. {0x1650, 0x0000},
  581. {0x1652, 0x0000},
  582. {0x1654, 0x0000},
  583. {0x1656, 0x0000},
  584. {0x1658, 0x0000},
  585. {0x1660, 0x0000},
  586. {0x1662, 0x0000},
  587. {0x1664, 0x0000},
  588. {0x1666, 0x0000},
  589. {0x1668, 0x0000},
  590. {0x1670, 0x0000},
  591. {0x1672, 0x0000},
  592. {0x1674, 0x0000},
  593. {0x1676, 0x0000},
  594. {0x1678, 0x0000},
  595. {0x1680, 0x0000},
  596. {0x1682, 0x0000},
  597. {0x1684, 0x0000},
  598. {0x1686, 0x0000},
  599. {0x1688, 0x0000},
  600. {0x1690, 0x0000},
  601. {0x1692, 0x0000},
  602. {0x1694, 0x0000},
  603. {0x1696, 0x0000},
  604. {0x1698, 0x0000},
  605. {0x1700, 0x0000},
  606. {0x1702, 0x0000},
  607. {0x1704, 0x0000},
  608. {0x1706, 0x0000},
  609. {0x1708, 0x0000},
  610. {0x1710, 0x0000},
  611. {0x1712, 0x0000},
  612. {0x1714, 0x0000},
  613. {0x1716, 0x0000},
  614. {0x1718, 0x0000},
  615. {0x1720, 0x0000},
  616. {0x1722, 0x0000},
  617. {0x1724, 0x0000},
  618. {0x1726, 0x0000},
  619. {0x1728, 0x0000},
  620. {0x1730, 0x0000},
  621. {0x1732, 0x0000},
  622. {0x1734, 0x0000},
  623. {0x1736, 0x0000},
  624. {0x1738, 0x0000},
  625. {0x173a, 0x0000},
  626. {0x173c, 0x0000},
  627. {0x173e, 0x0000},
  628. {0x17bb, 0x0500},
  629. {0x17bd, 0x0004},
  630. {0x17bf, 0x0004},
  631. {0x17c1, 0x0004},
  632. {0x17c2, 0x7fff},
  633. {0x17c3, 0x0000},
  634. {0x17c5, 0x0000},
  635. {0x17c7, 0x0000},
  636. {0x17c9, 0x0000},
  637. {0x17cb, 0x2010},
  638. {0x17cd, 0x0000},
  639. {0x17cf, 0x0000},
  640. {0x17d1, 0x0000},
  641. {0x17d3, 0x0000},
  642. {0x17d5, 0x0000},
  643. {0x17d7, 0x0000},
  644. {0x17d9, 0x0000},
  645. {0x17db, 0x0000},
  646. {0x17dd, 0x0000},
  647. {0x17df, 0x0000},
  648. {0x17e1, 0x0000},
  649. {0x17e3, 0x0000},
  650. {0x17e5, 0x0000},
  651. {0x17e7, 0x0000},
  652. {0x17e9, 0x0000},
  653. {0x17eb, 0x0000},
  654. {0x17ed, 0x0000},
  655. {0x17ef, 0x0000},
  656. {0x17f1, 0x0000},
  657. {0x17f3, 0x0000},
  658. {0x17f5, 0x0000},
  659. {0x17f7, 0x0000},
  660. {0x17f9, 0x0000},
  661. {0x17fb, 0x0000},
  662. {0x17fd, 0x0000},
  663. {0x17ff, 0x0000},
  664. {0x1801, 0x0000},
  665. {0x1803, 0x0000},
  666. };
  667. static int rt1011_reg_init(struct snd_soc_component *component)
  668. {
  669. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  670. regmap_multi_reg_write(rt1011->regmap,
  671. init_list, ARRAY_SIZE(init_list));
  672. return 0;
  673. }
  674. static bool rt1011_volatile_register(struct device *dev, unsigned int reg)
  675. {
  676. switch (reg) {
  677. case RT1011_RESET:
  678. case RT1011_SRC_2:
  679. case RT1011_CLK_DET:
  680. case RT1011_SIL_DET:
  681. case RT1011_VERSION_ID:
  682. case RT1011_VENDOR_ID:
  683. case RT1011_DEVICE_ID:
  684. case RT1011_DUM_RO:
  685. case RT1011_DAC_SET_3:
  686. case RT1011_PWM_CAL:
  687. case RT1011_SPK_VOL_TEST_OUT:
  688. case RT1011_VBAT_VOL_DET_1:
  689. case RT1011_VBAT_TEST_OUT_1:
  690. case RT1011_VBAT_TEST_OUT_2:
  691. case RT1011_VBAT_PROTECTION:
  692. case RT1011_VBAT_DET:
  693. case RT1011_BOOST_CON_1:
  694. case RT1011_SHORT_CIRCUIT_DET_1:
  695. case RT1011_SPK_TEMP_PROTECT_3:
  696. case RT1011_SPK_TEMP_PROTECT_6:
  697. case RT1011_SPK_PRO_DC_DET_3:
  698. case RT1011_SPK_PRO_DC_DET_7:
  699. case RT1011_SPK_PRO_DC_DET_8:
  700. case RT1011_SPL_1:
  701. case RT1011_SPL_4:
  702. case RT1011_EXCUR_PROTECT_1:
  703. case RT1011_CROSS_BQ_SET_1:
  704. case RT1011_CROSS_BQ_SET_2:
  705. case RT1011_BQ_SET_0:
  706. case RT1011_BQ_SET_1:
  707. case RT1011_BQ_SET_2:
  708. case RT1011_TEST_PAD_STATUS:
  709. case RT1011_DC_CALIB_CLASSD_1:
  710. case RT1011_DC_CALIB_CLASSD_5:
  711. case RT1011_DC_CALIB_CLASSD_6:
  712. case RT1011_DC_CALIB_CLASSD_7:
  713. case RT1011_DC_CALIB_CLASSD_8:
  714. case RT1011_SINE_GEN_REG_2:
  715. case RT1011_STP_CALIB_RS_TEMP:
  716. case RT1011_SPK_RESISTANCE_1:
  717. case RT1011_SPK_RESISTANCE_2:
  718. case RT1011_SPK_THERMAL:
  719. case RT1011_ALC_BK_GAIN_O:
  720. case RT1011_ALC_BK_GAIN_O_PRE:
  721. case RT1011_SPK_DC_O_23_16:
  722. case RT1011_SPK_DC_O_15_0:
  723. case RT1011_INIT_RECIPROCAL_SYN_24_16:
  724. case RT1011_INIT_RECIPROCAL_SYN_15_0:
  725. case RT1011_SPK_EXCURSION_23_16:
  726. case RT1011_SPK_EXCURSION_15_0:
  727. case RT1011_SEP_MAIN_OUT_23_16:
  728. case RT1011_SEP_MAIN_OUT_15_0:
  729. case RT1011_ALC_DRC_HB_INTERNAL_5:
  730. case RT1011_ALC_DRC_HB_INTERNAL_6:
  731. case RT1011_ALC_DRC_HB_INTERNAL_7:
  732. case RT1011_ALC_DRC_BB_INTERNAL_5:
  733. case RT1011_ALC_DRC_BB_INTERNAL_6:
  734. case RT1011_ALC_DRC_BB_INTERNAL_7:
  735. case RT1011_ALC_DRC_POS_INTERNAL_5:
  736. case RT1011_ALC_DRC_POS_INTERNAL_6:
  737. case RT1011_ALC_DRC_POS_INTERNAL_7:
  738. case RT1011_ALC_DRC_POS_INTERNAL_8:
  739. case RT1011_ALC_DRC_POS_INTERNAL_9:
  740. case RT1011_ALC_DRC_POS_INTERNAL_10:
  741. case RT1011_ALC_DRC_POS_INTERNAL_11:
  742. case RT1011_IRQ_1:
  743. case RT1011_EFUSE_CONTROL_1:
  744. case RT1011_EFUSE_CONTROL_2:
  745. case RT1011_EFUSE_MATCH_DONE ... RT1011_EFUSE_READ_R0_3_15_0:
  746. return true;
  747. default:
  748. return false;
  749. }
  750. }
  751. static bool rt1011_readable_register(struct device *dev, unsigned int reg)
  752. {
  753. switch (reg) {
  754. case RT1011_RESET:
  755. case RT1011_CLK_1:
  756. case RT1011_CLK_2:
  757. case RT1011_CLK_3:
  758. case RT1011_CLK_4:
  759. case RT1011_PLL_1:
  760. case RT1011_PLL_2:
  761. case RT1011_SRC_1:
  762. case RT1011_SRC_2:
  763. case RT1011_SRC_3:
  764. case RT1011_CLK_DET:
  765. case RT1011_SIL_DET:
  766. case RT1011_PRIV_INDEX:
  767. case RT1011_PRIV_DATA:
  768. case RT1011_CUSTOMER_ID:
  769. case RT1011_FM_VER:
  770. case RT1011_VERSION_ID:
  771. case RT1011_VENDOR_ID:
  772. case RT1011_DEVICE_ID:
  773. case RT1011_DUM_RW_0:
  774. case RT1011_DUM_YUN:
  775. case RT1011_DUM_RW_1:
  776. case RT1011_DUM_RO:
  777. case RT1011_MAN_I2C_DEV:
  778. case RT1011_DAC_SET_1:
  779. case RT1011_DAC_SET_2:
  780. case RT1011_DAC_SET_3:
  781. case RT1011_ADC_SET:
  782. case RT1011_ADC_SET_1:
  783. case RT1011_ADC_SET_2:
  784. case RT1011_ADC_SET_3:
  785. case RT1011_ADC_SET_4:
  786. case RT1011_ADC_SET_5:
  787. case RT1011_TDM_TOTAL_SET:
  788. case RT1011_TDM1_SET_TCON:
  789. case RT1011_TDM1_SET_1:
  790. case RT1011_TDM1_SET_2:
  791. case RT1011_TDM1_SET_3:
  792. case RT1011_TDM1_SET_4:
  793. case RT1011_TDM1_SET_5:
  794. case RT1011_TDM2_SET_1:
  795. case RT1011_TDM2_SET_2:
  796. case RT1011_TDM2_SET_3:
  797. case RT1011_TDM2_SET_4:
  798. case RT1011_TDM2_SET_5:
  799. case RT1011_PWM_CAL:
  800. case RT1011_MIXER_1:
  801. case RT1011_MIXER_2:
  802. case RT1011_ADRC_LIMIT:
  803. case RT1011_A_PRO:
  804. case RT1011_A_TIMING_1:
  805. case RT1011_A_TIMING_2:
  806. case RT1011_A_TEMP_SEN:
  807. case RT1011_SPK_VOL_DET_1:
  808. case RT1011_SPK_VOL_DET_2:
  809. case RT1011_SPK_VOL_TEST_OUT:
  810. case RT1011_VBAT_VOL_DET_1:
  811. case RT1011_VBAT_VOL_DET_2:
  812. case RT1011_VBAT_TEST_OUT_1:
  813. case RT1011_VBAT_TEST_OUT_2:
  814. case RT1011_VBAT_PROTECTION:
  815. case RT1011_VBAT_DET:
  816. case RT1011_POWER_1:
  817. case RT1011_POWER_2:
  818. case RT1011_POWER_3:
  819. case RT1011_POWER_4:
  820. case RT1011_POWER_5:
  821. case RT1011_POWER_6:
  822. case RT1011_POWER_7:
  823. case RT1011_POWER_8:
  824. case RT1011_POWER_9:
  825. case RT1011_CLASS_D_POS:
  826. case RT1011_BOOST_CON_1:
  827. case RT1011_BOOST_CON_2:
  828. case RT1011_ANALOG_CTRL:
  829. case RT1011_POWER_SEQ:
  830. case RT1011_SHORT_CIRCUIT_DET_1:
  831. case RT1011_SHORT_CIRCUIT_DET_2:
  832. case RT1011_SPK_TEMP_PROTECT_0:
  833. case RT1011_SPK_TEMP_PROTECT_1:
  834. case RT1011_SPK_TEMP_PROTECT_2:
  835. case RT1011_SPK_TEMP_PROTECT_3:
  836. case RT1011_SPK_TEMP_PROTECT_4:
  837. case RT1011_SPK_TEMP_PROTECT_5:
  838. case RT1011_SPK_TEMP_PROTECT_6:
  839. case RT1011_SPK_TEMP_PROTECT_7:
  840. case RT1011_SPK_TEMP_PROTECT_8:
  841. case RT1011_SPK_TEMP_PROTECT_9:
  842. case RT1011_SPK_PRO_DC_DET_1:
  843. case RT1011_SPK_PRO_DC_DET_2:
  844. case RT1011_SPK_PRO_DC_DET_3:
  845. case RT1011_SPK_PRO_DC_DET_4:
  846. case RT1011_SPK_PRO_DC_DET_5:
  847. case RT1011_SPK_PRO_DC_DET_6:
  848. case RT1011_SPK_PRO_DC_DET_7:
  849. case RT1011_SPK_PRO_DC_DET_8:
  850. case RT1011_SPL_1:
  851. case RT1011_SPL_2:
  852. case RT1011_SPL_3:
  853. case RT1011_SPL_4:
  854. case RT1011_THER_FOLD_BACK_1:
  855. case RT1011_THER_FOLD_BACK_2:
  856. case RT1011_EXCUR_PROTECT_1:
  857. case RT1011_EXCUR_PROTECT_2:
  858. case RT1011_EXCUR_PROTECT_3:
  859. case RT1011_EXCUR_PROTECT_4:
  860. case RT1011_BAT_GAIN_1:
  861. case RT1011_BAT_GAIN_2:
  862. case RT1011_BAT_GAIN_3:
  863. case RT1011_BAT_GAIN_4:
  864. case RT1011_BAT_GAIN_5:
  865. case RT1011_BAT_GAIN_6:
  866. case RT1011_BAT_GAIN_7:
  867. case RT1011_BAT_GAIN_8:
  868. case RT1011_BAT_GAIN_9:
  869. case RT1011_BAT_GAIN_10:
  870. case RT1011_BAT_GAIN_11:
  871. case RT1011_BAT_RT_THMAX_1:
  872. case RT1011_BAT_RT_THMAX_2:
  873. case RT1011_BAT_RT_THMAX_3:
  874. case RT1011_BAT_RT_THMAX_4:
  875. case RT1011_BAT_RT_THMAX_5:
  876. case RT1011_BAT_RT_THMAX_6:
  877. case RT1011_BAT_RT_THMAX_7:
  878. case RT1011_BAT_RT_THMAX_8:
  879. case RT1011_BAT_RT_THMAX_9:
  880. case RT1011_BAT_RT_THMAX_10:
  881. case RT1011_BAT_RT_THMAX_11:
  882. case RT1011_BAT_RT_THMAX_12:
  883. case RT1011_SPREAD_SPECTURM:
  884. case RT1011_PRO_GAIN_MODE:
  885. case RT1011_RT_DRC_CROSS:
  886. case RT1011_RT_DRC_HB_1:
  887. case RT1011_RT_DRC_HB_2:
  888. case RT1011_RT_DRC_HB_3:
  889. case RT1011_RT_DRC_HB_4:
  890. case RT1011_RT_DRC_HB_5:
  891. case RT1011_RT_DRC_HB_6:
  892. case RT1011_RT_DRC_HB_7:
  893. case RT1011_RT_DRC_HB_8:
  894. case RT1011_RT_DRC_BB_1:
  895. case RT1011_RT_DRC_BB_2:
  896. case RT1011_RT_DRC_BB_3:
  897. case RT1011_RT_DRC_BB_4:
  898. case RT1011_RT_DRC_BB_5:
  899. case RT1011_RT_DRC_BB_6:
  900. case RT1011_RT_DRC_BB_7:
  901. case RT1011_RT_DRC_BB_8:
  902. case RT1011_RT_DRC_POS_1:
  903. case RT1011_RT_DRC_POS_2:
  904. case RT1011_RT_DRC_POS_3:
  905. case RT1011_RT_DRC_POS_4:
  906. case RT1011_RT_DRC_POS_5:
  907. case RT1011_RT_DRC_POS_6:
  908. case RT1011_RT_DRC_POS_7:
  909. case RT1011_RT_DRC_POS_8:
  910. case RT1011_CROSS_BQ_SET_1:
  911. case RT1011_CROSS_BQ_SET_2:
  912. case RT1011_BQ_SET_0:
  913. case RT1011_BQ_SET_1:
  914. case RT1011_BQ_SET_2:
  915. case RT1011_BQ_PRE_GAIN_28_16:
  916. case RT1011_BQ_PRE_GAIN_15_0:
  917. case RT1011_BQ_POST_GAIN_28_16:
  918. case RT1011_BQ_POST_GAIN_15_0:
  919. case RT1011_BQ_H0_28_16 ... RT1011_BQ_A2_15_0:
  920. case RT1011_BQ_1_H0_28_16 ... RT1011_BQ_1_A2_15_0:
  921. case RT1011_BQ_2_H0_28_16 ... RT1011_BQ_2_A2_15_0:
  922. case RT1011_BQ_3_H0_28_16 ... RT1011_BQ_3_A2_15_0:
  923. case RT1011_BQ_4_H0_28_16 ... RT1011_BQ_4_A2_15_0:
  924. case RT1011_BQ_5_H0_28_16 ... RT1011_BQ_5_A2_15_0:
  925. case RT1011_BQ_6_H0_28_16 ... RT1011_BQ_6_A2_15_0:
  926. case RT1011_BQ_7_H0_28_16 ... RT1011_BQ_7_A2_15_0:
  927. case RT1011_BQ_8_H0_28_16 ... RT1011_BQ_8_A2_15_0:
  928. case RT1011_BQ_9_H0_28_16 ... RT1011_BQ_9_A2_15_0:
  929. case RT1011_BQ_10_H0_28_16 ... RT1011_BQ_10_A2_15_0:
  930. case RT1011_TEST_PAD_STATUS ... RT1011_PLL_INTERNAL_SET:
  931. case RT1011_TEST_OUT_1 ... RT1011_TEST_OUT_3:
  932. case RT1011_DC_CALIB_CLASSD_1 ... RT1011_DC_CALIB_CLASSD_10:
  933. case RT1011_CLASSD_INTERNAL_SET_1 ... RT1011_VREF_LV_1:
  934. case RT1011_SMART_BOOST_TIMING_1 ... RT1011_SMART_BOOST_TIMING_36:
  935. case RT1011_SINE_GEN_REG_1 ... RT1011_SINE_GEN_REG_3:
  936. case RT1011_STP_INITIAL_RS_TEMP ... RT1011_SPK_THERMAL:
  937. case RT1011_STP_OTP_TH ... RT1011_INIT_RECIPROCAL_SYN_15_0:
  938. case RT1011_STP_BQ_1_A1_L_28_16 ... RT1011_STP_BQ_1_H0_R_15_0:
  939. case RT1011_STP_BQ_2_A1_L_28_16 ... RT1011_SEP_RE_REG_15_0:
  940. case RT1011_DRC_CF_PARAMS_1 ... RT1011_DRC_CF_PARAMS_12:
  941. case RT1011_ALC_DRC_HB_INTERNAL_1 ... RT1011_ALC_DRC_HB_INTERNAL_7:
  942. case RT1011_ALC_DRC_BB_INTERNAL_1 ... RT1011_ALC_DRC_BB_INTERNAL_7:
  943. case RT1011_ALC_DRC_POS_INTERNAL_1 ... RT1011_ALC_DRC_POS_INTERNAL_8:
  944. case RT1011_ALC_DRC_POS_INTERNAL_9 ... RT1011_BQ_1_PARAMS_CHECK_5:
  945. case RT1011_BQ_2_PARAMS_CHECK_1 ... RT1011_BQ_2_PARAMS_CHECK_5:
  946. case RT1011_BQ_3_PARAMS_CHECK_1 ... RT1011_BQ_3_PARAMS_CHECK_5:
  947. case RT1011_BQ_4_PARAMS_CHECK_1 ... RT1011_BQ_4_PARAMS_CHECK_5:
  948. case RT1011_BQ_5_PARAMS_CHECK_1 ... RT1011_BQ_5_PARAMS_CHECK_5:
  949. case RT1011_BQ_6_PARAMS_CHECK_1 ... RT1011_BQ_6_PARAMS_CHECK_5:
  950. case RT1011_BQ_7_PARAMS_CHECK_1 ... RT1011_BQ_7_PARAMS_CHECK_5:
  951. case RT1011_BQ_8_PARAMS_CHECK_1 ... RT1011_BQ_8_PARAMS_CHECK_5:
  952. case RT1011_BQ_9_PARAMS_CHECK_1 ... RT1011_BQ_9_PARAMS_CHECK_5:
  953. case RT1011_BQ_10_PARAMS_CHECK_1 ... RT1011_BQ_10_PARAMS_CHECK_5:
  954. case RT1011_IRQ_1 ... RT1011_PART_NUMBER_EFUSE:
  955. case RT1011_EFUSE_CONTROL_1 ... RT1011_EFUSE_READ_R0_3_15_0:
  956. return true;
  957. default:
  958. return false;
  959. }
  960. }
  961. static const char * const rt1011_din_source_select[] = {
  962. "Left",
  963. "Right",
  964. "Left + Right average",
  965. };
  966. static SOC_ENUM_SINGLE_DECL(rt1011_din_source_enum, RT1011_CROSS_BQ_SET_1, 5,
  967. rt1011_din_source_select);
  968. static const char * const rt1011_tdm_data_out_select[] = {
  969. "TDM_O_LR", "BQ1", "DVOL", "BQ10", "ALC", "DMIX", "ADC_SRC_LR",
  970. "ADC_O_LR", "ADC_MONO", "RSPK_BPF_LR", "DMIX_ADD", "ENVELOPE_FS",
  971. "SEP_O_GAIN", "ALC_BK_GAIN", "STP_V_C", "DMIX_ABST"
  972. };
  973. static const char * const rt1011_tdm_l_ch_data_select[] = {
  974. "Slot0", "Slot1", "Slot2", "Slot3", "Slot4", "Slot5", "Slot6", "Slot7"
  975. };
  976. static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_l_dac1_enum, RT1011_TDM1_SET_4, 12,
  977. rt1011_tdm_l_ch_data_select);
  978. static SOC_ENUM_SINGLE_DECL(rt1011_tdm2_l_dac1_enum, RT1011_TDM2_SET_4, 12,
  979. rt1011_tdm_l_ch_data_select);
  980. static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_adc1_dat_enum,
  981. RT1011_ADCDAT_OUT_SOURCE, 0, rt1011_tdm_data_out_select);
  982. static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_adc1_loc_enum, RT1011_TDM1_SET_2, 0,
  983. rt1011_tdm_l_ch_data_select);
  984. static const char * const rt1011_adc_data_mode_select[] = {
  985. "Stereo", "Mono"
  986. };
  987. static SOC_ENUM_SINGLE_DECL(rt1011_adc_dout_mode_enum, RT1011_TDM1_SET_1, 12,
  988. rt1011_adc_data_mode_select);
  989. static const char * const rt1011_tdm_adc_data_len_control[] = {
  990. "1CH", "2CH", "3CH", "4CH", "5CH", "6CH", "7CH", "8CH"
  991. };
  992. static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_dout_len_enum, RT1011_TDM1_SET_2, 13,
  993. rt1011_tdm_adc_data_len_control);
  994. static SOC_ENUM_SINGLE_DECL(rt1011_tdm2_dout_len_enum, RT1011_TDM2_SET_2, 13,
  995. rt1011_tdm_adc_data_len_control);
  996. static const char * const rt1011_tdm_adc_swap_select[] = {
  997. "L/R", "R/L", "L/L", "R/R"
  998. };
  999. static SOC_ENUM_SINGLE_DECL(rt1011_tdm_adc1_1_enum, RT1011_TDM1_SET_3, 6,
  1000. rt1011_tdm_adc_swap_select);
  1001. static SOC_ENUM_SINGLE_DECL(rt1011_tdm_adc2_1_enum, RT1011_TDM1_SET_3, 4,
  1002. rt1011_tdm_adc_swap_select);
  1003. static void rt1011_reset(struct regmap *regmap)
  1004. {
  1005. regmap_write(regmap, RT1011_RESET, 0);
  1006. }
  1007. static int rt1011_recv_spk_mode_get(struct snd_kcontrol *kcontrol,
  1008. struct snd_ctl_elem_value *ucontrol)
  1009. {
  1010. struct snd_soc_component *component =
  1011. snd_soc_kcontrol_component(kcontrol);
  1012. struct rt1011_priv *rt1011 =
  1013. snd_soc_component_get_drvdata(component);
  1014. ucontrol->value.integer.value[0] = rt1011->recv_spk_mode;
  1015. return 0;
  1016. }
  1017. static int rt1011_recv_spk_mode_put(struct snd_kcontrol *kcontrol,
  1018. struct snd_ctl_elem_value *ucontrol)
  1019. {
  1020. struct snd_soc_component *component =
  1021. snd_soc_kcontrol_component(kcontrol);
  1022. struct rt1011_priv *rt1011 =
  1023. snd_soc_component_get_drvdata(component);
  1024. if (ucontrol->value.integer.value[0] == rt1011->recv_spk_mode)
  1025. return 0;
  1026. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
  1027. rt1011->recv_spk_mode = ucontrol->value.integer.value[0];
  1028. if (rt1011->recv_spk_mode) {
  1029. /* 1: recevier mode on */
  1030. snd_soc_component_update_bits(component,
  1031. RT1011_CLASSD_INTERNAL_SET_3,
  1032. RT1011_REG_GAIN_CLASSD_RI_SPK_MASK,
  1033. RT1011_REG_GAIN_CLASSD_RI_410K);
  1034. snd_soc_component_update_bits(component,
  1035. RT1011_CLASSD_INTERNAL_SET_1,
  1036. RT1011_RECV_MODE_SPK_MASK,
  1037. RT1011_RECV_MODE);
  1038. } else {
  1039. /* 0: speaker mode on */
  1040. snd_soc_component_update_bits(component,
  1041. RT1011_CLASSD_INTERNAL_SET_3,
  1042. RT1011_REG_GAIN_CLASSD_RI_SPK_MASK,
  1043. RT1011_REG_GAIN_CLASSD_RI_72P5K);
  1044. snd_soc_component_update_bits(component,
  1045. RT1011_CLASSD_INTERNAL_SET_1,
  1046. RT1011_RECV_MODE_SPK_MASK,
  1047. RT1011_SPK_MODE);
  1048. }
  1049. }
  1050. return 0;
  1051. }
  1052. static bool rt1011_validate_bq_drc_coeff(unsigned short reg)
  1053. {
  1054. if ((reg == RT1011_DAC_SET_1) ||
  1055. (reg >= RT1011_ADC_SET && reg <= RT1011_ADC_SET_1) ||
  1056. (reg == RT1011_ADC_SET_4) || (reg == RT1011_ADC_SET_5) ||
  1057. (reg == RT1011_MIXER_1) ||
  1058. (reg == RT1011_A_TIMING_1) ||
  1059. (reg >= RT1011_POWER_7 && reg <= RT1011_POWER_8) ||
  1060. (reg == RT1011_CLASS_D_POS) || (reg == RT1011_ANALOG_CTRL) ||
  1061. (reg >= RT1011_SPK_TEMP_PROTECT_0 && reg <= RT1011_SPK_TEMP_PROTECT_6) ||
  1062. (reg >= RT1011_SPK_PRO_DC_DET_5 && reg <= RT1011_BAT_GAIN_1) ||
  1063. (reg >= RT1011_RT_DRC_CROSS && reg <= RT1011_RT_DRC_POS_8) ||
  1064. (reg >= RT1011_CROSS_BQ_SET_1 && reg <= RT1011_BQ_10_A2_15_0) ||
  1065. (reg >= RT1011_SMART_BOOST_TIMING_1 && reg <= RT1011_SMART_BOOST_TIMING_36) ||
  1066. (reg == RT1011_SINE_GEN_REG_1) ||
  1067. (reg >= RT1011_STP_ALPHA_RECIPROCAL_MSB && reg <= RT1011_BQ_6_PARAMS_CHECK_5) ||
  1068. (reg >= RT1011_BQ_7_PARAMS_CHECK_1 && reg <= RT1011_BQ_10_PARAMS_CHECK_5))
  1069. return true;
  1070. return false;
  1071. }
  1072. static int rt1011_bq_drc_coeff_get(struct snd_kcontrol *kcontrol,
  1073. struct snd_ctl_elem_value *ucontrol)
  1074. {
  1075. struct snd_soc_component *component =
  1076. snd_soc_kcontrol_component(kcontrol);
  1077. struct rt1011_priv *rt1011 =
  1078. snd_soc_component_get_drvdata(component);
  1079. struct rt1011_bq_drc_params *bq_drc_info;
  1080. struct rt1011_bq_drc_params *params =
  1081. (struct rt1011_bq_drc_params *)ucontrol->value.integer.value;
  1082. unsigned int i, mode_idx = 0;
  1083. if (strstr(ucontrol->id.name, "AdvanceMode Initial Set"))
  1084. mode_idx = RT1011_ADVMODE_INITIAL_SET;
  1085. else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff"))
  1086. mode_idx = RT1011_ADVMODE_SEP_BQ_COEFF;
  1087. else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff"))
  1088. mode_idx = RT1011_ADVMODE_EQ_BQ_COEFF;
  1089. else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff"))
  1090. mode_idx = RT1011_ADVMODE_BQ_UI_COEFF;
  1091. else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff"))
  1092. mode_idx = RT1011_ADVMODE_SMARTBOOST_COEFF;
  1093. else
  1094. return -EINVAL;
  1095. pr_info("%s, id.name=%s, mode_idx=%d\n", __func__,
  1096. ucontrol->id.name, mode_idx);
  1097. bq_drc_info = rt1011->bq_drc_params[mode_idx];
  1098. for (i = 0; i < RT1011_BQ_DRC_NUM; i++) {
  1099. params[i].reg = bq_drc_info[i].reg;
  1100. params[i].val = bq_drc_info[i].val;
  1101. }
  1102. return 0;
  1103. }
  1104. static int rt1011_bq_drc_coeff_put(struct snd_kcontrol *kcontrol,
  1105. struct snd_ctl_elem_value *ucontrol)
  1106. {
  1107. struct snd_soc_component *component =
  1108. snd_soc_kcontrol_component(kcontrol);
  1109. struct rt1011_priv *rt1011 =
  1110. snd_soc_component_get_drvdata(component);
  1111. struct rt1011_bq_drc_params *bq_drc_info;
  1112. struct rt1011_bq_drc_params *params =
  1113. (struct rt1011_bq_drc_params *)ucontrol->value.integer.value;
  1114. unsigned int i, mode_idx = 0;
  1115. if (strstr(ucontrol->id.name, "AdvanceMode Initial Set"))
  1116. mode_idx = RT1011_ADVMODE_INITIAL_SET;
  1117. else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff"))
  1118. mode_idx = RT1011_ADVMODE_SEP_BQ_COEFF;
  1119. else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff"))
  1120. mode_idx = RT1011_ADVMODE_EQ_BQ_COEFF;
  1121. else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff"))
  1122. mode_idx = RT1011_ADVMODE_BQ_UI_COEFF;
  1123. else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff"))
  1124. mode_idx = RT1011_ADVMODE_SMARTBOOST_COEFF;
  1125. else
  1126. return -EINVAL;
  1127. bq_drc_info = rt1011->bq_drc_params[mode_idx];
  1128. memset(bq_drc_info, 0,
  1129. sizeof(struct rt1011_bq_drc_params) * RT1011_BQ_DRC_NUM);
  1130. pr_info("%s, id.name=%s, mode_idx=%d\n", __func__,
  1131. ucontrol->id.name, mode_idx);
  1132. for (i = 0; i < RT1011_BQ_DRC_NUM; i++) {
  1133. bq_drc_info[i].reg = params[i].reg;
  1134. bq_drc_info[i].val = params[i].val;
  1135. }
  1136. for (i = 0; i < RT1011_BQ_DRC_NUM; i++) {
  1137. if (bq_drc_info[i].reg == 0)
  1138. break;
  1139. else if (rt1011_validate_bq_drc_coeff(bq_drc_info[i].reg)) {
  1140. snd_soc_component_write(component, bq_drc_info[i].reg,
  1141. bq_drc_info[i].val);
  1142. }
  1143. }
  1144. return 0;
  1145. }
  1146. static int rt1011_bq_drc_info(struct snd_kcontrol *kcontrol,
  1147. struct snd_ctl_elem_info *uinfo)
  1148. {
  1149. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1150. uinfo->count = 128;
  1151. uinfo->value.integer.max = 0x17ffffff;
  1152. return 0;
  1153. }
  1154. #define RT1011_BQ_DRC(xname) \
  1155. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1156. .info = rt1011_bq_drc_info, \
  1157. .get = rt1011_bq_drc_coeff_get, \
  1158. .put = rt1011_bq_drc_coeff_put \
  1159. }
  1160. static int rt1011_r0_cali_get(struct snd_kcontrol *kcontrol,
  1161. struct snd_ctl_elem_value *ucontrol)
  1162. {
  1163. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  1164. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1165. ucontrol->value.integer.value[0] = rt1011->cali_done;
  1166. return 0;
  1167. }
  1168. static int rt1011_r0_cali_put(struct snd_kcontrol *kcontrol,
  1169. struct snd_ctl_elem_value *ucontrol)
  1170. {
  1171. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  1172. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1173. rt1011->cali_done = 0;
  1174. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF &&
  1175. ucontrol->value.integer.value[0])
  1176. rt1011_calibrate(rt1011, 1);
  1177. return 0;
  1178. }
  1179. static int rt1011_r0_load(struct rt1011_priv *rt1011)
  1180. {
  1181. if (!rt1011->r0_reg)
  1182. return -EINVAL;
  1183. /* write R0 to register */
  1184. regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_24_16,
  1185. ((rt1011->r0_reg>>16) & 0x1ff));
  1186. regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_15_0,
  1187. (rt1011->r0_reg & 0xffff));
  1188. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4080);
  1189. return 0;
  1190. }
  1191. static int rt1011_r0_load_mode_get(struct snd_kcontrol *kcontrol,
  1192. struct snd_ctl_elem_value *ucontrol)
  1193. {
  1194. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  1195. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1196. ucontrol->value.integer.value[0] = rt1011->r0_reg;
  1197. return 0;
  1198. }
  1199. static int rt1011_r0_load_mode_put(struct snd_kcontrol *kcontrol,
  1200. struct snd_ctl_elem_value *ucontrol)
  1201. {
  1202. struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
  1203. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1204. struct device *dev;
  1205. unsigned int r0_integer, r0_factor, format;
  1206. if (ucontrol->value.integer.value[0] == rt1011->r0_reg)
  1207. return 0;
  1208. if (ucontrol->value.integer.value[0] == 0)
  1209. return -EINVAL;
  1210. dev = regmap_get_device(rt1011->regmap);
  1211. if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
  1212. rt1011->r0_reg = ucontrol->value.integer.value[0];
  1213. format = 2147483648U; /* 2^24 * 128 */
  1214. r0_integer = format / rt1011->r0_reg / 128;
  1215. r0_factor = ((format / rt1011->r0_reg * 100) / 128)
  1216. - (r0_integer * 100);
  1217. dev_info(dev, "New r0 resistance about %d.%02d ohm, reg=0x%X\n",
  1218. r0_integer, r0_factor, rt1011->r0_reg);
  1219. if (rt1011->r0_reg)
  1220. rt1011_r0_load(rt1011);
  1221. }
  1222. return 0;
  1223. }
  1224. static int rt1011_r0_load_info(struct snd_kcontrol *kcontrol,
  1225. struct snd_ctl_elem_info *uinfo)
  1226. {
  1227. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1228. uinfo->count = 1;
  1229. uinfo->value.integer.max = 0x1ffffff;
  1230. return 0;
  1231. }
  1232. #define RT1011_R0_LOAD(xname) \
  1233. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1234. .info = rt1011_r0_load_info, \
  1235. .get = rt1011_r0_load_mode_get, \
  1236. .put = rt1011_r0_load_mode_put \
  1237. }
  1238. static const char * const rt1011_i2s_ref[] = {
  1239. "None", "Left Channel", "Right Channel"
  1240. };
  1241. static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum, 0, 0,
  1242. rt1011_i2s_ref);
  1243. static int rt1011_i2s_ref_put(struct snd_kcontrol *kcontrol,
  1244. struct snd_ctl_elem_value *ucontrol)
  1245. {
  1246. struct snd_soc_component *component =
  1247. snd_soc_kcontrol_component(kcontrol);
  1248. struct rt1011_priv *rt1011 =
  1249. snd_soc_component_get_drvdata(component);
  1250. rt1011->i2s_ref = ucontrol->value.enumerated.item[0];
  1251. switch (rt1011->i2s_ref) {
  1252. case RT1011_I2S_REF_LEFT_CH:
  1253. regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
  1254. regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
  1255. regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022);
  1256. regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
  1257. break;
  1258. case RT1011_I2S_REF_RIGHT_CH:
  1259. regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
  1260. regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
  1261. regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2);
  1262. regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
  1263. break;
  1264. default:
  1265. dev_info(component->dev, "I2S Reference: Do nothing\n");
  1266. }
  1267. return 0;
  1268. }
  1269. static int rt1011_i2s_ref_get(struct snd_kcontrol *kcontrol,
  1270. struct snd_ctl_elem_value *ucontrol)
  1271. {
  1272. struct snd_soc_component *component =
  1273. snd_soc_kcontrol_component(kcontrol);
  1274. struct rt1011_priv *rt1011 =
  1275. snd_soc_component_get_drvdata(component);
  1276. ucontrol->value.enumerated.item[0] = rt1011->i2s_ref;
  1277. return 0;
  1278. }
  1279. static const struct snd_kcontrol_new rt1011_snd_controls[] = {
  1280. /* I2S Data In Selection */
  1281. SOC_ENUM("DIN Source", rt1011_din_source_enum),
  1282. /* TDM Data In Selection */
  1283. SOC_ENUM("TDM1 DIN Source", rt1011_tdm1_l_dac1_enum),
  1284. SOC_ENUM("TDM2 DIN Source", rt1011_tdm2_l_dac1_enum),
  1285. /* TDM1 Data Out Selection */
  1286. SOC_ENUM("TDM1 DOUT Source", rt1011_tdm1_adc1_dat_enum),
  1287. SOC_ENUM("TDM1 DOUT Location", rt1011_tdm1_adc1_loc_enum),
  1288. SOC_ENUM("TDM1 ADC1DAT Swap Select", rt1011_tdm_adc1_1_enum),
  1289. SOC_ENUM("TDM1 ADC2DAT Swap Select", rt1011_tdm_adc2_1_enum),
  1290. /* Data Out Mode */
  1291. SOC_ENUM("I2S ADC DOUT Mode", rt1011_adc_dout_mode_enum),
  1292. SOC_ENUM("TDM1 DOUT Length", rt1011_tdm1_dout_len_enum),
  1293. SOC_ENUM("TDM2 DOUT Length", rt1011_tdm2_dout_len_enum),
  1294. /* Speaker/Receiver Mode */
  1295. SOC_SINGLE_EXT("RECV SPK Mode", SND_SOC_NOPM, 0, 1, 0,
  1296. rt1011_recv_spk_mode_get, rt1011_recv_spk_mode_put),
  1297. /* BiQuad/DRC/SmartBoost Settings */
  1298. RT1011_BQ_DRC("AdvanceMode Initial Set"),
  1299. RT1011_BQ_DRC("AdvanceMode SEP BQ Coeff"),
  1300. RT1011_BQ_DRC("AdvanceMode EQ BQ Coeff"),
  1301. RT1011_BQ_DRC("AdvanceMode BQ UI Coeff"),
  1302. RT1011_BQ_DRC("AdvanceMode SmartBoost Coeff"),
  1303. /* R0 */
  1304. SOC_SINGLE_EXT("R0 Calibration", SND_SOC_NOPM, 0, 1, 0,
  1305. rt1011_r0_cali_get, rt1011_r0_cali_put),
  1306. RT1011_R0_LOAD("R0 Load Mode"),
  1307. /* R0 temperature */
  1308. SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
  1309. 2, 255, 0),
  1310. /* I2S Reference */
  1311. SOC_ENUM_EXT("I2S Reference", rt1011_i2s_ref_enum,
  1312. rt1011_i2s_ref_get, rt1011_i2s_ref_put),
  1313. };
  1314. static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
  1315. struct snd_soc_dapm_widget *sink)
  1316. {
  1317. struct snd_soc_component *component =
  1318. snd_soc_dapm_to_component(source->dapm);
  1319. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1320. if (rt1011->sysclk_src == RT1011_FS_SYS_PRE_S_PLL1)
  1321. return 1;
  1322. else
  1323. return 0;
  1324. }
  1325. static int rt1011_dac_event(struct snd_soc_dapm_widget *w,
  1326. struct snd_kcontrol *kcontrol, int event)
  1327. {
  1328. struct snd_soc_component *component =
  1329. snd_soc_dapm_to_component(w->dapm);
  1330. switch (event) {
  1331. case SND_SOC_DAPM_POST_PMU:
  1332. snd_soc_component_update_bits(component,
  1333. RT1011_SPK_TEMP_PROTECT_0,
  1334. RT1011_STP_EN_MASK | RT1011_STP_RS_CLB_EN_MASK,
  1335. RT1011_STP_EN | RT1011_STP_RS_CLB_EN);
  1336. snd_soc_component_update_bits(component, RT1011_POWER_9,
  1337. RT1011_POW_MNL_SDB_MASK, RT1011_POW_MNL_SDB);
  1338. msleep(50);
  1339. snd_soc_component_update_bits(component,
  1340. RT1011_CLASSD_INTERNAL_SET_1,
  1341. RT1011_DRIVER_READY_SPK, RT1011_DRIVER_READY_SPK);
  1342. break;
  1343. case SND_SOC_DAPM_PRE_PMD:
  1344. snd_soc_component_update_bits(component, RT1011_POWER_9,
  1345. RT1011_POW_MNL_SDB_MASK, 0);
  1346. snd_soc_component_update_bits(component,
  1347. RT1011_SPK_TEMP_PROTECT_0,
  1348. RT1011_STP_EN_MASK | RT1011_STP_RS_CLB_EN_MASK, 0);
  1349. msleep(200);
  1350. snd_soc_component_update_bits(component,
  1351. RT1011_CLASSD_INTERNAL_SET_1,
  1352. RT1011_DRIVER_READY_SPK, 0);
  1353. break;
  1354. default:
  1355. return 0;
  1356. }
  1357. return 0;
  1358. }
  1359. static const struct snd_soc_dapm_widget rt1011_dapm_widgets[] = {
  1360. SND_SOC_DAPM_SUPPLY("LDO2", RT1011_POWER_1,
  1361. RT1011_POW_LDO2_BIT, 0, NULL, 0),
  1362. SND_SOC_DAPM_SUPPLY("ISENSE SPK", RT1011_POWER_1,
  1363. RT1011_POW_ISENSE_SPK_BIT, 0, NULL, 0),
  1364. SND_SOC_DAPM_SUPPLY("VSENSE SPK", RT1011_POWER_1,
  1365. RT1011_POW_VSENSE_SPK_BIT, 0, NULL, 0),
  1366. SND_SOC_DAPM_SUPPLY("PLL", RT1011_POWER_2,
  1367. RT1011_PLLEN_BIT, 0, NULL, 0),
  1368. SND_SOC_DAPM_SUPPLY("BG", RT1011_POWER_2,
  1369. RT1011_POW_BG_BIT, 0, NULL, 0),
  1370. SND_SOC_DAPM_SUPPLY("BG MBIAS", RT1011_POWER_2,
  1371. RT1011_POW_BG_MBIAS_LV_BIT, 0, NULL, 0),
  1372. SND_SOC_DAPM_SUPPLY("DET VBAT", RT1011_POWER_3,
  1373. RT1011_POW_DET_VBAT_BIT, 0, NULL, 0),
  1374. SND_SOC_DAPM_SUPPLY("MBIAS", RT1011_POWER_3,
  1375. RT1011_POW_MBIAS_LV_BIT, 0, NULL, 0),
  1376. SND_SOC_DAPM_SUPPLY("ADC I", RT1011_POWER_3,
  1377. RT1011_POW_ADC_I_BIT, 0, NULL, 0),
  1378. SND_SOC_DAPM_SUPPLY("ADC V", RT1011_POWER_3,
  1379. RT1011_POW_ADC_V_BIT, 0, NULL, 0),
  1380. SND_SOC_DAPM_SUPPLY("ADC T", RT1011_POWER_3,
  1381. RT1011_POW_ADC_T_BIT, 0, NULL, 0),
  1382. SND_SOC_DAPM_SUPPLY("DITHER ADC T", RT1011_POWER_3,
  1383. RT1011_POWD_ADC_T_BIT, 0, NULL, 0),
  1384. SND_SOC_DAPM_SUPPLY("MIX I", RT1011_POWER_3,
  1385. RT1011_POW_MIX_I_BIT, 0, NULL, 0),
  1386. SND_SOC_DAPM_SUPPLY("MIX V", RT1011_POWER_3,
  1387. RT1011_POW_MIX_V_BIT, 0, NULL, 0),
  1388. SND_SOC_DAPM_SUPPLY("SUM I", RT1011_POWER_3,
  1389. RT1011_POW_SUM_I_BIT, 0, NULL, 0),
  1390. SND_SOC_DAPM_SUPPLY("SUM V", RT1011_POWER_3,
  1391. RT1011_POW_SUM_V_BIT, 0, NULL, 0),
  1392. SND_SOC_DAPM_SUPPLY("MIX T", RT1011_POWER_3,
  1393. RT1011_POW_MIX_T_BIT, 0, NULL, 0),
  1394. SND_SOC_DAPM_SUPPLY("VREF", RT1011_POWER_3,
  1395. RT1011_POW_VREF_LV_BIT, 0, NULL, 0),
  1396. SND_SOC_DAPM_SUPPLY("BOOST SWR", RT1011_POWER_4,
  1397. RT1011_POW_EN_SWR_BIT, 0, NULL, 0),
  1398. SND_SOC_DAPM_SUPPLY("BGOK SWR", RT1011_POWER_4,
  1399. RT1011_POW_EN_PASS_BGOK_SWR_BIT, 0, NULL, 0),
  1400. SND_SOC_DAPM_SUPPLY("VPOK SWR", RT1011_POWER_4,
  1401. RT1011_POW_EN_PASS_VPOK_SWR_BIT, 0, NULL, 0),
  1402. SND_SOC_DAPM_SUPPLY("TEMP REG", RT1011_A_TEMP_SEN,
  1403. RT1011_POW_TEMP_REG_BIT, 0, NULL, 0),
  1404. /* Audio Interface */
  1405. SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  1406. /* Digital Interface */
  1407. SND_SOC_DAPM_SUPPLY("DAC Power", RT1011_POWER_1,
  1408. RT1011_POW_DAC_BIT, 0, NULL, 0),
  1409. SND_SOC_DAPM_SUPPLY("CLK12M", RT1011_POWER_1,
  1410. RT1011_POW_CLK12M_BIT, 0, NULL, 0),
  1411. SND_SOC_DAPM_DAC_E("DAC", NULL, RT1011_DAC_SET_3,
  1412. RT1011_DA_MUTE_EN_SFT, 1, rt1011_dac_event,
  1413. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
  1414. /* Output Lines */
  1415. SND_SOC_DAPM_OUTPUT("SPO"),
  1416. };
  1417. static const struct snd_soc_dapm_route rt1011_dapm_routes[] = {
  1418. { "DAC", NULL, "AIF1RX" },
  1419. { "DAC", NULL, "DAC Power" },
  1420. { "DAC", NULL, "LDO2" },
  1421. { "DAC", NULL, "ISENSE SPK" },
  1422. { "DAC", NULL, "VSENSE SPK" },
  1423. { "DAC", NULL, "CLK12M" },
  1424. { "DAC", NULL, "PLL", rt1011_is_sys_clk_from_pll },
  1425. { "DAC", NULL, "BG" },
  1426. { "DAC", NULL, "BG MBIAS" },
  1427. { "DAC", NULL, "BOOST SWR" },
  1428. { "DAC", NULL, "BGOK SWR" },
  1429. { "DAC", NULL, "VPOK SWR" },
  1430. { "DAC", NULL, "DET VBAT" },
  1431. { "DAC", NULL, "MBIAS" },
  1432. { "DAC", NULL, "VREF" },
  1433. { "DAC", NULL, "ADC I" },
  1434. { "DAC", NULL, "ADC V" },
  1435. { "DAC", NULL, "ADC T" },
  1436. { "DAC", NULL, "DITHER ADC T" },
  1437. { "DAC", NULL, "MIX I" },
  1438. { "DAC", NULL, "MIX V" },
  1439. { "DAC", NULL, "SUM I" },
  1440. { "DAC", NULL, "SUM V" },
  1441. { "DAC", NULL, "MIX T" },
  1442. { "DAC", NULL, "TEMP REG" },
  1443. { "SPO", NULL, "DAC" },
  1444. };
  1445. static int rt1011_get_clk_info(int sclk, int rate)
  1446. {
  1447. int i;
  1448. static const int pd[] = {1, 2, 3, 4, 6, 8, 12, 16};
  1449. if (sclk <= 0 || rate <= 0)
  1450. return -EINVAL;
  1451. rate = rate << 8;
  1452. for (i = 0; i < ARRAY_SIZE(pd); i++)
  1453. if (sclk == rate * pd[i])
  1454. return i;
  1455. return -EINVAL;
  1456. }
  1457. static int rt1011_hw_params(struct snd_pcm_substream *substream,
  1458. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  1459. {
  1460. struct snd_soc_component *component = dai->component;
  1461. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1462. unsigned int val_len = 0, ch_len = 0, val_clk, mask_clk;
  1463. int pre_div, bclk_ms, frame_size;
  1464. rt1011->lrck = params_rate(params);
  1465. pre_div = rt1011_get_clk_info(rt1011->sysclk, rt1011->lrck);
  1466. if (pre_div < 0) {
  1467. dev_warn(component->dev, "Force using PLL ");
  1468. snd_soc_dai_set_pll(dai, 0, RT1011_PLL1_S_BCLK,
  1469. rt1011->lrck * 64, rt1011->lrck * 256);
  1470. snd_soc_dai_set_sysclk(dai, RT1011_FS_SYS_PRE_S_PLL1,
  1471. rt1011->lrck * 256, SND_SOC_CLOCK_IN);
  1472. pre_div = 0;
  1473. }
  1474. frame_size = snd_soc_params_to_frame_size(params);
  1475. if (frame_size < 0) {
  1476. dev_err(component->dev, "Unsupported frame size: %d\n",
  1477. frame_size);
  1478. return -EINVAL;
  1479. }
  1480. bclk_ms = frame_size > 32;
  1481. rt1011->bclk = rt1011->lrck * (32 << bclk_ms);
  1482. dev_dbg(component->dev, "bclk_ms is %d and pre_div is %d for iis %d\n",
  1483. bclk_ms, pre_div, dai->id);
  1484. dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d\n",
  1485. rt1011->lrck, pre_div, dai->id);
  1486. switch (params_width(params)) {
  1487. case 16:
  1488. val_len |= RT1011_I2S_TX_DL_16B;
  1489. val_len |= RT1011_I2S_RX_DL_16B;
  1490. ch_len |= RT1011_I2S_CH_TX_LEN_16B;
  1491. ch_len |= RT1011_I2S_CH_RX_LEN_16B;
  1492. break;
  1493. case 20:
  1494. val_len |= RT1011_I2S_TX_DL_20B;
  1495. val_len |= RT1011_I2S_RX_DL_20B;
  1496. ch_len |= RT1011_I2S_CH_TX_LEN_20B;
  1497. ch_len |= RT1011_I2S_CH_RX_LEN_20B;
  1498. break;
  1499. case 24:
  1500. val_len |= RT1011_I2S_TX_DL_24B;
  1501. val_len |= RT1011_I2S_RX_DL_24B;
  1502. ch_len |= RT1011_I2S_CH_TX_LEN_24B;
  1503. ch_len |= RT1011_I2S_CH_RX_LEN_24B;
  1504. break;
  1505. case 32:
  1506. val_len |= RT1011_I2S_TX_DL_32B;
  1507. val_len |= RT1011_I2S_RX_DL_32B;
  1508. ch_len |= RT1011_I2S_CH_TX_LEN_32B;
  1509. ch_len |= RT1011_I2S_CH_RX_LEN_32B;
  1510. break;
  1511. case 8:
  1512. val_len |= RT1011_I2S_TX_DL_8B;
  1513. val_len |= RT1011_I2S_RX_DL_8B;
  1514. ch_len |= RT1011_I2S_CH_TX_LEN_8B;
  1515. ch_len |= RT1011_I2S_CH_RX_LEN_8B;
  1516. break;
  1517. default:
  1518. return -EINVAL;
  1519. }
  1520. switch (dai->id) {
  1521. case RT1011_AIF1:
  1522. mask_clk = RT1011_FS_SYS_DIV_MASK;
  1523. val_clk = pre_div << RT1011_FS_SYS_DIV_SFT;
  1524. snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET,
  1525. RT1011_I2S_TX_DL_MASK | RT1011_I2S_RX_DL_MASK,
  1526. val_len);
  1527. snd_soc_component_update_bits(component, RT1011_TDM1_SET_1,
  1528. RT1011_I2S_CH_TX_LEN_MASK |
  1529. RT1011_I2S_CH_RX_LEN_MASK,
  1530. ch_len);
  1531. break;
  1532. default:
  1533. dev_err(component->dev, "Invalid dai->id: %d\n", dai->id);
  1534. return -EINVAL;
  1535. }
  1536. snd_soc_component_update_bits(component,
  1537. RT1011_CLK_2, mask_clk, val_clk);
  1538. return 0;
  1539. }
  1540. static int rt1011_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1541. {
  1542. struct snd_soc_component *component = dai->component;
  1543. struct snd_soc_dapm_context *dapm =
  1544. snd_soc_component_get_dapm(component);
  1545. unsigned int reg_val = 0, reg_bclk_inv = 0;
  1546. int ret = 0;
  1547. snd_soc_dapm_mutex_lock(dapm);
  1548. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1549. case SND_SOC_DAIFMT_CBS_CFS:
  1550. reg_val |= RT1011_I2S_TDM_MS_S;
  1551. break;
  1552. default:
  1553. ret = -EINVAL;
  1554. goto _set_fmt_err_;
  1555. }
  1556. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1557. case SND_SOC_DAIFMT_NB_NF:
  1558. break;
  1559. case SND_SOC_DAIFMT_IB_NF:
  1560. reg_bclk_inv |= RT1011_TDM_INV_BCLK;
  1561. break;
  1562. default:
  1563. ret = -EINVAL;
  1564. goto _set_fmt_err_;
  1565. }
  1566. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1567. case SND_SOC_DAIFMT_I2S:
  1568. break;
  1569. case SND_SOC_DAIFMT_LEFT_J:
  1570. reg_val |= RT1011_I2S_TDM_DF_LEFT;
  1571. break;
  1572. case SND_SOC_DAIFMT_DSP_A:
  1573. reg_val |= RT1011_I2S_TDM_DF_PCM_A;
  1574. break;
  1575. case SND_SOC_DAIFMT_DSP_B:
  1576. reg_val |= RT1011_I2S_TDM_DF_PCM_B;
  1577. break;
  1578. default:
  1579. ret = -EINVAL;
  1580. goto _set_fmt_err_;
  1581. }
  1582. switch (dai->id) {
  1583. case RT1011_AIF1:
  1584. snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET,
  1585. RT1011_I2S_TDM_MS_MASK | RT1011_I2S_TDM_DF_MASK,
  1586. reg_val);
  1587. snd_soc_component_update_bits(component, RT1011_TDM1_SET_1,
  1588. RT1011_TDM_INV_BCLK_MASK, reg_bclk_inv);
  1589. snd_soc_component_update_bits(component, RT1011_TDM2_SET_1,
  1590. RT1011_TDM_INV_BCLK_MASK, reg_bclk_inv);
  1591. break;
  1592. default:
  1593. dev_err(component->dev, "Invalid dai->id: %d\n", dai->id);
  1594. ret = -EINVAL;
  1595. }
  1596. _set_fmt_err_:
  1597. snd_soc_dapm_mutex_unlock(dapm);
  1598. return ret;
  1599. }
  1600. static int rt1011_set_component_sysclk(struct snd_soc_component *component,
  1601. int clk_id, int source, unsigned int freq, int dir)
  1602. {
  1603. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1604. unsigned int reg_val = 0;
  1605. if (freq == rt1011->sysclk && clk_id == rt1011->sysclk_src)
  1606. return 0;
  1607. /* disable MCLK detect in default */
  1608. snd_soc_component_update_bits(component, RT1011_CLK_DET,
  1609. RT1011_EN_MCLK_DET_MASK, 0);
  1610. switch (clk_id) {
  1611. case RT1011_FS_SYS_PRE_S_MCLK:
  1612. reg_val |= RT1011_FS_SYS_PRE_MCLK;
  1613. snd_soc_component_update_bits(component, RT1011_CLK_DET,
  1614. RT1011_EN_MCLK_DET_MASK, RT1011_EN_MCLK_DET);
  1615. break;
  1616. case RT1011_FS_SYS_PRE_S_BCLK:
  1617. reg_val |= RT1011_FS_SYS_PRE_BCLK;
  1618. break;
  1619. case RT1011_FS_SYS_PRE_S_PLL1:
  1620. reg_val |= RT1011_FS_SYS_PRE_PLL1;
  1621. break;
  1622. case RT1011_FS_SYS_PRE_S_RCCLK:
  1623. reg_val |= RT1011_FS_SYS_PRE_RCCLK;
  1624. break;
  1625. default:
  1626. dev_err(component->dev, "Invalid clock id (%d)\n", clk_id);
  1627. return -EINVAL;
  1628. }
  1629. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1630. RT1011_FS_SYS_PRE_MASK, reg_val);
  1631. rt1011->sysclk = freq;
  1632. rt1011->sysclk_src = clk_id;
  1633. dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n",
  1634. freq, clk_id);
  1635. return 0;
  1636. }
  1637. static int rt1011_set_component_pll(struct snd_soc_component *component,
  1638. int pll_id, int source, unsigned int freq_in,
  1639. unsigned int freq_out)
  1640. {
  1641. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1642. struct rl6231_pll_code pll_code;
  1643. int ret;
  1644. if (source == rt1011->pll_src && freq_in == rt1011->pll_in &&
  1645. freq_out == rt1011->pll_out)
  1646. return 0;
  1647. if (!freq_in || !freq_out) {
  1648. dev_dbg(component->dev, "PLL disabled\n");
  1649. rt1011->pll_in = 0;
  1650. rt1011->pll_out = 0;
  1651. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1652. RT1011_FS_SYS_PRE_MASK, RT1011_FS_SYS_PRE_BCLK);
  1653. return 0;
  1654. }
  1655. switch (source) {
  1656. case RT1011_PLL2_S_MCLK:
  1657. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1658. RT1011_PLL2_SRC_MASK, RT1011_PLL2_SRC_MCLK);
  1659. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1660. RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_PLL2);
  1661. snd_soc_component_update_bits(component, RT1011_CLK_DET,
  1662. RT1011_EN_MCLK_DET_MASK, RT1011_EN_MCLK_DET);
  1663. break;
  1664. case RT1011_PLL1_S_BCLK:
  1665. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1666. RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_BCLK);
  1667. break;
  1668. case RT1011_PLL2_S_RCCLK:
  1669. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1670. RT1011_PLL2_SRC_MASK, RT1011_PLL2_SRC_RCCLK);
  1671. snd_soc_component_update_bits(component, RT1011_CLK_2,
  1672. RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_PLL2);
  1673. break;
  1674. default:
  1675. dev_err(component->dev, "Unknown PLL Source %d\n", source);
  1676. return -EINVAL;
  1677. }
  1678. ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
  1679. if (ret < 0) {
  1680. dev_err(component->dev, "Unsupported input clock %d\n",
  1681. freq_in);
  1682. return ret;
  1683. }
  1684. dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n",
  1685. pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
  1686. pll_code.n_code, pll_code.k_code);
  1687. snd_soc_component_write(component, RT1011_PLL_1,
  1688. ((pll_code.m_bp ? 0 : pll_code.m_code) << RT1011_PLL1_QM_SFT) |
  1689. (pll_code.m_bp << RT1011_PLL1_BPM_SFT) |
  1690. pll_code.n_code);
  1691. snd_soc_component_write(component, RT1011_PLL_2,
  1692. pll_code.k_code);
  1693. rt1011->pll_in = freq_in;
  1694. rt1011->pll_out = freq_out;
  1695. rt1011->pll_src = source;
  1696. return 0;
  1697. }
  1698. static int rt1011_set_tdm_slot(struct snd_soc_dai *dai,
  1699. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
  1700. {
  1701. struct snd_soc_component *component = dai->component;
  1702. struct snd_soc_dapm_context *dapm =
  1703. snd_soc_component_get_dapm(component);
  1704. unsigned int val = 0, tdm_en = 0, rx_slotnum, tx_slotnum;
  1705. int ret = 0, first_bit, last_bit;
  1706. snd_soc_dapm_mutex_lock(dapm);
  1707. if (rx_mask || tx_mask)
  1708. tdm_en = RT1011_TDM_I2S_DOCK_EN_1;
  1709. switch (slots) {
  1710. case 4:
  1711. val |= RT1011_I2S_TX_4CH;
  1712. val |= RT1011_I2S_RX_4CH;
  1713. break;
  1714. case 6:
  1715. val |= RT1011_I2S_TX_6CH;
  1716. val |= RT1011_I2S_RX_6CH;
  1717. break;
  1718. case 8:
  1719. val |= RT1011_I2S_TX_8CH;
  1720. val |= RT1011_I2S_RX_8CH;
  1721. break;
  1722. case 2:
  1723. break;
  1724. default:
  1725. ret = -EINVAL;
  1726. goto _set_tdm_err_;
  1727. }
  1728. switch (slot_width) {
  1729. case 20:
  1730. val |= RT1011_I2S_CH_TX_LEN_20B;
  1731. val |= RT1011_I2S_CH_RX_LEN_20B;
  1732. break;
  1733. case 24:
  1734. val |= RT1011_I2S_CH_TX_LEN_24B;
  1735. val |= RT1011_I2S_CH_RX_LEN_24B;
  1736. break;
  1737. case 32:
  1738. val |= RT1011_I2S_CH_TX_LEN_32B;
  1739. val |= RT1011_I2S_CH_RX_LEN_32B;
  1740. break;
  1741. case 16:
  1742. break;
  1743. default:
  1744. ret = -EINVAL;
  1745. goto _set_tdm_err_;
  1746. }
  1747. /* Rx slot configuration */
  1748. rx_slotnum = hweight_long(rx_mask);
  1749. if (rx_slotnum > 1 || !rx_slotnum) {
  1750. ret = -EINVAL;
  1751. dev_err(component->dev, "too many rx slots or zero slot\n");
  1752. goto _set_tdm_err_;
  1753. }
  1754. first_bit = __ffs(rx_mask);
  1755. switch (first_bit) {
  1756. case 0:
  1757. case 2:
  1758. case 4:
  1759. case 6:
  1760. snd_soc_component_update_bits(component,
  1761. RT1011_CROSS_BQ_SET_1, RT1011_MONO_LR_SEL_MASK,
  1762. RT1011_MONO_L_CHANNEL);
  1763. snd_soc_component_update_bits(component,
  1764. RT1011_TDM1_SET_4,
  1765. RT1011_TDM_I2S_TX_L_DAC1_1_MASK |
  1766. RT1011_TDM_I2S_TX_R_DAC1_1_MASK,
  1767. (first_bit << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) |
  1768. ((first_bit+1) << RT1011_TDM_I2S_TX_R_DAC1_1_SFT));
  1769. break;
  1770. case 1:
  1771. case 3:
  1772. case 5:
  1773. case 7:
  1774. snd_soc_component_update_bits(component,
  1775. RT1011_CROSS_BQ_SET_1, RT1011_MONO_LR_SEL_MASK,
  1776. RT1011_MONO_R_CHANNEL);
  1777. snd_soc_component_update_bits(component,
  1778. RT1011_TDM1_SET_4,
  1779. RT1011_TDM_I2S_TX_L_DAC1_1_MASK |
  1780. RT1011_TDM_I2S_TX_R_DAC1_1_MASK,
  1781. ((first_bit-1) << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) |
  1782. (first_bit << RT1011_TDM_I2S_TX_R_DAC1_1_SFT));
  1783. break;
  1784. default:
  1785. ret = -EINVAL;
  1786. goto _set_tdm_err_;
  1787. }
  1788. /* Tx slot configuration */
  1789. tx_slotnum = hweight_long(tx_mask);
  1790. if (tx_slotnum > 2 || !tx_slotnum) {
  1791. ret = -EINVAL;
  1792. dev_err(component->dev, "too many tx slots or zero slot\n");
  1793. goto _set_tdm_err_;
  1794. }
  1795. first_bit = __ffs(tx_mask);
  1796. last_bit = __fls(tx_mask);
  1797. if (last_bit - first_bit > 1) {
  1798. ret = -EINVAL;
  1799. dev_err(component->dev, "tx slot location error\n");
  1800. goto _set_tdm_err_;
  1801. }
  1802. if (tx_slotnum == 1) {
  1803. snd_soc_component_update_bits(component, RT1011_TDM1_SET_2,
  1804. RT1011_TDM_I2S_DOCK_ADCDAT_LEN_1_MASK |
  1805. RT1011_TDM_ADCDAT1_DATA_LOCATION, first_bit);
  1806. switch (first_bit) {
  1807. case 1:
  1808. snd_soc_component_update_bits(component,
  1809. RT1011_TDM1_SET_3,
  1810. RT1011_TDM_I2S_RX_ADC1_1_MASK,
  1811. RT1011_TDM_I2S_RX_ADC1_1_LL);
  1812. break;
  1813. case 3:
  1814. snd_soc_component_update_bits(component,
  1815. RT1011_TDM1_SET_3,
  1816. RT1011_TDM_I2S_RX_ADC2_1_MASK,
  1817. RT1011_TDM_I2S_RX_ADC2_1_LL);
  1818. break;
  1819. case 5:
  1820. snd_soc_component_update_bits(component,
  1821. RT1011_TDM1_SET_3,
  1822. RT1011_TDM_I2S_RX_ADC3_1_MASK,
  1823. RT1011_TDM_I2S_RX_ADC3_1_LL);
  1824. break;
  1825. case 7:
  1826. snd_soc_component_update_bits(component,
  1827. RT1011_TDM1_SET_3,
  1828. RT1011_TDM_I2S_RX_ADC4_1_MASK,
  1829. RT1011_TDM_I2S_RX_ADC4_1_LL);
  1830. break;
  1831. case 0:
  1832. snd_soc_component_update_bits(component,
  1833. RT1011_TDM1_SET_3,
  1834. RT1011_TDM_I2S_RX_ADC1_1_MASK, 0);
  1835. break;
  1836. case 2:
  1837. snd_soc_component_update_bits(component,
  1838. RT1011_TDM1_SET_3,
  1839. RT1011_TDM_I2S_RX_ADC2_1_MASK, 0);
  1840. break;
  1841. case 4:
  1842. snd_soc_component_update_bits(component,
  1843. RT1011_TDM1_SET_3,
  1844. RT1011_TDM_I2S_RX_ADC3_1_MASK, 0);
  1845. break;
  1846. case 6:
  1847. snd_soc_component_update_bits(component,
  1848. RT1011_TDM1_SET_3,
  1849. RT1011_TDM_I2S_RX_ADC4_1_MASK, 0);
  1850. break;
  1851. default:
  1852. ret = -EINVAL;
  1853. dev_dbg(component->dev,
  1854. "tx slot location error\n");
  1855. goto _set_tdm_err_;
  1856. }
  1857. } else if (tx_slotnum == 2) {
  1858. switch (first_bit) {
  1859. case 0:
  1860. case 2:
  1861. case 4:
  1862. case 6:
  1863. snd_soc_component_update_bits(component,
  1864. RT1011_TDM1_SET_2,
  1865. RT1011_TDM_I2S_DOCK_ADCDAT_LEN_1_MASK |
  1866. RT1011_TDM_ADCDAT1_DATA_LOCATION,
  1867. RT1011_TDM_I2S_DOCK_ADCDAT_2CH | first_bit);
  1868. break;
  1869. default:
  1870. ret = -EINVAL;
  1871. dev_dbg(component->dev,
  1872. "tx slot location should be paired and start from slot0/2/4/6\n");
  1873. goto _set_tdm_err_;
  1874. }
  1875. }
  1876. snd_soc_component_update_bits(component, RT1011_TDM1_SET_1,
  1877. RT1011_I2S_CH_TX_MASK | RT1011_I2S_CH_RX_MASK |
  1878. RT1011_I2S_CH_TX_LEN_MASK | RT1011_I2S_CH_RX_LEN_MASK, val);
  1879. snd_soc_component_update_bits(component, RT1011_TDM2_SET_1,
  1880. RT1011_I2S_CH_TX_MASK | RT1011_I2S_CH_RX_MASK |
  1881. RT1011_I2S_CH_TX_LEN_MASK | RT1011_I2S_CH_RX_LEN_MASK, val);
  1882. snd_soc_component_update_bits(component, RT1011_TDM1_SET_2,
  1883. RT1011_TDM_I2S_DOCK_EN_1_MASK, tdm_en);
  1884. snd_soc_component_update_bits(component, RT1011_TDM2_SET_2,
  1885. RT1011_TDM_I2S_DOCK_EN_2_MASK, tdm_en);
  1886. snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET,
  1887. RT1011_ADCDAT1_PIN_CONFIG | RT1011_ADCDAT2_PIN_CONFIG,
  1888. RT1011_ADCDAT1_OUTPUT | RT1011_ADCDAT2_OUTPUT);
  1889. _set_tdm_err_:
  1890. snd_soc_dapm_mutex_unlock(dapm);
  1891. return ret;
  1892. }
  1893. static int rt1011_probe(struct snd_soc_component *component)
  1894. {
  1895. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1896. int i;
  1897. rt1011->component = component;
  1898. schedule_work(&rt1011->cali_work);
  1899. rt1011->i2s_ref = 0;
  1900. rt1011->bq_drc_params = devm_kcalloc(component->dev,
  1901. RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
  1902. GFP_KERNEL);
  1903. if (!rt1011->bq_drc_params)
  1904. return -ENOMEM;
  1905. for (i = 0; i < RT1011_ADVMODE_NUM; i++) {
  1906. rt1011->bq_drc_params[i] = devm_kcalloc(component->dev,
  1907. RT1011_BQ_DRC_NUM, sizeof(struct rt1011_bq_drc_params),
  1908. GFP_KERNEL);
  1909. if (!rt1011->bq_drc_params[i])
  1910. return -ENOMEM;
  1911. }
  1912. return 0;
  1913. }
  1914. static void rt1011_remove(struct snd_soc_component *component)
  1915. {
  1916. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1917. cancel_work_sync(&rt1011->cali_work);
  1918. rt1011_reset(rt1011->regmap);
  1919. }
  1920. #ifdef CONFIG_PM
  1921. static int rt1011_suspend(struct snd_soc_component *component)
  1922. {
  1923. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1924. regcache_cache_only(rt1011->regmap, true);
  1925. regcache_mark_dirty(rt1011->regmap);
  1926. return 0;
  1927. }
  1928. static int rt1011_resume(struct snd_soc_component *component)
  1929. {
  1930. struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
  1931. regcache_cache_only(rt1011->regmap, false);
  1932. regcache_sync(rt1011->regmap);
  1933. return 0;
  1934. }
  1935. #else
  1936. #define rt1011_suspend NULL
  1937. #define rt1011_resume NULL
  1938. #endif
  1939. static int rt1011_set_bias_level(struct snd_soc_component *component,
  1940. enum snd_soc_bias_level level)
  1941. {
  1942. switch (level) {
  1943. case SND_SOC_BIAS_OFF:
  1944. snd_soc_component_write(component,
  1945. RT1011_SYSTEM_RESET_1, 0x0000);
  1946. snd_soc_component_write(component,
  1947. RT1011_SYSTEM_RESET_2, 0x0000);
  1948. snd_soc_component_write(component,
  1949. RT1011_SYSTEM_RESET_3, 0x0001);
  1950. snd_soc_component_write(component,
  1951. RT1011_SYSTEM_RESET_1, 0x003f);
  1952. snd_soc_component_write(component,
  1953. RT1011_SYSTEM_RESET_2, 0x7fd7);
  1954. snd_soc_component_write(component,
  1955. RT1011_SYSTEM_RESET_3, 0x770f);
  1956. break;
  1957. default:
  1958. break;
  1959. }
  1960. return 0;
  1961. }
  1962. #define RT1011_STEREO_RATES SNDRV_PCM_RATE_8000_192000
  1963. #define RT1011_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
  1964. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE | \
  1965. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1966. static const struct snd_soc_dai_ops rt1011_aif_dai_ops = {
  1967. .hw_params = rt1011_hw_params,
  1968. .set_fmt = rt1011_set_dai_fmt,
  1969. .set_tdm_slot = rt1011_set_tdm_slot,
  1970. };
  1971. static struct snd_soc_dai_driver rt1011_dai[] = {
  1972. {
  1973. .name = "rt1011-aif",
  1974. .playback = {
  1975. .stream_name = "AIF1 Playback",
  1976. .channels_min = 1,
  1977. .channels_max = 2,
  1978. .rates = RT1011_STEREO_RATES,
  1979. .formats = RT1011_FORMATS,
  1980. },
  1981. .ops = &rt1011_aif_dai_ops,
  1982. },
  1983. };
  1984. static const struct snd_soc_component_driver soc_component_dev_rt1011 = {
  1985. .probe = rt1011_probe,
  1986. .remove = rt1011_remove,
  1987. .suspend = rt1011_suspend,
  1988. .resume = rt1011_resume,
  1989. .set_bias_level = rt1011_set_bias_level,
  1990. .controls = rt1011_snd_controls,
  1991. .num_controls = ARRAY_SIZE(rt1011_snd_controls),
  1992. .dapm_widgets = rt1011_dapm_widgets,
  1993. .num_dapm_widgets = ARRAY_SIZE(rt1011_dapm_widgets),
  1994. .dapm_routes = rt1011_dapm_routes,
  1995. .num_dapm_routes = ARRAY_SIZE(rt1011_dapm_routes),
  1996. .set_sysclk = rt1011_set_component_sysclk,
  1997. .set_pll = rt1011_set_component_pll,
  1998. .use_pmdown_time = 1,
  1999. .endianness = 1,
  2000. };
  2001. static const struct regmap_config rt1011_regmap = {
  2002. .reg_bits = 16,
  2003. .val_bits = 16,
  2004. .max_register = RT1011_MAX_REG + 1,
  2005. .volatile_reg = rt1011_volatile_register,
  2006. .readable_reg = rt1011_readable_register,
  2007. .cache_type = REGCACHE_RBTREE,
  2008. .reg_defaults = rt1011_reg,
  2009. .num_reg_defaults = ARRAY_SIZE(rt1011_reg),
  2010. .use_single_read = true,
  2011. .use_single_write = true,
  2012. };
  2013. #if defined(CONFIG_OF)
  2014. static const struct of_device_id rt1011_of_match[] = {
  2015. { .compatible = "realtek,rt1011", },
  2016. {},
  2017. };
  2018. MODULE_DEVICE_TABLE(of, rt1011_of_match);
  2019. #endif
  2020. #ifdef CONFIG_ACPI
  2021. static const struct acpi_device_id rt1011_acpi_match[] = {
  2022. {"10EC1011", 0,},
  2023. {},
  2024. };
  2025. MODULE_DEVICE_TABLE(acpi, rt1011_acpi_match);
  2026. #endif
  2027. static const struct i2c_device_id rt1011_i2c_id[] = {
  2028. { "rt1011", 0 },
  2029. { }
  2030. };
  2031. MODULE_DEVICE_TABLE(i2c, rt1011_i2c_id);
  2032. static int rt1011_calibrate(struct rt1011_priv *rt1011, unsigned char cali_flag)
  2033. {
  2034. unsigned int value, count = 0, r0[3];
  2035. unsigned int chk_cnt = 50; /* DONT change this */
  2036. unsigned int dc_offset;
  2037. unsigned int r0_integer, r0_factor, format;
  2038. struct device *dev = regmap_get_device(rt1011->regmap);
  2039. struct snd_soc_dapm_context *dapm =
  2040. snd_soc_component_get_dapm(rt1011->component);
  2041. int ret = 0;
  2042. snd_soc_dapm_mutex_lock(dapm);
  2043. regcache_cache_bypass(rt1011->regmap, true);
  2044. regmap_write(rt1011->regmap, RT1011_RESET, 0x0000);
  2045. regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x740f);
  2046. regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x770f);
  2047. /* RC clock */
  2048. regmap_write(rt1011->regmap, RT1011_CLK_2, 0x9400);
  2049. regmap_write(rt1011->regmap, RT1011_PLL_1, 0x0800);
  2050. regmap_write(rt1011->regmap, RT1011_PLL_2, 0x0020);
  2051. regmap_write(rt1011->regmap, RT1011_CLK_DET, 0x0800);
  2052. /* ADC/DAC setting */
  2053. regmap_write(rt1011->regmap, RT1011_ADC_SET_5, 0x0a20);
  2054. regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xe232);
  2055. regmap_write(rt1011->regmap, RT1011_ADC_SET_4, 0xc000);
  2056. /* DC detection */
  2057. regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_1, 0xb00c);
  2058. regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_2, 0xcccc);
  2059. /* Power */
  2060. regmap_write(rt1011->regmap, RT1011_POWER_1, 0xe0e0);
  2061. regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5003);
  2062. regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa860);
  2063. regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xa032);
  2064. /* POW_PLL / POW_BG / POW_BG_MBIAS_LV / POW_V/I */
  2065. regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0007);
  2066. regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5ff7);
  2067. regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f44);
  2068. regmap_write(rt1011->regmap, RT1011_A_TIMING_1, 0x4054);
  2069. regmap_write(rt1011->regmap, RT1011_BAT_GAIN_1, 0x309c);
  2070. /* DC offset from EFUSE */
  2071. regmap_write(rt1011->regmap, RT1011_DC_CALIB_CLASSD_3, 0xcb00);
  2072. regmap_write(rt1011->regmap, RT1011_BOOST_CON_1, 0xe080);
  2073. regmap_write(rt1011->regmap, RT1011_POWER_4, 0x16f2);
  2074. regmap_write(rt1011->regmap, RT1011_POWER_6, 0x36ad);
  2075. /* mixer */
  2076. regmap_write(rt1011->regmap, RT1011_MIXER_1, 0x3f1d);
  2077. /* EFUSE read */
  2078. regmap_write(rt1011->regmap, RT1011_EFUSE_CONTROL_1, 0x0d0a);
  2079. msleep(30);
  2080. regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_18_16, &value);
  2081. dc_offset = value << 16;
  2082. regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_15_0, &value);
  2083. dc_offset |= (value & 0xffff);
  2084. dev_info(dev, "ADC offset=0x%x\n", dc_offset);
  2085. regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_20_16, &value);
  2086. dc_offset = value << 16;
  2087. regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_15_0, &value);
  2088. dc_offset |= (value & 0xffff);
  2089. dev_info(dev, "Gain0 offset=0x%x\n", dc_offset);
  2090. regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_20_16, &value);
  2091. dc_offset = value << 16;
  2092. regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_15_0, &value);
  2093. dc_offset |= (value & 0xffff);
  2094. dev_info(dev, "Gain1 offset=0x%x\n", dc_offset);
  2095. if (cali_flag) {
  2096. regmap_write(rt1011->regmap, RT1011_ADC_SET_1, 0x2925);
  2097. /* Class D on */
  2098. regmap_write(rt1011->regmap, RT1011_CLASS_D_POS, 0x010e);
  2099. regmap_write(rt1011->regmap,
  2100. RT1011_CLASSD_INTERNAL_SET_1, 0x1701);
  2101. /* STP enable */
  2102. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x8000);
  2103. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_7, 0xf000);
  2104. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4040);
  2105. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0xc000);
  2106. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x07c2);
  2107. r0[0] = r0[1] = r0[2] = count = 0;
  2108. while (count < chk_cnt) {
  2109. msleep(100);
  2110. regmap_read(rt1011->regmap,
  2111. RT1011_INIT_RECIPROCAL_SYN_24_16, &value);
  2112. r0[count%3] = value << 16;
  2113. regmap_read(rt1011->regmap,
  2114. RT1011_INIT_RECIPROCAL_SYN_15_0, &value);
  2115. r0[count%3] |= value;
  2116. if (r0[count%3] == 0)
  2117. continue;
  2118. count++;
  2119. if (r0[0] == r0[1] && r0[1] == r0[2])
  2120. break;
  2121. }
  2122. if (count > chk_cnt) {
  2123. dev_err(dev, "Calibrate R0 Failure\n");
  2124. ret = -EAGAIN;
  2125. } else {
  2126. format = 2147483648U; /* 2^24 * 128 */
  2127. r0_integer = format / r0[0] / 128;
  2128. r0_factor = ((format / r0[0] * 100) / 128)
  2129. - (r0_integer * 100);
  2130. rt1011->r0_reg = r0[0];
  2131. rt1011->cali_done = 1;
  2132. dev_info(dev, "r0 resistance about %d.%02d ohm, reg=0x%X\n",
  2133. r0_integer, r0_factor, r0[0]);
  2134. }
  2135. }
  2136. /* depop */
  2137. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x0000);
  2138. msleep(400);
  2139. regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa840);
  2140. regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x0702);
  2141. regmap_write(rt1011->regmap, RT1011_MIXER_1, 0xffdd);
  2142. regmap_write(rt1011->regmap, RT1011_CLASSD_INTERNAL_SET_1, 0x0701);
  2143. regmap_write(rt1011->regmap, RT1011_DAC_SET_3, 0xe004);
  2144. regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f40);
  2145. regmap_write(rt1011->regmap, RT1011_POWER_1, 0x0000);
  2146. regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0000);
  2147. regmap_write(rt1011->regmap, RT1011_POWER_3, 0x0002);
  2148. regmap_write(rt1011->regmap, RT1011_POWER_4, 0x00f2);
  2149. regmap_write(rt1011->regmap, RT1011_RESET, 0x0000);
  2150. if (cali_flag) {
  2151. if (count <= chk_cnt) {
  2152. regmap_write(rt1011->regmap,
  2153. RT1011_INIT_RECIPROCAL_REG_24_16,
  2154. ((r0[0]>>16) & 0x1ff));
  2155. regmap_write(rt1011->regmap,
  2156. RT1011_INIT_RECIPROCAL_REG_15_0,
  2157. (r0[0] & 0xffff));
  2158. regmap_write(rt1011->regmap,
  2159. RT1011_SPK_TEMP_PROTECT_4, 0x4080);
  2160. }
  2161. }
  2162. regcache_cache_bypass(rt1011->regmap, false);
  2163. regcache_mark_dirty(rt1011->regmap);
  2164. regcache_sync(rt1011->regmap);
  2165. snd_soc_dapm_mutex_unlock(dapm);
  2166. return ret;
  2167. }
  2168. static void rt1011_calibration_work(struct work_struct *work)
  2169. {
  2170. struct rt1011_priv *rt1011 =
  2171. container_of(work, struct rt1011_priv, cali_work);
  2172. struct snd_soc_component *component = rt1011->component;
  2173. unsigned int r0_integer, r0_factor, format;
  2174. if (rt1011->r0_calib)
  2175. rt1011_calibrate(rt1011, 0);
  2176. else
  2177. rt1011_calibrate(rt1011, 1);
  2178. /*
  2179. * This flag should reset after booting.
  2180. * The factory test will do calibration again and use this flag to check
  2181. * whether the calibration completed
  2182. */
  2183. rt1011->cali_done = 0;
  2184. /* initial */
  2185. rt1011_reg_init(component);
  2186. /* Apply temperature and calibration data from device property */
  2187. if (rt1011->temperature_calib <= 0xff &&
  2188. rt1011->temperature_calib > 0) {
  2189. snd_soc_component_update_bits(component,
  2190. RT1011_STP_INITIAL_RESISTANCE_TEMP, 0x3ff,
  2191. (rt1011->temperature_calib << 2));
  2192. }
  2193. if (rt1011->r0_calib) {
  2194. rt1011->r0_reg = rt1011->r0_calib;
  2195. format = 2147483648U; /* 2^24 * 128 */
  2196. r0_integer = format / rt1011->r0_reg / 128;
  2197. r0_factor = ((format / rt1011->r0_reg * 100) / 128)
  2198. - (r0_integer * 100);
  2199. dev_info(component->dev, "DP r0 resistance about %d.%02d ohm, reg=0x%X\n",
  2200. r0_integer, r0_factor, rt1011->r0_reg);
  2201. rt1011_r0_load(rt1011);
  2202. }
  2203. snd_soc_component_write(component, RT1011_ADC_SET_1, 0x2925);
  2204. }
  2205. static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev)
  2206. {
  2207. device_property_read_u32(dev, "realtek,temperature_calib",
  2208. &rt1011->temperature_calib);
  2209. device_property_read_u32(dev, "realtek,r0_calib",
  2210. &rt1011->r0_calib);
  2211. dev_dbg(dev, "%s: r0_calib: 0x%x, temperature_calib: 0x%x",
  2212. __func__, rt1011->r0_calib, rt1011->temperature_calib);
  2213. return 0;
  2214. }
  2215. static int rt1011_i2c_probe(struct i2c_client *i2c)
  2216. {
  2217. struct rt1011_priv *rt1011;
  2218. int ret;
  2219. unsigned int val;
  2220. rt1011 = devm_kzalloc(&i2c->dev, sizeof(struct rt1011_priv),
  2221. GFP_KERNEL);
  2222. if (!rt1011)
  2223. return -ENOMEM;
  2224. i2c_set_clientdata(i2c, rt1011);
  2225. rt1011_parse_dp(rt1011, &i2c->dev);
  2226. rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap);
  2227. if (IS_ERR(rt1011->regmap)) {
  2228. ret = PTR_ERR(rt1011->regmap);
  2229. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  2230. ret);
  2231. return ret;
  2232. }
  2233. regmap_read(rt1011->regmap, RT1011_DEVICE_ID, &val);
  2234. if (val != RT1011_DEVICE_ID_NUM) {
  2235. dev_err(&i2c->dev,
  2236. "Device with ID register %x is not rt1011\n", val);
  2237. return -ENODEV;
  2238. }
  2239. INIT_WORK(&rt1011->cali_work, rt1011_calibration_work);
  2240. return devm_snd_soc_register_component(&i2c->dev,
  2241. &soc_component_dev_rt1011,
  2242. rt1011_dai, ARRAY_SIZE(rt1011_dai));
  2243. }
  2244. static void rt1011_i2c_shutdown(struct i2c_client *client)
  2245. {
  2246. struct rt1011_priv *rt1011 = i2c_get_clientdata(client);
  2247. rt1011_reset(rt1011->regmap);
  2248. }
  2249. static struct i2c_driver rt1011_i2c_driver = {
  2250. .driver = {
  2251. .name = "rt1011",
  2252. .of_match_table = of_match_ptr(rt1011_of_match),
  2253. .acpi_match_table = ACPI_PTR(rt1011_acpi_match)
  2254. },
  2255. .probe_new = rt1011_i2c_probe,
  2256. .shutdown = rt1011_i2c_shutdown,
  2257. .id_table = rt1011_i2c_id,
  2258. };
  2259. module_i2c_driver(rt1011_i2c_driver);
  2260. MODULE_DESCRIPTION("ASoC RT1011 amplifier driver");
  2261. MODULE_AUTHOR("Shuming Fan <[email protected]>");
  2262. MODULE_LICENSE("GPL");