reset-sunxi.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Allwinner SoCs Reset Controller driver
  4. *
  5. * Copyright 2013 Maxime Ripard
  6. *
  7. * Maxime Ripard <maxime.ripard@free-electrons.com>
  8. */
  9. #include <linux/err.h>
  10. #include <linux/io.h>
  11. #include <linux/init.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/reset-controller.h>
  16. #include <linux/reset/reset-simple.h>
  17. #include <linux/reset/sunxi.h>
  18. #include <linux/slab.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/types.h>
  21. static int sunxi_reset_init(struct device_node *np)
  22. {
  23. struct reset_simple_data *data;
  24. struct resource res;
  25. resource_size_t size;
  26. int ret;
  27. data = kzalloc(sizeof(*data), GFP_KERNEL);
  28. if (!data)
  29. return -ENOMEM;
  30. ret = of_address_to_resource(np, 0, &res);
  31. if (ret)
  32. goto err_alloc;
  33. size = resource_size(&res);
  34. if (!request_mem_region(res.start, size, np->name)) {
  35. ret = -EBUSY;
  36. goto err_alloc;
  37. }
  38. data->membase = ioremap(res.start, size);
  39. if (!data->membase) {
  40. ret = -ENOMEM;
  41. goto err_alloc;
  42. }
  43. spin_lock_init(&data->lock);
  44. data->rcdev.owner = THIS_MODULE;
  45. data->rcdev.nr_resets = size * 8;
  46. data->rcdev.ops = &reset_simple_ops;
  47. data->rcdev.of_node = np;
  48. data->active_low = true;
  49. return reset_controller_register(&data->rcdev);
  50. err_alloc:
  51. kfree(data);
  52. return ret;
  53. };
  54. /*
  55. * These are the reset controller we need to initialize early on in
  56. * our system, before we can even think of using a regular device
  57. * driver for it.
  58. * The controllers that we can register through the regular device
  59. * model are handled by the simple reset driver directly.
  60. */
  61. static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = {
  62. { .compatible = "allwinner,sun6i-a31-ahb1-reset", },
  63. { /* sentinel */ },
  64. };
  65. void __init sun6i_reset_init(void)
  66. {
  67. struct device_node *np;
  68. for_each_matching_node(np, sunxi_early_reset_dt_ids)
  69. sunxi_reset_init(np);
  70. }