Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761776AbcLPPx2 (ORCPT ); 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 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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2370 Lines: 82 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(-) 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 = { -- 2.9.3