From e21462512c3f8f19742fa31ca175a5c3043dd879 Mon Sep 17 00:00:00 2001 From: Hu Kejun Date: Thu, 14 Feb 2019 17:02:07 +0800 Subject: [PATCH] media: spi: RK1608: add more config information Change-Id: Ic68ef2dfdcf72a721dca3c4ad263f429144ed537 Signed-off-by: Hu Kejun --- drivers/media/spi/rk1608.c | 76 ++++++++++++++++++--------------- drivers/media/spi/rk1608.h | 4 +- drivers/media/spi/rk1608_dphy.c | 44 ++++++++++++++++++- drivers/media/spi/rk1608_dphy.h | 18 +++++++- 4 files changed, 104 insertions(+), 38 deletions(-) diff --git a/drivers/media/spi/rk1608.c b/drivers/media/spi/rk1608.c index f788382ddeb8..453ae923f7d9 100644 --- a/drivers/media/spi/rk1608.c +++ b/drivers/media/spi/rk1608.c @@ -472,8 +472,6 @@ static int rk1608_lsb_w32(struct spi_device *spi, s32 addr, s32 data) static int rk1608_msg_init_sensor(struct rk1608_state *pdata, struct msg_init *msg, int id) { - struct i2c_client *client; - msg->msg_head.size = sizeof(struct msg_init); msg->msg_head.type = id_msg_init_sensor_t; msg->msg_head.id.camera_id = id; @@ -482,12 +480,11 @@ static int rk1608_msg_init_sensor(struct rk1608_state *pdata, msg->out_mipi_phy = pdata->dphy[id]->out_mipi; msg->mipi_lane = pdata->dphy[id]->mipi_lane; msg->bayer = 0; - memcpy(msg->sensor_name, pdata->sensor[id]->name, + memcpy(msg->sensor_name, pdata->dphy[id]->sensor_name, sizeof(msg->sensor_name)); - client = v4l2_get_subdevdata(pdata->sensor[id]); - msg->i2c_slave_addr = (client->addr) << 1; - msg->i2c_bus = 1; + msg->i2c_slave_addr = pdata->dphy[id]->i2c_addr; + msg->i2c_bus = pdata->dphy[id]->i2c_bus; return rk1608_send_msg_to_dsp(pdata, &msg->msg_head); } @@ -495,30 +492,50 @@ static int rk1608_msg_init_sensor(struct rk1608_state *pdata, static int rk1608_msg_set_input_size(struct rk1608_state *pdata, struct msg_in_size *msg, int id) { - msg->msg_head.size = sizeof(struct msg_in_size) / sizeof(int); + u32 i; + u32 msg_size = sizeof(struct msg); + + for (i = 0; i < 4; i++) { + if (pdata->dphy[id]->in_ch[i].width == 0) + break; + + msg->channel[i].width = pdata->dphy[id]->in_ch[i].width; + msg->channel[i].height = pdata->dphy[id]->in_ch[i].height; + msg->channel[i].data_id = pdata->dphy[id]->in_ch[i].data_id; + msg->channel[i].decode_format = + pdata->dphy[id]->in_ch[i].decode_format; + msg->channel[i].flag = pdata->dphy[id]->in_ch[i].flag; + msg_size += sizeof(struct preisp_vc_cfg); + } + + msg->msg_head.size = msg_size / sizeof(int); msg->msg_head.type = id_msg_set_input_size_t; msg->msg_head.id.camera_id = id; msg->msg_head.mux.sync = 1; - msg->channel[0].data_id = 0x6b; - msg->channel[0].decode_format = 0x2b; - msg->channel[0].flag = 1; - msg->channel[0].width = pdata->dphy[id]->mf.width; - msg->channel[0].height = pdata->dphy[id]->mf.height * 2; - - msg->channel[1].data_id = 0x2b; - msg->channel[1].decode_format = 0x2b; - msg->channel[1].flag = 2; - msg->channel[1].width = pdata->dphy[id]->mf.width; - msg->channel[1].height = pdata->dphy[id]->mf.height; - return rk1608_send_msg_to_dsp(pdata, &msg->msg_head); } static int rk1608_msg_set_output_size(struct rk1608_state *pdata, struct msg_set_output_size *msg, int id) { - msg->head.msg_head.size = sizeof(struct msg_set_output_size) / sizeof(int); + u32 i; + u32 msg_size = sizeof(struct msg_out_size_head); + + for (i = 0; i < 4; i++) { + if (pdata->dphy[id]->out_ch[i].width == 0) + break; + + msg->channel[i].width = pdata->dphy[id]->out_ch[i].width; + msg->channel[i].height = pdata->dphy[id]->out_ch[i].height; + msg->channel[i].data_id = pdata->dphy[id]->out_ch[i].data_id; + msg->channel[i].decode_format = + pdata->dphy[id]->out_ch[i].decode_format; + msg->channel[i].flag = pdata->dphy[id]->out_ch[i].flag; + msg_size += sizeof(struct preisp_vc_cfg); + } + + msg->head.msg_head.size = msg_size / sizeof(int); msg->head.msg_head.type = id_msg_set_output_size_t; msg->head.msg_head.id.camera_id = id; msg->head.msg_head.mux.sync = 1; @@ -529,18 +546,6 @@ static int rk1608_msg_set_output_size(struct rk1608_state *pdata, msg->head.frame_length_lines = pdata->dphy[id]->vtotal; msg->head.mipi_lane = pdata->dphy[id]->mipi_lane; - msg->channel[0].data_id = 0x2b; - msg->channel[0].decode_format = 0x2b; - msg->channel[0].flag = 1; - msg->channel[0].width = pdata->dphy[id]->mf.width; - msg->channel[0].height = pdata->dphy[id]->mf.height; - - msg->channel[1].data_id = 0x30; - msg->channel[1].decode_format = 0x2b; - msg->channel[1].flag = 0; - msg->channel[1].width = pdata->dphy[id]->mf.width; - msg->channel[1].height = 2; - return rk1608_send_msg_to_dsp(pdata, &msg->head.msg_head); } @@ -891,10 +896,13 @@ static int rk1608_s_stream(struct v4l2_subdev *sd, int enable) int ret; struct rk1608_state *pdata = to_state(sd); - if (enable) + if (enable) { + v4l2_subdev_call(pdata->sensor[sd->grp_id], core, s_power, enable); ret = rk1608_stream_on(pdata); - else + } else { ret = rk1608_stream_off(pdata); + v4l2_subdev_call(pdata->sensor[sd->grp_id], core, s_power, enable); + } v4l2_subdev_call(pdata->sensor[sd->grp_id], video, s_stream, enable); diff --git a/drivers/media/spi/rk1608.h b/drivers/media/spi/rk1608.h index f011ba791a94..ef1e0905b746 100644 --- a/drivers/media/spi/rk1608.h +++ b/drivers/media/spi/rk1608.h @@ -197,7 +197,7 @@ struct preisp_vc_cfg { struct msg_in_size { struct msg msg_head; - struct preisp_vc_cfg channel[2]; + struct preisp_vc_cfg channel[4]; }; struct msg_out_size_head { @@ -212,7 +212,7 @@ struct msg_out_size_head { struct msg_set_output_size { struct msg_out_size_head head; - struct preisp_vc_cfg channel[2]; + struct preisp_vc_cfg channel[4]; }; enum ISP_AE_Bayer_Mode_e { diff --git a/drivers/media/spi/rk1608_dphy.c b/drivers/media/spi/rk1608_dphy.c index 7ef1d7b7f72e..008b77ca5c1b 100644 --- a/drivers/media/spi/rk1608_dphy.c +++ b/drivers/media/spi/rk1608_dphy.c @@ -347,7 +347,8 @@ static int rk1608_initialize_controls(struct rk1608_dphy *dphy) pixel_bit = 8; break; } - pixel_rate = V4L2_CID_LINK_FREQ * dphy->mipi_lane * 2 / pixel_bit; + pixel_rate = dphy->link_freqs * dphy->mipi_lane * 2; + do_div(pixel_rate, pixel_bit); dphy->pixel_rate = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, 0, pixel_rate, 1, pixel_rate); @@ -453,6 +454,12 @@ static int rk1608_dphy_dt_property(struct rk1608_dphy *dphy) ret = of_property_read_u32(node, "mipi_lane", &dphy->mipi_lane); if (ret) dev_warn(dphy->dev, "Can not get mipi_lane!"); + ret = of_property_read_u32(node, "sensor_i2c_bus", &dphy->i2c_bus); + if (ret) + dev_warn(dphy->dev, "Can not get sensor_i2c_bus!"); + ret = of_property_read_u32(node, "sensor_i2c_addr", &dphy->i2c_addr); + if (ret) + dev_warn(dphy->dev, "Can not get sensor_i2c_addr!"); ret = of_property_read_u32(node, "field", &dphy->mf.field); if (ret) dev_warn(dphy->dev, "Can not get field!"); @@ -477,6 +484,41 @@ static int rk1608_dphy_dt_property(struct rk1608_dphy *dphy) ret = of_property_read_u64(node, "link-freqs", &dphy->link_freqs); if (ret) dev_warn(dphy->dev, "Can not get link_freqs!"); + ret = of_property_read_string(node, "sensor-name", &dphy->sensor_name); + if (ret) + dev_warn(dphy->dev, "Can not get sensor-name!"); + ret = of_property_read_u32_array(node, "inch0-info", + (u32 *)&dphy->in_ch[0], 5); + if (ret) + dev_warn(dphy->dev, "Can not get inch0-info!"); + ret = of_property_read_u32_array(node, "inch1-info", + (u32 *)&dphy->in_ch[1], 5); + if (ret) + dev_info(dphy->dev, "Can not get inch1-info!"); + ret = of_property_read_u32_array(node, "inch2-info", + (u32 *)&dphy->in_ch[2], 5); + if (ret) + dev_info(dphy->dev, "Can not get inch2-info!"); + ret = of_property_read_u32_array(node, "inch3-info", + (u32 *)&dphy->in_ch[3], 5); + if (ret) + dev_info(dphy->dev, "Can not get inch3-info!"); + ret = of_property_read_u32_array(node, "outch0-info", + (u32 *)&dphy->out_ch[0], 5); + if (ret) + dev_warn(dphy->dev, "Can not get outch0-info!"); + ret = of_property_read_u32_array(node, "outch1-info", + (u32 *)&dphy->out_ch[1], 5); + if (ret) + dev_info(dphy->dev, "Can not get outch1-info!"); + ret = of_property_read_u32_array(node, "outch2-info", + (u32 *)&dphy->out_ch[2], 5); + if (ret) + dev_info(dphy->dev, "Can not get outch2-info!"); + ret = of_property_read_u32_array(node, "outch3-info", + (u32 *)&dphy->out_ch[3], 5); + if (ret) + dev_info(dphy->dev, "Can not get outch3-info!"); return ret; } diff --git a/drivers/media/spi/rk1608_dphy.h b/drivers/media/spi/rk1608_dphy.h index 2da36455a098..918fd72a774a 100644 --- a/drivers/media/spi/rk1608_dphy.h +++ b/drivers/media/spi/rk1608_dphy.h @@ -1,5 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0 */ +struct rk1608_chinf { + u32 width; + u32 height; + u32 data_id; + u32 decode_format; + u32 flag; +}; + struct rk1608_dphy { struct v4l2_subdev sd; struct v4l2_subdev *rk1608_sd; @@ -15,10 +23,11 @@ struct rk1608_dphy { struct v4l2_ctrl *gain; struct v4l2_ctrl_handler ctrl_handler; u32 cam_nums; + u32 data_type; u32 in_mipi; u32 out_mipi; u32 mipi_lane; - u32 data_type; + u32 htotal; u32 vtotal; s64 link_freqs; @@ -26,4 +35,11 @@ struct rk1608_dphy { const char *module_facing; const char *module_name; const char *len_name; + + u32 i2c_bus; + u32 i2c_addr; + const char *sensor_name; + + struct rk1608_chinf in_ch[4]; + struct rk1608_chinf out_ch[4]; };