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 /* Card hardware initialization block */
1117 unsigned int msr; /* master sample rate in rsrs */
1121 unsigned int msr; /* master sample rate in rsrs */
1122 unsigned char input; /* the input source of ADC */
1123 unsigned char mic20db; /* boost mic by 20db if input is microphone */
1127 unsigned int msr; /* master sample rate in rsrs */
1131 unsigned long vm_pgt_phys;
1134 static int hw_daio_init(struct hw *hw, const struct daio_conf *info)
1139 /* Program I2S with proper sample rate and enable the correct I2S
1140 * channel. ED(0/8/16/24): Enable all I2S/I2X master clock output */
1141 if (1 == info->msr) {
1142 hw_write_20kx(hw, AUDIO_IO_MCLK, 0x01010101);
1143 hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x01010101);
1144 hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
1145 } else if (2 == info->msr) {
1146 hw_write_20kx(hw, AUDIO_IO_MCLK, 0x11111111);
1147 /* Specify all playing 96khz
1151 * RTB [12:13] - 96kHz
1153 * RTC [20:21] - 96kHz
1155 * RTD [28:29] - 96kHz */
1156 hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x11111111);
1157 hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
1159 printk(KERN_ALERT "ctxfi: ERROR!!! Invalid sampling rate!!!\n");
1163 for (i = 0; i < 8; i++) {
1165 /* 1st 3 channels are SPDIFs (SB0960) */
1171 hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), data);
1172 hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), data);
1174 /* Initialize the SPDIF Out Channel status registers.
1175 * The value specified here is based on the typical
1176 * values provided in the specification, namely: Clock
1177 * Accuracy of 1000ppm, Sample Rate of 48KHz,
1178 * unspecified source number, Generation status = 1,
1179 * Category code = 0x12 (Digital Signal Mixer),
1180 * Mode = 0, Emph = 0, Copy Permitted, AN = 0
1181 * (indicating that we're transmitting digital audio,
1182 * and the Professional Use bit is 0. */
1184 hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+(0x40*i),
1185 0x02109204); /* Default to 48kHz */
1187 hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_H+(0x40*i), 0x0B);
1189 /* Next 5 channels are I2S (SB0960) */
1191 hw_write_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i), data);
1192 if (2 == info->msr) {
1193 /* Four channels per sample period */
1196 hw_write_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i), data);
1203 /* TRANSPORT operations */
1204 static int hw_trn_init(struct hw *hw, const struct trn_conf *info)
1207 u32 ptp_phys_low, ptp_phys_high;
1210 /* Set up device page table */
1211 if ((~0UL) == info->vm_pgt_phys) {
1212 printk(KERN_ALERT "ctxfi: "
1213 "Wrong device page table page address!!!\n");
1217 vmctl = 0x80000C0F; /* 32-bit, 4k-size page */
1218 ptp_phys_low = (u32)info->vm_pgt_phys;
1219 ptp_phys_high = upper_32_bits(info->vm_pgt_phys);
1220 if (sizeof(void *) == 8) /* 64bit address */
1222 /* Write page table physical address to all PTPAL registers */
1223 for (i = 0; i < 64; i++) {
1224 hw_write_20kx(hw, VMEM_PTPAL+(16*i), ptp_phys_low);
1225 hw_write_20kx(hw, VMEM_PTPAH+(16*i), ptp_phys_high);
1227 /* Enable virtual memory transfer */
1228 hw_write_20kx(hw, VMEM_CTL, vmctl);
1229 /* Enable transport bus master and queueing of request */
1230 hw_write_20kx(hw, TRANSPORT_CTL, 0x03);
1231 hw_write_20kx(hw, TRANSPORT_INT, 0x200c01);
1232 /* Enable transport ring */
1233 data = hw_read_20kx(hw, TRANSPORT_ENB);
1234 hw_write_20kx(hw, TRANSPORT_ENB, (data | 0x03));
1239 /* Card initialization */
1240 #define GCTL_AIE 0x00000001
1241 #define GCTL_UAA 0x00000002
1242 #define GCTL_DPC 0x00000004
1243 #define GCTL_DBP 0x00000008
1244 #define GCTL_ABP 0x00000010
1245 #define GCTL_TBP 0x00000020
1246 #define GCTL_SBP 0x00000040
1247 #define GCTL_FBP 0x00000080
1248 #define GCTL_ME 0x00000100
1249 #define GCTL_AID 0x00001000
1251 #define PLLCTL_SRC 0x00000007
1252 #define PLLCTL_SPE 0x00000008
1253 #define PLLCTL_RD 0x000000F0
1254 #define PLLCTL_FD 0x0001FF00
1255 #define PLLCTL_OD 0x00060000
1256 #define PLLCTL_B 0x00080000
1257 #define PLLCTL_AS 0x00100000
1258 #define PLLCTL_LF 0x03E00000
1259 #define PLLCTL_SPS 0x1C000000
1260 #define PLLCTL_AD 0x60000000
1262 #define PLLSTAT_CCS 0x00000007
1263 #define PLLSTAT_SPL 0x00000008
1264 #define PLLSTAT_CRD 0x000000F0
1265 #define PLLSTAT_CFD 0x0001FF00
1266 #define PLLSTAT_SL 0x00020000
1267 #define PLLSTAT_FAS 0x00040000
1268 #define PLLSTAT_B 0x00080000
1269 #define PLLSTAT_PD 0x00100000
1270 #define PLLSTAT_OCA 0x00200000
1271 #define PLLSTAT_NCA 0x00400000
1273 static int hw_pll_init(struct hw *hw, unsigned int rsr)
1275 unsigned int pllenb;
1276 unsigned int pllctl;
1277 unsigned int pllstat;
1281 hw_write_20kx(hw, PLL_ENB, pllenb);
1282 pllctl = 0x20D00000;
1283 set_field(&pllctl, PLLCTL_FD, 16 - 4);
1284 hw_write_20kx(hw, PLL_CTL, pllctl);
1286 pllctl = hw_read_20kx(hw, PLL_CTL);
1287 set_field(&pllctl, PLLCTL_B, 0);
1289 set_field(&pllctl, PLLCTL_FD, 16 - 2);
1290 set_field(&pllctl, PLLCTL_RD, 1 - 1);
1291 } else { /* 44100 */
1292 set_field(&pllctl, PLLCTL_FD, 147 - 2);
1293 set_field(&pllctl, PLLCTL_RD, 10 - 1);
1295 hw_write_20kx(hw, PLL_CTL, pllctl);
1297 for (i = 0; i < 1000; i++) {
1298 pllstat = hw_read_20kx(hw, PLL_STAT);
1299 if (get_field(pllstat, PLLSTAT_PD))
1302 if (get_field(pllstat, PLLSTAT_B) !=
1303 get_field(pllctl, PLLCTL_B))
1306 if (get_field(pllstat, PLLSTAT_CCS) !=
1307 get_field(pllctl, PLLCTL_SRC))
1310 if (get_field(pllstat, PLLSTAT_CRD) !=
1311 get_field(pllctl, PLLCTL_RD))
1314 if (get_field(pllstat, PLLSTAT_CFD) !=
1315 get_field(pllctl, PLLCTL_FD))
1321 printk(KERN_ALERT "ctxfi: PLL initialization failed!!!\n");
1328 static int hw_auto_init(struct hw *hw)
1333 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1334 set_field(&gctl, GCTL_AIE, 0);
1335 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1336 set_field(&gctl, GCTL_AIE, 1);
1337 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1339 for (i = 0; i < 400000; i++) {
1340 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1341 if (get_field(gctl, GCTL_AID))
1344 if (!get_field(gctl, GCTL_AID)) {
1345 printk(KERN_ALERT "ctxfi: Card Auto-init failed!!!\n");
1352 /* DAC operations */
1354 #define CS4382_MC1 0x1
1355 #define CS4382_MC2 0x2
1356 #define CS4382_MC3 0x3
1357 #define CS4382_FC 0x4
1358 #define CS4382_IC 0x5
1359 #define CS4382_XC1 0x6
1360 #define CS4382_VCA1 0x7
1361 #define CS4382_VCB1 0x8
1362 #define CS4382_XC2 0x9
1363 #define CS4382_VCA2 0xA
1364 #define CS4382_VCB2 0xB
1365 #define CS4382_XC3 0xC
1366 #define CS4382_VCA3 0xD
1367 #define CS4382_VCB3 0xE
1368 #define CS4382_XC4 0xF
1369 #define CS4382_VCA4 0x10
1370 #define CS4382_VCB4 0x11
1371 #define CS4382_CREV 0x12
1374 #define STATE_LOCKED 0x00
1375 #define STATE_UNLOCKED 0xAA
1376 #define DATA_READY 0x800000 /* Used with I2C_IF_STATUS */
1377 #define DATA_ABORT 0x10000 /* Used with I2C_IF_STATUS */
1379 #define I2C_STATUS_DCM 0x00000001
1380 #define I2C_STATUS_BC 0x00000006
1381 #define I2C_STATUS_APD 0x00000008
1382 #define I2C_STATUS_AB 0x00010000
1383 #define I2C_STATUS_DR 0x00800000
1385 #define I2C_ADDRESS_PTAD 0x0000FFFF
1386 #define I2C_ADDRESS_SLAD 0x007F0000
1388 struct regs_cs4382 {
1413 static int hw20k2_i2c_unlock_full_access(struct hw *hw)
1415 u8 UnlockKeySequence_FLASH_FULLACCESS_MODE[2] = {0xB3, 0xD4};
1417 /* Send keys for forced BIOS mode */
1418 hw_write_20kx(hw, I2C_IF_WLOCK,
1419 UnlockKeySequence_FLASH_FULLACCESS_MODE[0]);
1420 hw_write_20kx(hw, I2C_IF_WLOCK,
1421 UnlockKeySequence_FLASH_FULLACCESS_MODE[1]);
1422 /* Check whether the chip is unlocked */
1423 if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_UNLOCKED)
1429 static int hw20k2_i2c_lock_chip(struct hw *hw)
1432 hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED);
1433 hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED);
1434 if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_LOCKED)
1440 static int hw20k2_i2c_init(struct hw *hw, u8 dev_id, u8 addr_size, u8 data_size)
1442 struct hw20k2 *hw20k2 = (struct hw20k2 *)hw;
1444 unsigned int i2c_status;
1445 unsigned int i2c_addr;
1447 err = hw20k2_i2c_unlock_full_access(hw);
1451 hw20k2->addr_size = addr_size;
1452 hw20k2->data_size = data_size;
1453 hw20k2->dev_id = dev_id;
1456 set_field(&i2c_addr, I2C_ADDRESS_SLAD, dev_id);
1458 hw_write_20kx(hw, I2C_IF_ADDRESS, i2c_addr);
1460 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1462 set_field(&i2c_status, I2C_STATUS_DCM, 1); /* Direct control mode */
1464 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1469 static int hw20k2_i2c_uninit(struct hw *hw)
1471 unsigned int i2c_status;
1472 unsigned int i2c_addr;
1475 set_field(&i2c_addr, I2C_ADDRESS_SLAD, 0x57); /* I2C id */
1477 hw_write_20kx(hw, I2C_IF_ADDRESS, i2c_addr);
1479 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1481 set_field(&i2c_status, I2C_STATUS_DCM, 0); /* I2C mode */
1483 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1485 return hw20k2_i2c_lock_chip(hw);
1488 static int hw20k2_i2c_wait_data_ready(struct hw *hw)
1494 ret = hw_read_20kx(hw, I2C_IF_STATUS);
1495 } while ((!(ret & DATA_READY)) && --i);
1500 static int hw20k2_i2c_read(struct hw *hw, u16 addr, u32 *datap)
1502 struct hw20k2 *hw20k2 = (struct hw20k2 *)hw;
1503 unsigned int i2c_status;
1505 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1506 set_field(&i2c_status, I2C_STATUS_BC,
1507 (4 == hw20k2->addr_size) ? 0 : hw20k2->addr_size);
1508 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1509 if (!hw20k2_i2c_wait_data_ready(hw))
1512 hw_write_20kx(hw, I2C_IF_WDATA, addr);
1513 if (!hw20k2_i2c_wait_data_ready(hw))
1516 /* Force a read operation */
1517 hw_write_20kx(hw, I2C_IF_RDATA, 0);
1518 if (!hw20k2_i2c_wait_data_ready(hw))
1521 *datap = hw_read_20kx(hw, I2C_IF_RDATA);
1526 static int hw20k2_i2c_write(struct hw *hw, u16 addr, u32 data)
1528 struct hw20k2 *hw20k2 = (struct hw20k2 *)hw;
1529 unsigned int i2c_data = (data << (hw20k2->addr_size * 8)) | addr;
1530 unsigned int i2c_status;
1532 i2c_status = hw_read_20kx(hw, I2C_IF_STATUS);
1534 set_field(&i2c_status, I2C_STATUS_BC,
1535 (4 == (hw20k2->addr_size + hw20k2->data_size)) ?
1536 0 : (hw20k2->addr_size + hw20k2->data_size));
1538 hw_write_20kx(hw, I2C_IF_STATUS, i2c_status);
1539 hw20k2_i2c_wait_data_ready(hw);
1540 /* Dummy write to trigger the write oprtation */
1541 hw_write_20kx(hw, I2C_IF_WDATA, 0);
1542 hw20k2_i2c_wait_data_ready(hw);
1544 /* This is the real data */
1545 hw_write_20kx(hw, I2C_IF_WDATA, i2c_data);
1546 hw20k2_i2c_wait_data_ready(hw);
1551 static int hw_dac_init(struct hw *hw, const struct dac_conf *info)
1556 struct regs_cs4382 cs_read = {0};
1557 struct regs_cs4382 cs_def = {
1558 0x00000001, /* Mode Control 1 */
1559 0x00000000, /* Mode Control 2 */
1560 0x00000084, /* Mode Control 3 */
1561 0x00000000, /* Filter Control */
1562 0x00000000, /* Invert Control */
1563 0x00000024, /* Mixing Control Pair 1 */
1564 0x00000000, /* Vol Control A1 */
1565 0x00000000, /* Vol Control B1 */
1566 0x00000024, /* Mixing Control Pair 2 */
1567 0x00000000, /* Vol Control A2 */
1568 0x00000000, /* Vol Control B2 */
1569 0x00000024, /* Mixing Control Pair 3 */
1570 0x00000000, /* Vol Control A3 */
1571 0x00000000, /* Vol Control B3 */
1572 0x00000024, /* Mixing Control Pair 4 */
1573 0x00000000, /* Vol Control A4 */
1574 0x00000000 /* Vol Control B4 */
1577 /* Set DAC reset bit as output */
1578 data = hw_read_20kx(hw, GPIO_CTRL);
1580 hw_write_20kx(hw, GPIO_CTRL, data);
1582 err = hw20k2_i2c_init(hw, 0x18, 1, 1);
1586 for (i = 0; i < 2; i++) {
1587 /* Reset DAC twice just in-case the chip
1588 * didn't initialized properly */
1589 data = hw_read_20kx(hw, GPIO_DATA);
1590 /* GPIO data bit 1 */
1592 hw_write_20kx(hw, GPIO_DATA, data);
1595 hw_write_20kx(hw, GPIO_DATA, data);
1598 /* Reset the 2nd time */
1600 hw_write_20kx(hw, GPIO_DATA, data);
1603 hw_write_20kx(hw, GPIO_DATA, data);
1606 if (hw20k2_i2c_read(hw, CS4382_MC1, &cs_read.mode_control_1))
1609 if (hw20k2_i2c_read(hw, CS4382_MC2, &cs_read.mode_control_2))
1612 if (hw20k2_i2c_read(hw, CS4382_MC3, &cs_read.mode_control_3))
1615 if (hw20k2_i2c_read(hw, CS4382_FC, &cs_read.filter_control))
1618 if (hw20k2_i2c_read(hw, CS4382_IC, &cs_read.invert_control))
1621 if (hw20k2_i2c_read(hw, CS4382_XC1, &cs_read.mix_control_P1))
1624 if (hw20k2_i2c_read(hw, CS4382_VCA1, &cs_read.vol_control_A1))
1627 if (hw20k2_i2c_read(hw, CS4382_VCB1, &cs_read.vol_control_B1))
1630 if (hw20k2_i2c_read(hw, CS4382_XC2, &cs_read.mix_control_P2))
1633 if (hw20k2_i2c_read(hw, CS4382_VCA2, &cs_read.vol_control_A2))
1636 if (hw20k2_i2c_read(hw, CS4382_VCB2, &cs_read.vol_control_B2))
1639 if (hw20k2_i2c_read(hw, CS4382_XC3, &cs_read.mix_control_P3))
1642 if (hw20k2_i2c_read(hw, CS4382_VCA3, &cs_read.vol_control_A3))
1645 if (hw20k2_i2c_read(hw, CS4382_VCB3, &cs_read.vol_control_B3))
1648 if (hw20k2_i2c_read(hw, CS4382_XC4, &cs_read.mix_control_P4))
1651 if (hw20k2_i2c_read(hw, CS4382_VCA4, &cs_read.vol_control_A4))
1654 if (hw20k2_i2c_read(hw, CS4382_VCB4, &cs_read.vol_control_B4))
1657 if (memcmp(&cs_read, &cs_def, sizeof(cs_read)))
1666 /* Note: Every I2C write must have some delay.
1667 * This is not a requirement but the delay works here... */
1668 hw20k2_i2c_write(hw, CS4382_MC1, 0x80);
1669 hw20k2_i2c_write(hw, CS4382_MC2, 0x10);
1670 if (1 == info->msr) {
1671 hw20k2_i2c_write(hw, CS4382_XC1, 0x24);
1672 hw20k2_i2c_write(hw, CS4382_XC2, 0x24);
1673 hw20k2_i2c_write(hw, CS4382_XC3, 0x24);
1674 hw20k2_i2c_write(hw, CS4382_XC4, 0x24);
1675 } else if (2 == info->msr) {
1676 hw20k2_i2c_write(hw, CS4382_XC1, 0x25);
1677 hw20k2_i2c_write(hw, CS4382_XC2, 0x25);
1678 hw20k2_i2c_write(hw, CS4382_XC3, 0x25);
1679 hw20k2_i2c_write(hw, CS4382_XC4, 0x25);
1681 hw20k2_i2c_write(hw, CS4382_XC1, 0x26);
1682 hw20k2_i2c_write(hw, CS4382_XC2, 0x26);
1683 hw20k2_i2c_write(hw, CS4382_XC3, 0x26);
1684 hw20k2_i2c_write(hw, CS4382_XC4, 0x26);
1690 hw20k2_i2c_uninit(hw);
1694 /* ADC operations */
1695 #define MAKE_WM8775_ADDR(addr, data) (u32)(((addr<<1)&0xFE)|((data>>8)&0x1))
1696 #define MAKE_WM8775_DATA(data) (u32)(data&0xFF)
1698 #define WM8775_IC 0x0B
1699 #define WM8775_MMC 0x0C
1700 #define WM8775_AADCL 0x0E
1701 #define WM8775_AADCR 0x0F
1702 #define WM8775_ADCMC 0x15
1703 #define WM8775_RESET 0x17
1705 static int hw_is_adc_input_selected(struct hw *hw, enum ADCSRC type)
1709 data = hw_read_20kx(hw, GPIO_DATA);
1712 data = (data & (0x1 << 14)) ? 1 : 0;
1715 data = (data & (0x1 << 14)) ? 0 : 1;
1723 static int hw_adc_input_select(struct hw *hw, enum ADCSRC type)
1727 data = hw_read_20kx(hw, GPIO_DATA);
1730 data |= (0x1 << 14);
1731 hw_write_20kx(hw, GPIO_DATA, data);
1732 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x101),
1733 MAKE_WM8775_DATA(0x101)); /* Mic-in */
1734 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xE7),
1735 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1736 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xE7),
1737 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1740 data &= ~(0x1 << 14);
1741 hw_write_20kx(hw, GPIO_DATA, data);
1742 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x102),
1743 MAKE_WM8775_DATA(0x102)); /* Line-in */
1744 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xCF),
1745 MAKE_WM8775_DATA(0xCF)); /* No boost */
1746 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
1747 MAKE_WM8775_DATA(0xCF)); /* No boost */
1756 static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
1759 u32 mux = 2, data, ctl;
1761 /* Set ADC reset bit as output */
1762 data = hw_read_20kx(hw, GPIO_CTRL);
1763 data |= (0x1 << 15);
1764 hw_write_20kx(hw, GPIO_CTRL, data);
1766 /* Initialize I2C */
1767 err = hw20k2_i2c_init(hw, 0x1A, 1, 1);
1769 printk(KERN_ALERT "ctxfi: Failure to acquire I2C!!!\n");
1773 /* Make ADC in normal operation */
1774 data = hw_read_20kx(hw, GPIO_DATA);
1775 data &= ~(0x1 << 15);
1777 data |= (0x1 << 15);
1778 hw_write_20kx(hw, GPIO_DATA, data);
1781 /* Set the master mode (256fs) */
1782 if (1 == info->msr) {
1783 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x02),
1784 MAKE_WM8775_DATA(0x02));
1785 } else if (2 == info->msr) {
1786 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x0A),
1787 MAKE_WM8775_DATA(0x0A));
1789 printk(KERN_ALERT "ctxfi: Invalid master sampling "
1790 "rate (msr %d)!!!\n", info->msr);
1795 /* Configure GPIO bit 14 change to line-in/mic-in */
1796 ctl = hw_read_20kx(hw, GPIO_CTRL);
1798 hw_write_20kx(hw, GPIO_CTRL, ctl);
1800 /* Check using Mic-in or Line-in */
1801 data = hw_read_20kx(hw, GPIO_DATA);
1804 /* Configures GPIO data to select Mic-in */
1806 hw_write_20kx(hw, GPIO_DATA, data);
1808 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x101),
1809 MAKE_WM8775_DATA(0x101)); /* Mic-in */
1810 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xE7),
1811 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1812 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xE7),
1813 MAKE_WM8775_DATA(0xE7)); /* +12dB boost */
1814 } else if (mux == 2) {
1815 /* Configures GPIO data to select Line-in */
1816 data &= ~(0x1 << 14);
1817 hw_write_20kx(hw, GPIO_DATA, data);
1820 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, 0x102),
1821 MAKE_WM8775_DATA(0x102)); /* Line-in */
1822 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, 0xCF),
1823 MAKE_WM8775_DATA(0xCF)); /* No boost */
1824 hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
1825 MAKE_WM8775_DATA(0xCF)); /* No boost */
1827 printk(KERN_ALERT "ctxfi: ERROR!!! Invalid input mux!!!\n");
1835 hw20k2_i2c_uninit(hw);
1839 static int hw_have_digit_io_switch(struct hw *hw)
1844 static int hw_card_start(struct hw *hw)
1847 struct pci_dev *pci = hw->pci;
1850 err = pci_enable_device(pci);
1854 /* Set DMA transfer mask */
1855 if (pci_set_dma_mask(pci, CT_XFI_DMA_MASK) < 0 ||
1856 pci_set_consistent_dma_mask(pci, CT_XFI_DMA_MASK) < 0) {
1857 printk(KERN_ERR "ctxfi: architecture does not support PCI "
1858 "busmaster DMA with mask 0x%llx\n", CT_XFI_DMA_MASK);
1864 err = pci_request_regions(pci, "XFi");
1868 hw->io_base = pci_resource_start(hw->pci, 2);
1869 hw->mem_base = (unsigned long)ioremap(hw->io_base,
1870 pci_resource_len(hw->pci, 2));
1871 if (NULL == (void *)hw->mem_base) {
1877 /* Switch to 20k2 mode from UAA mode. */
1878 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1879 set_field(&gctl, GCTL_UAA, 0);
1880 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1882 /*if ((err = request_irq(pci->irq, ct_atc_interrupt, IRQF_SHARED,
1883 atc->chip_details->nm_card, hw))) {
1889 pci_set_master(pci);
1894 iounmap((void *)hw->mem_base);
1895 hw->mem_base = (unsigned long)NULL;*/
1897 pci_release_regions(pci);
1900 pci_disable_device(pci);
1904 static int hw_card_stop(struct hw *hw)
1908 /* disable transport bus master and queueing of request */
1909 hw_write_20kx(hw, TRANSPORT_CTL, 0x00);
1912 data = hw_read_20kx(hw, PLL_ENB);
1913 hw_write_20kx(hw, PLL_ENB, (data & (~0x07)));
1915 /* TODO: Disable interrupt and so on... */
1919 static int hw_card_shutdown(struct hw *hw)
1922 free_irq(hw->irq, hw);
1926 if (NULL != ((void *)hw->mem_base))
1927 iounmap((void *)hw->mem_base);
1929 hw->mem_base = (unsigned long)NULL;
1932 pci_release_regions(hw->pci);
1936 pci_disable_device(hw->pci);
1941 static int hw_card_init(struct hw *hw, struct card_conf *info)
1946 struct dac_conf dac_info = {0};
1947 struct adc_conf adc_info = {0};
1948 struct daio_conf daio_info = {0};
1949 struct trn_conf trn_info = {0};
1951 /* Get PCI io port/memory base address and
1952 * do 20kx core switch if needed. */
1953 err = hw_card_start(hw);
1958 err = hw_pll_init(hw, info->rsr);
1962 /* kick off auto-init */
1963 err = hw_auto_init(hw);
1967 gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL);
1968 set_field(&gctl, GCTL_DBP, 1);
1969 set_field(&gctl, GCTL_TBP, 1);
1970 set_field(&gctl, GCTL_FBP, 1);
1971 set_field(&gctl, GCTL_DPC, 0);
1972 hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl);
1974 /* Reset all global pending interrupts */
1975 hw_write_20kx(hw, INTERRUPT_GIE, 0);
1976 /* Reset all SRC pending interrupts */
1977 hw_write_20kx(hw, SRC_IP, 0);
1979 /* TODO: detect the card ID and configure GPIO accordingly. */
1980 /* Configures GPIO (0xD802 0x98028) */
1981 /*hw_write_20kx(hw, GPIO_CTRL, 0x7F07);*/
1982 /* Configures GPIO (SB0880) */
1983 /*hw_write_20kx(hw, GPIO_CTRL, 0xFF07);*/
1984 hw_write_20kx(hw, GPIO_CTRL, 0xD802);
1986 /* Enable audio ring */
1987 hw_write_20kx(hw, MIXER_AR_ENABLE, 0x01);
1989 trn_info.vm_pgt_phys = info->vm_pgt_phys;
1990 err = hw_trn_init(hw, &trn_info);
1994 daio_info.msr = info->msr;
1995 err = hw_daio_init(hw, &daio_info);
1999 dac_info.msr = info->msr;
2000 err = hw_dac_init(hw, &dac_info);
2004 adc_info.msr = info->msr;
2005 adc_info.input = ADC_LINEIN;
2006 adc_info.mic20db = 0;
2007 err = hw_adc_init(hw, &adc_info);
2011 data = hw_read_20kx(hw, SRC_MCTL);
2012 data |= 0x1; /* Enables input from the audio ring */
2013 hw_write_20kx(hw, SRC_MCTL, data);
2019 static int hw_suspend(struct hw *hw, pm_message_t state)
2021 struct pci_dev *pci = hw->pci;
2025 pci_disable_device(pci);
2026 pci_save_state(pci);
2027 pci_set_power_state(pci, pci_choose_state(pci, state));
2032 static int hw_resume(struct hw *hw, struct card_conf *info)
2034 struct pci_dev *pci = hw->pci;
2036 pci_set_power_state(pci, PCI_D0);
2037 pci_restore_state(pci);
2039 /* Re-initialize card hardware. */
2040 return hw_card_init(hw, info);
2044 static u32 hw_read_20kx(struct hw *hw, u32 reg)
2046 return readl((void *)(hw->mem_base + reg));
2049 static void hw_write_20kx(struct hw *hw, u32 reg, u32 data)
2051 writel(data, (void *)(hw->mem_base + reg));
2054 static struct hw ct20k2_preset __devinitdata = {
2057 .card_init = hw_card_init,
2058 .card_stop = hw_card_stop,
2059 .pll_init = hw_pll_init,
2060 .is_adc_source_selected = hw_is_adc_input_selected,
2061 .select_adc_source = hw_adc_input_select,
2062 .have_digit_io_switch = hw_have_digit_io_switch,
2064 .suspend = hw_suspend,
2065 .resume = hw_resume,
2068 .src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk,
2069 .src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk,
2070 .src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk,
2071 .src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk,
2072 .src_set_state = src_set_state,
2073 .src_set_bm = src_set_bm,
2074 .src_set_rsr = src_set_rsr,
2075 .src_set_sf = src_set_sf,
2076 .src_set_wr = src_set_wr,
2077 .src_set_pm = src_set_pm,
2078 .src_set_rom = src_set_rom,
2079 .src_set_vo = src_set_vo,
2080 .src_set_st = src_set_st,
2081 .src_set_ie = src_set_ie,
2082 .src_set_ilsz = src_set_ilsz,
2083 .src_set_bp = src_set_bp,
2084 .src_set_cisz = src_set_cisz,
2085 .src_set_ca = src_set_ca,
2086 .src_set_sa = src_set_sa,
2087 .src_set_la = src_set_la,
2088 .src_set_pitch = src_set_pitch,
2089 .src_set_dirty = src_set_dirty,
2090 .src_set_clear_zbufs = src_set_clear_zbufs,
2091 .src_set_dirty_all = src_set_dirty_all,
2092 .src_commit_write = src_commit_write,
2093 .src_get_ca = src_get_ca,
2094 .src_get_dirty = src_get_dirty,
2095 .src_dirty_conj_mask = src_dirty_conj_mask,
2096 .src_mgr_enbs_src = src_mgr_enbs_src,
2097 .src_mgr_enb_src = src_mgr_enb_src,
2098 .src_mgr_dsb_src = src_mgr_dsb_src,
2099 .src_mgr_commit_write = src_mgr_commit_write,
2101 .srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk,
2102 .srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk,
2103 .srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc,
2104 .srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser,
2105 .srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt,
2106 .srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr,
2107 .srcimp_mgr_commit_write = srcimp_mgr_commit_write,
2109 .amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk,
2110 .amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk,
2111 .amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk,
2112 .amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk,
2113 .amixer_set_mode = amixer_set_mode,
2114 .amixer_set_iv = amixer_set_iv,
2115 .amixer_set_x = amixer_set_x,
2116 .amixer_set_y = amixer_set_y,
2117 .amixer_set_sadr = amixer_set_sadr,
2118 .amixer_set_se = amixer_set_se,
2119 .amixer_set_dirty = amixer_set_dirty,
2120 .amixer_set_dirty_all = amixer_set_dirty_all,
2121 .amixer_commit_write = amixer_commit_write,
2122 .amixer_get_y = amixer_get_y,
2123 .amixer_get_dirty = amixer_get_dirty,
2125 .dai_get_ctrl_blk = dai_get_ctrl_blk,
2126 .dai_put_ctrl_blk = dai_put_ctrl_blk,
2127 .dai_srt_set_srco = dai_srt_set_srco,
2128 .dai_srt_set_srcm = dai_srt_set_srcm,
2129 .dai_srt_set_rsr = dai_srt_set_rsr,
2130 .dai_srt_set_drat = dai_srt_set_drat,
2131 .dai_srt_set_ec = dai_srt_set_ec,
2132 .dai_srt_set_et = dai_srt_set_et,
2133 .dai_commit_write = dai_commit_write,
2135 .dao_get_ctrl_blk = dao_get_ctrl_blk,
2136 .dao_put_ctrl_blk = dao_put_ctrl_blk,
2137 .dao_set_spos = dao_set_spos,
2138 .dao_commit_write = dao_commit_write,
2139 .dao_get_spos = dao_get_spos,
2141 .daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk,
2142 .daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk,
2143 .daio_mgr_enb_dai = daio_mgr_enb_dai,
2144 .daio_mgr_dsb_dai = daio_mgr_dsb_dai,
2145 .daio_mgr_enb_dao = daio_mgr_enb_dao,
2146 .daio_mgr_dsb_dao = daio_mgr_dsb_dao,
2147 .daio_mgr_dao_init = daio_mgr_dao_init,
2148 .daio_mgr_set_imaparc = daio_mgr_set_imaparc,
2149 .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt,
2150 .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr,
2151 .daio_mgr_commit_write = daio_mgr_commit_write,
2154 int __devinit create_20k2_hw_obj(struct hw **rhw)
2156 struct hw20k2 *hw20k2;
2159 hw20k2 = kzalloc(sizeof(*hw20k2), GFP_KERNEL);
2163 hw20k2->hw = ct20k2_preset;
2169 int destroy_20k2_hw_obj(struct hw *hw)
2172 hw_card_shutdown(hw);