diff mbox series

[linux,dev-5.8,3/3] ucd9000: Add a throttle delay attribute in debugfs

Message ID 20200902071736.2578715-4-andrew@aj.id.au
State New
Headers show
Series i2c: Introduce transfer throttling | expand

Commit Message

Andrew Jeffery Sept. 2, 2020, 7:17 a.m. UTC
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 drivers/hwmon/pmbus/ucd9000.c | 39 ++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c
index 7ba400d62475..23036f1b1bd1 100644
--- a/drivers/hwmon/pmbus/ucd9000.c
+++ b/drivers/hwmon/pmbus/ucd9000.c
@@ -401,6 +401,37 @@  static int ucd9000_debugfs_show_mfr_status_bit(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_mfr_status_bit,
 			 ucd9000_debugfs_show_mfr_status_bit, NULL, "%1lld\n");
 
+#define UCD9000_SMBUS_THROTTLE_US	1000
+static int throttle_delay_us = UCD9000_SMBUS_THROTTLE_US;
+
+static int ucd9000_debugfs_show_smbus_throttle_delay(void *data,
+						     u64 *val)
+{
+	struct i2c_client *client = data;
+	unsigned long ulval;
+	int rc;
+
+	rc = i2c_smbus_throttle_value(client, &ulval);
+	if (rc)
+		return rc;
+
+	*val = ulval;
+
+	return 0;
+}
+
+static int ucd9000_debugfs_store_smbus_throttle_delay(void *data,
+						      u64 val)
+{
+	struct i2c_client *client = data;
+
+	throttle_delay_us = val;
+	return i2c_smbus_throttle_client(client, val);
+}
+DEFINE_DEBUGFS_ATTRIBUTE(ucd9000_debugfs_smbus_throttle_delay,
+			 ucd9000_debugfs_show_smbus_throttle_delay,
+			 ucd9000_debugfs_store_smbus_throttle_delay, "%llu\n");
+
 static ssize_t ucd9000_debugfs_read_mfr_status(struct file *file,
 					       char __user *buf, size_t count,
 					       loff_t *ppos)
@@ -475,6 +506,8 @@  static int ucd9000_init_debugfs(struct i2c_client *client,
 	scnprintf(name, UCD9000_DEBUGFS_NAME_LEN, "mfr_status");
 	debugfs_create_file(name, 0444, data->debugfs, client,
 			    &ucd9000_debugfs_show_mfr_status_fops);
+	debugfs_create_file("smbus_throttle_delay", 0664, data->debugfs, client,
+			    &ucd9000_debugfs_smbus_throttle_delay);
 
 	return 0;
 }
@@ -487,8 +520,6 @@  static int ucd9000_init_debugfs(struct i2c_client *client,
 }
 #endif /* CONFIG_DEBUG_FS */
 
-#define UCD9000_SMBUS_THROTTLE_US	1000
-
 static int ucd9000_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -504,7 +535,9 @@  static int ucd9000_probe(struct i2c_client *client,
 				     I2C_FUNC_SMBUS_BLOCK_DATA))
 		return -ENODEV;
 
-	i2c_smbus_throttle_client(client, UCD9000_SMBUS_THROTTLE_US);
+	ret = i2c_smbus_throttle_client(client, throttle_delay_us);
+	if (ret)
+		return ret;
 
 	ret = i2c_smbus_read_block_data(client, UCD9000_DEVICE_ID,
 					block_buffer);