From patchwork Sat May 18 23:03:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 2589531 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id ED574DF2E5 for ; Sat, 18 May 2013 23:04:07 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UdqAW-0002Zw-4r; Sat, 18 May 2013 23:04:04 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UdqAT-0005Pn-9M; Sat, 18 May 2013 23:04:01 +0000 Received: from mail-ee0-f46.google.com ([74.125.83.46]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UdqAP-0005PK-Pl for linux-arm-kernel@lists.infradead.org; Sat, 18 May 2013 23:03:58 +0000 Received: by mail-ee0-f46.google.com with SMTP id e49so3306216eek.33 for ; Sat, 18 May 2013 16:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=WVXSJ7h/qO2Y6zs8+HeQAIsP5HiH9Tx9dum8Qn5wxz0=; b=mnabPHPZYlu3i+Nv673HV6TCQx1aUckDFCWeWrifk5dXkDTmrqPmEQQH5qTtIYHUQo 9Al7GP0oK6XI4ds9Nu06eKkpX3XtOgD31CDUGsOw/iMalERCCgKj3KBi2/p8Oxs5T8J0 b7wwaLqngUGeIYcimpxiNvUKiPNbgnQ8qE/njk/3N0tX/eR6QmKe4fF51sufqk9nEE1n ogl5FXxHWtKfVADqbB9Ll1IX9zuPy6VYBIRTqCFWn/eMEo5yXG/l+chbmeF/XZT3Cxa1 9R7NYhM3aJ9jVeUFTwHxJpcSeZIM9uQ3VYJ0ltN7BT617HGJy4gfRwcomfGvk6WhnRIl Xtbw== X-Received: by 10.15.107.77 with SMTP id ca53mr18912052eeb.40.1368918215862; Sat, 18 May 2013 16:03:35 -0700 (PDT) Received: from flatron.tomeq (87-207-52-162.dynamic.chello.pl. [87.207.52.162]) by mx.google.com with ESMTPSA id w52sm28266805eev.12.2013.05.18.16.03.33 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 18 May 2013 16:03:34 -0700 (PDT) From: Tomasz Figa To: netdev@vger.kernel.org Subject: [PATCH] net: dm9000: Allow instantiation using device tree Date: Sun, 19 May 2013 01:03:14 +0200 Message-Id: <1368918194-24030-1-git-send-email-tomasz.figa@gmail.com> X-Mailer: git-send-email 1.8.2.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130518_190357_976142_BF702DE7 X-CRM114-Status: GOOD ( 17.93 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (tomasz.figa[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.83.46 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: devicetree-discuss@lists.ozlabs.org, Tomasz Figa , Rob Herring , Grant Likely , s.hauer@pengutronix.de, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch adds Device Tree support to dm9000 driver. Signed-off-by: Tomasz Figa --- .../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 --- /dev/null +++ b/Documentation/devicetree/bindings/net/davicom-dm9000.txt @@ -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@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; + }; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 6931c43..2fe74e6 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -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. diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c index 9105465..6c91708 100644 --- a/drivers/net/ethernet/davicom/dm9000.c +++ b/drivers/net/ethernet/davicom/dm9000.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1358,6 +1359,50 @@ static const struct net_device_ops dm9000_netdev_ops = { #endif }; +#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; + + 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; + 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; + + if (len < sizeof(pdata->dev_addr)) { + dev_err(dev, "invalid length of local-mac-address property\n"); + return ERR_PTR(-EINVAL); + } + + memcpy(pdata->dev_addr, prop, sizeof(pdata->dev_addr)); + + return pdata; +} +#else +static struct dm9000_plat_data *dm9000_parse_dt(struct device *unused) +{ + return NULL; +} +#endif + /* * Search DM9000 board, allocate space and register it */ @@ -1373,6 +1418,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); + } + /* Init network device */ ndev = alloc_etherdev(sizeof(struct board_info)); if (!ndev) @@ -1683,11 +1734,20 @@ dm9000_drv_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id dm9000_of_matches[] = { + { .compatible = "davicom,dm9000", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, dm9000_of_matches); +#endif + static struct platform_driver dm9000_driver = { .driver = { .name = "dm9000", .owner = THIS_MODULE, .pm = &dm9000_drv_pm_ops, + .of_match_table = of_match_ptr(dm9000_of_matches), }, .probe = dm9000_probe, .remove = dm9000_drv_remove,