1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2022, Aspeed Technology Inc.
4  */
5 #include <config.h>
6 #include <platform_config.h>
7 #include <io.h>
8 #include <mm/core_memprot.h>
9 #include <kernel/boot.h>
10 #include <kernel/delay.h>
11 #include <kernel/panic.h>
12 
13 #include "hace_ast2600.h"
14 
15 #define SCU_RST1		0x40
16 #define SCU_RSTCLR1		0x44
17 #define SCU_RST_CRYPTO		BIT(4)
18 
19 #define SCU_CLKGATE1		0x80
20 #define SCU_CLKGATECLR1		0x84
21 #define SCU_CLKGATE_HACE	BIT(13)
22 
crypto_ast2600_init(void)23 static TEE_Result crypto_ast2600_init(void)
24 {
25 	TEE_Result rc = TEE_ERROR_GENERIC;
26 	vaddr_t scu_virt = 0;
27 
28 	scu_virt = core_mmu_get_va(SCU_BASE, MEM_AREA_IO_NSEC, SMALL_PAGE_SIZE);
29 	if (!scu_virt)
30 		panic();
31 
32 	/* ast2600 crypto engines share the same reset control */
33 	io_write32(scu_virt + SCU_RST1, SCU_RST_CRYPTO);
34 	udelay(100);
35 	io_write32(scu_virt + SCU_RSTCLR1, SCU_RST_CRYPTO);
36 
37 	if (IS_ENABLED(CFG_CRYPTO_DRV_HASH)) {
38 		io_write32(scu_virt + SCU_CLKGATECLR1, SCU_CLKGATE_HACE);
39 
40 		rc = ast2600_drvcrypt_register_hash();
41 		if (rc) {
42 			EMSG("cannot register hash driver, rc=%d", rc);
43 			return rc;
44 		}
45 	}
46 
47 	return TEE_SUCCESS;
48 }
49 
50 early_init_late(crypto_ast2600_init);
51