Commit affb05d9 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'non-platform-devices-of_get_mac_address'



Michael Walle says:

====================
of: net: support non-platform devices in of_get_mac_address()

of_get_mac_address() is commonly used to fetch the MAC address
from the device tree. It also supports reading it from a NVMEM
provider. But the latter is only possible for platform devices,
because only platform devices are searched for a matching device
node.

Add a second method to fetch the NVMEM cell by a device tree node
instead of a "struct device".

Moreover, the NVMEM subsystem will return dynamically allocated
data which has to be freed after use. Currently, this is handled
by allocating a device resource manged buffer to store the MAC
address. of_get_mac_address() then returns a pointer to this
buffer. Without a device, this trick is not possible anymore.
Thus, change the of_get_mac_address() API to have the caller
supply a buffer.

It was considered to use the network device to attach the buffer
to, but then the order matters and netdev_register() has to be
called before of_get_mac_address(). No driver does it this way.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 40b5d2f1 f10843e0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ static void __init kirkwood_dt_eth_fixup(void)
		struct device_node *pnp = of_get_parent(np);
		struct clk *clk;
		struct property *pmac;
		u8 tmpmac[ETH_ALEN];
		void __iomem *io;
		u8 *macaddr;
		u32 reg;
@@ -93,7 +94,7 @@ static void __init kirkwood_dt_eth_fixup(void)

		/* skip disabled nodes or nodes with valid MAC address*/
		if (!of_device_is_available(pnp) ||
		    !IS_ERR(of_get_mac_address(np)))
		    !of_get_mac_address(np, tmpmac))
			goto eth_fixup_skip;

		clk = of_clk_get(pnp, 0);
+1 −4
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ static int __init tsi108_eth_of_init(void)
		struct device_node *phy, *mdio;
		hw_info tsi_eth_data;
		const unsigned int *phy_id;
		const void *mac_addr;
		const phandle *ph;

		memset(r, 0, sizeof(r));
@@ -101,9 +100,7 @@ static int __init tsi108_eth_of_init(void)
			goto err;
		}

		mac_addr = of_get_mac_address(np);
		if (!IS_ERR(mac_addr))
			ether_addr_copy(tsi_eth_data.mac_addr, mac_addr);
		of_get_mac_address(np, tsi_eth_data.mac_addr);

		ph = of_get_property(np, "mdio-handle", NULL);
		mdio = of_find_node_by_phandle(*ph);
+3 −3
Original line number Diff line number Diff line
@@ -1449,10 +1449,10 @@ static int greth_of_probe(struct platform_device *ofdev)
			break;
	}
	if (i == 6) {
		const u8 *addr;
		u8 addr[ETH_ALEN];

		addr = of_get_mac_address(ofdev->dev.of_node);
		if (!IS_ERR(addr)) {
		err = of_get_mac_address(ofdev->dev.of_node, addr);
		if (!err) {
			for (i = 0; i < 6; i++)
				macaddr[i] = (unsigned int) addr[i];
		} else {
+3 −7
Original line number Diff line number Diff line
@@ -790,7 +790,6 @@ static int emac_probe(struct platform_device *pdev)
	struct emac_board_info *db;
	struct net_device *ndev;
	int ret = 0;
	const char *mac_addr;

	ndev = alloc_etherdev(sizeof(struct emac_board_info));
	if (!ndev) {
@@ -853,12 +852,9 @@ static int emac_probe(struct platform_device *pdev)
	}

	/* Read MAC-address from DT */
	mac_addr = of_get_mac_address(np);
	if (!IS_ERR(mac_addr))
		ether_addr_copy(ndev->dev_addr, mac_addr);

	/* Check if the MAC address is valid, if not get a random one */
	if (!is_valid_ether_addr(ndev->dev_addr)) {
	ret = of_get_mac_address(np, ndev->dev_addr);
	if (ret) {
		/* if the MAC address is invalid get a random one */
		eth_hw_addr_random(ndev);
		dev_warn(&pdev->dev, "using random MAC address %pM\n",
			 ndev->dev_addr);
+2 −5
Original line number Diff line number Diff line
@@ -1351,7 +1351,6 @@ static int altera_tse_probe(struct platform_device *pdev)
	struct resource *control_port;
	struct resource *dma_res;
	struct altera_tse_private *priv;
	const unsigned char *macaddr;
	void __iomem *descmap;
	const struct of_device_id *of_id = NULL;

@@ -1525,10 +1524,8 @@ static int altera_tse_probe(struct platform_device *pdev)
	priv->rx_dma_buf_sz = ALTERA_RXDMABUFFER_SIZE;

	/* get default MAC address from device tree */
	macaddr = of_get_mac_address(pdev->dev.of_node);
	if (!IS_ERR(macaddr))
		ether_addr_copy(ndev->dev_addr, macaddr);
	else
	ret = of_get_mac_address(pdev->dev.of_node, ndev->dev_addr);
	if (ret)
		eth_hw_addr_random(ndev);

	/* get phy addr and create mdio */
Loading