0003-clk-mediatek-Add-reset-controller-support.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. From c91e8490e45c68ea517f70f24568034b7735e8b9 Mon Sep 17 00:00:00 2001
  2. From: Sascha Hauer <[email protected]>
  3. Date: Thu, 23 Apr 2015 10:35:40 +0200
  4. Subject: [PATCH 03/76] clk: mediatek: Add reset controller support
  5. The pericfg and infracfg units also provide reset lines to several
  6. other SoC internal units. This adds a function which can be called
  7. from the pericfg and infracfg initialization functions which will
  8. register the reset controller using reset_controller_register. The
  9. reset controller will provide support for resetting the units
  10. connected to the pericfg and infracfg controller. The units resetted
  11. by this controller can use the standard reset device tree binding
  12. to gain access to the reset lines.
  13. Signed-off-by: Sascha Hauer <[email protected]>
  14. Acked-by: Philipp Zabel <[email protected]>
  15. ---
  16. drivers/clk/mediatek/Makefile | 1 +
  17. drivers/clk/mediatek/clk-mtk.h | 10 +++++
  18. drivers/clk/mediatek/reset.c | 97 ++++++++++++++++++++++++++++++++++++++++
  19. 3 files changed, 108 insertions(+)
  20. create mode 100644 drivers/clk/mediatek/reset.c
  21. diff --git a/drivers/clk/mediatek/Makefile b/drivers/clk/mediatek/Makefile
  22. index c384e97..0b6f1c3 100644
  23. --- a/drivers/clk/mediatek/Makefile
  24. +++ b/drivers/clk/mediatek/Makefile
  25. @@ -1 +1,2 @@
  26. obj-y += clk-mtk.o clk-pll.o clk-gate.o
  27. +obj-$(CONFIG_RESET_CONTROLLER) += reset.o
  28. diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
  29. index 694fc39..61035b9 100644
  30. --- a/drivers/clk/mediatek/clk-mtk.h
  31. +++ b/drivers/clk/mediatek/clk-mtk.h
  32. @@ -156,4 +156,14 @@ void __init mtk_clk_register_plls(struct device_node *node,
  33. const struct mtk_pll_data *plls, int num_plls,
  34. struct clk_onecell_data *clk_data);
  35. +#ifdef CONFIG_RESET_CONTROLLER
  36. +void mtk_register_reset_controller(struct device_node *np,
  37. + unsigned int num_regs, int regofs);
  38. +#else
  39. +static inline void mtk_register_reset_controller(struct device_node *np,
  40. + unsigned int num_regs, int regofs)
  41. +{
  42. +}
  43. +#endif
  44. +
  45. #endif /* __DRV_CLK_MTK_H */
  46. diff --git a/drivers/clk/mediatek/reset.c b/drivers/clk/mediatek/reset.c
  47. new file mode 100644
  48. index 0000000..9e9fe4b
  49. --- /dev/null
  50. +++ b/drivers/clk/mediatek/reset.c
  51. @@ -0,0 +1,97 @@
  52. +/*
  53. + * Copyright (c) 2014 MediaTek Inc.
  54. + *
  55. + * This program is free software; you can redistribute it and/or modify
  56. + * it under the terms of the GNU General Public License version 2 as
  57. + * published by the Free Software Foundation.
  58. + *
  59. + * This program is distributed in the hope that it will be useful,
  60. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  61. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  62. + * GNU General Public License for more details.
  63. + */
  64. +
  65. +#include <linux/mfd/syscon.h>
  66. +#include <linux/module.h>
  67. +#include <linux/of.h>
  68. +#include <linux/platform_device.h>
  69. +#include <linux/regmap.h>
  70. +#include <linux/reset-controller.h>
  71. +#include <linux/slab.h>
  72. +
  73. +#include "clk-mtk.h"
  74. +
  75. +struct mtk_reset {
  76. + struct regmap *regmap;
  77. + int regofs;
  78. + struct reset_controller_dev rcdev;
  79. +};
  80. +
  81. +static int mtk_reset_assert(struct reset_controller_dev *rcdev,
  82. + unsigned long id)
  83. +{
  84. + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
  85. +
  86. + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
  87. + BIT(id % 32), ~0);
  88. +}
  89. +
  90. +static int mtk_reset_deassert(struct reset_controller_dev *rcdev,
  91. + unsigned long id)
  92. +{
  93. + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
  94. +
  95. + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
  96. + BIT(id % 32), 0);
  97. +}
  98. +
  99. +static int mtk_reset(struct reset_controller_dev *rcdev,
  100. + unsigned long id)
  101. +{
  102. + int ret;
  103. +
  104. + ret = mtk_reset_assert(rcdev, id);
  105. + if (ret)
  106. + return ret;
  107. +
  108. + return mtk_reset_deassert(rcdev, id);
  109. +}
  110. +
  111. +static struct reset_control_ops mtk_reset_ops = {
  112. + .assert = mtk_reset_assert,
  113. + .deassert = mtk_reset_deassert,
  114. + .reset = mtk_reset,
  115. +};
  116. +
  117. +void mtk_register_reset_controller(struct device_node *np,
  118. + unsigned int num_regs, int regofs)
  119. +{
  120. + struct mtk_reset *data;
  121. + int ret;
  122. + struct regmap *regmap;
  123. +
  124. + regmap = syscon_node_to_regmap(np);
  125. + if (IS_ERR(regmap)) {
  126. + pr_err("Cannot find regmap for %s: %ld\n", np->full_name,
  127. + PTR_ERR(regmap));
  128. + return;
  129. + }
  130. +
  131. + data = kzalloc(sizeof(*data), GFP_KERNEL);
  132. + if (!data)
  133. + return;
  134. +
  135. + data->regmap = regmap;
  136. + data->regofs = regofs;
  137. + data->rcdev.owner = THIS_MODULE;
  138. + data->rcdev.nr_resets = num_regs * 32;
  139. + data->rcdev.ops = &mtk_reset_ops;
  140. + data->rcdev.of_node = np;
  141. +
  142. + ret = reset_controller_register(&data->rcdev);
  143. + if (ret) {
  144. + pr_err("could not register reset controller: %d\n", ret);
  145. + kfree(data);
  146. + return;
  147. + }
  148. +}
  149. --
  150. 1.7.10.4