Skip to content

Commit

Permalink
Add PWM minimum duty
Browse files Browse the repository at this point in the history
Replaces SMOOTH_FANS_MIN. Turn fans off when the target is below a
certain duty, and turn don't turn fans on until that duty is reached.

All boards should probably define this.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Aug 5, 2024
1 parent a3a77eb commit c695755
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/board/system76/common/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ void fan_event(void) {
fan1_pwm_target = 0;
fan1_pwm_actual = 0;
} else if (fan1_pwm_actual < fan1_pwm_target) {
// TODO :Check against board-defined maximum
if (fan1_pwm_actual < CTR0) {
fan1_pwm_actual++;
if (fan1_pwm_actual < FAN1.pwm_min) {
fan1_pwm_actual = FAN1.pwm_min;
}
}
} else if (fan1_pwm_actual > fan1_pwm_target) {
// TODO: Check against board-defined minimum
if (fan1_pwm_actual > 0) {
fan1_pwm_actual--;
if (fan1_pwm_actual < FAN1.pwm_min) {
fan1_pwm_actual = 0;
}
}
}
TRACE("FAN1 duty=%d\n", fan1_pwm_actual);
Expand All @@ -119,14 +123,18 @@ void fan_event(void) {
fan2_pwm_target = 0;
fan2_pwm_actual = 0;
} else if (fan2_pwm_actual < fan2_pwm_target) {
// TODO :Check against board-defined maximum
if (fan2_pwm_actual < CTR0) {
fan2_pwm_actual++;
if (fan2_pwm_actual < FAN2.pwm_min) {
fan2_pwm_actual = FAN2.pwm_min;
}
}
} else if (fan2_pwm_actual > fan2_pwm_target) {
// TODO: Check against board-defined minimum
if (fan2_pwm_actual > 0) {
fan2_pwm_actual--;
if (fan2_pwm_actual < FAN2.pwm_min) {
fan2_pwm_actual = 0;
}
}
}
TRACE("FAN2 duty=%d\n", fan2_pwm_actual);
Expand Down
1 change: 1 addition & 0 deletions src/board/system76/common/include/board/fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct FanPoint {
struct Fan {
const struct FanPoint *const points;
const uint8_t points_size;
const uint8_t pwm_min;
};

extern const struct Fan __code FAN1;
Expand Down
2 changes: 2 additions & 0 deletions src/board/system76/darp10-b/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(27),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -33,4 +34,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(27),
};
2 changes: 2 additions & 0 deletions src/board/system76/gaze17-3050/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(20),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -31,4 +32,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(20),
};
2 changes: 2 additions & 0 deletions src/board/system76/oryp11/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(28),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -31,4 +32,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(28),
};
2 changes: 2 additions & 0 deletions src/board/system76/oryp6/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(25),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -31,4 +32,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(25),
};
2 changes: 2 additions & 0 deletions src/board/system76/oryp7/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(25),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -31,4 +32,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(25),
};
2 changes: 2 additions & 0 deletions src/board/system76/oryp8/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(25),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -31,4 +32,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(25),
};
2 changes: 2 additions & 0 deletions src/board/system76/serw13/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static const struct FanPoint __code FAN1_POINTS[] = {
const struct Fan __code FAN1 = {
.points = FAN1_POINTS,
.points_size = ARRAY_SIZE(FAN1_POINTS),
.pwm_min = PWM_DUTY(28),
};

static const struct FanPoint __code FAN2_POINTS[] = {
Expand All @@ -29,4 +30,5 @@ static const struct FanPoint __code FAN2_POINTS[] = {
const struct Fan __code FAN2 = {
.points = FAN2_POINTS,
.points_size = ARRAY_SIZE(FAN2_POINTS),
.pwm_min = PWM_DUTY(28),
};

0 comments on commit c695755

Please sign in to comment.