AppleTexas2Audio.h [plain text]
#ifndef _APPLETEXAS2AUDIO_H
#define _APPLETEXAS2AUDIO_H
#include <IOKit/i2c/PPCI2CInterface.h>
#include "AppleDallasDriver.h"
#include "AppleOnboardAudio.h"
#include "Texas2_hw.h"
class IOInterruptEventSource;
class IORegistryEntry;
struct awacs_regmap_t;
struct IODBDMAChannelRegisters;
struct IODBDMADescriptor;
#if 0
#define kInsertionDelayNanos 4000000000ULL
#else
#define kInsertionDelayNanos 1000000000ULL
#endif
#define kNotifyTimerDelay 60000 // in milliseconds = 60 seconds
#define kUserLoginDelay 20000
#define kSpeakerConnectError "SpeakerConnectError"
enum {
kMaximumVolume = 141,
kMinimumVolume = 0,
kInitialVolume = 101
};
typedef Boolean GpioActiveState;
typedef UInt8* GpioPtr;
enum {
kInternalSpeakerActive = 1,
kHeadphonesActive = 2,
kExternalSpeakersActive = 4
};
typedef enum TicksPerFrame {
k64TicksPerFrame = 64, k32TicksPerFrame = 32 } TicksPerFrame;
typedef enum ClockSource {
kClock49MHz = 49152000, kClock45MHz = 45158400, kClock18MHz = 18432000 } ClockSource;
typedef enum SoundFormat {
kSndIOFormatI2SSony,
kSndIOFormatI2S64x,
kSndIOFormatI2S32x,
kSndIOFormatUnknown
} SoundFormat;
class AppleTexas2Audio : public AppleOnboardAudio
{
OSDeclareDefaultStructors(AppleTexas2Audio);
friend class AudioHardwareOutput;
friend class AudioHardwareInput;
friend class AudioHardwareMux;
protected:
SInt32 minVolume;
SInt32 maxVolume;
Boolean gVolMuteActive;
Boolean mCanPollStatus;
IOInterruptEventSource *headphoneIntEventSource;
IOInterruptEventSource *lineOutIntEventSource; IOInterruptEventSource *dallasIntEventSource;
Boolean hasVideo; Boolean hasSerial; Boolean headphonesActive;
Boolean lineOutActive;
Boolean headphonesConnected;
Boolean lineOutConnected; Boolean dallasSpeakersConnected;
DRCInfo drc; UInt32 layoutID; UInt32 speakerID; GpioPtr hwResetGpio;
GpioPtr hdpnMuteGpio;
GpioPtr ampMuteGpio;
GpioPtr lineInExtIntGpio; GpioPtr lineOutExtIntGpio; GpioPtr lineOutMuteGpio; GpioPtr masterMuteGpio; GpioPtr headphoneExtIntGpio;
GpioPtr dallasExtIntGpio;
GpioActiveState hwResetActiveState; GpioActiveState hdpnActiveState; GpioActiveState ampActiveState; GpioActiveState headphoneInsertedActiveState;
GpioActiveState dallasInsertedActiveState;
GpioActiveState lineInExtIntActiveState; GpioActiveState lineOutExtIntActiveState; GpioActiveState lineOutMuteActiveState; GpioActiveState masterMuteActiveState; UInt32 detectCollection; UInt8 DEQAddress; Texas2_ShadowReg shadowTexas2Regs; Boolean semaphores;
UInt32 deviceID;
double biquadGroupInfo[kNumberOfBiquadCoefficients];
IOService * ourProvider;
IODeviceMemory * hdpnMuteRegMem; IODeviceMemory * ampMuteRegMem; IODeviceMemory * hwResetRegMem; IODeviceMemory * headphoneExtIntGpioMem; IODeviceMemory * dallasExtIntGpioMem; IODeviceMemory * lineInExtIntGpioMem; IODeviceMemory * lineOutExtIntGpioMem; IODeviceMemory * lineOutMuteGpioMem; IODeviceMemory * masterMuteGpioMem; UInt32 i2sSerialFormat;
IOService * headphoneIntProvider;
IOService * lineOutIntProvider; IOService * dallasIntProvider;
const OSSymbol * gAppleAudioVideoJackStateKey;
const OSSymbol * gAppleAudioSerialJackStateKey;
AppleDallasDriver * dallasDriver;
IONotifier * dallasDriverNotifier;
IOTimerEventSource * dallasHandlerTimer;
IOTimerEventSource * notifierHandlerTimer;
Boolean doneWaiting;
UInt64 savedNanos;
Boolean speakerConnectFailed;
UInt32 activeOutput; Boolean useMasterVolumeControl;
UInt32 lastLeftVol;
UInt32 lastRightVol;
Boolean dallasSpeakersProbed; Boolean hasANDedReset;
Boolean gModemSoundActive;
Boolean dontReleaseHPMute;
ClockSource clockSource;
UInt32 mclkDivisor;
UInt32 sclkDivisor;
SoundFormat serialFormat;
virtual void sndHWInitialize(IOService *provider) ;
virtual void sndHWPostDMAEngineInit (IOService *provider);
virtual UInt32 sndHWGetInSenseBits(void) ;
virtual UInt32 sndHWGetRegister(UInt32 regNum) ;
virtual IOReturn sndHWSetRegister(UInt32 regNum, UInt32 value) ;
virtual UInt32 sndHWGetActiveOutputExclusive(void);
virtual IOReturn sndHWSetActiveOutputExclusive(UInt32 outputPort );
virtual UInt32 sndHWGetActiveInputExclusive(void);
virtual IOReturn sndHWSetActiveInputExclusive(UInt32 input );
virtual bool sndHWGetSystemMute(void);
virtual IOReturn sndHWSetSystemMute(bool mutestate);
virtual bool sndHWSetSystemVolume(UInt32 leftVolume, UInt32 rightVolume);
virtual IOReturn sndHWSetSystemVolume(UInt32 value);
virtual IOReturn sndHWSetPlayThrough(bool playthroughstate);
virtual IOReturn sndHWSetSystemInputGain(UInt32 leftGain, UInt32 rightGain) ;
virtual UInt32 sndHWGetType( void );
virtual UInt32 sndHWGetManufacturer( void );
virtual void setDeviceDetectionActive (void);
virtual void setDeviceDetectionInActive (void);
public:
virtual bool init(OSDictionary *properties);
virtual void free();
virtual IOService* probe(IOService *provider, SInt32*);
virtual bool initHardware(IOService *provider);
virtual IOReturn sndHWSetPowerState(IOAudioDevicePowerState theState);
virtual UInt32 sndHWGetConnectedDevices(void);
virtual UInt32 sndHWGetProgOutput();
virtual IOReturn sndHWSetProgOutput(UInt32 outputBits);
private:
virtual void checkStatus(bool force);
static void timerCallback(OSObject *target, IOAudioDevice *device);
Boolean IsHeadphoneConnected (void);
Boolean IsLineOutConnected (void);
Boolean IsSpeakerConnected (void);
UInt32 ParseDetectCollection ( void );
public:
void RealLineOutInterruptHandler (IOInterruptEventSource *source, int count); void RealHeadphoneInterruptHandler (IOInterruptEventSource *source, int count);
void RealDallasInterruptHandler (IOInterruptEventSource *source, int count);
virtual IOReturn performDeviceWake ();
virtual IOReturn performDeviceSleep ();
protected:
IOReturn AdjustControls (void);
IOReturn SetVolumeCoefficients (UInt32 left, UInt32 right);
IOReturn SetAmplifierMuteState (UInt32 ampID, Boolean muteState);
IOReturn SelectHeadphoneAmplifier( void );
IOReturn SelectLineOutAmplifier( void );
IOReturn SelectMasterMuteAmplifier( void );
IOReturn SelectSpeakerAmplifier( void );
IOReturn SetMixerState ( UInt32 mixerState ); IOReturn InitEQSerialMode (UInt32 mode, Boolean restoreOnNormal);
Boolean GpioRead (UInt8* gpioAddress);
UInt8 GpioGetDDR (UInt8* gpioAddress);
IOReturn AppleTexas2Audio::GetShadowRegisterInfo( UInt8 regAddr, UInt8 ** shadowPtr, UInt8* registerSize );
IOReturn Texas2_Initialize ();
Boolean IsCodecRESET( Boolean logMessage );
void Texas2_Reset ( void );
void Texas2_Reset_ASSERT ( void );
void Texas2_Reset_NEGATE ( void );
IOReturn Texas2_ReadRegister (UInt8 regAddr, UInt8* registerData);
IOReturn Texas2_WriteRegister (UInt8 regAddr, UInt8* registerData, UInt8 mode);
void GpioWrite (UInt8* gpioAddress, UInt8 data);
void SetBiquadInfoToUnityAllPass (void);
void SetUnityGainAllPass (void);
void ExcludeHPMuteRelease (UInt32 layout);
IOReturn SndHWSetDRC( DRCInfoPtr theDRCSettings );
static IOReturn DeviceInterruptServiceAction (OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
void DeviceInterruptService (void);
IOReturn GetCustomEQCoefficients (UInt32 layoutID, UInt32 deviceID, UInt32 speakerID, EQPrefsElementPtr *filterSettings);
UInt32 GetDeviceMatch (void);
IOReturn SndHWSetOutputBiquad( UInt32 streamID, UInt32 biquadRefNum, FourDotTwenty *biquadCoefficients );
IOReturn SndHWSetOutputBiquadGroup( UInt32 biquadFilterCount, FourDotTwenty *biquadCoefficients );
IOReturn SetOutputBiquadCoefficients (UInt32 streamID, UInt32 biquadRefNum, UInt8 *biquadCoefficients);
void SelectOutputAndLoadEQ ( void );
IOReturn SetActiveOutput (UInt32 output, Boolean touchBiquad);
IOReturn SetAnalogPowerDownMode( UInt8 mode );
IOReturn ToggleAnalogPowerDownWake( void );
IORegistryEntry * FindEntryByProperty (const IORegistryEntry * start, const char * key, const char * value);
IORegistryEntry * FindEntryByNameAndProperty (const IORegistryEntry * start, const char * name, const char * key, UInt32 value);
UInt32 GetDeviceID (void);
Boolean HasANDedReset (void);
Boolean HasInput (void);
static bool interruptFilter (OSObject *, IOFilterInterruptEventSource *);
static void dallasInterruptHandler (OSObject *owner, IOInterruptEventSource *source, int count);
static bool DallasDriverPublished (AppleTexas2Audio * appleTexas2Audio, void * refCon, IOService * newService);
static void DallasInterruptHandlerTimer (OSObject *owner, IOTimerEventSource *sender);
static void DisplaySpeakersNotFullyConnected (OSObject *owner, IOTimerEventSource *sender);
static void headphoneInterruptHandler(OSObject *owner, IOInterruptEventSource *source, int count);
static void lineOutInterruptHandler(OSObject *owner, IOInterruptEventSource *source, int count);
void SetOutputSelectorCurrentSelection (void);
PPCI2CInterface *interface;
UInt32 getI2CPort ();
bool openI2C ();
void closeI2C ();
bool findAndAttachI2C (IOService *provider);
bool detachFromI2C (IOService* );
void *soundConfigSpace; void *ioBaseAddress; void *ioClockBaseAddress;
UInt8 i2SInterfaceNumber;
void KLSetRegister(void *klRegister, UInt32 value);
UInt32 KLGetRegister(void *klRegister);
bool clockRun(bool start);
inline UInt32 ReadWordLittleEndian(void *address, UInt32 offset);
inline void WriteWordLittleEndian(void *address, UInt32 offset, UInt32 value);
inline void I2SSetSerialFormatReg(UInt32 value);
inline UInt32 I2SGetSerialFormatReg(void);
inline void I2SSetDataWordSizeReg(UInt32 value);
inline UInt32 I2SGetDataWordSizeReg(void);
inline void Fcr1SetReg(UInt32 value);
inline UInt32 Fcr1GetReg(void);
inline void Fcr3SetReg(UInt32 value);
inline UInt32 Fcr3GetReg(void);
inline UInt32 I2SGetIntCtlReg();
bool setSampleParameters(UInt32 sampleRate, UInt32 mclkToFsRatio);
void setSerialFormatRegister(ClockSource clockSource, UInt32 mclkDivisor, UInt32 sclkDivisor, SoundFormat serialFormat);
bool setHWSampleRate(UInt rate);
UInt32 frameRate(UInt32 index);
protected:
UInt32 mActiveOutput; UInt32 mActiveInput; UInt32 gInputNoneAlias;
UInt8 * getGPIOAddress (UInt32 gpioSelector);
void GpioWriteByte( UInt8* gpioAddress, UInt8 data );
UInt8 GpioReadByte( UInt8* gpioAddress );
virtual UInt8 readGPIO (UInt32 selector);
virtual void writeGPIO (UInt32 selector, UInt8 data);
virtual Boolean getGPIOActiveState (UInt32 gpioSelector);
};
#endif