Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp997198lqo; Thu, 9 May 2024 01:21:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnupA1mMBDZPbaeuhLWWFTTrUk7Ma4yJeJf9KX7cm3GRW1y9NTA21e9EWYSkon47j14UMxUDqv4hKvMxmXr/93+88nuvnowrv7A1vFNA== X-Google-Smtp-Source: AGHT+IGy43s4lReHRB2oI3SGzd8VOlOTVLnIMCoITWbOgazpDADEDjP7RBeDQCmMl5fyoKkyF76p X-Received: by 2002:a50:bb05:0:b0:572:7c99:a280 with SMTP id 4fb4d7f45d1cf-5731d9d4572mr3362672a12.15.1715242911221; Thu, 09 May 2024 01:21:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715242911; cv=pass; d=google.com; s=arc-20160816; b=G4X6mc/cqxM8Vd9CJjf+70CW9R3FYmsUPlXmccB34SCpYUvopXMH5O23x6rkudN+Pd kFOstyY5q+nBvUQlobI8E5jaAAJQ+Ebg1ld++2Gp29yrKmJoqYBvODgZ8aO1AY+0Bzxd 130Ss3nCC6UBRD3+iAvMd8O7p5BnkN6Qzr52v6z7QRwHecr3zjiBvEPhOBrBCoZVDJGV Uo6X9PYjMmx1xN+bicA1b2LFI/76HFIGTd72XVCzgPeA691UnRPU/4gjwUo/13iYcZF8 t9P2GDLokUt90gYLi+ZbGpVYQUE/6X4hdDNo0D2+2B9nXH/X1AZmyLcJlhMcEjTTCYLF 6n1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=syLm9Olf0fGCn0zTzlomV7zWJ+9A4GH/D4wM89uH8tA=; fh=yxkvTXKlzxYPV7e53mgyNaQsLoJ+IvHPq/76OKYZsoc=; b=qdf/9C+17/TjWiMJ1rpS0H1AQdR/5gx36MMQEoprMgfcLfFfAZleg5DYw6BBE0Ws23 FVVsimtin0VbFbknLyKxPjI38k1BCM/NJljSgB7iPm/prGA06CNs8wqYodb20DbJ+xE+ igOX6ILDw/lefz9uPnjGbmBHyCOzKL9n2yx6sAu1dlS+pNA5hSg+eYgRTLFL3eB2GecK GS10J+7n5rySv4Xgu10PEidxPTgSLgzjz7QcYwZSUUceYRp+TNqOd1P6+Z8fcU5Y50Dw ErRMbeaNrOOgQQsFbH99pRtFOFxrQxJwP+cmUJKkgltD/mpzCiCnkQkRUrRNJ2o3KiRY h5ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Sx1qPmbk; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-174281-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c36e2dbsi583728a12.552.2024.05.09.01.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 01:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174281-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Sx1qPmbk; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-174281-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174281-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C0AF31F21E01 for ; Thu, 9 May 2024 08:21:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F181B149DF7; Thu, 9 May 2024 08:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Sx1qPmbk" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AF7E13B5A9; Thu, 9 May 2024 08:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715242903; cv=none; b=qK3t+8rr9A3vpB1G+QQcwXC1TegAfnadSko3nh3euQ7knZe8cHBUNYHgACCpIfMqiWHE8w9HfHnNS2mRuckmmGSuZHpaomi128m6rvpvXpk1E1nAyCgm+KphRB6iPKsjlQJZ1E68FsUdpGS/qjcjP0pqpr5jSwjdhlF7+hdoj8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715242903; c=relaxed/simple; bh=bgDLzxpYitnFqSBkidhPvmb7A8VF+kvubgyIU2MFg0g=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=T82L4Zd25nnVoERcRe46VSVjM0FQUV6AJL/4S3lryhx7ZaueUuXIz4e/hFyPlHQoEr0O+Uqe8lIZzgxfl6A9gaC3KN0c5Ae4FR0fiKvXGlWDhRi87/6MIv3iuq8i8X+zhs6cJFa2wGWar44dnJBIBGnDk9XofRWfi4OEBr9SmP8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Sx1qPmbk; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715242902; x=1746778902; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=bgDLzxpYitnFqSBkidhPvmb7A8VF+kvubgyIU2MFg0g=; b=Sx1qPmbk7c+xdTC2smjOeJdfyELeISbORiRnbNiQP3UHqIeDOCcc9zuZ UVPYeUp7XND6zlwhznxYcWD9rKhuRkrtTvZHO2Ufnleuwpx6+o/y/zLLf fmSKPcs7hzDc8tnh+AkYBZYsRDbocXkTcyGbz4HgWd8gRqtKPJKHSMhfH hS3vyfEhomN21aK9bqJ+vWw0V2boz5/pxrvnCIxG5dY9wI8i4RghfX9Cs AFcspf/B7Q+h2+Vn2jX5h+J//TYd2MlcClYXfFjHAxaPSXyHhVSapx3CB cOA142EK5hmWsHR9CfFMqAivOXJU7NsTsWEPYLSBiOIk5Cnr+iy5ABSeN w==; X-CSE-ConnectionGUID: EsycnyROQS6/TWLL2lvC6Q== X-CSE-MsgGUID: CE8fm41dSJGUoGbdpRXJ/A== X-IronPort-AV: E=McAfee;i="6600,9927,11067"; a="22550983" X-IronPort-AV: E=Sophos;i="6.08,147,1712646000"; d="scan'208";a="22550983" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2024 01:21:41 -0700 X-CSE-ConnectionGUID: bBIbfyPmRDytOOx14qdCmA== X-CSE-MsgGUID: faG8c/p9TD2G7pIk/O9Vdw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,147,1712646000"; d="scan'208";a="29095902" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.34.226]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2024 01:21:38 -0700 Message-ID: Date: Thu, 9 May 2024 11:21:32 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/1] mmc: sdhci-of-dwcmshc: add callback functions for dwcmshc_priv To: Chen Wang , Chen Wang , ulf.hansson@linaro.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, jszhang@kernel.org, dfustini@baylibre.com, yifeng.zhao@rock-chips.com, shawn.lin@rock-chips.com, chao.wei@sophgo.com, haijiao.liu@sophgo.com, xiaoguang.xing@sophgo.com, tingzhu.wang@sophgo.com, guoren@kernel.org, inochiama@outlook.com References: <5bb708cc830684676dede5f44ee22c7fd03300b7.1714270290.git.unicorn_wang@outlook.com> Content-Language: en-US From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 9/05/24 05:17, Chen Wang wrote: > > On 2024/4/29 15:08, Adrian Hunter wrote: >> On 28/04/24 05:32, Chen Wang wrote: >>> From: Chen Wang >>> >>> The current framework is not easily extended to support new SOCs. >>> For example, in the current code we see that the SOC-level >>> structure `rk35xx_priv` and related logic are distributed in >>> functions such as dwcmshc_probe/dwcmshc_remove/dwcmshc_suspend/......, >>> which is inappropriate. >>> >>> The solution is to abstract some possible common operations of soc >>> into virtual members of `dwcmshc_priv`. Each soc implements its own >>> corresponding callback function and registers it in init function. >>> dwcmshc framework is responsible for calling these callback functions >>> in those dwcmshc_xxx functions. >>> >>> Signed-off-by: Chen Wang >>> --- >>>   drivers/mmc/host/sdhci-of-dwcmshc.c | 152 +++++++++++++++++----------- >>>   1 file changed, 91 insertions(+), 61 deletions(-) >>> >>> diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c >>> index 39edf04fedcf..525f954bcb65 100644 >>> --- a/drivers/mmc/host/sdhci-of-dwcmshc.c >>> +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c >>> @@ -214,6 +214,10 @@ struct dwcmshc_priv { >>>       void *priv; /* pointer to SoC private stuff */ >>>       u16 delay_line; >>>       u16 flags; >>> + >>> +    void (*soc_postinit)(struct sdhci_host *host, struct dwcmshc_priv *dwc_priv); >>> +    int (*soc_clks_enable)(struct dwcmshc_priv *dwc_priv); >>> +    void (*soc_clks_disable)(struct dwcmshc_priv *dwc_priv); >> Normally the ops would be part of platform data.  For example, >> sdhci-of-arasan.c has: >> >>     struct sdhci_arasan_of_data { >>         const struct sdhci_arasan_soc_ctl_map *soc_ctl_map; >>         const struct sdhci_pltfm_data *pdata; >>         const struct sdhci_arasan_clk_ops *clk_ops; >>     }; >> >> And then: >> >>     static struct sdhci_arasan_of_data sdhci_arasan_rk3399_data = { >>         .soc_ctl_map = &rk3399_soc_ctl_map, >>         .pdata = &sdhci_arasan_cqe_pdata, >>         .clk_ops = &arasan_clk_ops, >>     }; >>     etc >> >>     static const struct of_device_id sdhci_arasan_of_match[] = { >>         /* SoC-specific compatible strings w/ soc_ctl_map */ >>         { >>             .compatible = "rockchip,rk3399-sdhci-5.1", >>             .data = &sdhci_arasan_rk3399_data, >>         }, >>         etc >> >> So, say: >> >> struct dwcmshc_pltfm_data { >>     const struct sdhci_pltfm_data *pltfm_data; >>     void (*postinit)(struct sdhci_host *host, struct dwcmshc_priv *dwc_priv); >>     int  (*clks_enable)(struct dwcmshc_priv *dwc_priv); >>     void (*clks_disable)(struct dwcmshc_priv *dwc_priv); >> } >> >> Or if the ops are mostly the same, it might be more convenient to >> have them in their own structure: >> >> struct dwcmshc_pltfm_data { >>     const struct sdhci_pltfm_data *pltfm_data; >>     const struct dwcmshc_ops *ops; >> } > > hi, Adrian, > > I thought about it for a while, and I would like to continue discussing this issue as follows. > > I feel like it would be simpler to put it at the dwcmshc_priv level based on the ops involved in the code so far. Judging from the SOCs currently supported by dwcmshc, the ops I abstracted only operate data below the dwcmshc_priv level, and these ops are not used by most SOCs. > - postinit: only required by rk35xx > - init: involves rk35xx and th1520, and the new soc(sg2042) I want to add. > - clks_enable/clks_disable: only rk35xx and the sg2042 I want to add > > In particular, for dwcmshc_suspend/dwcmshc_resume, we have already obtained dwcmshc_priv. If ops is to be placed at the platformdata level, we have to use device_get_match_data to obtain data again, which feels a bit unnecessary. > > What do you think? In sdhci-of-arasan.c, ops are copied from platform data to driver private data e.g. static int sdhci_arasan_probe(struct platform_device *pdev) { ... struct sdhci_arasan_data *sdhci_arasan; const struct sdhci_arasan_of_data *data; data = of_device_get_match_data(dev); if (!data) return -EINVAL; ... sdhci_arasan = sdhci_pltfm_priv(pltfm_host); ... sdhci_arasan->clk_ops = data->clk_ops; Alternatively, a pointer could be put in driver private data to point to platform data.