cpu-reset.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2014 Marvell
  3. *
  4. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #define pr_fmt(fmt) "mvebu-cpureset: " fmt
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/of_address.h>
  14. #include <linux/io.h>
  15. #include <linux/resource.h>
  16. #include "common.h"
  17. static void __iomem *cpu_reset_base;
  18. static size_t cpu_reset_size;
  19. #define CPU_RESET_OFFSET(cpu) (cpu * 0x8)
  20. #define CPU_RESET_ASSERT BIT(0)
  21. int mvebu_cpu_reset_deassert(int cpu)
  22. {
  23. u32 reg;
  24. if (!cpu_reset_base)
  25. return -ENODEV;
  26. if (CPU_RESET_OFFSET(cpu) >= cpu_reset_size)
  27. return -EINVAL;
  28. reg = readl(cpu_reset_base + CPU_RESET_OFFSET(cpu));
  29. reg &= ~CPU_RESET_ASSERT;
  30. writel(reg, cpu_reset_base + CPU_RESET_OFFSET(cpu));
  31. return 0;
  32. }
  33. static int mvebu_cpu_reset_map(struct device_node *np, int res_idx)
  34. {
  35. struct resource res;
  36. if (of_address_to_resource(np, res_idx, &res)) {
  37. pr_err("unable to get resource\n");
  38. return -ENOENT;
  39. }
  40. if (!request_mem_region(res.start, resource_size(&res),
  41. np->full_name)) {
  42. pr_err("unable to request region\n");
  43. return -EBUSY;
  44. }
  45. cpu_reset_base = ioremap(res.start, resource_size(&res));
  46. if (!cpu_reset_base) {
  47. pr_err("unable to map registers\n");
  48. release_mem_region(res.start, resource_size(&res));
  49. return -ENOMEM;
  50. }
  51. cpu_reset_size = resource_size(&res);
  52. return 0;
  53. }
  54. static int __init mvebu_cpu_reset_init(void)
  55. {
  56. struct device_node *np;
  57. int res_idx;
  58. int ret;
  59. np = of_find_compatible_node(NULL, NULL,
  60. "marvell,armada-370-cpu-reset");
  61. if (np) {
  62. res_idx = 0;
  63. } else {
  64. /*
  65. * This code is kept for backward compatibility with
  66. * old Device Trees.
  67. */
  68. np = of_find_compatible_node(NULL, NULL,
  69. "marvell,armada-370-xp-pmsu");
  70. if (np) {
  71. pr_warn(FW_WARN "deprecated pmsu binding\n");
  72. res_idx = 1;
  73. }
  74. }
  75. /* No reset node found */
  76. if (!np)
  77. return -ENODEV;
  78. ret = mvebu_cpu_reset_map(np, res_idx);
  79. of_node_put(np);
  80. return ret;
  81. }
  82. early_initcall(mvebu_cpu_reset_init);