cthw20k1.c 48 KB

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