public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Tim Harvey <tharvey@gateworks.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	Robert Jones <rjones@gateworks.com>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hwmon: gsc-hwmon: add fan sensor
Date: Sun, 30 Aug 2020 08:11:00 -0700	[thread overview]
Message-ID: <20200830151100.GA168034@roeck-us.net> (raw)

On Thu, Aug 27, 2020 at 01:04:54PM -0700, Tim Harvey wrote:
> Add a fan sensor to report RPM's from a fan tach input.
> 
> Signed-off-by: Tim Harvey <tharvey@gateworks.com>

Applied.

Thanks,
Guenter

> --

Note there is a '-' missing here, causing the version history to be added
to the commit log. I dropped that.

> v2:
>  - avoid unnecessary line split and fix opening brace location
> ---
>  drivers/hwmon/gsc-hwmon.c               | 32 +++++++++++++++++++++++++++++---
>  include/linux/platform_data/gsc_hwmon.h |  1 +
>  2 files changed, 30 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/gsc-hwmon.c b/drivers/hwmon/gsc-hwmon.c
> index c6d4567..1fe3741 100644
> --- a/drivers/hwmon/gsc-hwmon.c
> +++ b/drivers/hwmon/gsc-hwmon.c
> @@ -17,6 +17,7 @@
>  
>  #define GSC_HWMON_MAX_TEMP_CH	16
>  #define GSC_HWMON_MAX_IN_CH	16
> +#define GSC_HWMON_MAX_FAN_CH	16
>  
>  #define GSC_HWMON_RESOLUTION	12
>  #define GSC_HWMON_VREF		2500
> @@ -27,11 +28,14 @@ struct gsc_hwmon_data {
>  	struct regmap *regmap;
>  	const struct gsc_hwmon_channel *temp_ch[GSC_HWMON_MAX_TEMP_CH];
>  	const struct gsc_hwmon_channel *in_ch[GSC_HWMON_MAX_IN_CH];
> +	const struct gsc_hwmon_channel *fan_ch[GSC_HWMON_MAX_FAN_CH];
>  	u32 temp_config[GSC_HWMON_MAX_TEMP_CH + 1];
>  	u32 in_config[GSC_HWMON_MAX_IN_CH + 1];
> +	u32 fan_config[GSC_HWMON_MAX_FAN_CH + 1];
>  	struct hwmon_channel_info temp_info;
>  	struct hwmon_channel_info in_info;
> -	const struct hwmon_channel_info *info[3];
> +	struct hwmon_channel_info fan_info;
> +	const struct hwmon_channel_info *info[4];
>  	struct hwmon_chip_info chip;
>  };
>  
> @@ -155,6 +159,9 @@ gsc_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
>  	case hwmon_temp:
>  		ch = hwmon->temp_ch[channel];
>  		break;
> +	case hwmon_fan:
> +		ch = hwmon->fan_ch[channel];
> +		break;
>  	default:
>  		return -EOPNOTSUPP;
>  	}
> @@ -187,6 +194,9 @@ gsc_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
>  		/* adjust by uV offset */
>  		tmp += ch->mvoffset;
>  		break;
> +	case mode_fan:
> +		tmp *= 30; /* convert to revolutions per minute */
> +		break;
>  	case mode_voltage_24bit:
>  	case mode_voltage_16bit:
>  		/* no adjustment needed */
> @@ -211,6 +221,9 @@ gsc_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type,
>  	case hwmon_temp:
>  		*buf = hwmon->temp_ch[channel]->name;
>  		break;
> +	case hwmon_fan:
> +		*buf = hwmon->fan_ch[channel]->name;
> +		break;
>  	default:
>  		return -ENOTSUPP;
>  	}
> @@ -304,7 +317,7 @@ static int gsc_hwmon_probe(struct platform_device *pdev)
>  	struct gsc_hwmon_platform_data *pdata = dev_get_platdata(dev);
>  	struct gsc_hwmon_data *hwmon;
>  	const struct attribute_group **groups;
> -	int i, i_in, i_temp;
> +	int i, i_in, i_temp, i_fan;
>  
>  	if (!pdata) {
>  		pdata = gsc_hwmon_get_devtree_pdata(dev);
> @@ -324,7 +337,7 @@ static int gsc_hwmon_probe(struct platform_device *pdev)
>  	if (IS_ERR(hwmon->regmap))
>  		return PTR_ERR(hwmon->regmap);
>  
> -	for (i = 0, i_in = 0, i_temp = 0; i < hwmon->pdata->nchannels; i++) {
> +	for (i = 0, i_in = 0, i_temp = 0, i_fan = 0; i < hwmon->pdata->nchannels; i++) {
>  		const struct gsc_hwmon_channel *ch = &pdata->channels[i];
>  
>  		switch (ch->mode) {
> @@ -338,6 +351,16 @@ static int gsc_hwmon_probe(struct platform_device *pdev)
>  						     HWMON_T_LABEL;
>  			i_temp++;
>  			break;
> +		case mode_fan:
> +			if (i_fan == GSC_HWMON_MAX_FAN_CH) {
> +				dev_err(gsc->dev, "too many fan channels\n");
> +				return -EINVAL;
> +			}
> +			hwmon->fan_ch[i_fan] = ch;
> +			hwmon->fan_config[i_fan] = HWMON_F_INPUT |
> +						   HWMON_F_LABEL;
> +			i_fan++;
> +			break;
>  		case mode_voltage_24bit:
>  		case mode_voltage_16bit:
>  		case mode_voltage_raw:
> @@ -361,10 +384,13 @@ static int gsc_hwmon_probe(struct platform_device *pdev)
>  	hwmon->chip.info = hwmon->info;
>  	hwmon->info[0] = &hwmon->temp_info;
>  	hwmon->info[1] = &hwmon->in_info;
> +	hwmon->info[2] = &hwmon->fan_info;
>  	hwmon->temp_info.type = hwmon_temp;
>  	hwmon->temp_info.config = hwmon->temp_config;
>  	hwmon->in_info.type = hwmon_in;
>  	hwmon->in_info.config = hwmon->in_config;
> +	hwmon->fan_info.type = hwmon_fan;
> +	hwmon->fan_info.config = hwmon->fan_config;
>  
>  	groups = pdata->fan_base ? gsc_hwmon_groups : NULL;
>  	hwmon_dev = devm_hwmon_device_register_with_info(dev,
> diff --git a/include/linux/platform_data/gsc_hwmon.h b/include/linux/platform_data/gsc_hwmon.h
> index 37a8f554d..281f499 100644
> --- a/include/linux/platform_data/gsc_hwmon.h
> +++ b/include/linux/platform_data/gsc_hwmon.h
> @@ -7,6 +7,7 @@ enum gsc_hwmon_mode {
>  	mode_voltage_24bit,
>  	mode_voltage_raw,
>  	mode_voltage_16bit,
> +	mode_fan,
>  	mode_max,
>  };
>  
> -- 
> 2.7.4
> 

             reply	other threads:[~2020-08-30 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-30 15:11 Guenter Roeck [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-08-27 20:04 [PATCH v2] hwmon: gsc-hwmon: add fan sensor Tim Harvey

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=20200830151100.GA168034@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjones@gateworks.com \
    --cc=tharvey@gateworks.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox