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

clk: at91: make use of syscon/regmap internally

Use the regmap coming from syscon to access the registers instead of using
pmc_read/pmc_write. This allows to avoid passing the at91_pmc structure to
the child nodes of the PMC.

The final benefit is to have each clock register itself instead of having
to iterate over the children.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Boris Brezillon and committed by
Alexandre Belloni
1bdf0232 863a81c3

+693 -693
+53 -38
drivers/clk/at91/clk-generated.c
··· 17 17 #include <linux/of.h> 18 18 #include <linux/of_address.h> 19 19 #include <linux/io.h> 20 + #include <linux/mfd/syscon.h> 21 + #include <linux/regmap.h> 20 22 21 23 #include "pmc.h" 22 24 ··· 30 28 31 29 struct clk_generated { 32 30 struct clk_hw hw; 33 - struct at91_pmc *pmc; 31 + struct regmap *regmap; 34 32 struct clk_range range; 33 + spinlock_t *lock; 35 34 u32 id; 36 35 u32 gckdiv; 37 36 u8 parent_id; ··· 44 41 static int clk_generated_enable(struct clk_hw *hw) 45 42 { 46 43 struct clk_generated *gck = to_clk_generated(hw); 47 - struct at91_pmc *pmc = gck->pmc; 48 - u32 tmp; 44 + unsigned long flags; 49 45 50 46 pr_debug("GCLK: %s, gckdiv = %d, parent id = %d\n", 51 47 __func__, gck->gckdiv, gck->parent_id); 52 48 53 - pmc_lock(pmc); 54 - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); 55 - tmp = pmc_read(pmc, AT91_PMC_PCR) & 56 - ~(AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK); 57 - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_GCKCSS(gck->parent_id) 58 - | AT91_PMC_PCR_CMD 59 - | AT91_PMC_PCR_GCKDIV(gck->gckdiv) 60 - | AT91_PMC_PCR_GCKEN); 61 - pmc_unlock(pmc); 49 + spin_lock_irqsave(gck->lock, flags); 50 + regmap_write(gck->regmap, AT91_PMC_PCR, 51 + (gck->id & AT91_PMC_PCR_PID_MASK)); 52 + regmap_update_bits(gck->regmap, AT91_PMC_PCR, 53 + AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK | 54 + AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN, 55 + AT91_PMC_PCR_GCKCSS(gck->parent_id) | 56 + AT91_PMC_PCR_CMD | 57 + AT91_PMC_PCR_GCKDIV(gck->gckdiv) | 58 + AT91_PMC_PCR_GCKEN); 59 + spin_unlock_irqrestore(gck->lock, flags); 62 60 return 0; 63 61 } 64 62 65 63 static void clk_generated_disable(struct clk_hw *hw) 66 64 { 67 65 struct clk_generated *gck = to_clk_generated(hw); 68 - struct at91_pmc *pmc = gck->pmc; 69 - u32 tmp; 66 + unsigned long flags; 70 67 71 - pmc_lock(pmc); 72 - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); 73 - tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_GCKEN; 74 - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD); 75 - pmc_unlock(pmc); 68 + spin_lock_irqsave(gck->lock, flags); 69 + regmap_write(gck->regmap, AT91_PMC_PCR, 70 + (gck->id & AT91_PMC_PCR_PID_MASK)); 71 + regmap_update_bits(gck->regmap, AT91_PMC_PCR, 72 + AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN, 73 + AT91_PMC_PCR_CMD); 74 + spin_unlock_irqrestore(gck->lock, flags); 76 75 } 77 76 78 77 static int clk_generated_is_enabled(struct clk_hw *hw) 79 78 { 80 79 struct clk_generated *gck = to_clk_generated(hw); 81 - struct at91_pmc *pmc = gck->pmc; 82 - int ret; 80 + unsigned long flags; 81 + unsigned int status; 83 82 84 - pmc_lock(pmc); 85 - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); 86 - ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_GCKEN); 87 - pmc_unlock(pmc); 83 + spin_lock_irqsave(gck->lock, flags); 84 + regmap_write(gck->regmap, AT91_PMC_PCR, 85 + (gck->id & AT91_PMC_PCR_PID_MASK)); 86 + regmap_read(gck->regmap, AT91_PMC_PCR, &status); 87 + spin_unlock_irqrestore(gck->lock, flags); 88 88 89 - return ret; 89 + return status & AT91_PMC_PCR_GCKEN ? 1 : 0; 90 90 } 91 91 92 92 static unsigned long ··· 220 214 */ 221 215 static void clk_generated_startup(struct clk_generated *gck) 222 216 { 223 - struct at91_pmc *pmc = gck->pmc; 224 217 u32 tmp; 218 + unsigned long flags; 225 219 226 - pmc_lock(pmc); 227 - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); 228 - tmp = pmc_read(pmc, AT91_PMC_PCR); 229 - pmc_unlock(pmc); 220 + spin_lock_irqsave(gck->lock, flags); 221 + regmap_write(gck->regmap, AT91_PMC_PCR, 222 + (gck->id & AT91_PMC_PCR_PID_MASK)); 223 + regmap_read(gck->regmap, AT91_PMC_PCR, &tmp); 224 + spin_unlock_irqrestore(gck->lock, flags); 230 225 231 226 gck->parent_id = (tmp & AT91_PMC_PCR_GCKCSS_MASK) 232 227 >> AT91_PMC_PCR_GCKCSS_OFFSET; ··· 236 229 } 237 230 238 231 static struct clk * __init 239 - at91_clk_register_generated(struct at91_pmc *pmc, const char *name, 240 - const char **parent_names, u8 num_parents, 232 + at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char 233 + *name, const char **parent_names, u8 num_parents, 241 234 u8 id, const struct clk_range *range) 242 235 { 243 236 struct clk_generated *gck; ··· 256 249 257 250 gck->id = id; 258 251 gck->hw.init = &init; 259 - gck->pmc = pmc; 252 + gck->regmap = regmap; 253 + gck->lock = lock; 260 254 gck->range = *range; 261 255 262 256 clk = clk_register(NULL, &gck->hw); ··· 269 261 return clk; 270 262 } 271 263 272 - void __init of_sama5d2_clk_generated_setup(struct device_node *np, 273 - struct at91_pmc *pmc) 264 + void __init of_sama5d2_clk_generated_setup(struct device_node *np) 274 265 { 275 266 int num; 276 267 u32 id; ··· 279 272 const char *parent_names[GENERATED_SOURCE_MAX]; 280 273 struct device_node *gcknp; 281 274 struct clk_range range = CLK_RANGE(0, 0); 275 + struct regmap *regmap; 282 276 283 277 num_parents = of_clk_get_parent_count(np); 284 278 if (num_parents <= 0 || num_parents > GENERATED_SOURCE_MAX) ··· 289 281 290 282 num = of_get_child_count(np); 291 283 if (!num || num > PERIPHERAL_MAX) 284 + return; 285 + 286 + regmap = syscon_node_to_regmap(of_get_parent(np)); 287 + if (IS_ERR(regmap)) 292 288 return; 293 289 294 290 for_each_child_of_node(np, gcknp) { ··· 308 296 of_at91_get_clk_range(gcknp, "atmel,clk-output-range", 309 297 &range); 310 298 311 - clk = at91_clk_register_generated(pmc, name, parent_names, 312 - num_parents, id, &range); 299 + clk = at91_clk_register_generated(regmap, &pmc_pcr_lock, name, 300 + parent_names, num_parents, 301 + id, &range); 313 302 if (IS_ERR(clk)) 314 303 continue; 315 304 316 305 of_clk_add_provider(gcknp, of_clk_src_simple_get, clk); 317 306 } 318 307 } 308 + CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated", 309 + of_sama5d2_clk_generated_setup);
+20 -12
drivers/clk/at91/clk-h32mx.c
··· 24 24 #include <linux/irq.h> 25 25 #include <linux/sched.h> 26 26 #include <linux/wait.h> 27 + #include <linux/regmap.h> 28 + #include <linux/mfd/syscon.h> 27 29 28 30 #include "pmc.h" 29 31 ··· 33 31 34 32 struct clk_sama5d4_h32mx { 35 33 struct clk_hw hw; 36 - struct at91_pmc *pmc; 34 + struct regmap *regmap; 37 35 }; 38 36 39 37 #define to_clk_sama5d4_h32mx(hw) container_of(hw, struct clk_sama5d4_h32mx, hw) ··· 42 40 unsigned long parent_rate) 43 41 { 44 42 struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw); 43 + unsigned int mckr; 45 44 46 - if (pmc_read(h32mxclk->pmc, AT91_PMC_MCKR) & AT91_PMC_H32MXDIV) 45 + regmap_read(h32mxclk->regmap, AT91_PMC_MCKR, &mckr); 46 + if (mckr & AT91_PMC_H32MXDIV) 47 47 return parent_rate / 2; 48 48 49 49 if (parent_rate > H32MX_MAX_FREQ) ··· 74 70 unsigned long parent_rate) 75 71 { 76 72 struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw); 77 - struct at91_pmc *pmc = h32mxclk->pmc; 78 - u32 tmp; 73 + u32 mckr = 0; 79 74 80 75 if (parent_rate != rate && (parent_rate / 2) != rate) 81 76 return -EINVAL; 82 77 83 - pmc_lock(pmc); 84 - tmp = pmc_read(pmc, AT91_PMC_MCKR) & ~AT91_PMC_H32MXDIV; 85 78 if ((parent_rate / 2) == rate) 86 - tmp |= AT91_PMC_H32MXDIV; 87 - pmc_write(pmc, AT91_PMC_MCKR, tmp); 88 - pmc_unlock(pmc); 79 + mckr = AT91_PMC_H32MXDIV; 80 + 81 + regmap_update_bits(h32mxclk->regmap, AT91_PMC_MCKR, 82 + AT91_PMC_H32MXDIV, mckr); 89 83 90 84 return 0; 91 85 } ··· 94 92 .set_rate = clk_sama5d4_h32mx_set_rate, 95 93 }; 96 94 97 - void __init of_sama5d4_clk_h32mx_setup(struct device_node *np, 98 - struct at91_pmc *pmc) 95 + static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np) 99 96 { 100 97 struct clk_sama5d4_h32mx *h32mxclk; 101 98 struct clk_init_data init; 102 99 const char *parent_name; 100 + struct regmap *regmap; 103 101 struct clk *clk; 102 + 103 + regmap = syscon_node_to_regmap(of_get_parent(np)); 104 + if (IS_ERR(regmap)) 105 + return; 104 106 105 107 h32mxclk = kzalloc(sizeof(*h32mxclk), GFP_KERNEL); 106 108 if (!h32mxclk) ··· 119 113 init.flags = CLK_SET_RATE_GATE; 120 114 121 115 h32mxclk->hw.init = &init; 122 - h32mxclk->pmc = pmc; 116 + h32mxclk->regmap = regmap; 123 117 124 118 clk = clk_register(NULL, &h32mxclk->hw); 125 119 if (!clk) { ··· 129 123 130 124 of_clk_add_provider(np, of_clk_src_simple_get, clk); 131 125 } 126 + CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx", 127 + of_sama5d4_clk_h32mx_setup);
+159 -89
drivers/clk/at91/clk-main.c
··· 18 18 #include <linux/io.h> 19 19 #include <linux/interrupt.h> 20 20 #include <linux/irq.h> 21 + #include <linux/mfd/syscon.h> 22 + #include <linux/regmap.h> 21 23 #include <linux/sched.h> 22 24 #include <linux/wait.h> 23 25 ··· 36 34 37 35 struct clk_main_osc { 38 36 struct clk_hw hw; 39 - struct at91_pmc *pmc; 37 + struct regmap *regmap; 40 38 unsigned int irq; 41 39 wait_queue_head_t wait; 42 40 }; ··· 45 43 46 44 struct clk_main_rc_osc { 47 45 struct clk_hw hw; 48 - struct at91_pmc *pmc; 46 + struct regmap *regmap; 49 47 unsigned int irq; 50 48 wait_queue_head_t wait; 51 49 unsigned long frequency; ··· 56 54 57 55 struct clk_rm9200_main { 58 56 struct clk_hw hw; 59 - struct at91_pmc *pmc; 57 + struct regmap *regmap; 60 58 }; 61 59 62 60 #define to_clk_rm9200_main(hw) container_of(hw, struct clk_rm9200_main, hw) 63 61 64 62 struct clk_sam9x5_main { 65 63 struct clk_hw hw; 66 - struct at91_pmc *pmc; 64 + struct regmap *regmap; 67 65 unsigned int irq; 68 66 wait_queue_head_t wait; 69 67 u8 parent; ··· 81 79 return IRQ_HANDLED; 82 80 } 83 81 82 + static inline bool clk_main_osc_ready(struct regmap *regmap) 83 + { 84 + unsigned int status; 85 + 86 + regmap_read(regmap, AT91_PMC_SR, &status); 87 + 88 + return status & AT91_PMC_MOSCS; 89 + } 90 + 84 91 static int clk_main_osc_prepare(struct clk_hw *hw) 85 92 { 86 93 struct clk_main_osc *osc = to_clk_main_osc(hw); 87 - struct at91_pmc *pmc = osc->pmc; 94 + struct regmap *regmap = osc->regmap; 88 95 u32 tmp; 89 96 90 - tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK; 97 + regmap_read(regmap, AT91_CKGR_MOR, &tmp); 98 + tmp &= ~MOR_KEY_MASK; 99 + 91 100 if (tmp & AT91_PMC_OSCBYPASS) 92 101 return 0; 93 102 94 103 if (!(tmp & AT91_PMC_MOSCEN)) { 95 104 tmp |= AT91_PMC_MOSCEN | AT91_PMC_KEY; 96 - pmc_write(pmc, AT91_CKGR_MOR, tmp); 105 + regmap_write(regmap, AT91_CKGR_MOR, tmp); 97 106 } 98 107 99 - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS)) { 108 + while (!clk_main_osc_ready(regmap)) { 100 109 enable_irq(osc->irq); 101 110 wait_event(osc->wait, 102 - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS); 111 + clk_main_osc_ready(regmap)); 103 112 } 104 113 105 114 return 0; ··· 119 106 static void clk_main_osc_unprepare(struct clk_hw *hw) 120 107 { 121 108 struct clk_main_osc *osc = to_clk_main_osc(hw); 122 - struct at91_pmc *pmc = osc->pmc; 123 - u32 tmp = pmc_read(pmc, AT91_CKGR_MOR); 109 + struct regmap *regmap = osc->regmap; 110 + u32 tmp; 124 111 112 + regmap_read(regmap, AT91_CKGR_MOR, &tmp); 125 113 if (tmp & AT91_PMC_OSCBYPASS) 126 114 return; 127 115 ··· 130 116 return; 131 117 132 118 tmp &= ~(AT91_PMC_KEY | AT91_PMC_MOSCEN); 133 - pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY); 119 + regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_KEY); 134 120 } 135 121 136 122 static int clk_main_osc_is_prepared(struct clk_hw *hw) 137 123 { 138 124 struct clk_main_osc *osc = to_clk_main_osc(hw); 139 - struct at91_pmc *pmc = osc->pmc; 140 - u32 tmp = pmc_read(pmc, AT91_CKGR_MOR); 125 + struct regmap *regmap = osc->regmap; 126 + u32 tmp, status; 141 127 128 + regmap_read(regmap, AT91_CKGR_MOR, &tmp); 142 129 if (tmp & AT91_PMC_OSCBYPASS) 143 130 return 1; 144 131 145 - return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS) && 146 - (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN)); 132 + regmap_read(regmap, AT91_PMC_SR, &status); 133 + 134 + return (status & AT91_PMC_MOSCS) && (tmp & AT91_PMC_MOSCEN); 147 135 } 148 136 149 137 static const struct clk_ops main_osc_ops = { ··· 155 139 }; 156 140 157 141 static struct clk * __init 158 - at91_clk_register_main_osc(struct at91_pmc *pmc, 142 + at91_clk_register_main_osc(struct regmap *regmap, 159 143 unsigned int irq, 160 144 const char *name, 161 145 const char *parent_name, ··· 166 150 struct clk *clk = NULL; 167 151 struct clk_init_data init; 168 152 169 - if (!pmc || !irq || !name || !parent_name) 153 + if (!irq || !name || !parent_name) 170 154 return ERR_PTR(-EINVAL); 171 155 172 156 osc = kzalloc(sizeof(*osc), GFP_KERNEL); ··· 180 164 init.flags = CLK_IGNORE_UNUSED; 181 165 182 166 osc->hw.init = &init; 183 - osc->pmc = pmc; 167 + osc->regmap = regmap; 184 168 osc->irq = irq; 185 169 186 170 init_waitqueue_head(&osc->wait); ··· 193 177 } 194 178 195 179 if (bypass) 196 - pmc_write(pmc, AT91_CKGR_MOR, 197 - (pmc_read(pmc, AT91_CKGR_MOR) & 198 - ~(MOR_KEY_MASK | AT91_PMC_MOSCEN)) | 199 - AT91_PMC_OSCBYPASS | AT91_PMC_KEY); 180 + regmap_update_bits(regmap, 181 + AT91_CKGR_MOR, MOR_KEY_MASK | 182 + AT91_PMC_MOSCEN, 183 + AT91_PMC_OSCBYPASS | AT91_PMC_KEY); 200 184 201 185 clk = clk_register(NULL, &osc->hw); 202 186 if (IS_ERR(clk)) { ··· 207 191 return clk; 208 192 } 209 193 210 - void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np, 211 - struct at91_pmc *pmc) 194 + static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np) 212 195 { 213 196 struct clk *clk; 214 197 unsigned int irq; 215 198 const char *name = np->name; 216 199 const char *parent_name; 200 + struct regmap *regmap; 217 201 bool bypass; 218 202 219 203 of_property_read_string(np, "clock-output-names", &name); 220 204 bypass = of_property_read_bool(np, "atmel,osc-bypass"); 221 205 parent_name = of_clk_get_parent_name(np, 0); 222 206 207 + regmap = syscon_node_to_regmap(of_get_parent(np)); 208 + if (IS_ERR(regmap)) 209 + return; 210 + 223 211 irq = irq_of_parse_and_map(np, 0); 224 212 if (!irq) 225 213 return; 226 214 227 - clk = at91_clk_register_main_osc(pmc, irq, name, parent_name, bypass); 215 + clk = at91_clk_register_main_osc(regmap, irq, name, parent_name, bypass); 228 216 if (IS_ERR(clk)) 229 217 return; 230 218 231 219 of_clk_add_provider(np, of_clk_src_simple_get, clk); 232 220 } 221 + CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc", 222 + of_at91rm9200_clk_main_osc_setup); 233 223 234 224 static irqreturn_t clk_main_rc_osc_irq_handler(int irq, void *dev_id) 235 225 { ··· 247 225 return IRQ_HANDLED; 248 226 } 249 227 228 + static bool clk_main_rc_osc_ready(struct regmap *regmap) 229 + { 230 + unsigned int status; 231 + 232 + regmap_read(regmap, AT91_PMC_SR, &status); 233 + 234 + return status & AT91_PMC_MOSCRCS; 235 + } 236 + 250 237 static int clk_main_rc_osc_prepare(struct clk_hw *hw) 251 238 { 252 239 struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw); 253 - struct at91_pmc *pmc = osc->pmc; 254 - u32 tmp; 240 + struct regmap *regmap = osc->regmap; 241 + unsigned int mor; 255 242 256 - tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK; 243 + regmap_read(regmap, AT91_CKGR_MOR, &mor); 257 244 258 - if (!(tmp & AT91_PMC_MOSCRCEN)) { 259 - tmp |= AT91_PMC_MOSCRCEN | AT91_PMC_KEY; 260 - pmc_write(pmc, AT91_CKGR_MOR, tmp); 261 - } 245 + if (!(mor & AT91_PMC_MOSCRCEN)) 246 + regmap_update_bits(regmap, AT91_CKGR_MOR, 247 + MOR_KEY_MASK | AT91_PMC_MOSCRCEN, 248 + AT91_PMC_MOSCRCEN | AT91_PMC_KEY); 262 249 263 - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS)) { 250 + while (!clk_main_rc_osc_ready(regmap)) { 264 251 enable_irq(osc->irq); 265 252 wait_event(osc->wait, 266 - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS); 253 + clk_main_rc_osc_ready(regmap)); 267 254 } 268 255 269 256 return 0; ··· 281 250 static void clk_main_rc_osc_unprepare(struct clk_hw *hw) 282 251 { 283 252 struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw); 284 - struct at91_pmc *pmc = osc->pmc; 285 - u32 tmp = pmc_read(pmc, AT91_CKGR_MOR); 253 + struct regmap *regmap = osc->regmap; 254 + unsigned int mor; 286 255 287 - if (!(tmp & AT91_PMC_MOSCRCEN)) 256 + regmap_read(regmap, AT91_CKGR_MOR, &mor); 257 + 258 + if (!(mor & AT91_PMC_MOSCRCEN)) 288 259 return; 289 260 290 - tmp &= ~(MOR_KEY_MASK | AT91_PMC_MOSCRCEN); 291 - pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY); 261 + regmap_update_bits(regmap, AT91_CKGR_MOR, 262 + MOR_KEY_MASK | AT91_PMC_MOSCRCEN, AT91_PMC_KEY); 292 263 } 293 264 294 265 static int clk_main_rc_osc_is_prepared(struct clk_hw *hw) 295 266 { 296 267 struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw); 297 - struct at91_pmc *pmc = osc->pmc; 268 + struct regmap *regmap = osc->regmap; 269 + unsigned int mor, status; 298 270 299 - return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS) && 300 - (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCRCEN)); 271 + regmap_read(regmap, AT91_CKGR_MOR, &mor); 272 + regmap_read(regmap, AT91_PMC_SR, &status); 273 + 274 + return (mor & AT91_PMC_MOSCRCEN) && (status & AT91_PMC_MOSCRCS); 301 275 } 302 276 303 277 static unsigned long clk_main_rc_osc_recalc_rate(struct clk_hw *hw, ··· 330 294 }; 331 295 332 296 static struct clk * __init 333 - at91_clk_register_main_rc_osc(struct at91_pmc *pmc, 297 + at91_clk_register_main_rc_osc(struct regmap *regmap, 334 298 unsigned int irq, 335 299 const char *name, 336 300 u32 frequency, u32 accuracy) ··· 340 304 struct clk *clk = NULL; 341 305 struct clk_init_data init; 342 306 343 - if (!pmc || !irq || !name || !frequency) 307 + if (!name || !frequency) 344 308 return ERR_PTR(-EINVAL); 345 309 346 310 osc = kzalloc(sizeof(*osc), GFP_KERNEL); ··· 354 318 init.flags = CLK_IS_ROOT | CLK_IGNORE_UNUSED; 355 319 356 320 osc->hw.init = &init; 357 - osc->pmc = pmc; 321 + osc->regmap = regmap; 358 322 osc->irq = irq; 359 323 osc->frequency = frequency; 360 324 osc->accuracy = accuracy; ··· 375 339 return clk; 376 340 } 377 341 378 - void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np, 379 - struct at91_pmc *pmc) 342 + static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np) 380 343 { 381 344 struct clk *clk; 382 345 unsigned int irq; 383 346 u32 frequency = 0; 384 347 u32 accuracy = 0; 385 348 const char *name = np->name; 349 + struct regmap *regmap; 386 350 387 351 of_property_read_string(np, "clock-output-names", &name); 388 352 of_property_read_u32(np, "clock-frequency", &frequency); ··· 392 356 if (!irq) 393 357 return; 394 358 395 - clk = at91_clk_register_main_rc_osc(pmc, irq, name, frequency, 359 + regmap = syscon_node_to_regmap(of_get_parent(np)); 360 + if (IS_ERR(regmap)) 361 + return; 362 + 363 + clk = at91_clk_register_main_rc_osc(regmap, irq, name, frequency, 396 364 accuracy); 397 365 if (IS_ERR(clk)) 398 366 return; 399 367 400 368 of_clk_add_provider(np, of_clk_src_simple_get, clk); 401 369 } 370 + CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc", 371 + of_at91sam9x5_clk_main_rc_osc_setup); 402 372 403 373 404 - static int clk_main_probe_frequency(struct at91_pmc *pmc) 374 + static int clk_main_probe_frequency(struct regmap *regmap) 405 375 { 406 376 unsigned long prep_time, timeout; 407 - u32 tmp; 377 + unsigned int mcfr; 408 378 409 379 timeout = jiffies + usecs_to_jiffies(MAINFRDY_TIMEOUT); 410 380 do { 411 381 prep_time = jiffies; 412 - tmp = pmc_read(pmc, AT91_CKGR_MCFR); 413 - if (tmp & AT91_PMC_MAINRDY) 382 + regmap_read(regmap, AT91_CKGR_MCFR, &mcfr); 383 + if (mcfr & AT91_PMC_MAINRDY) 414 384 return 0; 415 385 usleep_range(MAINF_LOOP_MIN_WAIT, MAINF_LOOP_MAX_WAIT); 416 386 } while (time_before(prep_time, timeout)); ··· 424 382 return -ETIMEDOUT; 425 383 } 426 384 427 - static unsigned long clk_main_recalc_rate(struct at91_pmc *pmc, 385 + static unsigned long clk_main_recalc_rate(struct regmap *regmap, 428 386 unsigned long parent_rate) 429 387 { 430 - u32 tmp; 388 + unsigned int mcfr; 431 389 432 390 if (parent_rate) 433 391 return parent_rate; 434 392 435 393 pr_warn("Main crystal frequency not set, using approximate value\n"); 436 - tmp = pmc_read(pmc, AT91_CKGR_MCFR); 437 - if (!(tmp & AT91_PMC_MAINRDY)) 394 + regmap_read(regmap, AT91_CKGR_MCFR, &mcfr); 395 + if (!(mcfr & AT91_PMC_MAINRDY)) 438 396 return 0; 439 397 440 - return ((tmp & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV; 398 + return ((mcfr & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV; 441 399 } 442 400 443 401 static int clk_rm9200_main_prepare(struct clk_hw *hw) 444 402 { 445 403 struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw); 446 404 447 - return clk_main_probe_frequency(clkmain->pmc); 405 + return clk_main_probe_frequency(clkmain->regmap); 448 406 } 449 407 450 408 static int clk_rm9200_main_is_prepared(struct clk_hw *hw) 451 409 { 452 410 struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw); 411 + unsigned int status; 453 412 454 - return !!(pmc_read(clkmain->pmc, AT91_CKGR_MCFR) & AT91_PMC_MAINRDY); 413 + regmap_read(clkmain->regmap, AT91_CKGR_MCFR, &status); 414 + 415 + return status & AT91_PMC_MAINRDY ? 1 : 0; 455 416 } 456 417 457 418 static unsigned long clk_rm9200_main_recalc_rate(struct clk_hw *hw, ··· 462 417 { 463 418 struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw); 464 419 465 - return clk_main_recalc_rate(clkmain->pmc, parent_rate); 420 + return clk_main_recalc_rate(clkmain->regmap, parent_rate); 466 421 } 467 422 468 423 static const struct clk_ops rm9200_main_ops = { ··· 472 427 }; 473 428 474 429 static struct clk * __init 475 - at91_clk_register_rm9200_main(struct at91_pmc *pmc, 430 + at91_clk_register_rm9200_main(struct regmap *regmap, 476 431 const char *name, 477 432 const char *parent_name) 478 433 { ··· 480 435 struct clk *clk = NULL; 481 436 struct clk_init_data init; 482 437 483 - if (!pmc || !name) 438 + if (!name) 484 439 return ERR_PTR(-EINVAL); 485 440 486 441 if (!parent_name) ··· 497 452 init.flags = 0; 498 453 499 454 clkmain->hw.init = &init; 500 - clkmain->pmc = pmc; 455 + clkmain->regmap = regmap; 501 456 502 457 clk = clk_register(NULL, &clkmain->hw); 503 458 if (IS_ERR(clk)) ··· 506 461 return clk; 507 462 } 508 463 509 - void __init of_at91rm9200_clk_main_setup(struct device_node *np, 510 - struct at91_pmc *pmc) 464 + static void __init of_at91rm9200_clk_main_setup(struct device_node *np) 511 465 { 512 466 struct clk *clk; 513 467 const char *parent_name; 514 468 const char *name = np->name; 469 + struct regmap *regmap; 515 470 516 471 parent_name = of_clk_get_parent_name(np, 0); 517 472 of_property_read_string(np, "clock-output-names", &name); 518 473 519 - clk = at91_clk_register_rm9200_main(pmc, name, parent_name); 474 + regmap = syscon_node_to_regmap(of_get_parent(np)); 475 + if (IS_ERR(regmap)) 476 + return; 477 + 478 + clk = at91_clk_register_rm9200_main(regmap, name, parent_name); 520 479 if (IS_ERR(clk)) 521 480 return; 522 481 523 482 of_clk_add_provider(np, of_clk_src_simple_get, clk); 524 483 } 484 + CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main", 485 + of_at91rm9200_clk_main_setup); 525 486 526 487 static irqreturn_t clk_sam9x5_main_irq_handler(int irq, void *dev_id) 527 488 { ··· 539 488 return IRQ_HANDLED; 540 489 } 541 490 491 + static inline bool clk_sam9x5_main_ready(struct regmap *regmap) 492 + { 493 + unsigned int status; 494 + 495 + regmap_read(regmap, AT91_PMC_SR, &status); 496 + 497 + return status & AT91_PMC_MOSCSELS ? 1 : 0; 498 + } 499 + 542 500 static int clk_sam9x5_main_prepare(struct clk_hw *hw) 543 501 { 544 502 struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw); 545 - struct at91_pmc *pmc = clkmain->pmc; 503 + struct regmap *regmap = clkmain->regmap; 546 504 547 - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) { 505 + while (!clk_sam9x5_main_ready(regmap)) { 548 506 enable_irq(clkmain->irq); 549 507 wait_event(clkmain->wait, 550 - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS); 508 + clk_sam9x5_main_ready(regmap)); 551 509 } 552 510 553 - return clk_main_probe_frequency(pmc); 511 + return clk_main_probe_frequency(regmap); 554 512 } 555 513 556 514 static int clk_sam9x5_main_is_prepared(struct clk_hw *hw) 557 515 { 558 516 struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw); 559 517 560 - return !!(pmc_read(clkmain->pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS); 518 + return clk_sam9x5_main_ready(clkmain->regmap); 561 519 } 562 520 563 521 static unsigned long clk_sam9x5_main_recalc_rate(struct clk_hw *hw, ··· 574 514 { 575 515 struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw); 576 516 577 - return clk_main_recalc_rate(clkmain->pmc, parent_rate); 517 + return clk_main_recalc_rate(clkmain->regmap, parent_rate); 578 518 } 579 519 580 520 static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index) 581 521 { 582 522 struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw); 583 - struct at91_pmc *pmc = clkmain->pmc; 584 - u32 tmp; 523 + struct regmap *regmap = clkmain->regmap; 524 + unsigned int tmp; 585 525 586 526 if (index > 1) 587 527 return -EINVAL; 588 528 589 - tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK; 529 + regmap_read(regmap, AT91_CKGR_MOR, &tmp); 530 + tmp &= ~MOR_KEY_MASK; 590 531 591 532 if (index && !(tmp & AT91_PMC_MOSCSEL)) 592 - pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL); 533 + regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL); 593 534 else if (!index && (tmp & AT91_PMC_MOSCSEL)) 594 - pmc_write(pmc, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL); 535 + regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL); 595 536 596 - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) { 537 + while (!clk_sam9x5_main_ready(regmap)) { 597 538 enable_irq(clkmain->irq); 598 539 wait_event(clkmain->wait, 599 - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS); 540 + clk_sam9x5_main_ready(regmap)); 600 541 } 601 542 602 543 return 0; ··· 606 545 static u8 clk_sam9x5_main_get_parent(struct clk_hw *hw) 607 546 { 608 547 struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw); 548 + unsigned int status; 609 549 610 - return !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN); 550 + regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status); 551 + 552 + return status & AT91_PMC_MOSCEN ? 1 : 0; 611 553 } 612 554 613 555 static const struct clk_ops sam9x5_main_ops = { ··· 622 558 }; 623 559 624 560 static struct clk * __init 625 - at91_clk_register_sam9x5_main(struct at91_pmc *pmc, 561 + at91_clk_register_sam9x5_main(struct regmap *regmap, 626 562 unsigned int irq, 627 563 const char *name, 628 564 const char **parent_names, ··· 632 568 struct clk_sam9x5_main *clkmain; 633 569 struct clk *clk = NULL; 634 570 struct clk_init_data init; 571 + unsigned int status; 635 572 636 - if (!pmc || !irq || !name) 573 + if (!name) 637 574 return ERR_PTR(-EINVAL); 638 575 639 576 if (!parent_names || !num_parents) ··· 651 586 init.flags = CLK_SET_PARENT_GATE; 652 587 653 588 clkmain->hw.init = &init; 654 - clkmain->pmc = pmc; 589 + clkmain->regmap = regmap; 655 590 clkmain->irq = irq; 656 - clkmain->parent = !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) & 657 - AT91_PMC_MOSCEN); 591 + regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status); 592 + clkmain->parent = status & AT91_PMC_MOSCEN ? 1 : 0; 658 593 init_waitqueue_head(&clkmain->wait); 659 594 irq_set_status_flags(clkmain->irq, IRQ_NOAUTOEN); 660 595 ret = request_irq(clkmain->irq, clk_sam9x5_main_irq_handler, ··· 671 606 return clk; 672 607 } 673 608 674 - void __init of_at91sam9x5_clk_main_setup(struct device_node *np, 675 - struct at91_pmc *pmc) 609 + static void __init of_at91sam9x5_clk_main_setup(struct device_node *np) 676 610 { 677 611 struct clk *clk; 678 612 const char *parent_names[2]; 679 613 int num_parents; 680 614 unsigned int irq; 681 615 const char *name = np->name; 616 + struct regmap *regmap; 682 617 683 618 num_parents = of_clk_get_parent_count(np); 684 619 if (num_parents <= 0 || num_parents > 2) 685 620 return; 686 621 687 622 of_clk_parent_fill(np, parent_names, num_parents); 623 + regmap = syscon_node_to_regmap(of_get_parent(np)); 624 + if (IS_ERR(regmap)) 625 + return; 688 626 689 627 of_property_read_string(np, "clock-output-names", &name); 690 628 ··· 695 627 if (!irq) 696 628 return; 697 629 698 - clk = at91_clk_register_sam9x5_main(pmc, irq, name, parent_names, 630 + clk = at91_clk_register_sam9x5_main(regmap, irq, name, parent_names, 699 631 num_parents); 700 632 if (IS_ERR(clk)) 701 633 return; 702 634 703 635 of_clk_add_provider(np, of_clk_src_simple_get, clk); 704 636 } 637 + CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main", 638 + of_at91sam9x5_clk_main_setup);
+43 -25
drivers/clk/at91/clk-master.c
··· 19 19 #include <linux/sched.h> 20 20 #include <linux/interrupt.h> 21 21 #include <linux/irq.h> 22 + #include <linux/mfd/syscon.h> 23 + #include <linux/regmap.h> 22 24 23 25 #include "pmc.h" 24 26 ··· 46 44 47 45 struct clk_master { 48 46 struct clk_hw hw; 49 - struct at91_pmc *pmc; 47 + struct regmap *regmap; 50 48 unsigned int irq; 51 49 wait_queue_head_t wait; 52 50 const struct clk_master_layout *layout; ··· 62 60 63 61 return IRQ_HANDLED; 64 62 } 63 + 64 + static inline bool clk_master_ready(struct regmap *regmap) 65 + { 66 + unsigned int status; 67 + 68 + regmap_read(regmap, AT91_PMC_SR, &status); 69 + 70 + return status & AT91_PMC_MCKRDY ? 1 : 0; 71 + } 72 + 65 73 static int clk_master_prepare(struct clk_hw *hw) 66 74 { 67 75 struct clk_master *master = to_clk_master(hw); 68 - struct at91_pmc *pmc = master->pmc; 69 76 70 - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY)) { 77 + while (!clk_master_ready(master->regmap)) { 71 78 enable_irq(master->irq); 72 79 wait_event(master->wait, 73 - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY); 80 + clk_master_ready(master->regmap)); 74 81 } 75 82 76 83 return 0; ··· 89 78 { 90 79 struct clk_master *master = to_clk_master(hw); 91 80 92 - return !!(pmc_read(master->pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY); 81 + return clk_master_ready(master->regmap); 93 82 } 94 83 95 84 static unsigned long clk_master_recalc_rate(struct clk_hw *hw, ··· 99 88 u8 div; 100 89 unsigned long rate = parent_rate; 101 90 struct clk_master *master = to_clk_master(hw); 102 - struct at91_pmc *pmc = master->pmc; 103 91 const struct clk_master_layout *layout = master->layout; 104 92 const struct clk_master_characteristics *characteristics = 105 93 master->characteristics; 106 - u32 tmp; 94 + unsigned int mckr; 107 95 108 - pmc_lock(pmc); 109 - tmp = pmc_read(pmc, AT91_PMC_MCKR) & layout->mask; 110 - pmc_unlock(pmc); 96 + regmap_read(master->regmap, AT91_PMC_MCKR, &mckr); 97 + mckr &= layout->mask; 111 98 112 - pres = (tmp >> layout->pres_shift) & MASTER_PRES_MASK; 113 - div = (tmp >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK; 99 + pres = (mckr >> layout->pres_shift) & MASTER_PRES_MASK; 100 + div = (mckr >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK; 114 101 115 102 if (characteristics->have_div3_pres && pres == MASTER_PRES_MAX) 116 103 rate /= 3; ··· 128 119 static u8 clk_master_get_parent(struct clk_hw *hw) 129 120 { 130 121 struct clk_master *master = to_clk_master(hw); 131 - struct at91_pmc *pmc = master->pmc; 122 + unsigned int mckr; 132 123 133 - return pmc_read(pmc, AT91_PMC_MCKR) & AT91_PMC_CSS; 124 + regmap_read(master->regmap, AT91_PMC_MCKR, &mckr); 125 + 126 + return mckr & AT91_PMC_CSS; 134 127 } 135 128 136 129 static const struct clk_ops master_ops = { ··· 143 132 }; 144 133 145 134 static struct clk * __init 146 - at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq, 135 + at91_clk_register_master(struct regmap *regmap, unsigned int irq, 147 136 const char *name, int num_parents, 148 137 const char **parent_names, 149 138 const struct clk_master_layout *layout, ··· 154 143 struct clk *clk = NULL; 155 144 struct clk_init_data init; 156 145 157 - if (!pmc || !irq || !name || !num_parents || !parent_names) 146 + if (!name || !num_parents || !parent_names) 158 147 return ERR_PTR(-EINVAL); 159 148 160 149 master = kzalloc(sizeof(*master), GFP_KERNEL); ··· 170 159 master->hw.init = &init; 171 160 master->layout = layout; 172 161 master->characteristics = characteristics; 173 - master->pmc = pmc; 162 + master->regmap = regmap; 174 163 master->irq = irq; 175 164 init_waitqueue_head(&master->wait); 176 165 irq_set_status_flags(master->irq, IRQ_NOAUTOEN); ··· 228 217 } 229 218 230 219 static void __init 231 - of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc, 220 + of_at91_clk_master_setup(struct device_node *np, 232 221 const struct clk_master_layout *layout) 233 222 { 234 223 struct clk *clk; ··· 237 226 const char *parent_names[MASTER_SOURCE_MAX]; 238 227 const char *name = np->name; 239 228 struct clk_master_characteristics *characteristics; 229 + struct regmap *regmap; 240 230 241 231 num_parents = of_clk_get_parent_count(np); 242 232 if (num_parents <= 0 || num_parents > MASTER_SOURCE_MAX) ··· 251 239 if (!characteristics) 252 240 return; 253 241 242 + regmap = syscon_node_to_regmap(of_get_parent(np)); 243 + if (IS_ERR(regmap)) 244 + return; 245 + 254 246 irq = irq_of_parse_and_map(np, 0); 255 247 if (!irq) 256 248 goto out_free_characteristics; 257 249 258 - clk = at91_clk_register_master(pmc, irq, name, num_parents, 250 + clk = at91_clk_register_master(regmap, irq, name, num_parents, 259 251 parent_names, layout, 260 252 characteristics); 261 253 if (IS_ERR(clk)) ··· 272 256 kfree(characteristics); 273 257 } 274 258 275 - void __init of_at91rm9200_clk_master_setup(struct device_node *np, 276 - struct at91_pmc *pmc) 259 + static void __init of_at91rm9200_clk_master_setup(struct device_node *np) 277 260 { 278 - of_at91_clk_master_setup(np, pmc, &at91rm9200_master_layout); 261 + of_at91_clk_master_setup(np, &at91rm9200_master_layout); 279 262 } 263 + CLK_OF_DECLARE(at91rm9200_clk_master, "atmel,at91rm9200-clk-master", 264 + of_at91rm9200_clk_master_setup); 280 265 281 - void __init of_at91sam9x5_clk_master_setup(struct device_node *np, 282 - struct at91_pmc *pmc) 266 + static void __init of_at91sam9x5_clk_master_setup(struct device_node *np) 283 267 { 284 - of_at91_clk_master_setup(np, pmc, &at91sam9x5_master_layout); 268 + of_at91_clk_master_setup(np, &at91sam9x5_master_layout); 285 269 } 270 + CLK_OF_DECLARE(at91sam9x5_clk_master, "atmel,at91sam9x5-clk-master", 271 + of_at91sam9x5_clk_master_setup);
+79 -56
drivers/clk/at91/clk-peripheral.c
··· 14 14 #include <linux/of.h> 15 15 #include <linux/of_address.h> 16 16 #include <linux/io.h> 17 + #include <linux/mfd/syscon.h> 18 + #include <linux/regmap.h> 17 19 18 20 #include "pmc.h" 21 + 22 + DEFINE_SPINLOCK(pmc_pcr_lock); 19 23 20 24 #define PERIPHERAL_MAX 64 21 25 ··· 37 33 38 34 struct clk_peripheral { 39 35 struct clk_hw hw; 40 - struct at91_pmc *pmc; 36 + struct regmap *regmap; 41 37 u32 id; 42 38 }; 43 39 ··· 45 41 46 42 struct clk_sam9x5_peripheral { 47 43 struct clk_hw hw; 48 - struct at91_pmc *pmc; 44 + struct regmap *regmap; 49 45 struct clk_range range; 46 + spinlock_t *lock; 50 47 u32 id; 51 48 u32 div; 52 49 bool auto_div; ··· 59 54 static int clk_peripheral_enable(struct clk_hw *hw) 60 55 { 61 56 struct clk_peripheral *periph = to_clk_peripheral(hw); 62 - struct at91_pmc *pmc = periph->pmc; 63 57 int offset = AT91_PMC_PCER; 64 58 u32 id = periph->id; 65 59 ··· 66 62 return 0; 67 63 if (id > PERIPHERAL_ID_MAX) 68 64 offset = AT91_PMC_PCER1; 69 - pmc_write(pmc, offset, PERIPHERAL_MASK(id)); 65 + regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id)); 66 + 70 67 return 0; 71 68 } 72 69 73 70 static void clk_peripheral_disable(struct clk_hw *hw) 74 71 { 75 72 struct clk_peripheral *periph = to_clk_peripheral(hw); 76 - struct at91_pmc *pmc = periph->pmc; 77 73 int offset = AT91_PMC_PCDR; 78 74 u32 id = periph->id; 79 75 ··· 81 77 return; 82 78 if (id > PERIPHERAL_ID_MAX) 83 79 offset = AT91_PMC_PCDR1; 84 - pmc_write(pmc, offset, PERIPHERAL_MASK(id)); 80 + regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id)); 85 81 } 86 82 87 83 static int clk_peripheral_is_enabled(struct clk_hw *hw) 88 84 { 89 85 struct clk_peripheral *periph = to_clk_peripheral(hw); 90 - struct at91_pmc *pmc = periph->pmc; 91 86 int offset = AT91_PMC_PCSR; 87 + unsigned int status; 92 88 u32 id = periph->id; 93 89 94 90 if (id < PERIPHERAL_ID_MIN) 95 91 return 1; 96 92 if (id > PERIPHERAL_ID_MAX) 97 93 offset = AT91_PMC_PCSR1; 98 - return !!(pmc_read(pmc, offset) & PERIPHERAL_MASK(id)); 94 + regmap_read(periph->regmap, offset, &status); 95 + 96 + return status & PERIPHERAL_MASK(id) ? 1 : 0; 99 97 } 100 98 101 99 static const struct clk_ops peripheral_ops = { ··· 107 101 }; 108 102 109 103 static struct clk * __init 110 - at91_clk_register_peripheral(struct at91_pmc *pmc, const char *name, 104 + at91_clk_register_peripheral(struct regmap *regmap, const char *name, 111 105 const char *parent_name, u32 id) 112 106 { 113 107 struct clk_peripheral *periph; 114 108 struct clk *clk = NULL; 115 109 struct clk_init_data init; 116 110 117 - if (!pmc || !name || !parent_name || id > PERIPHERAL_ID_MAX) 111 + if (!name || !parent_name || id > PERIPHERAL_ID_MAX) 118 112 return ERR_PTR(-EINVAL); 119 113 120 114 periph = kzalloc(sizeof(*periph), GFP_KERNEL); ··· 129 123 130 124 periph->id = id; 131 125 periph->hw.init = &init; 132 - periph->pmc = pmc; 126 + periph->regmap = regmap; 133 127 134 128 clk = clk_register(NULL, &periph->hw); 135 129 if (IS_ERR(clk)) ··· 166 160 static int clk_sam9x5_peripheral_enable(struct clk_hw *hw) 167 161 { 168 162 struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw); 169 - struct at91_pmc *pmc = periph->pmc; 170 - u32 tmp; 163 + unsigned long flags; 171 164 172 165 if (periph->id < PERIPHERAL_ID_MIN) 173 166 return 0; 174 167 175 - pmc_lock(pmc); 176 - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK)); 177 - tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_DIV_MASK; 178 - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_DIV(periph->div) 179 - | AT91_PMC_PCR_CMD 180 - | AT91_PMC_PCR_EN); 181 - pmc_unlock(pmc); 168 + spin_lock_irqsave(periph->lock, flags); 169 + regmap_write(periph->regmap, AT91_PMC_PCR, 170 + (periph->id & AT91_PMC_PCR_PID_MASK)); 171 + regmap_update_bits(periph->regmap, AT91_PMC_PCR, 172 + AT91_PMC_PCR_DIV_MASK | AT91_PMC_PCR_CMD | 173 + AT91_PMC_PCR_EN, 174 + AT91_PMC_PCR_DIV(periph->div) | 175 + AT91_PMC_PCR_CMD | 176 + AT91_PMC_PCR_EN); 177 + spin_unlock_irqrestore(periph->lock, flags); 178 + 182 179 return 0; 183 180 } 184 181 185 182 static void clk_sam9x5_peripheral_disable(struct clk_hw *hw) 186 183 { 187 184 struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw); 188 - struct at91_pmc *pmc = periph->pmc; 189 - u32 tmp; 185 + unsigned long flags; 190 186 191 187 if (periph->id < PERIPHERAL_ID_MIN) 192 188 return; 193 189 194 - pmc_lock(pmc); 195 - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK)); 196 - tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_EN; 197 - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD); 198 - pmc_unlock(pmc); 190 + spin_lock_irqsave(periph->lock, flags); 191 + regmap_write(periph->regmap, AT91_PMC_PCR, 192 + (periph->id & AT91_PMC_PCR_PID_MASK)); 193 + regmap_update_bits(periph->regmap, AT91_PMC_PCR, 194 + AT91_PMC_PCR_EN | AT91_PMC_PCR_CMD, 195 + AT91_PMC_PCR_CMD); 196 + spin_unlock_irqrestore(periph->lock, flags); 199 197 } 200 198 201 199 static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw) 202 200 { 203 201 struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw); 204 - struct at91_pmc *pmc = periph->pmc; 205 - int ret; 202 + unsigned long flags; 203 + unsigned int status; 206 204 207 205 if (periph->id < PERIPHERAL_ID_MIN) 208 206 return 1; 209 207 210 - pmc_lock(pmc); 211 - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK)); 212 - ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_EN); 213 - pmc_unlock(pmc); 208 + spin_lock_irqsave(periph->lock, flags); 209 + regmap_write(periph->regmap, AT91_PMC_PCR, 210 + (periph->id & AT91_PMC_PCR_PID_MASK)); 211 + regmap_read(periph->regmap, AT91_PMC_PCR, &status); 212 + spin_unlock_irqrestore(periph->lock, flags); 214 213 215 - return ret; 214 + return status & AT91_PMC_PCR_EN ? 1 : 0; 216 215 } 217 216 218 217 static unsigned long ··· 225 214 unsigned long parent_rate) 226 215 { 227 216 struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw); 228 - struct at91_pmc *pmc = periph->pmc; 229 - u32 tmp; 217 + unsigned long flags; 218 + unsigned int status; 230 219 231 220 if (periph->id < PERIPHERAL_ID_MIN) 232 221 return parent_rate; 233 222 234 - pmc_lock(pmc); 235 - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK)); 236 - tmp = pmc_read(pmc, AT91_PMC_PCR); 237 - pmc_unlock(pmc); 223 + spin_lock_irqsave(periph->lock, flags); 224 + regmap_write(periph->regmap, AT91_PMC_PCR, 225 + (periph->id & AT91_PMC_PCR_PID_MASK)); 226 + regmap_read(periph->regmap, AT91_PMC_PCR, &status); 227 + spin_unlock_irqrestore(periph->lock, flags); 238 228 239 - if (tmp & AT91_PMC_PCR_EN) { 240 - periph->div = PERIPHERAL_RSHIFT(tmp); 229 + if (status & AT91_PMC_PCR_EN) { 230 + periph->div = PERIPHERAL_RSHIFT(status); 241 231 periph->auto_div = false; 242 232 } else { 243 233 clk_sam9x5_peripheral_autodiv(periph); ··· 330 318 }; 331 319 332 320 static struct clk * __init 333 - at91_clk_register_sam9x5_peripheral(struct at91_pmc *pmc, const char *name, 334 - const char *parent_name, u32 id, 335 - const struct clk_range *range) 321 + at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock, 322 + const char *name, const char *parent_name, 323 + u32 id, const struct clk_range *range) 336 324 { 337 325 struct clk_sam9x5_peripheral *periph; 338 326 struct clk *clk = NULL; 339 327 struct clk_init_data init; 340 328 341 - if (!pmc || !name || !parent_name) 329 + if (!name || !parent_name) 342 330 return ERR_PTR(-EINVAL); 343 331 344 332 periph = kzalloc(sizeof(*periph), GFP_KERNEL); ··· 354 342 periph->id = id; 355 343 periph->hw.init = &init; 356 344 periph->div = 0; 357 - periph->pmc = pmc; 345 + periph->regmap = regmap; 346 + periph->lock = lock; 358 347 periph->auto_div = true; 359 348 periph->range = *range; 360 349 ··· 369 356 } 370 357 371 358 static void __init 372 - of_at91_clk_periph_setup(struct device_node *np, struct at91_pmc *pmc, u8 type) 359 + of_at91_clk_periph_setup(struct device_node *np, u8 type) 373 360 { 374 361 int num; 375 362 u32 id; ··· 377 364 const char *parent_name; 378 365 const char *name; 379 366 struct device_node *periphclknp; 367 + struct regmap *regmap; 380 368 381 369 parent_name = of_clk_get_parent_name(np, 0); 382 370 if (!parent_name) ··· 385 371 386 372 num = of_get_child_count(np); 387 373 if (!num || num > PERIPHERAL_MAX) 374 + return; 375 + 376 + regmap = syscon_node_to_regmap(of_get_parent(np)); 377 + if (IS_ERR(regmap)) 388 378 return; 389 379 390 380 for_each_child_of_node(np, periphclknp) { ··· 402 384 name = periphclknp->name; 403 385 404 386 if (type == PERIPHERAL_AT91RM9200) { 405 - clk = at91_clk_register_peripheral(pmc, name, 387 + clk = at91_clk_register_peripheral(regmap, name, 406 388 parent_name, id); 407 389 } else { 408 390 struct clk_range range = CLK_RANGE(0, 0); ··· 411 393 "atmel,clk-output-range", 412 394 &range); 413 395 414 - clk = at91_clk_register_sam9x5_peripheral(pmc, name, 396 + clk = at91_clk_register_sam9x5_peripheral(regmap, 397 + &pmc_pcr_lock, 398 + name, 415 399 parent_name, 416 400 id, &range); 417 401 } ··· 425 405 } 426 406 } 427 407 428 - void __init of_at91rm9200_clk_periph_setup(struct device_node *np, 429 - struct at91_pmc *pmc) 408 + static void __init of_at91rm9200_clk_periph_setup(struct device_node *np) 430 409 { 431 - of_at91_clk_periph_setup(np, pmc, PERIPHERAL_AT91RM9200); 410 + of_at91_clk_periph_setup(np, PERIPHERAL_AT91RM9200); 432 411 } 412 + CLK_OF_DECLARE(at91rm9200_clk_periph, "atmel,at91rm9200-clk-peripheral", 413 + of_at91rm9200_clk_periph_setup); 433 414 434 - void __init of_at91sam9x5_clk_periph_setup(struct device_node *np, 435 - struct at91_pmc *pmc) 415 + static void __init of_at91sam9x5_clk_periph_setup(struct device_node *np) 436 416 { 437 - of_at91_clk_periph_setup(np, pmc, PERIPHERAL_AT91SAM9X5); 417 + of_at91_clk_periph_setup(np, PERIPHERAL_AT91SAM9X5); 438 418 } 419 + CLK_OF_DECLARE(at91sam9x5_clk_periph, "atmel,at91sam9x5-clk-peripheral", 420 + of_at91sam9x5_clk_periph_setup); 421 +
+70 -49
drivers/clk/at91/clk-pll.c
··· 20 20 #include <linux/sched.h> 21 21 #include <linux/interrupt.h> 22 22 #include <linux/irq.h> 23 + #include <linux/mfd/syscon.h> 24 + #include <linux/regmap.h> 23 25 24 26 #include "pmc.h" 25 27 ··· 60 58 61 59 struct clk_pll { 62 60 struct clk_hw hw; 63 - struct at91_pmc *pmc; 61 + struct regmap *regmap; 64 62 unsigned int irq; 65 63 wait_queue_head_t wait; 66 64 u8 id; ··· 81 79 return IRQ_HANDLED; 82 80 } 83 81 82 + static inline bool clk_pll_ready(struct regmap *regmap, int id) 83 + { 84 + unsigned int status; 85 + 86 + regmap_read(regmap, AT91_PMC_SR, &status); 87 + 88 + return status & PLL_STATUS_MASK(id) ? 1 : 0; 89 + } 90 + 84 91 static int clk_pll_prepare(struct clk_hw *hw) 85 92 { 86 93 struct clk_pll *pll = to_clk_pll(hw); 87 - struct at91_pmc *pmc = pll->pmc; 94 + struct regmap *regmap = pll->regmap; 88 95 const struct clk_pll_layout *layout = pll->layout; 89 96 const struct clk_pll_characteristics *characteristics = 90 97 pll->characteristics; ··· 101 90 u32 mask = PLL_STATUS_MASK(id); 102 91 int offset = PLL_REG(id); 103 92 u8 out = 0; 104 - u32 pllr, icpr; 93 + unsigned int pllr; 94 + unsigned int status; 105 95 u8 div; 106 96 u16 mul; 107 97 108 - pllr = pmc_read(pmc, offset); 98 + regmap_read(regmap, offset, &pllr); 109 99 div = PLL_DIV(pllr); 110 100 mul = PLL_MUL(pllr, layout); 111 101 112 - if ((pmc_read(pmc, AT91_PMC_SR) & mask) && 102 + regmap_read(regmap, AT91_PMC_SR, &status); 103 + if ((status & mask) && 113 104 (div == pll->div && mul == pll->mul)) 114 105 return 0; 115 106 116 107 if (characteristics->out) 117 108 out = characteristics->out[pll->range]; 118 - if (characteristics->icpll) { 119 - icpr = pmc_read(pmc, AT91_PMC_PLLICPR) & ~PLL_ICPR_MASK(id); 120 - icpr |= (characteristics->icpll[pll->range] << 121 - PLL_ICPR_SHIFT(id)); 122 - pmc_write(pmc, AT91_PMC_PLLICPR, icpr); 123 - } 124 109 125 - pllr &= ~layout->pllr_mask; 126 - pllr |= layout->pllr_mask & 127 - (pll->div | (PLL_MAX_COUNT << PLL_COUNT_SHIFT) | 128 - (out << PLL_OUT_SHIFT) | 129 - ((pll->mul & layout->mul_mask) << layout->mul_shift)); 130 - pmc_write(pmc, offset, pllr); 110 + if (characteristics->icpll) 111 + regmap_update_bits(regmap, AT91_PMC_PLLICPR, PLL_ICPR_MASK(id), 112 + characteristics->icpll[pll->range] << PLL_ICPR_SHIFT(id)); 131 113 132 - while (!(pmc_read(pmc, AT91_PMC_SR) & mask)) { 114 + regmap_update_bits(regmap, offset, layout->pllr_mask, 115 + pll->div | (PLL_MAX_COUNT << PLL_COUNT_SHIFT) | 116 + (out << PLL_OUT_SHIFT) | 117 + ((pll->mul & layout->mul_mask) << layout->mul_shift)); 118 + 119 + while (!clk_pll_ready(regmap, pll->id)) { 133 120 enable_irq(pll->irq); 134 121 wait_event(pll->wait, 135 - pmc_read(pmc, AT91_PMC_SR) & mask); 122 + clk_pll_ready(regmap, pll->id)); 136 123 } 137 124 138 125 return 0; ··· 139 130 static int clk_pll_is_prepared(struct clk_hw *hw) 140 131 { 141 132 struct clk_pll *pll = to_clk_pll(hw); 142 - struct at91_pmc *pmc = pll->pmc; 143 133 144 - return !!(pmc_read(pmc, AT91_PMC_SR) & 145 - PLL_STATUS_MASK(pll->id)); 134 + return clk_pll_ready(pll->regmap, pll->id); 146 135 } 147 136 148 137 static void clk_pll_unprepare(struct clk_hw *hw) 149 138 { 150 139 struct clk_pll *pll = to_clk_pll(hw); 151 - struct at91_pmc *pmc = pll->pmc; 152 - const struct clk_pll_layout *layout = pll->layout; 153 - int offset = PLL_REG(pll->id); 154 - u32 tmp = pmc_read(pmc, offset) & ~(layout->pllr_mask); 140 + unsigned int mask = pll->layout->pllr_mask; 155 141 156 - pmc_write(pmc, offset, tmp); 142 + regmap_update_bits(pll->regmap, PLL_REG(pll->id), mask, ~mask); 157 143 } 158 144 159 145 static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, 160 146 unsigned long parent_rate) 161 147 { 162 148 struct clk_pll *pll = to_clk_pll(hw); 149 + unsigned int pllr; 150 + u16 mul; 151 + u8 div; 163 152 164 - if (!pll->div || !pll->mul) 153 + regmap_read(pll->regmap, PLL_REG(pll->id), &pllr); 154 + 155 + div = PLL_DIV(pllr); 156 + mul = PLL_MUL(pllr, pll->layout); 157 + 158 + if (!div || !mul) 165 159 return 0; 166 160 167 - return (parent_rate / pll->div) * (pll->mul + 1); 161 + return (parent_rate / div) * (mul + 1); 168 162 } 169 163 170 164 static long clk_pll_get_best_div_mul(struct clk_pll *pll, unsigned long rate, ··· 320 308 }; 321 309 322 310 static struct clk * __init 323 - at91_clk_register_pll(struct at91_pmc *pmc, unsigned int irq, const char *name, 311 + at91_clk_register_pll(struct regmap *regmap, unsigned int irq, const char *name, 324 312 const char *parent_name, u8 id, 325 313 const struct clk_pll_layout *layout, 326 314 const struct clk_pll_characteristics *characteristics) ··· 330 318 struct clk_init_data init; 331 319 int ret; 332 320 int offset = PLL_REG(id); 333 - u32 tmp; 321 + unsigned int pllr; 334 322 335 323 if (id > PLL_MAX_ID) 336 324 return ERR_PTR(-EINVAL); ··· 349 337 pll->hw.init = &init; 350 338 pll->layout = layout; 351 339 pll->characteristics = characteristics; 352 - pll->pmc = pmc; 340 + pll->regmap = regmap; 353 341 pll->irq = irq; 354 - tmp = pmc_read(pmc, offset) & layout->pllr_mask; 355 - pll->div = PLL_DIV(tmp); 356 - pll->mul = PLL_MUL(tmp, layout); 342 + regmap_read(regmap, offset, &pllr); 343 + pll->div = PLL_DIV(pllr); 344 + pll->mul = PLL_MUL(pllr, layout); 357 345 init_waitqueue_head(&pll->wait); 358 346 irq_set_status_flags(pll->irq, IRQ_NOAUTOEN); 359 347 ret = request_irq(pll->irq, clk_pll_irq_handler, IRQF_TRIGGER_HIGH, ··· 495 483 } 496 484 497 485 static void __init 498 - of_at91_clk_pll_setup(struct device_node *np, struct at91_pmc *pmc, 486 + of_at91_clk_pll_setup(struct device_node *np, 499 487 const struct clk_pll_layout *layout) 500 488 { 501 489 u32 id; 502 490 unsigned int irq; 503 491 struct clk *clk; 492 + struct regmap *regmap; 504 493 const char *parent_name; 505 494 const char *name = np->name; 506 495 struct clk_pll_characteristics *characteristics; ··· 513 500 514 501 of_property_read_string(np, "clock-output-names", &name); 515 502 503 + regmap = syscon_node_to_regmap(of_get_parent(np)); 504 + if (IS_ERR(regmap)) 505 + return; 506 + 516 507 characteristics = of_at91_clk_pll_get_characteristics(np); 517 508 if (!characteristics) 518 509 return; ··· 525 508 if (!irq) 526 509 return; 527 510 528 - clk = at91_clk_register_pll(pmc, irq, name, parent_name, id, layout, 511 + clk = at91_clk_register_pll(regmap, irq, name, parent_name, id, layout, 529 512 characteristics); 530 513 if (IS_ERR(clk)) 531 514 goto out_free_characteristics; ··· 537 520 kfree(characteristics); 538 521 } 539 522 540 - void __init of_at91rm9200_clk_pll_setup(struct device_node *np, 541 - struct at91_pmc *pmc) 523 + static void __init of_at91rm9200_clk_pll_setup(struct device_node *np) 542 524 { 543 - of_at91_clk_pll_setup(np, pmc, &at91rm9200_pll_layout); 525 + of_at91_clk_pll_setup(np, &at91rm9200_pll_layout); 544 526 } 527 + CLK_OF_DECLARE(at91rm9200_clk_pll, "atmel,at91rm9200-clk-pll", 528 + of_at91rm9200_clk_pll_setup); 545 529 546 - void __init of_at91sam9g45_clk_pll_setup(struct device_node *np, 547 - struct at91_pmc *pmc) 530 + static void __init of_at91sam9g45_clk_pll_setup(struct device_node *np) 548 531 { 549 - of_at91_clk_pll_setup(np, pmc, &at91sam9g45_pll_layout); 532 + of_at91_clk_pll_setup(np, &at91sam9g45_pll_layout); 550 533 } 534 + CLK_OF_DECLARE(at91sam9g45_clk_pll, "atmel,at91sam9g45-clk-pll", 535 + of_at91sam9g45_clk_pll_setup); 551 536 552 - void __init of_at91sam9g20_clk_pllb_setup(struct device_node *np, 553 - struct at91_pmc *pmc) 537 + static void __init of_at91sam9g20_clk_pllb_setup(struct device_node *np) 554 538 { 555 - of_at91_clk_pll_setup(np, pmc, &at91sam9g20_pllb_layout); 539 + of_at91_clk_pll_setup(np, &at91sam9g20_pllb_layout); 556 540 } 541 + CLK_OF_DECLARE(at91sam9g20_clk_pllb, "atmel,at91sam9g20-clk-pllb", 542 + of_at91sam9g20_clk_pllb_setup); 557 543 558 - void __init of_sama5d3_clk_pll_setup(struct device_node *np, 559 - struct at91_pmc *pmc) 544 + static void __init of_sama5d3_clk_pll_setup(struct device_node *np) 560 545 { 561 - of_at91_clk_pll_setup(np, pmc, &sama5d3_pll_layout); 546 + of_at91_clk_pll_setup(np, &sama5d3_pll_layout); 562 547 } 548 + CLK_OF_DECLARE(sama5d3_clk_pll, "atmel,sama5d3-clk-pll", 549 + of_sama5d3_clk_pll_setup);
+20 -22
drivers/clk/at91/clk-plldiv.c
··· 14 14 #include <linux/of.h> 15 15 #include <linux/of_address.h> 16 16 #include <linux/io.h> 17 + #include <linux/mfd/syscon.h> 18 + #include <linux/regmap.h> 17 19 18 20 #include "pmc.h" 19 21 ··· 23 21 24 22 struct clk_plldiv { 25 23 struct clk_hw hw; 26 - struct at91_pmc *pmc; 24 + struct regmap *regmap; 27 25 }; 28 26 29 27 static unsigned long clk_plldiv_recalc_rate(struct clk_hw *hw, 30 28 unsigned long parent_rate) 31 29 { 32 30 struct clk_plldiv *plldiv = to_clk_plldiv(hw); 33 - struct at91_pmc *pmc = plldiv->pmc; 31 + unsigned int mckr; 34 32 35 - if (pmc_read(pmc, AT91_PMC_MCKR) & AT91_PMC_PLLADIV2) 33 + regmap_read(plldiv->regmap, AT91_PMC_MCKR, &mckr); 34 + 35 + if (mckr & AT91_PMC_PLLADIV2) 36 36 return parent_rate / 2; 37 37 38 38 return parent_rate; ··· 61 57 unsigned long parent_rate) 62 58 { 63 59 struct clk_plldiv *plldiv = to_clk_plldiv(hw); 64 - struct at91_pmc *pmc = plldiv->pmc; 65 - u32 tmp; 66 60 67 - if (parent_rate != rate && (parent_rate / 2) != rate) 61 + if ((parent_rate != rate) && (parent_rate / 2 != rate)) 68 62 return -EINVAL; 69 63 70 - pmc_lock(pmc); 71 - tmp = pmc_read(pmc, AT91_PMC_MCKR) & ~AT91_PMC_PLLADIV2; 72 - if ((parent_rate / 2) == rate) 73 - tmp |= AT91_PMC_PLLADIV2; 74 - pmc_write(pmc, AT91_PMC_MCKR, tmp); 75 - pmc_unlock(pmc); 64 + regmap_update_bits(plldiv->regmap, AT91_PMC_MCKR, AT91_PMC_PLLADIV2, 65 + parent_rate != rate ? AT91_PMC_PLLADIV2 : 0); 76 66 77 67 return 0; 78 68 } ··· 78 80 }; 79 81 80 82 static struct clk * __init 81 - at91_clk_register_plldiv(struct at91_pmc *pmc, const char *name, 83 + at91_clk_register_plldiv(struct regmap *regmap, const char *name, 82 84 const char *parent_name) 83 85 { 84 86 struct clk_plldiv *plldiv; ··· 96 98 init.flags = CLK_SET_RATE_GATE; 97 99 98 100 plldiv->hw.init = &init; 99 - plldiv->pmc = pmc; 101 + plldiv->regmap = regmap; 100 102 101 103 clk = clk_register(NULL, &plldiv->hw); 102 104 ··· 107 109 } 108 110 109 111 static void __init 110 - of_at91_clk_plldiv_setup(struct device_node *np, struct at91_pmc *pmc) 112 + of_at91sam9x5_clk_plldiv_setup(struct device_node *np) 111 113 { 112 114 struct clk *clk; 113 115 const char *parent_name; 114 116 const char *name = np->name; 117 + struct regmap *regmap; 115 118 116 119 parent_name = of_clk_get_parent_name(np, 0); 117 120 118 121 of_property_read_string(np, "clock-output-names", &name); 119 122 120 - clk = at91_clk_register_plldiv(pmc, name, parent_name); 123 + regmap = syscon_node_to_regmap(of_get_parent(np)); 124 + if (IS_ERR(regmap)) 125 + return; 121 126 127 + clk = at91_clk_register_plldiv(regmap, name, parent_name); 122 128 if (IS_ERR(clk)) 123 129 return; 124 130 125 131 of_clk_add_provider(np, of_clk_src_simple_get, clk); 126 132 return; 127 133 } 128 - 129 - void __init of_at91sam9x5_clk_plldiv_setup(struct device_node *np, 130 - struct at91_pmc *pmc) 131 - { 132 - of_at91_clk_plldiv_setup(np, pmc); 133 - } 134 + CLK_OF_DECLARE(at91sam9x5_clk_plldiv, "atmel,at91sam9x5-clk-plldiv", 135 + of_at91sam9x5_clk_plldiv_setup);
+51 -41
drivers/clk/at91/clk-programmable.c
··· 16 16 #include <linux/io.h> 17 17 #include <linux/wait.h> 18 18 #include <linux/sched.h> 19 + #include <linux/mfd/syscon.h> 20 + #include <linux/regmap.h> 19 21 20 22 #include "pmc.h" 21 23 ··· 26 24 27 25 #define PROG_STATUS_MASK(id) (1 << ((id) + 8)) 28 26 #define PROG_PRES_MASK 0x7 27 + #define PROG_PRES(layout, pckr) ((pckr >> layout->pres_shift) & PROG_PRES_MASK) 29 28 #define PROG_MAX_RM9200_CSS 3 30 29 31 30 struct clk_programmable_layout { ··· 37 34 38 35 struct clk_programmable { 39 36 struct clk_hw hw; 40 - struct at91_pmc *pmc; 37 + struct regmap *regmap; 41 38 u8 id; 42 39 const struct clk_programmable_layout *layout; 43 40 }; ··· 47 44 static unsigned long clk_programmable_recalc_rate(struct clk_hw *hw, 48 45 unsigned long parent_rate) 49 46 { 50 - u32 pres; 51 47 struct clk_programmable *prog = to_clk_programmable(hw); 52 - struct at91_pmc *pmc = prog->pmc; 53 - const struct clk_programmable_layout *layout = prog->layout; 48 + unsigned int pckr; 54 49 55 - pres = (pmc_read(pmc, AT91_PMC_PCKR(prog->id)) >> layout->pres_shift) & 56 - PROG_PRES_MASK; 57 - return parent_rate >> pres; 50 + regmap_read(prog->regmap, AT91_PMC_PCKR(prog->id), &pckr); 51 + 52 + return parent_rate >> PROG_PRES(prog->layout, pckr); 58 53 } 59 54 60 55 static int clk_programmable_determine_rate(struct clk_hw *hw, ··· 102 101 { 103 102 struct clk_programmable *prog = to_clk_programmable(hw); 104 103 const struct clk_programmable_layout *layout = prog->layout; 105 - struct at91_pmc *pmc = prog->pmc; 106 - u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) & ~layout->css_mask; 104 + unsigned int mask = layout->css_mask; 105 + unsigned int pckr = 0; 107 106 108 107 if (layout->have_slck_mck) 109 - tmp &= AT91_PMC_CSSMCK_MCK; 108 + mask |= AT91_PMC_CSSMCK_MCK; 110 109 111 110 if (index > layout->css_mask) { 112 - if (index > PROG_MAX_RM9200_CSS && layout->have_slck_mck) { 113 - tmp |= AT91_PMC_CSSMCK_MCK; 114 - return 0; 115 - } else { 111 + if (index > PROG_MAX_RM9200_CSS && !layout->have_slck_mck) 116 112 return -EINVAL; 117 - } 113 + 114 + pckr |= AT91_PMC_CSSMCK_MCK; 118 115 } 119 116 120 - pmc_write(pmc, AT91_PMC_PCKR(prog->id), tmp | index); 117 + regmap_update_bits(prog->regmap, AT91_PMC_PCKR(prog->id), mask, pckr); 118 + 121 119 return 0; 122 120 } 123 121 124 122 static u8 clk_programmable_get_parent(struct clk_hw *hw) 125 123 { 126 - u32 tmp; 127 - u8 ret; 128 124 struct clk_programmable *prog = to_clk_programmable(hw); 129 - struct at91_pmc *pmc = prog->pmc; 130 125 const struct clk_programmable_layout *layout = prog->layout; 126 + unsigned int pckr; 127 + u8 ret; 131 128 132 - tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)); 133 - ret = tmp & layout->css_mask; 134 - if (layout->have_slck_mck && (tmp & AT91_PMC_CSSMCK_MCK) && !ret) 129 + regmap_read(prog->regmap, AT91_PMC_PCKR(prog->id), &pckr); 130 + 131 + ret = pckr & layout->css_mask; 132 + 133 + if (layout->have_slck_mck && (pckr & AT91_PMC_CSSMCK_MCK) && !ret) 135 134 ret = PROG_MAX_RM9200_CSS + 1; 136 135 137 136 return ret; ··· 141 140 unsigned long parent_rate) 142 141 { 143 142 struct clk_programmable *prog = to_clk_programmable(hw); 144 - struct at91_pmc *pmc = prog->pmc; 145 143 const struct clk_programmable_layout *layout = prog->layout; 146 144 unsigned long div = parent_rate / rate; 145 + unsigned int pckr; 147 146 int shift = 0; 148 - u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) & 149 - ~(PROG_PRES_MASK << layout->pres_shift); 147 + 148 + regmap_read(prog->regmap, AT91_PMC_PCKR(prog->id), &pckr); 150 149 151 150 if (!div) 152 151 return -EINVAL; 153 152 154 153 shift = fls(div) - 1; 155 154 156 - if (div != (1<<shift)) 155 + if (div != (1 << shift)) 157 156 return -EINVAL; 158 157 159 158 if (shift >= PROG_PRES_MASK) 160 159 return -EINVAL; 161 160 162 - pmc_write(pmc, AT91_PMC_PCKR(prog->id), 163 - tmp | (shift << layout->pres_shift)); 161 + regmap_update_bits(prog->regmap, AT91_PMC_PCKR(prog->id), 162 + PROG_PRES_MASK << layout->pres_shift, 163 + shift << layout->pres_shift); 164 164 165 165 return 0; 166 166 } ··· 175 173 }; 176 174 177 175 static struct clk * __init 178 - at91_clk_register_programmable(struct at91_pmc *pmc, 176 + at91_clk_register_programmable(struct regmap *regmap, 179 177 const char *name, const char **parent_names, 180 178 u8 num_parents, u8 id, 181 179 const struct clk_programmable_layout *layout) ··· 200 198 prog->id = id; 201 199 prog->layout = layout; 202 200 prog->hw.init = &init; 203 - prog->pmc = pmc; 201 + prog->regmap = regmap; 204 202 205 203 clk = clk_register(NULL, &prog->hw); 206 204 if (IS_ERR(clk)) ··· 228 226 }; 229 227 230 228 static void __init 231 - of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc, 229 + of_at91_clk_prog_setup(struct device_node *np, 232 230 const struct clk_programmable_layout *layout) 233 231 { 234 232 int num; ··· 238 236 const char *parent_names[PROG_SOURCE_MAX]; 239 237 const char *name; 240 238 struct device_node *progclknp; 239 + struct regmap *regmap; 241 240 242 241 num_parents = of_clk_get_parent_count(np); 243 242 if (num_parents <= 0 || num_parents > PROG_SOURCE_MAX) ··· 250 247 if (!num || num > (PROG_ID_MAX + 1)) 251 248 return; 252 249 250 + regmap = syscon_node_to_regmap(of_get_parent(np)); 251 + if (IS_ERR(regmap)) 252 + return; 253 + 253 254 for_each_child_of_node(np, progclknp) { 254 255 if (of_property_read_u32(progclknp, "reg", &id)) 255 256 continue; ··· 261 254 if (of_property_read_string(np, "clock-output-names", &name)) 262 255 name = progclknp->name; 263 256 264 - clk = at91_clk_register_programmable(pmc, name, 257 + clk = at91_clk_register_programmable(regmap, name, 265 258 parent_names, num_parents, 266 259 id, layout); 267 260 if (IS_ERR(clk)) ··· 272 265 } 273 266 274 267 275 - void __init of_at91rm9200_clk_prog_setup(struct device_node *np, 276 - struct at91_pmc *pmc) 268 + static void __init of_at91rm9200_clk_prog_setup(struct device_node *np) 277 269 { 278 - of_at91_clk_prog_setup(np, pmc, &at91rm9200_programmable_layout); 270 + of_at91_clk_prog_setup(np, &at91rm9200_programmable_layout); 279 271 } 272 + CLK_OF_DECLARE(at91rm9200_clk_prog, "atmel,at91rm9200-clk-programmable", 273 + of_at91rm9200_clk_prog_setup); 280 274 281 - void __init of_at91sam9g45_clk_prog_setup(struct device_node *np, 282 - struct at91_pmc *pmc) 275 + static void __init of_at91sam9g45_clk_prog_setup(struct device_node *np) 283 276 { 284 - of_at91_clk_prog_setup(np, pmc, &at91sam9g45_programmable_layout); 277 + of_at91_clk_prog_setup(np, &at91sam9g45_programmable_layout); 285 278 } 279 + CLK_OF_DECLARE(at91sam9g45_clk_prog, "atmel,at91sam9g45-clk-programmable", 280 + of_at91sam9g45_clk_prog_setup); 286 281 287 - void __init of_at91sam9x5_clk_prog_setup(struct device_node *np, 288 - struct at91_pmc *pmc) 282 + static void __init of_at91sam9x5_clk_prog_setup(struct device_node *np) 289 283 { 290 - of_at91_clk_prog_setup(np, pmc, &at91sam9x5_programmable_layout); 284 + of_at91_clk_prog_setup(np, &at91sam9x5_programmable_layout); 291 285 } 286 + CLK_OF_DECLARE(at91sam9x5_clk_prog, "atmel,at91sam9x5-clk-programmable", 287 + of_at91sam9x5_clk_prog_setup);
+19 -8
drivers/clk/at91/clk-slow.c
··· 21 21 #include <linux/io.h> 22 22 #include <linux/interrupt.h> 23 23 #include <linux/irq.h> 24 + #include <linux/mfd/syscon.h> 25 + #include <linux/regmap.h> 24 26 #include <linux/sched.h> 25 27 #include <linux/wait.h> 26 28 ··· 60 58 61 59 struct clk_sam9260_slow { 62 60 struct clk_hw hw; 63 - struct at91_pmc *pmc; 61 + struct regmap *regmap; 64 62 }; 65 63 66 64 #define to_clk_sam9260_slow(hw) container_of(hw, struct clk_sam9260_slow, hw) ··· 390 388 static u8 clk_sam9260_slow_get_parent(struct clk_hw *hw) 391 389 { 392 390 struct clk_sam9260_slow *slowck = to_clk_sam9260_slow(hw); 391 + unsigned int status; 393 392 394 - return !!(pmc_read(slowck->pmc, AT91_PMC_SR) & AT91_PMC_OSCSEL); 393 + regmap_read(slowck->regmap, AT91_PMC_SR, &status); 394 + 395 + return status & AT91_PMC_OSCSEL ? 1 : 0; 395 396 } 396 397 397 398 static const struct clk_ops sam9260_slow_ops = { ··· 402 397 }; 403 398 404 399 static struct clk * __init 405 - at91_clk_register_sam9260_slow(struct at91_pmc *pmc, 400 + at91_clk_register_sam9260_slow(struct regmap *regmap, 406 401 const char *name, 407 402 const char **parent_names, 408 403 int num_parents) ··· 411 406 struct clk *clk = NULL; 412 407 struct clk_init_data init; 413 408 414 - if (!pmc || !name) 409 + if (!name) 415 410 return ERR_PTR(-EINVAL); 416 411 417 412 if (!parent_names || !num_parents) ··· 428 423 init.flags = 0; 429 424 430 425 slowck->hw.init = &init; 431 - slowck->pmc = pmc; 426 + slowck->regmap = regmap; 432 427 433 428 clk = clk_register(NULL, &slowck->hw); 434 429 if (IS_ERR(clk)) ··· 437 432 return clk; 438 433 } 439 434 440 - void __init of_at91sam9260_clk_slow_setup(struct device_node *np, 441 - struct at91_pmc *pmc) 435 + static void __init of_at91sam9260_clk_slow_setup(struct device_node *np) 442 436 { 443 437 struct clk *clk; 444 438 const char *parent_names[2]; 445 439 int num_parents; 446 440 const char *name = np->name; 441 + struct regmap *regmap; 447 442 448 443 num_parents = of_clk_get_parent_count(np); 449 444 if (num_parents != 2) 450 445 return; 451 446 452 447 of_clk_parent_fill(np, parent_names, num_parents); 448 + regmap = syscon_node_to_regmap(of_get_parent(np)); 449 + if (IS_ERR(regmap)) 450 + return; 453 451 454 452 of_property_read_string(np, "clock-output-names", &name); 455 453 456 - clk = at91_clk_register_sam9260_slow(pmc, name, parent_names, 454 + clk = at91_clk_register_sam9260_slow(regmap, name, parent_names, 457 455 num_parents); 458 456 if (IS_ERR(clk)) 459 457 return; 460 458 461 459 of_clk_add_provider(np, of_clk_src_simple_get, clk); 462 460 } 461 + 462 + CLK_OF_DECLARE(at91sam9260_clk_slow, "atmel,at91sam9260-clk-slow", 463 + of_at91sam9260_clk_slow_setup);
+30 -24
drivers/clk/at91/clk-smd.c
··· 14 14 #include <linux/of.h> 15 15 #include <linux/of_address.h> 16 16 #include <linux/io.h> 17 + #include <linux/mfd/syscon.h> 18 + #include <linux/regmap.h> 17 19 18 20 #include "pmc.h" 19 21 ··· 26 24 27 25 struct at91sam9x5_clk_smd { 28 26 struct clk_hw hw; 29 - struct at91_pmc *pmc; 27 + struct regmap *regmap; 30 28 }; 31 29 32 30 #define to_at91sam9x5_clk_smd(hw) \ ··· 35 33 static unsigned long at91sam9x5_clk_smd_recalc_rate(struct clk_hw *hw, 36 34 unsigned long parent_rate) 37 35 { 38 - u32 tmp; 39 - u8 smddiv; 40 36 struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw); 41 - struct at91_pmc *pmc = smd->pmc; 37 + unsigned int smdr; 38 + u8 smddiv; 42 39 43 - tmp = pmc_read(pmc, AT91_PMC_SMD); 44 - smddiv = (tmp & AT91_PMC_SMD_DIV) >> SMD_DIV_SHIFT; 40 + regmap_read(smd->regmap, AT91_PMC_SMD, &smdr); 41 + smddiv = (smdr & AT91_PMC_SMD_DIV) >> SMD_DIV_SHIFT; 42 + 45 43 return parent_rate / (smddiv + 1); 46 44 } 47 45 ··· 69 67 70 68 static int at91sam9x5_clk_smd_set_parent(struct clk_hw *hw, u8 index) 71 69 { 72 - u32 tmp; 73 70 struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw); 74 - struct at91_pmc *pmc = smd->pmc; 75 71 76 72 if (index > 1) 77 73 return -EINVAL; 78 - tmp = pmc_read(pmc, AT91_PMC_SMD) & ~AT91_PMC_SMDS; 79 - if (index) 80 - tmp |= AT91_PMC_SMDS; 81 - pmc_write(pmc, AT91_PMC_SMD, tmp); 74 + 75 + regmap_update_bits(smd->regmap, AT91_PMC_SMD, AT91_PMC_SMDS, 76 + index ? AT91_PMC_SMDS : 0); 77 + 82 78 return 0; 83 79 } 84 80 85 81 static u8 at91sam9x5_clk_smd_get_parent(struct clk_hw *hw) 86 82 { 87 83 struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw); 88 - struct at91_pmc *pmc = smd->pmc; 84 + unsigned int smdr; 89 85 90 - return pmc_read(pmc, AT91_PMC_SMD) & AT91_PMC_SMDS; 86 + regmap_read(smd->regmap, AT91_PMC_SMD, &smdr); 87 + 88 + return smdr & AT91_PMC_SMDS; 91 89 } 92 90 93 91 static int at91sam9x5_clk_smd_set_rate(struct clk_hw *hw, unsigned long rate, 94 92 unsigned long parent_rate) 95 93 { 96 - u32 tmp; 97 94 struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw); 98 - struct at91_pmc *pmc = smd->pmc; 99 95 unsigned long div = parent_rate / rate; 100 96 101 97 if (parent_rate % rate || div < 1 || div > (SMD_MAX_DIV + 1)) 102 98 return -EINVAL; 103 - tmp = pmc_read(pmc, AT91_PMC_SMD) & ~AT91_PMC_SMD_DIV; 104 - tmp |= (div - 1) << SMD_DIV_SHIFT; 105 - pmc_write(pmc, AT91_PMC_SMD, tmp); 99 + 100 + regmap_update_bits(smd->regmap, AT91_PMC_SMD, AT91_PMC_SMD_DIV, 101 + (div - 1) << SMD_DIV_SHIFT); 106 102 107 103 return 0; 108 104 } ··· 114 114 }; 115 115 116 116 static struct clk * __init 117 - at91sam9x5_clk_register_smd(struct at91_pmc *pmc, const char *name, 117 + at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name, 118 118 const char **parent_names, u8 num_parents) 119 119 { 120 120 struct at91sam9x5_clk_smd *smd; ··· 132 132 init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE; 133 133 134 134 smd->hw.init = &init; 135 - smd->pmc = pmc; 135 + smd->regmap = regmap; 136 136 137 137 clk = clk_register(NULL, &smd->hw); 138 138 if (IS_ERR(clk)) ··· 141 141 return clk; 142 142 } 143 143 144 - void __init of_at91sam9x5_clk_smd_setup(struct device_node *np, 145 - struct at91_pmc *pmc) 144 + static void __init of_at91sam9x5_clk_smd_setup(struct device_node *np) 146 145 { 147 146 struct clk *clk; 148 147 int num_parents; 149 148 const char *parent_names[SMD_SOURCE_MAX]; 150 149 const char *name = np->name; 150 + struct regmap *regmap; 151 151 152 152 num_parents = of_clk_get_parent_count(np); 153 153 if (num_parents <= 0 || num_parents > SMD_SOURCE_MAX) ··· 157 157 158 158 of_property_read_string(np, "clock-output-names", &name); 159 159 160 - clk = at91sam9x5_clk_register_smd(pmc, name, parent_names, 160 + regmap = syscon_node_to_regmap(of_get_parent(np)); 161 + if (IS_ERR(regmap)) 162 + return; 163 + 164 + clk = at91sam9x5_clk_register_smd(regmap, name, parent_names, 161 165 num_parents); 162 166 if (IS_ERR(clk)) 163 167 return; 164 168 165 169 of_clk_add_provider(np, of_clk_src_simple_get, clk); 166 170 } 171 + CLK_OF_DECLARE(at91sam9x5_clk_smd, "atmel,at91sam9x5-clk-smd", 172 + of_at91sam9x5_clk_smd_setup);
+37 -23
drivers/clk/at91/clk-system.c
··· 19 19 #include <linux/interrupt.h> 20 20 #include <linux/wait.h> 21 21 #include <linux/sched.h> 22 + #include <linux/mfd/syscon.h> 23 + #include <linux/regmap.h> 22 24 23 25 #include "pmc.h" 24 26 ··· 31 29 #define to_clk_system(hw) container_of(hw, struct clk_system, hw) 32 30 struct clk_system { 33 31 struct clk_hw hw; 34 - struct at91_pmc *pmc; 32 + struct regmap *regmap; 35 33 unsigned int irq; 36 34 wait_queue_head_t wait; 37 35 u8 id; ··· 51 49 return IRQ_HANDLED; 52 50 } 53 51 52 + static inline bool clk_system_ready(struct regmap *regmap, int id) 53 + { 54 + unsigned int status; 55 + 56 + regmap_read(regmap, AT91_PMC_SR, &status); 57 + 58 + return status & (1 << id) ? 1 : 0; 59 + } 60 + 54 61 static int clk_system_prepare(struct clk_hw *hw) 55 62 { 56 63 struct clk_system *sys = to_clk_system(hw); 57 - struct at91_pmc *pmc = sys->pmc; 58 - u32 mask = 1 << sys->id; 59 64 60 - pmc_write(pmc, AT91_PMC_SCER, mask); 65 + regmap_write(sys->regmap, AT91_PMC_SCER, 1 << sys->id); 61 66 62 67 if (!is_pck(sys->id)) 63 68 return 0; 64 69 65 - while (!(pmc_read(pmc, AT91_PMC_SR) & mask)) { 70 + while (!clk_system_ready(sys->regmap, sys->id)) { 66 71 if (sys->irq) { 67 72 enable_irq(sys->irq); 68 73 wait_event(sys->wait, 69 - pmc_read(pmc, AT91_PMC_SR) & mask); 70 - } else 74 + clk_system_ready(sys->regmap, sys->id)); 75 + } else { 71 76 cpu_relax(); 77 + } 72 78 } 73 79 return 0; 74 80 } ··· 84 74 static void clk_system_unprepare(struct clk_hw *hw) 85 75 { 86 76 struct clk_system *sys = to_clk_system(hw); 87 - struct at91_pmc *pmc = sys->pmc; 88 77 89 - pmc_write(pmc, AT91_PMC_SCDR, 1 << sys->id); 78 + regmap_write(sys->regmap, AT91_PMC_SCDR, 1 << sys->id); 90 79 } 91 80 92 81 static int clk_system_is_prepared(struct clk_hw *hw) 93 82 { 94 83 struct clk_system *sys = to_clk_system(hw); 95 - struct at91_pmc *pmc = sys->pmc; 84 + unsigned int status; 96 85 97 - if (!(pmc_read(pmc, AT91_PMC_SCSR) & (1 << sys->id))) 86 + regmap_read(sys->regmap, AT91_PMC_SCSR, &status); 87 + 88 + if (!(status & (1 << sys->id))) 98 89 return 0; 99 90 100 91 if (!is_pck(sys->id)) 101 92 return 1; 102 93 103 - return !!(pmc_read(pmc, AT91_PMC_SR) & (1 << sys->id)); 94 + regmap_read(sys->regmap, AT91_PMC_SR, &status); 95 + 96 + return status & (1 << sys->id) ? 1 : 0; 104 97 } 105 98 106 99 static const struct clk_ops system_ops = { ··· 113 100 }; 114 101 115 102 static struct clk * __init 116 - at91_clk_register_system(struct at91_pmc *pmc, const char *name, 103 + at91_clk_register_system(struct regmap *regmap, const char *name, 117 104 const char *parent_name, u8 id, int irq) 118 105 { 119 106 struct clk_system *sys; ··· 136 123 137 124 sys->id = id; 138 125 sys->hw.init = &init; 139 - sys->pmc = pmc; 126 + sys->regmap = regmap; 140 127 sys->irq = irq; 141 128 if (irq) { 142 129 init_waitqueue_head(&sys->wait); ··· 159 146 return clk; 160 147 } 161 148 162 - static void __init 163 - of_at91_clk_sys_setup(struct device_node *np, struct at91_pmc *pmc) 149 + static void __init of_at91rm9200_clk_sys_setup(struct device_node *np) 164 150 { 165 151 int num; 166 152 int irq = 0; ··· 168 156 const char *name; 169 157 struct device_node *sysclknp; 170 158 const char *parent_name; 159 + struct regmap *regmap; 171 160 172 161 num = of_get_child_count(np); 173 162 if (num > (SYSTEM_MAX_ID + 1)) 163 + return; 164 + 165 + regmap = syscon_node_to_regmap(of_get_parent(np)); 166 + if (IS_ERR(regmap)) 174 167 return; 175 168 176 169 for_each_child_of_node(np, sysclknp) { ··· 190 173 191 174 parent_name = of_clk_get_parent_name(sysclknp, 0); 192 175 193 - clk = at91_clk_register_system(pmc, name, parent_name, id, irq); 176 + clk = at91_clk_register_system(regmap, name, parent_name, id, 177 + irq); 194 178 if (IS_ERR(clk)) 195 179 continue; 196 180 197 181 of_clk_add_provider(sysclknp, of_clk_src_simple_get, clk); 198 182 } 199 183 } 200 - 201 - void __init of_at91rm9200_clk_sys_setup(struct device_node *np, 202 - struct at91_pmc *pmc) 203 - { 204 - of_at91_clk_sys_setup(np, pmc); 205 - } 184 + CLK_OF_DECLARE(at91rm9200_clk_sys, "atmel,at91rm9200-clk-system", 185 + of_at91rm9200_clk_sys_setup);
+68 -53
drivers/clk/at91/clk-usb.c
··· 14 14 #include <linux/of.h> 15 15 #include <linux/of_address.h> 16 16 #include <linux/io.h> 17 + #include <linux/mfd/syscon.h> 18 + #include <linux/regmap.h> 17 19 18 20 #include "pmc.h" 19 21 ··· 29 27 30 28 struct at91sam9x5_clk_usb { 31 29 struct clk_hw hw; 32 - struct at91_pmc *pmc; 30 + struct regmap *regmap; 33 31 }; 34 32 35 33 #define to_at91sam9x5_clk_usb(hw) \ ··· 37 35 38 36 struct at91rm9200_clk_usb { 39 37 struct clk_hw hw; 40 - struct at91_pmc *pmc; 38 + struct regmap *regmap; 41 39 u32 divisors[4]; 42 40 }; 43 41 ··· 47 45 static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw, 48 46 unsigned long parent_rate) 49 47 { 50 - u32 tmp; 51 - u8 usbdiv; 52 48 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 53 - struct at91_pmc *pmc = usb->pmc; 49 + unsigned int usbr; 50 + u8 usbdiv; 54 51 55 - tmp = pmc_read(pmc, AT91_PMC_USB); 56 - usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT; 52 + regmap_read(usb->regmap, AT91_PMC_USB, &usbr); 53 + usbdiv = (usbr & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT; 57 54 58 55 return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1)); 59 56 } ··· 110 109 111 110 static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index) 112 111 { 113 - u32 tmp; 114 112 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 115 - struct at91_pmc *pmc = usb->pmc; 116 113 117 114 if (index > 1) 118 115 return -EINVAL; 119 - tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_USBS; 120 - if (index) 121 - tmp |= AT91_PMC_USBS; 122 - pmc_write(pmc, AT91_PMC_USB, tmp); 116 + 117 + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS, 118 + index ? AT91_PMC_USBS : 0); 119 + 123 120 return 0; 124 121 } 125 122 126 123 static u8 at91sam9x5_clk_usb_get_parent(struct clk_hw *hw) 127 124 { 128 125 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 129 - struct at91_pmc *pmc = usb->pmc; 126 + unsigned int usbr; 130 127 131 - return pmc_read(pmc, AT91_PMC_USB) & AT91_PMC_USBS; 128 + regmap_read(usb->regmap, AT91_PMC_USB, &usbr); 129 + 130 + return usbr & AT91_PMC_USBS; 132 131 } 133 132 134 133 static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate, 135 134 unsigned long parent_rate) 136 135 { 137 - u32 tmp; 138 136 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 139 - struct at91_pmc *pmc = usb->pmc; 140 137 unsigned long div; 141 138 142 139 if (!rate) ··· 144 145 if (div > SAM9X5_USB_MAX_DIV + 1 || !div) 145 146 return -EINVAL; 146 147 147 - tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV; 148 - tmp |= (div - 1) << SAM9X5_USB_DIV_SHIFT; 149 - pmc_write(pmc, AT91_PMC_USB, tmp); 148 + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_OHCIUSBDIV, 149 + (div - 1) << SAM9X5_USB_DIV_SHIFT); 150 150 151 151 return 0; 152 152 } ··· 161 163 static int at91sam9n12_clk_usb_enable(struct clk_hw *hw) 162 164 { 163 165 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 164 - struct at91_pmc *pmc = usb->pmc; 165 166 166 - pmc_write(pmc, AT91_PMC_USB, 167 - pmc_read(pmc, AT91_PMC_USB) | AT91_PMC_USBS); 167 + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS, 168 + AT91_PMC_USBS); 169 + 168 170 return 0; 169 171 } 170 172 171 173 static void at91sam9n12_clk_usb_disable(struct clk_hw *hw) 172 174 { 173 175 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 174 - struct at91_pmc *pmc = usb->pmc; 175 176 176 - pmc_write(pmc, AT91_PMC_USB, 177 - pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_USBS); 177 + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS, 0); 178 178 } 179 179 180 180 static int at91sam9n12_clk_usb_is_enabled(struct clk_hw *hw) 181 181 { 182 182 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 183 - struct at91_pmc *pmc = usb->pmc; 183 + unsigned int usbr; 184 184 185 - return !!(pmc_read(pmc, AT91_PMC_USB) & AT91_PMC_USBS); 185 + regmap_read(usb->regmap, AT91_PMC_USB, &usbr); 186 + 187 + return usbr & AT91_PMC_USBS; 186 188 } 187 189 188 190 static const struct clk_ops at91sam9n12_usb_ops = { ··· 195 197 }; 196 198 197 199 static struct clk * __init 198 - at91sam9x5_clk_register_usb(struct at91_pmc *pmc, const char *name, 200 + at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, 199 201 const char **parent_names, u8 num_parents) 200 202 { 201 203 struct at91sam9x5_clk_usb *usb; ··· 214 216 CLK_SET_RATE_PARENT; 215 217 216 218 usb->hw.init = &init; 217 - usb->pmc = pmc; 219 + usb->regmap = regmap; 218 220 219 221 clk = clk_register(NULL, &usb->hw); 220 222 if (IS_ERR(clk)) ··· 224 226 } 225 227 226 228 static struct clk * __init 227 - at91sam9n12_clk_register_usb(struct at91_pmc *pmc, const char *name, 229 + at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name, 228 230 const char *parent_name) 229 231 { 230 232 struct at91sam9x5_clk_usb *usb; ··· 242 244 init.flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT; 243 245 244 246 usb->hw.init = &init; 245 - usb->pmc = pmc; 247 + usb->regmap = regmap; 246 248 247 249 clk = clk_register(NULL, &usb->hw); 248 250 if (IS_ERR(clk)) ··· 255 257 unsigned long parent_rate) 256 258 { 257 259 struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw); 258 - struct at91_pmc *pmc = usb->pmc; 259 - u32 tmp; 260 + unsigned int pllbr; 260 261 u8 usbdiv; 261 262 262 - tmp = pmc_read(pmc, AT91_CKGR_PLLBR); 263 - usbdiv = (tmp & AT91_PMC_USBDIV) >> RM9200_USB_DIV_SHIFT; 263 + regmap_read(usb->regmap, AT91_CKGR_PLLBR, &pllbr); 264 + 265 + usbdiv = (pllbr & AT91_PMC_USBDIV) >> RM9200_USB_DIV_SHIFT; 264 266 if (usb->divisors[usbdiv]) 265 267 return parent_rate / usb->divisors[usbdiv]; 266 268 ··· 308 310 static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate, 309 311 unsigned long parent_rate) 310 312 { 311 - u32 tmp; 312 313 int i; 313 314 struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw); 314 - struct at91_pmc *pmc = usb->pmc; 315 315 unsigned long div; 316 316 317 317 if (!rate) ··· 319 323 320 324 for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) { 321 325 if (usb->divisors[i] == div) { 322 - tmp = pmc_read(pmc, AT91_CKGR_PLLBR) & 323 - ~AT91_PMC_USBDIV; 324 - tmp |= i << RM9200_USB_DIV_SHIFT; 325 - pmc_write(pmc, AT91_CKGR_PLLBR, tmp); 326 + regmap_update_bits(usb->regmap, AT91_CKGR_PLLBR, 327 + AT91_PMC_USBDIV, 328 + i << RM9200_USB_DIV_SHIFT); 329 + 326 330 return 0; 327 331 } 328 332 } ··· 337 341 }; 338 342 339 343 static struct clk * __init 340 - at91rm9200_clk_register_usb(struct at91_pmc *pmc, const char *name, 344 + at91rm9200_clk_register_usb(struct regmap *regmap, const char *name, 341 345 const char *parent_name, const u32 *divisors) 342 346 { 343 347 struct at91rm9200_clk_usb *usb; ··· 355 359 init.flags = CLK_SET_RATE_PARENT; 356 360 357 361 usb->hw.init = &init; 358 - usb->pmc = pmc; 362 + usb->regmap = regmap; 359 363 memcpy(usb->divisors, divisors, sizeof(usb->divisors)); 360 364 361 365 clk = clk_register(NULL, &usb->hw); ··· 365 369 return clk; 366 370 } 367 371 368 - void __init of_at91sam9x5_clk_usb_setup(struct device_node *np, 369 - struct at91_pmc *pmc) 372 + static void __init of_at91sam9x5_clk_usb_setup(struct device_node *np) 370 373 { 371 374 struct clk *clk; 372 375 int num_parents; 373 376 const char *parent_names[USB_SOURCE_MAX]; 374 377 const char *name = np->name; 378 + struct regmap *regmap; 375 379 376 380 num_parents = of_clk_get_parent_count(np); 377 381 if (num_parents <= 0 || num_parents > USB_SOURCE_MAX) ··· 381 385 382 386 of_property_read_string(np, "clock-output-names", &name); 383 387 384 - clk = at91sam9x5_clk_register_usb(pmc, name, parent_names, num_parents); 388 + regmap = syscon_node_to_regmap(of_get_parent(np)); 389 + if (IS_ERR(regmap)) 390 + return; 391 + 392 + clk = at91sam9x5_clk_register_usb(regmap, name, parent_names, 393 + num_parents); 385 394 if (IS_ERR(clk)) 386 395 return; 387 396 388 397 of_clk_add_provider(np, of_clk_src_simple_get, clk); 389 398 } 399 + CLK_OF_DECLARE(at91sam9x5_clk_usb, "atmel,at91sam9x5-clk-usb", 400 + of_at91sam9x5_clk_usb_setup); 390 401 391 - void __init of_at91sam9n12_clk_usb_setup(struct device_node *np, 392 - struct at91_pmc *pmc) 402 + static void __init of_at91sam9n12_clk_usb_setup(struct device_node *np) 393 403 { 394 404 struct clk *clk; 395 405 const char *parent_name; 396 406 const char *name = np->name; 407 + struct regmap *regmap; 397 408 398 409 parent_name = of_clk_get_parent_name(np, 0); 399 410 if (!parent_name) ··· 408 405 409 406 of_property_read_string(np, "clock-output-names", &name); 410 407 411 - clk = at91sam9n12_clk_register_usb(pmc, name, parent_name); 408 + regmap = syscon_node_to_regmap(of_get_parent(np)); 409 + if (IS_ERR(regmap)) 410 + return; 411 + 412 + clk = at91sam9n12_clk_register_usb(regmap, name, parent_name); 412 413 if (IS_ERR(clk)) 413 414 return; 414 415 415 416 of_clk_add_provider(np, of_clk_src_simple_get, clk); 416 417 } 418 + CLK_OF_DECLARE(at91sam9n12_clk_usb, "atmel,at91sam9n12-clk-usb", 419 + of_at91sam9n12_clk_usb_setup); 417 420 418 - void __init of_at91rm9200_clk_usb_setup(struct device_node *np, 419 - struct at91_pmc *pmc) 421 + static void __init of_at91rm9200_clk_usb_setup(struct device_node *np) 420 422 { 421 423 struct clk *clk; 422 424 const char *parent_name; 423 425 const char *name = np->name; 424 426 u32 divisors[4] = {0, 0, 0, 0}; 427 + struct regmap *regmap; 425 428 426 429 parent_name = of_clk_get_parent_name(np, 0); 427 430 if (!parent_name) ··· 439 430 440 431 of_property_read_string(np, "clock-output-names", &name); 441 432 442 - clk = at91rm9200_clk_register_usb(pmc, name, parent_name, divisors); 433 + regmap = syscon_node_to_regmap(of_get_parent(np)); 434 + if (IS_ERR(regmap)) 435 + return; 436 + 437 + clk = at91rm9200_clk_register_usb(regmap, name, parent_name, divisors); 443 438 if (IS_ERR(clk)) 444 439 return; 445 440 446 441 of_clk_add_provider(np, of_clk_src_simple_get, clk); 447 442 } 443 + CLK_OF_DECLARE(at91rm9200_clk_usb, "atmel,at91rm9200-clk-usb", 444 + of_at91rm9200_clk_usb_setup);
+30 -23
drivers/clk/at91/clk-utmi.c
··· 19 19 #include <linux/io.h> 20 20 #include <linux/sched.h> 21 21 #include <linux/wait.h> 22 + #include <linux/mfd/syscon.h> 23 + #include <linux/regmap.h> 22 24 23 25 #include "pmc.h" 24 26 ··· 28 26 29 27 struct clk_utmi { 30 28 struct clk_hw hw; 31 - struct at91_pmc *pmc; 29 + struct regmap *regmap; 32 30 unsigned int irq; 33 31 wait_queue_head_t wait; 34 32 }; ··· 45 43 return IRQ_HANDLED; 46 44 } 47 45 46 + static inline bool clk_utmi_ready(struct regmap *regmap) 47 + { 48 + unsigned int status; 49 + 50 + regmap_read(regmap, AT91_PMC_SR, &status); 51 + 52 + return status & AT91_PMC_LOCKU; 53 + } 54 + 48 55 static int clk_utmi_prepare(struct clk_hw *hw) 49 56 { 50 57 struct clk_utmi *utmi = to_clk_utmi(hw); 51 - struct at91_pmc *pmc = utmi->pmc; 52 - u32 tmp = pmc_read(pmc, AT91_CKGR_UCKR) | AT91_PMC_UPLLEN | 53 - AT91_PMC_UPLLCOUNT | AT91_PMC_BIASEN; 58 + unsigned int uckr = AT91_PMC_UPLLEN | AT91_PMC_UPLLCOUNT | 59 + AT91_PMC_BIASEN; 54 60 55 - pmc_write(pmc, AT91_CKGR_UCKR, tmp); 61 + regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, uckr, uckr); 56 62 57 - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU)) { 63 + while (!clk_utmi_ready(utmi->regmap)) { 58 64 enable_irq(utmi->irq); 59 65 wait_event(utmi->wait, 60 - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU); 66 + clk_utmi_ready(utmi->regmap)); 61 67 } 62 68 63 69 return 0; ··· 74 64 static int clk_utmi_is_prepared(struct clk_hw *hw) 75 65 { 76 66 struct clk_utmi *utmi = to_clk_utmi(hw); 77 - struct at91_pmc *pmc = utmi->pmc; 78 67 79 - return !!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU); 68 + return clk_utmi_ready(utmi->regmap); 80 69 } 81 70 82 71 static void clk_utmi_unprepare(struct clk_hw *hw) 83 72 { 84 73 struct clk_utmi *utmi = to_clk_utmi(hw); 85 - struct at91_pmc *pmc = utmi->pmc; 86 - u32 tmp = pmc_read(pmc, AT91_CKGR_UCKR) & ~AT91_PMC_UPLLEN; 87 74 88 - pmc_write(pmc, AT91_CKGR_UCKR, tmp); 75 + regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, AT91_PMC_UPLLEN, 0); 89 76 } 90 77 91 78 static unsigned long clk_utmi_recalc_rate(struct clk_hw *hw, ··· 100 93 }; 101 94 102 95 static struct clk * __init 103 - at91_clk_register_utmi(struct at91_pmc *pmc, unsigned int irq, 96 + at91_clk_register_utmi(struct regmap *regmap, unsigned int irq, 104 97 const char *name, const char *parent_name) 105 98 { 106 99 int ret; ··· 119 112 init.flags = CLK_SET_RATE_GATE; 120 113 121 114 utmi->hw.init = &init; 122 - utmi->pmc = pmc; 115 + utmi->regmap = regmap; 123 116 utmi->irq = irq; 124 117 init_waitqueue_head(&utmi->wait); 125 118 irq_set_status_flags(utmi->irq, IRQ_NOAUTOEN); ··· 139 132 return clk; 140 133 } 141 134 142 - static void __init 143 - of_at91_clk_utmi_setup(struct device_node *np, struct at91_pmc *pmc) 135 + static void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np) 144 136 { 145 137 unsigned int irq; 146 138 struct clk *clk; 147 139 const char *parent_name; 148 140 const char *name = np->name; 141 + struct regmap *regmap; 149 142 150 143 parent_name = of_clk_get_parent_name(np, 0); 151 144 ··· 155 148 if (!irq) 156 149 return; 157 150 158 - clk = at91_clk_register_utmi(pmc, irq, name, parent_name); 151 + regmap = syscon_node_to_regmap(of_get_parent(np)); 152 + if (IS_ERR(regmap)) 153 + return; 154 + 155 + clk = at91_clk_register_utmi(regmap, irq, name, parent_name); 159 156 if (IS_ERR(clk)) 160 157 return; 161 158 162 159 of_clk_add_provider(np, of_clk_src_simple_get, clk); 163 160 return; 164 161 } 165 - 166 - void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np, 167 - struct at91_pmc *pmc) 168 - { 169 - of_at91_clk_utmi_setup(np, pmc); 170 - } 162 + CLK_OF_DECLARE(at91sam9x5_clk_utmi, "atmel,at91sam9x5-clk-utmi", 163 + of_at91sam9x5_clk_utmi_setup);
+12 -143
drivers/clk/at91/pmc.c
··· 20 20 #include <linux/irqdomain.h> 21 21 #include <linux/of_irq.h> 22 22 #include <linux/mfd/syscon.h> 23 + #include <linux/regmap.h> 23 24 24 25 #include <asm/proc-fns.h> 25 26 ··· 71 70 { 72 71 struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 73 72 74 - pmc_write(pmc, AT91_PMC_IDR, 1 << d->hwirq); 73 + regmap_write(pmc->regmap, AT91_PMC_IDR, 1 << d->hwirq); 75 74 } 76 75 77 76 static void pmc_irq_unmask(struct irq_data *d) 78 77 { 79 78 struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 80 79 81 - pmc_write(pmc, AT91_PMC_IER, 1 << d->hwirq); 80 + regmap_write(pmc->regmap, AT91_PMC_IER, 1 << d->hwirq); 82 81 } 83 82 84 83 static int pmc_irq_set_type(struct irq_data *d, unsigned type) ··· 95 94 { 96 95 struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 97 96 98 - pmc->imr = pmc_read(pmc, AT91_PMC_IMR); 99 - pmc_write(pmc, AT91_PMC_IDR, pmc->imr); 97 + regmap_read(pmc->regmap, AT91_PMC_IMR, &pmc->imr); 98 + regmap_write(pmc->regmap, AT91_PMC_IDR, pmc->imr); 100 99 } 101 100 102 101 static void pmc_irq_resume(struct irq_data *d) 103 102 { 104 103 struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 105 104 106 - pmc_write(pmc, AT91_PMC_IER, pmc->imr); 105 + regmap_write(pmc->regmap, AT91_PMC_IER, pmc->imr); 107 106 } 108 107 109 108 static struct irq_chip pmc_irq = { ··· 162 161 static irqreturn_t pmc_irq_handler(int irq, void *data) 163 162 { 164 163 struct at91_pmc *pmc = (struct at91_pmc *)data; 164 + unsigned int tmpsr, imr; 165 165 unsigned long sr; 166 166 int n; 167 167 168 - sr = pmc_read(pmc, AT91_PMC_SR) & pmc_read(pmc, AT91_PMC_IMR); 168 + regmap_read(pmc->regmap, AT91_PMC_SR, &tmpsr); 169 + regmap_read(pmc->regmap, AT91_PMC_IMR, &imr); 170 + 171 + sr = tmpsr & imr; 169 172 if (!sr) 170 173 return IRQ_NONE; 171 174 ··· 244 239 if (!pmc) 245 240 return NULL; 246 241 247 - spin_lock_init(&pmc->lock); 248 242 pmc->regmap = regmap; 249 243 pmc->virq = virq; 250 244 pmc->caps = caps; 251 245 252 246 pmc->irqdomain = irq_domain_add_linear(np, 32, &pmc_irq_ops, pmc); 253 - 254 247 if (!pmc->irqdomain) 255 248 goto out_free_pmc; 256 249 257 - pmc_write(pmc, AT91_PMC_IDR, 0xffffffff); 250 + regmap_write(pmc->regmap, AT91_PMC_IDR, 0xffffffff); 258 251 if (request_irq(pmc->virq, pmc_irq_handler, 259 252 IRQF_SHARED | IRQF_COND_SUSPEND, "pmc", pmc)) 260 253 goto out_remove_irqdomain; ··· 267 264 return NULL; 268 265 } 269 266 270 - static const struct of_device_id pmc_clk_ids[] __initconst = { 271 - /* Slow oscillator */ 272 - { 273 - .compatible = "atmel,at91sam9260-clk-slow", 274 - .data = of_at91sam9260_clk_slow_setup, 275 - }, 276 - /* Main clock */ 277 - { 278 - .compatible = "atmel,at91rm9200-clk-main-osc", 279 - .data = of_at91rm9200_clk_main_osc_setup, 280 - }, 281 - { 282 - .compatible = "atmel,at91sam9x5-clk-main-rc-osc", 283 - .data = of_at91sam9x5_clk_main_rc_osc_setup, 284 - }, 285 - { 286 - .compatible = "atmel,at91rm9200-clk-main", 287 - .data = of_at91rm9200_clk_main_setup, 288 - }, 289 - { 290 - .compatible = "atmel,at91sam9x5-clk-main", 291 - .data = of_at91sam9x5_clk_main_setup, 292 - }, 293 - /* PLL clocks */ 294 - { 295 - .compatible = "atmel,at91rm9200-clk-pll", 296 - .data = of_at91rm9200_clk_pll_setup, 297 - }, 298 - { 299 - .compatible = "atmel,at91sam9g45-clk-pll", 300 - .data = of_at91sam9g45_clk_pll_setup, 301 - }, 302 - { 303 - .compatible = "atmel,at91sam9g20-clk-pllb", 304 - .data = of_at91sam9g20_clk_pllb_setup, 305 - }, 306 - { 307 - .compatible = "atmel,sama5d3-clk-pll", 308 - .data = of_sama5d3_clk_pll_setup, 309 - }, 310 - { 311 - .compatible = "atmel,at91sam9x5-clk-plldiv", 312 - .data = of_at91sam9x5_clk_plldiv_setup, 313 - }, 314 - /* Master clock */ 315 - { 316 - .compatible = "atmel,at91rm9200-clk-master", 317 - .data = of_at91rm9200_clk_master_setup, 318 - }, 319 - { 320 - .compatible = "atmel,at91sam9x5-clk-master", 321 - .data = of_at91sam9x5_clk_master_setup, 322 - }, 323 - /* System clocks */ 324 - { 325 - .compatible = "atmel,at91rm9200-clk-system", 326 - .data = of_at91rm9200_clk_sys_setup, 327 - }, 328 - /* Peripheral clocks */ 329 - { 330 - .compatible = "atmel,at91rm9200-clk-peripheral", 331 - .data = of_at91rm9200_clk_periph_setup, 332 - }, 333 - { 334 - .compatible = "atmel,at91sam9x5-clk-peripheral", 335 - .data = of_at91sam9x5_clk_periph_setup, 336 - }, 337 - /* Programmable clocks */ 338 - { 339 - .compatible = "atmel,at91rm9200-clk-programmable", 340 - .data = of_at91rm9200_clk_prog_setup, 341 - }, 342 - { 343 - .compatible = "atmel,at91sam9g45-clk-programmable", 344 - .data = of_at91sam9g45_clk_prog_setup, 345 - }, 346 - { 347 - .compatible = "atmel,at91sam9x5-clk-programmable", 348 - .data = of_at91sam9x5_clk_prog_setup, 349 - }, 350 - /* UTMI clock */ 351 - #if defined(CONFIG_HAVE_AT91_UTMI) 352 - { 353 - .compatible = "atmel,at91sam9x5-clk-utmi", 354 - .data = of_at91sam9x5_clk_utmi_setup, 355 - }, 356 - #endif 357 - /* USB clock */ 358 - #if defined(CONFIG_HAVE_AT91_USB_CLK) 359 - { 360 - .compatible = "atmel,at91rm9200-clk-usb", 361 - .data = of_at91rm9200_clk_usb_setup, 362 - }, 363 - { 364 - .compatible = "atmel,at91sam9x5-clk-usb", 365 - .data = of_at91sam9x5_clk_usb_setup, 366 - }, 367 - { 368 - .compatible = "atmel,at91sam9n12-clk-usb", 369 - .data = of_at91sam9n12_clk_usb_setup, 370 - }, 371 - #endif 372 - /* SMD clock */ 373 - #if defined(CONFIG_HAVE_AT91_SMD) 374 - { 375 - .compatible = "atmel,at91sam9x5-clk-smd", 376 - .data = of_at91sam9x5_clk_smd_setup, 377 - }, 378 - #endif 379 - #if defined(CONFIG_HAVE_AT91_H32MX) 380 - { 381 - .compatible = "atmel,sama5d4-clk-h32mx", 382 - .data = of_sama5d4_clk_h32mx_setup, 383 - }, 384 - #endif 385 - #if defined(CONFIG_HAVE_AT91_GENERATED_CLK) 386 - { 387 - .compatible = "atmel,sama5d2-clk-generated", 388 - .data = of_sama5d2_clk_generated_setup, 389 - }, 390 - #endif 391 - { /*sentinel*/ } 392 - }; 393 - 394 267 static void __init of_at91_pmc_setup(struct device_node *np, 395 268 const struct at91_pmc_caps *caps) 396 269 { 397 270 struct at91_pmc *pmc; 398 - struct device_node *childnp; 399 - void (*clk_setup)(struct device_node *, struct at91_pmc *); 400 - const struct of_device_id *clk_id; 401 271 void __iomem *regbase = of_iomap(np, 0); 402 272 struct regmap *regmap; 403 273 int virq; ··· 286 410 pmc = at91_pmc_init(np, regmap, regbase, virq, caps); 287 411 if (!pmc) 288 412 return; 289 - for_each_child_of_node(np, childnp) { 290 - clk_id = of_match_node(pmc_clk_ids, childnp); 291 - if (!clk_id) 292 - continue; 293 - clk_setup = clk_id->data; 294 - clk_setup(childnp, pmc); 295 - } 296 413 } 297 414 298 415 static void __init of_at91rm9200_pmc_setup(struct device_node *np)
+2 -87
drivers/clk/at91/pmc.h
··· 17 17 #include <linux/regmap.h> 18 18 #include <linux/spinlock.h> 19 19 20 + extern spinlock_t pmc_pcr_lock; 21 + 20 22 struct clk_range { 21 23 unsigned long min; 22 24 unsigned long max; ··· 33 31 struct at91_pmc { 34 32 struct regmap *regmap; 35 33 int virq; 36 - spinlock_t lock; 37 34 const struct at91_pmc_caps *caps; 38 35 struct irq_domain *irqdomain; 39 36 u32 imr; 40 37 }; 41 38 42 - static inline void pmc_lock(struct at91_pmc *pmc) 43 - { 44 - spin_lock(&pmc->lock); 45 - } 46 - 47 - static inline void pmc_unlock(struct at91_pmc *pmc) 48 - { 49 - spin_unlock(&pmc->lock); 50 - } 51 - 52 - static inline u32 pmc_read(struct at91_pmc *pmc, int offset) 53 - { 54 - unsigned int ret = 0; 55 - 56 - regmap_read(pmc->regmap, offset, &ret); 57 - 58 - return ret; 59 - } 60 - 61 - static inline void pmc_write(struct at91_pmc *pmc, int offset, u32 value) 62 - { 63 - regmap_write(pmc->regmap, offset, value); 64 - } 65 - 66 39 int of_at91_get_clk_range(struct device_node *np, const char *propname, 67 40 struct clk_range *range); 68 - 69 - void of_at91sam9260_clk_slow_setup(struct device_node *np, 70 - struct at91_pmc *pmc); 71 - 72 - void of_at91rm9200_clk_main_osc_setup(struct device_node *np, 73 - struct at91_pmc *pmc); 74 - void of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np, 75 - struct at91_pmc *pmc); 76 - void of_at91rm9200_clk_main_setup(struct device_node *np, 77 - struct at91_pmc *pmc); 78 - void of_at91sam9x5_clk_main_setup(struct device_node *np, 79 - struct at91_pmc *pmc); 80 - 81 - void of_at91rm9200_clk_pll_setup(struct device_node *np, 82 - struct at91_pmc *pmc); 83 - void of_at91sam9g45_clk_pll_setup(struct device_node *np, 84 - struct at91_pmc *pmc); 85 - void of_at91sam9g20_clk_pllb_setup(struct device_node *np, 86 - struct at91_pmc *pmc); 87 - void of_sama5d3_clk_pll_setup(struct device_node *np, 88 - struct at91_pmc *pmc); 89 - void of_at91sam9x5_clk_plldiv_setup(struct device_node *np, 90 - struct at91_pmc *pmc); 91 - 92 - void of_at91rm9200_clk_master_setup(struct device_node *np, 93 - struct at91_pmc *pmc); 94 - void of_at91sam9x5_clk_master_setup(struct device_node *np, 95 - struct at91_pmc *pmc); 96 - 97 - void of_at91rm9200_clk_sys_setup(struct device_node *np, 98 - struct at91_pmc *pmc); 99 - 100 - void of_at91rm9200_clk_periph_setup(struct device_node *np, 101 - struct at91_pmc *pmc); 102 - void of_at91sam9x5_clk_periph_setup(struct device_node *np, 103 - struct at91_pmc *pmc); 104 - 105 - void of_at91rm9200_clk_prog_setup(struct device_node *np, 106 - struct at91_pmc *pmc); 107 - void of_at91sam9g45_clk_prog_setup(struct device_node *np, 108 - struct at91_pmc *pmc); 109 - void of_at91sam9x5_clk_prog_setup(struct device_node *np, 110 - struct at91_pmc *pmc); 111 - 112 - void of_at91sam9x5_clk_utmi_setup(struct device_node *np, 113 - struct at91_pmc *pmc); 114 - 115 - void of_at91rm9200_clk_usb_setup(struct device_node *np, 116 - struct at91_pmc *pmc); 117 - void of_at91sam9x5_clk_usb_setup(struct device_node *np, 118 - struct at91_pmc *pmc); 119 - void of_at91sam9n12_clk_usb_setup(struct device_node *np, 120 - struct at91_pmc *pmc); 121 - 122 - void of_at91sam9x5_clk_smd_setup(struct device_node *np, 123 - struct at91_pmc *pmc); 124 - 125 - void of_sama5d4_clk_h32mx_setup(struct device_node *np, 126 - struct at91_pmc *pmc); 127 - 128 - void of_sama5d2_clk_generated_setup(struct device_node *np, 129 - struct at91_pmc *pmc); 130 41 131 42 #endif /* __PMC_H_ */