Skip to contentSkip to conversation

mpc52xx: Add SPI driver.

PATCH Superseded Grzegorz Bernacki 3 participants 8 messages Jun 9, 2009 – Jun 10, 2009 SPI

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 mpc52xx: Add SPI driver.

---
v2:
- use accessor macros

 drivers/spi/Makefile      |    1 +
 drivers/spi/mpc52xx_spi.c |  109 +++++++++++++++++++++++++++++++++++++++++++++
 include/mpc5xxx.h         |   18 +++++++
 3 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/mpc52xx_spi.c
drivers/spi/Makefile +1 -0
index 1350f3e..1272c17 100644
@@ -28,6 +28,7 @@ LIB	:= $(obj)libspi.a
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
+COBJS-$(CONFIG_MPC52XX_SPI) += mpc52xx_spi.o
 COBJS-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
 COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
 COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
drivers/spi/mpc52xx_spi.c new file +109 -0

109 lines not on this page · raw message

include/mpc5xxx.h +18 -0
index 463d5ae..476d149 100644
@@ -392,6 +392,24 @@
 #define I2C_IF		0x02
 #define I2C_RXAK	0x01
 
+/* SPI control register 1 bits */
+#define SPI_CR_LSBFE	0x01
+#define SPI_CR_SSOE	0x02
+#define SPI_CR_CPHA	0x04
+#define SPI_CR_CPOL	0x08
+#define SPI_CR_MSTR	0x10
+#define SPI_CR_SWOM	0x20
+#define SPI_CR_SPE	0x40
+#define SPI_CR_SPIE	0x80
+
+/* SPI status register bits */
+#define SPI_SR_MODF	0x10
+#define SPI_SR_WCOL	0x40
+#define SPI_SR_SPIF	0x80
+
+/* SPI port data register bits */
+#define SPI_PDR_SS	0x08
+
 /* Programmable Serial Controller (PSC) status register bits */
 #define PSC_SR_CDE		0x0080
 #define PSC_SR_RXRDY		0x0100
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH v2 2/3 digsy MTC: Add SPI support.

---
v2:
- use accessor macros

 board/digsy_mtc/digsy_mtc.c |   14 ++++++++++++++
 include/configs/digsy_mtc.h |    7 +++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
board/digsy_mtc/digsy_mtc.c +14 -0
index 83d5864..8e863bf 100644
@@ -186,6 +186,10 @@ int checkboard(void)
 
 int board_early_init_r(void)
 {
+#ifdef CONFIG_MPC52XX_SPI
+	struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
+	struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt*)MPC5XXX_GPT;
+#endif
 	/*
 	 * Now, when we are in RAM, enable flash write access for detection
 	 * process.  Note that CS_BOOT cannot be cleared when executing in
@@ -202,6 +206,16 @@ int board_early_init_r(void)
 	/* Low level USB init, required for proper kernel operation */
 	usb_cpu_init();
 #endif
+#ifdef CONFIG_MPC52XX_SPI
+	/* SPI on Tmr2/3/4/5 pins */
+	setbits_be32(&gpio->port_config, (1 << 29));
+
+	/* GPT 6 Output Enable */
+	out_be32(&gpt[6].emsr, 0x00000034);
+	/* GPT 7 Output Enable */
+	out_be32(&gpt[7].emsr, 0x00000034);
+#endif
+
 	return (0);
 }
 
include/configs/digsy_mtc.h +7 -0
index 66badd7..0cc2a8d 100644
@@ -100,6 +100,7 @@
 #define CONFIG_CMD_PING
 #define CONFIG_CMD_REGINFO
 #define CONFIG_CMD_SAVES
+#define CONFIG_CMD_SPI
 #define CONFIG_CMD_USB
 
 #if (TEXT_BASE == 0xFF000000)
@@ -137,6 +138,12 @@
 	""
 
 /*
+ * SPI configuration
+ */
+#define CONFIG_HARD_SPI		1
+#define CONFIG_MPC52XX_SPI	1
+
+/*
  * I2C configuration
  */
 #define CONFIG_HARD_I2C		1
Signature · 1 line
1.6.0.6
#2 lore raw

PATCH v2 2/3 digsy MTC: Add SPI support.

Hi Grzegorz,

Quoted 8 lines

---
v2:
- use accessor macros

 board/digsy_mtc/digsy_mtc.c |   14 ++++++++++++++
 include/configs/digsy_mtc.h |    7 +++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

[...]

board/digsy_mtc/digsy_mtc.c int board_early_init_r(void) · line 211

Quoted 3 lines
board/digsy_mtc/digsy_mtc.c +3 -0
+#ifdef CONFIG_MPC52XX_SPI
+	/* SPI on Tmr2/3/4/5 pins */
+	setbits_be32(&gpio->port_config, (1 << 29));

Sorry for missing this on the first round, but as this is always defined we should work this into CONFIG_SYS_GPS_PORT_CONFIG in digsy_mtc.h. A comment explaining this (as far as easily possible) would also be nice. include/configs/inka4x0.h is a nice example on how to do this.

Cheers
Detlev

Signature · 5 lines
Emacs is the way to purify your soul using garbage collection.
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: [email protected]
#3 lore raw

PATCH v2 2/3 digsy MTC: Add SPI support.

Quoted 11 lines

board/digsy_mtc/digsy_mtc.c int board_early_init_r(void) · line 211

Quoted 5 lines
board/digsy_mtc/digsy_mtc.c +3 -0
+#ifdef CONFIG_MPC52XX_SPI
+	/* SPI on Tmr2/3/4/5 pins */
+	setbits_be32(&gpio->port_config, (1 << 29));

Sorry for missing this on the first round, but as this is always defined we should work this into CONFIG_SYS_GPS_PORT_CONFIG in digsy_mtc.h. A comment explaining this (as far as easily possible) would also be nice. include/configs/inka4x0.h is a nice example on how to do this.

Setting this bit is unnecessary since it is already set in CONFIG_SYS_GPS_PORT_CONFIG which is used in digsy. I will create another patch in which I add some comment to this define.

Grzesiek

#4 lore raw

PATCH v2 3/3 digsy MTC: Add 'mtc' command.

In reply to Grzegorz Bernacki

New command allows to:
o check FW version
o set LED status
o set digital output status
o get digital input status

---
v2:
- implement sub-commands via U_BOOT_CMD_MKENT macro

 board/digsy_mtc/Makefile    |    2 +-
 board/digsy_mtc/cmd_mtc.c   |  350 +++++++++++++++++++++++++++++++++++++++++++
 board/digsy_mtc/cmd_mtc.h   |   60 ++++++++
 board/digsy_mtc/digsy_mtc.c |    2 +
 4 files changed, 413 insertions(+), 1 deletions(-)
 create mode 100644 board/digsy_mtc/cmd_mtc.c
 create mode 100644 board/digsy_mtc/cmd_mtc.h
board/digsy_mtc/Makefile +1 -1
index 7d659e5..0bededc 100644
@@ -7,7 +7,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(BOARD).a
 
-COBJS	:= $(BOARD).o
+COBJS	:= $(BOARD).o cmd_mtc.o
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
board/digsy_mtc/cmd_mtc.c new file +350 -0

350 lines not on this page · raw message

board/digsy_mtc/cmd_mtc.h new file +60 -0

60 lines not on this page · raw message

board/digsy_mtc/digsy_mtc.c +2 -0
index 8e863bf..e3c0329 100644
@@ -244,6 +244,7 @@ void board_get_enetaddr (uchar * enet)
 
 int misc_init_r(void)
 {
+	extern int mtc_cmd_init_r (void);
 	uchar enetaddr[6];
 
 	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
@@ -251,6 +252,7 @@ int misc_init_r(void)
 		eth_setenv_enetaddr("ethaddr", enetaddr);
 	}
 
+	mtc_cmd_init_r();
 	return 0;
 }
 
Signature · 1 line
1.6.0.6
#5 lore raw

PATCH v2 1/3 mpc52xx: Add SPI driver.

In reply to Grzegorz Bernacki

Hi Grzegorz,

Quoted 5 lines

---
v2:
- use accessor macros

[...]

drivers/spi/mpc52xx_spi.c line 43

Quoted 6 lines
drivers/spi/mpc52xx_spi.c new file +6 -0
+	out8((u32)&spi->ddr, 0x0F);	/* set all SPI pins as output */
+	out8((u32)&spi->pdr, 0x00);	/* set SS low */
+	/* SPI is master, SS is general purpose output */
+	out8((u32)&spi->cr1, SPI_CR_MSTR | SPI_CR_SPE);
+	out8((u32)&spi->cr2, 0x00);	/* normal operation */
+	out8((u32)&spi->brr, 0x77);	/* baud rate: IPB clock / 2048 */

Ok, we're actually using the accessor macros, but I fail to see why a (u32) cast is needed here - it even actively prevents one of the "features" of the macros, namely type checking.

Why exactly are they needed?

Thanks
Detlev

Signature · 6 lines
Irrationality is the square root of all evil.
                                     -- Douglas Hofstadter
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#6 lore raw

PATCH v2 1/3 mpc52xx: Add SPI driver.

Quoted 7 lines · Detlev Zundel

drivers/spi/mpc52xx_spi.c line 43

Quoted 1 line
drivers/spi/mpc52xx_spi.c new file +1 -0
+	out8((u32)&spi->brr, 0x77);	/* baud rate: IPB clock / 2048 */

Ok, we're actually using the accessor macros, but I fail to see why a (u32) cast is needed here - it even actively prevents one of the "features" of the macros, namely type checking.

Why exactly are they needed?

Declaration of out8() is in common.h file:
void out8(unsigned int, unsigned char);
so I think that this cast is necessary.

Without it I get warning:
mpc52xx_spi.c:38: warning: passing argument 1 of 'out8' makes integer from pointer without a cast

regards,
Grzesiek

#7 lore raw

PATCH v2 1/3 mpc52xx: Add SPI driver.

Dear Grzegorz Bernacki,

Quoted 8 lines · In message <[email protected]> you wrote:

Declaration of out8() is in common.h file:
void out8(unsigned int, unsigned char);
so I think that this cast is necessary.

Without it I get warning:
mpc52xx_spi.c:38: warning: passing argument 1 of 'out8' makes integer from pointer without a cast

This should make you think if out8() is the correct accessor macro to use on a PowerPC system.

Given the fact that U-Boot has not adapted ioread*() / iowrite*() yet, you should better use out_8() instead (see asm/io.h).

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"A dirty mind is a joy forever."                       - Randy Kunkee