18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * drivers/clk/at91/pmc.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __PMC_H_ 98c2ecf20Sopenharmony_ci#define __PMC_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci#include <linux/irqdomain.h> 138c2ecf20Sopenharmony_ci#include <linux/regmap.h> 148c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciextern spinlock_t pmc_pcr_lock; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct pmc_data { 198c2ecf20Sopenharmony_ci unsigned int ncore; 208c2ecf20Sopenharmony_ci struct clk_hw **chws; 218c2ecf20Sopenharmony_ci unsigned int nsystem; 228c2ecf20Sopenharmony_ci struct clk_hw **shws; 238c2ecf20Sopenharmony_ci unsigned int nperiph; 248c2ecf20Sopenharmony_ci struct clk_hw **phws; 258c2ecf20Sopenharmony_ci unsigned int ngck; 268c2ecf20Sopenharmony_ci struct clk_hw **ghws; 278c2ecf20Sopenharmony_ci unsigned int npck; 288c2ecf20Sopenharmony_ci struct clk_hw **pchws; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci struct clk_hw *hwtable[]; 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct clk_range { 348c2ecf20Sopenharmony_ci unsigned long min; 358c2ecf20Sopenharmony_ci unsigned long max; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define CLK_RANGE(MIN, MAX) {.min = MIN, .max = MAX,} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct clk_master_layout { 418c2ecf20Sopenharmony_ci u32 offset; 428c2ecf20Sopenharmony_ci u32 mask; 438c2ecf20Sopenharmony_ci u8 pres_shift; 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciextern const struct clk_master_layout at91rm9200_master_layout; 478c2ecf20Sopenharmony_ciextern const struct clk_master_layout at91sam9x5_master_layout; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct clk_master_characteristics { 508c2ecf20Sopenharmony_ci struct clk_range output; 518c2ecf20Sopenharmony_ci u32 divisors[4]; 528c2ecf20Sopenharmony_ci u8 have_div3_pres; 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistruct clk_pll_layout { 568c2ecf20Sopenharmony_ci u32 pllr_mask; 578c2ecf20Sopenharmony_ci u32 mul_mask; 588c2ecf20Sopenharmony_ci u32 frac_mask; 598c2ecf20Sopenharmony_ci u32 div_mask; 608c2ecf20Sopenharmony_ci u32 endiv_mask; 618c2ecf20Sopenharmony_ci u8 mul_shift; 628c2ecf20Sopenharmony_ci u8 frac_shift; 638c2ecf20Sopenharmony_ci u8 div_shift; 648c2ecf20Sopenharmony_ci u8 endiv_shift; 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ciextern const struct clk_pll_layout at91rm9200_pll_layout; 688c2ecf20Sopenharmony_ciextern const struct clk_pll_layout at91sam9g45_pll_layout; 698c2ecf20Sopenharmony_ciextern const struct clk_pll_layout at91sam9g20_pllb_layout; 708c2ecf20Sopenharmony_ciextern const struct clk_pll_layout sama5d3_pll_layout; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistruct clk_pll_characteristics { 738c2ecf20Sopenharmony_ci struct clk_range input; 748c2ecf20Sopenharmony_ci int num_output; 758c2ecf20Sopenharmony_ci const struct clk_range *output; 768c2ecf20Sopenharmony_ci u16 *icpll; 778c2ecf20Sopenharmony_ci u8 *out; 788c2ecf20Sopenharmony_ci u8 upll : 1; 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistruct clk_programmable_layout { 828c2ecf20Sopenharmony_ci u8 pres_mask; 838c2ecf20Sopenharmony_ci u8 pres_shift; 848c2ecf20Sopenharmony_ci u8 css_mask; 858c2ecf20Sopenharmony_ci u8 have_slck_mck; 868c2ecf20Sopenharmony_ci u8 is_pres_direct; 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciextern const struct clk_programmable_layout at91rm9200_programmable_layout; 908c2ecf20Sopenharmony_ciextern const struct clk_programmable_layout at91sam9g45_programmable_layout; 918c2ecf20Sopenharmony_ciextern const struct clk_programmable_layout at91sam9x5_programmable_layout; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct clk_pcr_layout { 948c2ecf20Sopenharmony_ci u32 offset; 958c2ecf20Sopenharmony_ci u32 cmd; 968c2ecf20Sopenharmony_ci u32 div_mask; 978c2ecf20Sopenharmony_ci u32 gckcss_mask; 988c2ecf20Sopenharmony_ci u32 pid_mask; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) 1028c2ecf20Sopenharmony_ci#define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define ndck(a, s) (a[s - 1].id + 1) 1058c2ecf20Sopenharmony_ci#define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1) 1068c2ecf20Sopenharmony_cistruct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem, 1078c2ecf20Sopenharmony_ci unsigned int nperiph, unsigned int ngck, 1088c2ecf20Sopenharmony_ci unsigned int npck); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciint of_at91_get_clk_range(struct device_node *np, const char *propname, 1118c2ecf20Sopenharmony_ci struct clk_range *range); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistruct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct clk_hw * __init 1168c2ecf20Sopenharmony_ciat91_clk_register_audio_pll_frac(struct regmap *regmap, const char *name, 1178c2ecf20Sopenharmony_ci const char *parent_name); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistruct clk_hw * __init 1208c2ecf20Sopenharmony_ciat91_clk_register_audio_pll_pad(struct regmap *regmap, const char *name, 1218c2ecf20Sopenharmony_ci const char *parent_name); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct clk_hw * __init 1248c2ecf20Sopenharmony_ciat91_clk_register_audio_pll_pmc(struct regmap *regmap, const char *name, 1258c2ecf20Sopenharmony_ci const char *parent_name); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistruct clk_hw * __init 1288c2ecf20Sopenharmony_ciat91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, 1298c2ecf20Sopenharmony_ci const struct clk_pcr_layout *layout, 1308c2ecf20Sopenharmony_ci const char *name, const char **parent_names, 1318c2ecf20Sopenharmony_ci u32 *mux_table, u8 num_parents, u8 id, 1328c2ecf20Sopenharmony_ci const struct clk_range *range, int chg_pid); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistruct clk_hw * __init 1358c2ecf20Sopenharmony_ciat91_clk_register_h32mx(struct regmap *regmap, const char *name, 1368c2ecf20Sopenharmony_ci const char *parent_name); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistruct clk_hw * __init 1398c2ecf20Sopenharmony_ciat91_clk_i2s_mux_register(struct regmap *regmap, const char *name, 1408c2ecf20Sopenharmony_ci const char * const *parent_names, 1418c2ecf20Sopenharmony_ci unsigned int num_parents, u8 bus_id); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistruct clk_hw * __init 1448c2ecf20Sopenharmony_ciat91_clk_register_main_rc_osc(struct regmap *regmap, const char *name, 1458c2ecf20Sopenharmony_ci u32 frequency, u32 accuracy); 1468c2ecf20Sopenharmony_cistruct clk_hw * __init 1478c2ecf20Sopenharmony_ciat91_clk_register_main_osc(struct regmap *regmap, const char *name, 1488c2ecf20Sopenharmony_ci const char *parent_name, bool bypass); 1498c2ecf20Sopenharmony_cistruct clk_hw * __init 1508c2ecf20Sopenharmony_ciat91_clk_register_rm9200_main(struct regmap *regmap, 1518c2ecf20Sopenharmony_ci const char *name, 1528c2ecf20Sopenharmony_ci const char *parent_name); 1538c2ecf20Sopenharmony_cistruct clk_hw * __init 1548c2ecf20Sopenharmony_ciat91_clk_register_sam9x5_main(struct regmap *regmap, const char *name, 1558c2ecf20Sopenharmony_ci const char **parent_names, int num_parents); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistruct clk_hw * __init 1588c2ecf20Sopenharmony_ciat91_clk_register_master(struct regmap *regmap, const char *name, 1598c2ecf20Sopenharmony_ci int num_parents, const char **parent_names, 1608c2ecf20Sopenharmony_ci const struct clk_master_layout *layout, 1618c2ecf20Sopenharmony_ci const struct clk_master_characteristics *characteristics); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistruct clk_hw * __init 1648c2ecf20Sopenharmony_ciat91_clk_sama7g5_register_master(struct regmap *regmap, 1658c2ecf20Sopenharmony_ci const char *name, int num_parents, 1668c2ecf20Sopenharmony_ci const char **parent_names, u32 *mux_table, 1678c2ecf20Sopenharmony_ci spinlock_t *lock, u8 id, bool critical, 1688c2ecf20Sopenharmony_ci int chg_pid); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistruct clk_hw * __init 1718c2ecf20Sopenharmony_ciat91_clk_register_peripheral(struct regmap *regmap, const char *name, 1728c2ecf20Sopenharmony_ci const char *parent_name, u32 id); 1738c2ecf20Sopenharmony_cistruct clk_hw * __init 1748c2ecf20Sopenharmony_ciat91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock, 1758c2ecf20Sopenharmony_ci const struct clk_pcr_layout *layout, 1768c2ecf20Sopenharmony_ci const char *name, const char *parent_name, 1778c2ecf20Sopenharmony_ci u32 id, const struct clk_range *range, 1788c2ecf20Sopenharmony_ci int chg_pid); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cistruct clk_hw * __init 1818c2ecf20Sopenharmony_ciat91_clk_register_pll(struct regmap *regmap, const char *name, 1828c2ecf20Sopenharmony_ci const char *parent_name, u8 id, 1838c2ecf20Sopenharmony_ci const struct clk_pll_layout *layout, 1848c2ecf20Sopenharmony_ci const struct clk_pll_characteristics *characteristics); 1858c2ecf20Sopenharmony_cistruct clk_hw * __init 1868c2ecf20Sopenharmony_ciat91_clk_register_plldiv(struct regmap *regmap, const char *name, 1878c2ecf20Sopenharmony_ci const char *parent_name); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cistruct clk_hw * __init 1908c2ecf20Sopenharmony_cisam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock, 1918c2ecf20Sopenharmony_ci const char *name, const char *parent_name, u8 id, 1928c2ecf20Sopenharmony_ci const struct clk_pll_characteristics *characteristics, 1938c2ecf20Sopenharmony_ci const struct clk_pll_layout *layout, bool critical); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistruct clk_hw * __init 1968c2ecf20Sopenharmony_cisam9x60_clk_register_frac_pll(struct regmap *regmap, spinlock_t *lock, 1978c2ecf20Sopenharmony_ci const char *name, const char *parent_name, 1988c2ecf20Sopenharmony_ci struct clk_hw *parent_hw, u8 id, 1998c2ecf20Sopenharmony_ci const struct clk_pll_characteristics *characteristics, 2008c2ecf20Sopenharmony_ci const struct clk_pll_layout *layout, bool critical); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistruct clk_hw * __init 2038c2ecf20Sopenharmony_ciat91_clk_register_programmable(struct regmap *regmap, const char *name, 2048c2ecf20Sopenharmony_ci const char **parent_names, u8 num_parents, u8 id, 2058c2ecf20Sopenharmony_ci const struct clk_programmable_layout *layout, 2068c2ecf20Sopenharmony_ci u32 *mux_table); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistruct clk_hw * __init 2098c2ecf20Sopenharmony_ciat91_clk_register_sam9260_slow(struct regmap *regmap, 2108c2ecf20Sopenharmony_ci const char *name, 2118c2ecf20Sopenharmony_ci const char **parent_names, 2128c2ecf20Sopenharmony_ci int num_parents); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistruct clk_hw * __init 2158c2ecf20Sopenharmony_ciat91sam9x5_clk_register_smd(struct regmap *regmap, const char *name, 2168c2ecf20Sopenharmony_ci const char **parent_names, u8 num_parents); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistruct clk_hw * __init 2198c2ecf20Sopenharmony_ciat91_clk_register_system(struct regmap *regmap, const char *name, 2208c2ecf20Sopenharmony_ci const char *parent_name, u8 id); 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistruct clk_hw * __init 2238c2ecf20Sopenharmony_ciat91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, 2248c2ecf20Sopenharmony_ci const char **parent_names, u8 num_parents); 2258c2ecf20Sopenharmony_cistruct clk_hw * __init 2268c2ecf20Sopenharmony_ciat91sam9n12_clk_register_usb(struct regmap *regmap, const char *name, 2278c2ecf20Sopenharmony_ci const char *parent_name); 2288c2ecf20Sopenharmony_cistruct clk_hw * __init 2298c2ecf20Sopenharmony_cisam9x60_clk_register_usb(struct regmap *regmap, const char *name, 2308c2ecf20Sopenharmony_ci const char **parent_names, u8 num_parents); 2318c2ecf20Sopenharmony_cistruct clk_hw * __init 2328c2ecf20Sopenharmony_ciat91rm9200_clk_register_usb(struct regmap *regmap, const char *name, 2338c2ecf20Sopenharmony_ci const char *parent_name, const u32 *divisors); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cistruct clk_hw * __init 2368c2ecf20Sopenharmony_ciat91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr, 2378c2ecf20Sopenharmony_ci const char *name, const char *parent_name); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistruct clk_hw * __init 2408c2ecf20Sopenharmony_ciat91_clk_sama7g5_register_utmi(struct regmap *regmap, const char *name, 2418c2ecf20Sopenharmony_ci const char *parent_name); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 2448c2ecf20Sopenharmony_civoid pmc_register_id(u8 id); 2458c2ecf20Sopenharmony_civoid pmc_register_pck(u8 pck); 2468c2ecf20Sopenharmony_ci#else 2478c2ecf20Sopenharmony_cistatic inline void pmc_register_id(u8 id) {} 2488c2ecf20Sopenharmony_cistatic inline void pmc_register_pck(u8 pck) {} 2498c2ecf20Sopenharmony_ci#endif 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci#endif /* __PMC_H_ */ 252