From patchwork Mon Oct 27 15:03:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5161871 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A628B9F318 for ; Mon, 27 Oct 2014 15:33:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 925E82017D for ; Mon, 27 Oct 2014 15:33:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D20A2020E for ; Mon, 27 Oct 2014 15:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752393AbaJ0Pdw (ORCPT ); Mon, 27 Oct 2014 11:33:52 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:48572 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750909AbaJ0P3i (ORCPT ); Mon, 27 Oct 2014 11:29:38 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NE400JVB0I2T880@mailout3.w1.samsung.com>; Mon, 27 Oct 2014 15:32:26 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-0b-544e64dcb8f2 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 0B.E5.04619.CD46E445; Mon, 27 Oct 2014 15:29:32 +0000 (GMT) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NE4003280CPPUA0@eusync4.samsung.com>; Mon, 27 Oct 2014 15:29:32 +0000 (GMT) From: Krzysztof Kozlowski To: Samuel Ortiz , Lee Jones , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, Ben Dooks , Kukjin Kim , Russell King , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org Cc: Kyungmin Park , Marek Szyprowski , Bartlomiej Zolnierkiewicz , Javier Martinez Canillas , Chanwoo Choi , Krzysztof Kozlowski Subject: [PATCH 6/8] regulator: max77686: Add external GPIO control Date: Mon, 27 Oct 2014 16:03:44 +0100 Message-id: <1414422226-10948-7-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1414422226-10948-1-git-send-email-k.kozlowski@samsung.com> References: <1414422226-10948-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLLMWRmVeSWpSXmKPExsVy+t/xa7p3UvxCDBr+MVtsnLGe1WLSugNM FlMfPmGzuP7lOavF/CPnWC2O/i6weP3C0KJ3wVU2i7NNb9gt7n89ymjx7UoHk8Wmx9dYLS7v msNmMeP8PiaL25d5LdYeuctucbqb1UHQo6W5h83j7/PrLB5/V71g9tg56y67x6ZVnWwed67t YfOYdzLQY/OSeo++LasYPT5vkgvgiuKySUnNySxLLdK3S+DK2LL3BkvBY4uKW5ta2RsYj+l1 MXJySAiYSHycdYkNwhaTuHBvPZDNxSEksJRR4uuXKcwQTh+TxME9c8Cq2ASMJTYvXwJWJSLQ ySzRc7AXrIpZYDWTxM8rp5hBqoQFnCWubu8E62ARUJW42rgZLM4r4C6x/NUJJoh9chInj01m BbE5BTwkXt//ClYjBFTz+f1WxgmMvAsYGVYxiqaWJhcUJ6XnGuoVJ+YWl+al6yXn525ihAT5 lx2Mi49ZHWIU4GBU4uHdMc03RIg1say4MvcQowQHs5II76kAvxAh3pTEyqrUovz4otKc1OJD jEwcnFINjKvWvHfz3iXHFTdr4jWReIvj/j9lN/z9mbR1bWb+IdtUfvEdzh7VnBdfdUdknbPP 3TS5yu7Oy+e/FZsWJD35oFj5S+DEqmALtsM/Dq87V5335Z5Z8yeT35I9v1aZJF/XOVG9dBbz mSPFB+5m7kpILpJrPPhly4TJeWdEpl/dXbNXmYf1m9bCfSZKLMUZiYZazEXFiQBgfDXPUAIA AA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 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 Add control over GPIO for regulators supporting this: LDO20, LDO21, LDO22, buck8 and buck9. This is needed for proper (and full) configuration of the Maxim 77686 PMIC without creating redundant 'regulator-fixed' entries. Signed-off-by: Krzysztof Kozlowski --- drivers/regulator/max77686.c | 101 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 5 deletions(-) diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index e5738c363f07..c54a8603f5b2 100644 --- a/drivers/regulator/max77686.c +++ b/drivers/regulator/max77686.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,11 @@ #define MAX77686_DVS_UVSTEP 12500 /* + * Value for configuring buck[89] and LDO{20,21,22} as external control. + * It is the same as 'off' for other regulators. + */ +#define MAX77686_EXT_CONTROL 0x0 +/* * Values used for configuring LDOs and bucks. * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26 */ @@ -85,6 +91,9 @@ struct max77686_data { struct max77686_regulator_data *regulators; int num_regulators; + /* Array of size num_regulators with GPIOs for external control. */ + int *ext_control_gpio; + unsigned int opmode[MAX77686_REGULATORS]; }; @@ -102,6 +111,28 @@ static unsigned int max77686_get_opmode_shift(int id) } } +/* + * When regulator is configured for external control then it + * replaces "normal" mode. Any change from low power mode to normal + * should actually change to external control. + * Map normal mode to proper value for such regulators. + */ +static int max77686_map_normal_mode(struct max77686_data *max77686, int id) +{ + switch (id) { + case MAX77686_BUCK8: + case MAX77686_BUCK9: + if (gpio_is_valid(max77686->ext_control_gpio[id])) + return MAX77686_EXT_CONTROL; + + case MAX77686_LDO20 ... MAX77686_LDO22: + if (gpio_is_valid(max77686->ext_control_gpio[id])) + return MAX77686_EXT_CONTROL; + } + + return MAX77686_NORMAL; +} + /* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */ static int max77686_set_suspend_disable(struct regulator_dev *rdev) { @@ -138,7 +169,7 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev, val = MAX77686_LDO_LOWPOWER_PWRREQ; break; case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ - val = MAX77686_NORMAL; + val = max77686_map_normal_mode(max77686, id); break; default: pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", @@ -162,7 +193,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, { unsigned int val; struct max77686_data *max77686 = rdev_get_drvdata(rdev); - int ret; + int ret, id = rdev_get_id(rdev); switch (mode) { case REGULATOR_MODE_STANDBY: /* switch off */ @@ -172,7 +203,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, val = MAX77686_LDO_LOWPOWER_PWRREQ; break; case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ - val = MAX77686_NORMAL; + val = max77686_map_normal_mode(max77686, id); break; default: pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", @@ -186,7 +217,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, if (ret) return ret; - max77686->opmode[rdev_get_id(rdev)] = val; + max77686->opmode[id] = val; return 0; } @@ -199,7 +230,7 @@ static int max77686_enable(struct regulator_dev *rdev) shift = max77686_get_opmode_shift(id); if (max77686->opmode[id] == MAX77686_OFF_PWRREQ) - max77686->opmode[id] = MAX77686_NORMAL; + max77686->opmode[id] = max77686_map_normal_mode(max77686, id); return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, @@ -433,6 +464,42 @@ static const struct regulator_desc regulators[] = { regulator_desc_buck(9), }; +static int max77686_enable_ext_control(struct regulator_dev *rdev) +{ + return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, + rdev->desc->enable_mask, + MAX77686_EXT_CONTROL); +} + +static void max77686_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev, + struct max77686_regulator_data *rdata, + struct max77686_data *max77686) +{ + int *gpio = max77686->ext_control_gpio; + unsigned int i; + unsigned int valid_regulators[5] = { MAX77686_LDO20, MAX77686_LDO21, + MAX77686_LDO22, MAX77686_BUCK8, MAX77686_BUCK9 }; + + /* + * 0 is a valid GPIO so initialize all GPIOs to negative value + * to indicate that external control won't be used for this regulator. + */ + for (i = 0; i < max77686->num_regulators; i++) + max77686->ext_control_gpio[i] = -EINVAL; + + for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) { + unsigned int reg = valid_regulators[i]; + + if (!rdata[reg].initdata || !rdata[reg].of_node) + continue; + + gpio[reg] = of_get_named_gpio(rdata[reg].of_node, "gpio", 0); + if (gpio_is_valid(gpio[reg])) + dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n", + gpio[reg], reg, rdata[reg].of_node->name); + } +} + static int max77686_pmic_dt_parse(struct platform_device *pdev, struct max77686_data *max77686) { @@ -457,6 +524,14 @@ static int max77686_pmic_dt_parse(struct platform_device *pdev, return -ENOMEM; } + max77686->ext_control_gpio = devm_kmalloc_array(&pdev->dev, + max77686->num_regulators, + sizeof(*max77686->ext_control_gpio), GFP_KERNEL); + if (!max77686->ext_control_gpio) { + of_node_put(regulators_np); + return -ENOMEM; + } + for (i = 0; i < max77686->num_regulators; i++) { rmatch.name = regulators[i].name; rmatch.init_data = NULL; @@ -466,7 +541,9 @@ static int max77686_pmic_dt_parse(struct platform_device *pdev, rdata[i].of_node = rmatch.of_node; } + max77686_pmic_dt_parse_ext_control_gpio(pdev, rdata, max77686); max77686->regulators = rdata; + of_node_put(regulators_np); return 0; @@ -499,6 +576,7 @@ static int max77686_pmic_probe(struct platform_device *pdev) config.dev = &pdev->dev; config.regmap = iodev->regmap; config.driver_data = max77686; + config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; platform_set_drvdata(pdev, max77686); for (i = 0; i < MAX77686_REGULATORS; i++) { @@ -506,6 +584,8 @@ static int max77686_pmic_probe(struct platform_device *pdev) config.init_data = max77686->regulators[i].initdata; config.of_node = max77686->regulators[i].of_node; + config.ena_gpio = max77686->ext_control_gpio[i]; + config.ena_gpio_initialized = true; max77686->opmode[i] = MAX77686_NORMAL; @@ -516,6 +596,17 @@ static int max77686_pmic_probe(struct platform_device *pdev) "regulator init failed for %d\n", i); return PTR_ERR(rdev); } + + if (gpio_is_valid(config.ena_gpio)) { + ret = max77686_enable_ext_control(rdev); + + if (ret < 0) { + dev_err(&pdev->dev, + "regulator enable ext control failed for %d\n", + i); + return ret; + } + } } return 0;