diff mbox

[v4,05/05] clk: shmobile: Make MSTP clock-output-names optional

Message ID 20150829091418.28546.8569.sendpatchset@little-apple (mailing list archive)
State Changes Requested
Delegated to: Geert Uytterhoeven
Headers show

Commit Message

Magnus Damm Aug. 29, 2015, 9:14 a.m. UTC
From: Magnus Damm <damm+renesas@opensource.se>

This patch updates the MSTP driver to make the "clock-output-names"
DT property optional instead of mandatory. In case the DT property
is omitted then the function clk_register_clkdev() is skipped.

The default for new SoCs is to not use "clock-output-names".

Signed-off-by: Magnus Damm <damm+renesas@opensource.se>
---

 Changes since V3:
 - Added support for multiple MSTP bits. =)

 drivers/clk/shmobile/clk-mstp.c |   28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Geert Uytterhoeven Aug. 29, 2015, 10:44 a.m. UTC | #1
On Sat, Aug 29, 2015 at 11:14 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
> --- 0001/drivers/clk/shmobile/clk-mstp.c
> +++ work/drivers/clk/shmobile/clk-mstp.c        2015-08-29 18:01:00.662366518 +0900
> @@ -199,26 +199,29 @@ static void __init cpg_mstp_clocks_init(
>         for (i = 0; i < MSTP_MAX_CLOCKS; ++i) {
>                 const char *parent_name;
>                 const char *name;
> +               bool allocated_name;

If you make it "const char *allocated_name = NULL;" ...

>                 u32 clkidx;
>                 int ret;
>
> -               /* Skip clocks with no name. */
> -               ret = of_property_read_string_index(np, "clock-output-names",
> -                                                   i, &name);
> -               if (ret < 0 || strlen(name) == 0)
> -                       continue;
> -
>                 parent_name = of_clk_get_parent_name(np, i);
>                 ret = of_property_read_u32_index(np, idxname, i, &clkidx);
>                 if (parent_name == NULL || ret < 0)
>                         break;
>
>                 if (clkidx >= MSTP_MAX_CLOCKS) {
> -                       pr_err("%s: invalid clock %s %s index %u)\n",
> -                              __func__, np->name, name, clkidx);
> +                       pr_err("%s: invalid clock %s index %u)\n",
> +                              __func__, np->name, clkidx);
>                         continue;
>                 }
>
> +               if (of_property_read_string_index(np, "clock-output-names",
> +                                                 i, &name) == 0) {
> +                       allocated_name = false;

... you can drop this branch...

> +               } else {
> +                       name = kasprintf(GFP_KERNEL, "%s.%u", np->name, clkidx);
> +                       allocated_name = true;

... and use "allocated_name = name = kasprintf(...);"

> +               }
> +
>                 clks[clkidx] = cpg_mstp_clock_register(name, parent_name,
>                                                        clkidx, group);
>                 if (!IS_ERR(clks[clkidx])) {
> @@ -231,12 +234,19 @@ static void __init cpg_mstp_clocks_init(
>                          *
>                          * FIXME: Remove this when all devices that require a
>                          * clock will be instantiated from DT.
> +                        *
> +                        * We currently register clkdev only when the DT
> +                        * property clock-output-names is present.
>                          */
> -                       clk_register_clkdev(clks[clkidx], name, NULL);
> +                       if (!allocated_name)
> +                               clk_register_clkdev(clks[clkidx], name, NULL);
>                 } else {
>                         pr_err("%s: failed to register %s %s clock (%ld)\n",
>                                __func__, np->name, name, PTR_ERR(clks[clkidx]));
>                 }
> +
> +               if (allocated_name)
> +                       kfree(name);

... and kfree(allocated_name) unconditionally.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- 0001/drivers/clk/shmobile/clk-mstp.c
+++ work/drivers/clk/shmobile/clk-mstp.c	2015-08-29 18:01:00.662366518 +0900
@@ -199,26 +199,29 @@  static void __init cpg_mstp_clocks_init(
 	for (i = 0; i < MSTP_MAX_CLOCKS; ++i) {
 		const char *parent_name;
 		const char *name;
+		bool allocated_name;
 		u32 clkidx;
 		int ret;
 
-		/* Skip clocks with no name. */
-		ret = of_property_read_string_index(np, "clock-output-names",
-						    i, &name);
-		if (ret < 0 || strlen(name) == 0)
-			continue;
-
 		parent_name = of_clk_get_parent_name(np, i);
 		ret = of_property_read_u32_index(np, idxname, i, &clkidx);
 		if (parent_name == NULL || ret < 0)
 			break;
 
 		if (clkidx >= MSTP_MAX_CLOCKS) {
-			pr_err("%s: invalid clock %s %s index %u)\n",
-			       __func__, np->name, name, clkidx);
+			pr_err("%s: invalid clock %s index %u)\n",
+			       __func__, np->name, clkidx);
 			continue;
 		}
 
+		if (of_property_read_string_index(np, "clock-output-names",
+						  i, &name) == 0) {
+			allocated_name = false;
+		} else {
+			name = kasprintf(GFP_KERNEL, "%s.%u", np->name, clkidx);
+			allocated_name = true;
+		}
+
 		clks[clkidx] = cpg_mstp_clock_register(name, parent_name,
 						       clkidx, group);
 		if (!IS_ERR(clks[clkidx])) {
@@ -231,12 +234,19 @@  static void __init cpg_mstp_clocks_init(
 			 *
 			 * FIXME: Remove this when all devices that require a
 			 * clock will be instantiated from DT.
+			 *
+			 * We currently register clkdev only when the DT
+			 * property clock-output-names is present.
 			 */
-			clk_register_clkdev(clks[clkidx], name, NULL);
+			if (!allocated_name)
+				clk_register_clkdev(clks[clkidx], name, NULL);
 		} else {
 			pr_err("%s: failed to register %s %s clock (%ld)\n",
 			       __func__, np->name, name, PTR_ERR(clks[clkidx]));
 		}
+
+		if (allocated_name)
+			kfree(name);
 	}
 
 	of_clk_add_provider(np, of_clk_src_onecell_get, &group->data);