From patchwork Sat Oct 1 15:21:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9359311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3BECD608A0 for ; Sat, 1 Oct 2016 15:22:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C95828D44 for ; Sat, 1 Oct 2016 15:22:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ACDA28D47; Sat, 1 Oct 2016 15:22:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9BFB128D49 for ; Sat, 1 Oct 2016 15:22:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bqM7A-0003cp-H2; Sat, 01 Oct 2016 15:22:12 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bqM77-0003Kx-87 for linux-amlogic@lists.infradead.org; Sat, 01 Oct 2016 15:22:10 +0000 Received: by mail-wm0-x244.google.com with SMTP id p138so7610187wmb.0 for ; Sat, 01 Oct 2016 08:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Sb4fPLyWsI1+hHns3m06jUMwsKkaxMjpomZPIJeyqmo=; b=SYYIAinbM60Lry+fvZ72Ab7gqc5/+CCTP5uye/4DiNjlAn8KAWTxwTrPkmo86Oa2Yp x0470NutJk077ki4VCdyJzckf77V1c76ValKBhtgjW7tCB+vRl301W/L0VFmgd9Lnayj ttukjmUM+SSYU744SRc1H2VdigO794N4lUStxwq5xZ8e6nGHdISd6B9prI5WfUFI1HJg DDLdX6CjlTgLB3a1ZA+O9YycfqfqziJQ23pW238Y7pfl0UqBFNRNMO5P7U0WnUGWRVdy g1McuokoeIYzJjaijtOPbcV7kH4LEuPp7Hm3J+w7GetlLX6/kJbcwZEsmgfTZeV4jT17 8DyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Sb4fPLyWsI1+hHns3m06jUMwsKkaxMjpomZPIJeyqmo=; b=jgr2LXXjKRYYaYSLrL6MafMGlO6szzrnlKSGvy8CCHC9RZIs9UEMigidk0DfDOGfXl cAmiA8gX5Y1lz77V8pdmErYc7/V33FgnJNY3fam8Xi7TUKZ/H9dS69+Q6YFlFVVv5hGO aOD1C/D43ndn+WbDcDobTu0e8eTBvbTolCQqUL2/bmnCbQCExdA7u4FJlP2n8PolnjEP 8tFYWrpdneQw9edLpKHS/6Xk+DBbPE+EwTq8mj1DIzlOahWfi5b9vG0/PEE1A9D5Ph36 2VDJVVsWpE1SPSpmK93BlcbRqxu52nqwCXPsHQWNXjHPRKm4I/DzkZ9Eod3TDldlmVMX G3LA== X-Gm-Message-State: AA6/9RkTQ5K86SnhtAcL2zmnK0HxtRbNTPmybd75UJCU4j79Rxugo7lMD6ZReazZheFRxQ== X-Received: by 10.28.153.11 with SMTP id b11mr2457248wme.94.1475335306622; Sat, 01 Oct 2016 08:21:46 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3D31B041155F9C87FD159CD.dip0.t-ipconnect.de. [2003:dc:d3d3:1b04:1155:f9c8:7fd1:59cd]) by smtp.googlemail.com with ESMTPSA id 137sm9643171wmi.16.2016.10.01.08.21.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Oct 2016 08:21:45 -0700 (PDT) From: Martin Blumenstingl To: p.zabel@pengutronix.de, linux-amlogic@lists.infradead.org Subject: [PATCH 1/3] reset: allow using reset_control_reset with shared reset Date: Sat, 1 Oct 2016 17:21:32 +0200 Message-Id: <20161001152134.8168-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161001152134.8168-1-martin.blumenstingl@googlemail.com> References: <20161001152134.8168-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161001_082209_473263_0CB1B86F X-CRM114-Status: GOOD ( 14.63 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, Martin Blumenstingl , khilman@baylibre.com, will.deacon@arm.com, kishon@ti.com, catalin.marinas@arm.com, carlo@caione.org, dt@kernel.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some SoCs (for example Amlogic GXBB) implement a reset controller which only supports a reset pulse (triggered via reset_control_reset). At the same time multiple devices (in case of the Amlogic GXBB SoC both USB PHYs) are sharing the same reset line. This patch allows using reset_control_reset also for shared resets. There are limitations though: reset_control_reset can only be used if reset_control_assert was not used yet. reset_control_assert can only be used if reset_control_reset was not used yet. For shared resets the reset is only triggered once for the lifetime of the reset_control instance (the reset can be triggered again if all consumers of that specific reset_control are gone, as the reset framework will free the reset_control instance in that case). Signed-off-by: Martin Blumenstingl --- drivers/reset/core.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 395dc9c..1565348 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -32,6 +32,7 @@ static LIST_HEAD(reset_controller_list); * @refcnt: Number of gets of this reset_control * @shared: Is this a shared (1), or an exclusive (0) reset_control? * @deassert_cnt: Number of times this reset line has been deasserted + * triggered_count: Number of times this reset line has been reset */ struct reset_control { struct reset_controller_dev *rcdev; @@ -40,6 +41,7 @@ struct reset_control { unsigned int refcnt; int shared; atomic_t deassert_count; + atomic_t triggered_count; }; /** @@ -134,17 +136,28 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register); * reset_control_reset - reset the controlled device * @rstc: reset controller * - * Calling this on a shared reset controller is an error. + * On a shared reset line the actual reset pulse is only triggered once. */ int reset_control_reset(struct reset_control *rstc) { - if (WARN_ON(rstc->shared)) - return -EINVAL; + int ret; - if (rstc->rcdev->ops->reset) - return rstc->rcdev->ops->reset(rstc->rcdev, rstc->id); + if (!rstc->rcdev->ops->reset) + return -ENOTSUPP; - return -ENOTSUPP; + if (rstc->shared) { + if (WARN_ON(atomic_read(&rstc->deassert_count) != 0)) + return -EINVAL; + + if (atomic_read(&rstc->triggered_count) != 0) + return 0; + } + + ret = rstc->rcdev->ops->reset(rstc->rcdev, rstc->id); + if (rstc->shared && !ret) + atomic_inc(&rstc->triggered_count); + + return ret; } EXPORT_SYMBOL_GPL(reset_control_reset); @@ -165,6 +178,9 @@ int reset_control_assert(struct reset_control *rstc) return -ENOTSUPP; if (rstc->shared) { + if (WARN_ON(atomic_read(&rstc->triggered_count) != 0)) + return -EINVAL; + if (WARN_ON(atomic_read(&rstc->deassert_count) == 0)) return -EINVAL; @@ -188,6 +204,9 @@ int reset_control_deassert(struct reset_control *rstc) return -ENOTSUPP; if (rstc->shared) { + if (WARN_ON(atomic_read(&rstc->triggered_count) != 0)) + return -EINVAL; + if (atomic_inc_return(&rstc->deassert_count) != 1) return 0; }