Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6879859ybc; Thu, 28 Nov 2019 07:04:06 -0800 (PST) X-Google-Smtp-Source: APXvYqxzxv4MChmqR/UXZPANLOkiDMixzQ/ynugsAV1qaBOQxkx/qd7ZwJOxHc3wUc5t8K9mHfb/ X-Received: by 2002:ae9:e907:: with SMTP id x7mr7131314qkf.298.1574953445849; Thu, 28 Nov 2019 07:04:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574953445; cv=none; d=google.com; s=arc-20160816; b=fuZX+SiZTtWDe8g8uHoqGAT3/cY3urn0irVSucCCPi3fu7yLdU5AlmzIImowL3q+NS xrc5SCn/9cEhzH00YayInFfVn12Sgc5mPQOXpNaUKweGdGbFPuUF7Kj2BhCasQuacZg7 Ddv5BV417WeV7BxS7MXjN94Ul/Y3N492juf73K89jM5VATgEGoqHLfiqVlxViSVNOJEM Zxu19h8b5e9u2OBJof+brnIb0RZRq6vhgqzlBBKnsd33WRJJQbNG8KZPNwex5hyHSTx5 WbDaVwyrrgloKphe/l7T0wc4Q9FWKZwHVcGFt7LrjkV1LJuS/bt2cBUEV3xgENiY5lPR XMZw== 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=PS8hZ/FNZ5fnmFnMC7wpuYE5CME6gqxRCzSgU7yOKOk=; b=ABneI/CE1cqphI3P/1c9qfTCBvCJwO+AcOmxm4XxJL36F4M/LGk0C8Td5bNFn+xd/S hp5BLdK80RSL6Bf4ueqMg17WwcsXNrABXVptqrrrGRnJ0padftHrU1y3QjzlwcjV8h/u qndwpE/232ILyfmoViN/3sMQw8t00cFGODuWGWEMCLommwkJ3gKxY1GaGCcZyzqsYo8Q duT3xtrW/6n6TzTBw9dK9iTCK3DwMo+mCKpLQBIV1ZAh3FuYh8apqKbPOwsbYB0XpXWa sDYC/LZpOSmn3kr/CezY9/uUTAxLo8AxSNz51u0+O+bLiu5rXzZ7SE5MzXS+MggsbY00 ZRrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Dwl4dqLd; 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 q14si12007962ejt.381.2019.11.28.07.03.40; Thu, 28 Nov 2019 07:04:05 -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=Dwl4dqLd; 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 S1727741AbfK1O7P (ORCPT + 99 others); Thu, 28 Nov 2019 09:59:15 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40713 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727455AbfK1O5q (ORCPT ); Thu, 28 Nov 2019 09:57:46 -0500 Received: by mail-lj1-f195.google.com with SMTP id s22so9822172ljs.7 for ; Thu, 28 Nov 2019 06:57:45 -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=PS8hZ/FNZ5fnmFnMC7wpuYE5CME6gqxRCzSgU7yOKOk=; b=Dwl4dqLdHHKnldphnAGAr1ToN610EqBZwSqoR/hgQSNxfsV/4wXOcOzAUM9uz6FotW 9qwt38QjaaeFHldetsUOgPoIM24I2pCcWdKTSDI7nv8y8op+zapWHlf8st+tVkHCz7P5 bh30cwYMxpmBmbI75/QPPKlSxYLuOhMWYJifE= 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=PS8hZ/FNZ5fnmFnMC7wpuYE5CME6gqxRCzSgU7yOKOk=; b=hzED7cByI7d5fszZoEsrZkcZLuNJIg8Fr33Ri2tm3B66ZcRjqBa9H1HJjQIiyR961Z 33ka12PzcvlHkndphGVGes1kRTl3JTam76po7OvDldSVcmlrMZ88cee0xFeBZyjcV75u H20ngTJUl/vCgC2q32xRxFFdhwQKQyiHZS3hRkrD4ivMBeGUzr3M6rW2/KdFhwdbgyxr RzOoKCTVbpRfBoyAetJAvip4KndNX68I2JHCn1vRQawHjMeqL9GOeSenvmJnCd7kgM0w /Ooryyb1o203SBkC10QGM7F824czqp22I+aG24H6Hn+ON5vmMbnhJhtMItpRHc1Uhq+O N10g== X-Gm-Message-State: APjAAAVA9mocJTKzuYfD/JdwTBiHzvf6S4Bxomk/z00gKm1TTrgpG7gd w/DDSTOHHv0MrsSaGeKk55nOig== X-Received: by 2002:a2e:3e08:: with SMTP id l8mr5147340lja.236.1574953064981; Thu, 28 Nov 2019 06:57:44 -0800 (PST) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id u2sm2456803lfl.18.2019.11.28.06.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 06:57:44 -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 , Timur Tabi , Rasmus Villemoes , linux-serial@vger.kernel.org Subject: [PATCH v6 30/49] serial: ucc_uart: factor out soft_uart initialization Date: Thu, 28 Nov 2019 15:55:35 +0100 Message-Id: <20191128145554.1297-31-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191128145554.1297-1-linux@rasmusvillemoes.dk> References: <20191128145554.1297-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. Reviewed-by: Timur Tabi Acked-by: Timur Tabi 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