Lines Matching +full:no +full:- +full:sd

2  * tc35874x - Toshiba HDMI to CSI-2 bridge
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * REF_01 - Toshiba, TC358743XBG (H2C), Functional Specification, Rev 0.60
25 * REF_02 - Toshiba, TC358743XBG_HDMI-CSI_Tv11p_nm.xls
26 * REF_02 - Toshiba, TC358749XBG (H2C+), Functional Specification, Rev 0.74
41 #include <linux/v4l2-dv-timings.h>
45 #include <linux/rk-camera-module.h>
46 #include <media/v4l2-dv-timings.h>
47 #include <media/v4l2-device.h>
48 #include <media/v4l2-ctrls.h>
49 #include <media/v4l2-event.h>
50 #include <media/v4l2-fwnode.h>
57 MODULE_PARM_DESC(debug, "debug level (0-3)");
59 MODULE_DESCRIPTION("Toshiba TC35874X HDMI to CSI-2 bridge driver");
192 struct v4l2_subdev sd; member
228 static void tc35874x_enable_interrupts(struct v4l2_subdev *sd,
230 static int tc35874x_s_ctrl_detect_tx_5v(struct v4l2_subdev *sd);
231 static int tc35874x_s_dv_timings(struct v4l2_subdev *sd,
234 static inline struct tc35874x_state *to_state(struct v4l2_subdev *sd) in to_state() argument
236 return container_of(sd, struct tc35874x_state, sd); in to_state()
239 /* --------------- I2C --------------- */
241 static void i2c_rd(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) in i2c_rd() argument
243 struct tc35874x_state *state = to_state(sd); in i2c_rd()
244 struct i2c_client *client = state->i2c_client; in i2c_rd()
249 .addr = client->addr, in i2c_rd()
255 .addr = client->addr, in i2c_rd()
262 err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in i2c_rd()
264 v4l2_err(sd, "%s: reading register 0x%x from 0x%x failed\n", in i2c_rd()
265 __func__, reg, client->addr); in i2c_rd()
269 static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) in i2c_wr() argument
271 struct tc35874x_state *state = to_state(sd); in i2c_wr()
272 struct i2c_client *client = state->i2c_client; in i2c_wr()
278 n = I2C_MAX_XFER_SIZE - 2; in i2c_wr()
279 v4l2_warn(sd, "i2c wr reg=%04x: len=%d is too big!\n", in i2c_wr()
283 msg.addr = client->addr; in i2c_wr()
294 err = i2c_transfer(client->adapter, &msg, 1); in i2c_wr()
296 v4l2_err(sd, "%s: writing register 0x%x from 0x%x failed\n", in i2c_wr()
297 __func__, reg, client->addr); in i2c_wr()
306 v4l2_info(sd, "I2C write 0x%04x = 0x%02x\n", in i2c_wr()
310 v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x\n", in i2c_wr()
314 v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x%02x%02x\n", in i2c_wr()
318 v4l2_info(sd, "I2C write %d bytes from address 0x%04x\n", in i2c_wr()
323 static noinline u32 i2c_rdreg(struct v4l2_subdev *sd, u16 reg, u32 n) in i2c_rdreg() argument
327 i2c_rd(sd, reg, (u8 __force *)&val, n); in i2c_rdreg()
332 static noinline void i2c_wrreg(struct v4l2_subdev *sd, u16 reg, u32 val, u32 n) in i2c_wrreg() argument
336 i2c_wr(sd, reg, (u8 __force *)&raw, n); in i2c_wrreg()
339 static u8 i2c_rd8(struct v4l2_subdev *sd, u16 reg) in i2c_rd8() argument
341 return i2c_rdreg(sd, reg, 1); in i2c_rd8()
344 static void i2c_wr8(struct v4l2_subdev *sd, u16 reg, u8 val) in i2c_wr8() argument
346 i2c_wrreg(sd, reg, val, 1); in i2c_wr8()
349 static void i2c_wr8_and_or(struct v4l2_subdev *sd, u16 reg, in i2c_wr8_and_or() argument
352 i2c_wrreg(sd, reg, (i2c_rdreg(sd, reg, 1) & mask) | val, 1); in i2c_wr8_and_or()
355 static u16 i2c_rd16(struct v4l2_subdev *sd, u16 reg) in i2c_rd16() argument
357 return i2c_rdreg(sd, reg, 2); in i2c_rd16()
360 static void i2c_wr16(struct v4l2_subdev *sd, u16 reg, u16 val) in i2c_wr16() argument
362 i2c_wrreg(sd, reg, val, 2); in i2c_wr16()
365 static void i2c_wr16_and_or(struct v4l2_subdev *sd, u16 reg, u16 mask, u16 val) in i2c_wr16_and_or() argument
367 i2c_wrreg(sd, reg, (i2c_rdreg(sd, reg, 2) & mask) | val, 2); in i2c_wr16_and_or()
370 static u32 i2c_rd32(struct v4l2_subdev *sd, u16 reg) in i2c_rd32() argument
372 return i2c_rdreg(sd, reg, 4); in i2c_rd32()
375 static void i2c_wr32(struct v4l2_subdev *sd, u16 reg, u32 val) in i2c_wr32() argument
377 i2c_wrreg(sd, reg, val, 4); in i2c_wr32()
380 /* --------------- STATUS --------------- */
382 static inline bool is_hdmi(struct v4l2_subdev *sd) in is_hdmi() argument
384 return i2c_rd8(sd, SYS_STATUS) & MASK_S_HDMI; in is_hdmi()
387 static inline bool tx_5v_power_present(struct v4l2_subdev *sd) in tx_5v_power_present() argument
389 return i2c_rd8(sd, SYS_STATUS) & MASK_S_DDC5V; in tx_5v_power_present()
392 static inline bool no_signal(struct v4l2_subdev *sd) in no_signal() argument
394 return !(i2c_rd8(sd, SYS_STATUS) & MASK_S_TMDS); in no_signal()
397 static inline bool no_sync(struct v4l2_subdev *sd) in no_sync() argument
399 return !(i2c_rd8(sd, SYS_STATUS) & MASK_S_SYNC); in no_sync()
402 static inline bool audio_present(struct v4l2_subdev *sd) in audio_present() argument
404 return i2c_rd8(sd, AU_STATUS0) & MASK_S_A_SAMPLE; in audio_present()
407 static int get_audio_sampling_rate(struct v4l2_subdev *sd) in get_audio_sampling_rate() argument
415 if (no_signal(sd)) in get_audio_sampling_rate()
418 return code_to_rate[i2c_rd8(sd, FS_SET) & MASK_FS]; in get_audio_sampling_rate()
421 /* --------------- TIMINGS --------------- */
428 return DIV_ROUND_CLOSEST((unsigned)t->pixelclock, in fps()
432 static int tc35874x_get_detected_timings(struct v4l2_subdev *sd, in tc35874x_get_detected_timings() argument
435 struct v4l2_bt_timings *bt = &timings->bt; in tc35874x_get_detected_timings()
437 struct tc35874x_state *state = to_state(sd); in tc35874x_get_detected_timings()
442 if (no_signal(sd)) { in tc35874x_get_detected_timings()
443 v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__); in tc35874x_get_detected_timings()
444 return -ENOLINK; in tc35874x_get_detected_timings()
446 if (no_sync(sd)) { in tc35874x_get_detected_timings()
447 v4l2_dbg(1, debug, sd, "%s: no sync on signal\n", __func__); in tc35874x_get_detected_timings()
448 return -ENOLCK; in tc35874x_get_detected_timings()
451 timings->type = V4L2_DV_BT_656_1120; in tc35874x_get_detected_timings()
452 bt->interlaced = i2c_rd8(sd, VI_STATUS1) & MASK_S_V_INTERLACE ? in tc35874x_get_detected_timings()
455 width = ((i2c_rd8(sd, DE_WIDTH_H_HI) & 0x1f) << 8) + in tc35874x_get_detected_timings()
456 i2c_rd8(sd, DE_WIDTH_H_LO); in tc35874x_get_detected_timings()
457 height = ((i2c_rd8(sd, DE_WIDTH_V_HI) & 0x1f) << 8) + in tc35874x_get_detected_timings()
458 i2c_rd8(sd, DE_WIDTH_V_LO); in tc35874x_get_detected_timings()
459 frame_width = ((i2c_rd8(sd, H_SIZE_HI) & 0x1f) << 8) + in tc35874x_get_detected_timings()
460 i2c_rd8(sd, H_SIZE_LO); in tc35874x_get_detected_timings()
461 frame_height = (((i2c_rd8(sd, V_SIZE_HI) & 0x3f) << 8) + in tc35874x_get_detected_timings()
462 i2c_rd8(sd, V_SIZE_LO)) / 2; in tc35874x_get_detected_timings()
465 frame_interval = ((i2c_rd8(sd, FV_CNT_HI) & 0x3) << 8) + in tc35874x_get_detected_timings()
466 i2c_rd8(sd, FV_CNT_LO); in tc35874x_get_detected_timings()
470 bt->width = width; in tc35874x_get_detected_timings()
471 bt->height = height; in tc35874x_get_detected_timings()
472 bt->vsync = frame_height - height; in tc35874x_get_detected_timings()
473 bt->hsync = frame_width - width; in tc35874x_get_detected_timings()
474 bt->pixelclock = frame_width * frame_height * fps; in tc35874x_get_detected_timings()
475 if (bt->interlaced == V4L2_DV_INTERLACED) { in tc35874x_get_detected_timings()
476 bt->height *= 2; in tc35874x_get_detected_timings()
477 bt->il_vsync = bt->vsync + 1; in tc35874x_get_detected_timings()
478 bt->pixelclock /= 2; in tc35874x_get_detected_timings()
481 i2c_wr16(sd, FCCTL, 0x0002); in tc35874x_get_detected_timings()
483 i2c_wr16(sd, PACKETID1, 0x1e1e); in tc35874x_get_detected_timings()
485 i2c_wr16(sd, FCCTL, 0); in tc35874x_get_detected_timings()
488 if (state->csi_lanes_in_use == 4) { in tc35874x_get_detected_timings()
499 if ((bt->interlaced == V4L2_DV_INTERLACED) || (fps <= 33)) in tc35874x_get_detected_timings()
502 v4l2_dbg(2, debug, sd, "%s interlaced:%d, fifo_level:%d\n", in tc35874x_get_detected_timings()
503 __func__, bt->interlaced, fifo_level); in tc35874x_get_detected_timings()
504 i2c_wr16(sd, FIFOCTL, fifo_level); in tc35874x_get_detected_timings()
510 /* --------------- HOTPLUG / HDCP / EDID --------------- */
517 struct v4l2_subdev *sd = &state->sd; in tc35874x_delayed_work_enable_hotplug() local
519 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc35874x_delayed_work_enable_hotplug()
521 i2c_wr8_and_or(sd, HPD_CTL, ~MASK_HPD_OUT0, MASK_HPD_OUT0); in tc35874x_delayed_work_enable_hotplug()
524 static void tc35874x_set_hdmi_hdcp(struct v4l2_subdev *sd, bool enable) in tc35874x_set_hdmi_hdcp() argument
526 v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? in tc35874x_set_hdmi_hdcp()
530 i2c_wr8_and_or(sd, HDCP_REG3, ~KEY_RD_CMD, KEY_RD_CMD); in tc35874x_set_hdmi_hdcp()
532 i2c_wr8_and_or(sd, HDCP_MODE, ~MASK_MANUAL_AUTHENTICATION, 0); in tc35874x_set_hdmi_hdcp()
534 i2c_wr8_and_or(sd, HDCP_REG1, 0xff, in tc35874x_set_hdmi_hdcp()
538 i2c_wr8_and_or(sd, HDCP_REG2, ~MASK_AUTO_P3_RESET, in tc35874x_set_hdmi_hdcp()
541 i2c_wr8_and_or(sd, HDCP_MODE, ~MASK_MANUAL_AUTHENTICATION, in tc35874x_set_hdmi_hdcp()
546 static void tc35874x_disable_edid(struct v4l2_subdev *sd) in tc35874x_disable_edid() argument
548 struct tc35874x_state *state = to_state(sd); in tc35874x_disable_edid()
550 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc35874x_disable_edid()
552 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); in tc35874x_disable_edid()
556 i2c_wr8_and_or(sd, HPD_CTL, ~MASK_HPD_OUT0, 0x0); in tc35874x_disable_edid()
559 static void tc35874x_enable_edid(struct v4l2_subdev *sd) in tc35874x_enable_edid() argument
561 struct tc35874x_state *state = to_state(sd); in tc35874x_enable_edid()
563 if (state->edid_blocks_written == 0) { in tc35874x_enable_edid()
564 v4l2_dbg(2, debug, sd, "%s: no EDID -> no hotplug\n", __func__); in tc35874x_enable_edid()
565 tc35874x_s_ctrl_detect_tx_5v(sd); in tc35874x_enable_edid()
569 v4l2_dbg(2, debug, sd, "%s:\n", __func__); in tc35874x_enable_edid()
573 schedule_delayed_work(&state->delayed_work_enable_hotplug, HZ / 10); in tc35874x_enable_edid()
575 tc35874x_enable_interrupts(sd, true); in tc35874x_enable_edid()
576 tc35874x_s_ctrl_detect_tx_5v(sd); in tc35874x_enable_edid()
579 static void tc35874x_erase_bksv(struct v4l2_subdev *sd) in tc35874x_erase_bksv() argument
584 i2c_wr8(sd, BKSV + i, 0); in tc35874x_erase_bksv()
587 /* --------------- AVI infoframe --------------- */
589 static void print_avi_infoframe(struct v4l2_subdev *sd) in print_avi_infoframe() argument
591 struct i2c_client *client = v4l2_get_subdevdata(sd); in print_avi_infoframe()
592 struct device *dev = &client->dev; in print_avi_infoframe()
596 if (!is_hdmi(sd)) { in print_avi_infoframe()
597 v4l2_info(sd, "DVI-D signal - AVI infoframe not supported\n"); in print_avi_infoframe()
601 i2c_rd(sd, PK_AVI_0HEAD, buffer, HDMI_INFOFRAME_SIZE(AVI)); in print_avi_infoframe()
604 v4l2_err(sd, "%s: unpack of AVI infoframe failed\n", __func__); in print_avi_infoframe()
611 /* --------------- CTRLS --------------- */
613 static int tc35874x_s_ctrl_detect_tx_5v(struct v4l2_subdev *sd) in tc35874x_s_ctrl_detect_tx_5v() argument
615 struct tc35874x_state *state = to_state(sd); in tc35874x_s_ctrl_detect_tx_5v()
617 return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, in tc35874x_s_ctrl_detect_tx_5v()
618 tx_5v_power_present(sd)); in tc35874x_s_ctrl_detect_tx_5v()
621 static int tc35874x_s_ctrl_audio_sampling_rate(struct v4l2_subdev *sd) in tc35874x_s_ctrl_audio_sampling_rate() argument
623 struct tc35874x_state *state = to_state(sd); in tc35874x_s_ctrl_audio_sampling_rate()
625 return v4l2_ctrl_s_ctrl(state->audio_sampling_rate_ctrl, in tc35874x_s_ctrl_audio_sampling_rate()
626 get_audio_sampling_rate(sd)); in tc35874x_s_ctrl_audio_sampling_rate()
629 static int tc35874x_s_ctrl_audio_present(struct v4l2_subdev *sd) in tc35874x_s_ctrl_audio_present() argument
631 struct tc35874x_state *state = to_state(sd); in tc35874x_s_ctrl_audio_present()
633 return v4l2_ctrl_s_ctrl(state->audio_present_ctrl, in tc35874x_s_ctrl_audio_present()
634 audio_present(sd)); in tc35874x_s_ctrl_audio_present()
637 static int tc35874x_update_controls(struct v4l2_subdev *sd) in tc35874x_update_controls() argument
641 ret |= tc35874x_s_ctrl_detect_tx_5v(sd); in tc35874x_update_controls()
642 ret |= tc35874x_s_ctrl_audio_sampling_rate(sd); in tc35874x_update_controls()
643 ret |= tc35874x_s_ctrl_audio_present(sd); in tc35874x_update_controls()
648 /* --------------- INIT --------------- */
650 static void tc35874x_reset_phy(struct v4l2_subdev *sd) in tc35874x_reset_phy() argument
652 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in tc35874x_reset_phy()
654 i2c_wr8_and_or(sd, PHY_RST, ~MASK_RESET_CTRL, 0); in tc35874x_reset_phy()
655 i2c_wr8_and_or(sd, PHY_RST, ~MASK_RESET_CTRL, MASK_RESET_CTRL); in tc35874x_reset_phy()
658 static void tc35874x_reset(struct v4l2_subdev *sd, uint16_t mask) in tc35874x_reset() argument
660 u16 sysctl = i2c_rd16(sd, SYSCTL); in tc35874x_reset()
662 i2c_wr16(sd, SYSCTL, sysctl | mask); in tc35874x_reset()
663 i2c_wr16(sd, SYSCTL, sysctl & ~mask); in tc35874x_reset()
666 static inline void tc35874x_sleep_mode(struct v4l2_subdev *sd, bool enable) in tc35874x_sleep_mode() argument
668 i2c_wr16_and_or(sd, SYSCTL, ~MASK_SLEEP, in tc35874x_sleep_mode()
672 static inline void enable_stream(struct v4l2_subdev *sd, bool enable) in enable_stream() argument
674 struct tc35874x_state *state = to_state(sd); in enable_stream()
676 v4l2_dbg(3, debug, sd, "%s: %sable\n", in enable_stream()
681 * LP11->HS. Set to non-continuous mode to enable clock lane in enable_stream()
683 i2c_wr32(sd, TXOPTIONCNTRL, 0); in enable_stream()
684 /* Set to continuous mode to trigger LP11->HS transition */ in enable_stream()
685 i2c_wr32(sd, TXOPTIONCNTRL, MASK_CONTCLKMODE); in enable_stream()
687 i2c_wr8(sd, VI_MUTE, MASK_AUTO_MUTE); in enable_stream()
690 * No data is output to CSI Tx block. */ in enable_stream()
691 i2c_wr8(sd, VI_MUTE, MASK_AUTO_MUTE | MASK_VI_MUTE); in enable_stream()
692 /* Set to non-continuous mode to enable clock lane LP11 state. */ in enable_stream()
693 i2c_wr32(sd, TXOPTIONCNTRL, 0); in enable_stream()
696 mutex_lock(&state->confctl_mutex); in enable_stream()
697 i2c_wr16_and_or(sd, CONFCTL, ~(MASK_VBUFEN | MASK_ABUFEN), in enable_stream()
699 mutex_unlock(&state->confctl_mutex); in enable_stream()
702 static void tc35874x_set_pll(struct v4l2_subdev *sd) in tc35874x_set_pll() argument
704 struct tc35874x_state *state = to_state(sd); in tc35874x_set_pll()
705 struct tc35874x_platform_data *pdata = &state->pdata; in tc35874x_set_pll()
706 u16 pllctl0 = i2c_rd16(sd, PLLCTL0); in tc35874x_set_pll()
707 u16 pllctl1 = i2c_rd16(sd, PLLCTL1); in tc35874x_set_pll()
712 if (state->csi_lanes_in_use == 4) { in tc35874x_set_pll()
713 if ((state->timings.bt.interlaced) || in tc35874x_set_pll()
714 (fps(&(state->timings.bt)) <= 33)) { in tc35874x_set_pll()
715 pdata->pll_prd = 2; in tc35874x_set_pll()
716 pdata->pll_fbd = 65; in tc35874x_set_pll()
719 pdata->pll_prd = 5; in tc35874x_set_pll()
720 pdata->pll_fbd = 138; in tc35874x_set_pll()
724 hsck = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; in tc35874x_set_pll()
726 if (state->timings.bt.interlaced) in tc35874x_set_pll()
738 pllctl0_new = SET_PLL_PRD(pdata->pll_prd) | SET_PLL_FBD(pdata->pll_fbd); in tc35874x_set_pll()
740 v4l2_dbg(1, debug, sd, in tc35874x_set_pll()
742 __func__, pdata->pll_prd, pdata->pll_fbd, pll_frs, in tc35874x_set_pll()
743 state->timings.bt.interlaced, fps(&(state->timings.bt))); in tc35874x_set_pll()
750 v4l2_dbg(1, debug, sd, "%s: updating PLL clock\n", __func__); in tc35874x_set_pll()
751 tc35874x_sleep_mode(sd, true); in tc35874x_set_pll()
752 i2c_wr16(sd, PLLCTL0, pllctl0_new); in tc35874x_set_pll()
753 i2c_wr16_and_or(sd, PLLCTL1, in tc35874x_set_pll()
758 i2c_wr16_and_or(sd, PLLCTL1, ~MASK_CKEN, MASK_CKEN); in tc35874x_set_pll()
759 tc35874x_sleep_mode(sd, false); in tc35874x_set_pll()
763 static void tc35874x_set_ref_clk(struct v4l2_subdev *sd) in tc35874x_set_ref_clk() argument
765 struct tc35874x_state *state = to_state(sd); in tc35874x_set_ref_clk()
766 struct tc35874x_platform_data *pdata = &state->pdata; in tc35874x_set_ref_clk()
772 BUG_ON(!(pdata->refclk_hz == 26000000 || in tc35874x_set_ref_clk()
773 pdata->refclk_hz == 27000000 || in tc35874x_set_ref_clk()
774 pdata->refclk_hz == 42000000)); in tc35874x_set_ref_clk()
776 sys_freq = pdata->refclk_hz / 10000; in tc35874x_set_ref_clk()
777 i2c_wr8(sd, SYS_FREQ0, sys_freq & 0x00ff); in tc35874x_set_ref_clk()
778 i2c_wr8(sd, SYS_FREQ1, (sys_freq & 0xff00) >> 8); in tc35874x_set_ref_clk()
780 i2c_wr8_and_or(sd, PHY_CTL0, ~MASK_PHY_SYSCLK_IND, in tc35874x_set_ref_clk()
781 (pdata->refclk_hz == 42000000) ? in tc35874x_set_ref_clk()
784 fh_min = pdata->refclk_hz / 100000; in tc35874x_set_ref_clk()
785 i2c_wr8(sd, FH_MIN0, fh_min & 0x00ff); in tc35874x_set_ref_clk()
786 i2c_wr8(sd, FH_MIN1, (fh_min & 0xff00) >> 8); in tc35874x_set_ref_clk()
789 i2c_wr8(sd, FH_MAX0, fh_max & 0x00ff); in tc35874x_set_ref_clk()
790 i2c_wr8(sd, FH_MAX1, (fh_max & 0xff00) >> 8); in tc35874x_set_ref_clk()
792 lockdet_ref = pdata->refclk_hz / 100; in tc35874x_set_ref_clk()
793 i2c_wr8(sd, LOCKDET_REF0, lockdet_ref & 0x0000ff); in tc35874x_set_ref_clk()
794 i2c_wr8(sd, LOCKDET_REF1, (lockdet_ref & 0x00ff00) >> 8); in tc35874x_set_ref_clk()
795 i2c_wr8(sd, LOCKDET_REF2, (lockdet_ref & 0x0f0000) >> 16); in tc35874x_set_ref_clk()
797 i2c_wr8_and_or(sd, NCO_F0_MOD, ~MASK_NCO_F0_MOD, in tc35874x_set_ref_clk()
798 (pdata->refclk_hz == 27000000) ? in tc35874x_set_ref_clk()
802 static void tc35874x_set_csi_color_space(struct v4l2_subdev *sd) in tc35874x_set_csi_color_space() argument
804 struct tc35874x_state *state = to_state(sd); in tc35874x_set_csi_color_space()
806 switch (state->mbus_fmt_code) { in tc35874x_set_csi_color_space()
808 v4l2_dbg(2, debug, sd, "%s: YCbCr 422 16-bit\n", __func__); in tc35874x_set_csi_color_space()
809 i2c_wr8_and_or(sd, VOUT_SET2, in tc35874x_set_csi_color_space()
812 i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, in tc35874x_set_csi_color_space()
814 mutex_lock(&state->confctl_mutex); in tc35874x_set_csi_color_space()
815 i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, in tc35874x_set_csi_color_space()
817 mutex_unlock(&state->confctl_mutex); in tc35874x_set_csi_color_space()
820 v4l2_dbg(2, debug, sd, "%s: RGB 888 24-bit\n", __func__); in tc35874x_set_csi_color_space()
821 i2c_wr8_and_or(sd, VOUT_SET2, in tc35874x_set_csi_color_space()
824 i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, in tc35874x_set_csi_color_space()
826 mutex_lock(&state->confctl_mutex); in tc35874x_set_csi_color_space()
827 i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, 0); in tc35874x_set_csi_color_space()
828 mutex_unlock(&state->confctl_mutex); in tc35874x_set_csi_color_space()
831 v4l2_dbg(2, debug, sd, "%s: Unsupported format code 0x%x\n", in tc35874x_set_csi_color_space()
832 __func__, state->mbus_fmt_code); in tc35874x_set_csi_color_space()
836 static void tc35874x_set_csi(struct v4l2_subdev *sd) in tc35874x_set_csi() argument
838 struct tc35874x_state *state = to_state(sd); in tc35874x_set_csi()
839 struct tc35874x_platform_data *pdata = &state->pdata; in tc35874x_set_csi()
840 unsigned lanes = state->csi_lanes_in_use; in tc35874x_set_csi()
842 v4l2_dbg(3, debug, sd, "%s:\n", __func__); in tc35874x_set_csi()
844 tc35874x_reset(sd, MASK_CTXRST); in tc35874x_set_csi()
847 i2c_wr32(sd, CLW_CNTRL, MASK_CLW_LANEDISABLE); in tc35874x_set_csi()
849 i2c_wr32(sd, D0W_CNTRL, MASK_D0W_LANEDISABLE); in tc35874x_set_csi()
851 i2c_wr32(sd, D1W_CNTRL, MASK_D1W_LANEDISABLE); in tc35874x_set_csi()
853 i2c_wr32(sd, D2W_CNTRL, MASK_D2W_LANEDISABLE); in tc35874x_set_csi()
855 i2c_wr32(sd, D3W_CNTRL, MASK_D3W_LANEDISABLE); in tc35874x_set_csi()
857 v4l2_dbg(1, debug, sd, "%s: interlaced:%d, fps:%d\n", __func__, in tc35874x_set_csi()
858 state->timings.bt.interlaced, fps(&(state->timings.bt))); in tc35874x_set_csi()
859 if (state->csi_lanes_in_use == 4) { in tc35874x_set_csi()
860 if ((state->timings.bt.interlaced) || in tc35874x_set_csi()
861 (fps(&(state->timings.bt)) <= 33)) { in tc35874x_set_csi()
862 state->pdata.lineinitcnt = 0x7d0; in tc35874x_set_csi()
863 state->pdata.lptxtimecnt = 0x002; in tc35874x_set_csi()
864 state->pdata.tclk_headercnt = 0x901; in tc35874x_set_csi()
865 state->pdata.tclk_trailcnt = 0x00; in tc35874x_set_csi()
866 state->pdata.ths_headercnt = 0x02; in tc35874x_set_csi()
867 state->pdata.twakeup = 0x32c8; in tc35874x_set_csi()
868 state->pdata.tclk_postcnt = 0x006; in tc35874x_set_csi()
869 state->pdata.ths_trailcnt = 0x0; in tc35874x_set_csi()
870 state->pdata.hstxvregcnt = 5; in tc35874x_set_csi()
872 state->pdata.lineinitcnt = 0x1770; in tc35874x_set_csi()
873 state->pdata.lptxtimecnt = 0x05; in tc35874x_set_csi()
874 state->pdata.tclk_headercnt = 0x1505; in tc35874x_set_csi()
875 state->pdata.tclk_trailcnt = 0x01; in tc35874x_set_csi()
876 state->pdata.ths_headercnt = 0x0105; in tc35874x_set_csi()
877 state->pdata.twakeup = 0x332c; in tc35874x_set_csi()
878 state->pdata.tclk_postcnt = 0x08; in tc35874x_set_csi()
879 state->pdata.ths_trailcnt = 0x02; in tc35874x_set_csi()
880 state->pdata.hstxvregcnt = 0x05; in tc35874x_set_csi()
884 i2c_wr32(sd, LINEINITCNT, pdata->lineinitcnt); in tc35874x_set_csi()
885 i2c_wr32(sd, LPTXTIMECNT, pdata->lptxtimecnt); in tc35874x_set_csi()
886 i2c_wr32(sd, TCLK_HEADERCNT, pdata->tclk_headercnt); in tc35874x_set_csi()
887 i2c_wr32(sd, TCLK_TRAILCNT, pdata->tclk_trailcnt); in tc35874x_set_csi()
888 i2c_wr32(sd, THS_HEADERCNT, pdata->ths_headercnt); in tc35874x_set_csi()
889 i2c_wr32(sd, TWAKEUP, pdata->twakeup); in tc35874x_set_csi()
890 i2c_wr32(sd, TCLK_POSTCNT, pdata->tclk_postcnt); in tc35874x_set_csi()
891 i2c_wr32(sd, THS_TRAILCNT, pdata->ths_trailcnt); in tc35874x_set_csi()
892 i2c_wr32(sd, HSTXVREGCNT, pdata->hstxvregcnt); in tc35874x_set_csi()
894 i2c_wr32(sd, HSTXVREGEN, in tc35874x_set_csi()
901 i2c_wr32(sd, TXOPTIONCNTRL, (state->bus.flags & in tc35874x_set_csi()
903 i2c_wr32(sd, STARTCNTRL, MASK_START); in tc35874x_set_csi()
904 i2c_wr32(sd, CSI_START, MASK_STRT); in tc35874x_set_csi()
906 i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | in tc35874x_set_csi()
914 i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | in tc35874x_set_csi()
918 i2c_wr32(sd, CSI_CONFW, MASK_MODE_CLEAR | in tc35874x_set_csi()
921 i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | in tc35874x_set_csi()
925 static void tc35874x_set_hdmi_phy(struct v4l2_subdev *sd) in tc35874x_set_hdmi_phy() argument
927 struct tc35874x_state *state = to_state(sd); in tc35874x_set_hdmi_phy()
928 struct tc35874x_platform_data *pdata = &state->pdata; in tc35874x_set_hdmi_phy()
932 i2c_wr8_and_or(sd, PHY_EN, ~MASK_ENABLE_PHY, 0x0); in tc35874x_set_hdmi_phy()
933 i2c_wr8(sd, PHY_CTL1, SET_PHY_AUTO_RST1_US(1600) | in tc35874x_set_hdmi_phy()
935 i2c_wr8_and_or(sd, PHY_CTL2, ~MASK_PHY_AUTO_RSTn, in tc35874x_set_hdmi_phy()
936 (pdata->hdmi_phy_auto_reset_tmds_detected ? in tc35874x_set_hdmi_phy()
938 (pdata->hdmi_phy_auto_reset_tmds_in_range ? in tc35874x_set_hdmi_phy()
940 (pdata->hdmi_phy_auto_reset_tmds_valid ? in tc35874x_set_hdmi_phy()
942 i2c_wr8(sd, PHY_BIAS, 0x40); in tc35874x_set_hdmi_phy()
943 i2c_wr8(sd, PHY_CSQ, SET_CSQ_CNT_LEVEL(0x0a)); in tc35874x_set_hdmi_phy()
944 i2c_wr8(sd, AVM_CTL, 45); in tc35874x_set_hdmi_phy()
945 i2c_wr8_and_or(sd, HDMI_DET, ~MASK_HDMI_DET_V, in tc35874x_set_hdmi_phy()
946 pdata->hdmi_detection_delay << 4); in tc35874x_set_hdmi_phy()
947 i2c_wr8_and_or(sd, HV_RST, ~(MASK_H_PI_RST | MASK_V_PI_RST), in tc35874x_set_hdmi_phy()
948 (pdata->hdmi_phy_auto_reset_hsync_out_of_range ? in tc35874x_set_hdmi_phy()
950 (pdata->hdmi_phy_auto_reset_vsync_out_of_range ? in tc35874x_set_hdmi_phy()
952 i2c_wr8_and_or(sd, PHY_EN, ~MASK_ENABLE_PHY, MASK_ENABLE_PHY); in tc35874x_set_hdmi_phy()
955 static void tc35874x_set_hdmi_audio(struct v4l2_subdev *sd) in tc35874x_set_hdmi_audio() argument
957 struct tc35874x_state *state = to_state(sd); in tc35874x_set_hdmi_audio()
960 i2c_wr8(sd, FORCE_MUTE, 0x00); in tc35874x_set_hdmi_audio()
961 i2c_wr8(sd, AUTO_CMD0, MASK_AUTO_MUTE7 | MASK_AUTO_MUTE6 | in tc35874x_set_hdmi_audio()
964 i2c_wr8(sd, AUTO_CMD1, MASK_AUTO_MUTE9); in tc35874x_set_hdmi_audio()
965 i2c_wr8(sd, AUTO_CMD2, MASK_AUTO_PLAY3 | MASK_AUTO_PLAY2); in tc35874x_set_hdmi_audio()
966 i2c_wr8(sd, BUFINIT_START, SET_BUFINIT_START_MS(500)); in tc35874x_set_hdmi_audio()
967 i2c_wr8(sd, FS_MUTE, 0x00); in tc35874x_set_hdmi_audio()
968 i2c_wr8(sd, FS_IMODE, MASK_NLPCM_SMODE | MASK_FS_SMODE); in tc35874x_set_hdmi_audio()
969 i2c_wr8(sd, ACR_MODE, MASK_CTS_MODE); in tc35874x_set_hdmi_audio()
970 i2c_wr8(sd, ACR_MDF0, MASK_ACR_L2MDF_1976_PPM | MASK_ACR_L1MDF_976_PPM); in tc35874x_set_hdmi_audio()
971 i2c_wr8(sd, ACR_MDF1, MASK_ACR_L3MDF_3906_PPM); in tc35874x_set_hdmi_audio()
972 i2c_wr8(sd, SDO_MODE1, MASK_SDO_FMT_I2S); in tc35874x_set_hdmi_audio()
973 i2c_wr8(sd, DIV_MODE, SET_DIV_DLY_MS(100)); in tc35874x_set_hdmi_audio()
975 mutex_lock(&state->confctl_mutex); in tc35874x_set_hdmi_audio()
976 i2c_wr16_and_or(sd, CONFCTL, 0xffff, MASK_AUDCHNUM_2 | in tc35874x_set_hdmi_audio()
978 mutex_unlock(&state->confctl_mutex); in tc35874x_set_hdmi_audio()
981 static void tc35874x_set_hdmi_info_frame_mode(struct v4l2_subdev *sd) in tc35874x_set_hdmi_info_frame_mode() argument
984 i2c_wr8(sd, PK_INT_MODE, MASK_ISRC2_INT_MODE | MASK_ISRC_INT_MODE | in tc35874x_set_hdmi_info_frame_mode()
988 i2c_wr8(sd, NO_PKT_LIMIT, 0x2c); in tc35874x_set_hdmi_info_frame_mode()
989 i2c_wr8(sd, NO_PKT_CLR, 0x53); in tc35874x_set_hdmi_info_frame_mode()
990 i2c_wr8(sd, ERR_PK_LIMIT, 0x01); in tc35874x_set_hdmi_info_frame_mode()
991 i2c_wr8(sd, NO_PKT_LIMIT2, 0x30); in tc35874x_set_hdmi_info_frame_mode()
992 i2c_wr8(sd, NO_GDB_LIMIT, 0x10); in tc35874x_set_hdmi_info_frame_mode()
995 static void tc35874x_initial_setup(struct v4l2_subdev *sd) in tc35874x_initial_setup() argument
997 struct tc35874x_state *state = to_state(sd); in tc35874x_initial_setup()
998 struct tc35874x_platform_data *pdata = &state->pdata; in tc35874x_initial_setup()
1001 i2c_wr16_and_or(sd, SYSCTL, ~(MASK_CECRST | MASK_IRRST | MASK_I2SDIS), in tc35874x_initial_setup()
1004 tc35874x_reset(sd, MASK_CTXRST | MASK_HDMIRST); in tc35874x_initial_setup()
1005 tc35874x_sleep_mode(sd, false); in tc35874x_initial_setup()
1007 i2c_wr16(sd, FIFOCTL, pdata->fifo_level); in tc35874x_initial_setup()
1009 tc35874x_set_ref_clk(sd); in tc35874x_initial_setup()
1011 i2c_wr8_and_or(sd, DDC_CTL, ~MASK_DDC5V_MODE, in tc35874x_initial_setup()
1012 pdata->ddc5v_delay & MASK_DDC5V_MODE); in tc35874x_initial_setup()
1013 i2c_wr8_and_or(sd, EDID_MODE, ~MASK_EDID_MODE, MASK_EDID_MODE_E_DDC); in tc35874x_initial_setup()
1015 tc35874x_set_hdmi_phy(sd); in tc35874x_initial_setup()
1016 tc35874x_set_hdmi_hdcp(sd, pdata->enable_hdcp); in tc35874x_initial_setup()
1017 tc35874x_set_hdmi_audio(sd); in tc35874x_initial_setup()
1018 tc35874x_set_hdmi_info_frame_mode(sd); in tc35874x_initial_setup()
1021 i2c_wr8_and_or(sd, VI_MODE, ~MASK_RGB_DVI, 0); in tc35874x_initial_setup()
1023 i2c_wr8_and_or(sd, VOUT_SET2, ~MASK_VOUTCOLORMODE, in tc35874x_initial_setup()
1025 i2c_wr8(sd, VOUT_SET3, MASK_VOUT_EXTCNT); in tc35874x_initial_setup()
1028 /* --------------- IRQ --------------- */
1030 static void tc35874x_format_change(struct v4l2_subdev *sd) in tc35874x_format_change() argument
1032 struct tc35874x_state *state = to_state(sd); in tc35874x_format_change()
1039 if (tc35874x_get_detected_timings(sd, &timings)) { in tc35874x_format_change()
1040 enable_stream(sd, false); in tc35874x_format_change()
1042 v4l2_dbg(1, debug, sd, "%s: No signal\n", in tc35874x_format_change()
1045 if (!v4l2_match_dv_timings(&state->timings, &timings, 0, false)) { in tc35874x_format_change()
1046 enable_stream(sd, false); in tc35874x_format_change()
1048 tc35874x_s_dv_timings(sd, &timings); in tc35874x_format_change()
1051 v4l2_print_dv_timings(sd->name, in tc35874x_format_change()
1056 if (sd->devnode) in tc35874x_format_change()
1057 v4l2_subdev_notify_event(sd, &tc35874x_ev_fmt); in tc35874x_format_change()
1060 static void tc35874x_init_interrupts(struct v4l2_subdev *sd) in tc35874x_init_interrupts() argument
1066 i2c_wr8(sd, i, 0xff); in tc35874x_init_interrupts()
1068 i2c_wr16(sd, INTSTATUS, 0xffff); in tc35874x_init_interrupts()
1071 static void tc35874x_enable_interrupts(struct v4l2_subdev *sd, in tc35874x_enable_interrupts() argument
1074 v4l2_dbg(2, debug, sd, "%s: cable connected = %d\n", __func__, in tc35874x_enable_interrupts()
1078 i2c_wr8(sd, SYS_INTM, ~(MASK_M_DDC | MASK_M_DVI_DET | in tc35874x_enable_interrupts()
1080 i2c_wr8(sd, CLK_INTM, ~MASK_M_IN_DE_CHG); in tc35874x_enable_interrupts()
1081 i2c_wr8(sd, CBIT_INTM, ~(MASK_M_CBIT_FS | MASK_M_AF_LOCK | in tc35874x_enable_interrupts()
1083 i2c_wr8(sd, AUDIO_INTM, ~MASK_M_BUFINIT_END); in tc35874x_enable_interrupts()
1084 i2c_wr8(sd, MISC_INTM, ~MASK_M_SYNC_CHG); in tc35874x_enable_interrupts()
1086 i2c_wr8(sd, SYS_INTM, ~MASK_M_DDC & 0xff); in tc35874x_enable_interrupts()
1087 i2c_wr8(sd, CLK_INTM, 0xff); in tc35874x_enable_interrupts()
1088 i2c_wr8(sd, CBIT_INTM, 0xff); in tc35874x_enable_interrupts()
1089 i2c_wr8(sd, AUDIO_INTM, 0xff); in tc35874x_enable_interrupts()
1090 i2c_wr8(sd, MISC_INTM, 0xff); in tc35874x_enable_interrupts()
1094 static void tc35874x_hdmi_audio_int_handler(struct v4l2_subdev *sd, in tc35874x_hdmi_audio_int_handler() argument
1097 u8 audio_int_mask = i2c_rd8(sd, AUDIO_INTM); in tc35874x_hdmi_audio_int_handler()
1098 u8 audio_int = i2c_rd8(sd, AUDIO_INT) & ~audio_int_mask; in tc35874x_hdmi_audio_int_handler()
1100 i2c_wr8(sd, AUDIO_INT, audio_int); in tc35874x_hdmi_audio_int_handler()
1102 v4l2_dbg(3, debug, sd, "%s: AUDIO_INT = 0x%02x\n", __func__, audio_int); in tc35874x_hdmi_audio_int_handler()
1104 tc35874x_s_ctrl_audio_sampling_rate(sd); in tc35874x_hdmi_audio_int_handler()
1105 tc35874x_s_ctrl_audio_present(sd); in tc35874x_hdmi_audio_int_handler()
1108 static void tc35874x_csi_err_int_handler(struct v4l2_subdev *sd, bool *handled) in tc35874x_csi_err_int_handler() argument
1110 v4l2_err(sd, "%s: CSI_ERR = 0x%x\n", __func__, i2c_rd32(sd, CSI_ERR)); in tc35874x_csi_err_int_handler()
1112 i2c_wr32(sd, CSI_INT_CLR, MASK_ICRER); in tc35874x_csi_err_int_handler()
1115 static void tc35874x_hdmi_misc_int_handler(struct v4l2_subdev *sd, in tc35874x_hdmi_misc_int_handler() argument
1118 u8 misc_int_mask = i2c_rd8(sd, MISC_INTM); in tc35874x_hdmi_misc_int_handler()
1119 u8 misc_int = i2c_rd8(sd, MISC_INT) & ~misc_int_mask; in tc35874x_hdmi_misc_int_handler()
1121 i2c_wr8(sd, MISC_INT, misc_int); in tc35874x_hdmi_misc_int_handler()
1123 v4l2_dbg(3, debug, sd, "%s: MISC_INT = 0x%02x\n", __func__, misc_int); in tc35874x_hdmi_misc_int_handler()
1129 if (no_sync(sd) || no_signal(sd)) { in tc35874x_hdmi_misc_int_handler()
1130 tc35874x_reset_phy(sd); in tc35874x_hdmi_misc_int_handler()
1131 tc35874x_erase_bksv(sd); in tc35874x_hdmi_misc_int_handler()
1134 tc35874x_format_change(sd); in tc35874x_hdmi_misc_int_handler()
1142 v4l2_err(sd, "%s: Unhandled MISC_INT interrupts: 0x%02x\n", in tc35874x_hdmi_misc_int_handler()
1147 static void tc35874x_hdmi_cbit_int_handler(struct v4l2_subdev *sd, in tc35874x_hdmi_cbit_int_handler() argument
1150 u8 cbit_int_mask = i2c_rd8(sd, CBIT_INTM); in tc35874x_hdmi_cbit_int_handler()
1151 u8 cbit_int = i2c_rd8(sd, CBIT_INT) & ~cbit_int_mask; in tc35874x_hdmi_cbit_int_handler()
1153 i2c_wr8(sd, CBIT_INT, cbit_int); in tc35874x_hdmi_cbit_int_handler()
1155 v4l2_dbg(3, debug, sd, "%s: CBIT_INT = 0x%02x\n", __func__, cbit_int); in tc35874x_hdmi_cbit_int_handler()
1159 v4l2_dbg(1, debug, sd, "%s: Audio sample rate changed\n", in tc35874x_hdmi_cbit_int_handler()
1161 tc35874x_s_ctrl_audio_sampling_rate(sd); in tc35874x_hdmi_cbit_int_handler()
1170 v4l2_dbg(1, debug, sd, "%s: Audio present changed\n", in tc35874x_hdmi_cbit_int_handler()
1172 tc35874x_s_ctrl_audio_present(sd); in tc35874x_hdmi_cbit_int_handler()
1180 v4l2_err(sd, "%s: Unhandled CBIT_INT interrupts: 0x%02x\n", in tc35874x_hdmi_cbit_int_handler()
1185 static void tc35874x_hdmi_clk_int_handler(struct v4l2_subdev *sd, bool *handled) in tc35874x_hdmi_clk_int_handler() argument
1187 u8 clk_int_mask = i2c_rd8(sd, CLK_INTM); in tc35874x_hdmi_clk_int_handler()
1188 u8 clk_int = i2c_rd8(sd, CLK_INT) & ~clk_int_mask; in tc35874x_hdmi_clk_int_handler()
1191 i2c_wr8(sd, CLK_INT, clk_int | 0x80 | MASK_I_OUT_H_CHG); in tc35874x_hdmi_clk_int_handler()
1193 v4l2_dbg(3, debug, sd, "%s: CLK_INT = 0x%02x\n", __func__, clk_int); in tc35874x_hdmi_clk_int_handler()
1197 v4l2_dbg(1, debug, sd, "%s: DE size or position has changed\n", in tc35874x_hdmi_clk_int_handler()
1201 * frequency as the existing (e.g. 1080p25 -> 720p50), the in tc35874x_hdmi_clk_int_handler()
1206 if (!no_signal(sd) && !no_sync(sd)) in tc35874x_hdmi_clk_int_handler()
1207 tc35874x_format_change(sd); in tc35874x_hdmi_clk_int_handler()
1215 v4l2_err(sd, "%s: Unhandled CLK_INT interrupts: 0x%02x\n", in tc35874x_hdmi_clk_int_handler()
1220 static void tc35874x_hdmi_sys_int_handler(struct v4l2_subdev *sd, bool *handled) in tc35874x_hdmi_sys_int_handler() argument
1222 struct tc35874x_state *state = to_state(sd); in tc35874x_hdmi_sys_int_handler()
1223 u8 sys_int_mask = i2c_rd8(sd, SYS_INTM); in tc35874x_hdmi_sys_int_handler()
1224 u8 sys_int = i2c_rd8(sd, SYS_INT) & ~sys_int_mask; in tc35874x_hdmi_sys_int_handler()
1226 i2c_wr8(sd, SYS_INT, sys_int); in tc35874x_hdmi_sys_int_handler()
1228 v4l2_dbg(3, debug, sd, "%s: SYS_INT = 0x%02x\n", __func__, sys_int); in tc35874x_hdmi_sys_int_handler()
1231 bool tx_5v = tx_5v_power_present(sd); in tc35874x_hdmi_sys_int_handler()
1233 v4l2_dbg(1, debug, sd, "%s: Tx 5V power present: %s\n", in tc35874x_hdmi_sys_int_handler()
1234 __func__, tx_5v ? "yes" : "no"); in tc35874x_hdmi_sys_int_handler()
1237 tc35874x_enable_edid(sd); in tc35874x_hdmi_sys_int_handler()
1239 tc35874x_enable_interrupts(sd, false); in tc35874x_hdmi_sys_int_handler()
1240 tc35874x_disable_edid(sd); in tc35874x_hdmi_sys_int_handler()
1241 memset(&state->timings, 0, sizeof(state->timings)); in tc35874x_hdmi_sys_int_handler()
1242 tc35874x_erase_bksv(sd); in tc35874x_hdmi_sys_int_handler()
1243 tc35874x_update_controls(sd); in tc35874x_hdmi_sys_int_handler()
1252 v4l2_dbg(1, debug, sd, "%s: HDMI->DVI change detected\n", in tc35874x_hdmi_sys_int_handler()
1258 if (no_sync(sd) || no_signal(sd)) { in tc35874x_hdmi_sys_int_handler()
1259 tc35874x_reset_phy(sd); in tc35874x_hdmi_sys_int_handler()
1260 tc35874x_erase_bksv(sd); in tc35874x_hdmi_sys_int_handler()
1269 v4l2_dbg(1, debug, sd, "%s: DVI->HDMI change detected\n", in tc35874x_hdmi_sys_int_handler()
1273 i2c_wr8(sd, ANA_CTL, MASK_APPL_PCSX_NORMAL | MASK_ANALOG_ON); in tc35874x_hdmi_sys_int_handler()
1281 v4l2_err(sd, "%s: Unhandled SYS_INT interrupts: 0x%02x\n", in tc35874x_hdmi_sys_int_handler()
1286 /* --------------- CTRL OPS --------------- */
1290 int ret = -1; in tc35874x_get_ctrl()
1291 struct tc35874x_state *state = container_of(ctrl->handler, in tc35874x_get_ctrl()
1293 struct v4l2_subdev *sd = &(state->sd); in tc35874x_get_ctrl() local
1295 if (ctrl->id == V4L2_CID_DV_RX_POWER_PRESENT) { in tc35874x_get_ctrl()
1296 ret = tx_5v_power_present(sd); in tc35874x_get_ctrl()
1297 *ctrl->p_new.p_s32 = ret; in tc35874x_get_ctrl()
1303 /* --------------- CORE OPS --------------- */
1305 static int tc35874x_log_status(struct v4l2_subdev *sd) in tc35874x_log_status() argument
1307 struct tc35874x_state *state = to_state(sd); in tc35874x_log_status()
1309 uint8_t hdmi_sys_status = i2c_rd8(sd, SYS_STATUS); in tc35874x_log_status()
1310 uint16_t sysctl = i2c_rd16(sd, SYSCTL); in tc35874x_log_status()
1311 u8 vi_status3 = i2c_rd8(sd, VI_STATUS3); in tc35874x_log_status()
1318 v4l2_info(sd, "-----Chip status-----\n"); in tc35874x_log_status()
1319 v4l2_info(sd, "Chip ID: 0x%02x\n", in tc35874x_log_status()
1320 (i2c_rd16(sd, CHIPID) & MASK_CHIPID) >> 8); in tc35874x_log_status()
1321 v4l2_info(sd, "Chip revision: 0x%02x\n", in tc35874x_log_status()
1322 i2c_rd16(sd, CHIPID) & MASK_REVID); in tc35874x_log_status()
1323 v4l2_info(sd, "Reset: IR: %d, CEC: %d, CSI TX: %d, HDMI: %d\n", in tc35874x_log_status()
1328 v4l2_info(sd, "Sleep mode: %s\n", sysctl & MASK_SLEEP ? "on" : "off"); in tc35874x_log_status()
1329 v4l2_info(sd, "Cable detected (+5V power): %s\n", in tc35874x_log_status()
1330 hdmi_sys_status & MASK_S_DDC5V ? "yes" : "no"); in tc35874x_log_status()
1331 v4l2_info(sd, "DDC lines enabled: %s\n", in tc35874x_log_status()
1332 (i2c_rd8(sd, EDID_MODE) & MASK_EDID_MODE_E_DDC) ? in tc35874x_log_status()
1333 "yes" : "no"); in tc35874x_log_status()
1334 v4l2_info(sd, "Hotplug enabled: %s\n", in tc35874x_log_status()
1335 (i2c_rd8(sd, HPD_CTL) & MASK_HPD_OUT0) ? in tc35874x_log_status()
1336 "yes" : "no"); in tc35874x_log_status()
1337 v4l2_info(sd, "CEC enabled: %s\n", in tc35874x_log_status()
1338 (i2c_rd16(sd, CECEN) & MASK_CECEN) ? "yes" : "no"); in tc35874x_log_status()
1339 v4l2_info(sd, "-----Signal status-----\n"); in tc35874x_log_status()
1340 v4l2_info(sd, "TMDS signal detected: %s\n", in tc35874x_log_status()
1341 hdmi_sys_status & MASK_S_TMDS ? "yes" : "no"); in tc35874x_log_status()
1342 v4l2_info(sd, "Stable sync signal: %s\n", in tc35874x_log_status()
1343 hdmi_sys_status & MASK_S_SYNC ? "yes" : "no"); in tc35874x_log_status()
1344 v4l2_info(sd, "PHY PLL locked: %s\n", in tc35874x_log_status()
1345 hdmi_sys_status & MASK_S_PHY_PLL ? "yes" : "no"); in tc35874x_log_status()
1346 v4l2_info(sd, "PHY DE detected: %s\n", in tc35874x_log_status()
1347 hdmi_sys_status & MASK_S_PHY_SCDT ? "yes" : "no"); in tc35874x_log_status()
1349 if (tc35874x_get_detected_timings(sd, &timings)) { in tc35874x_log_status()
1350 v4l2_info(sd, "No video detected\n"); in tc35874x_log_status()
1352 v4l2_print_dv_timings(sd->name, "Detected format: ", &timings, in tc35874x_log_status()
1355 v4l2_print_dv_timings(sd->name, "Configured format: ", &state->timings, in tc35874x_log_status()
1358 v4l2_info(sd, "-----CSI-TX status-----\n"); in tc35874x_log_status()
1359 v4l2_info(sd, "Lanes in use: %d\n", in tc35874x_log_status()
1360 state->csi_lanes_in_use); in tc35874x_log_status()
1361 v4l2_info(sd, "Waiting for particular sync signal: %s\n", in tc35874x_log_status()
1362 (i2c_rd16(sd, CSI_STATUS) & MASK_S_WSYNC) ? in tc35874x_log_status()
1363 "yes" : "no"); in tc35874x_log_status()
1364 v4l2_info(sd, "Transmit mode: %s\n", in tc35874x_log_status()
1365 (i2c_rd16(sd, CSI_STATUS) & MASK_S_TXACT) ? in tc35874x_log_status()
1366 "yes" : "no"); in tc35874x_log_status()
1367 v4l2_info(sd, "Receive mode: %s\n", in tc35874x_log_status()
1368 (i2c_rd16(sd, CSI_STATUS) & MASK_S_RXACT) ? in tc35874x_log_status()
1369 "yes" : "no"); in tc35874x_log_status()
1370 v4l2_info(sd, "Stopped: %s\n", in tc35874x_log_status()
1371 (i2c_rd16(sd, CSI_STATUS) & MASK_S_HLT) ? in tc35874x_log_status()
1372 "yes" : "no"); in tc35874x_log_status()
1373 v4l2_info(sd, "Color space: %s\n", in tc35874x_log_status()
1374 state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_2X8 ? in tc35874x_log_status()
1375 "YCbCr 422 16-bit" : in tc35874x_log_status()
1376 state->mbus_fmt_code == MEDIA_BUS_FMT_RGB888_1X24 ? in tc35874x_log_status()
1377 "RGB 888 24-bit" : "Unsupported"); in tc35874x_log_status()
1379 v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); in tc35874x_log_status()
1380 v4l2_info(sd, "HDCP encrypted content: %s\n", in tc35874x_log_status()
1381 hdmi_sys_status & MASK_S_HDCP ? "yes" : "no"); in tc35874x_log_status()
1382 v4l2_info(sd, "Input color space: %s %s range\n", in tc35874x_log_status()
1385 if (!is_hdmi(sd)) in tc35874x_log_status()
1387 v4l2_info(sd, "AV Mute: %s\n", hdmi_sys_status & MASK_S_AVMUTE ? "on" : in tc35874x_log_status()
1389 v4l2_info(sd, "Deep color mode: %d-bits per channel\n", in tc35874x_log_status()
1390 deep_color_mode[(i2c_rd8(sd, VI_STATUS1) & in tc35874x_log_status()
1392 print_avi_infoframe(sd); in tc35874x_log_status()
1398 static void tc35874x_print_register_map(struct v4l2_subdev *sd) in tc35874x_print_register_map() argument
1400 v4l2_info(sd, "0x0000-0x00FF: Global Control Register\n"); in tc35874x_print_register_map()
1401 v4l2_info(sd, "0x0100-0x01FF: CSI2-TX PHY Register\n"); in tc35874x_print_register_map()
1402 v4l2_info(sd, "0x0200-0x03FF: CSI2-TX PPI Register\n"); in tc35874x_print_register_map()
1403 v4l2_info(sd, "0x0400-0x05FF: Reserved\n"); in tc35874x_print_register_map()
1404 v4l2_info(sd, "0x0600-0x06FF: CEC Register\n"); in tc35874x_print_register_map()
1405 v4l2_info(sd, "0x0700-0x84FF: Reserved\n"); in tc35874x_print_register_map()
1406 v4l2_info(sd, "0x8500-0x85FF: HDMIRX System Control Register\n"); in tc35874x_print_register_map()
1407 v4l2_info(sd, "0x8600-0x86FF: HDMIRX Audio Control Register\n"); in tc35874x_print_register_map()
1408 v4l2_info(sd, "0x8700-0x87FF: HDMIRX InfoFrame packet data Register\n"); in tc35874x_print_register_map()
1409 v4l2_info(sd, "0x8800-0x88FF: HDMIRX HDCP Port Register\n"); in tc35874x_print_register_map()
1410 v4l2_info(sd, "0x8900-0x89FF: HDMIRX Video Output Port & 3D Register\n"); in tc35874x_print_register_map()
1411 v4l2_info(sd, "0x8A00-0x8BFF: Reserved\n"); in tc35874x_print_register_map()
1412 v4l2_info(sd, "0x8C00-0x8FFF: HDMIRX EDID-RAM (1024bytes)\n"); in tc35874x_print_register_map()
1413 v4l2_info(sd, "0x9000-0x90FF: HDMIRX GBD Extraction Control\n"); in tc35874x_print_register_map()
1414 v4l2_info(sd, "0x9100-0x92FF: HDMIRX GBD RAM read\n"); in tc35874x_print_register_map()
1415 v4l2_info(sd, "0x9300- : Reserved\n"); in tc35874x_print_register_map()
1420 /* REF_01 p. 66-72 */ in tc35874x_get_reg_size()
1431 static int tc35874x_g_register(struct v4l2_subdev *sd, in tc35874x_g_register() argument
1434 if (reg->reg > 0xffff) { in tc35874x_g_register()
1435 tc35874x_print_register_map(sd); in tc35874x_g_register()
1436 return -EINVAL; in tc35874x_g_register()
1439 reg->size = tc35874x_get_reg_size(reg->reg); in tc35874x_g_register()
1441 reg->val = i2c_rdreg(sd, reg->reg, reg->size); in tc35874x_g_register()
1446 static int tc35874x_s_register(struct v4l2_subdev *sd, in tc35874x_s_register() argument
1449 if (reg->reg > 0xffff) { in tc35874x_s_register()
1450 tc35874x_print_register_map(sd); in tc35874x_s_register()
1451 return -EINVAL; in tc35874x_s_register()
1455 * v4l2-dbg command. in tc35874x_s_register()
1460 if (reg->reg == HDCP_MODE || in tc35874x_s_register()
1461 reg->reg == HDCP_REG1 || in tc35874x_s_register()
1462 reg->reg == HDCP_REG2 || in tc35874x_s_register()
1463 reg->reg == HDCP_REG3 || in tc35874x_s_register()
1464 reg->reg == BCAPS) in tc35874x_s_register()
1467 i2c_wrreg(sd, (u16)reg->reg, reg->val, in tc35874x_s_register()
1468 tc35874x_get_reg_size(reg->reg)); in tc35874x_s_register()
1474 static int tc35874x_isr(struct v4l2_subdev *sd, u32 status, bool *handled) in tc35874x_isr() argument
1476 u16 intstatus = i2c_rd16(sd, INTSTATUS); in tc35874x_isr()
1478 v4l2_dbg(1, debug, sd, "%s: IntStatus = 0x%04x\n", __func__, intstatus); in tc35874x_isr()
1481 u8 hdmi_int0 = i2c_rd8(sd, HDMI_INT0); in tc35874x_isr()
1482 u8 hdmi_int1 = i2c_rd8(sd, HDMI_INT1); in tc35874x_isr()
1485 tc35874x_hdmi_misc_int_handler(sd, handled); in tc35874x_isr()
1487 tc35874x_hdmi_cbit_int_handler(sd, handled); in tc35874x_isr()
1489 tc35874x_hdmi_clk_int_handler(sd, handled); in tc35874x_isr()
1491 tc35874x_hdmi_sys_int_handler(sd, handled); in tc35874x_isr()
1493 tc35874x_hdmi_audio_int_handler(sd, handled); in tc35874x_isr()
1495 i2c_wr16(sd, INTSTATUS, MASK_HDMI_INT); in tc35874x_isr()
1500 u32 csi_int = i2c_rd32(sd, CSI_INT); in tc35874x_isr()
1503 tc35874x_csi_err_int_handler(sd, handled); in tc35874x_isr()
1505 i2c_wr16(sd, INTSTATUS, MASK_CSI_INT); in tc35874x_isr()
1508 intstatus = i2c_rd16(sd, INTSTATUS); in tc35874x_isr()
1510 v4l2_dbg(1, debug, sd, in tc35874x_isr()
1523 tc35874x_isr(&state->sd, 0, &handled); in tc35874x_irq_handler()
1533 schedule_work(&state->work_i2c_poll); in tc35874x_irq_poll_timer()
1539 msecs = state->cec_adap ? POLL_INTERVAL_CEC_MS : POLL_INTERVAL_MS; in tc35874x_irq_poll_timer()
1540 mod_timer(&state->timer, jiffies + msecs_to_jiffies(msecs)); in tc35874x_irq_poll_timer()
1549 tc35874x_isr(&state->sd, 0, &handled); in tc35874x_work_i2c_poll()
1552 static int tc35874x_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, in tc35874x_subscribe_event() argument
1555 switch (sub->type) { in tc35874x_subscribe_event()
1557 return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); in tc35874x_subscribe_event()
1559 return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); in tc35874x_subscribe_event()
1561 return -EINVAL; in tc35874x_subscribe_event()
1565 /* --------------- VIDEO OPS --------------- */
1567 static int tc35874x_g_input_status(struct v4l2_subdev *sd, u32 *status) in tc35874x_g_input_status() argument
1570 *status |= no_signal(sd) ? V4L2_IN_ST_NO_SIGNAL : 0; in tc35874x_g_input_status()
1571 *status |= no_sync(sd) ? V4L2_IN_ST_NO_SYNC : 0; in tc35874x_g_input_status()
1573 v4l2_dbg(1, debug, sd, "%s: status = 0x%x\n", __func__, *status); in tc35874x_g_input_status()
1578 static int tc35874x_s_dv_timings(struct v4l2_subdev *sd, in tc35874x_s_dv_timings() argument
1581 struct tc35874x_state *state = to_state(sd); in tc35874x_s_dv_timings()
1584 return -EINVAL; in tc35874x_s_dv_timings()
1587 v4l2_print_dv_timings(sd->name, "tc35874x_s_dv_timings: ", in tc35874x_s_dv_timings()
1590 if (v4l2_match_dv_timings(&state->timings, timings, 0, false)) { in tc35874x_s_dv_timings()
1591 v4l2_dbg(1, debug, sd, "%s: no change\n", __func__); in tc35874x_s_dv_timings()
1597 v4l2_dbg(1, debug, sd, "%s: timings out of range\n", __func__); in tc35874x_s_dv_timings()
1598 return -ERANGE; in tc35874x_s_dv_timings()
1601 state->timings = *timings; in tc35874x_s_dv_timings()
1603 enable_stream(sd, false); in tc35874x_s_dv_timings()
1604 tc35874x_set_pll(sd); in tc35874x_s_dv_timings()
1605 tc35874x_set_csi(sd); in tc35874x_s_dv_timings()
1610 static int tc35874x_g_dv_timings(struct v4l2_subdev *sd, in tc35874x_g_dv_timings() argument
1613 struct tc35874x_state *state = to_state(sd); in tc35874x_g_dv_timings()
1615 *timings = state->timings; in tc35874x_g_dv_timings()
1620 static int tc35874x_enum_dv_timings(struct v4l2_subdev *sd, in tc35874x_enum_dv_timings() argument
1623 if (timings->pad != 0) in tc35874x_enum_dv_timings()
1624 return -EINVAL; in tc35874x_enum_dv_timings()
1630 static int tc35874x_query_dv_timings(struct v4l2_subdev *sd, in tc35874x_query_dv_timings() argument
1635 ret = tc35874x_get_detected_timings(sd, timings); in tc35874x_query_dv_timings()
1640 v4l2_print_dv_timings(sd->name, "tc35874x_query_dv_timings: ", in tc35874x_query_dv_timings()
1645 v4l2_dbg(1, debug, sd, "%s: timings out of range\n", __func__); in tc35874x_query_dv_timings()
1646 return -ERANGE; in tc35874x_query_dv_timings()
1652 static int tc35874x_dv_timings_cap(struct v4l2_subdev *sd, in tc35874x_dv_timings_cap() argument
1655 if (cap->pad != 0) in tc35874x_dv_timings_cap()
1656 return -EINVAL; in tc35874x_dv_timings_cap()
1663 static int tc35874x_g_mbus_config(struct v4l2_subdev *sd, in tc35874x_g_mbus_config() argument
1666 struct tc35874x_state *state = to_state(sd); in tc35874x_g_mbus_config()
1668 cfg->type = V4L2_MBUS_CSI2_DPHY; in tc35874x_g_mbus_config()
1670 /* Support for non-continuous CSI-2 clock is missing in the driver */ in tc35874x_g_mbus_config()
1671 cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; in tc35874x_g_mbus_config()
1673 switch (state->csi_lanes_in_use) { in tc35874x_g_mbus_config()
1675 cfg->flags |= V4L2_MBUS_CSI2_1_LANE; in tc35874x_g_mbus_config()
1678 cfg->flags |= V4L2_MBUS_CSI2_2_LANE; in tc35874x_g_mbus_config()
1681 cfg->flags |= V4L2_MBUS_CSI2_3_LANE; in tc35874x_g_mbus_config()
1684 cfg->flags |= V4L2_MBUS_CSI2_4_LANE; in tc35874x_g_mbus_config()
1687 return -EINVAL; in tc35874x_g_mbus_config()
1693 static int tc35874x_s_stream(struct v4l2_subdev *sd, int enable) in tc35874x_s_stream() argument
1695 enable_stream(sd, enable); in tc35874x_s_stream()
1699 tc35874x_set_csi(sd); in tc35874x_s_stream()
1703 /* --------------- PAD OPS --------------- */
1705 static int tc35874x_enum_mbus_code(struct v4l2_subdev *sd, in tc35874x_enum_mbus_code() argument
1709 switch (code->index) { in tc35874x_enum_mbus_code()
1711 code->code = MEDIA_BUS_FMT_UYVY8_2X8; in tc35874x_enum_mbus_code()
1715 code->code = MEDIA_BUS_FMT_RGB888_1X24; in tc35874x_enum_mbus_code()
1719 return -EINVAL; in tc35874x_enum_mbus_code()
1724 static int tc35874x_enum_frame_sizes(struct v4l2_subdev *sd, in tc35874x_enum_frame_sizes() argument
1728 v4l2_dbg(1, debug, sd, "%s:\n", __func__); in tc35874x_enum_frame_sizes()
1730 if (fse->index >= ARRAY_SIZE(supported_modes)) in tc35874x_enum_frame_sizes()
1731 return -EINVAL; in tc35874x_enum_frame_sizes()
1733 if (fse->code != MEDIA_BUS_FMT_UYVY8_2X8) in tc35874x_enum_frame_sizes()
1734 return -EINVAL; in tc35874x_enum_frame_sizes()
1736 fse->min_width = supported_modes[fse->index].width; in tc35874x_enum_frame_sizes()
1737 fse->max_width = supported_modes[fse->index].width; in tc35874x_enum_frame_sizes()
1738 fse->max_height = supported_modes[fse->index].height; in tc35874x_enum_frame_sizes()
1739 fse->min_height = supported_modes[fse->index].height; in tc35874x_enum_frame_sizes()
1744 static int tc35874x_enum_frame_interval(struct v4l2_subdev *sd, in tc35874x_enum_frame_interval() argument
1748 if (fie->index >= ARRAY_SIZE(supported_modes)) in tc35874x_enum_frame_interval()
1749 return -EINVAL; in tc35874x_enum_frame_interval()
1751 fie->code = MEDIA_BUS_FMT_UYVY8_2X8; in tc35874x_enum_frame_interval()
1753 fie->width = supported_modes[fie->index].width; in tc35874x_enum_frame_interval()
1754 fie->height = supported_modes[fie->index].height; in tc35874x_enum_frame_interval()
1755 fie->interval = supported_modes[fie->index].max_fps; in tc35874x_enum_frame_interval()
1759 static int tc35874x_get_fmt(struct v4l2_subdev *sd, in tc35874x_get_fmt() argument
1763 struct tc35874x_state *state = to_state(sd); in tc35874x_get_fmt()
1764 u8 vi_rep = i2c_rd8(sd, VI_REP); in tc35874x_get_fmt()
1766 format->format.code = state->mbus_fmt_code; in tc35874x_get_fmt()
1767 format->format.width = state->timings.bt.width; in tc35874x_get_fmt()
1768 format->format.height = state->timings.bt.height; in tc35874x_get_fmt()
1769 format->format.field = in tc35874x_get_fmt()
1770 state->timings.bt.interlaced ? in tc35874x_get_fmt()
1776 format->format.colorspace = V4L2_COLORSPACE_SRGB; in tc35874x_get_fmt()
1780 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M; in tc35874x_get_fmt()
1784 format->format.colorspace = V4L2_COLORSPACE_REC709; in tc35874x_get_fmt()
1787 format->format.colorspace = 0; in tc35874x_get_fmt()
1797 return abs(mode->width - framefmt->width) + in tc35874x_get_reso_dist()
1798 abs(mode->height - framefmt->height); in tc35874x_get_reso_dist()
1804 struct v4l2_mbus_framefmt *framefmt = &fmt->format; in tc35874x_find_best_fit()
1807 int cur_best_fit_dist = -1; in tc35874x_find_best_fit()
1812 if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) { in tc35874x_find_best_fit()
1821 static int tc35874x_set_fmt(struct v4l2_subdev *sd, in tc35874x_set_fmt() argument
1825 struct tc35874x_state *state = to_state(sd); in tc35874x_set_fmt()
1828 u32 code = format->format.code; /* is overwritten by get_fmt */ in tc35874x_set_fmt()
1829 int ret = tc35874x_get_fmt(sd, cfg, format); in tc35874x_set_fmt()
1831 format->format.code = code; in tc35874x_set_fmt()
1841 return -EINVAL; in tc35874x_set_fmt()
1844 if (format->which == V4L2_SUBDEV_FORMAT_TRY) in tc35874x_set_fmt()
1847 state->mbus_fmt_code = format->format.code; in tc35874x_set_fmt()
1849 enable_stream(sd, false); in tc35874x_set_fmt()
1851 state->cur_mode = mode; in tc35874x_set_fmt()
1853 __v4l2_ctrl_s_ctrl(state->link_freq, in tc35874x_set_fmt()
1855 __v4l2_ctrl_s_ctrl_int64(state->pixel_rate, in tc35874x_set_fmt()
1858 tc35874x_set_pll(sd); in tc35874x_set_fmt()
1859 tc35874x_set_csi(sd); in tc35874x_set_fmt()
1860 tc35874x_set_csi_color_space(sd); in tc35874x_set_fmt()
1865 static int tc35874x_g_edid(struct v4l2_subdev *sd, in tc35874x_g_edid() argument
1868 struct tc35874x_state *state = to_state(sd); in tc35874x_g_edid()
1870 memset(edid->reserved, 0, sizeof(edid->reserved)); in tc35874x_g_edid()
1872 if (edid->pad != 0) in tc35874x_g_edid()
1873 return -EINVAL; in tc35874x_g_edid()
1875 if (edid->start_block == 0 && edid->blocks == 0) { in tc35874x_g_edid()
1876 edid->blocks = state->edid_blocks_written; in tc35874x_g_edid()
1880 if (state->edid_blocks_written == 0) in tc35874x_g_edid()
1881 return -ENODATA; in tc35874x_g_edid()
1883 if (edid->start_block >= state->edid_blocks_written || in tc35874x_g_edid()
1884 edid->blocks == 0) in tc35874x_g_edid()
1885 return -EINVAL; in tc35874x_g_edid()
1887 if (edid->start_block + edid->blocks > state->edid_blocks_written) in tc35874x_g_edid()
1888 edid->blocks = state->edid_blocks_written - edid->start_block; in tc35874x_g_edid()
1890 i2c_rd(sd, EDID_RAM + (edid->start_block * EDID_BLOCK_SIZE), edid->edid, in tc35874x_g_edid()
1891 edid->blocks * EDID_BLOCK_SIZE); in tc35874x_g_edid()
1896 static int tc35874x_s_edid(struct v4l2_subdev *sd, in tc35874x_s_edid() argument
1899 struct tc35874x_state *state = to_state(sd); in tc35874x_s_edid()
1900 u16 edid_len = edid->blocks * EDID_BLOCK_SIZE; in tc35874x_s_edid()
1903 v4l2_dbg(2, debug, sd, "%s, pad %d, start block %d, blocks %d\n", in tc35874x_s_edid()
1904 __func__, edid->pad, edid->start_block, edid->blocks); in tc35874x_s_edid()
1906 memset(edid->reserved, 0, sizeof(edid->reserved)); in tc35874x_s_edid()
1908 if (edid->pad != 0) in tc35874x_s_edid()
1909 return -EINVAL; in tc35874x_s_edid()
1911 if (edid->start_block != 0) in tc35874x_s_edid()
1912 return -EINVAL; in tc35874x_s_edid()
1914 if (edid->blocks > EDID_NUM_BLOCKS_MAX) { in tc35874x_s_edid()
1915 edid->blocks = EDID_NUM_BLOCKS_MAX; in tc35874x_s_edid()
1916 return -E2BIG; in tc35874x_s_edid()
1919 tc35874x_disable_edid(sd); in tc35874x_s_edid()
1921 i2c_wr8(sd, EDID_LEN1, edid_len & 0xff); in tc35874x_s_edid()
1922 i2c_wr8(sd, EDID_LEN2, edid_len >> 8); in tc35874x_s_edid()
1924 if (edid->blocks == 0) { in tc35874x_s_edid()
1925 state->edid_blocks_written = 0; in tc35874x_s_edid()
1930 i2c_wr(sd, EDID_RAM + i, edid->edid + i, EDID_BLOCK_SIZE); in tc35874x_s_edid()
1931 i2c_wr(sd, EDID_EXT_RAM + i, EDID_extend + i, EDID_BLOCK_SIZE); in tc35874x_s_edid()
1934 state->edid_blocks_written = edid->blocks; in tc35874x_s_edid()
1936 if (tx_5v_power_present(sd)) in tc35874x_s_edid()
1937 tc35874x_enable_edid(sd); in tc35874x_s_edid()
1942 static int tc35874x_g_frame_interval(struct v4l2_subdev *sd, in tc35874x_g_frame_interval() argument
1945 struct tc35874x_state *state = to_state(sd); in tc35874x_g_frame_interval()
1946 const struct tc35874x_mode *mode = state->cur_mode; in tc35874x_g_frame_interval()
1948 mutex_lock(&state->confctl_mutex); in tc35874x_g_frame_interval()
1949 fi->interval = mode->max_fps; in tc35874x_g_frame_interval()
1950 mutex_unlock(&state->confctl_mutex); in tc35874x_g_frame_interval()
1959 strlcpy(inf->base.sensor, TC35874X_NAME, sizeof(inf->base.sensor)); in tc35874x_get_module_inf()
1960 strlcpy(inf->base.module, tc35874x->module_name, in tc35874x_get_module_inf()
1961 sizeof(inf->base.module)); in tc35874x_get_module_inf()
1962 strlcpy(inf->base.lens, tc35874x->len_name, sizeof(inf->base.lens)); in tc35874x_get_module_inf()
1965 static long tc35874x_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) in tc35874x_ioctl() argument
1967 struct tc35874x_state *tc35874x = to_state(sd); in tc35874x_ioctl()
1975 ret = -ENOIOCTLCMD; in tc35874x_ioctl()
1983 static long tc35874x_compat_ioctl32(struct v4l2_subdev *sd, in tc35874x_compat_ioctl32() argument
1995 ret = -ENOMEM; in tc35874x_compat_ioctl32()
1999 ret = tc35874x_ioctl(sd, cmd, inf); in tc35874x_compat_ioctl32()
2003 ret = -EFAULT; in tc35874x_compat_ioctl32()
2010 ret = -ENOMEM; in tc35874x_compat_ioctl32()
2016 ret = tc35874x_ioctl(sd, cmd, cfg); in tc35874x_compat_ioctl32()
2018 ret = -EFAULT; in tc35874x_compat_ioctl32()
2022 ret = -ENOIOCTLCMD; in tc35874x_compat_ioctl32()
2030 /* -------------------------------------------------------------------------- */
2079 /* --------------- CUSTOM CTRLS --------------- */
2082 int ret = -EINVAL; in tc35874x_get_custom_ctrl()
2083 struct tc35874x_state *state = container_of(ctrl->handler, in tc35874x_get_custom_ctrl()
2085 struct v4l2_subdev *sd = &state->sd; in tc35874x_get_custom_ctrl() local
2087 if (ctrl->id == TC35874X_CID_AUDIO_SAMPLING_RATE) { in tc35874x_get_custom_ctrl()
2088 ret = get_audio_sampling_rate(sd); in tc35874x_get_custom_ctrl()
2089 *ctrl->p_new.p_s32 = ret; in tc35874x_get_custom_ctrl()
2122 /* --------------- PROBE / REMOVE --------------- */
2128 gpiod_set_value(state->reset_gpio, 1); in tc35874x_gpio_reset()
2130 gpiod_set_value(state->reset_gpio, 0); in tc35874x_gpio_reset()
2136 struct device *dev = &state->i2c_client->dev; in tc35874x_probe_of()
2141 int ret = -EINVAL; in tc35874x_probe_of()
2145 if (PTR_ERR(refclk) != -EPROBE_DEFER) in tc35874x_probe_of()
2151 ep = of_graph_get_next_endpoint(dev->of_node, NULL); in tc35874x_probe_of()
2154 return -EINVAL; in tc35874x_probe_of()
2166 dev_err(dev, "missing CSI-2 properties in endpoint\n"); in tc35874x_probe_of()
2170 state->csi_lanes_in_use = endpoint.bus.mipi_csi2.num_data_lanes; in tc35874x_probe_of()
2171 state->bus = endpoint.bus.mipi_csi2; in tc35874x_probe_of()
2179 state->pdata.refclk_hz = clk_get_rate(refclk); in tc35874x_probe_of()
2180 state->pdata.ddc5v_delay = DDC5V_DELAY_100_MS; in tc35874x_probe_of()
2181 state->pdata.enable_hdcp = false; in tc35874x_probe_of()
2182 /* A FIFO level of 16 should be enough for 2-lane 720p60 at 594 MHz. */ in tc35874x_probe_of()
2183 state->pdata.fifo_level = 16; in tc35874x_probe_of()
2188 switch (state->pdata.refclk_hz) { in tc35874x_probe_of()
2192 state->pdata.pll_prd = state->pdata.refclk_hz / 6000000; in tc35874x_probe_of()
2196 state->pdata.refclk_hz); in tc35874x_probe_of()
2202 * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60. in tc35874x_probe_of()
2211 state->pdata.pll_fbd = bps_pr_lane / in tc35874x_probe_of()
2212 state->pdata.refclk_hz * state->pdata.pll_prd; in tc35874x_probe_of()
2221 state->pdata.lineinitcnt = 0xe80; in tc35874x_probe_of()
2222 state->pdata.lptxtimecnt = 0x003; in tc35874x_probe_of()
2223 /* tclk-preparecnt: 3, tclk-zerocnt: 20 */ in tc35874x_probe_of()
2224 state->pdata.tclk_headercnt = 0x1403; in tc35874x_probe_of()
2225 state->pdata.tclk_trailcnt = 0x00; in tc35874x_probe_of()
2226 /* ths-preparecnt: 3, ths-zerocnt: 1 */ in tc35874x_probe_of()
2227 state->pdata.ths_headercnt = 0x0103; in tc35874x_probe_of()
2228 state->pdata.twakeup = 0x4882; in tc35874x_probe_of()
2229 state->pdata.tclk_postcnt = 0x008; in tc35874x_probe_of()
2230 state->pdata.ths_trailcnt = 0x2; in tc35874x_probe_of()
2231 state->pdata.hstxvregcnt = 0; in tc35874x_probe_of()
2233 state->reset_gpio = devm_gpiod_get_optional(dev, "reset", in tc35874x_probe_of()
2235 if (IS_ERR(state->reset_gpio)) { in tc35874x_probe_of()
2237 ret = PTR_ERR(state->reset_gpio); in tc35874x_probe_of()
2241 if (state->reset_gpio) in tc35874x_probe_of()
2258 return -ENODEV; in tc35874x_probe_of()
2268 struct tc35874x_platform_data *pdata = client->dev.platform_data; in tc35874x_probe()
2269 struct v4l2_subdev *sd; in tc35874x_probe() local
2271 struct device *dev = &client->dev; in tc35874x_probe()
2272 struct device_node *node = dev->of_node; in tc35874x_probe()
2281 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tc35874x_probe()
2282 return -EIO; in tc35874x_probe()
2284 client->addr << 1, client->adapter->name); in tc35874x_probe()
2286 state = devm_kzalloc(&client->dev, sizeof(struct tc35874x_state), in tc35874x_probe()
2289 return -ENOMEM; in tc35874x_probe()
2292 &state->module_index); in tc35874x_probe()
2294 &state->module_facing); in tc35874x_probe()
2296 &state->module_name); in tc35874x_probe()
2298 &state->len_name); in tc35874x_probe()
2301 return -EINVAL; in tc35874x_probe()
2304 state->i2c_client = client; in tc35874x_probe()
2305 state->cur_mode = &supported_modes[0]; in tc35874x_probe()
2309 state->pdata = *pdata; in tc35874x_probe()
2310 state->bus.flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; in tc35874x_probe()
2313 if (err == -ENODEV) in tc35874x_probe()
2314 v4l_err(client, "No platform data!\n"); in tc35874x_probe()
2319 sd = &state->sd; in tc35874x_probe()
2320 v4l2_i2c_subdev_init(sd, client, &tc35874x_ops); in tc35874x_probe()
2321 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in tc35874x_probe()
2324 data = i2c_rd16(sd, CHIPID) & MASK_CHIPID; in tc35874x_probe()
2330 v4l2_info(sd, "not a tc35874x on address 0x%x\n", in tc35874x_probe()
2331 client->addr << 1); in tc35874x_probe()
2332 return -ENODEV; in tc35874x_probe()
2336 v4l2_ctrl_handler_init(&state->hdl, 4); in tc35874x_probe()
2338 state->link_freq = v4l2_ctrl_new_int_menu(&state->hdl, NULL, in tc35874x_probe()
2341 state->pixel_rate = v4l2_ctrl_new_std(&state->hdl, NULL, in tc35874x_probe()
2345 state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&state->hdl, in tc35874x_probe()
2349 if (state->detect_tx_5v_ctrl) in tc35874x_probe()
2350 state->detect_tx_5v_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in tc35874x_probe()
2353 state->audio_sampling_rate_ctrl = v4l2_ctrl_new_custom(&state->hdl, in tc35874x_probe()
2355 if (state->audio_sampling_rate_ctrl) in tc35874x_probe()
2356 state->audio_sampling_rate_ctrl->flags |= in tc35874x_probe()
2359 state->audio_present_ctrl = v4l2_ctrl_new_custom(&state->hdl, in tc35874x_probe()
2362 sd->ctrl_handler = &state->hdl; in tc35874x_probe()
2363 if (state->hdl.error) { in tc35874x_probe()
2364 err = state->hdl.error; in tc35874x_probe()
2368 if (tc35874x_update_controls(sd)) { in tc35874x_probe()
2369 err = -ENODEV; in tc35874x_probe()
2373 state->pad.flags = MEDIA_PAD_FL_SOURCE; in tc35874x_probe()
2374 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; in tc35874x_probe()
2375 err = media_entity_pads_init(&sd->entity, 1, &state->pad); in tc35874x_probe()
2379 state->mbus_fmt_code = MEDIA_BUS_FMT_UYVY8_2X8; in tc35874x_probe()
2381 sd->dev = &client->dev; in tc35874x_probe()
2383 if (strcmp(state->module_facing, "back") == 0) in tc35874x_probe()
2388 snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s", in tc35874x_probe()
2389 state->module_index, facing, in tc35874x_probe()
2390 TC35874X_NAME, dev_name(sd->dev)); in tc35874x_probe()
2391 err = v4l2_async_register_subdev(sd); in tc35874x_probe()
2395 mutex_init(&state->confctl_mutex); in tc35874x_probe()
2397 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, in tc35874x_probe()
2400 tc35874x_initial_setup(sd); in tc35874x_probe()
2402 tc35874x_s_dv_timings(sd, &default_timing); in tc35874x_probe()
2404 tc35874x_set_csi_color_space(sd); in tc35874x_probe()
2411 tc35874x_s_edid(sd, &def_edid); in tc35874x_probe()
2413 tc35874x_init_interrupts(sd); in tc35874x_probe()
2415 if (state->i2c_client->irq) { in tc35874x_probe()
2416 err = devm_request_threaded_irq(&client->dev, in tc35874x_probe()
2417 state->i2c_client->irq, in tc35874x_probe()
2424 INIT_WORK(&state->work_i2c_poll, in tc35874x_probe()
2426 timer_setup(&state->timer, tc35874x_irq_poll_timer, 0); in tc35874x_probe()
2427 state->timer.expires = jiffies + in tc35874x_probe()
2429 add_timer(&state->timer); in tc35874x_probe()
2432 tc35874x_enable_interrupts(sd, tx_5v_power_present(sd)); in tc35874x_probe()
2433 i2c_wr16(sd, INTMASK, ~(MASK_HDMI_MSK | MASK_CSI_MSK) & 0xffff); in tc35874x_probe()
2435 err = v4l2_ctrl_handler_setup(sd->ctrl_handler); in tc35874x_probe()
2439 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, in tc35874x_probe()
2440 client->addr << 1, client->adapter->name); in tc35874x_probe()
2445 if (!state->i2c_client->irq) in tc35874x_probe()
2446 flush_work(&state->work_i2c_poll); in tc35874x_probe()
2447 cancel_delayed_work(&state->delayed_work_enable_hotplug); in tc35874x_probe()
2448 mutex_destroy(&state->confctl_mutex); in tc35874x_probe()
2450 media_entity_cleanup(&sd->entity); in tc35874x_probe()
2451 v4l2_ctrl_handler_free(&state->hdl); in tc35874x_probe()
2457 struct v4l2_subdev *sd = i2c_get_clientdata(client); in tc35874x_remove() local
2458 struct tc35874x_state *state = to_state(sd); in tc35874x_remove()
2460 if (!state->i2c_client->irq) { in tc35874x_remove()
2461 del_timer_sync(&state->timer); in tc35874x_remove()
2462 flush_work(&state->work_i2c_poll); in tc35874x_remove()
2464 cancel_delayed_work(&state->delayed_work_enable_hotplug); in tc35874x_remove()
2465 v4l2_async_unregister_subdev(sd); in tc35874x_remove()
2466 v4l2_device_unregister_subdev(sd); in tc35874x_remove()
2467 mutex_destroy(&state->confctl_mutex); in tc35874x_remove()
2468 media_entity_cleanup(&sd->entity); in tc35874x_remove()
2469 v4l2_ctrl_handler_free(&state->hdl); in tc35874x_remove()