From patchwork Thu May 5 12:34:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 9024321 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B8D59F30C for ; Thu, 5 May 2016 12:39:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A52FE200DE for ; Thu, 5 May 2016 12:39:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93B60200E6 for ; Thu, 5 May 2016 12:39:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755742AbcEEMfV (ORCPT ); Thu, 5 May 2016 08:35:21 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:55159 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755163AbcEEMfA (ORCPT ); Thu, 5 May 2016 08:35:00 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O6P005Y8EY8XM60@mailout3.w1.samsung.com>; Thu, 05 May 2016 13:34:57 +0100 (BST) X-AuditID: cbfec7f5-f792a6d000001302-0f-572b3df02a22 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 87.41.04866.0FD3B275; Thu, 5 May 2016 13:34:56 +0100 (BST) Received: from AMDC2174.DIGITAL.local ([106.120.53.17]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O6P00KEEEXN8E00@eusync4.samsung.com>; Thu, 05 May 2016 13:34:56 +0100 (BST) From: Krzysztof Kozlowski To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, Ulf Hansson , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Greg Kroah-Hartman , Mark Brown Cc: tjakobi@math.uni-bielefeld.de, m.szyprowski@samsung.com, hverkuil@xs4all.nl, Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz Subject: [RFC v2 07/13] power: pwrseq: simple: Add support for toggling regulator Date: Thu, 05 May 2016 14:34:20 +0200 Message-id: <1462451666-17945-8-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1462451666-17945-1-git-send-email-k.kozlowski@samsung.com> References: <1462451666-17945-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRmVeSWpSXmKPExsVy+t/xa7ofbLXDDY6tMbHYOGM9q8XUh0/Y LCY9ec9sMf/IOVaLiSsnM1s0L17PZnFq8jMmi9cvDC02Pb7GanF51xw2iyP/+xktPvceYbSY cX4fk8WiZa3MFmuP3GW3OL27xKJt9QdWi+Nrwx2EPHbOusvusXmFlsemVZ1sHneu7WHz2D93 DVBoSb3Hv2PsHn1bVjF6fN4k53Hq62f2AK4oLpuU1JzMstQifbsErozeF4/ZCibIVUzeeJO1 gfGJRBcjJ4eEgInEznn3mSFsMYkL99azdTFycQgJLGWUuHvsMCOE08gkseroNFaQKjYBY4nN y5eAVYkI3GCWeLVzMjOIwyywg1Hi77I7LCBVwgLBEu/eLGcDsVkEVCUmX9sKtoNXwF1i34Mv UPvkJE4emww2lVPAQ+Lsr/lgthBQzaHf0xknMPIuYGRYxSiaWppcUJyUnmukV5yYW1yal66X nJ+7iRES7l93MC49ZnWIUYCDUYmHN2OuVrgQa2JZcWXuIUYJDmYlEV55YLQI8aYkVlalFuXH F5XmpBYfYpTmYFES5525632IkEB6YklqdmpqQWoRTJaJg1OqgTFb+f47yW7ltqs5qkEV9ZMF SiTepL88J1Q7I74hTlx/klv8lbk7hDqVr9kt8dtTN8VvIutmt6IT9vemc5x+MVFZbNvH5YsX XH0tUOcy+1OJ3/TLjXYPp576ov9b/PinZfGuZ86+bf1eucldw/rwEvaUzYlnV7tOig7Qm2Pw wLj0a7iN4Gve7FwlluKMREMt5qLiRAAW/YT4cwIAAA== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Some devices need real hard-reset by cutting the power. During power sequence turn off and on the regulator, if it is provided. Signed-off-by: Krzysztof Kozlowski --- .../devicetree/bindings/mmc/mmc-pwrseq-simple.txt | 2 + drivers/power/pwrseq/pwrseq_simple.c | 50 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.txt b/Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.txt index ce0e76749671..176ff831e7f1 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.txt +++ b/Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.txt @@ -16,6 +16,7 @@ Optional properties: See ../clocks/clock-bindings.txt for details. - clock-names : Must include the following entry: "ext_clock" (External clock provided to the card). +- ext-supply : External regulator supply Example: @@ -24,4 +25,5 @@ Example: reset-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>; clocks = <&clk_32768_ck>; clock-names = "ext_clock"; + ext-supply = <&buck8>; } diff --git a/drivers/power/pwrseq/pwrseq_simple.c b/drivers/power/pwrseq/pwrseq_simple.c index ab0098412690..4d5ea53d3ead 100644 --- a/drivers/power/pwrseq/pwrseq_simple.c +++ b/drivers/power/pwrseq/pwrseq_simple.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include @@ -25,6 +27,7 @@ struct mmc_pwrseq_simple { bool clk_enabled; struct clk *ext_clk; struct gpio_descs *reset_gpios; + struct regulator *ext_reg; }; #define to_pwrseq_simple(p) container_of(p, struct mmc_pwrseq_simple, pwrseq) @@ -62,6 +65,13 @@ static void mmc_pwrseq_simple_post_power_on(struct pwrseq *_pwrseq) { struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(_pwrseq); + if (pwrseq->ext_reg) { + int err; + + err = regulator_enable(pwrseq->ext_reg); + WARN_ON_ONCE(err); + } + mmc_pwrseq_simple_set_gpios_value(pwrseq, 0); } @@ -75,6 +85,13 @@ static void mmc_pwrseq_simple_power_off(struct pwrseq *_pwrseq) clk_disable_unprepare(pwrseq->ext_clk); pwrseq->clk_enabled = false; } + + if (pwrseq->ext_reg) { + int err; + + err = regulator_disable(pwrseq->ext_reg); + WARN_ON_ONCE(err); + } } static const struct pwrseq_ops mmc_pwrseq_simple_ops = { @@ -102,6 +119,32 @@ static int mmc_pwrseq_simple_probe(struct platform_device *pdev) if (IS_ERR(pwrseq->ext_clk) && PTR_ERR(pwrseq->ext_clk) != -ENOENT) return PTR_ERR(pwrseq->ext_clk); + /* FIXME: regulator_get_exclusive? */ + pwrseq->ext_reg = devm_regulator_get_optional(dev, "ext"); + if (IS_ERR(pwrseq->ext_reg)) { + if (PTR_ERR(pwrseq->ext_reg) == -ENODEV) + pwrseq->ext_reg = NULL; + else + return PTR_ERR(pwrseq->ext_reg); + } else { + int err; + /* + * Be sure that regulator is off, before the driver will start + * power sequence. It is likely that regulator is on by default + * and it without toggling it here, it would be disabled much + * later by the core. + */ + + err = regulator_enable(pwrseq->ext_reg); + WARN_ON_ONCE(err); + + /* FIXME: handle this in a more sensible way */ + mdelay(10); + + err = regulator_disable(pwrseq->ext_reg); + WARN_ON_ONCE(err); + } + pwrseq->reset_gpios = devm_gpiod_get_array(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(pwrseq->reset_gpios) && @@ -124,6 +167,13 @@ static int mmc_pwrseq_simple_remove(struct platform_device *pdev) pwrseq_unregister(&pwrseq->pwrseq); + if (pwrseq->ext_reg) { + int err; + + err = regulator_disable(pwrseq->ext_reg); + WARN_ON_ONCE(err); + } + return 0; }