2009-05-07 06:30:01 -06:00
|
|
|
/*
|
|
|
|
* adv7343 - ADV7343 Video Encoder Driver
|
|
|
|
*
|
|
|
|
* The encoder hardware does not support SECAM.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed .as is. WITHOUT ANY WARRANTY of any
|
|
|
|
* kind, whether express or implied; without even the implied warranty
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ctype.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-05-07 06:30:01 -06:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
|
|
|
#include <media/adv7343.h>
|
|
|
|
#include <media/v4l2-device.h>
|
|
|
|
#include <media/v4l2-chip-ident.h>
|
2010-12-12 04:19:16 -07:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
#include "adv7343_regs.h"
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ADV7343 video encoder driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static int debug;
|
|
|
|
module_param(debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug level 0-1");
|
|
|
|
|
|
|
|
struct adv7343_state {
|
|
|
|
struct v4l2_subdev sd;
|
2010-12-12 04:19:16 -07:00
|
|
|
struct v4l2_ctrl_handler hdl;
|
2013-01-21 21:19:50 -07:00
|
|
|
const struct adv7343_platform_data *pdata;
|
2009-05-07 06:30:01 -06:00
|
|
|
u8 reg00;
|
|
|
|
u8 reg01;
|
|
|
|
u8 reg02;
|
|
|
|
u8 reg35;
|
|
|
|
u8 reg80;
|
|
|
|
u8 reg82;
|
|
|
|
u32 output;
|
|
|
|
v4l2_std_id std;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct adv7343_state *to_state(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
return container_of(sd, struct adv7343_state, sd);
|
|
|
|
}
|
|
|
|
|
2010-12-12 04:19:16 -07:00
|
|
|
static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
return &container_of(ctrl->handler, struct adv7343_state, hdl)->sd;
|
|
|
|
}
|
|
|
|
|
2009-05-07 06:30:01 -06:00
|
|
|
static inline int adv7343_write(struct v4l2_subdev *sd, u8 reg, u8 value)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
|
|
|
|
return i2c_smbus_write_byte_data(client, reg, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const u8 adv7343_init_reg_val[] = {
|
|
|
|
ADV7343_SOFT_RESET, ADV7343_SOFT_RESET_DEFAULT,
|
|
|
|
ADV7343_POWER_MODE_REG, ADV7343_POWER_MODE_REG_DEFAULT,
|
|
|
|
|
|
|
|
ADV7343_HD_MODE_REG1, ADV7343_HD_MODE_REG1_DEFAULT,
|
|
|
|
ADV7343_HD_MODE_REG2, ADV7343_HD_MODE_REG2_DEFAULT,
|
|
|
|
ADV7343_HD_MODE_REG3, ADV7343_HD_MODE_REG3_DEFAULT,
|
|
|
|
ADV7343_HD_MODE_REG4, ADV7343_HD_MODE_REG4_DEFAULT,
|
|
|
|
ADV7343_HD_MODE_REG5, ADV7343_HD_MODE_REG5_DEFAULT,
|
|
|
|
ADV7343_HD_MODE_REG6, ADV7343_HD_MODE_REG6_DEFAULT,
|
|
|
|
ADV7343_HD_MODE_REG7, ADV7343_HD_MODE_REG7_DEFAULT,
|
|
|
|
|
|
|
|
ADV7343_SD_MODE_REG1, ADV7343_SD_MODE_REG1_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG2, ADV7343_SD_MODE_REG2_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG3, ADV7343_SD_MODE_REG3_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG4, ADV7343_SD_MODE_REG4_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG5, ADV7343_SD_MODE_REG5_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG6, ADV7343_SD_MODE_REG6_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG7, ADV7343_SD_MODE_REG7_DEFAULT,
|
|
|
|
ADV7343_SD_MODE_REG8, ADV7343_SD_MODE_REG8_DEFAULT,
|
|
|
|
|
|
|
|
ADV7343_SD_HUE_REG, ADV7343_SD_HUE_REG_DEFAULT,
|
|
|
|
ADV7343_SD_CGMS_WSS0, ADV7343_SD_CGMS_WSS0_DEFAULT,
|
|
|
|
ADV7343_SD_BRIGHTNESS_WSS, ADV7343_SD_BRIGHTNESS_WSS_DEFAULT,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2^32
|
|
|
|
* FSC(reg) = FSC (HZ) * --------
|
|
|
|
* 27000000
|
|
|
|
*/
|
|
|
|
static const struct adv7343_std_info stdinfo[] = {
|
|
|
|
{
|
|
|
|
/* FSC(Hz) = 3,579,545.45 Hz */
|
|
|
|
SD_STD_NTSC, 569408542, V4L2_STD_NTSC,
|
|
|
|
}, {
|
|
|
|
/* FSC(Hz) = 3,575,611.00 Hz */
|
|
|
|
SD_STD_PAL_M, 568782678, V4L2_STD_PAL_M,
|
|
|
|
}, {
|
|
|
|
/* FSC(Hz) = 3,582,056.00 */
|
|
|
|
SD_STD_PAL_N, 569807903, V4L2_STD_PAL_Nc,
|
|
|
|
}, {
|
|
|
|
/* FSC(Hz) = 4,433,618.75 Hz */
|
|
|
|
SD_STD_PAL_N, 705268427, V4L2_STD_PAL_N,
|
|
|
|
}, {
|
|
|
|
/* FSC(Hz) = 4,433,618.75 Hz */
|
|
|
|
SD_STD_PAL_BDGHI, 705268427, V4L2_STD_PAL,
|
|
|
|
}, {
|
|
|
|
/* FSC(Hz) = 4,433,618.75 Hz */
|
|
|
|
SD_STD_NTSC, 705268427, V4L2_STD_NTSC_443,
|
|
|
|
}, {
|
|
|
|
/* FSC(Hz) = 4,433,618.75 Hz */
|
|
|
|
SD_STD_PAL_M, 705268427, V4L2_STD_PAL_60,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int adv7343_setstd(struct v4l2_subdev *sd, v4l2_std_id std)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state = to_state(sd);
|
|
|
|
struct adv7343_std_info *std_info;
|
2012-04-20 04:30:48 -06:00
|
|
|
int num_std;
|
2009-05-07 06:30:01 -06:00
|
|
|
char *fsc_ptr;
|
|
|
|
u8 reg, val;
|
|
|
|
int err = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
std_info = (struct adv7343_std_info *)stdinfo;
|
|
|
|
num_std = ARRAY_SIZE(stdinfo);
|
|
|
|
|
|
|
|
for (i = 0; i < num_std; i++) {
|
|
|
|
if (std_info[i].stdid & std)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == num_std) {
|
|
|
|
v4l2_dbg(1, debug, sd,
|
|
|
|
"Invalid std or std is not supported: %llx\n",
|
|
|
|
(unsigned long long)std);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the standard */
|
|
|
|
val = state->reg80 & (~(SD_STD_MASK));
|
|
|
|
val |= std_info[i].standard_val3;
|
|
|
|
err = adv7343_write(sd, ADV7343_SD_MODE_REG1, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setstd_exit;
|
|
|
|
|
|
|
|
state->reg80 = val;
|
|
|
|
|
|
|
|
/* Configure the input mode register */
|
|
|
|
val = state->reg01 & (~((u8) INPUT_MODE_MASK));
|
|
|
|
val |= SD_INPUT_MODE;
|
|
|
|
err = adv7343_write(sd, ADV7343_MODE_SELECT_REG, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setstd_exit;
|
|
|
|
|
|
|
|
state->reg01 = val;
|
|
|
|
|
|
|
|
/* Program the sub carrier frequency registers */
|
|
|
|
fsc_ptr = (unsigned char *)&std_info[i].fsc_val;
|
|
|
|
reg = ADV7343_FSC_REG0;
|
|
|
|
for (i = 0; i < 4; i++, reg++, fsc_ptr++) {
|
|
|
|
err = adv7343_write(sd, reg, *fsc_ptr);
|
|
|
|
if (err < 0)
|
|
|
|
goto setstd_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = state->reg80;
|
|
|
|
|
|
|
|
/* Filter settings */
|
|
|
|
if (std & (V4L2_STD_NTSC | V4L2_STD_NTSC_443))
|
|
|
|
val &= 0x03;
|
|
|
|
else if (std & ~V4L2_STD_SECAM)
|
|
|
|
val |= 0x04;
|
|
|
|
|
|
|
|
err = adv7343_write(sd, ADV7343_SD_MODE_REG1, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setstd_exit;
|
|
|
|
|
|
|
|
state->reg80 = val;
|
|
|
|
|
|
|
|
setstd_exit:
|
|
|
|
if (err != 0)
|
|
|
|
v4l2_err(sd, "Error setting std, write failed\n");
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7343_setoutput(struct v4l2_subdev *sd, u32 output_type)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state = to_state(sd);
|
|
|
|
unsigned char val;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (output_type > ADV7343_SVIDEO_ID) {
|
|
|
|
v4l2_dbg(1, debug, sd,
|
|
|
|
"Invalid output type or output type not supported:%d\n",
|
|
|
|
output_type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable Appropriate DAC */
|
|
|
|
val = state->reg00 & 0x03;
|
|
|
|
|
2013-01-21 21:19:50 -07:00
|
|
|
/* configure default configuration */
|
|
|
|
if (!state->pdata)
|
|
|
|
if (output_type == ADV7343_COMPOSITE_ID)
|
|
|
|
val |= ADV7343_COMPOSITE_POWER_VALUE;
|
|
|
|
else if (output_type == ADV7343_COMPONENT_ID)
|
|
|
|
val |= ADV7343_COMPONENT_POWER_VALUE;
|
|
|
|
else
|
|
|
|
val |= ADV7343_SVIDEO_POWER_VALUE;
|
2009-05-07 06:30:01 -06:00
|
|
|
else
|
2013-01-21 21:19:50 -07:00
|
|
|
val = state->pdata->mode_config.sleep_mode << 0 |
|
|
|
|
state->pdata->mode_config.pll_control << 1 |
|
|
|
|
state->pdata->mode_config.dac_3 << 2 |
|
|
|
|
state->pdata->mode_config.dac_2 << 3 |
|
|
|
|
state->pdata->mode_config.dac_1 << 4 |
|
|
|
|
state->pdata->mode_config.dac_6 << 5 |
|
|
|
|
state->pdata->mode_config.dac_5 << 6 |
|
|
|
|
state->pdata->mode_config.dac_4 << 7;
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
err = adv7343_write(sd, ADV7343_POWER_MODE_REG, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setoutput_exit;
|
|
|
|
|
|
|
|
state->reg00 = val;
|
|
|
|
|
|
|
|
/* Enable YUV output */
|
|
|
|
val = state->reg02 | YUV_OUTPUT_SELECT;
|
|
|
|
err = adv7343_write(sd, ADV7343_MODE_REG0, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setoutput_exit;
|
|
|
|
|
|
|
|
state->reg02 = val;
|
|
|
|
|
|
|
|
/* configure SD DAC Output 2 and SD DAC Output 1 bit to zero */
|
|
|
|
val = state->reg82 & (SD_DAC_1_DI & SD_DAC_2_DI);
|
2013-01-21 21:19:50 -07:00
|
|
|
|
|
|
|
if (state->pdata && state->pdata->sd_config.sd_dac_out1)
|
|
|
|
val = val | (state->pdata->sd_config.sd_dac_out1 << 1);
|
|
|
|
else if (state->pdata && !state->pdata->sd_config.sd_dac_out1)
|
|
|
|
val = val & ~(state->pdata->sd_config.sd_dac_out1 << 1);
|
|
|
|
|
|
|
|
if (state->pdata && state->pdata->sd_config.sd_dac_out2)
|
|
|
|
val = val | (state->pdata->sd_config.sd_dac_out2 << 2);
|
|
|
|
else if (state->pdata && !state->pdata->sd_config.sd_dac_out2)
|
|
|
|
val = val & ~(state->pdata->sd_config.sd_dac_out2 << 2);
|
|
|
|
|
2009-05-07 06:30:01 -06:00
|
|
|
err = adv7343_write(sd, ADV7343_SD_MODE_REG2, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setoutput_exit;
|
|
|
|
|
|
|
|
state->reg82 = val;
|
|
|
|
|
|
|
|
/* configure ED/HD Color DAC Swap and ED/HD RGB Input Enable bit to
|
|
|
|
* zero */
|
|
|
|
val = state->reg35 & (HD_RGB_INPUT_DI & HD_DAC_SWAP_DI);
|
|
|
|
err = adv7343_write(sd, ADV7343_HD_MODE_REG6, val);
|
|
|
|
if (err < 0)
|
|
|
|
goto setoutput_exit;
|
|
|
|
|
|
|
|
state->reg35 = val;
|
|
|
|
|
|
|
|
setoutput_exit:
|
|
|
|
if (err != 0)
|
|
|
|
v4l2_err(sd, "Error setting output, write failed\n");
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7343_log_status(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state = to_state(sd);
|
|
|
|
|
|
|
|
v4l2_info(sd, "Standard: %llx\n", (unsigned long long)state->std);
|
|
|
|
v4l2_info(sd, "Output: %s\n", (state->output == 0) ? "Composite" :
|
|
|
|
((state->output == 1) ? "Component" : "S-Video"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-12 04:19:16 -07:00
|
|
|
static int adv7343_s_ctrl(struct v4l2_ctrl *ctrl)
|
2009-05-07 06:30:01 -06:00
|
|
|
{
|
2010-12-12 04:19:16 -07:00
|
|
|
struct v4l2_subdev *sd = to_sd(ctrl);
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_BRIGHTNESS:
|
2010-12-12 04:19:16 -07:00
|
|
|
return adv7343_write(sd, ADV7343_SD_BRIGHTNESS_WSS,
|
|
|
|
ctrl->val);
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
case V4L2_CID_HUE:
|
2010-12-12 04:19:16 -07:00
|
|
|
return adv7343_write(sd, ADV7343_SD_HUE_REG, ctrl->val);
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
case V4L2_CID_GAIN:
|
2010-12-12 04:19:16 -07:00
|
|
|
return adv7343_write(sd, ADV7343_DAC2_OUTPUT_LEVEL, ctrl->val);
|
2009-05-07 06:30:01 -06:00
|
|
|
}
|
2010-12-12 04:19:16 -07:00
|
|
|
return -EINVAL;
|
2009-05-07 06:30:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7343_g_chip_ident(struct v4l2_subdev *sd,
|
|
|
|
struct v4l2_dbg_chip_ident *chip)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
|
|
|
|
return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7343, 0);
|
|
|
|
}
|
|
|
|
|
2010-12-12 04:19:16 -07:00
|
|
|
static const struct v4l2_ctrl_ops adv7343_ctrl_ops = {
|
|
|
|
.s_ctrl = adv7343_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2009-05-07 06:30:01 -06:00
|
|
|
static const struct v4l2_subdev_core_ops adv7343_core_ops = {
|
2010-12-12 04:19:16 -07:00
|
|
|
.log_status = adv7343_log_status,
|
|
|
|
.g_chip_ident = adv7343_g_chip_ident,
|
|
|
|
.g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
|
|
|
|
.try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
|
|
|
|
.s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
|
|
|
|
.g_ctrl = v4l2_subdev_g_ctrl,
|
|
|
|
.s_ctrl = v4l2_subdev_s_ctrl,
|
|
|
|
.queryctrl = v4l2_subdev_queryctrl,
|
|
|
|
.querymenu = v4l2_subdev_querymenu,
|
2009-05-07 06:30:01 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static int adv7343_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state = to_state(sd);
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (state->std == std)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err = adv7343_setstd(sd, std);
|
|
|
|
if (!err)
|
|
|
|
state->std = std;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7343_s_routing(struct v4l2_subdev *sd,
|
|
|
|
u32 input, u32 output, u32 config)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state = to_state(sd);
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (state->output == output)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err = adv7343_setoutput(sd, output);
|
|
|
|
if (!err)
|
|
|
|
state->output = output;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct v4l2_subdev_video_ops adv7343_video_ops = {
|
|
|
|
.s_std_output = adv7343_s_std_output,
|
|
|
|
.s_routing = adv7343_s_routing,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_subdev_ops adv7343_ops = {
|
|
|
|
.core = &adv7343_core_ops,
|
|
|
|
.video = &adv7343_video_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int adv7343_initialize(struct v4l2_subdev *sd)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state = to_state(sd);
|
|
|
|
int err = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(adv7343_init_reg_val); i += 2) {
|
|
|
|
|
|
|
|
err = adv7343_write(sd, adv7343_init_reg_val[i],
|
|
|
|
adv7343_init_reg_val[i+1]);
|
|
|
|
if (err) {
|
|
|
|
v4l2_err(sd, "Error initializing\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure for default video standard */
|
|
|
|
err = adv7343_setoutput(sd, state->output);
|
|
|
|
if (err < 0) {
|
|
|
|
v4l2_err(sd, "Error setting output during init\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = adv7343_setstd(sd, state->std);
|
|
|
|
if (err < 0) {
|
|
|
|
v4l2_err(sd, "Error setting std during init\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7343_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct adv7343_state *state;
|
2010-12-12 04:19:16 -07:00
|
|
|
int err;
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
v4l_info(client, "chip found @ 0x%x (%s)\n",
|
|
|
|
client->addr << 1, client->adapter->name);
|
|
|
|
|
2013-01-03 06:08:46 -07:00
|
|
|
state = devm_kzalloc(&client->dev, sizeof(struct adv7343_state),
|
|
|
|
GFP_KERNEL);
|
2009-05-07 06:30:01 -06:00
|
|
|
if (state == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-01-21 21:19:50 -07:00
|
|
|
/* Copy board specific information here */
|
|
|
|
state->pdata = client->dev.platform_data;
|
|
|
|
|
2009-05-07 06:30:01 -06:00
|
|
|
state->reg00 = 0x80;
|
|
|
|
state->reg01 = 0x00;
|
|
|
|
state->reg02 = 0x20;
|
|
|
|
state->reg35 = 0x00;
|
|
|
|
state->reg80 = ADV7343_SD_MODE_REG1_DEFAULT;
|
|
|
|
state->reg82 = ADV7343_SD_MODE_REG2_DEFAULT;
|
|
|
|
|
|
|
|
state->output = ADV7343_COMPOSITE_ID;
|
|
|
|
state->std = V4L2_STD_NTSC;
|
|
|
|
|
|
|
|
v4l2_i2c_subdev_init(&state->sd, client, &adv7343_ops);
|
2010-12-12 04:19:16 -07:00
|
|
|
|
|
|
|
v4l2_ctrl_handler_init(&state->hdl, 2);
|
|
|
|
v4l2_ctrl_new_std(&state->hdl, &adv7343_ctrl_ops,
|
|
|
|
V4L2_CID_BRIGHTNESS, ADV7343_BRIGHTNESS_MIN,
|
|
|
|
ADV7343_BRIGHTNESS_MAX, 1,
|
|
|
|
ADV7343_BRIGHTNESS_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->hdl, &adv7343_ctrl_ops,
|
|
|
|
V4L2_CID_HUE, ADV7343_HUE_MIN,
|
|
|
|
ADV7343_HUE_MAX, 1,
|
|
|
|
ADV7343_HUE_DEF);
|
|
|
|
v4l2_ctrl_new_std(&state->hdl, &adv7343_ctrl_ops,
|
|
|
|
V4L2_CID_GAIN, ADV7343_GAIN_MIN,
|
|
|
|
ADV7343_GAIN_MAX, 1,
|
|
|
|
ADV7343_GAIN_DEF);
|
|
|
|
state->sd.ctrl_handler = &state->hdl;
|
|
|
|
if (state->hdl.error) {
|
|
|
|
int err = state->hdl.error;
|
|
|
|
|
|
|
|
v4l2_ctrl_handler_free(&state->hdl);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
v4l2_ctrl_handler_setup(&state->hdl);
|
|
|
|
|
|
|
|
err = adv7343_initialize(&state->sd);
|
2013-01-03 06:08:46 -07:00
|
|
|
if (err)
|
2010-12-12 04:19:16 -07:00
|
|
|
v4l2_ctrl_handler_free(&state->hdl);
|
|
|
|
return err;
|
2009-05-07 06:30:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int adv7343_remove(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = i2c_get_clientdata(client);
|
2010-12-12 04:19:16 -07:00
|
|
|
struct adv7343_state *state = to_state(sd);
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
v4l2_device_unregister_subdev(sd);
|
2010-12-12 04:19:16 -07:00
|
|
|
v4l2_ctrl_handler_free(&state->hdl);
|
2009-05-07 06:30:01 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id adv7343_id[] = {
|
|
|
|
{"adv7343", 0},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(i2c, adv7343_id);
|
|
|
|
|
|
|
|
static struct i2c_driver adv7343_driver = {
|
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "adv7343",
|
|
|
|
},
|
|
|
|
.probe = adv7343_probe,
|
|
|
|
.remove = adv7343_remove,
|
|
|
|
.id_table = adv7343_id,
|
|
|
|
};
|
|
|
|
|
2012-02-12 02:56:32 -07:00
|
|
|
module_i2c_driver(adv7343_driver);
|