From patchwork Tue Oct 28 00:02:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 5167341 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 729A7C11AC for ; Tue, 28 Oct 2014 00:03:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 092672017A for ; Tue, 28 Oct 2014 00:03:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 915DF20219 for ; Tue, 28 Oct 2014 00:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753155AbaJ1ADC (ORCPT ); Mon, 27 Oct 2014 20:03:02 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:58306 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753107AbaJ1ADA (ORCPT ); Mon, 27 Oct 2014 20:03:00 -0400 Received: by mail-wg0-f46.google.com with SMTP id x13so2528246wgg.5 for ; Mon, 27 Oct 2014 17:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oUEyceLGxBjnxZgFkhWYJ99x7QVD6JzhiZFikj5VclM=; b=k0fpQAA1WBd30+KTgQVVQlfoc0MYszDAAlDqrFbr7IRewCu4h5FqF/cMZHBdG2wu7m BCAWFTv4JMr7qTtY0NXdfuurGv6MUEenU3jGsQuUqlVUq7D39X2K5WLr0S+/pS0KRyTY mG1/jLwcZop3I31n/xa/gpumycnwTbcAukXZZ+eLZNYe7twYgFfuHf4tb3upALS50OEr H5zma6sUqRA6y5Mkx9dWJsnM/cdHs8ZI6yEre56L21gDxgn8VzDi8d3J7Uzh0PzXzBir 5cNPmprpVH5BPHaYyAkazv+GNeW1iaT8TvPxjQG906HH0hGEucpZ1+T3YkAnL6qakNBm Rnog== X-Received: by 10.180.73.103 with SMTP id k7mr23967721wiv.83.1414454578787; Mon, 27 Oct 2014 17:02:58 -0700 (PDT) Received: from fangorn.rup.mentorg.com (nat-min.mentorg.com. [139.181.32.34]) by mx.google.com with ESMTPSA id fq1sm13495340wib.12.2014.10.27.17.02.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Oct 2014 17:02:58 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-spi@vger.kernel.org, linux-fbdev@vger.kernel.org, alsa-devel@alsa-project.org Cc: Andrea Adami , Russell King , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Linus Walleij , Alexandre Courbot , Dmitry Torokhov , Bryan Wu , Richard Purdie , Samuel Ortiz , Lee Jones , Mark Brown , Jingoo Han , Liam Girdwood Subject: [PATCH 14/15] gpio: locomo: implement per-pin irq handling Date: Tue, 28 Oct 2014 03:02:07 +0300 Message-Id: <1414454528-24240-15-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1414454528-24240-1-git-send-email-dbaryshkov@gmail.com> References: <1414454528-24240-1-git-send-email-dbaryshkov@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP LoCoMo has a possibility to generate per-GPIO edge irqs. Support for that was there in old locomo driver, got 'cleaned up' during old driver IRQ cascading cleanup and is now reimplemented. It is expected that SL-5500 (collie) will use locomo gpio irqs for mmc detection irq. Signed-off-by: Dmitry Eremin-Solenikov --- drivers/gpio/gpio-locomo.c | 158 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/drivers/gpio/gpio-locomo.c b/drivers/gpio/gpio-locomo.c index 3b54b07..6ef0fc4 100644 --- a/drivers/gpio/gpio-locomo.c +++ b/drivers/gpio/gpio-locomo.c @@ -18,13 +18,18 @@ #include #include #include +#include #include +#define LOCOMO_GPIO_NR_IRQS 16 + struct locomo_gpio { void __iomem *regs; + int irq; spinlock_t lock; struct gpio_chip gpio; + int irq_base; u16 rising_edge; u16 falling_edge; @@ -114,6 +119,148 @@ static int locomo_gpio_direction_output(struct gpio_chip *chip, return 0; } +static int locomo_gpio_to_irq(struct gpio_chip *chip, unsigned offset) +{ + struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio); + + return lg->irq_base + offset; +} + +static void +locomo_gpio_handler(unsigned int irq, struct irq_desc *desc) +{ + u16 req; + struct locomo_gpio *lg = irq_get_handler_data(irq); + int i = lg->irq_base; + + req = readw(lg->regs + LOCOMO_GIR) & + readw(lg->regs + LOCOMO_GPD); + + while (req) { + if (req & 1) + generic_handle_irq(i); + req >>= 1; + i++; + } +} + +static void locomo_gpio_ack_irq(struct irq_data *d) +{ + struct locomo_gpio *lg = irq_data_get_irq_chip_data(d); + unsigned long flags; + u16 r; + + spin_lock_irqsave(&lg->lock, flags); + + r = readw(lg->regs + LOCOMO_GWE); + r |= (0x0001 << (d->irq - lg->irq_base)); + writew(r, lg->regs + LOCOMO_GWE); + + r = readw(lg->regs + LOCOMO_GIS); + r &= ~(0x0001 << (d->irq - lg->irq_base)); + writew(r, lg->regs + LOCOMO_GIS); + + r = readw(lg->regs + LOCOMO_GWE); + r &= ~(0x0001 << (d->irq - lg->irq_base)); + writew(r, lg->regs + LOCOMO_GWE); + + spin_unlock_irqrestore(&lg->lock, flags); +} + +static void locomo_gpio_mask_irq(struct irq_data *d) +{ + struct locomo_gpio *lg = irq_data_get_irq_chip_data(d); + unsigned long flags; + u16 r; + + spin_lock_irqsave(&lg->lock, flags); + + r = readw(lg->regs + LOCOMO_GIE); + r &= ~(0x0001 << (d->irq - lg->irq_base)); + writew(r, lg->regs + LOCOMO_GIE); + + spin_unlock_irqrestore(&lg->lock, flags); +} + +static void locomo_gpio_unmask_irq(struct irq_data *d) +{ + struct locomo_gpio *lg = irq_data_get_irq_chip_data(d); + unsigned long flags; + u16 r; + + spin_lock_irqsave(&lg->lock, flags); + + r = readw(lg->regs + LOCOMO_GIE); + r |= (0x0001 << (d->irq - lg->irq_base)); + writew(r, lg->regs + LOCOMO_GIE); + + spin_unlock_irqrestore(&lg->lock, flags); +} + +static int locomo_gpio_type(struct irq_data *d, unsigned int type) +{ + unsigned int mask; + struct locomo_gpio *lg = irq_data_get_irq_chip_data(d); + unsigned long flags; + + mask = 1 << (d->irq - lg->irq_base); + + if (type == IRQ_TYPE_PROBE) { + if ((lg->rising_edge | lg->falling_edge) & mask) + return 0; + type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; + } + + if (type & IRQ_TYPE_EDGE_RISING) + lg->rising_edge |= mask; + else + lg->rising_edge &= ~mask; + if (type & IRQ_TYPE_EDGE_FALLING) + lg->falling_edge |= mask; + else + lg->falling_edge &= ~mask; + + spin_lock_irqsave(&lg->lock, flags); + + writew(lg->rising_edge, lg->regs + LOCOMO_GRIE); + writew(lg->falling_edge, lg->regs + LOCOMO_GFIE); + + spin_unlock_irqrestore(&lg->lock, flags); + + return 0; +} + +static struct irq_chip locomo_gpio_chip = { + .name = "LOCOMO-gpio", + .irq_ack = locomo_gpio_ack_irq, + .irq_mask = locomo_gpio_mask_irq, + .irq_unmask = locomo_gpio_unmask_irq, + .irq_set_type = locomo_gpio_type, +}; + +static void locomo_gpio_setup_irq(struct locomo_gpio *lg) +{ + int irq; + + lg->irq_base = irq_alloc_descs(-1, 0, LOCOMO_GPIO_NR_IRQS, -1); + + /* Install handlers for IRQ_LOCOMO_* */ + for (irq = lg->irq_base; + irq < lg->irq_base + LOCOMO_GPIO_NR_IRQS; + irq++) { + irq_set_chip_and_handler(irq, &locomo_gpio_chip, + handle_edge_irq); + irq_set_chip_data(irq, lg); + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); + } + + /* + * Install handler for IRQ_LOCOMO_HW. + */ + irq_set_handler_data(lg->irq, lg); + irq_set_chained_handler(lg->irq, locomo_gpio_handler); +} + #ifdef CONFIG_PM_SLEEP static int locomo_gpio_suspend(struct device *dev) { @@ -169,6 +316,10 @@ static int locomo_gpio_probe(struct platform_device *pdev) if (!lg) return -ENOMEM; + lg->irq = platform_get_irq(pdev, 0); + if (lg->irq < 0) + return -ENXIO; + lg->regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(lg->regs)) return PTR_ERR(lg->regs); @@ -189,11 +340,14 @@ static int locomo_gpio_probe(struct platform_device *pdev) lg->gpio.get = locomo_gpio_get; lg->gpio.direction_input = locomo_gpio_direction_input; lg->gpio.direction_output = locomo_gpio_direction_output; + lg->gpio.to_irq = locomo_gpio_to_irq; ret = gpiochip_add(&lg->gpio); if (ret) return ret; + locomo_gpio_setup_irq(lg); + return 0; } @@ -208,6 +362,10 @@ static int locomo_gpio_remove(struct platform_device *pdev) return ret; } + irq_set_chained_handler(lg->irq, NULL); + irq_set_handler_data(lg->irq, NULL); + irq_free_descs(lg->irq_base, LOCOMO_GPIO_NR_IRQS); + return 0; }