From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH 2/4] mci: mci_spi: extend driver for device tree probing
Date: Sat, 19 Mar 2022 08:24:08 +0100 [thread overview]
Message-ID: <20220319072410.1310723-2-ahmad@a3f.at> (raw)
In-Reply-To: <20220319072410.1310723-1-ahmad@a3f.at>
Driver has been matched by name only so far, add optional support for
the device tree binding.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
drivers/mci/mci_spi.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index ed3ddf890f7f..6ae2824eddc8 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -18,6 +18,8 @@
#include <mci.h>
#include <crc.h>
#include <crc7.h>
+#include <of.h>
+#include <gpiod.h>
#define to_spi_host(mci) container_of(mci, struct mmc_spi_host, mci)
#define spi_setup(spi) spi->master->setup(spi)
@@ -47,6 +49,7 @@ struct mmc_spi_host {
struct mci_host mci;
struct spi_device *spi;
struct device_d *dev;
+ int detect_pin;
/* for bulk data transfers */
struct spi_transfer t_tx;
@@ -351,8 +354,23 @@ static int mmc_spi_init(struct mci_host *mci, struct device_d *mci_dev)
return 0;
}
+static int spi_mci_card_present(struct mci_host *mci)
+{
+ struct mmc_spi_host *host = to_spi_host(mci);
+ int ret;
+
+ /* No gpio, assume card is present */
+ if (!gpio_is_valid(host->detect_pin))
+ return 1;
+
+ ret = gpio_get_value(host->detect_pin);
+
+ return ret == 0 ? 1 : 0;
+}
+
static int spi_mci_probe(struct device_d *dev)
{
+ struct device_node *np = dev_of_node(dev);
struct spi_device *spi = (struct spi_device *)dev->type_data;
struct mmc_spi_host *host;
void *ones;
@@ -362,6 +380,7 @@ static int spi_mci_probe(struct device_d *dev)
host->mci.send_cmd = mmc_spi_request;
host->mci.set_ios = mmc_spi_set_ios;
host->mci.init = mmc_spi_init;
+ host->mci.card_present = spi_mci_card_present;
host->mci.hw_dev = dev;
/* MMC and SD specs only seem to care that sampling is on the
@@ -415,14 +434,26 @@ static int spi_mci_probe(struct device_d *dev)
host->mci.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
host->mci.host_caps = MMC_CAP_SPI;
+ host->detect_pin = -EINVAL;
+
+ if (np) {
+ host->mci.devname = xstrdup(of_alias_get(np));
+ host->detect_pin = gpiod_get(dev, NULL, GPIOD_IN);
+ }
mci_register(&host->mci);
return 0;
}
+static __maybe_unused struct of_device_id spi_mci_compatible[] = {
+ { .compatible = "mmc-spi-slot" },
+ { /* sentinel */ }
+};
+
static struct driver_d spi_mci_driver = {
.name = "spi_mci",
.probe = spi_mci_probe,
+ .of_compatible = DRV_OF_COMPAT(spi_mci_compatible),
};
device_spi_driver(spi_mci_driver);
--
2.34.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2022-03-19 7:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-19 7:24 [PATCH 1/4] spi: Port SiFive SPI controller driver Ahmad Fatoum
2022-03-19 7:24 ` Ahmad Fatoum [this message]
2022-03-28 9:44 ` [PATCH 2/4] mci: mci_spi: extend driver for device tree probing Sascha Hauer
2022-03-28 9:48 ` Ahmad Fatoum
2022-03-19 7:24 ` [PATCH 3/4] mtd: spi-nor: add support for ISSI IS25WP256 Ahmad Fatoum
2022-03-19 7:24 ` [PATCH 4/4] RISC-V: sifive: enable SPI Flash and SD in config Ahmad Fatoum
2022-03-28 9:43 ` [PATCH 1/4] spi: Port SiFive SPI controller driver Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220319072410.1310723-2-ahmad@a3f.at \
--to=ahmad@a3f.at \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox