Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: at91: utmi: set the mainck rate

By default, it is assumed that the UTMI clock is generated from a 12 MHz
reference clock (MAINCK). If it's not the case, the FREQ field of the
SFR_UTMICKTRIM has to be updated to generate the UTMI clock in the
proper way.

The UTMI clock has a fixed rate of 480 MHz. In fact, there is no
multiplier we can configure. The multiplier is managed internally,
depending on the reference clock frequency, to achieve the target of
480 MHz.

Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Acked-by: Ingo van Lil <inguin@gmx.de>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Ludovic Desroches and committed by
Stephen Boyd
92041a9f 2bd6bf03

+83 -14
+81 -14
drivers/clk/at91/clk-utmi.c
··· 14 14 #include <linux/of.h> 15 15 #include <linux/mfd/syscon.h> 16 16 #include <linux/regmap.h> 17 + #include <soc/at91/atmel-sfr.h> 17 18 18 19 #include "pmc.h" 19 20 20 - #define UTMI_FIXED_MUL 40 21 + /* 22 + * The purpose of this clock is to generate a 480 MHz signal. A different 23 + * rate can't be configured. 24 + */ 25 + #define UTMI_RATE 480000000 21 26 22 27 struct clk_utmi { 23 28 struct clk_hw hw; 24 - struct regmap *regmap; 29 + struct regmap *regmap_pmc; 30 + struct regmap *regmap_sfr; 25 31 }; 26 32 27 33 #define to_clk_utmi(hw) container_of(hw, struct clk_utmi, hw) ··· 43 37 44 38 static int clk_utmi_prepare(struct clk_hw *hw) 45 39 { 40 + struct clk_hw *hw_parent; 46 41 struct clk_utmi *utmi = to_clk_utmi(hw); 47 42 unsigned int uckr = AT91_PMC_UPLLEN | AT91_PMC_UPLLCOUNT | 48 43 AT91_PMC_BIASEN; 44 + unsigned int utmi_ref_clk_freq; 45 + unsigned long parent_rate; 49 46 50 - regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, uckr, uckr); 47 + /* 48 + * If mainck rate is different from 12 MHz, we have to configure the 49 + * FREQ field of the SFR_UTMICKTRIM register to generate properly 50 + * the utmi clock. 51 + */ 52 + hw_parent = clk_hw_get_parent(hw); 53 + parent_rate = clk_hw_get_rate(hw_parent); 51 54 52 - while (!clk_utmi_ready(utmi->regmap)) 55 + switch (parent_rate) { 56 + case 12000000: 57 + utmi_ref_clk_freq = 0; 58 + break; 59 + case 16000000: 60 + utmi_ref_clk_freq = 1; 61 + break; 62 + case 24000000: 63 + utmi_ref_clk_freq = 2; 64 + break; 65 + /* 66 + * Not supported on SAMA5D2 but it's not an issue since MAINCK 67 + * maximum value is 24 MHz. 68 + */ 69 + case 48000000: 70 + utmi_ref_clk_freq = 3; 71 + break; 72 + default: 73 + pr_err("UTMICK: unsupported mainck rate\n"); 74 + return -EINVAL; 75 + } 76 + 77 + if (utmi->regmap_sfr) { 78 + regmap_update_bits(utmi->regmap_sfr, AT91_SFR_UTMICKTRIM, 79 + AT91_UTMICKTRIM_FREQ, utmi_ref_clk_freq); 80 + } else if (utmi_ref_clk_freq) { 81 + pr_err("UTMICK: sfr node required\n"); 82 + return -EINVAL; 83 + } 84 + 85 + regmap_update_bits(utmi->regmap_pmc, AT91_CKGR_UCKR, uckr, uckr); 86 + 87 + while (!clk_utmi_ready(utmi->regmap_pmc)) 53 88 cpu_relax(); 54 89 55 90 return 0; ··· 100 53 { 101 54 struct clk_utmi *utmi = to_clk_utmi(hw); 102 55 103 - return clk_utmi_ready(utmi->regmap); 56 + return clk_utmi_ready(utmi->regmap_pmc); 104 57 } 105 58 106 59 static void clk_utmi_unprepare(struct clk_hw *hw) 107 60 { 108 61 struct clk_utmi *utmi = to_clk_utmi(hw); 109 62 110 - regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, AT91_PMC_UPLLEN, 0); 63 + regmap_update_bits(utmi->regmap_pmc, AT91_CKGR_UCKR, 64 + AT91_PMC_UPLLEN, 0); 111 65 } 112 66 113 67 static unsigned long clk_utmi_recalc_rate(struct clk_hw *hw, 114 68 unsigned long parent_rate) 115 69 { 116 - /* UTMI clk is a fixed clk multiplier */ 117 - return parent_rate * UTMI_FIXED_MUL; 70 + /* UTMI clk rate is fixed. */ 71 + return UTMI_RATE; 118 72 } 119 73 120 74 static const struct clk_ops utmi_ops = { ··· 126 78 }; 127 79 128 80 static struct clk_hw * __init 129 - at91_clk_register_utmi(struct regmap *regmap, 81 + at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr, 130 82 const char *name, const char *parent_name) 131 83 { 132 84 struct clk_utmi *utmi; ··· 145 97 init.flags = CLK_SET_RATE_GATE; 146 98 147 99 utmi->hw.init = &init; 148 - utmi->regmap = regmap; 100 + utmi->regmap_pmc = regmap_pmc; 101 + utmi->regmap_sfr = regmap_sfr; 149 102 150 103 hw = &utmi->hw; 151 104 ret = clk_hw_register(NULL, &utmi->hw); ··· 163 114 struct clk_hw *hw; 164 115 const char *parent_name; 165 116 const char *name = np->name; 166 - struct regmap *regmap; 117 + struct regmap *regmap_pmc, *regmap_sfr; 167 118 168 119 parent_name = of_clk_get_parent_name(np, 0); 169 120 170 121 of_property_read_string(np, "clock-output-names", &name); 171 122 172 - regmap = syscon_node_to_regmap(of_get_parent(np)); 173 - if (IS_ERR(regmap)) 123 + regmap_pmc = syscon_node_to_regmap(of_get_parent(np)); 124 + if (IS_ERR(regmap_pmc)) 174 125 return; 175 126 176 - hw = at91_clk_register_utmi(regmap, name, parent_name); 127 + /* 128 + * If the device supports different mainck rates, this value has to be 129 + * set in the UTMI Clock Trimming register. 130 + * - 9x5: mainck supports several rates but it is indicated that a 131 + * 12 MHz is needed in case of USB. 132 + * - sama5d3 and sama5d2: mainck supports several rates. Configuring 133 + * the FREQ field of the UTMI Clock Trimming register is mandatory. 134 + * - sama5d4: mainck is at 12 MHz. 135 + * 136 + * We only need to retrieve sama5d3 or sama5d2 sfr regmap. 137 + */ 138 + regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d3-sfr"); 139 + if (IS_ERR(regmap_sfr)) { 140 + regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr"); 141 + if (IS_ERR(regmap_sfr)) 142 + regmap_sfr = NULL; 143 + } 144 + 145 + hw = at91_clk_register_utmi(regmap_pmc, regmap_sfr, name, parent_name); 177 146 if (IS_ERR(hw)) 178 147 return; 179 148
+2
include/soc/at91/atmel-sfr.h
··· 17 17 /* 0x08 ~ 0x0c: Reserved */ 18 18 #define AT91_SFR_OHCIICR 0x10 /* OHCI INT Configuration Register */ 19 19 #define AT91_SFR_OHCIISR 0x14 /* OHCI INT Status Register */ 20 + #define AT91_SFR_UTMICKTRIM 0x30 /* UTMI Clock Trimming Register */ 20 21 #define AT91_SFR_I2SCLKSEL 0x90 /* I2SC Register */ 21 22 22 23 /* Field definitions */ ··· 29 28 AT91_OHCIICR_SUSPEND_B | \ 30 29 AT91_OHCIICR_SUSPEND_C) 31 30 31 + #define AT91_UTMICKTRIM_FREQ GENMASK(1, 0) 32 32 33 33 #endif /* _LINUX_MFD_SYSCON_ATMEL_SFR_H */