From patchwork Wed Jun 1 09:53:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 9147005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C859460761 for ; Wed, 1 Jun 2016 09:55:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B64FF20093 for ; Wed, 1 Jun 2016 09:55:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAE0426785; Wed, 1 Jun 2016 09:55:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F3632040D for ; Wed, 1 Jun 2016 09:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757764AbcFAJyd (ORCPT ); Wed, 1 Jun 2016 05:54:33 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:33998 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757737AbcFAJy3 (ORCPT ); Wed, 1 Jun 2016 05:54:29 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8300JI07IOXF90@mailout2.w1.samsung.com>; Wed, 01 Jun 2016 10:54:24 +0100 (BST) X-AuditID: cbfec7f5-f792a6d000001302-54-574eb0d084cc Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 24.A4.04866.0D0BE475; Wed, 1 Jun 2016 10:54:24 +0100 (BST) Received: from AMDC2174.DIGITAL.local ([106.120.53.17]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8300COA7ICBX70@eusync2.samsung.com>; Wed, 01 Jun 2016 10:54:24 +0100 (BST) From: Krzysztof Kozlowski To: Kukjin Kim , Krzysztof Kozlowski , MyungJoo Ham , Chanwoo Choi , Dmitry Torokhov , Richard Purdie , Jacek Anaszewski , Lee Jones , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Liam Girdwood , Mark Brown , Alessandro Zummo , Alexandre Belloni , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org, rtc-linux@googlegroups.com Cc: r.baldyga@hackerion.com, Bartlomiej Zolnierkiewicz Subject: [PATCH v7 2/6] mfd: max8997: handle IRQs using regmap Date: Wed, 01 Jun 2016 11:53:57 +0200 Message-id: <1464774841-1439-2-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1464774841-1439-1-git-send-email-k.kozlowski@samsung.com> References: <1464774841-1439-1-git-send-email-k.kozlowski@samsung.com> In-reply-to: <1464773339-756-1-git-send-email-k.kozlowski@samsung.com> References: <1464773339-756-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRmVeSWpSXmKPExsVy+t/xK7oXNviFG3Qs47ZYcvEqu0XHtcVM FhtnrGe1mPrwCZvF9S/PWS0mPXnPbDH/yDlWi8OLXjBaTFw5mdmi9+pzRovXLwwt+h+/Zra4 //Uoo8W3Kx1MFpseX2O1uPnpG6vF5V1z2Cy2vlnHaPG59wijxYzz+5gsbjeuYLO4++8To8Xu XU9ZLfZ3djBanN5d4iDp8WTTRUaPnbPusnvsmXiSzePIzmNsHptXaHlsWtXJ5nHn2h4gb0m9 x575P1g9+rasYvSYPu8nk8fnTXIBPFFcNimpOZllqUX6dglcGbPmz2YvOLKbsaJh8X/mBsbz sxi7GDk5JARMJGbPPglli0lcuLeerYuRi0NIYCmjRNu8zUwQTiOTxONX/8Gq2ASMJTYvXwJW JSLwkU3i8vtnQAkODmaBYImfU8FqhAXsJGY9OMYKYrMIqEpM3nOFCcTmFXCT2Liumw1im5zE yWOTwWo4Bdwl7s+5AxYXAqpZ/nw/E8hITiD75xkOEFNIwFXi+wquCYz8CxgZVjGKppYmFxQn peca6RUn5haX5qXrJefnbmKERN7XHYxLj1kdYhTgYFTi4a247BsuxJpYVlyZe4hRgoNZSYR3 ziq/cCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8M3e9DxESSE8sSc1OTS1ILYLJMnFwSjUwsjbZ Fboabn/jx3yqy/aW5o/ACcn/vmyOVl4geVDrstaLBWaefNyNcwtlu5lf/D1sZHos/+rVlv4Z SzosHr8Mk7NLjzB9eel8CYeraa7B5D+cmQ5ZYXsnxf+LDa/6v8RTsl33bdJn/9n792ouOuKf PfmP1A9m5WCeI7b+qRuXCqtq2AiHlR9UYinOSDTUYi4qTgQAfItQQLgCAAA= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Robert Baldyga This patch modifies mfd driver to use regmap for handling interrupts. It allows to simplify irq handling process. This modifications needed to make small changes in function drivers, which use interrupts. Signed-off-by: Robert Baldyga Reviewed-by: Krzysztof Kozlowski [For extcon part] Acked-by: Chanwoo Choi [For the mfd part] Acked-by: Lee Jones Acked-by: Alexandre Belloni [k.kozlowski: Collect acks, rebase on v4.6-rc6] Signed-off-by: Krzysztof Kozlowski --- drivers/extcon/extcon-max8997.c | 3 +- drivers/mfd/Kconfig | 2 +- drivers/mfd/Makefile | 2 +- drivers/mfd/max8997-irq.c | 369 ------------------------------------ drivers/mfd/max8997.c | 112 ++++++++++- drivers/rtc/rtc-max8997.c | 2 +- include/linux/mfd/max8997-private.h | 63 +++++- 7 files changed, 165 insertions(+), 388 deletions(-) delete mode 100644 drivers/mfd/max8997-irq.c diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index fc812257bfc7..9d27cc23038f 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -662,7 +662,8 @@ static int max8997_muic_probe(struct platform_device *pdev) struct max8997_muic_irq *muic_irq = &muic_irqs[i]; unsigned int virq = 0; - virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq); + virq = regmap_irq_get_virq(max8997->irq_data_muic, + muic_irq->irq); if (!virq) { ret = -EINVAL; goto err_irq; diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index d7c6491ce3b9..b1bc339a91f9 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -622,7 +622,7 @@ config MFD_MAX8997 depends on I2C=y select MFD_CORE select REGMAP_I2C - select IRQ_DOMAIN + select REGMAP_IRQ help Say yes here to add support for Maxim Semiconductor MAX8997/8966. This is a Power Management IC with RTC, Flash, Fuel Gauge, Haptic, diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 42a66e19e191..cd2cd2b2c316 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -135,7 +135,7 @@ obj-$(CONFIG_MFD_MAX77843) += max77843.o obj-$(CONFIG_MFD_MAX8907) += max8907.o max8925-objs := max8925-core.o max8925-i2c.o obj-$(CONFIG_MFD_MAX8925) += max8925.o -obj-$(CONFIG_MFD_MAX8997) += max8997.o max8997-irq.o +obj-$(CONFIG_MFD_MAX8997) += max8997.o obj-$(CONFIG_MFD_MAX8998) += max8998.o max8998-irq.o pcf50633-objs := pcf50633-core.o pcf50633-irq.o diff --git a/drivers/mfd/max8997-irq.c b/drivers/mfd/max8997-irq.c deleted file mode 100644 index 6ab5f955c510..000000000000 --- a/drivers/mfd/max8997-irq.c +++ /dev/null @@ -1,369 +0,0 @@ -/* - * max8997-irq.c - Interrupt controller support for MAX8997 - * - * Copyright (C) 2011 Samsung Electronics Co.Ltd - * MyungJoo Ham - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * This driver is based on max8998-irq.c - */ - -#include -#include -#include -#include -#include -#include - -static const u8 max8997_mask_reg[] = { - [PMIC_INT1] = MAX8997_REG_INT1MSK, - [PMIC_INT2] = MAX8997_REG_INT2MSK, - [PMIC_INT3] = MAX8997_REG_INT3MSK, - [PMIC_INT4] = MAX8997_REG_INT4MSK, - [FUEL_GAUGE] = MAX8997_REG_INVALID, - [MUIC_INT1] = MAX8997_MUIC_REG_INTMASK1, - [MUIC_INT2] = MAX8997_MUIC_REG_INTMASK2, - [MUIC_INT3] = MAX8997_MUIC_REG_INTMASK3, - [GPIO_LOW] = MAX8997_REG_INVALID, - [GPIO_HI] = MAX8997_REG_INVALID, - [FLASH_STATUS] = MAX8997_REG_INVALID, -}; - -struct max8997_irq_data { - int mask; - enum max8997_irq_source group; -}; - -#define DECLARE_IRQ(idx, _group, _mask) \ - [(idx)] = { .group = (_group), .mask = (_mask) } -static const struct max8997_irq_data max8997_irqs[] = { - DECLARE_IRQ(MAX8997_PMICIRQ_PWRONR, PMIC_INT1, 1 << 0), - DECLARE_IRQ(MAX8997_PMICIRQ_PWRONF, PMIC_INT1, 1 << 1), - DECLARE_IRQ(MAX8997_PMICIRQ_PWRON1SEC, PMIC_INT1, 1 << 3), - DECLARE_IRQ(MAX8997_PMICIRQ_JIGONR, PMIC_INT1, 1 << 4), - DECLARE_IRQ(MAX8997_PMICIRQ_JIGONF, PMIC_INT1, 1 << 5), - DECLARE_IRQ(MAX8997_PMICIRQ_LOWBAT2, PMIC_INT1, 1 << 6), - DECLARE_IRQ(MAX8997_PMICIRQ_LOWBAT1, PMIC_INT1, 1 << 7), - - DECLARE_IRQ(MAX8997_PMICIRQ_JIGR, PMIC_INT2, 1 << 0), - DECLARE_IRQ(MAX8997_PMICIRQ_JIGF, PMIC_INT2, 1 << 1), - DECLARE_IRQ(MAX8997_PMICIRQ_MR, PMIC_INT2, 1 << 2), - DECLARE_IRQ(MAX8997_PMICIRQ_DVS1OK, PMIC_INT2, 1 << 3), - DECLARE_IRQ(MAX8997_PMICIRQ_DVS2OK, PMIC_INT2, 1 << 4), - DECLARE_IRQ(MAX8997_PMICIRQ_DVS3OK, PMIC_INT2, 1 << 5), - DECLARE_IRQ(MAX8997_PMICIRQ_DVS4OK, PMIC_INT2, 1 << 6), - - DECLARE_IRQ(MAX8997_PMICIRQ_CHGINS, PMIC_INT3, 1 << 0), - DECLARE_IRQ(MAX8997_PMICIRQ_CHGRM, PMIC_INT3, 1 << 1), - DECLARE_IRQ(MAX8997_PMICIRQ_DCINOVP, PMIC_INT3, 1 << 2), - DECLARE_IRQ(MAX8997_PMICIRQ_TOPOFFR, PMIC_INT3, 1 << 3), - DECLARE_IRQ(MAX8997_PMICIRQ_CHGRSTF, PMIC_INT3, 1 << 5), - DECLARE_IRQ(MAX8997_PMICIRQ_MBCHGTMEXPD, PMIC_INT3, 1 << 7), - - DECLARE_IRQ(MAX8997_PMICIRQ_RTC60S, PMIC_INT4, 1 << 0), - DECLARE_IRQ(MAX8997_PMICIRQ_RTCA1, PMIC_INT4, 1 << 1), - DECLARE_IRQ(MAX8997_PMICIRQ_RTCA2, PMIC_INT4, 1 << 2), - DECLARE_IRQ(MAX8997_PMICIRQ_SMPL_INT, PMIC_INT4, 1 << 3), - DECLARE_IRQ(MAX8997_PMICIRQ_RTC1S, PMIC_INT4, 1 << 4), - DECLARE_IRQ(MAX8997_PMICIRQ_WTSR, PMIC_INT4, 1 << 5), - - DECLARE_IRQ(MAX8997_MUICIRQ_ADCError, MUIC_INT1, 1 << 2), - DECLARE_IRQ(MAX8997_MUICIRQ_ADCLow, MUIC_INT1, 1 << 1), - DECLARE_IRQ(MAX8997_MUICIRQ_ADC, MUIC_INT1, 1 << 0), - - DECLARE_IRQ(MAX8997_MUICIRQ_VBVolt, MUIC_INT2, 1 << 4), - DECLARE_IRQ(MAX8997_MUICIRQ_DBChg, MUIC_INT2, 1 << 3), - DECLARE_IRQ(MAX8997_MUICIRQ_DCDTmr, MUIC_INT2, 1 << 2), - DECLARE_IRQ(MAX8997_MUICIRQ_ChgDetRun, MUIC_INT2, 1 << 1), - DECLARE_IRQ(MAX8997_MUICIRQ_ChgTyp, MUIC_INT2, 1 << 0), - - DECLARE_IRQ(MAX8997_MUICIRQ_OVP, MUIC_INT3, 1 << 2), -}; - -static void max8997_irq_lock(struct irq_data *data) -{ - struct max8997_dev *max8997 = irq_data_get_irq_chip_data(data); - - mutex_lock(&max8997->irqlock); -} - -static void max8997_irq_sync_unlock(struct irq_data *data) -{ - struct max8997_dev *max8997 = irq_data_get_irq_chip_data(data); - int i; - - for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) { - struct regmap *map; - u8 mask_reg = max8997_mask_reg[i]; - - if (i >= MUIC_INT1 && i <= MUIC_INT3) - map = max8997->regmap_muic; - else - map = max8997->regmap; - - if (mask_reg == MAX8997_REG_INVALID || - IS_ERR_OR_NULL(map)) - continue; - max8997->irq_masks_cache[i] = max8997->irq_masks_cur[i]; - - regmap_write(map, max8997_mask_reg[i], - max8997->irq_masks_cur[i]); - } - - mutex_unlock(&max8997->irqlock); -} - -static const inline struct max8997_irq_data * -irq_to_max8997_irq(struct max8997_dev *max8997, struct irq_data *data) -{ - return &max8997_irqs[data->hwirq]; -} - -static void max8997_irq_mask(struct irq_data *data) -{ - struct max8997_dev *max8997 = irq_data_get_irq_chip_data(data); - const struct max8997_irq_data *irq_data = irq_to_max8997_irq(max8997, - data); - - max8997->irq_masks_cur[irq_data->group] |= irq_data->mask; -} - -static void max8997_irq_unmask(struct irq_data *data) -{ - struct max8997_dev *max8997 = irq_data_get_irq_chip_data(data); - const struct max8997_irq_data *irq_data = irq_to_max8997_irq(max8997, - data); - - max8997->irq_masks_cur[irq_data->group] &= ~irq_data->mask; -} - -static struct irq_chip max8997_irq_chip = { - .name = "max8997", - .irq_bus_lock = max8997_irq_lock, - .irq_bus_sync_unlock = max8997_irq_sync_unlock, - .irq_mask = max8997_irq_mask, - .irq_unmask = max8997_irq_unmask, -}; - -#define MAX8997_IRQSRC_PMIC (1 << 1) -#define MAX8997_IRQSRC_FUELGAUGE (1 << 2) -#define MAX8997_IRQSRC_MUIC (1 << 3) -#define MAX8997_IRQSRC_GPIO (1 << 4) -#define MAX8997_IRQSRC_FLASH (1 << 5) -static irqreturn_t max8997_irq_thread(int irq, void *data) -{ - struct max8997_dev *max8997 = data; - u8 irq_reg[MAX8997_IRQ_GROUP_NR] = {}; - unsigned int irq_src; - int ret; - int i, cur_irq; - - ret = regmap_read(max8997->regmap, MAX8997_REG_INTSRC, &irq_src); - if (ret < 0) { - dev_err(max8997->dev, "Failed to read interrupt source: %d\n", - ret); - return IRQ_NONE; - } - - if (irq_src & MAX8997_IRQSRC_PMIC) { - /* PMIC INT1 ~ INT4 */ - regmap_bulk_read(max8997->regmap, MAX8997_REG_INT1, - &irq_reg[PMIC_INT1], 4); - } - if (irq_src & MAX8997_IRQSRC_FUELGAUGE) { - /* - * TODO: FUEL GAUGE - * - * This is to be supported by Max17042 driver. When - * an interrupt incurs here, it should be relayed to a - * Max17042 device that is connected (probably by - * platform-data). However, we do not have interrupt - * handling in Max17042 driver currently. The Max17042 IRQ - * driver should be ready to be used as a stand-alone device and - * a Max8997-dependent device. Because it is not ready in - * Max17042-side and it is not too critical in operating - * Max8997, we do not implement this in initial releases. - */ - irq_reg[FUEL_GAUGE] = 0; - } - if (irq_src & MAX8997_IRQSRC_MUIC) { - /* MUIC INT1 ~ INT3 */ - regmap_bulk_read(max8997->regmap_muic, MAX8997_MUIC_REG_INT1, - &irq_reg[MUIC_INT1], 3); - } - if (irq_src & MAX8997_IRQSRC_GPIO) { - /* GPIO Interrupt */ - u8 gpio_info[MAX8997_NUM_GPIO]; - - irq_reg[GPIO_LOW] = 0; - irq_reg[GPIO_HI] = 0; - - regmap_bulk_read(max8997->regmap, MAX8997_REG_GPIOCNTL1, - gpio_info, MAX8997_NUM_GPIO); - for (i = 0; i < MAX8997_NUM_GPIO; i++) { - bool interrupt = false; - - switch (gpio_info[i] & MAX8997_GPIO_INT_MASK) { - case MAX8997_GPIO_INT_BOTH: - if (max8997->gpio_status[i] != gpio_info[i]) - interrupt = true; - break; - case MAX8997_GPIO_INT_RISE: - if ((max8997->gpio_status[i] != gpio_info[i]) && - (gpio_info[i] & MAX8997_GPIO_DATA_MASK)) - interrupt = true; - break; - case MAX8997_GPIO_INT_FALL: - if ((max8997->gpio_status[i] != gpio_info[i]) && - !(gpio_info[i] & MAX8997_GPIO_DATA_MASK)) - interrupt = true; - break; - default: - break; - } - - if (interrupt) { - if (i < 8) - irq_reg[GPIO_LOW] |= (1 << i); - else - irq_reg[GPIO_HI] |= (1 << (i - 8)); - } - - } - } - if (irq_src & MAX8997_IRQSRC_FLASH) { - /* Flash Status Interrupt */ - unsigned int data; - ret = regmap_read(max8997->regmap, - MAX8997_REG_FLASHSTATUS, &data); - irq_reg[FLASH_STATUS] = data; - } - - /* Apply masking */ - for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) - irq_reg[i] &= ~max8997->irq_masks_cur[i]; - - /* Report */ - for (i = 0; i < MAX8997_IRQ_NR; i++) { - if (irq_reg[max8997_irqs[i].group] & max8997_irqs[i].mask) { - cur_irq = irq_find_mapping(max8997->irq_domain, i); - if (cur_irq) - handle_nested_irq(cur_irq); - } - } - - return IRQ_HANDLED; -} - -int max8997_irq_resume(struct max8997_dev *max8997) -{ - if (max8997->irq && max8997->irq_domain) - max8997_irq_thread(0, max8997); - return 0; -} - -static int max8997_irq_domain_map(struct irq_domain *d, unsigned int irq, - irq_hw_number_t hw) -{ - struct max8997_dev *max8997 = d->host_data; - - irq_set_chip_data(irq, max8997); - irq_set_chip_and_handler(irq, &max8997_irq_chip, handle_edge_irq); - irq_set_nested_thread(irq, 1); - irq_set_noprobe(irq); - - return 0; -} - -static const struct irq_domain_ops max8997_irq_domain_ops = { - .map = max8997_irq_domain_map, -}; - -int max8997_irq_init(struct max8997_dev *max8997) -{ - struct irq_domain *domain; - int i; - int ret; - unsigned int val; - - if (!max8997->irq) { - dev_warn(max8997->dev, "No interrupt specified.\n"); - return 0; - } - - mutex_init(&max8997->irqlock); - - /* Mask individual interrupt sources */ - for (i = 0; i < MAX8997_IRQ_GROUP_NR; i++) { - max8997->irq_masks_cur[i] = 0xff; - max8997->irq_masks_cache[i] = 0xff; - - if (IS_ERR_OR_NULL(max8997->regmap)) - continue; - if (max8997_mask_reg[i] == MAX8997_REG_INVALID) - continue; - - regmap_write(max8997->regmap, max8997_mask_reg[i], 0xff); - } - - for (i = 0; i < MAX8997_NUM_GPIO; i++) { - max8997->gpio_status[i] = (regmap_read(max8997->regmap, - MAX8997_REG_GPIOCNTL1 + i, - &val) - & MAX8997_GPIO_DATA_MASK) ? - true : false; - } - - domain = irq_domain_add_linear(NULL, MAX8997_IRQ_NR, - &max8997_irq_domain_ops, max8997); - if (!domain) { - dev_err(max8997->dev, "could not create irq domain\n"); - return -ENODEV; - } - max8997->irq_domain = domain; - - ret = request_threaded_irq(max8997->irq, NULL, max8997_irq_thread, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - "max8997-irq", max8997); - - if (ret) { - dev_err(max8997->dev, "Failed to request IRQ %d: %d\n", - max8997->irq, ret); - return ret; - } - - if (!max8997->ono) - return 0; - - ret = request_threaded_irq(max8997->ono, NULL, max8997_irq_thread, - IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | - IRQF_ONESHOT, "max8997-ono", max8997); - - if (ret) - dev_err(max8997->dev, "Failed to request ono-IRQ %d: %d\n", - max8997->ono, ret); - - return 0; -} - -void max8997_irq_exit(struct max8997_dev *max8997) -{ - if (max8997->ono) - free_irq(max8997->ono, max8997); - - if (max8997->irq) - free_irq(max8997->irq, max8997); -} diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c index f1c82110b2ab..932e22c05026 100644 --- a/drivers/mfd/max8997.c +++ b/drivers/mfd/max8997.c @@ -65,6 +65,49 @@ static const struct regmap_config max8997_regmap_config = { .max_register = MAX8997_REG_PMIC_END, }; +static const struct regmap_irq max8997_irqs[] = { + /* PMIC_INT1 interrupts */ + { .reg_offset = 0, .mask = PMIC_INT1_PWRONR_MASK, }, + { .reg_offset = 0, .mask = PMIC_INT1_PWRONF_MASK, }, + { .reg_offset = 0, .mask = PMIC_INT1_PWRON1SEC_MASK, }, + { .reg_offset = 0, .mask = PMIC_INT1_JIGONR_MASK, }, + { .reg_offset = 0, .mask = PMIC_INT1_JIGONF_MASK, }, + { .reg_offset = 0, .mask = PMIC_INT1_LOWBAT2_MASK, }, + { .reg_offset = 0, .mask = PMIC_INT1_LOWBAT1_MASK, }, + /* PMIC_INT2 interrupts */ + { .reg_offset = 1, .mask = PMIC_INT2_JIGR_MASK, }, + { .reg_offset = 1, .mask = PMIC_INT2_JIGF_MASK, }, + { .reg_offset = 1, .mask = PMIC_INT2_MR_MASK, }, + { .reg_offset = 1, .mask = PMIC_INT2_DVS1OK_MASK, }, + { .reg_offset = 1, .mask = PMIC_INT2_DVS2OK_MASK, }, + { .reg_offset = 1, .mask = PMIC_INT2_DVS3OK_MASK, }, + { .reg_offset = 1, .mask = PMIC_INT2_DVS4OK_MASK, }, + /* PMIC_INT3 interrupts */ + { .reg_offset = 2, .mask = PMIC_INT3_CHGINS_MASK, }, + { .reg_offset = 2, .mask = PMIC_INT3_CHGRM_MASK, }, + { .reg_offset = 2, .mask = PMIC_INT3_DCINOVP_MASK, }, + { .reg_offset = 2, .mask = PMIC_INT3_TOPOFFR_MASK, }, + { .reg_offset = 2, .mask = PMIC_INT3_CHGRSTF_MASK, }, + { .reg_offset = 2, .mask = PMIC_INT3_MBCHGTMEXPD_MASK, }, + /* PMIC_INT4 interrupts */ + { .reg_offset = 3, .mask = PMIC_INT4_RTC60S_MASK, }, + { .reg_offset = 3, .mask = PMIC_INT4_RTCA1_MASK, }, + { .reg_offset = 3, .mask = PMIC_INT4_RTCA2_MASK, }, + { .reg_offset = 3, .mask = PMIC_INT4_SMPL_INT_MASK, }, + { .reg_offset = 3, .mask = PMIC_INT4_RTC1S_MASK, }, + { .reg_offset = 3, .mask = PMIC_INT4_WTSR_MASK, }, +}; + +static const struct regmap_irq_chip max8997_irq_chip = { + .name = "max8997", + .status_base = MAX8997_REG_INT1, + .mask_base = MAX8997_REG_INT1MSK, + .mask_invert = false, + .num_regs = 4, + .irqs = max8997_irqs, + .num_irqs = ARRAY_SIZE(max8997_irqs), +}; + static const struct regmap_config max8997_regmap_rtc_config = { .reg_bits = 8, .val_bits = 8, @@ -83,6 +126,31 @@ static const struct regmap_config max8997_regmap_muic_config = { .max_register = MAX8997_MUIC_REG_END, }; +static const struct regmap_irq max8997_irqs_muic[] = { + /* MUIC_INT1 interrupts */ + { .reg_offset = 0, .mask = MUIC_INT1_ADC_MASK, }, + { .reg_offset = 0, .mask = MUIC_INT1_ADCLOW_MASK, }, + { .reg_offset = 0, .mask = MUIC_INT1_ADCERROR_MASK, }, + /* MUIC_INT2 interrupts */ + { .reg_offset = 1, .mask = MUIC_INT2_CHGTYP_MASK, }, + { .reg_offset = 1, .mask = MUIC_INT2_CHGDETRUN_MASK, }, + { .reg_offset = 1, .mask = MUIC_INT2_DCDTMR_MASK, }, + { .reg_offset = 1, .mask = MUIC_INT2_DBCHG_MASK, }, + { .reg_offset = 1, .mask = MUIC_INT2_VBVOLT_MASK, }, + /* MUIC_INT3 interrupts */ + { .reg_offset = 2, .mask = MUIC_INT3_OVP_MASK, }, +}; + +static const struct regmap_irq_chip max8997_irq_chip_muic = { + .name = "max8997-muic", + .status_base = MAX8997_MUIC_REG_INT1, + .mask_base = MAX8997_MUIC_REG_INTMASK1, + .mask_invert = true, + .num_regs = 3, + .irqs = max8997_irqs_muic, + .num_irqs = ARRAY_SIZE(max8997_irqs_muic), +}; + /* * Only the common platform data elements for max8997 are parsed here from the * device tree. Other sub-modules of max8997 such as pmic, rtc and others have @@ -215,9 +283,26 @@ static int max8997_i2c_probe(struct i2c_client *i2c, goto err_regmap; } - pm_runtime_set_active(max8997->dev); + ret = regmap_add_irq_chip(max8997->regmap, max8997->irq, + IRQF_ONESHOT | IRQF_SHARED | + IRQF_TRIGGER_FALLING, 0, + &max8997_irq_chip, &max8997->irq_data); + if (ret) { + dev_err(max8997->dev, "failed to add irq chip: %d\n", ret); + goto err_regmap; + } - max8997_irq_init(max8997); + ret = regmap_add_irq_chip(max8997->regmap_muic, max8997->irq, + IRQF_ONESHOT | IRQF_SHARED | + IRQF_TRIGGER_FALLING, 0, + &max8997_irq_chip_muic, + &max8997->irq_data_muic); + if (ret) { + dev_err(max8997->dev, "failed to add irq chip: %d\n", ret); + goto err_irq_muic; + } + + pm_runtime_set_active(max8997->dev); ret = mfd_add_devices(max8997->dev, -1, max8997_devs, ARRAY_SIZE(max8997_devs), @@ -239,6 +324,9 @@ static int max8997_i2c_probe(struct i2c_client *i2c, err_mfd: mfd_remove_devices(max8997->dev); + regmap_del_irq_chip(max8997->irq, max8997->irq_data_muic); +err_irq_muic: + regmap_del_irq_chip(max8997->irq, max8997->irq_data); err_regmap: i2c_unregister_device(max8997->muic); err_i2c_muic: @@ -253,6 +341,10 @@ static int max8997_i2c_remove(struct i2c_client *i2c) struct max8997_dev *max8997 = i2c_get_clientdata(i2c); mfd_remove_devices(max8997->dev); + + regmap_del_irq_chip(max8997->irq, max8997->irq_data_muic); + regmap_del_irq_chip(max8997->irq, max8997->irq_data); + i2c_unregister_device(max8997->muic); i2c_unregister_device(max8997->haptic); i2c_unregister_device(max8997->rtc); @@ -469,8 +561,11 @@ static int max8997_suspend(struct device *dev) struct i2c_client *i2c = to_i2c_client(dev); struct max8997_dev *max8997 = i2c_get_clientdata(i2c); - if (device_may_wakeup(dev)) - irq_set_irq_wake(max8997->irq, 1); + if (device_may_wakeup(dev)) { + enable_irq_wake(max8997->irq); + disable_irq(max8997->irq); + } + return 0; } @@ -479,9 +574,12 @@ static int max8997_resume(struct device *dev) struct i2c_client *i2c = to_i2c_client(dev); struct max8997_dev *max8997 = i2c_get_clientdata(i2c); - if (device_may_wakeup(dev)) - irq_set_irq_wake(max8997->irq, 0); - return max8997_irq_resume(max8997); + if (device_may_wakeup(dev)) { + disable_irq_wake(max8997->irq); + enable_irq(max8997->irq); + } + + return 0; } static const struct dev_pm_ops max8997_pm = { diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c index d017a34a9f70..4998aee0f07f 100644 --- a/drivers/rtc/rtc-max8997.c +++ b/drivers/rtc/rtc-max8997.c @@ -496,7 +496,7 @@ static int max8997_rtc_probe(struct platform_device *pdev) return ret; } - virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1); + virq = regmap_irq_get_virq(max8997->irq_data, MAX8997_PMICIRQ_RTCA1); if (!virq) { dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n"); ret = -ENXIO; diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h index ea80ef80dbf8..f42ea222988f 100644 --- a/include/linux/mfd/max8997-private.h +++ b/include/linux/mfd/max8997-private.h @@ -333,6 +333,48 @@ enum max8997_irq_source { MAX8997_IRQ_GROUP_NR, }; +#define PMIC_INT1_PWRONR_MASK (0x1 << 0) +#define PMIC_INT1_PWRONF_MASK (0x1 << 1) +#define PMIC_INT1_PWRON1SEC_MASK (0x1 << 3) +#define PMIC_INT1_JIGONR_MASK (0x1 << 4) +#define PMIC_INT1_JIGONF_MASK (0x1 << 5) +#define PMIC_INT1_LOWBAT2_MASK (0x1 << 6) +#define PMIC_INT1_LOWBAT1_MASK (0x1 << 7) + +#define PMIC_INT2_JIGR_MASK (0x1 << 0) +#define PMIC_INT2_JIGF_MASK (0x1 << 1) +#define PMIC_INT2_MR_MASK (0x1 << 2) +#define PMIC_INT2_DVS1OK_MASK (0x1 << 3) +#define PMIC_INT2_DVS2OK_MASK (0x1 << 4) +#define PMIC_INT2_DVS3OK_MASK (0x1 << 5) +#define PMIC_INT2_DVS4OK_MASK (0x1 << 6) + +#define PMIC_INT3_CHGINS_MASK (0x1 << 0) +#define PMIC_INT3_CHGRM_MASK (0x1 << 1) +#define PMIC_INT3_DCINOVP_MASK (0x1 << 2) +#define PMIC_INT3_TOPOFFR_MASK (0x1 << 3) +#define PMIC_INT3_CHGRSTF_MASK (0x1 << 5) +#define PMIC_INT3_MBCHGTMEXPD_MASK (0x1 << 7) + +#define PMIC_INT4_RTC60S_MASK (0x1 << 0) +#define PMIC_INT4_RTCA1_MASK (0x1 << 1) +#define PMIC_INT4_RTCA2_MASK (0x1 << 2) +#define PMIC_INT4_SMPL_INT_MASK (0x1 << 3) +#define PMIC_INT4_RTC1S_MASK (0x1 << 4) +#define PMIC_INT4_WTSR_MASK (0x1 << 5) + +#define MUIC_INT1_ADC_MASK (0x1 << 0) +#define MUIC_INT1_ADCLOW_MASK (0x1 << 1) +#define MUIC_INT1_ADCERROR_MASK (0x1 << 2) + +#define MUIC_INT2_CHGTYP_MASK (0x1 << 0) +#define MUIC_INT2_CHGDETRUN_MASK (0x1 << 1) +#define MUIC_INT2_DCDTMR_MASK (0x1 << 2) +#define MUIC_INT2_DBCHG_MASK (0x1 << 3) +#define MUIC_INT2_VBVOLT_MASK (0x1 << 4) + +#define MUIC_INT3_OVP_MASK (0x1 << 2) + enum max8997_irq { MAX8997_PMICIRQ_PWRONR, MAX8997_PMICIRQ_PWRONF, @@ -364,19 +406,23 @@ enum max8997_irq { MAX8997_PMICIRQ_RTC1S, MAX8997_PMICIRQ_WTSR, - MAX8997_MUICIRQ_ADCError, - MAX8997_MUICIRQ_ADCLow, + MAX8997_PMICIRQ_NR, +}; + +enum max8997_irq_muic { MAX8997_MUICIRQ_ADC, + MAX8997_MUICIRQ_ADCLow, + MAX8997_MUICIRQ_ADCError, - MAX8997_MUICIRQ_VBVolt, - MAX8997_MUICIRQ_DBChg, - MAX8997_MUICIRQ_DCDTmr, - MAX8997_MUICIRQ_ChgDetRun, MAX8997_MUICIRQ_ChgTyp, + MAX8997_MUICIRQ_ChgDetRun, + MAX8997_MUICIRQ_DCDTmr, + MAX8997_MUICIRQ_DBChg, + MAX8997_MUICIRQ_VBVolt, MAX8997_MUICIRQ_OVP, - MAX8997_IRQ_NR, + MAX8997_MUCIRQ_NR, }; #define MAX8997_NUM_GPIO 12 @@ -397,9 +443,10 @@ struct max8997_dev { struct regmap *regmap_haptic; struct regmap *regmap_muic; + struct regmap_irq_chip_data *irq_data; + struct regmap_irq_chip_data *irq_data_muic; int irq; int ono; - struct irq_domain *irq_domain; struct mutex irqlock; int irq_masks_cur[MAX8997_IRQ_GROUP_NR]; int irq_masks_cache[MAX8997_IRQ_GROUP_NR];