From patchwork Tue Feb 19 07:31:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 158686 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3360367jaa; Mon, 18 Feb 2019 23:32:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IYfx8sLuPgzMHFHp7oqsvh2kRVUPYjHRiBFwtGHLv9RxhxmfF6oRnMf1/eLe1Dde8e5ospf X-Received: by 2002:a63:f30d:: with SMTP id l13mr22768571pgh.399.1550561524359; Mon, 18 Feb 2019 23:32:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550561524; cv=none; d=google.com; s=arc-20160816; b=xgNPLc5ZAXhTHh/++iL+JMF80Uy1gahIPZIpq1NKPv/K4Pm8YssJYuG9OhC/tk31X6 L5pG2cTa1DSLTWnwQoeMKuZ0D7bydpfCBTpWm8PgIq6mmMA2NCcnYDilMsL1PKotwHet +VTJRoDEjBZa0K2qQrFTMxrSjTDc5Ur7pGf7AtfuEaMBwWnK2FswZjKeXNMDmrgKicJD rVIM2X8DYbGm9A2uUwiWVfgEaum9FPitOb1MrBsR3yFnn43lYRkoFE47gm1c0C6TJg7c flWEkD1/lZwv9B+ifyBit/wKjr+p/D7ea6Yyh8D+RkSPAcz7w5eLYq8dIOw2g75CLHDJ RNYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=OH4/R/+Sw0xSAT1PY7Jcu+TD5xcCuEZT5i9WHOVRd/E=; b=KDDd3EA20PH4RfGwNH9WtEuEZHto3a6WJquLGFVWKsTaym4T/o68oXRDgM1h6Lqm/D CoLW1kNjbAI6PXZ/imXYH9YnpumPrb7ksvFNKqrJGPyqfpLpJD1+owhgZbwJMaDIqTJH bUUwFnhAJlKtZl3OuB1C3ooh2vHaNgbrLvN4zq/U7+2CnxLZPJoWqnsL5OMMFf6ZyXlA gY8z25WbWWWqJit7gu+UrGoZqlpDOu/xsYlim2N/qHXDsfrrfFt7U/1BMMCeTbCwVXji i/pPXneHx7DitiobFlEzRfa6dUgOOOi4Qu79B2WKKenFyXDl26/XTkq98axPgLSzX2up bSwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mBVRP98Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 25si12857911pgz.309.2019.02.18.23.32.04; Mon, 18 Feb 2019 23:32:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mBVRP98Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727216AbfBSHcC (ORCPT + 32 others); Tue, 19 Feb 2019 02:32:02 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41015 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbfBSHcB (ORCPT ); Tue, 19 Feb 2019 02:32:01 -0500 Received: by mail-pf1-f193.google.com with SMTP id d25so1470323pfn.8 for ; Mon, 18 Feb 2019 23:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=OH4/R/+Sw0xSAT1PY7Jcu+TD5xcCuEZT5i9WHOVRd/E=; b=mBVRP98YrgXxSycI+IEpurKiIyLWSygxELFbpBiYNuhcEegSpkm8ZYEkBKgHbHaOXl 8p22pkX0L8RdjuZay61ImSfuY+W2gLqUR64kM6GcN2YHly9w/hZKA9FoCBEWLbCJt7be T+OHTKD+0tD4AnNTzMIBJrOlpm84cd5HoSEMj/SjPMM1WOmDgQ1w4mOY5KyUChN+sXG4 /Z+aryL/8ty5KWOYxQ/JesGZZ79S62Wtz4qqY/yOu+oraDQBJ3LsEotuWCoeQsalXPXo FxH7b6KPXrhlby6qbdISBaSfi/an3m2z18Lpi38RWDjGwunSaoRKZX46867Bst+BrpHy jnlw== 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:in-reply-to:references; bh=OH4/R/+Sw0xSAT1PY7Jcu+TD5xcCuEZT5i9WHOVRd/E=; b=Y7cn8AbCm9q7o5HS5HpXEal38N+2HsuUYnQioiPjD/sz1CanP1D0Wv3RjG7t1Xjn// sYlSz11uvfeKiKSkFsSMFsJn92SSYYWhWqMXK/Nk/5KZZ6RHvqKqlEQLoN0cFH6xucAW 9+sZZKxI/sUft221K6En1UkCMNejPPIZQVFLrstHiaCT2MHwwpvZfZVpB5IrfKAl8qfZ GgCo9HWemK9OivkviSySqbRsSXecvYr5TTdz0rrWr0f6yWgo4EOKosPYAK8kS7TmMOp+ ngCRfhleEkcFQmtZ3Ujv+R0zFkF1DnBWMEvh/4TEmNj+DXbzHZmouFSAlhQvPqjI83jC OCtg== X-Gm-Message-State: AHQUAubMAZNQbSSx6mFl3rX6lEl4WTXPrUP3YSzJV6vHrzuGNfpIz9TW 7yBOgYJH8Pn/aEhGPZTl5S1VFg== X-Received: by 2002:a63:ae0e:: with SMTP id q14mr26926027pgf.151.1550561519923; Mon, 18 Feb 2019 23:31:59 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id n27sm31556569pfb.8.2019.02.18.23.31.55 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Feb 2019 23:31:59 -0800 (PST) From: Baolin Wang To: gregkh@linuxfoundation.org, jslaby@suse.com, robh+dt@kernel.org, mark.rutland@arm.com, orsonzhai@gmail.com, zhang.lyra@gmail.com Cc: baolin.wang@linaro.org, broonie@kernel.org, lanqing.liu@unisoc.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 3/5] serial: sprd: Add power management for the Spreadtrum serial controller Date: Tue, 19 Feb 2019 15:31:13 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lanqing Liu This patch adds power management for the Spreadtrum serial controller. Signed-off-by: Lanqing Liu Signed-off-by: Baolin Wang --- drivers/tty/serial/sprd_serial.c | 61 +++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) -- 1.7.9.5 diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c index 1891a45..8f45b66 100644 --- a/drivers/tty/serial/sprd_serial.c +++ b/drivers/tty/serial/sprd_serial.c @@ -100,10 +100,12 @@ #define SPRD_IMSR_TX_FIFO_EMPTY BIT(1) #define SPRD_IMSR_BREAK_DETECT BIT(7) #define SPRD_IMSR_TIMEOUT BIT(13) +#define SPRD_DEFAULT_SOURCE_CLK 26000000 struct sprd_uart_port { struct uart_port port; char name[16]; + struct clk *clk; }; static struct sprd_uart_port *sprd_port[UART_NR_MAX]; @@ -491,6 +493,22 @@ static int sprd_verify_port(struct uart_port *port, struct serial_struct *ser) return 0; } +static void sprd_pm(struct uart_port *port, unsigned int state, + unsigned int oldstate) +{ + struct sprd_uart_port *sup = + container_of(port, struct sprd_uart_port, port); + + switch (state) { + case UART_PM_STATE_ON: + clk_prepare_enable(sup->clk); + break; + case UART_PM_STATE_OFF: + clk_disable_unprepare(sup->clk); + break; + } +} + static const struct uart_ops serial_sprd_ops = { .tx_empty = sprd_tx_empty, .get_mctrl = sprd_get_mctrl, @@ -507,6 +525,7 @@ static int sprd_verify_port(struct uart_port *port, struct serial_struct *ser) .request_port = sprd_request_port, .config_port = sprd_config_port, .verify_port = sprd_verify_port, + .pm = sprd_pm, }; #ifdef CONFIG_SERIAL_SPRD_CONSOLE @@ -671,11 +690,45 @@ static int sprd_remove(struct platform_device *dev) return 0; } +static int sprd_clk_init(struct uart_port *uport) +{ + struct clk *clk_uart, *clk_parent; + struct sprd_uart_port *u = sprd_port[uport->line]; + + clk_uart = devm_clk_get(uport->dev, "uart"); + if (IS_ERR(clk_uart)) { + dev_warn(uport->dev, "uart%d can't get uart clock\n", + uport->line); + clk_uart = NULL; + } + + clk_parent = devm_clk_get(uport->dev, "source"); + if (IS_ERR(clk_parent)) { + dev_warn(uport->dev, "uart%d can't get source clock\n", + uport->line); + clk_parent = NULL; + } + + if (!clk_uart || clk_set_parent(clk_uart, clk_parent)) + uport->uartclk = SPRD_DEFAULT_SOURCE_CLK; + else + uport->uartclk = clk_get_rate(clk_uart); + + u->clk = devm_clk_get(uport->dev, "enable"); + if (IS_ERR(u->clk)) { + if (PTR_ERR(u->clk) != -EPROBE_DEFER) + dev_err(uport->dev, "uart%d can't get enable clock\n", + uport->line); + return PTR_ERR(u->clk); + } + + return 0; +} + static int sprd_probe(struct platform_device *pdev) { struct resource *res; struct uart_port *up; - struct clk *clk; int irq; int index; int ret; @@ -704,9 +757,9 @@ static int sprd_probe(struct platform_device *pdev) up->ops = &serial_sprd_ops; up->flags = UPF_BOOT_AUTOCONF; - clk = devm_clk_get(&pdev->dev, NULL); - if (!IS_ERR_OR_NULL(clk)) - up->uartclk = clk_get_rate(clk); + ret = sprd_clk_init(up); + if (ret) + return ret; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); up->membase = devm_ioremap_resource(&pdev->dev, res);