All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
To: "kyle.roeschley-acOepvfBmUk@public.gmane.org"
	<kyle.roeschley-acOepvfBmUk@public.gmane.org>,
	"geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org"
	<geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
Cc: "linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org"
	<broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: Re: spidev: Instantiating from DT as "spidev"
Date: Wed, 29 Nov 2017 20:22:25 +0000	[thread overview]
Message-ID: <1511986944.9792.36.camel@impinj.com> (raw)
In-Reply-To: <CAMuHMdUps9Ti=CRZM7UxrHLD8GA+FKD+_RFLW3H9wUpSRTYs8w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Wed, 2017-11-29 at 17:32 +0100, Geert Uytterhoeven wrote:
> On Wed, Nov 29, 2017 at 4:04 PM, Kyle Roeschley <kyle.roeschley@ni.com> wrote:
> > Since commit 956b200a846e ("spi: spidev: Warn loudly if instantiated from DT as
> > "spidev""), listing "spidev" directly in a device tree is not recommended.
> > Instead, what I see in the (many) past discussions is that I should change my
> > device tree to describe the actual hardware and add whatever new ID I create to
> > spidev_dt_ids. That seems perfectly reasonable.
> > 
> > 
> > Is there a "correct" solution to this problem? Both the Raspberry Pi [2] and
> > Beaglebone [3] kernels have just added "spidev" back to the match table, but I
> > would rather not carry a patch around just for some printk spam.
> 
> Implement something in sysfs like "new_device" for i2c, or "slave" for SPI.
> Then people can add a new device (e.g. "spidev") by writing to that
> virtual file.

I had a product that used a number of devices controlled via spidev,
and patching the kernel to add them to the spidev_dt_ids list is,
IMNSHO, a crap solution.  So I came up with something different.

Some other Linux bus subsystems, like PCI and platform, have a
"driver_override" sysfs attribute for each device.  Writing the name of
a driver to this attribute will bind the device to the named driver, 
even if the driver does not explicitly list the device in the bind
table.  This can be used to bind spidev to a device, without adding the
device type to a dt id list in spidev nor giving the device a type of
"spidev" rather than the real type.

So I added driver_override to to the spi bus.  There are some other
uses too, as platform and pci have the attribute and there is no spidev
driver for those buses.  For instance, you can bind spidev to a device
with a real kernel driver to debug something, at runtime, without
needing to modify device tree entries or patch the kernel.

Rather than manual write to driver_override files, one can use udev
rules to do it automatically.  Example:

SUBSYSTEM=="spi", ENV{MODALIAS}=="spi:adrf6820", ATTR{driver_override}+="spidev"

One can now use a "proper" compatible entry in the device tree,
compatible = "adi,adrf6820".

Creating new spi device is, IMHO, a separate problem from binding a spi
device to spidev.  One could try to solve that with the "new_device"
system used in i2c.  However, i2c added that over eight years ago when
device tree support was a lot less common and device tree fragments
didn't exist.  Now that we have dynamic dt fragment loading, maybe that
is a better system?

One can create a dt fragment that adds a new spi device, and this gives
you the ability to add all the properties the device might need (spi
mode, speed, device specific parameters, etc.).  It could bind to an 
normal spi-slave kernel driver or to spidev.

If adding a dt fragment is "too hard", just wrap it in a script.  It
should be trivial to write a script that takes a spi bus and chip
select and produces a generic dt fragment with those fields plugged in
and sends it to the appropriate place in sysfs.

      parent reply	other threads:[~2017-11-29 20:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29 15:04 spidev: Instantiating from DT as "spidev" Kyle Roeschley
2017-11-29 16:32 ` Geert Uytterhoeven
     [not found]   ` <CAMuHMdUps9Ti=CRZM7UxrHLD8GA+FKD+_RFLW3H9wUpSRTYs8w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-11-29 19:24     ` Kyle Roeschley
2017-11-29 22:18       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdX62=vC6=P-v=SPe_hq0F12tOZCgePaS7=MZZg_4PkvUw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-11-30  2:07           ` Trent Piepho
     [not found]             ` <1512007657.9792.45.camel-cgc2CodaaHDQT0dZR+AlfA@public.gmane.org>
2017-11-30  8:03               ` Geert Uytterhoeven
     [not found]                 ` <CAMuHMdXv2WsGCUBD4Td9K1zOfZ9DOfeW5rYtCyq27Ucp21xGRA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-11-30 22:24                   ` Kyle Roeschley
2017-12-12 18:44                     ` Kyle Roeschley
2017-11-29 20:22     ` Trent Piepho [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=1511986944.9792.36.camel@impinj.com \
    --to=tpiepho-cgc2codaahdqt0dzr+alfa@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
    --cc=kyle.roeschley-acOepvfBmUk@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@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.