* [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver.
@ 2009-06-09 12:14 Grzegorz Bernacki
2009-06-09 12:14 ` [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support Grzegorz Bernacki
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Grzegorz Bernacki @ 2009-06-09 12:14 UTC (permalink / raw)
To: u-boot
Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com>
---
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
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 1350f3e..1272c17 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -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
diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
new file mode 100644
index 0000000..a5483af
--- /dev/null
+++ b/drivers/spi/mpc52xx_spi.c
@@ -0,0 +1,109 @@
+/*
+ * (C) Copyright 2009
+ * Frank Bodammer <frank.bodammer@gcd-solutions.de>
+ * (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 <asm/io.h>
+#include <malloc.h>
+#include <spi.h>
+#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
+ */
+ 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 */
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+ unsigned int max_hz, unsigned int mode)
+{
+ struct spi_slave *slave;
+
+ slave = malloc(sizeof(struct spi_slave));
+ if (!slave)
+ return NULL;
+
+ slave->bus = bus;
+ slave->cs = cs;
+
+ return slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+ free(slave);
+}
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+ return 0;
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+ return;
+}
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
+ void *din, unsigned long flags)
+{
+ struct mpc5xxx_spi *spi = (struct mpc5xxx_spi *)MPC5XXX_SPI;
+ int i, iter = bitlen >> 3;
+ const uchar *txp = dout;
+ uchar *rxp = din;
+
+ debug("spi_xfer: slave %u:%u dout %08X din %08X bitlen %u\n",
+ slave->bus, slave->cs, *(uint *) dout, *(uint *) din, bitlen);
+
+ if (flags & SPI_XFER_BEGIN)
+ setbits_8(&spi->pdr, SPI_PDR_SS);
+
+ for (i = 0; i < iter; i++) {
+ udelay(1000);
+ debug("spi_xfer: sending %x\n", txp[i]);
+ out8((u32)&spi->dr, txp[i]);
+ while (!(in8((u32)&spi->sr) & SPI_SR_SPIF)) {
+ udelay(1000);
+ if (in8((u32)&spi->sr) & SPI_SR_WCOL) {
+ rxp[i] = in8((u32)&spi->dr);
+ puts("spi_xfer: write collision\n");
+ return -1;
+ }
+ }
+ rxp[i] = in8((u32)&spi->dr);
+ debug("spi_xfer: received %x\n", rxp[i]);
+ }
+ if (flags & SPI_XFER_END)
+ clrbits_8(&spi->pdr, SPI_PDR_SS);
+
+ return 0;
+}
diff --git a/include/mpc5xxx.h b/include/mpc5xxx.h
index 463d5ae..476d149 100644
--- a/include/mpc5xxx.h
+++ b/include/mpc5xxx.h
@@ -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
--
1.6.0.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support. 2009-06-09 12:14 [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Grzegorz Bernacki @ 2009-06-09 12:14 ` Grzegorz Bernacki 2009-06-10 11:39 ` Detlev Zundel 2009-06-09 12:14 ` [U-Boot] [PATCH v2 3/3] digsy MTC: Add 'mtc' command Grzegorz Bernacki 2009-06-10 11:33 ` [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Detlev Zundel 2 siblings, 1 reply; 8+ messages in thread From: Grzegorz Bernacki @ 2009-06-09 12:14 UTC (permalink / raw) To: u-boot Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com> --- v2: - use accessor macros board/digsy_mtc/digsy_mtc.c | 14 ++++++++++++++ include/configs/digsy_mtc.h | 7 +++++++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/board/digsy_mtc/digsy_mtc.c b/board/digsy_mtc/digsy_mtc.c index 83d5864..8e863bf 100644 --- a/board/digsy_mtc/digsy_mtc.c +++ b/board/digsy_mtc/digsy_mtc.c @@ -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); } diff --git a/include/configs/digsy_mtc.h b/include/configs/digsy_mtc.h index 66badd7..0cc2a8d 100644 --- a/include/configs/digsy_mtc.h +++ b/include/configs/digsy_mtc.h @@ -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 -- 1.6.0.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support. 2009-06-09 12:14 ` [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support Grzegorz Bernacki @ 2009-06-10 11:39 ` Detlev Zundel 2009-06-10 14:03 ` Grzegorz Bernacki 0 siblings, 1 reply; 8+ messages in thread From: Detlev Zundel @ 2009-06-10 11:39 UTC (permalink / raw) To: u-boot Hi Grzegorz, > Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com> > --- > v2: > - use accessor macros > > board/digsy_mtc/digsy_mtc.c | 14 ++++++++++++++ > include/configs/digsy_mtc.h | 7 +++++++ > 2 files changed, 21 insertions(+), 0 deletions(-) [...] > +#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 -- 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: dzu@denx.de ^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support. 2009-06-10 11:39 ` Detlev Zundel @ 2009-06-10 14:03 ` Grzegorz Bernacki 0 siblings, 0 replies; 8+ messages in thread From: Grzegorz Bernacki @ 2009-06-10 14:03 UTC (permalink / raw) To: u-boot > >> +#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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH v2 3/3] digsy MTC: Add 'mtc' command. 2009-06-09 12:14 [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Grzegorz Bernacki 2009-06-09 12:14 ` [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support Grzegorz Bernacki @ 2009-06-09 12:14 ` Grzegorz Bernacki 2009-06-10 11:33 ` [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Detlev Zundel 2 siblings, 0 replies; 8+ messages in thread From: Grzegorz Bernacki @ 2009-06-09 12:14 UTC (permalink / raw) To: u-boot New command allows to: o check FW version o set LED status o set digital output status o get digital input status Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com> --- 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 diff --git a/board/digsy_mtc/Makefile b/board/digsy_mtc/Makefile index 7d659e5..0bededc 100644 --- a/board/digsy_mtc/Makefile +++ b/board/digsy_mtc/Makefile @@ -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)) diff --git a/board/digsy_mtc/cmd_mtc.c b/board/digsy_mtc/cmd_mtc.c new file mode 100644 index 0000000..9e377cd --- /dev/null +++ b/board/digsy_mtc/cmd_mtc.c @@ -0,0 +1,350 @@ +/* + * (C) Copyright 2009 + * Werner Pfister <Pfister_Werner@intercontrol.de> + * + * (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 <command.h> +#include <mpc5xxx.h> +#include "spi.h" +#include "cmd_mtc.h" + +DECLARE_GLOBAL_DATA_PTR; + +static const char *led_names[] = { + "diag", + "can1", + "can2", + "can3", + "can4", + "usbpwr", + "usbbusy", + "user1", + "user2", + "" +}; + +static void mtc_calculate_checksum(tx_msp_cmd *packet) +{ + int i; + uchar *buff; + + buff = (uchar *) packet; + + for (i = 0; i < 6; i++) + packet->cks += buff[i]; +} + +static int do_mtc_led(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + tx_msp_cmd pcmd; + rx_msp_cmd prx; + int err = 0; + int i; + + if (argc < 2) { + cmd_usage(cmdtp); + return -1; + } + + memset(&pcmd, 0, sizeof(pcmd)); + memset(&prx, 0, sizeof(prx)); + + pcmd.cmd = CMD_SET_LED; + + pcmd.cmd_val0 = 0xff; + for (i = 0; strlen(led_names[i]) != 0; i++) { + if (strncmp(argv[1], led_names[i], strlen(led_names[i])) == 0) { + pcmd.cmd_val0 = i; + break; + } + } + + if (pcmd.cmd_val0 == 0xff) { + printf("Usage:\n%s\n", cmdtp->help); + return -1; + } + + if (argc >= 3) { + if (strncmp(argv[2], "red", 3) == 0) + pcmd.cmd_val1 = 1; + else if (strncmp(argv[2], "green", 5) == 0) + pcmd.cmd_val1 = 2; + else if (strncmp(argv[2], "orange", 6) == 0) + pcmd.cmd_val1 = 3; + else + pcmd.cmd_val1 = 0; + } + + if (argc >= 4) + pcmd.cmd_val2 = simple_strtol(argv[3], NULL, 10); + else + pcmd.cmd_val2 = 0; + + mtc_calculate_checksum(&pcmd); + err = spi_xfer(NULL, MTC_TRANSFER_SIZE, &pcmd, &prx, + SPI_XFER_BEGIN | SPI_XFER_END); + + return err; +} + +static int do_mtc_key(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + tx_msp_cmd pcmd; + rx_msp_cmd prx; + int err = 0; + + memset(&pcmd, 0, sizeof(pcmd)); + memset(&prx, 0, sizeof(prx)); + + pcmd.cmd = CMD_GET_VIM; + + mtc_calculate_checksum(&pcmd); + err = spi_xfer(NULL, MTC_TRANSFER_SIZE, &pcmd, &prx, + SPI_XFER_BEGIN | SPI_XFER_END); + + if (!err) { + /* function returns '0' if key is pressed */ + err = (prx.input & 0x80) ? 0 : 1; + } + + return err; +} + +static int do_mtc_digout(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + tx_msp_cmd pcmd; + rx_msp_cmd prx; + int err = 0; + uchar channel_mask = 0; + + if (argc < 3) { + cmd_usage(cmdtp); + return -1; + } + + if (strncmp(argv[1], "on", 2) == 0) + channel_mask |= 1; + if (strncmp(argv[2], "on", 2) == 0) + channel_mask |= 2; + + memset(&pcmd, 0, sizeof(pcmd)); + memset(&prx, 0, sizeof(prx)); + + pcmd.cmd = CMD_GET_VIM; + pcmd.user_out = channel_mask; + + mtc_calculate_checksum(&pcmd); + err = spi_xfer(NULL, MTC_TRANSFER_SIZE, &pcmd, &prx, + SPI_XFER_BEGIN | SPI_XFER_END); + + return err; +} + +static int do_mtc_digin(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + tx_msp_cmd pcmd; + rx_msp_cmd prx; + int err = 0; + uchar channel_num = 0; + + if (argc < 2) { + cmd_usage(cmdtp); + return -1; + } + + channel_num = simple_strtol(argv[1], NULL, 10); + if ((channel_num != 1) && (channel_num != 2)) { + printf("mtc digin: invalid parameter - must be '1' or '2'\n"); + return -1; + } + + memset(&pcmd, 0, sizeof(pcmd)); + memset(&prx, 0, sizeof(prx)); + + pcmd.cmd = CMD_GET_VIM; + + mtc_calculate_checksum(&pcmd); + err = spi_xfer(NULL, MTC_TRANSFER_SIZE, &pcmd, &prx, + SPI_XFER_BEGIN | SPI_XFER_END); + + if (!err) { + /* function returns '0' when digin is on */ + err = (prx.input & channel_num) ? 0 : 1; + } + + return err; +} + +static int do_mtc_appreg(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + tx_msp_cmd pcmd; + rx_msp_cmd prx; + int err; + char buf[5]; + + /* read appreg */ + memset(&pcmd, 0, sizeof(pcmd)); + memset(&prx, 0, sizeof(prx)); + + pcmd.cmd = CMD_WD_PARA; + pcmd.cmd_val0 = 5; /* max. Count */ + pcmd.cmd_val1 = 5; /* max. Time */ + pcmd.cmd_val2 = 0; /* =0 means read appreg */ + + mtc_calculate_checksum(&pcmd); + err = spi_xfer(NULL, MTC_TRANSFER_SIZE, &pcmd, &prx, + SPI_XFER_BEGIN | SPI_XFER_END); + if (!err) { + sprintf(buf, "%d", prx.ack2); + setenv("appreg", buf); + } + + return err; +} + +static int do_mtc_version(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + tx_msp_cmd pcmd; + rx_msp_cmd prx; + int err = 0; + + memset(&pcmd, 0, sizeof(pcmd)); + memset(&prx, 0, sizeof(prx)); + + pcmd.cmd = CMD_FW_VERSION; + + mtc_calculate_checksum(&pcmd); + err = spi_xfer(NULL, MTC_TRANSFER_SIZE, &pcmd, &prx, + SPI_XFER_BEGIN | SPI_XFER_END); + + if (!err) { + printf("FW V%d.%d.%d / HW %d\n", + prx.ack0, prx.ack1, prx.ack3, prx.ack2); + } + + return err; +} + +static int do_mtc_help(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); + +cmd_tbl_t cmd_mtc_sub[] = { + U_BOOT_CMD_MKENT(led, 3, 1, do_mtc_led, + "set state of leds", + "[ledname] [state] [blink]\n" + " - lednames: diag can1 can2 can3 can4 usbpwr usbbusy user1 user2\n" + " - state: off red green orange\n" + " - blink: blink interval in 100ms steps (1 - 10; 0 = static)\n"), + U_BOOT_CMD_MKENT(key, 0, 1, do_mtc_key, + "returns state of user key\n", ""), + U_BOOT_CMD_MKENT(version, 0, 1, do_mtc_version, + "returns firmware version of supervisor uC\n", ""), + U_BOOT_CMD_MKENT(appreg, 0, 1, do_mtc_appreg, + "reads appreg value and stores in environment variable 'appreg'\n", ""), + U_BOOT_CMD_MKENT(digin, 1, 1, do_mtc_digin, + "returns state of digital input", + "<channel_num> - get state of digital input (1 or 2)\n"), + U_BOOT_CMD_MKENT(digout, 2, 1, do_mtc_digout, + "sets digital outputs", + "<on|off> <on|off>- set state of digital output 1 and 2\n"), + U_BOOT_CMD_MKENT(help, 4, 1, do_mtc_help, "get help", + "[command] - get help for command\n"), +}; + +static int do_mtc_help(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + extern int _do_help(cmd_tbl_t *cmd_start, int cmd_items, + cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[]); +#ifdef CONFIG_SYS_LONGHELP + puts("mtc "); +#endif + return _do_help(&cmd_mtc_sub[0], + ARRAY_SIZE(cmd_mtc_sub), cmdtp, flag, argc, argv); +} + +/* Relocate the command table function pointers when running in RAM */ +int mtc_cmd_init_r(void) +{ + cmd_tbl_t *cmdtp; + + for (cmdtp = &cmd_mtc_sub[0]; cmdtp != + &cmd_mtc_sub[ARRAY_SIZE(cmd_mtc_sub)]; cmdtp++) { + ulong addr; + + addr = (ulong)(cmdtp->cmd) + gd->reloc_off; + cmdtp->cmd = + (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr; + + addr = (ulong)(cmdtp->name) + gd->reloc_off; + cmdtp->name = (char *)addr; + + if (cmdtp->usage) { + addr = (ulong)(cmdtp->usage) + gd->reloc_off; + cmdtp->usage = (char *)addr; + } +#ifdef CONFIG_SYS_LONGHELP + if (cmdtp->help) { + addr = (ulong)(cmdtp->help) + gd->reloc_off; + cmdtp->help = (char *)addr; + } +#endif + } + return 0; +} + +int cmd_mtc(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + cmd_tbl_t *c; + int err = 0; + + c = find_cmd_tbl(argv[1], &cmd_mtc_sub[0], ARRAY_SIZE(cmd_mtc_sub)); + if (c) { + argc--; + argv++; + return c->cmd(c, flag, argc, argv); + } else { + /* Unrecognized command */ + cmd_usage(cmdtp); + return 1; + } + + return err; +} + +U_BOOT_CMD(mtc, 5, 1, cmd_mtc, + "mtc - special commands for digsyMTC\n", + "[subcommand] [args...]\n" + "Subcommands list:\n" + "led [ledname] [state] [blink] - set state of leds\n" + " [ledname]: diag can1 can2 can3 can4 usbpwr usbbusy user1 user2\n" + " [state]: off red green orange\n" + " [blink]: blink interval in 100ms steps (1 - 10; 0 = static)\n" + "key - returns state of user key\n" + "version - returns firmware version of supervisor uC\n" + "appreg - reads appreg value and stores in environment variable" + " 'appreg'\n" + "digin [channel] - returns state of digital input (1 or 2)\n" + "digout <on|off> <on|off> - sets state of two digital outputs\n" + "help [subcommand] - get help for subcommand\n"); + diff --git a/board/digsy_mtc/cmd_mtc.h b/board/digsy_mtc/cmd_mtc.h new file mode 100644 index 0000000..db3aeed --- /dev/null +++ b/board/digsy_mtc/cmd_mtc.h @@ -0,0 +1,60 @@ +/* + * (C) Copyright 2009 + * Werner Pfister <Pfister_Werner@intercontrol.de> + * + * (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 + */ + +#ifndef CMD_MTC_H +#define CMD_MTC_H + +#define CMD_WD_PARA 0x02 +#define CMD_FW_VERSION 0x10 +#define CMD_GET_VIM 0x30 +#define CMD_SET_LED 0x40 + +typedef struct { + u8 cmd; + u8 sys_in; + u8 cmd_val0; + u8 cmd_val1; + u8 cmd_val2; + u8 user_out; + u8 cks; + u8 dummy1; + u8 dummy2; +} tx_msp_cmd; + +typedef struct { + u8 input; + u8 state; + u8 ack2; + u8 ack3; + u8 ack0; + u8 ack1; + u8 ack; + u8 dummy; + u8 cks; +} rx_msp_cmd; + +#define MTC_TRANSFER_SIZE (sizeof(tx_msp_cmd) * 8) + +#endif diff --git a/board/digsy_mtc/digsy_mtc.c b/board/digsy_mtc/digsy_mtc.c index 8e863bf..e3c0329 100644 --- a/board/digsy_mtc/digsy_mtc.c +++ b/board/digsy_mtc/digsy_mtc.c @@ -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; } -- 1.6.0.6 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver. 2009-06-09 12:14 [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Grzegorz Bernacki 2009-06-09 12:14 ` [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support Grzegorz Bernacki 2009-06-09 12:14 ` [U-Boot] [PATCH v2 3/3] digsy MTC: Add 'mtc' command Grzegorz Bernacki @ 2009-06-10 11:33 ` Detlev Zundel 2009-06-10 12:50 ` Grzegorz Bernacki 2 siblings, 1 reply; 8+ messages in thread From: Detlev Zundel @ 2009-06-10 11:33 UTC (permalink / raw) To: u-boot Hi Grzegorz, > Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com> > --- > v2: > - use accessor macros > [...] > + 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 -- 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver. 2009-06-10 11:33 ` [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Detlev Zundel @ 2009-06-10 12:50 ` Grzegorz Bernacki 2009-06-10 13:29 ` Wolfgang Denk 0 siblings, 1 reply; 8+ messages in thread From: Grzegorz Bernacki @ 2009-06-10 12:50 UTC (permalink / raw) To: u-boot Detlev Zundel wrote: >> + 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver. 2009-06-10 12:50 ` Grzegorz Bernacki @ 2009-06-10 13:29 ` Wolfgang Denk 0 siblings, 0 replies; 8+ messages in thread From: Wolfgang Denk @ 2009-06-10 13:29 UTC (permalink / raw) To: u-boot Dear Grzegorz Bernacki, In message <4A2FAC29.2000304@semihalf.com> 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 -- 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-06-10 14:03 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-06-09 12:14 [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Grzegorz Bernacki 2009-06-09 12:14 ` [U-Boot] [PATCH v2 2/3] digsy MTC: Add SPI support Grzegorz Bernacki 2009-06-10 11:39 ` Detlev Zundel 2009-06-10 14:03 ` Grzegorz Bernacki 2009-06-09 12:14 ` [U-Boot] [PATCH v2 3/3] digsy MTC: Add 'mtc' command Grzegorz Bernacki 2009-06-10 11:33 ` [U-Boot] [PATCH v2 1/3] mpc52xx: Add SPI driver Detlev Zundel 2009-06-10 12:50 ` Grzegorz Bernacki 2009-06-10 13:29 ` Wolfgang Denk
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox