/*****************************************************************************/
/* Copyright (c) 2008 NXP B.V.                                               */
/*                                                                           */
/* This library is free software; you can redistribute it and/or             */
/* modify it under the terms of the GNU Lesser General Public                */
/* License as published by the Free Software Foundation, using               */
/* version 2.1 of the License.                                               */
/*                                                                           */
/* This library 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 the GNU          */
/* Lesser General Public License for more details.                           */
/*                                                                           */
/* You should have received a copy of the GNU Lesser General Public          */
/* License along with this library; if not, write to the Free Software       */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   */
/*                                                                           */
/*****************************************************************************/
/*
   NXP STB22X Driver

   Code is derived from TI Davinci driver.

   TI Davinci driver

   (c) Copyright 2007  Telio AG

   Written by Denis Oliver Kropp <dok@directfb.org>

   Code is derived from VMWare driver.

   (c) Copyright 2001-2007  The DirectFB Organization (directfb.org)
   (c) Copyright 2000-2004  Convergence (integrated media) GmbH

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
              Andreas Hundt <andi@fischlustig.de>,
              Sven Neumann <neo@directfb.org>,
              Ville Syrjälä <syrjala@sci.fi> and
              Claudio Ciccani <klan@users.sf.net>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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 the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*//**
    @file   phStbDFB_output.c
    @brief  Output Implementation for DirectFB.

@b  Component:  phStbDFB.

*//*

Rev Date        Author      Comments
--------------------------------------------------------------------------------
  1 20080103    laird       New version for DirectFB 1.1.1
  2 20080902    laird       Updated copyright.
  3 20080905    neill       Correct output name
--------------------------------------------------------------------------------
    For consistency and standardisation retain the Section Separators.
*/

/***********************************************
* INCLUDE FILES                                *
************************************************/
#include "phStbDFB_output.h"

/***********************************************
* LOCAL MACROS                                 *
* recommendation only: <MODULE><_WORD>+        *
************************************************/

/******************************************************************
* LOCAL TYPEDEFS                                                  *
* recommendation only:                [p]phStbTemplate_<Word>+_t  *
*******************************************************************/
D_DEBUG_DOMAIN( phStbDFB_Outputs, "NXP/STB22X/Output", "NXP 22X Outputs" );

/******************************************************************
* STATIC FUNCTION PROTOTYPES                  <Module>_<Word>+    *
*******************************************************************/

/******************************************************************
* STATIC DATA                  g[k|p|kp|pk|kpk]<Module>_<Word>+   *
*******************************************************************/

/**
 * @brief Name the Outputs.
 * @todo  Outputs are being changed to be mapped to physical outputs the names will then be fixed.
 */
static char_t *gphStbDFB_OutputName = "Main";

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

/*******************************************************************************
* FUNCTION IMPLEMENTATION  <Module>[_<Word>+] for static functions             *
*                          tm[<screen>]<Module>[_<Word>+] for exported functions*
********************************************************************************/

/******************************************************************************/
extern DFBResult phStbDFB_InitOutput(
    CoreScreen                   *screen,
    void                         *driver_data,
    void                         *screen_data,
    int                           output,
    DFBScreenOutputDescription   *description,
    DFBScreenOutputConfig        *config )
{
    DFBResult result = DFB_OK;
    phStbDFB_ScreenData_t *pScreenData = (phStbDFB_ScreenData_t*)screen_data;

    D_DEBUG_ENTER( phStbDFB_Outputs, "");
    D_ASSUME(output < PH_STBVIDEORENDERER_MAX_INSTANCES);

    /*Setup our default capabilities*/
    description->caps = PH_STBDFB_SCREEN_OUTPUT_CAPABILITIES;
    description->all_signals = DSOS_656;

    /*Set default which is 656 only and no connectors*/
    config->out_signals = DSOS_656;
    config->out_connectors = DSOC_UNKNOWN;

    /*Define the flags that are allowed to be set default is none*/
    config->flags = DSOCONF_NONE;

    /*Our output name*/
    strcpy(description->name, gphStbDFB_OutputName);

    /*If we have more than one encoder indicate that support for switching encoders exists*/
    if(pScreenData->numberEncoders > 1)
    {
        description->caps |= DSOCAPS_ENCODER_SEL;
    }

    D_DEBUG_EXIT( phStbDFB_Outputs, "result => 0x%08x", result);
    return result;
}

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

extern DFBResult phStbDFB_SetPowerMode(
    CoreScreen             *screen,
    void                   *driver_data,
    void                   *screen_data,
    DFBScreenPowerMode      mode )
{
    DFBResult result = DFB_UNSUPPORTED;

    D_DEBUG_ENTER( phStbDFB_Outputs, "");
    D_DEBUG_EXIT( phStbDFB_Outputs, "result => 0x%08x", result);
    return result;
}

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

extern DFBResult phStbDFB_TestOutputConfig(
    CoreScreen                  *screen,
    void                        *driver_data,
    void                        *screen_data,
    int                          output,
    const DFBScreenOutputConfig *config,
    DFBScreenOutputConfigFlags  *failed)
{
    DFBResult result = DFB_OK;

    D_DEBUG_ENTER( phStbDFB_Outputs, "");

    /*If any flags are set other than the supported flags then or them to
      failed value and return*/
    if (config->flags & ~PH_STBDFB_SCREEN_OUTPUT_CONFIGFLAGS)
    {
        *failed |= ~PH_STBDFB_SCREEN_OUTPUT_CAPABILITIES;
        result = DFB_UNSUPPORTED;
        goto RETURN;
    }

RETURN:
    D_DEBUG_EXIT( phStbDFB_Outputs, "result => 0x%08x", result);
    return result;
}

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

extern DFBResult phStbDFB_SetOutputConfig(
    CoreScreen                  *screen,
    void                        *driver_data,
    void                        *screen_data,
    int                          output,
    const DFBScreenOutputConfig *config)
{
    DFBResult result = DFB_OK;


    D_DEBUG_ENTER( phStbDFB_Outputs, "config->flags 0x%08x", config->flags);
    D_ASSUME(output < PH_STBVIDEORENDERER_MAX_INSTANCES);

    D_DEBUG_EXIT( phStbDFB_Outputs, "result => 0x%08x", result);
    return result;
}

