12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 20ad6125bSBoris BREZILLON /* 30ad6125bSBoris BREZILLON * drivers/clk/at91/pmc.h 40ad6125bSBoris BREZILLON * 50ad6125bSBoris BREZILLON * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> 60ad6125bSBoris BREZILLON */ 70ad6125bSBoris BREZILLON 80ad6125bSBoris BREZILLON #ifndef __PMC_H_ 90ad6125bSBoris BREZILLON #define __PMC_H_ 100ad6125bSBoris BREZILLON 110ad6125bSBoris BREZILLON #include <linux/io.h> 120ad6125bSBoris BREZILLON #include <linux/irqdomain.h> 13863a81c3SBoris Brezillon #include <linux/regmap.h> 140ad6125bSBoris BREZILLON #include <linux/spinlock.h> 150ad6125bSBoris BREZILLON 161bdf0232SBoris Brezillon extern spinlock_t pmc_pcr_lock; 171bdf0232SBoris Brezillon 18b00cd8e4SAlexandre Belloni struct pmc_data { 19b00cd8e4SAlexandre Belloni unsigned int ncore; 20b00cd8e4SAlexandre Belloni struct clk_hw **chws; 21b00cd8e4SAlexandre Belloni unsigned int nsystem; 22b00cd8e4SAlexandre Belloni struct clk_hw **shws; 23b00cd8e4SAlexandre Belloni unsigned int nperiph; 24b00cd8e4SAlexandre Belloni struct clk_hw **phws; 25b00cd8e4SAlexandre Belloni unsigned int ngck; 26b00cd8e4SAlexandre Belloni struct clk_hw **ghws; 2799767cd4SMichał Mirosław unsigned int npck; 2899767cd4SMichał Mirosław struct clk_hw **pchws; 297425f246SMichał Mirosław 307425f246SMichał Mirosław struct clk_hw *hwtable[]; 31b00cd8e4SAlexandre Belloni }; 32b00cd8e4SAlexandre Belloni 330ad6125bSBoris BREZILLON struct clk_range { 340ad6125bSBoris BREZILLON unsigned long min; 350ad6125bSBoris BREZILLON unsigned long max; 360ad6125bSBoris BREZILLON }; 370ad6125bSBoris BREZILLON 380ad6125bSBoris BREZILLON #define CLK_RANGE(MIN, MAX) {.min = MIN, .max = MAX,} 390ad6125bSBoris BREZILLON 40b2e39dc0SAlexandre Belloni struct clk_master_layout { 41e5be5370SAlexandre Belloni u32 offset; 42b2e39dc0SAlexandre Belloni u32 mask; 43b2e39dc0SAlexandre Belloni u8 pres_shift; 44b2e39dc0SAlexandre Belloni }; 45b2e39dc0SAlexandre Belloni 46b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91rm9200_master_layout; 47b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91sam9x5_master_layout; 48b2e39dc0SAlexandre Belloni 49b2e39dc0SAlexandre Belloni struct clk_master_characteristics { 50b2e39dc0SAlexandre Belloni struct clk_range output; 51b2e39dc0SAlexandre Belloni u32 divisors[4]; 52b2e39dc0SAlexandre Belloni u8 have_div3_pres; 53b2e39dc0SAlexandre Belloni }; 54b2e39dc0SAlexandre Belloni 55b2e39dc0SAlexandre Belloni struct clk_pll_layout { 56b2e39dc0SAlexandre Belloni u32 pllr_mask; 57b2e39dc0SAlexandre Belloni u16 mul_mask; 58b2e39dc0SAlexandre Belloni u8 mul_shift; 59b2e39dc0SAlexandre Belloni }; 60b2e39dc0SAlexandre Belloni 61b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91rm9200_pll_layout; 62b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g45_pll_layout; 63b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g20_pllb_layout; 64b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout sama5d3_pll_layout; 65b2e39dc0SAlexandre Belloni 66b2e39dc0SAlexandre Belloni struct clk_pll_characteristics { 67b2e39dc0SAlexandre Belloni struct clk_range input; 68b2e39dc0SAlexandre Belloni int num_output; 697b4c162eSStephen Boyd const struct clk_range *output; 70b2e39dc0SAlexandre Belloni u16 *icpll; 71b2e39dc0SAlexandre Belloni u8 *out; 72a436c2a4SAlexandre Belloni u8 upll : 1; 73b2e39dc0SAlexandre Belloni }; 74b2e39dc0SAlexandre Belloni 75b2e39dc0SAlexandre Belloni struct clk_programmable_layout { 7645b06682SMatthias Wieloch u8 pres_mask; 77b2e39dc0SAlexandre Belloni u8 pres_shift; 78b2e39dc0SAlexandre Belloni u8 css_mask; 79b2e39dc0SAlexandre Belloni u8 have_slck_mck; 8045b06682SMatthias Wieloch u8 is_pres_direct; 81b2e39dc0SAlexandre Belloni }; 82b2e39dc0SAlexandre Belloni 83b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91rm9200_programmable_layout; 84b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9g45_programmable_layout; 85b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9x5_programmable_layout; 86b2e39dc0SAlexandre Belloni 87cb4f4949SAlexandre Belloni struct clk_pcr_layout { 88cb4f4949SAlexandre Belloni u32 offset; 89cb4f4949SAlexandre Belloni u32 cmd; 90cb4f4949SAlexandre Belloni u32 div_mask; 91cb4f4949SAlexandre Belloni u32 gckcss_mask; 92cb4f4949SAlexandre Belloni u32 pid_mask; 93cb4f4949SAlexandre Belloni }; 94cb4f4949SAlexandre Belloni 95cb4f4949SAlexandre Belloni #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) 96cb4f4949SAlexandre Belloni #define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) 97cb4f4949SAlexandre Belloni 98b00cd8e4SAlexandre Belloni #define ndck(a, s) (a[s - 1].id + 1) 99b00cd8e4SAlexandre Belloni #define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1) 100b00cd8e4SAlexandre Belloni struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem, 10199767cd4SMichał Mirosław unsigned int nperiph, unsigned int ngck, 10299767cd4SMichał Mirosław unsigned int npck); 103b00cd8e4SAlexandre Belloni 1040ad6125bSBoris BREZILLON int of_at91_get_clk_range(struct device_node *np, const char *propname, 1050ad6125bSBoris BREZILLON struct clk_range *range); 1060ad6125bSBoris BREZILLON 107b2e39dc0SAlexandre Belloni struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data); 108b2e39dc0SAlexandre Belloni 109b2e39dc0SAlexandre Belloni struct clk_hw * __init 110b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_frac(struct regmap *regmap, const char *name, 111b2e39dc0SAlexandre Belloni const char *parent_name); 112b2e39dc0SAlexandre Belloni 113b2e39dc0SAlexandre Belloni struct clk_hw * __init 114b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pad(struct regmap *regmap, const char *name, 115b2e39dc0SAlexandre Belloni const char *parent_name); 116b2e39dc0SAlexandre Belloni 117b2e39dc0SAlexandre Belloni struct clk_hw * __init 118b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pmc(struct regmap *regmap, const char *name, 119b2e39dc0SAlexandre Belloni const char *parent_name); 120b2e39dc0SAlexandre Belloni 121b2e39dc0SAlexandre Belloni struct clk_hw * __init 122b2e39dc0SAlexandre Belloni at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, 123e4cfb823SAlexandre Belloni const struct clk_pcr_layout *layout, 124b2e39dc0SAlexandre Belloni const char *name, const char **parent_names, 12522a1dfe9SClaudiu Beznea u32 *mux_table, u8 num_parents, u8 id, 12664c9247bSClaudiu Beznea const struct clk_range *range, int chg_pid); 127b2e39dc0SAlexandre Belloni 128b2e39dc0SAlexandre Belloni struct clk_hw * __init 129b2e39dc0SAlexandre Belloni at91_clk_register_h32mx(struct regmap *regmap, const char *name, 130b2e39dc0SAlexandre Belloni const char *parent_name); 131b2e39dc0SAlexandre Belloni 132b2e39dc0SAlexandre Belloni struct clk_hw * __init 133b2e39dc0SAlexandre Belloni at91_clk_i2s_mux_register(struct regmap *regmap, const char *name, 134b2e39dc0SAlexandre Belloni const char * const *parent_names, 135b2e39dc0SAlexandre Belloni unsigned int num_parents, u8 bus_id); 136b2e39dc0SAlexandre Belloni 137b2e39dc0SAlexandre Belloni struct clk_hw * __init 138b2e39dc0SAlexandre Belloni at91_clk_register_main_rc_osc(struct regmap *regmap, const char *name, 139b2e39dc0SAlexandre Belloni u32 frequency, u32 accuracy); 140b2e39dc0SAlexandre Belloni struct clk_hw * __init 141b2e39dc0SAlexandre Belloni at91_clk_register_main_osc(struct regmap *regmap, const char *name, 142b2e39dc0SAlexandre Belloni const char *parent_name, bool bypass); 143b2e39dc0SAlexandre Belloni struct clk_hw * __init 144b2e39dc0SAlexandre Belloni at91_clk_register_rm9200_main(struct regmap *regmap, 145b2e39dc0SAlexandre Belloni const char *name, 146b2e39dc0SAlexandre Belloni const char *parent_name); 147b2e39dc0SAlexandre Belloni struct clk_hw * __init 148b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_main(struct regmap *regmap, const char *name, 149b2e39dc0SAlexandre Belloni const char **parent_names, int num_parents); 150b2e39dc0SAlexandre Belloni 151b2e39dc0SAlexandre Belloni struct clk_hw * __init 152b2e39dc0SAlexandre Belloni at91_clk_register_master(struct regmap *regmap, const char *name, 153b2e39dc0SAlexandre Belloni int num_parents, const char **parent_names, 154b2e39dc0SAlexandre Belloni const struct clk_master_layout *layout, 155b2e39dc0SAlexandre Belloni const struct clk_master_characteristics *characteristics); 156b2e39dc0SAlexandre Belloni 157b2e39dc0SAlexandre Belloni struct clk_hw * __init 15875c88143SClaudiu Beznea at91_clk_sama7g5_register_master(struct regmap *regmap, 15975c88143SClaudiu Beznea const char *name, int num_parents, 16075c88143SClaudiu Beznea const char **parent_names, u32 *mux_table, 16175c88143SClaudiu Beznea spinlock_t *lock, u8 id, bool critical, 16275c88143SClaudiu Beznea int chg_pid); 16375c88143SClaudiu Beznea 16475c88143SClaudiu Beznea struct clk_hw * __init 165b2e39dc0SAlexandre Belloni at91_clk_register_peripheral(struct regmap *regmap, const char *name, 166b2e39dc0SAlexandre Belloni const char *parent_name, u32 id); 167b2e39dc0SAlexandre Belloni struct clk_hw * __init 168b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock, 169cb4f4949SAlexandre Belloni const struct clk_pcr_layout *layout, 170b2e39dc0SAlexandre Belloni const char *name, const char *parent_name, 171*b4c115c7SClaudiu Beznea u32 id, const struct clk_range *range, 172*b4c115c7SClaudiu Beznea int chg_pid); 173b2e39dc0SAlexandre Belloni 174b2e39dc0SAlexandre Belloni struct clk_hw * __init 175b2e39dc0SAlexandre Belloni at91_clk_register_pll(struct regmap *regmap, const char *name, 176b2e39dc0SAlexandre Belloni const char *parent_name, u8 id, 177b2e39dc0SAlexandre Belloni const struct clk_pll_layout *layout, 178b2e39dc0SAlexandre Belloni const struct clk_pll_characteristics *characteristics); 179b2e39dc0SAlexandre Belloni struct clk_hw * __init 180b2e39dc0SAlexandre Belloni at91_clk_register_plldiv(struct regmap *regmap, const char *name, 181b2e39dc0SAlexandre Belloni const char *parent_name); 182b2e39dc0SAlexandre Belloni 183b2e39dc0SAlexandre Belloni struct clk_hw * __init 184a436c2a4SAlexandre Belloni sam9x60_clk_register_pll(struct regmap *regmap, spinlock_t *lock, 185a436c2a4SAlexandre Belloni const char *name, const char *parent_name, u8 id, 186a436c2a4SAlexandre Belloni const struct clk_pll_characteristics *characteristics); 187a436c2a4SAlexandre Belloni 188a436c2a4SAlexandre Belloni struct clk_hw * __init 189b2e39dc0SAlexandre Belloni at91_clk_register_programmable(struct regmap *regmap, const char *name, 190b2e39dc0SAlexandre Belloni const char **parent_names, u8 num_parents, u8 id, 191b2e39dc0SAlexandre Belloni const struct clk_programmable_layout *layout); 192b2e39dc0SAlexandre Belloni 193b2e39dc0SAlexandre Belloni struct clk_hw * __init 194b2e39dc0SAlexandre Belloni at91_clk_register_sam9260_slow(struct regmap *regmap, 195b2e39dc0SAlexandre Belloni const char *name, 196b2e39dc0SAlexandre Belloni const char **parent_names, 197b2e39dc0SAlexandre Belloni int num_parents); 198b2e39dc0SAlexandre Belloni 199b2e39dc0SAlexandre Belloni struct clk_hw * __init 200b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name, 201b2e39dc0SAlexandre Belloni const char **parent_names, u8 num_parents); 202b2e39dc0SAlexandre Belloni 203b2e39dc0SAlexandre Belloni struct clk_hw * __init 204b2e39dc0SAlexandre Belloni at91_clk_register_system(struct regmap *regmap, const char *name, 205b2e39dc0SAlexandre Belloni const char *parent_name, u8 id); 206b2e39dc0SAlexandre Belloni 207b2e39dc0SAlexandre Belloni struct clk_hw * __init 208b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, 209b2e39dc0SAlexandre Belloni const char **parent_names, u8 num_parents); 210b2e39dc0SAlexandre Belloni struct clk_hw * __init 211b2e39dc0SAlexandre Belloni at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name, 212b2e39dc0SAlexandre Belloni const char *parent_name); 213b2e39dc0SAlexandre Belloni struct clk_hw * __init 2142423eeaeSAlexandre Belloni sam9x60_clk_register_usb(struct regmap *regmap, const char *name, 2152423eeaeSAlexandre Belloni const char **parent_names, u8 num_parents); 2162423eeaeSAlexandre Belloni struct clk_hw * __init 217b2e39dc0SAlexandre Belloni at91rm9200_clk_register_usb(struct regmap *regmap, const char *name, 218b2e39dc0SAlexandre Belloni const char *parent_name, const u32 *divisors); 219b2e39dc0SAlexandre Belloni 220b2e39dc0SAlexandre Belloni struct clk_hw * __init 221b2e39dc0SAlexandre Belloni at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr, 222b2e39dc0SAlexandre Belloni const char *name, const char *parent_name); 223b2e39dc0SAlexandre Belloni 224b3b02eacSAlexandre Belloni #ifdef CONFIG_PM 225b3b02eacSAlexandre Belloni void pmc_register_id(u8 id); 22613967beaSRomain Izard void pmc_register_pck(u8 pck); 227b3b02eacSAlexandre Belloni #else 228b3b02eacSAlexandre Belloni static inline void pmc_register_id(u8 id) {} 22913967beaSRomain Izard static inline void pmc_register_pck(u8 pck) {} 230b3b02eacSAlexandre Belloni #endif 231b3b02eacSAlexandre Belloni 2320ad6125bSBoris BREZILLON #endif /* __PMC_H_ */ 233