1 /* 2 * Copyright (c) 2018-2019 Linaro Limited 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/device.h> 8 #include <zephyr/init.h> 9 #include <zephyr/kernel.h> 10 #include <soc.h> 11 #include <zephyr/sys/sys_io.h> 12 #include <zephyr/drivers/gpio/gpio_cmsdk_ahb.h> 13 14 /** 15 * @brief Pinmux driver for ARM MPS2 AN521 Board 16 * 17 * The ARM MPS2 AN521 Board has 4 GPIO controllers. These controllers 18 * are responsible for pin muxing, input/output, pull-up, etc. 19 * 20 * All GPIO controller pins are exposed via the following sequence of pin 21 * numbers: 22 * Pins 0 - 15 are for GPIO0 23 * Pins 16 - 31 are for GPIO1 24 * Pins 32 - 47 are for GPIO2 25 * Pins 48 - 51 are for GPIO3 26 * 27 * For the GPIO controllers configuration ARM MPS2 AN521 Board follows the 28 * Arduino compliant pin out. 29 */ 30 31 #define CMSDK_AHB_GPIO0_DEV \ 32 ((volatile struct gpio_cmsdk_ahb *)DT_REG_ADDR(DT_NODELABEL(gpio0))) 33 #define CMSDK_AHB_GPIO1_DEV \ 34 ((volatile struct gpio_cmsdk_ahb *)DT_REG_ADDR(DT_NODELABEL(gpio1))) 35 #define CMSDK_AHB_GPIO2_DEV \ 36 ((volatile struct gpio_cmsdk_ahb *)DT_REG_ADDR(DT_NODELABEL(gpio2))) 37 #define CMSDK_AHB_GPIO3_DEV \ 38 ((volatile struct gpio_cmsdk_ahb *)DT_REG_ADDR(DT_NODELABEL(gpio3))) 39 40 /* 41 * This is the mapping from the ARM MPS2 AN521 Board pins to GPIO 42 * controllers. 43 * 44 * D0 : EXT_0 45 * D1 : EXT_4 46 * D2 : EXT_2 47 * D3 : EXT_3 48 * D4 : EXT_1 49 * D5 : EXT_6 50 * D6 : EXT_7 51 * D7 : EXT_8 52 * D8 : EXT_9 53 * D9 : EXT_10 54 * D10 : EXT_12 55 * D11 : EXT_13 56 * D12 : EXT_14 57 * D13 : EXT_11 58 * D14 : EXT_15 59 * D15 : EXT_5 60 * D16 : EXT_16 61 * D17 : EXT_17 62 * D18 : EXT_18 63 * D19 : EXT_19 64 * D20 : EXT_20 65 * D21 : EXT_21 66 * D22 : EXT_22 67 * D23 : EXT_23 68 * D24 : EXT_24 69 * D25 : EXT_25 70 * D26 : EXT_26 71 * D27 : EXT_30 72 * D28 : EXT_28 73 * D29 : EXT_29 74 * D30 : EXT_27 75 * D31 : EXT_32 76 * D32 : EXT_33 77 * D33 : EXT_34 78 * D34 : EXT_35 79 * D35 : EXT_36 80 * D36 : EXT_38 81 * D37 : EXT_39 82 * D38 : EXT_40 83 * D39 : EXT_44 84 * D40 : EXT_41 85 * D41 : EXT_31 86 * D42 : EXT_37 87 * D43 : EXT_42 88 * D44 : EXT_43 89 * D45 : EXT_45 90 * D46 : EXT_46 91 * D47 : EXT_47 92 * D48 : EXT_48 93 * D49 : EXT_49 94 * D50 : EXT_50 95 * D51 : EXT_51 96 * 97 * UART_3_RX : D0 98 * UART_3_TX : D1 99 * SPI_3_CS : D10 100 * SPI_3_MOSI : D11 101 * SPI_3_MISO : D12 102 * SPI_3_SCLK : D13 103 * I2C_3_SDA : D14 104 * I2C_3_SCL : D15 105 * UART_4_RX : D26 106 * UART_4_TX : D30 107 * SPI_4_CS : D36 108 * SPI_4_MOSI : D37 109 * SPI_4_MISO : D38 110 * SPI_4_SCK : D39 111 * I2C_4_SDA : D40 112 * I2C_4_SCL : D41 113 * 114 */ arm_mps2_pinmux_defaults(void)115static void arm_mps2_pinmux_defaults(void) 116 { 117 uint32_t gpio_0 = 0; 118 uint32_t gpio_1 = 0; 119 uint32_t gpio_2 = 0; 120 121 /* Set GPIO Alternate Functions */ 122 123 gpio_0 = (1<<0) /* Shield 0 UART 3 RXD */ 124 | (1<<4) /* Shield 0 UART 3 TXD */ 125 | (1<<5) /* Shield 0 I2C SCL SBCON2 */ 126 | (1<<15) /* Shield 0 I2C SDA SBCON2 */ 127 | (1<<11) /* Shield 0 SPI 3 SCK */ 128 | (1<<12) /* Shield 0 SPI 3 SS */ 129 | (1<<13) /* Shield 0 SPI 3 MOSI */ 130 | (1<<14); /* Shield 0 SPI 3 MISO */ 131 132 CMSDK_AHB_GPIO0_DEV->altfuncset = gpio_0; 133 134 gpio_1 = (1<<10) /* Shield 1 UART 4 RXD */ 135 | (1<<14) /* Shield 1 UART 4 TXD */ 136 | (1<<15) /* Shield 1 I2C SCL SBCON3 */ 137 | (1<<0) /* ADC SPI 2 SS */ 138 | (1<<1) /* ADC SPI 2 MISO */ 139 | (1<<2) /* ADC SPI 2 MOSI */ 140 | (1<<3) /* ADC SPI 2 SCK */ 141 | (1<<5) /* USER BUTTON 0 */ 142 | (1<<6); /* USER BUTTON 1 */ 143 144 CMSDK_AHB_GPIO1_DEV->altfuncset = gpio_1; 145 146 gpio_2 = (1<<9) /* Shield 1 I2C SDA SBCON3 */ 147 | (1<<6) /* Shield 1 SPI 4 SS */ 148 | (1<<7) /* Shield 1 SPI 4 MOSI */ 149 | (1<<8) /* Shield 1 SPI 4 MISO */ 150 | (1<<12); /* Shield 1 SPI 4 SCK */ 151 152 CMSDK_AHB_GPIO2_DEV->altfuncset = gpio_2; 153 } 154 arm_mps2_pinmux_init(void)155static int arm_mps2_pinmux_init(void) 156 { 157 158 arm_mps2_pinmux_defaults(); 159 160 return 0; 161 } 162 163 SYS_INIT(arm_mps2_pinmux_init, PRE_KERNEL_1, 164 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); 165