linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: Ernst Schwab <eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
Cc: David Brownell
	<dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	yi.li-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 2/2] spi/mmc_spi: mmc_spi adaptations for SPI bus locking API
Date: Wed, 17 Feb 2010 13:07:35 -0700	[thread overview]
Message-ID: <fa686aa41002171207x237da42dsb513cf5c8e0478b0@mail.gmail.com> (raw)
In-Reply-To: <20100217191900.a57d0a60.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>

On Wed, Feb 17, 2010 at 11:19 AM, Ernst Schwab <eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org> wrote:
> From: Ernst Schwab <eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
>
> Modification of the mmc_spi driver to use the SPI bus locking API.
> With this, the mmc_spi driver can be used together with other SPI
> devices on the same SPI bus. The exclusive access to the SPI bus is
> now managed in the SPI layer. The counting of chip selects in the probe
> function is no longer needed.
>
> Signed-off-by: Ernst Schwab <eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>

Looks good to me.

g.

> ---
> diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
> --- a/drivers/mmc/host/mmc_spi.c
> +++ b/drivers/mmc/host/mmc_spi.c
> @@ -181,7 +181,7 @@ mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
>                                host->data_dma, sizeof(*host->data),
>                                DMA_FROM_DEVICE);
>
> -       status = spi_sync(host->spi, &host->readback);
> +       status = spi_sync_locked(host->spi, &host->readback);
>
>        if (host->dma_dev)
>                dma_sync_single_for_cpu(host->dma_dev,
> @@ -540,7 +540,7 @@ mmc_spi_command_send(struct mmc_spi_host *host,
>                                host->data_dma, sizeof(*host->data),
>                                DMA_BIDIRECTIONAL);
>        }
> -       status = spi_sync(host->spi, &host->m);
> +       status = spi_sync_locked(host->spi, &host->m);
>
>        if (host->dma_dev)
>                dma_sync_single_for_cpu(host->dma_dev,
> @@ -684,7 +684,7 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t,
>                                host->data_dma, sizeof(*scratch),
>                                DMA_BIDIRECTIONAL);
>
> -       status = spi_sync(spi, &host->m);
> +       status = spi_sync_locked(spi, &host->m);
>
>        if (status != 0) {
>                dev_dbg(&spi->dev, "write error (%d)\n", status);
> @@ -821,7 +821,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t,
>                                DMA_FROM_DEVICE);
>        }
>
> -       status = spi_sync(spi, &host->m);
> +       status = spi_sync_locked(spi, &host->m);
>
>        if (host->dma_dev) {
>                dma_sync_single_for_cpu(host->dma_dev,
> @@ -1017,7 +1017,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
>                                        host->data_dma, sizeof(*scratch),
>                                        DMA_BIDIRECTIONAL);
>
> -               tmp = spi_sync(spi, &host->m);
> +               tmp = spi_sync_locked(spi, &host->m);
>
>                if (host->dma_dev)
>                        dma_sync_single_for_cpu(host->dma_dev,
> @@ -1083,6 +1083,9 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
>        }
>  #endif
>
> +       /* request exclusive bus access */
> +       spi_bus_lock(host->spi);
> +
>        /* issue command; then optionally data and stop */
>        status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
>        if (status == 0 && mrq->data) {
> @@ -1093,6 +1096,9 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
>                        mmc_cs_off(host);
>        }
>
> +       /* release the bus */
> +       spi_bus_unlock(host->spi);
> +
>        mmc_request_done(host->mmc, mrq);
>  }
>
> @@ -1289,23 +1295,6 @@ mmc_spi_detect_irq(int irq, void *mmc)
>        return IRQ_HANDLED;
>  }
>
> -struct count_children {
> -       unsigned        n;
> -       struct bus_type *bus;
> -};
> -
> -static int maybe_count_child(struct device *dev, void *c)
> -{
> -       struct count_children *ccp = c;
> -
> -       if (dev->bus == ccp->bus) {
> -               if (ccp->n)
> -                       return -EBUSY;
> -               ccp->n++;
> -       }
> -       return 0;
> -}
> -
>  static int mmc_spi_probe(struct spi_device *spi)
>  {
>        void                    *ones;
> @@ -1337,32 +1326,6 @@ static int mmc_spi_probe(struct spi_device *spi)
>                return status;
>        }
>
> -       /* We can use the bus safely iff nobody else will interfere with us.
> -        * Most commands consist of one SPI message to issue a command, then
> -        * several more to collect its response, then possibly more for data
> -        * transfer.  Clocking access to other devices during that period will
> -        * corrupt the command execution.
> -        *
> -        * Until we have software primitives which guarantee non-interference,
> -        * we'll aim for a hardware-level guarantee.
> -        *
> -        * REVISIT we can't guarantee another device won't be added later...
> -        */
> -       if (spi->master->num_chipselect > 1) {
> -               struct count_children cc;
> -
> -               cc.n = 0;
> -               cc.bus = spi->dev.bus;
> -               status = device_for_each_child(spi->dev.parent, &cc,
> -                               maybe_count_child);
> -               if (status < 0) {
> -                       dev_err(&spi->dev, "can't share SPI bus\n");
> -                       return status;
> -               }
> -
> -               dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
> -       }
> -
>        /* We need a supply of ones to transmit.  This is the only time
>         * the CPU touches these, so cache coherency isn't a concern.
>         *
>
>
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev

      parent reply	other threads:[~2010-02-17 20:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-17 18:15 [PATCH 0/2] spi/mmc_spi: SPI bus locking API and mmc_spi adaptations Ernst Schwab
     [not found] ` <20100217191513.52392dd6.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
2010-02-17 18:17   ` [PATCH 1/2] spi/mmc_spi: SPI bus locking API, using mutex Ernst Schwab
     [not found]     ` <20100217191709.2fd1028c.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
2010-02-17 19:03       ` Mike Frysinger
     [not found]         ` <8bd0f97a1002171103g3e08ee02pf761866f3c57f391-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17 20:06           ` Grant Likely
     [not found]             ` <fa686aa41002171206o6cbb7477r7f427ef7be0e8450-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17 20:19               ` Mike Frysinger
     [not found]                 ` <8bd0f97a1002171219y78c67661o4e1b03c92e2793d0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17 21:07                   ` Grant Likely
     [not found]                     ` <fa686aa41002171307p694a737ax426dcf26fb547280-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17 21:41                       ` Mike Frysinger
     [not found]                         ` <8bd0f97a1002171341ja37d5c7nb0040ec5058e95fb-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-24 20:39                           ` Grant Likely
2010-02-17 20:03       ` Grant Likely
2010-02-17 18:19   ` [PATCH 2/2] spi/mmc_spi: mmc_spi adaptations for SPI bus locking API Ernst Schwab
     [not found]     ` <20100217191900.a57d0a60.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
2010-02-17 20:07       ` Grant Likely [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=fa686aa41002171207x237da42dsb513cf5c8e0478b0@mail.gmail.com \
    --to=grant.likely-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
    --cc=dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org \
    --cc=yi.li-OyLXuOCK7orQT0dZR+AlfA@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;
as well as URLs for NNTP newsgroup(s).