mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-01 00:49:43 +00:00
e761035b64
With the relatively new button API in U-Boot, it's now much easier to model the common usecase of mapping arbitrary actions to different buttons during boot - for example entering fastboot mode, setting some additional kernel cmdline arguments, or booting with a custom recovery ramdisk, to name a few. Historically, this functionality has been implemented in board code, making it fixed for a given U-Boot binary and requiring the code be duplicated and modified for every board. Implement a generic abstraction to run an arbitrary command during boot when a specific button is pressed. The button -> command mapping is configured via environment variables with the following format: button_cmd_N_name=<button label> button_cmd_N=<command to run> Where N is the mapping number starting from 0. For example: button_cmd_0_name=vol_down button_cmd_0=fastboot usb 0 This will cause the device to enter fastboot mode if volume down is held during boot. After we enter the cli loop the button commands are no longer valid, this allows the buttons to additionally be used for navigating a boot menu. Tested-by: Svyatoslav Ryhel <clamor95@gmail.com> # Tegra30 Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
86 lines
2 KiB
C
86 lines
2 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/*
|
|
* Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
|
|
*/
|
|
|
|
#ifndef __BUTTON_H
|
|
#define __BUTTON_H
|
|
|
|
struct udevice;
|
|
|
|
/**
|
|
* struct button_uc_plat - Platform data the uclass stores about each device
|
|
*
|
|
* @label: Button label
|
|
*/
|
|
struct button_uc_plat {
|
|
const char *label;
|
|
};
|
|
|
|
/**
|
|
* enum button_state_t - State used for button
|
|
* - BUTTON_OFF - Button is not pressed
|
|
* - BUTTON_ON - Button is pressed
|
|
* - BUTTON_COUNT - Number of button state
|
|
*/
|
|
enum button_state_t {
|
|
BUTTON_OFF = 0,
|
|
BUTTON_ON = 1,
|
|
BUTTON_COUNT,
|
|
};
|
|
|
|
struct button_ops {
|
|
/**
|
|
* get_state() - get the state of a button
|
|
*
|
|
* @dev: button device to change
|
|
* @return button state button_state_t, or -ve on error
|
|
*/
|
|
enum button_state_t (*get_state)(struct udevice *dev);
|
|
|
|
/**
|
|
* get_code() - get linux event code of a button
|
|
*
|
|
* @dev: button device to change
|
|
* @return button code, or -ENODATA on error
|
|
*/
|
|
int (*get_code)(struct udevice *dev);
|
|
};
|
|
|
|
#define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops)
|
|
|
|
/**
|
|
* button_get_by_label() - Find a button device by label
|
|
*
|
|
* @label: button label to look up
|
|
* @devp: Returns the associated device, if found
|
|
* Return: 0 if found, -ENODEV if not found, other -ve on error
|
|
*/
|
|
int button_get_by_label(const char *label, struct udevice **devp);
|
|
|
|
/**
|
|
* button_get_state() - get the state of a button
|
|
*
|
|
* @dev: button device to change
|
|
* Return: button state button_state_t, or -ve on error
|
|
*/
|
|
enum button_state_t button_get_state(struct udevice *dev);
|
|
|
|
/**
|
|
* button_get_code() - get linux event code of a button
|
|
*
|
|
* @dev: button device to change
|
|
* @return button code, or -ve on error
|
|
*/
|
|
int button_get_code(struct udevice *dev);
|
|
|
|
#if IS_ENABLED(CONFIG_BUTTON_CMD)
|
|
/* Process button command mappings specified in the environment,
|
|
* running the commands for buttons which are pressed
|
|
*/
|
|
void process_button_cmds(void);
|
|
#else
|
|
static inline void process_button_cmds(void) {}
|
|
#endif /* CONFIG_BUTTON_CMD */
|
|
|
|
#endif
|