mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller
@ 2015-05-11 21:00 Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 1/5] net: dm9k: show only one phy on miibus Antony Pavlov
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-05-11 21:00 UTC (permalink / raw)
  To: barebox

Changes since v1 (http://lists.infradead.org/pipermail/barebox/2014-September):

  * rework 'net: dm9k: add device tree support' completely;
  * add additional comments to 'net: dm9k: show only one phy on miibus';
  * add img-ci20-related patches.


Antony Pavlov (5):
  net: dm9k: show only one phy on miibus
  net: dm9k: add device tree support
  net: dm9k: fix reset routine
  MIPS: img-ci20: enable dm9000 ethernet controller
  MIPS: img-ci20_defconfig: enable network stuff

 arch/mips/configs/img-ci20_defconfig |  11 ++-
 arch/mips/dts/img-ci20.dts           |  15 ++++
 arch/mips/mach-xburst/Kconfig        |   1 +
 drivers/net/dm9k.c                   | 138 ++++++++++++++++++++++++++++++-----
 4 files changed, 143 insertions(+), 22 deletions(-)

-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/5] net: dm9k: show only one phy on miibus
  2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
@ 2015-05-11 21:00 ` Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 2/5] net: dm9k: add device tree support Antony Pavlov
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-05-11 21:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/net/dm9k.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/dm9k.c b/drivers/net/dm9k.c
index abcb7ee..5798e16 100644
--- a/drivers/net/dm9k.c
+++ b/drivers/net/dm9k.c
@@ -359,6 +359,11 @@ static int dm9k_phy_read(struct mii_bus *bus, int addr, int reg)
 	struct dm9k *priv = bus->priv;
 	struct device_d *dev = &bus->dev;
 
+	/* only internal phy supported by now, so show only one phy on miibus */
+	if (addr != 0) {
+		return 0xffff;
+	}
+
 	/* Fill the phyxcer register into REG_0C */
 	dm9k_iow(priv, DM9K_EPAR, DM9K_PHY | reg);
 	dm9k_iow(priv, DM9K_EPCR, 0xc);	/* Issue phyxcer read command */
@@ -378,6 +383,11 @@ static int dm9k_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
 	struct dm9k *priv = bus->priv;
 	struct device_d *dev = &bus->dev;
 
+	/* only internal phy supported by now, so show only one phy on miibus */
+	if (addr != 0) {
+		return 0;
+	}
+
 	/* Fill the phyxcer register into REG_0C */
 	dm9k_iow(priv, DM9K_EPAR, DM9K_PHY | reg);
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/5] net: dm9k: add device tree support
  2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 1/5] net: dm9k: show only one phy on miibus Antony Pavlov
@ 2015-05-11 21:00 ` Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 3/5] net: dm9k: fix reset routine Antony Pavlov
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-05-11 21:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/net/dm9k.c | 103 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 87 insertions(+), 16 deletions(-)

diff --git a/drivers/net/dm9k.c b/drivers/net/dm9k.c
index 5798e16..4251a91 100644
--- a/drivers/net/dm9k.c
+++ b/drivers/net/dm9k.c
@@ -708,17 +708,66 @@ static int dm9k_init_dev(struct eth_device *edev)
 	return 0;
 }
 
+static int dm9000_setup_buswidth(struct device_d *dev, struct dm9k *priv, uint32_t width)
+{
+	switch (width) {
+	case 1:
+		priv->buswidth = IORESOURCE_MEM_8BIT;
+		break;
+	case 2:
+		priv->buswidth = IORESOURCE_MEM_16BIT;
+		break;
+	case 4:
+		priv->buswidth = IORESOURCE_MEM_32BIT;
+		break;
+	default:
+		dev_err(dev, "Wrong io resource size\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int dm9000_parse_dt(struct device_d *dev, struct dm9k *priv)
+{
+	struct device_node *np = dev->device_node;
+	uint32_t prop;
+
+	if (!IS_ENABLED(CONFIG_OFDEVICE) || !np)
+		return -ENODEV;
+
+	if (of_find_property(np, "davicom,no-eeprom", NULL)) {
+		priv->srom = 0;
+	} else {
+		priv->srom = 1;
+	}
+
+	if (of_property_read_u32(np, "reg-io-width", &prop)) {
+		/* Use 8-bit registers by default */
+		prop = 1;
+	}
+
+	return dm9000_setup_buswidth(dev, priv, prop);
+}
+
+static int dm9000_parse_pdata(struct device_d *dev, struct dm9k *priv)
+{
+	struct dm9000_platform_data *pdata = dev->platform_data;
+	uint32_t width;
+
+	priv->srom = pdata->srom;
+
+	width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+
+	return dm9000_setup_buswidth(dev, priv, width);
+}
+
 static int dm9k_probe(struct device_d *dev)
 {
 	unsigned io_mode;
 	struct eth_device *edev;
 	struct dm9k *priv;
-	struct dm9000_platform_data *pdata;
-
-	if (!dev->platform_data) {
-		dev_err(dev, "No platform_data\n");
-		return -ENODEV;
-	}
+	int ret;
 
 	if (dev->num_resources < 2) {
 		dev_err(dev, "Need 2 resources base and data");
@@ -727,19 +776,28 @@ static int dm9k_probe(struct device_d *dev)
 
 	edev = xzalloc(sizeof(struct eth_device) + sizeof(struct dm9k));
 	edev->priv = (struct dm9k *)(edev + 1);
+	priv = edev->priv;
 
-	pdata = dev->platform_data;
+	if (dev->platform_data) {
+		ret = dm9000_parse_pdata(dev, priv);
+	} else {
+		ret = dm9000_parse_dt(dev, priv);
+	}
 
-	priv = edev->priv;
+	if (ret)
+		goto err;
 
-	priv->buswidth = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
 	priv->iodata = dev_request_mem_region(dev, 1);
-	if (!priv->iodata)
-		return -EBUSY;
+	if (!priv->iodata) {
+		ret = -EBUSY;
+		goto err;
+	}
+
 	priv->iobase = dev_request_mem_region(dev, 0);
-	if (!priv->iobase)
-		return -EBUSY;
-	priv->srom = pdata->srom;
+	if (!priv->iobase) {
+		ret = -EBUSY;
+		goto err;
+	}
 
 	edev->init = dm9k_init_dev;
 	edev->open = dm9k_eth_open;
@@ -757,8 +815,10 @@ static int dm9k_probe(struct device_d *dev)
 
 	/* RESET device */
 	dm9k_reset(priv);
-	if(dm9k_check_id(priv))
-		return -ENODEV;
+	if (dm9k_check_id(priv)) {
+		ret = -ENODEV;
+		goto err;
+	}
 
 	io_mode = dm9k_ior(priv, DM9K_ISR) >> 6;
 	switch (io_mode) {
@@ -790,10 +850,21 @@ static int dm9k_probe(struct device_d *dev)
 	eth_register(edev);
 
 	return 0;
+
+err:
+	free(edev);
+
+	return ret;
 }
 
+static struct of_device_id dm9000_of_matches[] = {
+	{ .compatible = "davicom,dm9000", },
+	{ /* sentinel */ }
+};
+
 static struct driver_d dm9k_driver = {
 	.name  = "dm9000",
 	.probe = dm9k_probe,
+	.of_compatible = DRV_OF_COMPAT(dm9000_of_matches),
 };
 device_platform_driver(dm9k_driver);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 3/5] net: dm9k: fix reset routine
  2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 1/5] net: dm9k: show only one phy on miibus Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 2/5] net: dm9k: add device tree support Antony Pavlov
@ 2015-05-11 21:00 ` Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 4/5] MIPS: img-ci20: enable dm9000 ethernet controller Antony Pavlov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-05-11 21:00 UTC (permalink / raw)
  To: barebox

Based on Linux's commit:

    commit 09ee9f87d02e779e4fc3f5c29212c733d6d6e349
    Author: Michael Abbott <michael.abbott@diamond.ac.uk>
    Date:   Wed Oct 16 11:41:33 2013 +0300

        dm9000: Implement full reset of DM9000 network device

        A Davicom application note for the DM9000 network device recommends
        performing software reset twice to correctly initialise the device.
        Without this reset some devices fail to initialise correctly on
        system startup.

N.B. DM9000B on MIPS Creator CI20 board needs additional workaround
(see the 'Make all GPIO pins outputs' and 'Power internal PHY' lines).

This workaround was taken from this U-boot's commit:

    commit fbcb7ece0ea1e364180f1cf963e0fa0ce7f6560d
    Author: Remy Bohmer <linux@bohmer.net>
    Date:   Tue Jun 3 15:26:24 2008 +0200

        DM9000: Improve eth_reset() routine

        According to the application notes of the DM9000 v1.22 chapter 5.2 bullet 2, the
        reset procedure must be done twice to properly reset the DM9000 by means of software.
        This errata is not needed anymore for the DM9000A, but it does not bother it.

        This change has been tested with DM9000A, DM9000E, DM9000EP.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/net/dm9k.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dm9k.c b/drivers/net/dm9k.c
index 4251a91..c3c2a80 100644
--- a/drivers/net/dm9k.c
+++ b/drivers/net/dm9k.c
@@ -48,6 +48,7 @@
 # define NCR_FCOL	(1 << 4)
 # define NCR_FDX	(1 << 3)
 # define NCR_LBK	(3 << 1)
+# define NCR_MAC_LBK	(1 << 1)
 # define NCR_RST	(1 << 0)
 
 #define DM9K_NSR	0x01
@@ -472,8 +473,28 @@ static void dm9k_reset(struct dm9k *priv)
 	struct device_d *dev = priv->miibus.parent;
 
 	dev_dbg(dev, "%s\n", __func__);
-	dm9k_iow(priv, DM9K_NCR, NCR_RST);
-	udelay(1000);		/* delay 1ms */
+
+	/* Reset DM9000, see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
+	 * The essential point is that we have to do a double reset, and the
+	 * instruction is to set LBK into MAC internal loopback mode.
+	 */
+
+	/* Make all GPIO pins outputs */
+	dm9k_iow(priv, DM9K_GPCR, 0x0F);
+	/* Power internal PHY by writing 0 to GPIO0 pin */
+	dm9k_iow(priv, DM9K_GPR, 0);
+
+	dm9k_iow(priv, DM9K_NCR, NCR_RST | NCR_MAC_LBK);
+	udelay(100); /* Application note says at least 20 us */
+	if (dm9k_ior(priv, DM9K_NCR) & NCR_RST)
+		dev_err(dev, "dm9000 did not respond to first reset\n");
+
+	dm9k_iow(priv, DM9K_NCR, 0);
+	dm9k_iow(priv, DM9K_NCR, NCR_RST | NCR_MAC_LBK);
+	udelay(100);
+
+	if (dm9k_ior(priv, DM9K_NCR) & NCR_RST)
+		dev_err(dev, "dm9000 did not respond to second reset\n");
 }
 
 static int dm9k_eth_open(struct eth_device *edev)
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 4/5] MIPS: img-ci20: enable dm9000 ethernet controller
  2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
                   ` (2 preceding siblings ...)
  2015-05-11 21:00 ` [PATCH v2 3/5] net: dm9k: fix reset routine Antony Pavlov
@ 2015-05-11 21:00 ` Antony Pavlov
  2015-05-11 21:00 ` [PATCH v2 5/5] MIPS: img-ci20_defconfig: enable network stuff Antony Pavlov
  2015-05-12  6:22 ` [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-05-11 21:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/dts/img-ci20.dts    | 15 +++++++++++++++
 arch/mips/mach-xburst/Kconfig |  1 +
 2 files changed, 16 insertions(+)

diff --git a/arch/mips/dts/img-ci20.dts b/arch/mips/dts/img-ci20.dts
index f2022dd..da2a5bf 100644
--- a/arch/mips/dts/img-ci20.dts
+++ b/arch/mips/dts/img-ci20.dts
@@ -28,6 +28,21 @@
 		device_type = "memory";
 		reg = <0x0 0x10000000>;
 	};
+
+	board {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "simple-bus";
+		ranges = <>;
+
+		dm9000@16000000 {
+			compatible = "davicom,dm9000";
+			davicom,no-eeprom;
+
+			reg = <0x16000000 1   /* addr */
+			       0x16000002 1>; /* data */
+		};
+	};
 };
 
 &uart0 {
diff --git a/arch/mips/mach-xburst/Kconfig b/arch/mips/mach-xburst/Kconfig
index 2598c41..fd106fe 100644
--- a/arch/mips/mach-xburst/Kconfig
+++ b/arch/mips/mach-xburst/Kconfig
@@ -27,6 +27,7 @@ config BOARD_RZX50
 config BOARD_CI20
 	bool "Imagination Creator CI20"
 	select CPU_JZ4780
+	select HAS_DM9000
 
 endchoice
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 5/5] MIPS: img-ci20_defconfig: enable network stuff
  2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
                   ` (3 preceding siblings ...)
  2015-05-11 21:00 ` [PATCH v2 4/5] MIPS: img-ci20: enable dm9000 ethernet controller Antony Pavlov
@ 2015-05-11 21:00 ` Antony Pavlov
  2015-05-12  6:22 ` [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2015-05-11 21:00 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/configs/img-ci20_defconfig | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/mips/configs/img-ci20_defconfig b/arch/mips/configs/img-ci20_defconfig
index 6702c88..28319c5 100644
--- a/arch/mips/configs/img-ci20_defconfig
+++ b/arch/mips/configs/img-ci20_defconfig
@@ -28,15 +28,18 @@ CONFIG_CMD_UIMAGE=y
 CONFIG_CMD_MD5SUM=y
 CONFIG_CMD_GETOPT=y
 CONFIG_CMD_SLEEP=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_MIITOOL=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_TFTP=y
 CONFIG_CMD_EDIT=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_OF_PROPERTY=y
 CONFIG_CMD_OFTREE=y
+CONFIG_NET=y
 CONFIG_OFDEVICE=y
+CONFIG_DRIVER_NET_DM9K=y
 # CONFIG_SPI is not set
-CONFIG_CLOCKSOURCE_DUMMY=y
 CONFIG_CLOCKSOURCE_DUMMY_RATE=3500
-CONFIG_DIGEST_SHA1_GENERIC=y
-CONFIG_DIGEST_SHA224_GENERIC=y
-CONFIG_DIGEST_SHA256_GENERIC=y
+CONFIG_FS_TFTP=y
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller
  2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
                   ` (4 preceding siblings ...)
  2015-05-11 21:00 ` [PATCH v2 5/5] MIPS: img-ci20_defconfig: enable network stuff Antony Pavlov
@ 2015-05-12  6:22 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-05-12  6:22 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Tue, May 12, 2015 at 12:00:48AM +0300, Antony Pavlov wrote:
> Changes since v1 (http://lists.infradead.org/pipermail/barebox/2014-September):
> 
>   * rework 'net: dm9k: add device tree support' completely;
>   * add additional comments to 'net: dm9k: show only one phy on miibus';
>   * add img-ci20-related patches.
> 
> 
> Antony Pavlov (5):
>   net: dm9k: show only one phy on miibus
>   net: dm9k: add device tree support
>   net: dm9k: fix reset routine
>   MIPS: img-ci20: enable dm9000 ethernet controller
>   MIPS: img-ci20_defconfig: enable network stuff

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-05-12  6:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-11 21:00 [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Antony Pavlov
2015-05-11 21:00 ` [PATCH v2 1/5] net: dm9k: show only one phy on miibus Antony Pavlov
2015-05-11 21:00 ` [PATCH v2 2/5] net: dm9k: add device tree support Antony Pavlov
2015-05-11 21:00 ` [PATCH v2 3/5] net: dm9k: fix reset routine Antony Pavlov
2015-05-11 21:00 ` [PATCH v2 4/5] MIPS: img-ci20: enable dm9000 ethernet controller Antony Pavlov
2015-05-11 21:00 ` [PATCH v2 5/5] MIPS: img-ci20_defconfig: enable network stuff Antony Pavlov
2015-05-12  6:22 ` [PATCH v2 0/5] dm9k fixups; img-ci20: enable dm9000 ethernet controller Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox