From: Chen-Yu Tsai <wens@csie.org> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jslaby@suse.cz>, Pawel Moll <pawel.moll@arm.com>, Mark Rutland <mark.rutland@arm.com>, Ian Campbell <ijc+devicetree@hellion.org.uk>, Kumar Gala <galak@codeaurora.org>, Rob Herring <robh+dt@kernel.org> Cc: Chen-Yu Tsai <wens@csie.org>, Maxime Ripard <maxime.ripard@free-electrons.com>, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/2] serial: 8250_dw: Add support for deferred probing Date: Wed, 23 Jul 2014 23:33:07 +0800 [thread overview] Message-ID: <1406129587-24668-3-git-send-email-wens@csie.org> (raw) In-Reply-To: <1406129587-24668-1-git-send-email-wens@csie.org> The 8250_dw driver fails to probe if the specified clock isn't registered at probe time. Even if a clock frequency is given, the required clock might be gated because it wasn't properly enabled. This happened to me when the device is registered through DT, and the clock was part of an MFD, the PRCM found on A31 and A23 SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE, which happen almost immediately after the kernel starts, the clocks are registered as sub-devices of the PRCM MFD platform device. Even though devices are registered in the order they are found in the DT, the drivers are registered in a different, arbitrary order. It is possible that the 8250_dw driver is registered, and thus associated with the device and probed, before the clock driver is registered and probed. 8250_dw then reports unable to get the clock, and fails. Without a working console, the kernel panics. This patch adds support for deferred probe handling for the clock and reset controller. It also fixes the cleanup path if serial8250_register_8250_port fails. Signed-off-by: Chen-Yu Tsai <wens@csie.org> --- drivers/tty/serial/8250/8250_dw.c | 41 ++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 501db2f..4db7987 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -365,8 +365,10 @@ static int dw8250_probe(struct platform_device *pdev) data->usr_reg = DW_UART_USR; data->clk = devm_clk_get(&pdev->dev, "baudclk"); - if (IS_ERR(data->clk)) + if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER) data->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) + return -EPROBE_DEFER; if (!IS_ERR(data->clk)) { err = clk_prepare_enable(data->clk); if (err) @@ -377,15 +379,23 @@ static int dw8250_probe(struct platform_device *pdev) } data->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); + if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) { + err = -EPROBE_DEFER; + goto err_clk; + } if (!IS_ERR(data->pclk)) { err = clk_prepare_enable(data->pclk); if (err) { dev_err(&pdev->dev, "could not enable apb_pclk\n"); - return err; + goto err_clk; } } data->rst = devm_reset_control_get_optional(&pdev->dev, NULL); + if (IS_ERR(data->rst) && PTR_ERR(data->rst) == -EPROBE_DEFER) { + err = -EPROBE_DEFER; + goto err_pclk; + } if (!IS_ERR(data->rst)) reset_control_deassert(data->rst); @@ -403,18 +413,21 @@ static int dw8250_probe(struct platform_device *pdev) if (pdev->dev.of_node) { err = dw8250_probe_of(&uart.port, data); if (err) - return err; + goto err_reset; } else if (ACPI_HANDLE(&pdev->dev)) { err = dw8250_probe_acpi(&uart, data); if (err) - return err; + goto err_reset; } else { - return -ENODEV; + err = -ENODEV; + goto err_reset; } data->line = serial8250_register_8250_port(&uart); - if (data->line < 0) - return data->line; + if (data->line < 0) { + err = data->line; + goto err_reset; + } platform_set_drvdata(pdev, data); @@ -422,6 +435,20 @@ static int dw8250_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); return 0; + +err_reset: + if (!IS_ERR(data->rst)) + reset_control_assert(data->rst); + +err_pclk: + if (!IS_ERR(data->pclk)) + clk_disable_unprepare(data->pclk); + +err_clk: + if (!IS_ERR(data->clk)) + clk_disable_unprepare(data->clk); + + return err; } static int dw8250_remove(struct platform_device *pdev) -- 2.0.1
WARNING: multiple messages have this Message-ID (diff)
From: wens@csie.org (Chen-Yu Tsai) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 2/2] serial: 8250_dw: Add support for deferred probing Date: Wed, 23 Jul 2014 23:33:07 +0800 [thread overview] Message-ID: <1406129587-24668-3-git-send-email-wens@csie.org> (raw) In-Reply-To: <1406129587-24668-1-git-send-email-wens@csie.org> The 8250_dw driver fails to probe if the specified clock isn't registered at probe time. Even if a clock frequency is given, the required clock might be gated because it wasn't properly enabled. This happened to me when the device is registered through DT, and the clock was part of an MFD, the PRCM found on A31 and A23 SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE, which happen almost immediately after the kernel starts, the clocks are registered as sub-devices of the PRCM MFD platform device. Even though devices are registered in the order they are found in the DT, the drivers are registered in a different, arbitrary order. It is possible that the 8250_dw driver is registered, and thus associated with the device and probed, before the clock driver is registered and probed. 8250_dw then reports unable to get the clock, and fails. Without a working console, the kernel panics. This patch adds support for deferred probe handling for the clock and reset controller. It also fixes the cleanup path if serial8250_register_8250_port fails. Signed-off-by: Chen-Yu Tsai <wens@csie.org> --- drivers/tty/serial/8250/8250_dw.c | 41 ++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 501db2f..4db7987 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -365,8 +365,10 @@ static int dw8250_probe(struct platform_device *pdev) data->usr_reg = DW_UART_USR; data->clk = devm_clk_get(&pdev->dev, "baudclk"); - if (IS_ERR(data->clk)) + if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER) data->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) + return -EPROBE_DEFER; if (!IS_ERR(data->clk)) { err = clk_prepare_enable(data->clk); if (err) @@ -377,15 +379,23 @@ static int dw8250_probe(struct platform_device *pdev) } data->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); + if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER) { + err = -EPROBE_DEFER; + goto err_clk; + } if (!IS_ERR(data->pclk)) { err = clk_prepare_enable(data->pclk); if (err) { dev_err(&pdev->dev, "could not enable apb_pclk\n"); - return err; + goto err_clk; } } data->rst = devm_reset_control_get_optional(&pdev->dev, NULL); + if (IS_ERR(data->rst) && PTR_ERR(data->rst) == -EPROBE_DEFER) { + err = -EPROBE_DEFER; + goto err_pclk; + } if (!IS_ERR(data->rst)) reset_control_deassert(data->rst); @@ -403,18 +413,21 @@ static int dw8250_probe(struct platform_device *pdev) if (pdev->dev.of_node) { err = dw8250_probe_of(&uart.port, data); if (err) - return err; + goto err_reset; } else if (ACPI_HANDLE(&pdev->dev)) { err = dw8250_probe_acpi(&uart, data); if (err) - return err; + goto err_reset; } else { - return -ENODEV; + err = -ENODEV; + goto err_reset; } data->line = serial8250_register_8250_port(&uart); - if (data->line < 0) - return data->line; + if (data->line < 0) { + err = data->line; + goto err_reset; + } platform_set_drvdata(pdev, data); @@ -422,6 +435,20 @@ static int dw8250_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); return 0; + +err_reset: + if (!IS_ERR(data->rst)) + reset_control_assert(data->rst); + +err_pclk: + if (!IS_ERR(data->pclk)) + clk_disable_unprepare(data->pclk); + +err_clk: + if (!IS_ERR(data->clk)) + clk_disable_unprepare(data->clk); + + return err; } static int dw8250_remove(struct platform_device *pdev) -- 2.0.1
next prev parent reply other threads:[~2014-07-23 15:33 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-07-23 15:33 [PATCH v5 0/2] serial: 8250_dw: optional reset control and deferred probe support Chen-Yu Tsai 2014-07-23 15:33 ` Chen-Yu Tsai 2014-07-23 15:33 ` Chen-Yu Tsai 2014-07-23 15:33 ` [PATCH v5 1/2] serial: 8250_dw: Add optional reset control support Chen-Yu Tsai 2014-07-23 15:33 ` Chen-Yu Tsai 2014-07-23 15:33 ` Chen-Yu Tsai [this message] 2014-07-23 15:33 ` [PATCH v5 2/2] serial: 8250_dw: Add support for deferred probing Chen-Yu Tsai
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=1406129587-24668-3-git-send-email-wens@csie.org \ --to=wens@csie.org \ --cc=devicetree@vger.kernel.org \ --cc=galak@codeaurora.org \ --cc=gregkh@linuxfoundation.org \ --cc=ijc+devicetree@hellion.org.uk \ --cc=jslaby@suse.cz \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-serial@vger.kernel.org \ --cc=mark.rutland@arm.com \ --cc=maxime.ripard@free-electrons.com \ --cc=pawel.moll@arm.com \ --cc=robh+dt@kernel.org \ /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.