xref: /openbmc/qemu/include/hw/gpio/stm32l4x5_gpio.h (revision 1c38129d)
11cdcfb6eSInès Varhol /*
21cdcfb6eSInès Varhol  * STM32L4x5 GPIO (General Purpose Input/Ouput)
31cdcfb6eSInès Varhol  *
41cdcfb6eSInès Varhol  * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr>
51cdcfb6eSInès Varhol  * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr>
61cdcfb6eSInès Varhol  *
71cdcfb6eSInès Varhol  * SPDX-License-Identifier: GPL-2.0-or-later
81cdcfb6eSInès Varhol  *
91cdcfb6eSInès Varhol  * This work is licensed under the terms of the GNU GPL, version 2 or later.
101cdcfb6eSInès Varhol  * See the COPYING file in the top-level directory.
111cdcfb6eSInès Varhol  */
121cdcfb6eSInès Varhol 
131cdcfb6eSInès Varhol /*
141cdcfb6eSInès Varhol  * The reference used is the STMicroElectronics RM0351 Reference manual
151cdcfb6eSInès Varhol  * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs.
161cdcfb6eSInès Varhol  * https://www.st.com/en/microcontrollers-microprocessors/stm32l4x5/documentation.html
171cdcfb6eSInès Varhol  */
181cdcfb6eSInès Varhol 
191cdcfb6eSInès Varhol #ifndef HW_STM32L4X5_GPIO_H
201cdcfb6eSInès Varhol #define HW_STM32L4X5_GPIO_H
211cdcfb6eSInès Varhol 
221cdcfb6eSInès Varhol #include "hw/sysbus.h"
231cdcfb6eSInès Varhol #include "qom/object.h"
241cdcfb6eSInès Varhol 
251cdcfb6eSInès Varhol #define TYPE_STM32L4X5_GPIO "stm32l4x5-gpio"
261cdcfb6eSInès Varhol OBJECT_DECLARE_SIMPLE_TYPE(Stm32l4x5GpioState, STM32L4X5_GPIO)
271cdcfb6eSInès Varhol 
28*1c38129dSInès Varhol #define NUM_GPIOS 8
291cdcfb6eSInès Varhol #define GPIO_NUM_PINS 16
301cdcfb6eSInès Varhol 
311cdcfb6eSInès Varhol struct Stm32l4x5GpioState {
321cdcfb6eSInès Varhol     SysBusDevice parent_obj;
331cdcfb6eSInès Varhol 
341cdcfb6eSInès Varhol     MemoryRegion mmio;
351cdcfb6eSInès Varhol 
361cdcfb6eSInès Varhol     /* GPIO registers */
371cdcfb6eSInès Varhol     uint32_t moder;
381cdcfb6eSInès Varhol     uint32_t otyper;
391cdcfb6eSInès Varhol     uint32_t ospeedr;
401cdcfb6eSInès Varhol     uint32_t pupdr;
411cdcfb6eSInès Varhol     uint32_t idr;
421cdcfb6eSInès Varhol     uint32_t odr;
431cdcfb6eSInès Varhol     uint32_t lckr;
441cdcfb6eSInès Varhol     uint32_t afrl;
451cdcfb6eSInès Varhol     uint32_t afrh;
461cdcfb6eSInès Varhol     uint32_t ascr;
471cdcfb6eSInès Varhol 
481cdcfb6eSInès Varhol     /* GPIO registers reset values */
491cdcfb6eSInès Varhol     uint32_t moder_reset;
501cdcfb6eSInès Varhol     uint32_t ospeedr_reset;
511cdcfb6eSInès Varhol     uint32_t pupdr_reset;
521cdcfb6eSInès Varhol 
531cdcfb6eSInès Varhol     /*
541cdcfb6eSInès Varhol      * External driving of pins.
551cdcfb6eSInès Varhol      * The pins can be set externally through the device
561cdcfb6eSInès Varhol      * anonymous input GPIOs lines under certain conditions.
571cdcfb6eSInès Varhol      * The pin must not be in push-pull output mode,
581cdcfb6eSInès Varhol      * and can't be set high in open-drain mode.
591cdcfb6eSInès Varhol      * Pins driven externally and configured to
601cdcfb6eSInès Varhol      * output mode will in general be "disconnected"
611cdcfb6eSInès Varhol      * (see `get_gpio_pinmask_to_disconnect()`)
621cdcfb6eSInès Varhol      */
631cdcfb6eSInès Varhol     uint16_t disconnected_pins;
641cdcfb6eSInès Varhol     uint16_t pins_connected_high;
651cdcfb6eSInès Varhol 
661cdcfb6eSInès Varhol     char *name;
671cdcfb6eSInès Varhol     Clock *clk;
681cdcfb6eSInès Varhol     qemu_irq pin[GPIO_NUM_PINS];
691cdcfb6eSInès Varhol };
701cdcfb6eSInès Varhol 
711cdcfb6eSInès Varhol #endif
72