From patchwork Fri Jun 14 07:19:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13697971 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 B35B9C2BA15 for ; Fri, 14 Jun 2024 07:20:17 +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=4TwzmK6wu9zm3cDBCz3PFUOjizlSmEgRc0oDvfVQTQY=; b=Ocyszg6xb5eQ1tiv3WQDJHzhaz r/UhpjDVv/prIyUeSQGL9pwZIOglFawvA7ZbHx1EHBK/tCJLg0rHsPETw8/Xv6DRwApZqrgH67DZi bzke6cOPj1jfrNV6e6CgpgvEmn/0NCI5UfbJzMPp5MfTZU83IZcSFS64YMA6thQWHcycu8pVLztYh 7UAIhNXJZhpJBIOlCCySqg8V5mPU/zCWwJduz1OKpVGXdjl+PBjDmb3FVf8JWqQj/7RRh3zQk+noz y8pJT3LFCDyKiBmiHwjKaJwtOf3SDDzyAfQIcKlVUaW4Jhoox6h4sGi80uFhAjfMolWjT007dpX/F LvHtVNmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI1ED-00000001jUe-000t; Fri, 14 Jun 2024 07:20:05 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI1E6-00000001jQ6-0ZPt for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 07:19:59 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-52c525257feso2368718e87.1 for ; Fri, 14 Jun 2024 00:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1718349596; x=1718954396; 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=4TwzmK6wu9zm3cDBCz3PFUOjizlSmEgRc0oDvfVQTQY=; b=Zo3xl43vngCYtDatMI9PUERPFn+9C4kmW46n4kSULT7EX6HmztrE/p0IQwIlk125UG uPXNqgFGTlZ6s/503oPV1kyHHPFvnWAM3JR5wNWrldUag6XQTM9FjY8rxD5h0lxfRXD4 P2jCzDrPkWHkMf+9TykNAqkiSV9jskBDc1GD1ypiWhlO9pKHKLLvjEceAUru532kvRwG doamIf6uc1moWnZ0SdFvss2XZFCuOWzHcgh/p8VmqGyRocEpgw8SO/JWUPJA5MJ5j9a9 lL6y3EjXToJVTEqOX9OAnpv+NNghDO4+Vw9pfxd0+7ek9tKz/u/YS3t6bA26FHTBjVuE d4aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718349596; x=1718954396; 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=4TwzmK6wu9zm3cDBCz3PFUOjizlSmEgRc0oDvfVQTQY=; b=XhzJyZ06EbRR3NiiEBMd0ju2CLXC6pNML/OLXdEVSV8dlJiSv3JsWlna4cXSzwK8aJ tLwf6QKZOy3MioBpZXAeqZY7mQT+/7Rrn1Ds4qti2taWQ20K6OwQSHMbZlaH7Uekzdg1 v1d3bo7XnHGz20h4V7NzsMX/eRKVMFIWzahA3CoRy/Y+jDPFdoW6ZWouLXdtcpinMDgC n0tuiani4ivs+3X45MkrsC1VPPOGuT13+u7JGm7y0zklEvebI7p/f7CUAyoVfTg8T0I4 wIvCruR93qmLDi1nz3bE0K1Zqwqf/xnJ7A6r51HolmJKxCWZZ+8R0VOnIWHN3LK+3VU6 q7kg== X-Forwarded-Encrypted: i=1; AJvYcCWKmuXtDcD52PA1G0dXZ1K/rMPb+tPzk+q6yev1MP8lZRn+JL86hb95M+FOL8AcqScUOoHvYrQ2C51IjjA0qi86erzZp9UibtFBhzjJrCeGnhihRIM= X-Gm-Message-State: AOJu0YwLxWjdTqqXqwIfIQImt7KqCicUEfngGI8sWBAANfjEwFS4YS4Q dXdakO9gcE/B4LSkKDn99l/1+MgPxKE0PMin7jO5f37H5Axd7OeMKaGoLjHCAOY= X-Google-Smtp-Source: AGHT+IEkRyLEr340Rwpfq72yYbGglbHdtExlmdcIVFwIxZNQRwzK7ZbbzF4tgxXpzngXHiqUzVu8cg== X-Received: by 2002:ac2:57c3:0:b0:52b:c292:f7c with SMTP id 2adb3069b0e04-52ca6e9886emr1049235e87.62.1718349596425; Fri, 14 Jun 2024 00:19:56 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.189]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42286eef9eesm87272555e9.9.2024.06.14.00.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 00:19:55 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: geert+renesas@glider.be, mturquette@baylibre.com, sboyd@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, lee@kernel.org, alexandre.belloni@bootlin.com, magnus.damm@gmail.com Cc: linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, claudiu.beznea@tuxon.dev, Claudiu Beznea Subject: [PATCH 04/12] clk: renesas: clk-vbattb: Add VBATTB clock driver Date: Fri, 14 Jun 2024 10:19:24 +0300 Message-Id: <20240614071932.1014067-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240614071932.1014067-1-claudiu.beznea.uj@bp.renesas.com> References: <20240614071932.1014067-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_001958_222726_DFA10C4D X-CRM114-Status: GOOD ( 23.52 ) 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 From: Claudiu Beznea The VBATTB IP of the Renesas RZ/G3S SoC controls the clock that is used by the RTC. The input to the VBATTB could be a 32KHz crystal connected to both the RTXIN and RTXOUT pins or an external clock connected to RTXOUT pin. In case an external clock is connected to the RTXOUT pin the renesas,vbattb-osc-bypass DT property need to be used when describing the node. The load capacitance of the on-board oscillator need to be configured with renesas,vbattb-load-nanofarads DT property. Signed-off-by: Claudiu Beznea --- drivers/clk/renesas/Kconfig | 4 + drivers/clk/renesas/Makefile | 1 + drivers/clk/renesas/clk-vbattb.c | 202 +++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 drivers/clk/renesas/clk-vbattb.c diff --git a/drivers/clk/renesas/Kconfig b/drivers/clk/renesas/Kconfig index d252150402e8..1dc38e3a8326 100644 --- a/drivers/clk/renesas/Kconfig +++ b/drivers/clk/renesas/Kconfig @@ -228,6 +228,10 @@ config CLK_RZG2L bool "Renesas RZ/{G2L,G2UL,G3S,V2L} family clock support" if COMPILE_TEST select RESET_CONTROLLER +config CLK_VBATTB + bool "Renesas VBATTB clock controller" + select RESET_CONTROLLER + # Generic config CLK_RENESAS_CPG_MSSR bool "CPG/MSSR clock support" if COMPILE_TEST diff --git a/drivers/clk/renesas/Makefile b/drivers/clk/renesas/Makefile index f7e18679c3b8..e9e487f53577 100644 --- a/drivers/clk/renesas/Makefile +++ b/drivers/clk/renesas/Makefile @@ -51,3 +51,4 @@ obj-$(CONFIG_CLK_RZG2L) += rzg2l-cpg.o obj-$(CONFIG_CLK_RENESAS_CPG_MSSR) += renesas-cpg-mssr.o obj-$(CONFIG_CLK_RENESAS_CPG_MSTP) += clk-mstp.o obj-$(CONFIG_CLK_RENESAS_DIV6) += clk-div6.o +obj-$(CONFIG_CLK_VBATTB) += clk-vbattb.o diff --git a/drivers/clk/renesas/clk-vbattb.c b/drivers/clk/renesas/clk-vbattb.c new file mode 100644 index 000000000000..0a5cc886e89c --- /dev/null +++ b/drivers/clk/renesas/clk-vbattb.c @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * VBATTB clock driver + * + * Copyright (C) 2024 Renesas Electronics Corp. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define VBATTB_BKSCCR 0x1c +#define VBATTB_BKSCCR_SOSEL BIT(6) +#define VBATTB_SOSCCR2 0x24 +#define VBATTB_SOSCCR2_SOSTP2 BIT(0) +#define VBATTB_XOSCCR 0x30 +#define VBATTB_XOSCCR_OUTEN BIT(16) +#define VBATTB_XOSCCR_XSEL GENMASK(1, 0) +#define VBATTB_XOSCCR_XSEL_4_PF 0x0 +#define VBATTB_XOSCCR_XSEL_7_PF 0x1 +#define VBATTB_XOSCCR_XSEL_9_PF 0x2 +#define VBATTB_XOSCCR_XSEL_12_5_PF 0x3 + +/** + * struct vbattb_clk - VBATTB clock data structure + * @regmap: regmap + * @hw: clk hw + * @lock: device lock + * @load_capacitance: load capacitance + */ +struct vbattb_clk { + struct regmap *regmap; + struct clk_hw hw; + spinlock_t lock; + u8 load_capacitance; +}; + +#define to_vbattb_clk(_hw) container_of(_hw, struct vbattb_clk, hw) + +static int vbattb_clk_enable(struct clk_hw *hw) +{ + struct vbattb_clk *vbclk = to_vbattb_clk(hw); + struct regmap *regmap = vbclk->regmap; + + spin_lock(&vbclk->lock); + regmap_update_bits(regmap, VBATTB_SOSCCR2, VBATTB_SOSCCR2_SOSTP2, 0); + regmap_update_bits(regmap, VBATTB_XOSCCR, VBATTB_XOSCCR_OUTEN | VBATTB_XOSCCR_XSEL, + VBATTB_XOSCCR_OUTEN | vbclk->load_capacitance); + spin_unlock(&vbclk->lock); + + return 0; +} + +static void vbattb_clk_disable(struct clk_hw *hw) +{ + struct vbattb_clk *vbclk = to_vbattb_clk(hw); + struct regmap *regmap = vbclk->regmap; + + spin_lock(&vbclk->lock); + regmap_update_bits(regmap, VBATTB_XOSCCR, VBATTB_XOSCCR_OUTEN, 0); + regmap_update_bits(regmap, VBATTB_SOSCCR2, VBATTB_SOSCCR2_SOSTP2, VBATTB_SOSCCR2_SOSTP2); + spin_unlock(&vbclk->lock); +} + +static int vbattb_clk_is_enabled(struct clk_hw *hw) +{ + struct vbattb_clk *vbclk = to_vbattb_clk(hw); + struct regmap *regmap = vbclk->regmap; + unsigned int xosccr, sosccr2; + int ret; + + spin_lock(&vbclk->lock); + ret = regmap_read(regmap, VBATTB_XOSCCR, &xosccr); + if (ret) + goto unlock; + + ret = regmap_read(regmap, VBATTB_SOSCCR2, &sosccr2); +unlock: + spin_unlock(&vbclk->lock); + + if (ret) + return 0; + + return ((xosccr & VBATTB_XOSCCR_OUTEN) && !(sosccr2 & VBATTB_SOSCCR2_SOSTP2)); +} + +static const struct clk_ops vbattb_clk_ops = { + .enable = vbattb_clk_enable, + .disable = vbattb_clk_disable, + .is_enabled = vbattb_clk_is_enabled, +}; + +static int vbattb_clk_validate_load_capacitance(struct vbattb_clk *vbclk, u32 load_capacitance) +{ + switch (load_capacitance) { + case 4000: + vbclk->load_capacitance = VBATTB_XOSCCR_XSEL_4_PF; + break; + case 7000: + vbclk->load_capacitance = VBATTB_XOSCCR_XSEL_7_PF; + break; + case 9000: + vbclk->load_capacitance = VBATTB_XOSCCR_XSEL_9_PF; + break; + case 12500: + vbclk->load_capacitance = VBATTB_XOSCCR_XSEL_12_5_PF; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int vbattb_clk_probe(struct platform_device *pdev) +{ + struct clk_parent_data parent_data = { .fw_name = "vbattb_xtal" }; + struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct clk_init_data init = {}; + struct vbattb_clk *vbclk; + u32 load_capacitance; + struct clk_hw *hw; + bool bypass; + int ret; + + vbclk = devm_kzalloc(dev, GFP_KERNEL, sizeof(*vbclk)); + if (!vbclk) + return -ENOMEM; + + vbclk->regmap = syscon_node_to_regmap(np->parent); + if (IS_ERR(vbclk->regmap)) + return PTR_ERR(vbclk->regmap); + + bypass = of_property_read_bool(np, "renesas,vbattb-osc-bypass"); + ret = of_property_read_u32(np, "renesas,vbattb-load-nanofarads", &load_capacitance); + if (ret) + return ret; + + ret = vbattb_clk_validate_load_capacitance(vbclk, load_capacitance); + if (ret) + return ret; + + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + ret = pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + regmap_update_bits(vbclk->regmap, VBATTB_BKSCCR, VBATTB_BKSCCR_SOSEL, + bypass ? VBATTB_BKSCCR_SOSEL : 0); + + init.name = "vbattclk"; + init.ops = &vbattb_clk_ops; + init.parent_data = &parent_data; + init.num_parents = 1; + init.flags = 0; + + vbclk->hw.init = &init; + hw = &vbclk->hw; + + spin_lock_init(&vbclk->lock); + + ret = devm_clk_hw_register(dev, hw); + if (ret) + goto rpm_put; + + ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); + if (ret) + goto rpm_put; + + return 0; + +rpm_put: + pm_runtime_put(dev); + return ret; +} + +static const struct of_device_id vbattb_clk_match[] = { + { .compatible = "renesas,rzg3s-vbattb-clk" }, + { /* sentinel */ } +}; + +static struct platform_driver vbattb_clk_driver = { + .driver = { + .name = "vbattb-clk", + .of_match_table = vbattb_clk_match, + }, + .probe = vbattb_clk_probe, +}; +module_platform_driver(vbattb_clk_driver); + +MODULE_DESCRIPTION("Renesas VBATTB Clock Driver"); +MODULE_AUTHOR("Claudiu Beznea "); +MODULE_LICENSE("GPL");