Linux-Clk Archive on lore.kernel.org
 help / Atom feed
* [PATCH v2 0/2] clk: Add driver and bindings for Fixed MMIO clock
@ 2018-12-13 12:49 Jan Kotas
  2018-12-13 12:49 ` [PATCH v2 1/2] dt-bindings: clk: Add " Jan Kotas
  2018-12-13 12:49 ` [PATCH v2 2/2] clk: Add Fixed MMIO clock driver Jan Kotas
  0 siblings, 2 replies; 6+ messages in thread
From: Jan Kotas @ 2018-12-13 12:49 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, mark.rutland
  Cc: linux-clk, devicetree, linux-kernel, Jan Kotas

This patchset adds a driver support for Fixed Memory Mapped IO clock.

The driver reads a clock frequency value from a single 32-bit memory
mapped register and registers it as a fixed rate clock.

It can be useful for prototyping Linux on various hardware platforms.
It is not intended to be used on finished, complete SoCs.

Changes since V1:
	Added platform driver support.
	Removed unnecessary messages.

Jan Kotas (2):
  dt-bindings: clk: Add bindings for Fixed MMIO clock
  clk: Add Fixed MMIO clock driver

 .../devicetree/bindings/clock/fixed-mmio-clock.txt |  24 +++++
 drivers/clk/Kconfig                                |   6 ++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-fixed-mmio.c                       | 109 +++++++++++++++++++++
 4 files changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/fixed-mmio-clock.txt
 create mode 100644 drivers/clk/clk-fixed-mmio.c

-- 
2.15.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] dt-bindings: clk: Add bindings for Fixed MMIO clock
  2018-12-13 12:49 [PATCH v2 0/2] clk: Add driver and bindings for Fixed MMIO clock Jan Kotas
@ 2018-12-13 12:49 ` " Jan Kotas
  2019-01-09 19:42   ` Stephen Boyd
  2018-12-13 12:49 ` [PATCH v2 2/2] clk: Add Fixed MMIO clock driver Jan Kotas
  1 sibling, 1 reply; 6+ messages in thread
From: Jan Kotas @ 2018-12-13 12:49 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, mark.rutland
  Cc: linux-clk, devicetree, linux-kernel, Jan Kotas

This patch adds a DT binding documentation for Fixed
Memory Mapped IO clocks.

Signed-off-by: Jan Kotas <jank@cadence.com>
---
 .../devicetree/bindings/clock/fixed-mmio-clock.txt | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/fixed-mmio-clock.txt

diff --git a/Documentation/devicetree/bindings/clock/fixed-mmio-clock.txt b/Documentation/devicetree/bindings/clock/fixed-mmio-clock.txt
new file mode 100644
index 000000000..c359367fd
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/fixed-mmio-clock.txt
@@ -0,0 +1,24 @@
+Binding for simple memory mapped io fixed-rate clock sources.
+The driver reads a clock frequency value from a single 32-bit memory mapped
+I/O register and registers it as a fixed rate clock.
+
+It was designed for test systems, like FPGA, not for complete, finished SoCs.
+
+This binding uses the common clock binding[1].
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : shall be "fixed-mmio-clock".
+- #clock-cells : from common clock binding; shall be set to 0.
+- reg : Address and length of the clock value register set.
+
+Optional properties:
+- clock-output-names : From common clock binding.
+
+Example:
+sysclock: sysclock@fd020004 {
+	#clock-cells = <0>;
+	compatible = "fixed-mmio-clock";
+	reg = <0xfd020004 0x4>;
+};
-- 
2.15.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] clk: Add Fixed MMIO clock driver
  2018-12-13 12:49 [PATCH v2 0/2] clk: Add driver and bindings for Fixed MMIO clock Jan Kotas
  2018-12-13 12:49 ` [PATCH v2 1/2] dt-bindings: clk: Add " Jan Kotas
@ 2018-12-13 12:49 ` Jan Kotas
  2019-01-09 19:42   ` Stephen Boyd
  2019-01-09 19:42   ` Stephen Boyd
  1 sibling, 2 replies; 6+ messages in thread
From: Jan Kotas @ 2018-12-13 12:49 UTC (permalink / raw)
  To: mturquette, sboyd, robh+dt, mark.rutland
  Cc: linux-clk, devicetree, linux-kernel, Jan Kotas

This patch adds a driver for Fixed MMIO clock.
The driver reads a clock frequency value from a single 32-bit memory
mapped register and registers it as a fixed rate clock.

It can be enabled with COMMON_CLK_FIXED_MMIO Kconfig option.

Signed-off-by: Jan Kotas <jank@cadence.com>
---
 drivers/clk/Kconfig          |   6 +++
 drivers/clk/Makefile         |   1 +
 drivers/clk/clk-fixed-mmio.c | 109 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/clk/clk-fixed-mmio.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 81cdb4eac..69c7fb859 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -283,6 +283,12 @@ config COMMON_CLK_STM32H7
 	---help---
 	  Support for stm32h7 SoC family clocks
 
+config COMMON_CLK_FIXED_MMIO
+	bool "Clock driver for Memory Mapped Fixed values"
+	depends on COMMON_CLK && OF
+	help
+	  Support for Memory Mapped IO Fixed clocks
+
 source "drivers/clk/actions/Kconfig"
 source "drivers/clk/bcm/Kconfig"
 source "drivers/clk/hisilicon/Kconfig"
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 72be7a38c..4e61961dc 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_COMMON_CLK_CDCE925)	+= clk-cdce925.o
 obj-$(CONFIG_ARCH_CLPS711X)		+= clk-clps711x.o
 obj-$(CONFIG_COMMON_CLK_CS2000_CP)	+= clk-cs2000-cp.o
 obj-$(CONFIG_ARCH_EFM32)		+= clk-efm32gg.o
+obj-$(CONFIG_COMMON_CLK_FIXED_MMIO)	+= clk-fixed-mmio.o
 obj-$(CONFIG_COMMON_CLK_GEMINI)		+= clk-gemini.o
 obj-$(CONFIG_COMMON_CLK_ASPEED)		+= clk-aspeed.o
 obj-$(CONFIG_ARCH_HIGHBANK)		+= clk-highbank.o
diff --git a/drivers/clk/clk-fixed-mmio.c b/drivers/clk/clk-fixed-mmio.c
new file mode 100644
index 000000000..84e202d07
--- /dev/null
+++ b/drivers/clk/clk-fixed-mmio.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Memory Mapped IO Fixed clock driver
+ *
+ * Copyright (C) 2018 Cadence Design Systems, Inc.
+ *
+ * Authors:
+ *	Jan Kotas <jank@cadence.com>
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+static struct clk *fixed_mmio_clk_setup(struct device_node *node)
+{
+	struct clk *clk;
+	const char *clk_name = node->name;
+	void __iomem *base;
+	u32 freq;
+	int ret;
+
+	base = of_iomap(node, 0);
+	if (!base) {
+		pr_err("%pOFn: failed to map address\n", node);
+		return ERR_PTR(-EIO);
+	}
+
+	freq = readl(base);
+	iounmap(base);
+	of_property_read_string(node, "clock-output-names", &clk_name);
+
+	clk = clk_register_fixed_rate(NULL, clk_name, NULL, 0, freq);
+	if (IS_ERR(clk)) {
+		pr_err("%pOFn: failed to register fixed rate clock\n", node);
+		return clk;
+	}
+
+	ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
+	if (ret) {
+		pr_err("%pOFn: failed to add clock provider\n", node);
+		clk_unregister(clk);
+		return ERR_PTR(ret);
+	}
+
+	return clk;
+}
+
+/**
+ * Setup function for fixed mmio clock
+ */
+void __init of_fixed_mmio_clk_setup(struct device_node *node)
+{
+	fixed_mmio_clk_setup(node);
+}
+CLK_OF_DECLARE(fixed_mmio_clk, "fixed-mmio-clock", of_fixed_mmio_clk_setup);
+
+
+/**
+ * Platform driver probe
+ * It is not executed when of_fixed_mmio_clk_setup succeeded.
+ */
+static int of_fixed_mmio_clk_probe(struct platform_device *pdev)
+{
+	struct clk *clk;
+
+	clk = fixed_mmio_clk_setup(pdev->dev.of_node);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	platform_set_drvdata(pdev, clk);
+
+	return 0;
+}
+
+/**
+ * Platform driver remove
+ */
+static int of_fixed_mmio_clk_remove(struct platform_device *pdev)
+{
+	struct clk *clk = platform_get_drvdata(pdev);
+
+	of_clk_del_provider(pdev->dev.of_node);
+	clk_unregister_fixed_rate(clk);
+
+	return 0;
+}
+
+static const struct of_device_id of_fixed_mmio_clk_ids[] = {
+	{ .compatible = "fixed-mmio-clock" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, of_fixed_mmio_clk_ids);
+
+static struct platform_driver of_fixed_mmio_clk_driver = {
+	.driver = {
+		.name = "of_fixed_mmio_clk",
+		.of_match_table = of_fixed_mmio_clk_ids,
+	},
+	.probe = of_fixed_mmio_clk_probe,
+	.remove = of_fixed_mmio_clk_remove,
+};
+module_platform_driver(of_fixed_mmio_clk_driver);
+
+MODULE_AUTHOR("Jan Kotas <jank@cadence.com>");
+MODULE_DESCRIPTION("Memory Mapped IO Fixed clock driver");
+MODULE_LICENSE("GPL v2");
-- 
2.15.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] clk: Add Fixed MMIO clock driver
  2018-12-13 12:49 ` [PATCH v2 2/2] clk: Add Fixed MMIO clock driver Jan Kotas
@ 2019-01-09 19:42   ` Stephen Boyd
  2019-01-09 19:42   ` Stephen Boyd
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2019-01-09 19:42 UTC (permalink / raw)
  To: Jan Kotas, mark.rutland, mturquette, robh+dt
  Cc: linux-clk, devicetree, linux-kernel, Jan Kotas

Quoting Jan Kotas (2018-12-13 04:49:29)
> This patch adds a driver for Fixed MMIO clock.
> The driver reads a clock frequency value from a single 32-bit memory
> mapped register and registers it as a fixed rate clock.
> 
> It can be enabled with COMMON_CLK_FIXED_MMIO Kconfig option.
> 
> Signed-off-by: Jan Kotas <jank@cadence.com>

This needed to use the clk_hw based APIs and add a static. I made the
changes myself. Let me know if you have any problems with what's in
clk-next and it can be fixed.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] dt-bindings: clk: Add bindings for Fixed MMIO clock
  2018-12-13 12:49 ` [PATCH v2 1/2] dt-bindings: clk: Add " Jan Kotas
@ 2019-01-09 19:42   ` Stephen Boyd
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2019-01-09 19:42 UTC (permalink / raw)
  To: Jan Kotas, mark.rutland, mturquette, robh+dt
  Cc: linux-clk, devicetree, linux-kernel, Jan Kotas

Quoting Jan Kotas (2018-12-13 04:49:28)
> This patch adds a DT binding documentation for Fixed
> Memory Mapped IO clocks.
> 
> Signed-off-by: Jan Kotas <jank@cadence.com>
> ---

Applied to clk-next


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] clk: Add Fixed MMIO clock driver
  2018-12-13 12:49 ` [PATCH v2 2/2] clk: Add Fixed MMIO clock driver Jan Kotas
  2019-01-09 19:42   ` Stephen Boyd
@ 2019-01-09 19:42   ` Stephen Boyd
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2019-01-09 19:42 UTC (permalink / raw)
  To: Jan Kotas, mark.rutland, mturquette, robh+dt
  Cc: linux-clk, devicetree, linux-kernel, Jan Kotas

Quoting Jan Kotas (2018-12-13 04:49:29)
> This patch adds a driver for Fixed MMIO clock.
> The driver reads a clock frequency value from a single 32-bit memory
> mapped register and registers it as a fixed rate clock.
> 
> It can be enabled with COMMON_CLK_FIXED_MMIO Kconfig option.
> 
> Signed-off-by: Jan Kotas <jank@cadence.com>
> ---

Applied to clk-next


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 12:49 [PATCH v2 0/2] clk: Add driver and bindings for Fixed MMIO clock Jan Kotas
2018-12-13 12:49 ` [PATCH v2 1/2] dt-bindings: clk: Add " Jan Kotas
2019-01-09 19:42   ` Stephen Boyd
2018-12-13 12:49 ` [PATCH v2 2/2] clk: Add Fixed MMIO clock driver Jan Kotas
2019-01-09 19:42   ` Stephen Boyd
2019-01-09 19:42   ` Stephen Boyd

Linux-Clk Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-clk/0 linux-clk/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-clk linux-clk/ https://lore.kernel.org/linux-clk \
		linux-clk@vger.kernel.org linux-clk@archiver.kernel.org
	public-inbox-index linux-clk


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-clk


AGPL code for this site: git clone https://public-inbox.org/ public-inbox