From patchwork Mon Sep 2 07:53:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13786878 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 99EFB1547CA for ; Mon, 2 Sep 2024 07:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263727; cv=none; b=s6NUXfCG5ZlIZtsEllpjUcdwbjuYb56JtJOhCn4j4swibqTGzqmti4sRTVyNMAIm2i1RwcEnEUfsNfVWUezQtWjIcrHYK78Djm6eLOVp/zD7zcLrpMAGdf47C2kiOFTpoFUYwT7Y1IUKo+v+5zEfeeIAmIbeuvC46irLl7uQFlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263727; c=relaxed/simple; bh=06uiLkKD7zpUn6GdcOmDA03uOQJzZV0sd0l320q5UYo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=afOjdhw0+lHLbCls5xDsjDMAp+uhwE8uWhuWWc3qFSE03V8y+Sh+arvsae2yumK5xfCTcEC7D3ylDhMAtexPsgIvF3BnGaM7UbbQoDhsNwJCcAdU0U7Qyrtb8F5Rxtf7yM6lS2wUlp3rpU7Bt+KnHSJ/N3hl9sK2QZFujCmhJtE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=HSx8Ga3J; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="HSx8Ga3J" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a86acbaddb4so454179166b.1 for ; Mon, 02 Sep 2024 00:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1725263723; x=1725868523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9JIYHNVS9jheuQnwK+apksnNMgGOwCb6OieNOcohN6g=; b=HSx8Ga3J2afzZ8MHXez4a9uBknR7bStYzQKKeYijDU8VflkvakBRXcV0sNkgM4nk/2 NYuCwTQ9kVWm5SHuz7ZSZQfX7NSKpanIfXVcctzCfYZ+V4mYkq4UZg5qZUVU1SHYmYV1 syf53AkO1rl68+tmOBm0QLVqiVuP2SfhbjYUGBbzgXitOyXH8zX8ffldTxqIG0N2G59G V6a8i9nmlM5Sdt6Ul6MIwqbKko91L/uttnhYkuZBsgeSBxdS2Ev4jHfg/+eT12IjqxIT vLw7pDxZ3vxVJ/zYqTGToevMPsxO/sP+zXHadm1BKiTsuKMQbkMdFn43xcrsVkzeSNNz CuMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725263723; x=1725868523; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9JIYHNVS9jheuQnwK+apksnNMgGOwCb6OieNOcohN6g=; b=ZJQJhDO4MhgtEXLZh6LXrRBt5PrV9BpVwP1na3Mt2vFoj/cFPNGqIhZNq7nNzPrvWt abPXebwip0SFKpbl2ZgXuhNd286kBPec26lW0UAEnGcIH0nDfZm24GzmomBrXbxuExt7 gGkDiGA8u8H251da2o8pUPlNcZIgk7EnlYDGaxCughY0oG6EAiIFrvjOcS69icsUIEO3 v1VDb3nZSz/7B+IgYnlo/ruUn/dLStmdZd8/zzVQuZXvPGmuDGzq0jTXIdZE25T2jfzE D9/XvsOLk+GxoDJS/LvJsrpeRXPFLsHtZtsbjGZG98kas8oLLlXPsteLL9VjyVqMkRut fvNQ== X-Forwarded-Encrypted: i=1; AJvYcCXl1MQQQhzYiHPc0QW90n5rFFd1AJ97+3vuhiBRiD5AuMXJZJ9syDDTlluYkdTriBiYWCU9X78DiSlfbw==@vger.kernel.org X-Gm-Message-State: AOJu0YxAlDMoXi6uQQ/t8Iy7PgWZno857G0lv72swRz0sdRlt1KDqyoR cALO8nyIAMczXZNo9iqv9yF1tsthAwQBbG+3o3TC+yJf52lsep/T4iCAXGNyEv4RvSU5/D+XuxB g X-Google-Smtp-Source: AGHT+IHBL15hnriVFJ1TgbcdMvsToBtmxxPz1BGIINIqhrU22QhT1uhYESrGqMpOfhrzyXwh+9s0bw== X-Received: by 2002:a17:907:7e94:b0:a7a:a3f7:389e with SMTP id a640c23a62f3a-a897f78daccmr1087271466b.6.1725263722810; Mon, 02 Sep 2024 00:55:22 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989022481sm521076066b.86.2024.09.02.00.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:55:22 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, Patrick Rudolph , linux-hwmon@vger.kernel.org Subject: [PATCH v3 1/5] hwmon: pmbus: Implement generic bus access delay Date: Mon, 2 Sep 2024 09:53:12 +0200 Message-ID: <20240902075319.585656-1-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some drivers, like the max15301 or zl6100, are intentionally delaying SMBus communications, to prevent transmission errors. As this is necessary on additional PMBus compatible devices, implement a generic delay mechanism in the pmbus core. Introduces two delay settings in the pmbus_driver_info struct, one applies to every SMBus transaction and the other is for write transaction only. Once set by the driver the SMBus traffic, using the generic pmbus access helpers, is automatically delayed when necessary. The two settings are: access_delay: - Unit in microseconds - Stores the accessed timestamp after every SMBus access - Delays when necessary before the next SMBus access write_delay: - Unit in microseconds - Stores the written timestamp after a write SMBus access - Delays when necessary before the next SMBus access This allows to drop the custom delay code from the drivers and easily introduce this feature in additional pmbus drivers. Signed-off-by: Patrick Rudolph --- Changelog v2: - Rename pmbus_optional_wait() - Drop inline keyword - Use fsleep over usleep Changelog v3: - Added changelog drivers/hwmon/pmbus/pmbus.h | 10 ++++ drivers/hwmon/pmbus/pmbus_core.c | 92 +++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index fb442fae7b3e..5d5dc774187b 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -466,6 +466,16 @@ struct pmbus_driver_info { /* custom attributes */ const struct attribute_group **groups; + + /* + * Some chips need a little delay between SMBus communication. When + * set, the generic PMBus helper functions will wait if necessary + * to meet this requirement. The access delay is honored after + * every SMBus operation. The write delay is only honored after + * SMBus write operations. + */ + int access_delay; /* in microseconds */ + int write_delay; /* in microseconds */ }; /* Regulator ops */ diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index cb4c65a7f288..0ea6fe7eb17c 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -108,6 +109,8 @@ struct pmbus_data { int vout_low[PMBUS_PAGES]; /* voltage low margin */ int vout_high[PMBUS_PAGES]; /* voltage high margin */ + ktime_t write_time; /* Last SMBUS write timestamp */ + ktime_t access_time; /* Last SMBUS access timestamp */ }; struct pmbus_debugfs_entry { @@ -158,6 +161,39 @@ void pmbus_set_update(struct i2c_client *client, u8 reg, bool update) } EXPORT_SYMBOL_NS_GPL(pmbus_set_update, PMBUS); +/* Some chips need a delay between accesses. */ +static void pmbus_wait(struct i2c_client *client) +{ + struct pmbus_data *data = i2c_get_clientdata(client); + const struct pmbus_driver_info *info = data->info; + s64 delta; + + if (info->access_delay) { + delta = ktime_us_delta(ktime_get(), data->access_time); + + if (delta < info->access_delay) + fsleep(info->access_delay - delta); + } else if (info->write_delay) { + delta = ktime_us_delta(ktime_get(), data->write_time); + + if (delta < info->write_delay) + fsleep(info->write_delay - delta); + } +} + +/* Sets the last accessed timestamp for pmbus_wait */ +static void pmbus_update_ts(struct i2c_client *client, bool write_op) +{ + struct pmbus_data *data = i2c_get_clientdata(client); + const struct pmbus_driver_info *info = data->info; + + if (info->access_delay) { + data->access_time = ktime_get(); + } else if (info->write_delay && write_op) { + data->write_time = ktime_get(); + } +} + int pmbus_set_page(struct i2c_client *client, int page, int phase) { struct pmbus_data *data = i2c_get_clientdata(client); @@ -168,11 +204,15 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL) && data->info->pages > 1 && page != data->currpage) { + pmbus_wait(client); rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); + pmbus_update_ts(client, true); if (rv < 0) return rv; + pmbus_wait(client); rv = i2c_smbus_read_byte_data(client, PMBUS_PAGE); + pmbus_update_ts(client, false); if (rv < 0) return rv; @@ -183,8 +223,10 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase) if (data->info->phases[page] && data->currphase != phase && !(data->info->func[page] & PMBUS_PHASE_VIRTUAL)) { + pmbus_wait(client); rv = i2c_smbus_write_byte_data(client, PMBUS_PHASE, phase); + pmbus_update_ts(client, true); if (rv) return rv; } @@ -202,7 +244,11 @@ int pmbus_write_byte(struct i2c_client *client, int page, u8 value) if (rv < 0) return rv; - return i2c_smbus_write_byte(client, value); + pmbus_wait(client); + rv = i2c_smbus_write_byte(client, value); + pmbus_update_ts(client, true); + + return rv; } EXPORT_SYMBOL_NS_GPL(pmbus_write_byte, PMBUS); @@ -233,7 +279,11 @@ int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg, if (rv < 0) return rv; - return i2c_smbus_write_word_data(client, reg, word); + pmbus_wait(client); + rv = i2c_smbus_write_word_data(client, reg, word); + pmbus_update_ts(client, true); + + return rv; } EXPORT_SYMBOL_NS_GPL(pmbus_write_word_data, PMBUS); @@ -351,7 +401,11 @@ int pmbus_read_word_data(struct i2c_client *client, int page, int phase, u8 reg) if (rv < 0) return rv; - return i2c_smbus_read_word_data(client, reg); + pmbus_wait(client); + rv = i2c_smbus_read_word_data(client, reg); + pmbus_update_ts(client, false); + + return rv; } EXPORT_SYMBOL_NS_GPL(pmbus_read_word_data, PMBUS); @@ -410,7 +464,11 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg) if (rv < 0) return rv; - return i2c_smbus_read_byte_data(client, reg); + pmbus_wait(client); + rv = i2c_smbus_read_byte_data(client, reg); + pmbus_update_ts(client, false); + + return rv; } EXPORT_SYMBOL_NS_GPL(pmbus_read_byte_data, PMBUS); @@ -422,7 +480,11 @@ int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value) if (rv < 0) return rv; - return i2c_smbus_write_byte_data(client, reg, value); + pmbus_wait(client); + rv = i2c_smbus_write_byte_data(client, reg, value); + pmbus_update_ts(client, true); + + return rv; } EXPORT_SYMBOL_NS_GPL(pmbus_write_byte_data, PMBUS); @@ -454,7 +516,11 @@ static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg, if (rv < 0) return rv; - return i2c_smbus_read_block_data(client, reg, data_buf); + pmbus_wait(client); + rv = i2c_smbus_read_block_data(client, reg, data_buf); + pmbus_update_ts(client, false); + + return rv; } static struct pmbus_sensor *pmbus_find_sensor(struct pmbus_data *data, int page, @@ -2450,9 +2516,11 @@ static int pmbus_read_coefficients(struct i2c_client *client, data.block[1] = attr->reg; data.block[2] = 0x01; + pmbus_wait(client); rv = i2c_smbus_xfer(client->adapter, client->addr, client->flags, I2C_SMBUS_WRITE, PMBUS_COEFFICIENTS, I2C_SMBUS_BLOCK_PROC_CALL, &data); + pmbus_update_ts(client, true); if (rv < 0) return rv; @@ -2604,7 +2672,10 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, /* Enable PEC if the controller and bus supports it */ if (!(data->flags & PMBUS_NO_CAPABILITY)) { + pmbus_wait(client); ret = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY); + pmbus_update_ts(client, false); + if (ret >= 0 && (ret & PB_CAPABILITY_ERROR_CHECK)) { if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_PEC)) client->flags |= I2C_CLIENT_PEC; @@ -2617,10 +2688,16 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, * Bail out if both registers are not supported. */ data->read_status = pmbus_read_status_word; + pmbus_wait(client); ret = i2c_smbus_read_word_data(client, PMBUS_STATUS_WORD); + pmbus_update_ts(client, false); + if (ret < 0 || ret == 0xffff) { data->read_status = pmbus_read_status_byte; + pmbus_wait(client); ret = i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE); + pmbus_update_ts(client, false); + if (ret < 0 || ret == 0xff) { dev_err(dev, "PMBus status register not found\n"); return -ENODEV; @@ -2635,7 +2712,10 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, * limit registers need to be disabled. */ if (!(data->flags & PMBUS_NO_WRITE_PROTECT)) { + pmbus_wait(client); ret = i2c_smbus_read_byte_data(client, PMBUS_WRITE_PROTECT); + pmbus_update_ts(client, false); + if (ret > 0 && (ret & PB_WP_ANY)) data->flags |= PMBUS_WRITE_PROTECTED | PMBUS_SKIP_STATUS_CHECK; } From patchwork Mon Sep 2 07:53:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13786879 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 DC19B154C07 for ; Mon, 2 Sep 2024 07:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263727; cv=none; b=VfDZgByCXezudeS2hJXsZwxL9dCPPn9tqDMgwHK3EEHIqQQgKbyoyaO0Yaifh4MfM+nKmRok+vXjr/3kvzyrioIRQQYWEnpMg6D75/kFxkODTWHTqMpwZ6DS2tYeZ+P+yVmjFWtrR7GlSJ6IsfnAg1s9K6h+or7gC8I71oTVqng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263727; c=relaxed/simple; bh=CHTREiAcEZMsJXs1E2EV/u8Fu6chAqB+ClVn1Vb70uQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EnQygi4CMaqbVEjfPARwbbigjKtTEolVkn008RaSy8A0UWGhIA2sBlkoWu4lSUrXwGwHrCXGGYXB4jPYKoTLIJ9kDhSOKIn8BwJP9KdErP064PnBEcxtEj8rQBgvpSdDL2wp2mCqtD1PWobJQFokkMa4HMn29SlOKvd4UN6yD9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=KfEq8Pvu; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="KfEq8Pvu" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a80eab3945eso341830766b.1 for ; Mon, 02 Sep 2024 00:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1725263724; x=1725868524; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2wJu6eSYrIH+jWqR93bP7w6T/N0xlGC/9JkjmC8TAO0=; b=KfEq8PvuWfudjCQkPag4TGwYWcvDqpWqQCVULjWDsHsQ2HEoYHF+1gYal0//NdI1HM Jizs+lCv7F6eX+tZF76cCVfJyUjnYph2OV+Dq6+Qd9V8G6Hm7bVWmCQg+I00+TsSo08W 7+lRPxE0/jfk+FvnEWg5ONUglQZW8pv9FWTYn8N2C8XsKE7b0Gj7/TvdTIWRE2b1QgZ0 1khzzzRGDpqtfQWsa2TDwKQqKOmL9kxy3SaQ0byn3CeKS558v7fDzk0X+6LvRdof8e0V XREucuZKNqOntfgLUTCh+cN4xls7Lf6krqhw2J6X+gE/dEmHNOyIj3oC4WcSr71HXdeT vZkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725263724; x=1725868524; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2wJu6eSYrIH+jWqR93bP7w6T/N0xlGC/9JkjmC8TAO0=; b=lUdpde7SWfoQQ7GoE2YBeCb+Iy3R+79ipWnvHf0tvPPksfCcfRM3F5eEZNYDJNOLy7 AtjiHvi2TJdcv3B0amma8si1GUvfin4pNBglhksYkOV1HJ7ZUOZE+m00vqqrd0elKZUS v9DnhgMGDvW9mIS3oFncSdMu8d6IdclaMcYUm1BtymvLje9vmtqhPwH0l8TfNneo8lLH NxMd7L9ogHLtlcS5w7/JdnSUWR/uZ3tGmYNvxjHeD9R181/2tTJ8GUcdImazz6li4Cqz qrN5otWdegqov5rvCcOJxafcp4OKohDC2eyJUASQd2bUWe41EyIhEaksDAkBt5tnrPsq bmjw== X-Forwarded-Encrypted: i=1; AJvYcCVDZDolrlGt1Yj7zsiYCFdiZUSQ91ZNiq0ozBhUZthDfx/xEfF9Z8uoqOnwwp6fP6Zt4Js3QxUeHvefZA==@vger.kernel.org X-Gm-Message-State: AOJu0YypzRj1LnIhIHIWEgEMnire/SmZE9uc4RGNZ7rskRx4J88HuOCz LB58d3Q6Mneeqoin2v32rB4bdjpqP9pLAWBM3ub9vkAkkg+4T+Df8GcGDI1Q0ok= X-Google-Smtp-Source: AGHT+IHuc6RANhB2GFUELent8s8Fr0cwtTYQacm2gMM6HYRleWFgZr0ofL5/w80YH5dqa6wZI+h+Ag== X-Received: by 2002:a17:907:948b:b0:a86:c252:aaa2 with SMTP id a640c23a62f3a-a89a379d069mr706616766b.51.1725263724106; Mon, 02 Sep 2024 00:55:24 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989022481sm521076066b.86.2024.09.02.00.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:55:23 -0700 (PDT) From: Patrick Rudolph To: Daniel Nilsson Cc: jdelvare@suse.com, linux@roeck-us.net, Patrick Rudolph , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/5] hwmon: pmbus: max15301: Use generic code Date: Mon, 2 Sep 2024 09:53:13 +0200 Message-ID: <20240902075319.585656-2-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240902075319.585656-1-patrick.rudolph@9elements.com> References: <20240902075319.585656-1-patrick.rudolph@9elements.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the generic pmbus bus access delay. Signed-off-by: Patrick Rudolph --- Changelog v2: - No change Changelog v3: - Added changelog drivers/hwmon/pmbus/max15301.c | 92 +--------------------------------- 1 file changed, 1 insertion(+), 91 deletions(-) diff --git a/drivers/hwmon/pmbus/max15301.c b/drivers/hwmon/pmbus/max15301.c index 986404fe6a31..f5367a7bc0f5 100644 --- a/drivers/hwmon/pmbus/max15301.c +++ b/drivers/hwmon/pmbus/max15301.c @@ -31,8 +31,6 @@ MODULE_DEVICE_TABLE(i2c, max15301_id); struct max15301_data { int id; - ktime_t access; /* Chip access time */ - int delay; /* Delay between chip accesses in us */ struct pmbus_driver_info info; }; @@ -55,89 +53,6 @@ static struct max15301_data max15301_data = { } }; -/* This chip needs a delay between accesses */ -static inline void max15301_wait(const struct max15301_data *data) -{ - if (data->delay) { - s64 delta = ktime_us_delta(ktime_get(), data->access); - - if (delta < data->delay) - udelay(data->delay - delta); - } -} - -static int max15301_read_word_data(struct i2c_client *client, int page, - int phase, int reg) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct max15301_data *data = to_max15301_data(info); - int ret; - - if (page > 0) - return -ENXIO; - - if (reg >= PMBUS_VIRT_BASE) - return -ENXIO; - - max15301_wait(data); - ret = pmbus_read_word_data(client, page, phase, reg); - data->access = ktime_get(); - - return ret; -} - -static int max15301_read_byte_data(struct i2c_client *client, int page, int reg) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct max15301_data *data = to_max15301_data(info); - int ret; - - if (page > 0) - return -ENXIO; - - max15301_wait(data); - ret = pmbus_read_byte_data(client, page, reg); - data->access = ktime_get(); - - return ret; -} - -static int max15301_write_word_data(struct i2c_client *client, int page, int reg, - u16 word) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct max15301_data *data = to_max15301_data(info); - int ret; - - if (page > 0) - return -ENXIO; - - if (reg >= PMBUS_VIRT_BASE) - return -ENXIO; - - max15301_wait(data); - ret = pmbus_write_word_data(client, page, reg, word); - data->access = ktime_get(); - - return ret; -} - -static int max15301_write_byte(struct i2c_client *client, int page, u8 value) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct max15301_data *data = to_max15301_data(info); - int ret; - - if (page > 0) - return -ENXIO; - - max15301_wait(data); - ret = pmbus_write_byte(client, page, value); - data->access = ktime_get(); - - return ret; -} - static int max15301_probe(struct i2c_client *client) { int status; @@ -164,12 +79,7 @@ static int max15301_probe(struct i2c_client *client) return -ENODEV; } - max15301_data.delay = delay; - - info->read_byte_data = max15301_read_byte_data; - info->read_word_data = max15301_read_word_data; - info->write_byte = max15301_write_byte; - info->write_word_data = max15301_write_word_data; + info->access_delay = delay; return pmbus_do_probe(client, info); } From patchwork Mon Sep 2 07:53:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13786880 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 3C36917C7C6 for ; Mon, 2 Sep 2024 07:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263729; cv=none; b=gwQjbURGgt5XAiJddfAL91CbPzx4pWr7EnLgUHXONrmCGpqI/fZg87vvaAn+Qmr4FRZZRQtpWGXDrTH+hKpviKFbDxTlEi2titVgvYAdgEq0mg0D6cGQ0gYE4NgUOvNdC0pI8EpqJktNOHJTmRBcQ74g+pKxEPGoDYDN9Il2g00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263729; c=relaxed/simple; bh=aWOWSzyMeRbm3ItC9i35pWQz0CkR9clxZFABoapwEmA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fH+BcpmvrSMHUFsVB/viGDy8WvVgm5o83hAO6wMCDKD/eBRIc6iJIrURtGWspif8I1FTempAG1sxyItm6XcdxGU9ejHiRzi5f/K0MYwr2ifsAh6XtM45cOLQ1zNPAU+7ZUN+whqUXKqmtW6YxdY6x9n0TLUDS3yablYgnJks7Mw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=DydYV0CZ; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="DydYV0CZ" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8692bbec79so435086066b.3 for ; Mon, 02 Sep 2024 00:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1725263725; x=1725868525; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hsVXyLDSs2fFLBUKODkBzg9eUfumfnlE3Ahu+IB1q70=; b=DydYV0CZpJDFtWlk/tQhQckBANGBqtVInUku0qwk3b5mvUqajifVbFDcG0JTriIO1X Pdy+bdfktZCxi7KLzgJNErbdSeVon2TSCaOcmNfMR87GBZgYOy7EJXhDJzJChdBMTHf1 nBRToo6slDZnrLGBaE6E3ddh0OsHb4cgQuJXmVKF7K5HfkQ3hVQuDVMlZSLRsP4iQ62j q5aKeLWJKkmlW7Nx3AnueOyN3xov9dL6RsKyvxth2MRrXvgkT+rqs9p9cE0Sr2iAiEDz 04F9TT+6F/Kcaxdusy63ksJ/0YZqa+hHU9wh1WNMk6dwAW4hQ1qLjJ+F292CKGYYgC6S ZO8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725263725; x=1725868525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hsVXyLDSs2fFLBUKODkBzg9eUfumfnlE3Ahu+IB1q70=; b=aaxnOTMza/vmbsLMb/YI/bPgnkfUOFqE/H97w9WEwO/wHEAfSwamXwyXGczM90q2jl dm7YImwWfETQlErMdIgtz1ygdQ8lgCLgzeFsvF9G4okAXAKSBI+OWKfvYbp3AkvFdErt 6VvtDTMJngSfd3FnaMjbucvJcs8BarMX8rtpKUAXfIYmut7SegsxpjWbtKM/baVozkjx 1cz3Sm1OBkGLNV1HqiZUmgfdQ6/ETr5nztwLCEo413vROI9NelcxgR06aG+29Ib6PHEL qD/o9yVDbW3IDlB9pMpl8e1FdFSS/ME9VAMGP1bbdgKoGn5l84gzjy2tQTlWTZ99NC79 rn4g== X-Forwarded-Encrypted: i=1; AJvYcCWDIS8d/fKhZBZPx5JGrx2AI+TuSogVPNNPRIVR8nBeJiTWtHCRjI36NmeBLZC9MdqbIusqh5PyBc+otQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyHI/UXZiDm4GZjBGrVlI7PxyR24KG5C0nsKsK8GEV3uEChshOe DrmkYdtAfi2Adae+t5LVZ1LXyZhZYU+up2GPMk5obVrgokjaDt6YeOW17tQVSSE= X-Google-Smtp-Source: AGHT+IEBRtDc4jtuzw3Cb4zykGMMX4ofSyV73MtXmrgXfWD3fmQiUt5cg2UBsDskc07WY1CLzZzkjw== X-Received: by 2002:a17:907:72c7:b0:a86:a30f:4aef with SMTP id a640c23a62f3a-a89a35dee4cmr633103266b.22.1725263725486; Mon, 02 Sep 2024 00:55:25 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989022481sm521076066b.86.2024.09.02.00.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:55:25 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, Patrick Rudolph , linux-hwmon@vger.kernel.org Subject: [PATCH v3 3/5] hwmon: pmbus: ucd9000: Use generic code Date: Mon, 2 Sep 2024 09:53:14 +0200 Message-ID: <20240902075319.585656-3-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240902075319.585656-1-patrick.rudolph@9elements.com> References: <20240902075319.585656-1-patrick.rudolph@9elements.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use generic pmbus bus write access delay. Signed-off-by: Patrick Rudolph --- Changelog v2: - No change Changelog v3: - Added changelog drivers/hwmon/pmbus/ucd9000.c | 64 ++--------------------------------- 1 file changed, 2 insertions(+), 62 deletions(-) diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c index d817c719b90b..5d3d1773bf52 100644 --- a/drivers/hwmon/pmbus/ucd9000.c +++ b/drivers/hwmon/pmbus/ucd9000.c @@ -67,7 +67,6 @@ struct ucd9000_data { struct gpio_chip gpio; #endif struct dentry *debugfs; - ktime_t write_time; }; #define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info) @@ -86,63 +85,6 @@ struct ucd9000_debugfs_entry { */ #define UCD90320_WAIT_DELAY_US 500 -static inline void ucd90320_wait(const struct ucd9000_data *data) -{ - s64 delta = ktime_us_delta(ktime_get(), data->write_time); - - if (delta < UCD90320_WAIT_DELAY_US) - udelay(UCD90320_WAIT_DELAY_US - delta); -} - -static int ucd90320_read_word_data(struct i2c_client *client, int page, - int phase, int reg) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct ucd9000_data *data = to_ucd9000_data(info); - - if (reg >= PMBUS_VIRT_BASE) - return -ENXIO; - - ucd90320_wait(data); - return pmbus_read_word_data(client, page, phase, reg); -} - -static int ucd90320_read_byte_data(struct i2c_client *client, int page, int reg) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct ucd9000_data *data = to_ucd9000_data(info); - - ucd90320_wait(data); - return pmbus_read_byte_data(client, page, reg); -} - -static int ucd90320_write_word_data(struct i2c_client *client, int page, - int reg, u16 word) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct ucd9000_data *data = to_ucd9000_data(info); - int ret; - - ucd90320_wait(data); - ret = pmbus_write_word_data(client, page, reg, word); - data->write_time = ktime_get(); - - return ret; -} - -static int ucd90320_write_byte(struct i2c_client *client, int page, u8 value) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct ucd9000_data *data = to_ucd9000_data(info); - int ret; - - ucd90320_wait(data); - ret = pmbus_write_byte(client, page, value); - data->write_time = ktime_get(); - - return ret; -} - static int ucd9000_get_fan_config(struct i2c_client *client, int fan) { int fan_config = 0; @@ -667,10 +609,8 @@ static int ucd9000_probe(struct i2c_client *client) info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12 | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34; } else if (mid->driver_data == ucd90320) { - info->read_byte_data = ucd90320_read_byte_data; - info->read_word_data = ucd90320_read_word_data; - info->write_byte = ucd90320_write_byte; - info->write_word_data = ucd90320_write_word_data; + /* Delay SMBus operations after a write */ + info->write_delay = UCD90320_WAIT_DELAY_US; } ucd9000_probe_gpio(client, mid, data); From patchwork Mon Sep 2 07:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13786881 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 532F717E8E2 for ; Mon, 2 Sep 2024 07:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263730; cv=none; b=JRs93pdElh02c9M3p6MFdq3fAYg3zquZcq7tsChA0oJnLNymMxSbDekJII1VRXJb5KZsHrJurotwYtbbxRkuCG5MUgabSIw5ssekZouHX6WlyxPQWa9kVu5hxbeyPc2PVSYhzxyVFZopxPwB193H4GuHxgnHwHKvUtQBxVoMX+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263730; c=relaxed/simple; bh=vkdQQTtJMCaK7D9Qmffo/4tl8CP+rqpbSTlT3cc6OkY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ogo7wNmKW8aWfkYfQs1fDERCcjtKsE/RxfhezAbAeKBjetwgXvF90N4xGxLCCz39sUTvB3ZJa1Og/kaU5Lq1YC16YfczVgWSScs90AUg6tlZrWfrS1XQA+SZ4nTVhCIvptnZWDnkq1h2AC6IlihWUiBofcnVbOEfK1M78x4nTmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=Q/T3tJwd; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="Q/T3tJwd" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a86910caf9cso849414166b.1 for ; Mon, 02 Sep 2024 00:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1725263727; x=1725868527; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dYk1yMobC2+FZ4/7R3fu6ntVjIVPnY0mmcZFCjv/XxU=; b=Q/T3tJwd6Lt/wr7hzTOtuJ4CQjQ1RD9v/iwQENRkEPvcxVsewGbOUmF+de44DVX48t F7j0NmKskuvR1+geFD/cMLDbU+34d62FdDDun/duMNrcOTZ77JwxjcymLe4AZoSglRZW fNoKRy5fcAHQXKPN8r98/sfCBNk+b0hh4KeZNgH18LkKCW3C4XK5qwyqv9tGR+2kj6C7 lSFl/1VAXu81YW4nVxJGJKXlHYVroxmI3yXWpNFVEi59Qkl1GeJnG3FHDUNmNWiNbP9o K+AitZKQJMw8kqxHx9xitdFmytyZ/QdROHftepz15EingBrQvj8MEmpuyAy0lJJLp9Lf RiOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725263727; x=1725868527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dYk1yMobC2+FZ4/7R3fu6ntVjIVPnY0mmcZFCjv/XxU=; b=dMh/OlcBuoR1NCrDP0J5giB/B//05uUH8lyZmFGcNpN7CYkuootXpQdWAJjw0/6S9g ktBDAF6HwoLi4npLilZVkp/r5cfddyszjiASP9npZMFQPEzS2gy7Eq0q84OOFV5DszAP tJ17ydiV//5Avk9+GDvB4uabg84/3L/6newhybgBRIcgCDYOsrlv9YAHLUSNzZRvmOUf TrfNtia2bxdIOxRewrhee3u4QZfLQ8Jyse3ZLlykQEbb7pdA6K4OJIFv0Psy6Zi2HcAd zOdAu14DOxP1EfYWe0IYFpy4KSRnvft2tcrO5Aw2poyPucsdcaSoH5mX3xy1wmPJlT1a MUbw== X-Forwarded-Encrypted: i=1; AJvYcCXO1jwsQ4hgltCmXUrrIUTmkPXwN8JJaCjkgDzH8yOmFvvQzBAXYMH7KB6GI2RfpPj8YlUcbeDOJTNsfA==@vger.kernel.org X-Gm-Message-State: AOJu0YxBxBIKA6KtsmNBbPlRAaKfcIr8SwviNiREWyj9Shk8iV91aPtw cekZOKvam+1JNc3r2pHVff9XgvOZ0zPnMauKX7RXMBVm526E+Z/TdrZIIWfKhu62tzcusLc+KjH k X-Google-Smtp-Source: AGHT+IEMUGg64TB8U7G23ZOTGc8VE++MmnHcv0X5yhxZN5UsApokCoy7pUVSLQvYbqk9PTQT8I97dA== X-Received: by 2002:a17:907:da5:b0:a7a:130e:fb6e with SMTP id a640c23a62f3a-a898259d4f2mr1425756866b.15.1725263726724; Mon, 02 Sep 2024 00:55:26 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989022481sm521076066b.86.2024.09.02.00.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:55:26 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, Patrick Rudolph , linux-hwmon@vger.kernel.org Subject: [PATCH v3 4/5] hwmon: pmbus: zl6100: Use generic code Date: Mon, 2 Sep 2024 09:53:15 +0200 Message-ID: <20240902075319.585656-4-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240902075319.585656-1-patrick.rudolph@9elements.com> References: <20240902075319.585656-1-patrick.rudolph@9elements.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use generic pmbus bus access delay. Signed-off-by: Patrick Rudolph --- Changelog v2: - Drop now unused variables to make it compile Changelog v3: - Added changelog drivers/hwmon/pmbus/zl6100.c | 66 +++++------------------------------- 1 file changed, 8 insertions(+), 58 deletions(-) diff --git a/drivers/hwmon/pmbus/zl6100.c b/drivers/hwmon/pmbus/zl6100.c index 83458df0d0cf..7920a16203e1 100644 --- a/drivers/hwmon/pmbus/zl6100.c +++ b/drivers/hwmon/pmbus/zl6100.c @@ -22,8 +22,6 @@ enum chips { zl2004, zl2005, zl2006, zl2008, zl2105, zl2106, zl6100, zl6105, struct zl6100_data { int id; - ktime_t access; /* chip access time */ - int delay; /* Delay between chip accesses in uS */ struct pmbus_driver_info info; }; @@ -122,16 +120,6 @@ static u16 zl6100_d2l(long val) return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800); } -/* Some chips need a delay between accesses */ -static inline void zl6100_wait(const struct zl6100_data *data) -{ - if (data->delay) { - s64 delta = ktime_us_delta(ktime_get(), data->access); - if (delta < data->delay) - udelay(data->delay - delta); - } -} - static int zl6100_read_word_data(struct i2c_client *client, int page, int phase, int reg) { @@ -174,9 +162,7 @@ static int zl6100_read_word_data(struct i2c_client *client, int page, break; } - zl6100_wait(data); ret = pmbus_read_word_data(client, page, phase, vreg); - data->access = ktime_get(); if (ret < 0) return ret; @@ -195,14 +181,11 @@ static int zl6100_read_word_data(struct i2c_client *client, int page, static int zl6100_read_byte_data(struct i2c_client *client, int page, int reg) { const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct zl6100_data *data = to_zl6100_data(info); int ret, status; if (page >= info->pages) return -ENXIO; - zl6100_wait(data); - switch (reg) { case PMBUS_VIRT_STATUS_VMON: ret = pmbus_read_byte_data(client, 0, @@ -225,7 +208,6 @@ static int zl6100_read_byte_data(struct i2c_client *client, int page, int reg) ret = pmbus_read_byte_data(client, page, reg); break; } - data->access = ktime_get(); return ret; } @@ -234,8 +216,7 @@ static int zl6100_write_word_data(struct i2c_client *client, int page, int reg, u16 word) { const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct zl6100_data *data = to_zl6100_data(info); - int ret, vreg; + int vreg; if (page >= info->pages) return -ENXIO; @@ -265,27 +246,7 @@ static int zl6100_write_word_data(struct i2c_client *client, int page, int reg, vreg = reg; } - zl6100_wait(data); - ret = pmbus_write_word_data(client, page, vreg, word); - data->access = ktime_get(); - - return ret; -} - -static int zl6100_write_byte(struct i2c_client *client, int page, u8 value) -{ - const struct pmbus_driver_info *info = pmbus_get_driver_info(client); - struct zl6100_data *data = to_zl6100_data(info); - int ret; - - if (page >= info->pages) - return -ENXIO; - - zl6100_wait(data); - ret = pmbus_write_byte(client, page, value); - data->access = ktime_get(); - - return ret; + return pmbus_write_word_data(client, page, vreg, word); } static const struct i2c_device_id zl6100_id[] = { @@ -363,14 +324,7 @@ static int zl6100_probe(struct i2c_client *client) * supported chips are known to require a wait time between I2C * accesses. */ - data->delay = delay; - - /* - * Since there was a direct I2C device access above, wait before - * accessing the chip again. - */ - data->access = ktime_get(); - zl6100_wait(data); + udelay(delay); info = &data->info; @@ -404,8 +358,7 @@ static int zl6100_probe(struct i2c_client *client) if (ret < 0) return ret; - data->access = ktime_get(); - zl6100_wait(data); + udelay(delay); if (ret & ZL8802_MFR_PHASES_MASK) info->func[1] |= PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; @@ -418,8 +371,7 @@ static int zl6100_probe(struct i2c_client *client) if (ret < 0) return ret; - data->access = ktime_get(); - zl6100_wait(data); + udelay(delay); ret = i2c_smbus_read_word_data(client, ZL8802_MFR_USER_CONFIG); if (ret < 0) @@ -428,8 +380,7 @@ static int zl6100_probe(struct i2c_client *client) if (ret & ZL8802_MFR_XTEMP_ENABLE_2) info->func[i] |= PMBUS_HAVE_TEMP2; - data->access = ktime_get(); - zl6100_wait(data); + udelay(delay); } ret = i2c_smbus_read_word_data(client, ZL8802_MFR_USER_GLOBAL_CONFIG); if (ret < 0) @@ -446,13 +397,12 @@ static int zl6100_probe(struct i2c_client *client) info->func[0] |= PMBUS_HAVE_TEMP2; } - data->access = ktime_get(); - zl6100_wait(data); + udelay(delay); + info->access_delay = delay; info->read_word_data = zl6100_read_word_data; info->read_byte_data = zl6100_read_byte_data; info->write_word_data = zl6100_write_word_data; - info->write_byte = zl6100_write_byte; return pmbus_do_probe(client, info); } From patchwork Mon Sep 2 07:53:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13786882 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.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 0DBF9185B50 for ; Mon, 2 Sep 2024 07:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263731; cv=none; b=mYHnFWLWjsyXL2tCBlBhccQSBwiY48AFJ0dU4Oa6L6LmdCkuYsRH+pmrjJ2UrSsnwimZaJXJXs9a85LE0QbRSD6zrsMJ2SxjEBwn11mnFyUoyF0RPFQqrmsNSDSQ5kuTDfZjApWiQ+Vz2zewZ+c6u7B/qj5qLvdx5jWVULqmyBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725263731; c=relaxed/simple; bh=g88+rV3OZb7bY790ZHs+bSaBQ0kK1PuDYLwRhNwjZJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QRet5zghqDBpE6QRtptsTLJrRKpPShcC/4DLp0Blkdvf9Hz9PIQj93+I8rXSsR0P3TDc+Aci9tM9iZCxiTjGRuFzINUGmqb/2rrs5iyFMLeSYZ8m/Ic9vfoLoGR2rBok4VkNNh3WLowin6jU4M9u0S46p2Nmp31BgD7d2VqEUNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=NlhKgbJ/; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="NlhKgbJ/" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5c210e23573so3955567a12.0 for ; Mon, 02 Sep 2024 00:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1725263728; x=1725868528; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Qb7ceK/B/OV9H1eLIURr+7V31ikoGciE1WKE/XMoutk=; b=NlhKgbJ/9ib/uNv2Nj8WQfR3f+Ae8Y6ZUhmTTQYQacC2Awg4xh6AvzIz6kfWVRfkoX MVbKfkSTAMoi3FkhW1kEJU2fGPwLHPe5KU+admNcnnqebk+7GgFhNCEYhS98o+Y8j8oz HV1SNXyV8WYF4G4pFSWJWFt8HUR3d1dHtEXSdBt5uFtHWdeg3hiv+2WB0KOvDq9QHYw3 bpdqt+iAsC2/GKNn4PcYhBiEZg53vRhD2MvG34xCg0qYrf995bspvkyR8xMGVGHtaQYw +i7QwT4hpOcTfcycAVks8qzWhLP4FMfl5FPrKAvxs/WhyzmD1bOxF6LukbI8qlS2uihA MGtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725263728; x=1725868528; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qb7ceK/B/OV9H1eLIURr+7V31ikoGciE1WKE/XMoutk=; b=lXOnDw+bJCDKxHGDtcsaTbdyzUGufRihf6N6Zi7YVjYyED5ZM6S4eB6TYn0RhrMey0 7OFlFJWaH7eBEbgasDwJiIpn76G/fYoZADpjqm3fw4CBNeciZRd+oV3IEypKwVmhTKa1 ZqZaAPdQ0Bp83+zhm1UsS6780XvHo/7uDAZJiFlWzuDpkRYIu6nCzh0PkMvqsj1WGJAp QODdggCBt4l0xuWs/Ph408ojicJhF+ak3FpSMLsIQqX9e7vy4NeWW5yvsl137ycXwFFT cuXjqJG9hnrjMdihlOFVirwG8Z5dAEaVuSym2tkjiTsceE37N3LpDutuOuaeQcCyYnjt k/Mw== X-Forwarded-Encrypted: i=1; AJvYcCWWbpopurDtyMa2P/TL3KHax3DheZdO0w9nbcs++doU1neAVcxrAxLIXB9KiQPDRT2ghVs6rDxlXIlOHQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyCbUWmdG4zvIOlMxjdKYXo8zSypt+wtv0mgWCM7USs2obkgStk gZ4PJTPXDMGkgpMTLQGcRaGZh6pl6Jsgt5FjeU9RqummSFvfvlXFXnv4BUdF+ok= X-Google-Smtp-Source: AGHT+IHbIDyamXFnvl4gbct9/HlR5EYVuSaL7iRyKN6FCDoR3OKvvmjNyU60C3hFefxqL4LEPSCUPg== X-Received: by 2002:a17:906:f5a2:b0:a86:6a2b:3e57 with SMTP id a640c23a62f3a-a897f8e73b0mr1181403866b.29.1725263728339; Mon, 02 Sep 2024 00:55:28 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989022481sm521076066b.86.2024.09.02.00.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:55:28 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, Patrick Rudolph , linux-hwmon@vger.kernel.org Subject: [PATCH v3 5/5] hwmon: pmbus: pli12096bc: Add write delay Date: Mon, 2 Sep 2024 09:53:16 +0200 Message-ID: <20240902075319.585656-5-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240902075319.585656-1-patrick.rudolph@9elements.com> References: <20240902075319.585656-1-patrick.rudolph@9elements.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Tests on PLI12096bc showed that sometimes a small delay is necessary after a write operation before a new operation can be processed. If not respected the device will probably NACK the data phase of the SMBus transaction. Tests showed that the probability to observe transaction errors can be raised by either reading sensor data or toggling the regulator enable. Further tests showed that 250 microseconds, as used previously for the CLEAR_FAULTS workaround, is sufficient. Signed-off-by: Patrick Rudolph --- Changelog v2: - No change Changelog v3: - Added changelog drivers/hwmon/pmbus/pli1209bc.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/drivers/hwmon/pmbus/pli1209bc.c b/drivers/hwmon/pmbus/pli1209bc.c index 2c6c9ec2a652..178e0cdb7887 100644 --- a/drivers/hwmon/pmbus/pli1209bc.c +++ b/drivers/hwmon/pmbus/pli1209bc.c @@ -54,30 +54,6 @@ static int pli1209bc_read_word_data(struct i2c_client *client, int page, } } -static int pli1209bc_write_byte(struct i2c_client *client, int page, u8 reg) -{ - int ret; - - switch (reg) { - case PMBUS_CLEAR_FAULTS: - ret = pmbus_write_byte(client, page, reg); - /* - * PLI1209 takes 230 usec to execute the CLEAR_FAULTS command. - * During that time it's busy and NACKs all requests on the - * SMBUS interface. It also NACKs reads on PMBUS_STATUS_BYTE - * making it impossible to poll the BUSY flag. - * - * Just wait for not BUSY unconditionally. - */ - usleep_range(250, 300); - break; - default: - ret = -ENODATA; - break; - } - return ret; -} - #if IS_ENABLED(CONFIG_SENSORS_PLI1209BC_REGULATOR) static const struct regulator_desc pli1209bc_reg_desc = { .name = "vout2", @@ -127,7 +103,7 @@ static struct pmbus_driver_info pli1209bc_info = { | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_INPUT, .read_word_data = pli1209bc_read_word_data, - .write_byte = pli1209bc_write_byte, + .write_delay = 250, #if IS_ENABLED(CONFIG_SENSORS_PLI1209BC_REGULATOR) .num_regulators = 1, .reg_desc = &pli1209bc_reg_desc,