2022-09-08 16:07:05

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 00/21] Variety of fixes and new features for mr75203 driver

List of fixes:
- Fix "intel,vm-map" property to be optional.
- Fix VM sensor allocation when "intel,vm-map" not defined.
- Fix multi-channel voltage reading.
- Fix voltage equation for negative source input.
- Modify the temperature equation according to series 5 datasheet.
- Fix coding style issue.

List of new features:
- Modify "reset" property to be optional.
- Add optional "moortec,vm-active-channels" property to define the number
of active channels per VM.
- Add support for mr76006 pre-scaler to multiply the voltage result by 2.
- Add support for series 6 temperature equation.
- Add coefficient properties to fine tune the temperature equation.
- Add debugfs to read and write temperature coefficients

---------

Changes between v4 and v5:
- 0004: Add detailed comment in code explaining the cast and the div instead of
right shift or use of BIT().
- 0011: Fix typo in description (nou --> not).
- 0020: Return j coefficient to use debugfs_create_file() instead of
debugfs_create_u32() because j is signed.
- 0021: Move the coding style patch to be last in the series (it does not fix
the code), and remove the "Fixes:" tag.

Changes between v3 and v4:
*) Provide a Fixes tag for all fixes in the series.
*) Start series with fixes.
*) New patch to add description in moortec,mr75203.yaml.
*) New patch to add moortec to vendor-prefixes.
*) Fix moortec,mr75203.yaml checker errors.
*) Remove validation of device-tree parameters.
*) Fix per patch specific comments (detailed in each patch).

Changes between v2 and v3:
*) Add "moortec" prefix to all new device-tree properties.
*) Change order of patches.
*) Add explanations to better understand the changes.
*) Change "reset" property to be optional and remove the
"reset-control-skip" property.
*) Split the patch for "fix multi-channel voltage reading" to two
patches.
*) Change pre-scaler property format and fix typo (scalar --> scaler).
*) Fix voltage equation to support negative values instead of limiting
value to zero.
*) Temperature equation - protect from overflow and add clamping.
*) Add new "moortec,ts-series" property to select between temperature
equation of series 5 or series 6.

Changes between v1 and v2:
*) Fix compilation error for patch 08/16:
"warning: ISO C90 forbids variable length array"

---------

Eliav Farber (21):
dt-bindings: hwmon: (mr75203) fix "intel,vm-map" property to be
optional
hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not
defined
hwmon: (mr75203) update pvt->v_num and vm_num to the actual number of
used sensors
hwmon: (mr75203) fix voltage equation for negative source input
hwmon: (mr75203) fix multi-channel voltage reading
hwmon: (mr75203) enable polling for all VM channels
dt-bindings: hwmon: (mr75203) add description for Moortec's PVT
controller
dt-bindings: hwmon: (mr75203) change "resets" property to be optional
hwmon: (mr75203) skip reset-control deassert for SOCs that don't
support it
dt-bindings: vendor-prefixes: add vendor prefix for Moortec
dt-bindings: hwmon: (mr75203) add "moortec,vm-active-channels"
property
hwmon: (mr75203) add VM active channel support
dt-bindings: hwmon: (mr75203) add "moortec,vm-pre-scaler-x2" property
hwmon: (mr75203) add VM pre-scaler x2 support
hwmon: (mr75203) modify the temperature equation according to series 5
datasheet
dt-bindings: hwmon: (mr75203) add "moortec,ts-series" property
hwmon: (mr75203) add support for series 6 temperature equation
dt-bindings: hwmon: (mr75203) add coefficient properties for the
thermal equation
hwmon: (mr75203) parse temperature coefficients from device-tree
hwmon: (mr75203) add debugfs to read and write temperature
coefficients
hwmon: (mr75203) fix coding style space errors

.../bindings/hwmon/moortec,mr75203.yaml | 97 +++-
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
drivers/hwmon/mr75203.c | 433 +++++++++++++++---
3 files changed, 466 insertions(+), 66 deletions(-)

--
2.37.1


2022-09-08 16:07:20

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 02/21] hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined

Bug - in case "intel,vm-map" is missing in device-tree ,'num' is set
to 0, and no voltage channel infos are allocated.

The reason num is set to 0 when "intel,vm-map" is missing is to set the
entire pvt->vm_idx[] with incremental channel numbers, but it didn't
take into consideration that same num is used later in devm_kcalloc().

If "intel,vm-map" does exist there is no need to set the unspecified
channels with incremental numbers, because the unspecified channels
can't be accessed in pvt_read_in() which is the only other place besides
the probe functions that uses pvt->vm_idx[].

This change fixes the bug by moving the incremental channel numbers
setting to be done only if "intel,vm-map" property is defined (starting
loop from 0), and removing 'num = 0'.

Fixes: 9d823351a337 ("hwmon: Add hardware monitoring driver for Moortec MR75203 PVT controller")
Signed-off-by: Eliav Farber <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
V4 -> v3:
- Simplify the fix by not removing the local num variable (it is removed as
part of a later commit).

drivers/hwmon/mr75203.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 046523d47c29..81ccb4c6fa5c 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -594,7 +594,12 @@ static int mr75203_probe(struct platform_device *pdev)
ret = device_property_read_u8_array(dev, "intel,vm-map",
pvt->vm_idx, vm_num);
if (ret) {
- num = 0;
+ /*
+ * Incase intel,vm-map property is not defined, we
+ * assume incremental channel numbers.
+ */
+ for (i = 0; i < vm_num; i++)
+ pvt->vm_idx[i] = i;
} else {
for (i = 0; i < vm_num; i++)
if (pvt->vm_idx[i] >= vm_num ||
@@ -604,13 +609,6 @@ static int mr75203_probe(struct platform_device *pdev)
}
}

- /*
- * Incase intel,vm-map property is not defined, we assume
- * incremental channel numbers.
- */
- for (i = num; i < vm_num; i++)
- pvt->vm_idx[i] = i;
-
in_config = devm_kcalloc(dev, num + 1,
sizeof(*in_config), GFP_KERNEL);
if (!in_config)
--
2.37.1

2022-09-08 16:08:01

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 16/21] dt-bindings: hwmon: (mr75203) add "moortec,ts-series" property

Add optional "moortec,ts-series" property to define the temperature
equation and coefficients that shall be used to convert the digital
output to value in milli-Celsius.
Supported series: 5 (default) and 6.

Series 5:
T = G + H * (n / cal5 - 0.5) + J * F
Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz

Series 6:
T = G + H * (n / cal5 - 0.5)
Where: G = 57.4, H = 249.4, cal5 = 4096

Signed-off-by: Eliav Farber <[email protected]>
---
V4 -> V3:
- Remove constraints in free-form text descriptions.

V3 -> V2:
- New patch to introduce "moortec,ts-series" property.

.../devicetree/bindings/hwmon/moortec,mr75203.yaml | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
index d6b03a6d7043..df849517464e 100644
--- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
+++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
@@ -91,6 +91,15 @@ properties:
Each channel should not appear more than once.
$ref: /schemas/types.yaml#/definitions/uint8-array

+ moortec,ts-series:
+ description:
+ Definition of the temperature equation and coefficients that shall be
+ used to convert the digital output to value in milli-Celsius.
+ minimum: 5
+ maximum: 6
+ default: 5
+ $ref: /schemas/types.yaml#/definitions/uint32
+
required:
- compatible
- reg
--
2.37.1

2022-09-08 16:09:28

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 11/21] dt-bindings: hwmon: (mr75203) add "moortec,vm-active-channels" property

Add optional "moortec,vm-active-channels" property to define the number
of active channels per VM.

This shall be useful to avoid exposing sysfs for reading inputs that are
not connected to any voltage source.

Signed-off-by: Eliav Farber <[email protected]>
---
V5 -> V4:
- Fix typo in description (nou --> not).

V4 -> V3:
- Fix DT checker errors.

V3 -> V2:
- Add "moortec" prefix to property name.
- Add explanation why this change is needed.

.../devicetree/bindings/hwmon/moortec,mr75203.yaml | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
index 9454576ebb73..5d4bf0edea5c 100644
--- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
+++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
@@ -70,6 +70,15 @@ properties:
"#thermal-sensor-cells":
const: 1

+ moortec,vm-active-channels:
+ description:
+ Defines the number of channels per VM that are actually used and are
+ connected to some input source.
+ Maximum number of items - number of VMs.
+ Maximum value of each item - number of channels.
+ Minimum value of each item - 0 (which means entire VM sensor is not used).
+ $ref: /schemas/types.yaml#/definitions/uint8-array
+
required:
- compatible
- reg
@@ -91,5 +100,6 @@ examples:
intel,vm-map = [03 01 04 ff ff];
clocks = <&osc0>;
resets = <&rcu0 0x40 7>;
+ moortec,vm-active-channels = /bits/ 8 <0x10 0x05>;
#thermal-sensor-cells = <1>;
};
--
2.37.1

2022-09-08 16:12:29

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 19/21] hwmon: (mr75203) parse temperature coefficients from device-tree

Use thermal coefficients from the device tree if they exist.
Otherwise, use default values according to the series (5 or 6).
All coefficients can be used or only part of them.

The coefficients shall be used for fine tuning the default values since
coefficients can vary between product and product.

Signed-off-by: Eliav Farber <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
V4 -> V3:
- Replace of_property_read_u32() with device_property_read_u32().
- Fix "Code shouldn't be a YAML validator".
- Read directly to ts_coeff-> parameter to avoid conditional if.

drivers/hwmon/mr75203.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index bbb59dd7e7cb..07668545c3ae 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -719,6 +719,15 @@ static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt)

dev_dbg(dev, "temperature sensor series = %u\n", series);

+ /* Override ts-coeff-h/g/j/cal5 if they are defined. */
+ device_property_read_u32(dev, "moortec,ts-coeff-h", &ts_coeff->h);
+ device_property_read_u32(dev, "moortec,ts-coeff-g", &ts_coeff->g);
+ device_property_read_u32(dev, "moortec,ts-coeff-j", &ts_coeff->j);
+ device_property_read_u32(dev, "moortec,ts-coeff-cal5", &ts_coeff->cal5);
+
+ dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n",
+ ts_coeff->h, ts_coeff->g, ts_coeff->j, ts_coeff->cal5);
+
return 0;
}

--
2.37.1

2022-09-08 16:13:17

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 17/21] hwmon: (mr75203) add support for series 6 temperature equation

The current equation used in code is aligned to series 5:
T = G + H * (n / cal5 - 0.5) + J * F
Where:
G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz

Series 6 has a slightly different equation:
T = G + H * (n / cal5 - 0.5)
and a different set of coefficients:
G = 57.4, H = 249.4, cal5 = 4096

This change supports equation and coefficients for both series.
(for series 6, J is set to 0).

The series is determined according to “moortec,ts-series” property in
the device tree.
If absent, series 5 is assumed to be the default.

Signed-off-by: Eliav Farber <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
V4 -> V3:
- Replace of_property_read_u32() with device_property_read_u32().
- Use switch-case instead of if-else.

V3 -> V2:
- New patch to support temperature sensor series 6 instead of having to
set all 4 coefficients.

drivers/hwmon/mr75203.c | 66 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 62 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 0de64642cc42..bbb59dd7e7cb 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -115,6 +115,15 @@
#define PVT_SERIES5_J_CONST -100
#define PVT_SERIES5_CAL5_CONST 4094

+/* Temperature coefficients for series 6 */
+#define PVT_SERIES6_H_CONST 249400
+#define PVT_SERIES6_G_CONST 57400
+#define PVT_SERIES6_J_CONST 0
+#define PVT_SERIES6_CAL5_CONST 4096
+
+#define TEMPERATURE_SENSOR_SERIES_5 5
+#define TEMPERATURE_SENSOR_SERIES_6 6
+
#define PRE_SCALER_X1 1
#define PRE_SCALER_X2 2

@@ -147,6 +156,13 @@ struct voltage_channels {
u8 max;
};

+struct temp_coeff {
+ u32 h;
+ u32 g;
+ u32 cal5;
+ s32 j;
+};
+
struct pvt_device {
struct regmap *c_map;
struct regmap *t_map;
@@ -156,6 +172,7 @@ struct pvt_device {
struct reset_control *rst;
struct voltage_device *vd;
struct voltage_channels vm_channels;
+ struct temp_coeff ts_coeff;
u32 t_num;
u32 p_num;
u32 v_num;
@@ -186,10 +203,12 @@ static long pvt_calc_temp(struct pvt_device *pvt, u32 nbs)
* Convert the register value to degrees centigrade temperature:
* T = G + H * (n / cal5 - 0.5) + J * F
*/
- s64 tmp = PVT_SERIES5_G_CONST +
- PVT_SERIES5_H_CONST * (s64)nbs / PVT_SERIES5_CAL5_CONST -
- PVT_SERIES5_H_CONST / 2 +
- PVT_SERIES5_J_CONST * (s64)pvt->ip_freq / HZ_PER_MHZ;
+ struct temp_coeff *ts_coeff = &pvt->ts_coeff;
+
+ s64 tmp = ts_coeff->g +
+ ts_coeff->h * (s64)nbs / ts_coeff->cal5 -
+ ts_coeff->h / 2 +
+ ts_coeff->j * (s64)pvt->ip_freq / HZ_PER_MHZ;

return clamp_val(tmp, PVT_TEMP_MIN_mC, PVT_TEMP_MAX_mC);
}
@@ -668,6 +687,41 @@ static int pvt_get_pre_scaler(struct device *dev, struct pvt_device *pvt)
return ret;
}

+static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt)
+{
+ struct temp_coeff *ts_coeff = &pvt->ts_coeff;
+ u32 series;
+ int ret;
+
+ /* Incase ts-series property is not defined, use default 5. */
+ ret = device_property_read_u32(dev, "moortec,ts-series", &series);
+ if (ret)
+ series = TEMPERATURE_SENSOR_SERIES_5;
+
+ switch (series) {
+ case TEMPERATURE_SENSOR_SERIES_5:
+ ts_coeff->h = PVT_SERIES5_H_CONST;
+ ts_coeff->g = PVT_SERIES5_G_CONST;
+ ts_coeff->j = PVT_SERIES5_J_CONST;
+ ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST;
+ break;
+ case TEMPERATURE_SENSOR_SERIES_6:
+ ts_coeff->h = PVT_SERIES6_H_CONST;
+ ts_coeff->g = PVT_SERIES6_G_CONST;
+ ts_coeff->j = PVT_SERIES6_J_CONST;
+ ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST;
+ break;
+ default:
+ dev_err(dev, "invalid temperature sensor series (%u)\n",
+ series);
+ return -EINVAL;
+ }
+
+ dev_dbg(dev, "temperature sensor series = %u\n", series);
+
+ return 0;
+}
+
static int mr75203_probe(struct platform_device *pdev)
{
u32 ts_num, vm_num, pd_num, ch_num, val, index, i;
@@ -738,6 +792,10 @@ static int mr75203_probe(struct platform_device *pdev)
if (ret)
return ret;

+ ret = pvt_set_temp_coeff(dev, pvt);
+ if (ret)
+ return ret;
+
temp_config = devm_kcalloc(dev, ts_num + 1,
sizeof(*temp_config), GFP_KERNEL);
if (!temp_config)
--
2.37.1

2022-09-08 16:13:56

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 09/21] hwmon: (mr75203) skip reset-control deassert for SOCs that don't support it

Don't fail the probe function and don't deassert the reset controller if
a "reset" property doesn't exist in the device tree.

Change is done for SOCs that don't support a reset controller.

Signed-off-by: Eliav Farber <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
V3 -> v2:
- Change "reset" property to be optional instead of skipping it.

drivers/hwmon/mr75203.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 41e3d3b54baf..19ec9fb91202 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -551,14 +551,17 @@ static int mr75203_probe(struct platform_device *pdev)
return ret;
}

- pvt->rst = devm_reset_control_get_exclusive(dev, NULL);
+ pvt->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
if (IS_ERR(pvt->rst))
return dev_err_probe(dev, PTR_ERR(pvt->rst),
"failed to get reset control\n");

- ret = pvt_reset_control_deassert(dev, pvt);
- if (ret)
- return dev_err_probe(dev, ret, "cannot deassert reset control\n");
+ if (pvt->rst) {
+ ret = pvt_reset_control_deassert(dev, pvt);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "cannot deassert reset control\n");
+ }

ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val);
if(ret < 0)
--
2.37.1

2022-09-08 16:44:03

by Farber, Eliav

[permalink] [raw]
Subject: [PATCH v5 12/21] hwmon: (mr75203) add VM active channel support

Add active channel support per voltage monitor.
The number of active channels is read from the device-tree.
When absent in device-tree, all channels are assumed to be used.

This shall be useful to expose sysfs only for inputs that are connected
to a voltage source.

Setting number of active channels to 0, means that entire VM sensor is
not used.

Signed-off-by: Eliav Farber <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
V4 -> V3:
- Convert comments to kernel doc.
- Repalce for loop with memset.
- Add {} to outer for loop.

V3 -> V2:
- Refactor the code changes (move code to a new function and group
parameters in dedicated structure).

V2 -> V1:
- Fix compilation error for patch 08/16:
"warning: ISO C90 forbids variable length array"

drivers/hwmon/mr75203.c | 121 ++++++++++++++++++++++++++++++++--------
1 file changed, 99 insertions(+), 22 deletions(-)

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 19ec9fb91202..56e19c430919 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -29,6 +29,8 @@
#define CH_NUM_MSK GENMASK(31, 24)
#define CH_NUM_SFT 24

+#define VM_NUM_MAX (VM_NUM_MSK >> VM_NUM_SFT)
+
/* Macro Common Register */
#define CLK_SYNTH 0x00
#define CLK_SYNTH_LO_SFT 0
@@ -106,6 +108,31 @@
#define PVT_N_CONST 90
#define PVT_R_CONST 245805

+/**
+ * struct voltage_device - VM single input parameters.
+ * @vm_map: Map channel number to VM index.
+ * @ch_map: Map channel number to channel index.
+ *
+ * The structure provides mapping between channel-number (0..N-1) to VM-index
+ * (0..num_vm-1) and channel-index (0..ch_num-1) where N = num_vm * ch_num.
+ */
+struct voltage_device {
+ u32 vm_map;
+ u32 ch_map;
+};
+
+/**
+ * struct voltage_channels - VM channel count.
+ * @total: Total number of channels in all VMs.
+ * @max: Maximum number of channels among all VMs.
+ *
+ * The structure provides channel count information across all VMs.
+ */
+struct voltage_channels {
+ u32 total;
+ u8 max;
+};
+
struct pvt_device {
struct regmap *c_map;
struct regmap *t_map;
@@ -113,12 +140,12 @@ struct pvt_device {
struct regmap *v_map;
struct clk *clk;
struct reset_control *rst;
+ struct voltage_device *vd;
+ struct voltage_channels vm_channels;
u32 t_num;
u32 p_num;
u32 v_num;
- u32 c_num;
u32 ip_freq;
- u8 *vm_idx;
};

static umode_t pvt_is_visible(const void *data, enum hwmon_sensor_types type,
@@ -184,11 +211,11 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val)
u32 n, stat;
int ret;

- if (channel >= pvt->v_num * pvt->c_num)
+ if (channel >= pvt->vm_channels.total)
return -EINVAL;

- vm_idx = pvt->vm_idx[channel / pvt->c_num];
- ch_idx = channel % pvt->c_num;
+ vm_idx = pvt->vd[channel].vm_map;
+ ch_idx = pvt->vd[channel].ch_map;

switch (attr) {
case hwmon_in_input:
@@ -398,7 +425,7 @@ static int pvt_init(struct pvt_device *pvt)
if (ret)
return ret;

- val = (BIT(pvt->c_num) - 1) | VM_CH_INIT |
+ val = (BIT(pvt->vm_channels.max) - 1) | VM_CH_INIT |
IP_POLL << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG;
ret = regmap_write(v_map, SDIF_W, val);
if (ret < 0)
@@ -523,6 +550,60 @@ static int pvt_reset_control_deassert(struct device *dev, struct pvt_device *pvt
return devm_add_action_or_reset(dev, pvt_reset_control_assert, pvt);
}

+static int pvt_get_active_channel(struct device *dev, struct pvt_device *pvt,
+ u32 vm_num, u32 ch_num, u8 *vm_idx)
+{
+ u8 vm_active_ch[VM_NUM_MAX];
+ int ret, i, j, k;
+
+ ret = device_property_read_u8_array(dev, "moortec,vm-active-channels",
+ vm_active_ch, vm_num);
+ if (ret) {
+ /*
+ * Incase "moortec,vm-active-channels" property is not defined,
+ * we assume each VM sensor has all of its channels active.
+ */
+ memset(vm_active_ch, ch_num, vm_num);
+ pvt->vm_channels.max = ch_num;
+ pvt->vm_channels.total = ch_num * vm_num;
+ } else {
+ for (i = 0; i < vm_num; i++) {
+ if (vm_active_ch[i] > ch_num) {
+ dev_err(dev, "invalid active channels: %u\n",
+ vm_active_ch[i]);
+ return -EINVAL;
+ }
+
+ pvt->vm_channels.total += vm_active_ch[i];
+
+ if (vm_active_ch[i] > pvt->vm_channels.max)
+ pvt->vm_channels.max = vm_active_ch[i];
+ }
+ }
+
+ /*
+ * Map between the channel-number to VM-index and channel-index.
+ * Example - 3 VMs, "moortec,vm_active_ch" = <5 2 4>:
+ * vm_map = [0 0 0 0 0 1 1 2 2 2 2]
+ * ch_map = [0 1 2 3 4 0 1 0 1 2 3]
+ */
+ pvt->vd = devm_kcalloc(dev, pvt->vm_channels.total, sizeof(*pvt->vd),
+ GFP_KERNEL);
+ if (!pvt->vd)
+ return -ENOMEM;
+
+ k = 0;
+ for (i = 0; i < vm_num; i++) {
+ for (j = 0; j < vm_active_ch[i]; j++) {
+ pvt->vd[k].vm_map = vm_idx[i];
+ pvt->vd[k].ch_map = j;
+ k++;
+ }
+ }
+
+ return 0;
+}
+
static int mr75203_probe(struct platform_device *pdev)
{
u32 ts_num, vm_num, pd_num, ch_num, val, index, i;
@@ -574,7 +655,6 @@ static int mr75203_probe(struct platform_device *pdev)
pvt->t_num = ts_num;
pvt->p_num = pd_num;
pvt->v_num = vm_num;
- pvt->c_num = ch_num;
val = 0;
if (ts_num)
val++;
@@ -611,44 +691,41 @@ static int mr75203_probe(struct platform_device *pdev)
}

if (vm_num) {
- u32 total_ch;
+ u8 vm_idx[VM_NUM_MAX];

ret = pvt_get_regmap(pdev, "vm", pvt);
if (ret)
return ret;

- pvt->vm_idx = devm_kcalloc(dev, vm_num, sizeof(*pvt->vm_idx),
- GFP_KERNEL);
- if (!pvt->vm_idx)
- return -ENOMEM;
-
- ret = device_property_read_u8_array(dev, "intel,vm-map",
- pvt->vm_idx, vm_num);
+ ret = device_property_read_u8_array(dev, "intel,vm-map", vm_idx,
+ vm_num);
if (ret) {
/*
* Incase intel,vm-map property is not defined, we
* assume incremental channel numbers.
*/
for (i = 0; i < vm_num; i++)
- pvt->vm_idx[i] = i;
+ vm_idx[i] = i;
} else {
for (i = 0; i < vm_num; i++)
- if (pvt->vm_idx[i] >= vm_num ||
- pvt->vm_idx[i] == 0xff) {
+ if (vm_idx[i] >= vm_num || vm_idx[i] == 0xff) {
pvt->v_num = i;
vm_num = i;
break;
}
}

- total_ch = ch_num * vm_num;
- in_config = devm_kcalloc(dev, total_ch + 1,
+ ret = pvt_get_active_channel(dev, pvt, vm_num, ch_num, vm_idx);
+ if (ret)
+ return ret;
+
+ in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1,
sizeof(*in_config), GFP_KERNEL);
if (!in_config)
return -ENOMEM;

- memset32(in_config, HWMON_I_INPUT, total_ch);
- in_config[total_ch] = 0;
+ memset32(in_config, HWMON_I_INPUT, pvt->vm_channels.total);
+ in_config[pvt->vm_channels.total] = 0;
pvt_in.config = in_config;

pvt_info[index++] = &pvt_in;
--
2.37.1

2022-09-08 19:40:01

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 16/21] dt-bindings: hwmon: (mr75203) add "moortec,ts-series" property

On Thu, Sep 08, 2022 at 03:24:44PM +0000, Eliav Farber wrote:
> Add optional "moortec,ts-series" property to define the temperature
> equation and coefficients that shall be used to convert the digital
> output to value in milli-Celsius.
> Supported series: 5 (default) and 6.
>
> Series 5:
> T = G + H * (n / cal5 - 0.5) + J * F
> Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz
>
> Series 6:
> T = G + H * (n / cal5 - 0.5)
> Where: G = 57.4, H = 249.4, cal5 = 4096
>
> Signed-off-by: Eliav Farber <[email protected]>
> ---
> V4 -> V3:
> - Remove constraints in free-form text descriptions.
>
> V3 -> V2:
> - New patch to introduce "moortec,ts-series" property.
>
> .../devicetree/bindings/hwmon/moortec,mr75203.yaml | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
> index d6b03a6d7043..df849517464e 100644
> --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
> +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
> @@ -91,6 +91,15 @@ properties:
> Each channel should not appear more than once.
> $ref: /schemas/types.yaml#/definitions/uint8-array
>
> + moortec,ts-series:
> + description:
> + Definition of the temperature equation and coefficients that shall be
> + used to convert the digital output to value in milli-Celsius.
> + minimum: 5
> + maximum: 6
> + default: 5
> + $ref: /schemas/types.yaml#/definitions/uint32
> +

I am not a dt expert, but I wonder if this should be handled
with different "compatible" properties. Sorry if this was already
addressed and I missed it.

Thanks,
Guenter

2022-09-08 20:33:04

by Farber, Eliav

[permalink] [raw]
Subject: Re: [PATCH v5 16/21] dt-bindings: hwmon: (mr75203) add "moortec, ts-series" property

On 9/8/2022 10:02 PM, Guenter Roeck wrote:
> On Thu, Sep 08, 2022 at 03:24:44PM +0000, Eliav Farber wrote:
>> Add optional "moortec,ts-series" property to define the temperature
>> equation and coefficients that shall be used to convert the digital
>> output to value in milli-Celsius.
>> Supported series: 5 (default) and 6.
>>
>> Series 5:
>>   T = G + H * (n / cal5 - 0.5) + J * F
>> Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in
>> MHz
>>
>> Series 6:
>>    T = G + H * (n / cal5 - 0.5)
>> Where: G = 57.4, H = 249.4, cal5 = 4096
>>
>> Signed-off-by: Eliav Farber <[email protected]>
>> ---
>> V4 -> V3:
>> - Remove constraints in free-form text descriptions.
>>
>> V3 -> V2:
>> - New patch to introduce "moortec,ts-series" property.
>>
>>  .../devicetree/bindings/hwmon/moortec,mr75203.yaml       | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git
>> a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>> b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>> index d6b03a6d7043..df849517464e 100644
>> --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>> +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>> @@ -91,6 +91,15 @@ properties:
>>        Each channel should not appear more than once.
>>      $ref: /schemas/types.yaml#/definitions/uint8-array
>>
>> +  moortec,ts-series:
>> +    description:
>> +      Definition of the temperature equation and coefficients that
>> shall be
>> +      used to convert the digital output to value in milli-Celsius.
>> +    minimum: 5
>> +    maximum: 6
>> +    default: 5
>> +    $ref: /schemas/types.yaml#/definitions/uint32
>> +
>
> I am not a dt expert, but I wonder if this should be handled
> with different "compatible" properties. Sorry if this was already
> addressed and I missed it.

It was already addressed in [PATCH v3 14/19] by Philipp.
It is indeed confusing which is why I added a detailed description
to moortec,mr75203.yaml in [PATCH v5 07/21].
Shortly, the driver is for the controller unit (mr75203), while the
"series" is a parameter of the temperature unit (mr74137).
Therefore I added a new TS property and not a different compatible.

--
Regards, Eliav

2022-09-08 20:36:00

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 16/21] dt-bindings: hwmon: (mr75203) add "moortec, ts-series" property

On 9/8/22 13:18, Farber, Eliav wrote:
> On 9/8/2022 10:02 PM, Guenter Roeck wrote:
>> On Thu, Sep 08, 2022 at 03:24:44PM +0000, Eliav Farber wrote:
>>> Add optional "moortec,ts-series" property to define the temperature
>>> equation and coefficients that shall be used to convert the digital
>>> output to value in milli-Celsius.
>>> Supported series: 5 (default) and 6.
>>>
>>> Series 5:
>>>   T = G + H * (n / cal5 - 0.5) + J * F
>>> Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz
>>>
>>> Series 6:
>>>    T = G + H * (n / cal5 - 0.5)
>>> Where: G = 57.4, H = 249.4, cal5 = 4096
>>>
>>> Signed-off-by: Eliav Farber <[email protected]>
>>> ---
>>> V4 -> V3:
>>> - Remove constraints in free-form text descriptions.
>>>
>>> V3 -> V2:
>>> - New patch to introduce "moortec,ts-series" property.
>>>
>>>  .../devicetree/bindings/hwmon/moortec,mr75203.yaml       | 9 +++++++++
>>>  1 file changed, 9 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>>> index d6b03a6d7043..df849517464e 100644
>>> --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>>> +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml
>>> @@ -91,6 +91,15 @@ properties:
>>>        Each channel should not appear more than once.
>>>      $ref: /schemas/types.yaml#/definitions/uint8-array
>>>
>>> +  moortec,ts-series:
>>> +    description:
>>> +      Definition of the temperature equation and coefficients that shall be
>>> +      used to convert the digital output to value in milli-Celsius.
>>> +    minimum: 5
>>> +    maximum: 6
>>> +    default: 5
>>> +    $ref: /schemas/types.yaml#/definitions/uint32
>>> +
>>
>> I am not a dt expert, but I wonder if this should be handled
>> with different "compatible" properties. Sorry if this was already
>> addressed and I missed it.
>
> It was already addressed in [PATCH v3 14/19] by Philipp.
> It is indeed confusing which is why I added a detailed description
> to moortec,mr75203.yaml in [PATCH v5 07/21].
> Shortly, the driver is for the controller unit (mr75203), while the
> "series" is a parameter of the temperature unit (mr74137).
> Therefore I added a new TS property and not a different compatible.
>

Thanks a lot for the clarification.

Guenter

2022-09-09 02:34:56

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 09/21] hwmon: (mr75203) skip reset-control deassert for SOCs that don't support it

On Thu, Sep 08, 2022 at 03:24:37PM +0000, Eliav Farber wrote:
> Don't fail the probe function and don't deassert the reset controller if
> a "reset" property doesn't exist in the device tree.
>
> Change is done for SOCs that don't support a reset controller.
>
> Signed-off-by: Eliav Farber <[email protected]>
> Reviewed-by: Andy Shevchenko <[email protected]>

Applied to hwmon-next.

Thanks,
Guenter

> ---
> V3 -> v2:
> - Change "reset" property to be optional instead of skipping it.
>
> drivers/hwmon/mr75203.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
> index 41e3d3b54baf..19ec9fb91202 100644
> --- a/drivers/hwmon/mr75203.c
> +++ b/drivers/hwmon/mr75203.c
> @@ -551,14 +551,17 @@ static int mr75203_probe(struct platform_device *pdev)
> return ret;
> }
>
> - pvt->rst = devm_reset_control_get_exclusive(dev, NULL);
> + pvt->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
> if (IS_ERR(pvt->rst))
> return dev_err_probe(dev, PTR_ERR(pvt->rst),
> "failed to get reset control\n");
>
> - ret = pvt_reset_control_deassert(dev, pvt);
> - if (ret)
> - return dev_err_probe(dev, ret, "cannot deassert reset control\n");
> + if (pvt->rst) {
> + ret = pvt_reset_control_deassert(dev, pvt);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "cannot deassert reset control\n");
> + }
>
> ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val);
> if(ret < 0)

2022-09-13 12:11:04

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v5 16/21] dt-bindings: hwmon: (mr75203) add "moortec,ts-series" property

On Thu, 08 Sep 2022 15:24:44 +0000, Eliav Farber wrote:
> Add optional "moortec,ts-series" property to define the temperature
> equation and coefficients that shall be used to convert the digital
> output to value in milli-Celsius.
> Supported series: 5 (default) and 6.
>
> Series 5:
> T = G + H * (n / cal5 - 0.5) + J * F
> Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz
>
> Series 6:
> T = G + H * (n / cal5 - 0.5)
> Where: G = 57.4, H = 249.4, cal5 = 4096
>
> Signed-off-by: Eliav Farber <[email protected]>
> ---
> V4 -> V3:
> - Remove constraints in free-form text descriptions.
>
> V3 -> V2:
> - New patch to introduce "moortec,ts-series" property.
>
> .../devicetree/bindings/hwmon/moortec,mr75203.yaml | 9 +++++++++
> 1 file changed, 9 insertions(+)
>

Reviewed-by: Rob Herring <[email protected]>

2022-09-13 12:17:45

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v5 11/21] dt-bindings: hwmon: (mr75203) add "moortec,vm-active-channels" property

On Thu, 08 Sep 2022 15:24:39 +0000, Eliav Farber wrote:
> Add optional "moortec,vm-active-channels" property to define the number
> of active channels per VM.
>
> This shall be useful to avoid exposing sysfs for reading inputs that are
> not connected to any voltage source.
>
> Signed-off-by: Eliav Farber <[email protected]>
> ---
> V5 -> V4:
> - Fix typo in description (nou --> not).
>
> V4 -> V3:
> - Fix DT checker errors.
>
> V3 -> V2:
> - Add "moortec" prefix to property name.
> - Add explanation why this change is needed.
>
> .../devicetree/bindings/hwmon/moortec,mr75203.yaml | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>

Reviewed-by: Rob Herring <[email protected]>

2022-09-19 13:34:36

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 17/21] hwmon: (mr75203) add support for series 6 temperature equation

On Thu, Sep 08, 2022 at 03:24:45PM +0000, Eliav Farber wrote:
> The current equation used in code is aligned to series 5:
> T = G + H * (n / cal5 - 0.5) + J * F
> Where:
> G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz
>
> Series 6 has a slightly different equation:
> T = G + H * (n / cal5 - 0.5)
> and a different set of coefficients:
> G = 57.4, H = 249.4, cal5 = 4096
>
> This change supports equation and coefficients for both series.
> (for series 6, J is set to 0).
>
> The series is determined according to “moortec,ts-series” property in
> the device tree.
> If absent, series 5 is assumed to be the default.
>
> Signed-off-by: Eliav Farber <[email protected]>
> Reviewed-by: Andy Shevchenko <[email protected]>

Applied to hwmon-next.

Thanks,
Guenter

2022-09-19 13:46:24

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 11/21] dt-bindings: hwmon: (mr75203) add "moortec,vm-active-channels" property

On Thu, Sep 08, 2022 at 03:24:39PM +0000, Eliav Farber wrote:
> Add optional "moortec,vm-active-channels" property to define the number
> of active channels per VM.
>
> This shall be useful to avoid exposing sysfs for reading inputs that are
> not connected to any voltage source.
>
> Signed-off-by: Eliav Farber <[email protected]>
> Reviewed-by: Rob Herring <[email protected]>

Applied to hwmon-next.

Thanks,
Guenter

2022-09-19 14:08:28

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 19/21] hwmon: (mr75203) parse temperature coefficients from device-tree

On Thu, Sep 08, 2022 at 03:24:47PM +0000, Eliav Farber wrote:
> Use thermal coefficients from the device tree if they exist.
> Otherwise, use default values according to the series (5 or 6).
> All coefficients can be used or only part of them.
>
> The coefficients shall be used for fine tuning the default values since
> coefficients can vary between product and product.
>
> Signed-off-by: Eliav Farber <[email protected]>
> Reviewed-by: Andy Shevchenko <[email protected]>

Applied to hwmon-next.

Thanks,
Guenter

2022-09-19 14:09:26

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 12/21] hwmon: (mr75203) add VM active channel support

On Thu, Sep 08, 2022 at 03:24:40PM +0000, Eliav Farber wrote:
> Add active channel support per voltage monitor.
> The number of active channels is read from the device-tree.
> When absent in device-tree, all channels are assumed to be used.
>
> This shall be useful to expose sysfs only for inputs that are connected
> to a voltage source.
>
> Setting number of active channels to 0, means that entire VM sensor is
> not used.
>
> Signed-off-by: Eliav Farber <[email protected]>
> Reviewed-by: Andy Shevchenko <[email protected]>

Applied to hwmon-next.

Thanks,
Guenter

2022-09-19 14:10:53

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 16/21] dt-bindings: hwmon: (mr75203) add "moortec,ts-series" property

On Thu, Sep 08, 2022 at 03:24:44PM +0000, Eliav Farber wrote:
> Add optional "moortec,ts-series" property to define the temperature
> equation and coefficients that shall be used to convert the digital
> output to value in milli-Celsius.
> Supported series: 5 (default) and 6.
>
> Series 5:
> T = G + H * (n / cal5 - 0.5) + J * F
> Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz
>
> Series 6:
> T = G + H * (n / cal5 - 0.5)
> Where: G = 57.4, H = 249.4, cal5 = 4096
>
> Signed-off-by: Eliav Farber <[email protected]>
> Reviewed-by: Rob Herring <[email protected]>

Applied to hwmon-next.

Thanks,
Guenter