From patchwork Mon Mar 14 01:51:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 8574701 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2ABB09F54C for ; Mon, 14 Mar 2016 01:53:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0212620460 for ; Mon, 14 Mar 2016 01:53:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3EFE20453 for ; Mon, 14 Mar 2016 01:53:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1afHfv-0003wA-Q4; Mon, 14 Mar 2016 01:52:03 +0000 Received: from mail-pa0-x233.google.com ([2607:f8b0:400e:c03::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1afHfr-0003vG-69 for linux-arm-kernel@lists.infradead.org; Mon, 14 Mar 2016 01:52:00 +0000 Received: by mail-pa0-x233.google.com with SMTP id fe3so129093512pab.1 for ; Sun, 13 Mar 2016 18:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=PR6qqF6NvoZ2VhxzJ/ypxGYqE2dpEwf9HVe5EvwmqtA=; b=cilGcxvNYtwiioVMbhbz6eayRuTMgrmUgXXtmeHaoyaas39iSld4rHE89ysVjSm4xg SN1U5Sn33Sg2uV+3+cKa9l4628irxRHSkqhNDMTBT/PTkvBGkQ6LQTZ6S1fS/wAnfUcF pG8Xl32HWd5FpaIhKW7qXvw2T6b7Hq7WoytNc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PR6qqF6NvoZ2VhxzJ/ypxGYqE2dpEwf9HVe5EvwmqtA=; b=F+x3oaFEPVDB7/mEu3Hg/opBGaqZQpKNozWkecoM4cfVnfz6FF6M7jp5NF5C569fDy 1OmnhLEPnDidI77xJUZDSXQS7zxYZoJGiqZsAXJr6dZZvK572FNPbd+epYjySasT47TV i1BSfCEMAU9IqT1DqqCLFCC2cyJDgkrcXuVojYea9Z7jqbi4xU6P1wMIRM/F5VZxij7K oF6mUM/qKPHvzOKJQ2PIFAs6QqGSrG6fAIQEcMJAWgXQXBYaopj/EbvgExiLsuI2tm8a V5KFzZXFA6/OdghHt2979WW0tudTSw5BO9RQT8MgFUzwRXcgAc4zX/7J8aEqe1amb7Nj lgng== X-Gm-Message-State: AD7BkJJbsY8NYJV2cmoli40J/MFoTgONWzfxWFnsB2RD+pWU2cLm3BHYU9TRQHMGaNS1smr0 X-Received: by 10.66.190.168 with SMTP id gr8mr34146812pac.23.1457920297877; Sun, 13 Mar 2016 18:51:37 -0700 (PDT) Received: from localhost.localdomain (us1.aimitrade.com. [173.255.218.183]) by smtp.gmail.com with ESMTPSA id fk9sm27696323pad.9.2016.03.13.18.51.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 Mar 2016 18:51:36 -0700 (PDT) From: Jun Nie To: andre.przywara@arm.com, timur@codeaurora.org, linux@arm.linux.org.uk, graeme.gregory@linaro.org, peter@hurleysoftware.com, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, shawn.guo@linaro.org Subject: [PATCH 1/2] serial: amba-pl011: make platform driver generic Date: Mon, 14 Mar 2016 09:51:21 +0800 Message-Id: <1457920282-14823-1-git-send-email-jun.nie@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160313_185159_511717_7A43931A X-CRM114-Status: GOOD ( 15.21 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jason.liu@linaro.org, Jun Nie 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=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 make sbsa uart platform driver more generic so that platform driver code can be reused by ZTE uart platform driver. Signed-off-by: Jun Nie --- drivers/tty/serial/amba-pl011.c | 57 +++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 7c198e0..2d1917e 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -73,6 +73,9 @@ #define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) #define UART_DUMMY_DR_RX (1 << 16) +static const struct uart_ops amba_pl011_pops; +static const struct uart_ops sbsa_uart_pops; + static u16 pl011_std_offsets[REG_ARRAY_SIZE] = { [REG_DR] = UART01x_DR, [REG_FR] = UART01x_FR, @@ -92,6 +95,7 @@ static u16 pl011_std_offsets[REG_ARRAY_SIZE] = { /* There is by now at least one vendor with differing details, so handle it */ struct vendor_data { const u16 *reg_offset; + const struct uart_ops *uart_pops; unsigned int ifls; bool access_32b; bool oversampling; @@ -119,13 +123,20 @@ static struct vendor_data vendor_arm = { .get_fifosize = get_fifosize_arm, }; +static unsigned int get_fifosize_sbsa(struct amba_device *dev) +{ + return 32; +} + static struct vendor_data vendor_sbsa = { .reg_offset = pl011_std_offsets, + .uart_pops = &sbsa_uart_pops, .oversampling = false, .dma_threshold = false, .cts_event_workaround = false, .always_enabled = true, .fixed_options = true, + .get_fifosize = get_fifosize_sbsa, }; static u16 pl011_st_offsets[REG_ARRAY_SIZE] = { @@ -189,6 +200,7 @@ static const u16 pl011_zte_offsets[REG_ARRAY_SIZE] = { static struct vendor_data vendor_zte __maybe_unused = { .reg_offset = pl011_zte_offsets, + .uart_pops = &amba_pl011_pops, .access_32b = true, .ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8, .get_fifosize = get_fifosize_arm, @@ -2086,7 +2098,7 @@ static int pl011_verify_port(struct uart_port *port, struct serial_struct *ser) return ret; } -static struct uart_ops amba_pl011_pops = { +static const struct uart_ops amba_pl011_pops = { .tx_empty = pl011_tx_empty, .set_mctrl = pl011_set_mctrl, .get_mctrl = pl011_get_mctrl, @@ -2521,10 +2533,12 @@ static int pl011_resume(struct device *dev) #endif static SIMPLE_DEV_PM_OPS(pl011_dev_pm_ops, pl011_suspend, pl011_resume); +static const struct of_device_id pl011_uart_plat_of_match[]; -static int sbsa_uart_probe(struct platform_device *pdev) +static int pl011_uart_plat_probe(struct platform_device *pdev) { struct uart_amba_port *uap; + struct vendor_data *vendor; struct resource *r; int portnr, ret; int baudrate; @@ -2535,11 +2549,15 @@ static int sbsa_uart_probe(struct platform_device *pdev) */ if (pdev->dev.of_node) { struct device_node *np = pdev->dev.of_node; + const struct of_device_id *of_id = + of_match_device(pl011_uart_plat_of_match, &pdev->dev); ret = of_property_read_u32(np, "current-speed", &baudrate); if (ret) return ret; + vendor = (struct vendor_data *)of_id->data; } else { + vendor = &vendor_sbsa; baudrate = 115200; } @@ -2552,15 +2570,15 @@ static int sbsa_uart_probe(struct platform_device *pdev) if (!uap) return -ENOMEM; - uap->reg_offset = vendor_sbsa.reg_offset; - uap->vendor = &vendor_sbsa; - uap->fifosize = 32; - uap->port.iotype = vendor_sbsa.access_32b ? UPIO_MEM32 : UPIO_MEM; + uap->vendor = vendor; + uap->reg_offset = vendor->reg_offset; + uap->fifosize = vendor->get_fifosize(NULL); + uap->port.iotype = vendor->access_32b ? UPIO_MEM32 : UPIO_MEM; uap->port.irq = platform_get_irq(pdev, 0); - uap->port.ops = &sbsa_uart_pops; + uap->port.ops = vendor->uart_pops; uap->fixed_baud = baudrate; - snprintf(uap->type, sizeof(uap->type), "SBSA"); + snprintf(uap->type, sizeof(uap->type), "PL011 plat"); r = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -2573,7 +2591,7 @@ static int sbsa_uart_probe(struct platform_device *pdev) return pl011_register_port(uap); } -static int sbsa_uart_remove(struct platform_device *pdev) +static int pl011_uart_plat_remove(struct platform_device *pdev) { struct uart_amba_port *uap = platform_get_drvdata(pdev); @@ -2582,11 +2600,12 @@ static int sbsa_uart_remove(struct platform_device *pdev) return 0; } -static const struct of_device_id sbsa_uart_of_match[] = { - { .compatible = "arm,sbsa-uart", }, +static const struct of_device_id pl011_uart_plat_of_match[] = { + { .compatible = "arm,sbsa-uart", .data = &vendor_sbsa }, + { .compatible = "zte,zx296702-uart", .data = &vendor_zte }, {}, }; -MODULE_DEVICE_TABLE(of, sbsa_uart_of_match); +MODULE_DEVICE_TABLE(of, pl011_uart_plat_of_match); static const struct acpi_device_id sbsa_uart_acpi_match[] = { { "ARMH0011", 0 }, @@ -2594,12 +2613,12 @@ static const struct acpi_device_id sbsa_uart_acpi_match[] = { }; MODULE_DEVICE_TABLE(acpi, sbsa_uart_acpi_match); -static struct platform_driver arm_sbsa_uart_platform_driver = { - .probe = sbsa_uart_probe, - .remove = sbsa_uart_remove, +static struct platform_driver pl011_uart_platform_driver = { + .probe = pl011_uart_plat_probe, + .remove = pl011_uart_plat_remove, .driver = { - .name = "sbsa-uart", - .of_match_table = of_match_ptr(sbsa_uart_of_match), + .name = "uart-pl011-plat", + .of_match_table = of_match_ptr(pl011_uart_plat_of_match), .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match), }, }; @@ -2634,14 +2653,14 @@ static int __init pl011_init(void) { printk(KERN_INFO "Serial: AMBA PL011 UART driver\n"); - if (platform_driver_register(&arm_sbsa_uart_platform_driver)) + if (platform_driver_register(&pl011_uart_platform_driver)) pr_warn("could not register SBSA UART platform driver\n"); return amba_driver_register(&pl011_driver); } static void __exit pl011_exit(void) { - platform_driver_unregister(&arm_sbsa_uart_platform_driver); + platform_driver_unregister(&pl011_uart_platform_driver); amba_driver_unregister(&pl011_driver); }