From: Sagar Dharia <sdharia@codeaurora.org>
To: gregkh@linuxfoundation.org, bp@suse.de, poeschel@lemonage.de,
sdharia@codeaurora.org, treding@nvidia.com, broonie@kernel.org,
gong.chen@linux.intel.com, andreas.noever@gmail.com,
alan@linux.intel.com, mathieu.poirier@linaro.org,
daniel@ffwll.ch, oded.gabbay@amd.com, jkosina@suse.cz,
sharon.dvir1@mail.huji.ac.il, joe@perches.com,
davem@davemloft.net, james.hogan@imgtec.com,
michael.opdenacker@free-electrons.com,
daniel.thompson@linaro.org, linux-kernel@vger.kernel.org
Cc: nkaje@codeaurora.org, kheitke@audience.com,
mlocke@codeaurora.org, agross@codeaurora.org,
linux-arm-msm@vger.kernel.org
Subject: [PATCH V2 2/6] of/slimbus: OF helper for SLIMbus
Date: Tue, 16 Jun 2015 19:46:00 -0600 [thread overview]
Message-ID: <1434505564-14333-3-git-send-email-sdharia@codeaurora.org> (raw)
In-Reply-To: <1434505564-14333-1-git-send-email-sdharia@codeaurora.org>
OF helper routine scans the SLIMbus DeviceTree, allocates resources,
and creates slim_devices according to the hierarchy.
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
---
Documentation/devicetree/bindings/slimbus/bus.txt | 34 ++++++++++
drivers/slimbus/slimbus.c | 76 +++++++++++++++++++++++
2 files changed, 110 insertions(+)
create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt
diff --git a/Documentation/devicetree/bindings/slimbus/bus.txt b/Documentation/devicetree/bindings/slimbus/bus.txt
new file mode 100644
index 0000000..a7a36aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/slimbus/bus.txt
@@ -0,0 +1,34 @@
+SLIM(Serial Low Power Interchip Media Bus) bus
+
+SLIMbus is a 2-wire bus, and is used to communicate with peripheral
+components like audio-codec.
+
+Required property for SLIMbus controller node:
+- compatible - name of SLIMbus controller.
+
+No other properties are required in the SLIMbus controller bus node.
+
+Child nodes:
+
+Every SLIMbus controller node can contain zero or more child nodes
+representing slave devices on the bus. Every SLIMbus slave device is
+uniquely determined by the 6 byte enumeration address.
+
+Required property for SLIMbus child node:
+enumeration-addr - 6 byte enumeration address of the slave
+
+SLIMbus example for Qualcomm's slimbus manager compoent:
+
+ slim@28080000 {
+ compatible = "qcom,slim-msm";
+ reg = <0x28080000 0x2000>,
+ reg-names = "slimbus_physical";
+ interrupts = <0 33 0>;
+ interrupt-names = "slimbus_irq";
+ clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>;
+ clock-names = "iface_clk", "core_clk";
+
+ slim_codec_slave {
+ enumeration-addr = [00 01 60 00 17 02];
+ };
+ };
diff --git a/drivers/slimbus/slimbus.c b/drivers/slimbus/slimbus.c
index 2baf43a..0295a06 100644
--- a/drivers/slimbus/slimbus.c
+++ b/drivers/slimbus/slimbus.c
@@ -19,6 +19,7 @@
#include <linux/idr.h>
#include <linux/pm_runtime.h>
#include <linux/slimbus.h>
+#include <linux/of.h>
static DEFINE_MUTEX(slim_lock);
static DEFINE_IDR(ctrl_idr);
@@ -270,6 +271,80 @@ static LIST_HEAD(board_list);
static LIST_HEAD(slim_ctrl_list);
static DEFINE_MUTEX(board_lock);
+#if IS_ENABLED(CONFIG_OF)
+/* OF helpers for SLIMbus */
+static void of_register_slim_devices(struct slim_controller *ctrl)
+{
+ struct device_node *node;
+ struct slim_boardinfo *temp, *binfo = NULL;
+ int ret, n = 0;
+
+ if (!ctrl->dev.of_node)
+ return;
+
+ for_each_child_of_node(ctrl->dev.of_node, node) {
+ struct property *prop;
+ u8 *ea;
+ struct slim_device *slim;
+ char *name;
+
+ prop = of_find_property(node, "enumeration-addr", NULL);
+ if (!prop || prop->length != 6) {
+ dev_err(&ctrl->dev, "of_slim: invalid E-addr\n");
+ continue;
+ }
+ ea = (u8 *)prop->value;
+ name = kcalloc(SLIMBUS_NAME_SIZE, sizeof(char), GFP_KERNEL);
+ if (!name)
+ goto of_slim_err;
+
+ ret = of_modalias_node(node, name, SLIMBUS_NAME_SIZE);
+ if (ret < 0) {
+ dev_err(&ctrl->dev, "of_slim: modalias fail:%d on %s\n",
+ ret, node->full_name);
+ kfree(name);
+ continue;
+ }
+ slim = kzalloc(sizeof(struct slim_device), GFP_KERNEL);
+ if (!slim) {
+ kfree(name);
+ goto of_slim_err;
+ }
+ slim->e_addr.manf_id = (u16)(ea[5] << 8) | ea[4];
+ slim->e_addr.prod_code = (u16)(ea[3] << 8) | ea[2];
+ slim->e_addr.dev_index = ea[1];
+ slim->e_addr.instance = ea[0];
+
+
+ temp = krealloc(binfo, (n + 1) * sizeof(struct slim_boardinfo),
+ GFP_KERNEL);
+ if (!temp) {
+ kfree(name);
+ kfree(slim);
+ goto of_slim_err;
+ }
+ binfo = temp;
+ slim->dev.of_node = of_node_get(node);
+ slim->name = name;
+ binfo[n].bus_num = ctrl->nr;
+ binfo[n].slim_slave = slim;
+ n++;
+ }
+ slim_register_board_info(binfo, n);
+ return;
+
+of_slim_err:
+ n--;
+ while (n >= 0) {
+ kfree(binfo[n].slim_slave->name);
+ kfree(binfo[n].slim_slave);
+ }
+ kfree(binfo);
+}
+#else
+static void of_register_slim_devices(struct slim_controller *ctrl) { }
+#endif
+
/* If controller is not present, only add to boards list */
static void slim_match_ctrl_to_boardinfo(struct slim_controller *ctrl,
struct slim_boardinfo *bi)
@@ -326,6 +401,7 @@ void slim_ctrl_add_boarddevs(struct slim_controller *ctrl)
{
struct sbi_boardinfo *bi;
+ of_register_slim_devices(ctrl);
mutex_lock(&board_lock);
list_add_tail(&ctrl->list, &slim_ctrl_list);
list_for_each_entry(bi, &board_list, list)
--
1.8.2.1
next prev parent reply other threads:[~2015-06-17 1:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-17 1:45 [PATCH V2 0/6] Introduce framework for SLIMbus device drivers Sagar Dharia
2015-06-17 1:45 ` [PATCH V2 1/6] SLIMbus: Device management on SLIMbus Sagar Dharia
2015-06-17 3:38 ` Joe Perches
2015-06-17 13:16 ` Mark Brown
2015-06-17 17:36 ` Sagar Dharia
2015-06-18 21:39 ` Srinivas Kandagatla
2015-06-19 8:22 ` Daniel Thompson
2015-06-17 1:46 ` Sagar Dharia [this message]
2015-06-17 13:09 ` [PATCH V2 2/6] of/slimbus: OF helper for SLIMbus Mark Brown
2015-06-17 17:01 ` Sagar Dharia
2015-06-17 1:46 ` [PATCH V2 3/6] slimbus: Add messaging APIs to slimbus framework Sagar Dharia
2015-06-17 1:46 ` [PATCH V2 4/6] slim: qcom: Add Qualcomm Slimbus controller driver Sagar Dharia
2015-06-17 13:53 ` Mark Brown
2015-06-28 19:13 ` Sagar Dharia
2015-06-17 1:46 ` [PATCH V2 5/6] slimbus: Add support for 'clock-pause' feature Sagar Dharia
2015-06-17 1:46 ` [PATCH V2 6/6] slim: qcom: Add runtime-pm support using clock-pause feature Sagar Dharia
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=1434505564-14333-3-git-send-email-sdharia@codeaurora.org \
--to=sdharia@codeaurora.org \
--cc=agross@codeaurora.org \
--cc=alan@linux.intel.com \
--cc=andreas.noever@gmail.com \
--cc=bp@suse.de \
--cc=broonie@kernel.org \
--cc=daniel.thompson@linaro.org \
--cc=daniel@ffwll.ch \
--cc=davem@davemloft.net \
--cc=gong.chen@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=james.hogan@imgtec.com \
--cc=jkosina@suse.cz \
--cc=joe@perches.com \
--cc=kheitke@audience.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=michael.opdenacker@free-electrons.com \
--cc=mlocke@codeaurora.org \
--cc=nkaje@codeaurora.org \
--cc=oded.gabbay@amd.com \
--cc=poeschel@lemonage.de \
--cc=sharon.dvir1@mail.huji.ac.il \
--cc=treding@nvidia.com \
/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