Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33D03EB64DC for ; Fri, 14 Jul 2023 16:16:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EF65586DC4; Fri, 14 Jul 2023 18:16:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YE9baFAq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E77686DCF; Fri, 14 Jul 2023 18:16:47 +0200 (CEST) Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0C60486D91 for ; Fri, 14 Jul 2023 18:16:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=clamor95@gmail.com Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fb4146e8fcso13470275e9.0 for ; Fri, 14 Jul 2023 09:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689351403; x=1691943403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+R6iEDxkfgsqal18EUHk30KwvU+YEOJhMKMPahVWXNA=; b=YE9baFAqKdTtNZTtTAHcHRwbAzpbmJNS5IdFBkiPxCIpdbXbllzpbqRFCsvj73GWT6 WYFtCC7vSv+Z5KPV5+W48Hx2FD10zP47YI01c2xbdAjFD2rNYeIVrz5R9qTJN3IjWieW aBXWOj4WYnVp5Ub93jMkQQbSygBLZ0J42/mCIYjIhpi8IR1Q37+m8LHa7v8ObCf+7OYO DYOUigE1NJ5LcJTerHDr6SWQJ7MMjYU6S7c+Ot89k5+NDiWfQP6T/vey9FyW9YRFD510 EcLPWfMiEwXrYu7y55mdRMwNxIWci1WgplZeSFX5+7FObJ28IwTQfiHm7kX49uFiEA8C YJNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689351403; x=1691943403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+R6iEDxkfgsqal18EUHk30KwvU+YEOJhMKMPahVWXNA=; b=MFQxPNN4aFCZV+wWJLrAtZYYaH7cB4F0FVAxIHW4bxutFAXOyi2W5BQjQC410KVX5K ce98PT1cgpVDTfodk7cX0zwZqBMqhk0E5mjAzFcxmMXPLyvEpkVkTiN4VsiOvlYGOyCy yIT3Jbk8hLTRlsP7oZeo92r3QieBrochbMPeYbyr8EINaY2/Q0YmGJhzL5lLIYyaDC5P RosEGu5ByCkRUoz1qBWKlzwrXo7CcgbMmyuADXKyxo3uIx6Db6yUuI9auKFj646LMMBy wjuMgBRrUbhWZjvRoQLjNkCHZx+rOaaC/hgUysJiMkVkF/s3TKXKMABIRlQzq4xUspUN mTsw== X-Gm-Message-State: ABy/qLaz/EMddWFGhqK72A6oPLaSKqua0p6LKiAGcxJMogEL70BnHtCe BV/1lYumiEs79XD1OJTNCDaBmmDb0Bw= X-Google-Smtp-Source: APBJJlFCpSM4ZipbInmaycHOf9kSmpVYYFftdua+5KGe2V95c7M5dQXURWRsnggGwUHkKymn2RKQ7g== X-Received: by 2002:a05:600c:2983:b0:3f7:a20a:561d with SMTP id r3-20020a05600c298300b003f7a20a561dmr2775486wmd.8.1689351403410; Fri, 14 Jul 2023 09:16:43 -0700 (PDT) Received: from xeon.. ([188.163.112.64]) by smtp.gmail.com with ESMTPSA id y7-20020a5d6147000000b0031412b685d2sm11280134wrt.32.2023.07.14.09.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 09:16:43 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Svyatoslav Ryhel Cc: u-boot@lists.denx.de Subject: [PATCH v1 1/6] power: pmic: add the base max77663 pmic support Date: Fri, 14 Jul 2023 19:16:16 +0300 Message-Id: <20230714161621.76702-2-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230714161621.76702-1-clamor95@gmail.com> References: <20230714161621.76702-1-clamor95@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers. Signed-off-by: Svyatoslav Ryhel --- doc/device-tree-bindings/pmic/max77663.txt | 84 ++++++++++++++++++++++ drivers/power/pmic/Kconfig | 6 ++ drivers/power/pmic/Makefile | 1 + drivers/power/pmic/max77663.c | 81 +++++++++++++++++++++ include/power/max77663.h | 40 +++++++++++ 5 files changed, 212 insertions(+) create mode 100644 doc/device-tree-bindings/pmic/max77663.txt create mode 100644 drivers/power/pmic/max77663.c create mode 100644 include/power/max77663.h diff --git a/doc/device-tree-bindings/pmic/max77663.txt b/doc/device-tree-bindings/pmic/max77663.txt new file mode 100644 index 0000000000..ddb7d3eb14 --- /dev/null +++ b/doc/device-tree-bindings/pmic/max77663.txt @@ -0,0 +1,84 @@ +MAXIM, MAX77663 PMIC + +This device uses two drivers: +- drivers/power/pmic/max77663.c (for parent device) +- drivers/power/regulator/max77663_regulator.c (for child regulators) + +This chapter describes the binding info for the PMIC driver and regulators. + +Required properties for PMIC: +- compatible: "maxim,max77663" +- reg: usually 0x1c or 0x3c + +With those two properties, the pmic device can be used for read/write only. +To bind each regulator, the optional regulators subnode should exists. + +Optional subnode: +- name: regulators (subnode list of each device's regulator) + +Regulators subnode contains set on supported regulators. + +Required properties: +- regulator-name: used for regulator uclass platform data '.name', + +List of supported regulator nodes names for max77663: +- sd0, sd1, sd2, sd3, ldo0, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8 + +Optional: +- regulator-min-microvolt: minimum allowed Voltage to set +- regulator-max-microvolt: minimum allowed Voltage to set +- regulator-always-on: regulator should be never disabled +- regulator-boot-on: regulator should be enabled by the bootloader + +Linux driver binding for this driver is compatible. + +Example: + +max77663@1c { + compatible = "maxim,max77663"; + reg = <0x1c>; + + regulators { + sd0 { + regulator-name = "vdd_cpu"; + regulator-min-microvolt = <800000>; + regulator-max-microvolt = <1250000>; + regulator-always-on; + regulator-boot-on; + }; + + ... + + ldo0 { + regulator-name = "avdd_pll"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + }; + + ... + + ldo2 { + regulator-name = "avdd_usb"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-always-on; + regulator-boot-on; + }; + + ldo3 { + regulator-name = "vdd_sdmmc3"; + regulator-min-microvolt = <3000000>; + regulator-max-microvolt = <3000000>; + regulator-always-on; + regulator-boot-on; + }; + + ... + + ldo8 { + regulator-name = "avdd_dsi_csi"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + }; + }; +}; diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig index 176fb07c65..abea0fe4ed 100644 --- a/drivers/power/pmic/Kconfig +++ b/drivers/power/pmic/Kconfig @@ -184,6 +184,12 @@ config SPL_DM_PMIC_PFUZE100 This config enables implementation of driver-model pmic uclass features for PMIC PFUZE100 in SPL. The driver implements read/write operations. +config DM_PMIC_MAX77663 + bool "Enable Driver Model for PMIC MAX77663" + ---help--- + This config enables implementation of driver-model pmic uclass features + for PMIC MAX77663. The driver implements read/write operations. + config DM_PMIC_MAX77686 bool "Enable Driver Model for PMIC MAX77686" ---help--- diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile index 0b3b3d62d0..414a9d8225 100644 --- a/drivers/power/pmic/Makefile +++ b/drivers/power/pmic/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_$(SPL_TPL_)DM_PMIC) += pmic-uclass.o obj-$(CONFIG_$(SPL_)DM_PMIC_FAN53555) += fan53555.o obj-$(CONFIG_$(SPL_)DM_PMIC_DA9063) += da9063.o +obj-$(CONFIG_$(SPL_)DM_PMIC_MAX77663) += max77663.o obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o diff --git a/drivers/power/pmic/max77663.c b/drivers/power/pmic/max77663.c new file mode 100644 index 0000000000..fa70d2d936 --- /dev/null +++ b/drivers/power/pmic/max77663.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright(C) 2023 Svyatoslav Ryhel + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct pmic_child_info pmic_children_info[] = { + { .prefix = "ldo", .driver = MAX77663_LDO_DRIVER }, + { .prefix = "sd", .driver = MAX77663_SD_DRIVER }, + { }, +}; + +static int max77663_write(struct udevice *dev, uint reg, const uint8_t *buff, + int len) +{ + if (dm_i2c_write(dev, reg, buff, len)) { + log_err("write error to device: %p register: %#x!\n", dev, reg); + return -EIO; + } + + return 0; +} + +static int max77663_read(struct udevice *dev, uint reg, uint8_t *buff, int len) +{ + if (dm_i2c_read(dev, reg, buff, len)) { + log_err("read error from device: %p register: %#x!\n", dev, reg); + return -EIO; + } + + return 0; +} + +static int max77663_bind(struct udevice *dev) +{ + ofnode regulators_node; + int children; + + regulators_node = dev_read_subnode(dev, "regulators"); + if (!ofnode_valid(regulators_node)) { + log_err("%s regulators subnode not found!\n", dev->name); + return -ENXIO; + } + + debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); + + children = pmic_bind_children(dev, regulators_node, pmic_children_info); + if (!children) + log_err("%s - no child found\n", dev->name); + + /* Always return success for this device */ + return 0; +} + +static struct dm_pmic_ops max77663_ops = { + .read = max77663_read, + .write = max77663_write, +}; + +static const struct udevice_id max77663_ids[] = { + { .compatible = "maxim,max77663" }, + { } +}; + +U_BOOT_DRIVER(pmic_max77663) = { + .name = "max77663_pmic", + .id = UCLASS_PMIC, + .of_match = max77663_ids, + .bind = max77663_bind, + .ops = &max77663_ops, +}; diff --git a/include/power/max77663.h b/include/power/max77663.h new file mode 100644 index 0000000000..53a0976346 --- /dev/null +++ b/include/power/max77663.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright(C) 2023 Svyatoslav Ryhel + */ + +#ifndef _MAX77663_H_ +#define _MAX77663_H_ + +#define MAX77663_LDO_NUM 9 +#define MAX77663_SD_NUM 5 + +/* Drivers name */ +#define MAX77663_LDO_DRIVER "max77663_ldo" +#define MAX77663_SD_DRIVER "max77663_sd" + +#define MAX77663_SD_STATUS_MASK 0x30 + +#define MAX77663_SD0_VOLT_MAX_HEX 0x40 +#define MAX77663_SD1_VOLT_MAX_HEX 0X4C +#define MAX77663_SD_VOLT_MAX_HEX 0XFF +#define MAX77663_SD_VOLT_MIN_HEX 0x02 + +#define MAX77663_SD0_VOLT_MAX 1400000 +#define MAX77663_SD1_VOLT_MAX 1550000 +#define MAX77663_SD_VOLT_MAX 3787500 +#define MAX77663_SD_VOLT_MIN 625000 + +#define MAX77663_SD_VOLT_BASE 600000 + +#define MAX77663_LDO_STATUS_MASK 0xC0 +#define MAX77663_LDO_VOLT_MASK 0x3F +#define MAX77663_LDO_VOLT_MAX_HEX 0x3F + +#define MAX77663_LDO01_VOLT_MAX 2375000 +#define MAX77663_LDO4_VOLT_MAX 1587500 +#define MAX77663_LDO_VOLT_MAX 3950000 + +#define MAX77663_LDO_VOLT_BASE 800000 + +#endif /* _MAX77663_H_ */ -- 2.39.2