blob: 400c73ad51e4784476088478df5635964e113055 [file] [log] [blame]
Aaron Williams251d65d2020-12-11 17:05:59 +01001// SPDX-License-Identifier: GPL-2.0
2/*
Stefan Roese1fb7e272022-04-07 09:11:44 +02003 * Copyright (C) 2020-2022 Marvell International Ltd.
Aaron Williams251d65d2020-12-11 17:05:59 +01004 *
5 * FDT Helper functions similar to those provided to U-Boot.
6 */
7
Stefan Roese1fb7e272022-04-07 09:11:44 +02008#include <dm.h>
9#include <i2c.h>
Aaron Williams251d65d2020-12-11 17:05:59 +010010#include <log.h>
11#include <malloc.h>
12#include <net.h>
13#include <linux/delay.h>
Stefan Roese1fb7e272022-04-07 09:11:44 +020014#include <asm-generic/gpio.h>
Aaron Williams251d65d2020-12-11 17:05:59 +010015
16#include <mach/cvmx-regs.h>
17#include <mach/cvmx-csr.h>
18#include <mach/cvmx-bootmem.h>
19#include <mach/octeon-model.h>
20#include <mach/octeon_fdt.h>
21#include <mach/cvmx-helper.h>
22#include <mach/cvmx-helper-board.h>
23#include <mach/cvmx-helper-cfg.h>
24#include <mach/cvmx-helper-fdt.h>
Aaron Williams251d65d2020-12-11 17:05:59 +010025
26/**
27 * Local allocator to handle both SE and U-Boot that also zeroes out memory
28 *
29 * @param size number of bytes to allocate
30 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010031 * Return: pointer to allocated memory or NULL if out of memory.
Aaron Williams251d65d2020-12-11 17:05:59 +010032 * Alignment is set to 8-bytes.
33 */
Stefan Roese1fb7e272022-04-07 09:11:44 +020034static void *cvmx_fdt_alloc(size_t size)
Aaron Williams251d65d2020-12-11 17:05:59 +010035{
36 return calloc(size, 1);
37}
38
Stefan Roese1fb7e272022-04-07 09:11:44 +020039int cvmx_ofnode_lookup_phandles(ofnode node, const char *prop_name, int *lenp,
40 ofnode *nodes)
Aaron Williams251d65d2020-12-11 17:05:59 +010041{
42 const u32 *phandles;
43 int count;
44 int i;
45
Stefan Roese1fb7e272022-04-07 09:11:44 +020046 phandles = ofnode_get_property(node, prop_name, &count);
Aaron Williams251d65d2020-12-11 17:05:59 +010047 if (!phandles || count < 0)
48 return -FDT_ERR_NOTFOUND;
49
50 count /= 4;
51 if (count > *lenp)
52 count = *lenp;
53
54 for (i = 0; i < count; i++)
Stefan Roese1fb7e272022-04-07 09:11:44 +020055 nodes[i] = ofnode_get_by_phandle(fdt32_to_cpu(phandles[i]));
56
Aaron Williams251d65d2020-12-11 17:05:59 +010057 *lenp = count;
58 return 0;
59}
60
61/**
62 * Given a FDT node return the CPU node number
63 *
64 * @param[in] fdt_addr Address of FDT
65 * @param node FDT node number
66 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010067 * Return: CPU node number or error if negative
Aaron Williams251d65d2020-12-11 17:05:59 +010068 */
69int cvmx_fdt_get_cpu_node(const void *fdt_addr, int node)
70{
71 int parent = node;
72 const u32 *ranges;
73 int len = 0;
74
75 while (fdt_node_check_compatible(fdt_addr, parent, "simple-bus") != 0) {
76 parent = fdt_parent_offset(fdt_addr, parent);
77 if (parent < 0)
78 return parent;
79 }
80 ranges = fdt_getprop(fdt_addr, parent, "ranges", &len);
81 if (!ranges)
82 return len;
83
84 if (len == 0)
85 return 0;
86
87 if (len < 24)
88 return -FDT_ERR_TRUNCATED;
89
90 return fdt32_to_cpu(ranges[2]) / 0x10;
91}
92
93/**
Aaron Williams251d65d2020-12-11 17:05:59 +010094 * Parses all of the channels assigned to a VSC7224 device
95 *
96 * @param[in] fdt_addr Address of flat device tree
97 * @param of_offset Offset of vsc7224 node
98 * @param[in,out] vsc7224 Data structure to hold the data
99 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100100 * Return: 0 for success, -1 on error
Aaron Williams251d65d2020-12-11 17:05:59 +0100101 */
Stefan Roese1fb7e272022-04-07 09:11:44 +0200102static int cvmx_fdt_parse_vsc7224_channels(ofnode node,
Aaron Williams251d65d2020-12-11 17:05:59 +0100103 struct cvmx_vsc7224 *vsc7224)
104{
Stefan Roese1fb7e272022-04-07 09:11:44 +0200105 struct ofnode_phandle_args phandle;
Aaron Williams251d65d2020-12-11 17:05:59 +0100106 int err = 0;
107 int reg;
108 int num_chan = 0;
109 struct cvmx_vsc7224_chan *channel;
110 struct cvmx_fdt_sfp_info *sfp_info;
111 int len;
112 int num_taps;
113 int i;
114 const u32 *tap_values;
115 int of_mac;
116 int xiface, index;
117 bool is_tx;
118 bool is_qsfp;
119 const char *mac_str;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200120 ofnode node_chan;
Aaron Williams251d65d2020-12-11 17:05:59 +0100121
Stefan Roese1fb7e272022-04-07 09:11:44 +0200122 debug("%s(%x, %s)\n", __func__, ofnode_to_offset(node), vsc7224->name);
123 ofnode_for_each_compatible_node(node_chan, "vitesse,vsc7224-channel") {
124 if (!ofnode_valid(node_chan)) {
125 debug("%s: Error parsing FDT node %s\n",
126 __func__, ofnode_get_name(node));
Aaron Williams251d65d2020-12-11 17:05:59 +0100127 break;
128 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200129
130 if (ofnode_to_offset(ofnode_get_parent(node_chan)) !=
131 ofnode_to_offset(node))
Aaron Williams251d65d2020-12-11 17:05:59 +0100132 break;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200133
134 reg = ofnode_get_addr(node_chan);
Aaron Williams251d65d2020-12-11 17:05:59 +0100135 if (reg < 0 || reg > 3) {
136 debug("%s: channel reg is either not present or out of range\n",
137 __func__);
138 err = -1;
139 break;
140 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200141 is_tx = ofnode_read_bool(node_chan, "direction-tx");
Aaron Williams251d65d2020-12-11 17:05:59 +0100142
143 debug("%s(%s): Adding %cx channel %d\n",
144 __func__, vsc7224->name, is_tx ? 't' : 'r',
145 reg);
Stefan Roese1fb7e272022-04-07 09:11:44 +0200146 tap_values = ofnode_get_property(node_chan, "taps", &len);
Aaron Williams251d65d2020-12-11 17:05:59 +0100147 if (!tap_values) {
148 debug("%s: Error: no taps defined for vsc7224 channel %d\n",
149 __func__, reg);
150 err = -1;
151 break;
152 }
153
154 if (vsc7224->channel[reg]) {
155 debug("%s: Error: channel %d already assigned at %p\n",
156 __func__, reg,
157 vsc7224->channel[reg]);
158 err = -1;
159 break;
160 }
161 if (len % 16) {
162 debug("%s: Error: tap format error for channel %d\n",
163 __func__, reg);
164 err = -1;
165 break;
166 }
167 num_taps = len / 16;
168 debug("%s: Adding %d taps\n", __func__, num_taps);
169
Stefan Roese1fb7e272022-04-07 09:11:44 +0200170 channel = cvmx_fdt_alloc(sizeof(*channel) +
171 num_taps * sizeof(struct cvmx_vsc7224_tap));
Aaron Williams251d65d2020-12-11 17:05:59 +0100172 if (!channel) {
173 debug("%s: Out of memory\n", __func__);
174 err = -1;
175 break;
176 }
177 vsc7224->channel[reg] = channel;
178 channel->num_taps = num_taps;
179 channel->lane = reg;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200180 channel->of_offset = ofnode_to_offset(node_chan);
Aaron Williams251d65d2020-12-11 17:05:59 +0100181 channel->is_tx = is_tx;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200182 channel->pretap_disable = ofnode_read_bool(node_chan,
183 "pretap-disable");
184 channel->posttap_disable = ofnode_read_bool(node_chan,
185 "posttap-disable");
Aaron Williams251d65d2020-12-11 17:05:59 +0100186 channel->vsc7224 = vsc7224;
187 /* Read all the tap values */
188 for (i = 0; i < num_taps; i++) {
189 channel->taps[i].len = fdt32_to_cpu(tap_values[i * 4 + 0]);
190 channel->taps[i].main_tap = fdt32_to_cpu(tap_values[i * 4 + 1]);
191 channel->taps[i].pre_tap = fdt32_to_cpu(tap_values[i * 4 + 2]);
192 channel->taps[i].post_tap = fdt32_to_cpu(tap_values[i * 4 + 3]);
193 debug("%s: tap %d: len: %d, main_tap: 0x%x, pre_tap: 0x%x, post_tap: 0x%x\n",
194 __func__, i, channel->taps[i].len, channel->taps[i].main_tap,
195 channel->taps[i].pre_tap, channel->taps[i].post_tap);
196 }
197 /* Now find out which interface it's mapped to */
198 channel->ipd_port = -1;
199
200 mac_str = "sfp-mac";
Stefan Roese1fb7e272022-04-07 09:11:44 +0200201 if (ofnode_get_property(node_chan, mac_str, NULL)) {
Aaron Williams251d65d2020-12-11 17:05:59 +0100202 is_qsfp = false;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200203 } else if (ofnode_get_property(node_chan, "qsfp-mac", NULL)) {
Aaron Williams251d65d2020-12-11 17:05:59 +0100204 is_qsfp = true;
205 mac_str = "qsfp-mac";
206 } else {
207 debug("%s: Error: MAC not found for %s channel %d\n", __func__,
208 vsc7224->name, reg);
209 return -1;
210 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200211
212 err = ofnode_parse_phandle_with_args(node_chan, mac_str, NULL,
213 0, 0, &phandle);
214 if (err) {
Aaron Williams251d65d2020-12-11 17:05:59 +0100215 debug("%s: Error %d with MAC %s phandle for %s\n", __func__, of_mac,
216 mac_str, vsc7224->name);
217 return -1;
218 }
219
Stefan Roese1fb7e272022-04-07 09:11:44 +0200220 debug("%s: Found mac at %s\n", __func__,
221 ofnode_get_name(phandle.node));
Aaron Williams251d65d2020-12-11 17:05:59 +0100222
Stefan Roese1fb7e272022-04-07 09:11:44 +0200223 xiface = (ofnode_get_addr(ofnode_get_parent(phandle.node))
224 >> 24) & 0x0f;
225 index = ofnode_get_addr(phandle.node);
226 channel->xiface = xiface;
227 channel->index = index;
228 channel->ipd_port = cvmx_helper_get_ipd_port(xiface, index);
Aaron Williams251d65d2020-12-11 17:05:59 +0100229
Stefan Roese1fb7e272022-04-07 09:11:44 +0200230 debug("%s: Found MAC, xiface: 0x%x, index: %d, ipd port: %d\n", __func__,
231 xiface, index, channel->ipd_port);
232 if (channel->ipd_port >= 0) {
233 cvmx_helper_cfg_set_vsc7224_chan_info(xiface, index, channel);
234 debug("%s: Storing config channel for xiface 0x%x, index %d\n",
235 __func__, xiface, index);
Aaron Williams251d65d2020-12-11 17:05:59 +0100236 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200237 sfp_info = cvmx_helper_cfg_get_sfp_info(xiface, index);
238 if (!sfp_info) {
239 debug("%s: Warning: no (Q)SFP+ slot found for xinterface 0x%x, index %d for channel %d\n",
240 __func__, xiface, index, channel->lane);
241 continue;
242 }
243
244 /* Link it */
245 channel->next = sfp_info->vsc7224_chan;
246 if (sfp_info->vsc7224_chan)
247 sfp_info->vsc7224_chan->prev = channel;
248 sfp_info->vsc7224_chan = channel;
249 sfp_info->is_vsc7224 = true;
250 debug("%s: Registering VSC7224 %s channel %d with SFP %s\n", __func__,
251 vsc7224->name, channel->lane, sfp_info->name);
252 if (!sfp_info->mod_abs_changed) {
253 debug("%s: Registering cvmx_sfp_vsc7224_mod_abs_changed at %p for xinterface 0x%x, index %d\n",
254 __func__, &cvmx_sfp_vsc7224_mod_abs_changed, xiface, index);
255 cvmx_sfp_register_mod_abs_changed(
256 sfp_info,
257 &cvmx_sfp_vsc7224_mod_abs_changed,
258 NULL);
259 }
260
261 if (num_chan >= 4)
262 break;
263 }
Aaron Williams251d65d2020-12-11 17:05:59 +0100264
265 return err;
266}
267
268/**
269 * @INTERNAL
270 * Parses all instances of the Vitesse VSC7224 reclocking chip
271 *
272 * @param[in] fdt_addr Address of flat device tree
273 *
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100274 * Return: 0 for success, error otherwise
Aaron Williams251d65d2020-12-11 17:05:59 +0100275 */
276int __cvmx_fdt_parse_vsc7224(const void *fdt_addr)
277{
Aaron Williams251d65d2020-12-11 17:05:59 +0100278 struct cvmx_vsc7224 *vsc7224 = NULL;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200279 ofnode node;
Aaron Williams251d65d2020-12-11 17:05:59 +0100280 int err = 0;
Aaron Williams251d65d2020-12-11 17:05:59 +0100281 static bool parsed;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200282 const int *init_array;
283 struct udevice *dev;
284 u16 value;
285 int reg;
286 int len;
287 int ret;
288 int i;
Aaron Williams251d65d2020-12-11 17:05:59 +0100289
290 debug("%s(%p)\n", __func__, fdt_addr);
291
292 if (parsed) {
293 debug("%s: Already parsed\n", __func__);
294 return 0;
295 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200296
297 ofnode_for_each_compatible_node(node, "vitesse,vsc7224") {
298 if (!ofnode_valid(node)) {
299 debug("%s: Error parsing FDT node %s\n",
300 __func__, ofnode_get_name(node));
Aaron Williams251d65d2020-12-11 17:05:59 +0100301 break;
302 }
303
Stefan Roese1fb7e272022-04-07 09:11:44 +0200304 vsc7224 = cvmx_fdt_alloc(sizeof(*vsc7224));
Aaron Williams251d65d2020-12-11 17:05:59 +0100305 if (!vsc7224) {
306 debug("%s: Out of memory!\n", __func__);
307 return -1;
308 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200309
310 vsc7224->of_offset = ofnode_to_offset(node);
311 vsc7224->i2c_addr = ofnode_get_addr(node);
312 vsc7224->i2c_bus = cvmx_ofnode_get_i2c_bus(ofnode_get_parent(node));
Aaron Williams251d65d2020-12-11 17:05:59 +0100313 if (vsc7224->i2c_addr < 0) {
314 debug("%s: Error: reg field missing\n", __func__);
315 err = -1;
316 break;
317 }
318 if (!vsc7224->i2c_bus) {
319 debug("%s: Error getting i2c bus\n", __func__);
320 err = -1;
321 break;
322 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200323 vsc7224->name = ofnode_get_name(node);
Aaron Williams251d65d2020-12-11 17:05:59 +0100324 debug("%s: Adding %s\n", __func__, vsc7224->name);
Stefan Roese1fb7e272022-04-07 09:11:44 +0200325
326 err = gpio_request_by_name_nodev(node, "reset", 0,
327 &vsc7224->reset_gpio,
328 GPIOD_IS_OUT);
329 if (err) {
330 printf("%s: reset GPIO not found in DT!\n", __func__);
331 return -ENODEV;
Aaron Williams251d65d2020-12-11 17:05:59 +0100332 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200333
334 err = gpio_request_by_name_nodev(node, "los", 0,
335 &vsc7224->los_gpio,
336 GPIOD_IS_IN);
337 if (err) {
338 printf("%s: los GPIO not found in DT!\n", __func__);
339 return -ENODEV;
Aaron Williams251d65d2020-12-11 17:05:59 +0100340 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200341
342 /*
343 * This code was taken from the NIC23 board specific code
344 * but should be better placed here in the common code
345 */
346 debug("%s: Putting device in reset\n", __func__);
347 dm_gpio_set_value(&vsc7224->reset_gpio, 1);
348 mdelay(10);
349 debug("%s: Taking device out of reset\n", __func__);
350 dm_gpio_set_value(&vsc7224->reset_gpio, 0);
351 mdelay(50);
352
353 init_array = ofnode_get_property(node, "vitesse,reg-init",
354 &len);
355 if (!init_array) {
356 debug("%s: No initialization array\n", __func__);
357 continue;
358 }
359 if ((len % 8) != 0) {
360 printf("%s: Error: register init string should be an array of reg number followed by value\n",
361 __func__);
362 return -1;
363 }
364
365 ret = i2c_get_chip(vsc7224->i2c_bus->i2c_bus,
366 vsc7224->i2c_addr, 1, &dev);
367 if (ret) {
368 debug("Cannot find I2C device: %d\n", ret);
369 return -1;
370 }
371
372 for (i = 0; i < len / sizeof(int); i += 2) {
373 u8 buffer[2];
374
375 reg = fdt32_to_cpu(init_array[i]);
376 value = fdt32_to_cpu(init_array[i + 1]);
377 buffer[0] = value >> 8;
378 buffer[1] = value & 0xff;
379 ret = dm_i2c_write(dev, reg, buffer, 2);
380 if (ret) {
381 debug("Cannot write I2C device: %d\n", ret);
382 return -1;
383 }
384
385 debug(" Wrote 0x%02x <= 0x%02x%02x\n", reg,
386 buffer[0], buffer[1]);
387 }
388
Aaron Williams251d65d2020-12-11 17:05:59 +0100389 debug("%s: Parsing channels\n", __func__);
Stefan Roese1fb7e272022-04-07 09:11:44 +0200390 err = cvmx_fdt_parse_vsc7224_channels(node, vsc7224);
Aaron Williams251d65d2020-12-11 17:05:59 +0100391 if (err) {
392 debug("%s: Error parsing VSC7224 channels\n", __func__);
393 break;
394 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200395 }
Aaron Williams251d65d2020-12-11 17:05:59 +0100396
397 if (err) {
398 debug("%s(): Error\n", __func__);
399 if (vsc7224) {
Stefan Roese1fb7e272022-04-07 09:11:44 +0200400 dm_gpio_free(vsc7224->reset_gpio.dev,
401 &vsc7224->reset_gpio);
402 dm_gpio_free(vsc7224->los_gpio.dev,
403 &vsc7224->los_gpio);
Aaron Williams251d65d2020-12-11 17:05:59 +0100404 if (vsc7224->i2c_bus)
405 cvmx_fdt_free_i2c_bus(vsc7224->i2c_bus);
Stefan Roese1fb7e272022-04-07 09:11:44 +0200406 free(vsc7224);
Aaron Williams251d65d2020-12-11 17:05:59 +0100407 }
408 }
409 if (!err)
410 parsed = true;
411
412 return err;
413}
414
415/**
Stefan Roese1fb7e272022-04-07 09:11:44 +0200416 * Given the parent offset of an i2c device build up a list describing the bus
417 * which can contain i2c muxes and switches.
Aaron Williams251d65d2020-12-11 17:05:59 +0100418 *
Stefan Roese1fb7e272022-04-07 09:11:44 +0200419 * @param[in] node ofnode of the parent node of a GPIO device in
420 * the device tree.
Aaron Williams251d65d2020-12-11 17:05:59 +0100421 *
Stefan Roese1fb7e272022-04-07 09:11:44 +0200422 * @return pointer to list of i2c devices starting from the root which
423 * can include i2c muxes and switches or NULL if error. Note that
424 * all entries are allocated on the heap.
425 *
426 * @see cvmx_fdt_free_i2c_bus()
Aaron Williams251d65d2020-12-11 17:05:59 +0100427 */
Stefan Roese1fb7e272022-04-07 09:11:44 +0200428struct cvmx_fdt_i2c_bus_info *cvmx_ofnode_get_i2c_bus(ofnode node)
Aaron Williams251d65d2020-12-11 17:05:59 +0100429{
Stefan Roese1fb7e272022-04-07 09:11:44 +0200430 struct cvmx_fdt_i2c_bus_info *businfo = NULL;
431 struct udevice *bus;
432 int ret;
Aaron Williams251d65d2020-12-11 17:05:59 +0100433
Stefan Roese1fb7e272022-04-07 09:11:44 +0200434 businfo = cvmx_fdt_alloc(sizeof(*businfo));
435 if (!businfo) {
436 debug("Out of memory\n");
437 return NULL;
Aaron Williams251d65d2020-12-11 17:05:59 +0100438 }
439
Stefan Roese1fb7e272022-04-07 09:11:44 +0200440 debug("%s: Found node %s\n", __func__, ofnode_get_name(node));
441 businfo->of_offset = ofnode_to_offset(node);
Aaron Williams251d65d2020-12-11 17:05:59 +0100442
Stefan Roese1fb7e272022-04-07 09:11:44 +0200443 /*
444 * Get I2C bus and probe it automatically - needed for later use
Aaron Williams251d65d2020-12-11 17:05:59 +0100445 */
Stefan Roese1fb7e272022-04-07 09:11:44 +0200446 ret = device_get_global_by_ofnode(node, &bus);
447 if (!bus || ret) {
448 printf("Cannot find a I2C bus\n");
449 return NULL;
450 }
451
452 businfo->i2c_bus = bus;
453
454 return businfo;
Aaron Williams251d65d2020-12-11 17:05:59 +0100455}
456
457/**
Stefan Roese1fb7e272022-04-07 09:11:44 +0200458 * Return the Octeon bus number for a bus descriptor
Aaron Williams251d65d2020-12-11 17:05:59 +0100459 *
Stefan Roese1fb7e272022-04-07 09:11:44 +0200460 * @param[in] bus bus descriptor
Aaron Williams251d65d2020-12-11 17:05:59 +0100461 *
Stefan Roese1fb7e272022-04-07 09:11:44 +0200462 * @return Octeon twsi bus number or -1 on error
Aaron Williams251d65d2020-12-11 17:05:59 +0100463 */
Stefan Roese1fb7e272022-04-07 09:11:44 +0200464int cvmx_fdt_i2c_get_root_bus(const struct cvmx_fdt_i2c_bus_info *bus)
Aaron Williams251d65d2020-12-11 17:05:59 +0100465{
Stefan Roese1fb7e272022-04-07 09:11:44 +0200466 if (bus->type != CVMX_I2C_BUS_OCTEON)
Aaron Williams251d65d2020-12-11 17:05:59 +0100467 return -1;
Stefan Roese1fb7e272022-04-07 09:11:44 +0200468 return bus->channel;
Aaron Williams251d65d2020-12-11 17:05:59 +0100469}
470
471/**
Stefan Roese1fb7e272022-04-07 09:11:44 +0200472 * Frees all entries for an i2c bus descriptor
Aaron Williams251d65d2020-12-11 17:05:59 +0100473 *
Stefan Roese1fb7e272022-04-07 09:11:44 +0200474 * @param bus bus to free
475 *
476 * @return 0
Aaron Williams251d65d2020-12-11 17:05:59 +0100477 */
Stefan Roese1fb7e272022-04-07 09:11:44 +0200478int cvmx_fdt_free_i2c_bus(struct cvmx_fdt_i2c_bus_info *bus)
Aaron Williams251d65d2020-12-11 17:05:59 +0100479{
Stefan Roese1fb7e272022-04-07 09:11:44 +0200480 struct cvmx_fdt_i2c_bus_info *last;
Aaron Williams251d65d2020-12-11 17:05:59 +0100481
Stefan Roese1fb7e272022-04-07 09:11:44 +0200482 while (bus) {
483 last = bus;
484 bus = bus->child;
485 free(last);
Aaron Williams251d65d2020-12-11 17:05:59 +0100486 }
Stefan Roese1fb7e272022-04-07 09:11:44 +0200487 return 0;
Aaron Williams251d65d2020-12-11 17:05:59 +0100488}