From patchwork Mon Jul 15 07:30:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13733003 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 D8AEC6FC6 for ; Mon, 15 Jul 2024 07:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028676; cv=none; b=n6I9plMtTb3H9u6aor6YSUSulnzFrHbRmzw/e+SyNJLgKjQB+/27fKiGt7WK6Kcqr0QJhp57Fp0kqLzUq9tDJe+cXmQu7xiJc8mNErNCGS4R/Gt6AanvBq2PJF1V4s5Egx4R6JIiOBvt3869PUdYm3JcHwv1jsBWdG6vFGhgUWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028676; c=relaxed/simple; bh=Ou50GOAWw2kdAQfyu9TdIvfhc9Mn+WHegspwL46p4os=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Gkpii2B6Tt97Rx9tLTny5gK0qy6Ze2Jp1scBZV8kSrTx+3Xyx2VZU0cLXHkzTuI5qb9ETLo7fS0FA825FfYjQrJMChm9qhjE/IwUnVZDBMwE+AJHZN70FDNKzQr2CxGEEMP6i2XlxY3aXzAeRITtvYBpHkC51SnIfiv46I4lHOA= 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=XHqCVNGo; arc=none smtp.client-ip=209.85.208.49 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="XHqCVNGo" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-58b0dddab8cso6188290a12.0 for ; Mon, 15 Jul 2024 00:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1721028671; x=1721633471; 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=hIgbkIgpuhUUTyEP4yU6UO9nNgxyTbzBP+NM20P/uqs=; b=XHqCVNGoudZ+dIkKSuRmt8SPnmCQa5BD3Hko6ab21iD8oeyPk/JdoTwxu1R1r7ASb9 QrghwC3EoIwxojxDAs1NUJliwpPFD7JfAkmOAdTPQ2RlQFiSKWwbZd0m2UsKxk5veyzy SxuKPl9iHNfFzYzgVXwycBMwBqWtOM5oVWfyhB36JY6Gs9ylA3H0e3aPUBvWU2HKDof7 5zy5cLspb3PbUv9doQa/7xWTBblAwZn3prR3l4bPCIexaBlcVxWoYp/pNX5DrlXu+LPJ hAkNXcjMKUd+9aos9H6D87SIMFDlrQUx6oCgfJVZOOBnFhic76TdRdC/r/8yYCuE/XBQ K8hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721028671; x=1721633471; 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=hIgbkIgpuhUUTyEP4yU6UO9nNgxyTbzBP+NM20P/uqs=; b=jbcYyz1lF79LXGNJVlYO5CwHIhN8T0Rgr+Ne9u5kzoTDUWxRG6jMsInJuG5neJdalY YN76yGxy+NCOiDXrQnlHLWZGtofLRvnn2/DyhXjwSV3+I8Fr6eKHg7iSdX8qQS0DqVNG uolJaYV10Q2hxN+/gSxWIJSHhYR96E3Y32HR00XziDC8hQyBYEhcvpDm+em2um0t7sCR O4adR1xXUDpyXQUoxwMxE0mkmuqs5/y0Jq4HmPgrQFEUeQkDEujmgyujFcTen4IAJ/Ti 1rpwOeDszEYM8s6vtTjNtylNqw94DafqBZRMNXThe63+sfiSvuh5aXP8WA78LL7Mraks 6N2g== X-Forwarded-Encrypted: i=1; AJvYcCV8Hil60wDOkIxYsdK07HD8+YmUN43yDlgxeaoGoz7TJtAqpHypS97KPvGbZsX9FLr4VApUfZut1NIqudQoNoe8qN1bZZxdnu/+tLg= X-Gm-Message-State: AOJu0YxrKoqvl1kx93PI4bFYPm64rOz/egF4MkRPWMQeCmSJyCYYnVtf /bC39jilna3lFkPbVybHGm99bO+zR9LZwcNH62SW171nUwUGpwNTIkEXFX3FvvX7trvcQFuOe5U u X-Google-Smtp-Source: AGHT+IGxC2zo0wtaKuXtCJ6xzHcnTfen2wLQKORuc10rLBVJ/vL0HT7CauszKyAP6RYeVaxOw/kDVg== X-Received: by 2002:aa7:d98f:0:b0:57d:105c:c40c with SMTP id 4fb4d7f45d1cf-594bb67e9e9mr10785917a12.24.1721028671165; Mon, 15 Jul 2024 00:31:11 -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 4fb4d7f45d1cf-59cf7763236sm1274023a12.12.2024.07.15.00.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 00:31:10 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: Patrick Rudolph , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH 1/5] hwmon: pmbus: Implement generic bus access delay Date: Mon, 15 Jul 2024 09:30:58 +0200 Message-ID: <20240715073105.594221-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 --- 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..5cb093c898a1 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 inline void pmbus_optional_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) + udelay(info->access_delay - delta); + } else if (info->write_delay) { + delta = ktime_us_delta(ktime_get(), data->write_time); + + if (delta < info->write_delay) + udelay(info->write_delay - delta); + } +} + +/* Sets the last accessed timestamp for pmbus_optional_wait */ +static inline 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_optional_wait(client); rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); + pmbus_update_ts(client, true); if (rv < 0) return rv; + pmbus_optional_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_optional_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_optional_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_optional_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_optional_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_optional_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_optional_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_optional_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_optional_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, false); 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_optional_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_optional_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_optional_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_optional_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 Jul 15 07:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13733002 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.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 16C7513A240 for ; Mon, 15 Jul 2024 07:31:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028676; cv=none; b=LJq51o1N5Ow+txe9ldfsohGwp4gzP677lNrO5J51cotwPi8tT0bFtiRLd1Z5+yR3f+2rDjo6qpmutIXdr6GcEIrd7xtAop2zbLOvytmr0Dma5koM+c316V9y509fW+U3h8EKb5WgmEp6syvedPVFzmhpg9UAxi3eQyFMJ+Fmaf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028676; c=relaxed/simple; bh=tWz44zz6lM29PayvcPvj0KkLvjaLEEv6fqqBbA3P+WE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HHAveWh3lsAIg8tWMECPek3lQeDp5RnjAahb+m2cChzJE2Yc+jvEqbTppv/XJ1WLC/V64Wv/B02CqMfpeZD11J1ed2thY7+t6aDhqIVDWlsVaCLWvFThZARRJIH/Y/6KwhoR1DdZUHAd2bFPrCAYXqYhtL2HbrRiik/6lubvgys= 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=bXFgKJ9T; arc=none smtp.client-ip=209.85.208.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="bXFgKJ9T" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-58b966b41fbso4807964a12.1 for ; Mon, 15 Jul 2024 00:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1721028672; x=1721633472; 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=MwpJFValDdiHcvaMz/RllZFXslcWnajiskOco8CbPLY=; b=bXFgKJ9Tw7dbb1Rtaibo7K0Dc9LDufu1kDLEaG92czLv7DIu9UD+hSV0/nT0txT6V7 lmU+9b3YtYyPRJn0s0IaR7CgaEM9Wy/Dnk/aSoipg7ScGFgvXsPkFG9g6U/xj8b/66s5 E7jHIbVEaxCPa4CCAaF/4Sm8ZpF/MZHZkQ1qCenLfUf9/TMI63buJlafmv3H3Ij8MzhR Tc8iO1SQUxPgysRWfvll+B2Gy10C45BK66N7EnW4ys6UUmf034/NwVe5KMxniD098SaR vnpzHQWEijqMeKA8qzdjXeC3iIC8T0PAyeVqZRa44IcQDvu8xfiIPOB+YBo0MBKVUNXG qiSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721028672; x=1721633472; 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=MwpJFValDdiHcvaMz/RllZFXslcWnajiskOco8CbPLY=; b=XRqiOjiCv+V9dQPDPAFRrkFRIQAUnwrgvAItOstd/8ywsf7KVjFO1p7qLkRTB4/ub2 p6tpJlxJMIpTGglE336uTE/hSMq25hFf5tGZzPUpCd+TkSx6IpOVsO1m5U5ooi4ZDSQe clNjB/rdisZaBfmRsxjKCoLBzwvjTfDv8jcEH8zAZyc1OfucOLfMcSewTcx56b+ngV36 j85I9GXtG3e/mcYRFdAWNzZf0cgjtgTMA8MJdS/dvh5s9AunOptJXlQ8GMXjvgW29ZSy y6Qqq1YjNiuvSoMUaAzUjNsz+rrrLSux4jOtUk9KMriqMTsMbWSvN1LCNMZVBDgkcThh X7EA== X-Forwarded-Encrypted: i=1; AJvYcCV6aeIkvzOCDgiPTpjhBzuDK/LGKZ2R1VXPbyHpwl+3zVA78T3jmtTZ/kVbx4Tuz9oA3mPZtTIrb616Nzm6n9XuY0llNeHWjuq1bak= X-Gm-Message-State: AOJu0Yzt+/EgsYScexgVL0MbLuRGEjZ/C37V2Tb+VGEcG1Nfzqzw4Qsm n/GLyK44MjmcDpDPJpsTHNYO4jBn4LWq1Za8dUZaNg/fr2VvqGDPBI0s8naJP3k= X-Google-Smtp-Source: AGHT+IET9GugG9iq4Mjb01d+J2K+BOGdM7/WmeU/m7MyvFbZXnE0EoCj2FgfZMlYfbxYupY5KPnECg== X-Received: by 2002:a05:6402:1ecf:b0:586:12f6:c0fe with SMTP id 4fb4d7f45d1cf-594ba99755cmr14477598a12.5.1721028672463; Mon, 15 Jul 2024 00:31:12 -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 4fb4d7f45d1cf-59cf7763236sm1274023a12.12.2024.07.15.00.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 00:31:12 -0700 (PDT) From: Patrick Rudolph To: Daniel Nilsson Cc: Patrick Rudolph , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] hwmon: pmbus: max15301: Use generic code Date: Mon, 15 Jul 2024 09:30:59 +0200 Message-ID: <20240715073105.594221-2-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240715073105.594221-1-patrick.rudolph@9elements.com> References: <20240715073105.594221-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 --- 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 Jul 15 07:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13733004 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 BB65F18410A for ; Mon, 15 Jul 2024 07:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028677; cv=none; b=BBCBNKO10p+Hx/VnSbMZyRm3t4/3/DIQmm39XEr8N2uZDwYO3rAPictQFrA76OOqom2kqDiYWlBPGHs7bfUN/CEL2wzGzE0Ss5KIt5ySpdxHgyjE5KRZyFyXTSE1mZXdWVK+tEpdsZpx4u4h1f8SUZp/KnoaNUDcuUUpCiXclwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028677; c=relaxed/simple; bh=ELszuHUI2Sho29pe1aUjUExSj0Jd1K3H1CrC966SsaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PWTWJj5CaakuwCsm+qEIMSgBmrJBwGMtfNKDC0YY+i43k72HMUmXjigu/LPDUJ6Ka9gEKXuAYUqpXCVXheOf06jGaqTDzYN8oxXE1p45HqXPsddvZYwoJ9jIXFcrNg+ECBXLNsivkY13o+IikfL6OA8ajxQYmtYRhd3/GY+DBfY= 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=aCg0yyIq; arc=none smtp.client-ip=209.85.208.50 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="aCg0yyIq" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5854ac817afso4887403a12.2 for ; Mon, 15 Jul 2024 00:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1721028674; x=1721633474; 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=Rte73YBhPAaVfekdORAEqN2cWG8+g6DnTMOK+KE3CVI=; b=aCg0yyIqvUxEVjHLBe0exLt0PrKDreFYXOMpfTsiPTmX/RN4IoSak/B3lnRcOnhoQG aGNsyrAeuEib7fvnBFHa7QXJ8WWFRim0rckqhSQP0zdVIenOJVKlcyyhAaB6250YGlOA BXpbawxJ+owXVISyMYATovBplECP9ONAfKkINWeFnxF1aA4Dqvi4ZEfLGZ6txehJAlZl VANhg6ADqH3NHouvHZf1kuVkyI1D8P0FbUCINwV0Rw9Q+OqhTKIJc03eD7GI4+TuwFe3 +b4GaB9IoyBht/VK/lc4CZkRt+ilx47tMAfldvywjcIcUnkHUUTP7P+GALEMi7IJCGdi 8Exg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721028674; x=1721633474; 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=Rte73YBhPAaVfekdORAEqN2cWG8+g6DnTMOK+KE3CVI=; b=r1e3RF7u6QV4+yLRJHqSpTs+nl3XTx+gQ+kcwp7IzNWyAXv2xFx0Dlpp0HYFa0BoQv Xd90ARPlYaAQS1zI1FCinj7o0wxazmiUoSK/H54GDC1CThRloeD0vnj8ZfFHsLCyz/0s jKc7mpx4Nx/c1F0jlGT++CGr94hjmnTORn9ZkgfgiYdCM8afw+SI0ov6jbfM2Y80Hfph MYuo6mDfOQeY61R9zoxFAZ+VojR9zWrCjVtfx6au9PMjPMflZUynP7pEWLoHYoubvs1e u1gb9baWpI7JyKyVk4iPSRftDAhJDV/S3gPCXxHMl1XSucXJ0m33q9NdhoR5i/F7R/hd qIRw== X-Forwarded-Encrypted: i=1; AJvYcCUPTUHprA70c84bbneIgxYSW2sA1IKI+OBIj40UhZ9uY6pESKUMxS1nsNnUD2LVrVIn9wqisz9Ni5DKprbA3xKocyiwbqWc6B/MjgY= X-Gm-Message-State: AOJu0YzcbR5x7Gcqg17DTl5LeoJVtPjuzgARls7MEMYdkZo2g0gBBwaV mhpBMdCZn4hapKk4z79UYc5BaXhR7mWp13FyomvZ5LJAz3YWDK/C4V0Ee+Su0Ls= X-Google-Smtp-Source: AGHT+IHRbJ6yV7v/2MCAadhdZz+/1HuasIfVetVYq4oKDfUM7efr3Ya7KJSdKljBYgL0GzJ4CtJkaA== X-Received: by 2002:a05:6402:3406:b0:58a:e73f:6edb with SMTP id 4fb4d7f45d1cf-594bcab0181mr11008890a12.40.1721028673765; Mon, 15 Jul 2024 00:31:13 -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 4fb4d7f45d1cf-59cf7763236sm1274023a12.12.2024.07.15.00.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 00:31:13 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: Patrick Rudolph , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH 3/5] hwmon: pmbus: ucd9000: Use generic code Date: Mon, 15 Jul 2024 09:31:00 +0200 Message-ID: <20240715073105.594221-3-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240715073105.594221-1-patrick.rudolph@9elements.com> References: <20240715073105.594221-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 --- 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 Jul 15 07:31:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13733005 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.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 A9E7918411B for ; Mon, 15 Jul 2024 07:31:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028678; cv=none; b=WxgrAo6Dei359M20tl9QZEPxEz9GjUwCtakVUyiRnB19BRVQQyToGD+hz2/5ZKoZX7TJkWCFGiCF0Z9VlVUGSvS4EqtI8fShUuNpsSCOMyLNl0z1MOUiDg3riCeD+79mypnJElEuXIZbnu8pGmUj53pruKZsSOeMiEI07h57RYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028678; c=relaxed/simple; bh=tYZDDZWvBTpejG174O9PndlbXCIw+ayXufXLEKsZNvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OSgd7v9YcNrsClHj95V1Dar3/aIJDe03PN2zE+vKXDc5VYKE90s1Q4vVQ0QTrnWaAAGYixu8n7Dxeyfx5ZCws8zi4ZxpMbepLHp/F5IYBNe99Vmy9+8wiKXCiRm9HBMGGQu3cr+8XJopsrCqdBq+yINi/5sSp0qZGdwbGVeL5gk= 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=FlSG0SxL; arc=none smtp.client-ip=209.85.208.53 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="FlSG0SxL" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-58b0dddab63so5986854a12.3 for ; Mon, 15 Jul 2024 00:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1721028675; x=1721633475; 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=EPmtYZFgC7tRnIlhBHtUvekj0dLjjVnIqoGBl2RANU0=; b=FlSG0SxL1P6X0/xM6WooSp6caeNijUWZxCT9DZCFLVyhoJNgxDwSS+LEydNSV2m1n+ 6sLUkh7iS/lXXm8DjVkCk/XoYfYCV0nWfb/BGThp2Dmbkg5fxEj6GVWIx9iUz4qkOgXi eDekbXxm7gGgEBs6g3uUlKpdogelzXN2woodcFA2MO0dmeej28/820MtQBh8qcCytaVN lcfF+hip6Hi8Usya0h0vTpsm1J6BkqJ1UBqAPidgMgydimSG7Xn3DFM1ZfLJOHWVdNsa j8SdJ/0D0Xes+gBKxPXN4qpn+Ccrk/I8nZh9IM2FqEJldiB/f2H5gKiSamfwP4ifVQbO Ptiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721028675; x=1721633475; 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=EPmtYZFgC7tRnIlhBHtUvekj0dLjjVnIqoGBl2RANU0=; b=rW1kcn4UTljX+Cn8218ZtcowpG1Mt9sVN0tGeASVcKraGfSP9AX4ZqxgO7fUe9kFja iJ7ThhRUuMRrnG0oAUv29t0Ehh64vOnNpc6Qm9yQcjXR3R8K256bgywMjGOQrzvXVFaH hIBEHhsrWGtaYqByJX8QsY8+QtIGegRZ/xO2DmSE0nFAv2A35e0/0PWw6+GF78sDiLyr reJqjwKCS7G/NQZ3pGD32RAh7T2sKJtUFFqpDsGSNprpZlSFkUED9LfQjLy3kTzNsotZ k/r46mVtdlFkVeovyHu/su+3ZFf0NVSfQ6OermLc2VoAjDROWgze+hvP6SQxZmn1kTxp q82A== X-Forwarded-Encrypted: i=1; AJvYcCVCJKFSfvWWs96Qgfkf0VvX4Yk1GhRsax+IzhWuQyddMSwhAK7Uy3vsv4fq5Vua8Ap/KU3h2AMRZhL3dQceoTsUaF0OaBjAlgYbEC4= X-Gm-Message-State: AOJu0YzACy7K6jp4ihvxJNzfzDbMlnZmea/nlKcveiEE0M0uvZGPbuPa A2q8j0SBtKSwOCe6Sf1CipNRvN1ACU1Wtww8u1wI8fF12RwQvAPWf2emI3akoxo= X-Google-Smtp-Source: AGHT+IHbwLHHpEgp1M+yBnPEp7huvSBAXcSkrjZ0jnOnstKvKPQTyQUZBkqzrsps3dIIX3VapopV0w== X-Received: by 2002:a05:6402:1d54:b0:587:2dcd:d930 with SMTP id 4fb4d7f45d1cf-594ba0cbe58mr13813838a12.17.1721028675094; Mon, 15 Jul 2024 00:31:15 -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 4fb4d7f45d1cf-59cf7763236sm1274023a12.12.2024.07.15.00.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 00:31:14 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: Patrick Rudolph , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH 4/5] hwmon: pmbus: zl6100: Use generic code Date: Mon, 15 Jul 2024 09:31:01 +0200 Message-ID: <20240715073105.594221-4-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240715073105.594221-1-patrick.rudolph@9elements.com> References: <20240715073105.594221-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 --- drivers/hwmon/pmbus/zl6100.c | 62 ++++-------------------------------- 1 file changed, 7 insertions(+), 55 deletions(-) diff --git a/drivers/hwmon/pmbus/zl6100.c b/drivers/hwmon/pmbus/zl6100.c index 83458df0d0cf..a2aff76325fb 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; @@ -201,8 +187,6 @@ static int zl6100_read_byte_data(struct i2c_client *client, int page, int reg) 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 +209,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; } @@ -265,27 +248,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 +326,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 +360,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 +373,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 +382,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 +399,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 Jul 15 07:31:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 13733006 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.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 0909F1849D0 for ; Mon, 15 Jul 2024 07:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028680; cv=none; b=YAGgpI8fqL38Y/Yuog+N/iSHpSbtQlyV2iSYkWZI/3SYi/bPZs4fa2NShXwX7DdkAGJYa746awgrBx3AJFaukxozgAGrQlJ2veCXpFNopCtsp8JCODG8qWstD7ulmofrnpy3iIhkWsnoGNfw1d3a7k/zrEO7TA2Pc01hg1j5NKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721028680; c=relaxed/simple; bh=msdvHICFqZBk3Qmz2OXLcwYLDlWXsaOJTSf+xIoW5K8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V59RsNtE594b21Xhbg0NudIO6RXx4kFSKoPTp94BW14GPUK2P68oMnzApjzcwMAcbIqWGodcpspvBvgaHBiFdANBvzVscsOdAIjp58CM3t/yppf25Bvl0e0NF0IaryH6HALvOP6qntk97Rw3FbvoAsicnExRmU+guILpFaXebHc= 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=Xz3s8Kf+; arc=none smtp.client-ip=209.85.208.53 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="Xz3s8Kf+" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-595856e2332so5015964a12.1 for ; Mon, 15 Jul 2024 00:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1721028677; x=1721633477; 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=7H+3a2UnmA5NVXZ9zwW5RQvv7oqwdwKXWiUEHwm4fFk=; b=Xz3s8Kf+WTojUkDnICtQoLmdoYQPcZaLg2nE8jhzkxBony45vvT2vWqTqHPHZYOdKB 66Y7eViW4jKqCXszu3lY9vpzQoZDZcz40gBbjloVSPg38460pYk3v7DghIJVMtIZhaMy qiGPMYtbQs93uBQAXj6Q5meeRNyV90YDgVjjO/4HHyMfB3/5Ck8UawaRb0E8XQvyrPFi nLQ9SUFOSjnJ2aFb9vtW6FDkIYryhz+6ivqaQ0QORM6hncfJ7D8El/jWCEy6QaXzQuXQ nUYtF6uE+8BcQcqs2fz4lh2Zm4L9umVjhmPpCwpwMSNJTi/3N7Jh6M3rVbok6huCe644 sjhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721028677; x=1721633477; 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=7H+3a2UnmA5NVXZ9zwW5RQvv7oqwdwKXWiUEHwm4fFk=; b=gesX+oD8MXhU8QkS5Ir51/2zbcxOSYYxhjOrD9rIEDTcOuKrRQQxGFA1X9zHHYNUkl WUToosiLtpeI7GDym/+6sJ9R+RQrs3vPjkfJL9jNeLRIVNcM+0UYBPDwhCLmGPjvn+RT KohdHSw0gHY6tvkDhR2MSe0wvI76VeobrSvPQ74OoTXypo8KttKSE3fuc/nHnF+KGFCo XrVuMLIbisfM6ckHU5ER7X0tqkHtGz0NrrckGK4oeLxLQ2J03Wq5+Virnkr7hECOS46j FSuHA0aemK0rtcyHWmzo5iUW6DYIAlJBi2BFiThDhaw2wa2IwrmNS5A6QEEwYPvfujXE IU4Q== X-Forwarded-Encrypted: i=1; AJvYcCUHOYNxXzVBvtzECeweE5yC54GVM+exhJL6aEmw+WZhO2AOMf59mJ+qTOmoriNaLVCzvAczPiY7DyLfqQRdFwIY81MgnPU5fnleh3Y= X-Gm-Message-State: AOJu0YyqgpKgbbBcBeMgGtDyxlQtibk9po7DXudAt8E5e915LSARPL/l JTCco2cYhIwtlIFbD5BgIZBhihetTXYPDWzNLBactfhE/nrHUVgdETBy1GFEoxk= X-Google-Smtp-Source: AGHT+IHnUUX2ROHLKdUMz/8YZsTBxpX8KbBG7oBgLNCvKmKvPz20CS13QNSFgp78xwmOKgcSET5u1g== X-Received: by 2002:a05:6402:2707:b0:57d:10c:6c40 with SMTP id 4fb4d7f45d1cf-594ba98e3c7mr14379033a12.7.1721028676341; Mon, 15 Jul 2024 00:31:16 -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 4fb4d7f45d1cf-59cf7763236sm1274023a12.12.2024.07.15.00.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jul 2024 00:31:16 -0700 (PDT) From: Patrick Rudolph To: linux-kernel@vger.kernel.org Cc: Patrick Rudolph , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Subject: [PATCH 5/5] hwmon: pmbus: pli12096bc: Add write delay Date: Mon, 15 Jul 2024 09:31:02 +0200 Message-ID: <20240715073105.594221-5-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240715073105.594221-1-patrick.rudolph@9elements.com> References: <20240715073105.594221-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 --- 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,