All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux dev-4.10] drivers/hwmon: max31785 Set fan fault response based on dev tree
@ 2017-06-20 18:37 Christopher Bostic
  2017-06-21  5:05 ` Joel Stanley
  0 siblings, 1 reply; 2+ messages in thread
From: Christopher Bostic @ 2017-06-20 18:37 UTC (permalink / raw)
  To: joel; +Cc: Christopher Bostic, openbmc

Check for the optional device tree property 'fault-max-fan'.  If
present, configure hardware for 100% PWM fan duty cycle on fault
condition.

Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
---
v3 - Change bit field definition to use macro BIT(x)
   - Set all 6 fans to same fault response
   - Rename fault response register #define to match the spec

v2 - Set 4 fans to same fault response
---
 drivers/hwmon/max31785.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/hwmon/max31785.c b/drivers/hwmon/max31785.c
index fc03b7c..4010504 100644
--- a/drivers/hwmon/max31785.c
+++ b/drivers/hwmon/max31785.c
@@ -38,6 +38,7 @@
 #define MAX31785_REG_MFR_ID			0x99
 #define MAX31785_REG_MFR_MODEL			0x9a
 #define MAX31785_REG_MFR_REVISION		0x9b
+#define MAX31785_REG_MFR_FAULT_RESP		0xd9
 #define MAX31785_REG_MFR_FAN_CONFIG		0xf1
 #define MAX31785_REG_READ_FAN_PWM		0xf3
 
@@ -51,6 +52,9 @@
 /* Fan Status register bits */
 #define MAX31785_FAN_STATUS_FAULT_MASK		0x80
 
+/* Fault response register bits */
+#define MAX31785_FAULT_PIN_MONITOR		BIT(0)
+
 /* Fan Command constants */
 #define MAX31785_FAN_COMMAND_PWM_RATIO		40
 
@@ -762,6 +766,35 @@ static int max31785_get_capabilities(struct max31785 *data)
 	return 0;
 }
 
+static int max31785_init_fault_resp(struct i2c_client *client)
+{
+	struct device_node *np = client->dev.of_node;
+	int page;
+	int rc;
+
+	if (np && of_get_property(np, "fault-max-fan", NULL)) {
+		for (page = 0; page < NR_CHANNEL; page++) {
+
+			/* set max fans on fault */
+			rc = max31785_set_page(client, page);
+			if (rc < 0)
+				return rc;
+
+			rc = i2c_smbus_read_byte_data(client,
+					MAX31785_REG_MFR_FAULT_RESP);
+			if (rc < 0)
+				return rc;
+
+			rc |= MAX31785_FAULT_PIN_MONITOR;
+			rc = i2c_smbus_write_byte_data(client,
+					MAX31785_REG_MFR_FAULT_RESP, rc);
+		}
+		return rc;
+	}
+
+	return 0;
+}
+
 static int max31785_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
@@ -783,6 +816,10 @@ static int max31785_probe(struct i2c_client *client,
 	data->client = client;
 	mutex_init(&data->lock);
 
+	rc = max31785_init_fault_resp(client);
+	if (rc)
+		return rc;
+
 	rc = max31785_init_fans(data);
 	if (rc)
 		return rc;
-- 
1.8.2.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH linux dev-4.10] drivers/hwmon: max31785 Set fan fault response based on dev tree
  2017-06-20 18:37 [PATCH linux dev-4.10] drivers/hwmon: max31785 Set fan fault response based on dev tree Christopher Bostic
@ 2017-06-21  5:05 ` Joel Stanley
  0 siblings, 0 replies; 2+ messages in thread
From: Joel Stanley @ 2017-06-21  5:05 UTC (permalink / raw)
  To: Christopher Bostic; +Cc: OpenBMC Maillist

On Wed, Jun 21, 2017 at 4:07 AM, Christopher Bostic
<cbostic@linux.vnet.ibm.com> wrote:
> Check for the optional device tree property 'fault-max-fan'.  If
> present, configure hardware for 100% PWM fan duty cycle on fault
> condition.
>
> Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
> ---
> v3 - Change bit field definition to use macro BIT(x)
>    - Set all 6 fans to same fault response
>    - Rename fault response register #define to match the spec

Applied to dev-4.10.

Cheers,

Joel

>
> v2 - Set 4 fans to same fault response
> ---
>  drivers/hwmon/max31785.c | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
>
> diff --git a/drivers/hwmon/max31785.c b/drivers/hwmon/max31785.c
> index fc03b7c..4010504 100644
> --- a/drivers/hwmon/max31785.c
> +++ b/drivers/hwmon/max31785.c
> @@ -38,6 +38,7 @@
>  #define MAX31785_REG_MFR_ID                    0x99
>  #define MAX31785_REG_MFR_MODEL                 0x9a
>  #define MAX31785_REG_MFR_REVISION              0x9b
> +#define MAX31785_REG_MFR_FAULT_RESP            0xd9
>  #define MAX31785_REG_MFR_FAN_CONFIG            0xf1
>  #define MAX31785_REG_READ_FAN_PWM              0xf3
>
> @@ -51,6 +52,9 @@
>  /* Fan Status register bits */
>  #define MAX31785_FAN_STATUS_FAULT_MASK         0x80
>
> +/* Fault response register bits */
> +#define MAX31785_FAULT_PIN_MONITOR             BIT(0)
> +
>  /* Fan Command constants */
>  #define MAX31785_FAN_COMMAND_PWM_RATIO         40
>
> @@ -762,6 +766,35 @@ static int max31785_get_capabilities(struct max31785 *data)
>         return 0;
>  }
>
> +static int max31785_init_fault_resp(struct i2c_client *client)
> +{
> +       struct device_node *np = client->dev.of_node;
> +       int page;
> +       int rc;
> +
> +       if (np && of_get_property(np, "fault-max-fan", NULL)) {

For reference, you can use of_property_read_bool here.

> +               for (page = 0; page < NR_CHANNEL; page++) {
> +
> +                       /* set max fans on fault */
> +                       rc = max31785_set_page(client, page);
> +                       if (rc < 0)
> +                               return rc;
> +
> +                       rc = i2c_smbus_read_byte_data(client,
> +                                       MAX31785_REG_MFR_FAULT_RESP);
> +                       if (rc < 0)
> +                               return rc;
> +
> +                       rc |= MAX31785_FAULT_PIN_MONITOR;
> +                       rc = i2c_smbus_write_byte_data(client,
> +                                       MAX31785_REG_MFR_FAULT_RESP, rc);
> +               }
> +               return rc;
> +       }
> +
> +       return 0;
> +}
> +
>  static int max31785_probe(struct i2c_client *client,
>                           const struct i2c_device_id *id)
>  {
> @@ -783,6 +816,10 @@ static int max31785_probe(struct i2c_client *client,
>         data->client = client;
>         mutex_init(&data->lock);
>
> +       rc = max31785_init_fault_resp(client);
> +       if (rc)
> +               return rc;
> +
>         rc = max31785_init_fans(data);
>         if (rc)
>                 return rc;
> --
> 1.8.2.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-21  5:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-20 18:37 [PATCH linux dev-4.10] drivers/hwmon: max31785 Set fan fault response based on dev tree Christopher Bostic
2017-06-21  5:05 ` Joel Stanley

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.