iomux.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <log.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/imx-regs.h>
  9. #include <asm/arch/iomux.h>
  10. static void *base = (void *)IOMUXC_BASE_ADDR;
  11. /*
  12. * iomuxc0 base address. In imx7ulp-pins.h,
  13. * the offsets of pins in iomuxc0 are from 0xD000,
  14. * so we set the base address to (0x4103D000 - 0xD000 = 0x41030000)
  15. */
  16. static void *base_mports = (void *)(AIPS0_BASE + 0x30000);
  17. /*
  18. * configures a single pad in the iomuxer
  19. */
  20. void mx7ulp_iomux_setup_pad(iomux_cfg_t pad)
  21. {
  22. u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT;
  23. u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT;
  24. u32 sel_input_ofs =
  25. (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT;
  26. u32 sel_input =
  27. (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT;
  28. u32 pad_ctrl_ofs = mux_ctrl_ofs;
  29. u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT;
  30. debug("[PAD CFG] = 0x%16llX \r\n\tmux_ctl = 0x%X(0x%X) sel_input = 0x%X(0x%X) pad_ctrl = 0x%X(0x%X)\r\n",
  31. pad, mux_ctrl_ofs, mux_mode, sel_input_ofs, sel_input,
  32. pad_ctrl_ofs, pad_ctrl);
  33. if (mux_mode & IOMUX_CONFIG_MPORTS) {
  34. mux_mode &= ~IOMUX_CONFIG_MPORTS;
  35. base = base_mports;
  36. } else {
  37. base = (void *)IOMUXC_BASE_ADDR;
  38. }
  39. __raw_writel(((mux_mode << IOMUXC_PCR_MUX_ALT_SHIFT) &
  40. IOMUXC_PCR_MUX_ALT_MASK), base + mux_ctrl_ofs);
  41. if (sel_input_ofs)
  42. __raw_writel((sel_input << IOMUXC_PSMI_IMUX_ALT_SHIFT),
  43. base + sel_input_ofs);
  44. if (!(pad_ctrl & NO_PAD_CTRL))
  45. __raw_writel(((mux_mode << IOMUXC_PCR_MUX_ALT_SHIFT) &
  46. IOMUXC_PCR_MUX_ALT_MASK) |
  47. (pad_ctrl & (~IOMUXC_PCR_MUX_ALT_MASK)),
  48. base + pad_ctrl_ofs);
  49. }
  50. /* configures a list of pads within declared with IOMUX_PADS macro */
  51. void mx7ulp_iomux_setup_multiple_pads(iomux_cfg_t const *pad_list,
  52. unsigned count)
  53. {
  54. iomux_cfg_t const *p = pad_list;
  55. int i;
  56. for (i = 0; i < count; i++) {
  57. mx7ulp_iomux_setup_pad(*p);
  58. p++;
  59. }
  60. }