From patchwork Tue Aug 21 20:47:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Prisk X-Patchwork-Id: 179163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ob0-f184.google.com (mail-ob0-f184.google.com [209.85.214.184]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 8C2DE2C00BC for ; Wed, 22 Aug 2012 06:48:03 +1000 (EST) Received: by obbwc20 with SMTP id wc20sf189542obb.11 for ; Tue, 21 Aug 2012 13:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=pZHDettmWxJKba2/IUk669zWBJHm49aYI2knnQuZ6JI=; b=H3WMONyeXU8msKDy5viCh9hcu3XSII2M3P60bU3hAMXKEBPCb9I+xcahO3WnamIVOA dZD/eIRsTvuB2VAGSXkOCJmxjVz7qdMGb4k4M+i8mPlG31leYHG3WUq27rVffx/Zo6G4 rI7UqqaCA3A3ju/eRxlVJ33SK0K2wtwODlcsdDud8ZymK1cuVqR1m69lPjQJ/vPz/Jxv 0EPJ7uJJtE+1PnLR/h258U0WYMihQSt1UquPnVK1XPPnLf2d6ei0B8wqun/Xdnfp2NbM KCSJe1yfc5/nS2qanZOQ1U5dEcdrkhTY9HSUuS4A3oxv8ZCuUVvfCPzySvGtaxch8GSC 6O3w== Received: by 10.68.211.6 with SMTP id my6mr2922245pbc.15.1345582080654; Tue, 21 Aug 2012 13:48:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.68.194.202 with SMTP id hy10ls578984pbc.0.gmail; Tue, 21 Aug 2012 13:48:00 -0700 (PDT) Received: by 10.66.77.199 with SMTP id u7mr2707257paw.25.1345582080322; Tue, 21 Aug 2012 13:48:00 -0700 (PDT) Received: by 10.66.77.199 with SMTP id u7mr2707256paw.25.1345582080311; Tue, 21 Aug 2012 13:48:00 -0700 (PDT) Received: from mta03.xtra.co.nz (mta06.xtra.co.nz. [210.54.141.249]) by gmr-mx.google.com with ESMTP id vo7si1102594pbc.1.2012.08.21.13.47.59; Tue, 21 Aug 2012 13:48:00 -0700 (PDT) Received-SPF: neutral (google.com: 210.54.141.249 is neither permitted nor denied by best guess record for domain of linux@prisktech.co.nz) client-ip=210.54.141.249; Received: from gitbox.prisktech.co.nz ([115.188.14.127]) by mta03.xtra.co.nz with ESMTP id <20120821204758.ORVN22346.mta03.xtra.co.nz@gitbox.prisktech.co.nz>; Wed, 22 Aug 2012 08:47:58 +1200 From: Tony Prisk To: vt8500-wm8505-linux-kernel@googlegroup.com Cc: Tony Prisk , Russell King , Alessandro Zummo , Alan Cox , Greg Kroah-Hartman , Florian Tobias Schandinat , Arnd Bergmann , Grant Likely , Rob Herring , Rob Landley , Linus Walleij , Mike Turquette , Stephen Warren , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-serial@vger.kernel.org, rtc-linux@googlegroups.com, devicetree-discuss@lists.ozlabs.org Subject: [rtc-linux] [PATCHv3 3/9] serial: vt8500: Add devicetree support for vt8500-serial Date: Wed, 22 Aug 2012 08:47:32 +1200 Message-Id: <1345582058-2291-4-git-send-email-linux@prisktech.co.nz> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1345582058-2291-1-git-send-email-linux@prisktech.co.nz> References: <1345582058-2291-1-git-send-email-linux@prisktech.co.nz> X-Original-Sender: linux@prisktech.co.nz X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 210.54.141.249 is neither permitted nor denied by best guess record for domain of linux@prisktech.co.nz) smtp.mail=linux@prisktech.co.nz Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Signed-off-by: Tony Prisk --- drivers/tty/serial/vt8500_serial.c | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c index 2be006f..72e32db 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c @@ -34,6 +34,7 @@ #include #include #include +#include /* * UART Register offsets @@ -76,6 +77,8 @@ #define RX_FIFO_INTS (RXFAF | RXFF | RXOVER | PER | FER | RXTOUT) #define TX_FIFO_INTS (TXFAE | TXFE | TXUDR) +#define VT8500_MAX_PORTS 6 + struct vt8500_port { struct uart_port uart; char name[16]; @@ -83,6 +86,13 @@ struct vt8500_port { unsigned int ier; }; +/* + * we use this variable to keep track of which ports + * have been allocated as we can't use pdev->id in + * devicetree + */ +static unsigned long vt8500_ports_in_use; + static inline void vt8500_write(struct uart_port *port, unsigned int val, unsigned int off) { @@ -431,7 +441,7 @@ static int vt8500_verify_port(struct uart_port *port, return 0; } -static struct vt8500_port *vt8500_uart_ports[4]; +static struct vt8500_port *vt8500_uart_ports[VT8500_MAX_PORTS]; static struct uart_driver vt8500_uart_driver; #ifdef CONFIG_SERIAL_VT8500_CONSOLE @@ -549,6 +559,7 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev) struct vt8500_port *vt8500_port; struct resource *mmres, *irqres; int ret; + int port; mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0); irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0); @@ -559,13 +570,25 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev) if (!vt8500_port) return -ENOMEM; + /* calculate the port id */ + port = find_first_zero_bit(&vt8500_ports_in_use, + sizeof(vt8500_ports_in_use)); + if (port > VT8500_MAX_PORTS) + return -ENODEV; + + /* reserve the port id */ + if (test_and_set_bit(port, &vt8500_ports_in_use)) { + /* port already in use - shouldn't really happen */ + return -EBUSY; + } + vt8500_port->uart.type = PORT_VT8500; vt8500_port->uart.iotype = UPIO_MEM; vt8500_port->uart.mapbase = mmres->start; vt8500_port->uart.irq = irqres->start; vt8500_port->uart.fifosize = 16; vt8500_port->uart.ops = &vt8500_uart_pops; - vt8500_port->uart.line = pdev->id; + vt8500_port->uart.line = port; vt8500_port->uart.dev = &pdev->dev; vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; vt8500_port->uart.uartclk = 24000000; @@ -579,7 +602,7 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev) goto err; } - vt8500_uart_ports[pdev->id] = vt8500_port; + vt8500_uart_ports[port] = vt8500_port; uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart); @@ -603,12 +626,18 @@ static int __devexit vt8500_serial_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id wmt_dt_ids[] = { + { .compatible = "via,vt8500-uart", }, + {} +}; + static struct platform_driver vt8500_platform_driver = { .probe = vt8500_serial_probe, .remove = __devexit_p(vt8500_serial_remove), .driver = { .name = "vt8500_serial", .owner = THIS_MODULE, + .of_match_table = of_match_ptr(wmt_dt_ids), }, }; @@ -642,4 +671,4 @@ module_exit(vt8500_serial_exit); MODULE_AUTHOR("Alexey Charkov "); MODULE_DESCRIPTION("Driver for vt8500 serial device"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2");