spi.h 20 KB

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