Files
OpenCellular/include/fan.h
Bill Richardson 88503ab4ec Provide multiple fan support within the EC itself
This adds explicit "int fan" args to the exported functions from
common/fan.c: fan_set_percent_needed() and fan_percent_to_rpm(). Within that
file, multiple fans are handled independently.

This is not complete, though. Host commands and sysjump support still only
handle a single fan, so at the moment multiple fans are treated identically
in those cases.

BUG=chrome-os-partner:23530
BRANCH=none
TEST=manual

All boards build, "make runtests" passes.

On a multi-fan system, the EC command "faninfo" displays multiple results:

  > faninfo
  Fan 0 Actual:    0 rpm
  Fan 0 Target:    0 rpm
  Fan 0 Duty:   0%
  Fan 0 Status: 0 (not spinning)
  Fan 0 Mode:   rpm
  Fan 0 Auto:   yes
  Fan 0 Enable: yes

  Fan 1 Actual:    0 rpm
  Fan 1 Target:    0 rpm
  Fan 1 Duty:   0%
  Fan 1 Status: 0 (not spinning)
  Fan 1 Mode:   rpm
  Fan 1 Auto:   no
  Fan 1 Enable: no
  >

and the "fanduty", "fanset", and "fanauto" all require the fan number as the
first arg:

  > fanduty 0 30
  Setting fan 0 duty cycle to 30%
  > fanset 1 2000
  Setting fan 1 rpm target to 2000
  > fanauto 0
  > fanauto 1

On single-fan systems, there is no visible change.

Change-Id: Idb8b818122e157960d56779b2a86e5ba433bee1b
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175368
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2013-11-02 01:07:16 +00:00

92 lines
2.5 KiB
C

/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Fan control module for Chrome EC */
#ifndef __CROS_EC_FAN_H
#define __CROS_EC_FAN_H
/* Characteristic of each physical fan */
struct fan_t {
unsigned int flags;
int rpm_min;
int rpm_max;
/* Hardware channel number (the meaning is chip-specific) */
int ch;
/* Active-high power_good input GPIO, or -1 if none */
int pgood_gpio;
/* Active-high power_enable output GPIO, or -1 if none */
int enable_gpio;
};
/* Values for the flags field */
#define FAN_USE_RPM_MODE (1 << 0)
/* The list of fans is instantiated in board.c. */
extern const struct fan_t fans[];
/**
* Set the amount of active cooling needed. The thermal control task will call
* this frequently, and the fan control logic will attempt to provide it.
*
* @param fan Fan number (index into fans[])
* @param pct Percentage of cooling effort needed (0 - 100)
*/
void fan_set_percent_needed(int fan, int pct);
/**
* This function translates the percentage of cooling needed into a target RPM.
* The default implementation should be sufficient for most needs, but
* individual boards may provide a custom version if needed (see config.h).
*
* @param fan Fan number (index into fans[])
* @param pct Percentage of cooling effort needed (always in [0,100])
* Return Target RPM for fan
*/
int fan_percent_to_rpm(int fan, int pct);
/**
* These functions require chip-specific implementations.
*/
/* Enable/Disable the fan controller */
void fan_set_enabled(int ch, int enabled);
int fan_get_enabled(int ch);
/* Fixed pwm duty cycle (0-100%) */
void fan_set_duty(int ch, int percent);
int fan_get_duty(int ch);
/* Enable/Disable automatic RPM control using tach feedback */
void fan_set_rpm_mode(int ch, int rpm_mode);
int fan_get_rpm_mode(int ch);
/* Set the target for the automatic RPM control */
void fan_set_rpm_target(int ch, int rpm);
int fan_get_rpm_actual(int ch);
int fan_get_rpm_target(int ch);
/* Is the fan stalled when it shouldn't be? */
int fan_is_stalled(int ch);
/* How is the automatic RPM control doing? */
enum fan_status {
FAN_STATUS_STOPPED = 0,
FAN_STATUS_CHANGING = 1,
FAN_STATUS_LOCKED = 2,
FAN_STATUS_FRUSTRATED = 3
};
enum fan_status fan_get_status(int ch);
/* Flag to enable automatic RPM control using tach input */
#define FAN_USE_RPM_MODE (1 << 0)
/* Initialize the HW according to the desired flags */
void fan_channel_setup(int ch, unsigned int flags);
#endif /* __CROS_EC_FAN_H */