aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2017-06-13 07:23:52 -0400
committerMark Brown <broonie@kernel.org>2017-06-13 13:51:11 -0400
commit8caab75fd2c2a92667cbb1cd315720bede3feaa9 (patch)
tree8252d9a84e32698fe52f12dd6e94227555857668
parentc94085f587a77495eabb78a959bd591bee4ec89b (diff)
spi: Generalize SPI "master" to "controller"
Now struct spi_master is used for both SPI master and slave controllers, it makes sense to rename it to struct spi_controller, and replace "master" by "controller" where appropriate. For now this conversion is done for SPI core infrastructure only. Wrappers are provided for backwards compatibility, until all SPI drivers have been converted. Noteworthy details: - SPI_MASTER_GPIO_SS is retained, as it only makes sense for SPI master controllers, - spi_busnum_to_master() is retained, as it looks up masters only, - A new field spi_device.controller is added, but spi_device.master is retained for compatibility (both are always initialized by spi_alloc_device()), - spi_flash_read() is used by SPI masters only. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi.c1081
-rw-r--r--include/linux/spi/spi.h198
-rw-r--r--include/trace/events/spi.h26
3 files changed, 668 insertions, 637 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index c3f6b524b3ce..4fcbb0aa71d3 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -48,11 +48,11 @@ static void spidev_release(struct device *dev)
48{ 48{
49 struct spi_device *spi = to_spi_device(dev); 49 struct spi_device *spi = to_spi_device(dev);
50 50
51 /* spi masters may cleanup for released devices */ 51 /* spi controllers may cleanup for released devices */
52 if (spi->master->cleanup) 52 if (spi->controller->cleanup)
53 spi->master->cleanup(spi); 53 spi->controller->cleanup(spi);
54 54
55 spi_master_put(spi->master); 55 spi_controller_put(spi->controller);
56 kfree(spi); 56 kfree(spi);
57} 57}
58 58
@@ -71,17 +71,17 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)
71static DEVICE_ATTR_RO(modalias); 71static DEVICE_ATTR_RO(modalias);
72 72
73#define SPI_STATISTICS_ATTRS(field, file) \ 73#define SPI_STATISTICS_ATTRS(field, file) \
74static ssize_t spi_master_##field##_show(struct device *dev, \ 74static ssize_t spi_controller_##field##_show(struct device *dev, \
75 struct device_attribute *attr, \ 75 struct device_attribute *attr, \
76 char *buf) \ 76 char *buf) \
77{ \ 77{ \
78 struct spi_master *master = container_of(dev, \ 78 struct spi_controller *ctlr = container_of(dev, \
79 struct spi_master, dev); \ 79 struct spi_controller, dev); \
80 return spi_statistics_##field##_show(&master->statistics, buf); \ 80 return spi_statistics_##field##_show(&ctlr->statistics, buf); \
81} \ 81} \
82static struct device_attribute dev_attr_spi_master_##field = { \ 82static struct device_attribute dev_attr_spi_controller_##field = { \
83 .attr = { .name = file, .mode = 0444 }, \ 83 .attr = { .name = file, .mode = 0444 }, \
84 .show = spi_master_##field##_show, \ 84 .show = spi_controller_##field##_show, \
85}; \ 85}; \
86static ssize_t spi_device_##field##_show(struct device *dev, \ 86static ssize_t spi_device_##field##_show(struct device *dev, \
87 struct device_attribute *attr, \ 87 struct device_attribute *attr, \
@@ -201,51 +201,51 @@ static const struct attribute_group *spi_dev_groups[] = {
201 NULL, 201 NULL,
202}; 202};
203 203
204static struct attribute *spi_master_statistics_attrs[] = { 204static struct attribute *spi_controller_statistics_attrs[] = {
205 &dev_attr_spi_master_messages.attr, 205 &dev_attr_spi_controller_messages.attr,
206 &dev_attr_spi_master_transfers.attr, 206 &dev_attr_spi_controller_transfers.attr,
207 &dev_attr_spi_master_errors.attr, 207 &dev_attr_spi_controller_errors.attr,
208 &dev_attr_spi_master_timedout.attr, 208 &dev_attr_spi_controller_timedout.attr,
209 &dev_attr_spi_master_spi_sync.attr, 209 &dev_attr_spi_controller_spi_sync.attr,
210 &dev_attr_spi_master_spi_sync_immediate.attr, 210 &dev_attr_spi_controller_spi_sync_immediate.attr,
211 &dev_attr_spi_master_spi_async.attr, 211 &dev_attr_spi_controller_spi_async.attr,
212 &dev_attr_spi_master_bytes.attr, 212 &dev_attr_spi_controller_bytes.attr,
213 &dev_attr_spi_master_bytes_rx.attr, 213 &dev_attr_spi_controller_bytes_rx.attr,
214 &dev_attr_spi_master_bytes_tx.attr, 214 &dev_attr_spi_controller_bytes_tx.attr,
215 &dev_attr_spi_master_transfer_bytes_histo0.attr, 215 &dev_attr_spi_controller_transfer_bytes_histo0.attr,
216 &dev_attr_spi_master_transfer_bytes_histo1.attr, 216 &dev_attr_spi_controller_transfer_bytes_histo1.attr,
217 &dev_attr_spi_master_transfer_bytes_histo2.attr, 217 &dev_attr_spi_controller_transfer_bytes_histo2.attr,
218 &dev_attr_spi_master_transfer_bytes_histo3.attr, 218 &dev_attr_spi_controller_transfer_bytes_histo3.attr,
219 &dev_attr_spi_master_transfer_bytes_histo4.attr, 219 &dev_attr_spi_controller_transfer_bytes_histo4.attr,
220 &dev_attr_spi_master_transfer_bytes_histo5.attr, 220 &dev_attr_spi_controller_transfer_bytes_histo5.attr,
221 &dev_attr_spi_master_transfer_bytes_histo6.attr, 221 &dev_attr_spi_controller_transfer_bytes_histo6.attr,
222 &dev_attr_spi_master_transfer_bytes_histo7.attr, 222 &dev_attr_spi_controller_transfer_bytes_histo7.attr,
223 &dev_attr_spi_master_transfer_bytes_histo8.attr, 223 &dev_attr_spi_controller_transfer_bytes_histo8.attr,
224 &dev_attr_spi_master_transfer_bytes_histo9.attr, 224 &dev_attr_spi_controller_transfer_bytes_histo9.attr,
225 &dev_attr_spi_master_transfer_bytes_histo10.attr, 225 &dev_attr_spi_controller_transfer_bytes_histo10.attr,
226 &dev_attr_spi_master_transfer_bytes_histo11.attr, 226 &dev_attr_spi_controller_transfer_bytes_histo11.attr,
227 &dev_attr_spi_master_transfer_bytes_histo12.attr, 227 &dev_attr_spi_controller_transfer_bytes_histo12.attr,
228 &dev_attr_spi_master_transfer_bytes_histo13.attr, 228 &dev_attr_spi_controller_transfer_bytes_histo13.attr,
229 &dev_attr_spi_master_transfer_bytes_histo14.attr, 229 &dev_attr_spi_controller_transfer_bytes_histo14.attr,
230 &dev_attr_spi_master_transfer_bytes_histo15.attr, 230 &dev_attr_spi_controller_transfer_bytes_histo15.attr,
231 &dev_attr_spi_master_transfer_bytes_histo16.attr, 231 &dev_attr_spi_controller_transfer_bytes_histo16.attr,
232 &dev_attr_spi_master_transfers_split_maxsize.attr, 232 &dev_attr_spi_controller_transfers_split_maxsize.attr,
233 NULL, 233 NULL,
234}; 234};
235 235
236static const struct attribute_group spi_master_statistics_group = { 236static const struct attribute_group spi_controller_statistics_group = {
237 .name = "statistics", 237 .name = "statistics",
238 .attrs = spi_master_statistics_attrs, 238 .attrs = spi_controller_statistics_attrs,
239}; 239};
240 240
241static const struct attribute_group *spi_master_groups[] = { 241static const struct attribute_group *spi_master_groups[] = {
242 &spi_master_statistics_group, 242 &spi_controller_statistics_group,
243 NULL, 243 NULL,
244}; 244};
245 245
246void spi_statistics_add_transfer_stats(struct spi_statistics *stats, 246void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
247 struct spi_transfer *xfer, 247 struct spi_transfer *xfer,
248 struct spi_master *master) 248 struct spi_controller *ctlr)
249{ 249{
250 unsigned long flags; 250 unsigned long flags;
251 int l2len = min(fls(xfer->len), SPI_STATISTICS_HISTO_SIZE) - 1; 251 int l2len = min(fls(xfer->len), SPI_STATISTICS_HISTO_SIZE) - 1;
@@ -260,10 +260,10 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
260 260
261 stats->bytes += xfer->len; 261 stats->bytes += xfer->len;
262 if ((xfer->tx_buf) && 262 if ((xfer->tx_buf) &&
263 (xfer->tx_buf != master->dummy_tx)) 263 (xfer->tx_buf != ctlr->dummy_tx))
264 stats->bytes_tx += xfer->len; 264 stats->bytes_tx += xfer->len;
265 if ((xfer->rx_buf) && 265 if ((xfer->rx_buf) &&
266 (xfer->rx_buf != master->dummy_rx)) 266 (xfer->rx_buf != ctlr->dummy_rx))
267 stats->bytes_rx += xfer->len; 267 stats->bytes_rx += xfer->len;
268 268
269 spin_unlock_irqrestore(&stats->lock, flags); 269 spin_unlock_irqrestore(&stats->lock, flags);
@@ -405,7 +405,7 @@ EXPORT_SYMBOL_GPL(__spi_register_driver);
405/*-------------------------------------------------------------------------*/ 405/*-------------------------------------------------------------------------*/
406 406
407/* SPI devices should normally not be created by SPI device drivers; that 407/* SPI devices should normally not be created by SPI device drivers; that
408 * would make them board-specific. Similarly with SPI master drivers. 408 * would make them board-specific. Similarly with SPI controller drivers.
409 * Device registration normally goes into like arch/.../mach.../board-YYY.c 409 * Device registration normally goes into like arch/.../mach.../board-YYY.c
410 * with other readonly (flashable) information about mainboard devices. 410 * with other readonly (flashable) information about mainboard devices.
411 */ 411 */
@@ -416,17 +416,17 @@ struct boardinfo {
416}; 416};
417 417
418static LIST_HEAD(board_list); 418static LIST_HEAD(board_list);
419static LIST_HEAD(spi_master_list); 419static LIST_HEAD(spi_controller_list);
420 420
421/* 421/*
422 * Used to protect add/del opertion for board_info list and 422 * Used to protect add/del opertion for board_info list and
423 * spi_master list, and their matching process 423 * spi_controller list, and their matching process
424 */ 424 */
425static DEFINE_MUTEX(board_lock); 425static DEFINE_MUTEX(board_lock);
426 426
427/** 427/**
428 * spi_alloc_device - Allocate a new SPI device 428 * spi_alloc_device - Allocate a new SPI device
429 * @master: Controller to which device is connected 429 * @ctlr: Controller to which device is connected
430 * Context: can sleep 430 * Context: can sleep
431 * 431 *
432 * Allows a driver to allocate and initialize a spi_device without 432 * Allows a driver to allocate and initialize a spi_device without
@@ -435,27 +435,27 @@ static DEFINE_MUTEX(board_lock);
435 * spi_add_device() on it. 435 * spi_add_device() on it.
436 * 436 *
437 * Caller is responsible to call spi_add_device() on the returned 437 * Caller is responsible to call spi_add_device() on the returned
438 * spi_device structure to add it to the SPI master. If the caller 438 * spi_device structure to add it to the SPI controller. If the caller
439 * needs to discard the spi_device without adding it, then it should 439 * needs to discard the spi_device without adding it, then it should
440 * call spi_dev_put() on it. 440 * call spi_dev_put() on it.
441 * 441 *
442 * Return: a pointer to the new device, or NULL. 442 * Return: a pointer to the new device, or NULL.
443 */ 443 */
444struct spi_device *spi_alloc_device(struct spi_master *master) 444struct spi_device *spi_alloc_device(struct spi_controller *ctlr)
445{ 445{
446 struct spi_device *spi; 446 struct spi_device *spi;
447 447
448 if (!spi_master_get(master)) 448 if (!spi_controller_get(ctlr))
449 return NULL; 449 return NULL;
450 450
451 spi = kzalloc(sizeof(*spi), GFP_KERNEL); 451 spi = kzalloc(sizeof(*spi), GFP_KERNEL);
452 if (!spi) { 452 if (!spi) {
453 spi_master_put(master); 453 spi_controller_put(ctlr);
454 return NULL; 454 return NULL;
455 } 455 }
456 456
457 spi->master = master; 457 spi->master = spi->controller = ctlr;
458 spi->dev.parent = &master->dev; 458 spi->dev.parent = &ctlr->dev;
459 spi->dev.bus = &spi_bus_type; 459 spi->dev.bus = &spi_bus_type;
460 spi->dev.release = spidev_release; 460 spi->dev.release = spidev_release;
461 spi->cs_gpio = -ENOENT; 461 spi->cs_gpio = -ENOENT;
@@ -476,7 +476,7 @@ static void spi_dev_set_name(struct spi_device *spi)
476 return; 476 return;
477 } 477 }
478 478
479 dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev), 479 dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->controller->dev),
480 spi->chip_select); 480 spi->chip_select);
481} 481}
482 482
@@ -485,7 +485,7 @@ static int spi_dev_check(struct device *dev, void *data)
485 struct spi_device *spi = to_spi_device(dev); 485 struct spi_device *spi = to_spi_device(dev);
486 struct spi_device *new_spi = data; 486 struct spi_device *new_spi = data;
487 487
488 if (spi->master == new_spi->master && 488 if (spi->controller == new_spi->controller &&
489 spi->chip_select == new_spi->chip_select) 489 spi->chip_select == new_spi->chip_select)
490 return -EBUSY; 490 return -EBUSY;
491 return 0; 491 return 0;
@@ -503,15 +503,14 @@ static int spi_dev_check(struct device *dev, void *data)
503int spi_add_device(struct spi_device *spi) 503int spi_add_device(struct spi_device *spi)
504{ 504{
505 static DEFINE_MUTEX(spi_add_lock); 505 static DEFINE_MUTEX(spi_add_lock);
506 struct spi_master *master = spi->master; 506 struct spi_controller *ctlr = spi->controller;
507 struct device *dev = master->dev.parent; 507 struct device *dev = ctlr->dev.parent;
508 int status; 508 int status;
509 509
510 /* Chipselects are numbered 0..max; validate. */ 510 /* Chipselects are numbered 0..max; validate. */
511 if (spi->chip_select >= master->num_chipselect) { 511 if (spi->chip_select >= ctlr->num_chipselect) {
512 dev_err(dev, "cs%d >= max %d\n", 512 dev_err(dev, "cs%d >= max %d\n", spi->chip_select,
513 spi->chip_select, 513 ctlr->num_chipselect);
514 master->num_chipselect);
515 return -EINVAL; 514 return -EINVAL;
516 } 515 }
517 516
@@ -531,8 +530,8 @@ int spi_add_device(struct spi_device *spi)
531 goto done; 530 goto done;
532 } 531 }
533 532
534 if (master->cs_gpios) 533 if (ctlr->cs_gpios)
535 spi->cs_gpio = master->cs_gpios[spi->chip_select]; 534 spi->cs_gpio = ctlr->cs_gpios[spi->chip_select];
536 535
537 /* Drivers may modify this initial i/o setup, but will 536 /* Drivers may modify this initial i/o setup, but will
538 * normally rely on the device being setup. Devices 537 * normally rely on the device being setup. Devices
@@ -561,7 +560,7 @@ EXPORT_SYMBOL_GPL(spi_add_device);
561 560
562/** 561/**
563 * spi_new_device - instantiate one new SPI device 562 * spi_new_device - instantiate one new SPI device
564 * @master: Controller to which device is connected 563 * @ctlr: Controller to which device is connected
565 * @chip: Describes the SPI device 564 * @chip: Describes the SPI device
566 * Context: can sleep 565 * Context: can sleep
567 * 566 *
@@ -573,7 +572,7 @@ EXPORT_SYMBOL_GPL(spi_add_device);
573 * 572 *
574 * Return: the new device, or NULL. 573 * Return: the new device, or NULL.
575 */ 574 */
576struct spi_device *spi_new_device(struct spi_master *master, 575struct spi_device *spi_new_device(struct spi_controller *ctlr,
577 struct spi_board_info *chip) 576 struct spi_board_info *chip)
578{ 577{
579 struct spi_device *proxy; 578 struct spi_device *proxy;
@@ -586,7 +585,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
586 * suggests syslogged diagnostics are best here (ugh). 585 * suggests syslogged diagnostics are best here (ugh).
587 */ 586 */
588 587
589 proxy = spi_alloc_device(master); 588 proxy = spi_alloc_device(ctlr);
590 if (!proxy) 589 if (!proxy)
591 return NULL; 590 return NULL;
592 591
@@ -604,7 +603,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
604 if (chip->properties) { 603 if (chip->properties) {
605 status = device_add_properties(&proxy->dev, chip->properties); 604 status = device_add_properties(&proxy->dev, chip->properties);
606 if (status) { 605 if (status) {
607 dev_err(&master->dev, 606 dev_err(&ctlr->dev,
608 "failed to add properties to '%s': %d\n", 607 "failed to add properties to '%s': %d\n",
609 chip->modalias, status); 608 chip->modalias, status);
610 goto err_dev_put; 609 goto err_dev_put;
@@ -631,7 +630,7 @@ EXPORT_SYMBOL_GPL(spi_new_device);
631 * @spi: spi_device to unregister 630 * @spi: spi_device to unregister
632 * 631 *
633 * Start making the passed SPI device vanish. Normally this would be handled 632 * Start making the passed SPI device vanish. Normally this would be handled
634 * by spi_unregister_master(). 633 * by spi_unregister_controller().
635 */ 634 */
636void spi_unregister_device(struct spi_device *spi) 635void spi_unregister_device(struct spi_device *spi)
637{ 636{
@@ -648,17 +647,17 @@ void spi_unregister_device(struct spi_device *spi)
648} 647}
649EXPORT_SYMBOL_GPL(spi_unregister_device); 648EXPORT_SYMBOL_GPL(spi_unregister_device);
650 649
651static void spi_match_master_to_boardinfo(struct spi_master *master, 650static void spi_match_controller_to_boardinfo(struct spi_controller *ctlr,
652 struct spi_board_info *bi) 651 struct spi_board_info *bi)
653{ 652{
654 struct spi_device *dev; 653 struct spi_device *dev;
655 654
656 if (master->bus_num != bi->bus_num) 655 if (ctlr->bus_num != bi->bus_num)
657 return; 656 return;
658 657
659 dev = spi_new_device(master, bi); 658 dev = spi_new_device(ctlr, bi);
660 if (!dev) 659 if (!dev)
661 dev_err(master->dev.parent, "can't create new device for %s\n", 660 dev_err(ctlr->dev.parent, "can't create new device for %s\n",
662 bi->modalias); 661 bi->modalias);
663} 662}
664 663
@@ -697,7 +696,7 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
697 return -ENOMEM; 696 return -ENOMEM;
698 697
699 for (i = 0; i < n; i++, bi++, info++) { 698 for (i = 0; i < n; i++, bi++, info++) {
700 struct spi_master *master; 699 struct spi_controller *ctlr;
701 700
702 memcpy(&bi->board_info, info, sizeof(*info)); 701 memcpy(&bi->board_info, info, sizeof(*info));
703 if (info->properties) { 702 if (info->properties) {
@@ -709,8 +708,9 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
709 708
710 mutex_lock(&board_lock); 709 mutex_lock(&board_lock);
711 list_add_tail(&bi->list, &board_list); 710 list_add_tail(&bi->list, &board_list);
712 list_for_each_entry(master, &spi_master_list, list) 711 list_for_each_entry(ctlr, &spi_controller_list, list)
713 spi_match_master_to_boardinfo(master, &bi->board_info); 712 spi_match_controller_to_boardinfo(ctlr,
713 &bi->board_info);
714 mutex_unlock(&board_lock); 714 mutex_unlock(&board_lock);
715 } 715 }
716 716
@@ -727,16 +727,16 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
727 if (gpio_is_valid(spi->cs_gpio)) { 727 if (gpio_is_valid(spi->cs_gpio)) {
728 gpio_set_value(spi->cs_gpio, !enable); 728 gpio_set_value(spi->cs_gpio, !enable);
729 /* Some SPI masters need both GPIO CS & slave_select */ 729 /* Some SPI masters need both GPIO CS & slave_select */
730 if ((spi->master->flags & SPI_MASTER_GPIO_SS) && 730 if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
731 spi->master->set_cs) 731 spi->controller->set_cs)
732 spi->master->set_cs(spi, !enable); 732 spi->controller->set_cs(spi, !enable);
733 } else if (spi->master->set_cs) { 733 } else if (spi->controller->set_cs) {
734 spi->master->set_cs(spi, !enable); 734 spi->controller->set_cs(spi, !enable);
735 } 735 }
736} 736}
737 737
738#ifdef CONFIG_HAS_DMA 738#ifdef CONFIG_HAS_DMA
739static int spi_map_buf(struct spi_master *master, struct device *dev, 739static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
740 struct sg_table *sgt, void *buf, size_t len, 740 struct sg_table *sgt, void *buf, size_t len,
741 enum dma_data_direction dir) 741 enum dma_data_direction dir)
742{ 742{
@@ -761,7 +761,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
761 desc_len = min_t(int, max_seg_size, PAGE_SIZE); 761 desc_len = min_t(int, max_seg_size, PAGE_SIZE);
762 sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len); 762 sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
763 } else if (virt_addr_valid(buf)) { 763 } else if (virt_addr_valid(buf)) {
764 desc_len = min_t(int, max_seg_size, master->max_dma_len); 764 desc_len = min_t(int, max_seg_size, ctlr->max_dma_len);
765 sgs = DIV_ROUND_UP(len, desc_len); 765 sgs = DIV_ROUND_UP(len, desc_len);
766 } else { 766 } else {
767 return -EINVAL; 767 return -EINVAL;
@@ -811,7 +811,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
811 return 0; 811 return 0;
812} 812}
813 813
814static void spi_unmap_buf(struct spi_master *master, struct device *dev, 814static void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev,
815 struct sg_table *sgt, enum dma_data_direction dir) 815 struct sg_table *sgt, enum dma_data_direction dir)
816{ 816{
817 if (sgt->orig_nents) { 817 if (sgt->orig_nents) {
@@ -820,31 +820,31 @@ static void spi_unmap_buf(struct spi_master *master, struct device *dev,
820 } 820 }
821} 821}
822 822
823static int __spi_map_msg(struct spi_master *master, struct spi_message *msg) 823static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
824{ 824{
825 struct device *tx_dev, *rx_dev; 825 struct device *tx_dev, *rx_dev;
826 struct spi_transfer *xfer; 826 struct spi_transfer *xfer;
827 int ret; 827 int ret;
828 828
829 if (!master->can_dma) 829 if (!ctlr->can_dma)
830 return 0; 830 return 0;
831 831
832 if (master->dma_tx) 832 if (ctlr->dma_tx)
833 tx_dev = master->dma_tx->device->dev; 833 tx_dev = ctlr->dma_tx->device->dev;
834 else 834 else
835 tx_dev = master->dev.parent; 835 tx_dev = ctlr->dev.parent;
836 836
837 if (master->dma_rx) 837 if (ctlr->dma_rx)
838 rx_dev = master->dma_rx->device->dev; 838 rx_dev = ctlr->dma_rx->device->dev;
839 else 839 else
840 rx_dev = master->dev.parent; 840 rx_dev = ctlr->dev.parent;
841 841
842 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 842 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
843 if (!master->can_dma(master, msg->spi, xfer)) 843 if (!ctlr->can_dma(ctlr, msg->spi, xfer))
844 continue; 844 continue;
845 845
846 if (xfer->tx_buf != NULL) { 846 if (xfer->tx_buf != NULL) {
847 ret = spi_map_buf(master, tx_dev, &xfer->tx_sg, 847 ret = spi_map_buf(ctlr, tx_dev, &xfer->tx_sg,
848 (void *)xfer->tx_buf, xfer->len, 848 (void *)xfer->tx_buf, xfer->len,
849 DMA_TO_DEVICE); 849 DMA_TO_DEVICE);
850 if (ret != 0) 850 if (ret != 0)
@@ -852,79 +852,78 @@ static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)
852 } 852 }
853 853
854 if (xfer->rx_buf != NULL) { 854 if (xfer->rx_buf != NULL) {
855 ret = spi_map_buf(master, rx_dev, &xfer->rx_sg, 855 ret = spi_map_buf(ctlr, rx_dev, &xfer->rx_sg,
856 xfer->rx_buf, xfer->len, 856 xfer->rx_buf, xfer->len,
857 DMA_FROM_DEVICE); 857 DMA_FROM_DEVICE);
858 if (ret != 0) { 858 if (ret != 0) {
859 spi_unmap_buf(master, tx_dev, &xfer->tx_sg, 859 spi_unmap_buf(ctlr, tx_dev, &xfer->tx_sg,
860 DMA_TO_DEVICE); 860 DMA_TO_DEVICE);
861 return ret; 861 return ret;
862 } 862 }
863 } 863 }
864 } 864 }
865 865
866 master->cur_msg_mapped = true; 866 ctlr->cur_msg_mapped = true;
867 867
868 return 0; 868 return 0;
869} 869}
870 870
871static int __spi_unmap_msg(struct spi_master *master, struct spi_message *msg) 871static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg)
872{ 872{
873 struct spi_transfer *xfer; 873 struct spi_transfer *xfer;
874 struct device *tx_dev, *rx_dev; 874 struct device *tx_dev, *rx_dev;
875 875
876 if (!master->cur_msg_mapped || !master->can_dma) 876 if (!ctlr->cur_msg_mapped || !ctlr->can_dma)
877 return 0; 877 return 0;
878 878
879 if (master->dma_tx) 879 if (ctlr->dma_tx)
880 tx_dev = master->dma_tx->device->dev; 880 tx_dev = ctlr->dma_tx->device->dev;
881 else 881 else
882 tx_dev = master->dev.parent; 882 tx_dev = ctlr->dev.parent;
883 883
884 if (master->dma_rx) 884 if (ctlr->dma_rx)
885 rx_dev = master->dma_rx->device->dev; 885 rx_dev = ctlr->dma_rx->device->dev;
886 else 886 else
887 rx_dev = master->dev.parent; 887 rx_dev = ctlr->dev.parent;
888 888
889 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 889 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
890 if (!master->can_dma(master, msg->spi, xfer)) 890 if (!ctlr->can_dma(ctlr, msg->spi, xfer))
891 continue; 891 continue;
892 892
893 spi_unmap_buf(master, rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); 893 spi_unmap_buf(ctlr, rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE);
894 spi_unmap_buf(master, tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); 894 spi_unmap_buf(ctlr, tx_dev, &xfer->tx_sg, DMA_TO_DEVICE);
895 } 895 }
896 896
897 return 0; 897 return 0;
898} 898}
899#else /* !CONFIG_HAS_DMA */ 899#else /* !CONFIG_HAS_DMA */
900static inline int spi_map_buf(struct spi_master *master, 900static inline int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
901 struct device *dev, struct sg_table *sgt, 901 struct sg_table *sgt, void *buf, size_t len,
902 void *buf, size_t len,
903 enum dma_data_direction dir) 902 enum dma_data_direction dir)
904{ 903{
905 return -EINVAL; 904 return -EINVAL;
906} 905}
907 906
908static inline void spi_unmap_buf(struct spi_master *master, 907static inline void spi_unmap_buf(struct spi_controller *ctlr,
909 struct device *dev, struct sg_table *sgt, 908 struct device *dev, struct sg_table *sgt,
910 enum dma_data_direction dir) 909 enum dma_data_direction dir)
911{ 910{
912} 911}
913 912
914static inline int __spi_map_msg(struct spi_master *master, 913static inline int __spi_map_msg(struct spi_controller *ctlr,
915 struct spi_message *msg) 914 struct spi_message *msg)
916{ 915{
917 return 0; 916 return 0;
918} 917}
919 918
920static inline int __spi_unmap_msg(struct spi_master *master, 919static inline int __spi_unmap_msg(struct spi_controller *ctlr,
921 struct spi_message *msg) 920 struct spi_message *msg)
922{ 921{
923 return 0; 922 return 0;
924} 923}
925#endif /* !CONFIG_HAS_DMA */ 924#endif /* !CONFIG_HAS_DMA */
926 925
927static inline int spi_unmap_msg(struct spi_master *master, 926static inline int spi_unmap_msg(struct spi_controller *ctlr,
928 struct spi_message *msg) 927 struct spi_message *msg)
929{ 928{
930 struct spi_transfer *xfer; 929 struct spi_transfer *xfer;
@@ -934,63 +933,63 @@ static inline int spi_unmap_msg(struct spi_master *master,
934 * Restore the original value of tx_buf or rx_buf if they are 933 * Restore the original value of tx_buf or rx_buf if they are
935 * NULL. 934 * NULL.
936 */ 935 */
937 if (xfer->tx_buf == master->dummy_tx) 936 if (xfer->tx_buf == ctlr->dummy_tx)
938 xfer->tx_buf = NULL; 937 xfer->tx_buf = NULL;
939 if (xfer->rx_buf == master->dummy_rx) 938 if (xfer->rx_buf == ctlr->dummy_rx)
940 xfer->rx_buf = NULL; 939 xfer->rx_buf = NULL;
941 } 940 }
942 941
943 return __spi_unmap_msg(master, msg); 942 return __spi_unmap_msg(ctlr, msg);
944} 943}
945 944
946static int spi_map_msg(struct spi_master *master, struct spi_message *msg) 945static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
947{ 946{
948 struct spi_transfer *xfer; 947 struct spi_transfer *xfer;
949 void *tmp; 948 void *tmp;
950 unsigned int max_tx, max_rx; 949 unsigned int max_tx, max_rx;
951 950
952 if (master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) { 951 if (ctlr->flags & (SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX)) {
953 max_tx = 0; 952 max_tx = 0;
954 max_rx = 0; 953 max_rx = 0;
955 954
956 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 955 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
957 if ((master->flags & SPI_MASTER_MUST_TX) && 956 if ((ctlr->flags & SPI_CONTROLLER_MUST_TX) &&
958 !xfer->tx_buf) 957 !xfer->tx_buf)
959 max_tx = max(xfer->len, max_tx); 958 max_tx = max(xfer->len, max_tx);
960 if ((master->flags & SPI_MASTER_MUST_RX) && 959 if ((ctlr->flags & SPI_CONTROLLER_MUST_RX) &&
961 !xfer->rx_buf) 960 !xfer->rx_buf)
962 max_rx = max(xfer->len, max_rx); 961 max_rx = max(xfer->len, max_rx);
963 } 962 }
964 963
965 if (max_tx) { 964 if (max_tx) {
966 tmp = krealloc(master->dummy_tx, max_tx, 965 tmp = krealloc(ctlr->dummy_tx, max_tx,
967 GFP_KERNEL | GFP_DMA); 966 GFP_KERNEL | GFP_DMA);
968 if (!tmp) 967 if (!tmp)
969 return -ENOMEM; 968 return -ENOMEM;
970 master->dummy_tx = tmp; 969 ctlr->dummy_tx = tmp;
971 memset(tmp, 0, max_tx); 970 memset(tmp, 0, max_tx);
972 } 971 }
973 972
974 if (max_rx) { 973 if (max_rx) {
975 tmp = krealloc(master->dummy_rx, max_rx, 974 tmp = krealloc(ctlr->dummy_rx, max_rx,
976 GFP_KERNEL | GFP_DMA); 975 GFP_KERNEL | GFP_DMA);
977 if (!tmp) 976 if (!tmp)
978 return -ENOMEM; 977 return -ENOMEM;
979 master->dummy_rx = tmp; 978 ctlr->dummy_rx = tmp;
980 } 979 }
981 980
982 if (max_tx || max_rx) { 981 if (max_tx || max_rx) {
983 list_for_each_entry(xfer, &msg->transfers, 982 list_for_each_entry(xfer, &msg->transfers,
984 transfer_list) { 983 transfer_list) {
985 if (!xfer->tx_buf) 984 if (!xfer->tx_buf)
986 xfer->tx_buf = master->dummy_tx; 985 xfer->tx_buf = ctlr->dummy_tx;
987 if (!xfer->rx_buf) 986 if (!xfer->rx_buf)
988 xfer->rx_buf = master->dummy_rx; 987 xfer->rx_buf = ctlr->dummy_rx;
989 } 988 }
990 } 989 }
991 } 990 }
992 991
993 return __spi_map_msg(master, msg); 992 return __spi_map_msg(ctlr, msg);
994} 993}
995 994
996/* 995/*
@@ -1000,14 +999,14 @@ static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
1000 * drivers which implement a transfer_one() operation. It provides 999 * drivers which implement a transfer_one() operation. It provides
1001 * standard handling of delays and chip select management. 1000 * standard handling of delays and chip select management.
1002 */ 1001 */
1003static int spi_transfer_one_message(struct spi_master *master, 1002static int spi_transfer_one_message(struct spi_controller *ctlr,
1004 struct spi_message *msg) 1003 struct spi_message *msg)
1005{ 1004{
1006 struct spi_transfer *xfer; 1005 struct spi_transfer *xfer;
1007 bool keep_cs = false; 1006 bool keep_cs = false;
1008 int ret = 0; 1007 int ret = 0;
1009 unsigned long long ms = 1; 1008 unsigned long long ms = 1;
1010 struct spi_statistics *statm = &master->statistics; 1009 struct spi_statistics *statm = &ctlr->statistics;
1011 struct spi_statistics *stats = &msg->spi->statistics; 1010 struct spi_statistics *stats = &msg->spi->statistics;
1012 1011
1013 spi_set_cs(msg->spi, true); 1012 spi_set_cs(msg->spi, true);
@@ -1018,13 +1017,13 @@ static int spi_transfer_one_message(struct spi_master *master,
1018 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 1017 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
1019 trace_spi_transfer_start(msg, xfer); 1018 trace_spi_transfer_start(msg, xfer);
1020 1019
1021 spi_statistics_add_transfer_stats(statm, xfer, master); 1020 spi_statistics_add_transfer_stats(statm, xfer, ctlr);
1022 spi_statistics_add_transfer_stats(stats, xfer, master); 1021 spi_statistics_add_transfer_stats(stats, xfer, ctlr);
1023 1022
1024 if (xfer->tx_buf || xfer->rx_buf) { 1023 if (xfer->tx_buf || xfer->rx_buf) {
1025 reinit_completion(&master->xfer_completion); 1024 reinit_completion(&ctlr->xfer_completion);
1026 1025
1027 ret = master->transfer_one(master, msg->spi, xfer); 1026 ret = ctlr->transfer_one(ctlr, msg->spi, xfer);
1028 if (ret < 0) { 1027 if (ret < 0) {
1029 SPI_STATISTICS_INCREMENT_FIELD(statm, 1028 SPI_STATISTICS_INCREMENT_FIELD(statm,
1030 errors); 1029 errors);
@@ -1044,7 +1043,7 @@ static int spi_transfer_one_message(struct spi_master *master,
1044 if (ms > UINT_MAX) 1043 if (ms > UINT_MAX)
1045 ms = UINT_MAX; 1044 ms = UINT_MAX;
1046 1045
1047 ms = wait_for_completion_timeout(&master->xfer_completion, 1046 ms = wait_for_completion_timeout(&ctlr->xfer_completion,
1048 msecs_to_jiffies(ms)); 1047 msecs_to_jiffies(ms));
1049 } 1048 }
1050 1049
@@ -1099,33 +1098,33 @@ out:
1099 if (msg->status == -EINPROGRESS) 1098 if (msg->status == -EINPROGRESS)
1100 msg->status = ret; 1099 msg->status = ret;
1101 1100
1102 if (msg->status && master->handle_err) 1101 if (msg->status && ctlr->handle_err)
1103 master->handle_err(master, msg); 1102 ctlr->handle_err(ctlr, msg);
1104 1103
1105 spi_res_release(master, msg); 1104 spi_res_release(ctlr, msg);
1106 1105
1107 spi_finalize_current_message(master); 1106 spi_finalize_current_message(ctlr);
1108 1107
1109 return ret; 1108 return ret;
1110} 1109}
1111 1110
1112/** 1111/**
1113 * spi_finalize_current_transfer - report completion of a transfer 1112 * spi_finalize_current_transfer - report completion of a transfer
1114 * @master: the master reporting completion 1113 * @ctlr: the controller reporting completion
1115 * 1114 *
1116 * Called by SPI drivers using the core transfer_one_message() 1115 * Called by SPI drivers using the core transfer_one_message()
1117 * implementation to notify it that the current interrupt driven 1116 * implementation to notify it that the current interrupt driven
1118 * transfer has finished and the next one may be scheduled. 1117 * transfer has finished and the next one may be scheduled.
1119 */ 1118 */
1120void spi_finalize_current_transfer(struct spi_master *master) 1119void spi_finalize_current_transfer(struct spi_controller *ctlr)
1121{ 1120{
1122 complete(&master->xfer_completion); 1121 complete(&ctlr->xfer_completion);
1123} 1122}
1124EXPORT_SYMBOL_GPL(spi_finalize_current_transfer); 1123EXPORT_SYMBOL_GPL(spi_finalize_current_transfer);
1125 1124
1126/** 1125/**
1127 * __spi_pump_messages - function which processes spi message queue 1126 * __spi_pump_messages - function which processes spi message queue
1128 * @master: master to process queue for 1127 * @ctlr: controller to process queue for
1129 * @in_kthread: true if we are in the context of the message pump thread 1128 * @in_kthread: true if we are in the context of the message pump thread
1130 * 1129 *
1131 * This function checks if there is any spi message in the queue that 1130 * This function checks if there is any spi message in the queue that
@@ -1136,136 +1135,136 @@ EXPORT_SYMBOL_GPL(spi_finalize_current_transfer);
1136 * inside spi_sync(); the queue extraction handling at the top of the 1135 * inside spi_sync(); the queue extraction handling at the top of the
1137 * function should deal with this safely. 1136 * function should deal with this safely.
1138 */ 1137 */
1139static void __spi_pump_messages(struct spi_master *master, bool in_kthread) 1138static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
1140{ 1139{
1141 unsigned long flags; 1140 unsigned long flags;
1142 bool was_busy = false; 1141 bool was_busy = false;
1143 int ret; 1142 int ret;
1144 1143
1145 /* Lock queue */ 1144 /* Lock queue */
1146 spin_lock_irqsave(&master->queue_lock, flags); 1145 spin_lock_irqsave(&ctlr->queue_lock, flags);
1147 1146
1148 /* Make sure we are not already running a message */ 1147 /* Make sure we are not already running a message */
1149 if (master->cur_msg) { 1148 if (ctlr->cur_msg) {
1150 spin_unlock_irqrestore(&master->queue_lock, flags); 1149 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1151 return; 1150 return;
1152 } 1151 }
1153 1152
1154 /* If another context is idling the device then defer */ 1153 /* If another context is idling the device then defer */
1155 if (master->idling) { 1154 if (ctlr->idling) {
1156 kthread_queue_work(&master->kworker, &master->pump_messages); 1155 kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1157 spin_unlock_irqrestore(&master->queue_lock, flags); 1156 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1158 return; 1157 return;
1159 } 1158 }
1160 1159
1161 /* Check if the queue is idle */ 1160 /* Check if the queue is idle */
1162 if (list_empty(&master->queue) || !master->running) { 1161 if (list_empty(&ctlr->queue) || !ctlr->running) {
1163 if (!master->busy) { 1162 if (!ctlr->busy) {
1164 spin_unlock_irqrestore(&master->queue_lock, flags); 1163 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1165 return; 1164 return;
1166 } 1165 }
1167 1166
1168 /* Only do teardown in the thread */ 1167 /* Only do teardown in the thread */
1169 if (!in_kthread) { 1168 if (!in_kthread) {
1170 kthread_queue_work(&master->kworker, 1169 kthread_queue_work(&ctlr->kworker,
1171 &master->pump_messages); 1170 &ctlr->pump_messages);
1172 spin_unlock_irqrestore(&master->queue_lock, flags); 1171 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1173 return; 1172 return;
1174 } 1173 }
1175 1174
1176 master->busy = false; 1175 ctlr->busy = false;
1177 master->idling = true; 1176 ctlr->idling = true;
1178 spin_unlock_irqrestore(&master->queue_lock, flags); 1177 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1179 1178
1180 kfree(master->dummy_rx); 1179 kfree(ctlr->dummy_rx);
1181 master->dummy_rx = NULL; 1180 ctlr->dummy_rx = NULL;
1182 kfree(master->dummy_tx); 1181 kfree(ctlr->dummy_tx);
1183 master->dummy_tx = NULL; 1182 ctlr->dummy_tx = NULL;
1184 if (master->unprepare_transfer_hardware && 1183 if (ctlr->unprepare_transfer_hardware &&
1185 master->unprepare_transfer_hardware(master)) 1184 ctlr->unprepare_transfer_hardware(ctlr))
1186 dev_err(&master->dev, 1185 dev_err(&ctlr->dev,
1187 "failed to unprepare transfer hardware\n"); 1186 "failed to unprepare transfer hardware\n");
1188 if (master->auto_runtime_pm) { 1187 if (ctlr->auto_runtime_pm) {
1189 pm_runtime_mark_last_busy(master->dev.parent); 1188 pm_runtime_mark_last_busy(ctlr->dev.parent);
1190 pm_runtime_put_autosuspend(master->dev.parent); 1189 pm_runtime_put_autosuspend(ctlr->dev.parent);
1191 } 1190 }
1192 trace_spi_master_idle(master); 1191 trace_spi_controller_idle(ctlr);
1193 1192
1194 spin_lock_irqsave(&master->queue_lock, flags); 1193 spin_lock_irqsave(&ctlr->queue_lock, flags);
1195 master->idling = false; 1194 ctlr->idling = false;
1196 spin_unlock_irqrestore(&master->queue_lock, flags); 1195 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1197 return; 1196 return;
1198 } 1197 }
1199 1198
1200 /* Extract head of queue */ 1199 /* Extract head of queue */
1201 master->cur_msg = 1200 ctlr->cur_msg =
1202 list_first_entry(&master->queue, struct spi_message, queue); 1201 list_first_entry(&ctlr->queue, struct spi_message, queue);
1203 1202
1204 list_del_init(&master->cur_msg->queue); 1203 list_del_init(&ctlr->cur_msg->queue);
1205 if (master->busy) 1204 if (ctlr->busy)
1206 was_busy = true; 1205 was_busy = true;
1207 else 1206 else
1208 master->busy = true; 1207 ctlr->busy = true;
1209 spin_unlock_irqrestore(&master->queue_lock, flags); 1208 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1210 1209
1211 mutex_lock(&master->io_mutex); 1210 mutex_lock(&ctlr->io_mutex);
1212 1211
1213 if (!was_busy && master->auto_runtime_pm) { 1212 if (!was_busy && ctlr->auto_runtime_pm) {
1214 ret = pm_runtime_get_sync(master->dev.parent); 1213 ret = pm_runtime_get_sync(ctlr->dev.parent);
1215 if (ret < 0) { 1214 if (ret < 0) {
1216 dev_err(&master->dev, "Failed to power device: %d\n", 1215 dev_err(&ctlr->dev, "Failed to power device: %d\n",
1217 ret); 1216 ret);
1218 mutex_unlock(&master->io_mutex); 1217 mutex_unlock(&ctlr->io_mutex);
1219 return; 1218 return;
1220 } 1219 }
1221 } 1220 }
1222 1221
1223 if (!was_busy) 1222 if (!was_busy)
1224 trace_spi_master_busy(master); 1223 trace_spi_controller_busy(ctlr);
1225 1224
1226 if (!was_busy && master->prepare_transfer_hardware) { 1225 if (!was_busy && ctlr->prepare_transfer_hardware) {
1227 ret = master->prepare_transfer_hardware(master); 1226 ret = ctlr->prepare_transfer_hardware(ctlr);
1228 if (ret) { 1227 if (ret) {
1229 dev_err(&master->dev, 1228 dev_err(&ctlr->dev,
1230 "failed to prepare transfer hardware\n"); 1229 "failed to prepare transfer hardware\n");
1231 1230
1232 if (master->auto_runtime_pm) 1231 if (ctlr->auto_runtime_pm)
1233 pm_runtime_put(master->dev.parent); 1232 pm_runtime_put(ctlr->dev.parent);
1234 mutex_unlock(&master->io_mutex); 1233 mutex_unlock(&ctlr->io_mutex);
1235 return; 1234 return;
1236 } 1235 }
1237 } 1236 }
1238 1237
1239 trace_spi_message_start(master->cur_msg); 1238 trace_spi_message_start(ctlr->cur_msg);
1240 1239
1241 if (master->prepare_message) { 1240 if (ctlr->prepare_message) {
1242 ret = master->prepare_message(master, master->cur_msg); 1241 ret = ctlr->prepare_message(ctlr, ctlr->cur_msg);
1243 if (ret) { 1242 if (ret) {
1244 dev_err(&master->dev, 1243 dev_err(&ctlr->dev, "failed to prepare message: %d\n",
1245 "failed to prepare message: %d\n", ret); 1244 ret);
1246 master->cur_msg->status = ret; 1245 ctlr->cur_msg->status = ret;
1247 spi_finalize_current_message(master); 1246 spi_finalize_current_message(ctlr);
1248 goto out; 1247 goto out;
1249 } 1248 }
1250 master->cur_msg_prepared = true; 1249 ctlr->cur_msg_prepared = true;
1251 } 1250 }
1252 1251
1253 ret = spi_map_msg(master, master->cur_msg); 1252 ret = spi_map_msg(ctlr, ctlr->cur_msg);
1254 if (ret) { 1253 if (ret) {
1255 master->cur_msg->status = ret; 1254 ctlr->cur_msg->status = ret;
1256 spi_finalize_current_message(master); 1255 spi_finalize_current_message(ctlr);
1257 goto out; 1256 goto out;
1258 } 1257 }
1259 1258
1260 ret = master->transfer_one_message(master, master->cur_msg); 1259 ret = ctlr->transfer_one_message(ctlr, ctlr->cur_msg);
1261 if (ret) { 1260 if (ret) {
1262 dev_err(&master->dev, 1261 dev_err(&ctlr->dev,
1263 "failed to transfer one message from queue\n"); 1262 "failed to transfer one message from queue\n");
1264 goto out; 1263 goto out;
1265 } 1264 }
1266 1265
1267out: 1266out:
1268 mutex_unlock(&master->io_mutex); 1267 mutex_unlock(&ctlr->io_mutex);
1269 1268
1270 /* Prod the scheduler in case transfer_one() was busy waiting */ 1269 /* Prod the scheduler in case transfer_one() was busy waiting */
1271 if (!ret) 1270 if (!ret)
@@ -1274,44 +1273,43 @@ out:
1274 1273
1275/** 1274/**
1276 * spi_pump_messages - kthread work function which processes spi message queue 1275 * spi_pump_messages - kthread work function which processes spi message queue
1277 * @work: pointer to kthread work struct contained in the master struct 1276 * @work: pointer to kthread work struct contained in the controller struct
1278 */ 1277 */
1279static void spi_pump_messages(struct kthread_work *work) 1278static void spi_pump_messages(struct kthread_work *work)
1280{ 1279{
1281 struct spi_master *master = 1280 struct spi_controller *ctlr =
1282 container_of(work, struct spi_master, pump_messages); 1281 container_of(work, struct spi_controller, pump_messages);
1283 1282
1284 __spi_pump_messages(master, true); 1283 __spi_pump_messages(ctlr, true);
1285} 1284}
1286 1285
1287static int spi_init_queue(struct spi_master *master) 1286static int spi_init_queue(struct spi_controller *ctlr)
1288{ 1287{
1289 struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 }; 1288 struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
1290 1289
1291 master->running = false; 1290 ctlr->running = false;
1292 master->busy = false; 1291 ctlr->busy = false;
1293 1292
1294 kthread_init_worker(&master->kworker); 1293 kthread_init_worker(&ctlr->kworker);
1295 master->kworker_task = kthread_run(kthread_worker_fn, 1294 ctlr->kworker_task = kthread_run(kthread_worker_fn, &ctlr->kworker,
1296 &master->kworker, "%s", 1295 "%s", dev_name(&ctlr->dev));
1297 dev_name(&master->dev)); 1296 if (IS_ERR(ctlr->kworker_task)) {
1298 if (IS_ERR(master->kworker_task)) { 1297 dev_err(&ctlr->dev, "failed to create message pump task\n");
1299 dev_err(&master->dev, "failed to create message pump task\n"); 1298 return PTR_ERR(ctlr->kworker_task);
1300 return PTR_ERR(master->kworker_task);
1301 } 1299 }
1302 kthread_init_work(&master->pump_messages, spi_pump_messages); 1300 kthread_init_work(&ctlr->pump_messages, spi_pump_messages);
1303 1301
1304 /* 1302 /*
1305 * Master config will indicate if this controller should run the 1303 * Controller config will indicate if this controller should run the
1306 * message pump with high (realtime) priority to reduce the transfer 1304 * message pump with high (realtime) priority to reduce the transfer
1307 * latency on the bus by minimising the delay between a transfer 1305 * latency on the bus by minimising the delay between a transfer
1308 * request and the scheduling of the message pump thread. Without this 1306 * request and the scheduling of the message pump thread. Without this
1309 * setting the message pump thread will remain at default priority. 1307 * setting the message pump thread will remain at default priority.
1310 */ 1308 */
1311 if (master->rt) { 1309 if (ctlr->rt) {
1312 dev_info(&master->dev, 1310 dev_info(&ctlr->dev,
1313 "will run message pump with realtime priority\n"); 1311 "will run message pump with realtime priority\n");
1314 sched_setscheduler(master->kworker_task, SCHED_FIFO, &param); 1312 sched_setscheduler(ctlr->kworker_task, SCHED_FIFO, &param);
1315 } 1313 }
1316 1314
1317 return 0; 1315 return 0;
@@ -1320,23 +1318,23 @@ static int spi_init_queue(struct spi_master *master)
1320/** 1318/**
1321 * spi_get_next_queued_message() - called by driver to check for queued 1319 * spi_get_next_queued_message() - called by driver to check for queued
1322 * messages 1320 * messages
1323 * @master: the master to check for queued messages 1321 * @ctlr: the controller to check for queued messages
1324 * 1322 *
1325 * If there are more messages in the queue, the next message is returned from 1323 * If there are more messages in the queue, the next message is returned from
1326 * this call. 1324 * this call.
1327 * 1325 *
1328 * Return: the next message in the queue, else NULL if the queue is empty. 1326 * Return: the next message in the queue, else NULL if the queue is empty.
1329 */ 1327 */
1330struct spi_message *spi_get_next_queued_message(struct spi_master *master) 1328struct spi_message *spi_get_next_queued_message(struct spi_controller *ctlr)
1331{ 1329{
1332 struct spi_message *next; 1330 struct spi_message *next;
1333 unsigned long flags; 1331 unsigned long flags;
1334 1332
1335 /* get a pointer to the next message, if any */ 1333 /* get a pointer to the next message, if any */
1336 spin_lock_irqsave(&master->queue_lock, flags); 1334 spin_lock_irqsave(&ctlr->queue_lock, flags);
1337 next = list_first_entry_or_null(&master->queue, struct spi_message, 1335 next = list_first_entry_or_null(&ctlr->queue, struct spi_message,
1338 queue); 1336 queue);
1339 spin_unlock_irqrestore(&master->queue_lock, flags); 1337 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1340 1338
1341 return next; 1339 return next;
1342} 1340}
@@ -1344,36 +1342,36 @@ EXPORT_SYMBOL_GPL(spi_get_next_queued_message);
1344 1342
1345/** 1343/**
1346 * spi_finalize_current_message() - the current message is complete 1344 * spi_finalize_current_message() - the current message is complete
1347 * @master: the master to return the message to 1345 * @ctlr: the controller to return the message to
1348 * 1346 *
1349 * Called by the driver to notify the core that the message in the front of the 1347 * Called by the driver to notify the core that the message in the front of the
1350 * queue is complete and can be removed from the queue. 1348 * queue is complete and can be removed from the queue.
1351 */ 1349 */
1352void spi_finalize_current_message(struct spi_master *master) 1350void spi_finalize_current_message(struct spi_controller *ctlr)
1353{ 1351{
1354 struct spi_message *mesg; 1352 struct spi_message *mesg;
1355 unsigned long flags; 1353 unsigned long flags;
1356 int ret; 1354 int ret;
1357 1355
1358 spin_lock_irqsave(&master->queue_lock, flags); 1356 spin_lock_irqsave(&ctlr->queue_lock, flags);
1359 mesg = master->cur_msg; 1357 mesg = ctlr->cur_msg;
1360 spin_unlock_irqrestore(&master->queue_lock, flags); 1358 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1361 1359
1362 spi_unmap_msg(master, mesg); 1360 spi_unmap_msg(ctlr, mesg);
1363 1361
1364 if (master->cur_msg_prepared && master->unprepare_message) { 1362 if (ctlr->cur_msg_prepared && ctlr->unprepare_message) {
1365 ret = master->unprepare_message(master, mesg); 1363 ret = ctlr->unprepare_message(ctlr, mesg);
1366 if (ret) { 1364 if (ret) {
1367 dev_err(&master->dev, 1365 dev_err(&ctlr->dev, "failed to unprepare message: %d\n",
1368 "failed to unprepare message: %d\n", ret); 1366 ret);
1369 } 1367 }
1370 } 1368 }
1371 1369
1372 spin_lock_irqsave(&master->queue_lock, flags); 1370 spin_lock_irqsave(&ctlr->queue_lock, flags);
1373 master->cur_msg = NULL; 1371 ctlr->cur_msg = NULL;
1374 master->cur_msg_prepared = false; 1372 ctlr->cur_msg_prepared = false;
1375 kthread_queue_work(&master->kworker, &master->pump_messages); 1373 kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1376 spin_unlock_irqrestore(&master->queue_lock, flags); 1374 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1377 1375
1378 trace_spi_message_done(mesg); 1376 trace_spi_message_done(mesg);
1379 1377
@@ -1383,66 +1381,65 @@ void spi_finalize_current_message(struct spi_master *master)
1383} 1381}
1384EXPORT_SYMBOL_GPL(spi_finalize_current_message); 1382EXPORT_SYMBOL_GPL(spi_finalize_current_message);
1385 1383
1386static int spi_start_queue(struct spi_master *master) 1384static int spi_start_queue(struct spi_controller *ctlr)
1387{ 1385{
1388 unsigned long flags; 1386 unsigned long flags;
1389 1387
1390 spin_lock_irqsave(&master->queue_lock, flags); 1388 spin_lock_irqsave(&ctlr->queue_lock, flags);
1391 1389
1392 if (master->running || master->busy) { 1390 if (ctlr->running || ctlr->busy) {
1393 spin_unlock_irqrestore(&master->queue_lock, flags); 1391 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1394 return -EBUSY; 1392 return -EBUSY;
1395 } 1393 }
1396 1394
1397 master->running = true; 1395 ctlr->running = true;
1398 master->cur_msg = NULL; 1396 ctlr->cur_msg = NULL;
1399 spin_unlock_irqrestore(&master->queue_lock, flags); 1397 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1400 1398
1401 kthread_queue_work(&master->kworker, &master->pump_messages); 1399 kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1402 1400
1403 return 0; 1401 return 0;
1404} 1402}
1405 1403
1406static int spi_stop_queue(struct spi_master *master) 1404static int spi_stop_queue(struct spi_controller *ctlr)
1407{ 1405{
1408 unsigned long flags; 1406 unsigned long flags;
1409 unsigned limit = 500; 1407 unsigned limit = 500;
1410 int ret = 0; 1408 int ret = 0;
1411 1409
1412 spin_lock_irqsave(&master->queue_lock, flags); 1410 spin_lock_irqsave(&ctlr->queue_lock, flags);
1413 1411
1414 /* 1412 /*
1415 * This is a bit lame, but is optimized for the common execution path. 1413 * This is a bit lame, but is optimized for the common execution path.
1416 * A wait_queue on the master->busy could be used, but then the common 1414 * A wait_queue on the ctlr->busy could be used, but then the common
1417 * execution path (pump_messages) would be required to call wake_up or 1415 * execution path (pump_messages) would be required to call wake_up or
1418 * friends on every SPI message. Do this instead. 1416 * friends on every SPI message. Do this instead.
1419 */ 1417 */
1420 while ((!list_empty(&master->queue) || master->busy) && limit--) { 1418 while ((!list_empty(&ctlr->queue) || ctlr->busy) && limit--) {
1421 spin_unlock_irqrestore(&master->queue_lock, flags); 1419 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1422 usleep_range(10000, 11000); 1420 usleep_range(10000, 11000);
1423 spin_lock_irqsave(&master->queue_lock, flags); 1421 spin_lock_irqsave(&ctlr->queue_lock, flags);
1424 } 1422 }
1425 1423
1426 if (!list_empty(&master->queue) || master->busy) 1424 if (!list_empty(&ctlr->queue) || ctlr->busy)
1427 ret = -EBUSY; 1425 ret = -EBUSY;
1428 else 1426 else
1429 master->running = false; 1427 ctlr->running = false;
1430 1428
1431 spin_unlock_irqrestore(&master->queue_lock, flags); 1429 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1432 1430
1433 if (ret) { 1431 if (ret) {
1434 dev_warn(&master->dev, 1432 dev_warn(&ctlr->dev, "could not stop message queue\n");
1435 "could not stop message queue\n");
1436 return ret; 1433 return ret;
1437 } 1434 }
1438 return ret; 1435 return ret;
1439} 1436}
1440 1437
1441static int spi_destroy_queue(struct spi_master *master) 1438static int spi_destroy_queue(struct spi_controller *ctlr)
1442{ 1439{
1443 int ret; 1440 int ret;
1444 1441
1445 ret = spi_stop_queue(master); 1442 ret = spi_stop_queue(ctlr);
1446 1443
1447 /* 1444 /*
1448 * kthread_flush_worker will block until all work is done. 1445 * kthread_flush_worker will block until all work is done.
@@ -1451,12 +1448,12 @@ static int spi_destroy_queue(struct spi_master *master)
1451 * return anyway. 1448 * return anyway.
1452 */ 1449 */
1453 if (ret) { 1450 if (ret) {
1454 dev_err(&master->dev, "problem destroying queue\n"); 1451 dev_err(&ctlr->dev, "problem destroying queue\n");
1455 return ret; 1452 return ret;
1456 } 1453 }
1457 1454
1458 kthread_flush_worker(&master->kworker); 1455 kthread_flush_worker(&ctlr->kworker);
1459 kthread_stop(master->kworker_task); 1456 kthread_stop(ctlr->kworker_task);
1460 1457
1461 return 0; 1458 return 0;
1462} 1459}
@@ -1465,23 +1462,23 @@ static int __spi_queued_transfer(struct spi_device *spi,
1465 struct spi_message *msg, 1462 struct spi_message *msg,
1466 bool need_pump) 1463 bool need_pump)
1467{ 1464{
1468 struct spi_master *master = spi->master; 1465 struct spi_controller *ctlr = spi->controller;
1469 unsigned long flags; 1466 unsigned long flags;
1470 1467
1471 spin_lock_irqsave(&master->queue_lock, flags); 1468 spin_lock_irqsave(&ctlr->queue_lock, flags);
1472 1469
1473 if (!master->running) { 1470 if (!ctlr->running) {
1474 spin_unlock_irqrestore(&master->queue_lock, flags); 1471 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1475 return -ESHUTDOWN; 1472 return -ESHUTDOWN;
1476 } 1473 }
1477 msg->actual_length = 0; 1474 msg->actual_length = 0;
1478 msg->status = -EINPROGRESS; 1475 msg->status = -EINPROGRESS;
1479 1476
1480 list_add_tail(&msg->queue, &master->queue); 1477 list_add_tail(&msg->queue, &ctlr->queue);
1481 if (!master->busy && need_pump) 1478 if (!ctlr->busy && need_pump)
1482 kthread_queue_work(&master->kworker, &master->pump_messages); 1479 kthread_queue_work(&ctlr->kworker, &ctlr->pump_messages);
1483 1480
1484 spin_unlock_irqrestore(&master->queue_lock, flags); 1481 spin_unlock_irqrestore(&ctlr->queue_lock, flags);
1485 return 0; 1482 return 0;
1486} 1483}
1487 1484
@@ -1497,31 +1494,31 @@ static int spi_queued_transfer(struct spi_device *spi, struct spi_message *msg)
1497 return __spi_queued_transfer(spi, msg, true); 1494 return __spi_queued_transfer(spi, msg, true);
1498} 1495}
1499 1496
1500static int spi_master_initialize_queue(struct spi_master *master) 1497static int spi_controller_initialize_queue(struct spi_controller *ctlr)
1501{ 1498{
1502 int ret; 1499 int ret;
1503 1500
1504 master->transfer = spi_queued_transfer; 1501 ctlr->transfer = spi_queued_transfer;
1505 if (!master->transfer_one_message) 1502 if (!ctlr->transfer_one_message)
1506 master->transfer_one_message = spi_transfer_one_message; 1503 ctlr->transfer_one_message = spi_transfer_one_message;
1507 1504
1508 /* Initialize and start queue */ 1505 /* Initialize and start queue */
1509 ret = spi_init_queue(master); 1506 ret = spi_init_queue(ctlr);
1510 if (ret) { 1507 if (ret) {
1511 dev_err(&master->dev, "problem initializing queue\n"); 1508 dev_err(&ctlr->dev, "problem initializing queue\n");
1512 goto err_init_queue; 1509 goto err_init_queue;
1513 } 1510 }
1514 master->queued = true; 1511 ctlr->queued = true;
1515 ret = spi_start_queue(master); 1512 ret = spi_start_queue(ctlr);
1516 if (ret) { 1513 if (ret) {
1517 dev_err(&master->dev, "problem starting queue\n"); 1514 dev_err(&ctlr->dev, "problem starting queue\n");
1518 goto err_start_queue; 1515 goto err_start_queue;
1519 } 1516 }
1520 1517
1521 return 0; 1518 return 0;
1522 1519
1523err_start_queue: 1520err_start_queue:
1524 spi_destroy_queue(master); 1521 spi_destroy_queue(ctlr);
1525err_init_queue: 1522err_init_queue:
1526 return ret; 1523 return ret;
1527} 1524}
@@ -1529,7 +1526,7 @@ err_init_queue:
1529/*-------------------------------------------------------------------------*/ 1526/*-------------------------------------------------------------------------*/
1530 1527
1531#if defined(CONFIG_OF) 1528#if defined(CONFIG_OF)
1532static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi, 1529static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
1533 struct device_node *nc) 1530 struct device_node *nc)
1534{ 1531{
1535 u32 value; 1532 u32 value;
@@ -1559,7 +1556,7 @@ static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi,
1559 spi->mode |= SPI_TX_QUAD; 1556 spi->mode |= SPI_TX_QUAD;
1560 break; 1557 break;
1561 default: 1558 default:
1562 dev_warn(&master->dev, 1559 dev_warn(&ctlr->dev,
1563 "spi-tx-bus-width %d not supported\n", 1560 "spi-tx-bus-width %d not supported\n",
1564 value); 1561 value);
1565 break; 1562 break;
@@ -1577,16 +1574,16 @@ static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi,
1577 spi->mode |= SPI_RX_QUAD; 1574 spi->mode |= SPI_RX_QUAD;
1578 break; 1575 break;
1579 default: 1576 default:
1580 dev_warn(&master->dev, 1577 dev_warn(&ctlr->dev,
1581 "spi-rx-bus-width %d not supported\n", 1578 "spi-rx-bus-width %d not supported\n",
1582 value); 1579 value);
1583 break; 1580 break;
1584 } 1581 }
1585 } 1582 }
1586 1583
1587 if (spi_controller_is_slave(master)) { 1584 if (spi_controller_is_slave(ctlr)) {
1588 if (strcmp(nc->name, "slave")) { 1585 if (strcmp(nc->name, "slave")) {
1589 dev_err(&master->dev, "%s is not called 'slave'\n", 1586 dev_err(&ctlr->dev, "%s is not called 'slave'\n",
1590 nc->full_name); 1587 nc->full_name);
1591 return -EINVAL; 1588 return -EINVAL;
1592 } 1589 }
@@ -1596,7 +1593,7 @@ static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi,
1596 /* Device address */ 1593 /* Device address */
1597 rc = of_property_read_u32(nc, "reg", &value); 1594 rc = of_property_read_u32(nc, "reg", &value);
1598 if (rc) { 1595 if (rc) {
1599 dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n", 1596 dev_err(&ctlr->dev, "%s has no valid 'reg' property (%d)\n",
1600 nc->full_name, rc); 1597 nc->full_name, rc);
1601 return rc; 1598 return rc;
1602 } 1599 }
@@ -1605,7 +1602,8 @@ static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi,
1605 /* Device speed */ 1602 /* Device speed */
1606 rc = of_property_read_u32(nc, "spi-max-frequency", &value); 1603 rc = of_property_read_u32(nc, "spi-max-frequency", &value);
1607 if (rc) { 1604 if (rc) {
1608 dev_err(&master->dev, "%s has no valid 'spi-max-frequency' property (%d)\n", 1605 dev_err(&ctlr->dev,
1606 "%s has no valid 'spi-max-frequency' property (%d)\n",
1609 nc->full_name, rc); 1607 nc->full_name, rc);
1610 return rc; 1608 return rc;
1611 } 1609 }
@@ -1615,15 +1613,15 @@ static int of_spi_parse_dt(struct spi_master *master, struct spi_device *spi,
1615} 1613}
1616 1614
1617static struct spi_device * 1615static struct spi_device *
1618of_register_spi_device(struct spi_master *master, struct device_node *nc) 1616of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc)
1619{ 1617{
1620 struct spi_device *spi; 1618 struct spi_device *spi;
1621 int rc; 1619 int rc;
1622 1620
1623 /* Alloc an spi_device */ 1621 /* Alloc an spi_device */
1624 spi = spi_alloc_device(master); 1622 spi = spi_alloc_device(ctlr);
1625 if (!spi) { 1623 if (!spi) {
1626 dev_err(&master->dev, "spi_device alloc error for %s\n", 1624 dev_err(&ctlr->dev, "spi_device alloc error for %s\n",
1627 nc->full_name); 1625 nc->full_name);
1628 rc = -ENOMEM; 1626 rc = -ENOMEM;
1629 goto err_out; 1627 goto err_out;
@@ -1633,12 +1631,12 @@ of_register_spi_device(struct spi_master *master, struct device_node *nc)
1633 rc = of_modalias_node(nc, spi->modalias, 1631 rc = of_modalias_node(nc, spi->modalias,
1634 sizeof(spi->modalias)); 1632 sizeof(spi->modalias));
1635 if (rc < 0) { 1633 if (rc < 0) {
1636 dev_err(&master->dev, "cannot find modalias for %s\n", 1634 dev_err(&ctlr->dev, "cannot find modalias for %s\n",
1637 nc->full_name); 1635 nc->full_name);
1638 goto err_out; 1636 goto err_out;
1639 } 1637 }
1640 1638
1641 rc = of_spi_parse_dt(master, spi, nc); 1639 rc = of_spi_parse_dt(ctlr, spi, nc);
1642 if (rc) 1640 if (rc)
1643 goto err_out; 1641 goto err_out;
1644 1642
@@ -1649,7 +1647,7 @@ of_register_spi_device(struct spi_master *master, struct device_node *nc)
1649 /* Register the new device */ 1647 /* Register the new device */
1650 rc = spi_add_device(spi); 1648 rc = spi_add_device(spi);
1651 if (rc) { 1649 if (rc) {
1652 dev_err(&master->dev, "spi_device register error %s\n", 1650 dev_err(&ctlr->dev, "spi_device register error %s\n",
1653 nc->full_name); 1651 nc->full_name);
1654 goto err_of_node_put; 1652 goto err_of_node_put;
1655 } 1653 }
@@ -1665,39 +1663,40 @@ err_out:
1665 1663
1666/** 1664/**
1667 * of_register_spi_devices() - Register child devices onto the SPI bus 1665 * of_register_spi_devices() - Register child devices onto the SPI bus
1668 * @master: Pointer to spi_master device 1666 * @ctlr: Pointer to spi_controller device
1669 * 1667 *
1670 * Registers an spi_device for each child node of controller node which 1668 * Registers an spi_device for each child node of controller node which
1671 * represents a valid SPI slave. 1669 * represents a valid SPI slave.
1672 */ 1670 */
1673static void of_register_spi_devices(struct spi_master *master) 1671static void of_register_spi_devices(struct spi_controller *ctlr)
1674{ 1672{
1675 struct spi_device *spi; 1673 struct spi_device *spi;
1676 struct device_node *nc; 1674 struct device_node *nc;
1677 1675
1678 if (!master->dev.of_node) 1676 if (!ctlr->dev.of_node)
1679 return; 1677 return;
1680 1678
1681 for_each_available_child_of_node(master->dev.of_node, nc) { 1679 for_each_available_child_of_node(ctlr->dev.of_node, nc) {
1682 if (of_node_test_and_set_flag(nc, OF_POPULATED)) 1680 if (of_node_test_and_set_flag(nc, OF_POPULATED))
1683 continue; 1681 continue;
1684 spi = of_register_spi_device(master, nc); 1682 spi = of_register_spi_device(ctlr, nc);
1685 if (IS_ERR(spi)) { 1683 if (IS_ERR(spi)) {
1686 dev_warn(&master->dev, "Failed to create SPI device for %s\n", 1684 dev_warn(&ctlr->dev,
1687 nc->full_name); 1685 "Failed to create SPI device for %s\n",
1686 nc->full_name);
1688 of_node_clear_flag(nc, OF_POPULATED); 1687 of_node_clear_flag(nc, OF_POPULATED);
1689 } 1688 }
1690 } 1689 }
1691} 1690}
1692#else 1691#else
1693static void of_register_spi_devices(struct spi_master *master) { } 1692static void of_register_spi_devices(struct spi_controller *ctlr) { }
1694#endif 1693#endif
1695 1694
1696#ifdef CONFIG_ACPI 1695#ifdef CONFIG_ACPI
1697static int acpi_spi_add_resource(struct acpi_resource *ares, void *data) 1696static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
1698{ 1697{
1699 struct spi_device *spi = data; 1698 struct spi_device *spi = data;
1700 struct spi_master *master = spi->master; 1699 struct spi_controller *ctlr = spi->controller;
1701 1700
1702 if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) { 1701 if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
1703 struct acpi_resource_spi_serialbus *sb; 1702 struct acpi_resource_spi_serialbus *sb;
@@ -1711,8 +1710,8 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
1711 * 0 .. max - 1 so we need to ask the driver to 1710 * 0 .. max - 1 so we need to ask the driver to
1712 * translate between the two schemes. 1711 * translate between the two schemes.
1713 */ 1712 */
1714 if (master->fw_translate_cs) { 1713 if (ctlr->fw_translate_cs) {
1715 int cs = master->fw_translate_cs(master, 1714 int cs = ctlr->fw_translate_cs(ctlr,
1716 sb->device_selection); 1715 sb->device_selection);
1717 if (cs < 0) 1716 if (cs < 0)
1718 return cs; 1717 return cs;
@@ -1741,7 +1740,7 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
1741 return 1; 1740 return 1;
1742} 1741}
1743 1742
1744static acpi_status acpi_register_spi_device(struct spi_master *master, 1743static acpi_status acpi_register_spi_device(struct spi_controller *ctlr,
1745 struct acpi_device *adev) 1744 struct acpi_device *adev)
1746{ 1745{
1747 struct list_head resource_list; 1746 struct list_head resource_list;
@@ -1752,9 +1751,9 @@ static acpi_status acpi_register_spi_device(struct spi_master *master,
1752 acpi_device_enumerated(adev)) 1751 acpi_device_enumerated(adev))
1753 return AE_OK; 1752 return AE_OK;
1754 1753
1755 spi = spi_alloc_device(master); 1754 spi = spi_alloc_device(ctlr);
1756 if (!spi) { 1755 if (!spi) {
1757 dev_err(&master->dev, "failed to allocate SPI device for %s\n", 1756 dev_err(&ctlr->dev, "failed to allocate SPI device for %s\n",
1758 dev_name(&adev->dev)); 1757 dev_name(&adev->dev));
1759 return AE_NO_MEMORY; 1758 return AE_NO_MEMORY;
1760 } 1759 }
@@ -1783,7 +1782,7 @@ static acpi_status acpi_register_spi_device(struct spi_master *master,
1783 adev->power.flags.ignore_parent = true; 1782 adev->power.flags.ignore_parent = true;
1784 if (spi_add_device(spi)) { 1783 if (spi_add_device(spi)) {
1785 adev->power.flags.ignore_parent = false; 1784 adev->power.flags.ignore_parent = false;
1786 dev_err(&master->dev, "failed to add SPI device %s from ACPI\n", 1785 dev_err(&ctlr->dev, "failed to add SPI device %s from ACPI\n",
1787 dev_name(&adev->dev)); 1786 dev_name(&adev->dev));
1788 spi_dev_put(spi); 1787 spi_dev_put(spi);
1789 } 1788 }
@@ -1794,46 +1793,45 @@ static acpi_status acpi_register_spi_device(struct spi_master *master,
1794static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level, 1793static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level,
1795 void *data, void **return_value) 1794 void *data, void **return_value)
1796{ 1795{
1797 struct spi_master *master = data; 1796 struct spi_controller *ctlr = data;
1798 struct acpi_device *adev; 1797 struct acpi_device *adev;
1799 1798
1800 if (acpi_bus_get_device(handle, &adev)) 1799 if (acpi_bus_get_device(handle, &adev))
1801 return AE_OK; 1800 return AE_OK;
1802 1801
1803 return acpi_register_spi_device(master, adev); 1802 return acpi_register_spi_device(ctlr, adev);
1804} 1803}
1805 1804
1806static void acpi_register_spi_devices(struct spi_master *master) 1805static void acpi_register_spi_devices(struct spi_controller *ctlr)
1807{ 1806{
1808 acpi_status status; 1807 acpi_status status;
1809 acpi_handle handle; 1808 acpi_handle handle;
1810 1809
1811 handle = ACPI_HANDLE(master->dev.parent); 1810 handle = ACPI_HANDLE(ctlr->dev.parent);
1812 if (!handle) 1811 if (!handle)
1813 return; 1812 return;
1814 1813
1815 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, 1814 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
1816 acpi_spi_add_device, NULL, 1815 acpi_spi_add_device, NULL, ctlr, NULL);
1817 master, NULL);
1818 if (ACPI_FAILURE(status)) 1816 if (ACPI_FAILURE(status))
1819 dev_warn(&master->dev, "failed to enumerate SPI slaves\n"); 1817 dev_warn(&ctlr->dev, "failed to enumerate SPI slaves\n");
1820} 1818}
1821#else 1819#else
1822static inline void acpi_register_spi_devices(struct spi_master *master) {} 1820static inline void acpi_register_spi_devices(struct spi_controller *ctlr) {}
1823#endif /* CONFIG_ACPI */ 1821#endif /* CONFIG_ACPI */
1824 1822
1825static void spi_master_release(struct device *dev) 1823static void spi_controller_release(struct device *dev)
1826{ 1824{
1827 struct spi_master *master; 1825 struct spi_controller *ctlr;
1828 1826
1829 master = container_of(dev, struct spi_master, dev); 1827 ctlr = container_of(dev, struct spi_controller, dev);
1830 kfree(master); 1828 kfree(ctlr);
1831} 1829}
1832 1830
1833static struct class spi_master_class = { 1831static struct class spi_master_class = {
1834 .name = "spi_master", 1832 .name = "spi_master",
1835 .owner = THIS_MODULE, 1833 .owner = THIS_MODULE,
1836 .dev_release = spi_master_release, 1834 .dev_release = spi_controller_release,
1837 .dev_groups = spi_master_groups, 1835 .dev_groups = spi_master_groups,
1838}; 1836};
1839 1837
@@ -1845,10 +1843,10 @@ static struct class spi_master_class = {
1845 */ 1843 */
1846int spi_slave_abort(struct spi_device *spi) 1844int spi_slave_abort(struct spi_device *spi)
1847{ 1845{
1848 struct spi_master *master = spi->master; 1846 struct spi_controller *ctlr = spi->controller;
1849 1847
1850 if (spi_controller_is_slave(master) && master->slave_abort) 1848 if (spi_controller_is_slave(ctlr) && ctlr->slave_abort)
1851 return master->slave_abort(master); 1849 return ctlr->slave_abort(ctlr);
1852 1850
1853 return -ENOTSUPP; 1851 return -ENOTSUPP;
1854} 1852}
@@ -1862,7 +1860,8 @@ static int match_true(struct device *dev, void *data)
1862static ssize_t spi_slave_show(struct device *dev, 1860static ssize_t spi_slave_show(struct device *dev,
1863 struct device_attribute *attr, char *buf) 1861 struct device_attribute *attr, char *buf)
1864{ 1862{
1865 struct spi_master *ctlr = container_of(dev, struct spi_master, dev); 1863 struct spi_controller *ctlr = container_of(dev, struct spi_controller,
1864 dev);
1866 struct device *child; 1865 struct device *child;
1867 1866
1868 child = device_find_child(&ctlr->dev, NULL, match_true); 1867 child = device_find_child(&ctlr->dev, NULL, match_true);
@@ -1874,7 +1873,8 @@ static ssize_t spi_slave_store(struct device *dev,
1874 struct device_attribute *attr, const char *buf, 1873 struct device_attribute *attr, const char *buf,
1875 size_t count) 1874 size_t count)
1876{ 1875{
1877 struct spi_master *ctlr = container_of(dev, struct spi_master, dev); 1876 struct spi_controller *ctlr = container_of(dev, struct spi_controller,
1877 dev);
1878 struct spi_device *spi; 1878 struct spi_device *spi;
1879 struct device *child; 1879 struct device *child;
1880 char name[32]; 1880 char name[32];
@@ -1921,7 +1921,7 @@ static const struct attribute_group spi_slave_group = {
1921}; 1921};
1922 1922
1923static const struct attribute_group *spi_slave_groups[] = { 1923static const struct attribute_group *spi_slave_groups[] = {
1924 &spi_master_statistics_group, 1924 &spi_controller_statistics_group,
1925 &spi_slave_group, 1925 &spi_slave_group,
1926 NULL, 1926 NULL,
1927}; 1927};
@@ -1929,7 +1929,7 @@ static const struct attribute_group *spi_slave_groups[] = {
1929static struct class spi_slave_class = { 1929static struct class spi_slave_class = {
1930 .name = "spi_slave", 1930 .name = "spi_slave",
1931 .owner = THIS_MODULE, 1931 .owner = THIS_MODULE,
1932 .dev_release = spi_master_release, 1932 .dev_release = spi_controller_release,
1933 .dev_groups = spi_slave_groups, 1933 .dev_groups = spi_slave_groups,
1934}; 1934};
1935#else 1935#else
@@ -1941,62 +1941,63 @@ extern struct class spi_slave_class; /* dummy */
1941 * @dev: the controller, possibly using the platform_bus 1941 * @dev: the controller, possibly using the platform_bus
1942 * @size: how much zeroed driver-private data to allocate; the pointer to this 1942 * @size: how much zeroed driver-private data to allocate; the pointer to this
1943 * memory is in the driver_data field of the returned device, 1943 * memory is in the driver_data field of the returned device,
1944 * accessible with spi_master_get_devdata(). 1944 * accessible with spi_controller_get_devdata().
1945 * @slave: flag indicating whether to allocate an SPI master (false) or SPI 1945 * @slave: flag indicating whether to allocate an SPI master (false) or SPI
1946 * slave (true) controller 1946 * slave (true) controller
1947 * Context: can sleep 1947 * Context: can sleep
1948 * 1948 *
1949 * This call is used only by SPI controller drivers, which are the 1949 * This call is used only by SPI controller drivers, which are the
1950 * only ones directly touching chip registers. It's how they allocate 1950 * only ones directly touching chip registers. It's how they allocate
1951 * an spi_master structure, prior to calling spi_register_master(). 1951 * an spi_controller structure, prior to calling spi_register_controller().
1952 * 1952 *
1953 * This must be called from context that can sleep. 1953 * This must be called from context that can sleep.
1954 * 1954 *
1955 * The caller is responsible for assigning the bus number and initializing the 1955 * The caller is responsible for assigning the bus number and initializing the
1956 * controller's methods before calling spi_register_master(); and (after errors 1956 * controller's methods before calling spi_register_controller(); and (after
1957 * adding the device) calling spi_master_put() to prevent a memory leak. 1957 * errors adding the device) calling spi_controller_put() to prevent a memory
1958 * leak.
1958 * 1959 *
1959 * Return: the SPI controller structure on success, else NULL. 1960 * Return: the SPI controller structure on success, else NULL.
1960 */ 1961 */
1961struct spi_master *__spi_alloc_controller(struct device *dev, 1962struct spi_controller *__spi_alloc_controller(struct device *dev,
1962 unsigned int size, bool slave) 1963 unsigned int size, bool slave)
1963{ 1964{
1964 struct spi_master *master; 1965 struct spi_controller *ctlr;
1965 1966
1966 if (!dev) 1967 if (!dev)
1967 return NULL; 1968 return NULL;
1968 1969
1969 master = kzalloc(size + sizeof(*master), GFP_KERNEL); 1970 ctlr = kzalloc(size + sizeof(*ctlr), GFP_KERNEL);
1970 if (!master) 1971 if (!ctlr)
1971 return NULL; 1972 return NULL;
1972 1973
1973 device_initialize(&master->dev); 1974 device_initialize(&ctlr->dev);
1974 master->bus_num = -1; 1975 ctlr->bus_num = -1;
1975 master->num_chipselect = 1; 1976 ctlr->num_chipselect = 1;
1976 master->slave = slave; 1977 ctlr->slave = slave;
1977 if (IS_ENABLED(CONFIG_SPI_SLAVE) && slave) 1978 if (IS_ENABLED(CONFIG_SPI_SLAVE) && slave)
1978 master->dev.class = &spi_slave_class; 1979 ctlr->dev.class = &spi_slave_class;
1979 else 1980 else
1980 master->dev.class = &spi_master_class; 1981 ctlr->dev.class = &spi_master_class;
1981 master->dev.parent = dev; 1982 ctlr->dev.parent = dev;
1982 pm_suspend_ignore_children(&master->dev, true); 1983 pm_suspend_ignore_children(&ctlr->dev, true);
1983 spi_master_set_devdata(master, &master[1]); 1984 spi_controller_set_devdata(ctlr, &ctlr[1]);
1984 1985
1985 return master; 1986 return ctlr;
1986} 1987}
1987EXPORT_SYMBOL_GPL(__spi_alloc_controller); 1988EXPORT_SYMBOL_GPL(__spi_alloc_controller);
1988 1989
1989#ifdef CONFIG_OF 1990#ifdef CONFIG_OF
1990static int of_spi_register_master(struct spi_master *master) 1991static int of_spi_register_master(struct spi_controller *ctlr)
1991{ 1992{
1992 int nb, i, *cs; 1993 int nb, i, *cs;
1993 struct device_node *np = master->dev.of_node; 1994 struct device_node *np = ctlr->dev.of_node;
1994 1995
1995 if (!np) 1996 if (!np)
1996 return 0; 1997 return 0;
1997 1998
1998 nb = of_gpio_named_count(np, "cs-gpios"); 1999 nb = of_gpio_named_count(np, "cs-gpios");
1999 master->num_chipselect = max_t(int, nb, master->num_chipselect); 2000 ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect);
2000 2001
2001 /* Return error only for an incorrectly formed cs-gpios property */ 2002 /* Return error only for an incorrectly formed cs-gpios property */
2002 if (nb == 0 || nb == -ENOENT) 2003 if (nb == 0 || nb == -ENOENT)
@@ -2004,15 +2005,14 @@ static int of_spi_register_master(struct spi_master *master)
2004 else if (nb < 0) 2005 else if (nb < 0)
2005 return nb; 2006 return nb;
2006 2007
2007 cs = devm_kzalloc(&master->dev, 2008 cs = devm_kzalloc(&ctlr->dev, sizeof(int) * ctlr->num_chipselect,
2008 sizeof(int) * master->num_chipselect,
2009 GFP_KERNEL); 2009 GFP_KERNEL);
2010 master->cs_gpios = cs; 2010 ctlr->cs_gpios = cs;
2011 2011
2012 if (!master->cs_gpios) 2012 if (!ctlr->cs_gpios)
2013 return -ENOMEM; 2013 return -ENOMEM;
2014 2014
2015 for (i = 0; i < master->num_chipselect; i++) 2015 for (i = 0; i < ctlr->num_chipselect; i++)
2016 cs[i] = -ENOENT; 2016 cs[i] = -ENOENT;
2017 2017
2018 for (i = 0; i < nb; i++) 2018 for (i = 0; i < nb; i++)
@@ -2021,20 +2021,21 @@ static int of_spi_register_master(struct spi_master *master)
2021 return 0; 2021 return 0;
2022} 2022}
2023#else 2023#else
2024static int of_spi_register_master(struct spi_master *master) 2024static int of_spi_register_master(struct spi_controller *ctlr)
2025{ 2025{
2026 return 0; 2026 return 0;
2027} 2027}
2028#endif 2028#endif
2029 2029
2030/** 2030/**
2031 * spi_register_master - register SPI master controller 2031 * spi_register_controller - register SPI master or slave controller
2032 * @master: initialized master, originally from spi_alloc_master() 2032 * @ctlr: initialized master, originally from spi_alloc_master() or
2033 * spi_alloc_slave()
2033 * Context: can sleep 2034 * Context: can sleep
2034 * 2035 *
2035 * SPI master controllers connect to their drivers using some non-SPI bus, 2036 * SPI controllers connect to their drivers using some non-SPI bus,
2036 * such as the platform bus. The final stage of probe() in that code 2037 * such as the platform bus. The final stage of probe() in that code
2037 * includes calling spi_register_master() to hook up to this SPI bus glue. 2038 * includes calling spi_register_controller() to hook up to this SPI bus glue.
2038 * 2039 *
2039 * SPI controllers use board specific (often SOC specific) bus numbers, 2040 * SPI controllers use board specific (often SOC specific) bus numbers,
2040 * and board-specific addressing for SPI devices combines those numbers 2041 * and board-specific addressing for SPI devices combines those numbers
@@ -2043,16 +2044,16 @@ static int of_spi_register_master(struct spi_master *master)
2043 * chip is at which address. 2044 * chip is at which address.
2044 * 2045 *
2045 * This must be called from context that can sleep. It returns zero on 2046 * This must be called from context that can sleep. It returns zero on
2046 * success, else a negative error code (dropping the master's refcount). 2047 * success, else a negative error code (dropping the controller's refcount).
2047 * After a successful return, the caller is responsible for calling 2048 * After a successful return, the caller is responsible for calling
2048 * spi_unregister_master(). 2049 * spi_unregister_controller().
2049 * 2050 *
2050 * Return: zero on success, else a negative error code. 2051 * Return: zero on success, else a negative error code.
2051 */ 2052 */
2052int spi_register_master(struct spi_master *master) 2053int spi_register_controller(struct spi_controller *ctlr)
2053{ 2054{
2054 static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1); 2055 static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
2055 struct device *dev = master->dev.parent; 2056 struct device *dev = ctlr->dev.parent;
2056 struct boardinfo *bi; 2057 struct boardinfo *bi;
2057 int status = -ENODEV; 2058 int status = -ENODEV;
2058 int dynamic = 0; 2059 int dynamic = 0;
@@ -2060,8 +2061,8 @@ int spi_register_master(struct spi_master *master)
2060 if (!dev) 2061 if (!dev)
2061 return -ENODEV; 2062 return -ENODEV;
2062 2063
2063 if (!spi_controller_is_slave(master)) { 2064 if (!spi_controller_is_slave(ctlr)) {
2064 status = of_spi_register_master(master); 2065 status = of_spi_register_master(ctlr);
2065 if (status) 2066 if (status)
2066 return status; 2067 return status;
2067 } 2068 }
@@ -2069,97 +2070,100 @@ int spi_register_master(struct spi_master *master)
2069 /* even if it's just one always-selected device, there must 2070 /* even if it's just one always-selected device, there must
2070 * be at least one chipselect 2071 * be at least one chipselect
2071 */ 2072 */
2072 if (master->num_chipselect == 0) 2073 if (ctlr->num_chipselect == 0)
2073 return -EINVAL; 2074 return -EINVAL;
2074 2075
2075 if ((master->bus_num < 0) && master->dev.of_node) 2076 if ((ctlr->bus_num < 0) && ctlr->dev.of_node)
2076 master->bus_num = of_alias_get_id(master->dev.of_node, "spi"); 2077 ctlr->bus_num = of_alias_get_id(ctlr->dev.of_node, "spi");
2077 2078
2078 /* convention: dynamically assigned bus IDs count down from the max */ 2079 /* convention: dynamically assigned bus IDs count down from the max */
2079 if (master->bus_num < 0) { 2080 if (ctlr->bus_num < 0) {
2080 /* FIXME switch to an IDR based scheme, something like 2081 /* FIXME switch to an IDR based scheme, something like
2081 * I2C now uses, so we can't run out of "dynamic" IDs 2082 * I2C now uses, so we can't run out of "dynamic" IDs
2082 */ 2083 */
2083 master->bus_num = atomic_dec_return(&dyn_bus_id); 2084 ctlr->bus_num = atomic_dec_return(&dyn_bus_id);
2084 dynamic = 1; 2085 dynamic = 1;
2085 } 2086 }
2086 2087
2087 INIT_LIST_HEAD(&master->queue); 2088 INIT_LIST_HEAD(&ctlr->queue);
2088 spin_lock_init(&master->queue_lock); 2089 spin_lock_init(&ctlr->queue_lock);
2089 spin_lock_init(&master->bus_lock_spinlock); 2090 spin_lock_init(&ctlr->bus_lock_spinlock);
2090 mutex_init(&master->bus_lock_mutex); 2091 mutex_init(&ctlr->bus_lock_mutex);
2091 mutex_init(&master->io_mutex); 2092 mutex_init(&ctlr->io_mutex);
2092 master->bus_lock_flag = 0; 2093 ctlr->bus_lock_flag = 0;
2093 init_completion(&master->xfer_completion); 2094 init_completion(&ctlr->xfer_completion);
2094 if (!master->max_dma_len) 2095 if (!ctlr->max_dma_len)
2095 master->max_dma_len = INT_MAX; 2096 ctlr->max_dma_len = INT_MAX;
2096 2097
2097 /* register the device, then userspace will see it. 2098 /* register the device, then userspace will see it.
2098 * registration fails if the bus ID is in use. 2099 * registration fails if the bus ID is in use.
2099 */ 2100 */
2100 dev_set_name(&master->dev, "spi%u", master->bus_num); 2101 dev_set_name(&ctlr->dev, "spi%u", ctlr->bus_num);
2101 status = device_add(&master->dev); 2102 status = device_add(&ctlr->dev);
2102 if (status < 0) 2103 if (status < 0)
2103 goto done; 2104 goto done;
2104 dev_dbg(dev, "registered %s %s%s\n", 2105 dev_dbg(dev, "registered %s %s%s\n",
2105 spi_controller_is_slave(master) ? "slave" : "master", 2106 spi_controller_is_slave(ctlr) ? "slave" : "master",
2106 dev_name(&master->dev), dynamic ? " (dynamic)" : ""); 2107 dev_name(&ctlr->dev), dynamic ? " (dynamic)" : "");
2107 2108
2108 /* If we're using a queued driver, start the queue */ 2109 /* If we're using a queued driver, start the queue */
2109 if (master->transfer) 2110 if (ctlr->transfer)
2110 dev_info(dev, "master is unqueued, this is deprecated\n"); 2111 dev_info(dev, "controller is unqueued, this is deprecated\n");
2111 else { 2112 else {
2112 status = spi_master_initialize_queue(master); 2113 status = spi_controller_initialize_queue(ctlr);
2113 if (status) { 2114 if (status) {
2114 device_del(&master->dev); 2115 device_del(&ctlr->dev);
2115 goto done; 2116 goto done;
2116 } 2117 }
2117 } 2118 }
2118 /* add statistics */ 2119 /* add statistics */
2119 spin_lock_init(&master->statistics.lock); 2120 spin_lock_init(&ctlr->statistics.lock);
2120 2121
2121 mutex_lock(&board_lock); 2122 mutex_lock(&board_lock);
2122 list_add_tail(&master->list, &spi_master_list); 2123 list_add_tail(&ctlr->list, &spi_controller_list);
2123 list_for_each_entry(bi, &board_list, list) 2124 list_for_each_entry(bi, &board_list, list)
2124 spi_match_master_to_boardinfo(master, &bi->board_info); 2125 spi_match_controller_to_boardinfo(ctlr, &bi->board_info);
2125 mutex_unlock(&board_lock); 2126 mutex_unlock(&board_lock);
2126 2127
2127 /* Register devices from the device tree and ACPI */ 2128 /* Register devices from the device tree and ACPI */
2128 of_register_spi_devices(master); 2129 of_register_spi_devices(ctlr);
2129 acpi_register_spi_devices(master); 2130 acpi_register_spi_devices(ctlr);
2130done: 2131done:
2131 return status; 2132 return status;
2132} 2133}
2133EXPORT_SYMBOL_GPL(spi_register_master); 2134EXPORT_SYMBOL_GPL(spi_register_controller);
2134 2135
2135static void devm_spi_unregister(struct device *dev, void *res) 2136static void devm_spi_unregister(struct device *dev, void *res)
2136{ 2137{
2137 spi_unregister_master(*(struct spi_master **)res); 2138 spi_unregister_controller(*(struct spi_controller **)res);
2138} 2139}
2139 2140
2140/** 2141/**
2141 * devm_spi_register_master - register managed SPI master controller 2142 * devm_spi_register_controller - register managed SPI master or slave
2142 * @dev: device managing SPI master 2143 * controller
2143 * @master: initialized master, originally from spi_alloc_master() 2144 * @dev: device managing SPI controller
2145 * @ctlr: initialized controller, originally from spi_alloc_master() or
2146 * spi_alloc_slave()
2144 * Context: can sleep 2147 * Context: can sleep
2145 * 2148 *
2146 * Register a SPI device as with spi_register_master() which will 2149 * Register a SPI device as with spi_register_controller() which will
2147 * automatically be unregister 2150 * automatically be unregister
2148 * 2151 *
2149 * Return: zero on success, else a negative error code. 2152 * Return: zero on success, else a negative error code.
2150 */ 2153 */
2151int devm_spi_register_master(struct device *dev, struct spi_master *master) 2154int devm_spi_register_controller(struct device *dev,
2155 struct spi_controller *ctlr)
2152{ 2156{
2153 struct spi_master **ptr; 2157 struct spi_controller **ptr;
2154 int ret; 2158 int ret;
2155 2159
2156 ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL); 2160 ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL);
2157 if (!ptr) 2161 if (!ptr)
2158 return -ENOMEM; 2162 return -ENOMEM;
2159 2163
2160 ret = spi_register_master(master); 2164 ret = spi_register_controller(ctlr);
2161 if (!ret) { 2165 if (!ret) {
2162 *ptr = master; 2166 *ptr = ctlr;
2163 devres_add(dev, ptr); 2167 devres_add(dev, ptr);
2164 } else { 2168 } else {
2165 devres_free(ptr); 2169 devres_free(ptr);
@@ -2167,7 +2171,7 @@ int devm_spi_register_master(struct device *dev, struct spi_master *master)
2167 2171
2168 return ret; 2172 return ret;
2169} 2173}
2170EXPORT_SYMBOL_GPL(devm_spi_register_master); 2174EXPORT_SYMBOL_GPL(devm_spi_register_controller);
2171 2175
2172static int __unregister(struct device *dev, void *null) 2176static int __unregister(struct device *dev, void *null)
2173{ 2177{
@@ -2176,71 +2180,71 @@ static int __unregister(struct device *dev, void *null)
2176} 2180}
2177 2181
2178/** 2182/**
2179 * spi_unregister_master - unregister SPI master controller 2183 * spi_unregister_controller - unregister SPI master or slave controller
2180 * @master: the master being unregistered 2184 * @ctlr: the controller being unregistered
2181 * Context: can sleep 2185 * Context: can sleep
2182 * 2186 *
2183 * This call is used only by SPI master controller drivers, which are the 2187 * This call is used only by SPI controller drivers, which are the
2184 * only ones directly touching chip registers. 2188 * only ones directly touching chip registers.
2185 * 2189 *
2186 * This must be called from context that can sleep. 2190 * This must be called from context that can sleep.
2187 */ 2191 */
2188void spi_unregister_master(struct spi_master *master) 2192void spi_unregister_controller(struct spi_controller *ctlr)
2189{ 2193{
2190 int dummy; 2194 int dummy;
2191 2195
2192 if (master->queued) { 2196 if (ctlr->queued) {
2193 if (spi_destroy_queue(master)) 2197 if (spi_destroy_queue(ctlr))
2194 dev_err(&master->dev, "queue remove failed\n"); 2198 dev_err(&ctlr->dev, "queue remove failed\n");
2195 } 2199 }
2196 2200
2197 mutex_lock(&board_lock); 2201 mutex_lock(&board_lock);
2198 list_del(&master->list); 2202 list_del(&ctlr->list);
2199 mutex_unlock(&board_lock); 2203 mutex_unlock(&board_lock);
2200 2204
2201 dummy = device_for_each_child(&master->dev, NULL, __unregister); 2205 dummy = device_for_each_child(&ctlr->dev, NULL, __unregister);
2202 device_unregister(&master->dev); 2206 device_unregister(&ctlr->dev);
2203} 2207}
2204EXPORT_SYMBOL_GPL(spi_unregister_master); 2208EXPORT_SYMBOL_GPL(spi_unregister_controller);
2205 2209
2206int spi_master_suspend(struct spi_master *master) 2210int spi_controller_suspend(struct spi_controller *ctlr)
2207{ 2211{
2208 int ret; 2212 int ret;
2209 2213
2210 /* Basically no-ops for non-queued masters */ 2214 /* Basically no-ops for non-queued controllers */
2211 if (!master->queued) 2215 if (!ctlr->queued)
2212 return 0; 2216 return 0;
2213 2217
2214 ret = spi_stop_queue(master); 2218 ret = spi_stop_queue(ctlr);
2215 if (ret) 2219 if (ret)
2216 dev_err(&master->dev, "queue stop failed\n"); 2220 dev_err(&ctlr->dev, "queue stop failed\n");
2217 2221
2218 return ret; 2222 return ret;
2219} 2223}
2220EXPORT_SYMBOL_GPL(spi_master_suspend); 2224EXPORT_SYMBOL_GPL(spi_controller_suspend);
2221 2225
2222int spi_master_resume(struct spi_master *master) 2226int spi_controller_resume(struct spi_controller *ctlr)
2223{ 2227{
2224 int ret; 2228 int ret;
2225 2229
2226 if (!master->queued) 2230 if (!ctlr->queued)
2227 return 0; 2231 return 0;
2228 2232
2229 ret = spi_start_queue(master); 2233 ret = spi_start_queue(ctlr);
2230 if (ret) 2234 if (ret)
2231 dev_err(&master->dev, "queue restart failed\n"); 2235 dev_err(&ctlr->dev, "queue restart failed\n");
2232 2236
2233 return ret; 2237 return ret;
2234} 2238}
2235EXPORT_SYMBOL_GPL(spi_master_resume); 2239EXPORT_SYMBOL_GPL(spi_controller_resume);
2236 2240
2237static int __spi_master_match(struct device *dev, const void *data) 2241static int __spi_controller_match(struct device *dev, const void *data)
2238{ 2242{
2239 struct spi_master *m; 2243 struct spi_controller *ctlr;
2240 const u16 *bus_num = data; 2244 const u16 *bus_num = data;
2241 2245
2242 m = container_of(dev, struct spi_master, dev); 2246 ctlr = container_of(dev, struct spi_controller, dev);
2243 return m->bus_num == *bus_num; 2247 return ctlr->bus_num == *bus_num;
2244} 2248}
2245 2249
2246/** 2250/**
@@ -2250,22 +2254,22 @@ static int __spi_master_match(struct device *dev, const void *data)
2250 * 2254 *
2251 * This call may be used with devices that are registered after 2255 * This call may be used with devices that are registered after
2252 * arch init time. It returns a refcounted pointer to the relevant 2256 * arch init time. It returns a refcounted pointer to the relevant
2253 * spi_master (which the caller must release), or NULL if there is 2257 * spi_controller (which the caller must release), or NULL if there is
2254 * no such master registered. 2258 * no such master registered.
2255 * 2259 *
2256 * Return: the SPI master structure on success, else NULL. 2260 * Return: the SPI master structure on success, else NULL.
2257 */ 2261 */
2258struct spi_master *spi_busnum_to_master(u16 bus_num) 2262struct spi_controller *spi_busnum_to_master(u16 bus_num)
2259{ 2263{
2260 struct device *dev; 2264 struct device *dev;
2261 struct spi_master *master = NULL; 2265 struct spi_controller *ctlr = NULL;
2262 2266
2263 dev = class_find_device(&spi_master_class, NULL, &bus_num, 2267 dev = class_find_device(&spi_master_class, NULL, &bus_num,
2264 __spi_master_match); 2268 __spi_controller_match);
2265 if (dev) 2269 if (dev)
2266 master = container_of(dev, struct spi_master, dev); 2270 ctlr = container_of(dev, struct spi_controller, dev);
2267 /* reference got in class_find_device */ 2271 /* reference got in class_find_device */
2268 return master; 2272 return ctlr;
2269} 2273}
2270EXPORT_SYMBOL_GPL(spi_busnum_to_master); 2274EXPORT_SYMBOL_GPL(spi_busnum_to_master);
2271 2275
@@ -2285,7 +2289,7 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
2285 * Return: the pointer to the allocated data 2289 * Return: the pointer to the allocated data
2286 * 2290 *
2287 * This may get enhanced in the future to allocate from a memory pool 2291 * This may get enhanced in the future to allocate from a memory pool
2288 * of the @spi_device or @spi_master to avoid repeated allocations. 2292 * of the @spi_device or @spi_controller to avoid repeated allocations.
2289 */ 2293 */
2290void *spi_res_alloc(struct spi_device *spi, 2294void *spi_res_alloc(struct spi_device *spi,
2291 spi_res_release_t release, 2295 spi_res_release_t release,
@@ -2337,11 +2341,10 @@ EXPORT_SYMBOL_GPL(spi_res_add);
2337 2341
2338/** 2342/**
2339 * spi_res_release - release all spi resources for this message 2343 * spi_res_release - release all spi resources for this message
2340 * @master: the @spi_master 2344 * @ctlr: the @spi_controller
2341 * @message: the @spi_message 2345 * @message: the @spi_message
2342 */ 2346 */
2343void spi_res_release(struct spi_master *master, 2347void spi_res_release(struct spi_controller *ctlr, struct spi_message *message)
2344 struct spi_message *message)
2345{ 2348{
2346 struct spi_res *res; 2349 struct spi_res *res;
2347 2350
@@ -2350,7 +2353,7 @@ void spi_res_release(struct spi_master *master,
2350 struct spi_res, entry); 2353 struct spi_res, entry);
2351 2354
2352 if (res->release) 2355 if (res->release)
2353 res->release(master, message, res->data); 2356 res->release(ctlr, message, res->data);
2354 2357
2355 list_del(&res->entry); 2358 list_del(&res->entry);
2356 2359
@@ -2363,7 +2366,7 @@ EXPORT_SYMBOL_GPL(spi_res_release);
2363 2366
2364/* Core methods for spi_message alterations */ 2367/* Core methods for spi_message alterations */
2365 2368
2366static void __spi_replace_transfers_release(struct spi_master *master, 2369static void __spi_replace_transfers_release(struct spi_controller *ctlr,
2367 struct spi_message *msg, 2370 struct spi_message *msg,
2368 void *res) 2371 void *res)
2369{ 2372{
@@ -2372,7 +2375,7 @@ static void __spi_replace_transfers_release(struct spi_master *master,
2372 2375
2373 /* call extra callback if requested */ 2376 /* call extra callback if requested */
2374 if (rxfer->release) 2377 if (rxfer->release)
2375 rxfer->release(master, msg, res); 2378 rxfer->release(ctlr, msg, res);
2376 2379
2377 /* insert replaced transfers back into the message */ 2380 /* insert replaced transfers back into the message */
2378 list_splice(&rxfer->replaced_transfers, rxfer->replaced_after); 2381 list_splice(&rxfer->replaced_transfers, rxfer->replaced_after);
@@ -2492,7 +2495,7 @@ struct spi_replaced_transfers *spi_replace_transfers(
2492} 2495}
2493EXPORT_SYMBOL_GPL(spi_replace_transfers); 2496EXPORT_SYMBOL_GPL(spi_replace_transfers);
2494 2497
2495static int __spi_split_transfer_maxsize(struct spi_master *master, 2498static int __spi_split_transfer_maxsize(struct spi_controller *ctlr,
2496 struct spi_message *msg, 2499 struct spi_message *msg,
2497 struct spi_transfer **xferp, 2500 struct spi_transfer **xferp,
2498 size_t maxsize, 2501 size_t maxsize,
@@ -2554,7 +2557,7 @@ static int __spi_split_transfer_maxsize(struct spi_master *master,
2554 *xferp = &xfers[count - 1]; 2557 *xferp = &xfers[count - 1];
2555 2558
2556 /* increment statistics counters */ 2559 /* increment statistics counters */
2557 SPI_STATISTICS_INCREMENT_FIELD(&master->statistics, 2560 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics,
2558 transfers_split_maxsize); 2561 transfers_split_maxsize);
2559 SPI_STATISTICS_INCREMENT_FIELD(&msg->spi->statistics, 2562 SPI_STATISTICS_INCREMENT_FIELD(&msg->spi->statistics,
2560 transfers_split_maxsize); 2563 transfers_split_maxsize);
@@ -2566,14 +2569,14 @@ static int __spi_split_transfer_maxsize(struct spi_master *master,
2566 * spi_split_tranfers_maxsize - split spi transfers into multiple transfers 2569 * spi_split_tranfers_maxsize - split spi transfers into multiple transfers
2567 * when an individual transfer exceeds a 2570 * when an individual transfer exceeds a
2568 * certain size 2571 * certain size
2569 * @master: the @spi_master for this transfer 2572 * @ctlr: the @spi_controller for this transfer
2570 * @msg: the @spi_message to transform 2573 * @msg: the @spi_message to transform
2571 * @maxsize: the maximum when to apply this 2574 * @maxsize: the maximum when to apply this
2572 * @gfp: GFP allocation flags 2575 * @gfp: GFP allocation flags
2573 * 2576 *
2574 * Return: status of transformation 2577 * Return: status of transformation
2575 */ 2578 */
2576int spi_split_transfers_maxsize(struct spi_master *master, 2579int spi_split_transfers_maxsize(struct spi_controller *ctlr,
2577 struct spi_message *msg, 2580 struct spi_message *msg,
2578 size_t maxsize, 2581 size_t maxsize,
2579 gfp_t gfp) 2582 gfp_t gfp)
@@ -2589,8 +2592,8 @@ int spi_split_transfers_maxsize(struct spi_master *master,
2589 */ 2592 */
2590 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 2593 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
2591 if (xfer->len > maxsize) { 2594 if (xfer->len > maxsize) {
2592 ret = __spi_split_transfer_maxsize( 2595 ret = __spi_split_transfer_maxsize(ctlr, msg, &xfer,
2593 master, msg, &xfer, maxsize, gfp); 2596 maxsize, gfp);
2594 if (ret) 2597 if (ret)
2595 return ret; 2598 return ret;
2596 } 2599 }
@@ -2602,18 +2605,18 @@ EXPORT_SYMBOL_GPL(spi_split_transfers_maxsize);
2602 2605
2603/*-------------------------------------------------------------------------*/ 2606/*-------------------------------------------------------------------------*/
2604 2607
2605/* Core methods for SPI master protocol drivers. Some of the 2608/* Core methods for SPI controller protocol drivers. Some of the
2606 * other core methods are currently defined as inline functions. 2609 * other core methods are currently defined as inline functions.
2607 */ 2610 */
2608 2611
2609static int __spi_validate_bits_per_word(struct spi_master *master, u8 bits_per_word) 2612static int __spi_validate_bits_per_word(struct spi_controller *ctlr,
2613 u8 bits_per_word)
2610{ 2614{
2611 if (master->bits_per_word_mask) { 2615 if (ctlr->bits_per_word_mask) {
2612 /* Only 32 bits fit in the mask */ 2616 /* Only 32 bits fit in the mask */
2613 if (bits_per_word > 32) 2617 if (bits_per_word > 32)
2614 return -EINVAL; 2618 return -EINVAL;
2615 if (!(master->bits_per_word_mask & 2619 if (!(ctlr->bits_per_word_mask & SPI_BPW_MASK(bits_per_word)))
2616 SPI_BPW_MASK(bits_per_word)))
2617 return -EINVAL; 2620 return -EINVAL;
2618 } 2621 }
2619 2622
@@ -2659,9 +2662,9 @@ int spi_setup(struct spi_device *spi)
2659 (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD))) 2662 (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD)))
2660 return -EINVAL; 2663 return -EINVAL;
2661 /* help drivers fail *cleanly* when they need options 2664 /* help drivers fail *cleanly* when they need options
2662 * that aren't supported with their current master 2665 * that aren't supported with their current controller
2663 */ 2666 */
2664 bad_bits = spi->mode & ~spi->master->mode_bits; 2667 bad_bits = spi->mode & ~spi->controller->mode_bits;
2665 ugly_bits = bad_bits & 2668 ugly_bits = bad_bits &
2666 (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD); 2669 (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD);
2667 if (ugly_bits) { 2670 if (ugly_bits) {
@@ -2680,15 +2683,16 @@ int spi_setup(struct spi_device *spi)
2680 if (!spi->bits_per_word) 2683 if (!spi->bits_per_word)
2681 spi->bits_per_word = 8; 2684 spi->bits_per_word = 8;
2682 2685
2683 status = __spi_validate_bits_per_word(spi->master, spi->bits_per_word); 2686 status = __spi_validate_bits_per_word(spi->controller,
2687 spi->bits_per_word);
2684 if (status) 2688 if (status)
2685 return status; 2689 return status;
2686 2690
2687 if (!spi->max_speed_hz) 2691 if (!spi->max_speed_hz)
2688 spi->max_speed_hz = spi->master->max_speed_hz; 2692 spi->max_speed_hz = spi->controller->max_speed_hz;
2689 2693
2690 if (spi->master->setup) 2694 if (spi->controller->setup)
2691 status = spi->master->setup(spi); 2695 status = spi->controller->setup(spi);
2692 2696
2693 spi_set_cs(spi, false); 2697 spi_set_cs(spi, false);
2694 2698
@@ -2707,7 +2711,7 @@ EXPORT_SYMBOL_GPL(spi_setup);
2707 2711
2708static int __spi_validate(struct spi_device *spi, struct spi_message *message) 2712static int __spi_validate(struct spi_device *spi, struct spi_message *message)
2709{ 2713{
2710 struct spi_master *master = spi->master; 2714 struct spi_controller *ctlr = spi->controller;
2711 struct spi_transfer *xfer; 2715 struct spi_transfer *xfer;
2712 int w_size; 2716 int w_size;
2713 2717
@@ -2719,16 +2723,16 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
2719 * either MOSI or MISO is missing. They can also be caused by 2723 * either MOSI or MISO is missing. They can also be caused by
2720 * software limitations. 2724 * software limitations.
2721 */ 2725 */
2722 if ((master->flags & SPI_MASTER_HALF_DUPLEX) 2726 if ((ctlr->flags & SPI_CONTROLLER_HALF_DUPLEX) ||
2723 || (spi->mode & SPI_3WIRE)) { 2727 (spi->mode & SPI_3WIRE)) {
2724 unsigned flags = master->flags; 2728 unsigned flags = ctlr->flags;
2725 2729
2726 list_for_each_entry(xfer, &message->transfers, transfer_list) { 2730 list_for_each_entry(xfer, &message->transfers, transfer_list) {
2727 if (xfer->rx_buf && xfer->tx_buf) 2731 if (xfer->rx_buf && xfer->tx_buf)
2728 return -EINVAL; 2732 return -EINVAL;
2729 if ((flags & SPI_MASTER_NO_TX) && xfer->tx_buf) 2733 if ((flags & SPI_CONTROLLER_NO_TX) && xfer->tx_buf)
2730 return -EINVAL; 2734 return -EINVAL;
2731 if ((flags & SPI_MASTER_NO_RX) && xfer->rx_buf) 2735 if ((flags & SPI_CONTROLLER_NO_RX) && xfer->rx_buf)
2732 return -EINVAL; 2736 return -EINVAL;
2733 } 2737 }
2734 } 2738 }
@@ -2748,13 +2752,12 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
2748 if (!xfer->speed_hz) 2752 if (!xfer->speed_hz)
2749 xfer->speed_hz = spi->max_speed_hz; 2753 xfer->speed_hz = spi->max_speed_hz;
2750 if (!xfer->speed_hz) 2754 if (!xfer->speed_hz)
2751 xfer->speed_hz = master->max_speed_hz; 2755 xfer->speed_hz = ctlr->max_speed_hz;
2752 2756
2753 if (master->max_speed_hz && 2757 if (ctlr->max_speed_hz && xfer->speed_hz > ctlr->max_speed_hz)
2754 xfer->speed_hz > master->max_speed_hz) 2758 xfer->speed_hz = ctlr->max_speed_hz;
2755 xfer->speed_hz = master->max_speed_hz;
2756 2759
2757 if (__spi_validate_bits_per_word(master, xfer->bits_per_word)) 2760 if (__spi_validate_bits_per_word(ctlr, xfer->bits_per_word))
2758 return -EINVAL; 2761 return -EINVAL;
2759 2762
2760 /* 2763 /*
@@ -2772,8 +2775,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
2772 if (xfer->len % w_size) 2775 if (xfer->len % w_size)
2773 return -EINVAL; 2776 return -EINVAL;
2774 2777
2775 if (xfer->speed_hz && master->min_speed_hz && 2778 if (xfer->speed_hz && ctlr->min_speed_hz &&
2776 xfer->speed_hz < master->min_speed_hz) 2779 xfer->speed_hz < ctlr->min_speed_hz)
2777 return -EINVAL; 2780 return -EINVAL;
2778 2781
2779 if (xfer->tx_buf && !xfer->tx_nbits) 2782 if (xfer->tx_buf && !xfer->tx_nbits)
@@ -2818,16 +2821,16 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
2818 2821
2819static int __spi_async(struct spi_device *spi, struct spi_message *message) 2822static int __spi_async(struct spi_device *spi, struct spi_message *message)
2820{ 2823{
2821 struct spi_master *master = spi->master; 2824 struct spi_controller *ctlr = spi->controller;
2822 2825
2823 message->spi = spi; 2826 message->spi = spi;
2824 2827
2825 SPI_STATISTICS_INCREMENT_FIELD(&master->statistics, spi_async); 2828 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, spi_async);
2826 SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, spi_async); 2829 SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, spi_async);
2827 2830
2828 trace_spi_message_submit(message); 2831 trace_spi_message_submit(message);
2829 2832
2830 return master->transfer(spi, message); 2833 return ctlr->transfer(spi, message);
2831} 2834}
2832 2835
2833/** 2836/**
@@ -2863,7 +2866,7 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
2863 */ 2866 */
2864int spi_async(struct spi_device *spi, struct spi_message *message) 2867int spi_async(struct spi_device *spi, struct spi_message *message)
2865{ 2868{
2866 struct spi_master *master = spi->master; 2869 struct spi_controller *ctlr = spi->controller;
2867 int ret; 2870 int ret;
2868 unsigned long flags; 2871 unsigned long flags;
2869 2872
@@ -2871,14 +2874,14 @@ int spi_async(struct spi_device *spi, struct spi_message *message)
2871 if (ret != 0) 2874 if (ret != 0)
2872 return ret; 2875 return ret;
2873 2876
2874 spin_lock_irqsave(&master->bus_lock_spinlock, flags); 2877 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags);
2875 2878
2876 if (master->bus_lock_flag) 2879 if (ctlr->bus_lock_flag)
2877 ret = -EBUSY; 2880 ret = -EBUSY;
2878 else 2881 else
2879 ret = __spi_async(spi, message); 2882 ret = __spi_async(spi, message);
2880 2883
2881 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags); 2884 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags);
2882 2885
2883 return ret; 2886 return ret;
2884} 2887}
@@ -2917,7 +2920,7 @@ EXPORT_SYMBOL_GPL(spi_async);
2917 */ 2920 */
2918int spi_async_locked(struct spi_device *spi, struct spi_message *message) 2921int spi_async_locked(struct spi_device *spi, struct spi_message *message)
2919{ 2922{
2920 struct spi_master *master = spi->master; 2923 struct spi_controller *ctlr = spi->controller;
2921 int ret; 2924 int ret;
2922 unsigned long flags; 2925 unsigned long flags;
2923 2926
@@ -2925,11 +2928,11 @@ int spi_async_locked(struct spi_device *spi, struct spi_message *message)
2925 if (ret != 0) 2928 if (ret != 0)
2926 return ret; 2929 return ret;
2927 2930
2928 spin_lock_irqsave(&master->bus_lock_spinlock, flags); 2931 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags);
2929 2932
2930 ret = __spi_async(spi, message); 2933 ret = __spi_async(spi, message);
2931 2934
2932 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags); 2935 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags);
2933 2936
2934 return ret; 2937 return ret;
2935 2938
@@ -2941,7 +2944,7 @@ int spi_flash_read(struct spi_device *spi,
2941 struct spi_flash_read_message *msg) 2944 struct spi_flash_read_message *msg)
2942 2945
2943{ 2946{
2944 struct spi_master *master = spi->master; 2947 struct spi_controller *master = spi->controller;
2945 struct device *rx_dev = NULL; 2948 struct device *rx_dev = NULL;
2946 int ret; 2949 int ret;
2947 2950
@@ -2995,7 +2998,7 @@ EXPORT_SYMBOL_GPL(spi_flash_read);
2995 2998
2996/*-------------------------------------------------------------------------*/ 2999/*-------------------------------------------------------------------------*/
2997 3000
2998/* Utility methods for SPI master protocol drivers, layered on 3001/* Utility methods for SPI protocol drivers, layered on
2999 * top of the core. Some other utility methods are defined as 3002 * top of the core. Some other utility methods are defined as
3000 * inline functions. 3003 * inline functions.
3001 */ 3004 */
@@ -3009,7 +3012,7 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message)
3009{ 3012{
3010 DECLARE_COMPLETION_ONSTACK(done); 3013 DECLARE_COMPLETION_ONSTACK(done);
3011 int status; 3014 int status;
3012 struct spi_master *master = spi->master; 3015 struct spi_controller *ctlr = spi->controller;
3013 unsigned long flags; 3016 unsigned long flags;
3014 3017
3015 status = __spi_validate(spi, message); 3018 status = __spi_validate(spi, message);
@@ -3020,7 +3023,7 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message)
3020 message->context = &done; 3023 message->context = &done;
3021 message->spi = spi; 3024 message->spi = spi;
3022 3025
3023 SPI_STATISTICS_INCREMENT_FIELD(&master->statistics, spi_sync); 3026 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, spi_sync);
3024 SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, spi_sync); 3027 SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, spi_sync);
3025 3028
3026 /* If we're not using the legacy transfer method then we will 3029 /* If we're not using the legacy transfer method then we will
@@ -3028,14 +3031,14 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message)
3028 * This code would be less tricky if we could remove the 3031 * This code would be less tricky if we could remove the
3029 * support for driver implemented message queues. 3032 * support for driver implemented message queues.
3030 */ 3033 */
3031 if (master->transfer == spi_queued_transfer) { 3034 if (ctlr->transfer == spi_queued_transfer) {
3032 spin_lock_irqsave(&master->bus_lock_spinlock, flags); 3035 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags);
3033 3036
3034 trace_spi_message_submit(message); 3037 trace_spi_message_submit(message);
3035 3038
3036 status = __spi_queued_transfer(spi, message, false); 3039 status = __spi_queued_transfer(spi, message, false);
3037 3040
3038 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags); 3041 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags);
3039 } else { 3042 } else {
3040 status = spi_async_locked(spi, message); 3043 status = spi_async_locked(spi, message);
3041 } 3044 }
@@ -3044,12 +3047,12 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message)
3044 /* Push out the messages in the calling context if we 3047 /* Push out the messages in the calling context if we
3045 * can. 3048 * can.
3046 */ 3049 */
3047 if (master->transfer == spi_queued_transfer) { 3050 if (ctlr->transfer == spi_queued_transfer) {
3048 SPI_STATISTICS_INCREMENT_FIELD(&master->statistics, 3051 SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics,
3049 spi_sync_immediate); 3052 spi_sync_immediate);
3050 SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, 3053 SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics,
3051 spi_sync_immediate); 3054 spi_sync_immediate);
3052 __spi_pump_messages(master, false); 3055 __spi_pump_messages(ctlr, false);
3053 } 3056 }
3054 3057
3055 wait_for_completion(&done); 3058 wait_for_completion(&done);
@@ -3084,9 +3087,9 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
3084{ 3087{
3085 int ret; 3088 int ret;
3086 3089
3087 mutex_lock(&spi->master->bus_lock_mutex); 3090 mutex_lock(&spi->controller->bus_lock_mutex);
3088 ret = __spi_sync(spi, message); 3091 ret = __spi_sync(spi, message);
3089 mutex_unlock(&spi->master->bus_lock_mutex); 3092 mutex_unlock(&spi->controller->bus_lock_mutex);
3090 3093
3091 return ret; 3094 return ret;
3092} 3095}
@@ -3116,7 +3119,7 @@ EXPORT_SYMBOL_GPL(spi_sync_locked);
3116 3119
3117/** 3120/**
3118 * spi_bus_lock - obtain a lock for exclusive SPI bus usage 3121 * spi_bus_lock - obtain a lock for exclusive SPI bus usage
3119 * @master: SPI bus master that should be locked for exclusive bus access 3122 * @ctlr: SPI bus master that should be locked for exclusive bus access
3120 * Context: can sleep 3123 * Context: can sleep
3121 * 3124 *
3122 * This call may only be used from a context that may sleep. The sleep 3125 * This call may only be used from a context that may sleep. The sleep
@@ -3129,15 +3132,15 @@ EXPORT_SYMBOL_GPL(spi_sync_locked);
3129 * 3132 *
3130 * Return: always zero. 3133 * Return: always zero.
3131 */ 3134 */
3132int spi_bus_lock(struct spi_master *master) 3135int spi_bus_lock(struct spi_controller *ctlr)
3133{ 3136{
3134 unsigned long flags; 3137 unsigned long flags;
3135 3138
3136 mutex_lock(&master->bus_lock_mutex); 3139 mutex_lock(&ctlr->bus_lock_mutex);
3137 3140
3138 spin_lock_irqsave(&master->bus_lock_spinlock, flags); 3141 spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags);
3139 master->bus_lock_flag = 1; 3142 ctlr->bus_lock_flag = 1;
3140 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags); 3143 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags);
3141 3144
3142 /* mutex remains locked until spi_bus_unlock is called */ 3145 /* mutex remains locked until spi_bus_unlock is called */
3143 3146
@@ -3147,7 +3150,7 @@ EXPORT_SYMBOL_GPL(spi_bus_lock);
3147 3150
3148/** 3151/**
3149 * spi_bus_unlock - release the lock for exclusive SPI bus usage 3152 * spi_bus_unlock - release the lock for exclusive SPI bus usage
3150 * @master: SPI bus master that was locked for exclusive bus access 3153 * @ctlr: SPI bus master that was locked for exclusive bus access
3151 * Context: can sleep 3154 * Context: can sleep
3152 * 3155 *
3153 * This call may only be used from a context that may sleep. The sleep 3156 * This call may only be used from a context that may sleep. The sleep
@@ -3158,11 +3161,11 @@ EXPORT_SYMBOL_GPL(spi_bus_lock);
3158 * 3161 *
3159 * Return: always zero. 3162 * Return: always zero.
3160 */ 3163 */
3161int spi_bus_unlock(struct spi_master *master) 3164int spi_bus_unlock(struct spi_controller *ctlr)
3162{ 3165{
3163 master->bus_lock_flag = 0; 3166 ctlr->bus_lock_flag = 0;
3164 3167
3165 mutex_unlock(&master->bus_lock_mutex); 3168 mutex_unlock(&ctlr->bus_lock_mutex);
3166 3169
3167 return 0; 3170 return 0;
3168} 3171}
@@ -3264,48 +3267,48 @@ static struct spi_device *of_find_spi_device_by_node(struct device_node *node)
3264 return dev ? to_spi_device(dev) : NULL; 3267 return dev ? to_spi_device(dev) : NULL;
3265} 3268}
3266 3269
3267static int __spi_of_master_match(struct device *dev, const void *data) 3270static int __spi_of_controller_match(struct device *dev, const void *data)
3268{ 3271{
3269 return dev->of_node == data; 3272 return dev->of_node == data;
3270} 3273}
3271 3274
3272/* the spi masters are not using spi_bus, so we find it with another way */ 3275/* the spi controllers are not using spi_bus, so we find it with another way */
3273static struct spi_master *of_find_spi_master_by_node(struct device_node *node) 3276static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
3274{ 3277{
3275 struct device *dev; 3278 struct device *dev;
3276 3279
3277 dev = class_find_device(&spi_master_class, NULL, node, 3280 dev = class_find_device(&spi_master_class, NULL, node,
3278 __spi_of_master_match); 3281 __spi_of_controller_match);
3279 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) 3282 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
3280 dev = class_find_device(&spi_slave_class, NULL, node, 3283 dev = class_find_device(&spi_slave_class, NULL, node,
3281 __spi_of_master_match); 3284 __spi_of_controller_match);
3282 if (!dev) 3285 if (!dev)
3283 return NULL; 3286 return NULL;
3284 3287
3285 /* reference got in class_find_device */ 3288 /* reference got in class_find_device */
3286 return container_of(dev, struct spi_master, dev); 3289 return container_of(dev, struct spi_controller, dev);
3287} 3290}
3288 3291
3289static int of_spi_notify(struct notifier_block *nb, unsigned long action, 3292static int of_spi_notify(struct notifier_block *nb, unsigned long action,
3290 void *arg) 3293 void *arg)
3291{ 3294{
3292 struct of_reconfig_data *rd = arg; 3295 struct of_reconfig_data *rd = arg;
3293 struct spi_master *master; 3296 struct spi_controller *ctlr;
3294 struct spi_device *spi; 3297 struct spi_device *spi;
3295 3298
3296 switch (of_reconfig_get_state_change(action, arg)) { 3299 switch (of_reconfig_get_state_change(action, arg)) {
3297 case OF_RECONFIG_CHANGE_ADD: 3300 case OF_RECONFIG_CHANGE_ADD:
3298 master = of_find_spi_master_by_node(rd->dn->parent); 3301 ctlr = of_find_spi_controller_by_node(rd->dn->parent);
3299 if (master == NULL) 3302 if (ctlr == NULL)
3300 return NOTIFY_OK; /* not for us */ 3303 return NOTIFY_OK; /* not for us */
3301 3304
3302 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) { 3305 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) {
3303 put_device(&master->dev); 3306 put_device(&ctlr->dev);
3304 return NOTIFY_OK; 3307 return NOTIFY_OK;
3305 } 3308 }
3306 3309
3307 spi = of_register_spi_device(master, rd->dn); 3310 spi = of_register_spi_device(ctlr, rd->dn);
3308 put_device(&master->dev); 3311 put_device(&ctlr->dev);
3309 3312
3310 if (IS_ERR(spi)) { 3313 if (IS_ERR(spi)) {
3311 pr_err("%s: failed to create for '%s'\n", 3314 pr_err("%s: failed to create for '%s'\n",
@@ -3344,7 +3347,7 @@ extern struct notifier_block spi_of_notifier;
3344#endif /* IS_ENABLED(CONFIG_OF_DYNAMIC) */ 3347#endif /* IS_ENABLED(CONFIG_OF_DYNAMIC) */
3345 3348
3346#if IS_ENABLED(CONFIG_ACPI) 3349#if IS_ENABLED(CONFIG_ACPI)
3347static int spi_acpi_master_match(struct device *dev, const void *data) 3350static int spi_acpi_controller_match(struct device *dev, const void *data)
3348{ 3351{
3349 return ACPI_COMPANION(dev->parent) == data; 3352 return ACPI_COMPANION(dev->parent) == data;
3350} 3353}
@@ -3354,19 +3357,19 @@ static int spi_acpi_device_match(struct device *dev, void *data)
3354 return ACPI_COMPANION(dev) == data; 3357 return ACPI_COMPANION(dev) == data;
3355} 3358}
3356 3359
3357static struct spi_master *acpi_spi_find_master_by_adev(struct acpi_device *adev) 3360static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
3358{ 3361{
3359 struct device *dev; 3362 struct device *dev;
3360 3363
3361 dev = class_find_device(&spi_master_class, NULL, adev, 3364 dev = class_find_device(&spi_master_class, NULL, adev,
3362 spi_acpi_master_match); 3365 spi_acpi_controller_match);
3363 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE)) 3366 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
3364 dev = class_find_device(&spi_slave_class, NULL, adev, 3367 dev = class_find_device(&spi_slave_class, NULL, adev,
3365 spi_acpi_master_match); 3368 spi_acpi_controller_match);
3366 if (!dev) 3369 if (!dev)
3367 return NULL; 3370 return NULL;
3368 3371
3369 return container_of(dev, struct spi_master, dev); 3372 return container_of(dev, struct spi_controller, dev);
3370} 3373}
3371 3374
3372static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev) 3375static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
@@ -3382,17 +3385,17 @@ static int acpi_spi_notify(struct notifier_block *nb, unsigned long value,
3382 void *arg) 3385 void *arg)
3383{ 3386{
3384 struct acpi_device *adev = arg; 3387 struct acpi_device *adev = arg;
3385 struct spi_master *master; 3388 struct spi_controller *ctlr;
3386 struct spi_device *spi; 3389 struct spi_device *spi;
3387 3390
3388 switch (value) { 3391 switch (value) {
3389 case ACPI_RECONFIG_DEVICE_ADD: 3392 case ACPI_RECONFIG_DEVICE_ADD:
3390 master = acpi_spi_find_master_by_adev(adev->parent); 3393 ctlr = acpi_spi_find_controller_by_adev(adev->parent);
3391 if (!master) 3394 if (!ctlr)
3392 break; 3395 break;
3393 3396
3394 acpi_register_spi_device(master, adev); 3397 acpi_register_spi_device(ctlr, adev);
3395 put_device(&master->dev); 3398 put_device(&ctlr->dev);
3396 break; 3399 break;
3397 case ACPI_RECONFIG_DEVICE_REMOVE: 3400 case ACPI_RECONFIG_DEVICE_REMOVE:
3398 if (!acpi_device_enumerated(adev)) 3401 if (!acpi_device_enumerated(adev))
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 0a78745e5766..7b2170bfd6e7 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -24,7 +24,7 @@
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
@@ -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
@@ -327,8 +329,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
327 * the device whose settings are being modified. 329 * the device whose settings are being modified.
328 * @transfer: adds a message to the controller's transfer queue. 330 * @transfer: adds a message to the controller's transfer queue.
329 * @cleanup: frees controller-specific state 331 * @cleanup: frees controller-specific state
330 * @can_dma: determine whether this master supports DMA 332 * @can_dma: determine whether this controller supports DMA
331 * @queued: whether this master is providing an internal message queue 333 * @queued: whether this controller is providing an internal message queue
332 * @kworker: thread struct for message pump 334 * @kworker: thread struct for message pump
333 * @kworker_task: pointer to task for message pump kworker thread 335 * @kworker_task: pointer to task for message pump kworker thread
334 * @pump_messages: work struct for scheduling work to the message pump 336 * @pump_messages: work struct for scheduling work to the message pump
@@ -384,7 +386,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
384 * @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
385 * number. Any individual value may be -ENOENT for CS lines that 387 * number. Any individual value may be -ENOENT for CS lines that
386 * are not GPIOs (driven by the SPI controller itself). 388 * are not GPIOs (driven by the SPI controller itself).
387 * @statistics: statistics for the spi_master 389 * @statistics: statistics for the spi_controller
388 * @dma_tx: DMA transmit channel 390 * @dma_tx: DMA transmit channel
389 * @dma_rx: DMA receive channel 391 * @dma_rx: DMA receive channel
390 * @dummy_rx: dummy receive buffer for full-duplex devices 392 * @dummy_rx: dummy receive buffer for full-duplex devices
@@ -393,7 +395,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
393 * what Linux expects, this optional hook can be used to translate 395 * what Linux expects, this optional hook can be used to translate
394 * between the two. 396 * between the two.
395 * 397 *
396 * Each SPI master controller can communicate with one or more @spi_device 398 * Each SPI controller can communicate with one or more @spi_device
397 * 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
398 * 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
399 * different clock rate, since those shared signals are ignored unless 401 * different clock rate, since those shared signals are ignored unless
@@ -404,7 +406,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
404 * 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
405 * message's completion function when the transaction completes. 407 * message's completion function when the transaction completes.
406 */ 408 */
407struct spi_master { 409struct spi_controller {
408 struct device dev; 410 struct device dev;
409 411
410 struct list_head list; 412 struct list_head list;
@@ -442,12 +444,13 @@ struct spi_master {
442 444
443 /* other constraints relevant to this driver */ 445 /* other constraints relevant to this driver */
444 u16 flags; 446 u16 flags;
445#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 */
446#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 */
447#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 */
448#define SPI_MASTER_MUST_RX BIT(3) /* requires rx */ 450#define SPI_CONTROLLER_MUST_RX BIT(3) /* requires rx */
449#define SPI_MASTER_MUST_TX BIT(4) /* requires tx */ 451#define SPI_CONTROLLER_MUST_TX BIT(4) /* requires tx */
450#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 */
451 454
452 /* flag indicating this is an SPI slave controller */ 455 /* flag indicating this is an SPI slave controller */
453 bool slave; 456 bool slave;
@@ -485,8 +488,8 @@ struct spi_master {
485 * any other request management 488 * any other request management
486 * + To a given spi_device, message queueing is pure fifo 489 * + To a given spi_device, message queueing is pure fifo
487 * 490 *
488 * + The master's main job is to process its message queue, 491 * + The controller's main job is to process its message queue,
489 * selecting a chip then transferring data 492 * selecting a chip (for masters), then transferring data
490 * + If there are multiple spi_device children, the i/o queue 493 * + If there are multiple spi_device children, the i/o queue
491 * arbitration algorithm is unspecified (round robin, fifo, 494 * arbitration algorithm is unspecified (round robin, fifo,
492 * priority, reservations, preemption, etc) 495 * priority, reservations, preemption, etc)
@@ -499,7 +502,7 @@ struct spi_master {
499 int (*transfer)(struct spi_device *spi, 502 int (*transfer)(struct spi_device *spi,
500 struct spi_message *mesg); 503 struct spi_message *mesg);
501 504
502 /* called on release() to free memory provided by spi_master */ 505 /* called on release() to free memory provided by spi_controller */
503 void (*cleanup)(struct spi_device *spi); 506 void (*cleanup)(struct spi_device *spi);
504 507
505 /* 508 /*
@@ -509,13 +512,13 @@ struct spi_master {
509 * 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
510 * while the device is prepared. 513 * while the device is prepared.
511 */ 514 */
512 bool (*can_dma)(struct spi_master *master, 515 bool (*can_dma)(struct spi_controller *ctlr,
513 struct spi_device *spi, 516 struct spi_device *spi,
514 struct spi_transfer *xfer); 517 struct spi_transfer *xfer);
515 518
516 /* 519 /*
517 * These hooks are for drivers that want to use the generic 520 * These hooks are for drivers that want to use the generic
518 * master transfer queueing mechanism. If these are used, the 521 * controller transfer queueing mechanism. If these are used, the
519 * transfer() function above must NOT be specified by the driver. 522 * transfer() function above must NOT be specified by the driver.
520 * 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.
521 */ 524 */
@@ -536,15 +539,15 @@ struct spi_master {
536 struct completion xfer_completion; 539 struct completion xfer_completion;
537 size_t max_dma_len; 540 size_t max_dma_len;
538 541
539 int (*prepare_transfer_hardware)(struct spi_master *master); 542 int (*prepare_transfer_hardware)(struct spi_controller *ctlr);
540 int (*transfer_one_message)(struct spi_master *master, 543 int (*transfer_one_message)(struct spi_controller *ctlr,
541 struct spi_message *mesg); 544 struct spi_message *mesg);
542 int (*unprepare_transfer_hardware)(struct spi_master *master); 545 int (*unprepare_transfer_hardware)(struct spi_controller *ctlr);
543 int (*prepare_message)(struct spi_master *master, 546 int (*prepare_message)(struct spi_controller *ctlr,
544 struct spi_message *message); 547 struct spi_message *message);
545 int (*unprepare_message)(struct spi_master *master, 548 int (*unprepare_message)(struct spi_controller *ctlr,
546 struct spi_message *message); 549 struct spi_message *message);
547 int (*slave_abort)(struct spi_master *spi); 550 int (*slave_abort)(struct spi_controller *ctlr);
548 int (*spi_flash_read)(struct spi_device *spi, 551 int (*spi_flash_read)(struct spi_device *spi,
549 struct spi_flash_read_message *msg); 552 struct spi_flash_read_message *msg);
550 bool (*spi_flash_can_dma)(struct spi_device *spi, 553 bool (*spi_flash_can_dma)(struct spi_device *spi,
@@ -556,9 +559,9 @@ struct spi_master {
556 * of transfer_one_message() provied by the core. 559 * of transfer_one_message() provied by the core.
557 */ 560 */
558 void (*set_cs)(struct spi_device *spi, bool enable); 561 void (*set_cs)(struct spi_device *spi, bool enable);
559 int (*transfer_one)(struct spi_master *master, struct spi_device *spi, 562 int (*transfer_one)(struct spi_controller *ctlr, struct spi_device *spi,
560 struct spi_transfer *transfer); 563 struct spi_transfer *transfer);
561 void (*handle_err)(struct spi_master *master, 564 void (*handle_err)(struct spi_controller *ctlr,
562 struct spi_message *message); 565 struct spi_message *message);
563 566
564 /* gpio chip select */ 567 /* gpio chip select */
@@ -575,58 +578,59 @@ struct spi_master {
575 void *dummy_rx; 578 void *dummy_rx;
576 void *dummy_tx; 579 void *dummy_tx;
577 580
578 int (*fw_translate_cs)(struct spi_master *master, unsigned cs); 581 int (*fw_translate_cs)(struct spi_controller *ctlr, unsigned cs);
579}; 582};
580 583
581static inline void *spi_master_get_devdata(struct spi_master *master) 584static inline void *spi_controller_get_devdata(struct spi_controller *ctlr)
582{ 585{
583 return dev_get_drvdata(&master->dev); 586 return dev_get_drvdata(&ctlr->dev);
584} 587}
585 588
586static 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)
587{ 591{
588 dev_set_drvdata(&master->dev, data); 592 dev_set_drvdata(&ctlr->dev, data);
589} 593}
590 594
591static inline struct spi_master *spi_master_get(struct spi_master *master) 595static inline struct spi_controller *spi_controller_get(struct spi_controller *ctlr)
592{ 596{
593 if (!master || !get_device(&master->dev)) 597 if (!ctlr || !get_device(&ctlr->dev))
594 return NULL; 598 return NULL;
595 return master; 599 return ctlr;
596} 600}
597 601
598static inline void spi_master_put(struct spi_master *master) 602static inline void spi_controller_put(struct spi_controller *ctlr)
599{ 603{
600 if (master) 604 if (ctlr)
601 put_device(&master->dev); 605 put_device(&ctlr->dev);
602} 606}
603 607
604static inline bool spi_controller_is_slave(struct spi_master *ctlr) 608static inline bool spi_controller_is_slave(struct spi_controller *ctlr)
605{ 609{
606 return IS_ENABLED(CONFIG_SPI_SLAVE) && ctlr->slave; 610 return IS_ENABLED(CONFIG_SPI_SLAVE) && ctlr->slave;
607} 611}
608 612
609/* PM calls that need to be issued by the driver */ 613/* PM calls that need to be issued by the driver */
610extern int spi_master_suspend(struct spi_master *master); 614extern int spi_controller_suspend(struct spi_controller *ctlr);
611extern int spi_master_resume(struct spi_master *master); 615extern int spi_controller_resume(struct spi_controller *ctlr);
612 616
613/* Calls the driver make to interact with the message queue */ 617/* Calls the driver make to interact with the message queue */
614extern 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);
615extern void spi_finalize_current_message(struct spi_master *master); 619extern void spi_finalize_current_message(struct spi_controller *ctlr);
616extern void spi_finalize_current_transfer(struct spi_master *master); 620extern void spi_finalize_current_transfer(struct spi_controller *ctlr);
617 621
618/* the spi driver core manages memory for the spi_master classdev */ 622/* the spi driver core manages memory for the spi_controller classdev */
619extern struct spi_master *__spi_alloc_controller(struct device *host, 623extern struct spi_controller *__spi_alloc_controller(struct device *host,
620 unsigned int size, bool slave); 624 unsigned int size, bool slave);
621 625
622static inline struct spi_master *spi_alloc_master(struct device *host, 626static inline struct spi_controller *spi_alloc_master(struct device *host,
623 unsigned int size) 627 unsigned int size)
624{ 628{
625 return __spi_alloc_controller(host, size, false); 629 return __spi_alloc_controller(host, size, false);
626} 630}
627 631
628static inline struct spi_master *spi_alloc_slave(struct device *host, 632static inline struct spi_controller *spi_alloc_slave(struct device *host,
629 unsigned int size) 633 unsigned int size)
630{ 634{
631 if (!IS_ENABLED(CONFIG_SPI_SLAVE)) 635 if (!IS_ENABLED(CONFIG_SPI_SLAVE))
632 return NULL; 636 return NULL;
@@ -634,18 +638,18 @@ static inline struct spi_master *spi_alloc_slave(struct device *host,
634 return __spi_alloc_controller(host, size, true); 638 return __spi_alloc_controller(host, size, true);
635} 639}
636 640
637extern int spi_register_master(struct spi_master *master); 641extern int spi_register_controller(struct spi_controller *ctlr);
638extern int devm_spi_register_master(struct device *dev, 642extern int devm_spi_register_controller(struct device *dev,
639 struct spi_master *master); 643 struct spi_controller *ctlr);
640extern void spi_unregister_master(struct spi_master *master); 644extern void spi_unregister_controller(struct spi_controller *ctlr);
641 645
642extern struct spi_master *spi_busnum_to_master(u16 busnum); 646extern struct spi_controller *spi_busnum_to_master(u16 busnum);
643 647
644/* 648/*
645 * SPI resource management while processing a SPI message 649 * SPI resource management while processing a SPI message
646 */ 650 */
647 651
648typedef void (*spi_res_release_t)(struct spi_master *master, 652typedef void (*spi_res_release_t)(struct spi_controller *ctlr,
649 struct spi_message *msg, 653 struct spi_message *msg,
650 void *res); 654 void *res);
651 655
@@ -670,7 +674,7 @@ extern void *spi_res_alloc(struct spi_device *spi,
670extern void spi_res_add(struct spi_message *message, void *res); 674extern void spi_res_add(struct spi_message *message, void *res);
671extern void spi_res_free(void *res); 675extern void spi_res_free(void *res);
672 676
673extern void spi_res_release(struct spi_master *master, 677extern void spi_res_release(struct spi_controller *ctlr,
674 struct spi_message *message); 678 struct spi_message *message);
675 679
676/*---------------------------------------------------------------------------*/ 680/*---------------------------------------------------------------------------*/
@@ -854,7 +858,7 @@ struct spi_message {
854 858
855 /* for optional use by whatever driver currently owns the 859 /* for optional use by whatever driver currently owns the
856 * spi_message ... between calls to spi_async and then later 860 * spi_message ... between calls to spi_async and then later
857 * complete(), that's the spi_master controller driver. 861 * complete(), that's the spi_controller controller driver.
858 */ 862 */
859 struct list_head queue; 863 struct list_head queue;
860 void *state; 864 void *state;
@@ -943,21 +947,22 @@ extern int spi_slave_abort(struct spi_device *spi);
943static inline size_t 947static inline size_t
944spi_max_message_size(struct spi_device *spi) 948spi_max_message_size(struct spi_device *spi)
945{ 949{
946 struct spi_master *master = spi->master; 950 struct spi_controller *ctlr = spi->controller;
947 if (!master->max_message_size) 951
952 if (!ctlr->max_message_size)
948 return SIZE_MAX; 953 return SIZE_MAX;
949 return master->max_message_size(spi); 954 return ctlr->max_message_size(spi);
950} 955}
951 956
952static inline size_t 957static inline size_t
953spi_max_transfer_size(struct spi_device *spi) 958spi_max_transfer_size(struct spi_device *spi)
954{ 959{
955 struct spi_master *master = spi->master; 960 struct spi_controller *ctlr = spi->controller;
956 size_t tr_max = SIZE_MAX; 961 size_t tr_max = SIZE_MAX;
957 size_t msg_max = spi_max_message_size(spi); 962 size_t msg_max = spi_max_message_size(spi);
958 963
959 if (master->max_transfer_size) 964 if (ctlr->max_transfer_size)
960 tr_max = master->max_transfer_size(spi); 965 tr_max = ctlr->max_transfer_size(spi);
961 966
962 /* transfer size limit must not be greater than messsage size limit */ 967 /* transfer size limit must not be greater than messsage size limit */
963 return min(tr_max, msg_max); 968 return min(tr_max, msg_max);
@@ -968,7 +973,7 @@ spi_max_transfer_size(struct spi_device *spi)
968/* SPI transfer replacement methods which make use of spi_res */ 973/* SPI transfer replacement methods which make use of spi_res */
969 974
970struct spi_replaced_transfers; 975struct spi_replaced_transfers;
971typedef void (*spi_replaced_release_t)(struct spi_master *master, 976typedef void (*spi_replaced_release_t)(struct spi_controller *ctlr,
972 struct spi_message *msg, 977 struct spi_message *msg,
973 struct spi_replaced_transfers *res); 978 struct spi_replaced_transfers *res);
974/** 979/**
@@ -1012,7 +1017,7 @@ extern struct spi_replaced_transfers *spi_replace_transfers(
1012 1017
1013/* SPI transfer transformation methods */ 1018/* SPI transfer transformation methods */
1014 1019
1015extern int spi_split_transfers_maxsize(struct spi_master *master, 1020extern int spi_split_transfers_maxsize(struct spi_controller *ctlr,
1016 struct spi_message *msg, 1021 struct spi_message *msg,
1017 size_t maxsize, 1022 size_t maxsize,
1018 gfp_t gfp); 1023 gfp_t gfp);
@@ -1026,8 +1031,8 @@ extern int spi_split_transfers_maxsize(struct spi_master *master,
1026 1031
1027extern int spi_sync(struct spi_device *spi, struct spi_message *message); 1032extern int spi_sync(struct spi_device *spi, struct spi_message *message);
1028extern 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);
1029extern int spi_bus_lock(struct spi_master *master); 1034extern int spi_bus_lock(struct spi_controller *ctlr);
1030extern int spi_bus_unlock(struct spi_master *master); 1035extern int spi_bus_unlock(struct spi_controller *ctlr);
1031 1036
1032/** 1037/**
1033 * spi_sync_transfer - synchronous SPI data transfer 1038 * spi_sync_transfer - synchronous SPI data transfer
@@ -1212,9 +1217,9 @@ struct spi_flash_read_message {
1212/* SPI core interface for flash read support */ 1217/* SPI core interface for flash read support */
1213static inline bool spi_flash_read_supported(struct spi_device *spi) 1218static inline bool spi_flash_read_supported(struct spi_device *spi)
1214{ 1219{
1215 return spi->master->spi_flash_read && 1220 return spi->controller->spi_flash_read &&
1216 (!spi->master->flash_read_supported || 1221 (!spi->controller->flash_read_supported ||
1217 spi->master->flash_read_supported(spi)); 1222 spi->controller->flash_read_supported(spi));
1218} 1223}
1219 1224
1220int spi_flash_read(struct spi_device *spi, 1225int spi_flash_read(struct spi_device *spi,
@@ -1247,7 +1252,7 @@ int spi_flash_read(struct spi_device *spi,
1247 * @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.
1248 * @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
1249 * from the chip datasheet and board-specific signal quality issues. 1254 * from the chip datasheet and board-specific signal quality issues.
1250 * @bus_num: Identifies which spi_master parents the spi_device; unused 1255 * @bus_num: Identifies which spi_controller parents the spi_device; unused
1251 * by spi_new_device(), and otherwise depends on board wiring. 1256 * by spi_new_device(), and otherwise depends on board wiring.
1252 * @chip_select: Initializes spi_device.chip_select; depends on how 1257 * @chip_select: Initializes spi_device.chip_select; depends on how
1253 * the board is wired. 1258 * the board is wired.
@@ -1288,7 +1293,7 @@ struct spi_board_info {
1288 1293
1289 1294
1290 /* 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
1291 * spi_master that will probably be registered later. 1296 * spi_controller that will probably be registered later.
1292 * 1297 *
1293 * chip_select reflects how this chip is wired to that master; 1298 * chip_select reflects how this chip is wired to that master;
1294 * it's less than num_chipselect. 1299 * it's less than num_chipselect.
@@ -1322,7 +1327,7 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
1322/* If you're hotplugging an adapter with devices (parport, usb, etc) 1327/* If you're hotplugging an adapter with devices (parport, usb, etc)
1323 * 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
1324 * spi_unregister_device() to start making that device vanish, but 1329 * spi_unregister_device() to start making that device vanish, but
1325 * normally that would be handled by spi_unregister_master(). 1330 * normally that would be handled by spi_unregister_controller().
1326 * 1331 *
1327 * 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
1328 * stage registration sequence for each spi_device. This gives the caller 1333 * stage registration sequence for each spi_device. This gives the caller
@@ -1331,13 +1336,13 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
1331 * be defined using the board info. 1336 * be defined using the board info.
1332 */ 1337 */
1333extern struct spi_device * 1338extern struct spi_device *
1334spi_alloc_device(struct spi_master *master); 1339spi_alloc_device(struct spi_controller *ctlr);
1335 1340
1336extern int 1341extern int
1337spi_add_device(struct spi_device *spi); 1342spi_add_device(struct spi_device *spi);
1338 1343
1339extern struct spi_device * 1344extern struct spi_device *
1340spi_new_device(struct spi_master *, struct spi_board_info *); 1345spi_new_device(struct spi_controller *, struct spi_board_info *);
1341 1346
1342extern void spi_unregister_device(struct spi_device *spi); 1347extern void spi_unregister_device(struct spi_device *spi);
1343 1348
@@ -1345,9 +1350,32 @@ extern const struct spi_device_id *
1345spi_get_device_id(const struct spi_device *sdev); 1350spi_get_device_id(const struct spi_device *sdev);
1346 1351
1347static inline bool 1352static inline bool
1348spi_transfer_is_last(struct spi_master *master, struct spi_transfer *xfer) 1353spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)
1349{ 1354{
1350 return list_is_last(&xfer->transfer_list, &master->cur_msg->transfers); 1355 return list_is_last(&xfer->transfer_list, &ctlr->cur_msg->transfers);
1351} 1356}
1352 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
1353#endif /* __LINUX_SPI_H */ 1381#endif /* __LINUX_SPI_H */
diff --git a/include/trace/events/spi.h b/include/trace/events/spi.h
index 7e02c983bbe2..f9f702b6ae2e 100644
--- a/include/trace/events/spi.h
+++ b/include/trace/events/spi.h
@@ -7,37 +7,37 @@
7#include <linux/ktime.h> 7#include <linux/ktime.h>
8#include <linux/tracepoint.h> 8#include <linux/tracepoint.h>
9 9
10DECLARE_EVENT_CLASS(spi_master, 10DECLARE_EVENT_CLASS(spi_controller,
11 11
12 TP_PROTO(struct spi_master *master), 12 TP_PROTO(struct spi_controller *controller),
13 13
14 TP_ARGS(master), 14 TP_ARGS(controller),
15 15
16 TP_STRUCT__entry( 16 TP_STRUCT__entry(
17 __field( int, bus_num ) 17 __field( int, bus_num )
18 ), 18 ),
19 19
20 TP_fast_assign( 20 TP_fast_assign(
21 __entry->bus_num = master->bus_num; 21 __entry->bus_num = controller->bus_num;
22 ), 22 ),
23 23
24 TP_printk("spi%d", (int)__entry->bus_num) 24 TP_printk("spi%d", (int)__entry->bus_num)
25 25
26); 26);
27 27
28DEFINE_EVENT(spi_master, spi_master_idle, 28DEFINE_EVENT(spi_controller, spi_controller_idle,
29 29
30 TP_PROTO(struct spi_master *master), 30 TP_PROTO(struct spi_controller *controller),
31 31
32 TP_ARGS(master) 32 TP_ARGS(controller)
33 33
34); 34);
35 35
36DEFINE_EVENT(spi_master, spi_master_busy, 36DEFINE_EVENT(spi_controller, spi_controller_busy,
37 37
38 TP_PROTO(struct spi_master *master), 38 TP_PROTO(struct spi_controller *controller),
39 39
40 TP_ARGS(master) 40 TP_ARGS(controller)
41 41
42); 42);
43 43
@@ -54,7 +54,7 @@ DECLARE_EVENT_CLASS(spi_message,
54 ), 54 ),
55 55
56 TP_fast_assign( 56 TP_fast_assign(
57 __entry->bus_num = msg->spi->master->bus_num; 57 __entry->bus_num = msg->spi->controller->bus_num;
58 __entry->chip_select = msg->spi->chip_select; 58 __entry->chip_select = msg->spi->chip_select;
59 __entry->msg = msg; 59 __entry->msg = msg;
60 ), 60 ),
@@ -95,7 +95,7 @@ TRACE_EVENT(spi_message_done,
95 ), 95 ),
96 96
97 TP_fast_assign( 97 TP_fast_assign(
98 __entry->bus_num = msg->spi->master->bus_num; 98 __entry->bus_num = msg->spi->controller->bus_num;
99 __entry->chip_select = msg->spi->chip_select; 99 __entry->chip_select = msg->spi->chip_select;
100 __entry->msg = msg; 100 __entry->msg = msg;
101 __entry->frame = msg->frame_length; 101 __entry->frame = msg->frame_length;
@@ -122,7 +122,7 @@ DECLARE_EVENT_CLASS(spi_transfer,
122 ), 122 ),
123 123
124 TP_fast_assign( 124 TP_fast_assign(
125 __entry->bus_num = msg->spi->master->bus_num; 125 __entry->bus_num = msg->spi->controller->bus_num;
126 __entry->chip_select = msg->spi->chip_select; 126 __entry->chip_select = msg->spi->chip_select;
127 __entry->xfer = xfer; 127 __entry->xfer = xfer;
128 __entry->len = xfer->len; 128 __entry->len = xfer->len;