From patchwork Wed Mar 22 15:38:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 742149 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 3vpDPZ4Sxlz9s2s for ; Thu, 23 Mar 2017 02:39:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935422AbdCVPjN (ORCPT ); Wed, 22 Mar 2017 11:39:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34530 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935098AbdCVPjC (ORCPT ); Wed, 22 Mar 2017 11:39:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 472CDC04BD58; Wed, 22 Mar 2017 15:39:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 472CDC04BD58 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=hdegoede@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 472CDC04BD58 Received: from shalem.localdomain.com (ovpn-117-206.ams2.redhat.com [10.36.117.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCCF77F395; Wed, 22 Mar 2017 15:39:00 +0000 (UTC) From: Hans de Goede To: Mika Westerberg , Heikki Krogerus , Linus Walleij Cc: Hans de Goede , Andy Shevchenko , linux-gpio@vger.kernel.org Subject: [PATCH v2] pinctrl: cherryview: Add support for GMMR GPIO opregion Date: Wed, 22 Mar 2017 16:38:58 +0100 Message-Id: <20170322153858.19656-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 22 Mar 2017 15:39:02 +0000 (UTC) Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On some Cherry Trail devices the ASL uses the GMMR GPIO to access GPIOs so as to serialize MMIO accesses to GPIO registers with the OS, because: "Due to a silicon issue, a shared lock must be used to prevent concurrent accesses across the 4 GPIO controllers. See Intel Atom Z8000 Processor Series Specification Update (Rev. 005), errata #CHT34, for further information." This commit adds support for this opregion, this fixes a number of ASL errors on my Ezpad mini3 tablet and makes the otg port device/host muxing which is controlled in firmware on this model work properly. Signed-off-by: Hans de Goede Reviewed-by: Andy Shevchenko Acked-by: Mika Westerberg --- Changes in v2: -Call acpi_remove_address_space_handler on remove --- drivers/pinctrl/intel/pinctrl-cherryview.c | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c index f80134e..4246493 100644 --- a/drivers/pinctrl/intel/pinctrl-cherryview.c +++ b/drivers/pinctrl/intel/pinctrl-cherryview.c @@ -148,6 +148,7 @@ struct chv_community { size_t ngpio_ranges; size_t ngpios; size_t nirqs; + acpi_adr_space_type acpi_space_id; }; struct chv_pin_context { @@ -404,6 +405,7 @@ static const struct chv_community southwest_community = { * trigger GPEs. */ .nirqs = 8, + .acpi_space_id = 0x91, }; static const struct pinctrl_pin_desc north_pins[] = { @@ -493,6 +495,7 @@ static const struct chv_community north_community = { * GPEs. */ .nirqs = 8, + .acpi_space_id = 0x92, }; static const struct pinctrl_pin_desc east_pins[] = { @@ -536,6 +539,7 @@ static const struct chv_community east_community = { .ngpio_ranges = ARRAY_SIZE(east_gpio_ranges), .ngpios = ARRAY_SIZE(east_pins), .nirqs = 16, + .acpi_space_id = 0x93, }; static const struct pinctrl_pin_desc southeast_pins[] = { @@ -662,6 +666,7 @@ static const struct chv_community southeast_community = { .ngpio_ranges = ARRAY_SIZE(southeast_gpio_ranges), .ngpios = ARRAY_SIZE(southeast_pins), .nirqs = 16, + .acpi_space_id = 0x94, }; static const struct chv_community *chv_communities[] = { @@ -1586,11 +1591,34 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) return 0; } +static acpi_status chv_pinctrl_mmio_access_handler(u32 function, + acpi_physical_address address, u32 bits, u64 *value, + void *handler_context, void *region_context) +{ + struct chv_pinctrl *pctrl = region_context; + unsigned long flags; + acpi_status ret = AE_OK; + + raw_spin_lock_irqsave(&chv_lock, flags); + + if (function == ACPI_WRITE) + chv_writel((u32)(*value), pctrl->regs + (u32)address); + else if (function == ACPI_READ) + *value = readl(pctrl->regs + (u32)address); + else + ret = AE_BAD_PARAMETER; + + raw_spin_unlock_irqrestore(&chv_lock, flags); + + return AE_OK; +} + static int chv_pinctrl_probe(struct platform_device *pdev) { struct chv_pinctrl *pctrl; struct acpi_device *adev; struct resource *res; + acpi_status status; int ret, irq, i; adev = ACPI_COMPANION(&pdev->dev); @@ -1646,11 +1674,29 @@ static int chv_pinctrl_probe(struct platform_device *pdev) if (ret) return ret; + status = acpi_install_address_space_handler(adev->handle, + pctrl->community->acpi_space_id, + chv_pinctrl_mmio_access_handler, + NULL, pctrl); + if (ACPI_FAILURE(status)) + dev_err(&pdev->dev, "failed to install ACPI addr space handler\n"); + platform_set_drvdata(pdev, pctrl); return 0; } +static int chv_pinctrl_remove(struct platform_device *pdev) +{ + struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); + + acpi_remove_address_space_handler(ACPI_COMPANION(&pdev->dev), + pctrl->community->acpi_space_id, + chv_pinctrl_mmio_access_handler); + + return 0; +} + #ifdef CONFIG_PM_SLEEP static int chv_pinctrl_suspend_noirq(struct device *dev) { @@ -1758,6 +1804,7 @@ MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match); static struct platform_driver chv_pinctrl_driver = { .probe = chv_pinctrl_probe, + .remove = chv_pinctrl_remove, .driver = { .name = "cherryview-pinctrl", .pm = &chv_pinctrl_pm_ops,