linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] spi/mmc_spi: SPI bus locking to use mmc_spi together with other SPI devices
@ 2010-02-16 19:44 Ernst Schwab
       [not found] ` <20100216204450.e043eed8.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
  0 siblings, 1 reply; 19+ messages in thread
From: Ernst Schwab @ 2010-02-16 19:44 UTC (permalink / raw)
  To: Grant Likely, Kumar Gala, David Brownell
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	yi.li-OyLXuOCK7orQT0dZR+AlfA, vapier-aBrp7R+bbdUdnm+yROfE0A

Abstract 
--------
* SPI bus locking required for mmc_spi driver sharing
  the bus with other SPI devices.
* Proposal for API functions for SPI bus locking:
  In addition to spi_lock_bus/spi_unlock_bus, there
  will be spi_register_lock_bus/spi_unregister_lock_bus.
* Patches for spi_mpc8xxx.c for SPI bus locking.

The problem
-----------
The mmc_spi driver requires an exclusive access to the
SPI bus that must not be interrupted by accessing any 
other SPI device on the same bus. 

The current situation
---------------------
In the current kernel, the mmc_spi driver is operable
only when no other SPI clients use the same bus. At 
initialization time, it checks if it is the only SPI 
client, and refuses to install itself with a 
"can't share SPI bus" message otherwise.
If it is the only SPI client, it tells its wishes 
with an "ASSUMING SPI bus stays unshared" message; 
future SPI client registrations will not be prohibited.

Previous attempts to solve the problem
--------------------------------------
There was a set of patches by Yi Li/Bryan Wu/Mike Frysinger 
to introduce two API functions spi_lock_bus() and 
spi_unlock_bus() to enable cooperative sharing of the
SPI bus between the mmc_spi driver and other SPI drivers. 
It requires code extension in the SPI master driver to 
handle the exclusive bus access, which was implemented in
the ucLinux Blackfin SPI driver spi_bfin5xx.c.
The extended SPI master driver transmits only SPI messages
for the SPI device that locked the bus, messages for all
other SPI devices remain queued until the bus is unlocked.
The code is available in the current uClinux Blackfin tree.

Proposal for a solution
-----------------------
In addition to the previously proposed spi_lock_bus() 
and spi_unlock_bus() functions, two functions 
spi_register_lock_bus() and spi_unregister_lock_bus() 
can be implemented that can be used by a driver 
that wants to call spi_lock_bus() and spi_unlock_bus. 

A transition from the existing situation 
to a convenient solution could be:

* Insertion of spi_(un)register_lock_bus 
  and spi_(un)lock_bus calls into mmc_spi.c
* Implementation of spi_register_(un)lock_bus() 
  in spi.c.
* Implementation of spi_(un)lock_bus() in spi.c.
* Integration of the changes to spi_bfin5xx.c 
  (uClinux Blackfin tree) and to the PowerQuicc 
  spi_mpc8xxx.c driver (new patch) implementing 
  the (un)lock_bus handlers.

Implementation of the API functions
-----------------------------------
int spi_register_lock_bus()
{
    // The implementation of spi_register_lock_bus()
    // allows bus locking only for one SPI driver,
    // i.e. the mmc_spi driver.
    if (bus locking rights already 
        granted to another caller) {
        return FAILURE;
    } 
    
    if (SPI master capable of bus locking) {
        return SUCCESS;
    } 

    if (caller is the only SPI device) {
        let future spi_add_device calls fail;
        return SUCCESS;
    } 
    

    return FAILURE;
}

void spi_lock_bus()
{
    // The implementation of spi_lock_bus has no need 
    // to sleep, and it cannot fail because nobody but
    // the caller itself (mmc_spi) can hold the lock.
  
    if (SPI master capable of bus locking) {
        call SPI master lock_bus();
    }
}

Possible future extensions
--------------------------
As soon as there will be a requirement for more than
one driver obtaining an SPI bus lock, the 
spi_(un)lock_bus() functions can be extended to 
put the caller to sleep until the bus lock 
becomes available. 
The spi_register_bus_lock() function then can allow
more than one driver to register for bus locking.
The mmc_spi driver and the already modified SPI
master drivers do not need to be reworked again.

Patches
-------
The successive mails will contain these patches:
1 - spi_lock_bus (previously released patch)
2 - spi_register_lock_bus
3 - added spi_lock_bus to mmc_spi (previously released patch)
4 - added spi_register_lock_bus to mmc_spi
5 - SPI bus locking for spi_mpc8xxx.c

------------------------------------------------------------------------------
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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-02-17 14:12 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-16 19:44 [PATCH 0/5] spi/mmc_spi: SPI bus locking to use mmc_spi together with other SPI devices Ernst Schwab
     [not found] ` <20100216204450.e043eed8.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
2010-02-16 19:57   ` [PATCH 1/5] spi: spi_lock_bus and spi_unlock_bus Ernst Schwab
     [not found]     ` <20100216205720.ebe949a1.eschwab-BGeptl67XyCzQB+pC5nmwQ@public.gmane.org>
2010-02-16 20:43       ` Grant Likely
     [not found]         ` <fa686aa41002161243y6e24e439yff54a28cbe295de3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-16 21:16           ` Ned Forrester
     [not found]             ` <4B7B0B1C.8050407-/d+BM93fTQY@public.gmane.org>
2010-02-16 23:23               ` Grant Likely
2010-02-17  0:07           ` Mike Frysinger
2010-02-17  0:21             ` Ernst Schwab
2010-02-17  0:40               ` Mike Frysinger
     [not found]             ` <8bd0f97a1002161607m3c748ccegaffb83c42667287a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17  3:48               ` Grant Likely
     [not found]                 ` <fa686aa41002161948o31a48fc9kac263b0ac34f1a8d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17  4:34                   ` Mike Frysinger
     [not found]                     ` <8bd0f97a1002162034r2d3e397eq12ae0f0df1ae2adb-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17  4:47                       ` Grant Likely
     [not found]                         ` <fa686aa41002162047h4b4c9cdam2133baf3b7d0e27c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17  5:04                           ` Mike Frysinger
     [not found]                             ` <8bd0f97a1002162104u5291da69gbff20837f78c9cdf-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17  5:08                               ` Grant Likely
2010-02-17  4:37               ` Grant Likely
2010-02-17  0:16         ` Ernst Schwab
2010-02-17  4:32           ` Grant Likely
2010-02-17  7:35             ` Ernst Schwab
2010-02-17 13:30               ` Grant Likely
     [not found]                 ` <fa686aa41002170530i2ae007c2ia4f2ad185dfd2713-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-17 14:12                   ` Grant Likely

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).