Skip to contentSkip to conversation

net: dm9000: Allow instantiation using device tree

PATCH Superseded Tomasz Figa 3 participants 6 messages May 18, 2013 – May 19, 2013

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dm9000: Allow instantiation using device tree

This patch adds Device Tree support to dm9000 driver.

---
 .../devicetree/bindings/net/davicom-dm9000.txt     | 27 ++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 drivers/net/ethernet/davicom/dm9000.c              | 60 ++++++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/davicom-dm9000.txt
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +27 -0
new file mode 100644
index 0000000..d2902db
@@ -0,0 +1,27 @@
+Davicom DM9000 Fast Ethernet controller
+
+Required properties:
+- compatible = "davicom,dm9000";
+- reg : physical addresses and sizes of registers, must contain 2 entries:
+    first entry : address register,
+    second entry : address register.
+- interrupt-parent : interrupt controller to which the device is connected
+- interrupts : interrupt specifier specific to interrupt controller
+
+Optional properties:
+- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC address
+    to use (from firmware or bootloader)
+- davicom,no-eeprom : Configuration EEPROM is not available
+- davicom,ext-phy : Use external PHY
+- davicom,simple-phy : Use NSR to find LinkStatus
+
+Example:
+
+	ethernet at 18000000 {
+		compatible = "davicom,dm9000";
+		reg = <0x18000000 0x2 0x18000004 0x2>;
+		interrupt-parent = <&gpn>;
+		interrupts = <7 4>;
+		local-mac-address = [00 00 de ad be ef];
+		davicom,no-eeprom;
+	};
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index 6931c43..2fe74e6 100644
@@ -18,6 +18,7 @@ chrp	Common Hardware Reference Platform
 cirrus	Cirrus Logic, Inc.
 cortina	Cortina Systems, Inc.
 dallas	Maxim Integrated Products (formerly Dallas Semiconductor)
+davicom	DAVICOM Semiconductor, Inc.
 denx	Denx Software Engineering
 emmicro	EM Microelectronic
 epson	Seiko Epson Corp.
drivers/net/ethernet/davicom/dm9000.c +60 -0

89 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#1 lore raw

Hi Tomasz,

Quoted 22 lines · Tomasz Figa

This patch adds Device Tree support to dm9000 driver.

---
 .../devicetree/bindings/net/davicom-dm9000.txt     | 27 ++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 drivers/net/ethernet/davicom/dm9000.c              | 60 ++++++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/davicom-dm9000.txt
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +6 -0
new file mode 100644
index 0000000..d2902db
@@ -0,0 +1,27 @@
+Davicom DM9000 Fast Ethernet controller
+
+Required properties:
+- compatible = "davicom,dm9000";
+- reg : physical addresses and sizes of registers, must contain 2 entries:
+    first entry : address register,

Documentation/devicetree/bindings/net/davicom-dm9000.txt line 16

Quoted 10 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +10 -0
+    second entry : address register.
+- interrupt-parent : interrupt controller to which the device is connected
+- interrupts : interrupt specifier specific to interrupt controller
+
+Optional properties:
+- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC address
+    to use (from firmware or bootloader)
+- davicom,no-eeprom : Configuration EEPROM is not available
+- davicom,ext-phy : Use external PHY
+- davicom,simple-phy : Use NSR to find LinkStatus

Do we really need to expose this simple-phy property? Looking at the drvier code this more looks like a work around shortcomings of the driver code rather than something really necessary.

Documentation/devicetree/bindings/net/davicom-dm9000.txt line 26

Quoted 10 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +10 -0
+#ifdef CONFIG_OF
+static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
+{
+	struct dm9000_plat_data *pdata;
+	struct device_node *np = dev->of_node;
+	const void *prop;
+	int len;
+
+	if (!np)
+		return NULL;

You should be able to kill the ifdef around this function by doing

	if (!IS_ENABLED(CONFIG_OF) || !np)
		return NULL;
Quoted 7 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +7 -0
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata) {
+		dev_err(dev, "failed to allocate platform data struct\n");
+		return ERR_PTR(-ENOMEM);
+	}
+

Documentation/devicetree/bindings/net/davicom-dm9000.txt

Quoted 10 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +10 -0
+	if (of_find_property(np, "davicom,ext-phy", NULL))
+		pdata->flags |= DM9000_PLATF_EXT_PHY;
+	if (of_find_property(np, "davicom,no-eeprom", NULL))
+		pdata->flags |= DM9000_PLATF_NO_EEPROM;
+	if (of_find_property(np, "davicom,simple-phy", NULL))
+		pdata->flags |= DM9000_PLATF_SIMPLE_PHY;
+
+	prop = of_get_property(np, "local-mac-address", &len);
+	if (!prop)
+		return pdata;

I think you should use of_get_mac_address() here.

Sascha

Signature · 4 lines
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 |
#2 lore raw

Sascha Hauer <[email protected]> :
[...]

Quoted 13 lines

drivers/net/ethernet/davicom/dm9000.c static const struct net_device_ops dm9000_netdev_ops = { · line 1371

Quoted 10 lines
drivers/net/ethernet/davicom/dm9000.c +10 -0
+#ifdef CONFIG_OF
+static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
+{
+	struct dm9000_plat_data *pdata;
+	struct device_node *np = dev->of_node;
+	const void *prop;
+	int len;
+
+	if (!np)
+		return NULL;

You should be able to kill the ifdef around this function by doing

Quoted 2 lines
	if (!IS_ENABLED(CONFIG_OF) || !np)
		return NULL;

It will be the first such use of IS_ENABLED in net land.

David, is it ok ?

Signature · 1 line
Ueimor
#3 lore raw
In reply to Sascha Hauer

Hi Sascha,

Quoted 33 lines · On Sunday 19 of May 2013 09:05:38 Sascha Hauer wrote:

Hi Tomasz,

Quoted 30 lines · Tomasz Figa

This patch adds Device Tree support to dm9000 driver.

---

 .../devicetree/bindings/net/davicom-dm9000.txt     | 27 ++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 drivers/net/ethernet/davicom/dm9000.c              | 60
 ++++++++++++++++++++++ 3 files changed, 88 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/davicom-dm9000.txt>

(quoted diff) +0 -0

b/Documentation/devicetree/bindings/net/davicom-dm9000.txt new file mode 100644
index 0000000..d2902db

Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +5 -0
@@ -0,0 +1,27 @@
+Davicom DM9000 Fast Ethernet controller
+
+Required properties:
+- compatible = "davicom,dm9000";
+- reg : physical addresses and sizes of registers, must contain 2

entries: + first entry : address register,
+ second entry : address register.
+- interrupt-parent : interrupt controller to which the device is connected +- interrupts : interrupt specifier specific to interrupt controller +
+Optional properties:
+- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC

Quoted 8 lines
Quoted 4 lines

address + to use (from firmware or bootloader)

+- davicom,no-eeprom : Configuration EEPROM is not available
+- davicom,ext-phy : Use external PHY
+- davicom,simple-phy : Use NSR to find LinkStatus

Do we really need to expose this simple-phy property? Looking at the drvier code this more looks like a work around shortcomings of the driver code rather than something really necessary.

Well, depending on this property it can use two different methods of checking carrier status and it seems to depend on hardware, which one should be used. I don't see any driver shortcomings here, but maybe I'm missing something.

Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +4 -0
+#ifdef CONFIG_OF
+static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
+{
+	struct dm9000_plat_data *pdata;
Quoted 8 lines

Documentation/devicetree/bindings/net/davicom-dm9000.txt

Quoted 6 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +6 -0
+	struct device_node *np = dev->of_node;
+	const void *prop;
+	int len;
+
+	if (!np)
+		return NULL;

You should be able to kill the ifdef around this function by doing

Basically this would be a kill with a double-edged sword.

I could completely drop the #ifdef without any additional check, as it is not possible that np is not NULL with !CONFIG_OF, but I decided to keep the code conditional to reduce driver code a bit on platforms that don't need OF.

Maybe this single driver wouldn't give any significant difference, but if you make all the drivers used on the platform this way, you will save some kilobytes.

Quoted 14 lines
	if (!IS_ENABLED(CONFIG_OF) || !np)
		return NULL;
Quoted 11 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +11 -0
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata) {
+		dev_err(dev, "failed to allocate platform data struct\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	if (of_find_property(np, "davicom,ext-phy", NULL))
+		pdata->flags |= DM9000_PLATF_EXT_PHY;
+	if (of_find_property(np, "davicom,no-eeprom", NULL))
+		pdata->flags |= DM9000_PLATF_NO_EEPROM;
Quoted 8 lines

Documentation/devicetree/bindings/net/davicom-dm9000.txt

Quoted 6 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +6 -0
+	if (of_find_property(np, "davicom,simple-phy", NULL))
+		pdata->flags |= DM9000_PLATF_SIMPLE_PHY;
+
+	prop = of_get_property(np, "local-mac-address", &len);
+	if (!prop)
+		return pdata;

I think you should use of_get_mac_address() here.

Oops. Right, this is what I was looking for, but somehow I failed. Will change this in next version. Thanks.

Best regards,
Tomasz

#4 lore raw
Quoted 45 lines · Tomasz Figa

Hi Sascha,

Quoted 33 lines · On Sunday 19 of May 2013 09:05:38 Sascha Hauer wrote:

Hi Tomasz,

Quoted 30 lines · Tomasz Figa

This patch adds Device Tree support to dm9000 driver.

---

 .../devicetree/bindings/net/davicom-dm9000.txt     | 27 ++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 drivers/net/ethernet/davicom/dm9000.c              | 60
 ++++++++++++++++++++++ 3 files changed, 88 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/davicom-dm9000.txt>

(quoted diff) +0 -0

b/Documentation/devicetree/bindings/net/davicom-dm9000.txt new file mode 100644
index 0000000..d2902db

Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +5 -0
@@ -0,0 +1,27 @@
+Davicom DM9000 Fast Ethernet controller
+
+Required properties:
+- compatible = "davicom,dm9000";
+- reg : physical addresses and sizes of registers, must contain 2

entries: + first entry : address register,
+ second entry : address register.
+- interrupt-parent : interrupt controller to which the device is connected +- interrupts : interrupt specifier specific to interrupt controller +
+Optional properties:
+- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC

Quoted 8 lines
Quoted 4 lines

address + to use (from firmware or bootloader)

+- davicom,no-eeprom : Configuration EEPROM is not available
+- davicom,ext-phy : Use external PHY
+- davicom,simple-phy : Use NSR to find LinkStatus

Do we really need to expose this simple-phy property? Looking at the drvier code this more looks like a work around shortcomings of the driver code rather than something really necessary.

Quoted 4 lines

Well, depending on this property it can use two different methods of checking carrier status and it seems to depend on hardware, which one should be used. I don't see any driver shortcomings here, but maybe I'm missing something.

It's not hardware dependent, at least not from the original commit log.

The driver doesn't use mdiobus_register which you normally would do today. If someone ports the driver over to mdiobus we would still have to support this legacy flag as a special case.

Since no mainline user makes use of this flag I suggest to skip it from the devicetree, at least until someone really asks for this specific flag (and has good reasons to use it)

Quoted 14 lines
Quoted 13 lines

Documentation/devicetree/bindings/net/davicom-dm9000.txt

Quoted 11 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +10 -0
+#ifdef CONFIG_OF
+static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
+{
+	struct dm9000_plat_data *pdata;
+	struct device_node *np = dev->of_node;
+	const void *prop;
+	int len;
+
+	if (!np)
+		return NULL;

You should be able to kill the ifdef around this function by doing

Quoted 4 lines

Basically this would be a kill with a double-edged sword.

I could completely drop the #ifdef without any additional check, as it is not possible that np is not NULL with !CONFIG_OF,

Yes, but the compiler doesn't know this.

Quoted 3 lines

but I decided to keep
the code conditional to reduce driver code a bit on platforms that don't need OF.

IS_ENABLED(CONFIG_OF) will expand to 0 without OF and the compiler will through the unused code away. You won't find differences in the binary size.

Sascha

Signature · 4 lines
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 |
#5 lore raw
Quoted 60 lines · On Sunday 19 of May 2013 12:35:44 Sascha Hauer wrote:
Quoted 51 lines · Tomasz Figa

Hi Sascha,

Quoted 39 lines · On Sunday 19 of May 2013 09:05:38 Sascha Hauer wrote:

Hi Tomasz,

Quoted 36 lines · Tomasz Figa

This patch adds Device Tree support to dm9000 driver.

---

 .../devicetree/bindings/net/davicom-dm9000.txt     | 27
 ++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 drivers/net/ethernet/davicom/dm9000.c              | 60
 ++++++++++++++++++++++ 3 files changed, 88 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/net/davicom-dm9000.txt>

diff --git a/Documentation/devicetree/bindings/net/davicom-dm9000.txt b/Documentation/devicetree/bindings/net/davicom-dm9000.txt new file
mode 100644
index 0000000..d2902db

Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +5 -0
@@ -0,0 +1,27 @@
+Davicom DM9000 Fast Ethernet controller
+
+Required properties:
+- compatible = "davicom,dm9000";
+- reg : physical addresses and sizes of registers, must contain 2

entries: + first entry : address register,
+ second entry : address register.
+- interrupt-parent : interrupt controller to which the device is connected +- interrupts : interrupt specifier specific to interrupt
controller +
+Optional properties:
+- local-mac-address : A bytestring of 6 bytes specifying Ethernet MAC

Quoted 8 lines
Quoted 4 lines

address + to use (from firmware or bootloader)

+- davicom,no-eeprom : Configuration EEPROM is not available
+- davicom,ext-phy : Use external PHY
+- davicom,simple-phy : Use NSR to find LinkStatus

Do we really need to expose this simple-phy property? Looking at the drvier code this more looks like a work around shortcomings of the driver code rather than something really necessary.

Quoted 5 lines

Well, depending on this property it can use two different methods of checking carrier status and it seems to depend on hardware, which one should be used. I don't see any driver shortcomings here, but maybe I'm
missing something.

It's not hardware dependent, at least not from the original commit log.

Quoted 7 lines

The driver doesn't use mdiobus_register which you normally would do today. If someone ports the driver over to mdiobus we would still have to support this legacy flag as a special case.

Since no mainline user makes use of this flag I suggest to skip it from the devicetree, at least until someone really asks for this specific flag (and has good reasons to use it)

Well, I don't need this flag on my platform, so I'm not strongly against removing it. If you really don't like it, I will remove it in v2.

Quoted 21 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +2 -0
+#ifdef CONFIG_OF
+static struct dm9000_plat_data *dm9000_parse_dt(struct device

*dev)

Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +2 -0
+{
+	struct dm9000_plat_data *pdata;
Quoted 8 lines

Documentation/devicetree/bindings/net/davicom-dm9000.txt

Quoted 6 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +6 -0
+	struct device_node *np = dev->of_node;
+	const void *prop;
+	int len;
+
+	if (!np)
+		return NULL;

You should be able to kill the ifdef around this function by doing

Quoted 4 lines

Basically this would be a kill with a double-edged sword.

I could completely drop the #ifdef without any additional check, as it is not possible that np is not NULL with !CONFIG_OF,

Yes, but the compiler doesn't know this.

Quoted 7 lines
Quoted 3 lines

but I decided to keep
the code conditional to reduce driver code a bit on platforms that don't need OF.

IS_ENABLED(CONFIG_OF) will expand to 0 without OF and the compiler will through the unused code away. You won't find differences in the binary size.

Hmm, so IS_ENABLED returns a constant, OK. I have never bothered to look that up and ended with a strange belief that it is a runtime check (which doesn't make sense...). Always good to learn something, thanks.

OK, I'm fine with this, will change it in v2.

Best regards,
Tomasz