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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. --- a/drivers/clk/mediatek/Makefile
  22. +++ b/drivers/clk/mediatek/Makefile
  23. @@ -1 +1,2 @@
  24. obj-y += clk-mtk.o clk-pll.o clk-gate.o
  25. +obj-$(CONFIG_RESET_CONTROLLER) += reset.o
  26. --- a/drivers/clk/mediatek/clk-mtk.h
  27. +++ b/drivers/clk/mediatek/clk-mtk.h
  28. @@ -156,4 +156,14 @@ void __init mtk_clk_register_plls(struct
  29. const struct mtk_pll_data *plls, int num_plls,
  30. struct clk_onecell_data *clk_data);
  31. +#ifdef CONFIG_RESET_CONTROLLER
  32. +void mtk_register_reset_controller(struct device_node *np,
  33. + unsigned int num_regs, int regofs);
  34. +#else
  35. +static inline void mtk_register_reset_controller(struct device_node *np,
  36. + unsigned int num_regs, int regofs)
  37. +{
  38. +}
  39. +#endif
  40. +
  41. #endif /* __DRV_CLK_MTK_H */
  42. --- /dev/null
  43. +++ b/drivers/clk/mediatek/reset.c
  44. @@ -0,0 +1,97 @@
  45. +/*
  46. + * Copyright (c) 2014 MediaTek Inc.
  47. + *
  48. + * This program is free software; you can redistribute it and/or modify
  49. + * it under the terms of the GNU General Public License version 2 as
  50. + * published by the Free Software Foundation.
  51. + *
  52. + * This program is distributed in the hope that it will be useful,
  53. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  54. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  55. + * GNU General Public License for more details.
  56. + */
  57. +
  58. +#include <linux/mfd/syscon.h>
  59. +#include <linux/module.h>
  60. +#include <linux/of.h>
  61. +#include <linux/platform_device.h>
  62. +#include <linux/regmap.h>
  63. +#include <linux/reset-controller.h>
  64. +#include <linux/slab.h>
  65. +
  66. +#include "clk-mtk.h"
  67. +
  68. +struct mtk_reset {
  69. + struct regmap *regmap;
  70. + int regofs;
  71. + struct reset_controller_dev rcdev;
  72. +};
  73. +
  74. +static int mtk_reset_assert(struct reset_controller_dev *rcdev,
  75. + unsigned long id)
  76. +{
  77. + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
  78. +
  79. + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
  80. + BIT(id % 32), ~0);
  81. +}
  82. +
  83. +static int mtk_reset_deassert(struct reset_controller_dev *rcdev,
  84. + unsigned long id)
  85. +{
  86. + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev);
  87. +
  88. + return regmap_update_bits(data->regmap, data->regofs + ((id / 32) << 2),
  89. + BIT(id % 32), 0);
  90. +}
  91. +
  92. +static int mtk_reset(struct reset_controller_dev *rcdev,
  93. + unsigned long id)
  94. +{
  95. + int ret;
  96. +
  97. + ret = mtk_reset_assert(rcdev, id);
  98. + if (ret)
  99. + return ret;
  100. +
  101. + return mtk_reset_deassert(rcdev, id);
  102. +}
  103. +
  104. +static struct reset_control_ops mtk_reset_ops = {
  105. + .assert = mtk_reset_assert,
  106. + .deassert = mtk_reset_deassert,
  107. + .reset = mtk_reset,
  108. +};
  109. +
  110. +void mtk_register_reset_controller(struct device_node *np,
  111. + unsigned int num_regs, int regofs)
  112. +{
  113. + struct mtk_reset *data;
  114. + int ret;
  115. + struct regmap *regmap;
  116. +
  117. + regmap = syscon_node_to_regmap(np);
  118. + if (IS_ERR(regmap)) {
  119. + pr_err("Cannot find regmap for %s: %ld\n", np->full_name,
  120. + PTR_ERR(regmap));
  121. + return;
  122. + }
  123. +
  124. + data = kzalloc(sizeof(*data), GFP_KERNEL);
  125. + if (!data)
  126. + return;
  127. +
  128. + data->regmap = regmap;
  129. + data->regofs = regofs;
  130. + data->rcdev.owner = THIS_MODULE;
  131. + data->rcdev.nr_resets = num_regs * 32;
  132. + data->rcdev.ops = &mtk_reset_ops;
  133. + data->rcdev.of_node = np;
  134. +
  135. + ret = reset_controller_register(&data->rcdev);
  136. + if (ret) {
  137. + pr_err("could not register reset controller: %d\n", ret);
  138. + kfree(data);
  139. + return;
  140. + }
  141. +}