From patchwork Wed Jan 18 06:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sahin, Okan" X-Patchwork-Id: 45049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2195039wrn; Tue, 17 Jan 2023 23:36:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXvgRb7qjQh4Y/9btAZj/MOC0odsJSvXYf3zzA6JWK63tQavYQSmiOEZwKLHu9nnv5wYE/5C X-Received: by 2002:a05:6a20:54aa:b0:b6:99c7:9283 with SMTP id i42-20020a056a2054aa00b000b699c79283mr8923217pzk.12.1674027370416; Tue, 17 Jan 2023 23:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674027370; cv=none; d=google.com; s=arc-20160816; b=Woks7P7EoDjgUYHcpsFYeSxplrgEghStENXKpuzbMXzZMwVpvVnpU48juoBRNzEn5V 4kvGz3NhAY+gXKaCgsp7pLSr3FjMFmSwrHmPuDN0AVxYXwNIJV4Qr5d4A0HSlcEAhZkB qobinnoL5TWOJ5AgXYSCC3bTBnKr6VOpP5AyUFAYdWpveeLjuZcWe3S4dQBjZYWp94cU 4raW+xWts7NWbIZ8rQ9YjUIDmiOSsMFcnjlGC2eVV1WTZOg9wdzwsFRvFq+/KHm1aL1z wUMppK2kmJiW8Hu7D4U0lqYzuehZbg6YU8L2dLjWLPAF5hUi/wq+Jg9+ZCAHK3Ka3yQX 8iuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=w9CirK/GUs5Pa4CIDkFNkWPN6Ek3bkRSQAGF9wNfYEU=; b=e6WFSm0cHwcvrTWvs0AhLgEIlRRGf2ruXasJdmoWsynUgQYOwxhDB9UE/LuC3F0ktx h5THnq9AQIE9e36MMNfPiEefE10xuED04PiylQUOLNZU3p4Po9AIPV4LcA99pJQl5KQc BEMi4J//dhx6zUsageKwbhh/WJHtcRKdMLUYIDY3BaeB8NF3Oql5ocP3F8kJlqPF15ut j5tUfJxdWrDlxqqGfAx4IWYlGs4Ic6WrTgbMYsaLFDC1L7zp1TqtoleOlCHzwTW7B8EW b5Q9J7bRjkvx22Drt0pWfR0qMcnrLgSd54ImBEq+ZF7XFVEHRKpKazJfofk+FWgl4pFM xxTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z21-20020aa78895000000b00557e99763d3si6090832pfe.93.2023.01.17.23.35.58; Tue, 17 Jan 2023 23:36:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbjARHR2 (ORCPT + 99 others); Wed, 18 Jan 2023 02:17:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjARHQ1 (ORCPT ); Wed, 18 Jan 2023 02:16:27 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8408D7A537; Tue, 17 Jan 2023 22:40:00 -0800 (PST) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30I50Ve4024672; Wed, 18 Jan 2023 01:39:40 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3n6048mc65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 01:39:39 -0500 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 30I6dc57050855 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Jan 2023 01:39:38 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:39:37 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Wed, 18 Jan 2023 01:39:37 -0500 Received: from okan.localdomain ([10.158.40.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 30I6ccUs005042; Wed, 18 Jan 2023 01:39:20 -0500 From: Okan Sahin To: CC: Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Caleb Connolly , Lad Prabhakar , William Breathitt Gray , Ramona Bolboaca , ChiYuan Huang , , , Subject: [PATCH v3 1/5] drivers: mfd: Add ADI MAX77541/MAX77540 PMIC Support Date: Wed, 18 Jan 2023 09:38:08 +0300 Message-ID: <20230118063822.14521-2-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230118063822.14521-1-okan.sahin@analog.com> References: <20230118063822.14521-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: OnZDbr9-KLpnTyXzsvlDWDcey9as2QNj X-Proofpoint-ORIG-GUID: OnZDbr9-KLpnTyXzsvlDWDcey9as2QNj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_01,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 phishscore=0 clxscore=1015 spamscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301180057 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755344923763425079?= X-GMAIL-MSGID: =?utf-8?q?1755344923763425079?= MFD driver for MAX77541/MAX77540 to enable its sub devices. The MAX77541 is a multi-function devices. It includes buck converter and ADC. The MAX77540 is a high-efficiency buck converter with two 3A switching phases. They have same regmap except for ADC part of MAX77541. Signed-off-by: Okan Sahin --- MAINTAINERS | 7 + drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 1 + drivers/mfd/max77541.c | 250 +++++++++++++++++++++++++++++++++++ include/linux/mfd/max77541.h | 108 +++++++++++++++ 5 files changed, 379 insertions(+) create mode 100644 drivers/mfd/max77541.c create mode 100644 include/linux/mfd/max77541.h diff --git a/MAINTAINERS b/MAINTAINERS index cf0f18502372..af94d06bb9f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12497,6 +12497,13 @@ S: Maintained F: Documentation/devicetree/bindings/regulator/maxim,max20086.yaml F: drivers/regulator/max20086-regulator.c +MAXIM MAX77541 PMIC MFD DRIVER +M: Okan Sahin +L: linux-kernel@vger.kernel.org +S: Maintained +F: drivers/mfd/max77541.c +F: include/linux/mfd/max77541.h + MAXIM MAX77650 PMIC MFD DRIVER M: Bartosz Golaszewski L: linux-kernel@vger.kernel.org diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 8b93856de432..e6bf621cbc8e 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -791,6 +791,19 @@ config MFD_MAX14577 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MAX77541 + tristate "Analog Devices MAX77541/77540 PMIC Support" + depends on I2C=y + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Analog Devices + MAX77541 and MAX77540 Power Management ICs.This + driver provides common support for accessing the + device;additional drivers must be enabled in order + to use the functionality of the device. + config MFD_MAX77620 bool "Maxim Semiconductor MAX77620 and MAX20024 PMIC Support" depends on I2C=y diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 7ed3ef4a698c..bf21228f5742 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -161,6 +161,7 @@ obj-$(CONFIG_MFD_DA9063) += da9063.o obj-$(CONFIG_MFD_DA9150) += da9150-core.o obj-$(CONFIG_MFD_MAX14577) += max14577.o +obj-$(CONFIG_MFD_MAX77541) += max77541.o obj-$(CONFIG_MFD_MAX77620) += max77620.o obj-$(CONFIG_MFD_MAX77650) += max77650.o obj-$(CONFIG_MFD_MAX77686) += max77686.o diff --git a/drivers/mfd/max77541.c b/drivers/mfd/max77541.c new file mode 100644 index 000000000000..0ccb96df5db0 --- /dev/null +++ b/drivers/mfd/max77541.c @@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Analog Devices, Inc. + * Mfd core driver for the MAX77540 and MAX77541 + */ + +#include +#include +#include +#include +#include + +static const struct regmap_config max77541_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static const struct regmap_irq max77541_src_irqs[] = { + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_INT_SRC_TOPSYS), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_INT_SRC_BUCK), +}; + +static const struct regmap_irq_chip max77541_src_irq_chip = { + .name = "max77541-src", + .status_base = MAX77541_REG_INT_SRC, + .mask_base = MAX77541_REG_INT_SRC, + .num_regs = 1, + .irqs = max77541_src_irqs, + .num_irqs = ARRAY_SIZE(max77541_src_irqs), +}; + +static const struct regmap_irq max77541_topsys_irqs[] = { + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_TOPSYS_INT_TJ_120C), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_TOPSYS_INT_TJ_140C), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_TOPSYS_INT_TSHDN), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_TOPSYS_INT_UVLO), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_TOPSYS_INT_ALT_SWO), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_TOPSYS_INT_EXT_FREQ_DET), +}; + +static const struct regmap_irq_chip max77541_topsys_irq_chip = { + .name = "max77541-topsys", + .status_base = MAX77541_REG_TOPSYS_INT, + .mask_base = MAX77541_REG_TOPSYS_INT_M, + .num_regs = 1, + .irqs = max77541_topsys_irqs, + .num_irqs = ARRAY_SIZE(max77541_topsys_irqs), +}; + +static const struct regmap_irq max77541_buck_irqs[] = { + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_BUCK_INT_M1_POK_FLT), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_BUCK_INT_M2_POK_FLT), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_BUCK_INT_M1_SCFLT), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_BUCK_INT_M2_SCFLT), +}; + +static const struct regmap_irq_chip max77541_buck_irq_chip = { + .name = "max77541-buck", + .status_base = MAX77541_REG_BUCK_INT, + .mask_base = MAX77541_REG_BUCK_INT_M, + .num_regs = 1, + .irqs = max77541_buck_irqs, + .num_irqs = ARRAY_SIZE(max77541_buck_irqs), +}; + +static const struct regmap_irq max77541_adc_irqs[] = { + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_ADC_INT_CH1_I), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_ADC_INT_CH2_I), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_ADC_INT_CH3_I), + MAX77541_REGMAP_IRQ_REG(MAX77541_BIT_ADC_INT_CH6_I), +}; + +static const struct regmap_irq_chip max77541_adc_irq_chip = { + .name = "max77541-adc", + .status_base = MAX77541_REG_ADC_INT, + .mask_base = MAX77541_REG_ADC_MSK, + .num_regs = 1, + .irqs = max77541_adc_irqs, + .num_irqs = ARRAY_SIZE(max77541_adc_irqs), +}; + +static const struct mfd_cell max77540_devs[] = { + MFD_CELL_OF("max77540-regulator", NULL, NULL, 0, 0, + "adi,max77540-regulator"), +}; + +static const struct mfd_cell max77541_devs[] = { + MFD_CELL_OF("max77541-regulator", NULL, NULL, 0, 0, + "adi,max77541-regulator"), + MFD_CELL_OF("max77541-adc", NULL, NULL, 0, 0, + NULL), +}; + +static const struct chip_info chip[] = { + [MAX77540] = { + .n_devs = ARRAY_SIZE(max77540_devs), + .devs = max77540_devs, + }, + [MAX77541] = { + .n_devs = ARRAY_SIZE(max77541_devs), + .devs = max77541_devs, + }, +}; + +static int max77541_pmic_irq_init(struct device *dev) +{ + struct max77541 *max77541 = dev_get_drvdata(dev); + int irq = max77541->i2c->irq; + int ret; + + ret = devm_regmap_add_irq_chip(dev, max77541->regmap, irq, + IRQF_ONESHOT | IRQF_SHARED, 0, + &max77541_src_irq_chip, + &max77541->irq_data); + if (ret) + return ret; + + ret = devm_regmap_add_irq_chip(dev, max77541->regmap, irq, + IRQF_ONESHOT | IRQF_SHARED, 0, + &max77541_topsys_irq_chip, + &max77541->irq_topsys); + if (ret) + return ret; + + ret = devm_regmap_add_irq_chip(dev, max77541->regmap, irq, + IRQF_ONESHOT | IRQF_SHARED, 0, + &max77541_buck_irq_chip, + &max77541->irq_buck); + if (ret) + return ret; + + if (max77541->id == MAX77541) { + ret = devm_regmap_add_irq_chip(dev, max77541->regmap, irq, + IRQF_ONESHOT | IRQF_SHARED, 0, + &max77541_adc_irq_chip, + &max77541->irq_adc); + if (ret) + return ret; + } + + return ret; +} + +static int max77541_pmic_setup(struct device *dev) +{ + struct max77541 *max77541 = dev_get_drvdata(dev); + unsigned int val; + int ret; + + ret = max77541_pmic_irq_init(dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize IRQ\n"); + + ret = regmap_read(max77541->regmap, MAX77541_REG_INT_SRC, &val); + if (ret) + return ret; + + ret = regmap_read(max77541->regmap, MAX77541_REG_TOPSYS_INT, &val); + if (ret) + return ret; + + ret = regmap_read(max77541->regmap, MAX77541_REG_BUCK_INT, &val); + if (ret) + return ret; + + ret = device_init_wakeup(dev, true); + if (ret) + return dev_err_probe(dev, ret, "Unable to init wakeup\n"); + + switch (max77541->id) { + case MAX77540: + return devm_mfd_add_devices(dev, -1, max77540_devs, + ARRAY_SIZE(max77540_devs), + NULL, 0, NULL); + case MAX77541: + return devm_mfd_add_devices(dev, -1, max77541_devs, + ARRAY_SIZE(max77541_devs), + NULL, 0, NULL); + default: + return -EINVAL; + } +} + +static int max77541_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct max77541 *max77541; + const void *match; + + max77541 = devm_kzalloc(&client->dev, sizeof(*max77541), GFP_KERNEL); + if (!max77541) + return -ENOMEM; + + i2c_set_clientdata(client, max77541); + max77541->i2c = client; + + match = device_get_match_data(dev); + if (match) + max77541->id = (enum max7754x_ids)match; + else if (id) + max77541->id = id->driver_data; + else + return -ENODEV; + + max77541->chip = &chip[max77541->id]; + + max77541->regmap = devm_regmap_init_i2c(client, + &max77541_regmap_config); + if (IS_ERR(max77541->regmap)) + return dev_err_probe(dev, PTR_ERR(max77541->regmap), + "Failed to allocate register map\n"); + + return max77541_pmic_setup(dev); +} + +static const struct of_device_id max77541_of_id[] = { + { + .compatible = "adi,max77540", + .data = (void *)MAX77540, + }, + { + .compatible = "adi,max77541", + .data = (void *)MAX77541, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, max77541_of_id); + +static const struct i2c_device_id max77541_i2c_id[] = { + { "max77540", MAX77540 }, + { "max77541", MAX77541 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, max77541_i2c_id); + +static struct i2c_driver max77541_i2c_driver = { + .driver = { + .name = "max77541", + .of_match_table = max77541_of_id, + }, + .probe = max77541_i2c_probe, + .id_table = max77541_i2c_id, +}; +module_i2c_driver(max77541_i2c_driver); + +MODULE_DESCRIPTION("MAX7740/MAX7741 MFD Driver"); +MODULE_AUTHOR("Okan Sahin "); +MODULE_LICENSE("GPL"); +MODULE_VERSION("1.0"); diff --git a/include/linux/mfd/max77541.h b/include/linux/mfd/max77541.h new file mode 100644 index 000000000000..44c3c0c2aa97 --- /dev/null +++ b/include/linux/mfd/max77541.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __MAX77541_MFD_H__ +#define __MAX77541_MFD_H__ + +#include +#include + +/* REGISTERS */ + +/* GLOBAL CONFIG1 */ +#define MAX77541_REG_INT_SRC 0x00 +#define MAX77541_REG_INT_SRC_M 0x01 +#define MAX77541_REG_TOPSYS_INT 0x02 +#define MAX77541_REG_TOPSYS_INT_M 0x03 + +#define MAX77541_REG_EN_CTRL 0x0B + +/* BUCK CONFIG */ +#define MAX77541_REG_BUCK_INT 0x20 +#define MAX77541_REG_BUCK_INT_M 0x21 + +#define MAX77541_REG_M1_VOUT 0x23 +#define MAX77541_REG_M1_CFG1 0x25 + +#define MAX77541_REG_M2_VOUT 0x33 +#define MAX77541_REG_M2_CFG1 0x35 + +/* INTERRUPT MASKS*/ +#define MAX77541_REG_INT_SRC_MASK 0x00 +#define MAX77541_REG_TOPSYS_INT_MASK 0x00 +#define MAX77541_REG_BUCK_INT_MASK 0x00 + +/*BITS OF REGISTERS*/ + +#define MAX77541_BIT_INT_SRC_TOPSYS BIT(0) +#define MAX77541_BIT_INT_SRC_BUCK BIT(1) + +#define MAX77541_BIT_TOPSYS_INT_TJ_120C BIT(0) +#define MAX77541_BIT_TOPSYS_INT_TJ_140C BIT(1) +#define MAX77541_BIT_TOPSYS_INT_TSHDN BIT(2) +#define MAX77541_BIT_TOPSYS_INT_UVLO BIT(3) +#define MAX77541_BIT_TOPSYS_INT_ALT_SWO BIT(4) +#define MAX77541_BIT_TOPSYS_INT_EXT_FREQ_DET BIT(5) + +#define MAX77541_BIT_BUCK_INT_M1_POK_FLT BIT(0) +#define MAX77541_BIT_BUCK_INT_M2_POK_FLT BIT(1) +#define MAX77541_BIT_BUCK_INT_M1_SCFLT BIT(4) +#define MAX77541_BIT_BUCK_INT_M2_SCFLT BIT(5) + +#define MAX77541_BIT_M1_EN BIT(0) +#define MAX77541_BIT_M2_EN BIT(1) + +#define MAX77541_BITS_MX_VOUT GENMASK(7, 0) +#define MAX77541_BITS_MX_CFG1_RNG GENMASK(7, 6) + +/* ADC */ +#define MAX77541_REG_ADC_INT 0x70 +#define MAX77541_REG_ADC_MSK 0x71 + +#define MAX77541_REG_ADC_DATA_CH1 0x72 +#define MAX77541_REG_ADC_DATA_CH2 0x73 +#define MAX77541_REG_ADC_DATA_CH3 0x74 +#define MAX77541_REG_ADC_DATA_CH6 0x77 + +#define MAX77541_BIT_ADC_INT_CH1_I BIT(0) +#define MAX77541_BIT_ADC_INT_CH2_I BIT(1) +#define MAX77541_BIT_ADC_INT_CH3_I BIT(2) +#define MAX77541_BIT_ADC_INT_CH6_I BIT(5) + +#define MAX77541_MAX_REGULATORS 2 + +#define MAX77541_REGMAP_IRQ_REG(_mask) \ + { .mask = (_mask) } + +enum max7754x_ids { + MAX77540 = 1, + MAX77541 = 2, +}; + +enum max77541_regulators { + MAX77541_BUCK1 = 1, + MAX77541_BUCK2, +}; + +struct chip_info { + int n_devs; + const struct mfd_cell *devs; +}; + +struct regmap; +struct regmap_irq_chip_data; +struct i2c_client; + +struct max77541 { + enum max7754x_ids id; + const struct chip_info *chip; + + struct regmap_irq_chip_data *irq_data; + struct regmap_irq_chip_data *irq_buck; + struct regmap_irq_chip_data *irq_topsys; + struct regmap_irq_chip_data *irq_adc; + + struct i2c_client *i2c; + struct regmap *regmap; +}; + +#endif /* __MAX77541_MFD_H__ */ From patchwork Wed Jan 18 06:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sahin, Okan" X-Patchwork-Id: 45051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2195189wrn; Tue, 17 Jan 2023 23:36:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWV0rQLyZNysu4Dg9fWHBOSAa44NvkALw5q31+vD2NuycHDPhat7VhguzDLlnjb3Z46tzO X-Received: by 2002:a17:907:8b09:b0:873:2612:e12c with SMTP id sz9-20020a1709078b0900b008732612e12cmr5237602ejc.21.1674027392704; Tue, 17 Jan 2023 23:36:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674027392; cv=none; d=google.com; s=arc-20160816; b=OFyUfQnA5QOXleufn7VbwsrIz2BdGgprwoHONv5udy1D4nmPQtWt/mPPlE6rbdKNFE iDhZqTE2Hq5kkQglVJYvznF9qNb9muWL6FVPFoZb9g9mmWRt7ovJ/A3+h1FjcP73CPhr 9jKF6VtoJGqWzKLInRVOoRxV8LX2HHcFAbKxPpjs+bi51KOwuhrSH4g9T2yRo+k658jp BFAVxYfrDefg6yJhhOEQRRgFYcpQMj5AQcGb+qKwSXZmLquup6V8TyWTkPbUeZp3tEi8 sAZTGrd4SSAR4SwyRhRc1jqJ6OGcwG8CKDAOrfhXlewCc3PG6Dn1o4tuGz4vtIgONDNj gECQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nplG1POEjoMUXbnSRMHvvCc+zEJGeO//3yq3iHJJJXc=; b=glNBf+Ik6BhSl9Viw/g84f7rtiU93z1vS77foY/xmg9u//PGVBINeMucr5q8nI8AAw 0HzbDyVTA9K+fM3yq2MGBUvwwE9rCMsEtrVJtskJi6KVS2uEXtVfnwPx4TjV09xjxIAt iIMfEHJtKToAMcNgNV7ToeyU6AH9lmVfKMlJi7Au5Rv4eKI9dqO+6cIjbOeaWEy89mii NgdVvIdWVgcMgtrKt2EXCpxKeRS/FesNiNsj9D13aSwGi9Ya3UBx/83YkMoSPWRD/Ct0 Z7J2cLnM4daa2j52Ro823YBDr44cKiucCk6I/lN4MTZtZ6GkSBKLu+pjEPckISs6MSyK IN2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du1-20020a17090772c100b0080f0493b9c8si39460627ejc.536.2023.01.17.23.36.08; Tue, 17 Jan 2023 23:36:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbjARHSC (ORCPT + 99 others); Wed, 18 Jan 2023 02:18:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjARHQq (ORCPT ); Wed, 18 Jan 2023 02:16:46 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 353BE5B59A; Tue, 17 Jan 2023 22:40:29 -0800 (PST) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30I4em6d024711; Wed, 18 Jan 2023 01:40:12 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3n6048mc7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 01:40:12 -0500 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 30I6eBi7002678 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Jan 2023 01:40:11 -0500 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:40:10 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:40:09 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Wed, 18 Jan 2023 01:40:09 -0500 Received: from okan.localdomain ([10.158.40.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 30I6ccUt005042; Wed, 18 Jan 2023 01:39:53 -0500 From: Okan Sahin To: CC: Lee Jones , Rob Herring , "Krzysztof Kozlowski" , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Caleb Connolly , Marcus Folkesson , Ramona Bolboaca , William Breathitt Gray , ChiYuan Huang , , , Subject: [PATCH v3 2/5] dt-bindings: mfd: Add ADI MAX77541/MAX77540 Date: Wed, 18 Jan 2023 09:38:09 +0300 Message-ID: <20230118063822.14521-3-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230118063822.14521-1-okan.sahin@analog.com> References: <20230118063822.14521-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: _p4AJKZ8iURkrSgALAzN46vnIqB6HLlJ X-Proofpoint-ORIG-GUID: _p4AJKZ8iURkrSgALAzN46vnIqB6HLlJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_01,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=991 suspectscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 phishscore=0 clxscore=1011 spamscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301180057 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755344947575229553?= X-GMAIL-MSGID: =?utf-8?q?1755344947575229553?= Add ADI MAX77541/MAX77540 devicetree document. Signed-off-by: Okan Sahin --- .../devicetree/bindings/mfd/adi,max77541.yaml | 87 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 88 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/adi,max77541.yaml diff --git a/Documentation/devicetree/bindings/mfd/adi,max77541.yaml b/Documentation/devicetree/bindings/mfd/adi,max77541.yaml new file mode 100644 index 000000000000..91d15e9ca2e3 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/adi,max77541.yaml @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/adi,max77541.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MAX77540/MAX77541 PMIC from ADI + +maintainers: + - Okan Sahin + +description: | + MAX77540 is a Power Management IC with 2 buck regulators. + + MAX77541 is a Power Management IC with 2 buck regulators and 1 ADC. + +properties: + compatible: + enum: + - adi,max77540 + - adi,max77541 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + regulators: + $ref: /schemas/regulator/adi,max77541-regulator.yaml# + +required: + - compatible + - reg + - interrupts + +allOf: + - if: + properties: + compatible: + contains: + const: adi,max77540 + then: + properties: + regulator: + properties: + compatible: + const: adi,max77540-regulator + else: + properties: + regulator: + properties: + compatible: + const: adi,max77541-regulator + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@69 { + compatible = "adi,max77541"; + reg = <0x69>; + interrupt-parent = <&gpio>; + interrupts = <16 IRQ_TYPE_EDGE_FALLING>; + + regulators { + buck1 { + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <5200000>; + regulator-boot-on; + regulator-always-on; + }; + buck2 { + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <5200000>; + regulator-boot-on; + regulator-always-on; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index af94d06bb9f0..22f5a9c490e3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12501,6 +12501,7 @@ MAXIM MAX77541 PMIC MFD DRIVER M: Okan Sahin L: linux-kernel@vger.kernel.org S: Maintained +F: Documentation/devicetree/bindings/mfd/adi,max77541.yaml F: drivers/mfd/max77541.c F: include/linux/mfd/max77541.h From patchwork Wed Jan 18 06:38:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sahin, Okan" X-Patchwork-Id: 45050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2195125wrn; Tue, 17 Jan 2023 23:36:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsbEU21cMzI9sXOmbhmhOpOc1LsZ+JHIQTXeEua25yZi47wU/C/U2yFoQvbkgrnR3pSkJ6o X-Received: by 2002:a17:90a:a2f:b0:219:b936:6bd7 with SMTP id o44-20020a17090a0a2f00b00219b9366bd7mr6574155pjo.19.1674027385409; Tue, 17 Jan 2023 23:36:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674027385; cv=none; d=google.com; s=arc-20160816; b=M7tC1ae09Fy92HnfgcmmTFw4Lmr59s2y3KiGLYw7+ICmLzYiiFRyf2VXHTl0XUyGNM VBTw8TfviLXhtC9L2+2Wmn0IFEh85IHtdmAB9iAJh8+xrQqZ7deSKqspMwlhhxxzveE+ +FDatrNqK7kfhiShk7gpA0ch/T0ln3UbhCiETnyDWbmbQv4yVFyJMLwAV3sruAHuveWk GXOhc/yOD64Ok5XjzMPaoEoO7B0ieUfUiRza3gdOIK5IEDT575yu8YaihYPC1A9ybG7s 5SRf5wRNEHjEMJDkQHTENlZ3zoBxNYc0wElLH0FM/Nw9+eXjaigq9ug/e/heF3BFZnIe sE4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yA2TcADhj3z0OBQEodLe+uAk9+XpOcYlwIx04A2dLBY=; b=jzzyVUMcGaqPFnZwAB6ZmSg9UmvMT8l5freOqCLkG7XnfUCJDBUeDlrR76rRss7XuN R+eMd7F+m4loDzv70gjUTODxUUYAbul3pREsHb/GUSXYVIxgm7moqbHE/OQLegRvOgDU kJYePrhiSiNxtyKHTUOq9+bBfRsLny/kLuSQfE5QRoDTvH+YRINZAecj/iPniqR/uAf4 UW7dpE+PAtZVxC37HxsnCoPHFDR7hwQAmE8n0MgkUXtBlmc1nDo9URg6idM3+fu3E9pD eUpiFNSsdsmlHjcug/qVJf7Xri+JZx6cAz3cmosPgzZGKjBwu2tH0h2r8D4VXiN5KJ0Y rwrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v31-20020a63151f000000b0049ca23d4915si33198456pgl.104.2023.01.17.23.36.13; Tue, 17 Jan 2023 23:36:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229790AbjARHS2 (ORCPT + 99 others); Wed, 18 Jan 2023 02:18:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230058AbjARHQ4 (ORCPT ); Wed, 18 Jan 2023 02:16:56 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71CA95B5A6; Tue, 17 Jan 2023 22:41:00 -0800 (PST) Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30I5I1T4024663; Wed, 18 Jan 2023 01:40:42 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3n6048mca9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 01:40:41 -0500 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 30I6eeAG002714 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Jan 2023 01:40:40 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:40:39 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Wed, 18 Jan 2023 01:40:39 -0500 Received: from okan.localdomain ([10.158.40.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 30I6ccUu005042; Wed, 18 Jan 2023 01:40:23 -0500 From: Okan Sahin To: CC: Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , ChiYuan Huang , Ramona Bolboaca , Caleb Connolly , William Breathitt Gray , , , Subject: [PATCH v3 3/5] drivers: regulator: Add ADI MAX77541/MAX77540 Regulator Support Date: Wed, 18 Jan 2023 09:38:10 +0300 Message-ID: <20230118063822.14521-4-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230118063822.14521-1-okan.sahin@analog.com> References: <20230118063822.14521-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: CLeYi4gvX2V921_rjSAQGM4XCKDyXsGT X-Proofpoint-ORIG-GUID: CLeYi4gvX2V921_rjSAQGM4XCKDyXsGT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_01,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 phishscore=0 clxscore=1015 spamscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301180057 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755344939728208342?= X-GMAIL-MSGID: =?utf-8?q?1755344939728208342?= Regulator driver for both MAX77541 and MAX77540. The MAX77541 is a high-efficiency step-down converter with two 3A switching phases for single-cell Li+ battery and 5VDC systems. The MAX77540 is a high-efficiency step-down converter with two 3A switching phases. Signed-off-by: Okan Sahin --- MAINTAINERS | 1 + drivers/regulator/Kconfig | 9 ++ drivers/regulator/Makefile | 1 + drivers/regulator/max77541-regulator.c | 160 +++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 drivers/regulator/max77541-regulator.c diff --git a/MAINTAINERS b/MAINTAINERS index 22f5a9c490e3..5704ed5afce3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12503,6 +12503,7 @@ L: linux-kernel@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/mfd/adi,max77541.yaml F: drivers/mfd/max77541.c +F: drivers/regulator/max77541-regulator.c F: include/linux/mfd/max77541.h MAXIM MAX77650 PMIC MFD DRIVER diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 070e4403c6c2..1e416c195af9 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -556,6 +556,15 @@ config REGULATOR_MAX597X The MAX5970/5978 is a smart switch with no output regulation, but fault protection and voltage and current monitoring capabilities. +config REGULATOR_MAX77541 + tristate "Analog Devices MAX77541/77540 Regulator" + depends on MFD_MAX77541 + help + This driver controls a Analog Devices MAX77541/77540 regulators + via I2C bus. Both MAX77540 and MAX77541 are dual-phase + high-efficiency buck converter. Say Y here to + enable the regulator driver. + config REGULATOR_MAX77620 tristate "Maxim 77620/MAX20024 voltage regulator" depends on MFD_MAX77620 || COMPILE_TEST diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 5962307e1130..c19efc7cfbef 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -68,6 +68,7 @@ obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o obj-$(CONFIG_REGULATOR_MAX597X) += max597x-regulator.o +obj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o diff --git a/drivers/regulator/max77541-regulator.c b/drivers/regulator/max77541-regulator.c new file mode 100644 index 000000000000..342d4f59405c --- /dev/null +++ b/drivers/regulator/max77541-regulator.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Analog Devices, Inc. + * ADI Regulator driver for the MAX77540 and MAX77541 + */ + +#include +#include +#include +#include +#include +#include + +static const struct regulator_ops max77541_buck_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .list_voltage = regulator_list_voltage_pickable_linear_range, + .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, + .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap, +}; + +static const struct linear_range max77540_buck_ranges[] = { + /* Ranges when VOLT_SEL bits are 0x00 */ + REGULATOR_LINEAR_RANGE(500000, 0x00, 0x8B, 5000), + REGULATOR_LINEAR_RANGE(1200000, 0x8C, 0xFF, 0), + /* Ranges when VOLT_SEL bits are 0x40 */ + REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x8B, 10000), + REGULATOR_LINEAR_RANGE(2400000, 0x8C, 0xFF, 0), + /* Ranges when VOLT_SEL bits are 0x80 */ + REGULATOR_LINEAR_RANGE(2000000, 0x00, 0x9F, 20000), + REGULATOR_LINEAR_RANGE(5200000, 0xA0, 0xFF, 0), +}; + +static const struct linear_range max77541_buck_ranges[] = { + /* Ranges when VOLT_SEL bits are 0x00 */ + REGULATOR_LINEAR_RANGE(300000, 0x00, 0xB3, 5000), + REGULATOR_LINEAR_RANGE(1200000, 0xB4, 0xFF, 0), + /* Ranges when VOLT_SEL bits are 0x40 */ + REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x8B, 10000), + REGULATOR_LINEAR_RANGE(2400000, 0x8C, 0xFF, 0), + /* Ranges when VOLT_SEL bits are 0x80 */ + REGULATOR_LINEAR_RANGE(2000000, 0x00, 0x9F, 20000), + REGULATOR_LINEAR_RANGE(5200000, 0xA0, 0xFF, 0), +}; + +static const unsigned int max77541_buck_volt_range_sel[] = { + 0x00, 0x00, 0x40, 0x40, 0x80, 0x80, +}; + +#define MAX77540_BUCK(_id, _ops) \ + { .id = MAX77541_BUCK ## _id, \ + .name = "buck"#_id, \ + .of_match = "buck"#_id, \ + .regulators_node = "regulators", \ + .enable_reg = MAX77541_REG_EN_CTRL, \ + .enable_mask = MAX77541_BIT_M ## _id ## _EN, \ + .ops = &(_ops), \ + .type = REGULATOR_VOLTAGE, \ + .linear_ranges = max77540_buck_ranges, \ + .n_linear_ranges = ARRAY_SIZE(max77540_buck_ranges), \ + .vsel_reg = MAX77541_REG_M ## _id ## _VOUT, \ + .vsel_mask = MAX77541_BITS_MX_VOUT, \ + .vsel_range_reg = MAX77541_REG_M ## _id ## _CFG1, \ + .vsel_range_mask = MAX77541_BITS_MX_CFG1_RNG, \ + .linear_range_selectors = max77541_buck_volt_range_sel, \ + .owner = THIS_MODULE, \ + } + +#define MAX77541_BUCK(_id, _ops) \ + { .id = MAX77541_BUCK ## _id, \ + .name = "buck"#_id, \ + .of_match = "buck"#_id, \ + .regulators_node = "regulators", \ + .enable_reg = MAX77541_REG_EN_CTRL, \ + .enable_mask = MAX77541_BIT_M ## _id ## _EN, \ + .ops = &(_ops), \ + .type = REGULATOR_VOLTAGE, \ + .linear_ranges = max77541_buck_ranges, \ + .n_linear_ranges = ARRAY_SIZE(max77541_buck_ranges), \ + .vsel_reg = MAX77541_REG_M ## _id ## _VOUT, \ + .vsel_mask = MAX77541_BITS_MX_VOUT, \ + .vsel_range_reg = MAX77541_REG_M ## _id ## _CFG1, \ + .vsel_range_mask = MAX77541_BITS_MX_CFG1_RNG, \ + .linear_range_selectors = max77541_buck_volt_range_sel, \ + .owner = THIS_MODULE, \ + } + +static const struct regulator_desc max77540_regulators_desc[] = { + MAX77540_BUCK(1, max77541_buck_ops), + MAX77540_BUCK(2, max77541_buck_ops), +}; + +static const struct regulator_desc max77541_regulators_desc[] = { + MAX77541_BUCK(1, max77541_buck_ops), + MAX77541_BUCK(2, max77541_buck_ops), +}; + +static int max77541_regulator_probe(struct platform_device *pdev) +{ + struct max77541 *max77541 = dev_get_drvdata(pdev->dev.parent); + struct regulator_config config = {}; + const struct regulator_desc *desc; + struct device *dev = &pdev->dev; + struct regulator_dev *rdev; + int i; + + config.dev = pdev->dev.parent; + + if (max77541->id == MAX77540) + desc = max77540_regulators_desc; + else if (max77541->id == MAX77541) + desc = max77541_regulators_desc; + else + return -EINVAL; + + for (i = 0; i < MAX77541_MAX_REGULATORS; i++) { + rdev = devm_regulator_register(dev, + &desc[i], &config); + if (IS_ERR(rdev)) + return dev_err_probe(dev, PTR_ERR(rdev), + "Failed to register regulator\n"); + } + + return 0; +} + +static const struct platform_device_id max77541_regulator_platform_id[] = { + { "max77540-regulator", MAX77540 }, + { "max77541-regulator", MAX77541 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, max77541_regulator_platform_id); + +static const struct of_device_id max77541_regulator_of_id[] = { + { + .compatible = "adi,max77540-regulator", + .data = (void *)MAX77540, + }, + { + .compatible = "adi,max77541-regulator", + .data = (void *)MAX77541, + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, max77541_regulator_of_id); + +static struct platform_driver max77541_regulator_driver = { + .driver = { + .name = "max77541-regulator", + .of_match_table = max77541_regulator_of_id, + }, + .probe = max77541_regulator_probe, + .id_table = max77541_regulator_platform_id, +}; +module_platform_driver(max77541_regulator_driver); + +MODULE_AUTHOR("Okan Sahin "); +MODULE_DESCRIPTION("MAX77540/MAX77541 regulator driver"); +MODULE_LICENSE("GPL"); From patchwork Wed Jan 18 06:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sahin, Okan" X-Patchwork-Id: 45052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2195263wrn; Tue, 17 Jan 2023 23:36:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXv/+FauF9wgMIxIjAfeEYDwCDtCf/SDlNncBTdoT0o1rLgzeRtAAhFGcqonNY1OS7el1TFS X-Received: by 2002:a05:6a20:d045:b0:ac:3f3f:9fbd with SMTP id hv5-20020a056a20d04500b000ac3f3f9fbdmr6362541pzb.48.1674027401883; Tue, 17 Jan 2023 23:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674027401; cv=none; d=google.com; s=arc-20160816; b=QMyt9cT+PeD5ZOYhVF4xQOYsVPqTDdZ453QolPsHmiqQx7wZM5cMW3cn1e39rh2XkV 7PhF0A1G2ZjYkY9tfYzIwh+mguO9JVk0quDnr707k4Pu3FP3bjWKTyK8pRbLkWQv+R4N LvNBu+08oQQeprMZeR3fvDfCGJJq2hL2tLJi2LQ68X1wHC1WOqOpD2NxVRYxOC0E+iru V9yl5aZR6SbcDt6glFUpLbwdZ/MsPFXGApaC5ixY/jVx6hKlDJTaP2sqVVDZvivTi/E7 i6tUbPJ19G3+wgoWRqzORouDsSysm1aXtyrk+N35phQRrcGZldPrpdh2/0y5Pw08ni9n EEsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nCntozt9Ai2CRdd7dY5LbQev/AaGU37xz5hdtXg5u0g=; b=UJQZRybZ+U6cKgHatJZf881BWvdCk3KoK6+EVGwGm9KsQo7mIAOItgN/BTxD4kKobM 4URL0Q2XihBDU4+fbItWa/Hy+DiKMgwmDI3OQBrqAHgMWc5TUdyX0oKu+DlfG0gs7K6l UkyS+HSo0uXq/h6BZuCzVb0B32KcVFFwINLbUChTLO1ud1vVEavO4yzvAN6OqQU0y68S tQdM26utJNIahscbZChuOMfjMesdWYa2R0FOeo9pnEk8HkFuk+KuRbhM41uTiSADf3/n UgThQRI5sFN2cDWUU4OFCNFb2sAiTmU6TrM9ECVX8w1gO5p7SYX/f+x+3uLB51WBcFAO H5vA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r20-20020a6560d4000000b004961cb25a14si30970910pgv.499.2023.01.17.23.36.29; Tue, 17 Jan 2023 23:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbjARHTY (ORCPT + 99 others); Wed, 18 Jan 2023 02:19:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230005AbjARHRW (ORCPT ); Wed, 18 Jan 2023 02:17:22 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86A24858C; Tue, 17 Jan 2023 22:41:24 -0800 (PST) Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30I3Lbem001227; Wed, 18 Jan 2023 01:41:05 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3n3q4d75ye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 01:41:05 -0500 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 30I6f3E8002741 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Jan 2023 01:41:03 -0500 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:41:02 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:41:02 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Wed, 18 Jan 2023 01:41:02 -0500 Received: from okan.localdomain ([10.158.40.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 30I6ccUv005042; Wed, 18 Jan 2023 01:40:48 -0500 From: Okan Sahin To: CC: Lee Jones , Rob Herring , "Krzysztof Kozlowski" , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Marcelo Schmitt , William Breathitt Gray , Ramona Bolboaca , "Lad Prabhakar" , Caleb Connolly , ChiYuan Huang , , , Subject: [PATCH v3 4/5] dt-bindings: regulator: Add ADI MAX77541/MAX77540 Regulator Date: Wed, 18 Jan 2023 09:38:11 +0300 Message-ID: <20230118063822.14521-5-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230118063822.14521-1-okan.sahin@analog.com> References: <20230118063822.14521-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: eaWgZfal4ExsWlogxkDHiCbOBtol-H4v X-Proofpoint-GUID: eaWgZfal4ExsWlogxkDHiCbOBtol-H4v X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_01,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 suspectscore=0 bulkscore=0 impostorscore=0 phishscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301180057 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755344957100329536?= X-GMAIL-MSGID: =?utf-8?q?1755344957100329536?= Add ADI MAX77541/MAX77540 Regulator devicetree document. Signed-off-by: Okan Sahin Reviewed-by: Krzysztof Kozlowski --- .../regulator/adi,max77541-regulator.yaml | 44 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml diff --git a/Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml b/Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml new file mode 100644 index 000000000000..fff463d5e79d --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/adi,max77541-regulator.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Buck Converter for MAX77540/MAX77541 + +maintainers: + - Okan Sahin + +description: | + This is a part of device tree bindings for ADI MAX77540/MAX77541 + + The buck converter is represented as a sub-node of the PMIC node on the device tree. + + The device has two buck regulators. + See also Documentation/devicetree/bindings/mfd/adi,max77541.yaml for + additional information and example. + +properties: + compatible: + enum: + - adi,max77540-regulator + - adi,max77541-regulator + +patternProperties: + "^buck[12]$": + type: object + $ref: regulator.yaml# + additionalProperties: false + description: | + Buck regulator. + + properties: + regulator-name: true + regulator-always-on: true + regulator-boot-on: true + regulator-min-microvolt: + minimum: 300000 + regulator-max-microvolt: + maximum: 5200000 + +additionalProperties: false diff --git a/MAINTAINERS b/MAINTAINERS index 5704ed5afce3..fcb846f7250f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12502,6 +12502,7 @@ M: Okan Sahin L: linux-kernel@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/mfd/adi,max77541.yaml +F: Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml F: drivers/mfd/max77541.c F: drivers/regulator/max77541-regulator.c F: include/linux/mfd/max77541.h From patchwork Wed Jan 18 06:38:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sahin, Okan" X-Patchwork-Id: 45053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2195303wrn; Tue, 17 Jan 2023 23:36:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXspKDbnRtIm52wRwLNxxTV3B6VC5/hb0oZmpC8ktQwgls+Oy3KOmIP3OO5MWcWBKKgUOckD X-Received: by 2002:a17:90a:eb03:b0:225:cc25:3947 with SMTP id j3-20020a17090aeb0300b00225cc253947mr5557399pjz.13.1674027410002; Tue, 17 Jan 2023 23:36:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674027409; cv=none; d=google.com; s=arc-20160816; b=cs3u4zPvrqEvPv2el8LASCa7VBQw9wFSvpJGLshcPkJ/D+sCAqMjrUAmJr1ff1eyOq 7xOGQfRoex38LDY2glaLgxrpGnB2VNKpXvq1Dct+NMqzwbwvL4sxgQuaIHzzgroi36zL YdoPoyl2agMnYKwWx40ArhhhO7+2MM3EVyMDHo0XQFgCS/KJML4DxDiArfTjeWep5cEe j4okJjGEmHvfInGJ1Fxi0WUcDUbMSlEhts/zDM4IgIOdBO+gb/1ktsk7qZMS4GA1KRF6 7XKjMTG9pGv4Y9oVxoYhKzTrFJS5PxPbs9aNzw8oTF8R/G3p78EFiRCPvWcC9PxaZofr aP7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=t2mJo0L0Za1DNMweuQZNgu7i5CvqgD0xj/VyOA87Ybg=; b=TBJJOCBNT+m6vcb780KNykPXhS5TZhFWUziY2o9lz+NN4gAnBo01lXGTK41PZeTrXw axVpPIGp9Wzoh70ClvmzjJJL3BBsPB/ZV7M6Hr/HJk/RtnFeuBqgoQlxx1y3nc0C+vVD GRKitCBAea9gjwKEdTcPI2h3oeuHCoXHfmMBToM0pFjds0jMT04eVBNu4MNAnb06eWhC gScNK5Jjsezc4JCUDI93f+J23OoVAHE8p+4EaqtJwyqOx9uSDmb2CzPN2RiPE0AVM7r3 MTi4QmXtRUPBz8JkPhaa+BWSnYfN/MAsmDbLhUnz8zGLQnzRFlgJkbXq6vmGsXSy+ydO 5/Hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020a17090ad90300b00225f3e34336si1282583pjv.89.2023.01.17.23.36.38; Tue, 17 Jan 2023 23:36:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbjARHUX (ORCPT + 99 others); Wed, 18 Jan 2023 02:20:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbjARHTa (ORCPT ); Wed, 18 Jan 2023 02:19:30 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D806A7ED71; Tue, 17 Jan 2023 22:41:58 -0800 (PST) Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30I3LlMY001202; Wed, 18 Jan 2023 01:41:39 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3n3q4d7646-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 01:41:39 -0500 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 30I6fbxc002766 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Jan 2023 01:41:37 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Wed, 18 Jan 2023 01:41:36 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Wed, 18 Jan 2023 01:41:36 -0500 Received: from okan.localdomain ([10.158.40.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 30I6ccUw005042; Wed, 18 Jan 2023 01:41:20 -0500 From: Okan Sahin To: CC: Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Geert Uytterhoeven , ChiYuan Huang , Marcelo Schmitt , Marcus Folkesson , William Breathitt Gray , Ramona Bolboaca , Caleb Connolly , , , Subject: [PATCH v3 5/5] drivers: iio: adc: Add ADI MAX77541 ADC Support Date: Wed, 18 Jan 2023 09:38:12 +0300 Message-ID: <20230118063822.14521-6-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230118063822.14521-1-okan.sahin@analog.com> References: <20230118063822.14521-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: WCKUANNcDOdZdcBwMcKdJU6TXSgghQ3U X-Proofpoint-GUID: WCKUANNcDOdZdcBwMcKdJU6TXSgghQ3U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_01,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 suspectscore=0 bulkscore=0 impostorscore=0 phishscore=0 malwarescore=0 priorityscore=1501 clxscore=1011 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301180057 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755344965898112787?= X-GMAIL-MSGID: =?utf-8?q?1755344965898112787?= The MAX77541 has an 8-bit Successive Approximation Register (SAR) ADC with four multiplexers for supporting the telemetry feature. Signed-off-by: Okan Sahin Reviewed-by: Jonathan Cameron --- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 11 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/max77541-adc.c | 200 +++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 drivers/iio/adc/max77541-adc.c diff --git a/MAINTAINERS b/MAINTAINERS index fcb846f7250f..763f2eec4bb7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12503,6 +12503,7 @@ L: linux-kernel@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/mfd/adi,max77541.yaml F: Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml +F: drivers/iio/adc/max77541-adc.c F: drivers/mfd/max77541.c F: drivers/regulator/max77541-regulator.c F: include/linux/mfd/max77541.h diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 791612ca6012..9716225b50da 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -696,6 +696,17 @@ config MAX1363 To compile this driver as a module, choose M here: the module will be called max1363. +config MAX77541_ADC + tristate "Analog Devices MAX77541 ADC driver" + depends on MFD_MAX77541 + help + This driver controls a Analog Devices MAX77541 ADC + via I2C bus. This device has one adc. Say yes here to build + support for Analog Devices MAX77541 ADC interface. + + To compile this driver as a module, choose M here: + the module will be called max77541-adc. + config MAX9611 tristate "Maxim max9611/max9612 ADC driver" depends on I2C diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 46caba7a010c..03774cccbb4b 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -64,6 +64,7 @@ obj-$(CONFIG_MAX1118) += max1118.o obj-$(CONFIG_MAX11205) += max11205.o obj-$(CONFIG_MAX1241) += max1241.o obj-$(CONFIG_MAX1363) += max1363.o +obj-$(CONFIG_MAX77541_ADC) += max77541-adc.o obj-$(CONFIG_MAX9611) += max9611.o obj-$(CONFIG_MCP320X) += mcp320x.o obj-$(CONFIG_MCP3422) += mcp3422.o diff --git a/drivers/iio/adc/max77541-adc.c b/drivers/iio/adc/max77541-adc.c new file mode 100644 index 000000000000..8c459661940f --- /dev/null +++ b/drivers/iio/adc/max77541-adc.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Analog Devices, Inc. + * ADI MAX77541 ADC Driver with IIO interface + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum max77541_adc_range { + LOW_RANGE, + MID_RANGE, + HIGH_RANGE, +}; + +struct max77541_adc_iio { + struct regmap *regmap; +}; + +enum max77541_adc_channel { + MAX77541_ADC_VSYS_V = 0, + MAX77541_ADC_VOUT1_V, + MAX77541_ADC_VOUT2_V, + MAX77541_ADC_TEMP, +}; + +static int max77541_adc_offset(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2) +{ + switch (chan->channel) { + case MAX77541_ADC_TEMP: + *val = DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS, + 1725); + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int max77541_adc_scale(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2) +{ + struct max77541_adc_iio *info = iio_priv(indio_dev); + unsigned int reg_val; + int ret; + + switch (chan->channel) { + case MAX77541_ADC_VSYS_V: + *val = 25; + return IIO_VAL_INT; + case MAX77541_ADC_VOUT1_V: + case MAX77541_ADC_VOUT2_V: + ret = regmap_read(info->regmap, MAX77541_REG_M2_CFG1, ®_val); + if (ret) + return ret; + reg_val = FIELD_GET(MAX77541_BITS_MX_CFG1_RNG, reg_val); + + switch (reg_val) { + case LOW_RANGE: + *val = 6; + *val2 = 250000; + break; + case MID_RANGE: + *val = 12; + *val2 = 500000; + break; + case HIGH_RANGE: + *val = 25; + return IIO_VAL_INT; + default: + return -EINVAL; + } + + return IIO_VAL_INT_PLUS_MICRO; + case MAX77541_ADC_TEMP: + *val = 1725; + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int max77541_adc_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct max77541_adc_iio *info = iio_priv(indio_dev); + int ret; + + ret = regmap_read(info->regmap, chan->address, val); + if (ret) + return ret; + + return IIO_VAL_INT; +} + +#define MAX77541_ADC_CHANNEL_V(_channel, _name, _type, _reg) \ + { \ + .type = _type, \ + .indexed = 1, \ + .channel = _channel, \ + .address = _reg, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .datasheet_name = _name, \ + } + +#define MAX77541_ADC_CHANNEL_TEMP(_channel, _name, _type, _reg) \ + { \ + .type = _type, \ + .indexed = 1, \ + .channel = _channel, \ + .address = _reg, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) |\ + BIT(IIO_CHAN_INFO_OFFSET),\ + .datasheet_name = _name, \ + } + +static const struct iio_chan_spec max77541_adc_channels[] = { + MAX77541_ADC_CHANNEL_V(MAX77541_ADC_VSYS_V, "vsys_v", IIO_VOLTAGE, + MAX77541_REG_ADC_DATA_CH1), + MAX77541_ADC_CHANNEL_V(MAX77541_ADC_VOUT1_V, "vout1_v", IIO_VOLTAGE, + MAX77541_REG_ADC_DATA_CH2), + MAX77541_ADC_CHANNEL_V(MAX77541_ADC_VOUT2_V, "vout2_v", IIO_VOLTAGE, + MAX77541_REG_ADC_DATA_CH3), + MAX77541_ADC_CHANNEL_TEMP(MAX77541_ADC_TEMP, "temp", IIO_TEMP, + MAX77541_REG_ADC_DATA_CH6), +}; + +static int max77541_adc_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_OFFSET: + return max77541_adc_offset(indio_dev, chan, val, val2); + case IIO_CHAN_INFO_SCALE: + return max77541_adc_scale(indio_dev, chan, val, val2); + case IIO_CHAN_INFO_RAW: + return max77541_adc_raw(indio_dev, chan, val); + default: + return -EINVAL; + } +} + +static const struct iio_info max77541_adc_info = { + .read_raw = max77541_adc_read_raw, +}; + +static int max77541_adc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct max77541_adc_iio *info; + struct iio_dev *indio_dev; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*info)); + if (!indio_dev) + return -ENOMEM; + + info = iio_priv(indio_dev); + + info->regmap = dev_get_regmap(dev->parent, NULL); + indio_dev->modes = INDIO_DIRECT_MODE; + + indio_dev->name = "max77541"; + indio_dev->info = &max77541_adc_info; + indio_dev->channels = max77541_adc_channels; + indio_dev->num_channels = ARRAY_SIZE(max77541_adc_channels); + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct platform_device_id max77541_adc_platform_id[] = { + { "max77541-adc", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, max77541_adc_platform_id); + +static struct platform_driver max77541_adc_driver = { + .driver = { + .name = "max77541-adc", + }, + .probe = max77541_adc_probe, + .id_table = max77541_adc_platform_id, +}; +module_platform_driver(max77541_adc_driver); + +MODULE_AUTHOR("Okan Sahin "); +MODULE_DESCRIPTION("MAX77541 ADC driver"); +MODULE_LICENSE("GPL");