Re: [PATCH v4 00/13] Add ACPI _DSD and unified device properties support

David Woodhouse
2015-01-14T18:42:31Z

[-- Attachment #1.1: Type: text/plain, Size: 1803 bytes --]

I'm looking again at updating of_serial to work with ACPI properties.

Specifically, I want to support a serial port with a non-standard baud
rate, something like this:

Device(COM1) {
Name(_HID, EisaId("PNP0501"))
Name(_CID, EisaId("PRP0001"))
Name(_DSD, Package() {
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"compatible", Package () {"ns16550a"}},
Package () {"clock-frequency", 2457600},
}
})
...
}

Firstly, the of_serial driver doesn't even get *invoked* unless I do
this:

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 0d08373..eb1201a 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2083,6 +2086,8 @@ static int acpi_add_single_object(struct acpi_device **child,
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
dev_name(&device->dev), (char *) buffer.pointer,
device->parent ? dev_name(&device->parent->dev) : "(null)"));
+ if (device->data.of_compatible)
+ acpi_create_platform_device(device);
kfree(buffer.pointer);
*child = device;
return 0;

Now it doesn't work because it uses of_match_device() to look the device
up and find the corresponding *data* for that entry in its match table.
And without CONFIG_OF, I don't *have* of_match_device().

We've talked about the fact that the platform bus probe function doesn't
pass you the match ID. Is that something we could potentially fix now
that things are a little more unified?

Or do we expect drivers still to have to use something like
of_match_id() to do the lookup again for themselves... and in that case
should we make of_match_id() available or produce a new
device_match_id() that they are expected to switch to?

--
dwmw2

[-- Attachment #1.2: of-serial-dev-properties.patch --]
[-- Type: text/x-patch, Size: 7650 bytes --]

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index c79b43c..65cf850 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1114,14 +1114,14 @@ config SERIAL_NETX_CONSOLE
you can make it the console by answering Y to this option.

config SERIAL_OF_PLATFORM
- tristate "Serial port on Open Firmware platform bus"
- depends on OF
+ tristate "Serial port on firmware platform bus"
+ depends on OF || ACPI
depends on SERIAL_8250 || SERIAL_OF_PLATFORM_NWPSERIAL
help
- If you have a PowerPC based system that has serial ports
- on a platform specific bus, you should enable this option.
- Currently, only 8250 compatible ports are supported, but
- others can easily be added.
+ If you have a system which advertises its serial ports through
+ devicetree or ACPI, you should enable this option. Currently
+ only 8250 compatible and NWP ports and are supported, but others
+ can easily be added.

config SERIAL_OMAP
tristate "OMAP serial port support"
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 64f1bab..54110e6 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -15,8 +15,7 @@
#include <linux/delay.h>
#include <linux/serial_core.h>
#include <linux/serial_reg.h>
-#include <linux/of_address.h>
-#include <linux/of_irq.h>
+#include <linux/property.h>
#include <linux/of_platform.h>
#include <linux/nwpserial.h>
#include <linux/clk.h>
@@ -54,22 +53,22 @@ static inline void tegra_serial_handle_break(struct uart_port *port)
/*
* Fill a struct uart_port for a given device node
*/
-static int of_platform_serial_setup(struct platform_device *ofdev,
+static int of_platform_serial_setup(struct platform_device *pdev,
int type, struct uart_port *port,
struct of_serial_info *info)
{
- struct resource resource;
- struct device_node *np = ofdev->dev.of_node;
u32 clk, spd, prop;
- int ret;
+ int iotype = -1;
+ u32 res_start;
+ int ret, i;

memset(port, 0, sizeof *port);
- if (of_property_read_u32(np, "clock-frequency", &clk)) {
+ if (device_property_read_u32(&pdev->dev, "clock-frequency", &clk)) {

/* Get clk rate through clk driver if present */
- info->clk = clk_get(&ofdev->dev, NULL);
+ info->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) {
- dev_warn(&ofdev->dev,
+ dev_warn(&pdev->dev,
"clk or clock-frequency not defined\n");
return PTR_ERR(info->clk);
}
@@ -78,57 +77,63 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
clk = clk_get_rate(info->clk);
}
/* If current-speed was set, then try not to change it. */
- if (of_property_read_u32(np, "current-speed", &spd) == 0)
+ if (device_property_read_u32(&pdev->dev, "current-speed", &spd) == 0)
port->custom_divisor = clk / (16 * spd);

- ret = of_address_to_resource(np, 0, &resource);
- if (ret) {
- dev_warn(&ofdev->dev, "invalid address\n");
+ /* Check for shifted address mapping */
+ if (device_property_read_u32(&pdev->dev, "reg-offset", &prop) != 0)
+ prop = 0;
+
+ for (i = 0; iotype == -1 && i < pdev->num_resources; i++) {
+ struct resource *resource = &pdev->resource[i];
+ if (resource_type(resource) == IORESOURCE_MEM) {
+ iotype = UPIO_MEM;
+ port->mapbase = res_start + prop;
+ } else if (resource_type(resource) == IORESOURCE_IO) {
+ iotype = UPIO_PORT;
+ port->iobase = res_start + prop;
+ }
+
+ res_start = resource->start;
+ }
+ if (iotype == -1) {
+ dev_warn(&pdev->dev, "invalid address\n");
goto out;
}

spin_lock_init(&port->lock);
- port->mapbase = resource.start;
-
- /* Check for shifted address mapping */
- if (of_property_read_u32(np, "reg-offset", &prop) == 0)
- port->mapbase += prop;

/* Check for registers offset within the devices address range */
- if (of_property_read_u32(np, "reg-shift", &prop) == 0)
+ if (device_property_read_u32(&pdev->dev, "reg-shift", &prop) == 0)
port->regshift = prop;

/* Check for fifo size */
- if (of_property_read_u32(np, "fifo-size", &prop) == 0)
+ if (device_property_read_u32(&pdev->dev, "fifo-size", &prop) == 0)
port->fifosize = prop;

- port->irq = irq_of_parse_and_map(np, 0);
- port->iotype = UPIO_MEM;
- if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
- switch (prop) {
- case 1:
- port->iotype = UPIO_MEM;
- break;
- case 4:
- port->iotype = UPIO_MEM32;
- break;
- default:
- dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n",
+ port->irq = platform_get_irq(pdev, 0);
+
+ if (device_property_read_u32(&pdev->dev, "reg-io-width", &prop) == 0) {
+ if (prop == 4 && iotype == UPIO_MEM) {
+ iotype = UPIO_MEM32;
+ } else {
+ dev_warn(&pdev->dev, "unsupported reg-io-width (%d)\n",
prop);
ret = -EINVAL;
goto out;
}
}

+ port->iotype = iotype;
port->type = type;
port->uartclk = clk;
port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
| UPF_FIXED_PORT | UPF_FIXED_TYPE;

- if (of_find_property(np, "no-loopback-test", NULL))
+ if (device_property_present(&pdev->dev, "no-loopback-test"))
port->flags |= UPF_SKIP_TEST;

- port->dev = &ofdev->dev;
+ port->dev = &pdev->dev;

switch (type) {
case PORT_TEGRA:
@@ -151,19 +156,19 @@ out:
* Try to register a serial port
*/
static struct of_device_id of_platform_serial_table[];
-static int of_platform_serial_probe(struct platform_device *ofdev)
+static int of_platform_serial_probe(struct platform_device *pdev)
{
const struct of_device_id *match;
struct of_serial_info *info;
struct uart_port port;
int port_type;
int ret;
-
- match = of_match_device(of_platform_serial_table, &ofdev->dev);
+ printk("%s\n", __func__);
+ match = of_match_device(of_platform_serial_table, &pdev->dev);
if (!match)
return -EINVAL;

- if (of_find_property(ofdev->dev.of_node, "used-by-rtas", NULL))
+ if (device_property_present(&pdev->dev, "used-by-rtas"))
return -EBUSY;

info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -171,7 +176,7 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
return -ENOMEM;

port_type = (unsigned long)match->data;
- ret = of_platform_serial_setup(ofdev, port_type, &port, info);
+ ret = of_platform_serial_setup(pdev, port_type, &port, info);
if (ret)
goto out;

@@ -187,8 +192,7 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
if (port.fifosize)
port8250.capabilities = UART_CAP_FIFO;

- if (of_property_read_bool(ofdev->dev.of_node,
- "auto-flow-control"))
+ if (device_property_present(&pdev->dev, "auto-flow-control"))
port8250.capabilities |= UART_CAP_AFE;

ret = serial8250_register_8250_port(&port8250);
@@ -203,7 +207,7 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
default:
/* need to add code for these */
case PORT_UNKNOWN:
- dev_info(&ofdev->dev, "Unknown serial port found, ignored\n");
+ dev_info(&pdev->dev, "Unknown serial port found, ignored\n");
ret = -ENODEV;
break;
}
@@ -212,20 +216,19 @@ static int of_platform_serial_probe(struct platform_device *ofdev)

info->type = port_type;
info->line = ret;
- platform_set_drvdata(ofdev, info);
+ platform_set_drvdata(pdev, info);
return 0;
out:
kfree(info);
- irq_dispose_mapping(port.irq);
return ret;
}

/*
* Release a line
*/
-static int of_platform_serial_remove(struct platform_device *ofdev)
+static int of_platform_serial_remove(struct platform_device *pdev)
{
- struct of_serial_info *info = platform_get_drvdata(ofdev);
+ struct of_serial_info *info = platform_get_drvdata(pdev);
switch (info->type) {
#ifdef CONFIG_SERIAL_8250
case PORT_8250 ... PORT_MAX_8250:

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5745 bytes --]