Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4411680pxk; Wed, 30 Sep 2020 02:09:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9FRrdmmlijug2A1rH4Med4ILoDtS3LVZjigjTZ6D19DvV92Tt12ExF4D9zznAO147+qNj X-Received: by 2002:a17:906:ae45:: with SMTP id lf5mr1724190ejb.339.1601456949042; Wed, 30 Sep 2020 02:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601456949; cv=none; d=google.com; s=arc-20160816; b=M0ryKPO4gJooMZc0qJFXPWfBcB01N1GIQgGjGhqxEe7Yu5V5XjzJed2GS0vL4zsZRW ul0asNycB7dMKXv9hU3DWs5ZSX+9ZAcSCDb4KaPfjDSfTGgRq9EbMjK//pXM7tsyfa7B YHcKSP07UuIYS3PJQHDa+it+YYsH0Um7Y8lzMZDFc6SnFCuhn7tC7tCyXDtmuR+j58+9 +GKGcMq2lndVIf5pxaUivq0kjJzIxIYV+n4egdlnQtjdF/rIa5TpSrVU7ojaK+4ntexZ 29L8mpZu48VGltoou2cNJF5oZhfpFhP5kH3FOWpcdEJsEnZI8QWcSDCFj6q1zzl8Z162 prdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SsJHRxDsIetGxwsT821CF0ejFakXrB67jr2iq4S9IUc=; b=mGfxj7cnwqnpu5TjlLLrcfNrl0ELhQGeESVESDv6/5d80gwZhosVk2nfJl0ymePnZY RlopX2i1siUY8Co94z2WPcI2wNxMXusnu3AtAUUWMHRFHuFnH8SfNdFDtf6G6Y29qE8N 98TCLsrnrgLWMbckKdu+96DUCq4UIX1qRC24FmSjvCzIsv/oGXyoG1TGpLwjDQEFmeBT ozTL+2SEYNOuTfH1w35sYjXfNY9/mJgatRHYI5lSfvuVdWpdeOOCZSbNV/bFGbcj46Zn /F9PXcYW+c7KvpKpyexv/O2JENgITCETJKyvo0AinPFdurmoD7tK12g/Fdz5v/0Ij3mQ 6x0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fAaNPtZY; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si731581ejy.632.2020.09.30.02.08.45; Wed, 30 Sep 2020 02:09:09 -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=@kernel.org header.s=default header.b=fAaNPtZY; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728235AbgI3JHq (ORCPT + 99 others); Wed, 30 Sep 2020 05:07:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:54434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgI3JHq (ORCPT ); Wed, 30 Sep 2020 05:07:46 -0400 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B3A920754; Wed, 30 Sep 2020 09:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601456865; bh=QoRVG2ebL4cYUkaDCdQ+XmLDYvdbkAU8qZxPoMO2OvA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fAaNPtZYczrVnTRPGPKuBg2P1dPhUVHEUL1d0LXPrJcOo267+aOR5jgZ/OFb2dXO+ WmRQqT547I44Af3QcPadn9HEr18c4x+4bs8/rQGIyNCwBJVwlyxXRUIx3pfkrmYYEY HuTmfdLzO44aNkMdWbUGq2sp926bRQlqe4lC5mQk= Received: by mail-ed1-f46.google.com with SMTP id b12so982527edz.11; Wed, 30 Sep 2020 02:07:45 -0700 (PDT) X-Gm-Message-State: AOAM532V05ghpTSSVYhOF/FKyT73j4B/ZFDswquBPJThKhjZkQM4S+UJ xw8IXQ0kNfE3d2DdS6hzhrf1AO+AUWLaWR3eiOk= X-Received: by 2002:aa7:da16:: with SMTP id r22mr1692538eds.132.1601456863786; Wed, 30 Sep 2020 02:07:43 -0700 (PDT) MIME-Version: 1.0 References: <20200930084258.25493-1-nicoleotsuka@gmail.com> <20200930084258.25493-2-nicoleotsuka@gmail.com> In-Reply-To: <20200930084258.25493-2-nicoleotsuka@gmail.com> From: Krzysztof Kozlowski Date: Wed, 30 Sep 2020 11:07:32 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 1/3] memory: tegra: Add devm_tegra_get_memory_controller() To: Nicolin Chen Cc: thierry.reding@gmail.com, joro@8bytes.org, digetx@gmail.com, vdumpa@nvidia.com, jonathanh@nvidia.com, linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org, "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "On Wed, 30 Sep 2020 at 10:48, Nicolin Chen wrote: > > From: Dmitry Osipenko > > Multiple Tegra drivers need to retrieve Memory Controller and hence there > is quite some duplication of the retrieval code among the drivers. Let's > add a new common helper for the retrieval of the MC. > > Signed-off-by: Dmitry Osipenko > Signed-off-by: Nicolin Chen > --- > > Changelog > v2->v3: > * Replaced with Dimtry's devm_tegra_get_memory_controller() > v1->v2: > * N/A > > drivers/memory/tegra/mc.c | 39 +++++++++++++++++++++++++++++++++++++++ > include/soc/tegra/mc.h | 17 +++++++++++++++++ > 2 files changed, 56 insertions(+) > > diff --git a/drivers/memory/tegra/mc.c b/drivers/memory/tegra/mc.c > index ec8403557ed4..dd691dc3738e 100644 > --- a/drivers/memory/tegra/mc.c > +++ b/drivers/memory/tegra/mc.c > @@ -42,6 +42,45 @@ static const struct of_device_id tegra_mc_of_match[] = { > }; > MODULE_DEVICE_TABLE(of, tegra_mc_of_match); > > +static void tegra_mc_devm_action_put_device(void *data) devm_tegra_memory_controller_put() > +{ > + struct tegra_mc *mc = data; > + > + put_device(mc->dev); > +} > + > +struct tegra_mc *devm_tegra_get_memory_controller(struct device *dev) Usually 'get' is a suffix (e.g. clk, gpiod, iio, led), so: devm_tegra_memory_controller_get() > +{ > + struct platform_device *pdev; > + struct device_node *np; > + struct tegra_mc *mc; > + int err; > + > + np = of_find_matching_node_and_match(NULL, tegra_mc_of_match, NULL); > + if (!np) > + return ERR_PTR(-ENOENT); > + > + pdev = of_find_device_by_node(np); > + of_node_put(np); > + if (!pdev) > + return ERR_PTR(-ENODEV); > + > + mc = platform_get_drvdata(pdev); > + if (!mc) { > + put_device(mc->dev); > + return ERR_PTR(-EPROBE_DEFER); > + } > + > + err = devm_add_action(dev, tegra_mc_devm_action_put_device, mc); > + if (err) { > + put_device(mc->dev); > + return ERR_PTR(err); > + } > + > + return mc; > +} > +EXPORT_SYMBOL_GPL(devm_tegra_get_memory_controller); > + > static int tegra_mc_block_dma_common(struct tegra_mc *mc, > const struct tegra_mc_reset *rst) > { > diff --git a/include/soc/tegra/mc.h b/include/soc/tegra/mc.h > index 1238e35653d1..c05142e3e244 100644 > --- a/include/soc/tegra/mc.h > +++ b/include/soc/tegra/mc.h > @@ -184,4 +184,21 @@ struct tegra_mc { > int tegra_mc_write_emem_configuration(struct tegra_mc *mc, unsigned long rate); > unsigned int tegra_mc_get_emem_device_count(struct tegra_mc *mc); > > +#ifdef CONFIG_TEGRA_MC > +/** > + * devm_tegra_get_memory_controller() - Get the tegra_mc pointer. > + * @dev: Device that will be interacted with This is not precise enough and there is no interaction with 'dev' in devm_tegra_get_memory_controller(). Something like: "Device that owns the pointer to tegra memory controller" > + * > + * Return: ERR_PTR() on error or a valid pointer to a struct tegra_mc. > + * > + * The mc->dev counter will be automatically put by the device management code. 1. s/mc/tegra_mc/ (it's the first occurence of word mc here) 2. "kerneldoc goes to the C file". Not to the header. Best regards, Krzysztof