All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Maxime Ripard
	<maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Alexandre Belloni
	<alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] spi: Force the registration of the spidev devices
Date: Tue, 29 Apr 2014 23:31:49 +0200	[thread overview]
Message-ID: <24BF05CB-35FF-42E8-BE5C-A5E4E3D0C52A@martin.sperl.org> (raw)
In-Reply-To: <20140429183758.GH15125-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>

On 29.04.2014, at 20:37, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:

> On Mon, Apr 28, 2014 at 10:22:54AM -0700, Maxime Ripard wrote:
> 
>> spidev device registration has always been a controversial subject since the
>> move to DT.
> 
> Why can we not handle this by using sysfs to bind spidev to the device?



I think the question is actually more generic than just "spidev" related.

A solution should also help all those users of development boards like 
raspberry pi, beagle board,... where people want to add spi devices without
having to know too much about the fine details of the kernel configuration
/kernel compiling/creating a new device tree or similar.... 
They just want their device to work with the existing kernel 
with minimal effort!

For just this purpose I got an out of tree module called spi-config that 
- as of now - allows to define the binding of spi devices (not solely 
focused on spidev) as per module argument while loading the driver.

This could easily get extended to work also via sysfs.

The problem here is mostly around the "passing" of driver specific platform 
data, which this module currently handles in a sort of "binary blob" way, 
which is suboptimal (as it is very architecture specific),
but at least it works...

Some examples of what is there:

Bind spidev to spi0.1 with a speed of 2MHz and SPI mode 3:
modprobe spi-config bus=0:cs=1:modalias=spidev:speed=2000000:mode=3

Bind an mcp2515 CAN-bus controller to spi0.0 with 10MHz speed and 
IRQ triggered via GPIO25:
modprobe spi-config bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:\
mode=0:pd=20:pdu32-0=16000000:pdu32-4=0x2002

The extra "pd...=" args are the ones describing platform data that is needed
by the mcp251x driver to set up the device correctly. 
In the above example we define:
* pd=20: the platform data size is 20 bytes (zero filled)
* pdu32-0: a u32 at offset 0 with a value of 16MHz Quarz speed
* pdu32-4: a u32 at offset 4 the interrupt flags used by the driver
           (=IRQF_TRIGGER_FALLING|IRQF_ONESHOT)

The above mcp2515 device now configured via sysfs could look like this:
echo "cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:mode=0:\
pd=20:pdu32-0=16000000:pdu32-4=0x2002" > /sys/class/spi_master/spi0/register

Unregistering the device:
echo "cs=0" > /sys/class/spi_master/spi0/unregister

As said: the trickiest part is "platform data", all the "spi-parameters"
are well-defined and are easily parseable.

Options that come to my mind to increase "readability" are:
* "const char *extra_parameters" 
  in spi_device containing all "unhandled" parameters left for the driver
  to parse during probing.
* "int (*config)(struct spi_device *,const char *key,const char *value)"
  in spi_driver that sets the corresponding parameters
  (creating platform data if it is not already set/allocated) 
  and which is called prior to calling spi_driver->probe(spi)

So with those "readability" options the sysfs interface could 
look like this:
echo "cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:mode=0:\
can_oscillator_hz=16000000:interrupt_flags=0x2002" \
> /sys/class/spi_master/spi0/register

When using the second option the framework could fall back to the
voodoo-"pd...=" approach that I have show above to avoid having to touch 
all spi drivers immediately to make use of this interface.

The biggest pitfall I see is that if a device driver expects platform
data but none is provided, then loading the driver could crash the kernel.
But that is something that probably should get fixed in the driver 
itself and not in the framework.

A totally different approach could be the use of device-tree overlays, 
which is also not included in the kernel, but would allow for similar
config schemes.
But that would leave systems not using device tree without this option.

So it seems as if we need to find an approach that is acceptable...

Ciao,
	Martin

--
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:[~2014-04-29 21:31 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-28 17:22 [PATCH] spi: Force the registration of the spidev devices Maxime Ripard
2014-04-28 17:22 ` Maxime Ripard
2014-04-29 18:37 ` Mark Brown
2014-04-29 18:37   ` Mark Brown
     [not found]   ` <20140429183758.GH15125-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-04-29 21:31     ` Martin Sperl [this message]
     [not found]       ` <24BF05CB-35FF-42E8-BE5C-A5E4E3D0C52A-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2014-04-30 18:14         ` Maxime Ripard
2014-04-30 20:00           ` Martin Sperl
     [not found]             ` <DA3907EB-0C1B-42FB-B288-9E33F6E24E3E-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2014-04-30 22:19               ` Maxime Ripard
2014-05-01  1:21               ` Mark Brown
2014-04-30 18:06   ` Maxime Ripard
2014-04-30 18:06     ` Maxime Ripard
2014-05-01  1:18     ` Mark Brown
2014-05-01  1:18       ` Mark Brown
2014-05-01 22:36       ` Maxime Ripard
2014-05-01 22:36         ` Maxime Ripard
2014-05-01 23:28         ` Geert Uytterhoeven
2014-05-02 16:55           ` Mark Brown
2014-05-02 16:55             ` Mark Brown
2014-05-05  4:17           ` Maxime Ripard
2014-05-05  7:10             ` Geert Uytterhoeven
2014-05-05 13:57               ` Alexandre Belloni
2014-05-05 13:57                 ` Alexandre Belloni
2014-05-05 14:22                 ` Geert Uytterhoeven
2014-05-05 14:22                   ` Geert Uytterhoeven
2014-05-05 19:16               ` Mark Brown
2014-05-02 17:40         ` Mark Brown
2014-05-02 17:40           ` Mark Brown
2014-05-05  4:21           ` Maxime Ripard
2014-05-05 19:17             ` Mark Brown
2014-05-05 19:17               ` Mark Brown
2014-05-08  2:22               ` Maxime Ripard
2014-05-08  2:22                 ` Maxime Ripard
2015-05-12 20:33 Maxime Ripard
2015-05-12 20:33 ` Maxime Ripard
2015-05-13 11:26 ` Mark Brown
2015-05-13 11:26   ` Mark Brown
2015-05-13 12:35   ` Michal Suchanek
2015-05-13 12:35     ` Michal Suchanek
2015-05-13 12:51   ` Maxime Ripard
2015-05-13 12:51     ` Maxime Ripard
2015-05-13 14:36     ` Mark Brown
2015-05-13 14:36       ` Mark Brown
2015-05-13 15:31       ` Michal Suchanek
2015-05-13 15:31         ` Michal Suchanek
2015-05-13 17:43         ` Mark Brown
2015-05-13 17:43           ` Mark Brown
2015-05-13 19:09       ` Maxime Ripard
2015-05-13 19:10     ` Geert Uytterhoeven
2015-05-13 19:10       ` Geert Uytterhoeven
2015-05-13 19:41       ` Maxime Ripard
2015-05-13 19:41         ` Maxime Ripard
2015-05-13 15:37   ` Greg Kroah-Hartman
2015-05-13 15:37     ` Greg Kroah-Hartman
2015-05-13 15:52     ` Michal Suchanek
2015-05-13 15:52       ` Michal Suchanek
2015-05-13 17:13     ` Mark Brown
2015-05-13 17:13       ` Mark Brown
2015-05-13 17:20       ` Greg Kroah-Hartman
2015-05-13 17:20         ` Greg Kroah-Hartman
2015-05-13 17:39         ` Mark Brown
2015-05-13 17:39           ` Mark Brown
2015-05-13 18:16           ` Greg Kroah-Hartman
2015-05-13 18:16             ` Greg Kroah-Hartman
2015-05-13 18:32             ` Mark Brown
2015-05-13 18:36               ` Greg Kroah-Hartman
2015-05-13 18:36                 ` Greg Kroah-Hartman
2015-05-13 18:51                 ` Mark Brown
2015-05-13 18:51                   ` Mark Brown
2015-05-13 19:17                   ` Maxime Ripard
2015-05-13 19:17                     ` Maxime Ripard
2015-05-13 17:50     ` Maxime Ripard
2015-05-13 17:50       ` Maxime Ripard
2015-05-13 18:12       ` Mark Brown
2015-05-13 18:17       ` Greg Kroah-Hartman
2015-05-13 18:17         ` Greg Kroah-Hartman
2015-05-13 19:23         ` Geert Uytterhoeven
2015-05-13 19:23           ` Geert Uytterhoeven
2015-05-13 19:26         ` Maxime Ripard
2015-05-13 19:26           ` Maxime Ripard
2015-05-13 22:33           ` Greg Kroah-Hartman
2015-05-13 22:33             ` Greg Kroah-Hartman
2015-05-14 14:34             ` Mark Brown
2015-05-14 14:34               ` Mark Brown
2015-05-15  8:09             ` Maxime Ripard
2015-07-15  6:27             ` Lucas De Marchi
2015-07-15  6:27               ` Lucas De Marchi

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=24BF05CB-35FF-42E8-BE5C-A5E4E3D0C52A@martin.sperl.org \
    --to=kernel-tqfnsx0mhmxhksadf0wuew@public.gmane.org \
    --cc=alexandre.belloni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.