1e66c49faSVikas Manocha /* 2e66c49faSVikas Manocha * (C) Copyright 2016 3e66c49faSVikas Manocha * Vikas Manocha, <vikas.manocha@st.com> 4e66c49faSVikas Manocha * 5e66c49faSVikas Manocha * SPDX-License-Identifier: GPL-2.0+ 6e66c49faSVikas Manocha */ 7e66c49faSVikas Manocha 8e66c49faSVikas Manocha #ifndef _STM32_GPIO_H_ 9e66c49faSVikas Manocha #define _STM32_GPIO_H_ 10*280057bdSVikas Manocha #include <asm/gpio.h> 11e66c49faSVikas Manocha 12e66c49faSVikas Manocha enum stm32_gpio_port { 13e66c49faSVikas Manocha STM32_GPIO_PORT_A = 0, 14e66c49faSVikas Manocha STM32_GPIO_PORT_B, 15e66c49faSVikas Manocha STM32_GPIO_PORT_C, 16e66c49faSVikas Manocha STM32_GPIO_PORT_D, 17e66c49faSVikas Manocha STM32_GPIO_PORT_E, 18e66c49faSVikas Manocha STM32_GPIO_PORT_F, 19e66c49faSVikas Manocha STM32_GPIO_PORT_G, 20e66c49faSVikas Manocha STM32_GPIO_PORT_H, 21e66c49faSVikas Manocha STM32_GPIO_PORT_I 22e66c49faSVikas Manocha }; 23e66c49faSVikas Manocha 24e66c49faSVikas Manocha enum stm32_gpio_pin { 25e66c49faSVikas Manocha STM32_GPIO_PIN_0 = 0, 26e66c49faSVikas Manocha STM32_GPIO_PIN_1, 27e66c49faSVikas Manocha STM32_GPIO_PIN_2, 28e66c49faSVikas Manocha STM32_GPIO_PIN_3, 29e66c49faSVikas Manocha STM32_GPIO_PIN_4, 30e66c49faSVikas Manocha STM32_GPIO_PIN_5, 31e66c49faSVikas Manocha STM32_GPIO_PIN_6, 32e66c49faSVikas Manocha STM32_GPIO_PIN_7, 33e66c49faSVikas Manocha STM32_GPIO_PIN_8, 34e66c49faSVikas Manocha STM32_GPIO_PIN_9, 35e66c49faSVikas Manocha STM32_GPIO_PIN_10, 36e66c49faSVikas Manocha STM32_GPIO_PIN_11, 37e66c49faSVikas Manocha STM32_GPIO_PIN_12, 38e66c49faSVikas Manocha STM32_GPIO_PIN_13, 39e66c49faSVikas Manocha STM32_GPIO_PIN_14, 40e66c49faSVikas Manocha STM32_GPIO_PIN_15 41e66c49faSVikas Manocha }; 42e66c49faSVikas Manocha 43e66c49faSVikas Manocha enum stm32_gpio_mode { 44e66c49faSVikas Manocha STM32_GPIO_MODE_IN = 0, 45e66c49faSVikas Manocha STM32_GPIO_MODE_OUT, 46e66c49faSVikas Manocha STM32_GPIO_MODE_AF, 47e66c49faSVikas Manocha STM32_GPIO_MODE_AN 48e66c49faSVikas Manocha }; 49e66c49faSVikas Manocha 50e66c49faSVikas Manocha enum stm32_gpio_otype { 51e66c49faSVikas Manocha STM32_GPIO_OTYPE_PP = 0, 52e66c49faSVikas Manocha STM32_GPIO_OTYPE_OD 53e66c49faSVikas Manocha }; 54e66c49faSVikas Manocha 55e66c49faSVikas Manocha enum stm32_gpio_speed { 56e66c49faSVikas Manocha STM32_GPIO_SPEED_2M = 0, 57e66c49faSVikas Manocha STM32_GPIO_SPEED_25M, 58e66c49faSVikas Manocha STM32_GPIO_SPEED_50M, 59e66c49faSVikas Manocha STM32_GPIO_SPEED_100M 60e66c49faSVikas Manocha }; 61e66c49faSVikas Manocha 62e66c49faSVikas Manocha enum stm32_gpio_pupd { 63e66c49faSVikas Manocha STM32_GPIO_PUPD_NO = 0, 64e66c49faSVikas Manocha STM32_GPIO_PUPD_UP, 65e66c49faSVikas Manocha STM32_GPIO_PUPD_DOWN 66e66c49faSVikas Manocha }; 67e66c49faSVikas Manocha 68e66c49faSVikas Manocha enum stm32_gpio_af { 69e66c49faSVikas Manocha STM32_GPIO_AF0 = 0, 70e66c49faSVikas Manocha STM32_GPIO_AF1, 71e66c49faSVikas Manocha STM32_GPIO_AF2, 72e66c49faSVikas Manocha STM32_GPIO_AF3, 73e66c49faSVikas Manocha STM32_GPIO_AF4, 74e66c49faSVikas Manocha STM32_GPIO_AF5, 75e66c49faSVikas Manocha STM32_GPIO_AF6, 76e66c49faSVikas Manocha STM32_GPIO_AF7, 77e66c49faSVikas Manocha STM32_GPIO_AF8, 78e66c49faSVikas Manocha STM32_GPIO_AF9, 79e66c49faSVikas Manocha STM32_GPIO_AF10, 80e66c49faSVikas Manocha STM32_GPIO_AF11, 81e66c49faSVikas Manocha STM32_GPIO_AF12, 82e66c49faSVikas Manocha STM32_GPIO_AF13, 83e66c49faSVikas Manocha STM32_GPIO_AF14, 84e66c49faSVikas Manocha STM32_GPIO_AF15 85e66c49faSVikas Manocha }; 86e66c49faSVikas Manocha 87e66c49faSVikas Manocha struct stm32_gpio_dsc { 88e66c49faSVikas Manocha enum stm32_gpio_port port; 89e66c49faSVikas Manocha enum stm32_gpio_pin pin; 90e66c49faSVikas Manocha }; 91e66c49faSVikas Manocha 92e66c49faSVikas Manocha struct stm32_gpio_ctl { 93e66c49faSVikas Manocha enum stm32_gpio_mode mode; 94e66c49faSVikas Manocha enum stm32_gpio_otype otype; 95e66c49faSVikas Manocha enum stm32_gpio_speed speed; 96e66c49faSVikas Manocha enum stm32_gpio_pupd pupd; 97e66c49faSVikas Manocha enum stm32_gpio_af af; 98e66c49faSVikas Manocha }; 99e66c49faSVikas Manocha 10077417102SVikas Manocha struct stm32_gpio_regs { 10177417102SVikas Manocha u32 moder; /* GPIO port mode */ 10277417102SVikas Manocha u32 otyper; /* GPIO port output type */ 10377417102SVikas Manocha u32 ospeedr; /* GPIO port output speed */ 10477417102SVikas Manocha u32 pupdr; /* GPIO port pull-up/pull-down */ 10577417102SVikas Manocha u32 idr; /* GPIO port input data */ 10677417102SVikas Manocha u32 odr; /* GPIO port output data */ 10777417102SVikas Manocha u32 bsrr; /* GPIO port bit set/reset */ 10877417102SVikas Manocha u32 lckr; /* GPIO port configuration lock */ 10977417102SVikas Manocha u32 afr[2]; /* GPIO alternate function */ 11077417102SVikas Manocha }; 11177417102SVikas Manocha 11277417102SVikas Manocha struct stm32_gpio_priv { 11377417102SVikas Manocha struct stm32_gpio_regs *regs; 11477417102SVikas Manocha }; 11577417102SVikas Manocha 116e66c49faSVikas Manocha static inline unsigned stm32_gpio_to_port(unsigned gpio) 117e66c49faSVikas Manocha { 118e66c49faSVikas Manocha return gpio / 16; 119e66c49faSVikas Manocha } 120e66c49faSVikas Manocha 121e66c49faSVikas Manocha static inline unsigned stm32_gpio_to_pin(unsigned gpio) 122e66c49faSVikas Manocha { 123e66c49faSVikas Manocha return gpio % 16; 124e66c49faSVikas Manocha } 125e66c49faSVikas Manocha 126e66c49faSVikas Manocha #endif /* _STM32_GPIO_H_ */ 127