From patchwork Sat Aug 15 04:37:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 7020401 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AA4889F373 for ; Sat, 15 Aug 2015 04:39:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C641E20632 for ; Sat, 15 Aug 2015 04:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3A2B2062B for ; Sat, 15 Aug 2015 04:39:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751335AbbHOEi2 (ORCPT ); Sat, 15 Aug 2015 00:38:28 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:36798 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751103AbbHOEiB (ORCPT ); Sat, 15 Aug 2015 00:38:01 -0400 Received: by pdco4 with SMTP id o4so37704177pdc.3; Fri, 14 Aug 2015 21:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XKuSg4JzkCAWCTaddNY8ytwLZfyh/qd8rhO19jazrNE=; b=bqHA3muMMs2ZwdViZY2icNt3W1Q8fRRt+pNHFcWPxT/W+sCvUU6g3dd0FRYWfzdFXQ Neq9N21MMlSWud96dUyoVa354dIP04aJGeZ26tNOU+5lQyid0UnCstDYoYl69EwnKjrU zlC15hixSQ+dRM3hlSqToH2RBG4/+u8wLaizlo3/KMeZVHMS2IVOw9etLWGFvtIQ6nsU eop1UfO1kMZ4IgGd2Fg55T+m9OH7CYxVu/GA9DHnw75ogiSTK4ApBoBbCabfw8jHXh/+ tsE2MD5pZY4ZmEya4wFmf9MbliMa3OVI7207riiFZTk4tY9XyDK01kQOZOAPwTKX1wVs rWow== X-Received: by 10.70.103.10 with SMTP id fs10mr29634996pdb.166.1439613480864; Fri, 14 Aug 2015 21:38:00 -0700 (PDT) Received: from localhost ([2601:647:4200:88bc::b05e]) by smtp.gmail.com with ESMTPSA id qe3sm7646471pbc.73.2015.08.14.21.37.59 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 14 Aug 2015 21:38:00 -0700 (PDT) From: Eduardo Valentin To: Greg Kroah-Hartman , Jiri Slaby , Fabio Estevam Cc: Sascha Hauer , Linux PM , linux-serial@vger.kernel.org, LKML , Eduardo Valentin Subject: [PATCHv4 3/4] serial: imx: add pm_qos request Date: Fri, 14 Aug 2015 21:37:47 -0700 Message-Id: <1439613468-22366-4-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1439613468-22366-1-git-send-email-edubezval@gmail.com> References: <1439613468-22366-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change introduces pm_qos requests in the imx serial driver. The idea is to skip deeper C-state in case we need a strict latency requirement in the uart port. The latency is computed based on the buffer size and the current baud rate. We schedule a work queue to set the pm qos requirement. Cc: Fabio Estevam Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/tty/serial/imx.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index d9ccf6b..24ed0fa 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -222,6 +223,10 @@ struct imx_port { unsigned int saved_reg[10]; bool context_saved; + struct pm_qos_request pm_qos_request; + u32 latency; + u32 calc_latency; + struct work_struct qos_work; bool is_suspending; }; @@ -1320,6 +1325,14 @@ static void imx_flush_buffer(struct uart_port *port) pm_runtime_put_autosuspend(sport->port.dev); } +static void serial_imx_uart_qos_work(struct work_struct *work) +{ + struct imx_port *sport = container_of(work, struct imx_port, + qos_work); + + pm_qos_update_request(&sport->pm_qos_request, sport->latency); +} + static void imx_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) @@ -1393,6 +1406,12 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios, baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16); quot = uart_get_divisor(port, baud); + /* calculate wakeup latency constraint */ + sport->calc_latency = (USEC_PER_SEC * sport->port.fifosize) / + (baud / 8); + sport->latency = sport->calc_latency; + schedule_work(&sport->qos_work); + spin_lock_irqsave(&sport->port.lock, flags); sport->port.read_status_mask = 0; @@ -2012,6 +2031,11 @@ static int serial_imx_probe(struct platform_device *pdev) imx_ports[sport->port.line] = sport; + sport->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; + sport->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; + pm_qos_add_request(&sport->pm_qos_request, PM_QOS_CPU_DMA_LATENCY, + sport->latency); + INIT_WORK(&sport->qos_work, serial_imx_uart_qos_work); platform_set_drvdata(pdev, sport); device_init_wakeup(sport->port.dev, true); @@ -2041,6 +2065,7 @@ static int serial_imx_remove(struct platform_device *pdev) clk_unprepare(sport->clk_per); clk_unprepare(sport->clk_ipg); ret = uart_remove_one_port(&imx_reg, &sport->port); + pm_qos_remove_request(&sport->pm_qos_request); device_init_wakeup(&pdev->dev, false); return ret; @@ -2119,6 +2144,8 @@ static int serial_imx_runtime_suspend(struct device *dev) serial_imx_save_context(sport); serial_imx_enable_wakeup(sport, true); + sport->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; + schedule_work(&sport->qos_work); clk_disable(sport->clk_per); clk_disable(sport->clk_ipg); @@ -2140,6 +2167,8 @@ static int serial_imx_runtime_resume(struct device *dev) } serial_imx_enable_wakeup(sport, false); + sport->latency = sport->calc_latency; + schedule_work(&sport->qos_work); serial_imx_restore_context(sport); return 0;