Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1055569pxb; Tue, 8 Feb 2022 08:18:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfWEXNepAkI3T7am/bPbvjnyaVmgqsCrNZaw52Mgh8gYcjyJQ6Irv/GVVY+PomkkT8qdn8 X-Received: by 2002:a17:902:ef49:: with SMTP id e9mr4952107plx.56.1644337084268; Tue, 08 Feb 2022 08:18:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644337084; cv=none; d=google.com; s=arc-20160816; b=By8TJlW0IZ55ZTAYfYnNQdpvUkAEhr1a0p5rvTUR9dnvp1uzMnebeKInNxO/81RvY0 b623TS7IAZOTtHjStRVNO2CMAbI85fNNyj+tMwYdT3bZ81tb2ohRfOTuBvQFUMov03FR idPoNDqeR7c8ufoBYK8J0LBA0HZ8CBJUuVW8nPEDEh8EO35WCwXbh4QDMeGqb3OaDyVN 3ZU/LqEWR8f066cqHWobouXLtDftrlfzw1MLvY7Cg+BWj21mD4Dtr/a0k0injfZDziFc NiX6nGF8BZt4BkTZPS6qEH5/dv/epQE4+OQZM7TItlN52bE8x5X79bISYZ51edb7ROzo qPsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Iw9wt34aXKvuMxoYZcgwMJfoVHqXFAcM6CtavfIfEfU=; b=Ebl8WVkBgsMqb/ddCZKai667BLKlKax6zvEbQumlXVXy1hHBr0e2c/hwRU100LlpU8 0nJEZVHNlDHnITCOu+UdgWFNwCuVlEZRdPpfKb+LNUtPGg5y0aqrxv7M0iheZs8SjOpn 4kcB619zvc/osgn50haT9NgyUKbhJeNjCrIDUqh2rYi8wjNLqSJt1XHkwZAU511DAPvi eiDB6OBvwrE9+rchujzb03tbyu+KSs2oe+afef/FGs8ZAZ0IFD/ctq4bPdO/EMDtgiXS YkAt/MLlvmjaJlIx53zBUklYC7DET7GT4uNJF7aQoU+Mt312vKxZwaox/0O5n65ewNel M5Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FtKsJjEE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x22si15455265pgk.297.2022.02.08.08.17.48; Tue, 08 Feb 2022 08:18:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FtKsJjEE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345118AbiBHBEa (ORCPT + 99 others); Mon, 7 Feb 2022 20:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240468AbiBGXWA (ORCPT ); Mon, 7 Feb 2022 18:22:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 49F79C061355 for ; Mon, 7 Feb 2022 15:21:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644276118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Iw9wt34aXKvuMxoYZcgwMJfoVHqXFAcM6CtavfIfEfU=; b=FtKsJjEEkdrpKxHaHXlWkTpg7Ie/MDEM4hFZqMW9DqTIntJhK2HyOz8M8M3wxwyynurYwR Nff+R7rrlFGeUOwT0YU8yIpxGYY6K5LqRv0JG8ThWHsY0TcVs+B4j2ozIfuNStvWIICaoN 01ctCY5HeRnMVstWOrC8LnXwHPQ5bow= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-9CfCEObdOymLaN9fMMgv0w-1; Mon, 07 Feb 2022 18:21:57 -0500 X-MC-Unique: 9CfCEObdOymLaN9fMMgv0w-1 Received: by mail-qk1-f200.google.com with SMTP id x16-20020a05620a449000b00508582d0db2so5257029qkp.0 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=teOJuvq9QQqRpkWuN7wDxr6mhC/ANpVl2bF0vsrkFkx0irqy2aJY1i0BKfdEzgnDhf g31QOUb2MJ6nYWpyFqpyz9i66guw40xeA+CVPAOdOZnOiAaacsXQqtnz0mqnUlD5OoKy G/T+HbOYSl1xPX67kmizYPEVOBVzStq8f4ssnOy2HPPzOA8f5nKa74C8MFp59T32+AeY /uKz/0hufI56aVDQTP05+91Dx4aCLX/DvT8UuF/GXBxYQ46ME4/uF05Zxy0IyGNrr2Uv RcqI9KR2LtHlRFJ8w5gR4fow2DXwb/cwqPpzfFfyFmd+ey8/NhE4YuAlGqPrnQWSYH4F 3zkg== X-Gm-Message-State: AOAM532g+OiAsb6NZZOrzSOtrPVww0HLzY1sXm/ZFTFx1DdpylQTaUL9 avCAk0NEDv7XHj5k8aN4t0yk1Fz0THj4k+MIawyFHvH4cN+R/M7MgM/fkxptPDlr36AVlmoz9sh UlElJ5LGj3eqgeckThtorgXkd X-Received: by 2002:ad4:5ce7:: with SMTP id iv7mr1363045qvb.121.1644276116278; Mon, 07 Feb 2022 15:21:56 -0800 (PST) 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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(-) 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, base-commit: 2ade8eef993c37a2a43e51a9b1f6c25509a2acce -- 2.34.1