Lines Matching refs:sd

69 	struct v4l2_subdev sd;
92 static void ad9389b_check_monitor_present_status(struct v4l2_subdev *sd);
93 static bool ad9389b_check_edid_status(struct v4l2_subdev *sd);
94 static void ad9389b_setup(struct v4l2_subdev *sd);
95 static int ad9389b_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq);
96 static int ad9389b_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
98 static inline struct ad9389b_state *get_ad9389b_state(struct v4l2_subdev *sd)
100 return container_of(sd, struct ad9389b_state, sd);
105 return &container_of(ctrl->handler, struct ad9389b_state, hdl)->sd;
110 static int ad9389b_rd(struct v4l2_subdev *sd, u8 reg)
112 struct i2c_client *client = v4l2_get_subdevdata(sd);
117 static int ad9389b_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
119 struct i2c_client *client = v4l2_get_subdevdata(sd);
128 v4l2_err(sd, "%s: failed reg 0x%x, val 0x%x\n", __func__, reg, val);
134 static inline void ad9389b_wr_and_or(struct v4l2_subdev *sd, u8 reg,
137 ad9389b_wr(sd, reg, (ad9389b_rd(sd, reg) & clr_mask) | val_mask);
140 static void ad9389b_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf)
142 struct ad9389b_state *state = get_ad9389b_state(sd);
145 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
151 static inline bool ad9389b_have_hotplug(struct v4l2_subdev *sd)
153 return ad9389b_rd(sd, 0x42) & MASK_AD9389B_HPD_DETECT;
156 static inline bool ad9389b_have_rx_sense(struct v4l2_subdev *sd)
158 return ad9389b_rd(sd, 0x42) & MASK_AD9389B_MSEN_DETECT;
161 static void ad9389b_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode)
163 ad9389b_wr_and_or(sd, 0x17, 0xe7, (mode & 0x3)<<3);
164 ad9389b_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5);
167 static void ad9389b_csc_coeff(struct v4l2_subdev *sd,
173 ad9389b_wr_and_or(sd, 0x18, 0xe0, A1>>8);
174 ad9389b_wr(sd, 0x19, A1);
175 ad9389b_wr_and_or(sd, 0x1A, 0xe0, A2>>8);
176 ad9389b_wr(sd, 0x1B, A2);
177 ad9389b_wr_and_or(sd, 0x1c, 0xe0, A3>>8);
178 ad9389b_wr(sd, 0x1d, A3);
179 ad9389b_wr_and_or(sd, 0x1e, 0xe0, A4>>8);
180 ad9389b_wr(sd, 0x1f, A4);
183 ad9389b_wr_and_or(sd, 0x20, 0xe0, B1>>8);
184 ad9389b_wr(sd, 0x21, B1);
185 ad9389b_wr_and_or(sd, 0x22, 0xe0, B2>>8);
186 ad9389b_wr(sd, 0x23, B2);
187 ad9389b_wr_and_or(sd, 0x24, 0xe0, B3>>8);
188 ad9389b_wr(sd, 0x25, B3);
189 ad9389b_wr_and_or(sd, 0x26, 0xe0, B4>>8);
190 ad9389b_wr(sd, 0x27, B4);
193 ad9389b_wr_and_or(sd, 0x28, 0xe0, C1>>8);
194 ad9389b_wr(sd, 0x29, C1);
195 ad9389b_wr_and_or(sd, 0x2A, 0xe0, C2>>8);
196 ad9389b_wr(sd, 0x2B, C2);
197 ad9389b_wr_and_or(sd, 0x2C, 0xe0, C3>>8);
198 ad9389b_wr(sd, 0x2D, C3);
199 ad9389b_wr_and_or(sd, 0x2E, 0xe0, C4>>8);
200 ad9389b_wr(sd, 0x2F, C4);
203 static void ad9389b_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable)
208 ad9389b_csc_conversion_mode(sd, csc_mode);
209 ad9389b_csc_coeff(sd,
214 ad9389b_wr_and_or(sd, 0x3b, 0xfe, 0x1);
216 ad9389b_wr_and_or(sd, 0xcd, 0xf9, 0x02);
219 ad9389b_wr_and_or(sd, 0x3b, 0xfe, 0x0);
221 ad9389b_wr_and_or(sd, 0xcd, 0xf9, 0x04);
225 static void ad9389b_set_IT_content_AVI_InfoFrame(struct v4l2_subdev *sd)
227 struct ad9389b_state *state = get_ad9389b_state(sd);
231 ad9389b_wr_and_or(sd, 0xcd, 0xbf, 0x00);
234 ad9389b_wr_and_or(sd, 0xcd, 0xbf, 0x40);
238 static int ad9389b_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl)
240 struct ad9389b_state *state = get_ad9389b_state(sd);
247 ad9389b_csc_rgb_full2limit(sd, true);
250 ad9389b_csc_rgb_full2limit(sd, false);
255 ad9389b_csc_rgb_full2limit(sd, true);
259 ad9389b_csc_rgb_full2limit(sd, false);
267 static void ad9389b_set_manual_pll_gear(struct v4l2_subdev *sd, u32 pixelclock)
295 ad9389b_wr_and_or(sd, 0x98, 0x0f, gear);
302 struct v4l2_subdev *sd = to_sd(ctrl);
303 struct ad9389b_state *state = get_ad9389b_state(sd);
305 v4l2_dbg(1, debug, sd,
310 ad9389b_wr_and_or(sd, 0xaf, 0xfd,
315 return ad9389b_set_rgb_quantization_mode(sd, ctrl);
326 static int ad9389b_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
328 reg->val = ad9389b_rd(sd, reg->reg & 0xff);
333 static int ad9389b_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
335 ad9389b_wr(sd, reg->reg & 0xff, reg->val & 0xff);
340 static int ad9389b_log_status(struct v4l2_subdev *sd)
342 struct ad9389b_state *state = get_ad9389b_state(sd);
369 v4l2_info(sd, "chip revision %d\n", state->chip_revision);
370 v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off");
371 v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n",
372 (ad9389b_rd(sd, 0x42) & MASK_AD9389B_HPD_DETECT) ?
374 (ad9389b_rd(sd, 0x42) & MASK_AD9389B_MSEN_DETECT) ?
377 v4l2_info(sd, "%s output %s\n",
378 (ad9389b_rd(sd, 0xaf) & 0x02) ?
380 (ad9389b_rd(sd, 0xa1) & 0x3c) ?
382 v4l2_info(sd, "ad9389b: %s\n", (ad9389b_rd(sd, 0xb8) & 0x40) ?
384 v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n",
385 states[ad9389b_rd(sd, 0xc8) & 0xf],
386 errors[ad9389b_rd(sd, 0xc8) >> 4],
388 ad9389b_rd(sd, 0x94), ad9389b_rd(sd, 0x96));
389 manual_gear = ad9389b_rd(sd, 0x98) & 0x80;
390 v4l2_info(sd, "ad9389b: RGB quantization: %s range\n",
391 ad9389b_rd(sd, 0x3b) & 0x01 ? "limited" : "full");
392 v4l2_info(sd, "ad9389b: %s gear %d\n",
394 manual_gear ? ((ad9389b_rd(sd, 0x98) & 0x70) >> 4) :
395 ((ad9389b_rd(sd, 0x9e) & 0x0e) >> 1));
396 if (ad9389b_rd(sd, 0xaf) & 0x02) {
398 u8 manual_cts = ad9389b_rd(sd, 0x0a) & 0x80;
399 u32 N = (ad9389b_rd(sd, 0x01) & 0xf) << 16 |
400 ad9389b_rd(sd, 0x02) << 8 |
401 ad9389b_rd(sd, 0x03);
402 u8 vic_detect = ad9389b_rd(sd, 0x3e) >> 2;
403 u8 vic_sent = ad9389b_rd(sd, 0x3d) & 0x3f;
407 CTS = (ad9389b_rd(sd, 0x07) & 0xf) << 16 |
408 ad9389b_rd(sd, 0x08) << 8 |
409 ad9389b_rd(sd, 0x09);
411 CTS = (ad9389b_rd(sd, 0x04) & 0xf) << 16 |
412 ad9389b_rd(sd, 0x05) << 8 |
413 ad9389b_rd(sd, 0x06);
414 N = (ad9389b_rd(sd, 0x01) & 0xf) << 16 |
415 ad9389b_rd(sd, 0x02) << 8 |
416 ad9389b_rd(sd, 0x03);
418 v4l2_info(sd, "ad9389b: CTS %s mode: N %d, CTS %d\n",
421 v4l2_info(sd, "ad9389b: VIC: detected %d, sent %d\n",
425 v4l2_print_dv_timings(sd->name, "timings: ",
428 v4l2_info(sd, "no timings set\n");
433 static int ad9389b_s_power(struct v4l2_subdev *sd, int on)
435 struct ad9389b_state *state = get_ad9389b_state(sd);
440 v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off");
446 ad9389b_wr_and_or(sd, 0x41, 0xbf, 0x40);
454 ad9389b_wr_and_or(sd, 0x41, 0xbf, 0x0);
455 if ((ad9389b_rd(sd, 0x41) & 0x40) == 0)
457 ad9389b_wr_and_or(sd, 0x41, 0xbf, 0x40);
461 v4l2_dbg(1, debug, sd, "failed to powerup the ad9389b\n");
462 ad9389b_s_power(sd, 0);
466 v4l2_dbg(1, debug, sd,
470 ad9389b_wr_and_or(sd, 0xba, 0xef, 0x10);
473 ad9389b_wr_and_or(sd, 0x98, 0xf0, 0x07);
474 ad9389b_wr(sd, 0x9c, 0x38);
475 ad9389b_wr_and_or(sd, 0x9d, 0xfc, 0x01);
479 ad9389b_wr(sd, 0xa2, pdata->diff_data_drive_strength);
481 ad9389b_wr(sd, 0xa2, 0x87);
484 ad9389b_wr(sd, 0xa3, pdata->diff_clk_drive_strength);
486 ad9389b_wr(sd, 0xa3, 0x87);
488 ad9389b_wr(sd, 0x0a, 0x01);
489 ad9389b_wr(sd, 0xbb, 0xff);
492 ad9389b_wr(sd, 0xc9, 0xf);
497 static void ad9389b_set_isr(struct v4l2_subdev *sd, bool enable)
507 else if (ad9389b_have_hotplug(sd))
519 ad9389b_wr(sd, 0x94, irqs);
520 irqs_rd = ad9389b_rd(sd, 0x94);
524 v4l2_err(sd, "Could not set interrupts: hw failure?\n");
528 static int ad9389b_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
533 ad9389b_set_isr(sd, false);
534 irq_status = ad9389b_rd(sd, 0x96);
536 ad9389b_wr(sd, 0x96, irq_status);
538 ad9389b_set_isr(sd, true);
540 v4l2_dbg(1, debug, sd, "%s: irq_status 0x%x\n", __func__, irq_status);
543 ad9389b_check_monitor_present_status(sd);
545 ad9389b_check_edid_status(sd);
564 static int ad9389b_s_stream(struct v4l2_subdev *sd, int enable)
566 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
568 ad9389b_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c));
570 ad9389b_check_monitor_present_status(sd);
572 ad9389b_s_power(sd, 0);
588 static int ad9389b_s_dv_timings(struct v4l2_subdev *sd,
591 struct ad9389b_state *state = get_ad9389b_state(sd);
593 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
609 ad9389b_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
613 ad9389b_set_manual_pll_gear(sd, (u32)timings->bt.pixelclock);
616 ad9389b_set_IT_content_AVI_InfoFrame(sd);
621 static int ad9389b_g_dv_timings(struct v4l2_subdev *sd,
624 struct ad9389b_state *state = get_ad9389b_state(sd);
626 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
636 static int ad9389b_enum_dv_timings(struct v4l2_subdev *sd,
646 static int ad9389b_dv_timings_cap(struct v4l2_subdev *sd,
664 static int ad9389b_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
666 struct ad9389b_state *state = get_ad9389b_state(sd);
673 v4l2_dbg(1, debug, sd, "EDID segment 0 not found\n");
693 static int ad9389b_s_audio_stream(struct v4l2_subdev *sd, int enable)
695 v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
698 ad9389b_wr_and_or(sd, 0x45, 0x3f, 0x80);
700 ad9389b_wr_and_or(sd, 0x45, 0x3f, 0x40);
705 static int ad9389b_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
722 ad9389b_wr(sd, 0x01, (N >> 16) & 0xf);
723 ad9389b_wr(sd, 0x02, (N >> 8) & 0xff);
724 ad9389b_wr(sd, 0x03, N & 0xff);
729 static int ad9389b_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq)
746 ad9389b_wr_and_or(sd, 0x15, 0xf, i2s_sf);
751 static int ad9389b_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config)
757 ad9389b_wr_and_or(sd, 0x50, 0x1f, 0x20);
759 ad9389b_wr(sd, 0x51, 0x00);
763 ad9389b_wr_and_or(sd, 0x14, 0xf0, 0x02);
785 static void ad9389b_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd,
793 v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment);
799 v4l2_dbg(lvl, debug, sd, "\n");
805 v4l2_dbg(lvl, debug, sd, "%s\n", b);
814 struct v4l2_subdev *sd = &state->sd;
817 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
819 if (ad9389b_check_edid_status(sd)) {
824 if (ad9389b_have_hotplug(sd)) {
830 v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__);
831 ad9389b_s_power(sd, false);
832 ad9389b_s_power(sd, true);
840 ed.segment = ad9389b_rd(sd, 0xc4);
841 v4l2_subdev_notify(sd, AD9389B_EDID_DETECT, (void *)&ed);
842 v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__);
845 static void ad9389b_audio_setup(struct v4l2_subdev *sd)
847 v4l2_dbg(1, debug, sd, "%s\n", __func__);
849 ad9389b_s_i2s_clock_freq(sd, 48000);
850 ad9389b_s_clock_freq(sd, 48000);
851 ad9389b_s_routing(sd, 0, 0, 0);
857 static void ad9389b_setup(struct v4l2_subdev *sd)
859 struct ad9389b_state *state = get_ad9389b_state(sd);
861 v4l2_dbg(1, debug, sd, "%s\n", __func__);
864 ad9389b_wr_and_or(sd, 0x15, 0xf1, 0x0);
866 ad9389b_wr_and_or(sd, 0x16, 0x3f, 0x0);
869 ad9389b_wr_and_or(sd, 0x17, 0xf9, 0x06);
871 ad9389b_wr_and_or(sd, 0x45, 0xc7, 0x08);
873 ad9389b_wr_and_or(sd, 0x46, 0x3f, 0x80);
875 ad9389b_wr(sd, 0x3c, 0x0);
877 ad9389b_wr(sd, 0x47, 0x80);
879 ad9389b_wr_and_or(sd, 0xaf, 0xef, 0x0);
881 ad9389b_wr_and_or(sd, 0xba, 0x1f, 0x60);
883 ad9389b_audio_setup(sd);
887 ad9389b_set_IT_content_AVI_InfoFrame(sd);
890 static void ad9389b_notify_monitor_detect(struct v4l2_subdev *sd)
893 struct ad9389b_state *state = get_ad9389b_state(sd);
896 v4l2_subdev_notify(sd, AD9389B_MONITOR_DETECT, (void *)&mdt);
899 static void ad9389b_update_monitor_present_status(struct v4l2_subdev *sd)
901 struct ad9389b_state *state = get_ad9389b_state(sd);
903 u8 status = ad9389b_rd(sd, 0x42);
905 v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n",
912 v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__);
914 if (!ad9389b_s_power(sd, true)) {
915 v4l2_dbg(1, debug, sd,
919 ad9389b_setup(sd);
920 ad9389b_notify_monitor_detect(sd);
924 v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__);
926 ad9389b_notify_monitor_detect(sd);
927 ad9389b_s_power(sd, false);
932 v4l2_ctrl_s_ctrl(state->hotplug_ctrl, ad9389b_have_hotplug(sd) ? 0x1 : 0x0);
933 v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, ad9389b_have_rx_sense(sd) ? 0x1 : 0x0);
941 static void ad9389b_check_monitor_present_status(struct v4l2_subdev *sd)
943 struct ad9389b_state *state = get_ad9389b_state(sd);
946 ad9389b_update_monitor_present_status(sd);
952 while (state->power_on && (ad9389b_rd(sd, 0x41) & 0x40)) {
954 v4l2_err(sd, "retried %d times, give up\n", retry);
957 v4l2_dbg(1, debug, sd, "%s: reset and re-check status (%d)\n", __func__, retry);
958 ad9389b_notify_monitor_detect(sd);
961 ad9389b_s_power(sd, false);
962 ad9389b_update_monitor_present_status(sd);
976 static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment)
978 struct ad9389b_state *state = get_ad9389b_state(sd);
990 static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment)
995 struct ad9389b_state *state = get_ad9389b_state(sd);
1009 static bool ad9389b_check_edid_status(struct v4l2_subdev *sd)
1011 struct ad9389b_state *state = get_ad9389b_state(sd);
1014 u8 edidRdy = ad9389b_rd(sd, 0xc5);
1016 v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n",
1022 segment = ad9389b_rd(sd, 0xc4);
1024 v4l2_err(sd, "edid segment number too big\n");
1027 v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment);
1028 ad9389b_edid_rd(sd, 256, &state->edid.data[segment * 256]);
1029 ad9389b_dbg_dump_edid(2, debug, sd, segment,
1033 v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n",
1036 if (!edid_verify_crc(sd, segment) ||
1037 !edid_verify_header(sd, segment)) {
1039 v4l2_err(sd, "%s: edid crc or header error\n", __func__);
1040 ad9389b_s_power(sd, false);
1041 ad9389b_s_power(sd, true);
1048 v4l2_dbg(1, debug, sd, "%s: request segment %d\n",
1050 ad9389b_wr(sd, 0xc9, 0xf);
1051 ad9389b_wr(sd, 0xc4, state->edid.segments);
1060 v4l2_subdev_notify(sd, AD9389B_EDID_DETECT, (void *)&ed);
1068 static void ad9389b_init_setup(struct v4l2_subdev *sd)
1070 struct ad9389b_state *state = get_ad9389b_state(sd);
1073 v4l2_dbg(1, debug, sd, "%s\n", __func__);
1076 ad9389b_wr(sd, 0x96, 0xff);
1080 ad9389b_set_isr(sd, false);
1089 struct v4l2_subdev *sd;
1110 sd = &state->sd;
1111 v4l2_i2c_subdev_init(sd, client, &ad9389b_ops);
1112 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1130 sd->ctrl_handler = hdl;
1137 sd->entity.function = MEDIA_ENT_F_DV_ENCODER;
1138 err = media_entity_pads_init(&sd->entity, 1, &state->pad);
1142 state->chip_revision = ad9389b_rd(sd, 0x0);
1144 v4l2_err(sd, "chip_revision %d != 2\n", state->chip_revision);
1148 v4l2_dbg(1, debug, sd, "reg 0x41 0x%x, chip version (reg 0x00) 0x%x\n",
1149 ad9389b_rd(sd, 0x41), state->chip_revision);
1153 v4l2_err(sd, "failed to register edid i2c client\n");
1161 ad9389b_init_setup(sd);
1162 ad9389b_set_isr(sd, true);
1164 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
1169 media_entity_cleanup(&sd->entity);
1179 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1180 struct ad9389b_state *state = get_ad9389b_state(sd);
1184 v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name,
1187 ad9389b_s_stream(sd, false);
1188 ad9389b_s_audio_stream(sd, false);
1189 ad9389b_init_setup(sd);
1192 v4l2_device_unregister_subdev(sd);
1193 media_entity_cleanup(&sd->entity);
1194 v4l2_ctrl_handler_free(sd->ctrl_handler);