From patchwork Fri May 24 16:20:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 165135 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3807056ili; Fri, 24 May 2019 09:21:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEvcdLD9xbcokWwld4tX3u59RG00jyqDTiIdYd94ZuTsSaYsvfNMq7p9HQOVxQosEG4o5G X-Received: by 2002:a62:d286:: with SMTP id c128mr114277833pfg.159.1558714872787; Fri, 24 May 2019 09:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558714872; cv=none; d=google.com; s=arc-20160816; b=srVVhZJdVRNw3qC41XctgbiaETW5yA7Z91JD0tmocQuFZ4ol86OV4Jd6ocvscydlUx 4SdanYzMWLu8+U1BFASrdW/luReCKwuIwu1U0ZMGY55DjdIdB7AReqMS6nLK+RPPkZan xFMd8g/khKPirAP2CTwePNJI3AYgb1h9zhIWwLOeO9QRT9fAXYwulOrK5tfIdAY7zk3y IUmMQph8eByVlMhCJ96yPPyyiGpYbdil8n3twkCQw1xdMb0cHZAZALMxBe+gG2P8jjfF iffVfSoEQHF285BViDwZBCdPe+b+dVdIWHpGv5XL/nQQ3n8vm+8wqv0IQzpua1gar9tZ MIhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eTEsCb23TLeixRMcycF5JVraveYSjIoqfPZsqxuqIKU=; b=V8V9OhuJyk0pUn7kmJqonQnqPjYu2FwHEfOvjgNNbpXCIdZ2CPIi1eYV6PNjkuyF18 INRAte547qSuhyFvwuZqU+q0ZmplqH637VGbufkEM4nPsNuz6yMUwOqdvq+gZkf5KYgO x+bo7YOu4+z+jLsmkH2V7+I89OpsU4yKM6tarkawsd/qukPu6OBimv1Pf7I3rnqeaxCD Ovz60sqJyRHHe5FuB3qF8u8d51e5VUskL4rAZyw0hnDf3fe52H3o3ya+PZZu41zAJyqR 30A2sJIHYHEj0XTJp22IyKYKk6ACGmP4wywe6HEaTQWEmYEDb2RdnHn4vA3eD1q3W/c2 1now== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GLxaiBAd; 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 m14si5204608pgj.377.2019.05.24.09.21.12; Fri, 24 May 2019 09:21:12 -0700 (PDT) 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=GLxaiBAd; 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 S2391014AbfEXQVL (ORCPT + 9 others); Fri, 24 May 2019 12:21:11 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:44513 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390308AbfEXQVL (ORCPT ); Fri, 24 May 2019 12:21:11 -0400 Received: by mail-lf1-f68.google.com with SMTP id n134so7566276lfn.11 for ; Fri, 24 May 2019 09:21:09 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=eTEsCb23TLeixRMcycF5JVraveYSjIoqfPZsqxuqIKU=; b=GLxaiBAdC5vmdEh/Nwlo5dRur66uY3HBkEyNriBkuevfdORykw6ng1WzHXj0AggSi4 +LSbOuVLeEEw6BNJAR12M8viisLPxMt+Ma6wMRvQFrfq9YRxlMw+qVEJervS/4UZEZkn hB3PoG9kEcmbqnhR2v9v13DPveEqqUJK5UryNHxZeCxV0/dlFLe+DzIZ2Q0ljgFbkABF qP7x2iEjE67e5+LfTNw6jhxVaWGfx9qkxcCkWEBSnTB8uhgfoOpEFWSLoHc5VmoFELve qjjLxSyIfiAs9sz/fEinszjSiHIdRDxA7lsAITygdnYfeTghNQJdTX/iPbq6gIn4bHiK 982A== 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:mime-version:content-transfer-encoding; bh=eTEsCb23TLeixRMcycF5JVraveYSjIoqfPZsqxuqIKU=; b=Ydh2xqpOjpZhMPmq/4LIf87mfnf3Nt9ejai1objluutiSodaaWN9qJN+94X2MI+V8Z JJMrnxLW0BgyfBKrbA/XtOfIB/lIiX5oxB6e2NA6j+5wxSIIdL5w5qrJz9MtDjxd+/Bl wB5e3QO/XLlNihbiAUeaYkPeaHYFl7YP0IQLNKRAXmtvXfqYA3e3Bj5ukRn8nkd2TOmc aaAxe2jtiwFS4yLtCzSSNq6AonHODlcxGiKZNCSK+nyvdMiM1wJso02OKWAYhPlxzU4+ wX9VC/56QFAVgpa+LkO6GOWWldkpejmtWOZj1iIj1blFIZb/ye67AEE5qsse2anhhYDS XCpQ== X-Gm-Message-State: APjAAAWRuSj2/Q7x2KQteSkfH+mvFA/LtyMiXsgHYqrvFkeJWcoqCClC OVUXDbdTej+7J/Z8uA5TVq9OgYaz1pI= X-Received: by 2002:a19:521a:: with SMTP id m26mr4815219lfb.134.1558714868390; Fri, 24 May 2019 09:21:08 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id y4sm618075lje.24.2019.05.24.09.21.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 May 2019 09:21:07 -0700 (PDT) From: Linus Walleij To: netdev@vger.kernel.org, "David S . Miller" Cc: Krzysztof Halasa , Linus Walleij Subject: [PATCH 8/8] net: ethernet: ixp4xx: Support device tree probing Date: Fri, 24 May 2019 18:20:23 +0200 Message-Id: <20190524162023.9115-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190524162023.9115-1-linus.walleij@linaro.org> References: <20190524162023.9115-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This adds device tree probing to the IXP4xx ethernet driver. We need to drop the memory region request as part of this since the OF core will request the memory for the device. Signed-off-by: Linus Walleij --- drivers/net/ethernet/xscale/ixp4xx_eth.c | 80 +++++++++++++++++++----- 1 file changed, 66 insertions(+), 14 deletions(-) -- 2.20.1 diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c index 8b883563a3d3..65fdc82d45a4 100644 --- a/drivers/net/ethernet/xscale/ixp4xx_eth.c +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c @@ -167,7 +167,6 @@ struct eth_regs { }; struct port { - struct resource *mem_res; struct eth_regs __iomem *regs; struct npe *npe; struct net_device *netdev; @@ -1367,19 +1366,72 @@ static const struct net_device_ops ixp4xx_netdev_ops = { .ndo_validate_addr = eth_validate_addr, }; +#ifdef CONFIG_OF +static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct of_phandle_args queue_spec; + struct eth_plat_info *plat; + u32 val; + int ret; + + plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + if (!plat) + return NULL; + + /* FIXME: get from MDIO handle */ + ret = of_property_read_u32(np, "phy", &val); + if (ret) { + dev_err(dev, "no phy\n"); + return NULL; + } + plat->phy = val; + + /* Get the rx queue as a resource from queue manager */ + ret = of_parse_phandle_with_fixed_args(np, "queue-rx", 1, 0, + &queue_spec); + if (ret) { + dev_err(dev, "no rx queue phandle\n"); + return NULL; + } + plat->rxq = queue_spec.args[0]; + + /* Get the txready queue as resource from queue manager */ + ret = of_parse_phandle_with_fixed_args(np, "queue-txready", 1, 0, + &queue_spec); + if (ret) { + dev_err(dev, "no txready queue phandle\n"); + return NULL; + } + plat->txreadyq = queue_spec.args[0]; + + return plat; +} +#else +static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev) +{ + return NULL; +} +#endif + static int ixp4xx_eth_probe(struct platform_device *pdev) { char phy_id[MII_BUS_ID_SIZE + 3]; struct phy_device *phydev = NULL; struct device *dev = &pdev->dev; struct eth_plat_info *plat; - resource_size_t regs_phys; struct net_device *ndev; struct resource *res; struct port *port; int err; - plat = dev_get_platdata(dev); + if (dev->of_node) + plat = ixp4xx_of_get_platdata(dev); + else + plat = dev_get_platdata(dev); + + if (!plat) + return -ENODEV; if (!(ndev = devm_alloc_etherdev(dev, sizeof(struct port)))) return -ENOMEM; @@ -1392,7 +1444,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) return -ENODEV; - regs_phys = res->start; port->regs = devm_ioremap_resource(dev, res); switch (res->start) { @@ -1450,12 +1501,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev) if (!(port->npe = npe_request(NPE_ID(port->id)))) return -EIO; - port->mem_res = request_mem_region(regs_phys, REGS_SIZE, ndev->name); - if (!port->mem_res) { - err = -EBUSY; - goto err_npe_rel; - } - port->plat = plat; npe_port_tab[NPE_ID(port->id)] = port; memcpy(ndev->dev_addr, plat->hwaddr, ETH_ALEN); @@ -1491,8 +1536,6 @@ static int ixp4xx_eth_probe(struct platform_device *pdev) phy_disconnect(phydev); err_free_mem: npe_port_tab[NPE_ID(port->id)] = NULL; - release_resource(port->mem_res); -err_npe_rel: npe_release(port->npe); return err; } @@ -1508,12 +1551,21 @@ static int ixp4xx_eth_remove(struct platform_device *pdev) ixp4xx_mdio_remove(); npe_port_tab[NPE_ID(port->id)] = NULL; npe_release(port->npe); - release_resource(port->mem_res); return 0; } +static const struct of_device_id ixp4xx_eth_of_match[] = { + { + .compatible = "intel,ixp4xx-ethernet", + }, + { }, +}; + static struct platform_driver ixp4xx_eth_driver = { - .driver.name = DRV_NAME, + .driver = { + .name = DRV_NAME, + .of_match_table = of_match_ptr(ixp4xx_eth_of_match), + }, .probe = ixp4xx_eth_probe, .remove = ixp4xx_eth_remove, };