From patchwork Mon Feb 13 15:33:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 9569993 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 B79B860442 for ; Mon, 13 Feb 2017 15:34:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAF3D20564 for ; Mon, 13 Feb 2017 15:34:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F490269DA; Mon, 13 Feb 2017 15:34:36 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CB1D020564 for ; Mon, 13 Feb 2017 15:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ZH/9ztrc17YDf1z7CFbCB1H0VNXP71cUJjPvp1clNMs=; b=Ad+ xW/IZKPrpmTbauUVZWg0dWrC14zS6RnU/JnozgCAQXC3opCmCNIzuxogGVAJy0ic+X9Oux+8OffFk RhYB3Lyx3Ql/NuO27JBKJSF/vXpsyrTN4pYJ09PuRv6Cc9naqRV51N9Vq6VvdESW/ODC9apyKBfYl gM22PfL4ABzNdYGbzRnqilLSgDBhP9VlEzDjew/2Qvk4iT98CHtq+Hn6N5PhHNXCL5Wzbh9X5cgNh CWCfsn3tHdK5dsHlStnzFP43E60P3oQxh246ksIaEZ1vOzrGZ1hTWk5EP/TooZJHGTHMgfRPbeABF heF4MRmtwWYSvhwE30+s3SwcocymW0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cdIe3-0006Ik-I2; Mon, 13 Feb 2017 15:34:27 +0000 Received: from mail-ot0-x241.google.com ([2607:f8b0:4003:c0f::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cdIdv-0006EG-Eh for linux-arm-kernel@lists.infradead.org; Mon, 13 Feb 2017 15:34:23 +0000 Received: by mail-ot0-x241.google.com with SMTP id 36so11971153otx.3 for ; Mon, 13 Feb 2017 07:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7vGkBTCoP6LW7ycs0QJ+RylzkRAmdBgD1RLTPXd83O4=; b=hJ4qwoz7CUGcAHSORTPXdJOKhlIcbo/+ql/S4dhJwv2KcZWVKFlREyfiQ0CWQdOiPI tygwIYosC9HEdmghMk9IvcQocGpTVE94CnsL9S6H44deGyB4rdR0JEL9iXbCUiTQ4eCc p972P98DSt7AWu4cNg6IWbvE2ZTxmtBhHIRGq1W7LqA0IfOnQoFqOjOTPFVjDBOEZ2aL XfpmLQJ8CUHqnQDUPrI2xlTZUr6jcBXHEgYK7FrA/RElqyEuXofXhBqtPu8cRjlcXwnq Uiw7X1sED/1VlUh6vJ+4ErpAKpdEQoakNX+UXNj3HIN2TPND4cfCE/HMBpva654mx5xH IKJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7vGkBTCoP6LW7ycs0QJ+RylzkRAmdBgD1RLTPXd83O4=; b=LpoMM0aoGODtS7qAAreZoHHCQO2u8gFZ1i5ktqsmOD943ic9bjrJo7ctRfC22Qq2ge SzezHc2ejQxvbqy8cn1gu/WjxCBJSIQ3mKfu+WF9fUW6VfIkGGIc2RnDNir/H7x06JQN cKsUqOFITFjjaZ/veSnRUmkzMgQAFkTYcXHskLBQJg42AUC6zvlUuZLq8TkVRM3VM+ui CvwCiUjET6kgJV7Ddb01rkjblCjaY8YVeO98wNli7UadEH9nR18Yb4Rh8FlkNlItkRD3 p3a3V0ODuZdO28be7l5jcTOl238laQw5IvXEu8Tr3p9sXxhYWUrXDSGOmErUu9bQZ+Kt jNJA== X-Gm-Message-State: AMke39kcDpLSsvBPNnqnybSZDSY2coxMn1m3Cr8hqSJC+Uk6o4V2CpMmXE9F0S5ctNh0iQ== X-Received: by 10.98.7.11 with SMTP id b11mr26357275pfd.154.1487000038349; Mon, 13 Feb 2017 07:33:58 -0800 (PST) Received: from localhost.localdomain (c-73-19-0-61.hsd1.wa.comcast.net. [73.19.0.61]) by smtp.gmail.com with ESMTPSA id a8sm21740424pfa.19.2017.02.13.07.33.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Feb 2017 07:33:57 -0800 (PST) From: Andrey Smirnov To: Philipp Zabel Subject: [PATCH v2] reset: Add i.MX7 SRC reset driver Date: Mon, 13 Feb 2017 07:33:37 -0800 Message-Id: <20170213153338.13518-1-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170213_073419_700223_9487F7AC X-CRM114-Status: GOOD ( 22.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Andrey Smirnov , linux-kernel@vger.kernel.org, Rob Herring , linux-arm-kernel@lists.infradead.org, Lucas Stach MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This driver exposes various reset faculties, impelented by System Reset Controller IP block, as a reset driver. Currently only PCIE related reset lines are implemented. Cc: Lucas Stach Cc: Rob Herring Cc: Mark Rutland Cc: devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Andrey Smirnov --- Changes since v1 (see [v1]): - Various small DT bindings description fixes as per feedback from Rob Herring [v1] https://lkml.org/lkml/2017/2/6/554 .../devicetree/bindings/reset/fsl,imx7-src.txt | 47 +++++++ drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-imx7.c | 149 +++++++++++++++++++++ include/dt-bindings/reset/imx7-reset.h | 28 ++++ 5 files changed, 233 insertions(+) create mode 100644 Documentation/devicetree/bindings/reset/fsl,imx7-src.txt create mode 100644 drivers/reset/reset-imx7.c create mode 100644 include/dt-bindings/reset/imx7-reset.h diff --git a/Documentation/devicetree/bindings/reset/fsl,imx7-src.txt b/Documentation/devicetree/bindings/reset/fsl,imx7-src.txt new file mode 100644 index 0000000..c38f7f0 --- /dev/null +++ b/Documentation/devicetree/bindings/reset/fsl,imx7-src.txt @@ -0,0 +1,47 @@ +Freescale i.MX7 System Reset Controller +====================================== + +Please also refer to reset.txt in this directory for common reset +controller binding usage. + +Required properties: +- compatible: Should be "fsl,imx7-src", "syscon" +- reg: should be register base and length as documented in the + datasheet +- interrupts: Should contain SRC interrupt +- #reset-cells: 1, see below + +example: + +src: reset-controller@30390000 { + compatible = "fsl,imx7d-src", "syscon"; + reg = <0x30390000 0x2000>; + interrupts = ; + #reset-cells = <1>; +}; + + +Specifying reset lines connected to IP modules +============================================== + +The system reset controller can be used to reset various set of +peripherals. Device nodes that need access to reset lines should +specify them as a reset phandle in their corresponding node as +specified in reset.txt. + +Example: + + pcie: pcie@33800000 { + + ... + + resets = <&src IMX7_RESET_PCIEPHY>, + <&src IMX7_RESET_PCIE_CTRL_APPS>; + reset-names = "pciephy", "apps"; + + ... + }; + + +For list of all valid reset indicies see + diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 172dc96..664a88b 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -92,6 +92,14 @@ config RESET_ZYNQ help This enables the reset controller driver for Xilinx Zynq SoCs. +config RESET_IMX7 + bool "i.MX7 Reset Driver" + depends on SOC_IMX7D || COMPILE_TEST + select MFD_SYSCON + default SOC_IMX7D + help + This enables the reset controller driver for i.MX7 SoCs. + source "drivers/reset/sti/Kconfig" source "drivers/reset/hisilicon/Kconfig" source "drivers/reset/tegra/Kconfig" diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 13b346e..417c9d0 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o obj-$(CONFIG_RESET_ZYNQ) += reset-zynq.o +obj-$(CONFIG_RESET_IMX7) += reset-imx7.o diff --git a/drivers/reset/reset-imx7.c b/drivers/reset/reset-imx7.c new file mode 100644 index 0000000..6d90e57 --- /dev/null +++ b/drivers/reset/reset-imx7.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2017, Impinj, Inc. + * + * i.MX7 System Reset Controller (SRC) driver + * + * Author: Andrey Smirnov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct imx7_src { + struct reset_controller_dev rcdev; + struct device *dev; + struct regmap *regmap; +}; + +enum imx7_src_registers { + SRC_PCIEPHY_RCR = 0x002c, + SRC_PCIEPHY_RCR_PCIEPHY_G_RST = BIT(1), + SRC_PCIEPHY_RCR_PCIEPHY_BTN = BIT(2), + SRC_PCIEPHY_RCR_PCIE_CTRL_APPS_EN = BIT(6), +}; + +static struct imx7_src *to_imx7_src(struct reset_controller_dev *rcdev) +{ + return container_of(rcdev, struct imx7_src, rcdev); +} + +static int imx7_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct imx7_src *imx7src = to_imx7_src(rcdev); + + switch (id) { + case IMX7_RESET_PCIE_CTRL_APPS: + regmap_update_bits(imx7src->regmap, + SRC_PCIEPHY_RCR, + SRC_PCIEPHY_RCR_PCIE_CTRL_APPS_EN, 0); + return 0; + + case IMX7_RESET_PCIEPHY: + regmap_update_bits(imx7src->regmap, + SRC_PCIEPHY_RCR, + SRC_PCIEPHY_RCR_PCIEPHY_G_RST, + SRC_PCIEPHY_RCR_PCIEPHY_G_RST); + regmap_update_bits(imx7src->regmap, + SRC_PCIEPHY_RCR, + SRC_PCIEPHY_RCR_PCIEPHY_BTN, + SRC_PCIEPHY_RCR_PCIEPHY_BTN); + return 0; + default: + dev_err(imx7src->dev, "Unknown reset ID %lu\n", id); + break; + } + + return -EINVAL; +} + +static int imx7_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct imx7_src *imx7src = to_imx7_src(rcdev); + + switch (id) { + case IMX7_RESET_PCIE_CTRL_APPS: + regmap_update_bits(imx7src->regmap, + SRC_PCIEPHY_RCR, + SRC_PCIEPHY_RCR_PCIE_CTRL_APPS_EN, + SRC_PCIEPHY_RCR_PCIE_CTRL_APPS_EN); + return 0; + + case IMX7_RESET_PCIEPHY: + /* wait for more than 10us to release phy g_rst and btnrst */ + udelay(10); + regmap_update_bits(imx7src->regmap, + SRC_PCIEPHY_RCR, + SRC_PCIEPHY_RCR_PCIEPHY_G_RST, 0); + regmap_update_bits(imx7src->regmap, + SRC_PCIEPHY_RCR, + SRC_PCIEPHY_RCR_PCIEPHY_BTN, 0); + return 0; + default: + dev_err(imx7src->dev, "Unknown reset ID %lu\n", id); + break; + }; + + return -EINVAL; +} + +static const struct reset_control_ops imx7_reset_ops = { + .assert = imx7_reset_assert, + .deassert = imx7_reset_deassert, +}; + +static int imx7_reset_probe(struct platform_device *pdev) +{ + struct imx7_src *imx7src; + struct device *dev = &pdev->dev; + + imx7src = devm_kzalloc(dev, sizeof(*imx7src), GFP_KERNEL); + if (!imx7src) + return -ENOMEM; + + imx7src->dev = dev; + imx7src->regmap = syscon_node_to_regmap(dev->of_node); + if (IS_ERR(imx7src->regmap)) { + dev_err(dev, "Unable to get imx7-src regmap"); + return PTR_ERR(imx7src->regmap); + } + + imx7src->rcdev.owner = THIS_MODULE; + imx7src->rcdev.nr_resets = IMX7_RESET_NUM; + imx7src->rcdev.ops = &imx7_reset_ops; + imx7src->rcdev.of_node = dev->of_node; + + return devm_reset_controller_register(dev, &imx7src->rcdev); +} + +static const struct of_device_id imx7_reset_dt_ids[] = { + { .compatible = "fsl,imx7d-src", }, + { /* sentinel */ }, +}; + +static struct platform_driver imx7_reset_driver = { + .probe = imx7_reset_probe, + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = imx7_reset_dt_ids, + }, +}; +builtin_platform_driver(imx7_reset_driver); diff --git a/include/dt-bindings/reset/imx7-reset.h b/include/dt-bindings/reset/imx7-reset.h new file mode 100644 index 0000000..e20f2db --- /dev/null +++ b/include/dt-bindings/reset/imx7-reset.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2017 Impinj, Inc. + * + * Author: Andrey Smirnov + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DT_BINDING_RESET_IMX7_H +#define DT_BINDING_RESET_IMX7_H + +#define IMX7_RESET_PCIE_CTRL_APPS 0 +#define IMX7_RESET_PCIEPHY 1 + +#define IMX7_RESET_NUM 2 + +#endif +