msdi.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * MSDI IP block reset
  4. *
  5. * Copyright (C) 2012 Texas Instruments, Inc.
  6. * Paul Walmsley
  7. *
  8. * XXX What about pad muxing?
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/err.h>
  12. #include "prm.h"
  13. #include "common.h"
  14. #include "control.h"
  15. #include "omap_hwmod.h"
  16. #include "omap_device.h"
  17. #include "mmc.h"
  18. /*
  19. * MSDI_CON_OFFSET: offset in bytes of the MSDI IP block's CON register
  20. * from the IP block's base address
  21. */
  22. #define MSDI_CON_OFFSET 0x0c
  23. /* Register bitfields in the CON register */
  24. #define MSDI_CON_POW_MASK BIT(11)
  25. #define MSDI_CON_CLKD_MASK (0x3f << 0)
  26. #define MSDI_CON_CLKD_SHIFT 0
  27. /* MSDI_TARGET_RESET_CLKD: clock divisor to use throughout the reset */
  28. #define MSDI_TARGET_RESET_CLKD 0x3ff
  29. /**
  30. * omap_msdi_reset - reset the MSDI IP block
  31. * @oh: struct omap_hwmod *
  32. *
  33. * The MSDI IP block on OMAP2420 has to have both the POW and CLKD
  34. * fields set inside its CON register for a reset to complete
  35. * successfully. This is not documented in the TRM. For CLKD, we use
  36. * the value that results in the lowest possible clock rate, to attempt
  37. * to avoid disturbing any cards.
  38. */
  39. int omap_msdi_reset(struct omap_hwmod *oh)
  40. {
  41. u16 v = 0;
  42. int c = 0;
  43. /* Write to the SOFTRESET bit */
  44. omap_hwmod_softreset(oh);
  45. /* Enable the MSDI core and internal clock */
  46. v |= MSDI_CON_POW_MASK;
  47. v |= MSDI_TARGET_RESET_CLKD << MSDI_CON_CLKD_SHIFT;
  48. omap_hwmod_write(v, oh, MSDI_CON_OFFSET);
  49. /* Poll on RESETDONE bit */
  50. omap_test_timeout((omap_hwmod_read(oh, oh->class->sysc->syss_offs)
  51. & SYSS_RESETDONE_MASK),
  52. MAX_MODULE_SOFTRESET_WAIT, c);
  53. if (c == MAX_MODULE_SOFTRESET_WAIT)
  54. pr_warn("%s: %s: softreset failed (waited %d usec)\n",
  55. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  56. else
  57. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  58. oh->name, c);
  59. /* Disable the MSDI internal clock */
  60. v &= ~MSDI_CON_CLKD_MASK;
  61. omap_hwmod_write(v, oh, MSDI_CON_OFFSET);
  62. return 0;
  63. }