1 /*
2  * Copyright (c) 2016 Linaro Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_MMIO32_H_
8 #define ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_MMIO32_H_
9 
10 #include <zephyr/device.h>
11 #include <zephyr/drivers/gpio.h>
12 #include <zephyr/types.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 extern const struct gpio_driver_api gpio_mmio32_api;
19 
20 struct gpio_mmio32_config {
21 	/* gpio_driver_config needs to be first */
22 	struct gpio_driver_config common;
23 	volatile uint32_t *reg;
24 	uint32_t mask;
25 };
26 
27 struct gpio_mmio32_context {
28 	/* gpio_driver_data needs to be first */
29 	struct gpio_driver_data common;
30 	const struct gpio_mmio32_config *config;
31 };
32 
33 int gpio_mmio32_init(const struct device *dev);
34 
35 #ifdef CONFIG_GPIO_MMIO32
36 
37 /**
38  * Create a device object for accessing a simple 32-bit i/o register using the
39  * same APIs as GPIO drivers.
40  *
41  * @param node_id   The devicetree node identifier.
42  * @param _address  The address of the 32-bit i/o register the device will
43  *		    provide access to.
44  * @param _mask     Mask of bits in the register that it is valid to access.
45  *		    E.g. 0xffffffffu to allow access to all of them.
46  *
47  */
48 #define GPIO_MMIO32_INIT(node_id, _address, _mask)					\
49 static struct gpio_mmio32_context _CONCAT(Z_DEVICE_DT_DEV_ID(node_id), _ctx);		\
50 											\
51 static const struct gpio_mmio32_config _CONCAT(Z_DEVICE_DT_DEV_ID(node_id), _cfg) = {	\
52 	.common = {									\
53 		 .port_pin_mask = _mask,						\
54 	},										\
55 	.reg	= (volatile uint32_t *)_address,					\
56 	.mask	= _mask,								\
57 };											\
58 											\
59 DEVICE_DT_DEFINE(node_id,								\
60 		    &gpio_mmio32_init,							\
61 		    NULL,								\
62 		    &_CONCAT(Z_DEVICE_DT_DEV_ID(node_id), _ctx),			\
63 		    &_CONCAT(Z_DEVICE_DT_DEV_ID(node_id), _cfg),			\
64 		    PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,			\
65 		    &gpio_mmio32_api)
66 
67 
68 #else /* CONFIG_GPIO_MMIO32 */
69 
70 /* Null definition for when support not configured into kernel */
71 #define GPIO_MMIO32_INIT(node_id, _address, _mask)
72 
73 #endif
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_MMIO32_H_ */
80