mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@avionic-design.de>
To: Alexandre Pereira da Silva <aletes.xgr@gmail.com>
Cc: Roland Stigge <stigge@antcom.de>,
	linux-doc@vger.kernel.org, devicetree-discuss@lists.ozlabs.org,
	linux-kernel@vger.kernel.org,
	Rob Herring <rob.herring@calxeda.com>,
	Rob Landley <rob@landley.net>,
	spi-devel-general@lists.sourceforge.net
Subject: Re: [PATCH v3] spi/pl022: add devicetree support
Date: Sun, 1 Jul 2012 10:39:24 +0200	[thread overview]
Message-ID: <20120701083923.GA29380@avionic-0098.mockup.avionic-design.de> (raw)
In-Reply-To: <1340719537-627-1-git-send-email-aletes.xgr@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3645 bytes --]

On Tue, Jun 26, 2012 at 11:05:36AM -0300, Alexandre Pereira da Silva wrote:
> Add the chipselect array and cur_cs properties to pl022 main structure
> 
> Add a wrapper function to decide if the cs should be controlled by the
> cs_control callback or the chipselect gpio
> 
> Populate chipselect property from cs-gpios
> 
> Populate master->dev.of_node, so the spi bus can find child spi
> devices and register them
> 
> At pl022 setup, fill chip_data structure from dt nodes, if not provided
> by platform.
> 
> Signed-off-by: Alexandre Pereira da Silva <aletes.xgr@gmail.com>
> Tested-by: Roland Stigge <stigge@antcom.de>
> ---
> Applies to v3.5-rc4
> 
> Changes since v2:
> * Use IS_ENABLED instead of #ifdef
> * Remove bogus const change
> 
> Changes since v1:
> * return EPROBE_DEFFER if gpios are not initialized yet
> 
> Thanks Thierry Reding for reviewing and improvements suggestions
> 
>  .../devicetree/bindings/spi/spi_pl022.txt          |   15 +++
>  drivers/spi/spi-pl022.c                            |  115 ++++++++++++++++----
>  2 files changed, 111 insertions(+), 19 deletions(-)
> 
[...]
> diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
[...]
> @@ -1998,8 +2039,14 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
>  		goto err_no_pdata;
>  	}
>  
> +	num_cs = platform_info->num_chipselect;
> +#if IS_ENABLED(CONFIG_OF)
> +	of_property_read_u32(np, "pl022,num-chipselects", &num_cs);
> +#endif
> +

Actually this has even more advantages if you use it as a condition in
an if expression:

	if (IS_ENABLED(CONFIG_OF))
		of_property_read_u32(...);

The above will be compiled wether CONFIG_OF is enabled or not, but it
will not be included in the final output because of the compiler's DCE
(dead code elimination) seeing this as "if (0)". The result is that the
source code gets much better compile coverage and errors in the
conditional code can be caught earlier.

> @@ -2017,13 +2064,40 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
>  	 * on this board
>  	 */
>  	master->bus_num = platform_info->bus_id;
> -	master->num_chipselect = platform_info->num_chipselect;
> +	master->num_chipselect = num_cs;
>  	master->cleanup = pl022_cleanup;
>  	master->setup = pl022_setup;
>  	master->prepare_transfer_hardware = pl022_prepare_transfer_hardware;
>  	master->transfer_one_message = pl022_transfer_one_message;
>  	master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware;
>  	master->rt = platform_info->rt;
> +	master->dev.of_node = dev->of_node;
> +
> +#if IS_ENABLED(CONFIG_OF)
> +	for (i = 0; i < num_cs; i++) {
> +		int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
> +
> +		if (cs_gpio == -EPROBE_DEFER) {
> +			status = -EPROBE_DEFER;
> +			goto err_no_gpio;
> +		}
> +
> +		pl022->chipselect[i] = cs_gpio;
> +
> +		if (gpio_is_valid(cs_gpio)) {
> +			if (gpio_request(cs_gpio, "ssp-pl022"))
> +				dev_err(&adev->dev,
> +					"could not request %d gpio\n", cs_gpio);
> +			else if (gpio_direction_output(cs_gpio, 1))
> +				dev_err(&adev->dev,
> +					"could set gpio %d as output\n",
> +					cs_gpio);
> +		}
> +	}
> +#else
> +	for (i = 0; i < num_cs; i++)
> +		pl022->chipselect[i] = -EINVAL;
> +#endif

Same here.

>  	/*
>  	 * Supports mode 0-3, loopback, and active low CS. Transfers are
> @@ -2130,6 +2204,9 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
>   err_no_ioremap:
>  	amba_release_regions(adev);
>   err_no_ioregion:
> + #if IS_ENABLED(CONFIG_OF)
> + err_no_gpio:
> + #endif

And here.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2012-07-01  8:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-26 14:05 Alexandre Pereira da Silva
2012-07-01  8:39 ` Thierry Reding [this message]
2012-07-02 10:32   ` Alexandre Pereira da Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120701083923.GA29380@avionic-0098.mockup.avionic-design.de \
    --to=thierry.reding@avionic-design.de \
    --cc=aletes.xgr@gmail.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=spi-devel-general@lists.sourceforge.net \
    --cc=stigge@antcom.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome