mtgpio.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2024, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <platform_def.h>
  8. #include <mtgpio.h>
  9. typedef enum {
  10. REG_0 = 0,
  11. REG_1,
  12. REG_2,
  13. REG_3,
  14. REG_4,
  15. REG_5,
  16. REG_6,
  17. REG_7,
  18. REG_8,
  19. REG_9,
  20. REG_10,
  21. REG_11,
  22. REG_12,
  23. REG_13,
  24. REG_14
  25. } RegEnum;
  26. uintptr_t mt_gpio_find_reg_addr(uint32_t pin)
  27. {
  28. uintptr_t reg_addr = 0U;
  29. struct mt_pin_info gpio_info;
  30. assert(pin < MAX_GPIO_PIN);
  31. gpio_info = mt_pin_infos[pin];
  32. switch (gpio_info.base & 0xF) {
  33. case REG_0:
  34. reg_addr = IOCFG_RT_BASE;
  35. break;
  36. case REG_1:
  37. reg_addr = IOCFG_RM1_BASE;
  38. break;
  39. case REG_2:
  40. reg_addr = IOCFG_RM2_BASE;
  41. break;
  42. case REG_3:
  43. reg_addr = IOCFG_RB_BASE;
  44. break;
  45. case REG_4:
  46. reg_addr = IOCFG_BM1_BASE;
  47. break;
  48. case REG_5:
  49. reg_addr = IOCFG_BM2_BASE;
  50. break;
  51. case REG_6:
  52. reg_addr = IOCFG_BM3_BASE;
  53. break;
  54. case REG_7:
  55. reg_addr = IOCFG_LT_BASE;
  56. break;
  57. case REG_8:
  58. reg_addr = IOCFG_LM1_BASE;
  59. break;
  60. case REG_9:
  61. reg_addr = IOCFG_LM2_BASE;
  62. break;
  63. case REG_10:
  64. reg_addr = IOCFG_LB1_BASE;
  65. break;
  66. case REG_11:
  67. reg_addr = IOCFG_LB2_BASE;
  68. break;
  69. case REG_12:
  70. reg_addr = IOCFG_TM1_BASE;
  71. break;
  72. case REG_13:
  73. reg_addr = IOCFG_TM2_BASE;
  74. break;
  75. case REG_14:
  76. reg_addr = IOCFG_TM3_BASE;
  77. break;
  78. default:
  79. break;
  80. }
  81. return reg_addr;
  82. }