/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights 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 the copyright holder 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
 * HOLDER 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 u_dsm.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *    This header file contains Device Status Manager (DSN) macro, typedef,
 *    and data structure definitions, which are exported to other Middleware
 *    components and applications.
 *         
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_DSM Device Status Manager
 *
 *  @ingroup groupMW
 *  @brief Provides external function for TV Application, Provides function for open device group/device or
 *           set/get information for devices .
 *  
 *
 *  @see groupMW
 *  @{ 
 */
 /*----------------------------------------------------------------------------*/
#ifndef _U_DSM_H_
#define _U_DSM_H_

/*---------------------------------------------------------------------------
                    include files
----------------------------------------------------------------------------*/

#include "u_common.h"
#include "u_device_type.h"
#include "u_handle.h"
#include "u_handle_grp.h"

/*--------------------------------------------------------------------------
 Constants, enumerations, and macros
---------------------------------------------------------------------------*/

/* Return code status from DSM API */
#define   DSMR_ASYNC_NFY              ((INT32)  1)    /**<        */
#define   DSMR_OK                     ((INT32)  0)    /**<        */
#define	  DSMR_FAIL                   ((INT32) -1)    /**<        */
#define   DSMR_OUT_OF_HANDLE          ((INT32) -2)    /**<        */
#define	  DSMR_OUT_OF_MEM             ((INT32) -3)    /**<        */
#define	  DSMR_INV_HANDLE             ((INT32) -4)    /**<        */
#define   DSMR_INV_ARG                ((INT32) -5)    /**<        */
#define	  DSMR_DEV_TYPE_NOT_SUPPORTED ((INT32) -6)    /**<        */
#define	  DSMR_DEV_NOT_FOUND          ((INT32) -7)    /**<        */
#define   DSMR_AEE_OUT_OF_RESOURCES   ((INT32) -8)    /**<        */
#define   DSMR_AEE_NO_RIGHTS          ((INT32) -9)    /**<        */

/*
   Return code from DSM calls to RM API's, these return code are
   also shared with the 1394 get/set APIs.
*/
#define   DSMR_INV_GET_OP            ((INT32) -10)    /**<        */
#define   DSMR_INV_GET_INFO          ((INT32) -11)    /**<        */
#define   DSMR_INV_SET_OP            ((INT32) -12)    /**<        */
#define   DSMR_INV_SET_INFO          ((INT32) -13)    /**<        */
#define   DSMR_NOT_ENOUGH_SPACE	     ((INT32) -14)    /**<        */

/* 
   Return code from DSM get/set APIs to 1394 devices.
*/
#define   DSMR_INV_GET_DATA          ((INT32) -11)    /**<        */
#define   DSMR_INV_SET_DATA          ((INT32) -13)    /**<        */
#define   DSMR_REJECTED              ((INT32) -14)    /**<        */


/* Handle type for the DSM group. */
#define   DSMT_GROUP_T              (HT_GROUP_DSM + ((HANDLE_TYPE_T) 1))    /**<        */

/* Handle type for the DSM device. */
#define   DSMT_DEVICE_T             (HT_GROUP_DSM + ((HANDLE_TYPE_T) 2))    /**<        */

/* Handle type for the DSM component. This handle type is only used internally
   by the DSM to RM interface.
*/
#define   DSMT_DSM_COMP_T           (HT_GROUP_DSM + ((HANDLE_TYPE_T) 3))    /**<        */

/* 
    typedef for DSM device notification condition.
*/
typedef	  UINT32                       DSM_COND_DEV_T;    /**<        */

/* 
    DSM device notification condition. 
*/

#define	DSM_COND_DEV_HANDLE_CLOSED	     ((DSM_COND_DEV_T)(1))    /**<        */

#define	DSM_COND_AVC_DEV		         ((DSM_COND_DEV_T)(128))    /**<        */
#define	DSM_COND_DEV_VIDEO_SIG_STATUS    ((DSM_COND_DEV_T)(DSM_COND_AVC_DEV+1))    /**<        */
#define	DSM_COND_DEV_AUDIO_SIG_STATUS	 ((DSM_COND_DEV_T)(DSM_COND_AVC_DEV+2))    /**<        */
#define	DSM_COND_DEV_MONITOR_STOP	     ((DSM_COND_DEV_T)(DSM_COND_AVC_DEV+3))    /**<        */
#define	DSM_COND_DEV_MONITOR_START	     ((DSM_COND_DEV_T)(DSM_COND_AVC_DEV+4))    /**<        */
#define DSM_COND_DEV_CABLE_STATUS        ((DSM_COND_DEV_T)(DSM_COND_AVC_DEV+5))    /**<        */

/* this is deprecated. */
#define DSM_COND_DEV_SIGNAL_STATUS       ((DSM_COND_DEV_T)(DSM_COND_AVC_DEV+2))    /**<        */


/*
Enum Flag for 'pass by value' or 'pass by reference'
for the 'pv_data' field in the DSM notification functions:
*/ 
/*
typedef enum
{
    DSM_NULL = 0,
    DSM_PASS_BY_VALUE,
    DSM_PASS_BY_REF	
} DSM_NFY_DATA_T ;
*/

/* 
   DSM device group set and get type operation.
*/
typedef   UINT32                       DSM_SET_T;    /**<        */
typedef   UINT32                       DSM_GET_T;    /**<        */


/* 
	types for DSM device set and get type operation.
*/
typedef   UINT32                       DSM_DEV_SET_T;    /**<        */

#define   DSM_SET_AVC_START_MONITOR    ((DSM_DEV_SET_T) 1)    /**<        */
#define   DSM_SET_AVC_STOP_MONITOR     ((DSM_DEV_SET_T) 2)    /**<        */
#define   DSM_SET_AVC_VID_SIG_RESET    ((DSM_DEV_SET_T) 3)    /**<        */

typedef   UINT32                       DSM_DEV_GET_T;    /**<        */

#define   DSM_GET_AVC_NUM_OF_DEV        ((DSM_DEV_GET_T) 32)    /**<        */
#define   DSM_GET_AVC_DEV_TYPE          ((DSM_DEV_GET_T) 33)    /**<        */
#define	  DSM_GET_AVC_VIDEO_SIG_STATUS  ((DSM_DEV_GET_T) 34)    /**<        */
#define	  DSM_GET_AVC_AUDIO_SIG_STATUS  ((DSM_DEV_GET_T) 35)    /**<        */
#define   DSM_GET_AVC_CABLE_STATUS      ((DSM_DEV_GET_T) 36)    /**<        */

/* this is deprecated. */
/* #define   DSM_GET_AVC_SIGNAL_STATUS     ((DSM_DEV_GET_T) 36) */


#define   DSM_VIEDO_TYPE_UNKNOWN             (0)    /**<        */
#define   DSM_VIDEO_TYPE_COMPOSITE           (1)    /**<        */
#define   DSM_VIDEO_TYPE_RGB                 (2)    /**<        */
#define   DSM_VIDEO_TYPE_MIXED               (3)    /**<        */
#define   DSM_VIDEO_TYPE_S_VIDEO             (4)    /**<        */

/*
  Video signal status information

  The status are bit-masked.  The SCART device provides
  video signal aspect ratio.  For example, when client receive notification
  or calling x_dsm_dev_get() API on the SCART video signal status, it can checks
  masked-bit to determine the value of the aspect ratio.

  For example:

  signal on and aspect ratio is 4:3

  (DSM_VIDEO_SIGNAL_ON | DSM_VIDEO_SIGNAL_ASPECT_RATIO_4_3)

  signal on and aspect ratio is 16:9
                
  (DSM_VIDEO_SIGNAL_ON | DSM_VIDEO_SIGNAL_ASPECT_RATIO_16_9)

  no video signal

  (DSM_VIDEO_SIGNAL_OFF)

*/
  
#define   DSM_VIDEO_SIGNAL_UNKNOWN           (0)    /**<        */
#define   DSM_VIDEO_SIGNAL_OFF               (1)    /**<        */
#define   DSM_VIDEO_SIGNAL_ON                (2)    /**<        */
#define   DSM_VIDEO_SIGNAL_ASPECT_RATIO_4_3  (4)    /**<        */
#define   DSM_VIDEO_SIGNAL_ASPECT_RATIO_16_9 (8)    /**<        */


/*
  Default parameters for the DSM thread and message queue.
*/
#define   DSM_DEFAULT_STACK_SZ      2048    /**<        */
#define   DSM_DEFAULT_PRIORITY      128    /**<        */
#define   DSM_DEFAULT_MSG_SIZE      64    /**<        */
#define   DSM_DEFAULT_NUM_OF_MSG    32    /**<        */

#define   DSM_DEFAULT_THREAD_NAME   "dsm_thread"    /**<        */
#define   DSM_MSG_QUEUE_NAME        "dsm_msg_q"    /**<        */
/*---------------------------------------------------------------------------
 Structures
----------------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/*! @struct DSM_CONFIG_T
 *  @brief DSM config information
 *  @code
 *  typedef struct _DSM_CONFIG_T_
 *  {
 *      SIZE_T   z_stack_sz;          
 *      UINT8    ui1_thread_priority; 
 *      UINT16   z_msg_size;          
 *      UINT16   ui2_msg_count;       
 *  }  DSM_CONFIG_T;
 *  @endcode
 *  @li@c  z_stack_sz                                        - stack size ,default size is 2048
 *  @li@c  ui1_thread_priority                               -thread priority  default is 128
 *  @li@c  z_msg_size                                        - msg size ,default is 64
 *  @li@c  ui2_msg_count                                     -msg number,default is 32
 */
/*------------------------------------------------------------------*/
typedef struct _DSM_CONFIG_T_
{
    SIZE_T   z_stack_sz;          /* If 0, then use the default size of 1024 */
    UINT8    ui1_thread_priority; /* if 0, then use priority of 32. */
    UINT16   z_msg_size;          /* If 0, then use default size of 64. */
    UINT16   ui2_msg_count;       /* If 0, then use the default msg count of = 32 */
}  DSM_CONFIG_T;
 
/*---------------------------------------------------------------------------
 Type definition
----------------------------------------------------------------------------*/

/*
  typedef for the DSM device notification function.  This fucntion
  is registered by the client to the DSM when calling x_dsm_dev_open.
*/
/*------------------------------------------------------------------*/
/*! @brief  Prototype for the device notification function. 
 *  @param [in] h_dsm_dev	handle to the device or device group.
 *  @param [in] e_cond	      Condition for the notification. This condition is defined by the actual device layer.  
 *                                     The DSM will translate the device notification condition to DSM device condition. 
 *                                    For example: if the source of notification is DEV_AVC_COMBI, then the notification is 
 *                                    one of the following value:
 *                          		DSM_COND_DEV_SIGNAL_STATUS
 *                          		DSM_COND_DEV_HANDLE_CLOSED
 *                         		DSM_COND_DEV_MONITOR_STOP
 *  @param [in]  pv_tag	client's tag value.
 *  @param [in]  ui4_data_1	 contain data returned to the client for the notification.  The interpretation of this data depends 
 *                                      on the notification source and condition of the notification.  
 *  @param [in] ui4_data_2:	 contain additional data to the client for the notification.
 *  @note
 *  @see
 *  @return
 *  @retval      -
 */
/*------------------------------------------------------------------*/
typedef VOID (*dsm_dev_nfy_fct)
(
    HANDLE_T          h_dsm_dev,
    DSM_COND_DEV_T    e_cond,
    VOID*             pv_tag,
    UINT32            ui4_data_1,
    UINT32            ui4_data_2
);


#endif /* _U_DSM_H_ */
/*----------------------------------------------------------------------------*/
/*! @} */                                             /* end of groupMW_DSM */
/*----------------------------------------------------------------------------*/
