From patchwork Fri Nov 16 14:00:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 151339 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp467496ljp; Fri, 16 Nov 2018 06:05:05 -0800 (PST) X-Google-Smtp-Source: AJdET5fAXZVylWQdKaBIBwgOEjNWspRbtQwl7yUFFQDirqCko9LXHEOT29FdjCR+fHfCcf3hN/Z+ X-Received: by 2002:a17:906:64cb:: with SMTP id p11-v6mr8895960ejn.181.1542377105410; Fri, 16 Nov 2018 06:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542377105; cv=none; d=google.com; s=arc-20160816; b=ytnmB/Ft/+lBJbS72dQSW/bY8i7aCRmRgYPDp82brVmVVnxBBUB7vQqU7Odh1dLADM wMAGhPLg/sGsXiB+XaSAILFSbUuz+DwDh/0l4Dl21MgavX23qIwlrZJnNRd2TPelOquL E3lwgApRchoNE5vU4dFCA+/SpbOkC/3jERtA/1Ml/7hhcDK136QRHJM3q/u+SRcy7s6j Cw3eaB0h3xqSZvZ4o+N0nbtHZFo4IMqxO2INQEOn8suHbZWhTxno2BsR/5fJ6g60Ry1Y +lzC7YIP3yPu+kSEdH2GzKri5WetFvQ5GmWJg5bFgz/fvhcMk538vMNbeQzjQVmQwDWx 8FhQ== 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=atC1zDoZTURexRBb5ZTHoG2jBvkrYoVuyj8ocvBtOZs=; b=H+EWina/RqBL552spq2UhB4ZNFvHwZf9/AcRzf5Ga5tr0EPZ+EnV2DufLMKd9H+Z+6 MnSEJ96TUpdv3HHjE03BZAG1FhaTCmzDzCYF8rr1XywNv/TTgJ7+7B+6tfuttU4NuuqX bR2RkyrWMfwE49CchTuYxA7kMy6vd+Db3EjMDYb5+/MxZx2RovEsoztwcRCJh26aX5a4 B8gtb6SzBpnDArm4pz1KKpYUYTs4mTslQnnd1gwKe1oktcdVJYCkLZ113Bj0qWuBUw4+ vkb6XG9Ec8hdYY15/E2hTiVOHvZQxRu8RveX5j3tmtQHrQSPUNWlFsVtZxrsyJ+KCjHg u+8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hLAtt6BF; 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 l16si6187548edv.432.2018.11.16.06.05.05; Fri, 16 Nov 2018 06:05:05 -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=hLAtt6BF; 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 0E142C22322; Fri, 16 Nov 2018 14:03:51 +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 5A23EC224FF; Fri, 16 Nov 2018 14:02:10 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EFC3DC2250F; Fri, 16 Nov 2018 14:01:27 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by lists.denx.de (Postfix) with ESMTPS id 8BE88C22322 for ; Fri, 16 Nov 2018 14:00:55 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id u5-v6so19712800wrn.9 for ; Fri, 16 Nov 2018 06:00:55 -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=GXDNe0FEgdZbWpZOnX2KzhNVVKKmxLBGP7IuIFJqUf8=; b=hLAtt6BFzHhAVYuWEF2KoGpP2b0xJtzjHmKVI0H2QP2TZBsdO+h6Ys4PYx3DL3OuR9 CX4JYEhJNw/Uj/og327dp/8YJXR3Bn2nxpPCNifUoo7wVO/mbQD1FsQ9be+28Zzhvphg x6g1PEw85w/BsmV582AzPrPIaClKt7aCATp/E= 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=GXDNe0FEgdZbWpZOnX2KzhNVVKKmxLBGP7IuIFJqUf8=; b=b1Hs9vBFeJebKAmMMaRJjZTccbx2FbP5v7onaVm0QyXaUwoilqEZ9tfQK9RGY43FIV 70guxHJ/SfBJJkdOCsFzs6C3yLe0O3zAZZjo5a2uZrYqMU6kQyMILI4ixZ0qGoTK75Ay FLtFUnmZrx9Rho+WU8Iry9wJoFpnA9Zn9+si7LlQynWho+8x74Vo+0l65zzWLjJE2/00 uef4FsBK4yR9pZ6YEGKwn+1u14KsoMBqOGp0KBJahRNTtJCf97lKEG5fCwEhyBKw9u+b lgD31dZR/jPtOFf8ipJ20uVTVdSJ5blMUdUDBYohjHOnDYnNmRj8/78ezG/So91KOAXs 3OKw== X-Gm-Message-State: AGRZ1gLeKZNF5fghLjQ50zJ7Qp4basp5tg/L/maCopXcE74hVMxTIvzZ DH3J4q9IxZh5yTSIhZue686xsw== X-Received: by 2002:adf:8919:: with SMTP id s25-v6mr9428807wrs.44.1542376854921; Fri, 16 Nov 2018 06:00:54 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Nov 2018 06:00:54 -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:36 +0100 Message-Id: <20181116140039.11628-2-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 Subject: [U-Boot] [PATCH v4 1/4] dm: Add Hardware Spinlock class 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" From: Benjamin Gaignard This is uclass for Hardware Spinlocks. It implements two mandatory operations: lock and unlock and one optional relax operation. Signed-off-by: Benjamin Gaignard Reviewed-by: Simon Glass Reviewed-by: Patrice Chotard --- version 4: - make timeout loop more robust arch/sandbox/dts/test.dts | 4 + arch/sandbox/include/asm/state.h | 1 + configs/sandbox_defconfig | 2 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/hwspinlock/Kconfig | 16 ++++ drivers/hwspinlock/Makefile | 6 ++ drivers/hwspinlock/hwspinlock-uclass.c | 144 ++++++++++++++++++++++++++++++++ drivers/hwspinlock/sandbox_hwspinlock.c | 56 +++++++++++++ include/dm/uclass-id.h | 1 + include/hwspinlock.h | 140 +++++++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/hwspinlock.c | 40 +++++++++ 13 files changed, 414 insertions(+) create mode 100644 drivers/hwspinlock/Kconfig create mode 100644 drivers/hwspinlock/Makefile create mode 100644 drivers/hwspinlock/hwspinlock-uclass.c create mode 100644 drivers/hwspinlock/sandbox_hwspinlock.c create mode 100644 include/hwspinlock.h create mode 100644 test/dm/hwspinlock.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 57e0dd7663..50cd2f89e0 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -712,6 +712,10 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + hwspinlock@0 { + compatible = "sandbox,hwspinlock"; + }; }; #include "sandbox_pmic.dtsi" diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index dcb6d5f568..a5d7c6aaf3 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -99,6 +99,7 @@ struct sandbox_state { ulong next_tag; /* Next address tag to allocate */ struct list_head mapmem_head; /* struct sandbox_mapmem_entry */ + bool hwspinlock; /* Hardware Spinlock status */ }; /* Minimum space we guarantee in the state FDT when calling read/write*/ diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 2ce336fc81..36b67be2df 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -97,6 +97,8 @@ CONFIG_BOARD=y CONFIG_BOARD_SANDBOX=y CONFIG_PM8916_GPIO=y CONFIG_SANDBOX_GPIO=y +CONFIG_DM_HWSPINLOCK=y +CONFIG_HWSPINLOCK_SANDBOX=y CONFIG_DM_I2C_COMPAT=y CONFIG_I2C_CROS_EC_TUNNEL=y CONFIG_I2C_CROS_EC_LDO=y diff --git a/drivers/Kconfig b/drivers/Kconfig index 927a2b87f6..7e6ca7cd3e 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -40,6 +40,8 @@ source "drivers/fpga/Kconfig" source "drivers/gpio/Kconfig" +source "drivers/hwspinlock/Kconfig" + source "drivers/i2c/Kconfig" source "drivers/input/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index fb38b67541..0ef56fb416 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -111,4 +111,5 @@ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_W1_EEPROM) += w1-eeprom/ obj-$(CONFIG_MACH_PIC32) += ddr/microchip/ +obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock/ endif diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig new file mode 100644 index 0000000000..de367fd2a9 --- /dev/null +++ b/drivers/hwspinlock/Kconfig @@ -0,0 +1,16 @@ +menu "Hardware Spinlock Support" + +config DM_HWSPINLOCK + bool "Enable U-Boot hardware spinlock support" + help + This option enables U-Boot hardware spinlock support + +config HWSPINLOCK_SANDBOX + bool "Enable Hardware Spinlock support for Sandbox" + depends on SANDBOX && DM_HWSPINLOCK + help + Enable hardware spinlock support in Sandbox. This is a dummy device that + can be probed and support all the methods of HWSPINLOCK, but does not + really do anything. + +endmenu diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile new file mode 100644 index 0000000000..2704d6814f --- /dev/null +++ b/drivers/hwspinlock/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +# +# Copyright (C) 2018, STMicroelectronics - All Rights Reserved + +obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock-uclass.o +obj-$(CONFIG_HWSPINLOCK_SANDBOX) += sandbox_hwspinlock.o diff --git a/drivers/hwspinlock/hwspinlock-uclass.c b/drivers/hwspinlock/hwspinlock-uclass.c new file mode 100644 index 0000000000..195f079707 --- /dev/null +++ b/drivers/hwspinlock/hwspinlock-uclass.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include + +static inline const struct hwspinlock_ops * +hwspinlock_dev_ops(struct udevice *dev) +{ + return (const struct hwspinlock_ops *)dev->driver->ops; +} + +static int hwspinlock_of_xlate_default(struct hwspinlock *hws, + struct ofnode_phandle_args *args) +{ + if (args->args_count > 1) { + debug("Invaild args_count: %d\n", args->args_count); + return -EINVAL; + } + + if (args->args_count) + hws->id = args->args[0]; + else + hws->id = 0; + + return 0; +} + +int hwspinlock_get_by_index(struct udevice *dev, int index, + struct hwspinlock *hws) +{ + int ret; + struct ofnode_phandle_args args; + struct udevice *dev_hws; + const struct hwspinlock_ops *ops; + + assert(hws); + hws->dev = NULL; + + ret = dev_read_phandle_with_args(dev, "hwlocks", "#hwlock-cells", 1, + index, &args); + if (ret) { + dev_dbg(dev, "%s: dev_read_phandle_with_args: err=%d\n", + __func__, ret); + return ret; + } + + ret = uclass_get_device_by_ofnode(UCLASS_HWSPINLOCK, + args.node, &dev_hws); + if (ret) { + dev_dbg(dev, + "%s: uclass_get_device_by_of_offset failed: err=%d\n", + __func__, ret); + return ret; + } + + hws->dev = dev_hws; + + ops = hwspinlock_dev_ops(dev_hws); + + if (ops->of_xlate) + ret = ops->of_xlate(hws, &args); + else + ret = hwspinlock_of_xlate_default(hws, &args); + if (ret) + dev_dbg(dev, "of_xlate() failed: %d\n", ret); + + return ret; +} + +int hwspinlock_lock_timeout(struct hwspinlock *hws, unsigned int timeout) +{ + const struct hwspinlock_ops *ops; + ulong start; + int ret; + + assert(hws); + + if (!hws->dev) + return -EINVAL; + + ops = hwspinlock_dev_ops(hws->dev); + if (!ops->lock) + return -ENOSYS; + + start = get_timer(0); + do { + ret = ops->lock(hws->dev, hws->id); + if (!ret) + return ret; + + if (ops->relax) + ops->relax(hws->dev); + } while (get_timer(start) < timeout); + + return -ETIMEDOUT; +} + +int hwspinlock_unlock(struct hwspinlock *hws) +{ + const struct hwspinlock_ops *ops; + + assert(hws); + + if (!hws->dev) + return -EINVAL; + + ops = hwspinlock_dev_ops(hws->dev); + if (!ops->unlock) + return -ENOSYS; + + return ops->unlock(hws->dev, hws->id); +} + +static int hwspinlock_post_bind(struct udevice *dev) +{ +#if defined(CONFIG_NEEDS_MANUAL_RELOC) + struct hwspinlock_ops *ops = device_get_ops(dev); + static int reloc_done; + + if (!reloc_done) { + if (ops->lock) + ops->lock += gd->reloc_off; + if (ops->unlock) + ops->unlock += gd->reloc_off; + if (ops->relax) + ops->relax += gd->reloc_off; + + reloc_done++; + } +#endif + return 0; +} + +UCLASS_DRIVER(hwspinlock) = { + .id = UCLASS_HWSPINLOCK, + .name = "hwspinlock", + .post_bind = hwspinlock_post_bind, +}; diff --git a/drivers/hwspinlock/sandbox_hwspinlock.c b/drivers/hwspinlock/sandbox_hwspinlock.c new file mode 100644 index 0000000000..be920f5f99 --- /dev/null +++ b/drivers/hwspinlock/sandbox_hwspinlock.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include + +static int sandbox_lock(struct udevice *dev, int index) +{ + struct sandbox_state *state = state_get_current(); + + if (index != 0) + return -1; + + if (state->hwspinlock) + return -1; + + state->hwspinlock = true; + + return 0; +} + +static int sandbox_unlock(struct udevice *dev, int index) +{ + struct sandbox_state *state = state_get_current(); + + if (index != 0) + return -1; + + if (!state->hwspinlock) + return -1; + + state->hwspinlock = false; + + return 0; +} + +static const struct hwspinlock_ops sandbox_hwspinlock_ops = { + .lock = sandbox_lock, + .unlock = sandbox_unlock, +}; + +static const struct udevice_id sandbox_hwspinlock_ids[] = { + { .compatible = "sandbox,hwspinlock" }, + {} +}; + +U_BOOT_DRIVER(hwspinlock_sandbox) = { + .name = "hwspinlock_sandbox", + .id = UCLASS_HWSPINLOCK, + .of_match = sandbox_hwspinlock_ids, + .ops = &sandbox_hwspinlock_ops, +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 269a2c6e72..6193017432 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -40,6 +40,7 @@ enum uclass_id { UCLASS_ETH, /* Ethernet device */ UCLASS_FS_FIRMWARE_LOADER, /* Generic loader */ UCLASS_GPIO, /* Bank of general-purpose I/O pins */ + UCLASS_HWSPINLOCK, /* Hardware semaphores */ UCLASS_FIRMWARE, /* Firmware */ UCLASS_I2C, /* I2C bus */ UCLASS_I2C_EEPROM, /* I2C EEPROM device */ diff --git a/include/hwspinlock.h b/include/hwspinlock.h new file mode 100644 index 0000000000..99389c13c2 --- /dev/null +++ b/include/hwspinlock.h @@ -0,0 +1,140 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#ifndef _HWSPINLOCK_H_ +#define _HWSPINLOCK_H_ + +/** + * Implement a hwspinlock uclass. + * Hardware spinlocks are used to perform hardware protection of + * critical sections and synchronisation between multiprocessors. + */ + +struct udevice; + +/** + * struct hwspinlock - A handle to (allowing control of) a single hardware + * spinlock. + * + * @dev: The device which implements the hardware spinlock. + * @id: The hardware spinlock ID within the provider. + */ +struct hwspinlock { + struct udevice *dev; + unsigned long id; +}; + +#if CONFIG_IS_ENABLED(DM_HWSPINLOCK) + +/** + * hwspinlock_get_by_index - Get a hardware spinlock by integer index + * + * This looks up and request a hardware spinlock. The index is relative to the + * client device; each device is assumed to have n hardware spinlock associated + * with it somehow, and this function finds and requests one of them. + * + * @dev: The client device. + * @index: The index of the hardware spinlock to request, within the + * client's list of hardware spinlock. + * @hws: A pointer to a hardware spinlock struct to initialize. + * @return 0 if OK, or a negative error code. + */ +int hwspinlock_get_by_index(struct udevice *dev, + int index, struct hwspinlock *hws); + +/** + * Lock the hardware spinlock + * + * @hws: A hardware spinlock struct that previously requested by + * hwspinlock_get_by_index + * @timeout: Timeout value in msecs + * @return: 0 if OK, -ETIMEDOUT if timeout, -ve on other errors + */ +int hwspinlock_lock_timeout(struct hwspinlock *hws, unsigned int timeout); + +/** + * Unlock the hardware spinlock + * + * @hws: A hardware spinlock struct that previously requested by + * hwspinlock_get_by_index + * @return: 0 if OK, -ve on error + */ +int hwspinlock_unlock(struct hwspinlock *hws); + +#else + +static inline int hwspinlock_get_by_index(struct udevice *dev, + int index, + struct hwspinlock *hws) +{ + return -ENOSYS; +} + +static inline int hwspinlock_lock_timeout(struct hwspinlock *hws, + int timeout) +{ + return -ENOSYS; +} + +static inline int hwspinlock_unlock(struct hwspinlock *hws) +{ + return -ENOSYS; +} + +#endif /* CONFIG_DM_HWSPINLOCK */ + +struct ofnode_phandle_args; + +/** + * struct hwspinlock_ops - Driver model hwspinlock operations + * + * The uclass interface is implemented by all hwspinlock devices which use + * driver model. + */ +struct hwspinlock_ops { + /** + * of_xlate - Translate a client's device-tree (OF) hardware specifier. + * + * The hardware core calls this function as the first step in + * implementing a client's hwspinlock_get_by_*() call. + * + * @hws: The hardware spinlock struct to hold the translation + * result. + * @args: The hardware spinlock specifier values from device tree. + * @return 0 if OK, or a negative error code. + */ + int (*of_xlate)(struct hwspinlock *hws, + struct ofnode_phandle_args *args); + + /** + * Lock the hardware spinlock + * + * @dev: hwspinlock Device + * @index: index of the lock to be used + * @return 0 if OK, -ve on error + */ + int (*lock)(struct udevice *dev, int index); + + /** + * Unlock the hardware spinlock + * + * @dev: hwspinlock Device + * @index: index of the lock to be unlocked + * @return 0 if OK, -ve on error + */ + int (*unlock)(struct udevice *dev, int index); + + /** + * Relax - optional + * Platform-specific relax method, called by hwspinlock core + * while spinning on a lock, between two successive call to + * lock + * + * @dev: hwspinlock Device + */ + void (*relax)(struct udevice *dev); +}; + +#endif /* _HWSPINLOCK_H_ */ diff --git a/test/dm/Makefile b/test/dm/Makefile index b490cf2862..9b3b0bf202 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_CLK) += clk.o obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o +obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o diff --git a/test/dm/hwspinlock.c b/test/dm/hwspinlock.c new file mode 100644 index 0000000000..09ec38b4f3 --- /dev/null +++ b/test/dm/hwspinlock.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Test that hwspinlock driver functions are called */ +static int dm_test_hwspinlock_base(struct unit_test_state *uts) +{ + struct sandbox_state *state = state_get_current(); + struct hwspinlock hws; + + ut_assertok(uclass_get_device(UCLASS_HWSPINLOCK, 0, &hws.dev)); + ut_assertnonnull(hws.dev); + ut_asserteq(false, state->hwspinlock); + + hws.id = 0; + ut_assertok(hwspinlock_lock_timeout(&hws, 1)); + ut_asserteq(true, state->hwspinlock); + + ut_assertok(hwspinlock_unlock(&hws)); + ut_asserteq(false, state->hwspinlock); + + ut_assertok(hwspinlock_lock_timeout(&hws, 1)); + ut_assertok(!hwspinlock_lock_timeout(&hws, 1)); + + ut_assertok(hwspinlock_unlock(&hws)); + ut_assertok(!hwspinlock_unlock(&hws)); + + return 0; +} + +DM_TEST(dm_test_hwspinlock_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Fri Nov 16 14:00:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 151337 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp465215ljp; Fri, 16 Nov 2018 06:03:24 -0800 (PST) X-Google-Smtp-Source: AJdET5d9cy4phADZ3Gd5g08yBhjBcIfFrSvDrkqH8jzZCG6m1Q37NffoanuvKZ5VnR5U71JZhvhD X-Received: by 2002:a50:8acd:: with SMTP id k13-v6mr9918696edk.189.1542377004184; Fri, 16 Nov 2018 06:03:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542377004; cv=none; d=google.com; s=arc-20160816; b=bdBLu7EYM4u3qqRfRvO7rR+3fmFhh4+ROzX+tlMO0RdBCo8gVRYwjNsoCCTAhnDKdb cKSYQe0IToCWwXVtReKH6gQDCaO5XPl1+Od17weIkrWn89JJyyP1+2lwYgbzqhEclxYY BM7EQnTj7EjFKm5xFnLtaaBSB81p5WHoz5OKBle3fIj1W+h6gdW5f5N+cluHFNeMDXjo pMCgS3/eSpNULUHdS0xx0jbNprPv1oMXPL8Qf7GOdP+9hMb25V1lRNkmbDMYcwX3G7Gl tVeG5IRnpYXIsYi6moqUAJ94fOwk6Ris/DAukq9ZpU6VhbpHW+AjN+HuGJVLQMg95GAR Nnow== 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=qBsbF35KyiQ6m+3yOOkuGVskKc/rTXAOXJGzHhcs/fg=; b=cmTt8y74UkS7nYhxvM3E1Rq8xJtmJchCLiFJbHkIuQJEggmZdVS+jm9K1U0dh29p1F mqARbGhSi4qKX0/trhv4HFaybBXA9sM6jU1VbvzarinBlbdZhOFBqV4EZfCg/Ftv41Am vxFaTi3HhlQU/ipUtx+j/7eBnRqgaKikgOEf+X8mlAXEPX9+pyC/lyD3EmBYzOfZDSP6 KezV6J3IgQE4Zzeo0kLEOVRWpfFOYqauBQyWsmVTChUEBWI7bphkfcR/WEOG+u6dwb+4 jKgL5EnrE9zE8+0TDf91pXleW+BWKwZaTue++fLFsbDDAByl63ilYZ4qEameYhECZOR2 OJow== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="eg/6vBc/"; 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 i19si3938194edr.271.2018.11.16.06.03.23; Fri, 16 Nov 2018 06:03:24 -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="eg/6vBc/"; 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 873BBC224EC; Fri, 16 Nov 2018 14:03:13 +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 3493FC224E8; Fri, 16 Nov 2018 14:01:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C3A16C22500; Fri, 16 Nov 2018 14:01:28 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by lists.denx.de (Postfix) with ESMTPS id A1E2CC224E8 for ; Fri, 16 Nov 2018 14:00:57 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id r63-v6so22293311wma.4 for ; Fri, 16 Nov 2018 06:00:57 -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=oLp9ZZs9aCvjbUr7WBcd79aLnWxjPpZLbs2+aMbjkOE=; b=eg/6vBc/2MGLx8eObUYpSm/WZ7ImSJOVKujNWFPwRoPJzG7qiR3m9rclXLN6WeaX/i TlTKUcEneiOO/aNtmVmfpa5rLyIZ2yF7fwaxy3DP++ori3DjAUpb8aHRdqKgoxR3Bzs0 iNU8WcNrWV8lEvq4kHmkt3Nu7UF9Ir/7cPG7c= 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=oLp9ZZs9aCvjbUr7WBcd79aLnWxjPpZLbs2+aMbjkOE=; b=ASp1grrz9jMa3PjBLRNx1nUVBUp+L4eBf+s4XDHCqUnR17fX80rekohLa9JWW1Kuya qycqoNrz5t/yBdFl8h/Dtz8JzNDU8wULRFQR37gq7Euqnr5FT0nbKlCcCs70Kt2dwMFc veC+bTrfjQGgjjtS3wI5fmS4JwR2Cy/5DNhlnVzlTvVex5SNeKG+82mDcZgDI9h/6dBm 4/yyGtVt9ceSoTI1l2EZd5BnrexdWwXMyKEm6xF7TOXkOW4EkXd4zxPtATRBWgre/XJD tq2t+1zja7McwbZ+SnQLpQ38cs6X5V2syc1Uai34ZnXWVOpe/Zp7zX4AxJWI227Y29vt l1ug== X-Gm-Message-State: AGRZ1gKqoamgTDrMF8+NhZgg+vhqAjZV83Ts1VnIcPqi+SLMEo/18Z4n 8H2/KuT2LCe3pArGlQTYaj7MXA== X-Received: by 2002:a1c:248b:: with SMTP id k133-v6mr8423089wmk.148.1542376857198; Fri, 16 Nov 2018 06:00:57 -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.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Nov 2018 06:00:56 -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:37 +0100 Message-Id: <20181116140039.11628-3-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 Subject: [U-Boot] [PATCH v4 2/4] clk: stm32: add hardware spinlock clock 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" From: Benjamin Gaignard Add hardware spinlock in the list of the clocks. Signed-off-by: Benjamin Gaignard Reviewed-by: Simon Glass Reviewed-by: Patrice Chotard --- drivers/clk/clk_stm32mp1.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/clk/clk_stm32mp1.c b/drivers/clk/clk_stm32mp1.c index 6a8c7b754f..b7c5d34fe0 100644 --- a/drivers/clk/clk_stm32mp1.c +++ b/drivers/clk/clk_stm32mp1.c @@ -104,6 +104,7 @@ #define RCC_MP_APB2ENSETR 0XA08 #define RCC_MP_APB3ENSETR 0xA10 #define RCC_MP_AHB2ENSETR 0xA18 +#define RCC_MP_AHB3ENSETR 0xA20 #define RCC_MP_AHB4ENSETR 0xA28 /* used for most of SELR register */ @@ -534,6 +535,8 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = { STM32MP1_CLK_SET_CLR(RCC_MP_AHB2ENSETR, 8, USBO_K, _USBO_SEL), STM32MP1_CLK_SET_CLR(RCC_MP_AHB2ENSETR, 16, SDMMC3_K, _SDMMC3_SEL), + STM32MP1_CLK_SET_CLR(RCC_MP_AHB3ENSETR, 11, HSEM, _UNKNOWN_SEL), + STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 0, GPIOA, _UNKNOWN_SEL), STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 1, GPIOB, _UNKNOWN_SEL), STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 2, GPIOC, _UNKNOWN_SEL), 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), +}; From patchwork Fri Nov 16 14:00:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 151341 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp469152ljp; Fri, 16 Nov 2018 06:06:20 -0800 (PST) X-Google-Smtp-Source: AJdET5eoVAkxATFS6gjz+EcKDjfzB54XS5SI1PJ3029rNsMXeonVHGiZmf5DLN7vkoS9Lgx0SCEl X-Received: by 2002:a50:940b:: with SMTP id p11mr9402647eda.135.1542377180858; Fri, 16 Nov 2018 06:06:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542377180; cv=none; d=google.com; s=arc-20160816; b=vQtIDmUwrI96T11my9BIsk5hAF4kjJSu8qLW2xUqBGAUcYBrbBRlQ2f/JwlQNZ2TCi Z/vPWFO1pJ4Nc+yaEMtQNLnebD/4U+xDpJlXqhHsLkXsgJK3AZQC6XZ+eUF4RbaRiaVz aEDKpaLjsKDUlNxtJ5/SMhevza64WzYt2MLdVZarBn5SsZPGvTR1vfkAfcc44Cj1PqeL czDIRYfci8oIg3Q7R6t5zoqkm3koj61Lyw8iXJAm+q6Va0Q/MU1ooffDg2TV7AmWjwY/ zQ+nzw1QN0fUdvvZQbiq8jLviay33lfMPeeY9VWDMdTRcCD8reAVMR3S4zsXk2L4UvFt 2eaQ== 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=lOMoY3gq5YPKZtwMLOqXgdeJ3l++0tJd8LOg1dN2PVg=; b=od9l3GaMXH3+t8Xu6rbDyvPJe5BlDPLTpYz+eJJ++wz36zZ8P4qaVJGQdayHwDFMdS pGmZU4c6poV5361CSRcgSbm4SoEuK6mq8OoP7gxtD1IsWwwFOLppHy9bEbwhIUd+ixtP OmBz5spGfIqI6w6tFQHMM788Zho2mvyr1OB+ozdth5l2ul8InYdDH8V4JeRCWzZjHpy+ 3zn3N4OxwQNwAlMgQVBYZrOY4qDIAjgW9EWlF0DXtX7KrRUCnSn/rk5ZYfnkT9Rs4c5u Y8E2Msx1L1nOWMbQhpMmKUs5RulqkrkV4115jg15Lx7KIGIP6HzWm05ijr8NI4Ybe6U1 MNxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QRlCpQWB; 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 c1si1284184edy.52.2018.11.16.06.06.20; Fri, 16 Nov 2018 06:06:20 -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=QRlCpQWB; 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 66F31C224F5; Fri, 16 Nov 2018 14:04:26 +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 D57CEC224F7; Fri, 16 Nov 2018 14:02:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3FD50C2231E; Fri, 16 Nov 2018 14:01:33 +0000 (UTC) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by lists.denx.de (Postfix) with ESMTPS id 21AE5C22512 for ; Fri, 16 Nov 2018 14:01:04 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id f10-v6so22140711wme.3 for ; Fri, 16 Nov 2018 06:01:04 -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=ejct8UX6bJFOwwcKpqlnsgVAZ2Zlsuz1xmZoHn47dBQ=; b=QRlCpQWBoQN76NJ5JbbWOtu2l2wf/5oKUHlUS3inu+9RInTd4Ig6rGfL+fxYvuoPL5 KEDHAA9GKxY6GLOmxChv2AfCh0x/JEAbYH+WR/k7c6LL3F+1Vaz5FrnJsi1bDHUTkqe0 zK27EL9hrOTPPOw6sA0b6hNqHyrBnzZZBEn1I= 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=ejct8UX6bJFOwwcKpqlnsgVAZ2Zlsuz1xmZoHn47dBQ=; b=d07CqGlmZyzVAlrP08CrqY9RJa8JoBOvblym0bZ2gTkCvHm6TJP15sk/8uret1UbQZ m2/NmpXa5p1gLc9swwQzTJanTDzoG2uZXv2gMguaTSTdKkj69RO16Vg7dFsOulGE3H4p 07aEsbxT8VUIvxZC6CpFCP8tFNA+EeWga8pMuo1yrrM1sJQrLh2MryQL5DwdLu0XZDuV X2C+yuthsrQVeuaEr6NeS+y7nWn5xzxN5hFNXC4S3SbETFOdroPGd2rygpNAUXrhGhEy JY68ZnfZ7Abc/mN4zeAsuws6LGk/3kAVppZaphi6X4CxD48UQzYnIwarx04131Hbp0BY 2wEA== X-Gm-Message-State: AGRZ1gLaVqUtTRAo4zoMauJ65pGLI6ISwrCflu8an3ChHpF7cBT6dZN4 mpxjlC2Hp94dBUKofwxh02DUKA== X-Received: by 2002:a1c:248b:: with SMTP id k133-v6mr8423407wmk.148.1542376863785; Fri, 16 Nov 2018 06:01:03 -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.01.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Nov 2018 06:01:03 -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:39 +0100 Message-Id: <20181116140039.11628-5-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 Subject: [U-Boot] [PATCH v4 4/4] pinctrl: stm32: make pinctrl use hwspinlock 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" From: Benjamin Gaignard Protect configuration registers with a hardware spinlock. If a hwspinlock is defined in the device-tree node used it to be sure that none of the others processors on the SoC could change the configuration at the same time. Signed-off-by: Benjamin Gaignard Reviewed-by: Simon Glass Reviewed-by: Patrice Chotard --- arch/arm/dts/stm32mp157c-ed1.dts | 4 ++++ drivers/pinctrl/pinctrl_stm32.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/arm/dts/stm32mp157c-ed1.dts b/arch/arm/dts/stm32mp157c-ed1.dts index fc277dd7d2..7a9b742d36 100644 --- a/arch/arm/dts/stm32mp157c-ed1.dts +++ b/arch/arm/dts/stm32mp157c-ed1.dts @@ -369,6 +369,10 @@ status = "okay"; }; +&pinctrl { + hwlocks = <&hwspinlock 0>; +}; + &usbphyc_port0 { phy-supply = <&vdd_usb>; vdda1v1-supply = <®11>; diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 31285cdd57..402b7803fc 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -19,12 +20,20 @@ static int stm32_gpio_config(struct gpio_desc *desc, { struct stm32_gpio_priv *priv = dev_get_priv(desc->dev); struct stm32_gpio_regs *regs = priv->regs; + struct hwspinlock *hws = dev_get_priv(dev_get_parent(desc->dev)); u32 index; + int ret; if (!ctl || ctl->af > 15 || ctl->mode > 3 || ctl->otype > 1 || ctl->pupd > 2 || ctl->speed > 3) return -EINVAL; + ret = hwspinlock_lock_timeout(hws, 1); + if (ret == -ETIME) { + dev_err(desc->dev, "HWSpinlock timeout\n"); + return ret; + } + index = (desc->offset & 0x07) * 4; clrsetbits_le32(®s->afr[desc->offset >> 3], AFR_MASK << index, ctl->af << index); @@ -39,6 +48,8 @@ static int stm32_gpio_config(struct gpio_desc *desc, index = desc->offset; clrsetbits_le32(®s->otyper, OTYPE_MSK << index, ctl->otype << index); + hwspinlock_unlock(hws); + return 0; } @@ -176,6 +187,20 @@ static int stm32_pinctrl_set_state_simple(struct udevice *dev, } #endif /* PINCTRL_FULL */ +static int stm32_pinctrl_probe(struct udevice *dev) +{ + struct hwspinlock *hws = dev_get_priv(dev); + int err; + + /* hwspinlock property is optional, just log the error */ + err = hwspinlock_get_by_index(dev, 0, hws); + if (err) + debug("%s: hwspinlock_get_by_index may have failed (%d)\n", + __func__, err); + + return 0; +} + static struct pinctrl_ops stm32_pinctrl_ops = { #if CONFIG_IS_ENABLED(PINCTRL_FULL) .set_state = stm32_pinctrl_set_state, @@ -200,4 +225,6 @@ U_BOOT_DRIVER(pinctrl_stm32) = { .of_match = stm32_pinctrl_ids, .ops = &stm32_pinctrl_ops, .bind = dm_scan_fdt_dev, + .probe = stm32_pinctrl_probe, + .priv_auto_alloc_size = sizeof(struct hwspinlock), };