From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 07/18] net: macb: Convert to driver model
Date: Thu, 5 May 2016 07:28:11 -0600 [thread overview]
Message-ID: <1462454902-6093-8-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1462454902-6093-1-git-send-email-sjg@chromium.org>
Add driver-model support to this driver. The old code remains for now so
that we can convert boards one at a time.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
Tested-on: smartweb, corvus, taurus, axm
Tested-by: Heiko Schocher <hs@denx.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---
Changes in v2: None
drivers/net/macb.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 119 insertions(+)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index ecdfc1b..63fb466 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
+#include <dm.h>
/*
* The u-boot networking stack is a little weird. It seems like the
@@ -28,7 +29,9 @@
*/
#include <net.h>
+#ifndef CONFIG_DM_ETH
#include <netdev.h>
+#endif
#include <malloc.h>
#include <miiphy.h>
@@ -100,11 +103,15 @@ struct macb_device {
unsigned long dummy_desc_dma;
const struct device *dev;
+#ifndef CONFIG_DM_ETH
struct eth_device netdev;
+#endif
unsigned short phy_addr;
struct mii_dev *bus;
};
+#ifndef CONFIG_DM_ETH
#define to_macb(_nd) container_of(_nd, struct macb_device, netdev)
+#endif
static int macb_is_gem(struct macb_device *macb)
{
@@ -194,8 +201,13 @@ void __weak arch_get_mdio_control(const char *name)
int macb_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
{
+#ifdef CONFIG_DM_ETH
+ struct udevice *dev = eth_get_dev_by_name(devname);
+ struct macb_device *macb = dev_get_priv(dev);
+#else
struct eth_device *dev = eth_get_dev_by_name(devname);
struct macb_device *macb = to_macb(dev);
+#endif
if (macb->phy_addr != phy_adr)
return -1;
@@ -208,8 +220,13 @@ int macb_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
int macb_miiphy_write(const char *devname, u8 phy_adr, u8 reg, u16 value)
{
+#ifdef CONFIG_DM_ETH
+ struct udevice *dev = eth_get_dev_by_name(devname);
+ struct macb_device *macb = dev_get_priv(dev);
+#else
struct eth_device *dev = eth_get_dev_by_name(devname);
struct macb_device *macb = to_macb(dev);
+#endif
if (macb->phy_addr != phy_adr)
return -1;
@@ -764,6 +781,7 @@ static void _macb_eth_initialize(struct macb_device *macb)
macb_writel(macb, NCFGR, ncfgr);
}
+#ifndef CONFIG_DM_ETH
static int macb_send(struct eth_device *netdev, void *packet, int length)
{
struct macb_device *macb = to_macb(netdev);
@@ -849,5 +867,106 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
#endif
return 0;
}
+#endif /* !CONFIG_DM_ETH */
+
+#ifdef CONFIG_DM_ETH
+
+static int macb_start(struct udevice *dev)
+{
+ struct macb_device *macb = dev_get_priv(dev);
+
+ return _macb_init(macb, dev->name);
+}
+
+static int macb_send(struct udevice *dev, void *packet, int length)
+{
+ struct macb_device *macb = dev_get_priv(dev);
+
+ return _macb_send(macb, dev->name, packet, length);
+}
+
+static int macb_recv(struct udevice *dev, int flags, uchar **packetp)
+{
+ struct macb_device *macb = dev_get_priv(dev);
+
+ macb->next_rx_tail = macb->rx_tail;
+ macb->wrapped = false;
+
+ return _macb_recv(macb, packetp);
+}
+
+static int macb_free_pkt(struct udevice *dev, uchar *packet, int length)
+{
+ struct macb_device *macb = dev_get_priv(dev);
+
+ reclaim_rx_buffers(macb, macb->next_rx_tail);
+
+ return 0;
+}
+
+static void macb_stop(struct udevice *dev)
+{
+ struct macb_device *macb = dev_get_priv(dev);
+
+ _macb_halt(macb);
+}
+
+static int macb_write_hwaddr(struct udevice *dev)
+{
+ struct eth_pdata *plat = dev_get_platdata(dev);
+ struct macb_device *macb = dev_get_priv(dev);
+
+ return _macb_write_hwaddr(macb, plat->enetaddr);
+}
+
+static const struct eth_ops macb_eth_ops = {
+ .start = macb_start,
+ .send = macb_send,
+ .recv = macb_recv,
+ .stop = macb_stop,
+ .free_pkt = macb_free_pkt,
+ .write_hwaddr = macb_write_hwaddr,
+};
+
+static int macb_eth_probe(struct udevice *dev)
+{
+ struct eth_pdata *pdata = dev_get_platdata(dev);
+ struct macb_device *macb = dev_get_priv(dev);
+
+ macb->regs = (void *)pdata->iobase;
+
+ _macb_eth_initialize(macb);
+#if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
+ miiphy_register(dev->name, macb_miiphy_read, macb_miiphy_write);
+ macb->bus = miiphy_get_dev_by_name(dev->name);
+#endif
+
+ return 0;
+}
+
+static int macb_eth_ofdata_to_platdata(struct udevice *dev)
+{
+ struct eth_pdata *pdata = dev_get_platdata(dev);
+
+ pdata->iobase = dev_get_addr(dev);
+ return 0;
+}
+
+static const struct udevice_id macb_eth_ids[] = {
+ { .compatible = "cdns,macb" },
+ { }
+};
+
+U_BOOT_DRIVER(eth_macb) = {
+ .name = "eth_macb",
+ .id = UCLASS_ETH,
+ .of_match = macb_eth_ids,
+ .ofdata_to_platdata = macb_eth_ofdata_to_platdata,
+ .probe = macb_eth_probe,
+ .ops = &macb_eth_ops,
+ .priv_auto_alloc_size = sizeof(struct macb_device),
+ .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
+#endif
#endif
--
2.8.0.rc3.226.g39d4020
next prev parent reply other threads:[~2016-05-05 13:28 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-05 13:28 [U-Boot] [PATCH v2 00/18] at91: Convert Ethernet and LCD to driver model Simon Glass
2016-05-05 13:28 ` [U-Boot] [PATCH v2 01/18] at91: Add support for the AT91 slow clock controller Simon Glass
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 02/18] arm: Allow skipping of low-level init with I-cache on Simon Glass
2016-05-05 14:07 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 03/18] bootm: Align cache flush end address correctly Simon Glass
2016-05-05 14:19 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 04/18] net: Handle an empty bootp extension section Simon Glass
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 05/18] net: macb: Prepare for driver-model conversion Simon Glass
2016-05-05 18:31 ` Joe Hershberger
2016-05-28 22:32 ` Andreas Bießmann
2016-06-20 1:30 ` Simon Glass
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 06/18] net: macb: Flush correct cache portion when sending Simon Glass
2016-05-28 12:35 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` Simon Glass [this message]
2016-05-28 22:43 ` [U-Boot] [PATCH v2 07/18] net: macb: Convert to driver model Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot,v2,07/18] " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 08/18] arm: at91: dts: Bring in device tree file for AT91SAM9G45 Simon Glass
2016-05-28 22:45 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 09/18] arm: at91: Add a header file for the real-time clock Simon Glass
2016-05-28 12:49 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 10/18] at91: Correct NAND ECC register access Simon Glass
2016-05-28 21:06 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 11/18] at91: nand: Set up the ECC strength correctly Simon Glass
2016-05-28 21:12 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 12/18] mtd: nand: Drop a blank line in nand_wait() Simon Glass
2016-05-28 12:53 ` Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 13/18] at91: Add driver-model GPIO devices for AT91SAM9G45 Simon Glass
2016-05-28 22:46 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 14/18] at91: mtd: nand: Add dev_warn() to correct build error in driver Simon Glass
2016-05-28 23:04 ` Andreas Bießmann
2016-06-04 20:27 ` [U-Boot] [PATCH] linux/compat.h: add dev_warn() Andreas Bießmann
2016-06-10 0:35 ` Simon Glass
2016-06-12 22:01 ` [U-Boot] " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 15/18] at91: video: Prepare for driver-model conversion Simon Glass
2016-06-04 20:08 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 16/18] at91: video: Support driver-model for the LCD driver Simon Glass
2016-06-04 20:11 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 17/18] fdt: Correct return value in fdtdec_decode_display_timing() Simon Glass
2016-06-04 20:14 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot, v2, " Andreas Bießmann
2016-05-05 13:28 ` [U-Boot] [PATCH v2 18/18] arm: at91: Add support for gurnard Simon Glass
2016-06-04 20:31 ` Andreas Bießmann
2016-06-12 22:01 ` [U-Boot] [U-Boot,v2,18/18] " Andreas Bießmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462454902-6093-8-git-send-email-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox