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: 5167711 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 94F519F349 for ; Tue, 28 Oct 2014 00:13:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9729D2020E for ; Tue, 28 Oct 2014 00:13:41 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4E9FC201C7 for ; Tue, 28 Oct 2014 00:13:40 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5AAB72650B4; Tue, 28 Oct 2014 01:13:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 25774264F32; Tue, 28 Oct 2014 01:05:40 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5C3D4264F0D; Tue, 28 Oct 2014 01:05:36 +0100 (CET) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by alsa0.perex.cz (Postfix) with ESMTP id 115CF2617A5 for ; Tue, 28 Oct 2014 01:02:59 +0100 (CET) Received: by mail-wi0-f180.google.com with SMTP id hi2so84376wib.7 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 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> Cc: Alexandre Courbot , Bryan Wu , Russell King , Samuel Ortiz , Lee Jones , Linus Walleij , Dmitry Torokhov , Liam Girdwood , Haojian Zhuang , Mark Brown , Andrea Adami , Jingoo Han , Richard Purdie , Robert Jarzmik , Daniel Mack Subject: [alsa-devel] [PATCH 14/15] gpio: locomo: implement per-pin irq handling X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.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; }