From: Sascha Hauer <s.hauer@pengutronix.de> To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Matthias Brugger <matthias.bgg@gmail.com>, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, Alan Cox <alan@linux.intel.com>, Sascha Hauer <s.hauer@pengutronix.de> Subject: [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling Date: Thu, 23 Apr 2015 10:51:05 +0200 [thread overview] Message-ID: <1429779066-21406-4-git-send-email-s.hauer@pengutronix.de> (raw) In-Reply-To: <1429779066-21406-1-git-send-email-s.hauer@pengutronix.de> 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 <s.hauer@pengutronix.de> --- 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; return 0; } @@ -212,10 +232,13 @@ static int mtk8250_remove(struct platform_device *pdev) pm_runtime_get_sync(&pdev->dev); serial8250_unregister_port(data->line); - clk_disable_unprepare(data->uart_clk); pm_runtime_disable(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); + + if (!pm_runtime_status_suspended(&pdev->dev)) + mtk8250_runtime_suspend(&pdev->dev); + return 0; } @@ -239,26 +262,6 @@ static int mtk8250_resume(struct device *dev) } #endif /* CONFIG_PM_SLEEP */ -#ifdef CONFIG_PM -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); - - clk_prepare_enable(data->uart_clk); - - return 0; -} -#endif - static const struct dev_pm_ops mtk8250_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(mtk8250_suspend, mtk8250_resume) SET_RUNTIME_PM_OPS(mtk8250_runtime_suspend, mtk8250_runtime_resume, -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: s.hauer@pengutronix.de (Sascha Hauer) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling Date: Thu, 23 Apr 2015 10:51:05 +0200 [thread overview] Message-ID: <1429779066-21406-4-git-send-email-s.hauer@pengutronix.de> (raw) In-Reply-To: <1429779066-21406-1-git-send-email-s.hauer@pengutronix.de> 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 <s.hauer@pengutronix.de> --- 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; return 0; } @@ -212,10 +232,13 @@ static int mtk8250_remove(struct platform_device *pdev) pm_runtime_get_sync(&pdev->dev); serial8250_unregister_port(data->line); - clk_disable_unprepare(data->uart_clk); pm_runtime_disable(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); + + if (!pm_runtime_status_suspended(&pdev->dev)) + mtk8250_runtime_suspend(&pdev->dev); + return 0; } @@ -239,26 +262,6 @@ static int mtk8250_resume(struct device *dev) } #endif /* CONFIG_PM_SLEEP */ -#ifdef CONFIG_PM -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); - - clk_prepare_enable(data->uart_clk); - - return 0; -} -#endif - static const struct dev_pm_ops mtk8250_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(mtk8250_suspend, mtk8250_resume) SET_RUNTIME_PM_OPS(mtk8250_runtime_suspend, mtk8250_runtime_resume, -- 2.1.4
next prev parent reply other threads:[~2015-04-23 8:52 UTC|newest] Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-04-23 8:51 tty: serial: 8250_mtk: Add support for second clock Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer 2015-04-23 8:51 ` [PATCH 1/4] tty: serial: 8250_mtk: Use devm_clk_get Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer 2015-04-24 10:28 ` Matthias Brugger 2015-04-24 10:28 ` Matthias Brugger 2015-04-24 10:28 ` Matthias Brugger 2015-04-24 10:31 ` Sascha Hauer 2015-04-24 10:31 ` Sascha Hauer 2015-04-24 10:31 ` Sascha Hauer 2015-04-24 10:53 ` Matthias Brugger 2015-04-24 10:53 ` Matthias Brugger 2015-04-24 10:53 ` Matthias Brugger 2015-04-24 10:56 ` Matthias Brugger 2015-04-24 10:56 ` Matthias Brugger 2015-04-24 10:56 ` Matthias Brugger 2015-04-27 6:33 ` Sascha Hauer 2015-04-27 6:33 ` Sascha Hauer 2015-04-27 6:33 ` Sascha Hauer 2015-04-23 8:51 ` [PATCH 2/4] tty: serial: 8250_mtk: remove unnecessary test Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer [this message] 2015-04-23 8:51 ` [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling Sascha Hauer 2015-04-23 8:51 ` [PATCH 4/4] tty: serial: 8250_mtk: Add support for bus clock Sascha Hauer 2015-04-23 8:51 ` Sascha Hauer 2015-04-24 11:18 ` Matthias Brugger 2015-04-24 11:18 ` Matthias Brugger 2015-04-24 11:18 ` Matthias Brugger 2015-04-27 6:49 [PATCH v2] tty: serial: 8250_mtk: Add support for second clock Sascha Hauer 2015-04-27 6:49 ` [PATCH 3/4] tty: serial: 8250_mtk: use pm_runtime callbacks for enabling Sascha Hauer 2015-04-27 6:49 ` Sascha Hauer 2015-04-27 6:49 ` Sascha Hauer 2015-05-04 11:05 ` Matthias Brugger 2015-05-04 11:05 ` Matthias Brugger 2015-05-04 11:05 ` Matthias Brugger 2015-05-04 12:06 ` Sascha Hauer 2015-05-04 12:06 ` Sascha Hauer 2015-05-04 12:06 ` Sascha Hauer 2015-05-05 15:29 ` Matthias Brugger 2015-05-05 15:29 ` Matthias Brugger 2015-05-05 15:29 ` Matthias Brugger
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1429779066-21406-4-git-send-email-s.hauer@pengutronix.de \ --to=s.hauer@pengutronix.de \ --cc=alan@linux.intel.com \ --cc=gregkh@linuxfoundation.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mediatek@lists.infradead.org \ --cc=linux-serial@vger.kernel.org \ --cc=matthias.bgg@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.