mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] mci: define fall-back hw_dev->detect for all MCIs
@ 2020-05-17 18:19 Ahmad Fatoum
  2020-05-17 18:19 ` [PATCH 2/3] mci: remove now-duplicate dev->detect implementations in host drivers Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2020-05-17 18:19 UTC (permalink / raw)
  To: barebox; +Cc: Lucas Stach, Ahmad Fatoum

A barebox environment oftree node may reference its storage by a phandle
to a partition node under a MCI node. barebox will then call the
device's detect method to detect the card if this hasn't happened
before. Out of 17 MCI drivers, 8 host drivers already implement
a detect method, which just calls mci_detect_card.

Provide a generic implementation that does the same.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Cc: Lucas Stach <lst@pengutronix.de>
---
 drivers/mci/mci-core.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index e8844a3c0007..ab80c4d5ba5c 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1806,9 +1806,14 @@ int mci_detect_card(struct mci_host *host)
 
 static int mci_detect(struct device_d *dev)
 {
-	struct mci *mci = container_of(dev, struct mci, dev);
+	struct mci *mci;
+
+	list_for_each_entry(mci, &mci_list, list) {
+		if (dev == &mci->dev || dev == mci->host->hw_dev)
+			return mci_detect_card(mci->host);
+	}
 
-	return mci_detect_card(mci->host);
+	return -ENODEV;
 }
 
 /**
@@ -1819,6 +1824,7 @@ static int mci_detect(struct device_d *dev)
 int mci_register(struct mci_host *host)
 {
 	struct mci *mci;
+	struct device_d *hw_dev;
 	struct param_d *param_probe;
 	int ret;
 
@@ -1833,13 +1839,16 @@ int mci_register(struct mci_host *host)
 		mci->dev.id = DEVICE_ID_DYNAMIC;
 	}
 
+	hw_dev = host->hw_dev;
 	mci->dev.platform_data = host;
-	mci->dev.parent = host->hw_dev;
+	mci->dev.parent = hw_dev;
 	mci->host = host;
 	host->mci = mci;
 	mci->dev.detect = mci_detect;
+	if (!hw_dev->detect)
+		hw_dev->detect = mci_detect;
 
-	host->supply = regulator_get(host->hw_dev, "vmmc");
+	host->supply = regulator_get(hw_dev, "vmmc");
 	if (IS_ERR(host->supply)) {
 		dev_err(&mci->dev, "Failed to get 'vmmc' regulator.\n");
 		host->supply = NULL;
@@ -1849,7 +1858,7 @@ int mci_register(struct mci_host *host)
 	if (ret)
 		goto err_free;
 
-	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(&mci->dev));
+	dev_info(hw_dev, "registered as %s\n", dev_name(&mci->dev));
 
 	param_probe = dev_add_param_bool(&mci->dev, "probe",
 			mci_set_probe, NULL, &mci->probe, mci);
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH 1/3] mci: define fall-back hw_dev->detect for all MCIs
@ 2020-06-02  8:00 Ahmad Fatoum
  2020-06-02  8:00 ` [PATCH 2/3] mci: remove now-duplicate dev->detect implementations in host drivers Ahmad Fatoum
  0 siblings, 1 reply; 5+ messages in thread
From: Ahmad Fatoum @ 2020-06-02  8:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

A barebox environment oftree node may reference its storage by a phandle
to a partition node under a MCI node. barebox will then call the
device's detect method to detect the card if this hasn't happened
before. Out of 17 MCI drivers, 8 host drivers already implement
a detect method, which just calls mci_detect_card.

Provide a generic implementation that does the same.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/mci-core.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index e8844a3c0007..09e66bad472e 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1811,6 +1811,18 @@ static int mci_detect(struct device_d *dev)
 	return mci_detect_card(mci->host);
 }
 
+static int mci_hw_detect(struct device_d *dev)
+{
+	struct mci *mci;
+
+	list_for_each_entry(mci, &mci_list, list) {
+		if (dev == &mci->dev || dev == mci->host->hw_dev)
+			return mci_detect_card(mci->host);
+	}
+
+	return -ENODEV;
+}
+
 /**
  * Create a new mci device (for convenience)
  * @param host mci_host for this MCI device
@@ -1819,6 +1831,7 @@ static int mci_detect(struct device_d *dev)
 int mci_register(struct mci_host *host)
 {
 	struct mci *mci;
+	struct device_d *hw_dev;
 	struct param_d *param_probe;
 	int ret;
 
@@ -1833,13 +1846,16 @@ int mci_register(struct mci_host *host)
 		mci->dev.id = DEVICE_ID_DYNAMIC;
 	}
 
+	hw_dev = host->hw_dev;
 	mci->dev.platform_data = host;
-	mci->dev.parent = host->hw_dev;
+	mci->dev.parent = hw_dev;
 	mci->host = host;
 	host->mci = mci;
 	mci->dev.detect = mci_detect;
+	if (!hw_dev->detect)
+		hw_dev->detect = mci_hw_detect;
 
-	host->supply = regulator_get(host->hw_dev, "vmmc");
+	host->supply = regulator_get(hw_dev, "vmmc");
 	if (IS_ERR(host->supply)) {
 		dev_err(&mci->dev, "Failed to get 'vmmc' regulator.\n");
 		host->supply = NULL;
@@ -1849,7 +1865,7 @@ int mci_register(struct mci_host *host)
 	if (ret)
 		goto err_free;
 
-	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(&mci->dev));
+	dev_info(hw_dev, "registered as %s\n", dev_name(&mci->dev));
 
 	param_probe = dev_add_param_bool(&mci->dev, "probe",
 			mci_set_probe, NULL, &mci->probe, mci);
-- 
2.27.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-06-02  8:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-17 18:19 [PATCH 1/3] mci: define fall-back hw_dev->detect for all MCIs Ahmad Fatoum
2020-05-17 18:19 ` [PATCH 2/3] mci: remove now-duplicate dev->detect implementations in host drivers Ahmad Fatoum
2020-05-17 18:19 ` [PATCH 3/3] mci: reword MCI_STARTUP text Ahmad Fatoum
2020-05-18  6:17 ` [PATCH 1/3] mci: define fall-back hw_dev->detect for all MCIs Sascha Hauer
2020-06-02  8:00 Ahmad Fatoum
2020-06-02  8:00 ` [PATCH 2/3] mci: remove now-duplicate dev->detect implementations in host drivers Ahmad Fatoum

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