clk-a10-mod1.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. static DEFINE_SPINLOCK(mod1_lock);
  21. #define SUN4I_MOD1_ENABLE 31
  22. #define SUN4I_MOD1_MUX 16
  23. #define SUN4I_MOD1_MUX_WIDTH 2
  24. #define SUN4I_MOD1_MAX_PARENTS 4
  25. static void __init sun4i_mod1_clk_setup(struct device_node *node)
  26. {
  27. struct clk *clk;
  28. struct clk_mux *mux;
  29. struct clk_gate *gate;
  30. const char *parents[4];
  31. const char *clk_name = node->name;
  32. void __iomem *reg;
  33. int i;
  34. reg = of_io_request_and_map(node, 0, of_node_full_name(node));
  35. if (IS_ERR(reg))
  36. return;
  37. mux = kzalloc(sizeof(*mux), GFP_KERNEL);
  38. if (!mux)
  39. goto err_unmap;
  40. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  41. if (!gate)
  42. goto err_free_mux;
  43. of_property_read_string(node, "clock-output-names", &clk_name);
  44. i = of_clk_parent_fill(node, parents, SUN4I_MOD1_MAX_PARENTS);
  45. gate->reg = reg;
  46. gate->bit_idx = SUN4I_MOD1_ENABLE;
  47. gate->lock = &mod1_lock;
  48. mux->reg = reg;
  49. mux->shift = SUN4I_MOD1_MUX;
  50. mux->mask = BIT(SUN4I_MOD1_MUX_WIDTH) - 1;
  51. mux->lock = &mod1_lock;
  52. clk = clk_register_composite(NULL, clk_name, parents, i,
  53. &mux->hw, &clk_mux_ops,
  54. NULL, NULL,
  55. &gate->hw, &clk_gate_ops, 0);
  56. if (IS_ERR(clk))
  57. goto err_free_gate;
  58. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  59. return;
  60. err_free_gate:
  61. kfree(gate);
  62. err_free_mux:
  63. kfree(mux);
  64. err_unmap:
  65. iounmap(reg);
  66. }
  67. CLK_OF_DECLARE(sun4i_mod1, "allwinner,sun4i-a10-mod1-clk",
  68. sun4i_mod1_clk_setup);