fsl_inputmux.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_inputmux.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /* Component ID definition, used by tools. */
  39. #ifndef FSL_COMPONENT_ID
  40. #define FSL_COMPONENT_ID "platform.drivers.inputmux"
  41. #endif
  42. /*******************************************************************************
  43. * Code
  44. ******************************************************************************/
  45. void INPUTMUX_Init(INPUTMUX_Type *base)
  46. {
  47. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  48. #if defined(FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE) && FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE
  49. CLOCK_EnableClock(kCLOCK_Sct);
  50. CLOCK_EnableClock(kCLOCK_Dma);
  51. #else
  52. CLOCK_EnableClock(kCLOCK_InputMux);
  53. #endif /* FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE */
  54. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  55. }
  56. void INPUTMUX_AttachSignal(INPUTMUX_Type *base, uint32_t index, inputmux_connection_t connection)
  57. {
  58. uint32_t pmux_id;
  59. uint32_t output_id;
  60. /* extract pmux to be used */
  61. pmux_id = ((uint32_t)(connection)) >> PMUX_SHIFT;
  62. /* extract function number */
  63. output_id = ((uint32_t)(connection)) & 0xffffU;
  64. /* programm signal */
  65. *(volatile uint32_t *)(((uint32_t)base) + pmux_id + (index * 4)) = output_id;
  66. }
  67. #if defined(FSL_FEATURE_INPUTMUX_HAS_SIGNAL_ENA)
  68. void INPUTMUX_EnableSignal(INPUTMUX_Type *base, inputmux_signal_t signal, bool enable)
  69. {
  70. uint32_t ena_id;
  71. uint32_t bit_offset;
  72. /* extract enable register to be used */
  73. ena_id = ((uint32_t)(signal)) >> ENA_SHIFT;
  74. /* extract enable bit offset */
  75. bit_offset = ((uint32_t)(signal)) & 0xfU;
  76. /* set signal */
  77. if (enable)
  78. {
  79. *(volatile uint32_t *)(((uint32_t)base) + ena_id) |= (1U << bit_offset);
  80. }
  81. else
  82. {
  83. *(volatile uint32_t *)(((uint32_t)base) + ena_id) &= ~(1U << bit_offset);
  84. }
  85. }
  86. #endif
  87. void INPUTMUX_Deinit(INPUTMUX_Type *base)
  88. {
  89. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  90. #if defined(FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE) && FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE
  91. CLOCK_DisableClock(kCLOCK_Sct);
  92. CLOCK_DisableClock(kCLOCK_Dma);
  93. #else
  94. CLOCK_DisableClock(kCLOCK_InputMux);
  95. #endif /* FSL_FEATURE_INPUTMUX_HAS_NO_INPUTMUX_CLOCK_SOURCE */
  96. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  97. }