diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2021-03-18 12:15:25 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-22 07:32:48 +0000 |
commit | 9991e288816da817eb9e1b85999e8244ae8c9d70 (patch) | |
tree | ad589fa3dbac6fca57bdc805a4cf024d0ddbe0dc /board/lazor | |
parent | b46071331a2b3ce342f40aa2e575a01134fc1320 (diff) | |
download | chrome-ec-9991e288816da817eb9e1b85999e8244ae8c9d70.tar.gz |
lazor: move sku functions into separate sku.c file
Refactor board.c to move the sku-related configuration detection
functionality to it's own file. This will make the process of
including this code in Zephyr easier.
Had to add an ugly ifdef around some TCPM stuff as we don't have that
going in Zephyr yet... sorry :-(
BUG=b:183054226,b:183118990
BRANCH=none
TEST=power sequence lazor (using CrOS EC OS build)
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: Ibf746de807afe284eb63134f0af47b0d2d5ac471
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2774366
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'board/lazor')
-rw-r--r-- | board/lazor/board.c | 53 | ||||
-rw-r--r-- | board/lazor/board.h | 2 | ||||
-rw-r--r-- | board/lazor/build.mk | 2 | ||||
-rw-r--r-- | board/lazor/sku.c | 88 |
4 files changed, 93 insertions, 52 deletions
diff --git a/board/lazor/board.c b/board/lazor/board.c index dbd402b0c8..d4d1f7fd17 100644 --- a/board/lazor/board.c +++ b/board/lazor/board.c @@ -52,8 +52,6 @@ static void board_connect_c0_sbu(enum gpio_signal s); #include "gpio_list.h" -static uint8_t sku_id; - /* GPIO Interrupt Handlers */ static void tcpc_alert_event(enum gpio_signal signal) { @@ -484,21 +482,6 @@ void lid_angle_peripheral_enable(int enable) } #endif -static int board_is_clamshell(void) -{ - /* SKU ID of Limozeen: 4, 5, 6 */ - return sku_id == 4 || sku_id == 5 || sku_id == 6; -} - -enum battery_cell_type board_get_battery_cell_type(void) -{ - /* SKU ID of Limozeen: 4, 5, 6 -> 3S battery */ - if (sku_id == 4 || sku_id == 5 || sku_id == 6) - return BATTERY_CELL_TYPE_3S; - - return BATTERY_CELL_TYPE_UNKNOWN; -} - __override int board_get_default_battery_type(void) { /* @@ -571,25 +554,8 @@ static void board_update_sensor_config_from_sku(void) gpio_enable_interrupt(GPIO_ACCEL_GYRO_INT_L); } } - -/* Read SKU ID from GPIO and initialize variables for board variants */ -static void sku_init(void) -{ - uint8_t val = 0; - - if (gpio_get_level(GPIO_SKU_ID0)) - val |= 0x01; - if (gpio_get_level(GPIO_SKU_ID1)) - val |= 0x02; - if (gpio_get_level(GPIO_SKU_ID2)) - val |= 0x04; - - sku_id = val; - CPRINTS("SKU: %u", sku_id); - - board_update_sensor_config_from_sku(); -} -DECLARE_HOOK(HOOK_INIT, sku_init, HOOK_PRIO_INIT_I2C + 1); +DECLARE_HOOK(HOOK_INIT, board_update_sensor_config_from_sku, + HOOK_PRIO_INIT_I2C + 2); /* Initialize board. */ static void board_init(void) @@ -644,21 +610,6 @@ void board_hibernate(void) ppc_vbus_sink_enable(i, 1); } -__override uint16_t board_get_ps8xxx_product_id(int port) -{ - /* - * Lazor (SKU_ID: 0, 1, 2, 3) rev 3+ changes TCPC from PS8751 to - * PS8805. - * - * Limozeen (SKU_ID: 4, 5, 6) all-rev uses PS8805. - */ - if ((sku_id == 0 || sku_id == 1 || sku_id == 2 || sku_id == 3) && - system_get_board_version() < 3) - return PS8751_PRODUCT_ID; - - return PS8805_PRODUCT_ID; -} - void board_tcpc_init(void) { /* Only reset TCPC if not sysjump */ diff --git a/board/lazor/board.h b/board/lazor/board.h index d76bf6d689..af65f9e900 100644 --- a/board/lazor/board.h +++ b/board/lazor/board.h @@ -114,6 +114,8 @@ enum battery_type { BATTERY_TYPE_COUNT, }; +int board_is_clamshell(void); + /* Custom function to indicate if sourcing VBUS */ int board_is_sourcing_vbus(int port); /* Enable VBUS sink for a given port */ diff --git a/board/lazor/build.mk b/board/lazor/build.mk index d06a4457f0..b8b2cbaa0b 100644 --- a/board/lazor/build.mk +++ b/board/lazor/build.mk @@ -11,4 +11,4 @@ CHIP_FAMILY:=npcx7 CHIP_VARIANT:=npcx7m6fc BASEBOARD:=trogdor -board-y=battery.o board.o led.o switchcap.o +board-y=battery.o board.o led.o sku.o switchcap.o diff --git a/board/lazor/sku.c b/board/lazor/sku.c new file mode 100644 index 0000000000..a89698e8b6 --- /dev/null +++ b/board/lazor/sku.c @@ -0,0 +1,88 @@ +/* Copyright 2021 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. + */ + +#include "common.h" +#include "config.h" +#include "console.h" +#include "driver/ln9310.h" +#include "gpio.h" +#include "hooks.h" +#include "system.h" + +#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) + +static uint8_t sku_id; + +enum board_model { + LAZOR, + LIMOZEEN, + UNKNOWN, +}; + +static const char *const model_name[] = { + "LAZOR", + "LIMOZEEN", + "UNKNOWN", +}; + +static enum board_model get_model(void) +{ + if (sku_id == 0 || sku_id == 1 || sku_id == 2 || sku_id == 3) + return LAZOR; + if (sku_id == 4 || sku_id == 5 || sku_id == 6) + return LIMOZEEN; + return UNKNOWN; +} + +/* Read SKU ID from GPIO and initialize variables for board variants */ +static void sku_init(void) +{ + uint8_t val = 0; + + if (gpio_get_level(GPIO_SKU_ID0)) + val |= 0x01; + if (gpio_get_level(GPIO_SKU_ID1)) + val |= 0x02; + if (gpio_get_level(GPIO_SKU_ID2)) + val |= 0x04; + + sku_id = val; + CPRINTS("SKU: %u (%s)", sku_id, model_name[get_model()]); +} +DECLARE_HOOK(HOOK_INIT, sku_init, HOOK_PRIO_INIT_I2C + 1); + +enum battery_cell_type board_get_battery_cell_type(void) +{ + switch (get_model()) { + case LIMOZEEN: + return BATTERY_CELL_TYPE_3S; + default: + return BATTERY_CELL_TYPE_UNKNOWN; + } +} + +int board_is_clamshell(void) +{ + return get_model() == LIMOZEEN; +} + +/* TODO(b:183118990): enable PS8xxx driver for zephyr */ +#ifndef CONFIG_ZEPHYR +#include "driver/tcpm/ps8xxx.h" +__override uint16_t board_get_ps8xxx_product_id(int port) +{ + /* + * Lazor (SKU_ID: 0, 1, 2, 3) rev 3+ changes TCPC from PS8751 to + * PS8805. + * + * Limozeen (SKU_ID: 4, 5, 6) all-rev uses PS8805. + */ + if (get_model() == LAZOR && system_get_board_version() < 3) + return PS8751_PRODUCT_ID; + + return PS8805_PRODUCT_ID; +} +#endif |