From patchwork Mon Jun 30 14:41:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 32743 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9A017203F4 for ; Mon, 30 Jun 2014 14:41:39 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id tr6sf53231146ieb.7 for ; Mon, 30 Jun 2014 07:41:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:in-reply-to:user-agent:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-disposition; bh=PvkyOgF0IGnjccdJIjU6pfwlFb/Bj1C2pK/r2Vhr/+8=; b=fsCZmb0qKH9+bEM0iro9/UxyTgxOGGEqYX4duKrFoj7Z3l7KzQQVL2jPxYFJLn333P 95wz/K5D8ION2jN2NOR4VLCNWTk/DxLxkxmWcISIWM1NQzub+x6Cc5Fp1/5Qxbz+acNg JOvSZar/8sBsDip+ulvhIUb5uGFORAYzgTrbfeRiEo8374iVZvL/rr3DlVO7daKquFyG E8DUJ6qgcOoTGY8unAo/enUdGZcZPtM4bUFxp3KPjKDTKFjjMhYkrNsuLwzn61GtSL2a NYq1DI78RW/E+pv9ZjAZXvm47tTSYyucOhGESnGwJVyXrOxUdVOz7W+gWnQ39Hs24Ah1 ZP7w== X-Gm-Message-State: ALoCoQn0oduxELGvf1OvD70MislY0oUw6UFtPfejIpB2GaRTdeEa9ItVbC0/Cti+3XPkASmd1qB+ X-Received: by 10.42.41.1 with SMTP id n1mr19723365ice.6.1404139299004; Mon, 30 Jun 2014 07:41:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.54 with SMTP id b51ls1552137qgf.48.gmail; Mon, 30 Jun 2014 07:41:38 -0700 (PDT) X-Received: by 10.52.75.202 with SMTP id e10mr872349vdw.54.1404139298751; Mon, 30 Jun 2014 07:41:38 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id jc7si10091594vdb.66.2014.06.30.07.41.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 07:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hy4so7608382vcb.20 for ; Mon, 30 Jun 2014 07:41:38 -0700 (PDT) X-Received: by 10.58.182.234 with SMTP id eh10mr1235641vec.41.1404139298648; Mon, 30 Jun 2014 07:41:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp145046vcb; Mon, 30 Jun 2014 07:41:38 -0700 (PDT) X-Received: by 10.66.155.227 with SMTP id vz3mr9719160pab.26.1404139297825; Mon, 30 Jun 2014 07:41:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb9si23416718pbd.51.2014.06.30.07.41.37; Mon, 30 Jun 2014 07:41:37 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753758AbaF3OlZ (ORCPT + 27 others); Mon, 30 Jun 2014 10:41:25 -0400 Received: from mail-ie0-f179.google.com ([209.85.223.179]:43337 "EHLO mail-ie0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753223AbaF3OlU (ORCPT ); Mon, 30 Jun 2014 10:41:20 -0400 Received: by mail-ie0-f179.google.com with SMTP id tr6so6982723ieb.38 for ; Mon, 30 Jun 2014 07:41:20 -0700 (PDT) X-Received: by 10.42.162.71 with SMTP id w7mr36916920icx.50.1404139280142; Mon, 30 Jun 2014 07:41:20 -0700 (PDT) Received: from lee--X1 (host109-148-235-194.range109-148.btcentralplus.com. [109.148.235.194]) by mx.google.com with ESMTPSA id v9sm25388152igd.14.2014.06.30.07.41.18 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 30 Jun 2014 07:41:19 -0700 (PDT) Date: Mon, 30 Jun 2014 15:41:14 +0100 From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kishon@ti.com Cc: kernel@stlinux.com Subject: [PATCH v2 4/5] phy: miphy365x: Represent each PHY channel as a subnode Message-ID: <20140630144114.GB25926@lee--X1> References: <1404133317-25953-1-git-send-email-lee.jones@linaro.org> <1404133317-25953-5-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 In-Reply-To: <1404133317-25953-5-git-send-email-lee.jones@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Content-Disposition: inline phy: miphy365x: Represent each PHY channel as a DT subnode This has the added advantages of being able to enable/disable each of the channels as simply as enabling/disabling the DT node. Suggested-by: Kishon Vijay Abraham I Signed-off-by: Lee Jones --- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/phy/phy-miphy365x.c b/drivers/phy/phy-miphy365x.c index 1109f42..2c4ea6e 100644 --- a/drivers/phy/phy-miphy365x.c +++ b/drivers/phy/phy-miphy365x.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,7 @@ struct miphy365x { void __iomem *pcie; u8 type; u8 port; + bool enabled; }; struct miphy365x_dev { @@ -468,7 +470,7 @@ static struct phy *miphy365x_xlate(struct device *dev, struct miphy365x_dev *state = dev_get_drvdata(dev); u8 port, type; - if (args->count != 2) { + if (args->args_count != 2) { dev_err(dev, "Invalid number of cells in 'phy' property\n"); return ERR_PTR(-EINVAL); } @@ -484,6 +486,11 @@ static struct phy *miphy365x_xlate(struct device *dev, if (WARN_ON(port >= ARRAY_SIZE(ports))) return ERR_PTR(-EINVAL); + if (!state->phys[port].enabled) { + dev_warn(dev, "PHY port %d is disabled\n", port); + return ERR_PTR(-EINVAL); + } + if (type == MIPHY_TYPE_SATA) state->phys[port].base = state->phys[port].sata; else if (type == MIPHY_TYPE_PCIE) @@ -503,38 +510,75 @@ static struct phy_ops miphy365x_ops = { .owner = THIS_MODULE, }; -static int miphy365x_get_base_addr(struct platform_device *pdev, - struct miphy365x_phy *phy, u8 port) +static int miphy365x_get_base_addr_one(struct platform_device *pdev, + struct miphy365x *phy, + struct device_node *child, + int index) { - struct resource *res; - char type[6]; + void __iomem *base; + const char *name; + int ret; - sprintf(type, "sata%d", port); + base = of_iomap(child, index); + if (!base) { + dev_err(&pdev->dev, "Failed to map %s\n", child->full_name); + return -EINVAL; + } - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, type); - if (!res) - return -ENODEV; + ret = of_property_read_string_index(child, "reg-names", index, &name); + if (ret) { + dev_err(&pdev->dev, + "%s: no reg-names property not found\n", child->name); + return ret; + } - phy->sata = devm_ioremap(&pdev->dev, res->start, resource_size(res)); - if (!phy->sata) - return -ENOMEM; + if (!strncmp(name, "sata", 4)) + phy->sata = base; + else if (!strncmp(name, "pcie", 4)) + phy->pcie = base; + else { + dev_err(&pdev->dev, "reg-names in %s not sata or pcie: %s", + child->name, name); + return -EINVAL; + } - sprintf(type, "pcie%d", port); + return 0; +} - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, type); - if (!res) - return -ENODEV; +static int miphy365x_get_base_addr(struct platform_device *pdev, + struct miphy365x *phy, + struct device_node *child) +{ + int index; + int ret; - phy->pcie = devm_ioremap(&pdev->dev, res->start, resource_size(res)); - if (!phy->pcie) - return -ENOMEM; + /* Each port handles SATA or PCIE. */ + for (index = 0; index < 2; index++) { + ret = miphy365x_get_base_addr_one(pdev, phy, + child, index); + if (ret) + return ret; + } return 0; } -static int miphy365x_of_probe(struct device_node *np, +static int miphy365x_of_probe(struct platform_device *pdev, struct miphy365x_dev *phy_dev) { + struct device_node *np = pdev->dev.of_node; + struct device_node *child; + int child_count = 0; + + for_each_child_of_node(np, child) + child_count++; + + if (child_count != ARRAY_SIZE(ports)) { + dev_err(&pdev->dev, "%d ports supported, %d supplied\n", + ARRAY_SIZE(ports), child_count); + return -EINVAL; + } + phy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); if (IS_ERR(phy_dev->regmap)) { dev_err(phy_dev->dev, "No syscfg phandle specified\n"); @@ -556,11 +600,10 @@ static int miphy365x_of_probe(struct device_node *np, static int miphy365x_probe(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node; + struct device_node *child, *np = pdev->dev.of_node; struct miphy365x_dev *phy_dev; struct device *dev = &pdev->dev; struct phy_provider *provider; - u8 port; int ret; if (!np) { @@ -572,7 +615,7 @@ static int miphy365x_probe(struct platform_device *pdev) if (!phy_dev) return -ENOMEM; - ret = miphy365x_of_probe(np, phy_dev); + ret = miphy365x_of_probe(pdev, phy_dev); if (ret) return ret; @@ -582,8 +625,9 @@ static int miphy365x_probe(struct platform_device *pdev) mutex_init(&phy_dev->miphy_mutex); - for (port = 0; port < ARRAY_SIZE(ports); port++) { + for_each_child_of_node(np, child) { struct phy *phy; + static int port = 0; phy = devm_phy_create(dev, &miphy365x_ops, NULL); if (IS_ERR(phy)) { @@ -591,15 +635,17 @@ static int miphy365x_probe(struct platform_device *pdev) return PTR_ERR(phy); } - phy_dev->phys[port].phy = phy; - phy_dev->phys[port].port = port; - - ret = miphy365x_get_base_addr(pdev, - &phy_dev->phys[port], port); + ret = miphy365x_get_base_addr(pdev, &phy_dev->phys[port], + child); if (ret) return ret; + phy_dev->phys[port].phy = phy; + phy_dev->phys[port].port = port; + phy_dev->phys[port].enabled = !!of_device_is_available(child); + phy_set_drvdata(phy, &phy_dev->phys[port]); + port++; } provider = devm_of_phy_provider_register(dev, miphy365x_xlate);