| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 6 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | | - * (at your option) any later version. |
|---|
| 8 | | - * |
|---|
| 9 | 4 | */ |
|---|
| 10 | 5 | |
|---|
| 11 | 6 | #include <linux/clk-provider.h> |
|---|
| 12 | 7 | #include <linux/clkdev.h> |
|---|
| 13 | 8 | #include <linux/clk/at91_pmc.h> |
|---|
| 14 | 9 | #include <linux/delay.h> |
|---|
| 15 | | -#include <linux/of.h> |
|---|
| 16 | 10 | #include <linux/mfd/syscon.h> |
|---|
| 17 | 11 | #include <linux/regmap.h> |
|---|
| 18 | 12 | |
|---|
| .. | .. |
|---|
| 132 | 126 | .is_prepared = clk_main_osc_is_prepared, |
|---|
| 133 | 127 | }; |
|---|
| 134 | 128 | |
|---|
| 135 | | -static struct clk_hw * __init |
|---|
| 129 | +struct clk_hw * __init |
|---|
| 136 | 130 | at91_clk_register_main_osc(struct regmap *regmap, |
|---|
| 137 | 131 | const char *name, |
|---|
| 138 | 132 | const char *parent_name, |
|---|
| 139 | 133 | bool bypass) |
|---|
| 140 | 134 | { |
|---|
| 141 | 135 | struct clk_main_osc *osc; |
|---|
| 142 | | - struct clk_init_data init = {}; |
|---|
| 136 | + struct clk_init_data init; |
|---|
| 143 | 137 | struct clk_hw *hw; |
|---|
| 144 | 138 | int ret; |
|---|
| 145 | 139 | |
|---|
| .. | .. |
|---|
| 175 | 169 | return hw; |
|---|
| 176 | 170 | } |
|---|
| 177 | 171 | |
|---|
| 178 | | -static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np) |
|---|
| 179 | | -{ |
|---|
| 180 | | - struct clk_hw *hw; |
|---|
| 181 | | - const char *name = np->name; |
|---|
| 182 | | - const char *parent_name; |
|---|
| 183 | | - struct regmap *regmap; |
|---|
| 184 | | - bool bypass; |
|---|
| 185 | | - |
|---|
| 186 | | - of_property_read_string(np, "clock-output-names", &name); |
|---|
| 187 | | - bypass = of_property_read_bool(np, "atmel,osc-bypass"); |
|---|
| 188 | | - parent_name = of_clk_get_parent_name(np, 0); |
|---|
| 189 | | - |
|---|
| 190 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
|---|
| 191 | | - if (IS_ERR(regmap)) |
|---|
| 192 | | - return; |
|---|
| 193 | | - |
|---|
| 194 | | - hw = at91_clk_register_main_osc(regmap, name, parent_name, bypass); |
|---|
| 195 | | - if (IS_ERR(hw)) |
|---|
| 196 | | - return; |
|---|
| 197 | | - |
|---|
| 198 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
|---|
| 199 | | -} |
|---|
| 200 | | -CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc", |
|---|
| 201 | | - of_at91rm9200_clk_main_osc_setup); |
|---|
| 202 | | - |
|---|
| 203 | 172 | static bool clk_main_rc_osc_ready(struct regmap *regmap) |
|---|
| 204 | 173 | { |
|---|
| 205 | 174 | unsigned int status; |
|---|
| 206 | 175 | |
|---|
| 207 | 176 | regmap_read(regmap, AT91_PMC_SR, &status); |
|---|
| 208 | 177 | |
|---|
| 209 | | - return status & AT91_PMC_MOSCRCS; |
|---|
| 178 | + return !!(status & AT91_PMC_MOSCRCS); |
|---|
| 210 | 179 | } |
|---|
| 211 | 180 | |
|---|
| 212 | 181 | static int clk_main_rc_osc_prepare(struct clk_hw *hw) |
|---|
| .. | .. |
|---|
| 279 | 248 | .recalc_accuracy = clk_main_rc_osc_recalc_accuracy, |
|---|
| 280 | 249 | }; |
|---|
| 281 | 250 | |
|---|
| 282 | | -static struct clk_hw * __init |
|---|
| 251 | +struct clk_hw * __init |
|---|
| 283 | 252 | at91_clk_register_main_rc_osc(struct regmap *regmap, |
|---|
| 284 | 253 | const char *name, |
|---|
| 285 | 254 | u32 frequency, u32 accuracy) |
|---|
| 286 | 255 | { |
|---|
| 287 | 256 | struct clk_main_rc_osc *osc; |
|---|
| 288 | | - struct clk_init_data init = {}; |
|---|
| 257 | + struct clk_init_data init; |
|---|
| 289 | 258 | struct clk_hw *hw; |
|---|
| 290 | 259 | int ret; |
|---|
| 291 | 260 | |
|---|
| .. | .. |
|---|
| 316 | 285 | |
|---|
| 317 | 286 | return hw; |
|---|
| 318 | 287 | } |
|---|
| 319 | | - |
|---|
| 320 | | -static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np) |
|---|
| 321 | | -{ |
|---|
| 322 | | - struct clk_hw *hw; |
|---|
| 323 | | - u32 frequency = 0; |
|---|
| 324 | | - u32 accuracy = 0; |
|---|
| 325 | | - const char *name = np->name; |
|---|
| 326 | | - struct regmap *regmap; |
|---|
| 327 | | - |
|---|
| 328 | | - of_property_read_string(np, "clock-output-names", &name); |
|---|
| 329 | | - of_property_read_u32(np, "clock-frequency", &frequency); |
|---|
| 330 | | - of_property_read_u32(np, "clock-accuracy", &accuracy); |
|---|
| 331 | | - |
|---|
| 332 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
|---|
| 333 | | - if (IS_ERR(regmap)) |
|---|
| 334 | | - return; |
|---|
| 335 | | - |
|---|
| 336 | | - hw = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy); |
|---|
| 337 | | - if (IS_ERR(hw)) |
|---|
| 338 | | - return; |
|---|
| 339 | | - |
|---|
| 340 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
|---|
| 341 | | -} |
|---|
| 342 | | -CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc", |
|---|
| 343 | | - of_at91sam9x5_clk_main_rc_osc_setup); |
|---|
| 344 | | - |
|---|
| 345 | 288 | |
|---|
| 346 | 289 | static int clk_main_probe_frequency(struct regmap *regmap) |
|---|
| 347 | 290 | { |
|---|
| .. | .. |
|---|
| 393 | 336 | |
|---|
| 394 | 337 | regmap_read(clkmain->regmap, AT91_CKGR_MCFR, &status); |
|---|
| 395 | 338 | |
|---|
| 396 | | - return status & AT91_PMC_MAINRDY ? 1 : 0; |
|---|
| 339 | + return !!(status & AT91_PMC_MAINRDY); |
|---|
| 397 | 340 | } |
|---|
| 398 | 341 | |
|---|
| 399 | 342 | static unsigned long clk_rm9200_main_recalc_rate(struct clk_hw *hw, |
|---|
| .. | .. |
|---|
| 410 | 353 | .recalc_rate = clk_rm9200_main_recalc_rate, |
|---|
| 411 | 354 | }; |
|---|
| 412 | 355 | |
|---|
| 413 | | -static struct clk_hw * __init |
|---|
| 356 | +struct clk_hw * __init |
|---|
| 414 | 357 | at91_clk_register_rm9200_main(struct regmap *regmap, |
|---|
| 415 | 358 | const char *name, |
|---|
| 416 | 359 | const char *parent_name) |
|---|
| 417 | 360 | { |
|---|
| 418 | 361 | struct clk_rm9200_main *clkmain; |
|---|
| 419 | | - struct clk_init_data init = {}; |
|---|
| 362 | + struct clk_init_data init; |
|---|
| 420 | 363 | struct clk_hw *hw; |
|---|
| 421 | 364 | int ret; |
|---|
| 422 | 365 | |
|---|
| .. | .. |
|---|
| 449 | 392 | return hw; |
|---|
| 450 | 393 | } |
|---|
| 451 | 394 | |
|---|
| 452 | | -static void __init of_at91rm9200_clk_main_setup(struct device_node *np) |
|---|
| 453 | | -{ |
|---|
| 454 | | - struct clk_hw *hw; |
|---|
| 455 | | - const char *parent_name; |
|---|
| 456 | | - const char *name = np->name; |
|---|
| 457 | | - struct regmap *regmap; |
|---|
| 458 | | - |
|---|
| 459 | | - parent_name = of_clk_get_parent_name(np, 0); |
|---|
| 460 | | - of_property_read_string(np, "clock-output-names", &name); |
|---|
| 461 | | - |
|---|
| 462 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
|---|
| 463 | | - if (IS_ERR(regmap)) |
|---|
| 464 | | - return; |
|---|
| 465 | | - |
|---|
| 466 | | - hw = at91_clk_register_rm9200_main(regmap, name, parent_name); |
|---|
| 467 | | - if (IS_ERR(hw)) |
|---|
| 468 | | - return; |
|---|
| 469 | | - |
|---|
| 470 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
|---|
| 471 | | -} |
|---|
| 472 | | -CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main", |
|---|
| 473 | | - of_at91rm9200_clk_main_setup); |
|---|
| 474 | | - |
|---|
| 475 | 395 | static inline bool clk_sam9x5_main_ready(struct regmap *regmap) |
|---|
| 476 | 396 | { |
|---|
| 477 | 397 | unsigned int status; |
|---|
| 478 | 398 | |
|---|
| 479 | 399 | regmap_read(regmap, AT91_PMC_SR, &status); |
|---|
| 480 | 400 | |
|---|
| 481 | | - return status & AT91_PMC_MOSCSELS ? 1 : 0; |
|---|
| 401 | + return !!(status & AT91_PMC_MOSCSELS); |
|---|
| 482 | 402 | } |
|---|
| 483 | 403 | |
|---|
| 484 | 404 | static int clk_sam9x5_main_prepare(struct clk_hw *hw) |
|---|
| .. | .. |
|---|
| 553 | 473 | .get_parent = clk_sam9x5_main_get_parent, |
|---|
| 554 | 474 | }; |
|---|
| 555 | 475 | |
|---|
| 556 | | -static struct clk_hw * __init |
|---|
| 476 | +struct clk_hw * __init |
|---|
| 557 | 477 | at91_clk_register_sam9x5_main(struct regmap *regmap, |
|---|
| 558 | 478 | const char *name, |
|---|
| 559 | 479 | const char **parent_names, |
|---|
| 560 | 480 | int num_parents) |
|---|
| 561 | 481 | { |
|---|
| 562 | 482 | struct clk_sam9x5_main *clkmain; |
|---|
| 563 | | - struct clk_init_data init = {}; |
|---|
| 483 | + struct clk_init_data init; |
|---|
| 564 | 484 | unsigned int status; |
|---|
| 565 | 485 | struct clk_hw *hw; |
|---|
| 566 | 486 | int ret; |
|---|
| .. | .. |
|---|
| 595 | 515 | |
|---|
| 596 | 516 | return hw; |
|---|
| 597 | 517 | } |
|---|
| 598 | | - |
|---|
| 599 | | -static void __init of_at91sam9x5_clk_main_setup(struct device_node *np) |
|---|
| 600 | | -{ |
|---|
| 601 | | - struct clk_hw *hw; |
|---|
| 602 | | - const char *parent_names[2]; |
|---|
| 603 | | - unsigned int num_parents; |
|---|
| 604 | | - const char *name = np->name; |
|---|
| 605 | | - struct regmap *regmap; |
|---|
| 606 | | - |
|---|
| 607 | | - num_parents = of_clk_get_parent_count(np); |
|---|
| 608 | | - if (num_parents == 0 || num_parents > 2) |
|---|
| 609 | | - return; |
|---|
| 610 | | - |
|---|
| 611 | | - of_clk_parent_fill(np, parent_names, num_parents); |
|---|
| 612 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
|---|
| 613 | | - if (IS_ERR(regmap)) |
|---|
| 614 | | - return; |
|---|
| 615 | | - |
|---|
| 616 | | - of_property_read_string(np, "clock-output-names", &name); |
|---|
| 617 | | - |
|---|
| 618 | | - hw = at91_clk_register_sam9x5_main(regmap, name, parent_names, |
|---|
| 619 | | - num_parents); |
|---|
| 620 | | - if (IS_ERR(hw)) |
|---|
| 621 | | - return; |
|---|
| 622 | | - |
|---|
| 623 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
|---|
| 624 | | -} |
|---|
| 625 | | -CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main", |
|---|
| 626 | | - of_at91sam9x5_clk_main_setup); |
|---|