linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups
@ 2019-03-19 10:01 Michael Tretter
  2019-03-19 10:01 ` [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents Michael Tretter
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Michael Tretter @ 2019-03-19 10:01 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel
  Cc: kernel, Michael Turquette, Stephen Boyd, Michal Simek,
	Jolly Shah, Michael Tretter

Hello,

This is v2 of the patchset to cleanup the ZynqMP clock driver.

I introduced the new is_frac field in zynqmp_clk_divider. The driver uses this
field to flag fractional dividers instead of misusing the clk_hw::core::flags
field.

Furthermore, the driver uses structs for the query responses from the firmware
instead of passing arrays with implicit size.

Michael

v1 -> v2:
- remove export of zynqmp_clk_register_divider
- move CLK_FLAG to property in zynqmp_clk_divider
- merge and rewrite patches 4 and 5 to use structs for responses

Michael Tretter (4):
  clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents
  clk: zynqmp: do not export zynqmp_clk_register_* functions
  clk: zynqmp: fix check for fractional clock
  clk: zynqmp: use structs for clk query responses

 drivers/clk/zynqmp/clk-mux-zynqmp.c |   1 -
 drivers/clk/zynqmp/clk-zynqmp.h     |   6 --
 drivers/clk/zynqmp/clkc.c           | 148 ++++++++++++++++------------
 drivers/clk/zynqmp/divider.c        |  10 +-
 4 files changed, 92 insertions(+), 73 deletions(-)

-- 
2.20.1


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

* [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents
  2019-03-19 10:01 [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
@ 2019-03-19 10:01 ` Michael Tretter
  2019-04-11 18:41   ` Stephen Boyd
  2019-03-19 10:01 ` [PATCH v2 2/4] clk: zynqmp: do not export zynqmp_clk_register_* functions Michael Tretter
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Michael Tretter @ 2019-03-19 10:01 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel
  Cc: kernel, Michael Turquette, Stephen Boyd, Michal Simek,
	Jolly Shah, Michael Tretter

The kerneldoc refers to __zynqmp_clock_get_topology(), but actually
documents __zynqmp_clock_get_parents(). Refer to the correct function
name in the kerneldoc.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
v1 -> v2:
- none
---
 drivers/clk/zynqmp/clkc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
index b0908ec62f73..d3d4ce305e71 100644
--- a/drivers/clk/zynqmp/clkc.c
+++ b/drivers/clk/zynqmp/clkc.c
@@ -408,7 +408,7 @@ static int zynqmp_clock_get_topology(u32 clk_id,
 }
 
 /**
- * __zynqmp_clock_get_topology() - Get parents info of clock from firmware
+ * __zynqmp_clock_get_parents() - Get parents info of clock from firmware
  *				   response data
  * @parents:		Clock parents
  * @data:		Clock parents data received from firmware
-- 
2.20.1


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

* [PATCH v2 2/4] clk: zynqmp: do not export zynqmp_clk_register_* functions
  2019-03-19 10:01 [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
  2019-03-19 10:01 ` [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents Michael Tretter
@ 2019-03-19 10:01 ` Michael Tretter
  2019-04-11 18:41   ` Stephen Boyd
  2019-03-19 10:01 ` [PATCH v2 3/4] clk: zynqmp: fix check for fractional clock Michael Tretter
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Michael Tretter @ 2019-03-19 10:01 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel
  Cc: kernel, Michael Turquette, Stephen Boyd, Michal Simek,
	Jolly Shah, Michael Tretter

The zynqmp_clk_register_* functions are internal functions of the
driver. Only clkc.c uses these functions to register these clocks.
Therefore, there is no need to export these functions.

The gate and pll already don't export their register_* functions.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
v1 -> v2:
- remove export of zynqmp_clk_register_divider
---
 drivers/clk/zynqmp/clk-mux-zynqmp.c | 1 -
 drivers/clk/zynqmp/divider.c        | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/clk/zynqmp/clk-mux-zynqmp.c b/drivers/clk/zynqmp/clk-mux-zynqmp.c
index 4143f560c28d..0af8f74c5fa5 100644
--- a/drivers/clk/zynqmp/clk-mux-zynqmp.c
+++ b/drivers/clk/zynqmp/clk-mux-zynqmp.c
@@ -138,4 +138,3 @@ struct clk_hw *zynqmp_clk_register_mux(const char *name, u32 clk_id,
 
 	return hw;
 }
-EXPORT_SYMBOL_GPL(zynqmp_clk_register_mux);
diff --git a/drivers/clk/zynqmp/divider.c b/drivers/clk/zynqmp/divider.c
index a371c66e72ef..16a1f021b4f2 100644
--- a/drivers/clk/zynqmp/divider.c
+++ b/drivers/clk/zynqmp/divider.c
@@ -214,4 +214,3 @@ struct clk_hw *zynqmp_clk_register_divider(const char *name,
 
 	return hw;
 }
-EXPORT_SYMBOL_GPL(zynqmp_clk_register_divider);
-- 
2.20.1


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

* [PATCH v2 3/4] clk: zynqmp: fix check for fractional clock
  2019-03-19 10:01 [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
  2019-03-19 10:01 ` [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents Michael Tretter
  2019-03-19 10:01 ` [PATCH v2 2/4] clk: zynqmp: do not export zynqmp_clk_register_* functions Michael Tretter
@ 2019-03-19 10:01 ` Michael Tretter
  2019-04-11 18:41   ` Stephen Boyd
  2019-03-19 10:01 ` [PATCH v2 4/4] clk: zynqmp: use structs for clk query responses Michael Tretter
  2019-04-04  8:16 ` [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
  4 siblings, 1 reply; 11+ messages in thread
From: Michael Tretter @ 2019-03-19 10:01 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel
  Cc: kernel, Michael Turquette, Stephen Boyd, Michal Simek,
	Jolly Shah, Michael Tretter

The firmware sets BIT(13) in clkflag to mark a divider as fractional
divider. The clock driver copies the clkflag straight to the flags of
the common clock framework. In the common clk framework flags, BIT(13)
is defined as CLK_DUTY_CYCLE_PARENT.

Add a new field to the zynqmp_clk_divider to specify if a divider is a
fractional devider. Set this field based on the clkflag when registering
a divider.

At the same time, unset BIT(13) from clkflag when copying the flags to
the common clk framework flags.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
v1 -> v2:
- add is_frac field to zynqmp_clk_divider
- remove CLK_FRAC from flags when copying to common clock framework
---
 drivers/clk/zynqmp/divider.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/zynqmp/divider.c b/drivers/clk/zynqmp/divider.c
index 16a1f021b4f2..7ee54c3fe20f 100644
--- a/drivers/clk/zynqmp/divider.c
+++ b/drivers/clk/zynqmp/divider.c
@@ -31,12 +31,14 @@
  * struct zynqmp_clk_divider - adjustable divider clock
  * @hw:		handle between common and hardware-specific interfaces
  * @flags:	Hardware specific flags
+ * @is_frac:	The divider is a fractional divider
  * @clk_id:	Id of clock
  * @div_type:	divisor type (TYPE_DIV1 or TYPE_DIV2)
  */
 struct zynqmp_clk_divider {
 	struct clk_hw hw;
 	u8 flags;
+	bool is_frac;
 	u32 clk_id;
 	u32 div_type;
 };
@@ -116,8 +118,7 @@ static long zynqmp_clk_divider_round_rate(struct clk_hw *hw,
 
 	bestdiv = zynqmp_divider_get_val(*prate, rate);
 
-	if ((clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) &&
-	    (divider->flags & CLK_FRAC))
+	if ((clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) && divider->is_frac)
 		bestdiv = rate % *prate ? 1 : bestdiv;
 	*prate = rate * bestdiv;
 
@@ -195,11 +196,13 @@ struct clk_hw *zynqmp_clk_register_divider(const char *name,
 
 	init.name = name;
 	init.ops = &zynqmp_clk_divider_ops;
-	init.flags = nodes->flag;
+	/* CLK_FRAC is not defined in the common clk framework */
+	init.flags = nodes->flag & ~CLK_FRAC;
 	init.parent_names = parents;
 	init.num_parents = 1;
 
 	/* struct clk_divider assignments */
+	div->is_frac = !!(nodes->flag & CLK_FRAC);
 	div->flags = nodes->type_flag;
 	div->hw.init = &init;
 	div->clk_id = clk_id;
-- 
2.20.1


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

* [PATCH v2 4/4] clk: zynqmp: use structs for clk query responses
  2019-03-19 10:01 [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
                   ` (2 preceding siblings ...)
  2019-03-19 10:01 ` [PATCH v2 3/4] clk: zynqmp: fix check for fractional clock Michael Tretter
@ 2019-03-19 10:01 ` Michael Tretter
  2019-04-04  8:16 ` [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
  4 siblings, 0 replies; 11+ messages in thread
From: Michael Tretter @ 2019-03-19 10:01 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel
  Cc: kernel, Michael Turquette, Stephen Boyd, Michal Simek,
	Jolly Shah, Michael Tretter

The driver retrieves the clock try by querying the ATF for the clock
names, the clock topology, the parents and other attributes. The driver
needs to unmarshal the responses.

The definition of the fields in the firmware responses to the queries is
inconsistent. Some are specified as a mask, some as a shift, and by the
length of the previous field.

Define C structs for the entire firmware responses to avoid passing
pointers to arrays of an implicit size and make the format of the
responses to the queries obvious.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
v1 -> v2:
- define structs for firmware responses
- fix size of CLK_TYPOLOGY_FLAGS
---
 drivers/clk/zynqmp/clk-zynqmp.h |   6 --
 drivers/clk/zynqmp/clkc.c       | 146 +++++++++++++++++++-------------
 2 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/drivers/clk/zynqmp/clk-zynqmp.h b/drivers/clk/zynqmp/clk-zynqmp.h
index 7ab163b67249..fec9a15c8786 100644
--- a/drivers/clk/zynqmp/clk-zynqmp.h
+++ b/drivers/clk/zynqmp/clk-zynqmp.h
@@ -10,12 +10,6 @@
 
 #include <linux/firmware/xlnx-zynqmp.h>
 
-/* Clock APIs payload parameters */
-#define CLK_GET_NAME_RESP_LEN				16
-#define CLK_GET_TOPOLOGY_RESP_WORDS			3
-#define CLK_GET_PARENTS_RESP_WORDS			3
-#define CLK_GET_ATTR_RESP_WORDS				1
-
 enum topology_type {
 	TYPE_INVALID,
 	TYPE_MUX,
diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
index d3d4ce305e71..b6a9e1f6c438 100644
--- a/drivers/clk/zynqmp/clkc.c
+++ b/drivers/clk/zynqmp/clkc.c
@@ -21,24 +21,6 @@
 #define MAX_NODES			6
 #define MAX_NAME_LEN			50
 
-#define CLK_TYPE_SHIFT			2
-
-#define PM_API_PAYLOAD_LEN		3
-
-#define NA_PARENT			0xFFFFFFFF
-#define DUMMY_PARENT			0xFFFFFFFE
-
-#define CLK_TYPE_FIELD_LEN		4
-#define CLK_TOPOLOGY_NODE_OFFSET	16
-#define NODES_PER_RESP			3
-
-#define CLK_TYPE_FIELD_MASK		0xF
-#define CLK_FLAG_FIELD_MASK		GENMASK(21, 8)
-#define CLK_TYPE_FLAG_FIELD_MASK	GENMASK(31, 24)
-
-#define CLK_PARENTS_ID_LEN		16
-#define CLK_PARENTS_ID_MASK		0xFFFF
-
 /* Flags for parents */
 #define PARENT_CLK_SELF			0
 #define PARENT_CLK_NODE1		1
@@ -52,7 +34,10 @@
 #define END_OF_PARENTS			1
 #define RESERVED_CLK_NAME		""
 
-#define CLK_VALID_MASK			0x1
+#define CLK_GET_NAME_RESP_LEN		16
+#define CLK_GET_TOPOLOGY_RESP_WORDS	3
+#define CLK_GET_PARENTS_RESP_WORDS	3
+#define CLK_GET_ATTR_RESP_WORDS		1
 
 enum clk_type {
 	CLK_TYPE_OUTPUT,
@@ -91,6 +76,31 @@ struct zynqmp_clock {
 	u32 num_parents;
 };
 
+struct name_resp {
+	char name[CLK_GET_NAME_RESP_LEN];
+};
+
+struct topology_resp {
+#define CLK_TOPOLOGY_TYPE		GENMASK(3, 0)
+#define CLK_TOPOLOGY_FLAGS		GENMASK(23, 8)
+#define CLK_TOPOLOGY_TYPE_FLAGS		GENMASK(31, 24)
+	u32 topology[CLK_GET_TOPOLOGY_RESP_WORDS];
+};
+
+struct parents_resp {
+#define NA_PARENT			0xFFFFFFFF
+#define DUMMY_PARENT			0xFFFFFFFE
+#define CLK_PARENTS_ID			GENMASK(15, 0)
+#define CLK_PARENTS_FLAGS		GENMASK(31, 16)
+	u32 parents[CLK_GET_PARENTS_RESP_WORDS];
+};
+
+struct attr_resp {
+#define CLK_ATTR_VALID			BIT(0)
+#define CLK_ATTR_TYPE			BIT(2)
+	u32 attr[CLK_GET_ATTR_RESP_WORDS];
+};
+
 static const char clk_type_postfix[][10] = {
 	[TYPE_INVALID] = "",
 	[TYPE_MUX] = "_mux",
@@ -199,14 +209,15 @@ static int zynqmp_pm_clock_get_num_clocks(u32 *nclocks)
 /**
  * zynqmp_pm_clock_get_name() - Get the name of clock for given id
  * @clock_id:	ID of the clock to be queried
- * @name:	Name of given clock
+ * @response:	Name of the clock with the given id
  *
  * This function is used to get name of clock specified by given
  * clock ID.
  *
- * Return: Returns 0, in case of error name would be 0
+ * Return: Returns 0
  */
-static int zynqmp_pm_clock_get_name(u32 clock_id, char *name)
+static int zynqmp_pm_clock_get_name(u32 clock_id,
+				    struct name_resp *response)
 {
 	struct zynqmp_pm_query_data qdata = {0};
 	u32 ret_payload[PAYLOAD_ARG_CNT];
@@ -215,7 +226,7 @@ static int zynqmp_pm_clock_get_name(u32 clock_id, char *name)
 	qdata.arg1 = clock_id;
 
 	eemi_ops->query_data(qdata, ret_payload);
-	memcpy(name, ret_payload, CLK_GET_NAME_RESP_LEN);
+	memcpy(response, ret_payload, sizeof(*response));
 
 	return 0;
 }
@@ -224,7 +235,7 @@ static int zynqmp_pm_clock_get_name(u32 clock_id, char *name)
  * zynqmp_pm_clock_get_topology() - Get the topology of clock for given id
  * @clock_id:	ID of the clock to be queried
  * @index:	Node index of clock topology
- * @topology:	Buffer to store nodes in topology and flags
+ * @response:	Buffer used for the topology response
  *
  * This function is used to get topology information for the clock
  * specified by given clock ID.
@@ -237,7 +248,8 @@ static int zynqmp_pm_clock_get_name(u32 clock_id, char *name)
  *
  * Return: 0 on success else error+reason
  */
-static int zynqmp_pm_clock_get_topology(u32 clock_id, u32 index, u32 *topology)
+static int zynqmp_pm_clock_get_topology(u32 clock_id, u32 index,
+					struct topology_resp *response)
 {
 	struct zynqmp_pm_query_data qdata = {0};
 	u32 ret_payload[PAYLOAD_ARG_CNT];
@@ -248,7 +260,7 @@ static int zynqmp_pm_clock_get_topology(u32 clock_id, u32 index, u32 *topology)
 	qdata.arg2 = index;
 
 	ret = eemi_ops->query_data(qdata, ret_payload);
-	memcpy(topology, &ret_payload[1], CLK_GET_TOPOLOGY_RESP_WORDS * 4);
+	memcpy(response, &ret_payload[1], sizeof(*response));
 
 	return ret;
 }
@@ -297,7 +309,7 @@ struct clk_hw *zynqmp_clk_register_fixed_factor(const char *name, u32 clk_id,
  * zynqmp_pm_clock_get_parents() - Get the first 3 parents of clock for given id
  * @clock_id:	Clock ID
  * @index:	Parent index
- * @parents:	3 parents of the given clock
+ * @response:	Parents of the given clock
  *
  * This function is used to get 3 parents for the clock specified by
  * given clock ID.
@@ -310,7 +322,8 @@ struct clk_hw *zynqmp_clk_register_fixed_factor(const char *name, u32 clk_id,
  *
  * Return: 0 on success else error+reason
  */
-static int zynqmp_pm_clock_get_parents(u32 clock_id, u32 index, u32 *parents)
+static int zynqmp_pm_clock_get_parents(u32 clock_id, u32 index,
+				       struct parents_resp *response)
 {
 	struct zynqmp_pm_query_data qdata = {0};
 	u32 ret_payload[PAYLOAD_ARG_CNT];
@@ -321,7 +334,7 @@ static int zynqmp_pm_clock_get_parents(u32 clock_id, u32 index, u32 *parents)
 	qdata.arg2 = index;
 
 	ret = eemi_ops->query_data(qdata, ret_payload);
-	memcpy(parents, &ret_payload[1], CLK_GET_PARENTS_RESP_WORDS * 4);
+	memcpy(response, &ret_payload[1], sizeof(*response));
 
 	return ret;
 }
@@ -329,13 +342,14 @@ static int zynqmp_pm_clock_get_parents(u32 clock_id, u32 index, u32 *parents)
 /**
  * zynqmp_pm_clock_get_attributes() - Get the attributes of clock for given id
  * @clock_id:	Clock ID
- * @attr:	Clock attributes
+ * @response:	Clock attributes response
  *
  * This function is used to get clock's attributes(e.g. valid, clock type, etc).
  *
  * Return: 0 on success else error+reason
  */
-static int zynqmp_pm_clock_get_attributes(u32 clock_id, u32 *attr)
+static int zynqmp_pm_clock_get_attributes(u32 clock_id,
+					  struct attr_resp *response)
 {
 	struct zynqmp_pm_query_data qdata = {0};
 	u32 ret_payload[PAYLOAD_ARG_CNT];
@@ -345,7 +359,7 @@ static int zynqmp_pm_clock_get_attributes(u32 clock_id, u32 *attr)
 	qdata.arg1 = clock_id;
 
 	ret = eemi_ops->query_data(qdata, ret_payload);
-	memcpy(attr, &ret_payload[1], CLK_GET_ATTR_RESP_WORDS * 4);
+	memcpy(response, &ret_payload[1], sizeof(*response));
 
 	return ret;
 }
@@ -354,24 +368,28 @@ static int zynqmp_pm_clock_get_attributes(u32 clock_id, u32 *attr)
  * __zynqmp_clock_get_topology() - Get topology data of clock from firmware
  *				   response data
  * @topology:		Clock topology
- * @data:		Clock topology data received from firmware
+ * @response:		Clock topology data received from firmware
  * @nnodes:		Number of nodes
  *
  * Return: 0 on success else error+reason
  */
 static int __zynqmp_clock_get_topology(struct clock_topology *topology,
-				       u32 *data, u32 *nnodes)
+				       struct topology_resp *response,
+				       u32 *nnodes)
 {
 	int i;
+	u32 type;
 
-	for (i = 0; i < PM_API_PAYLOAD_LEN; i++) {
-		if (!(data[i] & CLK_TYPE_FIELD_MASK))
+	for (i = 0; i < ARRAY_SIZE(response->topology); i++) {
+		type = FIELD_GET(CLK_TOPOLOGY_TYPE, response->topology[i]);
+		if (type == TYPE_INVALID)
 			return END_OF_TOPOLOGY_NODE;
-		topology[*nnodes].type = data[i] & CLK_TYPE_FIELD_MASK;
-		topology[*nnodes].flag = FIELD_GET(CLK_FLAG_FIELD_MASK,
-						   data[i]);
+		topology[*nnodes].type = type;
+		topology[*nnodes].flag = FIELD_GET(CLK_TOPOLOGY_FLAGS,
+						   response->topology[i]);
 		topology[*nnodes].type_flag =
-				FIELD_GET(CLK_TYPE_FLAG_FIELD_MASK, data[i]);
+				FIELD_GET(CLK_TOPOLOGY_TYPE_FLAGS,
+					  response->topology[i]);
 		(*nnodes)++;
 	}
 
@@ -392,14 +410,15 @@ static int zynqmp_clock_get_topology(u32 clk_id,
 				     u32 *num_nodes)
 {
 	int j, ret;
-	u32 pm_resp[PM_API_PAYLOAD_LEN] = {0};
+	struct topology_resp response = {0};
 
 	*num_nodes = 0;
-	for (j = 0; j <= MAX_NODES; j += 3) {
-		ret = zynqmp_pm_clock_get_topology(clk_id, j, pm_resp);
+	for (j = 0; j <= MAX_NODES; j += ARRAY_SIZE(response.topology)) {
+		ret = zynqmp_pm_clock_get_topology(clk_id, j, &response);
 		if (ret)
 			return ret;
-		ret = __zynqmp_clock_get_topology(topology, pm_resp, num_nodes);
+		ret = __zynqmp_clock_get_topology(topology, &response,
+						  num_nodes);
 		if (ret == END_OF_TOPOLOGY_NODE)
 			return 0;
 	}
@@ -411,28 +430,30 @@ static int zynqmp_clock_get_topology(u32 clk_id,
  * __zynqmp_clock_get_parents() - Get parents info of clock from firmware
  *				   response data
  * @parents:		Clock parents
- * @data:		Clock parents data received from firmware
+ * @response:		Clock parents data received from firmware
  * @nparent:		Number of parent
  *
  * Return: 0 on success else error+reason
  */
-static int __zynqmp_clock_get_parents(struct clock_parent *parents, u32 *data,
+static int __zynqmp_clock_get_parents(struct clock_parent *parents,
+				      struct parents_resp *response,
 				      u32 *nparent)
 {
 	int i;
 	struct clock_parent *parent;
 
-	for (i = 0; i < PM_API_PAYLOAD_LEN; i++) {
-		if (data[i] == NA_PARENT)
+	for (i = 0; i < ARRAY_SIZE(response->parents); i++) {
+		if (response->parents[i] == NA_PARENT)
 			return END_OF_PARENTS;
 
 		parent = &parents[i];
-		parent->id = data[i] & CLK_PARENTS_ID_MASK;
-		if (data[i] == DUMMY_PARENT) {
+		parent->id = FIELD_GET(CLK_PARENTS_ID, response->parents[i]);
+		if (response->parents[i] == DUMMY_PARENT) {
 			strcpy(parent->name, "dummy_name");
 			parent->flag = 0;
 		} else {
-			parent->flag = data[i] >> CLK_PARENTS_ID_LEN;
+			parent->flag = FIELD_GET(CLK_PARENTS_FLAGS,
+						 response->parents[i]);
 			if (zynqmp_get_clock_name(parent->id, parent->name))
 				continue;
 		}
@@ -454,20 +475,20 @@ static int zynqmp_clock_get_parents(u32 clk_id, struct clock_parent *parents,
 				    u32 *num_parents)
 {
 	int j = 0, ret;
-	u32 pm_resp[PM_API_PAYLOAD_LEN] = {0};
+	struct parents_resp response = {0};
 
 	*num_parents = 0;
 	do {
 		/* Get parents from firmware */
-		ret = zynqmp_pm_clock_get_parents(clk_id, j, pm_resp);
+		ret = zynqmp_pm_clock_get_parents(clk_id, j, &response);
 		if (ret)
 			return ret;
 
-		ret = __zynqmp_clock_get_parents(&parents[j], pm_resp,
+		ret = __zynqmp_clock_get_parents(&parents[j], &response,
 						 num_parents);
 		if (ret == END_OF_PARENTS)
 			return 0;
-		j += PM_API_PAYLOAD_LEN;
+		j += ARRAY_SIZE(response.parents);
 	} while (*num_parents <= MAX_PARENT);
 
 	return 0;
@@ -621,20 +642,23 @@ static int zynqmp_register_clocks(struct device_node *np)
 static void zynqmp_get_clock_info(void)
 {
 	int i, ret;
-	u32 attr, type = 0;
+	u32 type = 0;
+	struct attr_resp attr;
+	struct name_resp name;
 
 	for (i = 0; i < clock_max_idx; i++) {
-		zynqmp_pm_clock_get_name(i, clock[i].clk_name);
-		if (!strcmp(clock[i].clk_name, RESERVED_CLK_NAME))
+		zynqmp_pm_clock_get_name(i, &name);
+		if (!strcmp(name.name, RESERVED_CLK_NAME))
 			continue;
+		strncpy(clock[i].clk_name, name.name, MAX_NAME_LEN);
 
 		ret = zynqmp_pm_clock_get_attributes(i, &attr);
 		if (ret)
 			continue;
 
-		clock[i].valid = attr & CLK_VALID_MASK;
-		clock[i].type = attr >> CLK_TYPE_SHIFT ? CLK_TYPE_EXTERNAL :
-							CLK_TYPE_OUTPUT;
+		clock[i].valid = FIELD_GET(CLK_ATTR_VALID, attr.attr[0]);
+		clock[i].type = FIELD_GET(CLK_ATTR_TYPE, attr.attr[0]) ?
+			CLK_TYPE_EXTERNAL : CLK_TYPE_OUTPUT;
 	}
 
 	/* Get topology of all clock */
-- 
2.20.1


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

* Re: [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups
  2019-03-19 10:01 [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
                   ` (3 preceding siblings ...)
  2019-03-19 10:01 ` [PATCH v2 4/4] clk: zynqmp: use structs for clk query responses Michael Tretter
@ 2019-04-04  8:16 ` Michael Tretter
  2019-04-11 18:40   ` Stephen Boyd
  4 siblings, 1 reply; 11+ messages in thread
From: Michael Tretter @ 2019-04-04  8:16 UTC (permalink / raw)
  To: linux-clk, linux-arm-kernel
  Cc: kernel, Michael Turquette, Stephen Boyd, Michal Simek, Jolly Shah

On Tue, 19 Mar 2019 11:01:43 +0100, Michael Tretter wrote:
> This is v2 of the patchset to cleanup the ZynqMP clock driver.

Gentle ping.

Michael

> 
> I introduced the new is_frac field in zynqmp_clk_divider. The driver uses this
> field to flag fractional dividers instead of misusing the clk_hw::core::flags
> field.
> 
> Furthermore, the driver uses structs for the query responses from the firmware
> instead of passing arrays with implicit size.
> 
> Michael
> 
> v1 -> v2:
> - remove export of zynqmp_clk_register_divider
> - move CLK_FLAG to property in zynqmp_clk_divider
> - merge and rewrite patches 4 and 5 to use structs for responses
> 
> Michael Tretter (4):
>   clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents
>   clk: zynqmp: do not export zynqmp_clk_register_* functions
>   clk: zynqmp: fix check for fractional clock
>   clk: zynqmp: use structs for clk query responses
> 
>  drivers/clk/zynqmp/clk-mux-zynqmp.c |   1 -
>  drivers/clk/zynqmp/clk-zynqmp.h     |   6 --
>  drivers/clk/zynqmp/clkc.c           | 148 ++++++++++++++++------------
>  drivers/clk/zynqmp/divider.c        |  10 +-
>  4 files changed, 92 insertions(+), 73 deletions(-)
> 

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

* Re: [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups
  2019-04-04  8:16 ` [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
@ 2019-04-11 18:40   ` Stephen Boyd
  2019-04-12  9:36     ` Michael Tretter
  0 siblings, 1 reply; 11+ messages in thread
From: Stephen Boyd @ 2019-04-11 18:40 UTC (permalink / raw)
  To: Michael Tretter, linux-arm-kernel, linux-clk
  Cc: kernel, Michael Turquette, Michal Simek, Jolly Shah

Quoting Michael Tretter (2019-04-04 01:16:21)
> On Tue, 19 Mar 2019 11:01:43 +0100, Michael Tretter wrote:
> > This is v2 of the patchset to cleanup the ZynqMP clock driver.
> 
> Gentle ping.
> 

I could apply the first three, but the last one didn't work because
Jolly Shah sent some changes that wrecked it. Can you resend the last
patch reworked on top of it? You can use clk-zynq in clk.git if you need
something to base it upon.

 https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-zynq

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

* Re: [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents
  2019-03-19 10:01 ` [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents Michael Tretter
@ 2019-04-11 18:41   ` Stephen Boyd
  0 siblings, 0 replies; 11+ messages in thread
From: Stephen Boyd @ 2019-04-11 18:41 UTC (permalink / raw)
  To: Michael Tretter, linux-arm-kernel, linux-clk
  Cc: kernel, Michael Turquette, Michal Simek, Jolly Shah, Michael Tretter

Quoting Michael Tretter (2019-03-19 03:01:44)
> The kerneldoc refers to __zynqmp_clock_get_topology(), but actually
> documents __zynqmp_clock_get_parents(). Refer to the correct function
> name in the kerneldoc.
> 
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---

Applied to clk-next


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

* Re: [PATCH v2 2/4] clk: zynqmp: do not export zynqmp_clk_register_* functions
  2019-03-19 10:01 ` [PATCH v2 2/4] clk: zynqmp: do not export zynqmp_clk_register_* functions Michael Tretter
@ 2019-04-11 18:41   ` Stephen Boyd
  0 siblings, 0 replies; 11+ messages in thread
From: Stephen Boyd @ 2019-04-11 18:41 UTC (permalink / raw)
  To: Michael Tretter, linux-arm-kernel, linux-clk
  Cc: kernel, Michael Turquette, Michal Simek, Jolly Shah, Michael Tretter

Quoting Michael Tretter (2019-03-19 03:01:45)
> The zynqmp_clk_register_* functions are internal functions of the
> driver. Only clkc.c uses these functions to register these clocks.
> Therefore, there is no need to export these functions.
> 
> The gate and pll already don't export their register_* functions.
> 
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---

Applied to clk-next


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

* Re: [PATCH v2 3/4] clk: zynqmp: fix check for fractional clock
  2019-03-19 10:01 ` [PATCH v2 3/4] clk: zynqmp: fix check for fractional clock Michael Tretter
@ 2019-04-11 18:41   ` Stephen Boyd
  0 siblings, 0 replies; 11+ messages in thread
From: Stephen Boyd @ 2019-04-11 18:41 UTC (permalink / raw)
  To: Michael Tretter, linux-arm-kernel, linux-clk
  Cc: kernel, Michael Turquette, Michal Simek, Jolly Shah, Michael Tretter

Quoting Michael Tretter (2019-03-19 03:01:46)
> The firmware sets BIT(13) in clkflag to mark a divider as fractional
> divider. The clock driver copies the clkflag straight to the flags of
> the common clock framework. In the common clk framework flags, BIT(13)
> is defined as CLK_DUTY_CYCLE_PARENT.
> 
> Add a new field to the zynqmp_clk_divider to specify if a divider is a
> fractional devider. Set this field based on the clkflag when registering
> a divider.
> 
> At the same time, unset BIT(13) from clkflag when copying the flags to
> the common clk framework flags.
> 
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---

Applied to clk-next


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

* Re: [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups
  2019-04-11 18:40   ` Stephen Boyd
@ 2019-04-12  9:36     ` Michael Tretter
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Tretter @ 2019-04-12  9:36 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: linux-arm-kernel, linux-clk, kernel, Michael Turquette,
	Michal Simek, Jolly Shah

On Thu, 11 Apr 2019 11:40:58 -0700, Stephen Boyd wrote:
> Quoting Michael Tretter (2019-04-04 01:16:21)
> > On Tue, 19 Mar 2019 11:01:43 +0100, Michael Tretter wrote:  
> > > This is v2 of the patchset to cleanup the ZynqMP clock driver.  
> > 
> > Gentle ping.
> >   
> 
> I could apply the first three, but the last one didn't work because
> Jolly Shah sent some changes that wrecked it. Can you resend the last
> patch reworked on top of it? You can use clk-zynq in clk.git if you need
> something to base it upon.

Thanks. The changes in clk-zynq look really fragile to me, because the
fields from the firmware response are reused to build the clock id. I
will send a v3 of the patch anyway to properly get the fields of the
firmware responses.

Michael

> 
>  https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-zynq
> 

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

end of thread, other threads:[~2019-04-12  9:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 10:01 [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
2019-03-19 10:01 ` [PATCH v2 1/4] clk: zynqmp: fix kerneldoc of __zynqmp_clock_get_parents Michael Tretter
2019-04-11 18:41   ` Stephen Boyd
2019-03-19 10:01 ` [PATCH v2 2/4] clk: zynqmp: do not export zynqmp_clk_register_* functions Michael Tretter
2019-04-11 18:41   ` Stephen Boyd
2019-03-19 10:01 ` [PATCH v2 3/4] clk: zynqmp: fix check for fractional clock Michael Tretter
2019-04-11 18:41   ` Stephen Boyd
2019-03-19 10:01 ` [PATCH v2 4/4] clk: zynqmp: use structs for clk query responses Michael Tretter
2019-04-04  8:16 ` [PATCH v2 0/4] clk: zynqmp: fix CLK_FRAC and various cleanups Michael Tretter
2019-04-11 18:40   ` Stephen Boyd
2019-04-12  9:36     ` Michael Tretter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).