aboutsummaryrefslogtreecommitdiff
path: root/include/crypto/trng4xx.h
blob: d14f632701a25b169773054bec0f3eb450a7babe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
 *
 * Copyright (c) 2008 Loc Ho <spulijala@amcc.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 * @file trng4xx.h
 *
 * This file provides access to the AMCC SoC TRNG.
 *
 *
 */
#ifndef __TRNG4XX_H__
#define __TRNG4XX_H__

/**
 * TRNG Register and bit Definitions
 *
 */

/* Register TRNG4XX_STATUS bit definition */
#define TRNG4XX_STATUS_BUSY                0x00000001

/* Register TRNG4XX_CNTL bit definition */
#define TRNG4XX_CNTL_TST_RING_OUT          0x00000001
#define TRNG4XX_CNTL_TST_MODE              0x00000002
#define TRNG4XX_CNTL_TST_RUN               0x00000004
#define TRNG4XX_CNTL_TST_EN1               0x00000008
#define TRNG4XX_CNTL_TST_EN2               0x00000010
#define TRNG4XX_CNTL_DISABLE_ALARM         0x00000020
#define TRNG4XX_CNTL_CLOCK_ON              0x00000040
#define TRNG4XX_CNTL_SHORT_CYCLE           0x00000080
#define TRNG4XX_CNTL_TST_ALARM             0x00000100
#define TRNG4XX_CNTL_TST_LFSR              0x00000200
#define TRNG4XX_CNTL_RESET_LFSR            0x00000400
#define TRNG4XX_CNTL_BYPASS_TRNG           0x00000800
#define TRNG4XX_CNTL_POST_PROC_EN          0x00001000

/* Register TRNG4XX_CFG bit definition */
#define TRNG4XX_CFG_RING1_DELAY_SEL_SHIFT  0
#define TRNG4XX_CFG_RING1_DELAY_SEL_MASK   (7)
#define TRNG4XX_CFG_RING2_DELAY_SEL_SHIFT  3
#define TRNG4XX_CFG_RING2_DELAY_SEL_MASK   \
			(7 << TRNG4XX_CFG_RING2_DELAY_SEL_SHIFT)
#define TRNG4XX_CFG_RESET_CNT_SHIFT        6
#define TRNG4XX_CFG_RESET_CNT_SHIFT_MASK   \
			(0x3F << TRNG4XX_CFG_RING2_DELAY_SEL_SHIFT)

/* TRNG Register definition */
#define TRNG4XX_OUTPUT_ADDR       0x0000
#define TRNG4XX_STATUS_ADDR       0x0004
#define TRNG4XX_CNTL_ADDR         0x0008
#define TRNG4XX_CFG_ADDR          0x000C
#define TRNG4XX_ALARMCNT_ADDR     0x0010
#define TRNG4XX_AREG_ADDR         0x0014
#define TRNG4XX_BREG_ADDR         0x0018
#define TRNG4XX_XREG_0_ADDR       0x001C
#define TRNG4XX_XREG_1_ADDR       0x0020
#define TRNG4XX_XREG_2_ADDR       0x0024
#define TRNG4XX_LFSR1_L_ADDR      0x0028
#define TRNG4XX_LFSR1_H_ADDR      0x002C
#define TRNG4XX_LFSR2_L_ADDR      0x0030
#define TRNG4XX_LFSR2_H_ADDR      0x0034
#define TRNG4XX_KEY0_L_ADDR       0x0038
#define TRNG4XX_KEY0_H_ADDR       0x003C
#define TRNG4XX_KEY1_L_ADDR       0x0040
#define TRNG4XX_KEY1_H_ADDR       0x0044
#define TRNG4XX_IV_L_ADDR         0x0048
#define TRNG4XX_IV_H_ADDR         0x004C

struct hal_config;

/**
 * @brief   This function MUSTs be called to initialize the HW
 *          access function.
 * @param   hal_cfg        HW access configuration. If NULL,
 *                              default will be used.
 * @note    To load all access functions from HAL with default initial
 *              map address, pass a NULL as its parameter.
 */
int    trng4xx_config_set(struct hal_config *cfg);

/**
 * @brief   This function MUSTs be called to de-initialize the HW
 *          access function.
 */
int    trng4xx_config_clear(void);

/**
 * @brief   This functions reads from the TRNG registers.
 * @param   reg_addr    Device register offset
 * @param   data_val    An DWORD pointer to store the returned value
 */
inline int    trng4xx_hw_read32(u32 reg_addr, u32 *data_val);

/**
 * @brief   This functions writes to the TRNG registers.
 * @param   reg_addr    Device register offset
 * @param   data_val    An DWORD value to write
 */
inline int    trng4xx_hw_write32(u32 reg_addr, u32 data_val);

/**
 * @brief   This functions initializes the TRNG for operation.
 * @return  0 
 */
int 	trng4xx_hw_init(void);

/**
 * @brief   This functions de-initializes the TRNG.
 */
int 	trng4xx_hw_deinit(void);

/**
 * @brief   This functions retrieves an true random number.
 * @param   rand_val    A pointer to a DWORD to store the value
 * @return  0 if successfull. -EINPROGRESS if failed. This
 *          should not happen as this means the hardware still busy.
 */
int 	trng4xx_random(u32 *rand_val);

#endif