mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/3] mci: core: act upon broken-cd device tree property
@ 2022-09-30 15:33 Ahmad Fatoum
  2022-09-30 15:33 ` [PATCH v2 2/3] mci: core: add broken_cd device parameter Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2022-09-30 15:33 UTC (permalink / raw)
  To: barebox; +Cc: mfe, Ahmad Fatoum

We didn't care much for broken-cd so far, still we have some drivers
implementing the card_present callback, which we should ignore when
card-detect is marked broken.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - new patch
---
 drivers/mci/mci-core.c | 12 ++++++++----
 include/mci.h          |  1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 8c08a4f61f63..5f4457bab3df 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1750,10 +1750,13 @@ static int mci_card_probe(struct mci *mci)
 	int i, rc, disknum, ret;
 	bool has_bootpart = false;
 
-	if (host->card_present && !host->card_present(host) &&
-	    !host->non_removable) {
-		dev_err(&mci->dev, "no card inserted\n");
-		return -ENODEV;
+	if (host->card_present && !host->card_present(host) && !host->non_removable) {
+		if (!host->broken_cd) {
+			dev_err(&mci->dev, "no card inserted\n");
+			return -ENODEV;
+		}
+
+		dev_info(&mci->dev, "no card inserted (ignoring)\n");
 	}
 
 	ret = regulator_enable(host->supply);
@@ -2043,6 +2046,7 @@ void mci_of_parse_node(struct mci_host *host,
 		}
 	}
 
+	host->broken_cd = of_property_read_bool(np, "broken-cd");
 	host->non_removable = of_property_read_bool(np, "non-removable");
 	host->no_sd = of_property_read_bool(np, "no-sd");
 	host->disable_wp = of_property_read_bool(np, "disable-wp");
diff --git a/include/mci.h b/include/mci.h
index 2098b4fbf084..d949310fac30 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -404,6 +404,7 @@ struct mci_host {
 	unsigned max_req_size;
 	unsigned dsr_val;	/**< optional dsr value */
 	int use_dsr;		/**< optional dsr usage flag */
+	int broken_cd;		/**< card detect is broken */
 	bool non_removable;	/**< device is non removable */
 	bool no_sd;		/**< do not send SD commands during initialization */
 	bool disable_wp;	/**< ignore write-protect detection logic */
-- 
2.30.2




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

* [PATCH v2 2/3] mci: core: add broken_cd device parameter
  2022-09-30 15:33 [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
@ 2022-09-30 15:33 ` Ahmad Fatoum
  2022-09-30 15:33 ` [PATCH v2 3/3] mci: core: fixup broken-cd information into kernel DT Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2022-09-30 15:33 UTC (permalink / raw)
  To: barebox; +Cc: mfe, Ahmad Fatoum

Sometimes a broken card-detect is not a general issue affecting all
boards, but only a given board. Allow setting broken_cd for such boards
via a device parameter.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - replace Kconfig option with device parameter (Marco, Sascha)
---
 drivers/mci/mci-core.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 5f4457bab3df..26b524007609 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1919,7 +1919,7 @@ int mci_register(struct mci_host *host)
 {
 	struct mci *mci;
 	struct device_d *hw_dev;
-	struct param_d *param_probe;
+	struct param_d *param_probe, *param_broken_cd;
 	int ret;
 
 	mci = xzalloc(sizeof(*mci));
@@ -1973,6 +1973,15 @@ int mci_register(struct mci_host *host)
 		goto err_unregister;
 	}
 
+	param_broken_cd = dev_add_param_bool(&mci->dev, "broken_cd",
+					     NULL, NULL, &host->broken_cd, mci);
+
+	if (IS_ERR(param_broken_cd) && PTR_ERR(param_broken_cd) != -ENOSYS) {
+		ret = PTR_ERR(param_broken_cd);
+		dev_dbg(&mci->dev, "Failed to add 'broken_cd' parameter to the MCI device\n");
+		goto err_unregister;
+	}
+
 	if (IS_ENABLED(CONFIG_MCI_INFO))
 		mci->dev.info = mci_info;
 
-- 
2.30.2




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

* [PATCH v2 3/3] mci: core: fixup broken-cd information into kernel DT
  2022-09-30 15:33 [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
  2022-09-30 15:33 ` [PATCH v2 2/3] mci: core: add broken_cd device parameter Ahmad Fatoum
@ 2022-09-30 15:33 ` Ahmad Fatoum
  2022-09-30 16:22 ` [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
  2022-10-04  8:53 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2022-09-30 15:33 UTC (permalink / raw)
  To: barebox; +Cc: mfe, Ahmad Fatoum

In remote labs co-located with other hardware, we've observed card
detect levers of different boards to sporadically fail to detect
the card, e.g. because the cable on the usbsdmux was yanked around
by accident. When this happens, barebox usually boots up normally as
the card detect is ignored and then Linux waits indefinitely for
the card-detect to turn active. We already maintain a broken_cd flag
for each card. Use this to fixup the kernel DT appropriately.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - apply to all controllers that have broken-cd and not only
    to probed ones (Sascha)
---
 drivers/mci/mci-core.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 26b524007609..82f39d8fc9b8 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1739,6 +1739,31 @@ static int mci_register_partition(struct mci_part *part)
 	return 0;
 }
 
+static int of_broken_cd_fixup(struct device_node *root, void *ctx)
+{
+	struct mci_host *host = ctx;
+	struct device_d *hw_dev = host->hw_dev;
+	struct device_node *np;
+	char *name;
+
+	if (!host->broken_cd)
+		return 0;
+
+	name = of_get_reproducible_name(hw_dev->device_node);
+	np = of_find_node_by_reproducible_name(root, name);
+	free(name);
+	if (!np) {
+		dev_warn(hw_dev, "Cannot find nodepath %s, cannot fixup\n",
+			 hw_dev->device_node->full_name);
+		return -EINVAL;
+	}
+
+	of_property_write_bool(np, "cd-gpios", false);
+	of_property_write_bool(np, "broken-cd", true);
+
+	return 0;
+}
+
 /**
  * Probe an MCI card at the given host interface
  * @param mci MCI device instance
@@ -1989,6 +2014,9 @@ int mci_register(struct mci_host *host)
 	if (IS_ENABLED(CONFIG_MCI_STARTUP))
 		mci_card_probe(mci);
 
+	if (!host->no_sd && dev_of_node(host->hw_dev))
+		of_register_fixup(of_broken_cd_fixup, host);
+
 	list_add_tail(&mci->list, &mci_list);
 
 	return 0;
-- 
2.30.2




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

* Re: [PATCH v2 1/3] mci: core: act upon broken-cd device tree property
  2022-09-30 15:33 [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
  2022-09-30 15:33 ` [PATCH v2 2/3] mci: core: add broken_cd device parameter Ahmad Fatoum
  2022-09-30 15:33 ` [PATCH v2 3/3] mci: core: fixup broken-cd information into kernel DT Ahmad Fatoum
@ 2022-09-30 16:22 ` Ahmad Fatoum
  2022-10-04  8:53 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2022-09-30 16:22 UTC (permalink / raw)
  To: barebox; +Cc: mfe

On 30.09.22 16:33, Ahmad Fatoum wrote:
> We didn't care much for broken-cd so far, still we have some drivers
> implementing the card_present callback, which we should ignore when
> card-detect is marked broken.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   - new patch

Sorry, this was meant to be v3.

> ---
>  drivers/mci/mci-core.c | 12 ++++++++----
>  include/mci.h          |  1 +
>  2 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 8c08a4f61f63..5f4457bab3df 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -1750,10 +1750,13 @@ static int mci_card_probe(struct mci *mci)
>  	int i, rc, disknum, ret;
>  	bool has_bootpart = false;
>  
> -	if (host->card_present && !host->card_present(host) &&
> -	    !host->non_removable) {
> -		dev_err(&mci->dev, "no card inserted\n");
> -		return -ENODEV;
> +	if (host->card_present && !host->card_present(host) && !host->non_removable) {
> +		if (!host->broken_cd) {
> +			dev_err(&mci->dev, "no card inserted\n");
> +			return -ENODEV;
> +		}
> +
> +		dev_info(&mci->dev, "no card inserted (ignoring)\n");
>  	}
>  
>  	ret = regulator_enable(host->supply);
> @@ -2043,6 +2046,7 @@ void mci_of_parse_node(struct mci_host *host,
>  		}
>  	}
>  
> +	host->broken_cd = of_property_read_bool(np, "broken-cd");
>  	host->non_removable = of_property_read_bool(np, "non-removable");
>  	host->no_sd = of_property_read_bool(np, "no-sd");
>  	host->disable_wp = of_property_read_bool(np, "disable-wp");
> diff --git a/include/mci.h b/include/mci.h
> index 2098b4fbf084..d949310fac30 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -404,6 +404,7 @@ struct mci_host {
>  	unsigned max_req_size;
>  	unsigned dsr_val;	/**< optional dsr value */
>  	int use_dsr;		/**< optional dsr usage flag */
> +	int broken_cd;		/**< card detect is broken */
>  	bool non_removable;	/**< device is non removable */
>  	bool no_sd;		/**< do not send SD commands during initialization */
>  	bool disable_wp;	/**< ignore write-protect detection logic */


-- 
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] 5+ messages in thread

* Re: [PATCH v2 1/3] mci: core: act upon broken-cd device tree property
  2022-09-30 15:33 [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2022-09-30 16:22 ` [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
@ 2022-10-04  8:53 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2022-10-04  8:53 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, mfe

On Fri, Sep 30, 2022 at 05:33:15PM +0200, Ahmad Fatoum wrote:
> We didn't care much for broken-cd so far, still we have some drivers
> implementing the card_present callback, which we should ignore when
> card-detect is marked broken.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   - new patch
> ---
>  drivers/mci/mci-core.c | 12 ++++++++----
>  include/mci.h          |  1 +
>  2 files changed, 9 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index 8c08a4f61f63..5f4457bab3df 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -1750,10 +1750,13 @@ static int mci_card_probe(struct mci *mci)
>  	int i, rc, disknum, ret;
>  	bool has_bootpart = false;
>  
> -	if (host->card_present && !host->card_present(host) &&
> -	    !host->non_removable) {
> -		dev_err(&mci->dev, "no card inserted\n");
> -		return -ENODEV;
> +	if (host->card_present && !host->card_present(host) && !host->non_removable) {
> +		if (!host->broken_cd) {
> +			dev_err(&mci->dev, "no card inserted\n");
> +			return -ENODEV;
> +		}
> +
> +		dev_info(&mci->dev, "no card inserted (ignoring)\n");
>  	}
>  
>  	ret = regulator_enable(host->supply);
> @@ -2043,6 +2046,7 @@ void mci_of_parse_node(struct mci_host *host,
>  		}
>  	}
>  
> +	host->broken_cd = of_property_read_bool(np, "broken-cd");
>  	host->non_removable = of_property_read_bool(np, "non-removable");
>  	host->no_sd = of_property_read_bool(np, "no-sd");
>  	host->disable_wp = of_property_read_bool(np, "disable-wp");
> diff --git a/include/mci.h b/include/mci.h
> index 2098b4fbf084..d949310fac30 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -404,6 +404,7 @@ struct mci_host {
>  	unsigned max_req_size;
>  	unsigned dsr_val;	/**< optional dsr value */
>  	int use_dsr;		/**< optional dsr usage flag */
> +	int broken_cd;		/**< card detect is broken */
>  	bool non_removable;	/**< device is non removable */
>  	bool no_sd;		/**< do not send SD commands during initialization */
>  	bool disable_wp;	/**< ignore write-protect detection logic */
> -- 
> 2.30.2
> 
> 
> 

-- 
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] 5+ messages in thread

end of thread, other threads:[~2022-10-04  8:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 15:33 [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
2022-09-30 15:33 ` [PATCH v2 2/3] mci: core: add broken_cd device parameter Ahmad Fatoum
2022-09-30 15:33 ` [PATCH v2 3/3] mci: core: fixup broken-cd information into kernel DT Ahmad Fatoum
2022-09-30 16:22 ` [PATCH v2 1/3] mci: core: act upon broken-cd device tree property Ahmad Fatoum
2022-10-04  8:53 ` Sascha Hauer

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