public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] spi: imx: work with cs greater 0
Date: Mon, 13 May 2019 13:53:39 +0200	[thread overview]
Message-ID: <20190513115339.984305-3-hs@denx.de> (raw)
In-Reply-To: <20190513115339.984305-1-hs@denx.de>

currently spi mxc driver can only handle cs 0.
Allow it to handle also cs > 0.

Signed-off-by: Heiko Schocher <hs@denx.de>
---

 drivers/spi/mxc_spi.c | 54 +++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
index fba76bf740..c65955d59b 100644
--- a/drivers/spi/mxc_spi.c
+++ b/drivers/spi/mxc_spi.c
@@ -38,6 +38,8 @@ __weak int board_spi_cs_gpio(unsigned bus, unsigned cs)
 #define CONFIG_SYS_SPI_MXC_WAIT		(CONFIG_SYS_HZ/100)	/* 10 ms */
 #endif
 
+#define MAX_CS_COUNT	4
+
 struct mxc_spi_slave {
 	struct spi_slave slave;
 	unsigned long	base;
@@ -50,6 +52,8 @@ struct mxc_spi_slave {
 	unsigned int	max_hz;
 	unsigned int	mode;
 	struct gpio_desc ss;
+	struct gpio_desc cs_gpios[MAX_CS_COUNT];
+	struct udevice *dev;
 };
 
 static inline struct mxc_spi_slave *to_mxc_spi_slave(struct spi_slave *slave)
@@ -59,8 +63,16 @@ static inline struct mxc_spi_slave *to_mxc_spi_slave(struct spi_slave *slave)
 
 static void mxc_spi_cs_activate(struct mxc_spi_slave *mxcs)
 {
+	struct udevice *dev = mxcs->dev;
+	struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
+
+	u32 cs = slave_plat->cs;
+
 	if (CONFIG_IS_ENABLED(DM_SPI)) {
-		dm_gpio_set_value(&mxcs->ss, 1);
+		if (!dm_gpio_is_valid(&mxcs->cs_gpios[cs]))
+			return;
+
+		dm_gpio_set_value(&mxcs->cs_gpios[cs], 1);
 	} else {
 		if (mxcs->gpio > 0)
 			gpio_set_value(mxcs->gpio, mxcs->ss_pol);
@@ -69,8 +81,16 @@ static void mxc_spi_cs_activate(struct mxc_spi_slave *mxcs)
 
 static void mxc_spi_cs_deactivate(struct mxc_spi_slave *mxcs)
 {
+	struct udevice *dev = mxcs->dev;
+	struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
+
+	u32 cs = slave_plat->cs;
+
 	if (CONFIG_IS_ENABLED(DM_SPI)) {
-		dm_gpio_set_value(&mxcs->ss, 0);
+		if (!dm_gpio_is_valid(&mxcs->cs_gpios[cs]))
+			return;
+
+		dm_gpio_set_value(&mxcs->cs_gpios[cs], 0);
 	} else {
 		if (mxcs->gpio > 0)
 			gpio_set_value(mxcs->gpio, !(mxcs->ss_pol));
@@ -492,23 +512,31 @@ static int mxc_spi_probe(struct udevice *bus)
 	int node = dev_of_offset(bus);
 	const void *blob = gd->fdt_blob;
 	int ret;
+	int i;
 
-	if (gpio_request_by_name(bus, "cs-gpios", 0, &plat->ss,
-				 GPIOD_IS_OUT)) {
-		dev_err(bus, "No cs-gpios property\n");
-		return -EINVAL;
+	ret = gpio_request_list_by_name(bus, "cs-gpios", mxcs->cs_gpios,
+					ARRAY_SIZE(mxcs->cs_gpios), 0);
+	if (ret < 0) {
+		pr_err("Can't get %s gpios! Error: %d", bus->name, ret);
+		return ret;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(mxcs->cs_gpios); i++) {
+		if (!dm_gpio_is_valid(&mxcs->cs_gpios[i]))
+			continue;
+
+		ret = dm_gpio_set_dir_flags(&mxcs->cs_gpios[i],
+					    GPIOD_IS_OUT | GPIOD_ACTIVE_LOW);
+		if (ret) {
+			dev_err(bus, "Setting cs %d error\n", i);
+			return ret;
+		}
 	}
 
 	mxcs->base = devfdt_get_addr(bus);
 	if (mxcs->base == FDT_ADDR_T_NONE)
 		return -ENODEV;
 
-	ret = dm_gpio_set_value(&mxcs->ss, 0);
-	if (ret) {
-		dev_err(bus, "Setting cs error\n");
-		return ret;
-	}
-
 	mxcs->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency",
 				      20000000);
 
@@ -529,6 +557,8 @@ static int mxc_spi_claim_bus(struct udevice *dev)
 	struct mxc_spi_slave *mxcs = dev_get_platdata(dev->parent);
 	struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
 
+	mxcs->dev = dev;
+
 	return mxc_spi_claim_bus_internal(mxcs, slave_plat->cs);
 }
 
-- 
2.17.2

      parent reply	other threads:[~2019-05-13 11:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-13 11:53 [U-Boot] [PATCH 0/2] mxc_spi: DM improvements Heiko Schocher
2019-05-13 11:53 ` [U-Boot] [PATCH 1/2] spi: imx: remove doubled pointer from mxc_spi_probe Heiko Schocher
2019-05-13 11:53 ` Heiko Schocher [this message]

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=20190513115339.984305-3-hs@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /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