From patchwork Wed Dec 7 13:14:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiu Moga X-Patchwork-Id: 1713292 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=Iy3NSJdQ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NRyb51bqmz23ys for ; Thu, 8 Dec 2022 00:20:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DAF8785605; Wed, 7 Dec 2022 14:18:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="Iy3NSJdQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1355385642; Wed, 7 Dec 2022 14:18:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0A6448545F for ; Wed, 7 Dec 2022 14:17:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=Sergiu.Moga@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1670419067; x=1701955067; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ows9teBDIHzX35fIuwjcKGgkOoMysa4C3Z4GoxIEpHs=; b=Iy3NSJdQ07+NvrgEdnqePT3fuR+X1/zDNMD57uGCCbivVV9ST7O6WyVX DvUC9kusifsqcKv1/iKoCX9gSCNYH2xLeA2x6Hgr7O2AW4hwbZA98RFsI leh341pbTrkcdHRhaCPACg8WxNVGm9TX2XS8lz21S0dYLNT9XsPQlTU+J 0OdB2GG5aHZJrEPTjB4KiNH5eVdGhNF0wYJOHPI56gI6PhC7RRntPYOuV qIGAG/yscXbYhumjAtgCQY2mI9hXBLECSXxPTpGDaGJjluJKJ10jSQXcn OvSrEiw0mRoJdDtsR17nhSRG5pAivB+cVMZcHb5Aekf0L0rU9KoP2mhLK g==; X-IronPort-AV: E=Sophos;i="5.96,225,1665471600"; d="scan'208";a="192068654" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Dec 2022 06:17:44 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 7 Dec 2022 06:17:43 -0700 Received: from ROB-ULT-M68701.mchp-main.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 7 Dec 2022 06:17:37 -0700 From: Sergiu Moga To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH 11/18] reset: at91: Add reset driver for basic assert/deassert operations Date: Wed, 7 Dec 2022 15:14:40 +0200 Message-ID: <20221207131447.40590-12-sergiu.moga@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221207131447.40590-1-sergiu.moga@microchip.com> References: <20221207131447.40590-1-sergiu.moga@microchip.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Add support for at91 reset controller's basic assert/deassert operations. Since this driver conflicts with the SYSRESET driver because they both bind to the same RSTC node, implement a custom bind hook that would manually bind the sysreset driver, if enabled, to the same RSTC DT node. Furthermore, delete the no longer needed compatibles from the SYSRESET driver and rename it to make sure than any possible conflicts are avoided. Signed-off-by: Sergiu Moga Tested-by: Mihai Sain --- drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-at91.c | 143 +++++++++++++++++++++++++++++++ drivers/sysreset/sysreset_at91.c | 10 +-- 4 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 drivers/reset/reset-at91.c diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 4cb0ba0850..e4039d7474 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -211,4 +211,12 @@ config RESET_DRA7 help Support for TI DRA7-RESET subsystem. Basic Assert/Deassert is supported. + +config RESET_AT91 + bool "Enable support for Microchip/Atmel Reset Controller driver" + depends on DM_RESET && ARCH_AT91 + help + This enables the Reset Controller driver support for Microchip/Atmel + SoCs. Mainly used to expose assert/deassert methods to other drivers + that require it. endmenu diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 0620b62809..6c8b45ecba 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -31,3 +31,4 @@ obj-$(CONFIG_RESET_RASPBERRYPI) += reset-raspberrypi.o obj-$(CONFIG_RESET_SCMI) += reset-scmi.o obj-$(CONFIG_RESET_ZYNQMP) += reset-zynqmp.o obj-$(CONFIG_RESET_DRA7) += reset-dra7.o +obj-$(CONFIG_RESET_AT91) += reset-at91.o diff --git a/drivers/reset/reset-at91.c b/drivers/reset/reset-at91.c new file mode 100644 index 0000000000..ee035a8934 --- /dev/null +++ b/drivers/reset/reset-at91.c @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Support for Atmel/Microchip Reset Controller. + * + * Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries + * + * Author: Sergiu Moga + */ + +#include +#include +#include +#include +#include +#include +#include + +struct at91_reset { + void __iomem *dev_base; + struct at91_reset_data *data; +}; + +struct at91_reset_data { + u32 n_device_reset; + u8 device_reset_min_id; + u8 device_reset_max_id; +}; + +static const struct at91_reset_data sama7g5_data = { + .n_device_reset = 3, + .device_reset_min_id = SAMA7G5_RESET_USB_PHY1, + .device_reset_max_id = SAMA7G5_RESET_USB_PHY3, +}; + +static int at91_rst_update(struct at91_reset *reset, unsigned long id, + bool assert) +{ + u32 val; + + if (!reset->dev_base) + return 0; + + val = readl(reset->dev_base); + if (assert) + val |= BIT(id); + else + val &= ~BIT(id); + writel(val, reset->dev_base); + + return 0; +} + +static int at91_reset_of_xlate(struct reset_ctl *reset_ctl, + struct ofnode_phandle_args *args) +{ + struct at91_reset *reset = dev_get_priv(reset_ctl->dev); + + if (!reset->data->n_device_reset || + args->args[0] < reset->data->device_reset_min_id || + args->args[0] > reset->data->device_reset_max_id) + return -EINVAL; + + reset_ctl->id = args->args[0]; + + return 0; +} + +static int at91_rst_assert(struct reset_ctl *reset_ctl) +{ + struct at91_reset *reset = dev_get_priv(reset_ctl->dev); + + return at91_rst_update(reset, reset_ctl->id, true); +} + +static int at91_rst_deassert(struct reset_ctl *reset_ctl) +{ + struct at91_reset *reset = dev_get_priv(reset_ctl->dev); + + return at91_rst_update(reset, reset_ctl->id, false); +} + +struct reset_ops at91_reset_ops = { + .of_xlate = at91_reset_of_xlate, + .rst_assert = at91_rst_assert, + .rst_deassert = at91_rst_deassert, +}; + +static int at91_reset_probe(struct udevice *dev) +{ + struct at91_reset *reset = dev_get_priv(dev); + struct clk sclk; + int ret; + + reset->data = (struct at91_reset_data *)dev_get_driver_data(dev); + reset->dev_base = dev_remap_addr_index(dev, 1); + if (reset->data && reset->data->n_device_reset && !reset->dev_base) + return -EINVAL; + + ret = clk_get_by_index(dev, 0, &sclk); + if (ret) + return ret; + + ret = clk_prepare_enable(&sclk); + + return ret; +} + +static int at91_reset_bind(struct udevice *dev) +{ + struct udevice *at91_sysreset; + + if (CONFIG_IS_ENABLED(SYSRESET_AT91)) + return device_bind_driver_to_node(dev, "at91_sysreset", + "at91_sysreset", + dev_ofnode(dev), + &at91_sysreset); + + return 0; +} + +static const struct udevice_id at91_reset_ids[] = { + { + .compatible = "microchip,sama7g5-rstc", + .data = (ulong)&sama7g5_data, + }, + { + .compatible = "atmel,sama5d3-rstc", + }, + { + .compatible = "microchip,sam9x60-rstc", + }, + { } +}; + +U_BOOT_DRIVER(at91_reset) = { + .name = "at91_reset", + .id = UCLASS_RESET, + .of_match = at91_reset_ids, + .bind = at91_reset_bind, + .probe = at91_reset_probe, + .priv_auto = sizeof(struct at91_reset), + .ops = &at91_reset_ops, +}; diff --git a/drivers/sysreset/sysreset_at91.c b/drivers/sysreset/sysreset_at91.c index 6119a29927..fc85f31ebf 100644 --- a/drivers/sysreset/sysreset_at91.c +++ b/drivers/sysreset/sysreset_at91.c @@ -56,17 +56,9 @@ static struct sysreset_ops at91_sysreset = { .request = at91_sysreset_request, }; -static const struct udevice_id a91_sysreset_ids[] = { - { .compatible = "atmel,sama5d3-rstc" }, - { .compatible = "microchip,sam9x60-rstc" }, - { .compatible = "microchip,sama7g5-rstc" }, - { } -}; - U_BOOT_DRIVER(sysreset_at91) = { .id = UCLASS_SYSRESET, - .name = "at91_reset", + .name = "at91_sysreset", .ops = &at91_sysreset, .probe = at91_sysreset_probe, - .of_match = a91_sysreset_ids, };