163-clk-sunxi-mod1-clock.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. From 7fbbca069587b7f467e76f583ad640977de1a4ff Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <emilio@elopez.com.ar>
  3. Date: Fri, 18 Jul 2014 15:28:02 -0300
  4. Subject: [PATCH] clk: sunxi: mod1 clock support
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. The module 1 type of clocks consist of a gate and a mux and are used on
  9. the audio blocks to mux and gate the PLL2 outputs for AC97, IIS or
  10. SPDIF. This commit adds support for them on the sunxi clock driver.
  11. Signed-off-by: Emilio López <emilio@elopez.com.ar>
  12. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  13. ---
  14. drivers/clk/sunxi/Makefile | 1 +
  15. drivers/clk/sunxi/clk-a10-mod1.c | 69 ++++++++++++++++++++++++++++++++++++++++
  16. 2 files changed, 70 insertions(+)
  17. create mode 100644 drivers/clk/sunxi/clk-a10-mod1.c
  18. --- a/drivers/clk/sunxi/Makefile
  19. +++ b/drivers/clk/sunxi/Makefile
  20. @@ -5,6 +5,7 @@
  21. obj-y += clk-sunxi.o clk-factors.o
  22. obj-y += clk-a10-codec.o
  23. obj-y += clk-a10-hosc.o
  24. +obj-y += clk-a10-mod1.o
  25. obj-y += clk-a10-pll2.o
  26. obj-y += clk-a20-gmac.o
  27. obj-y += clk-mod0.o
  28. --- /dev/null
  29. +++ b/drivers/clk/sunxi/clk-a10-mod1.c
  30. @@ -0,0 +1,69 @@
  31. +/*
  32. + * Copyright 2013 Emilio López
  33. + *
  34. + * Emilio López <emilio@elopez.com.ar>
  35. + *
  36. + * This program is free software; you can redistribute it and/or modify
  37. + * it under the terms of the GNU General Public License as published by
  38. + * the Free Software Foundation; either version 2 of the License, or
  39. + * (at your option) any later version.
  40. + *
  41. + * This program is distributed in the hope that it will be useful,
  42. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44. + * GNU General Public License for more details.
  45. + */
  46. +
  47. +#include <linux/clk-provider.h>
  48. +#include <linux/clkdev.h>
  49. +#include <linux/of.h>
  50. +#include <linux/of_address.h>
  51. +
  52. +static DEFINE_SPINLOCK(mod1_lock);
  53. +
  54. +#define SUN4I_MOD1_ENABLE 31
  55. +#define SUN4I_MOD1_MUX 16
  56. +#define SUN4I_MOD1_MUX_WIDTH 2
  57. +#define SUN4I_MOD1_MAX_PARENTS 4
  58. +
  59. +static void __init sun4i_mod1_clk_setup(struct device_node *node)
  60. +{
  61. + struct clk *clk;
  62. + struct clk_mux *mux;
  63. + struct clk_gate *gate;
  64. + const char *parents[4];
  65. + const char *clk_name = node->name;
  66. + void __iomem *reg;
  67. + int i = 0;
  68. +
  69. + mux = kzalloc(sizeof(*mux), GFP_KERNEL);
  70. + gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  71. + if (!mux || !gate) {
  72. + kfree(mux);
  73. + kfree(gate);
  74. + return;
  75. + }
  76. +
  77. + of_property_read_string(node, "clock-output-names", &clk_name);
  78. + reg = of_iomap(node, 0);
  79. +
  80. + while (i < SUN4I_MOD1_MAX_PARENTS &&
  81. + (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
  82. + i++;
  83. +
  84. + gate->reg = reg;
  85. + gate->bit_idx = SUN4I_MOD1_ENABLE;
  86. + gate->lock = &mod1_lock;
  87. + mux->reg = reg;
  88. + mux->shift = SUN4I_MOD1_MUX;
  89. + mux->mask = BIT(SUN4I_MOD1_MUX_WIDTH) - 1;
  90. + mux->lock = &mod1_lock;
  91. +
  92. + clk = clk_register_composite(NULL, clk_name, parents, i,
  93. + &mux->hw, &clk_mux_ops,
  94. + NULL, NULL,
  95. + &gate->hw, &clk_gate_ops, 0);
  96. + if (!IS_ERR(clk))
  97. + of_clk_add_provider(node, of_clk_src_simple_get, clk);
  98. +}
  99. +CLK_OF_DECLARE(sun4i_mod1, "allwinner,sun4i-a10-mod1-clk", sun4i_mod1_clk_setup);