|
8 | 8 | #include <linux/slab.h>
|
9 | 9 | #include <linux/init.h>
|
10 | 10 | #include <linux/idr.h>
|
| 11 | +#include <linux/of.h> |
11 | 12 | #include <linux/slimbus.h>
|
12 | 13 | #include "slimbus.h"
|
13 | 14 |
|
@@ -113,6 +114,9 @@ static int slim_add_device(struct slim_controller *ctrl,
|
113 | 114 | sbdev->dev.driver = NULL;
|
114 | 115 | sbdev->ctrl = ctrl;
|
115 | 116 |
|
| 117 | + if (node) |
| 118 | + sbdev->dev.of_node = of_node_get(node); |
| 119 | + |
116 | 120 | dev_set_name(&sbdev->dev, "%x:%x:%x:%x",
|
117 | 121 | sbdev->e_addr.manf_id,
|
118 | 122 | sbdev->e_addr.prod_code,
|
@@ -143,6 +147,50 @@ static struct slim_device *slim_alloc_device(struct slim_controller *ctrl,
|
143 | 147 | return sbdev;
|
144 | 148 | }
|
145 | 149 |
|
| 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 | + |
146 | 194 | /*
|
147 | 195 | * slim_register_controller() - Controller bring-up and registration.
|
148 | 196 | *
|
@@ -174,6 +222,8 @@ int slim_register_controller(struct slim_controller *ctrl)
|
174 | 222 | dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n",
|
175 | 223 | ctrl->name, ctrl->dev);
|
176 | 224 |
|
| 225 | + of_register_slim_devices(ctrl); |
| 226 | + |
177 | 227 | return 0;
|
178 | 228 | }
|
179 | 229 | EXPORT_SYMBOL_GPL(slim_register_controller);
|
|
0 commit comments