diff mbox

[V2,2/6] of/slimbus: OF helper for SLIMbus

Message ID 1434505564-14333-3-git-send-email-sdharia@codeaurora.org (mailing list archive)
State Not Applicable, archived
Delegated to: Andy Gross
Headers show

Commit Message

sdharia@codeaurora.org June 17, 2015, 1:46 a.m. UTC
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

Comments

Mark Brown June 17, 2015, 1:09 p.m. UTC | #1
On Tue, Jun 16, 2015 at 07:46:00PM -0600, Sagar Dharia wrote:
> OF helper routine scans the SLIMbus DeviceTree, allocates resources,
> and creates slim_devices according to the hierarchy.

You've not CCed any of the DT maintainers on this, for a completely new
bus it seems like we really ought to get their input.

> @@ -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.

It seems better to just say that the controller is a normal device using
the binding for whatever bus it is on and that the binding is for the
bus which is a child node of the controller device?  Also, do we need
#address-cells or #size-cells here?

> +Required property for SLIMbus child node:
> +enumeration-addr	- 6 byte enumeration address of the slave

The idiom for DT seems to be that we define the bus address using the
reg property.  Should we not be following that pattern here too?  I'd
also expect to see the ability to define a compatible for the slaves.
sdharia@codeaurora.org June 17, 2015, 5:01 p.m. UTC | #2
On 6/17/2015 7:09 AM, Mark Brown wrote:
> On Tue, Jun 16, 2015 at 07:46:00PM -0600, Sagar Dharia wrote:
>> OF helper routine scans the SLIMbus DeviceTree, allocates resources,
>> and creates slim_devices according to the hierarchy.
> You've not CCed any of the DT maintainers on this, for a completely new
> bus it seems like we really ought to get their input.
Will do.
>
>> @@ -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.
> It seems better to just say that the controller is a normal device using
> the binding for whatever bus it is on and that the binding is for the
> bus which is a child node of the controller device?  Also, do we need
> #address-cells or #size-cells here?
It will be required if we use 'reg' property for enumeration address per 
my understanding (address-cells: 6, size-cells: 0)
I thought about using 'reg' and it seemed to work as well. Only reason 
for using 'enumeration-addr' was to be closer to what HW calls it.
Looking at other device-trees, (that 'reg' was used for other buses to 
represent slave address), I will document the 'reg' property and 
document it.
Thanks
Sagar
>
>> +Required property for SLIMbus child node:
>> +enumeration-addr	- 6 byte enumeration address of the slave
> The idiom for DT seems to be that we define the bus address using the
> reg property.  Should we not be following that pattern here too?  I'd
> also expect to see the ability to define a compatible for the slaves.
diff mbox

Patch

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)