RTEMS 6.1-rc6
Loading...
Searching...
No Matches
imx-gpio.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 2020 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef BSP_IMX_GPIO_H
29#define BSP_IMX_GPIO_H
30
31#include <rtems.h>
32#include <stdint.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif /* __cplusplus */
37
39struct imx_gpio;
40
42enum imx_gpio_mode {
43 IMX_GPIO_MODE_OUTPUT,
44 IMX_GPIO_MODE_INPUT,
45 IMX_GPIO_MODE_INTERRUPT_LOW,
46 IMX_GPIO_MODE_INTERRUPT_HIGH,
47 IMX_GPIO_MODE_INTERRUPT_RISING,
48 IMX_GPIO_MODE_INTERRUPT_FALLING,
49 IMX_GPIO_MODE_INTERRUPT_ANY_EDGE,
50};
51
61 volatile struct imx_gpio* gpio;
66 uint32_t mask;
68 unsigned int shift;
70 enum imx_gpio_mode mode;
76};
77
82void imx_gpio_init (struct imx_gpio_pin *pin);
83
104rtems_status_code imx_gpio_init_from_fdt_property_pointer(
105 struct imx_gpio_pin *pin,
106 const uint32_t *prop_pointer,
107 enum imx_gpio_mode mode,
108 const uint32_t **next_prop_pointer);
109
128rtems_status_code imx_gpio_init_from_fdt_property(
129 struct imx_gpio_pin *pin,
130 int node_offset,
131 const char *property,
132 enum imx_gpio_mode mode,
133 size_t index);
134
151rtems_vector_number imx_gpio_get_irq_of_node(
152 const void *fdt,
153 int node,
154 size_t index);
155
161struct imx_gpio *imx_gpio_get_by_index(unsigned idx);
162
166struct imx_gpio *imx_gpio_get_by_register(void *regs);
167
171const char *imx_gpio_get_name(struct imx_gpio *imx_gpio);
172
177void imx_gpio_set_output(struct imx_gpio_pin *pin, uint32_t set);
178
182void imx_gpio_toggle_output(struct imx_gpio_pin *pin);
183
188uint32_t imx_gpio_get_input(struct imx_gpio_pin *pin);
189
193void imx_gpio_int_disable(struct imx_gpio_pin *pin);
194
198void imx_gpio_int_enable(struct imx_gpio_pin *pin);
199
203uint32_t imx_gpio_get_isr(struct imx_gpio_pin *pin);
204
208void imx_gpio_clear_isr(struct imx_gpio_pin *pin, uint32_t clr);
209
214static inline uint32_t imx_gpio_get_active_level(struct imx_gpio_pin *pin)
215{
216 return (pin->is_active_low) ? 0 : 0xFFFFFFFFU;
217}
218
223static inline uint32_t imx_gpio_get_inactive_level(struct imx_gpio_pin *pin)
224{
225 return ~imx_gpio_get_active_level(pin);
226}
227
233#define IMX_GPIO1 (imx_gpio_get_by_index(0))
234#define IMX_GPIO2 (imx_gpio_get_by_index(1))
235#define IMX_GPIO3 (imx_gpio_get_by_index(2))
236#define IMX_GPIO4 (imx_gpio_get_by_index(3))
237#define IMX_GPIO5 (imx_gpio_get_by_index(4))
238#define IMX_GPIO6 (imx_gpio_get_by_index(5))
239#define IMX_GPIO7 (imx_gpio_get_by_index(6))
242#ifdef __cplusplus
243}
244#endif /* __cplusplus */
245
246#endif /* BSP_IMX_GPIO_H */
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
This header file defines the RTEMS Classic API.
Definition: imx-gpio.h:59
enum imx_gpio_mode mode
Definition: imx-gpio.h:70
bool is_active_low
Definition: imx-gpio.h:75
unsigned int shift
Definition: imx-gpio.h:68
volatile struct imx_gpio * gpio
Definition: imx-gpio.h:61
uint32_t mask
Definition: imx-gpio.h:66
Definition: imx-gpio.c:69