From patchwork Wed Jun 1 08:02:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 9146293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64C5B60751 for ; Wed, 1 Jun 2016 08:08:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 542FE22473 for ; Wed, 1 Jun 2016 08:08:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C142679B; Wed, 1 Jun 2016 08:08:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5240422473 for ; Wed, 1 Jun 2016 08:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757586AbcFAIDH (ORCPT ); Wed, 1 Jun 2016 04:03:07 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:26276 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757476AbcFAIC4 (ORCPT ); Wed, 1 Jun 2016 04:02:56 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8300BOD2CQL060@mailout2.w1.samsung.com>; Wed, 01 Jun 2016 09:02:50 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-56-574e96a9e0e9 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 5F.AB.05254.9A69E475; Wed, 1 Jun 2016 09:02:49 +0100 (BST) Received: from AMDC2174.DIGITAL.local ([106.120.53.17]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O830012K2CGIS90@eusync3.samsung.com>; Wed, 01 Jun 2016 09:02:49 +0100 (BST) From: Krzysztof Kozlowski To: hzpeterchen@gmail.com, Ulf Hansson , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Krzysztof Kozlowski , Javier Martinez Canillas , linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pm@vger.kernel.or, Alan Stern , linux-usb@vger.kernel.org, Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Kukjin Kim , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz Subject: [PATCH v3 07/12] power: pwrseq: Add support for USB hubs with external power Date: Wed, 01 Jun 2016 10:02:16 +0200 Message-id: <1464768141-25420-8-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1464768141-25420-1-git-send-email-k.kozlowski@samsung.com> References: <1464768141-25420-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeLIzCtJLcpLzFFi42I5/e/4Vd2V0/zCDRact7HYOGM9q8WkJ++Z LeYfOcdqMXHlZGaL/jcLWS2aF69ns+i6uonN4tyrlYwWb96uYbJ4/cLQov/xa2aLTY+vsVpc 3jWHzeLI/35Gi5kXV7NYzDi/j8li0bJWZoul1y8yWUyYvpbFonXvEXaL07tLLCb8vsBmcXxt uIO4x5p5axg9Lvf1MnnsnHWX3WPl8i9sHptXaHlsWtXJ5nHn2h42j/1z17B7bF5S77GlH6hg 9t0fjB59W1Yxehz5Op3F4/MmuQC+KC6blNSczLLUIn27BK6MjuYfbAVbZSoWXV3O1sB4QryL kZNDQsBE4seSKUwQtpjEhXvr2boYuTiEBJYySmydc4oVwmlkkuh++IAZpIpNwFhi8/IlYFUi Ah1sEpu2vmEHSTALZEucuveeFcQWFgiXmLH1PVgDi4CqxOXG1WA1vALuEh+27WeEWCcncfLY ZLB6TgEPiRMT/oPFhYBqGqdNZp3AyLuAkWEVo2hqaXJBcVJ6rqFecWJucWleul5yfu4mRkgk fdnBuPiY1SFGAQ5GJR5ehYu+4UKsiWXFlbmHGCU4mJVEeAUn+4UL8aYkVlalFuXHF5XmpBYf YpTmYFES5527632IkEB6YklqdmpqQWoRTJaJg1OqgXEZ99GTKStecu/9ybbDV8qKm789W7tj +3LxmY8XaE9M4Liam+L8ILCtaK57WKG3wYG+415WF8Wmh6gZdH+4M0P2LNvWO6nsh1k0H1g4 VmaUv2E5Ib4/dudxWbNZ1utVZQX3sjIH1V+YoM3KIM7hMONpVaZjcnV8uAenkHm5zXMVB65d z/ROKLEUZyQaajEXFScCAFRh3ZmgAgAA Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some USB devices on embedded boards have external power supply which has to be reset in certain conditions. Add pwrseq interface for this. Signed-off-by: Krzysztof Kozlowski --- drivers/power/pwrseq/pwrseq.c | 47 ++++++++++++++++++++++++++++++++++++++++++- include/linux/pwrseq.h | 11 ++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/power/pwrseq/pwrseq.c b/drivers/power/pwrseq/pwrseq.c index 495a19d3c30b..722aff4f740f 100644 --- a/drivers/power/pwrseq/pwrseq.c +++ b/drivers/power/pwrseq/pwrseq.c @@ -1,7 +1,9 @@ /* - * Copyright (C) 2014 Linaro Ltd + * Copyright (C) 2014 Linaro Ltd + * Copyright (C) 2016 Samsung Electronics * * Author: Ulf Hansson + * Krzysztof Kozlowski * * License terms: GNU General Public License (GPL) version 2 * @@ -52,6 +54,42 @@ int mmc_pwrseq_alloc(struct mmc_host *host) } EXPORT_SYMBOL_GPL(mmc_pwrseq_alloc); +struct pwrseq *pwrseq_alloc(struct device *dev, const char *phandle_name) +{ + struct device_node *np; + struct pwrseq *p, *ret = NULL; + + np = of_parse_phandle(dev->of_node, phandle_name, 0); + if (!np) + return NULL; + + mutex_lock(&pwrseq_list_mutex); + list_for_each_entry(p, &pwrseq_list, pwrseq_node) { + if (p->dev->of_node == np) { + if (!try_module_get(p->owner)) + dev_err(dev, + "increasing module refcount failed\n"); + else + ret = p; + + break; + } + } + + of_node_put(np); + mutex_unlock(&pwrseq_list_mutex); + + if (!ret) { + dev_dbg(dev, "%s defer probe\n", phandle_name); + return ERR_PTR(-EPROBE_DEFER); + } + + dev_info(dev, "allocated usb-pwrseq\n"); + + return ret; +} +EXPORT_SYMBOL_GPL(pwrseq_alloc); + void pwrseq_pre_power_on(struct pwrseq *pwrseq) { if (pwrseq && pwrseq->ops->pre_power_on) @@ -84,6 +122,13 @@ void mmc_pwrseq_free(struct mmc_host *host) } EXPORT_SYMBOL_GPL(mmc_pwrseq_free); +void pwrseq_free(const struct pwrseq *pwrseq) +{ + if (pwrseq) + module_put(pwrseq->owner); +} +EXPORT_SYMBOL_GPL(pwrseq_free); + int pwrseq_register(struct pwrseq *pwrseq) { if (!pwrseq || !pwrseq->ops || !pwrseq->dev) diff --git a/include/linux/pwrseq.h b/include/linux/pwrseq.h index fcc8fd855d4c..6215b3d6350d 100644 --- a/include/linux/pwrseq.h +++ b/include/linux/pwrseq.h @@ -31,9 +31,13 @@ void pwrseq_unregister(struct pwrseq *pwrseq); void pwrseq_pre_power_on(struct pwrseq *pwrseq); void pwrseq_post_power_on(struct pwrseq *pwrseq); void pwrseq_power_off(struct pwrseq *pwrseq); + int mmc_pwrseq_alloc(struct mmc_host *host); void mmc_pwrseq_free(struct mmc_host *host); +struct pwrseq *pwrseq_alloc(struct device *dev, const char *phandle_name); +void pwrseq_free(const struct pwrseq *pwrseq); + #else /* CONFIG_POWER_SEQ */ static inline int pwrseq_register(struct pwrseq *pwrseq) @@ -44,9 +48,16 @@ static inline void pwrseq_unregister(struct pwrseq *pwrseq) {} static inline void pwrseq_pre_power_on(struct pwrseq *pwrseq) {} static inline void pwrseq_post_power_on(struct pwrseq *pwrseq) {} static inline void pwrseq_power_off(struct pwrseq *pwrseq) {} + static inline int mmc_pwrseq_alloc(struct mmc_host *host) { return 0; } static inline void mmc_pwrseq_free(struct mmc_host *host) {} +static inline struct pwrseq *pwrseq_alloc(struct device *dev, const char *phandle_name) +{ + return NULL; +} +static inline void pwrseq_free(const struct pwrseq *pwrseq) {} + #endif /* CONFIG_POWER_SEQ */ #endif /* _LINUX_PWRSEQ_H */