From patchwork Fri Apr 7 12:38:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 748219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vzzcv20cgz9s7s for ; Fri, 7 Apr 2017 22:37:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932787AbdDGMht (ORCPT ); Fri, 7 Apr 2017 08:37:49 -0400 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:47525 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754564AbdDGMhs (ORCPT ); Fri, 7 Apr 2017 08:37:48 -0400 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v37CYuip014647; Fri, 7 Apr 2017 07:37:41 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.wolfsonmicro.com Received: from mail2.cirrus.com (mail1.cirrus.com [141.131.3.20]) by mx0a-001ae601.pphosted.com with ESMTP id 29p3qk8q11-1; Fri, 07 Apr 2017 07:37:41 -0500 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail2.cirrus.com (Postfix) with ESMTP id DEE5A6121AC9; Fri, 7 Apr 2017 07:37:40 -0500 (CDT) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Fri, 7 Apr 2017 13:37:40 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.223.36]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id v37CaxdT024920; Fri, 7 Apr 2017 13:37:00 +0100 From: Charles Keepax To: , CC: , , , , , , Subject: [PATCH 2/2] gpio: arizona: Add support for GPIOs that need to be maintained Date: Fri, 7 Apr 2017 13:38:45 +0100 Message-ID: <1491568725-14882-2-git-send-email-ckeepax@opensource.wolfsonmicro.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1491568725-14882-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> References: <1491568725-14882-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> MIME-Version: 1.0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704070106 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The Arizona devices only maintain the state of output GPIOs whilst the CODEC is active, this can cause issues if the CODEC suspends whilst something is relying on the state of one of its GPIOs. However, in many systems the CODEC GPIOs are used for audio related features and thus the state of the GPIOs is unimportant whilst the CODEC is suspended. Often keeping the CODEC resumed in such a system would incur a power impact that is unacceptable. Allow the user to select whether a GPIO output should keep the CODEC resumed, by adding a flag through the second cell of the GPIO specifier in device tree. The default behaviour remains the same with the GPIO not forcing the CODEC to remain active and losing state, so as to not cause power regressions on existing systems. Signed-off-by: Charles Keepax --- drivers/gpio/gpio-arizona.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/gpio/gpio-arizona.c b/drivers/gpio/gpio-arizona.c index 60b3102..027a70a 100644 --- a/drivers/gpio/gpio-arizona.c +++ b/drivers/gpio/gpio-arizona.c @@ -24,15 +24,27 @@ #include #include +#define ARIZONA_GP_STATE_OUTPUT 0x00000001 + struct arizona_gpio { struct arizona *arizona; struct gpio_chip gpio_chip; + int status[ARIZONA_MAX_GPIO]; }; static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset) { struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); struct arizona *arizona = arizona_gpio->arizona; + int status = arizona_gpio->status[offset]; + + status &= (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT); + if (status == (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT)) { + arizona_gpio->status[offset] &= ~ARIZONA_GP_STATE_OUTPUT; + + pm_runtime_mark_last_busy(chip->parent); + pm_runtime_put_autosuspend(chip->parent); + } return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, ARIZONA_GPN_DIR, ARIZONA_GPN_DIR); @@ -85,6 +97,19 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip, { struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); struct arizona *arizona = arizona_gpio->arizona; + int status = arizona_gpio->status[offset]; + int ret; + + status &= (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT); + if (status == ARIZONA_GP_MAINTAIN) { + arizona_gpio->status[offset] |= ARIZONA_GP_STATE_OUTPUT; + + ret = pm_runtime_get_sync(chip->parent); + if (ret < 0) { + dev_err(chip->parent, "Failed to resume: %d\n", ret); + return ret; + } + } if (value) value = ARIZONA_GPN_LVL; @@ -105,6 +130,29 @@ static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ARIZONA_GPN_LVL, value); } +static int arizona_gpio_of_xlate(struct gpio_chip *chip, + const struct of_phandle_args *gpiospec, + u32 *flags) +{ + struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); + u32 offset = gpiospec->args[0]; + u32 bits = gpiospec->args[1]; + + if (gpiospec->args_count < chip->of_gpio_n_cells) + return -EINVAL; + + if (offset >= chip->ngpio) + return -EINVAL; + + if (flags) + *flags = bits & ~ARIZONA_GP_MAINTAIN; + + if (bits & ARIZONA_GP_MAINTAIN) + arizona_gpio->status[offset] |= ARIZONA_GP_MAINTAIN; + + return offset; +} + static const struct gpio_chip template_chip = { .label = "arizona", .owner = THIS_MODULE, @@ -113,6 +161,8 @@ static const struct gpio_chip template_chip = { .direction_output = arizona_gpio_direction_out, .set = arizona_gpio_set, .can_sleep = true, + .of_xlate = arizona_gpio_of_xlate, + .of_gpio_n_cells = 2, }; static int arizona_gpio_probe(struct platform_device *pdev) @@ -158,6 +208,8 @@ static int arizona_gpio_probe(struct platform_device *pdev) else arizona_gpio->gpio_chip.base = -1; + pm_runtime_enable(&pdev->dev); + ret = devm_gpiochip_add_data(&pdev->dev, &arizona_gpio->gpio_chip, arizona_gpio); if (ret < 0) {