xref: /rk3399_rockchip-uboot/examples/standalone/README_rkspi.md (revision c26430b76c40c6d2ecf167f6ef78694f9cfe4d11)
1*c26430b7SJon Lin# RK SPI Standalone Bin
2*c26430b7SJon Lin
3*c26430b7SJon LinThis is the readme for the Das U-Boot standalone program rkspi
4*c26430b7SJon Lin
5*c26430b7SJon Lin
6*c26430b7SJon LinHow To Use
7*c26430b7SJon Lin------------------------
8*c26430b7SJon Lin### Compile
9*c26430b7SJon Lin
10*c26430b7SJon Lin1.Define the standalone load address in includes/configs/rkxxxxx_common.h
11*c26430b7SJon Lin
12*c26430b7SJon Lin```shell
13*c26430b7SJon Lin#define CONFIG_STANDALONE_LOAD_ADDR    0x40000000
14*c26430b7SJon Lin```
15*c26430b7SJon Lin
16*c26430b7SJon Lin2.Enable rkspi in defconfig
17*c26430b7SJon Lin
18*c26430b7SJon Lin```
19*c26430b7SJon LinCONFIG_ROCKCHIP_SPI=y
20*c26430b7SJon Lin```
21*c26430b7SJon Lin
22*c26430b7SJon Lin### Setting SPI hardware
23*c26430b7SJon Lin
24*c26430b7SJon Lin1.Setting the iomux and spiclk through:
25*c26430b7SJon Lin
26*c26430b7SJon Lin- u-boot shell command
27*c26430b7SJon Lin- define it in rkspi.c spi_hw_init
28*c26430b7SJon Lin
29*c26430b7SJon LinNote:
30*c26430b7SJon Lin
31*c26430b7SJon Lin- spiclk is the clock for spi controller, output to IO after internal frequency division of the controller.
32*c26430b7SJon Lin
33*c26430b7SJon Lin### Load And Executable
34*c26430b7SJon Lin
35*c26430b7SJon Lin1. load the bin by serial or tftp, take tftp as example:
36*c26430b7SJon Lin
37*c26430b7SJon Lin```shell
38*c26430b7SJon Linsetenv ipaddr 172.16.12.157
39*c26430b7SJon Linsetenv serverip 172.16.12.167
40*c26430b7SJon Lintftp 0x40000000 rkspi.bin		# 0x40000000 is define by CONFIG_STANDALONE_LOAD_ADDR
41*c26430b7SJon Lin```
42*c26430b7SJon Lin
43*c26430b7SJon Lin2. execute it
44*c26430b7SJon Lin
45*c26430b7SJon Lin```shell
46*c26430b7SJon Lingo 0x40000000		# 0x40000000 is define by CONFIG_STANDALONE_LOAD_ADDR
47*c26430b7SJon Lin```
48*c26430b7SJon Lin
49*c26430b7SJon Lin## Abort Codes
50*c26430b7SJon Lin
51*c26430b7SJon Lin### Introduction
52*c26430b7SJon Lin
53*c26430b7SJon Lin```c
54*c26430b7SJon Linint rockchip_spi_probe(u8 bus, uintptr_t base_addr, u32 rsd, u32 clock_div, u32 mode);
55*c26430b7SJon Lin```
56*c26430b7SJon Lin
57*c26430b7SJon Lin- bus: spi bus
58*c26430b7SJon Lin- base_addr: spi register base address
59*c26430b7SJon Lin- rsd: read sample clock shift with spiclk which is controller working rate
60*c26430b7SJon Lin- clock_div: internal frequency division of the controller
61*c26430b7SJon Lin- mode: spi mode, support:
62*c26430b7SJon Lin
63*c26430b7SJon Lin```c
64*c26430b7SJon Lin#define SPI_CPHA	BIT(0)			/* clock phase */
65*c26430b7SJon Lin#define SPI_CPOL	BIT(1)			/* clock polarity */
66*c26430b7SJon Lin#define SPI_MODE_0	(0 | 0)			/* (original MicroWire) */
67*c26430b7SJon Lin#define SPI_MODE_1	(0 | SPI_CPHA)
68*c26430b7SJon Lin#define SPI_MODE_2	(SPI_CPOL | 0)
69*c26430b7SJon Lin#define SPI_MODE_3	(SPI_CPOL | SPI_CPHA)
70*c26430b7SJon Lin```
71*c26430b7SJon Lin
72*c26430b7SJon Lin
73*c26430b7SJon Lin
74*c26430b7SJon Lin```c
75*c26430b7SJon Linint rockchip_spi_claim_bus(u8 bus);
76*c26430b7SJon Lin```
77*c26430b7SJon Lin
78*c26430b7SJon Lin- bus: spi bus
79*c26430b7SJon Lin
80*c26430b7SJon Lin
81*c26430b7SJon Lin
82*c26430b7SJon Lin```c
83*c26430b7SJon Linvoid rockchip_spi_release_bus(u8 bus);
84*c26430b7SJon Lin```
85*c26430b7SJon Lin
86*c26430b7SJon Lin- bus: spi bus
87*c26430b7SJon Lin
88*c26430b7SJon Lin
89*c26430b7SJon Lin
90*c26430b7SJon Lin```c
91*c26430b7SJon Linint rockchip_spi_xfer(u8 bus, u8 cs, unsigned int bitlen, const void *dout, void *din, unsigned long flags);
92*c26430b7SJon Lin```
93*c26430b7SJon Lin
94*c26430b7SJon Lin- bus: spi bus
95*c26430b7SJon Lin- cs: spi cs
96*c26430b7SJon Lin- bitlen: the transfer length in bits
97*c26430b7SJon Lin- dout: write buffer (if exits)
98*c26430b7SJon Lin- din: read buffer (if exits), if the dout and din both defined, spi work in duplex mode
99*c26430b7SJon Lin- flags: operation chip select, support:
100*c26430b7SJon Lin
101*c26430b7SJon Lin```c
102*c26430b7SJon Lin#define SPI_XFER_BEGIN		BIT(0)	/* Assert CS before transfer */
103*c26430b7SJon Lin#define SPI_XFER_END		BIT(1)	/* Deassert CS after transfer */
104*c26430b7SJon Lin#define SPI_XFER_ONCE		(SPI_XFER_BEGIN | SPI_XFER_END)
105*c26430b7SJon Lin```
106*c26430b7SJon Lin
107*c26430b7SJon Lin
108*c26430b7SJon Lin
109*c26430b7SJon Lin```c
110*c26430b7SJon Linint rockchip_spi_write_then_read(u8 bus, u8 cs,
111*c26430b7SJon Lin				 const u8 *opcode, size_t n_opcode,
112*c26430b7SJon Lin				 const u8 *txbuf, u8 *rxbuf, size_t n_buf);
113*c26430b7SJon Lin```
114*c26430b7SJon Lin
115*c26430b7SJon Lin- bus: spi bus
116*c26430b7SJon Lin- cs: spi cs
117*c26430b7SJon Lin- opcode: command code
118*c26430b7SJon Lin- n_opcode: the numbers of command code in bytes
119*c26430b7SJon Lin- txbuf: write buffer (if exits)
120*c26430b7SJon Lin- rxbuf: read buffer (if exits), if the dout and din both defined, spi work in duplex mode
121*c26430b7SJon Lin- n_buf: the transfer length in bytes
122*c26430b7SJon Lin
123*c26430b7SJon Lin### Demo
124*c26430b7SJon Lin
125*c26430b7SJon LinIs right in the main function of rkspi.
126*c26430b7SJon Lin
127