All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/2] mxc_spi: DM improvements
@ 2019-05-26 10:15 Heiko Schocher
  2019-05-26 10:15 ` [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from mxc_spi_probe Heiko Schocher
  2019-05-26 10:15 ` [U-Boot] [PATCH v2 2/2] spi: imx: work with cs greater 0 Heiko Schocher
  0 siblings, 2 replies; 5+ messages in thread
From: Heiko Schocher @ 2019-05-26 10:15 UTC (permalink / raw)
  To: u-boot

This series improves the mxc_spi DM support.

builds clean on travis, see:
https://travis-ci.org/hsdenx/u-boot-test/builds/537358053

Changes in v2:
- added Jagan Teki to cc
- based patches on:
  e1a2ed7180 - Merge git://git.denx.de/u-boot-mpc83xx <Tom Rini>
- fixed build error, seen on travis (Sorry for v1 I pushed
  the wrong branch to travis):
  drivers/spi/mxc_spi.c: In function 'mxc_spi_cs_activate':
  drivers/spi/mxc_spi.c:69:21: error: dereferencing pointer to incomplete type 'struct dm_spi_slave_platdata'

Heiko Schocher (2):
  spi: imx: remove doubled pointer from mxc_spi_probe
  spi: imx: work with cs greater 0

 drivers/spi/mxc_spi.c | 77 +++++++++++++++++++++++++++++--------------
 1 file changed, 53 insertions(+), 24 deletions(-)

-- 
2.21.0

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

* [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from mxc_spi_probe
  2019-05-26 10:15 [U-Boot] [PATCH v2 0/2] mxc_spi: DM improvements Heiko Schocher
@ 2019-05-26 10:15 ` Heiko Schocher
  2019-06-10  9:40   ` [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from sbabic at denx.de
  2019-05-26 10:15 ` [U-Boot] [PATCH v2 2/2] spi: imx: work with cs greater 0 Heiko Schocher
  1 sibling, 1 reply; 5+ messages in thread
From: Heiko Schocher @ 2019-05-26 10:15 UTC (permalink / raw)
  To: u-boot

in mxc_spi_probe() plat and mxcs pointer are created:

struct mxc_spi_slave *plat = bus->platdata;
struct mxc_spi_slave *mxcs = dev_get_platdata(bus);

which have the same value. Remove plat pointer.

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

---

Changes in v2:
- added Jagan Teki to cc
- based patches on:
  e1a2ed7180 - Merge git://git.denx.de/u-boot-mpc83xx <Tom Rini>

 drivers/spi/mxc_spi.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
index 6846762719..fba76bf740 100644
--- a/drivers/spi/mxc_spi.c
+++ b/drivers/spi/mxc_spi.c
@@ -488,7 +488,6 @@ void spi_release_bus(struct spi_slave *slave)
 
 static int mxc_spi_probe(struct udevice *bus)
 {
-	struct mxc_spi_slave *plat = bus->platdata;
 	struct mxc_spi_slave *mxcs = dev_get_platdata(bus);
 	int node = dev_of_offset(bus);
 	const void *blob = gd->fdt_blob;
@@ -500,11 +499,11 @@ static int mxc_spi_probe(struct udevice *bus)
 		return -EINVAL;
 	}
 
-	plat->base = devfdt_get_addr(bus);
-	if (plat->base == FDT_ADDR_T_NONE)
+	mxcs->base = devfdt_get_addr(bus);
+	if (mxcs->base == FDT_ADDR_T_NONE)
 		return -ENODEV;
 
-	ret = dm_gpio_set_value(&plat->ss, 0);
+	ret = dm_gpio_set_value(&mxcs->ss, 0);
 	if (ret) {
 		dev_err(bus, "Setting cs error\n");
 		return ret;
-- 
2.21.0

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

* [U-Boot] [PATCH v2 2/2] spi: imx: work with cs greater 0
  2019-05-26 10:15 [U-Boot] [PATCH v2 0/2] mxc_spi: DM improvements Heiko Schocher
  2019-05-26 10:15 ` [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from mxc_spi_probe Heiko Schocher
@ 2019-05-26 10:15 ` Heiko Schocher
  2019-06-10  9:39   ` sbabic at denx.de
  1 sibling, 1 reply; 5+ messages in thread
From: Heiko Schocher @ 2019-05-26 10:15 UTC (permalink / raw)
  To: u-boot

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

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

---

Changes in v2:
- fixed build error, seen on travis (Sorry for v1 I pushed
  the wrong branch to travis):
  drivers/spi/mxc_spi.c: In function 'mxc_spi_cs_activate':
  drivers/spi/mxc_spi.c:69:21: error: dereferencing pointer to incomplete type 'struct dm_spi_slave_platdata'

 drivers/spi/mxc_spi.c | 74 ++++++++++++++++++++++++++++++-------------
 1 file changed, 52 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
index fba76bf740..d94aaf9fdb 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,22 +63,38 @@ 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)
 {
-	if (CONFIG_IS_ENABLED(DM_SPI)) {
-		dm_gpio_set_value(&mxcs->ss, 1);
-	} else {
-		if (mxcs->gpio > 0)
-			gpio_set_value(mxcs->gpio, mxcs->ss_pol);
-	}
+#if defined(CONFIG_DM_SPI)
+	struct udevice *dev = mxcs->dev;
+	struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
+
+	u32 cs = slave_plat->cs;
+
+	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);
+#endif
 }
 
 static void mxc_spi_cs_deactivate(struct mxc_spi_slave *mxcs)
 {
-	if (CONFIG_IS_ENABLED(DM_SPI)) {
-		dm_gpio_set_value(&mxcs->ss, 0);
-	} else {
-		if (mxcs->gpio > 0)
-			gpio_set_value(mxcs->gpio, !(mxcs->ss_pol));
-	}
+#if defined(CONFIG_DM_SPI)
+	struct udevice *dev = mxcs->dev;
+	struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
+
+	u32 cs = slave_plat->cs;
+
+	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));
+#endif
 }
 
 u32 get_cspi_div(u32 div)
@@ -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.21.0

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

* [U-Boot]  [PATCH v2 2/2] spi: imx: work with cs greater 0
  2019-05-26 10:15 ` [U-Boot] [PATCH v2 2/2] spi: imx: work with cs greater 0 Heiko Schocher
@ 2019-06-10  9:39   ` sbabic at denx.de
  0 siblings, 0 replies; 5+ messages in thread
From: sbabic at denx.de @ 2019-06-10  9:39 UTC (permalink / raw)
  To: u-boot

> currently spi mxc driver can only handle cs 0.
> Allow it to handle also cs > 0.
> Signed-off-by: Heiko Schocher <hs@denx.de>

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

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

* [U-Boot]  [PATCH v2 1/2] spi: imx: remove doubled pointer from
  2019-05-26 10:15 ` [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from mxc_spi_probe Heiko Schocher
@ 2019-06-10  9:40   ` sbabic at denx.de
  0 siblings, 0 replies; 5+ messages in thread
From: sbabic at denx.de @ 2019-06-10  9:40 UTC (permalink / raw)
  To: u-boot

> in mxc_spi_probe() plat and mxcs pointer are created:
> struct mxc_spi_slave *plat = bus->platdata;
> struct mxc_spi_slave *mxcs = dev_get_platdata(bus);
> which have the same value. Remove plat pointer.
> Signed-off-by: Heiko Schocher <hs@denx.de>

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

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

end of thread, other threads:[~2019-06-10  9:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-26 10:15 [U-Boot] [PATCH v2 0/2] mxc_spi: DM improvements Heiko Schocher
2019-05-26 10:15 ` [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from mxc_spi_probe Heiko Schocher
2019-06-10  9:40   ` [U-Boot] [PATCH v2 1/2] spi: imx: remove doubled pointer from sbabic at denx.de
2019-05-26 10:15 ` [U-Boot] [PATCH v2 2/2] spi: imx: work with cs greater 0 Heiko Schocher
2019-06-10  9:39   ` sbabic at denx.de

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.