Lines Matching full:bridge
3 * Driver for ST MIPID02 CSI-2 to PARALLEL bridge
218 static int mipid02_read_reg(struct mipid02_dev *bridge, u16 reg, u8 *val) in mipid02_read_reg() argument
220 struct i2c_client *client = bridge->i2c_client; in mipid02_read_reg()
248 static int mipid02_write_reg(struct mipid02_dev *bridge, u16 reg, u8 val) in mipid02_write_reg() argument
250 struct i2c_client *client = bridge->i2c_client; in mipid02_write_reg()
274 static int mipid02_get_regulators(struct mipid02_dev *bridge) in mipid02_get_regulators() argument
279 bridge->supplies[i].supply = mipid02_supply_name[i]; in mipid02_get_regulators()
281 return devm_regulator_bulk_get(&bridge->i2c_client->dev, in mipid02_get_regulators()
283 bridge->supplies); in mipid02_get_regulators()
286 static void mipid02_apply_reset(struct mipid02_dev *bridge) in mipid02_apply_reset() argument
288 gpiod_set_value_cansleep(bridge->reset_gpio, 0); in mipid02_apply_reset()
290 gpiod_set_value_cansleep(bridge->reset_gpio, 1); in mipid02_apply_reset()
292 gpiod_set_value_cansleep(bridge->reset_gpio, 0); in mipid02_apply_reset()
296 static int mipid02_set_power_on(struct mipid02_dev *bridge) in mipid02_set_power_on() argument
298 struct i2c_client *client = bridge->i2c_client; in mipid02_set_power_on()
301 ret = clk_prepare_enable(bridge->xclk); in mipid02_set_power_on()
308 bridge->supplies); in mipid02_set_power_on()
315 if (bridge->reset_gpio) { in mipid02_set_power_on()
317 mipid02_apply_reset(bridge); in mipid02_set_power_on()
326 clk_disable_unprepare(bridge->xclk); in mipid02_set_power_on()
330 static void mipid02_set_power_off(struct mipid02_dev *bridge) in mipid02_set_power_off() argument
332 regulator_bulk_disable(MIPID02_NUM_SUPPLIES, bridge->supplies); in mipid02_set_power_off()
333 clk_disable_unprepare(bridge->xclk); in mipid02_set_power_off()
336 static int mipid02_detect(struct mipid02_dev *bridge) in mipid02_detect() argument
344 return mipid02_read_reg(bridge, MIPID02_CLK_LANE_WR_REG1, ®); in mipid02_detect()
347 static u32 mipid02_get_link_freq_from_cid_link_freq(struct mipid02_dev *bridge, in mipid02_get_link_freq_from_cid_link_freq() argument
366 static u32 mipid02_get_link_freq_from_cid_pixel_rate(struct mipid02_dev *bridge, in mipid02_get_link_freq_from_cid_pixel_rate() argument
369 struct v4l2_fwnode_endpoint *ep = &bridge->rx; in mipid02_get_link_freq_from_cid_pixel_rate()
372 u32 bpp = bpp_from_code(bridge->fmt.code); in mipid02_get_link_freq_from_cid_pixel_rate()
387 static int mipid02_configure_from_rx_speed(struct mipid02_dev *bridge) in mipid02_configure_from_rx_speed() argument
389 struct i2c_client *client = bridge->i2c_client; in mipid02_configure_from_rx_speed()
390 struct v4l2_subdev *subdev = bridge->s_subdev; in mipid02_configure_from_rx_speed()
393 link_freq = mipid02_get_link_freq_from_cid_link_freq(bridge, subdev); in mipid02_configure_from_rx_speed()
395 link_freq = mipid02_get_link_freq_from_cid_pixel_rate(bridge, in mipid02_configure_from_rx_speed()
404 bridge->r.clk_lane_reg1 |= (2000000000 / link_freq) << 2; in mipid02_configure_from_rx_speed()
409 static int mipid02_configure_clk_lane(struct mipid02_dev *bridge) in mipid02_configure_clk_lane() argument
411 struct i2c_client *client = bridge->i2c_client; in mipid02_configure_clk_lane()
412 struct v4l2_fwnode_endpoint *ep = &bridge->rx; in mipid02_configure_clk_lane()
420 bridge->r.clk_lane_reg1 |= (polarities[0] << 1) | CLK_ENABLE; in mipid02_configure_clk_lane()
425 static int mipid02_configure_data0_lane(struct mipid02_dev *bridge, int nb, in mipid02_configure_data0_lane() argument
438 bridge->r.data_lane0_reg1 = 1 << 1; in mipid02_configure_data0_lane()
439 bridge->r.data_lane0_reg1 |= DATA_ENABLE; in mipid02_configure_data0_lane()
444 static int mipid02_configure_data1_lane(struct mipid02_dev *bridge, int nb, in mipid02_configure_data1_lane() argument
453 bridge->r.data_lane1_reg1 = 1 << 1; in mipid02_configure_data1_lane()
454 bridge->r.data_lane1_reg1 |= DATA_ENABLE; in mipid02_configure_data1_lane()
459 static int mipid02_configure_from_rx(struct mipid02_dev *bridge) in mipid02_configure_from_rx() argument
461 struct v4l2_fwnode_endpoint *ep = &bridge->rx; in mipid02_configure_from_rx()
467 ret = mipid02_configure_clk_lane(bridge); in mipid02_configure_from_rx()
471 ret = mipid02_configure_data0_lane(bridge, nb, are_lanes_swap, in mipid02_configure_from_rx()
476 ret = mipid02_configure_data1_lane(bridge, nb, are_lanes_swap, in mipid02_configure_from_rx()
481 bridge->r.mode_reg1 |= are_lanes_swap ? MODE_DATA_SWAP : 0; in mipid02_configure_from_rx()
482 bridge->r.mode_reg1 |= (nb - 1) << 1; in mipid02_configure_from_rx()
484 return mipid02_configure_from_rx_speed(bridge); in mipid02_configure_from_rx()
487 static int mipid02_configure_from_tx(struct mipid02_dev *bridge) in mipid02_configure_from_tx() argument
489 struct v4l2_fwnode_endpoint *ep = &bridge->tx; in mipid02_configure_from_tx()
491 bridge->r.data_selection_ctrl = SELECTION_MANUAL_WIDTH; in mipid02_configure_from_tx()
492 bridge->r.pix_width_ctrl = ep->bus.parallel.bus_width; in mipid02_configure_from_tx()
493 bridge->r.pix_width_ctrl_emb = ep->bus.parallel.bus_width; in mipid02_configure_from_tx()
495 bridge->r.mode_reg2 |= MODE_HSYNC_ACTIVE_HIGH; in mipid02_configure_from_tx()
497 bridge->r.mode_reg2 |= MODE_VSYNC_ACTIVE_HIGH; in mipid02_configure_from_tx()
502 static int mipid02_configure_from_code(struct mipid02_dev *bridge) in mipid02_configure_from_code() argument
506 bridge->r.data_id_rreg = 0; in mipid02_configure_from_code()
508 if (bridge->fmt.code != MEDIA_BUS_FMT_JPEG_1X8) { in mipid02_configure_from_code()
509 bridge->r.data_selection_ctrl |= SELECTION_MANUAL_DATA; in mipid02_configure_from_code()
511 data_type = data_type_from_code(bridge->fmt.code); in mipid02_configure_from_code()
514 bridge->r.data_id_rreg = data_type; in mipid02_configure_from_code()
520 static int mipid02_stream_disable(struct mipid02_dev *bridge) in mipid02_stream_disable() argument
522 struct i2c_client *client = bridge->i2c_client; in mipid02_stream_disable()
526 ret = mipid02_write_reg(bridge, MIPID02_CLK_LANE_REG1, 0); in mipid02_stream_disable()
529 ret = mipid02_write_reg(bridge, MIPID02_DATA_LANE0_REG1, 0); in mipid02_stream_disable()
532 ret = mipid02_write_reg(bridge, MIPID02_DATA_LANE1_REG1, 0); in mipid02_stream_disable()
542 static int mipid02_stream_enable(struct mipid02_dev *bridge) in mipid02_stream_enable() argument
544 struct i2c_client *client = bridge->i2c_client; in mipid02_stream_enable()
547 if (!bridge->s_subdev) in mipid02_stream_enable()
550 memset(&bridge->r, 0, sizeof(bridge->r)); in mipid02_stream_enable()
552 ret = mipid02_configure_from_rx(bridge); in mipid02_stream_enable()
555 ret = mipid02_configure_from_tx(bridge); in mipid02_stream_enable()
558 ret = mipid02_configure_from_code(bridge); in mipid02_stream_enable()
563 ret = mipid02_write_reg(bridge, MIPID02_CLK_LANE_REG1, in mipid02_stream_enable()
564 bridge->r.clk_lane_reg1); in mipid02_stream_enable()
567 ret = mipid02_write_reg(bridge, MIPID02_CLK_LANE_REG3, CLK_MIPI_CSI); in mipid02_stream_enable()
570 ret = mipid02_write_reg(bridge, MIPID02_DATA_LANE0_REG1, in mipid02_stream_enable()
571 bridge->r.data_lane0_reg1); in mipid02_stream_enable()
574 ret = mipid02_write_reg(bridge, MIPID02_DATA_LANE0_REG2, in mipid02_stream_enable()
578 ret = mipid02_write_reg(bridge, MIPID02_DATA_LANE1_REG1, in mipid02_stream_enable()
579 bridge->r.data_lane1_reg1); in mipid02_stream_enable()
582 ret = mipid02_write_reg(bridge, MIPID02_DATA_LANE1_REG2, in mipid02_stream_enable()
586 ret = mipid02_write_reg(bridge, MIPID02_MODE_REG1, in mipid02_stream_enable()
587 MODE_NO_BYPASS | bridge->r.mode_reg1); in mipid02_stream_enable()
590 ret = mipid02_write_reg(bridge, MIPID02_MODE_REG2, in mipid02_stream_enable()
591 bridge->r.mode_reg2); in mipid02_stream_enable()
594 ret = mipid02_write_reg(bridge, MIPID02_DATA_ID_RREG, in mipid02_stream_enable()
595 bridge->r.data_id_rreg); in mipid02_stream_enable()
598 ret = mipid02_write_reg(bridge, MIPID02_DATA_SELECTION_CTRL, in mipid02_stream_enable()
599 bridge->r.data_selection_ctrl); in mipid02_stream_enable()
602 ret = mipid02_write_reg(bridge, MIPID02_PIX_WIDTH_CTRL, in mipid02_stream_enable()
603 bridge->r.pix_width_ctrl); in mipid02_stream_enable()
606 ret = mipid02_write_reg(bridge, MIPID02_PIX_WIDTH_CTRL_EMB, in mipid02_stream_enable()
607 bridge->r.pix_width_ctrl_emb); in mipid02_stream_enable()
615 mipid02_stream_disable(bridge); in mipid02_stream_enable()
622 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_s_stream() local
623 struct i2c_client *client = bridge->i2c_client; in mipid02_s_stream()
627 enable, bridge->streaming); in mipid02_s_stream()
628 mutex_lock(&bridge->lock); in mipid02_s_stream()
630 if (bridge->streaming == enable) in mipid02_s_stream()
633 ret = enable ? mipid02_stream_enable(bridge) : in mipid02_s_stream()
634 mipid02_stream_disable(bridge); in mipid02_s_stream()
636 bridge->streaming = enable; in mipid02_s_stream()
640 bridge->streaming, ret); in mipid02_s_stream()
641 mutex_unlock(&bridge->lock); in mipid02_s_stream()
650 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_enum_mbus_code() local
662 code->code = serial_to_parallel_code(bridge->fmt.code); in mipid02_enum_mbus_code()
678 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_get_fmt() local
679 struct i2c_client *client = bridge->i2c_client; in mipid02_get_fmt()
691 fmt = v4l2_subdev_get_try_format(&bridge->sd, cfg, format->pad); in mipid02_get_fmt()
693 fmt = &bridge->fmt; in mipid02_get_fmt()
695 mutex_lock(&bridge->lock); in mipid02_get_fmt()
702 mutex_unlock(&bridge->lock); in mipid02_get_fmt()
711 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_set_fmt_source() local
714 format->format = bridge->fmt; in mipid02_set_fmt_source()
729 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_set_fmt_sink() local
737 fmt = &bridge->fmt; in mipid02_set_fmt_sink()
746 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_set_fmt() local
747 struct i2c_client *client = bridge->i2c_client; in mipid02_set_fmt()
758 mutex_lock(&bridge->lock); in mipid02_set_fmt()
760 if (bridge->streaming) { in mipid02_set_fmt()
771 mutex_unlock(&bridge->lock); in mipid02_set_fmt()
799 struct mipid02_dev *bridge = to_mipid02_dev(notifier->sd); in mipid02_async_bound() local
800 struct i2c_client *client = bridge->i2c_client; in mipid02_async_bound()
816 &bridge->sd.entity, 0, in mipid02_async_bound()
824 bridge->s_subdev = s_subdev; in mipid02_async_bound()
833 struct mipid02_dev *bridge = to_mipid02_dev(notifier->sd); in mipid02_async_unbind() local
835 bridge->s_subdev = NULL; in mipid02_async_unbind()
843 static int mipid02_parse_rx_ep(struct mipid02_dev *bridge) in mipid02_parse_rx_ep() argument
846 struct i2c_client *client = bridge->i2c_client; in mipid02_parse_rx_ep()
851 ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, in mipid02_parse_rx_ep()
875 bridge->rx = ep; in mipid02_parse_rx_ep()
878 bridge->asd.match.fwnode = in mipid02_parse_rx_ep()
880 bridge->asd.match_type = V4L2_ASYNC_MATCH_FWNODE; in mipid02_parse_rx_ep()
883 v4l2_async_notifier_init(&bridge->notifier); in mipid02_parse_rx_ep()
884 ret = v4l2_async_notifier_add_subdev(&bridge->notifier, &bridge->asd); in mipid02_parse_rx_ep()
888 fwnode_handle_put(bridge->asd.match.fwnode); in mipid02_parse_rx_ep()
891 bridge->notifier.ops = &mipid02_notifier_ops; in mipid02_parse_rx_ep()
893 ret = v4l2_async_subdev_notifier_register(&bridge->sd, in mipid02_parse_rx_ep()
894 &bridge->notifier); in mipid02_parse_rx_ep()
896 v4l2_async_notifier_cleanup(&bridge->notifier); in mipid02_parse_rx_ep()
907 static int mipid02_parse_tx_ep(struct mipid02_dev *bridge) in mipid02_parse_tx_ep() argument
910 struct i2c_client *client = bridge->i2c_client; in mipid02_parse_tx_ep()
915 ep_node = of_graph_get_endpoint_by_regs(bridge->i2c_client->dev.of_node, in mipid02_parse_tx_ep()
930 bridge->tx = ep; in mipid02_parse_tx_ep()
944 struct mipid02_dev *bridge; in mipid02_probe() local
948 bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL); in mipid02_probe()
949 if (!bridge) in mipid02_probe()
952 init_format(&bridge->fmt); in mipid02_probe()
954 bridge->i2c_client = client; in mipid02_probe()
955 v4l2_i2c_subdev_init(&bridge->sd, client, &mipid02_subdev_ops); in mipid02_probe()
958 bridge->xclk = devm_clk_get(dev, "xclk"); in mipid02_probe()
959 if (IS_ERR(bridge->xclk)) { in mipid02_probe()
961 return PTR_ERR(bridge->xclk); in mipid02_probe()
964 clk_freq = clk_get_rate(bridge->xclk); in mipid02_probe()
971 bridge->reset_gpio = devm_gpiod_get_optional(dev, "reset", in mipid02_probe()
974 if (IS_ERR(bridge->reset_gpio)) { in mipid02_probe()
976 return PTR_ERR(bridge->reset_gpio); in mipid02_probe()
979 ret = mipid02_get_regulators(bridge); in mipid02_probe()
985 mutex_init(&bridge->lock); in mipid02_probe()
986 bridge->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; in mipid02_probe()
987 bridge->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in mipid02_probe()
988 bridge->sd.entity.ops = &mipid02_subdev_entity_ops; in mipid02_probe()
989 bridge->pad[0].flags = MEDIA_PAD_FL_SINK; in mipid02_probe()
990 bridge->pad[1].flags = MEDIA_PAD_FL_SINK; in mipid02_probe()
991 bridge->pad[2].flags = MEDIA_PAD_FL_SOURCE; in mipid02_probe()
992 ret = media_entity_pads_init(&bridge->sd.entity, MIPID02_PAD_NB, in mipid02_probe()
993 bridge->pad); in mipid02_probe()
1000 ret = mipid02_set_power_on(bridge); in mipid02_probe()
1004 ret = mipid02_detect(bridge); in mipid02_probe()
1010 ret = mipid02_parse_tx_ep(bridge); in mipid02_probe()
1016 ret = mipid02_parse_rx_ep(bridge); in mipid02_probe()
1022 ret = v4l2_async_register_subdev(&bridge->sd); in mipid02_probe()
1034 v4l2_async_notifier_unregister(&bridge->notifier); in mipid02_probe()
1035 v4l2_async_notifier_cleanup(&bridge->notifier); in mipid02_probe()
1037 mipid02_set_power_off(bridge); in mipid02_probe()
1039 media_entity_cleanup(&bridge->sd.entity); in mipid02_probe()
1041 mutex_destroy(&bridge->lock); in mipid02_probe()
1049 struct mipid02_dev *bridge = to_mipid02_dev(sd); in mipid02_remove() local
1051 v4l2_async_notifier_unregister(&bridge->notifier); in mipid02_remove()
1052 v4l2_async_notifier_cleanup(&bridge->notifier); in mipid02_remove()
1053 v4l2_async_unregister_subdev(&bridge->sd); in mipid02_remove()
1054 mipid02_set_power_off(bridge); in mipid02_remove()
1055 media_entity_cleanup(&bridge->sd.entity); in mipid02_remove()
1056 mutex_destroy(&bridge->lock); in mipid02_remove()
1079 MODULE_DESCRIPTION("STMicroelectronics MIPID02 CSI-2 bridge driver");