aboutsummaryrefslogtreecommitdiff
path: root/include/atsha204a-i2c.h
diff options
context:
space:
mode:
authorMarek BehĂșn2017-06-09 19:28:44 +0200
committerStefan Roese2017-07-12 06:57:38 +0200
commitaa5eb9a3acb7552e715aad48ed0105b7c3d6ed51 (patch)
tree5227ac2c2e37c8cf097a6d4cf1b48204d830775e /include/atsha204a-i2c.h
parent8e6eda7cda6c06e173eb5d6430dbe2fec732caf7 (diff)
drivers/misc: Add basic support for ATSHA204A Crypto module
This module can be found on the Turris Omnia board connected via the I2C interface. Among some cryptographic functions, the chip has a 512 bit One Time Programmable memory, 88 byte configuration memory and 512 byte general purpose memory. The Turris Omnia stores serial number and device MAC address in the OTP memory. This commit adds basic support for reading the EEPROM and also exposes the chips Random Number Generator. The driver is based on code by Josh Datko, Cryptotronix, jbd@cryptotronix.com and also Tomas Hlavacek, CZ.NIC, tomas.hlavacek@nic.cz Signed-off-by: Tomas Hlavacek <tomas.hlavacek@nic.cz> Signed-off-by: Marek Behun <marek.behun@nic.cz> create mode 100644 drivers/misc/atsha204a-i2c.c create mode 100644 include/atsha204a-i2c.h Signed-off-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'include/atsha204a-i2c.h')
-rw-r--r--include/atsha204a-i2c.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/atsha204a-i2c.h b/include/atsha204a-i2c.h
new file mode 100644
index 00000000000..344fd8ace7d
--- /dev/null
+++ b/include/atsha204a-i2c.h
@@ -0,0 +1,69 @@
+/*
+ * I2C Driver for Atmel ATSHA204 over I2C
+ *
+ * Copyright (C) 2014 Josh Datko, Cryptotronix, jbd@cryptotronix.com
+ * 2016 Tomas Hlavacek, CZ.NIC, tmshlvck@gmail.com
+ * 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _ATSHA204_I2C_H_
+#define _ATSHA204_I2C_H_
+
+enum atsha204a_zone
+{
+ ATSHA204A_ZONE_CONFIG = 0,
+ ATSHA204A_ZONE_OTP = 1,
+ ATSHA204A_ZONE_DATA = 2,
+};
+
+enum atsha204a_status
+{
+ ATSHA204A_STATUS_SUCCESS = 0x00,
+ ATSHA204A_STATUS_MISCOMPARE = 0x01,
+ ATSHA204A_STATUS_PARSE_ERROR = 0x03,
+ ATSHA204A_STATUS_EXEC_ERROR = 0x0F,
+ ATSHA204A_STATUS_AFTER_WAKE = 0x11,
+ ATSHA204A_STATUS_CRC_ERROR = 0xFF,
+};
+
+enum atsha204a_func
+{
+ ATSHA204A_FUNC_RESET = 0x00,
+ ATSHA204A_FUNC_SLEEP = 0x01,
+ ATSHA204A_FUNC_IDLE = 0x02,
+ ATSHA204A_FUNC_COMMAND = 0x03,
+};
+
+enum atsha204a_cmd
+{
+ ATSHA204A_CMD_READ = 0x02,
+ ATSHA204A_CMD_RANDOM = 0x1B,
+};
+
+struct atsha204a_resp
+{
+ u8 length;
+ u8 code;
+ u8 data[82];
+} __attribute__ ((packed));
+
+struct atsha204a_req
+{
+ u8 function;
+ u8 length;
+ u8 command;
+ u8 param1;
+ u16 param2;
+ u8 data[78];
+} __attribute__ ((packed));
+
+int atsha204a_wakeup(struct udevice *);
+int atsha204a_idle(struct udevice *);
+int atsha204a_sleep(struct udevice *);
+int atsha204a_read(struct udevice *, enum atsha204a_zone, bool, u16, u8 *);
+int atsha204a_get_random(struct udevice *, u8 *, size_t);
+
+#endif /* _ATSHA204_I2C_H_ */