Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1262952 > unrolled thread

[PATCH] spi: mediatek: single device does not require cs_gpios

Started byNicolas Boichat <drinkcat@chromium.org>
First post2015-11-05 07:00 +0100
Last post2015-11-05 11:40 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] spi: mediatek: single device does not require cs_gpios Nicolas Boichat <drinkcat@chromium.org> - 2015-11-05 07:00 +0100
    Re: [PATCH] spi: mediatek: single device does not require cs_gpios Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-11-05 10:20 +0100
      Re: [PATCH] spi: mediatek: single device does not require cs_gpios Nicolas Boichat <drinkcat@chromium.org> - 2015-11-05 11:40 +0100

#1262952 — [PATCH] spi: mediatek: single device does not require cs_gpios

FromNicolas Boichat <drinkcat@chromium.org>
Date2015-11-05 07:00 +0100
Subject[PATCH] spi: mediatek: single device does not require cs_gpios
Message-ID<qrlKz-2wU-23@gated-at.bofh.it>
When only one device is present, it is not necessary to specify
cs_gpios, as the CS line can be controlled by the hardware
module.

Without this patch, older device tree bindings used before
37457607 "spi: mediatek: mt8173 spi multiple devices support"
would cause a panic on boot. This fixes the crash, and
re-introduces backward compatibility.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
---

Applies on top of broonie/spi.git topic/mtk. Thanks!

 drivers/spi/spi-mt65xx.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 563954a..f694031 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -410,7 +410,7 @@ static int mtk_spi_setup(struct spi_device *spi)
 	if (!spi->controller_data)
 		spi->controller_data = (void *)&mtk_default_chip_info;
 
-	if (mdata->dev_comp->need_pad_sel)
+	if (mdata->dev_comp->need_pad_sel && spi->cs_gpio >= 0)
 		gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
 
 	return 0;
@@ -632,13 +632,23 @@ static int mtk_spi_probe(struct platform_device *pdev)
 			goto err_put_master;
 		}
 
-		for (i = 0; i < master->num_chipselect; i++) {
-			ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i],
-						dev_name(&pdev->dev));
-			if (ret) {
-				dev_err(&pdev->dev,
-					"can't get CS GPIO %i\n", i);
-				goto err_put_master;
+		if (!master->cs_gpios && master->num_chipselect > 1) {
+			dev_err(&pdev->dev,
+				"cs_gpios not specified and num_chipselect > 1\n");
+			ret = -EINVAL;
+			goto err_put_master;
+		}
+
+		if (master->cs_gpios) {
+			for (i = 0; i < master->num_chipselect; i++) {
+				ret = devm_gpio_request(&pdev->dev,
+							master->cs_gpios[i],
+							dev_name(&pdev->dev));
+				if (ret) {
+					dev_err(&pdev->dev,
+						"can't get CS GPIO %i\n", i);
+					goto err_put_master;
+				}
 			}
 		}
 	}
-- 
2.6.0.rc2.230.g3dd15c0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1263033

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2015-11-05 10:20 +0100
Message-ID<qroS6-4FF-15@gated-at.bofh.it>
In reply to#1262952
On Thu, Nov 5, 2015 at 7:50 AM, Nicolas Boichat <drinkcat@chromium.org> wrote:
> When only one device is present, it is not necessary to specify
> cs_gpios, as the CS line can be controlled by the hardware
> module.
>
> Without this patch, older device tree bindings used before
> 37457607 "spi: mediatek: mt8173 spi multiple devices support"
> would cause a panic on boot. This fixes the crash, and
> re-introduces backward compatibility.
>
> Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
> ---
>
> Applies on top of broonie/spi.git topic/mtk. Thanks!
>
>  drivers/spi/spi-mt65xx.c | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
> index 563954a..f694031 100644
> --- a/drivers/spi/spi-mt65xx.c
> +++ b/drivers/spi/spi-mt65xx.c
> @@ -410,7 +410,7 @@ static int mtk_spi_setup(struct spi_device *spi)
>         if (!spi->controller_data)
>                 spi->controller_data = (void *)&mtk_default_chip_info;
>
> -       if (mdata->dev_comp->need_pad_sel)
> +       if (mdata->dev_comp->need_pad_sel && spi->cs_gpio >= 0)

gpio_is_valid() ?

>                 gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
>
>         return 0;
> @@ -632,13 +632,23 @@ static int mtk_spi_probe(struct platform_device *pdev)
>                         goto err_put_master;
>                 }
>
> -               for (i = 0; i < master->num_chipselect; i++) {
> -                       ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i],
> -                                               dev_name(&pdev->dev));
> -                       if (ret) {
> -                               dev_err(&pdev->dev,
> -                                       "can't get CS GPIO %i\n", i);
> -                               goto err_put_master;
> +               if (!master->cs_gpios && master->num_chipselect > 1) {
> +                       dev_err(&pdev->dev,
> +                               "cs_gpios not specified and num_chipselect > 1\n");
> +                       ret = -EINVAL;
> +                       goto err_put_master;
> +               }
> +
> +               if (master->cs_gpios) {
> +                       for (i = 0; i < master->num_chipselect; i++) {
> +                               ret = devm_gpio_request(&pdev->dev,
> +                                                       master->cs_gpios[i],
> +                                                       dev_name(&pdev->dev));
> +                               if (ret) {
> +                                       dev_err(&pdev->dev,
> +                                               "can't get CS GPIO %i\n", i);
> +                                       goto err_put_master;
> +                               }
>                         }
>                 }
>         }
> --
> 2.6.0.rc2.230.g3dd15c0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-spi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1263082

FromNicolas Boichat <drinkcat@chromium.org>
Date2015-11-05 11:40 +0100
Message-ID<qrq7w-5nA-11@gated-at.bofh.it>
In reply to#1263033
On Thu, Nov 5, 2015 at 5:16 PM, Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Thu, Nov 5, 2015 at 7:50 AM, Nicolas Boichat <drinkcat@chromium.org> wrote:
[...]
>> diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
>> index 563954a..f694031 100644
>> --- a/drivers/spi/spi-mt65xx.c
>> +++ b/drivers/spi/spi-mt65xx.c
>> @@ -410,7 +410,7 @@ static int mtk_spi_setup(struct spi_device *spi)
>>         if (!spi->controller_data)
>>                 spi->controller_data = (void *)&mtk_default_chip_info;
>>
>> -       if (mdata->dev_comp->need_pad_sel)
>> +       if (mdata->dev_comp->need_pad_sel && spi->cs_gpio >= 0)
>
> gpio_is_valid() ?

Yes, thanks! Will fix in next round. (there is a few other ones in
driver/spi/* that should probably be fixed too...)

Best,
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web