fsl_inputmux.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include "fsl_inputmux.h"
  9. /*******************************************************************************
  10. * Definitions
  11. ******************************************************************************/
  12. /* Component ID definition, used by tools. */
  13. #ifndef FSL_COMPONENT_ID
  14. #define FSL_COMPONENT_ID "platform.drivers.inputmux"
  15. #endif
  16. /*******************************************************************************
  17. * Code
  18. ******************************************************************************/
  19. /*!
  20. * brief Initialize INPUTMUX peripheral.
  21. * This function enables the INPUTMUX clock.
  22. *
  23. * param base Base address of the INPUTMUX peripheral.
  24. *
  25. * retval None.
  26. */
  27. void INPUTMUX_Init(INPUTMUX_Type *base)
  28. {
  29. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  30. #if defined(FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE) && FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE
  31. CLOCK_EnableClock(kCLOCK_Sct);
  32. CLOCK_EnableClock(kCLOCK_Dma);
  33. #else
  34. CLOCK_EnableClock(kCLOCK_InputMux);
  35. #endif /* FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE */
  36. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  37. }
  38. /*!
  39. * brief Attaches a signal
  40. *
  41. * This function gates the INPUTPMUX clock.
  42. *
  43. * param base Base address of the INPUTMUX peripheral.
  44. * param index Destination peripheral to attach the signal to.
  45. * param connection Selects connection.
  46. *
  47. * retval None.
  48. */
  49. void INPUTMUX_AttachSignal(INPUTMUX_Type *base, uint32_t index, inputmux_connection_t connection)
  50. {
  51. uint32_t pmux_id;
  52. uint32_t output_id;
  53. /* extract pmux to be used */
  54. pmux_id = ((uint32_t)(connection)) >> PMUX_SHIFT;
  55. /* extract function number */
  56. output_id = ((uint32_t)(connection)) & 0xffffU;
  57. /* programm signal */
  58. *(volatile uint32_t *)(((uint32_t)base) + pmux_id + (index * 4)) = output_id;
  59. }
  60. #if defined(FSL_FEATURE_INPUTMUX_HAS_SIGNAL_ENA)
  61. /*!
  62. * brief Enable/disable a signal
  63. *
  64. * This function gates the INPUTPMUX clock.
  65. *
  66. * param base Base address of the INPUTMUX peripheral.
  67. * param signal Enable signal register id and bit offset.
  68. * param enable Selects enable or disable.
  69. *
  70. * retval None.
  71. */
  72. void INPUTMUX_EnableSignal(INPUTMUX_Type *base, inputmux_signal_t signal, bool enable)
  73. {
  74. uint32_t ena_id;
  75. uint32_t bit_offset;
  76. /* extract enable register to be used */
  77. ena_id = ((uint32_t)(signal)) >> ENA_SHIFT;
  78. /* extract enable bit offset */
  79. bit_offset = ((uint32_t)(signal)) & 0xfU;
  80. /* set signal */
  81. if (enable)
  82. {
  83. *(volatile uint32_t *)(((uint32_t)base) + ena_id) |= (1U << bit_offset);
  84. }
  85. else
  86. {
  87. *(volatile uint32_t *)(((uint32_t)base) + ena_id) &= ~(1U << bit_offset);
  88. }
  89. }
  90. #endif
  91. /*!
  92. * brief Deinitialize INPUTMUX peripheral.
  93. * This function disables the INPUTMUX clock.
  94. *
  95. * param base Base address of the INPUTMUX peripheral.
  96. *
  97. * retval None.
  98. */
  99. void INPUTMUX_Deinit(INPUTMUX_Type *base)
  100. {
  101. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  102. #if defined(FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE) && FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE
  103. CLOCK_DisableClock(kCLOCK_Sct);
  104. CLOCK_DisableClock(kCLOCK_Dma);
  105. #else
  106. CLOCK_DisableClock(kCLOCK_InputMux);
  107. #endif /* FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE */
  108. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  109. }