/*
 * 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   ak470x.h
    @brief  Linux implementation of the AK470X (AV Scart switch) driver.

    @b  Module:  AK470X (AV Scart switch) driver.

*//*

Rev Date        Author      Comments
--------------------------------------------------------------------------------
  1 2006XXXX    neill       Import from STB810
  2 20070430    burningh    Remove u8 typedef, in DFB header now.
  3 20071002    neill       Remove YPrPb mode (Always enabled!)
  4 20080206    batelaan    Update file copyright/license text
  5 20090120    batelaan    Update file copyright/license text
  6 20090325    burningh    Correct initial volume setting (from Hugh Fox)
--------------------------------------------------------------------------------
    For consistency and standardisation retain the Section Separators.
*/
#ifndef __AK470X_H__
#define __AK470X_H__

#include <linux/ioctl.h>
#include <linux/types.h>

#if defined(__cplusplus)
extern "C" {
#endif

//  ****************************************************************************
//  *                                                                          *
//  *                       A V    S W I T C H     S E C T I O N               *
//  *                                                                          *
//  ****************************************************************************
typedef enum {
        TV_OUTPUT       =   0
    ,   VCR_OUTPUT      =   1
    ,   NUM_OUTPUTS     =   2
}   output_enum;

typedef enum {
        SRC_PRIMARY
    ,   SRC_SECONDARY
    ,   SRC_VCRIN
    ,   SRC_TVIN
    ,   SRC_MUTE
}   src_enum;

typedef enum {
        MODE_RGB
    ,   MODE_YC
    ,   MODE_CVBS
}   mode_enum;

typedef enum {
        BLANK_SLOW_OFF
    ,   BLANK_SLOW_16_9
    ,   BLANK_SLOW_4_3
    ,   BLANK_SLOW_FOLLOW
    ,   BLANK_SLOW_MONITOR
}   blanking_enum;

typedef struct {
        src_enum      src_select    ;
        mode_enum     display_mode  ;
        blanking_enum slow_blanking ;
}   av_output_attr;

typedef struct {
        int loopthrough             ;
        av_output_attr attribute[NUM_OUTPUTS] ;
}   av_switch_data;

//  ****************************************************************************
//  *                                                                          *
//  *                           A U D I O     S E C T I O N                    *
//  *                                                                          *
//  ****************************************************************************
//  ----------------------- AK470X Audio Channel Number (0 offset)  ------------
typedef enum    AK470X_AUDIO_CHANNEL_NUMBER         {
        AK470X_AUDIO_CHANNEL_NUMBER_MIN = 0
    ,   AK470X_AUDIO_CHANNEL_NUMBER_0   = 0
    ,   AK470X_AUDIO_CHANNEL_NUMBER_MAX = 0
    ,   AK470X_AUDIO_CHANNEL_COUNT = AK470X_AUDIO_CHANNEL_NUMBER_MAX-AK470X_AUDIO_CHANNEL_NUMBER_MIN+1
}   AK470X_AUDIO_CHANNEL_NUMBER_t;


//  ----------------------- AK470X Audio External Volume Range      ------------
typedef enum    AK470X_AUDIO_EXTERNAL_VOLUME_RANGE      {
        AK470X_AUDIO_EXTERNAL_VOLUME_MIN = 0
    ,   AK470X_AUDIO_EXTERNAL_VOLUME_MAX = 100
    ,   AK470X_AUDIO_EXTERNAL_VOLUME_MID = 84
}   AK470X_AUDIO_EXTERNAL_VOLUME_RANGE_t;


//  ----------------------- AK470X Audio Internal Gain Range -------------------
typedef enum    AK470X_AUDIO_INTERNAL_GAIN_RANGE {
        AK470X_AUDIO_INTERNAL_GAIN_MIN = 0
    ,   AK470X_AUDIO_INTERNAL_GAIN_MAX = 34
}   AK470X_AUDIO_INTERNAL_GAIN_RANGE_t;


//  ----------------------- AK470X attenuation & volume boundaries      --------
typedef enum    AK470X_AUDIO_VOLUME_BOUNDARY                {
        AK470X_gain_min = AK470X_AUDIO_INTERNAL_GAIN_MIN
    ,   AK470X_gain_max = AK470X_AUDIO_INTERNAL_GAIN_MAX
    ,   AK470X_gain_mag = AK470X_AUDIO_INTERNAL_GAIN_MAX   - AK470X_AUDIO_INTERNAL_GAIN_MIN
    ,   AK470X_vol_min  = AK470X_AUDIO_EXTERNAL_VOLUME_MIN
    ,   AK470X_vol_max  = AK470X_AUDIO_EXTERNAL_VOLUME_MAX
    ,   AK470X_vol_mag  = AK470X_AUDIO_EXTERNAL_VOLUME_MAX - AK470X_AUDIO_EXTERNAL_VOLUME_MIN
}   AK470X_AUDIO_VOLUME_BOUNDARY_t;


//  ----------------------- AK470X Audio Internal Types --------------------
typedef u8  AK470X_AUDIO_MASTER_VOLUME_t;

//  ****************************************************************************
//  *                                                                          *
//  *                           M O D U L E    S E C T I O N                   *
//  *                                                                          *
//  ****************************************************************************
//  ----------------------- MODULE Definition   --------------------------------
#define AK470X_MODULE_DESCRIPTION   "AK470X (AV Scart switch) driver"

//------------------------------------------------------------------------------
//                              I O C T L ' s  data structures
//------------------------------------------------------------------------------

//  ----------------------- MODULE IOCTL Control Structure  (Switch Mode)   ----
typedef  av_switch_data     AK470X_SWITCH_IOCTL_MODE_t;


//  ----------------------- MODULE IOCTL Control Structure  (Audio Mode)    ----
typedef struct  AK470X_AUDIO_IOCTL_MODE                 {
        AK470X_AUDIO_CHANNEL_NUMBER_t       audio_channel;
}   AK470X_AUDIO_IOCTL_MODE_t;


//  ----------------------- MODULE IOCTL Control Structure  (Audio Volume)  ----
typedef struct  AK470X_AUDIO_IOCTL_VOLUME               {
        AK470X_AUDIO_MASTER_VOLUME_t        master_left;
        AK470X_AUDIO_MASTER_VOLUME_t        master_right;
        AK470X_AUDIO_CHANNEL_NUMBER_t       audio_channel;
        int									external_left;
        int									external_right;
}   AK470X_AUDIO_IOCTL_VOLUME_t;

//------------------------------------------------------------------------------
//                              I O C T L ' s  definition
//------------------------------------------------------------------------------
//  ----------------------- MODULE IOCTLs base  --------------------------------
#define AK470X_IOCTL_GENERIC (0xBE)
#define AK470X_IOCTL_BASE    (0x00)

//  ----------------------- MODULE Switch IOCTL's   ----------------------------
#define AK470X_IOCTL_SWITCH             (AK470X_IOCTL_BASE + 0x00)
#define AK470X_IOCTL_SWITCH_MODE_SET    _IOW(AK470X_IOCTL_GENERIC, AK470X_IOCTL_SWITCH + 0, AK470X_SWITCH_IOCTL_MODE_t*)
#define AK470X_IOCTL_SWITCH_MODE_GET    _IOR(AK470X_IOCTL_GENERIC, AK470X_IOCTL_SWITCH + 1, AK470X_SWITCH_IOCTL_MODE_t*)

//  ----------------------- ... for backward compatibility with Rev<003 --------
#define AV_SWITCH_BASE (0)
#define AV_SWITCH_SET_MODE _IOW(0xBE, AV_SWITCH_BASE+0, av_switch_data*)

//  ----------------------- MODULE Audio IOCTL's    ----------------------------
#define AK470X_IOCTL_AUDIO              (AK470X_IOCTL_BASE + 0x10)
#define AK470X_IOCTL_AUDIO_MODE_SET     _IOW(AK470X_IOCTL_GENERIC, AK470X_IOCTL_AUDIO + 0, AK470X_AUDIO_IOCTL_MODE_t*)
#define AK470X_IOCTL_AUDIO_VOLUME_GET   _IOR(AK470X_IOCTL_GENERIC, AK470X_IOCTL_AUDIO + 1, AK470X_AUDIO_IOCTL_VOLUME_t*)
#define AK470X_IOCTL_AUDIO_VOLUME_SET   _IOW(AK470X_IOCTL_GENERIC, AK470X_IOCTL_AUDIO + 2, AK470X_AUDIO_IOCTL_VOLUME_t*)

//  ****************************************************************************
//  *                                                                          *
//  *                       P U B L I C    O B J E C T S                       *
//  *                                                                          *
//  ****************************************************************************
//  ----------------------- AK470X IOCTL wrapper  (Commands)    ----------------
extern int ak470x_exec                 (unsigned int cmd, void *p_object);
extern int ak470x_std_volume_get       (int channel, int *p_left, int *p_right);
extern int ak470x_std_volume_set       (int channel, int left, int right);
extern int ak470x_std_volume_range_get (int channel, int *p_min, int *p_max);
extern int ak470x_switch_get (av_switch_data* pInfo);
extern int ak470x_switch_set (const av_switch_data* pInfo);
extern int ak470x_switch_installed (void);

#if defined(__cplusplus)
}
#endif
#endif /* __AK470X_H__ */

