2007-07-20 06:29:43 -06:00
|
|
|
/*
|
|
|
|
On Screen Display cx23415 Framebuffer driver
|
|
|
|
|
|
|
|
This module presents the cx23415 OSD (onscreen display) framebuffer memory
|
|
|
|
as a standard Linux /dev/fb style framebuffer device. The framebuffer has
|
2007-07-20 07:16:03 -06:00
|
|
|
support for 8, 16 & 32 bpp packed pixel formats with alpha channel. In 16bpp
|
2007-07-20 06:29:43 -06:00
|
|
|
mode, there is a choice of a three color depths (12, 15 or 16 bits), but no
|
|
|
|
local alpha. The colorspace is selectable between rgb & yuv.
|
|
|
|
Depending on the TV standard configured in the ivtv module at load time,
|
|
|
|
the initial resolution is either 640x400 (NTSC) or 640x480 (PAL) at 8bpp.
|
|
|
|
Video timings are locked to ensure a vertical refresh rate of 50Hz (PAL)
|
|
|
|
or 59.94 (NTSC)
|
|
|
|
|
|
|
|
Copyright (c) 2003 Matt T. Yourst <yourst@yourst.com>
|
|
|
|
|
|
|
|
Derived from drivers/video/vesafb.c
|
|
|
|
Portions (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
|
|
|
|
|
|
|
|
2.6 kernel port:
|
|
|
|
Copyright (C) 2004 Matthias Badaire
|
|
|
|
|
|
|
|
Copyright (C) 2004 Chris Kennedy <c@groovy.org>
|
|
|
|
|
|
|
|
Copyright (C) 2006 Ian Armstrong <ian@iarmst.demon.co.uk>
|
|
|
|
|
|
|
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fb.h>
|
2007-08-26 03:04:10 -06:00
|
|
|
#include <linux/ivtvfb.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_MTRR
|
|
|
|
#include <asm/mtrr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ivtv-driver.h"
|
2008-11-29 15:38:23 -07:00
|
|
|
#include "ivtv-cards.h"
|
2008-10-19 15:58:26 -06:00
|
|
|
#include "ivtv-i2c.h"
|
2007-07-20 06:29:43 -06:00
|
|
|
#include "ivtv-udma.h"
|
|
|
|
#include "ivtv-mailbox.h"
|
2010-06-12 10:41:57 -06:00
|
|
|
#include "ivtv-firmware.h"
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* card parameters */
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_card_id = -1;
|
|
|
|
static int ivtvfb_debug = 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
static int osd_laced;
|
|
|
|
static int osd_depth;
|
|
|
|
static int osd_upper;
|
|
|
|
static int osd_left;
|
|
|
|
static int osd_yres;
|
|
|
|
static int osd_xres;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
module_param(ivtvfb_card_id, int, 0444);
|
|
|
|
module_param_named(debug,ivtvfb_debug, int, 0644);
|
2007-07-20 06:29:43 -06:00
|
|
|
module_param(osd_laced, bool, 0444);
|
|
|
|
module_param(osd_depth, int, 0444);
|
|
|
|
module_param(osd_upper, int, 0444);
|
|
|
|
module_param(osd_left, int, 0444);
|
|
|
|
module_param(osd_yres, int, 0444);
|
|
|
|
module_param(osd_xres, int, 0444);
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
MODULE_PARM_DESC(ivtvfb_card_id,
|
2007-07-20 06:29:43 -06:00
|
|
|
"Only use framebuffer of the specified ivtv card (0-31)\n"
|
|
|
|
"\t\t\tdefault -1: initialize all available framebuffers");
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(debug,
|
|
|
|
"Debug level (bitmask). Default: errors only\n"
|
|
|
|
"\t\t\t(debug = 3 gives full debugging)");
|
|
|
|
|
|
|
|
/* Why upper, left, xres, yres, depth, laced ? To match terminology used
|
|
|
|
by fbset.
|
|
|
|
Why start at 1 for left & upper coordinate ? Because X doesn't allow 0 */
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(osd_laced,
|
|
|
|
"Interlaced mode\n"
|
|
|
|
"\t\t\t0=off\n"
|
|
|
|
"\t\t\t1=on\n"
|
|
|
|
"\t\t\tdefault off");
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(osd_depth,
|
2007-07-20 07:16:03 -06:00
|
|
|
"Bits per pixel - 8, 16, 32\n"
|
2007-07-20 06:29:43 -06:00
|
|
|
"\t\t\tdefault 8");
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(osd_upper,
|
|
|
|
"Vertical start position\n"
|
|
|
|
"\t\t\tdefault 0 (Centered)");
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(osd_left,
|
|
|
|
"Horizontal start position\n"
|
|
|
|
"\t\t\tdefault 0 (Centered)");
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(osd_yres,
|
|
|
|
"Display height\n"
|
|
|
|
"\t\t\tdefault 480 (PAL)\n"
|
|
|
|
"\t\t\t 400 (NTSC)");
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(osd_xres,
|
|
|
|
"Display width\n"
|
|
|
|
"\t\t\tdefault 640");
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil, John Harvey, Ian Armstrong");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
#define IVTVFB_DBGFLG_WARN (1 << 0)
|
|
|
|
#define IVTVFB_DBGFLG_INFO (1 << 1)
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
#define IVTVFB_DEBUG(x, type, fmt, args...) \
|
2007-07-20 06:29:43 -06:00
|
|
|
do { \
|
2007-08-28 00:24:31 -06:00
|
|
|
if ((x) & ivtvfb_debug) \
|
2008-11-29 15:38:23 -07:00
|
|
|
printk(KERN_INFO "ivtvfb%d " type ": " fmt, itv->instance , ## args); \
|
2007-07-20 06:29:43 -06:00
|
|
|
} while (0)
|
2007-08-28 00:24:31 -06:00
|
|
|
#define IVTVFB_DEBUG_WARN(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_WARN, "warning", fmt , ## args)
|
|
|
|
#define IVTVFB_DEBUG_INFO(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_INFO, "info", fmt , ## args)
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Standard kernel messages */
|
2008-11-29 15:38:23 -07:00
|
|
|
#define IVTVFB_ERR(fmt, args...) printk(KERN_ERR "ivtvfb%d: " fmt, itv->instance , ## args)
|
|
|
|
#define IVTVFB_WARN(fmt, args...) printk(KERN_WARNING "ivtvfb%d: " fmt, itv->instance , ## args)
|
|
|
|
#define IVTVFB_INFO(fmt, args...) printk(KERN_INFO "ivtvfb%d: " fmt, itv->instance , ## args)
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#define IVTV_OSD_MAX_WIDTH 720
|
|
|
|
#define IVTV_OSD_MAX_HEIGHT 576
|
|
|
|
|
|
|
|
#define IVTV_OSD_BPP_8 0x00
|
|
|
|
#define IVTV_OSD_BPP_16_444 0x03
|
|
|
|
#define IVTV_OSD_BPP_16_555 0x02
|
|
|
|
#define IVTV_OSD_BPP_16_565 0x01
|
|
|
|
#define IVTV_OSD_BPP_32 0x04
|
|
|
|
|
|
|
|
struct osd_info {
|
|
|
|
/* Physical base address */
|
|
|
|
unsigned long video_pbase;
|
|
|
|
/* Relative base address (relative to start of decoder memory) */
|
|
|
|
u32 video_rbase;
|
|
|
|
/* Mapped base address */
|
|
|
|
volatile char __iomem *video_vbase;
|
|
|
|
/* Buffer size */
|
|
|
|
u32 video_buffer_size;
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTRR
|
|
|
|
/* video_base rounded down as required by hardware MTRRs */
|
|
|
|
unsigned long fb_start_aligned_physaddr;
|
|
|
|
/* video_base rounded up as required by hardware MTRRs */
|
|
|
|
unsigned long fb_end_aligned_physaddr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Store the buffer offset */
|
|
|
|
int set_osd_coords_x;
|
|
|
|
int set_osd_coords_y;
|
|
|
|
|
|
|
|
/* Current dimensions (NOT VISIBLE SIZE!) */
|
|
|
|
int display_width;
|
|
|
|
int display_height;
|
|
|
|
int display_byte_stride;
|
|
|
|
|
|
|
|
/* Current bits per pixel */
|
|
|
|
int bits_per_pixel;
|
|
|
|
int bytes_per_pixel;
|
|
|
|
|
|
|
|
/* Frame buffer stuff */
|
|
|
|
struct fb_info ivtvfb_info;
|
|
|
|
struct fb_var_screeninfo ivtvfb_defined;
|
|
|
|
struct fb_fix_screeninfo ivtvfb_fix;
|
2010-06-12 10:41:57 -06:00
|
|
|
|
|
|
|
/* Used for a warm start */
|
|
|
|
struct fb_var_screeninfo fbvar_cur;
|
|
|
|
int blank_cur;
|
|
|
|
u32 palette_cur[256];
|
|
|
|
u32 pan_cur;
|
2007-07-20 06:29:43 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ivtv_osd_coords {
|
|
|
|
unsigned long offset;
|
|
|
|
unsigned long max_offset;
|
|
|
|
int pixel_stride;
|
|
|
|
int lines;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* ivtv API calls for framebuffer related support */
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_get_framebuffer(struct ivtv *itv, u32 *fbbase,
|
2007-07-20 06:29:43 -06:00
|
|
|
u32 *fblength)
|
|
|
|
{
|
|
|
|
u32 data[CX2341X_MBOX_MAX_DATA];
|
|
|
|
int rc;
|
|
|
|
|
2010-06-12 10:41:57 -06:00
|
|
|
ivtv_firmware_check(itv, "ivtvfb_get_framebuffer");
|
2007-07-20 06:29:43 -06:00
|
|
|
rc = ivtv_vapi_result(itv, data, CX2341X_OSD_GET_FRAMEBUFFER, 0);
|
|
|
|
*fbbase = data[0];
|
|
|
|
*fblength = data[1];
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_get_osd_coords(struct ivtv *itv,
|
2007-07-20 06:29:43 -06:00
|
|
|
struct ivtv_osd_coords *osd)
|
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
2007-07-20 06:29:43 -06:00
|
|
|
u32 data[CX2341X_MBOX_MAX_DATA];
|
|
|
|
|
|
|
|
ivtv_vapi_result(itv, data, CX2341X_OSD_GET_OSD_COORDS, 0);
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
osd->offset = data[0] - oi->video_rbase;
|
|
|
|
osd->max_offset = oi->display_width * oi->display_height * 4;
|
2007-07-20 06:29:43 -06:00
|
|
|
osd->pixel_stride = data[1];
|
|
|
|
osd->lines = data[2];
|
|
|
|
osd->x = data[3];
|
|
|
|
osd->y = data[4];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_set_osd_coords(struct ivtv *itv, const struct ivtv_osd_coords *osd)
|
2007-07-20 06:29:43 -06:00
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
|
|
|
|
|
|
|
oi->display_width = osd->pixel_stride;
|
|
|
|
oi->display_byte_stride = osd->pixel_stride * oi->bytes_per_pixel;
|
|
|
|
oi->set_osd_coords_x += osd->x;
|
|
|
|
oi->set_osd_coords_y = osd->y;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
return ivtv_vapi(itv, CX2341X_OSD_SET_OSD_COORDS, 5,
|
2007-07-20 07:16:03 -06:00
|
|
|
osd->offset + oi->video_rbase,
|
2007-07-20 06:29:43 -06:00
|
|
|
osd->pixel_stride,
|
|
|
|
osd->lines, osd->x, osd->y);
|
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_set_display_window(struct ivtv *itv, struct v4l2_rect *ivtv_window)
|
2007-07-20 06:29:43 -06:00
|
|
|
{
|
2011-05-29 18:33:17 -06:00
|
|
|
int osd_height_limit = itv->is_out_50hz ? 576 : 480;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Only fail if resolution too high, otherwise fudge the start coords. */
|
|
|
|
if ((ivtv_window->height > osd_height_limit) || (ivtv_window->width > IVTV_OSD_MAX_WIDTH))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Ensure we don't exceed display limits */
|
|
|
|
if (ivtv_window->top + ivtv_window->height > osd_height_limit) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("ivtv_ioctl_fb_set_display_window - Invalid height setting (%d, %d)\n",
|
2007-07-20 06:29:43 -06:00
|
|
|
ivtv_window->top, ivtv_window->height);
|
|
|
|
ivtv_window->top = osd_height_limit - ivtv_window->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ivtv_window->left + ivtv_window->width > IVTV_OSD_MAX_WIDTH) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("ivtv_ioctl_fb_set_display_window - Invalid width setting (%d, %d)\n",
|
2007-07-20 06:29:43 -06:00
|
|
|
ivtv_window->left, ivtv_window->width);
|
|
|
|
ivtv_window->left = IVTV_OSD_MAX_WIDTH - ivtv_window->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the OSD origin */
|
|
|
|
write_reg((ivtv_window->top << 16) | ivtv_window->left, 0x02a04);
|
|
|
|
|
|
|
|
/* How much to display */
|
|
|
|
write_reg(((ivtv_window->top+ivtv_window->height) << 16) | (ivtv_window->left+ivtv_window->width), 0x02a08);
|
|
|
|
|
|
|
|
/* Pass this info back the yuv handler */
|
|
|
|
itv->yuv_info.osd_vis_w = ivtv_window->width;
|
|
|
|
itv->yuv_info.osd_vis_h = ivtv_window->height;
|
|
|
|
itv->yuv_info.osd_x_offset = ivtv_window->left;
|
|
|
|
itv->yuv_info.osd_y_offset = ivtv_window->top;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,
|
2007-07-20 06:29:43 -06:00
|
|
|
unsigned long ivtv_dest_addr, void __user *userbuf,
|
|
|
|
int size_in_bytes)
|
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
int got_sig = 0;
|
|
|
|
|
|
|
|
mutex_lock(&itv->udma.lock);
|
|
|
|
/* Map User DMA */
|
|
|
|
if (ivtv_udma_setup(itv, ivtv_dest_addr, userbuf, size_in_bytes) <= 0) {
|
|
|
|
mutex_unlock(&itv->udma.lock);
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_WARN("ivtvfb_prep_dec_dma_to_device, "
|
2007-07-20 06:29:43 -06:00
|
|
|
"Error with get_user_pages: %d bytes, %d pages returned\n",
|
|
|
|
size_in_bytes, itv->udma.page_count);
|
|
|
|
|
|
|
|
/* get_user_pages must have failed completely */
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("ivtvfb_prep_dec_dma_to_device, %d bytes, %d pages\n",
|
2007-07-20 06:29:43 -06:00
|
|
|
size_in_bytes, itv->udma.page_count);
|
|
|
|
|
|
|
|
ivtv_udma_prepare(itv);
|
|
|
|
prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
|
|
|
|
/* if no UDMA is pending and no UDMA is in progress, then the DMA
|
|
|
|
is finished */
|
2009-05-02 08:10:23 -06:00
|
|
|
while (test_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags) ||
|
|
|
|
test_bit(IVTV_F_I_UDMA, &itv->i_flags)) {
|
2007-07-20 06:29:43 -06:00
|
|
|
/* don't interrupt if the DMA is in progress but break off
|
|
|
|
a still pending DMA. */
|
|
|
|
got_sig = signal_pending(current);
|
|
|
|
if (got_sig && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags))
|
|
|
|
break;
|
|
|
|
got_sig = 0;
|
|
|
|
schedule();
|
|
|
|
}
|
|
|
|
finish_wait(&itv->dma_waitq, &wait);
|
|
|
|
|
|
|
|
/* Unmap Last DMA Xfer */
|
|
|
|
ivtv_udma_unmap(itv);
|
|
|
|
mutex_unlock(&itv->udma.lock);
|
|
|
|
if (got_sig) {
|
|
|
|
IVTV_DEBUG_INFO("User stopped OSD\n");
|
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
|
2008-10-04 07:28:24 -06:00
|
|
|
return 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,
|
2007-07-20 07:16:03 -06:00
|
|
|
unsigned long dest_offset, int count)
|
2007-07-20 06:29:43 -06:00
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
2007-07-21 13:43:36 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Nothing to do */
|
|
|
|
if (count == 0) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("ivtvfb_prep_frame: Nothing to do. count = 0\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check Total FB Size */
|
2007-07-21 13:43:36 -06:00
|
|
|
if ((dest_offset + count) > oi->video_buffer_size) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_WARN("ivtvfb_prep_frame: Overflowing the framebuffer %ld, only %d available\n",
|
2007-07-21 13:43:36 -06:00
|
|
|
dest_offset + count, oi->video_buffer_size);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -E2BIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not fatal, but will have undesirable results */
|
|
|
|
if ((unsigned long)source & 3)
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_WARN("ivtvfb_prep_frame: Source address not 32 bit aligned (0x%08lx)\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
(unsigned long)source);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
if (dest_offset & 3)
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_WARN("ivtvfb_prep_frame: Dest offset not 32 bit aligned (%ld)\n", dest_offset);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
if (count & 3)
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_WARN("ivtvfb_prep_frame: Count not a multiple of 4 (%d)\n", count);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Check Source */
|
|
|
|
if (!access_ok(VERIFY_READ, source + dest_offset, count)) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_WARN("Invalid userspace pointer 0x%08lx\n",
|
2007-07-20 06:29:43 -06:00
|
|
|
(unsigned long)source);
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("access_ok() failed for offset 0x%08lx source 0x%08lx count %d\n",
|
2007-07-20 06:29:43 -06:00
|
|
|
dest_offset, (unsigned long)source,
|
|
|
|
count);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OSD Address to send DMA to */
|
2007-08-23 03:32:46 -06:00
|
|
|
dest_offset += IVTV_DECODER_OFFSET + oi->video_rbase;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Fill Buffers */
|
2007-08-28 00:24:31 -06:00
|
|
|
return ivtvfb_prep_dec_dma_to_device(itv, dest_offset, source, count);
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
2008-05-12 08:53:10 -06:00
|
|
|
static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
|
2008-10-06 00:03:18 -06:00
|
|
|
size_t count, loff_t *ppos)
|
2008-05-12 08:53:10 -06:00
|
|
|
{
|
|
|
|
unsigned long p = *ppos;
|
|
|
|
void *dst;
|
|
|
|
int err = 0;
|
2008-10-04 07:28:24 -06:00
|
|
|
int dma_err;
|
2008-05-12 08:53:10 -06:00
|
|
|
unsigned long total_size;
|
|
|
|
struct ivtv *itv = (struct ivtv *) info->par;
|
|
|
|
unsigned long dma_offset =
|
|
|
|
IVTV_DECODER_OFFSET + itv->osd_info->video_rbase;
|
|
|
|
unsigned long dma_size;
|
|
|
|
u16 lead = 0, tail = 0;
|
|
|
|
|
|
|
|
if (info->state != FBINFO_STATE_RUNNING)
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
total_size = info->screen_size;
|
|
|
|
|
|
|
|
if (total_size == 0)
|
|
|
|
total_size = info->fix.smem_len;
|
|
|
|
|
|
|
|
if (p > total_size)
|
|
|
|
return -EFBIG;
|
|
|
|
|
|
|
|
if (count > total_size) {
|
|
|
|
err = -EFBIG;
|
|
|
|
count = total_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count + p > total_size) {
|
|
|
|
if (!err)
|
|
|
|
err = -ENOSPC;
|
|
|
|
count = total_size - p;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = (void __force *) (info->screen_base + p);
|
|
|
|
|
|
|
|
if (info->fbops->fb_sync)
|
|
|
|
info->fbops->fb_sync(info);
|
|
|
|
|
2008-10-04 07:28:24 -06:00
|
|
|
/* If transfer size > threshold and both src/dst
|
|
|
|
addresses are aligned, use DMA */
|
|
|
|
if (count >= 4096 &&
|
|
|
|
((unsigned long)buf & 3) == ((unsigned long)dst & 3)) {
|
|
|
|
/* Odd address = can't DMA. Align */
|
|
|
|
if ((unsigned long)dst & 3) {
|
|
|
|
lead = 4 - ((unsigned long)dst & 3);
|
|
|
|
if (copy_from_user(dst, buf, lead))
|
|
|
|
return -EFAULT;
|
|
|
|
buf += lead;
|
|
|
|
dst += lead;
|
2008-05-12 08:53:10 -06:00
|
|
|
}
|
2008-10-04 07:28:24 -06:00
|
|
|
/* DMA resolution is 32 bits */
|
|
|
|
if ((count - lead) & 3)
|
|
|
|
tail = (count - lead) & 3;
|
|
|
|
/* DMA the data */
|
|
|
|
dma_size = count - lead - tail;
|
|
|
|
dma_err = ivtvfb_prep_dec_dma_to_device(itv,
|
|
|
|
p + lead + dma_offset, (void __user *)buf, dma_size);
|
|
|
|
if (dma_err)
|
|
|
|
return dma_err;
|
|
|
|
dst += dma_size;
|
|
|
|
buf += dma_size;
|
|
|
|
/* Copy any leftover data */
|
|
|
|
if (tail && copy_from_user(dst, buf, tail))
|
|
|
|
return -EFAULT;
|
|
|
|
} else if (copy_from_user(dst, buf, count)) {
|
|
|
|
return -EFAULT;
|
2008-05-12 08:53:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!err)
|
|
|
|
*ppos += count;
|
|
|
|
|
|
|
|
return (err) ? err : count;
|
|
|
|
}
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
struct ivtv *itv = (struct ivtv *)info->par;
|
2007-07-20 07:16:03 -06:00
|
|
|
int rc = 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FBIOGET_VBLANK: {
|
|
|
|
struct fb_vblank vblank;
|
|
|
|
u32 trace;
|
|
|
|
|
2010-09-15 15:44:22 -06:00
|
|
|
memset(&vblank, 0, sizeof(struct fb_vblank));
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT |
|
|
|
|
FB_VBLANK_HAVE_VSYNC;
|
2010-03-13 16:37:25 -07:00
|
|
|
trace = read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16;
|
2011-05-29 18:33:17 -06:00
|
|
|
if (itv->is_out_50hz && trace > 312)
|
2008-10-04 07:28:24 -06:00
|
|
|
trace -= 312;
|
2011-05-29 18:33:17 -06:00
|
|
|
else if (itv->is_out_60hz && trace > 262)
|
2008-10-04 07:28:24 -06:00
|
|
|
trace -= 262;
|
|
|
|
if (trace == 1)
|
|
|
|
vblank.flags |= FB_VBLANK_VSYNCING;
|
2007-08-23 08:31:57 -06:00
|
|
|
vblank.count = itv->last_vsync_field;
|
2007-07-20 06:29:43 -06:00
|
|
|
vblank.vcount = trace;
|
|
|
|
vblank.hcount = 0;
|
|
|
|
if (copy_to_user((void __user *)arg, &vblank, sizeof(vblank)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
case FBIO_WAITFORVSYNC:
|
2007-07-20 06:29:43 -06:00
|
|
|
prepare_to_wait(&itv->vsync_waitq, &wait, TASK_INTERRUPTIBLE);
|
2008-10-04 07:28:24 -06:00
|
|
|
if (!schedule_timeout(msecs_to_jiffies(50)))
|
|
|
|
rc = -ETIMEDOUT;
|
2007-07-20 07:16:03 -06:00
|
|
|
finish_wait(&itv->vsync_waitq, &wait);
|
2007-07-20 06:29:43 -06:00
|
|
|
return rc;
|
|
|
|
|
2007-07-20 07:30:32 -06:00
|
|
|
case IVTVFB_IOC_DMA_FRAME: {
|
|
|
|
struct ivtvfb_dma_frame args;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("IVTVFB_IOC_DMA_FRAME\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
if (copy_from_user(&args, (void __user *)arg, sizeof(args)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
return ivtvfb_prep_frame(itv, cmd, args.source, args.dest_offset, args.count);
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Unknown ioctl %08x\n", cmd);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Framebuffer device handling */
|
|
|
|
|
|
|
|
static int ivtvfb_set_var(struct ivtv *itv, struct fb_var_screeninfo *var)
|
|
|
|
{
|
2007-07-21 13:43:36 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
2007-07-20 06:29:43 -06:00
|
|
|
struct ivtv_osd_coords ivtv_osd;
|
|
|
|
struct v4l2_rect ivtv_window;
|
2007-07-21 13:43:36 -06:00
|
|
|
int osd_mode = -1;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("ivtvfb_set_var\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Select color space */
|
|
|
|
if (var->nonstd) /* YUV */
|
2007-07-20 07:16:03 -06:00
|
|
|
write_reg(read_reg(0x02a00) | 0x0002000, 0x02a00);
|
2007-07-20 06:29:43 -06:00
|
|
|
else /* RGB */
|
2007-07-20 07:16:03 -06:00
|
|
|
write_reg(read_reg(0x02a00) & ~0x0002000, 0x02a00);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-21 13:43:36 -06:00
|
|
|
/* Set the color mode */
|
2007-07-20 06:29:43 -06:00
|
|
|
switch (var->bits_per_pixel) {
|
|
|
|
case 8:
|
2007-07-21 13:43:36 -06:00
|
|
|
osd_mode = IVTV_OSD_BPP_8;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
case 32:
|
2007-07-21 13:43:36 -06:00
|
|
|
osd_mode = IVTV_OSD_BPP_32;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
switch (var->green.length) {
|
|
|
|
case 4:
|
2007-07-21 13:43:36 -06:00
|
|
|
osd_mode = IVTV_OSD_BPP_16_444;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
case 5:
|
2007-07-21 13:43:36 -06:00
|
|
|
osd_mode = IVTV_OSD_BPP_16_555;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
case 6:
|
2007-07-21 13:43:36 -06:00
|
|
|
osd_mode = IVTV_OSD_BPP_16_565;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
default:
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("ivtvfb_set_var - Invalid bpp\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("ivtvfb_set_var - Invalid bpp\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
2007-10-12 05:15:41 -06:00
|
|
|
/* Set video mode. Although rare, the display can become scrambled even
|
|
|
|
if we don't change mode. Always 'bounce' to osd_mode via mode 0 */
|
|
|
|
if (osd_mode != -1) {
|
2007-07-21 13:43:36 -06:00
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_PIXEL_FORMAT, 1, 0);
|
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_PIXEL_FORMAT, 1, osd_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
oi->bits_per_pixel = var->bits_per_pixel;
|
|
|
|
oi->bytes_per_pixel = var->bits_per_pixel / 8;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Set the flicker filter */
|
|
|
|
switch (var->vmode & FB_VMODE_MASK) {
|
|
|
|
case FB_VMODE_NONINTERLACED: /* Filter on */
|
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_FLICKER_STATE, 1, 1);
|
|
|
|
break;
|
|
|
|
case FB_VMODE_INTERLACED: /* Filter off */
|
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_FLICKER_STATE, 1, 0);
|
|
|
|
break;
|
|
|
|
default:
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("ivtvfb_set_var - Invalid video mode\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the current osd info */
|
2007-08-28 00:24:31 -06:00
|
|
|
ivtvfb_get_osd_coords(itv, &ivtv_osd);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Now set the OSD to the size we want */
|
|
|
|
ivtv_osd.pixel_stride = var->xres_virtual;
|
|
|
|
ivtv_osd.lines = var->yres_virtual;
|
|
|
|
ivtv_osd.x = 0;
|
|
|
|
ivtv_osd.y = 0;
|
2007-08-28 00:24:31 -06:00
|
|
|
ivtvfb_set_osd_coords(itv, &ivtv_osd);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Can't seem to find the right API combo for this.
|
|
|
|
Use another function which does what we need through direct register access. */
|
|
|
|
ivtv_window.width = var->xres;
|
|
|
|
ivtv_window.height = var->yres;
|
|
|
|
|
|
|
|
/* Minimum margin cannot be 0, as X won't allow such a mode */
|
2010-06-12 10:41:57 -06:00
|
|
|
if (!var->upper_margin)
|
|
|
|
var->upper_margin++;
|
|
|
|
if (!var->left_margin)
|
|
|
|
var->left_margin++;
|
2007-07-20 06:29:43 -06:00
|
|
|
ivtv_window.top = var->upper_margin - 1;
|
|
|
|
ivtv_window.left = var->left_margin - 1;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
ivtvfb_set_display_window(itv, &ivtv_window);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
V4L/DVB (6717): ivtv: Initial merge of video48 yuv handling into the IVTV_IOC_DMA_FRAME framework
Previously, all yuv data written to /dev/video48 had only basic support with
no double buffering to avoid display tearing.
With this patch, yuv frames written to video48 are now handled by the existing
IVTV_IOC_DMA_FRAME framework. As such, the frames are hardware buffered to
avoid tearing, and honour scaling mode & field order options. Unlike the
proprietary IVTV_IOC_DMA_FRAME ioctl, all parameters are controlled by the
V4L2 API.
Due to mpeg & yuv output restrictions being different, their V4L2 output
controls have been separated. To control the yuv output, the V4L2 calls must
be done via video48.
If the ivtvfb module is loaded, there will be one side effect to this merge.
The yuv output window will be constrained to the visible framebuffer area. In
the event that a virtual framebuffer size is being used, the limit to the
output size will be the virtual dimensions, but only the portion that falls
within the currently visible area of the framebuffer will be shown.
Like the IVTV_IOC_DMA_FRAME ioctl, the supplied frames must be padded to 720
pixels wide. However the height must only be padded up the nearest multiple
of 32. This would mean an image of 102 lines must be padded to 128. As long
as the true source image size is given, the padding will not be visible in
the final output.
Signed-off-by: Ian Armstrong <ian@iarmst.demon.co.uk>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
2007-11-05 10:27:09 -07:00
|
|
|
/* Pass screen size back to yuv handler */
|
|
|
|
itv->yuv_info.osd_full_w = ivtv_osd.pixel_stride;
|
|
|
|
itv->yuv_info.osd_full_h = ivtv_osd.lines;
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
/* Force update of yuv registers */
|
|
|
|
itv->yuv_info.yuv_forced_update = 1;
|
|
|
|
|
2010-06-12 10:41:57 -06:00
|
|
|
/* Keep a copy of these settings */
|
|
|
|
memcpy(&oi->fbvar_cur, var, sizeof(oi->fbvar_cur));
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Display size: %dx%d (virtual %dx%d) @ %dbpp\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
var->xres, var->yres,
|
|
|
|
var->xres_virtual, var->yres_virtual,
|
|
|
|
var->bits_per_pixel);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Display position: %d, %d\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
var->left_margin, var->upper_margin);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Display filter: %s\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
(var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED ? "on" : "off");
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Color space: %s\n", var->nonstd ? "YUV" : "RGB");
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ivtvfb_get_fix(struct ivtv *itv, struct fb_fix_screeninfo *fix)
|
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("ivtvfb_get_fix\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
memset(fix, 0, sizeof(struct fb_fix_screeninfo));
|
2008-04-26 05:51:51 -06:00
|
|
|
strlcpy(fix->id, "cx23415 TV out", sizeof(fix->id));
|
2007-07-20 07:16:03 -06:00
|
|
|
fix->smem_start = oi->video_pbase;
|
|
|
|
fix->smem_len = oi->video_buffer_size;
|
2007-07-20 06:29:43 -06:00
|
|
|
fix->type = FB_TYPE_PACKED_PIXELS;
|
2007-07-20 07:16:03 -06:00
|
|
|
fix->visual = (oi->bits_per_pixel == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
|
2007-07-20 06:29:43 -06:00
|
|
|
fix->xpanstep = 1;
|
|
|
|
fix->ypanstep = 1;
|
|
|
|
fix->ywrapstep = 0;
|
2007-07-20 07:16:03 -06:00
|
|
|
fix->line_length = oi->display_byte_stride;
|
2007-07-20 06:29:43 -06:00
|
|
|
fix->accel = FB_ACCEL_NONE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the requested display mode, returning -EINVAL if we can't
|
|
|
|
handle it. */
|
|
|
|
|
|
|
|
static int _ivtvfb_check_var(struct fb_var_screeninfo *var, struct ivtv *itv)
|
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
2007-08-03 06:51:58 -06:00
|
|
|
int osd_height_limit;
|
|
|
|
u32 pixclock, hlimit, vlimit;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("ivtvfb_check_var\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-03 06:51:58 -06:00
|
|
|
/* Set base references for mode calcs. */
|
2011-05-29 18:33:17 -06:00
|
|
|
if (itv->is_out_50hz) {
|
2007-08-03 06:51:58 -06:00
|
|
|
pixclock = 84316;
|
|
|
|
hlimit = 776;
|
|
|
|
vlimit = 591;
|
|
|
|
osd_height_limit = 576;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pixclock = 83926;
|
|
|
|
hlimit = 776;
|
|
|
|
vlimit = 495;
|
|
|
|
osd_height_limit = 480;
|
|
|
|
}
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
if (var->bits_per_pixel == 8 || var->bits_per_pixel == 32) {
|
|
|
|
var->transp.offset = 24;
|
|
|
|
var->transp.length = 8;
|
|
|
|
var->red.offset = 16;
|
|
|
|
var->red.length = 8;
|
|
|
|
var->green.offset = 8;
|
|
|
|
var->green.length = 8;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 8;
|
|
|
|
}
|
|
|
|
else if (var->bits_per_pixel == 16) {
|
|
|
|
/* To find out the true mode, check green length */
|
|
|
|
switch (var->green.length) {
|
|
|
|
case 4:
|
|
|
|
var->red.offset = 8;
|
|
|
|
var->red.length = 4;
|
|
|
|
var->green.offset = 4;
|
|
|
|
var->green.length = 4;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 4;
|
2007-08-22 05:58:47 -06:00
|
|
|
var->transp.offset = 12;
|
|
|
|
var->transp.length = 1;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
var->red.offset = 10;
|
|
|
|
var->red.length = 5;
|
|
|
|
var->green.offset = 5;
|
|
|
|
var->green.length = 5;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 5;
|
2007-08-22 05:58:47 -06:00
|
|
|
var->transp.offset = 15;
|
|
|
|
var->transp.length = 1;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
var->red.offset = 11;
|
|
|
|
var->red.length = 5;
|
|
|
|
var->green.offset = 5;
|
|
|
|
var->green.length = 6;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 5;
|
2007-08-22 05:58:47 -06:00
|
|
|
var->transp.offset = 0;
|
|
|
|
var->transp.length = 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid colour mode: %d\n", var->bits_per_pixel);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the resolution */
|
2007-10-17 12:09:56 -06:00
|
|
|
if (var->xres > IVTV_OSD_MAX_WIDTH || var->yres > osd_height_limit) {
|
|
|
|
IVTVFB_DEBUG_WARN("Invalid resolution: %dx%d\n",
|
|
|
|
var->xres, var->yres);
|
|
|
|
return -EINVAL;
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
2007-10-17 12:09:56 -06:00
|
|
|
/* Max horizontal size is 1023 @ 32bpp, 2046 & 16bpp, 4092 @ 8bpp */
|
|
|
|
if (var->xres_virtual > 4095 / (var->bits_per_pixel / 8) ||
|
|
|
|
var->xres_virtual * var->yres_virtual * (var->bits_per_pixel / 8) > oi->video_buffer_size ||
|
|
|
|
var->xres_virtual < var->xres ||
|
|
|
|
var->yres_virtual < var->yres) {
|
|
|
|
IVTVFB_DEBUG_WARN("Invalid virtual resolution: %dx%d\n",
|
|
|
|
var->xres_virtual, var->yres_virtual);
|
|
|
|
return -EINVAL;
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Some extra checks if in 8 bit mode */
|
|
|
|
if (var->bits_per_pixel == 8) {
|
|
|
|
/* Width must be a multiple of 4 */
|
|
|
|
if (var->xres & 3) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid resolution for 8bpp: %d\n", var->xres);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (var->xres_virtual & 3) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid virtual resolution for 8bpp: %d)\n", var->xres_virtual);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (var->bits_per_pixel == 16) {
|
|
|
|
/* Width must be a multiple of 2 */
|
|
|
|
if (var->xres & 1) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid resolution for 16bpp: %d\n", var->xres);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (var->xres_virtual & 1) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid virtual resolution for 16bpp: %d)\n", var->xres_virtual);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check the offsets */
|
|
|
|
if (var->xoffset >= var->xres_virtual || var->yoffset >= var->yres_virtual) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid offset: %d (%d) %d (%d)\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
var->xoffset, var->xres_virtual, var->yoffset, var->yres_virtual);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check pixel format */
|
|
|
|
if (var->nonstd > 1) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid nonstd % d\n", var->nonstd);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check video mode */
|
|
|
|
if (((var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED) &&
|
|
|
|
((var->vmode & FB_VMODE_MASK) != FB_VMODE_INTERLACED)) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_WARN("Invalid video mode: %d\n", var->vmode & FB_VMODE_MASK);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the left & upper margins
|
|
|
|
If the margins are too large, just center the screen
|
|
|
|
(enforcing margins causes too many problems) */
|
|
|
|
|
2011-05-29 18:33:17 -06:00
|
|
|
if (var->left_margin + var->xres > IVTV_OSD_MAX_WIDTH + 1)
|
2007-07-20 06:29:43 -06:00
|
|
|
var->left_margin = 1 + ((IVTV_OSD_MAX_WIDTH - var->xres) / 2);
|
2011-05-29 18:33:17 -06:00
|
|
|
|
|
|
|
if (var->upper_margin + var->yres > (itv->is_out_50hz ? 577 : 481))
|
|
|
|
var->upper_margin = 1 + (((itv->is_out_50hz ? 576 : 480) -
|
|
|
|
var->yres) / 2);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Maintain overall 'size' for a constant refresh rate */
|
2007-08-03 06:51:58 -06:00
|
|
|
var->right_margin = hlimit - var->left_margin - var->xres;
|
|
|
|
var->lower_margin = vlimit - var->upper_margin - var->yres;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Fixed sync times */
|
|
|
|
var->hsync_len = 24;
|
|
|
|
var->vsync_len = 2;
|
|
|
|
|
|
|
|
/* Non-interlaced / interlaced mode is used to switch the OSD filter
|
|
|
|
on or off. Adjust the clock timings to maintain a constant
|
|
|
|
vertical refresh rate. */
|
|
|
|
if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED)
|
2007-08-03 06:51:58 -06:00
|
|
|
var->pixclock = pixclock / 2;
|
|
|
|
else
|
|
|
|
var->pixclock = pixclock;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2008-06-22 08:57:31 -06:00
|
|
|
itv->osd_rect.width = var->xres;
|
|
|
|
itv->osd_rect.height = var->yres;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Display size: %dx%d (virtual %dx%d) @ %dbpp\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
var->xres, var->yres,
|
|
|
|
var->xres_virtual, var->yres_virtual,
|
2007-07-20 06:29:43 -06:00
|
|
|
var->bits_per_pixel);
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Display position: %d, %d\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
var->left_margin, var->upper_margin);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Display filter: %s\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
(var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED ? "on" : "off");
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Color space: %s\n", var->nonstd ? "YUV" : "RGB");
|
2007-07-20 06:29:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ivtvfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct ivtv *itv = (struct ivtv *) info->par;
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("ivtvfb_check_var\n");
|
2007-07-20 07:16:03 -06:00
|
|
|
return _ivtvfb_check_var(var, itv);
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ivtvfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
|
|
|
|
{
|
|
|
|
u32 osd_pan_index;
|
|
|
|
struct ivtv *itv = (struct ivtv *) info->par;
|
|
|
|
|
2011-05-28 19:15:41 -06:00
|
|
|
if (var->yoffset + info->var.yres > info->var.yres_virtual ||
|
|
|
|
var->xoffset + info->var.xres > info->var.xres_virtual)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-05-25 03:41:23 -06:00
|
|
|
osd_pan_index = var->yoffset * info->fix.line_length
|
|
|
|
+ var->xoffset * info->var.bits_per_pixel / 8;
|
2007-07-20 07:16:03 -06:00
|
|
|
write_reg(osd_pan_index, 0x02A0C);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Pass this info back the yuv handler */
|
|
|
|
itv->yuv_info.osd_x_pan = var->xoffset;
|
|
|
|
itv->yuv_info.osd_y_pan = var->yoffset;
|
|
|
|
/* Force update of yuv registers */
|
|
|
|
itv->yuv_info.yuv_forced_update = 1;
|
2010-06-12 10:41:57 -06:00
|
|
|
/* Remember this value */
|
|
|
|
itv->osd_info->pan_cur = osd_pan_index;
|
2007-07-20 06:29:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ivtvfb_set_par(struct fb_info *info)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct ivtv *itv = (struct ivtv *) info->par;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("ivtvfb_set_par\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
rc = ivtvfb_set_var(itv, &info->var);
|
|
|
|
ivtvfb_pan_display(&info->var, info);
|
2007-07-20 07:16:03 -06:00
|
|
|
ivtvfb_get_fix(itv, &info->fix);
|
2010-06-12 10:41:57 -06:00
|
|
|
ivtv_firmware_check(itv, "ivtvfb_set_par");
|
2007-07-20 06:29:43 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ivtvfb_setcolreg(unsigned regno, unsigned red, unsigned green,
|
|
|
|
unsigned blue, unsigned transp,
|
|
|
|
struct fb_info *info)
|
|
|
|
{
|
|
|
|
u32 color, *palette;
|
2007-07-20 07:16:03 -06:00
|
|
|
struct ivtv *itv = (struct ivtv *)info->par;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
if (regno >= info->cmap.len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
color = ((transp & 0xFF00) << 16) |((red & 0xFF00) << 8) | (green & 0xFF00) | ((blue & 0xFF00) >> 8);
|
|
|
|
if (info->var.bits_per_pixel <= 8) {
|
|
|
|
write_reg(regno, 0x02a30);
|
|
|
|
write_reg(color, 0x02a34);
|
2010-06-12 10:41:57 -06:00
|
|
|
itv->osd_info->palette_cur[regno] = color;
|
2007-07-20 07:16:03 -06:00
|
|
|
return 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
2007-07-20 07:16:03 -06:00
|
|
|
if (regno >= 16)
|
|
|
|
return -EINVAL;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
palette = info->pseudo_palette;
|
|
|
|
if (info->var.bits_per_pixel == 16) {
|
|
|
|
switch (info->var.green.length) {
|
|
|
|
case 4:
|
|
|
|
color = ((red & 0xf000) >> 4) |
|
|
|
|
((green & 0xf000) >> 8) |
|
|
|
|
((blue & 0xf000) >> 12);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
color = ((red & 0xf800) >> 1) |
|
|
|
|
((green & 0xf800) >> 6) |
|
|
|
|
((blue & 0xf800) >> 11);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
color = (red & 0xf800 ) |
|
|
|
|
((green & 0xfc00) >> 5) |
|
|
|
|
((blue & 0xf800) >> 11);
|
|
|
|
break;
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
}
|
2007-07-20 07:16:03 -06:00
|
|
|
palette[regno] = color;
|
2007-07-20 06:29:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't really support blanking. All this does is enable or
|
|
|
|
disable the OSD. */
|
|
|
|
static int ivtvfb_blank(int blank_mode, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct ivtv *itv = (struct ivtv *)info->par;
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_DEBUG_INFO("Set blanking mode : %d\n", blank_mode);
|
2007-07-20 06:29:43 -06:00
|
|
|
switch (blank_mode) {
|
|
|
|
case FB_BLANK_UNBLANK:
|
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 1);
|
2008-11-29 15:38:23 -07:00
|
|
|
ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
|
2007-07-20 06:29:43 -06:00
|
|
|
break;
|
|
|
|
case FB_BLANK_NORMAL:
|
|
|
|
case FB_BLANK_HSYNC_SUSPEND:
|
|
|
|
case FB_BLANK_VSYNC_SUSPEND:
|
2008-10-19 15:58:26 -06:00
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0);
|
2008-11-29 15:38:23 -07:00
|
|
|
ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
|
2008-10-19 15:58:26 -06:00
|
|
|
break;
|
2007-07-20 06:29:43 -06:00
|
|
|
case FB_BLANK_POWERDOWN:
|
2008-11-29 15:38:23 -07:00
|
|
|
ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 0);
|
2007-07-20 06:29:43 -06:00
|
|
|
ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0);
|
|
|
|
break;
|
|
|
|
}
|
2010-06-12 10:41:57 -06:00
|
|
|
itv->osd_info->blank_cur = blank_mode;
|
2007-07-20 06:29:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fb_ops ivtvfb_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-05-12 08:53:10 -06:00
|
|
|
.fb_write = ivtvfb_write,
|
2007-07-20 06:29:43 -06:00
|
|
|
.fb_check_var = ivtvfb_check_var,
|
|
|
|
.fb_set_par = ivtvfb_set_par,
|
|
|
|
.fb_setcolreg = ivtvfb_setcolreg,
|
|
|
|
.fb_fillrect = cfb_fillrect,
|
|
|
|
.fb_copyarea = cfb_copyarea,
|
|
|
|
.fb_imageblit = cfb_imageblit,
|
|
|
|
.fb_cursor = NULL,
|
|
|
|
.fb_ioctl = ivtvfb_ioctl,
|
|
|
|
.fb_pan_display = ivtvfb_pan_display,
|
|
|
|
.fb_blank = ivtvfb_blank,
|
|
|
|
};
|
|
|
|
|
2010-06-12 10:41:57 -06:00
|
|
|
/* Restore hardware after firmware restart */
|
|
|
|
static void ivtvfb_restore(struct ivtv *itv)
|
|
|
|
{
|
|
|
|
struct osd_info *oi = itv->osd_info;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ivtvfb_set_var(itv, &oi->fbvar_cur);
|
|
|
|
ivtvfb_blank(oi->blank_cur, &oi->ivtvfb_info);
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
write_reg(i, 0x02a30);
|
|
|
|
write_reg(oi->palette_cur[i], 0x02a34);
|
|
|
|
}
|
|
|
|
write_reg(oi->pan_cur, 0x02a0c);
|
|
|
|
}
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup our initial video mode */
|
|
|
|
static int ivtvfb_init_vidmode(struct ivtv *itv)
|
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
2007-07-20 06:29:43 -06:00
|
|
|
struct v4l2_rect start_window;
|
2007-07-20 07:16:03 -06:00
|
|
|
int max_height;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Color mode */
|
|
|
|
|
2007-10-17 12:09:56 -06:00
|
|
|
if (osd_depth != 8 && osd_depth != 16 && osd_depth != 32)
|
|
|
|
osd_depth = 8;
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->bits_per_pixel = osd_depth;
|
|
|
|
oi->bytes_per_pixel = oi->bits_per_pixel / 8;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Horizontal size & position */
|
|
|
|
|
2007-10-17 12:09:56 -06:00
|
|
|
if (osd_xres > 720)
|
|
|
|
osd_xres = 720;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Must be a multiple of 4 for 8bpp & 2 for 16bpp */
|
|
|
|
if (osd_depth == 8)
|
|
|
|
osd_xres &= ~3;
|
|
|
|
else if (osd_depth == 16)
|
|
|
|
osd_xres &= ~1;
|
|
|
|
|
2007-10-17 12:09:56 -06:00
|
|
|
start_window.width = osd_xres ? osd_xres : 640;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Check horizontal start (osd_left). */
|
|
|
|
if (osd_left && osd_left + start_window.width > 721) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("Invalid osd_left - assuming default\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
osd_left = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hardware coords start at 0, user coords start at 1. */
|
2007-07-20 07:16:03 -06:00
|
|
|
osd_left--;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2011-05-29 18:33:17 -06:00
|
|
|
start_window.left = osd_left >= 0 ?
|
|
|
|
osd_left : ((IVTV_OSD_MAX_WIDTH - start_window.width) / 2);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->display_byte_stride =
|
|
|
|
start_window.width * oi->bytes_per_pixel;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Vertical size & position */
|
|
|
|
|
2011-05-29 18:33:17 -06:00
|
|
|
max_height = itv->is_out_50hz ? 576 : 480;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
if (osd_yres > max_height)
|
|
|
|
osd_yres = max_height;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2011-05-29 18:33:17 -06:00
|
|
|
start_window.height = osd_yres ?
|
|
|
|
osd_yres : itv->is_out_50hz ? 480 : 400;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Check vertical start (osd_upper). */
|
|
|
|
if (osd_upper + start_window.height > max_height + 1) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("Invalid osd_upper - assuming default\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
osd_upper = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hardware coords start at 0, user coords start at 1. */
|
2007-07-20 07:16:03 -06:00
|
|
|
osd_upper--;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
start_window.top = osd_upper >= 0 ? osd_upper : ((max_height - start_window.height) / 2);
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->display_width = start_window.width;
|
|
|
|
oi->display_height = start_window.height;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Generate a valid fb_var_screeninfo */
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->ivtvfb_defined.xres = oi->display_width;
|
|
|
|
oi->ivtvfb_defined.yres = oi->display_height;
|
|
|
|
oi->ivtvfb_defined.xres_virtual = oi->display_width;
|
|
|
|
oi->ivtvfb_defined.yres_virtual = oi->display_height;
|
|
|
|
oi->ivtvfb_defined.bits_per_pixel = oi->bits_per_pixel;
|
|
|
|
oi->ivtvfb_defined.vmode = (osd_laced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED);
|
|
|
|
oi->ivtvfb_defined.left_margin = start_window.left + 1;
|
|
|
|
oi->ivtvfb_defined.upper_margin = start_window.top + 1;
|
|
|
|
oi->ivtvfb_defined.accel_flags = FB_ACCEL_NONE;
|
|
|
|
oi->ivtvfb_defined.nonstd = 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* We've filled in the most data, let the usual mode check
|
|
|
|
routine fill in the rest. */
|
2007-07-20 07:16:03 -06:00
|
|
|
_ivtvfb_check_var(&oi->ivtvfb_defined, itv);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Generate valid fb_fix_screeninfo */
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
ivtvfb_get_fix(itv, &oi->ivtvfb_fix);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Generate valid fb_info */
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->ivtvfb_info.node = -1;
|
|
|
|
oi->ivtvfb_info.flags = FBINFO_FLAG_DEFAULT;
|
|
|
|
oi->ivtvfb_info.fbops = &ivtvfb_ops;
|
|
|
|
oi->ivtvfb_info.par = itv;
|
|
|
|
oi->ivtvfb_info.var = oi->ivtvfb_defined;
|
|
|
|
oi->ivtvfb_info.fix = oi->ivtvfb_fix;
|
|
|
|
oi->ivtvfb_info.screen_base = (u8 __iomem *)oi->video_vbase;
|
|
|
|
oi->ivtvfb_info.fbops = &ivtvfb_ops;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Supply some monitor specs. Bogus values will do for now */
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->ivtvfb_info.monspecs.hfmin = 8000;
|
|
|
|
oi->ivtvfb_info.monspecs.hfmax = 70000;
|
|
|
|
oi->ivtvfb_info.monspecs.vfmin = 10;
|
|
|
|
oi->ivtvfb_info.monspecs.vfmax = 100;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Allocate color map */
|
2007-07-20 07:16:03 -06:00
|
|
|
if (fb_alloc_cmap(&oi->ivtvfb_info.cmap, 256, 1)) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("abort, unable to alloc cmap\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the pseudo palette */
|
2008-05-01 07:31:12 -06:00
|
|
|
oi->ivtvfb_info.pseudo_palette =
|
|
|
|
kmalloc(sizeof(u32) * 16, GFP_KERNEL|__GFP_NOWARN);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
if (!oi->ivtvfb_info.pseudo_palette) {
|
2011-03-30 19:57:33 -06:00
|
|
|
IVTVFB_ERR("abort, unable to alloc pseudo palette\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find OSD buffer base & size. Add to mtrr. Zero osd buffer. */
|
|
|
|
|
|
|
|
static int ivtvfb_init_io(struct ivtv *itv)
|
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
|
|
|
|
2007-08-25 02:41:52 -06:00
|
|
|
mutex_lock(&itv->serialize_lock);
|
2007-07-25 09:55:52 -06:00
|
|
|
if (ivtv_init_on_first_open(itv)) {
|
2007-08-25 02:41:52 -06:00
|
|
|
mutex_unlock(&itv->serialize_lock);
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("Failed to initialize ivtv\n");
|
2007-07-25 09:55:52 -06:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
2007-08-25 02:41:52 -06:00
|
|
|
mutex_unlock(&itv->serialize_lock);
|
2007-07-25 09:55:52 -06:00
|
|
|
|
2010-05-23 19:10:30 -06:00
|
|
|
if (ivtvfb_get_framebuffer(itv, &oi->video_rbase,
|
|
|
|
&oi->video_buffer_size) < 0) {
|
|
|
|
IVTVFB_ERR("Firmware failed to respond\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* The osd buffer size depends on the number of video buffers allocated
|
|
|
|
on the PVR350 itself. For now we'll hardcode the smallest osd buffer
|
|
|
|
size to prevent any overlap. */
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->video_buffer_size = 1704960;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->video_pbase = itv->base_addr + IVTV_DECODER_OFFSET + oi->video_rbase;
|
|
|
|
oi->video_vbase = itv->dec_mem + oi->video_rbase;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
if (!oi->video_vbase) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("abort, video memory 0x%x @ 0x%lx isn't mapped!\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->video_buffer_size, oi->video_pbase);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_INFO("Framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->video_pbase, oi->video_vbase,
|
|
|
|
oi->video_buffer_size / 1024);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_MTRR
|
|
|
|
{
|
|
|
|
/* Find the largest power of two that maps the whole buffer */
|
|
|
|
int size_shift = 31;
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
while (!(oi->video_buffer_size & (1 << size_shift))) {
|
2007-07-20 06:29:43 -06:00
|
|
|
size_shift--;
|
|
|
|
}
|
|
|
|
size_shift++;
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->fb_start_aligned_physaddr = oi->video_pbase & ~((1 << size_shift) - 1);
|
|
|
|
oi->fb_end_aligned_physaddr = oi->video_pbase + oi->video_buffer_size;
|
|
|
|
oi->fb_end_aligned_physaddr += (1 << size_shift) - 1;
|
|
|
|
oi->fb_end_aligned_physaddr &= ~((1 << size_shift) - 1);
|
|
|
|
if (mtrr_add(oi->fb_start_aligned_physaddr,
|
|
|
|
oi->fb_end_aligned_physaddr - oi->fb_start_aligned_physaddr,
|
2007-07-20 06:29:43 -06:00
|
|
|
MTRR_TYPE_WRCOMB, 1) < 0) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_INFO("disabled mttr\n");
|
2007-07-20 07:16:03 -06:00
|
|
|
oi->fb_start_aligned_physaddr = 0;
|
|
|
|
oi->fb_end_aligned_physaddr = 0;
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
}
|
2007-07-20 07:16:03 -06:00
|
|
|
#endif
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Blank the entire osd. */
|
2007-07-20 07:16:03 -06:00
|
|
|
memset_io(oi->video_vbase, 0, oi->video_buffer_size);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release any memory we've grabbed & remove mtrr entry */
|
|
|
|
static void ivtvfb_release_buffers (struct ivtv *itv)
|
|
|
|
{
|
2007-07-20 07:16:03 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
/* Release cmap */
|
2007-08-28 00:28:04 -06:00
|
|
|
if (oi->ivtvfb_info.cmap.len)
|
|
|
|
fb_dealloc_cmap(&oi->ivtvfb_info.cmap);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Release pseudo palette */
|
2007-07-20 07:16:03 -06:00
|
|
|
if (oi->ivtvfb_info.pseudo_palette)
|
|
|
|
kfree(oi->ivtvfb_info.pseudo_palette);
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_MTRR
|
2007-07-20 07:16:03 -06:00
|
|
|
if (oi->fb_end_aligned_physaddr) {
|
|
|
|
mtrr_del(-1, oi->fb_start_aligned_physaddr,
|
|
|
|
oi->fb_end_aligned_physaddr - oi->fb_start_aligned_physaddr);
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
kfree(oi);
|
2007-07-20 06:29:43 -06:00
|
|
|
itv->osd_info = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the specified card */
|
|
|
|
|
2007-07-20 07:16:03 -06:00
|
|
|
static int ivtvfb_init_card(struct ivtv *itv)
|
2007-07-20 06:29:43 -06:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (itv->osd_info) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("Card %d already initialised\n", ivtvfb_card_id);
|
2007-07-20 06:29:43 -06:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2008-05-01 07:31:12 -06:00
|
|
|
itv->osd_info = kzalloc(sizeof(struct osd_info),
|
|
|
|
GFP_ATOMIC|__GFP_NOWARN);
|
2007-12-08 06:35:06 -07:00
|
|
|
if (itv->osd_info == NULL) {
|
2007-08-28 00:24:31 -06:00
|
|
|
IVTVFB_ERR("Failed to allocate memory for osd_info\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find & setup the OSD buffer */
|
2010-05-23 19:10:30 -06:00
|
|
|
rc = ivtvfb_init_io(itv);
|
|
|
|
if (rc) {
|
|
|
|
ivtvfb_release_buffers(itv);
|
2007-07-20 06:29:43 -06:00
|
|
|
return rc;
|
2010-05-23 19:10:30 -06:00
|
|
|
}
|
2007-07-20 06:29:43 -06:00
|
|
|
|
|
|
|
/* Set the startup video mode information */
|
2007-07-20 07:16:03 -06:00
|
|
|
if ((rc = ivtvfb_init_vidmode(itv))) {
|
2007-07-20 06:29:43 -06:00
|
|
|
ivtvfb_release_buffers(itv);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the framebuffer */
|
|
|
|
if (register_framebuffer(&itv->osd_info->ivtvfb_info) < 0) {
|
|
|
|
ivtvfb_release_buffers(itv);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
itv->osd_video_pbase = itv->osd_info->video_pbase;
|
|
|
|
|
|
|
|
/* Set the card to the requested mode */
|
|
|
|
ivtvfb_set_par(&itv->osd_info->ivtvfb_info);
|
|
|
|
|
|
|
|
/* Set color 0 to black */
|
|
|
|
write_reg(0, 0x02a30);
|
|
|
|
write_reg(0, 0x02a34);
|
|
|
|
|
|
|
|
/* Enable the osd */
|
|
|
|
ivtvfb_blank(FB_BLANK_UNBLANK, &itv->osd_info->ivtvfb_info);
|
|
|
|
|
2010-06-12 10:41:57 -06:00
|
|
|
/* Enable restart */
|
|
|
|
itv->ivtvfb_restore = ivtvfb_restore;
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
/* Allocate DMA */
|
|
|
|
ivtv_udma_alloc(itv);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-29 15:38:23 -07:00
|
|
|
static int __init ivtvfb_callback_init(struct device *dev, void *p)
|
|
|
|
{
|
|
|
|
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
|
2009-02-07 03:02:27 -07:00
|
|
|
struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev);
|
2008-11-29 15:38:23 -07:00
|
|
|
|
2010-07-19 11:39:34 -06:00
|
|
|
if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
|
2008-11-29 15:38:23 -07:00
|
|
|
if (ivtvfb_init_card(itv) == 0) {
|
|
|
|
IVTVFB_INFO("Framebuffer registered on %s\n",
|
2009-02-07 03:02:27 -07:00
|
|
|
itv->v4l2_dev.name);
|
2008-11-29 15:38:23 -07:00
|
|
|
(*(int *)p)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ivtvfb_callback_cleanup(struct device *dev, void *p)
|
|
|
|
{
|
|
|
|
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
|
2009-02-07 03:02:27 -07:00
|
|
|
struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev);
|
2010-05-23 19:10:30 -06:00
|
|
|
struct osd_info *oi = itv->osd_info;
|
2008-11-29 15:38:23 -07:00
|
|
|
|
2010-07-19 11:39:34 -06:00
|
|
|
if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
|
2008-11-29 15:38:23 -07:00
|
|
|
if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) {
|
|
|
|
IVTVFB_WARN("Framebuffer %d is in use, cannot unload\n",
|
|
|
|
itv->instance);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
IVTVFB_INFO("Unregister framebuffer %d\n", itv->instance);
|
2010-06-12 10:41:57 -06:00
|
|
|
itv->ivtvfb_restore = NULL;
|
2010-05-23 19:10:30 -06:00
|
|
|
ivtvfb_blank(FB_BLANK_VSYNC_SUSPEND, &oi->ivtvfb_info);
|
2008-11-29 15:38:23 -07:00
|
|
|
ivtvfb_release_buffers(itv);
|
|
|
|
itv->osd_video_pbase = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-20 06:29:43 -06:00
|
|
|
static int __init ivtvfb_init(void)
|
|
|
|
{
|
2008-11-29 15:38:23 -07:00
|
|
|
struct device_driver *drv;
|
|
|
|
int registered = 0;
|
|
|
|
int err;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-28 00:24:31 -06:00
|
|
|
if (ivtvfb_card_id < -1 || ivtvfb_card_id >= IVTV_MAX_CARDS) {
|
|
|
|
printk(KERN_ERR "ivtvfb: ivtvfb_card_id parameter is out of range (valid range: -1 - %d)\n",
|
2007-07-20 06:29:43 -06:00
|
|
|
IVTV_MAX_CARDS - 1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-11-29 15:38:23 -07:00
|
|
|
drv = driver_find("ivtv", &pci_bus_type);
|
|
|
|
err = driver_for_each_device(drv, NULL, ®istered, ivtvfb_callback_init);
|
|
|
|
put_driver(drv);
|
2007-07-20 06:29:43 -06:00
|
|
|
if (!registered) {
|
2008-11-29 15:38:23 -07:00
|
|
|
printk(KERN_ERR "ivtvfb: no cards found\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ivtvfb_cleanup(void)
|
|
|
|
{
|
2008-11-29 15:38:23 -07:00
|
|
|
struct device_driver *drv;
|
|
|
|
int err;
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2007-08-26 03:11:07 -06:00
|
|
|
printk(KERN_INFO "ivtvfb: Unloading framebuffer module\n");
|
2007-07-20 06:29:43 -06:00
|
|
|
|
2008-11-29 15:38:23 -07:00
|
|
|
drv = driver_find("ivtv", &pci_bus_type);
|
|
|
|
err = driver_for_each_device(drv, NULL, NULL, ivtvfb_callback_cleanup);
|
|
|
|
put_driver(drv);
|
2007-07-20 06:29:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ivtvfb_init);
|
|
|
|
module_exit(ivtvfb_cleanup);
|