1 /*
2 * pinmux.c
3 *
4 * configure the device pins for different peripheral signals
5 *
6 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * This file was automatically generated on 7/21/2014 at 3:06:20 PM
40 * by TI PinMux version 3.0.334
41 * (Then modified to meet Zephyr coding style)
42 */
43
44 /*
45 * TI Recommends use of the PinMux utility to ensure consistent configuration
46 * of pins: http://processors.wiki.ti.com/index.php/TI_PinMux_Tool
47 *
48 * Zephyr GPIO API however allows runtime configuration by applications.
49 *
50 * For the TI CC32XX port we leverage this output file
51 * from the PinMux tool, and guard sections based on Kconfig variables.
52 *
53 * The individual (uart/gpio) driver init/configuration functions
54 * therefore assume pinmux initialization is done here rather in the drivers
55 * at runtime.
56 */
57
58 #include <init.h>
59
60 #include <drivers/pinmux.h>
61
62 #include <inc/hw_types.h>
63 #include <inc/hw_memmap.h>
64 #include <inc/hw_gpio.h>
65 #include <driverlib/pin.h>
66 #include <driverlib/rom.h>
67 #include <driverlib/rom_map.h>
68 #include <driverlib/gpio.h>
69 #include <driverlib/prcm.h>
70 #include <driverlib/i2c.h>
71
72 /* Defines taken from SimpleLink SDK's I2CCC32XX.h: */
73 /*
74 * Macros defining possible I2C signal pin mux options
75 *
76 * The bits in the pin mode macros are as follows:
77 * The lower 8 bits of the macro refer to the pin, offset by 1, to match
78 * driverlib pin defines. For example, I2C_CC32XX_PIN_01_I2C_SCL & 0xff = 0,
79 * which equals PIN_01 in driverlib pin.h. By matching the PIN_xx defines in
80 * driverlib pin.h, we can pass the pin directly to the driverlib functions.
81 * The upper 8 bits of the macro correspond to the pin mux confg mode
82 * value for the pin to operate in the I2C mode. For example, pin 1 is
83 * configured with mode 1 to operate as I2C_SCL.
84 */
85 #define I2C_CC32XX_PIN_01_I2C_SCL 0x100 /*!< PIN 1 is used for I2C_SCL */
86 #define I2C_CC32XX_PIN_02_I2C_SDA 0x101 /*!< PIN 2 is used for I2C_SDA */
87 #define I2C_CC32XX_PIN_03_I2C_SCL 0x502 /*!< PIN 3 is used for I2C_SCL */
88 #define I2C_CC32XX_PIN_04_I2C_SDA 0x503 /*!< PIN 4 is used for I2C_SDA */
89 #define I2C_CC32XX_PIN_05_I2C_SCL 0x504 /*!< PIN 5 is used for I2C_SCL */
90 #define I2C_CC32XX_PIN_06_I2C_SDA 0x505 /*!< PIN 6 is used for I2C_SDA */
91 #define I2C_CC32XX_PIN_16_I2C_SCL 0x90F /*!< PIN 16 is used for I2C_SCL */
92 #define I2C_CC32XX_PIN_17_I2C_SDA 0x910 /*!< PIN 17 is used for I2C_SDA */
93
pinmux_initialize(const struct device * port)94 int pinmux_initialize(const struct device *port)
95 {
96 ARG_UNUSED(port);
97
98 #ifdef CONFIG_UART_CC32XX
99 /* Configure PIN_55 for UART0 UART0_TX */
100 MAP_PinTypeUART(PIN_55, PIN_MODE_3);
101
102 /* Configure PIN_57 for UART0 UART0_RX */
103 MAP_PinTypeUART(PIN_57, PIN_MODE_3);
104 #endif
105
106 /* Enable Peripheral Clocks */
107 MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK);
108
109 /* The following enables the 3 LEDs for the blinking samples */
110
111 /* Configure PIN_64 for GPIOOutput */
112 MAP_PinTypeGPIO(PIN_64, PIN_MODE_0, false);
113 MAP_GPIODirModeSet(GPIOA1_BASE, 0x2, GPIO_DIR_MODE_OUT);
114
115 /* Configure PIN_01 for GPIOOutput */
116 MAP_PinTypeGPIO(PIN_01, PIN_MODE_0, false);
117 MAP_GPIODirModeSet(GPIOA1_BASE, 0x4, GPIO_DIR_MODE_OUT);
118
119 /* Configure PIN_02 for GPIOOutput */
120 MAP_PinTypeGPIO(PIN_02, PIN_MODE_0, false);
121 MAP_GPIODirModeSet(GPIOA1_BASE, 0x8, GPIO_DIR_MODE_OUT);
122
123 /* SW3: Configure PIN_04 (GPIO13) for GPIOInput */
124 MAP_PinTypeGPIO(PIN_04, PIN_MODE_0, false);
125 MAP_GPIODirModeSet(GPIOA1_BASE, 0x20, GPIO_DIR_MODE_IN);
126
127 MAP_PRCMPeripheralClkEnable(PRCM_GPIOA2, PRCM_RUN_MODE_CLK);
128
129 /* SW2: Configure PIN_15 (GPIO22) for GPIOInput */
130 MAP_PinTypeGPIO(PIN_15, PIN_MODE_0, false);
131 MAP_GPIODirModeSet(GPIOA2_BASE, 0x40, GPIO_DIR_MODE_IN);
132
133 MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK);
134
135 #ifdef CONFIG_I2C_CC32XX
136 {
137 unsigned long pin;
138 unsigned long mode;
139
140 /* Enable the I2C module clocks and wait for completion:*/
141 MAP_PRCMPeripheralClkEnable(PRCM_I2CA0,
142 PRCM_RUN_MODE_CLK |
143 PRCM_SLP_MODE_CLK);
144 while (!MAP_PRCMPeripheralStatusGet(PRCM_I2CA0)) {
145 }
146
147 pin = I2C_CC32XX_PIN_01_I2C_SCL & 0xff;
148 mode = (I2C_CC32XX_PIN_01_I2C_SCL >> 8) & 0xff;
149 MAP_PinTypeI2C(pin, mode);
150
151 pin = I2C_CC32XX_PIN_02_I2C_SDA & 0xff;
152 mode = (I2C_CC32XX_PIN_02_I2C_SDA >> 8) & 0xff;
153 MAP_PinTypeI2C(pin, mode);
154 }
155 #endif
156
157 return 0;
158 }
159
160 SYS_INIT(pinmux_initialize, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
161