103120fefSJani Nikula // SPDX-License-Identifier: MIT
203120fefSJani Nikula /*
303120fefSJani Nikula  * Copyright © 2022 Intel Corporation
403120fefSJani Nikula  */
503120fefSJani Nikula 
603120fefSJani Nikula #include "i915_drv.h"
703120fefSJani Nikula #include "intel_de.h"
803120fefSJani Nikula #include "intel_display.h"
903120fefSJani Nikula #include "intel_hti.h"
1003120fefSJani Nikula #include "intel_hti_regs.h"
1103120fefSJani Nikula 
intel_hti_init(struct drm_i915_private * i915)1203120fefSJani Nikula void intel_hti_init(struct drm_i915_private *i915)
1303120fefSJani Nikula {
1403120fefSJani Nikula 	/*
1503120fefSJani Nikula 	 * If the platform has HTI, we need to find out whether it has reserved
1603120fefSJani Nikula 	 * any display resources before we create our display outputs.
1703120fefSJani Nikula 	 */
18*5af5169dSMatt Roper 	if (DISPLAY_INFO(i915)->has_hti)
1962749912SJani Nikula 		i915->display.hti.state = intel_de_read(i915, HDPORT_STATE);
2003120fefSJani Nikula }
2103120fefSJani Nikula 
intel_hti_uses_phy(struct drm_i915_private * i915,enum phy phy)2203120fefSJani Nikula bool intel_hti_uses_phy(struct drm_i915_private *i915, enum phy phy)
2303120fefSJani Nikula {
24d1dd9908SJani Nikula 	if (drm_WARN_ON(&i915->drm, phy == PHY_NONE))
25d1dd9908SJani Nikula 		return false;
26d1dd9908SJani Nikula 
2762749912SJani Nikula 	return i915->display.hti.state & HDPORT_ENABLED &&
2862749912SJani Nikula 		i915->display.hti.state & HDPORT_DDI_USED(phy);
2903120fefSJani Nikula }
3003120fefSJani Nikula 
intel_hti_dpll_mask(struct drm_i915_private * i915)3103120fefSJani Nikula u32 intel_hti_dpll_mask(struct drm_i915_private *i915)
3203120fefSJani Nikula {
3362749912SJani Nikula 	if (!(i915->display.hti.state & HDPORT_ENABLED))
3403120fefSJani Nikula 		return 0;
3503120fefSJani Nikula 
3603120fefSJani Nikula 	/*
3703120fefSJani Nikula 	 * Note: This is subtle. The values must coincide with what's defined
3803120fefSJani Nikula 	 * for the platform.
3903120fefSJani Nikula 	 */
4062749912SJani Nikula 	return REG_FIELD_GET(HDPORT_DPLL_USED_MASK, i915->display.hti.state);
4103120fefSJani Nikula }
42