From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752626AbbEDMHY (ORCPT ); Mon, 4 May 2015 08:07:24 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:53156 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbbEDMHT (ORCPT ); Mon, 4 May 2015 08:07:19 -0400 Date: Mon, 4 May 2015 14:06:51 +0200 From: Sascha Hauer To: Matthias Brugger Cc: "linux-kernel@vger.kernel.org" , Greg KH , linux-mediatek@lists.infradead.org, "linux-arm-kernel@lists.infradead.org" , linux-serial@vger.kernel.org, Alan Cox Subject: Re: [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling Message-ID: <20150504120651.GR6325@pengutronix.de> References: <1430117397-13517-1-git-send-email-s.hauer@pengutronix.de> <1430117397-13517-4-git-send-email-s.hauer@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 14:02:55 up 48 days, 23:54, 90 users, load average: 0.09, 0.17, 0.17 User-Agent: Mutt/1.5.21 (2010-09-15) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 04, 2015 at 01:05:27PM +0200, Matthias Brugger wrote: > 2015-04-27 8:49 GMT+02:00 Sascha Hauer : > > The pm_runtime callbacks already enable and disable the device. > > Use them in probe() and remove() instead of duplicating the > > code. This allows us to concentrate more code for enabling/disabling > > the UART in a single place. > > > > Signed-off-by: Sascha Hauer > > --- > > drivers/tty/serial/8250/8250_mtk.c | 69 ++++++++++++++++++++------------------ > > 1 file changed, 36 insertions(+), 33 deletions(-) > > > > diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c > > index bcfaa8dc..2f28bd0 100644 > > --- a/drivers/tty/serial/8250/8250_mtk.c > > +++ b/drivers/tty/serial/8250/8250_mtk.c > > @@ -115,6 +115,29 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, > > tty_termios_encode_baud_rate(termios, baud, baud); > > } > > > > +static int mtk8250_runtime_suspend(struct device *dev) > > +{ > > + struct mtk8250_data *data = dev_get_drvdata(dev); > > + > > + clk_disable_unprepare(data->uart_clk); > > + > > + return 0; > > +} > > + > > +static int mtk8250_runtime_resume(struct device *dev) > > +{ > > + struct mtk8250_data *data = dev_get_drvdata(dev); > > + int err; > > + > > + err = clk_prepare_enable(data->uart_clk); > > + if (err) { > > + dev_warn(dev, "Can't enable clock\n"); > > + return err; > > + } > > + > > + return 0; > > +} > > + > > static void > > mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) > > { > > @@ -130,19 +153,12 @@ mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) > > static int mtk8250_probe_of(struct platform_device *pdev, struct uart_port *p, > > struct mtk8250_data *data) > > { > > - int err; > > - > > data->uart_clk = devm_clk_get(&pdev->dev, NULL); > > if (IS_ERR(data->uart_clk)) { > > dev_warn(&pdev->dev, "Can't get uart clock\n"); > > return PTR_ERR(data->uart_clk); > > } > > > > - err = clk_prepare_enable(data->uart_clk); > > - if (err) { > > - dev_warn(&pdev->dev, "Can't prepare clock\n"); > > - return err; > > - } > > p->uartclk = clk_get_rate(data->uart_clk); > > > > return 0; > > @@ -193,14 +209,18 @@ static int mtk8250_probe(struct platform_device *pdev) > > writel(0x0, uart.port.membase + > > (MTK_UART_RATE_FIX << uart.port.regshift)); > > > > - data->line = serial8250_register_8250_port(&uart); > > - if (data->line < 0) > > - return data->line; > > - > > platform_set_drvdata(pdev, data); > > > > - pm_runtime_set_active(&pdev->dev); > > pm_runtime_enable(&pdev->dev); > > + if (!pm_runtime_enabled(&pdev->dev)) { > > + err = mtk8250_runtime_resume(&pdev->dev); > > + if (err) > > + return err; > > + } > > + > > + data->line = serial8250_register_8250_port(&uart); > > + if (data->line < 0) > > + return data->line; > > Why do you delete pm_runtime_set_active here? pm_runtime_set_active() communicates the initial state of the device to the pm core. Previously the driver activated the device manually by directly calling clk_prepare_enable(). Since this manual enabling of the clock is removed in this patch, the device is no longer active, hence pm_runtime_set_active() has to be removed. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sascha Hauer Subject: Re: [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling Date: Mon, 4 May 2015 14:06:51 +0200 Message-ID: <20150504120651.GR6325@pengutronix.de> References: <1430117397-13517-1-git-send-email-s.hauer@pengutronix.de> <1430117397-13517-4-git-send-email-s.hauer@pengutronix.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+glpam-linux-mediatek=m.gmane.org-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org To: Matthias Brugger Cc: Greg KH , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org" , Alan Cox List-Id: linux-serial@vger.kernel.org On Mon, May 04, 2015 at 01:05:27PM +0200, Matthias Brugger wrote: > 2015-04-27 8:49 GMT+02:00 Sascha Hauer : > > The pm_runtime callbacks already enable and disable the device. > > Use them in probe() and remove() instead of duplicating the > > code. This allows us to concentrate more code for enabling/disabling > > the UART in a single place. > > > > Signed-off-by: Sascha Hauer > > --- > > drivers/tty/serial/8250/8250_mtk.c | 69 ++++++++++++++++++++------------------ > > 1 file changed, 36 insertions(+), 33 deletions(-) > > > > diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c > > index bcfaa8dc..2f28bd0 100644 > > --- a/drivers/tty/serial/8250/8250_mtk.c > > +++ b/drivers/tty/serial/8250/8250_mtk.c > > @@ -115,6 +115,29 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, > > tty_termios_encode_baud_rate(termios, baud, baud); > > } > > > > +static int mtk8250_runtime_suspend(struct device *dev) > > +{ > > + struct mtk8250_data *data = dev_get_drvdata(dev); > > + > > + clk_disable_unprepare(data->uart_clk); > > + > > + return 0; > > +} > > + > > +static int mtk8250_runtime_resume(struct device *dev) > > +{ > > + struct mtk8250_data *data = dev_get_drvdata(dev); > > + int err; > > + > > + err = clk_prepare_enable(data->uart_clk); > > + if (err) { > > + dev_warn(dev, "Can't enable clock\n"); > > + return err; > > + } > > + > > + return 0; > > +} > > + > > static void > > mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) > > { > > @@ -130,19 +153,12 @@ mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) > > static int mtk8250_probe_of(struct platform_device *pdev, struct uart_port *p, > > struct mtk8250_data *data) > > { > > - int err; > > - > > data->uart_clk = devm_clk_get(&pdev->dev, NULL); > > if (IS_ERR(data->uart_clk)) { > > dev_warn(&pdev->dev, "Can't get uart clock\n"); > > return PTR_ERR(data->uart_clk); > > } > > > > - err = clk_prepare_enable(data->uart_clk); > > - if (err) { > > - dev_warn(&pdev->dev, "Can't prepare clock\n"); > > - return err; > > - } > > p->uartclk = clk_get_rate(data->uart_clk); > > > > return 0; > > @@ -193,14 +209,18 @@ static int mtk8250_probe(struct platform_device *pdev) > > writel(0x0, uart.port.membase + > > (MTK_UART_RATE_FIX << uart.port.regshift)); > > > > - data->line = serial8250_register_8250_port(&uart); > > - if (data->line < 0) > > - return data->line; > > - > > platform_set_drvdata(pdev, data); > > > > - pm_runtime_set_active(&pdev->dev); > > pm_runtime_enable(&pdev->dev); > > + if (!pm_runtime_enabled(&pdev->dev)) { > > + err = mtk8250_runtime_resume(&pdev->dev); > > + if (err) > > + return err; > > + } > > + > > + data->line = serial8250_register_8250_port(&uart); > > + if (data->line < 0) > > + return data->line; > > Why do you delete pm_runtime_set_active here? pm_runtime_set_active() communicates the initial state of the device to the pm core. Previously the driver activated the device manually by directly calling clk_prepare_enable(). Since this manual enabling of the clock is removed in this patch, the device is no longer active, hence pm_runtime_set_active() has to be removed. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | From mboxrd@z Thu Jan 1 00:00:00 1970 From: s.hauer@pengutronix.de (Sascha Hauer) Date: Mon, 4 May 2015 14:06:51 +0200 Subject: [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling In-Reply-To: References: <1430117397-13517-1-git-send-email-s.hauer@pengutronix.de> <1430117397-13517-4-git-send-email-s.hauer@pengutronix.de> Message-ID: <20150504120651.GR6325@pengutronix.de> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Mon, May 04, 2015 at 01:05:27PM +0200, Matthias Brugger wrote: > 2015-04-27 8:49 GMT+02:00 Sascha Hauer : > > The pm_runtime callbacks already enable and disable the device. > > Use them in probe() and remove() instead of duplicating the > > code. This allows us to concentrate more code for enabling/disabling > > the UART in a single place. > > > > Signed-off-by: Sascha Hauer > > --- > > drivers/tty/serial/8250/8250_mtk.c | 69 ++++++++++++++++++++------------------ > > 1 file changed, 36 insertions(+), 33 deletions(-) > > > > diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c > > index bcfaa8dc..2f28bd0 100644 > > --- a/drivers/tty/serial/8250/8250_mtk.c > > +++ b/drivers/tty/serial/8250/8250_mtk.c > > @@ -115,6 +115,29 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, > > tty_termios_encode_baud_rate(termios, baud, baud); > > } > > > > +static int mtk8250_runtime_suspend(struct device *dev) > > +{ > > + struct mtk8250_data *data = dev_get_drvdata(dev); > > + > > + clk_disable_unprepare(data->uart_clk); > > + > > + return 0; > > +} > > + > > +static int mtk8250_runtime_resume(struct device *dev) > > +{ > > + struct mtk8250_data *data = dev_get_drvdata(dev); > > + int err; > > + > > + err = clk_prepare_enable(data->uart_clk); > > + if (err) { > > + dev_warn(dev, "Can't enable clock\n"); > > + return err; > > + } > > + > > + return 0; > > +} > > + > > static void > > mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) > > { > > @@ -130,19 +153,12 @@ mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) > > static int mtk8250_probe_of(struct platform_device *pdev, struct uart_port *p, > > struct mtk8250_data *data) > > { > > - int err; > > - > > data->uart_clk = devm_clk_get(&pdev->dev, NULL); > > if (IS_ERR(data->uart_clk)) { > > dev_warn(&pdev->dev, "Can't get uart clock\n"); > > return PTR_ERR(data->uart_clk); > > } > > > > - err = clk_prepare_enable(data->uart_clk); > > - if (err) { > > - dev_warn(&pdev->dev, "Can't prepare clock\n"); > > - return err; > > - } > > p->uartclk = clk_get_rate(data->uart_clk); > > > > return 0; > > @@ -193,14 +209,18 @@ static int mtk8250_probe(struct platform_device *pdev) > > writel(0x0, uart.port.membase + > > (MTK_UART_RATE_FIX << uart.port.regshift)); > > > > - data->line = serial8250_register_8250_port(&uart); > > - if (data->line < 0) > > - return data->line; > > - > > platform_set_drvdata(pdev, data); > > > > - pm_runtime_set_active(&pdev->dev); > > pm_runtime_enable(&pdev->dev); > > + if (!pm_runtime_enabled(&pdev->dev)) { > > + err = mtk8250_runtime_resume(&pdev->dev); > > + if (err) > > + return err; > > + } > > + > > + data->line = serial8250_register_8250_port(&uart); > > + if (data->line < 0) > > + return data->line; > > Why do you delete pm_runtime_set_active here? pm_runtime_set_active() communicates the initial state of the device to the pm core. Previously the driver activated the device manually by directly calling clk_prepare_enable(). Since this manual enabling of the clock is removed in this patch, the device is no longer active, hence pm_runtime_set_active() has to be removed. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |