/*
* Driver for the NXP SAA7164 PCIe bridge
*
* Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "saa7164.h"
#define ENCODER_MAX_BITRATE 6500000
#define ENCODER_MIN_BITRATE 1000000
#define ENCODER_DEF_BITRATE 5000000
/*
* This is a dummy non-zero value for the sizeimage field of v4l2_pix_format.
* It is not actually used for anything since this driver does not support
* stream I/O, only read(), and because this driver produces an MPEG stream
* and not discrete frames. But the V4L2 spec doesn't allow for this value
* to be 0, so set it to 0x10000 instead.
*
* If we ever change this driver to support stream I/O, then this field
* will be the size of the streaming buffers.
*/
#define SAA7164_SIZEIMAGE (0x10000)
static struct saa7164_tvnorm saa7164_tvnorms[] = {
{
.name = "NTSC-M",
.id = V4L2_STD_NTSC_M,
}, {
.name = "NTSC-JP",
.id = V4L2_STD_NTSC_M_JP,
}
};
/* Take the encoder configuration form the port struct and
* flush it to the hardware.
*/
static void saa7164_encoder_configure(struct saa7164_port *port)
{
struct saa7164_dev *dev = port->dev;
dprintk(DBGLVL_ENC, "%s()\n", __func__);
port->encoder_params.width = port->width;
port->encoder_params.height = port->height;
port->encoder_params.is_50hz =
(port->encodernorm.id & V4L2_STD_625_50) != 0;
/* Set up the DIF (enable it) for analog mode by default */
saa7164_api_initialize_dif(port);
/* Configure the correct video standard */
saa7164_api_configure_dif(port, port->encodernorm.id);
/* Ensure the audio decoder is correct configured */
saa7164_api_set_audio_std(port);
}
static int saa7164_encoder_buffers_dealloc(struct saa7164_port *port)
{
struct list_head *c, *n, *p, *q, *l, *v;
struct saa7164_dev *dev = port->dev;
struct saa7164_buffer *buf;
struct saa7164_user_buffer *ubuf;
/* Remove any allocated buffers */
mutex_lock(&port->dmaqueue_lock);
dprintk(DBGLVL_ENC, "%s(port=%d) dmaqueue\n", __func__, port->nr);
list_for_each_safe(c, n, &port->dmaqueue.list) {
buf = list_entry(c, struct saa7164_buffer, list);
list_del(c);
saa7164_buffer_dealloc(buf);
}
dprintk(DBGLVL_ENC, "%s(port=%d) used\n", __func__, port->nr);
list_for_each_safe(p, q, &port->list_buf_used.list) {
ubuf = list_entry(p, struct saa7164_user_buffer, list);
list_del(p);
saa7164_buffer_dealloc_user(ubuf);
}
dprintk(DBGLVL_ENC, "%s(port=%d) free\n", __func__, port->nr);
list_for_each_safe(l, v, &port->list_buf_free.list) {
ubuf = list_entry(l, struct saa7164_user_buffer, list);
list_del(l);
saa7164_buffer_dealloc_user(ubuf);
}
mutex_unlock(&port->dmaqueue_lock);
dprintk(DBGLVL_ENC, "%s(port=%d) done\n", __func__, port->nr);
return 0;
}
/* Dynamic buffer switch at encoder start time */
static int saa7164_encoder_buffers_alloc(struct saa7164_port *port)
{
struct saa7164_dev *dev