aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-07-04 15:01:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-04 15:01:07 -0400
commitb39de277b02ffd8e3dccb01e9159bd45cb07b95d (patch)
tree0cfa6f87f308b0a17b3026dc09813a3eff888ae1 /include/linux
parentd62eb5edf6643ede7e48b4d03ba972c0e8949acc (diff)
parent082f6968bb204d1a3d8b2da3c53d6b7a59bbd985 (diff)
Merge tag 'spi-v4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi updates from Mark Brown: "There's only one big change in this release but it's a very big change: Geert Uytterhoeven has implemented support for SPI slave mode. This feature has been on the cards since the subsystem was originally merged back in the mists of time so it's great that Geert stepped up and finally implemented it. - SPI slave support, together with wholesale renaming of SPI controllers from master to controller which went surprisingly smoothly. This is already used with Renesas SoCs and support is in the works for i.MX too. - New drivers for Meson SPICC and ST STM32" * tag 'spi-v4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (57 commits) spi: loopback-test: Fix kfree() NULL pointer error. spi: loopback-test: fix spelling mistake: "reruning" -> "rerunning" spi: sirf: fix spelling mistake: "registerred" -> "registered" spi: stm32: fix potential dereference null return value spi: stm32: enhance DMA error management spi: stm32: add runtime PM support spi: stm32: use normal conditional statements instead of ternary operator spi: stm32: replace st, spi-midi with st, spi-midi-ns to fit bindings spi: stm32: fix example with st, spi-midi-ns property spi: stm32: fix compatible to fit with new bindings spi: stm32: use SoC specific compatible spi: rockchip: Disable Runtime PM when chip select is asserted spi: rockchip: Set GPIO_SS flag to enable Slave Select with GPIO CS spi: atmel: fix corrupted data issue on SAM9 family SoCs spi: stm32: fix error check on mbr being -ve spi: add driver for STM32 SPI controller spi: Document the STM32 SPI bindings spi/bcm63xx: Fix checkpatch warnings spi: imx: Check for allocation failure earlier spi: mediatek: add spi support for mt2712 IC ...
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/platform_data/spi-mt65xx.h2
-rw-r--r--include/linux/pxa2xx_ssp.h1
-rw-r--r--include/linux/spi/sh_msiof.h6
-rw-r--r--include/linux/spi/spi.h217
4 files changed, 145 insertions, 81 deletions
diff --git a/include/linux/platform_data/spi-mt65xx.h b/include/linux/platform_data/spi-mt65xx.h
index 54b04483976c..ba4e4bb70262 100644
--- a/include/linux/platform_data/spi-mt65xx.h
+++ b/include/linux/platform_data/spi-mt65xx.h
@@ -16,5 +16,7 @@
16struct mtk_chip_config { 16struct mtk_chip_config {
17 u32 tx_mlsb; 17 u32 tx_mlsb;
18 u32 rx_mlsb; 18 u32 rx_mlsb;
19 u32 cs_pol;
20 u32 sample_sel;
19}; 21};
20#endif 22#endif
diff --git a/include/linux/pxa2xx_ssp.h b/include/linux/pxa2xx_ssp.h
index a0522328d7aa..8461b18e4608 100644
--- a/include/linux/pxa2xx_ssp.h
+++ b/include/linux/pxa2xx_ssp.h
@@ -196,6 +196,7 @@ enum pxa_ssp_type {
196 LPSS_BSW_SSP, 196 LPSS_BSW_SSP,
197 LPSS_SPT_SSP, 197 LPSS_SPT_SSP,
198 LPSS_BXT_SSP, 198 LPSS_BXT_SSP,
199 LPSS_CNL_SSP,
199}; 200};
200 201
201struct ssp_device { 202struct ssp_device {
diff --git a/include/linux/spi/sh_msiof.h b/include/linux/spi/sh_msiof.h
index b087a85f5f72..f74b581f242f 100644
--- a/include/linux/spi/sh_msiof.h
+++ b/include/linux/spi/sh_msiof.h
@@ -1,10 +1,16 @@
1#ifndef __SPI_SH_MSIOF_H__ 1#ifndef __SPI_SH_MSIOF_H__
2#define __SPI_SH_MSIOF_H__ 2#define __SPI_SH_MSIOF_H__
3 3
4enum {
5 MSIOF_SPI_MASTER,
6 MSIOF_SPI_SLAVE,
7};
8
4struct sh_msiof_spi_info { 9struct sh_msiof_spi_info {
5 int tx_fifo_override; 10 int tx_fifo_override;
6 int rx_fifo_override; 11 int rx_fifo_override;
7 u16 num_chipselect; 12 u16 num_chipselect;
13 int mode;
8 unsigned int dma_tx_id; 14 unsigned int dma_tx_id;
9 unsigned int dma_rx_id; 15 unsigned int dma_rx_id;
10 u32 dtdl; 16 u32 dtdl;
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 935bd2854ff1..7b2170bfd6e7 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -24,13 +24,13 @@
24 24
25struct dma_chan; 25struct dma_chan;
26struct property_entry; 26struct property_entry;
27struct spi_master; 27struct spi_controller;
28struct spi_transfer; 28struct spi_transfer;
29struct spi_flash_read_message; 29struct spi_flash_read_message;
30 30
31/* 31/*
32 * INTERFACES between SPI master-side drivers and SPI infrastructure. 32 * INTERFACES between SPI master-side drivers and SPI slave protocol handlers,
33 * (There's no SPI slave support for Linux yet...) 33 * and SPI infrastructure.
34 */ 34 */
35extern struct bus_type spi_bus_type; 35extern struct bus_type spi_bus_type;
36 36
@@ -84,7 +84,7 @@ struct spi_statistics {
84 84
85void spi_statistics_add_transfer_stats(struct spi_statistics *stats, 85void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
86 struct spi_transfer *xfer, 86 struct spi_transfer *xfer,
87 struct spi_master *master); 87 struct spi_controller *ctlr);
88 88
89#define SPI_STATISTICS_ADD_TO_FIELD(stats, field, count) \ 89#define SPI_STATISTICS_ADD_TO_FIELD(stats, field, count) \
90 do { \ 90 do { \
@@ -98,13 +98,14 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
98 SPI_STATISTICS_ADD_TO_FIELD(stats, field, 1) 98 SPI_STATISTICS_ADD_TO_FIELD(stats, field, 1)
99 99
100/** 100/**
101 * struct spi_device - Master side proxy for an SPI slave device 101 * struct spi_device - Controller side proxy for an SPI slave device
102 * @dev: Driver model representation of the device. 102 * @dev: Driver model representation of the device.
103 * @master: SPI controller used with the device. 103 * @controller: SPI controller used with the device.
104 * @master: Copy of controller, for backwards compatibility.
104 * @max_speed_hz: Maximum clock rate to be used with this chip 105 * @max_speed_hz: Maximum clock rate to be used with this chip
105 * (on this board); may be changed by the device's driver. 106 * (on this board); may be changed by the device's driver.
106 * The spi_transfer.speed_hz can override this for each transfer. 107 * The spi_transfer.speed_hz can override this for each transfer.
107 * @chip_select: Chipselect, distinguishing chips handled by @master. 108 * @chip_select: Chipselect, distinguishing chips handled by @controller.
108 * @mode: The spi mode defines how data is clocked out and in. 109 * @mode: The spi mode defines how data is clocked out and in.
109 * This may be changed by the device's driver. 110 * This may be changed by the device's driver.
110 * The "active low" default for chipselect mode can be overridden 111 * The "active low" default for chipselect mode can be overridden
@@ -140,7 +141,8 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
140 */ 141 */
141struct spi_device { 142struct spi_device {
142 struct device dev; 143 struct device dev;
143 struct spi_master *master; 144 struct spi_controller *controller;
145 struct spi_controller *master; /* compatibility layer */
144 u32 max_speed_hz; 146 u32 max_speed_hz;
145 u8 chip_select; 147 u8 chip_select;
146 u8 bits_per_word; 148 u8 bits_per_word;
@@ -198,7 +200,7 @@ static inline void spi_dev_put(struct spi_device *spi)
198 put_device(&spi->dev); 200 put_device(&spi->dev);
199} 201}
200 202
201/* ctldata is for the bus_master driver's runtime state */ 203/* ctldata is for the bus_controller driver's runtime state */
202static inline void *spi_get_ctldata(struct spi_device *spi) 204static inline void *spi_get_ctldata(struct spi_device *spi)
203{ 205{
204 return spi->controller_state; 206 return spi->controller_state;
@@ -292,9 +294,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
292 spi_unregister_driver) 294 spi_unregister_driver)
293 295
294/** 296/**
295 * struct spi_master - interface to SPI master controller 297 * struct spi_controller - interface to SPI master or slave controller
296 * @dev: device interface to this driver 298 * @dev: device interface to this driver
297 * @list: link with the global spi_master list 299 * @list: link with the global spi_controller list
298 * @bus_num: board-specific (and often SOC-specific) identifier for a 300 * @bus_num: board-specific (and often SOC-specific) identifier for a
299 * given SPI controller. 301 * given SPI controller.
300 * @num_chipselect: chipselects are used to distinguish individual 302 * @num_chipselect: chipselects are used to distinguish individual
@@ -311,6 +313,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
311 * @min_speed_hz: Lowest supported transfer speed 313 * @min_speed_hz: Lowest supported transfer speed
312 * @max_speed_hz: Highest supported transfer speed 314 * @max_speed_hz: Highest supported transfer speed
313 * @flags: other constraints relevant to this driver 315 * @flags: other constraints relevant to this driver
316 * @slave: indicates that this is an SPI slave controller
314 * @max_transfer_size: function that returns the max transfer size for 317 * @max_transfer_size: function that returns the max transfer size for
315 * a &spi_device; may be %NULL, so the default %SIZE_MAX will be used. 318 * a &spi_device; may be %NULL, so the default %SIZE_MAX will be used.
316 * @max_message_size: function that returns the max message size for 319 * @max_message_size: function that returns the max message size for
@@ -326,8 +329,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
326 * the device whose settings are being modified. 329 * the device whose settings are being modified.
327 * @transfer: adds a message to the controller's transfer queue. 330 * @transfer: adds a message to the controller's transfer queue.
328 * @cleanup: frees controller-specific state 331 * @cleanup: frees controller-specific state
329 * @can_dma: determine whether this master supports DMA 332 * @can_dma: determine whether this controller supports DMA
330 * @queued: whether this master is providing an internal message queue 333 * @queued: whether this controller is providing an internal message queue
331 * @kworker: thread struct for message pump 334 * @kworker: thread struct for message pump
332 * @kworker_task: pointer to task for message pump kworker thread 335 * @kworker_task: pointer to task for message pump kworker thread
333 * @pump_messages: work struct for scheduling work to the message pump 336 * @pump_messages: work struct for scheduling work to the message pump
@@ -374,6 +377,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
374 * @handle_err: the subsystem calls the driver to handle an error that occurs 377 * @handle_err: the subsystem calls the driver to handle an error that occurs
375 * in the generic implementation of transfer_one_message(). 378 * in the generic implementation of transfer_one_message().
376 * @unprepare_message: undo any work done by prepare_message(). 379 * @unprepare_message: undo any work done by prepare_message().
380 * @slave_abort: abort the ongoing transfer request on an SPI slave controller
377 * @spi_flash_read: to support spi-controller hardwares that provide 381 * @spi_flash_read: to support spi-controller hardwares that provide
378 * accelerated interface to read from flash devices. 382 * accelerated interface to read from flash devices.
379 * @spi_flash_can_dma: analogous to can_dma() interface, but for 383 * @spi_flash_can_dma: analogous to can_dma() interface, but for
@@ -382,7 +386,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
382 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS 386 * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
383 * number. Any individual value may be -ENOENT for CS lines that 387 * number. Any individual value may be -ENOENT for CS lines that
384 * are not GPIOs (driven by the SPI controller itself). 388 * are not GPIOs (driven by the SPI controller itself).
385 * @statistics: statistics for the spi_master 389 * @statistics: statistics for the spi_controller
386 * @dma_tx: DMA transmit channel 390 * @dma_tx: DMA transmit channel
387 * @dma_rx: DMA receive channel 391 * @dma_rx: DMA receive channel
388 * @dummy_rx: dummy receive buffer for full-duplex devices 392 * @dummy_rx: dummy receive buffer for full-duplex devices
@@ -391,7 +395,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
391 * what Linux expects, this optional hook can be used to translate 395 * what Linux expects, this optional hook can be used to translate
392 * between the two. 396 * between the two.
393 * 397 *
394 * Each SPI master controller can communicate with one or more @spi_device 398 * Each SPI controller can communicate with one or more @spi_device
395 * children. These make a small bus, sharing MOSI, MISO and SCK signals 399 * children. These make a small bus, sharing MOSI, MISO and SCK signals
396 * but not chip select signals. Each device may be configured to use a 400 * but not chip select signals. Each device may be configured to use a
397 * different clock rate, since those shared signals are ignored unless 401 * different clock rate, since those shared signals are ignored unless
@@ -402,7 +406,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
402 * an SPI slave device. For each such message it queues, it calls the 406 * an SPI slave device. For each such message it queues, it calls the
403 * message's completion function when the transaction completes. 407 * message's completion function when the transaction completes.
404 */ 408 */
405struct spi_master { 409struct spi_controller {
406 struct device dev; 410 struct device dev;
407 411
408 struct list_head list; 412 struct list_head list;
@@ -440,12 +444,16 @@ struct spi_master {
440 444
441 /* other constraints relevant to this driver */ 445 /* other constraints relevant to this driver */
442 u16 flags; 446 u16 flags;
443#define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */ 447#define SPI_CONTROLLER_HALF_DUPLEX BIT(0) /* can't do full duplex */
444#define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */ 448#define SPI_CONTROLLER_NO_RX BIT(1) /* can't do buffer read */
445#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */ 449#define SPI_CONTROLLER_NO_TX BIT(2) /* can't do buffer write */
446#define SPI_MASTER_MUST_RX BIT(3) /* requires rx */ 450#define SPI_CONTROLLER_MUST_RX BIT(3) /* requires rx */
447#define SPI_MASTER_MUST_TX BIT(4) /* requires tx */ 451#define SPI_CONTROLLER_MUST_TX BIT(4) /* requires tx */
448#define SPI_MASTER_GPIO_SS BIT(5) /* GPIO CS must select slave */ 452
453#define SPI_MASTER_GPIO_SS BIT(5) /* GPIO CS must select slave */
454
455 /* flag indicating this is an SPI slave controller */
456 bool slave;
449 457
450 /* 458 /*
451 * on some hardware transfer / message size may be constrained 459 * on some hardware transfer / message size may be constrained
@@ -480,8 +488,8 @@ struct spi_master {
480 * any other request management 488 * any other request management
481 * + To a given spi_device, message queueing is pure fifo 489 * + To a given spi_device, message queueing is pure fifo
482 * 490 *
483 * + The master's main job is to process its message queue, 491 * + The controller's main job is to process its message queue,
484 * selecting a chip then transferring data 492 * selecting a chip (for masters), then transferring data
485 * + If there are multiple spi_device children, the i/o queue 493 * + If there are multiple spi_device children, the i/o queue
486 * arbitration algorithm is unspecified (round robin, fifo, 494 * arbitration algorithm is unspecified (round robin, fifo,
487 * priority, reservations, preemption, etc) 495 * priority, reservations, preemption, etc)
@@ -494,7 +502,7 @@ struct spi_master {
494 int (*transfer)(struct spi_device *spi, 502 int (*transfer)(struct spi_device *spi,
495 struct spi_message *mesg); 503 struct spi_message *mesg);
496 504
497 /* called on release() to free memory provided by spi_master */ 505 /* called on release() to free memory provided by spi_controller */
498 void (*cleanup)(struct spi_device *spi); 506 void (*cleanup)(struct spi_device *spi);
499 507
500 /* 508 /*
@@ -504,13 +512,13 @@ struct spi_master {
504 * not modify or store xfer and dma_tx and dma_rx must be set 512 * not modify or store xfer and dma_tx and dma_rx must be set
505 * while the device is prepared. 513 * while the device is prepared.
506 */ 514 */
507 bool (*can_dma)(struct spi_master *master, 515 bool (*can_dma)(struct spi_controller *ctlr,
508 struct spi_device *spi, 516 struct spi_device *spi,
509 struct spi_transfer *xfer); 517 struct spi_transfer *xfer);
510 518
511 /* 519 /*
512 * These hooks are for drivers that want to use the generic 520 * These hooks are for drivers that want to use the generic
513 * master transfer queueing mechanism. If these are used, the 521 * controller transfer queueing mechanism. If these are used, the
514 * transfer() function above must NOT be specified by the driver. 522 * transfer() function above must NOT be specified by the driver.
515 * Over time we expect SPI drivers to be phased over to this API. 523 * Over time we expect SPI drivers to be phased over to this API.
516 */ 524 */
@@ -531,14 +539,15 @@ struct spi_master {
531 struct completion xfer_completion; 539 struct completion xfer_completion;
532 size_t max_dma_len; 540 size_t max_dma_len;
533 541
534 int (*prepare_transfer_hardware)(struct spi_master *master); 542 int (*prepare_transfer_hardware)(struct spi_controller *ctlr);
535 int (*transfer_one_message)(struct spi_master *master, 543 int (*transfer_one_message)(struct spi_controller *ctlr,
536 struct spi_message *mesg); 544 struct spi_message *mesg);
537 int (*unprepare_transfer_hardware)(struct spi_master *master); 545 int (*unprepare_transfer_hardware)(struct spi_controller *ctlr);
538 int (*prepare_message)(struct spi_master *master, 546 int (*prepare_message)(struct spi_controller *ctlr,
539 struct spi_message *message); 547 struct spi_message *message);
540 int (*unprepare_message)(struct spi_master *master, 548 int (*unprepare_message)(struct spi_controller *ctlr,
541 struct spi_message *message); 549 struct spi_message *message);
550 int (*slave_abort)(struct spi_controller *ctlr);
542 int (*spi_flash_read)(struct spi_device *spi, 551 int (*spi_flash_read)(struct spi_device *spi,
543 struct spi_flash_read_message *msg); 552 struct spi_flash_read_message *msg);
544 bool (*spi_flash_can_dma)(struct spi_device *spi, 553 bool (*spi_flash_can_dma)(struct spi_device *spi,
@@ -550,9 +559,9 @@ struct spi_master {
550 * of transfer_one_message() provied by the core. 559 * of transfer_one_message() provied by the core.
551 */ 560 */
552 void (*set_cs)(struct spi_device *spi, bool enable); 561 void (*set_cs)(struct spi_device *spi, bool enable);
553 int (*transfer_one)(struct spi_master *master, struct spi_device *spi, 562 int (*transfer_one)(struct spi_controller *ctlr, struct spi_device *spi,
554 struct spi_transfer *transfer); 563 struct spi_transfer *transfer);
555 void (*handle_err)(struct spi_master *master, 564 void (*handle_err)(struct spi_controller *ctlr,
556 struct spi_message *message); 565 struct spi_message *message);
557 566
558 /* gpio chip select */ 567 /* gpio chip select */
@@ -569,57 +578,78 @@ struct spi_master {
569 void *dummy_rx; 578 void *dummy_rx;
570 void *dummy_tx; 579 void *dummy_tx;
571 580
572 int (*fw_translate_cs)(struct spi_master *master, unsigned cs); 581 int (*fw_translate_cs)(struct spi_controller *ctlr, unsigned cs);
573}; 582};
574 583
575static inline void *spi_master_get_devdata(struct spi_master *master) 584static inline void *spi_controller_get_devdata(struct spi_controller *ctlr)
576{ 585{
577 return dev_get_drvdata(&master->dev); 586 return dev_get_drvdata(&ctlr->dev);
578} 587}
579 588
580static inline void spi_master_set_devdata(struct spi_master *master, void *data) 589static inline void spi_controller_set_devdata(struct spi_controller *ctlr,
590 void *data)
581{ 591{
582 dev_set_drvdata(&master->dev, data); 592 dev_set_drvdata(&ctlr->dev, data);
583} 593}
584 594
585static inline struct spi_master *spi_master_get(struct spi_master *master) 595static inline struct spi_controller *spi_controller_get(struct spi_controller *ctlr)
586{ 596{
587 if (!master || !get_device(&master->dev)) 597 if (!ctlr || !get_device(&ctlr->dev))
588 return NULL; 598 return NULL;
589 return master; 599 return ctlr;
600}
601
602static inline void spi_controller_put(struct spi_controller *ctlr)
603{
604 if (ctlr)
605 put_device(&ctlr->dev);
590} 606}
591 607
592static inline void spi_master_put(struct spi_master *master) 608static inline bool spi_controller_is_slave(struct spi_controller *ctlr)
593{ 609{
594 if (master) 610 return IS_ENABLED(CONFIG_SPI_SLAVE) && ctlr->slave;
595 put_device(&master->dev);
596} 611}
597 612
598/* PM calls that need to be issued by the driver */ 613/* PM calls that need to be issued by the driver */
599extern int spi_master_suspend(struct spi_master *master); 614extern int spi_controller_suspend(struct spi_controller *ctlr);
600extern int spi_master_resume(struct spi_master *master); 615extern int spi_controller_resume(struct spi_controller *ctlr);
601 616
602/* Calls the driver make to interact with the message queue */ 617/* Calls the driver make to interact with the message queue */
603extern struct spi_message *spi_get_next_queued_message(struct spi_master *master); 618extern struct spi_message *spi_get_next_queued_message(struct spi_controller *ctlr);
604extern void spi_finalize_current_message(struct spi_master *master); 619extern void spi_finalize_current_message(struct spi_controller *ctlr);
605extern void spi_finalize_current_transfer(struct spi_master *master); 620extern void spi_finalize_current_transfer(struct spi_controller *ctlr);
606 621
607/* the spi driver core manages memory for the spi_master classdev */ 622/* the spi driver core manages memory for the spi_controller classdev */
608extern struct spi_master * 623extern struct spi_controller *__spi_alloc_controller(struct device *host,
609spi_alloc_master(struct device *host, unsigned size); 624 unsigned int size, bool slave);
610 625
611extern int spi_register_master(struct spi_master *master); 626static inline struct spi_controller *spi_alloc_master(struct device *host,
612extern int devm_spi_register_master(struct device *dev, 627 unsigned int size)
613 struct spi_master *master); 628{
614extern void spi_unregister_master(struct spi_master *master); 629 return __spi_alloc_controller(host, size, false);
630}
615 631
616extern struct spi_master *spi_busnum_to_master(u16 busnum); 632static inline struct spi_controller *spi_alloc_slave(struct device *host,
633 unsigned int size)
634{
635 if (!IS_ENABLED(CONFIG_SPI_SLAVE))
636 return NULL;
637
638 return __spi_alloc_controller(host, size, true);
639}
640
641extern int spi_register_controller(struct spi_controller *ctlr);
642extern int devm_spi_register_controller(struct device *dev,
643 struct spi_controller *ctlr);
644extern void spi_unregister_controller(struct spi_controller *ctlr);
645
646extern struct spi_controller *spi_busnum_to_master(u16 busnum);
617 647
618/* 648/*
619 * SPI resource management while processing a SPI message 649 * SPI resource management while processing a SPI message
620 */ 650 */
621 651
622typedef void (*spi_res_release_t)(struct spi_master *master, 652typedef void (*spi_res_release_t)(struct spi_controller *ctlr,
623 struct spi_message *msg, 653 struct spi_message *msg,
624 void *res); 654 void *res);
625 655
@@ -644,7 +674,7 @@ extern void *spi_res_alloc(struct spi_device *spi,
644extern void spi_res_add(struct spi_message *message, void *res); 674extern void spi_res_add(struct spi_message *message, void *res);
645extern void spi_res_free(void *res); 675extern void spi_res_free(void *res);
646 676
647extern void spi_res_release(struct spi_master *master, 677extern void spi_res_release(struct spi_controller *ctlr,
648 struct spi_message *message); 678 struct spi_message *message);
649 679
650/*---------------------------------------------------------------------------*/ 680/*---------------------------------------------------------------------------*/
@@ -828,7 +858,7 @@ struct spi_message {
828 858
829 /* for optional use by whatever driver currently owns the 859 /* for optional use by whatever driver currently owns the
830 * spi_message ... between calls to spi_async and then later 860 * spi_message ... between calls to spi_async and then later
831 * complete(), that's the spi_master controller driver. 861 * complete(), that's the spi_controller controller driver.
832 */ 862 */
833 struct list_head queue; 863 struct list_head queue;
834 void *state; 864 void *state;
@@ -912,25 +942,27 @@ extern int spi_setup(struct spi_device *spi);
912extern int spi_async(struct spi_device *spi, struct spi_message *message); 942extern int spi_async(struct spi_device *spi, struct spi_message *message);
913extern int spi_async_locked(struct spi_device *spi, 943extern int spi_async_locked(struct spi_device *spi,
914 struct spi_message *message); 944 struct spi_message *message);
945extern int spi_slave_abort(struct spi_device *spi);
915 946
916static inline size_t 947static inline size_t
917spi_max_message_size(struct spi_device *spi) 948spi_max_message_size(struct spi_device *spi)
918{ 949{
919 struct spi_master *master = spi->master; 950 struct spi_controller *ctlr = spi->controller;
920 if (!master->max_message_size) 951
952 if (!ctlr->max_message_size)
921 return SIZE_MAX; 953 return SIZE_MAX;
922 return master->max_message_size(spi); 954 return ctlr->max_message_size(spi);
923} 955}
924 956
925static inline size_t 957static inline size_t
926spi_max_transfer_size(struct spi_device *spi) 958spi_max_transfer_size(struct spi_device *spi)
927{ 959{
928 struct spi_master *master = spi->master; 960 struct spi_controller *ctlr = spi->controller;
929 size_t tr_max = SIZE_MAX; 961 size_t tr_max = SIZE_MAX;
930 size_t msg_max = spi_max_message_size(spi); 962 size_t msg_max = spi_max_message_size(spi);
931 963
932 if (master->max_transfer_size) 964 if (ctlr->max_transfer_size)
933 tr_max = master->max_transfer_size(spi); 965 tr_max = ctlr->max_transfer_size(spi);
934 966
935 /* transfer size limit must not be greater than messsage size limit */ 967 /* transfer size limit must not be greater than messsage size limit */
936 return min(tr_max, msg_max); 968 return min(tr_max, msg_max);
@@ -941,7 +973,7 @@ spi_max_transfer_size(struct spi_device *spi)
941/* SPI transfer replacement methods which make use of spi_res */ 973/* SPI transfer replacement methods which make use of spi_res */
942 974
943struct spi_replaced_transfers; 975struct spi_replaced_transfers;
944typedef void (*spi_replaced_release_t)(struct spi_master *master, 976typedef void (*spi_replaced_release_t)(struct spi_controller *ctlr,
945 struct spi_message *msg, 977 struct spi_message *msg,
946 struct spi_replaced_transfers *res); 978 struct spi_replaced_transfers *res);
947/** 979/**
@@ -985,7 +1017,7 @@ extern struct spi_replaced_transfers *spi_replace_transfers(
985 1017
986/* SPI transfer transformation methods */ 1018/* SPI transfer transformation methods */
987 1019
988extern int spi_split_transfers_maxsize(struct spi_master *master, 1020extern int spi_split_transfers_maxsize(struct spi_controller *ctlr,
989 struct spi_message *msg, 1021 struct spi_message *msg,
990 size_t maxsize, 1022 size_t maxsize,
991 gfp_t gfp); 1023 gfp_t gfp);
@@ -999,8 +1031,8 @@ extern int spi_split_transfers_maxsize(struct spi_master *master,
999 1031
1000extern int spi_sync(struct spi_device *spi, struct spi_message *message); 1032extern int spi_sync(struct spi_device *spi, struct spi_message *message);
1001extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message); 1033extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message);
1002extern int spi_bus_lock(struct spi_master *master); 1034extern int spi_bus_lock(struct spi_controller *ctlr);
1003extern int spi_bus_unlock(struct spi_master *master); 1035extern int spi_bus_unlock(struct spi_controller *ctlr);
1004 1036
1005/** 1037/**
1006 * spi_sync_transfer - synchronous SPI data transfer 1038 * spi_sync_transfer - synchronous SPI data transfer
@@ -1185,9 +1217,9 @@ struct spi_flash_read_message {
1185/* SPI core interface for flash read support */ 1217/* SPI core interface for flash read support */
1186static inline bool spi_flash_read_supported(struct spi_device *spi) 1218static inline bool spi_flash_read_supported(struct spi_device *spi)
1187{ 1219{
1188 return spi->master->spi_flash_read && 1220 return spi->controller->spi_flash_read &&
1189 (!spi->master->flash_read_supported || 1221 (!spi->controller->flash_read_supported ||
1190 spi->master->flash_read_supported(spi)); 1222 spi->controller->flash_read_supported(spi));
1191} 1223}
1192 1224
1193int spi_flash_read(struct spi_device *spi, 1225int spi_flash_read(struct spi_device *spi,
@@ -1220,7 +1252,7 @@ int spi_flash_read(struct spi_device *spi,
1220 * @irq: Initializes spi_device.irq; depends on how the board is wired. 1252 * @irq: Initializes spi_device.irq; depends on how the board is wired.
1221 * @max_speed_hz: Initializes spi_device.max_speed_hz; based on limits 1253 * @max_speed_hz: Initializes spi_device.max_speed_hz; based on limits
1222 * from the chip datasheet and board-specific signal quality issues. 1254 * from the chip datasheet and board-specific signal quality issues.
1223 * @bus_num: Identifies which spi_master parents the spi_device; unused 1255 * @bus_num: Identifies which spi_controller parents the spi_device; unused
1224 * by spi_new_device(), and otherwise depends on board wiring. 1256 * by spi_new_device(), and otherwise depends on board wiring.
1225 * @chip_select: Initializes spi_device.chip_select; depends on how 1257 * @chip_select: Initializes spi_device.chip_select; depends on how
1226 * the board is wired. 1258 * the board is wired.
@@ -1261,7 +1293,7 @@ struct spi_board_info {
1261 1293
1262 1294
1263 /* bus_num is board specific and matches the bus_num of some 1295 /* bus_num is board specific and matches the bus_num of some
1264 * spi_master that will probably be registered later. 1296 * spi_controller that will probably be registered later.
1265 * 1297 *
1266 * chip_select reflects how this chip is wired to that master; 1298 * chip_select reflects how this chip is wired to that master;
1267 * it's less than num_chipselect. 1299 * it's less than num_chipselect.
@@ -1295,7 +1327,7 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
1295/* If you're hotplugging an adapter with devices (parport, usb, etc) 1327/* If you're hotplugging an adapter with devices (parport, usb, etc)
1296 * use spi_new_device() to describe each device. You can also call 1328 * use spi_new_device() to describe each device. You can also call
1297 * spi_unregister_device() to start making that device vanish, but 1329 * spi_unregister_device() to start making that device vanish, but
1298 * normally that would be handled by spi_unregister_master(). 1330 * normally that would be handled by spi_unregister_controller().
1299 * 1331 *
1300 * You can also use spi_alloc_device() and spi_add_device() to use a two 1332 * You can also use spi_alloc_device() and spi_add_device() to use a two
1301 * stage registration sequence for each spi_device. This gives the caller 1333 * stage registration sequence for each spi_device. This gives the caller
@@ -1304,13 +1336,13 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
1304 * be defined using the board info. 1336 * be defined using the board info.
1305 */ 1337 */
1306extern struct spi_device * 1338extern struct spi_device *
1307spi_alloc_device(struct spi_master *master); 1339spi_alloc_device(struct spi_controller *ctlr);
1308 1340
1309extern int 1341extern int
1310spi_add_device(struct spi_device *spi); 1342spi_add_device(struct spi_device *spi);
1311 1343
1312extern struct spi_device * 1344extern struct spi_device *
1313spi_new_device(struct spi_master *, struct spi_board_info *); 1345spi_new_device(struct spi_controller *, struct spi_board_info *);
1314 1346
1315extern void spi_unregister_device(struct spi_device *spi); 1347extern void spi_unregister_device(struct spi_device *spi);
1316 1348
@@ -1318,9 +1350,32 @@ extern const struct spi_device_id *
1318spi_get_device_id(const struct spi_device *sdev); 1350spi_get_device_id(const struct spi_device *sdev);
1319 1351
1320static inline bool 1352static inline bool
1321spi_transfer_is_last(struct spi_master *master, struct spi_transfer *xfer) 1353spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)
1322{ 1354{
1323 return list_is_last(&xfer->transfer_list, &master->cur_msg->transfers); 1355 return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers);
1324} 1356}
1325 1357
1358
1359/* Compatibility layer */
1360#define spi_master spi_controller
1361
1362#define SPI_MASTER_HALF_DUPLEX SPI_CONTROLLER_HALF_DUPLEX
1363#define SPI_MASTER_NO_RX SPI_CONTROLLER_NO_RX
1364#define SPI_MASTER_NO_TX SPI_CONTROLLER_NO_TX
1365#define SPI_MASTER_MUST_RX SPI_CONTROLLER_MUST_RX
1366#define SPI_MASTER_MUST_TX SPI_CONTROLLER_MUST_TX
1367
1368#define spi_master_get_devdata(_ctlr) spi_controller_get_devdata(_ctlr)
1369#define spi_master_set_devdata(_ctlr, _data) \
1370 spi_controller_set_devdata(_ctlr, _data)
1371#define spi_master_get(_ctlr) spi_controller_get(_ctlr)
1372#define spi_master_put(_ctlr) spi_controller_put(_ctlr)
1373#define spi_master_suspend(_ctlr) spi_controller_suspend(_ctlr)
1374#define spi_master_resume(_ctlr) spi_controller_resume(_ctlr)
1375
1376#define spi_register_master(_ctlr) spi_register_controller(_ctlr)
1377#define devm_spi_register_master(_dev, _ctlr) \
1378 devm_spi_register_controller(_dev, _ctlr)
1379#define spi_unregister_master(_ctlr) spi_unregister_controller(_ctlr)
1380
1326#endif /* __LINUX_SPI_H */ 1381#endif /* __LINUX_SPI_H */