Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1170596ybk; Sat, 16 May 2020 03:15:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy82Tlf1170xylFH/73pB4XmfV4Y+nUMwmcRWPdgQdnAiWOrHjQz/zFbYV56XwlFfDtHmaE X-Received: by 2002:a17:906:1659:: with SMTP id n25mr6958602ejd.122.1589624151854; Sat, 16 May 2020 03:15:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589624151; cv=none; d=google.com; s=arc-20160816; b=svkqK3fXwQD39Js9lCII+h2ytXkEpNwmaf4iuRclshyzeuPtxg51f+5NGcK/IiuBfi T3Bq6M/3XnLOgG/01DTSbPQNplnzmzRNpZmJ4V8qNNFHZC1UEBb5GQvY0ETNepypd7p/ 0Q4qciEe1mMXRVDDx7HgLmN1sfxW6ZRGFAjP8zo3M+giSOz+XQO4mvWCb8aI1QRCRc6q TPD2e4d1f1lt49c9m4BTjnqpBgK0bzdMM1A5taUmAvQVjBDhAa2LgGPc9lN9KhgfUfrP 6QDqSS5V//Tkp1Ih5G3JBc6jHQHf2qnYRY3gw735hquZ4WiYw/2j/5dFFa0aVTrHBHSc x02Q== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=RQl1P4szH3kWTsTLG3CehhmmEmneaN+4ongdk+HLtbg=; b=fRMd91ude2cD87CT8xKNvQMt/TUv5G38AjR21kcw+WpHMnJXi/94MqU3/JutC1/8Vx Fz60yLt5kjo0jbxiKhhT4GgaemUfSKe66/J2bmNOFvRcE8F3WwLH/PWDTGk5eUTt8lAQ UkrX0mG1ZvQlQgD1QnKN1z1rPML086qCtb3O9VnzKtBf8i83+gwq3xypdiznBT4G1Vx6 /DOTBkSzEO+Hx4hECy8bg2JsymT5m87sZAt9+BRmo3cvwFRVfb2/Dz6bC6OXGBTyeDuY 6tQDJbXQq42FVAVcC8ygaXt60v55YWP/txKKE850224y8sGIJOZWup/SEgwSU2xrAzAr Yh+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a2EwnWXu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me17si3029067ejb.410.2020.05.16.03.15.28; Sat, 16 May 2020 03:15:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a2EwnWXu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbgEPKNO (ORCPT + 99 others); Sat, 16 May 2020 06:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725853AbgEPKNN (ORCPT ); Sat, 16 May 2020 06:13:13 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 020DCC061A0C for ; Sat, 16 May 2020 03:13:13 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id a13so429417pls.8 for ; Sat, 16 May 2020 03:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=RQl1P4szH3kWTsTLG3CehhmmEmneaN+4ongdk+HLtbg=; b=a2EwnWXumzWFmtjiRec8COutadGxoC7GElipdSq2ttNFhcFY6DyLown1YioJJQ/6F/ Aqin+JUfJ9UeddHm1dk5mIeutirci5Deqay1ppaYyF9QOrYRbLpEwih3t9Et9+5T/ZYj uZXrA762bkNc9mvs39dEtB1/auY9Sfrh4Gh/7YJJaubH4t1WlFuQb8djlcggvduoK8fU YnX8vI9I/Glwz0+CWBdlv+CzovnF9IOmHJ0c1+To1Is1AObMBcI0xyWOHUZQRn8dsscC fLU1PC1u3muhNRCjF/JfuSeASVPdtG7vXvsOx7NW2YpZa1izpTG2iQwo7MUd37zVGFKP /3eg== 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:in-reply-to:references; bh=RQl1P4szH3kWTsTLG3CehhmmEmneaN+4ongdk+HLtbg=; b=rZIqgrCmCXoSFbswg/ss9xczVJtGJJ1xSIZ/zPZPxTmcL9o9yAcPVYDmMXjUEqdyOF P3k69++q1mexXRcgO4x+xa1FpF8bcjnjCuVwDgvj+/ondNQVhx/JNBZrLKsWpsD8q/Kp szi2Rfb/gw4YmN5Cbunkmx5B8h1z3jU2Rl3GPWKwlt1jx68fsTWbnu7PhaZbqPYCkzUa 3FdOKk9jsjBAOtSs66KEbjUbWqY4+ESUnXRCXjNrY/juGa/mwbZpe4yCLxrHhNs6l6jq t9U1uadjzvPnNhAeW/HohTsh/HrNbVz3cb7ufIkH1vOxv0j2xW7dg0WIkNhqeMiTIyeQ 5frA== X-Gm-Message-State: AOAM533m4H6jyQ44At1gyRG0db+QC6v/gD5ryvjQwi/v0pJ8UUASSzaV zGFOw3F4LmFAaaeoYhAdEyg= X-Received: by 2002:a17:90a:4d07:: with SMTP id c7mr8746446pjg.70.1589623992546; Sat, 16 May 2020 03:13:12 -0700 (PDT) Received: from localhost.localdomain ([45.135.186.16]) by smtp.gmail.com with ESMTPSA id x10sm3554542pgr.65.2020.05.16.03.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 May 2020 03:13:11 -0700 (PDT) From: Baolin Wang To: lee.jones@linaro.org, arnd@arndb.de Cc: broonie@kernel.org, baolin.wang7@gmail.com, orsonzhai@gmail.com, zhang.lyra@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] soc: sprd: Add Spreadtrum special bits updating support Date: Sat, 16 May 2020 18:12:29 +0800 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The spreadtrum platform uses a special set/clear method to update registers' bits, which can remove the race of updating the global registers between the multiple subsystems. Thus we can register a physical regmap bus into syscon core to support this. Signed-off-by: Baolin Wang --- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/sprd/Kconfig | 16 +++++++ drivers/soc/sprd/Makefile | 2 + drivers/soc/sprd/sprd_syscon.c | 86 ++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 drivers/soc/sprd/Kconfig create mode 100644 drivers/soc/sprd/Makefile create mode 100644 drivers/soc/sprd/sprd_syscon.c diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index 425ab6f7e375..8cfbf2dc518d 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -23,5 +23,6 @@ source "drivers/soc/versatile/Kconfig" source "drivers/soc/xilinx/Kconfig" source "drivers/soc/zte/Kconfig" source "drivers/soc/kendryte/Kconfig" +source "drivers/soc/sprd/Kconfig" endmenu diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 36452bed86ef..7d156a6dd536 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -29,3 +29,4 @@ obj-$(CONFIG_PLAT_VERSATILE) += versatile/ obj-y += xilinx/ obj-$(CONFIG_ARCH_ZX) += zte/ obj-$(CONFIG_SOC_KENDRYTE) += kendryte/ +obj-$(CONFIG_ARCH_SPRD) += sprd/ diff --git a/drivers/soc/sprd/Kconfig b/drivers/soc/sprd/Kconfig new file mode 100644 index 000000000000..38d1f5971a28 --- /dev/null +++ b/drivers/soc/sprd/Kconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# SPRD SoC drivers +# + +menu "Spreadtrum SoC drivers" + depends on ARCH_SPRD || COMPILE_TEST + +config SPRD_SYSCON + tristate "Spreadtrum syscon support" + depends on ARCH_SPRD || COMPILE_TEST + help + Say yes here to add support for the Spreadtrum syscon driver, + which is used to implement the atomic method of bits updating. + +endmenu diff --git a/drivers/soc/sprd/Makefile b/drivers/soc/sprd/Makefile new file mode 100644 index 000000000000..4d7715553cf6 --- /dev/null +++ b/drivers/soc/sprd/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SPRD_SYSCON) += sprd_syscon.o diff --git a/drivers/soc/sprd/sprd_syscon.c b/drivers/soc/sprd/sprd_syscon.c new file mode 100644 index 000000000000..cdc326ef94e5 --- /dev/null +++ b/drivers/soc/sprd/sprd_syscon.c @@ -0,0 +1,86 @@ +//SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Spreadtrum Communications Inc. + */ +#include +#include +#include +#include +#include +#include + +#define SPRD_REG_SET_OFFSET 0x1000 +#define SPRD_REG_CLR_OFFSET 0x2000 + +/* + * The Spreadtrum platform defines a special set/clear method to update + * registers' bits, which means it can write values to the register's SET + * address (offset is 0x1000) to set bits, and write values to the register's + * CLEAR address (offset is 0x2000) to clear bits. + * + * This set/clear method can help to remove the race of accessing the global + * registers between the multiple subsystems instead of using hardware + * spinlocks. + * + * Note: there is a potential risk when users want to set and clear bits + * at the same time, since the set/clear method will always do bits setting + * before bits clearing, which may cause some unexpected results if the + * operation sequence is strict. Thus we recommend that do not set and + * clear bits at the same time if you are not sure about the results. + */ +static int sprd_syscon_update_bits(void *context, unsigned int reg, + unsigned int mask, unsigned int val) +{ + void __iomem *base = context; + unsigned int set, clr; + + set = val & mask; + clr = ~set & mask; + + if (set) + writel(set, base + reg + SPRD_REG_SET_OFFSET); + + if (clr) + writel(clr, base + reg + SPRD_REG_CLR_OFFSET); + + WARN_ONCE(set && clr, "%s: non-atomic update", __func__); + return 0; +} + +static int sprd_syscon_read(void *context, unsigned int reg, unsigned int *val) +{ + void __iomem *base = context; + + *val = readl(base + reg); + return 0; +} + +static int sprd_syscon_write(void *context, unsigned int reg, unsigned int val) +{ + void __iomem *base = context; + + writel(val, base + reg); + return 0; +} + +static struct regmap_bus sprd_syscon_regmap = { + .fast_io = true, + .reg_write = sprd_syscon_write, + .reg_read = sprd_syscon_read, + .reg_update_bits = sprd_syscon_update_bits, + .val_format_endian_default = REGMAP_ENDIAN_LITTLE, +}; + +struct regmap *syscon_regmap_init(struct device_node *np, void __iomem *base, + struct regmap_config *syscon_config) +{ + if (of_device_is_compatible(np, "sprd,atomic-syscon")) + return regmap_init(NULL, &sprd_syscon_regmap, base, + syscon_config); + + return regmap_init_mmio(NULL, base, syscon_config); +} + +MODULE_DESCRIPTION("Spreadtrum syscon support"); +MODULE_AUTHOR("Baolin Wang "); +MODULE_LICENSE("GPL v2"); -- 2.17.1