From patchwork Fri Dec 16 15:52:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 88318 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1481512qgi; Fri, 16 Dec 2016 07:53:47 -0800 (PST) X-Received: by 10.99.114.89 with SMTP id c25mr6800521pgn.4.1481903627308; Fri, 16 Dec 2016 07:53:47 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p19si5632808pgk.133.2016.12.16.07.53.47; Fri, 16 Dec 2016 07:53:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761976AbcLPPx2 (ORCPT + 25 others); Fri, 16 Dec 2016 10:53:28 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:38372 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761889AbcLPPxA (ORCPT ); Fri, 16 Dec 2016 10:53:00 -0500 Received: by mail-wm0-f46.google.com with SMTP id f82so39645700wmf.1 for ; Fri, 16 Dec 2016 07:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1RzrSRHDsMt302mL+kzgFO/EHvkpAQ+FZJJ0mA/syss=; b=vFyo8E4i7EcOdhwu8Wp5a1h6NzIZ/CYt+oaf8EstDiZTwU73TUnrfksTxAh7+ASvfH 2ngY157OTV27W2XTO1/jT7US43aNADjo6Mg5yiNUlepCn1pJRyJqxrEzqIcyZA2QKMSx Acm1eG2CGKjsZMmKxfJQOK1e+xtF7aWWcRFcj3Vxz5Y8U8JpOf9RAz6mxdwUY3SQMEJy nyljdaUlOlybnCik+RtzGXW3TwcBImV8H8mHOpSjiYoHJH5RN9V0CzCosvSEztDsrDrR Jg3tsNesTdT70n6DzJ2Ihmrvt67jYIQkt9XCgFb8HjXbVJNJoAc4Q1tZDuwirqNhEzVy RogA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1RzrSRHDsMt302mL+kzgFO/EHvkpAQ+FZJJ0mA/syss=; b=FFDFgHOHGPYqP3kPXV3IxwzUbn5c4IEy1bfzegQ5lexe+o4CK77EJ/xcz96WY3qAa0 7AEzfeK3q48LeX96MOLs9+FB/J+OWxzjB+6qEbEK93w7DiucKPti3C30hvCH281U9wlj zeImhWsEB8/LEfwVo9w7thEgDr7mE+bRBQiN6EZIdB1/DRZ/OUP9D+LmN39PDzNRUGzp xMGDnWIWa5lJUdI0SjIj1xV+1BkUmEN8SryaEifUHp9jbIm3YtshJCp6Mk2XzqANz1R4 u2Ho3GqpXkPeEmZLaCJE32XVfSQmR3O6O2vyVVr+8rEggJySt6k/Es17qdMvtOgVzb7w fgOg== X-Gm-Message-State: AIkVDXLQu9CX2tcboucI5fKFUda0AbbhU+DEGTbupZ3wVdit96UQVKYi1vVTzofJ9VpPZdao X-Received: by 10.28.43.198 with SMTP id r189mr3737998wmr.67.1481903562192; Fri, 16 Dec 2016 07:52:42 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id f10sm7329843wjl.28.2016.12.16.07.52.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Dec 2016 07:52:41 -0800 (PST) From: Bartosz Golaszewski To: Liam Girdwood , Mark Brown , Rob Herring , Mark Rutland Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Kevin Hilman , Patrick Titiano , Neil Armstrong , Bartosz Golaszewski Subject: [PATCH 3/3] regulator: fixed: add support for gpio power switches Date: Fri, 16 Dec 2016 16:52:30 +0100 Message-Id: <1481903550-3582-4-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1481903550-3582-1-git-send-email-bgolaszewski@baylibre.com> References: <1481903550-3582-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The difference between a regular fixed regulator and a GPIO power load switch is the fact that the latter may be controlled from user space. Reuse the fixed regulator driver to support power switches. Signed-off-by: Bartosz Golaszewski --- drivers/regulator/fixed.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) -- 2.9.3 diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 988a747..f125a3e 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -31,6 +31,8 @@ #include #include +#define REG_FIXED_POWER_SWITCH BIT(0) + struct fixed_voltage_data { struct regulator_desc desc; struct regulator_dev *dev; @@ -97,11 +99,27 @@ of_get_fixed_voltage_config(struct device *dev, static struct regulator_ops fixed_voltage_ops = { }; +#if defined(CONFIG_OF) +static const struct of_device_id fixed_of_match[] = { + { + .compatible = "regulator-fixed", + }, + { + .compatible = "gpio-power-switch", + .data = (void *)REG_FIXED_POWER_SWITCH, + }, + {}, +}; +MODULE_DEVICE_TABLE(of, fixed_of_match); +#endif + static int reg_fixed_voltage_probe(struct platform_device *pdev) { struct fixed_voltage_config *config; struct fixed_voltage_data *drvdata; struct regulator_config cfg = { }; + const struct of_device_id *of_id; + long flags = 0; int ret; drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), @@ -175,6 +193,13 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) cfg.driver_data = drvdata; cfg.of_node = pdev->dev.of_node; + of_id = of_match_node(fixed_of_match, pdev->dev.of_node); + if (of_id) + flags = (long)of_id->data; + + if (flags & REG_FIXED_POWER_SWITCH) + drvdata->desc.userspace_control = 1; + drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc, &cfg); if (IS_ERR(drvdata->dev)) { @@ -191,14 +216,6 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) return 0; } -#if defined(CONFIG_OF) -static const struct of_device_id fixed_of_match[] = { - { .compatible = "regulator-fixed", }, - {}, -}; -MODULE_DEVICE_TABLE(of, fixed_of_match); -#endif - static struct platform_driver regulator_fixed_voltage_driver = { .probe = reg_fixed_voltage_probe, .driver = {