[U-Boot] [PATCHv2 14/21] net: sunxi: Have sunxi common functions together

Olliver Schinagl
2017-04-10T15:33:49Z

The sun[8x]i network drivers have some common functions. Let's introduce
a common file with the reading of the MAC address as a start.

In the future, we can move more sunxi shared/common code into this file.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
---
drivers/net/sunxi_common.c | 33 +++++++++++++++++++++++++++++++++
drivers/net/sunxi_common.h | 13 +++++++++++++
2 files changed, 46 insertions(+)
create mode 100644 drivers/net/sunxi_common.c
create mode 100644 drivers/net/sunxi_common.h

diff --git a/drivers/net/sunxi_common.c b/drivers/net/sunxi_common.c
new file mode 100644
index 0000000000..a0c0548059
--- /dev/null
+++ b/drivers/net/sunxi_common.c
@@ -0,0 +1,33 @@
+/*
+ * (c) Copyright 2017
+ * Author: Olliver Schinagl <oliver@schinagl.nl>
+ *
+ * SPX-License-Identifier: GPL-3.0+
+ *
+ * Common code for the sunxi series of the ethernet sunxi glue code
+ *
+ */
+
+#include <asm/arch/sys_proto.h>
+#include <common.h>
+#include <dm/device.h>
+#include <net.h>
+#include <linux/types.h>
+
+/*
+ * Set ethernet MAC address based on serial number.
+ * FIXME: For now we call sunxi_gen_hwaddr to generate the MAC address there.
+ * This is done because we have some devices, which expect their MAC address to
+ * to be passed via the environment and obtained from the FDT. Once that code
+ * has been refactored (it is quircky to say the least), the mac generating code
+ * should live here.
+ */
+int sunxi_eth_read_rom_hwaddr(struct udevice *dev)
+{
+ struct eth_pdata *pdata = dev_get_platdata(dev);
+
+ if (!pdata || (dev->seq < 0))
+ return -ENOSYS;
+
+ return sunxi_gen_hwaddr(dev->seq, pdata->enetaddr);
+}
diff --git a/drivers/net/sunxi_common.h b/drivers/net/sunxi_common.h
new file mode 100644
index 0000000000..79d33e40bb
--- /dev/null
+++ b/drivers/net/sunxi_common.h
@@ -0,0 +1,13 @@
+/*
+ * (c) Copyright 2017
+ * Author: Olliver Schinagl <oliver@schinagl.nl>
+ *
+ * SPX-License-Identifier: GPL-3.0+
+ *
+ * Common code for the sunxi series of the ethernet sunxi glue code
+ *
+ */
+
+#include <dm/device.h>
+
+int sunxi_eth_read_rom_hwaddr(struct udevice *dev);
--
2.11.0