2010-06-18 01:27:26 +08:00
|
|
|
/*
|
2013-03-25 16:35:17 +08:00
|
|
|
* Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
|
|
|
|
*
|
|
|
|
* Original author:
|
|
|
|
* Ben Collins <bcollins@ubuntu.com>
|
|
|
|
*
|
|
|
|
* Additional work by:
|
|
|
|
* John Brooks <john.brooks@bluecherry.net>
|
2010-06-18 01:27:26 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <media/v4l2-ioctl.h>
|
2013-03-25 16:35:17 +08:00
|
|
|
|
2011-02-11 20:36:27 +08:00
|
|
|
#include "solo6x10.h"
|
2010-06-18 01:27:26 +08:00
|
|
|
|
|
|
|
#define SOLO_VCLK_DELAY 3
|
|
|
|
#define SOLO_PROGRESSIVE_VSIZE 1024
|
|
|
|
|
|
|
|
#define SOLO_MOT_THRESH_W 64
|
|
|
|
#define SOLO_MOT_THRESH_H 64
|
|
|
|
#define SOLO_MOT_THRESH_SIZE 8192
|
|
|
|
#define SOLO_MOT_THRESH_REAL (SOLO_MOT_THRESH_W * SOLO_MOT_THRESH_H)
|
2013-03-25 16:35:17 +08:00
|
|
|
#define SOLO_MOT_FLAG_SIZE 1024
|
|
|
|
#define SOLO_MOT_FLAG_AREA (SOLO_MOT_FLAG_SIZE * 16)
|
2010-06-18 01:27:26 +08:00
|
|
|
|
2011-02-11 20:38:20 +08:00
|
|
|
static void solo_vin_config(struct solo_dev *solo_dev)
|
2010-06-18 01:27:26 +08:00
|
|
|
{
|
|
|
|
solo_dev->vin_hstart = 8;
|
|
|
|
solo_dev->vin_vstart = 2;
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_SYS_VCLK,
|
|
|
|
SOLO_VCLK_SELECT(2) |
|
|
|
|
SOLO_VCLK_VIN1415_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN1213_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN1011_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN0809_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN0607_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN0405_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN0203_DELAY(SOLO_VCLK_DELAY) |
|
|
|
|
SOLO_VCLK_VIN0001_DELAY(SOLO_VCLK_DELAY));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_ACT_I_P,
|
|
|
|
SOLO_VI_H_START(solo_dev->vin_hstart) |
|
|
|
|
SOLO_VI_V_START(solo_dev->vin_vstart) |
|
|
|
|
SOLO_VI_V_STOP(solo_dev->vin_vstart +
|
|
|
|
solo_dev->video_vsize));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_ACT_I_S,
|
|
|
|
SOLO_VI_H_START(solo_dev->vout_hstart) |
|
|
|
|
SOLO_VI_V_START(solo_dev->vout_vstart) |
|
|
|
|
SOLO_VI_V_STOP(solo_dev->vout_vstart +
|
|
|
|
solo_dev->video_vsize));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_ACT_P,
|
|
|
|
SOLO_VI_H_START(0) |
|
|
|
|
SOLO_VI_V_START(1) |
|
|
|
|
SOLO_VI_V_STOP(SOLO_PROGRESSIVE_VSIZE));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_CH_FORMAT,
|
|
|
|
SOLO_VI_FD_SEL_MASK(0) | SOLO_VI_PROG_MASK(0));
|
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
/* On 6110, initialize mozaic darkness stength */
|
|
|
|
if (solo_dev->type == SOLO_DEV_6010)
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_FMT_CFG, 0);
|
|
|
|
else
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_FMT_CFG, 16 << 22);
|
|
|
|
|
2010-06-18 01:27:26 +08:00
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PAGE_SW, 2);
|
|
|
|
|
|
|
|
if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_CONFIG,
|
|
|
|
SOLO_VI_PB_USER_MODE);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_RANGE_HV,
|
|
|
|
SOLO_VI_PB_HSIZE(858) | SOLO_VI_PB_VSIZE(246));
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_ACT_V,
|
|
|
|
SOLO_VI_PB_VSTART(4) |
|
|
|
|
SOLO_VI_PB_VSTOP(4 + 240));
|
|
|
|
} else {
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_CONFIG,
|
|
|
|
SOLO_VI_PB_USER_MODE | SOLO_VI_PB_PAL);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_RANGE_HV,
|
|
|
|
SOLO_VI_PB_HSIZE(864) | SOLO_VI_PB_VSIZE(294));
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_ACT_V,
|
|
|
|
SOLO_VI_PB_VSTART(4) |
|
|
|
|
SOLO_VI_PB_VSTOP(4 + 288));
|
|
|
|
}
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_PB_ACT_H, SOLO_VI_PB_HSTART(16) |
|
|
|
|
SOLO_VI_PB_HSTOP(16 + 720));
|
|
|
|
}
|
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
static void solo_vout_config_cursor(struct solo_dev *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Load (blank) cursor bitmap mask (2bpp) */
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
solo_reg_write(dev, SOLO_VO_CURSOR_MASK(i), 0);
|
|
|
|
|
|
|
|
solo_reg_write(dev, SOLO_VO_CURSOR_POS, 0);
|
|
|
|
|
|
|
|
solo_reg_write(dev, SOLO_VO_CURSOR_CLR,
|
|
|
|
(0x80 << 24) | (0x80 << 16) | (0x10 << 8) | 0x80);
|
|
|
|
solo_reg_write(dev, SOLO_VO_CURSOR_CLR2, (0xe0 << 8) | 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void solo_vout_config(struct solo_dev *solo_dev)
|
2010-06-18 01:27:26 +08:00
|
|
|
{
|
|
|
|
solo_dev->vout_hstart = 6;
|
|
|
|
solo_dev->vout_vstart = 8;
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_FMT_ENC,
|
|
|
|
solo_dev->video_type |
|
|
|
|
SOLO_VO_USER_COLOR_SET_NAV |
|
2013-03-25 16:35:17 +08:00
|
|
|
SOLO_VO_USER_COLOR_SET_NAH |
|
2010-06-18 01:27:26 +08:00
|
|
|
SOLO_VO_NA_COLOR_Y(0) |
|
|
|
|
SOLO_VO_NA_COLOR_CB(0) |
|
|
|
|
SOLO_VO_NA_COLOR_CR(0));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_ACT_H,
|
|
|
|
SOLO_VO_H_START(solo_dev->vout_hstart) |
|
|
|
|
SOLO_VO_H_STOP(solo_dev->vout_hstart +
|
|
|
|
solo_dev->video_hsize));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_ACT_V,
|
|
|
|
SOLO_VO_V_START(solo_dev->vout_vstart) |
|
|
|
|
SOLO_VO_V_STOP(solo_dev->vout_vstart +
|
|
|
|
solo_dev->video_vsize));
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RANGE_HV,
|
|
|
|
SOLO_VO_H_LEN(solo_dev->video_hsize) |
|
|
|
|
SOLO_VO_V_LEN(solo_dev->video_vsize));
|
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
/* Border & background colors */
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BORDER_LINE_COLOR,
|
|
|
|
(0xa0 << 24) | (0x88 << 16) | (0xa0 << 8) | 0x88);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BORDER_FILL_COLOR,
|
|
|
|
(0x10 << 24) | (0x8f << 16) | (0x10 << 8) | 0x8f);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BKG_COLOR,
|
|
|
|
(16 << 24) | (128 << 16) | (16 << 8) | 128);
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_DISP_ERASE, SOLO_VO_DISP_ERASE_ON);
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_WIN_SW, 0);
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_ZOOM_CTRL, 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_FREEZE_CTRL, 0);
|
2010-06-18 01:27:26 +08:00
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_DISP_CTRL, SOLO_VO_DISP_ON |
|
|
|
|
SOLO_VO_DISP_ERASE_COUNT(8) |
|
2011-02-11 20:33:26 +08:00
|
|
|
SOLO_VO_DISP_BASE(SOLO_DISP_EXT_ADDR));
|
2010-06-18 01:27:26 +08:00
|
|
|
|
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
solo_vout_config_cursor(solo_dev);
|
2010-06-18 01:27:26 +08:00
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
/* Enable channels we support */
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_CH_ENA,
|
|
|
|
(1 << solo_dev->nr_chans) - 1);
|
2010-06-18 01:27:26 +08:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:38:20 +08:00
|
|
|
static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off,
|
2010-06-18 01:27:26 +08:00
|
|
|
u16 val, int reg_size)
|
|
|
|
{
|
2014-08-21 03:27:38 +08:00
|
|
|
__le16 *buf;
|
2013-09-12 19:25:36 +08:00
|
|
|
const int n = 64, size = n * sizeof(*buf);
|
|
|
|
int i, ret = 0;
|
2010-06-18 01:27:26 +08:00
|
|
|
|
2013-09-12 19:25:36 +08:00
|
|
|
buf = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
2013-03-15 22:17:12 +08:00
|
|
|
buf[i] = cpu_to_le16(val);
|
2010-06-18 01:27:26 +08:00
|
|
|
|
2013-09-12 19:25:36 +08:00
|
|
|
for (i = 0; i < reg_size; i += size) {
|
|
|
|
ret = solo_p2m_dma(solo_dev, 1, buf,
|
|
|
|
SOLO_MOTION_EXT_ADDR(solo_dev) + off + i,
|
|
|
|
size, 0, 0);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2010-06-18 01:27:26 +08:00
|
|
|
|
2013-09-12 19:25:36 +08:00
|
|
|
kfree(buf);
|
2010-06-18 01:27:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
int solo_set_motion_threshold(struct solo_dev *solo_dev, u8 ch, u16 val)
|
2010-06-18 01:27:26 +08:00
|
|
|
{
|
|
|
|
if (ch > solo_dev->nr_chans)
|
2013-03-25 16:35:17 +08:00
|
|
|
return -EINVAL;
|
2010-06-18 01:27:26 +08:00
|
|
|
|
2013-03-25 16:35:17 +08:00
|
|
|
return solo_dma_vin_region(solo_dev, SOLO_MOT_FLAG_AREA +
|
|
|
|
(ch * SOLO_MOT_THRESH_SIZE * 2),
|
|
|
|
val, SOLO_MOT_THRESH_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:43:14 +08:00
|
|
|
int solo_set_motion_block(struct solo_dev *solo_dev, u8 ch,
|
2014-06-10 18:37:30 +08:00
|
|
|
const u16 *thresholds)
|
2013-03-25 16:35:17 +08:00
|
|
|
{
|
2014-02-08 01:51:24 +08:00
|
|
|
const unsigned size = sizeof(u16) * 64;
|
2013-03-18 19:43:14 +08:00
|
|
|
u32 off = SOLO_MOT_FLAG_AREA + ch * SOLO_MOT_THRESH_SIZE * 2;
|
2014-08-21 03:27:38 +08:00
|
|
|
__le16 *buf;
|
2013-03-18 19:43:14 +08:00
|
|
|
int x, y;
|
|
|
|
int ret = 0;
|
2013-03-25 16:35:17 +08:00
|
|
|
|
2014-02-08 01:51:24 +08:00
|
|
|
buf = kzalloc(size, GFP_KERNEL);
|
2014-07-25 19:19:54 +08:00
|
|
|
if (buf == NULL)
|
|
|
|
return -ENOMEM;
|
2013-03-18 19:43:14 +08:00
|
|
|
for (y = 0; y < SOLO_MOTION_SZ; y++) {
|
|
|
|
for (x = 0; x < SOLO_MOTION_SZ; x++)
|
2014-06-10 18:37:30 +08:00
|
|
|
buf[x] = cpu_to_le16(thresholds[y * SOLO_MOTION_SZ + x]);
|
2013-03-18 19:43:14 +08:00
|
|
|
ret |= solo_p2m_dma(solo_dev, 1, buf,
|
2014-02-08 01:51:24 +08:00
|
|
|
SOLO_MOTION_EXT_ADDR(solo_dev) + off + y * size,
|
|
|
|
size, 0, 0);
|
2013-03-18 19:43:14 +08:00
|
|
|
}
|
2014-02-08 01:51:24 +08:00
|
|
|
kfree(buf);
|
2013-03-18 19:43:14 +08:00
|
|
|
return ret;
|
2010-06-18 01:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* First 8k is motion flag (512 bytes * 16). Following that is an 8k+8k
|
|
|
|
* threshold and working table for each channel. Atleast that's what the
|
2013-03-25 16:35:17 +08:00
|
|
|
* spec says. However, this code (taken from rdk) has some mystery 8k
|
2010-06-18 01:27:26 +08:00
|
|
|
* block right after the flag area, before the first thresh table. */
|
2011-02-11 20:38:20 +08:00
|
|
|
static void solo_motion_config(struct solo_dev *solo_dev)
|
2010-06-18 01:27:26 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < solo_dev->nr_chans; i++) {
|
|
|
|
/* Clear motion flag area */
|
|
|
|
solo_dma_vin_region(solo_dev, i * SOLO_MOT_FLAG_SIZE, 0x0000,
|
|
|
|
SOLO_MOT_FLAG_SIZE);
|
|
|
|
|
|
|
|
/* Clear working cache table */
|
|
|
|
solo_dma_vin_region(solo_dev, SOLO_MOT_FLAG_AREA +
|
2013-03-25 16:35:17 +08:00
|
|
|
(i * SOLO_MOT_THRESH_SIZE * 2) +
|
|
|
|
SOLO_MOT_THRESH_SIZE, 0x0000,
|
|
|
|
SOLO_MOT_THRESH_SIZE);
|
2010-06-18 01:27:26 +08:00
|
|
|
|
|
|
|
/* Set default threshold table */
|
|
|
|
solo_set_motion_threshold(solo_dev, i, SOLO_DEF_MOT_THRESH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default motion settings */
|
2010-11-05 10:51:17 +08:00
|
|
|
solo_reg_write(solo_dev, SOLO_VI_MOT_ADR, SOLO_VI_MOTION_EN(0) |
|
2010-06-18 01:27:26 +08:00
|
|
|
(SOLO_MOTION_EXT_ADDR(solo_dev) >> 16));
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_MOT_CTRL,
|
|
|
|
SOLO_VI_MOTION_FRAME_COUNT(3) |
|
|
|
|
SOLO_VI_MOTION_SAMPLE_LENGTH(solo_dev->video_hsize / 16)
|
2013-03-25 16:35:17 +08:00
|
|
|
/* | SOLO_VI_MOTION_INTR_START_STOP */
|
|
|
|
| SOLO_VI_MOTION_SAMPLE_COUNT(10));
|
2010-06-18 01:27:26 +08:00
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_MOTION_BAR, 0);
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:38:20 +08:00
|
|
|
int solo_disp_init(struct solo_dev *solo_dev)
|
2010-06-18 01:27:26 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
solo_dev->video_hsize = 704;
|
2013-03-15 23:53:17 +08:00
|
|
|
if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) {
|
2010-06-18 01:27:26 +08:00
|
|
|
solo_dev->video_vsize = 240;
|
|
|
|
solo_dev->fps = 30;
|
|
|
|
} else {
|
|
|
|
solo_dev->video_vsize = 288;
|
|
|
|
solo_dev->fps = 25;
|
|
|
|
}
|
|
|
|
|
|
|
|
solo_vin_config(solo_dev);
|
|
|
|
solo_motion_config(solo_dev);
|
2013-03-25 16:35:17 +08:00
|
|
|
solo_vout_config(solo_dev);
|
2010-06-18 01:27:26 +08:00
|
|
|
|
|
|
|
for (i = 0; i < solo_dev->nr_chans; i++)
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_WIN_ON(i), 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:38:20 +08:00
|
|
|
void solo_disp_exit(struct solo_dev *solo_dev)
|
2010-06-18 01:27:26 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_DISP_CTRL, 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_ZOOM_CTRL, 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_FREEZE_CTRL, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < solo_dev->nr_chans; i++) {
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL0(i), 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL1(i), 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VI_WIN_ON(i), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set default border */
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BORDER_X(i), 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BORDER_Y(i), 0);
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BORDER_LINE_MASK, 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_BORDER_FILL_MASK, 0);
|
|
|
|
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_CTRL(0), 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_START(0), 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_STOP(0), 0);
|
2010-11-10 21:39:33 +08:00
|
|
|
|
2010-06-18 01:27:26 +08:00
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_CTRL(1), 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_START(1), 0);
|
|
|
|
solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_STOP(1), 0);
|
|
|
|
}
|