misc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2013 Stefan Roese <sr@denx.de>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <common.h>
  18. #include <asm/errno.h>
  19. #include <asm/io.h>
  20. #include <asm/imx-common/regs-common.h>
  21. /* 1 second delay should be plenty of time for block reset. */
  22. #define RESET_MAX_TIMEOUT 1000000
  23. #define MXS_BLOCK_SFTRST (1 << 31)
  24. #define MXS_BLOCK_CLKGATE (1 << 30)
  25. int mxs_wait_mask_set(struct mxs_register_32 *reg, uint32_t mask, unsigned
  26. int timeout)
  27. {
  28. while (--timeout) {
  29. if ((readl(&reg->reg) & mask) == mask)
  30. break;
  31. udelay(1);
  32. }
  33. return !timeout;
  34. }
  35. int mxs_wait_mask_clr(struct mxs_register_32 *reg, uint32_t mask, unsigned
  36. int timeout)
  37. {
  38. while (--timeout) {
  39. if ((readl(&reg->reg) & mask) == 0)
  40. break;
  41. udelay(1);
  42. }
  43. return !timeout;
  44. }
  45. int mxs_reset_block(struct mxs_register_32 *reg)
  46. {
  47. /* Clear SFTRST */
  48. writel(MXS_BLOCK_SFTRST, &reg->reg_clr);
  49. if (mxs_wait_mask_clr(reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  50. return 1;
  51. /* Clear CLKGATE */
  52. writel(MXS_BLOCK_CLKGATE, &reg->reg_clr);
  53. /* Set SFTRST */
  54. writel(MXS_BLOCK_SFTRST, &reg->reg_set);
  55. /* Wait for CLKGATE being set */
  56. if (mxs_wait_mask_set(reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  57. return 1;
  58. /* Clear SFTRST */
  59. writel(MXS_BLOCK_SFTRST, &reg->reg_clr);
  60. if (mxs_wait_mask_clr(reg, MXS_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
  61. return 1;
  62. /* Clear CLKGATE */
  63. writel(MXS_BLOCK_CLKGATE, &reg->reg_clr);
  64. if (mxs_wait_mask_clr(reg, MXS_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
  65. return 1;
  66. return 0;
  67. }