📄 hwctxt.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name: HWCTXT.CPP
Abstract: Platform dependent code for the mixing audio driver.
Notes: The following file contains all the hardware specific code
for the mixing audio driver. This code's primary responsibilities
are:
* Initialize audio hardware (including codec chip)
* Schedule DMA operations (move data from/to buffers)
* Handle audio interrupts
All other tasks (mixing, volume control, etc.) are handled by the "upper"
layers of this driver.
****** IMPORTANT ******
For the SC2443 CPU, DMA channel 2 can be used for both input and output. In this,
configuration, however, only one type operation (input or output) can execute. In
order to implement simultaneous playback and recording, two things must be done:
1) Input DMA should be moved to DMA Channel 1; Output DMA still uses DMA Channel 2.
2) Step #3 in InterruptThread() needs to be implemented so that the DMA interrupt
source (input DMA or output DMA?) can be determined. The interrupt source needs
to be determined so that the appropriate buffers can be copied (Steps #4,#5...etc.).
Lastly, the m_OutputDMAStatus and m_InputDMAStatus variables shouldn't need to be modified.
The logic surrounding these drivers is simply used to determine which buffer (A or B) needs
processing.
-*/
#include "wavemain.h"
#include <s3c2443.h>
#include <bsp.h> // Kingfish2
#include "ac97.h" // Kingfish2
#include "s3c2443_dmatransfer.h"
#include "hwctxt.h"
#include "DMA.h"
#include <ceddk.h>
#include <S3C2443REF_GPIO.h>
#define AC97_RECORD_MICIN 0
#define DMA_FLAG 1 // Kingfish2 1:DMA, 0:Polling
#define WAIT_DMA_END 0
#define DMA_CH_MIC 2
#define DMA_CH_OUT 1
//#define AC97_READY_CHECK_METHOD 0 // Kingfish2
#define AC97_READY_CHECK_METHOD 0 // 2443
#define AC97_DEBUG 0
#define AC97_DEBUG1 0
#define AC97_DEBUG2 0
#define AC97_DEBUG3 0
#define AC97MSG(b) RETAILMSG(AC97_DEBUG,b)
#define DELAY_COUNT 0x100000
//-------------------------------- Global Variables --------------------------------------
volatile S3C2443_IOPORT_REG *v_pIOPregs = NULL; // GPIO registers (needed to enable AC97)
volatile S3C2443_AC97_REG *v_pAC97regs = NULL; // AC97 control registers
volatile S3C2443_DMA_REG *v_pDMAregs = NULL; // DMA registers (needed for I/O on AC97)
volatile S3C2443_CLKPWR_REG *v_pCLKPWRreg = NULL; // Clock power registers (needed to enable AC97)
volatile S3C2443_INTR_REG *s2443INT = NULL;
HardwareContext *g_pHWContext = NULL;
PHYSICAL_ADDRESS g_PhysDMABufferAddr;
unsigned int delay_count;
//----------------------------------------------------------------------------------------
#ifdef DEBUG
#if 0 //JEFF conflict with WaveMain
DBGPARAM dpCurSettings = {
TEXT("WaveDriver"), {
TEXT("Test") // 0 ZONE_TEST
,TEXT("Params") // 1 ZONE_PARAMS
,TEXT("Verbose") // 2 ZONE_VERBOSE
,TEXT("Interrupt") // 3 ZONE_INTERRUPT
,TEXT("WODM") // 4 ZONE_WODM
,TEXT("WIDM") // 5 ZONE_WIDM
,TEXT("PDD") // 6 ZONE_PDD
,TEXT("MDD") // 7 ZONE_MDD
,TEXT("Regs") // 8 ZONE_REGS
,TEXT("Misc") // 9 ZONE_MISC
,TEXT("Init") // 10 ZONE_INIT
,TEXT("IOcontrol") // 11 ZONE_IOCTL
,TEXT("Alloc") // 12 ZONE_ALLOC
,TEXT("Function") // 13 ZONE_FUNCTION
,TEXT("Warning") // 14 ZONE_WARN
,TEXT("Error") // 15 ZONE_ERROR
},
(1 << 15) // Errors
| (1 << 14) // Warnings
};
#endif
#endif
// Kingfish2
volatile static int loop = S3C2443_FCLK/100000;
static void Delay(USHORT count)
{
volatile int i, j=0;
for(;count > 0;count--)
for(i=0;i < loop; i++) { j++; }
}
static void WriteCodecRegister(UCHAR Reg, USHORT Val)
{
v_pAC97regs->AC_CODEC_CMD = (Reg << AC97_CMD_ADDR_SHIFT) | (Val << AC97_CMD_DATA_SHIFT);
Delay(100);
//Sleep(5);
v_pAC97regs->AC_CODEC_CMD |= (AC97_READ_COMMAND); //To receive SLOTREQ bits when VRA is '1'.
}
static USHORT ReadCodecRegister(UCHAR Reg)
{
USHORT retval;
v_pAC97regs->AC_CODEC_CMD = AC97_READ_COMMAND | (Reg << AC97_CMD_ADDR_SHIFT);
Delay(100);
//Sleep(5);
retval = v_pAC97regs->AC_CODEC_STAT & AC97_STAT_DATA_READ_MASK;
return retval;
}
BOOL HardwareContext::CreateHWContext(DWORD Index)
{
if (g_pHWContext)
{
return(TRUE);
}
g_pHWContext = new HardwareContext;
if (!g_pHWContext)
{
return(FALSE);
}
return(g_pHWContext->Init(Index));
}
HardwareContext::HardwareContext()
: m_InputDeviceContext(), m_OutputDeviceContext()
{
InitializeCriticalSection(&m_Lock);
m_Initialized=FALSE;
}
HardwareContext::~HardwareContext()
{
DeleteCriticalSection(&m_Lock);
}
BOOL HardwareContext::Init(DWORD Index)
{
UINT32 Irq;
m_dwInputGain = 0xFFFF;
m_dwOutputGain = 0xFFFF;
m_fInputMute = FALSE;
m_fOutputMute = FALSE;
if (m_Initialized)
{
return(FALSE);
}
// Call the OAL to translate the audio IRQ into a SYSINTR value.
//
Irq = IRQ_DMA1; // audio output DMA interrupt.
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &m_dwSysintrOutput, sizeof(UINT32), NULL))
{
RETAILMSG(TRUE, (TEXT("ERROR: HardwareContext::Init: Failed to obtain sysintr value for output interrupt.\r\n")));
return FALSE;
}
Irq = IRQ_DMA2; // audio input DMA interrupt.
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &m_dwSysintrInput, sizeof(UINT32), NULL))
{
RETAILMSG(TRUE, (TEXT("ERROR: HardwareContext::Init: Failed to obtain sysintr value for input interrupt.\r\n")));
return FALSE;
}
//----- 1. Initialize the state/status variables -----
m_DriverIndex = Index;
m_InPowerHandler = FALSE;
m_InputDMARunning = FALSE;
m_OutputDMARunning = FALSE;
m_InputDMAStatus = DMA_CLEAR;
m_OutputDMAStatus = DMA_CLEAR;
//----- 2. Map the necessary descriptory channel and control registers into the driver's virtual address space -----
if(!MapRegisters())
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVEDEV.DLL:HardwareContext::Init() - Failed to map config registers.\r\n")));
goto Exit;
}
//----- 3. Map the DMA buffers into driver's virtual address space -----
if(!MapDMABuffers())
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVEDEV.DLL:HardwareContext::Init() - Failed to map DMA buffers.\r\n")));
goto Exit;
}
//HP detect EINT8
v_pIOPregs->GPGCON = ( v_pIOPregs->GPGCON & ~(0x3)) | 0x2;
#ifdef EVT1
v_pIOPregs->EXTINT1 = (READEXTINT1(v_pIOPregs->EXTINT1) & ~(0xF<<0)) | (0xF<<0);
#else
v_pIOPregs->EXTINT1 = (v_pIOPregs->EXTINT1 & ~(0xF<<0)) | (0xF<<0);
#endif
RETAILMSG(1,(TEXT("v_pIOPregs->GPGDAT= 0x%x \r\n"),v_pIOPregs->GPGCON));
//----4. Configure the AC97 Controller
// Confiure GPIO for AC97
AC97_Init();
//----- 5. Configure the Codec -----
InitCodec();
//-----65. Initialize the interrupt thread -----
if (!InitInterruptThread())
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVEDEV.DLL:HardwareContext::Init() - Failed to initialize interrupt thread.\r\n")));
goto Exit;
}
m_Initialized=TRUE;
//
// Power Manager expects us to init in D0.
// We are normally in D4 unless we are opened for play.
// Inform the PM.
//
m_Dx = D0;
DevicePowerNotify(_T("WAV1:"),(_CEDEVICE_POWER_STATE)D4, POWER_NAME);
Exit:
return(m_Initialized);
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: MapRegisters()
Description: Maps the config registers
Notes: The GPIO and AC97 controllers both use the GPIO config
registers, so these MUST be initialized FIRST.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::MapRegisters()
{
v_pIOPregs = (volatile S3C2443_IOPORT_REG*)VirtualAlloc(0, sizeof(S3C2443_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!v_pIOPregs)
{
DEBUGMSG(1, (TEXT("IOPreg: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)v_pIOPregs, (PVOID)(S3C2443_BASE_REG_PA_IOPORT >> 8), sizeof(S3C2443_IOPORT_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("IOPreg: VirtualCopy failed!\r\n")));
return(FALSE);
}
v_pDMAregs = (volatile S3C2443_DMA_REG*)VirtualAlloc(0, sizeof(S3C2443_DMA_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!v_pDMAregs)
{
DEBUGMSG(1, (TEXT("DMAreg: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)v_pDMAregs, (PVOID)(S3C2443_BASE_REG_PA_DMA >> 8), sizeof(S3C2443_DMA_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("DMAreg: VirtualCopy failed!\r\n")));
return(FALSE);
}
s2443INT = (volatile S3C2443_INTR_REG*)VirtualAlloc(0, sizeof(S3C2443_INTR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!s2443INT)
{
DEBUGMSG(1, (TEXT("INTreg: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)s2443INT, (PVOID)(S3C2443_BASE_REG_PA_INTR >> 8), sizeof(S3C2443_INTR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("INTreg: VirtualCopy failed!\r\n")));
return(FALSE);
}
v_pCLKPWRreg = (volatile S3C2443_CLKPWR_REG*)VirtualAlloc(0, sizeof(S3C2443_CLKPWR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!v_pCLKPWRreg)
{
DEBUGMSG(1, (TEXT("DMAreg: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)v_pCLKPWRreg, (PVOID)(S3C2443_BASE_REG_PA_CLOCK_POWER >> 8), sizeof(S3C2443_CLKPWR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("DMAreg: VirtualCopy failed!\r\n")));
return(FALSE);
}
v_pAC97regs = (volatile S3C2443_AC97_REG*)VirtualAlloc(0, sizeof(S3C2443_AC97_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!v_pAC97regs)
{
DEBUGMSG(1, (TEXT("AC97reg: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)v_pAC97regs, (PVOID)(S3C2443_BASE_REG_PA_AC97 >> 8), sizeof(S3C2443_AC97_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("AC97reg: VirtualCopy failed!\r\n")));
return(FALSE);
}
PowerUp();
return(TRUE);
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: Deinit()
Description: Deinitializest the hardware: disables DMA channel(s),
clears any pending interrupts, powers down the audio
codec chip, etc.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::Deinit()
{
//----- 1. Disable the input/output channels -----
// AUDIO_IN_DMA_DISABLE();
AUDIO_OUT_DMA_DISABLE();
//----- 2. Disable/clear DMA input/output interrupts -----
AUDIO_IN_CLEAR_INTERRUPTS();
AUDIO_OUT_CLEAR_INTERRUPTS();
//----- 3. Turn the audio hardware off -----
AudioMute(DMA_CH_OUT | DMA_CH_MIC, TRUE);
//----- 4. Unmap the control registers and DMA buffers -----
UnmapRegisters();
UnmapDMABuffers();
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: UnmapRegisters()
Description: Unmaps the config registers used by both the SPI and
AC97 controllers.
Notes: The SPI and AC97 controllers both use the GPIO config
registers, so these MUST be deinitialized LAST.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::UnmapRegisters()
{
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: MapDMABuffers()
Description: Maps the DMA buffers used for audio input/output
on the AC97 bus.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
BOOL HardwareContext::MapDMABuffers()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -