Skip to content

Commit 6de6868

Browse files
nsolanki22groeck
authored andcommitted
hwmon: (max6639) Allow setting target RPM
Currently, during startup, the fan is set to its maximum RPM by default, which may not be suitable for all use cases. This patch introduces support for specifying a target RPM via the Device Tree property "target-rpm". Changes: - Added `target_rpm` field to `max6639_data` structure to store the target RPM for each fan channel. - Modified `max6639_probe_child_from_dt()` to read the `"target-rpm"` property from the Device Tree and set `target_rpm` accordingly. - Updated `max6639_init_client()` to use `target_rpm` to compute the initial PWM duty cycle instead of defaulting to full speed (120/120). Behavior: - If `"target-rpm"` is specified, the fan speed is set accordingly. - If `"target-rpm"` is not specified, the previous behavior (full speed at startup) is retained. This allows better control over fan speed during system initialization. Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com> Link: https://lore.kernel.org/r/20250404115646.2000563-1-you@example.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 0b3c04c commit 6de6868

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

drivers/hwmon/max6639.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct max6639_data {
8080
/* Register values initialized only once */
8181
u8 ppr[MAX6639_NUM_CHANNELS]; /* Pulses per rotation 0..3 for 1..4 ppr */
8282
u8 rpm_range[MAX6639_NUM_CHANNELS]; /* Index in above rpm_ranges table */
83+
u32 target_rpm[MAX6639_NUM_CHANNELS];
8384

8485
/* Optional regulator for FAN supply */
8586
struct regulator *reg;
@@ -563,6 +564,10 @@ static int max6639_probe_child_from_dt(struct i2c_client *client,
563564
if (!err)
564565
data->rpm_range[i] = rpm_range_to_reg(val);
565566

567+
err = of_property_read_u32(child, "target-rpm", &val);
568+
if (!err)
569+
data->target_rpm[i] = val;
570+
566571
return 0;
567572
}
568573

@@ -573,6 +578,7 @@ static int max6639_init_client(struct i2c_client *client,
573578
const struct device_node *np = dev->of_node;
574579
struct device_node *child;
575580
int i, err;
581+
u8 target_duty;
576582

577583
/* Reset chip to default values, see below for GCONFIG setup */
578584
err = regmap_write(data->regmap, MAX6639_REG_GCONFIG, MAX6639_GCONFIG_POR);
@@ -586,6 +592,8 @@ static int max6639_init_client(struct i2c_client *client,
586592
/* default: 4000 RPM */
587593
data->rpm_range[0] = 1;
588594
data->rpm_range[1] = 1;
595+
data->target_rpm[0] = 4000;
596+
data->target_rpm[1] = 4000;
589597

590598
for_each_child_of_node(np, child) {
591599
if (strcmp(child->name, "fan"))
@@ -639,8 +647,12 @@ static int max6639_init_client(struct i2c_client *client,
639647
if (err)
640648
return err;
641649

642-
/* PWM 120/120 (i.e. 100%) */
643-
err = regmap_write(data->regmap, MAX6639_REG_TARGTDUTY(i), 120);
650+
/* Set PWM based on target RPM if specified */
651+
if (data->target_rpm[i] > rpm_ranges[data->rpm_range[i]])
652+
data->target_rpm[i] = rpm_ranges[data->rpm_range[i]];
653+
654+
target_duty = 120 * data->target_rpm[i] / rpm_ranges[data->rpm_range[i]];
655+
err = regmap_write(data->regmap, MAX6639_REG_TARGTDUTY(i), target_duty);
644656
if (err)
645657
return err;
646658
}

0 commit comments

Comments
 (0)