2020-03-04 15:10:45 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/* This file is part of the coreboot project. */
|
2016-05-09 03:15:25 +02:00
|
|
|
|
2020-04-23 21:51:42 +02:00
|
|
|
#include <assert.h>
|
2016-05-09 03:15:25 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <arch/acpi.h>
|
|
|
|
#include <arch/acpi_device.h>
|
|
|
|
#include <arch/acpigen.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/path.h>
|
2019-12-02 20:47:50 +01:00
|
|
|
#include <stdlib.h>
|
2019-12-13 12:16:06 +01:00
|
|
|
#include <crc_byte.h>
|
|
|
|
|
2019-03-06 01:53:33 +01:00
|
|
|
#if CONFIG(GENERIC_GPIO_LIB)
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
#include <gpio.h>
|
|
|
|
#endif
|
2016-05-09 03:15:25 +02:00
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
#define ACPI_DP_UUID "daffd814-6eba-4d8c-8a91-bc9bbf4aa301"
|
|
|
|
#define ACPI_DP_CHILD_UUID "dbb8e3e6-5886-4ba6-8795-1319f52a966b"
|
|
|
|
|
2016-05-10 00:38:36 +02:00
|
|
|
/* Write empty word value and return pointer to it */
|
|
|
|
static void *acpi_device_write_zero_len(void)
|
|
|
|
{
|
|
|
|
char *p = acpigen_get_current();
|
|
|
|
acpigen_emit_word(0);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in length value from start to current at specified location */
|
|
|
|
static void acpi_device_fill_from_len(char *ptr, char *start)
|
|
|
|
{
|
|
|
|
uint16_t len = acpigen_get_current() - start;
|
|
|
|
ptr[0] = len & 0xff;
|
|
|
|
ptr[1] = (len >> 8) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the length field with the value calculated from after
|
|
|
|
* the 16bit field to acpigen current as this length value does
|
|
|
|
* not include the length field itself.
|
|
|
|
*/
|
|
|
|
static void acpi_device_fill_len(void *ptr)
|
|
|
|
{
|
|
|
|
acpi_device_fill_from_len(ptr, ptr + sizeof(uint16_t));
|
|
|
|
}
|
|
|
|
|
2016-05-09 03:15:25 +02:00
|
|
|
/* Locate and return the ACPI name for this device */
|
2019-07-30 06:41:41 +02:00
|
|
|
const char *acpi_device_name(const struct device *dev)
|
2016-05-09 03:15:25 +02:00
|
|
|
{
|
2019-07-30 06:41:41 +02:00
|
|
|
const struct device *pdev = dev;
|
2018-05-07 23:28:53 +02:00
|
|
|
const char *name = NULL;
|
|
|
|
|
2016-05-09 03:15:25 +02:00
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Check for device specific handler */
|
|
|
|
if (dev->ops->acpi_name)
|
|
|
|
return dev->ops->acpi_name(dev);
|
|
|
|
|
2018-05-07 23:28:53 +02:00
|
|
|
/* Walk up the tree to find if any parent can identify this device */
|
|
|
|
while (pdev->bus) {
|
|
|
|
pdev = pdev->bus->dev;
|
|
|
|
if (!pdev)
|
|
|
|
break;
|
|
|
|
if (pdev->path.type == DEVICE_PATH_ROOT)
|
|
|
|
break;
|
|
|
|
if (pdev->ops && pdev->ops->acpi_name)
|
|
|
|
name = pdev->ops->acpi_name(dev);
|
|
|
|
if (name)
|
|
|
|
return name;
|
|
|
|
}
|
2016-05-09 03:15:25 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-20 08:20:01 +02:00
|
|
|
/* Locate and return the ACPI _HID (Hardware ID) for this device */
|
|
|
|
const char *acpi_device_hid(const struct device *dev)
|
|
|
|
{
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Check for device specific handler */
|
|
|
|
if (dev->ops->acpi_hid)
|
|
|
|
return dev->ops->acpi_hid(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't walk up the tree to find any parent that can identify this device, as
|
|
|
|
* PNP devices are hard to identify.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-13 12:16:06 +01:00
|
|
|
/*
|
|
|
|
* Generate unique ID based on the ACPI path.
|
|
|
|
* Collisions on the same _HID are possible but very unlikely.
|
|
|
|
*/
|
2020-04-25 06:27:29 +02:00
|
|
|
uint32_t acpi_device_uid(const struct device *dev)
|
2019-12-13 12:16:06 +01:00
|
|
|
{
|
|
|
|
const char *path = acpi_device_path(dev);
|
|
|
|
if (!path)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return CRC(path, strlen(path), crc32_byte);
|
|
|
|
}
|
|
|
|
|
2016-05-09 03:15:25 +02:00
|
|
|
/* Recursive function to find the root device and print a path from there */
|
2019-07-30 06:41:41 +02:00
|
|
|
static ssize_t acpi_device_path_fill(const struct device *dev, char *buf,
|
2018-05-07 23:28:53 +02:00
|
|
|
size_t buf_len, size_t cur)
|
2016-05-09 03:15:25 +02:00
|
|
|
{
|
|
|
|
const char *name = acpi_device_name(dev);
|
2018-05-07 23:28:53 +02:00
|
|
|
ssize_t next = 0;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return -1;
|
2016-05-09 03:15:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this name segment will fit, including the path segment
|
|
|
|
* separator and possible NUL terminator if this is the last segment.
|
|
|
|
*/
|
2018-05-07 23:28:53 +02:00
|
|
|
if (!dev || (cur + strlen(name) + 2) > buf_len)
|
2016-05-09 03:15:25 +02:00
|
|
|
return cur;
|
|
|
|
|
|
|
|
/* Walk up the tree to the root device */
|
|
|
|
if (dev->path.type != DEVICE_PATH_ROOT && dev->bus && dev->bus->dev)
|
|
|
|
next = acpi_device_path_fill(dev->bus->dev, buf, buf_len, cur);
|
2018-05-07 23:28:53 +02:00
|
|
|
if (next < 0)
|
|
|
|
return next;
|
2016-05-09 03:15:25 +02:00
|
|
|
|
|
|
|
/* Fill in the path from the root device */
|
|
|
|
next += snprintf(buf + next, buf_len - next, "%s%s",
|
2017-04-14 00:06:16 +02:00
|
|
|
(dev->path.type == DEVICE_PATH_ROOT
|
|
|
|
|| (strlen(name) == 0)) ?
|
|
|
|
"" : ".", name);
|
2016-05-09 03:15:25 +02:00
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Warning: just as with dev_path() this uses a static buffer
|
|
|
|
* so should not be called mulitple times in one statement
|
|
|
|
*/
|
2019-07-30 06:41:41 +02:00
|
|
|
const char *acpi_device_path(const struct device *dev)
|
2016-05-09 03:15:25 +02:00
|
|
|
{
|
|
|
|
static char buf[DEVICE_PATH_MAX] = {};
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (acpi_device_path_fill(dev, buf, sizeof(buf), 0) <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the path of the parent device as the ACPI Scope for this device */
|
2019-07-30 06:41:41 +02:00
|
|
|
const char *acpi_device_scope(const struct device *dev)
|
2016-05-09 03:15:25 +02:00
|
|
|
{
|
2016-06-30 23:37:37 +02:00
|
|
|
static char buf[DEVICE_PATH_MAX] = {};
|
|
|
|
|
2016-05-09 03:15:25 +02:00
|
|
|
if (!dev || !dev->bus || !dev->bus->dev)
|
|
|
|
return NULL;
|
|
|
|
|
2016-06-30 23:37:37 +02:00
|
|
|
if (acpi_device_path_fill(dev->bus->dev, buf, sizeof(buf), 0) <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return buf;
|
2016-05-09 03:15:25 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 21:29:25 +01:00
|
|
|
/* Concatenate the device path and provided name suffix */
|
2019-07-30 06:41:41 +02:00
|
|
|
const char *acpi_device_path_join(const struct device *dev, const char *name)
|
2016-05-09 03:15:25 +02:00
|
|
|
{
|
|
|
|
static char buf[DEVICE_PATH_MAX] = {};
|
2019-07-02 18:50:10 +02:00
|
|
|
ssize_t len;
|
2016-05-09 03:15:25 +02:00
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Build the path of this device */
|
|
|
|
len = acpi_device_path_fill(dev, buf, sizeof(buf), 0);
|
|
|
|
if (len <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Ensure there is room for the added name, separator, and NUL */
|
|
|
|
if ((len + strlen(name) + 2) > sizeof(buf))
|
|
|
|
return NULL;
|
|
|
|
snprintf(buf + len, sizeof(buf) - len, ".%s", name);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
2016-05-10 00:38:36 +02:00
|
|
|
|
2018-09-10 04:55:49 +02:00
|
|
|
int acpi_device_status(const struct device *dev)
|
|
|
|
{
|
|
|
|
if (!dev->enabled)
|
|
|
|
return ACPI_STATUS_DEVICE_ALL_OFF;
|
|
|
|
if (dev->hidden)
|
|
|
|
return ACPI_STATUS_DEVICE_HIDDEN_ON;
|
|
|
|
return ACPI_STATUS_DEVICE_ALL_ON;
|
|
|
|
}
|
|
|
|
|
2019-12-13 12:16:06 +01:00
|
|
|
|
|
|
|
/* Write the unique _UID based on ACPI device path. */
|
2020-04-25 06:27:29 +02:00
|
|
|
void acpi_device_write_uid(const struct device *dev)
|
2019-12-13 12:16:06 +01:00
|
|
|
{
|
|
|
|
acpigen_write_name_integer("_UID", acpi_device_uid(dev));
|
|
|
|
}
|
|
|
|
|
2016-05-10 00:38:36 +02:00
|
|
|
/* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */
|
|
|
|
void acpi_device_write_interrupt(const struct acpi_irq *irq)
|
|
|
|
{
|
|
|
|
void *desc_length;
|
|
|
|
uint8_t flags;
|
|
|
|
|
|
|
|
if (!irq || !irq->pin)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* This is supported by GpioInt() but not Interrupt() */
|
2017-02-21 22:16:30 +01:00
|
|
|
if (irq->polarity == ACPI_IRQ_ACTIVE_BOTH)
|
2016-05-10 00:38:36 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Byte 0: Descriptor Type */
|
|
|
|
acpigen_emit_byte(ACPI_DESCRIPTOR_INTERRUPT);
|
|
|
|
|
|
|
|
/* Byte 1-2: Length (filled in later) */
|
|
|
|
desc_length = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 3: Flags
|
|
|
|
* [7:5]: Reserved
|
|
|
|
* [4]: Wake (0=NO_WAKE 1=WAKE)
|
|
|
|
* [3]: Sharing (0=EXCLUSIVE 1=SHARED)
|
|
|
|
* [2]: Polarity (0=HIGH 1=LOW)
|
|
|
|
* [1]: Mode (0=LEVEL 1=EDGE)
|
|
|
|
* [0]: Resource (0=PRODUCER 1=CONSUMER)
|
|
|
|
*/
|
|
|
|
flags = 1 << 0; /* ResourceConsumer */
|
2017-02-21 22:16:30 +01:00
|
|
|
if (irq->mode == ACPI_IRQ_EDGE_TRIGGERED)
|
2016-05-10 00:38:36 +02:00
|
|
|
flags |= 1 << 1;
|
2017-02-21 22:16:30 +01:00
|
|
|
if (irq->polarity == ACPI_IRQ_ACTIVE_LOW)
|
2016-05-10 00:38:36 +02:00
|
|
|
flags |= 1 << 2;
|
2017-02-21 22:16:30 +01:00
|
|
|
if (irq->shared == ACPI_IRQ_SHARED)
|
2016-05-10 00:38:36 +02:00
|
|
|
flags |= 1 << 3;
|
2017-02-21 22:16:30 +01:00
|
|
|
if (irq->wake == ACPI_IRQ_WAKE)
|
2016-05-10 00:38:36 +02:00
|
|
|
flags |= 1 << 4;
|
|
|
|
acpigen_emit_byte(flags);
|
|
|
|
|
|
|
|
/* Byte 4: Interrupt Table Entry Count */
|
|
|
|
acpigen_emit_byte(1);
|
|
|
|
|
|
|
|
/* Byte 5-8: Interrupt Number */
|
|
|
|
acpigen_emit_dword(irq->pin);
|
|
|
|
|
|
|
|
/* Fill in Descriptor Length (account for len word) */
|
|
|
|
acpi_device_fill_len(desc_length);
|
|
|
|
}
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
|
|
|
|
/* ACPI 6.1 section 6.4.3.8.1 - GPIO Interrupt or I/O */
|
|
|
|
void acpi_device_write_gpio(const struct acpi_gpio *gpio)
|
|
|
|
{
|
|
|
|
void *start, *desc_length;
|
|
|
|
void *pin_table_offset, *vendor_data_offset, *resource_offset;
|
|
|
|
uint16_t flags = 0;
|
|
|
|
int pin;
|
|
|
|
|
|
|
|
if (!gpio || gpio->type > ACPI_GPIO_TYPE_IO)
|
|
|
|
return;
|
|
|
|
|
|
|
|
start = acpigen_get_current();
|
|
|
|
|
|
|
|
/* Byte 0: Descriptor Type */
|
|
|
|
acpigen_emit_byte(ACPI_DESCRIPTOR_GPIO);
|
|
|
|
|
|
|
|
/* Byte 1-2: Length (fill in later) */
|
|
|
|
desc_length = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 3: Revision ID */
|
|
|
|
acpigen_emit_byte(ACPI_GPIO_REVISION_ID);
|
|
|
|
|
|
|
|
/* Byte 4: GpioIo or GpioInt */
|
|
|
|
acpigen_emit_byte(gpio->type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 5-6: General Flags
|
|
|
|
* [15:1]: 0 => Reserved
|
|
|
|
* [0]: 1 => ResourceConsumer
|
|
|
|
*/
|
|
|
|
acpigen_emit_word(1 << 0);
|
|
|
|
|
|
|
|
switch (gpio->type) {
|
|
|
|
case ACPI_GPIO_TYPE_INTERRUPT:
|
|
|
|
/*
|
|
|
|
* Byte 7-8: GPIO Interrupt Flags
|
|
|
|
* [15:5]: 0 => Reserved
|
|
|
|
* [4]: Wake (0=NO_WAKE 1=WAKE)
|
|
|
|
* [3]: Sharing (0=EXCLUSIVE 1=SHARED)
|
|
|
|
* [2:1]: Polarity (0=HIGH 1=LOW 2=BOTH)
|
|
|
|
* [0]: Mode (0=LEVEL 1=EDGE)
|
|
|
|
*/
|
2017-02-21 22:16:30 +01:00
|
|
|
if (gpio->irq.mode == ACPI_IRQ_EDGE_TRIGGERED)
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
flags |= 1 << 0;
|
2017-02-21 22:16:30 +01:00
|
|
|
if (gpio->irq.shared == ACPI_IRQ_SHARED)
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
flags |= 1 << 3;
|
2017-02-21 22:16:30 +01:00
|
|
|
if (gpio->irq.wake == ACPI_IRQ_WAKE)
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
flags |= 1 << 4;
|
|
|
|
|
|
|
|
switch (gpio->irq.polarity) {
|
2017-02-21 22:16:30 +01:00
|
|
|
case ACPI_IRQ_ACTIVE_HIGH:
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
flags |= 0 << 1;
|
|
|
|
break;
|
2017-02-21 22:16:30 +01:00
|
|
|
case ACPI_IRQ_ACTIVE_LOW:
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
flags |= 1 << 1;
|
|
|
|
break;
|
2017-02-21 22:16:30 +01:00
|
|
|
case ACPI_IRQ_ACTIVE_BOTH:
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
flags |= 2 << 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_GPIO_TYPE_IO:
|
|
|
|
/*
|
|
|
|
* Byte 7-8: GPIO IO Flags
|
|
|
|
* [15:4]: 0 => Reserved
|
|
|
|
* [3]: Sharing (0=EXCLUSIVE 1=SHARED)
|
|
|
|
* [2]: 0 => Reserved
|
|
|
|
* [1:0]: IO Restriction
|
|
|
|
* 0 => IoRestrictionNone
|
|
|
|
* 1 => IoRestrictionInputOnly
|
|
|
|
* 2 => IoRestrictionOutputOnly
|
|
|
|
* 3 => IoRestrictionNoneAndPreserve
|
|
|
|
*/
|
|
|
|
flags |= gpio->io_restrict & 3;
|
|
|
|
if (gpio->io_shared)
|
|
|
|
flags |= 1 << 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
acpigen_emit_word(flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 9: Pin Configuration
|
|
|
|
* 0x01 => Default (no configuration applied)
|
|
|
|
* 0x02 => Pull-up
|
|
|
|
* 0x03 => Pull-down
|
|
|
|
* 0x04-0x7F => Reserved
|
|
|
|
* 0x80-0xff => Vendor defined
|
|
|
|
*/
|
|
|
|
acpigen_emit_byte(gpio->pull);
|
|
|
|
|
|
|
|
/* Byte 10-11: Output Drive Strength in 1/100 mA */
|
|
|
|
acpigen_emit_word(gpio->output_drive_strength);
|
|
|
|
|
|
|
|
/* Byte 12-13: Debounce Timeout in 1/100 ms */
|
|
|
|
acpigen_emit_word(gpio->interrupt_debounce_timeout);
|
|
|
|
|
|
|
|
/* Byte 14-15: Pin Table Offset, relative to start */
|
|
|
|
pin_table_offset = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 16: Reserved */
|
|
|
|
acpigen_emit_byte(0);
|
|
|
|
|
|
|
|
/* Byte 17-18: Resource Source Name Offset, relative to start */
|
|
|
|
resource_offset = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 19-20: Vendor Data Offset, relative to start */
|
|
|
|
vendor_data_offset = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 21-22: Vendor Data Length */
|
|
|
|
acpigen_emit_word(0);
|
|
|
|
|
|
|
|
/* Fill in Pin Table Offset */
|
|
|
|
acpi_device_fill_from_len(pin_table_offset, start);
|
|
|
|
|
|
|
|
/* Pin Table, one word for each pin */
|
2016-06-29 19:47:22 +02:00
|
|
|
for (pin = 0; pin < gpio->pin_count; pin++) {
|
|
|
|
uint16_t acpi_pin = gpio->pins[pin];
|
2019-03-06 01:53:33 +01:00
|
|
|
#if CONFIG(GENERIC_GPIO_LIB)
|
2016-06-29 19:47:22 +02:00
|
|
|
acpi_pin = gpio_acpi_pin(acpi_pin);
|
|
|
|
#endif
|
|
|
|
acpigen_emit_word(acpi_pin);
|
|
|
|
}
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
|
|
|
|
/* Fill in Resource Source Name Offset */
|
|
|
|
acpi_device_fill_from_len(resource_offset, start);
|
|
|
|
|
|
|
|
/* Resource Source Name String */
|
2019-03-06 01:53:33 +01:00
|
|
|
#if CONFIG(GENERIC_GPIO_LIB)
|
acpi_device: Add support for writing ACPI GPIO descriptors
Add definitions to describe GPIOs in generated ACPI objects and a
method to write a GpioIo() or GpioInt() descriptor to the SSDT.
ACPI GPIOs have many possible configuration options and a structure
is created to describe it accurately in ACPI terms. There are many
shared descriptor fields between GpioIo() and GpioInt() so the same
function can write both types.
GpioInt shares many properties with ACPI Interrupts and the same types
are re-used here where possible. One addition is that GpioInt can be
configured to trigger on both low and high edge transitions.
One descriptor can describe multiple GPIO pins (limited to 8 in this
implementation) that all share configuration and controller and are
used by the same device scope.
Accurately referring to the GPIO controller that this pin is connected
to requires the SoC/board to implement a function handler for
acpi_gpio_path(), or for the caller to provide this directly as a
string in the acpi_gpio->reference variable.
This will get used by device drivers to describe their resources in
the SSDT. Here is a sample for a Maxim 98357A I2S codec which has a
GPIO for power and channel selection called "sdmode".
chip.h:
struct drivers_generic_max98357a_config {
struct acpi_gpio sdmode_gpio;
};
max98357a.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_max98357a_config *config = dev->chip_info;
...
acpi_device_write_gpio(&config->sdmode_gpio);
...
}
devicetree.cb:
device pci 1f.3 on
chip drivers/generic/max98357a
register "sdmode_gpio" = "ACPI_GPIO_OUTPUT(GPP_C5)"
device generic 0 on end
end
end
SSDT.dsl:
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer, ,) { 53 }
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Change-Id: Ibf5bab9c4bf6f21252373fb013e78f872550b167
Reviewed-on: https://review.coreboot.org/14934
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 02:08:38 +02:00
|
|
|
acpigen_emit_string(gpio->resource ? : gpio_acpi_path(gpio->pins[0]));
|
|
|
|
#else
|
|
|
|
acpigen_emit_string(gpio->resource);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Fill in Vendor Data Offset */
|
|
|
|
acpi_device_fill_from_len(vendor_data_offset, start);
|
|
|
|
|
|
|
|
/* Fill in GPIO Descriptor Length (account for len word) */
|
|
|
|
acpi_device_fill_len(desc_length);
|
|
|
|
}
|
acpi_device: Add support for writing ACPI I2C descriptors
Add required definitions to describe an ACPI I2C bus and a method to
write the I2cSerialBus() descriptor to the SSDT.
This will be used by device drivers to describe their I2C resources to
the OS. The devicetree i2c device can supply the address and 7 or 10
bit mode as well as indicate the GPIO controller device, and the bus
speed can be fixed or configured by the driver.
chip.h:
struct drivers_i2c_generic_config {
enum i2c_speed bus_speed;
};
generic.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_i2c_generic_config *config = dev->chip_info;
struct acpi_i2c i2c = {
.address = dev->path->i2c.device,
.mode_10bit = dev->path.i2c.mode_10bit,
.speed = config->bus_speed ? : I2C_SPEED_FAST,
.resource = acpi_device_path(dev->bus->dev)
};
...
acpi_device_write_i2c(&i2c);
...
}
devicetree.cb:
device pci 15.0 on
chip drivers/i2c/generic
device i2c 10.0 on end
end
end
SSDT.dsl:
I2cSerialBus (0x10, ControllerInitiated, 400000, AddressingMode7Bit,
"\\_SB.PCI0.I2C0", 0, ResourceConsumer)
Change-Id: I598401ac81a92c72f19da0271af1e218580a6c49
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14935
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 05:10:47 +02:00
|
|
|
|
|
|
|
/* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */
|
|
|
|
void acpi_device_write_i2c(const struct acpi_i2c *i2c)
|
|
|
|
{
|
|
|
|
void *desc_length, *type_length;
|
|
|
|
|
|
|
|
/* Byte 0: Descriptor Type */
|
|
|
|
acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS);
|
|
|
|
|
|
|
|
/* Byte 1+2: Length (filled in later) */
|
|
|
|
desc_length = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 3: Revision ID */
|
2019-04-16 08:12:10 +02:00
|
|
|
acpigen_emit_byte(ACPI_I2C_SERIAL_BUS_REVISION_ID);
|
acpi_device: Add support for writing ACPI I2C descriptors
Add required definitions to describe an ACPI I2C bus and a method to
write the I2cSerialBus() descriptor to the SSDT.
This will be used by device drivers to describe their I2C resources to
the OS. The devicetree i2c device can supply the address and 7 or 10
bit mode as well as indicate the GPIO controller device, and the bus
speed can be fixed or configured by the driver.
chip.h:
struct drivers_i2c_generic_config {
enum i2c_speed bus_speed;
};
generic.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_i2c_generic_config *config = dev->chip_info;
struct acpi_i2c i2c = {
.address = dev->path->i2c.device,
.mode_10bit = dev->path.i2c.mode_10bit,
.speed = config->bus_speed ? : I2C_SPEED_FAST,
.resource = acpi_device_path(dev->bus->dev)
};
...
acpi_device_write_i2c(&i2c);
...
}
devicetree.cb:
device pci 15.0 on
chip drivers/i2c/generic
device i2c 10.0 on end
end
end
SSDT.dsl:
I2cSerialBus (0x10, ControllerInitiated, 400000, AddressingMode7Bit,
"\\_SB.PCI0.I2C0", 0, ResourceConsumer)
Change-Id: I598401ac81a92c72f19da0271af1e218580a6c49
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14935
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 05:10:47 +02:00
|
|
|
|
|
|
|
/* Byte 4: Resource Source Index is Reserved */
|
|
|
|
acpigen_emit_byte(0);
|
|
|
|
|
|
|
|
/* Byte 5: Serial Bus Type is I2C */
|
|
|
|
acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_I2C);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 6: Flags
|
|
|
|
* [7:2]: 0 => Reserved
|
|
|
|
* [1]: 1 => ResourceConsumer
|
|
|
|
* [0]: 0 => ControllerInitiated
|
|
|
|
*/
|
|
|
|
acpigen_emit_byte(1 << 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 7-8: Type Specific Flags
|
|
|
|
* [15:1]: 0 => Reserved
|
|
|
|
* [0]: 0 => 7bit, 1 => 10bit
|
|
|
|
*/
|
|
|
|
acpigen_emit_word(i2c->mode_10bit);
|
|
|
|
|
|
|
|
/* Byte 9: Type Specific Revision ID */
|
2019-04-16 08:12:10 +02:00
|
|
|
acpigen_emit_byte(ACPI_I2C_TYPE_SPECIFIC_REVISION_ID);
|
acpi_device: Add support for writing ACPI I2C descriptors
Add required definitions to describe an ACPI I2C bus and a method to
write the I2cSerialBus() descriptor to the SSDT.
This will be used by device drivers to describe their I2C resources to
the OS. The devicetree i2c device can supply the address and 7 or 10
bit mode as well as indicate the GPIO controller device, and the bus
speed can be fixed or configured by the driver.
chip.h:
struct drivers_i2c_generic_config {
enum i2c_speed bus_speed;
};
generic.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_i2c_generic_config *config = dev->chip_info;
struct acpi_i2c i2c = {
.address = dev->path->i2c.device,
.mode_10bit = dev->path.i2c.mode_10bit,
.speed = config->bus_speed ? : I2C_SPEED_FAST,
.resource = acpi_device_path(dev->bus->dev)
};
...
acpi_device_write_i2c(&i2c);
...
}
devicetree.cb:
device pci 15.0 on
chip drivers/i2c/generic
device i2c 10.0 on end
end
end
SSDT.dsl:
I2cSerialBus (0x10, ControllerInitiated, 400000, AddressingMode7Bit,
"\\_SB.PCI0.I2C0", 0, ResourceConsumer)
Change-Id: I598401ac81a92c72f19da0271af1e218580a6c49
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14935
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 05:10:47 +02:00
|
|
|
|
|
|
|
/* Byte 10-11: I2C Type Data Length */
|
|
|
|
type_length = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 12-15: I2C Bus Speed */
|
|
|
|
acpigen_emit_dword(i2c->speed);
|
|
|
|
|
|
|
|
/* Byte 16-17: I2C Slave Address */
|
|
|
|
acpigen_emit_word(i2c->address);
|
|
|
|
|
|
|
|
/* Fill in Type Data Length */
|
|
|
|
acpi_device_fill_len(type_length);
|
|
|
|
|
|
|
|
/* Byte 18+: ResourceSource */
|
|
|
|
acpigen_emit_string(i2c->resource);
|
|
|
|
|
|
|
|
/* Fill in I2C Descriptor Length */
|
|
|
|
acpi_device_fill_len(desc_length);
|
|
|
|
}
|
acpi_device: Add support for writing ACPI SPI descriptors
Add required definitions to describe an ACPI SPI bus and a method to
write the SpiSerialBus() descriptor to the SSDT.
This will be used by device drivers to describe their SPI resources to
the OS. SPI devices are not currently enumerated in the devicetree but
can be enumerated by device drivers directly.
generic.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct acpi_spi spi = {
.device_select = dev->path->generic.device.id,
.device_select_polarity = SPI_POLARITY_LOW,
.spi_wire_mode = SPI_4_WIRE_MODE,
.speed = 1000 * 1000; /* 1 mHz */
.data_bit_length = 8,
.clock_phase = SPI_CLOCK_PHASE_FIRST,
.clock_polarity = SPI_POLARITY_LOW,
.resource = acpi_device_path(dev->bus->dev)
};
...
acpi_device_write_spi(&spi);
...
}
devicetree.cb:
device pci 1e.2 on
chip drivers/spi/generic
device generic 0 on end
end
end
SSDT.dsl:
SpiSerialBus (0, PolarityLow, FourWireMode, 8, ControllerInitiated,
1000000, ClockPolarityLow, ClockPhaseFirst,
"\\_SB.PCI0.SPI0", 0, ResourceConsumer)
Change-Id: I0ef83dc111ac6c19d68872ab64e1e5e3a7756cae
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14936
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 16:26:34 +02:00
|
|
|
|
|
|
|
/* ACPI 6.1 section 6.4.3.8.2.2 - SpiSerialBus() */
|
|
|
|
void acpi_device_write_spi(const struct acpi_spi *spi)
|
|
|
|
{
|
|
|
|
void *desc_length, *type_length;
|
|
|
|
uint16_t flags = 0;
|
|
|
|
|
|
|
|
/* Byte 0: Descriptor Type */
|
|
|
|
acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS);
|
|
|
|
|
|
|
|
/* Byte 1+2: Length (filled in later) */
|
|
|
|
desc_length = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 3: Revision ID */
|
2019-04-16 08:12:10 +02:00
|
|
|
acpigen_emit_byte(ACPI_SPI_SERIAL_BUS_REVISION_ID);
|
acpi_device: Add support for writing ACPI SPI descriptors
Add required definitions to describe an ACPI SPI bus and a method to
write the SpiSerialBus() descriptor to the SSDT.
This will be used by device drivers to describe their SPI resources to
the OS. SPI devices are not currently enumerated in the devicetree but
can be enumerated by device drivers directly.
generic.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct acpi_spi spi = {
.device_select = dev->path->generic.device.id,
.device_select_polarity = SPI_POLARITY_LOW,
.spi_wire_mode = SPI_4_WIRE_MODE,
.speed = 1000 * 1000; /* 1 mHz */
.data_bit_length = 8,
.clock_phase = SPI_CLOCK_PHASE_FIRST,
.clock_polarity = SPI_POLARITY_LOW,
.resource = acpi_device_path(dev->bus->dev)
};
...
acpi_device_write_spi(&spi);
...
}
devicetree.cb:
device pci 1e.2 on
chip drivers/spi/generic
device generic 0 on end
end
end
SSDT.dsl:
SpiSerialBus (0, PolarityLow, FourWireMode, 8, ControllerInitiated,
1000000, ClockPolarityLow, ClockPhaseFirst,
"\\_SB.PCI0.SPI0", 0, ResourceConsumer)
Change-Id: I0ef83dc111ac6c19d68872ab64e1e5e3a7756cae
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14936
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 16:26:34 +02:00
|
|
|
|
|
|
|
/* Byte 4: Resource Source Index is Reserved */
|
|
|
|
acpigen_emit_byte(0);
|
|
|
|
|
|
|
|
/* Byte 5: Serial Bus Type is SPI */
|
|
|
|
acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_SPI);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 6: Flags
|
|
|
|
* [7:2]: 0 => Reserved
|
|
|
|
* [1]: 1 => ResourceConsumer
|
|
|
|
* [0]: 0 => ControllerInitiated
|
|
|
|
*/
|
|
|
|
acpigen_emit_byte(1 << 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Byte 7-8: Type Specific Flags
|
|
|
|
* [15:2]: 0 => Reserved
|
|
|
|
* [1]: 0 => ActiveLow, 1 => ActiveHigh
|
|
|
|
* [0]: 0 => FourWire, 1 => ThreeWire
|
|
|
|
*/
|
|
|
|
if (spi->wire_mode == SPI_3_WIRE_MODE)
|
|
|
|
flags |= 1 << 0;
|
|
|
|
if (spi->device_select_polarity == SPI_POLARITY_HIGH)
|
|
|
|
flags |= 1 << 1;
|
|
|
|
acpigen_emit_word(flags);
|
|
|
|
|
|
|
|
/* Byte 9: Type Specific Revision ID */
|
2019-04-16 08:12:10 +02:00
|
|
|
acpigen_emit_byte(ACPI_SPI_TYPE_SPECIFIC_REVISION_ID);
|
acpi_device: Add support for writing ACPI SPI descriptors
Add required definitions to describe an ACPI SPI bus and a method to
write the SpiSerialBus() descriptor to the SSDT.
This will be used by device drivers to describe their SPI resources to
the OS. SPI devices are not currently enumerated in the devicetree but
can be enumerated by device drivers directly.
generic.c:
void acpi_fill_ssdt_generator(struct device *dev) {
struct acpi_spi spi = {
.device_select = dev->path->generic.device.id,
.device_select_polarity = SPI_POLARITY_LOW,
.spi_wire_mode = SPI_4_WIRE_MODE,
.speed = 1000 * 1000; /* 1 mHz */
.data_bit_length = 8,
.clock_phase = SPI_CLOCK_PHASE_FIRST,
.clock_polarity = SPI_POLARITY_LOW,
.resource = acpi_device_path(dev->bus->dev)
};
...
acpi_device_write_spi(&spi);
...
}
devicetree.cb:
device pci 1e.2 on
chip drivers/spi/generic
device generic 0 on end
end
end
SSDT.dsl:
SpiSerialBus (0, PolarityLow, FourWireMode, 8, ControllerInitiated,
1000000, ClockPolarityLow, ClockPhaseFirst,
"\\_SB.PCI0.SPI0", 0, ResourceConsumer)
Change-Id: I0ef83dc111ac6c19d68872ab64e1e5e3a7756cae
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14936
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 16:26:34 +02:00
|
|
|
|
|
|
|
/* Byte 10-11: SPI Type Data Length */
|
|
|
|
type_length = acpi_device_write_zero_len();
|
|
|
|
|
|
|
|
/* Byte 12-15: Connection Speed */
|
|
|
|
acpigen_emit_dword(spi->speed);
|
|
|
|
|
|
|
|
/* Byte 16: Data Bit Length */
|
|
|
|
acpigen_emit_byte(spi->data_bit_length);
|
|
|
|
|
|
|
|
/* Byte 17: Clock Phase */
|
|
|
|
acpigen_emit_byte(spi->clock_phase);
|
|
|
|
|
|
|
|
/* Byte 18: Clock Polarity */
|
|
|
|
acpigen_emit_byte(spi->clock_polarity);
|
|
|
|
|
|
|
|
/* Byte 19-20: Device Selection */
|
|
|
|
acpigen_emit_word(spi->device_select);
|
|
|
|
|
|
|
|
/* Fill in Type Data Length */
|
|
|
|
acpi_device_fill_len(type_length);
|
|
|
|
|
|
|
|
/* Byte 21+: ResourceSource String */
|
|
|
|
acpigen_emit_string(spi->resource);
|
|
|
|
|
|
|
|
/* Fill in SPI Descriptor Length */
|
|
|
|
acpi_device_fill_len(desc_length);
|
|
|
|
}
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
|
2017-02-18 02:05:03 +01:00
|
|
|
/* PowerResource() with Enable and/or Reset control */
|
2018-04-26 22:52:30 +02:00
|
|
|
void acpi_device_add_power_res(const struct acpi_power_res_params *params)
|
2017-02-18 02:05:03 +01:00
|
|
|
{
|
2017-03-17 00:01:40 +01:00
|
|
|
static const char *power_res_dev_states[] = { "_PR0", "_PR3" };
|
2020-01-23 00:32:33 +01:00
|
|
|
unsigned int reset_gpio = params->reset_gpio ? params->reset_gpio->pins[0] : 0;
|
|
|
|
unsigned int enable_gpio = params->enable_gpio ? params->enable_gpio->pins[0] : 0;
|
|
|
|
unsigned int stop_gpio = params->stop_gpio ? params->stop_gpio->pins[0] : 0;
|
2017-02-18 02:05:03 +01:00
|
|
|
|
2017-08-29 02:20:49 +02:00
|
|
|
if (!reset_gpio && !enable_gpio && !stop_gpio)
|
2017-02-18 02:05:03 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* PowerResource (PRIC, 0, 0) */
|
|
|
|
acpigen_write_power_res("PRIC", 0, 0, power_res_dev_states,
|
|
|
|
ARRAY_SIZE(power_res_dev_states));
|
|
|
|
|
|
|
|
/* Method (_STA, 0, NotSerialized) { Return (0x1) } */
|
|
|
|
acpigen_write_STA(0x1);
|
|
|
|
|
|
|
|
/* Method (_ON, 0, Serialized) */
|
|
|
|
acpigen_write_method_serialized("_ON", 0);
|
|
|
|
if (reset_gpio)
|
2018-04-26 22:52:30 +02:00
|
|
|
acpigen_enable_tx_gpio(params->reset_gpio);
|
2017-02-18 02:05:03 +01:00
|
|
|
if (enable_gpio) {
|
2018-04-26 22:52:30 +02:00
|
|
|
acpigen_enable_tx_gpio(params->enable_gpio);
|
|
|
|
if (params->enable_delay_ms)
|
|
|
|
acpigen_write_sleep(params->enable_delay_ms);
|
2017-02-18 02:05:03 +01:00
|
|
|
}
|
|
|
|
if (reset_gpio) {
|
2018-04-26 22:52:30 +02:00
|
|
|
acpigen_disable_tx_gpio(params->reset_gpio);
|
|
|
|
if (params->reset_delay_ms)
|
|
|
|
acpigen_write_sleep(params->reset_delay_ms);
|
2017-02-18 02:05:03 +01:00
|
|
|
}
|
2017-08-29 02:20:49 +02:00
|
|
|
if (stop_gpio) {
|
2018-04-26 22:52:30 +02:00
|
|
|
acpigen_disable_tx_gpio(params->stop_gpio);
|
|
|
|
if (params->stop_delay_ms)
|
|
|
|
acpigen_write_sleep(params->stop_delay_ms);
|
2017-08-29 02:20:49 +02:00
|
|
|
}
|
2017-02-18 02:05:03 +01:00
|
|
|
acpigen_pop_len(); /* _ON method */
|
|
|
|
|
|
|
|
/* Method (_OFF, 0, Serialized) */
|
|
|
|
acpigen_write_method_serialized("_OFF", 0);
|
2018-04-26 22:52:30 +02:00
|
|
|
if (stop_gpio) {
|
|
|
|
acpigen_enable_tx_gpio(params->stop_gpio);
|
|
|
|
if (params->stop_off_delay_ms)
|
|
|
|
acpigen_write_sleep(params->stop_off_delay_ms);
|
|
|
|
}
|
|
|
|
if (reset_gpio) {
|
|
|
|
acpigen_enable_tx_gpio(params->reset_gpio);
|
|
|
|
if (params->reset_off_delay_ms)
|
|
|
|
acpigen_write_sleep(params->reset_off_delay_ms);
|
|
|
|
}
|
|
|
|
if (enable_gpio) {
|
|
|
|
acpigen_disable_tx_gpio(params->enable_gpio);
|
|
|
|
if (params->enable_off_delay_ms)
|
|
|
|
acpigen_write_sleep(params->enable_off_delay_ms);
|
|
|
|
}
|
2017-02-18 02:05:03 +01:00
|
|
|
acpigen_pop_len(); /* _OFF method */
|
|
|
|
|
|
|
|
acpigen_pop_len(); /* PowerResource PRIC */
|
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
static void acpi_dp_write_array(const struct acpi_dp *array);
|
|
|
|
static void acpi_dp_write_value(const struct acpi_dp *prop)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
|
|
|
switch (prop->type) {
|
|
|
|
case ACPI_DP_TYPE_INTEGER:
|
|
|
|
acpigen_write_integer(prop->integer);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_STRING:
|
2016-07-16 02:31:43 +02:00
|
|
|
case ACPI_DP_TYPE_CHILD:
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
acpigen_write_string(prop->string);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_REFERENCE:
|
|
|
|
acpigen_emit_namestring(prop->string);
|
|
|
|
break;
|
2016-07-03 04:56:06 +02:00
|
|
|
case ACPI_DP_TYPE_ARRAY:
|
|
|
|
acpi_dp_write_array(prop->array);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
/* Package (2) { "prop->name", VALUE } */
|
|
|
|
static void acpi_dp_write_property(const struct acpi_dp *prop)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
|
|
|
acpigen_write_package(2);
|
2016-07-03 04:56:06 +02:00
|
|
|
acpigen_write_string(prop->name);
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
acpi_dp_write_value(prop);
|
|
|
|
acpigen_pop_len();
|
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
/* Write array of Device Properties */
|
|
|
|
static void acpi_dp_write_array(const struct acpi_dp *array)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
2016-07-03 04:56:06 +02:00
|
|
|
const struct acpi_dp *dp;
|
|
|
|
char *pkg_count;
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
/* Package element count determined as it is populated */
|
|
|
|
pkg_count = acpigen_write_package(0);
|
|
|
|
|
2016-10-04 08:30:14 +02:00
|
|
|
/*
|
|
|
|
* Only acpi_dp of type DP_TYPE_TABLE is allowed to be an array.
|
|
|
|
* DP_TYPE_TABLE does not have a value to be written. Thus, start
|
|
|
|
* the loop from next type in the array.
|
|
|
|
*/
|
|
|
|
for (dp = array->next; dp; dp = dp->next) {
|
2016-07-03 04:56:06 +02:00
|
|
|
acpi_dp_write_value(dp);
|
|
|
|
(*pkg_count)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
acpigen_pop_len();
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
static void acpi_dp_free(struct acpi_dp *dp)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
2016-07-03 04:56:06 +02:00
|
|
|
while (dp) {
|
|
|
|
struct acpi_dp *p = dp->next;
|
|
|
|
|
|
|
|
switch (dp->type) {
|
|
|
|
case ACPI_DP_TYPE_CHILD:
|
|
|
|
acpi_dp_free(dp->child);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_ARRAY:
|
|
|
|
acpi_dp_free(dp->array);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(dp);
|
|
|
|
dp = p;
|
|
|
|
}
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
void acpi_dp_write(struct acpi_dp *table)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *dp, *prop;
|
2019-01-30 20:16:08 +01:00
|
|
|
char *dp_count, *prop_count = NULL;
|
2016-07-03 04:56:06 +02:00
|
|
|
int child_count = 0;
|
|
|
|
|
|
|
|
if (!table || table->type != ACPI_DP_TYPE_TABLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Name (name) */
|
|
|
|
acpigen_write_name(table->name);
|
|
|
|
|
|
|
|
/* Device Property list starts with the next entry */
|
|
|
|
prop = table->next;
|
|
|
|
|
2019-01-30 20:16:08 +01:00
|
|
|
/* Package (DP), default to assuming no properties or children */
|
|
|
|
dp_count = acpigen_write_package(0);
|
2016-07-03 04:56:06 +02:00
|
|
|
|
|
|
|
/* Print base properties */
|
|
|
|
for (dp = prop; dp; dp = dp->next) {
|
|
|
|
if (dp->type == ACPI_DP_TYPE_CHILD) {
|
|
|
|
child_count++;
|
|
|
|
} else {
|
2019-01-30 20:16:08 +01:00
|
|
|
/*
|
|
|
|
* The UUID and package is only added when
|
|
|
|
* we come across the first property. This
|
|
|
|
* is to avoid creating a zero-length package
|
|
|
|
* in situations where there are only children.
|
|
|
|
*/
|
|
|
|
if (!prop_count) {
|
|
|
|
*dp_count += 2;
|
|
|
|
/* ToUUID (ACPI_DP_UUID) */
|
|
|
|
acpigen_write_uuid(ACPI_DP_UUID);
|
|
|
|
/*
|
|
|
|
* Package (PROP), element count determined as
|
|
|
|
* it is populated
|
|
|
|
*/
|
|
|
|
prop_count = acpigen_write_package(0);
|
|
|
|
}
|
2016-07-03 04:56:06 +02:00
|
|
|
(*prop_count)++;
|
|
|
|
acpi_dp_write_property(dp);
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 20:16:08 +01:00
|
|
|
if (prop_count) {
|
|
|
|
/* Package (PROP) length, if a package was written */
|
|
|
|
acpigen_pop_len();
|
|
|
|
}
|
2016-07-03 04:56:06 +02:00
|
|
|
|
|
|
|
if (child_count) {
|
2019-01-30 20:16:08 +01:00
|
|
|
/* Update DP package count to 2 or 4 */
|
|
|
|
*dp_count += 2;
|
2016-07-03 04:56:06 +02:00
|
|
|
/* ToUUID (ACPI_DP_CHILD_UUID) */
|
|
|
|
acpigen_write_uuid(ACPI_DP_CHILD_UUID);
|
|
|
|
|
|
|
|
/* Print child pointer properties */
|
|
|
|
acpigen_write_package(child_count);
|
|
|
|
|
|
|
|
for (dp = prop; dp; dp = dp->next)
|
|
|
|
if (dp->type == ACPI_DP_TYPE_CHILD)
|
|
|
|
acpi_dp_write_property(dp);
|
2019-01-30 20:16:08 +01:00
|
|
|
/* Package (CHILD) length */
|
2016-07-03 04:56:06 +02:00
|
|
|
acpigen_pop_len();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Package (DP) length */
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
acpigen_pop_len();
|
2016-07-03 04:56:06 +02:00
|
|
|
|
|
|
|
/* Recursively parse children into separate tables */
|
|
|
|
for (dp = prop; dp; dp = dp->next)
|
|
|
|
if (dp->type == ACPI_DP_TYPE_CHILD)
|
|
|
|
acpi_dp_write(dp->child);
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
acpi_dp_free(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct acpi_dp *acpi_dp_new(struct acpi_dp *dp, enum acpi_dp_type type,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct acpi_dp *new;
|
|
|
|
|
|
|
|
new = malloc(sizeof(struct acpi_dp));
|
|
|
|
if (!new)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(new, 0, sizeof(*new));
|
|
|
|
new->type = type;
|
|
|
|
new->name = name;
|
|
|
|
|
|
|
|
if (dp) {
|
|
|
|
/* Add to end of property list */
|
|
|
|
while (dp->next)
|
|
|
|
dp = dp->next;
|
|
|
|
dp->next = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_dp *acpi_dp_new_table(const char *name)
|
|
|
|
{
|
|
|
|
return acpi_dp_new(NULL, ACPI_DP_TYPE_TABLE, name);
|
|
|
|
}
|
|
|
|
|
2017-08-29 17:26:50 +02:00
|
|
|
size_t acpi_dp_add_property_list(struct acpi_dp *dp,
|
|
|
|
const struct acpi_dp *property_list,
|
|
|
|
size_t property_count)
|
|
|
|
{
|
|
|
|
const struct acpi_dp *prop;
|
|
|
|
size_t i, properties_added = 0;
|
|
|
|
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp || !property_list)
|
|
|
|
return 0;
|
|
|
|
|
2017-08-29 17:26:50 +02:00
|
|
|
for (i = 0; i < property_count; i++) {
|
|
|
|
prop = &property_list[i];
|
|
|
|
|
|
|
|
if (prop->type == ACPI_DP_TYPE_UNKNOWN || !prop->name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (prop->type) {
|
|
|
|
case ACPI_DP_TYPE_INTEGER:
|
|
|
|
acpi_dp_add_integer(dp, prop->name, prop->integer);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_STRING:
|
|
|
|
acpi_dp_add_string(dp, prop->name, prop->string);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_REFERENCE:
|
|
|
|
acpi_dp_add_reference(dp, prop->name, prop->string);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_ARRAY:
|
|
|
|
acpi_dp_add_array(dp, prop->array);
|
|
|
|
break;
|
|
|
|
case ACPI_DP_TYPE_CHILD:
|
|
|
|
acpi_dp_add_child(dp, prop->name, prop->child);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++properties_added;
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties_added;
|
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *acpi_dp_add_integer(struct acpi_dp *dp, const char *name,
|
|
|
|
uint64_t value)
|
|
|
|
{
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp)
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_INTEGER, name);
|
|
|
|
|
|
|
|
if (new)
|
|
|
|
new->integer = value;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_dp *acpi_dp_add_string(struct acpi_dp *dp, const char *name,
|
|
|
|
const char *string)
|
|
|
|
{
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp)
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_STRING, name);
|
|
|
|
|
|
|
|
if (new)
|
|
|
|
new->string = string;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_dp *acpi_dp_add_reference(struct acpi_dp *dp, const char *name,
|
|
|
|
const char *reference)
|
|
|
|
{
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp)
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_REFERENCE, name);
|
|
|
|
|
|
|
|
if (new)
|
|
|
|
new->string = reference;
|
|
|
|
|
|
|
|
return new;
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *acpi_dp_add_child(struct acpi_dp *dp, const char *name,
|
|
|
|
struct acpi_dp *child)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *new;
|
|
|
|
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp || !child || child->type != ACPI_DP_TYPE_TABLE)
|
2016-07-03 04:56:06 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
new = acpi_dp_new(dp, ACPI_DP_TYPE_CHILD, name);
|
|
|
|
if (new) {
|
|
|
|
new->child = child;
|
|
|
|
new->string = child->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_dp *acpi_dp_add_array(struct acpi_dp *dp, struct acpi_dp *array)
|
|
|
|
{
|
|
|
|
struct acpi_dp *new;
|
|
|
|
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp || !array || array->type != ACPI_DP_TYPE_TABLE)
|
2016-07-03 04:56:06 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
new = acpi_dp_new(dp, ACPI_DP_TYPE_ARRAY, array->name);
|
|
|
|
if (new)
|
|
|
|
new->array = array;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name,
|
|
|
|
uint64_t *array, int len)
|
|
|
|
{
|
|
|
|
struct acpi_dp *dp_array;
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
int i;
|
2016-07-03 04:56:06 +02:00
|
|
|
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp || len <= 0)
|
2016-07-03 04:56:06 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dp_array = acpi_dp_new_table(name);
|
|
|
|
if (!dp_array)
|
|
|
|
return NULL;
|
|
|
|
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
for (i = 0; i < len; i++)
|
2016-07-03 04:56:06 +02:00
|
|
|
if (!acpi_dp_add_integer(dp_array, NULL, array[i]))
|
|
|
|
break;
|
|
|
|
|
|
|
|
acpi_dp_add_array(dp, dp_array);
|
|
|
|
|
|
|
|
return dp_array;
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *acpi_dp_add_gpio(struct acpi_dp *dp, const char *name,
|
|
|
|
const char *ref, int index, int pin,
|
|
|
|
int active_low)
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
{
|
2019-05-23 22:34:58 +02:00
|
|
|
if (!dp)
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-03 04:56:06 +02:00
|
|
|
struct acpi_dp *gpio = acpi_dp_new_table(name);
|
|
|
|
|
|
|
|
if (!gpio)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* The device that has _CRS containing GpioIO()/GpioInt() */
|
|
|
|
acpi_dp_add_reference(gpio, NULL, ref);
|
|
|
|
|
|
|
|
/* Index of the GPIO resource in _CRS starting from zero */
|
|
|
|
acpi_dp_add_integer(gpio, NULL, index);
|
|
|
|
|
|
|
|
/* Pin in the GPIO resource, typically zero */
|
|
|
|
acpi_dp_add_integer(gpio, NULL, pin);
|
|
|
|
|
|
|
|
/* Set if pin is active low */
|
|
|
|
acpi_dp_add_integer(gpio, NULL, active_low);
|
|
|
|
|
|
|
|
acpi_dp_add_array(dp, gpio);
|
|
|
|
|
|
|
|
return gpio;
|
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-05-10 22:18:17 +02:00
|
|
|
}
|
2020-04-23 21:51:42 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function writes a PCI device with _ADR object:
|
|
|
|
* Example:
|
|
|
|
* Scope (\_SB.PCI0)
|
|
|
|
* {
|
|
|
|
* Device (IGFX)
|
|
|
|
* {
|
|
|
|
* Name (_ADR, 0x0000000000000000)
|
|
|
|
* Method (_STA, 0, NotSerialized) { Return (status) }
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
2020-04-25 06:59:21 +02:00
|
|
|
void acpi_device_write_pci_dev(const struct device *dev)
|
2020-04-23 21:51:42 +02:00
|
|
|
{
|
|
|
|
const char *scope = acpi_device_scope(dev);
|
|
|
|
const char *name = acpi_device_name(dev);
|
|
|
|
|
|
|
|
assert(dev->path.type == DEVICE_PATH_PCI);
|
|
|
|
assert(name);
|
|
|
|
assert(scope);
|
|
|
|
|
|
|
|
acpigen_write_scope(scope);
|
|
|
|
acpigen_write_device(name);
|
|
|
|
|
|
|
|
acpigen_write_ADR_pci_device(dev);
|
|
|
|
acpigen_write_STA(acpi_device_status(dev));
|
|
|
|
|
|
|
|
acpigen_pop_len(); /* Device */
|
|
|
|
acpigen_pop_len(); /* Scope */
|
|
|
|
}
|