Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp751605ybt; Wed, 8 Jul 2020 10:45:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfdok9hdK1blY3Xpfy8HbqWTpZVXU3R6xUN7wW/jDLOAcGXqR3qQuNAeH7RDmoFmhDZMKk X-Received: by 2002:a50:ccc7:: with SMTP id b7mr25157902edj.9.1594230303032; Wed, 08 Jul 2020 10:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594230303; cv=none; d=google.com; s=arc-20160816; b=Kut3CHYH+BeYCYRLDlxAYqQMZCDfSWCeVP3+0bNnMZvTFBaC85bkMDQJfb4Sho088e pJbYWeZczgxwpY3YaN7KxuAWNwZk7GP0Gq2CgpZIwYj8tFVON6a6Yf7nrSvkSGBDcK59 IQovQp/9IZjfvNchf8HwioTikEEW1DOcWoPpLC2a0/AFu8zaASlCSPJya9uCclmnEoB9 XpEnqdoxYb9zopFM9lzbeXtOfOKUQK1Vhp1b2LP9mMC893cV/W0XcNpPXgBNGhrRzGwI qq1Z7WmyO3Sffo9OgSi5TtHk4dMo6T48aOwZXJjQc5yACH1TL6ZVI4mW+yoS8nWKO2Nl uaeg== 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=jLgbV2zJcDXscOF8tmDfCZC7s9/iU/zmjwoPk02j6nM=; b=Xawpb/7KHFGMyC3qRW8QvjJzAwbtDnct8EHl6i5Mx65HaB0vdeG8BqOZTkrr5i2hbb LQ2L0kywNtvQ84dWEhIeeJuys7rGyVHnsFyLGhO69FJl4/N1JzoHodoCUUUWBIJigEOZ uKYI0MrudEgdBYTvjoPEdglyCznEQ4U2a830jkh4dyz5X58haudKbpj1HVnsPgWQvBfH gwJkSxgpAd/ZmvpuZH6Zxii4NAxAcl2/XG9cZcLzFgBZhT4fmgHVNyHpA/n+llERqfsi zgiztQ6hyuMtHkYxioYTfEqDKOPmQKynnOYKAS6qBhPdJ8RRp6Txp9PnFsCoz4hc7Tg3 3eBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=UNRqpjMa; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=C1jAAWoO; 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 d3si447255edn.145.2020.07.08.10.44.39; Wed, 08 Jul 2020 10:45:03 -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=fm3 header.b=UNRqpjMa; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=C1jAAWoO; 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 S1727785AbgGHRnn (ORCPT + 99 others); Wed, 8 Jul 2020 13:43:43 -0400 Received: from wnew4-smtp.messagingengine.com ([64.147.123.18]:33255 "EHLO wnew4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbgGHRnk (ORCPT ); Wed, 8 Jul 2020 13:43:40 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id 4A85A2F2; Wed, 8 Jul 2020 13:43:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 08 Jul 2020 13:43:40 -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=fm3; bh=jLgbV2zJcDXsc OF8tmDfCZC7s9/iU/zmjwoPk02j6nM=; b=UNRqpjMa0L3djqi7ZnGHsNH/ZVGKU 6IkbWPB74M7Og0hqVKR3gEpvOnmXr4pi8vqLvO+2mb5wxd7L56pzOVabV10EIJp/ fEKX2zOlFKq5sBW7WR8z7UldtD2t+ZGm5zZdBnYnOWqohkbToOzpmmqgbXbhZFn0 RaeQOsbMPjjHErNUe8ItgGAV6MQxf7K5f5KsZayx1PtyJRuoo4z+8+NytOyGkHlL 3qjkdQFTwFT4tPQ0ElsuJxHFk0ZmWkn+Kaz5XJl194n5o5cy35+Uk3HZ33EI8/Q5 JkFzjfax9MZK8w0oGYYJL/fF9zU1NI7y/oaB5aCa9YHSRVjovi26BsqGA== 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= fm3; bh=jLgbV2zJcDXscOF8tmDfCZC7s9/iU/zmjwoPk02j6nM=; b=C1jAAWoO T70yXvBjI9ojA8Lr/QOrJNXW1aJ37GvjoBfN+AxhtdD8JaWmFNheIMoAbP3fgnXU jWsxrBuX3nfr1pXVZAGlCtu09oCtiwZ6jlfLqGmTw307Yg5fK5z7a3PVNyDrMr0s ckLxqwaXkI9QMunUvJn0JFrBoawcgSJALJJWPI2rDEsUFcSQEoyYnlTj8d+iAW5H 67Kuykou4jEOzkiTIDJCp7mWq5fjxOs/kh359oz/UeaanZelYcQmA1qQla9bvIK5 mZun9HgOMKpikesRuQTV5sWOc24JFSwvpk/pW94fAosQGGK1cA6FfNPJBESFSl0D mswjQHP7q2Qnfw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudejgdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgepgeefne 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 87AC3306005F; Wed, 8 Jul 2020 13:43:38 -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 v4 47/78] drm/vc4: hdmi: Retrieve the vc4_hdmi at unbind using our device Date: Wed, 8 Jul 2020 19:41:55 +0200 Message-Id: <0fc40024f73b3bc6d9eba0b47da217ed130c3374.1594230107.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 The unbind function needs to retrieve a vc4_hdmi structure pointer through the struct device that we're given since we want to support multiple HDMI controllers. However, our optional ASoC support doesn't make that trivial since it will overwrite the device drvdata if we use it, but obviously won't if we don't use it. Let's make sure the fields are at the proper offset to be able to cast between the snd_soc_card structure and the vc4_hdmi structure transparently so we can support both cases. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_hdmi.c | 24 +++++++++++++++++++++++- drivers/gpu/drm/vc4/vc4_hdmi.h | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 09b297a1b39d..7cd1394c10fa 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -1200,6 +1200,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) if (!vc4_hdmi) return -ENOMEM; + dev_set_drvdata(dev, vc4_hdmi); encoder = &vc4_hdmi->encoder.base.base; vc4_hdmi->encoder.base.type = VC4_ENCODER_TYPE_HDMI0; vc4_hdmi->pdev = pdev; @@ -1362,7 +1363,28 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master, { struct drm_device *drm = dev_get_drvdata(master); struct vc4_dev *vc4 = drm->dev_private; - struct vc4_hdmi *vc4_hdmi = vc4->hdmi; + struct vc4_hdmi *vc4_hdmi; + + /* + * ASoC makes it a bit hard to retrieve a pointer to the + * vc4_hdmi structure. Registering the card will overwrite our + * device drvdata with a pointer to the snd_soc_card structure, + * which can then be used to retrieve whatever drvdata we want + * to associate. + * + * However, that doesn't fly in the case where we wouldn't + * register an ASoC card (because of an old DT that is missing + * the dmas properties for example), then the card isn't + * registered and the device drvdata wouldn't be set. + * + * We can deal with both cases by making sure a snd_soc_card + * pointer and a vc4_hdmi structure are pointing to the same + * memory address, so we can treat them indistinctly without any + * issue. + */ + BUILD_BUG_ON(offsetof(struct vc4_hdmi_audio, card) != 0); + BUILD_BUG_ON(offsetof(struct vc4_hdmi, audio) != 0); + vc4_hdmi = dev_get_drvdata(dev); cec_unregister_adapter(vc4_hdmi->cec_adap); vc4_hdmi_connector_destroy(&vc4_hdmi->connector.base); diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index 749a807cd1f3..d43462789450 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -53,13 +53,13 @@ struct vc4_hdmi_audio { /* General HDMI hardware state. */ struct vc4_hdmi { + struct vc4_hdmi_audio audio; + struct platform_device *pdev; struct vc4_hdmi_encoder encoder; struct vc4_hdmi_connector connector; - struct vc4_hdmi_audio audio; - struct i2c_adapter *ddc; void __iomem *hdmicore_regs; void __iomem *hd_regs; -- git-series 0.9.1