clk-a10-hosc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2013 Emilio López
  3. *
  4. * Emilio López <emilio@elopez.com.ar>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/clk-provider.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/slab.h>
  20. #define SUNXI_OSC24M_GATE 0
  21. static DEFINE_SPINLOCK(hosc_lock);
  22. static void __init sun4i_osc_clk_setup(struct device_node *node)
  23. {
  24. struct clk *clk;
  25. struct clk_fixed_rate *fixed;
  26. struct clk_gate *gate;
  27. const char *clk_name = node->name;
  28. u32 rate;
  29. if (of_property_read_u32(node, "clock-frequency", &rate))
  30. return;
  31. /* allocate fixed-rate and gate clock structs */
  32. fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
  33. if (!fixed)
  34. return;
  35. gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
  36. if (!gate)
  37. goto err_free_fixed;
  38. of_property_read_string(node, "clock-output-names", &clk_name);
  39. /* set up gate and fixed rate properties */
  40. gate->reg = of_iomap(node, 0);
  41. gate->bit_idx = SUNXI_OSC24M_GATE;
  42. gate->lock = &hosc_lock;
  43. fixed->fixed_rate = rate;
  44. clk = clk_register_composite(NULL, clk_name,
  45. NULL, 0,
  46. NULL, NULL,
  47. &fixed->hw, &clk_fixed_rate_ops,
  48. &gate->hw, &clk_gate_ops, 0);
  49. if (IS_ERR(clk))
  50. goto err_free_gate;
  51. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  52. return;
  53. err_free_gate:
  54. kfree(gate);
  55. err_free_fixed:
  56. kfree(fixed);
  57. }
  58. CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-a10-osc-clk", sun4i_osc_clk_setup);