From patchwork Mon Mar 4 08:58:22 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: 159541 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3549871jad; Mon, 4 Mar 2019 00:59:23 -0800 (PST) X-Google-Smtp-Source: APXvYqz0sVKI3+oInAc9YMp1w1243wp1ooo87y+6ZyftP5Ekdg2mE0g0CJnuddRID3L1lVX62Ap7 X-Received: by 2002:a65:40c5:: with SMTP id u5mr17312464pgp.275.1551689963813; Mon, 04 Mar 2019 00:59:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551689963; cv=none; d=google.com; s=arc-20160816; b=ugzgqHC9/RIFrsi9XoUrTm3KNkUsFSaJBN2xJp8NJm2t4WM2dq0TU3y8+w1NFrOl+q NjbWl5Qr1R1VqTW3vRdy48IUKoRyySBVnw2LPWEXKjUyZISgd59N1brjGOSUQylytluL QIx7sginqddf1QqL2Cbuvu+rSJRf5nU4knzmxrE5X0IC7Ods6mwJTryRVvkU9CdSRSM2 QVjOsUmmxt3/cw6H/f3eLfL3abeu6YKc07I/nbI0ve2ZurIMbO9IDf1NZev7JWHPWYbA oi1JTpwj5ffoKxmpe8QweqHWAQaHSvly1DUEbEJKcq8jU7gfDKXkUXYXlsFWJkJZaTNZ zDFQ== 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=KC0uHLF9dnlk69iM6SgEka7RgIzyzJuKBqFo9RPB1WzkEKeeCUuRfwEYaU65MpPRUi JiETB9l8dXwTzw6rrDgFLRmQhm0C+GCajLzJe2JMrSVRGf4HREu7Y1SnIWKGgEzPNKQ9 /OIx39lyL9m6WYGfNJf3sl8DSOLJD96PAl5ze8wNXz2c0N5OVpnAgBk+dcI+uKtBzMw5 NruCmRIUHLATN2vIlN1Go8OGG/o8xkCW/JKBVYkg6/WXwRS94lRIPm0XhcU6rPFE5LRh zdLQ55PAm12AUMQJHWHbhjqdHiw8HvY8YwU51RFThEDnjbw3SjcdiVCpm5AfZnXAu6+c bcOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FDH+kg9U; 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 m22si4533730pgv.562.2019.03.04.00.59.23; Mon, 04 Mar 2019 00:59:23 -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=FDH+kg9U; 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 S1726348AbfCDI7V (ORCPT + 31 others); Mon, 4 Mar 2019 03:59:21 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44209 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbfCDI7U (ORCPT ); Mon, 4 Mar 2019 03:59:20 -0500 Received: by mail-pf1-f194.google.com with SMTP id a3so2523977pff.11 for ; Mon, 04 Mar 2019 00:59:20 -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=FDH+kg9UlgZpIFtvEodb8mfZQhQOH8YRfJPwwzImeazPa5C5/NKN3xyUNQ4rqN43q5 R9AB+rMf8FM8Niht2E1eS/Lb3mrPXyusbytrhShjHP3Eks18Os9iewfx1QbnOU0olPeJ GJ3iuGTBFaY3MT93Y/mv1dmBy09HFoui6EhFS4CY0UEjOIv8gyOePLscoAcGgokUoWhJ Slw8R80+y9W3tS493V3ipvX7guXngBmkQx9ep16nHEG6Gr4mSXtBOC92kKVFEmRNMh5s or3RlyudWjQF2MXphUqcLiOwT8ftsj0wjSiWpNP77ZvCyveznMRQa+CjFmISBMD8rvIk 3rqg== 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=nTdqp1W7mPuOtkSkly1/aPlgZm/2begjn+6YL8vx9otOpRkfVv/gOLcSByZJxVERmO zO6lXz2K3AdZsYpfgLbR+ESmA1WEbMRahwEVDo7XnPlV53GqlnBeGN4dM9jkZxKJSndq K3ylGR0V4l1dNEfBmOomdsEAM3k/iMjxaRtKcNOa2qVL9o0bvSqgHe7ryNpv9Bfb8trW 9YMSRF+mz5kVr+0+epEtNwJWOcxJS7ntf5Ctj1iYlF9JOloqan/yg0sGFRCK3xsNS4fh et6/gd3fkN5Ia3bdjjf7CyGiGIQ0FvT4tbfsHjfs5lIC4C2LJQLLO4/qTUiN7E5eL0ga UXQw== X-Gm-Message-State: APjAAAWU6xK5wbgUC5qd4DCi5S6T3QjoR7jCyz3QaldeOW2mGef3Ojty f/5IBz9NPBorxjtYq9dWJC+Jcg== X-Received: by 2002:a63:104e:: with SMTP id 14mr17440216pgq.185.1551689959930; Mon, 04 Mar 2019 00:59:19 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id k8sm7395523pgg.75.2019.03.04.00.59.15 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Mar 2019 00:59:19 -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 v2 2/4] serial: sprd: Add power management for the Spreadtrum serial controller Date: Mon, 4 Mar 2019 16:58:22 +0800 Message-Id: <904abaadecc22f8cbcfe0370ca30dc5c9ac52c11.1551689518.git.baolin.wang@linaro.org> 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);