From patchwork Fri Jun 21 11:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 13707428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DF93CC2BA1A for ; Fri, 21 Jun 2024 11:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YyW5+VbIADwYbvLjE/DRg3OiI2Mx9SABmjT69Y7dUKk=; b=A+5ySUv2VEe7g+x6QZnYc36++j //f5WVEkC4n6x4fnJgGdCHPDfVef3gfqxayF54Viwz467wnK4wVN7S/ia4Qa7Si5c6wC845+2xl6P sjQeNZKrVO4vPM/6c1NmhXw20U6LcQ1yObFkZqo75vDMBiX+hXVrhYbZIyopiI8MxPbe7rfetq+Zl T/lvMaRoNLtv++ngtFUpPpSVM1kiV+usDwZD9K6IyvaEczGWiwazj9/ikZBOYzNZxG6LAW6MpLvWd Ressx2t8VV7ysEeYlz+ZV+5cBtI2lza3bPR0ltg2de+o8QozodZXeuOnbdBTfMCwEbpshaogCpR1q 0tBeAzfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKcry-000000091vM-40Un; Fri, 21 Jun 2024 11:55:54 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKcrv-000000091tz-0Ekm for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 11:55:52 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2ec50d4e47bso3428801fa.2 for ; Fri, 21 Jun 2024 04:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718970949; x=1719575749; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YyW5+VbIADwYbvLjE/DRg3OiI2Mx9SABmjT69Y7dUKk=; b=ZOmQyyfIVVibcO2kooxiTerzBbTYfp+88GKaeU3RynohOPROzm8ObUq5u6zhs/fBpT ZyBe8FwqLYoVwuxsxuV0Qab9Cq2qSesgB+uNJbc02m6bE5YXalWG7iO64AqvOwRLOFoe oY/1twM2EdaaPdPC7UUUDP/9WOUI+XeG5vTr9i6QzTzV37KD18j281khqFDF7XlPOsjz IxUH4ZTCqYpM5+8gnlsSaRO7VzsJ9zVO011hZbje+fgCIbPv1UJKQ5un6PpSHaKnvdpZ M5SBlFR8JW19TakZwEh7A1ORhCoBPENejmpRFzPCCTr7Kz3Gw1QTaIZDytba2Mp7VQAS CYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718970949; x=1719575749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YyW5+VbIADwYbvLjE/DRg3OiI2Mx9SABmjT69Y7dUKk=; b=B3xgbGiX3/zamzvb/CcN1QswymuXDx7ot+7ct47scoY62a2aA8BrFaD0cVdec4weku ZwiENE2y8jF3b3Vbi8epmGe95bXuOHC2GS6QKzOFJlVOYv4udQie34EMUyFdmL8DxeLj tLDjBedIGSipHthX4CyCe317jZse+HO33tx29CK5XIkdJhFo1qRMv6Ul3Y4NvleHivug cQN0DNWO2oWI6/Zj72JNWdgXGb4CqigZ22axjbcIUsKvHQZcDMyo9I0PZ7blZlGoQmNF l7cgbY8iKwuXw+1hIPCukTaCryyFJthq8VLD89/88pll90hXqZNxgJAG6qQYrADaNp02 sJyQ== X-Gm-Message-State: AOJu0YzaHOKbOcRaveqt4/D5HEcS1gcQrgGRBJh2xzvhRz8moLEFrOi1 A6T1n4rEKyOHpuz2pYnqg6/Xm+Ec/cUx1epXWdGxJ2xUo7je0m6/Y57S0kpTqh8= X-Google-Smtp-Source: AGHT+IEK99mzL+zVK5iwlAts85kqCZbOM80etX+4cRw1BqvCAihCDCG8nvU55FlE1jsMiBzfFG2c3A== X-Received: by 2002:a05:6512:e98:b0:52c:cb97:ebba with SMTP id 2adb3069b0e04-52ccb97ec44mr6156327e87.24.1718970948984; Fri, 21 Jun 2024 04:55:48 -0700 (PDT) Received: from gpeter-l.lan ([2a0d:3344:2e8:8510::3aa]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208dcesm60386725e9.31.2024.06.21.04.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 04:55:48 -0700 (PDT) From: Peter Griffin To: lee@kernel.org, arnd@arndb.de, krzk@kernel.org, alim.akhtar@samsung.com Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org, andre.draszik@linaro.org, saravanak@google.com, willmcvicker@google.com, semen.protsenko@linaro.org, kernel-team@android.com, Peter Griffin Subject: [PATCH v3 1/2] mfd: syscon: add of_syscon_register_regmap() API Date: Fri, 21 Jun 2024 12:55:43 +0100 Message-ID: <20240621115544.1655458-2-peter.griffin@linaro.org> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog In-Reply-To: <20240621115544.1655458-1-peter.griffin@linaro.org> References: <20240621115544.1655458-1-peter.griffin@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_045551_119246_5AFF86E3 X-CRM114-Status: GOOD ( 20.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The of_syscon_register_regmap() API allows an externally created regmap to be registered with syscon. This regmap can then be returned to client drivers using the syscon_regmap_lookup_by_phandle() APIs. The API is used by platforms where mmio access to the syscon registers is not possible, and a underlying soc driver like exynos-pmu provides a SoC specific regmap that can issue a SMC or hypervisor call to write the register. This approach keeps the SoC complexities out of syscon, but allows common drivers such as syscon-poweroff, syscon-reboot and friends that are used by many SoCs already to be re-used. Signed-off-by: Peter Griffin Reviewed-by: Arnd Bergmann Reviewed-by: Sam Protsenko Tested-by: Will McVicker Reviewed-by: Krzysztof Kozlowski --- Changes in v3: - Move kzalloc allocation outside of spin lock (Arnd) - Link to v2 https://lore.kernel.org/linux-arm-kernel/20240620112446.1286223-2-peter.griffin@linaro.org/ Changes in v2: - Keep syscon lock held between checking and adding entry (Krzysztof) - Link to v1 https://lore.kernel.org/linux-arm-kernel/20240614140421.3172674-2-peter.griffin@linaro.org/ --- drivers/mfd/syscon.c | 48 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 8 +++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 7d0e91164cba..33f1e07ab24d 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -192,6 +192,54 @@ static struct regmap *device_node_get_regmap(struct device_node *np, return syscon->regmap; } +/** + * of_syscon_register_regmap() - Register regmap for specified device node + * @np: Device tree node + * @regmap: Pointer to regmap object + * + * Register an externally created regmap object with syscon for the specified + * device tree node. This regmap will then be returned to client drivers using + * the syscon_regmap_lookup_by_phandle() API. + * + * Return: 0 on success, negative error code on failure. + */ +int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap) +{ + struct syscon *entry, *syscon = NULL; + int ret; + + if (!np || !regmap) + return -EINVAL; + + syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); + if (!syscon) + return -ENOMEM; + + /* check if syscon entry already exists */ + spin_lock(&syscon_list_slock); + + list_for_each_entry(entry, &syscon_list, list) + if (entry->np == np) { + ret = -EEXIST; + goto err_unlock; + } + + syscon->regmap = regmap; + syscon->np = np; + + /* register the regmap in syscon list */ + list_add_tail(&syscon->list, &syscon_list); + spin_unlock(&syscon_list_slock); + + return 0; + +err_unlock: + spin_unlock(&syscon_list_slock); + kfree(syscon); + return ret; +} +EXPORT_SYMBOL_GPL(of_syscon_register_regmap); + struct regmap *device_node_to_regmap(struct device_node *np) { return device_node_get_regmap(np, false); diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index c315903f6dab..aad9c6b50463 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -28,6 +28,8 @@ struct regmap *syscon_regmap_lookup_by_phandle_args(struct device_node *np, unsigned int *out_args); struct regmap *syscon_regmap_lookup_by_phandle_optional(struct device_node *np, const char *property); +int of_syscon_register_regmap(struct device_node *np, + struct regmap *regmap); #else static inline struct regmap *device_node_to_regmap(struct device_node *np) { @@ -67,6 +69,12 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_optional( return NULL; } +static inline int of_syscon_register_regmap(struct device_node *np, + struct regmap *regmap) +{ + return -EOPNOTSUPP; +} + #endif #endif /* __LINUX_MFD_SYSCON_H__ */