1 /* 2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __HAL_IOMUX_H__ 16 #define __HAL_IOMUX_H__ 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #include "plat_types.h" 23 #include "plat_addr_map.h" 24 #if defined(NUTTX_BUILD) 25 #include "arch/board/board.h" 26 #endif 27 #include CHIP_SPECIFIC_HDR(hal_iomux) 28 29 enum HAL_IOMUX_OP_TYPE_T { 30 HAL_IOMUX_OP_KEEP_OTHER_FUNC_BIT = 0, 31 HAL_IOMUX_OP_CLEAN_OTHER_FUNC_BIT, 32 }; 33 34 enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T { 35 HAL_IOMUX_PIN_VOLTAGE_VIO = 0, 36 HAL_IOMUX_PIN_VOLTAGE_MEM, 37 // For PMU LED pins only 38 HAL_IOMUX_PIN_VOLTAGE_VBAT, 39 }; 40 41 enum HAL_IOMUX_PIN_PULL_SELECT_T { 42 HAL_IOMUX_PIN_NOPULL = 0, 43 HAL_IOMUX_PIN_PULLUP_ENABLE, 44 HAL_IOMUX_PIN_PULLDOWN_ENABLE, 45 }; 46 47 enum HAL_PWRKEY_IRQ_T { 48 HAL_PWRKEY_IRQ_NONE = 0, 49 HAL_PWRKEY_IRQ_FALLING_EDGE = (1 << 0), 50 HAL_PWRKEY_IRQ_RISING_EDGE = (1 << 1), 51 HAL_PWRKEY_IRQ_BOTH_EDGE = (HAL_PWRKEY_IRQ_FALLING_EDGE | HAL_PWRKEY_IRQ_RISING_EDGE), 52 }; 53 54 struct HAL_IOMUX_PIN_FUNCTION_MAP { 55 enum HAL_IOMUX_PIN_T pin; 56 enum HAL_IOMUX_FUNCTION_T function; 57 enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt; 58 enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel; 59 }; 60 61 uint32_t hal_iomux_check(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t count); 62 uint32_t hal_iomux_init(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t count); 63 uint32_t hal_iomux_set_function(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_FUNCTION_T func, enum HAL_IOMUX_OP_TYPE_T type); 64 enum HAL_IOMUX_FUNCTION_T hal_iomux_get_function(enum HAL_IOMUX_PIN_T pin); 65 uint32_t hal_iomux_set_io_voltage_domains(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); 66 uint32_t hal_iomux_set_io_pull_select(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel); 67 uint32_t hal_iomux_set_io_drv(enum HAL_IOMUX_PIN_T pin, uint32_t val); 68 69 void hal_iomux_set_default_config(void); 70 void hal_iomux_set_uart0_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); 71 void hal_iomux_set_uart1_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); 72 void hal_iomux_set_uart2_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); 73 bool hal_iomux_uart0_connected(void); 74 bool hal_iomux_uart1_connected(void); 75 void hal_iomux_set_uart0(void); 76 void hal_iomux_set_uart1(void); 77 void hal_iomux_set_uart2(void); 78 void hal_iomux_set_uart3(void); 79 void hal_iomux_set_analog_i2c(void); 80 void hal_iomux_set_analog_i2c_master_slave(void); 81 void hal_iomux_set_jtag(void); 82 void hal_iomux_set_sdmmc_dt_n_out_group(int enable); 83 void hal_iomux_set_sdmmc(void); 84 void hal_iomux_set_i2s0(void); 85 void hal_iomux_set_i2s1(void); 86 void hal_iomux_set_spdif0(void); 87 void hal_iomux_set_spdif1(void); 88 void hal_iomux_set_dig_mic_clock_pin(enum HAL_IOMUX_PIN_T pin); 89 void hal_iomux_set_dig_mic_data0_pin(enum HAL_IOMUX_PIN_T pin); 90 void hal_iomux_set_dig_mic_data1_pin(enum HAL_IOMUX_PIN_T pin); 91 void hal_iomux_set_dig_mic_data2_pin(enum HAL_IOMUX_PIN_T pin); 92 void hal_iomux_set_dig_mic(uint32_t map); 93 void hal_iomux_set_spi(void); 94 void hal_iomux_set_spilcd(void); 95 void hal_iomux_set_spilcd_slave(void); 96 void hal_iomux_set_i2c0(void); 97 void hal_iomux_set_i2c1(void); 98 void hal_iomux_set_i2c2(void); 99 void hal_iomux_set_i2c3(void); 100 void hal_iomux_set_pwm0(void); 101 void hal_iomux_set_pwm1(void); 102 void hal_iomux_set_pwm2(void); 103 void hal_iomux_set_pwm3(void); 104 void hal_iomux_set_pwm4(void); 105 void hal_iomux_set_pwm5(void); 106 void hal_iomux_set_pwm6(void); 107 void hal_iomux_set_pwm7(void); 108 void hal_iomux_set_ir(void); 109 void hal_iomux_set_sdio_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); 110 void hal_iomux_set_sdio(void); 111 void hal_iomux_set_sdmmc(void); 112 void hal_iomux_set_clock_out(void); 113 void hal_iomux_set_clock_12m(void); 114 void hal_iomux_clear_clock_12m(void); 115 void hal_iomux_set_bt_tport(void); 116 void hal_iomux_set_bt_rf_sw(int rx_on, int tx_on); 117 118 void hal_iomux_ispi_access_init(void); 119 #ifndef HAL_IOMUX_ISPI_ACCESS_T 120 enum HAL_IOMUX_ISPI_ACCESS_T hal_iomux_ispi_access_enable(enum HAL_IOMUX_ISPI_ACCESS_T access); 121 enum HAL_IOMUX_ISPI_ACCESS_T hal_iomux_ispi_access_disable(enum HAL_IOMUX_ISPI_ACCESS_T access); 122 #endif 123 124 int hal_pwrkey_set_irq(enum HAL_PWRKEY_IRQ_T type); 125 bool hal_pwrkey_pressed(void); 126 bool hal_pwrkey_startup_pressed(void); 127 enum HAL_PWRKEY_IRQ_T hal_pwrkey_get_irq_state(void); 128 129 void hal_iomux_set_codec_gpio_trigger(enum HAL_IOMUX_PIN_T pin, bool polarity); 130 131 void hal_iomux_single_wire_uart_rx(uint32_t uart); 132 void hal_iomux_single_wire_uart_tx(uint32_t uart); 133 134 #ifdef __cplusplus 135 } 136 #endif 137 138 #endif 139