1 /* 2 * Copyright (c) 2021 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __STM32MP1_GPIO_H__ 17 #define __STM32MP1_GPIO_H__ 18 19 #include "device_resource_if.h" 20 #include "gpio_core.h" 21 #include "hdf_device_desc.h" 22 #include "hdf_log.h" 23 #include "osal_io.h" 24 #include "osal_irq.h" 25 #include "osal_mem.h" 26 #include "osal_spinlock.h" 27 #include "stm32mp1xx_hal.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif /* __cplusplus */ 33 #endif /* __cplusplus */ 34 35 #define HDF_LOG_TAG gpio_stm32mp1xx 36 37 #define STM32MP1XX_GPIO_MODER(base) ((base) + 0x00) 38 #define STM32MP1XX_GPIO_IDR(base) ((base) + 0x10) 39 #define STM32MP1XX_GPIO_BSRR(base) ((base) + 0x18) 40 41 #define GROUP_MAX 13 42 #define BIT_MAX 16 43 44 struct GpioGroup { 45 volatile unsigned char *regBase; 46 EXTI_TypeDef *exitBase; 47 unsigned int index; 48 OsalIRQHandle irqFunc; 49 OsalSpinlock lock; 50 uint32_t irqSave; 51 }; 52 53 struct Mp1xxGpioCntlr { 54 struct GpioCntlr cntlr; 55 volatile unsigned char *regBase; 56 EXTI_TypeDef *exitBase; 57 uint32_t gpioPhyBase; 58 uint32_t gpioRegStep; 59 uint32_t irqPhyBase; 60 uint32_t iqrRegStep; 61 uint16_t groupNum; 62 uint16_t bitNum; 63 struct GpioGroup *groups; 64 }; 65 66 static struct Mp1xxGpioCntlr g_Mp1xxGpioCntlr = { 67 .groups = NULL, 68 .groupNum = GROUP_MAX, 69 .bitNum = BIT_MAX, 70 }; 71 72 enum pinNum { 73 PIN_0 = 0, 74 PIN_1 = 1, 75 PIN_2 = 2, 76 PIN_3 = 3, 77 PIN_4 = 4, 78 PIN_5 = 5, 79 PIN_6 = 6, 80 PIN_7 = 7, 81 PIN_8 = 8, 82 PIN_9 = 9, 83 PIN_10 = 10, 84 PIN_11 = 11, 85 PIN_12 = 12, 86 PIN_13 = 13, 87 PIN_14 = 14, 88 PIN_15 = 15, 89 }; 90 91 #ifdef __cplusplus 92 #if __cplusplus 93 } 94 #endif /* __cplusplus */ 95 #endif /* __cplusplus */ 96 97 #endif 98