18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * Copyright (C) ST-Ericsson SA 2010
48c2ecf20Sopenharmony_ci * Author: Shujuan Chen <shujuan.chen@stericsson.com> for ST-Ericsson.
58c2ecf20Sopenharmony_ci * Author: Jonas Linde <jonas.linde@stericsson.com> for ST-Ericsson.
68c2ecf20Sopenharmony_ci * Author: Joakim Bech <joakim.xx.bech@stericsson.com> for ST-Ericsson.
78c2ecf20Sopenharmony_ci * Author: Berne Hebark <berne.herbark@stericsson.com> for ST-Ericsson.
88c2ecf20Sopenharmony_ci * Author: Niklas Hernaeus <niklas.hernaeus@stericsson.com> for ST-Ericsson.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _CRYP_P_H_
128c2ecf20Sopenharmony_ci#define _CRYP_P_H_
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/io.h>
158c2ecf20Sopenharmony_ci#include <linux/bitops.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "cryp.h"
188c2ecf20Sopenharmony_ci#include "cryp_irqp.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/**
218c2ecf20Sopenharmony_ci * Generic Macros
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci#define CRYP_SET_BITS(reg_name, mask) \
248c2ecf20Sopenharmony_ci	writel_relaxed((readl_relaxed(reg_name) | mask), reg_name)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define CRYP_WRITE_BIT(reg_name, val, mask) \
278c2ecf20Sopenharmony_ci	writel_relaxed(((readl_relaxed(reg_name) & ~(mask)) |\
288c2ecf20Sopenharmony_ci			((val) & (mask))), reg_name)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define CRYP_TEST_BITS(reg_name, val) \
318c2ecf20Sopenharmony_ci	(readl_relaxed(reg_name) & (val))
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define CRYP_PUT_BITS(reg, val, shift, mask) \
348c2ecf20Sopenharmony_ci	writel_relaxed(((readl_relaxed(reg) & ~(mask)) | \
358c2ecf20Sopenharmony_ci		(((u32)val << shift) & (mask))), reg)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/**
388c2ecf20Sopenharmony_ci * CRYP specific Macros
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define CRYP_PERIPHERAL_ID0		0xE3
418c2ecf20Sopenharmony_ci#define CRYP_PERIPHERAL_ID1		0x05
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define CRYP_PERIPHERAL_ID2_DB8500	0x28
448c2ecf20Sopenharmony_ci#define CRYP_PERIPHERAL_ID3		0x00
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define CRYP_PCELL_ID0			0x0D
478c2ecf20Sopenharmony_ci#define CRYP_PCELL_ID1			0xF0
488c2ecf20Sopenharmony_ci#define CRYP_PCELL_ID2			0x05
498c2ecf20Sopenharmony_ci#define CRYP_PCELL_ID3			0xB1
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/**
528c2ecf20Sopenharmony_ci * CRYP register default values
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_ci#define MAX_DEVICE_SUPPORT		2
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* Priv set, keyrden set and datatype 8bits swapped set as default. */
578c2ecf20Sopenharmony_ci#define CRYP_CR_DEFAULT			0x0482
588c2ecf20Sopenharmony_ci#define CRYP_DMACR_DEFAULT		0x0
598c2ecf20Sopenharmony_ci#define CRYP_IMSC_DEFAULT		0x0
608c2ecf20Sopenharmony_ci#define CRYP_DIN_DEFAULT		0x0
618c2ecf20Sopenharmony_ci#define CRYP_DOUT_DEFAULT		0x0
628c2ecf20Sopenharmony_ci#define CRYP_KEY_DEFAULT		0x0
638c2ecf20Sopenharmony_ci#define CRYP_INIT_VECT_DEFAULT		0x0
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/**
668c2ecf20Sopenharmony_ci * CRYP Control register specific mask
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_ci#define CRYP_CR_SECURE_MASK		BIT(0)
698c2ecf20Sopenharmony_ci#define CRYP_CR_PRLG_MASK		BIT(1)
708c2ecf20Sopenharmony_ci#define CRYP_CR_ALGODIR_MASK		BIT(2)
718c2ecf20Sopenharmony_ci#define CRYP_CR_ALGOMODE_MASK		(BIT(5) | BIT(4) | BIT(3))
728c2ecf20Sopenharmony_ci#define CRYP_CR_DATATYPE_MASK		(BIT(7) | BIT(6))
738c2ecf20Sopenharmony_ci#define CRYP_CR_KEYSIZE_MASK		(BIT(9) | BIT(8))
748c2ecf20Sopenharmony_ci#define CRYP_CR_KEYRDEN_MASK		BIT(10)
758c2ecf20Sopenharmony_ci#define CRYP_CR_KSE_MASK		BIT(11)
768c2ecf20Sopenharmony_ci#define CRYP_CR_START_MASK		BIT(12)
778c2ecf20Sopenharmony_ci#define CRYP_CR_INIT_MASK		BIT(13)
788c2ecf20Sopenharmony_ci#define CRYP_CR_FFLUSH_MASK		BIT(14)
798c2ecf20Sopenharmony_ci#define CRYP_CR_CRYPEN_MASK		BIT(15)
808c2ecf20Sopenharmony_ci#define CRYP_CR_CONTEXT_SAVE_MASK	(CRYP_CR_SECURE_MASK |\
818c2ecf20Sopenharmony_ci					 CRYP_CR_PRLG_MASK |\
828c2ecf20Sopenharmony_ci					 CRYP_CR_ALGODIR_MASK |\
838c2ecf20Sopenharmony_ci					 CRYP_CR_ALGOMODE_MASK |\
848c2ecf20Sopenharmony_ci					 CRYP_CR_DATATYPE_MASK |\
858c2ecf20Sopenharmony_ci					 CRYP_CR_KEYSIZE_MASK |\
868c2ecf20Sopenharmony_ci					 CRYP_CR_KEYRDEN_MASK |\
878c2ecf20Sopenharmony_ci					 CRYP_CR_DATATYPE_MASK)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define CRYP_SR_INFIFO_READY_MASK	(BIT(0) | BIT(1))
918c2ecf20Sopenharmony_ci#define CRYP_SR_IFEM_MASK		BIT(0)
928c2ecf20Sopenharmony_ci#define CRYP_SR_BUSY_MASK		BIT(4)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/**
958c2ecf20Sopenharmony_ci * Bit position used while setting bits in register
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ci#define CRYP_CR_PRLG_POS		1
988c2ecf20Sopenharmony_ci#define CRYP_CR_ALGODIR_POS		2
998c2ecf20Sopenharmony_ci#define CRYP_CR_ALGOMODE_POS		3
1008c2ecf20Sopenharmony_ci#define CRYP_CR_DATATYPE_POS		6
1018c2ecf20Sopenharmony_ci#define CRYP_CR_KEYSIZE_POS		8
1028c2ecf20Sopenharmony_ci#define CRYP_CR_KEYRDEN_POS		10
1038c2ecf20Sopenharmony_ci#define CRYP_CR_KSE_POS			11
1048c2ecf20Sopenharmony_ci#define CRYP_CR_START_POS		12
1058c2ecf20Sopenharmony_ci#define CRYP_CR_INIT_POS		13
1068c2ecf20Sopenharmony_ci#define CRYP_CR_CRYPEN_POS		15
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define CRYP_SR_BUSY_POS		4
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/**
1118c2ecf20Sopenharmony_ci * CRYP PCRs------PC_NAND control register
1128c2ecf20Sopenharmony_ci * BIT_MASK
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_ci#define CRYP_DMA_REQ_MASK		(BIT(1) | BIT(0))
1158c2ecf20Sopenharmony_ci#define CRYP_DMA_REQ_MASK_POS		0
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistruct cryp_system_context {
1198c2ecf20Sopenharmony_ci	/* CRYP Register structure */
1208c2ecf20Sopenharmony_ci	struct cryp_register *p_cryp_reg[MAX_DEVICE_SUPPORT];
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#endif
124