From patchwork Mon Feb 6 15:08:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 9558191 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 EDCE660413 for ; Mon, 6 Feb 2017 15:10:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D89F627C05 for ; Mon, 6 Feb 2017 15:10:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB7142811E; Mon, 6 Feb 2017 15:10:11 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no 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 B7D9927FA8 for ; Mon, 6 Feb 2017 15:10:10 +0000 (UTC) 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 1cakvh-0006mr-UF; Mon, 06 Feb 2017 15:10:09 +0000 Received: from mail-pg0-f67.google.com ([74.125.83.67]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cakvc-0005WO-2S for linux-arm-kernel@lists.infradead.org; Mon, 06 Feb 2017 15:10:08 +0000 Received: by mail-pg0-f67.google.com with SMTP id 194so9329308pgd.0 for ; Mon, 06 Feb 2017 07:09:43 -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=P+ZbJskhNIgsOLOfXmn32/rojQaNwGSA0m6bibnT6f8=; b=fM7mAnEFVR3C07k+3fCwSwuB/HaK401k+RXfw7+Xjm1lpT+69JFOQEI2AhVnRgBb5e KoZA74lVjO38b0Ynv01r7F4MqlbzpEP1IonHjnWz3UVNz6g0ffLufKNk9ImK1jQptqVc BDtjlUjZE7U7fhclHOsAlMXn3NxCTD3WuLpPc9tAJ585EoNSoqJvGR6bBXuNH3RTz0yL myHLKIQprubzubna40xZelVjno83JXRbADfMCwdNyxneTd/mHU98QqQ5gQwbvlaDkbBl cOEykBrl7WrvMSMsBVnH8bWrkISo8amA/07/ZxEvfk5PG3QeAt4aqamHzTD34sUtxkCA 55ww== 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=P+ZbJskhNIgsOLOfXmn32/rojQaNwGSA0m6bibnT6f8=; b=qVkFmadwrSSDxcOskepitpG+iNHyn64Tl/HGu4JhLsmdPiRCPw+mXdYhe6SHxH1EPD xH6SCp9tnVqtvFuUBNDK3UaXzoZtn9iobEWtBIaNJt+9h4UTZaOICVKCcHz8rQSrmqq4 hMTLAzFHFBY0Ol1QwvX98II49i82ljQJsHHdy5DTrtJfWi/rz0ceyqgzzKVnj1q0PCYV epWaiNEKAwTB8JoxwZa3oHRpDw2aobQ62BnxSkZAyrOWQHV1x8Esag5An77f5BnDUqXh zOl7KQIVbD0eQlgL+eE9/qWrUhMfEu4xN2q26rqdzKIPhGheMQKHniWyLVY2Uhx/lCsS rxfQ== X-Gm-Message-State: AIkVDXLkeYwNFlHWPWeS13gmWDfzG8W7cRysGzB36xPcEF9meU9PSwSdF6KwcX0KwtMj7Q== X-Received: by 10.99.173.14 with SMTP id g14mr13985132pgf.176.1486393723138; Mon, 06 Feb 2017 07:08:43 -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 u24sm3557495pfi.25.2017.02.06.07.08.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Feb 2017 07:08:42 -0800 (PST) From: Andrey Smirnov To: Philipp Zabel Subject: [PATCH] reset: Add i.MX7 SRC reset driver Date: Mon, 6 Feb 2017 07:08:36 -0800 Message-Id: <20170206150836.10001-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-20170206_071004_178239_51D76AE7 X-CRM114-Status: GOOD ( 22.43 ) 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 , Fabio Estevam , 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: Fabio Estevam Cc: devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Andrey Smirnov --- .../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..19a77f9 --- /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: src@30390000 { + compatible = "fsl,imx7d-src", "syscon"; + reg = <0x30390000 0x10000>; + 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@0x33800000 { + + ... + + 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 +