From patchwork Mon Feb 7 23:21:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Thierry X-Patchwork-Id: 12737951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA7AAC433F5 for ; Mon, 7 Feb 2022 23:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ppauyoyNLYxktMhHQwVJ93fmpE7bLlm4GAEoIt0xD9A=; b=QI6DPXdoSkX4Zh zYPCYkupPiUgjldcA4MQSW4+UjJ6Zjmeu4Wyk8+DpR0Mq/+3XaBSoCEaDlIcH/AngYDha8csJkNOx mVDSrMAkqt1ubStxRLxbwRaLetihXnsZg+4rYyhNEczTr+v2yyUn5xwC28H1VtechPb1SpmT3DbQl xluA9/fuLEF2zr2Das5pPtCIj9onsWC/cq0Z1te5gNmGk/AUMyensrHyTh0NykZLU/ALNmHIotIIW 1hgQtlkn9w0AB6W/om8/crLIjd5ch+piOHvxbws2sTwTbKD/eR16tTHYj3kSRzVTdHKzW/wyQ6vCy 531WnBtpksB3XdrHrzig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHDKq-00BxY2-PD; Mon, 07 Feb 2022 23:22:16 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHDKk-00BxVE-Lz for linux-arm-kernel@lists.infradead.org; Mon, 07 Feb 2022 23:22:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644276120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Iw9wt34aXKvuMxoYZcgwMJfoVHqXFAcM6CtavfIfEfU=; b=apDP0H/qA7Kqn0tdHdWWs9ceUwEZfvRBUKQZeAdbfHtBGMN0k5Qn7fhx5xo1MX5n66ekde YpKwdsTvhH2WbaOST0YBIjGl8AE0DLnKT6P//TPqyjr1Wqd+o7xCxeecPgWwdcA/QDAfIM qOPGmh6mTq4o+4TXGgmv6Uuch7xWb0s= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-CxLsvKW3P4SuCqArps0E2w-1; Mon, 07 Feb 2022 18:21:57 -0500 X-MC-Unique: CxLsvKW3P4SuCqArps0E2w-1 Received: by mail-qk1-f197.google.com with SMTP id g3-20020a05620a108300b0047e16fc0d6cso9764958qkk.3 for ; Mon, 07 Feb 2022 15:21:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Iw9wt34aXKvuMxoYZcgwMJfoVHqXFAcM6CtavfIfEfU=; b=3PHLGSpHxgm3EBz90ghddpIaPL5G9FVD4Hpln/rxlCzppifq1qhKy312wba8JS3HfN kKWtWeCJ3vtB+Kvvcf3/KUA8Ayr9DoYVSJtGXZOtQCrcMfVd/gNOVg1vVFR+88TVuPB5 1Y5XagA7Y6sKiQuAW1csNFGXCUEqTMm0ntsMIs1QDmY0nylH1QsOWW5H3bjSafavbP1f ThSWZGgbhWCM2VezQrm1Z2nlcO7Oc1eL88KA2yfC8wWolme+n7U9glhcxPK+s2Pt0UR1 3tuis4P4ZeoVdrhmkgpuLHz+bRbiEitIZmaP2mT6iQwjNibSAyTXXOyECERJJUeRdRIA Rs+Q== X-Gm-Message-State: AOAM533ncaHzX6cRjJ/wig+0I603ik1ZAcSrfIVXTzegYsNVZoRLkoGn TJm8s5iWzQvZSlNtGA7wHpQyYutn4Lwx2KTu0OPe0tvzyJprukRcL6Wqt2IhV4PuXBcHeeA/UXc XocMvpI8v/mDSK6B0BZKZ4Pjg5DHqaUH2dRM= X-Received: by 2002:ad4:5ce7:: with SMTP id iv7mr1363060qvb.121.1644276116412; Mon, 07 Feb 2022 15:21:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1NtXQcsm5FW3EBilz/ZfT3Cvi3lIDzaSf3isXw3sfYe4piCqut0wV1cRBs/K/pJ1jR71oUg== X-Received: by 2002:ad4:5ce7:: with SMTP id iv7mr1363030qvb.121.1644276116076; Mon, 07 Feb 2022 15:21:56 -0800 (PST) Received: from fedora.hitronhub.home (modemcable200.11-22-96.mc.videotron.ca. [96.22.11.200]) by smtp.gmail.com with ESMTPSA id y2sm5906567qke.33.2022.02.07.15.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 15:21:55 -0800 (PST) From: Adrien Thierry To: linux-serial@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Adrien Thierry , Jeremy Linton , Greg Kroah-Hartman , Jiri Slaby , Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com Subject: [PATCH v3] serial: 8250_bcm2835aux: Add ACPI support Date: Mon, 7 Feb 2022 18:21:29 -0500 Message-Id: <20220207232129.402882-1-athierry@redhat.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=athierry@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220207_152210_889045_5D029F6D X-CRM114-Status: GOOD ( 25.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add ACPI support to 8250_bcm2835aux driver. This makes it possible to use the miniuart on the Raspberry Pi with the tianocore/edk2 UEFI firmware. Signed-off-by: Adrien Thierry Reviewed-by: Florian Fainelli Tested-by: Jeremy Linton --- V1 -> V2: Refactored code to remove unnecessary conditional paths and intermediate variables V2 -> V3: Cleaned up coding style and addressed review comments drivers/tty/serial/8250/8250_bcm2835aux.c | 52 ++++++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) base-commit: 2ade8eef993c37a2a43e51a9b1f6c25509a2acce diff --git a/drivers/tty/serial/8250/8250_bcm2835aux.c b/drivers/tty/serial/8250/8250_bcm2835aux.c index fd95860cd661..2a1226a78a0c 100644 --- a/drivers/tty/serial/8250/8250_bcm2835aux.c +++ b/drivers/tty/serial/8250/8250_bcm2835aux.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "8250.h" @@ -44,6 +45,10 @@ struct bcm2835aux_data { u32 cntl; }; +struct bcm2835_aux_serial_driver_data { + resource_size_t offset; +}; + static void bcm2835aux_rs485_start_tx(struct uart_8250_port *up) { if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) { @@ -80,9 +85,12 @@ static void bcm2835aux_rs485_stop_tx(struct uart_8250_port *up) static int bcm2835aux_serial_probe(struct platform_device *pdev) { + const struct bcm2835_aux_serial_driver_data *bcm_data; struct uart_8250_port up = { }; struct bcm2835aux_data *data; + resource_size_t offset = 0; struct resource *res; + unsigned int uartclk; int ret; /* allocate the custom structure */ @@ -109,9 +117,7 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); /* get the clock - this also enables the HW */ - data->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(data->clk)) - return dev_err_probe(&pdev->dev, PTR_ERR(data->clk), "could not get clk\n"); + data->clk = devm_clk_get_optional(&pdev->dev, NULL); /* get the interrupt */ ret = platform_get_irq(pdev, 0); @@ -125,8 +131,24 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) dev_err(&pdev->dev, "memory resource not found"); return -EINVAL; } - up.port.mapbase = res->start; - up.port.mapsize = resource_size(res); + + bcm_data = device_get_match_data(&pdev->dev); + + /* Some UEFI implementations (e.g. tianocore/edk2 for the Raspberry Pi) + * describe the miniuart with a base address that encompasses the auxiliary + * registers shared between the miniuart and spi. + * + * This is due to historical reasons, see discussion here : + * https://edk2.groups.io/g/devel/topic/87501357#84349 + * + * We need to add the offset between the miniuart and auxiliary + * registers to get the real miniuart base address. + */ + if (bcm_data) + offset = bcm_data->offset; + + up.port.mapbase = res->start + offset; + up.port.mapsize = resource_size(res) - offset; /* Check for a fixed line number */ ret = of_alias_get_id(pdev->dev.of_node, "serial"); @@ -141,12 +163,19 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) return ret; } + uartclk = clk_get_rate(data->clk); + if (!uartclk) { + ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk); + if (ret) + return dev_err_probe(&pdev->dev, ret, "could not get clk rate\n"); + } + /* the HW-clock divider for bcm2835aux is 8, * but 8250 expects a divider of 16, * so we have to multiply the actual clock by 2 * to get identical baudrates. */ - up.port.uartclk = clk_get_rate(data->clk) * 2; + up.port.uartclk = uartclk * 2; /* register the port */ ret = serial8250_register_8250_port(&up); @@ -173,16 +202,27 @@ static int bcm2835aux_serial_remove(struct platform_device *pdev) return 0; } +static const struct bcm2835_aux_serial_driver_data bcm2835_acpi_data = { + .offset = 0x40, +}; + static const struct of_device_id bcm2835aux_serial_match[] = { { .compatible = "brcm,bcm2835-aux-uart" }, { }, }; MODULE_DEVICE_TABLE(of, bcm2835aux_serial_match); +static const struct acpi_device_id bcm2835aux_serial_acpi_match[] = { + { "BCM2836", (kernel_ulong_t)&bcm2835_acpi_data }, + { } +}; +MODULE_DEVICE_TABLE(acpi, bcm2835aux_serial_acpi_match); + static struct platform_driver bcm2835aux_serial_driver = { .driver = { .name = "bcm2835-aux-uart", .of_match_table = bcm2835aux_serial_match, + .acpi_match_table = bcm2835aux_serial_acpi_match, }, .probe = bcm2835aux_serial_probe, .remove = bcm2835aux_serial_remove,