From nobody Wed Feb 5 20:31:34 2025 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2040.outbound.protection.outlook.com [40.107.20.40]) (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 4249E248171 for ; Wed, 15 Jan 2025 09:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736934942; cv=fail; b=d+UmwBetHE6o2itnWcP1aM/EyMP4yBr4FcexVrQr/iQcW00OPA2284IwEO61vXKEnnkxX46U+m4pSapXrj7mfLzuCrqjIjh3iF6b2oqEopduYcXd5lh/yNgTTbVlAlnn28BKSd14vgxMt8e1r2EkkYN2skEJQY0hdxUnKLDLUbc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736934942; c=relaxed/simple; bh=fCyE6vJxbjtaUpQUcRxljelj39g9oi28nCp6zlU80vg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:To:CC; b=HSpPFw3ktrXUCU2PSPcd37vImOvQsOng4LubCBqj07SpXf2X44GyY89ats0RFwps0DxUJ4GicPhHvsKDbYjVk2F8SYpCgAZNfqslt2hRXto3lsQyWVyvC4Lc/6ypjzRfkNnSzQstD8zCYLGuxDtnMOkoLktmJwLW3JOJWwRrBYk= 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=HYiPlz+Q; arc=fail smtp.client-ip=40.107.20.40 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="HYiPlz+Q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iYwIPB/lqfV1PKJ+j/VVtRWPAu3lf/pf0HdKc2sRYHlGR8OFeJ7813QCjONmYkx3qJFa50NUajppmQN2WmPxZcVC1AzKKYuZBFpK9N7+WFTCu1oA4Mp+FASFEq/ZqlAECVw8fSZ34rG5R+9JTj6Q4H+9qcQbel66wSLp4HZ3yuIgaf28qfQXNuQrCY6e7Vv6YAdzQLGTtwGOwKERcRGhpo8jZfun4bu5HUnOGJn9g47ckmLBgV9IlW2pQMrCiAN8ue/O/2/xy6OdgSJzaqAYHXXgdhFwZde8WfrDFCd2jKqQc61VQ9cPyklc8nwHJ+hC5+z6Z2LVR4FbwIzusCfx0w== 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=kMex9SvP5JScul28V1oRqEl8QbsBB1IXdpumFN+3xt8=; b=eewgvIo+U//LlVQAs8WFgngzhnAsMaB6pLQ0ViNKDkZ2xtKsrFYGLwinssRDRVlz4LdOfc5dcWctrp5YrJeGYBJ4cLeK4NKrJROCfNQWoC+/O/XV0ZdsfUJrKMc+ycY9TVOAbS2bgsaMQaKIvh9UcTeV2Wt/TLEkmXf4DAdOXo2EBW3Mb6wef5drXuERQjjnFuYgCB760Et7w4gO8txXpjH/FYyWqiiZDJFBWo8waNy8Q9Hw+HfR3li6t4IwQvbLcaU4TCmEgfe6d8/+O2e2RaF4VNPBxsxMyqWvlv2G7/nUukCVLy21MtTTY9zmkU4cNqZd/QaVZPKqTwkUZ0AbsA== 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=kMex9SvP5JScul28V1oRqEl8QbsBB1IXdpumFN+3xt8=; b=HYiPlz+Q8WEDWM1PB0n5u0vsuddAbd/TV3jV0Cx/FgcUEzfFQmFK4ss9dKg8x8Ex/r8mWPlucGBS4MMJMs/M28RZsURz9iWWFu2UT/jEpw8EFbEkLxoPg+vivgX3+V6mo3jTtfVE7fHdRYchmOHodJuV9EpIkZAwKO5llrhXA90= Received: from DUZPR01CA0234.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b4::25) by AS2PR02MB10054.eurprd02.prod.outlook.com (2603:10a6:20b:641::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Wed, 15 Jan 2025 09:55:33 +0000 Received: from DU6PEPF0000B61B.eurprd02.prod.outlook.com (2603:10a6:10:4b4:cafe::ca) by DUZPR01CA0234.outlook.office365.com (2603:10a6:10:4b4::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.13 via Frontend Transport; Wed, 15 Jan 2025 09:55:33 +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 DU6PEPF0000B61B.mail.protection.outlook.com (10.167.8.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Wed, 15 Jan 2025 09:55:33 +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; Wed, 15 Jan 2025 10:55:32 +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; Wed, 15 Jan 2025 10:55:32 +0100 Received: from se-intmail01x.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; Wed, 15 Jan 2025 10:55:32 +0100 Received: from pc59765-2437.se.axis.com (pc59765-2437.se.axis.com [10.85.128.12]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id 7D2211B7; Wed, 15 Jan 2025 10:55:32 +0100 (CET) Received: by pc59765-2437.se.axis.com (Postfix, from userid 18763) id 7BA9221EB41E; Wed, 15 Jan 2025 10:55:32 +0100 (CET) From: Jonas Andreasson Date: Wed, 15 Jan 2025 10:55:22 +0100 Subject: [PATCH] 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: <20250115-tps-fix-v1-1-2bd7b316409d@axis.com> X-B4-Tracking: v=1; b=H4sIAAmGh2cC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxNDI0Mj3ZKCYt20zArd1MTk1JSUlCQD4+REJaDqgqJUoDDYpOjY2loAaur dJ1kAAAA= To: Liam Girdwood , Mark Brown CC: , , Jonas Andreasson X-Mailer: b4 0.13.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU6PEPF0000B61B:EE_|AS2PR02MB10054:EE_ X-MS-Office365-Filtering-Correlation-Id: f7c5de3d-c584-4ca8-767a-08dd354ac0ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?M2p2enBvdDQxQVcrVG1ZK3FSbGhNOHlYWVMrUXJMeFR6Vk90a2g0cS9yZmR2?= =?utf-8?B?eTNiZWZadURGeVNMck5KRTUzQVg2Zm9VK2VRd0d4V2VzaXVjblJVWk90Mk1v?= =?utf-8?B?ZHlJTjQxTDVHTzlaTmxRMkU2c3VXbm9oZDhxVTA5UDVBY28xVHROek9QZGN1?= =?utf-8?B?SnJWbjU4RWhRVysxNWJwL2huUVp1OXNzcmE0RXcvZVNoZUVMVC9OaVgxb2Zr?= =?utf-8?B?TGIvVmZiaFhVYjFaS1daNFlHdGEzaE8zenhwMzVaeTFoUkFUQjZKWW4rR05F?= =?utf-8?B?b3F2enFIV2JCc3Q4SUlKWG9qVGhFZ1psSXpmcXdVSHBENVlXMTEvQklBd3Fs?= =?utf-8?B?VXM1YTYvRGY2RzFoT2pBZVJvcktQSHh2U3IzRk0vS1NGT1hmTysvTEhMVUFq?= =?utf-8?B?RHV2THVqUVBnOGhZT0tWZkdWN1B3N3ZTMG54SHJmZFBzSWJZaElGTkkzcGRl?= =?utf-8?B?cU0yaFFmS1d6cVNENWxTeU5WdkVqU3NYSk16NFJaanBiK2cyY053QjdQRTQ4?= =?utf-8?B?RkNDQVVLTUZLOXVZQnlSOVpNV3NVUkY5NGJTQUQvUG5Xb1k4UCszR3hyZGQx?= =?utf-8?B?TVJuTmMzVGdVeVFoT04xdVRoOUg1N1VZRmQ2YUFhVzl5clZPZ3Z4QzBVdHJw?= =?utf-8?B?b2tLbUp3QTl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R3?= =?utf-8?B?UElQbzVqdG0yUDNaTFZ1RHBWeVU5RzZ6enhDTElQaW5RSVJCZ1JMTml6MTd2?= =?utf-8?B?QzJwTGE1bklvOS9pcFhTNmR2ZjJZWUlhL3YzeFA5K21IVkVrOHY5eHRKK0Ft?= =?utf-8?B?MTdhZVlIQnh6RTViNm5ROVY0QlQzTWtpNlhCR2ZseUI2cGkwczZ3V0kyTlJi?= =?utf-8?B?ZEl6Q3phZjBBbzJ4THYvN2duR2VsU2NuTlpkYVpadkxaWHl1VjhTQUVJTlBC?= =?utf-8?B?Z24vUkFRLzBTenVaU1kyZ3pteDFzejUvenNST0RacC81UzU1L1ZKK3RYQ0d4?= =?utf-8?B?WWxoYlJMaUdvQTZWaDdScTFRL29NSjVPNHdBTU11dnFRR2NybzR3dFhxK0ZQ?= =?utf-8?B?ZXg5ays0cDRXcmRNa2RvZE05RndDK3pDemVEWm9rSTIrSm9QcHVGdUljZmxN?= =?utf-8?Q?N9fnT3Qsk9skkKWIW2e7uebKl/vEDY=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)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2025 09:55:33.6624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f7c5de3d-c584-4ca8-767a-08dd354ac0ef 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: DU6PEPF0000B61B.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR02MB10054 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 --- drivers/regulator/tps6287x-regulator.c | 60 ++++++++++++++++++++++++++++++= ++++ 1 file changed, 60 insertions(+) diff --git a/drivers/regulator/tps6287x-regulator.c b/drivers/regulator/tps= 6287x-regulator.c index 97f5ce138548..439ccb5f3b06 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, struct reg= ulator_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,31 @@ 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) + goto fallback; + + 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; + +fallback: + return regulator_map_voltage_pickable_linear_range(rdev, min_uV, max_uV); +} + static const struct regulator_ops tps6287x_regulator_ops =3D { .enable =3D regulator_enable_regmap, .disable =3D regulator_disable_regmap, @@ -100,6 +150,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 +181,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 +200,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