/*****************************************************************************
 Copyright (c) 2004, Intel Corporation 

 All rights reserved.

 Redistribution and use in source and binary forms, with or without 
 modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, 
 this list of conditions and the following disclaimer.

 2. Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation 
 and/or other materials provided with the distribution.

 3. Neither the name of Intel Corporation nor the names of its contributors 
 may be used to endorse or promote products derived from this software 
 without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

****************************************************************************/

#ifndef AFEDSP_INT_H
#define AFEDSP_INT_H

#include "hamcore.h"
#include "uart.h"
#include "rts.h"
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/proc_fs.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/tty.h>
#include <linux/serial.h>
#include <linux/serialP.h>
#include <linux/interrupt.h>
#include <asm/system.h>
#include <asm/irq.h>
#include <linux/poll.h>

typedef struct {
    unsigned int *bdbar;	
    dma_addr_t	 bdbar_addr;	
    dma_addr_t   physbuf;
    int dma_size;
} dmachnl_t;    

#define bool unsigned int
#define DRIVER_NAME 	"537"

typedef struct // Regular circular byte buffer
{
   /* This field must be first because scheduler will
   handle pointer to buf as pointer to int to check status */
   unsigned int  count;
   unsigned int  size;
   unsigned int  tail;
   unsigned int  head;
   char *buf;           // cuffer that will reside in kernel memory
   char WRAP_FLAG;
} CIRC_BUF;

typedef struct sysaudio_desc {
    unsigned long           SoundProfile;
    bool                    bIsAudio;

    unsigned long           dwSysAudioOpenRefCount;
    unsigned long           dwSysAudioPinCount;

    bool                    bIsRenderProceed;
    bool					bRenderVolumeExist;
    unsigned long           dwSysAudioRenderPinId;

    char                    RenderCurDataBuf[2048];
    char					*RenderCurDataBuf1;
    char					*RenderCurDataBuf2;

    unsigned long           RenderNumChannels;
    unsigned long           RenderBitsPerSample;
    unsigned long           RenderSamplesPerSec;
    unsigned long           RenderSamplesBlockSize;             /* the sample block size for NUM_AUDIO_BATCH PCM Buffers given
                                                                        the sample rate & bits per sample. the sample block size
                                                                        is returned in terms of bytes. */

    bool                    bIsCaptureProceed;
    bool                    bCaptureVolumeExist;
    unsigned long           dwSysAudioCapturePinId;

    char                    CaptureCurDataBuf[2048];
    char                    *CaptureCurDataBuf1;
    char                    *CaptureCurDataBuf2;

    unsigned long           CaptureNumChannels;
    unsigned long           CaptureBitsPerSample;
    unsigned long           CaptureSamplesPerSec;
    unsigned long           CaptureSamplesBlockSize;            /* the sample block size for NUM_AUDIO_BATCH PCM Buffers given
                                                                    the sample rate & bits per sample. the sample block size
                                                                    is returned in terms of bytes. */
    bool                    CaptureSoftControl;		
    unsigned long           RenderVolumeNodeId;
    char                    RenderVolumeLevel;
    unsigned long           CaptureVolumeNodeId;
    char                    CaptureVolumeLevel;
    volatile char           *SoundBuffer;
    volatile char           *SoundBuffer2;
    unsigned long           wakeUpSound;
} sysaudio_t;

typedef struct afe_device {
    struct pci_dev  *pcidev;
    void            *modem;
    void            *afeInternal;
    unsigned int    iobase;
    unsigned int    membase;
    sysaudio_t	    SysAudio;
    unsigned int    RdtscRes;
    int             afe_type;
} afe_device_t;

#pragma pack(1)
typedef struct {
    unsigned short sRate;
    unsigned short sVol;
    unsigned short sBufLen;
    char 	   sBuf[1];
} smpl_t, *smpl_p;
#pragma pack()

asmlinkage extern void circular_buffer_put(CIRC_BUF *write_buffer, void *tmpbuf, int count);
extern volatile afe_device_t *devAfe;
extern int sound_enabled;
asmlinkage extern void SoundTask(void *SysAudio);
extern void *pDspResources;
asmlinkage extern void ModemTask (void *unused);
asmlinkage extern void DspTask (void *unused);
asmlinkage extern int afe_init(unsigned int* cfg);
asmlinkage extern int afe_close(void);

extern dmachnl_t *michnl;
extern dmachnl_t *mochnl;
extern CIRC_BUF *write_buffer;

int create_afeproc(void);
void remove_afeproc(void);

#define save_cr0_and_clts(x) __asm__ __volatile__ ("movl %%cr0,%0; clts" :"=r" (x))
#define restore_cr0(x)       __asm__ __volatile__ ("movl %0,%%cr0": :"r" (x));
#define save_fpenv(x)        __asm__ __volatile__ ("fnsave %0" : "=m" (x))
#define restore_fpenv(x)     __asm__ __volatile__ ("frstor %0" : "=m" (x));

#endif

