⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saa7185.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
字号:
/*
 * Copyright (c) 1995,1999 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : saa7185.c    1.18
 *
 *  Last update              : 18:43:46 - 00/11/09
 *
 *  Description              :
 *
 *  Initialize and control routines for saa7185 DENC.
 *
 *  Revision                 :
 *      Built for the TCS 2.0 release
 *
 *
 */


#include <stdio.h>

#include <tm1/tmIIC.h>
#include <tm1/tmVO.h>
#include <tm1/tmVOmmio.h>
#include <tm1/tmVOboard.h>
#include <tm1/tmAvFormats.h>
#include <tm1/tmProcessor.h>
#include <tmlib/tmtypes.h>

#include "saa7185.h"

#define SAA7185_NREGS   0x7E    /* number of 7185 registers     */
#define SAA7185_STARADR 0x38    /* Start for sub-addresses for 7185 */
#define SAA7185_ADDR    0x88    /* SAA7185 IIC address */

#define SAA7185_BLACKLEVEL_REG    0x5D    /* bits 0-5 */

static unsigned char saa7185_init[SAA7185_NREGS - SAA7185_STARADR] = {
     /* 0x38 */ 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
     /* 0x40 */ 0x00, 0x00, 0x6B, 0x00, 0x00, 0x22, 0xAC, 0x0E,
     /* 0x48 */ 0x03, 0x1D, 0xAC, 0xF0, 0xC8, 0xB9, 0xD4, 0x38,
     /* 0x50 */ 0x47, 0xC1, 0xE3, 0x54, 0xA3, 0x54, 0xF2, 0x90,
     /* 0x58 */ 0x00, 0x00, 0x68, 0x82, 0xB6, 0x2D, 0x3F, 0x00,
     /* 0x60 */ 0x38, 0x56, 0x4E, 0xCB, 0x8A, 0x09, 0x2A, 0x00,
     /* 0x68 */ 0x00, 0x00, 0x00, 0x11, 0x7A, 0x04, 0xAC, 0x06,
     /* 0x70 */ 0x0C, 0x77, 0xF7, 0x33, 0x00, 0x00, 0x00, 0x00,
     /* 0x78 */ 0x03, 0x00, 0x70, 0x12, 0x35, 0x22
};

typedef struct subaddInfo_t {
    UInt8       subAddr;    /* subaddress of IIC register */
    UInt8       value;      /* data for IIC register */
}           subaddInfo_t;

static subaddInfo_t saa7185_pal[] = {
    {0x61, 0x56},        /* Standard Control */
    {0x3A, 0x1F},        /* Input port control */
    {0x42, 0x6B},        /* OSD Lut */
    {0x45, 0x52},        /* OSD Lut */
    {0x46, 0x90},        /* OSD Lut */
    {0x47, 0x12},        /* OSD Lut */
    {0x48, 0x2A},        /* OSD Lut */
    {0x49, 0x26},        /* OSD Lut */
    {0x4A, 0x90},        /* OSD Lut */
    {0x4B, 0x11},        /* OSD Lut */
    {0x4C, 0xB6},        /* OSD Lut */
    {0x4D, 0xA2},        /* OSD Lut */
    {0x4E, 0xEA},        /* OSD Lut */
    {0x4F, 0x4A},        /* OSD Lut */
    {0x50, 0x5E},        /* OSD Lut */
    {0x51, 0xD1},        /* OSD Lut */
    {0x52, 0xDA},        /* OSD Lut */
    {0x53, 0x70},        /* OSD Lut */
    {0x54, 0xA9},        /* OSD Lut */
    {0x55, 0x70},        /* OSD Lut */
    {0x56, 0xEE},        /* OSD Lut */
    {0x57, 0x90},        /* OSD Lut */
    {0x5A, 0x68},        /* Chroma Phase */
    {0x5B, 0x82},        /* Gain-U */
    {0x5C, 0xB6},        /* Gain-V */
    {0x5D, 0x2D},        /* Gain-U MSB, Black Level */
    {0x5E, 0x3F},        /* Gain-V MSB, Blanking Level */
    {0x60, 0x00},        /* Cross-colour select  */
    {0x62, 0x4E},        /* Burst Amplitude */
    {0x63, 0xCB},        /* Subcarrier Frequency, Byte 0 */
    {0x64, 0x8A},        /* Subcarrier Frequency, Byte 1 */
    {0x65, 0x09},        /* Subcarrier Frequency, Byte 2 */
    {0x66, 0x2A},        /* Subcarrier Frequency, Byte 3 */
    {0x67, 0x00},        /* */
    {0x68, 0x00},        /* */
    {0x69, 0x00},        /* */
    {0x6A, 0x00},        /* */
    {0x6B, 0x11},        /* Input Port & Closed Caption-Select Line Number */
    {0x6C, 0x6D},        /* FS on RCV1 falling, Htrig on RCV2 falling */
    {0x6D, 0x04},        /* RCM, CC mode */
    {0x6E, 0xAB},        /* Horizontal Trigger (LSB's) */
    {0x6F, 0x06},        /* Horizontal Trigger (MSB's) */
    {0x70, 0x80},        /* Reset when changing Subcarrier frequency */
    {0x71, 0x00},        /* Begin MP request */
    {0x72, 0x00},        /* End MP request */
    {0x73, 0x00},        /* MSBs MP request */
    {0x77, 0x00},        /* Begin RCV2 output */
    {0x78, 0x00},        /* End RCV2 output */
    {0x79, 0x00},        /* MSBs RCV2 output */
    {0x7A, 0x70},        /* Field Length */
    {0x7B, 0x16},        /* First Active Line */
    {0x7C, 0x36},        /* Last Active Line */
    {0x7D, 0x22}         /* Field Control (MSB's) */
};

/* NTSC mode */
static subaddInfo_t saa7185_ntsc[] = {
    {0x61, 0x55},        /* Standard Control */
    {0x3A, 0x1F},        /* Input port control */
    {0x42, 0x6B},        /* OSD Lut */
    {0x45, 0x52},        /* OSD Lut */
    {0x46, 0x90},        /* OSD Lut */
    {0x47, 0x12},        /* OSD Lut */
    {0x48, 0x2A},        /* OSD Lut */
    {0x49, 0x26},        /* OSD Lut */
    {0x4A, 0x90},        /* OSD Lut */
    {0x4B, 0x11},        /* OSD Lut */
    {0x4C, 0xB6},        /* OSD Lut */
    {0x4D, 0xA2},        /* OSD Lut */
    {0x4E, 0xEA},        /* OSD Lut */
    {0x4F, 0x4A},        /* OSD Lut */
    {0x50, 0x5E},        /* OSD Lut */
    {0x51, 0xD1},        /* OSD Lut */
    {0x52, 0xDA},        /* OSD Lut */
    {0x53, 0x70},        /* OSD Lut */
    {0x54, 0xA9},        /* OSD Lut */
    {0x55, 0x70},        /* OSD Lut */
    {0x56, 0xEE},        /* OSD Lut */
    {0x57, 0x90},        /* OSD Lut */
    {0x5A, 0x82},        /* Chroma Phase */
    {0x5B, 0x79},        /* Gain-U */
    {0x5C, 0xAD},        /* Gain-V */
    {0x5D, 0x3C},        /* Gain-U MSB, Black Level */
    {0x5E, 0x3A},        /* Gain-V MSB, Blanking Level */
    {0x60, 0x00},        /* Cross-colour select  */
    {0x62, 0x69},        /* Burst Amplitude */
    {0x63, 0x1F},        /* Subcarrier Frequency, Byte 0 */
    {0x64, 0x7C},        /* Subcarrier Frequency, Byte 1 */
    {0x65, 0xF0},        /* Subcarrier Frequency, Byte 2 */
    {0x66, 0x21},        /* Subcarrier Frequency, Byte 3 */
    {0x67, 0x00},        /* */
    {0x68, 0x00},        /* */
    {0x69, 0x00},        /* */
    {0x6A, 0x00},        /* */
    {0x6B, 0x11},        /* Input Port & Closed Caption-Select Line Number */
    {0x6C, 0x6D},        /* FS on RCV1 falling, Htrig on RCV2 falling */
    {0x6D, 0x04},        /* RCM, CC mode */
    {0x6E, 0x95},        /* Horizontal Trigger (LSB's) */
    {0x6F, 0x06},        /* Horizontal Trigger (MSB's) */
    {0x70, 0xc0},        /* Reset when changing Subcarrier frequency */
    {0x71, 0x00},        /* Begin MP request */
    {0x72, 0x80},        /* End MP request */
    {0x73, 0x00},        /* MSBs MP request */
    {0x77, 0x00},        /* Begin RCV2 output */
    {0x78, 0x00},        /* End RCV2 output */
    {0x79, 0x00},        /* MSBs RCV2 output */
    {0x7A, 0x0C},        /* Field Length */
    {0x7B, 0x11},        /* First Active Line */
    {0x7C, 0x03},        /* Last Active Line */
    {0x7D, 0x22}         /* Field Control (MSB's) */
};


static
tmLibdevErr_t 
saa7185Config(UInt32 address, subaddInfo_t * tobeupdated, UInt32 last_address)
{
    int         i, err;
    unsigned char subaddr, data;
    tmLibdevErr_t retval = TMLIBDEV_OK;

    /* Update the device */
    for (i = 0; i < last_address; i++) {
        subaddr = tobeupdated[i].subAddr;
        data = tobeupdated[i].value;
        err = iicWriteReg(address, subaddr, data);

        if (err)
            retval |= err;
    } 
    return (retval);
}

/****  Public Init function ****/
tmLibdevErr_t 
saa7185Init(pboardVOParam_t param)
{
    int         i;
    int         retval = 0;
    unsigned char subaddr, data;
    pprocCapabilities_t procCap;

    procGetCapabilities(&procCap);

    /* make sure VO clock is running at 27MHz! */
    MMIO(VO_CLOCK) = (unsigned int) (0.5 + 
        (1431655765.0 * 27000000 / (float) procCap->cpuClockFrequency));
    MMIO(VO_CTL) = 0x02700000 | (MMIO(VO_CTL) | VO_RESET);    
        /* do not take it out of reset */

    microsleep(20000);    /* wait an extra 20ms */

    if (param->videoStandard == vasNone) 
	return TMLIBDEV_OK;

    /* Update the device */
    for (i = 0; i < SAA7185_NREGS; i++)
        retval |= iicWriteReg(SAA7185_ADDR, i, 0);

    if (retval)
        return ((tmLibdevErr_t) retval);

    for (i = 0; i < (SAA7185_NREGS - SAA7185_STARADR); i++) {
        subaddr = (unsigned char) (SAA7185_STARADR + i);
        data = saa7185_init[i];
        retval |= iicWriteReg(SAA7185_ADDR, subaddr, data);
    }
    if (retval)
        return ((tmLibdevErr_t) retval);

    switch (param->videoStandard) {
    case vasNTSC:        /* Update for vasNTSC standard */
        retval |= saa7185Config(SAA7185_ADDR, saa7185_ntsc, 
                                (sizeof (saa7185_ntsc) >> 1));
        break;
    case vasPAL:        /* Update for vasPAL standard */
        retval |= saa7185Config(SAA7185_ADDR, saa7185_pal, 
                                (sizeof (saa7185_pal) >> 1));
        break;
    case vasNone:
	return TMLIBDEV_OK;
    default:
        return VO_ERR_STANDARD_NOT_SUPPORTED;
    }
    retval |= saa7185Stop(param->videoStandard);
    retval |= saa7185Start(param->videoStandard);

    return ((tmLibdevErr_t) retval);
}



/****  Public Config function ****/
tmLibdevErr_t 
saa7185Configure(UInt32 subaddr, UInt32 value)
{
    int         err;
    tmLibdevErr_t retval = TMLIBDEV_OK;

    err = iicWriteReg(SAA7185_ADDR, subaddr, value);

    if (err)
        retval |= err;
    return (retval);
}

/************************** Turn Denc DAC on  *****************************/
tmLibdevErr_t 
saa7185Start(tmVideoAnalogStandard_t standard)
{
    if (standard == vasNTSC)
        return (iicWriteReg(SAA7185_ADDR, 0x61, 0x15));
    else
        return (iicWriteReg(SAA7185_ADDR, 0x61, 0x16));
}

/************************** Turn Denc DAC off  *****************************/
tmLibdevErr_t 
saa7185Stop(tmVideoAnalogStandard_t standard)
{
    if (standard == vasNTSC)
        return (iicWriteReg(SAA7185_ADDR, 0x61, 0xD5));
    else
        return (iicWriteReg(SAA7185_ADDR, 0x61, 0xD6));
}

/************************** Set Brightness (or Balck Level) *****************/
tmLibdevErr_t 
saa7185SetBrightness(UInt val)
{
    if (val > 63)
        return BOARD_ERR_VAL_OUT_OF_RANGE;

    return iicWriteReg(SAA7185_ADDR, SAA7185_BLACKLEVEL_REG, val);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -