reset-sunxi.c 2.0 KB

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