From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: linuxppc-dev@ozlabs.org, Gary Jennejohn <garyj@denx.de>,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Subject: [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors
Date: Wed, 21 May 2008 19:41:39 +0400 [thread overview]
Message-ID: <20080521154139.GB4566@polina.dev.rtsoft.ru> (raw)
In-Reply-To: <20080521154103.GA32577@polina.dev.rtsoft.ru>
Dedicated (usually the ones that need to fill platform data) constructors
will create board info, so SPI core will probe them as normal SPI devices.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
drivers/spi/spi_of.c | 67 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/spi/spi_of.h | 5 +++
2 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/drivers/spi/spi_of.c b/drivers/spi/spi_of.c
index b5ae434..2e1a11f 100644
--- a/drivers/spi/spi_of.c
+++ b/drivers/spi/spi_of.c
@@ -11,6 +11,66 @@
#include <linux/spi/spi.h>
#include <linux/spi/spi_of.h>
+/*
+ * Caller have no idea who is master, i.e. this function does not
+ * accept pointer to the master, instead we use board infos.
+ */
+int of_spi_device_probe_common(struct device_node *np,
+ struct spi_board_info *spi_binfo,
+ const char *modalias)
+{
+ struct device_node *parent;
+ const u32 *bus_num;
+ const u32 *chip_select;
+ const u32 *max_speed;
+ int size;
+
+ parent = of_get_parent(np);
+ if (!parent) {
+ pr_err("%s: no parent\n", np->full_name);
+ return -EINVAL;
+ }
+
+ bus_num = of_get_property(parent, "reg", &size);
+ if (!bus_num || size < sizeof(*bus_num)) {
+ pr_err("%s: no reg specified for parent\n", np->full_name);
+ of_node_put(parent);
+ return -EINVAL;
+ }
+ spi_binfo->bus_num = *bus_num;
+ of_node_put(parent);
+
+ chip_select = of_get_property(np, "reg", &size);
+ if (!chip_select || size < sizeof(*chip_select)) {
+ pr_err("%s: no reg (chip-select) specified\n", np->full_name);
+ return -EINVAL;
+ }
+ spi_binfo->chip_select = *chip_select;
+
+ max_speed = of_get_property(np, "max-speed", &size);
+ if (!max_speed || size < sizeof(*max_speed))
+ spi_binfo->max_speed_hz = 100000;
+ else
+ spi_binfo->max_speed_hz = *max_speed;
+
+ strcpy(spi_binfo->modalias, modalias);
+
+ /*
+ * spi_of_register_devices() should not probe this device, it will
+ * be managed by the dedicated driver.
+ */
+ np->data = spi_binfo;
+
+ return 0;
+}
+EXPORT_SYMBOL(of_spi_device_probe_common);
+
+void of_spi_device_remove_common(struct device_node *np)
+{
+ /* For some reason dedicated driver changed its mind. */
+ np->data = NULL;
+}
+
/**
* spi_of_register_devices - Register child devices onto the SPI bus
* @master: Pointer to spi_master device
@@ -29,6 +89,13 @@ void spi_of_register_devices(struct spi_master *master, struct device_node *np)
int len;
for_each_child_of_node(np, nc) {
+ if (nc->data) {
+ dev_dbg(&master->dev, "%s: device seem to be not "
+ "a simple one, somebody took care of it "
+ "already\n", np->full_name);
+ continue;
+ }
+
/* Alloc an spi_device */
spi = spi_alloc_device(master);
if (!spi) {
diff --git a/include/linux/spi/spi_of.h b/include/linux/spi/spi_of.h
index c943f98..1ea2d82 100644
--- a/include/linux/spi/spi_of.h
+++ b/include/linux/spi/spi_of.h
@@ -12,6 +12,11 @@
#include <linux/of.h>
#include <linux/spi/spi.h>
+extern int of_spi_device_probe_common(struct device_node *np,
+ struct spi_board_info *spi_binfo,
+ const char *modalias);
+extern void of_spi_device_remove_common(struct device_node *np);
+
extern void spi_of_register_devices(struct spi_master *master,
struct device_node *np);
--
1.5.5.1
next prev parent reply other threads:[~2008-05-21 15:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-21 15:41 [RFC/DRAFT] SPI OF bindings, MMC-over-SPI, chip-selects and so on Anton Vorontsov
2008-05-21 15:41 ` [PATCH 1/4] [SPI] spi_mpc83xx: convert to the OF platform driver Anton Vorontsov
2008-05-21 16:50 ` Grant Likely
2008-05-21 17:05 ` Anton Vorontsov
2008-05-21 17:17 ` Grant Likely
2008-05-21 15:41 ` Anton Vorontsov [this message]
2008-05-21 15:56 ` [PATCH 2/4] [OF] spi_of: add support for dedicated SPI constructors Guennadi Liakhovetski
2008-05-21 16:10 ` Anton Vorontsov
2008-05-21 16:24 ` Guennadi Liakhovetski
2008-05-21 16:48 ` Anton Vorontsov
2008-05-21 17:05 ` Grant Likely
2008-05-21 17:51 ` Guennadi Liakhovetski
2008-05-21 19:06 ` Grant Likely
2008-05-21 19:20 ` Guennadi Liakhovetski
2008-05-21 19:53 ` Grant Likely
2008-05-21 20:00 ` Guennadi Liakhovetski
2008-05-21 20:07 ` Grant Likely
2008-05-21 17:30 ` Grant Likely
2008-05-21 15:41 ` [PATCH 3/4] [OF] MMC-over-SPI OF constructor Anton Vorontsov
2008-05-21 15:41 ` [PATCH 4/4] [POWERPC] 86xx: mpc8610_hpcd: support for MMC-over-SPI and PIXIS' GPIOs Anton Vorontsov
2008-05-21 15:54 ` [RFC/DRAFT] SPI OF bindings, MMC-over-SPI, chip-selects and so on Guennadi Liakhovetski
2008-05-21 16:01 ` Anton Vorontsov
2008-05-21 16:51 ` Grant Likely
2008-05-21 17:32 ` Grant Likely
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=20080521154139.GB4566@polina.dev.rtsoft.ru \
--to=avorontsov@ru.mvista.com \
--cc=g.liakhovetski@gmx.de \
--cc=garyj@denx.de \
--cc=grant.likely@secretlab.ca \
--cc=linuxppc-dev@ozlabs.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).