Thank you for your reply.
My driver is just like imx185_v1.c.
I deleted some code about register write/read which is for frame length,coarse time,gain.
static inline void ar0134a_get_frame_length_regs(ar0134_reg *regs,
u32 frame_length)
{
}
static inline void ar0134a_get_coarse_time_regs_shs1(ar0134_reg *regs,
u32 coarse_time)
{
}
static inline void ar0134a_get_coarse_time_regs_shs2(ar0134_reg *regs,
u32 coarse_time)
{
}
static inline void ar0134a_get_gain_reg(ar0134_reg *regs,
u8 gain)
{
}
static int test_mode;
module_param(test_mode, int, 0644);
static int ar0134a_power_on(struct camera_common_data *s_data)
{
struct ar0134 *priv = (struct ar0134 *)s_data->priv;
struct camera_common_power_rail *pw = &priv->power;
pw->state = SWITCH_ON;
return 0;
}
static int ar0134a_power_off(struct camera_common_data *s_data)
{
struct ar0134 *priv = (struct ar0134 *)s_data->priv;
struct camera_common_power_rail *pw = &priv->power;
pw->state = SWITCH_OFF;
return 0;
}
static int ar0134a_power_get(struct ar0134 *priv)
{
struct camera_common_power_rail *pw = &priv->power;
struct camera_common_pdata *pdata = priv->pdata;
struct device *dev = &priv->i2c_client->dev;
const char *mclk_name;
struct clk *parent;
int err = 0;
mclk_name = priv->pdata->mclk_name ?
priv->pdata->mclk_name : "extperiph1";
pw->mclk = devm_clk_get(&priv->i2c_client->dev, mclk_name);
if (IS_ERR(pw->mclk)) {
dev_err(dev,"unable to get clock %s\n", mclk_name);
return PTR_ERR(pw->mclk);
}
parent = devm_clk_get(&priv->i2c_client->dev, "pllp_grtba");
if (IS_ERR(parent))
dev_err(dev, "devm_clk_get failed for pllp_grtba");
else
clk_set_parent(pw->mclk, parent);
pw->reset_gpio = pdata->reset_gpio;
pw->state = SWITCH_OFF;
return err;
}
static int ar0134a_set_coarse_time(struct ar0134 *priv, s64 val);
static int ar0134a_set_coarse_time_hdr(struct ar0134 *priv, s64 val);
static int ar0134a_set_gain(struct ar0134 *priv, s64 val);
static int ar0134a_set_frame_rate(struct ar0134 *priv, s64 val);
static int ar0134a_set_exposure(struct ar0134 *priv, s64 val);
static int ar0134a_s_stream(struct v4l2_subdev *sd, int enable)
{
return 0;
}
static int ar0134a_g_input_status(struct v4l2_subdev *sd, u32 *status)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct camera_common_data *s_data = to_camera_common_data(&client->dev);
struct ar0134 *priv = (struct ar0134 *)s_data->priv;
struct camera_common_power_rail *pw = &priv->power;
*status = pw->state == SWITCH_ON;
return 0;
}
static struct v4l2_subdev_video_ops ar0134a_subdev_video_ops = {
.s_stream = ar0134a_s_stream,
.g_mbus_config = camera_common_g_mbus_config,
.g_input_status = ar0134a_g_input_status,
};
static struct v4l2_subdev_core_ops ar0134a_subdev_core_ops = {
.s_power = camera_common_s_power,
};
static int ar0134a_get_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
{
return camera_common_g_fmt(sd, &format->format);
}
static int ar0134a_set_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
{
int ret;
if (format->which == V4L2_SUBDEV_FORMAT_TRY)
{
ret = camera_common_try_fmt(sd, &format->format);
}
else
{
ret = camera_common_s_fmt(sd, &format->format);
}
return ret;
}
static struct v4l2_subdev_pad_ops ar0134a_subdev_pad_ops = {
.set_fmt = ar0134a_set_fmt,
.get_fmt = ar0134a_get_fmt,
.enum_mbus_code = camera_common_enum_mbus_code,
.enum_frame_size = camera_common_enum_framesizes,
.enum_frame_interval = camera_common_enum_frameintervals,
};
static struct v4l2_subdev_ops ar0134a_subdev_ops = {
.core = &ar0134a_subdev_core_ops,
.video = &ar0134a_subdev_video_ops,
.pad = &ar0134a_subdev_pad_ops,
};
static struct camera_common_sensor_ops ar0134a_common_ops = {
.power_on = ar0134a_power_on,
.power_off = ar0134a_power_off,
.write_reg = uglyNv_write_reg,
.read_reg = uglyNv_read_reg,
};
static int ar0134a_set_group_hold(struct ar0134 *priv, s32 val)
{
int err;
int gh_en = switch_ctrl_qmenu[val];
priv->group_hold_prev = val;
if (gh_en == SWITCH_ON) {
err = uglyNv_write_reg(priv->s_data,
AR0134_GROUP_HOLD_ADDR, 0x1);
if (err)
goto fail;
} else if (gh_en == SWITCH_OFF) {
err = uglyNv_write_reg(priv->s_data,
AR0134_GROUP_HOLD_ADDR, 0x0);
if (err)
goto fail;
}
return 0;
fail:
dev_dbg(&priv->i2c_client->dev,
"%s: Group hold control error\n", __func__);
return err;
}
static int ar0134a_set_gain(struct ar0134 *priv, s64 val)
{
return 0;
}
static int ar0134a_set_frame_rate(struct ar0134 *priv, s64 val)
{
int err;
u32 frame_length;
struct camera_common_data *s_data = priv->s_data;
const struct sensor_mode_properties *mode =
&s_data->sensor_props.sensor_modes[s_data->mode];
struct v4l2_control control;
struct device *dev = &priv->i2c_client->dev;
int hdr_en;
frame_length = mode->signal_properties.pixel_clock.val *
FIXED_POINT_SCALING_FACTOR /
mode->image_properties.line_length / val;
priv->frame_length = frame_length;
if (priv->frame_length > AR0134_MAX_FRAME_LENGTH)
priv->frame_length = AR0134_MAX_FRAME_LENGTH;
dev_dbg(&priv->i2c_client->dev,
"%s: val: %lld, , frame_length: %d\n", __func__,
val, priv->frame_length);
control.id = TEGRA_CAMERA_CID_HDR_EN;
err = camera_common_g_ctrl(priv->s_data, &control);
if (err < 0) {
dev_err(dev,"could not find device ctrl.\n");
return err;
}
hdr_en = switch_ctrl_qmenu[control.value];
if ((hdr_en == SWITCH_ON) && (priv->last_wdr_et_val != 0)) {
err = ar0134a_set_coarse_time_hdr(priv, priv->last_wdr_et_val);
if (err)
dev_dbg(&priv->i2c_client->dev,
"%s: error coarse time SHS1 SHS2 override\n", __func__);
}
return 0;
}
static int ar0134a_set_exposure(struct ar0134 *priv, s64 val)
{
int err;
struct v4l2_control control;
struct device *dev = &priv->i2c_client->dev;
int hdr_en;
dev_dbg(&priv->i2c_client->dev,
"%s: val: %lld\n", __func__, val);
control.id = TEGRA_CAMERA_CID_HDR_EN;
err = camera_common_g_ctrl(priv->s_data, &control);
if (err < 0) {
dev_err(dev,"could not find device ctrl.\n");
return err;
}
hdr_en = switch_ctrl_qmenu[control.value];
if (hdr_en == SWITCH_ON) {
err = ar0134a_set_coarse_time_hdr(priv, val);
if (err)
dev_dbg(&priv->i2c_client->dev,
"%s: error coarse time SHS1 SHS2 override\n", __func__);
} else {
err = ar0134a_set_coarse_time(priv, val);
if (err)
dev_dbg(&priv->i2c_client->dev,
"%s: error coarse time SHS1 override\n", __func__);
}
return err;
}
static int ar0134a_set_coarse_time(struct ar0134 *priv, s64 val)
{
return 0;
}
static int ar0134a_set_coarse_time_hdr(struct ar0134 *priv, s64 val)
{
return 0;
}
static int ar0134a_fuse_id_setup(struct ar0134 *priv)
{
return 0;
}
static int ar0134a_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
{
struct ar0134 *priv =
container_of(ctrl->handler, struct ar0134, ctrl_handler);
struct device *dev = &priv->i2c_client->dev;
int err = 0;
if (priv->power.state == SWITCH_OFF)
return 0;
switch (ctrl->id) {
default:
dev_err(dev,"%s: unknown ctrl id.\n", __func__);
return -EINVAL;
}
return err;
}
static int ar0134a_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct ar0134 *priv =
container_of(ctrl->handler, struct ar0134, ctrl_handler);
struct device *dev = &priv->i2c_client->dev;
struct camera_common_data *s_data = priv->s_data;
int err = 0;
if (priv->power.state == SWITCH_OFF)
return 0;
switch (ctrl->id) {
case TEGRA_CAMERA_CID_GAIN:
err = ar0134a_set_gain(priv, *ctrl->p_new.p_s64);
break;
case TEGRA_CAMERA_CID_EXPOSURE:
err = ar0134a_set_exposure(priv, *ctrl->p_new.p_s64);
break;
case TEGRA_CAMERA_CID_FRAME_RATE:
err = ar0134a_set_frame_rate(priv, *ctrl->p_new.p_s64);
break;
case TEGRA_CAMERA_CID_GROUP_HOLD:
err = ar0134a_set_group_hold(priv, ctrl->val);
break;
case TEGRA_CAMERA_CID_HDR_EN:
break;
case TEGRA_CAMERA_CID_SENSOR_MODE_ID:
s_data->sensor_mode_id = (int) (*ctrl->p_new.p_s64);
break;
default:
dev_err(dev,"%s: unknown ctrl id.\n", __func__);
return -EINVAL;
}
return err;
}
static int ar0134a_ctrls_init(struct ar0134 *priv)
{
struct i2c_client *client = priv->i2c_client;
struct v4l2_ctrl *ctrl;
int num_ctrls;
int err;
int i;
dev_dbg(&client->dev, "%s++\n", __func__);
dev_dbg(&client->dev, "\n****XX:%s++\n", __func__);
num_ctrls = ARRAY_SIZE(ctrl_config_list);
v4l2_ctrl_handler_init(&priv->ctrl_handler, num_ctrls);
for (i = 0; i < num_ctrls; i++) {
ctrl = v4l2_ctrl_new_custom(&priv->ctrl_handler,
&ctrl_config_list[i], NULL);
if (ctrl == NULL) {
dev_err(&client->dev, "Failed to init %s ctrl\n",
ctrl_config_list[i].name);
continue;
}
if (ctrl_config_list[i].type == V4L2_CTRL_TYPE_STRING &&
ctrl_config_list[i].flags & V4L2_CTRL_FLAG_READ_ONLY) {
ctrl->p_new.p_char = devm_kzalloc(&client->dev,
ctrl_config_list[i].max + 1, GFP_KERNEL);
}
priv->ctrls[i] = ctrl;
}
priv->numctrls = num_ctrls;
priv->subdev->ctrl_handler = &priv->ctrl_handler;
if (priv->ctrl_handler.error) {
dev_err(&client->dev, "Error %d adding controls\n",
priv->ctrl_handler.error);
err = priv->ctrl_handler.error;
goto error;
}
err = v4l2_ctrl_handler_setup(&priv->ctrl_handler);
if (err) {
dev_err(&client->dev,
"Error %d setting default controls\n", err);
goto error;
}
err = ar0134a_fuse_id_setup(priv);
if (err) {
dev_err(&client->dev,
"Error %d reading fuse id data\n", err);
goto error;
}
return 0;
error:
v4l2_ctrl_handler_free(&priv->ctrl_handler);
return err;
}
we use ar0134,the hardware about camera is:
ar0134(parallel)—>DS92LV16TVHG(serial)---->DS92LV16TVHG(deserial,parallel)---->FPGA(parallel)----->tc358748---->csi