summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-12-16 14:52:36 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-02 15:48:21 -0800
commitf147f61f38a27e57308033f81fedfd8834b58a62 (patch)
tree06b51d2c5f545523304d7863b414e7f8b6203101
parentd813935b827b55f4650365a5e9e8096e47122f07 (diff)
downloadchrome-ec-f147f61f38a27e57308033f81fedfd8834b58a62.tar.gz
Nami: Update board directory
Made board.c, board.h, gpio.inc match the schematics. Sensors anren't implemented. BUG=b:70157960 BRANCH=none TEST=Verify Nami boots to S0. Change-Id: Id8c800c8b78c66d558e0f664b54d47c4c808f643 Reviewed-on: https://chromium-review.googlesource.com/831121 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/nami/battery.c4
-rw-r--r--board/nami/board.c387
-rw-r--r--board/nami/board.h33
-rw-r--r--board/nami/gpio.inc186
-rw-r--r--board/nami/led.c273
-rw-r--r--board/nami/usb_pd_policy.c39
6 files changed, 449 insertions, 473 deletions
diff --git a/board/nami/battery.c b/board/nami/battery.c
index 19a803af6d..aac280264d 100644
--- a/board/nami/battery.c
+++ b/board/nami/battery.c
@@ -17,7 +17,7 @@
static enum battery_present batt_pres_prev = BP_NOT_SURE;
/*
- * TODO(philipchen): Check if these parameters are valid for Nautilus battery.
+ * TODO(dnojiri): Check if these parameters are valid for battery.
*
* Shutdown mode parameter to write to manufacturer access register
*/
@@ -136,7 +136,7 @@ static int battery_check_disconnect(void)
if (rv)
return BATTERY_DISCONNECT_ERROR;
- /* TODO(philipchen): Verify if Nautilus battery supports this check. */
+ /* TODO(dnojiri): Verify if battery supports this check. */
if ((data[3] & (BATTERY_DISCHARGING_DISABLED |
BATTERY_CHARGING_DISABLED)) ==
(BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED))
diff --git a/board/nami/board.c b/board/nami/board.c
index 165a5b9597..86d267db5d 100644
--- a/board/nami/board.c
+++ b/board/nami/board.c
@@ -7,7 +7,6 @@
#include "adc.h"
#include "adc_chip.h"
-#include "bd99992gw.h"
#include "board_config.h"
#include "button.h"
#include "charge_manager.h"
@@ -16,13 +15,13 @@
#include "charger.h"
#include "chipset.h"
#include "console.h"
+#include "driver/pmic_tps650x30.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/accel_bma2x2.h"
#include "driver/baro_bmp280.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "driver/tcpm/tcpm.h"
-#include "driver/temp_sensor/bd99992gw.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
@@ -36,6 +35,8 @@
#include "pi3usb9281.h"
#include "power.h"
#include "power_button.h"
+#include "pwm.h"
+#include "pwm_chip.h"
#include "spi.h"
#include "switch.h"
#include "system.h"
@@ -54,6 +55,14 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+int board_get_version(void)
+{
+ static int version = 0;
+ /* dnojiri: Read version from EEPROM */
+ CPRINTS("Board version: %d", version);
+ return version;
+}
+
static void tcpc_alert_event(enum gpio_signal signal)
{
if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
@@ -72,12 +81,8 @@ static void tcpc_alert_event(enum gpio_signal signal)
/* Set PD discharge whenever VBUS detection is high (i.e. below threshold). */
static void vbus_discharge_handler(void)
{
- if (system_get_board_version() >= 2) {
- pd_set_vbus_discharge(0,
- gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
- pd_set_vbus_discharge(1,
- gpio_get_level(GPIO_USB_C1_VBUS_WAKE_L));
- }
+ pd_set_vbus_discharge(0, gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L));
+ pd_set_vbus_discharge(1, gpio_get_level(GPIO_USB_C1_VBUS_WAKE_L));
}
DECLARE_DEFERRED(vbus_discharge_handler);
@@ -86,7 +91,6 @@ void vbus0_evt(enum gpio_signal signal)
/* VBUS present GPIO is inverted */
usb_charger_vbus_change(0, !gpio_get_level(signal));
task_wake(TASK_ID_PD_C0);
-
hook_call_deferred(&vbus_discharge_handler_data, 0);
}
@@ -95,7 +99,6 @@ void vbus1_evt(enum gpio_signal signal)
/* VBUS present GPIO is inverted */
usb_charger_vbus_change(1, !gpio_get_level(signal));
task_wake(TASK_ID_PD_C1);
-
hook_call_deferred(&vbus_discharge_handler_data, 0);
}
@@ -118,13 +121,8 @@ const struct power_signal_info power_signal_list[] = {
POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
"SLP_S0_DEASSERTED"},
#endif
-#ifdef CONFIG_ESPI_VW_SIGNALS
{VW_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
{VW_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
-#else
- {GPIO_PCH_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {GPIO_PCH_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
-#endif
{GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
{GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
{GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
@@ -134,16 +132,14 @@ BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
/* Hibernate wake configuration */
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_AC_PRESENT,
+ GPIO_LID_OPEN,
GPIO_POWER_BUTTON_L,
};
const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins);
/* ADC channels */
const struct adc_t adc_channels[] = {
- /* Base detection */
- [ADC_BASE_DET] = {"BASE_DET", NPCX_ADC_CH0,
- ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
- /* Vbus sensing (10x voltage divider). */
+ /* Vbus sensing (10x voltage divider). PPVAR_BOOSTIN_SENSE */
[ADC_VBUS] = {"VBUS", NPCX_ADC_CH2, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
/*
* Adapter current output or battery charging/discharging current (uV)
@@ -158,9 +154,11 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
const struct i2c_port_t i2c_ports[] = {
{"tcpc0", NPCX_I2C_PORT0_0, 400, GPIO_I2C0_0_SCL, GPIO_I2C0_0_SDA},
{"tcpc1", NPCX_I2C_PORT0_1, 400, GPIO_I2C0_1_SCL, GPIO_I2C0_1_SDA},
- {"charger", NPCX_I2C_PORT1, 100, GPIO_I2C1_SCL, GPIO_I2C1_SDA},
+ {"battery", NPCX_I2C_PORT1, 400, GPIO_I2C1_SCL, GPIO_I2C1_SDA}, /* dnojiri:verify */
+ {"charger", NPCX_I2C_PORT2, 100, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
{"pmic", NPCX_I2C_PORT2, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
{"accelgyro", NPCX_I2C_PORT3, 400, GPIO_I2C3_SCL, GPIO_I2C3_SDA},
+ /* dnojiri: Add KB backlight, ALS, G-sensor, Thermal sensor, BC1.2 Detectors. */
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
@@ -250,161 +248,148 @@ uint16_t tcpc_get_alert_status(void)
const struct temp_sensor_t temp_sensors[] = {
{"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_get_battery_temp, 0, 4},
-
- /* These BD99992GW temp sensors are only readable in S0 */
- {"Charger", TEMP_SENSOR_TYPE_BOARD, bd99992gw_get_val,
- BD99992GW_ADC_CHANNEL_SYSTHERM1, 4},
- {"DRAM", TEMP_SENSOR_TYPE_BOARD, bd99992gw_get_val,
- BD99992GW_ADC_CHANNEL_SYSTHERM2, 4},
+ /* dnojiri: Add temp sensors */
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
-/*
- * Check if PMIC fault registers indicate VR fault. If yes, print out fault
- * register info to console. Additionally, set panic reason so that the OS can
- * check for fault register info by looking at offset 0x14(PWRSTAT1) and
- * 0x15(PWRSTAT2) in cros ec panicinfo.
- */
-static void board_report_pmic_fault(const char *str)
-{
- int vrfault, pwrstat1 = 0, pwrstat2 = 0;
- uint32_t info;
+#define I2C_PMIC_READ(reg, data) \
+ i2c_read8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+#define I2C_PMIC_WRITE(reg, data) \
+ i2c_write8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
- /* RESETIRQ1 -- Bit 4: VRFAULT */
- if (i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x8, &vrfault)
- != EC_SUCCESS)
- return;
+static void board_pmic_init(void)
+{
+ int err;
+ int error_count = 0;
+ static uint8_t pmic_initialized = 0;
- if (!(vrfault & (1 << 4)))
+ if (pmic_initialized)
return;
- /* VRFAULT has occurred, print VRFAULT status bits. */
-
- /* PWRSTAT1 */
- i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x16, &pwrstat1);
-
- /* PWRSTAT2 */
- i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x17, &pwrstat2);
-
- CPRINTS("PMIC VRFAULT: %s", str);
- CPRINTS("PMIC VRFAULT: PWRSTAT1=0x%02x PWRSTAT2=0x%02x", pwrstat1,
- pwrstat2);
+ /* Read vendor ID */
+ while (1) {
+ int data;
+ err = I2C_PMIC_READ(TPS650X30_REG_VENDORID, &data);
+ if (!err && data == TPS650X30_VENDOR_ID)
+ break;
+ else if (error_count > 5)
+ goto pmic_error;
+ error_count++;
+ }
- /* Clear all faults -- Write 1 to clear. */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x8, (1 << 4));
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x16, pwrstat1);
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x17, pwrstat2);
+ /*
+ * VCCIOCNT register setting
+ * [6] : CSDECAYEN
+ * otherbits: default
+ */
+ err = I2C_PMIC_WRITE(TPS650X30_REG_VCCIOCNT, 0x4A);
+ if (err)
+ goto pmic_error;
/*
- * Status of the fault registers can be checked in the OS by looking at
- * offset 0x14(PWRSTAT1) and 0x15(PWRSTAT2) in cros ec panicinfo.
+ * VRMODECTRL:
+ * [4] : VCCIOLPM clear
+ * otherbits: default
*/
- info = ((pwrstat2 & 0xFF) << 8) | (pwrstat1 & 0xFF);
- panic_set_reason(PANIC_SW_PMIC_FAULT, info, 0);
-}
+ err = I2C_PMIC_WRITE(TPS650X30_REG_VRMODECTRL, 0x2F);
+ if (err)
+ goto pmic_error;
-static void board_pmic_disable_slp_s0_vr_decay(void)
-{
/*
- * VCCIOCNT:
- * Bit 6 (0) - Disable decay of VCCIO on SLP_S0# assertion
- * Bits 5:4 (00) - Nominal output voltage: 0.975V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * PGMASK1 : Exclude VCCIO from Power Good Tree
+ * [7] : MVCCIOPG clear
+ * otherbits: default
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0xa);
+ err = I2C_PMIC_WRITE(TPS650X30_REG_PGMASK1, 0x80);
+ if (err)
+ goto pmic_error;
/*
- * V18ACNT:
- * Bits 7:6 (00) - Disable low power mode on SLP_S0# assertion
- * Bits 5:4 (10) - Nominal voltage set to 1.8V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * PWFAULT_MASK1 Register settings
+ * [7] : 1b V4 Power Fault Masked
+ * [4] : 1b V7 Power Fault Masked
+ * [2] : 1b V9 Power Fault Masked
+ * [0] : 1b V13 Power Fault Masked
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x34, 0x2a);
+ err = I2C_PMIC_WRITE(TPS650X30_REG_PWFAULT_MASK1, 0x95);
+ if (err)
+ goto pmic_error;
/*
- * V100ACNT:
- * Bits 7:6 (00) - Disable low power mode on SLP_S0# assertion
- * Bits 5:4 (01) - Nominal voltage 1.0V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * Discharge control 4 register configuration
+ * [7:6] : 00b Reserved
+ * [5:4] : 01b V3.3S discharge resistance (V6S), 100 Ohm
+ * [3:2] : 01b V18S discharge resistance (V8S), 100 Ohm
+ * [1:0] : 01b V100S discharge resistance (V11S), 100 Ohm
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x1a);
+ err = I2C_PMIC_WRITE(TPS650X30_REG_DISCHCNT4, 0x15);
+ if (err)
+ goto pmic_error;
/*
- * V085ACNT:
- * Bits 7:6 (00) - Disable low power mode on SLP_S0# assertion
- * Bits 5:4 (11) - Nominal voltage 1.0V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * Discharge control 3 register configuration
+ * [7:6] : 01b V1.8U_2.5U discharge resistance (V9), 100 Ohm
+ * [5:4] : 01b V1.2U discharge resistance (V10), 100 Ohm
+ * [3:2] : 01b V100A discharge resistance (V11), 100 Ohm
+ * [1:0] : 01b V085A discharge resistance (V12), 100 Ohm
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x3a);
-}
+ err = I2C_PMIC_WRITE(TPS650X30_REG_DISCHCNT3, 0x55);
+ if (err)
+ goto pmic_error;
-static void board_pmic_enable_slp_s0_vr_decay(void)
-{
/*
- * VCCIOCNT:
- * Bit 6 (1) - Enable decay of VCCIO on SLP_S0# assertion
- * Bits 5:4 (00) - Nominal output voltage: 0.975V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * Discharge control 2 register configuration
+ * [7:6] : 01b V5ADS3 discharge resistance (V5), 100 Ohm
+ * [5:4] : 01b V33A_DSW discharge resistance (V6), 100 Ohm
+ * [3:2] : 01b V33PCH discharge resistance (V7), 100 Ohm
+ * [1:0] : 01b V18A discharge resistance (V8), 100 Ohm
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x4a);
+ err = I2C_PMIC_WRITE(TPS650X30_REG_DISCHCNT2, 0x55);
+ if (err)
+ goto pmic_error;
/*
- * V18ACNT:
- * Bits 7:6 (01) - Enable low power mode on SLP_S0# assertion
- * Bits 5:4 (10) - Nominal voltage set to 1.8V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * Discharge control 1 register configuration
+ * [7:2] : 00b Reserved
+ * [1:0] : 01b VCCIO discharge resistance (V4), 100 Ohm
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x34, 0x6a);
+ err = I2C_PMIC_WRITE(TPS650X30_REG_DISCHCNT1, 0x01);
+ if (err)
+ goto pmic_error;
/*
- * V100ACNT:
- * Bits 7:6 (01) - Enable low power mode on SLP_S0# assertion
- * Bits 5:4 (01) - Nominal voltage 1.0V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * Increase Voltage
+ * [7:0] : 0x2a default
+ * [5:4] : 10b default
+ * [5:4] : 01b 5.1V (0x1a)
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x5a);
+ err = I2C_PMIC_WRITE(TPS650X30_REG_V5ADS3CNT, 0x1a);
+ if (err)
+ goto pmic_error;
/*
- * V085ACNT:
- * Bits 7:6 (01) - Enable low power mode on SLP_S0# assertion
- * Bits 5:4 (11) - Nominal voltage 1.0V
- * Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
- * Bits 1:0 (10) - VR set to AUTO operating mode
+ * PBCONFIG Register configuration
+ * [7] : 1b Power button debounce, 0ms (no debounce)
+ * [6] : 0b Power button reset timer logic, no action (default)
+ * [5:0] : 011111b Force an Emergency reset time, 31s (default)
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x7a);
-}
+ err = I2C_PMIC_WRITE(TPS650X30_REG_PBCONFIG, 0x9F);
+ if (err)
+ goto pmic_error;
-void power_board_handle_host_sleep_event(enum host_sleep_event state)
-{
- if (state == HOST_SLEEP_EVENT_S0IX_SUSPEND)
- board_pmic_enable_slp_s0_vr_decay();
- else if (state == HOST_SLEEP_EVENT_S0IX_RESUME)
- board_pmic_disable_slp_s0_vr_decay();
+ CPRINTS("PMIC init done");
+ pmic_initialized = 1;
+ return;
+
+pmic_error:
+ CPRINTS("PMIC init failed: %d", err);
}
-static void board_pmic_init(void)
+static void chipset_pre_init(void)
{
- board_report_pmic_fault("SYSJUMP");
-
- if (system_jumped_to_this_image())
- return;
-
- /* DISCHGCNT3 - enable 100 ohm discharge on V1.00A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3e, 0x04);
-
- board_pmic_disable_slp_s0_vr_decay();
-
- /* VRMODECTRL - disable low-power mode for all rails */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3b, 0x1f);
+ board_pmic_init();
}
-DECLARE_HOOK(HOOK_INIT, board_pmic_init, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, chipset_pre_init, HOOK_PRIO_DEFAULT);
/* Initialize board. */
static void board_init(void)
@@ -418,10 +403,10 @@ static void board_init(void)
NPCX_PUPD_EN1 |= (1 << NPCX_DEVPU1_F_SPI_PUD_EN);
/* Provide AC status to the PCH */
- gpio_set_level(GPIO_PCH_ACOK, extpower_is_present());
+ gpio_set_level(GPIO_PCH_ACPRESENT, extpower_is_present());
/* Enable sensors power supply */
- gpio_set_level(GPIO_PP1800_DX_SENSOR, 1);
+ /* dnojiri: how do we enable it? */
/* Enable VBUS interrupt */
gpio_enable_interrupt(GPIO_USB_C0_VBUS_WAKE_L);
@@ -430,15 +415,6 @@ static void board_init(void)
/* Enable pericom BC1.2 interrupts */
gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_L);
gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_L);
-
- /* Level of sensor's I2C and interrupt are 3.3V on proto board */
- if(system_get_board_version() < 2) {
- /* ACCELGYRO3_INT_L */
- gpio_set_flags(GPIO_ACCELGYRO3_INT_L, GPIO_INT_FALLING);
- /* I2C3_SCL / I2C3_SDA */
- gpio_set_flags(GPIO_I2C3_SCL, GPIO_INPUT);
- gpio_set_flags(GPIO_I2C3_SDA, GPIO_INPUT);
- }
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
@@ -447,29 +423,23 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
*/
static void board_extpower(void)
{
- gpio_set_level(GPIO_PCH_ACOK, extpower_is_present());
+ gpio_set_level(GPIO_PCH_ACPRESENT, extpower_is_present());
}
DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT);
-/**
- * Set active charge port -- only one port can be active at a time.
- *
- * @param charge_port Charge port to enable.
- *
- * Returns EC_SUCCESS if charge port is accepted and made active,
- * EC_ERROR_* otherwise.
- */
+/* Set active charge port -- only one port can be active at a time. */
int board_set_active_charge_port(int charge_port)
{
/* charge port is a physical port */
int is_real_port = (charge_port >= 0 &&
charge_port < CONFIG_USB_PD_PORT_COUNT);
- /* check if we are source VBUS on the port */
- int source = gpio_get_level(charge_port == 0 ? GPIO_USB_C0_5V_EN :
- GPIO_USB_C1_5V_EN);
+ /* check if we are sourcing VBUS on the port */
+ /* dnojiri: revisit */
+ int is_source = gpio_get_level(charge_port == 0 ?
+ GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN);
- if (is_real_port && source) {
- CPRINTF("Skip enable p%d", charge_port);
+ if (is_real_port && is_source) {
+ CPRINTF("No charging on source port p%d is ", charge_port);
return EC_ERROR_INVAL;
}
@@ -481,6 +451,8 @@ int board_set_active_charge_port(int charge_port)
gpio_set_level(GPIO_USB_C1_CHARGE_L, 1);
} else {
/* Make sure non-charging port is disabled */
+ /* dnojiri: revisit. there is always this assumption that
+ * battery is present. If not, this may cause brownout. */
gpio_set_level(charge_port ? GPIO_USB_C0_CHARGE_L :
GPIO_USB_C1_CHARGE_L, 1);
/* Enable charging port */
@@ -491,80 +463,33 @@ int board_set_active_charge_port(int charge_port)
return EC_SUCCESS;
}
-/**
- * Set the charge limit based upon desired maximum.
- *
- * @param port Port number.
- * @param supplier Charge supplier type.
- * @param charge_ma Desired charge limit (mA).
- * @param charge_mv Negotiated charge voltage (mV).
- */
void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- /*
- * Limit the input current to 96% negotiated limit,
- * to account for the charger chip margin.
- */
+ /*
+ * Limit the input current to 96% negotiated limit,
+ * to account for the charger chip margin.
+ */
charge_ma = charge_ma * 96 / 100;
- charge_set_input_current_limit(MAX(charge_ma,
- CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
-}
-
-/**
- * Return whether ramping is allowed for given supplier
- */
-int board_is_ramp_allowed(int supplier)
-{
- /* Don't allow ramping in RO when write protected */
- if (!system_is_in_rw() && system_is_locked())
- return 0;
- else
- return (supplier == CHARGE_SUPPLIER_BC12_DCP ||
- supplier == CHARGE_SUPPLIER_BC12_SDP ||
- supplier == CHARGE_SUPPLIER_BC12_CDP ||
- supplier == CHARGE_SUPPLIER_OTHER);
-}
-
-/**
- * Return the maximum allowed input current
- */
-int board_get_ramp_current_limit(int supplier, int sup_curr)
-{
- switch (supplier) {
- case CHARGE_SUPPLIER_BC12_DCP:
- return 2000;
- case CHARGE_SUPPLIER_BC12_SDP:
- return 1000;
- case CHARGE_SUPPLIER_BC12_CDP:
- case CHARGE_SUPPLIER_PROPRIETARY:
- return sup_curr;
- default:
- return 500;
- }
+ charge_set_input_current_limit(
+ MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT),
+ charge_mv);
}
void board_hibernate(void)
{
CPRINTS("Triggering PMIC shutdown.");
uart_flush_output();
-
- /* Trigger PMIC shutdown. */
- if (i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x49, 0x01)) {
- /*
- * If we can't tell the PMIC to shutdown, instead reset
- * and don't start the AP. Hopefully we'll be able to
- * communicate with the PMIC next time.
- */
- CPRINTS("PMIC i2c failed.");
- system_reset(SYSTEM_RESET_LEAVE_AP_OFF);
- }
-
- /* Await shutdown. */
- while (1)
- ;
+ /* dnojiri: revisit */
}
+const struct pwm_t pwm_channels[] = {
+ [PWM_CH_LED_RED] = { 3, PWM_CONFIG_DSLEEP, 100 },
+ [PWM_CH_LED_GREEN] = { 5, PWM_CONFIG_DSLEEP, 100 },
+ [PWM_CH_FAN] = {4, PWM_CONFIG_OPEN_DRAIN, 25000},
+};
+BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
+
/* Lid Sensor mutex */
static struct mutex g_lid_mutex;
static struct mutex g_base_mutex;
@@ -717,12 +642,6 @@ void lid_angle_peripheral_enable(int enable)
}
#endif
-static void board_chipset_reset(void)
-{
- board_report_pmic_fault("CHIPSET RESET");
-}
-DECLARE_HOOK(HOOK_CHIPSET_RESET, board_chipset_reset, HOOK_PRIO_DEFAULT);
-
/* Called on AP S3 -> S0 transition */
static void board_chipset_resume(void)
{
@@ -736,15 +655,3 @@ static void board_chipset_suspend(void)
gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
}
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
-
-static void board_chipset_startup(void)
-{
- gpio_set_level(GPIO_ENABLE_TOUCHPAD, 1);
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT);
-
-static void board_chipset_shutdown(void)
-{
- gpio_set_level(GPIO_ENABLE_TOUCHPAD, 0);
-}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT);
diff --git a/board/nami/board.h b/board/nami/board.h
index 57bbeeb3df..9e077163c9 100644
--- a/board/nami/board.h
+++ b/board/nami/board.h
@@ -18,6 +18,7 @@
#define CONFIG_ADC
#define CONFIG_BACKLIGHT_LID
#define CONFIG_BOARD_VERSION
+#define CONFIG_BOARD_SPECIFIC_VERSION
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
#define CONFIG_DPTF
#define CONFIG_DPTF_DEVICE_ORIENTATION
@@ -32,6 +33,7 @@
#define CONFIG_LOW_POWER_IDLE
#define CONFIG_LTO
#define CONFIG_CHIP_PANIC_BACKUP
+#define CONFIG_PWM
#define CONFIG_SOFTWARE_PANIC
#define CONFIG_SPI_FLASH_REGS
#define CONFIG_SPI_FLASH_W25X40
@@ -45,9 +47,7 @@
#define CONFIG_WIRELESS
#define CONFIG_WIRELESS_SUSPEND \
(EC_WIRELESS_SWITCH_WLAN | EC_WIRELESS_SWITCH_WLAN_POWER)
-#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L
#define WIRELESS_GPIO_WLAN_POWER GPIO_PP3300_DX_WLAN
-#define WIRELESS_GPIO_WWAN GPIO_PP3300_DX_LTE
/* EC console commands */
#define CONFIG_CMD_ACCELS
@@ -102,9 +102,6 @@
/* Sensor */
#define CONFIG_TEMP_SENSOR
-#define CONFIG_TEMP_SENSOR_BD99992GW
-/* TODO(crosbug.com/p/61098): Is this the correct thermistor? */
-#define CONFIG_THERMISTOR_NCP15WB
#define CONFIG_MKBP_EVENT
#define CONFIG_MKBP_USE_HOST_EVENT
@@ -165,19 +162,18 @@
/* I2C ports */
#define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0
#define I2C_PORT_TCPC1 NPCX_I2C_PORT0_1
+#define I2C_PORT_USB_CHARGER_0 NPCX_I2C_PORT0_0
#define I2C_PORT_USB_CHARGER_1 NPCX_I2C_PORT0_1
-#define I2C_PORT_USB_CHARGER_0 NPCX_I2C_PORT1
-#define I2C_PORT_CHARGER NPCX_I2C_PORT1
#define I2C_PORT_BATTERY NPCX_I2C_PORT1
+#define I2C_PORT_CHARGER NPCX_I2C_PORT1
#define I2C_PORT_PMIC NPCX_I2C_PORT2
-#define I2C_PORT_MP2949 NPCX_I2C_PORT2
+/* dnojiri: KB backlight */
#define I2C_PORT_GYRO NPCX_I2C_PORT3
-#define I2C_PORT_BARO NPCX_I2C_PORT3
-#define I2C_PORT_ACCEL I2C_PORT_GYRO
-#define I2C_PORT_THERMAL I2C_PORT_PMIC
+#define I2C_PORT_ACCEL NPCX_I2C_PORT3
+#define I2C_PORT_THERMAL NPCX_I2C_PORT3
+/* dnojiri: ALS, G-sensor */
/* I2C addresses */
-#define I2C_ADDR_BD99992 0x60
#define I2C_ADDR_MP2949 0x40
#ifndef __ASSEMBLER__
@@ -197,11 +193,8 @@ enum power_signal {
POWER_SIGNAL_COUNT
};
-/* Nautilus doesn't have systherm0 and systherm3 */
enum temp_sensor_id {
- TEMP_SENSOR_BATTERY, /* BD99956GW TSENSE */
- TEMP_SENSOR_CHARGER, /* BD99992GW SYSTHERM1 */
- TEMP_SENSOR_DRAM, /* BD99992GW SYSTHERM2 */
+ TEMP_SENSOR_BATTERY,
TEMP_SENSOR_COUNT
};
@@ -225,6 +218,14 @@ enum adc_channel {
ADC_CH_COUNT
};
+enum pwm_channel {
+ PWM_CH_LED_RED,
+ PWM_CH_LED_GREEN,
+ PWM_CH_FAN,
+ /* Number of PWM channels */
+ PWM_CH_COUNT
+};
+
/* TODO(crosbug.com/p/61098): Verify the numbers below. */
/*
* delay to turn on the power supply max is ~16ms.
diff --git a/board/nami/gpio.inc b/board/nami/gpio.inc
index 93642ac6a0..597d718bae 100644
--- a/board/nami/gpio.inc
+++ b/board/nami/gpio.inc
@@ -8,116 +8,112 @@
/* Declare symbolic names for all the GPIOs that we care about.
* Note: Those with interrupt handlers must be declared first. */
-GPIO_INT(USB_C0_PD_INT_ODL, PIN(3, 7), GPIO_INT_FALLING, tcpc_alert_event)
-GPIO_INT(USB_C1_PD_INT_ODL, PIN(C, 5), GPIO_INT_FALLING, tcpc_alert_event)
+/*
+ * ADCs are not configured in this file but listed below for reference.
+ *
+ * PIN(4, 4) ADC1: IADP_AMON_BMON
+ * PIN(4, 3) ADC2: PPVAR_BOOSTIN_SENSE
+ */
+
+GPIO_INT(USB_C0_PD_INT_ODL, PIN(3, 7), GPIO_INT_FALLING, tcpc_alert_event)
+GPIO_INT(USB_C1_PD_INT_ODL, PIN(7, 1), GPIO_INT_FALLING, tcpc_alert_event)
#ifdef CONFIG_POWER_S0IX
-GPIO_INT(PCH_SLP_S0_L, PIN(7, 5), GPIO_INT_BOTH, power_signal_interrupt)
-#endif
-/* Use VW signals instead of GPIOs */
-#ifndef CONFIG_ESPI_VW_SIGNALS
-GPIO_INT(PCH_SLP_S3_L, PIN(7, 3), GPIO_INT_BOTH, power_signal_interrupt)
-GPIO_INT(PCH_SLP_S4_L, PIN(8, 6), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(PCH_SLP_S0_L, PIN(7, 5), GPIO_INT_BOTH, power_signal_interrupt)
#endif
-GPIO_INT(PCH_SLP_SUS_L, PIN(6, 2), GPIO_INT_BOTH, power_signal_interrupt)
-GPIO_INT(RSMRST_L_PGOOD, PIN(B, 0), GPIO_INT_BOTH, power_signal_interrupt)
-GPIO_INT(PMIC_DPWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt)
-GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH | GPIO_PULL_UP, power_button_interrupt)
-GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH, lid_interrupt)
-GPIO_INT(VOLUME_DOWN_L, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
-GPIO_INT(VOLUME_UP_L, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt)
-GPIO_INT(WP_L, PIN(4, 0), GPIO_INT_BOTH, switch_interrupt)
-GPIO_INT(AC_PRESENT, PIN(C, 1), GPIO_INT_BOTH, extpower_interrupt)
-GPIO_INT(USB_C0_VBUS_WAKE_L, PIN(9, 3), GPIO_INT_BOTH | GPIO_PULL_UP, vbus0_evt)
-GPIO_INT(USB_C1_VBUS_WAKE_L, PIN(9, 7), GPIO_INT_BOTH | GPIO_PULL_UP, vbus1_evt)
-GPIO_INT(USB_C0_BC12_INT_L, PIN(D, 3), GPIO_INT_FALLING, usb0_evt)
-GPIO_INT(USB_C1_BC12_INT_L, PIN(3, 3), GPIO_INT_FALLING, usb1_evt)
+GPIO_INT(PCH_SLP_SUS_L, PIN(6, 2), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(RSMRST_L_PGOOD, PIN(B, 0), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(PMIC_DPWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt)
+GPIO_INT(POWER_BUTTON_L, PIN(0, 3), GPIO_INT_BOTH | GPIO_PULL_UP,power_button_interrupt)
+GPIO_INT(LID_OPEN, PIN(8, 3), GPIO_INT_BOTH, lid_interrupt)
+GPIO_INT(VOLUME_DOWN_L, PIN(7, 3), GPIO_INT_BOTH | GPIO_PULL_UP,button_interrupt)
+GPIO_INT(VOLUME_UP_L, PIN(8, 6), GPIO_INT_BOTH | GPIO_PULL_UP,button_interrupt)
+GPIO_INT(WP_L, PIN(9, 3), GPIO_INT_BOTH, switch_interrupt)
+GPIO_INT(AC_PRESENT, PIN(C, 1), GPIO_INT_BOTH, extpower_interrupt)
+GPIO_INT(USB_C0_VBUS_WAKE_L, PIN(9, 7), GPIO_INT_BOTH | GPIO_PULL_UP,vbus0_evt)
+GPIO_INT(USB_C1_VBUS_WAKE_L, PIN(C, 5), GPIO_INT_BOTH | GPIO_PULL_UP,vbus1_evt)
+GPIO_INT(USB_C0_BC12_INT_L, PIN(D, 2), GPIO_INT_FALLING, usb0_evt)
+GPIO_INT(USB_C1_BC12_INT_L, PIN(D, 3), GPIO_INT_FALLING, usb1_evt)
GPIO_INT(ACCELGYRO3_INT_L, PIN(3, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt)
+/* Used to wake up system from deep S3. */
+/* GPIO_INT(TP_INT_CONN, PIN(4, 2), GPIO_INT_BOTH, trackpad_connect) dnojiri: Revisit */
+/* GPIO_INT(ALS_INT, PIN(3, 2),,) dnojiri: Revisit */
+/* GPIO_INT(3AXIS_INT, PIN(9, 5),,) dnojiri: Revisit */
+/* GPIO_INT(TABLET_MODE_L, PIN(7, 2), GPIO_INT_BOTH, tablet_mode_interrupt) dnojiri: Revisit */
-GPIO(ENABLE_TOUCHPAD, PIN(4, 5), GPIO_OUT_LOW)
-GPIO(PCH_RTCRST, PIN(2, 7), GPIO_OUT_LOW) /* RTCRST# to SOC (>= rev4) */
-GPIO(ENABLE_BACKLIGHT, PIN(5, 6), GPIO_OUT_LOW) /* Enable Backlight */
-GPIO(WLAN_OFF_L, PIN(7, 2), GPIO_OUT_LOW) /* Disable WLAN */
-GPIO(PP3300_DX_WLAN, PIN(A, 7), GPIO_OUT_LOW) /* Enable WLAN 3.3V Power */
-GPIO(CPU_PROCHOT, PIN(8, 1), GPIO_OUT_HIGH) /* PROCHOT# to SOC */
-GPIO(PCH_ACOK, PIN(5, 0), GPIO_ODR_LOW) /* ACOK to SOC */
-GPIO(PCH_WAKE_L, PIN(A, 3), GPIO_ODR_HIGH) /* Wake SOC */
-GPIO(PCH_RSMRST_L, PIN(7, 0), GPIO_OUT_LOW) /* RSMRST# to SOC */
-GPIO(PCH_PWRBTN_L, PIN(4, 1), GPIO_ODR_HIGH) /* Power Button to SOC */
-GPIO(EC_PLATFORM_RST, PIN(A, 6), GPIO_OUT_LOW) /* EC Reset to LDO_EN */
-GPIO(SYS_RESET_L, PIN(6, 1), GPIO_ODR_HIGH) /* Cold Reset to SOC */
-GPIO(PMIC_SLP_SUS_L, PIN(8, 5), GPIO_OUT_LOW) /* SLP_SUS# to PMIC */
-GPIO(BATTERY_PRESENT_L, PIN(3, 4), GPIO_INPUT) /* Battery Present */
-GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) /* Case Closed Debug Mode */
-GPIO(ENTERING_RW, PIN(7, 6), GPIO_OUTPUT) /* EC Entering RW */
-GPIO(PMIC_INT_L, PIN(6, 0), GPIO_INPUT) /* PMIC interrupt */
+GPIO(ENABLE_BACKLIGHT, PIN(6, 7), GPIO_OUT_LOW) /* LCD backlight */
+GPIO(PP3300_DX_WLAN, PIN(A, 7), GPIO_OUT_LOW) /* Enable WLAN 3.3V Power */
+GPIO(CPU_PROCHOT, PIN(8, 1), GPIO_OUT_HIGH) /* PROCHOT# to SOC */
+GPIO(PCH_ACPRESENT, PIN(5, 0), GPIO_ODR_LOW) /* ACOK to SOC */
+GPIO(PCH_WAKE_L, PIN(A, 3), GPIO_ODR_HIGH) /* Wake SOC */
+GPIO(PCH_RSMRST_L, PIN(7, 0), GPIO_OUT_LOW) /* RSMRST# to SOC */
+GPIO(PCH_PWRBTN_L, PIN(7, 4), GPIO_ODR_HIGH) /* Power Button to SOC */
+GPIO(EC_PLATFORM_RST, PIN(4, 5), GPIO_OUT_LOW) /* EC Reset to LDO_EN */
+GPIO(SYS_RESET_L, PIN(6, 1), GPIO_ODR_HIGH) /* Cold Reset to SOC */
+GPIO(PMIC_SLP_SUS_L, PIN(8, 5), GPIO_OUT_LOW) /* SLP_SUS# to PMIC */
+GPIO(BATTERY_PRESENT_L, PIN(3, 4), GPIO_INPUT) /* Battery Present */
+GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) /* Case Closed Debug Mode */
+GPIO(ENTERING_RW, PIN(7, 6), GPIO_OUTPUT) /* EC Entering RW */
+GPIO(PMIC_INT_L, PIN(6, 0), GPIO_INPUT) /* PMIC interrupt */
#ifndef CONFIG_POWER_S0IX
GPIO(PCH_SLP_S0_L, PIN(7, 5), GPIO_INPUT)
#endif
-
-/* NC pins */
-GPIO(GPIOD2_NC, PIN(D, 2), GPIO_INPUT | GPIO_PULL_UP)
-
-/* TODO(b/35585396): Make use of these GPIOs */
-GPIO(PP1800_DX_SENSOR, PIN(E, 7), GPIO_OUTPUT)
-
-GPIO(WLAN_PE_RST, PIN(1, 2), GPIO_OUTPUT)
-GPIO(PP3300_DX_LTE, PIN(0, 2), GPIO_OUT_LOW)
-GPIO(LTE_GPS_OFF_L, PIN(0, 0), GPIO_ODR_HIGH)
-GPIO(LTE_BODY_SAR_L, PIN(0, 1), GPIO_ODR_HIGH)
-GPIO(LTE_WAKE_L, PIN(7, 1), GPIO_INPUT)
-GPIO(LTE_OFF_ODL, PIN(8, 0), GPIO_ODR_LOW)
-/* end of TODO */
+GPIO(CR50_RESET_ODL, PIN(0, 2), GPIO_ODR_HIGH) /* Cr50 Reset. dnojiri: unused. */
+GPIO(GPP_B14, PIN(C, 2), GPIO_INPUT) /* Used for Intel's experimental uCode/P-unit update */
+/* Will be used to shut down EC on board_hibernate. */
+GPIO(EC_HIBERNATE, PIN(0, 1), GPIO_OUT_LOW)
+/* GPIO(PCH_RTCRST, PIN(E, 7), GPIO_INPUT) dnojiri: Revisit */
/* I2C pins - these will be reconfigured for alternate function below */
-GPIO(I2C0_0_SCL, PIN(B, 5), GPIO_INPUT) /* EC_I2C0_0_USBC_3V3_SCL */
-GPIO(I2C0_0_SDA, PIN(B, 4), GPIO_INPUT) /* EC_I2C0_0_USBC_3V3_SDA */
-GPIO(I2C0_1_SCL, PIN(B, 3), GPIO_INPUT) /* EC_I2C0_1_USBC_3V3_SCL */
-GPIO(I2C0_1_SDA, PIN(B, 2), GPIO_INPUT) /* EC_I2C0_1_USBC_3V3_SDA */
-GPIO(I2C1_SCL, PIN(9, 0), GPIO_INPUT) /* EC_I2C1_3V3_SCL */
-GPIO(I2C1_SDA, PIN(8, 7), GPIO_INPUT) /* EC_I2C1_3V3_SDA */
-GPIO(I2C2_SCL, PIN(9, 2), GPIO_INPUT) /* EC_I2C2_PMIC_3V3_SCL */
-GPIO(I2C2_SDA, PIN(9, 1), GPIO_INPUT) /* EC_I2C2_PMIC_3V3_SDA */
-GPIO(I2C3_SCL, PIN(D, 1), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C3_SENSOR_1V8_SCL */
-GPIO(I2C3_SDA, PIN(D, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C3_SENSOR_1V8_SDA */
+GPIO(I2C0_0_SCL, PIN(B, 5), GPIO_INPUT) /* EC_I2C0_0_USBC_3V3_SCL */
+GPIO(I2C0_0_SDA, PIN(B, 4), GPIO_INPUT) /* EC_I2C0_0_USBC_3V3_SDA */
+GPIO(I2C0_1_SCL, PIN(B, 3), GPIO_INPUT) /* EC_I2C0_1_USBC_3V3_SCL */
+GPIO(I2C0_1_SDA, PIN(B, 2), GPIO_INPUT) /* EC_I2C0_1_USBC_3V3_SDA */
+GPIO(I2C1_SCL, PIN(9, 0), GPIO_INPUT) /* EC_I2C1_3V3_SCL */
+GPIO(I2C1_SDA, PIN(8, 7), GPIO_INPUT) /* EC_I2C1_3V3_SDA */
+GPIO(I2C2_SCL, PIN(9, 2), GPIO_INPUT) /* EC_I2C2_PMIC_3V3_SCL */
+GPIO(I2C2_SDA, PIN(9, 1), GPIO_INPUT) /* EC_I2C2_PMIC_3V3_SDA */
+GPIO(I2C3_SCL, PIN(D, 1), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C3_SENSOR_1V8_SCL */
+GPIO(I2C3_SDA, PIN(D, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* EC_I2C3_SENSOR_1V8_SDA */
/* rev0: 5V enables: INPUT=1.5A, OUT_LOW=OFF, OUT_HIGH=3A */
-GPIO(USB_C0_5V_EN, PIN(4, 2), GPIO_OUT_LOW) /* C0 5V Enable */
-GPIO(USB_C0_3A_EN, PIN(6, 6), GPIO_OUT_LOW) /* C0 Enable 3A */
-GPIO(USB_C0_CHARGE_L, PIN(C, 0), GPIO_OUT_LOW) /* C0 Charge enable */
-GPIO(USB_C1_5V_EN, PIN(B, 1), GPIO_OUT_LOW) /* C1 5V Enable */
-GPIO(USB_C1_3A_EN, PIN(3, 5), GPIO_OUT_LOW) /* C1 3A Enable */
-GPIO(USB_C1_CHARGE_L, PIN(C, 3), GPIO_OUT_LOW) /* C1 Charge enable */
-GPIO(USB_C0_PD_RST_L, PIN(0, 3), GPIO_ODR_HIGH) /* C0 PD Reset */
-GPIO(USB_C1_PD_RST_L, PIN(7, 4), GPIO_ODR_HIGH) /* C1 PD Reset */
-GPIO(USB_C0_DP_HPD, PIN(9, 4), GPIO_INPUT) /* C0 DP Hotplug Detect */
-GPIO(USB_C1_DP_HPD, PIN(A, 5), GPIO_INPUT) /* C1 DP Hotplug Detect */
-GPIO(USB_C0_TCPC_PWR, PIN(8, 4), GPIO_OUT_LOW) /* Enable C0 TCPC Power */
-GPIO(USB2_OTG_ID, PIN(A, 1), GPIO_ODR_LOW) /* OTG ID */
-GPIO(USB2_OTG_VBUSSENSE, PIN(9, 5), GPIO_OUT_LOW) /* OTG VBUS Sense */
+GPIO(USB_C0_5V_EN, PIN(4, 0), GPIO_OUT_LOW) /* C0 5V Enable */
+GPIO(USB_C0_3A_EN, PIN(3, 5), GPIO_OUT_LOW) /* C0 Enable 3A */
+GPIO(USB_C0_CHARGE_L, PIN(C, 0), GPIO_OUT_LOW) /* C0 Charge enable. Active low. */
+GPIO(USB_C1_5V_EN, PIN(3, 3), GPIO_OUT_LOW) /* C1 5V Enable */
+GPIO(USB_C1_3A_EN, PIN(6, 6), GPIO_OUT_LOW) /* C1 3A Enable */
+GPIO(USB_C1_CHARGE_L, PIN(C, 3), GPIO_OUT_LOW) /* C1 Charge enable. Active low. */
+GPIO(USB_C0_PD_RST_L, PIN(C, 6), GPIO_ODR_HIGH) /* C0 PD Reset */
+GPIO(USB_C1_PD_RST_L, PIN(0, 0), GPIO_ODR_HIGH) /* C1 PD Reset */
+GPIO(USB_C0_DP_HPD, PIN(9, 4), GPIO_INPUT) /* C0 DP Hotplug Detect */
+GPIO(USB_C1_DP_HPD, PIN(A, 5), GPIO_INPUT) /* C1 DP Hotplug Detect */
+GPIO(USB_PP3300_USB_PD, PIN(8, 4), GPIO_INPUT) /* Reserved. Currently, has no effect. */
+GPIO(USB2_OTG_ID, PIN(5, 7), GPIO_ODR_LOW) /* OTG ID */
-/* LEDs (2 colors on each port) */
-GPIO(LED_ACIN, PIN(B, 6), GPIO_OUT_LOW) /* ACIN LED */
-GPIO(POWER_LED, PIN(B, 7), GPIO_OUT_LOW) /* Power LED */
-GPIO(LED_CHARGE, PIN(C, 6), GPIO_OUT_LOW) /* Charge LED */
+/* Sensors */
-/* Board ID */
-GPIO(BOARD_VERSION1, PIN(8, 6), GPIO_INPUT) /* Board ID bit0 */
-GPIO(BOARD_VERSION2, PIN(C, 2), GPIO_INPUT) /* Board ID bit1 */
-GPIO(BOARD_VERSION3, PIN(C, 4), GPIO_INPUT) /* Board ID bit2 */
+/* Trackpad */
+GPIO(TP_INT_EN, PIN(A, 1), GPIO_OUT_LOW)
/* Alternate functions GPIO definitions */
-ALTERNATE(PIN_MASK(6, 0x30), 1, MODULE_UART, 0) /* GPIO64-65 */ /* UART from EC to Servo */
-ALTERNATE(PIN_MASK(8, 0x80), 1, MODULE_I2C, 0) /* GPIO87 */ /* EC_I2C1_3V3_SDA */
-ALTERNATE(PIN_MASK(9, 0x01), 1, MODULE_I2C, 0) /* GPIO90 */ /* EC_I2C1_3V3_SCL */
-ALTERNATE(PIN_MASK(9, 0x06), 1, MODULE_I2C, 0) /* GPIO91-92 */ /* EC_I2C2_PMIC_3V3_SDA/SCL */
-ALTERNATE(PIN_MASK(B, 0x30), 1, MODULE_I2C, 0) /* GPIOB4-B5 */ /* EC_I2C0_0_USBC_3V3_SDA/SCL */
-ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, 0) /* GPOPB2-B3 */ /* EC_I2C0_1_3V3_SDA/SCL */
-ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* GPIOD0-D1 */ /* EC_I2C3_SENSOR_1V8_SDA/SCL */
+ALTERNATE(PIN_MASK(6, 0x30), 1, MODULE_UART, 0) /* GPIO64-65 UART from EC to Servo */
+ALTERNATE(PIN_MASK(8, 0x80), 1, MODULE_I2C, 0) /* GPIO87 EC_I2C1_3V3_SDA */
+ALTERNATE(PIN_MASK(9, 0x01), 1, MODULE_I2C, 0) /* GPIO90 EC_I2C1_3V3_SCL */
+ALTERNATE(PIN_MASK(9, 0x06), 1, MODULE_I2C, 0) /* GPIO91-92 EC_I2C2_SDA/SCL */
+ALTERNATE(PIN_MASK(B, 0x30), 1, MODULE_I2C, 0) /* GPIOB4-B5 EC_I2C0_0_SDA/SCL */
+ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, 0) /* GPOPB2-B3 EC_I2C0_1_SDA/SCL */
+ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* GPIOD0-D1 EC_I2C3_SDA/SCL */
+ALTERNATE(PIN_MASK(B, 0x40), 1, MODULE_PWM, 0) /* GPIOB6 PWM1 Fan control */
+ALTERNATE(PIN_MASK(8, 0x01), 1, MODULE_PWM, 0) /* GPIO80 PWM3 LED White */
+ALTERNATE(PIN_MASK(B, 0x80), 1, MODULE_PWM, 0) /* GPIOB7 PWM5 LED Yellow */
+ALTERNATE(PIN_MASK(A, 0x40), 1, MODULE_PWM, 0) /* GPIOA6 TA2 */
/* Keyboard pins */
-ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, 0)
-ALTERNATE(PIN_MASK(2, 0xfc), 0, MODULE_KEYBOARD_SCAN, 0)
-ALTERNATE(PIN_MASK(2, 0x03), 0, MODULE_KEYBOARD_SCAN, 0)
-ALTERNATE(PIN_MASK(0, 0xe0), 0, MODULE_KEYBOARD_SCAN, 0)
-ALTERNATE(PIN_MASK(1, 0x7f), 0, MODULE_KEYBOARD_SCAN, 0)
+#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP)
+#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH)
+ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT)
+ALTERNATE(PIN_MASK(2, 0xfc), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT)
+ALTERNATE(PIN_MASK(2, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
+ALTERNATE(PIN_MASK(1, 0x7f), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
+ALTERNATE(PIN_MASK(0, 0xf0), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
+ALTERNATE(PIN_MASK(8, 0x04), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT)
GPIO(KBD_KSO2, PIN(1, 7), GPIO_OUT_LOW)
diff --git a/board/nami/led.c b/board/nami/led.c
index 6b92ab6992..9b6942d241 100644
--- a/board/nami/led.c
+++ b/board/nami/led.c
@@ -2,132 +2,231 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * Power and battery LED control.
+ * Power and battery LED control for Fizz
*/
-#include "battery.h"
-#include "charge_manager.h"
-#include "charge_state.h"
#include "chipset.h"
+#include "console.h"
#include "ec_commands.h"
#include "gpio.h"
#include "hooks.h"
-#include "host_command.h"
#include "led_common.h"
-#include "system.h"
+#include "pwm.h"
+#include "timer.h"
#include "util.h"
-#define BAT_LED_ON 1
-#define BAT_LED_OFF 0
-
-#define LED_TOTAL_TICKS 16
-#define LED_ON_TICKS 8
-
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_POWER_LED,
- EC_LED_ID_BATTERY_LED};
-
+const enum ec_led_id supported_led_ids[] = {EC_LED_ID_POWER_LED};
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
enum led_color {
LED_OFF = 0,
LED_RED,
LED_GREEN,
- LED_BLUE,
+ LED_AMBER,
/* Number of colors, not a color itself */
LED_COLOR_COUNT
};
-/**
- * Set LED color
- *
- * @param color Enumerated color value
- */
-static void set_color(enum led_color color)
+static int set_color_power(enum led_color color, int duty)
{
- gpio_set_level(GPIO_POWER_LED, !(color == LED_BLUE));
- gpio_set_level(GPIO_LED_ACIN, !(color == LED_GREEN));
- gpio_set_level(GPIO_LED_CHARGE, !(color == LED_RED));
+ int green = 0;
+ int red = 0;
+
+ if (duty < 0 || 100 < duty)
+ return EC_ERROR_UNKNOWN;
+
+ switch (color) {
+ case LED_OFF:
+ break;
+ case LED_GREEN:
+ green = 1;
+ break;
+ case LED_RED:
+ red = 1;
+ break;
+ case LED_AMBER:
+ green = 1;
+ red = 1;
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+
+ if (red)
+ pwm_set_duty(PWM_CH_LED_RED, duty);
+ else
+ pwm_set_duty(PWM_CH_LED_RED, 0);
+
+ if (green)
+ pwm_set_duty(PWM_CH_LED_GREEN, duty);
+ else
+ pwm_set_duty(PWM_CH_LED_GREEN, 0);
+
+ return EC_SUCCESS;
}
-void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+static int set_color(enum ec_led_id id, enum led_color color, int duty)
{
- brightness_range[EC_LED_COLOR_RED] = 1;
- brightness_range[EC_LED_COLOR_BLUE] = 1;
- brightness_range[EC_LED_COLOR_GREEN] = 1;
+ switch (id) {
+ case EC_LED_ID_POWER_LED:
+ return set_color_power(color, duty);
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
}
-int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
-{
- gpio_set_level(GPIO_POWER_LED, !brightness[EC_LED_COLOR_BLUE]);
- gpio_set_level(GPIO_LED_ACIN, !brightness[EC_LED_COLOR_GREEN]);
- gpio_set_level(GPIO_LED_CHARGE, !brightness[EC_LED_COLOR_RED]);
+#define LED_PULSE_US (2 * SECOND)
+/* 40 msec for nice and smooth transition. */
+#define LED_PULSE_TICK_US (40 * MSEC)
- return EC_SUCCESS;
+/* When pulsing is enabled, brightness is incremented by <duty_inc> every
+ * <interval> usec from 0 to 100% in LED_PULSE_US usec. Then it's decremented
+ * likewise in LED_PULSE_US usec. */
+static struct {
+ uint32_t interval;
+ int duty_inc;
+ enum led_color color;
+ int duty;
+} led_pulse;
+
+#define CONFIG_TICK(interval, color) \
+ config_tick((interval), 100 / (LED_PULSE_US / (interval)), (color))
+
+static void config_tick(uint32_t interval, int duty_inc, enum led_color color)
+{
+ led_pulse.interval = interval;
+ led_pulse.duty_inc = duty_inc;
+ led_pulse.color = color;
+ led_pulse.duty = 0;
}
+static void pulse_power_led(enum led_color color)
+{
+ set_color(EC_LED_ID_POWER_LED, color, led_pulse.duty);
+ if (led_pulse.duty + led_pulse.duty_inc > 100)
+ led_pulse.duty_inc = led_pulse.duty_inc * -1;
+ else if (led_pulse.duty + led_pulse.duty_inc < 0)
+ led_pulse.duty_inc = led_pulse.duty_inc * -1;
+ led_pulse.duty += led_pulse.duty_inc;
+}
-static void nautilus_led_set_power_battery(void)
+static void led_tick(void);
+DECLARE_DEFERRED(led_tick);
+static void led_tick(void)
{
- static unsigned int power_ticks;
- enum led_color cur_led_color = LED_RED;
- enum charge_state chg_state = charge_get_state();
- int charge_percent = charge_get_percent();
-
- if (chipset_in_state(CHIPSET_STATE_ON)) {
- set_color(LED_BLUE);
- return;
+ uint32_t elapsed;
+ uint32_t next = 0;
+ uint32_t start = get_time().le.lo;
+ static uint8_t pwm_enabled = 0;
+
+ if (!pwm_enabled) {
+ pwm_enable(PWM_CH_LED_RED, 1);
+ pwm_enable(PWM_CH_LED_GREEN, 1);
+ pwm_enabled = 1;
}
+ if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ pulse_power_led(led_pulse.color);
+ elapsed = get_time().le.lo - start;
+ next = led_pulse.interval > elapsed ? led_pulse.interval - elapsed : 0;
+ hook_call_deferred(&led_tick_data, next);
+}
- /* Flash red on critical battery, which usually inhibits AP power-on. */
- if (battery_is_present() != BP_YES ||
- charge_percent < CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) {
- set_color(((power_ticks++ % LED_TOTAL_TICKS) < LED_ON_TICKS) ?
- LED_RED : LED_OFF);
- return;
- }
+static void led_suspend(void)
+{
+ CONFIG_TICK(LED_PULSE_TICK_US, LED_GREEN);
+ led_tick();
+}
+DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, led_suspend, HOOK_PRIO_DEFAULT);
- /* CHIPSET_STATE_OFF */
- switch (chg_state) {
- case PWR_STATE_DISCHARGE:
- if ((charge_get_flags() & CHARGE_FLAG_EXTERNAL_POWER) &&
- charge_percent >= BATTERY_LEVEL_NEAR_FULL)
- cur_led_color = LED_GREEN;
- else
- cur_led_color = LED_OFF;
- break;
- case PWR_STATE_CHARGE:
- cur_led_color = LED_RED;
- break;
- case PWR_STATE_ERROR:
- cur_led_color = ((power_ticks++ % LED_TOTAL_TICKS)
- < LED_ON_TICKS) ? LED_RED : LED_GREEN;
- break;
- case PWR_STATE_CHARGE_NEAR_FULL:
- case PWR_STATE_IDLE: /* External power connected in IDLE. */
- cur_led_color = LED_GREEN;
- break;
- default:
- cur_led_color = LED_RED;
- break;
- }
+static void led_shutdown(void)
+{
+ hook_call_deferred(&led_tick_data, -1);
+ if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ set_color(EC_LED_ID_POWER_LED, LED_OFF, 0);
+}
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, led_shutdown, HOOK_PRIO_DEFAULT);
+
+static void led_resume(void)
+{
+ /* Assume there is no race condition with led_tick, which also
+ * runs in hook_task. */
+ hook_call_deferred(&led_tick_data, -1);
+ if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ set_color(EC_LED_ID_POWER_LED, LED_GREEN, 100);
+}
+DECLARE_HOOK(HOOK_CHIPSET_RESUME, led_resume, HOOK_PRIO_DEFAULT);
- set_color(cur_led_color);
+void led_alert(int enable)
+{
+ if (enable) {
+ /* Overwrite the current signal */
+ config_tick(1 * SECOND, 100, LED_RED);
+ led_tick();
+ } else {
+ /* Restore the previous signal */
+ if (chipset_in_state(CHIPSET_STATE_ON))
+ led_resume();
+ else if (chipset_in_state(CHIPSET_STATE_SUSPEND))
+ led_suspend();
+ else if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ led_shutdown();
+ }
+}
- if (chg_state != PWR_STATE_ERROR)
- power_ticks = 0;
+void led_critical(void)
+{
+ hook_call_deferred(&led_tick_data, -1);
+ if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ set_color(EC_LED_ID_POWER_LED, LED_RED, 100);
}
-/**
- * Called by hook task every 250 ms
- */
-static void led_tick(void)
+static int command_led(int argc, char **argv)
{
- if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED) &&
- led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) {
- nautilus_led_set_power_battery();
+ enum ec_led_id id = EC_LED_ID_POWER_LED;
+
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ if (!strcasecmp(argv[1], "debug")) {
+ led_auto_control(id, !led_auto_control_is_enabled(id));
+ ccprintf("o%s\n", led_auto_control_is_enabled(id) ? "ff" : "n");
+ } else if (!strcasecmp(argv[1], "off")) {
+ set_color(id, LED_OFF, 0);
+ } else if (!strcasecmp(argv[1], "red")) {
+ set_color(id, LED_RED, 100);
+ } else if (!strcasecmp(argv[1], "green")) {
+ set_color(id, LED_GREEN, 100);
+ } else if (!strcasecmp(argv[1], "amber")) {
+ set_color(id, LED_AMBER, 100);
+ } else if (!strcasecmp(argv[1], "alert")) {
+ led_alert(1);
+ } else if (!strcasecmp(argv[1], "crit")) {
+ led_critical();
+ } else {
+ return EC_ERROR_PARAM1;
}
+ return EC_SUCCESS;
}
+DECLARE_CONSOLE_COMMAND(led, command_led,
+ "[debug|red|green|amber|off|alert|crit]",
+ "Turn on/off LED.");
-DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ brightness_range[EC_LED_COLOR_RED] = 100;
+ brightness_range[EC_LED_COLOR_GREEN] = 100;
+ brightness_range[EC_LED_COLOR_AMBER] = 100;
+}
+
+int led_set_brightness(enum ec_led_id id, const uint8_t *brightness)
+{
+ if (brightness[EC_LED_COLOR_RED])
+ return set_color(id, LED_RED, brightness[EC_LED_COLOR_RED]);
+ else if (brightness[EC_LED_COLOR_GREEN])
+ return set_color(id, LED_GREEN, brightness[EC_LED_COLOR_GREEN]);
+ else if (brightness[EC_LED_COLOR_AMBER])
+ return set_color(id, LED_AMBER, brightness[EC_LED_COLOR_AMBER]);
+ else
+ return set_color(id, LED_OFF, 0);
+}
diff --git a/board/nami/usb_pd_policy.c b/board/nami/usb_pd_policy.c
index 749eaff051..acf63f0e97 100644
--- a/board/nami/usb_pd_policy.c
+++ b/board/nami/usb_pd_policy.c
@@ -64,36 +64,10 @@ int board_vbus_source_enabled(int port)
static void board_vbus_update_source_current(int port)
{
- enum gpio_signal gpio_5v_en = port ? GPIO_USB_C1_5V_EN :
- GPIO_USB_C0_5V_EN;
- enum gpio_signal gpio_3a_en = port ? GPIO_USB_C1_3A_EN :
- GPIO_USB_C0_3A_EN;
-
- if (system_get_board_version() >= 1) {
- /*
- * For rev1 and beyond, 1.5 vs 3.0 A limit is controlled by a
- * dedicated gpio where high = 3.0A and low = 1.5A. VBUS on/off
- * is controlled by GPIO_USB_C0/1_5V_EN. Both of these signals
- * can remain outputs.
- */
- gpio_set_level(gpio_3a_en, vbus_rp[port] == TYPEC_RP_3A0 ?
- 1 : 0);
- gpio_set_level(gpio_5v_en, vbus_en[port]);
- } else {
- /*
- * Driving USB_Cx_5V_EN high, actually put a 16.5k resistance
- * (2x 33k in parallel) on the NX5P3290 load switch ILIM pin,
- * setting a minimum OCP current of 3186 mA.
- * Putting an internal pull-up on USB_Cx_5V_EN, effectively put
- * a 33k resistor on ILIM, setting a minimum OCP current of
- * 1505 mA.
- */
- int flags = (vbus_rp[port] == TYPEC_RP_1A5 && vbus_en[port]) ?
- (GPIO_INPUT | GPIO_PULL_UP) :
- (GPIO_OUTPUT | GPIO_PULL_UP);
- gpio_set_level(gpio_5v_en, vbus_en[port]);
- gpio_set_flags(gpio_5v_en, flags);
- }
+ gpio_set_level(port ? GPIO_USB_C1_3A_EN : GPIO_USB_C0_3A_EN,
+ vbus_rp[port] == TYPEC_RP_3A0 ? 1 : 0);
+ gpio_set_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN,
+ vbus_en[port]);
}
void typec_set_source_current_limit(int port, int rp)
@@ -117,8 +91,7 @@ int pd_set_power_supply_ready(int port)
vbus_en[port] = 1;
board_vbus_update_source_current(port);
- if (system_get_board_version() >= 2)
- pd_set_vbus_discharge(port, 0);
+ pd_set_vbus_discharge(port, 0);
/* notify host of power info change */
pd_send_host_event(PD_EVENT_POWER_CHANGE);
@@ -137,7 +110,7 @@ void pd_power_supply_reset(int port)
board_vbus_update_source_current(port);
/* Enable discharge if we were previously sourcing 5V */
- if (system_get_board_version() >= 2 && prev_en)
+ if (prev_en)
pd_set_vbus_discharge(port, 1);
/* Give back the current quota we are no longer using */