kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: agnel.joel@gmail.com (Joel Fernandes)
To: kernelnewbies@lists.kernelnewbies.org
Subject: How to use spi device from another kernel module?
Date: Tue, 6 Dec 2016 21:12:24 -0800	[thread overview]
Message-ID: <CAD=GYpb6GDKtKSADg7nqXtdCtSgT2uSFUBeXwdkKyXC57OnEzQ@mail.gmail.com> (raw)
In-Reply-To: <CAJ2oMh+f6x1jPp3sHc_k8HPK+fcTUdhwkVX9shX_TyL5dDvv2Q@mail.gmail.com>

On Tue, Dec 6, 2016 at 11:42 AM, Ran Shalit <ranshalit@gmail.com> wrote:
> Hello,
>
> I have spi device which is registered using spi_register_board_info(),
> and I would like to get a pointer to this device in some other kernel module.
>
> Is there a simple way to get a pointer to pointer to a device , so
> that we can use it from other module ? (something like i2c_get_adapter
> for i2c)

Find out what's the SPI bus number (for the master) and the chip
select on that SPI master (for the SPI device)

Then you can use bus_for_each_device on spi_bus_type and find the
spi_device you're looking for. See the following code for an example
of how to use bus_for_each_device:

http://lxr.free-electrons.com/source/drivers/spi/spi.c#L524

In your check function, just make sure your spi->master->bus_num is
the bus you want and the spi->chip_select is the chip select
corresponding to the device you want. If both these conditions are
satisfied, there you have your spi_device.

HTH,

-Joel

  reply	other threads:[~2016-12-07  5:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 19:42 How to use spi device from another kernel module? Ran Shalit
2016-12-07  5:12 ` Joel Fernandes [this message]
2016-12-07  7:02   ` Greg KH
2016-12-07 15:27     ` Ran Shalit
2016-12-07 16:58     ` Joel Fernandes
2016-12-07 17:26       ` Ran Shalit
2016-12-07 18:21         ` Ran Shalit
2016-12-08 10:42           ` Ran Shalit

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='CAD=GYpb6GDKtKSADg7nqXtdCtSgT2uSFUBeXwdkKyXC57OnEzQ@mail.gmail.com' \
    --to=agnel.joel@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.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).