summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--baseboard/hatch/baseboard.h1
-rw-r--r--board/hatch/board.c91
-rw-r--r--board/hatch/board.h29
-rw-r--r--board/hatch/gpio.inc8
-rw-r--r--common/fan.c2
5 files changed, 128 insertions, 3 deletions
diff --git a/baseboard/hatch/baseboard.h b/baseboard/hatch/baseboard.h
index 9d4eaed696..1ed7381022 100644
--- a/baseboard/hatch/baseboard.h
+++ b/baseboard/hatch/baseboard.h
@@ -18,6 +18,7 @@
#define CONFIG_I2C
/* EC Defines */
+#define CONFIG_ADC
#define CONFIG_PWM
#define CONFIG_VBOOT_HASH
#define CONFIG_VSTORE
diff --git a/board/hatch/board.c b/board/hatch/board.c
index 185794f0bc..cd6d7cd365 100644
--- a/board/hatch/board.c
+++ b/board/hatch/board.c
@@ -5,10 +5,17 @@
/* Hatch board-specific configuration */
+#include "adc.h"
+#include "adc_chip.h"
#include "common.h"
#include "driver/ppc/sn5s330.h"
+#include "ec_commands.h"
#include "extpower.h"
+#include "fan.h"
+#include "fan_chip.h"
#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
@@ -17,6 +24,9 @@
#include "spi.h"
#include "switch.h"
#include "system.h"
+#include "temp_sensor.h"
+#include "thermal.h"
+#include "thermistor.h"
#include "uart.h"
#include "usb_pd.h"
#include "usbc_ppc.h"
@@ -76,10 +86,89 @@ const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices);
/******************************************************************************/
/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
- [PWM_CH_KBLIGHT] = { .channel = 3, .flags = 0, .freq = 10000 }
+ [PWM_CH_KBLIGHT] = { .channel = 3, .flags = 0, .freq = 10000 },
+ [PWM_CH_FAN] = {.channel = 5, .flags = PWM_CONFIG_OPEN_DRAIN,
+ .freq = 25000},
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
+/******************************************************************************/
+/* Physical fans. These are logically separate from pwm_channels. */
+
+const struct fan_conf fan_conf_0 = {
+ .flags = FAN_USE_RPM_MODE,
+ .ch = MFT_CH_0, /* Use MFT id to control fan */
+ .pgood_gpio = -1,
+ .enable_gpio = GPIO_EN_PP5000_FAN,
+};
+
+/* Default */
+const struct fan_rpm fan_rpm_0 = {
+ .rpm_min = 3100,
+ .rpm_start = 3100,
+ .rpm_max = 6900,
+};
+
+struct fan_t fans[FAN_CH_COUNT] = {
+ [FAN_CH_0] = { .conf = &fan_conf_0, .rpm = &fan_rpm_0, },
+};
+
+/******************************************************************************/
+/* MFT channels. These are logically separate from pwm_channels. */
+const struct mft_t mft_channels[] = {
+ [MFT_CH_0] = {NPCX_MFT_MODULE_1, TCKC_LFCLK, PWM_CH_FAN},
+};
+BUILD_ASSERT(ARRAY_SIZE(mft_channels) == MFT_CH_COUNT);
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ [ADC_TEMP_SENSOR_1] = {
+ "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ [ADC_TEMP_SENSOR_2] = {
+ "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_1] = {.name = "Temp1",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_1,
+ .action_delay_sec = 1},
+ [TEMP_SENSOR_2] = {.name = "Temp2",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_2,
+ .action_delay_sec = 1},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+
+
+/* Nami/Vayne Remote 1, 2 */
+const static struct ec_thermal_config thermal_a = {
+ .temp_host = {
+ [EC_TEMP_THRESH_WARN] = 0,
+ [EC_TEMP_THRESH_HIGH] = C_TO_K(75),
+ [EC_TEMP_THRESH_HALT] = C_TO_K(80),
+ },
+ .temp_host_release = {
+ [EC_TEMP_THRESH_WARN] = 0,
+ [EC_TEMP_THRESH_HIGH] = C_TO_K(65),
+ [EC_TEMP_THRESH_HALT] = 0,
+ },
+ .temp_fan_off = C_TO_K(39),
+ .temp_fan_max = C_TO_K(50),
+};
+
+struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT];
+
+static void setup_fans(void)
+{
+ thermal_params[TEMP_SENSOR_1] = thermal_a;
+ thermal_params[TEMP_SENSOR_2] = thermal_a;
+}
+DECLARE_HOOK(HOOK_INIT, setup_fans, HOOK_PRIO_DEFAULT);
+
void board_overcurrent_event(int port, int is_overcurrented)
{
/* Sanity check the port. */
diff --git a/board/hatch/board.h b/board/hatch/board.h
index 7f91551111..ad665c6867 100644
--- a/board/hatch/board.h
+++ b/board/hatch/board.h
@@ -29,6 +29,14 @@
/* Keyboard features */
#define CONFIG_PWM_KBLIGHT
+/* Fan features */
+#define CONFIG_FANS 1
+#undef CONFIG_FAN_INIT_SPEED
+#define CONFIG_FAN_INIT_SPEED 50
+#define CONFIG_THERMISTOR
+#define CONFIG_THROTTLE_AP
+#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B
+
/*
* Macros for GPIO signals used in common code that don't match the
* schematic names. Signal names in gpio.inc match the schematic and are
@@ -49,14 +57,35 @@
#include "registers.h"
enum adc_channel {
+ ADC_TEMP_SENSOR_1, /* ADC0 */
+ ADC_TEMP_SENSOR_2, /* ADC1 */
ADC_CH_COUNT
};
enum pwm_channel {
PWM_CH_KBLIGHT,
+ PWM_CH_FAN,
PWM_CH_COUNT
};
+enum fan_channel {
+ FAN_CH_0 = 0,
+ /* Number of FAN channels */
+ FAN_CH_COUNT,
+};
+
+enum mft_channel {
+ MFT_CH_0 = 0,
+ /* Number of MFT channels */
+ MFT_CH_COUNT,
+};
+
+enum temp_sensor_id {
+ TEMP_SENSOR_1,
+ TEMP_SENSOR_2,
+ TEMP_SENSOR_COUNT
+};
+
/* List of possible batteries */
enum battery_type {
BATTERY_KEYSTONE,
diff --git a/board/hatch/gpio.inc b/board/hatch/gpio.inc
index 67db51c3d3..bbec264e83 100644
--- a/board/hatch/gpio.inc
+++ b/board/hatch/gpio.inc
@@ -57,6 +57,7 @@ GPIO(LED_2_L, PIN(C, 3), GPIO_OUT_HIGH) /* White (hatch)
GPIO(LED_3_L, PIN(C, 2), GPIO_OUT_HIGH)
GPIO(LED_4_L, PIN(6, 0), GPIO_OUT_HIGH)
GPIO(EC_KB_BL_EN, PIN(8, 6), GPIO_OUT_LOW) /* Keyboard backlight */
+GPIO(EN_PP5000_FAN, PIN(6, 1), GPIO_OUT_LOW)
/* I2C pins - Alternate function below configures I2C module on these pins */
@@ -97,4 +98,9 @@ ALTERNATE(PIN_MASK(B, 0x0C), 0, MODULE_I2C, 0) /* I2
ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */
/* PWM */
-ALTERNATE(PIN_MASK(8, 0x01), 0, MODULE_PWM, 0) /* PWM3 */
+ALTERNATE(PIN_MASK(8, 0x01), 0, MODULE_PWM, 0) /* PWM3 - Keyboard backlight */
+ALTERNATE(PIN_MASK(B, 0x80), 0, MODULE_PWM, 0) /* PWM5 - FAN */
+ALTERNATE(PIN_MASK(4, 0x01), 0, MODULE_PWM, 0) /* TA1 - Fan Tachometer */
+
+/* ADC */
+ALTERNATE(PIN_MASK(4, 0x30), 0, MODULE_ADC, 0) /* ADC0-1 */
diff --git a/common/fan.c b/common/fan.c
index d2d080070b..f9d32d6820 100644
--- a/common/fan.c
+++ b/common/fan.c
@@ -236,7 +236,7 @@ static int cc_fanset(int argc, char **argv)
if (argc < 2)
return EC_ERROR_PARAM_COUNT;
- rpm = strtoi(argv[1], &e, 0);
+ rpm = strtoi(argv[2], &e, 0);
if (*e == '%') { /* Wait, that's a percentage */
ccprintf("Fan rpm given as %d%%\n", rpm);
if (rpm < 0)