blob: 5761222fcbae55304b063fcf7863c8c228ccb121 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2012 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <debug.h>
24#include <assert.h>
25#include <dev/gpio.h>
26#include <platform/gpio.h>
27#include "ti_driverlib.h"
28
29static void *port_to_pointer(unsigned int port)
30{
31 switch (port) {
32 default:
33 case GPIO_PORT_A:
34 return (void *)GPIO_PORTA_AHB_BASE;
35 case GPIO_PORT_B:
36 return (void *)GPIO_PORTB_AHB_BASE;
37 case GPIO_PORT_C:
38 return (void *)GPIO_PORTC_AHB_BASE;
39 case GPIO_PORT_D:
40 return (void *)GPIO_PORTD_AHB_BASE;
41 case GPIO_PORT_E:
42 return (void *)GPIO_PORTE_AHB_BASE;
43 case GPIO_PORT_F:
44 return (void *)GPIO_PORTF_AHB_BASE;
45 case GPIO_PORT_G:
46 return (void *)GPIO_PORTG_AHB_BASE;
47 case GPIO_PORT_H:
48 return (void *)GPIO_PORTH_AHB_BASE;
49 case GPIO_PORT_J:
50 return (void *)GPIO_PORTJ_BASE;
51 case GPIO_PORT_K:
52 return (void *)GPIO_PORTK_BASE;
53 case GPIO_PORT_L:
54 return (void *)GPIO_PORTL_BASE;
55 case GPIO_PORT_M:
56 return (void *)GPIO_PORTM_BASE;
57 case GPIO_PORT_N:
58 return (void *)GPIO_PORTN_BASE;
59 case GPIO_PORT_P:
60 return (void *)GPIO_PORTP_BASE;
61 case GPIO_PORT_Q:
62 return (void *)GPIO_PORTQ_BASE;
63 }
64}
65
66void stellaris_gpio_early_init(void)
67{
68 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOA);
69 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOB);
70 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOC);
71 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
72 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOE);
73 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOF);
74 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOG);
75 SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOH);
76
77 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
78 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
79 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
80 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
81 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
82 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
83 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
84 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
85 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
86}
87
88void stellaris_gpio_init(void)
89{
90}
91
92#if 0
93int gpio_config(unsigned nr, unsigned flags)
94{
95 uint port = GPIO_PORT(nr);
96 uint pin = GPIO_PIN(nr);
97
98 enable_port(port);
99
100 GPIO_InitTypeDef init;
101 init.GPIO_Speed = GPIO_Speed_50MHz;
102
103 init.GPIO_Pin = (1 << pin);
104
105 if (flags & GPIO_STM32_AF) {
106 if (flags & GPIO_STM32_OD)
107 init.GPIO_Mode = GPIO_Mode_Out_OD;
108 else
109 init.GPIO_Mode = GPIO_Mode_AF_PP;
110 } else if (flags & GPIO_OUTPUT) {
111 if (flags & GPIO_STM32_OD)
112 init.GPIO_Mode = GPIO_Mode_Out_OD;
113 else
114 init.GPIO_Mode = GPIO_Mode_Out_PP;
115 } else { // GPIO_INPUT
116 if (flags & GPIO_PULLUP) {
117 init.GPIO_Mode = GPIO_Mode_IPU;
118 } else if (flags & GPIO_PULLDOWN) {
119 init.GPIO_Mode = GPIO_Mode_IPD;
120 } else {
121 init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
122 }
123 }
124
125 GPIO_Init(port_to_pointer(port), &init);
126
127 return 0;
128}
129#endif
130
131void gpio_set(unsigned nr, unsigned on)
132{
133 GPIOPinWrite((unsigned int)port_to_pointer(GPIO_PORT(nr)), 1 << GPIO_PIN(nr), on ? (1 << GPIO_PIN(nr)) : 0);
134}
135
136int gpio_get(unsigned nr)
137{
138 return GPIOPinRead((unsigned int)port_to_pointer(GPIO_PORT(nr)), 1 << GPIO_PIN(nr));
139}
140
141