Lines Matching +full:csi +full:- +full:bridge

1 // SPDX-License-Identifier: GPL-2.0-only
3 * tc358743 - Toshiba HDMI to CSI-2 bridge
11 * REF_01 - Toshiba, TC358743XBG (H2C), Functional Specification, Rev 0.60
12 * REF_02 - Toshiba, TC358743XBG_HDMI-CSI_Tv11p_nm.xls
27 #include <linux/v4l2-dv-timings.h>
30 #include <media/v4l2-dv-timings.h>
31 #include <media/v4l2-device.h>
32 #include <media/v4l2-ctrls.h>
33 #include <media/v4l2-event.h>
34 #include <media/v4l2-fwnode.h>
41 MODULE_PARM_DESC(debug, "debug level (0-3)");
43 MODULE_DESCRIPTION("Toshiba TC358743 HDMI to CSI-2 bridge driver");
115 /* --------------- I2C --------------- */
120 struct i2c_client *client = state->i2c_client; in i2c_rd()
125 .addr = client->addr, in i2c_rd()
131 .addr = client->addr, in i2c_rd()
138 err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in i2c_rd()
141 __func__, reg, client->addr, err); in i2c_rd()
148 struct i2c_client *client = state->i2c_client; in i2c_wr()
154 n = I2C_MAX_XFER_SIZE - 2; in i2c_wr()
159 msg.addr = client->addr; in i2c_wr()
170 err = i2c_transfer(client->adapter, &msg, 1); in i2c_wr()
173 __func__, reg, client->addr, err); in i2c_wr()
256 /* --------------- STATUS --------------- */
297 /* --------------- TIMINGS --------------- */
304 return DIV_ROUND_CLOSEST((unsigned)t->pixelclock, in fps()
311 struct v4l2_bt_timings *bt = &timings->bt; in tc358743_get_detected_timings()
318 return -ENOLINK; in tc358743_get_detected_timings()
322 return -ENOLINK; in tc358743_get_detected_timings()
326 return -ENOLCK; in tc358743_get_detected_timings()
329 timings->type = V4L2_DV_BT_656_1120; in tc358743_get_detected_timings()
330 bt->interlaced = i2c_rd8(sd, VI_STATUS1) & MASK_S_V_INTERLACE ? in tc358743_get_detected_timings()
348 bt->width = width; in tc358743_get_detected_timings()
349 bt->height = height; in tc358743_get_detected_timings()
350 bt->vsync = frame_height - height; in tc358743_get_detected_timings()
351 bt->hsync = frame_width - width; in tc358743_get_detected_timings()
352 bt->pixelclock = frame_width * frame_height * fps; in tc358743_get_detected_timings()
353 if (bt->interlaced == V4L2_DV_INTERLACED) { in tc358743_get_detected_timings()
354 bt->height *= 2; in tc358743_get_detected_timings()
355 bt->il_vsync = bt->vsync + 1; in tc358743_get_detected_timings()
356 bt->pixelclock /= 2; in tc358743_get_detected_timings()
362 /* --------------- HOTPLUG / HDCP / EDID --------------- */
369 struct v4l2_subdev *sd = &state->sd; in tc358743_delayed_work_enable_hotplug()
404 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); in tc358743_disable_edid()
415 if (state->edid_blocks_written == 0) { in tc358743_enable_edid()
416 v4l2_dbg(2, debug, sd, "%s: no EDID -> no hotplug\n", __func__); in tc358743_enable_edid()
425 schedule_delayed_work(&state->delayed_work_enable_hotplug, HZ / 10); in tc358743_enable_edid()
439 /* --------------- AVI infoframe --------------- */
455 i2c_rd(sd, PK_AVI_0HEAD, buf, PK_AVI_16BYTE - PK_AVI_0HEAD + 1); in tc358743_debugfs_if_read()
458 len = -ENOENT; in tc358743_debugfs_if_read()
467 struct device *dev = &client->dev; in print_avi_infoframe()
472 v4l2_info(sd, "DVI-D signal - AVI infoframe not supported\n"); in print_avi_infoframe()
486 /* --------------- CTRLS --------------- */
492 return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, in tc358743_s_ctrl_detect_tx_5v()
500 return v4l2_ctrl_s_ctrl(state->audio_sampling_rate_ctrl, in tc358743_s_ctrl_audio_sampling_rate()
508 return v4l2_ctrl_s_ctrl(state->audio_present_ctrl, in tc358743_s_ctrl_audio_present()
523 /* --------------- INIT --------------- */
555 /* It is critical for CSI receiver to see lane transition in enable_stream()
556 * LP11->HS. Set to non-continuous mode to enable clock lane in enable_stream()
559 /* Set to continuous mode to trigger LP11->HS transition */ in enable_stream()
565 * No data is output to CSI Tx block. */ in enable_stream()
569 mutex_lock(&state->confctl_mutex); in enable_stream()
572 mutex_unlock(&state->confctl_mutex); in enable_stream()
578 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_pll()
581 u16 pllctl0_new = SET_PLL_PRD(pdata->pll_prd) | in tc358743_set_pll()
582 SET_PLL_FBD(pdata->pll_fbd); in tc358743_set_pll()
583 u32 hsck = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; in tc358743_set_pll()
617 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_ref_clk()
624 BUG_ON(!(pdata->refclk_hz == 26000000 || in tc358743_set_ref_clk()
625 pdata->refclk_hz == 27000000 || in tc358743_set_ref_clk()
626 pdata->refclk_hz == 42000000)); in tc358743_set_ref_clk()
628 sys_freq = pdata->refclk_hz / 10000; in tc358743_set_ref_clk()
633 (pdata->refclk_hz == 42000000) ? in tc358743_set_ref_clk()
636 fh_min = pdata->refclk_hz / 100000; in tc358743_set_ref_clk()
644 lockdet_ref = pdata->refclk_hz / 100; in tc358743_set_ref_clk()
650 (pdata->refclk_hz == 27000000) ? in tc358743_set_ref_clk()
667 switch (state->mbus_fmt_code) { in tc358743_set_csi_color_space()
669 v4l2_dbg(2, debug, sd, "%s: YCbCr 422 16-bit\n", __func__); in tc358743_set_csi_color_space()
675 mutex_lock(&state->confctl_mutex); in tc358743_set_csi_color_space()
678 mutex_unlock(&state->confctl_mutex); in tc358743_set_csi_color_space()
681 v4l2_dbg(2, debug, sd, "%s: RGB 888 24-bit\n", __func__); in tc358743_set_csi_color_space()
687 mutex_lock(&state->confctl_mutex); in tc358743_set_csi_color_space()
689 mutex_unlock(&state->confctl_mutex); in tc358743_set_csi_color_space()
693 __func__, state->mbus_fmt_code); in tc358743_set_csi_color_space()
700 struct v4l2_bt_timings *bt = &state->timings.bt; in tc358743_num_csi_lanes_needed()
701 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_num_csi_lanes_needed()
703 (state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_1X16) ? 16 : 24; in tc358743_num_csi_lanes_needed()
704 u32 bps = bt->width * bt->height * fps(bt) * bits_pr_pixel; in tc358743_num_csi_lanes_needed()
705 u32 bps_pr_lane = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; in tc358743_num_csi_lanes_needed()
713 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_csi()
718 state->csi_lanes_in_use = lanes; in tc358743_set_csi()
733 i2c_wr32(sd, LINEINITCNT, pdata->lineinitcnt); in tc358743_set_csi()
734 i2c_wr32(sd, LPTXTIMECNT, pdata->lptxtimecnt); in tc358743_set_csi()
735 i2c_wr32(sd, TCLK_HEADERCNT, pdata->tclk_headercnt); in tc358743_set_csi()
736 i2c_wr32(sd, TCLK_TRAILCNT, pdata->tclk_trailcnt); in tc358743_set_csi()
737 i2c_wr32(sd, THS_HEADERCNT, pdata->ths_headercnt); in tc358743_set_csi()
738 i2c_wr32(sd, TWAKEUP, pdata->twakeup); in tc358743_set_csi()
739 i2c_wr32(sd, TCLK_POSTCNT, pdata->tclk_postcnt); in tc358743_set_csi()
740 i2c_wr32(sd, THS_TRAILCNT, pdata->ths_trailcnt); in tc358743_set_csi()
741 i2c_wr32(sd, HSTXVREGCNT, pdata->hstxvregcnt); in tc358743_set_csi()
750 i2c_wr32(sd, TXOPTIONCNTRL, (state->bus.flags & in tc358743_set_csi()
777 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_hdmi_phy()
785 (pdata->hdmi_phy_auto_reset_tmds_detected ? in tc358743_set_hdmi_phy()
787 (pdata->hdmi_phy_auto_reset_tmds_in_range ? in tc358743_set_hdmi_phy()
789 (pdata->hdmi_phy_auto_reset_tmds_valid ? in tc358743_set_hdmi_phy()
795 pdata->hdmi_detection_delay << 4); in tc358743_set_hdmi_phy()
797 (pdata->hdmi_phy_auto_reset_hsync_out_of_range ? in tc358743_set_hdmi_phy()
799 (pdata->hdmi_phy_auto_reset_vsync_out_of_range ? in tc358743_set_hdmi_phy()
824 mutex_lock(&state->confctl_mutex); in tc358743_set_hdmi_audio()
827 mutex_unlock(&state->confctl_mutex); in tc358743_set_hdmi_audio()
847 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_initial_setup()
862 i2c_wr16(sd, FIFOCTL, pdata->fifo_level); in tc358743_initial_setup()
867 pdata->ddc5v_delay & MASK_DDC5V_MODE); in tc358743_initial_setup()
871 tc358743_set_hdmi_hdcp(sd, pdata->enable_hdcp); in tc358743_initial_setup()
883 /* --------------- CEC --------------- */
888 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_enable()
889 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_enable()
902 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_monitor_all_enable()
903 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_monitor_all_enable()
917 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_log_addr()
918 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_log_addr()
932 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_transmit()
933 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_transmit()
938 (signal_free_time - 1)); in tc358743_cec_adap_transmit()
939 for (i = 0; i < msg->len; i++) in tc358743_cec_adap_transmit()
941 msg->msg[i] | ((i == msg->len - 1) ? MASK_CECTEOM : 0)); in tc358743_cec_adap_transmit()
971 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
974 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
977 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
984 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
1004 cec_received_msg(state->cec_adap, &msg); in tc358743_cec_handler()
1014 /* --------------- IRQ --------------- */
1031 if (!v4l2_match_dv_timings(&state->timings, &timings, 0, false)) in tc358743_format_change()
1035 v4l2_print_dv_timings(sd->name, in tc358743_format_change()
1040 if (sd->devnode) in tc358743_format_change()
1185 * frequency as the existing (e.g. 1080p25 -> 720p50), the in tc358743_hdmi_clk_int_handler()
1225 memset(&state->timings, 0, sizeof(state->timings)); in tc358743_hdmi_sys_int_handler()
1236 v4l2_dbg(1, debug, sd, "%s: HDMI->DVI change detected\n", in tc358743_hdmi_sys_int_handler()
1253 v4l2_dbg(1, debug, sd, "%s: DVI->HDMI change detected\n", in tc358743_hdmi_sys_int_handler()
1270 /* --------------- CORE OPS --------------- */
1285 v4l2_info(sd, "-----Chip status-----\n"); in tc358743_log_status()
1290 v4l2_info(sd, "Reset: IR: %d, CEC: %d, CSI TX: %d, HDMI: %d\n", in tc358743_log_status()
1306 v4l2_info(sd, "-----Signal status-----\n"); in tc358743_log_status()
1319 v4l2_print_dv_timings(sd->name, "Detected format: ", &timings, in tc358743_log_status()
1322 v4l2_print_dv_timings(sd->name, "Configured format: ", &state->timings, in tc358743_log_status()
1325 v4l2_info(sd, "-----CSI-TX status-----\n"); in tc358743_log_status()
1329 state->csi_lanes_in_use); in tc358743_log_status()
1343 state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_1X16 ? in tc358743_log_status()
1344 "YCbCr 422 16-bit" : in tc358743_log_status()
1345 state->mbus_fmt_code == MEDIA_BUS_FMT_RGB888_1X24 ? in tc358743_log_status()
1346 "RGB 888 24-bit" : "Unsupported"); in tc358743_log_status()
1348 v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); in tc358743_log_status()
1358 v4l2_info(sd, "Deep color mode: %d-bits per channel\n", in tc358743_log_status()
1369 v4l2_info(sd, "0x0000-0x00FF: Global Control Register\n"); in tc358743_print_register_map()
1370 v4l2_info(sd, "0x0100-0x01FF: CSI2-TX PHY Register\n"); in tc358743_print_register_map()
1371 v4l2_info(sd, "0x0200-0x03FF: CSI2-TX PPI Register\n"); in tc358743_print_register_map()
1372 v4l2_info(sd, "0x0400-0x05FF: Reserved\n"); in tc358743_print_register_map()
1373 v4l2_info(sd, "0x0600-0x06FF: CEC Register\n"); in tc358743_print_register_map()
1374 v4l2_info(sd, "0x0700-0x84FF: Reserved\n"); in tc358743_print_register_map()
1375 v4l2_info(sd, "0x8500-0x85FF: HDMIRX System Control Register\n"); in tc358743_print_register_map()
1376 v4l2_info(sd, "0x8600-0x86FF: HDMIRX Audio Control Register\n"); in tc358743_print_register_map()
1377 v4l2_info(sd, "0x8700-0x87FF: HDMIRX InfoFrame packet data Register\n"); in tc358743_print_register_map()
1378 v4l2_info(sd, "0x8800-0x88FF: HDMIRX HDCP Port Register\n"); in tc358743_print_register_map()
1379 v4l2_info(sd, "0x8900-0x89FF: HDMIRX Video Output Port & 3D Register\n"); in tc358743_print_register_map()
1380 v4l2_info(sd, "0x8A00-0x8BFF: Reserved\n"); in tc358743_print_register_map()
1381 v4l2_info(sd, "0x8C00-0x8FFF: HDMIRX EDID-RAM (1024bytes)\n"); in tc358743_print_register_map()
1382 v4l2_info(sd, "0x9000-0x90FF: HDMIRX GBD Extraction Control\n"); in tc358743_print_register_map()
1383 v4l2_info(sd, "0x9100-0x92FF: HDMIRX GBD RAM read\n"); in tc358743_print_register_map()
1384 v4l2_info(sd, "0x9300- : Reserved\n"); in tc358743_print_register_map()
1389 /* REF_01 p. 66-72 */ in tc358743_get_reg_size()
1403 if (reg->reg > 0xffff) { in tc358743_g_register()
1405 return -EINVAL; in tc358743_g_register()
1408 reg->size = tc358743_get_reg_size(reg->reg); in tc358743_g_register()
1410 reg->val = i2c_rdreg(sd, reg->reg, reg->size); in tc358743_g_register()
1418 if (reg->reg > 0xffff) { in tc358743_s_register()
1420 return -EINVAL; in tc358743_s_register()
1424 * v4l2-dbg command. in tc358743_s_register()
1429 if (reg->reg == HDCP_MODE || in tc358743_s_register()
1430 reg->reg == HDCP_REG1 || in tc358743_s_register()
1431 reg->reg == HDCP_REG2 || in tc358743_s_register()
1432 reg->reg == HDCP_REG3 || in tc358743_s_register()
1433 reg->reg == BCAPS) in tc358743_s_register()
1436 i2c_wrreg(sd, (u16)reg->reg, reg->val, in tc358743_s_register()
1437 tc358743_get_reg_size(reg->reg)); in tc358743_s_register()
1501 tc358743_isr(&state->sd, 0, &handled); in tc358743_irq_handler()
1511 schedule_work(&state->work_i2c_poll); in tc358743_irq_poll_timer()
1516 msecs = state->cec_adap ? POLL_INTERVAL_CEC_MS : POLL_INTERVAL_MS; in tc358743_irq_poll_timer()
1517 mod_timer(&state->timer, jiffies + msecs_to_jiffies(msecs)); in tc358743_irq_poll_timer()
1526 tc358743_isr(&state->sd, 0, &handled); in tc358743_work_i2c_poll()
1532 switch (sub->type) { in tc358743_subscribe_event()
1538 return -EINVAL; in tc358743_subscribe_event()
1542 /* --------------- VIDEO OPS --------------- */
1561 return -EINVAL; in tc358743_s_dv_timings()
1564 return -EINVAL; in tc358743_s_dv_timings()
1567 v4l2_print_dv_timings(sd->name, "tc358743_s_dv_timings: ", in tc358743_s_dv_timings()
1570 if (v4l2_match_dv_timings(&state->timings, timings, 0, false)) { in tc358743_s_dv_timings()
1578 return -ERANGE; in tc358743_s_dv_timings()
1581 state->timings = *timings; in tc358743_s_dv_timings()
1596 return -EINVAL; in tc358743_g_dv_timings()
1598 *timings = state->timings; in tc358743_g_dv_timings()
1606 if (timings->pad != 0) in tc358743_enum_dv_timings()
1607 return -EINVAL; in tc358743_enum_dv_timings()
1619 return -EINVAL; in tc358743_query_dv_timings()
1626 v4l2_print_dv_timings(sd->name, "tc358743_query_dv_timings: ", in tc358743_query_dv_timings()
1632 return -ERANGE; in tc358743_query_dv_timings()
1641 if (cap->pad != 0) in tc358743_dv_timings_cap()
1642 return -EINVAL; in tc358743_dv_timings_cap()
1655 cfg->type = V4L2_MBUS_CSI2_DPHY; in tc358743_get_mbus_config()
1657 /* Support for non-continuous CSI-2 clock is missing in the driver */ in tc358743_get_mbus_config()
1658 cfg->bus.mipi_csi2.flags = 0; in tc358743_get_mbus_config()
1659 cfg->bus.mipi_csi2.num_data_lanes = state->csi_lanes_in_use; in tc358743_get_mbus_config()
1668 /* Put all lanes in LP-11 state (STOPSTATE) */ in tc358743_s_stream()
1675 /* --------------- PAD OPS --------------- */
1681 switch (code->index) { in tc358743_enum_mbus_code()
1683 code->code = MEDIA_BUS_FMT_RGB888_1X24; in tc358743_enum_mbus_code()
1686 code->code = MEDIA_BUS_FMT_UYVY8_1X16; in tc358743_enum_mbus_code()
1689 return -EINVAL; in tc358743_enum_mbus_code()
1701 if (format->pad != 0) in tc358743_get_fmt()
1702 return -EINVAL; in tc358743_get_fmt()
1704 format->format.code = state->mbus_fmt_code; in tc358743_get_fmt()
1705 format->format.width = state->timings.bt.width; in tc358743_get_fmt()
1706 format->format.height = state->timings.bt.height; in tc358743_get_fmt()
1707 format->format.field = V4L2_FIELD_NONE; in tc358743_get_fmt()
1712 format->format.colorspace = V4L2_COLORSPACE_SRGB; in tc358743_get_fmt()
1716 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M; in tc358743_get_fmt()
1720 format->format.colorspace = V4L2_COLORSPACE_REC709; in tc358743_get_fmt()
1723 format->format.colorspace = 0; in tc358743_get_fmt()
1736 u32 code = format->format.code; /* is overwritten by get_fmt */ in tc358743_set_fmt()
1739 format->format.code = code; in tc358743_set_fmt()
1749 return -EINVAL; in tc358743_set_fmt()
1752 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in tc358743_set_fmt()
1755 state->mbus_fmt_code = format->format.code; in tc358743_set_fmt()
1770 memset(edid->reserved, 0, sizeof(edid->reserved)); in tc358743_g_edid()
1772 if (edid->pad != 0) in tc358743_g_edid()
1773 return -EINVAL; in tc358743_g_edid()
1775 if (edid->start_block == 0 && edid->blocks == 0) { in tc358743_g_edid()
1776 edid->blocks = state->edid_blocks_written; in tc358743_g_edid()
1780 if (state->edid_blocks_written == 0) in tc358743_g_edid()
1781 return -ENODATA; in tc358743_g_edid()
1783 if (edid->start_block >= state->edid_blocks_written || in tc358743_g_edid()
1784 edid->blocks == 0) in tc358743_g_edid()
1785 return -EINVAL; in tc358743_g_edid()
1787 if (edid->start_block + edid->blocks > state->edid_blocks_written) in tc358743_g_edid()
1788 edid->blocks = state->edid_blocks_written - edid->start_block; in tc358743_g_edid()
1790 i2c_rd(sd, EDID_RAM + (edid->start_block * EDID_BLOCK_SIZE), edid->edid, in tc358743_g_edid()
1791 edid->blocks * EDID_BLOCK_SIZE); in tc358743_g_edid()
1800 u16 edid_len = edid->blocks * EDID_BLOCK_SIZE; in tc358743_s_edid()
1806 __func__, edid->pad, edid->start_block, edid->blocks); in tc358743_s_edid()
1808 memset(edid->reserved, 0, sizeof(edid->reserved)); in tc358743_s_edid()
1810 if (edid->pad != 0) in tc358743_s_edid()
1811 return -EINVAL; in tc358743_s_edid()
1813 if (edid->start_block != 0) in tc358743_s_edid()
1814 return -EINVAL; in tc358743_s_edid()
1816 if (edid->blocks > EDID_NUM_BLOCKS_MAX) { in tc358743_s_edid()
1817 edid->blocks = EDID_NUM_BLOCKS_MAX; in tc358743_s_edid()
1818 return -E2BIG; in tc358743_s_edid()
1820 pa = cec_get_edid_phys_addr(edid->edid, edid->blocks * 128, NULL); in tc358743_s_edid()
1825 cec_phys_addr_invalidate(state->cec_adap); in tc358743_s_edid()
1832 if (edid->blocks == 0) { in tc358743_s_edid()
1833 state->edid_blocks_written = 0; in tc358743_s_edid()
1838 i2c_wr(sd, EDID_RAM + i, edid->edid + i, EDID_BLOCK_SIZE); in tc358743_s_edid()
1840 state->edid_blocks_written = edid->blocks; in tc358743_s_edid()
1842 cec_s_phys_addr(state->cec_adap, pa, false); in tc358743_s_edid()
1850 /* -------------------------------------------------------------------------- */
1888 /* --------------- CUSTOM CTRLS --------------- */
1912 /* --------------- PROBE / REMOVE --------------- */
1918 gpiod_set_value(state->reset_gpio, 1); in tc358743_gpio_reset()
1920 gpiod_set_value(state->reset_gpio, 0); in tc358743_gpio_reset()
1926 struct device *dev = &state->i2c_client->dev; in tc358743_probe_of()
1938 ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1); in tc358743_probe_of()
1941 return -EINVAL; in tc358743_probe_of()
1953 dev_err(dev, "missing CSI-2 properties in endpoint\n"); in tc358743_probe_of()
1954 ret = -EINVAL; in tc358743_probe_of()
1960 ret = -EINVAL; in tc358743_probe_of()
1964 state->bus = endpoint.bus.mipi_csi2; in tc358743_probe_of()
1972 state->pdata.refclk_hz = clk_get_rate(refclk); in tc358743_probe_of()
1973 state->pdata.ddc5v_delay = DDC5V_DELAY_100_MS; in tc358743_probe_of()
1974 state->pdata.enable_hdcp = false; in tc358743_probe_of()
1975 /* A FIFO level of 16 should be enough for 2-lane 720p60 at 594 MHz. */ in tc358743_probe_of()
1976 state->pdata.fifo_level = 16; in tc358743_probe_of()
1981 switch (state->pdata.refclk_hz) { in tc358743_probe_of()
1985 state->pdata.pll_prd = state->pdata.refclk_hz / 6000000; in tc358743_probe_of()
1989 state->pdata.refclk_hz); in tc358743_probe_of()
1994 * The CSI bps per lane must be between 62.5 Mbps and 1 Gbps. in tc358743_probe_of()
1995 * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60. in tc358743_probe_of()
2000 ret = -EINVAL; in tc358743_probe_of()
2004 /* The CSI speed per lane is refclk / pll_prd * pll_fbd */ in tc358743_probe_of()
2005 state->pdata.pll_fbd = bps_pr_lane / in tc358743_probe_of()
2006 state->pdata.refclk_hz * state->pdata.pll_prd; in tc358743_probe_of()
2015 state->pdata.lineinitcnt = 0xe80; in tc358743_probe_of()
2016 state->pdata.lptxtimecnt = 0x003; in tc358743_probe_of()
2017 /* tclk-preparecnt: 3, tclk-zerocnt: 20 */ in tc358743_probe_of()
2018 state->pdata.tclk_headercnt = 0x1403; in tc358743_probe_of()
2019 state->pdata.tclk_trailcnt = 0x00; in tc358743_probe_of()
2020 /* ths-preparecnt: 3, ths-zerocnt: 1 */ in tc358743_probe_of()
2021 state->pdata.ths_headercnt = 0x0103; in tc358743_probe_of()
2022 state->pdata.twakeup = 0x4882; in tc358743_probe_of()
2023 state->pdata.tclk_postcnt = 0x008; in tc358743_probe_of()
2024 state->pdata.ths_trailcnt = 0x2; in tc358743_probe_of()
2025 state->pdata.hstxvregcnt = 0; in tc358743_probe_of()
2027 state->reset_gpio = devm_gpiod_get_optional(dev, "reset", in tc358743_probe_of()
2029 if (IS_ERR(state->reset_gpio)) { in tc358743_probe_of()
2031 ret = PTR_ERR(state->reset_gpio); in tc358743_probe_of()
2035 if (state->reset_gpio) in tc358743_probe_of()
2052 return -ENODEV; in tc358743_probe_of()
2061 struct tc358743_platform_data *pdata = client->dev.platform_data; in tc358743_probe()
2066 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tc358743_probe()
2067 return -EIO; in tc358743_probe()
2069 client->addr << 1, client->adapter->name); in tc358743_probe()
2071 state = devm_kzalloc(&client->dev, sizeof(struct tc358743_state), in tc358743_probe()
2074 return -ENOMEM; in tc358743_probe()
2076 state->i2c_client = client; in tc358743_probe()
2080 state->pdata = *pdata; in tc358743_probe()
2081 state->bus.flags = 0; in tc358743_probe()
2084 if (err == -ENODEV) in tc358743_probe()
2090 sd = &state->sd; in tc358743_probe()
2092 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in tc358743_probe()
2097 client->addr << 1); in tc358743_probe()
2098 return -ENODEV; in tc358743_probe()
2102 v4l2_ctrl_handler_init(&state->hdl, 3); in tc358743_probe()
2104 state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&state->hdl, NULL, in tc358743_probe()
2108 state->audio_sampling_rate_ctrl = v4l2_ctrl_new_custom(&state->hdl, in tc358743_probe()
2111 state->audio_present_ctrl = v4l2_ctrl_new_custom(&state->hdl, in tc358743_probe()
2114 sd->ctrl_handler = &state->hdl; in tc358743_probe()
2115 if (state->hdl.error) { in tc358743_probe()
2116 err = state->hdl.error; in tc358743_probe()
2121 err = -ENODEV; in tc358743_probe()
2125 state->pad.flags = MEDIA_PAD_FL_SOURCE; in tc358743_probe()
2126 sd->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in tc358743_probe()
2127 err = media_entity_pads_init(&sd->entity, 1, &state->pad); in tc358743_probe()
2131 state->mbus_fmt_code = MEDIA_BUS_FMT_RGB888_1X24; in tc358743_probe()
2133 sd->dev = &client->dev; in tc358743_probe()
2135 mutex_init(&state->confctl_mutex); in tc358743_probe()
2137 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, in tc358743_probe()
2141 state->cec_adap = cec_allocate_adapter(&tc358743_cec_adap_ops, in tc358743_probe()
2142 state, dev_name(&client->dev), in tc358743_probe()
2144 if (IS_ERR(state->cec_adap)) { in tc358743_probe()
2145 err = PTR_ERR(state->cec_adap); in tc358743_probe()
2159 if (state->i2c_client->irq) { in tc358743_probe()
2160 err = devm_request_threaded_irq(&client->dev, in tc358743_probe()
2161 state->i2c_client->irq, in tc358743_probe()
2168 INIT_WORK(&state->work_i2c_poll, in tc358743_probe()
2170 timer_setup(&state->timer, tc358743_irq_poll_timer, 0); in tc358743_probe()
2171 state->timer.expires = jiffies + in tc358743_probe()
2173 add_timer(&state->timer); in tc358743_probe()
2176 err = cec_register_adapter(state->cec_adap, &client->dev); in tc358743_probe()
2179 cec_delete_adapter(state->cec_adap); in tc358743_probe()
2180 state->cec_adap = NULL; in tc358743_probe()
2187 err = v4l2_ctrl_handler_setup(sd->ctrl_handler); in tc358743_probe()
2195 state->debugfs_dir = debugfs_create_dir(sd->name, v4l2_debugfs_root()); in tc358743_probe()
2196 state->infoframes = v4l2_debugfs_if_alloc(state->debugfs_dir, in tc358743_probe()
2200 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in tc358743_probe()
2201 client->addr << 1, client->adapter->name); in tc358743_probe()
2206 cec_unregister_adapter(state->cec_adap); in tc358743_probe()
2207 if (!state->i2c_client->irq) { in tc358743_probe()
2208 timer_delete(&state->timer); in tc358743_probe()
2209 flush_work(&state->work_i2c_poll); in tc358743_probe()
2211 cancel_delayed_work(&state->delayed_work_enable_hotplug); in tc358743_probe()
2212 mutex_destroy(&state->confctl_mutex); in tc358743_probe()
2214 media_entity_cleanup(&sd->entity); in tc358743_probe()
2215 v4l2_ctrl_handler_free(&state->hdl); in tc358743_probe()
2224 if (!state->i2c_client->irq) { in tc358743_remove()
2225 timer_delete_sync(&state->timer); in tc358743_remove()
2226 flush_work(&state->work_i2c_poll); in tc358743_remove()
2228 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); in tc358743_remove()
2229 v4l2_debugfs_if_free(state->infoframes); in tc358743_remove()
2230 debugfs_remove_recursive(state->debugfs_dir); in tc358743_remove()
2231 cec_unregister_adapter(state->cec_adap); in tc358743_remove()
2234 mutex_destroy(&state->confctl_mutex); in tc358743_remove()
2235 media_entity_cleanup(&sd->entity); in tc358743_remove()
2236 v4l2_ctrl_handler_free(&state->hdl); in tc358743_remove()