clk-slow.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * drivers/clk/at91/clk-slow.c
  4. *
  5. * Copyright (C) 2013 Boris BREZILLON <[email protected]>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/clkdev.h>
  9. #include <linux/clk/at91_pmc.h>
  10. #include <linux/of.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/regmap.h>
  13. #include "pmc.h"
  14. struct clk_sam9260_slow {
  15. struct clk_hw hw;
  16. struct regmap *regmap;
  17. };
  18. #define to_clk_sam9260_slow(hw) container_of(hw, struct clk_sam9260_slow, hw)
  19. static u8 clk_sam9260_slow_get_parent(struct clk_hw *hw)
  20. {
  21. struct clk_sam9260_slow *slowck = to_clk_sam9260_slow(hw);
  22. unsigned int status;
  23. regmap_read(slowck->regmap, AT91_PMC_SR, &status);
  24. return status & AT91_PMC_OSCSEL ? 1 : 0;
  25. }
  26. static const struct clk_ops sam9260_slow_ops = {
  27. .get_parent = clk_sam9260_slow_get_parent,
  28. };
  29. struct clk_hw * __init
  30. at91_clk_register_sam9260_slow(struct regmap *regmap,
  31. const char *name,
  32. const char **parent_names,
  33. int num_parents)
  34. {
  35. struct clk_sam9260_slow *slowck;
  36. struct clk_hw *hw;
  37. struct clk_init_data init;
  38. int ret;
  39. if (!name)
  40. return ERR_PTR(-EINVAL);
  41. if (!parent_names || !num_parents)
  42. return ERR_PTR(-EINVAL);
  43. slowck = kzalloc(sizeof(*slowck), GFP_KERNEL);
  44. if (!slowck)
  45. return ERR_PTR(-ENOMEM);
  46. init.name = name;
  47. init.ops = &sam9260_slow_ops;
  48. init.parent_names = parent_names;
  49. init.num_parents = num_parents;
  50. init.flags = 0;
  51. slowck->hw.init = &init;
  52. slowck->regmap = regmap;
  53. hw = &slowck->hw;
  54. ret = clk_hw_register(NULL, &slowck->hw);
  55. if (ret) {
  56. kfree(slowck);
  57. hw = ERR_PTR(ret);
  58. }
  59. return hw;
  60. }