diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2019-08-12 08:52:37 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-12 05:39:14 +0000 |
commit | e4440d52945fef7e5f3c98911f50363e65fc488e (patch) | |
tree | 73cffd4360d9bdccd72cee70770f29075301cd1f /board/hammer | |
parent | fb0eb4d1b932ba469f7385e42cf43f5a11f09c85 (diff) | |
download | chrome-ec-e4440d52945fef7e5f3c98911f50363e65fc488e.tar.gz |
hammer: Refactor config options to support more variants
board.h is already quite difficult to read, and will become worse
as we add more and more derivatives, let's refactor most of the
variations into variants.h.
BRANCH=none
BUG=b:138968914
TEST=make buildall -j, see that there is no size change before
and after the change.
Change-Id: Ideb381d8d04c65c3e76eb3ab9353e1ce5cdee954
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1746352
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
Reviewed-by: Yilun Lin <yllin@chromium.org>
Diffstat (limited to 'board/hammer')
-rw-r--r-- | board/hammer/board.c | 15 | ||||
-rw-r--r-- | board/hammer/board.h | 72 | ||||
-rw-r--r-- | board/hammer/ec.tasklist | 2 | ||||
-rw-r--r-- | board/hammer/gpio.inc | 8 | ||||
-rw-r--r-- | board/hammer/variants.h | 80 |
5 files changed, 108 insertions, 69 deletions
diff --git a/board/hammer/board.c b/board/hammer/board.c index 6b7a4029cf..fe50321fa9 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -72,7 +72,7 @@ BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT); */ #ifdef SECTION_IS_RW -#ifdef BOARD_WHISKERS +#ifdef HAS_SPI_TOUCHPAD /* SPI devices */ const struct spi_device_t spi_devices[] = { [SPI_ST_TP_DEVICE_ID] = { CONFIG_SPI_TOUCHPAD_PORT, 2, GPIO_SPI1_NSS }, @@ -83,7 +83,7 @@ USB_SPI_CONFIG(usb_spi, USB_IFACE_I2C_SPI, USB_EP_I2C_SPI); /* SPI interface is always enabled, no need to do anything. */ void usb_spi_board_enable(struct usb_spi_config const *config) {} void usb_spi_board_disable(struct usb_spi_config const *config) {} -#endif /* !BOARD_WHISKERS */ +#endif /* !HAS_SPI_TOUCHPAD */ /* I2C ports */ const struct i2c_port_t i2c_ports[] = { @@ -193,8 +193,11 @@ static void board_init(void) usart_init(&ec_ec_usart); #endif /* BOARD_WAND */ -#ifdef BOARD_WHISKERS +#ifdef CONFIG_LED_DRIVER_LM3630A lm3630a_poweron(); +#endif + +#ifdef HAS_SPI_TOUCHPAD spi_enable(CONFIG_SPI_TOUCHPAD_PORT, 0); /* Disable SPI passthrough when the system is locked */ @@ -215,7 +218,7 @@ static void board_init(void) /* Enable SPI for touchpad */ gpio_config_module(MODULE_SPI_MASTER, 1); spi_enable(CONFIG_SPI_TOUCHPAD_PORT, 1); -#endif /* BOARD_WHISKERS */ +#endif /* HAS_SPI_TOUCHPAD */ #endif /* SECTION_IS_RW */ } /* This needs to happen before PWM is initialized. */ @@ -243,7 +246,7 @@ int board_has_keyboard_backlight(void) /* Reset the touchpad, mainly used to recover it from malfunction. */ void board_touchpad_reset(void) { -#ifdef BOARD_WHISKERS +#ifdef HAS_EN_PP3300_TP_ACTIVE_HIGH gpio_set_level(GPIO_EN_PP3300_TP, 0); msleep(100); gpio_set_level(GPIO_EN_PP3300_TP, 1); @@ -256,7 +259,7 @@ void board_touchpad_reset(void) #endif } -#if defined(BOARD_WHISKERS) && defined(SECTION_IS_RW) +#ifdef CONFIG_KEYBOARD_TABLET_MODE_SWITCH static void board_tablet_mode_change(void) { /* diff --git a/board/hammer/board.h b/board/hammer/board.h index 812ee6e6c3..a64167adc4 100644 --- a/board/hammer/board.h +++ b/board/hammer/board.h @@ -8,6 +8,8 @@ #ifndef __CROS_EC_BOARD_H #define __CROS_EC_BOARD_H +#include "variants.h" + /* TODO: Remove CONFIG_SYSTEM_UNLOCKED prior to building MP FW. */ #define CONFIG_SYSTEM_UNLOCKED /* TODO(b:63378217): Define FLASH_PSTATE_LOCKED prior to building MP FW. */ @@ -85,17 +87,6 @@ /* USB Configuration */ #define CONFIG_USB -#ifdef BOARD_HAMMER -#define CONFIG_USB_PID 0x5022 -#elif defined(BOARD_STAFF) -#define CONFIG_USB_PID 0x502b -#elif defined(BOARD_WAND) -#define CONFIG_USB_PID 0x502d -#elif defined(BOARD_WHISKERS) -#define CONFIG_USB_PID 0x5030 -#else -#error "Invalid board" -#endif #define CONFIG_STREAM_USB #define CONFIG_USB_UPDATE @@ -117,11 +108,6 @@ /* Replaced at runtime (board_read_serial) by chip unique-id-based number. */ #define DEFAULT_SERIALNO "" -#if defined(BOARD_WHISKERS) && defined(SECTION_IS_RW) -/* Enable to send heatmap to AP */ -#define CONFIG_USB_ISOCHRONOUS -#endif /* !(BOARD_WHISKERS && SECTION_IS_RW) */ - /* USB interface indexes (use define rather than enum to expand them) */ #ifdef SECTION_IS_RW #define USB_IFACE_HID_KEYBOARD 0 @@ -129,12 +115,12 @@ #define USB_IFACE_HID_TOUCHPAD 2 /* Can be either I2C or SPI passthrough, depending on the board. */ #define USB_IFACE_I2C_SPI 3 -#if defined(BOARD_WHISKERS) && defined(CONFIG_USB_ISOCHRONOUS) +#if defined(CONFIG_USB_ISOCHRONOUS) #define USB_IFACE_ST_TOUCHPAD 4 #define USB_IFACE_COUNT 5 -#else /* !(BOARD_WHISKERS && CONFIG_USB_ISOCHRONOUS) */ +#else /* !CONFIG_USB_ISOCHRONOUS */ #define USB_IFACE_COUNT 4 -#endif /* BOARD_WHISKERS && CONFIG_USB_ISOCHRONOUS */ +#endif /* CONFIG_USB_ISOCHRONOUS */ #else /* !SECTION_IS_RW */ #define USB_IFACE_UPDATE 0 #define USB_IFACE_COUNT 1 @@ -148,13 +134,13 @@ #define USB_EP_HID_TOUCHPAD 3 /* Can be either I2C or SPI passthrough, depending on the board. */ #define USB_EP_I2C_SPI 4 -#if defined(BOARD_WHISKERS) && defined(CONFIG_USB_ISOCHRONOUS) +#if defined(CONFIG_USB_ISOCHRONOUS) #define USB_EP_ST_TOUCHPAD 5 #define USB_EP_ST_TOUCHPAD_INT 6 #define USB_EP_COUNT 7 -#else /* !(BOARD_WHISKERS && CONFIG_USB_ISOCHRONOUS) */ +#else /* !CONFIG_USB_ISOCHRONOUS */ #define USB_EP_COUNT 5 -#endif /* BOARD_WHISKERS && CONFIG_USB_ISOCHRONOUS */ +#endif /* CONFIG_USB_ISOCHRONOUS */ #else /* !SECTION_IS_RW */ #define USB_EP_COUNT 2 #endif /* SECTION_IS_RW */ @@ -203,39 +189,9 @@ /* Include touchpad FW hashes in image */ #define CONFIG_TOUCHPAD_HASH_FW -/* Touchpad firmware size and dimension difference */ -#if defined(BOARD_HAMMER) || defined(BOARD_WAND) -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3207 -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1783 -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 511 -#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1018 /* tenth of mm */ -#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 566 /* tenth of mm */ -#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (48*1024) -#elif defined(BOARD_STAFF) -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3206 -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1832 -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 511 -#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1017 /* tenth of mm */ -#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 581 /* tenth of mm */ -#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (56*1024) -#elif defined(BOARD_WHISKERS) -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 2160 -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1573 -#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 255 -#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1030 /* tenth of mm */ -#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 750 /* tenth of mm */ -#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (CONFIG_UPDATE_PDU_SIZE + 128*1024) -#else -#error "No touchpad information for board." -#endif - #define CONFIG_KEYBOARD_DEBUG #undef CONFIG_KEYBOARD_BOOT_KEYS #undef CONFIG_KEYBOARD_RUNTIME_KEYS -#if defined(BOARD_HAMMER) || defined(BOARD_WAND) || defined(BOARD_WHISKERS) -#define CONFIG_KEYBOARD_BOARD_CONFIG -#define CONFIG_KEYBOARD_ASSISTANT_KEY -#endif /* Keyboard output port list */ #define KB_OUT_PORT_LIST GPIO_A, GPIO_B, GPIO_C, GPIO_F @@ -248,12 +204,13 @@ /* Enable PWM */ #define CONFIG_PWM -#ifdef BOARD_WHISKERS -#define CONFIG_LED_DRIVER_LM3630A +#ifdef CONFIG_HALL_SENSOR #define CONFIG_TABLET_MODE -#define CONFIG_HALL_SENSOR #define HALL_SENSOR_GPIO_L GPIO_TABLET_MODE_L #define CONFIG_KEYBOARD_TABLET_MODE_SWITCH +#endif + +#ifdef HAS_SPI_TOUCHPAD /* Enable control of SPI over USB */ #define CONFIG_USB_SPI #define CONFIG_SPI_MASTER @@ -265,8 +222,7 @@ #define CONFIG_CMD_SPI_XFER #define CONFIG_TOUCHPAD #define CONFIG_TOUCHPAD_ST - -#else /* !BOARD_WHISKERS */ +#elif defined(HAS_I2C_TOUCHPAD) /* HAS_SPI_TOUCHPAD */ /* Enable control of I2C over USB */ #define CONFIG_USB_I2C #define USB_IFACE_I2C USB_IFACE_I2C_SPI @@ -276,7 +232,7 @@ #define CONFIG_TOUCHPAD_ELAN #define CONFIG_TOUCHPAD_I2C_PORT I2C_PORT_MASTER #define CONFIG_TOUCHPAD_I2C_ADDR_FLAGS 0x15 -#endif /* BOARD_WHISKERS */ +#endif /* HAS_I2C_TOUCHPAD */ #define CONFIG_CURVE25519 diff --git a/board/hammer/ec.tasklist b/board/hammer/ec.tasklist index 8fd825b94f..d3a2e17f07 100644 --- a/board/hammer/ec.tasklist +++ b/board/hammer/ec.tasklist @@ -15,7 +15,7 @@ TASK_ALWAYS (CONSOLE, console_task, NULL, 1024) \ TASK_ALWAYS_RW(ECCOMM, ec_ec_comm_slave_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST_RW(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) -#elif defined(BOARD_WHISKERS) && defined(CONFIG_USB_ISOCHRONOUS) +#elif defined(CONFIG_USB_ISOCHRONOUS) #define CONFIG_TASK_LIST \ TASK_ALWAYS_RO(RWSIG, rwsig_task, NULL, 1280) \ TASK_ALWAYS (HOOKS, hook_task, NULL, 2048) \ diff --git a/board/hammer/gpio.inc b/board/hammer/gpio.inc index 34c0838612..806cb19f7f 100644 --- a/board/hammer/gpio.inc +++ b/board/hammer/gpio.inc @@ -10,9 +10,9 @@ #ifdef SECTION_IS_RW GPIO_INT(TOUCHPAD_INT, PIN(B, 8), GPIO_INT_FALLING, touchpad_interrupt) -#ifdef BOARD_WHISKERS +#ifdef CONFIG_HALL_SENSOR GPIO_INT(TABLET_MODE_L, PIN(B, 11), GPIO_PULL_UP | GPIO_INT_BOTH, hall_sensor_isr) -#endif /* BOARD_WHISKERS */ +#endif /* CONFIG_HALL_SENSOR */ #endif /* SECTION_IS_RW */ /* Keyboard inputs */ @@ -57,7 +57,7 @@ GPIO(KB_OUT12, PIN(C, 13), GPIO_KB_OUTPUT) GPIO(MASTER_I2C_SCL, PIN(B, 6), GPIO_INPUT) GPIO(MASTER_I2C_SDA, PIN(B, 7), GPIO_INPUT) /* TODO(crosbug.com/p/59083): Disable trackpad when appropriate */ -#ifdef BOARD_WHISKERS +#ifdef HAS_EN_PP3300_TP_ACTIVE_HIGH GPIO(EN_PP3300_TP, PIN(A, 14), GPIO_OUT_HIGH) #else GPIO(EN_PP3300_TP_ODL, PIN(A, 14), GPIO_OUT_LOW) @@ -93,7 +93,7 @@ ALTERNATE(PIN_MASK(A, 0x0004), 1, MODULE_USART, GPIO_ODR_HIGH) /* USART2: PA2 - ALTERNATE(PIN_MASK(B, 0x0c00), 1, MODULE_I2C, 0) /* I2C CHARGER: PB10/11 GPIO_ODR_HIGH */ #endif -#ifdef BOARD_WHISKERS +#ifdef HAS_SPI_TOUCHPAD ALTERNATE(PIN_MASK(B, 0x0038), 0, MODULE_SPI_MASTER, 0) /* SPI MASTER:PB3/4/5 */ #endif diff --git a/board/hammer/variants.h b/board/hammer/variants.h new file mode 100644 index 0000000000..e520a0b450 --- /dev/null +++ b/board/hammer/variants.h @@ -0,0 +1,80 @@ +/* Copyright 2019 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. + */ + +/* + * Hammer variants configuration, there should be no/little BOARD_ checks + * in the rest of the files. If this grows out of control, we can create + * variant_*.h files. + */ + +#ifndef __CROS_EC_VARIANTS_H +#define __CROS_EC_VARIANTS_H + +/* USB ID */ +#ifdef BOARD_HAMMER +#define CONFIG_USB_PID 0x5022 +#elif defined(BOARD_STAFF) +#define CONFIG_USB_PID 0x502b +#elif defined(BOARD_WAND) +#define CONFIG_USB_PID 0x502d +#elif defined(BOARD_WHISKERS) +#define CONFIG_USB_PID 0x5030 +#else +#error "Invalid board" +#endif + +#ifdef SECTION_IS_RW + +/* Touchpad interface, firmware size and physical dimension. */ +#if defined(BOARD_HAMMER) || defined(BOARD_WAND) +#define HAS_I2C_TOUCHPAD +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3207 +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1783 +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 511 +#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1018 /* tenth of mm */ +#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 566 /* tenth of mm */ +#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (48*1024) +#elif defined(BOARD_STAFF) +#define HAS_I2C_TOUCHPAD +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 3206 +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1832 +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 511 +#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1017 /* tenth of mm */ +#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 581 /* tenth of mm */ +#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (56*1024) +#elif defined(BOARD_WHISKERS) +#define HAS_SPI_TOUCHPAD +#define HAS_EN_PP3300_TP_ACTIVE_HIGH +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_X 2160 +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_Y 1573 +#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 255 +#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1030 /* tenth of mm */ +#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 750 /* tenth of mm */ +#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (CONFIG_UPDATE_PDU_SIZE + 128*1024) +/* Enable to send heatmap to AP */ +#define CONFIG_USB_ISOCHRONOUS +#else +#error "No touchpad information for board." +#endif + +/* Assistant key */ +#if defined(BOARD_HAMMER) || defined(BOARD_WAND) || defined(BOARD_WHISKERS) +#define CONFIG_KEYBOARD_BOARD_CONFIG +#define CONFIG_KEYBOARD_ASSISTANT_KEY +#endif + +/* Backlight driver */ +#ifdef BOARD_WHISKERS +#define CONFIG_LED_DRIVER_LM3630A +#endif + +/* Hall sensor for tablet mode detection */ +#ifdef BOARD_WHISKERS +#define CONFIG_HALL_SENSOR +#endif + +#endif /* SECTION_IS_RW */ + +#endif /* __CROS_EC_VARIANTS_H */ |