From patchwork Tue Dec 16 16:46:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zubair Lutfullah Kakakhel X-Patchwork-Id: 421996 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A6A671400D2 for ; Wed, 17 Dec 2014 03:46:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751638AbaLPQqv (ORCPT ); Tue, 16 Dec 2014 11:46:51 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:3017 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750918AbaLPQqv (ORCPT ); Tue, 16 Dec 2014 11:46:51 -0500 Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id 4D3AFCE5D5503; Tue, 16 Dec 2014 16:46:46 +0000 (GMT) Received: from LEMAIL01.le.imgtec.org (192.168.152.62) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 16 Dec 2014 16:46:48 +0000 Received: from zkakakhel-linux.le.imgtec.org (192.168.154.89) by LEMAIL01.le.imgtec.org (192.168.152.62) with Microsoft SMTP Server (TLS) id 14.3.210.2; Tue, 16 Dec 2014 16:46:48 +0000 From: Zubair Lutfullah Kakakhel To: CC: , , , , Subject: [PATCH_V2] dm9000: Add regulator and reset support to dm9000 Date: Tue, 16 Dec 2014 16:46:31 +0000 Message-ID: <1418748391-9955-1-git-send-email-Zubair.Kakakhel@imgtec.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [192.168.154.89] Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In boards, the dm9000 chip's power and reset can be controlled by gpio. It makes sense to add them to the dm9000 driver and let dt be used to enable power and reset the phy. Signed-off-by: Zubair Lutfullah Kakakhel Signed-off-by: Paul Burton --- V2. Fixed a small blooper. dev_dgb -> dev_dbg --- .../devicetree/bindings/net/davicom-dm9000.txt | 4 +++ drivers/net/ethernet/davicom/dm9000.c | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Documentation/devicetree/bindings/net/davicom-dm9000.txt b/Documentation/devicetree/bindings/net/davicom-dm9000.txt index 28767ed..dba19a2 100644 --- a/Documentation/devicetree/bindings/net/davicom-dm9000.txt +++ b/Documentation/devicetree/bindings/net/davicom-dm9000.txt @@ -11,6 +11,8 @@ Required properties: Optional properties: - davicom,no-eeprom : Configuration EEPROM is not available - davicom,ext-phy : Use external PHY +- reset-gpio : phandle of gpio that will be used to reset chip during probe +- vcc-supply : phandle of regulator that will be used to enable power to chip Example: @@ -21,4 +23,6 @@ Example: interrupts = <7 4>; local-mac-address = [00 00 de ad be ef]; davicom,no-eeprom; + reset-gpio = <&gpf 12 GPIO_ACTIVE_LOW>; + vcc-supply = <ð0_power>; }; diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c index ef0bb58..97dbeec 100644 --- a/drivers/net/ethernet/davicom/dm9000.c +++ b/drivers/net/ethernet/davicom/dm9000.c @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include #include #include @@ -1426,11 +1429,41 @@ dm9000_probe(struct platform_device *pdev) struct dm9000_plat_data *pdata = dev_get_platdata(&pdev->dev); struct board_info *db; /* Point a board information structure */ struct net_device *ndev; + struct device *dev = &pdev->dev; const unsigned char *mac_src; int ret = 0; int iosize; int i; u32 id_val; + int reset_gpio; + enum of_gpio_flags flags; + struct regulator *power; + + power = devm_regulator_get(dev, "vcc"); + if (IS_ERR(power)) { + dev_dbg(dev, "no regulator provided\n"); + } else if (!regulator_is_enabled(power)) { + ret = regulator_enable(power); + dev_dbg(dev, "regulator enabled\n"); + } + + reset_gpio = of_get_named_gpio_flags(dev->of_node, "reset-gpio", 0, + &flags); + if (gpio_is_valid(reset_gpio)) { + ret = devm_gpio_request_one(dev, reset_gpio, flags, + "dm9000_reset"); + if (ret) { + dev_err(dev, "failed to request reset gpio %d: %d\n", + reset_gpio, ret); + } else { + gpio_direction_output(reset_gpio, 0); + /* According to manual PWRST# Low Period Min 1ms */ + msleep(2); + gpio_direction_output(reset_gpio, 1); + /* Needs 3ms to read eeprom when PWRST is deasserted */ + msleep(4); + } + } if (!pdata) { pdata = dm9000_parse_dt(&pdev->dev);