Skip to content

Commit 7588a51

Browse files
Srinivas-Kandagatlagregkh
authored andcommitted
slimbus: core: add support to device tree helper
This patch adds support to parse slim devices from device tree. Signed-off-by: Srinivas Kandagatla <[email protected]> Reviwed-by: Mark Brown <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 46a2bb5 commit 7588a51

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

drivers/slimbus/core.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/slab.h>
99
#include <linux/init.h>
1010
#include <linux/idr.h>
11+
#include <linux/of.h>
1112
#include <linux/slimbus.h>
1213
#include "slimbus.h"
1314

@@ -113,6 +114,9 @@ static int slim_add_device(struct slim_controller *ctrl,
113114
sbdev->dev.driver = NULL;
114115
sbdev->ctrl = ctrl;
115116

117+
if (node)
118+
sbdev->dev.of_node = of_node_get(node);
119+
116120
dev_set_name(&sbdev->dev, "%x:%x:%x:%x",
117121
sbdev->e_addr.manf_id,
118122
sbdev->e_addr.prod_code,
@@ -143,6 +147,50 @@ static struct slim_device *slim_alloc_device(struct slim_controller *ctrl,
143147
return sbdev;
144148
}
145149

150+
static void of_register_slim_devices(struct slim_controller *ctrl)
151+
{
152+
struct device *dev = ctrl->dev;
153+
struct device_node *node;
154+
155+
if (!ctrl->dev->of_node)
156+
return;
157+
158+
for_each_child_of_node(ctrl->dev->of_node, node) {
159+
struct slim_device *sbdev;
160+
struct slim_eaddr e_addr;
161+
const char *compat = NULL;
162+
int reg[2], ret;
163+
int manf_id, prod_code;
164+
165+
compat = of_get_property(node, "compatible", NULL);
166+
if (!compat)
167+
continue;
168+
169+
ret = sscanf(compat, "slim%x,%x", &manf_id, &prod_code);
170+
if (ret != 2) {
171+
dev_err(dev, "Manf ID & Product code not found %s\n",
172+
compat);
173+
continue;
174+
}
175+
176+
ret = of_property_read_u32_array(node, "reg", reg, 2);
177+
if (ret) {
178+
dev_err(dev, "Device and Instance id not found:%d\n",
179+
ret);
180+
continue;
181+
}
182+
183+
e_addr.dev_index = reg[0];
184+
e_addr.instance = reg[1];
185+
e_addr.manf_id = manf_id;
186+
e_addr.prod_code = prod_code;
187+
188+
sbdev = slim_alloc_device(ctrl, &e_addr, node);
189+
if (!sbdev)
190+
continue;
191+
}
192+
}
193+
146194
/*
147195
* slim_register_controller() - Controller bring-up and registration.
148196
*
@@ -174,6 +222,8 @@ int slim_register_controller(struct slim_controller *ctrl)
174222
dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n",
175223
ctrl->name, ctrl->dev);
176224

225+
of_register_slim_devices(ctrl);
226+
177227
return 0;
178228
}
179229
EXPORT_SYMBOL_GPL(slim_register_controller);

0 commit comments

Comments
 (0)