From patchwork Tue May 28 13:36:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 165310 Delivered-To: patch@linaro.org Received: by 2002:ac9:2a84:0:0:0:0:0 with SMTP id p4csp8025969oca; Tue, 28 May 2019 06:37:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHrhqgNz8uadiAHy9UkpPmPiKmj3+eGQvfLAVoWncJYtXCteqBI/SI/3jlVOafveCvSa4B X-Received: by 2002:aa7:9726:: with SMTP id k6mr81393629pfg.246.1559050624526; Tue, 28 May 2019 06:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559050624; cv=none; d=google.com; s=arc-20160816; b=a66KJQ0G0R6cB3LBS0Th2vaIRpvfXwb6uS7xVUDlT5yfmlFWn3f/a0Ch08wWYdfZ2H fQK9sXSdZ0fM/XxmtwM1uMlM2GvvTy0gLn7JUNnqxyCfptqp4ALskg55Y4ag1A0VgOnh Ozq8eJSgvFhhvOMEumC9ci+WKD9P0iyNX4GsJrsX25KaDFBqM0Y+PmNOSLSFzdv3SKMT +StmhGdrRufWT3AnweAf0CZIbDAAbRqDMk43LZCi8WABi3iYtYt+0sqKpkbYN2AOyFs+ CAseccnrjHBgCyoDVAqbIz5ybIX2xG5c/3q4F9tkicV3GgkBHfdbMpWVpvdBojZSZqKf LXEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bbidxiifh4zQbXF3+idClmgRZbbOXntRKLhQM+IruEA=; b=TGpU8EdoePwI4u2JUOKoR9/twUYRAErD8IpzXBnFCWRYXetL21m6S3jRBS8sy2LQZ2 2oE27b69SRFbaY/tEk+a2LVobOZSw5HRZ0x+A/cL+tP6PBXE6m/Zv58kD44PWiT1Rd57 taSTiFYB+lvELZRsqyf+WlLLy7yaFNo5YqSgieVxiMozcQJ81zNcDX1BJmLgpd5kXjGb YnWUImSEc8yphNucCRJeBpcEqOPhHNSQJG52Z1QHistbVZqTL0KFwBPqJC6f5SQfwf/F D/fhnRUt3cWcHfWuiDkOzTmYpryynmt7IUkxrgqYv8/fIOdteZ75bUMV9jJQw7js2TY8 /iFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g9r4++eH; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si3433642pjs.104.2019.05.28.06.37.04; Tue, 28 May 2019 06:37:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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=@linaro.org header.s=google header.b=g9r4++eH; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727467AbfE1NhD (ORCPT + 9 others); Tue, 28 May 2019 09:37:03 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37392 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727090AbfE1NhD (ORCPT ); Tue, 28 May 2019 09:37:03 -0400 Received: by mail-wm1-f68.google.com with SMTP id 7so2908200wmo.2 for ; Tue, 28 May 2019 06:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bbidxiifh4zQbXF3+idClmgRZbbOXntRKLhQM+IruEA=; b=g9r4++eHwLh867+bZIoekdLRqjajwptL/liJwhVXgwhBPKGDq91Utht30DkTs2rLA8 6XkZmrhQcku9bdDJTCKfx17EMKG6UICuzY5+k7bio0APavWFb1UXXUtuLP23415dIlJ5 1/qnuMXVHlchnfPwtC4zFsD+ggvXQb4K49gfJ78eW6fOT59rbcBOhhFX8ApU8uOxMamh BBsA6HpW9Srs9QxHDkGywSvzGNL4W/T9PYNBhPl9B0otlG7uEaS1eNIOICTLyXVwZ1+j STdHEgUqufGyFsqmmYUwtRq+5AcF9kTkB+83hQpFzdP/ZS4VF9RRE0DEMTMpkXTkn+ab 4/mA== 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:mime-version:content-transfer-encoding; bh=bbidxiifh4zQbXF3+idClmgRZbbOXntRKLhQM+IruEA=; b=h3ojB/wSlZylQ5Pd8yMjvG2SywqsglTiqJEAj4aRQzw97jt+meU6tmE35NCFYSgUEi kANx0LV0HtWLgFlUxyV46BBj9ddr7z17ucklc8TaYt+9MdwUbSGOHjwteyqgLn1kxtoR vgcuJzb6YE1BKNXUaUq1bjgsiRoDabUfNqvJFa6IZ4fEAiSyOnZBkKeNgOWuc+tBMwjf oT5vfFhUKZgSF0bURN6tkMlpyqikGgs/abz9iv2kKcC8Kk/+dEqpYa+oApM2QFNpTTTo Wdq1uU0DZ5BF2ysAToQ3Rvan4GmWPr6DGwKih+aixaOc3OGzfZRyrpgakxQMi0BDBwro k/ow== X-Gm-Message-State: APjAAAUXlWRt5TWRtMCE6LL1rqOo4IYXkLjVjmOiMUjiik3pZd7AdZ+4 Ttq7Lr0Ohn2iS/0/lz9vVudbLQ== X-Received: by 2002:a7b:cbd8:: with SMTP id n24mr3221074wmi.2.1559050621491; Tue, 28 May 2019 06:37:01 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:c8c7:f81b:b165:1aa7]) by smtp.gmail.com with ESMTPSA id 95sm8652668wrk.70.2019.05.28.06.37.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 06:37:00 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, Ard Biesheuvel , Masahisa Kojima , Linus Walleij , Marc Zyngier , Graeme Gregory , Lorenzo Pieralisi , Mika Westerberg , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v4 4/4] gpio: mb86s7x: enable ACPI support Date: Tue, 28 May 2019 15:36:47 +0200 Message-Id: <20190528133647.3362-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190528133647.3362-1-ard.biesheuvel@linaro.org> References: <20190528133647.3362-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Make the mb86s7x GPIO block discoverable via ACPI. In addition, add support for ACPI GPIO interrupts routed via platform interrupts, by wiring the two together via the to_irq() gpiochip callback. Reviewed-by: Linus Walleij Signed-off-by: Ard Biesheuvel --- drivers/gpio/gpio-mb86s7x.c | 51 +++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) -- 2.20.1 diff --git a/drivers/gpio/gpio-mb86s7x.c b/drivers/gpio/gpio-mb86s7x.c index 9308081e0a4a..64027f57a8aa 100644 --- a/drivers/gpio/gpio-mb86s7x.c +++ b/drivers/gpio/gpio-mb86s7x.c @@ -14,6 +14,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -27,6 +28,8 @@ #include #include +#include "gpiolib.h" + /* * Only first 8bits of a register correspond to each pin, * so there are 4 registers for 32 pins. @@ -143,6 +146,20 @@ static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value) spin_unlock_irqrestore(&gchip->lock, flags); } +static int mb86s70_gpio_to_irq(struct gpio_chip *gc, unsigned int offset) +{ + int irq, index; + + for (index = 0;; index++) { + irq = platform_get_irq(to_platform_device(gc->parent), index); + if (irq <= 0) + break; + if (irq_get_irq_data(irq)->hwirq == offset) + return irq; + } + return -EINVAL; +} + static int mb86s70_gpio_probe(struct platform_device *pdev) { struct mb86s70_gpio_chip *gchip; @@ -158,13 +175,15 @@ static int mb86s70_gpio_probe(struct platform_device *pdev) if (IS_ERR(gchip->base)) return PTR_ERR(gchip->base); - gchip->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(gchip->clk)) - return PTR_ERR(gchip->clk); + if (!has_acpi_companion(&pdev->dev)) { + gchip->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(gchip->clk)) + return PTR_ERR(gchip->clk); - ret = clk_prepare_enable(gchip->clk); - if (ret) - return ret; + ret = clk_prepare_enable(gchip->clk); + if (ret) + return ret; + } spin_lock_init(&gchip->lock); @@ -180,19 +199,28 @@ static int mb86s70_gpio_probe(struct platform_device *pdev) gchip->gc.parent = &pdev->dev; gchip->gc.base = -1; + if (has_acpi_companion(&pdev->dev)) + gchip->gc.to_irq = mb86s70_gpio_to_irq; + ret = gpiochip_add_data(&gchip->gc, gchip); if (ret) { dev_err(&pdev->dev, "couldn't register gpio driver\n"); clk_disable_unprepare(gchip->clk); + return ret; } - return ret; + if (has_acpi_companion(&pdev->dev)) + acpi_gpiochip_request_interrupts(&gchip->gc); + + return 0; } static int mb86s70_gpio_remove(struct platform_device *pdev) { struct mb86s70_gpio_chip *gchip = platform_get_drvdata(pdev); + if (has_acpi_companion(&pdev->dev)) + acpi_gpiochip_free_interrupts(&gchip->gc); gpiochip_remove(&gchip->gc); clk_disable_unprepare(gchip->clk); @@ -205,10 +233,19 @@ static const struct of_device_id mb86s70_gpio_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, mb86s70_gpio_dt_ids); +#ifdef CONFIG_ACPI +static const struct acpi_device_id mb86s70_gpio_acpi_ids[] = { + { "SCX0007" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(acpi, mb86s70_gpio_acpi_ids); +#endif + static struct platform_driver mb86s70_gpio_driver = { .driver = { .name = "mb86s70-gpio", .of_match_table = mb86s70_gpio_dt_ids, + .acpi_match_table = ACPI_PTR(mb86s70_gpio_acpi_ids), }, .probe = mb86s70_gpio_probe, .remove = mb86s70_gpio_remove,