Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1048868ybm; Wed, 27 May 2020 14:53:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7W4/255dobJFejKOLX8nokiynCuSi2/4hZ2qYbOqrgSchAqcguGCfrgMpHa9MNXImklLJ X-Received: by 2002:a50:f09a:: with SMTP id v26mr161496edl.343.1590616434988; Wed, 27 May 2020 14:53:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590616434; cv=none; d=google.com; s=arc-20160816; b=0r4rivlK3pQzUk9pLpSJTt7/a1ESIyNT5ENUaeRXgmtfgfKriHa6asOcqwAKwmf1KJ Z/R4hUOItCZls45BvLpgxPkHa7iaMNmY/2tJGBSbLm+ortchZ5ejKNiimsw0yxM4deA/ XwWgRJa72uoGl+Sro6WAQ6f3OYGB34DPCOMP9PUp6kMYhUu5doVa7j/Q0xnNH5naDuyy Q8U6gPbOzRrRNzUgfSYmSNzNTVRYeraswXIVtWL3S098educbXl/7aXIvOvbmMlKy/Y3 bikIP+voZXcJPvSYDzHjCxuB6y9taKeSIYeboTRDNu9jrfrY/1yBSoGuiVr3OX5Ysk8r SvqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=YlfaQQFIbVFPLgp+Wylmd4RFKyipmTjj6tpheBg9HcQ=; b=uQ7TgS35LV2J3fKsH5YguU2lwiK7Np0C+0FMcqHctA/Iep+b06o1OlUWoyPMvoS/dD bGGtge+DJ0XxC1aoXvmuIrTyd266/VcGXbEp7n9fi2p6932aeRxsEA2+b8D7iUVgVu7/ sJdn9K3XNSLikAHAWJpSqu8z4n1PnxdGOYaiz2nCBSkrWZC2dhANU/8Z0u4G74Jim2Dl mPIH8NqVC9F9MIOoqN8NHv33FdcpZpqRB5WKhcaabSlK/AJUQrdQhgs1jQsQAEBHabQF dJvYbKfRAx7ut3UIkQ5xZxjceifhPYQOBhe1yFrJx7FPWs5vQhOEklDp90sjiUm7Gerq E7EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=Y2AhUEKo; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=aeU9anFO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si374435ejt.432.2020.05.27.14.53.31; Wed, 27 May 2020 14:53:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=Y2AhUEKo; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=aeU9anFO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388800AbgE0Py6 (ORCPT + 98 others); Wed, 27 May 2020 11:54:58 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:60191 "EHLO new1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390297AbgE0PvR (ORCPT ); Wed, 27 May 2020 11:51:17 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 068495801B2; Wed, 27 May 2020 11:51:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 27 May 2020 11:51:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=YlfaQQFIbVFPL gp+Wylmd4RFKyipmTjj6tpheBg9HcQ=; b=Y2AhUEKotTsLtyQ22Mz2LaVaiHYxe wlQ22K+izgsKJEmZFXM9x97mRbgrWDlay2aN2LXEg2Bh6/ZkJ4T9zR9jS3TSTXy4 aLNRyAVPSvSV34xY9vjZR2Lj3yXxLvpzGMAoUcN/zHl8qV3T95MVWcX+Dyn453Jd I0XrdjgFd50wyb7uIU0rY0g0e2yvoRn+bNp0G4g0ldIon1bwenqkb31ysNANDi3S rd/MvAN5/P3EOGq9nmS9wbZV2sSvpftpSEhEytDGnaFovg/QYfIFTypmfh+bN0lr Ly7Z9LE7nUxYWfzh4f/hny5dqy6gZVb1Tie2gq+0Ohh1zeOz27575LoMA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=YlfaQQFIbVFPLgp+Wylmd4RFKyipmTjj6tpheBg9HcQ=; b=aeU9anFO LnU+L0CzXYckkuqVhhewVzCNzBEqkUnhS7wztOLs6AnVWWyorLIG2NmdNlJGx8lB D5R+900772aqVDZmJFWiU3ye6yYZIRHWjG04jgyYiGKidRtlMlacRYbkAkyfBqq5 Y3x1zxJTfw7A2GnuM4wBUqbr2aj7lkRnvk2pE7F+5hLxZjNAMz+jtIP3yu0J5KBF Yg8z+z272uIUnjrQeScvwRu2x4dYsSKeRwzZLN2HBK/8scOTf4hV6czQMqxLvTAH R4T5yjrJQu/Vl9Qmd7vdIA74fP4E4htSISr3vtMJ9Ozilct80Ix79iF8AhoevSoc YA500xzDWi4Rog== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedruddvgedgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgepheefne curfgrrhgrmhepmhgrihhlfhhrohhmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id A359F30614FA; Wed, 27 May 2020 11:51:15 -0400 (EDT) From: Maxime Ripard To: Nicolas Saenz Julienne , Eric Anholt Cc: dri-devel@lists.freedesktop.org, linux-rpi-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Stevenson , Tim Gover , Phil Elwell , Maxime Ripard Subject: [PATCH v3 075/105] drm/vc4: hdmi: Add container_of macros for encoders and connectors Date: Wed, 27 May 2020 17:48:45 +0200 Message-Id: <343f2ebfaf29858cee93de344e1abcd0f4c3555d.1590594512.git-series.maxime@cerno.tech> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whenever the code needs to access the vc4_hdmi structure from a DRM connector or encoder, it first accesses the drm_device associated to the connector, then retrieve the drm_dev private data which gives it a pointer to our vc4_dev, and will finally follow the vc4_hdmi pointer in that structure. That will also give us some trouble when having multiple controllers, but now that we have our encoder and connector structures that are part of vc4_hdmi, we can simply call container_of on the DRM connector or encoder and retrieve the vc4_hdmi structure directly. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_hdmi.c | 41 ++++++++++------------------------- drivers/gpu/drm/vc4/vc4_hdmi.h | 16 ++++++++++++++- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 50c67d674331..4a28e0c0c814 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -121,9 +121,7 @@ static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused) static enum drm_connector_status vc4_hdmi_connector_detect(struct drm_connector *connector, bool force) { - struct drm_device *dev = connector->dev; - struct vc4_dev *vc4 = to_vc4_dev(dev); - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); if (vc4_hdmi->hpd_gpio) { if (gpio_get_value_cansleep(vc4_hdmi->hpd_gpio) ^ @@ -150,17 +148,13 @@ static void vc4_hdmi_connector_destroy(struct drm_connector *connector) static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) { - struct vc4_hdmi_connector *vc4_connector = - to_vc4_hdmi_connector(connector); - struct drm_encoder *encoder = vc4_connector->encoder; - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); - struct drm_device *dev = connector->dev; - struct vc4_dev *vc4 = to_vc4_dev(dev); + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); + struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder; int ret = 0; struct edid *edid; - edid = drm_get_edid(connector, vc4->hdmi->ddc); - cec_s_phys_addr_from_edid(vc4->hdmi->cec_adap, edid); + edid = drm_get_edid(connector, vc4_hdmi->ddc); + cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid); if (!edid) return -ENODEV; @@ -229,9 +223,7 @@ static int vc4_hdmi_connector_init(struct drm_device *dev, static int vc4_hdmi_stop_packet(struct drm_encoder *encoder, enum hdmi_infoframe_type type) { - struct drm_device *dev = encoder->dev; - struct vc4_dev *vc4 = to_vc4_dev(dev); - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); u32 packet_id = type - 0x80; HDMI_WRITE(VC4_HDMI_RAM_PACKET_CONFIG, @@ -244,9 +236,7 @@ static int vc4_hdmi_stop_packet(struct drm_encoder *encoder, static void vc4_hdmi_write_infoframe(struct drm_encoder *encoder, union hdmi_infoframe *frame) { - struct drm_device *dev = encoder->dev; - struct vc4_dev *vc4 = to_vc4_dev(dev); - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); u32 packet_id = frame->any.type - 0x80; u32 packet_reg = VC4_HDMI_RAM_PACKET(packet_id); uint8_t buffer[VC4_HDMI_PACKET_STRIDE]; @@ -292,9 +282,8 @@ static void vc4_hdmi_write_infoframe(struct drm_encoder *encoder, static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder) { + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); - struct vc4_dev *vc4 = encoder->dev->dev_private; - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; struct drm_connector *connector = &vc4_hdmi->connector.base; struct drm_connector_state *cstate = connector->state; struct drm_crtc *crtc = encoder->crtc; @@ -338,9 +327,7 @@ static void vc4_hdmi_set_spd_infoframe(struct drm_encoder *encoder) static void vc4_hdmi_set_audio_infoframe(struct drm_encoder *encoder) { - struct drm_device *drm = encoder->dev; - struct vc4_dev *vc4 = drm->dev_private; - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); union hdmi_infoframe frame; int ret; @@ -362,9 +349,7 @@ static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder) static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder) { - struct drm_device *dev = encoder->dev; - struct vc4_dev *vc4 = to_vc4_dev(dev); - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); int ret; HDMI_WRITE(VC4_HDMI_RAM_PACKET_CONFIG, 0); @@ -383,10 +368,8 @@ static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder) static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder) { struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); - struct drm_device *dev = encoder->dev; - struct vc4_dev *vc4 = to_vc4_dev(dev); - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); + struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder; bool debug_dump_regs = false; bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC; bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC; diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index cdc9d90f62ac..749a807cd1f3 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -78,6 +78,22 @@ struct vc4_hdmi { struct debugfs_regset32 hd_regset; }; +static inline struct vc4_hdmi * +connector_to_vc4_hdmi(struct drm_connector *connector) +{ + struct vc4_hdmi_connector *_connector = to_vc4_hdmi_connector(connector); + + return container_of(_connector, struct vc4_hdmi, connector); +} + +static inline struct vc4_hdmi * +encoder_to_vc4_hdmi(struct drm_encoder *encoder) +{ + struct vc4_hdmi_encoder *_encoder = to_vc4_hdmi_encoder(encoder); + + return container_of(_encoder, struct vc4_hdmi, encoder); +} + #define HDMI_READ(offset) readl(vc4_hdmi->hdmicore_regs + offset) #define HDMI_WRITE(offset, val) writel(val, vc4_hdmi->hdmicore_regs + offset) #define HD_READ(offset) readl(vc4_hdmi->hd_regs + offset) -- git-series 0.9.1