From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C237CC352A3 for ; Tue, 11 Feb 2020 12:27:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 925E420714 for ; Tue, 11 Feb 2020 12:27:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="D44SJaAm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 925E420714 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VqrOcuSCDCNB2AoTIdlL4/kWcF0LKQapISIxRIqeLWw=; b=D44SJaAmsyjGb3rO/N8F+D9t4I o3GkByd3HdZ+H2m5YyDQnsN9ItZ1sYQuBwjfa0raaV/LAIFaDPFLfwZ/WdC0YhXTQsyjrEwflxZl4 v1QqiHnfGMTFM7kKWLRm1Lx/uNq0xopIMlSabrdd5nyeDbp8vlS3DBkkRIyDdqGOSowlM96goOvRm ABwawwHPup9ww/a9PgU8Dk7rGad6xwF9MYnsyqYmvLIkiyCJtnFNdUIWk4FjgTjNJdScL1IOEAkd5 K7xopqzou8Q93t/LJbUiJ+NgZKkeZZn5QVclnVzPaDw9+CVjxhZ2gyJOvlaXQcvMJDoePDf4En5va PTEqtyIg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j1UdB-00042z-OU; Tue, 11 Feb 2020 12:27:09 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j1Ucb-0003SS-DO for linux-arm-kernel@lists.infradead.org; Tue, 11 Feb 2020 12:26:36 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3D7DEAFB2; Tue, 11 Feb 2020 12:26:31 +0000 (UTC) From: Nikolay Borisov To: mripard@kernel.org, bjorn.andersson@linaro.org Subject: [PATCH v2 1/3] hwspinlock: sunxi: Implement support for Allwinner's A64 SoC Date: Tue, 11 Feb 2020 14:26:22 +0200 Message-Id: <20200211122624.16484-2-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200211122624.16484-1-nborisov@suse.com> References: <20200211122624.16484-1-nborisov@suse.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200211_042633_766485_B8BAA33D X-CRM114-Status: GOOD ( 18.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nikolay Borisov , devicetree@vger.kernel.org, wens@csie.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Based on the datasheet this implements support for the hwspinlock IP block. Signed-off-by: Nikolay Borisov --- drivers/hwspinlock/Kconfig | 9 ++ drivers/hwspinlock/Makefile | 1 + drivers/hwspinlock/sun50i_hwspinlock.c | 163 +++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 drivers/hwspinlock/sun50i_hwspinlock.c diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index 37740e992cfa..aff39bad3e90 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -68,3 +68,12 @@ config HSEM_U8500 SoC. If unsure, say N. + +config HWSPINLOCK_SUN50I + tristate "Allwinner Hardware Spinlock device" + depends on ARCH_SUNXI + depends on HWSPINLOCK + help + Say y here to support the SUNXI Hardware Spinlock device. + + If unsure, say N. diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile index ed053e3f02be..ebabe5c7b7ef 100644 --- a/drivers/hwspinlock/Makefile +++ b/drivers/hwspinlock/Makefile @@ -8,5 +8,6 @@ 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_SUN50I) += sun50i_hwspinlock.o obj-$(CONFIG_HWSPINLOCK_STM32) += stm32_hwspinlock.o obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o diff --git a/drivers/hwspinlock/sun50i_hwspinlock.c b/drivers/hwspinlock/sun50i_hwspinlock.c new file mode 100644 index 000000000000..2b54c0a0148d --- /dev/null +++ b/drivers/hwspinlock/sun50i_hwspinlock.c @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Author: Nikolay Borisov */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hwspinlock_internal.h" + +/* Bits containing number of locks in SPINLOCK_SYSSTATUS_REG */ +#define SPINLOCK_LOCKS_NUM GENMASK(29, 28) + +/* Spinlock register offsets */ +#define SPINLOCK_ID(X) (0x100 + 0x4 * X) + +/* Possible values of SPINLOCK_LOCK_REG */ +#define SPINLOCK_NOTTAKEN (0) /* free */ +#define SPINLOCK_TAKEN (1) /* locked */ + +struct sun50i_hwspinlock { + struct clk *clk; + struct reset_control *reset; + struct hwspinlock_device *bank; +}; + +static int sun50i_hwspinlock_trylock(struct hwspinlock *lock) +{ + void __iomem *lock_addr = lock->priv; + + /* attempt to acquire the lock by reading its value */ + return readl(lock_addr) == SPINLOCK_NOTTAKEN; +} + +static void sun50i_hwspinlock_unlock(struct hwspinlock *lock) +{ + void __iomem *lock_addr = lock->priv; + + /* release the lock by writing 0 to it */ + writel(SPINLOCK_NOTTAKEN, lock_addr); +} + +static const struct hwspinlock_ops sun50i_hwspinlock_ops = { + .trylock = sun50i_hwspinlock_trylock, + .unlock = sun50i_hwspinlock_unlock, +}; + +static int sun50i_get_num_locks(void __iomem *io_base) +{ + u32 i = readl(io_base); + i = FIELD_GET(SPINLOCK_LOCKS_NUM, i); + + switch (i) { + case 0x1: return 32; + case 0x2: return 64; + case 0x3: return 128; + case 0x4: return 256; + } + + return 0; +} + +static int sun50i_hwspinlock_probe(struct platform_device *pdev) +{ + struct sun50i_hwspinlock *hw; + void __iomem *io_base; + struct clk *clk; + struct reset_control *reset; + int i, ret, num_locks; + + io_base = devm_platform_ioremap_resource(&pdev->dev, 0); + if (IS_ERR(io_base)) + return PTR_ERR(io_base); + + hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); + if (!hw) + return -ENOMEM; + + hw->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(hw->clk)) + return PTR_ERR(hw->clk); + + ret = clk_prepare_enable(hw->clk); + if (ret) { + dev_err(&pdev->dev, "Cannot enable clock\n"); + return ret; + } + + /* Disable soft reset */ + hw->reset= devm_reset_control_get_exclusive(&pdev->dev, NULL); + if (IS_ERR(hw->reset)) { + clk_disable_unprepare(hw->clk); + return PTR_ERR(hw->reset); + } + reset_control_deassert(hw->reset); + + ret = devm_add_action_or_reset(&pdev->dev, sun50i_hwpinlock_disable, + hw); + if (ret) { + dev_err(&pdev->dev, "Failed to add hwspinlock disable action\n"); + return ret; + } + + num_locks = sun50i_get_num_locks(io_base); + if (!num_locks) { + dev_err(&pdev->dev, "Unrecognised sun50i hwspinlock device\n"); + ret = -EINVAL; + goto out_reset; + } + + hw->bank = devm_kzalloc(&pdev->dev, + struct_size(hw->bank, lock, num_locks), + GFP_KERNEL); + if (!hw) { + ret = -ENOMEM; + goto out_reset; + } + + for (i = 0; i < num_locks; i++) + hw->bank.lock[i].priv = io_base + SPINLOCK_ID(i); + + platform_set_drvdata(pdev, hw); + + return devm_hwspin_lock_register(&pdev->dev, &hw->bank, + &sun50i_hwspinlock_ops, 0, num_locks); +} + +static int sun50i_hwspinlock_disable(struct platform_device *pdev) +{ + struct sun50i_hwspinlock *hw = platform_get_drvdata(pdev); + int ret; + + reset_control_assert(hw->reset); + clk_disable_unprepare(hw->clk); + + return 0; +} + +static const struct of_device_id sun50i_hwpinlock_ids[] = { + { .compatible = "allwinner,sun50i-a64-hwspinlock", }, + {}, +}; +MODULE_DEVICE_TABLE(of, sun50i_hwpinlock_ids); + +static struct platform_driver sun50i_hwspinlock_driver = { + .probe = sun50i_hwspinlock_probe, + .driver = { + .name = "sun50i_hwspinlock", + .of_match_table = sun50i_hwpinlock_ids, + }, +}; + +module_platform_driver(sun50i_hwspinlock_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Hardware spinlock driver for sun50i SoCs"); +MODULE_AUTHOR("Nikolay Borisov "); -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel