From patchwork Mon Apr 29 13:12:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 163019 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp1866458ill; Mon, 29 Apr 2019 06:12:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXZzTLDMk59wH8iPHjS0QAtBa9x41YgFr2T3Av30QJvz8a0xAsenWmA4McbMXKuQ/beFfh X-Received: by 2002:a17:902:29a7:: with SMTP id h36mr62178746plb.319.1556543542614; Mon, 29 Apr 2019 06:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556543542; cv=none; d=google.com; s=arc-20160816; b=WCvtBJd99rR4QwaK5AXTLDak/ut2KsnD/23xxvcMTDBQHu2YGZO0/MXc03gUfsvwVf uRTWKj3iwDZOP18B72yoPFvmfYAdcPADMLm3W6oI3FLtGLRawJHFqhnqieYN50dgJg+y MHufsfzgi010Ib3iwHccY0n3LeTRi7hzUcYHTgxmjMghzHMraExP+IBzmnzriUjgZL9V x+7r72r5X5xESGDwQHz3EjnndWlE6e+0EepA36J7wxLqFH1OfEwj6cpWwpXm7JTJMnKh P+iGPstiVbE0FnNbIp90JM+WiG9QK6po8f0H45TbyadcD+cnWUhvUqsJpN8DVgPNFs4l Ghxg== 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=EWtkEswA/ppJKsau0ucZOXQ0FjybdP/7oMBp2mQhOUw=; b=m/xguVLvC/52JRpwy/0zgBXdjqxAFnxyteMVvZ4FxXYDn5Pj0k2Wc+Wdbu6Jh9VjlC sICgO1+kMVJC0f4bnq5Rdrw3AFUj9r/BohWwXWeVoKwlODeUJHrk6QoaYFYkrEjr55ZO LrfvPu5QWjh1Y6+ld9UYZNMAI5CUyOHhet1mzROh426C1bLjSVAUAoG5NVtkF/BAetNd 7yRLZbl0RmjKkZQZ3jHWLSjaR3yUi80eGytO4DbfY2UG9BnEcZ1NjIQpvvyhv35wPruT zSRw/WvR45hcbnrsfU+g+IJCXzBhCy2CyMN9RlDDwzi34X+CEQwpLus2cejvc3yqoeAn fa2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=avQNkrkD; 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 t5si7550503plq.83.2019.04.29.06.12.22; Mon, 29 Apr 2019 06:12:22 -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=avQNkrkD; 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 S1728006AbfD2NMV (ORCPT + 9 others); Mon, 29 Apr 2019 09:12:21 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40503 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbfD2NMV (ORCPT ); Mon, 29 Apr 2019 09:12:21 -0400 Received: by mail-wm1-f68.google.com with SMTP id h11so15698034wmb.5 for ; Mon, 29 Apr 2019 06:12:19 -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=EWtkEswA/ppJKsau0ucZOXQ0FjybdP/7oMBp2mQhOUw=; b=avQNkrkDuUX/SIDLB2Sk61f/7WpPyXBxDA6gZqFxCDXCdzxT6U+W+gX9DxRmUClSwO sFUfh3j/XDAXHED0K0TkLdlz5zpmUr+MQtD4d73Q7NmxxUGAGPzu6wmYbItwxaELDhGI OChUm+KddPrwSKDBRDn2jP9Cmz8sMGNiRrM7TwxiRFa698s7flVazpEeC+9soz5p6eQZ VPyCTtMGWyHurppOIuI6fVfW5s3dN63XNlBUbJ+CBR2eLVlMDI8qaGUBJDPICuQyb9xf fwqFaWw4548vRi704SVGxALKRQtt5TRkeXVzVc98B2g7s3MjZ9Cm3eMWQ8nlT+5+uYil TRcg== 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=EWtkEswA/ppJKsau0ucZOXQ0FjybdP/7oMBp2mQhOUw=; b=t6ogQ+arA6AHq8qn/DsMpeK4aerrtrRaKgQTOxhjUR8Q3uRLGsLw4ARrR3Yk+bi1tl zrA9NOd4xmfRJnjZT1bUoELe6XcW0eupdDl+B1sfIF7h8U3vcvtiIvILMBYbM06NEzhz HPwpVMKRyKuwVzzQoPL9bee8Eu8jQyiCN7AsN+2YDdzGKjrVxwG2N9HVfW0hYbYUjpJM cAwkR6U9SzP03RvU9g0YnvVVE7zAqkSFN1EaheQnR1SKLTUxfRqnwrfySLlt6HrIbNA+ Z98AA8Wor3xSekNkOke3Ta5rgOGHUxDuu5HIH0WLYE04RIgjsXPb6Q6IhVZvcbp6wbS+ 8esA== X-Gm-Message-State: APjAAAWkSB8rwztIK2LkvTUeQICVQwQ4aOVhjV3OpACFQiyjURS726NU 9WDkzBzyGk5tZDG3PesFTHqMDA== X-Received: by 2002:a1c:2d0e:: with SMTP id t14mr17354279wmt.33.1556543539028; Mon, 29 Apr 2019 06:12:19 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:f9fc:88:6502:8fa7]) by smtp.gmail.com with ESMTPSA id s16sm5410282wrg.71.2019.04.29.06.12.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 06:12:18 -0700 (PDT) From: Ard Biesheuvel To: linux-gpio@vger.kernel.org Cc: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Masahisa Kojima , Linus Walleij , Marc Zyngier , Graeme Gregory , Lorenzo Pieralisi , Mika Westerberg , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 4/4] gpio: mb86s7x: enable ACPI support Date: Mon, 29 Apr 2019 15:12:08 +0200 Message-Id: <20190429131208.3620-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190429131208.3620-1-ard.biesheuvel@linaro.org> References: <20190429131208.3620-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. Signed-off-by: Ard Biesheuvel --- drivers/gpio/gpio-mb86s7x.c | 57 ++++++++++++++++---- 1 file changed, 48 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/drivers/gpio/gpio-mb86s7x.c b/drivers/gpio/gpio-mb86s7x.c index 3134c0d2bfe4..61ad95c3e3d2 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; @@ -160,13 +177,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 (!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); @@ -182,21 +201,32 @@ static int mb86s70_gpio_probe(struct platform_device *pdev) gchip->gc.parent = &pdev->dev; gchip->gc.base = -1; + if (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); + if (gchip->clk) + clk_disable_unprepare(gchip->clk); + return ret; } - return ret; + if (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 (ACPI_COMPANION(&pdev->dev)) + acpi_gpiochip_free_interrupts(&gchip->gc); gpiochip_remove(&gchip->gc); - clk_disable_unprepare(gchip->clk); + if (gchip->clk) + clk_disable_unprepare(gchip->clk); return 0; } @@ -207,10 +237,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,