Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp424324ybx; Fri, 1 Nov 2019 05:45:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYviCiwydoy0rFs2sZLB4mGQwnuNNnLpS8G/0YfhnYo1Drn17GZWHTkTHqVQ7Ib/TeT8Ig X-Received: by 2002:a17:906:6942:: with SMTP id c2mr9328757ejs.152.1572612314379; Fri, 01 Nov 2019 05:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572612314; cv=none; d=google.com; s=arc-20160816; b=BL4+YE4TtJqCjanvmmtxWLQ1G0A3byIJkc6CLdeDA3D3iJ7oRPt6P1TJUXK2Sgdqsg xmcnPqKv6GP1vGfxdqJLNHJ3c4YEEmeC8Scq7uBPNUB0iQ2FqHK1eZKP+sSpj5pVUOde QomguWkI6MROphPsm+kN5o5vRnJymNIjdmnw4+PbH6oo+u71PNn2NuOOOmzoLyY9584N I/pfOy/9Lq96KzC7f1MHVMmmGZGtHp0XlzkNqj2uinEmhfBLzrdsSDkb+g5wbIYA+LNZ O4MRpSFwqgINWR87XVORENRYoCXxDXHIl3+QaIixeRKpBu7/4Fnv5odEmqZht22cJxNe KMJQ== 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=ozz0Qru3WaO/ppuOL2ONTzHoeZo54gIRm33oTPOSYwBJj6NX1UldDBdZ6ve6GqRqWP RadaWwkBrCRUsIS7YkP5KyYlpnNeRza+KJ6AfYEm1Ky0UmuZHgLhXC+K58+2DbUn1wbL eqLWcYjO1SKVXEzkcFs/GiEus2G7BnIcRZg22x0lwCv0kbA5wdh8928RtePHrm9GVMST li194OBfiTCUYumPE2U3xDx3wypAVnpNaKOzWQGZxfmOi1mMXMVNqWioqmqyqhySre4Q CZPq1Sda2NMF30F1jOU+s+xcIydlltxjqTfjD/aUeh4VCFknIEWrYRc9+zCzeaLyGZLB CTMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=JlyPeQVc; 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 m17si5720387eja.415.2019.11.01.05.44.51; Fri, 01 Nov 2019 05:45:14 -0700 (PDT) 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=JlyPeQVc; 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 S1730892AbfKAMnW (ORCPT + 99 others); Fri, 1 Nov 2019 08:43:22 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37585 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730797AbfKAMmy (ORCPT ); Fri, 1 Nov 2019 08:42:54 -0400 Received: by mail-lj1-f194.google.com with SMTP id v2so10130058lji.4 for ; Fri, 01 Nov 2019 05:42:52 -0700 (PDT) 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=JlyPeQVcsCkn6meA+ft/u91froZy6pUJF8+frfj7p47K+TzysfloPqSKcKSWfUZVto akAMuL5TH0SelqXLgcKmhUMxAkYxiIKlZdanQjq1oOy4UpHTwZIW9Lrde31GRRCh3oD7 dKUMvxnfbKDVK6COMfIfpfg4KVLwutVYRu058= 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=WNLRK7hprvWSIfbKNIi976ZrbT9HUSsNVOMbnS7kKNMxTSdLW6/DTwxGkGXBFGGiEy ztKMEUezCWKivXu3rxs3/JzjmvTv6jomIgMQeCJyfp5VGxsj3fxGRW4HE6YqryTbIh6y uqLCD/O1cdBG6jM1qrVQSQ2CkknoBt17+h9abMZP3pPO1SrPckauYpEPibSlxfEioR5B 9V/xO0MBOCBRiKTCjinQ3RH3ImKBZ7R1j84vcQ9G6l+BM5uKCCjiP5kfU2XGAyjXeq3V HvDNa6GTYwGuukoYIoHJoMwTC1HuH2YewRWmshd1Tetlp6WGE0TNpNiB/ZosqY9agivd Zvpw== X-Gm-Message-State: APjAAAVUzBSO+oELwu2i49W/G8T/E5vYzNLMhIyH/qs34nlvMjdcDmKK JbhmbHOpujS+o5juGiUiQjtkpg== X-Received: by 2002:a2e:2903:: with SMTP id u3mr8372560lje.131.1572612171901; Fri, 01 Nov 2019 05:42:51 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id o26sm2458540lfi.57.2019.11.01.05.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2019 05:42:51 -0700 (PDT) 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 v3 30/36] serial: ucc_uart: factor out soft_uart initialization Date: Fri, 1 Nov 2019 13:42:04 +0100 Message-Id: <20191101124210.14510-31-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191101124210.14510-1-linux@rasmusvillemoes.dk> References: <20191018125234.21825-1-linux@rasmusvillemoes.dk> <20191101124210.14510-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