From patchwork Wed Oct 31 09:30:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 149773 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6552727ljp; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) X-Google-Smtp-Source: AJdET5dy0+u8JGSDuwaokysIroDBDaj6w8wVfkSPQI9ZEQIE98P25KhFL+TrBh3JETvAj9AWaa9i X-Received: by 2002:a62:8e0a:: with SMTP id k10-v6mr2638108pfe.182.1540978259518; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540978259; cv=none; d=google.com; s=arc-20160816; b=v9JMn7wHrh1auo5jHwXvCFEiyXhJ3LVP0oOkDqOeTYLpPLiaEEUvQ/uppaIUaAdw1e b/vei8VW8746lcS+f8NeM1S1YZms8EgIcfguSDqZuCcIoITlT/GVSGayoQfuq/PAF+HM HbzKeoAVX6RMT79RZOj5i0nyn5jLQnf+40rUz7R2/JLqyOHxJLecO1JvMkxW3KYZFGiD 3iPfl5ioWXsfBm9k3cuG96gcYFMcjt6XWk9ScEN6n60dSvm07ncGSvAP22EFtwPUyfli 3V16gLgOJZDY1ihwNxnDx4p24AM+w2qg9RBcrL9jYZRKDzPZTN9oEXCZvcP6KwKUa82w QqOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=OCewN85BXjXK6qI/FZdB9QY1FkUVogdwEIt0smFxfhs=; b=edCvkkfAztngJHgB30Og2866oImc7nq94yWMpA81hqeUQxvWtB1xim2M+keeVr35Pf xRXlmstB5o5icF7/Hin7bK62RIjkAxmwHFZcS1Ry0LV43M8VUze5y1cKBQR/W+qPI+V+ TnknG2vELe+jpCG3nvQIdRROTcQx6hZfspIqLzhJYeM+HhjuNEvxssiOt6DGU4hNMaqH Fd3fBQB3u1p8r8CLpNQtjkHOKIEagzroiPVC4/ZQtFBVpD5fbHl4yV/JpuRwi4E39CKk 8gVPoLuCpQCoigA4DMY3eQEp+zKIRZfWQqjC30KqibSmikdm7dDxgIbikoX3ZBKlAopB TC/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ebiZIiAc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si4793503ple.148.2018.10.31.02.30.59; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ebiZIiAc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728308AbeJaS2Q (ORCPT + 32 others); Wed, 31 Oct 2018 14:28:16 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34992 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728136AbeJaS2O (ORCPT ); Wed, 31 Oct 2018 14:28:14 -0400 Received: by mail-wm1-f66.google.com with SMTP id q12-v6so11131356wmq.0 for ; Wed, 31 Oct 2018 02:30:53 -0700 (PDT) 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=OCewN85BXjXK6qI/FZdB9QY1FkUVogdwEIt0smFxfhs=; b=ebiZIiAcOFS+c+u43A22LaTq48add9ZKsgKdQoX+XEj2Oqdne0CRjNM9vSl+y46ZJI Kz6prWMdHKZXBlX9qOWVcKlAX7k8xrB4j92tM4L0aYf6sT2W/t8//1ermdRcyI35JplU osGpoR0wsai40PeQ6+yjlMVXWSRlWWz+IEgWI= 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=OCewN85BXjXK6qI/FZdB9QY1FkUVogdwEIt0smFxfhs=; b=WWcSiVtKIFTAmmR1OsTWUpWDOfKHNenT9hydSSH8hsIKGBOq+xGFqlDe3WllRWXHa/ pPHqLxwwokEkVD8J6BNF0HcBY6rmpRY0hLK8rwaWgfC9wf+2KuUnM6fK6aosuZmRThcz f6ZxdGzYPSQkhpFF4X5ajD3t2ggLMp94UtCwA6ShqYqxwmcODrerWj2R9ZPGQ2KLJkL6 fy3MVLa7bKUCqaUdeERivj06H/QjGB5ZsZgvaP4sddZ2h+3vfTbduwF2pWeM0gNtIf79 SN668cTs6epDdskrNVm437gs98gd4ntW532OpHPtVlh0EtmrIlvfRPUCcBjngsLxOc1H r0zQ== X-Gm-Message-State: AGRZ1gLtdmHjvwrZy6T7j6JAtl2CoJm/6vp/0XlEIIyzkart9X2DYqp7 I5TIex8aeuSJviCQMrT65Kskhw== X-Received: by 2002:a1c:84cd:: with SMTP id g196-v6mr1723453wmd.38.1540978252699; Wed, 31 Oct 2018 02:30:52 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1086:999:fd1b:8629:a7fc:68b]) by smtp.gmail.com with ESMTPSA id w14-v6sm10737377wrt.73.2018.10.31.02.30.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Oct 2018 02:30:51 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, alexandre.torgue@st.com Cc: linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Benjamin Gaignard Subject: [PATCH 2/5] hwspinlock: add STM32 hwspinlock device Date: Wed, 31 Oct 2018 10:30:29 +0100 Message-Id: <20181031093032.20386-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181031093032.20386-1-benjamin.gaignard@st.com> References: <20181031093032.20386-1-benjamin.gaignard@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support of hardware semaphores for stm32mp1 SoC. The hardware block provides 32 semaphores. Signed-off-by: Benjamin Gaignard --- drivers/hwspinlock/Kconfig | 9 +++ drivers/hwspinlock/Makefile | 1 + drivers/hwspinlock/stm32_hwspinlock.c | 147 ++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 drivers/hwspinlock/stm32_hwspinlock.c -- 2.15.0 diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index e895d29500ee..e1a20b460590 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -59,3 +59,12 @@ config HSEM_U8500 SoC. If unsure, say N. + +config HWSPINLOCK_STM32 + tristate "STM32 Hardware Spinlock device" + depends on MACH_STM32MP157 + depends on HWSPINLOCK + help + Say y here to support the STM32 Hardware Spinlock device. + + If unsure, say N. diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile index b87c01a506a4..c0a9505b4dcf 100644 --- a/drivers/hwspinlock/Makefile +++ b/drivers/hwspinlock/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_HWSPINLOCK_QCOM) += qcom_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_SIRF) += sirf_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_SPRD) += sprd_hwspinlock.o obj-$(CONFIG_HSEM_U8500) += u8500_hsem.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 000000000000..6a0fafac7389 --- /dev/null +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics SA 2018 + * Author: Benjamin Gaignard for STMicroelectronics. + * License terms: GNU General Public License (GPL), version 2 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hwspinlock_internal.h" + +#define STM32_MUTEX_COREID BIT(8) +#define STM32_MUTEX_LOCK_BIT BIT(31) +#define STM32_MUTEX_NUM_LOCKS 32 + +struct stm32_hwspinlock { + struct clk *clk; + struct hwspinlock_device bank; +}; + +static int stm32_hwspinlock_trylock(struct hwspinlock *lock) +{ + void __iomem *lock_addr = lock->priv; + u32 status; + + writel(STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID, lock_addr); + status = readl(lock_addr); + + return status == (STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID); +} + +static void stm32_hwspinlock_unlock(struct hwspinlock *lock) +{ + void __iomem *lock_addr = lock->priv; + + writel(STM32_MUTEX_COREID, lock_addr); +} + +static const struct hwspinlock_ops stm32_hwspinlock_ops = { + .trylock = stm32_hwspinlock_trylock, + .unlock = stm32_hwspinlock_unlock, +}; + +static int stm32_hwspinlock_probe(struct platform_device *pdev) +{ + struct stm32_hwspinlock *hw; + void __iomem *io_base; + struct resource *res; + size_t array_size; + int i, ret; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + io_base = devm_ioremap_resource(&pdev->dev, res); + if (!io_base) + return -ENOMEM; + + array_size = STM32_MUTEX_NUM_LOCKS * sizeof(struct hwspinlock); + hw = devm_kzalloc(&pdev->dev, sizeof(*hw) + array_size, GFP_KERNEL); + if (!hw) + return -ENOMEM; + + hw->clk = devm_clk_get(&pdev->dev, "hwspinlock"); + if (IS_ERR(hw->clk)) + return PTR_ERR(hw->clk); + + for (i = 0; i < STM32_MUTEX_NUM_LOCKS; i++) + hw->bank.lock[i].priv = io_base + i * sizeof(u32); + + platform_set_drvdata(pdev, hw); + pm_runtime_enable(&pdev->dev); + + ret = hwspin_lock_register(&hw->bank, &pdev->dev, &stm32_hwspinlock_ops, + 0, STM32_MUTEX_NUM_LOCKS); + + if (ret) + pm_runtime_disable(&pdev->dev); + + return ret; +} + +static int stm32_hwspinlock_remove(struct platform_device *pdev) +{ + struct stm32_hwspinlock *hw = platform_get_drvdata(pdev); + int ret; + + ret = hwspin_lock_unregister(&hw->bank); + if (ret) { + dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret); + return ret; + } + + pm_runtime_disable(&pdev->dev); + + return 0; +} + +static int __maybe_unused stm32_hwspinlock_runtime_suspend(struct device *dev) +{ + struct stm32_hwspinlock *hw = dev_get_drvdata(dev); + + clk_disable_unprepare(hw->clk); + + return 0; +} + +static int __maybe_unused stm32_hwspinlock_runtime_resume(struct device *dev) +{ + struct stm32_hwspinlock *hw = dev_get_drvdata(dev); + + clk_prepare_enable(hw->clk); + + return 0; +} + +static const struct dev_pm_ops stm32_hwspinlock_pm_ops = { + SET_RUNTIME_PM_OPS(stm32_hwspinlock_runtime_suspend, + stm32_hwspinlock_runtime_resume, + NULL) +}; + +static const struct of_device_id stm32_hwpinlock_ids[] = { + { .compatible = "st,stm32-hwspinlock", }, + {}, +}; +MODULE_DEVICE_TABLE(of, stm32_hwpinlock_ids); + +static struct platform_driver stm32_hwspinlock_driver = { + .probe = stm32_hwspinlock_probe, + .remove = stm32_hwspinlock_remove, + .driver = { + .name = "stm32_hwspinlock", + .of_match_table = stm32_hwpinlock_ids, + .pm = &stm32_hwspinlock_pm_ops, + }, +}; +module_platform_driver(stm32_hwspinlock_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Hardware spinlock driver for STM32 SoCs"); +MODULE_AUTHOR("Benjamin Gaignard "); From patchwork Wed Oct 31 09:30:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 149772 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6552721ljp; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) X-Google-Smtp-Source: AJdET5clNNjLT66hpM0dkaOEtt1gKrEM6kMHGzkQrzF/uEdDgB3Rn0ZPQfwc/c5lMh7Un9FAomHd X-Received: by 2002:a17:902:a717:: with SMTP id w23-v6mr2565431plq.24.1540978259049; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540978259; cv=none; d=google.com; s=arc-20160816; b=xxUTmzydU2PabcNIYpW5DSxPU63vTkyJpyAPeEqF4QHTRe1RMdh3i+ZItJnjHTPayG W/KL2k7885Rp9JwS3//ZlnKBSHHU+w2Nh3DZUnedfVzn1tWTro0BK2UiNBvGAUJWTSQc +RxjWnJ3b8HnklkE3MmfLAEVTq1u5zrIB6Xb5XuTyXk3Aq9aXJq9EFIdCCXobpzygT4f HvtZJTPwTpRK+0O0QvmCjkHUum2QgXQjF/Y1tIw0OuVhHK8k1ORuYLlfl1u2RI/pjkTM 2DArHmpH3m8Q+juH0eEZZw5cL4bmD2PPI3GgwJVz6PvHTPbKtsnnMgJ8Au6vvNJzgpo7 Z+KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=YT2BGL73pI00O7JsdMy6/bfTMju1hXp1TWklR4ycj/Y=; b=sLxeqEvgFw2kbkSLXuPkSBvNSrNLYKWZdizRnCYdRGWAVsEGckTL4gA5Cpdqw88ilY mAZ3SJXTywknErhFNdvL34VyH+um8U3cnUtdYPMh/7GC3hMvDgyoNWMk/vKagvnc9fKB 0Gh+KOfOQ4gD2/FVvx2P95mOcBXlemYVUUlEDPw0NsgYFd1GCb29va5aVxoZYS2SUufs TuUSrNc8e5uupFh9KUczbz098dI3/HbJX4dv6DCp99J5dPf5w8HVhYlcZQ76Uh8OCz+7 b3yAdUf1f88juQNHezOtZdhFHFLI4dUuHqlzs8sbgYdfykgzycZMvmBLrTV0OCq36tiC tkcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BZum8nXL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si4793503ple.148.2018.10.31.02.30.58; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BZum8nXL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728240AbeJaS2Q (ORCPT + 32 others); Wed, 31 Oct 2018 14:28:16 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43496 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728154AbeJaS2Q (ORCPT ); Wed, 31 Oct 2018 14:28:16 -0400 Received: by mail-wr1-f68.google.com with SMTP id t10-v6so15627220wrn.10 for ; Wed, 31 Oct 2018 02:30:55 -0700 (PDT) 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=YT2BGL73pI00O7JsdMy6/bfTMju1hXp1TWklR4ycj/Y=; b=BZum8nXLTQ4NN966TU5Ngk/Fw9BfsYRg3AezKMn0W/0NnzF4JHYdoxnWX2otpQY7nq aJ5rNEnIqV4EdmjoG8rYDO3DqRMVPJdLTlk4yAtAHizGIHHsAqNyybbtYK1sU1fYHpzT 16ITGm0vTNp4UO2j1RqijxyBtY1o+dutoj2sc= 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=YT2BGL73pI00O7JsdMy6/bfTMju1hXp1TWklR4ycj/Y=; b=TTyb9dkv1hSf7PxfvsqOvZc+OM9d78E7kDxfcrm9PebzEMRkhiE9cM5BF/F/+yTiUS +bsjnN3lq0z3NLjfrRtLBMLBaQ03M5lO3Fgc/9rCyvkJCBommxwQ96mmy6NNeUY5ZK0r 6gTcgiFc+p4BGtknV6ij2qAMf8hGhoRvnM0sMDj0/74gi02sP7QZfyreZce8P5Pf1BsU gVOiScsZkSO3HtN5RnTUMc7HLvFaskAK2/J22muDcqOtvCkdkxE+HljX4HFOvGW/HyNo BXWteHiy+i4v2W4K1+f8Dlu2ljrdICLckLAZsUl+HplspAYsjOncftSTehjbYJA4zcdU PK4g== X-Gm-Message-State: AGRZ1gLEMqgxnHZEsDryKG5N+oIRzrNuHbie/I7pK5VsV5aLDqe7s4Al qAznSUopYaFjHzKtvFUjimyUyQ== X-Received: by 2002:a5d:560c:: with SMTP id l12-v6mr2038566wrv.281.1540978254624; Wed, 31 Oct 2018 02:30:54 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1086:999:fd1b:8629:a7fc:68b]) by smtp.gmail.com with ESMTPSA id w14-v6sm10737377wrt.73.2018.10.31.02.30.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Oct 2018 02:30:54 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, alexandre.torgue@st.com Cc: linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Benjamin Gaignard Subject: [PATCH 3/5] ARM: dts: stm32: Add hwspinlock node for stm32mp157 SoC Date: Wed, 31 Oct 2018 10:30:30 +0100 Message-Id: <20181031093032.20386-4-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181031093032.20386-1-benjamin.gaignard@st.com> References: <20181031093032.20386-1-benjamin.gaignard@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Declare hwspinlock device for stm32mp157 SoC Signed-off-by: Benjamin Gaignard --- arch/arm/boot/dts/stm32mp157c.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.15.0 diff --git a/arch/arm/boot/dts/stm32mp157c.dtsi b/arch/arm/boot/dts/stm32mp157c.dtsi index 185541a5b69f..9b16c28f8ac3 100644 --- a/arch/arm/boot/dts/stm32mp157c.dtsi +++ b/arch/arm/boot/dts/stm32mp157c.dtsi @@ -803,6 +803,15 @@ status = "disabled"; }; + hsem: 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>; From patchwork Wed Oct 31 09:30:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 149775 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6552779ljp; Wed, 31 Oct 2018 02:31:03 -0700 (PDT) X-Google-Smtp-Source: AJdET5cfBOc1gvWvrmb6IJOTUjgj3d7WESfv/RImioaJFKRwRwi6kA5qnKymo8hPYR2TaKGopwVU X-Received: by 2002:a17:902:654a:: with SMTP id d10-v6mr2450302pln.302.1540978263348; Wed, 31 Oct 2018 02:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540978263; cv=none; d=google.com; s=arc-20160816; b=nkew7jroY99mUjMKRyfYL2RMl0px5o1rvZJ6QmUBE5uKrmbOo1ftW+xgrdJoxNOvFl S4S0hbpvyuxVYMiwqP0A2afTeZsGrwH3/cLK8IZwJdFZqTTGFBoeSt/57PHollYun5TY qWK6J+7H2iLVGo/A7LoAUsk1f3aXj8MKCFD+IOFGG8oqds0ExEukAKLcXd9uB3NaWFqr SbfDCH2nmySSRRdHbtwHe8j+8PprPrChKU9CR+mBo6LFrB6d5QtoCtRKTR/+aCu6rSjJ atQmBY7J1oMcoASS+qEhN/wwkOhRmrn8sH6AKRNJDtdp0Lzhx57dpJtfbURmDv+Srj0n si9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=2uKBBGkCNMoGjJfIY95Fh+s9tnlSDO4scNahnS2PGqY=; b=Amkg1PzlRMb86d1xU1zAb4ODHCaKL5dE4Jj8THw8ytspkOXo8xMS8z9JXV5QqVVVMB 42NaKpWE8ligVx0wf56Kj5u4nxwX2kgbmkAOvBkiq4+kcBJ4ig2eflTOiDDgg4LvcY4F pInzxSmdZt5kQ3586aTeVpeBvaMhpeOxs8ul0icgUYDSyzu2ufnoRAvPP2NLqdiR+2DG uemmL8ftvD4qI6bg6X8So6khacM1B6f3C1upK4leRByowYVX5AG8Exl/bFG7S86L2clF UJiphx79ptIJmDRIGlv8qSjLcJJxDwVL76J9JBGg1EK5IDtghruIiCzduo9HMvJuQS8n FOIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JT+fIGxz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13-v6si822464plr.271.2018.10.31.02.31.02; Wed, 31 Oct 2018 02:31:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JT+fIGxz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728463AbeJaS2U (ORCPT + 32 others); Wed, 31 Oct 2018 14:28:20 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41599 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728044AbeJaS2U (ORCPT ); Wed, 31 Oct 2018 14:28:20 -0400 Received: by mail-wr1-f67.google.com with SMTP id x12-v6so15639424wrw.8 for ; Wed, 31 Oct 2018 02:30:59 -0700 (PDT) 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=2uKBBGkCNMoGjJfIY95Fh+s9tnlSDO4scNahnS2PGqY=; b=JT+fIGxzFE1oZ0o9/cuu8TmJdAOZGpwaGOYW4FfGgFbycJnB1k5HfvnFTwtwS5k+8H F/KY7au1njJwObf7X8BEGeBgVjct/1s1BsJZSodgBbAPqSuJCA1qTIdKLqLGIqGv12ej cs3mFxt3OZlg2x7Q4W2IZpIH32S7rvkSEfol4= 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=2uKBBGkCNMoGjJfIY95Fh+s9tnlSDO4scNahnS2PGqY=; b=s5YPFsPwoVsIdnNulijgEknOsc69+Z+k9X2MaMIqxudeoULc7FR/DoKS5uU0Z4OmVb mSTAYf7BF4OWmkk5PO1vI23RS0aYWrG9opFGg7YRsF+UQ5vSDbKYcHgkAty5uisWs1EJ ztIv8MgRVoOXVkCanWgTT2fsOZwGbxzc5wq+XAR0XDoL6Lr4NpisA1FhJhlhpq6Qg7BH 7/4pHb1BRgRJEk7wXuvLI2B7bGN2ua1SXQd5ETiCtSZpEWoezq1ndd58Lcfv2aWECw7p GwXIqBfbs8PT9qmq9AunNtk3BV6CH2H32QQd6mYanHrjfrGF9DGP/2RlBGQg3DE2+AYt V62w== X-Gm-Message-State: AGRZ1gJl+hVQe++XZcFSJnppEjwOfNQQ0zMunDYUdqRC8WZISorpH3KU KKwBgDQ5w2y2JT7C9KBEy4VcwA== X-Received: by 2002:a5d:4e01:: with SMTP id p1-v6mr2116103wrt.320.1540978258587; Wed, 31 Oct 2018 02:30:58 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1086:999:fd1b:8629:a7fc:68b]) by smtp.gmail.com with ESMTPSA id w14-v6sm10737377wrt.73.2018.10.31.02.30.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Oct 2018 02:30:58 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: ohad@wizery.com, bjorn.andersson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, alexandre.torgue@st.com Cc: linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Benjamin Gaignard Subject: [PATCH 5/5] hwspinlock: Add test module Date: Wed, 31 Oct 2018 10:30:32 +0100 Message-Id: <20181031093032.20386-6-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181031093032.20386-1-benjamin.gaignard@st.com> References: <20181031093032.20386-1-benjamin.gaignard@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a test module to perform simple unitary tests on hwspinlock. It doesn't cover all the possibles cases but at least allow to test that very basic features are working. Signed-off-by: Benjamin Gaignard --- drivers/hwspinlock/Kconfig | 9 +++ drivers/hwspinlock/Makefile | 1 + drivers/hwspinlock/hwspinlock_test.c | 132 +++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 drivers/hwspinlock/hwspinlock_test.c -- 2.15.0 diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index e1a20b460590..f340ebb4d1f7 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -68,3 +68,12 @@ config HWSPINLOCK_STM32 Say y here to support the STM32 Hardware Spinlock device. If unsure, say N. + +config HWSPINLOCK_TEST + tristate "hwspinlock test module" + depends on HWSPINLOCK && m + default n + help + Select M here if you want to build hwspinlock test module + + If unsure, say N. diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile index c0a9505b4dcf..e6b3d0212fe0 100644 --- a/drivers/hwspinlock/Makefile +++ b/drivers/hwspinlock/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_HWSPINLOCK_SIRF) += sirf_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_SPRD) += sprd_hwspinlock.o obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o +obj-$(CONFIG_HWSPINLOCK_TEST) += hwspinlock_test.o diff --git a/drivers/hwspinlock/hwspinlock_test.c b/drivers/hwspinlock/hwspinlock_test.c new file mode 100644 index 000000000000..75819337e45a --- /dev/null +++ b/drivers/hwspinlock/hwspinlock_test.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics SA 2018 + * Author: Benjamin Gaignard for STMicroelectronics. + * License terms: GNU General Public License (GPL), version 2 + */ + +#include +#include +#include + +#define TIMEOUT 50 /* ms */ + +static void hwspin_lock_test_twice_request_specific(void) +{ + struct hwspinlock *lock0 = hwspin_lock_request_specific(0); + struct hwspinlock *lock1 = hwspin_lock_request_specific(1); + + int ret; + + if (!lock0 || !lock1) { + pr_warn("Can't request twice hwspin_lock\n"); + return; + } + + ret = hwspin_trylock(lock0); + if (ret) + pr_warn("Can't trylock requested hwspin_lock 0 (%d)\n", ret); + + ret = hwspin_trylock(lock1); + if (ret) + pr_warn("Can't trylock requested hwspin_lock 1 (%d)\n", ret); + + hwspin_unlock(lock0); + hwspin_unlock(lock1); + + ret = hwspin_lock_free(lock0); + if (ret) + pr_warn("Can't free requested hwspin_lock 0\n"); + + ret = hwspin_lock_free(lock1); + if (ret) + pr_warn("Can't free requested hwspin_lock 0\n"); +} + +static void hwspin_lock_test_trylock(void) +{ + struct hwspinlock *lock = hwspin_lock_request(); + int ret; + + if (!lock) { + pr_warn("Can't request hwspin_lock\n"); + return; + } + + ret = hwspin_trylock(lock); + if (ret) + pr_warn("Can't trylock requested hwspin_lock (%d)\n", ret); + + /* Try to lock a second time, this should failed */ + ret = hwspin_trylock(lock); + if (ret != -EBUSY) + pr_warn("Getting twice the same lock ! (%d)\n", ret); + + hwspin_unlock(lock); + ret = hwspin_lock_free(lock); + if (ret) + pr_warn("Can't free requested hwspin_lock 0\n"); +} + +static void hwspin_lock_test_request_specific(void) +{ + /* + * Let's assume that any hwspin_lock driver would at least have one + * lock at index 0 + */ + struct hwspinlock *lock = hwspin_lock_request_specific(0); + int ret; + + if (!lock) { + pr_warn("Can't request hwspin_lock 0\n"); + return; + } + + ret = hwspin_lock_timeout(lock, TIMEOUT); + if (ret) + pr_warn("Can't lock requested hwspin_lock 0 (%d)\n", ret); + + hwspin_unlock(lock); + ret = hwspin_lock_free(lock); + if (ret) + pr_warn("Can't free requested hwspin_lock 0\n"); +} + +static void hwspin_lock_test_request(void) +{ + struct hwspinlock *lock = hwspin_lock_request(); + int ret; + + if (!lock) { + pr_warn("Can't request hwspin_lock\n"); + return; + } + + ret = hwspin_lock_timeout(lock, TIMEOUT); + if (ret) + pr_warn("Can't lock requested hwspin_lock (%d)\n", ret); + + hwspin_unlock(lock); + ret = hwspin_lock_free(lock); + if (ret) + pr_warn("Can't free requested hwspin_lock\n"); +} + +/* + * Test hwspinlock user API when module is loaded + */ +static int __init hwspin_lock_test_init(void) +{ + pr_warn("Loading hwspinlock test module\n"); + hwspin_lock_test_request(); + hwspin_lock_test_request_specific(); + hwspin_lock_test_trylock(); + hwspin_lock_test_twice_request_specific(); + + return 0; +} + +module_init(hwspin_lock_test_init); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Hardware spinlock test driver");