Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3230410ybb; Tue, 31 Mar 2020 00:38:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvIvKI2vJVgu6Q7iFzJz5gm1mJkI4o2cA/E0xqlgXdulsWqAPKqzPyOCh/kpczKkqAuMtOw X-Received: by 2002:a9d:5781:: with SMTP id q1mr12508174oth.258.1585640338640; Tue, 31 Mar 2020 00:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585640338; cv=none; d=google.com; s=arc-20160816; b=dw555MopCr05DIITrtMvAX1vW88ktjCToG7CsTM1KDjuaDoGVzZ6Qex3OV9TRldmHQ J18Me43o4hgFBgfKXROlr1sjmMBA5YOk6sViBSMhnSiIjdok0bSrMLulmOrLmvFq5dsy O0xkSn0Ffqrs9kaVdtmzHw0ZVO/HwFe/jSl/cdrcPde8GHm1yYAlNz1drJFaUVySdqNH 7dKwYwBIeA9hcAp1wjHVxVQC4Nxo9GSacb8evezjKGKeQt5n3Fz0fyxP3IxdT6+K+Sy8 xE3qiazRdou3Ou6NbeJ1fN9ib68J6ZIWiPPDpkL5U8dyT08D65xYd4bTeNBKaI3nj3TS wrFQ== 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=S6Q9hQ2oX9Ox06YI7dtd+yeRUlkspby1i/hG2sHJOwk=; b=j4jxDGNl5fp2rS1VUAuvKNX9hRcbbYIoIy04nX5eJWI+rU1NsXZVWnZ+JDZ7b1wsFR Z7JVPNLAMMxVhGGN3a/c/TVFt5Kjz9JW/aV7Q+BCIKSD/HBIIGhVSYGMEZMpx+ZlIoNJ QdeZRlogrd3FUSAHg+s80yL4lL1N+K6pmq/q5gguW1s5kIs3ZEgw1dGGmLNyGAAjTH6O 4EHEA0aiM77BHwHOpTFB/UatnBRKbqVdXMjMusdRyK+mbS9MpUlg1nM99GNsn1Bdkl9c HMADgKmHx20JRKbAnxOMse0ZmAdwJZ6m3j5vLOYmVHt4tztwpYclNmLbWdlVBK0Fn+a3 rutg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QPs5ozvI; 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 m2si7249341oof.17.2020.03.31.00.38.46; Tue, 31 Mar 2020 00:38:58 -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=QPs5ozvI; 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 S1729984AbgCaHg4 (ORCPT + 99 others); Tue, 31 Mar 2020 03:36:56 -0400 Received: from mail-vk1-f193.google.com ([209.85.221.193]:37135 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgCaHgz (ORCPT ); Tue, 31 Mar 2020 03:36:55 -0400 Received: by mail-vk1-f193.google.com with SMTP id o124so5441824vkc.4 for ; Tue, 31 Mar 2020 00:36:54 -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=S6Q9hQ2oX9Ox06YI7dtd+yeRUlkspby1i/hG2sHJOwk=; b=QPs5ozvIbF42Ytw0UwR9mtN42EIVg+Uhckg5kKc+/HZlfqR2lrKjQMDMC0u16BYIRJ lGDVlYNa6YxP1XX2KmFecCHQO+1hdmrptQMWezPbNv8ZGok0DAVsLxwy3rE+1DjsWUgW j8mmb1/Dd5UoAKKQMzm6uy6q2u1RWfpt2inKE= 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=S6Q9hQ2oX9Ox06YI7dtd+yeRUlkspby1i/hG2sHJOwk=; b=mMM1QQJraaNv6PELifu9veHoxrS+T6xVi3q+2PyXPYzFvD7YQcRILnwammAYmtSZ47 ptW+ybgELgZBX8DbsygcICV7mSEK1EDJ9a6+j0PUTUZXMB8fJFIUMRQzl207By5lsmN/ lJy7k1D62J/+ELDLH9ETILtY/ImioIHw5I1LEKnORmcNdaNilUfBTBUcgHUcU3j/Kgg2 V4VDe7EMJh0ZFiJ0DHwJQjTFOkbFmmfxzO+2rYVWYSz3dHMTOCIPvTrymSWoIlC6xuEz ri3MEBGUk4aEriO5zXVbPveYi9DEVSFbSGk7SG423Dza5l3kn0u5/GxiEW0/rpSmWyML SaLg== X-Gm-Message-State: AGi0PubXIY+JEi2PUFh23lUYbAZz0G7O1jPQJp8iOBvpLQW+qxyPpkxj LRTyoj+nRjdoVFaK5fYr3fhzp1oFLZEsSeWWR89lBg== X-Received: by 2002:a05:6122:2d0:: with SMTP id k16mr10595740vki.54.1585640214209; Tue, 31 Mar 2020 00:36:54 -0700 (PDT) MIME-Version: 1.0 References: <1585627657-3265-1-git-send-email-hsin-hsiung.wang@mediatek.com> <1585627657-3265-4-git-send-email-hsin-hsiung.wang@mediatek.com> In-Reply-To: <1585627657-3265-4-git-send-email-hsin-hsiung.wang@mediatek.com> From: Nicolas Boichat Date: Tue, 31 Mar 2020 15:36:43 +0800 Message-ID: Subject: Re: [PATCH v11 3/5] mfd: Add support for the MediaTek MT6358 PMIC To: Hsin-Hsiung Wang Cc: Lee Jones , Rob Herring , Matthias Brugger , Alexandre Belloni , Mark Rutland , Sean Wang , Sebastian Reichel , Eddie Huang , Alessandro Zummo , Kate Stewart , Richard Fontana , Frank Wunderlich , Josef Friedl , Thomas Gleixner , Ran Bi , Devicetree List , linux-arm Mailing List , "moderated list:ARM/Mediatek SoC support" , lkml , "open list:THERMAL" , linux-rtc@vger.kernel.org, srv_heupstream 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, Mar 31, 2020 at 12:07 PM Hsin-Hsiung Wang wrote: > > This adds support for the MediaTek MT6358 PMIC. This is a > multifunction device with the following sub modules: > > - Regulator > - RTC > - Codec > - Interrupt > > It is interfaced to the host controller using SPI interface > by a proprietary hardware called PMIC wrapper or pwrap. > MT6358 MFD is a child device of the pwrap. > > Signed-off-by: Hsin-Hsiung Wang > Reviewed-by: Nicolas Boichat This is missing a few comments from Lee Jones on v10, actually, repeated below: https://patchwork.kernel.org/patch/11431239/#23244041 > --- > drivers/mfd/Makefile | 2 +- > drivers/mfd/mt6358-irq.c | 236 +++++++++++++++++++++++++++++ > drivers/mfd/mt6397-core.c | 55 ++++++- > include/linux/mfd/mt6358/core.h | 158 ++++++++++++++++++++ > include/linux/mfd/mt6358/registers.h | 282 +++++++++++++++++++++++++++++++++++ > include/linux/mfd/mt6397/core.h | 3 + > 6 files changed, 731 insertions(+), 5 deletions(-) > create mode 100644 drivers/mfd/mt6358-irq.c > create mode 100644 include/linux/mfd/mt6358/core.h > create mode 100644 include/linux/mfd/mt6358/registers.h > > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > index b83f172..9af1414 100644 > --- a/drivers/mfd/Makefile > +++ b/drivers/mfd/Makefile > @@ -238,7 +238,7 @@ 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 > -mt6397-objs := mt6397-core.o mt6397-irq.o > +mt6397-objs := mt6397-core.o mt6397-irq.o mt6358-irq.o > obj-$(CONFIG_MFD_MT6397) += mt6397.o > obj-$(CONFIG_INTEL_SOC_PMIC_MRFLD) += intel_soc_pmic_mrfld.o > > diff --git a/drivers/mfd/mt6358-irq.c b/drivers/mfd/mt6358-irq.c > new file mode 100644 > index 0000000..022e5f5 > --- /dev/null > +++ b/drivers/mfd/mt6358-irq.c > @@ -0,0 +1,236 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// Copyright (c) 2019 MediaTek Inc. 2020 > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static struct irq_top_t mt6358_ints[] = { > + MT6358_TOP_GEN(BUCK), > + MT6358_TOP_GEN(LDO), > + MT6358_TOP_GEN(PSC), > + MT6358_TOP_GEN(SCK), > + MT6358_TOP_GEN(BM), > + MT6358_TOP_GEN(HK), > + MT6358_TOP_GEN(AUD), > + MT6358_TOP_GEN(MISC), > +}; > + > +static void pmic_irq_enable(struct irq_data *data) > +{ > + unsigned int hwirq = irqd_to_hwirq(data); > + struct mt6397_chip *chip = irq_data_get_irq_chip_data(data); > + struct pmic_irq_data *irqd = chip->irq_data; > + > + irqd->enable_hwirq[hwirq] = true; > +} > + > +static void pmic_irq_disable(struct irq_data *data) > +{ > + unsigned int hwirq = irqd_to_hwirq(data); > + struct mt6397_chip *chip = irq_data_get_irq_chip_data(data); > + struct pmic_irq_data *irqd = chip->irq_data; > + > + irqd->enable_hwirq[hwirq] = false; > +} > + > +static void pmic_irq_lock(struct irq_data *data) > +{ > + struct mt6397_chip *chip = irq_data_get_irq_chip_data(data); > + > + mutex_lock(&chip->irqlock); > +} > + > +static void pmic_irq_sync_unlock(struct irq_data *data) > +{ > + unsigned int i, top_gp, gp_offset, en_reg, int_regs, shift; > + struct mt6397_chip *chip = irq_data_get_irq_chip_data(data); > + struct pmic_irq_data *irqd = chip->irq_data; > + > + for (i = 0; i < irqd->num_pmic_irqs; i++) { > + if (irqd->enable_hwirq[i] == irqd->cache_hwirq[i]) > + continue; > + > + /* Find out the IRQ group */ > + top_gp = 0; > + while ((top_gp + 1) < irqd->num_top && > + i >= mt6358_ints[top_gp + 1].hwirq_base) > + top_gp++; > + > + /* Find the irq registers */ From Lee Jones: 'Nit: "IRQ"' > + gp_offset = i - mt6358_ints[top_gp].hwirq_base; > + int_regs = gp_offset / MT6358_REG_WIDTH; > + shift = gp_offset % MT6358_REG_WIDTH; > + en_reg = mt6358_ints[top_gp].en_reg + > + (mt6358_ints[top_gp].en_reg_shift * int_regs); > + [...] > +static const struct irq_domain_ops mt6358_irq_domain_ops = { > + .map = pmic_irq_domain_map, > + .xlate = irq_domain_xlate_twocell, > +}; > + > +int mt6358_irq_init(struct mt6397_chip *chip) > +{ > + int i, j, ret; > + struct pmic_irq_data *irqd; > + > + irqd = devm_kzalloc(chip->dev, sizeof(struct pmic_irq_data *), From Lee Jones: 'sizeof(*irqd)' > + GFP_KERNEL); > + if (!irqd) > + return -ENOMEM; > + > + chip->irq_data = irqd; > + [...] > @@ -154,19 +184,33 @@ static int mt6397_probe(struct platform_device *pdev) > if (pmic->irq <= 0) > return pmic->irq; > > - ret = mt6397_irq_init(pmic); > - if (ret) > - return ret; > - > switch (pmic->chip_id) { > case MT6323_CHIP_ID: > + ret = mt6397_irq_init(pmic); > + if (ret) > + return ret; > + > ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, > mt6323_devs, ARRAY_SIZE(mt6323_devs), > NULL, 0, pmic->irq_domain); > break; > > + case MT6358_CHIP_ID: > + ret = mt6358_irq_init(pmic); > + if (ret) > + return ret; > + > + ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, > + mt6358_devs, ARRAY_SIZE(mt6358_devs), > + NULL, 0, pmic->irq_domain); > + break; From Lee Jones: "In a subsequent patch you can choose the correct mtXXXX_devs structure to pass and call devm_mfd_add_devices() only once below the switch()." Can you look into that as a follow-up patch? > + > case MT6391_CHIP_ID: > case MT6397_CHIP_ID: > + ret = mt6397_irq_init(pmic); > + if (ret) > + return ret; > + > ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, > mt6397_devs, ARRAY_SIZE(mt6397_devs), > NULL, 0, pmic->irq_domain); [snip]