xref: /rk3399_rockchip-uboot/include/spi.h (revision a3171fa36692e3b3522663b31f526a2a678066c7)
1 /*
2  * Common SPI Interface: Controller-specific definitions
3  *
4  * (C) Copyright 2001
5  * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #ifndef _SPI_H_
11 #define _SPI_H_
12 
13 #include <common.h>
14 
15 /* SPI mode flags */
16 #define SPI_CPHA	BIT(0)			/* clock phase */
17 #define SPI_CPOL	BIT(1)			/* clock polarity */
18 #define SPI_MODE_0	(0|0)			/* (original MicroWire) */
19 #define SPI_MODE_1	(0|SPI_CPHA)
20 #define SPI_MODE_2	(SPI_CPOL|0)
21 #define SPI_MODE_3	(SPI_CPOL|SPI_CPHA)
22 #define SPI_CS_HIGH	BIT(2)			/* CS active high */
23 #define SPI_LSB_FIRST	BIT(3)			/* per-word bits-on-wire */
24 #define SPI_3WIRE	BIT(4)			/* SI/SO signals shared */
25 #define SPI_LOOP	BIT(5)			/* loopback mode */
26 #define SPI_SLAVE	BIT(6)			/* slave mode */
27 #define SPI_PREAMBLE	BIT(7)			/* Skip preamble bytes */
28 #define SPI_TX_BYTE	BIT(8)			/* transmit with 1 wire byte */
29 #define SPI_TX_DUAL	BIT(9)			/* transmit with 2 wires */
30 #define SPI_TX_QUAD	BIT(10)			/* transmit with 4 wires */
31 #define SPI_RX_SLOW	BIT(11)			/* receive with 1 wire slow */
32 #define SPI_RX_DUAL	BIT(12)			/* receive with 2 wires */
33 #define SPI_RX_QUAD	BIT(13)			/* receive with 4 wires */
34 #define SPI_DMA_PREPARE	BIT(24)			/* dma transfer skip waiting idle */
35 
36 /* Header byte that marks the start of the message */
37 #define SPI_PREAMBLE_END_BYTE	0xec
38 
39 #define SPI_DEFAULT_WORDLEN	8
40 
41 #ifdef CONFIG_DM_SPI
42 /* TODO(sjg@chromium.org): Remove this and use max_hz from struct spi_slave */
43 struct dm_spi_bus {
44 	uint max_hz;
45 };
46 
47 /**
48  * struct dm_spi_platdata - platform data for all SPI slaves
49  *
50  * This describes a SPI slave, a child device of the SPI bus. To obtain this
51  * struct from a spi_slave, use dev_get_parent_platdata(dev) or
52  * dev_get_parent_platdata(slave->dev).
53  *
54  * This data is immuatable. Each time the device is probed, @max_hz and @mode
55  * will be copied to struct spi_slave.
56  *
57  * @cs:		Chip select number (0..n-1)
58  * @max_hz:	Maximum bus speed that this slave can tolerate
59  * @mode:	SPI mode to use for this device (see SPI mode flags)
60  */
61 struct dm_spi_slave_platdata {
62 	unsigned int cs;
63 	uint max_hz;
64 	uint mode;
65 };
66 
67 #endif /* CONFIG_DM_SPI */
68 
69 /**
70  * struct spi_slave - Representation of a SPI slave
71  *
72  * For driver model this is the per-child data used by the SPI bus. It can
73  * be accessed using dev_get_parent_priv() on the slave device. The SPI uclass
74  * sets uip per_child_auto_alloc_size to sizeof(struct spi_slave), and the
75  * driver should not override it. Two platform data fields (max_hz and mode)
76  * are copied into this structure to provide an initial value. This allows
77  * them to be changed, since we should never change platform data in drivers.
78  *
79  * If not using driver model, drivers are expected to extend this with
80  * controller-specific data.
81  *
82  * @dev:		SPI slave device
83  * @max_hz:		Maximum speed for this slave
84  * @speed:		Current bus speed. This is 0 until the bus is first
85  *			claimed.
86  * @bus:		ID of the bus that the slave is attached to. For
87  *			driver model this is the sequence number of the SPI
88  *			bus (bus->seq) so does not need to be stored
89  * @cs:			ID of the chip select connected to the slave.
90  * @mode:		SPI mode to use for this slave (see SPI mode flags)
91  * @wordlen:		Size of SPI word in number of bits
92  * @max_read_size:	If non-zero, the maximum number of bytes which can
93  *			be read at once.
94  * @max_write_size:	If non-zero, the maximum number of bytes which can
95  *			be written at once.
96  * @memory_map:		Address of read-only SPI flash access.
97  * @flags:		Indication of SPI flags.
98  */
99 struct spi_slave {
100 #ifdef CONFIG_DM_SPI
101 	struct udevice *dev;	/* struct spi_slave is dev->parentdata */
102 	uint max_hz;
103 	uint speed;
104 #else
105 	unsigned int bus;
106 	unsigned int cs;
107 #endif
108 	uint mode;
109 	unsigned int wordlen;
110 	unsigned int max_read_size;
111 	unsigned int max_write_size;
112 	void *memory_map;
113 	u8 option;
114 
115 	u8 flags;
116 #define SPI_XFER_BEGIN		BIT(0)	/* Assert CS before transfer */
117 #define SPI_XFER_END		BIT(1)	/* Deassert CS after transfer */
118 #define SPI_XFER_ONCE		(SPI_XFER_BEGIN | SPI_XFER_END)
119 #define SPI_XFER_MMAP		BIT(2)	/* Memory Mapped start */
120 #define SPI_XFER_MMAP_END	BIT(3)	/* Memory Mapped End */
121 #define SPI_XFER_PREPARE	BIT(7)	/* Transfer skip waiting idle */
122 };
123 
124 /**
125  * Initialization, must be called once on start up.
126  *
127  * TODO: I don't think we really need this.
128  */
129 void spi_init(void);
130 
131 /**
132  * spi_do_alloc_slave - Allocate a new SPI slave (internal)
133  *
134  * Allocate and zero all fields in the spi slave, and set the bus/chip
135  * select. Use the helper macro spi_alloc_slave() to call this.
136  *
137  * @offset:	Offset of struct spi_slave within slave structure.
138  * @size:	Size of slave structure.
139  * @bus:	Bus ID of the slave chip.
140  * @cs:		Chip select ID of the slave chip on the specified bus.
141  */
142 void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
143 			 unsigned int cs);
144 
145 /**
146  * spi_alloc_slave - Allocate a new SPI slave
147  *
148  * Allocate and zero all fields in the spi slave, and set the bus/chip
149  * select.
150  *
151  * @_struct:	Name of structure to allocate (e.g. struct tegra_spi).
152  *		This structure must contain a member 'struct spi_slave *slave'.
153  * @bus:	Bus ID of the slave chip.
154  * @cs:		Chip select ID of the slave chip on the specified bus.
155  */
156 #define spi_alloc_slave(_struct, bus, cs) \
157 	spi_do_alloc_slave(offsetof(_struct, slave), \
158 			    sizeof(_struct), bus, cs)
159 
160 /**
161  * spi_alloc_slave_base - Allocate a new SPI slave with no private data
162  *
163  * Allocate and zero all fields in the spi slave, and set the bus/chip
164  * select.
165  *
166  * @bus:	Bus ID of the slave chip.
167  * @cs:		Chip select ID of the slave chip on the specified bus.
168  */
169 #define spi_alloc_slave_base(bus, cs) \
170 	spi_do_alloc_slave(0, sizeof(struct spi_slave), bus, cs)
171 
172 /**
173  * Set up communications parameters for a SPI slave.
174  *
175  * This must be called once for each slave. Note that this function
176  * usually doesn't touch any actual hardware, it only initializes the
177  * contents of spi_slave so that the hardware can be easily
178  * initialized later.
179  *
180  * @bus:	Bus ID of the slave chip.
181  * @cs:		Chip select ID of the slave chip on the specified bus.
182  * @max_hz:	Maximum SCK rate in Hz.
183  * @mode:	Clock polarity, clock phase and other parameters.
184  *
185  * Returns: A spi_slave reference that can be used in subsequent SPI
186  * calls, or NULL if one or more of the parameters are not supported.
187  */
188 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
189 		unsigned int max_hz, unsigned int mode);
190 
191 /**
192  * Free any memory associated with a SPI slave.
193  *
194  * @slave:	The SPI slave
195  */
196 void spi_free_slave(struct spi_slave *slave);
197 
198 /**
199  * Claim the bus and prepare it for communication with a given slave.
200  *
201  * This must be called before doing any transfers with a SPI slave. It
202  * will enable and initialize any SPI hardware as necessary, and make
203  * sure that the SCK line is in the correct idle state. It is not
204  * allowed to claim the same bus for several slaves without releasing
205  * the bus in between.
206  *
207  * @slave:	The SPI slave
208  *
209  * Returns: 0 if the bus was claimed successfully, or a negative value
210  * if it wasn't.
211  */
212 int spi_claim_bus(struct spi_slave *slave);
213 
214 /**
215  * Release the SPI bus
216  *
217  * This must be called once for every call to spi_claim_bus() after
218  * all transfers have finished. It may disable any SPI hardware as
219  * appropriate.
220  *
221  * @slave:	The SPI slave
222  */
223 void spi_release_bus(struct spi_slave *slave);
224 
225 /**
226  * Set the word length for SPI transactions
227  *
228  * Set the word length (number of bits per word) for SPI transactions.
229  *
230  * @slave:	The SPI slave
231  * @wordlen:	The number of bits in a word
232  *
233  * Returns: 0 on success, -1 on failure.
234  */
235 int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
236 
237 /**
238  * SPI transfer
239  *
240  * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
241  * "bitlen" bits in the SPI MISO port.  That's just the way SPI works.
242  *
243  * The source of the outgoing bits is the "dout" parameter and the
244  * destination of the input bits is the "din" parameter.  Note that "dout"
245  * and "din" can point to the same memory location, in which case the
246  * input data overwrites the output data (since both are buffered by
247  * temporary variables, this is OK).
248  *
249  * spi_xfer() interface:
250  * @slave:	The SPI slave which will be sending/receiving the data.
251  * @bitlen:	How many bits to write and read.
252  * @dout:	Pointer to a string of bits to send out.  The bits are
253  *		held in a byte array and are sent MSB first.
254  * @din:	Pointer to a string of bits that will be filled in.
255  * @flags:	A bitwise combination of SPI_XFER_* flags.
256  *
257  * Returns: 0 on success, not 0 on failure
258  */
259 int  spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
260 		void *din, unsigned long flags);
261 
262 /**
263  * spi_write_then_read - SPI synchronous write followed by read
264  *
265  * This performs a half duplex transaction in which the first transaction
266  * is to send the opcode and if the length of buf is non-zero then it start
267  * the second transaction as tx or rx based on the need from respective slave.
268  *
269  * @slave:	The SPI slave device with which opcode/data will be exchanged
270  * @opcode:	opcode used for specific transfer
271  * @n_opcode:	size of opcode, in bytes
272  * @txbuf:	buffer into which data to be written
273  * @rxbuf:	buffer into which data will be read
274  * @n_buf:	size of buf (whether it's [tx|rx]buf), in bytes
275  *
276  * Returns: 0 on success, not 0 on failure
277  */
278 int spi_write_then_read(struct spi_slave *slave, const u8 *opcode,
279 			size_t n_opcode, const u8 *txbuf, u8 *rxbuf,
280 			size_t n_buf);
281 
282 /* Copy memory mapped data */
283 void spi_flash_copy_mmap(void *data, void *offset, size_t len);
284 
285 /**
286  * Determine if a SPI chipselect is valid.
287  * This function is provided by the board if the low-level SPI driver
288  * needs it to determine if a given chipselect is actually valid.
289  *
290  * Returns: 1 if bus:cs identifies a valid chip on this board, 0
291  * otherwise.
292  */
293 int spi_cs_is_valid(unsigned int bus, unsigned int cs);
294 
295 #ifndef CONFIG_DM_SPI
296 /**
297  * Activate a SPI chipselect.
298  * This function is provided by the board code when using a driver
299  * that can't control its chipselects automatically (e.g.
300  * common/soft_spi.c). When called, it should activate the chip select
301  * to the device identified by "slave".
302  */
303 void spi_cs_activate(struct spi_slave *slave);
304 
305 /**
306  * Deactivate a SPI chipselect.
307  * This function is provided by the board code when using a driver
308  * that can't control its chipselects automatically (e.g.
309  * common/soft_spi.c). When called, it should deactivate the chip
310  * select to the device identified by "slave".
311  */
312 void spi_cs_deactivate(struct spi_slave *slave);
313 
314 /**
315  * Set transfer speed.
316  * This sets a new speed to be applied for next spi_xfer().
317  * @slave:	The SPI slave
318  * @hz:		The transfer speed
319  */
320 void spi_set_speed(struct spi_slave *slave, uint hz);
321 #endif
322 
323 /**
324  * Write 8 bits, then read 8 bits.
325  * @slave:	The SPI slave we're communicating with
326  * @byte:	Byte to be written
327  *
328  * Returns: The value that was read, or a negative value on error.
329  *
330  * TODO: This function probably shouldn't be inlined.
331  */
332 static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte)
333 {
334 	unsigned char dout[2];
335 	unsigned char din[2];
336 	int ret;
337 
338 	dout[0] = byte;
339 	dout[1] = 0;
340 
341 	ret = spi_xfer(slave, 16, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
342 	return ret < 0 ? ret : din[1];
343 }
344 
345 #ifdef CONFIG_DM_SPI
346 
347 /**
348  * struct spi_cs_info - Information about a bus chip select
349  *
350  * @dev:	Connected device, or NULL if none
351  */
352 struct spi_cs_info {
353 	struct udevice *dev;
354 };
355 
356 /**
357  * struct struct dm_spi_ops - Driver model SPI operations
358  *
359  * The uclass interface is implemented by all SPI devices which use
360  * driver model.
361  */
362 struct dm_spi_ops {
363 	/**
364 	 * Claim the bus and prepare it for communication.
365 	 *
366 	 * The device provided is the slave device. It's parent controller
367 	 * will be used to provide the communication.
368 	 *
369 	 * This must be called before doing any transfers with a SPI slave. It
370 	 * will enable and initialize any SPI hardware as necessary, and make
371 	 * sure that the SCK line is in the correct idle state. It is not
372 	 * allowed to claim the same bus for several slaves without releasing
373 	 * the bus in between.
374 	 *
375 	 * @dev:	The SPI slave
376 	 *
377 	 * Returns: 0 if the bus was claimed successfully, or a negative value
378 	 * if it wasn't.
379 	 */
380 	int (*claim_bus)(struct udevice *dev);
381 
382 	/**
383 	 * Release the SPI bus
384 	 *
385 	 * This must be called once for every call to spi_claim_bus() after
386 	 * all transfers have finished. It may disable any SPI hardware as
387 	 * appropriate.
388 	 *
389 	 * @dev:	The SPI slave
390 	 */
391 	int (*release_bus)(struct udevice *dev);
392 
393 	/**
394 	 * Set the word length for SPI transactions
395 	 *
396 	 * Set the word length (number of bits per word) for SPI transactions.
397 	 *
398 	 * @bus:	The SPI slave
399 	 * @wordlen:	The number of bits in a word
400 	 *
401 	 * Returns: 0 on success, -ve on failure.
402 	 */
403 	int (*set_wordlen)(struct udevice *dev, unsigned int wordlen);
404 
405 	/**
406 	 * SPI transfer
407 	 *
408 	 * This writes "bitlen" bits out the SPI MOSI port and simultaneously
409 	 * clocks "bitlen" bits in the SPI MISO port.  That's just the way SPI
410 	 * works.
411 	 *
412 	 * The source of the outgoing bits is the "dout" parameter and the
413 	 * destination of the input bits is the "din" parameter.  Note that
414 	 * "dout" and "din" can point to the same memory location, in which
415 	 * case the input data overwrites the output data (since both are
416 	 * buffered by temporary variables, this is OK).
417 	 *
418 	 * spi_xfer() interface:
419 	 * @dev:	The slave device to communicate with
420 	 * @bitlen:	How many bits to write and read.
421 	 * @dout:	Pointer to a string of bits to send out.  The bits are
422 	 *		held in a byte array and are sent MSB first.
423 	 * @din:	Pointer to a string of bits that will be filled in.
424 	 * @flags:	A bitwise combination of SPI_XFER_* flags.
425 	 *
426 	 * Returns: 0 on success, not -1 on failure
427 	 */
428 	int (*xfer)(struct udevice *dev, unsigned int bitlen, const void *dout,
429 		    void *din, unsigned long flags);
430 
431 	/**
432 	 * Optimized handlers for SPI memory-like operations.
433 	 *
434 	 * Optimized/dedicated operations for interactions with SPI memory. This
435 	 * field is optional and should only be implemented if the controller
436 	 * has native support for memory like operations.
437 	 */
438 	const struct spi_controller_mem_ops *mem_ops;
439 
440 	/**
441 	 * Set transfer speed.
442 	 * This sets a new speed to be applied for next spi_xfer().
443 	 * @bus:	The SPI bus
444 	 * @hz:		The transfer speed
445 	 * @return 0 if OK, -ve on error
446 	 */
447 	int (*set_speed)(struct udevice *bus, uint hz);
448 
449 	/**
450 	 * Set the SPI mode/flags
451 	 *
452 	 * It is unclear if we want to set speed and mode together instead
453 	 * of separately.
454 	 *
455 	 * @bus:	The SPI bus
456 	 * @mode:	Requested SPI mode (SPI_... flags)
457 	 * @return 0 if OK, -ve on error
458 	 */
459 	int (*set_mode)(struct udevice *bus, uint mode);
460 
461 	/**
462 	 * Get information on a chip select
463 	 *
464 	 * This is only called when the SPI uclass does not know about a
465 	 * chip select, i.e. it has no attached device. It gives the driver
466 	 * a chance to allow activity on that chip select even so.
467 	 *
468 	 * @bus:	The SPI bus
469 	 * @cs:		The chip select (0..n-1)
470 	 * @info:	Returns information about the chip select, if valid.
471 	 *		On entry info->dev is NULL
472 	 * @return 0 if OK (and @info is set up), -ENODEV if the chip select
473 	 *	   is invalid, other -ve value on error
474 	 */
475 	int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info);
476 };
477 
478 struct dm_spi_emul_ops {
479 	/**
480 	 * SPI transfer
481 	 *
482 	 * This writes "bitlen" bits out the SPI MOSI port and simultaneously
483 	 * clocks "bitlen" bits in the SPI MISO port.  That's just the way SPI
484 	 * works. Here the device is a slave.
485 	 *
486 	 * The source of the outgoing bits is the "dout" parameter and the
487 	 * destination of the input bits is the "din" parameter.  Note that
488 	 * "dout" and "din" can point to the same memory location, in which
489 	 * case the input data overwrites the output data (since both are
490 	 * buffered by temporary variables, this is OK).
491 	 *
492 	 * spi_xfer() interface:
493 	 * @slave:	The SPI slave which will be sending/receiving the data.
494 	 * @bitlen:	How many bits to write and read.
495 	 * @dout:	Pointer to a string of bits sent to the device. The
496 	 *		bits are held in a byte array and are sent MSB first.
497 	 * @din:	Pointer to a string of bits that will be sent back to
498 	 *		the master.
499 	 * @flags:	A bitwise combination of SPI_XFER_* flags.
500 	 *
501 	 * Returns: 0 on success, not -1 on failure
502 	 */
503 	int (*xfer)(struct udevice *slave, unsigned int bitlen,
504 		    const void *dout, void *din, unsigned long flags);
505 };
506 
507 /**
508  * spi_find_bus_and_cs() - Find bus and slave devices by number
509  *
510  * Given a bus number and chip select, this finds the corresponding bus
511  * device and slave device. Neither device is activated by this function,
512  * although they may have been activated previously.
513  *
514  * @busnum:	SPI bus number
515  * @cs:		Chip select to look for
516  * @busp:	Returns bus device
517  * @devp:	Return slave device
518  * @return 0 if found, -ENODEV on error
519  */
520 int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp,
521 			struct udevice **devp);
522 
523 /**
524  * spi_get_bus_and_cs() - Find and activate bus and slave devices by number
525  *
526  * Given a bus number and chip select, this finds the corresponding bus
527  * device and slave device.
528  *
529  * If no such slave exists, and drv_name is not NULL, then a new slave device
530  * is automatically bound on this chip select with requested speed and mode.
531  *
532  * Ths new slave device is probed ready for use with the speed and mode
533  * from platdata when available or the requested values.
534  *
535  * @busnum:	SPI bus number
536  * @cs:		Chip select to look for
537  * @speed:	SPI speed to use for this slave when not available in platdata
538  * @mode:	SPI mode to use for this slave when not available in platdata
539  * @drv_name:	Name of driver to attach to this chip select
540  * @dev_name:	Name of the new device thus created
541  * @busp:	Returns bus device
542  * @devp:	Return slave device
543  * @return 0 if found, -ve on error
544  */
545 int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
546 			const char *drv_name, const char *dev_name,
547 			struct udevice **busp, struct spi_slave **devp);
548 
549 /**
550  * spi_chip_select() - Get the chip select for a slave
551  *
552  * @return the chip select this slave is attached to
553  */
554 int spi_chip_select(struct udevice *slave);
555 
556 /**
557  * spi_find_chip_select() - Find the slave attached to chip select
558  *
559  * @bus:	SPI bus to search
560  * @cs:		Chip select to look for
561  * @devp:	Returns the slave device if found
562  * @return 0 if found, -ENODEV on error
563  */
564 int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp);
565 
566 /**
567  * spi_slave_ofdata_to_platdata() - decode standard SPI platform data
568  *
569  * This decodes the speed and mode for a slave from a device tree node
570  *
571  * @blob:	Device tree blob
572  * @node:	Node offset to read from
573  * @plat:	Place to put the decoded information
574  */
575 int spi_slave_ofdata_to_platdata(struct udevice *dev,
576 				 struct dm_spi_slave_platdata *plat);
577 
578 /**
579  * spi_cs_info() - Check information on a chip select
580  *
581  * This checks a particular chip select on a bus to see if it has a device
582  * attached, or is even valid.
583  *
584  * @bus:	The SPI bus
585  * @cs:		The chip select (0..n-1)
586  * @info:	Returns information about the chip select, if valid
587  * @return 0 if OK (and @info is set up), -ENODEV if the chip select
588  *	   is invalid, other -ve value on error
589  */
590 int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info);
591 
592 struct sandbox_state;
593 
594 /**
595  * sandbox_spi_get_emul() - get an emulator for a SPI slave
596  *
597  * This provides a way to attach an emulated SPI device to a particular SPI
598  * slave, so that xfer() operations on the slave will be handled by the
599  * emulator. If a emulator already exists on that chip select it is returned.
600  * Otherwise one is created.
601  *
602  * @state:	Sandbox state
603  * @bus:	SPI bus requesting the emulator
604  * @slave:	SPI slave device requesting the emulator
605  * @emuip:	Returns pointer to emulator
606  * @return 0 if OK, -ve on error
607  */
608 int sandbox_spi_get_emul(struct sandbox_state *state,
609 			 struct udevice *bus, struct udevice *slave,
610 			 struct udevice **emulp);
611 
612 /**
613  * Claim the bus and prepare it for communication with a given slave.
614  *
615  * This must be called before doing any transfers with a SPI slave. It
616  * will enable and initialize any SPI hardware as necessary, and make
617  * sure that the SCK line is in the correct idle state. It is not
618  * allowed to claim the same bus for several slaves without releasing
619  * the bus in between.
620  *
621  * @dev:	The SPI slave device
622  *
623  * Returns: 0 if the bus was claimed successfully, or a negative value
624  * if it wasn't.
625  */
626 int dm_spi_claim_bus(struct udevice *dev);
627 
628 /**
629  * Release the SPI bus
630  *
631  * This must be called once for every call to dm_spi_claim_bus() after
632  * all transfers have finished. It may disable any SPI hardware as
633  * appropriate.
634  *
635  * @slave:	The SPI slave device
636  */
637 void dm_spi_release_bus(struct udevice *dev);
638 
639 /**
640  * SPI transfer
641  *
642  * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
643  * "bitlen" bits in the SPI MISO port.  That's just the way SPI works.
644  *
645  * The source of the outgoing bits is the "dout" parameter and the
646  * destination of the input bits is the "din" parameter.  Note that "dout"
647  * and "din" can point to the same memory location, in which case the
648  * input data overwrites the output data (since both are buffered by
649  * temporary variables, this is OK).
650  *
651  * dm_spi_xfer() interface:
652  * @dev:	The SPI slave device which will be sending/receiving the data.
653  * @bitlen:	How many bits to write and read.
654  * @dout:	Pointer to a string of bits to send out.  The bits are
655  *		held in a byte array and are sent MSB first.
656  * @din:	Pointer to a string of bits that will be filled in.
657  * @flags:	A bitwise combination of SPI_XFER_* flags.
658  *
659  * Returns: 0 on success, not 0 on failure
660  */
661 int dm_spi_xfer(struct udevice *dev, unsigned int bitlen,
662 		const void *dout, void *din, unsigned long flags);
663 
664 /* Access the operations for a SPI device */
665 #define spi_get_ops(dev)	((struct dm_spi_ops *)(dev)->driver->ops)
666 #define spi_emul_get_ops(dev)	((struct dm_spi_emul_ops *)(dev)->driver->ops)
667 #endif /* CONFIG_DM_SPI */
668 
669 #endif	/* _SPI_H_ */
670