1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2021 NXP
4  *
5  * Helper Code for DSPI Controller driver
6  */
7 
8 #ifndef __DRIVERS_LS_DSPI_H
9 #define __DRIVERS_LS_DSPI_H
10 
11 #include <mm/core_memprot.h>
12 #include <spi.h>
13 
14 /* Clock and transfer attributes */
15 #define DSPI_CTAR_BRD	     0x80000000		/* Double Baud Rate [0] */
16 #define DSPI_CTAR_FMSZ(x)    (((x) & 0x0F) << 27) /* Frame Size [1-4] */
17 #define DSPI_CTAR_CPOL	     0x04000000		/* Clock Polarity [5] */
18 #define DSPI_CTAR_CPHA	     0x02000000		/* Clock Phase [6] */
19 #define DSPI_CTAR_LSBFE	     0x01000000		/* LSB First [7] */
20 #define DSPI_CTAR_PCS_SCK(x) (((x) & 0x03) << 22) /* PCSSCK [8-9] */
21 #define DSPI_CTAR_PA_SCK(x)  (((x) & 0x03) << 20) /* PASC [10-11] */
22 #define DSPI_CTAR_P_DT(x)    (((x) & 0x03) << 18) /* PDT [12-13] */
23 #define DSPI_CTAR_BRP(x)     \
24 	(((x) & 0x03) << 16) /* Baud Rate Prescaler [14-15] */
25 #define DSPI_CTAR_CS_SCK(x)  (((x) & 0x0F) << 12) /* CSSCK [16-19] */
26 #define DSPI_CTAR_A_SCK(x)   (((x) & 0x0F) << 8)	/* ASC [20-23] */
27 #define DSPI_CTAR_A_DT(x)    (((x) & 0x0F) << 4)	/* DT [24-27] */
28 #define DSPI_CTAR_BR(x)	     ((x) & 0x0F)	/* Baud Rate Scaler [28-31] */
29 
30 /*
31  * struct ls_dspi_data describes DSPI controller chip instance
32  * The structure contains below members:
33  * chip:		generic spi_chip instance
34  * base:		DSPI controller base address
35  * bus_clk_hz:		DSPI input clk frequency
36  * speed_hz:		Default SCK frequency=1mhz
37  * num_chipselect:	chip/slave selection
38  * slave_bus:		bus value of slave
39  * slave_cs:		chip slect value of slave
40  * slave_speed_max_hz:	max spped of slave
41  * slave_mode:		mode of slave
42  * slave_data_size_bits:Data size to be transferred (8 or 16 bits)
43  * ctar_val:		value of Clock and Transfer Attributes Register (CTAR)
44  * ctar_sel:		CTAR0 or CTAR1
45  */
46 struct ls_dspi_data {
47 	struct spi_chip chip;
48 	vaddr_t base;
49 	unsigned int bus_clk_hz;
50 	unsigned int speed_hz;
51 	unsigned int num_chipselect;
52 	unsigned int slave_bus;
53 	unsigned int slave_cs;
54 	unsigned int slave_speed_max_hz;
55 	unsigned int slave_mode;
56 	unsigned int slave_data_size_bits;
57 	unsigned int ctar_val;
58 	unsigned int ctar_sel;
59 };
60 
61 /*
62  * Initialize DSPI Controller
63  * dspi_data:	DSPI controller chip instance
64  */
65 TEE_Result ls_dspi_init(struct ls_dspi_data *dspi_data);
66 
67 /* Flush RX and TX FIFO */
68 void dspi_flush_fifo(struct ls_dspi_data *dspi_data);
69 
70 #endif /* __DRIVERS_LS_DSPI_H */
71