public inbox for linux-spi@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <florian-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
To: Jonas Gorski <jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Ian Campbell
	<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
	Kumar Gala <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Subject: Re: [PATCH 2/2] spi/bcm63xx: add support for probing through devicetree
Date: Thu, 10 Sep 2015 12:19:39 -0700	[thread overview]
Message-ID: <55F1D7CB.9020804@openwrt.org> (raw)
In-Reply-To: <1441898975-22540-3-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>

On 10/09/15 08:29, Jonas Gorski wrote:
> Add required binding support to probe through device tree.
> 
> Use the compatible instead of the resource size for identifiying the
> block type, and allow reducing the number of cs lines through OF.

This looks good to me, since this builds on top of your other 6 patches,
the end-result might be different, especially if we end-up using
platform_device_id as suggested. Other than that:

Reviewed-by: Florian Fainelli <f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Thanks for doing this!

> 
> Signed-off-by: Jonas Gorski <jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
> ---
>  drivers/spi/spi-bcm63xx.c | 56 +++++++++++++++++++++++++++++++++++------------
>  1 file changed, 42 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c
> index 42f33bc..ec094b1 100644
> --- a/drivers/spi/spi-bcm63xx.c
> +++ b/drivers/spi/spi-bcm63xx.c
> @@ -26,6 +26,7 @@
>  #include <linux/completion.h>
>  #include <linux/err.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/of.h>
>  
>  /* BCM 6338/6348 SPI core */
>  #define SPI_6348_RSET_SIZE		64
> @@ -465,6 +466,12 @@ static const unsigned long bcm6358_spi_reg_offsets[] = {
>  	[SPI_MSG_DATA_SIZE]	= SPI_6358_MSG_DATA_SIZE,
>  };
>  
> +static const struct of_device_id bcm63xx_spi_of_match[] = {
> +	{ .compatible = "brcm,bcm6348-spi", .data = &bcm6348_spi_reg_offsets },
> +	{ .compatible = "brcm,bcm6358-spi", .data = &bcm6358_spi_reg_offsets },
> +	{ },
> +};
> +
>  static int bcm63xx_spi_probe(struct platform_device *pdev)
>  {
>  	struct resource *r;
> @@ -474,6 +481,7 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
>  	struct clk *clk;
>  	struct bcm63xx_spi *bs;
>  	int ret;
> +	u32 num_cs = BCM63XX_SPI_MAX_CS;
>  
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq < 0) {
> @@ -516,27 +524,46 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
>  		goto out_err;
>  	}
>  
> -	master->bus_num = BCM63XX_SPI_BUS_NUM;
> -	master->num_chipselect = BCM63XX_SPI_MAX_CS;
>  	master->transfer_one_message = bcm63xx_spi_transfer_one;
>  	master->mode_bits = MODEBITS;
>  	master->bits_per_word_mask = SPI_BPW_MASK(8);
>  	master->auto_runtime_pm = true;
>  
> -	switch (resource_size(r)) {
> -	case SPI_6348_RSET_SIZE:
> -		bs->reg_offsets = bcm6348_spi_reg_offsets;
> -		break;
> -	case SPI_6358_RSET_SIZE:
> -		bs->reg_offsets = bcm6358_spi_reg_offsets;
> -		break;
> -	default:
> -		ret = -EINVAL;
> -		dev_err(dev, "unsupported register size: %i\n",
> -			resource_size(r));
> -		goto out_err;
> +	if (dev->of_node) {
> +		const struct of_device_id *match;
> +
> +		match = of_match_node(bcm63xx_spi_of_match, dev->of_node);
> +		if (!match) {
> +			ret = -EINVAL;
> +			goto out_err;
> +		}
> +		bs->reg_offsets = match->data;
> +		master->dev.of_node = dev->of_node;
> +		of_property_read_u32(dev->of_node, "num-cs", &num_cs);
> +		if (num_cs > BCM63XX_SPI_MAX_CS) {
> +			dev_warn(dev, "unsupported number of cs (%i), reducing to 8\n",
> +				 num_cs);
> +			num_cs = BCM63XX_SPI_MAX_CS;
> +		}
> +	} else {
> +		master->bus_num = BCM63XX_SPI_BUS_NUM;
> +
> +		switch (resource_size(r)) {
> +		case SPI_6348_RSET_SIZE:
> +			bs->reg_offsets = bcm6348_spi_reg_offsets;
> +			break;
> +		case SPI_6358_RSET_SIZE:
> +			bs->reg_offsets = bcm6358_spi_reg_offsets;
> +			break;
> +		default:
> +			ret = -EINVAL;
> +			dev_err(dev, "unsupported register size: %i\n",
> +				resource_size(r));
> +			goto out_err;
> +		}
>  	}
>  
> +	master->num_chipselect = num_cs;
>  	bs->msg_type_shift = bs->reg_offsets[SPI_MSG_TYPE_SHIFT];
>  	bs->msg_ctl_width = bs->reg_offsets[SPI_MSG_CTL_WIDTH];
>  	bs->fifo_size = bs->reg_offsets[SPI_MSG_DATA_SIZE];
> @@ -621,6 +648,7 @@ static struct platform_driver bcm63xx_spi_driver = {
>  	.driver = {
>  		.name	= "bcm63xx-spi",
>  		.pm	= &bcm63xx_spi_pm_ops,
> +		.of_match_table = bcm63xx_spi_of_match,
>  	},
>  	.probe		= bcm63xx_spi_probe,
>  	.remove		= bcm63xx_spi_remove,
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2015-09-10 19:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10 15:29 [PATCH 0/2] spi/bcm63xx: add device tree support Jonas Gorski
     [not found] ` <1441898975-22540-1-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
2015-09-10 15:29   ` [PATCH 1/2] spi/bcm63xx: document device tree bindings Jonas Gorski
     [not found]     ` <1441898975-22540-2-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
2015-09-10 19:17       ` Florian Fainelli
     [not found]         ` <55F1D754.9000101-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
2015-09-11 10:28           ` Jonas Gorski
2015-09-10 15:29   ` [PATCH 2/2] spi/bcm63xx: add support for probing through devicetree Jonas Gorski
     [not found]     ` <1441898975-22540-3-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
2015-09-10 19:19       ` Florian Fainelli [this message]

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=55F1D7CB.9020804@openwrt.org \
    --to=florian-p3rkhjxn3npafugrpc6u6w@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
    --cc=jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /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