-
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: entropy: add support for Microchip ATECC608
Add entropy support for Microchip ATECC608 and ATECC508. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
- Loading branch information
1 parent
e0fff6d
commit ea5f4b5
Showing
6 changed files
with
102 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,13 @@ | ||
# Microchip ATECCx08 entropy generator driver configuration | ||
|
||
# Copyright (c) 2024 Vogl Electronic GmbH | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config ENTROPY_ATECCX08 | ||
bool "Microchip ATECCx08 RNG driver" | ||
default y | ||
depends on DT_HAS_MICROCHIP_ATECCX08_ENTROPY_ENABLED | ||
depends on EEPROM_ATECCX08 | ||
select ENTROPY_HAS_DRIVER | ||
help | ||
This option enables the Microchip ATECCx08 RNG driver. |
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,75 @@ | ||
/* | ||
* Copyright (c) 2024 Vogl Electronic GmbH | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#define DT_DRV_COMPAT microchip_ateccx08_entropy | ||
|
||
#include <errno.h> | ||
#include <string.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/drivers/entropy.h> | ||
#include <zephyr/drivers/eeprom/ateccx08.h> | ||
#include <zephyr/init.h> | ||
#include <zephyr/kernel.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(entropy_ateccx08, CONFIG_ENTROPY_LOG_LEVEL); | ||
|
||
struct entropy_ateccx08_config { | ||
const struct device *parent; | ||
}; | ||
|
||
static int entropy_ateccx08_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length) | ||
{ | ||
const struct entropy_ateccx08_config *config = dev->config; | ||
const static uint8_t not_random[] = {0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; | ||
|
||
int ret = 0; | ||
|
||
while (length > 0) { | ||
size_t to_copy; | ||
uint8_t random_var[32] = {0}; | ||
|
||
ret = atecc_calib_random(config->parent, random_var); | ||
if (ret < 0) { | ||
return ret; | ||
} | ||
|
||
if (memcmp(random_var, not_random, sizeof(not_random)) == 0) { | ||
LOG_ERR("Config not locked, no random data available."); | ||
return -EIO; | ||
} | ||
|
||
to_copy = MIN(length, sizeof(random_var)); | ||
|
||
memcpy(buffer, random_var, to_copy); | ||
buffer += to_copy; | ||
length -= to_copy; | ||
} | ||
return ret; | ||
} | ||
|
||
static int entropy_ateccx08_init(const struct device *dev) | ||
{ | ||
const struct entropy_ateccx08_config *config = dev->config; | ||
|
||
if (!device_is_ready(config->parent)) { | ||
return -ENODEV; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static const struct entropy_driver_api entropy_ateccx08_api = { | ||
.get_entropy = entropy_ateccx08_get_entropy}; | ||
|
||
#define DEFINE_ATECCX08_ENTROPY(_num) \ | ||
static const struct entropy_ateccx08_config entropy_ateccx08_config##_num = { \ | ||
.parent = DEVICE_DT_GET(DT_INST_BUS(_num))}; \ | ||
DEVICE_DT_INST_DEFINE(_num, entropy_ateccx08_init, NULL, NULL, \ | ||
&entropy_ateccx08_config##_num, POST_KERNEL, \ | ||
CONFIG_EEPROM_INIT_PRIORITY, &entropy_ateccx08_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(DEFINE_ATECCX08_ENTROPY); |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
include: ["eeprom-base.yaml", i2c-device.yaml] | ||
|
||
bus: ateccx08 | ||
|
||
properties: | ||
size: | ||
required: true |
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 @@ | ||
# Copyright (c) 2024 Vogl Electronic GmbH | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Microchip ATECCx08 entropy binding | ||
|
||
compatible: "microchip,ateccx08-entropy" | ||
|
||
include: base.yaml | ||
|
||
on-bus: ateccx08 |