4 /* Timeouts in milliseconds */
5 #define WIP_TIMEOUT 250UL
6 #define DRDY_TIMEOUT 250UL
8 /* The default SRC syncronization state number is 1. This state occurs
9 just after de-assertion of SYNC. This is supposed to be the safest
10 state for accessing the codec with an ES1371 Rev 1. Later versions
11 of the chip allegedly don't require syncronization. Be very careful
12 if you change this ! */
14 #define SRC_UNSYNCED 0xffffffffUL
15 static u32_t SrcSyncState
= 0x00010000UL
;
18 void CodecSetSrcSyncState (int state
)
21 SrcSyncState
= SRC_UNSYNCED
;
23 SrcSyncState
= (u32_t
)state
<< 16;
24 SrcSyncState
&= 0x00070000Ul
;
29 int CodecWrite (DEV_STRUCT
* pCC
, u16_t wAddr
, u16_t wData
)
32 u16_t wBaseAddr
= pCC
->base
;
34 /* wait for WIP bit (Write In Progress) to go away */
35 /* remember, register CONC_dCODECCTL_OFF (0x14)
36 is a pseudo read-write register */
37 if (WaitBitd (wBaseAddr
+ CONC_dCODECCTL_OFF
, 30, 0, WIP_TIMEOUT
)){
38 printf("CODEC_ERR_WIP_TIMEOUT\n");
39 return (CODEC_ERR_WIP_TIMEOUT
);
41 if (SRC_UNSYNCED
!= SrcSyncState
)
43 /* enable SRC state data in SRC mux */
44 if (WaitBitd (wBaseAddr
+ CONC_dSRCIO_OFF
, SRC_BUSY_BIT
, 0, 1000))
45 return (CODEC_ERR_SRC_NOT_BUSY_TIMEOUT
);
47 /* todo: why are we writing an undefined register? */
48 dtemp
= pci_inl(wBaseAddr
+ CONC_dSRCIO_OFF
);
49 pci_outl(wBaseAddr
+ CONC_dSRCIO_OFF
, (dtemp
& SRC_CTLMASK
) |
52 /* wait for a SAFE time to write addr/data and then do it */
54 for( i
= 0; i
< 0x1000UL
; ++i
)
55 if( (pci_inl(wBaseAddr
+ CONC_dSRCIO_OFF
) & 0x00070000UL
) ==
61 return (CODEC_ERR_SRC_SYNC_TIMEOUT
);
65 /* A test for 5880 - prime the PCI data bus */
67 u32_t dat
= ((u32_t
) wAddr
<< 16) | wData
;
68 char page
= pci_inb(wBaseAddr
+ CONC_bMEMPAGE_OFF
);
70 pci_outl (wBaseAddr
+ CONC_bMEMPAGE_OFF
, dat
);
72 /* write addr and data */
73 pci_outl(wBaseAddr
+ CONC_dCODECCTL_OFF
, dat
);
75 pci_outb(wBaseAddr
+ CONC_bMEMPAGE_OFF
, page
); /* restore page reg */
78 if (SRC_UNSYNCED
!= SrcSyncState
)
83 if (WaitBitd (wBaseAddr
+ CONC_dSRCIO_OFF
, SRC_BUSY_BIT
, 0, 1000))
84 return (CODEC_ERR_SRC_NOT_BUSY_TIMEOUT
);
86 pci_outl(wBaseAddr
+ CONC_dSRCIO_OFF
, dtemp
& 0xfff8ffffUL
);
92 int CodecRead (DEV_STRUCT
* pCC
, u16_t wAddr
, u16_t
*data
)
95 u16_t base
= pCC
->base
;
97 /* wait for WIP to go away */
98 if (WaitBitd (base
+ CONC_dCODECCTL_OFF
, 30, 0, WIP_TIMEOUT
))
99 return (CODEC_ERR_WIP_TIMEOUT
);
101 if (SRC_UNSYNCED
!= SrcSyncState
)
103 /* enable SRC state data in SRC mux */
104 if (WaitBitd (base
+ CONC_dSRCIO_OFF
, SRC_BUSY_BIT
, 0, 1000))
105 return (CODEC_ERR_SRC_NOT_BUSY_TIMEOUT
);
107 dtemp
= pci_inl(base
+ CONC_dSRCIO_OFF
);
108 pci_outl(base
+ CONC_dSRCIO_OFF
, (dtemp
& SRC_CTLMASK
) |
111 /* wait for a SAFE time to write a read request and then do it */
112 /* todo: how do we solve the lock() problem? */
114 for( i
= 0; i
< 0x1000UL
; ++i
)
115 if( (pci_inl(base
+ CONC_dSRCIO_OFF
) & 0x00070000UL
) ==
121 return (CODEC_ERR_SRC_SYNC_TIMEOUT
);
125 /* A test for 5880 - prime the PCI data bus */
127 /* set bit 23, this means read in stead of write. */
128 u32_t dat
= ((u32_t
) wAddr
<< 16) | (1UL << 23);
129 char page
= pci_inb(base
+ CONC_bMEMPAGE_OFF
);
131 /* todo: why are we putting data in the mem page register??? */
132 pci_outl(base
+ CONC_bMEMPAGE_OFF
, dat
);
134 /* write addr w/data=0 and assert read request */
135 pci_outl(base
+ CONC_dCODECCTL_OFF
, dat
);
137 pci_outb(base
+ CONC_bMEMPAGE_OFF
, page
); /* restore page reg */
140 if (SRC_UNSYNCED
!= SrcSyncState
)
145 /* restore SRC reg */
146 if (WaitBitd (base
+ CONC_dSRCIO_OFF
, SRC_BUSY_BIT
, 0, 1000))
147 return (CODEC_ERR_SRC_NOT_BUSY_TIMEOUT
);
149 pci_outl(base
+ CONC_dSRCIO_OFF
, dtemp
& 0xfff8ffffUL
);
152 /* now wait for the stinkin' data (DRDY = data ready) */
153 if (WaitBitd (base
+ CONC_dCODECCTL_OFF
, 31, 1, DRDY_TIMEOUT
))
154 return (CODEC_ERR_DATA_TIMEOUT
);
156 dtemp
= pci_inl(base
+ CONC_dCODECCTL_OFF
);
159 *data
= (u16_t
) dtemp
;
165 int CodecWriteUnsynced (DEV_STRUCT
* pCC
, u16_t wAddr
, u16_t wData
)
167 /* wait for WIP to go away */
168 if (WaitBitd (pCC
->base
+ CONC_dCODECCTL_OFF
, 30, 0, WIP_TIMEOUT
))
169 return (CODEC_ERR_WIP_TIMEOUT
);
171 /* write addr and data */
172 pci_outl(pCC
->base
+ CONC_dCODECCTL_OFF
, ((u32_t
) wAddr
<< 16) | wData
);
177 int CodecReadUnsynced (DEV_STRUCT
* pCC
, u16_t wAddr
, u16_t
*data
)
181 /* wait for WIP to go away */
182 if (WaitBitd (pCC
->base
+ CONC_dCODECCTL_OFF
, 30, 0, WIP_TIMEOUT
))
183 return (CODEC_ERR_WIP_TIMEOUT
);
185 /* write addr w/data=0 and assert read request */
186 pci_outl(pCC
->base
+ CONC_dCODECCTL_OFF
, ((u32_t
) wAddr
<< 16) | (1UL << 23));
188 /* now wait for the stinkin' data (RDY) */
189 if (WaitBitd (pCC
->base
+ CONC_dCODECCTL_OFF
, 31, 1, DRDY_TIMEOUT
))
190 return (CODEC_ERR_DATA_TIMEOUT
);
192 dtemp
= pci_inl(pCC
->base
+ CONC_dCODECCTL_OFF
);
195 *data
= (u16_t
) dtemp
;
200 int CODECInit( DEV_STRUCT
* pCC
)
203 /* All powerdown modes: off */
205 retVal
= CodecWrite (pCC
, AC97_POWERDOWN_CONTROL_STAT
, 0x0000U
);
209 /* Mute Line Out & set to 0dB attenuation */
211 retVal
= CodecWrite (pCC
, AC97_MASTER_VOLUME
, 0x0000U
);
216 retVal
= CodecWrite (pCC
, AC97_MONO_VOLUME
, 0x8000U
);
220 retVal
= CodecWrite (pCC
, AC97_PHONE_VOLUME
, 0x8008U
);
224 retVal
= CodecWrite (pCC
, AC97_MIC_VOLUME
, 0x0008U
);
228 retVal
= CodecWrite (pCC
, AC97_LINE_IN_VOLUME
, 0x0808U
);
232 retVal
= CodecWrite (pCC
, AC97_CD_VOLUME
, 0x0808U
);
236 retVal
= CodecWrite (pCC
, AC97_AUX_IN_VOLUME
, 0x0808U
);
240 retVal
= CodecWrite (pCC
, AC97_PCM_OUT_VOLUME
, 0x0808U
);
244 retVal
= CodecWrite (pCC
, AC97_RECORD_GAIN_VOLUME
, 0x0000U
);
248 /* Connect Line In to ADC */
249 retVal
= CodecWrite (pCC
, AC97_RECORD_SELECT
, 0x0404U
);
253 retVal
= CodecWrite (pCC
, AC97_GENERAL_PURPOSE
, 0x0000U
);