All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors
@ 2020-05-11 13:22 Johannes Holland
  2020-05-11 13:22 ` [PATCH 2/2] spi: add support for all spi modes with soft spi Johannes Holland
  2020-07-09  0:22 ` [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors Tom Rini
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Holland @ 2020-05-11 13:22 UTC (permalink / raw)
  To: u-boot

tpm_tis_spi.c directly includes tpm_tis.h and tpm-v2.h which both
define the same enums (see e.g. TPM_ACCESS_VALID). Add an #ifndef to
prevent redeclaration errors.

Signed-off-by: Johannes Holland <johannes.holland@infineon.com>
---
 drivers/tpm/tpm_tis.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tpm/tpm_tis.h b/drivers/tpm/tpm_tis.h
index 947585f8e3..2a160fe05c 100644
--- a/drivers/tpm/tpm_tis.h
+++ b/drivers/tpm/tpm_tis.h
@@ -104,6 +104,7 @@ struct tpm_cmd_t {
 /* Max number of iterations after i2c NAK */
 #define MAX_COUNT		3
 
+#ifndef __TPM_V2_H
 /*
  * Max number of iterations after i2c NAK for 'long' commands
  *
@@ -127,5 +128,6 @@ enum tis_status {
 	TPM_STS_DATA_AVAIL		= 0x10,
 	TPM_STS_DATA_EXPECT		= 0x08,
 };
+#endif
 
 #endif
-- 
2.26.1

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

* [PATCH 2/2] spi: add support for all spi modes with soft spi
  2020-05-11 13:22 [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors Johannes Holland
@ 2020-05-11 13:22 ` Johannes Holland
  2020-07-09  8:22   ` Jagan Teki
  2020-07-09  0:22 ` [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors Tom Rini
  1 sibling, 1 reply; 4+ messages in thread
From: Johannes Holland @ 2020-05-11 13:22 UTC (permalink / raw)
  To: u-boot

The spi bitbanging driver did not implement all spi modes properly. Add
code to support all spi modes, honoring soft_spi_set_mode() and
defaulting to spi mode 0. Previously, CPHA was implemented inversely
(defaulting to CPHA=1) and CPOL=1 was hardcoded.

Signed-off-by: Johannes Holland <johannes.holland@infineon.com>
---
 drivers/spi/soft_spi.c | 48 ++++++++++++++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c
index b80f810bd1..08b6c53315 100644
--- a/drivers/spi/soft_spi.c
+++ b/drivers/spi/soft_spi.c
@@ -58,10 +58,12 @@ static int soft_spi_sda(struct udevice *dev, int bit)
 static int soft_spi_cs_activate(struct udevice *dev)
 {
 	struct udevice *bus = dev_get_parent(dev);
+	struct soft_spi_priv *priv = dev_get_priv(bus);
 	struct soft_spi_platdata *plat = dev_get_platdata(bus);
+	int cidle = !!(priv->mode & SPI_CPOL);
 
 	dm_gpio_set_value(&plat->cs, 0);
-	dm_gpio_set_value(&plat->sclk, 0);
+	dm_gpio_set_value(&plat->sclk, cidle); /* to idle */
 	dm_gpio_set_value(&plat->cs, 1);
 
 	return 0;
@@ -79,11 +81,14 @@ static int soft_spi_cs_deactivate(struct udevice *dev)
 
 static int soft_spi_claim_bus(struct udevice *dev)
 {
+	struct udevice *bus = dev_get_parent(dev);
+	struct soft_spi_priv *priv = dev_get_priv(bus);
+	int cidle = !!(priv->mode & SPI_CPOL);
 	/*
 	 * Make sure the SPI clock is in idle state as defined for
 	 * this slave.
 	 */
-	return soft_spi_scl(dev, 0);
+	return soft_spi_scl(dev, cidle);
 }
 
 static int soft_spi_release_bus(struct udevice *dev)
@@ -114,7 +119,8 @@ static int soft_spi_xfer(struct udevice *dev, unsigned int bitlen,
 	uchar		tmpdout = 0;
 	const u8	*txd = dout;
 	u8		*rxd = din;
-	int		cpha = priv->mode & SPI_CPHA;
+	int		cpha = !!(priv->mode & SPI_CPHA);
+	int		cidle = !!(priv->mode & SPI_CPOL);
 	unsigned int	j;
 
 	debug("spi_xfer: slave %s:%s dout %08X din %08X bitlen %u\n",
@@ -140,22 +146,42 @@ static int soft_spi_xfer(struct udevice *dev, unsigned int bitlen,
 			tmpdin  = 0;
 		}
 
-		if (!cpha)
-			soft_spi_scl(dev, 0);
+		/*
+		 * CPOL 0: idle is low (0), active is high (1)
+		 * CPOL 1: idle is high (1), active is low (0)
+		 */
+
+		/*
+		 * drive bit
+		 *  CPHA 1: CLK from idle to active
+		 */
+		if (cpha)
+			soft_spi_scl(dev, !cidle);
 		if ((plat->flags & SPI_MASTER_NO_TX) == 0)
 			soft_spi_sda(dev, !!(tmpdout & 0x80));
 		udelay(plat->spi_delay_us);
-		if (cpha)
-			soft_spi_scl(dev, 0);
+
+		/*
+		 * sample bit
+		 *  CPHA 0: CLK from idle to active
+		 *  CPHA 1: CLK from active to idle
+		 */
+		if (!cpha)
+			soft_spi_scl(dev, !cidle);
 		else
-			soft_spi_scl(dev, 1);
+			soft_spi_scl(dev, cidle);
 		tmpdin	<<= 1;
 		if ((plat->flags & SPI_MASTER_NO_RX) == 0)
 			tmpdin	|= dm_gpio_get_value(&plat->miso);
 		tmpdout	<<= 1;
 		udelay(plat->spi_delay_us);
-		if (cpha)
-			soft_spi_scl(dev, 1);
+
+		/*
+		 * drive bit
+		 *  CPHA 0: CLK from active to idle
+		 */
+		if (!cpha)
+			soft_spi_scl(dev, cidle);
 	}
 	/*
 	 * If the number of bits isn't a multiple of 8, shift the last
@@ -176,7 +202,7 @@ static int soft_spi_xfer(struct udevice *dev, unsigned int bitlen,
 
 static int soft_spi_set_speed(struct udevice *dev, unsigned int speed)
 {
-	/* Accept any speed */
+	/* Ignore any speed settings. Speed is implemented via "spi-delay-us" */
 	return 0;
 }
 
-- 
2.26.1

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

* [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors
  2020-05-11 13:22 [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors Johannes Holland
  2020-05-11 13:22 ` [PATCH 2/2] spi: add support for all spi modes with soft spi Johannes Holland
@ 2020-07-09  0:22 ` Tom Rini
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2020-07-09  0:22 UTC (permalink / raw)
  To: u-boot

On Mon, May 11, 2020 at 03:22:25PM +0200, Johannes Holland wrote:

> tpm_tis_spi.c directly includes tpm_tis.h and tpm-v2.h which both
> define the same enums (see e.g. TPM_ACCESS_VALID). Add an #ifndef to
> prevent redeclaration errors.
> 
> Signed-off-by: Johannes Holland <johannes.holland@infineon.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200708/99b027f4/attachment.sig>

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

* [PATCH 2/2] spi: add support for all spi modes with soft spi
  2020-05-11 13:22 ` [PATCH 2/2] spi: add support for all spi modes with soft spi Johannes Holland
@ 2020-07-09  8:22   ` Jagan Teki
  0 siblings, 0 replies; 4+ messages in thread
From: Jagan Teki @ 2020-07-09  8:22 UTC (permalink / raw)
  To: u-boot

On Mon, May 11, 2020 at 6:53 PM Johannes Holland
<johannes.holland@infineon.com> wrote:
>
> The spi bitbanging driver did not implement all spi modes properly. Add
> code to support all spi modes, honoring soft_spi_set_mode() and
> defaulting to spi mode 0. Previously, CPHA was implemented inversely
> (defaulting to CPHA=1) and CPOL=1 was hardcoded.
>
> Signed-off-by: Johannes Holland <johannes.holland@infineon.com>
> ---

Applied to u-boot-spi/master

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

end of thread, other threads:[~2020-07-09  8:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 13:22 [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors Johannes Holland
2020-05-11 13:22 ` [PATCH 2/2] spi: add support for all spi modes with soft spi Johannes Holland
2020-07-09  8:22   ` Jagan Teki
2020-07-09  0:22 ` [PATCH 1/2] tpm: add #ifndef to fix redeclaration build errors Tom Rini

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.