summaryrefslogtreecommitdiffstats
path: root/src/soc/sifive/fu540/include/soc/spi.h
blob: 3be5baf5cf3493c21816b5ceeb10e648f56ceaaf (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
/* SPDX-License-Identifier: GPL-2.0-only */

#ifndef __SOC_SIFIVE_HIFIVE_U_SPI_H__
#define __SOC_SIFIVE_HIFIVE_U_SPI_H__
#include <spi-generic.h>

/* Data Pins: MOSI MISO */
#define FU540_SPI_PROTO_S	0
/* Data Pins: DQ0 DQ1 */
#define FU540_SPI_PROTO_D	1
/* Data Pins: DQ0 DQ1 DQ2 DQ3 */
#define FU540_SPI_PROTO_Q	2

/* send MSB first */
#define FU540_SPI_ENDIAN_BIG	0
/* send LSB first */
#define FU540_SPI_ENDIAN_LITTLE	1

/* inactive state of SCK is logical 0 */
#define FU540_SPI_PHA_LOW	0
/* inactive state of SCK is logical 1 */
#define FU540_SPI_PHA_HIGH	1

/* data is sampled on leading edge */
#define FU540_SPI_POL_LEADING	0
/* data is sampled on trailing edge */
#define FU540_SPI_POL_TRAILING	1

struct fu540_spi_config {
	/* speed of spi interface */
	unsigned int freq;
	/* serial clock phase */
	unsigned int pha;
	/* serial clock polarity */
	unsigned int pol;
	unsigned int protocol;
	unsigned int endianness;
	/* up to 8bits */
	unsigned int bits_per_frame;
};

/* more detailed spi configuration */
int fu540_spi_setup(unsigned int bus, unsigned int cs, struct spi_slave *slave,
		struct fu540_spi_config *config);

/* This structure is used to describe the read command of SPI FLASH. */
struct fu540_spi_mmap_config {
	/* enable sending of command */
	unsigned int cmd_en;
	/* number of address bytes (0-4) */
	unsigned int addr_len;
	/* number of dummy cycles */
	unsigned int pad_cnt;
	/* protocol for transmitting command */
	unsigned int cmd_proto;
	/* protocol for transmitting address and padding */
	unsigned int addr_proto;
	/* protocol for receiving data bytes */
	unsigned int data_proto;
	/* value of command byte */
	unsigned int cmd_code;
	/* first 8 bits to transmit during dummy cycles */
	unsigned int pad_code;
};

int fu540_spi_mmap(
		const struct spi_slave *slave,
		const struct fu540_spi_mmap_config *config);

#endif /* __SOC_SIFIVE_HIFIVE_U_SPI_H__ */