Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3318092yba; Mon, 6 May 2019 22:18:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/GYeUNFFHKkVX54pcxiXkiDfTMTeqj27+y3VFeXnNgr2gfc205ey3Yx0khwLvKOnKhQaS X-Received: by 2002:a65:50c2:: with SMTP id s2mr37732604pgp.112.1557206292025; Mon, 06 May 2019 22:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557206292; cv=none; d=google.com; s=arc-20160816; b=A2+AapSUEbp4XU6vYbN8aG3wFJn4nJvDGVkhrMgzxAC3vlqnf4Jgm3B+KzfRDfM2tQ Z3ZfnzZUrCEfns1iRnsH+aYK0yUm+eh3ZYxEySqgVLxzMUGg8ECSTZgeMvCExeuCYpSp lWg1y2rxZKRQNeRNLbqZRgswYTXTH+m9v/mRqOMl8jdZpprfKi66y64Pg/cxnjafvHws q7y83KG+qlzn2Cd+ED0wZjTjkohKlh+U+wyZOG6HVY1+0bRRZkN+W4QIk6HC47SEi2dK 3Rlkup6d4ZeR/QXtowQxdA3rxmPcsP5OVE+8aqZgruoq79B0aeuxsGooJenYo/1IKH/X iOnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PnRZci9BrBwrlbT3SC42Kf4W6va6zoVHliMvmYjSekw=; b=p/KFGh1Y4Y093DkCyGza+J33uTuF9wlUqrypBtZFOFN4EUZ77b3WKSJhRinXQV9B5V 82ynQ/wvbE+naSIPUFC6wgd3of73YNm4fQw/HIl++YgK4+2w2Irpn1/2DDTk2JjRaf10 tSK6t5wyK4G32uYrlxvJfu2zkKHOVEKMt46dsIuG0z3jcTm3kVpFrle8tBVOMfVHdfHx gvOVNJwez/JwoQTxk48aitN0z8U8NktXlPxuQAsw4YFZTsEK3LrvsJVqfim/ZL25uVNz IneXSD2q+5vpxEjBiuwGfB7ebD7VrzVMElGLdNXuYDIc+WLBlHbcYtONl+2c3y+4uSYw bBdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=R4gWYUEL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92si18944132plb.251.2019.05.06.22.17.55; Mon, 06 May 2019 22:18:12 -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; dkim=pass header.i=@chromium.org header.s=google header.b=R4gWYUEL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbfEGFRC (ORCPT + 99 others); Tue, 7 May 2019 01:17:02 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:39322 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbfEGFRC (ORCPT ); Tue, 7 May 2019 01:17:02 -0400 Received: by mail-qt1-f195.google.com with SMTP id y42so257373qtk.6 for ; Mon, 06 May 2019 22:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PnRZci9BrBwrlbT3SC42Kf4W6va6zoVHliMvmYjSekw=; b=R4gWYUELHr/a9/HjmfqXKJAXVjIuhPoYDw7EqSogjZVsBx0V99F9ybsk5EF5O97UOw NNN3oQsKH4/kuW+AjpMhvRT7UaSOOxbDgaeBWl2nESNlKc9PAg8LxafcE981cZ/A+HtE ODYpJOhtMlFWd4MTZd0IxbO9deUY6o5TpxpMI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PnRZci9BrBwrlbT3SC42Kf4W6va6zoVHliMvmYjSekw=; b=X7UPOmuHUc3M/LMLYRGp0L5UEcMqyJypJi0LuzcUzsRcgpRGBk7eZEcWpXp7CSJlpB HLEzpF2lPLIZ+L6vMgxiIXG4dzZliLlWt35UNCw80i5hTupgJ9FBjVg7t5KF/v4aoozG 1hcG6eyS/rCyTzwwcfeWzVLzHMQ1ypv25PXMRatWrahMyGPwnrEbMcF5ryrnqLeU4qP2 xySJM75GB5b/ze0j44oBU5+OBbtU24TV749MDrXTcV/bH9bveIHxoEoAcleUo7hKWAYv CACZo8s3UuDUOZ/mrB1nXlKGboFGVCkewbLMteHMsXR15Q5CVAJ9rez7qI00ZoDsFuIk EmTQ== X-Gm-Message-State: APjAAAUN2814uBp4S1WQlinQe5C3IRwXdxLsEM4BCNCp5ATKA67SS2lY loEwMirS+2IFFP8k19juBomwjxMd+yAlN8wlPXGPHA== X-Received: by 2002:aed:3fad:: with SMTP id s42mr24926645qth.335.1557206221012; Mon, 06 May 2019 22:17:01 -0700 (PDT) MIME-Version: 1.0 References: <20190503093117.54830-1-hsin-hsiung.wang@mediatek.com> <20190503093117.54830-3-hsin-hsiung.wang@mediatek.com> In-Reply-To: From: Nicolas Boichat Date: Tue, 7 May 2019 14:16:50 +0900 Message-ID: Subject: Re: [PATCH v3 02/10] mfd: mt6397: extract irq related code from core driver To: Hsin-Hsiung Wang Cc: Lee Jones , Rob Herring , Mark Brown , Matthias Brugger , Mark Rutland , Alessandro Zummo , Alexandre Belloni , srv_heupstream , devicetree@vger.kernel.org, Sean Wang , Liam Girdwood , lkml , "moderated list:ARM/Mediatek SoC support" , linux-arm Mailing List , Eddie Huang , linux-rtc@vger.kernel.org, Claire Chang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 7, 2019 at 2:11 PM Nicolas Boichat wrote: > > On Fri, May 3, 2019 at 6:33 PM Hsin-Hsiung Wang > wrote: > > > > In order to support different types of irq design, we decide to add > > separate irq drivers for different design and keep mt6397 mfd core > > simple and reusable to all generations of PMICs so far. > > > > Signed-off-by: Hsin-Hsiung Wang > > --- > > drivers/mfd/Makefile | 3 +- > > drivers/mfd/mt6397-core.c | 146 -------------------------- > > drivers/mfd/mt6397-irq.c | 181 ++++++++++++++++++++++++++++++++ > > include/linux/mfd/mt6397/core.h | 9 ++ > > 4 files changed, 192 insertions(+), 147 deletions(-) > > create mode 100644 drivers/mfd/mt6397-irq.c > > > > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > > index b4569ed7f3f3..ab1e228b5a2f 100644 > > --- a/drivers/mfd/Makefile > > +++ b/drivers/mfd/Makefile > > @@ -234,7 +234,8 @@ obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o > > obj-$(CONFIG_INTEL_SOC_PMIC_BXTWC) += intel_soc_pmic_bxtwc.o > > obj-$(CONFIG_INTEL_SOC_PMIC_CHTWC) += intel_soc_pmic_chtwc.o > > obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI) += intel_soc_pmic_chtdc_ti.o > > -obj-$(CONFIG_MFD_MT6397) += mt6397-core.o > > +mt6397-objs := mt6397-core.o mt6397-irq.o > > +obj-$(CONFIG_MFD_MT6397) += mt6397.o > > > > obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o > > obj-$(CONFIG_MFD_STPMIC1) += stpmic1.o > > diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c > > index c9393bc86743..c80f0449fe7e 100644 > > --- a/drivers/mfd/mt6397-core.c > > +++ b/drivers/mfd/mt6397-core.c > > @@ -26,10 +26,6 @@ > > #define MT6397_RTC_BASE 0xe000 > > #define MT6397_RTC_SIZE 0x3e > > > > -#define MT6323_CHIP_ID 0x23 > > -#define MT6391_CHIP_ID 0x91 > > -#define MT6397_CHIP_ID 0x97 > > - > > static const struct resource mt6397_rtc_resources[] = { > > { > > .start = MT6397_RTC_BASE, > > @@ -94,148 +90,6 @@ static const struct mfd_cell mt6397_devs[] = { > > } > > }; > > > > -static void mt6397_irq_lock(struct irq_data *data) > > -{ > > - struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > - > > - mutex_lock(&mt6397->irqlock); > > -} > > - > > -static void mt6397_irq_sync_unlock(struct irq_data *data) > > -{ > > - struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > - > > - regmap_write(mt6397->regmap, mt6397->int_con[0], > > - mt6397->irq_masks_cur[0]); > > - regmap_write(mt6397->regmap, mt6397->int_con[1], > > - mt6397->irq_masks_cur[1]); > > - > > - mutex_unlock(&mt6397->irqlock); > > -} > > - > > -static void mt6397_irq_disable(struct irq_data *data) > > -{ > > - struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > - int shift = data->hwirq & 0xf; > > - int reg = data->hwirq >> 4; > > - > > - mt6397->irq_masks_cur[reg] &= ~BIT(shift); > > -} > > - > > -static void mt6397_irq_enable(struct irq_data *data) > > -{ > > - struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > - int shift = data->hwirq & 0xf; > > - int reg = data->hwirq >> 4; > > - > > - mt6397->irq_masks_cur[reg] |= BIT(shift); > > -} > > - > > -#ifdef CONFIG_PM_SLEEP > > -static int mt6397_irq_set_wake(struct irq_data *irq_data, unsigned int on) > > -{ > > - struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(irq_data); > > - int shift = irq_data->hwirq & 0xf; > > - int reg = irq_data->hwirq >> 4; > > - > > - if (on) > > - mt6397->wake_mask[reg] |= BIT(shift); > > - else > > - mt6397->wake_mask[reg] &= ~BIT(shift); > > - > > - return 0; > > -} > > -#else > > -#define mt6397_irq_set_wake NULL > > -#endif > > - > > -static struct irq_chip mt6397_irq_chip = { > > - .name = "mt6397-irq", > > - .irq_bus_lock = mt6397_irq_lock, > > - .irq_bus_sync_unlock = mt6397_irq_sync_unlock, > > - .irq_enable = mt6397_irq_enable, > > - .irq_disable = mt6397_irq_disable, > > - .irq_set_wake = mt6397_irq_set_wake, > > -}; > > - > > -static void mt6397_irq_handle_reg(struct mt6397_chip *mt6397, int reg, > > - int irqbase) > > -{ > > - unsigned int status; > > - int i, irq, ret; > > - > > - ret = regmap_read(mt6397->regmap, reg, &status); > > - if (ret) { > > - dev_err(mt6397->dev, "Failed to read irq status: %d\n", ret); > > - return; > > - } > > - > > - for (i = 0; i < 16; i++) { > > - if (status & BIT(i)) { > > - irq = irq_find_mapping(mt6397->irq_domain, irqbase + i); > > - if (irq) > > - handle_nested_irq(irq); > > - } > > - } > > - > > - regmap_write(mt6397->regmap, reg, status); > > -} > > - > > -static irqreturn_t mt6397_irq_thread(int irq, void *data) > > -{ > > - struct mt6397_chip *mt6397 = data; > > - > > - mt6397_irq_handle_reg(mt6397, mt6397->int_status[0], 0); > > - mt6397_irq_handle_reg(mt6397, mt6397->int_status[1], 16); > > - > > - return IRQ_HANDLED; > > -} > > - > > -static int mt6397_irq_domain_map(struct irq_domain *d, unsigned int irq, > > - irq_hw_number_t hw) > > -{ > > - struct mt6397_chip *mt6397 = d->host_data; > > - > > - irq_set_chip_data(irq, mt6397); > > - irq_set_chip_and_handler(irq, &mt6397_irq_chip, handle_level_irq); > > - irq_set_nested_thread(irq, 1); > > - irq_set_noprobe(irq); > > - > > - return 0; > > -} > > - > > -static const struct irq_domain_ops mt6397_irq_domain_ops = { > > - .map = mt6397_irq_domain_map, > > -}; > > - > > -static int mt6397_irq_init(struct mt6397_chip *mt6397) > > -{ > > - int ret; > > - > > - mutex_init(&mt6397->irqlock); > > - > > - /* Mask all interrupt sources */ > > - regmap_write(mt6397->regmap, mt6397->int_con[0], 0x0); > > - regmap_write(mt6397->regmap, mt6397->int_con[1], 0x0); > > - > > - mt6397->irq_domain = irq_domain_add_linear(mt6397->dev->of_node, > > - MT6397_IRQ_NR, &mt6397_irq_domain_ops, mt6397); > > - if (!mt6397->irq_domain) { > > - dev_err(mt6397->dev, "could not create irq domain\n"); > > - return -ENOMEM; > > - } > > - > > - ret = devm_request_threaded_irq(mt6397->dev, mt6397->irq, NULL, > > - mt6397_irq_thread, IRQF_ONESHOT, "mt6397-pmic", mt6397); > > - if (ret) { > > - dev_err(mt6397->dev, "failed to register irq=%d; err: %d\n", > > - mt6397->irq, ret); > > - return ret; > > - } > > - > > - return 0; > > -} > > - > > #ifdef CONFIG_PM_SLEEP > > static int mt6397_irq_suspend(struct device *dev) > > { > > diff --git a/drivers/mfd/mt6397-irq.c b/drivers/mfd/mt6397-irq.c > > new file mode 100644 > > index 000000000000..b2d3ce1f3115 > > --- /dev/null > > +++ b/drivers/mfd/mt6397-irq.c > > @@ -0,0 +1,181 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +// > > +// Copyright (c) 2019 MediaTek Inc. > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static void mt6397_irq_lock(struct irq_data *data) > > +{ > > + struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > + > > + mutex_lock(&mt6397->irqlock); > > +} > > + > > +static void mt6397_irq_sync_unlock(struct irq_data *data) > > +{ > > + struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > + > > + regmap_write(mt6397->regmap, mt6397->int_con[0], > > + mt6397->irq_masks_cur[0]); > > + regmap_write(mt6397->regmap, mt6397->int_con[1], > > + mt6397->irq_masks_cur[1]); > > + > > + mutex_unlock(&mt6397->irqlock); > > +} > > + > > +static void mt6397_irq_disable(struct irq_data *data) > > +{ > > + struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > + int shift = data->hwirq & 0xf; > > + int reg = data->hwirq >> 4; > > + > > + mt6397->irq_masks_cur[reg] &= ~BIT(shift); > > +} > > + > > +static void mt6397_irq_enable(struct irq_data *data) > > +{ > > + struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(data); > > + int shift = data->hwirq & 0xf; > > + int reg = data->hwirq >> 4; > > + > > + mt6397->irq_masks_cur[reg] |= BIT(shift); > > +} > > + > > +#ifdef CONFIG_PM_SLEEP > > +static int mt6397_irq_set_wake(struct irq_data *irq_data, unsigned int on) > > +{ > > + struct mt6397_chip *mt6397 = irq_data_get_irq_chip_data(irq_data); > > + int shift = irq_data->hwirq & 0xf; > > + int reg = irq_data->hwirq >> 4; > > + > > + if (on) > > + mt6397->wake_mask[reg] |= BIT(shift); > > + else > > + mt6397->wake_mask[reg] &= ~BIT(shift); > > + > > + return 0; > > +} > > +#else > > +#define mt6397_irq_set_wake NULL > > +#endif > > + > > +static struct irq_chip mt6397_irq_chip = { > > + .name = "mt6397-irq", > > + .irq_bus_lock = mt6397_irq_lock, > > + .irq_bus_sync_unlock = mt6397_irq_sync_unlock, > > + .irq_enable = mt6397_irq_enable, > > + .irq_disable = mt6397_irq_disable, > > + .irq_set_wake = mt6397_irq_set_wake, > > +}; > > + > > +static void mt6397_irq_handle_reg(struct mt6397_chip *mt6397, int reg, > > + int irqbase) > > +{ > > + unsigned int status; > > + int i, irq, ret; > > + > > + ret = regmap_read(mt6397->regmap, reg, &status); > > + if (ret) { > > + dev_err(mt6397->dev, "Failed to read irq status: %d\n", ret); > > + return; > > + } > > + > > + for (i = 0; i < 16; i++) { > > + if (status & BIT(i)) { > > + irq = irq_find_mapping(mt6397->irq_domain, irqbase + i); > > + if (irq) > > + handle_nested_irq(irq); > > + } > > + } > > + > > + regmap_write(mt6397->regmap, reg, status); > > +} > > + > > +static irqreturn_t mt6397_irq_thread(int irq, void *data) > > +{ > > + struct mt6397_chip *mt6397 = data; > > + > > + mt6397_irq_handle_reg(mt6397, mt6397->int_status[0], 0); > > + mt6397_irq_handle_reg(mt6397, mt6397->int_status[1], 16); > > + > > + return IRQ_HANDLED; > > +} > > + > > +static int mt6397_irq_domain_map(struct irq_domain *d, unsigned int irq, > > + irq_hw_number_t hw) > > +{ > > + struct mt6397_chip *mt6397 = d->host_data; > > + > > + irq_set_chip_data(irq, mt6397); > > + irq_set_chip_and_handler(irq, &mt6397_irq_chip, handle_level_irq); > > + irq_set_nested_thread(irq, 1); > > + irq_set_noprobe(irq); > > + > > + return 0; > > +} > > + > > +static const struct irq_domain_ops mt6397_irq_domain_ops = { > > + .map = mt6397_irq_domain_map, > > +}; > > + > > +int mt6397_irq_init(struct mt6397_chip *chip) > > +{ > > + int ret; > > + > > + mutex_init(&chip->irqlock); > > + > > + switch (chip->chip_id) { > > + case MT6323_CHIP_ID: > > + chip->int_con[0] = MT6323_INT_CON0; > > + chip->int_con[1] = MT6323_INT_CON1; > > + chip->int_status[0] = MT6323_INT_STATUS0; > > + chip->int_status[1] = MT6323_INT_STATUS1; > > + break; > > + > > + case MT6391_CHIP_ID: > > + case MT6397_CHIP_ID: > > + chip->int_con[0] = MT6397_INT_CON0; > > + chip->int_con[1] = MT6397_INT_CON1; > > + chip->int_status[0] = MT6397_INT_STATUS0; > > + chip->int_status[1] = MT6397_INT_STATUS1; > > + break; > > + > > + default: > > + dev_err(chip->dev, "unsupported chip: 0x%x\n", chip->chip_id); > > + return -ENODEV; > > + } > > This switch/case wasn't there before the move... Doesn't that now > duplicates with code in mt6397_probe, or am I missing something? Oh, I see, that's deleted in patch 3/10 (https://patchwork.kernel.org/patch/10928163/). That still does not look right. I'd have another patch before this that moves the switch/case statement, and keep this as a simple move with no functional difference. > > + > > + /* Mask all interrupt sources */ > > + regmap_write(chip->regmap, chip->int_con[0], 0x0); > > + regmap_write(chip->regmap, chip->int_con[1], 0x0); > > + > > + chip->irq_domain = irq_domain_add_linear(chip->dev->of_node, > > + MT6397_IRQ_NR, > > + &mt6397_irq_domain_ops, > > + chip); > > + if (!chip->irq_domain) { > > + dev_err(chip->dev, "could not create irq domain\n"); > > + return -ENOMEM; > > + } > > + > > + ret = devm_request_threaded_irq(chip->dev, chip->irq, NULL, > > + mt6397_irq_thread, IRQF_ONESHOT, > > + "mt6397-pmic", chip); > > + if (ret) { > > + dev_err(chip->dev, "failed to register irq=%d; err: %d\n", > > + chip->irq, ret); > > + return ret; > > + } > > + > > + return 0; > > +} > > diff --git a/include/linux/mfd/mt6397/core.h b/include/linux/mfd/mt6397/core.h > > index d678f526e498..93f9f5235575 100644 > > --- a/include/linux/mfd/mt6397/core.h > > +++ b/include/linux/mfd/mt6397/core.h > > @@ -15,6 +15,12 @@ > > #ifndef __MFD_MT6397_CORE_H__ > > #define __MFD_MT6397_CORE_H__ > > > > +enum chip_id { > > + MT6323_CHIP_ID = 0x23, > > + MT6391_CHIP_ID = 0x91, > > + MT6397_CHIP_ID = 0x97, > > +}; > > + > > enum mt6397_irq_numbers { > > MT6397_IRQ_SPKL_AB = 0, > > MT6397_IRQ_SPKR_AB, > > @@ -62,6 +68,9 @@ struct mt6397_chip { > > u16 irq_masks_cache[2]; > > u16 int_con[2]; > > u16 int_status[2]; > > + u16 chip_id; > > }; > > > > +int mt6397_irq_init(struct mt6397_chip *chip); > > + > > #endif /* __MFD_MT6397_CORE_H__ */ > > -- > > 2.18.0 > > > > > > _______________________________________________ > > Linux-mediatek mailing list > > Linux-mediatek@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-mediatek