Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp337218ybl; Wed, 11 Dec 2019 19:35:30 -0800 (PST) X-Google-Smtp-Source: APXvYqzErdjy3+Z1UabByjCzS9M+MQ7UAm2Tvnyxm+evYqQFaHsDKHbWav5/ZbViAm9inpapXWE0 X-Received: by 2002:a9d:74c8:: with SMTP id a8mr5360384otl.57.1576121730387; Wed, 11 Dec 2019 19:35:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576121730; cv=none; d=google.com; s=arc-20160816; b=KZhn9m2IsVD0OrX15gYCeOWZr8Aa480w2rmCmRbx1+dX8AbwRhc3xYfizU+lITbCe7 tbyJ5J0+TUrtTFW7oFpqAEDaXOwW+ufGTxjKonhMEVzxNC34vPSnAHFw/aK3RTwD4W5W Tx3FDVaRzQP4civIJHx6MZMbgTOq6LG6/3U3kwTEv/gzG2PYGVvLkhPoem3lkabDhPjG Nbhh7e56CWuap/e/pemOAeS9McMIpweH3C6w4t+zqRU8aehueRaJMwb1Oq41iHl/Yrl0 vfXVQGeJV4q3Tfy6XiUqyNaMSuC2C926gjvEeRXNJygy4yqv78q0NYDKT9Ic2KEQMdZ6 m9kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=p1P3InDUiioyKsJ0uqaLYPyxVpYrR5VZ44BOVhRr6QU=; b=wFR1qmGBEFh/2pRUJzp3+dlM0P/vj8AXm9dATVGPFKfEEJyJzUPWYZgS0wiPUTe177 fq4OPRy1r8umSDSE9McOT7VvSIMGMUVTo+LfRjCuVCMGjkFmrahDuAOhw1xXBU5vFBl7 fK8rc82t51xeHwqOkgm62Kx99gHkTGB0m7do4Gq2InTCC0ku37rvG4oLNKZh07KLpE92 K5iXaRvQIXF9YBmqw8G0dEux2WiIJyKz648L6eqwkmLpWG5M9J/WqP3vd6WbZtojeNME PcQagaYPgoTlHYm5fGxwYIj57OqC5/EB7k65z+J0OuerA9uDLMO1uOOfsajwOSslaX4w cgVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=FdUxNb09; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k23si2375558otp.181.2019.12.11.19.35.00; Wed, 11 Dec 2019 19:35:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=FdUxNb09; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726801AbfLLDeK (ORCPT + 99 others); Wed, 11 Dec 2019 22:34:10 -0500 Received: from conssluserg-03.nifty.com ([210.131.2.82]:37829 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726714AbfLLDeJ (ORCPT ); Wed, 11 Dec 2019 22:34:09 -0500 Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (authenticated) by conssluserg-03.nifty.com with ESMTP id xBC3Xl0H013734; Thu, 12 Dec 2019 12:33:47 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com xBC3Xl0H013734 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1576121628; bh=p1P3InDUiioyKsJ0uqaLYPyxVpYrR5VZ44BOVhRr6QU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=FdUxNb09tRix91rC7pFGfY91Alomf9VGqGWbt5CnOCadE5WbXoJg5TPifTUICLvWK LesPIlYRvDQDBtlsyO6qOj4DUBcy05EFUfaaIPppNaG6wXtfWE6+QFM3+BUxsmc0Aq DOh3Qjm0Q3M5HiAG3xgecFuFWSJ2oLbpNFA0osNVc2SwHOLl5l8DgByu6GYHdLMMrv rkYvYXDAjt6DAP9PTW/rNqdJJkckmBVkLGBtcXWlb8jnlZIHJG0kSJkXT7j9flOcZE q8NAQqaa0QUPV/XK+UyUcs8h4sK4R18uosuG/P4l3RBpr7Iebx9pi1anrFSlG+ULxp BZHYMF3jHk4+w== X-Nifty-SrcIP: [209.85.221.175] Received: by mail-vk1-f175.google.com with SMTP id i18so1102vkk.7; Wed, 11 Dec 2019 19:33:47 -0800 (PST) X-Gm-Message-State: APjAAAU1PQlTMP4/At5pbI8/0Qgw0s6rsdhMqtY/InVeNjF+vILP1l+B ubU/VEt66PmufqTbI+SSWcEZrDXO/I5gkJu0kdM= X-Received: by 2002:a1f:2e4a:: with SMTP id u71mr3263415vku.96.1576121626675; Wed, 11 Dec 2019 19:33:46 -0800 (PST) MIME-Version: 1.0 References: <20191211054538.8283-1-yamada.masahiro@socionext.com> <20191211054538.8283-2-yamada.masahiro@socionext.com> <399bb8ab-74c5-1be3-4156-6d854738b548@denx.de> In-Reply-To: <399bb8ab-74c5-1be3-4156-6d854738b548@denx.de> From: Masahiro Yamada Date: Thu, 12 Dec 2019 12:33:10 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/2] mtd: rawnand: denali_dt: add reset controlling To: Marek Vasut Cc: linux-mtd , Dinh Nguyen , Ley Foon Tan , Miquel Raynal , DTML , Rob Herring , Philipp Zabel , Richard Weinberger , Vignesh Raghavendra , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 12, 2019 at 10:05 AM Marek Vasut wrote: > > On 12/11/19 6:45 AM, Masahiro Yamada wrote: > [...] > > diff --git a/drivers/mtd/nand/raw/denali_dt.c b/drivers/mtd/nand/raw/denali_dt.c > > index 8b779a899dcf..9a294c3f6ec8 100644 > > --- a/drivers/mtd/nand/raw/denali_dt.c > > +++ b/drivers/mtd/nand/raw/denali_dt.c > > @@ -6,6 +6,7 @@ > > */ > > > > #include > > +#include > > #include > > #include > > #include > > @@ -14,6 +15,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "denali.h" > > > > @@ -22,6 +24,8 @@ struct denali_dt { > > struct clk *clk; /* core clock */ > > struct clk *clk_x; /* bus interface clock */ > > struct clk *clk_ecc; /* ECC circuit clock */ > > + struct reset_control *rst; /* core reset */ > > + struct reset_control *rst_reg; /* register reset */ > > }; > > > > struct denali_dt_data { > > @@ -151,6 +155,14 @@ static int denali_dt_probe(struct platform_device *pdev) > > if (IS_ERR(dt->clk_ecc)) > > return PTR_ERR(dt->clk_ecc); > > > > + dt->rst = devm_reset_control_get_optional_shared(dev, "nand"); > > + if (IS_ERR(dt->rst)) > > + return PTR_ERR(dt->rst); > > + > > + dt->rst_reg = devm_reset_control_get_optional_shared(dev, "reg"); > > + if (IS_ERR(dt->rst_reg)) > > + return PTR_ERR(dt->rst_reg); > > + > > ret = clk_prepare_enable(dt->clk); > > if (ret) > > return ret; > > @@ -166,10 +178,30 @@ static int denali_dt_probe(struct platform_device *pdev) > > denali->clk_rate = clk_get_rate(dt->clk); > > denali->clk_x_rate = clk_get_rate(dt->clk_x); > > > > - ret = denali_init(denali); > > + /* > > + * Deassert the register reset, and the core reset in this order. > > + * Deasserting the core reset while the register reset is asserted > > + * will cause unpredictable behavior in the controller. > > + */ > > + ret = reset_control_deassert(dt->rst_reg); > > if (ret) > > goto out_disable_clk_ecc; > > > > + ret = reset_control_deassert(dt->rst); > > + if (ret) > > + goto out_assert_rst_reg; > > + > > + /* > > + * When the reset is deasserted, the initialization sequence is kicked > > + * (bootstrap process). The driver must wait until it finished. > > + * Otherwise, it will result in unpredictable behavior. > > + */ > > + usleep_range(200, 1000); > > + > > + ret = denali_init(denali); > > + if (ret) > > + goto out_assert_rst; > > + > > for_each_child_of_node(dev->of_node, np) { > > ret = denali_dt_chip_init(denali, np); > > if (ret) { > > @@ -184,6 +216,10 @@ static int denali_dt_probe(struct platform_device *pdev) > > > > out_remove_denali: > > denali_remove(denali); > > +out_assert_rst: > > + reset_control_assert(dt->rst); > > +out_assert_rst_reg: > > + reset_control_assert(dt->rst_reg); > > Maybe you can use devm_add_action_or_reset() here , like in e.g. > drivers/input/touchscreen/ili210x.c , to avoid this unwinding ? No. Drivers should be explicit about what and when to do about the hardware access. This comes down to a question about why Linux kernel does not have such APIs as: devm_clk_prepare_enable() devm_reset_control_deassert() devm_regulator_enable() In fact, I saw some people sending such patches in the past. Mark Brown clearly answered the question. https://lkml.org/lkml/2014/2/1/131 I really support his thinking. -- Best Regards Masahiro Yamada