xref: /openbmc/u-boot/include/atsha204a-i2c.h (revision bf494d7e)
1 /*
2  * I2C Driver for Atmel ATSHA204 over I2C
3  *
4  * Copyright (C) 2014 Josh Datko, Cryptotronix, jbd@cryptotronix.com
5  * 		 2016 Tomas Hlavacek, CZ.NIC, tmshlvck@gmail.com
6  * 		 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 #ifndef _ATSHA204_I2C_H_
13 #define _ATSHA204_I2C_H_
14 
15 enum atsha204a_zone
16 {
17 	ATSHA204A_ZONE_CONFIG	= 0,
18 	ATSHA204A_ZONE_OTP	= 1,
19 	ATSHA204A_ZONE_DATA	= 2,
20 };
21 
22 enum atsha204a_status
23 {
24 	ATSHA204A_STATUS_SUCCESS	= 0x00,
25 	ATSHA204A_STATUS_MISCOMPARE	= 0x01,
26 	ATSHA204A_STATUS_PARSE_ERROR	= 0x03,
27 	ATSHA204A_STATUS_EXEC_ERROR	= 0x0F,
28 	ATSHA204A_STATUS_AFTER_WAKE	= 0x11,
29 	ATSHA204A_STATUS_CRC_ERROR	= 0xFF,
30 };
31 
32 enum atsha204a_func
33 {
34 	ATSHA204A_FUNC_RESET	= 0x00,
35 	ATSHA204A_FUNC_SLEEP	= 0x01,
36 	ATSHA204A_FUNC_IDLE	= 0x02,
37 	ATSHA204A_FUNC_COMMAND	= 0x03,
38 };
39 
40 enum atsha204a_cmd
41 {
42 	ATSHA204A_CMD_READ	= 0x02,
43 	ATSHA204A_CMD_RANDOM	= 0x1B,
44 };
45 
46 struct atsha204a_resp
47 {
48 	u8 length;
49 	u8 code;
50 	u8 data[82];
51 } __attribute__ ((packed));
52 
53 struct atsha204a_req
54 {
55 	u8 function;
56 	u8 length;
57 	u8 command;
58 	u8 param1;
59 	u16 param2;
60 	u8 data[78];
61 } __attribute__ ((packed));
62 
63 int atsha204a_wakeup(struct udevice *);
64 int atsha204a_idle(struct udevice *);
65 int atsha204a_sleep(struct udevice *);
66 int atsha204a_read(struct udevice *, enum atsha204a_zone, bool, u16, u8 *);
67 int atsha204a_get_random(struct udevice *, u8 *, size_t);
68 
69 #endif /* _ATSHA204_I2C_H_ */
70