ccu_reset.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2016 Maxime Ripard
  3. * Maxime Ripard <maxime.ripard@free-electrons.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/io.h>
  12. #include <linux/reset-controller.h>
  13. #include "ccu_reset.h"
  14. static int ccu_reset_assert(struct reset_controller_dev *rcdev,
  15. unsigned long id)
  16. {
  17. struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
  18. const struct ccu_reset_map *map = &ccu->reset_map[id];
  19. unsigned long flags;
  20. u32 reg;
  21. spin_lock_irqsave(ccu->lock, flags);
  22. reg = readl(ccu->base + map->reg);
  23. writel(reg & ~map->bit, ccu->base + map->reg);
  24. spin_unlock_irqrestore(ccu->lock, flags);
  25. return 0;
  26. }
  27. static int ccu_reset_deassert(struct reset_controller_dev *rcdev,
  28. unsigned long id)
  29. {
  30. struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
  31. const struct ccu_reset_map *map = &ccu->reset_map[id];
  32. unsigned long flags;
  33. u32 reg;
  34. spin_lock_irqsave(ccu->lock, flags);
  35. reg = readl(ccu->base + map->reg);
  36. writel(reg | map->bit, ccu->base + map->reg);
  37. spin_unlock_irqrestore(ccu->lock, flags);
  38. return 0;
  39. }
  40. static int ccu_reset_reset(struct reset_controller_dev *rcdev,
  41. unsigned long id)
  42. {
  43. ccu_reset_assert(rcdev, id);
  44. udelay(10);
  45. ccu_reset_deassert(rcdev, id);
  46. return 0;
  47. }
  48. static int ccu_reset_status(struct reset_controller_dev *rcdev,
  49. unsigned long id)
  50. {
  51. struct ccu_reset *ccu = rcdev_to_ccu_reset(rcdev);
  52. const struct ccu_reset_map *map = &ccu->reset_map[id];
  53. /*
  54. * The reset control API expects 0 if reset is not asserted,
  55. * which is the opposite of what our hardware uses.
  56. */
  57. return !(map->bit & readl(ccu->base + map->reg));
  58. }
  59. const struct reset_control_ops ccu_reset_ops = {
  60. .assert = ccu_reset_assert,
  61. .deassert = ccu_reset_deassert,
  62. .reset = ccu_reset_reset,
  63. .status = ccu_reset_status,
  64. };