We already have this pattern at quite a few places, and moving part of
the modeset helper stuff into the driver will add more.
v2: Don't clobber the crtc struct name with the macro parameter ...
Signed-Off-by: Daniel Vetter daniel.vet...@ffwll.ch
---
drivers/gpu/drm/i915/i915_drv.h |4 +++
drivers/gpu/drm/i915/intel_display.c | 38 -
drivers/gpu/drm/i915/intel_dp.c | 22 +--
3 files changed, 19 insertions(+), 45 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index a0c15ab..aa24fc1 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -79,6 +79,10 @@ enum port {
#define for_each_pipe(p) for ((p) = 0; (p) dev_priv-num_pipe; (p)++)
+#define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
+ list_for_each_entry((intel_encoder), (dev)-mode_config.encoder_list,
base.head) \
+ if ((intel_encoder)-base.crtc == (__crtc))
+
struct intel_pch_pll {
int refcount; /* count of number of CRTCs sharing this PLL */
int active; /* count of number of active CRTCs (i.e. DPMS on) */
diff --git a/drivers/gpu/drm/i915/intel_display.c
b/drivers/gpu/drm/i915/intel_display.c
index 3fbc802..72b73f8 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -627,11 +627,10 @@ static void intel_clock(struct drm_device *dev, int
refclk, intel_clock_t *clock
bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
{
struct drm_device *dev = crtc-dev;
- struct drm_mode_config *mode_config = dev-mode_config;
struct intel_encoder *encoder;
- list_for_each_entry(encoder, mode_config-encoder_list, base.head)
- if (encoder-base.crtc == crtc encoder-type == type)
+ for_each_encoder_on_crtc(dev, crtc, encoder)
+ if (encoder-type == type)
return true;
return false;
@@ -2805,16 +2804,13 @@ static void intel_crtc_wait_for_pending_flips(struct
drm_crtc *crtc)
static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
{
struct drm_device *dev = crtc-dev;
- struct drm_mode_config *mode_config = dev-mode_config;
struct intel_encoder *encoder;
/*
* If there's a non-PCH eDP on this crtc, it must be DP_A, and that
* must be driven by its own crtc; no sharing is possible.
*/
- list_for_each_entry(encoder, mode_config-encoder_list, base.head) {
- if (encoder-base.crtc != crtc)
- continue;
+ for_each_encoder_on_crtc(dev, crtc, encoder) {
/* On Haswell, LPT PCH handles the VGA connection via FDI, and
Haswell
* CPU handles all others */
@@ -3703,16 +3699,12 @@ static bool intel_choose_pipe_bpp_dither(struct
drm_crtc *crtc,
{
struct drm_device *dev = crtc-dev;
struct drm_i915_private *dev_priv = dev-dev_private;
- struct drm_encoder *encoder;
struct drm_connector *connector;
+ struct intel_encoder *intel_encoder;
unsigned int display_bpc = UINT_MAX, bpc;
/* Walk the encoders connectors on this crtc, get min bpc */
- list_for_each_entry(encoder, dev-mode_config.encoder_list, head) {
- struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
-
- if (encoder-crtc != crtc)
- continue;
+ for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
if (intel_encoder-type == INTEL_OUTPUT_LVDS) {
unsigned int lvds_bpc;
@@ -3744,7 +3736,7 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc
*crtc,
/* Not one of the known troublemakers, check the EDID */
list_for_each_entry(connector, dev-mode_config.connector_list,
head) {
- if (connector-encoder != encoder)
+ if (connector-encoder != intel_encoder-base)
continue;
/* Don't use an invalid EDID bpc value */
@@ -4213,15 +4205,11 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
u32 dspcntr, pipeconf, vsyncshift;
bool ok, has_reduced_clock = false, is_sdvo = false;
bool is_lvds = false, is_tv = false, is_dp = false;
- struct drm_mode_config *mode_config = dev-mode_config;
struct intel_encoder *encoder;
const intel_limit_t *limit;
int ret;
- list_for_each_entry(encoder, mode_config-encoder_list, base.head) {
- if (encoder-base.crtc != crtc)
- continue;
-
+ for_each_encoder_on_crtc(dev, crtc, encoder) {
switch (encoder-type) {
case INTEL_OUTPUT_LVDS:
is_lvds = true;
@@ -4524,15 +4512,11 @@ static int ironlake_get_refclk(struct drm_crtc *crtc)