From bb29785e0d6d150181704be2efcc3141044625e2 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 21 Dec 2012 19:32:09 +0000 Subject: spi/of: Use DT aliases for assigning bus number Linux assigns a number to each spi_master in the system, but when the platform used the device tree, the numbers are dynamically assigned and are not predictable. In general this shouldn't matter since the kernel doesn't use the bus number for anything other than matching a bus to spi_boardinfo (not used for DT). However, sometimes userspace needs to figure out which bus is which, so it makes sense to use the global /aliases namespace to choose a specific bus number. It is safe to derive the bus number from an alias because aliases will never cause two buses to try and use the same bus number. (At one time the cell-index property was used for this purpose, but cell-index has the risk of an id collision). Signed-off-by: Grant Likely Cc: Anatolij Gustschin Cc: Mark Brown --- drivers/spi/spi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/spi/spi.c') diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 19ee901577d..08ff4acd522 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1135,6 +1135,9 @@ int spi_register_master(struct spi_master *master) if (master->num_chipselect == 0) return -EINVAL; + if ((master->bus_num < 0) && master->dev.of_node) + master->bus_num = of_alias_get_id(master->dev.of_node, "spi"); + /* convention: dynamically assigned bus IDs count down from the max */ if (master->bus_num < 0) { /* FIXME switch to an IDR based scheme, something like -- cgit v1.2.3-18-g5258 From 059b8ffeee5b427949872bb6ed5db5ae0788054e Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Sat, 5 Jan 2013 00:17:14 +0530 Subject: spi: make sure all transfer has proper speed set When spi client does the spi transfer and if it does not set the speed for each transfer then set it as default of spi device in spi core before calling low level transfer. This will remove the extra check in low level driver for setting speed. Signed-off-by: Laxman Dewangan Signed-off-by: Grant Likely --- drivers/spi/spi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/spi/spi.c') diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 08ff4acd522..2edbe190380 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1369,12 +1369,14 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message) } /** - * Set transfer bits_per_word as spi device default if it is not - * set for this transfer. + * Set transfer bits_per_word and max speed as spi device default if + * it is not set for this transfer. */ list_for_each_entry(xfer, &message->transfers, transfer_list) { if (!xfer->bits_per_word) xfer->bits_per_word = spi->bits_per_word; + if (!xfer->speed_hz) + xfer->speed_hz = spi->max_speed_hz; } message->spi = spi; -- cgit v1.2.3-18-g5258 From 2cd94c8a1b4184b48ecbc16b353dcbb513053285 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Sun, 27 Jan 2013 14:35:04 +0800 Subject: spi: Ensure memory used for spi_write_then_read() is DMA safe Use GFP_DMA in order to ensure that the memory we allocate for transfers in spi_write_then_read() can be DMAed. On most platforms this will have no effect. Signed-off-by: Mark Brown Signed-off-by: Grant Likely --- drivers/spi/spi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/spi/spi.c') diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 2edbe190380..d1e0a316826 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1661,7 +1661,8 @@ int spi_write_then_read(struct spi_device *spi, * using the pre-allocated buffer or the transfer is too large. */ if ((n_tx + n_rx) > SPI_BUFSIZ || !mutex_trylock(&lock)) { - local_buf = kmalloc(max((unsigned)SPI_BUFSIZ, n_tx + n_rx), GFP_KERNEL); + local_buf = kmalloc(max((unsigned)SPI_BUFSIZ, n_tx + n_rx), + GFP_KERNEL | GFP_DMA); if (!local_buf) return -ENOMEM; } else { -- cgit v1.2.3-18-g5258 From 0da83bb1c9d2690465d27cb8887918e6664f647e Mon Sep 17 00:00:00 2001 From: Andreas Larsson Date: Tue, 29 Jan 2013 15:53:40 +0100 Subject: spi/of: Fix initialization of cs_gpios array Using memset does not set an array of integers properly. Replace with a loop to set each element properly. Signed-off-by: Andreas Larsson Signed-off-by: Grant Likely --- drivers/spi/spi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/spi/spi.c') diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index d1e0a316826..6707cb2f4fa 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1080,7 +1080,8 @@ static int of_spi_register_master(struct spi_master *master) if (!master->cs_gpios) return -ENOMEM; - memset(cs, -EINVAL, master->num_chipselect); + for (i = 0; i < master->num_chipselect; i++) + cs[i] = -EINVAL; for (i = 0; i < nb; i++) cs[i] = of_get_named_gpio(np, "cs-gpios", i); -- cgit v1.2.3-18-g5258