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; 57*43b1bb4aSClaudiu Beznea u32 mul_mask; 58*43b1bb4aSClaudiu Beznea u32 frac_mask; 59*43b1bb4aSClaudiu Beznea u32 div_mask; 60*43b1bb4aSClaudiu Beznea u32 endiv_mask; 61b2e39dc0SAlexandre Belloni u8 mul_shift; 62*43b1bb4aSClaudiu Beznea u8 frac_shift; 63*43b1bb4aSClaudiu Beznea u8 div_shift; 64*43b1bb4aSClaudiu Beznea u8 endiv_shift; 65b2e39dc0SAlexandre Belloni }; 66b2e39dc0SAlexandre Belloni 67b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91rm9200_pll_layout; 68b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g45_pll_layout; 69b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g20_pllb_layout; 70b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout sama5d3_pll_layout; 71b2e39dc0SAlexandre Belloni 72b2e39dc0SAlexandre Belloni struct clk_pll_characteristics { 73b2e39dc0SAlexandre Belloni struct clk_range input; 74b2e39dc0SAlexandre Belloni int num_output; 757b4c162eSStephen Boyd const struct clk_range *output; 76b2e39dc0SAlexandre Belloni u16 *icpll; 77b2e39dc0SAlexandre Belloni u8 *out; 78a436c2a4SAlexandre Belloni u8 upll : 1; 79b2e39dc0SAlexandre Belloni }; 80b2e39dc0SAlexandre Belloni 81b2e39dc0SAlexandre Belloni struct clk_programmable_layout { 8245b06682SMatthias Wieloch u8 pres_mask; 83b2e39dc0SAlexandre Belloni u8 pres_shift; 84b2e39dc0SAlexandre Belloni u8 css_mask; 85b2e39dc0SAlexandre Belloni u8 have_slck_mck; 8645b06682SMatthias Wieloch u8 is_pres_direct; 87b2e39dc0SAlexandre Belloni }; 88b2e39dc0SAlexandre Belloni 89b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91rm9200_programmable_layout; 90b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9g45_programmable_layout; 91b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9x5_programmable_layout; 92b2e39dc0SAlexandre Belloni 93cb4f4949SAlexandre Belloni struct clk_pcr_layout { 94cb4f4949SAlexandre Belloni u32 offset; 95cb4f4949SAlexandre Belloni u32 cmd; 96cb4f4949SAlexandre Belloni u32 div_mask; 97cb4f4949SAlexandre Belloni u32 gckcss_mask; 98cb4f4949SAlexandre Belloni u32 pid_mask; 99cb4f4949SAlexandre Belloni }; 100cb4f4949SAlexandre Belloni 101cb4f4949SAlexandre Belloni #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) 102cb4f4949SAlexandre Belloni #define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) 103cb4f4949SAlexandre Belloni 104b00cd8e4SAlexandre Belloni #define ndck(a, s) (a[s - 1].id + 1) 105b00cd8e4SAlexandre Belloni #define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1) 106b00cd8e4SAlexandre Belloni struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem, 10799767cd4SMichał Mirosław unsigned int nperiph, unsigned int ngck, 10899767cd4SMichał Mirosław unsigned int npck); 109b00cd8e4SAlexandre Belloni 1100ad6125bSBoris BREZILLON int of_at91_get_clk_range(struct device_node *np, const char *propname, 1110ad6125bSBoris BREZILLON struct clk_range *range); 1120ad6125bSBoris BREZILLON 113b2e39dc0SAlexandre Belloni struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data); 114b2e39dc0SAlexandre Belloni 115b2e39dc0SAlexandre Belloni struct clk_hw * __init 116b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_frac(struct regmap *regmap, const char *name, 117b2e39dc0SAlexandre Belloni const char *parent_name); 118b2e39dc0SAlexandre Belloni 119b2e39dc0SAlexandre Belloni struct clk_hw * __init 120b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pad(struct regmap *regmap, const char *name, 121b2e39dc0SAlexandre Belloni const char *parent_name); 122b2e39dc0SAlexandre Belloni 123b2e39dc0SAlexandre Belloni struct clk_hw * __init 124b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pmc(struct regmap *regmap, const char *name, 125b2e39dc0SAlexandre Belloni const char *parent_name); 126b2e39dc0SAlexandre Belloni 127b2e39dc0SAlexandre Belloni struct clk_hw * __init 128b2e39dc0SAlexandre Belloni at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, 129e4cfb823SAlexandre Belloni const struct clk_pcr_layout *layout, 130b2e39dc0SAlexandre Belloni const char *name, const char **parent_names, 13122a1dfe9SClaudiu Beznea u32 *mux_table, u8 num_parents, u8 id, 13264c9247bSClaudiu Beznea const struct clk_range *range, int chg_pid); 133b2e39dc0SAlexandre Belloni 134b2e39dc0SAlexandre Belloni struct clk_hw * __init 135b2e39dc0SAlexandre Belloni at91_clk_register_h32mx(struct regmap *regmap, const char *name, 136b2e39dc0SAlexandre Belloni const char *parent_name); 137b2e39dc0SAlexandre Belloni 138b2e39dc0SAlexandre Belloni struct clk_hw * __init 139b2e39dc0SAlexandre Belloni at91_clk_i2s_mux_register(struct regmap *regmap, const char *name, 140b2e39dc0SAlexandre Belloni const char * const *parent_names, 141b2e39dc0SAlexandre Belloni unsigned int num_parents, u8 bus_id); 142b2e39dc0SAlexandre Belloni 143b2e39dc0SAlexandre Belloni struct clk_hw * __init 144b2e39dc0SAlexandre Belloni at91_clk_register_main_rc_osc(struct regmap *regmap, const char *name, 145b2e39dc0SAlexandre Belloni u32 frequency, u32 accuracy); 146b2e39dc0SAlexandre Belloni struct clk_hw * __init 147b2e39dc0SAlexandre Belloni at91_clk_register_main_osc(struct regmap *regmap, const char *name, 148b2e39dc0SAlexandre Belloni const char *parent_name, bool bypass); 149b2e39dc0SAlexandre Belloni struct clk_hw * __init 150b2e39dc0SAlexandre Belloni at91_clk_register_rm9200_main(struct regmap *regmap, 151b2e39dc0SAlexandre Belloni const char *name, 152b2e39dc0SAlexandre Belloni const char *parent_name); 153b2e39dc0SAlexandre Belloni struct clk_hw * __init 154b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_main(struct regmap *regmap, const char *name, 155b2e39dc0SAlexandre Belloni const char **parent_names, int num_parents); 156b2e39dc0SAlexandre Belloni 157b2e39dc0SAlexandre Belloni struct clk_hw * __init 158b2e39dc0SAlexandre Belloni at91_clk_register_master(struct regmap *regmap, const char *name, 159b2e39dc0SAlexandre Belloni int num_parents, const char **parent_names, 160b2e39dc0SAlexandre Belloni const struct clk_master_layout *layout, 161b2e39dc0SAlexandre Belloni const struct clk_master_characteristics *characteristics); 162b2e39dc0SAlexandre Belloni 163b2e39dc0SAlexandre Belloni struct clk_hw * __init 16475c88143SClaudiu Beznea at91_clk_sama7g5_register_master(struct regmap *regmap, 16575c88143SClaudiu Beznea const char *name, int num_parents, 16675c88143SClaudiu Beznea const char **parent_names, u32 *mux_table, 16775c88143SClaudiu Beznea spinlock_t *lock, u8 id, bool critical, 16875c88143SClaudiu Beznea int chg_pid); 16975c88143SClaudiu Beznea 17075c88143SClaudiu Beznea struct clk_hw * __init 171b2e39dc0SAlexandre Belloni at91_clk_register_peripheral(struct regmap *regmap, const char *name, 172b2e39dc0SAlexandre Belloni const char *parent_name, u32 id); 173b2e39dc0SAlexandre Belloni struct clk_hw * __init 174b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock, 175cb4f4949SAlexandre Belloni const struct clk_pcr_layout *layout, 176b2e39dc0SAlexandre Belloni const char *name, const char *parent_name, 177b4c115c7SClaudiu Beznea u32 id, const struct clk_range *range, 178b4c115c7SClaudiu Beznea int chg_pid); 179b2e39dc0SAlexandre Belloni 180b2e39dc0SAlexandre Belloni struct clk_hw * __init 181b2e39dc0SAlexandre Belloni at91_clk_register_pll(struct regmap *regmap, const char *name, 182b2e39dc0SAlexandre Belloni const char *parent_name, u8 id, 183b2e39dc0SAlexandre Belloni const struct clk_pll_layout *layout, 184b2e39dc0SAlexandre Belloni const struct clk_pll_characteristics *characteristics); 185b2e39dc0SAlexandre Belloni struct clk_hw * __init 186b2e39dc0SAlexandre Belloni at91_clk_register_plldiv(struct regmap *regmap, const char *name, 187b2e39dc0SAlexandre Belloni const char *parent_name); 188b2e39dc0SAlexandre Belloni 189b2e39dc0SAlexandre Belloni struct clk_hw * __init 190*43b1bb4aSClaudiu Beznea sam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock, 191a436c2a4SAlexandre Belloni const char *name, const char *parent_name, u8 id, 192*43b1bb4aSClaudiu Beznea const struct clk_pll_characteristics *characteristics, 193*43b1bb4aSClaudiu Beznea const struct clk_pll_layout *layout, bool critical); 194*43b1bb4aSClaudiu Beznea 195*43b1bb4aSClaudiu Beznea struct clk_hw * __init 196*43b1bb4aSClaudiu Beznea sam9x60_clk_register_frac_pll(struct regmap *regmap, spinlock_t *lock, 197*43b1bb4aSClaudiu Beznea const char *name, const char *parent_name, 198*43b1bb4aSClaudiu Beznea struct clk_hw *parent_hw, u8 id, 199*43b1bb4aSClaudiu Beznea const struct clk_pll_characteristics *characteristics, 200*43b1bb4aSClaudiu Beznea const struct clk_pll_layout *layout, bool critical); 201a436c2a4SAlexandre Belloni 202a436c2a4SAlexandre Belloni struct clk_hw * __init 203b2e39dc0SAlexandre Belloni at91_clk_register_programmable(struct regmap *regmap, const char *name, 204b2e39dc0SAlexandre Belloni const char **parent_names, u8 num_parents, u8 id, 205c57aaaa2SClaudiu Beznea const struct clk_programmable_layout *layout, 206c57aaaa2SClaudiu Beznea u32 *mux_table); 207b2e39dc0SAlexandre Belloni 208b2e39dc0SAlexandre Belloni struct clk_hw * __init 209b2e39dc0SAlexandre Belloni at91_clk_register_sam9260_slow(struct regmap *regmap, 210b2e39dc0SAlexandre Belloni const char *name, 211b2e39dc0SAlexandre Belloni const char **parent_names, 212b2e39dc0SAlexandre Belloni int num_parents); 213b2e39dc0SAlexandre Belloni 214b2e39dc0SAlexandre Belloni struct clk_hw * __init 215b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name, 216b2e39dc0SAlexandre Belloni const char **parent_names, u8 num_parents); 217b2e39dc0SAlexandre Belloni 218b2e39dc0SAlexandre Belloni struct clk_hw * __init 219b2e39dc0SAlexandre Belloni at91_clk_register_system(struct regmap *regmap, const char *name, 220b2e39dc0SAlexandre Belloni const char *parent_name, u8 id); 221b2e39dc0SAlexandre Belloni 222b2e39dc0SAlexandre Belloni struct clk_hw * __init 223b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, 224b2e39dc0SAlexandre Belloni const char **parent_names, u8 num_parents); 225b2e39dc0SAlexandre Belloni struct clk_hw * __init 226b2e39dc0SAlexandre Belloni at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name, 227b2e39dc0SAlexandre Belloni const char *parent_name); 228b2e39dc0SAlexandre Belloni struct clk_hw * __init 2292423eeaeSAlexandre Belloni sam9x60_clk_register_usb(struct regmap *regmap, const char *name, 2302423eeaeSAlexandre Belloni const char **parent_names, u8 num_parents); 2312423eeaeSAlexandre Belloni struct clk_hw * __init 232b2e39dc0SAlexandre Belloni at91rm9200_clk_register_usb(struct regmap *regmap, const char *name, 233b2e39dc0SAlexandre Belloni const char *parent_name, const u32 *divisors); 234b2e39dc0SAlexandre Belloni 235b2e39dc0SAlexandre Belloni struct clk_hw * __init 236b2e39dc0SAlexandre Belloni at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr, 237b2e39dc0SAlexandre Belloni const char *name, const char *parent_name); 238b2e39dc0SAlexandre Belloni 239b3b02eacSAlexandre Belloni #ifdef CONFIG_PM 240b3b02eacSAlexandre Belloni void pmc_register_id(u8 id); 24113967beaSRomain Izard void pmc_register_pck(u8 pck); 242b3b02eacSAlexandre Belloni #else 243b3b02eacSAlexandre Belloni static inline void pmc_register_id(u8 id) {} 24413967beaSRomain Izard static inline void pmc_register_pck(u8 pck) {} 245b3b02eacSAlexandre Belloni #endif 246b3b02eacSAlexandre Belloni 2470ad6125bSBoris BREZILLON #endif /* __PMC_H_ */ 248