cthw20k1.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272
  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 cthw20k1.c
  9. *
  10. * @Brief
  11. * This file contains the implementation of hardware access methord for 20k1.
  12. *
  13. * @Author Liu Chun
  14. * @Date Jun 24 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/spinlock.h>
  23. #include <linux/kernel.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/delay.h>
  26. #include "cthw20k1.h"
  27. #include "ct20k1reg.h"
  28. #if BITS_PER_LONG == 32
  29. #define CT_XFI_DMA_MASK DMA_BIT_MASK(32) /* 32 bit PTE */
  30. #else
  31. #define CT_XFI_DMA_MASK DMA_BIT_MASK(64) /* 64 bit PTE */
  32. #endif
  33. struct hw20k1 {
  34. struct hw hw;
  35. spinlock_t reg_20k1_lock;
  36. spinlock_t reg_pci_lock;
  37. };
  38. static u32 hw_read_20kx(struct hw *hw, u32 reg);
  39. static void hw_write_20kx(struct hw *hw, u32 reg, u32 data);
  40. static u32 hw_read_pci(struct hw *hw, u32 reg);
  41. static void hw_write_pci(struct hw *hw, u32 reg, u32 data);
  42. /*
  43. * Type definition block.
  44. * The layout of control structures can be directly applied on 20k2 chip.
  45. */
  46. /*
  47. * SRC control block definitions.
  48. */
  49. /* SRC resource control block */
  50. #define SRCCTL_STATE 0x00000007
  51. #define SRCCTL_BM 0x00000008
  52. #define SRCCTL_RSR 0x00000030
  53. #define SRCCTL_SF 0x000001C0
  54. #define SRCCTL_WR 0x00000200
  55. #define SRCCTL_PM 0x00000400
  56. #define SRCCTL_ROM 0x00001800
  57. #define SRCCTL_VO 0x00002000
  58. #define SRCCTL_ST 0x00004000
  59. #define SRCCTL_IE 0x00008000
  60. #define SRCCTL_ILSZ 0x000F0000
  61. #define SRCCTL_BP 0x00100000
  62. #define SRCCCR_CISZ 0x000007FF
  63. #define SRCCCR_CWA 0x001FF800
  64. #define SRCCCR_D 0x00200000
  65. #define SRCCCR_RS 0x01C00000
  66. #define SRCCCR_NAL 0x3E000000
  67. #define SRCCCR_RA 0xC0000000
  68. #define SRCCA_CA 0x03FFFFFF
  69. #define SRCCA_RS 0x1C000000
  70. #define SRCCA_NAL 0xE0000000
  71. #define SRCSA_SA 0x03FFFFFF
  72. #define SRCLA_LA 0x03FFFFFF
  73. /* Mixer Parameter Ring ram Low and Hight register.
  74. * Fixed-point value in 8.24 format for parameter channel */
  75. #define MPRLH_PITCH 0xFFFFFFFF
  76. /* SRC resource register dirty flags */
  77. union src_dirty {
  78. struct {
  79. u16 ctl:1;
  80. u16 ccr:1;
  81. u16 sa:1;
  82. u16 la:1;
  83. u16 ca:1;
  84. u16 mpr:1;
  85. u16 czbfs:1; /* Clear Z-Buffers */
  86. u16 rsv:9;
  87. } bf;
  88. u16 data;
  89. };
  90. struct src_rsc_ctrl_blk {
  91. unsigned int ctl;
  92. unsigned int ccr;
  93. unsigned int ca;
  94. unsigned int sa;
  95. unsigned int la;
  96. unsigned int mpr;
  97. union src_dirty dirty;
  98. };
  99. /* SRC manager control block */
  100. union src_mgr_dirty {
  101. struct {
  102. u16 enb0:1;
  103. u16 enb1:1;
  104. u16 enb2:1;
  105. u16 enb3:1;
  106. u16 enb4:1;
  107. u16 enb5:1;
  108. u16 enb6:1;
  109. u16 enb7:1;
  110. u16 enbsa:1;
  111. u16 rsv:7;
  112. } bf;
  113. u16 data;
  114. };
  115. struct src_mgr_ctrl_blk {
  116. unsigned int enbsa;
  117. unsigned int enb[8];
  118. union src_mgr_dirty dirty;
  119. };
  120. /* SRCIMP manager control block */
  121. #define SRCAIM_ARC 0x00000FFF
  122. #define SRCAIM_NXT 0x00FF0000
  123. #define SRCAIM_SRC 0xFF000000
  124. struct srcimap {
  125. unsigned int srcaim;
  126. unsigned int idx;
  127. };
  128. /* SRCIMP manager register dirty flags */
  129. union srcimp_mgr_dirty {
  130. struct {
  131. u16 srcimap:1;
  132. u16 rsv:15;
  133. } bf;
  134. u16 data;
  135. };
  136. struct srcimp_mgr_ctrl_blk {
  137. struct srcimap srcimap;
  138. union srcimp_mgr_dirty dirty;
  139. };
  140. /*
  141. * Function implementation block.
  142. */
  143. static int src_get_rsc_ctrl_blk(void **rblk)
  144. {
  145. struct src_rsc_ctrl_blk *blk;
  146. *rblk = NULL;
  147. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  148. if (NULL == blk)
  149. return -ENOMEM;
  150. *rblk = blk;
  151. return 0;
  152. }
  153. static int src_put_rsc_ctrl_blk(void *blk)
  154. {
  155. kfree((struct src_rsc_ctrl_blk *)blk);
  156. return 0;
  157. }
  158. static int src_set_state(void *blk, unsigned int state)
  159. {
  160. struct src_rsc_ctrl_blk *ctl = blk;
  161. set_field(&ctl->ctl, SRCCTL_STATE, state);
  162. ctl->dirty.bf.ctl = 1;
  163. return 0;
  164. }
  165. static int src_set_bm(void *blk, unsigned int bm)
  166. {
  167. struct src_rsc_ctrl_blk *ctl = blk;
  168. set_field(&ctl->ctl, SRCCTL_BM, bm);
  169. ctl->dirty.bf.ctl = 1;
  170. return 0;
  171. }
  172. static int src_set_rsr(void *blk, unsigned int rsr)
  173. {
  174. struct src_rsc_ctrl_blk *ctl = blk;
  175. set_field(&ctl->ctl, SRCCTL_RSR, rsr);
  176. ctl->dirty.bf.ctl = 1;
  177. return 0;
  178. }
  179. static int src_set_sf(void *blk, unsigned int sf)
  180. {
  181. struct src_rsc_ctrl_blk *ctl = blk;
  182. set_field(&ctl->ctl, SRCCTL_SF, sf);
  183. ctl->dirty.bf.ctl = 1;
  184. return 0;
  185. }
  186. static int src_set_wr(void *blk, unsigned int wr)
  187. {
  188. struct src_rsc_ctrl_blk *ctl = blk;
  189. set_field(&ctl->ctl, SRCCTL_WR, wr);
  190. ctl->dirty.bf.ctl = 1;
  191. return 0;
  192. }
  193. static int src_set_pm(void *blk, unsigned int pm)
  194. {
  195. struct src_rsc_ctrl_blk *ctl = blk;
  196. set_field(&ctl->ctl, SRCCTL_PM, pm);
  197. ctl->dirty.bf.ctl = 1;
  198. return 0;
  199. }
  200. static int src_set_rom(void *blk, unsigned int rom)
  201. {
  202. struct src_rsc_ctrl_blk *ctl = blk;
  203. set_field(&ctl->ctl, SRCCTL_ROM, rom);
  204. ctl->dirty.bf.ctl = 1;
  205. return 0;
  206. }
  207. static int src_set_vo(void *blk, unsigned int vo)
  208. {
  209. struct src_rsc_ctrl_blk *ctl = blk;
  210. set_field(&ctl->ctl, SRCCTL_VO, vo);
  211. ctl->dirty.bf.ctl = 1;
  212. return 0;
  213. }
  214. static int src_set_st(void *blk, unsigned int st)
  215. {
  216. struct src_rsc_ctrl_blk *ctl = blk;
  217. set_field(&ctl->ctl, SRCCTL_ST, st);
  218. ctl->dirty.bf.ctl = 1;
  219. return 0;
  220. }
  221. static int src_set_ie(void *blk, unsigned int ie)
  222. {
  223. struct src_rsc_ctrl_blk *ctl = blk;
  224. set_field(&ctl->ctl, SRCCTL_IE, ie);
  225. ctl->dirty.bf.ctl = 1;
  226. return 0;
  227. }
  228. static int src_set_ilsz(void *blk, unsigned int ilsz)
  229. {
  230. struct src_rsc_ctrl_blk *ctl = blk;
  231. set_field(&ctl->ctl, SRCCTL_ILSZ, ilsz);
  232. ctl->dirty.bf.ctl = 1;
  233. return 0;
  234. }
  235. static int src_set_bp(void *blk, unsigned int bp)
  236. {
  237. struct src_rsc_ctrl_blk *ctl = blk;
  238. set_field(&ctl->ctl, SRCCTL_BP, bp);
  239. ctl->dirty.bf.ctl = 1;
  240. return 0;
  241. }
  242. static int src_set_cisz(void *blk, unsigned int cisz)
  243. {
  244. struct src_rsc_ctrl_blk *ctl = blk;
  245. set_field(&ctl->ccr, SRCCCR_CISZ, cisz);
  246. ctl->dirty.bf.ccr = 1;
  247. return 0;
  248. }
  249. static int src_set_ca(void *blk, unsigned int ca)
  250. {
  251. struct src_rsc_ctrl_blk *ctl = blk;
  252. set_field(&ctl->ca, SRCCA_CA, ca);
  253. ctl->dirty.bf.ca = 1;
  254. return 0;
  255. }
  256. static int src_set_sa(void *blk, unsigned int sa)
  257. {
  258. struct src_rsc_ctrl_blk *ctl = blk;
  259. set_field(&ctl->sa, SRCSA_SA, sa);
  260. ctl->dirty.bf.sa = 1;
  261. return 0;
  262. }
  263. static int src_set_la(void *blk, unsigned int la)
  264. {
  265. struct src_rsc_ctrl_blk *ctl = blk;
  266. set_field(&ctl->la, SRCLA_LA, la);
  267. ctl->dirty.bf.la = 1;
  268. return 0;
  269. }
  270. static int src_set_pitch(void *blk, unsigned int pitch)
  271. {
  272. struct src_rsc_ctrl_blk *ctl = blk;
  273. set_field(&ctl->mpr, MPRLH_PITCH, pitch);
  274. ctl->dirty.bf.mpr = 1;
  275. return 0;
  276. }
  277. static int src_set_clear_zbufs(void *blk, unsigned int clear)
  278. {
  279. ((struct src_rsc_ctrl_blk *)blk)->dirty.bf.czbfs = (clear ? 1 : 0);
  280. return 0;
  281. }
  282. static int src_set_dirty(void *blk, unsigned int flags)
  283. {
  284. ((struct src_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff);
  285. return 0;
  286. }
  287. static int src_set_dirty_all(void *blk)
  288. {
  289. ((struct src_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0);
  290. return 0;
  291. }
  292. #define AR_SLOT_SIZE 4096
  293. #define AR_SLOT_BLOCK_SIZE 16
  294. #define AR_PTS_PITCH 6
  295. #define AR_PARAM_SRC_OFFSET 0x60
  296. static unsigned int src_param_pitch_mixer(unsigned int src_idx)
  297. {
  298. return ((src_idx << 4) + AR_PTS_PITCH + AR_SLOT_SIZE
  299. - AR_PARAM_SRC_OFFSET) % AR_SLOT_SIZE;
  300. }
  301. static int src_commit_write(struct hw *hw, unsigned int idx, void *blk)
  302. {
  303. struct src_rsc_ctrl_blk *ctl = blk;
  304. int i;
  305. if (ctl->dirty.bf.czbfs) {
  306. /* Clear Z-Buffer registers */
  307. for (i = 0; i < 8; i++)
  308. hw_write_20kx(hw, SRCUPZ+idx*0x100+i*0x4, 0);
  309. for (i = 0; i < 4; i++)
  310. hw_write_20kx(hw, SRCDN0Z+idx*0x100+i*0x4, 0);
  311. for (i = 0; i < 8; i++)
  312. hw_write_20kx(hw, SRCDN1Z+idx*0x100+i*0x4, 0);
  313. ctl->dirty.bf.czbfs = 0;
  314. }
  315. if (ctl->dirty.bf.mpr) {
  316. /* Take the parameter mixer resource in the same group as that
  317. * the idx src is in for simplicity. Unlike src, all conjugate
  318. * parameter mixer resources must be programmed for
  319. * corresponding conjugate src resources. */
  320. unsigned int pm_idx = src_param_pitch_mixer(idx);
  321. hw_write_20kx(hw, PRING_LO_HI+4*pm_idx, ctl->mpr);
  322. hw_write_20kx(hw, PMOPLO+8*pm_idx, 0x3);
  323. hw_write_20kx(hw, PMOPHI+8*pm_idx, 0x0);
  324. ctl->dirty.bf.mpr = 0;
  325. }
  326. if (ctl->dirty.bf.sa) {
  327. hw_write_20kx(hw, SRCSA+idx*0x100, ctl->sa);
  328. ctl->dirty.bf.sa = 0;
  329. }
  330. if (ctl->dirty.bf.la) {
  331. hw_write_20kx(hw, SRCLA+idx*0x100, ctl->la);
  332. ctl->dirty.bf.la = 0;
  333. }
  334. if (ctl->dirty.bf.ca) {
  335. hw_write_20kx(hw, SRCCA+idx*0x100, ctl->ca);
  336. ctl->dirty.bf.ca = 0;
  337. }
  338. /* Write srccf register */
  339. hw_write_20kx(hw, SRCCF+idx*0x100, 0x0);
  340. if (ctl->dirty.bf.ccr) {
  341. hw_write_20kx(hw, SRCCCR+idx*0x100, ctl->ccr);
  342. ctl->dirty.bf.ccr = 0;
  343. }
  344. if (ctl->dirty.bf.ctl) {
  345. hw_write_20kx(hw, SRCCTL+idx*0x100, ctl->ctl);
  346. ctl->dirty.bf.ctl = 0;
  347. }
  348. return 0;
  349. }
  350. static int src_get_ca(struct hw *hw, unsigned int idx, void *blk)
  351. {
  352. struct src_rsc_ctrl_blk *ctl = blk;
  353. ctl->ca = hw_read_20kx(hw, SRCCA+idx*0x100);
  354. ctl->dirty.bf.ca = 0;
  355. return get_field(ctl->ca, SRCCA_CA);
  356. }
  357. static unsigned int src_get_dirty(void *blk)
  358. {
  359. return ((struct src_rsc_ctrl_blk *)blk)->dirty.data;
  360. }
  361. static unsigned int src_dirty_conj_mask(void)
  362. {
  363. return 0x20;
  364. }
  365. static int src_mgr_enbs_src(void *blk, unsigned int idx)
  366. {
  367. ((struct src_mgr_ctrl_blk *)blk)->enbsa = ~(0x0);
  368. ((struct src_mgr_ctrl_blk *)blk)->dirty.bf.enbsa = 1;
  369. ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32));
  370. return 0;
  371. }
  372. static int src_mgr_enb_src(void *blk, unsigned int idx)
  373. {
  374. ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32));
  375. ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32));
  376. return 0;
  377. }
  378. static int src_mgr_dsb_src(void *blk, unsigned int idx)
  379. {
  380. ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] &= ~(0x1 << (idx%32));
  381. ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32));
  382. return 0;
  383. }
  384. static int src_mgr_commit_write(struct hw *hw, void *blk)
  385. {
  386. struct src_mgr_ctrl_blk *ctl = blk;
  387. int i;
  388. unsigned int ret;
  389. if (ctl->dirty.bf.enbsa) {
  390. do {
  391. ret = hw_read_20kx(hw, SRCENBSTAT);
  392. } while (ret & 0x1);
  393. hw_write_20kx(hw, SRCENBS, ctl->enbsa);
  394. ctl->dirty.bf.enbsa = 0;
  395. }
  396. for (i = 0; i < 8; i++) {
  397. if ((ctl->dirty.data & (0x1 << i))) {
  398. hw_write_20kx(hw, SRCENB+(i*0x100), ctl->enb[i]);
  399. ctl->dirty.data &= ~(0x1 << i);
  400. }
  401. }
  402. return 0;
  403. }
  404. static int src_mgr_get_ctrl_blk(void **rblk)
  405. {
  406. struct src_mgr_ctrl_blk *blk;
  407. *rblk = NULL;
  408. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  409. if (NULL == blk)
  410. return -ENOMEM;
  411. *rblk = blk;
  412. return 0;
  413. }
  414. static int src_mgr_put_ctrl_blk(void *blk)
  415. {
  416. kfree((struct src_mgr_ctrl_blk *)blk);
  417. return 0;
  418. }
  419. static int srcimp_mgr_get_ctrl_blk(void **rblk)
  420. {
  421. struct srcimp_mgr_ctrl_blk *blk;
  422. *rblk = NULL;
  423. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  424. if (NULL == blk)
  425. return -ENOMEM;
  426. *rblk = blk;
  427. return 0;
  428. }
  429. static int srcimp_mgr_put_ctrl_blk(void *blk)
  430. {
  431. kfree((struct srcimp_mgr_ctrl_blk *)blk);
  432. return 0;
  433. }
  434. static int srcimp_mgr_set_imaparc(void *blk, unsigned int slot)
  435. {
  436. struct srcimp_mgr_ctrl_blk *ctl = blk;
  437. set_field(&ctl->srcimap.srcaim, SRCAIM_ARC, slot);
  438. ctl->dirty.bf.srcimap = 1;
  439. return 0;
  440. }
  441. static int srcimp_mgr_set_imapuser(void *blk, unsigned int user)
  442. {
  443. struct srcimp_mgr_ctrl_blk *ctl = blk;
  444. set_field(&ctl->srcimap.srcaim, SRCAIM_SRC, user);
  445. ctl->dirty.bf.srcimap = 1;
  446. return 0;
  447. }
  448. static int srcimp_mgr_set_imapnxt(void *blk, unsigned int next)
  449. {
  450. struct srcimp_mgr_ctrl_blk *ctl = blk;
  451. set_field(&ctl->srcimap.srcaim, SRCAIM_NXT, next);
  452. ctl->dirty.bf.srcimap = 1;
  453. return 0;
  454. }
  455. static int srcimp_mgr_set_imapaddr(void *blk, unsigned int addr)
  456. {
  457. struct srcimp_mgr_ctrl_blk *ctl = blk;
  458. ctl->srcimap.idx = addr;
  459. ctl->dirty.bf.srcimap = 1;
  460. return 0;
  461. }
  462. static int srcimp_mgr_commit_write(struct hw *hw, void *blk)
  463. {
  464. struct srcimp_mgr_ctrl_blk *ctl = blk;
  465. if (ctl->dirty.bf.srcimap) {
  466. hw_write_20kx(hw, SRCIMAP+ctl->srcimap.idx*0x100,
  467. ctl->srcimap.srcaim);
  468. ctl->dirty.bf.srcimap = 0;
  469. }
  470. return 0;
  471. }
  472. /*
  473. * AMIXER control block definitions.
  474. */
  475. #define AMOPLO_M 0x00000003
  476. #define AMOPLO_X 0x0003FFF0
  477. #define AMOPLO_Y 0xFFFC0000
  478. #define AMOPHI_SADR 0x000000FF
  479. #define AMOPHI_SE 0x80000000
  480. /* AMIXER resource register dirty flags */
  481. union amixer_dirty {
  482. struct {
  483. u16 amoplo:1;
  484. u16 amophi:1;
  485. u16 rsv:14;
  486. } bf;
  487. u16 data;
  488. };
  489. /* AMIXER resource control block */
  490. struct amixer_rsc_ctrl_blk {
  491. unsigned int amoplo;
  492. unsigned int amophi;
  493. union amixer_dirty dirty;
  494. };
  495. static int amixer_set_mode(void *blk, unsigned int mode)
  496. {
  497. struct amixer_rsc_ctrl_blk *ctl = blk;
  498. set_field(&ctl->amoplo, AMOPLO_M, mode);
  499. ctl->dirty.bf.amoplo = 1;
  500. return 0;
  501. }
  502. static int amixer_set_iv(void *blk, unsigned int iv)
  503. {
  504. /* 20k1 amixer does not have this field */
  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, AMOPLO+idx*8, ctl->amoplo);
  550. ctl->dirty.bf.amoplo = 0;
  551. hw_write_20kx(hw, 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((struct amixer_rsc_ctrl_blk *)blk);
  578. return 0;
  579. }
  580. static int amixer_mgr_get_ctrl_blk(void **rblk)
  581. {
  582. /*amixer_mgr_ctrl_blk_t *blk;*/
  583. *rblk = NULL;
  584. /*blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  585. if (NULL == blk)
  586. return -ENOMEM;
  587. *rblk = blk;*/
  588. return 0;
  589. }
  590. static int amixer_mgr_put_ctrl_blk(void *blk)
  591. {
  592. /*kfree((amixer_mgr_ctrl_blk_t *)blk);*/
  593. return 0;
  594. }
  595. /*
  596. * DAIO control block definitions.
  597. */
  598. /* Receiver Sample Rate Tracker Control register */
  599. #define SRTCTL_SRCR 0x000000FF
  600. #define SRTCTL_SRCL 0x0000FF00
  601. #define SRTCTL_RSR 0x00030000
  602. #define SRTCTL_DRAT 0x000C0000
  603. #define SRTCTL_RLE 0x10000000
  604. #define SRTCTL_RLP 0x20000000
  605. #define SRTCTL_EC 0x40000000
  606. #define SRTCTL_ET 0x80000000
  607. /* DAIO Receiver register dirty flags */
  608. union dai_dirty {
  609. struct {
  610. u16 srtctl:1;
  611. u16 rsv:15;
  612. } bf;
  613. u16 data;
  614. };
  615. /* DAIO Receiver control block */
  616. struct dai_ctrl_blk {
  617. unsigned int srtctl;
  618. union dai_dirty dirty;
  619. };
  620. /* S/PDIF Transmitter register dirty flags */
  621. union dao_dirty {
  622. struct {
  623. u16 spos:1;
  624. u16 rsv:15;
  625. } bf;
  626. u16 data;
  627. };
  628. /* S/PDIF Transmitter control block */
  629. struct dao_ctrl_blk {
  630. unsigned int spos; /* S/PDIF Output Channel Status Register */
  631. union dao_dirty dirty;
  632. };
  633. /* Audio Input Mapper RAM */
  634. #define AIM_ARC 0x00000FFF
  635. #define AIM_NXT 0x007F0000
  636. struct daoimap {
  637. unsigned int aim;
  638. unsigned int idx;
  639. };
  640. /* I2S Transmitter/Receiver Control register */
  641. #define I2SCTL_EA 0x00000004
  642. #define I2SCTL_EI 0x00000010
  643. /* S/PDIF Transmitter Control register */
  644. #define SPOCTL_OE 0x00000001
  645. #define SPOCTL_OS 0x0000000E
  646. #define SPOCTL_RIV 0x00000010
  647. #define SPOCTL_LIV 0x00000020
  648. #define SPOCTL_SR 0x000000C0
  649. /* S/PDIF Receiver Control register */
  650. #define SPICTL_EN 0x00000001
  651. #define SPICTL_I24 0x00000002
  652. #define SPICTL_IB 0x00000004
  653. #define SPICTL_SM 0x00000008
  654. #define SPICTL_VM 0x00000010
  655. /* DAIO manager register dirty flags */
  656. union daio_mgr_dirty {
  657. struct {
  658. u32 i2soctl:4;
  659. u32 i2sictl:4;
  660. u32 spoctl:4;
  661. u32 spictl:4;
  662. u32 daoimap:1;
  663. u32 rsv:15;
  664. } bf;
  665. u32 data;
  666. };
  667. /* DAIO manager control block */
  668. struct daio_mgr_ctrl_blk {
  669. unsigned int i2sctl;
  670. unsigned int spoctl;
  671. unsigned int spictl;
  672. struct daoimap daoimap;
  673. union daio_mgr_dirty dirty;
  674. };
  675. static int dai_srt_set_srcr(void *blk, unsigned int src)
  676. {
  677. struct dai_ctrl_blk *ctl = blk;
  678. set_field(&ctl->srtctl, SRTCTL_SRCR, src);
  679. ctl->dirty.bf.srtctl = 1;
  680. return 0;
  681. }
  682. static int dai_srt_set_srcl(void *blk, unsigned int src)
  683. {
  684. struct dai_ctrl_blk *ctl = blk;
  685. set_field(&ctl->srtctl, SRTCTL_SRCL, src);
  686. ctl->dirty.bf.srtctl = 1;
  687. return 0;
  688. }
  689. static int dai_srt_set_rsr(void *blk, unsigned int rsr)
  690. {
  691. struct dai_ctrl_blk *ctl = blk;
  692. set_field(&ctl->srtctl, SRTCTL_RSR, rsr);
  693. ctl->dirty.bf.srtctl = 1;
  694. return 0;
  695. }
  696. static int dai_srt_set_drat(void *blk, unsigned int drat)
  697. {
  698. struct dai_ctrl_blk *ctl = blk;
  699. set_field(&ctl->srtctl, SRTCTL_DRAT, drat);
  700. ctl->dirty.bf.srtctl = 1;
  701. return 0;
  702. }
  703. static int dai_srt_set_ec(void *blk, unsigned int ec)
  704. {
  705. struct dai_ctrl_blk *ctl = blk;
  706. set_field(&ctl->srtctl, SRTCTL_EC, ec ? 1 : 0);
  707. ctl->dirty.bf.srtctl = 1;
  708. return 0;
  709. }
  710. static int dai_srt_set_et(void *blk, unsigned int et)
  711. {
  712. struct dai_ctrl_blk *ctl = blk;
  713. set_field(&ctl->srtctl, SRTCTL_ET, et ? 1 : 0);
  714. ctl->dirty.bf.srtctl = 1;
  715. return 0;
  716. }
  717. static int dai_commit_write(struct hw *hw, unsigned int idx, void *blk)
  718. {
  719. struct dai_ctrl_blk *ctl = blk;
  720. if (ctl->dirty.bf.srtctl) {
  721. if (idx < 4) {
  722. /* S/PDIF SRTs */
  723. hw_write_20kx(hw, SRTSCTL+0x4*idx, ctl->srtctl);
  724. } else {
  725. /* I2S SRT */
  726. hw_write_20kx(hw, SRTICTL, ctl->srtctl);
  727. }
  728. ctl->dirty.bf.srtctl = 0;
  729. }
  730. return 0;
  731. }
  732. static int dai_get_ctrl_blk(void **rblk)
  733. {
  734. struct dai_ctrl_blk *blk;
  735. *rblk = NULL;
  736. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  737. if (NULL == blk)
  738. return -ENOMEM;
  739. *rblk = blk;
  740. return 0;
  741. }
  742. static int dai_put_ctrl_blk(void *blk)
  743. {
  744. kfree((struct dai_ctrl_blk *)blk);
  745. return 0;
  746. }
  747. static int dao_set_spos(void *blk, unsigned int spos)
  748. {
  749. ((struct dao_ctrl_blk *)blk)->spos = spos;
  750. ((struct dao_ctrl_blk *)blk)->dirty.bf.spos = 1;
  751. return 0;
  752. }
  753. static int dao_commit_write(struct hw *hw, unsigned int idx, void *blk)
  754. {
  755. struct dao_ctrl_blk *ctl = blk;
  756. if (ctl->dirty.bf.spos) {
  757. if (idx < 4) {
  758. /* S/PDIF SPOSx */
  759. hw_write_20kx(hw, SPOS+0x4*idx, ctl->spos);
  760. }
  761. ctl->dirty.bf.spos = 0;
  762. }
  763. return 0;
  764. }
  765. static int dao_get_spos(void *blk, unsigned int *spos)
  766. {
  767. *spos = ((struct dao_ctrl_blk *)blk)->spos;
  768. return 0;
  769. }
  770. static int dao_get_ctrl_blk(void **rblk)
  771. {
  772. struct dao_ctrl_blk *blk;
  773. *rblk = NULL;
  774. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  775. if (NULL == blk)
  776. return -ENOMEM;
  777. *rblk = blk;
  778. return 0;
  779. }
  780. static int dao_put_ctrl_blk(void *blk)
  781. {
  782. kfree((struct dao_ctrl_blk *)blk);
  783. return 0;
  784. }
  785. static int daio_mgr_enb_dai(void *blk, unsigned int idx)
  786. {
  787. struct daio_mgr_ctrl_blk *ctl = blk;
  788. if (idx < 4) {
  789. /* S/PDIF input */
  790. set_field(&ctl->spictl, SPICTL_EN << (idx*8), 1);
  791. ctl->dirty.bf.spictl |= (0x1 << idx);
  792. } else {
  793. /* I2S input */
  794. idx %= 4;
  795. set_field(&ctl->i2sctl, I2SCTL_EI << (idx*8), 1);
  796. ctl->dirty.bf.i2sictl |= (0x1 << idx);
  797. }
  798. return 0;
  799. }
  800. static int daio_mgr_dsb_dai(void *blk, unsigned int idx)
  801. {
  802. struct daio_mgr_ctrl_blk *ctl = blk;
  803. if (idx < 4) {
  804. /* S/PDIF input */
  805. set_field(&ctl->spictl, SPICTL_EN << (idx*8), 0);
  806. ctl->dirty.bf.spictl |= (0x1 << idx);
  807. } else {
  808. /* I2S input */
  809. idx %= 4;
  810. set_field(&ctl->i2sctl, I2SCTL_EI << (idx*8), 0);
  811. ctl->dirty.bf.i2sictl |= (0x1 << idx);
  812. }
  813. return 0;
  814. }
  815. static int daio_mgr_enb_dao(void *blk, unsigned int idx)
  816. {
  817. struct daio_mgr_ctrl_blk *ctl = blk;
  818. if (idx < 4) {
  819. /* S/PDIF output */
  820. set_field(&ctl->spoctl, SPOCTL_OE << (idx*8), 1);
  821. ctl->dirty.bf.spoctl |= (0x1 << idx);
  822. } else {
  823. /* I2S output */
  824. idx %= 4;
  825. set_field(&ctl->i2sctl, I2SCTL_EA << (idx*8), 1);
  826. ctl->dirty.bf.i2soctl |= (0x1 << idx);
  827. }
  828. return 0;
  829. }
  830. static int daio_mgr_dsb_dao(void *blk, unsigned int idx)
  831. {
  832. struct daio_mgr_ctrl_blk *ctl = blk;
  833. if (idx < 4) {
  834. /* S/PDIF output */
  835. set_field(&ctl->spoctl, SPOCTL_OE << (idx*8), 0);
  836. ctl->dirty.bf.spoctl |= (0x1 << idx);
  837. } else {
  838. /* I2S output */
  839. idx %= 4;
  840. set_field(&ctl->i2sctl, I2SCTL_EA << (idx*8), 0);
  841. ctl->dirty.bf.i2soctl |= (0x1 << idx);
  842. }
  843. return 0;
  844. }
  845. static int daio_mgr_dao_init(void *blk, unsigned int idx, unsigned int conf)
  846. {
  847. struct daio_mgr_ctrl_blk *ctl = blk;
  848. if (idx < 4) {
  849. /* S/PDIF output */
  850. switch ((conf & 0x7)) {
  851. case 0:
  852. set_field(&ctl->spoctl, SPOCTL_SR << (idx*8), 3);
  853. break; /* CDIF */
  854. case 1:
  855. set_field(&ctl->spoctl, SPOCTL_SR << (idx*8), 0);
  856. break;
  857. case 2:
  858. set_field(&ctl->spoctl, SPOCTL_SR << (idx*8), 1);
  859. break;
  860. case 4:
  861. set_field(&ctl->spoctl, SPOCTL_SR << (idx*8), 2);
  862. break;
  863. default:
  864. break;
  865. }
  866. set_field(&ctl->spoctl, SPOCTL_LIV << (idx*8),
  867. (conf >> 4) & 0x1); /* Non-audio */
  868. set_field(&ctl->spoctl, SPOCTL_RIV << (idx*8),
  869. (conf >> 4) & 0x1); /* Non-audio */
  870. set_field(&ctl->spoctl, SPOCTL_OS << (idx*8),
  871. ((conf >> 3) & 0x1) ? 2 : 2); /* Raw */
  872. ctl->dirty.bf.spoctl |= (0x1 << idx);
  873. } else {
  874. /* I2S output */
  875. /*idx %= 4; */
  876. }
  877. return 0;
  878. }
  879. static int daio_mgr_set_imaparc(void *blk, unsigned int slot)
  880. {
  881. struct daio_mgr_ctrl_blk *ctl = blk;
  882. set_field(&ctl->daoimap.aim, AIM_ARC, slot);
  883. ctl->dirty.bf.daoimap = 1;
  884. return 0;
  885. }
  886. static int daio_mgr_set_imapnxt(void *blk, unsigned int next)
  887. {
  888. struct daio_mgr_ctrl_blk *ctl = blk;
  889. set_field(&ctl->daoimap.aim, AIM_NXT, next);
  890. ctl->dirty.bf.daoimap = 1;
  891. return 0;
  892. }
  893. static int daio_mgr_set_imapaddr(void *blk, unsigned int addr)
  894. {
  895. struct daio_mgr_ctrl_blk *ctl = blk;
  896. ctl->daoimap.idx = addr;
  897. ctl->dirty.bf.daoimap = 1;
  898. return 0;
  899. }
  900. static int daio_mgr_commit_write(struct hw *hw, void *blk)
  901. {
  902. struct daio_mgr_ctrl_blk *ctl = blk;
  903. int i;
  904. if (ctl->dirty.bf.i2sictl || ctl->dirty.bf.i2soctl) {
  905. for (i = 0; i < 4; i++) {
  906. if ((ctl->dirty.bf.i2sictl & (0x1 << i)))
  907. ctl->dirty.bf.i2sictl &= ~(0x1 << i);
  908. if ((ctl->dirty.bf.i2soctl & (0x1 << i)))
  909. ctl->dirty.bf.i2soctl &= ~(0x1 << i);
  910. }
  911. hw_write_20kx(hw, I2SCTL, ctl->i2sctl);
  912. mdelay(1);
  913. }
  914. if (ctl->dirty.bf.spoctl) {
  915. for (i = 0; i < 4; i++) {
  916. if ((ctl->dirty.bf.spoctl & (0x1 << i)))
  917. ctl->dirty.bf.spoctl &= ~(0x1 << i);
  918. }
  919. hw_write_20kx(hw, SPOCTL, ctl->spoctl);
  920. mdelay(1);
  921. }
  922. if (ctl->dirty.bf.spictl) {
  923. for (i = 0; i < 4; i++) {
  924. if ((ctl->dirty.bf.spictl & (0x1 << i)))
  925. ctl->dirty.bf.spictl &= ~(0x1 << i);
  926. }
  927. hw_write_20kx(hw, SPICTL, ctl->spictl);
  928. mdelay(1);
  929. }
  930. if (ctl->dirty.bf.daoimap) {
  931. hw_write_20kx(hw, DAOIMAP+ctl->daoimap.idx*4,
  932. ctl->daoimap.aim);
  933. ctl->dirty.bf.daoimap = 0;
  934. }
  935. return 0;
  936. }
  937. static int daio_mgr_get_ctrl_blk(struct hw *hw, void **rblk)
  938. {
  939. struct daio_mgr_ctrl_blk *blk;
  940. *rblk = NULL;
  941. blk = kzalloc(sizeof(*blk), GFP_KERNEL);
  942. if (NULL == blk)
  943. return -ENOMEM;
  944. blk->i2sctl = hw_read_20kx(hw, I2SCTL);
  945. blk->spoctl = hw_read_20kx(hw, SPOCTL);
  946. blk->spictl = hw_read_20kx(hw, SPICTL);
  947. *rblk = blk;
  948. return 0;
  949. }
  950. static int daio_mgr_put_ctrl_blk(void *blk)
  951. {
  952. kfree((struct daio_mgr_ctrl_blk *)blk);
  953. return 0;
  954. }
  955. /* Timer interrupt */
  956. static int set_timer_irq(struct hw *hw, int enable)
  957. {
  958. hw_write_20kx(hw, GIE, enable ? IT_INT : 0);
  959. return 0;
  960. }
  961. static int set_timer_tick(struct hw *hw, unsigned int ticks)
  962. {
  963. if (ticks)
  964. ticks |= TIMR_IE | TIMR_IP;
  965. hw_write_20kx(hw, TIMR, ticks);
  966. return 0;
  967. }
  968. static unsigned int get_wc(struct hw *hw)
  969. {
  970. return hw_read_20kx(hw, WC);
  971. }
  972. /* Card hardware initialization block */
  973. struct dac_conf {
  974. unsigned int msr; /* master sample rate in rsrs */
  975. };
  976. struct adc_conf {
  977. unsigned int msr; /* master sample rate in rsrs */
  978. unsigned char input; /* the input source of ADC */
  979. unsigned char mic20db; /* boost mic by 20db if input is microphone */
  980. };
  981. struct daio_conf {
  982. unsigned int msr; /* master sample rate in rsrs */
  983. };
  984. struct trn_conf {
  985. unsigned long vm_pgt_phys;
  986. };
  987. static int hw_daio_init(struct hw *hw, const struct daio_conf *info)
  988. {
  989. u32 i2sorg;
  990. u32 spdorg;
  991. /* Read I2S CTL. Keep original value. */
  992. /*i2sorg = hw_read_20kx(hw, I2SCTL);*/
  993. i2sorg = 0x94040404; /* enable all audio out and I2S-D input */
  994. /* Program I2S with proper master sample rate and enable
  995. * the correct I2S channel. */
  996. i2sorg &= 0xfffffffc;
  997. /* Enable S/PDIF-out-A in fixed 24-bit data
  998. * format and default to 48kHz. */
  999. /* Disable all before doing any changes. */
  1000. hw_write_20kx(hw, SPOCTL, 0x0);
  1001. spdorg = 0x05;
  1002. switch (info->msr) {
  1003. case 1:
  1004. i2sorg |= 1;
  1005. spdorg |= (0x0 << 6);
  1006. break;
  1007. case 2:
  1008. i2sorg |= 2;
  1009. spdorg |= (0x1 << 6);
  1010. break;
  1011. case 4:
  1012. i2sorg |= 3;
  1013. spdorg |= (0x2 << 6);
  1014. break;
  1015. default:
  1016. i2sorg |= 1;
  1017. break;
  1018. }
  1019. hw_write_20kx(hw, I2SCTL, i2sorg);
  1020. hw_write_20kx(hw, SPOCTL, spdorg);
  1021. /* Enable S/PDIF-in-A in fixed 24-bit data format. */
  1022. /* Disable all before doing any changes. */
  1023. hw_write_20kx(hw, SPICTL, 0x0);
  1024. mdelay(1);
  1025. spdorg = 0x0a0a0a0a;
  1026. hw_write_20kx(hw, SPICTL, spdorg);
  1027. mdelay(1);
  1028. return 0;
  1029. }
  1030. /* TRANSPORT operations */
  1031. static int hw_trn_init(struct hw *hw, const struct trn_conf *info)
  1032. {
  1033. u32 trnctl;
  1034. u32 ptp_phys_low, ptp_phys_high;
  1035. /* Set up device page table */
  1036. if ((~0UL) == info->vm_pgt_phys) {
  1037. printk(KERN_ERR "Wrong device page table page address!\n");
  1038. return -1;
  1039. }
  1040. trnctl = 0x13; /* 32-bit, 4k-size page */
  1041. ptp_phys_low = (u32)info->vm_pgt_phys;
  1042. ptp_phys_high = upper_32_bits(info->vm_pgt_phys);
  1043. if (sizeof(void *) == 8) /* 64bit address */
  1044. trnctl |= (1 << 2);
  1045. #if 0 /* Only 4k h/w pages for simplicitiy */
  1046. #if PAGE_SIZE == 8192
  1047. trnctl |= (1<<5);
  1048. #endif
  1049. #endif
  1050. hw_write_20kx(hw, PTPALX, ptp_phys_low);
  1051. hw_write_20kx(hw, PTPAHX, ptp_phys_high);
  1052. hw_write_20kx(hw, TRNCTL, trnctl);
  1053. hw_write_20kx(hw, TRNIS, 0x200c01); /* realy needed? */
  1054. return 0;
  1055. }
  1056. /* Card initialization */
  1057. #define GCTL_EAC 0x00000001
  1058. #define GCTL_EAI 0x00000002
  1059. #define GCTL_BEP 0x00000004
  1060. #define GCTL_BES 0x00000008
  1061. #define GCTL_DSP 0x00000010
  1062. #define GCTL_DBP 0x00000020
  1063. #define GCTL_ABP 0x00000040
  1064. #define GCTL_TBP 0x00000080
  1065. #define GCTL_SBP 0x00000100
  1066. #define GCTL_FBP 0x00000200
  1067. #define GCTL_XA 0x00000400
  1068. #define GCTL_ET 0x00000800
  1069. #define GCTL_PR 0x00001000
  1070. #define GCTL_MRL 0x00002000
  1071. #define GCTL_SDE 0x00004000
  1072. #define GCTL_SDI 0x00008000
  1073. #define GCTL_SM 0x00010000
  1074. #define GCTL_SR 0x00020000
  1075. #define GCTL_SD 0x00040000
  1076. #define GCTL_SE 0x00080000
  1077. #define GCTL_AID 0x00100000
  1078. static int hw_pll_init(struct hw *hw, unsigned int rsr)
  1079. {
  1080. unsigned int pllctl;
  1081. int i;
  1082. pllctl = (48000 == rsr) ? 0x1480a001 : 0x1480a731;
  1083. for (i = 0; i < 3; i++) {
  1084. if (hw_read_20kx(hw, PLLCTL) == pllctl)
  1085. break;
  1086. hw_write_20kx(hw, PLLCTL, pllctl);
  1087. mdelay(40);
  1088. }
  1089. if (i >= 3) {
  1090. printk(KERN_ALERT "PLL initialization failed!!!\n");
  1091. return -EBUSY;
  1092. }
  1093. return 0;
  1094. }
  1095. static int hw_auto_init(struct hw *hw)
  1096. {
  1097. unsigned int gctl;
  1098. int i;
  1099. gctl = hw_read_20kx(hw, GCTL);
  1100. set_field(&gctl, GCTL_EAI, 0);
  1101. hw_write_20kx(hw, GCTL, gctl);
  1102. set_field(&gctl, GCTL_EAI, 1);
  1103. hw_write_20kx(hw, GCTL, gctl);
  1104. mdelay(10);
  1105. for (i = 0; i < 400000; i++) {
  1106. gctl = hw_read_20kx(hw, GCTL);
  1107. if (get_field(gctl, GCTL_AID))
  1108. break;
  1109. }
  1110. if (!get_field(gctl, GCTL_AID)) {
  1111. printk(KERN_ALERT "Card Auto-init failed!!!\n");
  1112. return -EBUSY;
  1113. }
  1114. return 0;
  1115. }
  1116. static int i2c_unlock(struct hw *hw)
  1117. {
  1118. if ((hw_read_pci(hw, 0xcc) & 0xff) == 0xaa)
  1119. return 0;
  1120. hw_write_pci(hw, 0xcc, 0x8c);
  1121. hw_write_pci(hw, 0xcc, 0x0e);
  1122. if ((hw_read_pci(hw, 0xcc) & 0xff) == 0xaa)
  1123. return 0;
  1124. hw_write_pci(hw, 0xcc, 0xee);
  1125. hw_write_pci(hw, 0xcc, 0xaa);
  1126. if ((hw_read_pci(hw, 0xcc) & 0xff) == 0xaa)
  1127. return 0;
  1128. return -1;
  1129. }
  1130. static void i2c_lock(struct hw *hw)
  1131. {
  1132. if ((hw_read_pci(hw, 0xcc) & 0xff) == 0xaa)
  1133. hw_write_pci(hw, 0xcc, 0x00);
  1134. }
  1135. static void i2c_write(struct hw *hw, u32 device, u32 addr, u32 data)
  1136. {
  1137. unsigned int ret;
  1138. do {
  1139. ret = hw_read_pci(hw, 0xEC);
  1140. } while (!(ret & 0x800000));
  1141. hw_write_pci(hw, 0xE0, device);
  1142. hw_write_pci(hw, 0xE4, (data << 8) | (addr & 0xff));
  1143. }
  1144. /* DAC operations */
  1145. static int hw_reset_dac(struct hw *hw)
  1146. {
  1147. u32 i;
  1148. u16 gpioorg;
  1149. unsigned int ret;
  1150. if (i2c_unlock(hw))
  1151. return -1;
  1152. do {
  1153. ret = hw_read_pci(hw, 0xEC);
  1154. } while (!(ret & 0x800000));
  1155. hw_write_pci(hw, 0xEC, 0x05); /* write to i2c status control */
  1156. /* To be effective, need to reset the DAC twice. */
  1157. for (i = 0; i < 2; i++) {
  1158. /* set gpio */
  1159. mdelay(100);
  1160. gpioorg = (u16)hw_read_20kx(hw, GPIO);
  1161. gpioorg &= 0xfffd;
  1162. hw_write_20kx(hw, GPIO, gpioorg);
  1163. mdelay(1);
  1164. hw_write_20kx(hw, GPIO, gpioorg | 0x2);
  1165. }
  1166. i2c_write(hw, 0x00180080, 0x01, 0x80);
  1167. i2c_write(hw, 0x00180080, 0x02, 0x10);
  1168. i2c_lock(hw);
  1169. return 0;
  1170. }
  1171. static int hw_dac_init(struct hw *hw, const struct dac_conf *info)
  1172. {
  1173. u32 data;
  1174. u16 gpioorg;
  1175. u16 subsys_id;
  1176. unsigned int ret;
  1177. pci_read_config_word(hw->pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1178. if ((subsys_id == 0x0022) || (subsys_id == 0x002F)) {
  1179. /* SB055x, unmute outputs */
  1180. gpioorg = (u16)hw_read_20kx(hw, GPIO);
  1181. gpioorg &= 0xffbf; /* set GPIO6 to low */
  1182. gpioorg |= 2; /* set GPIO1 to high */
  1183. hw_write_20kx(hw, GPIO, gpioorg);
  1184. return 0;
  1185. }
  1186. /* mute outputs */
  1187. gpioorg = (u16)hw_read_20kx(hw, GPIO);
  1188. gpioorg &= 0xffbf;
  1189. hw_write_20kx(hw, GPIO, gpioorg);
  1190. hw_reset_dac(hw);
  1191. if (i2c_unlock(hw))
  1192. return -1;
  1193. hw_write_pci(hw, 0xEC, 0x05); /* write to i2c status control */
  1194. do {
  1195. ret = hw_read_pci(hw, 0xEC);
  1196. } while (!(ret & 0x800000));
  1197. switch (info->msr) {
  1198. case 1:
  1199. data = 0x24;
  1200. break;
  1201. case 2:
  1202. data = 0x25;
  1203. break;
  1204. case 4:
  1205. data = 0x26;
  1206. break;
  1207. default:
  1208. data = 0x24;
  1209. break;
  1210. }
  1211. i2c_write(hw, 0x00180080, 0x06, data);
  1212. i2c_write(hw, 0x00180080, 0x09, data);
  1213. i2c_write(hw, 0x00180080, 0x0c, data);
  1214. i2c_write(hw, 0x00180080, 0x0f, data);
  1215. i2c_lock(hw);
  1216. /* unmute outputs */
  1217. gpioorg = (u16)hw_read_20kx(hw, GPIO);
  1218. gpioorg = gpioorg | 0x40;
  1219. hw_write_20kx(hw, GPIO, gpioorg);
  1220. return 0;
  1221. }
  1222. /* ADC operations */
  1223. static int is_adc_input_selected_SB055x(struct hw *hw, enum ADCSRC type)
  1224. {
  1225. return 0;
  1226. }
  1227. static int is_adc_input_selected_SBx(struct hw *hw, enum ADCSRC type)
  1228. {
  1229. u32 data;
  1230. data = hw_read_20kx(hw, GPIO);
  1231. switch (type) {
  1232. case ADC_MICIN:
  1233. data = ((data & (0x1<<7)) && (data & (0x1<<8)));
  1234. break;
  1235. case ADC_LINEIN:
  1236. data = (!(data & (0x1<<7)) && (data & (0x1<<8)));
  1237. break;
  1238. case ADC_NONE: /* Digital I/O */
  1239. data = (!(data & (0x1<<8)));
  1240. break;
  1241. default:
  1242. data = 0;
  1243. }
  1244. return data;
  1245. }
  1246. static int is_adc_input_selected_hendrix(struct hw *hw, enum ADCSRC type)
  1247. {
  1248. u32 data;
  1249. data = hw_read_20kx(hw, GPIO);
  1250. switch (type) {
  1251. case ADC_MICIN:
  1252. data = (data & (0x1 << 7)) ? 1 : 0;
  1253. break;
  1254. case ADC_LINEIN:
  1255. data = (data & (0x1 << 7)) ? 0 : 1;
  1256. break;
  1257. default:
  1258. data = 0;
  1259. }
  1260. return data;
  1261. }
  1262. static int hw_is_adc_input_selected(struct hw *hw, enum ADCSRC type)
  1263. {
  1264. u16 subsys_id;
  1265. pci_read_config_word(hw->pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1266. if ((subsys_id == 0x0022) || (subsys_id == 0x002F)) {
  1267. /* SB055x cards */
  1268. return is_adc_input_selected_SB055x(hw, type);
  1269. } else if ((subsys_id == 0x0029) || (subsys_id == 0x0031)) {
  1270. /* SB073x cards */
  1271. return is_adc_input_selected_hendrix(hw, type);
  1272. } else if ((subsys_id & 0xf000) == 0x6000) {
  1273. /* Vista compatible cards */
  1274. return is_adc_input_selected_hendrix(hw, type);
  1275. } else {
  1276. return is_adc_input_selected_SBx(hw, type);
  1277. }
  1278. }
  1279. static int
  1280. adc_input_select_SB055x(struct hw *hw, enum ADCSRC type, unsigned char boost)
  1281. {
  1282. u32 data;
  1283. /*
  1284. * check and set the following GPIO bits accordingly
  1285. * ADC_Gain = GPIO2
  1286. * DRM_off = GPIO3
  1287. * Mic_Pwr_on = GPIO7
  1288. * Digital_IO_Sel = GPIO8
  1289. * Mic_Sw = GPIO9
  1290. * Aux/MicLine_Sw = GPIO12
  1291. */
  1292. data = hw_read_20kx(hw, GPIO);
  1293. data &= 0xec73;
  1294. switch (type) {
  1295. case ADC_MICIN:
  1296. data |= (0x1<<7) | (0x1<<8) | (0x1<<9) ;
  1297. data |= boost ? (0x1<<2) : 0;
  1298. break;
  1299. case ADC_LINEIN:
  1300. data |= (0x1<<8);
  1301. break;
  1302. case ADC_AUX:
  1303. data |= (0x1<<8) | (0x1<<12);
  1304. break;
  1305. case ADC_NONE:
  1306. data |= (0x1<<12); /* set to digital */
  1307. break;
  1308. default:
  1309. return -1;
  1310. }
  1311. hw_write_20kx(hw, GPIO, data);
  1312. return 0;
  1313. }
  1314. static int
  1315. adc_input_select_SBx(struct hw *hw, enum ADCSRC type, unsigned char boost)
  1316. {
  1317. u32 data;
  1318. u32 i2c_data;
  1319. unsigned int ret;
  1320. if (i2c_unlock(hw))
  1321. return -1;
  1322. do {
  1323. ret = hw_read_pci(hw, 0xEC);
  1324. } while (!(ret & 0x800000)); /* i2c ready poll */
  1325. /* set i2c access mode as Direct Control */
  1326. hw_write_pci(hw, 0xEC, 0x05);
  1327. data = hw_read_20kx(hw, GPIO);
  1328. switch (type) {
  1329. case ADC_MICIN:
  1330. data |= ((0x1 << 7) | (0x1 << 8));
  1331. i2c_data = 0x1; /* Mic-in */
  1332. break;
  1333. case ADC_LINEIN:
  1334. data &= ~(0x1 << 7);
  1335. data |= (0x1 << 8);
  1336. i2c_data = 0x2; /* Line-in */
  1337. break;
  1338. case ADC_NONE:
  1339. data &= ~(0x1 << 8);
  1340. i2c_data = 0x0; /* set to Digital */
  1341. break;
  1342. default:
  1343. i2c_lock(hw);
  1344. return -1;
  1345. }
  1346. hw_write_20kx(hw, GPIO, data);
  1347. i2c_write(hw, 0x001a0080, 0x2a, i2c_data);
  1348. if (boost) {
  1349. i2c_write(hw, 0x001a0080, 0x1c, 0xe7); /* +12dB boost */
  1350. i2c_write(hw, 0x001a0080, 0x1e, 0xe7); /* +12dB boost */
  1351. } else {
  1352. i2c_write(hw, 0x001a0080, 0x1c, 0xcf); /* No boost */
  1353. i2c_write(hw, 0x001a0080, 0x1e, 0xcf); /* No boost */
  1354. }
  1355. i2c_lock(hw);
  1356. return 0;
  1357. }
  1358. static int
  1359. adc_input_select_hendrix(struct hw *hw, enum ADCSRC type, unsigned char boost)
  1360. {
  1361. u32 data;
  1362. u32 i2c_data;
  1363. unsigned int ret;
  1364. if (i2c_unlock(hw))
  1365. return -1;
  1366. do {
  1367. ret = hw_read_pci(hw, 0xEC);
  1368. } while (!(ret & 0x800000)); /* i2c ready poll */
  1369. /* set i2c access mode as Direct Control */
  1370. hw_write_pci(hw, 0xEC, 0x05);
  1371. data = hw_read_20kx(hw, GPIO);
  1372. switch (type) {
  1373. case ADC_MICIN:
  1374. data |= (0x1 << 7);
  1375. i2c_data = 0x1; /* Mic-in */
  1376. break;
  1377. case ADC_LINEIN:
  1378. data &= ~(0x1 << 7);
  1379. i2c_data = 0x2; /* Line-in */
  1380. break;
  1381. default:
  1382. i2c_lock(hw);
  1383. return -1;
  1384. }
  1385. hw_write_20kx(hw, GPIO, data);
  1386. i2c_write(hw, 0x001a0080, 0x2a, i2c_data);
  1387. if (boost) {
  1388. i2c_write(hw, 0x001a0080, 0x1c, 0xe7); /* +12dB boost */
  1389. i2c_write(hw, 0x001a0080, 0x1e, 0xe7); /* +12dB boost */
  1390. } else {
  1391. i2c_write(hw, 0x001a0080, 0x1c, 0xcf); /* No boost */
  1392. i2c_write(hw, 0x001a0080, 0x1e, 0xcf); /* No boost */
  1393. }
  1394. i2c_lock(hw);
  1395. return 0;
  1396. }
  1397. static int hw_adc_input_select(struct hw *hw, enum ADCSRC type)
  1398. {
  1399. u16 subsys_id;
  1400. pci_read_config_word(hw->pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1401. if ((subsys_id == 0x0022) || (subsys_id == 0x002F)) {
  1402. /* SB055x cards */
  1403. return adc_input_select_SB055x(hw, type, (ADC_MICIN == type));
  1404. } else if ((subsys_id == 0x0029) || (subsys_id == 0x0031)) {
  1405. /* SB073x cards */
  1406. return adc_input_select_hendrix(hw, type, (ADC_MICIN == type));
  1407. } else if ((subsys_id & 0xf000) == 0x6000) {
  1408. /* Vista compatible cards */
  1409. return adc_input_select_hendrix(hw, type, (ADC_MICIN == type));
  1410. } else {
  1411. return adc_input_select_SBx(hw, type, (ADC_MICIN == type));
  1412. }
  1413. }
  1414. static int adc_init_SB055x(struct hw *hw, int input, int mic20db)
  1415. {
  1416. return adc_input_select_SB055x(hw, input, mic20db);
  1417. }
  1418. static int adc_init_SBx(struct hw *hw, int input, int mic20db)
  1419. {
  1420. u16 gpioorg;
  1421. u16 input_source;
  1422. u32 adcdata;
  1423. unsigned int ret;
  1424. input_source = 0x100; /* default to analog */
  1425. switch (input) {
  1426. case ADC_MICIN:
  1427. adcdata = 0x1;
  1428. input_source = 0x180; /* set GPIO7 to select Mic */
  1429. break;
  1430. case ADC_LINEIN:
  1431. adcdata = 0x2;
  1432. break;
  1433. case ADC_VIDEO:
  1434. adcdata = 0x4;
  1435. break;
  1436. case ADC_AUX:
  1437. adcdata = 0x8;
  1438. break;
  1439. case ADC_NONE:
  1440. adcdata = 0x0;
  1441. input_source = 0x0; /* set to Digital */
  1442. break;
  1443. default:
  1444. adcdata = 0x0;
  1445. break;
  1446. }
  1447. if (i2c_unlock(hw))
  1448. return -1;
  1449. do {
  1450. ret = hw_read_pci(hw, 0xEC);
  1451. } while (!(ret & 0x800000)); /* i2c ready poll */
  1452. hw_write_pci(hw, 0xEC, 0x05); /* write to i2c status control */
  1453. i2c_write(hw, 0x001a0080, 0x0e, 0x08);
  1454. i2c_write(hw, 0x001a0080, 0x18, 0x0a);
  1455. i2c_write(hw, 0x001a0080, 0x28, 0x86);
  1456. i2c_write(hw, 0x001a0080, 0x2a, adcdata);
  1457. if (mic20db) {
  1458. i2c_write(hw, 0x001a0080, 0x1c, 0xf7);
  1459. i2c_write(hw, 0x001a0080, 0x1e, 0xf7);
  1460. } else {
  1461. i2c_write(hw, 0x001a0080, 0x1c, 0xcf);
  1462. i2c_write(hw, 0x001a0080, 0x1e, 0xcf);
  1463. }
  1464. if (!(hw_read_20kx(hw, ID0) & 0x100))
  1465. i2c_write(hw, 0x001a0080, 0x16, 0x26);
  1466. i2c_lock(hw);
  1467. gpioorg = (u16)hw_read_20kx(hw, GPIO);
  1468. gpioorg &= 0xfe7f;
  1469. gpioorg |= input_source;
  1470. hw_write_20kx(hw, GPIO, gpioorg);
  1471. return 0;
  1472. }
  1473. static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
  1474. {
  1475. int err;
  1476. u16 subsys_id;
  1477. pci_read_config_word(hw->pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1478. if ((subsys_id == 0x0022) || (subsys_id == 0x002F)) {
  1479. /* Sb055x card */
  1480. err = adc_init_SB055x(hw, info->input, info->mic20db);
  1481. } else {
  1482. err = adc_init_SBx(hw, info->input, info->mic20db);
  1483. }
  1484. return err;
  1485. }
  1486. static int hw_have_digit_io_switch(struct hw *hw)
  1487. {
  1488. u16 subsys_id;
  1489. pci_read_config_word(hw->pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1490. /* SB073x and Vista compatible cards have no digit IO switch */
  1491. return !((subsys_id == 0x0029) || (subsys_id == 0x0031)
  1492. || ((subsys_id & 0xf000) == 0x6000));
  1493. }
  1494. #define CTLBITS(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
  1495. #define UAA_CFG_PWRSTATUS 0x44
  1496. #define UAA_CFG_SPACE_FLAG 0xA0
  1497. #define UAA_CORE_CHANGE 0x3FFC
  1498. static int uaa_to_xfi(struct pci_dev *pci)
  1499. {
  1500. unsigned int bar0, bar1, bar2, bar3, bar4, bar5;
  1501. unsigned int cmd, irq, cl_size, l_timer, pwr;
  1502. unsigned int is_uaa;
  1503. unsigned int data[4] = {0};
  1504. unsigned int io_base;
  1505. void *mem_base;
  1506. int i;
  1507. const u32 CTLX = CTLBITS('C', 'T', 'L', 'X');
  1508. const u32 CTL_ = CTLBITS('C', 'T', 'L', '-');
  1509. const u32 CTLF = CTLBITS('C', 'T', 'L', 'F');
  1510. const u32 CTLi = CTLBITS('C', 'T', 'L', 'i');
  1511. const u32 CTLA = CTLBITS('C', 'T', 'L', 'A');
  1512. const u32 CTLZ = CTLBITS('C', 'T', 'L', 'Z');
  1513. const u32 CTLL = CTLBITS('C', 'T', 'L', 'L');
  1514. /* By default, Hendrix card UAA Bar0 should be using memory... */
  1515. io_base = pci_resource_start(pci, 0);
  1516. mem_base = ioremap(io_base, pci_resource_len(pci, 0));
  1517. if (NULL == mem_base)
  1518. return -ENOENT;
  1519. /* Read current mode from Mode Change Register */
  1520. for (i = 0; i < 4; i++)
  1521. data[i] = readl(mem_base + UAA_CORE_CHANGE);
  1522. /* Determine current mode... */
  1523. if (data[0] == CTLA) {
  1524. is_uaa = ((data[1] == CTLZ && data[2] == CTLL
  1525. && data[3] == CTLA) || (data[1] == CTLA
  1526. && data[2] == CTLZ && data[3] == CTLL));
  1527. } else if (data[0] == CTLZ) {
  1528. is_uaa = (data[1] == CTLL
  1529. && data[2] == CTLA && data[3] == CTLA);
  1530. } else if (data[0] == CTLL) {
  1531. is_uaa = (data[1] == CTLA
  1532. && data[2] == CTLA && data[3] == CTLZ);
  1533. } else {
  1534. is_uaa = 0;
  1535. }
  1536. if (!is_uaa) {
  1537. /* Not in UAA mode currently. Return directly. */
  1538. iounmap(mem_base);
  1539. return 0;
  1540. }
  1541. pci_read_config_dword(pci, PCI_BASE_ADDRESS_0, &bar0);
  1542. pci_read_config_dword(pci, PCI_BASE_ADDRESS_1, &bar1);
  1543. pci_read_config_dword(pci, PCI_BASE_ADDRESS_2, &bar2);
  1544. pci_read_config_dword(pci, PCI_BASE_ADDRESS_3, &bar3);
  1545. pci_read_config_dword(pci, PCI_BASE_ADDRESS_4, &bar4);
  1546. pci_read_config_dword(pci, PCI_BASE_ADDRESS_5, &bar5);
  1547. pci_read_config_dword(pci, PCI_INTERRUPT_LINE, &irq);
  1548. pci_read_config_dword(pci, PCI_CACHE_LINE_SIZE, &cl_size);
  1549. pci_read_config_dword(pci, PCI_LATENCY_TIMER, &l_timer);
  1550. pci_read_config_dword(pci, UAA_CFG_PWRSTATUS, &pwr);
  1551. pci_read_config_dword(pci, PCI_COMMAND, &cmd);
  1552. /* Set up X-Fi core PCI configuration space. */
  1553. /* Switch to X-Fi config space with BAR0 exposed. */
  1554. pci_write_config_dword(pci, UAA_CFG_SPACE_FLAG, 0x87654321);
  1555. /* Copy UAA's BAR5 into X-Fi BAR0 */
  1556. pci_write_config_dword(pci, PCI_BASE_ADDRESS_0, bar5);
  1557. /* Switch to X-Fi config space without BAR0 exposed. */
  1558. pci_write_config_dword(pci, UAA_CFG_SPACE_FLAG, 0x12345678);
  1559. pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, bar1);
  1560. pci_write_config_dword(pci, PCI_BASE_ADDRESS_2, bar2);
  1561. pci_write_config_dword(pci, PCI_BASE_ADDRESS_3, bar3);
  1562. pci_write_config_dword(pci, PCI_BASE_ADDRESS_4, bar4);
  1563. pci_write_config_dword(pci, PCI_INTERRUPT_LINE, irq);
  1564. pci_write_config_dword(pci, PCI_CACHE_LINE_SIZE, cl_size);
  1565. pci_write_config_dword(pci, PCI_LATENCY_TIMER, l_timer);
  1566. pci_write_config_dword(pci, UAA_CFG_PWRSTATUS, pwr);
  1567. pci_write_config_dword(pci, PCI_COMMAND, cmd);
  1568. /* Switch to X-Fi mode */
  1569. writel(CTLX, (mem_base + UAA_CORE_CHANGE));
  1570. writel(CTL_, (mem_base + UAA_CORE_CHANGE));
  1571. writel(CTLF, (mem_base + UAA_CORE_CHANGE));
  1572. writel(CTLi, (mem_base + UAA_CORE_CHANGE));
  1573. iounmap(mem_base);
  1574. return 0;
  1575. }
  1576. static irqreturn_t ct_20k1_interrupt(int irq, void *dev_id)
  1577. {
  1578. struct hw *hw = dev_id;
  1579. unsigned int status;
  1580. status = hw_read_20kx(hw, GIP);
  1581. if (!status)
  1582. return IRQ_NONE;
  1583. if (hw->irq_callback)
  1584. hw->irq_callback(hw->irq_callback_data, status);
  1585. hw_write_20kx(hw, GIP, status);
  1586. return IRQ_HANDLED;
  1587. }
  1588. static int hw_card_start(struct hw *hw)
  1589. {
  1590. int err;
  1591. struct pci_dev *pci = hw->pci;
  1592. u16 subsys_id;
  1593. err = pci_enable_device(pci);
  1594. if (err < 0)
  1595. return err;
  1596. /* Set DMA transfer mask */
  1597. if (pci_set_dma_mask(pci, CT_XFI_DMA_MASK) < 0 ||
  1598. pci_set_consistent_dma_mask(pci, CT_XFI_DMA_MASK) < 0) {
  1599. printk(KERN_ERR "architecture does not support PCI "
  1600. "busmaster DMA with mask 0x%llx\n",
  1601. CT_XFI_DMA_MASK);
  1602. err = -ENXIO;
  1603. goto error1;
  1604. }
  1605. err = pci_request_regions(pci, "XFi");
  1606. if (err < 0)
  1607. goto error1;
  1608. /* Switch to X-Fi mode from UAA mode if neeeded */
  1609. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1610. if ((0x5 == pci->device) && (0x6000 == (subsys_id & 0x6000))) {
  1611. err = uaa_to_xfi(pci);
  1612. if (err)
  1613. goto error2;
  1614. hw->io_base = pci_resource_start(pci, 5);
  1615. } else {
  1616. hw->io_base = pci_resource_start(pci, 0);
  1617. }
  1618. err = request_irq(pci->irq, ct_20k1_interrupt, IRQF_SHARED,
  1619. "ctxfi", hw);
  1620. if (err < 0) {
  1621. printk(KERN_ERR "XFi: Cannot get irq %d\n", pci->irq);
  1622. goto error2;
  1623. }
  1624. hw->irq = pci->irq;
  1625. pci_set_master(pci);
  1626. return 0;
  1627. error2:
  1628. pci_release_regions(pci);
  1629. hw->io_base = 0;
  1630. error1:
  1631. pci_disable_device(pci);
  1632. return err;
  1633. }
  1634. static int hw_card_stop(struct hw *hw)
  1635. {
  1636. /* TODO: Disable interrupt and so on... */
  1637. if (hw->irq >= 0)
  1638. synchronize_irq(hw->irq);
  1639. return 0;
  1640. }
  1641. static int hw_card_shutdown(struct hw *hw)
  1642. {
  1643. if (hw->irq >= 0)
  1644. free_irq(hw->irq, hw);
  1645. hw->irq = -1;
  1646. if (NULL != ((void *)hw->mem_base))
  1647. iounmap((void *)hw->mem_base);
  1648. hw->mem_base = (unsigned long)NULL;
  1649. if (hw->io_base)
  1650. pci_release_regions(hw->pci);
  1651. hw->io_base = 0;
  1652. pci_disable_device(hw->pci);
  1653. return 0;
  1654. }
  1655. static int hw_card_init(struct hw *hw, struct card_conf *info)
  1656. {
  1657. int err;
  1658. unsigned int gctl;
  1659. u16 subsys_id;
  1660. u32 data;
  1661. struct dac_conf dac_info = {0};
  1662. struct adc_conf adc_info = {0};
  1663. struct daio_conf daio_info = {0};
  1664. struct trn_conf trn_info = {0};
  1665. /* Get PCI io port base address and do Hendrix switch if needed. */
  1666. if (!hw->io_base) {
  1667. err = hw_card_start(hw);
  1668. if (err)
  1669. return err;
  1670. }
  1671. /* PLL init */
  1672. err = hw_pll_init(hw, info->rsr);
  1673. if (err < 0)
  1674. return err;
  1675. /* kick off auto-init */
  1676. err = hw_auto_init(hw);
  1677. if (err < 0)
  1678. return err;
  1679. /* Enable audio ring */
  1680. gctl = hw_read_20kx(hw, GCTL);
  1681. set_field(&gctl, GCTL_EAC, 1);
  1682. set_field(&gctl, GCTL_DBP, 1);
  1683. set_field(&gctl, GCTL_TBP, 1);
  1684. set_field(&gctl, GCTL_FBP, 1);
  1685. set_field(&gctl, GCTL_ET, 1);
  1686. hw_write_20kx(hw, GCTL, gctl);
  1687. mdelay(10);
  1688. /* Reset all global pending interrupts */
  1689. hw_write_20kx(hw, GIE, 0);
  1690. /* Reset all SRC pending interrupts */
  1691. hw_write_20kx(hw, SRCIP, 0);
  1692. mdelay(30);
  1693. pci_read_config_word(hw->pci, PCI_SUBSYSTEM_ID, &subsys_id);
  1694. /* Detect the card ID and configure GPIO accordingly. */
  1695. if ((subsys_id == 0x0022) || (subsys_id == 0x002F)) {
  1696. /* SB055x cards */
  1697. hw_write_20kx(hw, GPIOCTL, 0x13fe);
  1698. } else if ((subsys_id == 0x0029) || (subsys_id == 0x0031)) {
  1699. /* SB073x cards */
  1700. hw_write_20kx(hw, GPIOCTL, 0x00e6);
  1701. } else if ((subsys_id & 0xf000) == 0x6000) {
  1702. /* Vista compatible cards */
  1703. hw_write_20kx(hw, GPIOCTL, 0x00c2);
  1704. } else {
  1705. hw_write_20kx(hw, GPIOCTL, 0x01e6);
  1706. }
  1707. trn_info.vm_pgt_phys = info->vm_pgt_phys;
  1708. err = hw_trn_init(hw, &trn_info);
  1709. if (err < 0)
  1710. return err;
  1711. daio_info.msr = info->msr;
  1712. err = hw_daio_init(hw, &daio_info);
  1713. if (err < 0)
  1714. return err;
  1715. dac_info.msr = info->msr;
  1716. err = hw_dac_init(hw, &dac_info);
  1717. if (err < 0)
  1718. return err;
  1719. adc_info.msr = info->msr;
  1720. adc_info.input = ADC_LINEIN;
  1721. adc_info.mic20db = 0;
  1722. err = hw_adc_init(hw, &adc_info);
  1723. if (err < 0)
  1724. return err;
  1725. data = hw_read_20kx(hw, SRCMCTL);
  1726. data |= 0x1; /* Enables input from the audio ring */
  1727. hw_write_20kx(hw, SRCMCTL, data);
  1728. return 0;
  1729. }
  1730. static u32 hw_read_20kx(struct hw *hw, u32 reg)
  1731. {
  1732. u32 value;
  1733. unsigned long flags;
  1734. spin_lock_irqsave(
  1735. &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
  1736. outl(reg, hw->io_base + 0x0);
  1737. value = inl(hw->io_base + 0x4);
  1738. spin_unlock_irqrestore(
  1739. &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
  1740. return value;
  1741. }
  1742. static void hw_write_20kx(struct hw *hw, u32 reg, u32 data)
  1743. {
  1744. unsigned long flags;
  1745. spin_lock_irqsave(
  1746. &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
  1747. outl(reg, hw->io_base + 0x0);
  1748. outl(data, hw->io_base + 0x4);
  1749. spin_unlock_irqrestore(
  1750. &container_of(hw, struct hw20k1, hw)->reg_20k1_lock, flags);
  1751. }
  1752. static u32 hw_read_pci(struct hw *hw, u32 reg)
  1753. {
  1754. u32 value;
  1755. unsigned long flags;
  1756. spin_lock_irqsave(
  1757. &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
  1758. outl(reg, hw->io_base + 0x10);
  1759. value = inl(hw->io_base + 0x14);
  1760. spin_unlock_irqrestore(
  1761. &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
  1762. return value;
  1763. }
  1764. static void hw_write_pci(struct hw *hw, u32 reg, u32 data)
  1765. {
  1766. unsigned long flags;
  1767. spin_lock_irqsave(
  1768. &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
  1769. outl(reg, hw->io_base + 0x10);
  1770. outl(data, hw->io_base + 0x14);
  1771. spin_unlock_irqrestore(
  1772. &container_of(hw, struct hw20k1, hw)->reg_pci_lock, flags);
  1773. }
  1774. static struct hw ct20k1_preset __devinitdata = {
  1775. .irq = -1,
  1776. .card_init = hw_card_init,
  1777. .card_stop = hw_card_stop,
  1778. .pll_init = hw_pll_init,
  1779. .is_adc_source_selected = hw_is_adc_input_selected,
  1780. .select_adc_source = hw_adc_input_select,
  1781. .have_digit_io_switch = hw_have_digit_io_switch,
  1782. .src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk,
  1783. .src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk,
  1784. .src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk,
  1785. .src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk,
  1786. .src_set_state = src_set_state,
  1787. .src_set_bm = src_set_bm,
  1788. .src_set_rsr = src_set_rsr,
  1789. .src_set_sf = src_set_sf,
  1790. .src_set_wr = src_set_wr,
  1791. .src_set_pm = src_set_pm,
  1792. .src_set_rom = src_set_rom,
  1793. .src_set_vo = src_set_vo,
  1794. .src_set_st = src_set_st,
  1795. .src_set_ie = src_set_ie,
  1796. .src_set_ilsz = src_set_ilsz,
  1797. .src_set_bp = src_set_bp,
  1798. .src_set_cisz = src_set_cisz,
  1799. .src_set_ca = src_set_ca,
  1800. .src_set_sa = src_set_sa,
  1801. .src_set_la = src_set_la,
  1802. .src_set_pitch = src_set_pitch,
  1803. .src_set_dirty = src_set_dirty,
  1804. .src_set_clear_zbufs = src_set_clear_zbufs,
  1805. .src_set_dirty_all = src_set_dirty_all,
  1806. .src_commit_write = src_commit_write,
  1807. .src_get_ca = src_get_ca,
  1808. .src_get_dirty = src_get_dirty,
  1809. .src_dirty_conj_mask = src_dirty_conj_mask,
  1810. .src_mgr_enbs_src = src_mgr_enbs_src,
  1811. .src_mgr_enb_src = src_mgr_enb_src,
  1812. .src_mgr_dsb_src = src_mgr_dsb_src,
  1813. .src_mgr_commit_write = src_mgr_commit_write,
  1814. .srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk,
  1815. .srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk,
  1816. .srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc,
  1817. .srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser,
  1818. .srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt,
  1819. .srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr,
  1820. .srcimp_mgr_commit_write = srcimp_mgr_commit_write,
  1821. .amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk,
  1822. .amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk,
  1823. .amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk,
  1824. .amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk,
  1825. .amixer_set_mode = amixer_set_mode,
  1826. .amixer_set_iv = amixer_set_iv,
  1827. .amixer_set_x = amixer_set_x,
  1828. .amixer_set_y = amixer_set_y,
  1829. .amixer_set_sadr = amixer_set_sadr,
  1830. .amixer_set_se = amixer_set_se,
  1831. .amixer_set_dirty = amixer_set_dirty,
  1832. .amixer_set_dirty_all = amixer_set_dirty_all,
  1833. .amixer_commit_write = amixer_commit_write,
  1834. .amixer_get_y = amixer_get_y,
  1835. .amixer_get_dirty = amixer_get_dirty,
  1836. .dai_get_ctrl_blk = dai_get_ctrl_blk,
  1837. .dai_put_ctrl_blk = dai_put_ctrl_blk,
  1838. .dai_srt_set_srco = dai_srt_set_srcr,
  1839. .dai_srt_set_srcm = dai_srt_set_srcl,
  1840. .dai_srt_set_rsr = dai_srt_set_rsr,
  1841. .dai_srt_set_drat = dai_srt_set_drat,
  1842. .dai_srt_set_ec = dai_srt_set_ec,
  1843. .dai_srt_set_et = dai_srt_set_et,
  1844. .dai_commit_write = dai_commit_write,
  1845. .dao_get_ctrl_blk = dao_get_ctrl_blk,
  1846. .dao_put_ctrl_blk = dao_put_ctrl_blk,
  1847. .dao_set_spos = dao_set_spos,
  1848. .dao_commit_write = dao_commit_write,
  1849. .dao_get_spos = dao_get_spos,
  1850. .daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk,
  1851. .daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk,
  1852. .daio_mgr_enb_dai = daio_mgr_enb_dai,
  1853. .daio_mgr_dsb_dai = daio_mgr_dsb_dai,
  1854. .daio_mgr_enb_dao = daio_mgr_enb_dao,
  1855. .daio_mgr_dsb_dao = daio_mgr_dsb_dao,
  1856. .daio_mgr_dao_init = daio_mgr_dao_init,
  1857. .daio_mgr_set_imaparc = daio_mgr_set_imaparc,
  1858. .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt,
  1859. .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr,
  1860. .daio_mgr_commit_write = daio_mgr_commit_write,
  1861. .set_timer_irq = set_timer_irq,
  1862. .set_timer_tick = set_timer_tick,
  1863. .get_wc = get_wc,
  1864. };
  1865. int __devinit create_20k1_hw_obj(struct hw **rhw)
  1866. {
  1867. struct hw20k1 *hw20k1;
  1868. *rhw = NULL;
  1869. hw20k1 = kzalloc(sizeof(*hw20k1), GFP_KERNEL);
  1870. if (NULL == hw20k1)
  1871. return -ENOMEM;
  1872. spin_lock_init(&hw20k1->reg_20k1_lock);
  1873. spin_lock_init(&hw20k1->reg_pci_lock);
  1874. hw20k1->hw = ct20k1_preset;
  1875. *rhw = &hw20k1->hw;
  1876. return 0;
  1877. }
  1878. int destroy_20k1_hw_obj(struct hw *hw)
  1879. {
  1880. if (hw->io_base)
  1881. hw_card_shutdown(hw);
  1882. kfree(container_of(hw, struct hw20k1, hw));
  1883. return 0;
  1884. }