spi.h 20 KB

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