/*
 * Copyright 2010 Trident Microsystems (Far East) Ltd. All rights reserved.
 * All prior copyright rights in this work and the accompanying software
 * products transferred to Trident Microsystems (Far East) Ltd. by written
 * agreement.
 */
/*****************************************************************************/
/* Copyright (c) 2010 NXP B.V.  All rights are reserved.                     */
/*                                                                           */
/* Redistribution and use in source and binary forms, with or without        */
/* modification, are permitted provided that the following conditions        */
/* are met:                                                                  */
/*                                                                           */
/* Redistributions of source code must retain the above copyright            */
/* notice, this list of conditions and the following disclaimer.             */
/*                                                                           */
/* 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.      */
/*                                                                           */
/* Neither the name of NXP 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 THE COPYRIGHT      */
/* OWNER OR 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.                                                                   */
/*                                                                           */
/*****************************************************************************/
/*
    @file   tmdlAudioIO_Alsa.h

@b  Component:  tmdlAudioIO, phStbAlsa

*//*

Rev Date        Author          Comments
--------------------------------------------------------------------------------
  1 20090611    hnguyen         First implementation
--------------------------------------------------------------------------------
*/

#ifndef TMDLAUDIOIO_ALSA_H
#define TMDLAUDIOIO_ALSA_H

/*******************
* INCLUDE FILES    *
********************/
#include <tmNxTypes.h>
//#include <phStbDbg.h>
#include <linux/interrupt.h>
#include <linux/delay.h>

//hnx:testing begin
#ifndef ALSA_DIRECTIO
#define ALSA_DIRECTIO
#endif

//#undef ALSA_DIRECTIO //QMxxx
//hnx:testing end

#ifdef __cplusplus
extern "C"
{
#endif

/**************************************************************************
* EXPORTED MACROS                          PH_STBTEMPLATE_<_WORD>+        *
***************************************************************************/
#define MIN_ALSA_DIRECTIO_VOLUME    0
#define MAX_ALSA_DIRECTIO_VOLUME    100
#define MIN_ALSA_DIRECTIO_MIX       0
#define MAX_ALSA_DIRECTIO_MIX       100

#define ALSA_DIRECTIO_MIXLR     0x00000001
#define ALSA_DIRECTIO_MIXI2S    0x00000002
#define ALSA_DIRECTIO_MIXVOLUME 0x00000004
#define ALSA_DIRECTIO_MIXALL    (ALSA_DIRECTIO_MIXLR | ALSA_DIRECTIO_MIXI2S | ALSA_DIRECTIO_MIXVOLUME)

/*********************************************************************
* EXPORTED TYPEDEFS                      [p]phStbTemplate_<Word>+_t  *
**********************************************************************/
#define ALSA_PCM_BUF_SIZE   65536
typedef struct tmdlAudioIO_Alsa
{
    uint32_t    sampleRate;
    uint32_t    bitsPerSample;
    uint32_t    numChannels;
    uint32_t    volume;     //0..100
    uint32_t    mixLR;      //0..100 (50 is even on both left/right)
    uint32_t    mixI2S;     //0..100 (50 is even mix with I2S0/I2S1)
    bool        runAlsa;
    atomic_t    size;       //Current pcm size to be process, in bytes
    atomic_t    first;      //Current postion wait to be process, in bytes
    int8_t      data[ALSA_PCM_BUF_SIZE];//Buffer to hold pcm data
}tmdlAudioIO_Alsa_t;

/**************************************************************************
* EXPORTED DATA                     g[k|p|kp|pk|kpk]phStbTemplate_<Word>+ *
***************************************************************************/
extern tmdlAudioIO_Alsa_t  gAlsaObject;


/****************************************************************************
* EXPORTED FUNCTION PROTOTYPES                    phStbTemplate[_<Word>+]   *
*****************************************************************************/
extern tmErrorCode_t tmdlAudioIO_AlsaSetPCMFormat(uint32_t sampleRate,
                                                  uint32_t bitsPerSample,
                                                  uint32_t numChannels);

extern tmErrorCode_t tmdlAudioIO_AlsaMix(uint32_t flag,
                                         uint32_t volume,
                                         uint32_t mixLR,
                                         uint32_t mixI2S);

extern void tmdlAudioIO_AlsaInit();

extern tmErrorCode_t tmdlAudioIO_AlsaCopyPCMData(void __user *src, uint32_t size);

extern tmErrorCode_t tmdlAudioIO_AlsaProcessData(int32_t samples, int32_t *pMixAudio);

extern tmErrorCode_t tmdlAudioIO_AlsaRun(bool runAlsa);


extern int GetReadPointer (tmdlAudioIO_Output_t output);

extern bool SetStopAddr( tmdlAudioIO_Output_t output, uint32_t stopAddr );

#ifdef __cplusplus
}
#endif

#endif /* TMDLAUDIOIO_ALSA_H      Do not add any thing below this line */

