Skip to contentSkip to conversation

Add support for a Freescale non-CPM SPI controller

PATCH New Ben Warren 3 participants 4 messages Jan 17, 2008 – Jan 18, 2008

Subsystems (2)
lore
Share & tools
lore

Ben Warren

author
#0 lore raw

PATCH v2 1/2 Add support for a Freescale non-CPM SPI controller

This patch adds support for the SPI controller found on Freescale PowerPC processors such as the MCP834x family. Additionally, a new config option, CONFIG_HARD_SPI, is added for general purpose SPI controller use.

---
 Makefile                      |    2 +
 README                        |    8 +++
 drivers/spi/Makefile          |   46 ++++++++++++++
 drivers/spi/mpc8xxx_spi.c     |  138 +++++++++++++++++++++++++++++++++++++++++
 include/asm-ppc/immap_83xx.h  |    9 ++-
 include/asm-ppc/mpc8xxx_spi.h |   49 +++++++++++++++
 lib_ppc/board.c               |   16 +++++
 7 files changed, 264 insertions(+), 4 deletions(-)
 create mode 100644 drivers/spi/Makefile
 create mode 100644 drivers/spi/mpc8xxx_spi.c
 create mode 100644 include/asm-ppc/mpc8xxx_spi.h
Makefile +2 -0
index 1b3d2e6..8eb2a59 100644
@@ -230,6 +230,7 @@ LIBS += drivers/net/libnet.a
 LIBS += drivers/net/sk98lin/libsk98lin.a
 LIBS += drivers/pci/libpci.a
 LIBS += drivers/pcmcia/libpcmcia.a
+LIBS += drivers/spi/libspi.a
 ifeq ($(CPU),mpc83xx)
 LIBS += drivers/qe/qe.a
 endif
@@ -377,6 +378,7 @@ TAG_SUBDIRS += drivers/pcmcia
 TAG_SUBDIRS += drivers/qe
 TAG_SUBDIRS += drivers/rtc
 TAG_SUBDIRS += drivers/serial
+TAG_SUBDIRS += drivers/spi
 TAG_SUBDIRS += drivers/usb
 TAG_SUBDIRS += drivers/video
 
README +8 -0
index f2a4914..9a9e4de 100644
@@ -1377,6 +1377,14 @@ The following options need to be configured:
 		SPI configuration items (port pins to use, etc). For
 		an example, see include/configs/sacsng.h.
 
+		CONFIG_HARD_SPI
+
+		Enables a hardware SPI driver for general-purpose reads
+		and writes.  As with CONFIG_SOFT_SPI, the board configuration 
+		must define a list of chip-select function pointers.
+		Currently supported on some MPC8xxx processors.  For an
+		example, see include/configs/mpc8349emds.h. 
+
 - FPGA Support: CONFIG_FPGA
 
 		Enables FPGA subsystem.
drivers/spi/Makefile new file +46 -0

46 lines not on this page · raw message

drivers/spi/mpc8xxx_spi.c new file +138 -0

138 lines not on this page · raw message

include/asm-ppc/immap_83xx.h +5 -4
index 34ea295..c16a098 100644
@@ -30,6 +30,7 @@
 
 #include <asm/types.h>
 #include <asm/fsl_i2c.h>
+#include <asm/mpc8xxx_spi.h>
 
 /*
  * Local Access Window
@@ -627,7 +628,7 @@ typedef struct immap {
 	u8			res3[0x900];
 	lbus83xx_t		lbus;		/* Local Bus Controller Registers */
 	u8			res4[0x1000];
-	spi83xx_t		spi;		/* Serial Peripheral Interface */
+	spi8xxx_t		spi;		/* Serial Peripheral Interface */
 	dma83xx_t		dma;		/* DMA */
 	pciconf83xx_t		pci_conf[2];	/* PCI Software Configuration Registers */
 	ios83xx_t		ios;		/* Sequencer */
@@ -661,7 +662,7 @@ typedef struct immap {
 	u8			res2[0x900];
 	lbus83xx_t		lbus;		/* Local Bus Controller Registers */
 	u8			res3[0x1000];
-	spi83xx_t		spi;		/* Serial Peripheral Interface */
+	spi8xxx_t		spi;		/* Serial Peripheral Interface */
 	dma83xx_t		dma;		/* DMA */
 	pciconf83xx_t		pci_conf[1];	/* PCI Software Configuration Registers */
 	u8			res4[0x80];
@@ -696,7 +697,7 @@ typedef struct immap {
 	u8			res2[0x900];
 	lbus83xx_t		lbus;		/* Local Bus Controller Registers */
 	u8			res3[0x1000];
-	spi83xx_t		spi;		/* Serial Peripheral Interface */
+	spi8xxx_t		spi;		/* Serial Peripheral Interface */
 	dma83xx_t		dma;		/* DMA */
 	pciconf83xx_t		pci_conf[1];	/* PCI Software Configuration Registers */
 	u8			res4[0x80];
@@ -741,7 +742,7 @@ typedef struct immap {
 	u8			res2[0x900];
 	lbus83xx_t		lbus;		/* Local Bus Controller Registers */
 	u8			res3[0x1000];
-	spi83xx_t		spi;		/* Serial Peripheral Interface */
+	spi8xxx_t		spi;		/* Serial Peripheral Interface */
 	dma83xx_t		dma;		/* DMA */
 	pciconf83xx_t		pci_conf[1];	/* PCI Software Configuration Registers */
 	u8			res4[0x80];
include/asm-ppc/mpc8xxx_spi.h new file +49 -0

49 lines not on this page · raw message

lib_ppc/board.c +16 -0
index 7b95246..8b4095c 100644
@@ -87,6 +87,9 @@ void doc_init (void);
     defined(CONFIG_SOFT_I2C)
 #include <i2c.h>
 #endif
+#if defined(CONFIG_HARD_SPI)
+#include <spi.h>
+#endif
 #if defined(CONFIG_CMD_NAND)
 void nand_init (void);
 #endif
@@ -247,6 +250,16 @@ static int init_func_i2c (void)
 }
 #endif
 
+#if defined(CONFIG_HARD_SPI) 
+static int init_func_spi (void)
+{
+	puts ("SPI:   ");
+	spi_init ();
+	puts ("ready\n");
+	return (0);
+}
+#endif
+
 /***********************************************************************/
 
 #if defined(CONFIG_WATCHDOG)
@@ -329,6 +342,9 @@ init_fnc_t *init_sequence[] = {
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 	init_func_i2c,
 #endif
+#if defined(CONFIG_HARD_SPI)
+	init_func_spi,
+#endif
 #if defined(CONFIG_DTT)		/* Digital Thermometers and Thermostats */
 	dtt_init,
 #endif
Signature · 1 line
1.5.2.5
#1 lore raw

PATCH v2 1/2 Add support for a Freescale non-CPM SPI controller

Quoted 10 lines · On Wed, 16 Jan 2008 22:37:35 -0500 Ben Warren <[email protected]> wrote:

This patch adds support for the SPI controller found on Freescale PowerPC processors such as the MCP834x family. Additionally, a new config option, CONFIG_HARD_SPI, is added for general purpose SPI controller use.

---
 Makefile                      |    2 +
 README                        |    8 +++
 drivers/spi/Makefile          |   46 ++++++++++++++
 drivers/spi/mpc8xxx_spi.c     |  138 +++++++++++++++++++++++++++++++++++++++++

so, I just caught up on this spi stuff, turns out the mpc8610 has SPI, too, so mpc8xxx nomenclature seems ok (at least for now).

Only issues I noticed were CodingStyle related, so here are my comments, conveniently supplied in diff form :) :

drivers/spi/Makefile +3 -3
index 6b3898b..0b7a2df 100644
@@ -23,13 +23,13 @@
 
 include $(TOPDIR)/config.mk
 
-LIB 	:= $(obj)libspi.a
+LIB	:= $(obj)libspi.a
 
 COBJS-y += mpc8xxx_spi.o
 
 COBJS	:= $(COBJS-y)
-SRCS 	:= $(COBJS:.o=.c)
-OBJS 	:= $(addprefix $(obj),$(COBJS))
+SRCS	:= $(COBJS:.o=.c)
+OBJS	:= $(addprefix $(obj),$(COBJS))
 
 all:	$(LIB)
 
drivers/spi/mpc8xxx_spi.c +31 -26

109 lines not on this page · raw message

include/asm-ppc/mpc8xxx_spi.h +1 -2
index 38f12b9..053d11e 100644
@@ -32,8 +32,7 @@
 	defined(CONFIG_MPC8315) || \
 	defined(CONFIG_MPC837X)
 
-typedef struct spi8xxx
-{
+typedef struct spi8xxx {
 	u8 res0[0x20];	/* 0x0-0x01f reserved */
 	u32 mode;	/* mode register  */
 	u32 event;	/* event register */

Kim

#2 lore raw

PATCH v2 1/2 Add support for a Freescale non-CPMSPI controller

In reply to Ben Warren
Quoted 7 lines
include/asm-ppc/mpc8xxx_spi.h new file +6 -0
+#if defined(CONFIG_MPC834X) || \
+	defined(CONFIG_MPC8313) || \
+	defined(CONFIG_MPC8315) || \
+	defined(CONFIG_MPC837X)
+
+typedef struct spi8xxx

include/asm-ppc/mpc8xxx_spi.h line 45

Quoted 10 lines
include/asm-ppc/mpc8xxx_spi.h new file +10 -0
+{
+	u8 res0[0x20];	/* 0x0-0x01f reserved */
+	u32 mode;	/* mode register  */
+	u32 event;	/* event register */
+	u32 mask;	/* mask register  */
+	u32 com;	/* command register */
+	u32 tx;		/* transmit register */
+	u32 rx;		/* receive register */
+	u8 res1[0xC8];	/* fill up to 0x100 */
+} spi8xxx_t;

Ben, the sizeof(struct spi8xxx_t) should be 0x1000, So, This will break 83xx immap, the DMA and PCI will be failed. I will send one patch to fix it.

Thanks,
Dave

author
#3 lore raw

PATCH v2 1/2 Add support for a Freescale non-CPMSPI controller

Quoted 13 lines · Liu Dave
Quoted 13 lines
include/asm-ppc/mpc8xxx_spi.h new file +13 -0
+#if defined(CONFIG_MPC834X) || \
+	defined(CONFIG_MPC8313) || \
+	defined(CONFIG_MPC8315) || \
+	defined(CONFIG_MPC837X)
+
+typedef struct spi8xxx
+{
+	u8 res0[0x20];	/* 0x0-0x01f reserved */
+	u32 mode;	/* mode register  */
+	u32 event;	/* event register */
+	u32 mask;	/* mask register  */
+	u32 com;	/* command register */
+	u32 tx;		/* transmit register */
Quoted 10 lines

include/asm-ppc/mpc8xxx_spi.h line 45

Quoted 4 lines
include/asm-ppc/mpc8xxx_spi.h new file +3 -0
+	u32 rx;		/* receive register */
+	u8 res1[0xC8];	/* fill up to 0x100 */
+} spi8xxx_t;

Ben, the sizeof(struct spi8xxx_t) should be 0x1000, So, This will break 83xx immap, the DMA and PCI will be failed. I will send one patch to fix it.

Oh jeez. Sorry. I guess it should be res1[0xfc8]. Thanks for taking care of this Dave.

regards,
Ben