drivers: framework for a generic flash driver
The framework for a generic flash driver. Change-Id: I030eb6d88338f4d6611fc6e5cae42ac586cfdb12 Signed-off-by: Baohong Liu <baohong.liu@intel.com>
This commit is contained in:
parent
e81053ee03
commit
29c8f95ec4
5 changed files with 163 additions and 0 deletions
|
@ -67,4 +67,6 @@ source "drivers/qmsi/Kconfig"
|
|||
|
||||
source "drivers/nble/Kconfig"
|
||||
|
||||
source "drivers/flash/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -10,6 +10,7 @@ obj-$(CONFIG_PCI) += pci/
|
|||
obj-$(CONFIG_BLUETOOTH) += bluetooth/
|
||||
obj-$(CONFIG_SHARED_IRQ) += shared_irq/
|
||||
obj-$(CONFIG_SPI) += spi/
|
||||
obj-$(CONFIG_FLASH) += flash/
|
||||
obj-$(CONFIG_GPIO) += gpio/
|
||||
obj-$(CONFIG_I2C) += i2c/
|
||||
obj-$(CONFIG_PWM) += pwm/
|
||||
|
|
27
drivers/flash/Kconfig
Normal file
27
drivers/flash/Kconfig
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Kconfig - flash driver configuration options
|
||||
|
||||
#
|
||||
# Copyright (c) 2016 Intel Corporation
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# flash driver
|
||||
#
|
||||
menuconfig FLASH
|
||||
bool
|
||||
prompt "flash hardware support"
|
||||
default n
|
||||
help
|
||||
Enable support for the flash hardware.
|
0
drivers/flash/Makefile
Normal file
0
drivers/flash/Makefile
Normal file
133
include/flash.h
Normal file
133
include/flash.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for FLASH drivers
|
||||
*/
|
||||
|
||||
#ifndef __FLASH_H__
|
||||
#define __FLASH_H__
|
||||
|
||||
/**
|
||||
* @brief FLASH Interface
|
||||
* @defgroup flash_interface FLASH Interface
|
||||
* @ingroup io_interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int (*flash_api_read)(struct device *dev, uint32_t offset,
|
||||
unsigned int len, uint8_t *data);
|
||||
typedef int (*flash_api_write)(struct device *dev, uint32_t offset,
|
||||
unsigned int len, uint8_t *data);
|
||||
typedef int (*flash_api_erase)(struct device *dev, uint32_t offset,
|
||||
uint32_t size);
|
||||
typedef int (*flash_api_write_protection)(struct device *dev, bool enable);
|
||||
|
||||
struct flash_driver_api {
|
||||
flash_api_read read;
|
||||
flash_api_write write;
|
||||
flash_api_erase erase;
|
||||
flash_api_write_protection write_protection;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read data from flash
|
||||
*
|
||||
* @param dev : flash dev
|
||||
* @param offset : Offset (byte aligned) to read
|
||||
* @param len : Number of bytes to read.
|
||||
* @param data : Buffer to store read data
|
||||
*
|
||||
* @return DEV_OK on success else DEV_* code
|
||||
*/
|
||||
static inline int flash_read(struct device *dev, uint32_t offset,
|
||||
unsigned int len, uint8_t *data)
|
||||
{
|
||||
struct flash_driver_api *api = (struct flash_driver_api *)dev->driver_api;
|
||||
|
||||
return api->read(dev, offset, len, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write buffer into flash memory.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param offset : starting offset for the write
|
||||
* @param len : Number of bytes to write
|
||||
* @param data : data to write
|
||||
*
|
||||
* @return DEV_OK on success else DEV_* code
|
||||
*/
|
||||
static inline int flash_write(struct device *dev, uint32_t offset,
|
||||
unsigned int len, uint8_t *data)
|
||||
{
|
||||
struct flash_driver_api *api = (struct flash_driver_api *)dev->driver_api;
|
||||
|
||||
return api->write(dev, offset, len, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erase part or all of a flash memory
|
||||
*
|
||||
* Acceptable values of erase size are subject to hardware-specific
|
||||
* multiples of sector size.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param offset : erase area starting offset
|
||||
* @param size : size of area to be erased
|
||||
*
|
||||
* @return DEV_OK on success else DEV_* code
|
||||
*/
|
||||
static inline int flash_erase(struct device *dev, uint32_t offset, uint32_t size)
|
||||
{
|
||||
struct flash_driver_api *api = (struct flash_driver_api *)dev->driver_api;
|
||||
|
||||
return api->erase(dev, offset, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable write protection for a flash memory
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param enable : enable or disable flash write protection
|
||||
*
|
||||
* @return DEV_OK on success else DEV_* code
|
||||
*/
|
||||
static inline int flash_write_protection_set(struct device *dev, bool enable)
|
||||
{
|
||||
struct flash_driver_api *api = (struct flash_driver_api *)dev->driver_api;
|
||||
|
||||
return api->write_protection(dev, enable);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* _FLASH_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue