From patchwork Thu Jun 9 09:44:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 9166607 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 1D5FC6048F for ; Thu, 9 Jun 2016 09:50:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C2642830C for ; Thu, 9 Jun 2016 09:50:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00AC628336; Thu, 9 Jun 2016 09:50:45 +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 9D50D2830C for ; Thu, 9 Jun 2016 09:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933180AbcFIJuK (ORCPT ); Thu, 9 Jun 2016 05:50:10 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:55257 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933528AbcFIJpB (ORCPT ); Thu, 9 Jun 2016 05:45:01 -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 <0O8I005K20EVXU90@mailout2.w1.samsung.com>; Thu, 09 Jun 2016 10:44:56 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-9e-57593a977c89 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 0B.E6.05254.79A39575; Thu, 9 Jun 2016 10:44:55 +0100 (BST) Received: from AMDC2174.DIGITAL.local ([106.120.53.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8I006RA0EHZZ10@eusync1.samsung.com>; Thu, 09 Jun 2016 10:44:55 +0100 (BST) From: Krzysztof Kozlowski To: Ulf Hansson , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Krzysztof Kozlowski , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Liam Girdwood , Mark Brown , Greg Kroah-Hartman , Hans de Goede , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Heiko Stuebner , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-fbdev@vger.kernel.org, hzpeterchen@gmail.com Cc: Bartlomiej Zolnierkiewicz Subject: [RFC v4 09/14] power: pwrseq: Add support for USB hubs with external power Date: Thu, 09 Jun 2016 11:44:26 +0200 Message-id: <1465465471-28740-10-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1465465471-28740-1-git-send-email-k.kozlowski@samsung.com> References: <1465465471-28740-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWRbUhTYRiGe8/Zzo6j0WF+ndSEFhkpWVrQi1Rkfzo/Q5RVUG3pQcVt2qai RmWIoJLzM2emLp1ubW2OpuZHumhMp1lmW1sSKum0RM2FSgiW5hz9u+77vuD58eAoV80IwdMl 2bRUIhTxMDZjbNvmOKGIu8Y/VaGOhS/rjUz4eHYeg9XzHhQqreNMWKWtQWHFSgsTFqmMGFyx KRC4M7fMhGVOEwbHl7QALi/GwN+fSxBocruYcET+iwkd/Y0YtO5UALhebgWw/qMZga3qYhS2 f/mEwEqFgQE7ZhcRWDxoZcGx19nQqPyKQZuBfzGU0jfrAeWQlyNUX8M0i9JqNjCq83kktTQx xaBMulKMmnINYNSbJj2L6mx7QHnMToySd+kA1eNqRinbZA9CrZvCrxy4zj6XQovSc2npyQsC dlpJ0SaW1R2W1+rUYIVgJLgM+OEkcYZ8v1aL+TiInJgx7jIb5xLtgFTWfWf5wkOEHDS0AK+F EafJTk3bnhVA2FnkpL0H8Q4oAcnu7hcsL/sTSaSuuoPpZQZxlGxQVez1HIIi52eLge9cODk6 XLPn+O32czNu1Mtc4jI5qKrBKgHnGdinA4F0TnKW7HaqOCZaJhTLciSp0cmZYhPwfW+jF6iG 4yyAwAFvP+d4ylU+lynMleWLLYDEUV4AZ/PsNT6XkyLML6ClmbekOSJaZgGhOIMXzGnq9yRy iVRhNp1B01m09P+K4H4hhaBwQHpwSJFXeVcZ96hcEzadOKLNcNwbUL+92ev+dr6xK2ppRT2U Tk9durNsWK9KyAviTDYf+3NkCxl1d1kleK1/oCBq2HMo1rMYAm+sHna75KXEWvxP++rfqO2I uvgfIvN0weZ9+5O+xC3zwgdnwVNtoyBCn4QuTNS9EiS8s/AYsjRhTCQqlQn/AQPcEL25AgAA Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@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 */