-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2024-02-13-assorted-updates'
- Add the button command patch, update MAINTAINERS entry for a platform, fix a problem with the hash command, fix a problem on K3 platforms and revert a change on verdin-am62.
- Loading branch information
Showing
10 changed files
with
132 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* Copyright (c) 2023 Linaro Ltd. | ||
* Author: Caleb Connolly <caleb.connolly@linaro.org> | ||
*/ | ||
|
||
#include <button.h> | ||
#include <command.h> | ||
#include <env.h> | ||
#include <log.h> | ||
#include <vsprintf.h> | ||
|
||
/* Some sane limit "just in case" */ | ||
#define MAX_BTN_CMDS 32 | ||
|
||
struct button_cmd { | ||
bool pressed; | ||
const char *btn_name; | ||
const char *cmd; | ||
}; | ||
|
||
/* | ||
* Button commands are set via environment variables, e.g.: | ||
* button_cmd_N_name=Volume Up | ||
* button_cmd_N=fastboot usb 0 | ||
* | ||
* This function will retrieve the command for the given button N | ||
* and populate the cmd struct with the command string and pressed | ||
* state of the button. | ||
* | ||
* Returns 1 if a command was found, 0 otherwise. | ||
*/ | ||
static int get_button_cmd(int n, struct button_cmd *cmd) | ||
{ | ||
const char *cmd_str; | ||
struct udevice *btn; | ||
char buf[24]; | ||
|
||
snprintf(buf, sizeof(buf), "button_cmd_%d_name", n); | ||
cmd->btn_name = env_get(buf); | ||
if (!cmd->btn_name) | ||
return 0; | ||
|
||
button_get_by_label(cmd->btn_name, &btn); | ||
if (!btn) { | ||
log_err("No button labelled '%s'\n", cmd->btn_name); | ||
return 0; | ||
} | ||
|
||
cmd->pressed = button_get_state(btn) == BUTTON_ON; | ||
/* If the button isn't pressed then cmd->cmd will be unused so don't waste | ||
* cycles reading it | ||
*/ | ||
if (!cmd->pressed) | ||
return 1; | ||
|
||
snprintf(buf, sizeof(buf), "button_cmd_%d", n); | ||
cmd_str = env_get(buf); | ||
if (!cmd_str) { | ||
log_err("No command set for button '%s'\n", cmd->btn_name); | ||
return 0; | ||
} | ||
|
||
cmd->cmd = cmd_str; | ||
|
||
return 1; | ||
} | ||
|
||
void process_button_cmds(void) | ||
{ | ||
struct button_cmd cmd = {0}; | ||
int i = 0; | ||
|
||
while (get_button_cmd(i++, &cmd) && i < MAX_BTN_CMDS) { | ||
if (!cmd.pressed) | ||
continue; | ||
|
||
log_info("BTN '%s'> %s\n", cmd.btn_name, cmd.cmd); | ||
run_command(cmd.cmd, CMD_FLAG_ENV); | ||
/* Don't run commands for multiple buttons */ | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters