[cleo][buttons] Add support for MIC_MUTE and VOL+ Test: hid uapp read in Cleo. Change-Id: I23dafcdb784459f580ca1b51175173203ed6ab8f
diff --git a/system/dev/board/mt8167s_ref/mt8167-buttons.cpp b/system/dev/board/mt8167s_ref/mt8167-buttons.cpp index 68f7351..058c6f7 100644 --- a/system/dev/board/mt8167s_ref/mt8167-buttons.cpp +++ b/system/dev/board/mt8167s_ref/mt8167-buttons.cpp
@@ -16,7 +16,9 @@ namespace board_mt8167 { zx_status_t Mt8167::ButtonsInit() { - constexpr pbus_gpio_t mt8167_buttons_gpios[] = { + + // MT8167S_REF + constexpr pbus_gpio_t mt8167s_ref_pbus_gpios[] = { { // KPROW0. .gpio = 40, @@ -35,41 +37,84 @@ }, }; // clang-format off - static constexpr buttons_button_config_t buttons[] = { + static constexpr buttons_button_config_t mt8167s_ref_buttons[] = { {BUTTONS_TYPE_MATRIX, BUTTONS_ID_VOLUME_UP, 0, 2, 0}, {BUTTONS_TYPE_MATRIX, BUTTONS_ID_KEY_A, 1, 2, 0}, {BUTTONS_TYPE_MATRIX, BUTTONS_ID_KEY_M, 0, 3, 0}, {BUTTONS_TYPE_MATRIX, BUTTONS_ID_PLAY_PAUSE, 1, 3, 0}, }; - static constexpr buttons_gpio_config_t gpios[] = { + static constexpr buttons_gpio_config_t mt8167s_ref_gpios[] = { {BUTTONS_GPIO_TYPE_INTERRUPT, BUTTONS_GPIO_FLAG_INVERTED, {GPIO_PULL_UP}}, {BUTTONS_GPIO_TYPE_INTERRUPT, BUTTONS_GPIO_FLAG_INVERTED, {GPIO_PULL_UP}}, {BUTTONS_GPIO_TYPE_MATRIX_OUTPUT, BUTTONS_GPIO_FLAG_INVERTED, {0} }, {BUTTONS_GPIO_TYPE_MATRIX_OUTPUT, BUTTONS_GPIO_FLAG_INVERTED, {0} }, }; // clang-format on - static constexpr pbus_metadata_t available_buttons_metadata[] = { + static constexpr pbus_metadata_t mt8167s_ref_metadata[] = { { .type = DEVICE_METADATA_BUTTONS_BUTTONS, - .data_buffer = &buttons, - .data_size = sizeof(buttons), + .data_buffer = &mt8167s_ref_buttons, + .data_size = sizeof(mt8167s_ref_buttons), }, { .type = DEVICE_METADATA_BUTTONS_GPIOS, - .data_buffer = &gpios, - .data_size = sizeof(gpios), - }}; - pbus_dev_t mt8167_buttons_dev = {}; - mt8167_buttons_dev.name = "mt8167-buttons"; - mt8167_buttons_dev.vid = PDEV_VID_GENERIC; - mt8167_buttons_dev.pid = PDEV_PID_GENERIC; - mt8167_buttons_dev.did = PDEV_DID_HID_BUTTONS; - mt8167_buttons_dev.gpio_list = mt8167_buttons_gpios; - mt8167_buttons_dev.gpio_count = countof(mt8167_buttons_gpios); - mt8167_buttons_dev.metadata_list = available_buttons_metadata; - mt8167_buttons_dev.metadata_count = countof(available_buttons_metadata); + .data_buffer = &mt8167s_ref_gpios, + .data_size = sizeof(mt8167s_ref_gpios), + } + }; - zx_status_t status = pbus_.DeviceAdd(&mt8167_buttons_dev); + // Cleo + constexpr pbus_gpio_t cleo_pbus_gpios[] = { + { + // VOL+. TODO(andresoportus) plumb VOL- through PMIC. + .gpio = 42, + }, + { + // MUTE_MIC. + .gpio = 23, + }, + }; + static constexpr buttons_button_config_t cleo_buttons[] = { + {BUTTONS_TYPE_DIRECT, BUTTONS_ID_VOLUME_UP, 0, 0, 0}, + {BUTTONS_TYPE_DIRECT, BUTTONS_ID_MIC_MUTE, 1, 0, 0}, + }; + static constexpr buttons_gpio_config_t cleo_gpios[] = { + {BUTTONS_GPIO_TYPE_INTERRUPT, BUTTONS_GPIO_FLAG_INVERTED, {GPIO_PULL_UP}}, + {BUTTONS_GPIO_TYPE_INTERRUPT, BUTTONS_GPIO_FLAG_INVERTED, {GPIO_NO_PULL}}, + }; + static constexpr pbus_metadata_t cleo_metadata[] = { + { + .type = DEVICE_METADATA_BUTTONS_BUTTONS, + .data_buffer = &cleo_buttons, + .data_size = sizeof(cleo_buttons), + }, + { + .type = DEVICE_METADATA_BUTTONS_GPIOS, + .data_buffer = &cleo_gpios, + .data_size = sizeof(cleo_gpios), + } + }; + + pbus_dev_t dev = {}; + dev.name = "mt8167-buttons"; + dev.vid = PDEV_VID_GENERIC; + dev.pid = PDEV_PID_GENERIC; + dev.did = PDEV_DID_HID_BUTTONS; + if (board_info_.pid == PDEV_PID_MEDIATEK_8167S_REF) { + dev.gpio_list = mt8167s_ref_pbus_gpios; + dev.gpio_count = countof(mt8167s_ref_pbus_gpios); + dev.metadata_list = mt8167s_ref_metadata; + dev.metadata_count = countof(mt8167s_ref_metadata); + } else if (board_info_.pid == PDEV_PID_CLEO) { + dev.gpio_list = cleo_pbus_gpios; + dev.gpio_count = countof(cleo_pbus_gpios); + dev.metadata_list = cleo_metadata; + dev.metadata_count = countof(cleo_metadata); + } else { + return ZX_ERR_NOT_SUPPORTED; + } + + zx_status_t status = pbus_.DeviceAdd(&dev); if (status != ZX_OK) { zxlogf(ERROR, "%s: pbus_.DeviceAdd failed %d\n", __FUNCTION__, status); return status;