From patchwork Thu Nov 8 09:05:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 150484 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp582603ljp; Thu, 8 Nov 2018 01:05:22 -0800 (PST) X-Google-Smtp-Source: AJdET5eBgMqZjE63okPs/DdqG3hLdMcZmdwDxg7iFJty2GpG2KS7QtAwoIyon09xfo0cCzKwov06 X-Received: by 2002:a65:610e:: with SMTP id z14-v6mr3168411pgu.138.1541667921884; Thu, 08 Nov 2018 01:05:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541667921; cv=none; d=google.com; s=arc-20160816; b=aDoSlH5cAML6eKCOccy3i/0vtlUK/XgfUicP5SHaLH647wiSouL8R9YXKSQoFvbW2U xwY4KuhtSJ7H4eHjimz7GFzeKxOeKGXjck/8VFCMbIKpKQURLJb7fyclKDy2OFRSUffP x1Lgd94FEVWHhPX0pdLIi4sPApKkYJpGgGArlZQIPmNNZTdWY358T4U1H3xVhnBwwKz/ mz6gwu9+rQKGpXgC1II7faGwcyaN7KbCq1igxD8qQuCROgNeHQe+4ZaS9PBMA1vB1m/Y H8tx8rfr45VNDr0Ew1mZkdE1bP6CVofDbPQEKXSzCqsc/tckBNUbYVhhUl5mFXSqXvwH TGMg== 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=vfYBXlI8TGzQiJThszSCkUGyt2x6cRpuleHBiD2O0WI=; b=EDQOante39x+WHICUuToedIhCMAid/NvdLzf7Kj3Jp3IQ2LrzVUdp17K/4zGfaJBia FWGaiv1g2h0ZKQmdjAUN6y7q0jG6E0itDKhbZOJEZc0a7ikuI9bOA7q48yz/jBAeHWim tD3WwRAFXPdqjB2OK971iJFiR6L0XZH/wRwiUjH4nrlrMCQayv2qH40SVlmAU5R/2Q0R fppp6IKGmZcVJiTdrJdy6YGpkKGdeG8JbOQhvdouoDTumL0GwYmhBaJA29OOtWNM45Ft 8adtxArQ8wIuLI6Iibk+FZtW2vlHcWTZhcT/XBp2nXDSpQl+1m/tAFlzraTw6Foq4Nmu NhGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gKwZFQEd; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 t1-v6si3063534pgg.541.2018.11.08.01.05.21; Thu, 08 Nov 2018 01:05:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=gKwZFQEd; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1726881AbeKHSjv (ORCPT + 6 others); Thu, 8 Nov 2018 13:39:51 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33230 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726667AbeKHSjv (ORCPT ); Thu, 8 Nov 2018 13:39:51 -0500 Received: by mail-wm1-f65.google.com with SMTP id f19-v6so1037333wmb.0 for ; Thu, 08 Nov 2018 01:05:19 -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=vfYBXlI8TGzQiJThszSCkUGyt2x6cRpuleHBiD2O0WI=; b=gKwZFQEdxyx71OjEc1WYHh9hL7tMQAk1Q8NN1gKz3OPhXyowjVnmGmtP0pclDo03UO jjKBlQLxFIkeyqHRGQsU/p+AQxRhePTpYb9qaM1xBbr821jcgAfPA1Av1uKR1HzXbFeP acI/vnI+Lg+psXV1HGPrLaaUyj1gdfRBbrkuk= 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=vfYBXlI8TGzQiJThszSCkUGyt2x6cRpuleHBiD2O0WI=; b=C4mihT36CjAsgolCfCAwViU4LdqLTTAfFgyqDmJh8C4oHVvOAVqGjTBCU6FulcZUyH lLAs7kKu0eSQdNvKjojMtXa1nPv5hMxsvnJi8HdEVRhqmAQmZszcpeSNLnjLA+8jWYWs QrFakdDudMicwyxXsviae85Y93WdKnwgd4V2nkjBj9GiY8hsZwU72LfJdpPvBzfRCtA1 rf5O4KPXPbpXcxDJrhuEcYEVIyQqW2+DrhlaJRbaLTtiY/q4Aj2/qZKiUSNhw4LFcOdf DTm9cm/7OIftCIYH8hHsqnP1AhvAPX6kLgB7mAO+iUVz+rWyL+hbvWRzuS3Y2s0QYqM4 2RRQ== X-Gm-Message-State: AGRZ1gIEAdx3UvmoY/TidmzjwFBMXYw6hi8hlLV6A8oAtqeNUVPEAk+z 7OQDP3fPEdqJZgcrJd0C9HbLNw== X-Received: by 2002:a1c:5706:: with SMTP id l6-v6mr443683wmb.51.1541667918008; Thu, 08 Nov 2018 01:05:18 -0800 (PST) Received: from lmecxl0911.lme.st.com ([2a04:cec0:1094:149:440c:9368:8cda:a020]) by smtp.gmail.com with ESMTPSA id l140-v6sm6974469wmb.24.2018.11.08.01.05.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Nov 2018 01:05:17 -0800 (PST) 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 v2 2/4] hwspinlock: add STM32 hwspinlock device Date: Thu, 8 Nov 2018 10:05:00 +0100 Message-Id: <20181108090502.14543-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20181108090502.14543-1-benjamin.gaignard@st.com> References: <20181108090502.14543-1-benjamin.gaignard@st.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds support of hardware semaphores for stm32mp1 SoC. The hardware block provides 32 semaphores. Signed-off-by: Benjamin Gaignard --- version 2 : - change clock name from hwspinlock to hsem to be align with hardware documentation - remove useless licence terms from header - fix alphabetic order issues - do not abort remove function if hwspin_lock_unregister() failed drivers/hwspinlock/Kconfig | 9 +++ drivers/hwspinlock/Makefile | 1 + drivers/hwspinlock/stm32_hwspinlock.c | 144 ++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 drivers/hwspinlock/stm32_hwspinlock.c -- 2.15.0 diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index e895d29500ee..7869c67e5b6b 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -49,6 +49,15 @@ config HWSPINLOCK_SPRD 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. + config HSEM_U8500 tristate "STE Hardware Semaphore functionality" depends on HWSPINLOCK diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile index b87c01a506a4..ed053e3f02be 100644 --- a/drivers/hwspinlock/Makefile +++ b/drivers/hwspinlock/Makefile @@ -8,4 +8,5 @@ obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_QCOM) += qcom_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_SIRF) += sirf_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_SPRD) += sprd_hwspinlock.o +obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c new file mode 100644 index 000000000000..7eb36a5bbf68 --- /dev/null +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics SA 2018 + * Author: Benjamin Gaignard for STMicroelectronics. + */ + +#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, "hsem"); + 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); + + 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 ");