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 93C69EB64DA for ; Thu, 20 Jul 2023 08:49:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 743CF867DD; Thu, 20 Jul 2023 10:48:56 +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="GBgeRq+y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3724C867C0; Thu, 20 Jul 2023 10:48:38 +0200 (CEST) Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) (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 20CAE85746 for ; Thu, 20 Jul 2023 10:48:32 +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-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4fdd31bf179so814851e87.2 for ; Thu, 20 Jul 2023 01:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689842911; x=1690447711; 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=bgoAxYakE1EhoZnLV5DkYg40lzI/OfyPDiMeXEOTy1g=; b=GBgeRq+y6b6J8J2ECjnftNPOwqiLiUMuGRLYAdC3vlF9NaAnFq3cDpb/JoXCRZZ8X/ dLXjzkRouBCOmIV19MUWCuFgwoq29TOxGZc1kZ81XkAXv0FHi/npBkz/HnFbxfWx486E 8qopAdB6rx76/3tkEV6Il3Zb0eKvVc9nj6pnPZoRO1TxJt/c4UMqBPvwTXIXNPk2NRiE vIcgX/8BLKw0J2yx2SrASh+ewtialfPUgimCnCa/SP7GCD2FmIiS5oUF81S+OkshbqbN dXAHydAASBBtn2waC9WoJLkTS3U6LLpLt3are5Oxwdf9bjZyB2ws9QYHYW8hiT/D7/Fa hQuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689842911; x=1690447711; 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=bgoAxYakE1EhoZnLV5DkYg40lzI/OfyPDiMeXEOTy1g=; b=GAsxDAR8C2kT6vCCjdNJflyaGCATaj8BdpNo0xuxKuYrOAKk5nr+JY6KZAaKIHBdNJ 2EaGjGGm30ivM+Jo5Qcz2dRrCU4eE0lz8AUwcgeyfGiSBg0U6JAg47opY9F8ybZB56OE HnQaGRu3JUjN/C9gSUkBQ7y83c5fA8fGUCwFXyRE46xXSHcefKlkZQSN1sIo3orpjS2V LPpl2gev4HabzITY5JK4vmfFuVP42GnaAwcOXAoy6H2OvUk9ULrlXUSmIx0JEccyiika GUAapfZn+c3vUtOWbKVu7+D4cutt7qMlTgJJzp0SsmY1COuBBLSl2RhfRmo7d9P03+5d /fRQ== X-Gm-Message-State: ABy/qLYzASKnzkCczTn6ubLoyMNlnmBMmVHQ93kaFVpz9GQPIAzaxOaJ Uqq+Wn9cQoMUuo3tUs0flHg= X-Google-Smtp-Source: APBJJlHSeibnSIHZe3Brd71OPW96xb+Ty5WWVSF7UWp/Rv0FA2Q/1ElXs+7rKCd7N6NdPxYJfGHgTw== X-Received: by 2002:a19:4f5d:0:b0:4f9:51ac:41eb with SMTP id a29-20020a194f5d000000b004f951ac41ebmr1518762lfk.16.1689842911229; Thu, 20 Jul 2023 01:48:31 -0700 (PDT) Received: from xeon.. ([188.163.112.64]) by smtp.gmail.com with ESMTPSA id x5-20020a19f605000000b004f21f196701sm94287lfe.203.2023.07.20.01.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 01:48:30 -0700 (PDT) From: Svyatoslav Ryhel To: Jaehoon Chung , Simon Glass , Svyatoslav Ryhel Cc: u-boot@lists.denx.de Subject: [PATCH v2 6/9] power: pmic: add the base TPS80031 PMIC support Date: Thu, 20 Jul 2023 11:48:01 +0300 Message-Id: <20230720084804.77666-7-clamor95@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720084804.77666-1-clamor95@gmail.com> References: <20230720084804.77666-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/tps80031.txt | 76 +++++++++++++++++ drivers/power/pmic/Kconfig | 6 ++ drivers/power/pmic/Makefile | 1 + drivers/power/pmic/tps80031.c | 97 ++++++++++++++++++++++ include/power/tps80031.h | 45 ++++++++++ 5 files changed, 225 insertions(+) create mode 100644 doc/device-tree-bindings/pmic/tps80031.txt create mode 100644 drivers/power/pmic/tps80031.c create mode 100644 include/power/tps80031.h diff --git a/doc/device-tree-bindings/pmic/tps80031.txt b/doc/device-tree-bindings/pmic/tps80031.txt new file mode 100644 index 0000000000..577e6de1c1 --- /dev/null +++ b/doc/device-tree-bindings/pmic/tps80031.txt @@ -0,0 +1,76 @@ +Texas Instruments, TPS80031/TPS80032 PMIC + +This device uses two drivers: +- drivers/power/pmic/tps80031.c (for parent device) +- drivers/power/regulator/tps80031_regulator.c (for child regulators) + +This chapter describes the binding info for the PMIC driver and regulators. + +Required properties for PMIC: +- compatible: "ti,tps80031" or "ti,tps80032" +- reg: 0x48 + +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 tps80031/tps80032: +- smps1, smps2, smps3, smps4, smps5 +- ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldoln, ldousb + +SMPS5 in Linux 3.1.10 is referred as vio, but datasheet clearly names it SMPS5. + +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 + +Example: + +tps80032@48 { + compatible = "ti,tps80032"; + reg = <0x48>; + + regulators { + smps1 { + regulator-name = "vdd_cpu"; + regulator-min-microvolt = <800000>; + regulator-max-microvolt = <1250000>; + regulator-always-on; + regulator-boot-on; + }; + + ... + + smps5 { + regulator-name = "vdd_1v8_gen"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-always-on; + regulator-boot-on; + }; + + ldo1 { + regulator-name = "avdd_dsi_csi"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + regulator-boot-on; + }; + + ... + + ldousb { + regulator-name = "avdd_usb"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; + }; +}; diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig index abea0fe4ed..d25fe1ce0d 100644 --- a/drivers/power/pmic/Kconfig +++ b/drivers/power/pmic/Kconfig @@ -347,6 +347,12 @@ config DM_PMIC_TPS65910 DC-DC converter, 8 LDOs and a RTC. This driver binds the SMPS and LDO pmic children. +config DM_PMIC_TPS80031 + bool "Enable driver for Texas Instruments TPS80031/TPS80032 PMIC" + ---help--- + The TPS80031/TPS80032 are PMIC's containing several LDOs, SMPS. + This driver binds the pmic children. + config PMIC_STPMIC1 bool "Enable support for STMicroelectronics STPMIC1 PMIC" depends on DM_I2C diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile index 414a9d8225..55ee614364 100644 --- a/drivers/power/pmic/Makefile +++ b/drivers/power/pmic/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_$(SPL_)PMIC_RN5T567) += rn5t567.o obj-$(CONFIG_PMIC_TPS65090) += tps65090.o obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o obj-$(CONFIG_DM_PMIC_TPS65910) += pmic_tps65910_dm.o +obj-$(CONFIG_$(SPL_)DM_PMIC_TPS80031) += tps80031.o obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o obj-$(CONFIG_$(SPL_)PMIC_LP873X) += lp873x.o obj-$(CONFIG_$(SPL_)PMIC_LP87565) += lp87565.o diff --git a/drivers/power/pmic/tps80031.c b/drivers/power/pmic/tps80031.c new file mode 100644 index 0000000000..bce01c6276 --- /dev/null +++ b/drivers/power/pmic/tps80031.c @@ -0,0 +1,97 @@ +// 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 = TPS80031_LDO_DRIVER }, + { .prefix = "smps", .driver = TPS80031_SMPS_DRIVER }, + { }, +}; + +static int tps80031_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 tps80031_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 tps80031_poweroff(struct udevice *dev) +{ + return pmic_reg_write(dev, TPS80031_PHOENIX_DEV_ON, DEVOFF); +} + +static int tps80031_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 int tps80031_probe(struct udevice *dev) +{ + struct uc_pmic_priv *priv = dev_get_uclass_priv(dev); + + priv->sys_pow_ctrl = dev_read_bool(dev, "ti,system-power-controller"); + return 0; +} + +static struct dm_pmic_ops tps80031_ops = { + .poweroff = tps80031_poweroff, + .read = tps80031_read, + .write = tps80031_write, +}; + +static const struct udevice_id tps80031_ids[] = { + { .compatible = "ti,tps80031" }, + { .compatible = "ti,tps80032" }, + { } +}; + +U_BOOT_DRIVER(pmic_tps80031) = { + .name = "tps80031_pmic", + .id = UCLASS_PMIC, + .of_match = tps80031_ids, + .bind = tps80031_bind, + .probe = tps80031_probe, + .ops = &tps80031_ops, +}; diff --git a/include/power/tps80031.h b/include/power/tps80031.h new file mode 100644 index 0000000000..3d61ac54be --- /dev/null +++ b/include/power/tps80031.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright(C) 2023 Svyatoslav Ryhel + */ + +#ifndef _TPS80031_H_ +#define _TPS80031_H_ + +#define TPS80031_LDO_NUM 9 +#define TPS80031_SMPS_NUM 5 + +/* Drivers name */ +#define TPS80031_LDO_DRIVER "tps80031_ldo" +#define TPS80031_SMPS_DRIVER "tps80031_smps" + +#define TPS80031_SMPS_OFFSET 0xE0 +#define TPS80031_OFFSET_FLAG BIT(3) + +#define TPS80031_REGULATOR_STATUS_MASK 0x3 +#define TPS80031_REGULATOR_MODE_ON 0x1 + +#define TPS80031_SMPS_VOLT_MASK 0x3F +#define TPS80031_SMPS_VOLT_MAX_HEX 0x39 +#define TPS80031_SMPS_VOLT_MAX 1400000 +#define TPS80031_SMPS_VOLT_BASE 600000 +#define TPS80031_SMPS_VOLT_BASE_OFFSET 700000 + +#define TPS80031_LDO_VOLT_MASK 0x3F +#define TPS80031_LDO_VOLT_MAX_HEX 0x18 +#define TPS80031_LDO_VOLT_MIN_HEX 0x01 +#define TPS80031_LDO_VOLT_MAX 3360000 +#define TPS80031_LDO_VOLT_MIN 1018000 +#define TPS80031_LDO_VOLT_BASE 916000 + +#define TPS80031_PHOENIX_DEV_ON 0x25 +#define DEVOFF BIT(0) + +/* register groups */ +enum { + CTRL, + VOLT, + OFFSET, +}; + +#endif /* _TPS80031_H_ */ -- 2.39.2