int pal_set_fan_duty()

in meta-facebook/yv35-bb/src/sensor/dev/fan.c [97:145]


int pal_set_fan_duty(uint8_t pwm_id, uint8_t duty, uint8_t slot_index)
{
	const struct device *pwm_dev;
	uint8_t final_duty = 0;
	int ret = 0;

	pwm_dev = device_get_binding(PWM_DEVICE_NAME);
	if (pwm_dev == NULL) {
		printf("PWM device not found\n");
		return -1;
	}

	if (ctrl_fan_mode == FAN_AUTO_MODE) {
		// Auto mode need to compare slot1 and slot3, and set the higher one
		if (slot_index == 0x01) {
			if (duty >= pwm_record[1][pwm_id]) {
				final_duty = duty;
			} else {
				final_duty = pwm_record[1][pwm_id];
			}

		} else if (slot_index == 0x03) {
			if (duty >= pwm_record[0][pwm_id]) {
				final_duty = duty;
			} else {
				final_duty = pwm_record[0][pwm_id];
			}
		} else {
			printf("Invalid slot index: %d\n", slot_index);
			return -1;
		}

	} else if (ctrl_fan_mode == FAN_MANUAL_MODE) {
		final_duty = duty;
	}

	ret = pwm_pin_set_cycles(pwm_dev, pwm_id, MAX_FAN_DUTY, final_duty, 0);
	// If set pwm successful, update pwm table
	if (ret == 0) {
		if (slot_index == 0x01) {
			pwm_record[0][pwm_id] = duty;

		} else if (slot_index == 0x03) {
			pwm_record[1][pwm_id] = duty;
		}
	}

	return ret;
}