From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752238AbdJ3Do4 (ORCPT ); Sun, 29 Oct 2017 23:44:56 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:48671 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752213AbdJ3Dox (ORCPT ); Sun, 29 Oct 2017 23:44:53 -0400 X-Google-Smtp-Source: ABhQp+QqUg4K8hUqD2/2dXzsvmKDulK/5Ra4Cu83xvbMcz+vXNXrQmiGd1jP7oh05dKqDwh/DOxMkg== From: Joel Stanley To: Wolfram Sang Cc: Brendan Higgins , Philipp Zabel , Benjamin Herrenschmidt , Andrew Jeffery , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] i2c: aspeed: Deassert reset in probe Date: Mon, 30 Oct 2017 14:14:38 +1030 Message-Id: <20171030034438.26482-1-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@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 request is optional, so if a device tree does not specify a reset controller (or the driver is not built in), the driver continues to probe. Reviewed-by: Brendan Higgins Reviewed-by: Philipp Zabel Signed-off-by: Joel Stanley --- 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 --- drivers/i2c/busses/i2c-aspeed.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 284f8670dbeb..5dec00d663eb 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include /* I2C Register */ @@ -132,6 +134,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 +850,13 @@ 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_optional_shared(&pdev->dev, NULL); + if (IS_ERR(bus->rst)) { + dev_err(&pdev->dev, "invalid reset controller in device tree"); + bus->rst = NULL; + } else + reset_control_deassert(bus->rst); + ret = of_property_read_u32(pdev->dev.of_node, "bus-frequency", &bus->bus_frequency); if (ret < 0) { @@ -919,6 +929,8 @@ static int aspeed_i2c_remove_bus(struct platform_device *pdev) i2c_del_adapter(&bus->adap); + reset_control_assert(bus->rst); + return 0; } -- 2.14.1