105-reset-add-reset-ctrler.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. From 8015cea648c452bbfe0fc820dcb1185beaeb8736 Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <[email protected]>
  3. Date: Tue, 24 Sep 2013 11:07:43 +0300
  4. Subject: [PATCH] reset: Add Allwinner SoCs Reset Controller Driver
  5. The Allwinner A31 and most of the other Allwinner SoCs have an IP
  6. maintaining a few other IPs in the SoC in reset by default. Among these
  7. IPs are the A31's High Speed Timers, hence why we can't use the regular
  8. driver construct in every cases, and need to call the registering
  9. function directly during machine initialisation.
  10. Apart from this, the implementation is fairly straightforward, and could
  11. easily be moved to a generic MMIO-based reset controller driver if the
  12. need ever arise.
  13. Signed-off-by: Maxime Ripard <[email protected]>
  14. Acked-by: Philipp Zabel <[email protected]>
  15. ---
  16. drivers/reset/Makefile | 1 +
  17. drivers/reset/reset-sunxi.c | 175 ++++++++++++++++++++++++++++++++++++++++++++
  18. 2 files changed, 176 insertions(+)
  19. create mode 100644 drivers/reset/reset-sunxi.c
  20. --- a/drivers/reset/Makefile
  21. +++ b/drivers/reset/Makefile
  22. @@ -1 +1,2 @@
  23. obj-$(CONFIG_RESET_CONTROLLER) += core.o
  24. +obj-$(CONFIG_ARCH_SUNXI) += reset-sunxi.o
  25. --- /dev/null
  26. +++ b/drivers/reset/reset-sunxi.c
  27. @@ -0,0 +1,175 @@
  28. +/*
  29. + * Allwinner SoCs Reset Controller driver
  30. + *
  31. + * Copyright 2013 Maxime Ripard
  32. + *
  33. + * Maxime Ripard <[email protected]>
  34. + *
  35. + * This program is free software; you can redistribute it and/or modify
  36. + * it under the terms of the GNU General Public License as published by
  37. + * the Free Software Foundation; either version 2 of the License, or
  38. + * (at your option) any later version.
  39. + */
  40. +
  41. +#include <linux/err.h>
  42. +#include <linux/io.h>
  43. +#include <linux/module.h>
  44. +#include <linux/of.h>
  45. +#include <linux/of_address.h>
  46. +#include <linux/platform_device.h>
  47. +#include <linux/reset-controller.h>
  48. +#include <linux/slab.h>
  49. +#include <linux/spinlock.h>
  50. +#include <linux/types.h>
  51. +
  52. +struct sunxi_reset_data {
  53. + spinlock_t lock;
  54. + void __iomem *membase;
  55. + struct reset_controller_dev rcdev;
  56. +};
  57. +
  58. +static int sunxi_reset_assert(struct reset_controller_dev *rcdev,
  59. + unsigned long id)
  60. +{
  61. + struct sunxi_reset_data *data = container_of(rcdev,
  62. + struct sunxi_reset_data,
  63. + rcdev);
  64. + int bank = id / BITS_PER_LONG;
  65. + int offset = id % BITS_PER_LONG;
  66. + unsigned long flags;
  67. + u32 reg;
  68. +
  69. + spin_lock_irqsave(&data->lock, flags);
  70. +
  71. + reg = readl(data->membase + (bank * 4));
  72. + writel(reg & ~BIT(offset), data->membase + (bank * 4));
  73. +
  74. + spin_unlock_irqrestore(&data->lock, flags);
  75. +
  76. + return 0;
  77. +}
  78. +
  79. +static int sunxi_reset_deassert(struct reset_controller_dev *rcdev,
  80. + unsigned long id)
  81. +{
  82. + struct sunxi_reset_data *data = container_of(rcdev,
  83. + struct sunxi_reset_data,
  84. + rcdev);
  85. + int bank = id / BITS_PER_LONG;
  86. + int offset = id % BITS_PER_LONG;
  87. + unsigned long flags;
  88. + u32 reg;
  89. +
  90. + spin_lock_irqsave(&data->lock, flags);
  91. +
  92. + reg = readl(data->membase + (bank * 4));
  93. + writel(reg | BIT(offset), data->membase + (bank * 4));
  94. +
  95. + spin_unlock_irqrestore(&data->lock, flags);
  96. +
  97. + return 0;
  98. +}
  99. +
  100. +static struct reset_control_ops sunxi_reset_ops = {
  101. + .assert = sunxi_reset_assert,
  102. + .deassert = sunxi_reset_deassert,
  103. +};
  104. +
  105. +static int sunxi_reset_init(struct device_node *np)
  106. +{
  107. + struct sunxi_reset_data *data;
  108. + struct resource res;
  109. + resource_size_t size;
  110. + int ret;
  111. +
  112. + data = kzalloc(sizeof(*data), GFP_KERNEL);
  113. + if (!data)
  114. + return -ENOMEM;
  115. +
  116. + ret = of_address_to_resource(np, 0, &res);
  117. + if (ret)
  118. + goto err_alloc;
  119. +
  120. + size = resource_size(&res);
  121. + if (!request_mem_region(res.start, size, np->name)) {
  122. + ret = -EBUSY;
  123. + goto err_alloc;
  124. + }
  125. +
  126. + data->membase = ioremap(res.start, size);
  127. + if (!data->membase) {
  128. + ret = -ENOMEM;
  129. + goto err_alloc;
  130. + }
  131. +
  132. + data->rcdev.owner = THIS_MODULE;
  133. + data->rcdev.nr_resets = size * 32;
  134. + data->rcdev.ops = &sunxi_reset_ops;
  135. + data->rcdev.of_node = np;
  136. + reset_controller_register(&data->rcdev);
  137. +
  138. + return 0;
  139. +
  140. +err_alloc:
  141. + kfree(data);
  142. + return ret;
  143. +};
  144. +
  145. +/*
  146. + * These are the reset controller we need to initialize early on in
  147. + * our system, before we can even think of using a regular device
  148. + * driver for it.
  149. + */
  150. +static const struct of_device_id sunxi_early_reset_dt_ids[] __initdata = {
  151. + { .compatible = "allwinner,sun6i-a31-ahb1-reset", },
  152. + { /* sentinel */ },
  153. +};
  154. +
  155. +void __init sun6i_reset_init(void)
  156. +{
  157. + struct device_node *np;
  158. +
  159. + for_each_matching_node(np, sunxi_early_reset_dt_ids)
  160. + sunxi_reset_init(np);
  161. +}
  162. +
  163. +/*
  164. + * And these are the controllers we can register through the regular
  165. + * device model.
  166. + */
  167. +static const struct of_device_id sunxi_reset_dt_ids[] = {
  168. + { .compatible = "allwinner,sun6i-a31-clock-reset", },
  169. + { /* sentinel */ },
  170. +};
  171. +MODULE_DEVICE_TABLE(of, sunxi_reset_dt_ids);
  172. +
  173. +static int sunxi_reset_probe(struct platform_device *pdev)
  174. +{
  175. + return sunxi_reset_init(pdev->dev.of_node);
  176. +}
  177. +
  178. +static int sunxi_reset_remove(struct platform_device *pdev)
  179. +{
  180. + struct sunxi_reset_data *data = platform_get_drvdata(pdev);
  181. +
  182. + reset_controller_unregister(&data->rcdev);
  183. + iounmap(data->membase);
  184. + kfree(data);
  185. +
  186. + return 0;
  187. +}
  188. +
  189. +static struct platform_driver sunxi_reset_driver = {
  190. + .probe = sunxi_reset_probe,
  191. + .remove = sunxi_reset_remove,
  192. + .driver = {
  193. + .name = "sunxi-reset",
  194. + .owner = THIS_MODULE,
  195. + .of_match_table = sunxi_reset_dt_ids,
  196. + },
  197. +};
  198. +module_platform_driver(sunxi_reset_driver);
  199. +
  200. +MODULE_AUTHOR("Maxime Ripard <[email protected]");
  201. +MODULE_DESCRIPTION("Allwinner SoCs Reset Controller Driver");
  202. +MODULE_LICENSE("GPL");