spi: Header and core clean up and refactoring
Subsystems (20)
PATCH v3 1/14 spi: Remove unneeded OF node NULL checks
In reply to Andy ShevchenkoIn the couple of places the NULL check of OF node is implied by the call that takes it as a parameter. Drop the respective duplicate checks.
--- drivers/spi/spi.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/spi/spi.c +1 -4
@@ -2399,9 +2399,6 @@ static void of_register_spi_devices(struct spi_controller *ctlr)struct spi_device *spi;struct device_node *nc; -if (!ctlr->dev.of_node) -return ; -for_each_available_child_of_node (ctlr->dev.of_node, nc) {if (of_node_test_and_set_flag (nc,OF_POPULATED ))continue ;
@@ -3134,7 +3131,7 @@ int spi_register_controller(struct spi_controller *ctlr)if (WARN (id <0 ,"couldn't get idr" ))return id == -ENOSPC ? -EBUSY : id; ctlr->bus_num = id; - }else if (ctlr->dev.of_node) { + }else {/* Allocate dynamic bus number using Linux idr */ id =of_alias_get_id (ctlr->dev.of_node,"spi" );if (id >=0 ) {
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 2/14 spi: Deduplicate IDR allocation code in spi_register_controller()
In reply to Andy ShevchenkoRefactor spi_register_controller() to deduplicate IDR allocation by introducing a new spi_controller_id_alloc() helper and using it.
For the dynamic ID allocation for the highest OF aliases, this will shadow the ENOSPC error code as it's done for the other two cases. It shouldn't be a problem as the result will be the same, we may not get device ID allocated and flow will fail.
--- drivers/spi/spi.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/spi/spi.c +23 -21
@@ -3081,6 +3081,20 @@ static int spi_controller_check_ops(struct spi_controller *ctlr)return 0 ; } +/* Allocate dynamic bus number using Linux idr */ +static int spi_controller_id_alloc (struct spi_controller *ctlr,int start,int end) +{ +int id; + +mutex_lock (&board_lock); + id =idr_alloc (&spi_master_idr, ctlr, start, end,GFP_KERNEL ); +mutex_unlock (&board_lock); +if (WARN (id <0 ,"couldn't get idr" )) +return id == -ENOSPC ? -EBUSY : id; + ctlr->bus_num = id; +return 0 ; +} +/** * spi_register_controller - register SPI master or slave controller * @ctlr: initialized master, originally from spi_alloc_master() or
@@ -3124,24 +3138,16 @@ int spi_register_controller(struct spi_controller *ctlr)if (ctlr->bus_num >=0 ) {/* Devices with a fixed bus num must check-in with the num */ -mutex_lock (&board_lock); - id =idr_alloc (&spi_master_idr, ctlr, ctlr->bus_num, - ctlr->bus_num +1 ,GFP_KERNEL ); -mutex_unlock (&board_lock); -if (WARN (id <0 ,"couldn't get idr" )) -return id == -ENOSPC ? -EBUSY : id; - ctlr->bus_num = id; + status =spi_controller_id_alloc (ctlr, ctlr->bus_num, ctlr->bus_num +1 ); +if (status) +return status; }else {/* Allocate dynamic bus number using Linux idr */ id =of_alias_get_id (ctlr->dev.of_node,"spi" );if (id >=0 ) { - ctlr->bus_num = id; -mutex_lock (&board_lock); - id =idr_alloc (&spi_master_idr, ctlr, ctlr->bus_num, - ctlr->bus_num +1 ,GFP_KERNEL ); -mutex_unlock (&board_lock); -if (WARN (id <0 ,"couldn't get idr" )) -return id == -ENOSPC ? -EBUSY : id; + status =spi_controller_id_alloc (ctlr, id, id +1 ); +if (status) +return status; } }if (ctlr->bus_num <0 ) {
@@ -3151,13 +3157,9 @@ int spi_register_controller(struct spi_controller *ctlr)else first_dynamic++; -mutex_lock (&board_lock); - id =idr_alloc (&spi_master_idr, ctlr, first_dynamic, -0 ,GFP_KERNEL ); -mutex_unlock (&board_lock); -if (WARN (id <0 ,"couldn't get idr" )) -return id; - ctlr->bus_num = id; + status =spi_controller_id_alloc (ctlr, first_dynamic,0 ); +if (status) +return status; } ctlr->bus_lock_flag =0 ;init_completion (&ctlr->xfer_completion);
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 4/14 spi: Remove code duplication in spi_add_device*()
In reply to Andy ShevchenkoThe commit 0c79378c0199 ("spi: add ancillary device support") added a dozen of duplicating lines of code. We may move them to the __spi_add_device(). Note, that the code may be called under the mutex.
--- drivers/spi/spi.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-)
drivers/spi/spi.c +10 -22
@@ -631,6 +631,16 @@ static int __spi_add_device(struct spi_device *spi)struct device *dev = ctlr->dev.parent;int status; +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), + ctlr->num_chipselect); +return -EINVAL ; + } + +/* Set the bus ID string */ +spi_dev_set_name (spi); +/* * We need to make sure there's no other device with this * chipselect **BEFORE** we call setup(), else we'll trash
@@ -689,19 +699,8 @@ static int __spi_add_device(struct spi_device *spi)int spi_add_device (struct spi_device *spi) {struct spi_controller *ctlr = spi->controller; -struct device *dev = ctlr->dev.parent;int status; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; - } - -/* Set the bus ID string */ -spi_dev_set_name (spi); -mutex_lock (&ctlr->add_lock); status =__spi_add_device (spi);mutex_unlock (&ctlr->add_lock);
@@ -712,17 +711,6 @@ EXPORT_SYMBOL_GPL(spi_add_device);static int spi_add_device_locked (struct spi_device *spi) {struct spi_controller *ctlr = spi->controller; -struct device *dev = ctlr->dev.parent; - -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; - } - -/* Set the bus ID string */ -spi_dev_set_name (spi);WARN_ON (!mutex_is_locked (&ctlr->add_lock));return __spi_add_device (spi);
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 6/14 spi: Use sysfs_emit() to instead of s*printf()
In reply to Andy ShevchenkoFollow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.
--- drivers/spi/spi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/spi/spi.c +3 -4
@@ -64,7 +64,7 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)if (len != -ENODEV )return len; -return sprintf (buf,"%s%s\n" ,SPI_MODULE_PREFIX , spi->modalias); +return sysfs_emit (buf,"%s%s\n" ,SPI_MODULE_PREFIX , spi->modalias); }static DEVICE_ATTR_RO (modalias);
@@ -89,7 +89,7 @@ static ssize_t driver_override_show(struct device *dev,ssize_t len;device_lock (dev); - len =snprintf (buf,PAGE_SIZE ,"%s\n" , spi->driver_override ? :"" ); + len =sysfs_emit (buf,"%s\n" , spi->driver_override ? :"" );device_unlock (dev);return len; }
@@ -2797,8 +2797,7 @@ static ssize_t slave_show(struct device *dev, struct device_attribute *attr,struct device *child; child =device_find_any_child (&ctlr->dev); -return sprintf (buf,"%s\n" , - child ?to_spi_device (child)->modalias :NULL ); +return sysfs_emit (buf,"%s\n" , child ?to_spi_device (child)->modalias :NULL ); } static ssize_t slave_store(struct device *dev, struct device_attribute *attr,
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 8/14 spi: Sort headers alphabetically
In reply to Andy ShevchenkoSorting headers alphabetically helps locating duplicates, and make it easier to figure out where to insert new headers.
--- drivers/spi/spi.c | 42 ++++++++++++++++++++--------------------- include/linux/spi/spi.h | 14 +++++++------- 2 files changed, 28 insertions(+), 28 deletions(-)
drivers/spi/spi.c +21 -21
@@ -4,36 +4,36 @@// Copyright (C) 2005 David Brownell // Copyright (C) 2008 Secret Lab Technologies Ltd. -#include <linux/kernel.h> -#include <linux/device.h> -#include <linux/init.h> +#include <linux/acpi.h> #include <linux/cache.h> -#include <linux/dma-mapping.h> +#include <linux/clk/clk-conf.h> +#include <linux/delay.h> +#include <linux/device.h> #include <linux/dmaengine.h> +#include <linux/dma-mapping.h> +#include <linux/export.h> +#include <linux/gpio/consumer.h> +#include <linux/highmem.h> +#include <linux/idr.h> +#include <linux/init.h> +#include <linux/ioport.h> +#include <linux/kernel.h> +#include <linux/kthread.h> +#include <linux/mod_devicetable.h> #include <linux/mutex.h> #include <linux/of_device.h> #include <linux/of_irq.h> -#include <linux/clk/clk-conf.h> -#include <linux/slab.h> -#include <linux/mod_devicetable.h> -#include <linux/spi/spi.h> -#include <linux/spi/spi-mem.h> -#include <linux/gpio/consumer.h> -#include <linux/pm_runtime.h> +#include <linux/percpu.h> +#include <linux/platform_data/x86/apple.h> #include <linux/pm_domain.h> +#include <linux/pm_runtime.h> #include <linux/property.h> -#include <linux/export.h> +#include <linux/ptp_clock_kernel.h> #include <linux/sched/rt.h> +#include <linux/slab.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> #include <uapi/linux/sched/types.h> -#include <linux/delay.h> -#include <linux/kthread.h> -#include <linux/ioport.h> -#include <linux/acpi.h> -#include <linux/highmem.h> -#include <linux/idr.h> -#include <linux/platform_data/x86/apple.h> -#include <linux/ptp_clock_kernel.h> -#include <linux/percpu.h> #define CREATE_TRACE_POINTS #include <trace/events/spi.h>
include/linux/spi/spi.h +7 -7
@@ -6,19 +6,19 @@#ifndef __LINUX_SPI_H#define __LINUX_SPI_H +#include <linux/acpi.h> #include <linux/bits.h> +#include <linux/completion.h> #include <linux/device.h> -#include <linux/mod_devicetable.h> -#include <linux/slab.h> +#include <linux/gpio/consumer.h> #include <linux/kthread.h> -#include <linux/completion.h> +#include <linux/mod_devicetable.h> #include <linux/scatterlist.h> -#include <linux/gpio/consumer.h> - -#include <uapi/linux/spi/spi.h> -#include <linux/acpi.h> +#include <linux/slab.h> #include <linux/u64_stats_sync.h> +#include <uapi/linux/spi/spi.h> +struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 10/14 spi: Get rid of old SPI_MASTER_NO_TX & SPI_MASTER_NO_RX
In reply to Andy ShevchenkoConvert the users from SPI_MASTER_NO_TX and/or SPI_MASTER_NO_RX to SPI_CONTROLLER_NO_TX and/or SPI_CONTROLLER_NO_RX respectively and kill the not used anymore definitions.
--- drivers/spi/spi-bitbang-txrx.h | 16 ++++++++-------- drivers/spi/spi-bitbang.c | 2 +- drivers/spi/spi-gpio.c | 8 ++++---- drivers/spi/spi-lp8841-rtc.c | 8 ++++---- drivers/spi/spi-xtensa-xtfpga.c | 2 +- include/linux/spi/spi.h | 2 -- 6 files changed, 18 insertions(+), 20 deletions(-)
drivers/spi/spi-bitbang-txrx.h +8 -8
@@ -57,7 +57,7 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,for (word <<= (32 - bits);likely (bits); bits--) {/* setup MSB (to slave) on trailing edge */ -if ((flags &SPI_MASTER_NO_TX ) ==0 ) { +if ((flags &SPI_CONTROLLER_NO_TX ) ==0 ) {if ((word & (1 <<31 )) != oldbit) {setmosi (spi, word & (1 <<31 )); oldbit = word & (1 <<31 );
@@ -70,7 +70,7 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,/* sample MSB (from slave) on leading edge */ word <<=1 ; -if ((flags &SPI_MASTER_NO_RX ) ==0 ) +if ((flags &SPI_CONTROLLER_NO_RX ) ==0 ) word |=getmiso (spi);setsck (spi, cpol); }
@@ -90,7 +90,7 @@ bitbang_txrx_be_cpha1(struct spi_device *spi,/* setup MSB (to slave) on leading edge */ setsck (spi, !cpol); -if ((flags &SPI_MASTER_NO_TX ) ==0 ) { +if ((flags &SPI_CONTROLLER_NO_TX ) ==0 ) {if ((word & (1 <<31 )) != oldbit) {setmosi (spi, word & (1 <<31 )); oldbit = word & (1 <<31 );
@@ -103,7 +103,7 @@ bitbang_txrx_be_cpha1(struct spi_device *spi,/* sample MSB (from slave) on trailing edge */ word <<=1 ; -if ((flags &SPI_MASTER_NO_RX ) ==0 ) +if ((flags &SPI_CONTROLLER_NO_RX ) ==0 ) word |=getmiso (spi); }return word;
@@ -122,7 +122,7 @@ bitbang_txrx_le_cpha0(struct spi_device *spi,for (;likely (bits); bits--) {/* setup LSB (to slave) on trailing edge */ -if ((flags &SPI_MASTER_NO_TX ) ==0 ) { +if ((flags &SPI_CONTROLLER_NO_TX ) ==0 ) {if ((word &1 ) != oldbit) {setmosi (spi, word &1 ); oldbit = word &1 ;
@@ -135,7 +135,7 @@ bitbang_txrx_le_cpha0(struct spi_device *spi,/* sample LSB (from slave) on leading edge */ word >>=1 ; -if ((flags &SPI_MASTER_NO_RX ) ==0 ) +if ((flags &SPI_CONTROLLER_NO_RX ) ==0 ) word |=getmiso (spi) << rxbit;setsck (spi, cpol); }
@@ -156,7 +156,7 @@ bitbang_txrx_le_cpha1(struct spi_device *spi,/* setup LSB (to slave) on leading edge */ setsck (spi, !cpol); -if ((flags &SPI_MASTER_NO_TX ) ==0 ) { +if ((flags &SPI_CONTROLLER_NO_TX ) ==0 ) {if ((word &1 ) != oldbit) {setmosi (spi, word &1 ); oldbit = word &1 ;
@@ -169,7 +169,7 @@ bitbang_txrx_le_cpha1(struct spi_device *spi,/* sample LSB (from slave) on trailing edge */ word >>=1 ; -if ((flags &SPI_MASTER_NO_RX ) ==0 ) +if ((flags &SPI_CONTROLLER_NO_RX ) ==0 ) word |=getmiso (spi) << rxbit; }return word;
drivers/spi/spi-bitbang.c +1 -1
@@ -248,7 +248,7 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)if (spi->mode &SPI_3WIRE ) {unsigned flags; - flags = t->tx_buf ?SPI_MASTER_NO_RX :SPI_MASTER_NO_TX ; + flags = t->tx_buf ?SPI_CONTROLLER_NO_RX :SPI_CONTROLLER_NO_TX ;return cs->txrx_bufs (spi, cs->txrx_word, nsecs, t, flags); }return cs->txrx_bufs (spi, cs->txrx_word, nsecs, t,0 );
drivers/spi/spi-gpio.c +4 -4
@@ -170,7 +170,7 @@ static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,/* * These functions do not call setmosi or getmiso if respective flag -* (SPI_MASTER_NO_RX or SPI_MASTER_NO_TX) is set, so they are safe to +* (SPI_CONTROLLER_NO_RX or SPI_CONTROLLER_NO_TX) is set, so they are safe to * call when such pin is not present or defined in the controller. * A separate set of callbacks is defined to get highest possible * speed in the generic case (when both MISO and MOSI lines are
@@ -416,11 +416,11 @@ static int spi_gpio_probe(struct platform_device *pdev)if (!spi_gpio->mosi) {/* HW configuration without MOSI pin * -* No setting SPI_MASTER_NO_RX here - if there is only +* No setting SPI_CONTROLLER_NO_RX here - if there is only * a MOSI pin connected the host can still do RX by * changing the direction of the line. */ - master->flags =SPI_MASTER_NO_TX ; + master->flags =SPI_CONTROLLER_NO_TX ; } master->bus_num = pdev->id;
@@ -438,7 +438,7 @@ static int spi_gpio_probe(struct platform_device *pdev) bb->chipselect = spi_gpio_chipselect; bb->set_line_direction = spi_gpio_set_direction; -if (master->flags &SPI_MASTER_NO_TX ) { +if (master->flags &SPI_CONTROLLER_NO_TX ) { bb->txrx_word[SPI_MODE_0 ] = spi_gpio_spec_txrx_word_mode0; bb->txrx_word[SPI_MODE_1 ] = spi_gpio_spec_txrx_word_mode1; bb->txrx_word[SPI_MODE_2 ] = spi_gpio_spec_txrx_word_mode2;
drivers/spi/spi-lp8841-rtc.c +4 -4
@@ -75,14 +75,14 @@ bitbang_txrx_be_cpha0_lsb(struct spi_lp8841_rtc *data,for (;likely (bits); bits--) {/* setup LSB (to slave) on leading edge */ -if ((flags &SPI_MASTER_NO_TX ) ==0 ) +if ((flags &SPI_CONTROLLER_NO_TX ) ==0 )setmosi (data, (word &1 ));usleep_range (usecs, usecs +1 );/* T(setup) */ /* sample LSB (from slave) on trailing edge */ word >>=1 ; -if ((flags &SPI_MASTER_NO_RX ) ==0 ) +if ((flags &SPI_CONTROLLER_NO_RX ) ==0 ) word |= (getmiso (data) <<31 );setsck (data, !cpol);
@@ -113,7 +113,7 @@ spi_lp8841_rtc_transfer_one(struct spi_master *master,while (likely (count >0 )) { word = *tx++;bitbang_txrx_be_cpha0_lsb (data,1 ,0 , -SPI_MASTER_NO_RX , word,8 ); +SPI_CONTROLLER_NO_RX , word,8 ); count--; } }else if (rx) {
@@ -121,7 +121,7 @@ spi_lp8841_rtc_transfer_one(struct spi_master *master,writeb (data->state, data->iomem);while (likely (count >0 )) { word =bitbang_txrx_be_cpha0_lsb (data,1 ,0 , -SPI_MASTER_NO_TX , word,8 ); +SPI_CONTROLLER_NO_TX , word,8 ); *rx++ = word; count--; }
drivers/spi/spi-xtensa-xtfpga.c +1 -1
@@ -87,7 +87,7 @@ static int xtfpga_spi_probe(struct platform_device *pdev)if (!master)return -ENOMEM ; - master->flags =SPI_MASTER_NO_RX ; + master->flags =SPI_CONTROLLER_NO_RX ; master->bits_per_word_mask =SPI_BPW_RANGE_MASK (1 ,16 ); master->bus_num = pdev->dev.id; master->dev.of_node = pdev->dev.of_node;
include/linux/spi/spi.h +0 -2
@@ -1626,8 +1626,6 @@ spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)#define spi_master spi_controller#define SPI_MASTER_HALF_DUPLEX SPI_CONTROLLER_HALF_DUPLEX -#define SPI_MASTER_NO_RX SPI_CONTROLLER_NO_RX -#define SPI_MASTER_NO_TX SPI_CONTROLLER_NO_TX#define SPI_MASTER_MUST_RX SPI_CONTROLLER_MUST_RX#define SPI_MASTER_MUST_TX SPI_CONTROLLER_MUST_TX
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 11/14 spi: Get rid of old SPI_MASTER_MUST_TX & SPI_MASTER_MUST_RX
In reply to Andy ShevchenkoConvert the users from SPI_MASTER_MUST_TX and/or SPI_MASTER_MUST_RX to SPI_CONTROLLER_MUST_TX and/or SPI_CONTROLLER_MUST_RX respectively and kill the not used anymore definitions.
--- drivers/spi/spi-at91-usart.c | 2 +- drivers/spi/spi-atmel.c | 2 +- drivers/spi/spi-davinci.c | 2 +- drivers/spi/spi-fsl-lpspi.c | 2 +- drivers/spi/spi-meson-spicc.c | 2 +- drivers/spi/spi-mt65xx.c | 2 +- drivers/spi/spi-pci1xxxx.c | 2 +- drivers/spi/spi-pic32.c | 2 +- drivers/spi/spi-rb4xx.c | 2 +- drivers/spi/spi-slave-mt27xx.c | 2 +- drivers/spi/spi-stm32.c | 2 +- include/linux/spi/spi.h | 2 -- 12 files changed, 11 insertions(+), 13 deletions(-)
drivers/spi/spi-at91-usart.c +1 -1
@@ -527,7 +527,7 @@ static int at91_usart_spi_probe(struct platform_device *pdev) controller->dev.of_node = pdev->dev.parent->of_node; controller->bits_per_word_mask =SPI_BPW_MASK (8 ); controller->setup = at91_usart_spi_setup; - controller->flags =SPI_MASTER_MUST_RX |SPI_MASTER_MUST_TX ; + controller->flags =SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_MUST_TX ; controller->transfer_one = at91_usart_spi_transfer_one; controller->prepare_message = at91_usart_spi_prepare_message; controller->unprepare_message = at91_usart_spi_unprepare_message;
drivers/spi/spi-atmel.c +1 -1
@@ -1475,7 +1475,7 @@ static int atmel_spi_probe(struct platform_device *pdev) host->bus_num = pdev->id; host->num_chipselect =4 ; host->setup = atmel_spi_setup; - host->flags = (SPI_MASTER_MUST_RX |SPI_MASTER_MUST_TX | + host->flags = (SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_MUST_TX |SPI_MASTER_GPIO_SS ); host->transfer_one = atmel_spi_one_transfer; host->set_cs = atmel_spi_set_cs;
drivers/spi/spi-davinci.c +1 -1
@@ -939,7 +939,7 @@ static int davinci_spi_probe(struct platform_device *pdev) master->bus_num = pdev->id; master->num_chipselect = pdata->num_chipselect; master->bits_per_word_mask =SPI_BPW_RANGE_MASK (2 ,16 ); - master->flags =SPI_MASTER_MUST_RX |SPI_MASTER_GPIO_SS ; + master->flags =SPI_CONTROLLER_MUST_RX |SPI_MASTER_GPIO_SS ; master->setup = davinci_spi_setup; master->cleanup = davinci_spi_cleanup; master->can_dma = davinci_spi_can_dma;
drivers/spi/spi-fsl-lpspi.c +1 -1
@@ -856,7 +856,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev) controller->prepare_transfer_hardware = lpspi_prepare_xfer_hardware; controller->unprepare_transfer_hardware = lpspi_unprepare_xfer_hardware; controller->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH ; - controller->flags =SPI_MASTER_MUST_RX |SPI_MASTER_MUST_TX ; + controller->flags =SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_MUST_TX ; controller->dev.of_node = pdev->dev.of_node; controller->bus_num = pdev->id; controller->num_chipselect = fsl_lpspi->num_cs;
drivers/spi/spi-meson-spicc.c +1 -1
@@ -864,7 +864,7 @@ static int meson_spicc_probe(struct platform_device *pdev)SPI_BPW_MASK (24 ) |SPI_BPW_MASK (16 ) |SPI_BPW_MASK (8 ); - master->flags = (SPI_MASTER_MUST_RX |SPI_MASTER_MUST_TX ); + master->flags = (SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_MUST_TX ); master->min_speed_hz = spicc->data->min_speed_hz; master->max_speed_hz = spicc->data->max_speed_hz; master->setup = meson_spicc_setup;
drivers/spi/spi-mt65xx.c +1 -1
@@ -1142,7 +1142,7 @@ static int mtk_spi_probe(struct platform_device *pdev) master->mode_bits |=SPI_CS_HIGH ;if (mdata->dev_comp->must_tx) - master->flags =SPI_MASTER_MUST_TX ; + master->flags =SPI_CONTROLLER_MUST_TX ;if (mdata->dev_comp->ipm_design) master->mode_bits |=SPI_LOOP |SPI_RX_DUAL |SPI_TX_DUAL |SPI_RX_QUAD |SPI_TX_QUAD ;
drivers/spi/spi-pci1xxxx.c +1 -1
@@ -365,7 +365,7 @@ static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id * spi_host->bits_per_word_mask =SPI_BPW_MASK (8 ); spi_host->max_speed_hz =PCI1XXXX_SPI_MAX_CLOCK_HZ ; spi_host->min_speed_hz =PCI1XXXX_SPI_MIN_CLOCK_HZ ; - spi_host->flags =SPI_MASTER_MUST_TX ; + spi_host->flags =SPI_CONTROLLER_MUST_TX ;spi_master_set_devdata (spi_host, spi_sub_ptr); ret =devm_spi_register_master (dev, spi_host);if (ret)
drivers/spi/spi-pic32.c +1 -1
@@ -773,7 +773,7 @@ static int pic32_spi_probe(struct platform_device *pdev) master->max_speed_hz =clk_get_rate (pic32s->clk); master->setup = pic32_spi_setup; master->cleanup = pic32_spi_cleanup; - master->flags =SPI_MASTER_MUST_TX |SPI_MASTER_MUST_RX ; + master->flags =SPI_CONTROLLER_MUST_TX |SPI_CONTROLLER_MUST_RX ; master->bits_per_word_mask =SPI_BPW_MASK (8 ) |SPI_BPW_MASK (16 ) |SPI_BPW_MASK (32 ); master->transfer_one = pic32_spi_one_transfer;
drivers/spi/spi-rb4xx.c +1 -1
@@ -156,7 +156,7 @@ static int rb4xx_spi_probe(struct platform_device *pdev) master->num_chipselect =3 ; master->mode_bits =SPI_TX_DUAL ; master->bits_per_word_mask =SPI_BPW_MASK (8 ); - master->flags =SPI_MASTER_MUST_TX ; + master->flags =SPI_CONTROLLER_MUST_TX ; master->transfer_one = rb4xx_transfer_one; master->set_cs = rb4xx_set_cs;
drivers/spi/spi-slave-mt27xx.c +1 -1
@@ -414,7 +414,7 @@ static int mtk_spi_slave_probe(struct platform_device *pdev) mdata->dev_comp = of_id->data;if (mdata->dev_comp->must_rx) - ctlr->flags =SPI_MASTER_MUST_RX ; + ctlr->flags =SPI_CONTROLLER_MUST_RX ;platform_set_drvdata (pdev, ctlr);
drivers/spi/spi-stm32.c +1 -1
@@ -1750,7 +1750,7 @@ static const struct stm32_spi_cfg stm32f4_spi_cfg = { .baud_rate_div_min = STM32F4_SPI_BR_DIV_MIN, .baud_rate_div_max = STM32F4_SPI_BR_DIV_MAX, .has_fifo = false, - .flags = SPI_MASTER_MUST_TX, + .flags = SPI_CONTROLLER_MUST_TX, };static const struct stm32_spi_cfg stm32h7_spi_cfg = {
include/linux/spi/spi.h +0 -2
@@ -1626,8 +1626,6 @@ spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)#define spi_master spi_controller#define SPI_MASTER_HALF_DUPLEX SPI_CONTROLLER_HALF_DUPLEX -#define SPI_MASTER_MUST_RX SPI_CONTROLLER_MUST_RX -#define SPI_MASTER_MUST_TX SPI_CONTROLLER_MUST_TX#define spi_master_get_devdata (_ctlr) spi_controller_get_devdata(_ctlr)#define spi_master_set_devdata (_ctlr, _data) \
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 13/14 spi: Convert to SPI_CONTROLLER_HALF_DUPLEX
In reply to Andy ShevchenkoConvert the users under SPI subsystem to SPI_CONTROLLER_HALF_DUPLEX.
--- drivers/spi/spi-amd.c | 2 +- drivers/spi/spi-cavium-thunderx.c | 2 +- drivers/spi/spi-falcon.c | 2 +- drivers/spi/spi-lp8841-rtc.c | 2 +- drivers/spi/spi-mxs.c | 2 +- drivers/spi/spi-omap-uwire.c | 2 +- drivers/spi/spi-pic32-sqi.c | 2 +- drivers/spi/spi-qcom-qspi.c | 2 +- drivers/spi/spi-rockchip-sfc.c | 2 +- drivers/spi/spi-sprd-adi.c | 2 +- drivers/spi/spi-ti-qspi.c | 2 +- drivers/spi/spi-xcomm.c | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-)
drivers/spi/spi-amd.c +1 -1
@@ -404,7 +404,7 @@ static int amd_spi_probe(struct platform_device *pdev) master->bus_num =0 ; master->num_chipselect =4 ; master->mode_bits =0 ; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->max_speed_hz =AMD_SPI_MAX_HZ ; master->min_speed_hz =AMD_SPI_MIN_HZ ; master->setup = amd_spi_master_setup;
drivers/spi/spi-cavium-thunderx.c +1 -1
@@ -64,7 +64,7 @@ static int thunderx_spi_probe(struct pci_dev *pdev, p->sys_freq =SYS_FREQ_DEFAULT ;dev_info (dev,"Set system clock to %u\n" , p->sys_freq); - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->num_chipselect =4 ; master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_CS_HIGH |SPI_LSB_FIRST |SPI_3WIRE ;
drivers/spi/spi-falcon.c +1 -1
@@ -401,7 +401,7 @@ static int falcon_sflash_probe(struct platform_device *pdev) priv->master = master; master->mode_bits =SPI_MODE_3 ; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->setup = falcon_sflash_setup; master->transfer_one_message = falcon_sflash_xfer_one; master->dev.of_node = pdev->dev.of_node;
drivers/spi/spi-lp8841-rtc.c +1 -1
@@ -191,7 +191,7 @@ spi_lp8841_rtc_probe(struct platform_device *pdev)return -ENOMEM ;platform_set_drvdata (pdev, master); - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->mode_bits =SPI_CS_HIGH |SPI_3WIRE |SPI_LSB_FIRST ; master->bus_num = pdev->id;
drivers/spi/spi-mxs.c +1 -1
@@ -572,7 +572,7 @@ static int mxs_spi_probe(struct platform_device *pdev) master->mode_bits =SPI_CPOL |SPI_CPHA ; master->num_chipselect =3 ; master->dev.of_node = np; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->auto_runtime_pm = true; spi =spi_master_get_devdata (master);
drivers/spi/spi-omap-uwire.c +1 -1
@@ -486,7 +486,7 @@ static int uwire_probe(struct platform_device *pdev)/* the spi->mode bits understood by this driver: */ master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH ; master->bits_per_word_mask =SPI_BPW_RANGE_MASK (1 ,16 ); - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->bus_num =2 ;/* "official" */ master->num_chipselect =4 ;
drivers/spi/spi-pic32-sqi.c +1 -1
@@ -648,7 +648,7 @@ static int pic32_sqi_probe(struct platform_device *pdev) master->dev.of_node = pdev->dev.of_node; master->mode_bits =SPI_MODE_3 |SPI_MODE_0 |SPI_TX_DUAL |SPI_RX_DUAL |SPI_TX_QUAD |SPI_RX_QUAD ; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->can_dma = pic32_sqi_can_dma; master->bits_per_word_mask =SPI_BPW_RANGE_MASK (8 ,32 ); master->transfer_one_message = pic32_sqi_one_message;
drivers/spi/spi-qcom-qspi.c +1 -1
@@ -724,7 +724,7 @@ static int qcom_qspi_probe(struct platform_device *pdev) master->mode_bits =SPI_MODE_0 |SPI_TX_DUAL |SPI_RX_DUAL |SPI_TX_QUAD |SPI_RX_QUAD ; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->prepare_message = qcom_qspi_prepare_message; master->transfer_one = qcom_qspi_transfer_one; master->handle_err = qcom_qspi_handle_err;
drivers/spi/spi-rockchip-sfc.c +1 -1
@@ -565,7 +565,7 @@ static int rockchip_sfc_probe(struct platform_device *pdev)if (!master)return -ENOMEM ; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->mem_ops = &rockchip_sfc_mem_ops; master->dev.of_node = pdev->dev.of_node; master->mode_bits =SPI_TX_QUAD |SPI_TX_DUAL |SPI_RX_QUAD |SPI_RX_DUAL ;
drivers/spi/spi-sprd-adi.c +1 -1
@@ -580,7 +580,7 @@ static int sprd_adi_probe(struct platform_device *pdev) ctlr->dev.of_node = pdev->dev.of_node; ctlr->bus_num = pdev->id; ctlr->num_chipselect = num_chipselect; - ctlr->flags =SPI_MASTER_HALF_DUPLEX ; + ctlr->flags =SPI_CONTROLLER_HALF_DUPLEX ; ctlr->bits_per_word_mask =0 ; ctlr->transfer_one = sprd_adi_transfer_one;
drivers/spi/spi-ti-qspi.c +1 -1
@@ -770,7 +770,7 @@ static int ti_qspi_probe(struct platform_device *pdev) master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_RX_DUAL |SPI_RX_QUAD ; - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->setup = ti_qspi_setup; master->auto_runtime_pm = true; master->transfer_one_message = ti_qspi_start_transfer_one;
drivers/spi/spi-xcomm.c +1 -1
@@ -218,7 +218,7 @@ static int spi_xcomm_probe(struct i2c_client *i2c) master->num_chipselect =16 ; master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_3WIRE ; master->bits_per_word_mask =SPI_BPW_MASK (8 ); - master->flags =SPI_MASTER_HALF_DUPLEX ; + master->flags =SPI_CONTROLLER_HALF_DUPLEX ; master->transfer_one_message = spi_xcomm_transfer_one; master->dev.of_node = i2c->dev.of_node;i2c_set_clientdata (i2c, master);
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 12/14 spi: Rename SPI_MASTER_GPIO_SS to SPI_CONTROLLER_GPIO_SS
In reply to Andy ShevchenkoRename SPI_MASTER_GPIO_SS to SPI_CONTROLLER_GPIO_SS and convert the code to using SPI_CONTROLLER_GPIO_SS to follow the new naming schema.
--- drivers/spi/spi-ath79.c | 2 +- drivers/spi/spi-atmel.c | 2 +- drivers/spi/spi-bitbang.c | 6 +++--- drivers/spi/spi-davinci.c | 2 +- drivers/spi/spi-dw-core.c | 2 +- drivers/spi/spi-gpio.c | 2 +- drivers/spi/spi-imx.c | 2 +- drivers/spi/spi-orion.c | 2 +- drivers/spi/spi-rockchip.c | 2 +- drivers/spi/spi-sifive.c | 2 +- drivers/spi/spi.c | 4 ++-- include/linux/spi/spi.h | 3 +-- 12 files changed, 15 insertions(+), 16 deletions(-)
drivers/spi/spi-ath79.c +1 -1
@@ -185,7 +185,7 @@ static int ath79_spi_probe(struct platform_device *pdev) host->use_gpio_descriptors = true; host->bits_per_word_mask =SPI_BPW_RANGE_MASK (1 ,32 ); - host->flags =SPI_MASTER_GPIO_SS ; + host->flags =SPI_CONTROLLER_GPIO_SS ; host->num_chipselect =3 ; host->mem_ops = &ath79_mem_ops;
drivers/spi/spi-atmel.c +1 -1
@@ -1476,7 +1476,7 @@ static int atmel_spi_probe(struct platform_device *pdev) host->num_chipselect =4 ; host->setup = atmel_spi_setup; host->flags = (SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_MUST_TX | -SPI_MASTER_GPIO_SS ); +SPI_CONTROLLER_GPIO_SS ); host->transfer_one = atmel_spi_one_transfer; host->set_cs = atmel_spi_set_cs; host->cleanup = atmel_spi_cleanup;
drivers/spi/spi-bitbang.c +3 -3
@@ -349,11 +349,11 @@ int spi_bitbang_init(struct spi_bitbang *bitbang)/* * We only need the chipselect callback if we are actually using it. * If we just use GPIO descriptors, it is surplus. If the -* SPI_MASTER_GPIO_SS flag is set, we always need to call the +* SPI_CONTROLLER_GPIO_SS flag is set, we always need to call the * driver-specific chipselect routine. */ custom_cs = (!master->use_gpio_descriptors || - (master->flags &SPI_MASTER_GPIO_SS )); + (master->flags &SPI_CONTROLLER_GPIO_SS ));if (custom_cs && !bitbang->chipselect)return -EINVAL ;
@@ -371,7 +371,7 @@ int spi_bitbang_init(struct spi_bitbang *bitbang) master->transfer_one = spi_bitbang_transfer_one;/* * When using GPIO descriptors, the ->set_cs() callback doesn't even -* get called unless SPI_MASTER_GPIO_SS is set. +* get called unless SPI_CONTROLLER_GPIO_SS is set. */ if (custom_cs) master->set_cs = spi_bitbang_set_cs;
drivers/spi/spi-davinci.c +1 -1
@@ -939,7 +939,7 @@ static int davinci_spi_probe(struct platform_device *pdev) master->bus_num = pdev->id; master->num_chipselect = pdata->num_chipselect; master->bits_per_word_mask =SPI_BPW_RANGE_MASK (2 ,16 ); - master->flags =SPI_CONTROLLER_MUST_RX |SPI_MASTER_GPIO_SS ; + master->flags =SPI_CONTROLLER_MUST_RX |SPI_CONTROLLER_GPIO_SS ; master->setup = davinci_spi_setup; master->cleanup = davinci_spi_cleanup; master->can_dma = davinci_spi_can_dma;
drivers/spi/spi-dw-core.c +1 -1
@@ -932,7 +932,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->mem_ops.exec_op) master->mem_ops = &dws->mem_ops; master->max_speed_hz = dws->max_freq; - master->flags =SPI_MASTER_GPIO_SS ; + master->flags =SPI_CONTROLLER_GPIO_SS ; master->auto_runtime_pm = true;/* Get default rx sample delay */
drivers/spi/spi-gpio.c +1 -1
@@ -434,7 +434,7 @@ static int spi_gpio_probe(struct platform_device *pdev)* line, that we need to do on selection. This makes the local * callback for chipselect always get called. */ - master->flags |=SPI_MASTER_GPIO_SS ; + master->flags |=SPI_CONTROLLER_GPIO_SS ; bb->chipselect = spi_gpio_chipselect; bb->set_line_direction = spi_gpio_set_direction;
drivers/spi/spi-imx.c +1 -1
@@ -1779,7 +1779,7 @@ static int spi_imx_probe(struct platform_device *pdev)if (is_imx51_ecspi (spi_imx) ||is_imx53_ecspi (spi_imx)) { controller->max_native_cs =4 ; - controller->flags |=SPI_MASTER_GPIO_SS ; + controller->flags |=SPI_CONTROLLER_GPIO_SS ; } spi_imx->spi_drctl = spi_drctl;
drivers/spi/spi-orion.c +1 -1
@@ -677,7 +677,7 @@ static int orion_spi_probe(struct platform_device *pdev) master->bits_per_word_mask =SPI_BPW_MASK (8 ) |SPI_BPW_MASK (16 ); master->auto_runtime_pm = true; master->use_gpio_descriptors = true; - master->flags =SPI_MASTER_GPIO_SS ; + master->flags =SPI_CONTROLLER_GPIO_SS ;platform_set_drvdata (pdev, master);
drivers/spi/spi-rockchip.c +1 -1
@@ -858,7 +858,7 @@ static int rockchip_spi_probe(struct platform_device *pdev) ctlr->mode_bits |=SPI_NO_CS ; ctlr->slave_abort = rockchip_spi_slave_abort; }else { - ctlr->flags =SPI_MASTER_GPIO_SS ; + ctlr->flags =SPI_CONTROLLER_GPIO_SS ; ctlr->max_native_cs =ROCKCHIP_SPI_MAX_CS_NUM ;/* * rk spi0 has two native cs, spi1..5 one cs only
drivers/spi/spi-sifive.c +1 -1
@@ -379,7 +379,7 @@ static int sifive_spi_probe(struct platform_device *pdev)* we need to "left-align" the bits (unless SPI_LSB_FIRST) */ master->bits_per_word_mask =SPI_BPW_MASK (8 ); - master->flags =SPI_CONTROLLER_MUST_TX |SPI_MASTER_GPIO_SS ; + master->flags =SPI_CONTROLLER_MUST_TX |SPI_CONTROLLER_GPIO_SS ; master->prepare_message = sifive_spi_prepare_message; master->set_cs = sifive_spi_set_cs; master->transfer_one = sifive_spi_transfer_one;
drivers/spi/spi.c +2 -2
@@ -986,7 +986,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), activate); }/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && +if ((spi->controller->flags &SPI_CONTROLLER_GPIO_SS ) && spi->controller->set_cs) spi->controller->set_cs (spi, !enable); }else if (spi->controller->set_cs) {
@@ -3035,7 +3035,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr) ctlr->unused_native_cs =ffs (~native_cs_mask) -1 ; -if ((ctlr->flags &SPI_MASTER_GPIO_SS ) && num_cs_gpios && +if ((ctlr->flags &SPI_CONTROLLER_GPIO_SS ) && num_cs_gpios && ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) {dev_err (dev,"No unused native chip select available\n" );return -EINVAL ;
include/linux/spi/spi.h +1 -2
@@ -563,8 +563,7 @@ struct spi_controller {#define SPI_CONTROLLER_NO_TX BIT(2)/* Can't do buffer write */ #define SPI_CONTROLLER_MUST_RX BIT(3)/* Requires rx */ #define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */ - -#define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */ +#define SPI_CONTROLLER_GPIO_SS BIT(5)/* GPIO CS must select slave */ /* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 14/14 spi: Fix spelling typos and acronyms capitalization
In reply to Andy ShevchenkoFix
- spelling typos
- capitalization of acronyms
in the comments.
While at it, fix the multi-line comment style.
--- drivers/spi/spi.c | 54 ++++++++------- include/linux/spi/spi.h | 137 ++++++++++++++++++++----------------- include/trace/events/spi.h | 2 +- 3 files changed, 104 insertions(+), 89 deletions(-)
drivers/spi/spi.c +28 -26
@@ -692,7 +692,7 @@ static int __spi_add_device(struct spi_device *spi)* @spi: spi_device to register * * Companion function to spi_alloc_device. Devices allocated with -* spi_alloc_device can be added onto the spi bus with this function. +* spi_alloc_device can be added onto the SPI bus with this function. * * Return: 0 on success; negative errno on failure */
@@ -869,7 +869,7 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)* spi_res_alloc - allocate a spi resource that is life-cycle managed * during the processing of a spi_message while using * spi_transfer_one -* @spi: the spi device for which we allocate memory +* @spi: the SPI device for which we allocate memory * @release: the release code to execute for this resource * @size: size to alloc and return * @gfp: GFP allocation flags
@@ -895,7 +895,7 @@ static void *spi_res_alloc(struct spi_device *spi, spi_res_release_t release, }/** -* spi_res_free - free an spi resource +* spi_res_free - free an SPI resource * @res: pointer to the custom data of a resource */ static void spi_res_free (void *res)
@@ -911,7 +911,7 @@ static void spi_res_free(void *res)/** * spi_res_add - add a spi_res to the spi_message -* @message: the spi message +* @message: the SPI message * @res: the spi_resource */ static void spi_res_add (struct spi_message *message,void *res)
@@ -923,7 +923,7 @@ static void spi_res_add(struct spi_message *message, void *res) }/** -* spi_res_release - release all spi resources for this message +* spi_res_release - release all SPI resources for this message * @ctlr: the @spi_controller * @message: the @spi_message */
@@ -1404,7 +1404,7 @@ int spi_delay_to_ns(struct spi_delay *_delay, struct spi_transfer *xfer)return -EINVAL ;/* * If there is unknown effective speed, approximate it -* by underestimating with half of the requested hz. +* by underestimating with half of the requested Hz. */ hz = xfer->effective_speed_hz ?: xfer->speed_hz /2 ;if (!hz)
@@ -1719,11 +1719,11 @@ static int __spi_pump_transfer_message(struct spi_controller *ctlr, }/** -* __spi_pump_messages - function which processes spi message queue +* __spi_pump_messages - function which processes SPI message queue * @ctlr: controller to process queue for * @in_kthread: true if we are in the context of the message pump thread * -* This function checks if there is any spi message in the queue that +* This function checks if there is any SPI message in the queue that * needs processing and if so call out to the driver to initialize hardware * and transfer each message. *
@@ -1738,7 +1738,7 @@ static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)unsigned long flags;int ret; -/* Take the IO mutex */ +/* Take the I/O mutex */ mutex_lock (&ctlr->io_mutex);/* Lock queue */
@@ -2149,8 +2149,8 @@ static int __spi_queued_transfer(struct spi_device *spi,/** * spi_queued_transfer - transfer function for queued transfers -* @spi: spi device which is requesting transfer -* @msg: spi message which is to handled is queued to driver queue +* @spi: SPI device which is requesting transfer +* @msg: SPI message which is to handled is queued to driver queue * * Return: zero on success, else a negative error code. */
@@ -2479,7 +2479,7 @@ static int acpi_spi_count(struct acpi_resource *ares, void *data)* acpi_spi_count_resources - Count the number of SpiSerialBus resources * @adev: ACPI device * -* Returns the number of SpiSerialBus resources in the ACPI-device's +* Return: the number of SpiSerialBus resources in the ACPI-device's * resource-list; or a negative error code. */ int acpi_spi_count_resources (struct acpi_device *adev)
@@ -2613,10 +2613,10 @@ static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)* @adev: ACPI Device for the spi device * @index: Index of the spi resource inside the ACPI Node * -* This should be used to allocate a new spi device from and ACPI Node. -* The caller is responsible for calling spi_add_device to register the spi device. +* This should be used to allocate a new SPI device from and ACPI Device node. +* The caller is responsible for calling spi_add_device to register the SPI device. * -* If ctlr is set to NULL, the Controller for the spi device will be looked up +* If ctlr is set to NULL, the Controller for the SPI device will be looked up * using the resource. * If index is set to -1, index is not used. * Note: If index is -1, ctlr must be set.
@@ -3314,7 +3314,8 @@ void spi_unregister_controller(struct spi_controller *ctlr)if (IS_ENABLED (CONFIG_SPI_DYNAMIC ))mutex_unlock (&ctlr->add_lock); -/* Release the last reference on the controller if its driver +/* +* Release the last reference on the controller if its driver * has not yet been converted to devm_spi_alloc_master/slave(). */ if (!ctlr->devm_allocated)
@@ -3527,7 +3528,7 @@ static int __spi_split_transfer_maxsize(struct spi_controller *ctlr,/* All the others need rx_buf/tx_buf also set */ for (i =1 , offset = maxsize; i < count; offset += maxsize, i++) { -/* Update rx_buf, tx_buf and dma */ +/* Update rx_buf, tx_buf and DMA */ if (xfers[i].rx_buf) xfers[i].rx_buf += offset;if (xfers[i].rx_dma)
@@ -3597,7 +3598,7 @@ EXPORT_SYMBOL_GPL(spi_split_transfers_maxsize);/** -* spi_split_transfers_maxwords - split spi transfers into multiple transfers +* spi_split_transfers_maxwords - split SPI transfers into multiple transfers * when an individual transfer exceeds a * certain number of SPI words * @ctlr: the @spi_controller for this transfer
@@ -3646,7 +3647,8 @@ EXPORT_SYMBOL_GPL(spi_split_transfers_maxwords);/*-------------------------------------------------------------------------*/ -/* Core methods for SPI controller protocol drivers. Some of the +/* +* Core methods for SPI controller protocol drivers. Some of the * other core methods are currently defined as inline functions. */
@@ -3706,7 +3708,7 @@ static int spi_set_cs_timing(struct spi_device *spi)* changes those settings, and must be called from a context that can sleep. * Except for SPI_CS_HIGH, which takes effect immediately, the changes take * effect the next time the device is selected and data is transferred to -* or from it. When this function returns, the spi device is deselected. +* or from it. When this function returns, the SPI device is deselected. * * Note that this call will fail if the protocol driver specifies an option * that the underlying controller or its driver does not support. For
@@ -4044,7 +4046,7 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)* spi_async - asynchronous SPI transfer * @spi: device with which data will be exchanged * @message: describes the data transfers, including completion callback -* Context: any (irqs may be blocked, etc) +* Context: any (IRQs may be blocked, etc) * * This call may be used in_irq and other contexts which can't sleep, * as well as from task contexts which can sleep.
@@ -4098,7 +4100,7 @@ EXPORT_SYMBOL_GPL(spi_async);* spi_async_locked - version of spi_async with exclusive bus usage * @spi: device with which data will be exchanged * @message: describes the data transfers, including completion callback -* Context: any (irqs may be blocked, etc) +* Context: any (IRQs may be blocked, etc) * * This call may be used in_irq and other contexts which can't sleep, * as well as from task contexts which can sleep.
@@ -4361,9 +4363,9 @@ static u8 *buf;/** * spi_write_then_read - SPI synchronous write followed by read * @spi: device with which data will be exchanged -* @txbuf: data to be written (need not be dma-safe) +* @txbuf: data to be written (need not be DMA-safe) * @n_tx: size of txbuf, in bytes -* @rxbuf: buffer into which data will be read (need not be dma-safe) +* @rxbuf: buffer into which data will be read (need not be DMA-safe) * @n_rx: size of rxbuf, in bytes * Context: can sleep *
@@ -4374,7 +4376,7 @@ static u8 *buf;* * Parameters to this routine are always copied using a small buffer. * Performance-sensitive or bulk transfer code should instead use -* spi_{async,sync}() calls with dma-safe buffers. +* spi_{async,sync}() calls with DMA-safe buffers. * * Return: zero on success, else a negative error code. */
@@ -4419,7 +4421,7 @@ int spi_write_then_read(struct spi_device *spi, x[0 ].tx_buf = local_buf; x[1 ].rx_buf = local_buf + n_tx; -/* Do the i/o */ +/* Do the I/O */ status =spi_sync (spi, &message);if (status ==0 )memcpy (rxbuf, x[1 ].rx_buf, n_rx);
include/linux/spi/spi.h +75 -62
408 lines not on this page · raw message
include/trace/events/spi.h +1 -1
@@ -167,7 +167,7 @@ TRACE_EVENT(spi_message_done, );/* -* consider a buffer valid if non-NULL and if it doesn't match the dummy buffer +* Consider a buffer valid if non-NULL and if it doesn't match the dummy buffer * that only exist to work with controllers that have SPI_CONTROLLER_MUST_TX or * SPI_CONTROLLER_MUST_RX. */
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 7/14 spi: Use BITS_TO_BYTES()
In reply to Andy ShevchenkoBITS_TO_BYTES() is the existing macro which takes care about full bytes that may fully hold the given amount of bits. Use it.
--- drivers/spi/spi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/spi/spi.c +1 -3
@@ -3881,11 +3881,9 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)*/ if ((spi->mode &SPI_CS_WORD ) && (!(ctlr->mode_bits &SPI_CS_WORD ) ||spi_get_csgpiod (spi,0 ))) { -size_t maxsize; +size_t maxsize =BITS_TO_BYTES (spi->bits_per_word);int ret; - maxsize = (spi->bits_per_word +7 ) /8 ; -/* spi_split_transfers_maxsize() requires message->spi */ message->spi = spi;
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 9/14 spi: Use struct_size() helper
In reply to Andy ShevchenkoThe Documentation/process/deprecated.rst suggests to use flexible array members to provide a way to declare having a dynamically sized set of trailing elements in a structure.This makes code robust agains bunch of the issues described in the documentation, main of which is about the correctness of the sizeof() calculation for this data structure.
Due to above, prefer struct_size() over open-coded versions.
--- include/linux/spi/spi.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
include/linux/spi/spi.h +9 -6
@@ -13,6 +13,7 @@#include <linux/gpio/consumer.h> #include <linux/kthread.h> #include <linux/mod_devicetable.h> +#include <linux/overflow.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/u64_stats_sync.h>
@@ -1081,6 +1082,8 @@ struct spi_transfer {* @state: for use by whichever driver currently owns the message * @resources: for resource management when the spi message is processed * @prepared: spi_prepare_message was called for the this message +* @t: for use with spi_message_alloc() when message and transfers have +* been allocated together * * A @spi_message is used to execute an atomic sequence of data transfers, * each represented by a struct spi_transfer. The sequence is "atomic"
@@ -1133,6 +1136,9 @@ struct spi_message {/* List of spi_res reources when the spi message is processed */ struct list_head resources; + +/* For embedding transfers into the memory of the message */ +struct spi_transfer t[]; };static inline void spi_message_init_no_memset (struct spi_message *m)
@@ -1193,16 +1199,13 @@ static inline struct spi_message *spi_message_alloc(unsigned ntrans, gfp_t flags {struct spi_message *m; - m =kzalloc (sizeof (struct spi_message ) - + ntrans *sizeof (struct spi_transfer ), - flags); + m =kzalloc (struct_size (m, t, ntrans), flags);if (m) {unsigned i; -struct spi_transfer *t = (struct spi_transfer *)(m +1 );spi_message_init_no_memset (m); -for (i =0 ; i < ntrans; i++, t++) -spi_message_add_tail (t, m); +for (i =0 ; i < ntrans; i++) +spi_message_add_tail (&m->t[i], m); }return m; }
Signature · 1 line
2.40.0.1.gaa8946217a0b
v3 cover spi: Header and core clean up and refactoring
Various cleanups and refactorings of the SPI header and core parts united in a single series. It also touches drivers under SPI subsystem folder on the pure renaming purposes of some constants.
No functional change intended (with some subtle shortcuts which are explained in the respective commit messages).
Changelog v3:
- dropped controversial used to be patches 3,4,8,10 (Mark)
- amended many commit messages (Mark)
- added tag to patch 1 (AngeloGioacchino)
- split used to be patch 2 to patches 2 & 3 for better review (Mark)
- rewritten used to be patch 5 to patches 4 & 5 (Mark, Sebastian)
- added new patch 7
- fixed typos and added tag to patch 12 (Serge)
Changelog v2:
- added new patches 3,4,5,10,13,14
- massaged comment and kernel doc in patch 9
- split used to be patch 4 to patches 11,12
- covered a few things in SPI core in patch 15
- amended commit message for above (Mark)
- reshuffled patches in the series for better logical grouping
Andy Shevchenko (14):
spi: Remove unneeded OF node NULL checks
spi: Deduplicate IDR allocation code in spi_register_controller()
spi: Refactor bus number assigning code in spi_register_controller()
spi: Remove code duplication in spi_add_device*()
spi: Kill spi_add_device_locked()
spi: Use sysfs_emit() to instead of s*printf()
spi: Use BITS_TO_BYTES()
spi: Sort headers alphabetically
spi: Use struct_size() helper
spi: Get rid of old SPI_MASTER_NO_TX & SPI_MASTER_NO_RX
spi: Get rid of old SPI_MASTER_MUST_TX & SPI_MASTER_MUST_RX
spi: Rename SPI_MASTER_GPIO_SS to SPI_CONTROLLER_GPIO_SS
spi: Convert to SPI_CONTROLLER_HALF_DUPLEX
spi: Fix spelling typos and acronyms capitalization
drivers/spi/spi-amd.c | 2 +- drivers/spi/spi-at91-usart.c | 2 +- drivers/spi/spi-ath79.c | 2 +- drivers/spi/spi-atmel.c | 4 +- drivers/spi/spi-bitbang-txrx.h | 16 +-- drivers/spi/spi-bitbang.c | 8 +- drivers/spi/spi-cavium-thunderx.c | 2 +- drivers/spi/spi-davinci.c | 2 +- drivers/spi/spi-dw-core.c | 2 +- drivers/spi/spi-falcon.c | 2 +- drivers/spi/spi-fsl-lpspi.c | 2 +- drivers/spi/spi-gpio.c | 10 +- drivers/spi/spi-imx.c | 2 +- drivers/spi/spi-lp8841-rtc.c | 10 +- drivers/spi/spi-meson-spicc.c | 2 +- drivers/spi/spi-mt65xx.c | 2 +- drivers/spi/spi-mxs.c | 2 +- drivers/spi/spi-omap-uwire.c | 2 +- drivers/spi/spi-orion.c | 2 +- drivers/spi/spi-pci1xxxx.c | 2 +- drivers/spi/spi-pic32-sqi.c | 2 +- drivers/spi/spi-pic32.c | 2 +- drivers/spi/spi-qcom-qspi.c | 2 +- drivers/spi/spi-rb4xx.c | 2 +- drivers/spi/spi-rockchip-sfc.c | 2 +- drivers/spi/spi-rockchip.c | 2 +- drivers/spi/spi-sifive.c | 2 +- drivers/spi/spi-slave-mt27xx.c | 2 +- drivers/spi/spi-sprd-adi.c | 2 +- drivers/spi/spi-stm32.c | 2 +- drivers/spi/spi-ti-qspi.c | 2 +- drivers/spi/spi-xcomm.c | 2 +- drivers/spi/spi-xtensa-xtfpga.c | 2 +- drivers/spi/spi.c | 211 +++++++++++++----------------- include/linux/spi/spi.h | 173 ++++++++++++------------ include/trace/events/spi.h | 2 +- 36 files changed, 238 insertions(+), 252 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 3/14 spi: Refactor bus number assigning code in spi_register_controller()
Instead of 'else' branching use two sequential if:s, which allows to re-use the logic of IDR allocation in both cases.
--- drivers/spi/spi.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/spi/spi.c +3 -9
@@ -3122,8 +3122,8 @@ int spi_register_controller(struct spi_controller *ctlr) {struct device *dev = ctlr->dev.parent;struct boardinfo *bi; +int first_dynamic;int status; -int id, first_dynamic;if (!dev)return -ENODEV ;
@@ -3136,19 +3136,13 @@ int spi_register_controller(struct spi_controller *ctlr)if (status)return status; +if (ctlr->bus_num <0 ) + ctlr->bus_num =of_alias_get_id (ctlr->dev.of_node,"spi" );if (ctlr->bus_num >=0 ) {/* Devices with a fixed bus num must check-in with the num */ status =spi_controller_id_alloc (ctlr, ctlr->bus_num, ctlr->bus_num +1 );if (status)return status; - }else { -/* Allocate dynamic bus number using Linux idr */ - id =of_alias_get_id (ctlr->dev.of_node,"spi" ); -if (id >=0 ) { - status =spi_controller_id_alloc (ctlr, id, id +1 ); -if (status) -return status; - } }if (ctlr->bus_num <0 ) { first_dynamic =of_alias_get_highest_id ("spi" );
Signature · 1 line
2.40.0.1.gaa8946217a0b
PATCH v3 5/14 spi: Kill spi_add_device_locked()
In reply to Andy ShevchenkoNow, spi_add_device_locked() has just a line on top of __spi_add_device(). Besides that, it has a single caller. So, just kill it and embed its parts into the caller.
--- drivers/spi/spi.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/spi/spi.c +5 -10
@@ -708,14 +708,6 @@ int spi_add_device(struct spi_device *spi) }EXPORT_SYMBOL_GPL (spi_add_device); -static int spi_add_device_locked (struct spi_device *spi) -{ -struct spi_controller *ctlr = spi->controller; - -WARN_ON (!mutex_is_locked (&ctlr->add_lock)); -return __spi_add_device (spi); -} -/** * spi_new_device - instantiate one new SPI device * @ctlr: Controller to which device is connected
@@ -2417,11 +2409,12 @@ static void of_register_spi_devices(struct spi_controller *ctlr) { }struct spi_device *spi_new_ancillary_device (struct spi_device *spi,u8 chip_select) { +struct spi_controller *ctlr = spi->controller;struct spi_device *ancillary;int rc =0 ;/* Alloc an spi_device */ - ancillary =spi_alloc_device (spi->controller); + ancillary =spi_alloc_device (ctlr);if (!ancillary) { rc = -ENOMEM ; goto err_out;
@@ -2436,8 +2429,10 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi, ancillary->max_speed_hz = spi->max_speed_hz; ancillary->mode = spi->mode; +WARN_ON (!mutex_is_locked (&ctlr->add_lock)); +/* Register the new device */ - rc =spi_add_device_locked (ancillary); + rc =__spi_add_device (ancillary);if (rc) {dev_err (&spi->dev,"failed to register ancillary device\n" ); goto err_out;
Signature · 1 line
2.40.0.1.gaa8946217a0b
Re: [PATCH v3 04/14] spi: Remove code duplication in spi_add_device*()
In reply to Andy ShevchenkoHi,
Quoted 6 lines · Andy Shevchenko
The commit
0c79378c0199("spi: add ancillary device support") added a dozen of duplicating lines of code. We may move them to the__spi_add_device(). Note, that the code may be called under the mutex.Signed-off-by Andy Shevchenko <[email protected]>
-- Sebastian
Quoted 66 lines
--- drivers/spi/spi.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-)drivers/spi/spi.c +10
-22@@ -631,6 +631,16 @@ static int __spi_add_device(struct spi_device *spi)struct device *dev = ctlr->dev.parent;int status; +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), + ctlr->num_chipselect); +return -EINVAL ; + } + +/* Set the bus ID string */ +spi_dev_set_name (spi); +/* * We need to make sure there's no other device with this * chipselect **BEFORE** we call setup(), else we'll trash @@ -689,19 +699,8 @@ static int __spi_add_device(struct spi_device *spi)int spi_add_device (struct spi_device *spi) {struct spi_controller *ctlr = spi->controller; -struct device *dev = ctlr->dev.parent;int status; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; - } - -/* Set the bus ID string */ -spi_dev_set_name (spi); -mutex_lock (&ctlr->add_lock); status =__spi_add_device (spi);mutex_unlock (&ctlr->add_lock);@@ -712,17 +711,6 @@ EXPORT_SYMBOL_GPL(spi_add_device);static int spi_add_device_locked (struct spi_device *spi) {struct spi_controller *ctlr = spi->controller; -struct device *dev = ctlr->dev.parent; - -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; - } - -/* Set the bus ID string */ -spi_dev_set_name (spi);WARN_ON (!mutex_is_locked (&ctlr->add_lock));return __spi_add_device (spi);Signature · 1 line
2.40.0.1.gaa8946217a0b