Fix for imx-spi CS GPIOs
Subsystems (4)
v3 cover Fix for imx-spi CS GPIOs
This fixes a bug where GPIO based chip selects must be specified in the OF node for spi-imx when they should be optional.
Fixes a regression in the platform data of imx31moboard.
Clean up of some old platform data based spi-imx users.
Changes from V1:
* Collected reviewed bys.
* Minor change to coding style in one patch.
Changes from V2:
* Reverted minor coding change from V2, it was right to begin with
* Have imx-spi also honor "num-cs" property
* Leak of spi_bitbang on failure needed to be fixed differently
* Port to linux-next, which has other changes to spi-imx
Trent Piepho (4):
spi: imx: GPIO based chip selects should not be required
spi: imx: Fix failure path leak on GPIO request error
spi: imx: Don't require platform data chipselect array
ARM: imx: Update spi_imx platform data to reflect current state
arch/arm/mach-imx/mach-mx31_3ds.c | 18 ++---------------- arch/arm/mach-imx/mach-mx31lilly.c | 12 ++---------- arch/arm/mach-imx/mach-mx31lite.c | 16 ++-------------- arch/arm/mach-imx/mach-mx31moboard.c | 17 +++-------------- arch/arm/mach-imx/mach-pcm037_eet.c | 5 +---- drivers/spi/spi-imx.c | 36 ++++++++++++++++++++--------------- include/linux/platform_data/spi-imx.h | 29 ++++++++++++++++------------ 7 files changed, 48 insertions(+), 85 deletions(-)
Signature · 1 line
2.14.3
PATCH v3 1/4 spi: imx: GPIO based chip selects should not be required
The driver will fail to load if no gpio chip selects are specified, this patch changes this so that it no longer fails.
It's possible to use all native chip selects, in which case there is no reason to have a gpio chip select array. This is what happens if the *optional* device tree property "cs-gpios" is omitted.
The spi core already checks for the absence of gpio chip selects in the master and assigns any slaves the gpio_cs value of -ENOENT.
Also have the driver respect the standard SPI device tree property "num-cs" to allow setting the number of chip selects without using cs-gpios.
--- drivers/spi/spi-imx.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/spi/spi-imx.c +10 -8
@@ -1523,6 +1523,7 @@ static int spi_imx_probe(struct platform_device *pdev) spi_imx->devtype_data = devtype_data; +/* Get number of chip selects, either platform data or OF */ if (mxc_platform_info) { master->num_chipselect = mxc_platform_info->num_chipselect; master->cs_gpios = devm_kzalloc(&master->dev,
@@ -1532,7 +1533,13 @@ static int spi_imx_probe(struct platform_device *pdev)for (i =0 ; i < master->num_chipselect; i++) master->cs_gpios[i] = mxc_platform_info->chipselect[i]; - } + }else { +u32 num_cs; + +if (!of_property_read_u32 (np,"num-cs" , &num_cs)) + master->num_chipselect = num_cs; +/* If not preset, default value of 1 is used */ + } spi_imx->bitbang.chipselect = spi_imx_chipselect; spi_imx->bitbang.setup_transfer = spi_imx_setupxfer;
@@ -1619,13 +1626,8 @@ static int spi_imx_probe(struct platform_device *pdev) goto out_clk_put; } -if (!spi_imx->slave_mode) { -if (!master->cs_gpios) { -dev_err (&pdev->dev,"No CS GPIOs available\n" ); - ret = -EINVAL ; - goto out_clk_put; - } - +/* Request GPIO CS lines, if any */ +if (!spi_imx->slave_mode && master->cs_gpios) {for (i =0 ; i < master->num_chipselect; i++) {if (!gpio_is_valid (master->cs_gpios[i]))continue ;
Signature · 1 line
2.14.3
PATCH v3 2/4 spi: imx: Fix failure path leak on GPIO request error
In reply to Trent PiephoIf the code that requests any chip select GPIOs fails, the cleanup of spi_bitbang_start() by calling spi_bitbang_stop() is not done. Add this to the failure path.
Note that spi_bitbang_start() has to be called before requesting GPIOs because the GPIO data in the spi master is populated when the master is registed, and that doesn't happen until spi_bitbang_start() is called.
--- drivers/spi/spi-imx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi-imx.c +3 -1
@@ -1638,7 +1638,7 @@ static int spi_imx_probe(struct platform_device *pdev)if (ret) {dev_err (&pdev->dev,"Can't get CS GPIO %i\n" , master->cs_gpios[i]); - goto out_clk_put; + goto out_spi_bitbang; } } }
@@ -1649,6 +1649,8 @@ static int spi_imx_probe(struct platform_device *pdev)clk_disable (spi_imx->clk_per);return ret; +out_spi_bitbang: +spi_bitbang_stop (&spi_imx->bitbang); out_clk_put:clk_disable_unprepare (spi_imx->clk_ipg); out_put_per:
Signature · 1 line
2.14.3
Mark Brown
maintainerPATCH v3 2/4 spi: imx: Fix failure path leak on GPIO request error
Quoted 3 lines · Trent Piepho
If the code that requests any chip select GPIOs fails, the cleanup of
spi_bitbang_start()by callingspi_bitbang_stop()is not done. Add this to the failure path.
Please don't resubmit patches that have already been applied, you should
submit patches against current code in the tree you're expecting things
to be applied to. If any updates are needed to a patch that's already
been applied you should submit incremental patches which make those
updates. This avoids having to change published git commits which could
cause problems for people working against git.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171031/533efddf/attachment.sig>
A message that is not in the archive (sent off-list or not yet received): 20171031194907.29108-3-tpiepho-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org
Applied "spi: imx: Fix failure path leak on GPIO request error" to the spi tree
The patch
spi: imx: Fix failure path leak on GPIO request error
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
4e21791e741c7c1b962c4a8327529f52310b9aacMon Sep 17 00:00:00 2001
From: Trent Piepho <[email protected]>
Date: Tue, 31 Oct 2017 12:49:05 -0700
Subject: [PATCH] spi: imx: Fix failure path leak on GPIO request error
If the code that requests any chip select GPIOs fails, the cleanup of spi_bitbang_start() by calling spi_bitbang_stop() is not done. Add this to the failure path.
Note that spi_bitbang_start() has to be called before requesting GPIOs because the GPIO data in the spi master is populated when the master is registed, and that doesn't happen until spi_bitbang_start() is called.
--- drivers/spi/spi-imx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/spi/spi-imx.c +3 -1
@@ -1633,7 +1633,7 @@ static int spi_imx_probe(struct platform_device *pdev)if (ret) {dev_err (&pdev->dev,"Can't get CS GPIO %i\n" , master->cs_gpios[i]); - goto out_clk_put; + goto out_spi_bitbang; } } }
@@ -1650,6 +1650,8 @@ static int spi_imx_probe(struct platform_device *pdev)clk_disable (spi_imx->clk_per);return ret; +out_spi_bitbang: +spi_bitbang_stop (&spi_imx->bitbang); out_clk_put:clk_disable_unprepare (spi_imx->clk_ipg); out_put_per:
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 3/4 spi: imx: Don't require platform data chipselect array
In reply to Trent PiephoIf the array is not present, assume all chip selects are native. This is the standard behavior for SPI masters configured via the device tree and the behavior of this driver as well when it is configured via device tree.
This reduces platform data vs DT differences and allows most of the platform data based boards to remove their chip select arrays.
--- drivers/spi/spi-imx.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/spi/spi-imx.c +9 -7
@@ -1526,13 +1526,15 @@ static int spi_imx_probe(struct platform_device *pdev)/* Get number of chip selects, either platform data or OF */ if (mxc_platform_info) { master->num_chipselect = mxc_platform_info->num_chipselect; - master->cs_gpios =devm_kzalloc (&master->dev, -sizeof (int ) * master->num_chipselect,GFP_KERNEL ); -if (!master->cs_gpios) -return -ENOMEM ; - -for (i =0 ; i < master->num_chipselect; i++) - master->cs_gpios[i] = mxc_platform_info->chipselect[i]; +if (mxc_platform_info->chipselect) { + master->cs_gpios =devm_kzalloc (&master->dev, +sizeof (int ) * master->num_chipselect,GFP_KERNEL ); +if (!master->cs_gpios) +return -ENOMEM ; + +for (i =0 ; i < master->num_chipselect; i++) + master->cs_gpios[i] = mxc_platform_info->chipselect[i]; + } }else {u32 num_cs;
Signature · 1 line
2.14.3
A message that is not in the archive (sent off-list or not yet received): 20171031194907.29108-4-tpiepho-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org
Applied "spi: imx: Don't require platform data chipselect array" to the spi tree
The patch
spi: imx: Don't require platform data chipselect array
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
ffd4db9e10fdb431b559af052c17015682bbe2aaMon Sep 17 00:00:00 2001
From: Trent Piepho <[email protected]>
Date: Tue, 31 Oct 2017 12:49:06 -0700
Subject: [PATCH] spi: imx: Don't require platform data chipselect array
If the array is not present, assume all chip selects are native. This is the standard behavior for SPI masters configured via the device tree and the behavior of this driver as well when it is configured via device tree.
This reduces platform data vs DT differences and allows most of the platform data based boards to remove their chip select arrays.
--- drivers/spi/spi-imx.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/spi/spi-imx.c +9 -7
@@ -1526,13 +1526,15 @@ static int spi_imx_probe(struct platform_device *pdev)/* Get number of chip selects, either platform data or OF */ if (mxc_platform_info) { master->num_chipselect = mxc_platform_info->num_chipselect; - master->cs_gpios =devm_kzalloc (&master->dev, -sizeof (int ) * master->num_chipselect,GFP_KERNEL ); -if (!master->cs_gpios) -return -ENOMEM ; - -for (i =0 ; i < master->num_chipselect; i++) - master->cs_gpios[i] = mxc_platform_info->chipselect[i]; +if (mxc_platform_info->chipselect) { + master->cs_gpios =devm_kzalloc (&master->dev, +sizeof (int ) * master->num_chipselect,GFP_KERNEL ); +if (!master->cs_gpios) +return -ENOMEM ; + +for (i =0 ; i < master->num_chipselect; i++) + master->cs_gpios[i] = mxc_platform_info->chipselect[i]; + } }else {u32 num_cs;
Signature · 6 lines
2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 4/4 ARM: imx: Update spi_imx platform data to reflect current state
In reply to Trent PiephoThe docs for the spi_imx platform data still refer to a -32 offset used to specify a native chip select. This was removed in commit 602c8f4485cd ("spi: imx: fix use of native chip-selects with devicetree") and no longer works as documented. Update documentation.
The macro MXC_SPI_CS() is no longer is needed.
If a board uses all native chip selects, then it's not necessary to specify a chip select array at all, as all native is the default (this is how device-tree configured SPI masters work too). Most of the spi-imx platform data users have their chip select arrays removed by this patch.
This patch also fixes a bug in mx31moboard introduced in the '602 commit. When that board was updated in commit 901f26bce64a ("ARM: imx: set correct chip_select in platform setup") to reflect the SPI change, only SPI bus 2 was updated and SPI bus 1 was left with non-sequential chip selects. The mc13783 spi device on bus 1 had its chip select updated as if it were on bus 2.
--- arch/arm/mach-imx/mach-mx31_3ds.c | 18 ++---------------- arch/arm/mach-imx/mach-mx31lilly.c | 12 ++---------- arch/arm/mach-imx/mach-mx31lite.c | 16 ++-------------- arch/arm/mach-imx/mach-mx31moboard.c | 17 +++-------------- arch/arm/mach-imx/mach-pcm037_eet.c | 5 +---- include/linux/platform_data/spi-imx.h | 29 +++++++++++++++++------------ 6 files changed, 27 insertions(+), 70 deletions(-)
arch/arm/mach-imx/mach-mx31_3ds.c +2 -16
@@ -374,26 +374,12 @@ static struct imx_ssi_platform_data mx31_3ds_ssi_pdata = { };/* SPI */ -static int spi0_internal_chipselect[] = { -MXC_SPI_CS (0 ), -MXC_SPI_CS (1 ), -MXC_SPI_CS (2 ), -}; -static const struct spi_imx_master spi0_pdata__initconst = { - .chipselect = spi0_internal_chipselect, - .num_chipselect =ARRAY_SIZE (spi0_internal_chipselect), -}; - -static int spi1_internal_chipselect[] = { -MXC_SPI_CS (0 ), -MXC_SPI_CS (1 ), -MXC_SPI_CS (2 ), + .num_chipselect =3 , };static const struct spi_imx_master spi1_pdata__initconst = { - .chipselect = spi1_internal_chipselect, - .num_chipselect =ARRAY_SIZE (spi1_internal_chipselect), + .num_chipselect =3 , };static struct spi_board_info mx31_3ds_spi_devs[]__initdata = {
arch/arm/mach-imx/mach-mx31lilly.c +2 -10
@@ -226,20 +226,12 @@ static void __init lilly1131_usb_init(void)/* SPI */ -static int spi_internal_chipselect[] = { -MXC_SPI_CS (0 ), -MXC_SPI_CS (1 ), -MXC_SPI_CS (2 ), -}; -static const struct spi_imx_master spi0_pdata__initconst = { - .chipselect = spi_internal_chipselect, - .num_chipselect =ARRAY_SIZE (spi_internal_chipselect), + .num_chipselect =3 , };static const struct spi_imx_master spi1_pdata__initconst = { - .chipselect = spi_internal_chipselect, - .num_chipselect =ARRAY_SIZE (spi_internal_chipselect), + .num_chipselect =3 , };static struct mc13xxx_platform_data mc13783_pdata__initdata = {
arch/arm/mach-imx/mach-mx31lite.c +2 -14
@@ -83,15 +83,8 @@ static const struct imxuart_platform_data uart_pdata __initconst = { };/* SPI */ -static int spi0_internal_chipselect[] = { -MXC_SPI_CS (0 ), -MXC_SPI_CS (1 ), -MXC_SPI_CS (2 ), -}; -static const struct spi_imx_master spi0_pdata__initconst = { - .chipselect = spi0_internal_chipselect, - .num_chipselect =ARRAY_SIZE (spi0_internal_chipselect), + .num_chipselect =3 , }; static const struct mxc_nand_platform_data
@@ -133,13 +126,8 @@ static struct platform_device smsc911x_device = {* The MC13783 is the only hard-wired SPI device on the module. */ -static int spi1_internal_chipselect[] = { -MXC_SPI_CS (0 ), -}; -static const struct spi_imx_master spi1_pdata__initconst = { - .chipselect = spi1_internal_chipselect, - .num_chipselect =ARRAY_SIZE (spi1_internal_chipselect), + .num_chipselect =1 , };static struct mc13xxx_platform_data mc13783_pdata__initdata = {
arch/arm/mach-imx/mach-mx31moboard.c +3 -14
@@ -152,14 +152,8 @@ static const struct imxi2c_platform_data moboard_i2c1_data __initconst = { .bitrate = 100000, }; -static int moboard_spi1_cs[] = { -MXC_SPI_CS (0 ), -MXC_SPI_CS (2 ), -}; -static const struct spi_imx_master moboard_spi1_pdata__initconst = { - .chipselect = moboard_spi1_cs, - .num_chipselect =ARRAY_SIZE (moboard_spi1_cs), + .num_chipselect =3 , };static struct regulator_consumer_supply sdhc_consumers[] = {
@@ -296,19 +290,14 @@ static struct spi_board_info moboard_spi_board_info[] __initdata = {/* irq number is run-time assigned */ .max_speed_hz = 300000, .bus_num = 1, - .chip_select = 1, + .chip_select = 0, .platform_data = &moboard_pmic, .mode = SPI_CS_HIGH, }, }; -static int moboard_spi2_cs[] = { -MXC_SPI_CS (0 ),MXC_SPI_CS (1 ), -}; -static const struct spi_imx_master moboard_spi2_pdata__initconst = { - .chipselect = moboard_spi2_cs, - .num_chipselect =ARRAY_SIZE (moboard_spi2_cs), + .num_chipselect =2 , };#define SDHC1_CD IOMUX_TO_GPIO(MX31_PIN_ATA_CS0)
arch/arm/mach-imx/mach-pcm037_eet.c +1 -4
@@ -56,11 +56,8 @@ static struct spi_board_info pcm037_spi_dev[] = { };/* Platform Data for MXC CSPI */ -static int pcm037_spi1_cs[] = {MXC_SPI_CS (0 ),MXC_SPI_CS (1 ), }; -static const struct spi_imx_master pcm037_spi1_pdata__initconst = { - .chipselect = pcm037_spi1_cs, - .num_chipselect =ARRAY_SIZE (pcm037_spi1_cs), + .num_chipselect =2 , };/* GPIO-keys input device */
include/linux/platform_data/spi-imx.h +17 -12
@@ -4,24 +4,29 @@/* * struct spi_imx_master - device.platform_data for SPI controller devices. -* @chipselect: Array of chipselects for this master. Numbers >= 0 mean gpio -* pins, numbers < 0 mean internal CSPI chipselects according -* to MXC_SPI_CS(). Normally you want to use gpio based chip -* selects as the CSPI module tries to be intelligent about -* when to assert the chipselect: The CSPI module deasserts the -* chipselect once it runs out of input data. The other problem -* is that it is not possible to mix between high active and low -* active chipselects on one single bus using the internal -* chipselects. Unfortunately Freescale decided to put some +* @chipselect: Array of chipselects for this master or NULL. Numbers >= 0 +* mean GPIO pins, -ENOENT means internal CSPI chipselect +* matching the position in the array. E.g., if chipselect[1] = +* -ENOENT then a SPI slave using chip select 1 will use the +* native SS1 line of the CSPI. Omitting the array will use +* all native chip selects. + +* Normally you want to use gpio based chip selects as the CSPI +* module tries to be intelligent about when to assert the +* chipselect: The CSPI module deasserts the chipselect once it +* runs out of input data. The other problem is that it is not +* possible to mix between high active and low active chipselects +* on one single bus using the internal chipselects. +* Unfortunately, on some SoCs, Freescale decided to put some * chipselects on dedicated pins which are not usable as gpios, * so we have to support the internal chipselects. -* @num_chipselect: ARRAY_SIZE(chipselect) +* +* @num_chipselect: If @chipselect is specified, ARRAY_SIZE(chipselect), +* otherwise the number of native chip selects. */ struct spi_imx_master {int *chipselect;int num_chipselect; }; -#define MXC_SPI_CS (no) ((no) - 32) -#endif /* __MACH_SPI_H_*/
Signature · 1 line
2.14.3