From patchwork Wed Jan 14 18:42:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 5634361 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0BD17C058D for ; Wed, 14 Jan 2015 18:42:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D065F2018E for ; Wed, 14 Jan 2015 18:42:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DDCC20160 for ; Wed, 14 Jan 2015 18:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752209AbbANSmc (ORCPT ); Wed, 14 Jan 2015 13:42:32 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:51591 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbbANSmb (ORCPT ); Wed, 14 Jan 2015 13:42:31 -0500 Received: from [192.102.209.254] (helo=shinybook.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1YBStc-0005C2-J0; Wed, 14 Jan 2015 18:42:24 +0000 Message-ID: <1421260943.14516.19.camel@infradead.org> Subject: Re: [PATCH v4 00/13] Add ACPI _DSD and unified device properties support From: David Woodhouse To: Mark Rutland Cc: "Rafael J. Wysocki" , Linux Kernel Mailing List , Greg Kroah-Hartman , Mika Westerberg , ACPI Devel Maling List , Aaron Lu , "devicetree@vger.kernel.org" , Linus Walleij , Alexandre Courbot , Dmitry Torokhov , Bryan Wu , "grant.likely@linaro.org" , Arnd Bergmann , Darren Hart Date: Wed, 14 Jan 2015 10:42:23 -0800 In-Reply-To: <20141015131551.GC20034@leverpostej> References: <2660541.BycO7TFnA2@vostro.rjw.lan> <1413378271.2762.77.camel@infradead.org> <20141015131551.GC20034@leverpostej> X-Mailer: Evolution 3.12.9 (3.12.9-1.fc21) Mime-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: 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? 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 #include #include -#include -#include +#include #include #include #include @@ -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: