From: Wolfram Sang <w.sang@pengutronix.de>
To: Luotao Fu <l.fu@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>,
spi-devel-general@lists.sourceforge.net,
David Brownell <dbrownell@users.sourceforge.net>,
linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org
Subject: Re: [spi-devel-general] [PATCH 3/3] mpc52xx_spi: add gpio chipselect
Date: Wed, 11 Nov 2009 11:50:38 +0100 [thread overview]
Message-ID: <20091111105038.GC4234@pengutronix.de> (raw)
In-Reply-To: <1257844329-20687-4-git-send-email-l.fu@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 5363 bytes --]
On Tue, Nov 10, 2009 at 10:12:09AM +0100, Luotao Fu wrote:
> This one enables the mpc52xx_spi driver for usage of user defined gpio lines
> as chipselect. This way we can control some more spi devices than only one
>
> Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
> ---
> drivers/spi/mpc52xx_spi.c | 57 +++++++++++++++++++++++++++++++++++++++++---
> 1 files changed, 53 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
> index 79ba678..58c2ce5 100644
> --- a/drivers/spi/mpc52xx_spi.c
> +++ b/drivers/spi/mpc52xx_spi.c
> @@ -21,6 +21,7 @@
> #include <linux/spi/mpc52xx_spi.h>
> #include <linux/of_spi.h>
> #include <linux/io.h>
> +#include <linux/of_gpio.h>
> #include <asm/time.h>
> #include <asm/mpc52xx.h>
>
> @@ -79,7 +80,6 @@ struct mpc52xx_spi {
> spinlock_t lock;
> struct work_struct work;
>
> -
> /* Details of current transfer (length, and buffer pointers) */
> struct spi_message *message; /* current message */
> struct spi_transfer *transfer; /* current transfer */
> @@ -89,6 +89,8 @@ struct mpc52xx_spi {
> u8 *rx_buf;
> const u8 *tx_buf;
> int cs_change;
> + int gpio_cs_count;
> + unsigned int *gpio_cs;
> };
>
> /*
> @@ -96,7 +98,13 @@ struct mpc52xx_spi {
> */
> static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
> {
> - out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
> + int cs;
> +
> + if (ms->gpio_cs_count > 0) {
> + cs = ms->message->spi->chip_select;
> + gpio_direction_output(ms->gpio_cs[cs], value);
Use gpio_set_value() in combination with...
> + } else
> + out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
> }
>
> /*
> @@ -390,8 +398,9 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
> struct spi_master *master;
> struct mpc52xx_spi *ms;
> void __iomem *regs;
> - int rc;
> int ctrl1;
> + int rc, i = 0;
> + int gpio_cs;
>
> /* MMIO registers */
> dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
> @@ -426,8 +435,8 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
> rc = -ENOMEM;
> goto err_alloc;
> }
> +
> master->bus_num = -1;
> - master->num_chipselect = 1;
> master->setup = mpc52xx_spi_setup;
> master->transfer = mpc52xx_spi_transfer;
> master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
> @@ -441,6 +450,39 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
> ms->irq1 = irq_of_parse_and_map(op->node, 1);
> ms->state = mpc52xx_spi_fsmstate_idle;
> ms->ipb_freq = mpc5xxx_get_bus_frequency(op->node);
> + ms->gpio_cs_count = of_gpio_count(op->node);
> + if (ms->gpio_cs_count > 0) {
> + master->num_chipselect = ms->gpio_cs_count;
> + ms->gpio_cs = kmalloc(ms->gpio_cs_count * sizeof(unsigned int),
> + GFP_KERNEL);
> + if (!ms->gpio_cs) {
> + rc = -ENOMEM;
> + goto err_alloc;
> + }
> +
> + for (i = 0; i < ms->gpio_cs_count; i++) {
> + gpio_cs = of_get_gpio(op->node, i);
... with of_get_gpio_flags() to avoid initialisation jitter?
> + if (gpio_cs < 0) {
> + dev_err(&op->dev,
> + "could not parse the gpio field "
> + "in oftree\n");
> + rc = -ENODEV;
> + goto err_alloc;
That should go to err_gpio and unregister the previous allocated ones.
> + }
> +
> + ms->gpio_cs[i] = gpio_cs;
> + rc = gpio_request(ms->gpio_cs[i], dev_name(&op->dev));
> + if (rc) {
> + dev_err(&op->dev,
> + "can't request spi cs gpio #%d "
> + "on gpio line %d\n",
> + i, gpio_cs);
Last two lines could become one.
> + goto err_gpio;
> + }
> + }
> + } else
> + master->num_chipselect = 1;
> +
> spin_lock_init(&ms->lock);
> INIT_LIST_HEAD(&ms->queue);
> INIT_WORK(&ms->work, mpc52xx_spi_wq);
> @@ -477,6 +519,9 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
> err_register:
> dev_err(&ms->master->dev, "initialization failed\n");
> spi_master_put(master);
> + err_gpio:
> + while (i-- > 0)
> + gpio_free(ms->gpio_cs[i]);
> err_alloc:
> err_init:
> iounmap(regs);
> @@ -487,10 +532,14 @@ static int __devexit mpc52xx_spi_remove(struct of_device *op)
> {
> struct spi_master *master = dev_get_drvdata(&op->dev);
> struct mpc52xx_spi *ms = spi_master_get_devdata(master);
> + int i;
>
> free_irq(ms->irq0, ms);
> free_irq(ms->irq1, ms);
>
> + for (i = 0; i < ms->gpio_cs_count; i++)
> + gpio_free(ms->gpio_cs[i]);
> +
> spi_unregister_master(master);
> spi_master_put(master);
> iounmap(ms->regs);
> --
> 1.6.5.2
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> spi-devel-general mailing list
> spi-devel-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/spi-devel-general
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2009-11-11 10:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 9:12 Patches for mpc52xx_spi Luotao Fu
[not found] ` <1257844329-20687-1-git-send-email-l.fu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-10 9:12 ` [PATCH 1/3] mpc52xx_spi: fix clearing status register Luotao Fu
2009-11-10 9:12 ` [PATCH 2/3] mpc52xx_spi: add missing mode_bits definition Luotao Fu
[not found] ` <1257844329-20687-3-git-send-email-l.fu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-10 9:12 ` [PATCH 3/3] mpc52xx_spi: add gpio chipselect Luotao Fu
2009-11-11 10:50 ` Wolfram Sang [this message]
2009-11-11 10:38 ` [PATCH 2/3] mpc52xx_spi: add missing mode_bits definition Wolfram Sang
2009-11-11 9:48 ` [PATCH 1/3] mpc52xx_spi: fix clearing status register Wolfram Sang
2009-11-13 10:41 ` [V2] Patches for mpc52xx_spi Luotao Fu
[not found] ` <1258108877-25435-1-git-send-email-l.fu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-13 10:41 ` [PATCH 1/3] [V2] mpc52xx_spi: fix clearing status register Luotao Fu
2009-11-13 10:41 ` [PATCH 2/3] [V2] mpc52xx_spi: add missing mode_bits definition Luotao Fu
[not found] ` <1258108877-25435-3-git-send-email-l.fu-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-13 10:41 ` [PATCH 3/3] [V2] mpc52xx_spi: add gpio chipselect Luotao Fu
2009-11-13 11:10 ` Wolfram Sang
2009-11-13 18:22 ` Grant Likely
2009-11-13 18:53 ` [V2] Patches for mpc52xx_spi Grant Likely
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=20091111105038.GC4234@pengutronix.de \
--to=w.sang@pengutronix.de \
--cc=dbrownell@users.sourceforge.net \
--cc=grant.likely@secretlab.ca \
--cc=l.fu@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=spi-devel-general@lists.sourceforge.net \
/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;
as well as URLs for NNTP newsgroup(s).