Skip to contentSkip to conversation

ARM: sa1100: convert to common clock framework

PATCH In review Russell King 3 participants 5 messages Jun 29, 2019 – Jul 18, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: sa1100: convert to common clock framework

Convert sa1100 to use the common clock framework.

---
Please ack; this is part of a larger series. Thanks.

 arch/arm/Kconfig             |   1 +
 arch/arm/mach-sa1100/clock.c | 221 +++++++++++++++++++------------------------
 2 files changed, 96 insertions(+), 126 deletions(-)
arch/arm/Kconfig +1 -0
index 9aed25a6019b..005549cbc963 100644
@@ -549,6 +549,7 @@ config ARCH_SA1100
 	select CLKSRC_MMIO
 	select CLKSRC_PXA
 	select TIMER_OF if OF
+	select COMMON_CLK
 	select CPU_FREQ
 	select CPU_SA1100
 	select GENERIC_CLOCKEVENTS
arch/arm/mach-sa1100/clock.c +95 -126

271 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#1 lore raw

Quoting Russell King (2019-06-29 03:14:10)

Quoted 5 lines

Convert sa1100 to use the common clock framework.

---
Please ack; this is part of a larger series. Thanks.

Just a few minor comments but otherwise looks good to me.

arch/arm/mach-sa1100/clock.c line 19

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +2 -0
index 6199e87447ca..523ef25618f7 100644
+static const char * const clk_tucr_parents[] = {
+       "clk32768", "clk3686400",
 };

It would be great if you used the new way of specifying clk parents with direct pointers instead of strings. See commit fc0c209c147f ("clk: Allow parents to be specified without string names") for some details.

Quoted 53 lines
arch/arm/mach-sa1100/clock.c +6 -37
-struct clk {
-       const struct clkops     *ops;
-       unsigned int            enabled;
-};
-
-#define DEFINE_CLK(_name, _ops)                                \
-struct clk clk_##_name = {                             \
-               .ops    = _ops,                         \
-       }
-
-static DEFINE_SPINLOCK(clocks_lock);
-
-/* Dummy clk routine to build generic kernel parts that may be using them */
-long clk_round_rate(struct clk *clk, unsigned long rate)
-{
-       return clk_get_rate(clk);
-}
-EXPORT_SYMBOL(clk_round_rate);
-
-int clk_set_rate(struct clk *clk, unsigned long rate)
-{
-       return 0;
-}
-EXPORT_SYMBOL(clk_set_rate);
-
-int clk_set_parent(struct clk *clk, struct clk *parent)
-{
-       return 0;
-}
-EXPORT_SYMBOL(clk_set_parent);
+static DEFINE_SPINLOCK(tucr_lock);
 
-struct clk *clk_get_parent(struct clk *clk)
+static int clk_gpio27_enable(struct clk_hw *hw)
 {
-       return NULL;
-}
-EXPORT_SYMBOL(clk_get_parent);
+       unsigned long flags;
 
-static void clk_gpio27_enable(struct clk *clk)
-{
        /*
         * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
         * (SA-1110 Developer's Manual, section 9.1.2.1)
         */
+       local_irq_save(flags);
        GAFR |= GPIO_32_768kHz;
        GPDR |= GPIO_32_768kHz;
-       TUCR = TUCR_3_6864MHz;
+       local_irq_restore(flags);
+

arch/arm/mach-sa1100/clock.c line 43

Quoted 10 lines
arch/arm/mach-sa1100/clock.c +5 -2
+       return 0;
 }
 
-static void clk_gpio27_disable(struct clk *clk)
+static void clk_gpio27_disable(struct clk_hw *hw)
 {
-       TUCR = 0;
+       unsigned long flags;
+
+       local_irq_save(flags);

Why just disable irqs here?

Quoted 17 lines
        GPDR &= ~GPIO_32_768kHz;
        GAFR &= ~GPIO_32_768kHz;
arch/arm/mach-sa1100/clock.c +6 -6
+       local_irq_restore(flags);
 }
 
-static void clk_cpu_enable(struct clk *clk)
-{
-}
+static const struct clk_ops clk_gpio27_ops = {
+       .enable = clk_gpio27_enable,
+       .disable = clk_gpio27_disable,
+};
 
-static void clk_cpu_disable(struct clk *clk)
-{
-}
+static const char * const clk_gpio27_parents[] = {

arch/arm/mach-sa1100/clock.c line 63

Quoted 10 lines
arch/arm/mach-sa1100/clock.c +8 -1
+       "tucr-mux",
+};
 
-static unsigned long clk_cpu_get_rate(struct clk *clk)
+static const struct clk_init_data clk_gpio27_init_data __initconst = {
+       .name = "gpio27",
+       .ops = &clk_gpio27_ops,
+       .parent_names = clk_gpio27_parents,
+       .num_parents = ARRAY_SIZE(clk_gpio27_parents),
+       .flags = CLK_IS_BASIC,

CLK_IS_BASIC is gone. Please don't use it.

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +7 -0
+};
+
+/*
+ * Derived from the table 8-1 in the SA1110 manual, the MPLL appears to
+ * multiply its input rate by 4 x (4 + PPCR).  This calculation gives
+ * the exact rate.  The figures given in the table are the rates rounded
+ * to 100kHz.  Stick with sa11x0_getspeed() for the time being.

[...]

arch/arm/mach-sa1100/clock.c line 91

Quoted 6 lines
arch/arm/mach-sa1100/clock.c +6 -0
+static const struct clk_init_data clk_mpll_init_data __initconst = {
+       .name = "mpll",
+       .ops = &clk_mpll_ops,
+       .parent_names = clk_mpll_parents,
+       .num_parents = ARRAY_SIZE(clk_mpll_parents),
+       .flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE | CLK_IS_CRITICAL,

Please add a comment about these last two flags so we know why the rate can't be cached and the clk is critical.

#2 lore raw
Quoted 9 lines · Stephen Boyd

Quoting Russell King (2019-06-29 03:14:10)

Quoted 5 lines

Convert sa1100 to use the common clock framework.

---
Please ack; this is part of a larger series. Thanks.

Just a few minor comments but otherwise looks good to me.

Quoted 11 lines

arch/arm/mach-sa1100/clock.c line 19

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +2 -0
index 6199e87447ca..523ef25618f7 100644
+static const char * const clk_tucr_parents[] = {
+       "clk32768", "clk3686400",
 };

It would be great if you used the new way of specifying clk parents with direct pointers instead of strings. See commit fc0c209c147f ("clk: Allow parents to be specified without string names") for some details.

I don't see at the moment how this is used with clk-mux.c - can you provide some hints?

Quoted 57 lines
Quoted 57 lines
arch/arm/mach-sa1100/clock.c +7 -37
-struct clk {
-       const struct clkops     *ops;
-       unsigned int            enabled;
-};
-
-#define DEFINE_CLK(_name, _ops)                                \
-struct clk clk_##_name = {                             \
-               .ops    = _ops,                         \
-       }
-
-static DEFINE_SPINLOCK(clocks_lock);
-
-/* Dummy clk routine to build generic kernel parts that may be using them */
-long clk_round_rate(struct clk *clk, unsigned long rate)
-{
-       return clk_get_rate(clk);
-}
-EXPORT_SYMBOL(clk_round_rate);
-
-int clk_set_rate(struct clk *clk, unsigned long rate)
-{
-       return 0;
-}
-EXPORT_SYMBOL(clk_set_rate);
-
-int clk_set_parent(struct clk *clk, struct clk *parent)
-{
-       return 0;
-}
-EXPORT_SYMBOL(clk_set_parent);
+static DEFINE_SPINLOCK(tucr_lock);
 
-struct clk *clk_get_parent(struct clk *clk)
+static int clk_gpio27_enable(struct clk_hw *hw)
 {
-       return NULL;
-}
-EXPORT_SYMBOL(clk_get_parent);
+       unsigned long flags;
 
-static void clk_gpio27_enable(struct clk *clk)
-{
        /*
         * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
         * (SA-1110 Developer's Manual, section 9.1.2.1)
         */
+       local_irq_save(flags);
        GAFR |= GPIO_32_768kHz;
        GPDR |= GPIO_32_768kHz;
-       TUCR = TUCR_3_6864MHz;
+       local_irq_restore(flags);
+
+       return 0;
 }
Quoted 9 lines

arch/arm/mach-sa1100/clock.c line 43

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +4 -2
-static void clk_gpio27_disable(struct clk *clk)
+static void clk_gpio27_disable(struct clk_hw *hw)
 {
-       TUCR = 0;
+       unsigned long flags;
+
+       local_irq_save(flags);

Why just disable irqs here?

What do you mean? Do you mean "why are you only disabling IRQs and not taking a spinlock" or do you mean "why are you disabling IRQs here" ?

Quoted 21 lines
Quoted 21 lines
        GPDR &= ~GPIO_32_768kHz;
        GAFR &= ~GPIO_32_768kHz;
arch/arm/mach-sa1100/clock.c +8 -6
+       local_irq_restore(flags);
 }
 
-static void clk_cpu_enable(struct clk *clk)
-{
-}
+static const struct clk_ops clk_gpio27_ops = {
+       .enable = clk_gpio27_enable,
+       .disable = clk_gpio27_disable,
+};
 
-static void clk_cpu_disable(struct clk *clk)
-{
-}
+static const char * const clk_gpio27_parents[] = {
+       "tucr-mux",
+};
Quoted 9 lines

arch/arm/mach-sa1100/clock.c line 63

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +6 -1
-static unsigned long clk_cpu_get_rate(struct clk *clk)
+static const struct clk_init_data clk_gpio27_init_data __initconst = {
+       .name = "gpio27",
+       .ops = &clk_gpio27_ops,
+       .parent_names = clk_gpio27_parents,
+       .num_parents = ARRAY_SIZE(clk_gpio27_parents),
+       .flags = CLK_IS_BASIC,

CLK_IS_BASIC is gone. Please don't use it.

The patch is against 5.1, and you're right, so that was removed for the version that ended up going upstream.

Quoted 16 lines
Quoted 8 lines
arch/arm/mach-sa1100/clock.c +7 -0
+};
+
+/*
+ * Derived from the table 8-1 in the SA1110 manual, the MPLL appears to
+ * multiply its input rate by 4 x (4 + PPCR).  This calculation gives
+ * the exact rate.  The figures given in the table are the rates rounded
+ * to 100kHz.  Stick with sa11x0_getspeed() for the time being.

[...]

arch/arm/mach-sa1100/clock.c line 91

Quoted 6 lines
arch/arm/mach-sa1100/clock.c +6 -0
+static const struct clk_init_data clk_mpll_init_data __initconst = {
+       .name = "mpll",
+       .ops = &clk_mpll_ops,
+       .parent_names = clk_mpll_parents,
+       .num_parents = ARRAY_SIZE(clk_mpll_parents),
+       .flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE | CLK_IS_CRITICAL,
Quoted 2 lines

Please add a comment about these last two flags so we know why the rate can't be cached and the clk is critical.

Ok, I'll do that with a follow-up patch once the merge window is over.

Thanks.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
maintainer
#3 lore raw

Quoting Russell King - ARM Linux admin (2019-07-18 10:49:01)

Quoted 22 lines · Stephen Boyd
Quoted 9 lines

Quoting Russell King (2019-06-29 03:14:10)

Quoted 5 lines

Convert sa1100 to use the common clock framework.

---
Please ack; this is part of a larger series. Thanks.

Just a few minor comments but otherwise looks good to me.

Quoted 11 lines

arch/arm/mach-sa1100/clock.c line 19

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +2 -0
index 6199e87447ca..523ef25618f7 100644
+static const char * const clk_tucr_parents[] = {
+       "clk32768", "clk3686400",
 };

It would be great if you used the new way of specifying clk parents with direct pointers instead of strings. See commit fc0c209c147f ("clk: Allow parents to be specified without string names") for some details.

Quoted 2 lines

I don't see at the moment how this is used with clk-mux.c - can you provide some hints?

In this case both the parents are clk_hw pointers I think so an array where first element is the clk_hw pointer to clk32768 and the second element is the clk_hw pointer to clk3686400 would be assigned to clk_init_data's parent_hws member.

	struct clk_hw *clk_tucr_parents[] = {
		&clk32768_hw, 
		&clk3686400_hw,
	};

	clk_tucr_init.parent_hws = clk_tucr_parents;
Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
arch/arm/mach-sa1100/clock.c +4 -3
-static void clk_gpio27_enable(struct clk *clk)
-{
        /*
         * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
         * (SA-1110 Developer's Manual, section 9.1.2.1)
         */
+       local_irq_save(flags);
        GAFR |= GPIO_32_768kHz;
        GPDR |= GPIO_32_768kHz;
-       TUCR = TUCR_3_6864MHz;
+       local_irq_restore(flags);
+
+       return 0;
 }
Quoted 9 lines

arch/arm/mach-sa1100/clock.c line 43

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +4 -2
-static void clk_gpio27_disable(struct clk *clk)
+static void clk_gpio27_disable(struct clk_hw *hw)
 {
-       TUCR = 0;
+       unsigned long flags;
+
+       local_irq_save(flags);

Why just disable irqs here?

Quoted 2 lines

What do you mean? Do you mean "why are you only disabling IRQs and not taking a spinlock" or do you mean "why are you disabling IRQs here" ?

I mean, why are you disabling irqs and not taking a spinlock? Must be because there's already a spinlock in the clk framework?

Quoted 32 lines
Quoted 22 lines
Quoted 22 lines

        GPDR &= ~GPIO_32_768kHz;
        GAFR &= ~GPIO_32_768kHz;
arch/arm/mach-sa1100/clock.c +8 -6
+       local_irq_restore(flags);
 }
 
-static void clk_cpu_enable(struct clk *clk)
-{
-}
+static const struct clk_ops clk_gpio27_ops = {
+       .enable = clk_gpio27_enable,
+       .disable = clk_gpio27_disable,
+};
 
-static void clk_cpu_disable(struct clk *clk)
-{
-}
+static const char * const clk_gpio27_parents[] = {
+       "tucr-mux",
+};
Quoted 9 lines

arch/arm/mach-sa1100/clock.c line 63

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +6 -1
-static unsigned long clk_cpu_get_rate(struct clk *clk)
+static const struct clk_init_data clk_gpio27_init_data __initconst = {
+       .name = "gpio27",
+       .ops = &clk_gpio27_ops,
+       .parent_names = clk_gpio27_parents,
+       .num_parents = ARRAY_SIZE(clk_gpio27_parents),
+       .flags = CLK_IS_BASIC,

CLK_IS_BASIC is gone. Please don't use it.

Quoted 2 lines

The patch is against 5.1, and you're right, so that was removed for the version that ended up going upstream.

Oh did this get sent to Linus already? I guess I should have reviewed this earlier.

Quoted 17 lines
Quoted 17 lines
Quoted 9 lines
arch/arm/mach-sa1100/clock.c +7 -0
+};
+
+/*
+ * Derived from the table 8-1 in the SA1110 manual, the MPLL appears to
+ * multiply its input rate by 4 x (4 + PPCR).  This calculation gives
+ * the exact rate.  The figures given in the table are the rates rounded
+ * to 100kHz.  Stick with sa11x0_getspeed() for the time being.

[...]

Quoted 6 lines
arch/arm/mach-sa1100/clock.c +6 -0
+static const struct clk_init_data clk_mpll_init_data __initconst = {
+       .name = "mpll",
+       .ops = &clk_mpll_ops,
+       .parent_names = clk_mpll_parents,
+       .num_parents = ARRAY_SIZE(clk_mpll_parents),
+       .flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE | CLK_IS_CRITICAL,
Quoted 5 lines
Quoted 2 lines

Please add a comment about these last two flags so we know why the rate can't be cached and the clk is critical.

Ok, I'll do that with a follow-up patch once the merge window is over.

Ok, thanks.

#4 lore raw
Quoted 32 lines · Stephen Boyd

Quoting Russell King - ARM Linux admin (2019-07-18 10:49:01)

Quoted 22 lines · Stephen Boyd
Quoted 9 lines

Quoting Russell King (2019-06-29 03:14:10)

Quoted 5 lines

Convert sa1100 to use the common clock framework.

---
Please ack; this is part of a larger series. Thanks.

Just a few minor comments but otherwise looks good to me.

Quoted 11 lines

arch/arm/mach-sa1100/clock.c line 19

Quoted 7 lines
arch/arm/mach-sa1100/clock.c +2 -0
index 6199e87447ca..523ef25618f7 100644
+static const char * const clk_tucr_parents[] = {
+       "clk32768", "clk3686400",
 };

It would be great if you used the new way of specifying clk parents with direct pointers instead of strings. See commit fc0c209c147f ("clk: Allow parents to be specified without string names") for some details.

Quoted 2 lines

I don't see at the moment how this is used with clk-mux.c - can you provide some hints?

In this case both the parents are clk_hw pointers I think so an array where first element is the clk_hw pointer to clk32768 and the second element is the clk_hw pointer to clk3686400 would be assigned to clk_init_data's parent_hws member.

Quoted 6 lines
	struct clk_hw *clk_tucr_parents[] = {
		&clk32768_hw, 
		&clk3686400_hw,
	};

	clk_tucr_init.parent_hws = clk_tucr_parents;

Thanks.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 12 lines
arch/arm/mach-sa1100/clock.c +3 -3
-static void clk_gpio27_enable(struct clk *clk)
-{
        /*
         * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
         * (SA-1110 Developer's Manual, section 9.1.2.1)
         */
+       local_irq_save(flags);
        GAFR |= GPIO_32_768kHz;
        GPDR |= GPIO_32_768kHz;
-       TUCR = TUCR_3_6864MHz;
+       local_irq_restore(flags);
+

arch/arm/mach-sa1100/clock.c line 43

Quoted 10 lines
arch/arm/mach-sa1100/clock.c +5 -2
+       return 0;
 }
 
-static void clk_gpio27_disable(struct clk *clk)
+static void clk_gpio27_disable(struct clk_hw *hw)
 {
-       TUCR = 0;
+       unsigned long flags;
+
+       local_irq_save(flags);

Why just disable irqs here?

Quoted 5 lines
Quoted 2 lines

What do you mean? Do you mean "why are you only disabling IRQs and not taking a spinlock" or do you mean "why are you disabling IRQs here" ?

I mean, why are you disabling irqs and not taking a spinlock? Must be because there's already a spinlock in the clk framework?

Nope - it's because there's no point taking a spinlock on something that is fundamentally only a uniprocessor architecture. There's never going to be a SA11x0 compatible SoC that has more than one core.

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 17 lines
        GPDR &= ~GPIO_32_768kHz;
        GAFR &= ~GPIO_32_768kHz;
arch/arm/mach-sa1100/clock.c +6 -6
+       local_irq_restore(flags);
 }
 
-static void clk_cpu_enable(struct clk *clk)
-{
-}
+static const struct clk_ops clk_gpio27_ops = {
+       .enable = clk_gpio27_enable,
+       .disable = clk_gpio27_disable,
+};
 
-static void clk_cpu_disable(struct clk *clk)
-{
-}
+static const char * const clk_gpio27_parents[] = {

arch/arm/mach-sa1100/clock.c line 63

Quoted 10 lines
arch/arm/mach-sa1100/clock.c +8 -1
+       "tucr-mux",
+};
 
-static unsigned long clk_cpu_get_rate(struct clk *clk)
+static const struct clk_init_data clk_gpio27_init_data __initconst = {
+       .name = "gpio27",
+       .ops = &clk_gpio27_ops,
+       .parent_names = clk_gpio27_parents,
+       .num_parents = ARRAY_SIZE(clk_gpio27_parents),
+       .flags = CLK_IS_BASIC,

CLK_IS_BASIC is gone. Please don't use it.

Quoted 5 lines
Quoted 2 lines

The patch is against 5.1, and you're right, so that was removed for the version that ended up going upstream.

Oh did this get sent to Linus already? I guess I should have reviewed this earlier.

Generally, SA11x0 stuff doesn't interest people, and patches I send out don't attract comments - so I tend to wait a couple of weeks before queuing them for merging.

It hasn't yet been merged, but is in the queue - arm-soc has taken it into their late merges, but those haven't yet been sent.

Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
Quoted 7 lines
arch/arm/mach-sa1100/clock.c +7 -0
+};
+
+/*
+ * Derived from the table 8-1 in the SA1110 manual, the MPLL appears to
+ * multiply its input rate by 4 x (4 + PPCR).  This calculation gives
+ * the exact rate.  The figures given in the table are the rates rounded
+ * to 100kHz.  Stick with sa11x0_getspeed() for the time being.

[...]

Quoted 6 lines
arch/arm/mach-sa1100/clock.c +6 -0
+static const struct clk_init_data clk_mpll_init_data __initconst = {
+       .name = "mpll",
+       .ops = &clk_mpll_ops,
+       .parent_names = clk_mpll_parents,
+       .num_parents = ARRAY_SIZE(clk_mpll_parents),
+       .flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE | CLK_IS_CRITICAL,
Quoted 5 lines
Quoted 2 lines

Please add a comment about these last two flags so we know why the rate can't be cached and the clk is critical.

Ok, I'll do that with a follow-up patch once the merge window is over.

Ok, thanks.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up