diff mbox

[v3,4/4] hwmon: (adt7475) add high frequency support

Message ID 20170511034524.22698-5-chris.packham@alliedtelesis.co.nz (mailing list archive)
State Changes Requested
Headers show

Commit Message

Chris Packham May 11, 2017, 3:45 a.m. UTC
Systems using 4-wire fans usually require high frequency (22.5kHz)
output on the pwm. Add 22500 as a valid option in the pwmfreq_table. In
high frequency mode the low-order bit are ignored so they can safely be
set to 0.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v3:
- New

 drivers/hwmon/adt7475.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Chris Packham May 11, 2017, 9:31 p.m. UTC | #1
On 11/05/17 15:45, Chris Packham wrote:
> Systems using 4-wire fans usually require high frequency (22.5kHz)
> output on the pwm. Add 22500 as a valid option in the pwmfreq_table. In
> high frequency mode the low-order bit are ignored so they can safely be
> set to 0.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> Changes in v3:
> - New
>
>  drivers/hwmon/adt7475.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index f7322330789c..f5a65d1166cd 100644
> --- a/drivers/hwmon/adt7475.c
> +++ b/drivers/hwmon/adt7475.c
> @@ -936,7 +936,7 @@ static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
>
>  /* List of frequencies for the PWM */
>  static const int pwmfreq_table[] = {
> -	11, 14, 22, 29, 35, 44, 58, 88
> +	11, 14, 22, 29, 35, 44, 58, 88, 22500
>  };
>
>  static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
> @@ -944,9 +944,10 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
>  {
>  	struct adt7475_data *data = adt7475_update_device(dev);
>  	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
> +	int i = clamp_val(data->range[sattr->index] & 0xf, 0,
> +			  sizeof(pwmfreq_table));

Oops that should probably be

+			  ARRAY_SIZE(pwmfreq_table) - 1);

Guenter, do you want me to send a v4 or can you fix it up at your end?

>
> -	return sprintf(buf, "%d\n",
> -		       pwmfreq_table[data->range[sattr->index] & 7]);
> +	return sprintf(buf, "%d\n", pwmfreq_table[i]);
>  }
>
>  static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
> @@ -967,7 +968,7 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
>
>  	data->range[sattr->index] =
>  		adt7475_read(TEMP_TRANGE_REG(sattr->index));
> -	data->range[sattr->index] &= ~7;
> +	data->range[sattr->index] &= ~0xf;
>  	data->range[sattr->index] |= out;
>
>  	i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
>

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guenter Roeck May 14, 2017, 3:42 p.m. UTC | #2
On 05/11/2017 02:31 PM, Chris Packham wrote:
> On 11/05/17 15:45, Chris Packham wrote:
>> Systems using 4-wire fans usually require high frequency (22.5kHz)
>> output on the pwm. Add 22500 as a valid option in the pwmfreq_table. In
>> high frequency mode the low-order bit are ignored so they can safely be
>> set to 0.
>>
>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>> ---
>> Changes in v3:
>> - New
>>
>>  drivers/hwmon/adt7475.c | 9 +++++----
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
>> index f7322330789c..f5a65d1166cd 100644
>> --- a/drivers/hwmon/adt7475.c
>> +++ b/drivers/hwmon/adt7475.c
>> @@ -936,7 +936,7 @@ static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
>>
>>  /* List of frequencies for the PWM */
>>  static const int pwmfreq_table[] = {
>> -	11, 14, 22, 29, 35, 44, 58, 88
>> +	11, 14, 22, 29, 35, 44, 58, 88, 22500
>>  };
>>
>>  static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
>> @@ -944,9 +944,10 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
>>  {
>>  	struct adt7475_data *data = adt7475_update_device(dev);
>>  	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
>> +	int i = clamp_val(data->range[sattr->index] & 0xf, 0,
>> +			  sizeof(pwmfreq_table));
>
> Oops that should probably be
>
> +			  ARRAY_SIZE(pwmfreq_table) - 1);
>
> Guenter, do you want me to send a v4 or can you fix it up at your end?
>
Please resend together with patches 2 and 3.

Thanks,
Guenter

>>
>> -	return sprintf(buf, "%d\n",
>> -		       pwmfreq_table[data->range[sattr->index] & 7]);
>> +	return sprintf(buf, "%d\n", pwmfreq_table[i]);
>>  }
>>
>>  static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
>> @@ -967,7 +968,7 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
>>
>>  	data->range[sattr->index] =
>>  		adt7475_read(TEMP_TRANGE_REG(sattr->index));
>> -	data->range[sattr->index] &= ~7;
>> +	data->range[sattr->index] &= ~0xf;
>>  	data->range[sattr->index] |= out;
>>
>>  	i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),
>>
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index f7322330789c..f5a65d1166cd 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -936,7 +936,7 @@  static ssize_t set_pwmctrl(struct device *dev, struct device_attribute *attr,
 
 /* List of frequencies for the PWM */
 static const int pwmfreq_table[] = {
-	11, 14, 22, 29, 35, 44, 58, 88
+	11, 14, 22, 29, 35, 44, 58, 88, 22500
 };
 
 static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
@@ -944,9 +944,10 @@  static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr,
 {
 	struct adt7475_data *data = adt7475_update_device(dev);
 	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	int i = clamp_val(data->range[sattr->index] & 0xf, 0,
+			  sizeof(pwmfreq_table));
 
-	return sprintf(buf, "%d\n",
-		       pwmfreq_table[data->range[sattr->index] & 7]);
+	return sprintf(buf, "%d\n", pwmfreq_table[i]);
 }
 
 static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
@@ -967,7 +968,7 @@  static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
 
 	data->range[sattr->index] =
 		adt7475_read(TEMP_TRANGE_REG(sattr->index));
-	data->range[sattr->index] &= ~7;
+	data->range[sattr->index] &= ~0xf;
 	data->range[sattr->index] |= out;
 
 	i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(sattr->index),