drivers: eeprom: add API for EEPROM devices
Add API for accessing Electrically Erasable Programmable Read-Only Memory (EEPROM) devices. EEPROMs have an erase block size of 1 byte, a long lifetime, and allows overwriting data on byte-by-byte access. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
a58d8ebaa6
commit
a2a7b776cb
8 changed files with 177 additions and 0 deletions
|
@ -120,6 +120,7 @@
|
|||
/drivers/display/display_framebuf.c @andrewboie
|
||||
/drivers/dma/*sam0* @Sizurka
|
||||
/drivers/dma/dma_stm32* @cybertale
|
||||
/drivers/eeprom/ @henrikbrixandersen
|
||||
/drivers/espi/ @albertofloyd @franciscomunoz @scottwcpg
|
||||
/drivers/ps2/ @albertofloyd @franciscomunoz @scottwcpg
|
||||
/drivers/kscan/ @albertofloyd @franciscomunoz @scottwcpg
|
||||
|
|
|
@ -36,6 +36,7 @@ add_subdirectory_if_kconfig(espi)
|
|||
add_subdirectory_if_kconfig(ps2)
|
||||
add_subdirectory_if_kconfig(kscan)
|
||||
add_subdirectory_if_kconfig(video)
|
||||
add_subdirectory_if_kconfig(eeprom)
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_FLASH_HAS_DRIVER_ENABLED flash)
|
||||
add_subdirectory_ifdef(CONFIG_SERIAL_HAS_DRIVER serial)
|
||||
|
|
|
@ -87,4 +87,6 @@ source "drivers/kscan/Kconfig"
|
|||
|
||||
source "drivers/video/Kconfig"
|
||||
|
||||
source "drivers/eeprom/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
|
5
drivers/eeprom/CMakeLists.txt
Normal file
5
drivers/eeprom/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE eeprom_handlers.c)
|
17
drivers/eeprom/Kconfig
Normal file
17
drivers/eeprom/Kconfig
Normal file
|
@ -0,0 +1,17 @@
|
|||
# EEPROM driver configuration options
|
||||
|
||||
# Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig EEPROM
|
||||
bool "EEPROM hardware support"
|
||||
help
|
||||
Enable support for EEPROM hardware.
|
||||
|
||||
if EEPROM
|
||||
|
||||
module = EEPROM
|
||||
module-str = eeprom
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif # EEPROM
|
35
drivers/eeprom/eeprom_handlers.c
Normal file
35
drivers/eeprom/eeprom_handlers.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <syscall_handler.h>
|
||||
#include <drivers/eeprom.h>
|
||||
|
||||
static inline int z_vrfy_eeprom_read(struct device *dev, off_t offset,
|
||||
void *data, size_t len)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_EEPROM(dev, read));
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(data, len));
|
||||
return z_impl_eeprom_read((struct device *)dev, offset, (void *)data,
|
||||
len);
|
||||
}
|
||||
#include <syscalls/eeprom_read_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_eeprom_write(struct device *dev, off_t offset,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_EEPROM(dev, write));
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ(data, len));
|
||||
return z_impl_eeprom_write((struct device *)dev, offset,
|
||||
(const void *)data, len);
|
||||
}
|
||||
#include <syscalls/eeprom_write_mrsh.c>
|
||||
|
||||
static inline size_t z_vrfy_eeprom_get_size(struct device *dev)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_EEPROM(dev, size));
|
||||
return z_impl_eeprom_get_size((struct device *)dev);
|
||||
}
|
||||
#include <syscalls/eeprom_get_size_mrsh.c>
|
115
include/drivers/eeprom.h
Normal file
115
include/drivers/eeprom.h
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
*
|
||||
* Heavily based on drivers/flash.h which is:
|
||||
* Copyright (c) 2017 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for EEPROM drivers
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_
|
||||
|
||||
/**
|
||||
* @brief EEPROM Interface
|
||||
* @defgroup eeprom_interface EEPROM Interface
|
||||
* @ingroup io_interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int (*eeprom_api_read)(struct device *dev, off_t offset, void *data,
|
||||
size_t len);
|
||||
typedef int (*eeprom_api_write)(struct device *dev, off_t offset,
|
||||
const void *data, size_t len);
|
||||
typedef size_t (*eeprom_api_size)(struct device *dev);
|
||||
|
||||
struct eeprom_driver_api {
|
||||
eeprom_api_read read;
|
||||
eeprom_api_write write;
|
||||
eeprom_api_size size;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read data from EEPROM
|
||||
*
|
||||
* @param dev EEPROM device
|
||||
* @param offset Address offset to read from.
|
||||
* @param data Buffer to store read data.
|
||||
* @param len Number of bytes to read.
|
||||
*
|
||||
* @return 0 on success, negative errno code on failure.
|
||||
*/
|
||||
__syscall int eeprom_read(struct device *dev, off_t offset, void *data,
|
||||
size_t len);
|
||||
|
||||
static inline int z_impl_eeprom_read(struct device *dev, off_t offset,
|
||||
void *data, size_t len)
|
||||
{
|
||||
const struct eeprom_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->read(dev, offset, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write data to EEPROM
|
||||
*
|
||||
* @param dev EEPROM device
|
||||
* @param offset Address offset to write data to.
|
||||
* @param data Buffer with data to write.
|
||||
* @param len Number of bytes to write.
|
||||
*
|
||||
* @return 0 on success, negative errno code on failure.
|
||||
*/
|
||||
__syscall int eeprom_write(struct device *dev, off_t offset, const void *data,
|
||||
size_t len);
|
||||
|
||||
static inline int z_impl_eeprom_write(struct device *dev, off_t offset,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
const struct eeprom_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write(dev, offset, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the size of the EEPROM in bytes
|
||||
*
|
||||
* @param dev EEPROM device.
|
||||
*
|
||||
* @return EEPROM size in bytes.
|
||||
*/
|
||||
__syscall size_t eeprom_get_size(struct device *dev);
|
||||
|
||||
static inline size_t z_impl_eeprom_get_size(struct device *dev)
|
||||
{
|
||||
const struct eeprom_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->size(dev);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <syscalls/eeprom.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_ */
|
|
@ -112,6 +112,7 @@ subsystems = [
|
|||
"uart_driver_api",
|
||||
"can_driver_api",
|
||||
"ptp_clock_driver_api",
|
||||
"eeprom_driver_api",
|
||||
|
||||
# Fake 'sample driver' subsystem, used by tests/samples
|
||||
"sample_driver_api"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue