Lines Matching full:ctrl

123 	struct dp_ctrl_private *ctrl;  in dp_ctrl_push_idle()  local
125 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_push_idle()
127 reinit_completion(&ctrl->idle_comp); in dp_ctrl_push_idle()
128 dp_catalog_ctrl_state_ctrl(ctrl->catalog, DP_STATE_CTRL_PUSH_IDLE); in dp_ctrl_push_idle()
130 if (!wait_for_completion_timeout(&ctrl->idle_comp, in dp_ctrl_push_idle()
134 drm_dbg_dp(ctrl->drm_dev, "mainlink off\n"); in dp_ctrl_push_idle()
137 static void dp_ctrl_config_ctrl(struct dp_ctrl_private *ctrl) in dp_ctrl_config_ctrl() argument
140 const u8 *dpcd = ctrl->panel->dpcd; in dp_ctrl_config_ctrl()
145 if (ctrl->panel->dp_mode.out_fmt_is_yuv_420) in dp_ctrl_config_ctrl()
152 tbd = dp_link_get_test_bits_depth(ctrl->link, in dp_ctrl_config_ctrl()
153 ctrl->panel->dp_mode.bpp); in dp_ctrl_config_ctrl()
158 config |= ((ctrl->link->link_params.num_lanes - 1) in dp_ctrl_config_ctrl()
170 if (ctrl->panel->psr_cap.version) in dp_ctrl_config_ctrl()
173 dp_catalog_ctrl_config_ctrl(ctrl->catalog, config); in dp_ctrl_config_ctrl()
176 static void dp_ctrl_configure_source_params(struct dp_ctrl_private *ctrl) in dp_ctrl_configure_source_params() argument
180 dp_catalog_ctrl_lane_mapping(ctrl->catalog); in dp_ctrl_configure_source_params()
181 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, true); in dp_ctrl_configure_source_params()
182 dp_catalog_setup_peripheral_flush(ctrl->catalog); in dp_ctrl_configure_source_params()
184 dp_ctrl_config_ctrl(ctrl); in dp_ctrl_configure_source_params()
186 tb = dp_link_get_test_bits_depth(ctrl->link, in dp_ctrl_configure_source_params()
187 ctrl->panel->dp_mode.bpp); in dp_ctrl_configure_source_params()
188 cc = dp_link_get_colorimetry_config(ctrl->link); in dp_ctrl_configure_source_params()
189 dp_catalog_ctrl_config_misc(ctrl->catalog, cc, tb); in dp_ctrl_configure_source_params()
190 dp_panel_timing_cfg(ctrl->panel); in dp_ctrl_configure_source_params()
625 static void _dp_ctrl_calc_tu(struct dp_ctrl_private *ctrl, in _dp_ctrl_calc_tu() argument
710 drm_dbg_dp(ctrl->drm_dev, in _dp_ctrl_calc_tu()
746 drm_dbg_dp(ctrl->drm_dev, in _dp_ctrl_calc_tu()
941 drm_dbg_dp(ctrl->drm_dev, "TU: valid_boundary_link: %d\n", in _dp_ctrl_calc_tu()
943 drm_dbg_dp(ctrl->drm_dev, "TU: delay_start_link: %d\n", in _dp_ctrl_calc_tu()
945 drm_dbg_dp(ctrl->drm_dev, "TU: boundary_moderation_en: %d\n", in _dp_ctrl_calc_tu()
947 drm_dbg_dp(ctrl->drm_dev, "TU: valid_lower_boundary_link: %d\n", in _dp_ctrl_calc_tu()
949 drm_dbg_dp(ctrl->drm_dev, "TU: upper_boundary_count: %d\n", in _dp_ctrl_calc_tu()
951 drm_dbg_dp(ctrl->drm_dev, "TU: lower_boundary_count: %d\n", in _dp_ctrl_calc_tu()
953 drm_dbg_dp(ctrl->drm_dev, "TU: tu_size_minus1: %d\n", in _dp_ctrl_calc_tu()
959 static void dp_ctrl_calc_tu_parameters(struct dp_ctrl_private *ctrl, in dp_ctrl_calc_tu_parameters() argument
965 drm_mode = &ctrl->panel->dp_mode.drm_mode; in dp_ctrl_calc_tu_parameters()
967 in.lclk = ctrl->link->link_params.rate / 1000; in dp_ctrl_calc_tu_parameters()
971 in.nlanes = ctrl->link->link_params.num_lanes; in dp_ctrl_calc_tu_parameters()
972 in.bpp = ctrl->panel->dp_mode.bpp; in dp_ctrl_calc_tu_parameters()
973 in.pixel_enc = ctrl->panel->dp_mode.out_fmt_is_yuv_420 ? 420 : 444; in dp_ctrl_calc_tu_parameters()
980 _dp_ctrl_calc_tu(ctrl, &in, tu_table); in dp_ctrl_calc_tu_parameters()
983 static void dp_ctrl_setup_tr_unit(struct dp_ctrl_private *ctrl) in dp_ctrl_setup_tr_unit() argument
990 dp_ctrl_calc_tu_parameters(ctrl, &tu_calc_table); in dp_ctrl_setup_tr_unit()
1006 dp_catalog_ctrl_update_transfer_unit(ctrl->catalog, in dp_ctrl_setup_tr_unit()
1010 static int dp_ctrl_wait4video_ready(struct dp_ctrl_private *ctrl) in dp_ctrl_wait4video_ready() argument
1014 if (!wait_for_completion_timeout(&ctrl->video_comp, in dp_ctrl_wait4video_ready()
1022 static int dp_ctrl_set_vx_px(struct dp_ctrl_private *ctrl, in dp_ctrl_set_vx_px() argument
1025 union phy_configure_opts *phy_opts = &ctrl->phy_opts; in dp_ctrl_set_vx_px()
1031 phy_configure(ctrl->phy, phy_opts); in dp_ctrl_set_vx_px()
1037 static int dp_ctrl_update_vx_px(struct dp_ctrl_private *ctrl) in dp_ctrl_update_vx_px() argument
1039 struct dp_link *link = ctrl->link; in dp_ctrl_update_vx_px()
1046 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_update_vx_px()
1049 ret = dp_ctrl_set_vx_px(ctrl, in dp_ctrl_update_vx_px()
1056 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_update_vx_px()
1063 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_update_vx_px()
1071 lane_cnt = ctrl->link->link_params.num_lanes; in dp_ctrl_update_vx_px()
1076 drm_dbg_dp(ctrl->drm_dev, "sink: p|v=0x%x\n", in dp_ctrl_update_vx_px()
1078 ret = drm_dp_dpcd_write(ctrl->aux, DP_TRAINING_LANE0_SET, in dp_ctrl_update_vx_px()
1086 static bool dp_ctrl_train_pattern_set(struct dp_ctrl_private *ctrl, in dp_ctrl_train_pattern_set() argument
1092 drm_dbg_dp(ctrl->drm_dev, "sink: pattern=%x\n", pattern); in dp_ctrl_train_pattern_set()
1099 ret = drm_dp_dpcd_writeb(ctrl->aux, DP_TRAINING_PATTERN_SET, buf); in dp_ctrl_train_pattern_set()
1103 static int dp_ctrl_read_link_status(struct dp_ctrl_private *ctrl, in dp_ctrl_read_link_status() argument
1108 len = drm_dp_dpcd_read_link_status(ctrl->aux, link_status); in dp_ctrl_read_link_status()
1117 static int dp_ctrl_link_train_1(struct dp_ctrl_private *ctrl, in dp_ctrl_link_train_1() argument
1124 dp_catalog_ctrl_state_ctrl(ctrl->catalog, 0); in dp_ctrl_link_train_1()
1128 ret = dp_catalog_ctrl_set_pattern_state_bit(ctrl->catalog, 1); in dp_ctrl_link_train_1()
1131 dp_ctrl_train_pattern_set(ctrl, DP_TRAINING_PATTERN_1 | in dp_ctrl_link_train_1()
1134 ret = dp_ctrl_update_vx_px(ctrl); in dp_ctrl_link_train_1()
1139 old_v_level = ctrl->link->phy_params.v_level; in dp_ctrl_link_train_1()
1141 drm_dp_link_train_clock_recovery_delay(ctrl->aux, ctrl->panel->dpcd); in dp_ctrl_link_train_1()
1143 ret = dp_ctrl_read_link_status(ctrl, link_status); in dp_ctrl_link_train_1()
1148 ctrl->link->link_params.num_lanes)) { in dp_ctrl_link_train_1()
1152 if (ctrl->link->phy_params.v_level >= in dp_ctrl_link_train_1()
1158 if (old_v_level != ctrl->link->phy_params.v_level) { in dp_ctrl_link_train_1()
1160 old_v_level = ctrl->link->phy_params.v_level; in dp_ctrl_link_train_1()
1163 dp_link_adjust_levels(ctrl->link, link_status); in dp_ctrl_link_train_1()
1164 ret = dp_ctrl_update_vx_px(ctrl); in dp_ctrl_link_train_1()
1173 static int dp_ctrl_link_rate_down_shift(struct dp_ctrl_private *ctrl) in dp_ctrl_link_rate_down_shift() argument
1177 switch (ctrl->link->link_params.rate) { in dp_ctrl_link_rate_down_shift()
1179 ctrl->link->link_params.rate = 540000; in dp_ctrl_link_rate_down_shift()
1182 ctrl->link->link_params.rate = 270000; in dp_ctrl_link_rate_down_shift()
1185 ctrl->link->link_params.rate = 162000; in dp_ctrl_link_rate_down_shift()
1194 drm_dbg_dp(ctrl->drm_dev, "new rate=0x%x\n", in dp_ctrl_link_rate_down_shift()
1195 ctrl->link->link_params.rate); in dp_ctrl_link_rate_down_shift()
1201 static int dp_ctrl_link_lane_down_shift(struct dp_ctrl_private *ctrl) in dp_ctrl_link_lane_down_shift() argument
1204 if (ctrl->link->link_params.num_lanes == 1) in dp_ctrl_link_lane_down_shift()
1207 ctrl->link->link_params.num_lanes /= 2; in dp_ctrl_link_lane_down_shift()
1208 ctrl->link->link_params.rate = ctrl->panel->link_info.rate; in dp_ctrl_link_lane_down_shift()
1210 ctrl->link->phy_params.p_level = 0; in dp_ctrl_link_lane_down_shift()
1211 ctrl->link->phy_params.v_level = 0; in dp_ctrl_link_lane_down_shift()
1216 static void dp_ctrl_clear_training_pattern(struct dp_ctrl_private *ctrl) in dp_ctrl_clear_training_pattern() argument
1218 dp_ctrl_train_pattern_set(ctrl, DP_TRAINING_PATTERN_DISABLE); in dp_ctrl_clear_training_pattern()
1219 drm_dp_link_train_channel_eq_delay(ctrl->aux, ctrl->panel->dpcd); in dp_ctrl_clear_training_pattern()
1222 static int dp_ctrl_link_train_2(struct dp_ctrl_private *ctrl, in dp_ctrl_link_train_2() argument
1231 dp_catalog_ctrl_state_ctrl(ctrl->catalog, 0); in dp_ctrl_link_train_2()
1235 if (drm_dp_tps4_supported(ctrl->panel->dpcd)) { in dp_ctrl_link_train_2()
1238 } else if (drm_dp_tps3_supported(ctrl->panel->dpcd)) { in dp_ctrl_link_train_2()
1246 ret = dp_catalog_ctrl_set_pattern_state_bit(ctrl->catalog, state_ctrl_bit); in dp_ctrl_link_train_2()
1250 dp_ctrl_train_pattern_set(ctrl, pattern); in dp_ctrl_link_train_2()
1253 drm_dp_link_train_channel_eq_delay(ctrl->aux, ctrl->panel->dpcd); in dp_ctrl_link_train_2()
1255 ret = dp_ctrl_read_link_status(ctrl, link_status); in dp_ctrl_link_train_2()
1260 ctrl->link->link_params.num_lanes)) { in dp_ctrl_link_train_2()
1264 dp_link_adjust_levels(ctrl->link, link_status); in dp_ctrl_link_train_2()
1265 ret = dp_ctrl_update_vx_px(ctrl); in dp_ctrl_link_train_2()
1274 static int dp_ctrl_link_train(struct dp_ctrl_private *ctrl, in dp_ctrl_link_train() argument
1278 const u8 *dpcd = ctrl->panel->dpcd; in dp_ctrl_link_train()
1283 dp_ctrl_config_ctrl(ctrl); in dp_ctrl_link_train()
1285 link_info.num_lanes = ctrl->link->link_params.num_lanes; in dp_ctrl_link_train()
1286 link_info.rate = ctrl->link->link_params.rate; in dp_ctrl_link_train()
1289 dp_link_reset_phy_params_vx_px(ctrl->link); in dp_ctrl_link_train()
1291 dp_aux_link_configure(ctrl->aux, &link_info); in dp_ctrl_link_train()
1297 drm_dp_dpcd_write(ctrl->aux, DP_DOWNSPREAD_CTRL, encoding, 2); in dp_ctrl_link_train()
1301 drm_dp_dpcd_write(ctrl->aux, DP_EDP_CONFIGURATION_SET, in dp_ctrl_link_train()
1305 ret = dp_ctrl_link_train_1(ctrl, training_step); in dp_ctrl_link_train()
1312 drm_dbg_dp(ctrl->drm_dev, "link training #1 successful\n"); in dp_ctrl_link_train()
1314 ret = dp_ctrl_link_train_2(ctrl, training_step); in dp_ctrl_link_train()
1321 drm_dbg_dp(ctrl->drm_dev, "link training #2 successful\n"); in dp_ctrl_link_train()
1324 dp_catalog_ctrl_state_ctrl(ctrl->catalog, 0); in dp_ctrl_link_train()
1329 static int dp_ctrl_setup_main_link(struct dp_ctrl_private *ctrl, in dp_ctrl_setup_main_link() argument
1334 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, true); in dp_ctrl_setup_main_link()
1336 if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) in dp_ctrl_setup_main_link()
1345 ret = dp_ctrl_link_train(ctrl, training_step); in dp_ctrl_setup_main_link()
1352 struct dp_ctrl_private *ctrl; in dp_ctrl_core_clk_enable() local
1355 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_core_clk_enable()
1357 if (ctrl->core_clks_on) { in dp_ctrl_core_clk_enable()
1358 drm_dbg_dp(ctrl->drm_dev, "core clks already enabled\n"); in dp_ctrl_core_clk_enable()
1362 ret = clk_bulk_prepare_enable(ctrl->num_core_clks, ctrl->core_clks); in dp_ctrl_core_clk_enable()
1366 ctrl->core_clks_on = true; in dp_ctrl_core_clk_enable()
1368 drm_dbg_dp(ctrl->drm_dev, "enable core clocks \n"); in dp_ctrl_core_clk_enable()
1369 drm_dbg_dp(ctrl->drm_dev, "stream_clks:%s link_clks:%s core_clks:%s\n", in dp_ctrl_core_clk_enable()
1370 ctrl->stream_clks_on ? "on" : "off", in dp_ctrl_core_clk_enable()
1371 ctrl->link_clks_on ? "on" : "off", in dp_ctrl_core_clk_enable()
1372 ctrl->core_clks_on ? "on" : "off"); in dp_ctrl_core_clk_enable()
1379 struct dp_ctrl_private *ctrl; in dp_ctrl_core_clk_disable() local
1381 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_core_clk_disable()
1383 clk_bulk_disable_unprepare(ctrl->num_core_clks, ctrl->core_clks); in dp_ctrl_core_clk_disable()
1385 ctrl->core_clks_on = false; in dp_ctrl_core_clk_disable()
1387 drm_dbg_dp(ctrl->drm_dev, "disable core clocks \n"); in dp_ctrl_core_clk_disable()
1388 drm_dbg_dp(ctrl->drm_dev, "stream_clks:%s link_clks:%s core_clks:%s\n", in dp_ctrl_core_clk_disable()
1389 ctrl->stream_clks_on ? "on" : "off", in dp_ctrl_core_clk_disable()
1390 ctrl->link_clks_on ? "on" : "off", in dp_ctrl_core_clk_disable()
1391 ctrl->core_clks_on ? "on" : "off"); in dp_ctrl_core_clk_disable()
1396 struct dp_ctrl_private *ctrl; in dp_ctrl_link_clk_enable() local
1399 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_link_clk_enable()
1401 if (ctrl->link_clks_on) { in dp_ctrl_link_clk_enable()
1402 drm_dbg_dp(ctrl->drm_dev, "links clks already enabled\n"); in dp_ctrl_link_clk_enable()
1406 if (!ctrl->core_clks_on) { in dp_ctrl_link_clk_enable()
1407 drm_dbg_dp(ctrl->drm_dev, "Enable core clks before link clks\n"); in dp_ctrl_link_clk_enable()
1412 ret = clk_bulk_prepare_enable(ctrl->num_link_clks, ctrl->link_clks); in dp_ctrl_link_clk_enable()
1416 ctrl->link_clks_on = true; in dp_ctrl_link_clk_enable()
1418 drm_dbg_dp(ctrl->drm_dev, "enable link clocks\n"); in dp_ctrl_link_clk_enable()
1419 drm_dbg_dp(ctrl->drm_dev, "stream_clks:%s link_clks:%s core_clks:%s\n", in dp_ctrl_link_clk_enable()
1420 ctrl->stream_clks_on ? "on" : "off", in dp_ctrl_link_clk_enable()
1421 ctrl->link_clks_on ? "on" : "off", in dp_ctrl_link_clk_enable()
1422 ctrl->core_clks_on ? "on" : "off"); in dp_ctrl_link_clk_enable()
1429 struct dp_ctrl_private *ctrl; in dp_ctrl_link_clk_disable() local
1431 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_link_clk_disable()
1433 clk_bulk_disable_unprepare(ctrl->num_link_clks, ctrl->link_clks); in dp_ctrl_link_clk_disable()
1435 ctrl->link_clks_on = false; in dp_ctrl_link_clk_disable()
1437 drm_dbg_dp(ctrl->drm_dev, "disabled link clocks\n"); in dp_ctrl_link_clk_disable()
1438 drm_dbg_dp(ctrl->drm_dev, "stream_clks:%s link_clks:%s core_clks:%s\n", in dp_ctrl_link_clk_disable()
1439 ctrl->stream_clks_on ? "on" : "off", in dp_ctrl_link_clk_disable()
1440 ctrl->link_clks_on ? "on" : "off", in dp_ctrl_link_clk_disable()
1441 ctrl->core_clks_on ? "on" : "off"); in dp_ctrl_link_clk_disable()
1444 static int dp_ctrl_enable_mainlink_clocks(struct dp_ctrl_private *ctrl) in dp_ctrl_enable_mainlink_clocks() argument
1447 struct phy *phy = ctrl->phy; in dp_ctrl_enable_mainlink_clocks()
1448 const u8 *dpcd = ctrl->panel->dpcd; in dp_ctrl_enable_mainlink_clocks()
1450 ctrl->phy_opts.dp.lanes = ctrl->link->link_params.num_lanes; in dp_ctrl_enable_mainlink_clocks()
1451 ctrl->phy_opts.dp.link_rate = ctrl->link->link_params.rate / 100; in dp_ctrl_enable_mainlink_clocks()
1452 ctrl->phy_opts.dp.ssc = drm_dp_max_downspread(dpcd); in dp_ctrl_enable_mainlink_clocks()
1454 phy_configure(phy, &ctrl->phy_opts); in dp_ctrl_enable_mainlink_clocks()
1457 dev_pm_opp_set_rate(ctrl->dev, ctrl->link->link_params.rate * 1000); in dp_ctrl_enable_mainlink_clocks()
1458 ret = dp_ctrl_link_clk_enable(&ctrl->dp_ctrl); in dp_ctrl_enable_mainlink_clocks()
1462 drm_dbg_dp(ctrl->drm_dev, "link rate=%d\n", ctrl->link->link_params.rate); in dp_ctrl_enable_mainlink_clocks()
1469 struct dp_ctrl_private *ctrl; in dp_ctrl_reset_irq_ctrl() local
1471 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_reset_irq_ctrl()
1473 dp_catalog_ctrl_reset(ctrl->catalog); in dp_ctrl_reset_irq_ctrl()
1481 dp_catalog_ctrl_enable_irq(ctrl->catalog, enable); in dp_ctrl_reset_irq_ctrl()
1487 struct dp_ctrl_private *ctrl = container_of(dp_ctrl, in dp_ctrl_config_psr() local
1490 if (!ctrl->panel->psr_cap.version) in dp_ctrl_config_psr()
1493 dp_catalog_ctrl_config_psr(ctrl->catalog); in dp_ctrl_config_psr()
1496 drm_dp_dpcd_write(ctrl->aux, DP_PSR_EN_CFG, &cfg, 1); in dp_ctrl_config_psr()
1501 struct dp_ctrl_private *ctrl = container_of(dp_ctrl, in dp_ctrl_set_psr() local
1504 if (!ctrl->panel->psr_cap.version) in dp_ctrl_set_psr()
1518 reinit_completion(&ctrl->psr_op_comp); in dp_ctrl_set_psr()
1519 dp_catalog_ctrl_set_psr(ctrl->catalog, true); in dp_ctrl_set_psr()
1521 if (!wait_for_completion_timeout(&ctrl->psr_op_comp, in dp_ctrl_set_psr()
1524 dp_catalog_ctrl_set_psr(ctrl->catalog, false); in dp_ctrl_set_psr()
1529 dp_catalog_ctrl_state_ctrl(ctrl->catalog, 0); in dp_ctrl_set_psr()
1531 dp_catalog_ctrl_psr_mainlink_enable(ctrl->catalog, false); in dp_ctrl_set_psr()
1533 dp_catalog_ctrl_psr_mainlink_enable(ctrl->catalog, true); in dp_ctrl_set_psr()
1535 dp_catalog_ctrl_set_psr(ctrl->catalog, false); in dp_ctrl_set_psr()
1536 dp_catalog_ctrl_state_ctrl(ctrl->catalog, DP_STATE_CTRL_SEND_VIDEO); in dp_ctrl_set_psr()
1537 dp_ctrl_wait4video_ready(ctrl); in dp_ctrl_set_psr()
1538 dp_catalog_ctrl_state_ctrl(ctrl->catalog, 0); in dp_ctrl_set_psr()
1544 struct dp_ctrl_private *ctrl; in dp_ctrl_phy_init() local
1547 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_phy_init()
1548 phy = ctrl->phy; in dp_ctrl_phy_init()
1550 dp_catalog_ctrl_phy_reset(ctrl->catalog); in dp_ctrl_phy_init()
1553 drm_dbg_dp(ctrl->drm_dev, "phy=%p init=%d power_on=%d\n", in dp_ctrl_phy_init()
1559 struct dp_ctrl_private *ctrl; in dp_ctrl_phy_exit() local
1562 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_phy_exit()
1563 phy = ctrl->phy; in dp_ctrl_phy_exit()
1565 dp_catalog_ctrl_phy_reset(ctrl->catalog); in dp_ctrl_phy_exit()
1567 drm_dbg_dp(ctrl->drm_dev, "phy=%p init=%d power_on=%d\n", in dp_ctrl_phy_exit()
1571 static int dp_ctrl_reinitialize_mainlink(struct dp_ctrl_private *ctrl) in dp_ctrl_reinitialize_mainlink() argument
1573 struct phy *phy = ctrl->phy; in dp_ctrl_reinitialize_mainlink()
1576 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, false); in dp_ctrl_reinitialize_mainlink()
1577 ctrl->phy_opts.dp.lanes = ctrl->link->link_params.num_lanes; in dp_ctrl_reinitialize_mainlink()
1578 phy_configure(phy, &ctrl->phy_opts); in dp_ctrl_reinitialize_mainlink()
1584 dev_pm_opp_set_rate(ctrl->dev, 0); in dp_ctrl_reinitialize_mainlink()
1586 dp_ctrl_link_clk_disable(&ctrl->dp_ctrl); in dp_ctrl_reinitialize_mainlink()
1592 ret = dp_ctrl_enable_mainlink_clocks(ctrl); in dp_ctrl_reinitialize_mainlink()
1601 static int dp_ctrl_deinitialize_mainlink(struct dp_ctrl_private *ctrl) in dp_ctrl_deinitialize_mainlink() argument
1605 phy = ctrl->phy; in dp_ctrl_deinitialize_mainlink()
1607 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, false); in dp_ctrl_deinitialize_mainlink()
1609 dp_catalog_ctrl_reset(ctrl->catalog); in dp_ctrl_deinitialize_mainlink()
1611 dev_pm_opp_set_rate(ctrl->dev, 0); in dp_ctrl_deinitialize_mainlink()
1612 dp_ctrl_link_clk_disable(&ctrl->dp_ctrl); in dp_ctrl_deinitialize_mainlink()
1620 drm_dbg_dp(ctrl->drm_dev, "phy=%p init=%d power_on=%d\n", in dp_ctrl_deinitialize_mainlink()
1625 static int dp_ctrl_link_maintenance(struct dp_ctrl_private *ctrl) in dp_ctrl_link_maintenance() argument
1630 dp_ctrl_push_idle(&ctrl->dp_ctrl); in dp_ctrl_link_maintenance()
1632 ctrl->link->phy_params.p_level = 0; in dp_ctrl_link_maintenance()
1633 ctrl->link->phy_params.v_level = 0; in dp_ctrl_link_maintenance()
1635 ret = dp_ctrl_setup_main_link(ctrl, &training_step); in dp_ctrl_link_maintenance()
1639 dp_ctrl_clear_training_pattern(ctrl); in dp_ctrl_link_maintenance()
1641 dp_catalog_ctrl_state_ctrl(ctrl->catalog, DP_STATE_CTRL_SEND_VIDEO); in dp_ctrl_link_maintenance()
1643 ret = dp_ctrl_wait4video_ready(ctrl); in dp_ctrl_link_maintenance()
1648 static bool dp_ctrl_send_phy_test_pattern(struct dp_ctrl_private *ctrl) in dp_ctrl_send_phy_test_pattern() argument
1652 u32 pattern_requested = ctrl->link->phy_params.phy_test_pattern_sel; in dp_ctrl_send_phy_test_pattern()
1654 drm_dbg_dp(ctrl->drm_dev, "request: 0x%x\n", pattern_requested); in dp_ctrl_send_phy_test_pattern()
1656 if (dp_ctrl_set_vx_px(ctrl, in dp_ctrl_send_phy_test_pattern()
1657 ctrl->link->phy_params.v_level, in dp_ctrl_send_phy_test_pattern()
1658 ctrl->link->phy_params.p_level)) { in dp_ctrl_send_phy_test_pattern()
1662 dp_catalog_ctrl_send_phy_pattern(ctrl->catalog, pattern_requested); in dp_ctrl_send_phy_test_pattern()
1663 dp_ctrl_update_vx_px(ctrl); in dp_ctrl_send_phy_test_pattern()
1664 dp_link_send_test_response(ctrl->link); in dp_ctrl_send_phy_test_pattern()
1666 pattern_sent = dp_catalog_ctrl_read_phy_pattern(ctrl->catalog); in dp_ctrl_send_phy_test_pattern()
1695 drm_dbg_dp(ctrl->drm_dev, "%s: test->0x%x\n", in dp_ctrl_send_phy_test_pattern()
1700 static int dp_ctrl_process_phy_test_request(struct dp_ctrl_private *ctrl) in dp_ctrl_process_phy_test_request() argument
1705 if (!ctrl->link->phy_params.phy_test_pattern_sel) { in dp_ctrl_process_phy_test_request()
1706 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_process_phy_test_request()
1716 dp_ctrl_off(&ctrl->dp_ctrl); in dp_ctrl_process_phy_test_request()
1718 ret = dp_ctrl_on_link(&ctrl->dp_ctrl); in dp_ctrl_process_phy_test_request()
1724 pixel_rate = ctrl->panel->dp_mode.drm_mode.clock; in dp_ctrl_process_phy_test_request()
1725 ret = clk_set_rate(ctrl->pixel_clk, pixel_rate * 1000); in dp_ctrl_process_phy_test_request()
1731 if (ctrl->stream_clks_on) { in dp_ctrl_process_phy_test_request()
1732 drm_dbg_dp(ctrl->drm_dev, "pixel clks already enabled\n"); in dp_ctrl_process_phy_test_request()
1734 ret = clk_prepare_enable(ctrl->pixel_clk); in dp_ctrl_process_phy_test_request()
1739 ctrl->stream_clks_on = true; in dp_ctrl_process_phy_test_request()
1742 dp_ctrl_send_phy_test_pattern(ctrl); in dp_ctrl_process_phy_test_request()
1749 struct dp_ctrl_private *ctrl; in dp_ctrl_handle_sink_request() local
1757 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_handle_sink_request()
1758 sink_request = ctrl->link->sink_request; in dp_ctrl_handle_sink_request()
1761 drm_dbg_dp(ctrl->drm_dev, "PHY_TEST_PATTERN request\n"); in dp_ctrl_handle_sink_request()
1762 if (dp_ctrl_process_phy_test_request(ctrl)) { in dp_ctrl_handle_sink_request()
1769 if (dp_ctrl_link_maintenance(ctrl)) { in dp_ctrl_handle_sink_request()
1776 dp_link_send_test_response(ctrl->link); in dp_ctrl_handle_sink_request()
1777 if (dp_ctrl_link_maintenance(ctrl)) { in dp_ctrl_handle_sink_request()
1803 static bool dp_ctrl_channel_eq_ok(struct dp_ctrl_private *ctrl) in dp_ctrl_channel_eq_ok() argument
1806 int num_lanes = ctrl->link->link_params.num_lanes; in dp_ctrl_channel_eq_ok()
1808 dp_ctrl_read_link_status(ctrl, link_status); in dp_ctrl_channel_eq_ok()
1816 struct dp_ctrl_private *ctrl; in dp_ctrl_on_link() local
1827 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_on_link()
1829 rate = ctrl->panel->link_info.rate; in dp_ctrl_on_link()
1830 pixel_rate = ctrl->panel->dp_mode.drm_mode.clock; in dp_ctrl_on_link()
1832 dp_ctrl_core_clk_enable(&ctrl->dp_ctrl); in dp_ctrl_on_link()
1834 if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) { in dp_ctrl_on_link()
1835 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_on_link()
1840 ctrl->link->link_params.rate = rate; in dp_ctrl_on_link()
1841 ctrl->link->link_params.num_lanes = in dp_ctrl_on_link()
1842 ctrl->panel->link_info.num_lanes; in dp_ctrl_on_link()
1843 if (ctrl->panel->dp_mode.out_fmt_is_yuv_420) in dp_ctrl_on_link()
1847 drm_dbg_dp(ctrl->drm_dev, "rate=%d, num_lanes=%d, pixel_rate=%lu\n", in dp_ctrl_on_link()
1848 ctrl->link->link_params.rate, ctrl->link->link_params.num_lanes, in dp_ctrl_on_link()
1851 rc = dp_ctrl_enable_mainlink_clocks(ctrl); in dp_ctrl_on_link()
1857 rc = dp_ctrl_setup_main_link(ctrl, &training_step); in dp_ctrl_on_link()
1863 if (!dp_catalog_link_is_connected(ctrl->catalog)) in dp_ctrl_on_link()
1866 dp_ctrl_read_link_status(ctrl, link_status); in dp_ctrl_on_link()
1868 rc = dp_ctrl_link_rate_down_shift(ctrl); in dp_ctrl_on_link()
1871 ctrl->link->link_params.num_lanes)) { in dp_ctrl_on_link()
1876 rc = dp_ctrl_link_lane_down_shift(ctrl); in dp_ctrl_on_link()
1888 if (!dp_catalog_link_is_connected(ctrl->catalog)) in dp_ctrl_on_link()
1891 dp_ctrl_read_link_status(ctrl, link_status); in dp_ctrl_on_link()
1894 ctrl->link->link_params.num_lanes)) in dp_ctrl_on_link()
1895 rc = dp_ctrl_link_rate_down_shift(ctrl); in dp_ctrl_on_link()
1897 rc = dp_ctrl_link_lane_down_shift(ctrl); in dp_ctrl_on_link()
1905 dp_ctrl_clear_training_pattern(ctrl); in dp_ctrl_on_link()
1908 rc = dp_ctrl_reinitialize_mainlink(ctrl); in dp_ctrl_on_link()
1915 if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) in dp_ctrl_on_link()
1929 dp_ctrl_clear_training_pattern(ctrl); in dp_ctrl_on_link()
1931 dp_ctrl_deinitialize_mainlink(ctrl); in dp_ctrl_on_link()
1938 static int dp_ctrl_link_retrain(struct dp_ctrl_private *ctrl) in dp_ctrl_link_retrain() argument
1942 return dp_ctrl_setup_main_link(ctrl, &training_step); in dp_ctrl_link_retrain()
1949 struct dp_ctrl_private *ctrl; in dp_ctrl_on_stream() local
1956 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_on_stream()
1958 pixel_rate = pixel_rate_orig = ctrl->panel->dp_mode.drm_mode.clock; in dp_ctrl_on_stream()
1960 if (dp_ctrl->wide_bus_en || ctrl->panel->dp_mode.out_fmt_is_yuv_420) in dp_ctrl_on_stream()
1963 drm_dbg_dp(ctrl->drm_dev, "rate=%d, num_lanes=%d, pixel_rate=%lu\n", in dp_ctrl_on_stream()
1964 ctrl->link->link_params.rate, in dp_ctrl_on_stream()
1965 ctrl->link->link_params.num_lanes, pixel_rate); in dp_ctrl_on_stream()
1967 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_on_stream()
1969 ctrl->core_clks_on, ctrl->link_clks_on, ctrl->stream_clks_on); in dp_ctrl_on_stream()
1971 if (!ctrl->link_clks_on) { /* link clk is off */ in dp_ctrl_on_stream()
1972 ret = dp_ctrl_enable_mainlink_clocks(ctrl); in dp_ctrl_on_stream()
1979 ret = clk_set_rate(ctrl->pixel_clk, pixel_rate * 1000); in dp_ctrl_on_stream()
1985 if (ctrl->stream_clks_on) { in dp_ctrl_on_stream()
1986 drm_dbg_dp(ctrl->drm_dev, "pixel clks already enabled\n"); in dp_ctrl_on_stream()
1988 ret = clk_prepare_enable(ctrl->pixel_clk); in dp_ctrl_on_stream()
1993 ctrl->stream_clks_on = true; in dp_ctrl_on_stream()
1996 if (force_link_train || !dp_ctrl_channel_eq_ok(ctrl)) in dp_ctrl_on_stream()
1997 dp_ctrl_link_retrain(ctrl); in dp_ctrl_on_stream()
2000 dp_ctrl_clear_training_pattern(ctrl); in dp_ctrl_on_stream()
2006 reinit_completion(&ctrl->video_comp); in dp_ctrl_on_stream()
2008 dp_ctrl_configure_source_params(ctrl); in dp_ctrl_on_stream()
2010 dp_catalog_ctrl_config_msa(ctrl->catalog, in dp_ctrl_on_stream()
2011 ctrl->link->link_params.rate, in dp_ctrl_on_stream()
2013 ctrl->panel->dp_mode.out_fmt_is_yuv_420); in dp_ctrl_on_stream()
2015 dp_ctrl_setup_tr_unit(ctrl); in dp_ctrl_on_stream()
2017 dp_catalog_ctrl_state_ctrl(ctrl->catalog, DP_STATE_CTRL_SEND_VIDEO); in dp_ctrl_on_stream()
2019 ret = dp_ctrl_wait4video_ready(ctrl); in dp_ctrl_on_stream()
2023 mainlink_ready = dp_catalog_ctrl_mainlink_ready(ctrl->catalog); in dp_ctrl_on_stream()
2024 drm_dbg_dp(ctrl->drm_dev, in dp_ctrl_on_stream()
2033 struct dp_ctrl_private *ctrl; in dp_ctrl_off_link_stream() local
2036 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_off_link_stream()
2037 phy = ctrl->phy; in dp_ctrl_off_link_stream()
2039 dp_catalog_panel_disable_vsc_sdp(ctrl->catalog); in dp_ctrl_off_link_stream()
2042 dp_link_psm_config(ctrl->link, &ctrl->panel->link_info, true); in dp_ctrl_off_link_stream()
2044 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, false); in dp_ctrl_off_link_stream()
2046 if (ctrl->stream_clks_on) { in dp_ctrl_off_link_stream()
2047 clk_disable_unprepare(ctrl->pixel_clk); in dp_ctrl_off_link_stream()
2048 ctrl->stream_clks_on = false; in dp_ctrl_off_link_stream()
2051 dev_pm_opp_set_rate(ctrl->dev, 0); in dp_ctrl_off_link_stream()
2052 dp_ctrl_link_clk_disable(&ctrl->dp_ctrl); in dp_ctrl_off_link_stream()
2060 drm_dbg_dp(ctrl->drm_dev, "phy=%p init=%d power_on=%d\n", in dp_ctrl_off_link_stream()
2066 struct dp_ctrl_private *ctrl; in dp_ctrl_off_link() local
2069 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_off_link()
2070 phy = ctrl->phy; in dp_ctrl_off_link()
2072 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, false); in dp_ctrl_off_link()
2074 dp_ctrl_link_clk_disable(&ctrl->dp_ctrl); in dp_ctrl_off_link()
2087 struct dp_ctrl_private *ctrl; in dp_ctrl_off() local
2090 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_off()
2091 phy = ctrl->phy; in dp_ctrl_off()
2093 dp_catalog_panel_disable_vsc_sdp(ctrl->catalog); in dp_ctrl_off()
2095 dp_catalog_ctrl_mainlink_ctrl(ctrl->catalog, false); in dp_ctrl_off()
2097 dp_catalog_ctrl_reset(ctrl->catalog); in dp_ctrl_off()
2099 if (ctrl->stream_clks_on) { in dp_ctrl_off()
2100 clk_disable_unprepare(ctrl->pixel_clk); in dp_ctrl_off()
2101 ctrl->stream_clks_on = false; in dp_ctrl_off()
2104 dev_pm_opp_set_rate(ctrl->dev, 0); in dp_ctrl_off()
2105 dp_ctrl_link_clk_disable(&ctrl->dp_ctrl); in dp_ctrl_off()
2108 drm_dbg_dp(ctrl->drm_dev, "phy=%p init=%d power_on=%d\n", in dp_ctrl_off()
2114 struct dp_ctrl_private *ctrl; in dp_ctrl_isr() local
2121 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_isr()
2123 if (ctrl->panel->psr_cap.version) { in dp_ctrl_isr()
2124 isr = dp_catalog_ctrl_read_psr_interrupt_status(ctrl->catalog); in dp_ctrl_isr()
2127 complete(&ctrl->psr_op_comp); in dp_ctrl_isr()
2130 drm_dbg_dp(ctrl->drm_dev, "PSR exit done\n"); in dp_ctrl_isr()
2133 drm_dbg_dp(ctrl->drm_dev, "PSR frame update done\n"); in dp_ctrl_isr()
2136 drm_dbg_dp(ctrl->drm_dev, "PSR frame capture done\n"); in dp_ctrl_isr()
2139 isr = dp_catalog_ctrl_get_interrupt(ctrl->catalog); in dp_ctrl_isr()
2143 drm_dbg_dp(ctrl->drm_dev, "dp_video_ready\n"); in dp_ctrl_isr()
2144 complete(&ctrl->video_comp); in dp_ctrl_isr()
2149 drm_dbg_dp(ctrl->drm_dev, "idle_patterns_sent\n"); in dp_ctrl_isr()
2150 complete(&ctrl->idle_comp); in dp_ctrl_isr()
2169 struct dp_ctrl_private *ctrl; in dp_ctrl_clk_init() local
2173 ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl); in dp_ctrl_clk_init()
2174 dev = ctrl->dev; in dp_ctrl_clk_init()
2176 ctrl->num_core_clks = ARRAY_SIZE(core_clks); in dp_ctrl_clk_init()
2177 ctrl->core_clks = devm_kcalloc(dev, ctrl->num_core_clks, sizeof(*ctrl->core_clks), GFP_KERNEL); in dp_ctrl_clk_init()
2178 if (!ctrl->core_clks) in dp_ctrl_clk_init()
2181 for (i = 0; i < ctrl->num_core_clks; i++) in dp_ctrl_clk_init()
2182 ctrl->core_clks[i].id = core_clks[i]; in dp_ctrl_clk_init()
2184 rc = devm_clk_bulk_get(dev, ctrl->num_core_clks, ctrl->core_clks); in dp_ctrl_clk_init()
2188 ctrl->num_link_clks = ARRAY_SIZE(ctrl_clks); in dp_ctrl_clk_init()
2189 ctrl->link_clks = devm_kcalloc(dev, ctrl->num_link_clks, sizeof(*ctrl->link_clks), GFP_KERNEL); in dp_ctrl_clk_init()
2190 if (!ctrl->link_clks) in dp_ctrl_clk_init()
2193 for (i = 0; i < ctrl->num_link_clks; i++) in dp_ctrl_clk_init()
2194 ctrl->link_clks[i].id = ctrl_clks[i]; in dp_ctrl_clk_init()
2196 rc = devm_clk_bulk_get(dev, ctrl->num_link_clks, ctrl->link_clks); in dp_ctrl_clk_init()
2200 ctrl->pixel_clk = devm_clk_get(dev, "stream_pixel"); in dp_ctrl_clk_init()
2201 if (IS_ERR(ctrl->pixel_clk)) in dp_ctrl_clk_init()
2202 return PTR_ERR(ctrl->pixel_clk); in dp_ctrl_clk_init()
2212 struct dp_ctrl_private *ctrl; in dp_ctrl_get() local
2221 ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); in dp_ctrl_get()
2222 if (!ctrl) { in dp_ctrl_get()
2239 init_completion(&ctrl->idle_comp); in dp_ctrl_get()
2240 init_completion(&ctrl->psr_op_comp); in dp_ctrl_get()
2241 init_completion(&ctrl->video_comp); in dp_ctrl_get()
2244 ctrl->panel = panel; in dp_ctrl_get()
2245 ctrl->aux = aux; in dp_ctrl_get()
2246 ctrl->link = link; in dp_ctrl_get()
2247 ctrl->catalog = catalog; in dp_ctrl_get()
2248 ctrl->dev = dev; in dp_ctrl_get()
2249 ctrl->phy = phy; in dp_ctrl_get()
2251 ret = dp_ctrl_clk_init(&ctrl->dp_ctrl); in dp_ctrl_get()
2257 return &ctrl->dp_ctrl; in dp_ctrl_get()