2015-09-19 07:53:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-09-19 07:53:26 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-19 07:53:26 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-09-19 07:53:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file Header file for the MMIO-based GPIO driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GPIO_MMIO_H_
|
|
|
|
#define _GPIO_MMIO_H_
|
|
|
|
|
|
|
|
#include <nanokernel.h>
|
|
|
|
|
|
|
|
#include <gpio.h>
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-09-19 07:53:26 +08:00
|
|
|
/* For enable register:
|
|
|
|
* NORMAL: 0 - disable, 1 - enable
|
|
|
|
* INV: 0 - enable, 1 - disable
|
|
|
|
*/
|
|
|
|
#define GPIO_MMIO_CFG_EN_NORMAL (0 << 0)
|
|
|
|
#define GPIO_MMIO_CFG_EN_INV (1 << 0)
|
|
|
|
#define GPIO_MMIO_CFG_EN_MASK (1 << 0)
|
|
|
|
|
|
|
|
/* For direction register:
|
|
|
|
* NORMAL: 0 - pin is output, 1 - pin is input
|
|
|
|
* INV: 0 - pin is input, 1 - pin is output
|
|
|
|
*/
|
|
|
|
#define GPIO_MMIO_CFG_DIR_NORMAL (0 << 1)
|
|
|
|
#define GPIO_MMIO_CFG_DIR_INV (1 << 1)
|
|
|
|
#define GPIO_MMIO_CFG_DIR_MASK (1 << 1)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialization function for GPIO driver
|
|
|
|
*
|
|
|
|
* @param dev Device struct
|
|
|
|
* @return DEV_OK if successful, failed otherwise
|
|
|
|
*/
|
|
|
|
extern int gpio_mmio_init(struct device *dev);
|
|
|
|
|
2015-09-30 02:22:23 +08:00
|
|
|
/* internal use only for register access function */
|
|
|
|
typedef uint32_t (*__gpio_mmio_access_t)(uint32_t addr, uint32_t bit,
|
|
|
|
uint32_t value);
|
|
|
|
|
2015-09-19 07:53:26 +08:00
|
|
|
/** Configuration data */
|
|
|
|
struct gpio_mmio_config {
|
|
|
|
/* config flags */
|
|
|
|
uint32_t cfg_flags;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
/* enable register */
|
|
|
|
uint32_t en;
|
|
|
|
|
|
|
|
/* direction register */
|
|
|
|
uint32_t dir;
|
|
|
|
|
|
|
|
/* pin level register for input*/
|
|
|
|
uint32_t input;
|
|
|
|
|
|
|
|
/* pin level register for output */
|
|
|
|
uint32_t output;
|
|
|
|
} reg;
|
2015-09-30 02:22:23 +08:00
|
|
|
|
|
|
|
struct {
|
|
|
|
__gpio_mmio_access_t set_bit;
|
|
|
|
__gpio_mmio_access_t read;
|
|
|
|
__gpio_mmio_access_t write;
|
|
|
|
} access;
|
2015-09-19 07:53:26 +08:00
|
|
|
};
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-19 07:53:26 +08:00
|
|
|
#endif /* _GPIO_MMIO_H_ */
|