2 Copyright © 2005-2013, Davy Wentzler. All rights reserved.
6 #include <exec/memory.h>
7 #include <proto/expansion.h>
10 #include "pci_wrapper.h"
13 #include "library_card.h"
15 #include "library_mos.h"
20 #include "interrupt.h"
23 #include "DriverData.h"
27 /* Global in Card.c */
28 extern const UWORD InputBits
[];
29 extern struct DOSIFace
*IDOS
;
30 extern struct MMUIFace
* IMMU
;
32 struct Device
*TimerBase
= NULL
;
33 struct timerequest
*TimerIO
= NULL
;
34 struct MsgPort
*replymp
= NULL
;
35 unsigned long Dirs
[7] = {0x005FFFFF, 0x005FFFFF, 0x001EFFF7, 0x004000FA, 0x004000FA, 0x007FFF9F, 0x00FFFFFF};
37 /* Public functions in main.c */
38 int card_init(struct CardData
*card
);
39 void card_cleanup(struct CardData
*card
);
40 int aureon_ac97_init(struct CardData
*card
, unsigned long base
);
41 void AddResetHandler(struct CardData
*card
);
44 extern struct DriverBase
* AHIsubBase
;
47 static unsigned char inits_ak4358
[] = {
48 0x01, 0x02, /* 1: reset + soft mute */
50 0x00, 0x87, // I2S + unreset (used to be 0F)
52 0x01, 0x01, // unreset + soft mute off
53 0x02, 0x4F, /* 2: DA's power up, normal speed, RSTN#=0 */
54 0x03, 0x01, /* 3: de-emphasis 44.1 */
56 0x04, 0xFF, /* 4: LOUT1 volume (PCM) */
57 0x05, 0xFF, /* 5: ROUT1 volume */
59 0x06, 0x00, /* 6: LOUT2 volume (analogue in monitor, doesn't work) */
60 0x07, 0x00, /* 7: ROUT2 volume */
62 0x08, 0xFF, /* 8: LOUT3 volume (dig out monitor, use it as analogue out) */
63 0x09, 0xFF, /* 9: ROUT3 volume */
65 0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
67 0x0b, 0xFF, /* b: LOUT4 volume */
68 0x0c, 0xFF, /* c: ROUT4 volume */
76 void revo_i2s_mclk_changed(struct CardData
*card
)
78 /* assert PRST# to converters; MT05 bit 7 */
79 OUTBYTE(card
->mtbase
+ MT_AC97_CMD_STATUS
, INBYTE(card
->mtbase
+ MT_AC97_CMD_STATUS
) | 0x80);
82 OUTBYTE(card
->mtbase
+ MT_AC97_CMD_STATUS
, INBYTE(card
->mtbase
+ MT_AC97_CMD_STATUS
) & ~0x80);
86 void ClearMask8(struct CardData
*card
, unsigned long base
, unsigned char reg
, unsigned char mask
)
90 tmp
= INBYTE(base
+ reg
);
92 OUTBYTE(base
+ reg
, tmp
);
96 void WriteMask8(struct CardData
*card
, unsigned long base
, unsigned char reg
, unsigned char mask
)
100 tmp
= INBYTE(base
+ reg
);
102 OUTBYTE(base
+ reg
, tmp
);
106 void WritePartialMask(struct CardData
*card
, unsigned long base
, unsigned char reg
, unsigned long shift
, unsigned long mask
, unsigned long val
)
110 tmp
= INLONG(base
+ reg
);
111 tmp
&= ~(mask
<< shift
);
113 OUTLONG(base
+ reg
, tmp
);
117 void SetGPIOData(struct CardData
*card
, unsigned long base
, unsigned long data
)
119 OUTWORD(base
+ CCS_GPIO_DATA
, data
& 0xFFFF);
120 OUTBYTE(base
+ CCS_GPIO_DATA2
, (data
& (0xFF0000)) >> 16);
121 INWORD(base
+ CCS_GPIO_DATA
); /* dummy read for pci-posting */
124 void SetGPIOMask(struct CardData
*card
, unsigned long base
, unsigned long data
)
126 OUTWORD(base
+ CCS_GPIO_MASK
, data
& 0xFFFF);
127 OUTBYTE(base
+ CCS_GPIO_MASK2
, (data
& (0xFF0000)) >> 16);
128 INWORD(base
+ CCS_GPIO_MASK
); /* dummy read for pci-posting */
132 void SaveGPIO(struct PCIDevice
*dev
, struct CardData
* card
)
134 card
->SavedDir
= INLONG(card
->iobase
+ CCS_GPIO_DIR
) & 0x7FFFFF;
135 card
->SavedMask
= INWORD(card
->iobase
+ CCS_GPIO_MASK
);
139 void RestoreGPIO(struct PCIDevice
*dev
, struct CardData
* card
)
141 OUTLONG(card
->iobase
+ CCS_GPIO_DIR
, card
->SavedDir
);
142 OUTWORD(card
->iobase
+ CCS_GPIO_MASK
, card
->SavedMask
);
146 unsigned long GetGPIOData(struct CardData
*card
, unsigned long base
)
150 data
= (unsigned long) INBYTE(base
+ CCS_GPIO_DATA2
);
151 data
= (data
<< 16) | INWORD(base
+ CCS_GPIO_DATA
);
156 void SetGPIODir(struct PCIDevice
*dev
, struct CardData
* card
, unsigned long data
)
158 OUTLONG(card
->iobase
+ CCS_GPIO_DIR
, data
);
159 INWORD(card
->iobase
+ CCS_GPIO_DIR
);
163 unsigned char ReadI2C(struct PCIDevice
*dev
, struct CardData
*card
, unsigned char addr
)
169 OUTBYTE(card
->iobase
+ CCS_I2C_ADDR
, addr
);
170 OUTBYTE(card
->iobase
+ CCS_I2C_DEV_ADDRESS
, 0xA0);
172 while ((INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_BUSY
) && counter
< 10000)
178 if (counter
== 10000)
180 bug("Error reading from I2C\n");
183 val
= INBYTE(card
->iobase
+ CCS_I2C_DATA
);
189 void WriteI2C(struct PCIDevice
*dev
, struct CardData
*card
, unsigned chip_address
, unsigned char reg
, unsigned char data
)
193 while ((INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_BUSY
) && counter
< 10000)
199 if (counter
== 10000)
201 bug("Error reading from I2C (for write)\n");
205 OUTBYTE(card
->iobase
+ CCS_I2C_ADDR
, reg
);
206 OUTBYTE(card
->iobase
+ CCS_I2C_DATA
, data
);
208 while ((INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_BUSY
) && counter
< 10000)
213 if (counter
== 10000)
215 bug("Error reading from I2C (for write 2)\n");
218 OUTBYTE(card
->iobase
+ CCS_I2C_DEV_ADDRESS
, chip_address
| CCS_ADDRESS_WRITE
);
222 void update_spdif_bits(struct CardData
*card
, unsigned short val
)
224 unsigned char cbit
, disabled
;
226 cbit
= INBYTE(card
->iobase
+ CCS_SPDIF_CONFIG
); // get S/PDIF status
227 disabled
= cbit
& ~CCS_SPDIF_INTEGRATED
; // status without enabled bit set
229 if (cbit
!= disabled
) // it was enabled
230 OUTBYTE(card
->iobase
+ CCS_SPDIF_CONFIG
, disabled
); // so, disable it
232 OUTWORD(card
->mtbase
+ MT_SPDIF_TRANSMIT
, val
); // now we can safely write to the SPDIF control reg
234 if (cbit
!= disabled
)
235 OUTBYTE(card
->iobase
+ CCS_SPDIF_CONFIG
, cbit
); // restore
237 OUTWORD(card
->mtbase
+ MT_SPDIF_TRANSMIT
, val
); // twice???
241 void update_spdif_rate(struct CardData
*card
, unsigned short rate
)
243 unsigned short val
, nval
;
245 nval
= val
= INWORD(card
->mtbase
+ MT_SPDIF_TRANSMIT
);
249 case 48000: nval
|= 2 << 12; break;
250 case 32000: nval
|= 3 << 12; break;
253 update_spdif_bits(card
, nval
);
257 static void aureon_spi_write(struct CardData
*card
, unsigned long base
, unsigned int cs
, unsigned int data
, int bits
)
262 tmp
= GetGPIOData(card
, base
);
264 if (card
->SubType
== PHASE28
)
265 SetGPIOMask(card
, base
, ~(AUREON_WM_RW
|AUREON_WM_DATA
|AUREON_WM_CLK
|AUREON_WM_CS
));
267 SetGPIOMask(card
, base
, ~(AUREON_WM_RW
|AUREON_WM_DATA
|AUREON_WM_CLK
|AUREON_WM_CS
| AUREON_CS8415_CS
));
269 SetGPIOMask(card
, base
, 0);
273 SetGPIOData(card
, base
, tmp
); // set CS low
277 for (i
= bits
- 1; i
>= 0; i
--) {
278 tmp
&= ~AUREON_WM_CLK
;
279 SetGPIOData(card
, base
, tmp
);
282 tmp
|= AUREON_WM_DATA
;
284 tmp
&= ~AUREON_WM_DATA
;
285 SetGPIOData(card
, base
, tmp
);
287 tmp
|= AUREON_WM_CLK
;
288 SetGPIOData(card
, base
, tmp
);
292 tmp
&= ~AUREON_WM_CLK
;
294 SetGPIOData(card
, base
, tmp
);
296 tmp
|= AUREON_WM_CLK
;
297 SetGPIOData(card
, base
, tmp
);
302 static void aureon_ac97_write(struct CardData
*card
, unsigned long base
, unsigned short reg
, unsigned short val
)
306 /* Send address to XILINX chip */
307 tmp
= (GetGPIOData(card
, base
) & ~0xFF) | (reg
& 0x7F);
308 SetGPIOData(card
, base
, tmp
);
310 tmp
|= AUREON_AC97_ADDR
;
311 SetGPIOData(card
, base
, tmp
);
313 tmp
&= ~AUREON_AC97_ADDR
;
314 SetGPIOData(card
, base
, tmp
);
317 /* Send low-order byte to XILINX chip */
318 tmp
&= ~AUREON_AC97_DATA_MASK
;
319 tmp
|= val
& AUREON_AC97_DATA_MASK
;
320 SetGPIOData(card
, base
, tmp
);
322 tmp
|= AUREON_AC97_DATA_LOW
;
323 SetGPIOData(card
, base
, tmp
);
325 tmp
&= ~AUREON_AC97_DATA_LOW
;
326 SetGPIOData(card
, base
, tmp
);
329 /* Send high-order byte to XILINX chip */
330 tmp
&= ~AUREON_AC97_DATA_MASK
;
331 tmp
|= (val
>> 8) & AUREON_AC97_DATA_MASK
;
333 SetGPIOData(card
, base
, tmp
);
335 tmp
|= AUREON_AC97_DATA_HIGH
;
336 SetGPIOData(card
, base
, tmp
);
338 tmp
&= ~AUREON_AC97_DATA_HIGH
;
339 SetGPIOData(card
, base
, tmp
);
342 /* Instruct XILINX chip to parse the data to the STAC9744 chip */
343 tmp
|= AUREON_AC97_COMMIT
;
344 SetGPIOData(card
, base
, tmp
);
346 tmp
&= ~AUREON_AC97_COMMIT
;
347 SetGPIOData(card
, base
, tmp
);
352 int aureon_ac97_init(struct CardData
*card
, unsigned long base
)
355 static unsigned short ac97_defaults
[] = {
357 AC97_MASTER_VOL_STEREO
, 0x0101, // 0dB atten., no mute, may not exceed 0101!!!
358 AC97_AUXOUT_VOL
, 0x8808,
359 AC97_MASTER_VOL_MONO
, 0x8000,
360 AC97_PHONE_VOL
, 0x8008, // mute
361 AC97_MIC_VOL
, 0x8008,
362 AC97_LINEIN_VOL
, 0x8808,
364 AC97_VIDEO_VOL
, 0x8808,
365 AC97_AUX_VOL
, 0x8808,
366 AC97_PCMOUT_VOL
, 0x8808,
379 tmp
= (GetGPIOData(card
, base
) | AUREON_AC97_RESET
) & ~AUREON_AC97_DATA_MASK
;
381 SetGPIOData(card
, base
, tmp
);
384 tmp
&= ~AUREON_AC97_RESET
;
385 SetGPIOData(card
, base
, tmp
);
388 tmp
|= AUREON_AC97_RESET
;
389 SetGPIOData(card
, base
, tmp
);
392 for (i
=0; ac97_defaults
[i
] != (unsigned short)-1; i
+=2)
393 aureon_ac97_write(card
, base
, ac97_defaults
[i
], ac97_defaults
[i
+1]);
401 void wm_put(struct CardData
*card
, unsigned long base
, unsigned short reg
, unsigned short val
)
403 aureon_spi_write(card
, base
, AUREON_WM_CS
, (reg
<< 9) | (val
& 0x1ff), 16);
408 BOOL
SetupTimerDevice()
415 void MicroDelay(unsigned int val
)
417 replymp
= (struct MsgPort
*) CREATEPORT( NULL
, 0 );
420 DEBUGPRINTF("Could not create the reply port!\n" );
424 TimerIO
= (struct timerequest
*) CREATEIOREQUEST( replymp
, sizeof( struct timerequest
) );
428 DEBUGPRINTF( "Out of memory.\n" );
432 if( OPENDEVICE( "timer.device", UNIT_MICROHZ
, (struct IORequest
*) TimerIO
, 0) != 0 )
434 DEBUGPRINTF( "Unable to open 'timer.device'.\n" );
440 TimerBase
= (struct Device
*) TimerIO
->tr_node
.io_Device
;
446 TimerIO
->tr_node
.io_Command
= TR_ADDREQUEST
; /* Add a request. */
447 TimerIO
->tr_time
.tv_secs
= 0; /* 0 seconds. */
448 TimerIO
->tr_time
.tv_micro
= val
; /* 'val' micro seconds. */
449 DOIO( (struct IORequest
*) TimerIO
);
450 CLOSEDEVICE( (struct IORequest
*) TimerIO
);
451 DELETEIOREQUEST( (struct IORequest
*) TimerIO
);
462 void CleanUpTimerDevice()
468 INTGW( static, void, playbackinterrupt
, PlaybackInterrupt
);
469 INTGW( static, void, recordinterrupt
, RecordInterrupt
);
470 INTGW( static, ULONG
, cardinterrupt
, CardInterrupt
);
473 /******************************************************************************
474 ** DriverData allocation ******************************************************
475 ******************************************************************************/
477 // This code used to be in _AHIsub_AllocAudio(), but since we're now
478 // handling CAMD support too, it needs to be done at driver loading
481 struct CardData
* AllocDriverData(struct PCIDevice
*dev
, struct DriverBase
* AHIsubBase
)
483 struct CardData
* card
;
486 card
= ALLOCVEC( sizeof( *card
), MEMF_PUBLIC
| MEMF_CLEAR
);
490 Req( "Unable to allocate driver structure." );
494 card
->ahisubbase
= AHIsubBase
;
496 card
->interrupt
.is_Node
.ln_Type
= IRQTYPE
;
497 card
->interrupt
.is_Node
.ln_Pri
= 0;
498 card
->interrupt
.is_Node
.ln_Name
= (STRPTR
) LibName
;
500 card
->interrupt
.is_Code
= (void(*)(void)) CardInterrupt
;
502 card
->interrupt
.is_Code
= (void(*)(void)) &cardinterrupt
;
504 card
->interrupt
.is_Data
= (APTR
) card
;
506 card
->playback_interrupt
.is_Node
.ln_Type
= IRQTYPE
;
507 card
->playback_interrupt
.is_Node
.ln_Pri
= 0;
508 card
->playback_interrupt
.is_Node
.ln_Name
= (STRPTR
) LibName
;
510 card
->playback_interrupt
.is_Code
= PlaybackInterrupt
;
512 card
->playback_interrupt
.is_Code
= (void(*)(void)) &playbackinterrupt
;
514 card
->playback_interrupt
.is_Data
= (APTR
) card
;
516 card
->record_interrupt
.is_Node
.ln_Type
= IRQTYPE
;
517 card
->record_interrupt
.is_Node
.ln_Pri
= 0;
518 card
->record_interrupt
.is_Node
.ln_Name
= (STRPTR
) LibName
;
520 card
->record_interrupt
.is_Code
= RecordInterrupt
;
522 card
->record_interrupt
.is_Code
= (void(*)(void)) &recordinterrupt
;
524 card
->record_interrupt
.is_Data
= (APTR
) card
;
528 command_word
= READCONFIGWORD( PCI_COMMAND
);
529 command_word
|= PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
; // | PCI_COMMAND_MASTER;
530 WRITECONFIGWORD( PCI_COMMAND
, command_word
);
533 card
->pci_master_enabled
= TRUE
;
536 card
->iobase
= (unsigned long)ahi_pci_get_base_address(0, dev
);
537 card
->mtbase
= (unsigned long)ahi_pci_get_base_address(1, dev
);
538 card
->irq
= ahi_pci_get_irq(dev
);
539 card
->chiprev
= READCONFIGBYTE( PCI_REVISION_ID
);
540 card
->model
= READCONFIGWORD( PCI_SUBSYSTEM_ID
);
543 /*DEBUGPRINTF("---> chiprev = %u, model = %x, Vendor = %x\n", READCONFIGBYTE( PCI_REVISION_ID), READCONFIGWORD( PCI_SUBSYSTEM_ID),
544 READCONFIGWORD( PCI_SUBSYSTEM_VENDOR_ID));*/
548 if (SetupTimerDevice() == FALSE
)
553 /* Initialize chip */
554 if( card_init( card
) < 0 )
556 DEBUGPRINTF("Unable to initialize Card subsystem.");
561 //DEBUGPRINTF("INTERRUPT %lu\n", dev->MapInterrupt());
562 ahi_pci_add_intserver(&card
->interrupt
, dev
);
563 card
->interrupt_added
= TRUE
;
565 card
->card_initialized
= TRUE
;
567 if (card
->SubType
== REVO51
)
569 card
->input
= 1; // line in
576 card
->monitor_volume
= 0;
577 card
->input_gain
= 0x10000;
578 card
->output_volume
= 0x10000;
579 card
->input_is_24bits
= FALSE
;
580 card
->playback_buffer
= NULL
;
581 card
->current_bytesize
= 0;
583 //SaveMixerState(card);
586 AddResetHandler(card
);
593 /******************************************************************************
594 ** DriverData deallocation ****************************************************
595 ******************************************************************************/
597 // And this code used to be in _AHIsub_FreeAudio().
600 FreeDriverData( struct CardData
* card
,
601 struct DriverBase
* AHIsubBase
)
605 if( card
->pci_dev
!= NULL
)
607 if( card
->card_initialized
)
609 card_cleanup( card
);
612 if( card
->pci_master_enabled
)
615 struct PCIDevice
* dev
= card
->pci_dev
;
616 cmd
= READCONFIGWORD( PCI_COMMAND
);
617 cmd
&= ~( PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
618 WRITECONFIGWORD( PCI_COMMAND
, cmd
);
622 if( card
->interrupt_added
)
624 ahi_pci_rem_intserver(&card
->interrupt
, card
->pci_dev
);
630 CleanUpTimerDevice();
634 static unsigned short wm_inits
[] = {
636 0x18, 0x000, /* All power-up */
638 0x1b, 0x022, /* ADC Mux (AIN1 = CD-in) */
639 0x1c, 0x00B, /* Output1 = DAC + Aux (= ac'97 mix), output2 = DAC */
640 0x1d, 0x009, /* Output3+4 = DAC */
642 0x16, 0x122, /* I2S, normal polarity, 24bit */
643 0x17, 0x022, /* 256fs, slave mode */
645 0x00, 0x17F, /* DAC1 analog mute */
646 0x01, 0x17F, /* DAC2 analog mute */
647 0x02, 0x17F, /* DAC3 analog mute */
648 0x03, 0x17F, /* DAC4 analog mute */
649 0x04, 0x7F, /* DAC5 analog mute */
650 0x05, 0x7F, /* DAC6 analog mute */
651 0x06, 0x7F, /* DAC7 analog mute */
652 0x07, 0x7F, /* DAC8 analog mute */
653 0x08, 0x17F, /* master analog mute */
654 0x09, 0x1ff, /* DAC1 digital full */
655 0x0a, 0x1ff, /* DAC2 digital full */
656 0x0b, 0xff, /* DAC3 digital full */
657 0x0c, 0xff, /* DAC4 digital full */
658 0x0d, 0xff, /* DAC5 digital full */
659 0x0e, 0xff, /* DAC6 digital full */
660 0x0f, 0xff, /* DAC7 digital full */
661 0x10, 0xff, /* DAC8 digital full */
662 0x11, 0x1ff, /* master digital full */
663 0x12, 0x000, /* phase normal */
664 0x13, 0x090, /* unmute DAC L/R */
665 0x14, 0x000, /* all unmute (bit 5 is rec enable) */
666 0x15, 0x000, /* no deemphasis, no ZFLG */
667 0x19, 0x0C, /* 0dB gain ADC/L */
668 0x1a, 0x0C /* 0dB gain ADC/R */
671 static unsigned short wm_inits_Phase28
[] = {
673 0x18, 0x000, /* All power-up */
675 0x1b, 0x000, /* ADC Mux (AIN1 = Line-in, no other inputs are present) */
676 0x1c, 0x009, /* Output1 = DAC , Output2 = DAC */
677 0x1d, 0x009, /* Output3+4 = DAC */
679 0x16, 0x122, /* I2S, normal polarity, 24bit */
680 0x17, 0x022, /* 256fs, slave mode */
682 0x00, 0x000, /* DAC1 analog mute */
683 0x01, 0x000, /* DAC2 analog mute */
684 0x02, 0x7F, /* DAC3 analog mute */
685 0x03, 0x7F, /* DAC4 analog mute */
686 0x04, 0x7F, /* DAC5 analog mute */
687 0x05, 0x7F, /* DAC6 analog mute */
688 0x06, 0x7F, /* DAC7 analog mute */
689 0x07, 0x7F, /* DAC8 analog mute */
690 0x08, 0x17F, /* master analog mute */
691 0x09, 0xff, /* DAC1 digital full */
692 0x0a, 0xff, /* DAC2 digital full */
693 0x0b, 0xff, /* DAC3 digital full */
694 0x0c, 0xff, /* DAC4 digital full */
695 0x0d, 0xff, /* DAC5 digital full */
696 0x0e, 0xff, /* DAC6 digital full */
697 0x0f, 0xff, /* DAC7 digital full */
698 0x10, 0xff, /* DAC8 digital full */
699 0x11, 0x1ff, /* master digital full */
700 0x12, 0x000, /* phase normal */
701 0x13, 0x090, /* unmute DAC L/R */
702 0x14, 0x000, /* all unmute (bit 5 is rec enable) */
703 0x15, 0x000, /* no deemphasis, no ZFLG */
704 0x19, 0x0C, /* 0dB gain ADC/L */
705 0x1a, 0x0C /* 0dB gain ADC/R */
708 static unsigned short cs_inits
[] = {
710 0x0180, /* no mute */
712 0x0605, /* master, 16-bit slave, 24bit */
716 int card_init(struct CardData
*card
)
718 struct PCIDevice
*dev
= (struct PCIDevice
*) card
->pci_dev
;
722 OUTBYTE(card
->mtbase
+ MT_AC97_CMD_STATUS
, MT_AC97_RESET
); // tbd
724 OUTBYTE(card
->mtbase
+ MT_AC97_CMD_STATUS
, 0x00); // tbd
726 //DEBUGPRINTF("Envy24HT: card_init %lx\n", card);
728 OUTBYTE(card
->iobase
+ CCS_POWER_DOWN
, 0); // power up the whole thing
731 OUTBYTE(card
->mtbase
+ CCS_CTRL
, CCS_RESET_ALL
);
733 ClearMask8(card
, card
->mtbase
, CCS_CTRL
, CCS_RESET_ALL
);
736 //DEBUGPRINTF("Envy24HT: reading eeprom\n");
737 if ((INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_EPROM
) != 0)
739 unsigned long subvendor
= 0;
742 (ReadI2C(dev
, card
, 0x00) << 0) |
743 (ReadI2C(dev
, card
, 0x01) << 8) |
744 (ReadI2C(dev
, card
, 0x02) << 16) |
745 (ReadI2C(dev
, card
, 0x03) << 24);
749 case SUBVENDOR_AUREON_SKY
: card
->SubType
= AUREON_SKY
;
752 case SUBVENDOR_AUREON_SPACE
: card
->SubType
= AUREON_SPACE
;
755 case SUBVENDOR_PHASE28
: card
->SubType
= PHASE28
;
758 case SUBVENDOR_MAUDIO_REVOLUTION51
: card
->SubType
= REVO51
;
761 case SUBVENDOR_MAUDIO_REVOLUTION71
: card
->SubType
= REVO71
;
764 case SUBVENDOR_JULIA
: card
->SubType
= JULIA
;
767 case SUBVENDOR_PHASE22
: card
->SubType
= PHASE22
;
771 card
->SubType
= AUREON_SKY
;
774 DEBUGPRINTF("subvendor = %lx, Type = %d\n", subvendor
, card
->SubType
);
778 if (card
->SubType
== PHASE22
)
780 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x28);
781 OUTBYTE(card
->iobase
+ CCS_ACLINK_CONFIG
, 0x80); // AC-link
782 OUTBYTE(card
->iobase
+ CCS_I2S_FEATURES
, 0x70); // I2S
783 OUTBYTE(card
->iobase
+ CCS_SPDIF_CONFIG
, 0xC3); // S/PDIF
787 if (card
->SubType
== PHASE28
)
788 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x2B); // MIDI, ADC+SPDIF IN, 4 DACS
789 else if (card
->SubType
== AUREON_SPACE
)
790 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x0B); // ADC+SPDIF IN, 4 DACS
791 else if (card
->SubType
== REVO71
)
792 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x43); // XIN1 + ADC + 4 DACS
793 else if (card
->SubType
== REVO51
)
794 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x42);
795 else if (card
->SubType
== JULIA
)
796 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x20); // MIDI + ADC + DAC
797 else if (card
->SubType
== AUREON_SKY
)
798 OUTBYTE(card
->iobase
+ CCS_SYSTEM_CONFIG
, 0x0A); // ADC+SPDIF IN, 3 DACS
800 OUTBYTE(card
->iobase
+ CCS_ACLINK_CONFIG
, CCS_ACLINK_I2S
); // I2S in split mode
802 if (card
->SubType
== JULIA
)
803 OUTBYTE(card
->iobase
+ CCS_I2S_FEATURES
, CCS_I2S_96KHZ
| CCS_I2S_24BIT
| CCS_I2S_192KHZ
);
805 OUTBYTE(card
->iobase
+ CCS_I2S_FEATURES
, CCS_I2S_VOLMUTE
| CCS_I2S_96KHZ
| CCS_I2S_24BIT
| CCS_I2S_192KHZ
);
807 if (card
->SubType
== REVO71
|| card
->SubType
== REVO51
)
808 OUTBYTE(card
->iobase
+ CCS_SPDIF_CONFIG
, CCS_SPDIF_INTEGRATED
| CCS_SPDIF_INTERNAL_OUT
| CCS_SPDIF_EXTERNAL_OUT
);
810 OUTBYTE(card
->iobase
+ CCS_SPDIF_CONFIG
, CCS_SPDIF_INTEGRATED
| CCS_SPDIF_INTERNAL_OUT
| CCS_SPDIF_IN_PRESENT
| CCS_SPDIF_EXTERNAL_OUT
);
814 card
->SavedDir
= Dirs
[card
->SubType
];
815 OUTBYTE(card
->mtbase
+ MT_INTR_MASK
, MT_DMA_FIFO_MASK
);
817 if (card
->SubType
== REVO71
)
818 SetGPIOMask(card
, card
->iobase
, 0x00BFFF85);
819 else if (card
->SubType
== REVO51
)
820 SetGPIOMask(card
, card
->iobase
, 0x00BFFF05);
822 SetGPIOMask(card
, card
->iobase
, 0x00000000);
824 OUTLONG(card
->iobase
+ CCS_GPIO_DIR
, Dirs
[card
->SubType
]); // input/output
825 INWORD(card
->iobase
+ CCS_GPIO_DIR
);
827 if (card
->SubType
== REVO71
|| card
->SubType
== REVO51
) {
828 OUTWORD(card
->iobase
+ CCS_GPIO_DATA
, 0x0072);
829 OUTBYTE(card
->iobase
+ CCS_GPIO_DATA2
, 0x00);
831 else if (card
->SubType
== JULIA
) {
832 OUTWORD(card
->iobase
+ CCS_GPIO_DATA
, 0x3819);
835 OUTWORD(card
->iobase
+ CCS_GPIO_DATA
, 0x0000);
836 if (card
->SubType
!= PHASE22
)
837 OUTBYTE(card
->iobase
+ CCS_GPIO_DATA2
, 0x00);
839 INWORD(card
->iobase
+ CCS_GPIO_DATA
);
841 //SaveGPIO(dev, card);
843 if (card
->SubType
== REVO71
|| card
->SubType
== REVO51
)
844 OUTBYTE(card
->mtbase
+ MT_I2S_FORMAT
, 0x08);
846 OUTBYTE(card
->mtbase
+ MT_I2S_FORMAT
, 0);
848 if (card
->SubType
== AUREON_SKY
|| card
->SubType
== AUREON_SPACE
|| card
->SubType
== PHASE28
)
850 if (card
->SubType
== AUREON_SKY
|| card
->SubType
== AUREON_SPACE
)
852 aureon_ac97_init(card
, card
->iobase
);
853 SetGPIOMask(card
, card
->iobase
, ~(AUREON_WM_RESET
| AUREON_WM_CS
| AUREON_CS8415_CS
));
855 else if (card
->SubType
== PHASE28
)
856 SetGPIOMask(card
, card
->iobase
, ~(AUREON_WM_RESET
| AUREON_WM_CS
));
859 tmp
= GetGPIOData(card
, card
->iobase
);
860 tmp
&= ~AUREON_WM_RESET
;
861 SetGPIOData(card
, card
->iobase
, tmp
);
864 if (card
->SubType
!= PHASE28
)
865 tmp
|= AUREON_WM_CS
| AUREON_CS8415_CS
;
869 SetGPIOData(card
, card
->iobase
, tmp
);
871 tmp
|= AUREON_WM_RESET
;
872 SetGPIOData(card
, card
->iobase
, tmp
);
875 if (card
->SubType
!= PHASE28
)
877 /* initialize WM8770 codec */
878 for (i
= 0; i
< 60; i
+= 2)
880 wm_put(card
, card
->iobase
, wm_inits
[i
], wm_inits
[i
+1]);
883 /* initialize CS8415A codec */
884 for (i
= 0; i
< 4; i
++)
885 aureon_spi_write(card
, card
->iobase
, AUREON_CS8415_CS
, cs_inits
[i
] | 0x200000, 24);
889 /* initialize WM8770 codec */
890 for (i
= 0; i
< 60; i
+= 2)
892 wm_put(card
, card
->iobase
, wm_inits_Phase28
[i
], wm_inits_Phase28
[i
+1]);
896 else if (card
->SubType
== REVO51
)
898 card
->RevoFrontCodec
= ALLOCVEC(sizeof(struct akm_codec
), MEMF_ANY
);
899 card
->RevoFrontCodec
->caddr
= 2;
900 card
->RevoFrontCodec
->cif
= 0;
901 card
->RevoFrontCodec
->datamask
= REVO_CDOUT
;
902 card
->RevoFrontCodec
->clockmask
= REVO_CCLK
;
903 card
->RevoFrontCodec
->csmask
= REVO_CS0
| REVO_CS1
;
904 card
->RevoFrontCodec
->csaddr
= REVO_CS1
;
905 card
->RevoFrontCodec
->csnone
= REVO_CS0
| REVO_CS1
;
906 card
->RevoFrontCodec
->addflags
= REVO_CCLK
;
907 card
->RevoFrontCodec
->type
= AKM4358
;
908 card
->RevoFrontCodec
->totalmask
= 0;
909 card
->RevoFrontCodec
->newflag
= 1;
912 card
->RevoSurroundCodec
= NULL
;
914 card
->RevoRecCodec
= ALLOCVEC(sizeof(struct akm_codec
), MEMF_ANY
);
915 card
->RevoRecCodec
->caddr
= 2;
916 card
->RevoRecCodec
->csmask
= REVO_CS0
| REVO_CS1
;
917 card
->RevoRecCodec
->clockmask
= REVO_CCLK
;
918 card
->RevoRecCodec
->datamask
= REVO_CDOUT
;
919 card
->RevoRecCodec
->type
= AKM5365
;
920 card
->RevoRecCodec
->cif
= 0;
921 card
->RevoRecCodec
->addflags
= REVO_CCLK
;
922 card
->RevoRecCodec
->csaddr
= REVO_CS0
;
923 card
->RevoRecCodec
->csnone
= REVO_CS0
| REVO_CS1
;
924 card
->RevoRecCodec
->totalmask
= 0;
925 card
->RevoRecCodec
->newflag
= 1;
927 OUTBYTE(card
->mtbase
+ MT_SAMPLERATE
, 8);
930 unsigned int tmp
= GetGPIOData(card
, card
->iobase
);
931 tmp
&= ~REVO_MUTE
; // mute
932 SetGPIOData(card
, card
->iobase
, tmp
);
935 Init_akm4xxx(card
, card
->RevoFrontCodec
);
938 unsigned int tmp
= GetGPIOData(card
, card
->iobase
);
939 tmp
|= REVO_MUTE
; // unmute
940 SetGPIOData(card
, card
->iobase
, tmp
);
943 // Has to be after mute, otherwise the mask is changed in Revo51_Init() which enables the mute mask bit...
944 Revo51_Init(card
); // I2C
946 else if (card
->SubType
== REVO71
)
948 card
->RevoFrontCodec
= ALLOCVEC(sizeof(struct akm_codec
), MEMF_ANY
);
949 card
->RevoFrontCodec
->caddr
= 1;
950 card
->RevoFrontCodec
->csmask
= REVO_CS1
;
951 card
->RevoFrontCodec
->clockmask
= REVO_CCLK
;
952 card
->RevoFrontCodec
->datamask
= REVO_CDOUT
;
953 card
->RevoFrontCodec
->type
= AKM4381
;
954 card
->RevoFrontCodec
->cif
= 0;
955 card
->RevoFrontCodec
->addflags
= 0; //REVO_CCLK;?
957 card
->RevoSurroundCodec
= ALLOCVEC(sizeof(struct akm_codec
), MEMF_ANY
);
958 card
->RevoSurroundCodec
->caddr
= 3;
959 card
->RevoSurroundCodec
->csmask
= REVO_CS2
;
960 card
->RevoSurroundCodec
->clockmask
= REVO_CCLK
;
961 card
->RevoSurroundCodec
->datamask
= REVO_CDOUT
;
962 card
->RevoSurroundCodec
->type
= AKM4355
;
963 card
->RevoSurroundCodec
->cif
= 0;
964 card
->RevoSurroundCodec
->addflags
= 0; //REVO_CCLK;?
966 OUTBYTE(card
->mtbase
+ MT_SAMPLERATE
, 8);
969 unsigned int tmp
= GetGPIOData(card
, card
->iobase
);
970 tmp
&= ~REVO_MUTE
; // mute
971 SetGPIOData(card
, card
->iobase
, tmp
);
974 Init_akm4xxx(card
, card
->RevoFrontCodec
);
975 Init_akm4xxx(card
, card
->RevoSurroundCodec
);
976 //revo_i2s_mclk_changed(card);
979 unsigned int tmp
= GetGPIOData(card
, card
->iobase
);
980 tmp
|= REVO_MUTE
; // unmute
981 SetGPIOData(card
, card
->iobase
, tmp
);
985 else if (card
->SubType
== JULIA
)
987 unsigned char *ptr
, reg
, data
;
991 static unsigned char inits_ak4114
[] = {
992 0x00, 0x00, // power down & reset
993 0x00, 0x0F, // power on
995 0x02, 0x80, // TX1 output enable
996 0x03, 0x49, // 1024 LRCK + transmit data
997 0x04, 0x00, // no mask
998 0x05, 0x00, // no mask
1008 while (*ptr
!= 0xff) {
1011 WriteI2C(dev
, card
, AK4358_ADDR
, reg
, data
);
1016 while (*ptr
!= 0xff) {
1019 WriteI2C(dev
, card
, AK4114_ADDR
, reg
, data
);
1023 OUTBYTE(card
->mtbase
+ MT_SAMPLERATE
, MT_SPDIF_MASTER
);
1024 OUTLONG(card
->mtbase
+ 0x2C, 0x300200); // route
1026 else if (card
->SubType
== PHASE22
)
1028 card
->RevoFrontCodec
= ALLOCVEC(sizeof(struct akm_codec
), MEMF_ANY
);
1029 card
->RevoFrontCodec
->caddr
= 2;
1030 card
->RevoFrontCodec
->csmask
= 1 << 10;
1031 card
->RevoFrontCodec
->clockmask
= 1 << 5;
1032 card
->RevoFrontCodec
->datamask
= 1 << 4;
1033 card
->RevoFrontCodec
->type
= AKM4524
;
1034 card
->RevoFrontCodec
->cif
= 1;
1035 card
->RevoFrontCodec
->addflags
= 1 << 3;
1037 Init_akm4xxx(card
, card
->RevoFrontCodec
);
1040 //RestoreGPIO(dev, card);
1042 ClearMask8(card
, card
->iobase
, CCS_INTR_MASK
, CCS_INTR_PLAYREC
); // enable
1044 // Enter SPI mode for CS8415A digital receiver
1045 /*SetGPIOMask(card, card->iobase, ~(AUREON_CS8415_CS));
1046 tmp |= AUREON_CS8415_CS;
1047 SetGPIOData(card, card->iobase, tmp); // set CS high
1050 tmp &= ~AUREON_CS8415_CS;
1051 SetGPIOData(card, card->iobase, tmp); // set CS low
1054 // WritePartialMask(card, card->mtbase, 0x2C, 8, 7, 6); // this line is to route the s/pdif input to the left
1055 // analogue output for testing purposes
1061 void card_cleanup(struct CardData
*card
)
1067 /******************************************************************************
1068 ** Misc. **********************************************************************
1069 ******************************************************************************/
1072 SaveMixerState( struct CardData
* card
)
1078 RestoreMixerState( struct CardData
* card
)
1083 UpdateMonitorMixer( struct CardData
* card
)
1089 Linear2MixerGain( Fixed linear
,
1092 static const Fixed gain
[ 256 ] =
1354 while( linear
> gain
[ v
] && v
< 255)
1366 Linear2AKMGain( Fixed linear
,
1369 static const Fixed gain
[ 101 ] =
1477 while( linear
> gain
[ v
] && v
< 100)
1490 Linear2RecordGain( Fixed linear
,
1493 static const Fixed gain
[ 32 ] =
1531 while( linear
> gain
[ v
] && v
< 32)
1543 SamplerateToLinearPitch( ULONG samplingrate
)
1545 samplingrate
= (samplingrate
<< 8) / 375;
1546 return (samplingrate
>> 1) + (samplingrate
& 1);
1550 #define CACHELINE_SIZE 4096
1552 void *pci_alloc_consistent(size_t size
, APTR
*NonAlignedAddress
, unsigned int boundary
)
1558 if (IExec
->OpenResource("newmemory.resource"))
1560 address
= ALLOCVECTags(size
, AVT_Type
, MEMF_SHARED
, AVT_Contiguous
, TRUE
, AVT_Lock
, TRUE
,
1561 AVT_PhysicalAlignment
, 32, AVT_Clear
, 0, TAG_DONE
);
1565 address
= ALLOCVEC( size
+ CACHELINE_SIZE
, MEMF_PUBLIC
| MEMF_CLEAR
);
1567 if( address
!= NULL
)
1569 a
= (unsigned long) address
;
1570 a
= (a
+ CACHELINE_SIZE
- 1) & ~(CACHELINE_SIZE
- 1);
1571 address
= (void *) a
;
1575 *NonAlignedAddress
= address
;
1583 //address = AllocVecDMA(size + boundary, MEMF_PUBLIC | MEMF_CLEAR);
1585 address
= AllocVec(size
+ CACHELINE_SIZE
- 1, MEMF_PUBLIC
& ~MEMF_CLEAR
);
1587 FreeMem(address
, size
+ CACHELINE_SIZE
- 1);
1588 address
= AllocAbs(size
, (void*) ((ULONG
) (address
+ CACHELINE_SIZE
- 1) & ~(CACHELINE_SIZE
-1) ) );
1591 address
= AllocVecDMA(size
, MEMF_PUBLIC
| MEMF_CLEAR
);
1592 *NonAlignedAddress
= address
;
1594 memset(address
, 0, size
);
1599 address
= AllocVec(size
+ boundary
, MEMF_PUBLIC
| MEMF_CLEAR
);
1601 if (address
!= NULL
)
1603 a
= (unsigned long) address
;
1604 a
= (a
+ boundary
- 1) & ~(boundary
- 1);
1605 address
= (void *) a
;
1608 if (NonAlignedAddress
)
1610 *NonAlignedAddress
= address
;
1619 void pci_free_consistent(void* addr
)
1629 static ULONG
ResetHandler(struct ExceptionContext
*ctx
, struct ExecBase
*pExecBase
, struct CardData
*card
)
1631 struct PCIDevice
*dev
= card
->pci_dev
;
1633 ClearMask8(card
, card
->mtbase
, MT_DMA_CONTROL
, MT_PDMA0_START
| MT_PDMA4_START
| MT_RDMA0_MASK
| MT_RDMA1_MASK
);
1634 WriteMask8(card
, card
->mtbase
, MT_INTR_MASK
, MT_DMA_FIFO_MASK
| MT_PDMA0_MASK
| MT_RDMA0_MASK
| MT_RDMA1_MASK
);
1639 void AddResetHandler(struct CardData
*card
)
1641 static struct Interrupt interrupt
;
1643 interrupt
.is_Code
= (void (*)())ResetHandler
;
1644 interrupt
.is_Data
= (APTR
) card
;
1645 interrupt
.is_Node
.ln_Pri
= 0;
1646 interrupt
.is_Node
.ln_Type
= NT_EXTINTERRUPT
;
1647 interrupt
.is_Node
.ln_Name
= "reset handler";
1649 IExec
->AddResetCallback( &interrupt
);
1656 if ((INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_EPROM
) == 0)
1658 DEBUGPRINTF("No EEPROM found!\n");
1662 DEBUGPRINTF("EEPROM found!\n");
1666 /*OUTBYTE(card->iobase + CCS_I2C_DATA, 0x11);
1667 OUTBYTE(card->iobase + CCS_I2C_ADDR, 0);
1669 while (INBYTE(card->iobase + CCS_I2C_STATUS) & CCS_I2C_BUSY)
1672 OUTBYTE(card->iobase + CCS_I2C_DEV_ADDRESS, 0xA0);
1675 for (i
= 0; i
< 6; i
++)
1677 OUTBYTE(card
->iobase
+ CCS_I2C_ADDR
, i
);
1679 while (INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_BUSY
)
1683 OUTBYTE(card
->iobase
+ CCS_I2C_DEV_ADDRESS
, 0xA0);
1685 while (INBYTE(card
->iobase
+ CCS_I2C_STATUS
) & CCS_I2C_BUSY
)
1690 DEBUGPRINTF("%d = %x\n",i
, INBYTE(card
->iobase
+ CCS_I2C_DATA
));