blob: 9f9e99faa24d9813c77147f557ece476fdf4d330 [file] [log] [blame]
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08001/*
2 * Copyright (C) 2014-2018 Amlogic, Inc. All rights reserved.
3 *
4 * All information contained herein is Amlogic confidential.
5 *
6 * This software is provided to you pursuant to Software License Agreement
7 * (SLA) with Amlogic Inc ("Amlogic"). This software may be used
8 * only in accordance with the terms of this agreement.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification is strictly prohibited without prior written permission from
12 * Amlogic.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27/*
28 * gpio header file
29 */
30
31#ifndef _GPIO_H_
32#define _GPIO_H_
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37#include <gpio-data.h>
38
39/* trigger type for GPIO IRQ */
40#define IRQF_TRIGGER_NONE 0x00000000
41#define IRQF_TRIGGER_RISING 0x00000001
42#define IRQF_TRIGGER_FALLING 0x00000002
43#define IRQF_TRIGGER_HIGH 0x00000004
44#define IRQF_TRIGGER_LOW 0x00000008
45#define IRQF_TRIGGER_BOTH 0x00000010
46
47/* pin features */
48#define PINF_CONFIG_BIAS_DISABLE 0x00000001
49#define PINF_CONFIG_BIAS_PULL_UP 0x00000002
50#define PINF_CONFIG_BIAS_PULL_DOWN 0x00000004
51#define PINF_CONFIG_DRV_STRENGTH_0 0x00000008
52#define PINF_CONFIG_DRV_STRENGTH_1 0x00000010
53#define PINF_CONFIG_DRV_STRENGTH_2 0x00000020
54#define PINF_CONFIG_DRV_STRENGTH_3 0x00000040
55
56#define PINF_CONFIG_DRV_MASK 0x00000078
57
58/**
59 * enum GpioDirtype - type of gpio direction
60 */
61 enum GpioDirType {
62 GPIO_DIR_OUT = 0x0,
63 GPIO_DIR_IN,
64 GPIO_DIR_INVALID,
65 };
66
67/**
68 * enum GpioOutLevelType - type of gpio output level
69 */
70 enum GpioOutLevelType {
71 GPIO_LEVEL_LOW = 0x0,
72 GPIO_LEVEL_HIGH,
73 GPIO_LEVEL_INVALID,
74 };
75
76/**
77 * enum PinMuxType - type of pin mux
78 */
79 enum PinMuxType {
80 PIN_FUNC0 = 0x0,
81 PIN_FUNC1,
82 PIN_FUNC2,
83 PIN_FUNC3,
84 PIN_FUNC4,
85 PIN_FUNC5,
86 PIN_FUNC6,
87 PIN_FUNC7,
88 PIN_FUNC_INVALID,
89 };
90
91 typedef void (*GpioIRQHandler_t)(void);
92
93/**
94 * xGpioSetDir() - Set gpio direction
95 * @gpio: GPIO number
96 * @dir : direction value, and defined in "enum GpioDirType"
97 *
98 * Returns 0 on success, negative value on error.
99 */
100 extern int xGpioSetDir(uint16_t gpio, enum GpioDirType dir);
101
102/**
103 * xGpioSetValue() - Configure output level on GPIO pin
104 * @gpio : GPIO number
105 * @level : level value, and defined in "enum GpioOutLevelType"
106 *
107 * Returns 0 on success, negative value on error.
108 */
109 extern int xGpioSetValue(uint16_t gpio, enum GpioOutLevelType level);
110
111/**
112 * xGpioGetValue() - Sample GPIO pin and return it's value
113 * @gpio: GPIO number
114 *
115 */
116 extern int xGpioGetValue(uint16_t gpio);
117
118/**
119 * xPinconfSet() - Configure pin features
120 * @gpio : GPIO number
121 * @flags : pin features
122 *
123 * Returns 0 on success, negative value on error.
124 */
125 extern int xPinconfSet(uint16_t gpio, uint32_t flags);
126
127/**
128 * xPinmuxSet() - Select function for per pin
129 * @gpio : GPIO number
130 * @func : function value, and defined in "enum PinMuxType"
131 *
132 * Returns 0 on success, negative value on error.
133 */
134 extern int xPinmuxSet(uint16_t gpio, enum PinMuxType func);
135
136/**
137 * vGpioIRQInit() - initialize gpio IRQ
138 *
139 */
140 extern void vGpioIRQInit(void);
141
142/**
143 * xRequestGpioIRQ() - Request IRQ for gpio
144 * @gpio : GPIO number
145 * @handler: interrupt handler function
146 * @flags : Trigger type
147 *
148 * Returns 0 on success, negative value on error.
149 *
150 * Note: can't be called from interrupt context
151 */
152 extern int32_t xRequestGpioIRQ(uint16_t gpio, GpioIRQHandler_t handler,
153 uint32_t flags);
154
155/**
156 * vFreeGpioIRQ() - Free IRQ for gpio
157 * @gpio : GPIO number
158 *
159 * Note: can't be called from interrupt context
160 */
161 extern void vFreeGpioIRQ(uint16_t gpio);
162
163/**
164 * vEnableGpioIRQ() - Enable IRQ for gpio
165 * @gpio : GPIO number
166 *
167 */
168 extern void vEnableGpioIRQ(uint16_t gpio);
169
170/**
171 * vDisableGpioIRQ() - Disable IRQ for gpio
172 * @gpio : GPIO number
173 *
174 */
175 extern void vDisableGpioIRQ(uint16_t gpio);
176
177/**
178 * restore and backup irqreg
179 *
180 */
181 extern void vRestoreGpioIrqReg(void);
182 extern void vBackupAndClearGpioIrqReg(void);
183#ifdef __cplusplus
184}
185#endif
186#endif /* _GPIO_H_ */