From patchwork Mon Sep 30 03:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 1990712 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=qgCr30eR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XH5Fv48zcz1xsq for ; Mon, 30 Sep 2024 12:52:19 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CB22888DFA; Mon, 30 Sep 2024 04:52:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.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=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="qgCr30eR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9F63F88DBA; Mon, 30 Sep 2024 04:52:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,SPF_HELO_PASS,T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazlp170110003.outbound.protection.outlook.com [IPv6:2a01:111:f403:c201::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 39F5D88DFA for ; Mon, 30 Sep 2024 04:52:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ozdg1l2r5iXoCIfLjly4Ki82Rt06GqKNwvWeQqygcWMrJ7Upwy2ZBIa/UzfHNI7+k0bb7XOz6I0zdU3Ei3bJboptOkKUWQ3WuAEmHuVpAwjiifKAzkYId3+SCJro8v2ECaJ4aiiIZnWAfc0btYofCHG8GAsQJ+B6BvKgKHZVoKWI1peTDHOaYCn55wfx4SPha+v0EKOQsW2vRO0NXSrEqmR2WzNlGsG8L9847Xf7Ey9dOM3cXW19bDsVfrfA3ylQuPSRSbiNd3PBBUKT+/6roOvgqQOLr4cwVHdcBtrcMKMZi44vmtLv0ldIi60mBeU96HOo2jSn4Mae0sMg6UbNnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jC9IbHX2lkTFQySXHqgw5YQZJWCM+urXOST0p2NMWx8=; b=Fu19DSGPdnSFoMubBpeOmH9MYxuDllPuqCHC9On5YIcdj9nKtTBk7qMkTU+68YDkSTNeFc3lzxuFv9DY/tCA9py05i7t9YZYI27gCE8wVxWbcbrCyCjXo1Rgbz824qOjENr+vvTIYstlGC2bHgV+a8yh2/vV9Xk7m0fgW47gtQD0FvWUkkqwMErC1NETlQH03fhNdvHUvK+3n3Pvoc9uIf0K/ajJBFChZlmNrSXZOp6syVjOK0zhHwagHYaPOAvit+dlz+Z0ww7UB9dhC5qWhma93Wg0VzsyNEeY7MRJnM/0DQyl0UaxcHRmAcUQD6N85+7gify0EC24SUqSw9i8ag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jC9IbHX2lkTFQySXHqgw5YQZJWCM+urXOST0p2NMWx8=; b=qgCr30eRDLOvKRA/5i3HisvNMcnb/w92KlJ9F8wDrPVxrzfw02iwO0njft8oifRFvwFCpUphrL/03GTU90Qk23dBk2AKYW+ecIB45PDs/6YjdzjERmx2l9tVPImjrTT+hLhJ/K6t7NlP2G0LFxRrUZEPF8hSnmIYfaoJWBDfK4qMiKd0MFsMRALfci59Kpjxjr7ktQ/1Jk9RE0FhG5qrXsLFXQ1cE6akLSGNYpQ8dPE8ptf95eXJJz61iH7rCad+sLBSGkC4cgChdXPJMzwLBFQXowC72Sf5o1PVkjF0rF3IDujhYXTU3LdcqdN6N3elFgvPGWNRHmjVJdMNhdPbuQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by DU2PR04MB8712.eurprd04.prod.outlook.com (2603:10a6:10:2df::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 30 Sep 2024 02:52:02 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7982.018; Mon, 30 Sep 2024 02:52:00 +0000 From: "Peng Fan (OSS)" To: festevam@gmail.com, sbabic@denx.de, u-boot@lists.denx.de, Tom Rini , Jaehoon Chung Cc: uboot-imx@nxp.com, Joy Zou , Ye Li , Peng Fan Subject: [PATCH 1/4] power: pmic: Support pmic pf5300 Date: Mon, 30 Sep 2024 11:55:27 +0800 Message-Id: <20240930035531.27079-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.35.3 X-ClientProxiedBy: SI2P153CA0003.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::20) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|DU2PR04MB8712:EE_ X-MS-Office365-Filtering-Correlation-Id: 47739a30-5f80-4af6-27ae-08dce0fadb12 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|52116014|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: PPb6HHiXakN08tfUrstqc7A9OKuNzH/OveKz+6NqY2t0mdxCt6Cw2z7KndKMCw4gSfR/4LEl+tZFdQJUETCDVYeKlg8qFS4MXoNuROEoK90zjdYZf31SqQI/MYTD5Zs7E7cKFZmI9IgJjwYDpNHtNIlQQ8wo1Wbpyc31eDBJtDtlLax5HhpeT42QfuB7SIlarL95gVjHdXonu0lt2ylfTmA2kZh/MtFN0wVqzxyY/XUZbplIjLmOm8viwg2FsSms5WTkglj0ZviXikurUh4Ko3W9jyyJ9kI1ShWWBOIcxizcGTMeRFRZSGICjP+P8kRsTD3L6wGEGCFeObxaJFDsniZuwHLtLz0cTBJzKJHm3yxcSV60FJZV7gT6iiMeVqJM5YcEcP1OJ/HGHGtueZFpLIwY7pr2xjlSiO4sDEpu0kEO3SFQv6mCnopixbJcQc79xX7tJ9IQQustDTq9uiNCh7Nctt/+5KB2bUSKv6Gw0Dy33wqlkxdXKasJg1IwmzXcf0HjVq5Wyorc2I08Y6ZPNAHjfDvD0TjGiXbRWl3vKT6ZebSq4MxTfRXZK3/s5M7rXWF5XH61KlHgAD2RTvQ3CB3fzd8s9EiyA7JWTtMyGn8wv1Lu43O9xuMIzovoKBhZYRhSyXId2MZenZLEeIQpZKXNhooALFFAnfNEoZr/C29CIxMQImXzKZGEmg2u84gPIzaiiugCwaBkqMRmsVpU6yGPOgdRD3WNXWm0u3usrdb+hL2JbRaMWOi9lHr3K027sDxrSsDldEPHZUslLwpbmv60mZEVGOyQ/mspkkakyfHxMcbn+lIJnOpGPofIXFoXswZev+g2jMk5zyWJHFHISrPzGr/VXYOZET8B9n0H1K1qmopGJ5Cx2zMZ7dhe60+BGE+wqNRuPdnwgOCKPCv4dN97Bal8GCjoPRSYpgTPrybesIXS6uMv0OcLiEnuS0rWOHS3x6hKiZw6K80lKji84NwiqixDVfe7605pmQM+tBCe5AJLaxSUEHEhUyY7TsdaSeIfROofQW0g2Kk2TU0mbO8ofb3A3VN9ww/DKlS0NT+t1ZKMYnUOKtpICcxzXEbxe3Z1H2Fsz8zQgaGnD6phExpsDmvEdWYVA6vO4ioR9ShunIBQQxZavWBzH3ujqg6DkAzWjpKt0NHydjO6xvj1a4ZmTP1Xv4KsLV2YpSakrwTpfBiXCj23tSVzkk37Tm5XlppR5CrWU0oWVhCnrm3RmcvG5c8ttHgw7fClzjVbF+UNCI7YGcAQGWW5nOspPx+Ocgcif0b/oqs481vv5GyhLJfL+ZdjwQVSo7u6bTMC0cz5TB6u8Grm00fWJeTZBJESKJeJb2INXhB6Zcg0a7N8Lg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8459.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(52116014)(366016)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /cXNNp3iRg+OAkfWY3YUbT45epsn2nSIgRmn7hkrMFtOkSbg32QEHlEzn5xgUx/j43znYy0Xhym3J/8vRT21Rrj3Bf+IIEc/eaCj0Y4riVT7VIfdxSu+Rgmj2nFkafMs4asgRPNsYIB+uA7Kw3HjZuha5TABb3TFPTDUP6p/gRtdKn9514jHY99pe8NzZbaCwmJHgco2DpHi7dA61106Gd9ALyehiQSIG7SaUxFFpbWCFwt5RzN8R2RD+Vab3aOF9qKHpi2d1ZBSxJeDonm9y3jvclvkhwxZs39DvpJ6kVNtVDMGo3j40yJ0AqF1JnE5KGs78J8MC+vFIeRgg3Qfvf1KXbZCMqPmd81De4YOGjj1skwJBrldtjAO21A0isJsvDTMsMtEW00ChAs84lu+OR2eEd5dsfx2gAR7wtaycNFvsT55mNFb5YFli8YldGCIKRTkaLfqISX7X911cE5NfUMWLCxJa69p7HKCgIihLMuv23q6gnJUnJd60ZTlBJg2lGHmZ7lAhmAq99geP2XaVlR6qu6GWea8onHcw3oGPcW9kQUcuHVrXnkNlHSpwUB+IoeVY2A6VR2WEM4d2RJPUHk55lqBN2LFW2cL+hzZV7AfspAfifjCG9QbsnCQPXl8cEVvtkf0fRLXoFsHUg9CTOUnfkL24FQdEk6s8UEZ44Kf194Lzm7Uj2tlBztmB8gLyDhDsuWkZ5jBsOIWrOtY0NjvJVXO1wb6gf+OwTBURxaYEQ4oaCQgnXL/YkYAH0N+6xek/1uSEkrE/T20nETEBkGspPYq3qkPJyIxWAZJH/tYbDyzDsHT6gy72hqe7zjPa/N5FXO7wKmIUGskfAzg27rLbHN6jJQdi6Mx54WX6qFebp6aUudNnsamLi44x1T2ZlY+B/hw/NGqXiv1gB7asmgjHyt5nO0ARR81ERWm0AEGf8lDganbaqB5PUuo53/X+dL8tpMi5qeQkMJTwMXD3fHLKBLsMnu33EW8zr4QzmaRBK7iPMYSy0G0ePkMXI7+SJxEyqkt+2ekjMc+Lz28iqYs59Ub/VLkeirvcCA0T08xJ9b7ro19LV8E2eUViliFX5TEyXsG3xdfWOm39Axm0pwqd5/y1Pa1VvdO1f5J8Yn82PeY4w5j69kBESmNNwrRyt1v9u8sEC5jN/4XCBaQZFyT0Gt7nGTR+RzkfuOkUKIpPAYTpimRmiGmFn3tmd/jN4b5Jq0Wiwy+/qcN4mM2KNhZAs18fsyQVjiZAUtpJgVzc7u1PMBz6zR4IoPOOvirQvgThzi056gc5y2QRM84rTXRCMfu5KGs+W8QJ/FiKhUuAcBza4drXQDDUUg8xqyEcdF/nlrVp/WO17557jWEHkncSvBoesEs1cQLHxNYL6U5SFC8HZ1UmzDokGeEl9+3vkFHt8u6ebYlIzAC7ek/beSBlqokmOzi1rKUnaf3FAAfhp4wFWkVPc1sQhg4ewDQopnzDTfa88f5D6RLCGV8CPgLhHPAvik3K53JjU1KyYITUT937K7Ns0S1tWQzy5yv8TK7N6BLcUBBQDZvK2Vf5JuF/zyyAnq3zVFxk1CA4hJUvmry92LCUpHplWLVOzR8 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47739a30-5f80-4af6-27ae-08dce0fadb12 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 02:52:00.4639 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Fj6YxmP1NO8RDzRLWJRT/lsAIRv3OYp2/maWrqF+SLG2QMkgfMeEfraASeNp7/ciXpj+KrHpyCkhnrkaMc1ytQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8712 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 From: Joy Zou Support NXP pmic pf5300 Signed-off-by: Joy Zou Reviewed-by: Ye Li Signed-off-by: Peng Fan --- drivers/power/pmic/Kconfig | 15 ++++ drivers/power/pmic/Makefile | 1 + drivers/power/pmic/pf5300.c | 168 ++++++++++++++++++++++++++++++++++++ include/power/pf5300.h | 100 +++++++++++++++++++++ 4 files changed, 284 insertions(+) create mode 100644 drivers/power/pmic/pf5300.c create mode 100644 include/power/pf5300.h diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig index 1a5ef279ed6..420c4099937 100644 --- a/drivers/power/pmic/Kconfig +++ b/drivers/power/pmic/Kconfig @@ -186,6 +186,21 @@ config SPL_DM_PMIC_PF0900 This config enables implementation of driver-model pmic uclass features for PMIC PF0900 in SPL. The driver implements read/write operations. +config DM_PMIC_PF5300 + bool "Enable Driver Model for PMIC PF5300" + depends on DM_I2C + help + This config enables implementation of driver-model pmic uclass features + for PMIC PF5300. The driver implements read/write operations. + +config SPL_DM_PMIC_PF5300 + bool "Enable Driver Model for PMIC PF5300 in SPL" + depends on SPL_DM_PMIC + depends on SPL_DM_I2C + help + This config enables implementation of driver-model pmic uclass features + for PMIC PF5300 in SPL. The driver implements read/write operations. + config DM_PMIC_PFUZE100 bool "Enable Driver Model for PMIC PFUZE100" ---help--- diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile index 0041ab59406..74ace69daf5 100644 --- a/drivers/power/pmic/Makefile +++ b/drivers/power/pmic/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_$(SPL_)DM_PMIC_MP5416) += mp5416.o obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o obj-$(CONFIG_$(SPL_)DM_PMIC_PCA9450) += pca9450.o obj-$(CONFIG_$(SPL_)DM_PMIC_PF0900) += pf0900.o +obj-$(CONFIG_$(SPL_)DM_PMIC_PF5300) += pf5300.o obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o obj-$(CONFIG_PMIC_AB8500) += ab8500.o diff --git a/drivers/power/pmic/pf5300.c b/drivers/power/pmic/pf5300.c new file mode 100644 index 00000000000..b66fa756109 --- /dev/null +++ b/drivers/power/pmic/pf5300.c @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2023 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static const struct pmic_child_info pmic_children_info[] = { + /* sw */ + { .prefix = "S", .driver = PF5300_REGULATOR_DRIVER}, + { }, +}; + +static int pf5300_reg_count(struct udevice *dev) +{ + return PF5300_MAX_REGISTER; +} + +static u8 crc8_j1850(u8 *data, u8 length) +{ + u8 t_crc; + u8 i, j; + + t_crc = 0xFF; + for (i = 0; i < length; i++) { + t_crc ^= data[i]; + for (j = 0; j < 8; j++) { + if ((t_crc & 0x80) != 0) { + t_crc <<= 1; + t_crc ^= 0x1D; + } else { + t_crc <<= 1; + } + } + } + return t_crc; +} + +static int pf5300_read(struct udevice *dev, uint reg, u8 *buff, + int len) +{ + u8 crcBuf[3]; + u8 data[2], crc; + int ret; + struct pf5300_priv *priv = dev_get_priv(dev); + + if (reg < PF5300_MAX_REGISTER) { + ret = dm_i2c_read(dev, reg, data, + priv->crc_en ? 2U : 1U); + if (ret) + return ret; + buff[0] = data[0]; + if (priv->crc_en) { + /* Get CRC */ + crcBuf[0] = priv->addr << 1U | 0x1U; + crcBuf[1] = reg; + crcBuf[2] = data[0]; + crc = crc8_j1850(crcBuf, 3U); + if (crc != data[1]) + return -EINVAL; + } + } else { + return -EINVAL; + } + return ret; +} + +static int pf5300_write(struct udevice *dev, uint reg, const u8 *buff, + int len) +{ + u8 crcBuf[3]; + u8 data[2]; + int ret; + struct pf5300_priv *priv = dev_get_priv(dev); + + if (reg < PF5300_MAX_REGISTER) { + data[0] = buff[0]; + if (priv->crc_en) { + /* Get CRC */ + crcBuf[0] = priv->addr << 1U; + crcBuf[1] = reg; + crcBuf[2] = data[0]; + data[1] = crc8_j1850(crcBuf, 3U); + } + /* Write data */ + ret = dm_i2c_write(dev, reg, data, + priv->crc_en ? 2U : 1U); + if (ret) + return ret; + } + return ret; +} + +static int pf5300_bind(struct udevice *dev) +{ + int children; + ofnode regulators_node; + + regulators_node = dev_read_subnode(dev, "regulators"); + if (!ofnode_valid(regulators_node)) { + debug("%s: %s regulators subnode not found!", __func__, + 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) + debug("%s: %s - no child found\n", __func__, dev->name); + + /* Always return success for this device */ + return 0; +} + +static int pf5300_probe(struct udevice *dev) +{ + struct pf5300_priv *priv = dev_get_priv(dev); + unsigned int reg; + int ret = 0; + + ret = ofnode_read_u32(dev_ofnode(dev), "reg", ®); + if (ret) + return ret; + priv->addr = reg; + + if (ofnode_read_bool(dev_ofnode(dev), "i2c-crc-enable")) + priv->crc_en = true; + + return ret; +} + +static struct dm_pmic_ops pf5300_ops = { + .reg_count = pf5300_reg_count, + .read = pf5300_read, + .write = pf5300_write, +}; + +static const struct udevice_id pf5300_ids[] = { + { .compatible = "nxp,pf5300", .data = PF5300_TYPE_PF5300, }, + { .compatible = "nxp,pf5301", .data = PF5300_TYPE_PF5301, }, + { .compatible = "nxp,pf5302", .data = PF5300_TYPE_PF5302, }, + { } +}; + +U_BOOT_DRIVER(pmic_pf5300) = { + .name = "pf5300 pmic", + .id = UCLASS_PMIC, + .of_match = pf5300_ids, + .bind = pf5300_bind, + .probe = pf5300_probe, + .ops = &pf5300_ops, + .priv_auto = sizeof(struct pf5300_priv), +}; diff --git a/include/power/pf5300.h b/include/power/pf5300.h new file mode 100644 index 00000000000..0d2fa548a70 --- /dev/null +++ b/include/power/pf5300.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2023 NXP + */ + +#ifndef PF5300_H_ +#define PF5300_H_ + +#define PF5300_REGULATOR_DRIVER "pf5300_regulator" + +struct pf5300_priv { + u8 addr; + bool crc_en; +}; + +enum pf5300_chip_type { + PF5300_TYPE_PF5300 = 0, + PF5300_TYPE_PF5301 = 1, + PF5300_TYPE_PF5302 = 2, + PF5300_TYPE_AMOUNT, +}; + +enum { + PF5300_SW1 = 0, + PF5300_REGULATOR_CNT, +}; + +enum { + PF5300_DVS_LEVEL_RUN = 0, + PF5300_DVS_LEVEL_STANDBY, + PF5300_DVS_LEVEL_MAX, +}; + +#define PF5300_SW1_VOLTAGE_NUM 0x100 + +enum { + PF5300_REG_DEV_ID = 0x00, + PF5300_REG_REV_ID = 0x01, + PF5300_REG_EMREV = 0x02, + PF5300_REG_PROG_ID = 0x03, + PF5300_REG_CONFIG1 = 0x04, + PF5300_REG_INT_STATUS1 = 0x05, + PF5300_REG_INT_SENSE1 = 0x06, + PF5300_REG_INT_STATUS2 = 0x07, + PF5300_REG_INT_SENSE2 = 0x08, + PF5300_REG_BIST_STAT1 = 0x09, + PF5300_REG_BIST_CTRL = 0x0A, + PF5300_REG_STATE = 0x0B, + PF5300_REG_STATE_CTRL = 0x0C, + PF5300_REG_SW1_VOLT = 0x0D, + PF5300_REG_SW1_STBY_VOLT = 0x0E, + PF5300_REG_SW1_CTRL1 = 0x0F, + PF5300_REG_SW1_CTRL2 = 0x10, + PF5300_REG_CLK_CTRL = 0x11, + PF5300_REG_SEQ_CTRL1 = 0x12, + PF5300_REG_SEQ_CTRL2 = 0x13, + PF5300_REG_RANDOM_CHK = 0x14, + PF5300_REG_RANDOM_GEN = 0x15, + PF5300_REG_WD_CTRL = 0x16, + PF5300_REG_WD_SEED = 0x17, + PF5300_REG_WD_ANSWER = 0x18, + PF5300_REG_FLT_CNT1 = 0x19, + PF5300_REG_FLT_CNT2 = 0x1A, + PF5300_MAX_REGISTER, +}; + +/* PF5300 SW1_CTRL1 */ +#define SW_MODE_OFF 0x00 +#define SW_MODE_PWM 0x0c + +#define SW1_MODE_MASK 0x0C +#define SW1_STBY_MODE_MASK 0x30 + +#define SW1_RAMP_MASK 0x03 + +/* PF5300 SW1_VOLT/SW1_STBY_VOLT MASK */ +#define SW1_VOLT_MASK 0xFF +#define SW1_STBY_VOLT_MASK 0xFF + +/* PF5300_REG_INT_STATUS1 bits */ +#define IRQ_SDWN 0x80 +#define IRQ_BG_ERR 0x40 +#define IRQ_CRC 0x20 +#define IRQ_SW1_DVS_DONE 0x10 +#define IRQ_SW1_ILIM 0x08 +#define IRQ_VMON_UV 0x04 +#define IRQ_VMON_OV 0x02 +#define IRQ_VIN_OVLO 0x01 + +/* PF5300_REG_INT_STATUS2 bits */ +#define IRQ_PGOOD_STUCK_AT0 0x80 +#define IRQ_PGOOD_STUCK_AT1 0x40 +#define IRQ_DVS_ERR 0x20 +#define IRQ_FSYNC 0x10 +#define IRQ_THERM_155 0x08 +#define IRQ_THERM_140 0x04 +#define IRQ_THERM_125 0x02 +#define IRQ_THERM_110 0x01 + +#endif From patchwork Mon Sep 30 03:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 1990713 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=q2KmymYL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XH5Fz4dBrz1xsq for ; Mon, 30 Sep 2024 12:52:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3B57B88E43; Mon, 30 Sep 2024 04:52:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.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=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="q2KmymYL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 69EEB8641A; Mon, 30 Sep 2024 04:52:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,SPF_HELO_PASS,T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazlp170120003.outbound.protection.outlook.com [IPv6:2a01:111:f403:c200::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 49D0E889B8 for ; Mon, 30 Sep 2024 04:52:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x3HQmUMYxhaFZXmpdCtFjC4cDF10oSYEBAjYwSx4UeHXhAr2wvHeT1gxcB4oh4JzoCZIx7Snl+PZKdDTQ4pVc2lqi/1MR/Jikh+XizgchDM2sZ8jw5KihG//147mGoR3jyXq1lvcZ4NMzsZA29q3l6YJyTftR4Vv1mdS255FzRT/oMHDgPz9903al0srnYOwfJrznJ8fn+JfNeXi7o6IMoZHXCYtrkBeVMLTHyDctFaMZlMe3FJ/1zuGr4WLW5WfezWbh3tphWS0VoSNMPzFRpX600/9RD0sDwFOdrNpz1/fdDqETQsMuz+WDamBX3rAUmhR0qptk0Zx4v+DqnHYxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GJHCPSeeUrbuWgrN7iHTZdZkdDu+b1BF3+NTUzxBfNs=; b=Jqp/Off+h+F9/uXVgqs7Pr/+dnoQyWZnLMlF4f9Wc08k6QqBya04cJ7bhwSoAOioM9xcRv8uHw37YPurEse3eWScxryF6s8DnD0UbgKWUVPEm0K5jwXGGGUCKCQqg0zfbfOy1cNRYK+8saaqHYBJ/0s4WZQKv1sYaSJlMqVkia3HCdDqVgDU/s8rm33NDyPWuiyqsVvaL2Q6wPE+3xS/gcOKrOTu8+v2Kqyf6wv47RvShmAyOxdj1xajnUSTMZDBOb17mmjBff75w2BECjJ3B+NzxaPnZ7YtzBLG31vLzX5cGjOVLRyDStTx1nyOfq99GonUl/AwUvwTy8MLZ4lsPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GJHCPSeeUrbuWgrN7iHTZdZkdDu+b1BF3+NTUzxBfNs=; b=q2KmymYLnoi+lB9488kEYkTjvXnNY2iuol/FjtHIlgFYd4hfKYh6fZ9PSFxhkFqmL4Ba/1YWDyywJL+/VjimajKIV6CJVCRscOkDwXpzLc8CaowBDX9Qb8CUav5Ms4aQY/SWc3RkanwAmE0Z37trRcBI5/F7efFf/9gxmHFa0piKThxSm44zuA/rucgM555bqYrJaCUi+YyVqKQJLdZoDuQDSW1Y4QW8YOku3O4c+fhZyr70cNx63e9sgzcKCyDL8CzFgm4gRL/7CMSkj3rX2WnZ+cTiNSCWsZ4eieRgAPrG1+iIx0haMPXve53E3kLCHI57M5nZgzPYXd56e1dqLg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by DU2PR04MB8712.eurprd04.prod.outlook.com (2603:10a6:10:2df::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 30 Sep 2024 02:52:05 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7982.018; Mon, 30 Sep 2024 02:52:05 +0000 From: "Peng Fan (OSS)" To: festevam@gmail.com, sbabic@denx.de, u-boot@lists.denx.de, Tom Rini , Jaehoon Chung Cc: uboot-imx@nxp.com, Joy Zou , Ye Li , Peng Fan Subject: [PATCH 2/4] power: regulator: Support pmic pf5300 Date: Mon, 30 Sep 2024 11:55:28 +0800 Message-Id: <20240930035531.27079-2-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240930035531.27079-1-peng.fan@oss.nxp.com> References: <20240930035531.27079-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SI2P153CA0003.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::20) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|DU2PR04MB8712:EE_ X-MS-Office365-Filtering-Correlation-Id: a6ca4f33-990e-40ed-b554-08dce0faddd6 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|52116014|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: ICYEkkimVa9WrtQe9o5XNxauFVEHmpvswsItC2RFiNj3QBRmMbmQFUdYP+2WNbTq+XRR18thp6XnAP/aIt7/4v/X3GVGb/u5IY0gt/i4posFUI2UodqNRfUm6bWtKG+5A818E7UQp3a8DZ9bOQex18LUr21uvyPryegowPUkDOVBRqeajUu04luRXeawiC1Abi5c+B4KyRXYTbVKrs8vT1xLa2vkkzdQXTf59m1ZK+RTOTgEfw9+PMC1MuXr2/jPF4bhbWdT7DRzPet18zP92S6xnk10SN55LcSpVZFRp29s+4Kplz4MANgcSCFLFM+KZ2rBRl/iJCkjFsIobST7nCQUqJjcM5xcptj8AuIPQq7alFIUz1w36ZAben+SaPkBzRxfBpIANVXVeGeJoi84W92Qgcg4Xrv2NcRXF+SJ+QOtW56WtQQM6oO7FCBCpFUmjoDTMRGTOwzz+OX+EdyMMuAKn6O3AufY3bEtWv/KAt0yaiuJLVO88id4K4OnEkLvr/ynlYgLqFZUYllFYC+y6QOAoMAb5N5MMlPRNfhXphqoprC3BxVvWu0Mn+evV2aaD+h+TjjjCdWcPbdvyvzKTH7ipJ/vuknpVUjlW5lpD3XeqRVOdSPKL1ZKVWwvq+vF1L/vGleggS7EuRXUj6Lh+acSWDgQWxXjOJblOjZ0wndufrebSs4TCEReQd8FXeHAwwyyAH3U9k2on9PH1k5FRZaNlhNqpGG2dbyIxVEmAdVQdF/gi/pFOlW5jYbyT725m1KZjfz1iA4fkvFaghzptan915/chnPJx50H2wI+SLTAnPX7X/FqJ94FHAh9h/npG1wSmusEIFAs+rWZ2jeWhDGxYdzd55GIOOIR1wc83JJb319yhv4IE6iihW7S2fLHhxIF8IvRXQMuO4PCsVcGtL0bSftnEG8DAK3Bn+t2pLEJxXhFks0qxg+mpq6T/iljcAEYkrfy0XubZFV5dTintpXPBSY2ZWGNT6R9h90+izsnVbTvS9cef/hif0iRz8Z9xPdCkH+MetMSzxRywD8iEirvd9HeCamVgXWxP7cDpRjJUlofhBbmdMswq3o6XbCR85gUWkS3HyIhUs/XbKcGj8Zm4SMVY4S0dkvZ5Ok18wVNADOHVywYYLH4A3AtZeIBPl3H4uchJhSR9XWBDgIy63A2m6BTZneUcc6d1nh1HDpR2fgYquH4m8fKFk65A7FqCDIoMRBwd1LzZ7+KjsaEAa0CZsbV0R/ty8ik0OAZ1v2dVnqloTgu210yKwINt4p4MoE4MdblSp1bw6mhMCLkOr2ZSF3bun7SVMekddFFsFnVX64VJFRwkm4al45kXYhhDjqCaYpolCS0dREEOySR9g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8459.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(52116014)(366016)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nW6d8tsGyA1xJQpJRN/zPB5oFuJMU2uwEQMrS5X8ZPrbRd2TDPVoHVKmQkNsT4sxNFGDslQ96kNFprQLJpy+tXWYQTVFmPL32A9KAo/rzZYq4/jo98f3Us++/SZE3BNIXeDqp2VzgSZEeXEb3l7UU/qKYVlBTWxaKspAWvpcK3v6R7jtMBarDvo7vm9B8OEyk12hUkMt17HtF14J5Sp5A9B7bAoOugKFtGf3nGsp2GW3DfP2Bnm2KHfzMHogPuSHj6QmRhYM2E0f5beObHha2xNNHD0pzcWVyHyF4+/OOs2SDhG05cC1CGt+JpFUmRSJREaj+59FbOY/WncxLtngxtVIUDcKzFkhA3REuTRawcBosl804GrWklXoTJahQFcWAZwIFPPCX0PE2Y19KIyaZLqN/kVWzNV1C/aoDfSd81lJKsU+qEQt2k+krI5KuQaLSyQwXU2YHR1K6KLoagjuasN28BSj5Tgx9mWtNFYYbdM4/9v4rS/BwCQlAe0w33Zd9gUEfH56aC8XGklCSGuaiZJ9KiXMrM8meUm8Vjyk5tJC4ZaoupKWo/yD7BX8Zv/eal/MsVQOIHfqaZjXAeSZ97dwQ1t/Bu/gRqlTtPM3BEbGNXy7N+mH6vrriNxT5IEwn9F+9uvaPsJiif9Uf40p71awOri6AbJYSapkR1SURhhkg3OYQtlyyqMw++5pP/mbAmB+ZbXEHi7yM2Yi+UcNrnez5KCdgaPinW8CL5VfnG49Hp0zg2KbEuJXyAdvsTpY11iQKGHWfM8YitzMxfU7QtTi943pBl4JYzx+47o8xQQKkr5h9gharYgdd3ti1fhC4ef5OLM70thWUNKDZajS0nxFPT8HXwJ8P3BXDbz2BVhiGasySCRbCc+JTkAzSoOB8fVRq+CSZeENKToV6C3rloR3LDHxN0M7cGJbI/nagD3gq4iU/XpHaA70MCLiRo48Zm6XxDQ7XZnU5vezgY9yaJAxqQ4sjFTxgQ3SJ0pujISoFA1D0l8Ww2VjUM0NMMXq1keT4yVmU3KQPlR/RWGN1clALgRUCqu4vmQxhtRPYxJUdiQzt2L3BOKYFtR3hIow7bG75KN26g3OMzZ0kGo/36paYaJHxTD5qDbWguJ81hlav7THMyxkgv4goJyYFdOZpgB91u82qE5gbXwt81zR2IwDLjS0tDqRdVDtKO2oPKdZEl0idi89i3r/398YT1X5ZKis0opf1nYL2pDJ5qa/wkHpwr4RnXjWidYEJ5KdF5Us1f2K4hCj6Wo/ZdCZkuZNFWBrbfXv9YDe/iTiy1MK8KlF2GpwyUCi5HibsCGZg06HPxt23SOOMnqTU/nGHZ7Hdb5bv24W/h7+POQVGrxqzPEpwaQhFKtX+LichXLofS/uOgkwER73twVdR4gUDo/ZiDQM0Cd5e69eB+X+nw1B3aGisXmEpaCCU5JSqiMCUOSsKVat6LOchU6KpVa7ovvdLxvoQiegtSw6CDgXwBlfU4vH4ZTr8m71nDWfWLA0PQRSf1JQNgPT06GaoSLiDhrrk+zLEgjct9Y0bAEnH2GqX212dDs4FML5eGOEoj0ZSx3ddNM/Z7erzl2Cww8E9d1B X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6ca4f33-990e-40ed-b554-08dce0faddd6 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 02:52:05.0965 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZDIudlzs1XDS5xLRBmf++5e/a+NYa4naMx/+7y9wN5nmfFgoXtJmFjJ7VhFuL0r6eHOtzpv0a7pT2qQ4pF8rcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8712 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 From: Joy Zou Add regulator support for NXP pmic pf5300. Signed-off-by: Joy Zou Reviewed-by: Ye Li Signed-off-by: Peng Fan --- drivers/power/regulator/Kconfig | 15 ++ drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pf5300.c | 247 +++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 drivers/power/regulator/pf5300.c diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index b2f487b050b..69dfb07df50 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -111,6 +111,21 @@ config SPL_DM_REGULATOR_PF0900 This config enables implementation of driver-model regulator uclass features for regulators on ROHM PF0900 in SPL. +config DM_REGULATOR_PF5300 + bool "Enable Driver Model for NXP PF5300 regulators" + depends on DM_REGULATOR && DM_PMIC_PF5300 + help + This config enables implementation of driver-model regulator uclass + features for regulators on NXP PF5300 PMICs. PF5300 contains 1 sw. + The driver implements get/set api for value and enable. + +config SPL_DM_REGULATOR_PF5300 + bool "Enable Driver Model for NXP PF5300 regulators in SPL" + depends on DM_REGULATOR_PF0900 && SPL + help + This config enables implementation of driver-model regulator uclass + features for regulators on ROHM PF5300 in SPL. + config DM_REGULATOR_DA9063 bool "Enable Driver Model for REGULATOR DA9063" depends on DM_REGULATOR && DM_PMIC_DA9063 diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index a49700dfd25..7a580d45b72 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_BD71837) += bd71837.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PCA9450) += pca9450.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PF0900) += pf0900.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PF5300) += pf5300.o obj-$(CONFIG_$(SPL_)REGULATOR_PWM) += pwm_regulator.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_FAN53555) += fan53555.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_COMMON) += regulator_common.o diff --git a/drivers/power/regulator/pf5300.c b/drivers/power/regulator/pf5300.c new file mode 100644 index 00000000000..6df24934e09 --- /dev/null +++ b/drivers/power/regulator/pf5300.c @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * NXP PF5300 regulator driver + * Copyright 2023 NXP + */ + +#include +#include +#include +#include +#include +#include +#include + +/** + * struct pf5300_vrange - describe linear range of voltages + * + * @min_volt: smallest voltage in range + * @step: how much voltage changes at each selector step + * @min_sel: smallest selector in the range + * @max_sel: maximum selector in the range + */ +struct pf5300_vrange { + unsigned int min_volt; + u8 min_sel; + u8 max_sel; + unsigned int step; +}; + +/** + * struct pf5300_plat - describe regulator control registers + * + * @name: name of the regulator. Used for matching the dt-entry + * @enable_reg: register address used to enable/disable regulator + * @enablemask: register mask used to enable/disable regulator + * @volt_reg: register address used to configure regulator voltage + * @volt_mask: register mask used to configure regulator voltage + * @ranges: pointer to ranges of regulator voltages and matching register + * values + * @numranges: number of voltage ranges pointed by ranges + */ +struct pf5300_plat { + const char *name; + u8 enable_reg; + u8 enablemask; + u8 volt_reg; + u8 volt_mask; + struct pf5300_vrange *ranges; + unsigned int numranges; +}; + +#define PCA_RANGE(_min, _sel_low, _sel_hi, _vstep) \ +{ \ + .min_volt = (_min), .min_sel = (_sel_low), \ + .max_sel = (_sel_hi), .step = (_vstep),\ +} + +#define PCA_DATA(_name, enreg, enmask, vreg, vmask, _range) \ +{ \ + .name = (_name), .enable_reg = (enreg), .enablemask = (enmask), \ + .volt_reg = (vreg), .volt_mask = (vmask), .ranges = (_range), \ + .numranges = ARRAY_SIZE(_range) \ +} + +static struct pf5300_vrange pf5300_sw1_vranges[] = { + PCA_RANGE(500000, 0x00, 0x8C, 5000), + PCA_RANGE(0, 0x8D, 0xFF, 0), +}; + +static struct pf5300_plat pf5301_reg_data[] = { + PCA_DATA("SW1_2a", PF5300_REG_SW1_CTRL1, SW_MODE_PWM, + PF5300_REG_SW1_VOLT, SW1_VOLT_MASK, + pf5300_sw1_vranges), +}; + +static struct pf5300_plat pf5302_reg_data[] = { + PCA_DATA("SW1_29", PF5300_REG_SW1_CTRL1, SW_MODE_PWM, + PF5300_REG_SW1_VOLT, SW1_VOLT_MASK, + pf5300_sw1_vranges), +}; + +static int vrange_find_value(struct pf5300_vrange *r, unsigned int sel, + unsigned int *val) +{ + if (!val || sel < r->min_sel || sel > r->max_sel) + return -EINVAL; + + *val = r->min_volt + r->step * (sel - r->min_sel); + return 0; +} + +static int vrange_find_selector(struct pf5300_vrange *r, int val, + unsigned int *sel) +{ + int ret = -EINVAL; + int num_vals = r->max_sel - r->min_sel + 1; + + if (val >= r->min_volt && + val <= r->min_volt + r->step * (num_vals - 1)) { + if (r->step) { + *sel = r->min_sel + ((val - r->min_volt) / r->step); + ret = 0; + } else { + *sel = r->min_sel; + ret = 0; + } + } + return ret; +} + +static int pf5300_get_enable(struct udevice *dev) +{ + struct pf5300_plat *plat = dev_get_plat(dev); + int val; + + val = pmic_reg_read(dev->parent, plat->enable_reg); + if (val < 0) + return val; + + return (val & plat->enablemask); +} + +static int pf5300_set_enable(struct udevice *dev, bool enable) +{ + int val = 0; + int tmp = 0; + struct pf5300_plat *plat = dev_get_plat(dev); + + if (enable) + tmp = plat->enablemask; + val = pmic_reg_read(dev->parent, plat->enable_reg); + if (tmp < 0) + return tmp; + val = (tmp & plat->enablemask) | (val & (~plat->enablemask)); + + return pmic_reg_write(dev->parent, plat->enable_reg, val); +} + +static int pf5300_get_value(struct udevice *dev) +{ + struct pf5300_plat *plat = dev_get_plat(dev); + unsigned int reg, tmp; + int i, ret; + + ret = pmic_reg_read(dev->parent, plat->volt_reg); + if (ret < 0) + return ret; + + reg = ret; + reg &= plat->volt_mask; + + for (i = 0; i < plat->numranges; i++) { + struct pf5300_vrange *r = &plat->ranges[i]; + + if (!vrange_find_value(r, reg, &tmp)) + return tmp; + } + + pr_err("Unknown voltage value read from pmic\n"); + + return -EINVAL; +} + +static int pf5300_set_value(struct udevice *dev, int uvolt) +{ + struct pf5300_plat *plat = dev_get_plat(dev); + unsigned int sel; + int i, val, found = 0; + + for (i = 0; i < plat->numranges; i++) { + struct pf5300_vrange *r = &plat->ranges[i]; + + found = !vrange_find_selector(r, uvolt, &sel); + if (found) { + unsigned int tmp; + + /* + * We require exactly the requested value to be + * supported - this can be changed later if needed + */ + found = !vrange_find_value(r, sel, &tmp); + if (found && tmp == uvolt) + break; + found = 0; + } + } + + if (!found) + return -EINVAL; + + val = pmic_reg_read(dev->parent, plat->volt_reg); + if (val < 0) + return val; + val = (sel & plat->volt_mask) | (val & (~plat->volt_mask)); + return pmic_reg_write(dev->parent, plat->volt_reg, val); +} + +static int pf5300_regulator_probe(struct udevice *dev) +{ + struct pf5300_plat *plat = dev_get_plat(dev); + int i, type; + + type = dev_get_driver_data(dev_get_parent(dev)); + + if (type != PF5300_TYPE_PF5300 && type != PF5300_TYPE_PF5301 && + type != PF5300_TYPE_PF5302) { + debug("Unknown PMIC type\n"); + return -EINVAL; + } + + if (type == PF5300_TYPE_PF5301) { + for (i = 0; i < ARRAY_SIZE(pf5301_reg_data); i++) { + if (strcmp(dev->name, pf5301_reg_data[i].name)) + continue; + *plat = pf5301_reg_data[i]; + + return 0; + } + } else if (type == PF5300_TYPE_PF5302) { + for (i = 0; i < ARRAY_SIZE(pf5302_reg_data); i++) { + if (strcmp(dev->name, pf5302_reg_data[i].name)) + continue; + *plat = pf5301_reg_data[i]; + + return 0; + } + } + + pr_err("Unknown regulator '%s'\n", dev->name); + + return -ENOENT; +} + +static const struct dm_regulator_ops pf5300_regulator_ops = { + .get_value = pf5300_get_value, + .set_value = pf5300_set_value, + .get_enable = pf5300_get_enable, + .set_enable = pf5300_set_enable, +}; + +U_BOOT_DRIVER(pf5300_regulator) = { + .name = PF5300_REGULATOR_DRIVER, + .id = UCLASS_REGULATOR, + .ops = &pf5300_regulator_ops, + .probe = pf5300_regulator_probe, + .plat_auto = sizeof(struct pf5300_plat), +}; From patchwork Mon Sep 30 03:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 1990714 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=tXYmwdfy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XH5GD0P1tz1xsq for ; Mon, 30 Sep 2024 12:52:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD59988E6E; Mon, 30 Sep 2024 04:52:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.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=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="tXYmwdfy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9925A88DBA; Mon, 30 Sep 2024 04:52:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,SPF_HELO_PASS,T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazlp170110001.outbound.protection.outlook.com [IPv6:2a01:111:f403:c200::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9091F88E1C for ; Mon, 30 Sep 2024 04:52:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hjEG2R27zynR9F5t9C8+9kHXRtJ0+VVUcCJzLt/V3QTu6Q/A2khJPOkSl0iK/4PLgRoNRiN6Gsl22k2ifzrn5shxfMrOm49YrOFk2lRo9HGfBVEvCa/Dmmb0X/+dOS48/Jrsek/dgwqbHvlZkhA1N+a1L/3P5i/BSoAbEKhOt8lAuv9f2orBprhAGse1Ju6E/h72f073tHYgkaSEq8Rx4vvn2l6DTtORtY4NIkNh8cNjD3CkNzGRVdgfaGq4zzm6w4w3qsZhL4BsRs2dkyEsAAkZ7J0p/s+eSBIlqh95BuP9Cgz7Cvga5rilUJ7aXlWwnYuTGkzOUDOWZoiNmWt9KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=upqG9JAkU004nZ3uFh2EJIvdkRVex+/urhvVgnLTYaw=; b=My9nLpQSfbEHiRvVjNYAs0Bm6bNKX5a5QualfkJXCLESQxfhOtE3SLn3a2sz5knDK/SH4orxPzCU2NshhYZ/vCPqJ+L3fdvOJB0/dox7NHrVR+36Rp2BypBr3gLGRAGS+pxx3og1L2iNl//PtZRnJJhuWYqNlOeixwLJuJIWrnsVFRmkw4N7IC6Pm8912invMQwABOzgiSFYxfKv3La8a1sFQRGrmOKCtShUhYoacgHVXe8BgnB7BcTZskoBmYYAXJfPGXrhqC//3/KooOrSPqHMD98kd2WchKv0oRO0JZj1MLHdGJucHLQKkhsmNMujMwzBVSg8N1+xlF0ASY5NMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=upqG9JAkU004nZ3uFh2EJIvdkRVex+/urhvVgnLTYaw=; b=tXYmwdfybTMLYDUU9GyEii4XQVFO5nrGFwVoZPlMVlCjrKAUwFdL1Q5KAfX/vwCc2gZK1AfbVxmD4sIa0HJhMnW8Yq6cr97ts+XpzycatPxai4xRxZP6rxgxofRN8dBuQhsGDAj6FfKFXh3t+MVij+5DmxvemH9nLY1YPG79/Z/CAIMBEwbkyThElvwekorxGFI9JdJLhhLrOG6j6sMl6+mLdE2MMLYOmzrvJ7wM3ckCzw9J+/inoK4apoiFxIK6P1EKJoGKmMiQMlHhCbGGc8rRHV/aecRHBEHCPJqER/Q8OdmJhprYXzMgj59JCCZH+kvg1OfsMhNnVUzu4HImkQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by DU2PR04MB8712.eurprd04.prod.outlook.com (2603:10a6:10:2df::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 30 Sep 2024 02:52:08 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7982.018; Mon, 30 Sep 2024 02:52:08 +0000 From: "Peng Fan (OSS)" To: festevam@gmail.com, sbabic@denx.de, u-boot@lists.denx.de, Tom Rini , Jaehoon Chung Cc: uboot-imx@nxp.com, Joy Zou , Ye Li , Peng Fan Subject: [PATCH 3/4] power: pmic: ADD PMIC PF9453 support Date: Mon, 30 Sep 2024 11:55:29 +0800 Message-Id: <20240930035531.27079-3-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240930035531.27079-1-peng.fan@oss.nxp.com> References: <20240930035531.27079-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SI2P153CA0003.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::20) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|DU2PR04MB8712:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b352770-18d2-490f-d687-08dce0fae016 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|52116014|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: ULCt8k8zKEjieVA3exn87Dv9t8xqeLYaGve+u0HxGohNh8BgayIIXEnYJQ+8rRibN10aG6SuyEoQSQ+RJ3M8/HOcHbkNHBLFMJUYQ6kudkt9u4vwlLyPZugtjOfzjOrd2qkfH3oUa9EZoW7U5iiV4rrht2NJUy0+1PZphpaFijNMIFGyIOr8DJii0kb3TLsfU6ramC2VJCeCfQp323YX8xtfDuMWoMUvpZOSgMH6te1teOz8jYrcby4wqj0d/E78I+1628oD7/3+xhWv337ESApCTzAy6IHxMGgPsluDSbgO7Ry9xb6+G37XtpowtkNo9uVhzx49oyySujAbZDGqrnJ0QSN8HrqJ+Iikyy8gAYM/yukU742AaMB2kp5Nm+bcpSPvbfFAjoAwJjR/3uoac5iQ217pD2SNnyoVRDBydTJJ1kj3/coyRR4DXTSMJngAKCX8LyAzHUDrMYT6p5Xv0iX96q4j8MsMnTPzlO5Atyi0j0CZ6hjmXVInlM/M/ZGeHJL0f19pSW0w3UAtLHB8d5LWRzGUVY4RXzA7RMyjgAL/shMsl8zXsU1DETsrhvaJOBXJqFg23cpuctEJLEbWvD7pjmp2octGI/ddvEb5Ax7lRCEdSxC5ecAZCKvr424+h8emv96sSsSYYE4S+l+sbI4oobee8whchcaF7lSdosWsjO3zC8QpVw3Hm8vdmHnZBfwNACBxB4whmsPPjAIPLEK2LyfFSj+k0d8VUM9VDys6LReQcxr7zQug+SfezBR03OVtoMUcg4ftWdM2YcJIwVv4UAMwpcbkWdgkPYpt7tvkpvoMFJ/XIYsKBSeT3j3YdFFoWE5V6nZictSyeOE0WbTMMeDR/9OsGdPKjPx9FFacPUQ9EIX4TKKLVrZ5MHIpZebjYOIa6ATfksjcncpWng+qudfe0SxJWTh9AmasoL8RbR/wnCYthe/zDM0WuuHZz09XVe889cwgTgJI/zmnMM6VIwmzWlhIqCczs9Tah7cTweySKJMyRAKNj8y7PnKP+E+E0AXjv+301l+/35quyNI8B+YlWi2ucpRIxbhCtqkf+kivMOQ5S5R1KlFt2XoBgww0d5LAg21Nv9J39brQnXB7HYePOw9oO4Z4VGVwKgu0+JQuHT2A0a1p+gOW1PgWVe8VkVrVmqFsWI098hE1j/PTbJGCzf6jbtENIrXavmQLrz0POxbp5+7b+rbFAVc+21RtQfxahr6hEqRopJ6Na1OWIAsLUriRXB6AwDbfKfZZQ0CENgf4zxAhb030e/GwqxYmHrWvt2ukNLBCtHfWnCvdSMk6vhlR5n45aggpiUX6NGeqEtYW54yXojxPGrb2vcJGIrQtgK1rsB8iwWnh/w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8459.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(52116014)(366016)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SH4aIdv1eD1kUzt+CRMd7Zqt+D7Uu1N/cwK5G8nc7hUkKVMXXIVdQgZsRIWrLxAfhHzouJNPqzFUgxsDz9UmqDSdJ1l8aI0lbp6sX4I7x0hsB3ydX5JroPP+AOPImwKlfrciBMo3sERzN5EekKG6F4vaaYGLEDs2CXfhJ0fKZ5ibN9Uk0BvzTy7LGenX+M9bRwq14cxGin2dUEohIl8eDoMUc38XF2sccniYqmCx0jS9m++bNKIcK2YsWYxsIx2CfbsdFvfmI0evo7ScRSumpA7Ip3MNHWzr39U52IeussnYeE0r2xx1ViLd/Ewe2sLdYFnhjqOai3f6PIZCDwoT9/iR9XlxKbusqafa81ujKwo6sg3m7gac8X0sEcNusNo0bvK3rKwerzBD1VsaFmb9SlhIgM3l1Nasd283bb6YihnQX2NMAuV0rwfvCW5uD+z2X2ZKljBEe4pkA4UknJRMGhTDrNBJfwlhGgjHjreY5Me7cVe398UL17uIutv5EmNrhfVJe3WRJuBsbieWeb+neVfBdYYhhVpB0LTMoSBeI4CQGIRVOFeuSHjGZVuE83UeYFAPLqROfn91ji3+9ptsx5oDtX0lkly87I5CsAubJrg+cO04IFsF2qM3o4PUkpKIoYK32wdMVvzZlAQiokDfqwV0WVSP8A/FxgZ94Fz+lLU62JmqgwY083jZXzkYjI8a3mrz4t1xsBXg5YgjNCRnW/pPaFqKvkYCAfbcHlJqvd303BbfwmsCFTLo4m4VwzwMQ6IJYf+UnhcMvKxULvrD0xq4yGeGgQZshPiLEPNvH7vKCKBEkB2SsUK+OgEVwOq9mK9ZsYMdYvcYTunpiz6hL2EI39PdHC7Qk1U8glNGXNvT+V1p4V48r+eT4HjI6QQY83ehjMyc6hI4h1UycNEOMQMUROzLUqasenLGEvWNatn7BrcQtYTeHAE/u0gc0QNXMpSUIGr15DEQWRvbeFwYiG0F9YmM92SqObKnnXPXZBVWGCat65j1nst9rbVBldVxwm1vsMN5Ul3jp6Trq3J7H9WgJUAunzG3duPReYNYZ/6wwz5WK4tO9ipQrEFTYaPIYcy/yEzV80SLB6Nb3l1c+TXI5x47X6xxTjA0qGIiIwMDoPFHWE3yXKRI1QbC5UUFi0xW6faEnl/HwW0xhCMJoTZ95ak2PlabU4UEfaji2I/LtSHFQsdJgKvgGN/VST0IGeCAkx9mcnip5Rq/tLZ/i6nQfg2bGKd8t25ke0tO7ZDptL3pDRkvM09GAZ8o4mKqxQTS/I7Mr+3LFXH2tzQCLUk9SOaTUOYKqOaEbckkZh6aTZAK+usAFkVJSbhTItHiZihGsCxxU0dMLaDO5X+ZujdbapjRBMqmfE6e+jPxoOWbXOvQ4gR7y6PMwHA6EBmnb8JRb5Y4Xqopac7ooHJZ8r/DuYWcdgyw7oeARFLgkGYULzXX6SeigmtmWZlEP329McaSNICdqaaoSeziy9O23s2qULT6QiIsBAP/xdP7q0j48p6zz3naJQD6ZWhNfmECcx7eCzK3OceXldV3v0Z7UV78R/zM1lv7gNNvWMwyvqYytRuyb17k5y4Rgg0XYoSO X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b352770-18d2-490f-d687-08dce0fae016 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 02:52:08.7352 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rJ4o2ZlMAQhoNDFquokxbuWX686b29XK2gpNpFYDRp9/vtf96B4hxnAgwu/m5SU1jIyyy1VShUBgVqvqs/h7Ig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8712 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 From: Joy Zou Support NXP PMIC pf9453. Reviewed-by: Ye Li Reviewed-by: Peng Fan Signed-off-by: Joy Zou Signed-off-by: Peng Fan --- drivers/power/pmic/Kconfig | 15 ++++ drivers/power/pmic/Makefile | 1 + drivers/power/pmic/pf9453.c | 173 ++++++++++++++++++++++++++++++++++++ include/power/pf9453.h | 71 +++++++++++++++ 4 files changed, 260 insertions(+) create mode 100644 drivers/power/pmic/pf9453.c create mode 100644 include/power/pf9453.h diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig index 420c4099937..42e405901de 100644 --- a/drivers/power/pmic/Kconfig +++ b/drivers/power/pmic/Kconfig @@ -171,6 +171,21 @@ config SPL_DM_PMIC_PCA9450 This config enables implementation of driver-model pmic uclass features for PMIC PCA9450 in SPL. The driver implements read/write operations. +config DM_PMIC_PF9453 + bool "Enable Driver Model for PMIC PF9453" + depends on DM_I2C + help + This config enables implementation of driver-model pmic uclass features + for PMIC PF9453. The driver implements read/write operations. + +config SPL_DM_PMIC_PF9453 + bool "Enable Driver Model for PMIC PF9453 in SPL" + depends on SPL_DM_PMIC + depends on SPL_DM_I2C + help + This config enables implementation of driver-model pmic uclass features + for PMIC PF9453 in SPL. The driver implements read/write operations. + config DM_PMIC_PF0900 bool "Enable Driver Model for PMIC PF0900" depends on DM_I2C diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile index 74ace69daf5..7cee4ee0582 100644 --- a/drivers/power/pmic/Makefile +++ b/drivers/power/pmic/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o obj-$(CONFIG_$(SPL_)DM_PMIC_MP5416) += mp5416.o obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o obj-$(CONFIG_$(SPL_)DM_PMIC_PCA9450) += pca9450.o +obj-$(CONFIG_$(SPL_)DM_PMIC_PF9453) += pf9453.o obj-$(CONFIG_$(SPL_)DM_PMIC_PF0900) += pf0900.o obj-$(CONFIG_$(SPL_)DM_PMIC_PF5300) += pf5300.o obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o diff --git a/drivers/power/pmic/pf9453.c b/drivers/power/pmic/pf9453.c new file mode 100644 index 00000000000..893a7771d0e --- /dev/null +++ b/drivers/power/pmic/pf9453.c @@ -0,0 +1,173 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static const struct pmic_child_info pmic_children_info[] = { + /* buck */ + { .prefix = "b", .driver = PF9453_REGULATOR_DRIVER}, + { .prefix = "B", .driver = PF9453_REGULATOR_DRIVER}, + /* ldo */ + { .prefix = "l", .driver = PF9453_REGULATOR_DRIVER}, + { .prefix = "L", .driver = PF9453_REGULATOR_DRIVER}, + { }, +}; + +struct pf9453_priv { + struct gpio_desc *sd_vsel_gpio; +}; + +static int pf9453_reg_count(struct udevice *dev) +{ + return PF9453_REG_NUM; +} + +static bool is_reg_protect(uint reg) +{ + switch (reg) { + case PF9453_BUCK1OUT: + case PF9453_BUCK2OUT: + case PF9453_BUCK3OUT: + case PF9453_BUCK4OUT: + case PF9453_LDO1OUT_L: + case PF9453_LDO1OUT_H: + case PF9453_LDO2OUT: + case PF9453_LDOSNVS_CFG1: + case PF9453_BUCK2OUT_MAX_LIMIT: + case PF9453_BUCK2OUT_MIN_LIMIT: + return true; + default: + return false; + } +} + +static int pf9453_write(struct udevice *dev, uint reg, const uint8_t *buff, + int len) +{ + bool is_pro; + u32 val = PF9453_UNLOCK_KEY; + + is_pro = is_reg_protect(reg); + if (is_pro) { + if (dm_i2c_write(dev, PF9453_REG_LOCK, (uint8_t *)&val, 1)) { + pr_err("write error to device: %p register: %#x!\n", dev, reg); + return -EIO; + } + + if (dm_i2c_write(dev, reg, buff, len)) { + pr_err("write error to device: %p register: %#x!\n", dev, reg); + return -EIO; + } + + val = PF9453_LOCK_KEY; + if (dm_i2c_write(dev, PF9453_REG_LOCK, (uint8_t *)&val, 1)) { + pr_err("write error to device: %p register: %#x!\n", dev, reg); + return -EIO; + } + } else { + + if (dm_i2c_write(dev, reg, buff, len)) { + pr_err("write error to device: %p register: %#x!\n", dev, reg); + return -EIO; + } + } + + return 0; +} + +static int pf9453_read(struct udevice *dev, uint reg, uint8_t *buff, + int len) +{ + if (dm_i2c_read(dev, reg, buff, len)) { + pr_err("read error from device: %p register: %#x!\n", dev, reg); + return -EIO; + } + + return 0; +} + +static int pf9453_bind(struct udevice *dev) +{ + int children; + ofnode regulators_node; + + regulators_node = dev_read_subnode(dev, "regulators"); + if (!ofnode_valid(regulators_node)) { + debug("%s: %s regulators subnode not found!", __func__, + 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) + debug("%s: %s - no child found\n", __func__, dev->name); + + /* Always return success for this device */ + return 0; +} + +static int pf9453_probe(struct udevice *dev) +{ + struct pf9453_priv *priv = dev_get_priv(dev); + unsigned int reset_ctrl; + int ret = 0; + + if (CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(DM_REGULATOR_PF9453)) { + priv->sd_vsel_gpio = devm_gpiod_get_optional(dev, "sd-vsel", + GPIOD_IS_OUT | + GPIOD_IS_OUT_ACTIVE); + if (IS_ERR(priv->sd_vsel_gpio)) { + ret = PTR_ERR(priv->sd_vsel_gpio); + dev_err(dev, "Failed to request SD_VSEL GPIO: %d\n", ret); + if (ret) + return ret; + } + } + + if (ofnode_read_bool(dev_ofnode(dev), "nxp,wdog_b-warm-reset")) + reset_ctrl = PF9453_PMIC_RESET_WDOG_B_CFG_WARM; + else + reset_ctrl = PF9453_PMIC_RESET_WDOG_B_CFG_COLD; + + return pmic_clrsetbits(dev, PF9453_RESET_CTRL, + PF9453_PMIC_RESET_WDOG_B_CFG_MASK, reset_ctrl); +} + +static struct dm_pmic_ops pf9453_ops = { + .reg_count = pf9453_reg_count, + .read = pf9453_read, + .write = pf9453_write, +}; + +static const struct udevice_id pf9453_ids[] = { + { .compatible = "nxp,pf9453", .data = NXP_CHIP_TYPE_PF9453, }, + { } +}; + +U_BOOT_DRIVER(pmic_pf9453) = { + .name = "pf9453 pmic", + .id = UCLASS_PMIC, + .of_match = pf9453_ids, + .bind = pf9453_bind, + .probe = pf9453_probe, + .ops = &pf9453_ops, + .priv_auto = sizeof(struct pf9453_priv), +}; diff --git a/include/power/pf9453.h b/include/power/pf9453.h new file mode 100644 index 00000000000..fd9617edc2c --- /dev/null +++ b/include/power/pf9453.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + */ + +#ifndef PF9453_H_ +#define PF9453_H_ + +#define PF9453_REGULATOR_DRIVER "pf9453_regulator" + +enum { + PF9453_REG_DEV_ID = 0x00, + PF9453_OTP_VER = 0x01, + PF9453_INT1 = 0x02, + PF9453_INT1_MSK = 0x03, + PF9453_INT1_STATUS = 0x04, + PF9453_VRFLT1_INT = 0x05, + PF9453_VRFLT1_MASK = 0x06, + PF9453_PWRON_STAT = 0x07, + PF9453_RESET_CTRL = 0x08, + PF9453_SW_RST = 0x09, + PF9453_PWR_CTRL = 0x0a, + PF9453_CONFIG1 = 0x0b, + PF9453_CONFIG2 = 0x0c, + PF9453_32K_CONFIG = 0x0d, + PF9453_BUCK1CTRL = 0x10, + PF9453_BUCK1OUT = 0x11, + PF9453_BUCK2CTRL = 0x14, + PF9453_BUCK2OUT = 0x15, + PF9453_BUCK2OUT_STBY = 0x1D, + PF9453_BUCK2OUT_MAX_LIMIT = 0x1F, + PF9453_BUCK2OUT_MIN_LIMIT = 0x20, + PF9453_BUCK3CTRL = 0x21, + PF9453_BUCK3OUT = 0x22, + PF9453_BUCK4CTRL = 0x2e, + PF9453_BUCK4OUT = 0x2f, + PF9453_LDO1OUT_L = 0x36, + PF9453_LDO1CFG = 0x37, + PF9453_LDO1OUT_H = 0x38, + PF9453_LDOSNVS_CFG1 = 0x39, + PF9453_LDOSNVS_CFG2 = 0x3a, + PF9453_LDO2CFG = 0x3b, + PF9453_LDO2OUT = 0x3c, + PF9453_BUCK_POK = 0x3d, + PF9453_LSW_CTRL1 = 0x40, + PF9453_LSW_CTRL2 = 0x41, + PF9453_REG_LOCK = 0x4e, + PF9453_REG_NUM, +}; + +int power_pf9453_init(unsigned char bus, unsigned char addr); + +enum { + NXP_CHIP_TYPE_PF9453 = 0, + NXP_CHIP_TYPE_AMOUNT +}; + +#define PF9453_UNLOCK_KEY 0x5c +#define PF9453_LOCK_KEY 0x0 + +#define PF9453_EN_MODE_MASK 0x3 +#define PF9453_BUCK_RUN_MASK 0x7f +#define PF9453_LDO1_MASK 0x7f +#define PF9453_LDO2_MASK 0x3f +#define PF9453_LDOSNVS_MASK 0x7f + +#define PF9453_PMIC_RESET_WDOG_B_CFG_MASK 0xc0 +#define PF9453_PMIC_RESET_WDOG_B_CFG_WARM 0x40 +#define PF9453_PMIC_RESET_WDOG_B_CFG_COLD 0x80 + +#endif From patchwork Mon Sep 30 03:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 1990715 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=yLE3Ko1Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XH5GQ5gDVz1xsq for ; Mon, 30 Sep 2024 12:52:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1BD1F88E2D; Mon, 30 Sep 2024 04:52:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.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=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="yLE3Ko1Z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BA26088EE3; Mon, 30 Sep 2024 04:52:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,SPF_HELO_PASS,T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazlp170110003.outbound.protection.outlook.com [IPv6:2a01:111:f403:c201::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A2A0988E1C for ; Mon, 30 Sep 2024 04:52:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=abK6/X/oFC1QcQUhGAo2/lN7A7s4T65Cf9Z0NmSLNInsX2kRq1X00GrqxZDJ2oiCgUxpQQFXR/+6cK7GLDCzgD32eL5YQQRNzxHQzOJ4HjPMd2lqNdPgGk62RXR17L78frZZBefW+XSW+XKaoWagXSiwFceyZXpf2sv9jwU5ilI3dqQGczWOwbDkdQsuZkHaCNq6d7WyLk3U+dDlH7fncaokfw+HpO+eKEmFLyd2MrWNxp+CEd5VQP27fmQm/5mM+AOz/iDAnAk+jhASJQs98OSavfuNZXTr7eSYcC8jpCPA2ii5xcKFox+reBSLyuE5+z2auOZSqlx8crxgMTnGNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nKxduSYnonLrEAegFU+mhdUyX6uLcoDLv83GAbJ9RxE=; b=ADozEkF0mX1je/uOqAm4p4S8j4xqsvVSdg99akaFrD8HZVMvTRjNO7iKIFV/GVqowa/2agDwgtXtv0xxBfmrgjbCyaenWQWbrdehpiM+ZZvE7UjjqKgcbR4ntUScJbcw5Vgl+7G9uPJrvcuyFBUNfesEWtsbg1T4C8ct2qwP0d3xdTZiKQbfRTylf/YWCvYpVM/8OjD1ZRwnBM7OxBL5kimybil9dg3EPEEp0ikRaE2Qd+PIJ2gK4YVtKIhX5BAK9Wce9IYQRwGHExxWmROLbLd+PvkfFS/DYmCuZX3asClPv5ip5SDXUp6g10LMKMhDmn+0nVkd9vfLsqqilt37+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nKxduSYnonLrEAegFU+mhdUyX6uLcoDLv83GAbJ9RxE=; b=yLE3Ko1ZnqHYRj9+PsON1RAr7YbhzQEuiv7eYLuV4w67Doc7n0B8LrmdxuQuq81E7wD2JK9itiWbct/vhnfnS/mXyCTEqK74rIHEIzbXf/4RD5q7XvQaoL3WLCVVgNyZ6et5HNqOujX4p2LVTNZ8WZjfqNGi+jKD3Q5pG/rEiAvw97TMWIMM6qIkMa6eBAuH8slGXcYJTlBL794I/in4BzAJtigmVAFTCljHzVrD5J39PjFffvfn8MQRFXY8oo3YTGZeGDvG6MKZM6xLQ+6rgIsi7Y2GFBU6eb+oDmeBP+xtHn9cFpaq+UNRDOx2fSY/XkzeHSuNgSkC9lNHHVs4hg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by DU2PR04MB8712.eurprd04.prod.outlook.com (2603:10a6:10:2df::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 30 Sep 2024 02:52:12 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7982.018; Mon, 30 Sep 2024 02:52:12 +0000 From: "Peng Fan (OSS)" To: festevam@gmail.com, sbabic@denx.de, u-boot@lists.denx.de, Tom Rini , Jaehoon Chung Cc: uboot-imx@nxp.com, Joy Zou , Ye Li , Peng Fan Subject: [PATCH 4/4] power: regulator: ADD PMIC PF9453 support Date: Mon, 30 Sep 2024 11:55:30 +0800 Message-Id: <20240930035531.27079-4-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240930035531.27079-1-peng.fan@oss.nxp.com> References: <20240930035531.27079-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SI2P153CA0003.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::20) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|DU2PR04MB8712:EE_ X-MS-Office365-Filtering-Correlation-Id: 429c43bc-606a-456d-71c8-08dce0fae24b X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|52116014|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: ApbyF6QnwGRJZbl3A3SL837CJTr/P9M7GkKcdbKFkA9CboSZOPaquVOEr5+Mv2+++4mKHi8U/w8s1oNHIsO8Yg7jn8gMLrxxeZSfMl/ZZen715ByXZJJaf5v/KSl5LX5efvQHx01kbo8u6r8jr8oXwfX5H6UcAXpcPpsMO3BCg+IqwhwIkUZT2tDbqfr8Afsp4s5VLQvFRMyVxuGUMsQ2TQPRrq7i0ynh1hYV1WGoW9VBLruHzy5KpCKRfCn+j/KegHb54ffIVKD/VOe7APmMscvqLvegkJdtThLUlp9VWr5AmX78J0BT3A9Ysgh8CtsXnnAt38cPVCxEMYEH+fZv8WqIc3PFQ7z/lT3QRk+O7Ntv/zRMWxFnJmyKS+AhXzy48RdJ4Q+yE2ig9TrEzFIXj5RyEO/HB7nNVvI4uQKxW83KajGw3hrnR0mPTNrMLIUlJ3fUkaWc2MzSrXuBtre9QQHu6wx67kDnswF2jZeOOfxSrduEPK2sKJg8ADxImkSzipV2zgQmYFRM/+eiX63zpdKPfGUNhZ/NOh4ah/hf1pYACflY/p5gEMkDR4uF1uKPTpQU5IHu5Q0Gbp43smxR51HfVC075dyrHubGNYqRLvuEKLoNq6M3xZxDU5OOupqMjYhKsCyWv0ZQEDhj0gIgI7G19kxu0XpOwmWoP1bHJucpQcq1O9wlVLfLO8+Y981GQ43Ndod44m7woK7O5fVHynmVTmAvpjcIBz64fT6LgzcUWRgDIVmewIaZe++tR0HFwOk54SNOQz6VOxCMrLB0lIwVNOIpLxhDRZ2qxbJRRVpR4fnQ0XxN2E1WOhbVyrms5iK9OgVWBNrrAJ1+/7a6tR8uDmaObWS4ni/2POHgrTCk8Icwk38goA34PSpEZNh1wRdL+5wELx3uNqYt6WzPs62ayQ/lnMjph64kF5Qa2wUHJVJRpiYwPf3vL5pHyIX9/oP5BJ9r21qWy6nE8DRnWOZwiNVrtHJ1KjKkokEJBQGGrFhs+Qd/lEDHiMwAqfD2VtmbO63V+ZivG9oKlXl6X4klCq7sidbICV8vF0JK/EDvRHEzTXX2qRmLYxeTIMwdPi385CyP3OPR49WEV8RvDzVkD6SQCUIQ7Pv0cibMdnQurO1WqFZFuFJHzAdm7Gqr7BQSW13NHN7r1+/NVVwwKs/hoPkKYl3mXjnxkBiHlkrnWD+LiX0yMpZLRG/KDhti6wboLouo8MpBZe12AS1dPa1HcxLDbltpinE/M0PaaBuK6V9fFkcLsB626D2ZHccvVxVjtiTGmVMJVSWiBoCOKAWAWAaEf9Y0zHRdbhtqxw/Bck8OgNVorUELtv2ZF48AW6H32PJWrm2RP+bgCTNFw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8459.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(52116014)(366016)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p+ybhteq15scPzHj3JKUc0dl4EGMTBLl/QyCyP3rvqkkTHNBEkR8IIXEq3TgC/HcJ5A7Ps9S7IwLI1S+Pei/hlDp2FqeWdFPn6HuLk4q+/z3YqvW/bd9KlD/1x0LPhGRNgIdGvAIQlsytYqxGKcG1AsbF9kENveg25aeJ767OUDLpRH+J7s+VhPJbtA8sdtHJzyStkBqSQvAwcwRXsuvZAfPhHGKP6iuCLqrzQITbOntAoCPERHZsahUfcsU5mwOIA9+ZHPeFsSIhMhn33kNVefxTTHVJWuOfjj2a9DGO3AiaBWk6y2IoYArAn7t1kb3oMf7BBmMoKbuyWicQIPebbIm2ehZpk8xhBfm9skwDWfJ6kkhcMfXbwru7KXO1kXTWBGOwj0CJr/Parr6nGUsTOvUiY8tL5OGbxM3yjT0NHD8+4576x8/iXWiJFaihAZHiHyeiYqZ+gHloewtOz4bghw0c7u2UcMx6jOJz2s7Oz6GN8D7Z0ffZZ6m5PhULpV057VRTao8nCUBQgDCxrgFA7zVGVRPprp5kHvjvOkeIwxEvtlf48k3L5ZqB//g0gm/gC5U/U9xev2ML2d2c8a8fJNqpZiCbxyoQ0xixsToCb/GaVWJlogZOVrz5sMUCCErSQ1z6sXwmXn0eKvl9gjhbT6xyRAVqPa5tOl6af0o/3TUu1EGcipCjAiR3TaKcDhgHOitNME86S9V1CMzEp4CDM8ohWquZhWoQZiAJj7ZQjbcnla8NXhhlHGPBcBIO9FswNRStS2/iHpkDtwte8loMOCc2apgK9soWt7lhmzWJ2vK8MMl1KmzgTpoEZBIpJK09KtfmQ/BW7o66liMkNRBJBvkS+zdeAol3ZFRCd0BLCGstE0VdD1of67CZ7FPsoi2bGYN4DtrVbT3bvcX0ATOQBNqoRrp8yzpE8vmGF/SG4t0cVmU13W7Bis5DLLo6jDkEt5fBLQRXWuBEIHnXYwUn5zjImkRFRsgKtG0BtgWeXq72G0rp8dQS3CDyzvCHofnuvfVVeInRppfyGub//84pr+Ull9W9/dc0UqXH5bGPiM6PDHh0Efbow38pjbI34AjVWSdXx5e+awh7OBNkvfkZsHbt/f3XxmiCn36eo4KwZQhp5YGuDLF2Gl3zVYRwFnLwPCTL7vpXuHneYqyw2Wo2K1JGPb2wNgjWzEhtUjk+2bhLUh2ig180BdVi6nrjG3gd4vR8BG9QqH1aZkncKVWUTWJIH1PM8J4YpjtNrcJdXcu5g0J8Re/2UI1OgiC3/7fAJcDDbX5mTVEhKt92Lj1czfaxq6xg636PlsecGjueeHts0xPiNCJxZuCate56vR4d6CakRqBezHDjSdBzK0Qna9xn5ystALfBO4jN+qw52TvO1sf6UV2kAN3pCSnbJwevbey6XBmFSPd+Pb4OPwieoG+uY2McgQRdHwh0VdUI0Pyt+JL8RiWdSI+4kyKHCEmSGl8ZsiyHB5VEngZ0iaNgcxKWp8Ccd8/2y7NqGSqafrWPMsMJZ0zCuRuCsq5Lrjl7sW3dgUTdKoF4cMxv9s+K2FB0OJ34zUqybYETM+Gze3fS9+P7XTOIUszATIsYACP X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 429c43bc-606a-456d-71c8-08dce0fae24b X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 02:52:12.5814 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DE05iQbLdiF++YWyOKojR093eZ4u+zTmiOn6ll+rKCbDSFiqvyWstq3Y4+i/XdgT1du9uIILmRfJIZM6pOsJrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8712 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 From: Joy Zou Add regulator support for NXP PMIC pf9453 for imx91 qsb. Reviewed-by: Ye Li Reviewed-by: Peng Fan Signed-off-by: Joy Zou Signed-off-by: Peng Fan --- drivers/power/regulator/Kconfig | 15 ++ drivers/power/regulator/Makefile | 1 + drivers/power/regulator/pf9453.c | 256 +++++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 drivers/power/regulator/pf9453.c diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index 69dfb07df50..4aa963e745c 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -96,6 +96,21 @@ config SPL_DM_REGULATOR_PCA9450 This config enables implementation of driver-model regulator uclass features for regulators on ROHM PCA9450 in SPL. +config DM_REGULATOR_PF9453 + bool "Enable Driver Model for NXP PF9453 regulators" + depends on DM_REGULATOR && DM_PMIC_PF9453 + help + This config enables implementation of driver-model regulator uclass + features for regulators on NXP PF9453 PMICs. PF9453 contains 6 bucks + and 5 LDOS. The driver implements get/set api for value and enable. + +config SPL_DM_REGULATOR_PF9453 + bool "Enable Driver Model for NXP PF9453 regulators in SPL" + depends on DM_REGULATOR_PF9453 && SPL + help + This config enables implementation of driver-model regulator uclass + features for regulators on ROHM PF9453 in SPL. + config DM_REGULATOR_PF0900 bool "Enable Driver Model for NXP PF0900 regulators" depends on DM_REGULATOR && DM_PMIC_PF0900 diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile index 7a580d45b72..9e9a4da6217 100644 --- a/drivers/power/regulator/Makefile +++ b/drivers/power/regulator/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_DM_REGULATOR_NPCM8XX) += npcm8xx_regulator.o obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_BD71837) += bd71837.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PCA9450) += pca9450.o +obj-$(CONFIG_$(SPL_)DM_REGULATOR_PF9453) += pf9453.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PF0900) += pf0900.o obj-$(CONFIG_$(SPL_)DM_REGULATOR_PF5300) += pf5300.o obj-$(CONFIG_$(SPL_)REGULATOR_PWM) += pwm_regulator.o diff --git a/drivers/power/regulator/pf9453.c b/drivers/power/regulator/pf9453.c new file mode 100644 index 00000000000..d11c69c33e6 --- /dev/null +++ b/drivers/power/regulator/pf9453.c @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * NXP PF9453 regulator driver + * Copyright 2024 NXP + */ + +#include +#include +#include +#include +#include +#include +#include + +/** + * struct pf9453_vrange - describe linear range of voltages + * + * @min_volt: smallest voltage in range + * @step: how much voltage changes at each selector step + * @min_sel: smallest selector in the range + * @max_sel: maximum selector in the range + */ +struct pf9453_vrange { + unsigned int min_volt; + unsigned int step; + u8 min_sel; + u8 max_sel; +}; + +/** + * struct pf9453_plat - describe regulator control registers + * + * @name: name of the regulator. Used for matching the dt-entry + * @enable_reg: register address used to enable/disable regulator + * @enablemask: register mask used to enable/disable regulator + * @volt_reg: register address used to configure regulator voltage + * @volt_mask: register mask used to configure regulator voltage + * @ranges: pointer to ranges of regulator voltages and matching register + * values + * @numranges: number of voltage ranges pointed by ranges + */ +struct pf9453_plat { + const char *name; + u8 enable_reg; + u8 enablemask; + u8 volt_reg; + u8 volt_mask; + struct pf9453_vrange *ranges; + unsigned int numranges; +}; + +#define PCA_RANGE(_min, _vstep, _sel_low, _sel_hi) \ +{ \ + .min_volt = (_min), .step = (_vstep), \ + .min_sel = (_sel_low), .max_sel = (_sel_hi), \ +} + +#define PCA_DATA(_name, enreg, enmask, vreg, vmask, _range) \ +{ \ + .name = (_name), .enable_reg = (enreg), .enablemask = (enmask), \ + .volt_reg = (vreg), .volt_mask = (vmask), .ranges = (_range), \ + .numranges = ARRAY_SIZE(_range) \ +} + +static struct pf9453_vrange pf9453_buck134_vranges[] = { + PCA_RANGE(600000, 25000, 0, 0x7f), +}; + +static struct pf9453_vrange pf9453_buck2_vranges[] = { + PCA_RANGE(600000, 12500, 0, 0x7f), +}; + +static struct pf9453_vrange pf9453_ldo1_vranges[] = { + PCA_RANGE(800000, 25000, 0x0, 0x64), +}; + +static struct pf9453_vrange pf9453_ldo2_vranges[] = { + PCA_RANGE(500000, 25000, 0x0, 0x3a), +}; + +static struct pf9453_vrange pf9453_ldosnvs_vranges[] = { + PCA_RANGE(800000, 25000, 0x0, 0x58), +}; + +static struct pf9453_plat pf9453_reg_data[] = { + PCA_DATA("BUCK1", PF9453_BUCK1CTRL, PF9453_EN_MODE_MASK, + PF9453_BUCK1OUT, PF9453_BUCK_RUN_MASK, + pf9453_buck134_vranges), + PCA_DATA("BUCK2", PF9453_BUCK2CTRL, PF9453_EN_MODE_MASK, + PF9453_BUCK2OUT, PF9453_BUCK_RUN_MASK, + pf9453_buck2_vranges), + PCA_DATA("BUCK3", PF9453_BUCK3CTRL, PF9453_EN_MODE_MASK, + PF9453_BUCK3OUT, PF9453_BUCK_RUN_MASK, + pf9453_buck134_vranges), + PCA_DATA("BUCK4", PF9453_BUCK4CTRL, PF9453_EN_MODE_MASK, + PF9453_BUCK4OUT, PF9453_BUCK_RUN_MASK, + pf9453_buck134_vranges), + /* LDOs */ + PCA_DATA("LDO1", PF9453_LDO1CFG, PF9453_EN_MODE_MASK, + PF9453_LDO1OUT_H, PF9453_LDO1_MASK, + pf9453_ldo1_vranges), + PCA_DATA("LDO2", PF9453_LDO2CFG, PF9453_EN_MODE_MASK, + PF9453_LDO2OUT, PF9453_LDO2_MASK, + pf9453_ldo2_vranges), + PCA_DATA("LDOS_NVS", PF9453_LDOSNVS_CFG2, PF9453_EN_MODE_MASK, + PF9453_LDOSNVS_CFG1, PF9453_LDOSNVS_MASK, + pf9453_ldosnvs_vranges), +}; + +static int vrange_find_value(struct pf9453_vrange *r, unsigned int sel, + unsigned int *val) +{ + if (!val || sel < r->min_sel || sel > r->max_sel) + return -EINVAL; + + *val = r->min_volt + r->step * (sel - r->min_sel); + return 0; +} + +static int vrange_find_selector(struct pf9453_vrange *r, int val, + unsigned int *sel) +{ + int ret = -EINVAL; + int num_vals = r->max_sel - r->min_sel + 1; + + if (val >= r->min_volt && + val <= r->min_volt + r->step * (num_vals - 1)) { + if (r->step) { + *sel = r->min_sel + ((val - r->min_volt) / r->step); + ret = 0; + } else { + *sel = r->min_sel; + ret = 0; + } + } + return ret; +} + +static int pf9453_get_enable(struct udevice *dev) +{ + struct pf9453_plat *plat = dev_get_plat(dev); + int val; + + val = pmic_reg_read(dev->parent, plat->enable_reg); + if (val < 0) + return val; + + return (val & plat->enablemask); +} + +static int pf9453_set_enable(struct udevice *dev, bool enable) +{ + int val = 0; + struct pf9453_plat *plat = dev_get_plat(dev); + + if (enable) + val = plat->enablemask; + + return pmic_clrsetbits(dev->parent, plat->enable_reg, plat->enablemask, + val); +} + +static int pf9453_get_value(struct udevice *dev) +{ + struct pf9453_plat *plat = dev_get_plat(dev); + unsigned int reg, tmp; + int i, ret; + + ret = pmic_reg_read(dev->parent, plat->volt_reg); + if (ret < 0) + return ret; + + reg = ret; + reg &= plat->volt_mask; + + for (i = 0; i < plat->numranges; i++) { + struct pf9453_vrange *r = &plat->ranges[i]; + + if (!vrange_find_value(r, reg, &tmp)) + return tmp; + } + + pr_err("Unknown voltage value read from pmic\n"); + + return -EINVAL; +} + +static int pf9453_set_value(struct udevice *dev, int uvolt) +{ + struct pf9453_plat *plat = dev_get_plat(dev); + unsigned int sel; + int i, found = 0; + + for (i = 0; i < plat->numranges; i++) { + struct pf9453_vrange *r = &plat->ranges[i]; + + found = !vrange_find_selector(r, uvolt, &sel); + if (found) { + unsigned int tmp; + + /* + * We require exactly the requested value to be + * supported - this can be changed later if needed + */ + found = !vrange_find_value(r, sel, &tmp); + if (found && tmp == uvolt) + break; + found = 0; + } + } + + if (!found) + return -EINVAL; + + return pmic_clrsetbits(dev->parent, plat->volt_reg, + plat->volt_mask, sel); +} + +static int pf9453_regulator_probe(struct udevice *dev) +{ + struct pf9453_plat *plat = dev_get_plat(dev); + int i, type; + + type = dev_get_driver_data(dev_get_parent(dev)); + + if (type != NXP_CHIP_TYPE_PF9453) { + debug("Unknown PMIC type\n"); + return -EINVAL; + } + + for (i = 0; i < ARRAY_SIZE(pf9453_reg_data); i++) { + if (strcmp(dev->name, pf9453_reg_data[i].name)) + continue; + *plat = pf9453_reg_data[i]; + return 0; + } + + pr_err("Unknown regulator '%s'\n", dev->name); + + return -ENOENT; +} + +static const struct dm_regulator_ops pf9453_regulator_ops = { + .get_value = pf9453_get_value, + .set_value = pf9453_set_value, + .get_enable = pf9453_get_enable, + .set_enable = pf9453_set_enable, +}; + +U_BOOT_DRIVER(pf9453_regulator) = { + .name = PF9453_REGULATOR_DRIVER, + .id = UCLASS_REGULATOR, + .ops = &pf9453_regulator_ops, + .probe = pf9453_regulator_probe, + .plat_auto = sizeof(struct pf9453_plat), +};