2 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
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.
11 * This file contains the implementation of hardware access methord for 20k2.
18 #include <linux/types.h>
19 #include <linux/slab.h>
20 #include <linux/pci.h>
22 #include <linux/string.h>
23 #include <linux/kernel.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
27 #include "ct20k2reg.h"
29 #if BITS_PER_LONG == 32
30 #define CT_XFI_DMA_MASK DMA_BIT_MASK(32) /* 32 bit PTE */
32 #define CT_XFI_DMA_MASK DMA_BIT_MASK(64) /* 64 bit PTE */
39 unsigned char addr_size;
40 unsigned char data_size;
43 static u32 hw_read_20kx(struct hw *hw, u32 reg);
44 static void hw_write_20kx(struct hw *hw, u32 reg, u32 data);
47 * Type definition block.
48 * The layout of control structures can be directly applied on 20k2 chip.
52 * SRC control block definitions.
55 /* SRC resource control block */
56 #define SRCCTL_STATE 0x00000007
57 #define SRCCTL_BM 0x00000008
58 #define SRCCTL_RSR 0x00000030
59 #define SRCCTL_SF 0x000001C0
60 #define SRCCTL_WR 0x00000200
61 #define SRCCTL_PM 0x00000400
62 #define SRCCTL_ROM 0x00001800
63 #define SRCCTL_VO 0x00002000
64 #define SRCCTL_ST 0x00004000
65 #define SRCCTL_IE 0x00008000
66 #define SRCCTL_ILSZ 0x000F0000
67 #define SRCCTL_BP 0x00100000
69 #define SRCCCR_CISZ 0x000007FF
70 #define SRCCCR_CWA 0x001FF800
71 #define SRCCCR_D 0x00200000
72 #define SRCCCR_RS 0x01C00000
73 #define SRCCCR_NAL 0x3E000000
74 #define SRCCCR_RA 0xC0000000
76 #define SRCCA_CA 0x0FFFFFFF
77 #define SRCCA_RS 0xE0000000
79 #define SRCSA_SA 0x0FFFFFFF
81 #define SRCLA_LA 0x0FFFFFFF
83 /* Mixer Parameter Ring ram Low and Hight register.
84 * Fixed-point value in 8.24 format for parameter channel */
85 #define MPRLH_PITCH 0xFFFFFFFF
87 /* SRC resource register dirty flags */
96 u16 czbfs:1; /* Clear Z-Buffers */
102 struct src_rsc_ctrl_blk {
109 union src_dirty dirty;
112 /* SRC manager control block */
113 union src_mgr_dirty {
129 struct src_mgr_ctrl_blk {
132 union src_mgr_dirty dirty;
135 /* SRCIMP manager control block */
136 #define SRCAIM_ARC 0x00000FFF
137 #define SRCAIM_NXT 0x00FF0000
138 #define SRCAIM_SRC 0xFF000000
145 /* SRCIMP manager register dirty flags */
146 union srcimp_mgr_dirty {
154 struct srcimp_mgr_ctrl_blk {
155 struct srcimap srcimap;
156 union srcimp_mgr_dirty dirty;
160 * Function implementation block.
163 static int src_get_rsc_ctrl_blk(void **rblk)
165 struct src_rsc_ctrl_blk *blk;
168 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
177 static int src_put_rsc_ctrl_blk(void *blk)
184 static int src_set_state(void *blk, unsigned int state)
186 struct src_rsc_ctrl_blk *ctl = blk;
188 set_field(&ctl->ctl, SRCCTL_STATE, state);
189 ctl->dirty.bf.ctl = 1;
193 static int src_set_bm(void *blk, unsigned int bm)
195 struct src_rsc_ctrl_blk *ctl = blk;
197 set_field(&ctl->ctl, SRCCTL_BM, bm);
198 ctl->dirty.bf.ctl = 1;
202 static int src_set_rsr(void *blk, unsigned int rsr)
204 struct src_rsc_ctrl_blk *ctl = blk;
206 set_field(&ctl->ctl, SRCCTL_RSR, rsr);
207 ctl->dirty.bf.ctl = 1;
211 static int src_set_sf(void *blk, unsigned int sf)
213 struct src_rsc_ctrl_blk *ctl = blk;
215 set_field(&ctl->ctl, SRCCTL_SF, sf);
216 ctl->dirty.bf.ctl = 1;
220 static int src_set_wr(void *blk, unsigned int wr)
222 struct src_rsc_ctrl_blk *ctl = blk;
224 set_field(&ctl->ctl, SRCCTL_WR, wr);
225 ctl->dirty.bf.ctl = 1;
229 static int src_set_pm(void *blk, unsigned int pm)
231 struct src_rsc_ctrl_blk *ctl = blk;
233 set_field(&ctl->ctl, SRCCTL_PM, pm);
234 ctl->dirty.bf.ctl = 1;
238 static int src_set_rom(void *blk, unsigned int rom)
240 struct src_rsc_ctrl_blk *ctl = blk;
242 set_field(&ctl->ctl, SRCCTL_ROM, rom);
243 ctl->dirty.bf.ctl = 1;
247 static int src_set_vo(void *blk, unsigned int vo)
249 struct src_rsc_ctrl_blk *ctl = blk;
251 set_field(&ctl->ctl, SRCCTL_VO, vo);
252 ctl->dirty.bf.ctl = 1;
256 static int src_set_st(void *blk, unsigned int st)
258 struct src_rsc_ctrl_blk *ctl = blk;
260 set_field(&ctl->ctl, SRCCTL_ST, st);
261 ctl->dirty.bf.ctl = 1;
265 static int src_set_ie(void *blk, unsigned int ie)
267 struct src_rsc_ctrl_blk *ctl = blk;
269 set_field(&ctl->ctl, SRCCTL_IE, ie);
270 ctl->dirty.bf.ctl = 1;
274 static int src_set_ilsz(void *blk, unsigned int ilsz)
276 struct src_rsc_ctrl_blk *ctl = blk;
278 set_field(&ctl->ctl, SRCCTL_ILSZ, ilsz);
279 ctl->dirty.bf.ctl = 1;
283 static int src_set_bp(void *blk, unsigned int bp)
285 struct src_rsc_ctrl_blk *ctl = blk;
287 set_field(&ctl->ctl, SRCCTL_BP, bp);
288 ctl->dirty.bf.ctl = 1;
292 static int src_set_cisz(void *blk, unsigned int cisz)
294 struct src_rsc_ctrl_blk *ctl = blk;
296 set_field(&ctl->ccr, SRCCCR_CISZ, cisz);
297 ctl->dirty.bf.ccr = 1;
301 static int src_set_ca(void *blk, unsigned int ca)
303 struct src_rsc_ctrl_blk *ctl = blk;
305 set_field(&ctl->ca, SRCCA_CA, ca);
306 ctl->dirty.bf.ca = 1;
310 static int src_set_sa(void *blk, unsigned int sa)
312 struct src_rsc_ctrl_blk *ctl = blk;
314 set_field(&ctl->sa, SRCSA_SA, sa);
315 ctl->dirty.bf.sa = 1;
319 static int src_set_la(void *blk, unsigned int la)
321 struct src_rsc_ctrl_blk *ctl = blk;
323 set_field(&ctl->la, SRCLA_LA, la);
324 ctl->dirty.bf.la = 1;
328 static int src_set_pitch(void *blk, unsigned int pitch)
330 struct src_rsc_ctrl_blk *ctl = blk;
332 set_field(&ctl->mpr, MPRLH_PITCH, pitch);
333 ctl->dirty.bf.mpr = 1;
337 static int src_set_clear_zbufs(void *blk, unsigned int clear)
339 ((struct src_rsc_ctrl_blk *)blk)->dirty.bf.czbfs = (clear ? 1 : 0);
343 static int src_set_dirty(void *blk, unsigned int flags)
345 ((struct src_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff);
349 static int src_set_dirty_all(void *blk)
351 ((struct src_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0);
355 #define AR_SLOT_SIZE 4096
356 #define AR_SLOT_BLOCK_SIZE 16
357 #define AR_PTS_PITCH 6
358 #define AR_PARAM_SRC_OFFSET 0x60
360 static unsigned int src_param_pitch_mixer(unsigned int src_idx)
362 return ((src_idx << 4) + AR_PTS_PITCH + AR_SLOT_SIZE
363 - AR_PARAM_SRC_OFFSET) % AR_SLOT_SIZE;
367 static int src_commit_write(struct hw *hw, unsigned int idx, void *blk)
369 struct src_rsc_ctrl_blk *ctl = blk;
372 if (ctl->dirty.bf.czbfs) {
373 /* Clear Z-Buffer registers */
374 for (i = 0; i < 8; i++)
375 hw_write_20kx(hw, SRC_UPZ+idx*0x100+i*0x4, 0);
377 for (i = 0; i < 4; i++)
378 hw_write_20kx(hw, SRC_DN0Z+idx*0x100+i*0x4, 0);
380 for (i = 0; i < 8; i++)
381 hw_write_20kx(hw, SRC_DN1Z+idx*0x100+i*0x4, 0);
383 ctl->dirty.bf.czbfs = 0;
385 if (ctl->dirty.bf.mpr) {
386 /* Take the parameter mixer resource in the same group as that
387 * the idx src is in for simplicity. Unlike src, all conjugate
388 * parameter mixer resources must be programmed for
389 * corresponding conjugate src resources. */
390 unsigned int pm_idx = src_param_pitch_mixer(idx);
391 hw_write_20kx(hw, MIXER_PRING_LO_HI+4*pm_idx, ctl->mpr);
392 hw_write_20kx(hw, MIXER_PMOPLO+8*pm_idx, 0x3);
393 hw_write_20kx(hw, MIXER_PMOPHI+8*pm_idx, 0x0);
394 ctl->dirty.bf.mpr = 0;
396 if (ctl->dirty.bf.sa) {
397 hw_write_20kx(hw, SRC_SA+idx*0x100, ctl->sa);
398 ctl->dirty.bf.sa = 0;
400 if (ctl->dirty.bf.la) {
401 hw_write_20kx(hw, SRC_LA+idx*0x100, ctl->la);
402 ctl->dirty.bf.la = 0;
404 if (ctl->dirty.bf.ca) {
405 hw_write_20kx(hw, SRC_CA+idx*0x100, ctl->ca);
406 ctl->dirty.bf.ca = 0;
409 /* Write srccf register */
410 hw_write_20kx(hw, SRC_CF+idx*0x100, 0x0);
412 if (ctl->dirty.bf.ccr) {
413 hw_write_20kx(hw, SRC_CCR+idx*0x100, ctl->ccr);
414 ctl->dirty.bf.ccr = 0;
416 if (ctl->dirty.bf.ctl) {
417 hw_write_20kx(hw, SRC_CTL+idx*0x100, ctl->ctl);
418 ctl->dirty.bf.ctl = 0;
424 static int src_get_ca(struct hw *hw, unsigned int idx, void *blk)
426 struct src_rsc_ctrl_blk *ctl = blk;
428 ctl->ca = hw_read_20kx(hw, SRC_CA+idx*0x100);
429 ctl->dirty.bf.ca = 0;
431 return get_field(ctl->ca, SRCCA_CA);
434 static unsigned int src_get_dirty(void *blk)
436 return ((struct src_rsc_ctrl_blk *)blk)->dirty.data;
439 static unsigned int src_dirty_conj_mask(void)
444 static int src_mgr_enbs_src(void *blk, unsigned int idx)
446 ((struct src_mgr_ctrl_blk *)blk)->enbsa |= (0x1 << ((idx%128)/4));
447 ((struct src_mgr_ctrl_blk *)blk)->dirty.bf.enbsa = 1;
448 ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32));
452 static int src_mgr_enb_src(void *blk, unsigned int idx)
454 ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32));
455 ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32));
459 static int src_mgr_dsb_src(void *blk, unsigned int idx)
461 ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] &= ~(0x1 << (idx%32));
462 ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32));
466 static int src_mgr_commit_write(struct hw *hw, void *blk)
468 struct src_mgr_ctrl_blk *ctl = blk;
472 if (ctl->dirty.bf.enbsa) {
474 ret = hw_read_20kx(hw, SRC_ENBSTAT);
476 hw_write_20kx(hw, SRC_ENBSA, ctl->enbsa);
477 ctl->dirty.bf.enbsa = 0;
479 for (i = 0; i < 8; i++) {
480 if ((ctl->dirty.data & (0x1 << i))) {
481 hw_write_20kx(hw, SRC_ENB+(i*0x100), ctl->enb[i]);
482 ctl->dirty.data &= ~(0x1 << i);
489 static int src_mgr_get_ctrl_blk(void **rblk)
491 struct src_mgr_ctrl_blk *blk;
494 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
503 static int src_mgr_put_ctrl_blk(void *blk)
510 static int srcimp_mgr_get_ctrl_blk(void **rblk)
512 struct srcimp_mgr_ctrl_blk *blk;
515 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
524 static int srcimp_mgr_put_ctrl_blk(void *blk)
531 static int srcimp_mgr_set_imaparc(void *blk, unsigned int slot)
533 struct srcimp_mgr_ctrl_blk *ctl = blk;
535 set_field(&ctl->srcimap.srcaim, SRCAIM_ARC, slot);
536 ctl->dirty.bf.srcimap = 1;
540 static int srcimp_mgr_set_imapuser(void *blk, unsigned int user)
542 struct srcimp_mgr_ctrl_blk *ctl = blk;
544 set_field(&ctl->srcimap.srcaim, SRCAIM_SRC, user);
545 ctl->dirty.bf.srcimap = 1;
549 static int srcimp_mgr_set_imapnxt(void *blk, unsigned int next)
551 struct srcimp_mgr_ctrl_blk *ctl = blk;
553 set_field(&ctl->srcimap.srcaim, SRCAIM_NXT, next);
554 ctl->dirty.bf.srcimap = 1;
558 static int srcimp_mgr_set_imapaddr(void *blk, unsigned int addr)
560 ((struct srcimp_mgr_ctrl_blk *)blk)->srcimap.idx = addr;
561 ((struct srcimp_mgr_ctrl_blk *)blk)->dirty.bf.srcimap = 1;
565 static int srcimp_mgr_commit_write(struct hw *hw, void *blk)
567 struct srcimp_mgr_ctrl_blk *ctl = blk;
569 if (ctl->dirty.bf.srcimap) {
570 hw_write_20kx(hw, SRC_IMAP+ctl->srcimap.idx*0x100,
571 ctl->srcimap.srcaim);
572 ctl->dirty.bf.srcimap = 0;
579 * AMIXER control block definitions.
582 #define AMOPLO_M 0x00000003
583 #define AMOPLO_IV 0x00000004
584 #define AMOPLO_X 0x0003FFF0
585 #define AMOPLO_Y 0xFFFC0000
587 #define AMOPHI_SADR 0x000000FF
588 #define AMOPHI_SE 0x80000000
590 /* AMIXER resource register dirty flags */
600 /* AMIXER resource control block */
601 struct amixer_rsc_ctrl_blk {
604 union amixer_dirty dirty;
607 static int amixer_set_mode(void *blk, unsigned int mode)
609 struct amixer_rsc_ctrl_blk *ctl = blk;
611 set_field(&ctl->amoplo, AMOPLO_M, mode);
612 ctl->dirty.bf.amoplo = 1;
616 static int amixer_set_iv(void *blk, unsigned int iv)
618 struct amixer_rsc_ctrl_blk *ctl = blk;
620 set_field(&ctl->amoplo, AMOPLO_IV, iv);
621 ctl->dirty.bf.amoplo = 1;
625 static int amixer_set_x(void *blk, unsigned int x)
627 struct amixer_rsc_ctrl_blk *ctl = blk;
629 set_field(&ctl->amoplo, AMOPLO_X, x);
630 ctl->dirty.bf.amoplo = 1;
634 static int amixer_set_y(void *blk, unsigned int y)
636 struct amixer_rsc_ctrl_blk *ctl = blk;
638 set_field(&ctl->amoplo, AMOPLO_Y, y);
639 ctl->dirty.bf.amoplo = 1;
643 static int amixer_set_sadr(void *blk, unsigned int sadr)
645 struct amixer_rsc_ctrl_blk *ctl = blk;
647 set_field(&ctl->amophi, AMOPHI_SADR, sadr);
648 ctl->dirty.bf.amophi = 1;
652 static int amixer_set_se(void *blk, unsigned int se)
654 struct amixer_rsc_ctrl_blk *ctl = blk;
656 set_field(&ctl->amophi, AMOPHI_SE, se);
657 ctl->dirty.bf.amophi = 1;
661 static int amixer_set_dirty(void *blk, unsigned int flags)
663 ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff);
667 static int amixer_set_dirty_all(void *blk)
669 ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0);
673 static int amixer_commit_write(struct hw *hw, unsigned int idx, void *blk)
675 struct amixer_rsc_ctrl_blk *ctl = blk;
677 if (ctl->dirty.bf.amoplo || ctl->dirty.bf.amophi) {
678 hw_write_20kx(hw, MIXER_AMOPLO+idx*8, ctl->amoplo);
679 ctl->dirty.bf.amoplo = 0;
680 hw_write_20kx(hw, MIXER_AMOPHI+idx*8, ctl->amophi);
681 ctl->dirty.bf.amophi = 0;
687 static int amixer_get_y(void *blk)
689 struct amixer_rsc_ctrl_blk *ctl = blk;
691 return get_field(ctl->amoplo, AMOPLO_Y);
694 static unsigned int amixer_get_dirty(void *blk)
696 return ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data;
699 static int amixer_rsc_get_ctrl_blk(void **rblk)
701 struct amixer_rsc_ctrl_blk *blk;
704 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
713 static int amixer_rsc_put_ctrl_blk(void *blk)
720 static int amixer_mgr_get_ctrl_blk(void **rblk)
727 static int amixer_mgr_put_ctrl_blk(void *blk)
733 * DAIO control block definitions.
736 /* Receiver Sample Rate Tracker Control register */
737 #define SRTCTL_SRCO 0x000000FF
738 #define SRTCTL_SRCM 0x0000FF00
739 #define SRTCTL_RSR 0x00030000
740 #define SRTCTL_DRAT 0x00300000
741 #define SRTCTL_EC 0x01000000
742 #define SRTCTL_ET 0x10000000
744 /* DAIO Receiver register dirty flags */
753 /* DAIO Receiver control block */
754 struct dai_ctrl_blk {
756 union dai_dirty dirty;
759 /* Audio Input Mapper RAM */
760 #define AIM_ARC 0x00000FFF
761 #define AIM_NXT 0x007F0000
768 /* Audio Transmitter Control and Status register */
769 #define ATXCTL_EN 0x00000001
770 #define ATXCTL_MODE 0x00000010
771 #define ATXCTL_CD 0x00000020
772 #define ATXCTL_RAW 0x00000100
773 #define ATXCTL_MT 0x00000200
774 #define ATXCTL_NUC 0x00003000
775 #define ATXCTL_BEN 0x00010000
776 #define ATXCTL_BMUX 0x00700000
777 #define ATXCTL_B24 0x01000000
778 #define ATXCTL_CPF 0x02000000
779 #define ATXCTL_RIV 0x10000000
780 #define ATXCTL_LIV 0x20000000
781 #define ATXCTL_RSAT 0x40000000
782 #define ATXCTL_LSAT 0x80000000
784 /* XDIF Transmitter register dirty flags */
793 /* XDIF Transmitter control block */
794 struct dao_ctrl_blk {
795 /* XDIF Transmitter Channel Status Low Register */
797 union dao_dirty dirty;
800 /* Audio Receiver Control register */
801 #define ARXCTL_EN 0x00000001
803 /* DAIO manager register dirty flags */
804 union daio_mgr_dirty {
814 /* DAIO manager control block */
815 struct daio_mgr_ctrl_blk {
816 struct daoimap daoimap;
817 unsigned int txctl[8];
818 unsigned int rxctl[8];
819 union daio_mgr_dirty dirty;
822 static int dai_srt_set_srco(void *blk, unsigned int src)
824 struct dai_ctrl_blk *ctl = blk;
826 set_field(&ctl->srt, SRTCTL_SRCO, src);
827 ctl->dirty.bf.srt = 1;
831 static int dai_srt_set_srcm(void *blk, unsigned int src)
833 struct dai_ctrl_blk *ctl = blk;
835 set_field(&ctl->srt, SRTCTL_SRCM, src);
836 ctl->dirty.bf.srt = 1;
840 static int dai_srt_set_rsr(void *blk, unsigned int rsr)
842 struct dai_ctrl_blk *ctl = blk;
844 set_field(&ctl->srt, SRTCTL_RSR, rsr);
845 ctl->dirty.bf.srt = 1;
849 static int dai_srt_set_drat(void *blk, unsigned int drat)
851 struct dai_ctrl_blk *ctl = blk;
853 set_field(&ctl->srt, SRTCTL_DRAT, drat);
854 ctl->dirty.bf.srt = 1;
858 static int dai_srt_set_ec(void *blk, unsigned int ec)
860 struct dai_ctrl_blk *ctl = blk;
862 set_field(&ctl->srt, SRTCTL_EC, ec ? 1 : 0);
863 ctl->dirty.bf.srt = 1;
867 static int dai_srt_set_et(void *blk, unsigned int et)
869 struct dai_ctrl_blk *ctl = blk;
871 set_field(&ctl->srt, SRTCTL_ET, et ? 1 : 0);
872 ctl->dirty.bf.srt = 1;
876 static int dai_commit_write(struct hw *hw, unsigned int idx, void *blk)
878 struct dai_ctrl_blk *ctl = blk;
880 if (ctl->dirty.bf.srt) {
881 hw_write_20kx(hw, AUDIO_IO_RX_SRT_CTL+0x40*idx, ctl->srt);
882 ctl->dirty.bf.srt = 0;
888 static int dai_get_ctrl_blk(void **rblk)
890 struct dai_ctrl_blk *blk;
893 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
902 static int dai_put_ctrl_blk(void *blk)
909 static int dao_set_spos(void *blk, unsigned int spos)
911 ((struct dao_ctrl_blk *)blk)->atxcsl = spos;
912 ((struct dao_ctrl_blk *)blk)->dirty.bf.atxcsl = 1;
916 static int dao_commit_write(struct hw *hw, unsigned int idx, void *blk)
918 struct dao_ctrl_blk *ctl = blk;
920 if (ctl->dirty.bf.atxcsl) {
923 hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+0x40*idx,
926 ctl->dirty.bf.atxcsl = 0;
932 static int dao_get_spos(void *blk, unsigned int *spos)
934 *spos = ((struct dao_ctrl_blk *)blk)->atxcsl;
938 static int dao_get_ctrl_blk(void **rblk)
940 struct dao_ctrl_blk *blk;
943 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
952 static int dao_put_ctrl_blk(void *blk)
959 static int daio_mgr_enb_dai(void *blk, unsigned int idx)
961 struct daio_mgr_ctrl_blk *ctl = blk;
963 set_field(&ctl->rxctl[idx], ARXCTL_EN, 1);
964 ctl->dirty.bf.arxctl |= (0x1 << idx);
968 static int daio_mgr_dsb_dai(void *blk, unsigned int idx)
970 struct daio_mgr_ctrl_blk *ctl = blk;
972 set_field(&ctl->rxctl[idx], ARXCTL_EN, 0);
974 ctl->dirty.bf.arxctl |= (0x1 << idx);
978 static int daio_mgr_enb_dao(void *blk, unsigned int idx)
980 struct daio_mgr_ctrl_blk *ctl = blk;
982 set_field(&ctl->txctl[idx], ATXCTL_EN, 1);
983 ctl->dirty.bf.atxctl |= (0x1 << idx);
987 static int daio_mgr_dsb_dao(void *blk, unsigned int idx)
989 struct daio_mgr_ctrl_blk *ctl = blk;
991 set_field(&ctl->txctl[idx], ATXCTL_EN, 0);
992 ctl->dirty.bf.atxctl |= (0x1 << idx);
996 static int daio_mgr_dao_init(void *blk, unsigned int idx, unsigned int conf)
998 struct daio_mgr_ctrl_blk *ctl = blk;
1002 switch ((conf & 0x7)) {
1004 set_field(&ctl->txctl[idx], ATXCTL_NUC, 0);
1007 set_field(&ctl->txctl[idx], ATXCTL_NUC, 1);
1010 set_field(&ctl->txctl[idx], ATXCTL_NUC, 2);
1013 set_field(&ctl->txctl[idx], ATXCTL_NUC, 3);
1019 set_field(&ctl->txctl[idx], ATXCTL_CD, (!(conf & 0x7)));
1021 set_field(&ctl->txctl[idx], ATXCTL_LIV, (conf >> 4) & 0x1);
1023 set_field(&ctl->txctl[idx], ATXCTL_RIV, (conf >> 4) & 0x1);
1024 set_field(&ctl->txctl[idx], ATXCTL_RAW,
1025 ((conf >> 3) & 0x1) ? 0 : 0);
1026 ctl->dirty.bf.atxctl |= (0x1 << idx);
1034 static int daio_mgr_set_imaparc(void *blk, unsigned int slot)
1036 struct daio_mgr_ctrl_blk *ctl = blk;
1038 set_field(&ctl->daoimap.aim, AIM_ARC, slot);
1039 ctl->dirty.bf.daoimap = 1;
1043 static int daio_mgr_set_imapnxt(void *blk, unsigned int next)
1045 struct daio_mgr_ctrl_blk *ctl = blk;
1047 set_field(&ctl->daoimap.aim, AIM_NXT, next);
1048 ctl->dirty.bf.daoimap = 1;
1052 static int daio_mgr_set_imapaddr(void *blk, unsigned int addr)
1054 ((struct daio_mgr_ctrl_blk *)blk)->daoimap.idx = addr;
1055 ((struct daio_mgr_ctrl_blk *)blk)->dirty.bf.daoimap = 1;
1059 static int daio_mgr_commit_write(struct hw *hw, void *blk)
1061 struct daio_mgr_ctrl_blk *ctl = blk;
1065 for (i = 0; i < 8; i++) {
1066 if ((ctl->dirty.bf.atxctl & (0x1 << i))) {
1067 data = ctl->txctl[i];
1068 hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), data);
1069 ctl->dirty.bf.atxctl &= ~(0x1 << i);
1072 if ((ctl->dirty.bf.arxctl & (0x1 << i))) {
1073 data = ctl->rxctl[i];
1074 hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), data);
1075 ctl->dirty.bf.arxctl &= ~(0x1 << i);
1079 if (ctl->dirty.bf.daoimap) {
1080 hw_write_20kx(hw, AUDIO_IO_AIM+ctl->daoimap.idx*4,
1082 ctl->dirty.bf.daoimap = 0;
1088 static int daio_mgr_get_ctrl_blk(struct hw *hw, void **rblk)
1090 struct daio_mgr_ctrl_blk *blk;
1094 blk = kzalloc(sizeof(*blk), GFP_KERNEL);
1098 for (i = 0; i < 8; i++) {
1099 blk->txctl[i] = hw_read_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i));
1100 blk->rxctl[i] = hw_read_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i));
1108 static int daio_mgr_put_ctrl_blk(void *blk)
1115 /* Timer interrupt */
1116 static int set_timer_irq(struct hw *hw, int enable)
1118 hw_write_20kx(hw, GIE, enable ? IT_INT : 0);
1122 static int set_timer_tick(struct hw *hw, unsigned int ticks)
1125 ticks |= TIMR_IE | TIMR_IP;
1126 hw_write_20kx(hw, TIMR, ticks);
1130 static unsigned int get_wc(struct hw *hw)
1132 return hw_read_20kx(hw, WC);
1135 /* Card hardware initialization block */
1137 unsigned int msr; /* master sample rate in rsrs */
1141 unsigned int msr; /* master sample rate in rsrs */
1142 unsigned char input; /* the input source of ADC */
1143 unsigned char mic20db; /* boost mic by 20db if input is microphone */
1147 unsigned int msr; /* master sample rate in rsrs */
1151 unsigned long vm_pgt_phys;
1154 static int hw_daio_init(struct hw *hw, const struct daio_conf *info)
1159 /* Program I2S with proper sample rate and enable the correct I2S
1160 * channel. ED(0/8/16/24): Enable all I2S/I2X master clock output */
1161 if (1 == info->msr) {
1162 hw_write_20kx(hw, AUDIO_IO_MCLK, 0x01010101);
1163 hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x01010101);
1164 hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
1165 } else if (2 == info->msr) {
1166 hw_write_20kx(hw, AUDIO_IO_MCLK, 0x11111111);
1167 /* Specify all playing 96khz
1171 * RTB [12:13] - 96kHz
1173 * RTC [20:21] - 96kHz
1175 * RTD [28:29] - 96kHz */
1176 hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x11111111);
1177 hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
1179 printk(KERN_ALERT "ctxfi: ERROR!!! Invalid sampling rate!!!\n");
1183 for (i = 0; i < 8; i++) {
1185 /* 1st 3 channels are SPDIFs (SB0960) */
1191 hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), data);
1192 hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), data);
1194 /* Initialize the SPDIF Out Channel status registers.
1195 * The value specified here is based on the typical
1196 * values provided in the specification, namely: Clock
1197 * Accuracy of 1000ppm, Sample Rate of 48KHz,
1198 * unspecified source number, Generation status = 1,
1199 * Category code = 0x12 (Digital Signal Mixer),
1200 * Mode = 0, Emph = 0, Copy Permitted, AN = 0
1201 * (indicating that we're transmitting digital audio,
1202 * and the Professional Use bit is 0. */
1204 hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+(0x40*i),
1205 0x02109204); /* Default to 48kHz */
1207 hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_H+(0x40*i), 0x0B);
1209 /* Next 5 channels are I2S (SB0960) */
1211 hw_write_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i), data);
1212 if (2 == info->msr) {
1213 /* Four channels per sample period */
1216 hw_write_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i), data);
1223 /* TRANSPORT operations */
1224 static int hw_trn_init(struct hw *hw, const struct trn_conf *info)
1227 u32 ptp_phys_low, ptp_phys_high;
1230 /* Set up device page table */
1231 if ((~0UL) == info->vm_pgt_phys) {
1232 printk(KERN_ALERT "ctxfi: "
1233 "Wrong device page table page address!!!\n");
1237 vmctl = 0x80000C0F; /* 32-bit, 4k-size page */
1238 ptp_phys_low = (u32)info->vm_pgt_phys;
1239 ptp_phys_high = upper_32_bits(info->vm_pgt_phys);
1240 if (sizeof(void *) == 8) /* 64bit address */
1242 /* Write page table physical address to all PTPAL registers */
1243 for (i = 0; i < 64; i++) {
1244 hw_write_20kx(hw, VMEM_PTPAL+(16*i), ptp_phys_low);
1245 hw_write_20kx(hw, VMEM_PTPAH+(16*i), ptp_phys_high);
1247 /* Enable virtual memory transfer */
1248 hw_write_20kx(hw, VMEM_CTL, vmctl);
1249 /* Enable transport bus master and queueing of request */
1250 hw_write_20kx(hw, TRANSPORT_CTL, 0x03);
1251 hw_write_20kx(hw, TRANSPORT_INT, 0x200c01);
1252 /* Enable transport ring */
1253 data = hw_read_20kx(hw, TRANSPORT_ENB);
1254 hw_write_20kx(hw, TRANSPORT_ENB, (data | 0x03));
1259 /* Card initialization */
1260 #define GCTL_AIE 0x00000001
1261 #define GCTL_UAA 0x00000002
1262 #define GCTL_DPC 0x00000004
1263 #define GCTL_DBP 0x00000008
1264 #define GCTL_ABP 0x00000010
1265 #define GCTL_TBP 0x00000020
1266 #define GCTL_SBP 0x00000040
1267 #define GCTL_FBP 0x00000080
1268 #define GCTL_ME 0x00000100
1269 #define GCTL_AID 0x00001000
1271 #define PLLCTL_SRC 0x00000007
1272 #define PLLCTL_SPE 0x00000008
1273 #define PLLCTL_RD 0x000000F0
1274 #define PLLCTL_FD 0x0001FF00
1275 #define PLLCTL_OD 0x00060000
1276 #define PLLCTL_B 0x00080000
1277 #define PLLCTL_AS 0x00100000
1278 #define PLLCTL_LF 0x03E00000
1279 #define PLLCTL_SPS 0x1C000000
1280 #define PLLCTL_AD 0x60000000
1282 #define PLLSTAT_CCS 0x00000007
1283 #define PLLSTAT_SPL 0x00000008
1284 #define PLLSTAT_CRD 0x000000F0
1285 #define PLLSTAT_CFD 0x0001FF00
1286 #define PLLSTAT_SL 0x00020000
1287 #define PLLSTAT_FAS 0x00040000
1288 #define PLLSTAT_B 0x00080000
1289 #define PLLSTAT_PD 0x00100000
1290 #define PLLSTAT_OCA 0x00200000
1291 #define PLLSTAT_NCA 0x00400000
1293 static int hw_pll_init(struct hw *hw, unsigned int rsr)
1295 unsigned int pllenb;
1296 unsigned int pllctl;
1297 unsigned int pllstat;
1301 hw_write_20kx(hw, PLL_ENB, pllenb);
1302 pllctl = 0x20D00000;
1303 set_field(&pllctl, PLLCTL_FD, 16 - 4);
1304 hw_write_20kx(hw, PLL_CTL, pllctl);
1306 pllctl = hw_read_20kx(hw, PLL_CTL);
1307 set_field(&pllctl, PLLCTL_B, 0);
1309 set_field(&pllctl, PLLCTL_FD, 16 - 2);
1310 set_field(&pllctl, PLLCTL_RD, 1 - 1);
1311 } else { /* 44100 */
1312 set_field(&pllctl, PLLCTL_FD, 147 - 2);
1313 set_field(&pllctl, PLLCTL_RD, 10 - 1);
1315 hw_write_20kx(hw, PLL_CTL, pllctl);
1317 for (i = 0; i < 1000; i++) {
1318 pllstat = hw_read_20kx(hw, PLL_STAT);
1319 if (get_field(pllstat, PLLSTAT_PD))
1322 if (get_field(pllstat, PLLSTAT_B) !=
1323 get_field(pllctl, PLLCTL_B))
1326 if (get_field(pllstat, PLLSTAT_CCS) !=
1327 get_field(pllctl, PLLCTL_SRC))
1330 if (get_field(pllstat, PLLSTAT_CRD) !=
1331 get_field(pllctl, PLLCTL_RD))
1334 if (get_field(pllstat, PLLSTAT_CFD) !=
1335 get_field(pllctl, PLLCTL_FD))
1341 printk(KERN_ALERT "ctxfi: PLL initialization failed!!!\n");
1348 static int hw_auto_init(struct hw *hw)
1353 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1354 set_field(&gctl, GCTL_AIE, 0);
1355 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1356 set_field(&gctl, GCTL_AIE, 1);
1357 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1359 for (i = 0; i < 400000; i++) {
1360 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1361 if (get_field(gctl, GCTL_AID))
1364 if (!get_field(gctl, GCTL_AID)) {
1365 printk(KERN_ALERT "ctxfi: Card Auto-init failed!!!\n");
1372 /* DAC operations */
1374 #define CS4382_MC1 0x1
1375 #define CS4382_MC2 0x2
1376 #define CS4382_MC3 0x3
1377 #define CS4382_FC 0x4
1378 #define CS4382_IC 0x5
1379 #define CS4382_XC1 0x6
1380 #define CS4382_VCA1 0x7
1381 #define CS4382_VCB1 0x8
1382 #define CS4382_XC2 0x9
1383 #define CS4382_VCA2 0xA
1384 #define CS4382_VCB2 0xB
1385 #define CS4382_XC3 0xC
1386 #define CS4382_VCA3 0xD
1387 #define CS4382_VCB3 0xE
1388 #define CS4382_XC4 0xF
1389 #define CS4382_VCA4 0x10
1390 #define CS4382_VCB4 0x11
1391 #define CS4382_CREV 0x12
1394 #define STATE_LOCKED 0x00
1395 #define STATE_UNLOCKED 0xAA
1396 #define DATA_READY 0x800000 /* Used with I2C_IF_STATUS */
1397 #define DATA_ABORT 0x10000 /* Used with I2C_IF_STATUS */
1399 #define I2C_STATUS_DCM 0x00000001
1400 #define I2C_STATUS_BC 0x00000006
1401 #define I2C_STATUS_APD 0x00000008
1402 #define I2C_STATUS_AB 0x00010000
1403 #define I2C_STATUS_DR 0x00800000
1405 #define I2C_ADDRESS_PTAD 0x0000FFFF
1406 #define I2C_ADDRESS_SLAD 0x007F0000
1408 struct regs_cs4382 {
1433 static int hw20k2_i2c_unlock_full_access(struct hw *hw)
1435 u8 UnlockKeySequence_FLASH_FULLACCESS_MODE[2] = {0xB3, 0xD4};
1437 /* Send keys for forced BIOS mode */
1438 hw_write_20kx(hw, I2C_IF_WLOCK,
1439 UnlockKeySequence_FLASH_FULLACCESS_MODE[0]);
1440 hw_write_20kx(hw, I2C_IF_WLOCK,
1441 UnlockKeySequence_FLASH_FULLACCESS_MODE[1]);
1442 /* Check whether the chip is unlocked */
1443 if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_UNLOCKED)
1449 static int hw20k2_i2c_lock_chip(struct hw *hw)
1452 hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED);
1453 hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED);
1454 if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_LOCKED)
1460 static int hw20k2_i2c_init(struct hw *hw, u8 dev_id, u8 addr_size, u8 data_size)
1462 struct hw20k2 *hw20k2 = (struct hw20k2 *)hw;
1464 unsigned int i2c_status;
1465 unsigned int i2c_addr;
1467 err = hw20k2_i2c_unlock_full_access(hw);
1471 hw20k2->addr_size = addr_size;
1472 hw20k2->data_size = data_size;
1473 hw20k2->dev_id = dev_id;
1476 set_field(&i2c_addr, I2C_ADDRESS_SLAD, dev_id);
1478 hw_write_20kx(hw, I2C_IF_ADDRESS, i2c_addr);
1480 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1482 set_field(&i2c_status, I2C_STATUS_DCM, 1); /* Direct control mode */
1484 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1489 static int hw20k2_i2c_uninit(struct hw *hw)
1491 unsigned int i2c_status;
1492 unsigned int i2c_addr;
1495 set_field(&i2c_addr, I2C_ADDRESS_SLAD, 0x57); /* I2C id */
1497 hw_write_20kx(hw, I2C_IF_ADDRESS, i2c_addr);
1499 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1501 set_field(&i2c_status, I2C_STATUS_DCM, 0); /* I2C mode */
1503 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1505 return hw20k2_i2c_lock_chip(hw);
1508 static int hw20k2_i2c_wait_data_ready(struct hw *hw)
1514 ret = hw_read_20kx(hw, I2C_IF_STATUS);
1515 } while ((!(ret & DATA_READY)) && --i);
1520 static int hw20k2_i2c_read(struct hw *hw, u16 addr, u32 *datap)
1522 struct hw20k2 *hw20k2 = (struct hw20k2 *)hw;
1523 unsigned int i2c_status;
1525 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1526 set_field(&i2c_status, I2C_STATUS_BC,
1527 (4 == hw20k2->addr_size) ? 0 : hw20k2->addr_size);
1528 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1529 if (!hw20k2_i2c_wait_data_ready(hw))
1532 hw_write_20kx(hw, I2C_IF_WDATA, addr);
1533 if (!hw20k2_i2c_wait_data_ready(hw))
1536 /* Force a read operation */
1537 hw_write_20kx(hw, I2C_IF_RDATA, 0);
1538 if (!hw20k2_i2c_wait_data_ready(hw))
1541 *datap = hw_read_20kx(hw, I2C_IF_RDATA);
1546 static int hw20k2_i2c_write(struct hw *hw, u16 addr, u32 data)
1548 struct hw20k2 *hw20k2 = (struct hw20k2 *)hw;
1549 unsigned int i2c_data = (data << (hw20k2->addr_size * 8)) | addr;
1550 unsigned int i2c_status;
1552 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1554 set_field(&i2c_status, I2C_STATUS_BC,
1555 (4 == (hw20k2->addr_size + hw20k2->data_size)) ?
1556 0 : (hw20k2->addr_size + hw20k2->data_size));
1558 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1559 hw20k2_i2c_wait_data_ready(hw);
1560 /* Dummy write to trigger the write oprtation */
1561 hw_write_20kx(hw, I2C_IF_WDATA, 0);
1562 hw20k2_i2c_wait_data_ready(hw);
1564 /* This is the real data */
1565 hw_write_20kx(hw, I2C_IF_WDATA, i2c_data);
1566 hw20k2_i2c_wait_data_ready(hw);
1571 static int hw_dac_init(struct hw *hw, const struct dac_conf *info)
1576 struct regs_cs4382 cs_read = {0};
1577 struct regs_cs4382 cs_def = {
1578 0x00000001, /* Mode Control 1 */
1579 0x00000000, /* Mode Control 2 */
1580 0x00000084, /* Mode Control 3 */
1581 0x00000000, /* Filter Control */
1582 0x00000000, /* Invert Control */
1583 0x00000024, /* Mixing Control Pair 1 */
1584 0x00000000, /* Vol Control A1 */
1585 0x00000000, /* Vol Control B1 */
1586 0x00000024, /* Mixing Control Pair 2 */
1587 0x00000000, /* Vol Control A2 */
1588 0x00000000, /* Vol Control B2 */
1589 0x00000024, /* Mixing Control Pair 3 */
1590 0x00000000, /* Vol Control A3 */
1591 0x00000000, /* Vol Control B3 */
1592 0x00000024, /* Mixing Control Pair 4 */
1593 0x00000000, /* Vol Control A4 */
1594 0x00000000 /* Vol Control B4 */
1597 /* Set DAC reset bit as output */
1598 data = hw_read_20kx(hw, GPIO_CTRL);
1600 hw_write_20kx(hw, GPIO_CTRL, data);
1602 err = hw20k2_i2c_init(hw, 0x18, 1, 1);
1606 for (i = 0; i < 2; i++) {
1607 /* Reset DAC twice just in-case the chip
1608 * didn't initialized properly */
1609 data = hw_read_20kx(hw, GPIO_DATA);
1610 /* GPIO data bit 1 */
1612 hw_write_20kx(hw, GPIO_DATA, data);
1615 hw_write_20kx(hw, GPIO_DATA, data);
1618 /* Reset the 2nd time */
1620 hw_write_20kx(hw, GPIO_DATA, data);
1623 hw_write_20kx(hw, GPIO_DATA, data);
1626 if (hw20k2_i2c_read(hw, CS4382_MC1, &cs_read.mode_control_1))
1629 if (hw20k2_i2c_read(hw, CS4382_MC2, &cs_read.mode_control_2))
1632 if (hw20k2_i2c_read(hw, CS4382_MC3, &cs_read.mode_control_3))
1635 if (hw20k2_i2c_read(hw, CS4382_FC, &cs_read.filter_control))
1638 if (hw20k2_i2c_read(hw, CS4382_IC, &cs_read.invert_control))
1641 if (hw20k2_i2c_read(hw, CS4382_XC1, &cs_read.mix_control_P1))
1644 if (hw20k2_i2c_read(hw, CS4382_VCA1, &cs_read.vol_control_A1))
1647 if (hw20k2_i2c_read(hw, CS4382_VCB1, &cs_read.vol_control_B1))
1650 if (hw20k2_i2c_read(hw, CS4382_XC2, &cs_read.mix_control_P2))
1653 if (hw20k2_i2c_read(hw, CS4382_VCA2, &cs_read.vol_control_A2))
1656 if (hw20k2_i2c_read(hw, CS4382_VCB2, &cs_read.vol_control_B2))
1659 if (hw20k2_i2c_read(hw, CS4382_XC3, &cs_read.mix_control_P3))
1662 if (hw20k2_i2c_read(hw, CS4382_VCA3, &cs_read.vol_control_A3))
1665 if (hw20k2_i2c_read(hw, CS4382_VCB3, &cs_read.vol_control_B3))
1668 if (hw20k2_i2c_read(hw, CS4382_XC4, &cs_read.mix_control_P4))
1671 if (hw20k2_i2c_read(hw, CS4382_VCA4, &cs_read.vol_control_A4))
1674 if (hw20k2_i2c_read(hw, CS4382_VCB4, &cs_read.vol_control_B4))
1677 if (memcmp(&cs_read, &cs_def, sizeof(cs_read)))
1686 /* Note: Every I2C write must have some delay.
1687 * This is not a requirement but the delay works here... */
1688 hw20k2_i2c_write(hw, CS4382_MC1, 0x80);
1689 hw20k2_i2c_write(hw, CS4382_MC2, 0x10);
1690 if (1 == info->msr) {
1691 hw20k2_i2c_write(hw, CS4382_XC1, 0x24);
1692 hw20k2_i2c_write(hw, CS4382_XC2, 0x24);
1693 hw20k2_i2c_write(hw, CS4382_XC3, 0x24);
1694 hw20k2_i2c_write(hw, CS4382_XC4, 0x24);
1695 } else if (2 == info->msr) {
1696 hw20k2_i2c_write(hw, CS4382_XC1, 0x25);
1697 hw20k2_i2c_write(hw, CS4382_XC2, 0x25);
1698 hw20k2_i2c_write(hw, CS4382_XC3, 0x25);
1699 hw20k2_i2c_write(hw, CS4382_XC4, 0x25);
1701 hw20k2_i2c_write(hw, CS4382_XC1, 0x26);
1702 hw20k2_i2c_write(hw, CS4382_XC2, 0x26);
1703 hw20k2_i2c_write(hw, CS4382_XC3, 0x26);
1704 hw20k2_i2c_write(hw, CS4382_XC4, 0x26);
1710 hw20k2_i2c_uninit(hw);
1714 /* ADC operations */
1715 #define MAKE_WM8775_ADDR(addr, data) (u32)(((addr<<1)&0xFE)|((data>>8)&0x1))
1716 #define MAKE_WM8775_DATA(data) (u32)(data&0xFF)
1718 #define WM8775_IC 0x0B
1719 #define WM8775_MMC 0x0C
1720 #define WM8775_AADCL 0x0E
1721 #define WM8775_AADCR 0x0F
1722 #define WM8775_ADCMC 0x15
1723 #define WM8775_RESET 0x17
1725 static int hw_is_adc_input_selected(struct hw *hw, enum ADCSRC type)
1729 data = hw_read_20kx(hw, GPIO_DATA);
1732 data = (data & (0x1 << 14)) ? 1 : 0;
1735 data = (data & (0x1 << 14)) ? 0 : 1;
1743 static int hw_adc_input_select(struct hw *hw, enum ADCSRC type)
1747 data = hw_read_20kx(hw, GPIO_DATA);
1750 data |= (0x1 << 14);
1751 hw_write_20kx(hw, GPIO_DATA, data);
1752 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x101),
1753 MAKE_WM8775_DATA(0x101)); /* Mic-in */
1754 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xE7),
1755 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1756 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xE7),
1757 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1760 data &= ~(0x1 << 14);
1761 hw_write_20kx(hw, GPIO_DATA, data);
1762 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x102),
1763 MAKE_WM8775_DATA(0x102)); /* Line-in */
1764 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xCF),
1765 MAKE_WM8775_DATA(0xCF)); /* No boost */
1766 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
1767 MAKE_WM8775_DATA(0xCF)); /* No boost */
1776 static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
1779 u32 mux = 2, data, ctl;
1781 /* Set ADC reset bit as output */
1782 data = hw_read_20kx(hw, GPIO_CTRL);
1783 data |= (0x1 << 15);
1784 hw_write_20kx(hw, GPIO_CTRL, data);
1786 /* Initialize I2C */
1787 err = hw20k2_i2c_init(hw, 0x1A, 1, 1);
1789 printk(KERN_ALERT "ctxfi: Failure to acquire I2C!!!\n");
1793 /* Make ADC in normal operation */
1794 data = hw_read_20kx(hw, GPIO_DATA);
1795 data &= ~(0x1 << 15);
1797 data |= (0x1 << 15);
1798 hw_write_20kx(hw, GPIO_DATA, data);
1801 /* Set the master mode (256fs) */
1802 if (1 == info->msr) {
1803 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x02),
1804 MAKE_WM8775_DATA(0x02));
1805 } else if (2 == info->msr) {
1806 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x0A),
1807 MAKE_WM8775_DATA(0x0A));
1809 printk(KERN_ALERT "ctxfi: Invalid master sampling "
1810 "rate (msr %d)!!!\n", info->msr);
1815 /* Configure GPIO bit 14 change to line-in/mic-in */
1816 ctl = hw_read_20kx(hw, GPIO_CTRL);
1818 hw_write_20kx(hw, GPIO_CTRL, ctl);
1820 /* Check using Mic-in or Line-in */
1821 data = hw_read_20kx(hw, GPIO_DATA);
1824 /* Configures GPIO data to select Mic-in */
1826 hw_write_20kx(hw, GPIO_DATA, data);
1828 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x101),
1829 MAKE_WM8775_DATA(0x101)); /* Mic-in */
1830 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xE7),
1831 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1832 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xE7),
1833 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1834 } else if (mux == 2) {
1835 /* Configures GPIO data to select Line-in */
1836 data &= ~(0x1 << 14);
1837 hw_write_20kx(hw, GPIO_DATA, data);
1840 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x102),
1841 MAKE_WM8775_DATA(0x102)); /* Line-in */
1842 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xCF),
1843 MAKE_WM8775_DATA(0xCF)); /* No boost */
1844 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
1845 MAKE_WM8775_DATA(0xCF)); /* No boost */
1847 printk(KERN_ALERT "ctxfi: ERROR!!! Invalid input mux!!!\n");
1855 hw20k2_i2c_uninit(hw);
1859 static int hw_have_digit_io_switch(struct hw *hw)
1864 static irqreturn_t ct_20k2_interrupt(int irq, void *dev_id)
1866 struct hw *hw = dev_id;
1867 unsigned int status;
1869 status = hw_read_20kx(hw, GIP);
1873 if (hw->irq_callback)
1874 hw->irq_callback(hw->irq_callback_data, status);
1876 hw_write_20kx(hw, GIP, status);
1880 static int hw_card_start(struct hw *hw)
1883 struct pci_dev *pci = hw->pci;
1886 err = pci_enable_device(pci);
1890 /* Set DMA transfer mask */
1891 if (pci_set_dma_mask(pci, CT_XFI_DMA_MASK) < 0 ||
1892 pci_set_consistent_dma_mask(pci, CT_XFI_DMA_MASK) < 0) {
1893 printk(KERN_ERR "ctxfi: architecture does not support PCI "
1894 "busmaster DMA with mask 0x%llx\n", CT_XFI_DMA_MASK);
1900 err = pci_request_regions(pci, "XFi");
1904 hw->io_base = pci_resource_start(hw->pci, 2);
1905 hw->mem_base = (unsigned long)ioremap(hw->io_base,
1906 pci_resource_len(hw->pci, 2));
1907 if (NULL == (void *)hw->mem_base) {
1913 /* Switch to 20k2 mode from UAA mode. */
1914 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1915 set_field(&gctl, GCTL_UAA, 0);
1916 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1919 err = request_irq(pci->irq, ct_20k2_interrupt, IRQF_SHARED,
1922 printk(KERN_ERR "XFi: Cannot get irq %d\n", pci->irq);
1928 pci_set_master(pci);
1933 iounmap((void *)hw->mem_base);
1934 hw->mem_base = (unsigned long)NULL;*/
1936 pci_release_regions(pci);
1939 pci_disable_device(pci);
1943 static int hw_card_stop(struct hw *hw)
1947 /* disable transport bus master and queueing of request */
1948 hw_write_20kx(hw, TRANSPORT_CTL, 0x00);
1951 data = hw_read_20kx(hw, PLL_ENB);
1952 hw_write_20kx(hw, PLL_ENB, (data & (~0x07)));
1954 /* TODO: Disable interrupt and so on... */
1958 static int hw_card_shutdown(struct hw *hw)
1961 free_irq(hw->irq, hw);
1965 if (NULL != ((void *)hw->mem_base))
1966 iounmap((void *)hw->mem_base);
1968 hw->mem_base = (unsigned long)NULL;
1971 pci_release_regions(hw->pci);
1975 pci_disable_device(hw->pci);
1980 static int hw_card_init(struct hw *hw, struct card_conf *info)
1985 struct dac_conf dac_info = {0};
1986 struct adc_conf adc_info = {0};
1987 struct daio_conf daio_info = {0};
1988 struct trn_conf trn_info = {0};
1990 /* Get PCI io port/memory base address and
1991 * do 20kx core switch if needed. */
1992 err = hw_card_start(hw);
1997 err = hw_pll_init(hw, info->rsr);
2001 /* kick off auto-init */
2002 err = hw_auto_init(hw);
2006 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
2007 set_field(&gctl, GCTL_DBP, 1);
2008 set_field(&gctl, GCTL_TBP, 1);
2009 set_field(&gctl, GCTL_FBP, 1);
2010 set_field(&gctl, GCTL_DPC, 0);
2011 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
2013 /* Reset all global pending interrupts */
2014 hw_write_20kx(hw, GIE, 0);
2015 /* Reset all SRC pending interrupts */
2016 hw_write_20kx(hw, SRC_IP, 0);
2018 /* TODO: detect the card ID and configure GPIO accordingly. */
2019 /* Configures GPIO (0xD802 0x98028) */
2020 /*hw_write_20kx(hw, GPIO_CTRL, 0x7F07);*/
2021 /* Configures GPIO (SB0880) */
2022 /*hw_write_20kx(hw, GPIO_CTRL, 0xFF07);*/
2023 hw_write_20kx(hw, GPIO_CTRL, 0xD802);
2025 /* Enable audio ring */
2026 hw_write_20kx(hw, MIXER_AR_ENABLE, 0x01);
2028 trn_info.vm_pgt_phys = info->vm_pgt_phys;
2029 err = hw_trn_init(hw, &trn_info);
2033 daio_info.msr = info->msr;
2034 err = hw_daio_init(hw, &daio_info);
2038 dac_info.msr = info->msr;
2039 err = hw_dac_init(hw, &dac_info);
2043 adc_info.msr = info->msr;
2044 adc_info.input = ADC_LINEIN;
2045 adc_info.mic20db = 0;
2046 err = hw_adc_init(hw, &adc_info);
2050 data = hw_read_20kx(hw, SRC_MCTL);
2051 data |= 0x1; /* Enables input from the audio ring */
2052 hw_write_20kx(hw, SRC_MCTL, data);
2058 static int hw_suspend(struct hw *hw, pm_message_t state)
2060 struct pci_dev *pci = hw->pci;
2064 pci_disable_device(pci);
2065 pci_save_state(pci);
2066 pci_set_power_state(pci, pci_choose_state(pci, state));
2071 static int hw_resume(struct hw *hw, struct card_conf *info)
2073 struct pci_dev *pci = hw->pci;
2075 pci_set_power_state(pci, PCI_D0);
2076 pci_restore_state(pci);
2078 /* Re-initialize card hardware. */
2079 return hw_card_init(hw, info);
2083 static u32 hw_read_20kx(struct hw *hw, u32 reg)
2085 return readl((void *)(hw->mem_base + reg));
2088 static void hw_write_20kx(struct hw *hw, u32 reg, u32 data)
2090 writel(data, (void *)(hw->mem_base + reg));
2093 static struct hw ct20k2_preset __devinitdata = {
2096 .card_init = hw_card_init,
2097 .card_stop = hw_card_stop,
2098 .pll_init = hw_pll_init,
2099 .is_adc_source_selected = hw_is_adc_input_selected,
2100 .select_adc_source = hw_adc_input_select,
2101 .have_digit_io_switch = hw_have_digit_io_switch,
2103 .suspend = hw_suspend,
2104 .resume = hw_resume,
2107 .src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk,
2108 .src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk,
2109 .src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk,
2110 .src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk,
2111 .src_set_state = src_set_state,
2112 .src_set_bm = src_set_bm,
2113 .src_set_rsr = src_set_rsr,
2114 .src_set_sf = src_set_sf,
2115 .src_set_wr = src_set_wr,
2116 .src_set_pm = src_set_pm,
2117 .src_set_rom = src_set_rom,
2118 .src_set_vo = src_set_vo,
2119 .src_set_st = src_set_st,
2120 .src_set_ie = src_set_ie,
2121 .src_set_ilsz = src_set_ilsz,
2122 .src_set_bp = src_set_bp,
2123 .src_set_cisz = src_set_cisz,
2124 .src_set_ca = src_set_ca,
2125 .src_set_sa = src_set_sa,
2126 .src_set_la = src_set_la,
2127 .src_set_pitch = src_set_pitch,
2128 .src_set_dirty = src_set_dirty,
2129 .src_set_clear_zbufs = src_set_clear_zbufs,
2130 .src_set_dirty_all = src_set_dirty_all,
2131 .src_commit_write = src_commit_write,
2132 .src_get_ca = src_get_ca,
2133 .src_get_dirty = src_get_dirty,
2134 .src_dirty_conj_mask = src_dirty_conj_mask,
2135 .src_mgr_enbs_src = src_mgr_enbs_src,
2136 .src_mgr_enb_src = src_mgr_enb_src,
2137 .src_mgr_dsb_src = src_mgr_dsb_src,
2138 .src_mgr_commit_write = src_mgr_commit_write,
2140 .srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk,
2141 .srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk,
2142 .srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc,
2143 .srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser,
2144 .srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt,
2145 .srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr,
2146 .srcimp_mgr_commit_write = srcimp_mgr_commit_write,
2148 .amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk,
2149 .amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk,
2150 .amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk,
2151 .amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk,
2152 .amixer_set_mode = amixer_set_mode,
2153 .amixer_set_iv = amixer_set_iv,
2154 .amixer_set_x = amixer_set_x,
2155 .amixer_set_y = amixer_set_y,
2156 .amixer_set_sadr = amixer_set_sadr,
2157 .amixer_set_se = amixer_set_se,
2158 .amixer_set_dirty = amixer_set_dirty,
2159 .amixer_set_dirty_all = amixer_set_dirty_all,
2160 .amixer_commit_write = amixer_commit_write,
2161 .amixer_get_y = amixer_get_y,
2162 .amixer_get_dirty = amixer_get_dirty,
2164 .dai_get_ctrl_blk = dai_get_ctrl_blk,
2165 .dai_put_ctrl_blk = dai_put_ctrl_blk,
2166 .dai_srt_set_srco = dai_srt_set_srco,
2167 .dai_srt_set_srcm = dai_srt_set_srcm,
2168 .dai_srt_set_rsr = dai_srt_set_rsr,
2169 .dai_srt_set_drat = dai_srt_set_drat,
2170 .dai_srt_set_ec = dai_srt_set_ec,
2171 .dai_srt_set_et = dai_srt_set_et,
2172 .dai_commit_write = dai_commit_write,
2174 .dao_get_ctrl_blk = dao_get_ctrl_blk,
2175 .dao_put_ctrl_blk = dao_put_ctrl_blk,
2176 .dao_set_spos = dao_set_spos,
2177 .dao_commit_write = dao_commit_write,
2178 .dao_get_spos = dao_get_spos,
2180 .daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk,
2181 .daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk,
2182 .daio_mgr_enb_dai = daio_mgr_enb_dai,
2183 .daio_mgr_dsb_dai = daio_mgr_dsb_dai,
2184 .daio_mgr_enb_dao = daio_mgr_enb_dao,
2185 .daio_mgr_dsb_dao = daio_mgr_dsb_dao,
2186 .daio_mgr_dao_init = daio_mgr_dao_init,
2187 .daio_mgr_set_imaparc = daio_mgr_set_imaparc,
2188 .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt,
2189 .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr,
2190 .daio_mgr_commit_write = daio_mgr_commit_write,
2192 .set_timer_irq = set_timer_irq,
2193 .set_timer_tick = set_timer_tick,
2197 int __devinit create_20k2_hw_obj(struct hw **rhw)
2199 struct hw20k2 *hw20k2;
2202 hw20k2 = kzalloc(sizeof(*hw20k2), GFP_KERNEL);
2206 hw20k2->hw = ct20k2_preset;
2212 int destroy_20k2_hw_obj(struct hw *hw)
2215 hw_card_shutdown(hw);