media: i2c: tc35874x: update driver version

Adapt the driver to kernel-4.19.
Add 4 lanes and multi-resolution support.

Signed-off-by: Dingxian Wen <shawn.wen@rock-chips.com>
Change-Id: I1eca2b49113a0ce55d8bbd76301a1bf884a9dd13
This commit is contained in:
Dingxian Wen
2020-08-07 11:56:27 +08:00
committed by Tao Huang
parent e7d6a11012
commit bccce4c095
4 changed files with 432 additions and 43 deletions

View File

@@ -416,6 +416,17 @@ config VIDEO_TC358743_CEC
When selected the tc358743 will support the optional
HDMI CEC feature.
config VIDEO_TC35874X
tristate "Toshiba TC35874X decoder"
depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
select HDMI
select V4L2_FWNODE
help
Support for the Toshiba TC35874X series HDMI to MIPI CSI-2 bridge.
To compile this driver as a module, choose M here: the
module will be called tc35874x.
config VIDEO_TVP514X
tristate "Texas Instruments TVP514x video decoder"
depends on VIDEO_V4L2 && I2C

View File

@@ -122,6 +122,7 @@ obj-$(CONFIG_VIDEO_I2C) += video-i2c.o
obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o
obj-$(CONFIG_VIDEO_OV2659) += ov2659.o
obj-$(CONFIG_VIDEO_TC358743) += tc358743.o
obj-$(CONFIG_VIDEO_TC35874X) += tc35874x.o
obj-$(CONFIG_VIDEO_IMX219) += imx219.o
obj-$(CONFIG_VIDEO_IMX258) += imx258.o
obj-$(CONFIG_VIDEO_IMX258_EEPROM) += imx258_eeprom.o

View File

@@ -40,6 +40,8 @@
#include <linux/workqueue.h>
#include <linux/v4l2-dv-timings.h>
#include <linux/hdmi.h>
#include <linux/version.h>
#include <linux/rk-camera-module.h>
#include <media/v4l2-dv-timings.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
@@ -59,17 +61,24 @@ MODULE_AUTHOR("Mikhail Khelik <mkhelik@cisco.com>");
MODULE_AUTHOR("Mats Randgaard <matrandg@cisco.com>");
MODULE_LICENSE("GPL");
#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x1)
#define EDID_NUM_BLOCKS_MAX 8
#define EDID_BLOCK_SIZE 128
#define I2C_MAX_XFER_SIZE (EDID_BLOCK_SIZE + 2)
#define POLL_INTERVAL_CEC_MS 10
#define POLL_INTERVAL_MS 1000
#define TC35874X_LINK_FREQ_300MHZ 300000000
#define TC35874X_PIXEL_RATE (TC35874X_LINK_FREQ_300MHZ * 2 * 2 / 8)
/* PIXEL_RATE = MIPI_FREQ * 2 * lane / 8bit */
#define TC35874X_LINK_FREQ_310MHZ 310000000
#define TC35874X_PIXEL_RATE_310M TC35874X_LINK_FREQ_310MHZ
#define TC35874X_NAME "tc35874x"
static const s64 link_freq_menu_items[] = {
TC35874X_LINK_FREQ_300MHZ,
TC35874X_LINK_FREQ_310MHZ,
};
static const struct v4l2_dv_timings_cap tc35874x_timings_cap = {
@@ -77,7 +86,7 @@ static const struct v4l2_dv_timings_cap tc35874x_timings_cap = {
/* keep this initialization for compatibility with GCC < 4.4.6 */
.reserved = { 0 },
/* Pixel clock from REF_01 p. 20. Min/max height/width are unknown */
V4L2_INIT_BT_TIMINGS(1, 10000, 1, 10000, 0, 165000000,
V4L2_INIT_BT_TIMINGS(1, 10000, 1, 10000, 0, 310000000,
V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_INTERLACED |
@@ -123,6 +132,59 @@ static u8 EDID_extend[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32,
};
struct tc35874x_mode {
u32 width;
u32 height;
struct v4l2_fract max_fps;
u32 hts_def;
u32 vts_def;
u32 exp_def;
};
static const struct tc35874x_mode supported_modes[] = {
{
.width = 1920,
.height = 1080,
.max_fps = {
.numerator = 10000,
.denominator = 600000,
},
.exp_def = 0x470,
.hts_def = 0x898,
.vts_def = 0x465,
}, {
.width = 1280,
.height = 720,
.max_fps = {
.numerator = 10000,
.denominator = 600000,
},
.exp_def = 0x2f0,
.hts_def = 0x672,
.vts_def = 0x2ee,
}, {
.width = 720,
.height = 576,
.max_fps = {
.numerator = 10000,
.denominator = 500000,
},
.exp_def = 0x275,
.hts_def = 0x360,
.vts_def = 0x271,
}, {
.width = 720,
.height = 480,
.max_fps = {
.numerator = 10000,
.denominator = 600000,
},
.exp_def = 0x210,
.hts_def = 0x35a,
.vts_def = 0x20d,
},
};
struct tc35874x_state {
struct tc35874x_platform_data pdata;
struct v4l2_fwnode_bus_mipi_csi2 bus;
@@ -151,6 +213,15 @@ struct tc35874x_state {
u8 csi_lanes_in_use;
struct gpio_desc *reset_gpio;
struct cec_adapter *cec_adap;
u32 module_index;
const char *module_facing;
const char *module_name;
const char *len_name;
struct v4l2_ctrl *link_freq;
struct v4l2_ctrl *pixel_rate;
const struct tc35874x_mode *cur_mode;
};
static void tc35874x_enable_interrupts(struct v4l2_subdev *sd,
@@ -231,15 +302,15 @@ static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n)
switch (n) {
case 1:
v4l2_info(sd, "I2C write 0x%04x = 0x%02x",
v4l2_info(sd, "I2C write 0x%04x = 0x%02x\n",
reg, data[2]);
break;
case 2:
v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x",
v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x\n",
reg, data[3], data[2]);
break;
case 4:
v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x%02x%02x",
v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x%02x%02x\n",
reg, data[5], data[4], data[3], data[2]);
break;
default:
@@ -362,6 +433,8 @@ static int tc35874x_get_detected_timings(struct v4l2_subdev *sd,
{
struct v4l2_bt_timings *bt = &timings->bt;
unsigned width, height, frame_width, frame_height, frame_interval, fps;
struct tc35874x_state *state = to_state(sd);
u16 fifo_level;
memset(timings, 0, sizeof(struct v4l2_dv_timings));
@@ -411,6 +484,25 @@ static int tc35874x_get_detected_timings(struct v4l2_subdev *sd,
i2c_wr16(sd, FCCTL, 0);
}
if (state->csi_lanes_in_use == 4) {
if ((width == 1920 && height == 1080) ||
(width == 1280 && height == 720)) {
fifo_level = 370;
} else if ((width == 720 && height == 576) ||
(width == 720 && height == 480)) {
fifo_level = 350;
} else {
fifo_level = 300;
}
if ((bt->interlaced == V4L2_DV_INTERLACED) || (fps <= 33))
fifo_level = 300;
v4l2_dbg(2, debug, sd, "%s interlaced:%d, fifo_level:%d\n",
__func__, bt->interlaced, fifo_level);
i2c_wr16(sd, FIFOCTL, fifo_level);
}
return 0;
}
@@ -507,7 +599,7 @@ static void print_avi_infoframe(struct v4l2_subdev *sd)
i2c_rd(sd, PK_AVI_0HEAD, buffer, HDMI_INFOFRAME_SIZE(AVI));
if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
v4l2_err(sd, "%s: unpack of AVI infoframe failed\n", __func__);
return;
}
@@ -612,23 +704,43 @@ static void tc35874x_set_pll(struct v4l2_subdev *sd)
struct tc35874x_platform_data *pdata = &state->pdata;
u16 pllctl0 = i2c_rd16(sd, PLLCTL0);
u16 pllctl1 = i2c_rd16(sd, PLLCTL1);
u16 pllctl0_new = SET_PLL_PRD(pdata->pll_prd) |
SET_PLL_FBD(pdata->pll_fbd);
u32 hsck = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd;
u16 pllctl0_new;
u32 hsck;
u16 pll_frs;
v4l2_dbg(2, debug, sd, "%s:\n", __func__);
if (state->csi_lanes_in_use == 4) {
if ((state->timings.bt.interlaced) ||
(fps(&(state->timings.bt)) <= 33)) {
pdata->pll_prd = 2;
pdata->pll_fbd = 65;
pll_frs = 0x1;
} else {
pdata->pll_prd = 5;
pdata->pll_fbd = 138;
pll_frs = 0x0;
}
} else {
hsck = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd;
if (state->timings.bt.interlaced)
hsck /= 2;
if (hsck > 500000000)
pll_frs = 0x0;
else if (hsck > 250000000)
pll_frs = 0x1;
else if (hsck > 125000000)
pll_frs = 0x2;
else
pll_frs = 0x3;
}
pllctl0_new = SET_PLL_PRD(pdata->pll_prd) | SET_PLL_FBD(pdata->pll_fbd);
v4l2_dbg(1, debug, sd,
"%s: prd:%d, fbd:%d, frs:%d, interlaced:%d, fps:%d\n",
__func__, pdata->pll_prd, pdata->pll_fbd, pll_frs,
state->timings.bt.interlaced, fps(&(state->timings.bt)));
if (state->timings.bt.interlaced)
hsck /= 2;
if (hsck > 500000000)
pll_frs = 0x0;
else if (hsck > 250000000)
pll_frs = 0x1;
else if (hsck > 125000000)
pll_frs = 0x2;
else
pll_frs = 0x3;
/* Only rewrite when needed (new value or disabled), since rewriting
* triggers another format change event. */
if (pllctl0 != pllctl0_new || (pllctl1 & MASK_PLL_EN) == 0 ||
@@ -741,6 +853,33 @@ static void tc35874x_set_csi(struct v4l2_subdev *sd)
if (lanes < 4)
i2c_wr32(sd, D3W_CNTRL, MASK_D3W_LANEDISABLE);
v4l2_dbg(1, debug, sd, "%s: interlaced:%d, fps:%d\n", __func__,
state->timings.bt.interlaced, fps(&(state->timings.bt)));
if (state->csi_lanes_in_use == 4) {
if ((state->timings.bt.interlaced) ||
(fps(&(state->timings.bt)) <= 33)) {
state->pdata.lineinitcnt = 0x7d0;
state->pdata.lptxtimecnt = 0x002;
state->pdata.tclk_headercnt = 0x901;
state->pdata.tclk_trailcnt = 0x00;
state->pdata.ths_headercnt = 0x02;
state->pdata.twakeup = 0x32c8;
state->pdata.tclk_postcnt = 0x006;
state->pdata.ths_trailcnt = 0x0;
state->pdata.hstxvregcnt = 5;
} else {
state->pdata.lineinitcnt = 0x1770;
state->pdata.lptxtimecnt = 0x05;
state->pdata.tclk_headercnt = 0x1505;
state->pdata.tclk_trailcnt = 0x01;
state->pdata.ths_headercnt = 0x0105;
state->pdata.twakeup = 0x332c;
state->pdata.tclk_postcnt = 0x08;
state->pdata.ths_trailcnt = 0x02;
state->pdata.hstxvregcnt = 0x05;
}
}
i2c_wr32(sd, LINEINITCNT, pdata->lineinitcnt);
i2c_wr32(sd, LPTXTIMECNT, pdata->lptxtimecnt);
i2c_wr32(sd, TCLK_HEADERCNT, pdata->tclk_headercnt);
@@ -858,7 +997,7 @@ static void tc35874x_initial_setup(struct v4l2_subdev *sd)
struct tc35874x_platform_data *pdata = &state->pdata;
/* CEC and IR are not supported by this driver */
i2c_wr16_and_or(sd, SYSCTL, ~(MASK_CECRST | MASK_IRRST),
i2c_wr16_and_or(sd, SYSCTL, ~(MASK_CECRST | MASK_IRRST | MASK_I2SDIS),
(MASK_CECRST | MASK_IRRST));
tc35874x_reset(sd, MASK_CTXRST | MASK_HDMIRST);
@@ -902,7 +1041,7 @@ static void tc35874x_format_change(struct v4l2_subdev *sd)
v4l2_dbg(1, debug, sd, "%s: No signal\n",
__func__);
} else {
if (!v4l2_match_dv_timings(&state->timings, &timings, 0)) {
if (!v4l2_match_dv_timings(&state->timings, &timings, 0, false)) {
enable_stream(sd, false);
/* automaticly set timing rather than set by userspace */
tc35874x_s_dv_timings(sd, &timings);
@@ -1143,6 +1282,23 @@ static void tc35874x_hdmi_sys_int_handler(struct v4l2_subdev *sd, bool *handled)
}
}
/* --------------- CTRL OPS --------------- */
static int tc35874x_get_ctrl(struct v4l2_ctrl *ctrl)
{
int ret = -1;
struct tc35874x_state *state = container_of(ctrl->handler,
struct tc35874x_state, hdl);
struct v4l2_subdev *sd = &(state->sd);
if (ctrl->id == V4L2_CID_DV_RX_POWER_PRESENT) {
ret = tx_5v_power_present(sd);
*ctrl->p_new.p_s32 = ret;
}
return ret;
}
/* --------------- CORE OPS --------------- */
static int tc35874x_log_status(struct v4l2_subdev *sd)
@@ -1368,13 +1524,19 @@ static irqreturn_t tc35874x_irq_handler(int irq, void *dev_id)
return handled ? IRQ_HANDLED : IRQ_NONE;
}
static void tc35874x_irq_poll_timer(unsigned long arg)
static void tc35874x_irq_poll_timer(struct timer_list *t)
{
struct tc35874x_state *state = (struct tc35874x_state *)arg;
struct tc35874x_state *state = from_timer(state, t, timer);
unsigned int msecs;
schedule_work(&state->work_i2c_poll);
mod_timer(&state->timer, jiffies + msecs_to_jiffies(POLL_INTERVAL_MS));
/*
* If CEC is present, then we need to poll more frequently,
* otherwise we will miss CEC messages.
*/
msecs = state->cec_adap ? POLL_INTERVAL_CEC_MS : POLL_INTERVAL_MS;
mod_timer(&state->timer, jiffies + msecs_to_jiffies(msecs));
}
static void tc35874x_work_i2c_poll(struct work_struct *work)
@@ -1424,7 +1586,7 @@ static int tc35874x_s_dv_timings(struct v4l2_subdev *sd,
v4l2_print_dv_timings(sd->name, "tc35874x_s_dv_timings: ",
timings, false);
if (v4l2_match_dv_timings(&state->timings, timings, 0)) {
if (v4l2_match_dv_timings(&state->timings, timings, 0, false)) {
v4l2_dbg(1, debug, sd, "%s: no change\n", __func__);
return 0;
}
@@ -1545,17 +1707,55 @@ static int tc35874x_enum_mbus_code(struct v4l2_subdev *sd,
{
switch (code->index) {
case 0:
code->code = MEDIA_BUS_FMT_RGB888_1X24;
break;
case 1:
code->code = MEDIA_BUS_FMT_UYVY8_2X8;
break;
/*
case 1:
code->code = MEDIA_BUS_FMT_RGB888_1X24;
break;
*/
default:
return -EINVAL;
}
return 0;
}
static int tc35874x_enum_frame_sizes(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_frame_size_enum *fse)
{
v4l2_dbg(1, debug, sd, "%s:\n", __func__);
if (fse->index >= ARRAY_SIZE(supported_modes))
return -EINVAL;
if (fse->code != MEDIA_BUS_FMT_UYVY8_2X8)
return -EINVAL;
fse->min_width = supported_modes[fse->index].width;
fse->max_width = supported_modes[fse->index].width;
fse->max_height = supported_modes[fse->index].height;
fse->min_height = supported_modes[fse->index].height;
return 0;
}
static int tc35874x_enum_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_frame_interval_enum *fie)
{
if (fie->index >= ARRAY_SIZE(supported_modes))
return -EINVAL;
if (fie->code != MEDIA_BUS_FMT_UYVY8_2X8)
return -EINVAL;
fie->width = supported_modes[fie->index].width;
fie->height = supported_modes[fie->index].height;
fie->interval = supported_modes[fie->index].max_fps;
return 0;
}
static int tc35874x_get_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
@@ -1591,11 +1791,39 @@ static int tc35874x_get_fmt(struct v4l2_subdev *sd,
return 0;
}
static int tc35874x_get_reso_dist(const struct tc35874x_mode *mode,
struct v4l2_mbus_framefmt *framefmt)
{
return abs(mode->width - framefmt->width) +
abs(mode->height - framefmt->height);
}
static const struct tc35874x_mode *
tc35874x_find_best_fit(struct v4l2_subdev_format *fmt)
{
struct v4l2_mbus_framefmt *framefmt = &fmt->format;
int dist;
int cur_best_fit = 0;
int cur_best_fit_dist = -1;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
dist = tc35874x_get_reso_dist(&supported_modes[i], framefmt);
if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
cur_best_fit_dist = dist;
cur_best_fit = i;
}
}
return &supported_modes[cur_best_fit];
}
static int tc35874x_set_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
{
struct tc35874x_state *state = to_state(sd);
const struct tc35874x_mode *mode;
u32 code = format->format.code; /* is overwritten by get_fmt */
int ret = tc35874x_get_fmt(sd, cfg, format);
@@ -1619,6 +1847,14 @@ static int tc35874x_set_fmt(struct v4l2_subdev *sd,
state->mbus_fmt_code = format->format.code;
enable_stream(sd, false);
mode = tc35874x_find_best_fit(format);
state->cur_mode = mode;
__v4l2_ctrl_s_ctrl(state->link_freq,
link_freq_menu_items[0]);
__v4l2_ctrl_s_ctrl_int64(state->pixel_rate,
TC35874X_PIXEL_RATE_310M);
tc35874x_set_pll(sd);
tc35874x_set_csi(sd);
tc35874x_set_csi_color_space(sd);
@@ -1703,8 +1939,95 @@ static int tc35874x_s_edid(struct v4l2_subdev *sd,
return 0;
}
static int tc35874x_g_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_frame_interval *fi)
{
struct tc35874x_state *state = to_state(sd);
const struct tc35874x_mode *mode = state->cur_mode;
mutex_lock(&state->confctl_mutex);
fi->interval = mode->max_fps;
mutex_unlock(&state->confctl_mutex);
return 0;
}
static void tc35874x_get_module_inf(struct tc35874x_state *tc35874x,
struct rkmodule_inf *inf)
{
memset(inf, 0, sizeof(*inf));
strlcpy(inf->base.sensor, TC35874X_NAME, sizeof(inf->base.sensor));
strlcpy(inf->base.module, tc35874x->module_name,
sizeof(inf->base.module));
strlcpy(inf->base.lens, tc35874x->len_name, sizeof(inf->base.lens));
}
static long tc35874x_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
{
struct tc35874x_state *tc35874x = to_state(sd);
long ret = 0;
switch (cmd) {
case RKMODULE_GET_MODULE_INFO:
tc35874x_get_module_inf(tc35874x, (struct rkmodule_inf *)arg);
break;
default:
ret = -ENOIOCTLCMD;
break;
}
return ret;
}
#ifdef CONFIG_COMPAT
static long tc35874x_compat_ioctl32(struct v4l2_subdev *sd,
unsigned int cmd, unsigned long arg)
{
void __user *up = compat_ptr(arg);
struct rkmodule_inf *inf;
struct rkmodule_awb_cfg *cfg;
long ret;
switch (cmd) {
case RKMODULE_GET_MODULE_INFO:
inf = kzalloc(sizeof(*inf), GFP_KERNEL);
if (!inf) {
ret = -ENOMEM;
return ret;
}
ret = tc35874x_ioctl(sd, cmd, inf);
if (!ret)
ret = copy_to_user(up, inf, sizeof(*inf));
kfree(inf);
break;
case RKMODULE_AWB_CFG:
cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
if (!cfg) {
ret = -ENOMEM;
return ret;
}
ret = copy_from_user(cfg, up, sizeof(*cfg));
if (!ret)
ret = tc35874x_ioctl(sd, cmd, cfg);
kfree(cfg);
break;
default:
ret = -ENOIOCTLCMD;
break;
}
return ret;
}
#endif
/* -------------------------------------------------------------------------- */
static const struct v4l2_ctrl_ops tc35874x_ctrl_ops = {
.g_volatile_ctrl = tc35874x_get_ctrl,
};
static const struct v4l2_subdev_core_ops tc35874x_core_ops = {
.log_status = tc35874x_log_status,
#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1714,6 +2037,10 @@ static const struct v4l2_subdev_core_ops tc35874x_core_ops = {
.interrupt_service_routine = tc35874x_isr,
.subscribe_event = tc35874x_subscribe_event,
.unsubscribe_event = v4l2_event_subdev_unsubscribe,
.ioctl = tc35874x_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl32 = tc35874x_compat_ioctl32,
#endif
};
static const struct v4l2_subdev_video_ops tc35874x_video_ops = {
@@ -1723,10 +2050,13 @@ static const struct v4l2_subdev_video_ops tc35874x_video_ops = {
.query_dv_timings = tc35874x_query_dv_timings,
.g_mbus_config = tc35874x_g_mbus_config,
.s_stream = tc35874x_s_stream,
.g_frame_interval = tc35874x_g_frame_interval,
};
static const struct v4l2_subdev_pad_ops tc35874x_pad_ops = {
.enum_mbus_code = tc35874x_enum_mbus_code,
.enum_frame_size = tc35874x_enum_frame_sizes,
.enum_frame_interval = tc35874x_enum_frame_interval,
.set_fmt = tc35874x_set_fmt,
.get_fmt = tc35874x_get_fmt,
.get_edid = tc35874x_g_edid,
@@ -1931,8 +2261,16 @@ static int tc35874x_probe(struct i2c_client *client,
struct tc35874x_platform_data *pdata = client->dev.platform_data;
struct v4l2_subdev *sd;
struct v4l2_subdev_edid def_edid;
struct device *dev = &client->dev;
struct device_node *node = dev->of_node;
char facing[2];
int err, data;
dev_info(dev, "driver version: %02x.%02x.%02x",
DRIVER_VERSION >> 16,
(DRIVER_VERSION & 0xff00) >> 8,
DRIVER_VERSION & 0x00ff);
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -EIO;
v4l_dbg(1, debug, client, "chip found @ 0x%x (%s)\n",
@@ -1943,7 +2281,21 @@ static int tc35874x_probe(struct i2c_client *client,
if (!state)
return -ENOMEM;
err = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
&state->module_index);
err |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
&state->module_facing);
err |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
&state->module_name);
err |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
&state->len_name);
if (err) {
dev_err(dev, "could not get module information!\n");
return -EINVAL;
}
state->i2c_client = client;
state->cur_mode = &supported_modes[0];
/* platform data */
if (pdata) {
@@ -1976,14 +2328,19 @@ static int tc35874x_probe(struct i2c_client *client,
/* control handlers */
v4l2_ctrl_handler_init(&state->hdl, 4);
v4l2_ctrl_new_int_menu(&state->hdl, NULL, V4L2_CID_LINK_FREQ,
0, 0, link_freq_menu_items);
state->link_freq = v4l2_ctrl_new_int_menu(&state->hdl, NULL,
V4L2_CID_LINK_FREQ, 0, 0, link_freq_menu_items);
v4l2_ctrl_new_std(&state->hdl, NULL, V4L2_CID_PIXEL_RATE,
0, TC35874X_PIXEL_RATE, 1, TC35874X_PIXEL_RATE);
state->pixel_rate = v4l2_ctrl_new_std(&state->hdl, NULL,
V4L2_CID_PIXEL_RATE, 0, TC35874X_PIXEL_RATE_310M, 1,
TC35874X_PIXEL_RATE_310M);
state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&state->hdl, NULL,
V4L2_CID_DV_RX_POWER_PRESENT, 0, 1, 0, 0);
state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&state->hdl,
&tc35874x_ctrl_ops, V4L2_CID_DV_RX_POWER_PRESENT,
0, 1, 0, 0);
if (state->detect_tx_5v_ctrl)
state->detect_tx_5v_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
/* custom controls */
state->audio_sampling_rate_ctrl = v4l2_ctrl_new_custom(&state->hdl,
@@ -2007,14 +2364,23 @@ static int tc35874x_probe(struct i2c_client *client,
}
state->pad.flags = MEDIA_PAD_FL_SOURCE;
sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
err = media_entity_init(&sd->entity, 1, &state->pad, 0);
sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
err = media_entity_pads_init(&sd->entity, 1, &state->pad);
if (err < 0)
goto err_hdl;
state->mbus_fmt_code = MEDIA_BUS_FMT_UYVY8_2X8;
sd->dev = &client->dev;
memset(facing, 0, sizeof(facing));
if (strcmp(state->module_facing, "back") == 0)
facing[0] = 'b';
else
facing[0] = 'f';
snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s",
state->module_index, facing,
TC35874X_NAME, dev_name(sd->dev));
err = v4l2_async_register_subdev(sd);
if (err < 0)
goto err_hdl;
@@ -2050,8 +2416,7 @@ static int tc35874x_probe(struct i2c_client *client,
} else {
INIT_WORK(&state->work_i2c_poll,
tc35874x_work_i2c_poll);
state->timer.data = (unsigned long)state;
state->timer.function = tc35874x_irq_poll_timer;
timer_setup(&state->timer, tc35874x_irq_poll_timer, 0);
state->timer.expires = jiffies +
msecs_to_jiffies(POLL_INTERVAL_MS);
add_timer(&state->timer);
@@ -2118,7 +2483,7 @@ MODULE_DEVICE_TABLE(of, tc35874x_of_match);
static struct i2c_driver tc35874x_driver = {
.driver = {
.name = "tc35874x",
.name = TC35874X_NAME,
.of_match_table = of_match_ptr(tc35874x_of_match),
},
.probe = tc35874x_probe,
@@ -2126,4 +2491,15 @@ static struct i2c_driver tc35874x_driver = {
.id_table = tc35874x_id,
};
module_i2c_driver(tc35874x_driver);
static int __init tc35874x_driver_init(void)
{
return i2c_add_driver(&tc35874x_driver);
}
static void __exit tc35874x_driver_exit(void)
{
i2c_del_driver(&tc35874x_driver);
}
device_initcall_sync(tc35874x_driver_init);
module_exit(tc35874x_driver_exit);

View File

@@ -39,6 +39,7 @@
#define MASK_CECRST 0x0400
#define MASK_CTXRST 0x0200
#define MASK_HDMIRST 0x0100
#define MASK_I2SDIS 0x0080
#define MASK_SLEEP 0x0001
#define CONFCTL 0x0004