All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock
@ 2020-07-08 20:24 Eddie James
  2020-07-08 20:24 ` [PATCH linux dev-5.4 2/2] mmc: sdhci-of-aspeed: Prevent clock divider of zero Eddie James
  2020-07-09 11:34 ` [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock Andrew Jeffery
  0 siblings, 2 replies; 4+ messages in thread
From: Eddie James @ 2020-07-08 20:24 UTC (permalink / raw)
  To: openbmc; +Cc: joel, Eddie James

The EMMC clock can be derived from either the HPLL or the MPLL. Register
a clock mux so that the rate is calculated correctly based upon the
parent.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/clk/clk-ast2600.c | 49 ++++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/clk-ast2600.c b/drivers/clk/clk-ast2600.c
index 35f53956c762..bbacaccad554 100644
--- a/drivers/clk/clk-ast2600.c
+++ b/drivers/clk/clk-ast2600.c
@@ -131,6 +131,18 @@ static const struct clk_div_table ast2600_eclk_div_table[] = {
 	{ 0 }
 };
 
+static const struct clk_div_table ast2600_emmc_extclk_div_table[] = {
+	{ 0x0, 2 },
+	{ 0x1, 4 },
+	{ 0x2, 6 },
+	{ 0x3, 8 },
+	{ 0x4, 10 },
+	{ 0x5, 12 },
+	{ 0x6, 14 },
+	{ 0x7, 16 },
+	{ 0 }
+};
+
 static const struct clk_div_table ast2600_mac_div_table[] = {
 	{ 0x0, 4 },
 	{ 0x1, 4 },
@@ -390,6 +402,11 @@ static struct clk_hw *aspeed_g6_clk_hw_register_gate(struct device *dev,
 	return hw;
 }
 
+static const char *const emmc_extclk_parent_names[] = {
+	"emmc_extclk_hpll_in",
+	"mpll",
+};
+
 static const char * const vclk_parent_names[] = {
 	"dpll",
 	"d1pll",
@@ -459,16 +476,32 @@ static int aspeed_g6_clk_probe(struct platform_device *pdev)
 		return PTR_ERR(hw);
 	aspeed_g6_clk_data->hws[ASPEED_CLK_UARTX] = hw;
 
-	/* EMMC ext clock divider */
-	hw = clk_hw_register_gate(dev, "emmc_extclk_gate", "hpll", 0,
-			scu_g6_base + ASPEED_G6_CLK_SELECTION1, 15, 0,
-			&aspeed_g6_clk_lock);
+	/* EMMC ext clock */
+	hw = clk_hw_register_fixed_factor(dev, "emmc_extclk_hpll_in", "hpll",
+					  0, 1, 2);
 	if (IS_ERR(hw))
 		return PTR_ERR(hw);
-	hw = clk_hw_register_divider_table(dev, "emmc_extclk", "emmc_extclk_gate", 0,
-			scu_g6_base + ASPEED_G6_CLK_SELECTION1, 12, 3, 0,
-			ast2600_div_table,
-			&aspeed_g6_clk_lock);
+
+	hw = clk_hw_register_mux(dev, "emmc_extclk_mux",
+				 emmc_extclk_parent_names,
+				 ARRAY_SIZE(emmc_extclk_parent_names), 0,
+				 scu_g6_base + ASPEED_G6_CLK_SELECTION1, 11, 1,
+				 0, &aspeed_g6_clk_lock);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+
+	hw = clk_hw_register_gate(dev, "emmc_extclk_gate", "emmc_extclk_mux",
+				  0, scu_g6_base + ASPEED_G6_CLK_SELECTION1,
+				  15, 0, &aspeed_g6_clk_lock);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+
+	hw = clk_hw_register_divider_table(dev, "emmc_extclk",
+					   "emmc_extclk_gate", 0,
+					   scu_g6_base +
+						ASPEED_G6_CLK_SELECTION1, 12,
+					   3, 0, ast2600_emmc_extclk_div_table,
+					   &aspeed_g6_clk_lock);
 	if (IS_ERR(hw))
 		return PTR_ERR(hw);
 	aspeed_g6_clk_data->hws[ASPEED_CLK_EMMC] = hw;
-- 
2.24.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH linux dev-5.4 2/2] mmc: sdhci-of-aspeed: Prevent clock divider of zero
  2020-07-08 20:24 [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock Eddie James
@ 2020-07-08 20:24 ` Eddie James
  2020-07-09 11:56   ` Andrew Jeffery
  2020-07-09 11:34 ` [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock Andrew Jeffery
  1 sibling, 1 reply; 4+ messages in thread
From: Eddie James @ 2020-07-08 20:24 UTC (permalink / raw)
  To: openbmc; +Cc: joel, Eddie James

The Aspeed specification forbids a clock divider of zero, which will be
calculated if the parent clock is equal to the desired clock. Testing
confirmed this broke the host controller.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/mmc/host/sdhci-of-aspeed.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mmc/host/sdhci-of-aspeed.c b/drivers/mmc/host/sdhci-of-aspeed.c
index 8962f6664381..5aa72e80cae9 100644
--- a/drivers/mmc/host/sdhci-of-aspeed.c
+++ b/drivers/mmc/host/sdhci-of-aspeed.c
@@ -74,6 +74,10 @@ static void aspeed_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 	}
 	div >>= 1;
 
+	/* Aspeed forbids a clock div of 0 */
+	if (!div)
+		div = 1;
+
 	clk = div << SDHCI_DIVIDER_SHIFT;
 
 	sdhci_enable_clk(host, clk);
-- 
2.24.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock
  2020-07-08 20:24 [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock Eddie James
  2020-07-08 20:24 ` [PATCH linux dev-5.4 2/2] mmc: sdhci-of-aspeed: Prevent clock divider of zero Eddie James
@ 2020-07-09 11:34 ` Andrew Jeffery
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Jeffery @ 2020-07-09 11:34 UTC (permalink / raw)
  To: Eddie James, openbmc



On Thu, 9 Jul 2020, at 05:54, Eddie James wrote:
> The EMMC clock can be derived from either the HPLL or the MPLL. Register
> a clock mux so that the rate is calculated correctly based upon the
> parent.
> 
> Signed-off-by: Eddie James <eajames@linux.ibm.com>

Reviewed-by: Andrew Jeffery <andrew@aj.id.au>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH linux dev-5.4 2/2] mmc: sdhci-of-aspeed: Prevent clock divider of zero
  2020-07-08 20:24 ` [PATCH linux dev-5.4 2/2] mmc: sdhci-of-aspeed: Prevent clock divider of zero Eddie James
@ 2020-07-09 11:56   ` Andrew Jeffery
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Jeffery @ 2020-07-09 11:56 UTC (permalink / raw)
  To: Eddie James, openbmc



On Thu, 9 Jul 2020, at 05:54, Eddie James wrote:
> The Aspeed specification forbids a clock divider of zero, which will be
> calculated if the parent clock is equal to the desired clock. Testing
> confirmed this broke the host controller.
> 
> Signed-off-by: Eddie James <eajames@linux.ibm.com>
> ---
>  drivers/mmc/host/sdhci-of-aspeed.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci-of-aspeed.c 
> b/drivers/mmc/host/sdhci-of-aspeed.c
> index 8962f6664381..5aa72e80cae9 100644
> --- a/drivers/mmc/host/sdhci-of-aspeed.c
> +++ b/drivers/mmc/host/sdhci-of-aspeed.c
> @@ -74,6 +74,10 @@ static void aspeed_sdhci_set_clock(struct sdhci_host 
> *host, unsigned int clock)
>  	}
>  	div >>= 1;
>  
> +	/* Aspeed forbids a clock div of 0 */
> +	if (!div)
> +		div = 1;
> +

Nah, the search loop needs to initialise with div = 2. The current implementation is busted.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-09 11:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 20:24 [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock Eddie James
2020-07-08 20:24 ` [PATCH linux dev-5.4 2/2] mmc: sdhci-of-aspeed: Prevent clock divider of zero Eddie James
2020-07-09 11:56   ` Andrew Jeffery
2020-07-09 11:34 ` [PATCH linux dev-5.4 1/2] clk: AST2600: Add mux for EMMC clock Andrew Jeffery

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.