From patchwork Wed May 8 02:33:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16756 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f197.google.com (mail-gg0-f197.google.com [209.85.161.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 593AF238FD for ; Wed, 8 May 2013 02:35:20 +0000 (UTC) Received: by mail-gg0-f197.google.com with SMTP id w6sf1410530ggk.0 for ; Tue, 07 May 2013 19:35:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=tVZYK+2rZ1uCj3laWqbb9WhHoEFdpWTsST4ABHHEwps=; b=nyMj7EKIDATG6E1fpryfFxKBU+kQ7NEHrwtTQPCHwSe32SmZuQC0+WzZkjGRXrQiG2 SmzMLC44ecjDpNur72b66SLzb0wzqQkCcKsvePdpY3h8oSDsLku5S0EZVVyvj44/pCxJ 2LgQzg41oFZF/S4/Ul/5kM4PXCAwEQ8JAR2TxVbb7mgFU8lBKbLSG4hGYgJSW6vrnfpT Kn2TdvDQEO2N6XmcqpPRoMgoWiC9bVVHY/IVAVZ8Hbz1FYrnbGnhWAfVjCPVwv3jCZtN 9Ii7/EOLF1Un4LNqmHldJpHgjRmcriyouNDFW9z/ZHhEcHgFEnrthqaanT8kV49cOonh RJdA== X-Received: by 10.224.215.194 with SMTP id hf2mr6531320qab.0.1367980500193; Tue, 07 May 2013 19:35:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.16 with SMTP id z16ls728679qem.26.gmail; Tue, 07 May 2013 19:34:59 -0700 (PDT) X-Received: by 10.52.76.103 with SMTP id j7mr2724511vdw.90.1367980499914; Tue, 07 May 2013 19:34:59 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id f7si14143498vcs.42.2013.05.07.19.34.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:59 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id m16so1228712vca.2 for ; Tue, 07 May 2013 19:34:59 -0700 (PDT) X-Received: by 10.52.53.36 with SMTP id y4mr2456730vdo.51.1367980499793; Tue, 07 May 2013 19:34:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp131022veb; Tue, 7 May 2013 19:34:59 -0700 (PDT) X-Received: by 10.180.206.172 with SMTP id lp12mr6953503wic.11.1367980498689; Tue, 07 May 2013 19:34:58 -0700 (PDT) Received: from mail-we0-x234.google.com (mail-we0-x234.google.com [2a00:1450:400c:c03::234]) by mx.google.com with ESMTPS id az3si1335388wib.41.2013.05.07.19.34.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:58 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::234 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c03::234; Received: by mail-we0-f180.google.com with SMTP id n5so1234638wev.39 for ; Tue, 07 May 2013 19:34:58 -0700 (PDT) X-Received: by 10.194.58.163 with SMTP id s3mr7259219wjq.6.1367980498305; Tue, 07 May 2013 19:34:58 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id v6sm6823630wiy.11.2013.05.07.19.34.56 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 May 2013 19:34:57 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, patches@linaro.org, ian.campbell@citrix.com, Julien Grall Subject: [PATCH V2 21/33] xen/arm: Use device tree API in pl011 UART driver Date: Wed, 8 May 2013 03:33:41 +0100 Message-Id: <651d1e6d364d53a3f09c77f086a0a36c15e068c3.1367979526.git.julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQkknkhcyJ6WceZEulzKe+mOtFH/l4/ZApdxNqFzBKP2fOLHWmzsIrpIr6fqWefXQkyVaFrg X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Allow UART driver to retrieve all its information in the device tree. It's possible to choose the pl011 driver via the Xen command line. Signed-off-by: Julien Grall Changes in v2: - Rework TODO - Use the new function setup_dt_irq --- xen/arch/arm/gic.c | 4 --- xen/arch/arm/setup.c | 4 --- xen/drivers/char/pl011.c | 64 ++++++++++++++++++++++++++++++++++++---------- xen/include/xen/serial.h | 1 - 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index d719229..f7b9889 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -501,10 +501,6 @@ void gic_route_spis(void) int seridx; const struct dt_irq *irq; - /* XXX should get these from DT */ - /* UART */ - gic_route_irq(37, 0, 1u << smp_processor_id(), 0xa0); - for ( seridx = 0; seridx <= SERHND_IDX; seridx++ ) { if ( (irq = serial_dt_irq(seridx)) == NULL ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 7b2df8b..d8a3578 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -432,10 +432,6 @@ void __init start_xen(unsigned long boot_phys_offset, dt_unflatten_host_device_tree(); dt_irq_xlate = gic_irq_xlate; -#ifdef EARLY_UART_ADDRESS - /* TODO Need to get device tree or command line for UART address */ - pl011_init(0, FIXMAP_ADDR(FIXMAP_CONSOLE)); -#endif arm_uart_init(); console_init_preirq(); diff --git a/xen/drivers/char/pl011.c b/xen/drivers/char/pl011.c index 8efd08e..03161c4 100644 --- a/xen/drivers/char/pl011.c +++ b/xen/drivers/char/pl011.c @@ -22,9 +22,14 @@ #include #include #include +#include +#include +#include +#include static struct pl011 { - unsigned int baud, clock_hz, data_bits, parity, stop_bits, irq; + unsigned int baud, clock_hz, data_bits, parity, stop_bits; + struct dt_irq irq; volatile uint32_t *regs; /* UART with IRQ line: interrupt-driven I/O. */ struct irqaction irqaction; @@ -163,13 +168,13 @@ static void __init pl011_init_postirq(struct serial_port *port) struct pl011 *uart = port->uart; int rc; - if ( uart->irq > 0 ) + if ( uart->irq.irq > 0 ) { uart->irqaction.handler = pl011_interrupt; uart->irqaction.name = "pl011"; uart->irqaction.dev_id = port; - if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 ) - printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq); + if ( (rc = setup_dt_irq(&uart->irq, &uart->irqaction)) != 0 ) + printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq.irq); } /* Clear pending error interrupts */ @@ -215,7 +220,14 @@ static int pl011_getc(struct serial_port *port, char *pc) static int __init pl011_irq(struct serial_port *port) { struct pl011 *uart = port->uart; - return ((uart->irq > 0) ? uart->irq : -1); + return ((uart->irq.irq > 0) ? uart->irq.irq : -1); +} + +static const struct dt_irq __init *pl011_dt_irq(struct serial_port *port) +{ + struct pl011 *uart = port->uart; + + return &uart->irq; } static struct uart_driver __read_mostly pl011_driver = { @@ -227,32 +239,56 @@ static struct uart_driver __read_mostly pl011_driver = { .tx_ready = pl011_tx_ready, .putc = pl011_putc, .getc = pl011_getc, - .irq = pl011_irq + .irq = pl011_irq, + .dt_irq_get = pl011_dt_irq, }; -/* TODO: Parse UART config from device-tree or command-line */ - -void __init pl011_init(int index, unsigned long register_base_address) +/* TODO: Parse UART config from the command line */ +static int __init pl011_uart_init(struct dt_device_node *dev, + const void *data) { + const struct serial_arm_defaults *defaults = data; struct pl011 *uart; + int res; - if ( (index < 0) || (index > 1) ) - return; + if ( (defaults->index < 0) || (defaults->index > 1) ) + return -EINVAL; - uart = &pl011_com[index]; + uart = &pl011_com[defaults->index]; uart->clock_hz = 0x16e3600; uart->baud = 38400; uart->data_bits = 8; uart->parity = PARITY_NONE; uart->stop_bits = 1; - uart->irq = 37; /* TODO Need to find this from devicetree */ - uart->regs = (uint32_t *) register_base_address; + uart->regs = (uint32_t *) defaults->register_base_address; + + res = dt_device_get_irq(dev, 0, &uart->irq); + if ( res ) + { + early_printk("pl011: Unable to retrieve the IRQ\n"); + return res; + } /* Register with generic serial driver. */ serial_register_uart(uart - pl011_com, &pl011_driver, uart); + + dt_device_set_used_by(dev, DT_USED_BY_XEN); + + return 0; } +static const char const *pl011_dt_compat[] __initdata = +{ + "arm,pl011", + NULL +}; + +DT_DEVICE_START(pl011, "PL011 UART", DEVICE_SERIAL) + .compatible = pl011_dt_compat, + .init = pl011_uart_init, +DT_DEVICE_END + /* * Local variables: * mode: C diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index f548f8b..16ed261 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -156,7 +156,6 @@ struct ns16550_defaults { void ns16550_init(int index, struct ns16550_defaults *defaults); void ehci_dbgp_init(void); -void pl011_init(int index, unsigned long register_base_address); /* Default value for UART on ARM boards */ struct serial_arm_defaults { int index; /* Serial index */