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

clk: at91: remove IRQ handling and use polling

The AT91 clock drivers make use of IRQs to avoid polling when waiting for
some clocks to be enabled. Unfortunately, this leads to a crash when those
IRQs are threaded (which happens when using preempt-rt) because they are
registered before thread creation is possible.

Use polling on those clocks instead to avoid the problem.

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

+37 -446
+15 -123
drivers/clk/at91/clk-main.c
··· 13 13 #include <linux/clk/at91_pmc.h> 14 14 #include <linux/delay.h> 15 15 #include <linux/of.h> 16 - #include <linux/of_address.h> 17 - #include <linux/of_irq.h> 18 - #include <linux/io.h> 19 - #include <linux/interrupt.h> 20 - #include <linux/irq.h> 21 16 #include <linux/mfd/syscon.h> 22 17 #include <linux/regmap.h> 23 - #include <linux/sched.h> 24 - #include <linux/wait.h> 25 18 26 19 #include "pmc.h" 27 20 ··· 30 37 struct clk_main_osc { 31 38 struct clk_hw hw; 32 39 struct regmap *regmap; 33 - unsigned int irq; 34 - wait_queue_head_t wait; 35 40 }; 36 41 37 42 #define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, hw) ··· 37 46 struct clk_main_rc_osc { 38 47 struct clk_hw hw; 39 48 struct regmap *regmap; 40 - unsigned int irq; 41 - wait_queue_head_t wait; 42 49 unsigned long frequency; 43 50 unsigned long accuracy; 44 51 }; ··· 53 64 struct clk_sam9x5_main { 54 65 struct clk_hw hw; 55 66 struct regmap *regmap; 56 - unsigned int irq; 57 - wait_queue_head_t wait; 58 67 u8 parent; 59 68 }; 60 69 61 70 #define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, hw) 62 - 63 - static irqreturn_t clk_main_osc_irq_handler(int irq, void *dev_id) 64 - { 65 - struct clk_main_osc *osc = dev_id; 66 - 67 - wake_up(&osc->wait); 68 - disable_irq_nosync(osc->irq); 69 - 70 - return IRQ_HANDLED; 71 - } 72 71 73 72 static inline bool clk_main_osc_ready(struct regmap *regmap) 74 73 { ··· 84 107 regmap_write(regmap, AT91_CKGR_MOR, tmp); 85 108 } 86 109 87 - while (!clk_main_osc_ready(regmap)) { 88 - enable_irq(osc->irq); 89 - wait_event(osc->wait, 90 - clk_main_osc_ready(regmap)); 91 - } 110 + while (!clk_main_osc_ready(regmap)) 111 + cpu_relax(); 92 112 93 113 return 0; 94 114 } ··· 130 156 131 157 static struct clk * __init 132 158 at91_clk_register_main_osc(struct regmap *regmap, 133 - unsigned int irq, 134 159 const char *name, 135 160 const char *parent_name, 136 161 bool bypass) 137 162 { 138 - int ret; 139 163 struct clk_main_osc *osc; 140 164 struct clk *clk = NULL; 141 165 struct clk_init_data init; 142 166 143 - if (!irq || !name || !parent_name) 167 + if (!name || !parent_name) 144 168 return ERR_PTR(-EINVAL); 145 169 146 170 osc = kzalloc(sizeof(*osc), GFP_KERNEL); ··· 153 181 154 182 osc->hw.init = &init; 155 183 osc->regmap = regmap; 156 - osc->irq = irq; 157 - 158 - init_waitqueue_head(&osc->wait); 159 - irq_set_status_flags(osc->irq, IRQ_NOAUTOEN); 160 - ret = request_irq(osc->irq, clk_main_osc_irq_handler, 161 - IRQF_TRIGGER_HIGH, name, osc); 162 - if (ret) { 163 - kfree(osc); 164 - return ERR_PTR(ret); 165 - } 166 184 167 185 if (bypass) 168 186 regmap_update_bits(regmap, ··· 161 199 AT91_PMC_OSCBYPASS | AT91_PMC_KEY); 162 200 163 201 clk = clk_register(NULL, &osc->hw); 164 - if (IS_ERR(clk)) { 165 - free_irq(irq, osc); 202 + if (IS_ERR(clk)) 166 203 kfree(osc); 167 - } 168 204 169 205 return clk; 170 206 } ··· 170 210 static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np) 171 211 { 172 212 struct clk *clk; 173 - unsigned int irq; 174 213 const char *name = np->name; 175 214 const char *parent_name; 176 215 struct regmap *regmap; ··· 183 224 if (IS_ERR(regmap)) 184 225 return; 185 226 186 - irq = irq_of_parse_and_map(np, 0); 187 - if (!irq) 188 - return; 189 - 190 - clk = at91_clk_register_main_osc(regmap, irq, name, parent_name, bypass); 227 + clk = at91_clk_register_main_osc(regmap, name, parent_name, bypass); 191 228 if (IS_ERR(clk)) 192 229 return; 193 230 ··· 191 236 } 192 237 CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc", 193 238 of_at91rm9200_clk_main_osc_setup); 194 - 195 - static irqreturn_t clk_main_rc_osc_irq_handler(int irq, void *dev_id) 196 - { 197 - struct clk_main_rc_osc *osc = dev_id; 198 - 199 - wake_up(&osc->wait); 200 - disable_irq_nosync(osc->irq); 201 - 202 - return IRQ_HANDLED; 203 - } 204 239 205 240 static bool clk_main_rc_osc_ready(struct regmap *regmap) 206 241 { ··· 214 269 MOR_KEY_MASK | AT91_PMC_MOSCRCEN, 215 270 AT91_PMC_MOSCRCEN | AT91_PMC_KEY); 216 271 217 - while (!clk_main_rc_osc_ready(regmap)) { 218 - enable_irq(osc->irq); 219 - wait_event(osc->wait, 220 - clk_main_rc_osc_ready(regmap)); 221 - } 272 + while (!clk_main_rc_osc_ready(regmap)) 273 + cpu_relax(); 222 274 223 275 return 0; 224 276 } ··· 273 331 274 332 static struct clk * __init 275 333 at91_clk_register_main_rc_osc(struct regmap *regmap, 276 - unsigned int irq, 277 334 const char *name, 278 335 u32 frequency, u32 accuracy) 279 336 { 280 - int ret; 281 337 struct clk_main_rc_osc *osc; 282 338 struct clk *clk = NULL; 283 339 struct clk_init_data init; ··· 295 355 296 356 osc->hw.init = &init; 297 357 osc->regmap = regmap; 298 - osc->irq = irq; 299 358 osc->frequency = frequency; 300 359 osc->accuracy = accuracy; 301 360 302 - init_waitqueue_head(&osc->wait); 303 - irq_set_status_flags(osc->irq, IRQ_NOAUTOEN); 304 - ret = request_irq(osc->irq, clk_main_rc_osc_irq_handler, 305 - IRQF_TRIGGER_HIGH, name, osc); 306 - if (ret) 307 - return ERR_PTR(ret); 308 - 309 361 clk = clk_register(NULL, &osc->hw); 310 - if (IS_ERR(clk)) { 311 - free_irq(irq, osc); 362 + if (IS_ERR(clk)) 312 363 kfree(osc); 313 - } 314 364 315 365 return clk; 316 366 } ··· 308 378 static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np) 309 379 { 310 380 struct clk *clk; 311 - unsigned int irq; 312 381 u32 frequency = 0; 313 382 u32 accuracy = 0; 314 383 const char *name = np->name; ··· 317 388 of_property_read_u32(np, "clock-frequency", &frequency); 318 389 of_property_read_u32(np, "clock-accuracy", &accuracy); 319 390 320 - irq = irq_of_parse_and_map(np, 0); 321 - if (!irq) 322 - return; 323 - 324 391 regmap = syscon_node_to_regmap(of_get_parent(np)); 325 392 if (IS_ERR(regmap)) 326 393 return; 327 394 328 - clk = at91_clk_register_main_rc_osc(regmap, irq, name, frequency, 329 - accuracy); 395 + clk = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy); 330 396 if (IS_ERR(clk)) 331 397 return; 332 398 ··· 453 529 CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main", 454 530 of_at91rm9200_clk_main_setup); 455 531 456 - static irqreturn_t clk_sam9x5_main_irq_handler(int irq, void *dev_id) 457 - { 458 - struct clk_sam9x5_main *clkmain = dev_id; 459 - 460 - wake_up(&clkmain->wait); 461 - disable_irq_nosync(clkmain->irq); 462 - 463 - return IRQ_HANDLED; 464 - } 465 - 466 532 static inline bool clk_sam9x5_main_ready(struct regmap *regmap) 467 533 { 468 534 unsigned int status; ··· 467 553 struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw); 468 554 struct regmap *regmap = clkmain->regmap; 469 555 470 - while (!clk_sam9x5_main_ready(regmap)) { 471 - enable_irq(clkmain->irq); 472 - wait_event(clkmain->wait, 473 - clk_sam9x5_main_ready(regmap)); 474 - } 556 + while (!clk_sam9x5_main_ready(regmap)) 557 + cpu_relax(); 475 558 476 559 return clk_main_probe_frequency(regmap); 477 560 } ··· 505 594 else if (!index && (tmp & AT91_PMC_MOSCSEL)) 506 595 regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL); 507 596 508 - while (!clk_sam9x5_main_ready(regmap)) { 509 - enable_irq(clkmain->irq); 510 - wait_event(clkmain->wait, 511 - clk_sam9x5_main_ready(regmap)); 512 - } 597 + while (!clk_sam9x5_main_ready(regmap)) 598 + cpu_relax(); 513 599 514 600 return 0; 515 601 } ··· 531 623 532 624 static struct clk * __init 533 625 at91_clk_register_sam9x5_main(struct regmap *regmap, 534 - unsigned int irq, 535 626 const char *name, 536 627 const char **parent_names, 537 628 int num_parents) 538 629 { 539 - int ret; 540 630 struct clk_sam9x5_main *clkmain; 541 631 struct clk *clk = NULL; 542 632 struct clk_init_data init; ··· 558 652 559 653 clkmain->hw.init = &init; 560 654 clkmain->regmap = regmap; 561 - clkmain->irq = irq; 562 655 regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status); 563 656 clkmain->parent = status & AT91_PMC_MOSCEN ? 1 : 0; 564 - init_waitqueue_head(&clkmain->wait); 565 - irq_set_status_flags(clkmain->irq, IRQ_NOAUTOEN); 566 - ret = request_irq(clkmain->irq, clk_sam9x5_main_irq_handler, 567 - IRQF_TRIGGER_HIGH, name, clkmain); 568 - if (ret) 569 - return ERR_PTR(ret); 570 657 571 658 clk = clk_register(NULL, &clkmain->hw); 572 - if (IS_ERR(clk)) { 573 - free_irq(clkmain->irq, clkmain); 659 + if (IS_ERR(clk)) 574 660 kfree(clkmain); 575 - } 576 661 577 662 return clk; 578 663 } ··· 573 676 struct clk *clk; 574 677 const char *parent_names[2]; 575 678 int num_parents; 576 - unsigned int irq; 577 679 const char *name = np->name; 578 680 struct regmap *regmap; 579 681 ··· 587 691 588 692 of_property_read_string(np, "clock-output-names", &name); 589 693 590 - irq = irq_of_parse_and_map(np, 0); 591 - if (!irq) 592 - return; 593 - 594 - clk = at91_clk_register_sam9x5_main(regmap, irq, name, parent_names, 694 + clk = at91_clk_register_sam9x5_main(regmap, name, parent_names, 595 695 num_parents); 596 696 if (IS_ERR(clk)) 597 697 return;
+4 -42
drivers/clk/at91/clk-master.c
··· 12 12 #include <linux/clkdev.h> 13 13 #include <linux/clk/at91_pmc.h> 14 14 #include <linux/of.h> 15 - #include <linux/of_address.h> 16 - #include <linux/of_irq.h> 17 - #include <linux/io.h> 18 - #include <linux/wait.h> 19 - #include <linux/sched.h> 20 - #include <linux/interrupt.h> 21 - #include <linux/irq.h> 22 15 #include <linux/mfd/syscon.h> 23 16 #include <linux/regmap.h> 24 17 ··· 40 47 struct clk_master { 41 48 struct clk_hw hw; 42 49 struct regmap *regmap; 43 - unsigned int irq; 44 - wait_queue_head_t wait; 45 50 const struct clk_master_layout *layout; 46 51 const struct clk_master_characteristics *characteristics; 47 52 }; 48 - 49 - static irqreturn_t clk_master_irq_handler(int irq, void *dev_id) 50 - { 51 - struct clk_master *master = (struct clk_master *)dev_id; 52 - 53 - wake_up(&master->wait); 54 - disable_irq_nosync(master->irq); 55 - 56 - return IRQ_HANDLED; 57 - } 58 53 59 54 static inline bool clk_master_ready(struct regmap *regmap) 60 55 { ··· 57 76 { 58 77 struct clk_master *master = to_clk_master(hw); 59 78 60 - while (!clk_master_ready(master->regmap)) { 61 - enable_irq(master->irq); 62 - wait_event(master->wait, 63 - clk_master_ready(master->regmap)); 64 - } 79 + while (!clk_master_ready(master->regmap)) 80 + cpu_relax(); 65 81 66 82 return 0; 67 83 } ··· 121 143 }; 122 144 123 145 static struct clk * __init 124 - at91_clk_register_master(struct regmap *regmap, unsigned int irq, 146 + at91_clk_register_master(struct regmap *regmap, 125 147 const char *name, int num_parents, 126 148 const char **parent_names, 127 149 const struct clk_master_layout *layout, 128 150 const struct clk_master_characteristics *characteristics) 129 151 { 130 - int ret; 131 152 struct clk_master *master; 132 153 struct clk *clk = NULL; 133 154 struct clk_init_data init; ··· 148 171 master->layout = layout; 149 172 master->characteristics = characteristics; 150 173 master->regmap = regmap; 151 - master->irq = irq; 152 - init_waitqueue_head(&master->wait); 153 - irq_set_status_flags(master->irq, IRQ_NOAUTOEN); 154 - ret = request_irq(master->irq, clk_master_irq_handler, 155 - IRQF_TRIGGER_HIGH, "clk-master", master); 156 - if (ret) { 157 - kfree(master); 158 - return ERR_PTR(ret); 159 - } 160 174 161 175 clk = clk_register(NULL, &master->hw); 162 176 if (IS_ERR(clk)) { 163 - free_irq(master->irq, master); 164 177 kfree(master); 165 178 } 166 179 ··· 200 233 { 201 234 struct clk *clk; 202 235 int num_parents; 203 - unsigned int irq; 204 236 const char *parent_names[MASTER_SOURCE_MAX]; 205 237 const char *name = np->name; 206 238 struct clk_master_characteristics *characteristics; ··· 221 255 if (IS_ERR(regmap)) 222 256 return; 223 257 224 - irq = irq_of_parse_and_map(np, 0); 225 - if (!irq) 226 - goto out_free_characteristics; 227 - 228 - clk = at91_clk_register_master(regmap, irq, name, num_parents, 258 + clk = at91_clk_register_master(regmap, name, num_parents, 229 259 parent_names, layout, 230 260 characteristics); 231 261 if (IS_ERR(clk))
+4 -43
drivers/clk/at91/clk-pll.c
··· 12 12 #include <linux/clkdev.h> 13 13 #include <linux/clk/at91_pmc.h> 14 14 #include <linux/of.h> 15 - #include <linux/of_address.h> 16 - #include <linux/of_irq.h> 17 - #include <linux/io.h> 18 - #include <linux/kernel.h> 19 - #include <linux/wait.h> 20 - #include <linux/sched.h> 21 - #include <linux/interrupt.h> 22 - #include <linux/irq.h> 23 15 #include <linux/mfd/syscon.h> 24 16 #include <linux/regmap.h> 25 17 ··· 53 61 struct clk_pll { 54 62 struct clk_hw hw; 55 63 struct regmap *regmap; 56 - unsigned int irq; 57 - wait_queue_head_t wait; 58 64 u8 id; 59 65 u8 div; 60 66 u8 range; ··· 60 70 const struct clk_pll_layout *layout; 61 71 const struct clk_pll_characteristics *characteristics; 62 72 }; 63 - 64 - static irqreturn_t clk_pll_irq_handler(int irq, void *dev_id) 65 - { 66 - struct clk_pll *pll = (struct clk_pll *)dev_id; 67 - 68 - wake_up(&pll->wait); 69 - disable_irq_nosync(pll->irq); 70 - 71 - return IRQ_HANDLED; 72 - } 73 73 74 74 static inline bool clk_pll_ready(struct regmap *regmap, int id) 75 75 { ··· 107 127 (out << PLL_OUT_SHIFT) | 108 128 ((pll->mul & layout->mul_mask) << layout->mul_shift)); 109 129 110 - while (!clk_pll_ready(regmap, pll->id)) { 111 - enable_irq(pll->irq); 112 - wait_event(pll->wait, 113 - clk_pll_ready(regmap, pll->id)); 114 - } 130 + while (!clk_pll_ready(regmap, pll->id)) 131 + cpu_relax(); 115 132 116 133 return 0; 117 134 } ··· 297 320 }; 298 321 299 322 static struct clk * __init 300 - at91_clk_register_pll(struct regmap *regmap, unsigned int irq, const char *name, 323 + at91_clk_register_pll(struct regmap *regmap, const char *name, 301 324 const char *parent_name, u8 id, 302 325 const struct clk_pll_layout *layout, 303 326 const struct clk_pll_characteristics *characteristics) ··· 305 328 struct clk_pll *pll; 306 329 struct clk *clk = NULL; 307 330 struct clk_init_data init; 308 - int ret; 309 331 int offset = PLL_REG(id); 310 332 unsigned int pllr; 311 333 ··· 326 350 pll->layout = layout; 327 351 pll->characteristics = characteristics; 328 352 pll->regmap = regmap; 329 - pll->irq = irq; 330 353 regmap_read(regmap, offset, &pllr); 331 354 pll->div = PLL_DIV(pllr); 332 355 pll->mul = PLL_MUL(pllr, layout); 333 - init_waitqueue_head(&pll->wait); 334 - irq_set_status_flags(pll->irq, IRQ_NOAUTOEN); 335 - ret = request_irq(pll->irq, clk_pll_irq_handler, IRQF_TRIGGER_HIGH, 336 - id ? "clk-pllb" : "clk-plla", pll); 337 - if (ret) { 338 - kfree(pll); 339 - return ERR_PTR(ret); 340 - } 341 356 342 357 clk = clk_register(NULL, &pll->hw); 343 358 if (IS_ERR(clk)) { 344 - free_irq(pll->irq, pll); 345 359 kfree(pll); 346 360 } 347 361 ··· 465 499 const struct clk_pll_layout *layout) 466 500 { 467 501 u32 id; 468 - unsigned int irq; 469 502 struct clk *clk; 470 503 struct regmap *regmap; 471 504 const char *parent_name; ··· 486 521 if (!characteristics) 487 522 return; 488 523 489 - irq = irq_of_parse_and_map(np, 0); 490 - if (!irq) 491 - return; 492 - 493 - clk = at91_clk_register_pll(regmap, irq, name, parent_name, id, layout, 524 + clk = at91_clk_register_pll(regmap, name, parent_name, id, layout, 494 525 characteristics); 495 526 if (IS_ERR(clk)) 496 527 goto out_free_characteristics;
+6 -50
drivers/clk/at91/clk-system.c
··· 12 12 #include <linux/clkdev.h> 13 13 #include <linux/clk/at91_pmc.h> 14 14 #include <linux/of.h> 15 - #include <linux/of_address.h> 16 - #include <linux/io.h> 17 - #include <linux/irq.h> 18 - #include <linux/of_irq.h> 19 - #include <linux/interrupt.h> 20 - #include <linux/wait.h> 21 - #include <linux/sched.h> 22 15 #include <linux/mfd/syscon.h> 23 16 #include <linux/regmap.h> 24 17 ··· 25 32 struct clk_system { 26 33 struct clk_hw hw; 27 34 struct regmap *regmap; 28 - unsigned int irq; 29 - wait_queue_head_t wait; 30 35 u8 id; 31 36 }; 32 37 33 38 static inline int is_pck(int id) 34 39 { 35 40 return (id >= 8) && (id <= 15); 36 - } 37 - static irqreturn_t clk_system_irq_handler(int irq, void *dev_id) 38 - { 39 - struct clk_system *sys = (struct clk_system *)dev_id; 40 - 41 - wake_up(&sys->wait); 42 - disable_irq_nosync(sys->irq); 43 - 44 - return IRQ_HANDLED; 45 41 } 46 42 47 43 static inline bool clk_system_ready(struct regmap *regmap, int id) ··· 51 69 if (!is_pck(sys->id)) 52 70 return 0; 53 71 54 - while (!clk_system_ready(sys->regmap, sys->id)) { 55 - if (sys->irq) { 56 - enable_irq(sys->irq); 57 - wait_event(sys->wait, 58 - clk_system_ready(sys->regmap, sys->id)); 59 - } else { 60 - cpu_relax(); 61 - } 62 - } 72 + while (!clk_system_ready(sys->regmap, sys->id)) 73 + cpu_relax(); 74 + 63 75 return 0; 64 76 } 65 77 ··· 90 114 91 115 static struct clk * __init 92 116 at91_clk_register_system(struct regmap *regmap, const char *name, 93 - const char *parent_name, u8 id, int irq) 117 + const char *parent_name, u8 id) 94 118 { 95 119 struct clk_system *sys; 96 120 struct clk *clk = NULL; 97 121 struct clk_init_data init; 98 - int ret; 99 122 100 123 if (!parent_name || id > SYSTEM_MAX_ID) 101 124 return ERR_PTR(-EINVAL); ··· 112 137 sys->id = id; 113 138 sys->hw.init = &init; 114 139 sys->regmap = regmap; 115 - sys->irq = irq; 116 - if (irq) { 117 - init_waitqueue_head(&sys->wait); 118 - irq_set_status_flags(sys->irq, IRQ_NOAUTOEN); 119 - ret = request_irq(sys->irq, clk_system_irq_handler, 120 - IRQF_TRIGGER_HIGH, name, sys); 121 - if (ret) { 122 - kfree(sys); 123 - return ERR_PTR(ret); 124 - } 125 - } 126 140 127 141 clk = clk_register(NULL, &sys->hw); 128 - if (IS_ERR(clk)) { 129 - if (irq) 130 - free_irq(sys->irq, sys); 142 + if (IS_ERR(clk)) 131 143 kfree(sys); 132 - } 133 144 134 145 return clk; 135 146 } ··· 123 162 static void __init of_at91rm9200_clk_sys_setup(struct device_node *np) 124 163 { 125 164 int num; 126 - int irq = 0; 127 165 u32 id; 128 166 struct clk *clk; 129 167 const char *name; ··· 145 185 if (of_property_read_string(np, "clock-output-names", &name)) 146 186 name = sysclknp->name; 147 187 148 - if (is_pck(id)) 149 - irq = irq_of_parse_and_map(sysclknp, 0); 150 - 151 188 parent_name = of_clk_get_parent_name(sysclknp, 0); 152 189 153 - clk = at91_clk_register_system(regmap, name, parent_name, id, 154 - irq); 190 + clk = at91_clk_register_system(regmap, name, parent_name, id); 155 191 if (IS_ERR(clk)) 156 192 continue; 157 193
+5 -44
drivers/clk/at91/clk-utmi.c
··· 11 11 #include <linux/clk-provider.h> 12 12 #include <linux/clkdev.h> 13 13 #include <linux/clk/at91_pmc.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/irq.h> 16 14 #include <linux/of.h> 17 - #include <linux/of_address.h> 18 - #include <linux/of_irq.h> 19 - #include <linux/io.h> 20 - #include <linux/sched.h> 21 - #include <linux/wait.h> 22 15 #include <linux/mfd/syscon.h> 23 16 #include <linux/regmap.h> 24 17 ··· 22 29 struct clk_utmi { 23 30 struct clk_hw hw; 24 31 struct regmap *regmap; 25 - unsigned int irq; 26 - wait_queue_head_t wait; 27 32 }; 28 33 29 34 #define to_clk_utmi(hw) container_of(hw, struct clk_utmi, hw) 30 - 31 - static irqreturn_t clk_utmi_irq_handler(int irq, void *dev_id) 32 - { 33 - struct clk_utmi *utmi = (struct clk_utmi *)dev_id; 34 - 35 - wake_up(&utmi->wait); 36 - disable_irq_nosync(utmi->irq); 37 - 38 - return IRQ_HANDLED; 39 - } 40 35 41 36 static inline bool clk_utmi_ready(struct regmap *regmap) 42 37 { ··· 43 62 44 63 regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, uckr, uckr); 45 64 46 - while (!clk_utmi_ready(utmi->regmap)) { 47 - enable_irq(utmi->irq); 48 - wait_event(utmi->wait, 49 - clk_utmi_ready(utmi->regmap)); 50 - } 65 + while (!clk_utmi_ready(utmi->regmap)) 66 + cpu_relax(); 51 67 52 68 return 0; 53 69 } ··· 78 100 }; 79 101 80 102 static struct clk * __init 81 - at91_clk_register_utmi(struct regmap *regmap, unsigned int irq, 103 + at91_clk_register_utmi(struct regmap *regmap, 82 104 const char *name, const char *parent_name) 83 105 { 84 - int ret; 85 106 struct clk_utmi *utmi; 86 107 struct clk *clk = NULL; 87 108 struct clk_init_data init; ··· 97 120 98 121 utmi->hw.init = &init; 99 122 utmi->regmap = regmap; 100 - utmi->irq = irq; 101 - init_waitqueue_head(&utmi->wait); 102 - irq_set_status_flags(utmi->irq, IRQ_NOAUTOEN); 103 - ret = request_irq(utmi->irq, clk_utmi_irq_handler, 104 - IRQF_TRIGGER_HIGH, "clk-utmi", utmi); 105 - if (ret) { 106 - kfree(utmi); 107 - return ERR_PTR(ret); 108 - } 109 123 110 124 clk = clk_register(NULL, &utmi->hw); 111 - if (IS_ERR(clk)) { 112 - free_irq(utmi->irq, utmi); 125 + if (IS_ERR(clk)) 113 126 kfree(utmi); 114 - } 115 127 116 128 return clk; 117 129 } 118 130 119 131 static void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np) 120 132 { 121 - unsigned int irq; 122 133 struct clk *clk; 123 134 const char *parent_name; 124 135 const char *name = np->name; ··· 116 151 117 152 of_property_read_string(np, "clock-output-names", &name); 118 153 119 - irq = irq_of_parse_and_map(np, 0); 120 - if (!irq) 121 - return; 122 - 123 154 regmap = syscon_node_to_regmap(of_get_parent(np)); 124 155 if (IS_ERR(regmap)) 125 156 return; 126 157 127 - clk = at91_clk_register_utmi(regmap, irq, name, parent_name); 158 + clk = at91_clk_register_utmi(regmap, name, parent_name); 128 159 if (IS_ERR(clk)) 129 160 return; 130 161
+3 -141
drivers/clk/at91/pmc.c
··· 13 13 #include <linux/clk/at91_pmc.h> 14 14 #include <linux/of.h> 15 15 #include <linux/of_address.h> 16 - #include <linux/io.h> 17 - #include <linux/interrupt.h> 18 - #include <linux/irq.h> 19 - #include <linux/irqchip/chained_irq.h> 20 - #include <linux/irqdomain.h> 21 - #include <linux/of_irq.h> 22 16 #include <linux/mfd/syscon.h> 23 17 #include <linux/regmap.h> 24 18 ··· 60 66 return 0; 61 67 } 62 68 EXPORT_SYMBOL_GPL(of_at91_get_clk_range); 63 - 64 - static void pmc_irq_mask(struct irq_data *d) 65 - { 66 - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 67 - 68 - regmap_write(pmc->regmap, AT91_PMC_IDR, 1 << d->hwirq); 69 - } 70 - 71 - static void pmc_irq_unmask(struct irq_data *d) 72 - { 73 - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 74 - 75 - regmap_write(pmc->regmap, AT91_PMC_IER, 1 << d->hwirq); 76 - } 77 - 78 - static int pmc_irq_set_type(struct irq_data *d, unsigned type) 79 - { 80 - if (type != IRQ_TYPE_LEVEL_HIGH) { 81 - pr_warn("PMC: type not supported (support only IRQ_TYPE_LEVEL_HIGH type)\n"); 82 - return -EINVAL; 83 - } 84 - 85 - return 0; 86 - } 87 - 88 - static void pmc_irq_suspend(struct irq_data *d) 89 - { 90 - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 91 - 92 - regmap_read(pmc->regmap, AT91_PMC_IMR, &pmc->imr); 93 - regmap_write(pmc->regmap, AT91_PMC_IDR, pmc->imr); 94 - } 95 - 96 - static void pmc_irq_resume(struct irq_data *d) 97 - { 98 - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d); 99 - 100 - regmap_write(pmc->regmap, AT91_PMC_IER, pmc->imr); 101 - } 102 - 103 - static struct irq_chip pmc_irq = { 104 - .name = "PMC", 105 - .irq_disable = pmc_irq_mask, 106 - .irq_mask = pmc_irq_mask, 107 - .irq_unmask = pmc_irq_unmask, 108 - .irq_set_type = pmc_irq_set_type, 109 - .irq_suspend = pmc_irq_suspend, 110 - .irq_resume = pmc_irq_resume, 111 - }; 112 - 113 - static struct lock_class_key pmc_lock_class; 114 - 115 - static int pmc_irq_map(struct irq_domain *h, unsigned int virq, 116 - irq_hw_number_t hw) 117 - { 118 - struct at91_pmc *pmc = h->host_data; 119 - 120 - irq_set_lockdep_class(virq, &pmc_lock_class); 121 - 122 - irq_set_chip_and_handler(virq, &pmc_irq, 123 - handle_level_irq); 124 - irq_set_chip_data(virq, pmc); 125 - 126 - return 0; 127 - } 128 - 129 - static int pmc_irq_domain_xlate(struct irq_domain *d, 130 - struct device_node *ctrlr, 131 - const u32 *intspec, unsigned int intsize, 132 - irq_hw_number_t *out_hwirq, 133 - unsigned int *out_type) 134 - { 135 - struct at91_pmc *pmc = d->host_data; 136 - const struct at91_pmc_caps *caps = pmc->caps; 137 - 138 - if (WARN_ON(intsize < 1)) 139 - return -EINVAL; 140 - 141 - *out_hwirq = intspec[0]; 142 - 143 - if (!(caps->available_irqs & (1 << *out_hwirq))) 144 - return -EINVAL; 145 - 146 - *out_type = IRQ_TYPE_LEVEL_HIGH; 147 - 148 - return 0; 149 - } 150 - 151 - static const struct irq_domain_ops pmc_irq_ops = { 152 - .map = pmc_irq_map, 153 - .xlate = pmc_irq_domain_xlate, 154 - }; 155 - 156 - static irqreturn_t pmc_irq_handler(int irq, void *data) 157 - { 158 - struct at91_pmc *pmc = (struct at91_pmc *)data; 159 - unsigned int tmpsr, imr; 160 - unsigned long sr; 161 - int n; 162 - 163 - regmap_read(pmc->regmap, AT91_PMC_SR, &tmpsr); 164 - regmap_read(pmc->regmap, AT91_PMC_IMR, &imr); 165 - 166 - sr = tmpsr & imr; 167 - if (!sr) 168 - return IRQ_NONE; 169 - 170 - for_each_set_bit(n, &sr, BITS_PER_LONG) 171 - generic_handle_irq(irq_find_mapping(pmc->irqdomain, n)); 172 - 173 - return IRQ_HANDLED; 174 - } 175 69 176 70 static const struct at91_pmc_caps at91rm9200_caps = { 177 71 .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB | ··· 112 230 113 231 static struct at91_pmc *__init at91_pmc_init(struct device_node *np, 114 232 struct regmap *regmap, 115 - void __iomem *regbase, int virq, 233 + void __iomem *regbase, 116 234 const struct at91_pmc_caps *caps) 117 235 { 118 236 struct at91_pmc *pmc; 119 237 120 - if (!regbase || !virq || !caps) 238 + if (!regbase || !caps) 121 239 return NULL; 122 240 123 241 at91_pmc_base = regbase; ··· 127 245 return NULL; 128 246 129 247 pmc->regmap = regmap; 130 - pmc->virq = virq; 131 248 pmc->caps = caps; 132 249 133 - pmc->irqdomain = irq_domain_add_linear(np, 32, &pmc_irq_ops, pmc); 134 - if (!pmc->irqdomain) 135 - goto out_free_pmc; 136 - 137 250 regmap_write(pmc->regmap, AT91_PMC_IDR, 0xffffffff); 138 - if (request_irq(pmc->virq, pmc_irq_handler, 139 - IRQF_SHARED | IRQF_COND_SUSPEND, "pmc", pmc)) 140 - goto out_remove_irqdomain; 141 251 142 252 return pmc; 143 - 144 - out_remove_irqdomain: 145 - irq_domain_remove(pmc->irqdomain); 146 - out_free_pmc: 147 - kfree(pmc); 148 - 149 - return NULL; 150 253 } 151 254 152 255 static void __init of_at91_pmc_setup(struct device_node *np, ··· 140 273 struct at91_pmc *pmc; 141 274 void __iomem *regbase = of_iomap(np, 0); 142 275 struct regmap *regmap; 143 - int virq; 144 276 145 277 regmap = syscon_node_to_regmap(np); 146 278 if (IS_ERR(regmap)) 147 279 panic("Could not retrieve syscon regmap"); 148 280 149 - virq = irq_of_parse_and_map(np, 0); 150 - if (!virq) 151 - return; 152 - 153 - pmc = at91_pmc_init(np, regmap, regbase, virq, caps); 281 + pmc = at91_pmc_init(np, regmap, regbase, caps); 154 282 if (!pmc) 155 283 return; 156 284 }
-3
drivers/clk/at91/pmc.h
··· 32 32 33 33 struct at91_pmc { 34 34 struct regmap *regmap; 35 - int virq; 36 35 const struct at91_pmc_caps *caps; 37 - struct irq_domain *irqdomain; 38 - u32 imr; 39 36 }; 40 37 41 38 int of_at91_get_clk_range(struct device_node *np, const char *propname,