From patchwork Sun Feb 25 12:51:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 129520 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2580737lja; Sun, 25 Feb 2018 04:54:12 -0800 (PST) X-Google-Smtp-Source: AH8x224a5l6jpSfNYrm43MMAnO9VmDIdjyfB4SB4LtLDy9XKQgGha3Vm2LeezYnon97ixYR3NphQ X-Received: by 10.98.68.26 with SMTP id r26mr7424316pfa.231.1519563252859; Sun, 25 Feb 2018 04:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519563252; cv=none; d=google.com; s=arc-20160816; b=waFaRWt6irVMDLG0S/zxybNGHYzF/xCsKBdsp8cjPA6JXop2FFpsn0/6u7tkq9v3Ly 3vD/kH2Z70R4qf90hqOWO0lvULqUt0bUy0Q77JWeAlE3qnela+lrXR949IpDaFdkKIIW DTzVqEHgMUaWR1kYYn7hJHOQd5/mH3mTpkgQlg+e9KiED+KseW02+q9mhA6l32DlPeO4 l7S3iP9Obc+YiTUXUaUEIuSvdpBSjwjAu4pcZEMn0DlDyhdP96FvaAxIz6eTf2Rtdc4l 6mgSXmY2Piy54wyROIIA2myY1Jo2U4ZxSDrUBaj1FRkbz/kjnOJsk/MOlzBOO1sh+WvV g1ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=5NWpbaJZNfkvovM/6EoOL5lO72kWKJcjmS5LCc37VG4=; b=R5OHAaMCAxQtKcxND9ZBM3i4lQHNbiOnXmYyIa2fJTPgVJVGnjZ1NLkyPXfD/mDdo3 n0FjxlP11mCnaFxQrc4Yv/zA9HaxnGrnBkwop1j2D9/hLLWhdLM2piTshjlvpXAB75qu nxUABAgU+cR+mjEbQ8ZlQGy3oW7+i3tfOQccObGBv1RZlvGd9fe/q+Fz3x9NHqlinT7o o0dLKPoTJvU0CMrUsw0mXObU4l58EhO48ET94+7R1fBRom09Z4BbmwQrYVCacvt3L6+1 40IqP5gEBCiF3NsUDTJ2sIDpgSWfqq8ieptS2Ir3vsa6kTFWTluT4UW1nKb9ST+m3VQD xxJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W6RlWtL8; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l77si5131892pfk.210.2018.02.25.04.54.12; Sun, 25 Feb 2018 04:54:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W6RlWtL8; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751784AbeBYMyK (ORCPT + 8 others); Sun, 25 Feb 2018 07:54:10 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:46160 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751722AbeBYMyC (ORCPT ); Sun, 25 Feb 2018 07:54:02 -0500 Received: by mail-lf0-f65.google.com with SMTP id r80so18426022lfe.13 for ; Sun, 25 Feb 2018 04:54:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5NWpbaJZNfkvovM/6EoOL5lO72kWKJcjmS5LCc37VG4=; b=W6RlWtL85nHDSCgATwFAiG/038n7vr2+K72p4evU5H/UYc9Bu1mq4N2WUP9xPIr1+B ++Vcyejjuw8Gh+Hn7qiUgzB/TB8BWGOawHtbfLDb0OZCU9W0VKfMV5xGXMRRWhQbO7RS vt2NEHPBfO35AGi0XPIgURlj+ufRp7FzJtykI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5NWpbaJZNfkvovM/6EoOL5lO72kWKJcjmS5LCc37VG4=; b=qNcqPieq28XUxdQXeV5OowzRFTEqkBRF+G0xp2L75bhpYJAyLLGo0ObqQy6x3N3rPB QojBXcU6hC3f3ogJME88t6NEY2wq3Ve+De/rJyPGAJ5FxeDOmPup2PIZSKzQv3RUuWzd 0lpGvBgGlTO3FcCkogyxPzxdw/ohQO8tl6A3BqJMHiZoqHRSQerMYwf/DiFkPt1dXse4 LfETaowlJ8GgzwJ5yM8TRHiUfWMubueaAg+vXyG/R6eroTCrJ8ZUtHugeHRQPviiV5uj t2iDWLAxnAJCeC5ZRw5UTo0l8FojxNVdjxNbQBt4RQylB2Nl6HC7hnF2cExZJThr79j6 wDPw== X-Gm-Message-State: APf1xPDWvuPPpvaqjllACDfzv5i2GnjTDPJlm/uH3zzIZ+O015+S9/Gy GOZEfhb1oJLaRyDieBCzPRKpYg== X-Received: by 10.46.73.81 with SMTP id b17mr5169162ljd.144.1519563240827; Sun, 25 Feb 2018 04:54:00 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id 5sm1456574lfp.17.2018.02.25.04.53.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 25 Feb 2018 04:54:00 -0800 (PST) From: Linus Walleij To: Andrew Lunn , Florian Fainelli , "David S . Miller" Cc: netdev@vger.kernel.org, Laurent Pinchart , Linus Walleij Subject: [PATCH net-next 4/5] net: mdio-gpio: Merge platform data into state Date: Sun, 25 Feb 2018 13:51:31 +0100 Message-Id: <20180225125132.25275-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180225125132.25275-1-linus.walleij@linaro.org> References: <20180225125132.25275-1-linus.walleij@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is no instantiation without DT data, we can now move to a single state container and merge the DT property retrieveal into mdio_gpio_bus_init(). We decomission the phy_mask, phy_ignore_ta_mask and irqs array and the reset() callback that were all just sitting unused and taking up space. If bitbanged GPIOs need to set up reset() callbacks these should be done in the device tree using proper bindings. If bitbanged GPIOs need to handle IRQs, these should be done in the device tree using the proper bindings. Signed-off-by: Linus Walleij --- drivers/net/phy/mdio-gpio.c | 130 ++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 82 deletions(-) -- 2.14.3 diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c index 96c953d086c6..9146077b5278 100644 --- a/drivers/net/phy/mdio-gpio.c +++ b/drivers/net/phy/mdio-gpio.c @@ -30,61 +30,11 @@ #include #include -struct mdio_gpio_platform_data { - /* GPIO numbers for bus pins */ - unsigned int mdc; - unsigned int mdio; - unsigned int mdo; - - bool mdc_active_low; - bool mdio_active_low; - bool mdo_active_low; - - u32 phy_mask; - u32 phy_ignore_ta_mask; - int irqs[PHY_MAX_ADDR]; - /* reset callback */ - int (*reset)(struct mii_bus *bus); -}; - struct mdio_gpio_info { struct mdiobb_ctrl ctrl; struct gpio_desc *mdc, *mdio, *mdo; }; -static void *mdio_gpio_of_get_data(struct device *dev) -{ - struct device_node *np = dev->of_node; - struct mdio_gpio_platform_data *pdata; - enum of_gpio_flags flags; - int ret; - - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) - return NULL; - - ret = of_get_gpio_flags(np, 0, &flags); - if (ret < 0) - return NULL; - - pdata->mdc = ret; - pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW; - - ret = of_get_gpio_flags(np, 1, &flags); - if (ret < 0) - return NULL; - pdata->mdio = ret; - pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW; - - ret = of_get_gpio_flags(np, 2, &flags); - if (ret > 0) { - pdata->mdo = ret; - pdata->mdo_active_low = flags & OF_GPIO_ACTIVE_LOW; - } - - return pdata; -} - static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir) { struct mdio_gpio_info *bitbang = @@ -142,31 +92,60 @@ static const struct mdiobb_ops mdio_gpio_ops = { }; static struct mii_bus *mdio_gpio_bus_init(struct device *dev, - struct mdio_gpio_info *bitbang, - struct mdio_gpio_platform_data *pdata, - int bus_id) + struct mdio_gpio_info *bitbang) { - struct mii_bus *new_bus; - int i; - int mdc, mdio, mdo; + unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH; unsigned long mdc_flags = GPIOF_OUT_INIT_LOW; unsigned long mdio_flags = GPIOF_DIR_IN; - unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH; + struct device_node *np = dev->of_node; + enum of_gpio_flags flags; + struct mii_bus *new_bus; + bool mdio_active_low; + bool mdc_active_low; + bool mdo_active_low; + unsigned int mdio; + unsigned int mdc; + unsigned int mdo; + int bus_id; + int ret, i; + + ret = of_get_gpio_flags(np, 0, &flags); + if (ret < 0) + return NULL; + + mdc = ret; + mdc_active_low = flags & OF_GPIO_ACTIVE_LOW; + + ret = of_get_gpio_flags(np, 1, &flags); + if (ret < 0) + return NULL; + mdio = ret; + mdio_active_low = flags & OF_GPIO_ACTIVE_LOW; + + ret = of_get_gpio_flags(np, 2, &flags); + if (ret > 0) { + mdo = ret; + mdo_active_low = flags & OF_GPIO_ACTIVE_LOW; + } else { + mdo = 0; + } + + bus_id = of_alias_get_id(np, "mdio-gpio"); + if (bus_id < 0) { + dev_warn(dev, "failed to get alias id\n"); + bus_id = 0; + } bitbang->ctrl.ops = &mdio_gpio_ops; - bitbang->ctrl.reset = pdata->reset; - mdc = pdata->mdc; bitbang->mdc = gpio_to_desc(mdc); - if (pdata->mdc_active_low) + if (mdc_active_low) mdc_flags = GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW; - mdio = pdata->mdio; bitbang->mdio = gpio_to_desc(mdio); - if (pdata->mdio_active_low) + if (mdio_active_low) mdio_flags |= GPIOF_ACTIVE_LOW; - mdo = pdata->mdo; if (mdo) { bitbang->mdo = gpio_to_desc(mdo); - if (pdata->mdo_active_low) + if (mdo_active_low) mdo_flags = GPIOF_OUT_INIT_LOW | GPIOF_ACTIVE_LOW; } @@ -175,10 +154,6 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev, goto out; new_bus->name = "GPIO Bitbanged MDIO", - - new_bus->phy_mask = pdata->phy_mask; - new_bus->phy_ignore_ta_mask = pdata->phy_ignore_ta_mask; - memcpy(new_bus->irq, pdata->irqs, sizeof(new_bus->irq)); new_bus->parent = dev; if (new_bus->phy_mask == ~0) @@ -229,31 +204,22 @@ static void mdio_gpio_bus_destroy(struct device *dev) static int mdio_gpio_probe(struct platform_device *pdev) { - struct mdio_gpio_platform_data *pdata; struct device *dev = &pdev->dev; struct mdio_gpio_info *bitbang; struct mii_bus *new_bus; - int ret, bus_id; + struct device_node *np; + int ret; + np = dev->of_node; bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL); if (!bitbang) return -ENOMEM; - pdata = mdio_gpio_of_get_data(dev); - bus_id = of_alias_get_id(dev->of_node, "mdio-gpio"); - if (bus_id < 0) { - dev_warn(dev, "failed to get alias id\n"); - bus_id = 0; - } - - if (!pdata) - return -ENODEV; - - new_bus = mdio_gpio_bus_init(dev, bitbang, pdata, bus_id); + new_bus = mdio_gpio_bus_init(dev, bitbang); if (!new_bus) return -ENODEV; - ret = of_mdiobus_register(new_bus, dev->of_node); + ret = of_mdiobus_register(new_bus, np); if (ret) mdio_gpio_bus_deinit(dev);