local_gpio: simplify yaml description

Instead of:
    local_gpio:
      - power:
          chip: gpiochip0
          line: 7
          active_low: true
      - fastboot_key:
          chip: gpiochip0
          line: 8
          active_low: true
      - power_key:
          chip: gpiochip0
          line: 14
          active_low: true
      - usb_disconnect:
          chip: gpiochip1
          line: 4

Accept the following:
    local_gpio:
      power:
        chip: gpiochip0
        line: 7
        active_low: true
      fastboot_key:
        chip: gpiochip0
        line: 8
        active_low: true
      power_key:
        chip: gpiochip0
        line: 14
        active_low: true
      usb_disconnect:
        chip: gpiochip1
        line: 4

It's simpler and clearer.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
This commit is contained in:
Neil Armstrong
2023-11-02 17:15:35 +01:00
parent 494b04878a
commit e08d14a0df
2 changed files with 18 additions and 22 deletions

30
README
View File

@@ -66,21 +66,21 @@ devices:
console: /dev/serial/by-id/usb-1234-if00-port0
name: GPIO controller board
local_gpio:
- power:
chip: gpiochip0
line: 7
active_low: true
- fastboot_key:
chip: gpiochip0
line: 8
active_low: true
- power_key:
chip: gpiochip0
line: 14
active_low: true
- usb_disconnect:
chip: gpiochip1
line: 4
power:
chip: gpiochip0
line: 7
active_low: true
fastboot_key:
chip: gpiochip0
line: 8
active_low: true
power_key:
chip: gpiochip0
line: 14
active_low: true
usb_disconnect:
chip: gpiochip1
line: 4
fastboot: cacafada
fastboot_set_active: true
fastboot_key_timeout: 2

View File

@@ -54,16 +54,14 @@ void *local_gpio_parse_options(struct device_parser *dp)
char value[TOKEN_LENGTH];
char key[TOKEN_LENGTH];
device_parser_expect(dp, YAML_SEQUENCE_START_EVENT, NULL, 0);
device_parser_expect(dp, YAML_MAPPING_START_EVENT, NULL, 0);
options = calloc(1, sizeof(*options));
/* Loop over sub-properties */
while (device_parser_accept(dp, YAML_MAPPING_START_EVENT, NULL, 0)) {
while (device_parser_accept(dp, YAML_SCALAR_EVENT, key, TOKEN_LENGTH)) {
int gpio_id;
device_parser_accept(dp, YAML_SCALAR_EVENT, key, TOKEN_LENGTH);
if (!strcmp(key, "power")) {
gpio_id = GPIO_POWER;
} else if (!strcmp(key, "fastboot_key")) {
@@ -98,11 +96,9 @@ void *local_gpio_parse_options(struct device_parser *dp)
device_parser_expect(dp, YAML_MAPPING_END_EVENT, NULL, 0);
options->gpios[gpio_id].present = true;
device_parser_expect(dp, YAML_MAPPING_END_EVENT, NULL, 0);
}
device_parser_expect(dp, YAML_SEQUENCE_END_EVENT, NULL, 0);
device_parser_expect(dp, YAML_MAPPING_END_EVENT, NULL, 0);
return options;
}