From patchwork Wed Jun 14 08:29:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9785759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DEBD60325 for ; Wed, 14 Jun 2017 08:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23BDA285C9 for ; Wed, 14 Jun 2017 08:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1868D285D2; Wed, 14 Jun 2017 08:30:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA901285C9 for ; Wed, 14 Jun 2017 08:30:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ta/WPt3zLWkPmWn9VuM6s8nGYRPFqoa/vdrCHLpPr1w=; b=ftQ3/CfXCQd24mc8ZY28m3ifRb B2FpF8cYAFB/fJlQXfY47LrdxwUypFDRws1q6yHrJLoeauY9oi4mrnY80OLEkWllunPzFb9nZzwKV mzMQeWHrCoOQJ2tE1397KhXLoCZsNZbzWMetWn6GoVJ4nqrQ1eCh5lbi8yKhC/m9bzH5O6I7KiErL NUgVo6UrH9ht9i4G0a3xeROifCcw7i7vmOmLGRwSNzoL5lbZN92Ak4OBSdRAHrI7mQbofYgyxxIxI 52cjku7l6wSbrmwk133X9eKdw44Jk1E+sfUVAhZbrO0p75TwCEfNW8TAN+fT3OS3urJ8BnXCiCxVX AMJ+BA1A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dL3gp-0007wT-MO; Wed, 14 Jun 2017 08:30:11 +0000 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dL3gQ-0006We-Ud for linux-arm-kernel@lists.infradead.org; Wed, 14 Jun 2017 08:29:49 +0000 Received: by mail-wr0-x235.google.com with SMTP id q97so178261204wrb.2 for ; Wed, 14 Jun 2017 01:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YPHjAlGz9YHrACM2a0cYMXqqJnDCxUKZQQO7qolH27A=; b=SEZw8BJiArN2FealriEJ0pgxIGlavtXVMliIeeV/fCxTv+eAvVkkV4OJZ592DFWFIg u6tamn9qZyv97EPVkd6u9ZGWJyEx0ZO3s+vOxLm3gFCLYFpJ8q3sCm1kNLBbviEgJxFQ 9VjBAD2TrDXuwV4SJ7dYcpXSZLR3/Gvp6WTOcIoQmibxa3wnA5Ne/7+xVkxTXxYFjAKb Z/6+MdOM708fQUA1VJ5r1P3l0HTkPrUWfoPefs/RV3tMvgq5w4vkq9WHnWMxzvwuNTAr rwqmds4/FjMg0t/gvqOgTeIyAm68wUrGCYQg6qayHKosVdODNAdjd33R/4XWu9GDm+Ql 7b3w== 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; bh=YPHjAlGz9YHrACM2a0cYMXqqJnDCxUKZQQO7qolH27A=; b=dKb5bFYEf6kIWx2pfOrAdFRACIWnM2ro/qw+R4vTRR7sIl9zbDhs8Zx484HdU4TkJH JD+pIehr5oqszzdA3cESHh4/5cUAJ31wB0weHfShzQnjp2kB3Zjph1Qlxhqf7Et0sg36 TppEzjeHmNOo4Cad2/krGrKOg1X2nn1SZ92MGcKUb8unBmwkQjO/b7fjrmpfwQioumzq 9Ct3JI4V5Jla15YwQ0zzMOuM4uyGOO6BpgR+euNqxoXwaqkGmA6ZVRVqkk8vQ3q2c2Nd WaYMWl+4/F9tAyNypfmZut2WSdD96Zx9sAfPDpkVzDqPJBGZpH6gh6iEHR2XAXANvhjb dvag== X-Gm-Message-State: AKS2vOw3UktyoOWG9Qo2r0zsAlGFLq+C8moS2HtEy4/anWaIrBKptNRb UMDlUVZguv7rtny4 X-Received: by 10.28.175.71 with SMTP id y68mr12098110wme.75.1497428964859; Wed, 14 Jun 2017 01:29:24 -0700 (PDT) Received: from localhost.localdomain (home.amouriers.starnux.net. [82.228.250.61]) by smtp.gmail.com with ESMTPSA id 62sm321192wra.44.2017.06.14.01.29.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 01:29:24 -0700 (PDT) From: Neil Armstrong To: gregkh@linuxfoundation.org, khilman@baylibre.com Subject: [PATCH v5 2/4] tty/serial: meson_uart: update to stable bindings Date: Wed, 14 Jun 2017 10:29:15 +0200 Message-Id: <1497428957-19942-3-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497428957-19942-1-git-send-email-narmstrong@baylibre.com> References: <1497428957-19942-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170614_012947_143838_9E8226A1 X-CRM114-Status: GOOD ( 16.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Neil Armstrong , linux-kernel@vger.kernel.org, Helmut Klein , linux-serial@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Helmut Klein This patch handle the stable UART bindings but also keeps compatibility with the legacy non-stable bindings until all boards uses them. Reviewed-by: Jerome Brunet Signed-off-by: Helmut Klein Signed-off-by: Neil Armstrong --- drivers/tty/serial/meson_uart.c | 90 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index 60f1679..82e0709 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -579,8 +579,12 @@ static void meson_serial_early_console_write(struct console *co, device->con->write = meson_serial_early_console_write; return 0; } +/* Legacy bindings, should be removed when no more used */ OF_EARLYCON_DECLARE(meson, "amlogic,meson-uart", meson_serial_early_console_setup); +/* Stable bindings */ +OF_EARLYCON_DECLARE(meson, "amlogic,meson-ao-uart", + meson_serial_early_console_setup); #define MESON_SERIAL_CONSOLE (&meson_serial_console) #else @@ -595,11 +599,76 @@ static void meson_serial_early_console_write(struct console *co, .cons = MESON_SERIAL_CONSOLE, }; +static inline struct clk *meson_uart_probe_clock(struct device *dev, + const char *id) +{ + struct clk *clk = NULL; + int ret; + + clk = devm_clk_get(dev, id); + if (IS_ERR(clk)) + return clk; + + ret = clk_prepare_enable(clk); + if (ret) { + dev_err(dev, "couldn't enable clk\n"); + return ERR_PTR(ret); + } + + devm_add_action_or_reset(dev, + (void(*)(void *))clk_disable_unprepare, + clk); + + return clk; +} + +/* + * This function gets clocks in the legacy non-stable DT bindings. + * This code will be remove once all the platforms switch to the + * new DT bindings. + */ +static int meson_uart_probe_clocks_legacy(struct platform_device *pdev, + struct uart_port *port) +{ + struct clk *clk = NULL; + + clk = meson_uart_probe_clock(&pdev->dev, NULL); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + port->uartclk = clk_get_rate(clk); + + return 0; +} + +static int meson_uart_probe_clocks(struct platform_device *pdev, + struct uart_port *port) +{ + struct clk *clk_xtal = NULL; + struct clk *clk_pclk = NULL; + struct clk *clk_baud = NULL; + + clk_pclk = meson_uart_probe_clock(&pdev->dev, "pclk"); + if (IS_ERR(clk_pclk)) + return PTR_ERR(clk_pclk); + + clk_xtal = meson_uart_probe_clock(&pdev->dev, "xtal"); + if (IS_ERR(clk_xtal)) + return PTR_ERR(clk_xtal); + + clk_baud = meson_uart_probe_clock(&pdev->dev, "baud"); + if (IS_ERR(clk_baud)) + return PTR_ERR(clk_baud); + + port->uartclk = clk_get_rate(clk_baud); + + return 0; +} + static int meson_uart_probe(struct platform_device *pdev) { struct resource *res_mem, *res_irq; struct uart_port *port; - struct clk *clk; int ret = 0; if (pdev->dev.of_node) @@ -625,11 +694,15 @@ static int meson_uart_probe(struct platform_device *pdev) if (!port) return -ENOMEM; - clk = clk_get(&pdev->dev, NULL); - if (IS_ERR(clk)) - return PTR_ERR(clk); + /* Use legacy way until all platforms switch to new bindings */ + if (of_device_is_compatible(pdev->dev.of_node, "amlogic,meson-uart")) + ret = meson_uart_probe_clocks_legacy(pdev, port); + else + ret = meson_uart_probe_clocks(pdev, port); + + if (ret) + return ret; - port->uartclk = clk_get_rate(clk); port->iotype = UPIO_MEM; port->mapbase = res_mem->start; port->irq = res_irq->start; @@ -668,9 +741,14 @@ static int meson_uart_remove(struct platform_device *pdev) return 0; } - static const struct of_device_id meson_uart_dt_match[] = { + /* Legacy bindings, should be removed when no more used */ { .compatible = "amlogic,meson-uart" }, + /* Stable bindings */ + { .compatible = "amlogic,meson6-uart" }, + { .compatible = "amlogic,meson8-uart" }, + { .compatible = "amlogic,meson8b-uart" }, + { .compatible = "amlogic,meson-gx-uart" }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, meson_uart_dt_match);