From patchwork Tue Nov 13 08:51:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 150971 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4331833ljp; Tue, 13 Nov 2018 04:19:48 -0800 (PST) X-Google-Smtp-Source: AJdET5eeB7eceGb7EYVY3YMrwDTpq9jLJYRJUAJ/Eu/XUozHh4OHZAlz7HbM9zwhzMuhg8sx0hsP X-Received: by 2002:aa7:d9d1:: with SMTP id v17-v6mr15645692eds.25.1542111588822; Tue, 13 Nov 2018 04:19:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542111588; cv=none; d=google.com; s=arc-20160816; b=Z7XEweLTOF10GK26FYdmmcvnMgVZ3+eIl8xrAayImLabBAHIRItbOseYs7PEWAMyMG DSBgnLLlAFkzgytXqV3nhzNrLJ2zywuqhTmayloM5tDtGEb6XVvjKKwmlGEMkxjrrXkE /z5NmqZkgaRDT0Z6zrVy1pfi9BajQVngfwv9WtXpaTG2NqVP5wiPT3WiyOq7L3H1lPuC JhJe7rzwIuyS9vS3SPcjueHZKuA5sM1hEypL3YwxgUPGGBAiiwztIC8OXSa5P8sWUNVY BoxwIyaVCbExJmRnC0RDCSeEUNFyRM3uV3/LHxYasU2b1roVxB9GLA2hXNZpnKqDsL00 z7hA== 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=5TX6k4zbxI1y/Ij28haJddgZU+9Csl0O1FkG+EAfOgA=; b=AnSBPDzNAcEdAVFcQiWw5tjnSQ7EpsSSHH7je3X4YZUncYtis+Y0GNHJ3FRj8FMzdT Ka3KdhDIbXLSkXvO9+nwzJeofRwvcRaVxhAGwXMBijmQY4ZOkmT7kBiifbGvkDyOoPR6 MKhkRSLWCWu6RthQVHvhve5s7s0Zt96KrMgPoVzAEW60dPNY48WEiPUI8x/eei3qKPPB KFhElfeGhCNOsb7avwegVk4/OIRQvae6P7vFk0uaE8GFYEQg7FlM5UyP8/tgEKDVvXjf dig+uXlmqwMnrE7EtjvC0eutbjXoWz34l3HV0JnCBPq3A1AS1GyxzkPSKbRlL62ooHMs 13mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ULKyAqup; 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 l7si2548714eda.48.2018.11.13.04.19.48; Tue, 13 Nov 2018 04:19:48 -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=ULKyAqup; 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 694FCC22501; Tue, 13 Nov 2018 12:17:12 +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 6FCC1C2250B; Tue, 13 Nov 2018 12:15:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6DCD7C21EC8; Tue, 13 Nov 2018 08:52:02 +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 15C15C21DCA for ; Tue, 13 Nov 2018 08:52:02 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id r63-v6so11058838wma.4 for ; Tue, 13 Nov 2018 00:52:02 -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=pYXZmvYoND7akAV7DR5NStHgEy/NVVhkM/yb6GpUaNg=; b=ULKyAqup/Nevcu+apuWF6zHDKyRzWwT67E2SZGW66moPucExJARRYJ3RG1UcGRNrHM xM9rXOM/wlzspt+qUb8H9SfmBrfO/g0zC/zxBZ55r5wORq+ORIAhwazonDRdsuPzZ3ny wRB2Vx5XVxjHk8DPhNJj3rRyRKRRQ0GLzzU9s= 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=pYXZmvYoND7akAV7DR5NStHgEy/NVVhkM/yb6GpUaNg=; b=AE1X92A3f4XIWg3BxFB3GQA/zB9vAeDBu1iqmxguTtUqpFKOvpv4Pm3DDHJfsKFgQN c4UPlSn3Ls38mCVcfKjGdcvpSbpIGh3c3jb/6h6hlGGF+1llSIF6aGVo7Qpo9qlMGwZJ ywQzYPQ+FJswAJ7BFSPfWWnPfBvn3Qyh4qUQJSZv06pRgP0wqnrZcxNoJfF9GJjzwS6E mOiVq+RbMO5LX2EEvxhDINnahi4yeiKW1TiXZ1UtoxLBHr5K6zKS+CFo9oBaKCAr4+np 6SQKq20RZDWd/HMeAXSUv3fw0P5jgQEzdpiVxjLmABAMB/mskY4MUcJYR6pFESETCN+9 LZKg== X-Gm-Message-State: AGRZ1gKCk/xZ8iMEKTEuwYY6JoffYF6dF0rK0BTesq3Mqd//fslJ+SRF vNhaM/puo1IBHj+BjrVB9xrNTQ== X-Received: by 2002:a1c:f313:: with SMTP id q19-v6mr2328994wmq.87.1542099121409; Tue, 13 Nov 2018 00:52:01 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1047:8145:8cab:bca7:b2f2:d2bb]) by smtp.gmail.com with ESMTPSA id d18-v6sm4235544wre.25.2018.11.13.00.51.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Nov 2018 00:52: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: Tue, 13 Nov 2018 09:51:48 +0100 Message-Id: <20181113085151.32368-2-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181113085151.32368-1-benjamin.gaignard@st.com> References: <20181113085151.32368-1-benjamin.gaignard@st.com> X-Mailman-Approved-At: Tue, 13 Nov 2018 12:15:27 +0000 Cc: uboot-stm32@st-md-mailman.stormreply.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 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 --- 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 | 145 ++++++++++++++++++++++++++++++++ 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, 415 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..1fed24228c --- /dev/null +++ b/drivers/hwspinlock/hwspinlock-uclass.c @@ -0,0 +1,145 @@ +// 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 || !ops->lock) + return -EINVAL; + + for (start = get_timer(0); get_timer(start) < timeout;) { + ret = ops->lock(hws->dev, hws->id); + if (!ret) + return ret; + + if (ops->relax) + ops->relax(hws->dev); + } + + return -ETIME; +} + +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 || !ops->unlock) + return -EINVAL; + + 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..4671c8fce5 --- /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, -ETIME 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 Tue Nov 13 08:51:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 150969 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4331360ljp; Tue, 13 Nov 2018 04:19:20 -0800 (PST) X-Google-Smtp-Source: AJdET5fAd4/l1wpnejBw7ouaMw/O/ARLmFFFwHKJdGcwvQoqvqr+H8ZdUlZmm40ywsibmHz+jHKU X-Received: by 2002:a50:afa3:: with SMTP id h32-v6mr15947958edd.254.1542111560487; Tue, 13 Nov 2018 04:19:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542111560; cv=none; d=google.com; s=arc-20160816; b=dEhL2373XkgTiZeG1w9bjp7N0OMiQ5crrI7sSBBupK6cc0mMkXIc39U6yqOz5SWKg+ 0WywTSNP5h7HR76swQExW0hdjI3YoelkuBBJxEKz40sSxihNmxwXQSkCEb2diSmOyxhg Ddqyx6Lr6/k9xNHlDCxghJJ/hTi8MWuVthBw4QtynMnW00xM5slRFHJhIXmdiqHAWHl0 pE15BjCL2YOonL8WU6f3E4bxJ5vP2qoUeSiZYJgSzhpSqBRhc2trmjEd5ZxJBGQDXdfH zuEIhdSyg9i/1I8zu9JoKYZPUHkuzZCjA/4Pp3FwCh6K1/+Hv5JeQ+y2ruTh2+hrV77g gFIg== 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=p+dZUv5XijZ1MIXuQb0X8mTeOlnue36UM8+tlD5fybM=; b=ZiMdIennHCGIVASeSj24S1TuyzLgG+ebHJpNIj87u/Uh/a/POYCpdKoMbb5CCzBwvq onVA9S87Y5IlcHe/79NOTYkaCURKnPXVGUOB0skUfeVnvYoybgZJZ8VLZyW1KnFGW5ip f9wriAhtHk9vOc15CXUqaHm/HOClP4wsuI/8ogCaS7ZW1+UH2xMSq2lF609Ep6hLhLHS xGPw8Nm6fqhnV1fW3O0OM4SFo85reGwl7Sy1OCDi91frDU4F3Oe+4pUuqmb8TxrRXp/T kzUKLr5DmZTY0wU5Nua5lKfkEoYh3Z2Bh3O5r6wmVmyL44jQo3GOu1fvjxJRwQpMq/5B h++Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=O57vSiu4; 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 f19-v6si3298098edd.409.2018.11.13.04.19.20; Tue, 13 Nov 2018 04:19: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=O57vSiu4; 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 1D621C224DE; Tue, 13 Nov 2018 12:17:42 +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 72A8EC224F6; Tue, 13 Nov 2018 12:15:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B78C6C21EC8; Tue, 13 Nov 2018 08:52:03 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by lists.denx.de (Postfix) with ESMTPS id 61894C21EC8 for ; Tue, 13 Nov 2018 08:52:03 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id f2-v6so10543466wme.3 for ; Tue, 13 Nov 2018 00:52:03 -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=/CmlmCmViZQAz4cyHIO2o3IkVmiv6Tq2TnwqaDNM8mQ=; b=O57vSiu4LATMutYg1Mw3flF97GjJAPx91AnVjQFrEezdAF4RTDLDPv1hhP4qcEvvqs pMQP1Z2pPRYAd1nACbhAKGqRzUKyx1tHiyzG+meCssh3fSYe0qJorWXYUPLPmFA+zqh6 2ISwswNUwoNpD7XyO7x9DMBy8mx8OoWRb98Ro= 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=/CmlmCmViZQAz4cyHIO2o3IkVmiv6Tq2TnwqaDNM8mQ=; b=Ox06p1hwBRgma2vV8yUf+wN6QXv6+AG9bgNn0v6OZejKBj8LaZPbpR0EtElDvBoYB9 neSl3sMODKVht+qX7XYy/zGBZU2j/KHcKFxdbfcrs/s5uJUP2H+rd5iS6tDvYu0XKeF4 Eyx61ZFAm9skHI4futQxw0Fcj9xVRiCuHnjjDvOMl/gTEkuYVvX4X/Cv9dZcJBM30ek5 667b7Dt4Y4km0+HiusaEITA0v3CnngcBjGEVMbZq0s8nmHmlOgSfc4dUm8nqj/NWesRh gI2+KpR2MAfu1f2lvve5eATf2PreATL++lT/G3NHFWLlxK8v8Mo5ImZHWm1D7PCnb6HD qDmA== X-Gm-Message-State: AGRZ1gKlVg8hGp7sChbGEIka/m1XDIT8RG5poqX7U0sZQRdN8YxRRFzj fPxhVx6P4teWUki8118oMHjCyQ== X-Received: by 2002:a1c:9a0d:: with SMTP id c13-v6mr2302660wme.65.1542099123032; Tue, 13 Nov 2018 00:52:03 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1047:8145:8cab:bca7:b2f2:d2bb]) by smtp.gmail.com with ESMTPSA id d18-v6sm4235544wre.25.2018.11.13.00.52.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Nov 2018 00:52:02 -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: Tue, 13 Nov 2018 09:51:49 +0100 Message-Id: <20181113085151.32368-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181113085151.32368-1-benjamin.gaignard@st.com> References: <20181113085151.32368-1-benjamin.gaignard@st.com> X-Mailman-Approved-At: Tue, 13 Nov 2018 12:15:27 +0000 Cc: uboot-stm32@st-md-mailman.stormreply.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 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 --- 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 Tue Nov 13 08:51:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 150968 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4331201ljp; Tue, 13 Nov 2018 04:19:11 -0800 (PST) X-Google-Smtp-Source: AJdET5cYACJXluRSaxFORCBYBqkW30oHrYg3Km/LqrdyEbzcfXPPl6raePpcNd7Y18f6fKl4N+tn X-Received: by 2002:a50:b2e1:: with SMTP id p88-v6mr3141780edd.155.1542111551460; Tue, 13 Nov 2018 04:19:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542111551; cv=none; d=google.com; s=arc-20160816; b=FTfZQkW4vL5tTM/y/aykqd29DrUbMFE8EI6RrKtBL0QYSCizrpDtL449zZ1lkzTJ4b yWxhf262fXlatTX70oDHl+yRI+bUB1W9dbk0YUcGdjTHdtYze9d+xrn2nN5qdoc3p7c3 Ak1al6nHq3j8Nc+6ZnSjo8lOoQYlZKBST4ZrZ+hSqWheIqO9fWcMpO1PdHcVzF2rvwvM HGmwmMB0hiDEHdHJ3+vY34mO3AJubgJgBEPBroWNCIUsyfQXMVO4TAf0ohWNTOfdGe9C AzExWFK2D4UEJRQ9RV7pDwXKUEj1C7xUsWBtIuLVlCqOOBgYW8ra8tv4oT65jvzBJkIH qzoQ== 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=YuOXGnx+gusfEEYmUSqVSZWXa7Lvg3yNg2mQv3i5O6c=; b=cYb6/qrvtIPogg2dBLPB3Den1JP7dDmbZzLvGUbJTiyfuslMXCclzFp378MjIkXadu PhIihF7o+hl/UpkUMPOvErYLbcTITm+qPixLa4XZeFPZ6D2IlcUfnMisUTlDwaCV0uWu 6bQSOl6PB7Hf8mbAaf09pgFTaGfQhwN9yGhdBTglffeZWIplv2D2WZyL5h9xXWqLjCUU ttx+pw5LRJXJFFL0jThQg0Y0BxENPqvcp3h0xmlsXE+DAHetFUmCox6M3HbpvuizL9AU tmlq26LjAeVVp66WYR3IAHiaMMs38bI1r/CMFQ695AU7JLY0bmgbp0TU9xz7iCZG7x+c qzhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eD7o7g7d; 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 i12si2998566edq.264.2018.11.13.04.19.11; Tue, 13 Nov 2018 04:19:11 -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=eD7o7g7d; 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 ED891C224F3; Tue, 13 Nov 2018 12:18:01 +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 6950AC21F4E; Tue, 13 Nov 2018 12:15:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A6C83C21DCA; Tue, 13 Nov 2018 08:52:05 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id 51669C21ED5 for ; Tue, 13 Nov 2018 08:52:05 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id p4so3132825wrt.7 for ; Tue, 13 Nov 2018 00:52:05 -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=7QP/schaKsjBrzOqMH4l8S1XHL3dKdT8jJfVPxx9QA8=; b=eD7o7g7dXBL08n3fSvB9b9CRHZkkJzdGnjFGJY+jAMPXrmYJP4ubqol5VXZ7Bp1Wdq Jj0ZVC134G1zC26dnxlsPV/CfFngFQb1LWrAUdV98bvs8mu6WWfK9dPe1eeV6E0zq5Ei iqIfRi4t465ql+95YqezVFzSnBSut7H+e1L6A= 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=7QP/schaKsjBrzOqMH4l8S1XHL3dKdT8jJfVPxx9QA8=; b=p/BFU3xcfZ8tSUqDJJncqMI1eVZ3VCMKtrhFtbsWEVLBLqH1/9fHxyXhcVHts2Zm78 1xOCOAR+hj5k5EIq41QxNeG3bPxmMoidZZvb7fQQ2sufTo2AGXgJ1/IqCDKMUuK2lhxX QM3WHPRROSlsfGItl6ssEehDAb/FlsAO3Oq927wshVJ/KlR7PALEQlJZbT8mpm4mmgwk 4IsrUhcpK0qImwj1EC3+gDkWRX8Vg1XRisUQ5Wa7Szz849eKIcp7X2cpgBDG8CzofH9n kZktx6TDhW61g88zfW5kFaGHjs3wDt5GdMftlbvGu6Zw8ZcyfHfpyZy75+BmDGgOfmbf RItQ== X-Gm-Message-State: AGRZ1gJVpTEBRg9++lCJkhZ31U9WYIb7NFpTZ3ef61pDOuwOyMfSjoi3 QbGDfb0VpnLaahm/PN4LH4gTlw== X-Received: by 2002:adf:e84e:: with SMTP id d14-v6mr4024580wrn.51.1542099124844; Tue, 13 Nov 2018 00:52:04 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1047:8145:8cab:bca7:b2f2:d2bb]) by smtp.gmail.com with ESMTPSA id d18-v6sm4235544wre.25.2018.11.13.00.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Nov 2018 00:52:04 -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: Tue, 13 Nov 2018 09:51:50 +0100 Message-Id: <20181113085151.32368-4-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181113085151.32368-1-benjamin.gaignard@st.com> References: <20181113085151.32368-1-benjamin.gaignard@st.com> X-Mailman-Approved-At: Tue, 13 Nov 2018 12:15:27 +0000 Cc: uboot-stm32@st-md-mailman.stormreply.com, u-boot@lists.denx.de, Benjamin Gaignard Subject: [U-Boot] [PATCH 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 --- arch/arm/dts/stm32mp157c-ed1.dts | 4 ++ arch/arm/dts/stm32mp157c.dtsi | 9 ++++ configs/stm32mp15_basic_defconfig | 2 + drivers/hwspinlock/Kconfig | 6 +++ drivers/hwspinlock/Makefile | 1 + drivers/hwspinlock/stm32_hwspinlock.c | 90 +++++++++++++++++++++++++++++++++++ 6 files changed, 112 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..f28d582bb2 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -13,4 +13,10 @@ 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. + 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..b8f3b1632f --- /dev/null +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include +#include + +#define STM32_MUTEX_COREID BIT(8) +#define STM32_MUTEX_LOCK_BIT BIT(31) +#define STM32_MUTEX_NUM_LOCKS 32 + +static int stm32mp1_lock(struct udevice *dev, int index) +{ + fdt_addr_t *base = dev_get_priv(dev); + u32 status; + + if (index >= STM32_MUTEX_NUM_LOCKS) + return -EINVAL; + + status = readl(*base + index * sizeof(u32)); + if (status == (STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID)) + return -EBUSY; + + writel(STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID, + *base + index * sizeof(u32)); + + status = readl(*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) +{ + fdt_addr_t *base = dev_get_priv(dev); + + if (index >= STM32_MUTEX_NUM_LOCKS) + return -EINVAL; + + writel(STM32_MUTEX_COREID, *base + index * sizeof(u32)); + + return 0; +} + +static int stm32mp1_hwspinlock_probe(struct udevice *dev) +{ + fdt_addr_t *base = dev_get_priv(dev); + struct clk clk; + int ret; + + *base = dev_read_addr(dev); + if (*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(fdt_addr_t), +}; From patchwork Tue Nov 13 08:51:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 150970 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4331678ljp; Tue, 13 Nov 2018 04:19:37 -0800 (PST) X-Google-Smtp-Source: AJdET5dGn3ld5jxV93REnEe3OKTWllekYDWoji6yrM/QhaUP1tfAhD9nZ1xTT60bFu9ZqcjAUu2v X-Received: by 2002:aa7:c458:: with SMTP id n24-v6mr15430613edr.55.1542111577819; Tue, 13 Nov 2018 04:19:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542111577; cv=none; d=google.com; s=arc-20160816; b=eCbAuQmcFLWSOs4owVkpGQPvmIbDXUezujNPxbT2xu/mF7KVTvcTuU5EVPfqsUZFHE fTlNLxh1BnVjTZbcUhhz47n10vf0GwFb6Ib8hc2fGM5L1w0Onhev18svWkuxO4xAKP4j d2QhUUAqO69Ez9Jngt+2hLFKabVfamey36mWBXkbtzrCm6kBIF70JLQLvtPT5G0d5c/8 2P0QETQXUp7uht6cOvCFFKzBcDd/7KzFULRMAWtYgbQzhEkoGa0U0yhudZLz/cK407Lk wGJXZl6bIvockVC9i0nCTqDUfLQKl0Td6kcPP9eYHjwGluKPD4cYWnHn1WCV2MBXPn9G T8QA== 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=PFXYeJMQNGsdfi8EnPPQS0fy0bb4GSNBc3Qj2cKfH+g=; b=wGRfyMapgz7nRQu/t3hU1POVCvHqfCPchOL78l503UolP09G7oti01aFzlk0eWxDlY sX5Yu4kO1xz1EvMfSwi2bEYvcDRvcWM414jG/OBd/EVKxWPYZ9UDoJgeLf072XhPOdLF kSRxXkwgXtWHx/PrtHHQl8s83phULci1cMwz8iNFJeRifDYjR2wwn490osNmg1CjKQ/r GuhnBVVFoFygcCrjFEpStfnUHvOc2ykcS36dejWwDy1r/ezSFJMP8FUA+ApCQhcq5crf mCOfCSyGBDMXt+bSBa7dU5MuJ+U+Uz2AHTyXcuHMAHNVq8ZPF3vkmOHi0cTMZYw/ZKtg iY0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=d3JY4j5D; 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 r15-v6si1026201ejr.60.2018.11.13.04.19.37; Tue, 13 Nov 2018 04:19:37 -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=d3JY4j5D; 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 6C31CC224FC; Tue, 13 Nov 2018 12:18:18 +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 5C494C2252D; Tue, 13 Nov 2018 12:15:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A1BA3C21ED5; Tue, 13 Nov 2018 08:52:07 +0000 (UTC) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by lists.denx.de (Postfix) with ESMTPS id 16180C21DCA for ; Tue, 13 Nov 2018 08:52:07 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id u13-v6so10582784wmc.4 for ; Tue, 13 Nov 2018 00:52:07 -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=BD5rMv+N1dLdo+NQLGay9wz8+FWPDp+WsLPBmGRxhv0=; b=d3JY4j5D4ch1ZKPLNXp0sr6deIDDkoa9llx57a1x5nmNVBL8vMY8WneWhuUG8a/8Q0 ykAmq1Fe+InuuoTTvE/EvTt+C6XgmgHvMBKsmpn5hhk++5qngBNWHeyz1ELAHBhqf0Fj vOdC7L+oMnCEtMeWh7eM99HuXWL7bLihdNLto= 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=BD5rMv+N1dLdo+NQLGay9wz8+FWPDp+WsLPBmGRxhv0=; b=Mwe8smwWI9LtBAOe1b/2lETw7N04Zg0MjuJOoe3y0FFG5mi4EA16CnqGAkLKwQ0SBA q15ufSyg30gCtA7H16X/pswulwHDrECa8Bbvzlfb/g0FN++TNRqgIuAMN1Zyg6WS1XM2 1Xo33JT54uSRp8MQ2ZBuEKFbT5bf89AGYHbYXFRZPhkRQ8taKEiPN+nuxwVlNfmhblHj kzDU404YijdX8YDE2xCUK4dxBE3k3ucBFXZs3Aq5WrKSkGtZN5hXJDXCJGA9m5XBqF7p HRwcIYkaK/eGoIUnKgOkWvCCbJtQBMl9YVSDFgZHeXQ1VutCbhtaNMeZvEC5jIErosSC yDOA== X-Gm-Message-State: AGRZ1gJlUxUyBkXGXDevscajVOorG+al5TSymyae6zHQesGoPZvSr37V hEJiEP4Oia5SEffjXkcmKOsPwA== X-Received: by 2002:a1c:44d4:: with SMTP id r203-v6mr471642wma.50.1542099126645; Tue, 13 Nov 2018 00:52:06 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1047:8145:8cab:bca7:b2f2:d2bb]) by smtp.gmail.com with ESMTPSA id d18-v6sm4235544wre.25.2018.11.13.00.52.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Nov 2018 00:52:05 -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: Tue, 13 Nov 2018 09:51:51 +0100 Message-Id: <20181113085151.32368-5-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181113085151.32368-1-benjamin.gaignard@st.com> References: <20181113085151.32368-1-benjamin.gaignard@st.com> X-Mailman-Approved-At: Tue, 13 Nov 2018 12:15:27 +0000 Cc: uboot-stm32@st-md-mailman.stormreply.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH 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 Signed-off-by: Benjamin Gaignard --- arch/arm/dts/stm32mp157c-ed1.dts | 4 ++++ drivers/pinctrl/pinctrl_stm32.c | 22 ++++++++++++++++++++++ 2 files changed, 26 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..469cc0c543 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(desc->dev->parent); 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,15 @@ 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); + + hwspinlock_get_by_index(dev, 0, hws); + + return 0; +} + static struct pinctrl_ops stm32_pinctrl_ops = { #if CONFIG_IS_ENABLED(PINCTRL_FULL) .set_state = stm32_pinctrl_set_state, @@ -200,4 +220,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), };