cthw20k2.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134
  1. /**
  2. * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
  3. *
  4. * This source file is released under GPL v2 license (no other versions).
  5. * See the COPYING file included in the main directory of this source
  6. * distribution for the license terms and conditions.
  7. *
  8. * @File cthw20k2.c
  9. *
  10. * @Brief
  11. * This file contains the implementation of hardware access methord for 20k2.
  12. *
  13. * @Author Liu Chun
  14. * @Date May 14 2008
  15. *
  16. */
  17. #include "cthw20k2.h"
  18. #include "ct20k2reg.h"
  19. #include <linux/types.h>
  20. #include <linux/slab.h>
  21. #include <linux/pci.h>
  22. #include <linux/io.h>
  23. #include <linux/string.h>
  24. #include <linux/kernel.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #define CT_XFI_DMA_MASK DMA_BIT_MASK(32) /* 32 bits */
  28. static u32 hw_read_20kx(struct hw *hw, u32 reg);
  29. static void hw_write_20kx(struct hw *hw, u32 reg, u32 data);
  30. /*
  31. * Type definition block.
  32. * The layout of control structures can be directly applied on 20k2 chip.
  33. */
  34. /*
  35. * SRC control block definitions.
  36. */
  37. /* SRC resource control block */
  38. #define SRCCTL_STATE 0x00000007
  39. #define SRCCTL_BM 0x00000008
  40. #define SRCCTL_RSR 0x00000030
  41. #define SRCCTL_SF 0x000001C0
  42. #define SRCCTL_WR 0x00000200
  43. #define SRCCTL_PM 0x00000400
  44. #define SRCCTL_ROM 0x00001800
  45. #define SRCCTL_VO 0x00002000
  46. #define SRCCTL_ST 0x00004000
  47. #define SRCCTL_IE 0x00008000
  48. #define SRCCTL_ILSZ 0x000F0000
  49. #define SRCCTL_BP 0x00100000
  50. #define SRCCCR_CISZ 0x000007FF
  51. #define SRCCCR_CWA 0x001FF800
  52. #define SRCCCR_D 0x00200000
  53. #define SRCCCR_RS 0x01C00000
  54. #define SRCCCR_NAL 0x3E000000
  55. #define SRCCCR_RA 0xC0000000
  56. #define SRCCA_CA 0x0FFFFFFF
  57. #define SRCCA_RS 0xE0000000
  58. #define SRCSA_SA 0x0FFFFFFF
  59. #define SRCLA_LA 0x0FFFFFFF
  60. /* Mixer Parameter Ring ram Low and Hight register.
  61. * Fixed-point value in 8.24 format for parameter channel */
  62. #define MPRLH_PITCH 0xFFFFFFFF
  63. /* SRC resource register dirty flags */
  64. union src_dirty {
  65. struct {
  66. u16 ctl:1;
  67. u16 ccr:1;
  68. u16 sa:1;
  69. u16 la:1;
  70. u16 ca:1;
  71. u16 mpr:1;
  72. u16 czbfs:1; /* Clear Z-Buffers */
  73. u16 rsv:9;
  74. } bf;
  75. u16 data;
  76. };
  77. struct src_rsc_ctrl_blk {
  78. unsigned int ctl;
  79. unsigned int ccr;
  80. unsigned int ca;
  81. unsigned int sa;
  82. unsigned int la;
  83. unsigned int mpr;
  84. union src_dirty dirty;
  85. };
  86. /* SRC manager control block */
  87. union src_mgr_dirty {
  88. struct {
  89. u16 enb0:1;
  90. u16 enb1:1;
  91. u16 enb2:1;
  92. u16 enb3:1;
  93. u16 enb4:1;
  94. u16 enb5:1;
  95. u16 enb6:1;
  96. u16 enb7:1;
  97. u16 enbsa:1;
  98. u16 rsv:7;
  99. } bf;
  100. u16 data;
  101. };
  102. struct src_mgr_ctrl_blk {
  103. unsigned int enbsa;
  104. unsigned int enb[8];
  105. union src_mgr_dirty dirty;
  106. };
  107. /* SRCIMP manager control block */
  108. #define SRCAIM_ARC 0x00000FFF
  109. #define SRCAIM_NXT 0x00FF0000
  110. #define SRCAIM_SRC 0xFF000000
  111. struct srcimap {
  112. unsigned int srcaim;
  113. unsigned int idx;
  114. };
  115. /* SRCIMP manager register dirty flags */
  116. union srcimp_mgr_dirty {
  117. struct {
  118. u16 srcimap:1;
  119. u16 rsv:15;
  120. } bf;
  121. u16 data;
  122. };
  123. struct srcimp_mgr_ctrl_blk {
  124. struct srcimap srcimap;
  125. union srcimp_mgr_dirty dirty;
  126. };
  127. /*
  128. * Function implementation block.
  129. */
  130. static int src_get_rsc_ctrl_blk(void **rblk)
  131. {
  132. struct src_rsc_ctrl_blk *blk;
  133. *rblk = NULL;
  134. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  135. if (NULL == blk)
  136. return -ENOMEM;
  137. *rblk = blk;
  138. return 0;
  139. }
  140. static int src_put_rsc_ctrl_blk(void *blk)
  141. {
  142. kfree((struct src_rsc_ctrl_blk *)blk);
  143. return 0;
  144. }
  145. static int src_set_state(void *blk, unsigned int state)
  146. {
  147. struct src_rsc_ctrl_blk *ctl = blk;
  148. set_field(&ctl->ctl, SRCCTL_STATE, state);
  149. ctl->dirty.bf.ctl = 1;
  150. return 0;
  151. }
  152. static int src_set_bm(void *blk, unsigned int bm)
  153. {
  154. struct src_rsc_ctrl_blk *ctl = blk;
  155. set_field(&ctl->ctl, SRCCTL_BM, bm);
  156. ctl->dirty.bf.ctl = 1;
  157. return 0;
  158. }
  159. static int src_set_rsr(void *blk, unsigned int rsr)
  160. {
  161. struct src_rsc_ctrl_blk *ctl = blk;
  162. set_field(&ctl->ctl, SRCCTL_RSR, rsr);
  163. ctl->dirty.bf.ctl = 1;
  164. return 0;
  165. }
  166. static int src_set_sf(void *blk, unsigned int sf)
  167. {
  168. struct src_rsc_ctrl_blk *ctl = blk;
  169. set_field(&ctl->ctl, SRCCTL_SF, sf);
  170. ctl->dirty.bf.ctl = 1;
  171. return 0;
  172. }
  173. static int src_set_wr(void *blk, unsigned int wr)
  174. {
  175. struct src_rsc_ctrl_blk *ctl = blk;
  176. set_field(&ctl->ctl, SRCCTL_WR, wr);
  177. ctl->dirty.bf.ctl = 1;
  178. return 0;
  179. }
  180. static int src_set_pm(void *blk, unsigned int pm)
  181. {
  182. struct src_rsc_ctrl_blk *ctl = blk;
  183. set_field(&ctl->ctl, SRCCTL_PM, pm);
  184. ctl->dirty.bf.ctl = 1;
  185. return 0;
  186. }
  187. static int src_set_rom(void *blk, unsigned int rom)
  188. {
  189. struct src_rsc_ctrl_blk *ctl = blk;
  190. set_field(&ctl->ctl, SRCCTL_ROM, rom);
  191. ctl->dirty.bf.ctl = 1;
  192. return 0;
  193. }
  194. static int src_set_vo(void *blk, unsigned int vo)
  195. {
  196. struct src_rsc_ctrl_blk *ctl = blk;
  197. set_field(&ctl->ctl, SRCCTL_VO, vo);
  198. ctl->dirty.bf.ctl = 1;
  199. return 0;
  200. }
  201. static int src_set_st(void *blk, unsigned int st)
  202. {
  203. struct src_rsc_ctrl_blk *ctl = blk;
  204. set_field(&ctl->ctl, SRCCTL_ST, st);
  205. ctl->dirty.bf.ctl = 1;
  206. return 0;
  207. }
  208. static int src_set_ie(void *blk, unsigned int ie)
  209. {
  210. struct src_rsc_ctrl_blk *ctl = blk;
  211. set_field(&ctl->ctl, SRCCTL_IE, ie);
  212. ctl->dirty.bf.ctl = 1;
  213. return 0;
  214. }
  215. static int src_set_ilsz(void *blk, unsigned int ilsz)
  216. {
  217. struct src_rsc_ctrl_blk *ctl = blk;
  218. set_field(&ctl->ctl, SRCCTL_ILSZ, ilsz);
  219. ctl->dirty.bf.ctl = 1;
  220. return 0;
  221. }
  222. static int src_set_bp(void *blk, unsigned int bp)
  223. {
  224. struct src_rsc_ctrl_blk *ctl = blk;
  225. set_field(&ctl->ctl, SRCCTL_BP, bp);
  226. ctl->dirty.bf.ctl = 1;
  227. return 0;
  228. }
  229. static int src_set_cisz(void *blk, unsigned int cisz)
  230. {
  231. struct src_rsc_ctrl_blk *ctl = blk;
  232. set_field(&ctl->ccr, SRCCCR_CISZ, cisz);
  233. ctl->dirty.bf.ccr = 1;
  234. return 0;
  235. }
  236. static int src_set_ca(void *blk, unsigned int ca)
  237. {
  238. struct src_rsc_ctrl_blk *ctl = blk;
  239. set_field(&ctl->ca, SRCCA_CA, ca);
  240. ctl->dirty.bf.ca = 1;
  241. return 0;
  242. }
  243. static int src_set_sa(void *blk, unsigned int sa)
  244. {
  245. struct src_rsc_ctrl_blk *ctl = blk;
  246. set_field(&ctl->sa, SRCSA_SA, sa);
  247. ctl->dirty.bf.sa = 1;
  248. return 0;
  249. }
  250. static int src_set_la(void *blk, unsigned int la)
  251. {
  252. struct src_rsc_ctrl_blk *ctl = blk;
  253. set_field(&ctl->la, SRCLA_LA, la);
  254. ctl->dirty.bf.la = 1;
  255. return 0;
  256. }
  257. static int src_set_pitch(void *blk, unsigned int pitch)
  258. {
  259. struct src_rsc_ctrl_blk *ctl = blk;
  260. set_field(&ctl->mpr, MPRLH_PITCH, pitch);
  261. ctl->dirty.bf.mpr = 1;
  262. return 0;
  263. }
  264. static int src_set_clear_zbufs(void *blk, unsigned int clear)
  265. {
  266. ((struct src_rsc_ctrl_blk *)blk)->dirty.bf.czbfs = (clear ? 1 : 0);
  267. return 0;
  268. }
  269. static int src_set_dirty(void *blk, unsigned int flags)
  270. {
  271. ((struct src_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff);
  272. return 0;
  273. }
  274. static int src_set_dirty_all(void *blk)
  275. {
  276. ((struct src_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0);
  277. return 0;
  278. }
  279. #define AR_SLOT_SIZE 4096
  280. #define AR_SLOT_BLOCK_SIZE 16
  281. #define AR_PTS_PITCH 6
  282. #define AR_PARAM_SRC_OFFSET 0x60
  283. static unsigned int src_param_pitch_mixer(unsigned int src_idx)
  284. {
  285. return ((src_idx << 4) + AR_PTS_PITCH + AR_SLOT_SIZE
  286. - AR_PARAM_SRC_OFFSET) % AR_SLOT_SIZE;
  287. }
  288. static int src_commit_write(struct hw *hw, unsigned int idx, void *blk)
  289. {
  290. struct src_rsc_ctrl_blk *ctl = blk;
  291. int i = 0;
  292. if (ctl->dirty.bf.czbfs) {
  293. /* Clear Z-Buffer registers */
  294. for (i = 0; i < 8; i++)
  295. hw_write_20kx(hw, SRC_UPZ+idx*0x100+i*0x4, 0);
  296. for (i = 0; i < 4; i++)
  297. hw_write_20kx(hw, SRC_DN0Z+idx*0x100+i*0x4, 0);
  298. for (i = 0; i < 8; i++)
  299. hw_write_20kx(hw, SRC_DN1Z+idx*0x100+i*0x4, 0);
  300. ctl->dirty.bf.czbfs = 0;
  301. }
  302. if (ctl->dirty.bf.mpr) {
  303. /* Take the parameter mixer resource in the same group as that
  304. * the idx src is in for simplicity. Unlike src, all conjugate
  305. * parameter mixer resources must be programmed for
  306. * corresponding conjugate src resources. */
  307. unsigned int pm_idx = src_param_pitch_mixer(idx);
  308. hw_write_20kx(hw, MIXER_PRING_LO_HI+4*pm_idx, ctl->mpr);
  309. hw_write_20kx(hw, MIXER_PMOPLO+8*pm_idx, 0x3);
  310. hw_write_20kx(hw, MIXER_PMOPHI+8*pm_idx, 0x0);
  311. ctl->dirty.bf.mpr = 0;
  312. }
  313. if (ctl->dirty.bf.sa) {
  314. hw_write_20kx(hw, SRC_SA+idx*0x100, ctl->sa);
  315. ctl->dirty.bf.sa = 0;
  316. }
  317. if (ctl->dirty.bf.la) {
  318. hw_write_20kx(hw, SRC_LA+idx*0x100, ctl->la);
  319. ctl->dirty.bf.la = 0;
  320. }
  321. if (ctl->dirty.bf.ca) {
  322. hw_write_20kx(hw, SRC_CA+idx*0x100, ctl->ca);
  323. ctl->dirty.bf.ca = 0;
  324. }
  325. /* Write srccf register */
  326. hw_write_20kx(hw, SRC_CF+idx*0x100, 0x0);
  327. if (ctl->dirty.bf.ccr) {
  328. hw_write_20kx(hw, SRC_CCR+idx*0x100, ctl->ccr);
  329. ctl->dirty.bf.ccr = 0;
  330. }
  331. if (ctl->dirty.bf.ctl) {
  332. hw_write_20kx(hw, SRC_CTL+idx*0x100, ctl->ctl);
  333. ctl->dirty.bf.ctl = 0;
  334. }
  335. return 0;
  336. }
  337. static int src_get_ca(struct hw *hw, unsigned int idx, void *blk)
  338. {
  339. struct src_rsc_ctrl_blk *ctl = blk;
  340. ctl->ca = hw_read_20kx(hw, SRC_CA+idx*0x100);
  341. ctl->dirty.bf.ca = 0;
  342. return get_field(ctl->ca, SRCCA_CA);
  343. }
  344. static unsigned int src_get_dirty(void *blk)
  345. {
  346. return ((struct src_rsc_ctrl_blk *)blk)->dirty.data;
  347. }
  348. static unsigned int src_dirty_conj_mask(void)
  349. {
  350. return 0x20;
  351. }
  352. static int src_mgr_enbs_src(void *blk, unsigned int idx)
  353. {
  354. ((struct src_mgr_ctrl_blk *)blk)->enbsa |= (0x1 << ((idx%128)/4));
  355. ((struct src_mgr_ctrl_blk *)blk)->dirty.bf.enbsa = 1;
  356. ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32));
  357. return 0;
  358. }
  359. static int src_mgr_enb_src(void *blk, unsigned int idx)
  360. {
  361. ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32));
  362. ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32));
  363. return 0;
  364. }
  365. static int src_mgr_dsb_src(void *blk, unsigned int idx)
  366. {
  367. ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] &= ~(0x1 << (idx%32));
  368. ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32));
  369. return 0;
  370. }
  371. static int src_mgr_commit_write(struct hw *hw, void *blk)
  372. {
  373. struct src_mgr_ctrl_blk *ctl = blk;
  374. int i = 0;
  375. unsigned int ret = 0;
  376. if (ctl->dirty.bf.enbsa) {
  377. do {
  378. ret = hw_read_20kx(hw, SRC_ENBSTAT);
  379. } while (ret & 0x1);
  380. hw_write_20kx(hw, SRC_ENBSA, ctl->enbsa);
  381. ctl->dirty.bf.enbsa = 0;
  382. }
  383. for (i = 0; i < 8; i++) {
  384. if ((ctl->dirty.data & (0x1 << i))) {
  385. hw_write_20kx(hw, SRC_ENB+(i*0x100), ctl->enb[i]);
  386. ctl->dirty.data &= ~(0x1 << i);
  387. }
  388. }
  389. return 0;
  390. }
  391. static int src_mgr_get_ctrl_blk(void **rblk)
  392. {
  393. struct src_mgr_ctrl_blk *blk;
  394. *rblk = NULL;
  395. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  396. if (NULL == blk)
  397. return -ENOMEM;
  398. *rblk = blk;
  399. return 0;
  400. }
  401. static int src_mgr_put_ctrl_blk(void *blk)
  402. {
  403. kfree((struct src_mgr_ctrl_blk *)blk);
  404. return 0;
  405. }
  406. static int srcimp_mgr_get_ctrl_blk(void **rblk)
  407. {
  408. struct srcimp_mgr_ctrl_blk *blk;
  409. *rblk = NULL;
  410. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  411. if (NULL == blk)
  412. return -ENOMEM;
  413. *rblk = blk;
  414. return 0;
  415. }
  416. static int srcimp_mgr_put_ctrl_blk(void *blk)
  417. {
  418. kfree((struct srcimp_mgr_ctrl_blk *)blk);
  419. return 0;
  420. }
  421. static int srcimp_mgr_set_imaparc(void *blk, unsigned int slot)
  422. {
  423. struct srcimp_mgr_ctrl_blk *ctl = blk;
  424. set_field(&ctl->srcimap.srcaim, SRCAIM_ARC, slot);
  425. ctl->dirty.bf.srcimap = 1;
  426. return 0;
  427. }
  428. static int srcimp_mgr_set_imapuser(void *blk, unsigned int user)
  429. {
  430. struct srcimp_mgr_ctrl_blk *ctl = blk;
  431. set_field(&ctl->srcimap.srcaim, SRCAIM_SRC, user);
  432. ctl->dirty.bf.srcimap = 1;
  433. return 0;
  434. }
  435. static int srcimp_mgr_set_imapnxt(void *blk, unsigned int next)
  436. {
  437. struct srcimp_mgr_ctrl_blk *ctl = blk;
  438. set_field(&ctl->srcimap.srcaim, SRCAIM_NXT, next);
  439. ctl->dirty.bf.srcimap = 1;
  440. return 0;
  441. }
  442. static int srcimp_mgr_set_imapaddr(void *blk, unsigned int addr)
  443. {
  444. ((struct srcimp_mgr_ctrl_blk *)blk)->srcimap.idx = addr;
  445. ((struct srcimp_mgr_ctrl_blk *)blk)->dirty.bf.srcimap = 1;
  446. return 0;
  447. }
  448. static int srcimp_mgr_commit_write(struct hw *hw, void *blk)
  449. {
  450. struct srcimp_mgr_ctrl_blk *ctl = blk;
  451. if (ctl->dirty.bf.srcimap) {
  452. hw_write_20kx(hw, SRC_IMAP+ctl->srcimap.idx*0x100,
  453. ctl->srcimap.srcaim);
  454. ctl->dirty.bf.srcimap = 0;
  455. }
  456. return 0;
  457. }
  458. /*
  459. * AMIXER control block definitions.
  460. */
  461. #define AMOPLO_M 0x00000003
  462. #define AMOPLO_IV 0x00000004
  463. #define AMOPLO_X 0x0003FFF0
  464. #define AMOPLO_Y 0xFFFC0000
  465. #define AMOPHI_SADR 0x000000FF
  466. #define AMOPHI_SE 0x80000000
  467. /* AMIXER resource register dirty flags */
  468. union amixer_dirty {
  469. struct {
  470. u16 amoplo:1;
  471. u16 amophi:1;
  472. u16 rsv:14;
  473. } bf;
  474. u16 data;
  475. };
  476. /* AMIXER resource control block */
  477. struct amixer_rsc_ctrl_blk {
  478. unsigned int amoplo;
  479. unsigned int amophi;
  480. union amixer_dirty dirty;
  481. };
  482. static int amixer_set_mode(void *blk, unsigned int mode)
  483. {
  484. struct amixer_rsc_ctrl_blk *ctl = blk;
  485. set_field(&ctl->amoplo, AMOPLO_M, mode);
  486. ctl->dirty.bf.amoplo = 1;
  487. return 0;
  488. }
  489. static int amixer_set_iv(void *blk, unsigned int iv)
  490. {
  491. struct amixer_rsc_ctrl_blk *ctl = blk;
  492. set_field(&ctl->amoplo, AMOPLO_IV, iv);
  493. ctl->dirty.bf.amoplo = 1;
  494. return 0;
  495. }
  496. static int amixer_set_x(void *blk, unsigned int x)
  497. {
  498. struct amixer_rsc_ctrl_blk *ctl = blk;
  499. set_field(&ctl->amoplo, AMOPLO_X, x);
  500. ctl->dirty.bf.amoplo = 1;
  501. return 0;
  502. }
  503. static int amixer_set_y(void *blk, unsigned int y)
  504. {
  505. struct amixer_rsc_ctrl_blk *ctl = blk;
  506. set_field(&ctl->amoplo, AMOPLO_Y, y);
  507. ctl->dirty.bf.amoplo = 1;
  508. return 0;
  509. }
  510. static int amixer_set_sadr(void *blk, unsigned int sadr)
  511. {
  512. struct amixer_rsc_ctrl_blk *ctl = blk;
  513. set_field(&ctl->amophi, AMOPHI_SADR, sadr);
  514. ctl->dirty.bf.amophi = 1;
  515. return 0;
  516. }
  517. static int amixer_set_se(void *blk, unsigned int se)
  518. {
  519. struct amixer_rsc_ctrl_blk *ctl = blk;
  520. set_field(&ctl->amophi, AMOPHI_SE, se);
  521. ctl->dirty.bf.amophi = 1;
  522. return 0;
  523. }
  524. static int amixer_set_dirty(void *blk, unsigned int flags)
  525. {
  526. ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff);
  527. return 0;
  528. }
  529. static int amixer_set_dirty_all(void *blk)
  530. {
  531. ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0);
  532. return 0;
  533. }
  534. static int amixer_commit_write(struct hw *hw, unsigned int idx, void *blk)
  535. {
  536. struct amixer_rsc_ctrl_blk *ctl = blk;
  537. if (ctl->dirty.bf.amoplo || ctl->dirty.bf.amophi) {
  538. hw_write_20kx(hw, MIXER_AMOPLO+idx*8, ctl->amoplo);
  539. ctl->dirty.bf.amoplo = 0;
  540. hw_write_20kx(hw, MIXER_AMOPHI+idx*8, ctl->amophi);
  541. ctl->dirty.bf.amophi = 0;
  542. }
  543. return 0;
  544. }
  545. static int amixer_get_y(void *blk)
  546. {
  547. struct amixer_rsc_ctrl_blk *ctl = blk;
  548. return get_field(ctl->amoplo, AMOPLO_Y);
  549. }
  550. static unsigned int amixer_get_dirty(void *blk)
  551. {
  552. return ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data;
  553. }
  554. static int amixer_rsc_get_ctrl_blk(void **rblk)
  555. {
  556. struct amixer_rsc_ctrl_blk *blk;
  557. *rblk = NULL;
  558. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  559. if (NULL == blk)
  560. return -ENOMEM;
  561. *rblk = blk;
  562. return 0;
  563. }
  564. static int amixer_rsc_put_ctrl_blk(void *blk)
  565. {
  566. kfree((struct amixer_rsc_ctrl_blk *)blk);
  567. return 0;
  568. }
  569. static int amixer_mgr_get_ctrl_blk(void **rblk)
  570. {
  571. *rblk = NULL;
  572. return 0;
  573. }
  574. static int amixer_mgr_put_ctrl_blk(void *blk)
  575. {
  576. return 0;
  577. }
  578. /*
  579. * DAIO control block definitions.
  580. */
  581. /* Receiver Sample Rate Tracker Control register */
  582. #define SRTCTL_SRCO 0x000000FF
  583. #define SRTCTL_SRCM 0x0000FF00
  584. #define SRTCTL_RSR 0x00030000
  585. #define SRTCTL_DRAT 0x00300000
  586. #define SRTCTL_EC 0x01000000
  587. #define SRTCTL_ET 0x10000000
  588. /* DAIO Receiver register dirty flags */
  589. union dai_dirty {
  590. struct {
  591. u16 srt:1;
  592. u16 rsv:15;
  593. } bf;
  594. u16 data;
  595. };
  596. /* DAIO Receiver control block */
  597. struct dai_ctrl_blk {
  598. unsigned int srt;
  599. union dai_dirty dirty;
  600. };
  601. /* Audio Input Mapper RAM */
  602. #define AIM_ARC 0x00000FFF
  603. #define AIM_NXT 0x007F0000
  604. struct daoimap {
  605. unsigned int aim;
  606. unsigned int idx;
  607. };
  608. /* Audio Transmitter Control and Status register */
  609. #define ATXCTL_EN 0x00000001
  610. #define ATXCTL_MODE 0x00000010
  611. #define ATXCTL_CD 0x00000020
  612. #define ATXCTL_RAW 0x00000100
  613. #define ATXCTL_MT 0x00000200
  614. #define ATXCTL_NUC 0x00003000
  615. #define ATXCTL_BEN 0x00010000
  616. #define ATXCTL_BMUX 0x00700000
  617. #define ATXCTL_B24 0x01000000
  618. #define ATXCTL_CPF 0x02000000
  619. #define ATXCTL_RIV 0x10000000
  620. #define ATXCTL_LIV 0x20000000
  621. #define ATXCTL_RSAT 0x40000000
  622. #define ATXCTL_LSAT 0x80000000
  623. /* XDIF Transmitter register dirty flags */
  624. union dao_dirty {
  625. struct {
  626. u16 atxcsl:1;
  627. u16 rsv:15;
  628. } bf;
  629. u16 data;
  630. };
  631. /* XDIF Transmitter control block */
  632. struct dao_ctrl_blk {
  633. /* XDIF Transmitter Channel Status Low Register */
  634. unsigned int atxcsl;
  635. union dao_dirty dirty;
  636. };
  637. /* Audio Receiver Control register */
  638. #define ARXCTL_EN 0x00000001
  639. /* DAIO manager register dirty flags */
  640. union daio_mgr_dirty {
  641. struct {
  642. u32 atxctl:8;
  643. u32 arxctl:8;
  644. u32 daoimap:1;
  645. u32 rsv:15;
  646. } bf;
  647. u32 data;
  648. };
  649. /* DAIO manager control block */
  650. struct daio_mgr_ctrl_blk {
  651. struct daoimap daoimap;
  652. unsigned int txctl[8];
  653. unsigned int rxctl[8];
  654. union daio_mgr_dirty dirty;
  655. };
  656. static int dai_srt_set_srco(void *blk, unsigned int src)
  657. {
  658. struct dai_ctrl_blk *ctl = blk;
  659. set_field(&ctl->srt, SRTCTL_SRCO, src);
  660. ctl->dirty.bf.srt = 1;
  661. return 0;
  662. }
  663. static int dai_srt_set_srcm(void *blk, unsigned int src)
  664. {
  665. struct dai_ctrl_blk *ctl = blk;
  666. set_field(&ctl->srt, SRTCTL_SRCM, src);
  667. ctl->dirty.bf.srt = 1;
  668. return 0;
  669. }
  670. static int dai_srt_set_rsr(void *blk, unsigned int rsr)
  671. {
  672. struct dai_ctrl_blk *ctl = blk;
  673. set_field(&ctl->srt, SRTCTL_RSR, rsr);
  674. ctl->dirty.bf.srt = 1;
  675. return 0;
  676. }
  677. static int dai_srt_set_drat(void *blk, unsigned int drat)
  678. {
  679. struct dai_ctrl_blk *ctl = blk;
  680. set_field(&ctl->srt, SRTCTL_DRAT, drat);
  681. ctl->dirty.bf.srt = 1;
  682. return 0;
  683. }
  684. static int dai_srt_set_ec(void *blk, unsigned int ec)
  685. {
  686. struct dai_ctrl_blk *ctl = blk;
  687. set_field(&ctl->srt, SRTCTL_EC, ec ? 1 : 0);
  688. ctl->dirty.bf.srt = 1;
  689. return 0;
  690. }
  691. static int dai_srt_set_et(void *blk, unsigned int et)
  692. {
  693. struct dai_ctrl_blk *ctl = blk;
  694. set_field(&ctl->srt, SRTCTL_ET, et ? 1 : 0);
  695. ctl->dirty.bf.srt = 1;
  696. return 0;
  697. }
  698. static int dai_commit_write(struct hw *hw, unsigned int idx, void *blk)
  699. {
  700. struct dai_ctrl_blk *ctl = blk;
  701. if (ctl->dirty.bf.srt) {
  702. hw_write_20kx(hw, AUDIO_IO_RX_SRT_CTL+0x40*idx, ctl->srt);
  703. ctl->dirty.bf.srt = 0;
  704. }
  705. return 0;
  706. }
  707. static int dai_get_ctrl_blk(void **rblk)
  708. {
  709. struct dai_ctrl_blk *blk;
  710. *rblk = NULL;
  711. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  712. if (NULL == blk)
  713. return -ENOMEM;
  714. *rblk = blk;
  715. return 0;
  716. }
  717. static int dai_put_ctrl_blk(void *blk)
  718. {
  719. kfree((struct dai_ctrl_blk *)blk);
  720. return 0;
  721. }
  722. static int dao_set_spos(void *blk, unsigned int spos)
  723. {
  724. ((struct dao_ctrl_blk *)blk)->atxcsl = spos;
  725. ((struct dao_ctrl_blk *)blk)->dirty.bf.atxcsl = 1;
  726. return 0;
  727. }
  728. static int dao_commit_write(struct hw *hw, unsigned int idx, void *blk)
  729. {
  730. struct dao_ctrl_blk *ctl = blk;
  731. if (ctl->dirty.bf.atxcsl) {
  732. if (idx < 4) {
  733. /* S/PDIF SPOSx */
  734. hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+0x40*idx,
  735. ctl->atxcsl);
  736. }
  737. ctl->dirty.bf.atxcsl = 0;
  738. }
  739. return 0;
  740. }
  741. static int dao_get_spos(void *blk, unsigned int *spos)
  742. {
  743. *spos = ((struct dao_ctrl_blk *)blk)->atxcsl;
  744. return 0;
  745. }
  746. static int dao_get_ctrl_blk(void **rblk)
  747. {
  748. struct dao_ctrl_blk *blk;
  749. *rblk = NULL;
  750. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  751. if (NULL == blk)
  752. return -ENOMEM;
  753. *rblk = blk;
  754. return 0;
  755. }
  756. static int dao_put_ctrl_blk(void *blk)
  757. {
  758. kfree((struct dao_ctrl_blk *)blk);
  759. return 0;
  760. }
  761. static int daio_mgr_enb_dai(void *blk, unsigned int idx)
  762. {
  763. struct daio_mgr_ctrl_blk *ctl = blk;
  764. set_field(&ctl->rxctl[idx], ARXCTL_EN, 1);
  765. ctl->dirty.bf.arxctl |= (0x1 << idx);
  766. return 0;
  767. }
  768. static int daio_mgr_dsb_dai(void *blk, unsigned int idx)
  769. {
  770. struct daio_mgr_ctrl_blk *ctl = blk;
  771. set_field(&ctl->rxctl[idx], ARXCTL_EN, 0);
  772. ctl->dirty.bf.arxctl |= (0x1 << idx);
  773. return 0;
  774. }
  775. static int daio_mgr_enb_dao(void *blk, unsigned int idx)
  776. {
  777. struct daio_mgr_ctrl_blk *ctl = blk;
  778. set_field(&ctl->txctl[idx], ATXCTL_EN, 1);
  779. ctl->dirty.bf.atxctl |= (0x1 << idx);
  780. return 0;
  781. }
  782. static int daio_mgr_dsb_dao(void *blk, unsigned int idx)
  783. {
  784. struct daio_mgr_ctrl_blk *ctl = blk;
  785. set_field(&ctl->txctl[idx], ATXCTL_EN, 0);
  786. ctl->dirty.bf.atxctl |= (0x1 << idx);
  787. return 0;
  788. }
  789. static int daio_mgr_dao_init(void *blk, unsigned int idx, unsigned int conf)
  790. {
  791. struct daio_mgr_ctrl_blk *ctl = blk;
  792. if (idx < 4) {
  793. /* S/PDIF output */
  794. switch ((conf & 0x7)) {
  795. case 1:
  796. set_field(&ctl->txctl[idx], ATXCTL_NUC, 0);
  797. break;
  798. case 2:
  799. set_field(&ctl->txctl[idx], ATXCTL_NUC, 1);
  800. break;
  801. case 4:
  802. set_field(&ctl->txctl[idx], ATXCTL_NUC, 2);
  803. break;
  804. case 8:
  805. set_field(&ctl->txctl[idx], ATXCTL_NUC, 3);
  806. break;
  807. default:
  808. break;
  809. }
  810. /* CDIF */
  811. set_field(&ctl->txctl[idx], ATXCTL_CD, (!(conf & 0x7)));
  812. /* Non-audio */
  813. set_field(&ctl->txctl[idx], ATXCTL_LIV, (conf >> 4) & 0x1);
  814. /* Non-audio */
  815. set_field(&ctl->txctl[idx], ATXCTL_RIV, (conf >> 4) & 0x1);
  816. set_field(&ctl->txctl[idx], ATXCTL_RAW,
  817. ((conf >> 3) & 0x1) ? 0 : 0);
  818. ctl->dirty.bf.atxctl |= (0x1 << idx);
  819. } else {
  820. /* I2S output */
  821. /*idx %= 4; */
  822. }
  823. return 0;
  824. }
  825. static int daio_mgr_set_imaparc(void *blk, unsigned int slot)
  826. {
  827. struct daio_mgr_ctrl_blk *ctl = blk;
  828. set_field(&ctl->daoimap.aim, AIM_ARC, slot);
  829. ctl->dirty.bf.daoimap = 1;
  830. return 0;
  831. }
  832. static int daio_mgr_set_imapnxt(void *blk, unsigned int next)
  833. {
  834. struct daio_mgr_ctrl_blk *ctl = blk;
  835. set_field(&ctl->daoimap.aim, AIM_NXT, next);
  836. ctl->dirty.bf.daoimap = 1;
  837. return 0;
  838. }
  839. static int daio_mgr_set_imapaddr(void *blk, unsigned int addr)
  840. {
  841. ((struct daio_mgr_ctrl_blk *)blk)->daoimap.idx = addr;
  842. ((struct daio_mgr_ctrl_blk *)blk)->dirty.bf.daoimap = 1;
  843. return 0;
  844. }
  845. static int daio_mgr_commit_write(struct hw *hw, void *blk)
  846. {
  847. struct daio_mgr_ctrl_blk *ctl = blk;
  848. unsigned int data = 0;
  849. int i = 0;
  850. for (i = 0; i < 8; i++) {
  851. if ((ctl->dirty.bf.atxctl & (0x1 << i))) {
  852. data = ctl->txctl[i];
  853. hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), data);
  854. ctl->dirty.bf.atxctl &= ~(0x1 << i);
  855. mdelay(1);
  856. }
  857. if ((ctl->dirty.bf.arxctl & (0x1 << i))) {
  858. data = ctl->rxctl[i];
  859. hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), data);
  860. ctl->dirty.bf.arxctl &= ~(0x1 << i);
  861. mdelay(1);
  862. }
  863. }
  864. if (ctl->dirty.bf.daoimap) {
  865. hw_write_20kx(hw, AUDIO_IO_AIM+ctl->daoimap.idx*4,
  866. ctl->daoimap.aim);
  867. ctl->dirty.bf.daoimap = 0;
  868. }
  869. return 0;
  870. }
  871. static int daio_mgr_get_ctrl_blk(struct hw *hw, void **rblk)
  872. {
  873. struct daio_mgr_ctrl_blk *blk;
  874. int i = 0;
  875. *rblk = NULL;
  876. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  877. if (NULL == blk)
  878. return -ENOMEM;
  879. for (i = 0; i < 8; i++) {
  880. blk->txctl[i] = hw_read_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i));
  881. blk->rxctl[i] = hw_read_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i));
  882. }
  883. *rblk = blk;
  884. return 0;
  885. }
  886. static int daio_mgr_put_ctrl_blk(void *blk)
  887. {
  888. kfree((struct daio_mgr_ctrl_blk *)blk);
  889. return 0;
  890. }
  891. /* Card hardware initialization block */
  892. struct dac_conf {
  893. unsigned int msr; /* master sample rate in rsrs */
  894. };
  895. struct adc_conf {
  896. unsigned int msr; /* master sample rate in rsrs */
  897. unsigned char input; /* the input source of ADC */
  898. unsigned char mic20db; /* boost mic by 20db if input is microphone */
  899. };
  900. struct daio_conf {
  901. unsigned int msr; /* master sample rate in rsrs */
  902. };
  903. struct trn_conf {
  904. unsigned long vm_pgt_phys;
  905. };
  906. static int hw_daio_init(struct hw *hw, const struct daio_conf *info)
  907. {
  908. u32 dwData = 0;
  909. int i;
  910. /* Program I2S with proper sample rate and enable the correct I2S
  911. * channel. ED(0/8/16/24): Enable all I2S/I2X master clock output */
  912. if (1 == info->msr) {
  913. hw_write_20kx(hw, AUDIO_IO_MCLK, 0x01010101);
  914. hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x01010101);
  915. hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
  916. } else if (2 == info->msr) {
  917. hw_write_20kx(hw, AUDIO_IO_MCLK, 0x11111111);
  918. /* Specify all playing 96khz
  919. * EA [0] - Enabled
  920. * RTA [4:5] - 96kHz
  921. * EB [8] - Enabled
  922. * RTB [12:13] - 96kHz
  923. * EC [16] - Enabled
  924. * RTC [20:21] - 96kHz
  925. * ED [24] - Enabled
  926. * RTD [28:29] - 96kHz */
  927. hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x11111111);
  928. hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
  929. } else {
  930. printk(KERN_ALERT "ERROR!!! Invalid sampling rate!!!\n");
  931. return -EINVAL;
  932. }
  933. for (i = 0; i < 8; i++) {
  934. if (i <= 3) {
  935. /* 1st 3 channels are SPDIFs (SB0960) */
  936. if (i == 3)
  937. dwData = 0x1001001;
  938. else
  939. dwData = 0x1000001;
  940. hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), dwData);
  941. hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), dwData);
  942. /* Initialize the SPDIF Out Channel status registers.
  943. * The value specified here is based on the typical
  944. * values provided in the specification, namely: Clock
  945. * Accuracy of 1000ppm, Sample Rate of 48KHz,
  946. * unspecified source number, Generation status = 1,
  947. * Category code = 0x12 (Digital Signal Mixer),
  948. * Mode = 0, Emph = 0, Copy Permitted, AN = 0
  949. * (indicating that we're transmitting digital audio,
  950. * and the Professional Use bit is 0. */
  951. hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+(0x40*i),
  952. 0x02109204); /* Default to 48kHz */
  953. hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_H+(0x40*i), 0x0B);
  954. } else {
  955. /* Next 5 channels are I2S (SB0960) */
  956. dwData = 0x11;
  957. hw_write_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i), dwData);
  958. if (2 == info->msr) {
  959. /* Four channels per sample period */
  960. dwData |= 0x1000;
  961. }
  962. hw_write_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i), dwData);
  963. }
  964. }
  965. return 0;
  966. }
  967. /* TRANSPORT operations */
  968. static int hw_trn_init(struct hw *hw, const struct trn_conf *info)
  969. {
  970. u32 vmctl = 0, data = 0;
  971. unsigned long ptp_phys_low = 0, ptp_phys_high = 0;
  972. int i = 0;
  973. /* Set up device page table */
  974. if ((~0UL) == info->vm_pgt_phys) {
  975. printk(KERN_ALERT "Wrong device page table page address!!!\n");
  976. return -1;
  977. }
  978. vmctl = 0x80000C0F; /* 32-bit, 4k-size page */
  979. #if BITS_PER_LONG == 64
  980. ptp_phys_low = info->vm_pgt_phys & ((1UL<<32)-1);
  981. ptp_phys_high = (info->vm_pgt_phys>>32) & ((1UL<<32)-1);
  982. vmctl |= (3<<8);
  983. #elif BITS_PER_LONG == 32
  984. ptp_phys_low = info->vm_pgt_phys & (~0UL);
  985. ptp_phys_high = 0;
  986. #else
  987. # error "Unknown BITS_PER_LONG!"
  988. #endif
  989. #if PAGE_SIZE == 8192
  990. # error "Don't support 8k-page!"
  991. #endif
  992. /* Write page table physical address to all PTPAL registers */
  993. for (i = 0; i < 64; i++) {
  994. hw_write_20kx(hw, VMEM_PTPAL+(16*i), ptp_phys_low);
  995. hw_write_20kx(hw, VMEM_PTPAH+(16*i), ptp_phys_high);
  996. }
  997. /* Enable virtual memory transfer */
  998. hw_write_20kx(hw, VMEM_CTL, vmctl);
  999. /* Enable transport bus master and queueing of request */
  1000. hw_write_20kx(hw, TRANSPORT_CTL, 0x03);
  1001. hw_write_20kx(hw, TRANSPORT_INT, 0x200c01);
  1002. /* Enable transport ring */
  1003. data = hw_read_20kx(hw, TRANSPORT_ENB);
  1004. hw_write_20kx(hw, TRANSPORT_ENB, (data | 0x03));
  1005. return 0;
  1006. }
  1007. /* Card initialization */
  1008. #define GCTL_AIE 0x00000001
  1009. #define GCTL_UAA 0x00000002
  1010. #define GCTL_DPC 0x00000004
  1011. #define GCTL_DBP 0x00000008
  1012. #define GCTL_ABP 0x00000010
  1013. #define GCTL_TBP 0x00000020
  1014. #define GCTL_SBP 0x00000040
  1015. #define GCTL_FBP 0x00000080
  1016. #define GCTL_ME 0x00000100
  1017. #define GCTL_AID 0x00001000
  1018. #define PLLCTL_SRC 0x00000007
  1019. #define PLLCTL_SPE 0x00000008
  1020. #define PLLCTL_RD 0x000000F0
  1021. #define PLLCTL_FD 0x0001FF00
  1022. #define PLLCTL_OD 0x00060000
  1023. #define PLLCTL_B 0x00080000
  1024. #define PLLCTL_AS 0x00100000
  1025. #define PLLCTL_LF 0x03E00000
  1026. #define PLLCTL_SPS 0x1C000000
  1027. #define PLLCTL_AD 0x60000000
  1028. #define PLLSTAT_CCS 0x00000007
  1029. #define PLLSTAT_SPL 0x00000008
  1030. #define PLLSTAT_CRD 0x000000F0
  1031. #define PLLSTAT_CFD 0x0001FF00
  1032. #define PLLSTAT_SL 0x00020000
  1033. #define PLLSTAT_FAS 0x00040000
  1034. #define PLLSTAT_B 0x00080000
  1035. #define PLLSTAT_PD 0x00100000
  1036. #define PLLSTAT_OCA 0x00200000
  1037. #define PLLSTAT_NCA 0x00400000
  1038. static int hw_pll_init(struct hw *hw, unsigned int rsr)
  1039. {
  1040. unsigned int pllenb;
  1041. unsigned int pllctl;
  1042. unsigned int pllstat;
  1043. int i;
  1044. pllenb = 0xB;
  1045. hw_write_20kx(hw, PLL_ENB, pllenb);
  1046. pllctl = 0x20D00000;
  1047. set_field(&pllctl, PLLCTL_FD, 16 - 4);
  1048. hw_write_20kx(hw, PLL_CTL, pllctl);
  1049. mdelay(40);
  1050. pllctl = hw_read_20kx(hw, PLL_CTL);
  1051. set_field(&pllctl, PLLCTL_B, 0);
  1052. if (48000 == rsr) {
  1053. set_field(&pllctl, PLLCTL_FD, 16 - 2);
  1054. set_field(&pllctl, PLLCTL_RD, 1 - 1);
  1055. } else { /* 44100 */
  1056. set_field(&pllctl, PLLCTL_FD, 147 - 2);
  1057. set_field(&pllctl, PLLCTL_RD, 10 - 1);
  1058. }
  1059. hw_write_20kx(hw, PLL_CTL, pllctl);
  1060. mdelay(40);
  1061. for (i = 0; i < 1000; i++) {
  1062. pllstat = hw_read_20kx(hw, PLL_STAT);
  1063. if (get_field(pllstat, PLLSTAT_PD))
  1064. continue;
  1065. if (get_field(pllstat, PLLSTAT_B) !=
  1066. get_field(pllctl, PLLCTL_B))
  1067. continue;
  1068. if (get_field(pllstat, PLLSTAT_CCS) !=
  1069. get_field(pllctl, PLLCTL_SRC))
  1070. continue;
  1071. if (get_field(pllstat, PLLSTAT_CRD) !=
  1072. get_field(pllctl, PLLCTL_RD))
  1073. continue;
  1074. if (get_field(pllstat, PLLSTAT_CFD) !=
  1075. get_field(pllctl, PLLCTL_FD))
  1076. continue;
  1077. break;
  1078. }
  1079. if (i >= 1000) {
  1080. printk(KERN_ALERT "PLL initialization failed!!!\n");
  1081. return -EBUSY;
  1082. }
  1083. return 0;
  1084. }
  1085. static int hw_auto_init(struct hw *hw)
  1086. {
  1087. unsigned int gctl;
  1088. int i;
  1089. gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
  1090. set_field(&gctl, GCTL_AIE, 0);
  1091. hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
  1092. set_field(&gctl, GCTL_AIE, 1);
  1093. hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
  1094. mdelay(10);
  1095. for (i = 0; i < 400000; i++) {
  1096. gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
  1097. if (get_field(gctl, GCTL_AID))
  1098. break;
  1099. }
  1100. if (!get_field(gctl, GCTL_AID)) {
  1101. printk(KERN_ALERT "Card Auto-init failed!!!\n");
  1102. return -EBUSY;
  1103. }
  1104. return 0;
  1105. }
  1106. /* DAC operations */
  1107. #define CS4382_MC1 0x1
  1108. #define CS4382_MC2 0x2
  1109. #define CS4382_MC3 0x3
  1110. #define CS4382_FC 0x4
  1111. #define CS4382_IC 0x5
  1112. #define CS4382_XC1 0x6
  1113. #define CS4382_VCA1 0x7
  1114. #define CS4382_VCB1 0x8
  1115. #define CS4382_XC2 0x9
  1116. #define CS4382_VCA2 0xA
  1117. #define CS4382_VCB2 0xB
  1118. #define CS4382_XC3 0xC
  1119. #define CS4382_VCA3 0xD
  1120. #define CS4382_VCB3 0xE
  1121. #define CS4382_XC4 0xF
  1122. #define CS4382_VCA4 0x10
  1123. #define CS4382_VCB4 0x11
  1124. #define CS4382_CREV 0x12
  1125. /* I2C status */
  1126. #define STATE_LOCKED 0x00
  1127. #define STATE_UNLOCKED 0xAA
  1128. #define DATA_READY 0x800000 /* Used with I2C_IF_STATUS */
  1129. #define DATA_ABORT 0x10000 /* Used with I2C_IF_STATUS */
  1130. #define I2C_STATUS_DCM 0x00000001
  1131. #define I2C_STATUS_BC 0x00000006
  1132. #define I2C_STATUS_APD 0x00000008
  1133. #define I2C_STATUS_AB 0x00010000
  1134. #define I2C_STATUS_DR 0x00800000
  1135. #define I2C_ADDRESS_PTAD 0x0000FFFF
  1136. #define I2C_ADDRESS_SLAD 0x007F0000
  1137. struct REGS_CS4382 {
  1138. u32 dwModeControl_1;
  1139. u32 dwModeControl_2;
  1140. u32 dwModeControl_3;
  1141. u32 dwFilterControl;
  1142. u32 dwInvertControl;
  1143. u32 dwMixControl_P1;
  1144. u32 dwVolControl_A1;
  1145. u32 dwVolControl_B1;
  1146. u32 dwMixControl_P2;
  1147. u32 dwVolControl_A2;
  1148. u32 dwVolControl_B2;
  1149. u32 dwMixControl_P3;
  1150. u32 dwVolControl_A3;
  1151. u32 dwVolControl_B3;
  1152. u32 dwMixControl_P4;
  1153. u32 dwVolControl_A4;
  1154. u32 dwVolControl_B4;
  1155. };
  1156. static u8 m_bAddressSize, m_bDataSize, m_bDeviceID;
  1157. static int I2CUnlockFullAccess(struct hw *hw)
  1158. {
  1159. u8 UnlockKeySequence_FLASH_FULLACCESS_MODE[2] = {0xB3, 0xD4};
  1160. /* Send keys for forced BIOS mode */
  1161. hw_write_20kx(hw, I2C_IF_WLOCK,
  1162. UnlockKeySequence_FLASH_FULLACCESS_MODE[0]);
  1163. hw_write_20kx(hw, I2C_IF_WLOCK,
  1164. UnlockKeySequence_FLASH_FULLACCESS_MODE[1]);
  1165. /* Check whether the chip is unlocked */
  1166. if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_UNLOCKED)
  1167. return 0;
  1168. return -1;
  1169. }
  1170. static int I2CLockChip(struct hw *hw)
  1171. {
  1172. /* Write twice */
  1173. hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED);
  1174. hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED);
  1175. if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_LOCKED)
  1176. return 0;
  1177. return -1;
  1178. }
  1179. static int I2CInit(struct hw *hw, u8 bDeviceID, u8 bAddressSize, u8 bDataSize)
  1180. {
  1181. int err = 0;
  1182. unsigned int RegI2CStatus;
  1183. unsigned int RegI2CAddress;
  1184. err = I2CUnlockFullAccess(hw);
  1185. if (err < 0)
  1186. return err;
  1187. m_bAddressSize = bAddressSize;
  1188. m_bDataSize = bDataSize;
  1189. m_bDeviceID = bDeviceID;
  1190. RegI2CAddress = 0;
  1191. set_field(&RegI2CAddress, I2C_ADDRESS_SLAD, bDeviceID);
  1192. hw_write_20kx(hw, I2C_IF_ADDRESS, RegI2CAddress);
  1193. RegI2CStatus = hw_read_20kx(hw, I2C_IF_STATUS);
  1194. set_field(&RegI2CStatus, I2C_STATUS_DCM, 1); /* Direct control mode */
  1195. hw_write_20kx(hw, I2C_IF_STATUS, RegI2CStatus);
  1196. return 0;
  1197. }
  1198. static int I2CUninit(struct hw *hw)
  1199. {
  1200. unsigned int RegI2CStatus;
  1201. unsigned int RegI2CAddress;
  1202. RegI2CAddress = 0;
  1203. set_field(&RegI2CAddress, I2C_ADDRESS_SLAD, 0x57); /* I2C id */
  1204. hw_write_20kx(hw, I2C_IF_ADDRESS, RegI2CAddress);
  1205. RegI2CStatus = hw_read_20kx(hw, I2C_IF_STATUS);
  1206. set_field(&RegI2CStatus, I2C_STATUS_DCM, 0); /* I2C mode */
  1207. hw_write_20kx(hw, I2C_IF_STATUS, RegI2CStatus);
  1208. return I2CLockChip(hw);
  1209. }
  1210. static int I2CWaitDataReady(struct hw *hw)
  1211. {
  1212. int i = 0x400000;
  1213. unsigned int ret = 0;
  1214. do {
  1215. ret = hw_read_20kx(hw, I2C_IF_STATUS);
  1216. } while ((!(ret & DATA_READY)) && --i);
  1217. return i;
  1218. }
  1219. static int I2CRead(struct hw *hw, u16 wAddress, u32 *pdwData)
  1220. {
  1221. unsigned int RegI2CStatus;
  1222. RegI2CStatus = hw_read_20kx(hw, I2C_IF_STATUS);
  1223. set_field(&RegI2CStatus, I2C_STATUS_BC,
  1224. (4 == m_bAddressSize) ? 0 : m_bAddressSize);
  1225. hw_write_20kx(hw, I2C_IF_STATUS, RegI2CStatus);
  1226. if (!I2CWaitDataReady(hw))
  1227. return -1;
  1228. hw_write_20kx(hw, I2C_IF_WDATA, (u32)wAddress);
  1229. if (!I2CWaitDataReady(hw))
  1230. return -1;
  1231. /* Force a read operation */
  1232. hw_write_20kx(hw, I2C_IF_RDATA, 0);
  1233. if (!I2CWaitDataReady(hw))
  1234. return -1;
  1235. *pdwData = hw_read_20kx(hw, I2C_IF_RDATA);
  1236. return 0;
  1237. }
  1238. static int I2CWrite(struct hw *hw, u16 wAddress, u32 dwData)
  1239. {
  1240. unsigned int dwI2CData = (dwData << (m_bAddressSize * 8)) | wAddress;
  1241. unsigned int RegI2CStatus;
  1242. RegI2CStatus = hw_read_20kx(hw, I2C_IF_STATUS);
  1243. set_field(&RegI2CStatus, I2C_STATUS_BC,
  1244. (4 == (m_bAddressSize + m_bDataSize)) ?
  1245. 0 : (m_bAddressSize + m_bDataSize));
  1246. hw_write_20kx(hw, I2C_IF_STATUS, RegI2CStatus);
  1247. I2CWaitDataReady(hw);
  1248. /* Dummy write to trigger the write oprtation */
  1249. hw_write_20kx(hw, I2C_IF_WDATA, 0);
  1250. I2CWaitDataReady(hw);
  1251. /* This is the real data */
  1252. hw_write_20kx(hw, I2C_IF_WDATA, dwI2CData);
  1253. I2CWaitDataReady(hw);
  1254. return 0;
  1255. }
  1256. static int hw_dac_init(struct hw *hw, const struct dac_conf *info)
  1257. {
  1258. int err = 0;
  1259. u32 dwData = 0;
  1260. int i = 0;
  1261. struct REGS_CS4382 cs4382_Read = {0};
  1262. struct REGS_CS4382 cs4382_Def = {
  1263. 0x00000001, /* Mode Control 1 */
  1264. 0x00000000, /* Mode Control 2 */
  1265. 0x00000084, /* Mode Control 3 */
  1266. 0x00000000, /* Filter Control */
  1267. 0x00000000, /* Invert Control */
  1268. 0x00000024, /* Mixing Control Pair 1 */
  1269. 0x00000000, /* Vol Control A1 */
  1270. 0x00000000, /* Vol Control B1 */
  1271. 0x00000024, /* Mixing Control Pair 2 */
  1272. 0x00000000, /* Vol Control A2 */
  1273. 0x00000000, /* Vol Control B2 */
  1274. 0x00000024, /* Mixing Control Pair 3 */
  1275. 0x00000000, /* Vol Control A3 */
  1276. 0x00000000, /* Vol Control B3 */
  1277. 0x00000024, /* Mixing Control Pair 4 */
  1278. 0x00000000, /* Vol Control A4 */
  1279. 0x00000000 /* Vol Control B4 */
  1280. };
  1281. /* Set DAC reset bit as output */
  1282. dwData = hw_read_20kx(hw, GPIO_CTRL);
  1283. dwData |= 0x02;
  1284. hw_write_20kx(hw, GPIO_CTRL, dwData);
  1285. err = I2CInit(hw, 0x18, 1, 1);
  1286. if (err < 0)
  1287. goto End;
  1288. for (i = 0; i < 2; i++) {
  1289. /* Reset DAC twice just in-case the chip
  1290. * didn't initialized properly */
  1291. dwData = hw_read_20kx(hw, GPIO_DATA);
  1292. /* GPIO data bit 1 */
  1293. dwData &= 0xFFFFFFFD;
  1294. hw_write_20kx(hw, GPIO_DATA, dwData);
  1295. mdelay(10);
  1296. dwData |= 0x2;
  1297. hw_write_20kx(hw, GPIO_DATA, dwData);
  1298. mdelay(50);
  1299. /* Reset the 2nd time */
  1300. dwData &= 0xFFFFFFFD;
  1301. hw_write_20kx(hw, GPIO_DATA, dwData);
  1302. mdelay(10);
  1303. dwData |= 0x2;
  1304. hw_write_20kx(hw, GPIO_DATA, dwData);
  1305. mdelay(50);
  1306. if (I2CRead(hw, CS4382_MC1, &cs4382_Read.dwModeControl_1))
  1307. continue;
  1308. if (I2CRead(hw, CS4382_MC2, &cs4382_Read.dwModeControl_2))
  1309. continue;
  1310. if (I2CRead(hw, CS4382_MC3, &cs4382_Read.dwModeControl_3))
  1311. continue;
  1312. if (I2CRead(hw, CS4382_FC, &cs4382_Read.dwFilterControl))
  1313. continue;
  1314. if (I2CRead(hw, CS4382_IC, &cs4382_Read.dwInvertControl))
  1315. continue;
  1316. if (I2CRead(hw, CS4382_XC1, &cs4382_Read.dwMixControl_P1))
  1317. continue;
  1318. if (I2CRead(hw, CS4382_VCA1, &cs4382_Read.dwVolControl_A1))
  1319. continue;
  1320. if (I2CRead(hw, CS4382_VCB1, &cs4382_Read.dwVolControl_B1))
  1321. continue;
  1322. if (I2CRead(hw, CS4382_XC2, &cs4382_Read.dwMixControl_P2))
  1323. continue;
  1324. if (I2CRead(hw, CS4382_VCA2, &cs4382_Read.dwVolControl_A2))
  1325. continue;
  1326. if (I2CRead(hw, CS4382_VCB2, &cs4382_Read.dwVolControl_B2))
  1327. continue;
  1328. if (I2CRead(hw, CS4382_XC3, &cs4382_Read.dwMixControl_P3))
  1329. continue;
  1330. if (I2CRead(hw, CS4382_VCA3, &cs4382_Read.dwVolControl_A3))
  1331. continue;
  1332. if (I2CRead(hw, CS4382_VCB3, &cs4382_Read.dwVolControl_B3))
  1333. continue;
  1334. if (I2CRead(hw, CS4382_XC4, &cs4382_Read.dwMixControl_P4))
  1335. continue;
  1336. if (I2CRead(hw, CS4382_VCA4, &cs4382_Read.dwVolControl_A4))
  1337. continue;
  1338. if (I2CRead(hw, CS4382_VCB4, &cs4382_Read.dwVolControl_B4))
  1339. continue;
  1340. if (memcmp(&cs4382_Read, &cs4382_Def,
  1341. sizeof(struct REGS_CS4382)))
  1342. continue;
  1343. else
  1344. break;
  1345. }
  1346. if (i >= 2)
  1347. goto End;
  1348. /* Note: Every I2C write must have some delay.
  1349. * This is not a requirement but the delay works here... */
  1350. I2CWrite(hw, CS4382_MC1, 0x80);
  1351. I2CWrite(hw, CS4382_MC2, 0x10);
  1352. if (1 == info->msr) {
  1353. I2CWrite(hw, CS4382_XC1, 0x24);
  1354. I2CWrite(hw, CS4382_XC2, 0x24);
  1355. I2CWrite(hw, CS4382_XC3, 0x24);
  1356. I2CWrite(hw, CS4382_XC4, 0x24);
  1357. } else if (2 == info->msr) {
  1358. I2CWrite(hw, CS4382_XC1, 0x25);
  1359. I2CWrite(hw, CS4382_XC2, 0x25);
  1360. I2CWrite(hw, CS4382_XC3, 0x25);
  1361. I2CWrite(hw, CS4382_XC4, 0x25);
  1362. } else {
  1363. I2CWrite(hw, CS4382_XC1, 0x26);
  1364. I2CWrite(hw, CS4382_XC2, 0x26);
  1365. I2CWrite(hw, CS4382_XC3, 0x26);
  1366. I2CWrite(hw, CS4382_XC4, 0x26);
  1367. }
  1368. return 0;
  1369. End:
  1370. I2CUninit(hw);
  1371. return -1;
  1372. }
  1373. /* ADC operations */
  1374. #define MAKE_WM8775_ADDR(addr, data) (u32)(((addr<<1)&0xFE)|((data>>8)&0x1))
  1375. #define MAKE_WM8775_DATA(data) (u32)(data&0xFF)
  1376. #define WM8775_IC 0x0B
  1377. #define WM8775_MMC 0x0C
  1378. #define WM8775_AADCL 0x0E
  1379. #define WM8775_AADCR 0x0F
  1380. #define WM8775_ADCMC 0x15
  1381. #define WM8775_RESET 0x17
  1382. static int hw_is_adc_input_selected(struct hw *hw, enum ADCSRC type)
  1383. {
  1384. u32 data = 0;
  1385. data = hw_read_20kx(hw, GPIO_DATA);
  1386. switch (type) {
  1387. case ADC_MICIN:
  1388. data = (data & (0x1 << 14)) ? 1 : 0;
  1389. break;
  1390. case ADC_LINEIN:
  1391. data = (data & (0x1 << 14)) ? 0 : 1;
  1392. break;
  1393. default:
  1394. data = 0;
  1395. }
  1396. return data;
  1397. }
  1398. static int hw_adc_input_select(struct hw *hw, enum ADCSRC type)
  1399. {
  1400. u32 data = 0;
  1401. data = hw_read_20kx(hw, GPIO_DATA);
  1402. switch (type) {
  1403. case ADC_MICIN:
  1404. data |= (0x1 << 14);
  1405. hw_write_20kx(hw, GPIO_DATA, data);
  1406. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x101),
  1407. MAKE_WM8775_DATA(0x101)); /* Mic-in */
  1408. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xE7),
  1409. MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
  1410. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xE7),
  1411. MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
  1412. break;
  1413. case ADC_LINEIN:
  1414. data &= ~(0x1 << 14);
  1415. hw_write_20kx(hw, GPIO_DATA, data);
  1416. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x102),
  1417. MAKE_WM8775_DATA(0x102)); /* Line-in */
  1418. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xCF),
  1419. MAKE_WM8775_DATA(0xCF)); /* No boost */
  1420. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
  1421. MAKE_WM8775_DATA(0xCF)); /* No boost */
  1422. break;
  1423. default:
  1424. break;
  1425. }
  1426. return 0;
  1427. }
  1428. static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
  1429. {
  1430. int err = 0;
  1431. u32 dwMux = 2, dwData = 0, dwCtl = 0;
  1432. /* Set ADC reset bit as output */
  1433. dwData = hw_read_20kx(hw, GPIO_CTRL);
  1434. dwData |= (0x1 << 15);
  1435. hw_write_20kx(hw, GPIO_CTRL, dwData);
  1436. /* Initialize I2C */
  1437. err = I2CInit(hw, 0x1A, 1, 1);
  1438. if (err < 0) {
  1439. printk(KERN_ALERT "Failure to acquire I2C!!!\n");
  1440. goto error;
  1441. }
  1442. /* Make ADC in normal operation */
  1443. dwData = hw_read_20kx(hw, GPIO_DATA);
  1444. dwData &= ~(0x1 << 15);
  1445. mdelay(10);
  1446. dwData |= (0x1 << 15);
  1447. hw_write_20kx(hw, GPIO_DATA, dwData);
  1448. mdelay(50);
  1449. /* Set the master mode (256fs) */
  1450. if (1 == info->msr) {
  1451. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x02),
  1452. MAKE_WM8775_DATA(0x02));
  1453. } else if (2 == info->msr) {
  1454. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x0A),
  1455. MAKE_WM8775_DATA(0x0A));
  1456. } else {
  1457. printk(KERN_ALERT "Invalid master sampling "
  1458. "rate (msr %d)!!!\n", info->msr);
  1459. err = -EINVAL;
  1460. goto error;
  1461. }
  1462. /* Configure GPIO bit 14 change to line-in/mic-in */
  1463. dwCtl = hw_read_20kx(hw, GPIO_CTRL);
  1464. dwCtl |= 0x1<<14;
  1465. hw_write_20kx(hw, GPIO_CTRL, dwCtl);
  1466. /* Check using Mic-in or Line-in */
  1467. dwData = hw_read_20kx(hw, GPIO_DATA);
  1468. if (dwMux == 1) {
  1469. /* Configures GPIO data to select Mic-in */
  1470. dwData |= 0x1<<14;
  1471. hw_write_20kx(hw, GPIO_DATA, dwData);
  1472. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x101),
  1473. MAKE_WM8775_DATA(0x101)); /* Mic-in */
  1474. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xE7),
  1475. MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
  1476. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xE7),
  1477. MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
  1478. } else if (dwMux == 2) {
  1479. /* Configures GPIO data to select Line-in */
  1480. dwData &= ~(0x1<<14);
  1481. hw_write_20kx(hw, GPIO_DATA, dwData);
  1482. /* Setup ADC */
  1483. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x102),
  1484. MAKE_WM8775_DATA(0x102)); /* Line-in */
  1485. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xCF),
  1486. MAKE_WM8775_DATA(0xCF)); /* No boost */
  1487. I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
  1488. MAKE_WM8775_DATA(0xCF)); /* No boost */
  1489. } else {
  1490. printk(KERN_ALERT "ERROR!!! Invalid input mux!!!\n");
  1491. err = -EINVAL;
  1492. goto error;
  1493. }
  1494. return 0;
  1495. error:
  1496. I2CUninit(hw);
  1497. return err;
  1498. }
  1499. static int hw_have_digit_io_switch(struct hw *hw)
  1500. {
  1501. return 0;
  1502. }
  1503. static int hw_card_start(struct hw *hw)
  1504. {
  1505. int err = 0;
  1506. struct pci_dev *pci = hw->pci;
  1507. unsigned int gctl;
  1508. unsigned int dma_mask = 0;
  1509. err = pci_enable_device(pci);
  1510. if (err < 0)
  1511. return err;
  1512. /* Set DMA transfer mask */
  1513. dma_mask = CT_XFI_DMA_MASK;
  1514. if (pci_set_dma_mask(pci, dma_mask) < 0 ||
  1515. pci_set_consistent_dma_mask(pci, dma_mask) < 0) {
  1516. printk(KERN_ERR "architecture does not support PCI "
  1517. "busmaster DMA with mask 0x%x\n", dma_mask);
  1518. err = -ENXIO;
  1519. goto error1;
  1520. }
  1521. err = pci_request_regions(pci, "XFi");
  1522. if (err < 0)
  1523. goto error1;
  1524. hw->io_base = pci_resource_start(hw->pci, 2);
  1525. hw->mem_base = (unsigned long)ioremap(hw->io_base,
  1526. pci_resource_len(hw->pci, 2));
  1527. if (NULL == (void *)hw->mem_base) {
  1528. err = -ENOENT;
  1529. goto error2;
  1530. }
  1531. /* Switch to 20k2 mode from UAA mode. */
  1532. gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
  1533. set_field(&gctl, GCTL_UAA, 0);
  1534. hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
  1535. /*if ((err = request_irq(pci->irq, ct_atc_interrupt, IRQF_SHARED,
  1536. atc->chip_details->nm_card, hw))) {
  1537. goto error3;
  1538. }
  1539. hw->irq = pci->irq;
  1540. */
  1541. pci_set_master(pci);
  1542. return 0;
  1543. /*error3:
  1544. iounmap((void *)hw->mem_base);
  1545. hw->mem_base = (unsigned long)NULL;*/
  1546. error2:
  1547. pci_release_regions(pci);
  1548. hw->io_base = 0;
  1549. error1:
  1550. pci_disable_device(pci);
  1551. return err;
  1552. }
  1553. static int hw_card_stop(struct hw *hw)
  1554. {
  1555. /* TODO: Disable interrupt and so on... */
  1556. return 0;
  1557. }
  1558. static int hw_card_shutdown(struct hw *hw)
  1559. {
  1560. if (hw->irq >= 0)
  1561. free_irq(hw->irq, hw);
  1562. hw->irq = -1;
  1563. if (NULL != ((void *)hw->mem_base))
  1564. iounmap((void *)hw->mem_base);
  1565. hw->mem_base = (unsigned long)NULL;
  1566. if (hw->io_base)
  1567. pci_release_regions(hw->pci);
  1568. hw->io_base = 0;
  1569. pci_disable_device(hw->pci);
  1570. return 0;
  1571. }
  1572. static int hw_card_init(struct hw *hw, struct card_conf *info)
  1573. {
  1574. int err;
  1575. unsigned int gctl;
  1576. u32 data = 0;
  1577. struct dac_conf dac_info = {0};
  1578. struct adc_conf adc_info = {0};
  1579. struct daio_conf daio_info = {0};
  1580. struct trn_conf trn_info = {0};
  1581. /* Get PCI io port/memory base address and
  1582. * do 20kx core switch if needed. */
  1583. if (!hw->io_base) {
  1584. err = hw_card_start(hw);
  1585. if (err)
  1586. return err;
  1587. }
  1588. /* PLL init */
  1589. err = hw_pll_init(hw, info->rsr);
  1590. if (err < 0)
  1591. return err;
  1592. /* kick off auto-init */
  1593. err = hw_auto_init(hw);
  1594. if (err < 0)
  1595. return err;
  1596. gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
  1597. set_field(&gctl, GCTL_DBP, 1);
  1598. set_field(&gctl, GCTL_TBP, 1);
  1599. set_field(&gctl, GCTL_FBP, 1);
  1600. set_field(&gctl, GCTL_DPC, 0);
  1601. hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
  1602. /* Reset all global pending interrupts */
  1603. hw_write_20kx(hw, INTERRUPT_GIE, 0);
  1604. /* Reset all SRC pending interrupts */
  1605. hw_write_20kx(hw, SRC_IP, 0);
  1606. /* TODO: detect the card ID and configure GPIO accordingly. */
  1607. /* Configures GPIO (0xD802 0x98028) */
  1608. /*hw_write_20kx(hw, GPIO_CTRL, 0x7F07);*/
  1609. /* Configures GPIO (SB0880) */
  1610. /*hw_write_20kx(hw, GPIO_CTRL, 0xFF07);*/
  1611. hw_write_20kx(hw, GPIO_CTRL, 0xD802);
  1612. /* Enable audio ring */
  1613. hw_write_20kx(hw, MIXER_AR_ENABLE, 0x01);
  1614. trn_info.vm_pgt_phys = info->vm_pgt_phys;
  1615. err = hw_trn_init(hw, &trn_info);
  1616. if (err < 0)
  1617. return err;
  1618. daio_info.msr = info->msr;
  1619. err = hw_daio_init(hw, &daio_info);
  1620. if (err < 0)
  1621. return err;
  1622. dac_info.msr = info->msr;
  1623. err = hw_dac_init(hw, &dac_info);
  1624. if (err < 0)
  1625. return err;
  1626. adc_info.msr = info->msr;
  1627. adc_info.input = ADC_LINEIN;
  1628. adc_info.mic20db = 0;
  1629. err = hw_adc_init(hw, &adc_info);
  1630. if (err < 0)
  1631. return err;
  1632. data = hw_read_20kx(hw, SRC_MCTL);
  1633. data |= 0x1; /* Enables input from the audio ring */
  1634. hw_write_20kx(hw, SRC_MCTL, data);
  1635. return 0;
  1636. }
  1637. static u32 hw_read_20kx(struct hw *hw, u32 reg)
  1638. {
  1639. return readl((void *)(hw->mem_base + reg));
  1640. }
  1641. static void hw_write_20kx(struct hw *hw, u32 reg, u32 data)
  1642. {
  1643. writel(data, (void *)(hw->mem_base + reg));
  1644. }
  1645. int create_20k2_hw_obj(struct hw **rhw)
  1646. {
  1647. struct hw *hw;
  1648. *rhw = NULL;
  1649. hw = kzalloc(sizeof(*hw), GFP_KERNEL);
  1650. if (NULL == hw)
  1651. return -ENOMEM;
  1652. hw->io_base = 0;
  1653. hw->mem_base = (unsigned long)NULL;
  1654. hw->irq = -1;
  1655. hw->card_init = hw_card_init;
  1656. hw->card_stop = hw_card_stop;
  1657. hw->pll_init = hw_pll_init;
  1658. hw->is_adc_source_selected = hw_is_adc_input_selected;
  1659. hw->select_adc_source = hw_adc_input_select;
  1660. hw->have_digit_io_switch = hw_have_digit_io_switch;
  1661. hw->src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk;
  1662. hw->src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk;
  1663. hw->src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk;
  1664. hw->src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk;
  1665. hw->src_set_state = src_set_state;
  1666. hw->src_set_bm = src_set_bm;
  1667. hw->src_set_rsr = src_set_rsr;
  1668. hw->src_set_sf = src_set_sf;
  1669. hw->src_set_wr = src_set_wr;
  1670. hw->src_set_pm = src_set_pm;
  1671. hw->src_set_rom = src_set_rom;
  1672. hw->src_set_vo = src_set_vo;
  1673. hw->src_set_st = src_set_st;
  1674. hw->src_set_ie = src_set_ie;
  1675. hw->src_set_ilsz = src_set_ilsz;
  1676. hw->src_set_bp = src_set_bp;
  1677. hw->src_set_cisz = src_set_cisz;
  1678. hw->src_set_ca = src_set_ca;
  1679. hw->src_set_sa = src_set_sa;
  1680. hw->src_set_la = src_set_la;
  1681. hw->src_set_pitch = src_set_pitch;
  1682. hw->src_set_dirty = src_set_dirty;
  1683. hw->src_set_clear_zbufs = src_set_clear_zbufs;
  1684. hw->src_set_dirty_all = src_set_dirty_all;
  1685. hw->src_commit_write = src_commit_write;
  1686. hw->src_get_ca = src_get_ca;
  1687. hw->src_get_dirty = src_get_dirty;
  1688. hw->src_dirty_conj_mask = src_dirty_conj_mask;
  1689. hw->src_mgr_enbs_src = src_mgr_enbs_src;
  1690. hw->src_mgr_enb_src = src_mgr_enb_src;
  1691. hw->src_mgr_dsb_src = src_mgr_dsb_src;
  1692. hw->src_mgr_commit_write = src_mgr_commit_write;
  1693. hw->srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk;
  1694. hw->srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk;
  1695. hw->srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc;
  1696. hw->srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser;
  1697. hw->srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt;
  1698. hw->srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr;
  1699. hw->srcimp_mgr_commit_write = srcimp_mgr_commit_write;
  1700. hw->amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk;
  1701. hw->amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk;
  1702. hw->amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk;
  1703. hw->amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk;
  1704. hw->amixer_set_mode = amixer_set_mode;
  1705. hw->amixer_set_iv = amixer_set_iv;
  1706. hw->amixer_set_x = amixer_set_x;
  1707. hw->amixer_set_y = amixer_set_y;
  1708. hw->amixer_set_sadr = amixer_set_sadr;
  1709. hw->amixer_set_se = amixer_set_se;
  1710. hw->amixer_set_dirty = amixer_set_dirty;
  1711. hw->amixer_set_dirty_all = amixer_set_dirty_all;
  1712. hw->amixer_commit_write = amixer_commit_write;
  1713. hw->amixer_get_y = amixer_get_y;
  1714. hw->amixer_get_dirty = amixer_get_dirty;
  1715. hw->dai_get_ctrl_blk = dai_get_ctrl_blk;
  1716. hw->dai_put_ctrl_blk = dai_put_ctrl_blk;
  1717. hw->dai_srt_set_srco = dai_srt_set_srco;
  1718. hw->dai_srt_set_srcm = dai_srt_set_srcm;
  1719. hw->dai_srt_set_rsr = dai_srt_set_rsr;
  1720. hw->dai_srt_set_drat = dai_srt_set_drat;
  1721. hw->dai_srt_set_ec = dai_srt_set_ec;
  1722. hw->dai_srt_set_et = dai_srt_set_et;
  1723. hw->dai_commit_write = dai_commit_write;
  1724. hw->dao_get_ctrl_blk = dao_get_ctrl_blk;
  1725. hw->dao_put_ctrl_blk = dao_put_ctrl_blk;
  1726. hw->dao_set_spos = dao_set_spos;
  1727. hw->dao_commit_write = dao_commit_write;
  1728. hw->dao_get_spos = dao_get_spos;
  1729. hw->daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk;
  1730. hw->daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk;
  1731. hw->daio_mgr_enb_dai = daio_mgr_enb_dai;
  1732. hw->daio_mgr_dsb_dai = daio_mgr_dsb_dai;
  1733. hw->daio_mgr_enb_dao = daio_mgr_enb_dao;
  1734. hw->daio_mgr_dsb_dao = daio_mgr_dsb_dao;
  1735. hw->daio_mgr_dao_init = daio_mgr_dao_init;
  1736. hw->daio_mgr_set_imaparc = daio_mgr_set_imaparc;
  1737. hw->daio_mgr_set_imapnxt = daio_mgr_set_imapnxt;
  1738. hw->daio_mgr_set_imapaddr = daio_mgr_set_imapaddr;
  1739. hw->daio_mgr_commit_write = daio_mgr_commit_write;
  1740. *rhw = hw;
  1741. return 0;
  1742. }
  1743. int destroy_20k2_hw_obj(struct hw *hw)
  1744. {
  1745. if (hw->io_base)
  1746. hw_card_shutdown(hw);
  1747. kfree(hw);
  1748. return 0;
  1749. }