2009-09-18 18:17:20 -06:00
|
|
|
/*
|
|
|
|
* adv7180.c Analog Devices ADV7180 video decoder driver
|
|
|
|
* Copyright (c) 2009 Intel Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/i2c.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2009-09-18 18:17:20 -06:00
|
|
|
#include <media/v4l2-ioctl.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <media/v4l2-device.h>
|
2012-07-11 08:29:33 -06:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2009-09-18 18:17:20 -06:00
|
|
|
#include <media/v4l2-chip-ident.h>
|
2009-09-22 03:07:06 -06:00
|
|
|
#include <linux/mutex.h>
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2009-09-22 03:05:42 -06:00
|
|
|
#define ADV7180_INPUT_CONTROL_REG 0x00
|
|
|
|
#define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM 0x00
|
|
|
|
#define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM_PED 0x10
|
|
|
|
#define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_J_SECAM 0x20
|
|
|
|
#define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_M_SECAM 0x30
|
|
|
|
#define ADV7180_INPUT_CONTROL_NTSC_J 0x40
|
|
|
|
#define ADV7180_INPUT_CONTROL_NTSC_M 0x50
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL60 0x60
|
|
|
|
#define ADV7180_INPUT_CONTROL_NTSC_443 0x70
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_BG 0x80
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_N 0x90
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_M 0xa0
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_M_PED 0xb0
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_COMB_N 0xc0
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_COMB_N_PED 0xd0
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_SECAM 0xe0
|
|
|
|
#define ADV7180_INPUT_CONTROL_PAL_SECAM_PED 0xf0
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f
|
2009-09-22 03:05:42 -06:00
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
#define ADV7180_EXTENDED_OUTPUT_CONTROL_REG 0x04
|
|
|
|
#define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
#define ADV7180_AUTODETECT_ENABLE_REG 0x07
|
|
|
|
#define ADV7180_AUTODETECT_DEFAULT 0x7f
|
2012-07-11 08:29:33 -06:00
|
|
|
/* Contrast */
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_CON_REG 0x08 /*Unsigned */
|
2012-07-11 08:29:33 -06:00
|
|
|
#define ADV7180_CON_MIN 0
|
|
|
|
#define ADV7180_CON_DEF 128
|
|
|
|
#define ADV7180_CON_MAX 255
|
|
|
|
/* Brightness*/
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_BRI_REG 0x0a /*Signed */
|
2012-07-11 08:29:33 -06:00
|
|
|
#define ADV7180_BRI_MIN -128
|
|
|
|
#define ADV7180_BRI_DEF 0
|
|
|
|
#define ADV7180_BRI_MAX 127
|
|
|
|
/* Hue */
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_HUE_REG 0x0b /*Signed, inverted */
|
2012-07-11 08:29:33 -06:00
|
|
|
#define ADV7180_HUE_MIN -127
|
|
|
|
#define ADV7180_HUE_DEF 0
|
|
|
|
#define ADV7180_HUE_MAX 128
|
2012-04-12 09:39:36 -06:00
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
#define ADV7180_ADI_CTRL_REG 0x0e
|
|
|
|
#define ADV7180_ADI_CTRL_IRQ_SPACE 0x20
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_PWR_MAN_REG 0x0f
|
|
|
|
#define ADV7180_PWR_MAN_ON 0x04
|
|
|
|
#define ADV7180_PWR_MAN_OFF 0x24
|
|
|
|
#define ADV7180_PWR_MAN_RES 0x80
|
|
|
|
|
2009-09-22 03:05:42 -06:00
|
|
|
#define ADV7180_STATUS1_REG 0x10
|
|
|
|
#define ADV7180_STATUS1_IN_LOCK 0x01
|
|
|
|
#define ADV7180_STATUS1_AUTOD_MASK 0x70
|
2009-09-18 18:17:20 -06:00
|
|
|
#define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00
|
|
|
|
#define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_M 0x20
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_60 0x30
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_B_G 0x40
|
|
|
|
#define ADV7180_STATUS1_AUTOD_SECAM 0x50
|
|
|
|
#define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60
|
|
|
|
#define ADV7180_STATUS1_AUTOD_SECAM_525 0x70
|
|
|
|
|
|
|
|
#define ADV7180_IDENT_REG 0x11
|
|
|
|
#define ADV7180_ID_7180 0x18
|
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
#define ADV7180_ICONF1_ADI 0x40
|
|
|
|
#define ADV7180_ICONF1_ACTIVE_LOW 0x01
|
|
|
|
#define ADV7180_ICONF1_PSYNC_ONLY 0x10
|
|
|
|
#define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0
|
2012-07-11 08:29:33 -06:00
|
|
|
/* Saturation */
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_SD_SAT_CB_REG 0xe3 /*Unsigned */
|
|
|
|
#define ADV7180_SD_SAT_CR_REG 0xe4 /*Unsigned */
|
2012-07-11 08:29:33 -06:00
|
|
|
#define ADV7180_SAT_MIN 0
|
|
|
|
#define ADV7180_SAT_DEF 128
|
|
|
|
#define ADV7180_SAT_MAX 255
|
2012-04-12 09:39:36 -06:00
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
#define ADV7180_IRQ1_LOCK 0x01
|
|
|
|
#define ADV7180_IRQ1_UNLOCK 0x02
|
|
|
|
#define ADV7180_ISR1_ADI 0x42
|
|
|
|
#define ADV7180_ICR1_ADI 0x43
|
|
|
|
#define ADV7180_IMR1_ADI 0x44
|
|
|
|
#define ADV7180_IMR2_ADI 0x48
|
|
|
|
#define ADV7180_IRQ3_AD_CHANGE 0x08
|
|
|
|
#define ADV7180_ISR3_ADI 0x4A
|
|
|
|
#define ADV7180_ICR3_ADI 0x4B
|
|
|
|
#define ADV7180_IMR3_ADI 0x4C
|
|
|
|
#define ADV7180_IMR4_ADI 0x50
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
#define ADV7180_NTSC_V_BIT_END_REG 0xE6
|
|
|
|
#define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F
|
|
|
|
|
2009-09-18 18:17:20 -06:00
|
|
|
struct adv7180_state {
|
2012-07-11 08:29:33 -06:00
|
|
|
struct v4l2_ctrl_handler ctrl_hdl;
|
2009-09-22 03:06:34 -06:00
|
|
|
struct v4l2_subdev sd;
|
2009-09-22 03:07:06 -06:00
|
|
|
struct work_struct work;
|
|
|
|
struct mutex mutex; /* mutual excl. when accessing chip */
|
|
|
|
int irq;
|
2009-09-22 03:06:34 -06:00
|
|
|
v4l2_std_id curr_norm;
|
|
|
|
bool autodetect;
|
2012-04-12 09:39:36 -06:00
|
|
|
u8 input;
|
2009-09-18 18:17:20 -06:00
|
|
|
};
|
2012-07-11 08:29:33 -06:00
|
|
|
#define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
|
|
|
|
struct adv7180_state, \
|
|
|
|
ctrl_hdl)->sd)
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2009-09-22 03:05:42 -06:00
|
|
|
static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
|
2009-09-18 18:17:20 -06:00
|
|
|
{
|
2013-04-11 15:06:46 -06:00
|
|
|
/* in case V4L2_IN_ST_NO_SIGNAL */
|
|
|
|
if (!(status1 & ADV7180_STATUS1_IN_LOCK))
|
|
|
|
return V4L2_STD_UNKNOWN;
|
|
|
|
|
2009-09-18 18:17:20 -06:00
|
|
|
switch (status1 & ADV7180_STATUS1_AUTOD_MASK) {
|
|
|
|
case ADV7180_STATUS1_AUTOD_NTSM_M_J:
|
2009-09-22 03:05:42 -06:00
|
|
|
return V4L2_STD_NTSC;
|
2009-09-18 18:17:20 -06:00
|
|
|
case ADV7180_STATUS1_AUTOD_NTSC_4_43:
|
|
|
|
return V4L2_STD_NTSC_443;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_M:
|
|
|
|
return V4L2_STD_PAL_M;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_60:
|
|
|
|
return V4L2_STD_PAL_60;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_B_G:
|
|
|
|
return V4L2_STD_PAL;
|
|
|
|
case ADV7180_STATUS1_AUTOD_SECAM:
|
|
|
|
return V4L2_STD_SECAM;
|
|
|
|
case ADV7180_STATUS1_AUTOD_PAL_COMB:
|
|
|
|
return V4L2_STD_PAL_Nc | V4L2_STD_PAL_N;
|
|
|
|
case ADV7180_STATUS1_AUTOD_SECAM_525:
|
|
|
|
return V4L2_STD_SECAM;
|
|
|
|
default:
|
|
|
|
return V4L2_STD_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 03:06:34 -06:00
|
|
|
static int v4l2_std_to_adv7180(v4l2_std_id std)
|
|
|
|
{
|
|
|
|
if (std == V4L2_STD_PAL_60)
|
|
|
|
return ADV7180_INPUT_CONTROL_PAL60;
|
|
|
|
if (std == V4L2_STD_NTSC_443)
|
|
|
|
return ADV7180_INPUT_CONTROL_NTSC_443;
|
|
|
|
if (std == V4L2_STD_PAL_N)
|
|
|
|
return ADV7180_INPUT_CONTROL_PAL_N;
|
|
|
|
if (std == V4L2_STD_PAL_M)
|
|
|
|
return ADV7180_INPUT_CONTROL_PAL_M;
|
|
|
|
if (std == V4L2_STD_PAL_Nc)
|
|
|
|
return ADV7180_INPUT_CONTROL_PAL_COMB_N;
|
|
|
|
|
|
|
|
if (std & V4L2_STD_PAL)
|
|
|
|
return ADV7180_INPUT_CONTROL_PAL_BG;
|
|
|
|
if (std & V4L2_STD_NTSC)
|
|
|
|
return ADV7180_INPUT_CONTROL_NTSC_M;
|
|
|
|
if (std & V4L2_STD_SECAM)
|
|
|
|
return ADV7180_INPUT_CONTROL_PAL_SECAM;
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-09-22 03:05:42 -06:00
|
|
|
static u32 adv7180_status_to_v4l2(u8 status1)
|
|
|
|
{
|
|
|
|
if (!(status1 & ADV7180_STATUS1_IN_LOCK))
|
|
|
|
return V4L2_IN_ST_NO_SIGNAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __adv7180_status(struct i2c_client *client, u32 *status,
|
2012-04-12 09:39:36 -06:00
|
|
|
v4l2_std_id *std)
|
2009-09-22 03:05:42 -06:00
|
|
|
{
|
|
|
|
int status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG);
|
|
|
|
|
|
|
|
if (status1 < 0)
|
|
|
|
return status1;
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
*status = adv7180_status_to_v4l2(status1);
|
|
|
|
if (std)
|
|
|
|
*std = adv7180_std_to_v4l2(status1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:17:20 -06:00
|
|
|
static inline struct adv7180_state *to_state(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
return container_of(sd, struct adv7180_state, sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
|
|
|
|
{
|
2009-09-22 03:06:34 -06:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
2009-09-22 03:07:06 -06:00
|
|
|
int err = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2009-09-22 03:06:34 -06:00
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
/* when we are interrupt driven we know the state */
|
|
|
|
if (!state->autodetect || state->irq > 0)
|
2009-09-22 03:06:34 -06:00
|
|
|
*std = state->curr_norm;
|
|
|
|
else
|
|
|
|
err = __adv7180_status(v4l2_get_subdevdata(sd), NULL, std);
|
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
mutex_unlock(&state->mutex);
|
2009-09-22 03:06:34 -06:00
|
|
|
return err;
|
2009-09-22 03:05:42 -06:00
|
|
|
}
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input,
|
|
|
|
u32 output, u32 config)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2012-07-11 08:29:33 -06:00
|
|
|
/* We cannot discriminate between LQFP and 40-pin LFCSP, so accept
|
2012-04-12 09:39:36 -06:00
|
|
|
* all inputs and let the card driver take care of validation
|
|
|
|
*/
|
|
|
|
if ((input & ADV7180_INPUT_CONTROL_INSEL_MASK) != input)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = i2c_smbus_read_byte_data(client, ADV7180_INPUT_CONTROL_REG);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK;
|
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
|
|
|
ADV7180_INPUT_CONTROL_REG, ret | input);
|
|
|
|
state->input = input;
|
|
|
|
out:
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-22 03:05:42 -06:00
|
|
|
static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
|
|
|
|
{
|
2009-09-22 03:07:06 -06:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = __adv7180_status(v4l2_get_subdevdata(sd), status, NULL);
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
2009-09-18 18:17:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_g_chip_ident(struct v4l2_subdev *sd,
|
2012-04-12 09:39:36 -06:00
|
|
|
struct v4l2_dbg_chip_ident *chip)
|
2009-09-18 18:17:20 -06:00
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
|
|
|
|
return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7180, 0);
|
|
|
|
}
|
|
|
|
|
2009-09-22 03:06:34 -06:00
|
|
|
static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
2009-09-22 03:07:06 -06:00
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-09-22 03:06:34 -06:00
|
|
|
|
|
|
|
/* all standards -> autodetect */
|
|
|
|
if (std == V4L2_STD_ALL) {
|
2012-04-12 09:39:36 -06:00
|
|
|
ret =
|
|
|
|
i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG,
|
|
|
|
ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
|
|
|
|
| state->input);
|
2009-09-22 03:06:34 -06:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
__adv7180_status(client, NULL, &state->curr_norm);
|
2009-09-22 03:06:34 -06:00
|
|
|
state->autodetect = true;
|
|
|
|
} else {
|
|
|
|
ret = v4l2_std_to_adv7180(std);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
2012-04-12 09:39:36 -06:00
|
|
|
ADV7180_INPUT_CONTROL_REG,
|
|
|
|
ret | state->input);
|
2009-09-22 03:06:34 -06:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
state->curr_norm = std;
|
|
|
|
state->autodetect = false;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
out:
|
2009-09-22 03:07:06 -06:00
|
|
|
mutex_unlock(&state->mutex);
|
2009-09-22 03:06:34 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-11 08:29:33 -06:00
|
|
|
static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
|
2012-04-12 09:39:36 -06:00
|
|
|
{
|
2012-07-11 08:29:33 -06:00
|
|
|
struct v4l2_subdev *sd = to_adv7180_sd(ctrl);
|
2012-04-12 09:39:36 -06:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
2012-07-11 08:29:33 -06:00
|
|
|
int val;
|
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-07-11 08:29:33 -06:00
|
|
|
val = ctrl->val;
|
2012-04-12 09:39:36 -06:00
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_BRIGHTNESS:
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_BRI_REG, val);
|
2012-04-12 09:39:36 -06:00
|
|
|
break;
|
|
|
|
case V4L2_CID_HUE:
|
|
|
|
/*Hue is inverted according to HSL chart */
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_HUE_REG, -val);
|
2012-04-12 09:39:36 -06:00
|
|
|
break;
|
|
|
|
case V4L2_CID_CONTRAST:
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_CON_REG, val);
|
2012-04-12 09:39:36 -06:00
|
|
|
break;
|
|
|
|
case V4L2_CID_SATURATION:
|
|
|
|
/*
|
|
|
|
*This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE
|
|
|
|
*Let's not confuse the user, everybody understands saturation
|
|
|
|
*/
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_SD_SAT_CB_REG,
|
|
|
|
val);
|
2012-04-12 09:39:36 -06:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_SD_SAT_CR_REG,
|
|
|
|
val);
|
2012-04-12 09:39:36 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-11 08:29:33 -06:00
|
|
|
static const struct v4l2_ctrl_ops adv7180_ctrl_ops = {
|
|
|
|
.s_ctrl = adv7180_s_ctrl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int adv7180_init_controls(struct adv7180_state *state)
|
|
|
|
{
|
|
|
|
v4l2_ctrl_handler_init(&state->ctrl_hdl, 4);
|
|
|
|
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_BRIGHTNESS, ADV7180_BRI_MIN,
|
|
|
|
ADV7180_BRI_MAX, 1, ADV7180_BRI_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_CONTRAST, ADV7180_CON_MIN,
|
|
|
|
ADV7180_CON_MAX, 1, ADV7180_CON_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_SATURATION, ADV7180_SAT_MIN,
|
|
|
|
ADV7180_SAT_MAX, 1, ADV7180_SAT_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
|
|
|
|
V4L2_CID_HUE, ADV7180_HUE_MIN,
|
|
|
|
ADV7180_HUE_MAX, 1, ADV7180_HUE_DEF);
|
|
|
|
state->sd.ctrl_handler = &state->ctrl_hdl;
|
|
|
|
if (state->ctrl_hdl.error) {
|
|
|
|
int err = state->ctrl_hdl.error;
|
|
|
|
|
|
|
|
v4l2_ctrl_handler_free(&state->ctrl_hdl);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
v4l2_ctrl_handler_setup(&state->ctrl_hdl);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static void adv7180_exit_controls(struct adv7180_state *state)
|
|
|
|
{
|
|
|
|
v4l2_ctrl_handler_free(&state->ctrl_hdl);
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:17:20 -06:00
|
|
|
static const struct v4l2_subdev_video_ops adv7180_video_ops = {
|
|
|
|
.querystd = adv7180_querystd,
|
2009-09-22 03:05:42 -06:00
|
|
|
.g_input_status = adv7180_g_input_status,
|
2012-04-12 09:39:36 -06:00
|
|
|
.s_routing = adv7180_s_routing,
|
2009-09-18 18:17:20 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_subdev_core_ops adv7180_core_ops = {
|
|
|
|
.g_chip_ident = adv7180_g_chip_ident,
|
2009-09-22 03:06:34 -06:00
|
|
|
.s_std = adv7180_s_std,
|
2009-09-18 18:17:20 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_subdev_ops adv7180_ops = {
|
|
|
|
.core = &adv7180_core_ops,
|
|
|
|
.video = &adv7180_video_ops,
|
|
|
|
};
|
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
static void adv7180_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = container_of(work, struct adv7180_state,
|
2012-04-12 09:39:36 -06:00
|
|
|
work);
|
2009-09-22 03:07:06 -06:00
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
|
|
|
|
u8 isr3;
|
|
|
|
|
|
|
|
mutex_lock(&state->mutex);
|
|
|
|
i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG,
|
2012-04-12 09:39:36 -06:00
|
|
|
ADV7180_ADI_CTRL_IRQ_SPACE);
|
2009-09-22 03:07:06 -06:00
|
|
|
isr3 = i2c_smbus_read_byte_data(client, ADV7180_ISR3_ADI);
|
|
|
|
/* clear */
|
|
|
|
i2c_smbus_write_byte_data(client, ADV7180_ICR3_ADI, isr3);
|
|
|
|
i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 0);
|
|
|
|
|
|
|
|
if (isr3 & ADV7180_IRQ3_AD_CHANGE && state->autodetect)
|
|
|
|
__adv7180_status(client, NULL, &state->curr_norm);
|
|
|
|
mutex_unlock(&state->mutex);
|
|
|
|
|
|
|
|
enable_irq(state->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t adv7180_irq(int irq, void *devid)
|
|
|
|
{
|
|
|
|
struct adv7180_state *state = devid;
|
|
|
|
|
|
|
|
schedule_work(&state->work);
|
|
|
|
|
|
|
|
disable_irq_nosync(state->irq);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
static int init_device(struct i2c_client *client, struct adv7180_state *state)
|
2009-09-18 18:17:20 -06:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Initialize adv7180 */
|
2009-09-22 03:07:06 -06:00
|
|
|
/* Enable autodetection */
|
2012-04-12 09:39:36 -06:00
|
|
|
if (state->autodetect) {
|
|
|
|
ret =
|
|
|
|
i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG,
|
|
|
|
ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
|
|
|
|
| state->input);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
ret =
|
|
|
|
i2c_smbus_write_byte_data(client,
|
|
|
|
ADV7180_AUTODETECT_ENABLE_REG,
|
|
|
|
ADV7180_AUTODETECT_DEFAULT);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
ret = v4l2_std_to_adv7180(state->curr_norm);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
ret =
|
|
|
|
i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG,
|
|
|
|
ret | state->input);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
2009-09-22 03:07:06 -06:00
|
|
|
/* ITU-R BT.656-4 compatible */
|
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
2012-04-12 09:39:36 -06:00
|
|
|
ADV7180_EXTENDED_OUTPUT_CONTROL_REG,
|
|
|
|
ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);
|
2009-09-22 03:07:06 -06:00
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Manually set V bit end position in NTSC mode */
|
|
|
|
ret = i2c_smbus_write_byte_data(client,
|
|
|
|
ADV7180_NTSC_V_BIT_END_REG,
|
|
|
|
ADV7180_NTSC_V_BIT_END_MANUAL_NVEND);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
/* read current norm */
|
|
|
|
__adv7180_status(client, NULL, &state->curr_norm);
|
|
|
|
|
|
|
|
/* register for interrupts */
|
|
|
|
if (state->irq > 0) {
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = request_irq(state->irq, adv7180_irq, 0, KBUILD_MODNAME,
|
2012-04-12 09:39:36 -06:00
|
|
|
state);
|
2009-09-22 03:07:06 -06:00
|
|
|
if (ret)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG,
|
2012-04-12 09:39:36 -06:00
|
|
|
ADV7180_ADI_CTRL_IRQ_SPACE);
|
2009-09-22 03:07:06 -06:00
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
/* config the Interrupt pin to be active low */
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_ICONF1_ADI,
|
2012-04-12 09:39:36 -06:00
|
|
|
ADV7180_ICONF1_ACTIVE_LOW |
|
|
|
|
ADV7180_ICONF1_PSYNC_ONLY);
|
2009-09-22 03:07:06 -06:00
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_IMR1_ADI, 0);
|
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_IMR2_ADI, 0);
|
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
/* enable AD change interrupts interrupts */
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_IMR3_ADI,
|
2012-04-12 09:39:36 -06:00
|
|
|
ADV7180_IRQ3_AD_CHANGE);
|
2009-09-22 03:07:06 -06:00
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_IMR4_ADI, 0);
|
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG,
|
2012-04-12 09:39:36 -06:00
|
|
|
0);
|
2009-09-22 03:07:06 -06:00
|
|
|
if (ret < 0)
|
2012-04-12 09:39:36 -06:00
|
|
|
return ret;
|
2009-09-18 18:17:20 -06:00
|
|
|
}
|
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-21 14:17:53 -07:00
|
|
|
static int adv7180_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
2012-04-12 09:39:36 -06:00
|
|
|
{
|
|
|
|
struct adv7180_state *state;
|
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Check if the adapter supports the needed features */
|
|
|
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
v4l_info(client, "chip found @ 0x%02x (%s)\n",
|
|
|
|
client->addr, client->adapter->name);
|
|
|
|
|
|
|
|
state = kzalloc(sizeof(struct adv7180_state), GFP_KERNEL);
|
|
|
|
if (state == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->irq = client->irq;
|
|
|
|
INIT_WORK(&state->work, adv7180_work);
|
|
|
|
mutex_init(&state->mutex);
|
|
|
|
state->autodetect = true;
|
|
|
|
state->input = 0;
|
|
|
|
sd = &state->sd;
|
|
|
|
v4l2_i2c_subdev_init(sd, client, &adv7180_ops);
|
|
|
|
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = adv7180_init_controls(state);
|
|
|
|
if (ret)
|
2012-04-12 09:39:36 -06:00
|
|
|
goto err_unreg_subdev;
|
2012-07-11 08:29:33 -06:00
|
|
|
ret = init_device(client, state);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_ctrl;
|
2009-09-18 18:17:20 -06:00
|
|
|
return 0;
|
2009-09-22 03:07:06 -06:00
|
|
|
|
2012-07-11 08:29:33 -06:00
|
|
|
err_free_ctrl:
|
|
|
|
adv7180_exit_controls(state);
|
2009-09-22 03:07:06 -06:00
|
|
|
err_unreg_subdev:
|
|
|
|
mutex_destroy(&state->mutex);
|
|
|
|
v4l2_device_unregister_subdev(sd);
|
|
|
|
kfree(state);
|
|
|
|
err:
|
2012-07-11 08:29:33 -06:00
|
|
|
printk(KERN_ERR KBUILD_MODNAME ": Failed to probe: %d\n", ret);
|
2009-09-22 03:07:06 -06:00
|
|
|
return ret;
|
2009-09-18 18:17:20 -06:00
|
|
|
}
|
|
|
|
|
2012-12-21 14:17:53 -07:00
|
|
|
static int adv7180_remove(struct i2c_client *client)
|
2009-09-18 18:17:20 -06:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
2009-09-22 03:07:06 -06:00
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
|
|
|
|
if (state->irq > 0) {
|
|
|
|
free_irq(client->irq, state);
|
|
|
|
if (cancel_work_sync(&state->work)) {
|
|
|
|
/*
|
|
|
|
* Work was pending, therefore we need to enable
|
|
|
|
* IRQ here to balance the disable_irq() done in the
|
|
|
|
* interrupt handler.
|
|
|
|
*/
|
|
|
|
enable_irq(state->irq);
|
|
|
|
}
|
|
|
|
}
|
2009-09-18 18:17:20 -06:00
|
|
|
|
2009-09-22 03:07:06 -06:00
|
|
|
mutex_destroy(&state->mutex);
|
2009-09-18 18:17:20 -06:00
|
|
|
v4l2_device_unregister_subdev(sd);
|
|
|
|
kfree(to_state(sd));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id adv7180_id[] = {
|
2012-07-11 08:29:33 -06:00
|
|
|
{KBUILD_MODNAME, 0},
|
2009-09-18 18:17:20 -06:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2012-04-12 09:39:36 -06:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int adv7180_suspend(struct i2c_client *client, pm_message_t state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG,
|
|
|
|
ADV7180_PWR_MAN_OFF);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7180_resume(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
|
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG,
|
|
|
|
ADV7180_PWR_MAN_ON);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = init_device(client, state);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-18 18:17:20 -06:00
|
|
|
MODULE_DEVICE_TABLE(i2c, adv7180_id);
|
|
|
|
|
|
|
|
static struct i2c_driver adv7180_driver = {
|
|
|
|
.driver = {
|
2012-04-12 09:39:36 -06:00
|
|
|
.owner = THIS_MODULE,
|
2012-07-11 08:29:33 -06:00
|
|
|
.name = KBUILD_MODNAME,
|
2012-04-12 09:39:36 -06:00
|
|
|
},
|
|
|
|
.probe = adv7180_probe,
|
2012-12-21 14:17:53 -07:00
|
|
|
.remove = adv7180_remove,
|
2012-04-12 09:39:36 -06:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = adv7180_suspend,
|
|
|
|
.resume = adv7180_resume,
|
|
|
|
#endif
|
|
|
|
.id_table = adv7180_id,
|
2009-09-18 18:17:20 -06:00
|
|
|
};
|
|
|
|
|
2012-02-12 02:56:32 -07:00
|
|
|
module_i2c_driver(adv7180_driver);
|
2009-09-18 18:17:20 -06:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver");
|
|
|
|
MODULE_AUTHOR("Mocean Laboratories");
|
|
|
|
MODULE_LICENSE("GPL v2");
|