cthw20k2.c 47 KB

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