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


Groups > linux.kernel > #1306479

Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice

From Cyrille Pitchen <cyrille.pitchen@atmel.com>
Newsgroups linux.kernel
Subject Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice
Date 2016-01-11 17:40 +0100
Message-ID <qPNFE-4Vc-21@gated-at.bofh.it> (permalink)
References <qOsWC-7b8-9@gated-at.bofh.it> <qPMzU-4ae-33@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Hi Mans,

Le 11/01/2016 16:26, Nicolas Ferre a écrit :
> Le 08/01/2016 01:11, Mans Rullgard a écrit :
[...]
>> @@ -1569,13 +1576,6 @@ static int atmel_spi_probe(struct platform_device *pdev)
>>  
>>  	atmel_get_caps(as);
>>  
>> -	as->use_cs_gpios = true;
>> -	if (atmel_spi_is_v2(as) &&
> 
> I don't see this atmel_spi_is_v2() test in the resulting code anymore:
> did you make sure that the v1 of the peripheral is protected?
> 
>> -	    !of_get_property(pdev->dev.of_node, "cs-gpios", NULL)) {
>> -		as->use_cs_gpios = false;
>> -		master->num_chipselect = 4;
> 
> This line is pretty important: you mustn't remove it blindly!
> 
> 

Actually, few lines above master->num_chipselect is initialized with:
	master->dev.of_node = pdev->dev.of_node;
[...]
	master->num_chipselect = master->dev.of_node ? 0 : 4;


So 0 in the case of DT support, 4 otherwise.


Now looking at the source code of spi_register_master(), this function:

1 - calls of_spi_register_master(), which initializes master->num_chipselect:
	nb = of_gpio_name_count(np, "cs-gpios");
	master->num_chipselect = max_t(int, nb, master->num_chipselect);

	if (nb == 0 || nb == -ENOENT)
		return 0;

2 - check master->num_chipselect with:
	if (master->num_chipselect == 0)
		return -EINVAL;

It means that in the case of DT support, master->num_chipselect was initialized
according to the value of the "cs-gpios" DT property. Hence this property used
to be mandatory but now we want it to be optional for hardware version 2 and
later.

This is why we added a check "hw version >= 2 and cs-gpios missing". In such
a case the master->num_chipselect was initialized to 4 so spi_register_master()
does not fail with -EINVAL.

I have applied the following fix after your patch and now the driver works
again on sama5d2:

--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -1576,6 +1576,11 @@ static int atmel_spi_probe(struct platform_device *pdev)
 
        atmel_get_caps(as);
 
+       if (atmel_spi_is_v2(as) &&
+           master->dev.of_node &&
+           !of_get_property(master->dev.of_node, "cs-gpios", NULL))
+               master->num_chipselect = 4;
+
        as->use_dma = false;
        as->use_pdc = false;
        if (as->caps.has_dma_support) {

>> -	}
>> -
>>  	as->use_dma = false;
>>  	as->use_pdc = false;
>>  	if (as->caps.has_dma_support) {
>>
> 
> So, sorry but it's a NACK for me.
> 
> Bye,
> 

Best regards,

Cyrille

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] spi: atmel: improve internal vs gpio chip-select choice Mans Rullgard <mans@mansr.com> - 2016-01-08 01:20 +0100
  Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Nicolas Ferre <nicolas.ferre@atmel.com> - 2016-01-11 16:30 +0100
    Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Måns Rullgård <mans@mansr.com> - 2016-01-11 16:50 +0100
      Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Nicolas Ferre <nicolas.ferre@atmel.com> - 2016-01-12 10:00 +0100
        Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Måns Rullgård <mans@mansr.com> - 2016-01-12 10:10 +0100
        Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Måns Rullgård <mans@mansr.com> - 2016-01-13 03:10 +0100
    Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Cyrille Pitchen <cyrille.pitchen@atmel.com> - 2016-01-11 17:40 +0100
      Re: [PATCH] spi: atmel: improve internal vs gpio chip-select choice Måns Rullgård <mans@mansr.com> - 2016-01-11 17:40 +0100

csiph-web