From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5F81C4360F for ; Thu, 4 Apr 2019 13:22:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 837252082E for ; Thu, 4 Apr 2019 13:22:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LMCiOm2R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 837252082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To: References:Message-ID:Date:Subject:To:From:Reply-To:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vHBt1k79u7QUrC+ONKyHP5kTzo9la/KwwCui+IakzJI=; b=LMCiOm2RJ0wUnS 8zky52/JHLQxf9uWWngz7EWL4BhW6fHa7phLwXrf1cZxd+SD4lsildiPigIkRvnW7JsJ4lvVUx0Wl xVY9Y/pMFJnLijxj1B8My4Y8owBHJDCLpdNbRnRoPe3+YnIDbU7JaH4JhK57KnxX3V6A2me0r8ghz gYhxub4TrPW+pLyuvXq/u1mLhSHHx+ZfGa/zzRzUCXOucAna7EtsuqlN8krU79EpOxEECDpN5jKz1 vnSU3opK98UsBb75FzYjT6q/nWzSryzAvD3BgPXRwQKGlthNEaXtGScI2E+uh5itDEg5aonM2m+qe EuPypfz+aWp7ZR50g5mw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hC2K4-0004kP-Ku; Thu, 04 Apr 2019 13:22:28 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hC2K1-0004iV-3r for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 13:22:27 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x34DLZ2j016976; Thu, 4 Apr 2019 15:22:14 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2rmgevas4p-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 04 Apr 2019 15:22:14 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3B4993A; Thu, 4 Apr 2019 13:22:13 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag3node2.st.com [10.75.127.8]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D6BCF28A5; Thu, 4 Apr 2019 13:22:12 +0000 (GMT) Received: from SFHDAG3NODE2.st.com (10.75.127.8) by SFHDAG3NODE2.st.com (10.75.127.8) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 4 Apr 2019 15:22:12 +0200 Received: from SFHDAG3NODE2.st.com ([fe80::b82f:1ce:8854:5b96]) by SFHDAG3NODE2.st.com ([fe80::b82f:1ce:8854:5b96%20]) with mapi id 15.00.1347.000; Thu, 4 Apr 2019 15:22:12 +0200 From: Amelie DELAUNAY To: Lee Jones Subject: Re: [PATCH v4 2/9] mfd: Add ST Multi-Function eXpander (STMFX) core driver Thread-Topic: [PATCH v4 2/9] mfd: Add ST Multi-Function eXpander (STMFX) core driver Thread-Index: AQHUzn+8nfDE465XK0GwcabPvj+kJKYqScKAgAHKiYA= Date: Thu, 4 Apr 2019 13:22:12 +0000 Message-ID: References: <1551260094-32570-1-git-send-email-amelie.delaunay@st.com> <1551260094-32570-3-git-send-email-amelie.delaunay@st.com> <20190403100101.GK11301@dell> In-Reply-To: <20190403100101.GK11301@dell> Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.75.127.46] Content-ID: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-04-04_06:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_062225_447913_6455B35F X-CRM114-Status: GOOD ( 25.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , "devicetree@vger.kernel.org" , Alexandre TORGUE , Linus Walleij , "linux-kernel@vger.kernel.org" , "linux-gpio@vger.kernel.org" , Rob Herring , Maxime Coquelin , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 4/3/19 12:01 PM, Lee Jones wrote: > On Wed, 27 Feb 2019, Amelie Delaunay wrote: > >> STMicroelectronics Multi-Function eXpander (STMFX) is a slave controller >> using I2C for communication with the main MCU. Main features are: >> - 16 fast GPIOs individually configurable in input/output >> - 8 alternate GPIOs individually configurable in input/output when other >> STMFX functions are not used >> - Main MCU IDD measurement >> - Resistive touchscreen controller >> >> Signed-off-by: Amelie Delaunay >> --- >> drivers/mfd/Kconfig | 13 ++ >> drivers/mfd/Makefile | 2 +- >> drivers/mfd/stmfx.c | 568 ++++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/mfd/stmfx.h | 123 ++++++++++ >> 4 files changed, 705 insertions(+), 1 deletion(-) >> create mode 100644 drivers/mfd/stmfx.c >> create mode 100644 include/linux/mfd/stmfx.h > > Very nice first attempt for what is a pretty complex driver. > > Just a couple of nits below. > > [...] > Thanks for reviewing. >> +static int stmfx_chip_init(struct i2c_client *client) >> +{ >> + struct stmfx *stmfx = i2c_get_clientdata(client); >> + u32 id; >> + u8 version[2]; >> + int ret; >> + >> + stmfx->vdd = devm_regulator_get_optional(&client->dev, "vdd"); >> + if (IS_ERR(stmfx->vdd)) { >> + ret = PTR_ERR(stmfx->vdd); >> + if (ret != -ENODEV) { >> + if (ret != -EPROBE_DEFER) >> + dev_err(&client->dev, >> + "No VDD regulator found:%d\n", ret); > > Actually -ENODEV means this, which is okay. > > In this case we failed to obtain a provided regulator. > Ok, "Can't get VDD regulator" instead of "No VDD regulator found" is more accurate. >> + return ret; >> + } >> + } else { > > if (IS_ERR(stmfx->vdd) && PTR_ERR(stmfx->vdd) == -EPROBE_DEFER) { > return PTR_ERR(stmfx->vdd); > } else (IS_ERR(stmfx->vdd) && PTR_ERR(stmfx->vdd) == -ENODEV) { > stmfx->vdd = NULL; > } else (IS_ERR(stmfx->vdd))) { > dev_err(&client->dev, "Failed to get VDD regulator:%d\n", ret); > return PTR_ERR(stmfx->vdd); > } > > if (stmfx->vdd) { > >> + ret = regulator_enable(stmfx->vdd); >> + if (ret) { >> + dev_err(&client->dev, "VDD enable failed: %d\n", ret); >> + return ret; >> + } >> + } >> + > > [...] > >> +static const struct resource stmfx_ts_resources[] = { >> + DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_DET), >> + DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_NE), >> + DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_TH), >> + DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_FULL), >> + DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_OVF), >> +}; > > Please move everything from here ---------------> > >> +static struct mfd_cell stmfx_cells[] = { >> + { >> + .of_compatible = "st,stmfx-0300-pinctrl", >> + .name = "stmfx-pinctrl", >> + .resources = stmfx_pinctrl_resources, >> + .num_resources = ARRAY_SIZE(stmfx_pinctrl_resources), >> + }, >> + { >> + .of_compatible = "st,stmfx-0300-idd", >> + .name = "stmfx-idd", >> + .resources = stmfx_idd_resources, >> + .num_resources = ARRAY_SIZE(stmfx_idd_resources), >> + }, >> + { >> + .of_compatible = "st,stmfx-0300-ts", >> + .name = "stmfx-ts", >> + .resources = stmfx_ts_resources, >> + .num_resources = ARRAY_SIZE(stmfx_ts_resources), >> + }, >> +}; >> + >> +static bool stmfx_reg_volatile(struct device *dev, unsigned int reg) >> +{ >> + switch (reg) { >> + case STMFX_REG_SYS_CTRL: >> + case STMFX_REG_IRQ_SRC_EN: >> + case STMFX_REG_IRQ_PENDING: >> + case STMFX_REG_IRQ_GPI_PENDING1: >> + case STMFX_REG_IRQ_GPI_PENDING2: >> + case STMFX_REG_IRQ_GPI_PENDING3: >> + case STMFX_REG_GPIO_STATE1: >> + case STMFX_REG_GPIO_STATE2: >> + case STMFX_REG_GPIO_STATE3: >> + case STMFX_REG_IRQ_GPI_SRC1: >> + case STMFX_REG_IRQ_GPI_SRC2: >> + case STMFX_REG_IRQ_GPI_SRC3: >> + case STMFX_REG_GPO_SET1: >> + case STMFX_REG_GPO_SET2: >> + case STMFX_REG_GPO_SET3: >> + case STMFX_REG_GPO_CLR1: >> + case STMFX_REG_GPO_CLR2: >> + case STMFX_REG_GPO_CLR3: >> + return true; >> + default: >> + return false; >> + } >> +} >> + >> +static bool stmfx_reg_writeable(struct device *dev, unsigned int reg) >> +{ >> + return (reg >= STMFX_REG_SYS_CTRL); >> +} >> + >> +static const struct regmap_config stmfx_regmap_config = { >> + .reg_bits = 8, >> + .reg_stride = 1, >> + .val_bits = 8, >> + .max_register = STMFX_REG_MAX, >> + .volatile_reg = stmfx_reg_volatile, >> + .writeable_reg = stmfx_reg_writeable, >> + .cache_type = REGCACHE_RBTREE, >> +}; > > -----------------------> > > ... to here, up to the top, just below the includes. > I'll move the regmap_config & mfx_cell declarations just below the includes. >> +static int stmfx_probe(struct i2c_client *client, >> + const struct i2c_device_id *id) >> +{ >> + struct device *dev = &client->dev; >> + struct stmfx *stmfx; >> + int i, ret; >> + >> + stmfx = devm_kzalloc(dev, sizeof(*stmfx), GFP_KERNEL); >> + if (!stmfx) >> + return -ENOMEM; >> + >> + i2c_set_clientdata(client, stmfx); >> + >> + stmfx->dev = dev; >> + >> + stmfx->map = devm_regmap_init_i2c(client, &stmfx_regmap_config); >> + if (IS_ERR(stmfx->map)) { >> + ret = PTR_ERR(stmfx->map); >> + dev_err(dev, "Failed to allocate register map: %d\n", ret); >> + return ret; >> + } >> + >> + mutex_init(&stmfx->lock); >> + >> + ret = stmfx_chip_init(client); >> + if (ret) { >> + if (ret == -ETIMEDOUT) >> + return -EPROBE_DEFER; >> + return ret; >> + } >> + >> + if (client->irq < 0) { >> + dev_err(dev, "Failed to get IRQ: %d\n", client->irq); >> + ret = client->irq; >> + goto err_chip_exit; >> + } >> + >> + ret = stmfx_irq_init(client); >> + if (ret) >> + goto err_chip_exit; >> + >> + for (i = 0; i < ARRAY_SIZE(stmfx_cells); i++) { >> + stmfx_cells[i].platform_data = stmfx; >> + stmfx_cells[i].pdata_size = sizeof(struct stmfx); >> + } > > Pass this though dev_get_drvdata() instead. > > ... > > Actually, didn't you already set this with i2c_set_clientdata()? That > does exactly the same thing. So you can get this back from the client > via i2c_get_clientdata(). No need to send it though platform data. > Yes, I agree. I'll remove this loop and use dev_get_drvdata(pdev->dev.parent) in child drivers. >> + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, >> + stmfx_cells, ARRAY_SIZE(stmfx_cells), NULL, >> + 0, stmfx->irq_domain); >> + if (ret) >> + goto err_irq_exit; >> + >> + return 0; >> + >> +err_irq_exit: >> + stmfx_irq_exit(client); >> +err_chip_exit: >> + stmfx_chip_exit(client); >> + >> + return ret; >> +} >> + >> +static int stmfx_remove(struct i2c_client *client) >> +{ >> + stmfx_irq_exit(client); >> + >> + return stmfx_chip_exit(client); >> +} >> + >> +#ifdef CONFIG_PM_SLEEP >> +static int stmfx_backup_regs(struct stmfx *stmfx) >> +{ >> + int ret; >> + >> + ret = regmap_raw_read(stmfx->map, STMFX_REG_SYS_CTRL, >> + &stmfx->bkp_sysctrl, sizeof(stmfx->bkp_sysctrl)); >> + if (ret) >> + return ret; > > '\n' here. > >> + ret = regmap_raw_read(stmfx->map, STMFX_REG_IRQ_OUT_PIN, >> + &stmfx->bkp_irqoutpin, >> + sizeof(stmfx->bkp_irqoutpin)); >> + if (ret) >> + return ret; >> + >> + return 0; >> +} >> + >> +static int stmfx_restore_regs(struct stmfx *stmfx) >> +{ >> + int ret; >> + >> + ret = regmap_raw_write(stmfx->map, STMFX_REG_SYS_CTRL, >> + &stmfx->bkp_sysctrl, sizeof(stmfx->bkp_sysctrl)); >> + if (ret) >> + return ret; > > '\n' here. > >> + ret = regmap_raw_write(stmfx->map, STMFX_REG_IRQ_OUT_PIN, >> + &stmfx->bkp_irqoutpin, >> + sizeof(stmfx->bkp_irqoutpin)); >> + if (ret) >> + return ret; > > '\n' here. > >> + ret = regmap_raw_write(stmfx->map, STMFX_REG_IRQ_SRC_EN, >> + &stmfx->irq_src, sizeof(stmfx->irq_src)); >> + if (ret) >> + return ret; >> + >> + return 0; >> +} >> + >> +static int stmfx_suspend(struct device *dev) >> +{ >> + struct stmfx *stmfx = dev_get_drvdata(dev); >> + int ret; >> + >> + ret = stmfx_backup_regs(stmfx); > > Don't think you need a separate function for this. Just move the > regmap_raw_write() commands here. > I used a separate function to have only one dev_err in case of backup/restore failure. >> + if (ret) { >> + dev_err(stmfx->dev, "Registers backup failure\n"); >> + return ret; >> + } >> + >> + if (!IS_ERR(stmfx->vdd)) { >> + ret = regulator_disable(stmfx->vdd); >> + if (ret) >> + return ret; >> + } >> + >> + return 0; >> +} >> + >> +static int stmfx_resume(struct device *dev) >> +{ >> + struct stmfx *stmfx = dev_get_drvdata(dev); >> + int ret; >> + >> + if (!IS_ERR(stmfx->vdd)) { >> + ret = regulator_enable(stmfx->vdd); >> + if (ret) { >> + dev_err(stmfx->dev, >> + "VDD enable failed: %d\n", ret); >> + return ret; >> + } >> + } >> + >> + ret = stmfx_restore_regs(stmfx); > > As above. > >> + if (ret) { >> + dev_err(stmfx->dev, "Registers restoration failure\n"); >> + return ret; >> + } >> + >> + return 0; >> +} >> +#endif >> + >> +static SIMPLE_DEV_PM_OPS(stmfx_dev_pm_ops, stmfx_suspend, stmfx_resume); >> + >> +static const struct of_device_id stmfx_of_match[] = { >> + { .compatible = "st,stmfx-0300", }, >> + {}, >> +}; >> +MODULE_DEVICE_TABLE(of, stmfx_of_match); >> + >> +static struct i2c_driver stmfx_driver = { >> + .driver = { >> + .name = "stmfx-core", >> + .of_match_table = of_match_ptr(stmfx_of_match), >> + .pm = &stmfx_dev_pm_ops, >> + }, >> + .probe = stmfx_probe, >> + .remove = stmfx_remove, >> +}; >> +module_i2c_driver(stmfx_driver); >> + >> +MODULE_DESCRIPTION("STMFX core driver"); >> +MODULE_AUTHOR("Amelie Delaunay "); >> +MODULE_LICENSE("GPL v2"); > > [...] > I am prepare a v5. Is it OK for you if I keep the backup/restore separate functions ? Regards, Amelie _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel