Skip to contentSkip to conversation

mfd: madera: Update DT binding document to support clock supplies

PATCH Superseded Charles Keepax 3 participants 8 messages Aug 6, 2019 – Aug 13, 2019

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Charles Keepax

author maintainer
#0 lore raw

PATCH 1/2 mfd: madera: Update DT binding document to support clock supplies

Add the 3 input clock sources for the chip into the device tree binding document.

---
 Documentation/devicetree/bindings/mfd/madera.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/mfd/madera.txt +8 -0
index cad0f28005027..47e2b8bc60519 100644
@@ -67,6 +67,14 @@ Optional properties:
     As defined in bindings/gpio.txt.
     Although optional, it is strongly recommended to use a hardware reset
 
+  - clocks: Should reference the clocks supplied on MCLK1, MCLK2 and MCLK3
+  - clock-names: May contain up to three strings:
+      "mclk1" for the clock supplied on MCLK1, recommended to be a high
+      quality audio reference clock
+      "mclk2" for the clock supplied on MCLK2, required to be an always on
+      32k clock
+      "mclk3" for the clock supplied on MCLK3
+
   - MICBIASx : Initial data for the MICBIAS regulators, as covered in
     Documentation/devicetree/bindings/regulator/regulator.txt.
     One for each MICBIAS generator (MICBIAS1, MICBIAS2, ...)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 2/2 mfd: madera: Add support for requesting the supply clocks

Add the ability to get the clock for each clock input pin of the chip and enable MCLK2 since that is expected to be a permanently enabled 32kHz clock.

---
 drivers/mfd/madera-core.c       | 24 +++++++++++++++++++++++-
 include/linux/mfd/madera/core.h | 11 +++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
drivers/mfd/madera-core.c +23 -1
index 29540cbf75934..8d7ab1c7bf9f7 100644
@@ -428,6 +428,7 @@ static void madera_set_micbias_info(struct madera *madera)
 
 int madera_dev_init(struct madera *madera)
 {
+	static const char * const mclk_name[] = { "mclk1", "mclk2", "mclk3" };
 	struct device *dev = madera->dev;
 	unsigned int hwid;
 	int (*patch_fn)(struct madera *) = NULL;
@@ -450,6 +451,17 @@ int madera_dev_init(struct madera *madera)
 		       sizeof(madera->pdata));
 	}
 
+	BUILD_BUG_ON(ARRAY_SIZE(madera->mclk) != ARRAY_SIZE(mclk_name));
+	for (i = 0; i < ARRAY_SIZE(madera->mclk); i++) {
+		madera->mclk[i] = devm_clk_get_optional(madera->dev,
+							mclk_name[i]);
+		if (IS_ERR(madera->mclk[i])) {
+			dev_warn(madera->dev, "Failed to get %s: %ld\n",
+				 mclk_name[i], PTR_ERR(madera->mclk[i]));
+			madera->mclk[i] = NULL;
+		}
+	}
+
 	ret = madera_get_reset_gpio(madera);
 	if (ret)
 		return ret;
@@ -660,13 +672,19 @@ int madera_dev_init(struct madera *madera)
 	}
 
 	/* Init 32k clock sourced from MCLK2 */
+	ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2]);
+	if (ret != 0) {
+		dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret);
+		goto err_reset;
+	}
+
 	ret = regmap_update_bits(madera->regmap,
 			MADERA_CLOCK_32K_1,
 			MADERA_CLK_32K_ENA_MASK | MADERA_CLK_32K_SRC_MASK,
 			MADERA_CLK_32K_ENA | MADERA_32KZ_MCLK2);
 	if (ret) {
 		dev_err(madera->dev, "Failed to init 32k clock: %d\n", ret);
-		goto err_reset;
+		goto err_clock;
 	}
 
 	pm_runtime_set_active(madera->dev);
@@ -687,6 +705,8 @@ int madera_dev_init(struct madera *madera)
 
 err_pm_runtime:
 	pm_runtime_disable(madera->dev);
+err_clock:
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);
 err_reset:
 	madera_enable_hard_reset(madera);
 	regulator_disable(madera->dcvdd);
@@ -713,6 +733,8 @@ int madera_dev_exit(struct madera *madera)
 	 */
 	pm_runtime_disable(madera->dev);
 
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);
+
 	regulator_disable(madera->dcvdd);
 	regulator_put(madera->dcvdd);
 
include/linux/mfd/madera/core.h +11 -0
index 7ffa696cce7ca..2b6c83fe221dc 100644
@@ -8,6 +8,7 @@
 #ifndef MADERA_CORE_H
 #define MADERA_CORE_H
 
+#include <linux/clk.h>
 #include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/mfd/madera/pdata.h>
@@ -29,6 +30,13 @@ enum madera_type {
 	CS42L92 = 9,
 };
 
+enum {
+	MADERA_MCLK1,
+	MADERA_MCLK2,
+	MADERA_MCLK3,
+	MADERA_NUM_MCLK
+};
+
 #define MADERA_MAX_CORE_SUPPLIES	2
 #define MADERA_MAX_GPIOS		40
 
@@ -155,6 +163,7 @@ struct snd_soc_dapm_context;
  * @irq_dev:		the irqchip child driver device
  * @irq_data:		pointer to irqchip data for the child irqchip driver
  * @irq:		host irq number from SPI or I2C configuration
+ * @mclk:		pointers to clock supplies
  * @out_clamp:		indicates output clamp state for each analogue output
  * @out_shorted:	indicates short circuit state for each analogue output
  * @hp_ena:		bitflags of enable state for the headphone outputs
@@ -184,6 +193,8 @@ struct madera {
 	struct regmap_irq_chip_data *irq_data;
 	int irq;
 
+	struct clk *mclk[MADERA_NUM_MCLK];
+
 	unsigned int num_micbias;
 	unsigned int num_childbias[MADERA_MAX_MICBIAS];
 
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH 2/2] mfd: madera: Add support for requesting the supply clocks

Quoted 23 lines · Charles Keepax

Add the ability to get the clock for each clock input pin of the chip and enable MCLK2 since that is expected to be a permanently enabled 32kHz clock.

---
 drivers/mfd/madera-core.c       | 24 +++++++++++++++++++++++-
 include/linux/mfd/madera/core.h | 11 +++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
drivers/mfd/madera-core.c +1 -0
index 29540cbf75934..8d7ab1c7bf9f7 100644
@@ -428,6 +428,7 @@ static void madera_set_micbias_info(struct madera *madera)
 
 int madera_dev_init(struct madera *madera)
 {
+	static const char * const mclk_name[] = { "mclk1", "mclk2", "mclk3" };
 	struct device *dev = madera->dev;
 	unsigned int hwid;
 	int (*patch_fn)(struct madera *) = NULL;

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 454

Quoted 4 lines
drivers/mfd/madera-core.c +1 -0
@@ -450,6 +451,17 @@ int madera_dev_init(struct madera *madera)
 		       sizeof(madera->pdata));
 	}
 
+	BUILD_BUG_ON(ARRAY_SIZE(madera->mclk) != ARRAY_SIZE(mclk_name));

Not sure how this could happen. Surely we don't need it.

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 460

Quoted 6 lines
drivers/mfd/madera-core.c +6 -0
+	for (i = 0; i < ARRAY_SIZE(madera->mclk); i++) {
+		madera->mclk[i] = devm_clk_get_optional(madera->dev,
+							mclk_name[i]);
+		if (IS_ERR(madera->mclk[i])) {
+			dev_warn(madera->dev, "Failed to get %s: %ld\n",
+				 mclk_name[i], PTR_ERR(madera->mclk[i]));

Do we even want to warn on the non-acquisition of an optional clock?

Especially with a message that looks like something actually failed.

Quoted 8 lines
drivers/mfd/madera-core.c +4 -0
+			madera->mclk[i] = NULL;
+		}
+	}
+
 	ret = madera_get_reset_gpio(madera);
 	if (ret)
 		return ret;

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 679

Quoted 8 lines
drivers/mfd/madera-core.c +5 -0
@@ -660,13 +672,19 @@ int madera_dev_init(struct madera *madera)
 	}
 
 	/* Init 32k clock sourced from MCLK2 */
+	ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2]);
+	if (ret != 0) {
+		dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret);
+		goto err_reset;
+	}

What happened to this being optional?

Quoted 12 lines
drivers/mfd/madera-core.c +1 -1
 	ret = regmap_update_bits(madera->regmap,
 			MADERA_CLOCK_32K_1,
 			MADERA_CLK_32K_ENA_MASK | MADERA_CLK_32K_SRC_MASK,
 			MADERA_CLK_32K_ENA | MADERA_32KZ_MCLK2);
 	if (ret) {
 		dev_err(madera->dev, "Failed to init 32k clock: %d\n", ret);
-		goto err_reset;
+		goto err_clock;
 	}
 
 	pm_runtime_set_active(madera->dev);

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 709

Quoted 5 lines
drivers/mfd/madera-core.c +2 -0
@@ -687,6 +705,8 @@ int madera_dev_init(struct madera *madera)
 
 err_pm_runtime:
 	pm_runtime_disable(madera->dev);
+err_clock:
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);

Where are the other clocks consumed?

Quoted 55 lines
drivers/mfd/madera-core.c +2 -0
 err_reset:
 	madera_enable_hard_reset(madera);
 	regulator_disable(madera->dcvdd);
@@ -713,6 +733,8 @@ int madera_dev_exit(struct madera *madera)
 	 */
 	pm_runtime_disable(madera->dev);
 
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);
+
 	regulator_disable(madera->dcvdd);
 	regulator_put(madera->dcvdd);
 
include/linux/mfd/madera/core.h +11 -0
index 7ffa696cce7ca..2b6c83fe221dc 100644
@@ -8,6 +8,7 @@
 #ifndef MADERA_CORE_H
 #define MADERA_CORE_H
 
+#include <linux/clk.h>
 #include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/mfd/madera/pdata.h>
@@ -29,6 +30,13 @@ enum madera_type {
 	CS42L92 = 9,
 };
 
+enum {
+	MADERA_MCLK1,
+	MADERA_MCLK2,
+	MADERA_MCLK3,
+	MADERA_NUM_MCLK
+};
+
 #define MADERA_MAX_CORE_SUPPLIES	2
 #define MADERA_MAX_GPIOS		40
 
@@ -155,6 +163,7 @@ struct snd_soc_dapm_context;
  * @irq_dev:		the irqchip child driver device
  * @irq_data:		pointer to irqchip data for the child irqchip driver
  * @irq:		host irq number from SPI or I2C configuration
+ * @mclk:		pointers to clock supplies
  * @out_clamp:		indicates output clamp state for each analogue output
  * @out_shorted:	indicates short circuit state for each analogue output
  * @hp_ena:		bitflags of enable state for the headphone outputs
@@ -184,6 +193,8 @@ struct madera {
 	struct regmap_irq_chip_data *irq_data;
 	int irq;
 
+	struct clk *mclk[MADERA_NUM_MCLK];
+
 	unsigned int num_micbias;
 	unsigned int num_childbias[MADERA_MAX_MICBIAS];
 
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#7 lore raw
In reply to Charles Keepax
Quoted 7 lines · Charles Keepax

Add the 3 input clock sources for the chip into the device tree binding document.

---
 Documentation/devicetree/bindings/mfd/madera.txt | 8 ++++++++
 1 file changed, 8 insertions(+)

For my own reference:

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#3 lore raw

Re: [PATCH 2/2] mfd: madera: Add support for requesting the supply clocks

In reply to Lee Jones
Quoted 18 lines · Lee Jones
Quoted 16 lines · Charles Keepax

Add the ability to get the clock for each clock input pin of the chip and enable MCLK2 since that is expected to be a permanently enabled 32kHz clock.

---
int madera_dev_init(struct madera *madera)
{

drivers/mfd/madera-core.c +1 -0
+	static const char * const mclk_name[] = { "mclk1", "mclk2", "mclk3" };
 	struct device *dev = madera->dev;
 	unsigned int hwid;
 	int (*patch_fn)(struct madera *) = NULL;
@@ -450,6 +451,17 @@ int madera_dev_init(struct madera *madera)
 		       sizeof(madera->pdata));
 	}
 
Quoted 4 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 454

Quoted 1 line
drivers/mfd/madera-core.c +1 -0
+	BUILD_BUG_ON(ARRAY_SIZE(madera->mclk) != ARRAY_SIZE(mclk_name));

Not sure how this could happen. Surely we don't need it.

mclk_name is defined locally in this function and the mclk array in include/linux/mfd/madera/core.h. This is to guard against one of them being updated but not the other. It is by no means essential but it feels like a good trade off given there is really limited downside.

Quoted 11 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 460

Quoted 6 lines
drivers/mfd/madera-core.c +6 -0
+	for (i = 0; i < ARRAY_SIZE(madera->mclk); i++) {
+		madera->mclk[i] = devm_clk_get_optional(madera->dev,
+							mclk_name[i]);
+		if (IS_ERR(madera->mclk[i])) {
+			dev_warn(madera->dev, "Failed to get %s: %ld\n",
+				 mclk_name[i], PTR_ERR(madera->mclk[i]));

Do we even want to warn on the non-acquisition of an optional clock?

Especially with a message that looks like something actually failed.

devm_clk_get_optional will return NULL if the clock was not specified, so this is silent in that case. A warning in the case something actually went wrong seems reasonable even if the clock is optional as the user tried to do something and it didn't behave as they intended.

Quoted 10 lines
Quoted 10 lines
drivers/mfd/madera-core.c +4 -0
+			madera->mclk[i] = NULL;
+		}
+	}
+
 	ret = madera_get_reset_gpio(madera);
 	if (ret)
 		return ret;
@@ -660,13 +672,19 @@ int madera_dev_init(struct madera *madera)
 	}
 
Quoted 9 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 679

Quoted 6 lines
drivers/mfd/madera-core.c +5 -0
 	/* Init 32k clock sourced from MCLK2 */
+	ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2]);
+	if (ret != 0) {
+		dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret);
+		goto err_reset;
+	}

What happened to this being optional?

The device needs the clock but specifying it through DT is optional (the clock framework functions are no-ops and return success if the clock pointer is NULL). Normally the 32kHz clock is always on, and more importantly no existing users of the driver will be specifying one.

We could remove the optional status for MCLK2, but it could break existing users who don't yet specify the clock until they update their DT and it will complicate the code as the other clocks are definitely optional, so MCLK2 will need special handling.

Quoted 13 lines
Quoted 13 lines
drivers/mfd/madera-core.c +1 -1
 	ret = regmap_update_bits(madera->regmap,
 			MADERA_CLOCK_32K_1,
 			MADERA_CLK_32K_ENA_MASK | MADERA_CLK_32K_SRC_MASK,
 			MADERA_CLK_32K_ENA | MADERA_32KZ_MCLK2);
 	if (ret) {
 		dev_err(madera->dev, "Failed to init 32k clock: %d\n", ret);
-		goto err_reset;
+		goto err_clock;
 	}
 
 	pm_runtime_set_active(madera->dev);
@@ -687,6 +705,8 @@ int madera_dev_init(struct madera *madera)
 
Quoted 7 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 709

Quoted 4 lines
drivers/mfd/madera-core.c +2 -0
 err_pm_runtime:
 	pm_runtime_disable(madera->dev);
+err_clock:
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);

Where are the other clocks consumed?

Other clocks will be consumed by the ASoC part of the driver for clocking the audio functionality and running the FLLs. I haven't sent those patches yet, but was planning on doing so once this was merged.

Thanks,
Charles

#4 lore raw

Re: [PATCH 2/2] mfd: madera: Add support for requesting the supply clocks

Quoted 24 lines · Charles Keepax
Quoted 18 lines · Lee Jones
Quoted 16 lines · Charles Keepax

Add the ability to get the clock for each clock input pin of the chip and enable MCLK2 since that is expected to be a permanently enabled 32kHz clock.

---
int madera_dev_init(struct madera *madera)
{

drivers/mfd/madera-core.c +1 -0
+	static const char * const mclk_name[] = { "mclk1", "mclk2", "mclk3" };
  	struct device *dev = madera->dev;
  	unsigned int hwid;
  	int (*patch_fn)(struct madera *) = NULL;
@@ -450,6 +451,17 @@ int madera_dev_init(struct madera *madera)
  		       sizeof(madera->pdata));
  	}
 
Quoted 4 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 454

Quoted 1 line
drivers/mfd/madera-core.c +1 -0
+	BUILD_BUG_ON(ARRAY_SIZE(madera->mclk) != ARRAY_SIZE(mclk_name));

Not sure how this could happen. Surely we don't need it.

Quoted 6 lines

mclk_name is defined locally in this function and the mclk array in include/linux/mfd/madera/core.h. This is to guard against one of them being updated but not the other. It is by no means essential but it feels like a good trade off given there is really limited downside.

I'd like to keep it if we can. Nicer to pick up a mistake at build time than using runtime checking or falling off the end of an undersized array.
We use the same technique in the ASoC code.

Quoted 78 lines
Quoted 11 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 460

Quoted 6 lines
drivers/mfd/madera-core.c +6 -0
+	for (i = 0; i < ARRAY_SIZE(madera->mclk); i++) {
+		madera->mclk[i] = devm_clk_get_optional(madera->dev,
+							mclk_name[i]);
+		if (IS_ERR(madera->mclk[i])) {
+			dev_warn(madera->dev, "Failed to get %s: %ld\n",
+				 mclk_name[i], PTR_ERR(madera->mclk[i]));

Do we even want to warn on the non-acquisition of an optional clock?

Especially with a message that looks like something actually failed.

devm_clk_get_optional will return NULL if the clock was not specified, so this is silent in that case. A warning in the case something actually went wrong seems reasonable even if the clock is optional as the user tried to do something and it didn't behave as they intended.

Quoted 10 lines
Quoted 10 lines
drivers/mfd/madera-core.c +4 -0
+			madera->mclk[i] = NULL;
+		}
+	}
+
  	ret = madera_get_reset_gpio(madera);
  	if (ret)
  		return ret;
@@ -660,13 +672,19 @@ int madera_dev_init(struct madera *madera)
  	}
 
Quoted 9 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 679

Quoted 6 lines
drivers/mfd/madera-core.c +5 -0
  	/* Init 32k clock sourced from MCLK2 */
+	ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2]);
+	if (ret != 0) {
+		dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret);
+		goto err_reset;
+	}

What happened to this being optional?

The device needs the clock but specifying it through DT is optional (the clock framework functions are no-ops and return success if the clock pointer is NULL). Normally the 32kHz clock is always on, and more importantly no existing users of the driver will be specifying one.

We could remove the optional status for MCLK2, but it could break existing users who don't yet specify the clock until they update their DT and it will complicate the code as the other clocks are definitely optional, so MCLK2 will need special handling.

Quoted 13 lines
Quoted 13 lines
drivers/mfd/madera-core.c +1 -1
  	ret = regmap_update_bits(madera->regmap,
  			MADERA_CLOCK_32K_1,
  			MADERA_CLK_32K_ENA_MASK | MADERA_CLK_32K_SRC_MASK,
  			MADERA_CLK_32K_ENA | MADERA_32KZ_MCLK2);
  	if (ret) {
  		dev_err(madera->dev, "Failed to init 32k clock: %d\n", ret);
-		goto err_reset;
+		goto err_clock;
  	}
 
  	pm_runtime_set_active(madera->dev);
@@ -687,6 +705,8 @@ int madera_dev_init(struct madera *madera)
 
Quoted 7 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 709

Quoted 4 lines
drivers/mfd/madera-core.c +2 -0
  err_pm_runtime:
  	pm_runtime_disable(madera->dev);
+err_clock:
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);

Where are the other clocks consumed?

Other clocks will be consumed by the ASoC part of the driver for clocking the audio functionality and running the FLLs. I haven't sent those patches yet, but was planning on doing so once this was merged.

Thanks,
Charles

#5 lore raw

Re: [PATCH 2/2] mfd: madera: Add support for requesting the supply clocks

In reply to Charles Keepax
Quoted 24 lines · Charles Keepax
Quoted 18 lines · Lee Jones
Quoted 16 lines · Charles Keepax

Add the ability to get the clock for each clock input pin of the chip and enable MCLK2 since that is expected to be a permanently enabled 32kHz clock.

---
int madera_dev_init(struct madera *madera)
{

drivers/mfd/madera-core.c +1 -0
+	static const char * const mclk_name[] = { "mclk1", "mclk2", "mclk3" };
 	struct device *dev = madera->dev;
 	unsigned int hwid;
 	int (*patch_fn)(struct madera *) = NULL;
@@ -450,6 +451,17 @@ int madera_dev_init(struct madera *madera)
 		       sizeof(madera->pdata));
 	}
 
Quoted 4 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 454

Quoted 1 line
drivers/mfd/madera-core.c +1 -0
+	BUILD_BUG_ON(ARRAY_SIZE(madera->mclk) != ARRAY_SIZE(mclk_name));

Not sure how this could happen. Surely we don't need it.

Quoted 5 lines

mclk_name is defined locally in this function and the mclk array in include/linux/mfd/madera/core.h. This is to guard against one of them being updated but not the other. It is by no means essential but it feels like a good trade off given there is really limited downside.

It's fine in general I guess. How likely would it be for anyone to update either of the definitions? Can there be more/less clocks on a supported platform?

Quoted 9 lines
Quoted 9 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 460

Quoted 6 lines
drivers/mfd/madera-core.c +6 -0
+	for (i = 0; i < ARRAY_SIZE(madera->mclk); i++) {
+		madera->mclk[i] = devm_clk_get_optional(madera->dev,
+							mclk_name[i]);
+		if (IS_ERR(madera->mclk[i])) {
+			dev_warn(madera->dev, "Failed to get %s: %ld\n",
+				 mclk_name[i], PTR_ERR(madera->mclk[i]));

Do we even want to warn on the non-acquisition of an optional clock?

Quoted 8 lines
Quoted 2 lines

Especially with a message that looks like something actually failed.

devm_clk_get_optional will return NULL if the clock was not specified, so this is silent in that case. A warning in the case something actually went wrong seems reasonable even if the clock is optional as the user tried to do something and it didn't behave as they intended.

If something actually went wrong, then doesn't then become and error and should be reported (returned)?

Quoted 26 lines
Quoted 10 lines
Quoted 10 lines
drivers/mfd/madera-core.c +4 -0
+			madera->mclk[i] = NULL;
+		}
+	}
+
 	ret = madera_get_reset_gpio(madera);
 	if (ret)
 		return ret;
@@ -660,13 +672,19 @@ int madera_dev_init(struct madera *madera)
 	}
 
Quoted 9 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 679

Quoted 6 lines
drivers/mfd/madera-core.c +5 -0
 	/* Init 32k clock sourced from MCLK2 */
+	ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2]);
+	if (ret != 0) {
+		dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret);
+		goto err_reset;
+	}

What happened to this being optional?

The device needs the clock but specifying it through DT is optional (the clock framework functions are no-ops and return success if the clock pointer is NULL). Normally the 32kHz clock is always on, and more importantly no existing users of the driver will be specifying one.

Quoted 4 lines

We could remove the optional status for MCLK2, but it could break existing users who don't yet specify the clock until they update their DT and it will complicate the code as the other clocks are definitely optional, so MCLK2 will need special handling.

I'd prefer the code to reflect the actual situation. If the clock is not optional it doesn't sound correct to specify it as such. Maybe as an intermediary step we attempt to obtain it, but ignore missing clocks (with a message and comment) if it is not yet specified. We can look to change the behaviour once users have had the chance to update their DTs.

Quoted 20 lines
Quoted 13 lines
Quoted 13 lines
drivers/mfd/madera-core.c +1 -1
 	ret = regmap_update_bits(madera->regmap,
 			MADERA_CLOCK_32K_1,
 			MADERA_CLK_32K_ENA_MASK | MADERA_CLK_32K_SRC_MASK,
 			MADERA_CLK_32K_ENA | MADERA_32KZ_MCLK2);
 	if (ret) {
 		dev_err(madera->dev, "Failed to init 32k clock: %d\n", ret);
-		goto err_reset;
+		goto err_clock;
 	}
 
 	pm_runtime_set_active(madera->dev);
@@ -687,6 +705,8 @@ int madera_dev_init(struct madera *madera)
 
Quoted 6 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 709

Quoted 4 lines
drivers/mfd/madera-core.c +2 -0
 err_pm_runtime:
 	pm_runtime_disable(madera->dev);
+err_clock:
+	clk_disable_unprepare(madera->mclk[MADERA_MCLK2]);

Where are the other clocks consumed?

Quoted 4 lines

Other clocks will be consumed by the ASoC part of the driver for clocking the audio functionality and running the FLLs. I haven't sent those patches yet, but was planning on doing so once this was merged.

Okay.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author maintainer
#6 lore raw

Re: [PATCH 2/2] mfd: madera: Add support for requesting the supply clocks

Quoted 31 lines · Lee Jones
Quoted 24 lines · Charles Keepax
Quoted 18 lines · Lee Jones
Quoted 16 lines · Charles Keepax

Add the ability to get the clock for each clock input pin of the chip and enable MCLK2 since that is expected to be a permanently enabled 32kHz clock.

---
int madera_dev_init(struct madera *madera)
{

drivers/mfd/madera-core.c +1 -0
+	static const char * const mclk_name[] = { "mclk1", "mclk2", "mclk3" };
 	struct device *dev = madera->dev;
 	unsigned int hwid;
 	int (*patch_fn)(struct madera *) = NULL;
@@ -450,6 +451,17 @@ int madera_dev_init(struct madera *madera)
 		       sizeof(madera->pdata));
 	}
 
Quoted 4 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 454

Quoted 1 line
drivers/mfd/madera-core.c +1 -0
+	BUILD_BUG_ON(ARRAY_SIZE(madera->mclk) != ARRAY_SIZE(mclk_name));

Not sure how this could happen. Surely we don't need it.

Quoted 5 lines

mclk_name is defined locally in this function and the mclk array in include/linux/mfd/madera/core.h. This is to guard against one of them being updated but not the other. It is by no means essential but it feels like a good trade off given there is really limited downside.

Quoted 4 lines

It's fine in general I guess. How likely would it be for anyone to update either of the definitions? Can there be more/less clocks on a supported platform?

It's not super likely but if the hardware guys make a new spin out chip with an extra clock pin which is possible. But my problem here is there really is no down side to this check, we have two things that need to be in sync and if the compiler can warn me if they are not in sync that is clearly a win.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 460

Quoted 6 lines
drivers/mfd/madera-core.c +6 -0
+	for (i = 0; i < ARRAY_SIZE(madera->mclk); i++) {
+		madera->mclk[i] = devm_clk_get_optional(madera->dev,
+							mclk_name[i]);
+		if (IS_ERR(madera->mclk[i])) {
+			dev_warn(madera->dev, "Failed to get %s: %ld\n",
+				 mclk_name[i], PTR_ERR(madera->mclk[i]));

Do we even want to warn on the non-acquisition of an optional clock?

Especially with a message that looks like something actually failed.

Quoted 9 lines
Quoted 5 lines

devm_clk_get_optional will return NULL if the clock was not specified, so this is silent in that case. A warning in the case something actually went wrong seems reasonable even if the clock is optional as the user tried to do something and it didn't behave as they intended.

If something actually went wrong, then doesn't then become and error and should be reported (returned)?

Yeah I guess its a judgement call but there is not really any reason we need to proceed in the case of an error. I will update to fail probe here.

Quoted 31 lines
Quoted 26 lines
Quoted 10 lines
Quoted 10 lines
drivers/mfd/madera-core.c +4 -0
+			madera->mclk[i] = NULL;
+		}
+	}
+
 	ret = madera_get_reset_gpio(madera);
 	if (ret)
 		return ret;
@@ -660,13 +672,19 @@ int madera_dev_init(struct madera *madera)
 	}
 
Quoted 9 lines

drivers/mfd/madera-core.c int madera_dev_init(struct madera *madera) · line 679

Quoted 6 lines
drivers/mfd/madera-core.c +5 -0
 	/* Init 32k clock sourced from MCLK2 */
+	ret = clk_prepare_enable(madera->mclk[MADERA_MCLK2]);
+	if (ret != 0) {
+		dev_err(madera->dev, "Failed to enable 32k clock: %d\n", ret);
+		goto err_reset;
+	}

What happened to this being optional?

The device needs the clock but specifying it through DT is optional (the clock framework functions are no-ops and return success if the clock pointer is NULL). Normally the 32kHz clock is always on, and more importantly no existing users of the driver will be specifying one.

Quoted 4 lines

We could remove the optional status for MCLK2, but it could break existing users who don't yet specify the clock until they update their DT and it will complicate the code as the other clocks are definitely optional, so MCLK2 will need special handling.

Quoted 7 lines

I'd prefer the code to reflect the actual situation. If the clock is not optional it doesn't sound correct to specify it as such. Maybe as an intermediary step we attempt to obtain it, but ignore missing clocks (with a message and comment) if it is not yet specified. We can look to change the behaviour once users have had the chance to update their DTs.

Ok I will add a print for a missing MCLK2.

Thanks,
Charles