Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp402718yba; Wed, 24 Apr 2019 03:20:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxp3PQLa71f3qOj5X86FQzys3W+1PQ52IioZffeeSx7p1+98odFR3KtE2OILmVDw/K4G8MZ X-Received: by 2002:a63:750c:: with SMTP id q12mr29991370pgc.133.1556101256330; Wed, 24 Apr 2019 03:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101256; cv=none; d=google.com; s=arc-20160816; b=Lw6WLOJ+hC/GLyYFPOTY1IPjhvFIzer+Ha+612HwY8y1oz2X0iuN4RTjZVYEfwjpgg 2p1QPhpMOFKGwOU/n5NrLVJFNVz/pjRIg8eGYoMRrp5/inJC80GfDJi26XNA/4B000bd /EjI1GyhjZSoCqIxz/jJjpXjXSywtBZJ3ssEyJ5WuMkQONTz1hvbsyVdVq1A+tSj9LD6 t7lPYddnqSS8kD3esCaSQCtRRKjS36MG49fzOiXt7FHA2PB6dAHks5Q9VOUQolW9/T8k I7dKpSeZcKNDm02WBktCJPo4ZRaGcYiiuhCsO5w1z20QfwQptNA3hhYjWAsYlJGHWlTf aE0g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=UPfV/DrgJyxtqH6DzH3OLlc/Hf1Dl28eZ0hWeJ9raqA=; b=JbBGISsDWq6kuyYH+FR1oiZSw8w2glI9E+KxQh7epsPrYAqJV5gO+XnRLUfPdAAluD vK+rvGTIiMt2fN6nkFrY8vneEBse+/l1nI4hJ6zbO9kKMysRysXdtKnmwHGBKLQypyBF it9Lu0a0Vqo/pOQB+spDWgPa7B1uoxt8fSv4t0S1uDjCsVEFiPZqz4brVNZONYP2RHvO ff2nOy6ACXaMFCPbUWlmcnJNdXu0t8KErTrqve6U8+4LVJ59TonUBoxpH66FUPPGakTR bEuVjQdR5YVKwUM6HFENbDEvxfretg1Ed5gudg2S+oMXss/Tb/KYNPK4dRwSbhvw5349 4pwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d13si17818334pgg.1.2019.04.24.03.20.40; Wed, 24 Apr 2019 03:20:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729790AbfDXIMy (ORCPT + 99 others); Wed, 24 Apr 2019 04:12:54 -0400 Received: from lizzard.sbs.de ([194.138.37.39]:45866 "EHLO lizzard.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727350AbfDXIMx (ORCPT ); Wed, 24 Apr 2019 04:12:53 -0400 Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by lizzard.sbs.de (8.15.2/8.15.2) with ESMTPS id x3O8CiGD021031 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Apr 2019 10:12:44 +0200 Received: from [139.22.114.195] ([139.22.114.195]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id x3O8Cgkw010305; Wed, 24 Apr 2019 10:12:42 +0200 Subject: Re: [PATCH 2/2] gpio: sch: Add interrupt support To: Mika Westerberg Cc: Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Linux Kernel Mailing List , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, "Rafael J. Wysocki" References: <20190424075816.GU2654@lahna.fi.intel.com> From: Jan Kiszka Message-ID: <8999d3f8-d169-eb85-bd2f-08c99d184ea2@siemens.com> Date: Wed, 24 Apr 2019 10:12:42 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: <20190424075816.GU2654@lahna.fi.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24.04.19 09:58, Mika Westerberg wrote: > +Rafael and linux-acpi. > > On Thu, Apr 18, 2019 at 11:23:49AM +0200, Jan Kiszka wrote: >> From: Jan Kiszka >> >> Validated on the Quark platform, this adds interrupt support on rising >> and/or falling edges. > > The irqchip parts look good to me but but the ACPI SCI handling seems > weird. This is typically handled by ACPI core based on the values read > from FADT ACPI table. What does it contain on this Quark platform? There is no FADT on the original Quark firmware, nor did we add one. As we are talking about existing devices, possibly not only Quarks, I was going down the ACPI-independent way to hook into the interrupt. But I'm open to learn about better alternatives. Jan > >> Signed-off-by: Jan Kiszka >> --- >> drivers/gpio/gpio-sch.c | 142 +++++++++++++++++++++++++++++++++++++++++++++--- >> 1 file changed, 135 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c >> index fb143f28c386..9459f1920996 100644 >> --- a/drivers/gpio/gpio-sch.c >> +++ b/drivers/gpio/gpio-sch.c >> @@ -18,12 +18,17 @@ >> #define GEN 0x00 >> #define GIO 0x04 >> #define GLV 0x08 >> +#define GTPE 0x0c >> +#define GTNE 0x10 >> +#define GGPE 0x14 >> +#define GTS 0x1c >> >> struct sch_gpio { >> struct gpio_chip chip; >> spinlock_t lock; >> unsigned short iobase; >> unsigned short resume_base; >> + int irq_base; >> }; >> >> static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio, >> @@ -79,10 +84,11 @@ static void sch_gpio_reg_set(struct sch_gpio *sch, unsigned gpio, unsigned reg, >> static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num) >> { >> struct sch_gpio *sch = gpiochip_get_data(gc); >> + unsigned long flags; >> >> - spin_lock(&sch->lock); >> + spin_lock_irqsave(&sch->lock, flags); >> sch_gpio_reg_set(sch, gpio_num, GIO, 1); >> - spin_unlock(&sch->lock); >> + spin_unlock_irqrestore(&sch->lock, flags); >> return 0; >> } >> >> @@ -95,20 +101,22 @@ static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num) >> static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) >> { >> struct sch_gpio *sch = gpiochip_get_data(gc); >> + unsigned long flags; >> >> - spin_lock(&sch->lock); >> + spin_lock_irqsave(&sch->lock, flags); >> sch_gpio_reg_set(sch, gpio_num, GLV, val); >> - spin_unlock(&sch->lock); >> + spin_unlock_irqrestore(&sch->lock, flags); >> } >> >> static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num, >> int val) >> { >> struct sch_gpio *sch = gpiochip_get_data(gc); >> + unsigned long flags; >> >> - spin_lock(&sch->lock); >> + spin_lock_irqsave(&sch->lock, flags); >> sch_gpio_reg_set(sch, gpio_num, GIO, 0); >> - spin_unlock(&sch->lock); >> + spin_unlock_irqrestore(&sch->lock, flags); >> >> /* >> * according to the datasheet, writing to the level register has no >> @@ -130,6 +138,12 @@ static int sch_gpio_get_direction(struct gpio_chip *gc, unsigned gpio_num) >> return sch_gpio_reg_get(sch, gpio_num, GIO); >> } >> >> +static int sch_gpio_to_irq(struct gpio_chip *gpio, unsigned int offset) >> +{ >> + struct sch_gpio *sch = gpiochip_get_data(gpio); >> + return sch->irq_base + offset; >> +} >> + >> static const struct gpio_chip sch_gpio_chip = { >> .label = "sch_gpio", >> .owner = THIS_MODULE, >> @@ -138,12 +152,94 @@ static const struct gpio_chip sch_gpio_chip = { >> .direction_output = sch_gpio_direction_out, >> .set = sch_gpio_set, >> .get_direction = sch_gpio_get_direction, >> + .to_irq = sch_gpio_to_irq, >> }; >> >> +static u32 sch_sci_handler(void *context) >> +{ >> + struct sch_gpio *sch = context; >> + unsigned long core_status, resume_status; >> + unsigned int resume_gpios, offset; >> + >> + core_status = inl(sch->iobase + GTS); >> + resume_status = inl(sch->iobase + GTS + 0x20); >> + >> + if (core_status == 0 && resume_status == 0) >> + return ACPI_INTERRUPT_NOT_HANDLED; >> + >> + for_each_set_bit(offset, &core_status, sch->resume_base) >> + generic_handle_irq(sch->irq_base + offset); >> + >> + resume_gpios = sch->chip.ngpio - sch->resume_base; >> + for_each_set_bit(offset, &resume_status, resume_gpios) >> + generic_handle_irq(sch->irq_base + sch->resume_base + offset); >> + >> + outl(core_status, sch->iobase + GTS); >> + outl(resume_status, sch->iobase + GTS + 0x20); >> + >> + return ACPI_INTERRUPT_HANDLED; >> +} >> + >> +static int sch_irq_type(struct irq_data *d, unsigned int type) >> +{ >> + struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); >> + struct sch_gpio *sch = gc->private; >> + unsigned int gpio_num = d->irq - sch->irq_base; >> + int rising = 0; >> + int falling = 0; >> + >> + switch (type & IRQ_TYPE_SENSE_MASK) { >> + case IRQ_TYPE_EDGE_RISING: >> + rising = 1; >> + break; >> + case IRQ_TYPE_EDGE_FALLING: >> + falling = 1; >> + break; >> + case IRQ_TYPE_EDGE_BOTH: >> + rising = 1; >> + falling = 1; >> + break; >> + default: >> + return -EINVAL; >> + } >> + >> + spin_lock(&sch->lock); >> + sch_gpio_reg_set(sch, gpio_num, GTPE, rising); >> + sch_gpio_reg_set(sch, gpio_num, GTNE, falling); >> + spin_unlock(&sch->lock); >> + >> + return 0; >> +} >> + >> +static void sch_irq_set_enable(struct irq_data *d, int val) >> +{ >> + struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); >> + struct sch_gpio *sch = gc->private; >> + unsigned int gpio_num = d->irq - sch->irq_base; >> + >> + spin_lock(&sch->lock); >> + sch_gpio_reg_set(sch, gpio_num, GGPE, val); >> + spin_unlock(&sch->lock); >> +} >> + >> +static void sch_irq_mask(struct irq_data *d) >> +{ >> + sch_irq_set_enable(d, 0); >> +} >> + >> +static void sch_irq_unmask(struct irq_data *d) >> +{ >> + sch_irq_set_enable(d, 1); >> +} >> + >> static int sch_gpio_probe(struct platform_device *pdev) >> { >> + struct irq_chip_generic *gc; >> + struct irq_chip_type *ct; >> struct sch_gpio *sch; >> struct resource *res; >> + acpi_status status; >> + int irq_base, ret; >> >> sch = devm_kzalloc(&pdev->dev, sizeof(*sch), GFP_KERNEL); >> if (!sch) >> @@ -203,7 +299,39 @@ static int sch_gpio_probe(struct platform_device *pdev) >> >> platform_set_drvdata(pdev, sch); >> >> - return devm_gpiochip_add_data(&pdev->dev, &sch->chip, sch); >> + ret = devm_gpiochip_add_data(&pdev->dev, &sch->chip, sch); >> + if (ret) >> + return ret; >> + >> + irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, sch->chip.ngpio, >> + NUMA_NO_NODE); >> + if (irq_base < 0) >> + return irq_base; >> + sch->irq_base = irq_base; >> + >> + gc = devm_irq_alloc_generic_chip(&pdev->dev, "sch_gpio", 1, irq_base, >> + NULL, handle_simple_irq); >> + if (!gc) >> + return -ENOMEM; >> + >> + gc->private = sch; >> + ct = gc->chip_types; >> + >> + ct->chip.irq_mask = sch_irq_mask; >> + ct->chip.irq_unmask = sch_irq_unmask; >> + ct->chip.irq_set_type = sch_irq_type; >> + >> + ret = devm_irq_setup_generic_chip(&pdev->dev, gc, >> + IRQ_MSK(sch->chip.ngpio), >> + 0, IRQ_NOREQUEST | IRQ_NOPROBE, 0); >> + if (ret) >> + return ret; >> + >> + status = acpi_install_sci_handler(sch_sci_handler, sch); >> + if (ACPI_FAILURE(status)) >> + return -EINVAL; >> + >> + return 0; >> } >> >> static struct platform_driver sch_gpio_driver = { >> -- >> 2.16.4 -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux