From patchwork Wed Nov 1 00:23:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 117665 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp225222qgn; Tue, 31 Oct 2017 17:23:46 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RjmUwL+HaOS7phfzR8Jjub0JZ2t+SI1YqH0JSwSPjsHocz1Yi0aHc4ROZ1z/Yr1NLb2IzA X-Received: by 10.98.159.23 with SMTP id g23mr4062354pfe.216.1509495826770; Tue, 31 Oct 2017 17:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509495826; cv=none; d=google.com; s=arc-20160816; b=Wb5thL793xqShkr1nVYsYVRCtON7uJUbDU6wWSTW7JrYgdfMPC2KXlPqYmqHeG38U9 vr3ePORTP1DA/gS5673J7Yl/5D//3iIBn9MYYyF3wws1B/8lGZle+0Wv/HREfCB8V8Tq Kkq6t9aZ2rh4Dguntq7Fqb4/Z2oVSTlhEm6HdxgZlbm9I5pyx/Zli3XGXGIQnYDT5+k3 I0oDQS3WXb9tB9f1xKXj64sodYeNDzDDqMyX7SVjSxy6NAyd+Q7UOQYD/uMJzEtDDKgR j1C8tvWWxTjWU/Nci47S6R1NISolNRafXhwtVxRFlO289qeIO4RLyJjhcXi/SSG/uUHf MU9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=QGKUJwMwTyIiAF8D5HsK0FiEXfAUKQCFCK7Me0GtlzE=; b=wXxR2JrH8c0mc3Prgh2J8gme9CTmG6iKA16IWXIReOiYI1nFkG9YO0Du4hu5s9O6Xr qnnTfcHPLAJAAm4Q+X9ngxRFNsyRf0v/6ewSA715g/tKpTQpqTV0sLZ2LK4fMUxGjrWf skmKaDBumyobOlQvFtxkZQPzHuu8uJ1yj7eSkAFDEJVjZzKNXaXxAvxgBc4erANNB2cC yLfRb1ORJJ4J7oTqygD8d3sC8QWt8EpU64i7J+ISCC9KakdYPM2Bv1vVlaNrh44WNpML TvsQiFp+ahCEIhjU6KYRXtzj3YjUlS2i6K1lmKUCuWD/kitnC4WJWcRTeq4UiX8mvbSu afPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dPb1G3RY; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f67si2699167pgc.640.2017.10.31.17.23.46; Tue, 31 Oct 2017 17:23:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dPb1G3RY; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752859AbdKAAXp (ORCPT + 3 others); Tue, 31 Oct 2017 20:23:45 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:52130 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751286AbdKAAXo (ORCPT ); Tue, 31 Oct 2017 20:23:44 -0400 Received: by mail-pg0-f67.google.com with SMTP id p9so635769pgc.8; Tue, 31 Oct 2017 17:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=QGKUJwMwTyIiAF8D5HsK0FiEXfAUKQCFCK7Me0GtlzE=; b=dPb1G3RYwviPg3OGzm/hYlqNT4mZXQjgL0WPmSLR4Bf2xu3WeM4R4z6W8qCozCXX1b sEWc0a2KWNv0sLC1+k8ElNvva0AgfCX7TfYb4Lghb7ggL2T/ubrNuSbcsNQ3FuTBS7/r uz2ggjQuy5gtgY6n96sLxzKsq3MJqy1V5mLZqh7kXORV8VJq2bP364d5IWK1o8R1e/cY 77X7rmPP/DDhlMMH7TyJGX8pfy6+3omI2fna1nG7OcsKw1rGdhW2OYHCcTKcHcemMbng 7JfmMVQp4hmLxS3sjkWJHrVL226voO0GG1DgSc+wcqXzy6BBLvzUWXiB56vW3CWLVPO+ fHSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=QGKUJwMwTyIiAF8D5HsK0FiEXfAUKQCFCK7Me0GtlzE=; b=OcwNSZPAnXG3BSOXg7f8c8rRcwgWf9S6efOwQ2HlVJ8RdL74SA6aQEeNzCmRij3WdH j24qTveoVuhe8pnBrCOFVIffAjZlF6Ra2P4aWOxKMvmoYlRicRPMUoufWq79KydT7StS aYJw8HUnliSy0NDtBhAPv+/yjtdjOWPi2672MSmKAMyxjzcVA2lX/cXUARXgJCvp0cKo AasOttG3+NrJLJ5HRN6sLq+d6mdpWos/kXVq7SszNylfxSzVuwhUKcVkC+Vce+bqzryA KrMC1DO5YOZlUfsuI+/0BNFBOTtejRu36STyEy3b/86KrODleb5tyGwEUpTcr9dDISMc GIHA== X-Gm-Message-State: AMCzsaWRYrST6oU9jzZbW9pAjd1uxURAXd9031QGYzltJZQBAj+oniiK bAiQfSkgxs83l9qQ+CcP/M0= X-Received: by 10.101.88.203 with SMTP id e11mr3730755pgu.173.1509495823545; Tue, 31 Oct 2017 17:23:43 -0700 (PDT) Received: from aurora.jms.id.au (bh02i525f01.au.ibm.com. [202.81.18.30]) by smtp.gmail.com with ESMTPSA id 76sm5826731pfp.80.2017.10.31.17.23.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Oct 2017 17:23:42 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Wed, 01 Nov 2017 10:53:32 +1030 From: Joel Stanley To: Wolfram Sang Cc: Brendan Higgins , Philipp Zabel , Rob Herring , Benjamin Herrenschmidt , Andrew Jeffery , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] i2c: aspeed: Deassert reset in probe Date: Wed, 1 Nov 2017 10:53:30 +1030 Message-Id: <20171101002330.24981-1-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In order to use i2c from a cold boot, the i2c peripheral must be taken out of reset. We request a shared reset controller each time a bus driver is loaded, as the reset is shared between the 14 i2c buses. On remove the reset is asserted, which only touches the hardware once the last i2c bus is removed. The reset is required as the I2C buses will not work without releasing the reset. Previously the driver only worked with out of tree hacks that released this reset before the driver was loaded. Update the device tree bindings to reflect this. Signed-off-by: Joel Stanley --- v4: - Make reset required and update device tree bindings - Remove unnecessary delay.h - Exit when reset controller probing fails - Fix ordering when removing the driver so that it is the opposite of probing v3: Check for bad reset controller probe (caused by eg. bad device tree) and set ->rst to NULL so assert/desassert does not cause a warning to be printed v2: Sort the headers Documentation/devicetree/bindings/i2c/i2c-aspeed.txt | 7 +++++-- drivers/i2c/busses/i2c-aspeed.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) -- 2.14.1 diff --git a/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt b/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt index bd6480b19535..e7106bfc1f13 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt +++ b/Documentation/devicetree/bindings/i2c/i2c-aspeed.txt @@ -7,7 +7,9 @@ Required Properties: - compatible : should be "aspeed,ast2400-i2c-bus" or "aspeed,ast2500-i2c-bus" - clocks : root clock of bus, should reference the APB - clock + clock in the second cell +- resets : phandle to reset controller with the reset number in + the second cell - interrupts : interrupt number - interrupt-parent : interrupt controller for bus, should reference a aspeed,ast2400-i2c-ic or aspeed,ast2500-i2c-ic @@ -40,7 +42,8 @@ i2c { #interrupt-cells = <1>; reg = <0x40 0x40>; compatible = "aspeed,ast2400-i2c-bus"; - clocks = <&clk_apb>; + clocks = <&syscon ASPEED_CLK_APB>; + resets = <&syscon ASPEED_RESET_I2C>; bus-frequency = <100000>; interrupts = <0>; interrupt-parent = <&i2c_ic>; diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 284f8670dbeb..7d4aeb4465b3 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -27,6 +27,7 @@ #include #include #include +#include #include /* I2C Register */ @@ -132,6 +133,7 @@ struct aspeed_i2c_bus { struct i2c_adapter adap; struct device *dev; void __iomem *base; + struct reset_control *rst; /* Synchronizes I/O mem access to base. */ spinlock_t lock; struct completion cmd_complete; @@ -847,6 +849,14 @@ static int aspeed_i2c_probe_bus(struct platform_device *pdev) /* We just need the clock rate, we don't actually use the clk object. */ devm_clk_put(&pdev->dev, parent_clk); + bus->rst = devm_reset_control_get_shared(&pdev->dev, NULL); + if (IS_ERR(bus->rst)) { + dev_err(&pdev->dev, + "missing or invalid reset controller device tree entry"); + return PTR_ERR(bus->rst); + } + reset_control_deassert(bus->rst); + ret = of_property_read_u32(pdev->dev.of_node, "bus-frequency", &bus->bus_frequency); if (ret < 0) { @@ -917,6 +927,8 @@ static int aspeed_i2c_remove_bus(struct platform_device *pdev) spin_unlock_irqrestore(&bus->lock, flags); + reset_control_assert(bus->rst); + i2c_del_adapter(&bus->adap); return 0;