aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 19ee901577da..6f193b02a9e8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -33,7 +33,7 @@
33#include <linux/of_gpio.h> 33#include <linux/of_gpio.h>
34#include <linux/pm_runtime.h> 34#include <linux/pm_runtime.h>
35#include <linux/export.h> 35#include <linux/export.h>
36#include <linux/sched.h> 36#include <linux/sched/rt.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/kthread.h> 38#include <linux/kthread.h>
39#include <linux/ioport.h> 39#include <linux/ioport.h>
@@ -1059,15 +1059,14 @@ EXPORT_SYMBOL_GPL(spi_alloc_master);
1059#ifdef CONFIG_OF 1059#ifdef CONFIG_OF
1060static int of_spi_register_master(struct spi_master *master) 1060static int of_spi_register_master(struct spi_master *master)
1061{ 1061{
1062 u16 nb; 1062 int nb, i, *cs;
1063 int i, *cs;
1064 struct device_node *np = master->dev.of_node; 1063 struct device_node *np = master->dev.of_node;
1065 1064
1066 if (!np) 1065 if (!np)
1067 return 0; 1066 return 0;
1068 1067
1069 nb = of_gpio_named_count(np, "cs-gpios"); 1068 nb = of_gpio_named_count(np, "cs-gpios");
1070 master->num_chipselect = max(nb, master->num_chipselect); 1069 master->num_chipselect = max(nb, (int)master->num_chipselect);
1071 1070
1072 if (nb < 1) 1071 if (nb < 1)
1073 return 0; 1072 return 0;
@@ -1080,7 +1079,8 @@ static int of_spi_register_master(struct spi_master *master)
1080 if (!master->cs_gpios) 1079 if (!master->cs_gpios)
1081 return -ENOMEM; 1080 return -ENOMEM;
1082 1081
1083 memset(cs, -EINVAL, master->num_chipselect); 1082 for (i = 0; i < master->num_chipselect; i++)
1083 cs[i] = -EINVAL;
1084 1084
1085 for (i = 0; i < nb; i++) 1085 for (i = 0; i < nb; i++)
1086 cs[i] = of_get_named_gpio(np, "cs-gpios", i); 1086 cs[i] = of_get_named_gpio(np, "cs-gpios", i);
@@ -1135,6 +1135,9 @@ int spi_register_master(struct spi_master *master)
1135 if (master->num_chipselect == 0) 1135 if (master->num_chipselect == 0)
1136 return -EINVAL; 1136 return -EINVAL;
1137 1137
1138 if ((master->bus_num < 0) && master->dev.of_node)
1139 master->bus_num = of_alias_get_id(master->dev.of_node, "spi");
1140
1138 /* convention: dynamically assigned bus IDs count down from the max */ 1141 /* convention: dynamically assigned bus IDs count down from the max */
1139 if (master->bus_num < 0) { 1142 if (master->bus_num < 0) {
1140 /* FIXME switch to an IDR based scheme, something like 1143 /* FIXME switch to an IDR based scheme, something like
@@ -1366,12 +1369,14 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1366 } 1369 }
1367 1370
1368 /** 1371 /**
1369 * Set transfer bits_per_word as spi device default if it is not 1372 * Set transfer bits_per_word and max speed as spi device default if
1370 * set for this transfer. 1373 * it is not set for this transfer.
1371 */ 1374 */
1372 list_for_each_entry(xfer, &message->transfers, transfer_list) { 1375 list_for_each_entry(xfer, &message->transfers, transfer_list) {
1373 if (!xfer->bits_per_word) 1376 if (!xfer->bits_per_word)
1374 xfer->bits_per_word = spi->bits_per_word; 1377 xfer->bits_per_word = spi->bits_per_word;
1378 if (!xfer->speed_hz)
1379 xfer->speed_hz = spi->max_speed_hz;
1375 } 1380 }
1376 1381
1377 message->spi = spi; 1382 message->spi = spi;
@@ -1656,7 +1661,8 @@ int spi_write_then_read(struct spi_device *spi,
1656 * using the pre-allocated buffer or the transfer is too large. 1661 * using the pre-allocated buffer or the transfer is too large.
1657 */ 1662 */
1658 if ((n_tx + n_rx) > SPI_BUFSIZ || !mutex_trylock(&lock)) { 1663 if ((n_tx + n_rx) > SPI_BUFSIZ || !mutex_trylock(&lock)) {
1659 local_buf = kmalloc(max((unsigned)SPI_BUFSIZ, n_tx + n_rx), GFP_KERNEL); 1664 local_buf = kmalloc(max((unsigned)SPI_BUFSIZ, n_tx + n_rx),
1665 GFP_KERNEL | GFP_DMA);
1660 if (!local_buf) 1666 if (!local_buf)
1661 return -ENOMEM; 1667 return -ENOMEM;
1662 } else { 1668 } else {