From patchwork Fri Nov 16 14:00:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 151340 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp468677ljp; Fri, 16 Nov 2018 06:06:00 -0800 (PST) X-Google-Smtp-Source: AJdET5cwoFpOwcfNvYxynsQuVYBUVzXCxlvXrrNVOnyZJ7TaLzrnPyrdifgtyNTlMkNwqOKdsJeZ X-Received: by 2002:a50:ee1a:: with SMTP id g26mr8455304eds.266.1542377160515; Fri, 16 Nov 2018 06:06:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542377160; cv=none; d=google.com; s=arc-20160816; b=YKw4QT8aPAxghoTf3wQAPn33d5bQH0mzkzPMZzN2VST5LSR8pWx7HUfiq1+wEoEYhW lvnjnIVzdatOpqD9RpBit89yLTV0G9FP9Q6W49rz9kP2Fc1oq9zffMIq+3vEsfHUMTVG t4mM7s1Q1xsuz0YPHs9yQjhVmu0v+jE/ZNovZgIK9+8j4DflbqZ5wYumB+7kA4jrMOCj HD6vBKoEveyhZu6yLvyffg2vJjOi91SKEWnbzWUOqXxRMa38qOQ8nylSybuGRe5tMC7S K6xZnPXC8VyEUx0v+a55cC/geOTD6sTes4Si8/X1xTnmcFZo1XpxrENjqG5GNvVYiQXj nW4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature; bh=QYn7m6BH31WJSFZAwoZUpvWA2AEZlG7H20+urwS80W8=; b=YKfuuo+6DNZz47fGfqnAQoIv0o4uCeA1HJLWmf+H6p6VNJMLlmJWn/K7M/3pkxHuN3 mzB0PTR9XjIy+oRmi9jYkayFseBuOWTAJGj4qsV6nafp85EXC9/Ya7iy7O5B1OykbWsJ iAgxrbYWOkvV7cVLojyTuFu+BoHTVM3fGAEavdSMM4Co9MmQU/a8hg1BOZvGQyYhT3t4 4P8owaOGGFouRzzkQ4RSOb2fdPYFlmza5hNwkAIuNO4lW+aFeQomN4NDebRqVqO2eN7+ 1AltRoAHH0WQhtXNylt0RK28j12bGj7qDBSMk/qgIV5WSlnke0HRfozL+TslDO52EZ4t Jtew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D8b4Jx7+; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id l9-v6si6345137ejf.91.2018.11.16.06.06.00; Fri, 16 Nov 2018 06:06:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D8b4Jx7+; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 1D82DC22320; Fri, 16 Nov 2018 14:04:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 71D17C224EE; Fri, 16 Nov 2018 14:02:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 752C6C2250F; Fri, 16 Nov 2018 14:01:31 +0000 (UTC) Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by lists.denx.de (Postfix) with ESMTPS id 4C581C224FF for ; Fri, 16 Nov 2018 14:01:01 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id r63-v6so22293530wma.4 for ; Fri, 16 Nov 2018 06:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sOPemw7CQBPO+68fqz/LsUMUZWB/gj4l8Fem4wYOt3s=; b=D8b4Jx7+d+YstOPkdhtguKraphnbtocNYjavs5njcTiS/UXDiOkvfbH5pGY4UxPDvk 1xpVbYS28rO/MXc44Njy8q/qSCSRXXddtnsgw1dkdSoBeciSzVTgA98bleUoWT4yw39r D2V3tU9xQsEUst+0merqYPnIdk4eV0rqBDock= 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:in-reply-to :references; bh=sOPemw7CQBPO+68fqz/LsUMUZWB/gj4l8Fem4wYOt3s=; b=HhEzqPWevhFghXm6R7ewXQSgHI1Z8V2Q2XJoAW6z3RtskamBvdkmdbpU7K9rJbHmFP dULw9m59Zv4dcK/+YLWUiqQjYOD5dlZNEA4h0jlCDel2+eQfxBL1aDULx7qWDI4JyFAZ N/B1ET21LhZbrHc6RdELAwyc64vcGCs3Ae/9pb2hLH1YI6DX5Rx5Qbnud/b+3hIdFf0I TsX1Y30Xz3a+PSVKNtigqdQOMp0Wm6QCbxcXMJihzRx3w9yG8wZUTmGHM5Bt+cvhC5VL G1xZWEIpv1MP8sOtpWx9BVytPKcjLQ4bm0ZWmLnfX6HGcUVfVKeY1vJC8po0827gIGNn bVww== X-Gm-Message-State: AGRZ1gIksPPQScfee7rTedqf12LDW7sq4G+djtSmL+lXVjC5k3RFDoOF yyLp+CHPBPSgK6v/uV3dveZuZw== X-Received: by 2002:a1c:88c1:: with SMTP id k184-v6mr2700877wmd.84.1542376860753; Fri, 16 Nov 2018 06:01:00 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:105d:3df6:606e:fa38:9819:9c69]) by smtp.gmail.com with ESMTPSA id s81sm11208060wmf.14.2018.11.16.06.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Nov 2018 06:01:00 -0800 (PST) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: patrick.delaunay@st.com, albert.u.boot@aribaud.net, sjg@chromium.org, christophe.kerello@st.com, patrice.chotard@st.com Date: Fri, 16 Nov 2018 15:00:38 +0100 Message-Id: <20181116140039.11628-4-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181116140039.11628-1-benjamin.gaignard@st.com> References: <20181116140039.11628-1-benjamin.gaignard@st.com> Cc: uboot-stm32@st-md-mailman.stormreply.com, u-boot@lists.denx.de, Benjamin Gaignard Subject: [U-Boot] [PATCH v4 3/4] hwspinlock: add stm32 hardware spinlock support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Implement hardware spinlock support for STM32MP1. Signed-off-by: Benjamin Gaignard Reviewed-by: Simon Glass Reviewed-by: Patrice Chotard --- arch/arm/dts/stm32mp157c-ed1.dts | 4 ++ arch/arm/dts/stm32mp157c.dtsi | 9 ++++ configs/stm32mp15_basic_defconfig | 2 + drivers/hwspinlock/Kconfig | 8 +++ drivers/hwspinlock/Makefile | 1 + drivers/hwspinlock/stm32_hwspinlock.c | 92 +++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 drivers/hwspinlock/stm32_hwspinlock.c diff --git a/arch/arm/dts/stm32mp157c-ed1.dts b/arch/arm/dts/stm32mp157c-ed1.dts index f8b7701167..fc277dd7d2 100644 --- a/arch/arm/dts/stm32mp157c-ed1.dts +++ b/arch/arm/dts/stm32mp157c-ed1.dts @@ -365,6 +365,10 @@ usb33d-supply = <&usb33>; }; +&hwspinlock { + status = "okay"; +}; + &usbphyc_port0 { phy-supply = <&vdd_usb>; vdda1v1-supply = <®11>; diff --git a/arch/arm/dts/stm32mp157c.dtsi b/arch/arm/dts/stm32mp157c.dtsi index 33c5981869..37cadfa30c 100644 --- a/arch/arm/dts/stm32mp157c.dtsi +++ b/arch/arm/dts/stm32mp157c.dtsi @@ -690,6 +690,15 @@ status = "disabled"; }; + hwspinlock: hwspinlock@4c000000 { + compatible = "st,stm32-hwspinlock"; + #hwlock-cells = <1>; + reg = <0x4c000000 0x400>; + clocks = <&rcc HSEM>; + clock-names = "hwspinlock"; + status = "disabled"; + }; + rcc: rcc@50000000 { compatible = "st,stm32mp1-rcc", "syscon"; reg = <0x50000000 0x1000>; diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 3bf7538089..c8409fd04e 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -32,6 +32,8 @@ CONFIG_CMD_EXT4_WRITE=y # CONFIG_SPL_DOS_PARTITION is not set CONFIG_DEFAULT_DEVICE_TREE="stm32mp157c-ev1" CONFIG_STM32_ADC=y +CONFIG_DM_HWSPINLOCK=y +CONFIG_HWSPINLOCK_STM32=y CONFIG_DM_I2C=y CONFIG_SYS_I2C_STM32F7=y CONFIG_LED=y diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index de367fd2a9..96d4f5d6ca 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -13,4 +13,12 @@ config HWSPINLOCK_SANDBOX can be probed and support all the methods of HWSPINLOCK, but does not really do anything. +config HWSPINLOCK_STM32 + bool "Enable Hardware Spinlock support for STM32" + depends on ARCH_STM32MP && DM_HWSPINLOCK + help + Enable hardware spinlock support in STM32MP. Hardware spinlocks are + hardware mutex which provide a synchronisation mechanism for the + various processors on the SoC. + endmenu diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile index 2704d6814f..289b12a256 100644 --- a/drivers/hwspinlock/Makefile +++ b/drivers/hwspinlock/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock-uclass.o obj-$(CONFIG_HWSPINLOCK_SANDBOX) += sandbox_hwspinlock.o +obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c new file mode 100644 index 0000000000..a32bde4906 --- /dev/null +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include + +#define STM32_MUTEX_COREID BIT(8) +#define STM32_MUTEX_LOCK_BIT BIT(31) +#define STM32_MUTEX_NUM_LOCKS 32 + +struct stm32mp1_hws_priv { + fdt_addr_t base; +}; + +static int stm32mp1_lock(struct udevice *dev, int index) +{ + struct stm32mp1_hws_priv *priv = dev_get_priv(dev); + u32 status; + + if (index >= STM32_MUTEX_NUM_LOCKS) + return -EINVAL; + + status = readl(priv->base + index * sizeof(u32)); + if (status == (STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID)) + return -EBUSY; + + writel(STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID, + priv->base + index * sizeof(u32)); + + status = readl(priv->base + index * sizeof(u32)); + if (status != (STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID)) + return -EINVAL; + + return 0; +} + +static int stm32mp1_unlock(struct udevice *dev, int index) +{ + struct stm32mp1_hws_priv *priv = dev_get_priv(dev); + + if (index >= STM32_MUTEX_NUM_LOCKS) + return -EINVAL; + + writel(STM32_MUTEX_COREID, priv->base + index * sizeof(u32)); + + return 0; +} + +static int stm32mp1_hwspinlock_probe(struct udevice *dev) +{ + struct stm32mp1_hws_priv *priv = dev_get_priv(dev); + struct clk clk; + int ret; + + priv->base = dev_read_addr(dev); + if (priv->base == FDT_ADDR_T_NONE) + return -EINVAL; + + ret = clk_get_by_index(dev, 0, &clk); + if (ret) + return ret; + + ret = clk_enable(&clk); + if (ret) + clk_free(&clk); + + return ret; +} + +static const struct hwspinlock_ops stm32mp1_hwspinlock_ops = { + .lock = stm32mp1_lock, + .unlock = stm32mp1_unlock, +}; + +static const struct udevice_id stm32mp1_hwspinlock_ids[] = { + { .compatible = "st,stm32-hwspinlock" }, + {} +}; + +U_BOOT_DRIVER(hwspinlock_stm32mp1) = { + .name = "hwspinlock_stm32mp1", + .id = UCLASS_HWSPINLOCK, + .of_match = stm32mp1_hwspinlock_ids, + .ops = &stm32mp1_hwspinlock_ops, + .probe = stm32mp1_hwspinlock_probe, + .priv_auto_alloc_size = sizeof(struct stm32mp1_hws_priv), +};