cthw20k1.c 48 KB

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