clk: at91: updates for power management and dvfs
Subsystems (2)
v2 cover clk: at91: updates for power management and dvfs
Hi,
This series addresses the power management for SAMA7G5 and also updates the master clock prescaller and master clock divider drivers to accommodate the requests at [1].
The power management part is implemented by adding save_context()/restore_context() on each clock driver (patch 1/6). Since the PM part is necessary only for backup mode (supported on SAMA5D2 and SAMA7G5) the pmc.c has been adapted to call the save_context()/restore_context() only on switches to/from backup mode (patch 2/6).
Patch 3/6 adds the securam clock on SAMA7G5. This is necessary for backup mode of SAMA7G5.
Patch 4/6 adds registers definitions for the new master clocks (MCK1..4) of SAMA7G5 and adapt the clk-master.c. The defines exported in include/linux/clk/at91_pmc.h will be also used by platform specific PM code.
Patch 5/6 adpat the master clock divider and master clock prescaller to address the requests at [1].
Patch 6/6 clean up a bit the code in clk-master as suggested by Nicolas.
Thank you,
Claudiu Beznea
[1] https://lore.kernel.org/lkml/20210105104426.4tmgc2l3vyicwedd@vireshk-i7/
Changes in v2:
- addressed code review comments
- collected tags
Claudiu Beznea (6):
clk: at91: re-factor clocks suspend/resume
clk: at91: pmc: execute suspend/resume only for backup mode
clk: at91: sama7g5: add securam's peripheral clock
clk: at91: clk-master: add register definition for sama7g5's master
clock
clk: at91: clk-master: update for dvfs
clk: at91: clk-master: improve readability by using local variables
drivers/clk/at91/at91rm9200.c | 2 +- drivers/clk/at91/at91sam9260.c | 2 +- drivers/clk/at91/at91sam9g45.c | 2 +- drivers/clk/at91/at91sam9n12.c | 2 +- drivers/clk/at91/at91sam9rl.c | 2 +- drivers/clk/at91/at91sam9x5.c | 2 +- drivers/clk/at91/clk-generated.c | 46 +++- drivers/clk/at91/clk-main.c | 66 +++++ drivers/clk/at91/clk-master.c | 396 +++++++++++++++++++++------- drivers/clk/at91/clk-peripheral.c | 40 ++- drivers/clk/at91/clk-pll.c | 37 +++ drivers/clk/at91/clk-programmable.c | 29 +- drivers/clk/at91/clk-sam9x60-pll.c | 68 ++++- drivers/clk/at91/clk-system.c | 20 ++ drivers/clk/at91/clk-usb.c | 27 ++ drivers/clk/at91/clk-utmi.c | 47 +++- drivers/clk/at91/dt-compat.c | 2 +- drivers/clk/at91/pmc.c | 175 +++--------- drivers/clk/at91/pmc.h | 27 +- drivers/clk/at91/sam9x60.c | 2 +- drivers/clk/at91/sama5d2.c | 2 +- drivers/clk/at91/sama5d3.c | 2 +- drivers/clk/at91/sama5d4.c | 2 +- drivers/clk/at91/sama7g5.c | 3 +- include/linux/clk/at91_pmc.h | 26 ++ 25 files changed, 752 insertions(+), 277 deletions(-)
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/6 clk: at91: re-factor clocks suspend/resume
SAMA5D2 and SAMA7G5 have a special power saving mode (backup mode) where most of the SoC's components are powered off (including PMC). Resuming from this mode is done with the help of bootloader. Peripherals are not aware of the power saving mode thus most of them are disabling clocks in proper suspend API and re-enable them in resume API without taking into account the previously setup rate. Moreover some of the peripherals are acting as wakeup sources and are not disabling the clocks in this scenario, when suspending. Since backup mode cuts the power for peripherals, in resume part these clocks needs to be re-configured.
The initial PMC suspend/resume code was designed with SAMA5D2's PMC in mind. SAMA7G's PMC is different (few new functionalities, different registers offsets, different offsets in registers for each functionalities). To address both SAMA5D2 and SAMA7G5 PMC add .save_context()/.resume_context() support to each clocks driver and call this from PMC driver.
--- drivers/clk/at91/clk-generated.c | 46 +++++-- drivers/clk/at91/clk-main.c | 66 ++++++++++ drivers/clk/at91/clk-master.c | 183 ++++++++++++++++++++++++++-- drivers/clk/at91/clk-peripheral.c | 40 +++++- drivers/clk/at91/clk-pll.c | 37 ++++++ drivers/clk/at91/clk-programmable.c | 29 ++++- drivers/clk/at91/clk-sam9x60-pll.c | 68 ++++++++++- drivers/clk/at91/clk-system.c | 20 +++ drivers/clk/at91/clk-usb.c | 27 ++++ drivers/clk/at91/clk-utmi.c | 47 ++++++- drivers/clk/at91/pmc.c | 149 ++-------------------- drivers/clk/at91/pmc.h | 24 ++-- 12 files changed, 556 insertions(+), 180 deletions(-)
drivers/clk/at91/clk-generated.c +37 -9
@@ -27,6 +27,7 @@ struct clk_generated {u32 id;u32 gckdiv;const struct clk_pcr_layout *layout; +struct at91_clk_pms pms;u8 parent_id;int chg_pid; };
@@ -34,25 +35,35 @@ struct clk_generated {#define to_clk_generated (hw) \ container_of(hw, struct clk_generated, hw) -static int clk_generated_enable (struct clk_hw *hw) +static int clk_generated_set (struct clk_generated *gck,int status) { -struct clk_generated *gck =to_clk_generated (hw);unsigned long flags; - -pr_debug ("GCLK: %s, gckdiv = %d, parent id = %d\n" , - __func__, gck->gckdiv, gck->parent_id); +unsigned int enable = status ?AT91_PMC_PCR_GCKEN :0 ;spin_lock_irqsave (gck->lock, flags);regmap_write (gck->regmap, gck->layout->offset, (gck->id & gck->layout->pid_mask));regmap_update_bits (gck->regmap, gck->layout->offset,AT91_PMC_PCR_GCKDIV_MASK | gck->layout->gckcss_mask | - gck->layout->cmd |AT91_PMC_PCR_GCKEN , + gck->layout->cmd | enable,field_prep (gck->layout->gckcss_mask, gck->parent_id) | gck->layout->cmd |FIELD_PREP (AT91_PMC_PCR_GCKDIV_MASK , gck->gckdiv) | -AT91_PMC_PCR_GCKEN ); + enable);spin_unlock_irqrestore (gck->lock, flags); + +return 0 ; +} + +static int clk_generated_enable (struct clk_hw *hw) +{ +struct clk_generated *gck =to_clk_generated (hw); + +pr_debug ("GCLK: %s, gckdiv = %d, parent id = %d\n" , + __func__, gck->gckdiv, gck->parent_id); + +clk_generated_set (gck,1 ); +return 0 ; }
@@ -239,6 +250,23 @@ static int clk_generated_set_rate(struct clk_hw *hw,return 0 ; } +static int clk_generated_save_context (struct clk_hw *hw) +{ +struct clk_generated *gck =to_clk_generated (hw); + + gck->pms.status =clk_generated_is_enabled (&gck->hw); + +return 0 ; +} + +static void clk_generated_restore_context (struct clk_hw *hw) +{ +struct clk_generated *gck =to_clk_generated (hw); + +if (gck->pms.status) +clk_generated_set (gck, gck->pms.status); +} +static const struct clk_ops generated_ops = { .enable = clk_generated_enable, .disable = clk_generated_disable,
@@ -248,6 +276,8 @@ static const struct clk_ops generated_ops = { .get_parent = clk_generated_get_parent, .set_parent = clk_generated_set_parent, .set_rate = clk_generated_set_rate, + .save_context = clk_generated_save_context, + .restore_context = clk_generated_restore_context, };/**
@@ -314,8 +344,6 @@ at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,if (ret) {kfree (gck); hw =ERR_PTR (ret); - }else { -pmc_register_id (id); }return hw;
drivers/clk/at91/clk-main.c +66 -0
118 lines not on this page · raw message
drivers/clk/at91/clk-master.c +174 -9
297 lines not on this page · raw message
drivers/clk/at91/clk-peripheral.c +34 -6
@@ -37,6 +37,7 @@ struct clk_sam9x5_peripheral {u32 id;u32 div;const struct clk_pcr_layout *layout; +struct at91_clk_pms pms;bool auto_div;int chg_pid; };
@@ -155,10 +156,11 @@ static void clk_sam9x5_peripheral_autodiv(struct clk_sam9x5_peripheral *periph) periph->div = shift; } -static int clk_sam9x5_peripheral_enable (struct clk_hw *hw) +static int clk_sam9x5_peripheral_set (struct clk_sam9x5_peripheral *periph, +unsigned int status) { -struct clk_sam9x5_peripheral *periph =to_clk_sam9x5_peripheral (hw);unsigned long flags; +unsigned int enable = status ?AT91_PMC_PCR_EN :0 ;if (periph->id <PERIPHERAL_ID_MIN )return 0 ;
@@ -168,15 +170,21 @@ static int clk_sam9x5_peripheral_enable(struct clk_hw *hw) (periph->id & periph->layout->pid_mask));regmap_update_bits (periph->regmap, periph->layout->offset, periph->layout->div_mask | periph->layout->cmd | -AT91_PMC_PCR_EN , + enable,field_prep (periph->layout->div_mask, periph->div) | - periph->layout->cmd | -AT91_PMC_PCR_EN ); + periph->layout->cmd | enable);spin_unlock_irqrestore (periph->lock, flags);return 0 ; } +static int clk_sam9x5_peripheral_enable (struct clk_hw *hw) +{ +struct clk_sam9x5_peripheral *periph =to_clk_sam9x5_peripheral (hw); + +return clk_sam9x5_peripheral_set (periph,1 ); +} +static void clk_sam9x5_peripheral_disable (struct clk_hw *hw) {struct clk_sam9x5_peripheral *periph =to_clk_sam9x5_peripheral (hw);
@@ -393,6 +401,23 @@ static int clk_sam9x5_peripheral_set_rate(struct clk_hw *hw,return -EINVAL ; } +static int clk_sam9x5_peripheral_save_context (struct clk_hw *hw) +{ +struct clk_sam9x5_peripheral *periph =to_clk_sam9x5_peripheral (hw); + + periph->pms.status =clk_sam9x5_peripheral_is_enabled (hw); + +return 0 ; +} + +static void clk_sam9x5_peripheral_restore_context (struct clk_hw *hw) +{ +struct clk_sam9x5_peripheral *periph =to_clk_sam9x5_peripheral (hw); + +if (periph->pms.status) +clk_sam9x5_peripheral_set (periph, periph->pms.status); +} +static const struct clk_ops sam9x5_peripheral_ops = { .enable = clk_sam9x5_peripheral_enable, .disable = clk_sam9x5_peripheral_disable,
@@ -400,6 +425,8 @@ static const struct clk_ops sam9x5_peripheral_ops = { .recalc_rate = clk_sam9x5_peripheral_recalc_rate, .round_rate = clk_sam9x5_peripheral_round_rate, .set_rate = clk_sam9x5_peripheral_set_rate, + .save_context = clk_sam9x5_peripheral_save_context, + .restore_context = clk_sam9x5_peripheral_restore_context, };static const struct clk_ops sam9x5_peripheral_chg_ops = {
@@ -409,6 +436,8 @@ static const struct clk_ops sam9x5_peripheral_chg_ops = { .recalc_rate = clk_sam9x5_peripheral_recalc_rate, .determine_rate = clk_sam9x5_peripheral_determine_rate, .set_rate = clk_sam9x5_peripheral_set_rate, + .save_context = clk_sam9x5_peripheral_save_context, + .restore_context = clk_sam9x5_peripheral_restore_context, }; struct clk_hw * __init
@@ -460,7 +489,6 @@ at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock, hw =ERR_PTR (ret); }else {clk_sam9x5_peripheral_autodiv (periph); -pmc_register_id (id); }return hw;
drivers/clk/at91/clk-pll.c +37 -0
@@ -40,6 +40,7 @@ struct clk_pll {u16 mul;const struct clk_pll_layout *layout;const struct clk_pll_characteristics *characteristics; +struct at91_clk_pms pms; };static inline bool clk_pll_ready (struct regmap *regmap,int id)
@@ -260,6 +261,40 @@ static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,return 0 ; } +static int clk_pll_save_context (struct clk_hw *hw) +{ +struct clk_pll *pll =to_clk_pll (hw); +struct clk_hw *parent_hw =clk_hw_get_parent (hw); + + pll->pms.parent_rate =clk_hw_get_rate (parent_hw); + pll->pms.rate =clk_pll_recalc_rate (&pll->hw, pll->pms.parent_rate); + pll->pms.status =clk_pll_ready (pll->regmap,PLL_REG (pll->id)); + +return 0 ; +} + +static void clk_pll_restore_context (struct clk_hw *hw) +{ +struct clk_pll *pll =to_clk_pll (hw); +unsigned long calc_rate; +unsigned int pllr; +u8 out =0 ; + +if (pll->characteristics->out) + out = pll->characteristics->out[pll->range]; + +regmap_read (pll->regmap,PLL_REG (pll->id), &pllr); + + calc_rate = (pll->pms.parent_rate /PLL_DIV (pllr)) * + (PLL_MUL (pllr, pll->layout) +1 ); + +if (pll->pms.rate != calc_rate || + pll->pms.status !=clk_pll_ready (pll->regmap,PLL_REG (pll->id)) || + (((pllr >>PLL_COUNT_SHIFT ) &PLL_MAX_COUNT ) !=PLL_MAX_COUNT ) || + (out && ((pllr >>PLL_OUT_SHIFT ) & out) != out)) +pr_warn ("PLLAR was not configured properly by firmware\n" ); +} +static const struct clk_ops pll_ops = { .prepare = clk_pll_prepare, .unprepare = clk_pll_unprepare,
@@ -267,6 +302,8 @@ static const struct clk_ops pll_ops = { .recalc_rate = clk_pll_recalc_rate, .round_rate = clk_pll_round_rate, .set_rate = clk_pll_set_rate, + .save_context = clk_pll_save_context, + .restore_context = clk_pll_restore_context, }; struct clk_hw * __init
drivers/clk/at91/clk-programmable.c +27 -2
@@ -24,6 +24,7 @@ struct clk_programmable {u32 *mux_table;u8 id;const struct clk_programmable_layout *layout; +struct at91_clk_pms pms; };#define to_clk_programmable (hw) container_of(hw, struct clk_programmable, hw)
@@ -177,12 +178,38 @@ static int clk_programmable_set_rate(struct clk_hw *hw, unsigned long rate,return 0 ; } +static int clk_programmable_save_context (struct clk_hw *hw) +{ +struct clk_programmable *prog =to_clk_programmable (hw); +struct clk_hw *parent_hw =clk_hw_get_parent (hw); + + prog->pms.parent =clk_programmable_get_parent (hw); + prog->pms.parent_rate =clk_hw_get_rate (parent_hw); + prog->pms.rate =clk_programmable_recalc_rate (hw, prog->pms.parent_rate); + +return 0 ; +} + +static void clk_programmable_restore_context (struct clk_hw *hw) +{ +struct clk_programmable *prog =to_clk_programmable (hw); +int ret; + + ret =clk_programmable_set_parent (hw, prog->pms.parent); +if (ret) +return ; + +clk_programmable_set_rate (hw, prog->pms.rate, prog->pms.parent_rate); +} +static const struct clk_ops programmable_ops = { .recalc_rate = clk_programmable_recalc_rate, .determine_rate = clk_programmable_determine_rate, .get_parent = clk_programmable_get_parent, .set_parent = clk_programmable_set_parent, .set_rate = clk_programmable_set_rate, + .save_context = clk_programmable_save_context, + .restore_context = clk_programmable_restore_context, }; struct clk_hw * __init
@@ -221,8 +248,6 @@ at91_clk_register_programmable(struct regmap *regmap,if (ret) {kfree (prog); hw =ERR_PTR (ret); - }else { -pmc_register_pck (id); }return hw;
drivers/clk/at91/clk-sam9x60-pll.c +64 -4
138 lines not on this page · raw message
drivers/clk/at91/clk-system.c +20 -0
@@ -20,6 +20,7 @@struct clk_system {struct clk_hw hw;struct regmap *regmap; +struct at91_clk_pms pms;u8 id; };
@@ -77,10 +78,29 @@ static int clk_system_is_prepared(struct clk_hw *hw)return !!(status & (1 << sys->id)); } +static int clk_system_save_context (struct clk_hw *hw) +{ +struct clk_system *sys =to_clk_system (hw); + + sys->pms.status =clk_system_is_prepared (hw); + +return 0 ; +} + +static void clk_system_restore_context (struct clk_hw *hw) +{ +struct clk_system *sys =to_clk_system (hw); + +if (sys->pms.status) +clk_system_prepare (&sys->hw); +} +static const struct clk_ops system_ops = { .prepare = clk_system_prepare, .unprepare = clk_system_unprepare, .is_prepared = clk_system_is_prepared, + .save_context = clk_system_save_context, + .restore_context = clk_system_restore_context, }; struct clk_hw * __init
drivers/clk/at91/clk-usb.c +27 -0
@@ -24,6 +24,7 @@struct at91sam9x5_clk_usb {struct clk_hw hw;struct regmap *regmap; +struct at91_clk_pms pms;u32 usbs_mask;u8 num_parents; };
@@ -148,12 +149,38 @@ static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,return 0 ; } +static int at91sam9x5_usb_save_context (struct clk_hw *hw) +{ +struct at91sam9x5_clk_usb *usb =to_at91sam9x5_clk_usb (hw); +struct clk_hw *parent_hw =clk_hw_get_parent (hw); + + usb->pms.parent =at91sam9x5_clk_usb_get_parent (hw); + usb->pms.parent_rate =clk_hw_get_rate (parent_hw); + usb->pms.rate =at91sam9x5_clk_usb_recalc_rate (hw, usb->pms.parent_rate); + +return 0 ; +} + +static void at91sam9x5_usb_restore_context (struct clk_hw *hw) +{ +struct at91sam9x5_clk_usb *usb =to_at91sam9x5_clk_usb (hw); +int ret; + + ret =at91sam9x5_clk_usb_set_parent (hw, usb->pms.parent); +if (ret) +return ; + +at91sam9x5_clk_usb_set_rate (hw, usb->pms.rate, usb->pms.parent_rate); +} +static const struct clk_ops at91sam9x5_usb_ops = { .recalc_rate = at91sam9x5_clk_usb_recalc_rate, .determine_rate = at91sam9x5_clk_usb_determine_rate, .get_parent = at91sam9x5_clk_usb_get_parent, .set_parent = at91sam9x5_clk_usb_set_parent, .set_rate = at91sam9x5_clk_usb_set_rate, + .save_context = at91sam9x5_usb_save_context, + .restore_context = at91sam9x5_usb_restore_context, };static int at91sam9n12_clk_usb_enable (struct clk_hw *hw)
drivers/clk/at91/clk-utmi.c +46 -1
73 lines not on this page · raw message
drivers/clk/at91/pmc.c +8 -141
181 lines not on this page · raw message
drivers/clk/at91/pmc.h +16 -8
@@ -13,6 +13,8 @@#include <linux/regmap.h> #include <linux/spinlock.h> +#include <dt-bindings/clock/at91.h> +extern spinlock_t pmc_pcr_lock;struct pmc_data {
@@ -98,6 +100,20 @@ struct clk_pcr_layout {u32 pid_mask; }; +/** +* struct at91_clk_pms - Power management state for AT91 clock +* @status: clock status (enabled or disabled) +* @parent: clock parent index +* @parent_rate: clock parent rate +* @rate: clock rate +*/ +struct at91_clk_pms { +unsigned int status; +unsigned int parent; +unsigned long parent_rate; +unsigned long rate; +}; +#define field_get (_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))#define field_prep (_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))
@@ -248,12 +264,4 @@ struct clk_hw * __init at91_clk_sama7g5_register_utmi(struct regmap *regmap, const char *name, const char *parent_name); -#ifdef CONFIG_PM -void pmc_register_id (u8 id); -void pmc_register_pck (u8 pck); -#else -static inline void pmc_register_id (u8 id) {} -static inline void pmc_register_pck (u8 pck) {} -#endif -#endif /* __PMC_H_ */
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/6 clk: at91: pmc: execute suspend/resume only for backup mode
In reply to Claudiu BezneaBefore going to backup mode architecture specific PM code sets the first word in securam (and it will be cleared in a subsequent commit for the rest of power saving modes). Thus take this into account when suspending/resuming clocks. This will avoid executing unnecessary instructions when suspending to non backup modes. Since the clear of the 1st word in securam will be done in a subsequent commit the current commit will not broke the current behavior since up to this moment the suspend/resume were executed for all AT91 PM modes. The difference now is that the suspend/resume for clocks will be executed for the rest of AT91 PM modes just after the 1st enter/exit to/from backup mode. Also this commit changed the postcore_initcall() with subsys_initcall() to be able to execute of_find_compatible_node() since this was not available at the moment of postcore_initcall(). This should not alter the tcb_clksrc since the changes are related to clocks suspend/resume procedure that will be executed at the user space request, thus long ago after postcore_initcall().
--- drivers/clk/at91/pmc.c | 48 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-)
drivers/clk/at91/pmc.c +39 -9
@@ -8,6 +8,8 @@#include <linux/clkdev.h> #include <linux/clk/at91_pmc.h> #include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> #include <linux/mfd/syscon.h> #include <linux/platform_device.h> #include <linux/regmap.h>
@@ -110,13 +112,35 @@ struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem, }#ifdef CONFIG_PM + +/* Address in SECURAM that say if we suspend to backup mode. */ +static void __iomem *at91_pmc_backup_suspend; +static int at91_pmc_suspend (void ) { +unsigned int backup; + +if (!at91_pmc_backup_suspend) +return 0 ; + + backup = *(unsigned int *)at91_pmc_backup_suspend; +if (!backup) +return 0 ; +return clk_save_context (); }static void at91_pmc_resume (void ) { +unsigned int backup; + +if (!at91_pmc_backup_suspend) +return ; + + backup = *(unsigned int *)at91_pmc_backup_suspend; +if (!backup) +return ; +clk_restore_context (); }
@@ -125,24 +149,30 @@ static struct syscore_ops pmc_syscore_ops = { .resume = at91_pmc_resume, }; -static const struct of_device_id sama5d2_pmc_dt_ids[] = { - { .compatible ="atmel,sama5d2-pmc" }, - {/* sentinel */ } -}; -static int __init pmc_register_ops (void ) { +struct platform_device *pdev;struct device_node *np; - np =of_find_matching_node (NULL , sama5d2_pmc_dt_ids); + np =of_find_compatible_node (NULL ,NULL ,"atmel,sama5d2-securam" );if (!np) -return 0 ; +return -ENODEV ; + + pdev =of_find_device_by_node (np);of_node_put (np); +if (!pdev) +return -ENODEV ; + + at91_pmc_backup_suspend =of_iomap (np,0 ); +if (!at91_pmc_backup_suspend) { +pr_warn ("%s(): unable to map securam\n" , __func__); +return -ENOMEM ; + }register_syscore_ops (&pmc_syscore_ops);return 0 ; } -/* This has to happen before arch_initcall because of the tcb_clksrc driver */ -postcore_initcall (pmc_register_ops); + +subsys_initcall (pmc_register_ops);#endif
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 3/6 clk: at91: sama7g5: add securam's peripheral clock
In reply to Claudiu BezneaAdd SECURAM's peripheral clock.
--- drivers/clk/at91/sama7g5.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/at91/sama7g5.c +1 -0
@@ -377,6 +377,7 @@ static const struct {u8 id; } sama7g5_periphck[] = { { .n = "pioA_clk", .p = "mck0", .id = 11, }, + { .n = "securam_clk", .p = "mck0", .id = 18, }, { .n = "sfr_clk", .p = "mck1", .id = 19, }, { .n = "hsmc_clk", .p = "mck1", .id = 21, }, { .n = "xdmac0_clk", .p = "mck1", .id = 22, },
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 4/6 clk: at91: clk-master: add register definition for sama7g5's master clock
In reply to Claudiu BezneaAdd register definitions for SAMA7G5's master clock. These would be also used by architecture specific power saving code. With this, update also clk-master.c.
--- drivers/clk/at91/clk-master.c | 50 ++++++++++++++++------------------- include/linux/clk/at91_pmc.h | 26 ++++++++++++++++++ 2 files changed, 49 insertions(+), 27 deletions(-)
drivers/clk/at91/clk-master.c +23 -27
@@ -17,15 +17,7 @@#define MASTER_DIV_SHIFT 8#define MASTER_DIV_MASK 0x7 -#define PMC_MCR 0x30 -#define PMC_MCR_ID_MSK GENMASK(3, 0) -#define PMC_MCR_CMD BIT(7) -#define PMC_MCR_DIV GENMASK(10, 8) -#define PMC_MCR_CSS GENMASK(20, 16)#define PMC_MCR_CSS_SHIFT (16) -#define PMC_MCR_EN BIT(28) - -#define PMC_MCR_ID (x) ((x) & PMC_MCR_ID_MSK)#define MASTER_MAX_ID 4
@@ -682,20 +674,22 @@ static void clk_sama7g5_master_set(struct clk_master *master, {unsigned long flags;unsigned int val, cparent; -unsigned int enable = status ?PMC_MCR_EN :0 ; +unsigned int enable = status ?AT91_PMC_MCR_V2_EN :0 ;spin_lock_irqsave (master->lock, flags); -regmap_write (master->regmap,PMC_MCR ,PMC_MCR_ID (master->id)); -regmap_read (master->regmap,PMC_MCR , &val); -regmap_update_bits (master->regmap,PMC_MCR , - enable |PMC_MCR_CSS |PMC_MCR_DIV | -PMC_MCR_CMD |PMC_MCR_ID_MSK , +regmap_write (master->regmap,AT91_PMC_MCR_V2 , +AT91_PMC_MCR_V2_ID (master->id)); +regmap_read (master->regmap,AT91_PMC_MCR_V2 , &val); +regmap_update_bits (master->regmap,AT91_PMC_MCR_V2 , + enable |AT91_PMC_MCR_V2_CSS |AT91_PMC_MCR_V2_DIV | +AT91_PMC_MCR_V2_CMD |AT91_PMC_MCR_V2_ID_MSK , enable | (master->parent <<PMC_MCR_CSS_SHIFT ) | (master->div <<MASTER_DIV_SHIFT ) | -PMC_MCR_CMD |PMC_MCR_ID (master->id)); +AT91_PMC_MCR_V2_CMD | +AT91_PMC_MCR_V2_ID (master->id)); - cparent = (val &PMC_MCR_CSS ) >>PMC_MCR_CSS_SHIFT ; + cparent = (val &AT91_PMC_MCR_V2_CSS ) >>PMC_MCR_CSS_SHIFT ;/* Wait here only if parent is being changed. */ while ((cparent != master->parent) && !clk_master_ready (master))
@@ -720,10 +714,12 @@ static void clk_sama7g5_master_disable(struct clk_hw *hw)spin_lock_irqsave (master->lock, flags); -regmap_write (master->regmap,PMC_MCR , master->id); -regmap_update_bits (master->regmap,PMC_MCR , -PMC_MCR_EN |PMC_MCR_CMD |PMC_MCR_ID_MSK , -PMC_MCR_CMD |PMC_MCR_ID (master->id)); +regmap_write (master->regmap,AT91_PMC_MCR_V2 , master->id); +regmap_update_bits (master->regmap,AT91_PMC_MCR_V2 , +AT91_PMC_MCR_V2_EN |AT91_PMC_MCR_V2_CMD | +AT91_PMC_MCR_V2_ID_MSK , +AT91_PMC_MCR_V2_CMD | +AT91_PMC_MCR_V2_ID (master->id));spin_unlock_irqrestore (master->lock, flags); }
@@ -736,12 +732,12 @@ static int clk_sama7g5_master_is_enabled(struct clk_hw *hw)spin_lock_irqsave (master->lock, flags); -regmap_write (master->regmap,PMC_MCR , master->id); -regmap_read (master->regmap,PMC_MCR , &val); +regmap_write (master->regmap,AT91_PMC_MCR_V2 , master->id); +regmap_read (master->regmap,AT91_PMC_MCR_V2 , &val);spin_unlock_irqrestore (master->lock, flags); -return !!(val &PMC_MCR_EN ); +return !!(val &AT91_PMC_MCR_V2_EN ); } static int clk_sama7g5_master_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -837,10 +833,10 @@ at91_clk_sama7g5_register_master(struct regmap *regmap, master->mux_table = mux_table;spin_lock_irqsave (master->lock, flags); -regmap_write (master->regmap,PMC_MCR , master->id); -regmap_read (master->regmap,PMC_MCR , &val); - master->parent = (val &PMC_MCR_CSS ) >>PMC_MCR_CSS_SHIFT ; - master->div = (val &PMC_MCR_DIV ) >>MASTER_DIV_SHIFT ; +regmap_write (master->regmap,AT91_PMC_MCR_V2 , master->id); +regmap_read (master->regmap,AT91_PMC_MCR_V2 , &val); + master->parent = (val &AT91_PMC_MCR_V2_CSS ) >>PMC_MCR_CSS_SHIFT ; + master->div = (val &AT91_PMC_MCR_V2_DIV ) >>MASTER_DIV_SHIFT ;spin_unlock_irqrestore (master->lock, flags); hw = &master->hw;
include/linux/clk/at91_pmc.h +26 -0
@@ -137,6 +137,32 @@#define AT91_PMC_PLLADIV2_ON (1 << 12)#define AT91_PMC_H32MXDIV BIT(24) +#define AT91_PMC_MCR_V2 0x30/* Master Clock Register [SAMA7G5 only] */ +#define AT91_PMC_MCR_V2_ID_MSK (0xF) +#define AT91_PMC_MCR_V2_ID (_id) ((_id) & AT91_PMC_MCR_V2_ID_MSK) +#define AT91_PMC_MCR_V2_CMD (1 << 7) +#define AT91_PMC_MCR_V2_DIV (7 << 8) +#define AT91_PMC_MCR_V2_DIV1 (0 << 8) +#define AT91_PMC_MCR_V2_DIV2 (1 << 8) +#define AT91_PMC_MCR_V2_DIV4 (2 << 8) +#define AT91_PMC_MCR_V2_DIV8 (3 << 8) +#define AT91_PMC_MCR_V2_DIV16 (4 << 8) +#define AT91_PMC_MCR_V2_DIV32 (5 << 8) +#define AT91_PMC_MCR_V2_DIV64 (6 << 8) +#define AT91_PMC_MCR_V2_DIV3 (7 << 8) +#define AT91_PMC_MCR_V2_CSS (0x1F << 16) +#define AT91_PMC_MCR_V2_CSS_MD_SLCK (0 << 16) +#define AT91_PMC_MCR_V2_CSS_TD_SLCK (1 << 16) +#define AT91_PMC_MCR_V2_CSS_MAINCK (2 << 16) +#define AT91_PMC_MCR_V2_CSS_MCK0 (3 << 16) +#define AT91_PMC_MCR_V2_CSS_SYSPLL (5 << 16) +#define AT91_PMC_MCR_V2_CSS_DDRPLL (6 << 16) +#define AT91_PMC_MCR_V2_CSS_IMGPLL (7 << 16) +#define AT91_PMC_MCR_V2_CSS_BAUDPLL (8 << 16) +#define AT91_PMC_MCR_V2_CSS_AUDIOPLL (9 << 16) +#define AT91_PMC_MCR_V2_CSS_ETHPLL (10 << 16) +#define AT91_PMC_MCR_V2_EN (1 << 28) +#define AT91_PMC_XTALF 0x34/* Main XTAL Frequency Register [SAMA7G5 only] */ #define AT91_PMC_USB 0x38/* USB Clock Register [some SAM9 only] */
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 5/6 clk: at91: clk-master: update for dvfs
In reply to Claudiu BezneaSAMA7G5 supports CPU DVFS. The hardware block diagram for the clock system generating CPU clock is as follows:
+--------+
+-->|divider1|--> CPU clock
| +--------+
+--------+ +----------+ | +--------+
|CPU PLL |-->|prescaller|--+-->|divider0|--> MCK0 clock
+--------+ +----------+ +--------+The divider1 is not implemented in software since the supported CPU frequencies could be directly retrieved from CPU PLL + prescaller. Every time the CPU clock needs to be changed the MCK0 should also be changed to avoid its over/under clocking and also to preserve its initial value (200MHz). MCK0 feeds IPs that are glitch free aware.
The initial approach for implementing DVFS was to implement MCK0 and CPU clocks as 2 different Linux clocks, to pass these two clocks to CPUFreq driver and in CPUFreq driver to run clk_set_rate() on CPU and MCK clocks accordingly. E.g. if 1GHz speed was requested by CPUFreq subsystem the following were executed in CPUFreq driver:
/* ... */clk_set_rate(mck0, intermediary_freq_to_avoid_over_under_clocking); clk_set_rate(cpu, 1000000000);clk_set_rate(mck0, initial_freq);
/ ... */
However, it has been proposed in [1] to use the generic cpufreq-dt driver and to overload the necessary clocks operations in the proper clock driver.
To address this proposal the master clock prescaller registers a clock notifier that will update properly the master clock divider on PRE_RATE_CHANGE and POST_RATE_CHANGE events to avoid master clock divider over/under clocking and also to preserve its initial value (200MHz).
[1] https://lore.kernel.org/lkml/[email protected]/
--- drivers/clk/at91/at91rm9200.c | 2 +- drivers/clk/at91/at91sam9260.c | 2 +- drivers/clk/at91/at91sam9g45.c | 2 +- drivers/clk/at91/at91sam9n12.c | 2 +- drivers/clk/at91/at91sam9rl.c | 2 +- drivers/clk/at91/at91sam9x5.c | 2 +- drivers/clk/at91/clk-master.c | 187 ++++++++++++++++++++------------- drivers/clk/at91/dt-compat.c | 2 +- drivers/clk/at91/pmc.h | 3 +- drivers/clk/at91/sam9x60.c | 2 +- drivers/clk/at91/sama5d2.c | 2 +- drivers/clk/at91/sama5d3.c | 2 +- drivers/clk/at91/sama5d4.c | 2 +- drivers/clk/at91/sama7g5.c | 2 +- 14 files changed, 130 insertions(+), 84 deletions(-)
drivers/clk/at91/at91rm9200.c +1 -1
@@ -144,7 +144,7 @@ static void __init at91rm9200_pmc_setup(struct device_node *np) &at91rm9200_master_layout, &rm9200_mck_characteristics, &rm9200_mck_lock,CLK_SET_RATE_GATE , - INT_MIN); + INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/at91sam9260.c +1 -1
@@ -420,7 +420,7 @@ static void __init at91sam926x_pmc_setup(struct device_node *np, &at91rm9200_master_layout, data->mck_characteristics, &at91sam9260_mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/at91sam9g45.c +1 -1
@@ -155,7 +155,7 @@ static void __init at91sam9g45_pmc_setup(struct device_node *np) &at91rm9200_master_layout, &mck_characteristics, &at91sam9g45_mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/at91sam9n12.c +1 -1
@@ -182,7 +182,7 @@ static void __init at91sam9n12_pmc_setup(struct device_node *np) &at91sam9x5_master_layout, &mck_characteristics, &at91sam9n12_mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/at91sam9rl.c +1 -1
@@ -124,7 +124,7 @@ static void __init at91sam9rl_pmc_setup(struct device_node *np) &at91rm9200_master_layout, &sam9rl_mck_characteristics, &sam9rl_mck_lock,CLK_SET_RATE_GATE , - INT_MIN); + INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/at91sam9x5.c +1 -1
@@ -202,7 +202,7 @@ static void __init at91sam9x5_pmc_setup(struct device_node *np, parent_names, &at91sam9x5_master_layout, &mck_characteristics, &mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/clk-master.c +116 -71
291 lines not on this page · raw message
drivers/clk/at91/dt-compat.c +1 -1
@@ -393,7 +393,7 @@ of_at91_clk_master_setup(struct device_node *np, hw =at91_clk_register_master_pres (regmap,"masterck_pres" , num_parents, parent_names, layout, characteristics, &mck_lock, -CLK_SET_RATE_GATE ,INT_MIN ); +CLK_SET_RATE_GATE ,INT_MIN ,0 );if (IS_ERR (hw)) goto out_free_characteristics;
drivers/clk/at91/pmc.h +2 -1
@@ -175,7 +175,8 @@ at91_clk_register_master_pres(struct regmap *regmap, const char *name, int num_parents, const char **parent_names, const struct clk_master_layout *layout, const struct clk_master_characteristics *characteristics, - spinlock_t *lock, u32 flags, int chg_pid); + spinlock_t *lock, u32 flags, int chg_pid, + bool notifier);struct clk_hw *__init at91_clk_register_master_div(struct regmap *regmap, const char *name,
drivers/clk/at91/sam9x60.c +1 -1
@@ -272,7 +272,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np) hw =at91_clk_register_master_pres (regmap,"masterck_pres" ,3 , parent_names, &sam9x60_master_layout, &mck_characteristics, &mck_lock, -CLK_SET_RATE_GATE ,INT_MIN ); +CLK_SET_RATE_GATE ,INT_MIN ,0 );if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/sama5d2.c +1 -1
@@ -241,7 +241,7 @@ static void __init sama5d2_pmc_setup(struct device_node *np) parent_names, &at91sam9x5_master_layout, &mck_characteristics, &mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/sama5d3.c +1 -1
@@ -176,7 +176,7 @@ static void __init sama5d3_pmc_setup(struct device_node *np) parent_names, &at91sam9x5_master_layout, &mck_characteristics, &mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/sama5d4.c +1 -1
@@ -191,7 +191,7 @@ static void __init sama5d4_pmc_setup(struct device_node *np) parent_names, &at91sam9x5_master_layout, &mck_characteristics, &mck_lock, - CLK_SET_RATE_GATE, INT_MIN); + CLK_SET_RATE_GATE, INT_MIN, 0);if (IS_ERR (hw)) goto err_free;
drivers/clk/at91/sama7g5.c +1 -1
@@ -986,7 +986,7 @@ static void __init sama7g5_pmc_setup(struct device_node *np) hw =at91_clk_register_master_pres (regmap,"cpuck" ,1 , parent_names, &mck0_layout, &mck0_characteristics, &pmc_mck0_lock, -CLK_SET_RATE_PARENT ,0 ); +CLK_SET_RATE_PARENT ,0 ,1 );if (IS_ERR (hw)) goto err_free;
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 6/6 clk: at91: clk-master: improve readability by using local variables
In reply to Claudiu BezneaImprove readability in clk_sama7g5_master_set() by using local variables.
--- drivers/clk/at91/clk-master.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/at91/clk-master.c +3 -3
@@ -720,6 +720,8 @@ static void clk_sama7g5_master_set(struct clk_master *master,unsigned long flags;unsigned int val, cparent;unsigned int enable = status ?AT91_PMC_MCR_V2_EN :0 ; +unsigned int parent = master->parent <<PMC_MCR_CSS_SHIFT ; +unsigned int div = master->div <<MASTER_DIV_SHIFT ;spin_lock_irqsave (master->lock, flags);
@@ -729,9 +731,7 @@ static void clk_sama7g5_master_set(struct clk_master *master,regmap_update_bits (master->regmap,AT91_PMC_MCR_V2 , enable |AT91_PMC_MCR_V2_CSS |AT91_PMC_MCR_V2_DIV |AT91_PMC_MCR_V2_CMD |AT91_PMC_MCR_V2_ID_MSK , - enable | (master->parent <<PMC_MCR_CSS_SHIFT ) | - (master->div <<MASTER_DIV_SHIFT ) | -AT91_PMC_MCR_V2_CMD | + enable | parent | div |AT91_PMC_MCR_V2_CMD |AT91_PMC_MCR_V2_ID (master->id)); cparent = (val &AT91_PMC_MCR_V2_CSS ) >>PMC_MCR_CSS_SHIFT ;
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 35 lines · Claudiu Beznea
Hi,
This series addresses the power management for SAMA7G5 and also updates the master clock prescaller and master clock divider drivers to accommodate the requests at [1].
The power management part is implemented by adding save_context()/restore_context() on each clock driver (patch 1/6). Since the PM part is necessary only for backup mode (supported on SAMA5D2 and SAMA7G5) the
pmc.chas been adapted to call the save_context()/restore_context() only on switches to/from backup mode (patch 2/6).Patch 3/6 adds the securam clock on SAMA7G5. This is necessary for backup mode of SAMA7G5.
Patch 4/6 adds registers definitions for the new master clocks (MCK1..4) of SAMA7G5 and adapt the
clk-master.c. The defines exported ininclude/linux/clk/at91_pmc.hwill be also used by platform specific PM code.Patch 5/6 adpat the master clock divider and master clock prescaller to address the requests at [1].
Patch 6/6 clean up a bit the code in clk-master as suggested by Nicolas.
Thank you,
Claudiu Beznea[1] https://lore.kernel.org/lkml/20210105104426.4tmgc2l3vyicwedd@vireshk-i7/
Changes in v2:
- addressed code review comments
- collected tags
Quoted 7 lines
Claudiu Beznea (6):
clk: at91: re-factor clocks suspend/resume
clk: at91: pmc: execute suspend/resume only for backup mode
clk: at91: sama7g5: add securam's peripheral clock
clk: at91: clk-master: add register definition for sama7g5's master
clock
Hi Stephen,
Please ignore the DVFS patch in this series
(clk: at91: clk-master: update for dvfs) as I have some updates to it. I'll introduce them in the next version.
Thank you,
Claudiu Beznea
Stephen Boyd
maintainerQuoting [email protected] (2021-08-02 01:36:52)
Quoted 7 lines · Claudiu Beznea
Hi Stephen,
Please ignore the DVFS patch in this series
(clk: at91: clk-master: update for dvfs) as I have some updates to it. I'll introduce them in the next version.
Can I apply the rest of them though?
Quoted 6 lines · Stephen Boyd
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoting [email protected] (2021-08-02 01:36:52)
Quoted 3 lines · Claudiu Beznea
Hi Stephen,
Quoted 7 lines
Quoted 4 lines
Please ignore the DVFS patch in this series
(clk: at91: clk-master: update for dvfs) as I have some updates to it. I'll introduce them in the next version.Can I apply the rest of them though?
Yes, please! One note, at patch "clk: at91: clk-master: add register definition for sama7g5's master clock", is that changes in header (include/linux/clk/at91_pmc.h) were taken trough [1] via at91 tree because the build was broken at some point for multi_v7_defconfig on linux-next.
Thank you,
Claudiu Beznea
Stephen Boyd
maintainerQuoting [email protected] (2021-08-29 22:46:13)
Quoted 12 lines · Stephen Boyd
Quoted 11 lines
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoting [email protected] (2021-08-02 01:36:52)
Quoted 7 lines · Claudiu Beznea
Hi Stephen,
Please ignore the DVFS patch in this series
(clk: at91: clk-master: update for dvfs) as I have some updates to it. I'll introduce them in the next version.
Quoted 8 lines
Quoted 2 lines
Can I apply the rest of them though?
Yes, please! One note, at patch "clk: at91: clk-master: add register definition for sama7g5's master clock", is that changes in header (
include/linux/clk/at91_pmc.h) were taken trough [1] via at91 tree because the build was broken at some point formulti_v7_defconfigon linux-next.
Ok. Maybe it would be best to just resend the ones that you want me to apply then.