From patchwork Sat Jul 20 12:01:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Austen X-Patchwork-Id: 13737808 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 275BA142642; Sat, 20 Jul 2024 12:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721476919; cv=none; b=aM5i15m0TMbniV4oaucTfjKuvtkHwHBOUNcWPLbQgxWf7XHbtTpPqtahJTAEaXtWLtgD4itj4xPm6fmp6PBoXs37kYTCl2yVdC/fqq1SWSMOlBAV0jv2JRYVOyxf1Dt4QQcOcANQFj7QNC25PXhfMizFJmGE0+l4CYBr9jnS1YQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721476919; c=relaxed/simple; bh=XOgrXmx36ocMe8yIaBXGwCdgaghYMUR0QuYNWB3MhaI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pRgBkW2lMv50rRBTf9yTtXAQhhe96I1kTJIkboGhkkML4Ix9XXQWz4Sl/9TjHl7ymBzgKrRfZHkLqCe3Hw6Zq7uG15WUXLSkjOSJOJqCwgkzXaAZitRRUwslyDsQblOeCA9Re+RG8U3PpVM8mRBSDWlcORXTCa/YixeclkwVByg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=XKRNFcLf; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="XKRNFcLf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1721476916; x=1721736116; bh=5jmaGGTO5BGOVrfoAL7oMQKQ1TobOvHpgQ3brd4v+V8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=XKRNFcLfw8O4t/3COaptXfuxp7td5eg23225dmSe9YqpnFh1h+dwJTl442VUXoN3H XztQjo7cCySyVdi0XDGVeEUdk0kb89cE85rTYvBKMaIHpfumi1O6E3eCgt+wqx/8KE qoZYkTcnOdeJZx0sMsLqi6bueW5cQxToDPB/yfSe2HINtqGLOAjJInrftyrLpIER28 f0jpdbY6N1YjY5sn9RUslXJvL6hJcggCkuEYZENnRp3BVnOfWQd/2TOxBfVSeXMk6C foAqNpO7IDpC4stg3v4h5z9WKfpXyF8vklBdq4neX1SAWnyJ6O7xCVwreRvp1m/I6e YrNzgnxwEDXAw== Date: Sat, 20 Jul 2024 12:01:53 +0000 To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michal Simek From: Harry Austen Cc: Shubhrajyoti Datta , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Harry Austen Subject: [PATCH 5/7] clk: clocking-wizard: add user clock monitor support Message-ID: <20240720120048.36758-6-hpausten@protonmail.com> In-Reply-To: <20240720120048.36758-1-hpausten@protonmail.com> References: <20240720120048.36758-1-hpausten@protonmail.com> Feedback-ID: 53116287:user:proton X-Pm-Message-ID: f88c42a272ee02b36f2b255480c94508f9b0f581 Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Xilinx clocking wizard IP core supports monitoring of up to four optional user clock inputs, with a corresponding interrupt for notification in change of clock state (stop, underrun, overrun or glitch). Give userspace access to this monitor logic through use of the UIO framework. Use presence of the user monitor interrupt description in devicetree to indicate whether or not the UIO device should be registered. Also, this functionality is only supported from v6.0 onwards, so add indication of support to the device match data, in order to be tied to the utilised compatible string. Signed-off-by: Harry Austen --- drivers/clk/xilinx/Kconfig | 1 + drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 67 ++++++++++++++++++++-- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/drivers/clk/xilinx/Kconfig b/drivers/clk/xilinx/Kconfig index 051756953558b..907a435694687 100644 --- a/drivers/clk/xilinx/Kconfig +++ b/drivers/clk/xilinx/Kconfig @@ -21,6 +21,7 @@ config COMMON_CLK_XLNX_CLKWZRD tristate "Xilinx Clocking Wizard" depends on OF depends on HAS_IOMEM + depends on UIO help Support for the Xilinx Clocking Wizard IP core clock generator. Adds support for clocking wizard and compatible. diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c index 7b262d73310fe..2d419e8ad4419 100644 --- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c +++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c @@ -20,10 +20,13 @@ #include #include #include +#include #define WZRD_NUM_OUTPUTS 7 #define WZRD_ACLK_MAX_FREQ 250000000UL +#define WZRD_INTR_ENABLE 0x10 + #define WZRD_CLK_CFG_REG(v, n) (0x200 + 0x130 * (v) + 4 * (n)) #define WZRD_CLKOUT0_FRAC_EN BIT(18) @@ -171,8 +174,9 @@ struct clk_wzrd_divider { spinlock_t *lock; /* divider lock */ }; -struct versal_clk_data { +struct clk_wzrd_data { bool is_versal; + bool supports_monitor; }; #define to_clk_wzrd(_nb) container_of(_nb, struct clk_wzrd, nb) @@ -958,16 +962,55 @@ static int __maybe_unused clk_wzrd_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(clk_wzrd_dev_pm_ops, clk_wzrd_suspend, clk_wzrd_resume); -static const struct versal_clk_data versal_data = { - .is_versal = true, +static const struct clk_wzrd_data version_6_0_data = { + .is_versal = false, + .supports_monitor = true, +}; + +static const struct clk_wzrd_data versal_data = { + .is_versal = true, + .supports_monitor = true, }; +static int clk_wzrd_irqcontrol(struct uio_info *info, s32 irq_on) +{ + if (irq_on) + iowrite32(GENMASK(15, 0), info->mem[0].internal_addr + WZRD_INTR_ENABLE); + else + iowrite32(0, info->mem[0].internal_addr + WZRD_INTR_ENABLE); + + return 0; +} + +static int clk_wzrd_setup_monitor(struct device *dev, int irq, const struct resource *res) +{ + struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev); + struct uio_info *info; + + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->name = KBUILD_MODNAME; + info->version = "0.0.1"; + + info->mem[0].name = "user monitor"; + info->mem[0].memtype = UIO_MEM_PHYS; + info->mem[0].addr = res->start; + info->mem[0].size = WZRD_INTR_ENABLE; + info->mem[0].internal_addr = clk_wzrd->base; + + info->irq = irq; + info->irqcontrol = clk_wzrd_irqcontrol; + return devm_uio_register_device(dev, info); +} + static int clk_wzrd_register_output_clocks(struct device *dev, int nr_outputs) { const char *clkout_name, *clk_name, *clk_mul_name; struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev); u32 regl, regh, edge, regld, reghd, edged, div; - const struct versal_clk_data *data; + const struct clk_wzrd_data *data; unsigned long flags = 0; bool is_versal = false; void __iomem *ctrl_reg; @@ -1127,10 +1170,11 @@ static int clk_wzrd_register_output_clocks(struct device *dev, int nr_outputs) static int clk_wzrd_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; + const struct clk_wzrd_data *data; struct clk_wzrd *clk_wzrd; unsigned long rate; int nr_outputs; - int ret; + int irq, ret; clk_wzrd = devm_kzalloc(&pdev->dev, sizeof(*clk_wzrd), GFP_KERNEL); if (!clk_wzrd) @@ -1165,6 +1209,17 @@ static int clk_wzrd_probe(struct platform_device *pdev) return -EINVAL; } + data = device_get_match_data(&pdev->dev); + if (data && data->supports_monitor) { + irq = platform_get_irq(pdev, 0); + if (irq > 0) { + ret = clk_wzrd_setup_monitor(&pdev->dev, irq, + platform_get_resource(pdev, IORESOURCE_IO, 0)); + if (ret) + return dev_err_probe(&pdev->dev, ret, "failed to setup monitor\n"); + } + } + ret = of_property_read_u32(np, "xlnx,nr-outputs", &nr_outputs); if (ret || nr_outputs > WZRD_NUM_OUTPUTS) return -EINVAL; @@ -1208,7 +1263,7 @@ static const struct of_device_id clk_wzrd_ids[] = { { .compatible = "xlnx,versal-clk-wizard", .data = &versal_data }, { .compatible = "xlnx,clocking-wizard" }, { .compatible = "xlnx,clocking-wizard-v5.2" }, - { .compatible = "xlnx,clocking-wizard-v6.0" }, + { .compatible = "xlnx,clocking-wizard-v6.0", .data = &version_6_0_data }, { }, }; MODULE_DEVICE_TABLE(of, clk_wzrd_ids);