drivers: eeprom: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and dev->config instead. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
d2118eb1bc
commit
f5effdde6c
2 changed files with 26 additions and 30 deletions
|
@ -64,9 +64,6 @@
|
|||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(eeprom_emulator);
|
||||
|
||||
#define DEV_CONFIG(dev) ((dev)->config)
|
||||
#define DEV_DATA(dev) ((dev)->data)
|
||||
|
||||
struct eeprom_emu_config {
|
||||
/* EEPROM size */
|
||||
size_t size;
|
||||
|
@ -112,7 +109,7 @@ struct eeprom_emu_ctx {
|
|||
static inline int eeprom_emu_flash_read(const struct device *dev, off_t offset,
|
||||
uint8_t *blk, size_t len)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
|
||||
return flash_read(dev_config->flash_dev, dev_config->flash_offset +
|
||||
offset, blk, len);
|
||||
|
@ -124,7 +121,7 @@ static inline int eeprom_emu_flash_read(const struct device *dev, off_t offset,
|
|||
static inline int eeprom_emu_flash_write(const struct device *dev, off_t offset,
|
||||
const uint8_t *blk, size_t len)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
int rc;
|
||||
|
||||
rc = flash_write(dev_config->flash_dev, dev_config->flash_offset +
|
||||
|
@ -139,7 +136,7 @@ static inline int eeprom_emu_flash_write(const struct device *dev, off_t offset,
|
|||
static inline int eeprom_emu_flash_erase(const struct device *dev, off_t offset,
|
||||
size_t len)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
int rc;
|
||||
|
||||
rc = flash_erase(dev_config->flash_dev, dev_config->flash_offset +
|
||||
|
@ -152,7 +149,7 @@ static inline int eeprom_emu_flash_erase(const struct device *dev, off_t offset,
|
|||
*/
|
||||
static int eeprom_emu_page_invalidate(const struct device *dev, off_t offset)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
uint8_t buf[dev_config->flash_cbs];
|
||||
|
||||
LOG_DBG("Invalidating page at [0x%tx]", (ptrdiff_t)offset);
|
||||
|
@ -169,7 +166,7 @@ static int eeprom_emu_page_invalidate(const struct device *dev, off_t offset)
|
|||
static uint32_t eeprom_emu_get_address(const struct device *dev,
|
||||
const uint8_t *blk)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
uint32_t address = 0U;
|
||||
|
||||
blk += dev_config->flash_cbs / 2;
|
||||
|
@ -192,7 +189,7 @@ static void eeprom_emu_set_change(const struct device *dev,
|
|||
const uint32_t address, const uint8_t *data,
|
||||
uint8_t *blk)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
|
||||
for (int i = 0; i < (dev_config->flash_cbs / 2); i++) {
|
||||
(*blk++) = (*data++);
|
||||
|
@ -214,7 +211,7 @@ static void eeprom_emu_set_change(const struct device *dev,
|
|||
*/
|
||||
static int eeprom_emu_is_word_used(const struct device *dev, const uint8_t *blk)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
|
||||
for (int i = 0; i < dev_config->flash_cbs; i++) {
|
||||
if ((*blk++) != 0xff) {
|
||||
|
@ -233,8 +230,8 @@ static int eeprom_emu_is_word_used(const struct device *dev, const uint8_t *blk)
|
|||
static int eeprom_emu_word_read(const struct device *dev, off_t address,
|
||||
uint8_t *data)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_data *dev_data = DEV_DATA(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
const struct eeprom_emu_data *dev_data = dev->data;
|
||||
uint8_t buf[dev_config->flash_cbs];
|
||||
off_t direct_address;
|
||||
int rc;
|
||||
|
@ -282,7 +279,7 @@ static int eeprom_emu_word_read(const struct device *dev, off_t address,
|
|||
static int eeprom_emu_flash_get(const struct device *dev,
|
||||
struct eeprom_emu_ctx *ctx)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
off_t address = ctx->address + ctx->len - ctx->rlen;
|
||||
uint8_t *data8 = (uint8_t *)(ctx->data);
|
||||
uint8_t buf[dev_config->flash_cbs];
|
||||
|
@ -311,8 +308,8 @@ static int eeprom_emu_flash_get(const struct device *dev,
|
|||
static int eeprom_emu_compactor(const struct device *dev,
|
||||
struct eeprom_emu_ctx *ctx)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
struct eeprom_emu_data *dev_data = DEV_DATA(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
struct eeprom_emu_data *dev_data = dev->data;
|
||||
off_t next_page_offset;
|
||||
int rc = 0;
|
||||
|
||||
|
@ -419,8 +416,8 @@ static int eeprom_emu_word_write(const struct device *dev, off_t address,
|
|||
const uint8_t *data,
|
||||
struct eeprom_emu_ctx *ctx)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
struct eeprom_emu_data *dev_data = DEV_DATA(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
struct eeprom_emu_data *dev_data = dev->data;
|
||||
uint8_t buf[dev_config->flash_cbs], tmp[dev_config->flash_cbs];
|
||||
off_t direct_address, wraddr;
|
||||
int rc;
|
||||
|
@ -484,7 +481,7 @@ static int eeprom_emu_word_write(const struct device *dev, off_t address,
|
|||
static int eeprom_emu_flash_set(const struct device *dev,
|
||||
struct eeprom_emu_ctx *ctx)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
off_t address = ctx->address + ctx->len - ctx->rlen;
|
||||
uint8_t *data8 = (uint8_t *)(ctx->data);
|
||||
uint8_t buf[dev_config->flash_cbs];
|
||||
|
@ -515,7 +512,7 @@ static int eeprom_emu_flash_set(const struct device *dev,
|
|||
static int eeprom_emu_range_is_valid(const struct device *dev, off_t address,
|
||||
size_t len)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
|
||||
if ((address + len) <= dev_config->size) {
|
||||
return 1;
|
||||
|
@ -527,8 +524,8 @@ static int eeprom_emu_range_is_valid(const struct device *dev, off_t address,
|
|||
static int eeprom_emu_read(const struct device *dev, off_t address, void *data,
|
||||
size_t len)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
struct eeprom_emu_data *dev_data = DEV_DATA(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
struct eeprom_emu_data *dev_data = dev->data;
|
||||
struct eeprom_emu_ctx ctx = {
|
||||
.data = data,
|
||||
.len = len,
|
||||
|
@ -578,8 +575,8 @@ static int eeprom_emu_read(const struct device *dev, off_t address, void *data,
|
|||
static int eeprom_emu_write(const struct device *dev, off_t address,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
struct eeprom_emu_data *dev_data = DEV_DATA(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
struct eeprom_emu_data *dev_data = dev->data;
|
||||
struct eeprom_emu_ctx ctx = {
|
||||
.data = data,
|
||||
.len = len,
|
||||
|
@ -634,15 +631,15 @@ static int eeprom_emu_write(const struct device *dev, off_t address,
|
|||
|
||||
static size_t eeprom_emu_size(const struct device *dev)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
|
||||
return dev_config->size;
|
||||
}
|
||||
|
||||
static int eeprom_emu_init(const struct device *dev)
|
||||
{
|
||||
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
|
||||
struct eeprom_emu_data *dev_data = DEV_DATA(dev);
|
||||
const struct eeprom_emu_config *dev_config = dev->config;
|
||||
struct eeprom_emu_data *dev_data = dev->data;
|
||||
off_t offset;
|
||||
uint8_t buf[dev_config->flash_cbs];
|
||||
int rc;
|
||||
|
|
|
@ -36,7 +36,6 @@ struct eeprom_sim_config {
|
|||
};
|
||||
|
||||
#define DEV_NAME(dev) ((dev)->name)
|
||||
#define DEV_CONFIG(dev) ((dev)->config)
|
||||
|
||||
#define EEPROM(addr) (mock_eeprom + (addr))
|
||||
|
||||
|
@ -96,7 +95,7 @@ static uint8_t mock_eeprom[DT_INST_PROP(0, size)];
|
|||
static int eeprom_range_is_valid(const struct device *dev, off_t offset,
|
||||
size_t len)
|
||||
{
|
||||
const struct eeprom_sim_config *config = DEV_CONFIG(dev);
|
||||
const struct eeprom_sim_config *config = dev->config;
|
||||
|
||||
if ((offset + len) <= config->size) {
|
||||
return 1;
|
||||
|
@ -138,7 +137,7 @@ static int eeprom_sim_write(const struct device *dev, off_t offset,
|
|||
const void *data,
|
||||
size_t len)
|
||||
{
|
||||
const struct eeprom_sim_config *config = DEV_CONFIG(dev);
|
||||
const struct eeprom_sim_config *config = dev->config;
|
||||
|
||||
if (config->readonly) {
|
||||
LOG_WRN("attempt to write to read-only device");
|
||||
|
@ -196,7 +195,7 @@ end:
|
|||
|
||||
static size_t eeprom_sim_size(const struct device *dev)
|
||||
{
|
||||
const struct eeprom_sim_config *config = DEV_CONFIG(dev);
|
||||
const struct eeprom_sim_config *config = dev->config;
|
||||
|
||||
return config->size;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue