All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jeffery <andrew@aj.id.au>
To: joel@jms.id.au
Cc: tpearson@raptorengineering.com, Andrew Jeffery <andrew@aj.id.au>,
	openbmc@lists.ozlabs.org, cbostic@linux.vnet.ibm.com,
	msbarth@linux.vnet.ibm.com
Subject: [RFC PATCH linux dev-4.10 3/7] hwmon: max31785: Document implementation oddities
Date: Fri,  2 Jun 2017 15:52:03 +0930	[thread overview]
Message-ID: <20170602062208.15999-4-andrew@aj.id.au> (raw)
In-Reply-To: <20170602062208.15999-1-andrew@aj.id.au>

Some possible bugs are discussed, and the implementation semantics of
fall-through cases in switch statements are documented.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 drivers/hwmon/max31785.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/max31785.c b/drivers/hwmon/max31785.c
index fb7b3f010bd8..ad86082ffc7d 100644
--- a/drivers/hwmon/max31785.c
+++ b/drivers/hwmon/max31785.c
@@ -167,7 +167,12 @@ static struct max31785_data *max31785_update_device(struct device *dev)
 			}
 
 			if (!is_automatic_control_mode(data, i)) {
-				/* Poke watchdog for manual fan control */
+				/*
+				 * Poke watchdog for manual fan control
+				 *
+				 * XXX: This isn't documented in the MAX31785
+				 * datasheet, or anywhere else.
+				 */
 				rv = max31785_write_fan_data(client,
 					i, MAX31785_REG_FAN_COMMAND_1,
 					data->fan_command[i], 0);
@@ -290,6 +295,7 @@ static ssize_t set_fan_pulses(struct device *dev,
 	if (pulses > 4)
 		return -EINVAL;
 
+	/* XXX: This sequence disables the fan and sets in PWM mode */
 	data->fan_config[attr->index] &= MAX31785_FAN_CFG_PULSE_MASK;
 	data->fan_config[attr->index] |=
 				((pulses - MAX31785_FAN_CFG_PULSE_OFFSET)
@@ -297,8 +303,23 @@ static ssize_t set_fan_pulses(struct device *dev,
 
 	mutex_lock(&data->device_lock);
 
-	/* Write new pulse value */
+	/*
+	 * XXX: This seems suspect. Pulses must be in [1, 4], however
+	 * fan_command expects the following ranges:
+	 *
+	 * PWM:
+	 * [0x0000, 0x2710]: [0, 100]% PWM duty cycle
+	 * [0x2711, 0x7fff]: 100% PWM duty cycle
+	 *
+	 * RPM:
+	 * [0x0000, 0x7fff]: [0, 32767]RPM
+	 * [0x8000, 0xffff]: Automatic fan control
+	 *
+	 * In all cases [1-4] is quite low
+	 */
 	data->fan_command[attr->index] = pulses;
+
+	/* Write new pulse value */
 	err = max31785_write_fan_data(client, attr->index,
 				MAX31785_REG_FAN_CONFIG_1_2,
 				data->fan_config[attr->index], 1);
@@ -408,8 +429,8 @@ static ssize_t set_pwm_enable(struct device *dev,
 			data->fan_config[attr->index]
 			& ~MAX31785_FAN_CFG_PWM_ENABLE;
 		break;
-	case 1:
-	case 2:
+	case 1: /* fallthrough */
+	case 2: /* fallthrough */
 	case 3:
 		data->fan_config[attr->index] =
 			data->fan_config[attr->index]
-- 
2.11.0

  parent reply	other threads:[~2017-06-02  6:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-02  6:22 [RFC PATCH linux dev-4.10 0/7] Add fast rotor reads to MAX31785 Andrew Jeffery
2017-06-02  6:22 ` [RFC PATCH linux dev-4.10 1/7] hwmon: Add support for MAX31785 intelligent fan controller Andrew Jeffery
2017-06-02  6:22 ` [RFC PATCH linux dev-4.10 2/7] arm: aspeed: Add MAX31785 to aspeed_g5_defconfig Andrew Jeffery
2017-06-02  6:22 ` Andrew Jeffery [this message]
2017-06-02  6:22 ` [RFC PATCH linux dev-4.10 4/7] hwmon: max31785: Adapt to new hwmon APIs Andrew Jeffery
2017-06-02  6:22 ` [RFC PATCH linux dev-4.10 5/7] i2c: Add bogus I2C_SMBUS_DWORD_DATA bus protocol/transaction type Andrew Jeffery
2017-06-02  6:22 ` [RFC PATCH linux dev-4.10 6/7] hwmon: max31785: Enable fast rotor measurement feature Andrew Jeffery
2017-06-02  6:22 ` [RFC PATCH linux dev-4.10 7/7] hwmon: max31785: Provide config of fault pin behavior Andrew Jeffery
2017-06-05  6:01 ` [RFC PATCH linux dev-4.10 0/7] Add fast rotor reads to MAX31785 Joel Stanley
2017-06-05  6:05   ` Andrew Jeffery

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170602062208.15999-4-andrew@aj.id.au \
    --to=andrew@aj.id.au \
    --cc=cbostic@linux.vnet.ibm.com \
    --cc=joel@jms.id.au \
    --cc=msbarth@linux.vnet.ibm.com \
    --cc=openbmc@lists.ozlabs.org \
    --cc=tpearson@raptorengineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.