diff mbox

[2/4] mmc: sunxi: Make sample clocks optional

Message ID 1468665964-27142-3-git-send-email-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hans de Goede July 16, 2016, 10:46 a.m. UTC
It turns out that sun4i (A10) and sun5i (A13 & co) do not have sample
clocks, so make them optional.

Since these do not have sample clocks, they cannot (reliably) do
DDR rates, so only set MMC_CAP_1_8V_DDR when we do have sample clks.

Note this patch only changes the devm_clk_get error checking and sets
the clocks to NULL if they don't exists. All the clk_foo calls accept
a NULL clk and will return success when called with a NULL clk, so this
is all that is necessary.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/mmc/host/sunxi-mmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Ulf Hansson July 18, 2016, 11:12 a.m. UTC | #1
On 16 July 2016 at 12:46, Hans de Goede <hdegoede@redhat.com> wrote:
> It turns out that sun4i (A10) and sun5i (A13 & co) do not have sample
> clocks, so make them optional.
>
> Since these do not have sample clocks, they cannot (reliably) do
> DDR rates, so only set MMC_CAP_1_8V_DDR when we do have sample clks.
>
> Note this patch only changes the devm_clk_get error checking and sets
> the clocks to NULL if they don't exists. All the clk_foo calls accept
> a NULL clk and will return success when called with a NULL clk, so this
> is all that is necessary.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/mmc/host/sunxi-mmc.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index 71a480b..4552ee0 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -1016,14 +1016,20 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
>
>         host->clk_output = devm_clk_get(&pdev->dev, "output");
>         if (IS_ERR(host->clk_output)) {
> -               dev_err(&pdev->dev, "Could not get output clock\n");
> -               return PTR_ERR(host->clk_output);
> +               if (PTR_ERR(host->clk_output) != -ENOENT) {

This is new to me for how to implement support for optional clocks.

Is this how the clock maintainer think it should be implemented?

> +                       dev_err(&pdev->dev, "Could not get output clock\n");
> +                       return PTR_ERR(host->clk_output);
> +               }
> +               host->clk_output = NULL;
>         }
>
>         host->clk_sample = devm_clk_get(&pdev->dev, "sample");
>         if (IS_ERR(host->clk_sample)) {
> -               dev_err(&pdev->dev, "Could not get sample clock\n");
> -               return PTR_ERR(host->clk_sample);
> +               if (PTR_ERR(host->clk_sample) != -ENOENT) {
> +                       dev_err(&pdev->dev, "Could not get sample clock\n");
> +                       return PTR_ERR(host->clk_sample);
> +               }
> +               host->clk_sample = NULL;
>         }
>
>         host->reset = devm_reset_control_get_optional(&pdev->dev, "ahb");
> @@ -1126,9 +1132,11 @@ static int sunxi_mmc_probe(struct platform_device *pdev)
>         mmc->f_min              =   400000;
>         mmc->f_max              = 52000000;
>         mmc->caps              |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
> -                                 MMC_CAP_1_8V_DDR |
>                                   MMC_CAP_ERASE | MMC_CAP_SDIO_IRQ;
>
> +       if (host->clk_output && host->clk_sample)
> +               mmc->caps      |= MMC_CAP_1_8V_DDR;
> +
>         ret = mmc_of_parse(mmc);
>         if (ret)
>                 goto error_free_dma;
> --
> 2.7.4
>

Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Maxime Ripard July 25, 2016, 8:18 a.m. UTC | #2
Hi,

On Sat, Jul 16, 2016 at 12:46:02PM +0200, Hans de Goede wrote:
> It turns out that sun4i (A10) and sun5i (A13 & co) do not have sample
> clocks, so make them optional.
> 
> Since these do not have sample clocks, they cannot (reliably) do
> DDR rates, so only set MMC_CAP_1_8V_DDR when we do have sample clks.
> 
> Note this patch only changes the devm_clk_get error checking and sets
> the clocks to NULL if they don't exists. All the clk_foo calls accept
> a NULL clk and will return success when called with a NULL clk, so this
> is all that is necessary.

The clocks aren't really optional. They're not needed for the A10 /
A13, and mandatory for the A20 and later.

Having a new compatible for the A20 that would require that clock and
not require it for the A10/A13 anymore seems more appropriate.

Maxime
Hans de Goede July 30, 2016, 2:25 p.m. UTC | #3
Hi,

On 25-07-16 10:18, Maxime Ripard wrote:
> Hi,
>
> On Sat, Jul 16, 2016 at 12:46:02PM +0200, Hans de Goede wrote:
>> It turns out that sun4i (A10) and sun5i (A13 & co) do not have sample
>> clocks, so make them optional.
>>
>> Since these do not have sample clocks, they cannot (reliably) do
>> DDR rates, so only set MMC_CAP_1_8V_DDR when we do have sample clks.
>>
>> Note this patch only changes the devm_clk_get error checking and sets
>> the clocks to NULL if they don't exists. All the clk_foo calls accept
>> a NULL clk and will return success when called with a NULL clk, so this
>> is all that is necessary.
>
> The clocks aren't really optional. They're not needed for the A10 /
> A13, and mandatory for the A20 and later.
>
> Having a new compatible for the A20 that would require that clock and
> not require it for the A10/A13 anymore seems more appropriate.

Ok, I've prepared a new version using a new compatible.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 71a480b..4552ee0 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -1016,14 +1016,20 @@  static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
 
 	host->clk_output = devm_clk_get(&pdev->dev, "output");
 	if (IS_ERR(host->clk_output)) {
-		dev_err(&pdev->dev, "Could not get output clock\n");
-		return PTR_ERR(host->clk_output);
+		if (PTR_ERR(host->clk_output) != -ENOENT) {
+			dev_err(&pdev->dev, "Could not get output clock\n");
+			return PTR_ERR(host->clk_output);
+		}
+		host->clk_output = NULL;
 	}
 
 	host->clk_sample = devm_clk_get(&pdev->dev, "sample");
 	if (IS_ERR(host->clk_sample)) {
-		dev_err(&pdev->dev, "Could not get sample clock\n");
-		return PTR_ERR(host->clk_sample);
+		if (PTR_ERR(host->clk_sample) != -ENOENT) {
+			dev_err(&pdev->dev, "Could not get sample clock\n");
+			return PTR_ERR(host->clk_sample);
+		}
+		host->clk_sample = NULL;
 	}
 
 	host->reset = devm_reset_control_get_optional(&pdev->dev, "ahb");
@@ -1126,9 +1132,11 @@  static int sunxi_mmc_probe(struct platform_device *pdev)
 	mmc->f_min		=   400000;
 	mmc->f_max		= 52000000;
 	mmc->caps	       |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
-				  MMC_CAP_1_8V_DDR |
 				  MMC_CAP_ERASE | MMC_CAP_SDIO_IRQ;
 
+	if (host->clk_output && host->clk_sample)
+		mmc->caps      |= MMC_CAP_1_8V_DDR;
+
 	ret = mmc_of_parse(mmc);
 	if (ret)
 		goto error_free_dma;