OpenBIC
OpenSource Bridge-IC
hal_gpio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef HAL_GPIO_H
18#define HAL_GPIO_H
19
20#include <drivers/gpio.h>
21#include <devicetree.h>
22
23#define GEN_ENUM(ENUM) ENUM,
24#define GEN_STR(STR) #STR,
25
26#if defined(CONFIG_GPIO_ASPEED)
27#define FOREACH_GPIO(APPLY) \
28 APPLY(GPIO0_A_D) \
29 APPLY(GPIO0_E_H) \
30 APPLY(GPIO0_I_L) \
31 APPLY(GPIO0_M_P) \
32 APPLY(GPIO0_Q_T) \
33 APPLY(GPIO0_U_V)
34
35#define TOTAL_GPIO_NUM 168
36#define GPIO_GROUP_NUM 6
37#define GPIO_GROUP_SIZE 32
38#define REG_GPIO_BASE 0x7e780000
39#elif (CONFIG_GPIO_NPCM4XX)
40#define FOREACH_GPIO(APPLY) \
41 APPLY(GPIO_0) \
42 APPLY(GPIO_1) \
43 APPLY(GPIO_2) \
44 APPLY(GPIO_3) \
45 APPLY(GPIO_4) \
46 APPLY(GPIO_5) \
47 APPLY(GPIO_6) \
48 APPLY(GPIO_7) \
49 APPLY(GPIO_8) \
50 APPLY(GPIO_9) \
51 APPLY(GPIO_A) \
52 APPLY(GPIO_B) \
53 APPLY(GPIO_C) \
54 APPLY(GPIO_D) \
55 APPLY(GPIO_E) \
56 APPLY(GPIO_F)
57
58#define TOTAL_GPIO_NUM 124
59#define GPIO_GROUP_NUM 16
60#define GPIO_GROUP_SIZE 8
61#define REG_GPIO_BASE 0x40081000
62#else
63#error "Unsupported GPIO driver"
64#endif /* CONFIG_GPIO_ASPEED */
65
67
68#define ENABLE 1
69#define DISABLE 0
70#define CHIP_GPIO 0
71#define CHIP_SGPIO 1
72#define GPIO_LOW 0
73#define GPIO_HIGH 1
74#define GPIO_STACK_SIZE 3072
75
76#define OPEN_DRAIN 0
77#define PUSH_PULL 1
78
79#if defined(CONFIG_GPIO_ASPEED)
80#define REG_ADC_BASE 0x7e6e9000
81#define REG_SCU 0x7E6E2000
82#define REG_DIRECTION_OFFSET 4
83#define REG_INTERRUPT_ENABLE_OFFSET 8
84#define REG_INTERRUPT_TYPE0_OFFSET 0x0C
85#define REG_INTERRUPT_TYPE1_OFFSET 0x10
86#define REG_INTERRUPT_TYPE2_OFFSET 0x14
87#elif (CONFIG_GPIO_NPCM4XX)
88#define REG_DEVALTX 0x400C3000
89#define REG_DIRECTION_OFFSET 2
90#else /* defined(CONFIG_GPIO_ASPEED) */
91#endif /* defined(CONFIG_GPIO_ASPEED) */
92
93extern uint32_t GPIO_GROUP_REG_ACCESS[];
95extern const int GPIO_MULTI_FUNC_CFG_SIZE;
96
97#define GPIO_CFG_SIZE 168
98typedef struct _GPIO_CFG_ {
99 uint8_t chip;
100 uint8_t number;
101 uint8_t is_init;
102 uint8_t is_latch;
103 uint16_t direction;
104 uint8_t status;
105 uint8_t property;
107 void (*int_cb)();
109
110typedef struct _SET_GPIO_VALUE_CFG_ {
111 uint8_t gpio_num;
112 uint8_t gpio_value;
114
115extern GPIO_CFG gpio_cfg[];
116
120};
121
125};
126
132};
133
134extern char *gpio_name[];
135
136extern uint8_t gpio_ind_to_num_table[];
137extern uint8_t gpio_ind_to_num_table_cnt;
138
139typedef struct _SCU_CFG_ {
140 int reg;
141 int value;
143
144//void gpio_int_cb_test(void);
145void gpio_show(void);
146int gpio_get(uint8_t);
147int gpio_set(uint8_t, uint8_t);
148bool pal_load_gpio_config(void);
149int gpio_init(const struct device *args);
150int gpio_interrupt_conf(uint8_t, gpio_flags_t);
151uint8_t gpio_get_reg_value(uint8_t gpio_num, uint8_t reg_offset);
152int gpio_conf(uint8_t gpio_num, int dir);
153int gpio_get_direction(uint8_t gpio_num);
154void scu_init(SCU_CFG cfg[], size_t size);
155
156#endif
#define GPIO_LOW
Definition: hal_gpio.h:72
void scu_init(SCU_CFG cfg[], size_t size)
Definition: hal_gpio.c:316
uint8_t gpio_get_reg_value(uint8_t gpio_num, uint8_t reg_offset)
Definition: hal_gpio.c:211
GPIO_CFG gpio_cfg[]
Definition: hal_gpio.c:50
GPIO_STATUS
Definition: hal_gpio.h:127
@ LOW_ACTIVE
Definition: hal_gpio.h:128
@ HIGH_ACTIVE
Definition: hal_gpio.h:130
@ LOW_INACTIVE
Definition: hal_gpio.h:129
@ HIGH_INACTIVE
Definition: hal_gpio.h:131
uint8_t gpio_ind_to_num_table[]
Definition: hal_gpio.c:44
uint32_t GPIO_MULTI_FUNC_PIN_CTL_REG_ACCESS[]
Definition: hal_gpio.c:84
void gpio_show(void)
int gpio_set(uint8_t, uint8_t)
Definition: hal_gpio.c:274
int gpio_get_direction(uint8_t gpio_num)
Definition: hal_gpio.c:241
POWER_STATUS
Definition: hal_gpio.h:117
@ POWER_OFF
Definition: hal_gpio.h:119
@ POWER_ON
Definition: hal_gpio.h:118
#define GPIO_HIGH
Definition: hal_gpio.h:73
int gpio_get(uint8_t)
Definition: hal_gpio.c:261
char * gpio_name[]
Definition: hal_gpio.c:49
int gpio_conf(uint8_t gpio_num, int dir)
Definition: hal_gpio.c:232
struct _SET_GPIO_VALUE_CFG_ SET_GPIO_VALUE_CFG
struct _GPIO_CFG_ GPIO_CFG
uint8_t gpio_ind_to_num_table_cnt
Definition: hal_gpio.c:45
int gpio_init(const struct device *args)
Definition: hal_gpio.c:332
CONTROL_STATUS
Definition: hal_gpio.h:122
@ CONTROL_ON
Definition: hal_gpio.h:123
@ CONTROL_OFF
Definition: hal_gpio.h:124
#define GEN_ENUM(ENUM)
Definition: hal_gpio.h:23
uint32_t GPIO_GROUP_REG_ACCESS[]
Definition: hal_gpio.c:55
GPIO_GROUP
Definition: hal_gpio.h:66
@ FOREACH_GPIO
Definition: hal_gpio.h:66
bool pal_load_gpio_config(void)
Definition: hal_gpio.c:327
const int GPIO_MULTI_FUNC_CFG_SIZE
Definition: hal_gpio.c:140
struct _SCU_CFG_ SCU_CFG
int gpio_interrupt_conf(uint8_t, gpio_flags_t)
Definition: hal_gpio.c:202
uint16_t size
Definition: pldm_oem.h:0
Definition: hal_gpio.h:98
uint8_t is_init
Definition: hal_gpio.h:101
uint8_t status
Definition: hal_gpio.h:104
int int_type
Definition: hal_gpio.h:106
uint8_t chip
Definition: hal_gpio.h:99
uint8_t number
Definition: hal_gpio.h:100
uint16_t direction
Definition: hal_gpio.h:103
uint8_t property
Definition: hal_gpio.h:105
void(* int_cb)()
Definition: hal_gpio.h:107
uint8_t is_latch
Definition: hal_gpio.h:102
Definition: hal_gpio.h:139
int value
Definition: hal_gpio.h:141
int reg
Definition: hal_gpio.h:140
Definition: hal_gpio.h:110
uint8_t gpio_num
Definition: hal_gpio.h:111
uint8_t gpio_value
Definition: hal_gpio.h:112