blob: 7c5bef90af49fa788e6e39b7ccdffe364d663cfe [file] [log] [blame]
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08001/*
yang.li24770372022-01-11 15:21:49 +08002 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08003 *
yang.li24770372022-01-11 15:21:49 +08004 * SPDX-License-Identifier: MIT
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08005 */
6
7#ifndef _GPIO_H_
8#define _GPIO_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13#include <gpio-data.h>
14
15/* trigger type for GPIO IRQ */
16#define IRQF_TRIGGER_NONE 0x00000000
17#define IRQF_TRIGGER_RISING 0x00000001
18#define IRQF_TRIGGER_FALLING 0x00000002
19#define IRQF_TRIGGER_HIGH 0x00000004
20#define IRQF_TRIGGER_LOW 0x00000008
21#define IRQF_TRIGGER_BOTH 0x00000010
22
23/* pin features */
24#define PINF_CONFIG_BIAS_DISABLE 0x00000001
25#define PINF_CONFIG_BIAS_PULL_UP 0x00000002
26#define PINF_CONFIG_BIAS_PULL_DOWN 0x00000004
27#define PINF_CONFIG_DRV_STRENGTH_0 0x00000008
28#define PINF_CONFIG_DRV_STRENGTH_1 0x00000010
29#define PINF_CONFIG_DRV_STRENGTH_2 0x00000020
30#define PINF_CONFIG_DRV_STRENGTH_3 0x00000040
31
32#define PINF_CONFIG_DRV_MASK 0x00000078
33
34/**
35 * enum GpioDirtype - type of gpio direction
36 */
37 enum GpioDirType {
38 GPIO_DIR_OUT = 0x0,
39 GPIO_DIR_IN,
40 GPIO_DIR_INVALID,
41 };
42
43/**
44 * enum GpioOutLevelType - type of gpio output level
45 */
46 enum GpioOutLevelType {
47 GPIO_LEVEL_LOW = 0x0,
48 GPIO_LEVEL_HIGH,
49 GPIO_LEVEL_INVALID,
50 };
51
52/**
53 * enum PinMuxType - type of pin mux
54 */
55 enum PinMuxType {
56 PIN_FUNC0 = 0x0,
57 PIN_FUNC1,
58 PIN_FUNC2,
59 PIN_FUNC3,
60 PIN_FUNC4,
61 PIN_FUNC5,
62 PIN_FUNC6,
63 PIN_FUNC7,
64 PIN_FUNC_INVALID,
65 };
66
67 typedef void (*GpioIRQHandler_t)(void);
68
69/**
70 * xGpioSetDir() - Set gpio direction
71 * @gpio: GPIO number
72 * @dir : direction value, and defined in "enum GpioDirType"
73 *
74 * Returns 0 on success, negative value on error.
75 */
76 extern int xGpioSetDir(uint16_t gpio, enum GpioDirType dir);
77
78/**
79 * xGpioSetValue() - Configure output level on GPIO pin
80 * @gpio : GPIO number
81 * @level : level value, and defined in "enum GpioOutLevelType"
82 *
83 * Returns 0 on success, negative value on error.
84 */
85 extern int xGpioSetValue(uint16_t gpio, enum GpioOutLevelType level);
86
87/**
88 * xGpioGetValue() - Sample GPIO pin and return it's value
89 * @gpio: GPIO number
90 *
91 */
92 extern int xGpioGetValue(uint16_t gpio);
93
94/**
95 * xPinconfSet() - Configure pin features
96 * @gpio : GPIO number
97 * @flags : pin features
98 *
99 * Returns 0 on success, negative value on error.
100 */
101 extern int xPinconfSet(uint16_t gpio, uint32_t flags);
102
103/**
104 * xPinmuxSet() - Select function for per pin
105 * @gpio : GPIO number
106 * @func : function value, and defined in "enum PinMuxType"
107 *
108 * Returns 0 on success, negative value on error.
109 */
110 extern int xPinmuxSet(uint16_t gpio, enum PinMuxType func);
111
112/**
113 * vGpioIRQInit() - initialize gpio IRQ
114 *
115 */
116 extern void vGpioIRQInit(void);
117
118/**
119 * xRequestGpioIRQ() - Request IRQ for gpio
120 * @gpio : GPIO number
121 * @handler: interrupt handler function
122 * @flags : Trigger type
123 *
124 * Returns 0 on success, negative value on error.
125 *
126 * Note: can't be called from interrupt context
127 */
128 extern int32_t xRequestGpioIRQ(uint16_t gpio, GpioIRQHandler_t handler,
129 uint32_t flags);
130
131/**
132 * vFreeGpioIRQ() - Free IRQ for gpio
133 * @gpio : GPIO number
134 *
135 * Note: can't be called from interrupt context
136 */
137 extern void vFreeGpioIRQ(uint16_t gpio);
138
139/**
140 * vEnableGpioIRQ() - Enable IRQ for gpio
141 * @gpio : GPIO number
142 *
143 */
144 extern void vEnableGpioIRQ(uint16_t gpio);
145
146/**
147 * vDisableGpioIRQ() - Disable IRQ for gpio
148 * @gpio : GPIO number
149 *
150 */
151 extern void vDisableGpioIRQ(uint16_t gpio);
152
153/**
154 * restore and backup irqreg
155 *
156 */
157 extern void vRestoreGpioIrqReg(void);
158 extern void vBackupAndClearGpioIrqReg(void);
159#ifdef __cplusplus
160}
161#endif
162#endif /* _GPIO_H_ */