spi.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef __LINUX_SPI_H
  19. #define __LINUX_SPI_H
  20. /*
  21. * INTERFACES between SPI master-side drivers and SPI infrastructure.
  22. * (There's no SPI slave support for Linux yet...)
  23. */
  24. extern struct bus_type spi_bus_type;
  25. /**
  26. * struct spi_device - Master side proxy for an SPI slave device
  27. * @dev: Driver model representation of the device.
  28. * @master: SPI controller used with the device.
  29. * @max_speed_hz: Maximum clock rate to be used with this chip
  30. * (on this board); may be changed by the device's driver.
  31. * The spi_transfer.speed_hz can override this for each transfer.
  32. * @chip-select: Chipselect, distinguishing chips handled by "master".
  33. * @mode: The spi mode defines how data is clocked out and in.
  34. * This may be changed by the device's driver.
  35. * The "active low" default for chipselect mode can be overridden,
  36. * as can the "MSB first" default for each word in a transfer.
  37. * @bits_per_word: Data transfers involve one or more words; word sizes
  38. * like eight or 12 bits are common. In-memory wordsizes are
  39. * powers of two bytes (e.g. 20 bit samples use 32 bits).
  40. * This may be changed by the device's driver, or left at the
  41. * default (0) indicating protocol words are eight bit bytes.
  42. * The spi_transfer.bits_per_word can override this for each transfer.
  43. * @irq: Negative, or the number passed to request_irq() to receive
  44. * interrupts from this device.
  45. * @controller_state: Controller's runtime state
  46. * @controller_data: Board-specific definitions for controller, such as
  47. * FIFO initialization parameters; from board_info.controller_data
  48. *
  49. * An spi_device is used to interchange data between an SPI slave
  50. * (usually a discrete chip) and CPU memory.
  51. *
  52. * In "dev", the platform_data is used to hold information about this
  53. * device that's meaningful to the device's protocol driver, but not
  54. * to its controller. One example might be an identifier for a chip
  55. * variant with slightly different functionality.
  56. */
  57. struct spi_device {
  58. struct device dev;
  59. struct spi_master *master;
  60. u32 max_speed_hz;
  61. u8 chip_select;
  62. u8 mode;
  63. #define SPI_CPHA 0x01 /* clock phase */
  64. #define SPI_CPOL 0x02 /* clock polarity */
  65. #define SPI_MODE_0 (0|0) /* (original MicroWire) */
  66. #define SPI_MODE_1 (0|SPI_CPHA)
  67. #define SPI_MODE_2 (SPI_CPOL|0)
  68. #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
  69. #define SPI_CS_HIGH 0x04 /* chipselect active high? */
  70. #define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
  71. u8 bits_per_word;
  72. int irq;
  73. void *controller_state;
  74. void *controller_data;
  75. const char *modalias;
  76. // likely need more hooks for more protocol options affecting how
  77. // the controller talks to each chip, like:
  78. // - memory packing (12 bit samples into low bits, others zeroed)
  79. // - priority
  80. // - drop chipselect after each word
  81. // - chipselect delays
  82. // - ...
  83. };
  84. static inline struct spi_device *to_spi_device(struct device *dev)
  85. {
  86. return dev ? container_of(dev, struct spi_device, dev) : NULL;
  87. }
  88. /* most drivers won't need to care about device refcounting */
  89. static inline struct spi_device *spi_dev_get(struct spi_device *spi)
  90. {
  91. return (spi && get_device(&spi->dev)) ? spi : NULL;
  92. }
  93. static inline void spi_dev_put(struct spi_device *spi)
  94. {
  95. if (spi)
  96. put_device(&spi->dev);
  97. }
  98. /* ctldata is for the bus_master driver's runtime state */
  99. static inline void *spi_get_ctldata(struct spi_device *spi)
  100. {
  101. return spi->controller_state;
  102. }
  103. static inline void spi_set_ctldata(struct spi_device *spi, void *state)
  104. {
  105. spi->controller_state = state;
  106. }
  107. struct spi_message;
  108. struct spi_driver {
  109. int (*probe)(struct spi_device *spi);
  110. int (*remove)(struct spi_device *spi);
  111. void (*shutdown)(struct spi_device *spi);
  112. int (*suspend)(struct spi_device *spi, pm_message_t mesg);
  113. int (*resume)(struct spi_device *spi);
  114. struct device_driver driver;
  115. };
  116. static inline struct spi_driver *to_spi_driver(struct device_driver *drv)
  117. {
  118. return drv ? container_of(drv, struct spi_driver, driver) : NULL;
  119. }
  120. extern int spi_register_driver(struct spi_driver *sdrv);
  121. static inline void spi_unregister_driver(struct spi_driver *sdrv)
  122. {
  123. if (!sdrv)
  124. return;
  125. driver_unregister(&sdrv->driver);
  126. }
  127. /**
  128. * struct spi_master - interface to SPI master controller
  129. * @cdev: class interface to this driver
  130. * @bus_num: board-specific (and often SOC-specific) identifier for a
  131. * given SPI controller.
  132. * @num_chipselect: chipselects are used to distinguish individual
  133. * SPI slaves, and are numbered from zero to num_chipselects.
  134. * each slave has a chipselect signal, but it's common that not
  135. * every chipselect is connected to a slave.
  136. * @setup: updates the device mode and clocking records used by a
  137. * device's SPI controller; protocol code may call this.
  138. * @transfer: adds a message to the controller's transfer queue.
  139. * @cleanup: frees controller-specific state
  140. *
  141. * Each SPI master controller can communicate with one or more spi_device
  142. * children. These make a small bus, sharing MOSI, MISO and SCK signals
  143. * but not chip select signals. Each device may be configured to use a
  144. * different clock rate, since those shared signals are ignored unless
  145. * the chip is selected.
  146. *
  147. * The driver for an SPI controller manages access to those devices through
  148. * a queue of spi_message transactions, copyin data between CPU memory and
  149. * an SPI slave device). For each such message it queues, it calls the
  150. * message's completion function when the transaction completes.
  151. */
  152. struct spi_master {
  153. struct class_device cdev;
  154. /* other than negative (== assign one dynamically), bus_num is fully
  155. * board-specific. usually that simplifies to being SOC-specific.
  156. * example: one SOC has three SPI controllers, numbered 0..2,
  157. * and one board's schematics might show it using SPI-2. software
  158. * would normally use bus_num=2 for that controller.
  159. */
  160. s16 bus_num;
  161. /* chipselects will be integral to many controllers; some others
  162. * might use board-specific GPIOs.
  163. */
  164. u16 num_chipselect;
  165. /* setup mode and clock, etc (spi driver may call many times) */
  166. int (*setup)(struct spi_device *spi);
  167. /* bidirectional bulk transfers
  168. *
  169. * + The transfer() method may not sleep; its main role is
  170. * just to add the message to the queue.
  171. * + For now there's no remove-from-queue operation, or
  172. * any other request management
  173. * + To a given spi_device, message queueing is pure fifo
  174. *
  175. * + The master's main job is to process its message queue,
  176. * selecting a chip then transferring data
  177. * + If there are multiple spi_device children, the i/o queue
  178. * arbitration algorithm is unspecified (round robin, fifo,
  179. * priority, reservations, preemption, etc)
  180. *
  181. * + Chipselect stays active during the entire message
  182. * (unless modified by spi_transfer.cs_change != 0).
  183. * + The message transfers use clock and SPI mode parameters
  184. * previously established by setup() for this device
  185. */
  186. int (*transfer)(struct spi_device *spi,
  187. struct spi_message *mesg);
  188. /* called on release() to free memory provided by spi_master */
  189. void (*cleanup)(const struct spi_device *spi);
  190. };
  191. static inline void *spi_master_get_devdata(struct spi_master *master)
  192. {
  193. return class_get_devdata(&master->cdev);
  194. }
  195. static inline void spi_master_set_devdata(struct spi_master *master, void *data)
  196. {
  197. class_set_devdata(&master->cdev, data);
  198. }
  199. static inline struct spi_master *spi_master_get(struct spi_master *master)
  200. {
  201. if (!master || !class_device_get(&master->cdev))
  202. return NULL;
  203. return master;
  204. }
  205. static inline void spi_master_put(struct spi_master *master)
  206. {
  207. if (master)
  208. class_device_put(&master->cdev);
  209. }
  210. /* the spi driver core manages memory for the spi_master classdev */
  211. extern struct spi_master *
  212. spi_alloc_master(struct device *host, unsigned size);
  213. extern int spi_register_master(struct spi_master *master);
  214. extern void spi_unregister_master(struct spi_master *master);
  215. extern struct spi_master *spi_busnum_to_master(u16 busnum);
  216. /*---------------------------------------------------------------------------*/
  217. /*
  218. * I/O INTERFACE between SPI controller and protocol drivers
  219. *
  220. * Protocol drivers use a queue of spi_messages, each transferring data
  221. * between the controller and memory buffers.
  222. *
  223. * The spi_messages themselves consist of a series of read+write transfer
  224. * segments. Those segments always read the same number of bits as they
  225. * write; but one or the other is easily ignored by passing a null buffer
  226. * pointer. (This is unlike most types of I/O API, because SPI hardware
  227. * is full duplex.)
  228. *
  229. * NOTE: Allocation of spi_transfer and spi_message memory is entirely
  230. * up to the protocol driver, which guarantees the integrity of both (as
  231. * well as the data buffers) for as long as the message is queued.
  232. */
  233. /**
  234. * struct spi_transfer - a read/write buffer pair
  235. * @tx_buf: data to be written (dma-safe memory), or NULL
  236. * @rx_buf: data to be read (dma-safe memory), or NULL
  237. * @tx_dma: DMA address of tx_buf, if spi_message.is_dma_mapped
  238. * @rx_dma: DMA address of rx_buf, if spi_message.is_dma_mapped
  239. * @len: size of rx and tx buffers (in bytes)
  240. * @speed_hz: Select a speed other then the device default for this
  241. * transfer. If 0 the default (from spi_device) is used.
  242. * @bits_per_word: select a bits_per_word other then the device default
  243. * for this transfer. If 0 the default (from spi_device) is used.
  244. * @cs_change: affects chipselect after this transfer completes
  245. * @delay_usecs: microseconds to delay after this transfer before
  246. * (optionally) changing the chipselect status, then starting
  247. * the next transfer or completing this spi_message.
  248. * @transfer_list: transfers are sequenced through spi_message.transfers
  249. *
  250. * SPI transfers always write the same number of bytes as they read.
  251. * Protocol drivers should always provide rx_buf and/or tx_buf.
  252. * In some cases, they may also want to provide DMA addresses for
  253. * the data being transferred; that may reduce overhead, when the
  254. * underlying driver uses dma.
  255. *
  256. * If the transmit buffer is null, undefined data will be shifted out
  257. * while filling rx_buf. If the receive buffer is null, the data
  258. * shifted in will be discarded. Only "len" bytes shift out (or in).
  259. * It's an error to try to shift out a partial word. (For example, by
  260. * shifting out three bytes with word size of sixteen or twenty bits;
  261. * the former uses two bytes per word, the latter uses four bytes.)
  262. *
  263. * All SPI transfers start with the relevant chipselect active. Normally
  264. * it stays selected until after the last transfer in a message. Drivers
  265. * can affect the chipselect signal using cs_change:
  266. *
  267. * (i) If the transfer isn't the last one in the message, this flag is
  268. * used to make the chipselect briefly go inactive in the middle of the
  269. * message. Toggling chipselect in this way may be needed to terminate
  270. * a chip command, letting a single spi_message perform all of group of
  271. * chip transactions together.
  272. *
  273. * (ii) When the transfer is the last one in the message, the chip may
  274. * stay selected until the next transfer. This is purely a performance
  275. * hint; the controller driver may need to select a different device
  276. * for the next message.
  277. *
  278. * The code that submits an spi_message (and its spi_transfers)
  279. * to the lower layers is responsible for managing its memory.
  280. * Zero-initialize every field you don't set up explicitly, to
  281. * insulate against future API updates. After you submit a message
  282. * and its transfers, ignore them until its completion callback.
  283. */
  284. struct spi_transfer {
  285. /* it's ok if tx_buf == rx_buf (right?)
  286. * for MicroWire, one buffer must be null
  287. * buffers must work with dma_*map_single() calls, unless
  288. * spi_message.is_dma_mapped reports a pre-existing mapping
  289. */
  290. const void *tx_buf;
  291. void *rx_buf;
  292. unsigned len;
  293. dma_addr_t tx_dma;
  294. dma_addr_t rx_dma;
  295. unsigned cs_change:1;
  296. u8 bits_per_word;
  297. u16 delay_usecs;
  298. u32 speed_hz;
  299. struct list_head transfer_list;
  300. };
  301. /**
  302. * struct spi_message - one multi-segment SPI transaction
  303. * @transfers: list of transfer segments in this transaction
  304. * @spi: SPI device to which the transaction is queued
  305. * @is_dma_mapped: if true, the caller provided both dma and cpu virtual
  306. * addresses for each transfer buffer
  307. * @complete: called to report transaction completions
  308. * @context: the argument to complete() when it's called
  309. * @actual_length: the total number of bytes that were transferred in all
  310. * successful segments
  311. * @status: zero for success, else negative errno
  312. * @queue: for use by whichever driver currently owns the message
  313. * @state: for use by whichever driver currently owns the message
  314. *
  315. * An spi_message is used to execute an atomic sequence of data transfers,
  316. * each represented by a struct spi_transfer. The sequence is "atomic"
  317. * in the sense that no other spi_message may use that SPI bus until that
  318. * sequence completes. On some systems, many such sequences can execute as
  319. * as single programmed DMA transfer. On all systems, these messages are
  320. * queued, and might complete after transactions to other devices. Messages
  321. * sent to a given spi_device are alway executed in FIFO order.
  322. *
  323. * The code that submits an spi_message (and its spi_transfers)
  324. * to the lower layers is responsible for managing its memory.
  325. * Zero-initialize every field you don't set up explicitly, to
  326. * insulate against future API updates. After you submit a message
  327. * and its transfers, ignore them until its completion callback.
  328. */
  329. struct spi_message {
  330. struct list_head transfers;
  331. struct spi_device *spi;
  332. unsigned is_dma_mapped:1;
  333. /* REVISIT: we might want a flag affecting the behavior of the
  334. * last transfer ... allowing things like "read 16 bit length L"
  335. * immediately followed by "read L bytes". Basically imposing
  336. * a specific message scheduling algorithm.
  337. *
  338. * Some controller drivers (message-at-a-time queue processing)
  339. * could provide that as their default scheduling algorithm. But
  340. * others (with multi-message pipelines) could need a flag to
  341. * tell them about such special cases.
  342. */
  343. /* completion is reported through a callback */
  344. void (*complete)(void *context);
  345. void *context;
  346. unsigned actual_length;
  347. int status;
  348. /* for optional use by whatever driver currently owns the
  349. * spi_message ... between calls to spi_async and then later
  350. * complete(), that's the spi_master controller driver.
  351. */
  352. struct list_head queue;
  353. void *state;
  354. };
  355. static inline void spi_message_init(struct spi_message *m)
  356. {
  357. memset(m, 0, sizeof *m);
  358. INIT_LIST_HEAD(&m->transfers);
  359. }
  360. static inline void
  361. spi_message_add_tail(struct spi_transfer *t, struct spi_message *m)
  362. {
  363. list_add_tail(&t->transfer_list, &m->transfers);
  364. }
  365. static inline void
  366. spi_transfer_del(struct spi_transfer *t)
  367. {
  368. list_del(&t->transfer_list);
  369. }
  370. /* It's fine to embed message and transaction structures in other data
  371. * structures so long as you don't free them while they're in use.
  372. */
  373. static inline struct spi_message *spi_message_alloc(unsigned ntrans, gfp_t flags)
  374. {
  375. struct spi_message *m;
  376. m = kzalloc(sizeof(struct spi_message)
  377. + ntrans * sizeof(struct spi_transfer),
  378. flags);
  379. if (m) {
  380. int i;
  381. struct spi_transfer *t = (struct spi_transfer *)(m + 1);
  382. INIT_LIST_HEAD(&m->transfers);
  383. for (i = 0; i < ntrans; i++, t++)
  384. spi_message_add_tail(t, m);
  385. }
  386. return m;
  387. }
  388. static inline void spi_message_free(struct spi_message *m)
  389. {
  390. kfree(m);
  391. }
  392. /**
  393. * spi_setup -- setup SPI mode and clock rate
  394. * @spi: the device whose settings are being modified
  395. *
  396. * SPI protocol drivers may need to update the transfer mode if the
  397. * device doesn't work with the mode 0 default. They may likewise need
  398. * to update clock rates or word sizes from initial values. This function
  399. * changes those settings, and must be called from a context that can sleep.
  400. * The changes take effect the next time the device is selected and data
  401. * is transferred to or from it.
  402. */
  403. static inline int
  404. spi_setup(struct spi_device *spi)
  405. {
  406. return spi->master->setup(spi);
  407. }
  408. /**
  409. * spi_async -- asynchronous SPI transfer
  410. * @spi: device with which data will be exchanged
  411. * @message: describes the data transfers, including completion callback
  412. *
  413. * This call may be used in_irq and other contexts which can't sleep,
  414. * as well as from task contexts which can sleep.
  415. *
  416. * The completion callback is invoked in a context which can't sleep.
  417. * Before that invocation, the value of message->status is undefined.
  418. * When the callback is issued, message->status holds either zero (to
  419. * indicate complete success) or a negative error code. After that
  420. * callback returns, the driver which issued the transfer request may
  421. * deallocate the associated memory; it's no longer in use by any SPI
  422. * core or controller driver code.
  423. *
  424. * Note that although all messages to a spi_device are handled in
  425. * FIFO order, messages may go to different devices in other orders.
  426. * Some device might be higher priority, or have various "hard" access
  427. * time requirements, for example.
  428. *
  429. * On detection of any fault during the transfer, processing of
  430. * the entire message is aborted, and the device is deselected.
  431. * Until returning from the associated message completion callback,
  432. * no other spi_message queued to that device will be processed.
  433. * (This rule applies equally to all the synchronous transfer calls,
  434. * which are wrappers around this core asynchronous primitive.)
  435. */
  436. static inline int
  437. spi_async(struct spi_device *spi, struct spi_message *message)
  438. {
  439. message->spi = spi;
  440. return spi->master->transfer(spi, message);
  441. }
  442. /*---------------------------------------------------------------------------*/
  443. /* All these synchronous SPI transfer routines are utilities layered
  444. * over the core async transfer primitive. Here, "synchronous" means
  445. * they will sleep uninterruptibly until the async transfer completes.
  446. */
  447. extern int spi_sync(struct spi_device *spi, struct spi_message *message);
  448. /**
  449. * spi_write - SPI synchronous write
  450. * @spi: device to which data will be written
  451. * @buf: data buffer
  452. * @len: data buffer size
  453. *
  454. * This writes the buffer and returns zero or a negative error code.
  455. * Callable only from contexts that can sleep.
  456. */
  457. static inline int
  458. spi_write(struct spi_device *spi, const u8 *buf, size_t len)
  459. {
  460. struct spi_transfer t = {
  461. .tx_buf = buf,
  462. .len = len,
  463. };
  464. struct spi_message m;
  465. spi_message_init(&m);
  466. spi_message_add_tail(&t, &m);
  467. return spi_sync(spi, &m);
  468. }
  469. /**
  470. * spi_read - SPI synchronous read
  471. * @spi: device from which data will be read
  472. * @buf: data buffer
  473. * @len: data buffer size
  474. *
  475. * This writes the buffer and returns zero or a negative error code.
  476. * Callable only from contexts that can sleep.
  477. */
  478. static inline int
  479. spi_read(struct spi_device *spi, u8 *buf, size_t len)
  480. {
  481. struct spi_transfer t = {
  482. .rx_buf = buf,
  483. .len = len,
  484. };
  485. struct spi_message m;
  486. spi_message_init(&m);
  487. spi_message_add_tail(&t, &m);
  488. return spi_sync(spi, &m);
  489. }
  490. /* this copies txbuf and rxbuf data; for small transfers only! */
  491. extern int spi_write_then_read(struct spi_device *spi,
  492. const u8 *txbuf, unsigned n_tx,
  493. u8 *rxbuf, unsigned n_rx);
  494. /**
  495. * spi_w8r8 - SPI synchronous 8 bit write followed by 8 bit read
  496. * @spi: device with which data will be exchanged
  497. * @cmd: command to be written before data is read back
  498. *
  499. * This returns the (unsigned) eight bit number returned by the
  500. * device, or else a negative error code. Callable only from
  501. * contexts that can sleep.
  502. */
  503. static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
  504. {
  505. ssize_t status;
  506. u8 result;
  507. status = spi_write_then_read(spi, &cmd, 1, &result, 1);
  508. /* return negative errno or unsigned value */
  509. return (status < 0) ? status : result;
  510. }
  511. /**
  512. * spi_w8r16 - SPI synchronous 8 bit write followed by 16 bit read
  513. * @spi: device with which data will be exchanged
  514. * @cmd: command to be written before data is read back
  515. *
  516. * This returns the (unsigned) sixteen bit number returned by the
  517. * device, or else a negative error code. Callable only from
  518. * contexts that can sleep.
  519. *
  520. * The number is returned in wire-order, which is at least sometimes
  521. * big-endian.
  522. */
  523. static inline ssize_t spi_w8r16(struct spi_device *spi, u8 cmd)
  524. {
  525. ssize_t status;
  526. u16 result;
  527. status = spi_write_then_read(spi, &cmd, 1, (u8 *) &result, 2);
  528. /* return negative errno or unsigned value */
  529. return (status < 0) ? status : result;
  530. }
  531. /*---------------------------------------------------------------------------*/
  532. /*
  533. * INTERFACE between board init code and SPI infrastructure.
  534. *
  535. * No SPI driver ever sees these SPI device table segments, but
  536. * it's how the SPI core (or adapters that get hotplugged) grows
  537. * the driver model tree.
  538. *
  539. * As a rule, SPI devices can't be probed. Instead, board init code
  540. * provides a table listing the devices which are present, with enough
  541. * information to bind and set up the device's driver. There's basic
  542. * support for nonstatic configurations too; enough to handle adding
  543. * parport adapters, or microcontrollers acting as USB-to-SPI bridges.
  544. */
  545. /* board-specific information about each SPI device */
  546. struct spi_board_info {
  547. /* the device name and module name are coupled, like platform_bus;
  548. * "modalias" is normally the driver name.
  549. *
  550. * platform_data goes to spi_device.dev.platform_data,
  551. * controller_data goes to spi_device.controller_data,
  552. * irq is copied too
  553. */
  554. char modalias[KOBJ_NAME_LEN];
  555. const void *platform_data;
  556. void *controller_data;
  557. int irq;
  558. /* slower signaling on noisy or low voltage boards */
  559. u32 max_speed_hz;
  560. /* bus_num is board specific and matches the bus_num of some
  561. * spi_master that will probably be registered later.
  562. *
  563. * chip_select reflects how this chip is wired to that master;
  564. * it's less than num_chipselect.
  565. */
  566. u16 bus_num;
  567. u16 chip_select;
  568. /* ... may need additional spi_device chip config data here.
  569. * avoid stuff protocol drivers can set; but include stuff
  570. * needed to behave without being bound to a driver:
  571. * - chipselect polarity
  572. * - quirks like clock rate mattering when not selected
  573. */
  574. };
  575. #ifdef CONFIG_SPI
  576. extern int
  577. spi_register_board_info(struct spi_board_info const *info, unsigned n);
  578. #else
  579. /* board init code may ignore whether SPI is configured or not */
  580. static inline int
  581. spi_register_board_info(struct spi_board_info const *info, unsigned n)
  582. { return 0; }
  583. #endif
  584. /* If you're hotplugging an adapter with devices (parport, usb, etc)
  585. * use spi_new_device() to describe each device. You can also call
  586. * spi_unregister_device() to start making that device vanish, but
  587. * normally that would be handled by spi_unregister_master().
  588. */
  589. extern struct spi_device *
  590. spi_new_device(struct spi_master *, struct spi_board_info *);
  591. static inline void
  592. spi_unregister_device(struct spi_device *spi)
  593. {
  594. if (spi)
  595. device_unregister(&spi->dev);
  596. }
  597. #endif /* __LINUX_SPI_H */