How to: TVP5150 with DM365EVM + DVSDK4.02

Hi ALL!

At this moment, I use DM365EVM (DVSDK4.02) with TVP5150 (instead of TVP5146) for PAL cam.

TVP5150 was placed on a custom daughter card into IMAGER interface (J10).

This is small how to.

 

Step 1: "drivers/media/video/tvp5150.c"

 

I made a few changes:

1. The outputs is in tristate mode (disabled) by defaults. You need to enable outputs!!!

Look at 'static inline void tvp5150_selmux()'

----

/* Svideo should enable YCrCb output and disable GPCL output

* For Composite and TV, it should be the reverse

*/

val = tvp5150_read(sd, TVP5150_MISC_CTL);

if (decoder->input == TVP5150_SVIDEO)

val = (val & ~0x40) | 0x10;

else

val = (val & ~0x10) | 0x40;

val = val | 0x08; //!!! My fix. (enable outputs)

tvp5150_write(sd, TVP5150_MISC_CTL, val);

----

2. You can modify printout of i2c adr at 'tvp5150_probe()' and 'tvp5150_remove()' so driver will print more intelligible i2c adr (eg, '5D' instead of 'BA').

Simple change "c->addr << 1" to "c->addr".

I think that nothing else do not need to touch in this 'tvp5150.c' file!

But, you really have something to edit the file "vpfe-capture.c".

 

 

 

Step 2: "drivers/media/video/davinci/vpfe_capture.c"

1)

static int vpfe_config_ccdc_image_format()

----

/* At CCDC we need to set pix format based on source. */

if (vpfe_dev->imp_chained) {

if (vpfe_dev->current_subdev->is_camera)

pix_fmt = V4L2_PIX_FMT_SBGGR16;

else if (pix_fmt == V4L2_PIX_FMT_NV12)

pix_fmt = V4L2_PIX_FMT_UYVY;

}

pix_fmt = V4L2_PIX_FMT_UYVY; //!!! My fix!

if (ccdc_dev->hw_ops.set_pixel_format(pix_fmt) < 0) {

v4l2_err(&vpfe_dev->v4l2_dev,

"couldn't set pix format in ccdc\n");

return -EINVAL;

}

/* configure the image window */

ccdc_dev->hw_ops.set_image_window(&vpfe_dev->crop);

vpfe_dev->fmt.fmt.pix.field=V4L2_FIELD_INTERLACED; //!!! My fix!

switch (vpfe_dev->fmt.fmt.pix.field) {

case V4L2_FIELD_INTERLACED:

----

2)

static int vpfe_config_image_format()

----

/* first field and frame format based on standard frame format */

if (vpfe_dev->std_info.frame_format) {

vpfe_dev->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;

/* assume V4L2_PIX_FMT_UYVY as default */

vpfe_dev->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;

} else {

vpfe_dev->fmt.fmt.pix.field = V4L2_FIELD_NONE;

vpfe_dev->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;

}

// sd_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

sd_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; //!!! My fix!

/* if sub device supports g_fmt, override the defaults */

ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev,

----

Very important! the driver will not work if sd_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE !!!

You need change it to sd_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE

 

3)

static int vpfe_s_input()

----

/* set the default image parameters in the device */

if (vpfe_dev->current_subdev->is_camera) {

vpfe_dev->std_index = -1;

/* for camera, use ccdc default parameters */

ret = vpfe_get_ccdc_image_format(vpfe_dev, &vpfe_dev->fmt);

/* also set the current default format in the sensor */

if (ret)

goto unlock_out;

ret = vpfe_set_format_in_sensor(vpfe_dev, &vpfe_dev->fmt);

} else {

//vpfe_dev->std_index = 0; //NTSC

vpfe_dev->std_index = 1; //!!!My fix for PAL

/*

* For non-camera sub device, use standard to configure vpfe

* default

*/

ret = vpfe_config_image_format(vpfe_dev,

&vpfe_standards[vpfe_dev->std_index].std_id);

}

----

vpfe_dev->std_index =1; //(my settings for PAL)

see "const struct vpfe_standard vpfe_standards[]" at the top of "vpfe-capture.c" for details.

That's all that I corrected in the file 'vpfe-capture.c'.

 

 

Step 3: "include/media/davinci/vpfe_capture.h"

 

I added the 'tvp5150' device into 'include/media/davinci/vpfe_capture.h'

----

enum vpfe_subdev_id {

VPFE_SUBDEV_TVP5146 = 1,

VPFE_SUBDEV_MT9T031 = 2,

VPFE_SUBDEV_TVP7002 = 3,

VPFE_SUBDEV_MT9P031 = 4,

VPFE_SUBDEV_TVP5150 = 5, //!!!

};

----

 

 

The next changes are arch specific.

In my case I edited 'arch/arm/mach-davinci/board-dm365-evm.c'

 

Step 4: "arch/arm/mach-davinci/board-dm365-evm.c"

My TVP5150 is connected to DM365EVM via IMAGER interface, because I needed to make the correct switching of the multiplexer.

Also in this file, I prescribed a "tvp5150_inputs []" and yet something.

 

----

 

#include <media/tvp5150.h>

 

--- -

#define TVP5150_STD_ALL (V4L2_STD_NTSC | V4L2_STD_PAL)

/* Inputs available at the TVP5150 */

static struct v4l2_input tvp5150_inputs[] = {

{

.index = 0,

.name = "Composite",

.type = V4L2_INPUT_TYPE_CAMERA,

.std = TVP5150_STD_ALL,

},

{

.index = 1,

.name = "Composite1",

.type = V4L2_INPUT_TYPE_CAMERA,

.std = TVP5150_STD_ALL,

},

};

----

static struct vpfe_route tvp5150_routes[] = {

{ //see "include/media/tvp5150.h"

.input = TVP5150_COMPOSITE0,

.output = TVP5150_NORMAL,

},

};

----

static struct vpfe_subdev_info vpfe_sub_devs[] = {

{

.module_name = "tvp5150",

.grp_id = VPFE_SUBDEV_TVP5150,

.num_inputs = ARRAY_SIZE(tvp5150_inputs),

.inputs = tvp5150_inputs,

.routes = tvp5150_routes,

.can_route = 1,

.ccdc_if_params = {

.if_type = VPFE_BT656,

.hdpol = VPFE_PINPOL_POSITIVE,

.vdpol = VPFE_PINPOL_POSITIVE,

},

.board_info = {

I2C_BOARD_INFO("tvp5150", 0x5c), // <- place correct i2c adr here!

},

},

/*

ALL OTHERS CODECS (tvp5146,tvp7002,ths7353,mt9p031) ARE COMMENTED HERE! = disabled

*/

}; //end of struct vpfe_subdev_info vpfe_sub_devs[]

----

static int dm365evm_setup_video_input(enum vpfe_subdev_id id)

{

const char *label;

u8 mux, resets;

mux = __raw_readb(cpld + CPLD_MUX);

mux &= ~CPLD_VIDEO_INPUT_MUX_MASK;

resets = __raw_readb(cpld + CPLD_RESETS);

switch (id) {

case VPFE_SUBDEV_TVP5150:

mux |= CPLD_VIDEO_INPUT_MUX_IMAGER;

label = "tvp5150 SD";

break;

case VPFE_SUBDEV_TVP5146:

mux |= CPLD_VIDEO_INPUT_MUX_TVP5146;

resets &= ~BIT(0);

label = "tvp5146 SD";

dm365evm_reset_imager(0);

break;

----

That's all for 'board-dm365-evm.c'.

 

 

 

Step 5: Kernel Config (.config)

 

#

# Video decoders

#

CONFIG_VIDEO_TVP5150=y

 

 

 

Step 6: TEST IT!

SO! I HAVE IT ALL WORKS!

PS: I also got to change on the fly: Brightness, Contrast, Saturation and Hue.

 

 

 

Step 7: $DVSDK/dmai_2_20_00_15/packages/ti/sdo/dmai/linux/dm365/Capture.c

 

at the end of 'Capture_Handle Capture_create()'

 

----

...

hCapture->started = TRUE;

Tvp5150_fd = hCapture->fd; //store file id

return hCapture;

} //end of Capture_Handle Capture_create

...

----

 

at the top of 'Capture.c' file

 

----

...

extern Int Resizer_continuous_delete(int fd);

extern Int Previewer_continuous_delete(int fd);

int Tvp5150_fd=-1;

void Capture_chngTVPCtrl(unsigned char id, unsigned char val) {

if(Tvp5150_fd<0) {

printf("DMAI_Capture: TVP5150Ctl: Tvp5150_fd < 0\n");

return;

}

struct v4l2_control ctrl;

__s32 vv=val;

switch (id) {

case 0:

ctrl.id = V4L2_CID_BRIGHTNESS;

break;

case 1:

ctrl.id = V4L2_CID_CONTRAST;

break;

case 2:

ctrl.id = V4L2_CID_SATURATION;

break;

case 3:

ctrl.id = V4L2_CID_HUE;

vv=(__s32)val-128;

break;

default:

return;

}

ctrl.value = vv;

if (-1 == ioctl (Tvp5150_fd, VIDIOC_S_CTRL, &ctrl)) {

printf("DMAI_Capture: TVP5150Ctl: VIDIOC_S_CTRL failed!\n");

}

}

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

* cleanup

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

static Int cleanup(Capture_Handle hCapture)

...

----

 

Step 8: Change brightness and so on from DVSDK-DEMO (encode) EXAMPLE.

$DVSDK/dvsdk-demos_4_02_00_01/dm365/ctrl.c

------

#include <ti/sdo/dmai/Capture.h>

// Try other values!

unsigned char brt=128; //brightness 0..255

unsigned char con=128; //contrast 0..255

unsigned char sat=128; //saturation 0..255

unsigned char hue=128; //HUE 0..255

Capture_chngTVPCtrl(0,brt); //set brightness

Capture_chngTVPCtrl(1,con); //set contrast

Capture_chngTVPCtrl(2,sat); //set saturation

Capture_chngTVPCtrl(3,hue); //set hue

...

------

 

IT WORKS! :-)

 

Good luck!

 

14 Replies

  • Hi,  senchuss

    Thanks for your tvp5150  for dm365 guide!

    I use  your steps to moidfy the vpfe and  tvp5150 driver , and then run  dvsdk's  encode demo, the driver output "tvp5150 1-005d: VBI can't be configured without knowing number of lines" messages, and cann't capture video. Is there missing steps?

    I add a "printk"  in vpfe_isr function, when  run encode demo i can see the printk's output. Dose this means than tvp5150 work OK ?

  • Dear Sir,

    This howto has some proble.

    I use tvp5150 and dvsdk4 and use dvsdk-demos encode to test, but it can't capture ok.

    If I use :(PAL signal input)

    encode -v x.264 -I 1 -y 2 -w

    (This will VIDENC1_process ret -1)

    encode -v x.264 -I 1 -y 2 -w -r 704x576

    This will not receive isr, can't capture ok.

    I check tvp5150's reg and this howto so many times.

    But I can't capture ok.

    Please help me. Thanks.

  • In reply to qiu gongfen:

    There is my tvp5150 log status:
    ===
    tvp5150: Video input source selection #1 = 0x00
    tvp5150: Analog channel controls = 0x15
    tvp5150: Operation mode controls = 0x30
    tvp5150: Miscellaneous controls = 0x6f
    tvp5150: Autoswitch mask= 0xdc
    tvp5150: Color killer threshold control = 0x10
    tvp5150: Luminance processing controls #1 #2 and #3 = 60 00 00
    tvp5150: Brightness control = 0x80
    tvp5150: Color saturation control = 0x80
    tvp5150: Hue control = 0x00
    tvp5150: Contrast control = 0x80
    tvp5150: Outputs and data rates select = 0x47
    tvp5150: Configuration shared pins = 0x08
    tvp5150: Active video cropping start = 0x0000
    tvp5150: Active video cropping stop  = 0x0000
    tvp5150: Genlock/RTC = 0x01
    tvp5150: Horizontal sync start = 0x80
    tvp5150: Vertical blanking start = 0x00
    tvp5150: Vertical blanking stop = 0x00
    tvp5150: Chrominance processing control #1 and #2 = 0c 54
    tvp5150: Interrupt reset register B = 0x00
    tvp5150: Interrupt enable register B = 0x00
    tvp5150: Interrupt configuration register B = 0x00
    tvp5150: Video standard = 0x04
    tvp5150: Chroma gain factor: Cb=0xb2 Cr=0x7e
    tvp5150: Macrovision on counter = 0x0f
    tvp5150: Macrovision off counter = 0x01
    tvp5150: ITU-R BT.656.4 timing(TVP5150AM1 only)
    tvp5150: Device ID = 5150
    tvp5150: ROM version = (hex) 04.00
    tvp5150: Vertical line count = 0x0271
    tvp5150: Interrupt status register B = 0xdf
    tvp5150: Interrupt active register B = 0x00
    tvp5150: Status regs #1 to #5 = 6e 28 14 c5 83
    tvp5150: Teletext filter 1 reg 0xb1 =
    00
    00
    00
    00
    00
    tvp5150: Teletext filter 2 reg 0xb6 =
    00
    00
    00
    00
    00
    tvp5150: Teletext filter enable = 0x00
    tvp5150: Interrupt status register A = 0xc0
    tvp5150: Interrupt enable register A = 0x00
    tvp5150: Interrupt configuration = 0x04
    tvp5150: VDP status register = 0x40
    tvp5150: FIFO word count = 0x00
    tvp5150: FIFO interrupt threshold = 0x80
    tvp5150: FIFO reset = 0x00
    tvp5150: Line number interrupt = 0x00
    tvp5150: Pixel alignment register = 0x004e
    tvp5150: FIFO output control = 0x00
    tvp5150: Full field enable = 0x00
    tvp5150: Full field mode register = 0x7f
    tvp5150: CC   data reg 0x90 =
    00
    00
    00
    00
    tvp5150: WSS  data reg 0x94 =
    00
    00
    00
    00
    00
    00
    tvp5150: VPS  data reg 0x9a =
    00
    00
    00
    00
    00
    00
    00
    00
    tvp5150: VPS  data reg 0xa2 =
    00
    00
    00
    00
    00
    tvp5150: VITC data reg 0xa7 =
    00
    00
    00
    00
    00
    00
    00
    00
    00
    tvp5150: Line mode reg 0xd0 =
    00
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    tvp5150: Line mode reg 0xd8 =
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    tvp5150: Line mode reg 0xe0 =
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    tvp5150: Line mode reg 0xe8 =
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    tvp5150: Line mode reg 0xf0 =
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    ff
    tvp5150: Line mode reg 0xf8 =
    ff
    ff
    ff
    ff
    ======
    And the dvsdk4 encode demos is set NV12(YUV420), but vpfe_capture is set YUV422, 
    If I modify encode demos YUV420 to UYUV, there's some problem about the codec(only work YUV420).
    So how can I use dvsdk4.02 encode demos to work with tvp5150?
    Many thanks.
  • In reply to qiu gongfen:

    Hi,

        In the encode demo i can see that capture is set as ColorSpace_YUV420PSEMI (NV12), I think it is possible to set the capture as NV12 (YUV420) to meet the codec input requirement.

        I can see that DMAI & V4L2 layer supports NV12 configuration for capture. I am not familiar with the TVP51xx parts, but as the software layer has this supports someone underneath must do conversion if TVP51xx part can not get NV12 format.

    Best Regards

    Velan

  • In reply to Velan:

    Hi,

    Can i please ask what are you doing with the Y inputs of the DM365 ?
    TVP5150 uses bt656 8bit mode and they are connected to the DM365 C inputs,
    But what must i do with the DM365 Y inputs ?? Can I use them as GPIO ??
    What did you do with your DM365 Y input ??

    Any answer will be highly appriciated
    Thanks
    Amir

  • Thanks for this info, it was really useful. It helps me to create alternative firmware for DVS-310-1 (Appro oem video server).

    Also I noticed, that input video (from VPFE capture) must be forced to resizer, even if I don't need resizing, that's due Gstreamer's H264 encoder wants only NV12 format, but VPFE returns only UYVY or YUYV formats.

  • In reply to qiu gongfen:

    we do the steps  and the demo can run ,but no data return from dqbuf, the isr in vpfe_capture not called,

    we have been delaed by this issue for month now, anyone have solved this problem please share.

    and by the way, we connect the 5150 output to C0-7 of vpfe, is that correct????

  • In reply to Osery Huang:

    We have a similar problem. That's why i can't tell you the right solution of the problem. Two things i can advise:

    1. Check if YCINSWP bit is NOT set in CCDCFG register (you can find it a dm365_ccdc.c). This because you're using C0-7 inputs on your davinci.

    2. Check the PCLK output from decoder (tvp5150). I think that clock must present. If not, add "val |= 0x09;" instead of "val = val | 0x08;" in the decoder driver tvp5150.c , function tvp5150_selmux()

    Let me know if something of this helps you.

    Good luck.

  • In reply to Dmitry Kinyov:

    Hi ALL.
    I apologize if some people have problems. In my case all was fine with dm365evm (tvp5150 via imager connector).
    May be you need to check your hardware connections?
    Carefully check 'board-dm365-evm.c' and especially Altera MUX if you use imager interface for tvp5150. Check clocks and so on.

    Now, I have my custom board with TVP5150 routed directly to DM365 (YIN0..YIN7, HSYNC,VSYNC,PCLK). It works fine!

    to Osery Huang,
    Try to use YIN0..YIN7 inputs!

    Here is a patch based on first half of topic post -> 0743.TVP5150_without_BRDsupport.patch.zip


    The second task is to modify 'arch/arm/mach-davinci/board-dm365-evm.c' for your custom hardware design.
    I can't post my custom 'board-dm365-evm.c' because it has many modifications that not related to tvp5150. But it really based on topic post (tvp5150_routes[], vpfe_sub_devs[]). In my case I remove all things related to altera mux because my tvp5150 connected directly to YIN-port now.
    In my case all works fine.

  • In reply to senchuss:

    hi senchuss i do all the patch.

    on the boot kernel the tvp 5150 is detected and registered .

    the encoder cannot get lines and standard

    on the board i have connected the tvp7002 and all work ok.

    on the same bus i have sw for  connect the tvp5150 / tvp7002.(not the same add).

    the boot :

     i2c /dev entries driver
    Linux video capture interface: v2.00
    vpfe_init
    vpfe-capture: vpss clock vpss_master enabled
    vpfe-capture vpfe-capture: v4l2 device registered
    vpfe-capture vpfe-capture: video device registered
    EVM: switch to tvp5150 SD video input
    tvp5150 1-00ba: chip found @ 0x174 (DaVinci I2C adapter)
    vpfe-capture vpfe-capture: v4l2 sub device tvp5150 registered
    EVM: switch to tvp7002 HD video input
    from tvp7002 tvp7002_initialize
    tvp7002 1-005c: get id std =0 std 0x4000000000000
    tvp7002 1-005c: tvp7002 1-005c decoder driver registered !!
    vpfe-capture vpfe-capture: v4l2 sub device tvp7002 registered
    EVM: switch to tvp7002 HD video input
    ths7353 1-002e: chip found @ 0x5c (DaVinci I2C adapter)
    ths7353 1-002e: No platform data!!
    vpfe-capture vpfe-capture: v4l2 sub device ths7353 registered
    vpfe_register_ccdc_device: DM365 ISIF
    DM365 ISIF is registered with vpfe.
    Trying to register davinci display video device.
    layer=c14f8c00,layer->video_dev=c14f8d70
    Trying to register davinci display video device.
    layer=c14f9000,layer->video_dev=c14f9170
    davinci_init:DaVinci V4L2 Display Driver V1.0 loaded
    watchdog watchdog: heartbeat 60 sec
    TCP cubic registered

    .................................................................................

    after start the encoder:

    .................................................................................

    captureThrFxn vitvp5150 1-00ba: tvp5150_get_vbi lines=0  std =0xffffff
    deoInput = 2 gettvp5150 1-00ba: tvp5150_get_vbi lines=1  std =0xffffff
    std 5 std 5
    tvp5150 1-00ba: tvp5150_get_vbi lines=2  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=3  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=4  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=5  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=6  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=7  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=8  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=9  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=10  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=11  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=12  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=13  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=14  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=15  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=16  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=17  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=18  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=19  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=20  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=21  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=22  std =0xffffff
    tvp5150 1-00ba: tvp5150_get_vbi lines=23  std =0xffffff
    EVM: switch to tvp7002 HD video input
    vpfe-capture vpfe-capture: error in getting g_fmt from sub device
    Error: Failed to detect video standard, video input connected?
    Video.c: localBufferAlloc=1

    thanks  doron sandroy.