Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1508389pxb; Wed, 2 Feb 2022 06:35:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzzbRdjGiCeItqTHliunM/a1jnkNkP37OWLOV67Mw5j8RYHcQ2mEHaQ0/Y2zXB5tsU73nZ X-Received: by 2002:a17:90a:2fc5:: with SMTP id n5mr8341158pjm.69.1643812499986; Wed, 02 Feb 2022 06:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643812499; cv=none; d=google.com; s=arc-20160816; b=shmshZGJAqhum1VmZRe12WGz055pC43TvPNBm15KlTg2SiBuMgh9yOV7tZdwF1BRfT vMInH5uRFFTacVwulelfHI6YLA6A5lvbal18vq9LoRzyHQQ1z1EWShGNu1T/XatnNuto cvQbUS9ap2J5rgHGrzssLgJOgpnosyng7RlU2YfqWhA+A/v0RKW1XygxAl05bsMC9vQ4 xQy8tW/DgH0O8pGSS7dpfnz88q738xEOTFYkvE26NAkUtxVtxSY46a3/K2hkXCZcF+jN hoibwy1Vj9q5fk40aPF+yHLJMrHOZERO23QlIxHWs/7wvrA+I79/uyycLQid4TPo2Ix4 CZPg== 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=CXMEPCO/uu0dla1c1qYh6jAoya9d0BWMm4xi0Tv2h6E=; b=X6mXFdBduoYlxIsCkJip9H2KwqZ5Gxh2h6fjtgXtxpNtr3hOxGTcATrtnX9Z78l9dB gq49nCeweH2obkDVIcb4LuoWPVwyRoAe8r+FzqJPNxwLV5NjqQ2o6QChCSVA5cF6wZIu f1B7h8tI87zhTdY6C0OwcK3Poz3epJuorzQhRcI9xflUL20ZliFdCZ4d9ZsC9RTEl4j5 D/8JAq3uFsnMNoSbcCiS1OCuTiasAjUBTcb7S1jpxa1VLYGFwQcu0aIoE7kCD5JwM9/I agdqFUX6Vhqi4j3lZgpJbP1UEXVFiOT6cD/rSh02WVILLvSbSIs0wIJ/NgWbtcsse9sW GrqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K6DtNxVT; 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 k6si19878445pgr.673.2022.02.02.06.34.46; Wed, 02 Feb 2022 06:34:59 -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=K6DtNxVT; 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 S241927AbiBASu5 (ORCPT + 99 others); Tue, 1 Feb 2022 13:50:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27634 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbiBASu4 (ORCPT ); Tue, 1 Feb 2022 13:50:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643741455; 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=CXMEPCO/uu0dla1c1qYh6jAoya9d0BWMm4xi0Tv2h6E=; b=K6DtNxVTWRUq3slM6JRAzQcR0TTol5eER6IvAp3JfcuCwFWn2AL6nelF+xAtOSz43A86Il vrF3F5QXK6LEGTPjBwUWsR1heL6E8YlPw9PWg6VP9kdp58DINdXF8rbnJJniSH0eaRkQEI Z9kHT3jyqgKpoBD4xZdXXTCENkH7Uis= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-326-u83wDGirPWCbKuSqOIw8XQ-1; Tue, 01 Feb 2022 13:50:54 -0500 X-MC-Unique: u83wDGirPWCbKuSqOIw8XQ-1 Received: by mail-qv1-f72.google.com with SMTP id r12-20020a0562140c8c00b004226c4fc035so16771809qvr.4 for ; Tue, 01 Feb 2022 10:50:54 -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=CXMEPCO/uu0dla1c1qYh6jAoya9d0BWMm4xi0Tv2h6E=; b=ixXX8R4TrkLyN8oXGNeb1SJTQNzLxrhWqpYc7seEPqVHBmjlJk7TKy2thY9AcQ8rUy Ltz8iKRjcC6do7kY9S4C231eWkjsM7eH6gR71mcAVyt0IEmUYPTdZsvkt5YN2I4Nu7EI 3NXx39Wb+rk6GjUQMEDT4Bji0+PVSeRjJUSFw1ViuMmDQRdsE7q+7DKJGUjaUSH840En aMnBcNxyADNMliY82+HdhycsiZS3c/dIvGiG7y3j8HjUbFuhmuMLGXQgD7KElf1QSqfn r+/B1Wdw49EXGiHona5gZ+43i+Kr9yTTpf18ZojkaVhx6p+VK4Qv5m+OOUNViQBAOQd1 asOw== X-Gm-Message-State: AOAM532V3miRUT0B2XSfRqaSOtPqSyrkLj5gSQ/6IK+mxBGVTjSmt04u PB5SxzhSwLkx+N6ndVwZqXVpj5k3pfFIrlv0ohE/CULe1SfBALGPqJLttmLLIJZ06cAVj1iq8BD CJmhDmLfCKF0BQ+NyMNUYoARk X-Received: by 2002:a05:620a:2802:: with SMTP id f2mr16767625qkp.507.1643741453755; Tue, 01 Feb 2022 10:50:53 -0800 (PST) X-Received: by 2002:a05:620a:2802:: with SMTP id f2mr16767612qkp.507.1643741453530; Tue, 01 Feb 2022 10:50:53 -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 w22sm6225383qtk.7.2022.02.01.10.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 10:50:53 -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] serial: 8250_bcm2835aux: Add ACPI support Date: Tue, 1 Feb 2022 13:50:01 -0500 Message-Id: <20220201185001.926338-1-athierry@redhat.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- drivers/tty/serial/8250/8250_bcm2835aux.c | 103 +++++++++++++++++----- 1 file changed, 83 insertions(+), 20 deletions(-) diff --git a/drivers/tty/serial/8250/8250_bcm2835aux.c b/drivers/tty/serial/8250/8250_bcm2835aux.c index fd95860cd..b904b321e 100644 --- a/drivers/tty/serial/8250/8250_bcm2835aux.c +++ b/drivers/tty/serial/8250/8250_bcm2835aux.c @@ -12,6 +12,7 @@ * simultaneously to rs485. */ +#include #include #include #include @@ -44,6 +45,10 @@ struct bcm2835aux_data { u32 cntl; }; +struct bcm2835_aux_serial_acpi_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)) { @@ -82,8 +87,12 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) { struct uart_8250_port up = { }; struct bcm2835aux_data *data; + struct bcm2835_aux_serial_acpi_driver_data *acpi_data; struct resource *res; int ret; + resource_size_t mapbase; + resource_size_t mapsize; + unsigned int uartclk; /* allocate the custom structure */ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); @@ -108,10 +117,12 @@ 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"); + if (dev_of_node(&pdev->dev)) { + /* 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"); + } /* get the interrupt */ ret = platform_get_irq(pdev, 0); @@ -125,20 +136,59 @@ 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); - - /* Check for a fixed line number */ - ret = of_alias_get_id(pdev->dev.of_node, "serial"); - if (ret >= 0) - up.port.line = ret; - - /* enable the clock as a last step */ - ret = clk_prepare_enable(data->clk); - if (ret) { - dev_err(&pdev->dev, "unable to enable uart clock - %d\n", - ret); - return ret; + + mapbase = res->start; + mapsize = resource_size(res); + + if (has_acpi_companion(&pdev->dev)) { + const struct acpi_device_id *match; + + match = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); + if (!match) + return -ENODEV; + + acpi_data = (struct bcm2835_aux_serial_acpi_driver_data *)match->driver_data; + + /* 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. + */ + up.port.mapbase = mapbase + acpi_data->offset; + up.port.mapsize = mapsize - acpi_data->offset; + } else { + up.port.mapbase = mapbase; + up.port.mapsize = mapsize; + } + + if (dev_of_node(&pdev->dev)) { + /* Check for a fixed line number */ + ret = of_alias_get_id(pdev->dev.of_node, "serial"); + if (ret >= 0) + up.port.line = ret; + + /* enable the clock as a last step */ + ret = clk_prepare_enable(data->clk); + if (ret) { + dev_err(&pdev->dev, "unable to enable uart clock - %d\n", + ret); + return ret; + } + + uartclk = clk_get_rate(data->clk); + + + } else { + ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk); + if (ret) { + dev_err(&pdev->dev, "unable to get clock frequency\n"); + return ret; + } } /* the HW-clock divider for bcm2835aux is 8, @@ -146,7 +196,7 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) * 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); @@ -159,7 +209,9 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev) return 0; dis_clk: - clk_disable_unprepare(data->clk); + if (dev_of_node(&pdev->dev)) + clk_disable_unprepare(data->clk); + return ret; } @@ -173,16 +225,27 @@ static int bcm2835aux_serial_remove(struct platform_device *pdev) return 0; } +static const struct bcm2835_aux_serial_acpi_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: 26291c54e111ff6ba87a164d85d4a4e134b7315c -- 2.34.1