1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef __HAL_IOMUX_H__
5 #define __HAL_IOMUX_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include "plat_types.h"
12 #include "plat_addr_map.h"
13 #include CHIP_SPECIFIC_HDR(hal_iomux)
14 
15 enum HAL_IOMUX_OP_TYPE_T {
16     HAL_IOMUX_OP_KEEP_OTHER_FUNC_BIT = 0,
17     HAL_IOMUX_OP_CLEAN_OTHER_FUNC_BIT,
18 };
19 
20 enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T {
21     HAL_IOMUX_PIN_VOLTAGE_VIO = 0,
22     HAL_IOMUX_PIN_VOLTAGE_MEM,
23     // For PMU LED pins only
24     HAL_IOMUX_PIN_VOLTAGE_VBAT,
25 };
26 
27 enum HAL_IOMUX_PIN_PULL_SELECT_T {
28     HAL_IOMUX_PIN_NOPULL = 0,
29     HAL_IOMUX_PIN_PULLUP_ENALBE,
30     HAL_IOMUX_PIN_PULLDOWN_ENALBE,
31 };
32 
33 enum HAL_PWRKEY_IRQ_T {
34     HAL_PWRKEY_IRQ_NONE             = 0,
35     HAL_PWRKEY_IRQ_FALLING_EDGE     = (1 << 0),
36     HAL_PWRKEY_IRQ_RISING_EDGE      = (1 << 1),
37     HAL_PWRKEY_IRQ_BOTH_EDGE        = (HAL_PWRKEY_IRQ_FALLING_EDGE | HAL_PWRKEY_IRQ_RISING_EDGE),
38 };
39 
40 struct HAL_IOMUX_PIN_FUNCTION_MAP {
41     enum HAL_IOMUX_PIN_T pin;
42     enum HAL_IOMUX_FUNCTION_T function;
43     enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt;
44     enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel;
45 };
46 
47 uint32_t hal_iomux_check(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t count);
48 uint32_t hal_iomux_init(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t count);
49 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);
50 enum HAL_IOMUX_FUNCTION_T hal_iomux_get_function(enum HAL_IOMUX_PIN_T pin);
51 uint32_t hal_iomux_set_io_voltage_domains(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt);
52 uint32_t hal_iomux_set_io_pull_select(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel);
53 
54 void hal_iomux_set_default_config(void);
55 void hal_iomux_set_uart0_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt);
56 void hal_iomux_set_uart1_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt);
57 void hal_iomux_set_uart2_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt);
58 bool hal_iomux_uart0_connected(void);
59 bool hal_iomux_uart1_connected(void);
60 void hal_iomux_set_uart0(void);
61 void hal_iomux_set_uart1(void);
62 void hal_iomux_set_uart2(void);
63 void hal_iomux_set_analog_i2c(void);
64 void hal_iomux_set_analog_i2c_master_slave(void);
65 void hal_iomux_set_jtag(void);
66 void hal_iomux_set_sdmmc_dt_n_out_group(int enable);
67 void hal_iomux_set_i2s0(void);
68 void hal_iomux_set_i2s1(void);
69 void hal_iomux_set_spdif0(void);
70 void hal_iomux_set_spdif1(void);
71 void hal_iomux_set_dig_mic_clock_pin(enum HAL_IOMUX_PIN_T pin);
72 void hal_iomux_set_dig_mic_data0_pin(enum HAL_IOMUX_PIN_T pin);
73 void hal_iomux_set_dig_mic_data1_pin(enum HAL_IOMUX_PIN_T pin);
74 void hal_iomux_set_dig_mic_data2_pin(enum HAL_IOMUX_PIN_T pin);
75 void hal_iomux_set_dig_mic(uint32_t map);
76 void hal_iomux_set_spi(void);
77 void hal_iomux_set_spilcd(void);
78 void hal_iomux_set_i2c0(void);
79 void hal_iomux_set_i2c1(void);
80 void hal_iomux_set_clock_out(void);
81 void hal_iomux_set_clock_12m(void);
82 void hal_iomux_clear_clock_12m(void);
83 void hal_iomux_set_bt_tport(void);
84 void hal_iomux_set_bt_rf_sw(int rx_on, int tx_on);
85 
86 void hal_iomux_ispi_access_init(void);
87 enum HAL_IOMUX_ISPI_ACCESS_T hal_iomux_ispi_access_enable(enum HAL_IOMUX_ISPI_ACCESS_T access);
88 enum HAL_IOMUX_ISPI_ACCESS_T hal_iomux_ispi_access_disable(enum HAL_IOMUX_ISPI_ACCESS_T access);
89 
90 int hal_pwrkey_set_irq(enum HAL_PWRKEY_IRQ_T type);
91 bool hal_pwrkey_pressed(void);
92 bool hal_pwrkey_startup_pressed(void);
93 enum HAL_PWRKEY_IRQ_T hal_pwrkey_get_irq_state(void);
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif
100