blob: 8fd47a6a762fb9534e926b240d4b8323bdce4c69 [file] [log] [blame]
Aaron Durbinb0f81512016-07-25 21:31:41 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpigen.h>
Duncan Laurie718d1852018-12-10 11:29:36 -080017#if IS_ENABLED(CONFIG_GENERIC_GPIO_LIB)
18#include <gpio.h>
19#endif
Aaron Durbinb0f81512016-07-25 21:31:41 -050020#include "chromeos.h"
21
22void chromeos_acpi_gpio_generate(const struct cros_gpio *gpios, size_t num)
23{
24 size_t i;
Duncan Laurie718d1852018-12-10 11:29:36 -080025 int gpio_num;
Aaron Durbinb0f81512016-07-25 21:31:41 -050026
27 acpigen_write_scope("\\");
28 acpigen_write_name("OIPG");
29
30 acpigen_write_package(num);
31 for (i = 0; i < num; i++) {
32 acpigen_write_package(4);
33 acpigen_write_integer(gpios[i].type);
34 acpigen_write_integer(gpios[i].polarity);
Duncan Laurie718d1852018-12-10 11:29:36 -080035 gpio_num = gpios[i].gpio_num;
36#if IS_ENABLED(CONFIG_GENERIC_GPIO_LIB)
37 /* Get ACPI pin from GPIO library if available */
38 if (gpios[i].gpio_num != CROS_GPIO_VIRTUAL)
39 gpio_num = gpio_acpi_pin(gpio_num);
40#endif
41 acpigen_write_integer(gpio_num);
Aaron Durbinb0f81512016-07-25 21:31:41 -050042 acpigen_write_string(gpios[i].device);
43 acpigen_pop_len();
44 }
45 acpigen_pop_len();
46
47 acpigen_pop_len();
48}
49
50void chromeos_dsdt_generator(struct device *dev)
51{
52 mainboard_chromeos_acpi_generate();
53}