
On 21:58 Thu 20 Nov , ap@denx.de wrote:
From: Andreas Pfefferle ap@denx.de
This patch adds diagnosis functions for the buzzer, UARTs and digital IOs on inka4x0 hardware. Signed-off-by: Andreas Pfefferle ap@denx.de
board/inka4x0/Makefile | 2 +- board/inka4x0/inkadiag.c | 515 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 516 insertions(+), 1 deletions(-) create mode 100644 board/inka4x0/inkadiag.c
why not make this diagnostic active via CONFIG_?
diff --git a/board/inka4x0/Makefile b/board/inka4x0/Makefile index 442e2d0..2264dae 100644 --- a/board/inka4x0/Makefile +++ b/board/inka4x0/Makefile @@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
LIB = $(obj)lib$(BOARD).a
-COBJS := $(BOARD).o +COBJS := $(BOARD).o inkadiag.o
SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(COBJS)) diff --git a/board/inka4x0/inkadiag.c b/board/inka4x0/inkadiag.c new file mode 100644 index 0000000..6194b58 --- /dev/null +++ b/board/inka4x0/inkadiag.c @@ -0,0 +1,515 @@ +/*
- (C) Copyright 2008
- Andreas Pfefferle, DENX Software Engineering, ap@denx.de.
- 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 <asm/io.h> +#include <common.h> +#include <config.h> +#include <mpc5xxx.h> +#include <pci.h>
+#include <command.h>
+#define TEST_NAME(test, name) static char test##_program_name[] = name +#define TEST_USAGE(test, usage) static char test##_program_usage[] = usage +#define TEST_FUNCTION(test) do_##test +#define PRINT_TEST_USAGE(test) do {\
- printf(test##_program_usage, test##_program_name);\
- return -1;\
+} while (0)
+#define GPIO_BASE (u_char *)0x30400000
^^ whitespace please remove
+#define DIGIN_TOUCHSCR_MASK 0x00003000 /* Inputs 12-13 */ +#define DIGIN_KEYB_MASK 0x00010000 /* Input 16 */
+#define DIGIN_DRAWER_SW1 0x00400000 /* Input 22 */ +#define DIGIN_DRAWER_SW2 0x00800000 /* Input 23 */
+#define DIGIO_LED0 0x00000001 /* Output 0 */ +#define DIGIO_LED1 0x00000002 /* Output 1 */ +#define DIGIO_LED2 0x00000004 /* Output 2 */ +#define DIGIO_LED3 0x00000008 /* Output 3 */ +#define DIGIO_LED4 0x00000010 /* Output 4 */ +#define DIGIO_LED5 0x00000020 /* Output 5 */
+#define DIGIO_DRAWER1 0x00000100 /* Output 8 */ +#define DIGIO_DRAWER2 0x00000200 /* Output 9 */
+static unsigned int inka_digin_get_input(void) +{
- return in_8(GPIO_BASE + 0) << 0 | in_8(GPIO_BASE + 1) << 8 |
in_8(GPIO_BASE + 2) << 16 | in_8(GPIO_BASE + 3) << 24;
+}
+#define LED_HIGH(NUM)\ +out_be32((unsigned *)MPC5XXX_GPT##NUM##_ENABLE,\
in_be32((unsigned *)MPC5XXX_GPT##NUM##_ENABLE) | 0x10)
why not inline?
+#define LED_LOW(NUM)\ +out_be32((unsigned *)MPC5XXX_GPT##NUM##_ENABLE,\
in_be32((unsigned *)MPC5XXX_GPT##NUM##_ENABLE) & ~0x10)
why not inline?
+#define CHECK_LED(NUM) do {\
- if (state & (1 << NUM)) {\
LED_HIGH(NUM);\
- } else {\
LED_LOW(NUM);\
- } \
+} while (0)
why not inline?
+static void inka_digio_set_output(unsigned int state, int which) +{
- if (which == 0) {
CHECK_LED(0);
CHECK_LED(1);
CHECK_LED(2);
CHECK_LED(3);
CHECK_LED(4);
CHECK_LED(5);
- } else {
struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
please add a blank line
if (which == 1) {
if (state & DIGIO_DRAWER1) {
gpio->simple_dvo &= ~0x1000;
udelay(1);
gpio->simple_dvo |= 0x1000;
} else {
gpio->simple_dvo |= 0x1000;
udelay(1);
gpio->simple_dvo &= ~0x1000;
}
}
if (which == 2) {
if (state & DIGIO_DRAWER2) {
gpio->simple_dvo &= ~0x2000;
udelay(1);
gpio->simple_dvo |= 0x2000;
} else {
gpio->simple_dvo |= 0x2000;
udelay(1);
gpio->simple_dvo &= ~0x2000;
}
}
- }
- udelay(1);
+}
+TEST_NAME(io, "inkadiag io"); +TEST_USAGE(io, "Usage: %s\n\
<which> # get which[drawer1|drawer2|other] input\n\
<which> <val> # set which[drawer1|drawer2|other] output to val\n\
+");
+static int io_helper(int argc, char *argv[]) +{
- unsigned int state = inka_digin_get_input();
please add a blank line
- if (strcmp(argv[1], "drawer1") == 0) {
printf("exit code: 0x%X\n",
(state & DIGIN_DRAWER_SW1) >> (ffs(DIGIN_DRAWER_SW1) - 1));
- } else if (strcmp(argv[1], "drawer2") == 0) {
printf("exit code: 0x%X\n",
(state & DIGIN_DRAWER_SW2) >> (ffs(DIGIN_DRAWER_SW2) - 1));
- } else if (strcmp(argv[1], "other") == 0) {
printf("exit code: 0x%X\n",
((state & DIGIN_KEYB_MASK) >> (ffs(DIGIN_KEYB_MASK) - 1))
| ((state & DIGIN_TOUCHSCR_MASK) >>
(ffs(DIGIN_TOUCHSCR_MASK) - 2)));
- } else {
printf("Invalid argument: %s\n", argv[1]);
return -1;
- }
- return 0;
+}
+static int TEST_FUNCTION(io) (cmd_tbl_t *cmdtp, int flag, int argc,
char *argv[]) {
- if ((argc < 2) || (argc > 3))
PRINT_TEST_USAGE(io);
- if (argc == 2)
return io_helper(argc, argv);
why not instead if (argc == 2) return io_helper(argc, argv); else PRINT_TEST_USAGE(io);
- unsigned int val = simple_strtol(argv[2], NULL, 16);
declaration must at the beginning of the function
- if (strcmp(argv[1], "drawer1") == 0) {
val <<= (ffs(DIGIO_DRAWER1) - 1);
inka_digio_set_output(val, 1);
- } else if (strcmp(argv[1], "drawer2") == 0) {
val <<= (ffs(DIGIO_DRAWER2) - 1);
inka_digio_set_output(val, 2);
- } else if (strcmp(argv[1], "other") == 0)
inka_digio_set_output(val, 0);
- else {
printf("Invalid argument: %s\n", argv[1]);
return -1;
- }
- return io_helper(argc, argv);
+}
+DECLARE_GLOBAL_DATA_PTR;
+static int ser_init(volatile struct mpc5xxx_psc *psc, int baudrate) +{
- unsigned long baseclk;
- int div;
- /* reset PSC */
- psc->command = PSC_SEL_MODE_REG_1;
- /* select clock sources */
- psc->psc_clock_select = 0;
- baseclk = (gd->ipb_clk + 16) / 32;
- /* switch to UART mode */
- psc->sicr = 0;
- /* configure parity, bit length and so on */
- psc->mode = PSC_MODE_8_BITS | PSC_MODE_PARNONE;
- psc->mode = PSC_MODE_ONE_STOP;
- /* set up UART divisor */
- div = (baseclk + (baudrate / 2)) / baudrate;
- psc->ctur = (div >> 8) & 0xff;
- psc->ctlr = div & 0xff;
- /* disable all interrupts */
- psc->psc_imr = 0;
- /* reset and enable Rx/Tx */
- psc->command = PSC_RST_RX;
- psc->command = PSC_RST_TX;
- psc->command = PSC_RX_ENABLE | PSC_TX_ENABLE;
- return 0;
+}
+static void ser_putc(volatile struct mpc5xxx_psc *psc, const char c) +{
- /* Wait for last character to go. */
- int i = 0;
please add a blank line
- while (!(psc->psc_status & PSC_SR_TXEMP) && (i++ < CONFIG_SYS_HZ))
udelay(10);
- psc->psc_buffer_8 = c;
+}
+static int ser_getc(volatile struct mpc5xxx_psc *psc) +{
- /* Wait for a character to arrive. */
- int i = 0;
please add a blank line
- while (!(psc->psc_status & PSC_SR_RXRDY) && (i++ < CONFIG_SYS_HZ))
udelay(10);
- return psc->psc_buffer_8;
+}
+#define SERIAL_PORT_BASE (u_char *)0x80000000
+#define UART_RX 0 /* In: Receive buffer (DLAB=0) */ +#define UART_TX 0 /* Out: Transmit buffer (DLAB=0) */ +#define UART_DLL 0 /* Out: Divisor Latch Low (DLAB=1) */
+#define UART_LCR 3 /* Out: Line Control Register */ +#define UART_MCR 4 /* Out: Modem Control Register */
+#define UART_LSR 5 /* In: Line Status Register */ +#define UART_MSR 6 /* In: Modem Status Register */
+#define UART_LCR_WLEN8 0x03 /* Wordlength: 8 bits */
^^ please use tab
+#define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
+#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */ +#define UART_LSR_DR 0x01 /* Receiver data ready */
+#define UART_MCR_LOOP 0x10 /* Enable loopback test mode */ +#define UART_MCR_RTS 0x02 /* RTS complement */ +#define UART_MCR_DTR 0x01 /* DTR complement */
+#define UART_MSR_DCD 0x80 /* Data Carrier Detect */ +#define UART_MSR_DSR 0x20 /* Data Set Ready */ +#define UART_MSR_CTS 0x10 /* Clear to Send */ +#define PSC_OP1_RTS 0x01 +#define PSC_OP0_RTS 0x01
+static unsigned char serial_in(unsigned char num, int offset) +{
- return in_8(SERIAL_PORT_BASE + (num << 3) + offset);
+}
+static void serial_out(unsigned char num, int offset, unsigned char value) +{
- out_8(SERIAL_PORT_BASE + (num << 3) + offset, value);
+}
+TEST_NAME(serial, "inkadiag serial"); +TEST_USAGE(serial, "Usage: %s\n\
<num> <mode> <baudrate> <msg> # test uart num [0..11] in mode\
- and baudrate with msg\n\
+");
+static int TEST_FUNCTION(serial) (cmd_tbl_t *cmdtp, int flag, int argc,
char *argv[]) {
- if (argc < 5)
PRINT_TEST_USAGE(serial);
- argc--;
- argv++;
- unsigned int num = simple_strtol(argv[0], NULL, 0);
declaration must at the beginning of the function
- if (num < 0 || num > 11) {
printf("invalid argument for num: %d\n", num);
return -1;
- }
- unsigned int mode = simple_strtol(argv[1], NULL, 0);
declaration must at the beginning of the function
- int combrd = 0;
declaration must at the beginning of the function
- if (strcmp(argv[2], "115200") == 0)
combrd = 1;
- else if (strcmp(argv[2], "57600") == 0)
combrd = 2;
- else if (strcmp(argv[2], "38400") == 0)
combrd = 3;
- else if (strcmp(argv[2], "19200") == 0)
combrd = 6;
- else if (strcmp(argv[2], "9600") == 0)
combrd = 12;
- else if (strcmp(argv[2], "2400") == 0)
combrd = 48;
- else if (strcmp(argv[2], "1200") == 0)
combrd = 96;
- else if (strcmp(argv[2], "300") == 0)
combrd = 384;
- else
printf("Invalid baudrate: %s", argv[2]);
- printf("Testing uart %d.\n\n", num);
- if ((num >= 0) && (num <= 7)) {
if (mode & 1)
please add {}
/* turn on 'loopback' mode */
serial_out(num, UART_MCR, UART_MCR_LOOP);
else {
/* establish the UART's operational parameters */
/* set DLAB=1 */
serial_out(num, UART_LCR, UART_LCR_DLAB);
/* set baudrate */
serial_out(num, UART_DLL, combrd);
/* set data-format: 8-N-1 */
serial_out(num, UART_LCR, UART_LCR_WLEN8);
}
if (mode & 2) {
/* set request to send */
serial_out(num, UART_MCR, UART_MCR_RTS);
udelay(10);
/* check clear to send */
if ((serial_in(num, UART_MSR) & UART_MSR_CTS) == 0x00)
return -1;
}
if (mode & 4) {
/* set data terminal ready */
serial_out(num, UART_MCR, UART_MCR_DTR);
udelay(10);
/* check data set ready and carrier detect */
if ((serial_in(num, UART_MSR) &
(UART_MSR_DSR | UART_MSR_DCD))
!= (UART_MSR_DSR | UART_MSR_DCD))
return -1;
}
/* write each message-character, read it back, and display it */
int i, len = strlen(argv[3]);
declaration must at the beginning of the function
for (i = 0; i < len; ++i) {
int j = 0;
please add a blank line
while ((serial_in(num, UART_LSR) & UART_LSR_THRE) ==
0x00) {
if (j++ > CONFIG_SYS_HZ)
break;
udelay(10);
}
serial_out(num, UART_TX, argv[3][i]);
j = 0;
while ((serial_in(num, UART_LSR) & UART_LSR_DR) ==
0x00) {
if (j++ > CONFIG_SYS_HZ)
break;
udelay(10);
}
unsigned char data = serial_in(num, UART_RX);
printf("%c", data);
}
printf("\n\n");
serial_out(num, UART_MCR, 0x00);
- } else {
int address, irq;
please add a blank line
switch (num) {
case 8:
address = MPC5XXX_PSC6;
irq = MPC5XXX_PSC6_IRQ;
break;
case 9:
address = MPC5XXX_PSC3;
irq = MPC5XXX_PSC3_IRQ;
break;
case 10:
address = MPC5XXX_PSC2;
irq = MPC5XXX_PSC2_IRQ;
break;
case 11:
address = MPC5XXX_PSC1;
irq = MPC5XXX_PSC1_IRQ;
break;
}
volatile struct mpc5xxx_psc *psc =
(struct mpc5xxx_psc *)address;
ser_init(psc, simple_strtol(argv[2], NULL, 0));
if (mode & 2) {
/* set request to send */
out_8(&psc->op0, PSC_OP0_RTS);
udelay(10);
/* check clear to send */
if ((in_8(&psc->ip) & PSC_IPCR_CTS) == 0)
return -1;
}
int i, len = strlen(argv[3]);
declaration must at the beginning of the function
for (i = 0; i < len; ++i) {
ser_putc(psc, argv[3][i]);
printf("%c", ser_getc(psc));
}
printf("\n\n");
- }
- return 0;
+}
+#define BUZZER_GPT (MPC5XXX_GPT + 0x60) /* GPT6 */ +static void buzzer_turn_on(unsigned int freq) +{
- struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)(BUZZER_GPT);
- const u32 prescale = gd->ipb_clk / freq / 128;
- const u32 count = 128;
- const u32 width = 64;
- gpt->cir = (prescale << 16) | count;
- gpt->pwmcr = width << 16;
- gpt->emsr = 3; /* Timer enabled for PWM */
+}
+static void buzzer_turn_off(void) +{
- struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)(BUZZER_GPT);
please add a blank line
- gpt->emsr = 0;
+}
+TEST_NAME(buzzer, "inkadiag buzzer"); +TEST_USAGE(buzzer, "Usage: %s\n\
<period> <freq> # turn buzzer on for period ms with freq hz\n\
+");
+static int TEST_FUNCTION(buzzer) (cmd_tbl_t *cmdtp, int flag, int argc,
char *argv[]) {
- if (argc != 3)
PRINT_TEST_USAGE(buzzer);
- argc--;
- argv++;
- unsigned int period = simple_strtol(argv[0], NULL, 0);
declaration must at the beginning of the function
- if (!period)
printf("Zero period is senseless\n");
- argc--;
- argv++;
- unsigned int freq = simple_strtol(argv[0], NULL, 0);
declaration must at the beginning of the function
- /* avoid zero prescale in buzzer_turn_on() */
- if (freq > gd->ipb_clk / 128)
printf("%dHz exceeds maximum (%dHz)\n", freq,
gd->ipb_clk / 128);
- else if (!freq)
printf("Zero frequency is senseless\n");
- else
buzzer_turn_on(freq);
- clear_ctrlc();
- int prev = disable_ctrlc(0);
declaration must at the beginning of the function
- printf("Buzzing for %d ms. Type ^C to abort!\n\n", period);
- int i = 0;
- while (!ctrlc() && (i++ < CONFIG_SYS_HZ))
udelay(period);
- clear_ctrlc();
- disable_ctrlc(prev);
- buzzer_turn_off();
- return 0;
+}
Best Regards, J.