Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Atmel Corporation |
| 4 | * Wenyou.Yang <wenyou.yang@atmel.com> |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __AT91_PMC_H__ |
| 8 | #define __AT91_PMC_H__ |
| 9 | |
Claudiu Beznea | 8fdb425 | 2020-09-07 17:46:38 +0300 | [diff] [blame] | 10 | #include <linux/bitops.h> |
| 11 | #include <linux/io.h> |
| 12 | |
| 13 | /* Keep a range of 256 available clocks for every clock type. */ |
| 14 | #define AT91_TO_CLK_ID(_t, _i) (((_t) << 8) | ((_i) & 0xff)) |
| 15 | #define AT91_CLK_ID_TO_DID(_i) ((_i) & 0xff) |
Wenyou Yang | 6b66b92 | 2017-09-05 18:30:07 +0800 | [diff] [blame] | 16 | |
Claudiu Beznea | 923ac87 | 2020-09-07 17:46:42 +0300 | [diff] [blame] | 17 | struct clk_range { |
| 18 | unsigned long min; |
| 19 | unsigned long max; |
| 20 | }; |
| 21 | |
Claudiu Beznea | 1f9023a | 2020-09-07 17:46:43 +0300 | [diff] [blame] | 22 | struct clk_master_layout { |
| 23 | u32 offset; |
| 24 | u32 mask; |
| 25 | u8 pres_shift; |
| 26 | }; |
| 27 | |
| 28 | extern const struct clk_master_layout at91rm9200_master_layout; |
| 29 | extern const struct clk_master_layout at91sam9x5_master_layout; |
| 30 | |
| 31 | struct clk_master_characteristics { |
| 32 | struct clk_range output; |
| 33 | u32 divisors[4]; |
| 34 | u8 have_div3_pres; |
| 35 | }; |
| 36 | |
Claudiu Beznea | 923ac87 | 2020-09-07 17:46:42 +0300 | [diff] [blame] | 37 | struct clk_pll_characteristics { |
| 38 | struct clk_range input; |
| 39 | int num_output; |
| 40 | const struct clk_range *output; |
| 41 | u16 *icpll; |
| 42 | u8 *out; |
| 43 | u8 upll : 1; |
| 44 | }; |
| 45 | |
| 46 | struct clk_pll_layout { |
| 47 | u32 pllr_mask; |
| 48 | u32 mul_mask; |
| 49 | u32 frac_mask; |
| 50 | u32 div_mask; |
| 51 | u32 endiv_mask; |
| 52 | u8 mul_shift; |
| 53 | u8 frac_shift; |
| 54 | u8 div_shift; |
| 55 | u8 endiv_shift; |
| 56 | }; |
| 57 | |
Claudiu Beznea | 5d40887 | 2020-09-07 17:46:41 +0300 | [diff] [blame] | 58 | struct clk *at91_clk_main_rc(void __iomem *reg, const char *name, |
| 59 | const char *parent_name); |
| 60 | struct clk *at91_clk_main_osc(void __iomem *reg, const char *name, |
| 61 | const char *parent_name, bool bypass); |
| 62 | struct clk *at91_clk_rm9200_main(void __iomem *reg, const char *name, |
| 63 | const char *parent_name); |
| 64 | struct clk *at91_clk_sam9x5_main(void __iomem *reg, const char *name, |
| 65 | const char * const *parent_names, int num_parents, |
| 66 | const u32 *mux_table, int type); |
Claudiu Beznea | 923ac87 | 2020-09-07 17:46:42 +0300 | [diff] [blame] | 67 | struct clk * |
| 68 | sam9x60_clk_register_div_pll(void __iomem *base, const char *name, |
| 69 | const char *parent_name, u8 id, |
| 70 | const struct clk_pll_characteristics *characteristics, |
| 71 | const struct clk_pll_layout *layout, bool critical); |
| 72 | struct clk * |
| 73 | sam9x60_clk_register_frac_pll(void __iomem *base, const char *name, |
| 74 | const char *parent_name, u8 id, |
| 75 | const struct clk_pll_characteristics *characteristics, |
| 76 | const struct clk_pll_layout *layout, bool critical); |
Claudiu Beznea | 1f9023a | 2020-09-07 17:46:43 +0300 | [diff] [blame] | 77 | struct clk * |
| 78 | at91_clk_register_master(void __iomem *base, const char *name, |
| 79 | const char * const *parent_names, int num_parents, |
| 80 | const struct clk_master_layout *layout, |
| 81 | const struct clk_master_characteristics *characteristics, |
| 82 | const u32 *mux_table); |
Claudiu Beznea | e812b02 | 2020-09-07 17:46:44 +0300 | [diff] [blame] | 83 | struct clk * |
| 84 | at91_clk_sama7g5_register_master(void __iomem *base, const char *name, |
| 85 | const char * const *parent_names, int num_parents, |
| 86 | const u32 *mux_table, const u32 *clk_mux_table, |
| 87 | bool critical, u8 id); |
Claudiu Beznea | 96179bd | 2020-09-07 17:46:45 +0300 | [diff] [blame^] | 88 | struct clk * |
| 89 | at91_clk_register_utmi(void __iomem *base, struct udevice *dev, |
| 90 | const char *name, const char *parent_name); |
Claudiu Beznea | 5d40887 | 2020-09-07 17:46:41 +0300 | [diff] [blame] | 91 | |
Claudiu Beznea | 8fdb425 | 2020-09-07 17:46:38 +0300 | [diff] [blame] | 92 | int at91_clk_mux_val_to_index(const u32 *table, u32 num_parents, u32 val); |
| 93 | int at91_clk_mux_index_to_val(const u32 *table, u32 num_parents, u32 index); |
| 94 | |
| 95 | void pmc_read(void __iomem *base, unsigned int off, unsigned int *val); |
| 96 | void pmc_write(void __iomem *base, unsigned int off, unsigned int val); |
| 97 | void pmc_update_bits(void __iomem *base, unsigned int off, unsigned int mask, |
| 98 | unsigned int bits); |
Claudiu Beznea | 3f203a1 | 2020-09-07 17:46:39 +0300 | [diff] [blame] | 99 | |
Wenyou Yang | 8c772bd | 2016-07-20 17:55:12 +0800 | [diff] [blame] | 100 | #endif |