1 // SPDX-License-Identifier: GPL-2.0+
3 * mdio-boardinfo - Collect pre-declarations for MDIO devices
6 #include <linux/kernel.h>
7 #include <linux/slab.h>
8 #include <linux/export.h>
9 #include <linux/mutex.h>
10 #include <linux/list.h>
12 #include "mdio-boardinfo.h"
14 static LIST_HEAD(mdio_board_list
);
15 static DEFINE_MUTEX(mdio_board_lock
);
18 * mdiobus_setup_mdiodev_from_board_info - create and setup MDIO devices
19 * from pre-collected board specific MDIO information
20 * @bus: Bus the board_info belongs to
21 * @cb: Callback to create device on bus
24 void mdiobus_setup_mdiodev_from_board_info(struct mii_bus
*bus
,
27 struct mdio_board_info
*bi
))
29 struct mdio_board_entry
*be
;
30 struct mdio_board_entry
*tmp
;
31 struct mdio_board_info
*bi
;
34 mutex_lock(&mdio_board_lock
);
35 list_for_each_entry_safe(be
, tmp
, &mdio_board_list
, list
) {
38 if (strcmp(bus
->id
, bi
->bus_id
))
41 mutex_unlock(&mdio_board_lock
);
43 mutex_lock(&mdio_board_lock
);
48 mutex_unlock(&mdio_board_lock
);
50 EXPORT_SYMBOL(mdiobus_setup_mdiodev_from_board_info
);
53 * mdio_register_board_info - register MDIO devices for a given board
54 * @info: array of devices descriptors
55 * @n: number of descriptors provided
58 * The board info passed can be marked with __initdata but be pointers
59 * such as platform_data etc. are copied as-is
61 int mdiobus_register_board_info(const struct mdio_board_info
*info
,
64 struct mdio_board_entry
*be
;
67 be
= kcalloc(n
, sizeof(*be
), GFP_KERNEL
);
71 for (i
= 0; i
< n
; i
++, be
++, info
++) {
72 memcpy(&be
->board_info
, info
, sizeof(*info
));
73 mutex_lock(&mdio_board_lock
);
74 list_add_tail(&be
->list
, &mdio_board_list
);
75 mutex_unlock(&mdio_board_lock
);
80 EXPORT_SYMBOL(mdiobus_register_board_info
);