net: dm9000: Allow instantiation using device tree
Subsystems (3)
PATCH v2 1/1 net: dm9000: Allow instantiation using device tree
This patch adds Device Tree support to dm9000 driver.
---
Changes since v1:
- dropped davicom,simple-phy property as it seems to be of no use
- used of_get_mac_address() to get MAC address from device tree
- replaced #ifdef CONFIG_OF around dm9000_parse_dt() with IS_ENABLED
.../devicetree/bindings/net/davicom-dm9000.txt | 26 +++++++++++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + drivers/net/ethernet/davicom/dm9000.c | 44 ++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/davicom-dm9000.txt
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +26 -0
@@ -0,0 +1,26 @@ +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 + +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
@@ -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 +44 -0
73 lines not on this page · raw message
Signature · 1 line
1.8.2.1
Hi,
Documentation/devicetree/bindings/net/davicom-dm9000.txt line 7
Quoted 9 lines · Tomasz Figa
+++
b/Documentation/devicetree/bindings/net/davicom-dm9000.txtDocumentation/devicetree/bindings/net/davicom-dm9000.txt new file +7
-0@@ -0,0 +1,26 @@ +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.
Two address registers ? Shouldn't one of these be "data register" ?
Quoted 9 lines
(quoted diff) +9
-0+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;
Review
Quoted 10 lines
(quoted diff) +9
-0+ }; +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 *mac_addr; + + if (!IS_ENABLED(CONFIG_OF) || !np) + return NULL;
Shouldn't ERR_PTR() value be returned here ?
drivers/net/ethernet/davicom/dm9000.c static const struct net_device_ops dm9000_netdev_ops = { · line 1374
Quoted 3 lines
drivers/net/ethernet/davicom/dm9000.c +3
-0+ pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); +if (!pdata) { +dev_err (dev,"failed to allocate platform data struct\n" );
There is no need for this error log, k*alloc already logs any failures.
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1409
Quoted 9 lines
drivers/net/ethernet/davicom/dm9000.c +5
-0@@ -1373,6 +1402,12 @@ dm9000_probe(struct platform_device *pdev)int i;u32 id_val; +if (!pdata) { + pdata =dm9000_parse_dt (&pdev->dev); +if (IS_ERR (pdata)) +return PTR_ERR (pdata); + }
Thanks,
Sylwester
Hi Sylwester,
Quoted 14 lines · On Sunday 19 of May 2013 15:27:53 Sylwester Nawrocki wrote:
Hi,
Quoted 9 lines · Tomasz Figa
+++
b/Documentation/devicetree/bindings/net/davicom-dm9000.txtDocumentation/devicetree/bindings/net/davicom-dm9000.txt new file +5
-0@@ -0,0 +1,26 @@ +Davicom DM9000 Fast Ethernet controller + +Required properties: +- compatible = "davicom,dm9000"; +- reg : physical addresses and sizes of registers, must contain 2entries: + first entry : address register,
+ second entry : address register.Two address registers ? Shouldn't one of these be "data register" ?
Oops. I thought I already corrected this typo. Thanks.
Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/net/davicom-dm9000.txt new file +10
-0+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; + };
Quoted 10 lines
drivers/net/ethernet/davicom/dm9000.c static const struct net_device_ops dm9000_netdev_ops = { · line 1370
Quoted 8 lines
drivers/net/ethernet/davicom/dm9000.c +8
-0+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 *mac_addr; + +if (!IS_ENABLED (CONFIG_OF ) || !np) +return NULL ;Shouldn't
ERR_PTR()value be returned here ?
Nope. No platform data is a valid case, so no error here.
Quoted 5 lines
drivers/net/ethernet/davicom/dm9000.c static const struct net_device_ops dm9000_netdev_ops = { · line 1374
Quoted 3 lines
drivers/net/ethernet/davicom/dm9000.c +3
-0+ pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); +if (!pdata) { +dev_err (dev,"failed to allocate platform data struct\n" );There is no need for this error log, k*alloc already logs any failures.
Hmm. Does it print what allocation exactly failed? (e.g. a backtrace)
Not that it would give anything that could help you in an out of memory condition like this, but in general it's good to know in what point the failure happened.
Best regards,
Tomasz
Quoted 14 lines
drivers/net/ethernet/davicom/dm9000.c dm9000_probe(struct platform_device *pdev) · line 1410
Quoted 10 lines
drivers/net/ethernet/davicom/dm9000.c +5
-0@@ -1373,6 +1402,12 @@ dm9000_probe(struct platform_device *pdev)int i;u32 id_val; +if (!pdata) { + pdata =dm9000_parse_dt (&pdev->dev); +if (IS_ERR (pdata)) +return PTR_ERR (pdata); + }Thanks,
Sylwester
Quoted 9 lines · Tomasz Figa
Quoted 9 lines
Quoted 9 lines
+static struct
dm9000_plat_data*dm9000_parse_dt(struct device *dev)Quoted 7 lines
Quoted 7 lines
+{
+ structdm9000_plat_data*pdata;
+ structdevice_node*np =dev->of_node;
+ const void*mac_addr;
+
+ if (!IS_ENABLED(CONFIG_OF) || !np)
+ return NULL;
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Shouldn't
ERR_PTR()value be returned here ?Nope. No platform data is a valid case, so no error here.
OK, sorry, I should have checked that.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
+ pdata =
devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata) {
+dev_err(dev, "failed to allocate platform data struct\n");There is no need for this error log, k*alloc already logs any failures.
Hmm. Does it print what allocation exactly failed? (e.g. a backtrace)
It seems the caller tracking is supported in subset of the kernel configurations.
Quoted 3 lines
Not that it would give anything that could help you in an out of memory condition like this, but in general it's good to know in what point the failure happened.
As long as it is ENOMEM and the driver core reports failed probe I wouldn't really care. Nevertheless I saw patch series removing such already existing "Not enough memory" kind of error logs from the kernel, pointing out that mm already provides relevant error logging.
Thanks,
Sylwester