* Re: [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case"
2019-07-01 17:25 [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
@ 2019-07-02 11:35 ` Mark Brown
2019-07-02 11:39 ` Mark Brown
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2019-07-02 11:35 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-spi, linux-gpio, Andrey Smirnov
[-- Attachment #1: Type: text/plain, Size: 326 bytes --]
On Mon, Jul 01, 2019 at 07:25:17PM +0200, Linus Walleij wrote:
> This reverts commit 249e2632dcd0509b8f8f296f5aabf4d48dfd6da8.
>
> After this commit drivers/net/dsa/vitesse-vsc73xx.c stopped
Please use subject lines matching the style for the subsystem. This
makes it easier for people to identify relevant patches.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case"
2019-07-01 17:25 [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
2019-07-02 11:35 ` Mark Brown
@ 2019-07-02 11:39 ` Mark Brown
2019-07-02 13:08 ` Linus Walleij
2019-07-02 13:04 ` Applied "Revert "spi: gpio: Don't request CS GPIO in DT use-case"" to the spi tree Mark Brown
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2019-07-02 11:39 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-spi, linux-gpio, Andrey Smirnov
[-- Attachment #1: Type: text/plain, Size: 544 bytes --]
On Mon, Jul 01, 2019 at 07:25:17PM +0200, Linus Walleij wrote:
> This reverts commit 249e2632dcd0509b8f8f296f5aabf4d48dfd6da8.
>
> After this commit drivers/net/dsa/vitesse-vsc73xx.c stopped
> working. Apparently CS is not working because the reads
> from the device is just returning just 1:s or just 0:s at
> all bisection points, so it is a complete regression and
> I think spi-gpio CS is essentially broken.
Also I'm a bit concerned that nobody else noticed this - do we
have any understanding of what the actual problem is?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case"
2019-07-02 11:39 ` Mark Brown
@ 2019-07-02 13:08 ` Linus Walleij
2019-07-02 19:41 ` Linus Walleij
0 siblings, 1 reply; 9+ messages in thread
From: Linus Walleij @ 2019-07-02 13:08 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi, open list:GPIO SUBSYSTEM, Andrey Smirnov
On Tue, Jul 2, 2019 at 1:39 PM Mark Brown <broonie@kernel.org> wrote:
> On Mon, Jul 01, 2019 at 07:25:17PM +0200, Linus Walleij wrote:
> > This reverts commit 249e2632dcd0509b8f8f296f5aabf4d48dfd6da8.
> >
> > After this commit drivers/net/dsa/vitesse-vsc73xx.c stopped
> > working. Apparently CS is not working because the reads
> > from the device is just returning just 1:s or just 0:s at
> > all bisection points, so it is a complete regression and
> > I think spi-gpio CS is essentially broken.
>
> Also I'm a bit concerned that nobody else noticed this - do we
> have any understanding of what the actual problem is?
I am trying to rootcause it, I suspect I was just the first to try this
on real hardware actually.
The users in the device trees in the kernel
mostly point to consumers like LEDs, displays and switches
that wouldn't cause boot regressions
instead you must observe more elaborate aspects of the system
so that is why the automatic test farms cannot see it.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 9+ messages in thread
* Applied "Revert "spi: gpio: Don't request CS GPIO in DT use-case"" to the spi tree
2019-07-01 17:25 [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
2019-07-02 11:35 ` Mark Brown
2019-07-02 11:39 ` Mark Brown
@ 2019-07-02 13:04 ` Mark Brown
2019-07-02 13:04 ` Applied "spi: gpio: Fix handling of CS GPIO for DT systems" " Mark Brown
2019-07-04 7:00 ` [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
4 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2019-07-02 13:04 UTC (permalink / raw)
To: Linus Walleij; +Cc: Andrey Smirnov, linux-gpio, linux-spi, Mark Brown
The patch
Revert "spi: gpio: Don't request CS GPIO in DT use-case"
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.3
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
From 0540ac3729da9c7d664197151fb7f432a1e11e3a Mon Sep 17 00:00:00 2001
From: Linus Walleij <linus.walleij@linaro.org>
Date: Mon, 1 Jul 2019 19:25:17 +0200
Subject: [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case"
This reverts commit 249e2632dcd0509b8f8f296f5aabf4d48dfd6da8.
After this commit drivers/net/dsa/vitesse-vsc73xx.c stopped
working. Apparently CS is not working because the reads
from the device is just returning just 1:s or just 0:s at
all bisection points, so it is a complete regression and
I think spi-gpio CS is essentially broken.
The revert had to be hand-crafted to preserve all the other
cleanup and changes to this driver, but now it works.
I'm sad to revert the change because it is a nice cleanup
but with the short time before v5.2 is released this is
probably the best idea, so we can figure out the right way
to do this in the next kernel cycle.
Fixes: 249e2632dcd0 ("spi: gpio: Don't request CS GPIO in DT use-case")
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
drivers/spi/spi-gpio.c | 137 +++++++++++++++++++++++------------------
1 file changed, 78 insertions(+), 59 deletions(-)
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index eca9d52ecf65..7cf800efef93 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -36,6 +36,7 @@ struct spi_gpio {
struct gpio_desc *miso;
struct gpio_desc *mosi;
struct gpio_desc **cs_gpios;
+ bool has_cs;
};
/*----------------------------------------------------------------------*/
@@ -205,7 +206,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL);
/* Drive chip select line, if we have one */
- if (spi_gpio->cs_gpios) {
+ if (spi_gpio->has_cs) {
struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select];
/* SPI chip selects are normally active-low */
@@ -223,12 +224,10 @@ static int spi_gpio_setup(struct spi_device *spi)
* The CS GPIOs have already been
* initialized from the descriptor lookup.
*/
- if (spi_gpio->cs_gpios) {
- cs = spi_gpio->cs_gpios[spi->chip_select];
- if (!spi->controller_state && cs)
- status = gpiod_direction_output(cs,
- !(spi->mode & SPI_CS_HIGH));
- }
+ cs = spi_gpio->cs_gpios[spi->chip_select];
+ if (!spi->controller_state && cs)
+ status = gpiod_direction_output(cs,
+ !(spi->mode & SPI_CS_HIGH));
if (!status)
status = spi_bitbang_setup(spi);
@@ -279,8 +278,12 @@ static void spi_gpio_cleanup(struct spi_device *spi)
* floating signals. (A weak pulldown would save power too, but many
* drivers expect to see all-ones data as the no slave "response".)
*/
-static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio)
+static int spi_gpio_request(struct device *dev,
+ struct spi_gpio *spi_gpio,
+ unsigned int num_chipselects)
{
+ int i;
+
spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW);
if (IS_ERR(spi_gpio->mosi))
return PTR_ERR(spi_gpio->mosi);
@@ -293,6 +296,13 @@ static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio)
if (IS_ERR(spi_gpio->sck))
return PTR_ERR(spi_gpio->sck);
+ for (i = 0; i < num_chipselects; i++) {
+ spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs",
+ i, GPIOD_OUT_HIGH);
+ if (IS_ERR(spi_gpio->cs_gpios[i]))
+ return PTR_ERR(spi_gpio->cs_gpios[i]);
+ }
+
return 0;
}
@@ -303,55 +313,44 @@ static const struct of_device_id spi_gpio_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids);
-static int spi_gpio_probe_dt(struct platform_device *pdev,
- struct spi_master *master)
+static int spi_gpio_probe_dt(struct platform_device *pdev)
{
- master->dev.of_node = pdev->dev.of_node;
- master->use_gpio_descriptors = true;
-
- return 0;
-}
-#else
-static inline int spi_gpio_probe_dt(struct platform_device *pdev,
- struct spi_master *master)
-{
- return 0;
-}
-#endif
-
-static int spi_gpio_probe_pdata(struct platform_device *pdev,
- struct spi_master *master)
-{
- struct device *dev = &pdev->dev;
- struct spi_gpio_platform_data *pdata = dev_get_platdata(dev);
- struct spi_gpio *spi_gpio = spi_master_get_devdata(master);
- int i;
+ int ret;
+ u32 tmp;
+ struct spi_gpio_platform_data *pdata;
+ struct device_node *np = pdev->dev.of_node;
+ const struct of_device_id *of_id =
+ of_match_device(spi_gpio_dt_ids, &pdev->dev);
-#ifdef GENERIC_BITBANG
- if (!pdata || !pdata->num_chipselect)
- return -ENODEV;
-#endif
- /*
- * The master needs to think there is a chipselect even if not
- * connected
- */
- master->num_chipselect = pdata->num_chipselect ?: 1;
+ if (!of_id)
+ return 0;
- spi_gpio->cs_gpios = devm_kcalloc(dev, master->num_chipselect,
- sizeof(*spi_gpio->cs_gpios),
- GFP_KERNEL);
- if (!spi_gpio->cs_gpios)
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
return -ENOMEM;
- for (i = 0; i < master->num_chipselect; i++) {
- spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", i,
- GPIOD_OUT_HIGH);
- if (IS_ERR(spi_gpio->cs_gpios[i]))
- return PTR_ERR(spi_gpio->cs_gpios[i]);
+
+ ret = of_property_read_u32(np, "num-chipselects", &tmp);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "num-chipselects property not found\n");
+ goto error_free;
}
+ pdata->num_chipselect = tmp;
+ pdev->dev.platform_data = pdata;
+
+ return 1;
+
+error_free:
+ devm_kfree(&pdev->dev, pdata);
+ return ret;
+}
+#else
+static inline int spi_gpio_probe_dt(struct platform_device *pdev)
+{
return 0;
}
+#endif
static void spi_gpio_put(void *data)
{
@@ -363,11 +362,22 @@ static int spi_gpio_probe(struct platform_device *pdev)
int status;
struct spi_master *master;
struct spi_gpio *spi_gpio;
+ struct spi_gpio_platform_data *pdata;
struct device *dev = &pdev->dev;
struct spi_bitbang *bb;
- const struct of_device_id *of_id;
+ bool use_of = 0;
- of_id = of_match_device(spi_gpio_dt_ids, &pdev->dev);
+ status = spi_gpio_probe_dt(pdev);
+ if (status < 0)
+ return status;
+ if (status > 0)
+ use_of = 1;
+
+ pdata = dev_get_platdata(dev);
+#ifdef GENERIC_BITBANG
+ if (!pdata || (!use_of && !pdata->num_chipselect))
+ return -ENODEV;
+#endif
master = spi_alloc_master(dev, sizeof(*spi_gpio));
if (!master)
@@ -377,17 +387,22 @@ static int spi_gpio_probe(struct platform_device *pdev)
if (status)
return status;
- if (of_id)
- status = spi_gpio_probe_dt(pdev, master);
- else
- status = spi_gpio_probe_pdata(pdev, master);
+ spi_gpio = spi_master_get_devdata(master);
- if (status)
- return status;
+ spi_gpio->cs_gpios = devm_kcalloc(dev,
+ pdata->num_chipselect,
+ sizeof(*spi_gpio->cs_gpios),
+ GFP_KERNEL);
+ if (!spi_gpio->cs_gpios)
+ return -ENOMEM;
- spi_gpio = spi_master_get_devdata(master);
+ platform_set_drvdata(pdev, spi_gpio);
+
+ /* Determine if we have chip selects connected */
+ spi_gpio->has_cs = !!pdata->num_chipselect;
- status = spi_gpio_request(dev, spi_gpio);
+ status = spi_gpio_request(dev, spi_gpio,
+ pdata->num_chipselect);
if (status)
return status;
@@ -405,9 +420,13 @@ static int spi_gpio_probe(struct platform_device *pdev)
}
master->bus_num = pdev->id;
+ /* The master needs to think there is a chipselect even if not connected */
+ master->num_chipselect = spi_gpio->has_cs ? pdata->num_chipselect : 1;
master->setup = spi_gpio_setup;
master->cleanup = spi_gpio_cleanup;
-
+#ifdef CONFIG_OF
+ master->dev.of_node = dev->of_node;
+#endif
bb = &spi_gpio->bitbang;
bb->master = master;
bb->chipselect = spi_gpio_chipselect;
--
2.20.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Applied "spi: gpio: Fix handling of CS GPIO for DT systems" to the spi tree
2019-07-01 17:25 [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
` (2 preceding siblings ...)
2019-07-02 13:04 ` Applied "Revert "spi: gpio: Don't request CS GPIO in DT use-case"" to the spi tree Mark Brown
@ 2019-07-02 13:04 ` Mark Brown
2019-07-04 7:00 ` [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
4 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2019-07-02 13:04 UTC (permalink / raw)
To: Linus Walleij; +Cc: Andrey Smirnov, linux-gpio, linux-spi, Mark Brown
The patch
spi: gpio: Fix handling of CS GPIO for DT systems
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.2
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
From 83ce8ad482f64159155b605add18eb130b6a03fc Mon Sep 17 00:00:00 2001
From: Linus Walleij <linus.walleij@linaro.org>
Date: Mon, 1 Jul 2019 19:25:17 +0200
Subject: [PATCH] spi: gpio: Fix handling of CS GPIO for DT systems
This reverts commit 249e2632dcd0509b8f8f296f5aabf4d48dfd6da8.
After this commit drivers/net/dsa/vitesse-vsc73xx.c stopped
working. Apparently CS is not working because the reads
from the device is just returning just 1:s or just 0:s at
all bisection points, so it is a complete regression and
I think spi-gpio CS is essentially broken. [No other reports?
A bit concerning... --- broonie]
The revert had to be hand-crafted to preserve all the other
cleanup and changes to this driver, but now it works.
I'm sad to revert the change because it is a nice cleanup
but with the short time before v5.2 is released this is
probably the best idea, so we can figure out the right way
to do this in the next kernel cycle.
Fixes: 249e2632dcd0 ("spi: gpio: Don't request CS GPIO in DT use-case")
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
drivers/spi/spi-gpio.c | 137 +++++++++++++++++++++++------------------
1 file changed, 78 insertions(+), 59 deletions(-)
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 487ee55d26f7..45f3c196cc60 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -45,6 +45,7 @@ struct spi_gpio {
struct gpio_desc *miso;
struct gpio_desc *mosi;
struct gpio_desc **cs_gpios;
+ bool has_cs;
};
/*----------------------------------------------------------------------*/
@@ -214,7 +215,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL);
/* Drive chip select line, if we have one */
- if (spi_gpio->cs_gpios) {
+ if (spi_gpio->has_cs) {
struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select];
/* SPI chip selects are normally active-low */
@@ -232,12 +233,10 @@ static int spi_gpio_setup(struct spi_device *spi)
* The CS GPIOs have already been
* initialized from the descriptor lookup.
*/
- if (spi_gpio->cs_gpios) {
- cs = spi_gpio->cs_gpios[spi->chip_select];
- if (!spi->controller_state && cs)
- status = gpiod_direction_output(cs,
- !(spi->mode & SPI_CS_HIGH));
- }
+ cs = spi_gpio->cs_gpios[spi->chip_select];
+ if (!spi->controller_state && cs)
+ status = gpiod_direction_output(cs,
+ !(spi->mode & SPI_CS_HIGH));
if (!status)
status = spi_bitbang_setup(spi);
@@ -288,8 +287,12 @@ static void spi_gpio_cleanup(struct spi_device *spi)
* floating signals. (A weak pulldown would save power too, but many
* drivers expect to see all-ones data as the no slave "response".)
*/
-static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio)
+static int spi_gpio_request(struct device *dev,
+ struct spi_gpio *spi_gpio,
+ unsigned int num_chipselects)
{
+ int i;
+
spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW);
if (IS_ERR(spi_gpio->mosi))
return PTR_ERR(spi_gpio->mosi);
@@ -302,6 +305,13 @@ static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio)
if (IS_ERR(spi_gpio->sck))
return PTR_ERR(spi_gpio->sck);
+ for (i = 0; i < num_chipselects; i++) {
+ spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs",
+ i, GPIOD_OUT_HIGH);
+ if (IS_ERR(spi_gpio->cs_gpios[i]))
+ return PTR_ERR(spi_gpio->cs_gpios[i]);
+ }
+
return 0;
}
@@ -312,55 +322,44 @@ static const struct of_device_id spi_gpio_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids);
-static int spi_gpio_probe_dt(struct platform_device *pdev,
- struct spi_master *master)
+static int spi_gpio_probe_dt(struct platform_device *pdev)
{
- master->dev.of_node = pdev->dev.of_node;
- master->use_gpio_descriptors = true;
-
- return 0;
-}
-#else
-static inline int spi_gpio_probe_dt(struct platform_device *pdev,
- struct spi_master *master)
-{
- return 0;
-}
-#endif
-
-static int spi_gpio_probe_pdata(struct platform_device *pdev,
- struct spi_master *master)
-{
- struct device *dev = &pdev->dev;
- struct spi_gpio_platform_data *pdata = dev_get_platdata(dev);
- struct spi_gpio *spi_gpio = spi_master_get_devdata(master);
- int i;
+ int ret;
+ u32 tmp;
+ struct spi_gpio_platform_data *pdata;
+ struct device_node *np = pdev->dev.of_node;
+ const struct of_device_id *of_id =
+ of_match_device(spi_gpio_dt_ids, &pdev->dev);
-#ifdef GENERIC_BITBANG
- if (!pdata || !pdata->num_chipselect)
- return -ENODEV;
-#endif
- /*
- * The master needs to think there is a chipselect even if not
- * connected
- */
- master->num_chipselect = pdata->num_chipselect ?: 1;
+ if (!of_id)
+ return 0;
- spi_gpio->cs_gpios = devm_kcalloc(dev, master->num_chipselect,
- sizeof(*spi_gpio->cs_gpios),
- GFP_KERNEL);
- if (!spi_gpio->cs_gpios)
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
return -ENOMEM;
- for (i = 0; i < master->num_chipselect; i++) {
- spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", i,
- GPIOD_OUT_HIGH);
- if (IS_ERR(spi_gpio->cs_gpios[i]))
- return PTR_ERR(spi_gpio->cs_gpios[i]);
+
+ ret = of_property_read_u32(np, "num-chipselects", &tmp);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "num-chipselects property not found\n");
+ goto error_free;
}
+ pdata->num_chipselect = tmp;
+ pdev->dev.platform_data = pdata;
+
+ return 1;
+
+error_free:
+ devm_kfree(&pdev->dev, pdata);
+ return ret;
+}
+#else
+static inline int spi_gpio_probe_dt(struct platform_device *pdev)
+{
return 0;
}
+#endif
static void spi_gpio_put(void *data)
{
@@ -372,11 +371,22 @@ static int spi_gpio_probe(struct platform_device *pdev)
int status;
struct spi_master *master;
struct spi_gpio *spi_gpio;
+ struct spi_gpio_platform_data *pdata;
struct device *dev = &pdev->dev;
struct spi_bitbang *bb;
- const struct of_device_id *of_id;
+ bool use_of = 0;
- of_id = of_match_device(spi_gpio_dt_ids, &pdev->dev);
+ status = spi_gpio_probe_dt(pdev);
+ if (status < 0)
+ return status;
+ if (status > 0)
+ use_of = 1;
+
+ pdata = dev_get_platdata(dev);
+#ifdef GENERIC_BITBANG
+ if (!pdata || (!use_of && !pdata->num_chipselect))
+ return -ENODEV;
+#endif
master = spi_alloc_master(dev, sizeof(*spi_gpio));
if (!master)
@@ -386,17 +396,22 @@ static int spi_gpio_probe(struct platform_device *pdev)
if (status)
return status;
- if (of_id)
- status = spi_gpio_probe_dt(pdev, master);
- else
- status = spi_gpio_probe_pdata(pdev, master);
+ spi_gpio = spi_master_get_devdata(master);
- if (status)
- return status;
+ spi_gpio->cs_gpios = devm_kcalloc(dev,
+ pdata->num_chipselect,
+ sizeof(*spi_gpio->cs_gpios),
+ GFP_KERNEL);
+ if (!spi_gpio->cs_gpios)
+ return -ENOMEM;
- spi_gpio = spi_master_get_devdata(master);
+ platform_set_drvdata(pdev, spi_gpio);
+
+ /* Determine if we have chip selects connected */
+ spi_gpio->has_cs = !!pdata->num_chipselect;
- status = spi_gpio_request(dev, spi_gpio);
+ status = spi_gpio_request(dev, spi_gpio,
+ pdata->num_chipselect);
if (status)
return status;
@@ -414,9 +429,13 @@ static int spi_gpio_probe(struct platform_device *pdev)
}
master->bus_num = pdev->id;
+ /* The master needs to think there is a chipselect even if not connected */
+ master->num_chipselect = spi_gpio->has_cs ? pdata->num_chipselect : 1;
master->setup = spi_gpio_setup;
master->cleanup = spi_gpio_cleanup;
-
+#ifdef CONFIG_OF
+ master->dev.of_node = dev->of_node;
+#endif
bb = &spi_gpio->bitbang;
bb->master = master;
bb->chipselect = spi_gpio_chipselect;
--
2.20.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case"
2019-07-01 17:25 [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
` (3 preceding siblings ...)
2019-07-02 13:04 ` Applied "spi: gpio: Fix handling of CS GPIO for DT systems" " Mark Brown
@ 2019-07-04 7:00 ` Linus Walleij
2019-07-04 11:49 ` Mark Brown
4 siblings, 1 reply; 9+ messages in thread
From: Linus Walleij @ 2019-07-04 7:00 UTC (permalink / raw)
To: Mark Brown, linux-spi; +Cc: open list:GPIO SUBSYSTEM, Andrey Smirnov
Hi Mark,
the proper fix is now upstream in Torvald's tree so you can drop/revert
this patch.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case"
2019-07-04 7:00 ` [PATCH] Revert "spi: gpio: Don't request CS GPIO in DT use-case" Linus Walleij
@ 2019-07-04 11:49 ` Mark Brown
0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2019-07-04 11:49 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-spi, open list:GPIO SUBSYSTEM, Andrey Smirnov
[-- Attachment #1: Type: text/plain, Size: 188 bytes --]
On Thu, Jul 04, 2019 at 09:00:17AM +0200, Linus Walleij wrote:
> Hi Mark,
>
> the proper fix is now upstream in Torvald's tree so you can drop/revert
> this patch.
Great, thanks.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread