Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp907356pxb; Thu, 21 Oct 2021 11:46:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYOh9iRV1FnrMQ2fPpL6WBZ+Wm9k6vk/4f6cQG7ds/3tUU/Zwq98adUu8Kx+IKtxvmcoem X-Received: by 2002:a17:90b:1c92:: with SMTP id oo18mr8731373pjb.56.1634841991630; Thu, 21 Oct 2021 11:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634841991; cv=none; d=google.com; s=arc-20160816; b=ByPjjHQf2wZMOj9VgtSezOqVMv/cSujUvuIT8XKLjP+Hok2pe7Y4b6dczFCffuNxE2 YPgS4NbVExohDrysZLCmt/LwA4eBYbuX8qO0j4xeWxUofckIqt/U7UyPxxrZ58vju6cB a21TFYoHUuL7V49Awh2EY/fJTLP+1+oVZnk7HRIB8PeDew3ffAnuV0AxjzHd68VDvlk7 veT8PA33D5hCqHIupcnsoacER5PWot4Jq+hWpxeOMMZheemA314V8wVx8o7PWpJrIYQv dWp1r53RHjM1xUji8OaG2R1LFcvu7pFRYptHl+fLuKoIcSTtDqXRSlfZdeae5whVDwz0 JI+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HihTUTo5ENo8UN8nKvwlPsUn6I35WIIfYFDtca0WDLg=; b=hsivf4xFLZJwTJSxiLi2lqCbtWsk3xbTD0vd5UpYprvJjfajvWK8WCB02+96t4Dtev 2bFBG58Rg0CfcOs/06ZbxdJzA6D7zhCKRIPkKxGiWUBfI5isl5uNr1xKkp78FOm0+ici e8gPZaLy/FvY7B/8SY5eRWr4ThGB23qMeh8/niEkXuhCFcFIk+JbCPej6BGODd/SItQu SCGgH8IDpBqwPtdeZw+W2BcjoDn+kjPBiiTU1h9PgFG7NmLkOpIG0IdCwky9ETAJnnM5 fYZ4ROkQ07aYHYoZClLD5KYhiwoyZUAdlymIGB905Zqe4ZT8e1XlJa94RlAkcycnWkLd p9oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MF6TtrKe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si8547722pls.19.2021.10.21.11.46.18; Thu, 21 Oct 2021 11:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MF6TtrKe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbhJUSqR (ORCPT + 99 others); Thu, 21 Oct 2021 14:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbhJUSqQ (ORCPT ); Thu, 21 Oct 2021 14:46:16 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24C9C0613B9 for ; Thu, 21 Oct 2021 11:43:59 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id u18so963513wrg.5 for ; Thu, 21 Oct 2021 11:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=HihTUTo5ENo8UN8nKvwlPsUn6I35WIIfYFDtca0WDLg=; b=MF6TtrKeIXQVnGFpexkUtQsMS4FaDX0GUNt5WICN5ot947ON4Uv9kge/syuSZMkzfI CXPI665K5XXDAhIAMwOpeA/IZ7oMu/p8ZJrPDonTlPqwfX7pRslK9DGKzhBx6GfpHyi8 sr8T6y2wCenCNbufhEspHWLb6YAByuDxcth4rKbEBVY4KoaHhAVzWaG5Bbb27cU7FK1J Id+DVNUDyjPz4E2oWKo2jZWzsR1AlWl/P9EbLbA8aEzx3o/d3czd6Q7AFSvBh7fw4C+o ebsqc+EzNz73Tchq/QBC/RfNfl3mt5NZ6zTS421jAUnlpx2JzI9rWl90cWptrj4Xrs0s hUKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=HihTUTo5ENo8UN8nKvwlPsUn6I35WIIfYFDtca0WDLg=; b=Hosc6z2gcs2/vmoQDAYnqkrjrcNYvtiHs3TOXF9GkD13s71JKbvgNGAgvNHOob+t1I bjZP2aoZMV2SDydMZP7/RXwC6JQ52WZ+BxiezQznQWhJD+1e6PFLlVh5DS78Tr6u5vv4 GRiRApQ2BgcEyZF1qM1rYmOdopxSx/LxEqiOJ3gTBWa9TfKRaYshszGo28kdJqzISSPS FpCReOAhRiQypdSedrXONIsxE5I22UDhVC5524eGH7wQ83ajGj0EBDTB2+IpHlQHubqW OtuYTbFhk99xevqTS8J7Lz5s63Yk6+VjuHByY+byUDjT6ujV3vLJqe2IKmMINMs0QUuA bdMg== X-Gm-Message-State: AOAM530uKj0EtAlJymPwS5CIDGD/gNr0pZujKQT7xQ02uXysOGd1Fmvv R3pt3qet2z0ewa7M+rkOWtMtCg== X-Received: by 2002:adf:f902:: with SMTP id b2mr9532521wrr.265.1634841838272; Thu, 21 Oct 2021 11:43:58 -0700 (PDT) Received: from google.com ([95.148.6.207]) by smtp.gmail.com with ESMTPSA id l124sm9421388wml.8.2021.10.21.11.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 11:43:57 -0700 (PDT) Date: Thu, 21 Oct 2021 19:43:55 +0100 From: Lee Jones To: Luca Ceresoli Cc: linux-kernel@vger.kernel.org, Rob Herring , Alessandro Zummo , Alexandre Belloni , Chanwoo Choi , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Wim Van Sebroeck , Guenter Roeck , devicetree@vger.kernel.org, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org, Chiwoong Byun , Laxman Dewangan , Randy Dunlap Subject: Re: [PATCH v2 6/9] mfd: max77714: Add driver for Maxim MAX77714 PMIC Message-ID: References: <20211019145919.7327-1-luca@lucaceresoli.net> <20211019145919.7327-7-luca@lucaceresoli.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211019145919.7327-7-luca@lucaceresoli.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 Oct 2021, Luca Ceresoli wrote: > Add a simple driver for the Maxim MAX77714 PMIC, supporting RTC and > watchdog only. > > Signed-off-by: Luca Ceresoli > > --- > > Changes in v2: > - fix "watchdog" word in heading comment (Guenter Roeck) > - move struct max77714 to .c file (Krzysztof Kozlowski) > - change include guard format (Krzysztof Kozlowski) > - allow building as a module (Krzysztof Kozlowski) > - remove of_match_ptr usage (Krzysztof Kozlowski / lkp) > (Reported-by: kernel test robot ) > --- > MAINTAINERS | 2 + > drivers/mfd/Kconfig | 14 +++ > drivers/mfd/Makefile | 1 + > drivers/mfd/max77714.c | 165 +++++++++++++++++++++++++++++++++++ > include/linux/mfd/max77714.h | 60 +++++++++++++ > 5 files changed, 242 insertions(+) > create mode 100644 drivers/mfd/max77714.c > create mode 100644 include/linux/mfd/max77714.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 514ff4a735e5..abd9de8a9d99 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -11390,6 +11390,8 @@ MAXIM MAX77714 PMIC MFD DRIVER > M: Luca Ceresoli > S: Maintained > F: Documentation/devicetree/bindings/mfd/maxim,max77714.yaml > +F: drivers/mfd/max77714.c > +F: include/linux/mfd/max77714.h > > MAXIM MAX77802 PMIC REGULATOR DEVICE DRIVER > M: Javier Martinez Canillas > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig > index ca0edab91aeb..295a04b479c6 100644 > --- a/drivers/mfd/Kconfig > +++ b/drivers/mfd/Kconfig > @@ -853,6 +853,20 @@ config MFD_MAX77693 > additional drivers must be enabled in order to use the functionality > of the device. > > +config MFD_MAX77714 > + tristate "Maxim Semiconductor MAX77714 PMIC Support" > + depends on I2C > + depends on OF || COMPILE_TEST > + select MFD_CORE > + select REGMAP_I2C > + help > + Say yes here to add support for Maxim Semiconductor MAX77714. > + This is a Power Management IC with 4 buck regulators, 9 > + low-dropout regulators, 8 GPIOs, RTC, watchdog etc. This driver > + provides common support for accessing the device; additional > + drivers must be enabled in order to use each functionality of the > + device. > + > config MFD_MAX77843 > bool "Maxim Semiconductor MAX77843 PMIC Support" > depends on I2C=y > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > index 2ba6646e874c..fe43f2fdd5cb 100644 > --- a/drivers/mfd/Makefile > +++ b/drivers/mfd/Makefile > @@ -163,6 +163,7 @@ obj-$(CONFIG_MFD_MAX77620) += max77620.o > obj-$(CONFIG_MFD_MAX77650) += max77650.o > obj-$(CONFIG_MFD_MAX77686) += max77686.o > obj-$(CONFIG_MFD_MAX77693) += max77693.o > +obj-$(CONFIG_MFD_MAX77714) += max77714.o > obj-$(CONFIG_MFD_MAX77843) += max77843.o > obj-$(CONFIG_MFD_MAX8907) += max8907.o > max8925-objs := max8925-core.o max8925-i2c.o > diff --git a/drivers/mfd/max77714.c b/drivers/mfd/max77714.c > new file mode 100644 > index 000000000000..4b49d16fe199 > --- /dev/null > +++ b/drivers/mfd/max77714.c > @@ -0,0 +1,165 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Maxim MAX77714 MFD Driver > + * > + * Copyright (C) 2021 Luca Ceresoli > + * Author: Luca Ceresoli > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct max77714 { > + struct device *dev; > + struct regmap *regmap; > + struct regmap_irq_chip_data *irq_data; Is this used outside of .probe()? > + int irq; > +}; > + > +static const struct regmap_range max77714_readable_ranges[] = { > + regmap_reg_range(MAX77714_INT_TOP, MAX77714_INT_TOP), > + regmap_reg_range(MAX77714_INT_TOPM, MAX77714_INT_TOPM), > + regmap_reg_range(MAX77714_32K_STATUS, MAX77714_32K_CONFIG), > + regmap_reg_range(MAX77714_CNFG_GLBL2, MAX77714_CNFG2_ONOFF), > +}; > + > +static const struct regmap_range max77714_writable_ranges[] = { > + regmap_reg_range(MAX77714_INT_TOPM, MAX77714_INT_TOPM), > + regmap_reg_range(MAX77714_32K_CONFIG, MAX77714_32K_CONFIG), > + regmap_reg_range(MAX77714_CNFG_GLBL2, MAX77714_CNFG2_ONOFF), > +}; > + > +static const struct regmap_access_table max77714_readable_table = { > + .yes_ranges = max77714_readable_ranges, > + .n_yes_ranges = ARRAY_SIZE(max77714_readable_ranges), > +}; > + > +static const struct regmap_access_table max77714_writable_table = { > + .yes_ranges = max77714_writable_ranges, > + .n_yes_ranges = ARRAY_SIZE(max77714_writable_ranges), > +}; > + > +static const struct regmap_config max77714_regmap_config = { > + .reg_bits = 8, > + .val_bits = 8, > + .max_register = MAX77714_CNFG2_ONOFF, > + .rd_table = &max77714_readable_table, > + .wr_table = &max77714_writable_table, > +}; > + > +static const struct regmap_irq max77714_top_irqs[] = { > + REGMAP_IRQ_REG(MAX77714_IRQ_TOP_ONOFF, 0, MAX77714_INT_TOP_ONOFF), > + REGMAP_IRQ_REG(MAX77714_IRQ_TOP_RTC, 0, MAX77714_INT_TOP_RTC), > + REGMAP_IRQ_REG(MAX77714_IRQ_TOP_GPIO, 0, MAX77714_INT_TOP_GPIO), > + REGMAP_IRQ_REG(MAX77714_IRQ_TOP_LDO, 0, MAX77714_INT_TOP_LDO), > + REGMAP_IRQ_REG(MAX77714_IRQ_TOP_SD, 0, MAX77714_INT_TOP_SD), > + REGMAP_IRQ_REG(MAX77714_IRQ_TOP_GLBL, 0, MAX77714_INT_TOP_GLBL), > +}; > + > +static const struct regmap_irq_chip max77714_irq_chip = { > + .name = "max77714-pmic", > + .status_base = MAX77714_INT_TOP, > + .mask_base = MAX77714_INT_TOPM, > + .num_regs = 1, > + .irqs = max77714_top_irqs, > + .num_irqs = ARRAY_SIZE(max77714_top_irqs), > +}; > + > +static const struct mfd_cell max77714_cells[] = { > + { .name = "max77714-watchdog" }, > + { .name = "max77714-rtc" }, > +}; Please place this at the top of the file. > +/* > + * MAX77714 initially uses the internal, low precision oscillator. Enable > + * the external oscillator by setting the XOSC_RETRY bit. If the external > + * oscillator is not OK (probably not installed) this has no effect. > + */ > +static int max77714_setup_xosc(struct max77714 *chip) May as well just pass 'dev' and 'regmap' to this function and do away with the superfluous struct along with all of it's memory management handling requirements. > +{ > + /* Internal Crystal Load Capacitance, indexed by value of 32KLOAD bits */ > + static const unsigned int load_cap[4] = {0, 10, 12, 22}; Probably best to define these magic numbers. > + unsigned int load_cap_idx; > + unsigned int status; > + int err; > + > + err = regmap_update_bits(chip->regmap, MAX77714_32K_CONFIG, > + MAX77714_32K_CONFIG_XOSC_RETRY, > + MAX77714_32K_CONFIG_XOSC_RETRY); > + if (err) > + return dev_err_probe(chip->dev, err, "cannot configure XOSC\n"); Error messages should be clear: "Failed to configure the external oscillator" Same for the messages below. > + err = regmap_read(chip->regmap, MAX77714_32K_STATUS, &status); > + if (err) > + return dev_err_probe(chip->dev, err, "cannot read XOSC status\n"); > + > + load_cap_idx = (status >> MAX77714_32K_STATUS_32KLOAD_SHF) > + & MAX77714_32K_STATUS_32KLOAD_MSK; > + > + dev_info(chip->dev, "Using %s oscillator, %d pF load cap\n", > + status & MAX77714_32K_STATUS_32KSOURCE ? "internal" : "external", > + load_cap[load_cap_idx]); > + > + return 0; > +} > + > +static int max77714_probe(struct i2c_client *client) > +{ > + struct max77714 *chip; > + int err; > + > + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); > + if (!chip) > + return -ENOMEM; > + > + i2c_set_clientdata(client, chip); Where else is this used? The definition appears to be local. > + chip->dev = &client->dev; > + > + chip->regmap = devm_regmap_init_i2c(client, &max77714_regmap_config); > + if (IS_ERR(chip->regmap)) > + return dev_err_probe(chip->dev, PTR_ERR(chip->regmap), > + "failed to initialise regmap\n"); > + > + err = max77714_setup_xosc(chip); > + if (err) > + return err; > + > + err = devm_regmap_add_irq_chip(chip->dev, chip->regmap, client->irq, > + IRQF_ONESHOT | IRQF_SHARED, 0, > + &max77714_irq_chip, &chip->irq_data); > + if (err) > + return dev_err_probe(chip->dev, err, "failed to add PMIC irq chip\n"); IRQ > + err = devm_mfd_add_devices(chip->dev, PLATFORM_DEVID_NONE, > + max77714_cells, ARRAY_SIZE(max77714_cells), > + NULL, 0, NULL); > + if (err) > + return dev_err_probe(chip->dev, err, "failed adding MFD children\n"); "Failed to register child devices" > + return 0; > +} > + > +static const struct of_device_id max77714_dt_match[] = { > + { .compatible = "maxim,max77714" }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, max77714_dt_match); > + > +static struct i2c_driver max77714_driver = { > + .driver = { > + .name = "max77714", > + .of_match_table = max77714_dt_match, > + }, > + .probe_new = max77714_probe, > +}; > +module_i2c_driver(max77714_driver); > + > +MODULE_DESCRIPTION("Maxim MAX77714 MFD core driver"); > +MODULE_AUTHOR("Luca Ceresoli "); > +MODULE_LICENSE("GPL"); > diff --git a/include/linux/mfd/max77714.h b/include/linux/mfd/max77714.h > new file mode 100644 > index 000000000000..4a274592d4f2 > --- /dev/null > +++ b/include/linux/mfd/max77714.h > @@ -0,0 +1,60 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Maxim MAX77714 Register and data structures definition. > + * > + * Copyright (C) 2021 Luca Ceresoli > + * Author: Luca Ceresoli > + */ > + > +#ifndef __LINUX_MFD_MAX77714_H_ > +#define __LINUX_MFD_MAX77714_H_ > + > +#include > + > +#define MAX77714_INT_TOP 0x00 > +#define MAX77714_INT_TOPM 0x07 /* Datasheet says "read only", but it is RW */ > + > +#define MAX77714_INT_TOP_ONOFF BIT(1) > +#define MAX77714_INT_TOP_RTC BIT(3) > +#define MAX77714_INT_TOP_GPIO BIT(4) > +#define MAX77714_INT_TOP_LDO BIT(5) > +#define MAX77714_INT_TOP_SD BIT(6) > +#define MAX77714_INT_TOP_GLBL BIT(7) > + > +#define MAX77714_32K_STATUS 0x30 > +#define MAX77714_32K_STATUS_SIOSCOK BIT(5) > +#define MAX77714_32K_STATUS_XOSCOK BIT(4) > +#define MAX77714_32K_STATUS_32KSOURCE BIT(3) > +#define MAX77714_32K_STATUS_32KLOAD_MSK 0x3 > +#define MAX77714_32K_STATUS_32KLOAD_SHF 1 > +#define MAX77714_32K_STATUS_CRYSTAL_CFG BIT(0) > + > +#define MAX77714_32K_CONFIG 0x31 > +#define MAX77714_32K_CONFIG_XOSC_RETRY BIT(4) > + > +#define MAX77714_CNFG_GLBL2 0x91 > +#define MAX77714_WDTEN BIT(2) > +#define MAX77714_WDTSLPC BIT(3) > +#define MAX77714_TWD_MASK 0x3 > +#define MAX77714_TWD_2s 0x0 > +#define MAX77714_TWD_16s 0x1 > +#define MAX77714_TWD_64s 0x2 > +#define MAX77714_TWD_128s 0x3 > + > +#define MAX77714_CNFG_GLBL3 0x92 > +#define MAX77714_WDTC BIT(0) > + > +#define MAX77714_CNFG2_ONOFF 0x94 > +#define MAX77714_WD_RST_WK BIT(5) > + > +/* Interrupts */ > +enum { > + MAX77714_IRQ_TOP_ONOFF, > + MAX77714_IRQ_TOP_RTC, /* Real-time clock */ > + MAX77714_IRQ_TOP_GPIO, /* GPIOs */ > + MAX77714_IRQ_TOP_LDO, /* Low-dropout regulators */ > + MAX77714_IRQ_TOP_SD, /* Step-down regulators */ > + MAX77714_IRQ_TOP_GLBL, /* "Global resources": Low-Battery, overtemp... */ > +}; > + > +#endif /* __LINUX_MFD_MAX77714_H_ */ -- Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog