From patchwork Tue Jan 16 13:47:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 124702 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1020606lje; Tue, 16 Jan 2018 05:52:02 -0800 (PST) X-Google-Smtp-Source: ACJfBotGT/F0bEMG5ZZhHmuAR5kz307XgUb6fsTTvf0QvggB343hPVyRZRfMFcUIXy8Rkcu1D2Zu X-Received: by 10.80.165.180 with SMTP id a49mr30435383edc.79.1516110722169; Tue, 16 Jan 2018 05:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516110722; cv=none; d=google.com; s=arc-20160816; b=XB+9oMwIjmmpTTIAbCflH45HzDRywXlhSc/CUDgQ8WYvsAEWYOL3jtVhgtHiXMWAgU oMxH8Sq+w+h1ruTApXL3Jcr7v+B85WMBDPpKBho6V9i14RokBE7yKmW6d6yNDEQ1L9wS 1MZl8xlxVEqjP9sgV3JfuKOk/npIuKdGdKdZTmos95mjgbVczzPyNkRmv48XCGNTZyCy wlTr/huqqY8mq47OmoQaWrMkAUBsPb5OtATrkyrGVHxYlS2YspFJAzFbpqId3o9++ydb 7q7lz325pLIQHP7qtrmk2ZkIObpt3Nl7GdsIKyPpa/Ra9iey708uVpvbeDHp6f66wyzS Rtqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:arc-authentication-results; bh=lgTVubtFZyct4UncXXkgNczrVP2SVw6RC3sxouxiV5U=; b=paMiY96VoPrb21EXdnyc7dIGK6bDc89p4QbbIwTfl4j3it1DsNxpNXWd3R7lqqdXUz rBQ9rG76nklXTzF8JjqxKqJ1kvo+WqU24TXiHmu1OjqWk3VRIqi0k10RN+C7WvEww39J ykW4bGEwXiALHllvv+oKTnCU+ukDIUR2EhxAqa7LhIB8n9+xO6mgokG8Fa3UYaqT/9Gg ZX5sMiMbMxWFuX/ypwA46cSjtteftiRNSKYJ8LI7gHb6Lzf2fjqBZd4Qz+d3IXpij3i4 T6p85mkr6OLPHhoj2gmAt5YrCZLXsZ1kXzyqXXh6jvStH9Gxry/X8q3S4iiRBc9UMtus PoKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id w51si2316235edb.141.2018.01.16.05.52.01; Tue, 16 Jan 2018 05:52:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id BD9AFC21DA6; Tue, 16 Jan 2018 13:50:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id F20D6C21DFA; Tue, 16 Jan 2018 13:48:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D967EC21E1E; Tue, 16 Jan 2018 13:47:56 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 95438C21E16 for ; Tue, 16 Jan 2018 13:47:42 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5E6F4AD0F; Tue, 16 Jan 2018 13:47:42 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Tue, 16 Jan 2018 14:47:39 +0100 Message-Id: <20180116134741.4103-6-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180116134741.4103-1-agraf@suse.de> References: <20180116134741.4103-1-agraf@suse.de> Subject: [U-Boot] [PATCH 5/7] rpi: Properly detect which serial device is active X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Now that we have all infrastructure in place to dynamically determine whether a serial device is actually usable (read: routed to user accessible pins), we can wire it up to the board. This patch adds support to determine whether the pl011 or mini-uart or no serial is routed to the UART RX/TX pins on the Raspberry Pi family of boards. Signed-off-by: Alexander Graf --- board/raspberrypi/rpi/rpi.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c index a96d5d8952..b0cdad70f7 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -24,9 +24,16 @@ #include #endif #include +#include DECLARE_GLOBAL_DATA_PTR; +/* + * This is the GPIO pin that the user facing UART RX line is attached to. + * We use this pin to determine which serial device is available. + */ +#define BCM2835_GPIO_RX 15 + /* From lowlevel_init.S */ extern unsigned long fw_dtb_pointer; @@ -419,6 +426,68 @@ static void get_board_rev(void) printf("RPI %s (0x%x)\n", model->name, revision); } +/* + * We may get called before the device model is initialized, so we can not + * rely on the GPIO driver. + */ +int get_func_id(unsigned gpio) +{ + u32 val; + u32 node; + u32 *gpfsel; + fdt_addr_t addr; + fdt_size_t size; + + node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "brcm,bcm2835-gpio"); + if (node < 0) + return -EINVAL; + + addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, node, "reg", + 0, &size, true); + gpfsel = (void*)addr; + + val = readl(&gpfsel[BCM2835_GPIO_FSEL_BANK(gpio)]); + + return (val >> BCM2835_GPIO_FSEL_SHIFT(gpio) & BCM2835_GPIO_FSEL_MASK); +} + + +/* + * The RPi has 2 serial ports: A PL011 based one and the mini-uart. + * Depending on firmware configuration, either can be configured to either + * nothing, the wifi adapter or serial output. + * + * We only want to use the serial port that is user facing to not + * end up with a potentially unresponsive serial port. Due to this + * we need to check whether the serial device is actually connected + * to the UART RX/TX pins on the RPi GPIO pin bar. + * + * We only allow U-Boot to instantiate the serial driver for the serial + * device that is muxed correctly. + */ +int board_check_serial(struct udevice *dev) +{ + int func; + + printf("Checking serial %s\n", dev->name); + + if (device_is_compatible(dev, "arm,pl011")) { + func = BCM2835_GPIO_ALT0; + } else if (device_is_compatible(dev, "brcm,bcm2835-aux-uart")) { + func = BCM2835_GPIO_ALT5; + } else { + return 0; + } + + if (get_func_id(BCM2835_GPIO_RX) != func) { + printf("Disabling serial %s\n", dev->name); + return -ENODEV; + } + + printf("Enabling serial %s\n", dev->name); + return 0; +} + int board_init(void) { #ifdef CONFIG_HW_WATCHDOG