Messages in this thread | | | Subject | Re: [PATCH v5 20/21] hwmon: (mr75203) add debugfs to read and write temperature coefficients | Date | Tue, 13 Sep 2022 17:40:16 +0300 | From | "Farber, Eliav" <> |
| |
On 9/13/2022 4:06 PM, Farber, Eliav wrote: > On 9/8/2022 9:11 PM, Andy Shevchenko wrote: >> On Thu, Sep 08, 2022 at 03:24:48PM +0000, Eliav Farber wrote: >>> This change adds debugfs to read and write temperature sensor >>> coefficients >>> - g, h, j and cal5. >>> >>> The coefficients can vary between product and product, so it can be >>> very >>> useful to be able to modify them on the fly during the calibration >>> process. >>> >>> e.g.: >>> >>> cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_cal5 >>> 4096 >>> >>> echo 83000 > sys/kernel/debug/940f23d0000.pvt/ts_coeff_g >> >> ... >> >>> - Return j coefficient to use debugfs_create_file() instead of >>> debugfs_create_u32() because j is signed. >> >> You can use >> >> DEFINE_DEBUGFS_ATTRIBUTE(ts_coeff_j, ts_coeff_j_get, ts_coeff_j_set, >> "%lld\n"); >> >> which still makes code compact. > > > I tried your suggestion to use DEFINE_DEBUGFS_ATTRIBUTE but I can't set > j to be a negative value: > > root@alpine:~# cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > 0 > root@alpine:~# echo 100 > /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > root@alpine:~# cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > 100 > root@alpine:~# echo -100 > /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j > sh: write error: Invalid argument > > This is the code I added: > > static int ts_coeff_j_set(void *data, u64 val) > { > struct pvt_device *pvt = data; > > pvt->ts_coeff.j = val; > return 0; > } > > static int ts_coeff_j_get(void *data, u64 *val) > { > struct pvt_device *pvt = data; > > *val = pvt->ts_coeff.j; > return 0; > } > > DEFINE_DEBUGFS_ATTRIBUTE(ts_coeff_j_fops, ts_coeff_j_get, > ts_coeff_j_set, "%lld\n"); > > 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) > { > ... > debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt, > &ts_coeff_j_fops); > ... > > I'm using kernel 5.10.112. > Can you please see if I'm did anything wrong?
It seems like debugfs_attr_write() calls simple_attr_write() and it uses kstrtoull(), which is why it fails when setting a negative value. This is the same also in v6.0-rc5.
debugfs_attr_read() on the other hand does show the correct value also when j is negative.
-- Regards, Eliav
| |