Blame view

drivers/net/phy/mdio-boardinfo.c 1.92 KB
a2443fd1a   Andrew Lunn   net: phy: Convert...
1
  // SPDX-License-Identifier: GPL-2.0+
648ea0134   Florian Fainelli   net: phy: Allow p...
2
3
  /*
   * mdio-boardinfo - Collect pre-declarations for MDIO devices
648ea0134   Florian Fainelli   net: phy: Allow p...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   */
  
  #include <linux/kernel.h>
  #include <linux/slab.h>
  #include <linux/export.h>
  #include <linux/mutex.h>
  #include <linux/list.h>
  
  #include "mdio-boardinfo.h"
  
  static LIST_HEAD(mdio_board_list);
  static DEFINE_MUTEX(mdio_board_lock);
  
  /**
   * mdiobus_setup_mdiodev_from_board_info - create and setup MDIO devices
   * from pre-collected board specific MDIO information
19c5a5fec   Andrew Lunn   net: phy: Fixup p...
20
21
   * @bus: Bus the board_info belongs to
   * @cb: Callback to create device on bus
648ea0134   Florian Fainelli   net: phy: Allow p...
22
23
   * Context: can sleep
   */
d0281a56b   Florian Fainelli   net: phy: Allow b...
24
25
26
27
  void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus,
  					   int (*cb)
  					   (struct mii_bus *bus,
  					    struct mdio_board_info *bi))
648ea0134   Florian Fainelli   net: phy: Allow p...
28
29
  {
  	struct mdio_board_entry *be;
0263ea5cd   Andrew Lunn   net: phy: mdio-bo...
30
  	struct mdio_board_entry *tmp;
648ea0134   Florian Fainelli   net: phy: Allow p...
31
32
33
34
  	struct mdio_board_info *bi;
  	int ret;
  
  	mutex_lock(&mdio_board_lock);
0263ea5cd   Andrew Lunn   net: phy: mdio-bo...
35
  	list_for_each_entry_safe(be, tmp, &mdio_board_list, list) {
648ea0134   Florian Fainelli   net: phy: Allow p...
36
37
38
39
  		bi = &be->board_info;
  
  		if (strcmp(bus->id, bi->bus_id))
  			continue;
0263ea5cd   Andrew Lunn   net: phy: mdio-bo...
40
  		mutex_unlock(&mdio_board_lock);
d0281a56b   Florian Fainelli   net: phy: Allow b...
41
  		ret = cb(bus, bi);
0263ea5cd   Andrew Lunn   net: phy: mdio-bo...
42
  		mutex_lock(&mdio_board_lock);
d0281a56b   Florian Fainelli   net: phy: Allow b...
43
  		if (ret)
648ea0134   Florian Fainelli   net: phy: Allow p...
44
  			continue;
648ea0134   Florian Fainelli   net: phy: Allow p...
45
46
47
  	}
  	mutex_unlock(&mdio_board_lock);
  }
d0281a56b   Florian Fainelli   net: phy: Allow b...
48
  EXPORT_SYMBOL(mdiobus_setup_mdiodev_from_board_info);
648ea0134   Florian Fainelli   net: phy: Allow p...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  
  /**
   * mdio_register_board_info - register MDIO devices for a given board
   * @info: array of devices descriptors
   * @n: number of descriptors provided
   * Context: can sleep
   *
   * The board info passed can be marked with __initdata but be pointers
   * such as platform_data etc. are copied as-is
   */
  int mdiobus_register_board_info(const struct mdio_board_info *info,
  				unsigned int n)
  {
  	struct mdio_board_entry *be;
  	unsigned int i;
  
  	be = kcalloc(n, sizeof(*be), GFP_KERNEL);
  	if (!be)
  		return -ENOMEM;
  
  	for (i = 0; i < n; i++, be++, info++) {
  		memcpy(&be->board_info, info, sizeof(*info));
  		mutex_lock(&mdio_board_lock);
  		list_add_tail(&be->list, &mdio_board_list);
  		mutex_unlock(&mdio_board_lock);
  	}
  
  	return 0;
  }
90eff9096   Florian Fainelli   net: phy: Allow s...
78
  EXPORT_SYMBOL(mdiobus_register_board_info);