mpc52xx: Add SPI driver.
PATCH 1/3 mpc52xx: Add SPI driver.
--- drivers/spi/Makefile | 1 + drivers/spi/mpc52xx_spi.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ include/mpc5xxx.h | 18 +++++++ 3 files changed, 127 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/mpc52xx_spi.c
drivers/spi/Makefile +1 -0
@@ -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 +108 -0
108 lines not on this page · raw message
include/mpc5xxx.h +18 -0
@@ -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
PATCH 2/3 digsy MTC: Add SPI support.
--- 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
@@ -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 */ + gpio->port_config |=0x20000000 ; + +/* GPT 6 Output Enable */ + gpt[6 ].emsr =0x00000034 ; +/* GPT 7 Output Enable */ + gpt[7 ].emsr =0x00000034 ; +#endif +return (0 ); }
include/configs/digsy_mtc.h +7 -0
@@ -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
PATCH 2/3 digsy MTC: Add SPI support.
Hi Grzegorz,
Quoted 24 lines
Signed-off-by Grzegorz Bernacki <[email protected]>--- 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 +4
-0@@ -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 ();
board/digsy_mtc/digsy_mtc.c int board_early_init_r(void) · line 217
Quoted 10 lines
board/digsy_mtc/digsy_mtc.c +9
-0#endif +#ifdef CONFIG_MPC52XX_SPI +/* SPI on Tmr2/3/4/5 pins */ + gpio->port_config |=0x20000000 ; + +/* GPT 6 Output Enable */ + gpt[6 ].emsr =0x00000034 ; +/* GPT 7 Output Enable */ + gpt[7 ].emsr =0x00000034 ; +#endif
You want to use accessor macros here.
Cheers
Detlev
Signature · 8 lines
The latest code looks a bit similar to the old [linux] big-reader-locks hack (which got dropped for good many eons ago and with which i deny any involvement with, such as having authored it. [oh, did i say that out loud? crap.]), imple- mented cleanly and properly. -- Ingo Molnar <[email protected]> -- 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
PATCH 3/3 digsy MTC: Add 'mtc' command.
In reply to Grzegorz BernackiNew command allows to:
o check FW version
o set LED status
o set digital output status
o get digital input status
--- board/digsy_mtc/Makefile | 2 +- board/digsy_mtc/cmd_mtc.c | 287 +++++++++++++++++++++++++++++++++++++++++++++ board/digsy_mtc/cmd_mtc.h | 60 ++++++++++ 3 files changed, 348 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
@@ -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 +287 -0
287 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
Signature · 1 line
1.6.0.6
PATCH 3/3 digsy MTC: Add 'mtc' command.
Hi Grzegorz,
Quoted 14 lines
New command allows to:
o check FW version
o set LED status
o set digital output status
o get digital input statusSigned-off-by Grzegorz Bernacki <[email protected]>--- board/digsy_mtc/Makefile | 2 +- board/digsy_mtc/cmd_mtc.c | 287 +++++++++++++++++++++++++++++++++++++++++++++ board/digsy_mtc/cmd_mtc.h | 60 ++++++++++ 3 files changed, 348 insertions(+), 1 deletions(-) create mode 100644 board/digsy_mtc/cmd_mtc.c create mode 100644 board/digsy_mtc/cmd_mtc.h
[...]
Quoted 18 lines
board/digsy_mtc/cmd_mtc.c new file +18
-0+int cmd_mtc (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) +{ +int err =0 ; + +if (argc >1 ) { +if (strncmp (argv[1 ],"led" ,3 ) ==0 ) + err =subcmd_led (cmdtp, flag, argc, argv); +else if (strncmp (argv[1 ],"key" ,3 ) ==0 ) + err =subcmd_key (cmdtp, flag, argc, argv); +else if (strncmp (argv[1 ],"version" ,7 ) ==0 ) + err =subcmd_version (cmdtp, flag, argc, argv); +else if (strncmp (argv[1 ],"appreg" ,6 ) ==0 ) + err =subcmd_appreg (cmdtp, flag, argc, argv); +else if (strncmp (argv[1 ],"digin" ,5 ) ==0 ) + err =subcmd_digin (cmdtp, flag, argc, argv); +else if (strncmp (argv[1 ],"digout" ,6 ) ==0 ) + err =subcmd_digout (cmdtp, flag, argc, argv); +else {
board/digsy_mtc/cmd_mtc.c line 274
Quoted 10 lines
board/digsy_mtc/cmd_mtc.c new file +10
-0+printf ("Usage:\n%s\n" , cmdtp->help); + err =1 ; + } + }else { +printf ("Usage:\n%s\n" , cmdtp->help); + err =1 ; + } + +return err; +}
Please use your own cmd_tblt_t to implement sub-commands re-using existing infrastructure. Check board/inka4x0/inkadiag.c for an example.
Cheers
Detlev
Signature · 7 lines
X-Windows has to be the most expensive way ever of popping up an Emacs
window.
-- The UNIX Haters Handbook
--
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.dePATCH 1/3 mpc52xx: Add SPI driver.
In reply to Grzegorz BernackiHi Grzegorz,
Quoted 53 lines
Signed-off-by Grzegorz Bernacki <[email protected]>--- drivers/spi/Makefile | 1 + drivers/spi/mpc52xx_spi.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ include/mpc5xxx.h | 18 +++++++ 3 files changed, 127 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/mpc52xx_spi.cdrivers/spi/Makefile +1
-0@@ -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.odrivers/spi/mpc52xx_spi.c new file +27
-0@@ -0,0 +1,108 @@ +/* +* (C) Copyright 2009 +* Frank Bodammer <[email protected]> +* (C) Copyright 2009 Semihalf, Grzegorz Bernacki +* +* See file CREDITS for list of people who contributed to this +* project. +* +* 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>
drivers/spi/mpc52xx_spi.c line 37
Quoted 10 lines
drivers/spi/mpc52xx_spi.c new file +10
-0+#include <mpc5xxx.h> + +void spi_init (void ) +{ +struct mpc5xxx_spi *spi = (struct mpc5xxx_spi *)MPC5XXX_SPI ; +/* +* Its important to use the correct order when initializing the +* registers +*/ + spi->ddr =0x0F ;/* set all SPI pins as output */
Here and below you want to use accessor macros - please check the whole patch.
Cheers
Detlev
Signature · 8 lines
The latest code looks a bit similar to the old [linux] big-reader-locks hack (which got dropped for good many eons ago and with which i deny any involvement with, such as having authored it. [oh, did i say that out loud? crap.]), imple- mented cleanly and properly. -- Ingo Molnar <[email protected]> -- 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