mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mci: arasan: rework register_sdclk
@ 2024-04-09  5:57 Steffen Trumtrar
  2024-04-09 13:04 ` Sascha Hauer
  2024-04-09 13:06 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Steffen Trumtrar @ 2024-04-09  5:57 UTC (permalink / raw)
  To: barebox

Instead of guarding this at compile time, always call register_sdclk
with the correct clk_ops, like in linux.

Currently only ZynqMP and default arasan ops are supported.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
Instead of guarding the zynqmp functions at compile time and introducing
possible run-time problems, copy more of the linux driver and add
soc-specific clk_ops.

As the zynqmp_pm_* functions are only defined for ARCH_ZYNQMP we need to
add stub function definitions for other platforms that might use the
arasan-sdhci driver.
---
 drivers/mci/arasan-sdhci.c            | 53 ++++++++++++++++++++++++-----------
 include/mach/zynqmp/firmware-zynqmp.h | 11 ++++++++
 2 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
index b7dd98049f..5187dbe468 100644
--- a/drivers/mci/arasan-sdhci.c
+++ b/drivers/mci/arasan-sdhci.c
@@ -65,6 +65,8 @@ struct arasan_sdhci_host {
 	struct mci_host		mci;
 	struct sdhci		sdhci;
 	unsigned int		quirks; /* Arasan deviations from spec */
+	const struct clk_ops	*sdcardclk_ops;
+	const struct clk_ops	*sampleclk_ops;
 	struct sdhci_arasan_clk_data clk_data;
 /* Controller does not have CD wired and will not function normally without */
 #define SDHCI_ARASAN_QUIRK_FORCE_CDTEST		BIT(0)
@@ -352,7 +354,7 @@ static void arasan_dt_read_clk_phase(struct device *dev,
  *
  * Return: 0 on success and error value on error
  */
-static int arasan_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
+static __maybe_unused int arasan_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
 {
 	struct sdhci_arasan_clk_data *clk_data =
 		container_of(hw, struct sdhci_arasan_clk_data, sampleclk_hw);
@@ -402,8 +404,8 @@ static int arasan_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
 	return ret;
 }
 
-static unsigned long arasan_zynqmp_sampleclk_recalc_rate(struct clk_hw *hw,
-							 unsigned long parent_rate)
+static unsigned long arasan_sampleclk_recalc_rate(struct clk_hw *hw,
+						  unsigned long parent_rate)
 {
 	struct sdhci_arasan_clk_data *clk_data =
 		container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw);
@@ -424,7 +426,7 @@ static unsigned long arasan_zynqmp_sampleclk_recalc_rate(struct clk_hw *hw,
  *
  * Return: 0 on success and error value on error
  */
-static int arasan_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
+static __maybe_unused int arasan_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
 {
 	struct sdhci_arasan_clk_data *clk_data =
 		container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw);
@@ -474,8 +476,8 @@ static int arasan_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
 	return ret;
 }
 
-static unsigned long arasan_zynqmp_sdcardclk_recalc_rate(struct clk_hw *hw,
-							 unsigned long parent_rate)
+static unsigned long arasan_sdcardclk_recalc_rate(struct clk_hw *hw,
+						  unsigned long parent_rate)
 {
 	struct sdhci_arasan_clk_data *clk_data =
 		container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw);
@@ -486,13 +488,21 @@ static unsigned long arasan_zynqmp_sdcardclk_recalc_rate(struct clk_hw *hw,
 	return host->actual_clock;
 };
 
-static const struct clk_ops clk_sampleclk_ops = {
-	.recalc_rate = arasan_zynqmp_sampleclk_recalc_rate,
+static const struct clk_ops arasan_sampleclk_ops = {
+	.recalc_rate = arasan_sampleclk_recalc_rate,
+};
+
+static const struct clk_ops arasan_sdcardclk_ops = {
+	.recalc_rate = arasan_sdcardclk_recalc_rate,
+};
+
+static const struct clk_ops zynqmp_sampleclk_ops = {
+	.recalc_rate = arasan_sampleclk_recalc_rate,
 	.set_phase = arasan_zynqmp_sampleclk_set_phase,
 };
 
-static const struct clk_ops clk_sdcardclk_ops = {
-	.recalc_rate = arasan_zynqmp_sdcardclk_recalc_rate,
+static const struct clk_ops zynqmp_sdcardclk_ops = {
+	.recalc_rate = arasan_sdcardclk_recalc_rate,
 	.set_phase = arasan_zynqmp_sdcardclk_set_phase,
 };
 
@@ -510,10 +520,11 @@ static const struct clk_ops clk_sdcardclk_ops = {
  * Return: 0 on success and error value on error
  */
 static int
-arasan_sdhci_register_sampleclk(struct sdhci_arasan_clk_data *clk_data,
+arasan_sdhci_register_sampleclk(struct arasan_sdhci_host *sdhci_arasan,
 				struct clk *clk_xin,
 				struct device *dev)
 {
+	struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data;
 	struct device_node *np = dev->of_node;
 	struct clk_init_data sampleclk_init = {};
 	const char *clk_name;
@@ -529,7 +540,7 @@ arasan_sdhci_register_sampleclk(struct sdhci_arasan_clk_data *clk_data,
 	clk_name = __clk_get_name(clk_xin);
 	sampleclk_init.parent_names = &clk_name;
 	sampleclk_init.num_parents = 1;
-	sampleclk_init.ops = &clk_sampleclk_ops;
+	sampleclk_init.ops = sdhci_arasan->sampleclk_ops;
 
 	clk_data->sampleclk_hw.init = &sampleclk_init;
 	clk_data->sampleclk = clk_register(dev, &clk_data->sampleclk_hw);
@@ -559,10 +570,11 @@ arasan_sdhci_register_sampleclk(struct sdhci_arasan_clk_data *clk_data,
  * Return: 0 on success and error value on error
  */
 static int
-arasan_sdhci_register_sdcardclk(struct sdhci_arasan_clk_data *clk_data,
+arasan_sdhci_register_sdcardclk(struct arasan_sdhci_host *sdhci_arasan,
 				struct clk *clk_xin,
 				struct device *dev)
 {
+	struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data;
 	struct device_node *np = dev->of_node;
 	struct clk_init_data sdcardclk_init = {};
 	const char *clk_name;
@@ -577,7 +589,7 @@ arasan_sdhci_register_sdcardclk(struct sdhci_arasan_clk_data *clk_data,
 
 	clk_name = __clk_get_name(clk_xin);
 	sdcardclk_init.parent_names = &clk_name;
-	sdcardclk_init.ops = &clk_sdcardclk_ops;
+	sdcardclk_init.ops = sdhci_arasan->sdcardclk_ops;
 	sdcardclk_init.num_parents = 1;
 
 	clk_data->sdcardclk_hw.init = &sdcardclk_init;
@@ -615,7 +627,7 @@ arasan_sdhci_register_sdcardclk(struct sdhci_arasan_clk_data *clk_data,
  *
  * Return: 0 on success and error value on error
  */
-static int arasan_sdhci_register_sdclk(struct sdhci_arasan_clk_data *sdhci_arasan,
+static int arasan_sdhci_register_sdclk(struct arasan_sdhci_host *sdhci_arasan,
 				       struct clk *clk_xin,
 				       struct device *dev)
 {
@@ -772,8 +784,15 @@ static int arasan_sdhci_probe(struct device *dev)
 
 	mci->f_min = 50000000 / 256;
 
-	if (IS_ENABLED(CONFIG_ARCH_ZYNQMP))
-		arasan_sdhci_register_sdclk(&arasan_sdhci->clk_data, clk_xin, dev);
+	if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) {
+		arasan_sdhci->sdcardclk_ops = &zynqmp_sdcardclk_ops;
+		arasan_sdhci->sampleclk_ops = &zynqmp_sampleclk_ops;
+	} else {
+		arasan_sdhci->sdcardclk_ops = &arasan_sdcardclk_ops;
+		arasan_sdhci->sampleclk_ops = &arasan_sampleclk_ops;
+	}
+
+	arasan_sdhci_register_sdclk(arasan_sdhci, clk_xin, dev);
 
 	arasan_dt_parse_clk_phases(dev, &arasan_sdhci->clk_data);
 
diff --git a/include/mach/zynqmp/firmware-zynqmp.h b/include/mach/zynqmp/firmware-zynqmp.h
index 00c63058f4..9f833189d3 100644
--- a/include/mach/zynqmp/firmware-zynqmp.h
+++ b/include/mach/zynqmp/firmware-zynqmp.h
@@ -119,8 +119,19 @@ struct zynqmp_eemi_ops {
 
 const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void);
 
+#if defined(CONFIG_ARCH_ZYNQMP)
 int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value);
 int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type);
+#else
+static inline int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
+{
+	return -ENOSYS;
+}
+static inline int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
+{
+	return -ENOSYS;
+}
+#endif
 
 int zynqmp_pm_write_ggs(u32 index, u32 value);
 int zynqmp_pm_read_ggs(u32 index, u32 *value);

---
base-commit: aa03dc194997eabf157118b76b0ab5ef88a9faff
change-id: 20240408-v2024-03-0-topic-arasan-fixes-199c8b0710dc

Best regards,
-- 
Steffen Trumtrar <s.trumtrar@pengutronix.de>




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

* Re: [PATCH] mci: arasan: rework register_sdclk
  2024-04-09  5:57 [PATCH] mci: arasan: rework register_sdclk Steffen Trumtrar
@ 2024-04-09 13:04 ` Sascha Hauer
  2024-04-09 13:06 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-04-09 13:04 UTC (permalink / raw)
  To: barebox, Steffen Trumtrar


On Tue, 09 Apr 2024 07:57:20 +0200, Steffen Trumtrar wrote:
> Instead of guarding this at compile time, always call register_sdclk
> with the correct clk_ops, like in linux.
> 
> Currently only ZynqMP and default arasan ops are supported.
> 
> 

Applied, thanks!

[1/1] mci: arasan: rework register_sdclk
      https://git.pengutronix.de/cgit/barebox/commit/?id=70791fb7f1aa (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

* Re: [PATCH] mci: arasan: rework register_sdclk
  2024-04-09  5:57 [PATCH] mci: arasan: rework register_sdclk Steffen Trumtrar
  2024-04-09 13:04 ` Sascha Hauer
@ 2024-04-09 13:06 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-04-09 13:06 UTC (permalink / raw)
  To: Steffen Trumtrar; +Cc: barebox

On Tue, Apr 09, 2024 at 07:57:20AM +0200, Steffen Trumtrar wrote:
> Instead of guarding this at compile time, always call register_sdclk
> with the correct clk_ops, like in linux.
> 
> Currently only ZynqMP and default arasan ops are supported.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
> Instead of guarding the zynqmp functions at compile time and introducing
> possible run-time problems, copy more of the linux driver and add
> soc-specific clk_ops.
> 
> As the zynqmp_pm_* functions are only defined for ARCH_ZYNQMP we need to
> add stub function definitions for other platforms that might use the
> arasan-sdhci driver.
> ---
>  drivers/mci/arasan-sdhci.c            | 53 ++++++++++++++++++++++++-----------
>  include/mach/zynqmp/firmware-zynqmp.h | 11 ++++++++
>  2 files changed, 47 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
> index b7dd98049f..5187dbe468 100644
> --- a/drivers/mci/arasan-sdhci.c
> +++ b/drivers/mci/arasan-sdhci.c
> @@ -65,6 +65,8 @@ struct arasan_sdhci_host {
>  	struct mci_host		mci;
>  	struct sdhci		sdhci;
>  	unsigned int		quirks; /* Arasan deviations from spec */
> +	const struct clk_ops	*sdcardclk_ops;
> +	const struct clk_ops	*sampleclk_ops;
>  	struct sdhci_arasan_clk_data clk_data;
>  /* Controller does not have CD wired and will not function normally without */
>  #define SDHCI_ARASAN_QUIRK_FORCE_CDTEST		BIT(0)
> @@ -352,7 +354,7 @@ static void arasan_dt_read_clk_phase(struct device *dev,
>   *
>   * Return: 0 on success and error value on error
>   */
> -static int arasan_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)
> +static __maybe_unused int arasan_zynqmp_sampleclk_set_phase(struct clk_hw *hw, int degrees)

Dropped this unnecessary __maybe_unused here...

> -static int arasan_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
> +static __maybe_unused int arasan_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)

...and here while applying.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2024-04-09 13:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09  5:57 [PATCH] mci: arasan: rework register_sdclk Steffen Trumtrar
2024-04-09 13:04 ` Sascha Hauer
2024-04-09 13:06 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox