1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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
16 #include <hi_io.h>
17 #include <hi3861_platform.h>
18
app_io_set_gpio2_clkout_enable(hi_bool enable)19 hi_void app_io_set_gpio2_clkout_enable(hi_bool enable)
20 {
21 if (enable == HI_TRUE) {
22 hi_io_set_input_enable(HI_IO_NAME_GPIO_2, HI_TRUE);
23 hi_reg_write16(DIAG_CTL_DIAG_MUX, 0x2);
24 hi_reg_write16(DIAG_CTL_CLOCK_TEST_DIV, 0x0);
25 hi_reg_write16(DIAG_CTL_CLOCK_TEST_EN, 0x3FFF);
26 hi_reg_write16(DIAG_CTL_CLOCK_TEST_SEL, 0x1);
27 hi_io_set_func(HI_IO_NAME_GPIO_2, 0x6); /* let gpio2 output clk. */
28 hi_io_set_driver_strength(HI_IO_NAME_GPIO_2, HI_IO_DRIVER_STRENGTH_3);
29 } else {
30 hi_io_set_func(HI_IO_NAME_GPIO_2, HI_IO_FUNC_GPIO_2_GPIO);
31 hi_io_set_input_enable(HI_IO_NAME_GPIO_2, HI_FALSE); /* set io enable false, for low power. */
32 hi_io_set_pull(HI_IO_NAME_GPIO_2, HI_IO_PULL_NONE);
33 }
34 }
35
app_io_init(hi_void)36 hi_void app_io_init(hi_void)
37 {
38 /*
39 * You need to select the I/O multiplexing configuration of each peripheral
40 * based on the application scenario. The following is an example.
41 */
42 #ifdef CONFIG_UART0_SUPPORT
43 /* Configure UART0 as the debugging serial port. */
44 hi_io_set_func(HI_IO_NAME_GPIO_3, HI_IO_FUNC_GPIO_3_UART0_TXD); /* uart0 tx */
45 hi_io_set_func(HI_IO_NAME_GPIO_4, HI_IO_FUNC_GPIO_4_UART0_RXD); /* uart0 rx */
46 #endif
47
48 #ifdef CONFIG_UART1_SUPPORT
49 /* Configure UART1 as the AT command serial port. */
50 hi_io_set_func(HI_IO_NAME_GPIO_5, HI_IO_FUNC_GPIO_5_UART1_RXD); /* uart1 rx */
51 hi_io_set_func(HI_IO_NAME_GPIO_6, HI_IO_FUNC_GPIO_6_UART1_TXD); /* uart1 tx */
52 #endif
53
54 #ifdef CONFIG_UART2_SUPPORT
55 /* Configure UART1 as the SIGMA authentication serial port. */
56 hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_UART2_TXD); /* uart2 tx */
57 hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_UART2_RXD); /* uart2 rx */
58 #endif
59
60 /* SPI MUX: */
61 #ifdef CONFIG_SPI_SUPPORT
62 /* The SPI I/O multiplexing mode can also be 5/6/7/8 or 0/1/2/3 based on the product design. */
63 hi_io_set_func(HI_IO_NAME_GPIO_9, HI_IO_FUNC_GPIO_9_SPI0_TXD);
64 hi_io_set_func(HI_IO_NAME_GPIO_10, HI_IO_FUNC_GPIO_10_SPI0_CK);
65 hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_SPI0_RXD);
66 hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_SPI0_CSN);
67 hi_io_set_driver_strength(HI_IO_NAME_GPIO_9, HI_IO_DRIVER_STRENGTH_0);
68 #endif
69
70 /* I2C MUX: */
71 #ifdef CONFIG_I2C_SUPPORT
72 /* The I2C I/O multiplexing mode can also be 3/4 or 9/10 based on the product design. */
73 hi_io_set_func(HI_IO_NAME_GPIO_0, HI_IO_FUNC_GPIO_0_I2C1_SDA);
74 hi_io_set_func(HI_IO_NAME_GPIO_1, HI_IO_FUNC_GPIO_1_I2C1_SCL);
75 #endif
76
77 /* PWM MUX: */
78 #ifdef CONFIG_PWM_SUPPORT
79 /* The configurations for multiplexing 0/2/3/4/5 into PWM are similar. */
80 hi_io_set_func(HI_IO_NAME_GPIO_8, HI_IO_FUNC_GPIO_8_PWM1_OUT);
81 #endif
82
83 /* I2S MUX: */
84 #ifdef CONFIG_I2S_SUPPORT
85 hi_io_set_func(HI_IO_NAME_GPIO_9, HI_IO_FUNC_GPIO_9_I2S0_MCLK);
86 hi_io_set_func(HI_IO_NAME_GPIO_10, HI_IO_FUNC_GPIO_10_I2S0_TX);
87 hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_I2S0_RX);
88 hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_I2S0_BCLK);
89 hi_io_set_func(HI_IO_NAME_GPIO_13, HI_IO_FUNC_GPIO_13_I2S0_WS);
90 #endif
91
92 /* SDIO MUX: */
93 #ifdef CONFIG_SDIO_SUPPORT
94 (hi_void)hi_io_set_func(HI_IO_NAME_GPIO_9, HI_IO_FUNC_GPIO_9_SDIO_D2);
95 (hi_void)hi_io_set_func(HI_IO_NAME_GPIO_10, HI_IO_FUNC_GPIO_10_SDIO_D3);
96 (hi_void)hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_SDIO_CMD);
97 (hi_void)hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_SDIO_CLK);
98 (hi_void)hi_io_set_func(HI_IO_NAME_GPIO_13, HI_IO_FUNC_GPIO_13_SDIO_D0);
99 (hi_void)hi_io_set_func(HI_IO_NAME_GPIO_14, HI_IO_FUNC_GPIO_14_SDIO_D1);
100
101 (hi_void)hi_io_set_pull(HI_IO_NAME_GPIO_9, HI_IO_PULL_UP);
102 (hi_void)hi_io_set_pull(HI_IO_NAME_GPIO_10, HI_IO_PULL_UP);
103 (hi_void)hi_io_set_pull(HI_IO_NAME_GPIO_11, HI_IO_PULL_UP);
104 (hi_void)hi_io_set_pull(HI_IO_NAME_GPIO_13, HI_IO_PULL_UP);
105 (hi_void)hi_io_set_pull(HI_IO_NAME_GPIO_14, HI_IO_PULL_UP);
106 #endif
107 }
108
109