linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Eliav Farber <farbere@amazon.com>
Cc: jdelvare@suse.com, robh+dt@kernel.org, mark.rutland@arm.com,
	linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, talel@amazon.com,
	hhhawa@amazon.com, jonnyc@amazon.com, hanochu@amazon.com,
	ronenk@amazon.com, itamark@amazon.com, shellykz@amazon.com,
	shorer@amazon.com, amitlavi@amazon.com, almogbs@amazon.com,
	dwmw@amazon.co.uk, rtanwar@maxlinear.com
Subject: Re: [PATCH v2 16/16] hwmon: (mr75203) add debugfs to read and write temperature coefficients
Date: Thu, 18 Aug 2022 16:11:06 -0700	[thread overview]
Message-ID: <20220818231106.GA3505191@roeck-us.net> (raw)
In-Reply-To: <20220817054321.6519-17-farbere@amazon.com>

On Wed, Aug 17, 2022 at 05:43:21AM +0000, Eliav Farber wrote:
> This change adds debugfs to read and write TS coefficients - g, h, j and
> cal5.
> 
> The coefficients can vary between product and product, so to calibrate
> them it can be very useful to to be able to modify them on the fly.
> 
> e.g.
> 
> cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_cal5
> 4096
> 
> echo 83000 > sys/kernel/debug/940f23d0000.pvt/ts_coeff_g
> 

What happens if you write 0 into all those attributes, or 0xffffffff ?

Guenter

> Signed-off-by: Eliav Farber <farbere@amazon.com>
> ---
>  drivers/hwmon/mr75203.c | 196 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 196 insertions(+)
> 
> diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
> index 2898565afaab..ce34a44237e8 100644
> --- a/drivers/hwmon/mr75203.c
> +++ b/drivers/hwmon/mr75203.c
> @@ -9,6 +9,7 @@
>   */
>  #include <linux/bits.h>
>  #include <linux/clk.h>
> +#include <linux/debugfs.h>
>  #include <linux/hwmon.h>
>  #include <linux/module.h>
>  #include <linux/mod_devicetable.h>
> @@ -127,6 +128,7 @@ struct pvt_device {
>  	struct clk		*clk;
>  	struct reset_control	*rst;
>  	struct voltage_device	*vd;
> +	struct dentry		*dbgfs_dir;
>  	u32			t_num;
>  	u32			p_num;
>  	u32			v_num;
> @@ -139,6 +141,198 @@ struct pvt_device {
>  	u8			vm_ch_total;
>  };
>  
> +static ssize_t pvt_ts_coeff_h_read(struct file *file,
> +				   char __user *user_buf,
> +				   size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	char buf[16];
> +	unsigned int len;
> +
> +	len = sprintf(buf, "%u\n", pvt->ts_coeff_h);
> +
> +	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
> +}
> +
> +static ssize_t pvt_ts_coeff_h_write(struct file *file,
> +				    const char __user *user_buf,
> +				    size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	int ret;
> +	u32 coeff;
> +
> +	ret = kstrtou32_from_user(user_buf, count, 0, &coeff);
> +	if (ret)
> +		return ret;
> +
> +	pvt->ts_coeff_h = coeff;
> +
> +	return count;
> +}
> +
> +static const struct file_operations pvt_ts_coeff_h_fops = {
> +	.read = pvt_ts_coeff_h_read,
> +	.write = pvt_ts_coeff_h_write,
> +	.open = simple_open,
> +	.owner = THIS_MODULE,
> +	.llseek = default_llseek,
> +};
> +
> +static ssize_t pvt_ts_coeff_g_read(struct file *file,
> +				   char __user *user_buf,
> +				   size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	char buf[16];
> +	unsigned int len;
> +
> +	len = sprintf(buf, "%u\n", pvt->ts_coeff_g);
> +
> +	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
> +}
> +
> +static ssize_t pvt_ts_coeff_g_write(struct file *file,
> +				    const char __user *user_buf,
> +				    size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	int ret;
> +	u32 coeff;
> +
> +	ret = kstrtou32_from_user(user_buf, count, 0, &coeff);
> +	if (ret)
> +		return ret;
> +
> +	pvt->ts_coeff_g = coeff;
> +
> +	return count;
> +}
> +
> +static const struct file_operations pvt_ts_coeff_g_fops = {
> +	.read = pvt_ts_coeff_g_read,
> +	.write = pvt_ts_coeff_g_write,
> +	.open = simple_open,
> +	.owner = THIS_MODULE,
> +	.llseek = default_llseek,
> +};
> +
> +static ssize_t pvt_ts_coeff_j_read(struct file *file,
> +				   char __user *user_buf,
> +				   size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	char buf[16];
> +	unsigned int len;
> +
> +	len = sprintf(buf, "%d\n", pvt->ts_coeff_j);
> +
> +	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
> +}
> +
> +static ssize_t pvt_ts_coeff_j_write(struct file *file,
> +				    const char __user *user_buf,
> +				    size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	int ret;
> +	s32 coeff;
> +
> +	ret = kstrtos32_from_user(user_buf, count, 0, &coeff);
> +	if (ret)
> +		return ret;
> +
> +	pvt->ts_coeff_j = coeff;
> +
> +	return count;
> +}
> +
> +static const struct file_operations pvt_ts_coeff_j_fops = {
> +	.read = pvt_ts_coeff_j_read,
> +	.write = pvt_ts_coeff_j_write,
> +	.open = simple_open,
> +	.owner = THIS_MODULE,
> +	.llseek = default_llseek,
> +};
> +
> +static ssize_t pvt_ts_coeff_cal5_read(struct file *file,
> +				      char __user *user_buf,
> +				      size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	char buf[16];
> +	unsigned int len;
> +
> +	len = sprintf(buf, "%u\n", pvt->ts_coeff_cal5);
> +
> +	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
> +}
> +
> +static ssize_t pvt_ts_coeff_cal5_write(struct file *file,
> +				       const char __user *user_buf,
> +				       size_t count, loff_t *ppos)
> +{
> +	struct pvt_device *pvt = file->private_data;
> +	int ret;
> +	u32 coeff;
> +
> +	ret = kstrtou32_from_user(user_buf, count, 0, &coeff);
> +	if (ret)
> +		return ret;
> +
> +	if (coeff == 0)
> +		return -EINVAL;
> +
> +	pvt->ts_coeff_cal5 = coeff;
> +
> +	return count;
> +}
> +
> +static const struct file_operations pvt_ts_coeff_cal5_fops = {
> +	.read = pvt_ts_coeff_cal5_read,
> +	.write = pvt_ts_coeff_cal5_write,
> +	.open = simple_open,
> +	.owner = THIS_MODULE,
> +	.llseek = default_llseek,
> +};
> +
> +static void devm_pvt_ts_dbgfs_remove(void *data)
> +{
> +	struct pvt_device *pvt = (struct pvt_device *)data;
> +
> +	debugfs_remove_recursive(pvt->dbgfs_dir);
> +	pvt->dbgfs_dir = NULL;
> +}
> +
> +static int pvt_ts_dbgfs_create(struct pvt_device *pvt, struct device *dev)
> +{
> +	int ret;
> +
> +	pvt->dbgfs_dir = debugfs_create_dir(dev_name(dev), NULL);
> +	if (!pvt->dbgfs_dir) {
> +		dev_err(dev, "Failed to create dbgfs_dir\n");
> +		return -EINVAL;
> +	}
> +
> +	debugfs_create_file("ts_coeff_h", 0644, pvt->dbgfs_dir, pvt,
> +			    &pvt_ts_coeff_h_fops);
> +	debugfs_create_file("ts_coeff_g", 0644, pvt->dbgfs_dir, pvt,
> +			    &pvt_ts_coeff_g_fops);
> +	debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt,
> +			    &pvt_ts_coeff_j_fops);
> +	debugfs_create_file("ts_coeff_cal5", 0644, pvt->dbgfs_dir,  pvt,
> +			    &pvt_ts_coeff_cal5_fops);
> +
> +	ret = devm_add_action_or_reset(dev, devm_pvt_ts_dbgfs_remove, pvt);
> +	if (ret) {
> +		dev_err(dev, "failed to add action to remove pvt dbgfs (%d)\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  static umode_t pvt_is_visible(const void *data, enum hwmon_sensor_types type,
>  			      u32 attr, int channel)
>  {
> @@ -655,6 +849,8 @@ static int mr75203_probe(struct platform_device *pdev)
>  		dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n",
>  			pvt->ts_coeff_h, pvt->ts_coeff_g, pvt->ts_coeff_j,
>  			pvt->ts_coeff_cal5);
> +
> +		pvt_ts_dbgfs_create(pvt, dev);
>  	}
>  
>  	if (pd_num) {

  reply	other threads:[~2022-08-18 23:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17  5:43 [PATCH v2 00/16] Variety of fixes and new features for mr75203 driver Eliav Farber
2022-08-17  5:43 ` [PATCH v2 01/16] hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined Eliav Farber
2022-08-18 19:40   ` Guenter Roeck
2022-08-18 20:01     ` [PATCH v2 01/16] hwmon: (mr75203) fix VM sensor allocation when "intel, vm-map" " Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 02/16] hwmon: (mr75203) update pvt->v_num to the actual number of used sensors Eliav Farber
2022-08-18 19:44   ` Guenter Roeck
2022-08-17  5:43 ` [PATCH v2 03/16] hwmon: (mr75203) update Moortec PVT controller intel,vm-map property Eliav Farber
2022-08-18 19:47   ` Guenter Roeck
2022-08-18 20:20     ` [PATCH v2 03/16] hwmon: (mr75203) update Moortec PVT controller intel, vm-map property Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 04/16] hwmon: (mr75203) add Moortec PVT controller reset-control-skip property Eliav Farber
2022-08-18 20:01   ` Guenter Roeck
2022-08-22 11:54     ` Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 05/16] hwmon: (mr75203) add option to skip reset controller Eliav Farber
2022-08-17  5:43 ` [PATCH v2 06/16] hwmon: (mr75203) fix multi-channel voltage reading Eliav Farber
2022-08-18 20:03   ` Guenter Roeck
2022-08-22 12:37     ` Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 07/16] hwmon: (mr75203) add VM active channels property for Moortec PVT controller Eliav Farber
2022-08-18 20:07   ` Guenter Roeck
2022-08-17  5:43 ` [PATCH v2 08/16] hwmon: (mr75203) add VM active channel support Eliav Farber
2022-08-17  5:43 ` [PATCH v2 09/16] hwmon: (mr75203) add VM pre-scalar property for Moortec PVT controller Eliav Farber
2022-08-18 20:11   ` Guenter Roeck
2022-08-19  7:13     ` Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 10/16] hwmon: (mr75203) add VM pre-scalar support Eliav Farber
2022-08-17  5:43 ` [PATCH v2 11/16] hwmon: (mr75203) add protection for negative voltage value Eliav Farber
2022-08-18 20:13   ` Guenter Roeck
2022-08-17  5:43 ` [PATCH v2 12/16] hwmon: (mr75203) modify the temperature equation Eliav Farber
2022-08-18 20:23   ` Guenter Roeck
2022-08-19  7:44     ` Farber, Eliav
2022-08-19 11:35       ` Guenter Roeck
2022-08-17  5:43 ` [PATCH v2 13/16] hwmon: (mr75203) add thermal coefficient properties for Moortec PVT controller Eliav Farber
2022-08-18 20:25   ` Guenter Roeck
2022-08-22 13:24     ` Farber, Eliav
2022-08-22 16:25       ` Guenter Roeck
2022-08-29 18:46         ` Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 14/16] hwmon: (mr75203) parse thermal coefficients from device-tree Eliav Farber
2022-08-18 20:28   ` Guenter Roeck
2022-08-19  7:57     ` Farber, Eliav
2022-08-19 11:36       ` Guenter Roeck
2022-08-19 11:38       ` Guenter Roeck
2022-08-22 13:41         ` Farber, Eliav
2022-08-22 16:31           ` Guenter Roeck
2022-08-29 18:59             ` Farber, Eliav
2022-08-17  5:43 ` [PATCH v2 15/16] hwmon: (mr75203) fix coding style space errors Eliav Farber
2022-08-17  5:43 ` [PATCH v2 16/16] hwmon: (mr75203) add debugfs to read and write temperature coefficients Eliav Farber
2022-08-18 23:11   ` Guenter Roeck [this message]
2022-08-22 13:59     ` Farber, Eliav
2022-08-22 16:28       ` Guenter Roeck
2022-08-29 18:41         ` Farber, Eliav

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=20220818231106.GA3505191@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=almogbs@amazon.com \
    --cc=amitlavi@amazon.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw@amazon.co.uk \
    --cc=farbere@amazon.com \
    --cc=hanochu@amazon.com \
    --cc=hhhawa@amazon.com \
    --cc=itamark@amazon.com \
    --cc=jdelvare@suse.com \
    --cc=jonnyc@amazon.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=ronenk@amazon.com \
    --cc=rtanwar@maxlinear.com \
    --cc=shellykz@amazon.com \
    --cc=shorer@amazon.com \
    --cc=talel@amazon.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;
as well as URLs for NNTP newsgroup(s).