License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
// SPDX-License-Identifier: GPL-2.0
2011-06-11 17:46:43 +00:00
/*
* The Marvell camera core . This device appears in a number of settings ,
* so it needs platform - specific support outside of the core .
*
* Copyright 2011 Jonathan Corbet corbet @ lwn . net
*/
# include <linux/kernel.h>
# include <linux/module.h>
# include <linux/fs.h>
# include <linux/mm.h>
# include <linux/i2c.h>
# include <linux/interrupt.h>
# include <linux/spinlock.h>
# include <linux/slab.h>
# include <linux/device.h>
# include <linux/wait.h>
# include <linux/list.h>
# include <linux/dma-mapping.h>
# include <linux/delay.h>
# include <linux/vmalloc.h>
# include <linux/io.h>
2013-07-03 04:55:58 +00:00
# include <linux/clk.h>
2011-06-20 19:14:37 +00:00
# include <linux/videodev2.h>
# include <media/v4l2-device.h>
# include <media/v4l2-ioctl.h>
2013-01-29 10:58:48 +00:00
# include <media/v4l2-ctrls.h>
2015-03-05 16:05:24 +00:00
# include <media/v4l2-event.h>
2015-11-10 14:01:44 +00:00
# include <media/i2c/ov7670.h>
2011-06-20 19:14:37 +00:00
# include <media/videobuf2-vmalloc.h>
2011-06-20 19:14:40 +00:00
# include <media/videobuf2-dma-contig.h>
2011-06-30 20:05:27 +00:00
# include <media/videobuf2-dma-sg.h>
2011-06-11 17:46:43 +00:00
# include "mcam-core.h"
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_VMALLOC
2011-06-11 17:46:43 +00:00
/*
* Internal DMA buffer management . Since the controller cannot do S / G I / O ,
* we must have physically contiguous buffers to bring frames into .
* These parameters control how many buffers we use , whether we
* allocate them at load time ( better chance of success , but nails down
* memory ) or when somebody tries to use the camera ( riskier ) , and ,
* for load - time allocation , how big they should be .
*
* The controller can cycle through three buffers . We could use
* more by flipping pointers around , but it probably makes little
* sense .
*/
2012-01-12 23:02:20 +00:00
static bool alloc_bufs_at_read ;
2011-06-11 17:46:43 +00:00
module_param ( alloc_bufs_at_read , bool , 0444 ) ;
MODULE_PARM_DESC ( alloc_bufs_at_read ,
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
" Non-zero value causes DMA buffers to be allocated when the video capture device is read, rather than at module load time. This saves memory, but decreases the chances of successfully getting those buffers. This parameter is only used in the vmalloc buffer mode " ) ;
2011-06-11 17:46:43 +00:00
static int n_dma_bufs = 3 ;
module_param ( n_dma_bufs , uint , 0644 ) ;
MODULE_PARM_DESC ( n_dma_bufs ,
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
" The number of DMA buffers to allocate. Can be either two (saves memory, makes timing tighter) or three. " ) ;
2011-06-11 17:46:43 +00:00
static int dma_buf_size = VGA_WIDTH * VGA_HEIGHT * 2 ; /* Worst case */
module_param ( dma_buf_size , uint , 0444 ) ;
MODULE_PARM_DESC ( dma_buf_size ,
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
" The size of the allocated DMA buffers. If actual operating parameters require larger buffers, an attempt to reallocate will be made. " ) ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# else /* MCAM_MODE_VMALLOC */
2014-09-03 18:44:54 +00:00
static const bool alloc_bufs_at_read ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
static const int n_dma_bufs = 3 ; /* Used by S/G_PARM */
# endif /* MCAM_MODE_VMALLOC */
2011-06-11 17:46:43 +00:00
2012-01-12 23:02:20 +00:00
static bool flip ;
2011-06-11 17:46:43 +00:00
module_param ( flip , bool , 0444 ) ;
MODULE_PARM_DESC ( flip ,
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
" If set, the sensor will be instructed to flip the image vertically. " ) ;
2011-06-11 17:46:43 +00:00
2011-06-20 19:14:40 +00:00
static int buffer_mode = - 1 ;
module_param ( buffer_mode , int , 0444 ) ;
MODULE_PARM_DESC ( buffer_mode ,
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
" Set the buffer mode to be used; default is to go with what the platform driver asks for. Set to 0 for vmalloc, 1 for DMA contiguous. " ) ;
2011-06-20 19:14:40 +00:00
2011-06-11 17:46:43 +00:00
/*
* Status flags . Always manipulated with bit operations .
*/
# define CF_BUF0_VALID 0 /* Buffers valid - first three */
# define CF_BUF1_VALID 1
# define CF_BUF2_VALID 2
# define CF_DMA_ACTIVE 3 /* A frame is incoming */
# define CF_CONFIG_NEEDED 4 /* Must configure hardware */
2011-06-20 19:14:40 +00:00
# define CF_SINGLE_BUFFER 5 /* Running with a single buffer */
2011-06-30 20:05:27 +00:00
# define CF_SG_RESTART 6 /* SG restart needed */
2013-07-03 04:56:03 +00:00
# define CF_FRAME_SOF0 7 /* Frame 0 started */
# define CF_FRAME_SOF1 8
# define CF_FRAME_SOF2 9
2011-06-11 17:46:43 +00:00
# define sensor_call(cam, o, f, args...) \
v4l2_subdev_call ( cam - > sensor , o , f , # # args )
static struct mcam_format_struct {
__u8 * desc ;
__u32 pixelformat ;
int bpp ; /* Bytes per pixel */
2013-07-03 04:56:02 +00:00
bool planar ;
2014-11-10 17:28:31 +00:00
u32 mbus_code ;
2011-06-11 17:46:43 +00:00
} mcam_formats [ ] = {
{
. desc = " YUYV 4:2:2 " ,
. pixelformat = V4L2_PIX_FMT_YUYV ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_YUYV8_2X8 ,
2011-06-11 17:46:43 +00:00
. bpp = 2 ,
2013-07-03 04:56:02 +00:00
. planar = false ,
} ,
{
2015-04-13 14:18:51 +00:00
. desc = " YVYU 4:2:2 " ,
. pixelformat = V4L2_PIX_FMT_YVYU ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_YUYV8_2X8 ,
2013-07-03 04:56:02 +00:00
. bpp = 2 ,
. planar = false ,
} ,
{
. desc = " YUV 4:2:0 PLANAR " ,
. pixelformat = V4L2_PIX_FMT_YUV420 ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_YUYV8_2X8 ,
2015-03-09 20:14:36 +00:00
. bpp = 1 ,
2013-07-03 04:56:02 +00:00
. planar = true ,
} ,
{
. desc = " YVU 4:2:0 PLANAR " ,
. pixelformat = V4L2_PIX_FMT_YVU420 ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_YUYV8_2X8 ,
2015-03-09 20:14:36 +00:00
. bpp = 1 ,
2013-07-03 04:56:02 +00:00
. planar = true ,
2011-06-11 17:46:43 +00:00
} ,
{
2015-04-24 09:52:47 +00:00
. desc = " XRGB 444 " ,
. pixelformat = V4L2_PIX_FMT_XRGB444 ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE ,
2011-06-11 17:46:43 +00:00
. bpp = 2 ,
2013-07-03 04:56:02 +00:00
. planar = false ,
2011-06-11 17:46:43 +00:00
} ,
{
. desc = " RGB 565 " ,
. pixelformat = V4L2_PIX_FMT_RGB565 ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_RGB565_2X8_LE ,
2011-06-11 17:46:43 +00:00
. bpp = 2 ,
2013-07-03 04:56:02 +00:00
. planar = false ,
2011-06-11 17:46:43 +00:00
} ,
{
. desc = " Raw RGB Bayer " ,
. pixelformat = V4L2_PIX_FMT_SBGGR8 ,
2014-11-10 17:28:31 +00:00
. mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8 ,
2013-07-03 04:56:02 +00:00
. bpp = 1 ,
. planar = false ,
2011-06-11 17:46:43 +00:00
} ,
} ;
# define N_MCAM_FMTS ARRAY_SIZE(mcam_formats)
static struct mcam_format_struct * mcam_find_format ( u32 pixelformat )
{
unsigned i ;
for ( i = 0 ; i < N_MCAM_FMTS ; i + + )
if ( mcam_formats [ i ] . pixelformat = = pixelformat )
return mcam_formats + i ;
/* Not found? Then return the first format. */
return mcam_formats ;
}
/*
2011-07-08 20:50:46 +00:00
* The default format we use until somebody says otherwise .
2011-06-11 17:46:43 +00:00
*/
2011-07-08 20:50:46 +00:00
static const struct v4l2_pix_format mcam_def_pix_format = {
. width = VGA_WIDTH ,
. height = VGA_HEIGHT ,
. pixelformat = V4L2_PIX_FMT_YUYV ,
. field = V4L2_FIELD_NONE ,
. bytesperline = VGA_WIDTH * 2 ,
. sizeimage = VGA_WIDTH * VGA_HEIGHT * 2 ,
2015-03-05 08:19:23 +00:00
. colorspace = V4L2_COLORSPACE_SRGB ,
2011-07-08 20:50:46 +00:00
} ;
2011-06-11 17:46:43 +00:00
2014-11-10 17:28:31 +00:00
static const u32 mcam_def_mbus_code = MEDIA_BUS_FMT_YUYV8_2X8 ;
2011-06-11 17:46:43 +00:00
2011-06-30 20:05:27 +00:00
/*
* The two - word DMA descriptor format used by the Armada 610 and like . There
* Is a three - word format as well ( set C1_DESC_3WORD ) where the third
* word is a pointer to the next descriptor , but we don ' t use it . Two - word
* descriptors have to be contiguous in memory .
*/
struct mcam_dma_desc {
u32 dma_addr ;
u32 segment_len ;
} ;
2011-06-20 19:14:36 +00:00
/*
* Our buffer type for working with videobuf2 . Note that the vb2
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
* developers have decreed that struct vb2_v4l2_buffer must be at the
2011-06-20 19:14:36 +00:00
* beginning of this structure .
*/
struct mcam_vb_buffer {
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer vb_buf ;
2011-06-20 19:14:36 +00:00
struct list_head queue ;
2011-06-30 20:05:27 +00:00
struct mcam_dma_desc * dma_desc ; /* Descriptor virtual address */
dma_addr_t dma_desc_pa ; /* Descriptor physical address */
int dma_desc_nent ; /* Number of mapped descriptors */
2011-06-20 19:14:36 +00:00
} ;
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
static inline struct mcam_vb_buffer * vb_to_mvb ( struct vb2_v4l2_buffer * vb )
2011-06-20 19:14:36 +00:00
{
return container_of ( vb , struct mcam_vb_buffer , vb_buf ) ;
}
2011-07-08 20:50:46 +00:00
/*
* Hand a completed buffer back to user space .
*/
static void mcam_buffer_done ( struct mcam_camera * cam , int frame ,
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer * vbuf )
2011-07-08 20:50:46 +00:00
{
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
vbuf - > vb2_buf . planes [ 0 ] . bytesused = cam - > pix_format . sizeimage ;
vbuf - > sequence = cam - > buf_seq [ frame ] ;
vbuf - > field = V4L2_FIELD_NONE ;
2015-11-03 10:16:37 +00:00
vbuf - > vb2_buf . timestamp = ktime_get_ns ( ) ;
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
vb2_set_plane_payload ( & vbuf - > vb2_buf , 0 , cam - > pix_format . sizeimage ) ;
vb2_buffer_done ( & vbuf - > vb2_buf , VB2_BUF_STATE_DONE ) ;
2011-07-08 20:50:46 +00:00
}
2011-06-11 17:46:43 +00:00
/*
2011-06-11 17:46:49 +00:00
* Debugging and related .
2011-06-11 17:46:43 +00:00
*/
# define cam_err(cam, fmt, arg...) \
dev_err ( ( cam ) - > dev , fmt , # # arg ) ;
# define cam_warn(cam, fmt, arg...) \
dev_warn ( ( cam ) - > dev , fmt , # # arg ) ;
# define cam_dbg(cam, fmt, arg...) \
dev_dbg ( ( cam ) - > dev , fmt , # # arg ) ;
2011-07-08 20:50:46 +00:00
/*
* Flag manipulation helpers
*/
static void mcam_reset_buffers ( struct mcam_camera * cam )
{
int i ;
cam - > next_buf = - 1 ;
2013-07-03 04:56:03 +00:00
for ( i = 0 ; i < cam - > nbufs ; i + + ) {
2011-07-08 20:50:46 +00:00
clear_bit ( i , & cam - > flags ) ;
2013-07-03 04:56:03 +00:00
clear_bit ( CF_FRAME_SOF0 + i , & cam - > flags ) ;
}
2011-07-08 20:50:46 +00:00
}
static inline int mcam_needs_config ( struct mcam_camera * cam )
{
return test_bit ( CF_CONFIG_NEEDED , & cam - > flags ) ;
}
static void mcam_set_config_needed ( struct mcam_camera * cam , int needed )
{
if ( needed )
set_bit ( CF_CONFIG_NEEDED , & cam - > flags ) ;
else
clear_bit ( CF_CONFIG_NEEDED , & cam - > flags ) ;
}
2011-06-11 17:46:43 +00:00
/* ------------------------------------------------------------------- */
/*
2011-07-08 20:50:46 +00:00
* Make the controller start grabbing images . Everything must
* be set up before doing this .
2011-06-11 17:46:43 +00:00
*/
2011-07-08 20:50:46 +00:00
static void mcam_ctlr_start ( struct mcam_camera * cam )
{
/* set_bit performs a read, so no other barrier should be
needed here */
mcam_reg_set_bit ( cam , REG_CTRL0 , C0_ENABLE ) ;
}
static void mcam_ctlr_stop ( struct mcam_camera * cam )
{
mcam_reg_clear_bit ( cam , REG_CTRL0 , C0_ENABLE ) ;
}
2013-07-03 04:55:58 +00:00
static void mcam_enable_mipi ( struct mcam_camera * mcam )
{
/* Using MIPI mode and enable MIPI */
cam_dbg ( mcam , " camera: DPHY3=0x%x, DPHY5=0x%x, DPHY6=0x%x \n " ,
mcam - > dphy [ 0 ] , mcam - > dphy [ 1 ] , mcam - > dphy [ 2 ] ) ;
mcam_reg_write ( mcam , REG_CSI2_DPHY3 , mcam - > dphy [ 0 ] ) ;
mcam_reg_write ( mcam , REG_CSI2_DPHY5 , mcam - > dphy [ 1 ] ) ;
mcam_reg_write ( mcam , REG_CSI2_DPHY6 , mcam - > dphy [ 2 ] ) ;
if ( ! mcam - > mipi_enabled ) {
if ( mcam - > lane > 4 | | mcam - > lane < = 0 ) {
cam_warn ( mcam , " lane number error \n " ) ;
mcam - > lane = 1 ; /* set the default value */
}
/*
* 0x41 actives 1 lane
* 0x43 actives 2 lanes
* 0x45 actives 3 lanes ( never happen )
* 0x47 actives 4 lanes
*/
mcam_reg_write ( mcam , REG_CSI2_CTRL0 ,
CSI2_C0_MIPI_EN | CSI2_C0_ACT_LANE ( mcam - > lane ) ) ;
mcam_reg_write ( mcam , REG_CLKCTRL ,
( mcam - > mclk_src < < 29 ) | mcam - > mclk_div ) ;
mcam - > mipi_enabled = true ;
}
}
static void mcam_disable_mipi ( struct mcam_camera * mcam )
{
/* Using Parallel mode or disable MIPI */
mcam_reg_write ( mcam , REG_CSI2_CTRL0 , 0x0 ) ;
mcam_reg_write ( mcam , REG_CSI2_DPHY3 , 0x0 ) ;
mcam_reg_write ( mcam , REG_CSI2_DPHY5 , 0x0 ) ;
mcam_reg_write ( mcam , REG_CSI2_DPHY6 , 0x0 ) ;
mcam - > mipi_enabled = false ;
}
2015-03-09 19:59:59 +00:00
static bool mcam_fmt_is_planar ( __u32 pfmt )
{
struct mcam_format_struct * f ;
f = mcam_find_format ( pfmt ) ;
return f - > planar ;
}
static void mcam_write_yuv_bases ( struct mcam_camera * cam ,
unsigned frame , dma_addr_t base )
{
struct v4l2_pix_format * fmt = & cam - > pix_format ;
u32 pixel_count = fmt - > width * fmt - > height ;
dma_addr_t y , u = 0 , v = 0 ;
y = base ;
switch ( fmt - > pixelformat ) {
case V4L2_PIX_FMT_YUV420 :
u = y + pixel_count ;
v = u + pixel_count / 4 ;
break ;
case V4L2_PIX_FMT_YVU420 :
v = y + pixel_count ;
u = v + pixel_count / 4 ;
break ;
default :
break ;
}
mcam_reg_write ( cam , REG_Y0BAR + frame * 4 , y ) ;
if ( mcam_fmt_is_planar ( fmt - > pixelformat ) ) {
mcam_reg_write ( cam , REG_U0BAR + frame * 4 , u ) ;
mcam_reg_write ( cam , REG_V0BAR + frame * 4 , v ) ;
}
}
2011-07-08 20:50:46 +00:00
/* ------------------------------------------------------------------- */
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_VMALLOC
2011-07-08 20:50:46 +00:00
/*
* Code specific to the vmalloc buffer mode .
*/
/*
* Allocate in - kernel DMA buffers for vmalloc mode .
*/
static int mcam_alloc_dma_bufs ( struct mcam_camera * cam , int loadtime )
{
int i ;
mcam_set_config_needed ( cam , 1 ) ;
if ( loadtime )
cam - > dma_buf_size = dma_buf_size ;
else
cam - > dma_buf_size = cam - > pix_format . sizeimage ;
if ( n_dma_bufs > 3 )
n_dma_bufs = 3 ;
cam - > nbufs = 0 ;
for ( i = 0 ; i < n_dma_bufs ; i + + ) {
cam - > dma_bufs [ i ] = dma_alloc_coherent ( cam - > dev ,
cam - > dma_buf_size , cam - > dma_handles + i ,
GFP_KERNEL ) ;
if ( cam - > dma_bufs [ i ] = = NULL ) {
cam_warn ( cam , " Failed to allocate DMA buffer \n " ) ;
break ;
}
( cam - > nbufs ) + + ;
}
switch ( cam - > nbufs ) {
case 1 :
dma_free_coherent ( cam - > dev , cam - > dma_buf_size ,
cam - > dma_bufs [ 0 ] , cam - > dma_handles [ 0 ] ) ;
cam - > nbufs = 0 ;
2017-05-18 11:13:28 +00:00
/* fall-through */
2011-07-08 20:50:46 +00:00
case 0 :
cam_err ( cam , " Insufficient DMA buffers, cannot operate \n " ) ;
return - ENOMEM ;
case 2 :
if ( n_dma_bufs > 2 )
cam_warn ( cam , " Will limp along with only 2 buffers \n " ) ;
break ;
}
return 0 ;
}
static void mcam_free_dma_bufs ( struct mcam_camera * cam )
{
int i ;
for ( i = 0 ; i < cam - > nbufs ; i + + ) {
dma_free_coherent ( cam - > dev , cam - > dma_buf_size ,
cam - > dma_bufs [ i ] , cam - > dma_handles [ i ] ) ;
cam - > dma_bufs [ i ] = NULL ;
}
cam - > nbufs = 0 ;
}
2011-06-11 17:46:43 +00:00
/*
2011-06-20 19:14:40 +00:00
* Set up DMA buffers when operating in vmalloc mode
2011-06-11 17:46:43 +00:00
*/
2011-06-20 19:14:40 +00:00
static void mcam_ctlr_dma_vmalloc ( struct mcam_camera * cam )
2011-06-11 17:46:43 +00:00
{
/*
2015-03-09 19:59:59 +00:00
* Store the first two YUV buffers . Then either
2011-06-11 17:46:43 +00:00
* set the third if it exists , or tell the controller
* to just use two .
*/
2015-03-09 19:59:59 +00:00
mcam_write_yuv_bases ( cam , 0 , cam - > dma_handles [ 0 ] ) ;
mcam_write_yuv_bases ( cam , 1 , cam - > dma_handles [ 1 ] ) ;
2011-06-11 17:46:43 +00:00
if ( cam - > nbufs > 2 ) {
2015-03-09 19:59:59 +00:00
mcam_write_yuv_bases ( cam , 2 , cam - > dma_handles [ 2 ] ) ;
2011-06-11 17:46:43 +00:00
mcam_reg_clear_bit ( cam , REG_CTRL1 , C1_TWOBUFS ) ;
} else
mcam_reg_set_bit ( cam , REG_CTRL1 , C1_TWOBUFS ) ;
2013-05-29 09:59:44 +00:00
if ( cam - > chip_id = = MCAM_CAFE )
2011-06-11 17:46:49 +00:00
mcam_reg_write ( cam , REG_UBAR , 0 ) ; /* 32 bits only */
2011-06-11 17:46:43 +00:00
}
2011-07-08 20:50:46 +00:00
/*
* Copy data out to user space in the vmalloc case
*/
static void mcam_frame_tasklet ( unsigned long data )
{
struct mcam_camera * cam = ( struct mcam_camera * ) data ;
int i ;
unsigned long flags ;
struct mcam_vb_buffer * buf ;
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
for ( i = 0 ; i < cam - > nbufs ; i + + ) {
int bufno = cam - > next_buf ;
if ( cam - > state ! = S_STREAMING | | bufno < 0 )
break ; /* I/O got stopped */
if ( + + ( cam - > next_buf ) > = cam - > nbufs )
cam - > next_buf = 0 ;
if ( ! test_bit ( bufno , & cam - > flags ) )
continue ;
if ( list_empty ( & cam - > buffers ) ) {
2012-12-15 08:57:50 +00:00
cam - > frame_state . singles + + ;
2011-07-08 20:50:46 +00:00
break ; /* Leave it valid, hope for better later */
}
2012-12-15 08:57:50 +00:00
cam - > frame_state . delivered + + ;
2011-07-08 20:50:46 +00:00
clear_bit ( bufno , & cam - > flags ) ;
buf = list_first_entry ( & cam - > buffers , struct mcam_vb_buffer ,
queue ) ;
list_del_init ( & buf - > queue ) ;
/*
* Drop the lock during the big copy . This * should * be safe . . .
*/
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
memcpy ( vb2_plane_vaddr ( & buf - > vb_buf . vb2_buf , 0 ) ,
cam - > dma_bufs [ bufno ] ,
2011-07-08 20:50:46 +00:00
cam - > pix_format . sizeimage ) ;
mcam_buffer_done ( cam , bufno , & buf - > vb_buf ) ;
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
}
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
}
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
/*
* Make sure our allocated buffers are up to the task .
*/
static int mcam_check_dma_buffers ( struct mcam_camera * cam )
{
if ( cam - > nbufs > 0 & & cam - > dma_buf_size < cam - > pix_format . sizeimage )
mcam_free_dma_bufs ( cam ) ;
if ( cam - > nbufs = = 0 )
return mcam_alloc_dma_bufs ( cam , 0 ) ;
return 0 ;
}
static void mcam_vmalloc_done ( struct mcam_camera * cam , int frame )
{
tasklet_schedule ( & cam - > s_tasklet ) ;
}
# else /* MCAM_MODE_VMALLOC */
static inline int mcam_alloc_dma_bufs ( struct mcam_camera * cam , int loadtime )
{
return 0 ;
}
static inline void mcam_free_dma_bufs ( struct mcam_camera * cam )
{
return ;
}
static inline int mcam_check_dma_buffers ( struct mcam_camera * cam )
{
return 0 ;
}
# endif /* MCAM_MODE_VMALLOC */
# ifdef MCAM_MODE_DMA_CONTIG
2011-07-08 20:50:46 +00:00
/* ---------------------------------------------------------------------- */
/*
* DMA - contiguous code .
*/
2013-07-03 04:56:02 +00:00
2011-06-20 19:14:40 +00:00
/*
* Set up a contiguous buffer for the given frame . Here also is where
* the underrun strategy is set : if there is no buffer available , reuse
* the buffer from the other BAR and set the CF_SINGLE_BUFFER flag to
* keep the interrupt handler from giving that buffer back to user
* space . In this way , we always have a buffer to DMA to and don ' t
* have to try to play games stopping and restarting the controller .
*/
static void mcam_set_contig_buffer ( struct mcam_camera * cam , int frame )
{
struct mcam_vb_buffer * buf ;
2013-07-03 04:56:02 +00:00
dma_addr_t dma_handle ;
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer * vb ;
2013-07-03 04:56:02 +00:00
2011-06-20 19:14:40 +00:00
/*
* If there are no available buffers , go into single mode
*/
if ( list_empty ( & cam - > buffers ) ) {
buf = cam - > vb_bufs [ frame ^ 0x1 ] ;
set_bit ( CF_SINGLE_BUFFER , & cam - > flags ) ;
2012-12-15 08:57:50 +00:00
cam - > frame_state . singles + + ;
2013-07-03 04:56:01 +00:00
} else {
/*
* OK , we have a buffer we can use .
*/
buf = list_first_entry ( & cam - > buffers , struct mcam_vb_buffer ,
queue ) ;
list_del_init ( & buf - > queue ) ;
clear_bit ( CF_SINGLE_BUFFER , & cam - > flags ) ;
2011-06-20 19:14:40 +00:00
}
2013-07-03 04:56:01 +00:00
cam - > vb_bufs [ frame ] = buf ;
2013-07-03 04:56:02 +00:00
vb = & buf - > vb_buf ;
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
dma_handle = vb2_dma_contig_plane_dma_addr ( & vb - > vb2_buf , 0 ) ;
2015-03-09 19:59:59 +00:00
mcam_write_yuv_bases ( cam , frame , dma_handle ) ;
2011-06-20 19:14:40 +00:00
}
2011-06-30 20:05:27 +00:00
/*
* Initial B_DMA_contig setup .
*/
2011-06-20 19:14:40 +00:00
static void mcam_ctlr_dma_contig ( struct mcam_camera * cam )
{
mcam_reg_set_bit ( cam , REG_CTRL1 , C1_TWOBUFS ) ;
cam - > nbufs = 2 ;
mcam_set_contig_buffer ( cam , 0 ) ;
mcam_set_contig_buffer ( cam , 1 ) ;
}
2011-07-08 20:50:46 +00:00
/*
* Frame completion handling .
*/
static void mcam_dma_contig_done ( struct mcam_camera * cam , int frame )
{
struct mcam_vb_buffer * buf = cam - > vb_bufs [ frame ] ;
if ( ! test_bit ( CF_SINGLE_BUFFER , & cam - > flags ) ) {
2012-12-15 08:57:50 +00:00
cam - > frame_state . delivered + + ;
2015-03-05 21:00:07 +00:00
cam - > vb_bufs [ frame ] = NULL ;
2011-07-08 20:50:46 +00:00
mcam_buffer_done ( cam , frame , & buf - > vb_buf ) ;
}
mcam_set_contig_buffer ( cam , frame ) ;
}
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# endif /* MCAM_MODE_DMA_CONTIG */
2011-07-08 20:50:46 +00:00
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_DMA_SG
2011-07-08 20:50:46 +00:00
/* ---------------------------------------------------------------------- */
/*
* Scatter / gather - specific code .
*/
2011-06-20 19:14:40 +00:00
2011-06-30 20:05:27 +00:00
/*
* Set up the next buffer for S / G I / O ; caller should be sure that
* the controller is stopped and a buffer is available .
*/
static void mcam_sg_next_buffer ( struct mcam_camera * cam )
2011-06-20 19:14:40 +00:00
{
2011-06-30 20:05:27 +00:00
struct mcam_vb_buffer * buf ;
buf = list_first_entry ( & cam - > buffers , struct mcam_vb_buffer , queue ) ;
list_del_init ( & buf - > queue ) ;
2012-03-16 22:14:53 +00:00
/*
* Very Bad Not Good Things happen if you don ' t clear
* C1_DESC_ENA before making any descriptor changes .
*/
mcam_reg_clear_bit ( cam , REG_CTRL1 , C1_DESC_ENA ) ;
2011-06-30 20:05:27 +00:00
mcam_reg_write ( cam , REG_DMA_DESC_Y , buf - > dma_desc_pa ) ;
mcam_reg_write ( cam , REG_DESC_LEN_Y ,
buf - > dma_desc_nent * sizeof ( struct mcam_dma_desc ) ) ;
mcam_reg_write ( cam , REG_DESC_LEN_U , 0 ) ;
mcam_reg_write ( cam , REG_DESC_LEN_V , 0 ) ;
2012-03-16 22:14:53 +00:00
mcam_reg_set_bit ( cam , REG_CTRL1 , C1_DESC_ENA ) ;
2011-06-30 20:05:27 +00:00
cam - > vb_bufs [ 0 ] = buf ;
2011-06-20 19:14:40 +00:00
}
2011-06-30 20:05:27 +00:00
/*
* Initial B_DMA_sg setup
*/
static void mcam_ctlr_dma_sg ( struct mcam_camera * cam )
{
2011-12-30 17:13:41 +00:00
/*
* The list - empty condition can hit us at resume time
* if the buffer list was empty when the system was suspended .
*/
if ( list_empty ( & cam - > buffers ) ) {
set_bit ( CF_SG_RESTART , & cam - > flags ) ;
return ;
}
2011-06-30 20:05:27 +00:00
mcam_reg_clear_bit ( cam , REG_CTRL1 , C1_DESC_3WORD ) ;
mcam_sg_next_buffer ( cam ) ;
cam - > nbufs = 3 ;
}
2011-07-08 20:50:46 +00:00
2011-06-30 20:05:27 +00:00
/*
2011-07-08 20:50:46 +00:00
* Frame completion with S / G is trickier . We can ' t muck with
* a descriptor chain on the fly , since the controller buffers it
* internally . So we have to actually stop and restart ; Marvell
* says this is the way to do it .
*
* Of course , stopping is easier said than done ; experience shows
* that the controller can start a frame * after * C0_ENABLE has been
* cleared . So when running in S / G mode , the controller is " stopped "
* on receipt of the start - of - frame interrupt . That means we can
* safely change the DMA descriptor array here and restart things
* ( assuming there ' s another buffer waiting to go ) .
*/
static void mcam_dma_sg_done ( struct mcam_camera * cam , int frame )
{
struct mcam_vb_buffer * buf = cam - > vb_bufs [ 0 ] ;
2012-03-16 22:14:50 +00:00
/*
* If we ' re no longer supposed to be streaming , don ' t do anything .
*/
if ( cam - > state ! = S_STREAMING )
return ;
2011-07-08 20:50:46 +00:00
/*
* If we have another buffer available , put it in and
* restart the engine .
*/
if ( ! list_empty ( & cam - > buffers ) ) {
mcam_sg_next_buffer ( cam ) ;
mcam_ctlr_start ( cam ) ;
/*
* Otherwise set CF_SG_RESTART and the controller will
* be restarted once another buffer shows up .
*/
} else {
set_bit ( CF_SG_RESTART , & cam - > flags ) ;
2012-12-15 08:57:50 +00:00
cam - > frame_state . singles + + ;
2011-12-30 17:13:41 +00:00
cam - > vb_bufs [ 0 ] = NULL ;
2011-07-08 20:50:46 +00:00
}
/*
* Now we can give the completed frame back to user space .
*/
2012-12-15 08:57:50 +00:00
cam - > frame_state . delivered + + ;
2011-07-08 20:50:46 +00:00
mcam_buffer_done ( cam , frame , & buf - > vb_buf ) ;
}
/*
* Scatter / gather mode requires stopping the controller between
* frames so we can put in a new DMA descriptor array . If no new
* buffer exists at frame completion , the controller is left stopped ;
* this function is charged with gettig things going again .
*/
static void mcam_sg_restart ( struct mcam_camera * cam )
{
mcam_ctlr_dma_sg ( cam ) ;
mcam_ctlr_start ( cam ) ;
clear_bit ( CF_SG_RESTART , & cam - > flags ) ;
}
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# else /* MCAM_MODE_DMA_SG */
static inline void mcam_sg_restart ( struct mcam_camera * cam )
{
return ;
}
# endif /* MCAM_MODE_DMA_SG */
2011-07-08 20:50:46 +00:00
/* ---------------------------------------------------------------------- */
/*
* Buffer - mode - independent controller code .
*/
/*
* Image format setup
2011-06-30 20:05:27 +00:00
*/
2011-06-11 17:46:43 +00:00
static void mcam_ctlr_image ( struct mcam_camera * cam )
{
struct v4l2_pix_format * fmt = & cam - > pix_format ;
2013-07-03 04:56:02 +00:00
u32 widthy = 0 , widthuv = 0 , imgsz_h , imgsz_w ;
cam_dbg ( cam , " camera: bytesperline = %d; height = %d \n " ,
fmt - > bytesperline , fmt - > sizeimage / fmt - > bytesperline ) ;
imgsz_h = ( fmt - > height < < IMGSZ_V_SHIFT ) & IMGSZ_V_MASK ;
imgsz_w = ( fmt - > width * 2 ) & IMGSZ_H_MASK ;
switch ( fmt - > pixelformat ) {
case V4L2_PIX_FMT_YUYV :
2015-04-13 14:18:51 +00:00
case V4L2_PIX_FMT_YVYU :
2013-07-03 04:56:02 +00:00
widthy = fmt - > width * 2 ;
widthuv = 0 ;
break ;
case V4L2_PIX_FMT_YUV420 :
case V4L2_PIX_FMT_YVU420 :
widthy = fmt - > width ;
widthuv = fmt - > width / 2 ;
break ;
default :
widthy = fmt - > bytesperline ;
widthuv = 0 ;
2015-03-09 20:14:36 +00:00
break ;
2013-07-03 04:56:02 +00:00
}
mcam_reg_write_mask ( cam , REG_IMGPITCH , widthuv < < 16 | widthy ,
IMGP_YP_MASK | IMGP_UVP_MASK ) ;
mcam_reg_write ( cam , REG_IMGSIZE , imgsz_h | imgsz_w ) ;
mcam_reg_write ( cam , REG_IMGOFFSET , 0x0 ) ;
2011-06-11 17:46:43 +00:00
/*
* Tell the controller about the image format we are using .
*/
2013-07-03 04:56:02 +00:00
switch ( fmt - > pixelformat ) {
case V4L2_PIX_FMT_YUV420 :
case V4L2_PIX_FMT_YVU420 :
mcam_reg_write_mask ( cam , REG_CTRL0 ,
2015-04-13 14:18:51 +00:00
C0_DF_YUV | C0_YUV_420PL | C0_YUVE_VYUY , C0_DF_MASK ) ;
2013-07-03 04:56:02 +00:00
break ;
2011-06-11 17:46:43 +00:00
case V4L2_PIX_FMT_YUYV :
2013-07-03 04:56:02 +00:00
mcam_reg_write_mask ( cam , REG_CTRL0 ,
2015-04-13 14:18:51 +00:00
C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_NOSWAP , C0_DF_MASK ) ;
2013-07-03 04:56:02 +00:00
break ;
2015-04-13 14:18:51 +00:00
case V4L2_PIX_FMT_YVYU :
2013-07-03 04:56:02 +00:00
mcam_reg_write_mask ( cam , REG_CTRL0 ,
2015-04-13 14:18:51 +00:00
C0_DF_YUV | C0_YUV_PACKED | C0_YUVE_SWAP24 , C0_DF_MASK ) ;
2013-07-03 04:56:02 +00:00
break ;
2015-04-24 09:52:47 +00:00
case V4L2_PIX_FMT_XRGB444 :
2013-07-03 04:56:02 +00:00
mcam_reg_write_mask ( cam , REG_CTRL0 ,
2015-04-24 09:52:47 +00:00
C0_DF_RGB | C0_RGBF_444 | C0_RGB4_XBGR , C0_DF_MASK ) ;
2013-07-03 04:56:02 +00:00
break ;
2011-06-11 17:46:43 +00:00
case V4L2_PIX_FMT_RGB565 :
2013-07-03 04:56:02 +00:00
mcam_reg_write_mask ( cam , REG_CTRL0 ,
C0_DF_RGB | C0_RGBF_565 | C0_RGB5_BGGR , C0_DF_MASK ) ;
break ;
2015-03-14 11:47:01 +00:00
case V4L2_PIX_FMT_SBGGR8 :
mcam_reg_write_mask ( cam , REG_CTRL0 ,
C0_DF_RGB | C0_RGB5_GRBG , C0_DF_MASK ) ;
break ;
2011-06-11 17:46:43 +00:00
default :
2013-07-03 04:56:02 +00:00
cam_err ( cam , " camera: unknown format: %#x \n " , fmt - > pixelformat ) ;
break ;
2011-06-11 17:46:43 +00:00
}
2013-07-03 04:56:02 +00:00
2011-06-11 17:46:43 +00:00
/*
* Make sure it knows we want to use hsync / vsync .
*/
2013-07-03 04:56:02 +00:00
mcam_reg_write_mask ( cam , REG_CTRL0 , C0_SIF_HVSYNC , C0_SIFM_MASK ) ;
2013-07-03 04:55:58 +00:00
/*
* This field controls the generation of EOF ( DVP only )
*/
if ( cam - > bus_type ! = V4L2_MBUS_CSI2 )
mcam_reg_set_bit ( cam , REG_CTRL0 ,
C0_EOF_VSYNC | C0_VEDGE_CTRL ) ;
2011-06-11 17:46:43 +00:00
}
/*
* Configure the controller for operation ; caller holds the
* device mutex .
*/
static int mcam_ctlr_configure ( struct mcam_camera * cam )
{
unsigned long flags ;
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
2011-12-30 17:13:41 +00:00
clear_bit ( CF_SG_RESTART , & cam - > flags ) ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
cam - > dma_setup ( cam ) ;
2011-06-11 17:46:43 +00:00
mcam_ctlr_image ( cam ) ;
mcam_set_config_needed ( cam , 0 ) ;
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
return 0 ;
}
static void mcam_ctlr_irq_enable ( struct mcam_camera * cam )
{
/*
* Clear any pending interrupts , since we do not
* expect to have I / O active prior to enabling .
*/
mcam_reg_write ( cam , REG_IRQSTAT , FRAMEIRQS ) ;
mcam_reg_set_bit ( cam , REG_IRQMASK , FRAMEIRQS ) ;
}
static void mcam_ctlr_irq_disable ( struct mcam_camera * cam )
{
mcam_reg_clear_bit ( cam , REG_IRQMASK , FRAMEIRQS ) ;
}
2011-06-30 20:05:27 +00:00
2011-06-11 17:46:43 +00:00
static void mcam_ctlr_init ( struct mcam_camera * cam )
{
unsigned long flags ;
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
/*
* Make sure it ' s not powered down .
*/
mcam_reg_clear_bit ( cam , REG_CTRL1 , C1_PWRDWN ) ;
/*
* Turn off the enable bit . It sure should be off anyway ,
* but it ' s good to be sure .
*/
mcam_reg_clear_bit ( cam , REG_CTRL0 , C0_ENABLE ) ;
/*
* Clock the sensor appropriately . Controller clock should
* be 48 MHz , sensor " typical " value is half that .
*/
mcam_reg_write_mask ( cam , REG_CLKCTRL , 2 , CLK_DIV_MASK ) ;
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
}
/*
* Stop the controller , and don ' t return until we ' re really sure that no
* further DMA is going on .
*/
static void mcam_ctlr_stop_dma ( struct mcam_camera * cam )
{
unsigned long flags ;
/*
* Theory : stop the camera controller ( whether it is operating
* or not ) . Delay briefly just in case we race with the SOF
* interrupt , then wait until no DMA is active .
*/
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
2011-06-30 20:05:27 +00:00
clear_bit ( CF_SG_RESTART , & cam - > flags ) ;
2011-06-11 17:46:43 +00:00
mcam_ctlr_stop ( cam ) ;
2011-06-30 20:05:27 +00:00
cam - > state = S_IDLE ;
2011-06-11 17:46:43 +00:00
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
2012-03-16 22:14:52 +00:00
/*
* This is a brutally long sleep , but experience shows that
* it can take the controller a while to get the message that
* it needs to stop grabbing frames . In particular , we can
* sometimes ( on mmp ) get a frame at the end WITHOUT the
* start - of - frame indication .
*/
msleep ( 150 ) ;
2011-06-11 17:46:43 +00:00
if ( test_bit ( CF_DMA_ACTIVE , & cam - > flags ) )
cam_err ( cam , " Timeout waiting for DMA to end \n " ) ;
/* This would be bad news - what now? */
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
mcam_ctlr_irq_disable ( cam ) ;
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
}
/*
* Power up and down .
*/
2013-07-03 04:55:58 +00:00
static int mcam_ctlr_power_up ( struct mcam_camera * cam )
2011-06-11 17:46:43 +00:00
{
unsigned long flags ;
2013-07-03 04:55:58 +00:00
int ret ;
2011-06-11 17:46:43 +00:00
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
2013-07-03 04:55:58 +00:00
ret = cam - > plat_power_up ( cam ) ;
if ( ret ) {
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
return ret ;
}
2011-06-11 17:46:49 +00:00
mcam_reg_clear_bit ( cam , REG_CTRL1 , C1_PWRDWN ) ;
2011-06-11 17:46:43 +00:00
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
msleep ( 5 ) ; /* Just to be sure */
2013-07-03 04:55:58 +00:00
return 0 ;
2011-06-11 17:46:43 +00:00
}
static void mcam_ctlr_power_down ( struct mcam_camera * cam )
{
unsigned long flags ;
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
2011-06-11 17:46:49 +00:00
/*
* School of hard knocks department : be sure we do any register
* twiddling on the controller * before * calling the platform
* power down routine .
*/
2011-06-11 17:46:43 +00:00
mcam_reg_set_bit ( cam , REG_CTRL1 , C1_PWRDWN ) ;
2011-06-11 17:46:49 +00:00
cam - > plat_power_down ( cam ) ;
2011-06-11 17:46:43 +00:00
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
}
/* -------------------------------------------------------------------- */
/*
* Communications with the sensor .
*/
static int __mcam_cam_reset ( struct mcam_camera * cam )
{
return sensor_call ( cam , core , reset , 0 ) ;
}
/*
* We have found the sensor on the i2c . Let ' s try to have a
* conversation .
*/
static int mcam_cam_init ( struct mcam_camera * cam )
{
int ret ;
if ( cam - > state ! = S_NOTREADY )
cam_warn ( cam , " Cam init with device in funky state %d " ,
cam - > state ) ;
ret = __mcam_cam_reset ( cam ) ;
2013-05-29 09:59:44 +00:00
/* Get/set parameters? */
2011-07-08 20:50:46 +00:00
cam - > state = S_IDLE ;
mcam_ctlr_power_down ( cam ) ;
return ret ;
2011-06-11 17:46:43 +00:00
}
2011-07-08 20:50:46 +00:00
/*
* Configure the sensor to match the parameters we have . Caller should
* hold s_mutex
*/
static int mcam_cam_set_flip ( struct mcam_camera * cam )
2011-06-11 17:46:43 +00:00
{
2011-07-08 20:50:46 +00:00
struct v4l2_control ctrl ;
2011-06-11 17:46:43 +00:00
2011-07-08 20:50:46 +00:00
memset ( & ctrl , 0 , sizeof ( ctrl ) ) ;
ctrl . id = V4L2_CID_VFLIP ;
ctrl . value = flip ;
2016-07-03 11:58:55 +00:00
return v4l2_s_ctrl ( NULL , cam - > sensor - > ctrl_handler , & ctrl ) ;
2011-06-11 17:46:43 +00:00
}
2011-07-08 20:50:46 +00:00
static int mcam_cam_configure ( struct mcam_camera * cam )
{
2015-04-09 07:05:59 +00:00
struct v4l2_subdev_format format = {
. which = V4L2_SUBDEV_FORMAT_ACTIVE ,
} ;
2011-07-08 20:50:46 +00:00
int ret ;
2011-06-11 17:46:43 +00:00
2015-04-09 07:05:59 +00:00
v4l2_fill_mbus_format ( & format . format , & cam - > pix_format , cam - > mbus_code ) ;
2011-07-08 20:50:46 +00:00
ret = sensor_call ( cam , core , init , 0 ) ;
if ( ret = = 0 )
2015-04-09 07:05:59 +00:00
ret = sensor_call ( cam , pad , set_fmt , NULL , & format ) ;
2011-07-08 20:50:46 +00:00
/*
* OV7670 does weird things if flip is set * before * format . . .
*/
ret + = mcam_cam_set_flip ( cam ) ;
return ret ;
}
2011-06-11 17:46:43 +00:00
/*
* Get everything ready , and start grabbing frames .
*/
2011-06-20 19:14:40 +00:00
static int mcam_read_setup ( struct mcam_camera * cam )
2011-06-11 17:46:43 +00:00
{
int ret ;
unsigned long flags ;
/*
* Configuration . If we still don ' t have DMA buffers ,
* make one last , desperate attempt .
*/
2011-06-20 19:14:40 +00:00
if ( cam - > buffer_mode = = B_vmalloc & & cam - > nbufs = = 0 & &
mcam_alloc_dma_bufs ( cam , 0 ) )
return - ENOMEM ;
2011-06-11 17:46:43 +00:00
if ( mcam_needs_config ( cam ) ) {
mcam_cam_configure ( cam ) ;
ret = mcam_ctlr_configure ( cam ) ;
if ( ret )
return ret ;
}
/*
* Turn it loose .
*/
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
2012-03-16 22:14:52 +00:00
clear_bit ( CF_DMA_ACTIVE , & cam - > flags ) ;
2011-06-11 17:46:43 +00:00
mcam_reset_buffers ( cam ) ;
2013-07-03 04:55:58 +00:00
/*
* Update CSI2_DPHY value
*/
if ( cam - > calc_dphy )
cam - > calc_dphy ( cam ) ;
cam_dbg ( cam , " camera: DPHY sets: dphy3=0x%x, dphy5=0x%x, dphy6=0x%x \n " ,
cam - > dphy [ 0 ] , cam - > dphy [ 1 ] , cam - > dphy [ 2 ] ) ;
if ( cam - > bus_type = = V4L2_MBUS_CSI2 )
mcam_enable_mipi ( cam ) ;
else
mcam_disable_mipi ( cam ) ;
2011-06-11 17:46:43 +00:00
mcam_ctlr_irq_enable ( cam ) ;
2011-06-20 19:14:40 +00:00
cam - > state = S_STREAMING ;
2011-12-30 17:13:41 +00:00
if ( ! test_bit ( CF_SG_RESTART , & cam - > flags ) )
mcam_ctlr_start ( cam ) ;
2011-06-11 17:46:43 +00:00
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
return 0 ;
}
2011-06-20 19:14:36 +00:00
/* ----------------------------------------------------------------------- */
/*
* Videobuf2 interface code .
*/
2011-06-11 17:46:43 +00:00
2011-08-24 13:30:21 +00:00
static int mcam_vb_queue_setup ( struct vb2_queue * vq ,
2015-10-28 02:50:37 +00:00
unsigned int * nbufs ,
2011-08-24 09:43:36 +00:00
unsigned int * num_planes , unsigned int sizes [ ] ,
2016-04-15 12:15:05 +00:00
struct device * alloc_devs [ ] )
2011-06-11 17:46:43 +00:00
{
2011-06-20 19:14:36 +00:00
struct mcam_camera * cam = vb2_get_drv_priv ( vq ) ;
2011-06-30 20:05:27 +00:00
int minbufs = ( cam - > buffer_mode = = B_DMA_contig ) ? 3 : 2 ;
2015-10-28 02:50:37 +00:00
unsigned size = cam - > pix_format . sizeimage ;
2011-06-20 19:14:36 +00:00
2011-06-30 20:05:27 +00:00
if ( * nbufs < minbufs )
* nbufs = minbufs ;
2015-10-28 02:50:37 +00:00
if ( * num_planes )
return sizes [ 0 ] < size ? - EINVAL : 0 ;
sizes [ 0 ] = size ;
* num_planes = 1 ; /* Someday we have to support planar formats... */
2011-06-20 19:14:36 +00:00
return 0 ;
}
2011-06-30 20:05:27 +00:00
2011-06-20 19:14:36 +00:00
static void mcam_vb_buf_queue ( struct vb2_buffer * vb )
{
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer * vbuf = to_vb2_v4l2_buffer ( vb ) ;
struct mcam_vb_buffer * mvb = vb_to_mvb ( vbuf ) ;
2011-06-20 19:14:36 +00:00
struct mcam_camera * cam = vb2_get_drv_priv ( vb - > vb2_queue ) ;
unsigned long flags ;
2011-06-20 19:14:40 +00:00
int start ;
2011-06-20 19:14:36 +00:00
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
2011-06-20 19:14:40 +00:00
start = ( cam - > state = = S_BUFWAIT ) & & ! list_empty ( & cam - > buffers ) ;
list_add ( & mvb - > queue , & cam - > buffers ) ;
2012-03-16 22:14:50 +00:00
if ( cam - > state = = S_STREAMING & & test_bit ( CF_SG_RESTART , & cam - > flags ) )
2011-06-30 20:05:27 +00:00
mcam_sg_restart ( cam ) ;
2011-06-20 19:14:36 +00:00
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
2011-06-20 19:14:40 +00:00
if ( start )
mcam_read_setup ( cam ) ;
2011-06-20 19:14:36 +00:00
}
2015-03-05 21:00:07 +00:00
static void mcam_vb_requeue_bufs ( struct vb2_queue * vq ,
enum vb2_buffer_state state )
{
struct mcam_camera * cam = vb2_get_drv_priv ( vq ) ;
struct mcam_vb_buffer * buf , * node ;
unsigned long flags ;
unsigned i ;
spin_lock_irqsave ( & cam - > dev_lock , flags ) ;
list_for_each_entry_safe ( buf , node , & cam - > buffers , queue ) {
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
vb2_buffer_done ( & buf - > vb_buf . vb2_buf , state ) ;
2015-03-05 21:00:07 +00:00
list_del ( & buf - > queue ) ;
}
for ( i = 0 ; i < MAX_DMA_BUFS ; i + + ) {
buf = cam - > vb_bufs [ i ] ;
if ( buf ) {
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
vb2_buffer_done ( & buf - > vb_buf . vb2_buf , state ) ;
2015-03-05 21:00:07 +00:00
cam - > vb_bufs [ i ] = NULL ;
}
}
spin_unlock_irqrestore ( & cam - > dev_lock , flags ) ;
}
2011-06-20 19:14:36 +00:00
/*
* These need to be called with the mutex held from vb2
*/
2011-08-29 11:51:49 +00:00
static int mcam_vb_start_streaming ( struct vb2_queue * vq , unsigned int count )
2011-06-20 19:14:36 +00:00
{
struct mcam_camera * cam = vb2_get_drv_priv ( vq ) ;
2013-07-03 04:56:03 +00:00
unsigned int frame ;
2015-03-05 21:00:07 +00:00
int ret ;
2011-06-11 17:46:43 +00:00
2011-08-29 11:51:49 +00:00
if ( cam - > state ! = S_IDLE ) {
2015-03-05 21:00:07 +00:00
mcam_vb_requeue_bufs ( vq , VB2_BUF_STATE_QUEUED ) ;
2011-06-20 19:14:40 +00:00
return - EINVAL ;
2011-08-29 11:51:49 +00:00
}
2015-03-05 20:33:17 +00:00
cam - > frame_state . frames = 0 ;
cam - > frame_state . singles = 0 ;
cam - > frame_state . delivered = 0 ;
2011-06-20 19:14:40 +00:00
cam - > sequence = 0 ;
/*
* Videobuf2 sneakily hoards all the buffers and won ' t
* give them to us until * after * streaming starts . But
* we can ' t actually start streaming until we have a
* destination . So go into a wait state and hope they
* give us buffers soon .
*/
if ( cam - > buffer_mode ! = B_vmalloc & & list_empty ( & cam - > buffers ) ) {
cam - > state = S_BUFWAIT ;
return 0 ;
2011-06-11 17:46:43 +00:00
}
2013-07-03 04:56:03 +00:00
/*
* Ensure clear the left over frame flags
* before every really start streaming
*/
for ( frame = 0 ; frame < cam - > nbufs ; frame + + )
clear_bit ( CF_FRAME_SOF0 + frame , & cam - > flags ) ;
2015-03-05 21:00:07 +00:00
ret = mcam_read_setup ( cam ) ;
if ( ret )
mcam_vb_requeue_bufs ( vq , VB2_BUF_STATE_QUEUED ) ;
return ret ;
2011-06-20 19:14:36 +00:00
}
2014-04-17 05:47:21 +00:00
static void mcam_vb_stop_streaming ( struct vb2_queue * vq )
2011-06-20 19:14:36 +00:00
{
struct mcam_camera * cam = vb2_get_drv_priv ( vq ) ;
2015-03-05 20:33:17 +00:00
cam_dbg ( cam , " stop_streaming: %d frames, %d singles, %d delivered \n " ,
cam - > frame_state . frames , cam - > frame_state . singles ,
cam - > frame_state . delivered ) ;
2011-06-20 19:14:40 +00:00
if ( cam - > state = = S_BUFWAIT ) {
/* They never gave us buffers */
cam - > state = S_IDLE ;
2014-04-17 05:47:21 +00:00
return ;
2011-06-20 19:14:40 +00:00
}
2011-06-20 19:14:36 +00:00
if ( cam - > state ! = S_STREAMING )
2014-04-17 05:47:21 +00:00
return ;
2011-06-20 19:14:36 +00:00
mcam_ctlr_stop_dma ( cam ) ;
2013-07-03 04:56:00 +00:00
/*
* Reset the CCIC PHY after stopping streaming ,
* otherwise , the CCIC may be unstable .
*/
if ( cam - > ctlr_reset )
cam - > ctlr_reset ( cam ) ;
2011-06-11 17:46:43 +00:00
/*
2011-06-20 19:14:36 +00:00
* VB2 reclaims the buffers , so we need to forget
* about them .
2011-06-11 17:46:43 +00:00
*/
2015-03-05 21:00:07 +00:00
mcam_vb_requeue_bufs ( vq , VB2_BUF_STATE_ERROR ) ;
2011-06-11 17:46:43 +00:00
}
2011-06-20 19:14:36 +00:00
static const struct vb2_ops mcam_vb2_ops = {
. queue_setup = mcam_vb_queue_setup ,
. buf_queue = mcam_vb_buf_queue ,
. start_streaming = mcam_vb_start_streaming ,
. stop_streaming = mcam_vb_stop_streaming ,
2014-11-26 22:42:29 +00:00
. wait_prepare = vb2_ops_wait_prepare ,
. wait_finish = vb2_ops_wait_finish ,
2011-06-20 19:14:36 +00:00
} ;
2011-06-11 17:46:43 +00:00
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_DMA_SG
2011-06-30 20:05:27 +00:00
/*
2011-07-08 20:50:46 +00:00
* Scatter / gather mode uses all of the above functions plus a
* few extras to deal with DMA mapping .
2011-06-30 20:05:27 +00:00
*/
2011-07-08 20:50:46 +00:00
static int mcam_vb_sg_buf_init ( struct vb2_buffer * vb )
{
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer * vbuf = to_vb2_v4l2_buffer ( vb ) ;
struct mcam_vb_buffer * mvb = vb_to_mvb ( vbuf ) ;
2011-07-08 20:50:46 +00:00
struct mcam_camera * cam = vb2_get_drv_priv ( vb - > vb2_queue ) ;
int ndesc = cam - > pix_format . sizeimage / PAGE_SIZE + 1 ;
mvb - > dma_desc = dma_alloc_coherent ( cam - > dev ,
ndesc * sizeof ( struct mcam_dma_desc ) ,
& mvb - > dma_desc_pa , GFP_KERNEL ) ;
if ( mvb - > dma_desc = = NULL ) {
cam_err ( cam , " Unable to get DMA descriptor array \n " ) ;
return - ENOMEM ;
}
return 0 ;
}
static int mcam_vb_sg_buf_prepare ( struct vb2_buffer * vb )
{
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer * vbuf = to_vb2_v4l2_buffer ( vb ) ;
struct mcam_vb_buffer * mvb = vb_to_mvb ( vbuf ) ;
2013-08-02 13:20:00 +00:00
struct sg_table * sg_table = vb2_dma_sg_plane_desc ( vb , 0 ) ;
2011-07-08 20:50:46 +00:00
struct mcam_dma_desc * desc = mvb - > dma_desc ;
struct scatterlist * sg ;
int i ;
2014-11-24 11:50:31 +00:00
for_each_sg ( sg_table - > sgl , sg , sg_table - > nents , i ) {
2011-07-08 20:50:46 +00:00
desc - > dma_addr = sg_dma_address ( sg ) ;
desc - > segment_len = sg_dma_len ( sg ) ;
desc + + ;
}
return 0 ;
}
static void mcam_vb_sg_buf_cleanup ( struct vb2_buffer * vb )
{
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct vb2_v4l2_buffer * vbuf = to_vb2_v4l2_buffer ( vb ) ;
2011-07-08 20:50:46 +00:00
struct mcam_camera * cam = vb2_get_drv_priv ( vb - > vb2_queue ) ;
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 13:30:30 +00:00
struct mcam_vb_buffer * mvb = vb_to_mvb ( vbuf ) ;
2011-07-08 20:50:46 +00:00
int ndesc = cam - > pix_format . sizeimage / PAGE_SIZE + 1 ;
dma_free_coherent ( cam - > dev , ndesc * sizeof ( struct mcam_dma_desc ) ,
mvb - > dma_desc , mvb - > dma_desc_pa ) ;
}
2011-06-30 20:05:27 +00:00
static const struct vb2_ops mcam_vb2_sg_ops = {
. queue_setup = mcam_vb_queue_setup ,
. buf_init = mcam_vb_sg_buf_init ,
. buf_prepare = mcam_vb_sg_buf_prepare ,
. buf_queue = mcam_vb_buf_queue ,
. buf_cleanup = mcam_vb_sg_buf_cleanup ,
. start_streaming = mcam_vb_start_streaming ,
. stop_streaming = mcam_vb_stop_streaming ,
2014-11-26 22:42:29 +00:00
. wait_prepare = vb2_ops_wait_prepare ,
. wait_finish = vb2_ops_wait_finish ,
2011-06-30 20:05:27 +00:00
} ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# endif /* MCAM_MODE_DMA_SG */
2011-06-20 19:14:36 +00:00
static int mcam_setup_vb2 ( struct mcam_camera * cam )
{
struct vb2_queue * vq = & cam - > vb_queue ;
2011-06-11 17:46:43 +00:00
2011-06-20 19:14:36 +00:00
memset ( vq , 0 , sizeof ( * vq ) ) ;
vq - > type = V4L2_BUF_TYPE_VIDEO_CAPTURE ;
vq - > drv_priv = cam ;
2014-11-26 22:42:29 +00:00
vq - > lock = & cam - > s_mutex ;
2015-03-03 18:07:27 +00:00
vq - > timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ;
2015-03-09 21:02:23 +00:00
vq - > io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ ;
vq - > buf_struct_size = sizeof ( struct mcam_vb_buffer ) ;
2016-02-15 15:41:51 +00:00
vq - > dev = cam - > dev ;
2011-06-30 20:05:27 +00:00
INIT_LIST_HEAD ( & cam - > buffers ) ;
switch ( cam - > buffer_mode ) {
case B_DMA_contig :
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_DMA_CONTIG
2011-06-30 20:05:27 +00:00
vq - > ops = & mcam_vb2_ops ;
2011-06-20 19:14:40 +00:00
vq - > mem_ops = & vb2_dma_contig_memops ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
cam - > dma_setup = mcam_ctlr_dma_contig ;
cam - > frame_complete = mcam_dma_contig_done ;
# endif
2011-06-30 20:05:27 +00:00
break ;
case B_DMA_sg :
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_DMA_SG
2011-06-30 20:05:27 +00:00
vq - > ops = & mcam_vb2_sg_ops ;
vq - > mem_ops = & vb2_dma_sg_memops ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
cam - > dma_setup = mcam_ctlr_dma_sg ;
cam - > frame_complete = mcam_dma_sg_done ;
# endif
2011-06-30 20:05:27 +00:00
break ;
case B_vmalloc :
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
# ifdef MCAM_MODE_VMALLOC
tasklet_init ( & cam - > s_tasklet , mcam_frame_tasklet ,
( unsigned long ) cam ) ;
2011-06-30 20:05:27 +00:00
vq - > ops = & mcam_vb2_ops ;
2011-06-20 19:14:40 +00:00
vq - > mem_ops = & vb2_vmalloc_memops ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
cam - > dma_setup = mcam_ctlr_dma_vmalloc ;
cam - > frame_complete = mcam_vmalloc_done ;
# endif
2011-06-30 20:05:27 +00:00
break ;
}
2011-06-20 19:14:36 +00:00
return vb2_queue_init ( vq ) ;
}
2011-06-11 17:46:43 +00:00
2011-07-08 20:50:46 +00:00
/* ---------------------------------------------------------------------- */
2011-06-11 17:46:43 +00:00
/*
2011-07-08 20:50:46 +00:00
* The long list of V4L2 ioctl ( ) operations .
2011-06-11 17:46:43 +00:00
*/
static int mcam_vidioc_querycap ( struct file * file , void * priv ,
struct v4l2_capability * cap )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( file ) ;
2015-03-05 07:57:32 +00:00
2011-06-11 17:46:43 +00:00
strcpy ( cap - > driver , " marvell_ccic " ) ;
strcpy ( cap - > card , " marvell_ccic " ) ;
2015-03-05 07:57:32 +00:00
strlcpy ( cap - > bus_info , cam - > bus_info , sizeof ( cap - > bus_info ) ) ;
2014-11-24 09:37:25 +00:00
cap - > device_caps = V4L2_CAP_VIDEO_CAPTURE |
2011-06-11 17:46:43 +00:00
V4L2_CAP_READWRITE | V4L2_CAP_STREAMING ;
2014-11-24 09:37:25 +00:00
cap - > capabilities = cap - > device_caps | V4L2_CAP_DEVICE_CAPS ;
2011-06-11 17:46:43 +00:00
return 0 ;
}
static int mcam_vidioc_enum_fmt_vid_cap ( struct file * filp ,
void * priv , struct v4l2_fmtdesc * fmt )
{
if ( fmt - > index > = N_MCAM_FMTS )
return - EINVAL ;
strlcpy ( fmt - > description , mcam_formats [ fmt - > index ] . desc ,
sizeof ( fmt - > description ) ) ;
fmt - > pixelformat = mcam_formats [ fmt - > index ] . pixelformat ;
return 0 ;
}
static int mcam_vidioc_try_fmt_vid_cap ( struct file * filp , void * priv ,
struct v4l2_format * fmt )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2011-06-11 17:46:43 +00:00
struct mcam_format_struct * f ;
struct v4l2_pix_format * pix = & fmt - > fmt . pix ;
2015-04-09 07:05:35 +00:00
struct v4l2_subdev_pad_config pad_cfg ;
struct v4l2_subdev_format format = {
. which = V4L2_SUBDEV_FORMAT_TRY ,
} ;
2011-06-11 17:46:43 +00:00
int ret ;
f = mcam_find_format ( pix - > pixelformat ) ;
pix - > pixelformat = f - > pixelformat ;
2015-04-09 07:05:35 +00:00
v4l2_fill_mbus_format ( & format . format , pix , f - > mbus_code ) ;
ret = sensor_call ( cam , pad , set_fmt , & pad_cfg , & format ) ;
v4l2_fill_pix_format ( pix , & format . format ) ;
2015-03-09 20:14:36 +00:00
pix - > bytesperline = pix - > width * f - > bpp ;
2013-07-03 04:56:02 +00:00
switch ( f - > pixelformat ) {
case V4L2_PIX_FMT_YUV420 :
case V4L2_PIX_FMT_YVU420 :
2015-03-09 20:14:36 +00:00
pix - > sizeimage = pix - > height * pix - > bytesperline * 3 / 2 ;
2013-07-03 04:56:02 +00:00
break ;
default :
2015-03-09 20:14:36 +00:00
pix - > sizeimage = pix - > height * pix - > bytesperline ;
2013-07-03 04:56:02 +00:00
break ;
}
2015-03-05 08:19:23 +00:00
pix - > colorspace = V4L2_COLORSPACE_SRGB ;
2011-06-11 17:46:43 +00:00
return ret ;
}
static int mcam_vidioc_s_fmt_vid_cap ( struct file * filp , void * priv ,
struct v4l2_format * fmt )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2011-06-11 17:46:43 +00:00
struct mcam_format_struct * f ;
int ret ;
/*
* Can ' t do anything if the device is not idle
* Also can ' t if there are streaming buffers in place .
*/
2015-03-05 20:37:51 +00:00
if ( cam - > state ! = S_IDLE | | vb2_is_busy ( & cam - > vb_queue ) )
2011-06-11 17:46:43 +00:00
return - EBUSY ;
f = mcam_find_format ( fmt - > fmt . pix . pixelformat ) ;
/*
* See if the formatting works in principle .
*/
ret = mcam_vidioc_try_fmt_vid_cap ( filp , priv , fmt ) ;
if ( ret )
return ret ;
/*
* Now we start to change things for real , so let ' s do it
* under lock .
*/
cam - > pix_format = fmt - > fmt . pix ;
cam - > mbus_code = f - > mbus_code ;
/*
* Make sure we have appropriate DMA buffers .
*/
2011-06-20 19:14:40 +00:00
if ( cam - > buffer_mode = = B_vmalloc ) {
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
ret = mcam_check_dma_buffers ( cam ) ;
if ( ret )
goto out ;
2011-06-11 17:46:43 +00:00
}
2011-06-20 19:14:40 +00:00
mcam_set_config_needed ( cam , 1 ) ;
2011-06-11 17:46:43 +00:00
out :
return ret ;
}
/*
* Return our stored notion of how the camera is / should be configured .
* The V4l2 spec wants us to be smarter , and actually get this from
* the camera ( and not mess with it at open time ) . Someday .
*/
static int mcam_vidioc_g_fmt_vid_cap ( struct file * filp , void * priv ,
struct v4l2_format * f )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2011-06-11 17:46:43 +00:00
f - > fmt . pix = cam - > pix_format ;
return 0 ;
}
/*
* We only have one input - the sensor - so minimize the nonsense here .
*/
static int mcam_vidioc_enum_input ( struct file * filp , void * priv ,
struct v4l2_input * input )
{
if ( input - > index ! = 0 )
return - EINVAL ;
input - > type = V4L2_INPUT_TYPE_CAMERA ;
strcpy ( input - > name , " Camera " ) ;
return 0 ;
}
static int mcam_vidioc_g_input ( struct file * filp , void * priv , unsigned int * i )
{
* i = 0 ;
return 0 ;
}
static int mcam_vidioc_s_input ( struct file * filp , void * priv , unsigned int i )
{
if ( i ! = 0 )
return - EINVAL ;
return 0 ;
}
/*
* G / S_PARM . Most of this is done by the sensor , but we are
* the level which controls the number of read buffers .
*/
static int mcam_vidioc_g_parm ( struct file * filp , void * priv ,
2018-01-22 09:00:45 +00:00
struct v4l2_streamparm * a )
2011-06-11 17:46:43 +00:00
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2011-06-11 17:46:43 +00:00
int ret ;
2018-01-22 09:00:45 +00:00
ret = v4l2_g_parm_cap ( video_devdata ( filp ) , cam - > sensor , a ) ;
a - > parm . capture . readbuffers = n_dma_bufs ;
2011-06-11 17:46:43 +00:00
return ret ;
}
static int mcam_vidioc_s_parm ( struct file * filp , void * priv ,
2018-01-22 09:00:45 +00:00
struct v4l2_streamparm * a )
2011-06-11 17:46:43 +00:00
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2011-06-11 17:46:43 +00:00
int ret ;
2018-01-22 09:00:45 +00:00
ret = v4l2_s_parm_cap ( video_devdata ( filp ) , cam - > sensor , a ) ;
a - > parm . capture . readbuffers = n_dma_bufs ;
2011-06-11 17:46:43 +00:00
return ret ;
}
static int mcam_vidioc_enum_framesizes ( struct file * filp , void * priv ,
struct v4l2_frmsizeenum * sizes )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2015-03-04 09:48:00 +00:00
struct mcam_format_struct * f ;
struct v4l2_subdev_frame_size_enum fse = {
. index = sizes - > index ,
. which = V4L2_SUBDEV_FORMAT_ACTIVE ,
} ;
2011-06-11 17:46:43 +00:00
int ret ;
2015-03-04 09:48:00 +00:00
f = mcam_find_format ( sizes - > pixel_format ) ;
if ( f - > pixelformat ! = sizes - > pixel_format )
return - EINVAL ;
fse . code = f - > mbus_code ;
ret = sensor_call ( cam , pad , enum_frame_size , NULL , & fse ) ;
if ( ret )
return ret ;
if ( fse . min_width = = fse . max_width & &
fse . min_height = = fse . max_height ) {
sizes - > type = V4L2_FRMSIZE_TYPE_DISCRETE ;
sizes - > discrete . width = fse . min_width ;
sizes - > discrete . height = fse . min_height ;
return 0 ;
}
sizes - > type = V4L2_FRMSIZE_TYPE_CONTINUOUS ;
sizes - > stepwise . min_width = fse . min_width ;
sizes - > stepwise . max_width = fse . max_width ;
sizes - > stepwise . min_height = fse . min_height ;
sizes - > stepwise . max_height = fse . max_height ;
sizes - > stepwise . step_width = 1 ;
sizes - > stepwise . step_height = 1 ;
return 0 ;
2011-06-11 17:46:43 +00:00
}
static int mcam_vidioc_enum_frameintervals ( struct file * filp , void * priv ,
struct v4l2_frmivalenum * interval )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2015-03-04 09:48:00 +00:00
struct mcam_format_struct * f ;
struct v4l2_subdev_frame_interval_enum fie = {
. index = interval - > index ,
. width = interval - > width ,
. height = interval - > height ,
. which = V4L2_SUBDEV_FORMAT_ACTIVE ,
} ;
2011-06-11 17:46:43 +00:00
int ret ;
2015-03-04 09:48:00 +00:00
f = mcam_find_format ( interval - > pixel_format ) ;
if ( f - > pixelformat ! = interval - > pixel_format )
return - EINVAL ;
fie . code = f - > mbus_code ;
ret = sensor_call ( cam , pad , enum_frame_interval , NULL , & fie ) ;
if ( ret )
return ret ;
interval - > type = V4L2_FRMIVAL_TYPE_DISCRETE ;
interval - > discrete = fie . interval ;
return 0 ;
2011-06-11 17:46:43 +00:00
}
# ifdef CONFIG_VIDEO_ADV_DEBUG
static int mcam_vidioc_g_register ( struct file * file , void * priv ,
struct v4l2_dbg_register * reg )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( file ) ;
2011-06-11 17:46:43 +00:00
2013-05-29 10:00:02 +00:00
if ( reg - > reg > cam - > regs_size - 4 )
return - EINVAL ;
2013-05-29 09:59:44 +00:00
reg - > val = mcam_reg_read ( cam , reg - > reg ) ;
reg - > size = 4 ;
return 0 ;
2011-06-11 17:46:43 +00:00
}
static int mcam_vidioc_s_register ( struct file * file , void * priv ,
2013-03-24 11:28:46 +00:00
const struct v4l2_dbg_register * reg )
2011-06-11 17:46:43 +00:00
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( file ) ;
2011-06-11 17:46:43 +00:00
2013-05-29 10:00:02 +00:00
if ( reg - > reg > cam - > regs_size - 4 )
return - EINVAL ;
2013-05-29 09:59:44 +00:00
mcam_reg_write ( cam , reg - > reg , reg - > val ) ;
return 0 ;
2011-06-11 17:46:43 +00:00
}
# endif
static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
. vidioc_querycap = mcam_vidioc_querycap ,
. vidioc_enum_fmt_vid_cap = mcam_vidioc_enum_fmt_vid_cap ,
. vidioc_try_fmt_vid_cap = mcam_vidioc_try_fmt_vid_cap ,
. vidioc_s_fmt_vid_cap = mcam_vidioc_s_fmt_vid_cap ,
. vidioc_g_fmt_vid_cap = mcam_vidioc_g_fmt_vid_cap ,
. vidioc_enum_input = mcam_vidioc_enum_input ,
. vidioc_g_input = mcam_vidioc_g_input ,
. vidioc_s_input = mcam_vidioc_s_input ,
2015-03-05 20:33:17 +00:00
. vidioc_reqbufs = vb2_ioctl_reqbufs ,
2015-03-05 20:37:51 +00:00
. vidioc_create_bufs = vb2_ioctl_create_bufs ,
2015-03-05 20:33:17 +00:00
. vidioc_querybuf = vb2_ioctl_querybuf ,
. vidioc_qbuf = vb2_ioctl_qbuf ,
. vidioc_dqbuf = vb2_ioctl_dqbuf ,
2015-03-09 21:02:23 +00:00
. vidioc_expbuf = vb2_ioctl_expbuf ,
2015-03-05 20:33:17 +00:00
. vidioc_streamon = vb2_ioctl_streamon ,
. vidioc_streamoff = vb2_ioctl_streamoff ,
2011-06-11 17:46:43 +00:00
. vidioc_g_parm = mcam_vidioc_g_parm ,
. vidioc_s_parm = mcam_vidioc_s_parm ,
. vidioc_enum_framesizes = mcam_vidioc_enum_framesizes ,
. vidioc_enum_frameintervals = mcam_vidioc_enum_frameintervals ,
2015-03-05 16:05:24 +00:00
. vidioc_subscribe_event = v4l2_ctrl_subscribe_event ,
. vidioc_unsubscribe_event = v4l2_event_unsubscribe ,
2011-06-11 17:46:43 +00:00
# ifdef CONFIG_VIDEO_ADV_DEBUG
. vidioc_g_register = mcam_vidioc_g_register ,
. vidioc_s_register = mcam_vidioc_s_register ,
# endif
} ;
/* ---------------------------------------------------------------------- */
/*
2011-07-08 20:50:46 +00:00
* Our various file operations .
2011-06-11 17:46:43 +00:00
*/
2011-07-08 20:50:46 +00:00
static int mcam_v4l_open ( struct file * filp )
{
struct mcam_camera * cam = video_drvdata ( filp ) ;
2015-03-05 20:33:17 +00:00
int ret ;
2011-06-11 17:46:43 +00:00
2011-07-08 20:50:46 +00:00
mutex_lock ( & cam - > s_mutex ) ;
2015-03-05 20:33:17 +00:00
ret = v4l2_fh_open ( filp ) ;
if ( ret )
goto out ;
if ( v4l2_fh_is_singular_file ( filp ) ) {
2013-07-03 04:55:58 +00:00
ret = mcam_ctlr_power_up ( cam ) ;
if ( ret )
goto out ;
2011-07-08 20:50:46 +00:00
__mcam_cam_reset ( cam ) ;
mcam_set_config_needed ( cam , 1 ) ;
}
out :
mutex_unlock ( & cam - > s_mutex ) ;
2015-03-05 16:03:18 +00:00
if ( ret )
v4l2_fh_release ( filp ) ;
2011-07-08 20:50:46 +00:00
return ret ;
2011-06-20 19:14:40 +00:00
}
2011-06-11 17:46:43 +00:00
2011-07-08 20:50:46 +00:00
static int mcam_v4l_release ( struct file * filp )
{
2015-03-05 16:03:18 +00:00
struct mcam_camera * cam = video_drvdata ( filp ) ;
2015-03-05 20:33:17 +00:00
bool last_open ;
2011-06-20 19:14:36 +00:00
2011-07-08 20:50:46 +00:00
mutex_lock ( & cam - > s_mutex ) ;
2015-03-05 20:33:17 +00:00
last_open = v4l2_fh_is_singular_file ( filp ) ;
_vb2_fop_release ( filp , NULL ) ;
if ( last_open ) {
2013-07-03 04:55:58 +00:00
mcam_disable_mipi ( cam ) ;
2011-07-08 20:50:46 +00:00
mcam_ctlr_power_down ( cam ) ;
if ( cam - > buffer_mode = = B_vmalloc & & alloc_bufs_at_read )
mcam_free_dma_bufs ( cam ) ;
}
2013-07-03 04:55:58 +00:00
2011-07-08 20:50:46 +00:00
mutex_unlock ( & cam - > s_mutex ) ;
return 0 ;
2011-06-11 17:46:43 +00:00
}
2011-07-08 20:50:46 +00:00
static const struct v4l2_file_operations mcam_v4l_fops = {
. owner = THIS_MODULE ,
. open = mcam_v4l_open ,
. release = mcam_v4l_release ,
2015-03-05 20:33:17 +00:00
. read = vb2_fop_read ,
. poll = vb2_fop_poll ,
. mmap = vb2_fop_mmap ,
2011-07-08 20:50:46 +00:00
. unlocked_ioctl = video_ioctl2 ,
} ;
/*
* This template device holds all of those v4l2 methods ; we
* clone it for specific real devices .
*/
2017-08-26 12:57:26 +00:00
static const struct video_device mcam_v4l_template = {
2011-07-08 20:50:46 +00:00
. name = " mcam " ,
. fops = & mcam_v4l_fops ,
. ioctl_ops = & mcam_v4l_ioctl_ops ,
. release = video_device_release_empty ,
} ;
/* ---------------------------------------------------------------------- */
/*
* Interrupt handler stuff
*/
2011-06-11 17:46:43 +00:00
static void mcam_frame_complete ( struct mcam_camera * cam , int frame )
{
/*
* Basic frame housekeeping .
*/
set_bit ( frame , & cam - > flags ) ;
clear_bit ( CF_DMA_ACTIVE , & cam - > flags ) ;
2011-06-20 19:14:40 +00:00
cam - > next_buf = frame ;
2015-03-05 20:48:39 +00:00
cam - > buf_seq [ frame ] = cam - > sequence + + ;
2012-12-15 08:57:50 +00:00
cam - > frame_state . frames + + ;
2011-06-11 17:46:43 +00:00
/*
2011-06-30 20:05:27 +00:00
* " This should never happen "
2011-06-11 17:46:43 +00:00
*/
2011-06-30 20:05:27 +00:00
if ( cam - > state ! = S_STREAMING )
return ;
/*
* Process the frame and set up the next one .
*/
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
cam - > frame_complete ( cam , frame ) ;
2011-06-11 17:46:43 +00:00
}
2011-07-08 20:50:46 +00:00
/*
* The interrupt handler ; this needs to be called from the
* platform irq handler with the lock held .
*/
2011-06-11 17:46:43 +00:00
int mccic_irq ( struct mcam_camera * cam , unsigned int irqs )
{
unsigned int frame , handled = 0 ;
mcam_reg_write ( cam , REG_IRQSTAT , FRAMEIRQS ) ; /* Clear'em all */
/*
* Handle any frame completions . There really should
* not be more than one of these , or we have fallen
* far behind .
2011-06-30 20:05:27 +00:00
*
* When running in S / G mode , the frame number lacks any
* real meaning - there ' s only one descriptor array - but
* the controller still picks a different one to signal
* each time .
2011-06-11 17:46:43 +00:00
*/
for ( frame = 0 ; frame < cam - > nbufs ; frame + + )
2013-07-03 04:56:03 +00:00
if ( irqs & ( IRQ_EOF0 < < frame ) & &
test_bit ( CF_FRAME_SOF0 + frame , & cam - > flags ) ) {
2011-06-11 17:46:43 +00:00
mcam_frame_complete ( cam , frame ) ;
handled = 1 ;
2013-07-03 04:56:03 +00:00
clear_bit ( CF_FRAME_SOF0 + frame , & cam - > flags ) ;
2012-03-16 22:14:54 +00:00
if ( cam - > buffer_mode = = B_DMA_sg )
break ;
2011-06-11 17:46:43 +00:00
}
/*
* If a frame starts , note that we have DMA active . This
* code assumes that we won ' t get multiple frame interrupts
* at once ; may want to rethink that .
*/
2013-07-03 04:56:03 +00:00
for ( frame = 0 ; frame < cam - > nbufs ; frame + + ) {
if ( irqs & ( IRQ_SOF0 < < frame ) ) {
set_bit ( CF_FRAME_SOF0 + frame , & cam - > flags ) ;
handled = IRQ_HANDLED ;
}
}
if ( handled = = IRQ_HANDLED ) {
2011-06-11 17:46:43 +00:00
set_bit ( CF_DMA_ACTIVE , & cam - > flags ) ;
2011-06-30 20:05:27 +00:00
if ( cam - > buffer_mode = = B_DMA_sg )
mcam_ctlr_stop ( cam ) ;
2011-06-11 17:46:43 +00:00
}
return handled ;
}
2018-05-25 15:25:11 +00:00
EXPORT_SYMBOL_GPL ( mccic_irq ) ;
2011-06-11 17:46:43 +00:00
2011-07-08 20:50:46 +00:00
/* ---------------------------------------------------------------------- */
2011-06-11 17:46:43 +00:00
/*
* Registration and such .
*/
static struct ov7670_config sensor_cfg = {
/*
* Exclude QCIF mode , because it only captures a tiny portion
* of the sensor FOV
*/
. min_width = 320 ,
. min_height = 240 ,
} ;
int mccic_register ( struct mcam_camera * cam )
{
struct i2c_board_info ov7670_info = {
. type = " ov7670 " ,
2011-06-11 17:46:47 +00:00
. addr = 0x42 > > 1 ,
2011-06-11 17:46:43 +00:00
. platform_data = & sensor_cfg ,
} ;
int ret ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
/*
* Validate the requested buffer mode .
*/
if ( buffer_mode > = 0 )
cam - > buffer_mode = buffer_mode ;
if ( cam - > buffer_mode = = B_DMA_sg & &
2013-05-29 09:59:44 +00:00
cam - > chip_id = = MCAM_CAFE ) {
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
printk ( KERN_ERR " marvell-cam: Cafe can't do S/G I/O, attempting vmalloc mode instead \n " ) ;
[media] marvell-cam: Allow selection of supported buffer modes
The Marvell camera core can support all three videobuf2 buffer modes, which
is slick, but it also requires that all three modes be built and present,
even though only one is likely to be used. This patch allows the supported
modes to be selected at configuration time, reducing the footprint of the
driver. Prior to this patch, the MMP camera driver looked like this:
mmp_camera 19092 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_dma_contig 2188 1 mmp_camera
videobuf2_vmalloc 1718 1 mmp_camera
videobuf2_memops 2100 3 videobuf2_dma_sg,videobuf2_dma_contig,videobuf2_vmalloc
Afterward, instead, with scatter/gather only configured:
mmp_camera 16021 0
videobuf2_core 15542 1 mmp_camera
videobuf2_dma_sg 3173 1 mmp_camera
videobuf2_memops 2100 1 videobuf2_dma_sg
The total goes from 43,813 bytes to 36,836.
The emphasis has been on simplicity and minimal #ifdef use rather than on
squeezing out every possible byte of code. For configuration, the driver
simply looks at which videobuf2 modes have been configured in and supports
them all; it's simplistic but should be good enough.
The cafe driver is set to support vmalloc and dma-contig; mmp supports only
dma-sg, since that's the only mode that really makes sense to use.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2011-07-08 20:50:49 +00:00
cam - > buffer_mode = B_vmalloc ;
}
if ( ! mcam_buffer_mode_supported ( cam - > buffer_mode ) ) {
printk ( KERN_ERR " marvell-cam: buffer mode %d unsupported \n " ,
cam - > buffer_mode ) ;
return - EINVAL ;
}
2011-06-11 17:46:43 +00:00
/*
* Register with V4L
*/
ret = v4l2_device_register ( cam - > dev , & cam - > v4l2_dev ) ;
if ( ret )
return ret ;
mutex_init ( & cam - > s_mutex ) ;
cam - > state = S_NOTREADY ;
mcam_set_config_needed ( cam , 1 ) ;
cam - > pix_format = mcam_def_pix_format ;
cam - > mbus_code = mcam_def_mbus_code ;
mcam_ctlr_init ( cam ) ;
2015-03-05 15:00:11 +00:00
/*
* Get the v4l2 setup done .
*/
ret = v4l2_ctrl_handler_init ( & cam - > ctrl_handler , 10 ) ;
if ( ret )
goto out_unregister ;
cam - > v4l2_dev . ctrl_handler = & cam - > ctrl_handler ;
2011-06-11 17:46:43 +00:00
/*
* Try to find the sensor .
*/
2011-06-11 17:46:44 +00:00
sensor_cfg . clock_speed = cam - > clock_speed ;
sensor_cfg . use_smbus = cam - > use_smbus ;
2011-06-11 17:46:43 +00:00
cam - > sensor_addr = ov7670_info . addr ;
cam - > sensor = v4l2_i2c_new_subdev_board ( & cam - > v4l2_dev ,
2011-06-11 17:46:48 +00:00
cam - > i2c_adapter , & ov7670_info , NULL ) ;
2011-06-11 17:46:43 +00:00
if ( cam - > sensor = = NULL ) {
ret = - ENODEV ;
goto out_unregister ;
}
ret = mcam_cam_init ( cam ) ;
if ( ret )
goto out_unregister ;
2013-01-29 10:58:48 +00:00
2015-03-05 20:33:17 +00:00
ret = mcam_setup_vb2 ( cam ) ;
if ( ret )
goto out_unregister ;
2011-06-11 17:46:43 +00:00
mutex_lock ( & cam - > s_mutex ) ;
cam - > vdev = mcam_v4l_template ;
cam - > vdev . v4l2_dev = & cam - > v4l2_dev ;
2015-03-05 20:33:17 +00:00
cam - > vdev . lock = & cam - > s_mutex ;
cam - > vdev . queue = & cam - > vb_queue ;
2013-01-29 10:58:48 +00:00
video_set_drvdata ( & cam - > vdev , cam ) ;
2011-06-11 17:46:43 +00:00
ret = video_register_device ( & cam - > vdev , VFL_TYPE_GRABBER , - 1 ) ;
2015-03-05 20:33:17 +00:00
if ( ret ) {
mutex_unlock ( & cam - > s_mutex ) ;
goto out_unregister ;
}
2011-06-11 17:46:43 +00:00
/*
* If so requested , try to get our DMA buffers now .
*/
2011-06-20 19:14:40 +00:00
if ( cam - > buffer_mode = = B_vmalloc & & ! alloc_bufs_at_read ) {
2011-06-11 17:46:43 +00:00
if ( mcam_alloc_dma_bufs ( cam , 1 ) )
[media] marvell-ccic: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-18 19:44:09 +00:00
cam_warn ( cam , " Unable to alloc DMA buffers at load will try again later. " ) ;
2011-06-11 17:46:43 +00:00
}
mutex_unlock ( & cam - > s_mutex ) ;
2015-03-05 20:33:17 +00:00
return 0 ;
2011-06-11 17:46:43 +00:00
out_unregister :
2015-03-05 15:00:11 +00:00
v4l2_ctrl_handler_free ( & cam - > ctrl_handler ) ;
2011-06-11 17:46:43 +00:00
v4l2_device_unregister ( & cam - > v4l2_dev ) ;
return ret ;
}
2018-05-25 15:25:11 +00:00
EXPORT_SYMBOL_GPL ( mccic_register ) ;
2011-06-11 17:46:43 +00:00
void mccic_shutdown ( struct mcam_camera * cam )
{
2011-06-11 17:46:49 +00:00
/*
* If we have no users ( and we really , really should have no
* users ) the device will already be powered down . Trying to
* take it down again will wedge the machine , which is frowned
* upon .
*/
2015-03-05 20:33:17 +00:00
if ( ! list_empty ( & cam - > vdev . fh_list ) ) {
2011-06-11 17:46:43 +00:00
cam_warn ( cam , " Removing a device with users! \n " ) ;
2011-06-11 17:46:49 +00:00
mcam_ctlr_power_down ( cam ) ;
}
2011-06-20 19:14:40 +00:00
if ( cam - > buffer_mode = = B_vmalloc )
mcam_free_dma_bufs ( cam ) ;
2011-06-11 17:46:43 +00:00
video_unregister_device ( & cam - > vdev ) ;
2013-01-29 10:58:48 +00:00
v4l2_ctrl_handler_free ( & cam - > ctrl_handler ) ;
2011-06-11 17:46:43 +00:00
v4l2_device_unregister ( & cam - > v4l2_dev ) ;
}
2018-05-25 15:25:11 +00:00
EXPORT_SYMBOL_GPL ( mccic_shutdown ) ;
2011-06-11 17:46:43 +00:00
/*
* Power management
*/
# ifdef CONFIG_PM
void mccic_suspend ( struct mcam_camera * cam )
{
2011-12-30 17:13:41 +00:00
mutex_lock ( & cam - > s_mutex ) ;
2015-03-05 20:33:17 +00:00
if ( ! list_empty ( & cam - > vdev . fh_list ) ) {
2011-12-30 17:13:41 +00:00
enum mcam_state cstate = cam - > state ;
2011-06-11 17:46:43 +00:00
2011-12-30 17:13:41 +00:00
mcam_ctlr_stop_dma ( cam ) ;
mcam_ctlr_power_down ( cam ) ;
cam - > state = cstate ;
}
mutex_unlock ( & cam - > s_mutex ) ;
2011-06-11 17:46:43 +00:00
}
2018-05-25 15:25:11 +00:00
EXPORT_SYMBOL_GPL ( mccic_suspend ) ;
2011-06-11 17:46:43 +00:00
int mccic_resume ( struct mcam_camera * cam )
{
int ret = 0 ;
mutex_lock ( & cam - > s_mutex ) ;
2015-03-05 20:33:17 +00:00
if ( ! list_empty ( & cam - > vdev . fh_list ) ) {
2013-07-03 04:55:58 +00:00
ret = mcam_ctlr_power_up ( cam ) ;
if ( ret ) {
mutex_unlock ( & cam - > s_mutex ) ;
return ret ;
}
2011-06-11 17:46:43 +00:00
__mcam_cam_reset ( cam ) ;
} else {
mcam_ctlr_power_down ( cam ) ;
}
mutex_unlock ( & cam - > s_mutex ) ;
set_bit ( CF_CONFIG_NEEDED , & cam - > flags ) ;
2011-12-30 17:13:41 +00:00
if ( cam - > state = = S_STREAMING ) {
/*
* If there was a buffer in the DMA engine at suspend
* time , put it back on the queue or we ' ll forget about it .
*/
if ( cam - > buffer_mode = = B_DMA_sg & & cam - > vb_bufs [ 0 ] )
list_add ( & cam - > vb_bufs [ 0 ] - > queue , & cam - > buffers ) ;
2011-06-20 19:14:40 +00:00
ret = mcam_read_setup ( cam ) ;
2011-12-30 17:13:41 +00:00
}
2011-06-11 17:46:43 +00:00
return ret ;
}
2018-05-25 15:25:11 +00:00
EXPORT_SYMBOL_GPL ( mccic_resume ) ;
2011-06-11 17:46:43 +00:00
# endif /* CONFIG_PM */
2018-05-25 15:25:11 +00:00
MODULE_LICENSE ( " GPL v2 " ) ;
MODULE_AUTHOR ( " Jonathan Corbet <corbet@lwn.net> " ) ;