From patchwork Sun Dec 1 06:26:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 3261611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 33024BEEAD for ; Sun, 1 Dec 2013 06:31:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 181ED20124 for ; Sun, 1 Dec 2013 06:31:05 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE4B12011F for ; Sun, 1 Dec 2013 06:31:03 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0Wv-0006gK-Vv; Sun, 01 Dec 2013 06:29:23 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0WR-0002QX-8o; Sun, 01 Dec 2013 06:28:51 +0000 Received: from mail-la0-x22e.google.com ([2a00:1450:4010:c03::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0WK-0002Nx-JO for linux-arm-kernel@lists.infradead.org; Sun, 01 Dec 2013 06:28:45 +0000 Received: by mail-la0-f46.google.com with SMTP id eh20so7541996lab.5 for ; Sat, 30 Nov 2013 22:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ABLlRAD14zlmmkDNE2/xrWlCFWZG4TwYy29S/g5Zdbo=; b=mKP+E6Mps/9CDNIoBQxYqVDAgyWMMwWNhdZvcNhx3P34XCdNX5BGTrcmFqSVZCEPXg 1ZflYPoZ/ioi2h4WdAuhXfs4PtEMvruojxv5H2bMfxDDzyt3vNFrWwB2N9U8SfQKHt3j pKICMM2cxZwl8ac8ilU0DM11N1BDgHgSSUpz5IUC6dfi0vUv5LcIitmwQGg1k8Rk2LMw WkJHduMt3cP8DZfVACA+gfiwRnG92LSUtbTocxpCcxhsgyk5PDcm/CERAwe9x9Lhze+Q u0Kt/vDIl8S79smm6c0ShFeZw4bR7VRlSo3BlPrbTzgqWW+JajJF7E+x4kgi6t3njhhm H+6A== X-Received: by 10.152.28.230 with SMTP id e6mr35386467lah.3.1385879302360; Sat, 30 Nov 2013 22:28:22 -0800 (PST) Received: from host5.omatika.ru (0893675324.static.corbina.ru. [95.31.1.192]) by mx.google.com with ESMTPSA id e10sm82577921laa.6.2013.11.30.22.28.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Nov 2013 22:28:21 -0800 (PST) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 05/11] serial: support for 16550 serial ports on LP-8x4x Date: Sun, 1 Dec 2013 10:26:18 +0400 Message-Id: <1385879185-22455-6-git-send-email-ynvich@gmail.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1385879185-22455-1-git-send-email-ynvich@gmail.com> References: <1385879185-22455-1-git-send-email-ynvich@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131201_012844_948721_72BF1671 X-CRM114-Status: GOOD ( 26.85 ) X-Spam-Score: -1.9 (-) Cc: Heikki Krogerus , Eric Miao , Arnd Bergmann , Greg Kroah-Hartman , Haojian Zhuang , Sergei Ianovich , "open list:SERIAL DRIVERS" , Russell King , Jiri Slaby X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SBL, RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no 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 The patch adds support for 3 additional LP-8x4x built-in serial ports. The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet. Signed-off-by: Sergei Ianovich --- arch/arm/configs/lp8x4x_defconfig | 1 + arch/arm/mach-pxa/include/mach/lp8x4x.h | 6 ++ drivers/tty/serial/8250/8250_lp8x4x.c | 181 ++++++++++++++++++++++++++++++++ drivers/tty/serial/8250/Kconfig | 11 ++ drivers/tty/serial/8250/Makefile | 1 + 5 files changed, 200 insertions(+) create mode 100644 drivers/tty/serial/8250/8250_lp8x4x.c diff --git a/arch/arm/configs/lp8x4x_defconfig b/arch/arm/configs/lp8x4x_defconfig index 03c85bc..d297a67 100644 --- a/arch/arm/configs/lp8x4x_defconfig +++ b/arch/arm/configs/lp8x4x_defconfig @@ -1141,6 +1141,7 @@ CONFIG_SERIAL_8250_NR_UARTS=36 CONFIG_SERIAL_8250_RUNTIME_UARTS=36 CONFIG_SERIAL_8250_EXTENDED=y CONFIG_SERIAL_8250_MANY_PORTS=y +CONFIG_SERIAL_8250_LP8X4X=m CONFIG_SERIAL_8250_SHARE_IRQ=y # CONFIG_SERIAL_8250_DETECT_IRQ is not set # CONFIG_SERIAL_8250_RSA is not set diff --git a/arch/arm/mach-pxa/include/mach/lp8x4x.h b/arch/arm/mach-pxa/include/mach/lp8x4x.h index a49df22..4d5474e 100644 --- a/arch/arm/mach-pxa/include/mach/lp8x4x.h +++ b/arch/arm/mach-pxa/include/mach/lp8x4x.h @@ -50,6 +50,12 @@ #define LP8X4X_CLRFALLINT LP8X4X_P2V(0x1700901a) #define LP8X4X_RWRTC LP8X4X_P2V(0x1700901c) #define LP8X4X_SRAMBANK 0x1700901e +#define LP8X4X_TTYS0_QUIRK 0x17009030 +#define LP8X4X_TTYS1_QUIRK 0x17009032 +#define LP8X4X_TTYS2_QUIRK 0x17009034 +#define LP8X4X_TTYS0_IOMEM 0x17009050 +#define LP8X4X_TTYS1_IOMEM 0x17009060 +#define LP8X4X_TTYS2_IOMEM 0x17009070 #define LP8X4X_SRAM 0x1700a000 /* board specific IRQs */ diff --git a/drivers/tty/serial/8250/8250_lp8x4x.c b/drivers/tty/serial/8250/8250_lp8x4x.c new file mode 100644 index 0000000..27b01f0b --- /dev/null +++ b/drivers/tty/serial/8250/8250_lp8x4x.c @@ -0,0 +1,181 @@ +/* linux/drivers/tty/serial/8250/8250_lp8x4x.c + * + * Support for 16550 serial ports on ICP DAS LP-8x4x + * + * Copyright (C) 2013 Sergei Ianovich + * Framework taken from linux/drivers/tty/serial/8250/8250_accent.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include + +#define QUIRK_PORT(_base, _irq) \ + { \ + .iobase = _base, \ + .membase = (void *) _base, \ + .mapbase = _base, \ + .irq = _irq, \ + .uartclk = 14745600, \ + .regshift = 1, \ + .iotype = UPIO_MEM, \ + .flags = UPF_IOREMAP, \ + .set_termios = lp8x4x_set_termios, \ + .serial_in = lp8x4x_serial_in, \ + .serial_out = lp8x4x_serial_out, \ + } + +static void lp8x4x_set_termios(struct uart_port *port, + struct ktermios *termios, struct ktermios *old) +{ + unsigned int len; + unsigned int baud; + + switch (termios->c_cflag & CSIZE) { + case CS5: + len = 7; + break; + case CS6: + len = 8; + break; + case CS7: + len = 9; + break; + default: + case CS8: + len = 10; + break; + } + + if (termios->c_cflag & CSTOPB) + len++; + if (termios->c_cflag & PARENB) + len++; + if (!(termios->c_cflag & PARODD)) + len++; +#ifdef CMSPAR + if (termios->c_cflag & CMSPAR) + len++; +#endif + + len -= 9; + len &= 3; + len <<= 3; + /* + * Ask the core to calculate the divisor for us. + */ + baud = uart_get_baud_rate(port, termios, old, + port->uartclk / 16 / 0xffff, + port->uartclk / 16); + switch (baud) { + case 2400: + len |= 1; + case 4800: + len |= 2; + case 19200: + len |= 4; + case 38400: + len |= 5; + case 57600: + len |= 6; + case 115200: + len |= 7; + case 9600: + default: + len |= 3; + }; + iowrite8(len, port->private_data); + + serial8250_do_set_termios(port, termios, old); +} + +static unsigned int lp8x4x_serial_in(struct uart_port *p, int offset) +{ + unsigned int b; + udelay(30); + offset = offset << p->regshift; + b = readb(p->membase + offset); + return b; +} + +static void lp8x4x_serial_out(struct uart_port *p, int offset, int value) +{ + offset = offset << p->regshift; + writeb(value, p->membase + offset); +} + +static struct plat_serial8250_port lp8x4x_data[] = { + QUIRK_PORT(LP8X4X_TTYS0_IOMEM, LP8X4X_TTYS0_IRQ), + QUIRK_PORT(LP8X4X_TTYS1_IOMEM, LP8X4X_TTYS1_IRQ), + QUIRK_PORT(LP8X4X_TTYS2_IOMEM, LP8X4X_TTYS2_IRQ), + { }, +}; + +/* Total number of ports can be 35. The first 3 ports are on + * the device, the rest are on extension slots. Only the first 3 + * require termios quirk */ +#define LP8X4X_QUIRK_PORTS 3 + +static unsigned int extra_mem[LP8X4X_QUIRK_PORTS] = { + LP8X4X_TTYS0_QUIRK, + LP8X4X_TTYS1_QUIRK, + LP8X4X_TTYS2_QUIRK +}; + +static int request_and_remap(int i) +{ + if (!request_mem_region(extra_mem[i], 1, "serial")) + return -EBUSY; + + lp8x4x_data[i].private_data = ioremap(extra_mem[i], 1); + if (lp8x4x_data[i].private_data) + return 0; + + release_mem_region(extra_mem[i], 1); + return -ENODEV; +} + +static void release_and_unmap(int i) +{ + iounmap((void *) lp8x4x_data[i].private_data); + release_mem_region(extra_mem[i], 1); +} + +static struct platform_device lp8x4x_device = { + .name = "serial8250", + .id = PLAT8250_DEV_ACCENT, + .dev = { + .platform_data = lp8x4x_data, + }, +}; + +static int __init lp8x4x_init(void) +{ + int i = 0; + int err = 0; + + for (i = 0; i < LP8X4X_QUIRK_PORTS; i++) { + err = request_and_remap(i); + if (err == 0) + continue; + + for (; i >= 0; i--) + release_and_unmap(i); + lp8x4x_device.dev.platform_data = NULL; + return err; + } + return platform_device_register(&lp8x4x_device); +} + +module_init(lp8x4x_init); + +MODULE_AUTHOR("Sergei Ianovich"); +MODULE_DESCRIPTION("8250 serial port module for LP-8x4x"); +MODULE_LICENSE("GPL"); diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig index f3b306e..30b9af4 100644 --- a/drivers/tty/serial/8250/Kconfig +++ b/drivers/tty/serial/8250/Kconfig @@ -237,6 +237,17 @@ config SERIAL_8250_HUB6 To compile this driver as a module, choose M here: the module will be called 8250_hub6. +config SERIAL_8250_LP8X4X + tristate "Support 8250 ports on ICP DAS LP-8x4x" + depends on SERIAL_8250 != n && SERIAL_8250_MANY_PORTS && MACH_LP8X4X + help + In addition on serial ports on PXA270 SoC, LP-8x4x has 1 dual + RS232/RS485 port, 1 RS485 port and 1 RS232 port serial ports. + + Say N here, unless you plan to run this kernel on a LP-8x4x system. + + If you choose M, the module will be called 8250_lp8x4x. + # # Misc. options/drivers. # diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile index 36d68d0..451c558 100644 --- a/drivers/tty/serial/8250/Makefile +++ b/drivers/tty/serial/8250/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o +obj-$(CONFIG_SERIAL_8250_LP8X4X) += 8250_lp8x4x.o obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o