diff options
author | Guenter Roeck <linux@roeck-us.net> | 2019-08-08 12:53:03 -0700 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2019-09-03 12:47:17 -0700 |
commit | 7db0db3f6cced88af881520dd993c5b0044a7760 (patch) | |
tree | b8d86305de8d004a126699cc33e163ee5de8dd7d /drivers/hwmon | |
parent | 4a2d78822fdf1556dfbbfaedd71182fe5b562194 (diff) |
hwmon: (lm75) Support configuring the sample time for various chips
The conversion (sample) time is configurable for several chips supported
by the lm75 driver. With the necessary infrastructure in place, enable
this support for all chips using the configuration register for this
purpose.
DS1775:
Conversion time: 187.5, 375, 750, 1500 ms
Sensor resolution: 9, 10, 11, 12 bit
DS75, STDS75:
Conversion time: 150, 300, 600, 1200 ms
Sensor resolution: 9, 10, 11, 12 bit
DS7505:
Conversion time: 25, 50, 100, 200 ms
Sensor resolution: 9, 10, 11, 12 bit
MCP980[0123]:
Conversion time: 75, 150, 300, 600 ms
Sensor resolution: 9, 10, 11, 12 bit
TMP100, TMP101:
Conversion time: 75, 150, 300, 600 ms
Sensor resolution: 9, 10, 11, 12 bit
TMP75, TMP105, TMP175, TMP275:
Conversion time: 38, 75, 150, 300 ms
Sensor resolution: 9, 10, 11, 12 bit
While doing this, it became obvious that the masks and values to set
the converion (sample) time is similar for all those chips, and that
other chips with configurable sample times will need separate code anyway.
For that reason, replace the sample_set_masks and sample_clr_mask
configuration parameters with a single array and with a constant.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm75.c | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index f68ef9d451ab..6474b8f21981 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -73,10 +73,6 @@ enum lm75_type { /* keep sorted in alphabetical order */ * @sample_times: All the possible sample times to be set. Mandatory if * num_sample_times is larger than 1. If set, number of * entries must match num_sample_times. - * @sample_set_masks: All the set_masks for the possible sample times. - * Mandatory if num_sample_times is larger than 1. - * If set, number of entries must match num_sample_times. - * @sample_clr_mask: Clear mask used to set the sample time. */ struct lm75_params { @@ -88,8 +84,6 @@ struct lm75_params { unsigned int default_sample_time; u8 num_sample_times; const unsigned int *sample_times; - const u8 *sample_set_masks; - u8 sample_clr_mask; }; /* Addresses scanned */ @@ -115,6 +109,11 @@ struct lm75_data { }; /*-----------------------------------------------------------------------*/ + +static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 }; + +#define LM75_SAMPLE_CLEAR_MASK (3 << 5) + /* The structure below stores the configuration values of the supported devices. * In case of being supported multiple configurations, the default one must * always be the first element of the array @@ -129,19 +128,28 @@ static const struct lm75_params device_params[] = { .clr_mask = 3 << 5, .set_mask = 2 << 5, /* 11-bit mode */ .default_resolution = 11, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 750, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 188, 375, 750, 1500 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [ds75] = { .clr_mask = 3 << 5, .set_mask = 2 << 5, /* 11-bit mode */ .default_resolution = 11, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 600, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 150, 300, 600, 1200 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [stds75] = { .clr_mask = 3 << 5, .set_mask = 2 << 5, /* 11-bit mode */ .default_resolution = 11, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 600, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 150, 300, 600, 1200 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [stlm75] = { .default_resolution = 9, @@ -150,7 +158,10 @@ static const struct lm75_params device_params[] = { [ds7505] = { .set_mask = 3 << 5, /* 12-bit mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 4, + .default_sample_time = 200, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 25, 50, 100, 200 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [g751] = { .default_resolution = 9, @@ -194,56 +205,74 @@ static const struct lm75_params device_params[] = { .clr_mask = 1 << 7, /* not one-shot mode */ .default_resolution = 12, .resolution_limits = 9, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 240, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 75, 150, 300, 600 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp100] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode */ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 320, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 75, 150, 300, 600 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp101] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode */ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC, + .default_sample_time = 320, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 75, 150, 300, 600 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, - [tmp112] = { + [tmp105] = { .set_mask = 3 << 5, /* 12-bit mode */ - .clr_mask = 1 << 7, /* no one-shot mode*/ + .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 4, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, - [tmp105] = { + [tmp112] = { .set_mask = 3 << 5, /* 12-bit mode */ - .clr_mask = 1 << 7, /* not one-shot mode*/ + .clr_mask = 1 << 7, /* no one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = MSEC_PER_SEC / 4, }, [tmp175] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp275] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp75] = { .set_mask = 3 << 5, /* 12-bit mode */ .clr_mask = 1 << 7, /* not one-shot mode*/ .default_resolution = 12, - .default_sample_time = MSEC_PER_SEC / 2, + .default_sample_time = 220, + .num_sample_times = 4, + .sample_times = (unsigned int []){ 38, 75, 150, 300 }, + .resolutions = (u8 []) {9, 10, 11, 12 }, }, [tmp75b] = { /* not one-shot mode, Conversion rate 37Hz */ .clr_mask = 1 << 7 | 3 << 5, .default_resolution = 12, - .sample_set_masks = (u8 []){ 0 << 5, 1 << 5, 2 << 5, - 3 << 5 }, - .sample_clr_mask = 3 << 5, .default_sample_time = MSEC_PER_SEC / 37, .sample_times = (unsigned int []){ MSEC_PER_SEC / 37, MSEC_PER_SEC / 18, @@ -371,8 +400,8 @@ static int lm75_write_chip(struct device *dev, u32 attr, long val) (int)data->params->num_sample_times); err = lm75_write_config(data, - data->params->sample_set_masks[index], - data->params->sample_clr_mask); + lm75_sample_set_masks[index], + LM75_SAMPLE_CLEAR_MASK); if (err) return err; data->sample_time = data->params->sample_times[index]; |