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

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");
111 /* --------------- I2C --------------- */
116 struct i2c_client *client = state->i2c_client; in i2c_rd()
121 .addr = client->addr, in i2c_rd()
127 .addr = client->addr, in i2c_rd()
134 err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in i2c_rd()
137 __func__, reg, client->addr, err); in i2c_rd()
144 struct i2c_client *client = state->i2c_client; in i2c_wr()
150 n = I2C_MAX_XFER_SIZE - 2; in i2c_wr()
155 msg.addr = client->addr; in i2c_wr()
166 err = i2c_transfer(client->adapter, &msg, 1); in i2c_wr()
169 __func__, reg, client->addr, err); in i2c_wr()
252 /* --------------- STATUS --------------- */
293 /* --------------- TIMINGS --------------- */
300 return DIV_ROUND_CLOSEST((unsigned)t->pixelclock, in fps()
307 struct v4l2_bt_timings *bt = &timings->bt; in tc358743_get_detected_timings()
314 return -ENOLINK; in tc358743_get_detected_timings()
318 return -ENOLCK; in tc358743_get_detected_timings()
321 timings->type = V4L2_DV_BT_656_1120; in tc358743_get_detected_timings()
322 bt->interlaced = i2c_rd8(sd, VI_STATUS1) & MASK_S_V_INTERLACE ? in tc358743_get_detected_timings()
340 bt->width = width; in tc358743_get_detected_timings()
341 bt->height = height; in tc358743_get_detected_timings()
342 bt->vsync = frame_height - height; in tc358743_get_detected_timings()
343 bt->hsync = frame_width - width; in tc358743_get_detected_timings()
344 bt->pixelclock = frame_width * frame_height * fps; in tc358743_get_detected_timings()
345 if (bt->interlaced == V4L2_DV_INTERLACED) { in tc358743_get_detected_timings()
346 bt->height *= 2; in tc358743_get_detected_timings()
347 bt->il_vsync = bt->vsync + 1; in tc358743_get_detected_timings()
348 bt->pixelclock /= 2; in tc358743_get_detected_timings()
354 /* --------------- HOTPLUG / HDCP / EDID --------------- */
361 struct v4l2_subdev *sd = &state->sd; in tc358743_delayed_work_enable_hotplug()
396 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); in tc358743_disable_edid()
407 if (state->edid_blocks_written == 0) { in tc358743_enable_edid()
408 v4l2_dbg(2, debug, sd, "%s: no EDID -> no hotplug\n", __func__); in tc358743_enable_edid()
417 schedule_delayed_work(&state->delayed_work_enable_hotplug, HZ / 10); in tc358743_enable_edid()
431 /* --------------- AVI infoframe --------------- */
436 struct device *dev = &client->dev; in print_avi_infoframe()
441 v4l2_info(sd, "DVI-D signal - AVI infoframe not supported\n"); in print_avi_infoframe()
455 /* --------------- CTRLS --------------- */
461 return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, in tc358743_s_ctrl_detect_tx_5v()
469 return v4l2_ctrl_s_ctrl(state->audio_sampling_rate_ctrl, in tc358743_s_ctrl_audio_sampling_rate()
477 return v4l2_ctrl_s_ctrl(state->audio_present_ctrl, in tc358743_s_ctrl_audio_present()
492 /* --------------- INIT --------------- */
524 /* It is critical for CSI receiver to see lane transition in enable_stream()
525 * LP11->HS. Set to non-continuous mode to enable clock lane in enable_stream()
528 /* Set to continuous mode to trigger LP11->HS transition */ in enable_stream()
534 * No data is output to CSI Tx block. */ in enable_stream()
538 mutex_lock(&state->confctl_mutex); in enable_stream()
541 mutex_unlock(&state->confctl_mutex); in enable_stream()
547 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_pll()
550 u16 pllctl0_new = SET_PLL_PRD(pdata->pll_prd) | in tc358743_set_pll()
551 SET_PLL_FBD(pdata->pll_fbd); in tc358743_set_pll()
552 u32 hsck = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; in tc358743_set_pll()
586 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_ref_clk()
593 BUG_ON(!(pdata->refclk_hz == 26000000 || in tc358743_set_ref_clk()
594 pdata->refclk_hz == 27000000 || in tc358743_set_ref_clk()
595 pdata->refclk_hz == 42000000)); in tc358743_set_ref_clk()
597 sys_freq = pdata->refclk_hz / 10000; in tc358743_set_ref_clk()
602 (pdata->refclk_hz == 42000000) ? in tc358743_set_ref_clk()
605 fh_min = pdata->refclk_hz / 100000; in tc358743_set_ref_clk()
613 lockdet_ref = pdata->refclk_hz / 100; in tc358743_set_ref_clk()
619 (pdata->refclk_hz == 27000000) ? in tc358743_set_ref_clk()
636 switch (state->mbus_fmt_code) { in tc358743_set_csi_color_space()
638 v4l2_dbg(2, debug, sd, "%s: YCbCr 422 16-bit\n", __func__); in tc358743_set_csi_color_space()
644 mutex_lock(&state->confctl_mutex); in tc358743_set_csi_color_space()
647 mutex_unlock(&state->confctl_mutex); in tc358743_set_csi_color_space()
650 v4l2_dbg(2, debug, sd, "%s: RGB 888 24-bit\n", __func__); in tc358743_set_csi_color_space()
656 mutex_lock(&state->confctl_mutex); in tc358743_set_csi_color_space()
658 mutex_unlock(&state->confctl_mutex); in tc358743_set_csi_color_space()
662 __func__, state->mbus_fmt_code); in tc358743_set_csi_color_space()
669 struct v4l2_bt_timings *bt = &state->timings.bt; in tc358743_num_csi_lanes_needed()
670 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_num_csi_lanes_needed()
672 (state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_1X16) ? 16 : 24; in tc358743_num_csi_lanes_needed()
673 u32 bps = bt->width * bt->height * fps(bt) * bits_pr_pixel; in tc358743_num_csi_lanes_needed()
674 u32 bps_pr_lane = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; in tc358743_num_csi_lanes_needed()
682 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_csi()
687 state->csi_lanes_in_use = lanes; in tc358743_set_csi()
702 i2c_wr32(sd, LINEINITCNT, pdata->lineinitcnt); in tc358743_set_csi()
703 i2c_wr32(sd, LPTXTIMECNT, pdata->lptxtimecnt); in tc358743_set_csi()
704 i2c_wr32(sd, TCLK_HEADERCNT, pdata->tclk_headercnt); in tc358743_set_csi()
705 i2c_wr32(sd, TCLK_TRAILCNT, pdata->tclk_trailcnt); in tc358743_set_csi()
706 i2c_wr32(sd, THS_HEADERCNT, pdata->ths_headercnt); in tc358743_set_csi()
707 i2c_wr32(sd, TWAKEUP, pdata->twakeup); in tc358743_set_csi()
708 i2c_wr32(sd, TCLK_POSTCNT, pdata->tclk_postcnt); in tc358743_set_csi()
709 i2c_wr32(sd, THS_TRAILCNT, pdata->ths_trailcnt); in tc358743_set_csi()
710 i2c_wr32(sd, HSTXVREGCNT, pdata->hstxvregcnt); in tc358743_set_csi()
719 i2c_wr32(sd, TXOPTIONCNTRL, (state->bus.flags & in tc358743_set_csi()
746 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_hdmi_phy()
754 (pdata->hdmi_phy_auto_reset_tmds_detected ? in tc358743_set_hdmi_phy()
756 (pdata->hdmi_phy_auto_reset_tmds_in_range ? in tc358743_set_hdmi_phy()
758 (pdata->hdmi_phy_auto_reset_tmds_valid ? in tc358743_set_hdmi_phy()
764 pdata->hdmi_detection_delay << 4); in tc358743_set_hdmi_phy()
766 (pdata->hdmi_phy_auto_reset_hsync_out_of_range ? in tc358743_set_hdmi_phy()
768 (pdata->hdmi_phy_auto_reset_vsync_out_of_range ? in tc358743_set_hdmi_phy()
793 mutex_lock(&state->confctl_mutex); in tc358743_set_hdmi_audio()
796 mutex_unlock(&state->confctl_mutex); in tc358743_set_hdmi_audio()
816 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_initial_setup()
831 i2c_wr16(sd, FIFOCTL, pdata->fifo_level); in tc358743_initial_setup()
836 pdata->ddc5v_delay & MASK_DDC5V_MODE); in tc358743_initial_setup()
840 tc358743_set_hdmi_hdcp(sd, pdata->enable_hdcp); in tc358743_initial_setup()
852 /* --------------- CEC --------------- */
857 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_enable()
858 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_enable()
871 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_monitor_all_enable()
872 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_monitor_all_enable()
886 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_log_addr()
887 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_log_addr()
901 struct tc358743_state *state = adap->priv; in tc358743_cec_adap_transmit()
902 struct v4l2_subdev *sd = &state->sd; in tc358743_cec_adap_transmit()
907 (signal_free_time - 1)); in tc358743_cec_adap_transmit()
908 for (i = 0; i < msg->len; i++) in tc358743_cec_adap_transmit()
910 msg->msg[i] | ((i == msg->len - 1) ? MASK_CECTEOM : 0)); in tc358743_cec_adap_transmit()
940 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
943 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
946 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
953 cec_transmit_attempt_done(state->cec_adap, in tc358743_cec_handler()
973 cec_received_msg(state->cec_adap, &msg); in tc358743_cec_handler()
983 /* --------------- IRQ --------------- */
1000 if (!v4l2_match_dv_timings(&state->timings, &timings, 0, false)) in tc358743_format_change()
1004 v4l2_print_dv_timings(sd->name, in tc358743_format_change()
1009 if (sd->devnode) in tc358743_format_change()
1154 * frequency as the existing (e.g. 1080p25 -> 720p50), the in tc358743_hdmi_clk_int_handler()
1194 memset(&state->timings, 0, sizeof(state->timings)); in tc358743_hdmi_sys_int_handler()
1205 v4l2_dbg(1, debug, sd, "%s: HDMI->DVI change detected\n", in tc358743_hdmi_sys_int_handler()
1222 v4l2_dbg(1, debug, sd, "%s: DVI->HDMI change detected\n", in tc358743_hdmi_sys_int_handler()
1239 /* --------------- CORE OPS --------------- */
1254 v4l2_info(sd, "-----Chip status-----\n"); in tc358743_log_status()
1259 v4l2_info(sd, "Reset: IR: %d, CEC: %d, CSI TX: %d, HDMI: %d\n", in tc358743_log_status()
1275 v4l2_info(sd, "-----Signal status-----\n"); in tc358743_log_status()
1288 v4l2_print_dv_timings(sd->name, "Detected format: ", &timings, in tc358743_log_status()
1291 v4l2_print_dv_timings(sd->name, "Configured format: ", &state->timings, in tc358743_log_status()
1294 v4l2_info(sd, "-----CSI-TX status-----\n"); in tc358743_log_status()
1298 state->csi_lanes_in_use); in tc358743_log_status()
1312 state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_1X16 ? in tc358743_log_status()
1313 "YCbCr 422 16-bit" : in tc358743_log_status()
1314 state->mbus_fmt_code == MEDIA_BUS_FMT_RGB888_1X24 ? in tc358743_log_status()
1315 "RGB 888 24-bit" : "Unsupported"); in tc358743_log_status()
1317 v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); in tc358743_log_status()
1327 v4l2_info(sd, "Deep color mode: %d-bits per channel\n", in tc358743_log_status()
1338 v4l2_info(sd, "0x0000-0x00FF: Global Control Register\n"); in tc358743_print_register_map()
1339 v4l2_info(sd, "0x0100-0x01FF: CSI2-TX PHY Register\n"); in tc358743_print_register_map()
1340 v4l2_info(sd, "0x0200-0x03FF: CSI2-TX PPI Register\n"); in tc358743_print_register_map()
1341 v4l2_info(sd, "0x0400-0x05FF: Reserved\n"); in tc358743_print_register_map()
1342 v4l2_info(sd, "0x0600-0x06FF: CEC Register\n"); in tc358743_print_register_map()
1343 v4l2_info(sd, "0x0700-0x84FF: Reserved\n"); in tc358743_print_register_map()
1344 v4l2_info(sd, "0x8500-0x85FF: HDMIRX System Control Register\n"); in tc358743_print_register_map()
1345 v4l2_info(sd, "0x8600-0x86FF: HDMIRX Audio Control Register\n"); in tc358743_print_register_map()
1346 v4l2_info(sd, "0x8700-0x87FF: HDMIRX InfoFrame packet data Register\n"); in tc358743_print_register_map()
1347 v4l2_info(sd, "0x8800-0x88FF: HDMIRX HDCP Port Register\n"); in tc358743_print_register_map()
1348 v4l2_info(sd, "0x8900-0x89FF: HDMIRX Video Output Port & 3D Register\n"); in tc358743_print_register_map()
1349 v4l2_info(sd, "0x8A00-0x8BFF: Reserved\n"); in tc358743_print_register_map()
1350 v4l2_info(sd, "0x8C00-0x8FFF: HDMIRX EDID-RAM (1024bytes)\n"); in tc358743_print_register_map()
1351 v4l2_info(sd, "0x9000-0x90FF: HDMIRX GBD Extraction Control\n"); in tc358743_print_register_map()
1352 v4l2_info(sd, "0x9100-0x92FF: HDMIRX GBD RAM read\n"); in tc358743_print_register_map()
1353 v4l2_info(sd, "0x9300- : Reserved\n"); in tc358743_print_register_map()
1358 /* REF_01 p. 66-72 */ in tc358743_get_reg_size()
1372 if (reg->reg > 0xffff) { in tc358743_g_register()
1374 return -EINVAL; in tc358743_g_register()
1377 reg->size = tc358743_get_reg_size(reg->reg); in tc358743_g_register()
1379 reg->val = i2c_rdreg(sd, reg->reg, reg->size); in tc358743_g_register()
1387 if (reg->reg > 0xffff) { in tc358743_s_register()
1389 return -EINVAL; in tc358743_s_register()
1393 * v4l2-dbg command. in tc358743_s_register()
1398 if (reg->reg == HDCP_MODE || in tc358743_s_register()
1399 reg->reg == HDCP_REG1 || in tc358743_s_register()
1400 reg->reg == HDCP_REG2 || in tc358743_s_register()
1401 reg->reg == HDCP_REG3 || in tc358743_s_register()
1402 reg->reg == BCAPS) in tc358743_s_register()
1405 i2c_wrreg(sd, (u16)reg->reg, reg->val, in tc358743_s_register()
1406 tc358743_get_reg_size(reg->reg)); in tc358743_s_register()
1470 tc358743_isr(&state->sd, 0, &handled); in tc358743_irq_handler()
1480 schedule_work(&state->work_i2c_poll); in tc358743_irq_poll_timer()
1485 msecs = state->cec_adap ? POLL_INTERVAL_CEC_MS : POLL_INTERVAL_MS; in tc358743_irq_poll_timer()
1486 mod_timer(&state->timer, jiffies + msecs_to_jiffies(msecs)); in tc358743_irq_poll_timer()
1495 tc358743_isr(&state->sd, 0, &handled); in tc358743_work_i2c_poll()
1501 switch (sub->type) { in tc358743_subscribe_event()
1507 return -EINVAL; in tc358743_subscribe_event()
1511 /* --------------- VIDEO OPS --------------- */
1530 return -EINVAL; in tc358743_s_dv_timings()
1533 return -EINVAL; in tc358743_s_dv_timings()
1536 v4l2_print_dv_timings(sd->name, "tc358743_s_dv_timings: ", in tc358743_s_dv_timings()
1539 if (v4l2_match_dv_timings(&state->timings, timings, 0, false)) { in tc358743_s_dv_timings()
1547 return -ERANGE; in tc358743_s_dv_timings()
1550 state->timings = *timings; in tc358743_s_dv_timings()
1565 return -EINVAL; in tc358743_g_dv_timings()
1567 *timings = state->timings; in tc358743_g_dv_timings()
1575 if (timings->pad != 0) in tc358743_enum_dv_timings()
1576 return -EINVAL; in tc358743_enum_dv_timings()
1588 return -EINVAL; in tc358743_query_dv_timings()
1595 v4l2_print_dv_timings(sd->name, "tc358743_query_dv_timings: ", in tc358743_query_dv_timings()
1601 return -ERANGE; in tc358743_query_dv_timings()
1610 if (cap->pad != 0) in tc358743_dv_timings_cap()
1611 return -EINVAL; in tc358743_dv_timings_cap()
1624 cfg->type = V4L2_MBUS_CSI2_DPHY; in tc358743_get_mbus_config()
1626 /* Support for non-continuous CSI-2 clock is missing in the driver */ in tc358743_get_mbus_config()
1627 cfg->bus.mipi_csi2.flags = 0; in tc358743_get_mbus_config()
1628 cfg->bus.mipi_csi2.num_data_lanes = state->csi_lanes_in_use; in tc358743_get_mbus_config()
1637 /* Put all lanes in LP-11 state (STOPSTATE) */ in tc358743_s_stream()
1644 /* --------------- PAD OPS --------------- */
1650 switch (code->index) { in tc358743_enum_mbus_code()
1652 code->code = MEDIA_BUS_FMT_RGB888_1X24; in tc358743_enum_mbus_code()
1655 code->code = MEDIA_BUS_FMT_UYVY8_1X16; in tc358743_enum_mbus_code()
1658 return -EINVAL; in tc358743_enum_mbus_code()
1670 if (format->pad != 0) in tc358743_get_fmt()
1671 return -EINVAL; in tc358743_get_fmt()
1673 format->format.code = state->mbus_fmt_code; in tc358743_get_fmt()
1674 format->format.width = state->timings.bt.width; in tc358743_get_fmt()
1675 format->format.height = state->timings.bt.height; in tc358743_get_fmt()
1676 format->format.field = V4L2_FIELD_NONE; in tc358743_get_fmt()
1681 format->format.colorspace = V4L2_COLORSPACE_SRGB; in tc358743_get_fmt()
1685 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M; in tc358743_get_fmt()
1689 format->format.colorspace = V4L2_COLORSPACE_REC709; in tc358743_get_fmt()
1692 format->format.colorspace = 0; in tc358743_get_fmt()
1705 u32 code = format->format.code; /* is overwritten by get_fmt */ in tc358743_set_fmt()
1708 format->format.code = code; in tc358743_set_fmt()
1718 return -EINVAL; in tc358743_set_fmt()
1721 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in tc358743_set_fmt()
1724 state->mbus_fmt_code = format->format.code; in tc358743_set_fmt()
1739 memset(edid->reserved, 0, sizeof(edid->reserved)); in tc358743_g_edid()
1741 if (edid->pad != 0) in tc358743_g_edid()
1742 return -EINVAL; in tc358743_g_edid()
1744 if (edid->start_block == 0 && edid->blocks == 0) { in tc358743_g_edid()
1745 edid->blocks = state->edid_blocks_written; in tc358743_g_edid()
1749 if (state->edid_blocks_written == 0) in tc358743_g_edid()
1750 return -ENODATA; in tc358743_g_edid()
1752 if (edid->start_block >= state->edid_blocks_written || in tc358743_g_edid()
1753 edid->blocks == 0) in tc358743_g_edid()
1754 return -EINVAL; in tc358743_g_edid()
1756 if (edid->start_block + edid->blocks > state->edid_blocks_written) in tc358743_g_edid()
1757 edid->blocks = state->edid_blocks_written - edid->start_block; in tc358743_g_edid()
1759 i2c_rd(sd, EDID_RAM + (edid->start_block * EDID_BLOCK_SIZE), edid->edid, in tc358743_g_edid()
1760 edid->blocks * EDID_BLOCK_SIZE); in tc358743_g_edid()
1769 u16 edid_len = edid->blocks * EDID_BLOCK_SIZE; in tc358743_s_edid()
1775 __func__, edid->pad, edid->start_block, edid->blocks); in tc358743_s_edid()
1777 memset(edid->reserved, 0, sizeof(edid->reserved)); in tc358743_s_edid()
1779 if (edid->pad != 0) in tc358743_s_edid()
1780 return -EINVAL; in tc358743_s_edid()
1782 if (edid->start_block != 0) in tc358743_s_edid()
1783 return -EINVAL; in tc358743_s_edid()
1785 if (edid->blocks > EDID_NUM_BLOCKS_MAX) { in tc358743_s_edid()
1786 edid->blocks = EDID_NUM_BLOCKS_MAX; in tc358743_s_edid()
1787 return -E2BIG; in tc358743_s_edid()
1789 pa = cec_get_edid_phys_addr(edid->edid, edid->blocks * 128, NULL); in tc358743_s_edid()
1794 cec_phys_addr_invalidate(state->cec_adap); in tc358743_s_edid()
1801 if (edid->blocks == 0) { in tc358743_s_edid()
1802 state->edid_blocks_written = 0; in tc358743_s_edid()
1807 i2c_wr(sd, EDID_RAM + i, edid->edid + i, EDID_BLOCK_SIZE); in tc358743_s_edid()
1809 state->edid_blocks_written = edid->blocks; in tc358743_s_edid()
1811 cec_s_phys_addr(state->cec_adap, pa, false); in tc358743_s_edid()
1819 /* -------------------------------------------------------------------------- */
1852 .core = &tc358743_core_ops,
1857 /* --------------- CUSTOM CTRLS --------------- */
1881 /* --------------- PROBE / REMOVE --------------- */
1887 gpiod_set_value(state->reset_gpio, 1); in tc358743_gpio_reset()
1889 gpiod_set_value(state->reset_gpio, 0); in tc358743_gpio_reset()
1895 struct device *dev = &state->i2c_client->dev; in tc358743_probe_of()
1907 ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1); in tc358743_probe_of()
1910 return -EINVAL; in tc358743_probe_of()
1922 dev_err(dev, "missing CSI-2 properties in endpoint\n"); in tc358743_probe_of()
1923 ret = -EINVAL; in tc358743_probe_of()
1929 ret = -EINVAL; in tc358743_probe_of()
1933 state->bus = endpoint.bus.mipi_csi2; in tc358743_probe_of()
1941 state->pdata.refclk_hz = clk_get_rate(refclk); in tc358743_probe_of()
1942 state->pdata.ddc5v_delay = DDC5V_DELAY_100_MS; in tc358743_probe_of()
1943 state->pdata.enable_hdcp = false; in tc358743_probe_of()
1944 /* A FIFO level of 16 should be enough for 2-lane 720p60 at 594 MHz. */ in tc358743_probe_of()
1945 state->pdata.fifo_level = 16; in tc358743_probe_of()
1950 switch (state->pdata.refclk_hz) { in tc358743_probe_of()
1954 state->pdata.pll_prd = state->pdata.refclk_hz / 6000000; in tc358743_probe_of()
1958 state->pdata.refclk_hz); in tc358743_probe_of()
1963 * The CSI bps per lane must be between 62.5 Mbps and 1 Gbps. in tc358743_probe_of()
1964 * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60. in tc358743_probe_of()
1969 ret = -EINVAL; in tc358743_probe_of()
1973 /* The CSI speed per lane is refclk / pll_prd * pll_fbd */ in tc358743_probe_of()
1974 state->pdata.pll_fbd = bps_pr_lane / in tc358743_probe_of()
1975 state->pdata.refclk_hz * state->pdata.pll_prd; in tc358743_probe_of()
1984 state->pdata.lineinitcnt = 0xe80; in tc358743_probe_of()
1985 state->pdata.lptxtimecnt = 0x003; in tc358743_probe_of()
1986 /* tclk-preparecnt: 3, tclk-zerocnt: 20 */ in tc358743_probe_of()
1987 state->pdata.tclk_headercnt = 0x1403; in tc358743_probe_of()
1988 state->pdata.tclk_trailcnt = 0x00; in tc358743_probe_of()
1989 /* ths-preparecnt: 3, ths-zerocnt: 1 */ in tc358743_probe_of()
1990 state->pdata.ths_headercnt = 0x0103; in tc358743_probe_of()
1991 state->pdata.twakeup = 0x4882; in tc358743_probe_of()
1992 state->pdata.tclk_postcnt = 0x008; in tc358743_probe_of()
1993 state->pdata.ths_trailcnt = 0x2; in tc358743_probe_of()
1994 state->pdata.hstxvregcnt = 0; in tc358743_probe_of()
1996 state->reset_gpio = devm_gpiod_get_optional(dev, "reset", in tc358743_probe_of()
1998 if (IS_ERR(state->reset_gpio)) { in tc358743_probe_of()
2000 ret = PTR_ERR(state->reset_gpio); in tc358743_probe_of()
2004 if (state->reset_gpio) in tc358743_probe_of()
2021 return -ENODEV; in tc358743_probe_of()
2030 struct tc358743_platform_data *pdata = client->dev.platform_data; in tc358743_probe()
2035 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tc358743_probe()
2036 return -EIO; in tc358743_probe()
2038 client->addr << 1, client->adapter->name); in tc358743_probe()
2040 state = devm_kzalloc(&client->dev, sizeof(struct tc358743_state), in tc358743_probe()
2043 return -ENOMEM; in tc358743_probe()
2045 state->i2c_client = client; in tc358743_probe()
2049 state->pdata = *pdata; in tc358743_probe()
2050 state->bus.flags = 0; in tc358743_probe()
2053 if (err == -ENODEV) in tc358743_probe()
2059 sd = &state->sd; in tc358743_probe()
2061 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in tc358743_probe()
2066 client->addr << 1); in tc358743_probe()
2067 return -ENODEV; in tc358743_probe()
2071 v4l2_ctrl_handler_init(&state->hdl, 3); in tc358743_probe()
2073 state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&state->hdl, NULL, in tc358743_probe()
2077 state->audio_sampling_rate_ctrl = v4l2_ctrl_new_custom(&state->hdl, in tc358743_probe()
2080 state->audio_present_ctrl = v4l2_ctrl_new_custom(&state->hdl, in tc358743_probe()
2083 sd->ctrl_handler = &state->hdl; in tc358743_probe()
2084 if (state->hdl.error) { in tc358743_probe()
2085 err = state->hdl.error; in tc358743_probe()
2090 err = -ENODEV; in tc358743_probe()
2094 state->pad.flags = MEDIA_PAD_FL_SOURCE; in tc358743_probe()
2095 sd->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; in tc358743_probe()
2096 err = media_entity_pads_init(&sd->entity, 1, &state->pad); in tc358743_probe()
2100 state->mbus_fmt_code = MEDIA_BUS_FMT_RGB888_1X24; in tc358743_probe()
2102 sd->dev = &client->dev; in tc358743_probe()
2104 mutex_init(&state->confctl_mutex); in tc358743_probe()
2106 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, in tc358743_probe()
2110 state->cec_adap = cec_allocate_adapter(&tc358743_cec_adap_ops, in tc358743_probe()
2111 state, dev_name(&client->dev), in tc358743_probe()
2113 if (IS_ERR(state->cec_adap)) { in tc358743_probe()
2114 err = PTR_ERR(state->cec_adap); in tc358743_probe()
2128 if (state->i2c_client->irq) { in tc358743_probe()
2129 err = devm_request_threaded_irq(&client->dev, in tc358743_probe()
2130 state->i2c_client->irq, in tc358743_probe()
2137 INIT_WORK(&state->work_i2c_poll, in tc358743_probe()
2139 timer_setup(&state->timer, tc358743_irq_poll_timer, 0); in tc358743_probe()
2140 state->timer.expires = jiffies + in tc358743_probe()
2142 add_timer(&state->timer); in tc358743_probe()
2145 err = cec_register_adapter(state->cec_adap, &client->dev); in tc358743_probe()
2148 cec_delete_adapter(state->cec_adap); in tc358743_probe()
2149 state->cec_adap = NULL; in tc358743_probe()
2156 err = v4l2_ctrl_handler_setup(sd->ctrl_handler); in tc358743_probe()
2164 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in tc358743_probe()
2165 client->addr << 1, client->adapter->name); in tc358743_probe()
2170 cec_unregister_adapter(state->cec_adap); in tc358743_probe()
2171 if (!state->i2c_client->irq) in tc358743_probe()
2172 flush_work(&state->work_i2c_poll); in tc358743_probe()
2173 cancel_delayed_work(&state->delayed_work_enable_hotplug); in tc358743_probe()
2174 mutex_destroy(&state->confctl_mutex); in tc358743_probe()
2176 media_entity_cleanup(&sd->entity); in tc358743_probe()
2177 v4l2_ctrl_handler_free(&state->hdl); in tc358743_probe()
2186 if (!state->i2c_client->irq) { in tc358743_remove()
2187 del_timer_sync(&state->timer); in tc358743_remove()
2188 flush_work(&state->work_i2c_poll); in tc358743_remove()
2190 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); in tc358743_remove()
2191 cec_unregister_adapter(state->cec_adap); in tc358743_remove()
2194 mutex_destroy(&state->confctl_mutex); in tc358743_remove()
2195 media_entity_cleanup(&sd->entity); in tc358743_remove()
2196 v4l2_ctrl_handler_free(&state->hdl); in tc358743_remove()