735 lines
18 KiB
C
735 lines
18 KiB
C
/*
|
|
* adv7180.c Analog Devices ADV7180 video decoder driver
|
|
* Copyright (c) 2009 Intel Corporation
|
|
* Copyright (C) 2013 Cogent Embedded, Inc.
|
|
* Copyright (C) 2013 Renesas Solutions Corp.
|
|
*
|
|
* 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 <linux/slab.h>
|
|
#include <media/v4l2-ioctl.h>
|
|
#include <linux/videodev2.h>
|
|
#include <media/v4l2-device.h>
|
|
#include <media/v4l2-ctrls.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/delay.h>
|
|
|
|
#define ADV7180_REG_INPUT_CONTROL 0x0000
|
|
#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
|
|
#define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f
|
|
|
|
#define ADV7180_REG_EXTENDED_OUTPUT_CONTROL 0x0004
|
|
#define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5
|
|
|
|
#define ADV7180_REG_AUTODETECT_ENABLE 0x07
|
|
#define ADV7180_AUTODETECT_DEFAULT 0x7f
|
|
/* Contrast */
|
|
#define ADV7180_REG_CON 0x0008 /*Unsigned */
|
|
#define ADV7180_CON_MIN 0
|
|
#define ADV7180_CON_DEF 128
|
|
#define ADV7180_CON_MAX 255
|
|
/* Brightness*/
|
|
#define ADV7180_REG_BRI 0x000a /*Signed */
|
|
#define ADV7180_BRI_MIN -128
|
|
#define ADV7180_BRI_DEF 0
|
|
#define ADV7180_BRI_MAX 127
|
|
/* Hue */
|
|
#define ADV7180_REG_HUE 0x000b /*Signed, inverted */
|
|
#define ADV7180_HUE_MIN -127
|
|
#define ADV7180_HUE_DEF 0
|
|
#define ADV7180_HUE_MAX 128
|
|
|
|
#define ADV7180_REG_CTRL 0x000e
|
|
#define ADV7180_CTRL_IRQ_SPACE 0x20
|
|
|
|
#define ADV7180_REG_PWR_MAN 0x0f
|
|
#define ADV7180_PWR_MAN_ON 0x04
|
|
#define ADV7180_PWR_MAN_OFF 0x24
|
|
#define ADV7180_PWR_MAN_RES 0x80
|
|
|
|
#define ADV7180_REG_STATUS1 0x0010
|
|
#define ADV7180_STATUS1_IN_LOCK 0x01
|
|
#define ADV7180_STATUS1_AUTOD_MASK 0x70
|
|
#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_REG_IDENT 0x0011
|
|
#define ADV7180_ID_7180 0x18
|
|
|
|
#define ADV7180_REG_ICONF1 0x0040
|
|
#define ADV7180_ICONF1_ACTIVE_LOW 0x01
|
|
#define ADV7180_ICONF1_PSYNC_ONLY 0x10
|
|
#define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0
|
|
/* Saturation */
|
|
#define ADV7180_REG_SD_SAT_CB 0x00e3 /*Unsigned */
|
|
#define ADV7180_REG_SD_SAT_CR 0x00e4 /*Unsigned */
|
|
#define ADV7180_SAT_MIN 0
|
|
#define ADV7180_SAT_DEF 128
|
|
#define ADV7180_SAT_MAX 255
|
|
|
|
#define ADV7180_IRQ1_LOCK 0x01
|
|
#define ADV7180_IRQ1_UNLOCK 0x02
|
|
#define ADV7180_REG_ISR1 0x0042
|
|
#define ADV7180_REG_ICR1 0x0043
|
|
#define ADV7180_REG_IMR1 0x0044
|
|
#define ADV7180_REG_IMR2 0x0048
|
|
#define ADV7180_IRQ3_AD_CHANGE 0x08
|
|
#define ADV7180_REG_ISR3 0x004A
|
|
#define ADV7180_REG_ICR3 0x004B
|
|
#define ADV7180_REG_IMR3 0x004C
|
|
#define ADV7180_REG_IMR4 0x50
|
|
|
|
#define ADV7180_REG_NTSC_V_BIT_END 0x00E6
|
|
#define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F
|
|
|
|
struct adv7180_state {
|
|
struct v4l2_ctrl_handler ctrl_hdl;
|
|
struct v4l2_subdev sd;
|
|
struct mutex mutex; /* mutual excl. when accessing chip */
|
|
int irq;
|
|
v4l2_std_id curr_norm;
|
|
bool autodetect;
|
|
bool powered;
|
|
u8 input;
|
|
|
|
struct i2c_client *client;
|
|
unsigned int register_page;
|
|
};
|
|
#define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
|
|
struct adv7180_state, \
|
|
ctrl_hdl)->sd)
|
|
|
|
static int adv7180_select_page(struct adv7180_state *state, unsigned int page)
|
|
{
|
|
if (state->register_page != page) {
|
|
i2c_smbus_write_byte_data(state->client, ADV7180_REG_CTRL,
|
|
page);
|
|
state->register_page = page;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int adv7180_write(struct adv7180_state *state, unsigned int reg,
|
|
unsigned int value)
|
|
{
|
|
lockdep_assert_held(&state->mutex);
|
|
adv7180_select_page(state, reg >> 8);
|
|
return i2c_smbus_write_byte_data(state->client, reg & 0xff, value);
|
|
}
|
|
|
|
static int adv7180_read(struct adv7180_state *state, unsigned int reg)
|
|
{
|
|
lockdep_assert_held(&state->mutex);
|
|
adv7180_select_page(state, reg >> 8);
|
|
return i2c_smbus_read_byte_data(state->client, reg & 0xff);
|
|
}
|
|
|
|
|
|
static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
|
|
{
|
|
/* in case V4L2_IN_ST_NO_SIGNAL */
|
|
if (!(status1 & ADV7180_STATUS1_IN_LOCK))
|
|
return V4L2_STD_UNKNOWN;
|
|
|
|
switch (status1 & ADV7180_STATUS1_AUTOD_MASK) {
|
|
case ADV7180_STATUS1_AUTOD_NTSM_M_J:
|
|
return V4L2_STD_NTSC;
|
|
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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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 adv7180_state *state, u32 *status,
|
|
v4l2_std_id *std)
|
|
{
|
|
int status1 = adv7180_read(state, ADV7180_REG_STATUS1);
|
|
|
|
if (status1 < 0)
|
|
return status1;
|
|
|
|
if (status)
|
|
*status = adv7180_status_to_v4l2(status1);
|
|
if (std)
|
|
*std = adv7180_std_to_v4l2(status1);
|
|
|
|
return 0;
|
|
}
|
|
|
|
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)
|
|
{
|
|
struct adv7180_state *state = to_state(sd);
|
|
int err = mutex_lock_interruptible(&state->mutex);
|
|
if (err)
|
|
return err;
|
|
|
|
/* when we are interrupt driven we know the state */
|
|
if (!state->autodetect || state->irq > 0)
|
|
*std = state->curr_norm;
|
|
else
|
|
err = __adv7180_status(state, NULL, std);
|
|
|
|
mutex_unlock(&state->mutex);
|
|
return err;
|
|
}
|
|
|
|
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);
|
|
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* We cannot discriminate between LQFP and 40-pin LFCSP, so accept
|
|
* all inputs and let the card driver take care of validation
|
|
*/
|
|
if ((input & ADV7180_INPUT_CONTROL_INSEL_MASK) != input)
|
|
goto out;
|
|
|
|
ret = adv7180_read(state, ADV7180_REG_INPUT_CONTROL);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK;
|
|
ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ret | input);
|
|
state->input = input;
|
|
out:
|
|
mutex_unlock(&state->mutex);
|
|
return ret;
|
|
}
|
|
|
|
static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
|
|
{
|
|
struct adv7180_state *state = to_state(sd);
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = __adv7180_status(state, status, NULL);
|
|
mutex_unlock(&state->mutex);
|
|
return ret;
|
|
}
|
|
|
|
static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
|
|
{
|
|
struct adv7180_state *state = to_state(sd);
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* all standards -> autodetect */
|
|
if (std == V4L2_STD_ALL) {
|
|
ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
|
|
ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
|
|
| state->input);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
__adv7180_status(state, NULL, &state->curr_norm);
|
|
state->autodetect = true;
|
|
} else {
|
|
ret = v4l2_std_to_adv7180(std);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
|
|
ret | state->input);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
state->curr_norm = std;
|
|
state->autodetect = false;
|
|
}
|
|
ret = 0;
|
|
out:
|
|
mutex_unlock(&state->mutex);
|
|
return ret;
|
|
}
|
|
|
|
static int adv7180_set_power(struct adv7180_state *state, bool on)
|
|
{
|
|
u8 val;
|
|
|
|
if (on)
|
|
val = ADV7180_PWR_MAN_ON;
|
|
else
|
|
val = ADV7180_PWR_MAN_OFF;
|
|
|
|
return adv7180_write(state, ADV7180_REG_PWR_MAN, val);
|
|
}
|
|
|
|
static int adv7180_s_power(struct v4l2_subdev *sd, int on)
|
|
{
|
|
struct adv7180_state *state = to_state(sd);
|
|
int ret;
|
|
|
|
ret = mutex_lock_interruptible(&state->mutex);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = adv7180_set_power(state, on);
|
|
if (ret == 0)
|
|
state->powered = on;
|
|
|
|
mutex_unlock(&state->mutex);
|
|
return ret;
|
|
}
|
|
|
|
static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
{
|
|
struct v4l2_subdev *sd = to_adv7180_sd(ctrl);
|
|
struct adv7180_state *state = to_state(sd);
|
|
int ret = mutex_lock_interruptible(&state->mutex);
|
|
int val;
|
|
|
|
if (ret)
|
|
return ret;
|
|
val = ctrl->val;
|
|
switch (ctrl->id) {
|
|
case V4L2_CID_BRIGHTNESS:
|
|
ret = adv7180_write(state, ADV7180_REG_BRI, val);
|
|
break;
|
|
case V4L2_CID_HUE:
|
|
/*Hue is inverted according to HSL chart */
|
|
ret = adv7180_write(state, ADV7180_REG_HUE, -val);
|
|
break;
|
|
case V4L2_CID_CONTRAST:
|
|
ret = adv7180_write(state, ADV7180_REG_CON, val);
|
|
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
|
|
*/
|
|
ret = adv7180_write(state, ADV7180_REG_SD_SAT_CB, val);
|
|
if (ret < 0)
|
|
break;
|
|
ret = adv7180_write(state, ADV7180_REG_SD_SAT_CR, val);
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
}
|
|
|
|
mutex_unlock(&state->mutex);
|
|
return ret;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
static int adv7180_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index,
|
|
u32 *code)
|
|
{
|
|
if (index > 0)
|
|
return -EINVAL;
|
|
|
|
*code = MEDIA_BUS_FMT_YUYV8_2X8;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int adv7180_mbus_fmt(struct v4l2_subdev *sd,
|
|
struct v4l2_mbus_framefmt *fmt)
|
|
{
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
fmt->code = MEDIA_BUS_FMT_YUYV8_2X8;
|
|
fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
fmt->field = V4L2_FIELD_INTERLACED;
|
|
fmt->width = 720;
|
|
fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
|
|
struct v4l2_mbus_config *cfg)
|
|
{
|
|
/*
|
|
* The ADV7180 sensor supports BT.601/656 output modes.
|
|
* The BT.656 is default and not yet configurable by s/w.
|
|
*/
|
|
cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
|
|
V4L2_MBUS_DATA_ACTIVE_HIGH;
|
|
cfg->type = V4L2_MBUS_BT656;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct v4l2_subdev_video_ops adv7180_video_ops = {
|
|
.s_std = adv7180_s_std,
|
|
.querystd = adv7180_querystd,
|
|
.g_input_status = adv7180_g_input_status,
|
|
.s_routing = adv7180_s_routing,
|
|
.enum_mbus_fmt = adv7180_enum_mbus_fmt,
|
|
.try_mbus_fmt = adv7180_mbus_fmt,
|
|
.g_mbus_fmt = adv7180_mbus_fmt,
|
|
.s_mbus_fmt = adv7180_mbus_fmt,
|
|
.g_mbus_config = adv7180_g_mbus_config,
|
|
};
|
|
|
|
static const struct v4l2_subdev_core_ops adv7180_core_ops = {
|
|
.s_power = adv7180_s_power,
|
|
};
|
|
|
|
static const struct v4l2_subdev_ops adv7180_ops = {
|
|
.core = &adv7180_core_ops,
|
|
.video = &adv7180_video_ops,
|
|
};
|
|
|
|
static irqreturn_t adv7180_irq(int irq, void *devid)
|
|
{
|
|
struct adv7180_state *state = devid;
|
|
u8 isr3;
|
|
|
|
mutex_lock(&state->mutex);
|
|
isr3 = adv7180_read(state, ADV7180_REG_ISR3);
|
|
/* clear */
|
|
adv7180_write(state, ADV7180_REG_ICR3, isr3);
|
|
|
|
if (isr3 & ADV7180_IRQ3_AD_CHANGE && state->autodetect)
|
|
__adv7180_status(state, NULL, &state->curr_norm);
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int init_device(struct adv7180_state *state)
|
|
{
|
|
int ret;
|
|
|
|
mutex_lock(&state->mutex);
|
|
|
|
adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
|
|
usleep_range(2000, 10000);
|
|
|
|
/* Initialize adv7180 */
|
|
/* Enable autodetection */
|
|
if (state->autodetect) {
|
|
ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
|
|
ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
|
|
| state->input);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_AUTODETECT_ENABLE,
|
|
ADV7180_AUTODETECT_DEFAULT);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
} else {
|
|
ret = v4l2_std_to_adv7180(state->curr_norm);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
|
|
ret | state->input);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
}
|
|
/* ITU-R BT.656-4 compatible */
|
|
ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
|
|
ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
/* Manually set V bit end position in NTSC mode */
|
|
ret = adv7180_write(state, ADV7180_REG_NTSC_V_BIT_END,
|
|
ADV7180_NTSC_V_BIT_END_MANUAL_NVEND);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
/* read current norm */
|
|
__adv7180_status(state, NULL, &state->curr_norm);
|
|
|
|
/* register for interrupts */
|
|
if (state->irq > 0) {
|
|
/* config the Interrupt pin to be active low */
|
|
ret = adv7180_write(state, ADV7180_REG_ICONF1,
|
|
ADV7180_ICONF1_ACTIVE_LOW |
|
|
ADV7180_ICONF1_PSYNC_ONLY);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR1, 0);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR2, 0);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
/* enable AD change interrupts interrupts */
|
|
ret = adv7180_write(state, ADV7180_REG_IMR3,
|
|
ADV7180_IRQ3_AD_CHANGE);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
|
|
ret = adv7180_write(state, ADV7180_REG_IMR4, 0);
|
|
if (ret < 0)
|
|
goto out_unlock;
|
|
}
|
|
|
|
out_unlock:
|
|
mutex_unlock(&state->mutex);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int adv7180_probe(struct i2c_client *client,
|
|
const struct i2c_device_id *id)
|
|
{
|
|
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 = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
|
|
if (state == NULL)
|
|
return -ENOMEM;
|
|
|
|
state->client = client;
|
|
|
|
state->irq = client->irq;
|
|
mutex_init(&state->mutex);
|
|
state->autodetect = true;
|
|
state->powered = true;
|
|
state->input = 0;
|
|
sd = &state->sd;
|
|
v4l2_i2c_subdev_init(sd, client, &adv7180_ops);
|
|
|
|
ret = adv7180_init_controls(state);
|
|
if (ret)
|
|
goto err_unreg_subdev;
|
|
ret = init_device(state);
|
|
if (ret)
|
|
goto err_free_ctrl;
|
|
|
|
if (state->irq) {
|
|
ret = request_threaded_irq(client->irq, NULL, adv7180_irq,
|
|
IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
|
|
KBUILD_MODNAME, state);
|
|
if (ret)
|
|
goto err_free_ctrl;
|
|
}
|
|
|
|
ret = v4l2_async_register_subdev(sd);
|
|
if (ret)
|
|
goto err_free_irq;
|
|
|
|
return 0;
|
|
|
|
err_free_irq:
|
|
if (state->irq > 0)
|
|
free_irq(client->irq, state);
|
|
err_free_ctrl:
|
|
adv7180_exit_controls(state);
|
|
err_unreg_subdev:
|
|
mutex_destroy(&state->mutex);
|
|
return ret;
|
|
}
|
|
|
|
static int adv7180_remove(struct i2c_client *client)
|
|
{
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
v4l2_async_unregister_subdev(sd);
|
|
|
|
if (state->irq > 0)
|
|
free_irq(client->irq, state);
|
|
|
|
adv7180_exit_controls(state);
|
|
mutex_destroy(&state->mutex);
|
|
return 0;
|
|
}
|
|
|
|
static const struct i2c_device_id adv7180_id[] = {
|
|
{KBUILD_MODNAME, 0},
|
|
{},
|
|
};
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
static int adv7180_suspend(struct device *dev)
|
|
{
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
|
struct adv7180_state *state = to_state(sd);
|
|
|
|
return adv7180_set_power(state, false);
|
|
}
|
|
|
|
static int adv7180_resume(struct device *dev)
|
|
{
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
|
struct adv7180_state *state = to_state(sd);
|
|
int ret;
|
|
|
|
ret = init_device(state);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
ret = adv7180_set_power(state, state->powered);
|
|
if (ret)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static SIMPLE_DEV_PM_OPS(adv7180_pm_ops, adv7180_suspend, adv7180_resume);
|
|
#define ADV7180_PM_OPS (&adv7180_pm_ops)
|
|
|
|
#else
|
|
#define ADV7180_PM_OPS NULL
|
|
#endif
|
|
|
|
MODULE_DEVICE_TABLE(i2c, adv7180_id);
|
|
|
|
static struct i2c_driver adv7180_driver = {
|
|
.driver = {
|
|
.owner = THIS_MODULE,
|
|
.name = KBUILD_MODNAME,
|
|
.pm = ADV7180_PM_OPS,
|
|
},
|
|
.probe = adv7180_probe,
|
|
.remove = adv7180_remove,
|
|
.id_table = adv7180_id,
|
|
};
|
|
|
|
module_i2c_driver(adv7180_driver);
|
|
|
|
MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver");
|
|
MODULE_AUTHOR("Mocean Laboratories");
|
|
MODULE_LICENSE("GPL v2");
|