cthw20k2.c 47 KB

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