cthw20k2.c 48 KB

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