spi.h 20 KB

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