From patchwork Tue Feb 21 10:39: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: 59856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1793558wrn; Tue, 21 Feb 2023 02:48:16 -0800 (PST) X-Google-Smtp-Source: AK7set8sKf3pnerZxwJIdeFDmeiwe2HczKDL9RKQIvn3To2awdgRwg+ihOr6PL7kt17cPlsgGkGA X-Received: by 2002:a17:90b:350f:b0:234:e5c2:b92c with SMTP id ls15-20020a17090b350f00b00234e5c2b92cmr5495471pjb.15.1676976496382; Tue, 21 Feb 2023 02:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676976496; cv=none; d=google.com; s=arc-20160816; b=hCGFWcDvz4vY2dhH+go6XmtKDoBj0N8EGwAllDZ/NIVbzxCWzBwdTaKf6LJaW3YZy2 xdrOjMvT7rx98lII3rZ6ELYumWNnwOgNivW6eJgxyFHiwm2+ZT52klgjlpgT1bIoFPPJ tFVabZ/yhrQHSqFermRjMtrl42i5ZlInER+woG1q8SQF9/bktUZ8UdNv49vAce+e7gZD AlJFp3DqVYy3JqjSV2urydFxyfekhzD64oDJaED44OR23BbSmZ1iD1N2KqTjIB3WHyUr LO3HYdtSfK6FjHn0oUBw1rBDXpn5hFO3arxgV1P+fO9HIHQRDXJxGCR+Cyw43Csvu89g 0izQ== 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=3TobP+HocTFQc8BfSIcYH0fwMsXXDm5lh0uKkYv4GSc=; b=LOJljVwcgo4C3pS9EAKW7ivtkX/4bzSYzmGao3jSDNO63KnoW8Qv7qeJ6xGWQ4RbsX NdrjUKmzudO3WXEAItzB6/j6zUiawHJu0lt2NqjkpQpiaHj1LObHhM6ulEdjITTgdtf0 lEcD2t5do8DHFLybOX4bhgZAyHwAc4kReK0Z02dDDL9GWDLNbheJ/F8evQzZsdbyc+HZ SFHN5vWaPUOlW6sOCfIKfCKbB7meg1bVf1TEU2rA3MB7cdjwHScLVTQCA38RCH27viMI sTLS+Bhyqi93jqtf1fm1QtOiv20tIUOqOaLIc3lf/yctFLQG/XxgKdMxl30KufSV624H PpGw== 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 l185-20020a6391c2000000b004fb9504a5e7si7315896pge.730.2023.02.21.02.48.03; Tue, 21 Feb 2023 02:48:16 -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 S233605AbjBUKk5 (ORCPT + 99 others); Tue, 21 Feb 2023 05:40:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232986AbjBUKkz (ORCPT ); Tue, 21 Feb 2023 05:40:55 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF3581F5F6; Tue, 21 Feb 2023 02:40:51 -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 31L8piuN024973; Tue, 21 Feb 2023 05:40:32 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3nvdwdck8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Feb 2023 05:40:32 -0500 Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 31LAeVWm064406 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 21 Feb 2023 05:40:31 -0500 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) 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; Tue, 21 Feb 2023 05:40:30 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Tue, 21 Feb 2023 05:40:30 -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; Tue, 21 Feb 2023 05:40:29 -0500 Received: from okan.localdomain (IST-LT-43126.ad.analog.com [10.25.36.24]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 31LAdbGv012847; Tue, 21 Feb 2023 05:40:20 -0500 From: Okan Sahin To: CC: Krzysztof Kozlowski , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Ramona Bolboaca , Lad Prabhakar , Marcus Folkesson , ChiYuan Huang , "William Breathitt Gray" , Caleb Connolly , , , Subject: [PATCH v5 1/5] dt-bindings: regulator: max77541: Add ADI MAX77541/MAX77540 Regulator Date: Tue, 21 Feb 2023 13:39:09 +0300 Message-ID: <20230221103926.49597-2-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230221103926.49597-1-okan.sahin@analog.com> References: <20230221103926.49597-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: k9b88PzTyaLPlfoFh-JGe7eBcF8ubjRi X-Proofpoint-ORIG-GUID: k9b88PzTyaLPlfoFh-JGe7eBcF8ubjRi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_06,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210092 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?1758437306677382067?= X-GMAIL-MSGID: =?utf-8?q?1758437306677382067?= Add ADI MAX77541/MAX77540 Regulator devicetree document. Signed-off-by: Okan Sahin Reviewed-by: Krzysztof Kozlowski --- .../regulator/adi,max77541-regulator.yaml | 38 +++++++++++++++++++ 1 file changed, 38 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..9e36d5467b56 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/adi,max77541-regulator.yaml @@ -0,0 +1,38 @@ +# 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. + +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 From patchwork Tue Feb 21 10:39: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: 59857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1794740wrn; Tue, 21 Feb 2023 02:51:09 -0800 (PST) X-Google-Smtp-Source: AK7set/yx9aiC40w0xJQIWOpNSRhvkeJd0wtvYm0b6A5tJkVNNrX05r6ODxqWDxCnYEBhff2nmGZ X-Received: by 2002:a05:6402:25c2:b0:49e:4786:a0e2 with SMTP id x2-20020a05640225c200b0049e4786a0e2mr3499856edb.14.1676976669554; Tue, 21 Feb 2023 02:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676976669; cv=none; d=google.com; s=arc-20160816; b=wweYAvjjfN7+fwVkjsI0xnExZ1Vp1Hdg1owppgvscepU0tfdLfhy6CC8crcMM2/7hm dsr2mIZiauoXDzPb3PjLoGruCur8z8LRyz6gcdgDPF7Vu+8qlzDs9SFacMNiAjw66H3N EjoU+740wuk1IDvIWZ4C0x8jVAzsxGv522Jusv4SlD3xPhVT11He8dLN7Huqn7E3zqKB ivp95BmS9dWWRHzAZ2FwVO8iT5he85ZXlM0By4b7UwKKf1nXzPAUhk1x8jFKgMHLc1uU vLTEa6MYUYSu9nuIoI6+B0ehNYTU8Ys2PzoAQI9mVRuIYB3MsTRAzSN9+vdOf8HYmPQg 0dCw== 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=nzUGJvtVLy/o1skyhXv9m+Hfhfg++2M6MUo8atnFIVg=; b=F7XSHWKUINfHA5HI0TVdwfWKykBpgzayW9oEHjezgS+7VuZ3PcoEiE2xC0Hj0rNybd cqPewvFHvINOVdaoOPO6WYgmf16TLrSAYWlKFHFdYV5xkNXUyDm6dOhQ+x7rfuCMDvCz IHbGfC6KVNfE6R9WSQsuV0R/Ociq1cN5X6BzvQXmqmCA1w7AIroOz21efFGZV/NIea48 2+p0SMiKIFbpdfNBmZR8pTadtoBmjpQFtF4Sy2L0x/ZjmuhXFsWXFb1n2ZzxoowduNsb iKcDTYSg9fGqeLQNaXh4BajFEHOTTTVkBbcvA1g2ibFcCUbALEnMspFjbazYbJZ+nEfz KMeQ== 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 d11-20020aa7ce0b000000b004ab9fed6acesi19046660edv.384.2023.02.21.02.50.46; Tue, 21 Feb 2023 02:51:09 -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 S233711AbjBUKlb (ORCPT + 99 others); Tue, 21 Feb 2023 05:41:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbjBUKl2 (ORCPT ); Tue, 21 Feb 2023 05:41:28 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00A725E1A; Tue, 21 Feb 2023 02:41:25 -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 31L8piuV024973; Tue, 21 Feb 2023 05:41:02 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3nvdwdckar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Feb 2023 05:41:01 -0500 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 31LAf02F023076 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 21 Feb 2023 05:41:00 -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; Tue, 21 Feb 2023 05:40:59 -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; Tue, 21 Feb 2023 05:40:59 -0500 Received: from okan.localdomain (IST-LT-43126.ad.analog.com [10.25.36.24]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 31LAdbGw012847; Tue, 21 Feb 2023 05:40:47 -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 , ChiYuan Huang , Lad Prabhakar , Marcus Folkesson , William Breathitt Gray , Ramona Bolboaca , Caleb Connolly , , , Subject: [PATCH v5 2/5] regulator: max77541: Add ADI MAX77541/MAX77540 Regulator Support Date: Tue, 21 Feb 2023 13:39:10 +0300 Message-ID: <20230221103926.49597-3-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230221103926.49597-1-okan.sahin@analog.com> References: <20230221103926.49597-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: oOcyJlqxsz2f26NDmZ7yqeBDfbermXnC X-Proofpoint-ORIG-GUID: oOcyJlqxsz2f26NDmZ7yqeBDfbermXnC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_06,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210092 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?1758437488402260130?= X-GMAIL-MSGID: =?utf-8?q?1758437488402260130?= 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 --- drivers/regulator/Kconfig | 9 ++ drivers/regulator/Makefile | 1 + drivers/regulator/max77541-regulator.c | 154 +++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 drivers/regulator/max77541-regulator.c 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..75063e8de09d --- /dev/null +++ b/drivers/regulator/max77541-regulator.c @@ -0,0 +1,154 @@ +// 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 + +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, +}; + +enum max77541_regulators { + MAX77541_BUCK1 = 1, + MAX77541_BUCK2, +}; + +#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 regulator_config config = {}; + const struct regulator_desc *desc; + struct device *dev = &pdev->dev; + struct regulator_dev *rdev; + struct max77541 *max77541; + int i; + + max77541 = dev_get_drvdata(dev->parent); + config.dev = dev->parent; + + switch (max77541->chip->id) { + case MAX77540: + desc = max77540_regulators_desc; + break; + case MAX77541: + desc = max77541_regulators_desc; + break; + default: + 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" }, + { "max77541-regulator" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, max77541_regulator_platform_id); + +static struct platform_driver max77541_regulator_driver = { + .driver = { + .name = "max77541-regulator", + }, + .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 Tue Feb 21 10:39: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: 59858 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1794756wrn; Tue, 21 Feb 2023 02:51:11 -0800 (PST) X-Google-Smtp-Source: AK7set8IiIm5nPX1jM634YMtKx7EMUtryUT8K7A+8sVC5ieZ11wD7vLfQKO9xtcgTAd0r7hsNkkC X-Received: by 2002:a17:906:ce38:b0:8b2:8876:6a3c with SMTP id sd24-20020a170906ce3800b008b288766a3cmr14260018ejb.29.1676976671801; Tue, 21 Feb 2023 02:51:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676976671; cv=none; d=google.com; s=arc-20160816; b=d045LjKTVeuD5FNqX8nkwcKtMx5v9cxB63UWJPmVgYvrGLpWLM4yqiGS/xntfKVcc6 kprjVqQ9EmptDMlonYxK2Zrwqsc2qvdfNr5vCrlB8byRKFhvmuGN7NpigXRzZ01KSGa4 Oe15QUWG54EMIpktI+9pH1/oixZNI3me4HiUrd8TYMZMmavyyAmj/xtcgbQXOjomy6WR O+P/fWLYT2WTJ+ZcearBrP7imuH7XH4R8WK8YzmTuIsyWDa27U7Wo0cH3cAR372WSs4Q Xwmw9QO2zM23FzvFUheTOWa0m4MxYRd7nzSADmX0zKLHOeMLJVxyLJ6ZnZ9iShVE8HkR rz1A== 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=/IkweVphPCxmYQEjfvNJrMobTnxv/18tTJ/OjGwSVMw=; b=rZim0KlJa9GEKvHOepwS4v+nXK0S1HZ+UAZjiS1snzqlTKQ8JcgGW2uOfaooNUtHcN 5zMNjmx4h8pbrOzP6c3a8UDyksbEMn+lF4GL6IywJNoemCYr+adA3oeIq6YSoG2V+f+e 2O4cqtTrKoMorZLFcy6ne6D5+edWbqQT/KIzzeWr53U1bVygNwWfjib7qqMQAp8rkjKJ mL8v2FgjTmM/tej6Gy/Kh1jHatMKufIVqeE86a5In+YOt/TtfX5LHITQPl1tud9+g6wj xwAceCFgj9Qn/tnDZ1a2aMNbVw7AYGKtVZeG0/7/XldIRorXIwD5Vc8ToSlgfz8ZFzaj 8xKg== 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 k1-20020a056402048100b004ad6fc891ddsi15952061edv.505.2023.02.21.02.50.49; Tue, 21 Feb 2023 02:51:11 -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 S233739AbjBUKmJ (ORCPT + 99 others); Tue, 21 Feb 2023 05:42:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbjBUKmF (ORCPT ); Tue, 21 Feb 2023 05:42:05 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642DB23C51; Tue, 21 Feb 2023 02:41:51 -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 31L8fZrx018026; Tue, 21 Feb 2023 05:41:30 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3nvdcm4mvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Feb 2023 05:41:29 -0500 Received: from m0167088.ppops.net (m0167088.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31LAd0Cc028350; Tue, 21 Feb 2023 05:41:29 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3nvdcm4mv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Feb 2023 05:41:29 -0500 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 31LAfRia023096 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 21 Feb 2023 05:41:27 -0500 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) 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; Tue, 21 Feb 2023 05:41:27 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Tue, 21 Feb 2023 05:41:26 -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; Tue, 21 Feb 2023 05:41:26 -0500 Received: from okan.localdomain (IST-LT-43126.ad.analog.com [10.25.36.24]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 31LAdbGx012847; Tue, 21 Feb 2023 05:41:14 -0500 From: Okan Sahin To: CC: Jonathan Cameron , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Caleb Connolly , William Breathitt Gray , Geert Uytterhoeven , ChiYuan Huang , Lad Prabhakar , Ramona Bolboaca , , , Subject: [PATCH v5 3/5] iio: adc: max77541: Add ADI MAX77541 ADC Support Date: Tue, 21 Feb 2023 13:39:11 +0300 Message-ID: <20230221103926.49597-4-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230221103926.49597-1-okan.sahin@analog.com> References: <20230221103926.49597-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: 66YZjPVRV2ob86y0Soi81mhF-j_BFprZ X-Proofpoint-ORIG-GUID: MRk0J4PSP1w_3uTxfXAhZpFC8Yi-Jq4G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_06,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 phishscore=0 impostorscore=0 mlxscore=0 malwarescore=0 clxscore=1011 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210092 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?1758437490608156591?= X-GMAIL-MSGID: =?utf-8?q?1758437490608156591?= 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 --- drivers/iio/adc/Kconfig | 11 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/max77541-adc.c | 195 +++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 drivers/iio/adc/max77541-adc.c 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..d7805793f5e3 --- /dev/null +++ b/drivers/iio/adc/max77541-adc.c @@ -0,0 +1,195 @@ +// 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 + +enum max77541_adc_range { + LOW_RANGE, + MID_RANGE, + HIGH_RANGE, +}; + +enum max77541_adc_channel { + MAX77541_ADC_VSYS_V, + 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 regmap **regmap = 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(*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 regmap **regmap = iio_priv(indio_dev); + int ret; + + ret = regmap_read(*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 iio_dev *indio_dev; + struct regmap **regmap; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*regmap)); + if (!indio_dev) + return -ENOMEM; + + regmap = iio_priv(indio_dev); + + *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"); From patchwork Tue Feb 21 10:39: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: 59859 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1794783wrn; Tue, 21 Feb 2023 02:51:18 -0800 (PST) X-Google-Smtp-Source: AK7set+p1T0IAGzHHqKbgN4aAbTfwu8Wp5AHqnBYTtOgFNelNMzavqvzWJNjafZw566ewFGX01+X X-Received: by 2002:a17:906:6c99:b0:8b1:2998:6474 with SMTP id s25-20020a1709066c9900b008b129986474mr11597892ejr.16.1676976678362; Tue, 21 Feb 2023 02:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676976678; cv=none; d=google.com; s=arc-20160816; b=fCj5hktyKFO7dmTRUUy34ijpwLuYRJoI/utDYO+WDHwK/QSJY4S7UZMjrLUbeoMcwu 07K+ataF5R5G/53j5ieL4hTgTK9p2U+rhJ3Qi69ihNY4HioOZgoJad4fE0tRSuTjDB2U M3i+dgaG8P/PLR275pYR0WzTYkuZijcW4H2gGuoifmhU8y+dUjQLX8VunQ5ST5wLRkXm AbmItRCQDr2YDidstJ23XDEhS6kx0cgo7rx3edFlP6RGZXAwu4oHnhYIxT518LZ63how f0IXRSff7fQUi2qiJsJl6MLvLs2Hj2REm1OicMRnOhjyQm12jzia7wb2Cj/6Tix5VKpP ewqg== 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=ZAoNXR72+dWXSQmmymiLw6vdBzlS+7Xai2DPKuAmf4A=; b=e1G+0aQg3tvuxT2Tf89yngM2mqfXBqt6BdnZSp4swmBYZzd6TUhnClwSbOMfpWdrTA uTmCiIXJnueyzn0lE7pvCmKHTmKZ/uaTU5hQeYfQtx8YkCfcxeSadDo6wrgNpbiOFyNh OQyCC8qPzcaWKol5DLUS88iMuPh1F0BKvAPf7TGaitfgSD+ABqnwTyrAqgdU6VbXOI30 HSKPHxnosc8KxwPVJ6YAfhJf97G4SOPymsdlK61aTghLdrglaGIAKJquxm8emA2JfpFd EHpB+h/zVSqH5jOPHyCehn82FOuWIJIEJfD4z2FuSanA8mUd6Dx+oBqNsAtSc6UdL9Ws HDOw== 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 f3-20020a170906738300b008dad3ab54fcsi4045665ejl.400.2023.02.21.02.50.54; Tue, 21 Feb 2023 02:51:18 -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 S229732AbjBUKm0 (ORCPT + 99 others); Tue, 21 Feb 2023 05:42:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233411AbjBUKmY (ORCPT ); Tue, 21 Feb 2023 05:42:24 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC1CE26865; Tue, 21 Feb 2023 02:42:13 -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 31L9nH6Y021401; Tue, 21 Feb 2023 05:41:57 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3nvdcm4my5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Feb 2023 05:41:57 -0500 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 31LAftfd023114 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 21 Feb 2023 05:41:55 -0500 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) 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; Tue, 21 Feb 2023 05:41:54 -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; Tue, 21 Feb 2023 05:41:54 -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; Tue, 21 Feb 2023 05:41:52 -0500 Received: from okan.localdomain (IST-LT-43126.ad.analog.com [10.25.36.24]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 31LAdbH0012847; Tue, 21 Feb 2023 05:41:40 -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 , ChiYuan Huang , "William Breathitt Gray" , Ramona Bolboaca , , , Subject: [PATCH v5 4/5] dt-bindings: mfd: max77541: Add ADI MAX77541/MAX77540 Date: Tue, 21 Feb 2023 13:39:12 +0300 Message-ID: <20230221103926.49597-5-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230221103926.49597-1-okan.sahin@analog.com> References: <20230221103926.49597-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: sUQWx9sZgN_Ao4RGFWQ51hXFJJJvHeVz X-Proofpoint-ORIG-GUID: sUQWx9sZgN_Ao4RGFWQ51hXFJJJvHeVz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_06,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=947 spamscore=0 phishscore=0 impostorscore=0 mlxscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210092 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?1758437497118962080?= X-GMAIL-MSGID: =?utf-8?q?1758437497118962080?= Add ADI MAX77541/MAX77540 devicetree document. Signed-off-by: Okan Sahin Reviewed-by: Krzysztof Kozlowski --- .../devicetree/bindings/mfd/adi,max77541.yaml | 68 +++++++++++++++++++ 1 file changed, 68 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..c7895b2c38c9 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/adi,max77541.yaml @@ -0,0 +1,68 @@ +# 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 + +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; + }; + }; + }; + }; From patchwork Tue Feb 21 10:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sahin, Okan" X-Patchwork-Id: 59860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1795022wrn; Tue, 21 Feb 2023 02:52:02 -0800 (PST) X-Google-Smtp-Source: AK7set+8NljnBqNslYjd5hwRTIqkv9vvbZty+XJHwMgvqlDEEH8TokzZu6fJOnZIf66Pw1bx0NV1 X-Received: by 2002:a17:907:9627:b0:8d7:c649:635d with SMTP id gb39-20020a170907962700b008d7c649635dmr5241395ejc.37.1676976722798; Tue, 21 Feb 2023 02:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676976722; cv=none; d=google.com; s=arc-20160816; b=G9PBquOqtGLMpJtUqf1mlwxnrmbS8Kb+wTkj3Bt44fmwaDy2pX/KnFblwWBki0g+/k I+H79KEe4rDCmedn5JF0OfaaufxHlioXJj+9NzlJRtfgD1y588oWZFFO6n41+E/YwdU7 k6xxWvctiy1RJgISzyQmLcLfijIK8zPHN2x3RP11iKknXa0773y32K+MlA1ueUlOUtOj Fs8r4PmWq2JzPPylsVS1RRUSEnosOkLPJWKbFxmOUTsWP9SvS1ePv6cNZaeTWt4i5LyM KWPEnlbctvnPNbkEY7aEBT6MddboAWQ1/2IPiPf1FslTmQuhQDMo34JJF8K6YTo2M+En ZhcQ== 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=e1vCRZXbZIrkZxk71kCrLfnTZeg+HZOZS70+qMN0xo8=; b=OksAnuZF3EIwegOdCvnhO/XF9xL6qSlk8hUKQO6y2yR7j1TSF1YdhZHmp/sSmb3uuF dtncdpexUYH5PVAFh3/UYzq9+W8B47gCUTFDX8b9UW3L0SfU8UgGuwCytpeIgALP0eBN syQDVGFhl0FONvFBeoC+bzEuI9K39d1kL94ox+OAvqD4RWL6NHhWpDapymzgPz1QOILS DlVoDK25d92xPuT/1bbW1Dxfb+5bWVQjDVhcAgCuvZ4tqwZsB7c+1lUMGHRS0OBtP4FT LMbQ+dHZEwQlqFY5FbeMllqiY4AoreLACp6aB5Pu09medd+AnB5EieB/E7rbKg57TiZ0 6q1w== 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 m3-20020a50ef03000000b004acb6009aa3si19161949eds.617.2023.02.21.02.51.39; Tue, 21 Feb 2023 02:52:02 -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 S233817AbjBUKnL (ORCPT + 99 others); Tue, 21 Feb 2023 05:43:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233512AbjBUKnI (ORCPT ); Tue, 21 Feb 2023 05:43:08 -0500 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F099265A4; Tue, 21 Feb 2023 02:42:47 -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 31L8es1W002476; Tue, 21 Feb 2023 05:42:16 -0500 Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3nvdcm4n0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Feb 2023 05:42:15 -0500 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 31LAgEqV023126 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 21 Feb 2023 05:42:14 -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; Tue, 21 Feb 2023 05:42:13 -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; Tue, 21 Feb 2023 05:42:13 -0500 Received: from okan.localdomain (IST-LT-43126.ad.analog.com [10.25.36.24]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 31LAdbH1012847; Tue, 21 Feb 2023 05:42:02 -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 , Lad Prabhakar , William Breathitt Gray , Ramona Bolboaca , Caleb Connolly , , , Subject: [PATCH v5 5/5] mfd: max77541: Add ADI MAX77541/MAX77540 PMIC Support Date: Tue, 21 Feb 2023 13:39:13 +0300 Message-ID: <20230221103926.49597-6-okan.sahin@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230221103926.49597-1-okan.sahin@analog.com> References: <20230221103926.49597-1-okan.sahin@analog.com> MIME-Version: 1.0 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: K6MFZeP7kQHk3rgkBrKfeE2X65YA_KW8 X-Proofpoint-ORIG-GUID: K6MFZeP7kQHk3rgkBrKfeE2X65YA_KW8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_06,2023-02-20_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 phishscore=0 impostorscore=0 mlxscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302210092 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?1758437543817967378?= X-GMAIL-MSGID: =?utf-8?q?1758437543817967378?= 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 --- drivers/mfd/Kconfig | 13 ++ drivers/mfd/Makefile | 1 + drivers/mfd/max77541.c | 243 +++++++++++++++++++++++++++++++++++ include/linux/mfd/max77541.h | 102 +++++++++++++++ 4 files changed, 359 insertions(+) create mode 100644 drivers/mfd/max77541.c create mode 100644 include/linux/mfd/max77541.h 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..1452a51aa32c --- /dev/null +++ b/drivers/mfd/max77541.c @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Analog Devices, Inc. + * Driver for the MAX77540 and MAX77541 + */ + +#include +#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, + NULL), +}; + +static const struct mfd_cell max77541_devs[] = { + MFD_CELL_OF("max77541-regulator", NULL, NULL, 0, 0, + NULL), + MFD_CELL_OF("max77541-adc", NULL, NULL, 0, 0, + NULL), +}; + +static const struct chip_info chip[] = { + [MAX77540] = { + .id = MAX77540, + .n_devs = ARRAY_SIZE(max77540_devs), + .devs = max77540_devs, + }, + [MAX77541] = { + .id = 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->chip->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"); + + return devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, + max77541->chip->devs, + max77541->chip->n_devs, + NULL, 0, NULL); +} + +static const struct i2c_device_id max77541_i2c_id[]; + +static int max77541_i2c_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct max77541 *max77541; + + max77541 = devm_kzalloc(dev, sizeof(*max77541), GFP_KERNEL); + if (!max77541) + return -ENOMEM; + + i2c_set_clientdata(client, max77541); + max77541->i2c = client; + + if (dev->of_node) + max77541->chip = of_device_get_match_data(dev); + else + max77541->chip = (struct chip_info *) + i2c_match_id(max77541_i2c_id, + client)->driver_data; + if (!max77541->chip) + return -EINVAL; + + 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 = &chip[MAX77540], + }, + { + .compatible = "adi,max77541", + .data = &chip[MAX77541], + }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, max77541_of_id); + +static const struct i2c_device_id max77541_i2c_id[] = { + { "max77540", (kernel_ulong_t)&chip[MAX77540] }, + { "max77541", (kernel_ulong_t)&chip[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_new = 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"); diff --git a/include/linux/mfd/max77541.h b/include/linux/mfd/max77541.h new file mode 100644 index 000000000000..e1ed0aed823d --- /dev/null +++ b/include/linux/mfd/max77541.h @@ -0,0 +1,102 @@ +/* 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, + MAX77541, +}; + +struct chip_info { + enum max7754x_ids id; + int n_devs; + const struct mfd_cell *devs; +}; + +struct regmap; +struct regmap_irq_chip_data; +struct i2c_client; + +struct max77541 { + 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__ */