spi.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. /*
  2. * Copyright (C) 2005 David Brownell
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __LINUX_SPI_H
  15. #define __LINUX_SPI_H
  16. #include <linux/device.h>
  17. #include <linux/mod_devicetable.h>
  18. #include <linux/slab.h>
  19. #include <linux/kthread.h>
  20. #include <linux/completion.h>
  21. #include <linux/scatterlist.h>
  22. struct dma_chan;
  23. struct spi_master;
  24. struct spi_transfer;
  25. struct spi_flash_read_message;
  26. /*
  27. * INTERFACES between SPI master-side drivers and SPI infrastructure.
  28. * (There's no SPI slave support for Linux yet...)
  29. */
  30. extern struct bus_type spi_bus_type;
  31. /**
  32. * struct spi_statistics - statistics for spi transfers
  33. * @lock: lock protecting this structure
  34. *
  35. * @messages: number of spi-messages handled
  36. * @transfers: number of spi_transfers handled
  37. * @errors: number of errors during spi_transfer
  38. * @timedout: number of timeouts during spi_transfer
  39. *
  40. * @spi_sync: number of times spi_sync is used
  41. * @spi_sync_immediate:
  42. * number of times spi_sync is executed immediately
  43. * in calling context without queuing and scheduling
  44. * @spi_async: number of times spi_async is used
  45. *
  46. * @bytes: number of bytes transferred to/from device
  47. * @bytes_tx: number of bytes sent to device
  48. * @bytes_rx: number of bytes received from device
  49. *
  50. * @transfer_bytes_histo:
  51. * transfer bytes histogramm
  52. */
  53. struct spi_statistics {
  54. spinlock_t lock; /* lock for the whole structure */
  55. unsigned long messages;
  56. unsigned long transfers;
  57. unsigned long errors;
  58. unsigned long timedout;
  59. unsigned long spi_sync;
  60. unsigned long spi_sync_immediate;
  61. unsigned long spi_async;
  62. unsigned long long bytes;
  63. unsigned long long bytes_rx;
  64. unsigned long long bytes_tx;
  65. #define SPI_STATISTICS_HISTO_SIZE 17
  66. unsigned long transfer_bytes_histo[SPI_STATISTICS_HISTO_SIZE];
  67. };
  68. void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
  69. struct spi_transfer *xfer,
  70. struct spi_master *master);
  71. #define SPI_STATISTICS_ADD_TO_FIELD(stats, field, count) \
  72. do { \
  73. unsigned long flags; \
  74. spin_lock_irqsave(&(stats)->lock, flags); \
  75. (stats)->field += count; \
  76. spin_unlock_irqrestore(&(stats)->lock, flags); \
  77. } while (0)
  78. #define SPI_STATISTICS_INCREMENT_FIELD(stats, field) \
  79. SPI_STATISTICS_ADD_TO_FIELD(stats, field, 1)
  80. /**
  81. * struct spi_device - Master side proxy for an SPI slave device
  82. * @dev: Driver model representation of the device.
  83. * @master: SPI controller used with the device.
  84. * @max_speed_hz: Maximum clock rate to be used with this chip
  85. * (on this board); may be changed by the device's driver.
  86. * The spi_transfer.speed_hz can override this for each transfer.
  87. * @chip_select: Chipselect, distinguishing chips handled by @master.
  88. * @mode: The spi mode defines how data is clocked out and in.
  89. * This may be changed by the device's driver.
  90. * The "active low" default for chipselect mode can be overridden
  91. * (by specifying SPI_CS_HIGH) as can the "MSB first" default for
  92. * each word in a transfer (by specifying SPI_LSB_FIRST).
  93. * @bits_per_word: Data transfers involve one or more words; word sizes
  94. * like eight or 12 bits are common. In-memory wordsizes are
  95. * powers of two bytes (e.g. 20 bit samples use 32 bits).
  96. * This may be changed by the device's driver, or left at the
  97. * default (0) indicating protocol words are eight bit bytes.
  98. * The spi_transfer.bits_per_word can override this for each transfer.
  99. * @irq: Negative, or the number passed to request_irq() to receive
  100. * interrupts from this device.
  101. * @controller_state: Controller's runtime state
  102. * @controller_data: Board-specific definitions for controller, such as
  103. * FIFO initialization parameters; from board_info.controller_data
  104. * @modalias: Name of the driver to use with this device, or an alias
  105. * for that name. This appears in the sysfs "modalias" attribute
  106. * for driver coldplugging, and in uevents used for hotplugging
  107. * @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when
  108. * when not using a GPIO line)
  109. *
  110. * @statistics: statistics for the spi_device
  111. *
  112. * A @spi_device is used to interchange data between an SPI slave
  113. * (usually a discrete chip) and CPU memory.
  114. *
  115. * In @dev, the platform_data is used to hold information about this
  116. * device that's meaningful to the device's protocol driver, but not
  117. * to its controller. One example might be an identifier for a chip
  118. * variant with slightly different functionality; another might be
  119. * information about how this particular board wires the chip's pins.
  120. */
  121. struct spi_device {
  122. struct device dev;
  123. struct spi_master *master;
  124. u32 max_speed_hz;
  125. u8 chip_select;
  126. u8 bits_per_word;
  127. u16 mode;
  128. #define SPI_CPHA 0x01 /* clock phase */
  129. #define SPI_CPOL 0x02 /* clock polarity */
  130. #define SPI_MODE_0 (0|0) /* (original MicroWire) */
  131. #define SPI_MODE_1 (0|SPI_CPHA)
  132. #define SPI_MODE_2 (SPI_CPOL|0)
  133. #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
  134. #define SPI_CS_HIGH 0x04 /* chipselect active high? */
  135. #define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
  136. #define SPI_3WIRE 0x10 /* SI/SO signals shared */
  137. #define SPI_LOOP 0x20 /* loopback mode */
  138. #define SPI_NO_CS 0x40 /* 1 dev/bus, no chipselect */
  139. #define SPI_READY 0x80 /* slave pulls low to pause */
  140. #define SPI_TX_DUAL 0x100 /* transmit with 2 wires */
  141. #define SPI_TX_QUAD 0x200 /* transmit with 4 wires */
  142. #define SPI_RX_DUAL 0x400 /* receive with 2 wires */
  143. #define SPI_RX_QUAD 0x800 /* receive with 4 wires */
  144. int irq;
  145. void *controller_state;
  146. void *controller_data;
  147. char modalias[SPI_NAME_SIZE];
  148. int cs_gpio; /* chip select gpio */
  149. /* the statistics */
  150. struct spi_statistics statistics;
  151. /*
  152. * likely need more hooks for more protocol options affecting how
  153. * the controller talks to each chip, like:
  154. * - memory packing (12 bit samples into low bits, others zeroed)
  155. * - priority
  156. * - drop chipselect after each word
  157. * - chipselect delays
  158. * - ...
  159. */
  160. };
  161. static inline struct spi_device *to_spi_device(struct device *dev)
  162. {
  163. return dev ? container_of(dev, struct spi_device, dev) : NULL;
  164. }
  165. /* most drivers won't need to care about device refcounting */
  166. static inline struct spi_device *spi_dev_get(struct spi_device *spi)
  167. {
  168. return (spi && get_device(&spi->dev)) ? spi : NULL;
  169. }
  170. static inline void spi_dev_put(struct spi_device *spi)
  171. {
  172. if (spi)
  173. put_device(&spi->dev);
  174. }
  175. /* ctldata is for the bus_master driver's runtime state */
  176. static inline void *spi_get_ctldata(struct spi_device *spi)
  177. {
  178. return spi->controller_state;
  179. }
  180. static inline void spi_set_ctldata(struct spi_device *spi, void *state)
  181. {
  182. spi->controller_state = state;
  183. }
  184. /* device driver data */
  185. static inline void spi_set_drvdata(struct spi_device *spi, void *data)
  186. {
  187. dev_set_drvdata(&spi->dev, data);
  188. }
  189. static inline void *spi_get_drvdata(struct spi_device *spi)
  190. {
  191. return dev_get_drvdata(&spi->dev);
  192. }
  193. struct spi_message;
  194. struct spi_transfer;
  195. /**
  196. * struct spi_driver - Host side "protocol" driver
  197. * @id_table: List of SPI devices supported by this driver
  198. * @probe: Binds this driver to the spi device. Drivers can verify
  199. * that the device is actually present, and may need to configure
  200. * characteristics (such as bits_per_word) which weren't needed for
  201. * the initial configuration done during system setup.
  202. * @remove: Unbinds this driver from the spi device
  203. * @shutdown: Standard shutdown callback used during system state
  204. * transitions such as powerdown/halt and kexec
  205. * @driver: SPI device drivers should initialize the name and owner
  206. * field of this structure.
  207. *
  208. * This represents the kind of device driver that uses SPI messages to
  209. * interact with the hardware at the other end of a SPI link. It's called
  210. * a "protocol" driver because it works through messages rather than talking
  211. * directly to SPI hardware (which is what the underlying SPI controller
  212. * driver does to pass those messages). These protocols are defined in the
  213. * specification for the device(s) supported by the driver.
  214. *
  215. * As a rule, those device protocols represent the lowest level interface
  216. * supported by a driver, and it will support upper level interfaces too.
  217. * Examples of such upper levels include frameworks like MTD, networking,
  218. * MMC, RTC, filesystem character device nodes, and hardware monitoring.
  219. */
  220. struct spi_driver {
  221. const struct spi_device_id *id_table;
  222. int (*probe)(struct spi_device *spi);
  223. int (*remove)(struct spi_device *spi);
  224. void (*shutdown)(struct spi_device *spi);
  225. struct device_driver driver;
  226. };
  227. static inline struct spi_driver *to_spi_driver(struct device_driver *drv)
  228. {
  229. return drv ? container_of(drv, struct spi_driver, driver) : NULL;
  230. }
  231. extern int __spi_register_driver(struct module *owner, struct spi_driver *sdrv);
  232. /**
  233. * spi_unregister_driver - reverse effect of spi_register_driver
  234. * @sdrv: the driver to unregister
  235. * Context: can sleep
  236. */
  237. static inline void spi_unregister_driver(struct spi_driver *sdrv)
  238. {
  239. if (sdrv)
  240. driver_unregister(&sdrv->driver);
  241. }
  242. /* use a define to avoid include chaining to get THIS_MODULE */
  243. #define spi_register_driver(driver) \
  244. __spi_register_driver(THIS_MODULE, driver)
  245. /**
  246. * module_spi_driver() - Helper macro for registering a SPI driver
  247. * @__spi_driver: spi_driver struct
  248. *
  249. * Helper macro for SPI drivers which do not do anything special in module
  250. * init/exit. This eliminates a lot of boilerplate. Each module may only
  251. * use this macro once, and calling it replaces module_init() and module_exit()
  252. */
  253. #define module_spi_driver(__spi_driver) \
  254. module_driver(__spi_driver, spi_register_driver, \
  255. spi_unregister_driver)
  256. /**
  257. * struct spi_master - interface to SPI master controller
  258. * @dev: device interface to this driver
  259. * @list: link with the global spi_master list
  260. * @bus_num: board-specific (and often SOC-specific) identifier for a
  261. * given SPI controller.
  262. * @num_chipselect: chipselects are used to distinguish individual
  263. * SPI slaves, and are numbered from zero to num_chipselects.
  264. * each slave has a chipselect signal, but it's common that not
  265. * every chipselect is connected to a slave.
  266. * @dma_alignment: SPI controller constraint on DMA buffers alignment.
  267. * @mode_bits: flags understood by this controller driver
  268. * @bits_per_word_mask: A mask indicating which values of bits_per_word are
  269. * supported by the driver. Bit n indicates that a bits_per_word n+1 is
  270. * supported. If set, the SPI core will reject any transfer with an
  271. * unsupported bits_per_word. If not set, this value is simply ignored,
  272. * and it's up to the individual driver to perform any validation.
  273. * @min_speed_hz: Lowest supported transfer speed
  274. * @max_speed_hz: Highest supported transfer speed
  275. * @flags: other constraints relevant to this driver
  276. * @max_transfer_size: function that returns the max transfer size for
  277. * a &spi_device; may be %NULL, so the default %SIZE_MAX will be used.
  278. * @bus_lock_spinlock: spinlock for SPI bus locking
  279. * @bus_lock_mutex: mutex for SPI bus locking
  280. * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use
  281. * @setup: updates the device mode and clocking records used by a
  282. * device's SPI controller; protocol code may call this. This
  283. * must fail if an unrecognized or unsupported mode is requested.
  284. * It's always safe to call this unless transfers are pending on
  285. * the device whose settings are being modified.
  286. * @transfer: adds a message to the controller's transfer queue.
  287. * @cleanup: frees controller-specific state
  288. * @can_dma: determine whether this master supports DMA
  289. * @queued: whether this master is providing an internal message queue
  290. * @kworker: thread struct for message pump
  291. * @kworker_task: pointer to task for message pump kworker thread
  292. * @pump_messages: work struct for scheduling work to the message pump
  293. * @queue_lock: spinlock to syncronise access to message queue
  294. * @queue: message queue
  295. * @idling: the device is entering idle state
  296. * @cur_msg: the currently in-flight message
  297. * @cur_msg_prepared: spi_prepare_message was called for the currently
  298. * in-flight message
  299. * @cur_msg_mapped: message has been mapped for DMA
  300. * @xfer_completion: used by core transfer_one_message()
  301. * @busy: message pump is busy
  302. * @running: message pump is running
  303. * @rt: whether this queue is set to run as a realtime task
  304. * @auto_runtime_pm: the core should ensure a runtime PM reference is held
  305. * while the hardware is prepared, using the parent
  306. * device for the spidev
  307. * @max_dma_len: Maximum length of a DMA transfer for the device.
  308. * @prepare_transfer_hardware: a message will soon arrive from the queue
  309. * so the subsystem requests the driver to prepare the transfer hardware
  310. * by issuing this call
  311. * @transfer_one_message: the subsystem calls the driver to transfer a single
  312. * message while queuing transfers that arrive in the meantime. When the
  313. * driver is finished with this message, it must call
  314. * spi_finalize_current_message() so the subsystem can issue the next
  315. * message
  316. * @unprepare_transfer_hardware: there are currently no more messages on the
  317. * queue so the subsystem notifies the driver that it may relax the
  318. * hardware by issuing this call
  319. * @set_cs: set the logic level of the chip select line. May be called
  320. * from interrupt context.
  321. * @prepare_message: set up the controller to transfer a single message,
  322. * for example doing DMA mapping. Called from threaded
  323. * context.
  324. * @transfer_one: transfer a single spi_transfer.
  325. * - return 0 if the transfer is finished,
  326. * - return 1 if the transfer is still in progress. When
  327. * the driver is finished with this transfer it must
  328. * call spi_finalize_current_transfer() so the subsystem
  329. * can issue the next transfer. Note: transfer_one and
  330. * transfer_one_message are mutually exclusive; when both
  331. * are set, the generic subsystem does not call your
  332. * transfer_one callback.
  333. * @handle_err: the subsystem calls the driver to handle an error that occurs
  334. * in the generic implementation of transfer_one_message().
  335. * @unprepare_message: undo any work done by prepare_message().
  336. * @spi_flash_read: to support spi-controller hardwares that provide
  337. * accelerated interface to read from flash devices.
  338. * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
  339. * number. Any individual value may be -ENOENT for CS lines that
  340. * are not GPIOs (driven by the SPI controller itself).
  341. * @statistics: statistics for the spi_master
  342. * @dma_tx: DMA transmit channel
  343. * @dma_rx: DMA receive channel
  344. * @dummy_rx: dummy receive buffer for full-duplex devices
  345. * @dummy_tx: dummy transmit buffer for full-duplex devices
  346. * @fw_translate_cs: If the boot firmware uses different numbering scheme
  347. * what Linux expects, this optional hook can be used to translate
  348. * between the two.
  349. *
  350. * Each SPI master controller can communicate with one or more @spi_device
  351. * children. These make a small bus, sharing MOSI, MISO and SCK signals
  352. * but not chip select signals. Each device may be configured to use a
  353. * different clock rate, since those shared signals are ignored unless
  354. * the chip is selected.
  355. *
  356. * The driver for an SPI controller manages access to those devices through
  357. * a queue of spi_message transactions, copying data between CPU memory and
  358. * an SPI slave device. For each such message it queues, it calls the
  359. * message's completion function when the transaction completes.
  360. */
  361. struct spi_master {
  362. struct device dev;
  363. struct list_head list;
  364. /* other than negative (== assign one dynamically), bus_num is fully
  365. * board-specific. usually that simplifies to being SOC-specific.
  366. * example: one SOC has three SPI controllers, numbered 0..2,
  367. * and one board's schematics might show it using SPI-2. software
  368. * would normally use bus_num=2 for that controller.
  369. */
  370. s16 bus_num;
  371. /* chipselects will be integral to many controllers; some others
  372. * might use board-specific GPIOs.
  373. */
  374. u16 num_chipselect;
  375. /* some SPI controllers pose alignment requirements on DMAable
  376. * buffers; let protocol drivers know about these requirements.
  377. */
  378. u16 dma_alignment;
  379. /* spi_device.mode flags understood by this controller driver */
  380. u16 mode_bits;
  381. /* bitmask of supported bits_per_word for transfers */
  382. u32 bits_per_word_mask;
  383. #define SPI_BPW_MASK(bits) BIT((bits) - 1)
  384. #define SPI_BIT_MASK(bits) (((bits) == 32) ? ~0U : (BIT(bits) - 1))
  385. #define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - SPI_BIT_MASK(min - 1))
  386. /* limits on transfer speed */
  387. u32 min_speed_hz;
  388. u32 max_speed_hz;
  389. /* other constraints relevant to this driver */
  390. u16 flags;
  391. #define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */
  392. #define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */
  393. #define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */
  394. #define SPI_MASTER_MUST_RX BIT(3) /* requires rx */
  395. #define SPI_MASTER_MUST_TX BIT(4) /* requires tx */
  396. /*
  397. * on some hardware transfer size may be constrained
  398. * the limit may depend on device transfer settings
  399. */
  400. size_t (*max_transfer_size)(struct spi_device *spi);
  401. /* lock and mutex for SPI bus locking */
  402. spinlock_t bus_lock_spinlock;
  403. struct mutex bus_lock_mutex;
  404. /* flag indicating that the SPI bus is locked for exclusive use */
  405. bool bus_lock_flag;
  406. /* Setup mode and clock, etc (spi driver may call many times).
  407. *
  408. * IMPORTANT: this may be called when transfers to another
  409. * device are active. DO NOT UPDATE SHARED REGISTERS in ways
  410. * which could break those transfers.
  411. */
  412. int (*setup)(struct spi_device *spi);
  413. /* bidirectional bulk transfers
  414. *
  415. * + The transfer() method may not sleep; its main role is
  416. * just to add the message to the queue.
  417. * + For now there's no remove-from-queue operation, or
  418. * any other request management
  419. * + To a given spi_device, message queueing is pure fifo
  420. *
  421. * + The master's main job is to process its message queue,
  422. * selecting a chip then transferring data
  423. * + If there are multiple spi_device children, the i/o queue
  424. * arbitration algorithm is unspecified (round robin, fifo,
  425. * priority, reservations, preemption, etc)
  426. *
  427. * + Chipselect stays active during the entire message
  428. * (unless modified by spi_transfer.cs_change != 0).
  429. * + The message transfers use clock and SPI mode parameters
  430. * previously established by setup() for this device
  431. */
  432. int (*transfer)(struct spi_device *spi,
  433. struct spi_message *mesg);
  434. /* called on release() to free memory provided by spi_master */
  435. void (*cleanup)(struct spi_device *spi);
  436. /*
  437. * Used to enable core support for DMA handling, if can_dma()
  438. * exists and returns true then the transfer will be mapped
  439. * prior to transfer_one() being called. The driver should
  440. * not modify or store xfer and dma_tx and dma_rx must be set
  441. * while the device is prepared.
  442. */
  443. bool (*can_dma)(struct spi_master *master,
  444. struct spi_device *spi,
  445. struct spi_transfer *xfer);
  446. /*
  447. * These hooks are for drivers that want to use the generic
  448. * master transfer queueing mechanism. If these are used, the
  449. * transfer() function above must NOT be specified by the driver.
  450. * Over time we expect SPI drivers to be phased over to this API.
  451. */
  452. bool queued;
  453. struct kthread_worker kworker;
  454. struct task_struct *kworker_task;
  455. struct kthread_work pump_messages;
  456. spinlock_t queue_lock;
  457. struct list_head queue;
  458. struct spi_message *cur_msg;
  459. bool idling;
  460. bool busy;
  461. bool running;
  462. bool rt;
  463. bool auto_runtime_pm;
  464. bool cur_msg_prepared;
  465. bool cur_msg_mapped;
  466. struct completion xfer_completion;
  467. size_t max_dma_len;
  468. int (*prepare_transfer_hardware)(struct spi_master *master);
  469. int (*transfer_one_message)(struct spi_master *master,
  470. struct spi_message *mesg);
  471. int (*unprepare_transfer_hardware)(struct spi_master *master);
  472. int (*prepare_message)(struct spi_master *master,
  473. struct spi_message *message);
  474. int (*unprepare_message)(struct spi_master *master,
  475. struct spi_message *message);
  476. int (*spi_flash_read)(struct spi_device *spi,
  477. struct spi_flash_read_message *msg);
  478. /*
  479. * These hooks are for drivers that use a generic implementation
  480. * of transfer_one_message() provied by the core.
  481. */
  482. void (*set_cs)(struct spi_device *spi, bool enable);
  483. int (*transfer_one)(struct spi_master *master, struct spi_device *spi,
  484. struct spi_transfer *transfer);
  485. void (*handle_err)(struct spi_master *master,
  486. struct spi_message *message);
  487. /* gpio chip select */
  488. int *cs_gpios;
  489. /* statistics */
  490. struct spi_statistics statistics;
  491. /* DMA channels for use with core dmaengine helpers */
  492. struct dma_chan *dma_tx;
  493. struct dma_chan *dma_rx;
  494. /* dummy data for full duplex devices */
  495. void *dummy_rx;
  496. void *dummy_tx;
  497. int (*fw_translate_cs)(struct spi_master *master, unsigned cs);
  498. };
  499. static inline void *spi_master_get_devdata(struct spi_master *master)
  500. {
  501. return dev_get_drvdata(&master->dev);
  502. }
  503. static inline void spi_master_set_devdata(struct spi_master *master, void *data)
  504. {
  505. dev_set_drvdata(&master->dev, data);
  506. }
  507. static inline struct spi_master *spi_master_get(struct spi_master *master)
  508. {
  509. if (!master || !get_device(&master->dev))
  510. return NULL;
  511. return master;
  512. }
  513. static inline void spi_master_put(struct spi_master *master)
  514. {
  515. if (master)
  516. put_device(&master->dev);
  517. }
  518. /* PM calls that need to be issued by the driver */
  519. extern int spi_master_suspend(struct spi_master *master);
  520. extern int spi_master_resume(struct spi_master *master);
  521. /* Calls the driver make to interact with the message queue */
  522. extern struct spi_message *spi_get_next_queued_message(struct spi_master *master);
  523. extern void spi_finalize_current_message(struct spi_master *master);
  524. extern void spi_finalize_current_transfer(struct spi_master *master);
  525. /* the spi driver core manages memory for the spi_master classdev */
  526. extern struct spi_master *
  527. spi_alloc_master(struct device *host, unsigned size);
  528. extern int spi_register_master(struct spi_master *master);
  529. extern int devm_spi_register_master(struct device *dev,
  530. struct spi_master *master);
  531. extern void spi_unregister_master(struct spi_master *master);
  532. extern struct spi_master *spi_busnum_to_master(u16 busnum);
  533. /*---------------------------------------------------------------------------*/
  534. /*
  535. * I/O INTERFACE between SPI controller and protocol drivers
  536. *
  537. * Protocol drivers use a queue of spi_messages, each transferring data
  538. * between the controller and memory buffers.
  539. *
  540. * The spi_messages themselves consist of a series of read+write transfer
  541. * segments. Those segments always read the same number of bits as they
  542. * write; but one or the other is easily ignored by passing a null buffer
  543. * pointer. (This is unlike most types of I/O API, because SPI hardware
  544. * is full duplex.)
  545. *
  546. * NOTE: Allocation of spi_transfer and spi_message memory is entirely
  547. * up to the protocol driver, which guarantees the integrity of both (as
  548. * well as the data buffers) for as long as the message is queued.
  549. */
  550. /**
  551. * struct spi_transfer - a read/write buffer pair
  552. * @tx_buf: data to be written (dma-safe memory), or NULL
  553. * @rx_buf: data to be read (dma-safe memory), or NULL
  554. * @tx_dma: DMA address of tx_buf, if @spi_message.is_dma_mapped
  555. * @rx_dma: DMA address of rx_buf, if @spi_message.is_dma_mapped
  556. * @tx_nbits: number of bits used for writing. If 0 the default
  557. * (SPI_NBITS_SINGLE) is used.
  558. * @rx_nbits: number of bits used for reading. If 0 the default
  559. * (SPI_NBITS_SINGLE) is used.
  560. * @len: size of rx and tx buffers (in bytes)
  561. * @speed_hz: Select a speed other than the device default for this
  562. * transfer. If 0 the default (from @spi_device) is used.
  563. * @bits_per_word: select a bits_per_word other than the device default
  564. * for this transfer. If 0 the default (from @spi_device) is used.
  565. * @cs_change: affects chipselect after this transfer completes
  566. * @delay_usecs: microseconds to delay after this transfer before
  567. * (optionally) changing the chipselect status, then starting
  568. * the next transfer or completing this @spi_message.
  569. * @transfer_list: transfers are sequenced through @spi_message.transfers
  570. * @tx_sg: Scatterlist for transmit, currently not for client use
  571. * @rx_sg: Scatterlist for receive, currently not for client use
  572. *
  573. * SPI transfers always write the same number of bytes as they read.
  574. * Protocol drivers should always provide @rx_buf and/or @tx_buf.
  575. * In some cases, they may also want to provide DMA addresses for
  576. * the data being transferred; that may reduce overhead, when the
  577. * underlying driver uses dma.
  578. *
  579. * If the transmit buffer is null, zeroes will be shifted out
  580. * while filling @rx_buf. If the receive buffer is null, the data
  581. * shifted in will be discarded. Only "len" bytes shift out (or in).
  582. * It's an error to try to shift out a partial word. (For example, by
  583. * shifting out three bytes with word size of sixteen or twenty bits;
  584. * the former uses two bytes per word, the latter uses four bytes.)
  585. *
  586. * In-memory data values are always in native CPU byte order, translated
  587. * from the wire byte order (big-endian except with SPI_LSB_FIRST). So
  588. * for example when bits_per_word is sixteen, buffers are 2N bytes long
  589. * (@len = 2N) and hold N sixteen bit words in CPU byte order.
  590. *
  591. * When the word size of the SPI transfer is not a power-of-two multiple
  592. * of eight bits, those in-memory words include extra bits. In-memory
  593. * words are always seen by protocol drivers as right-justified, so the
  594. * undefined (rx) or unused (tx) bits are always the most significant bits.
  595. *
  596. * All SPI transfers start with the relevant chipselect active. Normally
  597. * it stays selected until after the last transfer in a message. Drivers
  598. * can affect the chipselect signal using cs_change.
  599. *
  600. * (i) If the transfer isn't the last one in the message, this flag is
  601. * used to make the chipselect briefly go inactive in the middle of the
  602. * message. Toggling chipselect in this way may be needed to terminate
  603. * a chip command, letting a single spi_message perform all of group of
  604. * chip transactions together.
  605. *
  606. * (ii) When the transfer is the last one in the message, the chip may
  607. * stay selected until the next transfer. On multi-device SPI busses
  608. * with nothing blocking messages going to other devices, this is just
  609. * a performance hint; starting a message to another device deselects
  610. * this one. But in other cases, this can be used to ensure correctness.
  611. * Some devices need protocol transactions to be built from a series of
  612. * spi_message submissions, where the content of one message is determined
  613. * by the results of previous messages and where the whole transaction
  614. * ends when the chipselect goes intactive.
  615. *
  616. * When SPI can transfer in 1x,2x or 4x. It can get this transfer information
  617. * from device through @tx_nbits and @rx_nbits. In Bi-direction, these
  618. * two should both be set. User can set transfer mode with SPI_NBITS_SINGLE(1x)
  619. * SPI_NBITS_DUAL(2x) and SPI_NBITS_QUAD(4x) to support these three transfer.
  620. *
  621. * The code that submits an spi_message (and its spi_transfers)
  622. * to the lower layers is responsible for managing its memory.
  623. * Zero-initialize every field you don't set up explicitly, to
  624. * insulate against future API updates. After you submit a message
  625. * and its transfers, ignore them until its completion callback.
  626. */
  627. struct spi_transfer {
  628. /* it's ok if tx_buf == rx_buf (right?)
  629. * for MicroWire, one buffer must be null
  630. * buffers must work with dma_*map_single() calls, unless
  631. * spi_message.is_dma_mapped reports a pre-existing mapping
  632. */
  633. const void *tx_buf;
  634. void *rx_buf;
  635. unsigned len;
  636. dma_addr_t tx_dma;
  637. dma_addr_t rx_dma;
  638. struct sg_table tx_sg;
  639. struct sg_table rx_sg;
  640. unsigned cs_change:1;
  641. unsigned tx_nbits:3;
  642. unsigned rx_nbits:3;
  643. #define SPI_NBITS_SINGLE 0x01 /* 1bit transfer */
  644. #define SPI_NBITS_DUAL 0x02 /* 2bits transfer */
  645. #define SPI_NBITS_QUAD 0x04 /* 4bits transfer */
  646. u8 bits_per_word;
  647. u16 delay_usecs;
  648. u32 speed_hz;
  649. struct list_head transfer_list;
  650. };
  651. /**
  652. * struct spi_message - one multi-segment SPI transaction
  653. * @transfers: list of transfer segments in this transaction
  654. * @spi: SPI device to which the transaction is queued
  655. * @is_dma_mapped: if true, the caller provided both dma and cpu virtual
  656. * addresses for each transfer buffer
  657. * @complete: called to report transaction completions
  658. * @context: the argument to complete() when it's called
  659. * @frame_length: the total number of bytes in the message
  660. * @actual_length: the total number of bytes that were transferred in all
  661. * successful segments
  662. * @status: zero for success, else negative errno
  663. * @queue: for use by whichever driver currently owns the message
  664. * @state: for use by whichever driver currently owns the message
  665. *
  666. * A @spi_message is used to execute an atomic sequence of data transfers,
  667. * each represented by a struct spi_transfer. The sequence is "atomic"
  668. * in the sense that no other spi_message may use that SPI bus until that
  669. * sequence completes. On some systems, many such sequences can execute as
  670. * as single programmed DMA transfer. On all systems, these messages are
  671. * queued, and might complete after transactions to other devices. Messages
  672. * sent to a given spi_device are always executed in FIFO order.
  673. *
  674. * The code that submits an spi_message (and its spi_transfers)
  675. * to the lower layers is responsible for managing its memory.
  676. * Zero-initialize every field you don't set up explicitly, to
  677. * insulate against future API updates. After you submit a message
  678. * and its transfers, ignore them until its completion callback.
  679. */
  680. struct spi_message {
  681. struct list_head transfers;
  682. struct spi_device *spi;
  683. unsigned is_dma_mapped:1;
  684. /* REVISIT: we might want a flag affecting the behavior of the
  685. * last transfer ... allowing things like "read 16 bit length L"
  686. * immediately followed by "read L bytes". Basically imposing
  687. * a specific message scheduling algorithm.
  688. *
  689. * Some controller drivers (message-at-a-time queue processing)
  690. * could provide that as their default scheduling algorithm. But
  691. * others (with multi-message pipelines) could need a flag to
  692. * tell them about such special cases.
  693. */
  694. /* completion is reported through a callback */
  695. void (*complete)(void *context);
  696. void *context;
  697. unsigned frame_length;
  698. unsigned actual_length;
  699. int status;
  700. /* for optional use by whatever driver currently owns the
  701. * spi_message ... between calls to spi_async and then later
  702. * complete(), that's the spi_master controller driver.
  703. */
  704. struct list_head queue;
  705. void *state;
  706. };
  707. static inline void spi_message_init_no_memset(struct spi_message *m)
  708. {
  709. INIT_LIST_HEAD(&m->transfers);
  710. }
  711. static inline void spi_message_init(struct spi_message *m)
  712. {
  713. memset(m, 0, sizeof *m);
  714. spi_message_init_no_memset(m);
  715. }
  716. static inline void
  717. spi_message_add_tail(struct spi_transfer *t, struct spi_message *m)
  718. {
  719. list_add_tail(&t->transfer_list, &m->transfers);
  720. }
  721. static inline void
  722. spi_transfer_del(struct spi_transfer *t)
  723. {
  724. list_del(&t->transfer_list);
  725. }
  726. /**
  727. * spi_message_init_with_transfers - Initialize spi_message and append transfers
  728. * @m: spi_message to be initialized
  729. * @xfers: An array of spi transfers
  730. * @num_xfers: Number of items in the xfer array
  731. *
  732. * This function initializes the given spi_message and adds each spi_transfer in
  733. * the given array to the message.
  734. */
  735. static inline void
  736. spi_message_init_with_transfers(struct spi_message *m,
  737. struct spi_transfer *xfers, unsigned int num_xfers)
  738. {
  739. unsigned int i;
  740. spi_message_init(m);
  741. for (i = 0; i < num_xfers; ++i)
  742. spi_message_add_tail(&xfers[i], m);
  743. }
  744. /* It's fine to embed message and transaction structures in other data
  745. * structures so long as you don't free them while they're in use.
  746. */
  747. static inline struct spi_message *spi_message_alloc(unsigned ntrans, gfp_t flags)
  748. {
  749. struct spi_message *m;
  750. m = kzalloc(sizeof(struct spi_message)
  751. + ntrans * sizeof(struct spi_transfer),
  752. flags);
  753. if (m) {
  754. unsigned i;
  755. struct spi_transfer *t = (struct spi_transfer *)(m + 1);
  756. INIT_LIST_HEAD(&m->transfers);
  757. for (i = 0; i < ntrans; i++, t++)
  758. spi_message_add_tail(t, m);
  759. }
  760. return m;
  761. }
  762. static inline void spi_message_free(struct spi_message *m)
  763. {
  764. kfree(m);
  765. }
  766. extern int spi_setup(struct spi_device *spi);
  767. extern int spi_async(struct spi_device *spi, struct spi_message *message);
  768. extern int spi_async_locked(struct spi_device *spi,
  769. struct spi_message *message);
  770. static inline size_t
  771. spi_max_transfer_size(struct spi_device *spi)
  772. {
  773. struct spi_master *master = spi->master;
  774. if (!master->max_transfer_size)
  775. return SIZE_MAX;
  776. return master->max_transfer_size(spi);
  777. }
  778. /*---------------------------------------------------------------------------*/
  779. /* All these synchronous SPI transfer routines are utilities layered
  780. * over the core async transfer primitive. Here, "synchronous" means
  781. * they will sleep uninterruptibly until the async transfer completes.
  782. */
  783. extern int spi_sync(struct spi_device *spi, struct spi_message *message);
  784. extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message);
  785. extern int spi_bus_lock(struct spi_master *master);
  786. extern int spi_bus_unlock(struct spi_master *master);
  787. /**
  788. * spi_write - SPI synchronous write
  789. * @spi: device to which data will be written
  790. * @buf: data buffer
  791. * @len: data buffer size
  792. * Context: can sleep
  793. *
  794. * This function writes the buffer @buf.
  795. * Callable only from contexts that can sleep.
  796. *
  797. * Return: zero on success, else a negative error code.
  798. */
  799. static inline int
  800. spi_write(struct spi_device *spi, const void *buf, size_t len)
  801. {
  802. struct spi_transfer t = {
  803. .tx_buf = buf,
  804. .len = len,
  805. };
  806. struct spi_message m;
  807. spi_message_init(&m);
  808. spi_message_add_tail(&t, &m);
  809. return spi_sync(spi, &m);
  810. }
  811. /**
  812. * spi_read - SPI synchronous read
  813. * @spi: device from which data will be read
  814. * @buf: data buffer
  815. * @len: data buffer size
  816. * Context: can sleep
  817. *
  818. * This function reads the buffer @buf.
  819. * Callable only from contexts that can sleep.
  820. *
  821. * Return: zero on success, else a negative error code.
  822. */
  823. static inline int
  824. spi_read(struct spi_device *spi, void *buf, size_t len)
  825. {
  826. struct spi_transfer t = {
  827. .rx_buf = buf,
  828. .len = len,
  829. };
  830. struct spi_message m;
  831. spi_message_init(&m);
  832. spi_message_add_tail(&t, &m);
  833. return spi_sync(spi, &m);
  834. }
  835. /**
  836. * spi_sync_transfer - synchronous SPI data transfer
  837. * @spi: device with which data will be exchanged
  838. * @xfers: An array of spi_transfers
  839. * @num_xfers: Number of items in the xfer array
  840. * Context: can sleep
  841. *
  842. * Does a synchronous SPI data transfer of the given spi_transfer array.
  843. *
  844. * For more specific semantics see spi_sync().
  845. *
  846. * Return: Return: zero on success, else a negative error code.
  847. */
  848. static inline int
  849. spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers,
  850. unsigned int num_xfers)
  851. {
  852. struct spi_message msg;
  853. spi_message_init_with_transfers(&msg, xfers, num_xfers);
  854. return spi_sync(spi, &msg);
  855. }
  856. /* this copies txbuf and rxbuf data; for small transfers only! */
  857. extern int spi_write_then_read(struct spi_device *spi,
  858. const void *txbuf, unsigned n_tx,
  859. void *rxbuf, unsigned n_rx);
  860. /**
  861. * spi_w8r8 - SPI synchronous 8 bit write followed by 8 bit read
  862. * @spi: device with which data will be exchanged
  863. * @cmd: command to be written before data is read back
  864. * Context: can sleep
  865. *
  866. * Callable only from contexts that can sleep.
  867. *
  868. * Return: the (unsigned) eight bit number returned by the
  869. * device, or else a negative error code.
  870. */
  871. static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
  872. {
  873. ssize_t status;
  874. u8 result;
  875. status = spi_write_then_read(spi, &cmd, 1, &result, 1);
  876. /* return negative errno or unsigned value */
  877. return (status < 0) ? status : result;
  878. }
  879. /**
  880. * spi_w8r16 - SPI synchronous 8 bit write followed by 16 bit read
  881. * @spi: device with which data will be exchanged
  882. * @cmd: command to be written before data is read back
  883. * Context: can sleep
  884. *
  885. * The number is returned in wire-order, which is at least sometimes
  886. * big-endian.
  887. *
  888. * Callable only from contexts that can sleep.
  889. *
  890. * Return: the (unsigned) sixteen bit number returned by the
  891. * device, or else a negative error code.
  892. */
  893. static inline ssize_t spi_w8r16(struct spi_device *spi, u8 cmd)
  894. {
  895. ssize_t status;
  896. u16 result;
  897. status = spi_write_then_read(spi, &cmd, 1, &result, 2);
  898. /* return negative errno or unsigned value */
  899. return (status < 0) ? status : result;
  900. }
  901. /**
  902. * spi_w8r16be - SPI synchronous 8 bit write followed by 16 bit big-endian read
  903. * @spi: device with which data will be exchanged
  904. * @cmd: command to be written before data is read back
  905. * Context: can sleep
  906. *
  907. * This function is similar to spi_w8r16, with the exception that it will
  908. * convert the read 16 bit data word from big-endian to native endianness.
  909. *
  910. * Callable only from contexts that can sleep.
  911. *
  912. * Return: the (unsigned) sixteen bit number returned by the device in cpu
  913. * endianness, or else a negative error code.
  914. */
  915. static inline ssize_t spi_w8r16be(struct spi_device *spi, u8 cmd)
  916. {
  917. ssize_t status;
  918. __be16 result;
  919. status = spi_write_then_read(spi, &cmd, 1, &result, 2);
  920. if (status < 0)
  921. return status;
  922. return be16_to_cpu(result);
  923. }
  924. /**
  925. * struct spi_flash_read_message - flash specific information for
  926. * spi-masters that provide accelerated flash read interfaces
  927. * @buf: buffer to read data
  928. * @from: offset within the flash from where data is to be read
  929. * @len: length of data to be read
  930. * @retlen: actual length of data read
  931. * @read_opcode: read_opcode to be used to communicate with flash
  932. * @addr_width: number of address bytes
  933. * @dummy_bytes: number of dummy bytes
  934. * @opcode_nbits: number of lines to send opcode
  935. * @addr_nbits: number of lines to send address
  936. * @data_nbits: number of lines for data
  937. */
  938. struct spi_flash_read_message {
  939. void *buf;
  940. loff_t from;
  941. size_t len;
  942. size_t retlen;
  943. u8 read_opcode;
  944. u8 addr_width;
  945. u8 dummy_bytes;
  946. u8 opcode_nbits;
  947. u8 addr_nbits;
  948. u8 data_nbits;
  949. };
  950. /* SPI core interface for flash read support */
  951. static inline bool spi_flash_read_supported(struct spi_device *spi)
  952. {
  953. return spi->master->spi_flash_read ? true : false;
  954. }
  955. int spi_flash_read(struct spi_device *spi,
  956. struct spi_flash_read_message *msg);
  957. /*---------------------------------------------------------------------------*/
  958. /*
  959. * INTERFACE between board init code and SPI infrastructure.
  960. *
  961. * No SPI driver ever sees these SPI device table segments, but
  962. * it's how the SPI core (or adapters that get hotplugged) grows
  963. * the driver model tree.
  964. *
  965. * As a rule, SPI devices can't be probed. Instead, board init code
  966. * provides a table listing the devices which are present, with enough
  967. * information to bind and set up the device's driver. There's basic
  968. * support for nonstatic configurations too; enough to handle adding
  969. * parport adapters, or microcontrollers acting as USB-to-SPI bridges.
  970. */
  971. /**
  972. * struct spi_board_info - board-specific template for a SPI device
  973. * @modalias: Initializes spi_device.modalias; identifies the driver.
  974. * @platform_data: Initializes spi_device.platform_data; the particular
  975. * data stored there is driver-specific.
  976. * @controller_data: Initializes spi_device.controller_data; some
  977. * controllers need hints about hardware setup, e.g. for DMA.
  978. * @irq: Initializes spi_device.irq; depends on how the board is wired.
  979. * @max_speed_hz: Initializes spi_device.max_speed_hz; based on limits
  980. * from the chip datasheet and board-specific signal quality issues.
  981. * @bus_num: Identifies which spi_master parents the spi_device; unused
  982. * by spi_new_device(), and otherwise depends on board wiring.
  983. * @chip_select: Initializes spi_device.chip_select; depends on how
  984. * the board is wired.
  985. * @mode: Initializes spi_device.mode; based on the chip datasheet, board
  986. * wiring (some devices support both 3WIRE and standard modes), and
  987. * possibly presence of an inverter in the chipselect path.
  988. *
  989. * When adding new SPI devices to the device tree, these structures serve
  990. * as a partial device template. They hold information which can't always
  991. * be determined by drivers. Information that probe() can establish (such
  992. * as the default transfer wordsize) is not included here.
  993. *
  994. * These structures are used in two places. Their primary role is to
  995. * be stored in tables of board-specific device descriptors, which are
  996. * declared early in board initialization and then used (much later) to
  997. * populate a controller's device tree after the that controller's driver
  998. * initializes. A secondary (and atypical) role is as a parameter to
  999. * spi_new_device() call, which happens after those controller drivers
  1000. * are active in some dynamic board configuration models.
  1001. */
  1002. struct spi_board_info {
  1003. /* the device name and module name are coupled, like platform_bus;
  1004. * "modalias" is normally the driver name.
  1005. *
  1006. * platform_data goes to spi_device.dev.platform_data,
  1007. * controller_data goes to spi_device.controller_data,
  1008. * irq is copied too
  1009. */
  1010. char modalias[SPI_NAME_SIZE];
  1011. const void *platform_data;
  1012. void *controller_data;
  1013. int irq;
  1014. /* slower signaling on noisy or low voltage boards */
  1015. u32 max_speed_hz;
  1016. /* bus_num is board specific and matches the bus_num of some
  1017. * spi_master that will probably be registered later.
  1018. *
  1019. * chip_select reflects how this chip is wired to that master;
  1020. * it's less than num_chipselect.
  1021. */
  1022. u16 bus_num;
  1023. u16 chip_select;
  1024. /* mode becomes spi_device.mode, and is essential for chips
  1025. * where the default of SPI_CS_HIGH = 0 is wrong.
  1026. */
  1027. u16 mode;
  1028. /* ... may need additional spi_device chip config data here.
  1029. * avoid stuff protocol drivers can set; but include stuff
  1030. * needed to behave without being bound to a driver:
  1031. * - quirks like clock rate mattering when not selected
  1032. */
  1033. };
  1034. #ifdef CONFIG_SPI
  1035. extern int
  1036. spi_register_board_info(struct spi_board_info const *info, unsigned n);
  1037. #else
  1038. /* board init code may ignore whether SPI is configured or not */
  1039. static inline int
  1040. spi_register_board_info(struct spi_board_info const *info, unsigned n)
  1041. { return 0; }
  1042. #endif
  1043. /* If you're hotplugging an adapter with devices (parport, usb, etc)
  1044. * use spi_new_device() to describe each device. You can also call
  1045. * spi_unregister_device() to start making that device vanish, but
  1046. * normally that would be handled by spi_unregister_master().
  1047. *
  1048. * You can also use spi_alloc_device() and spi_add_device() to use a two
  1049. * stage registration sequence for each spi_device. This gives the caller
  1050. * some more control over the spi_device structure before it is registered,
  1051. * but requires that caller to initialize fields that would otherwise
  1052. * be defined using the board info.
  1053. */
  1054. extern struct spi_device *
  1055. spi_alloc_device(struct spi_master *master);
  1056. extern int
  1057. spi_add_device(struct spi_device *spi);
  1058. extern struct spi_device *
  1059. spi_new_device(struct spi_master *, struct spi_board_info *);
  1060. extern void spi_unregister_device(struct spi_device *spi);
  1061. extern const struct spi_device_id *
  1062. spi_get_device_id(const struct spi_device *sdev);
  1063. static inline bool
  1064. spi_transfer_is_last(struct spi_master *master, struct spi_transfer *xfer)
  1065. {
  1066. return list_is_last(&xfer->transfer_list, &master->cur_msg->transfers);
  1067. }
  1068. #endif /* __LINUX_SPI_H */