From patchwork Mon May 25 11:41:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 6473781 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3D3AAC0020 for ; Mon, 25 May 2015 11:50:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 920E52041A for ; Mon, 25 May 2015 11:50:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8408220497 for ; Mon, 25 May 2015 11:50:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ywqoq-0003l8-Ji; Mon, 25 May 2015 11:45:20 +0000 Received: from mail-lb0-x231.google.com ([2a00:1450:4010:c04::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ywqmi-000260-5Z for linux-arm-kernel@lists.infradead.org; Mon, 25 May 2015 11:43:12 +0000 Received: by lbbuc2 with SMTP id uc2so50146532lbb.2 for ; Mon, 25 May 2015 04:42:35 -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=eRRTf1rrltnuhjzL8cy+ZU7aj+GTjyw9SQMzFeFRito=; b=Z222HtWRL2djHkKOEzEj5eIHdCqZUf8MnE4ktHLtLZrpIqCGWzUAuiYVCiJ++oGNuv WZY/VL/4eri3UfOtNy0LGuKD/9H9a3emaSxMQ5Z14S80nI+ke2mHk/wOq9HpHRv0R6vP 7il1+XY8cAZBI1LHieKuGm8E1V+NlKHjXIYoBwcchvS3Hl7CpvXzLfw/cfDxGYQwPmWo Cc2+MuNkPqVBeVaog2V5nwDmSQECWVb0lRzfVk/W8VHYUXXyBM577eFIW1BaLQUaO5n/ 6gM3peBoITnRI8PGy6FGQckFMAAD1SLglIJbISLNDmtOfeE/AjYryP1e10tZpKabd/VW u+xg== X-Received: by 10.112.235.133 with SMTP id um5mr18434267lbc.7.1432554155879; Mon, 25 May 2015 04:42:35 -0700 (PDT) Received: from anuminas.rup.mentorg.com (ppp89-110-13-209.pppoe.avangarddsl.ru. [89.110.13.209]) by mx.google.com with ESMTPSA id si3sm2315895lbb.32.2015.05.25.04.42.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 May 2015 04:42:34 -0700 (PDT) From: Dmitry Eremin-Solenikov To: Russell King , Daniel Mack , Robert Jarzmik , Linus Walleij , Alexandre Courbot , Dmitry Torokhov , Samuel Ortiz , Lee Jones , Mark Brown , Jingoo Han , Liam Girdwood , Andrea Adami Subject: [PATCH v4 09/18] gpio: locomo: implement per-pin irq handling Date: Mon, 25 May 2015 14:41:44 +0300 Message-Id: <1432554113-26280-10-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1432554113-26280-1-git-send-email-dbaryshkov@gmail.com> References: <1432554113-26280-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150525_044308_443946_3CB3FCA8 X-CRM114-Status: GOOD ( 17.18 ) X-Spam-Score: -0.8 (/) Cc: linux-gpio@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 Reviewed-by: Linus Walleij --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-locomo.c | 117 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 4542684..6b77614 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -737,6 +737,7 @@ config GPIO_KEMPLD config GPIO_LOCOMO bool "Sharp LoCoMo GPIO support" depends on MFD_LOCOMO + select GPIOLIB_IRQCHIP help Select this to support GPIO pins on Sharp LoCoMo Grid Array found in Sharp Zaurus collie and poodle models. diff --git a/drivers/gpio/gpio-locomo.c b/drivers/gpio/gpio-locomo.c index dd9a1ca..75dbf6b 100644 --- a/drivers/gpio/gpio-locomo.c +++ b/drivers/gpio/gpio-locomo.c @@ -16,13 +16,15 @@ #include #include #include -#include +#include #include +#include #include #include struct locomo_gpio { struct regmap *regmap; + int irq; struct gpio_chip gpio; @@ -79,6 +81,99 @@ static int locomo_gpio_direction_output(struct gpio_chip *chip, return 0; } +static void +locomo_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) +{ + struct gpio_chip *chip = irq_get_handler_data(irq); + struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio); + struct irq_chip *irqchip = irq_desc_get_chip(desc); + unsigned int gir; + unsigned int gpd; + unsigned int req; + + chained_irq_enter(irqchip, desc); + + while (1) { + regmap_read(lg->regmap, LOCOMO_GIR, &gir); + regmap_read(lg->regmap, LOCOMO_GPD, &gpd); + req = gir & gpd; + + if (!req) + break; + + generic_handle_irq(irq_find_mapping(lg->gpio.irqdomain, + ffs(req) - 1)); + } + + chained_irq_exit(irqchip, desc); +} + +static void locomo_gpio_ack_irq(struct irq_data *d) +{ + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio); + unsigned int mask = BIT(d->hwirq); + + regmap_update_bits(lg->regmap, LOCOMO_GWE, mask, mask); + regmap_update_bits(lg->regmap, LOCOMO_GIS, mask, 0); + regmap_update_bits(lg->regmap, LOCOMO_GWE, mask, 0); +} + +static void locomo_gpio_mask_irq(struct irq_data *d) +{ + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio); + unsigned int mask = BIT(d->hwirq); + + regmap_update_bits(lg->regmap, LOCOMO_GIE, mask, 0); +} + +static void locomo_gpio_unmask_irq(struct irq_data *d) +{ + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio); + unsigned int mask = BIT(d->hwirq); + + regmap_update_bits(lg->regmap, LOCOMO_GIE, mask, mask); +} + +static int locomo_gpio_type_irq(struct irq_data *d, unsigned int type) +{ + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio); + unsigned int mask; + + mask = BIT(d->hwirq); + + 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; + + regmap_write(lg->regmap, LOCOMO_GRIE, lg->rising_edge); + regmap_write(lg->regmap, LOCOMO_GFIE, lg->falling_edge); + + return 0; +} + +static struct irq_chip locomo_gpio_irq_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_irq, +}; + #ifdef CONFIG_PM_SLEEP static int locomo_gpio_suspend(struct device *dev) { @@ -119,6 +214,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->regmap = dev_get_regmap(pdev->dev.parent, NULL); if (!lg->regmap) return -EINVAL; @@ -130,6 +229,7 @@ static int locomo_gpio_probe(struct platform_device *pdev) regmap_write(lg->regmap, LOCOMO_GPD, 0x00); regmap_write(lg->regmap, LOCOMO_GIE, 0x00); + lg->gpio.dev = &pdev->dev; lg->gpio.base = pdata ? pdata->gpio_base : -1; lg->gpio.label = "locomo-gpio"; lg->gpio.ngpio = 16; @@ -142,7 +242,22 @@ static int locomo_gpio_probe(struct platform_device *pdev) if (ret) return ret; + ret = gpiochip_irqchip_add(&lg->gpio, &locomo_gpio_irq_chip, 0, + handle_level_irq, IRQ_TYPE_NONE); + if (ret) { + dev_err(&pdev->dev, "Failed to add irq chip\n"); + goto err_rm_gpiochip; + } + + gpiochip_set_chained_irqchip(&lg->gpio, &locomo_gpio_irq_chip, lg->irq, + locomo_gpio_irq_handler); + return 0; + +err_rm_gpiochip: + gpiochip_remove(&lg->gpio); + + return ret; } static int locomo_gpio_remove(struct platform_device *pdev)