cthw20k1.c 48 KB

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