Lines Matching +full:1 +full:- +full:sd
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");
73 struct v4l2_subdev sd; member
102 static void tc358743_enable_interrupts(struct v4l2_subdev *sd,
104 static int tc358743_s_ctrl_detect_tx_5v(struct v4l2_subdev *sd);
106 static inline struct tc358743_state *to_state(struct v4l2_subdev *sd) in to_state() argument
108 return container_of(sd, struct tc358743_state, sd); in to_state()
111 /* --------------- I2C --------------- */
113 static void i2c_rd(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) in i2c_rd() argument
115 struct tc358743_state *state = to_state(sd); in i2c_rd()
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()
136 v4l2_err(sd, "%s: reading register 0x%x from 0x%x failed: %d\n", in i2c_rd()
137 __func__, reg, client->addr, err); in i2c_rd()
141 static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) in i2c_wr() argument
143 struct tc358743_state *state = to_state(sd); in i2c_wr()
144 struct i2c_client *client = state->i2c_client; in i2c_wr()
150 n = I2C_MAX_XFER_SIZE - 2; in i2c_wr()
151 v4l2_warn(sd, "i2c wr reg=%04x: len=%d is too big!\n", in i2c_wr()
155 msg.addr = client->addr; in i2c_wr()
161 data[1] = reg & 0xff; in i2c_wr()
166 err = i2c_transfer(client->adapter, &msg, 1); in i2c_wr()
167 if (err != 1) { in i2c_wr()
168 v4l2_err(sd, "%s: writing register 0x%x from 0x%x failed: %d\n", in i2c_wr()
169 __func__, reg, client->addr, err); in i2c_wr()
177 case 1: in i2c_wr()
178 v4l2_info(sd, "I2C write 0x%04x = 0x%02x", in i2c_wr()
182 v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x", in i2c_wr()
186 v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x%02x%02x", in i2c_wr()
190 v4l2_info(sd, "I2C write %d bytes from address 0x%04x\n", in i2c_wr()
195 static noinline u32 i2c_rdreg(struct v4l2_subdev *sd, u16 reg, u32 n) in i2c_rdreg() argument
199 i2c_rd(sd, reg, (u8 __force *)&val, n); in i2c_rdreg()
204 static noinline void i2c_wrreg(struct v4l2_subdev *sd, u16 reg, u32 val, u32 n) in i2c_wrreg() argument
208 i2c_wr(sd, reg, (u8 __force *)&raw, n); in i2c_wrreg()
211 static u8 i2c_rd8(struct v4l2_subdev *sd, u16 reg) in i2c_rd8() argument
213 return i2c_rdreg(sd, reg, 1); in i2c_rd8()
216 static void i2c_wr8(struct v4l2_subdev *sd, u16 reg, u8 val) in i2c_wr8() argument
218 i2c_wrreg(sd, reg, val, 1); in i2c_wr8()
221 static void i2c_wr8_and_or(struct v4l2_subdev *sd, u16 reg, in i2c_wr8_and_or() argument
224 i2c_wrreg(sd, reg, (i2c_rdreg(sd, reg, 1) & mask) | val, 1); in i2c_wr8_and_or()
227 static u16 i2c_rd16(struct v4l2_subdev *sd, u16 reg) in i2c_rd16() argument
229 return i2c_rdreg(sd, reg, 2); in i2c_rd16()
232 static void i2c_wr16(struct v4l2_subdev *sd, u16 reg, u16 val) in i2c_wr16() argument
234 i2c_wrreg(sd, reg, val, 2); in i2c_wr16()
237 static void i2c_wr16_and_or(struct v4l2_subdev *sd, u16 reg, u16 mask, u16 val) in i2c_wr16_and_or() argument
239 i2c_wrreg(sd, reg, (i2c_rdreg(sd, reg, 2) & mask) | val, 2); in i2c_wr16_and_or()
242 static u32 i2c_rd32(struct v4l2_subdev *sd, u16 reg) in i2c_rd32() argument
244 return i2c_rdreg(sd, reg, 4); in i2c_rd32()
247 static void i2c_wr32(struct v4l2_subdev *sd, u16 reg, u32 val) in i2c_wr32() argument
249 i2c_wrreg(sd, reg, val, 4); in i2c_wr32()
252 /* --------------- STATUS --------------- */
254 static inline bool is_hdmi(struct v4l2_subdev *sd) in is_hdmi() argument
256 return i2c_rd8(sd, SYS_STATUS) & MASK_S_HDMI; in is_hdmi()
259 static inline bool tx_5v_power_present(struct v4l2_subdev *sd) in tx_5v_power_present() argument
261 return i2c_rd8(sd, SYS_STATUS) & MASK_S_DDC5V; in tx_5v_power_present()
264 static inline bool no_signal(struct v4l2_subdev *sd) in no_signal() argument
266 return !(i2c_rd8(sd, SYS_STATUS) & MASK_S_TMDS); in no_signal()
269 static inline bool no_sync(struct v4l2_subdev *sd) in no_sync() argument
271 return !(i2c_rd8(sd, SYS_STATUS) & MASK_S_SYNC); in no_sync()
274 static inline bool audio_present(struct v4l2_subdev *sd) in audio_present() argument
276 return i2c_rd8(sd, AU_STATUS0) & MASK_S_A_SAMPLE; in audio_present()
279 static int get_audio_sampling_rate(struct v4l2_subdev *sd) in get_audio_sampling_rate() argument
287 if (no_signal(sd)) in get_audio_sampling_rate()
290 return code_to_rate[i2c_rd8(sd, FS_SET) & MASK_FS]; in get_audio_sampling_rate()
293 /* --------------- TIMINGS --------------- */
300 return DIV_ROUND_CLOSEST((unsigned)t->pixelclock, in fps()
304 static int tc358743_get_detected_timings(struct v4l2_subdev *sd, in tc358743_get_detected_timings() argument
307 struct v4l2_bt_timings *bt = &timings->bt; in tc358743_get_detected_timings()
312 if (no_signal(sd)) { in tc358743_get_detected_timings()
313 v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__); in tc358743_get_detected_timings()
314 return -ENOLINK; in tc358743_get_detected_timings()
316 if (no_sync(sd)) { in tc358743_get_detected_timings()
317 v4l2_dbg(1, debug, sd, "%s: no sync on signal\n", __func__); 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()
325 width = ((i2c_rd8(sd, DE_WIDTH_H_HI) & 0x1f) << 8) + in tc358743_get_detected_timings()
326 i2c_rd8(sd, DE_WIDTH_H_LO); in tc358743_get_detected_timings()
327 height = ((i2c_rd8(sd, DE_WIDTH_V_HI) & 0x1f) << 8) + in tc358743_get_detected_timings()
328 i2c_rd8(sd, DE_WIDTH_V_LO); in tc358743_get_detected_timings()
329 frame_width = ((i2c_rd8(sd, H_SIZE_HI) & 0x1f) << 8) + in tc358743_get_detected_timings()
330 i2c_rd8(sd, H_SIZE_LO); in tc358743_get_detected_timings()
331 frame_height = (((i2c_rd8(sd, V_SIZE_HI) & 0x3f) << 8) + in tc358743_get_detected_timings()
332 i2c_rd8(sd, V_SIZE_LO)) / 2; in tc358743_get_detected_timings()
335 frame_interval = ((i2c_rd8(sd, FV_CNT_HI) & 0x3) << 8) + in tc358743_get_detected_timings()
336 i2c_rd8(sd, FV_CNT_LO); 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() local
363 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc358743_delayed_work_enable_hotplug()
365 i2c_wr8_and_or(sd, HPD_CTL, ~MASK_HPD_OUT0, MASK_HPD_OUT0); in tc358743_delayed_work_enable_hotplug()
368 static void tc358743_set_hdmi_hdcp(struct v4l2_subdev *sd, bool enable) in tc358743_set_hdmi_hdcp() argument
370 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? in tc358743_set_hdmi_hdcp()
374 i2c_wr8_and_or(sd, HDCP_REG3, ~KEY_RD_CMD, KEY_RD_CMD); in tc358743_set_hdmi_hdcp()
376 i2c_wr8_and_or(sd, HDCP_MODE, ~MASK_MANUAL_AUTHENTICATION, 0); in tc358743_set_hdmi_hdcp()
378 i2c_wr8_and_or(sd, HDCP_REG1, 0xff, in tc358743_set_hdmi_hdcp()
382 i2c_wr8_and_or(sd, HDCP_REG2, ~MASK_AUTO_P3_RESET, in tc358743_set_hdmi_hdcp()
385 i2c_wr8_and_or(sd, HDCP_MODE, ~MASK_MANUAL_AUTHENTICATION, in tc358743_set_hdmi_hdcp()
390 static void tc358743_disable_edid(struct v4l2_subdev *sd) in tc358743_disable_edid() argument
392 struct tc358743_state *state = to_state(sd); in tc358743_disable_edid()
394 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc358743_disable_edid()
396 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); in tc358743_disable_edid()
400 i2c_wr8_and_or(sd, HPD_CTL, ~MASK_HPD_OUT0, 0x0); in tc358743_disable_edid()
403 static void tc358743_enable_edid(struct v4l2_subdev *sd) in tc358743_enable_edid() argument
405 struct tc358743_state *state = to_state(sd); in tc358743_enable_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()
409 tc358743_s_ctrl_detect_tx_5v(sd); in tc358743_enable_edid()
413 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc358743_enable_edid()
417 schedule_delayed_work(&state->delayed_work_enable_hotplug, HZ / 10); in tc358743_enable_edid()
419 tc358743_enable_interrupts(sd, true); in tc358743_enable_edid()
420 tc358743_s_ctrl_detect_tx_5v(sd); in tc358743_enable_edid()
423 static void tc358743_erase_bksv(struct v4l2_subdev *sd) in tc358743_erase_bksv() argument
428 i2c_wr8(sd, BKSV + i, 0); in tc358743_erase_bksv()
431 /* --------------- AVI infoframe --------------- */
433 static void print_avi_infoframe(struct v4l2_subdev *sd) in print_avi_infoframe() argument
435 struct i2c_client *client = v4l2_get_subdevdata(sd); in print_avi_infoframe()
436 struct device *dev = &client->dev; in print_avi_infoframe()
440 if (!is_hdmi(sd)) { in print_avi_infoframe()
441 v4l2_info(sd, "DVI-D signal - AVI infoframe not supported\n"); in print_avi_infoframe()
445 i2c_rd(sd, PK_AVI_0HEAD, buffer, HDMI_INFOFRAME_SIZE(AVI)); in print_avi_infoframe()
448 v4l2_err(sd, "%s: unpack of AVI infoframe failed\n", __func__); in print_avi_infoframe()
455 /* --------------- CTRLS --------------- */
457 static int tc358743_s_ctrl_detect_tx_5v(struct v4l2_subdev *sd) in tc358743_s_ctrl_detect_tx_5v() argument
459 struct tc358743_state *state = to_state(sd); in tc358743_s_ctrl_detect_tx_5v()
461 return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, in tc358743_s_ctrl_detect_tx_5v()
462 tx_5v_power_present(sd)); in tc358743_s_ctrl_detect_tx_5v()
465 static int tc358743_s_ctrl_audio_sampling_rate(struct v4l2_subdev *sd) in tc358743_s_ctrl_audio_sampling_rate() argument
467 struct tc358743_state *state = to_state(sd); in tc358743_s_ctrl_audio_sampling_rate()
469 return v4l2_ctrl_s_ctrl(state->audio_sampling_rate_ctrl, in tc358743_s_ctrl_audio_sampling_rate()
470 get_audio_sampling_rate(sd)); in tc358743_s_ctrl_audio_sampling_rate()
473 static int tc358743_s_ctrl_audio_present(struct v4l2_subdev *sd) in tc358743_s_ctrl_audio_present() argument
475 struct tc358743_state *state = to_state(sd); in tc358743_s_ctrl_audio_present()
477 return v4l2_ctrl_s_ctrl(state->audio_present_ctrl, in tc358743_s_ctrl_audio_present()
478 audio_present(sd)); in tc358743_s_ctrl_audio_present()
481 static int tc358743_update_controls(struct v4l2_subdev *sd) in tc358743_update_controls() argument
485 ret |= tc358743_s_ctrl_detect_tx_5v(sd); in tc358743_update_controls()
486 ret |= tc358743_s_ctrl_audio_sampling_rate(sd); in tc358743_update_controls()
487 ret |= tc358743_s_ctrl_audio_present(sd); in tc358743_update_controls()
492 /* --------------- INIT --------------- */
494 static void tc358743_reset_phy(struct v4l2_subdev *sd) in tc358743_reset_phy() argument
496 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in tc358743_reset_phy()
498 i2c_wr8_and_or(sd, PHY_RST, ~MASK_RESET_CTRL, 0); in tc358743_reset_phy()
499 i2c_wr8_and_or(sd, PHY_RST, ~MASK_RESET_CTRL, MASK_RESET_CTRL); in tc358743_reset_phy()
502 static void tc358743_reset(struct v4l2_subdev *sd, uint16_t mask) in tc358743_reset() argument
504 u16 sysctl = i2c_rd16(sd, SYSCTL); in tc358743_reset()
506 i2c_wr16(sd, SYSCTL, sysctl | mask); in tc358743_reset()
507 i2c_wr16(sd, SYSCTL, sysctl & ~mask); in tc358743_reset()
510 static inline void tc358743_sleep_mode(struct v4l2_subdev *sd, bool enable) in tc358743_sleep_mode() argument
512 i2c_wr16_and_or(sd, SYSCTL, ~MASK_SLEEP, in tc358743_sleep_mode()
516 static inline void enable_stream(struct v4l2_subdev *sd, bool enable) in enable_stream() argument
518 struct tc358743_state *state = to_state(sd); in enable_stream()
520 v4l2_dbg(3, debug, sd, "%s: %sable\n", in enable_stream()
525 * LP11->HS. Set to non-continuous mode to enable clock lane in enable_stream()
527 i2c_wr32(sd, TXOPTIONCNTRL, 0); in enable_stream()
528 /* Set to continuous mode to trigger LP11->HS transition */ in enable_stream()
529 i2c_wr32(sd, TXOPTIONCNTRL, MASK_CONTCLKMODE); in enable_stream()
531 i2c_wr8(sd, VI_MUTE, MASK_AUTO_MUTE); in enable_stream()
535 i2c_wr8(sd, VI_MUTE, MASK_AUTO_MUTE | MASK_VI_MUTE); in enable_stream()
538 mutex_lock(&state->confctl_mutex); in enable_stream()
539 i2c_wr16_and_or(sd, CONFCTL, ~(MASK_VBUFEN | MASK_ABUFEN), in enable_stream()
541 mutex_unlock(&state->confctl_mutex); in enable_stream()
544 static void tc358743_set_pll(struct v4l2_subdev *sd) in tc358743_set_pll() argument
546 struct tc358743_state *state = to_state(sd); in tc358743_set_pll()
547 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_pll()
548 u16 pllctl0 = i2c_rd16(sd, PLLCTL0); in tc358743_set_pll()
549 u16 pllctl1 = i2c_rd16(sd, PLLCTL1); 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()
554 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc358743_set_pll()
570 v4l2_dbg(1, debug, sd, "%s: updating PLL clock\n", __func__); in tc358743_set_pll()
571 tc358743_sleep_mode(sd, true); in tc358743_set_pll()
572 i2c_wr16(sd, PLLCTL0, pllctl0_new); in tc358743_set_pll()
573 i2c_wr16_and_or(sd, PLLCTL1, in tc358743_set_pll()
578 i2c_wr16_and_or(sd, PLLCTL1, ~MASK_CKEN, MASK_CKEN); in tc358743_set_pll()
579 tc358743_sleep_mode(sd, false); in tc358743_set_pll()
583 static void tc358743_set_ref_clk(struct v4l2_subdev *sd) in tc358743_set_ref_clk() argument
585 struct tc358743_state *state = to_state(sd); in tc358743_set_ref_clk()
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()
598 i2c_wr8(sd, SYS_FREQ0, sys_freq & 0x00ff); in tc358743_set_ref_clk()
599 i2c_wr8(sd, SYS_FREQ1, (sys_freq & 0xff00) >> 8); in tc358743_set_ref_clk()
601 i2c_wr8_and_or(sd, PHY_CTL0, ~MASK_PHY_SYSCLK_IND, 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()
606 i2c_wr8(sd, FH_MIN0, fh_min & 0x00ff); in tc358743_set_ref_clk()
607 i2c_wr8(sd, FH_MIN1, (fh_min & 0xff00) >> 8); in tc358743_set_ref_clk()
610 i2c_wr8(sd, FH_MAX0, fh_max & 0x00ff); in tc358743_set_ref_clk()
611 i2c_wr8(sd, FH_MAX1, (fh_max & 0xff00) >> 8); in tc358743_set_ref_clk()
613 lockdet_ref = pdata->refclk_hz / 100; in tc358743_set_ref_clk()
614 i2c_wr8(sd, LOCKDET_REF0, lockdet_ref & 0x0000ff); in tc358743_set_ref_clk()
615 i2c_wr8(sd, LOCKDET_REF1, (lockdet_ref & 0x00ff00) >> 8); in tc358743_set_ref_clk()
616 i2c_wr8(sd, LOCKDET_REF2, (lockdet_ref & 0x0f0000) >> 16); in tc358743_set_ref_clk()
618 i2c_wr8_and_or(sd, NCO_F0_MOD, ~MASK_NCO_F0_MOD, in tc358743_set_ref_clk()
619 (pdata->refclk_hz == 27000000) ? in tc358743_set_ref_clk()
628 i2c_wr16(sd, CECHCLK, cec_freq); in tc358743_set_ref_clk()
629 i2c_wr16(sd, CECLCLK, cec_freq); in tc358743_set_ref_clk()
632 static void tc358743_set_csi_color_space(struct v4l2_subdev *sd) in tc358743_set_csi_color_space() argument
634 struct tc358743_state *state = to_state(sd); in tc358743_set_csi_color_space()
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()
639 i2c_wr8_and_or(sd, VOUT_SET2, in tc358743_set_csi_color_space()
642 i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, in tc358743_set_csi_color_space()
644 mutex_lock(&state->confctl_mutex); in tc358743_set_csi_color_space()
645 i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, 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()
651 i2c_wr8_and_or(sd, VOUT_SET2, in tc358743_set_csi_color_space()
654 i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, in tc358743_set_csi_color_space()
656 mutex_lock(&state->confctl_mutex); in tc358743_set_csi_color_space()
657 i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, 0); in tc358743_set_csi_color_space()
658 mutex_unlock(&state->confctl_mutex); in tc358743_set_csi_color_space()
661 v4l2_dbg(2, debug, sd, "%s: Unsupported format code 0x%x\n", in tc358743_set_csi_color_space()
662 __func__, state->mbus_fmt_code); in tc358743_set_csi_color_space()
666 static unsigned tc358743_num_csi_lanes_needed(struct v4l2_subdev *sd) in tc358743_num_csi_lanes_needed() argument
668 struct tc358743_state *state = to_state(sd); in tc358743_num_csi_lanes_needed()
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()
679 static void tc358743_set_csi(struct v4l2_subdev *sd) in tc358743_set_csi() argument
681 struct tc358743_state *state = to_state(sd); in tc358743_set_csi()
682 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_csi()
683 unsigned lanes = tc358743_num_csi_lanes_needed(sd); in tc358743_set_csi()
685 v4l2_dbg(3, debug, sd, "%s:\n", __func__); in tc358743_set_csi()
687 state->csi_lanes_in_use = lanes; in tc358743_set_csi()
689 tc358743_reset(sd, MASK_CTXRST); in tc358743_set_csi()
691 if (lanes < 1) in tc358743_set_csi()
692 i2c_wr32(sd, CLW_CNTRL, MASK_CLW_LANEDISABLE); in tc358743_set_csi()
693 if (lanes < 1) in tc358743_set_csi()
694 i2c_wr32(sd, D0W_CNTRL, MASK_D0W_LANEDISABLE); in tc358743_set_csi()
696 i2c_wr32(sd, D1W_CNTRL, MASK_D1W_LANEDISABLE); in tc358743_set_csi()
698 i2c_wr32(sd, D2W_CNTRL, MASK_D2W_LANEDISABLE); in tc358743_set_csi()
700 i2c_wr32(sd, D3W_CNTRL, MASK_D3W_LANEDISABLE); 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()
712 i2c_wr32(sd, HSTXVREGEN, in tc358743_set_csi()
715 ((lanes > 1) ? MASK_D1M_HSTXVREGEN : 0x0) | in tc358743_set_csi()
719 i2c_wr32(sd, TXOPTIONCNTRL, (state->bus.flags & in tc358743_set_csi()
721 i2c_wr32(sd, STARTCNTRL, MASK_START); in tc358743_set_csi()
722 i2c_wr32(sd, CSI_START, MASK_STRT); in tc358743_set_csi()
724 i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | in tc358743_set_csi()
732 i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | in tc358743_set_csi()
736 i2c_wr32(sd, CSI_CONFW, MASK_MODE_CLEAR | in tc358743_set_csi()
739 i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | in tc358743_set_csi()
743 static void tc358743_set_hdmi_phy(struct v4l2_subdev *sd) in tc358743_set_hdmi_phy() argument
745 struct tc358743_state *state = to_state(sd); in tc358743_set_hdmi_phy()
746 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_set_hdmi_phy()
750 i2c_wr8_and_or(sd, PHY_EN, ~MASK_ENABLE_PHY, 0x0); in tc358743_set_hdmi_phy()
751 i2c_wr8(sd, PHY_CTL1, SET_PHY_AUTO_RST1_US(1600) | in tc358743_set_hdmi_phy()
752 SET_FREQ_RANGE_MODE_CYCLES(1)); in tc358743_set_hdmi_phy()
753 i2c_wr8_and_or(sd, PHY_CTL2, ~MASK_PHY_AUTO_RSTn, 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()
760 i2c_wr8(sd, PHY_BIAS, 0x40); in tc358743_set_hdmi_phy()
761 i2c_wr8(sd, PHY_CSQ, SET_CSQ_CNT_LEVEL(0x0a)); in tc358743_set_hdmi_phy()
762 i2c_wr8(sd, AVM_CTL, 45); in tc358743_set_hdmi_phy()
763 i2c_wr8_and_or(sd, HDMI_DET, ~MASK_HDMI_DET_V, in tc358743_set_hdmi_phy()
764 pdata->hdmi_detection_delay << 4); in tc358743_set_hdmi_phy()
765 i2c_wr8_and_or(sd, HV_RST, ~(MASK_H_PI_RST | MASK_V_PI_RST), 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()
770 i2c_wr8_and_or(sd, PHY_EN, ~MASK_ENABLE_PHY, MASK_ENABLE_PHY); in tc358743_set_hdmi_phy()
773 static void tc358743_set_hdmi_audio(struct v4l2_subdev *sd) in tc358743_set_hdmi_audio() argument
775 struct tc358743_state *state = to_state(sd); in tc358743_set_hdmi_audio()
778 i2c_wr8(sd, FORCE_MUTE, 0x00); in tc358743_set_hdmi_audio()
779 i2c_wr8(sd, AUTO_CMD0, MASK_AUTO_MUTE7 | MASK_AUTO_MUTE6 | in tc358743_set_hdmi_audio()
782 i2c_wr8(sd, AUTO_CMD1, MASK_AUTO_MUTE9); in tc358743_set_hdmi_audio()
783 i2c_wr8(sd, AUTO_CMD2, MASK_AUTO_PLAY3 | MASK_AUTO_PLAY2); in tc358743_set_hdmi_audio()
784 i2c_wr8(sd, BUFINIT_START, SET_BUFINIT_START_MS(500)); in tc358743_set_hdmi_audio()
785 i2c_wr8(sd, FS_MUTE, 0x00); in tc358743_set_hdmi_audio()
786 i2c_wr8(sd, FS_IMODE, MASK_NLPCM_SMODE | MASK_FS_SMODE); in tc358743_set_hdmi_audio()
787 i2c_wr8(sd, ACR_MODE, MASK_CTS_MODE); in tc358743_set_hdmi_audio()
788 i2c_wr8(sd, ACR_MDF0, MASK_ACR_L2MDF_1976_PPM | MASK_ACR_L1MDF_976_PPM); in tc358743_set_hdmi_audio()
789 i2c_wr8(sd, ACR_MDF1, MASK_ACR_L3MDF_3906_PPM); in tc358743_set_hdmi_audio()
790 i2c_wr8(sd, SDO_MODE1, MASK_SDO_FMT_I2S); in tc358743_set_hdmi_audio()
791 i2c_wr8(sd, DIV_MODE, SET_DIV_DLY_MS(100)); in tc358743_set_hdmi_audio()
793 mutex_lock(&state->confctl_mutex); in tc358743_set_hdmi_audio()
794 i2c_wr16_and_or(sd, CONFCTL, 0xffff, MASK_AUDCHNUM_2 | in tc358743_set_hdmi_audio()
796 mutex_unlock(&state->confctl_mutex); in tc358743_set_hdmi_audio()
799 static void tc358743_set_hdmi_info_frame_mode(struct v4l2_subdev *sd) in tc358743_set_hdmi_info_frame_mode() argument
802 i2c_wr8(sd, PK_INT_MODE, MASK_ISRC2_INT_MODE | MASK_ISRC_INT_MODE | in tc358743_set_hdmi_info_frame_mode()
806 i2c_wr8(sd, NO_PKT_LIMIT, 0x2c); in tc358743_set_hdmi_info_frame_mode()
807 i2c_wr8(sd, NO_PKT_CLR, 0x53); in tc358743_set_hdmi_info_frame_mode()
808 i2c_wr8(sd, ERR_PK_LIMIT, 0x01); in tc358743_set_hdmi_info_frame_mode()
809 i2c_wr8(sd, NO_PKT_LIMIT2, 0x30); in tc358743_set_hdmi_info_frame_mode()
810 i2c_wr8(sd, NO_GDB_LIMIT, 0x10); in tc358743_set_hdmi_info_frame_mode()
813 static void tc358743_initial_setup(struct v4l2_subdev *sd) in tc358743_initial_setup() argument
815 struct tc358743_state *state = to_state(sd); in tc358743_initial_setup()
816 struct tc358743_platform_data *pdata = &state->pdata; in tc358743_initial_setup()
822 i2c_wr16_and_or(sd, SYSCTL, ~(MASK_IRRST | MASK_CECRST), in tc358743_initial_setup()
825 tc358743_reset(sd, MASK_CTXRST | MASK_HDMIRST); in tc358743_initial_setup()
827 tc358743_reset(sd, MASK_CECRST); in tc358743_initial_setup()
829 tc358743_sleep_mode(sd, false); in tc358743_initial_setup()
831 i2c_wr16(sd, FIFOCTL, pdata->fifo_level); in tc358743_initial_setup()
833 tc358743_set_ref_clk(sd); in tc358743_initial_setup()
835 i2c_wr8_and_or(sd, DDC_CTL, ~MASK_DDC5V_MODE, in tc358743_initial_setup()
836 pdata->ddc5v_delay & MASK_DDC5V_MODE); in tc358743_initial_setup()
837 i2c_wr8_and_or(sd, EDID_MODE, ~MASK_EDID_MODE, MASK_EDID_MODE_E_DDC); in tc358743_initial_setup()
839 tc358743_set_hdmi_phy(sd); in tc358743_initial_setup()
840 tc358743_set_hdmi_hdcp(sd, pdata->enable_hdcp); in tc358743_initial_setup()
841 tc358743_set_hdmi_audio(sd); in tc358743_initial_setup()
842 tc358743_set_hdmi_info_frame_mode(sd); in tc358743_initial_setup()
845 i2c_wr8_and_or(sd, VI_MODE, ~MASK_RGB_DVI, 0); in tc358743_initial_setup()
847 i2c_wr8_and_or(sd, VOUT_SET2, ~MASK_VOUTCOLORMODE, in tc358743_initial_setup()
849 i2c_wr8(sd, VOUT_SET3, MASK_VOUT_EXTCNT); 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() local
860 i2c_wr32(sd, CECIMSK, enable ? MASK_CECTIM | MASK_CECRIM : 0); in tc358743_cec_adap_enable()
861 i2c_wr32(sd, CECICLR, MASK_CECTICLR | MASK_CECRICLR); in tc358743_cec_adap_enable()
862 i2c_wr32(sd, CECEN, enable); in tc358743_cec_adap_enable()
864 i2c_wr32(sd, CECREN, MASK_CECREN); 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() local
875 reg = i2c_rd32(sd, CECRCTL1); in tc358743_cec_adap_monitor_all_enable()
880 i2c_wr32(sd, CECRCTL1, reg); 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() local
891 la = i2c_rd32(sd, CECADD); in tc358743_cec_adap_log_addr()
892 la |= 1 << log_addr; in tc358743_cec_adap_log_addr()
894 i2c_wr32(sd, CECADD, la); 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() local
905 i2c_wr32(sd, CECTCTL, 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()
909 i2c_wr32(sd, CECTBUF1 + i * 4, in tc358743_cec_adap_transmit()
910 msg->msg[i] | ((i == msg->len - 1) ? MASK_CECTEOM : 0)); in tc358743_cec_adap_transmit()
911 i2c_wr32(sd, CECTEN, MASK_CECTEN); in tc358743_cec_adap_transmit()
922 static void tc358743_cec_handler(struct v4l2_subdev *sd, u16 intstatus, in tc358743_cec_handler() argument
925 struct tc358743_state *state = to_state(sd); in tc358743_cec_handler()
929 cec_rxint = i2c_rd32(sd, CECRSTAT); in tc358743_cec_handler()
930 cec_txint = i2c_rd32(sd, CECTSTAT); in tc358743_cec_handler()
936 i2c_wr32(sd, CECICLR, clr); in tc358743_cec_handler()
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()
965 v = i2c_rd32(sd, CECRCTR); in tc358743_cec_handler()
970 v = i2c_rd32(sd, CECRBUF1 + i * 4); in tc358743_cec_handler()
973 cec_received_msg(state->cec_adap, &msg); in tc358743_cec_handler()
977 i2c_wr16(sd, INTSTATUS, in tc358743_cec_handler()
983 /* --------------- IRQ --------------- */
985 static void tc358743_format_change(struct v4l2_subdev *sd) in tc358743_format_change() argument
987 struct tc358743_state *state = to_state(sd); in tc358743_format_change()
994 if (tc358743_get_detected_timings(sd, &timings)) { in tc358743_format_change()
995 enable_stream(sd, false); in tc358743_format_change()
997 v4l2_dbg(1, debug, sd, "%s: No signal\n", in tc358743_format_change()
1000 if (!v4l2_match_dv_timings(&state->timings, &timings, 0, false)) in tc358743_format_change()
1001 enable_stream(sd, false); in tc358743_format_change()
1004 v4l2_print_dv_timings(sd->name, in tc358743_format_change()
1009 if (sd->devnode) in tc358743_format_change()
1010 v4l2_subdev_notify_event(sd, &tc358743_ev_fmt); in tc358743_format_change()
1013 static void tc358743_init_interrupts(struct v4l2_subdev *sd) in tc358743_init_interrupts() argument
1019 i2c_wr8(sd, i, 0xff); in tc358743_init_interrupts()
1021 i2c_wr16(sd, INTSTATUS, 0xffff); in tc358743_init_interrupts()
1024 static void tc358743_enable_interrupts(struct v4l2_subdev *sd, in tc358743_enable_interrupts() argument
1027 v4l2_dbg(2, debug, sd, "%s: cable connected = %d\n", __func__, in tc358743_enable_interrupts()
1031 i2c_wr8(sd, SYS_INTM, ~(MASK_M_DDC | MASK_M_DVI_DET | in tc358743_enable_interrupts()
1033 i2c_wr8(sd, CLK_INTM, ~MASK_M_IN_DE_CHG); in tc358743_enable_interrupts()
1034 i2c_wr8(sd, CBIT_INTM, ~(MASK_M_CBIT_FS | MASK_M_AF_LOCK | in tc358743_enable_interrupts()
1036 i2c_wr8(sd, AUDIO_INTM, ~MASK_M_BUFINIT_END); in tc358743_enable_interrupts()
1037 i2c_wr8(sd, MISC_INTM, ~MASK_M_SYNC_CHG); in tc358743_enable_interrupts()
1039 i2c_wr8(sd, SYS_INTM, ~MASK_M_DDC & 0xff); in tc358743_enable_interrupts()
1040 i2c_wr8(sd, CLK_INTM, 0xff); in tc358743_enable_interrupts()
1041 i2c_wr8(sd, CBIT_INTM, 0xff); in tc358743_enable_interrupts()
1042 i2c_wr8(sd, AUDIO_INTM, 0xff); in tc358743_enable_interrupts()
1043 i2c_wr8(sd, MISC_INTM, 0xff); in tc358743_enable_interrupts()
1047 static void tc358743_hdmi_audio_int_handler(struct v4l2_subdev *sd, in tc358743_hdmi_audio_int_handler() argument
1050 u8 audio_int_mask = i2c_rd8(sd, AUDIO_INTM); in tc358743_hdmi_audio_int_handler()
1051 u8 audio_int = i2c_rd8(sd, AUDIO_INT) & ~audio_int_mask; in tc358743_hdmi_audio_int_handler()
1053 i2c_wr8(sd, AUDIO_INT, audio_int); in tc358743_hdmi_audio_int_handler()
1055 v4l2_dbg(3, debug, sd, "%s: AUDIO_INT = 0x%02x\n", __func__, audio_int); in tc358743_hdmi_audio_int_handler()
1057 tc358743_s_ctrl_audio_sampling_rate(sd); in tc358743_hdmi_audio_int_handler()
1058 tc358743_s_ctrl_audio_present(sd); in tc358743_hdmi_audio_int_handler()
1061 static void tc358743_csi_err_int_handler(struct v4l2_subdev *sd, bool *handled) in tc358743_csi_err_int_handler() argument
1063 v4l2_err(sd, "%s: CSI_ERR = 0x%x\n", __func__, i2c_rd32(sd, CSI_ERR)); in tc358743_csi_err_int_handler()
1065 i2c_wr32(sd, CSI_INT_CLR, MASK_ICRER); in tc358743_csi_err_int_handler()
1068 static void tc358743_hdmi_misc_int_handler(struct v4l2_subdev *sd, in tc358743_hdmi_misc_int_handler() argument
1071 u8 misc_int_mask = i2c_rd8(sd, MISC_INTM); in tc358743_hdmi_misc_int_handler()
1072 u8 misc_int = i2c_rd8(sd, MISC_INT) & ~misc_int_mask; in tc358743_hdmi_misc_int_handler()
1074 i2c_wr8(sd, MISC_INT, misc_int); in tc358743_hdmi_misc_int_handler()
1076 v4l2_dbg(3, debug, sd, "%s: MISC_INT = 0x%02x\n", __func__, misc_int); in tc358743_hdmi_misc_int_handler()
1082 if (no_sync(sd) || no_signal(sd)) { in tc358743_hdmi_misc_int_handler()
1083 tc358743_reset_phy(sd); in tc358743_hdmi_misc_int_handler()
1084 tc358743_erase_bksv(sd); in tc358743_hdmi_misc_int_handler()
1087 tc358743_format_change(sd); in tc358743_hdmi_misc_int_handler()
1095 v4l2_err(sd, "%s: Unhandled MISC_INT interrupts: 0x%02x\n", in tc358743_hdmi_misc_int_handler()
1100 static void tc358743_hdmi_cbit_int_handler(struct v4l2_subdev *sd, in tc358743_hdmi_cbit_int_handler() argument
1103 u8 cbit_int_mask = i2c_rd8(sd, CBIT_INTM); in tc358743_hdmi_cbit_int_handler()
1104 u8 cbit_int = i2c_rd8(sd, CBIT_INT) & ~cbit_int_mask; in tc358743_hdmi_cbit_int_handler()
1106 i2c_wr8(sd, CBIT_INT, cbit_int); in tc358743_hdmi_cbit_int_handler()
1108 v4l2_dbg(3, debug, sd, "%s: CBIT_INT = 0x%02x\n", __func__, cbit_int); in tc358743_hdmi_cbit_int_handler()
1112 v4l2_dbg(1, debug, sd, "%s: Audio sample rate changed\n", in tc358743_hdmi_cbit_int_handler()
1114 tc358743_s_ctrl_audio_sampling_rate(sd); in tc358743_hdmi_cbit_int_handler()
1123 v4l2_dbg(1, debug, sd, "%s: Audio present changed\n", in tc358743_hdmi_cbit_int_handler()
1125 tc358743_s_ctrl_audio_present(sd); in tc358743_hdmi_cbit_int_handler()
1133 v4l2_err(sd, "%s: Unhandled CBIT_INT interrupts: 0x%02x\n", in tc358743_hdmi_cbit_int_handler()
1138 static void tc358743_hdmi_clk_int_handler(struct v4l2_subdev *sd, bool *handled) in tc358743_hdmi_clk_int_handler() argument
1140 u8 clk_int_mask = i2c_rd8(sd, CLK_INTM); in tc358743_hdmi_clk_int_handler()
1141 u8 clk_int = i2c_rd8(sd, CLK_INT) & ~clk_int_mask; in tc358743_hdmi_clk_int_handler()
1144 i2c_wr8(sd, CLK_INT, clk_int | 0x80 | MASK_I_OUT_H_CHG); in tc358743_hdmi_clk_int_handler()
1146 v4l2_dbg(3, debug, sd, "%s: CLK_INT = 0x%02x\n", __func__, clk_int); in tc358743_hdmi_clk_int_handler()
1150 v4l2_dbg(1, debug, sd, "%s: DE size or position has changed\n", in tc358743_hdmi_clk_int_handler()
1154 * frequency as the existing (e.g. 1080p25 -> 720p50), the in tc358743_hdmi_clk_int_handler()
1159 if (!no_signal(sd) && !no_sync(sd)) in tc358743_hdmi_clk_int_handler()
1160 tc358743_format_change(sd); in tc358743_hdmi_clk_int_handler()
1168 v4l2_err(sd, "%s: Unhandled CLK_INT interrupts: 0x%02x\n", in tc358743_hdmi_clk_int_handler()
1173 static void tc358743_hdmi_sys_int_handler(struct v4l2_subdev *sd, bool *handled) in tc358743_hdmi_sys_int_handler() argument
1175 struct tc358743_state *state = to_state(sd); in tc358743_hdmi_sys_int_handler()
1176 u8 sys_int_mask = i2c_rd8(sd, SYS_INTM); in tc358743_hdmi_sys_int_handler()
1177 u8 sys_int = i2c_rd8(sd, SYS_INT) & ~sys_int_mask; in tc358743_hdmi_sys_int_handler()
1179 i2c_wr8(sd, SYS_INT, sys_int); in tc358743_hdmi_sys_int_handler()
1181 v4l2_dbg(3, debug, sd, "%s: SYS_INT = 0x%02x\n", __func__, sys_int); in tc358743_hdmi_sys_int_handler()
1184 bool tx_5v = tx_5v_power_present(sd); in tc358743_hdmi_sys_int_handler()
1186 v4l2_dbg(1, debug, sd, "%s: Tx 5V power present: %s\n", in tc358743_hdmi_sys_int_handler()
1190 tc358743_enable_edid(sd); in tc358743_hdmi_sys_int_handler()
1192 tc358743_enable_interrupts(sd, false); in tc358743_hdmi_sys_int_handler()
1193 tc358743_disable_edid(sd); in tc358743_hdmi_sys_int_handler()
1194 memset(&state->timings, 0, sizeof(state->timings)); in tc358743_hdmi_sys_int_handler()
1195 tc358743_erase_bksv(sd); in tc358743_hdmi_sys_int_handler()
1196 tc358743_update_controls(sd); in tc358743_hdmi_sys_int_handler()
1205 v4l2_dbg(1, debug, sd, "%s: HDMI->DVI change detected\n", in tc358743_hdmi_sys_int_handler()
1211 if (no_sync(sd) || no_signal(sd)) { in tc358743_hdmi_sys_int_handler()
1212 tc358743_reset_phy(sd); in tc358743_hdmi_sys_int_handler()
1213 tc358743_erase_bksv(sd); in tc358743_hdmi_sys_int_handler()
1222 v4l2_dbg(1, debug, sd, "%s: DVI->HDMI change detected\n", in tc358743_hdmi_sys_int_handler()
1226 i2c_wr8(sd, ANA_CTL, MASK_APPL_PCSX_NORMAL | MASK_ANALOG_ON); in tc358743_hdmi_sys_int_handler()
1234 v4l2_err(sd, "%s: Unhandled SYS_INT interrupts: 0x%02x\n", in tc358743_hdmi_sys_int_handler()
1239 /* --------------- CORE OPS --------------- */
1241 static int tc358743_log_status(struct v4l2_subdev *sd) in tc358743_log_status() argument
1243 struct tc358743_state *state = to_state(sd); in tc358743_log_status()
1245 uint8_t hdmi_sys_status = i2c_rd8(sd, SYS_STATUS); in tc358743_log_status()
1246 uint16_t sysctl = i2c_rd16(sd, SYSCTL); in tc358743_log_status()
1247 u8 vi_status3 = i2c_rd8(sd, VI_STATUS3); in tc358743_log_status()
1254 v4l2_info(sd, "-----Chip status-----\n"); in tc358743_log_status()
1255 v4l2_info(sd, "Chip ID: 0x%02x\n", in tc358743_log_status()
1256 (i2c_rd16(sd, CHIPID) & MASK_CHIPID) >> 8); in tc358743_log_status()
1257 v4l2_info(sd, "Chip revision: 0x%02x\n", in tc358743_log_status()
1258 i2c_rd16(sd, CHIPID) & MASK_REVID); in tc358743_log_status()
1259 v4l2_info(sd, "Reset: IR: %d, CEC: %d, CSI TX: %d, HDMI: %d\n", in tc358743_log_status()
1264 v4l2_info(sd, "Sleep mode: %s\n", sysctl & MASK_SLEEP ? "on" : "off"); in tc358743_log_status()
1265 v4l2_info(sd, "Cable detected (+5V power): %s\n", in tc358743_log_status()
1267 v4l2_info(sd, "DDC lines enabled: %s\n", in tc358743_log_status()
1268 (i2c_rd8(sd, EDID_MODE) & MASK_EDID_MODE_E_DDC) ? in tc358743_log_status()
1270 v4l2_info(sd, "Hotplug enabled: %s\n", in tc358743_log_status()
1271 (i2c_rd8(sd, HPD_CTL) & MASK_HPD_OUT0) ? in tc358743_log_status()
1273 v4l2_info(sd, "CEC enabled: %s\n", in tc358743_log_status()
1274 (i2c_rd16(sd, CECEN) & MASK_CECEN) ? "yes" : "no"); in tc358743_log_status()
1275 v4l2_info(sd, "-----Signal status-----\n"); in tc358743_log_status()
1276 v4l2_info(sd, "TMDS signal detected: %s\n", in tc358743_log_status()
1278 v4l2_info(sd, "Stable sync signal: %s\n", in tc358743_log_status()
1280 v4l2_info(sd, "PHY PLL locked: %s\n", in tc358743_log_status()
1282 v4l2_info(sd, "PHY DE detected: %s\n", in tc358743_log_status()
1285 if (tc358743_get_detected_timings(sd, &timings)) { in tc358743_log_status()
1286 v4l2_info(sd, "No video detected\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()
1295 v4l2_info(sd, "Lanes needed: %d\n", in tc358743_log_status()
1296 tc358743_num_csi_lanes_needed(sd)); in tc358743_log_status()
1297 v4l2_info(sd, "Lanes in use: %d\n", in tc358743_log_status()
1298 state->csi_lanes_in_use); in tc358743_log_status()
1299 v4l2_info(sd, "Waiting for particular sync signal: %s\n", in tc358743_log_status()
1300 (i2c_rd16(sd, CSI_STATUS) & MASK_S_WSYNC) ? in tc358743_log_status()
1302 v4l2_info(sd, "Transmit mode: %s\n", in tc358743_log_status()
1303 (i2c_rd16(sd, CSI_STATUS) & MASK_S_TXACT) ? in tc358743_log_status()
1305 v4l2_info(sd, "Receive mode: %s\n", in tc358743_log_status()
1306 (i2c_rd16(sd, CSI_STATUS) & MASK_S_RXACT) ? in tc358743_log_status()
1308 v4l2_info(sd, "Stopped: %s\n", in tc358743_log_status()
1309 (i2c_rd16(sd, CSI_STATUS) & MASK_S_HLT) ? in tc358743_log_status()
1311 v4l2_info(sd, "Color space: %s\n", 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()
1318 v4l2_info(sd, "HDCP encrypted content: %s\n", in tc358743_log_status()
1320 v4l2_info(sd, "Input color space: %s %s range\n", in tc358743_log_status()
1321 input_color_space[(vi_status3 & MASK_S_V_COLOR) >> 1], in tc358743_log_status()
1323 if (!is_hdmi(sd)) in tc358743_log_status()
1325 v4l2_info(sd, "AV Mute: %s\n", hdmi_sys_status & MASK_S_AVMUTE ? "on" : in tc358743_log_status()
1327 v4l2_info(sd, "Deep color mode: %d-bits per channel\n", in tc358743_log_status()
1328 deep_color_mode[(i2c_rd8(sd, VI_STATUS1) & in tc358743_log_status()
1330 print_avi_infoframe(sd); in tc358743_log_status()
1336 static void tc358743_print_register_map(struct v4l2_subdev *sd) in tc358743_print_register_map() argument
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()
1366 return 1; in tc358743_get_reg_size()
1369 static int tc358743_g_register(struct v4l2_subdev *sd, in tc358743_g_register() argument
1372 if (reg->reg > 0xffff) { in tc358743_g_register()
1373 tc358743_print_register_map(sd); 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()
1384 static int tc358743_s_register(struct v4l2_subdev *sd, in tc358743_s_register() argument
1387 if (reg->reg > 0xffff) { in tc358743_s_register()
1388 tc358743_print_register_map(sd); 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()
1412 static int tc358743_isr(struct v4l2_subdev *sd, u32 status, bool *handled) in tc358743_isr() argument
1414 u16 intstatus = i2c_rd16(sd, INTSTATUS); in tc358743_isr()
1416 v4l2_dbg(1, debug, sd, "%s: IntStatus = 0x%04x\n", __func__, intstatus); in tc358743_isr()
1419 u8 hdmi_int0 = i2c_rd8(sd, HDMI_INT0); in tc358743_isr()
1420 u8 hdmi_int1 = i2c_rd8(sd, HDMI_INT1); in tc358743_isr()
1423 tc358743_hdmi_misc_int_handler(sd, handled); in tc358743_isr()
1425 tc358743_hdmi_cbit_int_handler(sd, handled); in tc358743_isr()
1427 tc358743_hdmi_clk_int_handler(sd, handled); in tc358743_isr()
1429 tc358743_hdmi_sys_int_handler(sd, handled); in tc358743_isr()
1431 tc358743_hdmi_audio_int_handler(sd, handled); in tc358743_isr()
1433 i2c_wr16(sd, INTSTATUS, MASK_HDMI_INT); in tc358743_isr()
1439 tc358743_cec_handler(sd, intstatus, handled); in tc358743_isr()
1440 i2c_wr16(sd, INTSTATUS, in tc358743_isr()
1447 u32 csi_int = i2c_rd32(sd, CSI_INT); in tc358743_isr()
1450 tc358743_csi_err_int_handler(sd, handled); in tc358743_isr()
1452 i2c_wr16(sd, INTSTATUS, MASK_CSI_INT); in tc358743_isr()
1455 intstatus = i2c_rd16(sd, INTSTATUS); in tc358743_isr()
1457 v4l2_dbg(1, debug, sd, in tc358743_isr()
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()
1498 static int tc358743_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, in tc358743_subscribe_event() argument
1501 switch (sub->type) { in tc358743_subscribe_event()
1503 return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); in tc358743_subscribe_event()
1505 return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); in tc358743_subscribe_event()
1507 return -EINVAL; in tc358743_subscribe_event()
1511 /* --------------- VIDEO OPS --------------- */
1513 static int tc358743_g_input_status(struct v4l2_subdev *sd, u32 *status) in tc358743_g_input_status() argument
1516 *status |= no_signal(sd) ? V4L2_IN_ST_NO_SIGNAL : 0; in tc358743_g_input_status()
1517 *status |= no_sync(sd) ? V4L2_IN_ST_NO_SYNC : 0; in tc358743_g_input_status()
1519 v4l2_dbg(1, debug, sd, "%s: status = 0x%x\n", __func__, *status); in tc358743_g_input_status()
1524 static int tc358743_s_dv_timings(struct v4l2_subdev *sd, unsigned int pad, in tc358743_s_dv_timings() argument
1527 struct tc358743_state *state = to_state(sd); in tc358743_s_dv_timings()
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()
1540 v4l2_dbg(1, debug, sd, "%s: no change\n", __func__); in tc358743_s_dv_timings()
1546 v4l2_dbg(1, debug, sd, "%s: timings out of range\n", __func__); in tc358743_s_dv_timings()
1547 return -ERANGE; in tc358743_s_dv_timings()
1550 state->timings = *timings; in tc358743_s_dv_timings()
1552 enable_stream(sd, false); in tc358743_s_dv_timings()
1553 tc358743_set_pll(sd); in tc358743_s_dv_timings()
1554 tc358743_set_csi(sd); in tc358743_s_dv_timings()
1559 static int tc358743_g_dv_timings(struct v4l2_subdev *sd, unsigned int pad, in tc358743_g_dv_timings() argument
1562 struct tc358743_state *state = to_state(sd); in tc358743_g_dv_timings()
1565 return -EINVAL; in tc358743_g_dv_timings()
1567 *timings = state->timings; in tc358743_g_dv_timings()
1572 static int tc358743_enum_dv_timings(struct v4l2_subdev *sd, in tc358743_enum_dv_timings() argument
1575 if (timings->pad != 0) in tc358743_enum_dv_timings()
1576 return -EINVAL; in tc358743_enum_dv_timings()
1582 static int tc358743_query_dv_timings(struct v4l2_subdev *sd, unsigned int pad, in tc358743_query_dv_timings() argument
1588 return -EINVAL; in tc358743_query_dv_timings()
1590 ret = tc358743_get_detected_timings(sd, timings); in tc358743_query_dv_timings()
1595 v4l2_print_dv_timings(sd->name, "tc358743_query_dv_timings: ", in tc358743_query_dv_timings()
1600 v4l2_dbg(1, debug, sd, "%s: timings out of range\n", __func__); in tc358743_query_dv_timings()
1601 return -ERANGE; in tc358743_query_dv_timings()
1607 static int tc358743_dv_timings_cap(struct v4l2_subdev *sd, in tc358743_dv_timings_cap() argument
1610 if (cap->pad != 0) in tc358743_dv_timings_cap()
1611 return -EINVAL; in tc358743_dv_timings_cap()
1618 static int tc358743_get_mbus_config(struct v4l2_subdev *sd, in tc358743_get_mbus_config() argument
1622 struct tc358743_state *state = to_state(sd); in tc358743_get_mbus_config()
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()
1633 static int tc358743_s_stream(struct v4l2_subdev *sd, int enable) in tc358743_s_stream() argument
1635 enable_stream(sd, enable); in tc358743_s_stream()
1637 /* Put all lanes in LP-11 state (STOPSTATE) */ in tc358743_s_stream()
1638 tc358743_set_csi(sd); in tc358743_s_stream()
1644 /* --------------- PAD OPS --------------- */
1646 static int tc358743_enum_mbus_code(struct v4l2_subdev *sd, in tc358743_enum_mbus_code() argument
1650 switch (code->index) { in tc358743_enum_mbus_code()
1652 code->code = MEDIA_BUS_FMT_RGB888_1X24; in tc358743_enum_mbus_code()
1654 case 1: 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()
1663 static int tc358743_get_fmt(struct v4l2_subdev *sd, in tc358743_get_fmt() argument
1667 struct tc358743_state *state = to_state(sd); in tc358743_get_fmt()
1668 u8 vi_rep = i2c_rd8(sd, VI_REP); in tc358743_get_fmt()
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()
1699 static int tc358743_set_fmt(struct v4l2_subdev *sd, in tc358743_set_fmt() argument
1703 struct tc358743_state *state = to_state(sd); in tc358743_set_fmt()
1705 u32 code = format->format.code; /* is overwritten by get_fmt */ in tc358743_set_fmt()
1706 int ret = tc358743_get_fmt(sd, sd_state, format); 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()
1726 enable_stream(sd, false); in tc358743_set_fmt()
1727 tc358743_set_pll(sd); in tc358743_set_fmt()
1728 tc358743_set_csi(sd); in tc358743_set_fmt()
1729 tc358743_set_csi_color_space(sd); in tc358743_set_fmt()
1734 static int tc358743_g_edid(struct v4l2_subdev *sd, in tc358743_g_edid() argument
1737 struct tc358743_state *state = to_state(sd); in tc358743_g_edid()
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()
1765 static int tc358743_s_edid(struct v4l2_subdev *sd, in tc358743_s_edid() argument
1768 struct tc358743_state *state = to_state(sd); in tc358743_s_edid()
1769 u16 edid_len = edid->blocks * EDID_BLOCK_SIZE; in tc358743_s_edid()
1774 v4l2_dbg(2, debug, sd, "%s, pad %d, start block %d, blocks %d\n", 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()
1796 tc358743_disable_edid(sd); in tc358743_s_edid()
1798 i2c_wr8(sd, EDID_LEN1, edid_len & 0xff); in tc358743_s_edid()
1799 i2c_wr8(sd, EDID_LEN2, edid_len >> 8); 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()
1813 if (tx_5v_power_present(sd)) in tc358743_s_edid()
1814 tc358743_enable_edid(sd); in tc358743_s_edid()
1819 /* -------------------------------------------------------------------------- */
1857 /* --------------- CUSTOM CTRLS --------------- */
1865 .step = 1,
1875 .max = 1,
1876 .step = 1,
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()
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()
2031 struct v4l2_subdev *sd; in tc358743_probe() local
2035 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tc358743_probe()
2036 return -EIO; in tc358743_probe()
2037 v4l_dbg(1, debug, client, "chip found @ 0x%x (%s)\n", 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()
2060 v4l2_i2c_subdev_init(sd, client, &tc358743_ops); in tc358743_probe()
2061 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in tc358743_probe()
2064 if ((i2c_rd16(sd, CHIPID) & MASK_CHIPID) != 0) { in tc358743_probe()
2065 v4l2_info(sd, "not a TC358743 on address 0x%x\n", 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()
2074 V4L2_CID_DV_RX_POWER_PRESENT, 0, 1, 0, 0); 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()
2089 if (tc358743_update_controls(sd)) { 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()
2120 tc358743_initial_setup(sd); in tc358743_probe()
2122 tc358743_s_dv_timings(sd, 0, &default_timing); in tc358743_probe()
2124 tc358743_set_csi_color_space(sd); in tc358743_probe()
2126 tc358743_init_interrupts(sd); 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()
2153 tc358743_enable_interrupts(sd, tx_5v_power_present(sd)); in tc358743_probe()
2154 i2c_wr16(sd, INTMASK, ~irq_mask); in tc358743_probe()
2156 err = v4l2_ctrl_handler_setup(sd->ctrl_handler); in tc358743_probe()
2160 err = v4l2_async_register_subdev(sd); 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()
2183 struct v4l2_subdev *sd = i2c_get_clientdata(client); in tc358743_remove() local
2184 struct tc358743_state *state = to_state(sd); in tc358743_remove()
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()
2192 v4l2_async_unregister_subdev(sd); in tc358743_remove()
2193 v4l2_device_unregister_subdev(sd); 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()