cthw20k2.c 49 KB

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