All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
       [not found] <1458204222-31149-1-git-send-email-yassinjaffer@gmail.com>
  2016-03-17  8:43   ` yassinjaffer
@ 2016-03-17  8:43   ` yassinjaffer
  0 siblings, 0 replies; 19+ messages in thread
From: yassinjaffer @ 2016-03-17  8:43 UTC (permalink / raw)
  To: dev
  Cc: Yassin Jaffer, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Maxime Ripard, Chen-Yu Tsai,
	Emilio López, Michael Turquette, Stephen Boyd,
	Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

From: Yassin Jaffer <yassinjaffer@gmail.com>

This patch adds a composite clock type consisting of
a clock gate, mux, configurable dividers, and a reset control.

Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
---
 Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
 drivers/clk/sunxi/Makefile                        |   1 +
 drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-a10-csi.c

diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt
index e59f57b..c3826f7 100644
--- a/Documentation/devicetree/bindings/clock/sunxi.txt
+++ b/Documentation/devicetree/bindings/clock/sunxi.txt
@@ -77,6 +77,7 @@ Required properties:
 	"allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
 	"allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
 	"allwinner,sun4i-a10-ve-clk" - for the Video Engine clock
+	"allwinner,sun4i-a10-csi-clk" - for the CSI module
 
 Required properties for all clocks:
 - reg : shall be the control register address for the clock.
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index 3fd7901..42ce752 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o
 obj-y += clk-a10-hosc.o
 obj-y += clk-a10-mod1.o
 obj-y += clk-a10-pll2.o
+obj-y += clk-a10-csi.o
 obj-y += clk-a10-ve.o
 obj-y += clk-a20-gmac.o
 obj-y += clk-mod0.o
diff --git a/drivers/clk/sunxi/clk-a10-csi.c b/drivers/clk/sunxi/clk-a10-csi.c
new file mode 100644
index 0000000..f17d206
--- /dev/null
+++ b/drivers/clk/sunxi/clk-a10-csi.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2016 Yassin Jaffer
+ *
+ * Yassin Jaffer <yassinjaffer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+static DEFINE_SPINLOCK(sun4i_csi_lock);
+
+#define SUN4I_CSI_PARENTS       5
+#define SUN4I_CSI_GATE_BIT      31
+#define SUN4I_CSI_RESET_BIT     30
+#define SUN4I_CSI_MUX_SHIFT     24
+#define SUN4I_CSI_DIV_WIDTH     5
+#define SUN4I_CSI_DIV_SHIFT     0
+
+static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = {
+	0x0,
+	0x1,
+	0x2,
+	0x5,
+	0x6,
+};
+
+struct csi_reset_data {
+	void __iomem			*reg;
+	spinlock_t			*lock; /* lock for reset handling */
+	struct reset_controller_dev	rcdev;
+};
+
+static int sun4i_csi_assert(struct reset_controller_dev *rcdev,
+			    unsigned long id)
+{
+	struct csi_reset_data *data = container_of(rcdev,
+						  struct csi_reset_data,
+						  rcdev);
+	unsigned long flags;
+	u32 reg;
+
+	spin_lock_irqsave(data->lock, flags);
+
+	reg = readl(data->reg);
+	writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg);
+
+	spin_unlock_irqrestore(data->lock, flags);
+
+	return 0;
+}
+
+static int sun4i_csi_deassert(struct reset_controller_dev *rcdev,
+			      unsigned long id)
+{
+	struct csi_reset_data *data = container_of(rcdev,
+						  struct csi_reset_data,
+						  rcdev);
+	unsigned long flags;
+	u32 reg;
+
+	spin_lock_irqsave(data->lock, flags);
+
+	reg = readl(data->reg);
+	writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg);
+
+	spin_unlock_irqrestore(data->lock, flags);
+
+	return 0;
+}
+
+static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev,
+			      const struct of_phandle_args *reset_spec)
+{
+	if (WARN_ON(reset_spec->args_count != 0))
+		return -EINVAL;
+
+	return 0;
+}
+
+static struct reset_control_ops sun4i_csi_reset_ops = {
+	.assert		= sun4i_csi_assert,
+	.deassert	= sun4i_csi_deassert,
+};
+
+static void __init sun4i_csi_clk_setup(struct device_node *node)
+{
+	const char *parents[SUN4I_CSI_PARENTS];
+	const char *clk_name = node->name;
+	struct csi_reset_data *reset_data;
+	struct clk_divider *div;
+	struct clk_gate *gate;
+	struct clk_mux *mux;
+	void __iomem *reg;
+	struct clk *clk;
+	int i = 0;
+
+	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+	if (IS_ERR(reg))
+		return;
+
+	of_property_read_string(node, "clock-output-names", &clk_name);
+
+	i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS);
+
+	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+	if (!mux)
+		goto err_unmap;
+
+	mux->reg = reg;
+	mux->shift = SUN4I_CSI_MUX_SHIFT;
+	mux->table = sun4i_csi_mux_table;
+	mux->lock = &sun4i_csi_lock;
+
+	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+	if (!gate)
+		goto err_free_mux;
+
+	gate->reg = reg;
+	gate->bit_idx = SUN4I_CSI_GATE_BIT;
+	gate->lock = &sun4i_csi_lock;
+
+	div = kzalloc(sizeof(*div), GFP_KERNEL);
+	if (!div)
+		goto err_free_gate;
+
+	div->reg = reg;
+	div->shift = SUN4I_CSI_DIV_SHIFT;
+	div->width = SUN4I_CSI_DIV_WIDTH;
+	div->lock = &sun4i_csi_lock;
+
+	clk = clk_register_composite(NULL, clk_name,
+				     parents, i,
+				     &mux->hw, &clk_mux_ops,
+				     &div->hw, &clk_divider_ops,
+				     &gate->hw, &clk_gate_ops,
+				     CLK_SET_RATE_PARENT);
+	if (IS_ERR(clk))
+		goto err_free_div;
+
+	of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+	reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
+	if (!reset_data)
+		goto err_free_clk;
+
+	reset_data->reg = reg;
+	reset_data->lock = &sun4i_csi_lock;
+	reset_data->rcdev.nr_resets = 1;
+	reset_data->rcdev.ops = &sun4i_csi_reset_ops;
+	reset_data->rcdev.of_node = node;
+	reset_data->rcdev.of_xlate = sun4i_csi_of_xlate;
+	reset_data->rcdev.of_reset_n_cells = 0;
+
+	if (reset_controller_register(&reset_data->rcdev))
+		goto err_free_reset;
+
+	return;
+
+err_free_reset:
+	kfree(reset_data);
+err_free_clk:
+	clk_unregister(clk);
+err_free_div:
+	kfree(div);
+err_free_gate:
+	kfree(gate);
+err_free_mux:
+	kfree(mux);
+err_unmap:
+	iounmap(reg);
+}
+
+CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk",
+	       sun4i_csi_clk_setup);
+
-- 
1.9.1

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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-03-17  8:43   ` yassinjaffer
  0 siblings, 0 replies; 19+ messages in thread
From: yassinjaffer @ 2016-03-17  8:43 UTC (permalink / raw)
  To: dev
  Cc: Yassin Jaffer, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Maxime Ripard, Chen-Yu Tsai,
	Emilio López, Michael Turquette, Stephen Boyd,
	Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

From: Yassin Jaffer <yassinjaffer@gmail.com>

This patch adds a composite clock type consisting of
a clock gate, mux, configurable dividers, and a reset control.

Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
---
 Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
 drivers/clk/sunxi/Makefile                        |   1 +
 drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-a10-csi.c

diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt
index e59f57b..c3826f7 100644
--- a/Documentation/devicetree/bindings/clock/sunxi.txt
+++ b/Documentation/devicetree/bindings/clock/sunxi.txt
@@ -77,6 +77,7 @@ Required properties:
 	"allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
 	"allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
 	"allwinner,sun4i-a10-ve-clk" - for the Video Engine clock
+	"allwinner,sun4i-a10-csi-clk" - for the CSI module
 
 Required properties for all clocks:
 - reg : shall be the control register address for the clock.
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index 3fd7901..42ce752 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o
 obj-y += clk-a10-hosc.o
 obj-y += clk-a10-mod1.o
 obj-y += clk-a10-pll2.o
+obj-y += clk-a10-csi.o
 obj-y += clk-a10-ve.o
 obj-y += clk-a20-gmac.o
 obj-y += clk-mod0.o
diff --git a/drivers/clk/sunxi/clk-a10-csi.c b/drivers/clk/sunxi/clk-a10-csi.c
new file mode 100644
index 0000000..f17d206
--- /dev/null
+++ b/drivers/clk/sunxi/clk-a10-csi.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2016 Yassin Jaffer
+ *
+ * Yassin Jaffer <yassinjaffer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+static DEFINE_SPINLOCK(sun4i_csi_lock);
+
+#define SUN4I_CSI_PARENTS       5
+#define SUN4I_CSI_GATE_BIT      31
+#define SUN4I_CSI_RESET_BIT     30
+#define SUN4I_CSI_MUX_SHIFT     24
+#define SUN4I_CSI_DIV_WIDTH     5
+#define SUN4I_CSI_DIV_SHIFT     0
+
+static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = {
+	0x0,
+	0x1,
+	0x2,
+	0x5,
+	0x6,
+};
+
+struct csi_reset_data {
+	void __iomem			*reg;
+	spinlock_t			*lock; /* lock for reset handling */
+	struct reset_controller_dev	rcdev;
+};
+
+static int sun4i_csi_assert(struct reset_controller_dev *rcdev,
+			    unsigned long id)
+{
+	struct csi_reset_data *data = container_of(rcdev,
+						  struct csi_reset_data,
+						  rcdev);
+	unsigned long flags;
+	u32 reg;
+
+	spin_lock_irqsave(data->lock, flags);
+
+	reg = readl(data->reg);
+	writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg);
+
+	spin_unlock_irqrestore(data->lock, flags);
+
+	return 0;
+}
+
+static int sun4i_csi_deassert(struct reset_controller_dev *rcdev,
+			      unsigned long id)
+{
+	struct csi_reset_data *data = container_of(rcdev,
+						  struct csi_reset_data,
+						  rcdev);
+	unsigned long flags;
+	u32 reg;
+
+	spin_lock_irqsave(data->lock, flags);
+
+	reg = readl(data->reg);
+	writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg);
+
+	spin_unlock_irqrestore(data->lock, flags);
+
+	return 0;
+}
+
+static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev,
+			      const struct of_phandle_args *reset_spec)
+{
+	if (WARN_ON(reset_spec->args_count != 0))
+		return -EINVAL;
+
+	return 0;
+}
+
+static struct reset_control_ops sun4i_csi_reset_ops = {
+	.assert		= sun4i_csi_assert,
+	.deassert	= sun4i_csi_deassert,
+};
+
+static void __init sun4i_csi_clk_setup(struct device_node *node)
+{
+	const char *parents[SUN4I_CSI_PARENTS];
+	const char *clk_name = node->name;
+	struct csi_reset_data *reset_data;
+	struct clk_divider *div;
+	struct clk_gate *gate;
+	struct clk_mux *mux;
+	void __iomem *reg;
+	struct clk *clk;
+	int i = 0;
+
+	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+	if (IS_ERR(reg))
+		return;
+
+	of_property_read_string(node, "clock-output-names", &clk_name);
+
+	i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS);
+
+	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+	if (!mux)
+		goto err_unmap;
+
+	mux->reg = reg;
+	mux->shift = SUN4I_CSI_MUX_SHIFT;
+	mux->table = sun4i_csi_mux_table;
+	mux->lock = &sun4i_csi_lock;
+
+	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+	if (!gate)
+		goto err_free_mux;
+
+	gate->reg = reg;
+	gate->bit_idx = SUN4I_CSI_GATE_BIT;
+	gate->lock = &sun4i_csi_lock;
+
+	div = kzalloc(sizeof(*div), GFP_KERNEL);
+	if (!div)
+		goto err_free_gate;
+
+	div->reg = reg;
+	div->shift = SUN4I_CSI_DIV_SHIFT;
+	div->width = SUN4I_CSI_DIV_WIDTH;
+	div->lock = &sun4i_csi_lock;
+
+	clk = clk_register_composite(NULL, clk_name,
+				     parents, i,
+				     &mux->hw, &clk_mux_ops,
+				     &div->hw, &clk_divider_ops,
+				     &gate->hw, &clk_gate_ops,
+				     CLK_SET_RATE_PARENT);
+	if (IS_ERR(clk))
+		goto err_free_div;
+
+	of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+	reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
+	if (!reset_data)
+		goto err_free_clk;
+
+	reset_data->reg = reg;
+	reset_data->lock = &sun4i_csi_lock;
+	reset_data->rcdev.nr_resets = 1;
+	reset_data->rcdev.ops = &sun4i_csi_reset_ops;
+	reset_data->rcdev.of_node = node;
+	reset_data->rcdev.of_xlate = sun4i_csi_of_xlate;
+	reset_data->rcdev.of_reset_n_cells = 0;
+
+	if (reset_controller_register(&reset_data->rcdev))
+		goto err_free_reset;
+
+	return;
+
+err_free_reset:
+	kfree(reset_data);
+err_free_clk:
+	clk_unregister(clk);
+err_free_div:
+	kfree(div);
+err_free_gate:
+	kfree(gate);
+err_free_mux:
+	kfree(mux);
+err_unmap:
+	iounmap(reg);
+}
+
+CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk",
+	       sun4i_csi_clk_setup);
+
-- 
1.9.1


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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-03-17  8:43   ` yassinjaffer
  0 siblings, 0 replies; 19+ messages in thread
From: yassinjaffer at gmail.com @ 2016-03-17  8:43 UTC (permalink / raw)
  To: linux-arm-kernel

From: Yassin Jaffer <yassinjaffer@gmail.com>

This patch adds a composite clock type consisting of
a clock gate, mux, configurable dividers, and a reset control.

Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
---
 Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
 drivers/clk/sunxi/Makefile                        |   1 +
 drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk-a10-csi.c

diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt
index e59f57b..c3826f7 100644
--- a/Documentation/devicetree/bindings/clock/sunxi.txt
+++ b/Documentation/devicetree/bindings/clock/sunxi.txt
@@ -77,6 +77,7 @@ Required properties:
 	"allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
 	"allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
 	"allwinner,sun4i-a10-ve-clk" - for the Video Engine clock
+	"allwinner,sun4i-a10-csi-clk" - for the CSI module
 
 Required properties for all clocks:
 - reg : shall be the control register address for the clock.
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index 3fd7901..42ce752 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o
 obj-y += clk-a10-hosc.o
 obj-y += clk-a10-mod1.o
 obj-y += clk-a10-pll2.o
+obj-y += clk-a10-csi.o
 obj-y += clk-a10-ve.o
 obj-y += clk-a20-gmac.o
 obj-y += clk-mod0.o
diff --git a/drivers/clk/sunxi/clk-a10-csi.c b/drivers/clk/sunxi/clk-a10-csi.c
new file mode 100644
index 0000000..f17d206
--- /dev/null
+++ b/drivers/clk/sunxi/clk-a10-csi.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2016 Yassin Jaffer
+ *
+ * Yassin Jaffer <yassinjaffer@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+static DEFINE_SPINLOCK(sun4i_csi_lock);
+
+#define SUN4I_CSI_PARENTS       5
+#define SUN4I_CSI_GATE_BIT      31
+#define SUN4I_CSI_RESET_BIT     30
+#define SUN4I_CSI_MUX_SHIFT     24
+#define SUN4I_CSI_DIV_WIDTH     5
+#define SUN4I_CSI_DIV_SHIFT     0
+
+static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = {
+	0x0,
+	0x1,
+	0x2,
+	0x5,
+	0x6,
+};
+
+struct csi_reset_data {
+	void __iomem			*reg;
+	spinlock_t			*lock; /* lock for reset handling */
+	struct reset_controller_dev	rcdev;
+};
+
+static int sun4i_csi_assert(struct reset_controller_dev *rcdev,
+			    unsigned long id)
+{
+	struct csi_reset_data *data = container_of(rcdev,
+						  struct csi_reset_data,
+						  rcdev);
+	unsigned long flags;
+	u32 reg;
+
+	spin_lock_irqsave(data->lock, flags);
+
+	reg = readl(data->reg);
+	writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg);
+
+	spin_unlock_irqrestore(data->lock, flags);
+
+	return 0;
+}
+
+static int sun4i_csi_deassert(struct reset_controller_dev *rcdev,
+			      unsigned long id)
+{
+	struct csi_reset_data *data = container_of(rcdev,
+						  struct csi_reset_data,
+						  rcdev);
+	unsigned long flags;
+	u32 reg;
+
+	spin_lock_irqsave(data->lock, flags);
+
+	reg = readl(data->reg);
+	writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg);
+
+	spin_unlock_irqrestore(data->lock, flags);
+
+	return 0;
+}
+
+static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev,
+			      const struct of_phandle_args *reset_spec)
+{
+	if (WARN_ON(reset_spec->args_count != 0))
+		return -EINVAL;
+
+	return 0;
+}
+
+static struct reset_control_ops sun4i_csi_reset_ops = {
+	.assert		= sun4i_csi_assert,
+	.deassert	= sun4i_csi_deassert,
+};
+
+static void __init sun4i_csi_clk_setup(struct device_node *node)
+{
+	const char *parents[SUN4I_CSI_PARENTS];
+	const char *clk_name = node->name;
+	struct csi_reset_data *reset_data;
+	struct clk_divider *div;
+	struct clk_gate *gate;
+	struct clk_mux *mux;
+	void __iomem *reg;
+	struct clk *clk;
+	int i = 0;
+
+	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+	if (IS_ERR(reg))
+		return;
+
+	of_property_read_string(node, "clock-output-names", &clk_name);
+
+	i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS);
+
+	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
+	if (!mux)
+		goto err_unmap;
+
+	mux->reg = reg;
+	mux->shift = SUN4I_CSI_MUX_SHIFT;
+	mux->table = sun4i_csi_mux_table;
+	mux->lock = &sun4i_csi_lock;
+
+	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+	if (!gate)
+		goto err_free_mux;
+
+	gate->reg = reg;
+	gate->bit_idx = SUN4I_CSI_GATE_BIT;
+	gate->lock = &sun4i_csi_lock;
+
+	div = kzalloc(sizeof(*div), GFP_KERNEL);
+	if (!div)
+		goto err_free_gate;
+
+	div->reg = reg;
+	div->shift = SUN4I_CSI_DIV_SHIFT;
+	div->width = SUN4I_CSI_DIV_WIDTH;
+	div->lock = &sun4i_csi_lock;
+
+	clk = clk_register_composite(NULL, clk_name,
+				     parents, i,
+				     &mux->hw, &clk_mux_ops,
+				     &div->hw, &clk_divider_ops,
+				     &gate->hw, &clk_gate_ops,
+				     CLK_SET_RATE_PARENT);
+	if (IS_ERR(clk))
+		goto err_free_div;
+
+	of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+	reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
+	if (!reset_data)
+		goto err_free_clk;
+
+	reset_data->reg = reg;
+	reset_data->lock = &sun4i_csi_lock;
+	reset_data->rcdev.nr_resets = 1;
+	reset_data->rcdev.ops = &sun4i_csi_reset_ops;
+	reset_data->rcdev.of_node = node;
+	reset_data->rcdev.of_xlate = sun4i_csi_of_xlate;
+	reset_data->rcdev.of_reset_n_cells = 0;
+
+	if (reset_controller_register(&reset_data->rcdev))
+		goto err_free_reset;
+
+	return;
+
+err_free_reset:
+	kfree(reset_data);
+err_free_clk:
+	clk_unregister(clk);
+err_free_div:
+	kfree(div);
+err_free_gate:
+	kfree(gate);
+err_free_mux:
+	kfree(mux);
+err_unmap:
+	iounmap(reg);
+}
+
+CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk",
+	       sun4i_csi_clk_setup);
+
-- 
1.9.1

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
  2016-03-17  8:43   ` yassinjaffer
@ 2016-03-18 19:25     ` Maxime Ripard
  -1 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-03-18 19:25 UTC (permalink / raw)
  To: yassinjaffer
  Cc: dev, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Chen-Yu Tsai, Emilio López, Michael Turquette,
	Stephen Boyd, Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 7484 bytes --]

Hi Yassin,

On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer@gmail.com wrote:
> From: Yassin Jaffer <yassinjaffer@gmail.com>
> 
> This patch adds a composite clock type consisting of
> a clock gate, mux, configurable dividers, and a reset control.
> 
> Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> ---
>  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
>  drivers/clk/sunxi/Makefile                        |   1 +
>  drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
>  3 files changed, 190 insertions(+)
>  create mode 100644 drivers/clk/sunxi/clk-a10-csi.c
> 
> diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt
> index e59f57b..c3826f7 100644
> --- a/Documentation/devicetree/bindings/clock/sunxi.txt
> +++ b/Documentation/devicetree/bindings/clock/sunxi.txt
> @@ -77,6 +77,7 @@ Required properties:
>  	"allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
>  	"allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
>  	"allwinner,sun4i-a10-ve-clk" - for the Video Engine clock
> +	"allwinner,sun4i-a10-csi-clk" - for the CSI module
>  
>  Required properties for all clocks:
>  - reg : shall be the control register address for the clock.
> diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
> index 3fd7901..42ce752 100644
> --- a/drivers/clk/sunxi/Makefile
> +++ b/drivers/clk/sunxi/Makefile
> @@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o
>  obj-y += clk-a10-hosc.o
>  obj-y += clk-a10-mod1.o
>  obj-y += clk-a10-pll2.o
> +obj-y += clk-a10-csi.o
>  obj-y += clk-a10-ve.o
>  obj-y += clk-a20-gmac.o
>  obj-y += clk-mod0.o
> diff --git a/drivers/clk/sunxi/clk-a10-csi.c b/drivers/clk/sunxi/clk-a10-csi.c
> new file mode 100644
> index 0000000..f17d206
> --- /dev/null
> +++ b/drivers/clk/sunxi/clk-a10-csi.c
> @@ -0,0 +1,188 @@
> +/*
> + * Copyright 2016 Yassin Jaffer
> + *
> + * Yassin Jaffer <yassinjaffer@gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/of_address.h>
> +#include <linux/reset-controller.h>
> +#include <linux/slab.h>
> +#include <linux/spinlock.h>
> +
> +static DEFINE_SPINLOCK(sun4i_csi_lock);
> +
> +#define SUN4I_CSI_PARENTS       5
> +#define SUN4I_CSI_GATE_BIT      31
> +#define SUN4I_CSI_RESET_BIT     30
> +#define SUN4I_CSI_MUX_SHIFT     24
> +#define SUN4I_CSI_DIV_WIDTH     5
> +#define SUN4I_CSI_DIV_SHIFT     0
> +
> +static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = {
> +	0x0,
> +	0x1,
> +	0x2,
> +	0x5,
> +	0x6,
> +};
> +
> +struct csi_reset_data {
> +	void __iomem			*reg;
> +	spinlock_t			*lock; /* lock for reset handling */
> +	struct reset_controller_dev	rcdev;
> +};
> +
> +static int sun4i_csi_assert(struct reset_controller_dev *rcdev,
> +			    unsigned long id)
> +{
> +	struct csi_reset_data *data = container_of(rcdev,
> +						  struct csi_reset_data,
> +						  rcdev);
> +	unsigned long flags;
> +	u32 reg;
> +
> +	spin_lock_irqsave(data->lock, flags);
> +
> +	reg = readl(data->reg);
> +	writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg);
> +
> +	spin_unlock_irqrestore(data->lock, flags);
> +
> +	return 0;
> +}
> +
> +static int sun4i_csi_deassert(struct reset_controller_dev *rcdev,
> +			      unsigned long id)
> +{
> +	struct csi_reset_data *data = container_of(rcdev,
> +						  struct csi_reset_data,
> +						  rcdev);
> +	unsigned long flags;
> +	u32 reg;
> +
> +	spin_lock_irqsave(data->lock, flags);
> +
> +	reg = readl(data->reg);
> +	writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg);
> +
> +	spin_unlock_irqrestore(data->lock, flags);
> +
> +	return 0;
> +}
> +
> +static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev,
> +			      const struct of_phandle_args *reset_spec)
> +{
> +	if (WARN_ON(reset_spec->args_count != 0))
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +static struct reset_control_ops sun4i_csi_reset_ops = {
> +	.assert		= sun4i_csi_assert,
> +	.deassert	= sun4i_csi_deassert,
> +};
> +
> +static void __init sun4i_csi_clk_setup(struct device_node *node)
> +{
> +	const char *parents[SUN4I_CSI_PARENTS];
> +	const char *clk_name = node->name;
> +	struct csi_reset_data *reset_data;
> +	struct clk_divider *div;
> +	struct clk_gate *gate;
> +	struct clk_mux *mux;
> +	void __iomem *reg;
> +	struct clk *clk;
> +	int i = 0;
> +
> +	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
> +	if (IS_ERR(reg))
> +		return;
> +
> +	of_property_read_string(node, "clock-output-names", &clk_name);
> +
> +	i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS);
> +
> +	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
> +	if (!mux)
> +		goto err_unmap;
> +
> +	mux->reg = reg;
> +	mux->shift = SUN4I_CSI_MUX_SHIFT;
> +	mux->table = sun4i_csi_mux_table;
> +	mux->lock = &sun4i_csi_lock;
> +
> +	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
> +	if (!gate)
> +		goto err_free_mux;
> +
> +	gate->reg = reg;
> +	gate->bit_idx = SUN4I_CSI_GATE_BIT;
> +	gate->lock = &sun4i_csi_lock;
> +
> +	div = kzalloc(sizeof(*div), GFP_KERNEL);
> +	if (!div)
> +		goto err_free_gate;
> +
> +	div->reg = reg;
> +	div->shift = SUN4I_CSI_DIV_SHIFT;
> +	div->width = SUN4I_CSI_DIV_WIDTH;
> +	div->lock = &sun4i_csi_lock;
> +
> +	clk = clk_register_composite(NULL, clk_name,
> +				     parents, i,
> +				     &mux->hw, &clk_mux_ops,
> +				     &div->hw, &clk_divider_ops,
> +				     &gate->hw, &clk_gate_ops,
> +				     CLK_SET_RATE_PARENT);
> +	if (IS_ERR(clk))
> +		goto err_free_div;
> +
> +	of_clk_add_provider(node, of_clk_src_simple_get, clk);
> +
> +	reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
> +	if (!reset_data)
> +		goto err_free_clk;
> +
> +	reset_data->reg = reg;
> +	reset_data->lock = &sun4i_csi_lock;
> +	reset_data->rcdev.nr_resets = 1;
> +	reset_data->rcdev.ops = &sun4i_csi_reset_ops;
> +	reset_data->rcdev.of_node = node;
> +	reset_data->rcdev.of_xlate = sun4i_csi_of_xlate;
> +	reset_data->rcdev.of_reset_n_cells = 0;
> +
> +	if (reset_controller_register(&reset_data->rcdev))
> +		goto err_free_reset;
> +
> +	return;
> +
> +err_free_reset:
> +	kfree(reset_data);
> +err_free_clk:
> +	clk_unregister(clk);
> +err_free_div:
> +	kfree(div);
> +err_free_gate:
> +	kfree(gate);
> +err_free_mux:
> +	kfree(mux);
> +err_unmap:
> +	iounmap(reg);
> +}
> +
> +CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk",
> +	       sun4i_csi_clk_setup);
> +

That's great, but it shares a lot of infrastructure of boilerplate
code with the display clocks that are part of my DRM serie.

I plan to post them early next week, I'll cc you so that you can base
your clock on top of it.

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-03-18 19:25     ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-03-18 19:25 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Yassin,

On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer at gmail.com wrote:
> From: Yassin Jaffer <yassinjaffer@gmail.com>
> 
> This patch adds a composite clock type consisting of
> a clock gate, mux, configurable dividers, and a reset control.
> 
> Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> ---
>  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
>  drivers/clk/sunxi/Makefile                        |   1 +
>  drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
>  3 files changed, 190 insertions(+)
>  create mode 100644 drivers/clk/sunxi/clk-a10-csi.c
> 
> diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt b/Documentation/devicetree/bindings/clock/sunxi.txt
> index e59f57b..c3826f7 100644
> --- a/Documentation/devicetree/bindings/clock/sunxi.txt
> +++ b/Documentation/devicetree/bindings/clock/sunxi.txt
> @@ -77,6 +77,7 @@ Required properties:
>  	"allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on A80
>  	"allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets on A80
>  	"allwinner,sun4i-a10-ve-clk" - for the Video Engine clock
> +	"allwinner,sun4i-a10-csi-clk" - for the CSI module
>  
>  Required properties for all clocks:
>  - reg : shall be the control register address for the clock.
> diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
> index 3fd7901..42ce752 100644
> --- a/drivers/clk/sunxi/Makefile
> +++ b/drivers/clk/sunxi/Makefile
> @@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o
>  obj-y += clk-a10-hosc.o
>  obj-y += clk-a10-mod1.o
>  obj-y += clk-a10-pll2.o
> +obj-y += clk-a10-csi.o
>  obj-y += clk-a10-ve.o
>  obj-y += clk-a20-gmac.o
>  obj-y += clk-mod0.o
> diff --git a/drivers/clk/sunxi/clk-a10-csi.c b/drivers/clk/sunxi/clk-a10-csi.c
> new file mode 100644
> index 0000000..f17d206
> --- /dev/null
> +++ b/drivers/clk/sunxi/clk-a10-csi.c
> @@ -0,0 +1,188 @@
> +/*
> + * Copyright 2016 Yassin Jaffer
> + *
> + * Yassin Jaffer <yassinjaffer@gmail.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/of_address.h>
> +#include <linux/reset-controller.h>
> +#include <linux/slab.h>
> +#include <linux/spinlock.h>
> +
> +static DEFINE_SPINLOCK(sun4i_csi_lock);
> +
> +#define SUN4I_CSI_PARENTS       5
> +#define SUN4I_CSI_GATE_BIT      31
> +#define SUN4I_CSI_RESET_BIT     30
> +#define SUN4I_CSI_MUX_SHIFT     24
> +#define SUN4I_CSI_DIV_WIDTH     5
> +#define SUN4I_CSI_DIV_SHIFT     0
> +
> +static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = {
> +	0x0,
> +	0x1,
> +	0x2,
> +	0x5,
> +	0x6,
> +};
> +
> +struct csi_reset_data {
> +	void __iomem			*reg;
> +	spinlock_t			*lock; /* lock for reset handling */
> +	struct reset_controller_dev	rcdev;
> +};
> +
> +static int sun4i_csi_assert(struct reset_controller_dev *rcdev,
> +			    unsigned long id)
> +{
> +	struct csi_reset_data *data = container_of(rcdev,
> +						  struct csi_reset_data,
> +						  rcdev);
> +	unsigned long flags;
> +	u32 reg;
> +
> +	spin_lock_irqsave(data->lock, flags);
> +
> +	reg = readl(data->reg);
> +	writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg);
> +
> +	spin_unlock_irqrestore(data->lock, flags);
> +
> +	return 0;
> +}
> +
> +static int sun4i_csi_deassert(struct reset_controller_dev *rcdev,
> +			      unsigned long id)
> +{
> +	struct csi_reset_data *data = container_of(rcdev,
> +						  struct csi_reset_data,
> +						  rcdev);
> +	unsigned long flags;
> +	u32 reg;
> +
> +	spin_lock_irqsave(data->lock, flags);
> +
> +	reg = readl(data->reg);
> +	writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg);
> +
> +	spin_unlock_irqrestore(data->lock, flags);
> +
> +	return 0;
> +}
> +
> +static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev,
> +			      const struct of_phandle_args *reset_spec)
> +{
> +	if (WARN_ON(reset_spec->args_count != 0))
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +static struct reset_control_ops sun4i_csi_reset_ops = {
> +	.assert		= sun4i_csi_assert,
> +	.deassert	= sun4i_csi_deassert,
> +};
> +
> +static void __init sun4i_csi_clk_setup(struct device_node *node)
> +{
> +	const char *parents[SUN4I_CSI_PARENTS];
> +	const char *clk_name = node->name;
> +	struct csi_reset_data *reset_data;
> +	struct clk_divider *div;
> +	struct clk_gate *gate;
> +	struct clk_mux *mux;
> +	void __iomem *reg;
> +	struct clk *clk;
> +	int i = 0;
> +
> +	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
> +	if (IS_ERR(reg))
> +		return;
> +
> +	of_property_read_string(node, "clock-output-names", &clk_name);
> +
> +	i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS);
> +
> +	mux = kzalloc(sizeof(*mux), GFP_KERNEL);
> +	if (!mux)
> +		goto err_unmap;
> +
> +	mux->reg = reg;
> +	mux->shift = SUN4I_CSI_MUX_SHIFT;
> +	mux->table = sun4i_csi_mux_table;
> +	mux->lock = &sun4i_csi_lock;
> +
> +	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
> +	if (!gate)
> +		goto err_free_mux;
> +
> +	gate->reg = reg;
> +	gate->bit_idx = SUN4I_CSI_GATE_BIT;
> +	gate->lock = &sun4i_csi_lock;
> +
> +	div = kzalloc(sizeof(*div), GFP_KERNEL);
> +	if (!div)
> +		goto err_free_gate;
> +
> +	div->reg = reg;
> +	div->shift = SUN4I_CSI_DIV_SHIFT;
> +	div->width = SUN4I_CSI_DIV_WIDTH;
> +	div->lock = &sun4i_csi_lock;
> +
> +	clk = clk_register_composite(NULL, clk_name,
> +				     parents, i,
> +				     &mux->hw, &clk_mux_ops,
> +				     &div->hw, &clk_divider_ops,
> +				     &gate->hw, &clk_gate_ops,
> +				     CLK_SET_RATE_PARENT);
> +	if (IS_ERR(clk))
> +		goto err_free_div;
> +
> +	of_clk_add_provider(node, of_clk_src_simple_get, clk);
> +
> +	reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL);
> +	if (!reset_data)
> +		goto err_free_clk;
> +
> +	reset_data->reg = reg;
> +	reset_data->lock = &sun4i_csi_lock;
> +	reset_data->rcdev.nr_resets = 1;
> +	reset_data->rcdev.ops = &sun4i_csi_reset_ops;
> +	reset_data->rcdev.of_node = node;
> +	reset_data->rcdev.of_xlate = sun4i_csi_of_xlate;
> +	reset_data->rcdev.of_reset_n_cells = 0;
> +
> +	if (reset_controller_register(&reset_data->rcdev))
> +		goto err_free_reset;
> +
> +	return;
> +
> +err_free_reset:
> +	kfree(reset_data);
> +err_free_clk:
> +	clk_unregister(clk);
> +err_free_div:
> +	kfree(div);
> +err_free_gate:
> +	kfree(gate);
> +err_free_mux:
> +	kfree(mux);
> +err_unmap:
> +	iounmap(reg);
> +}
> +
> +CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk",
> +	       sun4i_csi_clk_setup);
> +

That's great, but it shares a lot of infrastructure of boilerplate
code with the display clocks that are part of my DRM serie.

I plan to post them early next week, I'll cc you so that you can base
your clock on top of it.

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160318/3a8fbff3/attachment.sig>

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
  2016-03-17  8:43   ` yassinjaffer
@ 2016-03-19 23:59     ` Rob Herring
  -1 siblings, 0 replies; 19+ messages in thread
From: Rob Herring @ 2016-03-19 23:59 UTC (permalink / raw)
  To: yassinjaffer
  Cc: dev, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	Maxime Ripard, Chen-Yu Tsai, Emilio López,
	Michael Turquette, Stephen Boyd, Hans de Goede, Reinder de Haan,
	Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer@gmail.com wrote:
> From: Yassin Jaffer <yassinjaffer@gmail.com>
> 
> This patch adds a composite clock type consisting of
> a clock gate, mux, configurable dividers, and a reset control.
> 
> Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> ---
>  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +

I wish someone would just add all the sunxi clocks in one pass instead 
of one by one.

Acked-by: Rob Herring <robh@kernel.org>

>  drivers/clk/sunxi/Makefile                        |   1 +
>  drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
>  3 files changed, 190 insertions(+)
>  create mode 100644 drivers/clk/sunxi/clk-a10-csi.c

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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-03-19 23:59     ` Rob Herring
  0 siblings, 0 replies; 19+ messages in thread
From: Rob Herring @ 2016-03-19 23:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer at gmail.com wrote:
> From: Yassin Jaffer <yassinjaffer@gmail.com>
> 
> This patch adds a composite clock type consisting of
> a clock gate, mux, configurable dividers, and a reset control.
> 
> Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> ---
>  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +

I wish someone would just add all the sunxi clocks in one pass instead 
of one by one.

Acked-by: Rob Herring <robh@kernel.org>

>  drivers/clk/sunxi/Makefile                        |   1 +
>  drivers/clk/sunxi/clk-a10-csi.c                   | 188 ++++++++++++++++++++++
>  3 files changed, 190 insertions(+)
>  create mode 100644 drivers/clk/sunxi/clk-a10-csi.c

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
  2016-03-19 23:59     ` Rob Herring
@ 2016-04-02  1:14       ` Stephen Boyd
  -1 siblings, 0 replies; 19+ messages in thread
From: Stephen Boyd @ 2016-04-02  1:14 UTC (permalink / raw)
  To: Rob Herring
  Cc: yassinjaffer, dev, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Maxime Ripard, Chen-Yu Tsai, Emilio López,
	Michael Turquette, Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

On 03/19, Rob Herring wrote:
> On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer@gmail.com wrote:
> > From: Yassin Jaffer <yassinjaffer@gmail.com>
> > 
> > This patch adds a composite clock type consisting of
> > a clock gate, mux, configurable dividers, and a reset control.
> > 
> > Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> > ---
> >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
> 
> I wish someone would just add all the sunxi clocks in one pass instead 
> of one by one.
> 
> Acked-by: Rob Herring <robh@kernel.org>

Me too!

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-04-02  1:14       ` Stephen Boyd
  0 siblings, 0 replies; 19+ messages in thread
From: Stephen Boyd @ 2016-04-02  1:14 UTC (permalink / raw)
  To: linux-arm-kernel

On 03/19, Rob Herring wrote:
> On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer at gmail.com wrote:
> > From: Yassin Jaffer <yassinjaffer@gmail.com>
> > 
> > This patch adds a composite clock type consisting of
> > a clock gate, mux, configurable dividers, and a reset control.
> > 
> > Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> > ---
> >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
> 
> I wish someone would just add all the sunxi clocks in one pass instead 
> of one by one.
> 
> Acked-by: Rob Herring <robh@kernel.org>

Me too!

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-04-04 21:24         ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-04-04 21:24 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Rob Herring, yassinjaffer, dev, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Chen-Yu Tsai, Emilio López,
	Michael Turquette, Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 1242 bytes --]

Hi Stephen

On Fri, Apr 01, 2016 at 06:14:36PM -0700, Stephen Boyd wrote:
> On 03/19, Rob Herring wrote:
> > On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer@gmail.com wrote:
> > > From: Yassin Jaffer <yassinjaffer@gmail.com>
> > > 
> > > This patch adds a composite clock type consisting of
> > > a clock gate, mux, configurable dividers, and a reset control.
> > > 
> > > Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> > > ---
> > >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
> > 
> > I wish someone would just add all the sunxi clocks in one pass instead 
> > of one by one.
> > 
> > Acked-by: Rob Herring <robh@kernel.org>
> 
> Me too!

I understand, but it's probably not going to happen. The clock tree is
massive, and obviously you have to multiply that by the number of SoCs
we have.

And to be honest, I don't really see the point of merging clock
drivers that have never been tested, and might be massively broken,
especially now that we have this ABI requirement for the DT, and we
can't adjust the binding when we actually start using that clock.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-04-04 21:24         ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-04-04 21:24 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Rob Herring, yassinjaffer-Re5JQEeQqe8AvxtiuMwx3w,
	dev-3kdeTeqwOZ9EV1b7eY7vFQ, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Chen-Yu Tsai, Emilio López,
	Michael Turquette, Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 1324 bytes --]

Hi Stephen

On Fri, Apr 01, 2016 at 06:14:36PM -0700, Stephen Boyd wrote:
> On 03/19, Rob Herring wrote:
> > On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
> > > From: Yassin Jaffer <yassinjaffer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > 
> > > This patch adds a composite clock type consisting of
> > > a clock gate, mux, configurable dividers, and a reset control.
> > > 
> > > Signed-off-by: Yassin Jaffer <yassinjaffer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > ---
> > >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
> > 
> > I wish someone would just add all the sunxi clocks in one pass instead 
> > of one by one.
> > 
> > Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> 
> Me too!

I understand, but it's probably not going to happen. The clock tree is
massive, and obviously you have to multiply that by the number of SoCs
we have.

And to be honest, I don't really see the point of merging clock
drivers that have never been tested, and might be massively broken,
especially now that we have this ABI requirement for the DT, and we
can't adjust the binding when we actually start using that clock.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-04-04 21:24         ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-04-04 21:24 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Stephen

On Fri, Apr 01, 2016 at 06:14:36PM -0700, Stephen Boyd wrote:
> On 03/19, Rob Herring wrote:
> > On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassinjaffer at gmail.com wrote:
> > > From: Yassin Jaffer <yassinjaffer@gmail.com>
> > > 
> > > This patch adds a composite clock type consisting of
> > > a clock gate, mux, configurable dividers, and a reset control.
> > > 
> > > Signed-off-by: Yassin Jaffer <yassinjaffer@gmail.com>
> > > ---
> > >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 +
> > 
> > I wish someone would just add all the sunxi clocks in one pass instead 
> > of one by one.
> > 
> > Acked-by: Rob Herring <robh@kernel.org>
> 
> Me too!

I understand, but it's probably not going to happen. The clock tree is
massive, and obviously you have to multiply that by the number of SoCs
we have.

And to be honest, I don't really see the point of merging clock
drivers that have never been tested, and might be massively broken,
especially now that we have this ABI requirement for the DT, and we
can't adjust the binding when we actually start using that clock.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160404/8ab7147b/attachment.sig>

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
  2016-03-18 19:25     ` Maxime Ripard
@ 2016-04-07 11:55       ` Yassin Jaffer
  -1 siblings, 0 replies; 19+ messages in thread
From: Yassin Jaffer @ 2016-04-07 11:55 UTC (permalink / raw)
  To: linux-sunxi
  Cc: dev-3kdeTeqwOZ9EV1b7eY7vFQ, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, mark.rutland-5wv7dgnIgG8,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	galak-sgV2jX0FEOL9JmXXK+q4OQ, wens-jdAy2FN1RRM,
	emilio-0Z03zUJReD5OxF6Tv1QG9Q, mturquette-rdvid1DuHRBWk0Htik3J/w,
	sboyd-sgV2jX0FEOL9JmXXK+q4OQ, hdegoede-H+wXaHxf7aLQT0dZR+AlfA,
	patchesrdh-I1/eAgTnXDYAvxtiuMwx3w,
	jenskuske-Re5JQEeQqe8AvxtiuMwx3w,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-clk-u79uwXL29TY76Z2rM5mHXA


[-- Attachment #1.1: Type: text/plain, Size: 9999 bytes --]

Hi Maxime

I had a look at your display clock driver.The only issue I have is setting 
the clock parents. A simple mask wont do it. 
I guess using table is the only way. The CSI is only clock which is using 
irregular parents mux. The remaining clocks
including VE, can be based on your display clock driver. 
Thanx.

On Monday, March 21, 2016 at 7:42:48 PM UTC+11, Maxime Ripard wrote:
>
> Hi Yassin, 
>
> On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 
> <javascript:> wrote: 
> > From: Yassin Jaffer <yassin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> 
> > 
> > This patch adds a composite clock type consisting of 
> > a clock gate, mux, configurable dividers, and a reset control. 
> > 
> > Signed-off-by: Yassin Jaffer <yassin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> 
> > --- 
> >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 + 
> >  drivers/clk/sunxi/Makefile                        |   1 + 
> >  drivers/clk/sunxi/clk-a10-csi.c                   | 188 
> ++++++++++++++++++++++ 
> >  3 files changed, 190 insertions(+) 
> >  create mode 100644 drivers/clk/sunxi/clk-a10-csi.c 
> > 
> > diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt 
> b/Documentation/devicetree/bindings/clock/sunxi.txt 
> > index e59f57b..c3826f7 100644 
> > --- a/Documentation/devicetree/bindings/clock/sunxi.txt 
> > +++ b/Documentation/devicetree/bindings/clock/sunxi.txt 
> > @@ -77,6 +77,7 @@ Required properties: 
> >          "allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on 
> A80 
> >          "allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets 
> on A80 
> >          "allwinner,sun4i-a10-ve-clk" - for the Video Engine clock 
> > +        "allwinner,sun4i-a10-csi-clk" - for the CSI module 
> >   
> >  Required properties for all clocks: 
> >  - reg : shall be the control register address for the clock. 
> > diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile 
> > index 3fd7901..42ce752 100644 
> > --- a/drivers/clk/sunxi/Makefile 
> > +++ b/drivers/clk/sunxi/Makefile 
> > @@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o 
> >  obj-y += clk-a10-hosc.o 
> >  obj-y += clk-a10-mod1.o 
> >  obj-y += clk-a10-pll2.o 
> > +obj-y += clk-a10-csi.o 
> >  obj-y += clk-a10-ve.o 
> >  obj-y += clk-a20-gmac.o 
> >  obj-y += clk-mod0.o 
> > diff --git a/drivers/clk/sunxi/clk-a10-csi.c 
> b/drivers/clk/sunxi/clk-a10-csi.c 
> > new file mode 100644 
> > index 0000000..f17d206 
> > --- /dev/null 
> > +++ b/drivers/clk/sunxi/clk-a10-csi.c 
> > @@ -0,0 +1,188 @@ 
> > +/* 
> > + * Copyright 2016 Yassin Jaffer 
> > + * 
> > + * Yassin Jaffer <yassin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> 
> > + * 
> > + * This program is free software; you can redistribute it and/or modify 
> > + * it under the terms of the GNU General Public License as published by 
> > + * the Free Software Foundation; either version 2 of the License, or 
> > + * (at your option) any later version. 
> > + * 
> > + * This program is distributed in the hope that it will be useful, 
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of 
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
> > + * GNU General Public License for more details. 
> > + */ 
> > + 
> > +#include <linux/clk-provider.h> 
> > +#include <linux/of_address.h> 
> > +#include <linux/reset-controller.h> 
> > +#include <linux/slab.h> 
> > +#include <linux/spinlock.h> 
> > + 
> > +static DEFINE_SPINLOCK(sun4i_csi_lock); 
> > + 
> > +#define SUN4I_CSI_PARENTS       5 
> > +#define SUN4I_CSI_GATE_BIT      31 
> > +#define SUN4I_CSI_RESET_BIT     30 
> > +#define SUN4I_CSI_MUX_SHIFT     24 
> > +#define SUN4I_CSI_DIV_WIDTH     5 
> > +#define SUN4I_CSI_DIV_SHIFT     0 
> > + 
> > +static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = { 
> > +        0x0, 
> > +        0x1, 
> > +        0x2, 
> > +        0x5, 
> > +        0x6, 
> > +}; 
> > + 
> > +struct csi_reset_data { 
> > +        void __iomem                        *reg; 
> > +        spinlock_t                        *lock; /* lock for reset 
> handling */ 
> > +        struct reset_controller_dev        rcdev; 
> > +}; 
> > + 
> > +static int sun4i_csi_assert(struct reset_controller_dev *rcdev, 
> > +                            unsigned long id) 
> > +{ 
> > +        struct csi_reset_data *data = container_of(rcdev, 
> > +                                                  struct 
> csi_reset_data, 
> > +                                                  rcdev); 
> > +        unsigned long flags; 
> > +        u32 reg; 
> > + 
> > +        spin_lock_irqsave(data->lock, flags); 
> > + 
> > +        reg = readl(data->reg); 
> > +        writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg); 
> > + 
> > +        spin_unlock_irqrestore(data->lock, flags); 
> > + 
> > +        return 0; 
> > +} 
> > + 
> > +static int sun4i_csi_deassert(struct reset_controller_dev *rcdev, 
> > +                              unsigned long id) 
> > +{ 
> > +        struct csi_reset_data *data = container_of(rcdev, 
> > +                                                  struct 
> csi_reset_data, 
> > +                                                  rcdev); 
> > +        unsigned long flags; 
> > +        u32 reg; 
> > + 
> > +        spin_lock_irqsave(data->lock, flags); 
> > + 
> > +        reg = readl(data->reg); 
> > +        writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg); 
> > + 
> > +        spin_unlock_irqrestore(data->lock, flags); 
> > + 
> > +        return 0; 
> > +} 
> > + 
> > +static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev, 
> > +                              const struct of_phandle_args *reset_spec) 
> > +{ 
> > +        if (WARN_ON(reset_spec->args_count != 0)) 
> > +                return -EINVAL; 
> > + 
> > +        return 0; 
> > +} 
> > + 
> > +static struct reset_control_ops sun4i_csi_reset_ops = { 
> > +        .assert                = sun4i_csi_assert, 
> > +        .deassert        = sun4i_csi_deassert, 
> > +}; 
> > + 
> > +static void __init sun4i_csi_clk_setup(struct device_node *node) 
> > +{ 
> > +        const char *parents[SUN4I_CSI_PARENTS]; 
> > +        const char *clk_name = node->name; 
> > +        struct csi_reset_data *reset_data; 
> > +        struct clk_divider *div; 
> > +        struct clk_gate *gate; 
> > +        struct clk_mux *mux; 
> > +        void __iomem *reg; 
> > +        struct clk *clk; 
> > +        int i = 0; 
> > + 
> > +        reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 
> > +        if (IS_ERR(reg)) 
> > +                return; 
> > + 
> > +        of_property_read_string(node, "clock-output-names", &clk_name); 
> > + 
> > +        i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS); 
> > + 
> > +        mux = kzalloc(sizeof(*mux), GFP_KERNEL); 
> > +        if (!mux) 
> > +                goto err_unmap; 
> > + 
> > +        mux->reg = reg; 
> > +        mux->shift = SUN4I_CSI_MUX_SHIFT; 
> > +        mux->table = sun4i_csi_mux_table; 
> > +        mux->lock = &sun4i_csi_lock; 
> > + 
> > +        gate = kzalloc(sizeof(*gate), GFP_KERNEL); 
> > +        if (!gate) 
> > +                goto err_free_mux; 
> > + 
> > +        gate->reg = reg; 
> > +        gate->bit_idx = SUN4I_CSI_GATE_BIT; 
> > +        gate->lock = &sun4i_csi_lock; 
> > + 
> > +        div = kzalloc(sizeof(*div), GFP_KERNEL); 
> > +        if (!div) 
> > +                goto err_free_gate; 
> > + 
> > +        div->reg = reg; 
> > +        div->shift = SUN4I_CSI_DIV_SHIFT; 
> > +        div->width = SUN4I_CSI_DIV_WIDTH; 
> > +        div->lock = &sun4i_csi_lock; 
> > + 
> > +        clk = clk_register_composite(NULL, clk_name, 
> > +                                     parents, i, 
> > +                                     &mux->hw, &clk_mux_ops, 
> > +                                     &div->hw, &clk_divider_ops, 
> > +                                     &gate->hw, &clk_gate_ops, 
> > +                                     CLK_SET_RATE_PARENT); 
> > +        if (IS_ERR(clk)) 
> > +                goto err_free_div; 
> > + 
> > +        of_clk_add_provider(node, of_clk_src_simple_get, clk); 
> > + 
> > +        reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL); 
> > +        if (!reset_data) 
> > +                goto err_free_clk; 
> > + 
> > +        reset_data->reg = reg; 
> > +        reset_data->lock = &sun4i_csi_lock; 
> > +        reset_data->rcdev.nr_resets = 1; 
> > +        reset_data->rcdev.ops = &sun4i_csi_reset_ops; 
> > +        reset_data->rcdev.of_node = node; 
> > +        reset_data->rcdev.of_xlate = sun4i_csi_of_xlate; 
> > +        reset_data->rcdev.of_reset_n_cells = 0; 
> > + 
> > +        if (reset_controller_register(&reset_data->rcdev)) 
> > +                goto err_free_reset; 
> > + 
> > +        return; 
> > + 
> > +err_free_reset: 
> > +        kfree(reset_data); 
> > +err_free_clk: 
> > +        clk_unregister(clk); 
> > +err_free_div: 
> > +        kfree(div); 
> > +err_free_gate: 
> > +        kfree(gate); 
> > +err_free_mux: 
> > +        kfree(mux); 
> > +err_unmap: 
> > +        iounmap(reg); 
> > +} 
> > + 
> > +CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk", 
> > +               sun4i_csi_clk_setup); 
> > + 
>
> That's great, but it shares a lot of infrastructure of boilerplate 
> code with the display clocks that are part of my DRM serie. 
>
> I plan to post them early next week, I'll cc you so that you can base 
> your clock on top of it. 
>
> Thanks! 
> Maxime 
>
> -- 
> Maxime Ripard, Free Electrons 
> Embedded Linux, Kernel and Android engineering 
> http://free-electrons.com 
>

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 14382 bytes --]

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-04-07 11:55       ` Yassin Jaffer
  0 siblings, 0 replies; 19+ messages in thread
From: Yassin Jaffer @ 2016-04-07 11:55 UTC (permalink / raw)
  To: linux-sunxi
  Cc: dev, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak,
	wens, emilio, mturquette, sboyd, hdegoede, patchesrdh, jenskuske,
	devicetree, linux-arm-kernel, linux-kernel, linux-clk


[-- Attachment #1.1: Type: text/plain, Size: 9562 bytes --]

Hi Maxime

I had a look at your display clock driver.The only issue I have is setting 
the clock parents. A simple mask wont do it. 
I guess using table is the only way. The CSI is only clock which is using 
irregular parents mux. The remaining clocks
including VE, can be based on your display clock driver. 
Thanx.

On Monday, March 21, 2016 at 7:42:48 PM UTC+11, Maxime Ripard wrote:
>
> Hi Yassin, 
>
> On Thu, Mar 17, 2016 at 07:43:42PM +1100, yassin...@gmail.com 
> <javascript:> wrote: 
> > From: Yassin Jaffer <yassin...@gmail.com <javascript:>> 
> > 
> > This patch adds a composite clock type consisting of 
> > a clock gate, mux, configurable dividers, and a reset control. 
> > 
> > Signed-off-by: Yassin Jaffer <yassin...@gmail.com <javascript:>> 
> > --- 
> >  Documentation/devicetree/bindings/clock/sunxi.txt |   1 + 
> >  drivers/clk/sunxi/Makefile                        |   1 + 
> >  drivers/clk/sunxi/clk-a10-csi.c                   | 188 
> ++++++++++++++++++++++ 
> >  3 files changed, 190 insertions(+) 
> >  create mode 100644 drivers/clk/sunxi/clk-a10-csi.c 
> > 
> > diff --git a/Documentation/devicetree/bindings/clock/sunxi.txt 
> b/Documentation/devicetree/bindings/clock/sunxi.txt 
> > index e59f57b..c3826f7 100644 
> > --- a/Documentation/devicetree/bindings/clock/sunxi.txt 
> > +++ b/Documentation/devicetree/bindings/clock/sunxi.txt 
> > @@ -77,6 +77,7 @@ Required properties: 
> >          "allwinner,sun9i-a80-usb-mod-clk" - for usb gates + resets on 
> A80 
> >          "allwinner,sun9i-a80-usb-phy-clk" - for usb phy gates + resets 
> on A80 
> >          "allwinner,sun4i-a10-ve-clk" - for the Video Engine clock 
> > +        "allwinner,sun4i-a10-csi-clk" - for the CSI module 
> >   
> >  Required properties for all clocks: 
> >  - reg : shall be the control register address for the clock. 
> > diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile 
> > index 3fd7901..42ce752 100644 
> > --- a/drivers/clk/sunxi/Makefile 
> > +++ b/drivers/clk/sunxi/Makefile 
> > @@ -7,6 +7,7 @@ obj-y += clk-a10-codec.o 
> >  obj-y += clk-a10-hosc.o 
> >  obj-y += clk-a10-mod1.o 
> >  obj-y += clk-a10-pll2.o 
> > +obj-y += clk-a10-csi.o 
> >  obj-y += clk-a10-ve.o 
> >  obj-y += clk-a20-gmac.o 
> >  obj-y += clk-mod0.o 
> > diff --git a/drivers/clk/sunxi/clk-a10-csi.c 
> b/drivers/clk/sunxi/clk-a10-csi.c 
> > new file mode 100644 
> > index 0000000..f17d206 
> > --- /dev/null 
> > +++ b/drivers/clk/sunxi/clk-a10-csi.c 
> > @@ -0,0 +1,188 @@ 
> > +/* 
> > + * Copyright 2016 Yassin Jaffer 
> > + * 
> > + * Yassin Jaffer <yassin...@gmail.com <javascript:>> 
> > + * 
> > + * This program is free software; you can redistribute it and/or modify 
> > + * it under the terms of the GNU General Public License as published by 
> > + * the Free Software Foundation; either version 2 of the License, or 
> > + * (at your option) any later version. 
> > + * 
> > + * This program is distributed in the hope that it will be useful, 
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of 
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
> > + * GNU General Public License for more details. 
> > + */ 
> > + 
> > +#include <linux/clk-provider.h> 
> > +#include <linux/of_address.h> 
> > +#include <linux/reset-controller.h> 
> > +#include <linux/slab.h> 
> > +#include <linux/spinlock.h> 
> > + 
> > +static DEFINE_SPINLOCK(sun4i_csi_lock); 
> > + 
> > +#define SUN4I_CSI_PARENTS       5 
> > +#define SUN4I_CSI_GATE_BIT      31 
> > +#define SUN4I_CSI_RESET_BIT     30 
> > +#define SUN4I_CSI_MUX_SHIFT     24 
> > +#define SUN4I_CSI_DIV_WIDTH     5 
> > +#define SUN4I_CSI_DIV_SHIFT     0 
> > + 
> > +static u32 sun4i_csi_mux_table[SUN4I_CSI_PARENTS] = { 
> > +        0x0, 
> > +        0x1, 
> > +        0x2, 
> > +        0x5, 
> > +        0x6, 
> > +}; 
> > + 
> > +struct csi_reset_data { 
> > +        void __iomem                        *reg; 
> > +        spinlock_t                        *lock; /* lock for reset 
> handling */ 
> > +        struct reset_controller_dev        rcdev; 
> > +}; 
> > + 
> > +static int sun4i_csi_assert(struct reset_controller_dev *rcdev, 
> > +                            unsigned long id) 
> > +{ 
> > +        struct csi_reset_data *data = container_of(rcdev, 
> > +                                                  struct 
> csi_reset_data, 
> > +                                                  rcdev); 
> > +        unsigned long flags; 
> > +        u32 reg; 
> > + 
> > +        spin_lock_irqsave(data->lock, flags); 
> > + 
> > +        reg = readl(data->reg); 
> > +        writel(reg & ~BIT(SUN4I_CSI_RESET_BIT), data->reg); 
> > + 
> > +        spin_unlock_irqrestore(data->lock, flags); 
> > + 
> > +        return 0; 
> > +} 
> > + 
> > +static int sun4i_csi_deassert(struct reset_controller_dev *rcdev, 
> > +                              unsigned long id) 
> > +{ 
> > +        struct csi_reset_data *data = container_of(rcdev, 
> > +                                                  struct 
> csi_reset_data, 
> > +                                                  rcdev); 
> > +        unsigned long flags; 
> > +        u32 reg; 
> > + 
> > +        spin_lock_irqsave(data->lock, flags); 
> > + 
> > +        reg = readl(data->reg); 
> > +        writel(reg | BIT(SUN4I_CSI_RESET_BIT), data->reg); 
> > + 
> > +        spin_unlock_irqrestore(data->lock, flags); 
> > + 
> > +        return 0; 
> > +} 
> > + 
> > +static int sun4i_csi_of_xlate(struct reset_controller_dev *rcdev, 
> > +                              const struct of_phandle_args *reset_spec) 
> > +{ 
> > +        if (WARN_ON(reset_spec->args_count != 0)) 
> > +                return -EINVAL; 
> > + 
> > +        return 0; 
> > +} 
> > + 
> > +static struct reset_control_ops sun4i_csi_reset_ops = { 
> > +        .assert                = sun4i_csi_assert, 
> > +        .deassert        = sun4i_csi_deassert, 
> > +}; 
> > + 
> > +static void __init sun4i_csi_clk_setup(struct device_node *node) 
> > +{ 
> > +        const char *parents[SUN4I_CSI_PARENTS]; 
> > +        const char *clk_name = node->name; 
> > +        struct csi_reset_data *reset_data; 
> > +        struct clk_divider *div; 
> > +        struct clk_gate *gate; 
> > +        struct clk_mux *mux; 
> > +        void __iomem *reg; 
> > +        struct clk *clk; 
> > +        int i = 0; 
> > + 
> > +        reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 
> > +        if (IS_ERR(reg)) 
> > +                return; 
> > + 
> > +        of_property_read_string(node, "clock-output-names", &clk_name); 
> > + 
> > +        i = of_clk_parent_fill(node, parents, SUN4I_CSI_PARENTS); 
> > + 
> > +        mux = kzalloc(sizeof(*mux), GFP_KERNEL); 
> > +        if (!mux) 
> > +                goto err_unmap; 
> > + 
> > +        mux->reg = reg; 
> > +        mux->shift = SUN4I_CSI_MUX_SHIFT; 
> > +        mux->table = sun4i_csi_mux_table; 
> > +        mux->lock = &sun4i_csi_lock; 
> > + 
> > +        gate = kzalloc(sizeof(*gate), GFP_KERNEL); 
> > +        if (!gate) 
> > +                goto err_free_mux; 
> > + 
> > +        gate->reg = reg; 
> > +        gate->bit_idx = SUN4I_CSI_GATE_BIT; 
> > +        gate->lock = &sun4i_csi_lock; 
> > + 
> > +        div = kzalloc(sizeof(*div), GFP_KERNEL); 
> > +        if (!div) 
> > +                goto err_free_gate; 
> > + 
> > +        div->reg = reg; 
> > +        div->shift = SUN4I_CSI_DIV_SHIFT; 
> > +        div->width = SUN4I_CSI_DIV_WIDTH; 
> > +        div->lock = &sun4i_csi_lock; 
> > + 
> > +        clk = clk_register_composite(NULL, clk_name, 
> > +                                     parents, i, 
> > +                                     &mux->hw, &clk_mux_ops, 
> > +                                     &div->hw, &clk_divider_ops, 
> > +                                     &gate->hw, &clk_gate_ops, 
> > +                                     CLK_SET_RATE_PARENT); 
> > +        if (IS_ERR(clk)) 
> > +                goto err_free_div; 
> > + 
> > +        of_clk_add_provider(node, of_clk_src_simple_get, clk); 
> > + 
> > +        reset_data = kzalloc(sizeof(*reset_data), GFP_KERNEL); 
> > +        if (!reset_data) 
> > +                goto err_free_clk; 
> > + 
> > +        reset_data->reg = reg; 
> > +        reset_data->lock = &sun4i_csi_lock; 
> > +        reset_data->rcdev.nr_resets = 1; 
> > +        reset_data->rcdev.ops = &sun4i_csi_reset_ops; 
> > +        reset_data->rcdev.of_node = node; 
> > +        reset_data->rcdev.of_xlate = sun4i_csi_of_xlate; 
> > +        reset_data->rcdev.of_reset_n_cells = 0; 
> > + 
> > +        if (reset_controller_register(&reset_data->rcdev)) 
> > +                goto err_free_reset; 
> > + 
> > +        return; 
> > + 
> > +err_free_reset: 
> > +        kfree(reset_data); 
> > +err_free_clk: 
> > +        clk_unregister(clk); 
> > +err_free_div: 
> > +        kfree(div); 
> > +err_free_gate: 
> > +        kfree(gate); 
> > +err_free_mux: 
> > +        kfree(mux); 
> > +err_unmap: 
> > +        iounmap(reg); 
> > +} 
> > + 
> > +CLK_OF_DECLARE(sun4i_csi, "allwinner,sun4i-a10-csi-clk", 
> > +               sun4i_csi_clk_setup); 
> > + 
>
> That's great, but it shares a lot of infrastructure of boilerplate 
> code with the display clocks that are part of my DRM serie. 
>
> I plan to post them early next week, I'll cc you so that you can base 
> your clock on top of it. 
>
> Thanks! 
> Maxime 
>
> -- 
> Maxime Ripard, Free Electrons 
> Embedded Linux, Kernel and Android engineering 
> http://free-electrons.com 
>

[-- Attachment #1.2: Type: text/html, Size: 13940 bytes --]

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
  2016-04-04 21:24         ` Maxime Ripard
@ 2016-07-10 17:07           ` Hao Zhang
  -1 siblings, 0 replies; 19+ messages in thread
From: Hao Zhang @ 2016-07-10 17:07 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Stephen Boyd, Rob Herring, yassinjaffer-Re5JQEeQqe8AvxtiuMwx3w,
	dev-3kdeTeqwOZ9EV1b7eY7vFQ, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Chen-Yu Tsai, Emilio López,
	Michael Turquette, Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

Hi all
I am developing a media codec driver(using bt656) for cubieboard
one(allwinner a10 processor), i want to use DT to banding csi. after i get
some reference on
Documentation/devicetree/bindings/media/video-interfaces.txt, i have some
question about whether the csi driver for cubieboard one support to parse
the DT node just like in the reference document? if not, whether someone
is developing it or should i necessary to complete it together (What's the
progress of it) ?

Best regards :)
Hao Zhang

-- 
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 1136 bytes --]

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-07-10 17:07           ` Hao Zhang
  0 siblings, 0 replies; 19+ messages in thread
From: Hao Zhang @ 2016-07-10 17:07 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Stephen Boyd, Rob Herring, yassinjaffer, dev, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala, Chen-Yu Tsai,
	Emilio López, Michael Turquette, Hans de Goede,
	Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

Hi all
I am developing a media codec driver(using bt656) for cubieboard
one(allwinner a10 processor), i want to use DT to banding csi. after i get
some reference on
Documentation/devicetree/bindings/media/video-interfaces.txt, i have some
question about whether the csi driver for cubieboard one support to parse
the DT node just like in the reference document? if not, whether someone
is developing it or should i necessary to complete it together (What's the
progress of it) ?

Best regards :)
Hao Zhang

[-- Attachment #2: Type: text/html, Size: 644 bytes --]

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-07-13 20:52             ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-07-13 20:52 UTC (permalink / raw)
  To: Hao Zhang
  Cc: Stephen Boyd, Rob Herring, yassinjaffer, dev, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala, Chen-Yu Tsai,
	Emilio López, Michael Turquette, Hans de Goede,
	Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 816 bytes --]

Hi,

On Mon, Jul 11, 2016 at 01:07:26AM +0800, Hao Zhang wrote:
> Hi all
> I am developing a media codec driver(using bt656) for cubieboard
> one(allwinner a10 processor), i want to use DT to banding csi. after i get
> some reference on
> Documentation/devicetree/bindings/media/video-interfaces.txt, i have some
> question about whether the csi driver for cubieboard one support to parse
> the DT node just like in the reference document? if not, whether someone
> is developing it or should i necessary to complete it together (What's the
> progress of it) ?

There's no driver for it yet. We're currently working on it, so it's
probably going to be done soon, but it's not there yet.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-07-13 20:52             ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-07-13 20:52 UTC (permalink / raw)
  To: Hao Zhang
  Cc: Stephen Boyd, Rob Herring, yassinjaffer-Re5JQEeQqe8AvxtiuMwx3w,
	dev-3kdeTeqwOZ9EV1b7eY7vFQ, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Chen-Yu Tsai, Emilio López,
	Michael Turquette, Hans de Goede, Reinder de Haan, Jens Kuske,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/Allwinner sunXi SoC support, open list,
	open list:COMMON CLK FRAMEWORK

[-- Attachment #1: Type: text/plain, Size: 793 bytes --]

Hi,

On Mon, Jul 11, 2016 at 01:07:26AM +0800, Hao Zhang wrote:
> Hi all
> I am developing a media codec driver(using bt656) for cubieboard
> one(allwinner a10 processor), i want to use DT to banding csi. after i get
> some reference on
> Documentation/devicetree/bindings/media/video-interfaces.txt, i have some
> question about whether the csi driver for cubieboard one support to parse
> the DT node just like in the reference document? if not, whether someone
> is developing it or should i necessary to complete it together (What's the
> progress of it) ?

There's no driver for it yet. We're currently working on it, so it's
probably going to be done soon, but it's not there yet.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i
@ 2016-07-13 20:52             ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2016-07-13 20:52 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Mon, Jul 11, 2016 at 01:07:26AM +0800, Hao Zhang wrote:
> Hi all
> I am developing a media codec driver(using bt656) for cubieboard
> one(allwinner a10 processor), i want to use DT to banding csi. after i get
> some reference on
> Documentation/devicetree/bindings/media/video-interfaces.txt, i have some
> question about whether the csi driver for cubieboard one support to parse
> the DT node just like in the reference document? if not, whether someone
> is developing it or should i necessary to complete it together (What's the
> progress of it) ?

There's no driver for it yet. We're currently working on it, so it's
probably going to be done soon, but it's not there yet.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160713/6d4659d3/attachment.sig>

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

end of thread, other threads:[~2016-07-13 20:52 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1458204222-31149-1-git-send-email-yassinjaffer@gmail.com>
2016-03-17  8:43 ` [PATCH] clk: sunxi: Add CSI (camera's Sensors Interface) module clock driver for sun[457]i yassinjaffer
2016-03-17  8:43   ` yassinjaffer at gmail.com
2016-03-17  8:43   ` yassinjaffer
2016-03-18 19:25   ` Maxime Ripard
2016-03-18 19:25     ` Maxime Ripard
2016-04-07 11:55     ` Yassin Jaffer
2016-04-07 11:55       ` Yassin Jaffer
2016-03-19 23:59   ` Rob Herring
2016-03-19 23:59     ` Rob Herring
2016-04-02  1:14     ` Stephen Boyd
2016-04-02  1:14       ` Stephen Boyd
2016-04-04 21:24       ` Maxime Ripard
2016-04-04 21:24         ` Maxime Ripard
2016-04-04 21:24         ` Maxime Ripard
2016-07-10 17:07         ` Hao Zhang
2016-07-10 17:07           ` Hao Zhang
2016-07-13 20:52           ` Maxime Ripard
2016-07-13 20:52             ` Maxime Ripard
2016-07-13 20:52             ` Maxime Ripard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.