diff options
-rw-r--r-- | common/acpi.c | 55 | ||||
-rw-r--r-- | include/ec_commands.h | 9 |
2 files changed, 64 insertions, 0 deletions
diff --git a/common/acpi.c b/common/acpi.c index e21eb93b97..5f3ee04fb4 100644 --- a/common/acpi.c +++ b/common/acpi.c @@ -8,6 +8,7 @@ #include "common.h" #include "console.h" #include "dptf.h" +#include "gpio.h" #include "hooks.h" #include "host_command.h" #include "lpc.h" @@ -15,6 +16,7 @@ #include "tablet_mode.h" #include "pwm.h" #include "timer.h" +#include "usb_charge.h" #include "util.h" /* Console output macros */ @@ -36,6 +38,10 @@ static int __bss_slow dptf_temp_sensor_id; /* last sensor ID written */ static int __bss_slow dptf_temp_threshold; /* last threshold written */ #endif +#ifdef CONFIG_USB_PORT_POWER_DUMB +extern const int usb_port_enable[USB_PORT_COUNT]; +#endif + /* * Keep a read cache of four bytes when burst mode is enabled, which is the * size of the largest non-string memmap data type. @@ -202,6 +208,26 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr) result = val >> (8 * off); break; } + +#ifdef CONFIG_USB_PORT_POWER_DUMB + case EC_ACPI_MEM_USB_PORT_POWER: { + int i; + const int port_count = MIN(8, USB_PORT_COUNT); + + /* + * Convert each USB port power GPIO signal to a bit + * field with max size 8 bits. USB port ID (index) 0 is + * the least significant bit. + */ + result = 0; + for (i = 0; i < port_count; ++i) { + if (gpio_get_level(usb_port_enable[i]) != 0) + result |= 1 << i; + } + break; + } +#endif + default: result = acpi_read(acpi_addr); break; @@ -266,6 +292,35 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr) } break; #endif + +#ifdef CONFIG_USB_PORT_POWER_DUMB + case EC_ACPI_MEM_USB_PORT_POWER: { + int i; + int mode_field = data; + const int port_count = MIN(8, USB_PORT_COUNT); + + /* + * Read the port power bit field (with max size 8 bits) + * and set the charge mode of each USB port accordingly. + * USB port ID 0 is the least significant bit. + */ + for (i = 0; i < port_count; ++i) { + int mode = USB_CHARGE_MODE_DISABLED; + + if (mode_field & 1) + mode = USB_CHARGE_MODE_ENABLED; + + if (usb_charge_set_mode(i, mode)) { + CPRINTS("ERROR: could not set charge " + "mode of USB port p%d to %d", + i, mode); + } + mode_field >>= 1; + } + break; + } +#endif + default: CPRINTS("ACPI write 0x%02x = 0x%02x (ignored)", acpi_addr, data); diff --git a/include/ec_commands.h b/include/ec_commands.h index 022a3c82df..ff076e66f0 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -353,6 +353,15 @@ #define EC_ACPI_MEM_BATTERY_INDEX 0x12 /* + * USB Port Power. Each bit indicates whether the corresponding USB ports' power + * is enabled (1) or disabled (0). + * bit 0 USB port ID 0 + * ... + * bit 7 USB port ID 7 + */ +#define EC_ACPI_MEM_USB_PORT_POWER 0x13 + +/* * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. */ |