Skip to contentSkip to conversation

powerpc: eSPI and eSPI controller support

PATCH Superseded Shaohui Xie 4 participants 9 messages Apr 21, 2011 – Apr 22, 2011 SPI

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

From: Mingkai Hu <[email protected]>

---
changes for v2:
remove #ifdef wrapper and refactor spi_xfer by use SPI_XFER(BEGIN | END). remove 'volatile' use I/O accessors instead.

 drivers/spi/Makefile   |    1 +
 drivers/spi/fsl_espi.c |  297 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/spi.h          |    4 +-
 3 files changed, 301 insertions(+), 1 deletions(-)
 create mode 100644 drivers/spi/fsl_espi.c
drivers/spi/Makefile +1 -0
index d582fbb..74f1293 100644
@@ -38,6 +38,7 @@ COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
 COBJS-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
 COBJS-$(CONFIG_SH_SPI) += sh_spi.o
+COBJS-$(CONFIG_FSL_ESPI) += fsl_espi.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/spi/fsl_espi.c new file +297 -0

297 lines not on this page · raw message

include/spi.h +3 -1
index 320e50e..c5da3ca 100644
@@ -2,6 +2,8 @@
  * (C) Copyright 2001
  * Gerald Van Baren, Custom IDEAS, vanbaren at cideas.com.
  *
+ * Copyright 2010-2011 Freescale Semiconductor, Inc
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
@@ -27,7 +29,7 @@
 /* Controller-specific definitions: */
 
 /* CONFIG_HARD_SPI triggers SPI bus initialization in PowerPC */
-#ifdef CONFIG_MPC8XXX_SPI
+#if defined(CONFIG_MPC8XXX_SPI) || defined(CONFIG_FSL_ESPI)
 # ifndef CONFIG_HARD_SPI
 #  define CONFIG_HARD_SPI
 # endif
Signature · 1 line
1.6.4
#1 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

Quoted 10 lines · Shaohui Xie
include/spi.h +0 -0

?/* Controller-specific definitions: */

?/* CONFIG_HARD_SPI triggers SPI bus initialization in PowerPC */

include/spi.h +1 -1
-#ifdef CONFIG_MPC8XXX_SPI
+#if defined(CONFIG_MPC8XXX_SPI) || defined(CONFIG_FSL_ESPI)

?# ifndef CONFIG_HARD_SPI
?# ?define CONFIG_HARD_SPI
?# endif

i cant see why this PowerPC-specific code needs to be in the common spi.h. why cant this live in a PowerPC header like asm/config.h ? (i know this code predates asm/config.h)
-mike

#2 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

Quoted 5 lines · Mike Frysinger
Quoted 4 lines · Shaohui Xie
include/spi.h +0 -0

/* Controller-specific definitions: */

Quoted 11 lines
Quoted 6 lines

/* CONFIG_HARD_SPI triggers SPI bus initialization in PowerPC */

include/spi.h +1 -1
-#ifdef CONFIG_MPC8XXX_SPI
+#if defined(CONFIG_MPC8XXX_SPI) || defined(CONFIG_FSL_ESPI)
# ifndef CONFIG_HARD_SPI
#  define CONFIG_HARD_SPI
# endif

i cant see why this PowerPC-specific code needs to be in the common spi.h. why cant this live in a PowerPC header like asm/config.h ? (i know this code predates asm/config.h)
-mike

If the rest of the patch looks fine we can move this into asm/config.h

There are a bunch of board patches I'd like to get in that depend on the base SPI driver being in tree.

- k

#3 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

Quoted 17 lines · Kumar Gala
Quoted 5 lines · Mike Frysinger
Quoted 4 lines · Shaohui Xie
include/spi.h +0 -0

/* Controller-specific definitions: */

Quoted 10 lines
Quoted 6 lines

/* CONFIG_HARD_SPI triggers SPI bus initialization in PowerPC */

include/spi.h +1 -1
-#ifdef CONFIG_MPC8XXX_SPI
+#if defined(CONFIG_MPC8XXX_SPI) || defined(CONFIG_FSL_ESPI)
# ifndef CONFIG_HARD_SPI
# ?define CONFIG_HARD_SPI
# endif

i cant see why this PowerPC-specific code needs to be in the common spi.h. ?why cant this live in a PowerPC header like asm/config.h ? ?(i know this code predates asm/config.h)

Quoted 3 lines

If the rest of the patch looks fine we can move this into asm/config.h

There are a bunch of board patches I'd like to get in that depend on the base SPI driver being in tree.

i dont run spi drivers through my tree, so generally if the arch maintainer is happy with it, it's up to them to merge it. i watch over the spi core and the spi flash pieces, and sometimes give feedback on the specific spi drivers.
-mike

#4 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

Quoted 20 lines · Mike Frysinger
Quoted 19 lines · Kumar Gala
Quoted 5 lines · Mike Frysinger
Quoted 4 lines · Shaohui Xie
include/spi.h +0 -0

/* Controller-specific definitions: */

Quoted 10 lines
Quoted 6 lines

/* CONFIG_HARD_SPI triggers SPI bus initialization in PowerPC */

include/spi.h +1 -1
-#ifdef CONFIG_MPC8XXX_SPI
+#if defined(CONFIG_MPC8XXX_SPI) || defined(CONFIG_FSL_ESPI)
# ifndef CONFIG_HARD_SPI
#  define CONFIG_HARD_SPI
# endif

i cant see why this PowerPC-specific code needs to be in the common spi.h. why cant this live in a PowerPC header like asm/config.h ? (i know this code predates asm/config.h)

If the rest of the patch looks fine we can move this into asm/config.h

Quoted 7 lines
Quoted 1 line

There are a bunch of board patches I'd like to get in that depend on the base SPI driver being in tree.

i dont run spi drivers through my tree, so generally if the arch maintainer is happy with it, it's up to them to merge it. i watch over the spi core and the spi flash pieces, and sometimes give feedback on the specific spi drivers.
-mike

Ok, I'll take it via my tree, but would like your ack on the patch.

- k

#5 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

In reply to Mike Frysinger
Quoted 5 lines

-----Original Message-----

From: [email protected] [mailto:vapierfilter at gmail.com] On Behalf Of

Quoted 12 lines

Mike Frysinger
Sent: Friday, April 22, 2011 1:10 AM
To: Xie Shaohui-B21989
Cc: u-boot at lists.denx.de; Gala Kumar-B11780; Zang Roy-R61911; Hu Mingkai- B21284
Subject: Re: [PATCH 1/2][v2] powerpc: eSPI and eSPI controller support

Quoted 4 lines · Shaohui Xie
include/spi.h +0 -0

?/* Controller-specific definitions: */

Quoted 10 lines
Quoted 6 lines

?/* CONFIG_HARD_SPI triggers SPI bus initialization in PowerPC */

include/spi.h +1 -1
-#ifdef CONFIG_MPC8XXX_SPI
+#if defined(CONFIG_MPC8XXX_SPI) || defined(CONFIG_FSL_ESPI)

?# ifndef CONFIG_HARD_SPI
?# ?define CONFIG_HARD_SPI
?# endif

i cant see why this PowerPC-specific code needs to be in the common spi.h. why cant this live in a PowerPC header like asm/config.h ? (i know this code predates asm/config.h) -mike

[Xie Shaohui] OK, I'll move these codes to asm/config.h

Best Regards,
Shaohui Xie

#6 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

In reply to Shaohui Xie

drivers/spi/fsl_espi.c line 59

Quoted 4 lines · Shaohui Xie
drivers/spi/fsl_espi.c new file +4 -0
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+ ? ? ? ? ? ? ? unsigned int max_hz, unsigned int mode)
+{
+       ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);

you support just one bus ? that's no fun ;).

Quoted 6 lines

+ ? ? ? /* Enable eSPI interface */
+ ? ? ? out_be32(&espi->mode, ESPI_MODE_RXTHR(3)
+ ? ? ? ? ? ? ? ? ? ? ? | ESPI_MODE_TXTHR(4) | ESPI_MODE_EN);

(quoted diff) +3 -0
+
+ ? ? ? out_be32(&espi->event, 0xffffffff); /* Clear all eSPI events */
+ ? ? ? out_be32(&espi->mask, 0x00000000); /* Mask ?all eSPI interrupts */

Review

Quoted 10 lines
(quoted diff) +9 -0
+
+ ? ? ? /* Init CS mode interface */
+ ? ? ? for (i = 0; i < ESPI_MAX_CS_NUM; i++)
+ ? ? ? ? ? ? ? out_be32(&espi->csmode[i], ESPI_CSMODE_INIT_VAL);
+
+ ? ? ? out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) &
+ ? ? ? ? ? ? ? ~(ESPI_CSMODE_PM(0xF) | ESPI_CSMODE_DIV16
+ ? ? ? ? ? ? ? | ESPI_CSMODE_CI_INACTIVEHIGH | ESPI_CSMODE_CP_BEGIN_EDGCLK
+ ? ? ? ? ? ? ? | ESPI_CSMODE_REV_MSB_FIRST | ESPI_CSMODE_LEN(0xF)));
........

usually spi_setup_slave() is to get the slave client ready to be used.
it shouldnt be programming any actual hardware registers. that is
the point of the spi_claim_bus() and spi_release_bus() steps ... use the information in the slave state to setup the hardware for that slave and then break it down in the release step.

Quoted 13 lines
(quoted diff) +13 -0
+static u8 cmd_buf[16];
+static size_t cmd_len;
+static size_t data_len;
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out,
+ ? ? ? ? ? ? ? void *data_in, unsigned long flags)
+{
+ ? ? ? ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
+ ? ? ? unsigned int tmpdout, tmpdin, event;
+ ? ? ? const void *dout = NULL;
+ ? ? ? void *din = NULL;
+ ? ? ? unsigned int len;
+ ? ? ? int numBlks;

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ? ? ? int num_bytes;
+ ? ? ? unsigned char *ch;
+ ? ? ? unsigned char *buffer;
+ ? ? ? size_t buf_len;
+
+ ? ? ? switch (flags) {
+ ? ? ? case SPI_XFER_BEGIN:
+ ? ? ? ? ? ? ? cmd_len = bitlen / 8;
+ ? ? ? ? ? ? ? memcpy(cmd_buf, data_out, cmd_len);
+ ? ? ? ? ? ? ? return 0;

interesting solution to the problem, but i'd think it might make more sense to have this state live in the slave data rather than in the global bus.

Review

Quoted 12 lines
(quoted diff) +12 -0
+void spi_cs_activate(struct spi_slave *slave)
+{
+ ? ? ? ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
+ ? ? ? unsigned int com = 0;
+
+ ? ? ? com &= ~(ESPI_COM_CS(0x3) | ESPI_COM_TRANLEN(0xFFFF));
+ ? ? ? com |= ESPI_COM_CS(slave->cs);
+ ? ? ? com |= ESPI_COM_TRANLEN(data_len - 1);
+ ? ? ? out_be32(&espi->com, com);
+
+ ? ? ? return;
+}

that return is useless and can be punted
-mike

#7 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

Quoted 7 lines · Mike Frysinger

drivers/spi/fsl_espi.c line 59

Quoted 4 lines · Shaohui Xie
drivers/spi/fsl_espi.c new file +4 -0
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+               unsigned int max_hz, unsigned int mode)
+{
+       ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);

you support just one bus ? that's no fun ;).

Until our SoC guys actually build a device with more than one, we'll keep with the one.

Quoted 52 lines
Quoted 7 lines
drivers/spi/fsl_espi.c new file +6 -0
+       /* Enable eSPI interface */
+       out_be32(&espi->mode, ESPI_MODE_RXTHR(3)
+                       | ESPI_MODE_TXTHR(4) | ESPI_MODE_EN);
+
+       out_be32(&espi->event, 0xffffffff); /* Clear all eSPI events */
+       out_be32(&espi->mask, 0x00000000); /* Mask  all eSPI interrupts */

drivers/spi/fsl_espi.c line 90

Quoted 10 lines
drivers/spi/fsl_espi.c new file +9 -0
+
+       /* Init CS mode interface */
+       for (i = 0; i < ESPI_MAX_CS_NUM; i++)
+               out_be32(&espi->csmode[i], ESPI_CSMODE_INIT_VAL);
+
+       out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) &
+               ~(ESPI_CSMODE_PM(0xF) | ESPI_CSMODE_DIV16
+               | ESPI_CSMODE_CI_INACTIVEHIGH | ESPI_CSMODE_CP_BEGIN_EDGCLK
+               | ESPI_CSMODE_REV_MSB_FIRST | ESPI_CSMODE_LEN(0xF)));
........

usually spi_setup_slave() is to get the slave client ready to be used. it shouldnt be programming any actual hardware registers. that is the point of the spi_claim_bus() and spi_release_bus() steps ... use the information in the slave state to setup the hardware for that slave and then break it down in the release step.

Quoted 13 lines
drivers/spi/fsl_espi.c new file +13 -0
+static u8 cmd_buf[16];
+static size_t cmd_len;
+static size_t data_len;
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out,
+               void *data_in, unsigned long flags)
+{
+       ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
+       unsigned int tmpdout, tmpdin, event;
+       const void *dout = NULL;
+       void *din = NULL;
+       unsigned int len;
+       int numBlks;

drivers/spi/fsl_espi.c line 172

Quoted 10 lines
drivers/spi/fsl_espi.c new file +10 -0
+       int num_bytes;
+       unsigned char *ch;
+       unsigned char *buffer;
+       size_t buf_len;
+
+       switch (flags) {
+       case SPI_XFER_BEGIN:
+               cmd_len = bitlen / 8;
+               memcpy(cmd_buf, data_out, cmd_len);
+               return 0;

interesting solution to the problem, but i'd think it might make more sense to have this state live in the slave data rather than in the global bus.

Quoted 14 lines

drivers/spi/fsl_espi.c line 288

Quoted 12 lines
drivers/spi/fsl_espi.c new file +12 -0
+void spi_cs_activate(struct spi_slave *slave)
+{
+       ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
+       unsigned int com = 0;
+
+       com &= ~(ESPI_COM_CS(0x3) | ESPI_COM_TRANLEN(0xFFFF));
+       com |= ESPI_COM_CS(slave->cs);
+       com |= ESPI_COM_TRANLEN(data_len - 1);
+       out_be32(&espi->com, com);
+
+       return;
+}

that return is useless and can be punted

- k

#8 lore raw

PATCH v2 1/2 powerpc: eSPI and eSPI controller support

In reply to Mike Frysinger

From: [email protected] [mailto:vapierfilter at gmail.com] On Behalf Of

Quoted 7 lines

Mike Frysinger
Sent: Friday, April 22, 2011 5:25 AM
To: Xie Shaohui-B21989
Cc: u-boot at lists.denx.de; Gala Kumar-B11780; Zang Roy-R61911; Hu Mingkai- B21284
Subject: Re: [PATCH 1/2][v2] powerpc: eSPI and eSPI controller support

Quoted 6 lines

drivers/spi/fsl_espi.c line 59

Quoted 3 lines · Shaohui Xie
drivers/spi/fsl_espi.c new file +3 -0
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+ ? ? ? ? ? ? ? unsigned int max_hz, unsigned int mode) {
+       ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);

you support just one bus ? that's no fun ;).

[Xie Shaohui] See Kumar's comment.

Quoted 18 lines
Quoted 18 lines

+ ? ? ? /* Enable eSPI interface */
+ ? ? ? out_be32(&espi->mode, ESPI_MODE_RXTHR(3)
+ ? ? ? ? ? ? ? ? ? ? ? | ESPI_MODE_TXTHR(4) | ESPI_MODE_EN);

(quoted diff) +14 -0
+
+ ? ? ? out_be32(&espi->event, 0xffffffff); /* Clear all eSPI events
+ */
+ ? ? ? out_be32(&espi->mask, 0x00000000); /* Mask ?all eSPI
+ interrupts */
+
+ ? ? ? /* Init CS mode interface */
+ ? ? ? for (i = 0; i < ESPI_MAX_CS_NUM; i++)
+ ? ? ? ? ? ? ? out_be32(&espi->csmode[i], ESPI_CSMODE_INIT_VAL);
+
+ ? ? ? out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) &
+ ? ? ? ? ? ? ? ~(ESPI_CSMODE_PM(0xF) | ESPI_CSMODE_DIV16
+ ? ? ? ? ? ? ? | ESPI_CSMODE_CI_INACTIVEHIGH |
+ ESPI_CSMODE_CP_BEGIN_EDGCLK
Quoted 9 lines
Quoted 2 lines

+ ? ? ? ? ? ? ? | ESPI_CSMODE_REV_MSB_FIRST | ESPI_CSMODE_LEN(0xF)));
........

usually spi_setup_slave() is to get the slave client ready to be used. it shouldnt be programming any actual hardware registers. that is the point of the spi_claim_bus() and spi_release_bus() steps ... use the information in the slave state to setup the hardware for that slave and then break it down in the release step.

[Xie Shaohui] OK, I'll move these operations out of spi_setup_slave(), use spi_claim_bus() and spi_release_bus() to setup and break down hardware.

Quoted 19 lines
Quoted 19 lines
(quoted diff) +19 -0
+static u8 cmd_buf[16];
+static size_t cmd_len;
+static size_t data_len;
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void
+*data_out,
+ ? ? ? ? ? ? ? void *data_in, unsigned long flags) {
+ ? ? ? ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
+ ? ? ? unsigned int tmpdout, tmpdin, event;
+ ? ? ? const void *dout = NULL;
+ ? ? ? void *din = NULL;
+ ? ? ? unsigned int len;
+ ? ? ? int numBlks;
+ ? ? ? int num_bytes;
+ ? ? ? unsigned char *ch;
+ ? ? ? unsigned char *buffer;
+ ? ? ? size_t buf_len;
+
+ ? ? ? switch (flags) {
Quoted 9 lines
Quoted 4 lines

+ ? ? ? case SPI_XFER_BEGIN:
+ ? ? ? ? ? ? ? cmd_len = bitlen / 8;
+ ? ? ? ? ? ? ? memcpy(cmd_buf, data_out, cmd_len);
+ ? ? ? ? ? ? ? return 0;

interesting solution to the problem, but i'd think it might make more sense to have this state live in the slave data rather than in the global bus.

[Xie Shaohui] OK, I'll use slave data to store these info.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +5 -0
+void spi_cs_activate(struct spi_slave *slave) {
+ ? ? ? ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
+ ? ? ? unsigned int com = 0;
+
+ ? ? ? com &= ~(ESPI_COM_CS(0x3) | ESPI_COM_TRANLEN(0xFFFF));
Quoted 8 lines

drivers/spi/fsl_espi.c line 103

Quoted 6 lines

+ ? ? ? com |= ESPI_COM_CS(slave->cs);
+ ? ? ? com |= ESPI_COM_TRANLEN(data_len - 1);
+ ? ? ? out_be32(&espi->com, com);

drivers/spi/fsl_espi.c new file +3 -0
+
+ ? ? ? return;
+}

that return is useless and can be punted -mike

[Xie Shaohui] OK, I'll drop the return. Thanks.

Best Regards,
Shaohui Xie