aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-10-28 14:31:50 -0400
committerJean Delvare <khali@endymion.delvare>2010-10-28 14:31:50 -0400
commitf6c61cff8bcb58b8dfb645d4243a049908c02024 (patch)
treebff2919dcf335f38cb36bdbd27fd5c5870e4b0e9
parentc36364dbf38382ef6be2fb99a3ce361a679c0ecb (diff)
hwmon: (lm85) Add support for ADT7468 high-frequency PWM mode
The ADT7468 supports a high-frequency PWM output mode where all PWM outputs are driven by a 22.5 kHz clock. Add support for this mode, and document it, as it may surprise the user that setting one PWM output frequency also affects the other PWM outputs. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Darrick J. Wong <djwong@us.ibm.com> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
-rw-r--r--Documentation/hwmon/lm857
-rw-r--r--drivers/hwmon/lm85.c35
2 files changed, 35 insertions, 7 deletions
diff --git a/Documentation/hwmon/lm85 b/Documentation/hwmon/lm85
index 83cd5bb1ac7..239258a63c8 100644
--- a/Documentation/hwmon/lm85
+++ b/Documentation/hwmon/lm85
@@ -101,6 +101,13 @@ Devices has confirmed this "bug". The ADT7463 is reported to work as
101described in the documentation. The current lm85 driver does not show the 101described in the documentation. The current lm85 driver does not show the
102offset register. 102offset register.
103 103
104The ADT7468 has a high-frequency PWM mode, where all PWM outputs are
105driven by a 22.5 kHz clock. This is a global mode, not per-PWM output,
106which means that setting any PWM frequency above 11.3 kHz will switch
107all 3 PWM outputs to a 22.5 kHz frequency. Conversely, setting any PWM
108frequency below 11.3 kHz will switch all 3 PWM outputs to a frequency
109between 10 and 100 Hz, which can then be tuned separately.
110
104See the vendor datasheets for more information. There is application note 111See the vendor datasheets for more information. There is application note
105from National (AN-1260) with some additional information about the LM85. 112from National (AN-1260) with some additional information about the LM85.
106The Analog Devices datasheet is very detailed and describes a procedure for 113The Analog Devices datasheet is very detailed and describes a procedure for
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 2e8f0c9458d..1e229847f37 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -64,9 +64,12 @@ enum chips {
64#define LM85_REG_VERSTEP 0x3f 64#define LM85_REG_VERSTEP 0x3f
65 65
66#define ADT7468_REG_CFG5 0x7c 66#define ADT7468_REG_CFG5 0x7c
67#define ADT7468_OFF64 0x01 67#define ADT7468_OFF64 (1 << 0)
68#define ADT7468_HFPWM (1 << 1)
68#define IS_ADT7468_OFF64(data) \ 69#define IS_ADT7468_OFF64(data) \
69 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) 70 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
71#define IS_ADT7468_HFPWM(data) \
72 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
70 73
71/* These are the recognized values for the above regs */ 74/* These are the recognized values for the above regs */
72#define LM85_COMPANY_NATIONAL 0x01 75#define LM85_COMPANY_NATIONAL 0x01
@@ -567,8 +570,14 @@ static ssize_t show_pwm_freq(struct device *dev,
567{ 570{
568 int nr = to_sensor_dev_attr(attr)->index; 571 int nr = to_sensor_dev_attr(attr)->index;
569 struct lm85_data *data = lm85_update_device(dev); 572 struct lm85_data *data = lm85_update_device(dev);
570 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map, 573 int freq;
571 data->pwm_freq[nr])); 574
575 if (IS_ADT7468_HFPWM(data))
576 freq = 22500;
577 else
578 freq = FREQ_FROM_REG(data->freq_map, data->pwm_freq[nr]);
579
580 return sprintf(buf, "%d\n", freq);
572} 581}
573 582
574static ssize_t set_pwm_freq(struct device *dev, 583static ssize_t set_pwm_freq(struct device *dev,
@@ -580,10 +589,22 @@ static ssize_t set_pwm_freq(struct device *dev,
580 long val = simple_strtol(buf, NULL, 10); 589 long val = simple_strtol(buf, NULL, 10);
581 590
582 mutex_lock(&data->update_lock); 591 mutex_lock(&data->update_lock);
583 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); 592 /* The ADT7468 has a special high-frequency PWM output mode,
584 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 593 * where all PWM outputs are driven by a 22.5 kHz clock.
585 (data->zone[nr].range << 4) 594 * This might confuse the user, but there's not much we can do. */
586 | data->pwm_freq[nr]); 595 if (data->type == adt7468 && val >= 11300) { /* High freq. mode */
596 data->cfg5 &= ~ADT7468_HFPWM;
597 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
598 } else { /* Low freq. mode */
599 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
600 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
601 (data->zone[nr].range << 4)
602 | data->pwm_freq[nr]);
603 if (data->type == adt7468) {
604 data->cfg5 |= ADT7468_HFPWM;
605 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
606 }
607 }
587 mutex_unlock(&data->update_lock); 608 mutex_unlock(&data->update_lock);
588 return count; 609 return count;
589} 610}