| .. | .. |
|---|
| 15 | 15 | #include <linux/of_graph.h> |
|---|
| 16 | 16 | #include <linux/platform_device.h> |
|---|
| 17 | 17 | #include <linux/reset.h> |
|---|
| 18 | | -#include <media/v4l2-device.h> |
|---|
| 19 | | -#include <media/v4l2-fwnode.h> |
|---|
| 20 | | -#include <media/v4l2-subdev.h> |
|---|
| 21 | | -#include <media/v4l2-event.h> |
|---|
| 22 | 18 | #include <linux/rk-camera-module.h> |
|---|
| 23 | 19 | #include <media/v4l2-ioctl.h> |
|---|
| 24 | 20 | #include "mipi-csi2.h" |
|---|
| 21 | +#include <linux/rkcif-config.h> |
|---|
| 22 | +#include <linux/regulator/consumer.h> |
|---|
| 25 | 23 | |
|---|
| 26 | 24 | static int csi2_debug; |
|---|
| 27 | 25 | module_param_named(debug_csi2, csi2_debug, int, 0644); |
|---|
| 28 | 26 | MODULE_PARM_DESC(debug_csi2, "Debug level (0-1)"); |
|---|
| 29 | 27 | |
|---|
| 30 | | -/* |
|---|
| 31 | | - * there must be 5 pads: 1 input pad from sensor, and |
|---|
| 32 | | - * the 4 virtual channel output pads |
|---|
| 33 | | - */ |
|---|
| 34 | | -#define CSI2_SINK_PAD 0 |
|---|
| 35 | | -#define CSI2_NUM_SINK_PADS 1 |
|---|
| 36 | | -#define CSI2_NUM_SRC_PADS 4 |
|---|
| 37 | | -#define CSI2_NUM_PADS 5 |
|---|
| 38 | | -#define CSI2_NUM_PADS_SINGLE_LINK 2 |
|---|
| 39 | | -#define MAX_CSI2_SENSORS 2 |
|---|
| 40 | | - |
|---|
| 41 | | -#define RKCIF_DEFAULT_WIDTH 640 |
|---|
| 42 | | -#define RKCIF_DEFAULT_HEIGHT 480 |
|---|
| 43 | | - |
|---|
| 44 | | -/* |
|---|
| 45 | | - * The default maximum bit-rate per lane in Mbps, if the |
|---|
| 46 | | - * source subdev does not provide V4L2_CID_LINK_FREQ. |
|---|
| 47 | | - */ |
|---|
| 48 | | -#define CSI2_DEFAULT_MAX_MBPS 849 |
|---|
| 49 | | - |
|---|
| 50 | | -#define IMX_MEDIA_GRP_ID_CSI2 BIT(8) |
|---|
| 51 | | -#define CSIHOST_MAX_ERRINT_COUNT 10 |
|---|
| 52 | | - |
|---|
| 53 | | -/* |
|---|
| 54 | | - * add new chip id in tail in time order |
|---|
| 55 | | - * by increasing to distinguish csi2 host version |
|---|
| 56 | | - */ |
|---|
| 57 | | -enum rkcsi2_chip_id { |
|---|
| 58 | | - CHIP_PX30_CSI2, |
|---|
| 59 | | - CHIP_RK1808_CSI2, |
|---|
| 60 | | - CHIP_RK3128_CSI2, |
|---|
| 61 | | - CHIP_RK3288_CSI2, |
|---|
| 62 | | - CHIP_RV1126_CSI2, |
|---|
| 63 | | - CHIP_RK3568_CSI2, |
|---|
| 64 | | -}; |
|---|
| 65 | | - |
|---|
| 66 | | -enum csi2_pads { |
|---|
| 67 | | - RK_CSI2_PAD_SINK = 0, |
|---|
| 68 | | - RK_CSI2X_PAD_SOURCE0, |
|---|
| 69 | | - RK_CSI2X_PAD_SOURCE1, |
|---|
| 70 | | - RK_CSI2X_PAD_SOURCE2, |
|---|
| 71 | | - RK_CSI2X_PAD_SOURCE3 |
|---|
| 72 | | -}; |
|---|
| 73 | | - |
|---|
| 74 | | -enum csi2_err { |
|---|
| 75 | | - RK_CSI2_ERR_SOTSYN = 0x0, |
|---|
| 76 | | - RK_CSI2_ERR_FS_FE_MIS, |
|---|
| 77 | | - RK_CSI2_ERR_FRM_SEQ_ERR, |
|---|
| 78 | | - RK_CSI2_ERR_CRC_ONCE, |
|---|
| 79 | | - RK_CSI2_ERR_CRC, |
|---|
| 80 | | - RK_CSI2_ERR_ALL, |
|---|
| 81 | | - RK_CSI2_ERR_MAX |
|---|
| 82 | | -}; |
|---|
| 83 | | - |
|---|
| 84 | | -enum host_type_t { |
|---|
| 85 | | - RK_CSI_RXHOST, |
|---|
| 86 | | - RK_DSI_RXHOST |
|---|
| 87 | | -}; |
|---|
| 88 | | - |
|---|
| 89 | | -struct csi2_match_data { |
|---|
| 90 | | - int chip_id; |
|---|
| 91 | | - int num_pads; |
|---|
| 92 | | -}; |
|---|
| 93 | | - |
|---|
| 94 | | -struct csi2_sensor { |
|---|
| 95 | | - struct v4l2_subdev *sd; |
|---|
| 96 | | - struct v4l2_mbus_config mbus; |
|---|
| 97 | | - int lanes; |
|---|
| 98 | | -}; |
|---|
| 99 | | - |
|---|
| 100 | | -struct csi2_err_stats { |
|---|
| 101 | | - unsigned int cnt; |
|---|
| 102 | | -}; |
|---|
| 103 | | - |
|---|
| 104 | | -struct csi2_dev { |
|---|
| 105 | | - struct device *dev; |
|---|
| 106 | | - struct v4l2_subdev sd; |
|---|
| 107 | | - struct media_pad pad[CSI2_NUM_PADS]; |
|---|
| 108 | | - struct clk_bulk_data *clks_bulk; |
|---|
| 109 | | - int clks_num; |
|---|
| 110 | | - struct reset_control *rsts_bulk; |
|---|
| 111 | | - |
|---|
| 112 | | - void __iomem *base; |
|---|
| 113 | | - struct v4l2_async_notifier notifier; |
|---|
| 114 | | - struct v4l2_fwnode_bus_mipi_csi2 bus; |
|---|
| 115 | | - |
|---|
| 116 | | - /* lock to protect all members below */ |
|---|
| 117 | | - struct mutex lock; |
|---|
| 118 | | - |
|---|
| 119 | | - struct v4l2_mbus_framefmt format_mbus; |
|---|
| 120 | | - struct v4l2_rect crop; |
|---|
| 121 | | - int stream_count; |
|---|
| 122 | | - struct v4l2_subdev *src_sd; |
|---|
| 123 | | - bool sink_linked[CSI2_NUM_SRC_PADS]; |
|---|
| 124 | | - struct csi2_sensor sensors[MAX_CSI2_SENSORS]; |
|---|
| 125 | | - const struct csi2_match_data *match_data; |
|---|
| 126 | | - int num_sensors; |
|---|
| 127 | | - atomic_t frm_sync_seq; |
|---|
| 128 | | - struct csi2_err_stats err_list[RK_CSI2_ERR_MAX]; |
|---|
| 129 | | - int dsi_input_en; |
|---|
| 130 | | -}; |
|---|
| 131 | | - |
|---|
| 132 | | -#define DEVICE_NAME "rockchip-mipi-csi2" |
|---|
| 133 | | - |
|---|
| 134 | | -/* CSI Host Registers Define */ |
|---|
| 135 | | -#define CSIHOST_N_LANES 0x04 |
|---|
| 136 | | -#define CSIHOST_DPHY_SHUTDOWNZ 0x08 |
|---|
| 137 | | -#define CSIHOST_PHY_RSTZ 0x0c |
|---|
| 138 | | -#define CSIHOST_RESETN 0x10 |
|---|
| 139 | | -#define CSIHOST_PHY_STATE 0x14 |
|---|
| 140 | | -#define CSIHOST_ERR1 0x20 |
|---|
| 141 | | -#define CSIHOST_ERR2 0x24 |
|---|
| 142 | | -#define CSIHOST_MSK1 0x28 |
|---|
| 143 | | -#define CSIHOST_MSK2 0x2c |
|---|
| 144 | | -#define CSIHOST_CONTROL 0x40 |
|---|
| 145 | | - |
|---|
| 146 | | -#define CSIHOST_ERR1_PHYERR_SPTSYNCHS 0x0000000f |
|---|
| 147 | | -#define CSIHOST_ERR1_ERR_BNDRY_MATCH 0x000000f0 |
|---|
| 148 | | -#define CSIHOST_ERR1_ERR_SEQ 0x00000f00 |
|---|
| 149 | | -#define CSIHOST_ERR1_ERR_FRM_DATA 0x0000f000 |
|---|
| 150 | | -#define CSIHOST_ERR1_ERR_CRC 0x1f000000 |
|---|
| 151 | | - |
|---|
| 152 | | -#define CSIHOST_ERR2_PHYERR_ESC 0x0000000f |
|---|
| 153 | | -#define CSIHOST_ERR2_PHYERR_SOTHS 0x000000f0 |
|---|
| 154 | | -#define CSIHOST_ERR2_ECC_CORRECTED 0x00000f00 |
|---|
| 155 | | -#define CSIHOST_ERR2_ERR_ID 0x0000f000 |
|---|
| 156 | | -#define CSIHOST_ERR2_PHYERR_CODEHS 0x01000000 |
|---|
| 157 | | - |
|---|
| 158 | | -#define SW_CPHY_EN(x) ((x) << 0) |
|---|
| 159 | | -#define SW_DSI_EN(x) ((x) << 4) |
|---|
| 160 | | -#define SW_DATATYPE_FS(x) ((x) << 8) |
|---|
| 161 | | -#define SW_DATATYPE_FE(x) ((x) << 14) |
|---|
| 162 | | -#define SW_DATATYPE_LS(x) ((x) << 20) |
|---|
| 163 | | -#define SW_DATATYPE_LE(x) ((x) << 26) |
|---|
| 164 | | - |
|---|
| 165 | 28 | #define write_csihost_reg(base, addr, val) writel(val, (addr) + (base)) |
|---|
| 166 | 29 | #define read_csihost_reg(base, addr) readl((addr) + (base)) |
|---|
| 167 | 30 | |
|---|
| 168 | | -static struct csi2_dev *g_csi2_dev; |
|---|
| 169 | 31 | static ATOMIC_NOTIFIER_HEAD(g_csi_host_chain); |
|---|
| 170 | 32 | |
|---|
| 171 | 33 | int rkcif_csi2_register_notifier(struct notifier_block *nb) |
|---|
| .. | .. |
|---|
| 183 | 45 | return container_of(sdev, struct csi2_dev, sd); |
|---|
| 184 | 46 | } |
|---|
| 185 | 47 | |
|---|
| 186 | | -static struct csi2_sensor *sd_to_sensor(struct csi2_dev *csi2, |
|---|
| 48 | +static struct csi2_sensor_info *sd_to_sensor(struct csi2_dev *csi2, |
|---|
| 187 | 49 | struct v4l2_subdev *sd) |
|---|
| 188 | 50 | { |
|---|
| 189 | 51 | int i; |
|---|
| .. | .. |
|---|
| 227 | 89 | *sensor_sd = NULL; |
|---|
| 228 | 90 | return; |
|---|
| 229 | 91 | } |
|---|
| 92 | + |
|---|
| 230 | 93 | media_graph_walk_start(&graph, entity); |
|---|
| 231 | 94 | while ((entity = media_graph_walk_next(&graph))) { |
|---|
| 232 | 95 | if (entity->function == MEDIA_ENT_F_CAM_SENSOR) |
|---|
| .. | .. |
|---|
| 234 | 97 | } |
|---|
| 235 | 98 | mutex_unlock(&mdev->graph_mutex); |
|---|
| 236 | 99 | media_graph_walk_cleanup(&graph); |
|---|
| 100 | + |
|---|
| 237 | 101 | if (entity) |
|---|
| 238 | 102 | *sensor_sd = media_entity_to_v4l2_subdev(entity); |
|---|
| 239 | 103 | else |
|---|
| .. | .. |
|---|
| 242 | 106 | |
|---|
| 243 | 107 | static void csi2_update_sensor_info(struct csi2_dev *csi2) |
|---|
| 244 | 108 | { |
|---|
| 245 | | - struct csi2_sensor *sensor = &csi2->sensors[0]; |
|---|
| 246 | 109 | struct v4l2_subdev *terminal_sensor_sd = NULL; |
|---|
| 110 | + struct csi2_sensor_info *sensor = &csi2->sensors[0]; |
|---|
| 247 | 111 | struct v4l2_mbus_config mbus; |
|---|
| 248 | 112 | int ret = 0; |
|---|
| 249 | 113 | |
|---|
| 250 | | - ret = v4l2_subdev_call(sensor->sd, video, g_mbus_config, &mbus); |
|---|
| 114 | + ret = v4l2_subdev_call(sensor->sd, pad, get_mbus_config, 0, &mbus); |
|---|
| 251 | 115 | if (ret) { |
|---|
| 252 | 116 | v4l2_err(&csi2->sd, "update sensor info failed!\n"); |
|---|
| 253 | 117 | return; |
|---|
| 254 | 118 | } |
|---|
| 255 | 119 | |
|---|
| 256 | 120 | get_remote_terminal_sensor(&csi2->sd, &terminal_sensor_sd); |
|---|
| 257 | | - if (terminal_sensor_sd) { |
|---|
| 258 | | - ret = v4l2_subdev_call(terminal_sensor_sd, core, ioctl, |
|---|
| 259 | | - RKMODULE_GET_CSI_DSI_INFO, &csi2->dsi_input_en); |
|---|
| 260 | | - if (ret) |
|---|
| 261 | | - csi2->dsi_input_en = 0; |
|---|
| 121 | + ret = v4l2_subdev_call(terminal_sensor_sd, core, ioctl, |
|---|
| 122 | + RKMODULE_GET_CSI_DSI_INFO, &csi2->dsi_input_en); |
|---|
| 123 | + if (ret) { |
|---|
| 124 | + v4l2_dbg(1, csi2_debug, &csi2->sd, "get CSI/DSI sel failed, default csi!\n"); |
|---|
| 125 | + csi2->dsi_input_en = 0; |
|---|
| 262 | 126 | } |
|---|
| 127 | + |
|---|
| 263 | 128 | csi2->bus.flags = mbus.flags; |
|---|
| 264 | 129 | switch (csi2->bus.flags & V4L2_MBUS_CSI2_LANES) { |
|---|
| 265 | 130 | case V4L2_MBUS_CSI2_1_LANE: |
|---|
| .. | .. |
|---|
| 316 | 181 | write_csihost_reg(base, CSIHOST_MSK2, 0xffffffff); |
|---|
| 317 | 182 | } |
|---|
| 318 | 183 | |
|---|
| 184 | +static int csi2_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id, |
|---|
| 185 | + struct v4l2_mbus_config *mbus); |
|---|
| 186 | + |
|---|
| 319 | 187 | static void csi2_enable(struct csi2_dev *csi2, |
|---|
| 320 | 188 | enum host_type_t host_type) |
|---|
| 321 | 189 | { |
|---|
| 322 | 190 | void __iomem *base = csi2->base; |
|---|
| 323 | 191 | int lanes = csi2->bus.num_data_lanes; |
|---|
| 192 | + struct v4l2_mbus_config mbus; |
|---|
| 193 | + u32 val = 0; |
|---|
| 194 | + |
|---|
| 195 | + csi2_g_mbus_config(&csi2->sd, 0, &mbus); |
|---|
| 196 | + if (mbus.type == V4L2_MBUS_CSI2_DPHY) |
|---|
| 197 | + val = SW_CPHY_EN(0); |
|---|
| 198 | + else if (mbus.type == V4L2_MBUS_CSI2_CPHY) |
|---|
| 199 | + val = SW_CPHY_EN(1); |
|---|
| 324 | 200 | |
|---|
| 325 | 201 | write_csihost_reg(base, CSIHOST_N_LANES, lanes - 1); |
|---|
| 326 | 202 | |
|---|
| 327 | 203 | if (host_type == RK_DSI_RXHOST) { |
|---|
| 328 | | - write_csihost_reg(base, CSIHOST_CONTROL, |
|---|
| 329 | | - SW_CPHY_EN(0) | SW_DSI_EN(1) | |
|---|
| 330 | | - SW_DATATYPE_FS(0x01) | SW_DATATYPE_FE(0x11) | |
|---|
| 331 | | - SW_DATATYPE_LS(0x21) | SW_DATATYPE_LE(0x31)); |
|---|
| 204 | + val |= SW_DSI_EN(1) | SW_DATATYPE_FS(0x01) | |
|---|
| 205 | + SW_DATATYPE_FE(0x11) | SW_DATATYPE_LS(0x21) | |
|---|
| 206 | + SW_DATATYPE_LE(0x31); |
|---|
| 207 | + write_csihost_reg(base, CSIHOST_CONTROL, val); |
|---|
| 332 | 208 | /* Disable some error interrupt when HOST work on DSI RX mode */ |
|---|
| 333 | 209 | write_csihost_reg(base, CSIHOST_MSK1, 0xe00000f0); |
|---|
| 334 | 210 | write_csihost_reg(base, CSIHOST_MSK2, 0xff00); |
|---|
| 335 | 211 | } else { |
|---|
| 336 | | - write_csihost_reg(base, CSIHOST_CONTROL, |
|---|
| 337 | | - SW_CPHY_EN(0) | SW_DSI_EN(0)); |
|---|
| 338 | | - write_csihost_reg(base, CSIHOST_MSK1, 0); |
|---|
| 212 | + val |= SW_DSI_EN(0) | SW_DATATYPE_FS(0x0) | |
|---|
| 213 | + SW_DATATYPE_FE(0x01) | SW_DATATYPE_LS(0x02) | |
|---|
| 214 | + SW_DATATYPE_LE(0x03); |
|---|
| 215 | + write_csihost_reg(base, CSIHOST_CONTROL, val); |
|---|
| 216 | + write_csihost_reg(base, CSIHOST_MSK1, 0x0); |
|---|
| 339 | 217 | write_csihost_reg(base, CSIHOST_MSK2, 0xf000); |
|---|
| 218 | + csi2->is_check_sot_sync = true; |
|---|
| 340 | 219 | } |
|---|
| 341 | 220 | |
|---|
| 342 | 221 | write_csihost_reg(base, CSIHOST_RESETN, 1); |
|---|
| .. | .. |
|---|
| 500 | 379 | csi2->crop.left = 0; |
|---|
| 501 | 380 | csi2->crop.width = RKCIF_DEFAULT_WIDTH; |
|---|
| 502 | 381 | csi2->crop.height = RKCIF_DEFAULT_HEIGHT; |
|---|
| 382 | + csi2->csi_idx = 0; |
|---|
| 503 | 383 | |
|---|
| 504 | 384 | return media_entity_pads_init(&sd->entity, num_pads, csi2->pad); |
|---|
| 505 | 385 | } |
|---|
| .. | .. |
|---|
| 556 | 436 | switch (sel->target) { |
|---|
| 557 | 437 | case V4L2_SEL_TGT_CROP_BOUNDS: |
|---|
| 558 | 438 | if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) { |
|---|
| 439 | + sel->pad = 0; |
|---|
| 559 | 440 | ret = v4l2_subdev_call(sensor, pad, get_selection, |
|---|
| 560 | 441 | cfg, sel); |
|---|
| 561 | 442 | if (ret) { |
|---|
| 562 | 443 | fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; |
|---|
| 444 | + fmt.pad = 0; |
|---|
| 563 | 445 | ret = v4l2_subdev_call(sensor, pad, get_fmt, NULL, &fmt); |
|---|
| 564 | 446 | if (!ret) { |
|---|
| 565 | 447 | csi2->format_mbus = fmt.format; |
|---|
| .. | .. |
|---|
| 608 | 490 | return ret; |
|---|
| 609 | 491 | } |
|---|
| 610 | 492 | |
|---|
| 611 | | -static int csi2_g_mbus_config(struct v4l2_subdev *sd, |
|---|
| 493 | +static int csi2_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id, |
|---|
| 612 | 494 | struct v4l2_mbus_config *mbus) |
|---|
| 613 | 495 | { |
|---|
| 614 | 496 | struct csi2_dev *csi2 = sd_to_dev(sd); |
|---|
| 615 | 497 | struct v4l2_subdev *sensor_sd = get_remote_sensor(sd); |
|---|
| 616 | 498 | int ret; |
|---|
| 617 | 499 | |
|---|
| 618 | | - ret = v4l2_subdev_call(sensor_sd, video, g_mbus_config, mbus); |
|---|
| 500 | + ret = v4l2_subdev_call(sensor_sd, pad, get_mbus_config, 0, mbus); |
|---|
| 619 | 501 | if (ret) { |
|---|
| 620 | | - mbus->type = V4L2_MBUS_CSI2; |
|---|
| 502 | + mbus->type = V4L2_MBUS_CSI2_DPHY; |
|---|
| 621 | 503 | mbus->flags = csi2->bus.flags; |
|---|
| 622 | 504 | mbus->flags |= BIT(csi2->bus.num_data_lanes - 1); |
|---|
| 623 | 505 | } |
|---|
| .. | .. |
|---|
| 630 | 512 | .link_validate = v4l2_subdev_link_validate, |
|---|
| 631 | 513 | }; |
|---|
| 632 | 514 | |
|---|
| 633 | | -void rkcif_csi2_event_inc_sof(void) |
|---|
| 515 | +void rkcif_csi2_event_reset_pipe(struct csi2_dev *csi2_dev, int reset_src) |
|---|
| 634 | 516 | { |
|---|
| 635 | | - if (g_csi2_dev) { |
|---|
| 517 | + if (csi2_dev) { |
|---|
| 636 | 518 | struct v4l2_event event = { |
|---|
| 637 | | - .type = V4L2_EVENT_FRAME_SYNC, |
|---|
| 638 | | - .u.frame_sync.frame_sequence = |
|---|
| 639 | | - atomic_inc_return(&g_csi2_dev->frm_sync_seq) - 1, |
|---|
| 519 | + .type = V4L2_EVENT_RESET_DEV, |
|---|
| 520 | + .reserved[0] = reset_src, |
|---|
| 640 | 521 | }; |
|---|
| 641 | | - v4l2_event_queue(g_csi2_dev->sd.devnode, &event); |
|---|
| 522 | + v4l2_event_queue(csi2_dev->sd.devnode, &event); |
|---|
| 642 | 523 | } |
|---|
| 643 | 524 | } |
|---|
| 644 | 525 | |
|---|
| 645 | | -u32 rkcif_csi2_get_sof(void) |
|---|
| 526 | +void rkcif_csi2_event_inc_sof(struct csi2_dev *csi2_dev) |
|---|
| 646 | 527 | { |
|---|
| 647 | | - if (g_csi2_dev) { |
|---|
| 648 | | - return atomic_read(&g_csi2_dev->frm_sync_seq) - 1; |
|---|
| 528 | + if (csi2_dev) { |
|---|
| 529 | + struct v4l2_event event = { |
|---|
| 530 | + .type = V4L2_EVENT_FRAME_SYNC, |
|---|
| 531 | + .u.frame_sync.frame_sequence = |
|---|
| 532 | + atomic_inc_return(&csi2_dev->frm_sync_seq) - 1, |
|---|
| 533 | + }; |
|---|
| 534 | + v4l2_event_queue(csi2_dev->sd.devnode, &event); |
|---|
| 649 | 535 | } |
|---|
| 536 | +} |
|---|
| 537 | + |
|---|
| 538 | +u32 rkcif_csi2_get_sof(struct csi2_dev *csi2_dev) |
|---|
| 539 | +{ |
|---|
| 540 | + if (csi2_dev) |
|---|
| 541 | + return atomic_read(&csi2_dev->frm_sync_seq) - 1; |
|---|
| 650 | 542 | |
|---|
| 651 | 543 | return 0; |
|---|
| 652 | 544 | } |
|---|
| 653 | 545 | |
|---|
| 654 | | -void rkcif_csi2_set_sof(u32 seq) |
|---|
| 546 | +void rkcif_csi2_set_sof(struct csi2_dev *csi2_dev, u32 seq) |
|---|
| 655 | 547 | { |
|---|
| 656 | | - if (g_csi2_dev) { |
|---|
| 657 | | - atomic_set(&g_csi2_dev->frm_sync_seq, seq); |
|---|
| 658 | | - } |
|---|
| 548 | + if (csi2_dev) |
|---|
| 549 | + atomic_set(&csi2_dev->frm_sync_seq, seq); |
|---|
| 659 | 550 | } |
|---|
| 660 | 551 | |
|---|
| 661 | 552 | static int rkcif_csi2_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, |
|---|
| 662 | 553 | struct v4l2_event_subscription *sub) |
|---|
| 663 | 554 | { |
|---|
| 664 | | - if (sub->type != V4L2_EVENT_FRAME_SYNC) |
|---|
| 555 | + if (sub->type == V4L2_EVENT_FRAME_SYNC || |
|---|
| 556 | + sub->type == V4L2_EVENT_RESET_DEV) |
|---|
| 557 | + return v4l2_event_subscribe(fh, sub, RKCIF_V4L2_EVENT_ELEMS, NULL); |
|---|
| 558 | + else |
|---|
| 665 | 559 | return -EINVAL; |
|---|
| 666 | | - |
|---|
| 667 | | - return v4l2_event_subscribe(fh, sub, 0, NULL); |
|---|
| 668 | 560 | } |
|---|
| 561 | + |
|---|
| 562 | +static int rkcif_csi2_s_power(struct v4l2_subdev *sd, int on) |
|---|
| 563 | +{ |
|---|
| 564 | + return 0; |
|---|
| 565 | +} |
|---|
| 566 | + |
|---|
| 567 | +static long rkcif_csi2_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) |
|---|
| 568 | +{ |
|---|
| 569 | + struct csi2_dev *csi2 = sd_to_dev(sd); |
|---|
| 570 | + long ret = 0; |
|---|
| 571 | + |
|---|
| 572 | + switch (cmd) { |
|---|
| 573 | + case RKCIF_CMD_SET_CSI_IDX: |
|---|
| 574 | + csi2->csi_idx = *((u32 *)arg); |
|---|
| 575 | + break; |
|---|
| 576 | + default: |
|---|
| 577 | + ret = -ENOIOCTLCMD; |
|---|
| 578 | + break; |
|---|
| 579 | + } |
|---|
| 580 | + |
|---|
| 581 | + return ret; |
|---|
| 582 | +} |
|---|
| 583 | + |
|---|
| 584 | +#ifdef CONFIG_COMPAT |
|---|
| 585 | +static long rkcif_csi2_compat_ioctl32(struct v4l2_subdev *sd, |
|---|
| 586 | + unsigned int cmd, unsigned long arg) |
|---|
| 587 | +{ |
|---|
| 588 | + void __user *up = compat_ptr(arg); |
|---|
| 589 | + u32 csi_idx = 0; |
|---|
| 590 | + long ret; |
|---|
| 591 | + |
|---|
| 592 | + switch (cmd) { |
|---|
| 593 | + case RKCIF_CMD_SET_CSI_IDX: |
|---|
| 594 | + if (copy_from_user(&csi_idx, up, sizeof(u32))) |
|---|
| 595 | + return -EFAULT; |
|---|
| 596 | + |
|---|
| 597 | + ret = rkcif_csi2_ioctl(sd, cmd, &csi_idx); |
|---|
| 598 | + break; |
|---|
| 599 | + default: |
|---|
| 600 | + ret = -ENOIOCTLCMD; |
|---|
| 601 | + break; |
|---|
| 602 | + } |
|---|
| 603 | + |
|---|
| 604 | + return ret; |
|---|
| 605 | +} |
|---|
| 606 | +#endif |
|---|
| 669 | 607 | |
|---|
| 670 | 608 | static const struct v4l2_subdev_core_ops csi2_core_ops = { |
|---|
| 671 | 609 | .subscribe_event = rkcif_csi2_subscribe_event, |
|---|
| 672 | 610 | .unsubscribe_event = v4l2_event_subdev_unsubscribe, |
|---|
| 611 | + .s_power = rkcif_csi2_s_power, |
|---|
| 612 | + .ioctl = rkcif_csi2_ioctl, |
|---|
| 613 | +#ifdef CONFIG_COMPAT |
|---|
| 614 | + .compat_ioctl32 = rkcif_csi2_compat_ioctl32, |
|---|
| 615 | +#endif |
|---|
| 673 | 616 | }; |
|---|
| 674 | 617 | |
|---|
| 675 | 618 | static const struct v4l2_subdev_video_ops csi2_video_ops = { |
|---|
| 676 | | - .g_mbus_config = csi2_g_mbus_config, |
|---|
| 677 | 619 | .s_stream = csi2_s_stream, |
|---|
| 678 | 620 | }; |
|---|
| 679 | 621 | |
|---|
| .. | .. |
|---|
| 682 | 624 | .set_fmt = csi2_get_set_fmt, |
|---|
| 683 | 625 | .get_selection = csi2_get_selection, |
|---|
| 684 | 626 | .set_selection = csi2_set_selection, |
|---|
| 627 | + .get_mbus_config = csi2_g_mbus_config, |
|---|
| 685 | 628 | }; |
|---|
| 686 | 629 | |
|---|
| 687 | 630 | static const struct v4l2_subdev_ops csi2_subdev_ops = { |
|---|
| .. | .. |
|---|
| 716 | 659 | struct csi2_dev *csi2 = container_of(notifier, |
|---|
| 717 | 660 | struct csi2_dev, |
|---|
| 718 | 661 | notifier); |
|---|
| 719 | | - struct csi2_sensor *sensor; |
|---|
| 662 | + struct csi2_sensor_info *sensor; |
|---|
| 720 | 663 | struct media_link *link; |
|---|
| 721 | 664 | unsigned int pad, ret; |
|---|
| 722 | 665 | |
|---|
| .. | .. |
|---|
| 772 | 715 | struct csi2_dev *csi2 = container_of(notifier, |
|---|
| 773 | 716 | struct csi2_dev, |
|---|
| 774 | 717 | notifier); |
|---|
| 775 | | - struct csi2_sensor *sensor = sd_to_sensor(csi2, sd); |
|---|
| 718 | + struct csi2_sensor_info *sensor = sd_to_sensor(csi2, sd); |
|---|
| 776 | 719 | |
|---|
| 777 | | - sensor->sd = NULL; |
|---|
| 778 | | - |
|---|
| 720 | + if (sensor) |
|---|
| 721 | + sensor->sd = NULL; |
|---|
| 779 | 722 | } |
|---|
| 780 | 723 | |
|---|
| 781 | 724 | static const struct |
|---|
| .. | .. |
|---|
| 784 | 727 | .unbind = csi2_notifier_unbind, |
|---|
| 785 | 728 | }; |
|---|
| 786 | 729 | |
|---|
| 730 | +static void csi2_find_err_vc(int val, char *vc_info) |
|---|
| 731 | +{ |
|---|
| 732 | + int i; |
|---|
| 733 | + char cur_str[CSI_VCINFO_LEN] = {0}; |
|---|
| 734 | + |
|---|
| 735 | + memset(vc_info, 0, sizeof(*vc_info)); |
|---|
| 736 | + for (i = 0; i < 4; i++) { |
|---|
| 737 | + if ((val >> i) & 0x1) { |
|---|
| 738 | + snprintf(cur_str, CSI_VCINFO_LEN, " %d", i); |
|---|
| 739 | + if (strlen(vc_info) + strlen(cur_str) < CSI_VCINFO_LEN) |
|---|
| 740 | + strncat(vc_info, cur_str, strlen(cur_str)); |
|---|
| 741 | + } |
|---|
| 742 | + } |
|---|
| 743 | +} |
|---|
| 744 | + |
|---|
| 745 | +#define csi2_err_strncat(dst_str, src_str) {\ |
|---|
| 746 | + if (strlen(dst_str) + strlen(src_str) < CSI_ERRSTR_LEN)\ |
|---|
| 747 | + strncat(dst_str, src_str, strlen(src_str)); } |
|---|
| 748 | + |
|---|
| 787 | 749 | static irqreturn_t rk_csirx_irq1_handler(int irq, void *ctx) |
|---|
| 788 | 750 | { |
|---|
| 789 | 751 | struct device *dev = ctx; |
|---|
| .. | .. |
|---|
| 791 | 753 | struct csi2_err_stats *err_list = NULL; |
|---|
| 792 | 754 | unsigned long err_stat = 0; |
|---|
| 793 | 755 | u32 val; |
|---|
| 756 | + char err_str[CSI_ERRSTR_LEN] = {0}; |
|---|
| 757 | + char cur_str[CSI_ERRSTR_LEN] = {0}; |
|---|
| 758 | + char vc_info[CSI_VCINFO_LEN] = {0}; |
|---|
| 759 | + bool is_add_cnt = false; |
|---|
| 794 | 760 | |
|---|
| 795 | 761 | val = read_csihost_reg(csi2->base, CSIHOST_ERR1); |
|---|
| 796 | 762 | if (val) { |
|---|
| 797 | | - write_csihost_reg(csi2->base, |
|---|
| 798 | | - CSIHOST_ERR1, 0x0); |
|---|
| 799 | | - |
|---|
| 800 | 763 | if (val & CSIHOST_ERR1_PHYERR_SPTSYNCHS) { |
|---|
| 801 | 764 | err_list = &csi2->err_list[RK_CSI2_ERR_SOTSYN]; |
|---|
| 802 | 765 | err_list->cnt++; |
|---|
| 803 | | - v4l2_err(&csi2->sd, |
|---|
| 804 | | - "ERR1: start of transmission error(no synchronization achieved), reg: 0x%x,cnt:%d\n", |
|---|
| 805 | | - val, err_list->cnt); |
|---|
| 766 | + if (csi2->match_data->chip_id == CHIP_RK3588_CSI2) { |
|---|
| 767 | + if (err_list->cnt > 3 && |
|---|
| 768 | + csi2->err_list[RK_CSI2_ERR_ALL].cnt <= err_list->cnt) { |
|---|
| 769 | + csi2->is_check_sot_sync = false; |
|---|
| 770 | + write_csihost_reg(csi2->base, CSIHOST_MSK1, 0xf); |
|---|
| 771 | + } |
|---|
| 772 | + if (csi2->is_check_sot_sync) { |
|---|
| 773 | + csi2_find_err_vc(val & 0xf, vc_info); |
|---|
| 774 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(sot sync,lane:%s) ", vc_info); |
|---|
| 775 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 776 | + } |
|---|
| 777 | + } else { |
|---|
| 778 | + csi2_find_err_vc(val & 0xf, vc_info); |
|---|
| 779 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(sot sync,lane:%s) ", vc_info); |
|---|
| 780 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 781 | + is_add_cnt = true; |
|---|
| 782 | + } |
|---|
| 806 | 783 | } |
|---|
| 807 | 784 | |
|---|
| 808 | 785 | if (val & CSIHOST_ERR1_ERR_BNDRY_MATCH) { |
|---|
| 809 | 786 | err_list = &csi2->err_list[RK_CSI2_ERR_FS_FE_MIS]; |
|---|
| 810 | 787 | err_list->cnt++; |
|---|
| 811 | | - v4l2_err(&csi2->sd, |
|---|
| 812 | | - "ERR1: error matching frame start with frame end, reg: 0x%x,cnt:%d\n", |
|---|
| 813 | | - val, err_list->cnt); |
|---|
| 788 | + csi2_find_err_vc((val >> 4) & 0xf, vc_info); |
|---|
| 789 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(fs/fe mis,vc:%s) ", vc_info); |
|---|
| 790 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 791 | + if (csi2->match_data->chip_id < CHIP_RK3588_CSI2) |
|---|
| 792 | + is_add_cnt = true; |
|---|
| 814 | 793 | } |
|---|
| 815 | 794 | |
|---|
| 816 | 795 | if (val & CSIHOST_ERR1_ERR_SEQ) { |
|---|
| 817 | 796 | err_list = &csi2->err_list[RK_CSI2_ERR_FRM_SEQ_ERR]; |
|---|
| 818 | 797 | err_list->cnt++; |
|---|
| 819 | | - v4l2_err(&csi2->sd, |
|---|
| 820 | | - "ERR1: incorrect frame sequence detected, reg: 0x%x,cnt:%d\n", |
|---|
| 821 | | - val, err_list->cnt); |
|---|
| 798 | + csi2_find_err_vc((val >> 8) & 0xf, vc_info); |
|---|
| 799 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(f_seq,vc:%s) ", vc_info); |
|---|
| 800 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 822 | 801 | } |
|---|
| 823 | 802 | |
|---|
| 824 | 803 | if (val & CSIHOST_ERR1_ERR_FRM_DATA) { |
|---|
| 825 | 804 | err_list = &csi2->err_list[RK_CSI2_ERR_CRC_ONCE]; |
|---|
| 805 | + is_add_cnt = true; |
|---|
| 826 | 806 | err_list->cnt++; |
|---|
| 827 | | - v4l2_dbg(1, csi2_debug, &csi2->sd, |
|---|
| 828 | | - "ERR1: at least one crc error, reg: 0x%x\n,cnt:%d", val, err_list->cnt); |
|---|
| 807 | + csi2_find_err_vc((val >> 12) & 0xf, vc_info); |
|---|
| 808 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(err_data,vc:%s) ", vc_info); |
|---|
| 809 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 829 | 810 | } |
|---|
| 830 | 811 | |
|---|
| 831 | 812 | if (val & CSIHOST_ERR1_ERR_CRC) { |
|---|
| 832 | 813 | err_list = &csi2->err_list[RK_CSI2_ERR_CRC]; |
|---|
| 833 | 814 | err_list->cnt++; |
|---|
| 834 | | - v4l2_err(&csi2->sd, |
|---|
| 835 | | - "ERR1: crc errors, reg: 0x%x, cnt:%d\n", |
|---|
| 836 | | - val, err_list->cnt); |
|---|
| 815 | + is_add_cnt = true; |
|---|
| 816 | + csi2_find_err_vc((val >> 24) & 0xf, vc_info); |
|---|
| 817 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(crc,vc:%s) ", vc_info); |
|---|
| 818 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 837 | 819 | } |
|---|
| 838 | 820 | |
|---|
| 839 | | - csi2->err_list[RK_CSI2_ERR_ALL].cnt++; |
|---|
| 840 | | - err_stat = ((csi2->err_list[RK_CSI2_ERR_FS_FE_MIS].cnt & 0xff) << 8) | |
|---|
| 841 | | - ((csi2->err_list[RK_CSI2_ERR_ALL].cnt) & 0xff); |
|---|
| 821 | + if (val & CSIHOST_ERR1_ERR_ECC2) { |
|---|
| 822 | + err_list = &csi2->err_list[RK_CSI2_ERR_CRC]; |
|---|
| 823 | + err_list->cnt++; |
|---|
| 824 | + is_add_cnt = true; |
|---|
| 825 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(ecc2) "); |
|---|
| 826 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 827 | + } |
|---|
| 842 | 828 | |
|---|
| 843 | | - atomic_notifier_call_chain(&g_csi_host_chain, |
|---|
| 844 | | - err_stat, |
|---|
| 845 | | - NULL); |
|---|
| 829 | + if (val & CSIHOST_ERR1_ERR_CTRL) { |
|---|
| 830 | + csi2_find_err_vc((val >> 16) & 0xf, vc_info); |
|---|
| 831 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(ctrl,vc:%s) ", vc_info); |
|---|
| 832 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 833 | + } |
|---|
| 834 | + |
|---|
| 835 | + pr_err("%s ERR1:0x%x %s\n", csi2->dev_name, val, err_str); |
|---|
| 836 | + |
|---|
| 837 | + if (is_add_cnt) { |
|---|
| 838 | + csi2->err_list[RK_CSI2_ERR_ALL].cnt++; |
|---|
| 839 | + err_stat = ((csi2->err_list[RK_CSI2_ERR_FS_FE_MIS].cnt & 0xff) << 8) | |
|---|
| 840 | + ((csi2->err_list[RK_CSI2_ERR_ALL].cnt) & 0xff); |
|---|
| 841 | + |
|---|
| 842 | + atomic_notifier_call_chain(&g_csi_host_chain, |
|---|
| 843 | + err_stat, |
|---|
| 844 | + &csi2->csi_idx); |
|---|
| 845 | + } |
|---|
| 846 | 846 | |
|---|
| 847 | 847 | } |
|---|
| 848 | 848 | |
|---|
| .. | .. |
|---|
| 854 | 854 | struct device *dev = ctx; |
|---|
| 855 | 855 | struct csi2_dev *csi2 = sd_to_dev(dev_get_drvdata(dev)); |
|---|
| 856 | 856 | u32 val; |
|---|
| 857 | + char cur_str[CSI_ERRSTR_LEN] = {0}; |
|---|
| 858 | + char err_str[CSI_ERRSTR_LEN] = {0}; |
|---|
| 859 | + char vc_info[CSI_VCINFO_LEN] = {0}; |
|---|
| 857 | 860 | |
|---|
| 858 | 861 | val = read_csihost_reg(csi2->base, CSIHOST_ERR2); |
|---|
| 859 | 862 | if (val) { |
|---|
| 860 | | - if (val & CSIHOST_ERR2_PHYERR_ESC) |
|---|
| 861 | | - v4l2_err(&csi2->sd, "ERR2: escape entry error(ULPM), reg: 0x%x\n", val); |
|---|
| 862 | | - if (val & CSIHOST_ERR2_PHYERR_SOTHS) |
|---|
| 863 | | - v4l2_err(&csi2->sd, |
|---|
| 864 | | - "ERR2: start of transmission error(synchronization can still be achieved), reg: 0x%x\n", |
|---|
| 865 | | - val); |
|---|
| 866 | | - if (val & CSIHOST_ERR2_ECC_CORRECTED) |
|---|
| 867 | | - v4l2_dbg(1, csi2_debug, &csi2->sd, |
|---|
| 868 | | - "ERR2: header error detected and corrected, reg: 0x%x\n", |
|---|
| 869 | | - val); |
|---|
| 870 | | - if (val & CSIHOST_ERR2_ERR_ID) |
|---|
| 871 | | - v4l2_err(&csi2->sd, |
|---|
| 872 | | - "ERR2: unrecognized or unimplemented data type detected, reg: 0x%x\n", |
|---|
| 873 | | - val); |
|---|
| 874 | | - if (val & CSIHOST_ERR2_PHYERR_CODEHS) |
|---|
| 875 | | - v4l2_err(&csi2->sd, "ERR2: receiv error code, reg: 0x%x\n", val); |
|---|
| 863 | + if (val & CSIHOST_ERR2_PHYERR_ESC) { |
|---|
| 864 | + csi2_find_err_vc(val & 0xf, vc_info); |
|---|
| 865 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(ULPM,lane:%s) ", vc_info); |
|---|
| 866 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 867 | + } |
|---|
| 868 | + if (val & CSIHOST_ERR2_PHYERR_SOTHS) { |
|---|
| 869 | + csi2_find_err_vc((val >> 4) & 0xf, vc_info); |
|---|
| 870 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(sot,lane:%s) ", vc_info); |
|---|
| 871 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 872 | + } |
|---|
| 873 | + if (val & CSIHOST_ERR2_ECC_CORRECTED) { |
|---|
| 874 | + csi2_find_err_vc((val >> 8) & 0xf, vc_info); |
|---|
| 875 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(ecc,vc:%s) ", vc_info); |
|---|
| 876 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 877 | + } |
|---|
| 878 | + if (val & CSIHOST_ERR2_ERR_ID) { |
|---|
| 879 | + csi2_find_err_vc((val >> 12) & 0xf, vc_info); |
|---|
| 880 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(err id,vc:%s) ", vc_info); |
|---|
| 881 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 882 | + } |
|---|
| 883 | + if (val & CSIHOST_ERR2_PHYERR_CODEHS) { |
|---|
| 884 | + snprintf(cur_str, CSI_ERRSTR_LEN, "(err code) "); |
|---|
| 885 | + csi2_err_strncat(err_str, cur_str); |
|---|
| 886 | + } |
|---|
| 887 | + |
|---|
| 888 | + pr_err("%s ERR2:0x%x %s\n", csi2->dev_name, val, err_str); |
|---|
| 876 | 889 | } |
|---|
| 877 | 890 | |
|---|
| 878 | 891 | return IRQ_HANDLED; |
|---|
| .. | .. |
|---|
| 883 | 896 | struct v4l2_async_notifier *ntf = &csi2->notifier; |
|---|
| 884 | 897 | int ret; |
|---|
| 885 | 898 | |
|---|
| 899 | + v4l2_async_notifier_init(ntf); |
|---|
| 900 | + |
|---|
| 886 | 901 | ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(csi2->dev, |
|---|
| 887 | 902 | &csi2->notifier, |
|---|
| 888 | 903 | sizeof(struct v4l2_async_subdev), 0, |
|---|
| 889 | 904 | csi2_parse_endpoint); |
|---|
| 890 | 905 | if (ret < 0) |
|---|
| 891 | 906 | return ret; |
|---|
| 892 | | - |
|---|
| 893 | | - if (!ntf->num_subdevs) |
|---|
| 894 | | - return -ENODEV; /* no endpoint */ |
|---|
| 895 | 907 | |
|---|
| 896 | 908 | csi2->sd.subdev_notifier = &csi2->notifier; |
|---|
| 897 | 909 | csi2->notifier.ops = &csi2_async_ops; |
|---|
| .. | .. |
|---|
| 929 | 941 | .num_pads = CSI2_NUM_PADS, |
|---|
| 930 | 942 | }; |
|---|
| 931 | 943 | |
|---|
| 944 | +static const struct csi2_match_data rk3588_csi2_match_data = { |
|---|
| 945 | + .chip_id = CHIP_RK3588_CSI2, |
|---|
| 946 | + .num_pads = CSI2_NUM_PADS_MAX, |
|---|
| 947 | +}; |
|---|
| 948 | + |
|---|
| 949 | +static const struct csi2_match_data rk3562_csi2_match_data = { |
|---|
| 950 | + .chip_id = CHIP_RK3562_CSI2, |
|---|
| 951 | + .num_pads = CSI2_NUM_PADS_MAX, |
|---|
| 952 | +}; |
|---|
| 953 | + |
|---|
| 932 | 954 | static const struct of_device_id csi2_dt_ids[] = { |
|---|
| 933 | 955 | { |
|---|
| 934 | 956 | .compatible = "rockchip,rk1808-mipi-csi2", |
|---|
| .. | .. |
|---|
| 945 | 967 | { |
|---|
| 946 | 968 | .compatible = "rockchip,rv1126-mipi-csi2", |
|---|
| 947 | 969 | .data = &rv1126_csi2_match_data, |
|---|
| 970 | + }, |
|---|
| 971 | + { |
|---|
| 972 | + .compatible = "rockchip,rk3588-mipi-csi2", |
|---|
| 973 | + .data = &rk3588_csi2_match_data, |
|---|
| 974 | + }, |
|---|
| 975 | + { |
|---|
| 976 | + .compatible = "rockchip,rk3562-mipi-csi2", |
|---|
| 977 | + .data = &rk3562_csi2_match_data, |
|---|
| 948 | 978 | }, |
|---|
| 949 | 979 | { /* sentinel */ } |
|---|
| 950 | 980 | }; |
|---|
| .. | .. |
|---|
| 972 | 1002 | csi2->dev = &pdev->dev; |
|---|
| 973 | 1003 | csi2->match_data = data; |
|---|
| 974 | 1004 | |
|---|
| 1005 | + csi2->dev_name = node->name; |
|---|
| 975 | 1006 | v4l2_subdev_init(&csi2->sd, &csi2_subdev_ops); |
|---|
| 976 | 1007 | v4l2_set_subdevdata(&csi2->sd, &pdev->dev); |
|---|
| 977 | 1008 | csi2->sd.entity.ops = &csi2_entity_ops; |
|---|
| .. | .. |
|---|
| 984 | 1015 | platform_set_drvdata(pdev, &csi2->sd); |
|---|
| 985 | 1016 | |
|---|
| 986 | 1017 | csi2->clks_num = devm_clk_bulk_get_all(dev, &csi2->clks_bulk); |
|---|
| 987 | | - if (csi2->clks_num < 0) |
|---|
| 1018 | + if (csi2->clks_num < 0) { |
|---|
| 1019 | + csi2->clks_num = 0; |
|---|
| 988 | 1020 | dev_err(dev, "failed to get csi2 clks\n"); |
|---|
| 1021 | + } |
|---|
| 989 | 1022 | |
|---|
| 990 | 1023 | csi2->rsts_bulk = devm_reset_control_array_get_optional_exclusive(dev); |
|---|
| 991 | 1024 | if (IS_ERR(csi2->rsts_bulk)) { |
|---|
| 992 | 1025 | if (PTR_ERR(csi2->rsts_bulk) != -EPROBE_DEFER) |
|---|
| 993 | 1026 | dev_err(dev, "failed to get csi2 reset\n"); |
|---|
| 994 | | - return PTR_ERR(csi2->rsts_bulk); |
|---|
| 1027 | + csi2->rsts_bulk = NULL; |
|---|
| 995 | 1028 | } |
|---|
| 996 | 1029 | |
|---|
| 997 | 1030 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| .. | .. |
|---|
| 1019 | 1052 | if (ret < 0) |
|---|
| 1020 | 1053 | v4l2_err(&csi2->sd, "request csi-intr1 irq failed: %d\n", |
|---|
| 1021 | 1054 | ret); |
|---|
| 1055 | + csi2->irq1 = irq; |
|---|
| 1022 | 1056 | } else { |
|---|
| 1023 | 1057 | v4l2_err(&csi2->sd, "No found irq csi-intr1\n"); |
|---|
| 1024 | 1058 | } |
|---|
| .. | .. |
|---|
| 1032 | 1066 | if (ret < 0) |
|---|
| 1033 | 1067 | v4l2_err(&csi2->sd, "request csi-intr2 failed: %d\n", |
|---|
| 1034 | 1068 | ret); |
|---|
| 1069 | + csi2->irq2 = irq; |
|---|
| 1035 | 1070 | } else { |
|---|
| 1036 | 1071 | v4l2_err(&csi2->sd, "No found irq csi-intr2\n"); |
|---|
| 1037 | 1072 | } |
|---|
| .. | .. |
|---|
| 1044 | 1079 | ret = csi2_notifier(csi2); |
|---|
| 1045 | 1080 | if (ret) |
|---|
| 1046 | 1081 | goto rmmutex; |
|---|
| 1047 | | - |
|---|
| 1048 | | - csi2_hw_do_reset(csi2); |
|---|
| 1049 | | - |
|---|
| 1050 | | - g_csi2_dev = csi2; |
|---|
| 1051 | 1082 | |
|---|
| 1052 | 1083 | v4l2_info(&csi2->sd, "probe success, v4l2_dev:%s!\n", csi2->sd.v4l2_dev->name); |
|---|
| 1053 | 1084 | |
|---|
| .. | .. |
|---|
| 1079 | 1110 | .remove = csi2_remove, |
|---|
| 1080 | 1111 | }; |
|---|
| 1081 | 1112 | |
|---|
| 1082 | | -int __init rkcif_csi2_plat_drv_init(void) |
|---|
| 1113 | +int rkcif_csi2_plat_drv_init(void) |
|---|
| 1083 | 1114 | { |
|---|
| 1084 | 1115 | return platform_driver_register(&csi2_driver); |
|---|
| 1085 | 1116 | } |
|---|