Lines Matching +full:force +full:- +full:bt656 +full:- +full:4
1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/v4l2-dv-timings.h>
19 #include <media/v4l2-ctrls.h>
20 #include <media/v4l2-device.h>
21 #include <media/v4l2-dv-timings.h>
22 #include <media/v4l2-event.h>
23 #include <media/v4l2-fwnode.h>
31 #include <dt-bindings/media/tda1997x.h>
40 MODULE_PARM_DESC(debug, "debug level (0-2)");
46 "OBA", /* One-Bit Audio */
71 "Full Range (0-255)",
72 "Limited Range (16-235)",
78 "YUV422 semi-planar", /* YUV422 16bit data base, 8bpp */
79 "YUV422 CCIR656", /* BT656 (YUV 8bpp 2 clock per pixel) */
121 "YUV709 -> RGB full",
122 -256, -2048, -2048,
123 4769, -2183, -873,
129 "YUV601 -> RGB full",
130 -256, -2048, -2048,
131 4769, -3330, -1602,
137 "RGB limited -> RGB full",
138 -256, -256, -256,
145 "RGB limited -> ITU601",
146 -256, -256, -256,
148 -1754, 2095, -341,
149 -1388, -707, 2095,
153 "RGB limited -> ITU709",
154 -256, -256, -256,
156 -1894, 2087, -190,
157 -1607, -477, 2087,
161 "RGB full -> ITU601",
164 -1506, 1799, -293,
165 -1192, -607, 1799,
169 "RGB full -> ITU709",
172 -1627, 1792, -163,
173 -1380, -410, 1792,
303 return &container_of(ctrl->handler, struct tda1997x_state, hdl)->sd; in to_sd()
311 val = i2c_smbus_read_byte_data(state->client_cec, reg); in tda1997x_cec_read()
313 v4l_err(state->client, "read reg error: reg=%2x\n", reg); in tda1997x_cec_read()
314 val = -1; in tda1997x_cec_read()
325 ret = i2c_smbus_write_byte_data(state->client_cec, reg, val); in tda1997x_cec_write()
327 v4l_err(state->client, "write reg error:reg=%2x,val=%2x\n", in tda1997x_cec_write()
329 ret = -1; in tda1997x_cec_write()
335 /* -----------------------------------------------------------------------------
344 if (state->page != page) { in tda1997x_setpage()
345 ret = i2c_smbus_write_byte_data(state->client, in tda1997x_setpage()
348 v4l_err(state->client, in tda1997x_setpage()
353 state->page = page; in tda1997x_setpage()
363 mutex_lock(&state->page_lock); in io_read()
365 val = -1; in io_read()
369 val = i2c_smbus_read_byte_data(state->client, reg&0xff); in io_read()
371 v4l_err(state->client, "read reg error: reg=%2x\n", reg & 0xff); in io_read()
372 val = -1; in io_read()
377 mutex_unlock(&state->page_lock); in io_read()
441 mutex_lock(&state->page_lock); in io_write()
443 ret = -1; in io_write()
447 ret = i2c_smbus_write_byte_data(state->client, reg & 0xff, val); in io_write()
449 v4l_err(state->client, "write reg error:reg=%2x,val=%2x\n", in io_write()
451 ret = -1; in io_write()
456 mutex_unlock(&state->page_lock); in io_write()
489 /* -----------------------------------------------------------------------------
564 struct v4l2_subdev *sd = &state->sd; in tda1997x_delayed_work_enable_hpd()
572 state->edid.present = 1; in tda1997x_delayed_work_enable_hpd()
580 cancel_delayed_work_sync(&state->delayed_work_enable_hpd); in tda1997x_disable_edid()
593 schedule_delayed_work(&state->delayed_work_enable_hpd, HZ / 10); in tda1997x_enable_edid()
596 /* -----------------------------------------------------------------------------
606 v4l_dbg(1, debug, state->client, "%s code=0x%x\n", __func__, code); in tda1997x_setup_format()
612 state->vid_fmt = OF_FMT_444; in tda1997x_setup_format()
617 state->vid_fmt = OF_FMT_422_SMPT; in tda1997x_setup_format()
622 state->vid_fmt = OF_FMT_422_CCIR; in tda1997x_setup_format()
625 v4l_err(state->client, "incompatible format (0x%x)\n", code); in tda1997x_setup_format()
626 return -EINVAL; in tda1997x_setup_format()
628 v4l_dbg(1, debug, state->client, "%s code=0x%x fmt=%s\n", __func__, in tda1997x_setup_format()
629 code, vidfmt_names[state->vid_fmt]); in tda1997x_setup_format()
630 state->mbus_code = code; in tda1997x_setup_format()
638 * full-range and YUV is to be limited range.
640 * RGB full-range uses values from 0 to 255 which is recommended on a monitor
648 struct hdmi_avi_infoframe *avi = &state->avi_infoframe; in tda1997x_configure_csc()
649 struct v4l2_hdmi_colorimetry *c = &state->colorimetry; in tda1997x_configure_csc()
661 v4l_dbg(1, debug, state->client, "input:%s quant:%s output:%s\n", in tda1997x_configure_csc()
662 hdmi_colorspace_names[avi->colorspace], in tda1997x_configure_csc()
663 v4l2_quantization_names[c->quantization], in tda1997x_configure_csc()
664 vidfmt_names[state->vid_fmt]); in tda1997x_configure_csc()
665 state->conv = NULL; in tda1997x_configure_csc()
666 switch (state->vid_fmt) { in tda1997x_configure_csc()
670 if (c->colorspace == V4L2_COLORSPACE_SRGB) { in tda1997x_configure_csc()
671 if (c->quantization == V4L2_QUANTIZATION_LIM_RANGE) in tda1997x_configure_csc()
672 state->conv = &conv_matrix[RGBLIMITED_RGBFULL]; in tda1997x_configure_csc()
674 if (c->colorspace == V4L2_COLORSPACE_REC709) in tda1997x_configure_csc()
675 state->conv = &conv_matrix[ITU709_RGBFULL]; in tda1997x_configure_csc()
676 else if (c->colorspace == V4L2_COLORSPACE_SMPTE170M) in tda1997x_configure_csc()
677 state->conv = &conv_matrix[ITU601_RGBFULL]; in tda1997x_configure_csc()
682 case OF_FMT_422_SMPT: /* semi-planar */ in tda1997x_configure_csc()
685 if ((c->colorspace == V4L2_COLORSPACE_SRGB) && in tda1997x_configure_csc()
686 (c->quantization == V4L2_QUANTIZATION_FULL_RANGE)) { in tda1997x_configure_csc()
687 if (state->timings.bt.height <= 576) in tda1997x_configure_csc()
688 state->conv = &conv_matrix[RGBFULL_ITU601]; in tda1997x_configure_csc()
690 state->conv = &conv_matrix[RGBFULL_ITU709]; in tda1997x_configure_csc()
691 } else if ((c->colorspace == V4L2_COLORSPACE_SRGB) && in tda1997x_configure_csc()
692 (c->quantization == V4L2_QUANTIZATION_LIM_RANGE)) { in tda1997x_configure_csc()
693 if (state->timings.bt.height <= 576) in tda1997x_configure_csc()
694 state->conv = &conv_matrix[RGBLIMITED_ITU601]; in tda1997x_configure_csc()
696 state->conv = &conv_matrix[RGBLIMITED_ITU709]; in tda1997x_configure_csc()
701 if (state->conv) { in tda1997x_configure_csc()
702 v4l_dbg(1, debug, state->client, "%s\n", in tda1997x_configure_csc()
703 state->conv->name); in tda1997x_configure_csc()
709 io_write16(sd, REG_VDP_MATRIX + 0, state->conv->offint1); in tda1997x_configure_csc()
710 io_write16(sd, REG_VDP_MATRIX + 2, state->conv->offint2); in tda1997x_configure_csc()
711 io_write16(sd, REG_VDP_MATRIX + 4, state->conv->offint3); in tda1997x_configure_csc()
713 io_write16(sd, REG_VDP_MATRIX + 6, state->conv->p11coef); in tda1997x_configure_csc()
714 io_write16(sd, REG_VDP_MATRIX + 8, state->conv->p12coef); in tda1997x_configure_csc()
715 io_write16(sd, REG_VDP_MATRIX + 10, state->conv->p13coef); in tda1997x_configure_csc()
716 io_write16(sd, REG_VDP_MATRIX + 12, state->conv->p21coef); in tda1997x_configure_csc()
717 io_write16(sd, REG_VDP_MATRIX + 14, state->conv->p22coef); in tda1997x_configure_csc()
718 io_write16(sd, REG_VDP_MATRIX + 16, state->conv->p23coef); in tda1997x_configure_csc()
719 io_write16(sd, REG_VDP_MATRIX + 18, state->conv->p31coef); in tda1997x_configure_csc()
720 io_write16(sd, REG_VDP_MATRIX + 20, state->conv->p32coef); in tda1997x_configure_csc()
721 io_write16(sd, REG_VDP_MATRIX + 22, state->conv->p33coef); in tda1997x_configure_csc()
723 io_write16(sd, REG_VDP_MATRIX + 24, state->conv->offout1); in tda1997x_configure_csc()
724 io_write16(sd, REG_VDP_MATRIX + 26, state->conv->offout2); in tda1997x_configure_csc()
725 io_write16(sd, REG_VDP_MATRIX + 28, state->conv->offout3); in tda1997x_configure_csc()
735 io_write16(sd, REG_BLK_GY, blanking_codes->code_gy); in tda1997x_configure_csc()
736 io_write16(sd, REG_BLK_BU, blanking_codes->code_bu); in tda1997x_configure_csc()
737 io_write16(sd, REG_BLK_RV, blanking_codes->code_rv); in tda1997x_configure_csc()
746 const struct v4l2_bt_timings *bt = &state->timings.bt; in tda1997x_configure_vhref()
755 href_start = bt->hbackporch + bt->hsync + 1; in tda1997x_configure_vhref()
756 href_end = href_start + bt->width; in tda1997x_configure_vhref()
757 vref_f1_start = bt->height + bt->vbackporch + bt->vsync + in tda1997x_configure_vhref()
758 bt->il_vbackporch + bt->il_vsync + in tda1997x_configure_vhref()
759 bt->il_vfrontporch; in tda1997x_configure_vhref()
760 vref_f1_width = bt->vbackporch + bt->vsync + bt->vfrontporch; in tda1997x_configure_vhref()
765 if (bt->interlaced) { in tda1997x_configure_vhref()
766 vref_f2_start = (bt->height / 2) + in tda1997x_configure_vhref()
767 (bt->il_vbackporch + bt->il_vsync - 1); in tda1997x_configure_vhref()
768 vref_f2_width = bt->il_vbackporch + bt->il_vsync + in tda1997x_configure_vhref()
769 bt->il_vfrontporch; in tda1997x_configure_vhref()
770 fieldref_f2_start = vref_f2_start + bt->il_vfrontporch + in tda1997x_configure_vhref()
786 if (state->chip_revision == 0) in tda1997x_configure_vhref()
787 io_write16(sd, REG_PXCNT_PR, 4); in tda1997x_configure_vhref()
805 * horiz and vert ref values (non-active pixel areas) of the generator in tda1997x_configure_vhref()
830 struct v4l2_subdev *sd = &state->sd; in tda1997x_configure_vidout()
831 struct tda1997x_platform_data *pdata = &state->pdata; in tda1997x_configure_vidout()
836 reg = (state->vid_fmt == OF_FMT_422_CCIR) ? in tda1997x_configure_vidout()
838 reg |= pdata->vidout_delay_pclk << PCLK_DELAY_SHIFT; in tda1997x_configure_vidout()
839 reg |= pdata->vidout_inv_pclk << PCLK_INV_SHIFT; in tda1997x_configure_vidout()
842 /* Configure pre-filter */ in tda1997x_configure_vidout()
845 if ((state->vid_fmt == OF_FMT_422_SMPT) || in tda1997x_configure_vidout()
846 (state->vid_fmt == OF_FMT_422_CCIR)) { in tda1997x_configure_vidout()
854 reg = state->vid_fmt & OF_FMT_MASK; in tda1997x_configure_vidout()
855 if (state->vid_fmt == OF_FMT_422_CCIR) in tda1997x_configure_vidout()
862 /* pre-filter is needed unless (REG_FILTERS_CTRL == 0) */ in tda1997x_configure_vidout()
868 if (state->vid_fmt == OF_FMT_444) in tda1997x_configure_vidout()
874 if ((pdata->vidout_delay_vs < 4) || (pdata->vidout_delay_hs < 4)) in tda1997x_configure_vidout()
879 reg = pdata->vidout_delay_de << DE_FREF_DELAY_SHIFT | in tda1997x_configure_vidout()
880 pdata->vidout_inv_de << DE_FREF_INV_SHIFT | in tda1997x_configure_vidout()
881 pdata->vidout_sel_de << DE_FREF_SEL_SHIFT; in tda1997x_configure_vidout()
885 if (state->vid_fmt != OF_FMT_422_CCIR) { in tda1997x_configure_vidout()
886 reg = pdata->vidout_delay_hs << HS_HREF_DELAY_SHIFT | in tda1997x_configure_vidout()
887 pdata->vidout_inv_hs << HS_HREF_INV_SHIFT | in tda1997x_configure_vidout()
888 pdata->vidout_sel_hs << HS_HREF_SEL_SHIFT; in tda1997x_configure_vidout()
894 if (state->vid_fmt != OF_FMT_422_CCIR) { in tda1997x_configure_vidout()
895 reg = pdata->vidout_delay_vs << VS_VREF_DELAY_SHIFT | in tda1997x_configure_vidout()
896 pdata->vidout_inv_vs << VS_VREF_INV_SHIFT | in tda1997x_configure_vidout()
897 pdata->vidout_sel_vs << VS_VREF_SEL_SHIFT; in tda1997x_configure_vidout()
910 struct tda1997x_platform_data *pdata = &state->pdata; in tda1997x_configure_audout()
914 if (!pdata->audout_format) in tda1997x_configure_audout()
917 /* channel assignment (CEA-861-D Table 20) */ in tda1997x_configure_audout()
922 switch (pdata->audout_format) { in tda1997x_configure_audout()
930 switch (state->audio_type) { in tda1997x_configure_audout()
943 if (pdata->audout_layout == 1) { in tda1997x_configure_audout()
946 if (pdata->audout_format == AUDFMT_TYPE_SPDIF) in tda1997x_configure_audout()
954 if (pdata->audout_width == 32) in tda1997x_configure_audout()
960 if (pdata->audio_auto_mute) in tda1997x_configure_audout()
963 if (pdata->audout_invert_clk) in tda1997x_configure_audout()
968 reg = (pdata->audout_layout) ? AUDIO_LAYOUT_LAYOUT1 : 0; in tda1997x_configure_audout()
969 if (!pdata->audout_layoutauto) in tda1997x_configure_audout()
1006 if (pdata->audout_format == AUDFMT_TYPE_I2S) in tda1997x_configure_audout()
1032 /* Disable REFTIM to restart start-up-sequencer (SUS) */ in tda1997x_hdmi_info_reset()
1045 struct v4l2_subdev *sd = &state->sd; in tda1997x_power_mode()
1094 struct v4l2_subdev *sd = &state->sd; in tda1997x_detect_std()
1111 if (!state->input_detect[0] && !state->input_detect[1]) in tda1997x_detect_std()
1112 return -ENOLINK; in tda1997x_detect_std()
1123 _hper = (u32)bt->pixelclock / width; in tda1997x_detect_std()
1124 if (bt->interlaced) in tda1997x_detect_std()
1126 /* vper +/- 0.7% */ in tda1997x_detect_std()
1129 /* hper +/- 1.0% */ in tda1997x_detect_std()
1132 /* hsper +/- 2 (take care to avoid 32bit overflow) */ in tda1997x_detect_std()
1133 _hsper = 27000 * bt->hsync / ((u32)bt->pixelclock/1000); in tda1997x_detect_std()
1134 hsmin = _hsper - 2; in tda1997x_detect_std()
1144 v4l2_print_dv_timings(sd->name, "Detected format: ", in tda1997x_detect_std()
1153 v4l_err(state->client, "no resolution match for timings: %d/%d/%d\n", in tda1997x_detect_std()
1155 return -ERANGE; in tda1997x_detect_std()
1161 struct v4l2_subdev *sd = &state->sd; in tda1997x_reset_n1()
1221 struct v4l2_hdmi_colorimetry *c = &state->colorimetry; in set_rgb_quantization_range()
1223 state->colorimetry = v4l2_hdmi_rx_colorimetry(&state->avi_infoframe, in set_rgb_quantization_range()
1225 state->timings.bt.height); in set_rgb_quantization_range()
1227 if (c->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) { in set_rgb_quantization_range()
1228 switch (state->rgb_quantization_range) { in set_rgb_quantization_range()
1230 c->quantization = V4L2_QUANTIZATION_FULL_RANGE; in set_rgb_quantization_range()
1233 c->quantization = V4L2_QUANTIZATION_LIM_RANGE; in set_rgb_quantization_range()
1237 v4l_dbg(1, debug, state->client, in set_rgb_quantization_range()
1239 state->avi_infoframe.colorspace, c->colorspace, in set_rgb_quantization_range()
1240 state->avi_infoframe.colorimetry, in set_rgb_quantization_range()
1241 v4l2_quantization_names[c->quantization], in set_rgb_quantization_range()
1242 state->avi_infoframe.content_type); in set_rgb_quantization_range()
1249 struct v4l2_subdev *sd = &state->sd; in tda1997x_parse_infoframe()
1259 v4l_err(state->client, in tda1997x_parse_infoframe()
1264 hdmi_infoframe_log(KERN_INFO, &state->client->dev, &frame); in tda1997x_parse_infoframe()
1271 state->audio_samplerate = 32000; in tda1997x_parse_infoframe()
1274 state->audio_samplerate = 44100; in tda1997x_parse_infoframe()
1277 state->audio_samplerate = 48000; in tda1997x_parse_infoframe()
1280 state->audio_samplerate = 88200; in tda1997x_parse_infoframe()
1283 state->audio_samplerate = 96000; in tda1997x_parse_infoframe()
1286 state->audio_samplerate = 176400; in tda1997x_parse_infoframe()
1289 state->audio_samplerate = 192000; in tda1997x_parse_infoframe()
1299 state->audio_samplesize = 16; in tda1997x_parse_infoframe()
1302 state->audio_samplesize = 20; in tda1997x_parse_infoframe()
1305 state->audio_samplesize = 24; in tda1997x_parse_infoframe()
1313 state->audio_channels = frame.audio.channels; in tda1997x_parse_infoframe()
1315 frame.audio.channel_allocation != state->audio_ch_alloc) { in tda1997x_parse_infoframe()
1317 state->audio_ch_alloc = frame.audio.channel_allocation; in tda1997x_parse_infoframe()
1318 tda1997x_configure_audout(sd, state->audio_ch_alloc); in tda1997x_parse_infoframe()
1326 state->avi_infoframe = frame.avi; in tda1997x_parse_infoframe()
1336 /* ConfigurePixelRepeater: repeat n-times each pixel */ in tda1997x_parse_infoframe()
1353 struct v4l2_subdev *sd = &state->sd; in tda1997x_irq_sus()
1361 if (state->mptrw_in_progress) in tda1997x_irq_sus()
1362 state->mptrw_in_progress = 0; in tda1997x_irq_sus()
1374 state->hdmi_status = 0; in tda1997x_irq_sus()
1387 v4l_err(state->client, "BAD SUS STATUS\n"); in tda1997x_irq_sus()
1393 v4l2_subdev_notify_event(&state->sd, &tda1997x_ev_fmt); in tda1997x_irq_sus()
1399 struct v4l2_subdev *sd = &state->sd; in tda1997x_irq_ddc()
1406 if (state->mptrw_in_progress) in tda1997x_irq_ddc()
1407 state->mptrw_in_progress = 0; in tda1997x_irq_ddc()
1412 v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, in tda1997x_irq_ddc()
1419 struct v4l2_subdev *sd = &state->sd; in tda1997x_irq_rate()
1448 if ((irq_status & mask) != (state->activity_status & mask)) { in tda1997x_irq_rate()
1451 v4l_info(state->client, in tda1997x_irq_rate()
1452 "HDMI-%c: Digital Activity Lost\n", in tda1997x_irq_rate()
1461 if (state->chip_revision == 0) in tda1997x_irq_rate()
1464 state->input_detect[input] = 0; in tda1997x_irq_rate()
1470 v4l_info(state->client, in tda1997x_irq_rate()
1471 "HDMI-%c: Digital Activity Detected\n", in tda1997x_irq_rate()
1473 state->input_detect[input] = 1; in tda1997x_irq_rate()
1477 state->activity_status = (irq_status & mask); in tda1997x_irq_rate()
1484 struct v4l2_subdev *sd = &state->sd; in tda1997x_irq_info()
1511 struct v4l2_subdev *sd = &state->sd; in tda1997x_irq_audio()
1538 state->audio_samplerate = freq[reg & 7]; in tda1997x_irq_audio()
1539 v4l_info(state->client, "Audio Frequency Change: %dHz\n", in tda1997x_irq_audio()
1540 state->audio_samplerate); in tda1997x_irq_audio()
1545 state->audio_type = AUDCFG_TYPE_DST; in tda1997x_irq_audio()
1547 state->audio_type = AUDCFG_TYPE_OBA; in tda1997x_irq_audio()
1549 state->audio_type = AUDCFG_TYPE_HBR; in tda1997x_irq_audio()
1551 state->audio_type = AUDCFG_TYPE_PCM; in tda1997x_irq_audio()
1552 v4l_info(state->client, "Audio Type: %s\n", in tda1997x_irq_audio()
1553 audtype_names[state->audio_type]); in tda1997x_irq_audio()
1559 struct v4l2_subdev *sd = &state->sd; in tda1997x_irq_hdcp()
1567 state->mptrw_in_progress = 0; in tda1997x_irq_hdcp()
1580 struct v4l2_subdev *sd = &state->sd; in tda1997x_isr_thread()
1583 mutex_lock(&state->lock); in tda1997x_isr_thread()
1611 mutex_unlock(&state->lock); in tda1997x_isr_thread()
1616 /* -----------------------------------------------------------------------------
1628 mutex_lock(&state->lock); in tda1997x_g_input_status()
1644 state->input_detect[0], state->input_detect[1], in tda1997x_g_input_status()
1646 if (!state->input_detect[0] && !state->input_detect[1]) in tda1997x_g_input_status()
1652 mutex_unlock(&state->lock); in tda1997x_g_input_status()
1662 v4l_dbg(1, debug, state->client, "%s\n", __func__); in tda1997x_s_dv_timings()
1664 if (v4l2_match_dv_timings(&state->timings, timings, 0, false)) in tda1997x_s_dv_timings()
1669 return -ERANGE; in tda1997x_s_dv_timings()
1671 mutex_lock(&state->lock); in tda1997x_s_dv_timings()
1672 state->timings = *timings; in tda1997x_s_dv_timings()
1677 mutex_unlock(&state->lock); in tda1997x_s_dv_timings()
1687 v4l_dbg(1, debug, state->client, "%s\n", __func__); in tda1997x_g_dv_timings()
1688 mutex_lock(&state->lock); in tda1997x_g_dv_timings()
1689 *timings = state->timings; in tda1997x_g_dv_timings()
1690 mutex_unlock(&state->lock); in tda1997x_g_dv_timings()
1701 v4l_dbg(1, debug, state->client, "%s\n", __func__); in tda1997x_query_dv_timings()
1703 mutex_lock(&state->lock); in tda1997x_query_dv_timings()
1705 mutex_unlock(&state->lock); in tda1997x_query_dv_timings()
1718 /* -----------------------------------------------------------------------------
1729 mf->code = state->mbus_codes[0]; in tda1997x_init_cfg()
1740 v4l_dbg(1, debug, state->client, "%s %d\n", __func__, code->index); in tda1997x_enum_mbus_code()
1741 if (code->index >= ARRAY_SIZE(state->mbus_codes)) in tda1997x_enum_mbus_code()
1742 return -EINVAL; in tda1997x_enum_mbus_code()
1744 if (!state->mbus_codes[code->index]) in tda1997x_enum_mbus_code()
1745 return -EINVAL; in tda1997x_enum_mbus_code()
1747 code->code = state->mbus_codes[code->index]; in tda1997x_enum_mbus_code()
1758 bt = &state->timings.bt; in tda1997x_fill_format()
1759 format->width = bt->width; in tda1997x_fill_format()
1760 format->height = bt->height; in tda1997x_fill_format()
1761 format->colorspace = state->colorimetry.colorspace; in tda1997x_fill_format()
1762 format->field = (bt->interlaced) ? in tda1997x_fill_format()
1772 v4l_dbg(1, debug, state->client, "%s pad=%d which=%d\n", in tda1997x_get_format()
1773 __func__, format->pad, format->which); in tda1997x_get_format()
1775 tda1997x_fill_format(state, &format->format); in tda1997x_get_format()
1777 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in tda1997x_get_format()
1780 fmt = v4l2_subdev_get_try_format(sd, sd_state, format->pad); in tda1997x_get_format()
1781 format->format.code = fmt->code; in tda1997x_get_format()
1783 format->format.code = state->mbus_code; in tda1997x_get_format()
1796 v4l_dbg(1, debug, state->client, "%s pad=%d which=%d fmt=0x%x\n", in tda1997x_set_format()
1797 __func__, format->pad, format->which, format->format.code); in tda1997x_set_format()
1799 for (i = 0; i < ARRAY_SIZE(state->mbus_codes); i++) { in tda1997x_set_format()
1800 if (format->format.code == state->mbus_codes[i]) { in tda1997x_set_format()
1801 code = state->mbus_codes[i]; in tda1997x_set_format()
1806 code = state->mbus_codes[0]; in tda1997x_set_format()
1808 tda1997x_fill_format(state, &format->format); in tda1997x_set_format()
1809 format->format.code = code; in tda1997x_set_format()
1811 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { in tda1997x_set_format()
1814 fmt = v4l2_subdev_get_try_format(sd, sd_state, format->pad); in tda1997x_set_format()
1815 *fmt = format->format; in tda1997x_set_format()
1817 int ret = tda1997x_setup_format(state, format->format.code); in tda1997x_set_format()
1821 /* mbus_code has changed - re-configure csc/vidout */ in tda1997x_set_format()
1833 v4l_dbg(1, debug, state->client, "%s pad=%d\n", __func__, edid->pad); in tda1997x_get_edid()
1834 memset(edid->reserved, 0, sizeof(edid->reserved)); in tda1997x_get_edid()
1836 if (edid->start_block == 0 && edid->blocks == 0) { in tda1997x_get_edid()
1837 edid->blocks = state->edid.blocks; in tda1997x_get_edid()
1841 if (!state->edid.present) in tda1997x_get_edid()
1842 return -ENODATA; in tda1997x_get_edid()
1844 if (edid->start_block >= state->edid.blocks) in tda1997x_get_edid()
1845 return -EINVAL; in tda1997x_get_edid()
1847 if (edid->start_block + edid->blocks > state->edid.blocks) in tda1997x_get_edid()
1848 edid->blocks = state->edid.blocks - edid->start_block; in tda1997x_get_edid()
1850 memcpy(edid->edid, state->edid.edid + edid->start_block * 128, in tda1997x_get_edid()
1851 edid->blocks * 128); in tda1997x_get_edid()
1861 v4l_dbg(1, debug, state->client, "%s pad=%d\n", __func__, edid->pad); in tda1997x_set_edid()
1862 memset(edid->reserved, 0, sizeof(edid->reserved)); in tda1997x_set_edid()
1864 if (edid->start_block != 0) in tda1997x_set_edid()
1865 return -EINVAL; in tda1997x_set_edid()
1867 if (edid->blocks == 0) { in tda1997x_set_edid()
1868 state->edid.blocks = 0; in tda1997x_set_edid()
1869 state->edid.present = 0; in tda1997x_set_edid()
1874 if (edid->blocks > 2) { in tda1997x_set_edid()
1875 edid->blocks = 2; in tda1997x_set_edid()
1876 return -E2BIG; in tda1997x_set_edid()
1883 io_write(sd, REG_EDID_IN_BYTE0 + i, edid->edid[i]); in tda1997x_set_edid()
1887 io_write(sd, REG_EDID_IN_BYTE128 + i, edid->edid[i+128]); in tda1997x_set_edid()
1890 memcpy(state->edid.edid, edid->edid, 256); in tda1997x_set_edid()
1891 state->edid.blocks = edid->blocks; in tda1997x_set_edid()
1923 /* -----------------------------------------------------------------------------
1939 v4l_err(state->client, in tda1997x_log_infoframe()
1944 hdmi_infoframe_log(KERN_INFO, &state->client->dev, &frame); in tda1997x_log_infoframe()
1953 struct hdmi_avi_infoframe *avi = &state->avi_infoframe; in tda1997x_log_status()
1955 v4l2_info(sd, "-----Chip status-----\n"); in tda1997x_log_status()
1956 v4l2_info(sd, "Chip: %s N%d\n", state->info->name, in tda1997x_log_status()
1957 state->chip_revision + 1); in tda1997x_log_status()
1958 v4l2_info(sd, "EDID Enabled: %s\n", state->edid.present ? "yes" : "no"); in tda1997x_log_status()
1960 v4l2_info(sd, "-----Signal status-----\n"); in tda1997x_log_status()
1966 v4l2_info(sd, "-----Video Timings-----\n"); in tda1997x_log_status()
1968 case -ENOLINK: in tda1997x_log_status()
1971 case -ERANGE: in tda1997x_log_status()
1975 v4l2_print_dv_timings(sd->name, "Configured format: ", in tda1997x_log_status()
1976 &state->timings, true); in tda1997x_log_status()
1978 v4l2_info(sd, "-----Color space-----\n"); in tda1997x_log_status()
1980 hdmi_colorspace_names[avi->colorspace], in tda1997x_log_status()
1981 (avi->colorspace == HDMI_COLORSPACE_RGB) ? "" : in tda1997x_log_status()
1982 hdmi_colorimetry_names[avi->colorimetry], in tda1997x_log_status()
1983 v4l2_quantization_names[state->colorimetry.quantization]); in tda1997x_log_status()
1985 vidfmt_names[state->vid_fmt]); in tda1997x_log_status()
1986 v4l2_info(sd, "Color space conversion: %s", state->conv ? in tda1997x_log_status()
1987 state->conv->name : "None"); in tda1997x_log_status()
1989 v4l2_info(sd, "-----Audio-----\n"); in tda1997x_log_status()
1990 if (state->audio_channels) { in tda1997x_log_status()
1991 v4l2_info(sd, "audio: %dch %dHz\n", state->audio_channels, in tda1997x_log_status()
1992 state->audio_samplerate); in tda1997x_log_status()
1997 v4l2_info(sd, "-----Infoframes-----\n"); in tda1997x_log_status()
2009 switch (sub->type) { in tda1997x_subscribe_event()
2015 return -EINVAL; in tda1997x_subscribe_event()
2025 /* -----------------------------------------------------------------------------
2035 /* -----------------------------------------------------------------------------
2044 switch (ctrl->id) { in tda1997x_s_ctrl()
2047 state->rgb_quantization_range = ctrl->val; in tda1997x_s_ctrl()
2053 return -EINVAL; in tda1997x_s_ctrl()
2061 if (ctrl->id == V4L2_CID_DV_RX_IT_CONTENT_TYPE) { in tda1997x_g_volatile_ctrl()
2062 ctrl->val = state->avi_infoframe.content_type; in tda1997x_g_volatile_ctrl()
2065 return -EINVAL; in tda1997x_g_volatile_ctrl()
2076 struct tda1997x_platform_data *pdata = &state->pdata; in tda1997x_core_init()
2082 if (state->chip_revision == 0) { in tda1997x_core_init()
2087 /* reset infoframe at end of start-up-sequencer */ in tda1997x_core_init()
2091 /* Enable TMDS pull-ups */ in tda1997x_core_init()
2147 if (state->chip_revision == 0) in tda1997x_core_init()
2151 if (state->chip_revision == 0) in tda1997x_core_init()
2162 if (state->chip_revision == 0) in tda1997x_core_init()
2167 * and reset SUS to force format detection in tda1997x_core_init()
2182 /* reset start-up-sequencer to force format detection */ in tda1997x_core_init()
2195 v4l_dbg(1, debug, state->client, "vidout_cfg[%d]=0x%02x\n", i, in tda1997x_core_init()
2196 pdata->vidout_port_cfg[i]); in tda1997x_core_init()
2197 io_write(sd, REG_VP35_32_CTRL + i, pdata->vidout_port_cfg[i]); in tda1997x_core_init()
2204 switch (pdata->audout_mclk_fs) { in tda1997x_core_init()
2236 state->hdmi_status = io_read(sd, REG_HDMI_FLAGS); in tda1997x_core_init()
2248 state->supplies); in tda1997x_set_power()
2252 state->supplies); in tda1997x_set_power()
2274 struct tda1997x_platform_data *pdata = &state->pdata; in tda1997x_parse_dt()
2285 * - HREF: active high from start to end of row in tda1997x_parse_dt()
2286 * - VS: Vertical Sync active high at beginning of frame in tda1997x_parse_dt()
2287 * - DE: Active high when data valid in tda1997x_parse_dt()
2288 * - A_CLK: 128*Fs in tda1997x_parse_dt()
2290 pdata->vidout_sel_hs = HS_HREF_SEL_HREF_VHREF; in tda1997x_parse_dt()
2291 pdata->vidout_sel_vs = VS_VREF_SEL_VREF_HDMI; in tda1997x_parse_dt()
2292 pdata->vidout_sel_de = DE_FREF_SEL_DE_VHREF; in tda1997x_parse_dt()
2294 np = state->client->dev.of_node; in tda1997x_parse_dt()
2297 return -EINVAL; in tda1997x_parse_dt()
2305 pdata->vidout_bus_type = bus_cfg.bus_type; in tda1997x_parse_dt()
2310 pdata->vidout_inv_hs = 1; in tda1997x_parse_dt()
2312 pdata->vidout_inv_vs = 1; in tda1997x_parse_dt()
2314 pdata->vidout_inv_de = 1; in tda1997x_parse_dt()
2315 pdata->vidout_bus_width = bus_cfg.bus.parallel.bus_width; in tda1997x_parse_dt()
2318 ret = of_property_count_u32_elems(np, "nxp,vidout-portcfg"); in tda1997x_parse_dt()
2323 of_property_read_u32_index(np, "nxp,vidout-portcfg", in tda1997x_parse_dt()
2325 of_property_read_u32_index(np, "nxp,vidout-portcfg", in tda1997x_parse_dt()
2328 pdata->vidout_port_cfg[reg] = val; in tda1997x_parse_dt()
2331 v4l_err(state->client, "nxp,vidout-portcfg missing\n"); in tda1997x_parse_dt()
2332 return -EINVAL; in tda1997x_parse_dt()
2336 pdata->audout_layoutauto = true; in tda1997x_parse_dt()
2338 pdata->audout_format = AUDFMT_TYPE_DISABLED; in tda1997x_parse_dt()
2339 if (!of_property_read_string(np, "nxp,audout-format", &str)) { in tda1997x_parse_dt()
2341 pdata->audout_format = AUDFMT_TYPE_I2S; in tda1997x_parse_dt()
2343 pdata->audout_format = AUDFMT_TYPE_SPDIF; in tda1997x_parse_dt()
2345 v4l_err(state->client, "nxp,audout-format invalid\n"); in tda1997x_parse_dt()
2346 return -EINVAL; in tda1997x_parse_dt()
2348 if (!of_property_read_u32(np, "nxp,audout-layout", &v)) { in tda1997x_parse_dt()
2354 v4l_err(state->client, in tda1997x_parse_dt()
2355 "nxp,audout-layout invalid\n"); in tda1997x_parse_dt()
2356 return -EINVAL; in tda1997x_parse_dt()
2358 pdata->audout_layout = v; in tda1997x_parse_dt()
2360 if (!of_property_read_u32(np, "nxp,audout-width", &v)) { in tda1997x_parse_dt()
2366 v4l_err(state->client, in tda1997x_parse_dt()
2367 "nxp,audout-width invalid\n"); in tda1997x_parse_dt()
2368 return -EINVAL; in tda1997x_parse_dt()
2370 pdata->audout_width = v; in tda1997x_parse_dt()
2372 if (!of_property_read_u32(np, "nxp,audout-mclk-fs", &v)) { in tda1997x_parse_dt()
2382 v4l_err(state->client, in tda1997x_parse_dt()
2383 "nxp,audout-mclk-fs invalid\n"); in tda1997x_parse_dt()
2384 return -EINVAL; in tda1997x_parse_dt()
2386 pdata->audout_mclk_fs = v; in tda1997x_parse_dt()
2398 state->supplies[i].supply = tda1997x_supply_name[i]; in tda1997x_get_regulators()
2400 return devm_regulator_bulk_get(&state->client->dev, in tda1997x_get_regulators()
2402 state->supplies); in tda1997x_get_regulators()
2407 struct v4l2_subdev *sd = &state->sd; in tda1997x_identify_module()
2413 state->tmdsb_clk = (reg >> 6) & 0x01; /* use tmds clock B_inv for B */ in tda1997x_identify_module()
2414 state->tmdsb_soc = (reg >> 5) & 0x01; /* tmds of input B */ in tda1997x_identify_module()
2415 state->port_30bit = (reg >> 2) & 0x03; /* 30bit vs 24bit */ in tda1997x_identify_module()
2416 state->output_2p5 = (reg >> 1) & 0x01; /* output supply 2.5v */ in tda1997x_identify_module()
2417 switch ((reg >> 4) & 0x03) { in tda1997x_identify_module()
2426 dev_err(&state->client->dev, "unsupported chip ID\n"); in tda1997x_identify_module()
2427 return -EIO; in tda1997x_identify_module()
2429 if (state->info->type != type) { in tda1997x_identify_module()
2430 dev_err(&state->client->dev, "chip id mismatch\n"); in tda1997x_identify_module()
2431 return -EIO; in tda1997x_identify_module()
2435 state->chip_revision = io_read(sd, REG_CMTP_REG11); in tda1997x_identify_module()
2445 /* -----------------------------------------------------------------------------
2449 /* refine sample-rate based on HDMI source */
2454 struct snd_soc_component *component = dai->component; in tda1997x_pcm_startup()
2455 struct snd_pcm_runtime *rtd = substream->runtime; in tda1997x_pcm_startup()
2458 rate = state->audio_samplerate; in tda1997x_pcm_startup()
2462 dev_err(component->dev, "failed to constrain samplerate to %dHz\n", in tda1997x_pcm_startup()
2466 dev_info(component->dev, "set samplerate constraint to %dHz\n", rate); in tda1997x_pcm_startup()
2521 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tda1997x_probe()
2522 return -EIO; in tda1997x_probe()
2526 return -ENOMEM; in tda1997x_probe()
2528 state->client = client; in tda1997x_probe()
2529 pdata = &state->pdata; in tda1997x_probe()
2530 if (IS_ENABLED(CONFIG_OF) && client->dev.of_node) { in tda1997x_probe()
2533 oid = of_match_node(tda1997x_of_id, client->dev.of_node); in tda1997x_probe()
2534 state->info = oid->data; in tda1997x_probe()
2541 } else if (client->dev.platform_data) { in tda1997x_probe()
2543 client->dev.platform_data; in tda1997x_probe()
2544 state->info = in tda1997x_probe()
2545 (const struct tda1997x_chip_info *)id->driver_data; in tda1997x_probe()
2546 state->pdata = *pdata; in tda1997x_probe()
2549 ret = -ENODEV; in tda1997x_probe()
2561 mutex_init(&state->page_lock); in tda1997x_probe()
2562 mutex_init(&state->lock); in tda1997x_probe()
2563 state->page = 0xff; in tda1997x_probe()
2565 INIT_DELAYED_WORK(&state->delayed_work_enable_hpd, in tda1997x_probe()
2574 sd = &state->sd; in tda1997x_probe()
2576 snprintf(sd->name, sizeof(sd->name), "%s %d-%04x", in tda1997x_probe()
2577 id->name, i2c_adapter_id(client->adapter), in tda1997x_probe()
2578 client->addr); in tda1997x_probe()
2579 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; in tda1997x_probe()
2580 sd->entity.function = MEDIA_ENT_F_DV_DECODER; in tda1997x_probe()
2581 sd->entity.ops = &tda1997x_media_ops; in tda1997x_probe()
2583 /* set allowed mbus modes based on chip, bus-type, and bus-width */ in tda1997x_probe()
2585 mbus_codes = state->mbus_codes; in tda1997x_probe()
2586 switch (state->info->type) { in tda1997x_probe()
2588 switch (pdata->vidout_bus_type) { in tda1997x_probe()
2590 switch (pdata->vidout_bus_width) { in tda1997x_probe()
2601 switch (pdata->vidout_bus_width) { in tda1997x_probe()
2616 switch (pdata->vidout_bus_type) { in tda1997x_probe()
2618 switch (pdata->vidout_bus_width) { in tda1997x_probe()
2633 switch (pdata->vidout_bus_width) { in tda1997x_probe()
2653 if (WARN_ON(i > ARRAY_SIZE(state->mbus_codes))) { in tda1997x_probe()
2654 ret = -EINVAL; in tda1997x_probe()
2659 tda1997x_setup_format(state, state->mbus_codes[0]); in tda1997x_probe()
2660 state->timings = cea1920x1080; in tda1997x_probe()
2666 state->colorimetry.colorspace = V4L2_COLORSPACE_SRGB; in tda1997x_probe()
2667 state->colorimetry.quantization = V4L2_QUANTIZATION_FULL_RANGE; in tda1997x_probe()
2674 * shifts in case of embedded sync/or delay lower than 4 in tda1997x_probe()
2676 if (state->chip_revision != 0) { in tda1997x_probe()
2681 v4l_info(client, "NXP %s N%d detected\n", state->info->name, in tda1997x_probe()
2682 state->chip_revision + 1); in tda1997x_probe()
2684 pdata->vidout_bus_width, in tda1997x_probe()
2685 (pdata->vidout_bus_type == V4L2_MBUS_PARALLEL) ? in tda1997x_probe()
2686 "parallel" : "BT656", in tda1997x_probe()
2688 if (pdata->audout_format) { in tda1997x_probe()
2690 pdata->audout_layout ? 2 : 8, in tda1997x_probe()
2691 audfmt_names[pdata->audout_format], in tda1997x_probe()
2692 pdata->audout_layout, in tda1997x_probe()
2693 pdata->audout_mclk_fs); in tda1997x_probe()
2696 ret = 0x34 + ((io_read(sd, REG_SLAVE_ADDR)>>4) & 0x03); in tda1997x_probe()
2697 state->client_cec = devm_i2c_new_dummy_device(&client->dev, in tda1997x_probe()
2698 client->adapter, ret); in tda1997x_probe()
2699 if (IS_ERR(state->client_cec)) { in tda1997x_probe()
2700 ret = PTR_ERR(state->client_cec); in tda1997x_probe()
2711 hdl = &state->hdl; in tda1997x_probe()
2718 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in tda1997x_probe()
2720 state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(hdl, NULL, in tda1997x_probe()
2722 state->rgb_quantization_range_ctrl = v4l2_ctrl_new_std_menu(hdl, in tda1997x_probe()
2726 state->sd.ctrl_handler = hdl; in tda1997x_probe()
2727 if (hdl->error) { in tda1997x_probe()
2728 ret = hdl->error; in tda1997x_probe()
2734 state->pads[TDA1997X_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; in tda1997x_probe()
2735 ret = media_entity_pads_init(&sd->entity, TDA1997X_NUM_PADS, in tda1997x_probe()
2736 state->pads); in tda1997x_probe()
2747 if (pdata->audout_format) { in tda1997x_probe()
2750 if (pdata->audout_width == 32) in tda1997x_probe()
2755 ret = devm_snd_soc_register_component(&state->client->dev, in tda1997x_probe()
2759 dev_err(&client->dev, "register audio codec failed\n"); in tda1997x_probe()
2762 dev_set_drvdata(&state->client->dev, state); in tda1997x_probe()
2763 v4l_info(state->client, "registered audio codec\n"); in tda1997x_probe()
2767 ret = devm_request_threaded_irq(&client->dev, client->irq, in tda1997x_probe()
2772 v4l_err(client, "irq%d reg failed: %d\n", client->irq, ret); in tda1997x_probe()
2779 media_entity_cleanup(&sd->entity); in tda1997x_probe()
2781 v4l2_ctrl_handler_free(&state->hdl); in tda1997x_probe()
2783 cancel_delayed_work(&state->delayed_work_enable_hpd); in tda1997x_probe()
2784 mutex_destroy(&state->page_lock); in tda1997x_probe()
2785 mutex_destroy(&state->lock); in tda1997x_probe()
2788 dev_err(&client->dev, "%s failed: %d\n", __func__, ret); in tda1997x_probe()
2797 struct tda1997x_platform_data *pdata = &state->pdata; in tda1997x_remove()
2799 if (pdata->audout_format) { in tda1997x_remove()
2800 mutex_destroy(&state->audio_lock); in tda1997x_remove()
2803 disable_irq(state->client->irq); in tda1997x_remove()
2807 media_entity_cleanup(&sd->entity); in tda1997x_remove()
2808 v4l2_ctrl_handler_free(&state->hdl); in tda1997x_remove()
2809 regulator_bulk_disable(TDA1997X_NUM_SUPPLIES, state->supplies); in tda1997x_remove()
2810 cancel_delayed_work_sync(&state->delayed_work_enable_hpd); in tda1997x_remove()
2811 mutex_destroy(&state->page_lock); in tda1997x_remove()
2812 mutex_destroy(&state->lock); in tda1997x_remove()