-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: eeprom: add support for Microchip ATECC608
Add support for Microchip ATECC608 EEPROM and ATECC508 EEPROM. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
- Loading branch information
1 parent
48d69b4
commit d785ac4
Showing
23 changed files
with
1,623 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.