From nobody Fri Nov 29 10:21:04 2024 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 591BE17A922 for ; Fri, 20 Sep 2024 16:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850851; cv=none; b=pv7/VMN5Uazu/uTV7gBFH586oWAJaAE4Uu9+lH5XpNgCmZ7ZLRiOQpbqKA5bPLQ6f6RpobLqUv5Qv1cnmwrwEsxWgpsgHoQFoGg8Ee0BAoLtjMXJM77FydbIo4AnV2GThXFJPYHkYPTunb4cVF/pSP9CxU7GZ8Z7+kXfEzR2NFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850851; c=relaxed/simple; bh=kWmDB7nojGoj156gSMkRuwtglVlXdhF+7Ma/4bI48yE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qKx6UJtgTjEcS8Tho6ZYBRn6V5QJyNZEQKvAtPrcJYlYgGNeltSJ6AWGGy43jPOAovUqVReDTnj3I691Gww5HCXQT+3lvMMym94GMujFUxOC9CLJO3a+OD1+gQ4YU5dSd1yALOmcsQl2vrnVmbICt9ZkRn2MjxOxplvlz14QUC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=tJ9pNwkn; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="tJ9pNwkn" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso21050625e9.2 for ; Fri, 20 Sep 2024 09:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726850848; x=1727455648; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=j2l/YT0SVwM2BKGIIcvG36vkjoblImIQN3qbMI+AN58=; b=tJ9pNwknkdzccDeLhxn+N4AGuBfk8VylLBxb1rdRVVXSaf9Gz8in5TN8NL9Rt8wTt6 0Zf7C+gfNZEFkUM2kdCKSp7AiaXcsD31+LCQPY4LsSW9oEcLdraDOAkw3agsg9gUSoyN b0QgqIlWHPlqISwoI+OmBHF+bHLoahFIyfel4tuIu6WCfe3X5NE5RtlMZoUhVnVPALdY MllSM1rPMiel40/RUlGi0u2hQC+AQmuNvPyWpvK84E+lehGaJRE9NFMYR1NAOvDCTJ6O woJG0JEtm1t03of37vEwT1vjIZeTTeq5YJ2UCrFTX+YoEjwgyJt2hOmG6ppvQtc8yOFM pHuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726850848; x=1727455648; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j2l/YT0SVwM2BKGIIcvG36vkjoblImIQN3qbMI+AN58=; b=m4pVG09DDil1HTvn+F1CNZomQCu5rdUNlAvaMnDNE1VTnrH31Oo1GScCMBMfFwroJk txrwwIkcbQNMgo1EsPTtIqxOcLstFaXrpVFrA45MUUzNNzxjdcYzTURY2tXTeY+N+lz2 6cs7V+CEFYMGvC9ldQkT9LjN8jhHZ9MqAMgwHI+CUt1O9rxytGPpF+PlEWhAsQVKcpcE fpgCqVw6Y17408OpVSVe00+QX4dShiMcr4CyY+/7EvPCLvJH8wT4DYNDZoSN2BH+zrvE EAOEE2J+nzlgNmf0P8UuB/Mva6U3e90fHRIhuT2SzYkqfKb4bjUobx9bj+D6k6zGoslu erXA== X-Gm-Message-State: AOJu0YzUwbyeUJahnRlz9YaZud9lNa6kobBt4AomuhY/fF4eSa3W4ssl yh29usqrs6KEayQHGn/RNeXLHEEGX8cyHL18a89PntR5QkiTYIz243sh0Z/2c9s= X-Google-Smtp-Source: AGHT+IGJkUkTnhqw6d3RXsoe5pIlfc7IWhH06fn71XCVrA7qhdEYf5C1n8nmKLARkeSlarPrXdjEiw== X-Received: by 2002:a05:600c:3486:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-42e7c159dcdmr25826755e9.1.1726850847740; Fri, 20 Sep 2024 09:47:27 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:8e69:83a7:a29a:ba83]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-378e7804476sm18172250f8f.90.2024.09.20.09.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 09:47:26 -0700 (PDT) From: Jerome Brunet Date: Fri, 20 Sep 2024 18:47:02 +0200 Subject: [PATCH 1/5] regulator: core: add callback to perform runtime init 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: <20240920-pmbus-wp-v1-1-d679ef31c483@baylibre.com> References: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> In-Reply-To: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Jerome Brunet X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1560; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=kWmDB7nojGoj156gSMkRuwtglVlXdhF+7Ma/4bI48yE=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm7acZjTiI6NYDcqe/A6lJd9wte11A1ks5RZgzs RVe7T000QOJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZu2nGQAKCRDm/A8cN/La hW52D/4yGNHNYs/Bd+K9A1vBnJCVbqpRd3EMOUqpTxOkIOnUFDHhmUoSfOSSwh7QKsXytEH0GLZ 66qRDZPV+81S+h2gnrSaGBhUy9ymbKLIsi6VyKUvINvVFInEdqjb0isi9b4Y1AkA8YmULf2bdbh 6n6ly35NtH449jTH5b+c1rX9D5urlYZzhzvNTdmybs6YS4KLDJrVMkRGhzIPfn+0l7LLXtjqN0j TCYDyXvHVb7CX1KGoIgFqYQelQLA4rNNDO1JSM8uYQOgquyCS6b7tUONQqoh1qh8yg3bNpU18fr DUQqVze8T1r25olUFlu0AmGmcpwdI7mf/d+iSrB29HHhsud58QL9T7of6VPE6dfxKB6zq67VEKT 7XbY/1OVnaH/1pzKHQdDErG7dL3O8uWUp4xU+Cu8bEtCUGBLR9FJ5Y1cNffJw2A8irD/qppM8vg KN6bnWOjhbjLHa71unWmaYBufmbgC46Md8ckZ3/9lA57He1Ka6wbkz828zqWqCn3iGrAlJh2BXM 4LId6A2tDWJtrKOAST8PtMeowzHVesROoizRgXAhF7p3TPCJWtq6CjDts+ImL33+Q4ZVeizI1xd JsSBKhX77pQ6AcUW8F3WGVQaq1NfNiQlJ/ciQPANrnnTNVsKZ29PE+nlUIfUDtVs+yf2EOMIVIJ 8mX63BgY3kjQVDQ== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Provide an initialisation callback to handle runtime parameters. The idea is similar to the regulator_init() callback, but it provides regulator specific structures, instead of just the driver specific data. As an example, this allows the driver to amend the regulator constraints based on runtime parameters if necessary. Signed-off-by: Jerome Brunet --- drivers/regulator/core.c | 6 ++++++ include/linux/regulator/driver.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1179766811f5..4c90ab5ad876 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -5747,6 +5747,12 @@ regulator_register(struct device *dev, goto wash; } =20 + if (regulator_desc->init_cb) { + ret =3D regulator_desc->init_cb(rdev, config); + if (ret < 0) + goto wash; + } + if ((rdev->supply_name && !rdev->supply) && (rdev->constraints->always_on || rdev->constraints->boot_on)) { diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/dri= ver.h index f230a472ccd3..d2f4427504f0 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -365,6 +365,8 @@ struct regulator_desc { int (*of_parse_cb)(struct device_node *, const struct regulator_desc *, struct regulator_config *); + int (*init_cb)(struct regulator_dev *, + struct regulator_config *); int id; unsigned int continuous_voltage_range:1; unsigned n_voltages; --=20 2.45.2 From nobody Fri Nov 29 10:21:04 2024 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DC8017E472 for ; Fri, 20 Sep 2024 16:47:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850853; cv=none; b=qEVKF7g/VQdafLH8caQ3sx0/FxOE5FyUP/+GDWFVG2vUibo1leUWvYwQCH7ZKI/9sDZqijzR1c+JLkv7ezjlHPKVa7K9K+SCgJc923JI4CX0fUwtb72TL0M5poT/qXcAhrJUzTQz7HDHI3H2jUZ9FaLKSctjEkxf0qTA3/wrtfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850853; c=relaxed/simple; bh=3p8epjwY1oVoba554UVp1ZMZNkGwAgCoLLhC2PSJKOM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ApU1wSVgbNcMViqj3vVP6lurA76lAbF4HD1C7DmhqkOtVq0lZudATvCqEH+kowLKQkrtYyrUF3lm9d3q+am5h6Z79LiwHA9PHP2gcQHXOz9v835tRk7Q6rUFYhzRptcP2c7eawDj1f1ZMRcMDgRiT8Fyd24RjJ/TbzridCz5DDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=uL3z3rkq; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="uL3z3rkq" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-374ba74e9b6so1707588f8f.0 for ; Fri, 20 Sep 2024 09:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726850849; x=1727455649; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=auS1Nijn3/MM+vVwjmIp4Kgr8RxjQxso8G43GcLWcTA=; b=uL3z3rkqZcPgS5yRPjXj3VG1n5M6ku0OzbGm3pi4wJPQqx8ImhdipFi0KcRVYn3GbJ D/peGKRY+1cEpl+xT0jKDLDFigZEqeEQY7mMHlySv6VgOoShfe/ykrRde/pEa2L+CqSF OvuaaYyUM/AtE18BMvRYPNpcoH+irBRYcV7vqPGR2dhwIkEemMf3Q9FtZoQhIUJ3CLwS mhrHCx3AzMjg/BpdCaCMDHZZgCaU8n6DK2ALH45TpouZS0arZDgOeHEpXK9X0Eba0aNi yJefg594tkCt3CBf2b3wVVgqz1OwWj+AEwReUBiclcMSR2KzyU5a3OHBDrM70qMuIHqq fsyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726850849; x=1727455649; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=auS1Nijn3/MM+vVwjmIp4Kgr8RxjQxso8G43GcLWcTA=; b=HCDN1hxvpEZo+CGlR7h3YabpTIE/pInzKInEHUg+ZDzptuJlF1Aas58cnA9Fz0P/Ub lawJaylZUpJxAeU0yF0tcjMB2vqFZ0XEjUOA/I71b9tNzkbamXGLr1I5NiNOi7w67o6o f1WG4ryp1+gb4jWMq33hSShV2RjFpv3fTJIw7Gx54MZHY5l5OWGrBE9KcQPcNqpCLbga QEFsdgHMrHIofod8Z2Z5EojUPDZXmGRCN3yI1SrJ8L3FG7LS/8Qug1hZmjxexxU0nUNi 7bfy3GxtEDPuT9iQ+ktFaYIutip3agEUaQCuHJM+v4nc0LQVmmRBcCsKmXGeW/elF1e5 uB6Q== X-Gm-Message-State: AOJu0YzXjo//nrtywR0FaySVn+X4kSQb/nRkYnAHwz/st8lGZkxDxjaH 26edmHeQhw6YwjPeGnur6RZMhEtXoTRIq9XyNZ6zCnnQwkZcipb+HjTO7/nBbc4= X-Google-Smtp-Source: AGHT+IHXZIFkEVB0paBQKp6NWhbzwDh87vNSKY+P6NiQas53tTtsyxNthvn6Df+xga4/u+MbyHXoIQ== X-Received: by 2002:a5d:4741:0:b0:374:c6b8:50b5 with SMTP id ffacd0b85a97d-37a422783aamr2678511f8f.17.1726850848643; Fri, 20 Sep 2024 09:47:28 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:8e69:83a7:a29a:ba83]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-378e7804476sm18172250f8f.90.2024.09.20.09.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 09:47:28 -0700 (PDT) From: Jerome Brunet Date: Fri, 20 Sep 2024 18:47:03 +0200 Subject: [PATCH 2/5] regulator: core: remove machine init callback from config 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: <20240920-pmbus-wp-v1-2-d679ef31c483@baylibre.com> References: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> In-Reply-To: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Jerome Brunet X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1661; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=3p8epjwY1oVoba554UVp1ZMZNkGwAgCoLLhC2PSJKOM=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm7acZNBtZ0hTqllWyyFMkYkYea+7oUuVASt9st N3sfAwEOmyJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZu2nGQAKCRDm/A8cN/La hYf9D/46acuxSjA+sfoQ9+odznEGE2QZudI7LvM+JHSU/uTEuptHRL1hXmdE1Qz6bnv1WEoelb5 7oVKFTLwZMGp7We3tD8/wedhHL5r01t52dh2tD642SNH5nXOOZgZbazATUe+vSH4DFV05/aYIhm HXcQ0L1e2W3/HmXhWmIkfdbly++V3pNkkSDBjbQdJ+iNN1Dh1yX0p+Qnq/ndZnoSDPauKrJmqkt xWpM0uObnaIsR5lEQipTJUJOpkQWwzfufyYHdQb2CBdwvSMNJs4SxjCxcBj/HdtrVw9dFG0BDvz oyVwKTMwhKodI638sksCw4ZCUkRkrkmJbnD5I6F0iR5yOn6J8gHoYJX2UZSlUKvAyid6VcqAfU8 0yKY5jx2A1On/UvNFFNBw3BAzY5+dmZNO1ud3iiurAnLqETdxsaYG9B4fGm+CHaBE/q+EzY6V8H HG3nLSgyEh2FEfIWwqy0av3r34GXSzueXAYt9iI91E5tc23gw+Op5Mo+tXHCoaL/tdJT1NiIDkf 90MEHG/fXhcccoStXKKIji+IFMZRxXPBOzhf6+6biaGizZ14hPFUHh7VB9eBJqptmqRzK9fjXlR WeK2wU+8Qio/NF2dgy/hx0xQ+5t9aUK2NMMjN2VABPjh0UQkG5ya/eGfbGGpvxVytYKDWschLnc dnfdIuMTDuI7igA== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 The machine specific regulator_init() appears to be unused. It does not allow a lot of interactiona with the regulator framework, since nothing from the framework is passed along (desc, config, etc ...) Machine specific init may also be done with the added init_cb() in the regulator description, so remove regulator_init(). Signed-off-by: Jerome Brunet --- drivers/regulator/core.c | 7 ------- include/linux/regulator/machine.h | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4c90ab5ad876..4666b0e226c2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -5764,13 +5764,6 @@ regulator_register(struct device *dev, resolved_early =3D true; } =20 - /* perform any regulator specific init */ - if (init_data && init_data->regulator_init) { - ret =3D init_data->regulator_init(rdev->reg_data); - if (ret < 0) - goto wash; - } - if (config->ena_gpiod) { ret =3D regulator_ena_gpio_request(rdev, config); if (ret !=3D 0) { diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/ma= chine.h index 0cd76d264727..d0d700ff337a 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -285,8 +285,7 @@ struct regulator_init_data { int num_consumer_supplies; struct regulator_consumer_supply *consumer_supplies; =20 - /* optional regulator machine specific init */ - int (*regulator_init)(void *driver_data); + /* optional regulator machine specific data */ void *driver_data; /* core does not touch this */ }; =20 --=20 2.45.2 From nobody Fri Nov 29 10:21:04 2024 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60FD617E47A for ; Fri, 20 Sep 2024 16:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850853; cv=none; b=NR2s02nD3oc5wtdddT1HzeT9hHGOK/4NXVB7f0hZFojglw3i8Zsu9tgqa7V+lO4oZuHoWUD0ZX+TgeSJ8CGLGu0wG/+BZkistYNZvmDJmNG0X5UkG9AVLcx3qr742lH7B1D0ey//Z2/VpWEtHHiWizBikWQlITH1/EzMkei3I5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850853; c=relaxed/simple; bh=7Gd97J5FZJ8x51YDJ0TveVRB+r/ZL3dVmW0gShb0mFQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tmj69fFJ4cJpW/6XHyWGntCVjUHhSaJ/ta60/1qSNfwQUbD4g3kClefkSRMqgQMCX79i+8igyVrMw7bLuFTZSLCe0bbls7SpnKfyxFm8VnogcmCSOHIY80pRSbEnDHXwHwK2W1Zx2C4/L/wmZoj1/2eN/b7nui/7/QZPAzmRh6k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=QHV+AA2j; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="QHV+AA2j" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-378f90ad32dso1476545f8f.0 for ; Fri, 20 Sep 2024 09:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726850850; x=1727455650; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Grd6/QarEoX1VDGP2KnV3P4yoP18b6h6fWLKjReB7pQ=; b=QHV+AA2jqm2Xt3VklSL6soiUStVJlv6sJlzGVldo4Y+B6eEvgAb10Dnf1ux737oNLc +hzTlOEvUwJxIvcoyuiaWk2JqMg6CK6BzFoI57wyngJxnuARrawixzNfzga8dKqXjLH1 x58suh/P+IvcEpycKAqxQyZCpofFO3UD4H77k+mPUQWJUbd8EUWByEHWkVWG/RAGuMt9 c2Ljvx5lraQbW3OTohLVHroEoXGPSiXVpTw1yWgoyyQdXWW3gZibPhf3xO4deULJpFKf LthzEsy8sWkvJvPxyqe0V3I4jvV/Ct8eTilaP06cxfkGxMB7HhejXKvfmLell7iIEdD3 VOkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726850850; x=1727455650; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Grd6/QarEoX1VDGP2KnV3P4yoP18b6h6fWLKjReB7pQ=; b=jkR1gZIPFsOiKTgupnCDanqKQhioe8twhgQ1QH1SnHflZzbJIYwo09i/P22oylogNJ r/Xc3Mrw+vixVqIoif6WOmGAGv58tpqg7Us48NViDC/4lJslJCVDK72WLGGchzsVl2uw Ub8DF28cUGNl7g5k0q41ZczXUzVtI+AxiJG4TlCDxxjxvlmGAenM8A36lNhY+hwk7mL2 QgKYUXBotLhxvLGoc8AawUjd+u66V3DTPy94b8bV71Yw1SUwNphfwJcMMuDGs+/abZYV IVK/Anwl1P5fgFpO1+Yki1mtwpAkhrvfstYf430hYkSGRQkKOuAyX3vpjdaNxGWTl2ei 1iEg== X-Gm-Message-State: AOJu0YwKhOuW1svyGmgJShfYwEs2BhlqrpxYDdwwJk4EzgboY98hgB7b 08YaKZNe/sGcPfTNwsvEb/YKCBi9GnrucXNcTB1uRaFTLjUZeS9XdRj8TxwfqpI= X-Google-Smtp-Source: AGHT+IG8T/Uxxp3O3XxMqRJvOjGpV7ESRsDjpxKRPa7+9h85Ch4V4TUG0cezV+sC11zAQjuSit0j4w== X-Received: by 2002:a05:6000:186c:b0:368:5bb4:169b with SMTP id ffacd0b85a97d-37a43128c93mr2271652f8f.4.1726850849724; Fri, 20 Sep 2024 09:47:29 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:8e69:83a7:a29a:ba83]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-378e7804476sm18172250f8f.90.2024.09.20.09.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 09:47:29 -0700 (PDT) From: Jerome Brunet Date: Fri, 20 Sep 2024 18:47:04 +0200 Subject: [PATCH 3/5] hwmon: (pmbus/core) allow drivers to override WRITE_PROTECT 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: <20240920-pmbus-wp-v1-3-d679ef31c483@baylibre.com> References: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> In-Reply-To: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Jerome Brunet X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1110; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=7Gd97J5FZJ8x51YDJ0TveVRB+r/ZL3dVmW0gShb0mFQ=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm7acaXTvdJKP2FMN9pQ4umDAkwEokdT5Fn2ljm LQ7DUrb6xaJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZu2nGgAKCRDm/A8cN/La haMxD/9QfNw3IwRMsafMz8ch2EJPLc14eq+igVnicuHhSAD2mgJovVwOh6Gk4aOLqCpyMmEBh64 uoCpwQFDtcKN30sKNarIugge8PvQUQDgXrXQs2Do5QaZx4pYRpviK60KyiTY/yWQOd7iUESYGVo xgC3Nl7g+n4PUVlMyjlrrxQTWMky97X2AufoH4/3SdL85E60vOcmbaxb/1CNQnhtTe00Aw8Jxhg PC1X832P8pBeHzg6OfoT8poveY6i+fGd8p1dFCXK1gsfHHjRfOSN/mkI02zYNUZRw4ZnLzO1A6l AOENu885QxuDVFluRzVFdKsJ7Qph/eyvoiwezXrU3DdFc0WU8YEabOap269ObbADlg/lhQX8F7D t9Dgjaj6Ns5tEPaQfXXX8IH/VKy8su5qeYqrU5DGTy6TaFGK3QLCG9u8xZpY1gO1HBPCGjLSGkr o1PnicrBJdEwQ2ricOIiyLPGCS0Gbsppq7Of/MGLvvjBLHHiC5sntuSXsvVkm3G3ZoPAps6FhxH buhBG2LeT248LMNAUh44JMRcCXKJN8NDTfjNoKqLiQacewAlim/nqmj2RbSWx8ZNL2/US9IKCzT uqIsgcDcS5Y1Bzr/8gA9dguykUNuah9qs5PHt3z7l6zhQWZBFVcSr45gOSO25VaZyddRc3JEit+ 3cD2ojqjflq/7yw== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Use _pmbus_read_byte_data() rather than calling smbus directly to check the write protection status. This give a chance to device implementing write protection differently to report back on the actual write protection status. Signed-off-by: Jerome Brunet --- drivers/hwmon/pmbus/pmbus_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_c= ore.c index 0ea6fe7eb17c..82522fc9090a 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2712,9 +2712,7 @@ static int pmbus_init_common(struct i2c_client *clien= t, struct pmbus_data *data, * limit registers need to be disabled. */ if (!(data->flags & PMBUS_NO_WRITE_PROTECT)) { - pmbus_wait(client); - ret =3D i2c_smbus_read_byte_data(client, PMBUS_WRITE_PROTECT); - pmbus_update_ts(client, false); + ret =3D _pmbus_read_byte_data(client, 0xff, PMBUS_WRITE_PROTECT); =20 if (ret > 0 && (ret & PB_WP_ANY)) data->flags |=3D PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK; --=20 2.45.2 From nobody Fri Nov 29 10:21:04 2024 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B1F4183090 for ; Fri, 20 Sep 2024 16:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850855; cv=none; b=FGIiW8AEhLnilCqq08QjKsIfPLuWUAcXOf9S+KBj2rsAsGE0G4GCOW3dDGXlwdbPipXGN/s6dLscLS083tI3Ib5HpurRsa0s625l63Zy+WhOL8XxV5UDAVE6eKRhJqdFbW78KsDvvYeMxd7yLgDNKSxlJwtDnaqPMYKLhCTeGfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850855; c=relaxed/simple; bh=zsNq+PDcTEKGZXeuBcmGNoMaVB7tGewK0MhypO0Gu/k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ElyfnWDMMU26dy8hbHqtvcxRUCv/2EmYTqT+kalO18Jt++N1vqyNciyjvc70FJCCg7KjUKa8Zg3YqD04wtEjB413GWNs9wGEsy1IQpVwCivxwCBoA+gdeZn8g0BQXk7RRxp9LXRjglYMiQNiQ/eaonsEVXcis39ywHfXuEbJUyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=Zz36+hBl; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="Zz36+hBl" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-37a413085cbso838655f8f.1 for ; Fri, 20 Sep 2024 09:47:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726850851; x=1727455651; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=xvG11yWq9fBDuA1GWIjJf5XkqaA0AVG/AvWx55StoTg=; b=Zz36+hBl7h3Bt2s1OCAGoOlI+RC6frOWoZzz8RS8+AqZLPa3Qx0R56h66kXUYH2iZ9 vIG0p/lvVdAAxooKxZ5HYlU3Ik5a0OPdX8E3e8UG6qOR9cJka4XTDx4r2AnJLrr1dIjv Vd4xMRvVUCAfBFLYqo1x7xnMJnE5bIMJDrNBjvFDTB1jt5pAk27kA1jIC4iu5OFQAimC YZD4X2vq3z6+sCSVmToVgsSocvz1OruqnYebWdbb/UHTzIxVkVDAQHj2eHeH30wShkYY 1AOEPydKrcuZjzlpQL1HgYQr/RXlihgfl5nmb7u8TiihV976IQwU+D62DvNFAusA5T5M sXLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726850851; x=1727455651; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xvG11yWq9fBDuA1GWIjJf5XkqaA0AVG/AvWx55StoTg=; b=H8rIOmlWtzOD386hDBlcrMc0JbeCmPuOE/X8XHe6Bi3+UJwBU/oKbf7VzrQJCdmTbI Je6Yo/BtBVLvfdP715iBS5TUZ1HoPsJoBy1yYuWno8NZT/qqfiJrdv2aRRXHnukaK0cT sl6shapT1oR1m/royVQJWhZCatl0PI0rL/uCed3dUWLmkV737QNWge7RhlSjaTTOfQp2 g9/6b6u82V44ee6ffb0ZnA9j/mC8veSJrpgxxuHUjbewP5gpnBooflVotUsY/extRqVn wImGW0uN8mWQEIQFKXJZvzrmcNoxB5Lr6gQ6NxvPDpAPdVUqKDYuWH7XsahWGKCaJU2e uHVA== X-Gm-Message-State: AOJu0YyHYFlirFoJuNmykgvLAtIHRasvIZDPPj3aWahsU7BL2SfIbBad fnEsVZ5FvFB2guBkZgZ6sgJf6FBMjMhf/dZkmMQePY1j7BGV9L1dbMMoAPwuk+o= X-Google-Smtp-Source: AGHT+IFNfQPAgXWVZgTbiHDHxfW/w57ppwxvispcmBLKSumCGr63LrH09BizxXHzfnC2wMVwUg8w0Q== X-Received: by 2002:a5d:5b84:0:b0:374:b6e4:16a7 with SMTP id ffacd0b85a97d-3799a1d312dmr3849296f8f.8.1726850850718; Fri, 20 Sep 2024 09:47:30 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:8e69:83a7:a29a:ba83]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-378e7804476sm18172250f8f.90.2024.09.20.09.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 09:47:30 -0700 (PDT) From: Jerome Brunet Date: Fri, 20 Sep 2024 18:47:05 +0200 Subject: [PATCH 4/5] hwmon: (pmbus/core) improve handling of write protected regulators 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: <20240920-pmbus-wp-v1-4-d679ef31c483@baylibre.com> References: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> In-Reply-To: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Jerome Brunet X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4754; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=zsNq+PDcTEKGZXeuBcmGNoMaVB7tGewK0MhypO0Gu/k=; b=owEBbAKT/ZANAwAKAeb8Dxw38tqFAcsmYgBm7acbao3zIvXqaNheqeFc3p0DmPTEMe5MluMfx h7HTttOKFWJAjIEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZu2nGwAKCRDm/A8cN/La hRTdD/jpC8QdC54NzWDrfJ2/jk4ANYii+AlBOJ3MNcMKC4CU+IMtZ9ACXEJiesnQK8dTHY/wWrY UZMOmA65g7/145Oh7G/pPCYXMZMSWVT888pi+TJybFg1wUp945EzXKiH3leu426uP1ZfQWQz+k7 SBWOUAHA7ptD8H6qR5v4KxNXT5Z6h8cax7gfkySX/SvQffwk/wRtcKqD6Yc7ruVdifKWcS6PqTV TREAWioe298JtdrpeW7IZrYHhhB0qcXe+Js26t9vUE68Ed9UBH1UlwKcxvM9Y/iQ9PZvdAC9Dm9 24/zJ/GAR7TvjT5b5NiXH9RBm9XHQtocSttHSP2XBIlAyrfTzS686MMZtv11VokoH4guUooL+5j vHDN2or35kkdjDAWFRozRYeQMqvCP0pV6nUzL3tJGsfFBgKbvmS5ucHok2DSt0bCNeQvlZHQ1p9 oRiWIKFqVqh2qAS9TB4Bhfrx6C1b5FhIBAvmkdzXUhYG2W4o5QQPWNEs+wmPH2z4LHiQlPicTgd ptaLiB1o4FjAleovO84Z0xN0JybS0cI44z6B2IrMAvjbLnl6B9wV058NIYj7630C7FdBOC6LL4V x+5WB2JCuyTlLyo2XUz5vf7yL2ZP3aigr74nreqTi4CfXEX+B8q76CFqk9sl1zEt5xnlOUah+xl j6FNMIUb/UTO/ X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Writing PMBus protected registers does succeed from the smbus perspective, even if the write is ignored by the device and a communication fault is raised. This fault will silently be caught and cleared by pmbus irq if one has been registered. This means that the regulator call may return succeed although the operation was ignored. With this change, the operation which are not supported will be properly flagged as such and the regulator framework won't even try to execute them. Signed-off-by: Jerome Brunet --- drivers/hwmon/pmbus/pmbus.h | 4 ++++ drivers/hwmon/pmbus/pmbus_core.c | 35 ++++++++++++++++++++++++++++++++++- include/linux/pmbus.h | 14 ++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 5d5dc774187b..76cff65f38d5 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -481,6 +481,8 @@ struct pmbus_driver_info { /* Regulator ops */ =20 extern const struct regulator_ops pmbus_regulator_ops; +int pmbus_regulator_init_cb(struct regulator_dev *rdev, + struct regulator_config *config); =20 /* Macros for filling in array of struct regulator_desc */ #define PMBUS_REGULATOR_STEP(_name, _id, _voltages, _step, _min_uV) \ @@ -495,6 +497,7 @@ extern const struct regulator_ops pmbus_regulator_ops; .n_voltages =3D _voltages, \ .uV_step =3D _step, \ .min_uV =3D _min_uV, \ + .init_cb =3D pmbus_regulator_init_cb, \ } =20 #define PMBUS_REGULATOR(_name, _id) PMBUS_REGULATOR_STEP(_name, _id, 0, = 0, 0) @@ -510,6 +513,7 @@ extern const struct regulator_ops pmbus_regulator_ops; .n_voltages =3D _voltages, \ .uV_step =3D _step, \ .min_uV =3D _min_uV, \ + .init_cb =3D pmbus_regulator_init_cb, \ } =20 #define PMBUS_REGULATOR_ONE(_name) PMBUS_REGULATOR_STEP_ONE(_name, 0, 0,= 0) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_c= ore.c index 82522fc9090a..363def768888 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2714,8 +2714,21 @@ static int pmbus_init_common(struct i2c_client *clie= nt, struct pmbus_data *data, if (!(data->flags & PMBUS_NO_WRITE_PROTECT)) { ret =3D _pmbus_read_byte_data(client, 0xff, PMBUS_WRITE_PROTECT); =20 - if (ret > 0 && (ret & PB_WP_ANY)) + switch (ret) { + case PB_WP_ALL: + data->flags |=3D PMBUS_OP_PROTECTED; + fallthrough; + case PB_WP_OP: + data->flags |=3D PMBUS_VOUT_PROTECTED; + fallthrough; + case PB_WP_VOUT: data->flags |=3D PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK; + break; + + default: + /* Ignore manufacturer specific and invalid as well as errors */ + break; + } } =20 if (data->info->pages) @@ -3172,8 +3185,12 @@ static int pmbus_regulator_list_voltage(struct regul= ator_dev *rdev, { struct device *dev =3D rdev_get_dev(rdev); struct i2c_client *client =3D to_i2c_client(dev->parent); + struct pmbus_data *data =3D i2c_get_clientdata(client); int val, low, high; =20 + if (data->flags & PMBUS_VOUT_PROTECTED) + return 0; + if (selector >=3D rdev->desc->n_voltages || selector < rdev->desc->linear_min_sel) return -EINVAL; @@ -3208,6 +3225,22 @@ const struct regulator_ops pmbus_regulator_ops =3D { }; EXPORT_SYMBOL_NS_GPL(pmbus_regulator_ops, PMBUS); =20 +int pmbus_regulator_init_cb(struct regulator_dev *rdev, + struct regulator_config *config) +{ + struct pmbus_data *data =3D config->driver_data; + struct regulation_constraints *constraints =3D rdev->constraints; + + if (data->flags & PMBUS_OP_PROTECTED) + constraints->valid_ops_mask &=3D ~REGULATOR_CHANGE_STATUS; + + if (data->flags & PMBUS_VOUT_PROTECTED) + constraints->valid_ops_mask &=3D ~REGULATOR_CHANGE_VOLTAGE; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(pmbus_regulator_init_cb, PMBUS); + static int pmbus_regulator_register(struct pmbus_data *data) { struct device *dev =3D data->dev; diff --git a/include/linux/pmbus.h b/include/linux/pmbus.h index fa9f08164c36..884040e1383b 100644 --- a/include/linux/pmbus.h +++ b/include/linux/pmbus.h @@ -73,6 +73,20 @@ */ #define PMBUS_USE_COEFFICIENTS_CMD BIT(5) =20 +/* + * PMBUS_OP_PROTECTED + * Set if the chip OPERATION command is protected and protection is not + * determined by the standard WRITE_PROTECT command. + */ +#define PMBUS_OP_PROTECTED BIT(6) + +/* + * PMBUS_VOUT_PROTECTED + * Set if the chip VOUT_COMMAND command is protected and protection is not + * determined by the standard WRITE_PROTECT command. + */ +#define PMBUS_VOUT_PROTECTED BIT(7) + struct pmbus_platform_data { u32 flags; /* Device specific flags */ =20 --=20 2.45.2 From nobody Fri Nov 29 10:21:04 2024 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A216F183CA1 for ; Fri, 20 Sep 2024 16:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850855; cv=none; b=ZC2xm06jpsqakPljAbdbZ5OPmw6c+btg+C7GRqSeqrM/jFS56NRvLvdi7AlEcYUfyyLOEbLMySzGVxOszjVVZXjxlpUjlQ4+g/M2+teK3mwDyjNLs+po0+1FENomGiHyrIMZfT+HcL+9zrmwwEMZAkOWA3GBCQE8hzStgN71A2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726850855; c=relaxed/simple; bh=CjFFhc9MMW49VE8u5F61A8xLqeMREhaJD452w7fqvfs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QkKrwm3j4vm+n3ciAbijYTVlRNXrp8iq5G0LbXHYVmlCPiZmThX4aez/Pr/Jnr8wO1txCRkd4QKeiS6/LZvpToloh+6nkIDWt7ZMjsvEp8jNpzO8jH12WjefEbDt7VcolrjdnNmf+euKavc+DFROd64wiaNXUdszEzxTOznCnTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=Am13g7Pp; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="Am13g7Pp" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-42cc43454d5so18170335e9.3 for ; Fri, 20 Sep 2024 09:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726850852; x=1727455652; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9qllhEfwvR3O4kFWcLK8tY64jimzQys29VMp9CXwNVU=; b=Am13g7Pp4Th2TNYl0OmOU3HxwArqkgR04NFH39lh+mBc4t76MgCfvoXI7UMAaco9Ec ExnvAtOQjmlyYezI4+edKQ5yeCeb4wk8Vq15yjjIOt2WmI0v2x/nRAVcoCgoh8KyUsy0 DEOHVeeg42z9FOsdxESzvV2IU6CAyY7MZsdtoEfHMyFt0iltrY0uUxmxPuF18ZKwXHLN OfaBNgcf5LqGs1fpdbIMeGX4kKtMhYITFRMK4lpaxDnUcF2+FNYxaN01OdUvSwjC/KG2 vKYlbXM1b3WZJK8ipM6c7seqWy49GoZJ0wDbvnL5QkaPh67b50SzpHdNqBegC5U6N/UY iZRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726850852; x=1727455652; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9qllhEfwvR3O4kFWcLK8tY64jimzQys29VMp9CXwNVU=; b=C/t1+D+uZpgFQVhqLw5oN/xwdmwEwr9v/dxVHEiAGFQpyrAAM0pcSJkuVeZ05Il8Th jG6I7kB5BOzDKqhG0Zhsbi4kyTmczZvkE6DHYCuoaWI4KCExqoNagLyS8SsKB3BP3SAI QYprPZx8wiRboIwCsm3gyYwjFVpJTk2zzYSI0/uzu2ZelQhSt+navR4zbvVOj9EiP4Bg gdz5JAs60NgDn1KTrUMBKyd7JpncK2HXsyEZUIkgQsM2CnCQa1E3NtKFs/LPb0fmGet7 Wc8gQx8m9Td/NBDGoSzJBc8cpG5tl97SxfjiFbl70CNw+Y2Y9sd5ZfyQ4Yxj798K6Ert ZhyQ== X-Gm-Message-State: AOJu0YwT+80n48y4hZkwowWCI1GzLSyfINAmJTXpytzgLKOYlAyHPAJY TQbOkbiToMY0TZvExaXHakUrNssXq7Dn04cV86iRG2y8XLax2Exnc/kTRH75AGc= X-Google-Smtp-Source: AGHT+IEt0mM17T+QkgiiYQ9Xi5bCM7DZKFGhbLt/nTTYRXLtk0K+n3YEG7uPcLIhjOVfXQUGSIfHYw== X-Received: by 2002:a05:600c:4f0c:b0:42c:a7cc:cb64 with SMTP id 5b1f17b1804b1-42e7abe4424mr26563375e9.3.1726850851917; Fri, 20 Sep 2024 09:47:31 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:8e69:83a7:a29a:ba83]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-378e7804476sm18172250f8f.90.2024.09.20.09.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 09:47:31 -0700 (PDT) From: Jerome Brunet Date: Fri, 20 Sep 2024 18:47:06 +0200 Subject: [PATCH 5/5] hwmon: (pmbus/core) add wp module param 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: <20240920-pmbus-wp-v1-5-d679ef31c483@baylibre.com> References: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> In-Reply-To: <20240920-pmbus-wp-v1-0-d679ef31c483@baylibre.com> To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Jerome Brunet X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4312; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=CjFFhc9MMW49VE8u5F61A8xLqeMREhaJD452w7fqvfs=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBm7accgwF3pAoGMadS0uLmPG3TjPnHKaehiS7BO q/wHo52nMaJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZu2nHAAKCRDm/A8cN/La hTCCD/9bQZablXDI+t6T4xSNVQA9V6jPgrq8Mwr4Qdn3Sb1S6l7rmjLjRCZ+ukYqm8JfNaQjtiU b/z1f1CS+g84eBFCphG1xjCrgNoVAtVToR2fPbE4ugvqFAFeq8VoTKrxh9cbnz7JwrJRtZ16TGM MRPPglExlRbgQcbWfVOMaxa+83bdubMwNqDtWnfmVb+zW57F/iKyAsqka+1PqaZsozpWBvsB7Ak +ePVvPOkkGVT1XtwmeCF4x0vs5PuFIWMZ4ct6Qlca8UVSpLocVwkZ3b1L3cDYjdX3hLMODXsI9+ FwcFiNICY75flV9AcriBS3MiPR9vCjWW4vGYIwSAw4/sRfXtwuUWcQyI3rwtKj5uAkp3Oj4DxCR xgwXtj79YOWkfADhVBaB+4i8cLTSIfJlpcYvowhfZKEOUXsuA10cuVr9+ZskgpLVPGDRJd2A2et GOEXHuMdd7xibOoNCypCxEASsGAnz983G0+HkvudeN++D1tv+uyYbxENUa58aXU1cZdMU91gcwO eZvu5FPf/jeZ2B+kRTLwiabTcqhdP0VU+xIPB2jp/QMxcULFZQtW7nsnjHRj+gSBGShnZmvUA0F leJizcwQ/QM9NaCjS8AsaRY74u1TRTTLZd5IrtNIHYGNRuGStjuLIAuOqnmRzftdBi7VKWdonVA INERHNsw978xEAQ== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Add a module parameter to force the write protection mode of pmbus chips. 2 protections modes are provided to start with: * 0: Remove the write protection if possible * 1: Enable full write protection if possible Of course, if the parameter is not provided, the default write protection status of the pmbus chips is left untouched. Suggested-by: Guenter Roeck Signed-off-by: Jerome Brunet --- Documentation/admin-guide/kernel-parameters.txt | 4 ++ drivers/hwmon/pmbus/pmbus_core.c | 74 ++++++++++++++++++---= ---- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 09126bb8cc9f..e41d13f46140 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4672,6 +4672,10 @@ Format: { parport | timid | 0 } See also Documentation/admin-guide/parport.rst. =20 + pmbus.wp=3D [HW] PMBus Chips write protection forced mode + Format: { 0 | 1 } + See drivers/hwmon/pmbus/pmbus_core.c + pmtmr=3D [X86] Manual setup of pmtmr I/O Port. Override pmtimer IOPort with a hex value. e.g. pmtmr=3D0x508 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_c= ore.c index 363def768888..ca5803bfd24a 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -31,6 +31,20 @@ #define PMBUS_ATTR_ALLOC_SIZE 32 #define PMBUS_NAME_SIZE 24 =20 +/* + * PMBus write protect forced mode: + * PMBus may come up with a variety of write protection configuration. + * 'pmbus_wp' may be used if a particular write protection is necessary. + * The ability to actually alter the protection may also depend on the chip + * so the actual runtime write protection configuration may differ from + * the requested one. pmbus_core currently support the following value: + * - 0: write protection removed + * - 1: write protection fully enabled, including OPERATION and VOUT_COMMA= ND + * registers. Chips essentially become read-only with this. + */ +static int wp =3D -1; +module_param(wp, int, 0444); + struct pmbus_sensor { struct pmbus_sensor *next; char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */ @@ -2658,6 +2672,45 @@ static void pmbus_remove_pec(void *dev) device_remove_file(dev, &dev_attr_pec); } =20 +static void pmbus_init_wp(struct i2c_client *client, struct pmbus_data *da= ta) +{ + int ret; + + switch (wp) { + case 0: + _pmbus_write_byte_data(client, 0xff, + PMBUS_WRITE_PROTECT, 0); + break; + + case 1: + _pmbus_write_byte_data(client, 0xff, + PMBUS_WRITE_PROTECT, PB_WP_ALL); + break; + + default: + /* Ignore the other values */ + break; + } + + ret =3D _pmbus_read_byte_data(client, 0xff, PMBUS_WRITE_PROTECT); + + switch (ret) { + case PB_WP_ALL: + data->flags |=3D PMBUS_OP_PROTECTED; + fallthrough; + case PB_WP_OP: + data->flags |=3D PMBUS_VOUT_PROTECTED; + fallthrough; + case PB_WP_VOUT: + data->flags |=3D PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK; + break; + + default: + /* Ignore manufacturer specific and invalid as well as errors */ + break; + } +} + static int pmbus_init_common(struct i2c_client *client, struct pmbus_data = *data, struct pmbus_driver_info *info) { @@ -2711,25 +2764,8 @@ static int pmbus_init_common(struct i2c_client *clie= nt, struct pmbus_data *data, * faults, and we should not try it. Also, in that case, writes into * limit registers need to be disabled. */ - if (!(data->flags & PMBUS_NO_WRITE_PROTECT)) { - ret =3D _pmbus_read_byte_data(client, 0xff, PMBUS_WRITE_PROTECT); - - switch (ret) { - case PB_WP_ALL: - data->flags |=3D PMBUS_OP_PROTECTED; - fallthrough; - case PB_WP_OP: - data->flags |=3D PMBUS_VOUT_PROTECTED; - fallthrough; - case PB_WP_VOUT: - data->flags |=3D PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK; - break; - - default: - /* Ignore manufacturer specific and invalid as well as errors */ - break; - } - } + if (!(data->flags & PMBUS_NO_WRITE_PROTECT)) + pmbus_init_wp(client, data); =20 if (data->info->pages) pmbus_clear_faults(client); --=20 2.45.2