Skip to content

Commit f9d6f92

Browse files
potugasrkhuangtao
authored andcommitted
media: rockchip: vicap add CSI RGB888 format input support
Signed-off-by: Jianwei Fan <[email protected]> Change-Id: Iaaaf63a380e3c8de461f1c5a651a1f7efc313773
1 parent 653c8f5 commit f9d6f92

File tree

5 files changed

+79
-10
lines changed

5 files changed

+79
-10
lines changed

drivers/media/platform/rockchip/cif/capture.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static struct rkcif_sensor_info *sd_to_sensor(struct rkcif_device *dev,
595595
return NULL;
596596
}
597597

598-
static unsigned char get_data_type(u32 pixelformat, u8 cmd_mode_en)
598+
static unsigned char get_data_type(u32 pixelformat, u8 cmd_mode_en, u8 dsi_input)
599599
{
600600
switch (pixelformat) {
601601
/* csi raw8 */
@@ -622,12 +622,15 @@ static unsigned char get_data_type(u32 pixelformat, u8 cmd_mode_en)
622622
case MEDIA_BUS_FMT_YUYV8_2X8:
623623
case MEDIA_BUS_FMT_YVYU8_2X8:
624624
return 0x1e;
625-
case MEDIA_BUS_FMT_RGB888_1X24: {
626-
if (cmd_mode_en) /* dsi command mode*/
627-
return 0x39;
628-
else /* dsi video mode */
629-
return 0x3e;
630-
}
625+
case MEDIA_BUS_FMT_RGB888_1X24:
626+
if (dsi_input) {
627+
if (cmd_mode_en) /* dsi command mode*/
628+
return 0x39;
629+
else /* dsi video mode */
630+
return 0x3e;
631+
} else {
632+
return 0x24;
633+
}
631634
case MEDIA_BUS_FMT_EBD_1X8:
632635
return 0x12;
633636
case MEDIA_BUS_FMT_SPD_2X8:
@@ -2089,6 +2092,7 @@ static int rkcif_csi_channel_init(struct rkcif_stream *stream,
20892092
channel->fmt_val = stream->cif_fmt_out->csi_fmt_val;
20902093

20912094
channel->cmd_mode_en = 0; /* default use DSI Video Mode */
2095+
channel->dsi_input = dev->terminal_sensor.dsi_input_en;
20922096

20932097
if (stream->crop_enable) {
20942098
channel->crop_en = 1;
@@ -2157,10 +2161,12 @@ static int rkcif_csi_channel_init(struct rkcif_stream *stream,
21572161
channel->data_type = dev->channels[stream->id].data_type;
21582162
else
21592163
channel->data_type = get_data_type(stream->cif_fmt_in->mbus_code,
2160-
channel->cmd_mode_en);
2164+
channel->cmd_mode_en,
2165+
channel->dsi_input);
21612166
} else {
21622167
channel->data_type = get_data_type(stream->cif_fmt_in->mbus_code,
2163-
channel->cmd_mode_en);
2168+
channel->cmd_mode_en,
2169+
channel->dsi_input);
21642170
}
21652171
channel->csi_fmt_val = get_csi_fmt_val(stream->cif_fmt_in,
21662172
&dev->channels[stream->id]);
@@ -3808,6 +3814,13 @@ int rkcif_update_sensor_info(struct rkcif_stream *stream)
38083814
__func__, terminal_sensor->sd->name);
38093815
return ret;
38103816
}
3817+
if (v4l2_subdev_call(terminal_sensor->sd, core, ioctl, RKMODULE_GET_CSI_DSI_INFO,
3818+
&terminal_sensor->dsi_input_en)) {
3819+
v4l2_dbg(1, rkcif_debug, &stream->cifdev->v4l2_dev,
3820+
"%s: get terminal %s CSI/DSI sel failed, default csi input!\n",
3821+
__func__, terminal_sensor->sd->name);
3822+
terminal_sensor->dsi_input_en = 0;
3823+
}
38113824
} else {
38123825
v4l2_err(&stream->cifdev->v4l2_dev,
38133826
"%s: stream[%d] get remote terminal sensor failed!\n",

drivers/media/platform/rockchip/cif/dev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct rkcif_sensor_info {
220220
int lanes;
221221
struct v4l2_rect raw_rect;
222222
struct v4l2_subdev_selection selection;
223+
int dsi_input_en;
223224
};
224225

225226
enum cif_fmt_type {
@@ -283,6 +284,7 @@ struct csi_channel_info {
283284
unsigned int virtual_width;
284285
unsigned int crop_st_x;
285286
unsigned int crop_st_y;
287+
unsigned int dsi_input;
286288
struct rkmodule_lvds_cfg lvds_cfg;
287289
};
288290

drivers/media/platform/rockchip/cif/mipi-csi2.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/of_graph.h>
1616
#include <linux/platform_device.h>
1717
#include <linux/reset.h>
18+
#include <linux/rk-camera-module.h>
19+
#include <media/v4l2-ioctl.h>
1820
#include "mipi-csi2.h"
1921

2022
static int csi2_debug;
@@ -69,9 +71,41 @@ static struct v4l2_subdev *get_remote_sensor(struct v4l2_subdev *sd)
6971
return media_entity_to_v4l2_subdev(sensor_me);
7072
}
7173

74+
static void get_remote_terminal_sensor(struct v4l2_subdev *sd,
75+
struct v4l2_subdev **sensor_sd)
76+
{
77+
struct media_graph graph;
78+
struct media_entity *entity = &sd->entity;
79+
struct media_device *mdev = entity->graph_obj.mdev;
80+
int ret;
81+
82+
/* Walk the graph to locate sensor nodes. */
83+
mutex_lock(&mdev->graph_mutex);
84+
ret = media_graph_walk_init(&graph, mdev);
85+
if (ret) {
86+
mutex_unlock(&mdev->graph_mutex);
87+
*sensor_sd = NULL;
88+
return;
89+
}
90+
91+
media_graph_walk_start(&graph, entity);
92+
while ((entity = media_graph_walk_next(&graph))) {
93+
if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
94+
break;
95+
}
96+
mutex_unlock(&mdev->graph_mutex);
97+
media_graph_walk_cleanup(&graph);
98+
99+
if (entity)
100+
*sensor_sd = media_entity_to_v4l2_subdev(entity);
101+
else
102+
*sensor_sd = NULL;
103+
}
104+
72105
static void csi2_update_sensor_info(struct csi2_dev *csi2)
73106
{
74107
struct csi2_sensor *sensor = &csi2->sensors[0];
108+
struct v4l2_subdev *terminal_sensor_sd = NULL;
75109
struct v4l2_mbus_config mbus;
76110
int ret = 0;
77111

@@ -81,6 +115,14 @@ static void csi2_update_sensor_info(struct csi2_dev *csi2)
81115
return;
82116
}
83117

118+
get_remote_terminal_sensor(&csi2->sd, &terminal_sensor_sd);
119+
ret = v4l2_subdev_call(terminal_sensor_sd, core, ioctl,
120+
RKMODULE_GET_CSI_DSI_INFO, &csi2->dsi_input_en);
121+
if (ret) {
122+
v4l2_dbg(1, csi2_debug, &csi2->sd, "get CSI/DSI sel failed, default csi!\n");
123+
csi2->dsi_input_en = 0;
124+
}
125+
84126
csi2->bus.flags = mbus.flags;
85127
switch (csi2->bus.flags & V4L2_MBUS_CSI2_LANES) {
86128
case V4L2_MBUS_CSI2_1_LANE:
@@ -193,7 +235,7 @@ static int csi2_start(struct csi2_dev *csi2)
193235

194236
csi2_update_sensor_info(csi2);
195237

196-
if (csi2->format_mbus.code == MEDIA_BUS_FMT_RGB888_1X24)
238+
if (csi2->dsi_input_en == RKMODULE_DSI_INPUT)
197239
host_type = RK_DSI_RXHOST;
198240
else
199241
host_type = RK_CSI_RXHOST;

drivers/media/platform/rockchip/cif/mipi-csi2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct csi2_dev {
156156
int irq2;
157157
bool is_check_sot_sync;
158158
const char *dev_name;
159+
int dsi_input_en;
159160
};
160161

161162
u32 rkcif_csi2_get_sof(struct csi2_dev *csi2_dev);

include/uapi/linux/rk-camera-module.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
#define RKMODULE_GET_CSI_DPHY_PARAM \
157157
_IOWR('V', BASE_VIDIOC_PRIVATE + 32, struct rkmodule_csi_dphy_param)
158158

159+
#define RKMODULE_GET_CSI_DSI_INFO \
160+
_IOWR('V', BASE_VIDIOC_PRIVATE + 33, __u32)
161+
159162
struct rkmodule_i2cdev_info {
160163
u8 slave_addr;
161164
} __attribute__ ((packed));
@@ -419,6 +422,14 @@ enum hdr_esp_mode {
419422
HDR_ID_CODE,
420423
};
421424

425+
/*
426+
* CSI/DSI input select IOCTL
427+
*/
428+
enum rkmodule_csi_dsi_seq {
429+
RKMODULE_CSI_INPUT = 0,
430+
RKMODULE_DSI_INPUT,
431+
};
432+
422433
/**
423434
* lcnt: line counter
424435
* padnum: the pixels of padding row

0 commit comments

Comments
 (0)