From patchwork Wed Dec 10 15:48:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 5470241 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 843079F444 for ; Wed, 10 Dec 2014 15:53:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89A6D20103 for ; Wed, 10 Dec 2014 15:53:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89FCA200CC for ; Wed, 10 Dec 2014 15:53:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XyjWg-0002Bs-F9; Wed, 10 Dec 2014 15:50:06 +0000 Received: from mailout4.w1.samsung.com ([210.118.77.14]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XyjW0-0000pO-Ty for linux-arm-kernel@lists.infradead.org; Wed, 10 Dec 2014 15:49:28 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NGD001LLISPOOA0@mailout4.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 10 Dec 2014 15:53:14 +0000 (GMT) X-AuditID: cbfec7f5-b7fc86d0000066b7-99-54886b766e39 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 6A.30.26295.67B68845; Wed, 10 Dec 2014 15:49:10 +0000 (GMT) Received: from AMDC1061.digital.local ([106.116.147.88]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NGD00L5CIL48260@eusync1.samsung.com>; Wed, 10 Dec 2014 15:49:10 +0000 (GMT) From: Andrzej Hajda To: linux-kernel@vger.kernel.org (open list) Subject: [RFC 09/15] phy: add restrack support Date: Wed, 10 Dec 2014 16:48:27 +0100 Message-id: <1418226513-14105-10-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1418226513-14105-1-git-send-email-a.hajda@samsung.com> References: <1418226513-14105-1-git-send-email-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsVy+t/xy7pl2R0hBvdOaVvcWneO1eLAi4Us FlMfPmGzmH8EyL3y9T2bxblXj1gsDvzZwWjRvHg9m8Wk+xNYLC487WGz+Halg8liyp/lTBab Hl9jtdg8/w+jxeVdc9gsZpzfx2Rx+zKvxdojd9ktnk64yGbRuvcIu8XPXfNYHEQ9Wpp72Dye bLrI6LFz1l12j02rOtk87lzbw+axf+4ado/73ceZPDYvqffo27KK0eP4je1MHp83yQVwR3HZ pKTmZJalFunbJXBlXJs4l7HgiGrF+2s32RoYr8t3MXJySAiYSKxp7WCHsMUkLtxbz9bFyMUh JLCUUWLxjjksEE4fk8TF9+1MIFVsApoSfzffZAOxRQR0JK73dDODFDELbGCXWDd9H1CCg0NY QE9i+TJHkBoWAVWJiVsusIDYvAIuEr33ZzJBbJOTOHlsMiuIzQkU//t8LyOILSTgLLFk23vW CYy8CxgZVjGKppYmFxQnpeca6RUn5haX5qXrJefnbmKExMbXHYxLj1kdYhTgYFTi4d2h2BYi xJpYVlyZe4hRgoNZSYR3YXJHiBBvSmJlVWpRfnxRaU5q8SFGJg5OqQZGlt3/nP7Xh/SzbhNj 8DKvKunk5GfjctzS6uC8PeBJem5Bdri5xdSzV3lrw4unpoSXWcXvePPNOkzv2mNu5z97eh1X CfPIlQbzs5lnzY2fv26ScNiUKiFXy8MJbpOi879N/OR1T92+uGKpsVnPkY0LFr1ikbFblj31 vfaCqDxvn7x5prNXvVFiKc5INNRiLipOBAC4B2VYawIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141210_074925_150945_BEB97ACE X-CRM114-Status: GOOD ( 13.20 ) X-Spam-Score: -5.0 (-----) Cc: Alexandre Courbot , "moderated list:ARM/S5P EXYNOS AR..." , Mike Turquette , "open list:DRM PANEL DRIVERS" , "open list:GPIO SUBSYSTEM" , Greg Kroah-Hartman , Linus Walleij , Liam Girdwood , Rob Herring , Kishon Vijay Abraham I , Inki Dae , Andrzej Hajda , "open list:OPEN FIRMWARE AND..." , Thierry Reding , boris.brezillon@free-electrons.com, Mark Brown , Grant Likely , Russell King , "moderated list:ARM/CLKDEV SUPPORT" , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP PHYs supports different methods of lookup. The patch adds restrack support only to DT based PHYs. Signed-off-by: Andrzej Hajda --- drivers/phy/phy-core.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 3 ++ include/linux/restrack.h | 1 + 3 files changed, 94 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index ff5eec5..449ec4e 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -22,6 +22,7 @@ #include #include #include +#include static struct class *phy_class; static DEFINE_MUTEX(phy_provider_mutex); @@ -754,6 +755,8 @@ struct phy_provider *__of_phy_provider_register(struct device *dev, list_add_tail(&phy_provider->list, &phy_provider_list); mutex_unlock(&phy_provider_mutex); + restrack_up(RESTRACK_TYPE_PHY, dev->of_node, phy_provider); + return phy_provider; } EXPORT_SYMBOL_GPL(__of_phy_provider_register); @@ -804,6 +807,9 @@ void of_phy_provider_unregister(struct phy_provider *phy_provider) if (IS_ERR(phy_provider)) return; + restrack_down(RESTRACK_TYPE_PHY, phy_provider->dev->of_node, + phy_provider); + mutex_lock(&phy_provider_mutex); list_del(&phy_provider->list); kfree(phy_provider); @@ -828,6 +834,90 @@ void devm_of_phy_provider_unregister(struct device *dev, } EXPORT_SYMBOL_GPL(devm_of_phy_provider_unregister); +int of_get_phy_spec(struct device *dev, const char *name, + struct of_phandle_args *spec) +{ + struct device_node *np = dev->of_node; + int idx; + + idx = of_property_match_string(np, "phy-names", name); + + return of_parse_phandle_with_args(np, "phys", "#phy-cells", idx, spec); +} + +struct phy_restrack_desc { + struct phy **ptr; + const char *name; + struct of_phandle_args spec; + struct restrack_desc desc; +}; + +static int phy_restrack_init(struct device *dev, + struct restrack_desc *desc) +{ + struct phy_restrack_desc *rd = restrack_desc_to_rd(rd, desc); + int ret; + + ret = of_get_phy_spec(dev, rd->name, &rd->spec); + if (!ret) + desc->if_id = rd->spec.np; + return ret; +} + +static void phy_restrack_destroy(struct device *dev, + struct restrack_desc *desc) +{ + struct phy_restrack_desc *rd = restrack_desc_to_rd(rd, desc); + + of_node_put(desc->if_id); + kfree(rd); +} + +static int phy_restrack_ifup(struct device *dev, + struct restrack_desc *desc, void *data) +{ + struct phy_restrack_desc *rd = restrack_desc_to_rd(rd, desc); + struct phy_provider *phy_provider = data; + + *rd->ptr = phy_provider->of_xlate(phy_provider->dev, &rd->spec); + return PTR_ERR_OR_ZERO(*rd->ptr); +} + +static void phy_restrack_ifdown(struct device *dev, + struct restrack_desc *desc, void *data) +{ + struct phy_restrack_desc *rd = restrack_desc_to_rd(rd, desc); + + *rd->ptr = ERR_PTR(-EPROBE_DEFER); +} + +static const struct restrack_ops phy_restrack_ops = { + .if_type = RESTRACK_TYPE_PHY, + .init = phy_restrack_init, + .destroy = phy_restrack_destroy, + .if_up = phy_restrack_ifup, + .if_down = phy_restrack_ifdown, +}; + +/** + * phy_restrack_desc - phy resource descriptor allocator + * @phy: pointer to variable which will be set to phy handle + * @name: name of phy + * + * The function creates resource description for phy, which shall be used + * by *restrack_register functions. + */ +struct restrack_desc *phy_restrack_desc(struct phy **phy, const char *name) +{ + struct phy_restrack_desc *rd; + + RESTRACK_DESC_ALLOC(rd, phy_restrack_ops, phy, name); + + return rd ? &rd->desc : ERR_PTR(-ENOMEM); +} +EXPORT_SYMBOL_GPL(phy_restrack_desc); + + /** * phy_release() - release the phy * @dev: the dev member within phy diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index 8cb6f81..14d176c 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -174,6 +174,9 @@ struct phy_provider *__devm_of_phy_provider_register(struct device *dev, void of_phy_provider_unregister(struct phy_provider *phy_provider); void devm_of_phy_provider_unregister(struct device *dev, struct phy_provider *phy_provider); + +struct restrack_desc; +struct restrack_desc *phy_restrack_desc(struct phy **phy, const char *name); #else static inline int phy_pm_runtime_get(struct phy *phy) { diff --git a/include/linux/restrack.h b/include/linux/restrack.h index 6707dce..411d791 100644 --- a/include/linux/restrack.h +++ b/include/linux/restrack.h @@ -7,6 +7,7 @@ #define RESTRACK_TYPE_REGULATOR 2 #define RESTRACK_TYPE_GPIO 3 #define RESTRACK_TYPE_CLOCK 4 +#define RESTRACK_TYPE_PHY 5 struct device; struct restrack_ctx;