clk-a10-hosc.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2013 Emilio López
  4. *
  5. * Emilio López <[email protected]>
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/slab.h>
  11. #define SUNXI_OSC24M_GATE 0
  12. static DEFINE_SPINLOCK(hosc_lock);
  13. static void __init sun4i_osc_clk_setup(struct device_node *node)
  14. {
  15. struct clk *clk;
  16. struct clk_fixed_rate *fixed;
  17. struct clk_gate *gate;
  18. const char *clk_name = node->name;
  19. u32 rate;
  20. if (of_property_read_u32(node, "clock-frequency", &rate))
  21. return;
  22. /* allocate fixed-rate and gate clock structs */
  23. fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
  24. if (!fixed)
  25. return;
  26. gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
  27. if (!gate)
  28. goto err_free_fixed;
  29. of_property_read_string(node, "clock-output-names", &clk_name);
  30. /* set up gate and fixed rate properties */
  31. gate->reg = of_iomap(node, 0);
  32. gate->bit_idx = SUNXI_OSC24M_GATE;
  33. gate->lock = &hosc_lock;
  34. fixed->fixed_rate = rate;
  35. clk = clk_register_composite(NULL, clk_name,
  36. NULL, 0,
  37. NULL, NULL,
  38. &fixed->hw, &clk_fixed_rate_ops,
  39. &gate->hw, &clk_gate_ops, 0);
  40. if (IS_ERR(clk))
  41. goto err_free_gate;
  42. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  43. return;
  44. err_free_gate:
  45. kfree(gate);
  46. err_free_fixed:
  47. kfree(fixed);
  48. }
  49. CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-a10-osc-clk", sun4i_osc_clk_setup);