Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2482155ybx; Fri, 8 Nov 2019 05:03:56 -0800 (PST) X-Google-Smtp-Source: APXvYqwB8xRzfj/uliagtIiLlFpe+QbIaGO0j4cHBZkPOIcYT/7cDktD8xMn/CE1Be3OLZJjfbBN X-Received: by 2002:a17:906:7c4e:: with SMTP id g14mr8375791ejp.150.1573218235889; Fri, 08 Nov 2019 05:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573218235; cv=none; d=google.com; s=arc-20160816; b=AD/0d/2r6WUwWicruEqIv6bqJAx/sxYT+ppuF0AmHmtuqgkwZBmfJKJZNZ3RglVvIt hAl+JBE4HxAUimrNqY4WU6cz6TBpmgEkcGV8wpw1xLlNvCUJwE7D1SeAjvA0n1YuJbS4 AFva1RGs46KHMw274Kj02xDcFSFvyH5kejEZpVyd56teNRlAcpvbDTn1Bsz4zgct3yaO ex8Gxvcv2m5xEIymjmgho3tgRrGFAj1uY24lcYfah379Z1hkyW1KhgYtph5AFB4bUVvE tTR9eyVRD3d61t2A5RXlu1PiZouNucpo4J/viNXogj4FQ8nGcDgccAqkzVRTP17f8X8c Al0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A4Xv5WoIG3tnGwzAreyDrYqib6OrZF77Ddvl40A6T0E=; b=Qlgcna58a2Fu0UfY7vA3OzqTQuB9cJ+nGwVUbhG4E6cK/zgKg1hUxjU3VKDT0j6dIz ncEykYuVU5vP0x8c3Pol+SDr4+OZu4/X+n8N33oyhTh8aT5CQZhMmfV6SLV2mYZhHVap Da3qOXtTqG31Mb3HdMfBniGVv7kaVVYvxHUwBaRJ9i6RV06dVPWIf3FYbKAIGhu6DPwV usNp3FwNB/7se2aWjvtZLbVXWmfk81tdyDLXK4fq+j0YVpHwpONpeQ0GRJVDoWGXcgI6 nDza7rJWXa6SijhoM/82mhzUDv9BMGrDpmBpBQD8pklWv9sFm6zibhr4RWW3zscqm7TN 53nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=URxmLDTd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y26si4015439edb.360.2019.11.08.05.03.32; Fri, 08 Nov 2019 05:03:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=URxmLDTd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730192AbfKHNCN (ORCPT + 99 others); Fri, 8 Nov 2019 08:02:13 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:40026 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729919AbfKHNCJ (ORCPT ); Fri, 8 Nov 2019 08:02:09 -0500 Received: by mail-lf1-f65.google.com with SMTP id f4so4413268lfk.7 for ; Fri, 08 Nov 2019 05:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A4Xv5WoIG3tnGwzAreyDrYqib6OrZF77Ddvl40A6T0E=; b=URxmLDTdcAq80aCnMhvo9+yxriyxiXCl2huzwXJbiNzXqU4LBIzlQJxwIlqwDb0B6D 4l1aeb0I3lz6KK864Ho3RFQFugG/ukSM1ds9W4OZWaEV8jGHwac3TWVpT/rSftXjdWZi hxoY84qVs4c5q00EAZcnrdRF2IW6X2EmBpgMo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A4Xv5WoIG3tnGwzAreyDrYqib6OrZF77Ddvl40A6T0E=; b=iUw1KqX14q9379SxPzvMtDXI5sTntMUGTR3CuXmcRbHItTk+3Mmgvc7cBYQSi8UzM+ 8lb/4r3YsAGvR9B8zHHujSL9QGzdtCGmTW58xnB+VYqrBAZiLu39+A8hTcI/LusNoEZu vuPggQbK13Q8lM6CdXgNI+mmVG7KjvgS6gxiGUZ3cz3kMbIIj5hQ7d766lbmtfKDvm8m 5Qfi3XUrhOpJeaOVTZ+Gzmjee5rdxZviOqwFi8HRQkt5OlWyepOzzkhNUUWYBNjCCSPf iDBbEcZypiSzyi0mmncO377Hs39SJ/tsZmfOBzL5+OacJ1P9zKGxX8tEGfJJoeeMs+Wd z1/w== X-Gm-Message-State: APjAAAWt1HEwyrj7EK6h8N4FzHBruZx9tgUq7B480B/S1trLTuhyv0VW 7+P3f6mvCloSIKqPjvy7YYrFpQ== X-Received: by 2002:ac2:4a8a:: with SMTP id l10mr6565299lfp.185.1573218126060; Fri, 08 Nov 2019 05:02:06 -0800 (PST) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id d28sm2454725lfn.33.2019.11.08.05.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2019 05:02:05 -0800 (PST) From: Rasmus Villemoes To: Qiang Zhao , Li Yang , Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Scott Wood , Rasmus Villemoes , linux-serial@vger.kernel.org Subject: [PATCH v4 30/47] serial: ucc_uart: factor out soft_uart initialization Date: Fri, 8 Nov 2019 14:01:06 +0100 Message-Id: <20191108130123.6839-31-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191108130123.6839-1-linux@rasmusvillemoes.dk> References: <20191108130123.6839-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "soft uart" mechanism is a workaround for a silicon bug which (as far as I know) only affects some PPC-based SOCs. The code that determines which microcode blob to request relies on some powerpc-specific bits (e.g. the mfspr(SPRN_SVR) and hence also the asm/reg.h header). This makes it a little awkward to allow this driver to be built for non-PPC based SOCs with a QE, even if they are not affected by that silicon bug and thus don't need any of the Soft UART logic. There's no way around guarding those bits with some ifdeffery, so to keep that isolated, factor out the do-we-need-soft-uart-and-if-so-handle-the-firmware to a separate function, which we can then easily stub out for non-PPC. Signed-off-by: Rasmus Villemoes --- drivers/tty/serial/ucc_uart.c | 110 ++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c index 8a378ee5d34f..f286e91714cb 100644 --- a/drivers/tty/serial/ucc_uart.c +++ b/drivers/tty/serial/ucc_uart.c @@ -1183,70 +1183,76 @@ static void uart_firmware_cont(const struct firmware *fw, void *context) release_firmware(fw); } -static int ucc_uart_probe(struct platform_device *ofdev) +static int soft_uart_init(struct platform_device *ofdev) { struct device_node *np = ofdev->dev.of_node; - const unsigned int *iprop; /* Integer OF properties */ - const char *sprop; /* String OF properties */ - struct uart_qe_port *qe_port = NULL; - struct resource res; + struct qe_firmware_info *qe_fw_info; int ret; - /* - * Determine if we need Soft-UART mode - */ if (of_find_property(np, "soft-uart", NULL)) { dev_dbg(&ofdev->dev, "using Soft-UART mode\n"); soft_uart = 1; + } else { + return 0; } - /* - * If we are using Soft-UART, determine if we need to upload the - * firmware, too. - */ - if (soft_uart) { - struct qe_firmware_info *qe_fw_info; - - qe_fw_info = qe_get_firmware_info(); - - /* Check if the firmware has been uploaded. */ - if (qe_fw_info && strstr(qe_fw_info->id, "Soft-UART")) { - firmware_loaded = 1; - } else { - char filename[32]; - unsigned int soc; - unsigned int rev_h; - unsigned int rev_l; - - soc = soc_info(&rev_h, &rev_l); - if (!soc) { - dev_err(&ofdev->dev, "unknown CPU model\n"); - return -ENXIO; - } - sprintf(filename, "fsl_qe_ucode_uart_%u_%u%u.bin", - soc, rev_h, rev_l); - - dev_info(&ofdev->dev, "waiting for firmware %s\n", - filename); + qe_fw_info = qe_get_firmware_info(); - /* - * We call request_firmware_nowait instead of - * request_firmware so that the driver can load and - * initialize the ports without holding up the rest of - * the kernel. If hotplug support is enabled in the - * kernel, then we use it. - */ - ret = request_firmware_nowait(THIS_MODULE, - FW_ACTION_HOTPLUG, filename, &ofdev->dev, - GFP_KERNEL, &ofdev->dev, uart_firmware_cont); - if (ret) { - dev_err(&ofdev->dev, - "could not load firmware %s\n", - filename); - return ret; - } + /* Check if the firmware has been uploaded. */ + if (qe_fw_info && strstr(qe_fw_info->id, "Soft-UART")) { + firmware_loaded = 1; + } else { + char filename[32]; + unsigned int soc; + unsigned int rev_h; + unsigned int rev_l; + + soc = soc_info(&rev_h, &rev_l); + if (!soc) { + dev_err(&ofdev->dev, "unknown CPU model\n"); + return -ENXIO; + } + sprintf(filename, "fsl_qe_ucode_uart_%u_%u%u.bin", + soc, rev_h, rev_l); + + dev_info(&ofdev->dev, "waiting for firmware %s\n", + filename); + + /* + * We call request_firmware_nowait instead of + * request_firmware so that the driver can load and + * initialize the ports without holding up the rest of + * the kernel. If hotplug support is enabled in the + * kernel, then we use it. + */ + ret = request_firmware_nowait(THIS_MODULE, + FW_ACTION_HOTPLUG, filename, &ofdev->dev, + GFP_KERNEL, &ofdev->dev, uart_firmware_cont); + if (ret) { + dev_err(&ofdev->dev, + "could not load firmware %s\n", + filename); + return ret; } } + return 0; +} + +static int ucc_uart_probe(struct platform_device *ofdev) +{ + struct device_node *np = ofdev->dev.of_node; + const unsigned int *iprop; /* Integer OF properties */ + const char *sprop; /* String OF properties */ + struct uart_qe_port *qe_port = NULL; + struct resource res; + int ret; + + /* + * Determine if we need Soft-UART mode + */ + ret = soft_uart_init(ofdev); + if (ret) + return ret; qe_port = kzalloc(sizeof(struct uart_qe_port), GFP_KERNEL); if (!qe_port) { -- 2.23.0