Skip to content

Commit

Permalink
drivers: eeprom: add support for Microchip ATECC608
Browse files Browse the repository at this point in the history
Add support for Microchip ATECC608 EEPROM and
ATECC508 EEPROM.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
  • Loading branch information
maass-hamburg committed Aug 1, 2024
1 parent 48d69b4 commit d785ac4
Show file tree
Hide file tree
Showing 23 changed files with 1,623 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/eeprom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ zephyr_library_sources_ifdef(CONFIG_EEPROM_FAKE eeprom_fake.c)
zephyr_library_sources_ifdef(CONFIG_EEPROM_AT2X_EMUL eeprom_at2x_emul.c)

zephyr_library_sources_ifdef(CONFIG_EEPROM_MB85RCXX eeprom_mb85rcxx.c)

zephyr_library_sources_ifdef(CONFIG_EEPROM_ATECCX08_OTP eeprom_ateccx08_otp.c)
1 change: 1 addition & 0 deletions drivers/eeprom/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ source "drivers/eeprom/Kconfig.eeprom_emu"
source "drivers/eeprom/Kconfig.tmp116"
source "drivers/eeprom/Kconfig.xec"
source "drivers/eeprom/Kconfig.mb85rcxx"
source "drivers/eeprom/Kconfig.ateccx08"

config EEPROM_SIMULATOR
bool "Simulated EEPROM driver"
Expand Down
19 changes: 19 additions & 0 deletions drivers/eeprom/Kconfig.ateccx08
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Microchip ATECCx08 eeprom driver configuration

# Copyright (c) 2024 Vogl Electronic GmbH
# SPDX-License-Identifier: Apache-2.0

config EEPROM_ATECCX08_OTP
bool "Microchip ATECCx08 otp eeprom driver"
default y
depends on DT_HAS_MICROCHIP_ATECCX08_OTP_ENABLED
depends on MFD_ATECCX08
help
This option enables the Microchip ATECCx08 otp eeprom driver.

config EEPROM_ATECCX08_OTP_INIT_PRIORITY
int "Microchip ATECCx08 otp eeprom driver initialization priority"
default MFD_ATECCX08_SUBDEVICE_INIT_PRIORITY
depends on EEPROM_ATECCX08_OTP
help
Microchip ATECCx08 otp eeprom device initialization priority.
83 changes: 83 additions & 0 deletions drivers/eeprom/eeprom_ateccx08_otp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2024 Vogl Electronic GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Driver for Microchip ATECCX08 I2C EEPROMs.
*/

#define DT_DRV_COMPAT microchip_ateccx08_otp

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/mfd/ateccx08.h>
#include <zephyr/drivers/eeprom.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(ateccx08_otp, CONFIG_EEPROM_LOG_LEVEL);

struct eeprom_ateccx08_config {
const struct device *parent;
bool readonly;
};

static size_t eeprom_ateccx08_size(const struct device *dev)
{
ARG_UNUSED(dev);

return atecc_get_zone_size(ATECC_ZONE_OTP, 0);
}

static int eeprom_ateccx08_write(const struct device *dev, off_t offset, const void *data,
size_t len)
{
const struct eeprom_ateccx08_config *cfg = dev->config;

if (cfg->readonly) {
LOG_ERR("attempt to write to read-only device");
return -EACCES;
}

return atecc_write_bytes(cfg->parent, ATECC_ZONE_OTP, 0, offset, data, len);
}

static int eeprom_ateccx08_read(const struct device *dev, off_t offset, void *data, size_t len)
{
const struct eeprom_ateccx08_config *cfg = dev->config;

return atecc_read_bytes(cfg->parent, ATECC_ZONE_OTP, 0, offset, data, len);
}

static int eeprom_ateccx08_init(const struct device *dev)
{
const struct eeprom_ateccx08_config *cfg = dev->config;

if (!device_is_ready(cfg->parent)) {
return -ENODEV;
}

return 0;
}

static const struct eeprom_driver_api eeprom_ateccx08_driver_api = {
.read = &eeprom_ateccx08_read,
.write = &eeprom_ateccx08_write,
.size = &eeprom_ateccx08_size,
};

BUILD_ASSERT(CONFIG_EEPROM_ATECCX08_OTP_INIT_PRIORITY >= CONFIG_MFD_ATECCX08_INIT_PRIORITY,
"ATECCX08 EEPROM driver must be initialized after the mfd driver");

#define DEFINE_ATECCX08_OTP(_num) \
static const struct eeprom_ateccx08_config eeprom_ateccx08_config##_num = { \
.parent = DEVICE_DT_GET(DT_INST_BUS(_num)), \
.readonly = DT_INST_PROP(_num, read_only)}; \
DEVICE_DT_INST_DEFINE(_num, eeprom_ateccx08_init, NULL, NULL, \
&eeprom_ateccx08_config##_num, POST_KERNEL, \
CONFIG_EEPROM_ATECCX08_OTP_INIT_PRIORITY, \
&eeprom_ateccx08_driver_api);

DT_INST_FOREACH_STATUS_OKAY(DEFINE_ATECCX08_OTP);
2 changes: 2 additions & 0 deletions drivers/mfd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ zephyr_library_sources_ifdef(CONFIG_MFD_MAX31790 mfd_max31790.c)
zephyr_library_sources_ifdef(CONFIG_NXP_LP_FLEXCOMM mfd_nxp_lp_flexcomm.c)
zephyr_library_sources_ifdef(CONFIG_MFD_BD8LB600FS mfd_bd8lb600fs.c)
zephyr_library_sources_ifdef(CONFIG_MFD_TLE9104 mfd_tle9104.c)

add_subdirectory_ifdef(CONFIG_MFD_ATECCX08 ateccx08)
2 changes: 2 additions & 0 deletions drivers/mfd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ source "drivers/mfd/Kconfig.npm6001"
source "drivers/mfd/Kconfig.lpflexcomm"
source "drivers/mfd/Kconfig.tle9104"

source "drivers/mfd/ateccx08/Kconfig"

endif # MFD
10 changes: 10 additions & 0 deletions drivers/mfd/ateccx08/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library_sources(mfd_ateccx08.c)
zephyr_library_sources(atecc_basic.c)
zephyr_library_sources(atecc_execution.c)
zephyr_library_sources(atecc_random.c)
zephyr_library_sources(atecc_read.c)
zephyr_library_sources(atecc_write.c)
zephyr_library_sources(atecc_info.c)
zephyr_library_sources(atecc_lock.c)
43 changes: 43 additions & 0 deletions drivers/mfd/ateccx08/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Microchip ATECCx08 MFD

# Copyright (c) 2024 Vogl Electronic GmbH
# SPDX-License-Identifier: Apache-2.0

config MFD_ATECCX08
bool
help
Enable support for Microchip ATECCx08 I2C CRYPTOs.

config MFD_ATECC608
bool "Microchip ATECC608 I2C CRYPTO support"
default y
depends on DT_HAS_MICROCHIP_ATECC608_ENABLED
select I2C
select MFD_ATECCX08
help
Enable support for Microchip ATECC608 I2C CRYPTOs.

config MFD_ATECC508
bool "Microchip ATECC508 I2C CRYPTO support"
default y
depends on DT_HAS_MICROCHIP_ATECC508_ENABLED
select I2C
select MFD_ATECCX08
help
Enable support for Microchip ATECC508 I2C CRYPTOs.

if MFD_ATECCX08

config MFD_ATECCX08_INIT_PRIORITY
int "Microchip ATECCx08 Initialization priority"
default 55
help
This option enables the Microchip ATECCx08 eeprom driver OTP.

config MFD_ATECCX08_SUBDEVICE_INIT_PRIORITY
int "Microchip ATECCx08 subdevice Initialization priority"
default 56
help
This option enables the Microchip ATECCx08 eeprom driver OTP.

endif
Loading

0 comments on commit d785ac4

Please sign in to comment.