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