From nobody Wed Feb 5 22:49:35 2025 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2059.outbound.protection.outlook.com [40.107.21.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E56F41F3D5D for ; Tue, 21 Jan 2025 14:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737470319; cv=fail; b=qEAfwjXiX86CokEcsjWIqsvqa1IT5OtirtmF54nSPMdqDeHzHTmavn5my1w5gFvGbHrz8C5v0RSwhVf7dXOPWhMEow8OddJZ+FqMkx+9Xo/KXSGLoCcZ9HrmjGjzbHWxTKpsFBHsZ199g2r8+X45Vl/EnVXzF1eK1UfXAC8Ei24= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737470319; c=relaxed/simple; bh=oddCAm/izbxUpTjrDgTDhbWtdHMcmxKkwmykuqKdoaQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:To:CC; b=tcqVsybeVJ1KL33BZKdRSKb++JRhLEcxt1H0GKZ11i95J4St/ZVxSZSNst8tLpn73hCaqKS1fqtGGrXP0AudhP5R3KAt6+97Np6yPnUHlNqn6CxYkQLGMWPxK37bDZ1kymaZRVr2QUJHNceW+LUJXtz0KgtVOWtRysO/kZDUwbQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=axis.com; spf=pass smtp.mailfrom=axis.com; dkim=pass (1024-bit key) header.d=axis.com header.i=@axis.com header.b=sDmn7dBC; arc=fail smtp.client-ip=40.107.21.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=axis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=axis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=axis.com header.i=@axis.com header.b="sDmn7dBC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uNvY6FYfJqp4s+eSsEdjiSCakgf0KV+U/PnWX+0aZi+WZU1IGGzyZ81nKNzDcF7i1UoRcEteXKPvuNcXzQ/LeC/JZBlEPWqDJLKHpxykv0gFHf8ev3V0XJ6U1QcRBAuLBWF1L5mVfKS1gy28ZjcMhauxlNWsZExqqaSM+xwKvQMOoDbDQMPyLLf+OBwiddDJKP/MeRZAwCoJQO8e9p5x/J2Eg80WyCEA5rd8MLZhfVtEekZATjBzdV3FJlPzBj94oP4fayMi59m1a/b5fUtKddEdbuF2DOd4sEGHlYXjFW1lRX9Az3JqpMZojfEdRdrR5I/4kifX7XZ12b+AmV2vaw== 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=U4fgVvxWfCYucPdhBQZqvD916IQQwy/C73BqMRPO7Y0=; b=hBBISg3xRkXHNMmhfbN1Bmi1NLPa+N2n6zR3nue1GqWKi98UUXCwNdomZ77/BotTzbDG/klTSTN7k7j5EA7R1yeKChfXABevTnh1UxmLno+B8Xa+yroyeQIiCnddbXzdgcn0EC5iGUUj/MVoYrrZcbaQZ34UUt4vCDR84ar6TTxMQ2X9tmFFfGw1ueLfl2qvtzXF1RFR2IEuTeN5yynixnQFgWD4Ph5Ikvg+1McIMNwFupsqsQgfFa/2TC8nWy7/DNAR3YbotlWwNBzkjN6FwAlrrg/AWcAdVZXqXOvUPk4dY5G5aCc9dfLPY3BtU51BkWSIw4v5uvMRFeeaoq4Xtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 195.60.68.100) smtp.rcpttodomain=gmail.com smtp.mailfrom=axis.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U4fgVvxWfCYucPdhBQZqvD916IQQwy/C73BqMRPO7Y0=; b=sDmn7dBCKChrQpnmWVWayJTWSd9aTEL+fPTEKWiuDd4jG7oIKb0tApII5kYUH/dW6NIeT7JK2dpe9lVnbQiX73yN4+4RTTZn6s9fTZodbvedPCbZcYklnWBB+IzMEM2rxFZnOda9QwEzIbs15AhGGb+lwCexr5cdNefcz5slYA4= Received: from AS9P251CA0018.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:50f::16) by PA4PR02MB7136.eurprd02.prod.outlook.com (2603:10a6:102:101::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.22; Tue, 21 Jan 2025 14:38:31 +0000 Received: from AM3PEPF0000A795.eurprd04.prod.outlook.com (2603:10a6:20b:50f:cafe::5e) by AS9P251CA0018.outlook.office365.com (2603:10a6:20b:50f::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Tue, 21 Jan 2025 14:38:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=axis.com; Received-SPF: Pass (protection.outlook.com: domain of axis.com designates 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; pr=C Received: from mail.axis.com (195.60.68.100) by AM3PEPF0000A795.mail.protection.outlook.com (10.167.16.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8377.8 via Frontend Transport; Tue, 21 Jan 2025 14:38:31 +0000 Received: from SE-MAILARCH01W.axis.com (10.20.40.15) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Tue, 21 Jan 2025 15:38:29 +0100 Received: from se-mail01w.axis.com (10.20.40.7) by SE-MAILARCH01W.axis.com (10.20.40.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Tue, 21 Jan 2025 15:38:29 +0100 Received: from se-intmail02x.se.axis.com (10.4.0.28) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server id 15.1.2507.44 via Frontend Transport; Tue, 21 Jan 2025 15:38:29 +0100 Received: from pc59765-2437.se.axis.com (pc59765-2437.se.axis.com [10.85.128.12]) by se-intmail02x.se.axis.com (Postfix) with ESMTP id 6B86E21E; Tue, 21 Jan 2025 15:38:29 +0100 (CET) Received: by pc59765-2437.se.axis.com (Postfix, from userid 18763) id 6A5492069E40; Tue, 21 Jan 2025 15:38:29 +0100 (CET) From: Jonas Andreasson Date: Tue, 21 Jan 2025 15:37:50 +0100 Subject: [PATCH v2] regulator: TPS6287X: Use min/max uV to get VRANGE Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20250121-tps-fix-v2-1-50cc4d0f1635@axis.com> X-B4-Tracking: v=1; b=H4sIAD2xj2cC/z3Myw6CMBCF4Vchs7amU0CjK9/DsOhllFlISYc0G NJ3t7Bw+Z+cfBsIJSaBe7NBoszCcaphTg340U5vUhxqg9GmQ4NGLbOoF6+KrKcQgtOtt1Dfc6I 6H9JzqD2yLDF9Dzjjvu5GrxH7v5FRoTIuXF2Ll07fwsOuLGcfPzCUUn5/tJ04nQAAAA== To: Liam Girdwood , Mark Brown CC: , , Jonas Andreasson X-Mailer: b4 0.13.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF0000A795:EE_|PA4PR02MB7136:EE_ X-MS-Office365-Filtering-Correlation-Id: 03a43802-b9b0-469b-19a2-08dd3a29471e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026|13003099007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZmJ4KzNZcGplL2dZTXlDVkh4VzNtWG5iOFBDU0Z0OGwwWFZZKytRdkR3MGtl?= =?utf-8?B?Z1h3dUZ2YVVsMk5IcG5ka1RGbnF3Kzlqekp1TmF5d3NlMTMvd0xIb0p3L2VI?= =?utf-8?B?QmVTK252dDczZGNWWDNwcm9GRno4Zy9SSzhtWDlhbDJuYzJvcVN0TU4zWW5q?= =?utf-8?B?UnZqMGpic3FQM0U5bVhFeTBhQmpWM3hEZGlodjRQUnVmNGlZUGE2UzZWbU9u?= =?utf-8?B?TWdnNXpoU0xtUE5hTmtNMmlibHo4NUtKUFZ3eEVtOUlYM3VRZ0EwK2dOUytU?= =?utf-8?B?aDduS05RdVkydys0UklkLy9CZ0tqSnQxL1NFSTg5UzJsdmFHOUViMDBZK3Vm?= =?utf-8?B?WUhscU0rei90Uk5xVkw2azZXZVdoWFpSNHUxSldkU3M3ZGp0T1hyaDdOMGU0?= =?utf-8?B?RVN1WldHV09NRmlFajdyQ0ZtNm93VER3bDlCbnFFejEwWXk4ZkFKVW5ZUlBl?= =?utf-8?B?QnN6TDFqdmpWMFpNRG9WV3dZL2FzcHdJSWNmbjBaTytTbDVPeGk5elZ6Kzlx?= =?utf-8?B?YnlLTUFuN3FuNWZxNXBHRXlsN3pueCt1dzZsbHVkeURXeTR1bGVEYncyZTJR?= =?utf-8?B?STUrVlR6WXQxYW9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= =?utf-8?B?Y2hGckYwUExqM0lUMCtrZzRDWDF4NjlicjVwcjhYZ2xJU2lqaE51VDZtZVE4?= =?utf-8?B?a3lwUGh3OG9pRDEwczV0dDRlam1pN2RnZjcyemhkcjJQWGZsZzdRNFl5ZGtz?= =?utf-8?B?ZFlrUDU3azd0RkErOXBpYUkwRmR0VUNYRHVZRVB4am5NOFJwa2dqSUU0Q1VZ?= =?utf-8?B?NVBOVm14Z0c5VTdJa3dpVkFRWlI2VUZXeG54Y0lJUnY4blN0MFlZbjhWM1Iz?= =?utf-8?B?SUFRM1VZSHF5cXU1VEErTStYcHRKbVFGR3F6QWhidi9vQUhSa0R6eit2Wndu?= =?utf-8?B?VDRCanRMUXBaUXlUUmx3Nk56cE80cnd4elhxRVFxTHpBR1ZsNVNZQlRDdFJq?= =?utf-8?B?Q1JMM1NqVTJKK1c5WlZvblNNWmxaVTZVUzYvNVFwSjRTUDdyUHlwNFRLQlpv?= =?utf-8?B?aURyUlliWUFwa0Q4RzBlSXcrQXh0SjJkNm1KdmhLRHBtRnhkR3FiRUs3T2hV?= =?utf-8?Q?1kbEp8Az14OezRnSfHCC3rsHQPDFc4=3D?= X-Forefront-Antispam-Report: CIP:195.60.68.100;CTRY:SE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.axis.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2025 14:38:31.7391 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03a43802-b9b0-469b-19a2-08dd3a29471e X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af;Ip=[195.60.68.100];Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR02MB7136 Changing voltage might ignore slew rate and cause a current surge. With current implementation the driver will get the regulator to change the voltage range used during run time. According to communication I have had with Texas Instruments, this is not intended, since the Dynamic Voltage Scaling in the hardware is only designed to work within a voltage range. The current implementation will therefore ignore the slew rate that is defined in devicetree when the voltage range is changed during use. The current implementation will always select a voltage in the most accurate range that can reach that voltage even though multiple ranges are able to reach that voltage. There are 4 Voltage ranges with the following reach: 0b00: 0.4-0.71875V (1.25mV step size) 0b01: 0.4-1.0375V (2.5mV) 0b10: 0.4-1.675V (5mV) 0b11: 0.8-3.3V (10mV) This in practice means that a change from below to above 0.71875V will use the smallest range(0b00) for the values below and the second smallest range(0b01) for the voltages above (Up to 1.675V). I have timed how long it takes to go from below 0.71875V to above. The increase was 100mV which, with the slew rate set to 1250=C2=B5V/=C2=B5s. Th= is in theory should take 80=C2=B5s to do. With the current implementation, it takes 10=C2=B5s on my hardware. Doing the same test with the slew rate set to 5000=C2=B5V/=C2=B5s, which should take 20=C2=B5s, also only takes 10=C2= =B5s to do on my hardware. Not only is this not in line with the technical specification for the regulator. It also causes a current surge. Which when calculating the output current, as described in the technical specification, compared to what I could observe on my hardware the real output is ~1A higher (~1.2A) than what I calculated it to be(~0.2A). I tested also transitioning from a bigger to a smaller range, and the results were the same. Instead, let's limit the voltage range to a single one, which is in line with the intended use of the regulator. This is done by looking up the minimum and maximum requested voltage specified in devicetree. Signed-off-by: Jonas Andreasson --- Changes in v2: - Removed unnecessary goto statement - Added missing const qualifier in function parameter - Link to v1: https://lore.kernel.org/r/20250115-tps-fix-v1-1-2bd7b316409d@= axis.com --- drivers/regulator/tps6287x-regulator.c | 57 ++++++++++++++++++++++++++++++= ++++ 1 file changed, 57 insertions(+) diff --git a/drivers/regulator/tps6287x-regulator.c b/drivers/regulator/tps= 6287x-regulator.c index 97f5ce138548..c0f5f0a186a3 100644 --- a/drivers/regulator/tps6287x-regulator.c +++ b/drivers/regulator/tps6287x-regulator.c @@ -44,10 +44,35 @@ static const unsigned int tps6287x_voltage_range_sel[] = =3D { 0x0, 0x1, 0x2, 0x3 }; =20 +static const unsigned int tps6287x_voltage_range_prefix[] =3D { + 0x000, 0x100, 0x200, 0x300 +}; + static const unsigned int tps6287x_ramp_table[] =3D { 10000, 5000, 1250, 500 }; =20 +struct tps6287x_reg_data { + int range; +}; + +static int tps6287x_best_range(struct regulator_config *config, const stru= ct regulator_desc *desc) +{ + const struct linear_range *r; + int i; + + if (!config->init_data->constraints.apply_uV) + return -1; + + for (i =3D 0; i < desc->n_linear_ranges; i++) { + r =3D &desc->linear_ranges[i]; + if (r->min <=3D config->init_data->constraints.min_uV && + config->init_data->constraints.max_uV <=3D linear_range_get_max_valu= e(r)) + return i; + } + return -1; +} + static int tps6287x_set_mode(struct regulator_dev *rdev, unsigned int mode) { unsigned int val; @@ -91,6 +116,28 @@ static unsigned int tps6287x_of_map_mode(unsigned int m= ode) } } =20 +static int tps6287x_map_voltage(struct regulator_dev *rdev, int min_uV, in= t max_uV) +{ + struct tps6287x_reg_data *data =3D (struct tps6287x_reg_data *)rdev->reg_= data; + struct linear_range selected_range; + int selector, voltage; + + if (!data || data->range =3D=3D -1) + return regulator_map_voltage_pickable_linear_range(rdev, min_uV, max_uV); + + selected_range =3D rdev->desc->linear_ranges[data->range]; + selector =3D DIV_ROUND_UP(min_uV - selected_range.min, selected_range.ste= p); + if (selector < selected_range.min_sel || selector > selected_range.max_se= l) + return -EINVAL; + + selector |=3D tps6287x_voltage_range_prefix[data->range]; + voltage =3D rdev->desc->ops->list_voltage(rdev, selector); + if (voltage < min_uV || voltage > max_uV) + return -EINVAL; + + return selector; +} + static const struct regulator_ops tps6287x_regulator_ops =3D { .enable =3D regulator_enable_regmap, .disable =3D regulator_disable_regmap, @@ -100,6 +147,7 @@ static const struct regulator_ops tps6287x_regulator_op= s =3D { .get_voltage_sel =3D regulator_get_voltage_sel_pickable_regmap, .set_voltage_sel =3D regulator_set_voltage_sel_pickable_regmap, .list_voltage =3D regulator_list_voltage_pickable_linear_range, + .map_voltage =3D tps6287x_map_voltage, .set_ramp_delay =3D regulator_set_ramp_delay_regmap, }; =20 @@ -130,8 +178,14 @@ static int tps6287x_i2c_probe(struct i2c_client *i2c) { struct device *dev =3D &i2c->dev; struct regulator_config config =3D {}; + struct tps6287x_reg_data *reg_data; struct regulator_dev *rdev; =20 + reg_data =3D devm_kzalloc(dev, sizeof(struct tps6287x_reg_data), GFP_KERN= EL); + + if (!reg_data) + return -ENOMEM; + config.regmap =3D devm_regmap_init_i2c(i2c, &tps6287x_regmap_config); if (IS_ERR(config.regmap)) { dev_err(dev, "Failed to init i2c\n"); @@ -143,12 +197,15 @@ static int tps6287x_i2c_probe(struct i2c_client *i2c) config.init_data =3D of_get_regulator_init_data(dev, dev->of_node, &tps6287x_reg); =20 + reg_data->range =3D tps6287x_best_range(&config, &tps6287x_reg); + rdev =3D devm_regulator_register(dev, &tps6287x_reg, &config); if (IS_ERR(rdev)) { dev_err(dev, "Failed to register regulator\n"); return PTR_ERR(rdev); } =20 + rdev->reg_data =3D (void *)reg_data; dev_dbg(dev, "Probed regulator\n"); =20 return 0; --- base-commit: adc218676eef25575469234709c2d87185ca223a change-id: 20241212-tps-fix-eacedddb03ca Best regards, --=20 Jonas Andreasson