Interfacing GPIO hardware modules

This section describes the interface between the GPIO hardware modules.

The GPIO hardware module sends data to and receives data from the GPIO hardware. The two key structures for interfacing io-gpio are gpio_hwmod_t and hwmod_funcs_t.

GPIO hardware module configuration (gpio_hwmod_t)

This structure describes a loaded GPIO hardware module instance, including its configuration parameters, helper interfaces provided by the resource manager, and the hardware-specific operations implemented by the module.

The definition of gpio_hwmod_t is:

#include <hw/gpio_hw.h>

typedef struct gpio_hwmod_s   gpio_hwmod_t;

struct gpio_hwmod_s {
    void           *hdl;                    /* Handle to the dynamically loaded GPIO HW module (returned by dlopen()) */
    paddr_t         phybase;                /* Physical base address of the GPIO controller */
    const char     *args;                   /* Hardware driver's subopts */
    uint32_t        pins_per_bank;          /* Maximum number of GPIO pins per bank (default: 32, overridable by HW module) */
    uint32_t        num_banks;              /* Total number of GPIO banks (default: 1, overridable by HW module) */
    uint32_t       *bank_index_id_map;      /* Array mapping internal bank index to bank ID.
                                               bank_index_id_map[i] returns the bank ID corresponding to internal bank index i.
                                               By default, each bank's index is the same as its ID,
                                               and this pointer is set to NULL. */
    int32_t         reserved[8];            /* Reserved for future expansion */
    gpio_helper_t   gpio_helper;            /* GPIO helper functions provided by io-gpio */
    hwmod_funcs_t   hwfuncs;                /* GPIO HW APIs implemented by the HW module */
};

Hardware module operation interface (hwmod_funcs_t)

This structure defines the set of hardware-specific operations implemented by a GPIO hardware module and invoked by the resource manager. Each function pointer represents a mandatory or optional callback providing support for a specific GPIO operation.

The definition of hwmod_funcs_t is:

#include <hw/gpio_hw.h>

typedef struct hwmod_funcs_s hwmod_funcs_t;

struct hwmod_funcs_s {

    int32_t (*gpio_init)( gpio_hwmod_t *hwmod );

    void    (*gpio_fini)( void );

    int32_t (*gpio_dir)( gpio_header_t *gpio_hdr,
                         gpio_dir_t *dir,
                         uint8_t set );

    int32_t (*gpio_enable)( gpio_header_t *gpio_hdr,
                            gpio_enable_t *enable,
                            uint8_t set );

    int32_t (*gpio_level)( gpio_header_t *gpio_hdr,
                           gpio_level_t *level,
                           uint8_t set );

    int32_t (*gpio_pull)( gpio_header_t *gpio_hdr,
                          gpio_pull_t *pull,
                          uint8_t set );

    int32_t (*gpio_get_fsel)( gpio_header_t *gpio_hdr,
                              int32_t *fsel );

    int32_t (*gpio_itype)( gpio_header_t *gpio_hdr,
                           gpio_itype_t *itype,
                           uint8_t set );

    int32_t (*gpio_debounce)( gpio_header_t *gpio_hdr,
                              int32_t *debounce,
                              uint8_t set );

    int32_t (*gpio_custom)( gpio_header_t *gpio_hdr,
                            void *data );

    void *reserved[8];
};

Page updated: