[U-Boot] [PATCH 1/2][v2] powerpc: eSPI and eSPI controller support

From: Mingkai Hu Mingkai.hu@freescale.com
Signed-off-by: Mingkai Hu Mingkai.hu@freescale.com Singed-off-by: Jerry Huang Chang-Ming.Huang@freescale.com Signed-off-by: Shaohui Xie b21989@freescale.com Cc: Mike Frysinger vapier@gentoo.org --- 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
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index d582fbb..74f1293 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -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) diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c new file mode 100644 index 0000000..9b8ae9a --- /dev/null +++ b/drivers/spi/fsl_espi.c @@ -0,0 +1,297 @@ +/* + * eSPI controller driver. + * + * Copyright 2010-2011 Freescale Semiconductor, Inc. + * Author: Mingkai Hu (Mingkai.hu@freescale.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> + +#include <malloc.h> +#include <spi.h> +#include <asm/immap_85xx.h> + +#define ESPI_MAX_CS_NUM 4 + +#define ESPI_EV_RNE (1 << 9) +#define ESPI_EV_TNF (1 << 8) + +#define ESPI_MODE_EN (1 << 31) /* Enable interface */ +#define ESPI_MODE_TXTHR(x) ((x) << 8) /* Tx FIFO threshold */ +#define ESPI_MODE_RXTHR(x) ((x) << 0) /* Rx FIFO threshold */ + +#define ESPI_COM_CS(x) ((x) << 30) +#define ESPI_COM_TRANLEN(x) ((x) << 0) + +#define ESPI_CSMODE_CI_INACTIVEHIGH (1 << 31) +#define ESPI_CSMODE_CP_BEGIN_EDGCLK (1 << 30) +#define ESPI_CSMODE_REV_MSB_FIRST (1 << 29) +#define ESPI_CSMODE_DIV16 (1 << 28) +#define ESPI_CSMODE_PM(x) ((x) << 24) +#define ESPI_CSMODE_POL_ASSERTED_LOW (1 << 20) +#define ESPI_CSMODE_LEN(x) ((x) << 16) +#define ESPI_CSMODE_CSBEF(x) ((x) << 12) +#define ESPI_CSMODE_CSAFT(x) ((x) << 8) +#define ESPI_CSMODE_CSCG(x) ((x) << 3) + +#define ESPI_CSMODE_INIT_VAL (ESPI_CSMODE_POL_ASSERTED_LOW | \ + ESPI_CSMODE_CSBEF(0) | ESPI_CSMODE_CSAFT(0) | \ + ESPI_CSMODE_CSCG(1)) + +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); + struct spi_slave *slave; + sys_info_t sysinfo; + unsigned long spibrg = 0; + unsigned char pm = 0; + int i; + + if (!spi_cs_is_valid(bus, cs)) + return NULL; + + slave = malloc(sizeof(struct spi_slave)); + if (!slave) + return NULL; + + slave->bus = bus; + slave->cs = cs; + + /* 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 */ + + /* 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))); + + /* Set eSPI BRG clock source */ + get_sys_info(&sysinfo); + spibrg = sysinfo.freqSystemBus / 2; + if ((spibrg / max_hz) > 32) { + out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) + | ESPI_CSMODE_DIV16); + pm = spibrg / (max_hz * 16 * 2); + if (pm > 16) { + pm = 16; + debug("Requested speed is too low: %d Hz" + " %d Hz is used.\n", max_hz, spibrg / (32 * 16)); + } + } else + pm = spibrg / (max_hz * 2); + if (pm) + pm--; + out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) + | ESPI_CSMODE_PM(pm)); + + /* Set eSPI mode */ + if (mode & SPI_CPHA) + out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) + | ESPI_CSMODE_CP_BEGIN_EDGCLK); + if (mode & SPI_CPOL) + out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) + | ESPI_CSMODE_CI_INACTIVEHIGH); + + /* Character bit order: msb first */ + out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) + | ESPI_CSMODE_REV_MSB_FIRST); + + /* Character length in bits, between 0x3~0xf, i.e. 4bits~16bits */ + out_be32(&espi->csmode[cs], in_be32(&espi->csmode[cs]) + | ESPI_CSMODE_LEN(7)); + + return slave; +} + +void spi_free_slave(struct spi_slave *slave) +{ + free(slave); +} + +void spi_init(void) +{ + +} + +int spi_claim_bus(struct spi_slave *slave) +{ + return 0; +} + +void spi_release_bus(struct spi_slave *slave) +{ + +} + +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) { + case SPI_XFER_BEGIN: + cmd_len = bitlen / 8; + memcpy(cmd_buf, data_out, cmd_len); + return 0; + case 0: + case SPI_XFER_END: + if (bitlen == 0) { + spi_cs_deactivate(slave); + return 0; + } + buf_len = 2 * cmd_len + bitlen / 8; + len = cmd_len + bitlen / 8; + buffer = (unsigned char *)malloc(buf_len); + if (!buffer) { + debug("SF: Failed to malloc memory.\n"); + return 1; + } + memcpy(buffer, cmd_buf, cmd_len); + if (cmd_len != 1) { + if (data_in == NULL) + memcpy(buffer + cmd_len, data_out, bitlen / 8); + else if (data_out == NULL) + din = buffer + cmd_len; + } else { + din = buffer + cmd_len; + } + dout = buffer; + break; + case SPI_XFER_BEGIN | SPI_XFER_END: + len = bitlen / 8; + buffer = (unsigned char *)malloc(len * 2); + if (!buffer) { + debug("SF: Failed to malloc memory.\n"); + return 1; + } + memcpy(buffer, data_out, len); + dout = buffer; + din = buffer + len; + break; + default: + printf("Bad flags: %ld\n", flags); + return 1; + } + numBlks = len / 4 + (len % 4 ? 1 : 0); + num_bytes = len % 4; + + debug("spi_xfer: slave %u:%u dout %08X(%08x) din %08X(%08x) len %u\n", + slave->bus, slave->cs, *(uint *) dout, + dout, *(uint *) din, din, len); + + data_len = len; + spi_cs_activate(slave); + + /* Clear all eSPI events */ + out_be32(&espi->event , 0xffffffff); + + /* handle data in 32-bit chunks */ + while (numBlks--) { + + event = in_be32(&espi->event); + if (event & ESPI_EV_TNF) { + tmpdout = *(u32 *)dout; + + /* Set up the next iteration if sending > 4 bytes */ + if (len > 4) { + len -= 4; + dout += 4; + } + + out_be32(&espi->tx, tmpdout); + out_be32(&espi->event, ESPI_EV_TNF); + debug("*** spi_xfer: ... %08x written\n", tmpdout); + } + + /* Wait for eSPI transmit to get out */ + udelay(80); + + event = in_be32(&espi->event); + if (event & ESPI_EV_RNE) { + tmpdin = in_be32(&espi->rx); + if (numBlks == 0 && num_bytes != 0) { + ch = (unsigned char *)&tmpdin; + while (num_bytes--) + *(unsigned char *)din++ = *ch++; + } else { + *(u32 *) din = tmpdin; + din += 4; + } + + out_be32(&espi->event, in_be32(&espi->event) + | ESPI_EV_RNE); + debug("*** spi_xfer: ... %08x readed\n", tmpdin); + } + } + + spi_cs_deactivate(slave); + if (data_in) + memcpy(data_in, buffer + 2 * cmd_len, bitlen/8); + + free(buffer); + return 0; +} + +int spi_cs_is_valid(unsigned int bus, unsigned int cs) +{ + return bus == 0 && cs < ESPI_MAX_CS_NUM; +} + +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; +} + +void spi_cs_deactivate(struct spi_slave *slave) +{ + ccsr_espi_t *espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR); + + /* clear the RXCNT and TXCNT */ + out_be32(&espi->mode, in_be32(&espi->mode) & (~ESPI_MODE_EN)); + out_be32(&espi->mode, in_be32(&espi->mode) | ESPI_MODE_EN); +} diff --git a/include/spi.h b/include/spi.h index 320e50e..c5da3ca 100644 --- a/include/spi.h +++ b/include/spi.h @@ -2,6 +2,8 @@ * (C) Copyright 2001 * Gerald Van Baren, Custom IDEAS, vanbaren@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

On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
--- a/include/spi.h +++ b/include/spi.h /* 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
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

On Apr 21, 2011, at 12:10 PM, Mike Frysinger wrote:
On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
--- a/include/spi.h +++ b/include/spi.h /* 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
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

On Thu, Apr 21, 2011 at 2:13 PM, Kumar Gala wrote:
On Apr 21, 2011, at 12:10 PM, Mike Frysinger wrote:
On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
--- a/include/spi.h +++ b/include/spi.h /* 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
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
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

On Apr 21, 2011, at 4:20 PM, Mike Frysinger wrote:
On Thu, Apr 21, 2011 at 2:13 PM, Kumar Gala wrote:
On Apr 21, 2011, at 12:10 PM, Mike Frysinger wrote:
On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
--- a/include/spi.h +++ b/include/spi.h /* 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
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
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

-----Original Message----- From: vapierfilter@gmail.com [mailto:vapierfilter@gmail.com] On Behalf Of Mike Frysinger Sent: Friday, April 22, 2011 1:10 AM To: Xie Shaohui-B21989 Cc: u-boot@lists.denx.de; Gala Kumar-B11780; Zang Roy-R61911; Hu Mingkai- B21284 Subject: Re: [PATCH 1/2][v2] powerpc: eSPI and eSPI controller support
On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
--- a/include/spi.h +++ b/include/spi.h /* 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
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

On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
+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 ;).
- /* 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 */
- /* 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.
+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) {
- 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.
+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

On Apr 21, 2011, at 4:25 PM, Mike Frysinger wrote:
On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
+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.
/* 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 */
/* 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.
+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) {
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.
+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

From: vapierfilter@gmail.com [mailto:vapierfilter@gmail.com] On Behalf Of Mike Frysinger Sent: Friday, April 22, 2011 5:25 AM To: Xie Shaohui-B21989 Cc: u-boot@lists.denx.de; Gala Kumar-B11780; Zang Roy-R61911; Hu Mingkai- B21284 Subject: Re: [PATCH 1/2][v2] powerpc: eSPI and eSPI controller support
On Thu, Apr 21, 2011 at 2:04 AM, Shaohui Xie wrote:
+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.
- /* 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 */
- /* 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.
[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.
+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) {
- 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.
+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
[Xie Shaohui] OK, I'll drop the return. Thanks.
Best Regards, Shaohui Xie
participants (5)
-
Kumar Gala
-
Kumar Gala
-
Mike Frysinger
-
Shaohui Xie
-
Xie Shaohui-B21989