Skip to contentSkip to conversation

arm: add uart dcc support

PATCH New Jean-Christophe PLAGNIOL-VILLARD 3 participants 4 messages Feb 7, 2009 – Feb 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: add uart dcc support

---
 common/devices.c         |    3 +
 drivers/serial/Makefile  |    1 +
 drivers/serial/arm_dcc.c |  270 ++++++++++++++++++++++++++++++++++++++++++++++
 include/devices.h        |    3 +
 lib_arm/board.c          |    3 +
 5 files changed, 280 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/arm_dcc.c
common/devices.c +3 -0
index 38f1bbc..ba53c9b 100644
@@ -215,6 +215,9 @@ int devices_init (void)
 	/* Initialize the list */
 	INIT_LIST_HEAD(&(devs.list));
 
+#ifdef CONFIG_ARM_DCC_MULTI
+	drv_arm_dcc_init ();
+#endif
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
 #endif
drivers/serial/Makefile +1 -0
index b6fd0d7..af121a2 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libserial.a
 
+COBJS-$(CONFIG_ARM_DCC) += arm_dcc.o
 COBJS-$(CONFIG_ATMEL_USART) += atmel_usart.o
 COBJS-$(CONFIG_MCFUART) += mcfuart.o
 COBJS-$(CONFIG_NS9750_UART) += ns9750_serial.o
drivers/serial/arm_dcc.c new file +270 -0

270 lines not on this page · raw message

include/devices.h +3 -0
index 84c4514..3a9881b 100644
@@ -98,6 +98,9 @@ struct list_head* device_get_list(void);
 device_t* device_get_by_name(char* name);
 device_t* device_clone(device_t *dev);
 
+#ifdef CONFIG_ARM_DCC_MULTI
+int drv_arm_dcc_init(void);
+#endif
 #ifdef CONFIG_LCD
 int	drv_lcd_init (void);
 #endif
lib_arm/board.c +3 -0
index 41f7603..0b79fe1 100644
@@ -145,6 +145,9 @@ void inline yellow_LED_off(void)__attribute__((weak, alias("__yellow_LED_off")))
  * but let's get it working (again) first...
  */
 
+#if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
+#define CONFIG_BAUDRATE 115200
+#endif
 static int init_baudrate (void)
 {
 	char tmp[64];	/* long enough for environment variables */
Signature · 1 line
1.5.6.5
#1 lore raw

PATCH 1/1 arm: add uart dcc support

Dear Jean-Christophe,

Jean-Christophe PLAGNIOL-VILLARD wrote:

Do you like to add some words going to git describing this patch here? E.g. what DCC is and what it might be used for?

Quoted 29 lines
---
 common/devices.c         |    3 +
 drivers/serial/Makefile  |    1 +
 drivers/serial/arm_dcc.c |  270 ++++++++++++++++++++++++++++++++++++++++++++++
 include/devices.h        |    3 +
 lib_arm/board.c          |    3 +
 5 files changed, 280 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/arm_dcc.c
common/devices.c +3 -0
index 38f1bbc..ba53c9b 100644
@@ -215,6 +215,9 @@ int devices_init (void)
 	/* Initialize the list */
 	INIT_LIST_HEAD(&(devs.list));
 
+#ifdef CONFIG_ARM_DCC_MULTI
+	drv_arm_dcc_init ();
+#endif
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
 #endif
drivers/serial/Makefile +0 -0
index b6fd0d7..af121a2 100644

drivers/serial/Makefile include $(TOPDIR)/config.mk · line 28

Quoted 4 lines
drivers/serial/Makefile +1 -0
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libserial.a
 
+COBJS-$(CONFIG_ARM_DCC) += arm_dcc.o

Above you use CONFIG_ARM_DCC_MULTI, here you use CONFIG_ARM_DCC.

Why do you introduce two (new?) macros? Wouldn't one be sufficient?

For which board do want to enable this? There is no enable of these two macros in this patch?

And you will know better than I, but do new basic config options like these need some documentation somewhere?

drivers/serial/arm_dcc.c line 3

Quoted 12 lines
drivers/serial/Makefile +0 -0
 COBJS-$(CONFIG_ATMEL_USART) += atmel_usart.o
 COBJS-$(CONFIG_MCFUART) += mcfuart.o
 COBJS-$(CONFIG_NS9750_UART) += ns9750_serial.o
drivers/serial/arm_dcc.c new file +3 -0
new file mode 100644
index 0000000..8be4d4c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2004-2007 ARM Limited.
+ * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>

2009?

Quoted 24 lines
drivers/serial/arm_dcc.c new file +24 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ *
+ * As a special exception, if other files instantiate templates or use macros
+ * or inline functions from this file, or you compile this file and link it
+ * with other works to produce a work based on this file, this file does not
+ * by itself cause the resulting work to be covered by the GNU General Public
+ * License. However the source code for this file must still be made available
+ * in accordance with section (3) of the GNU General Public License.
+
+ * This exception does not invalidate any other reasons why a work based on
+ * this file might be covered by the GNU General Public License.
+ */

drivers/serial/arm_dcc.c line 37

Quoted 10 lines
drivers/serial/arm_dcc.c new file +10 -0
+
+#include <common.h>
+#include <devices.h>
+
+#define DCC_ARM9_RBIT	(1 << 0)
+#define DCC_ARM9_WBIT	(1 << 1)
+#define DCC_ARM10_RBIT	(1 << 7)
+#define DCC_ARM10_WBIT	(1 << 6)
+#define DCC_ARM11_RBIT	(1 << 30)
+#define DCC_ARM11_WBIT	(1 << 29)

Should something like this go to a header file?

drivers/serial/arm_dcc.c line 41

Quoted 3 lines
drivers/serial/arm_dcc.c new file +3 -0
+#define read_core_id(x)	do {						\
+		__asm__ ("mrc p15, 0, %0, c0, c0, 0\n" : "=r" (x));	\
+		x = (x >> 4) & 0xFFF;					\

What's about macros instead of hard coded values?

Quoted 73 lines
drivers/serial/arm_dcc.c new file +73 -0
+		} while (0);
+
+/*
+ * ARM9
+ */
+#define write_arm9_dcc(x)	\
+		__asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
+
+#define read_arm9_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
+
+#define status_arm9_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
+
+#define can_read_arm9_dcc(x)	do {	\
+		status_arm9_dcc(x);	\
+		x &= DCC_ARM9_RBIT;	\
+		} while (0);
+
+#define can_write_arm9_dcc(x)	do {	\
+		status_arm9_dcc(x);	\
+		x &= DCC_ARM9_WBIT;	\
+		x = (x == 0);		\
+		} while (0);
+
+/*
+ * ARM10
+ */
+#define write_arm10_dcc(x)	\
+		__asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
+
+#define read_arm10_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
+
+#define status_arm10_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
+
+#define can_read_arm10_dcc(x)	do {	\
+		status_arm10_dcc(x);	\
+		x &= DCC_ARM10_RBIT;	\
+		} while (0);
+
+#define can_write_arm10_dcc(x)	do {	\
+		status_arm10_dcc(x);	\
+		x &= DCC_ARM10_WBIT;	\
+		x = (x == 0);		\
+		} while (0);
+
+/*
+ * ARM11
+ */
+#define write_arm11_dcc(x)	\
+		__asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
+
+#define read_arm11_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
+
+#define status_arm11_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
+
+#define can_read_arm11_dcc(x)	do {	\
+		status_arm11_dcc(x);	\
+		x &= DCC_ARM11_RBIT;	\
+		} while (0);
+
+#define can_write_arm11_dcc(x)	do {	\
+		status_arm11_dcc(x);	\
+		x &= DCC_ARM11_WBIT;	\
+		x = (x == 0);		\
+		} while (0);
+
+#define TIMEOUT_COUNT 0x4000000
+

drivers/serial/arm_dcc.c line 124

Quoted 10 lines
drivers/serial/arm_dcc.c new file +10 -0
+static enum {arm9_and_earlier, arm10, arm11_and_later} arm_type = arm9_and_earlier;
+
+#ifndef CONFIG_ARM_DCC_MULTI
+#define arm_dcc_init serial_init
+void serial_setbrg(void) {}
+#define arm_dcc_getc serial_getc
+#define arm_dcc_putc serial_putc
+#define arm_dcc_puts serial_puts
+#define arm_dcc_tstc serial_tstc
+#endif

Why are all these #defines above in a .c file and not in a header file?

drivers/serial/arm_dcc.c line 132

Quoted 7 lines
drivers/serial/arm_dcc.c new file +7 -0
+int arm_dcc_init(void)
+{
+	register unsigned int id;
+
+	read_core_id(id);
+
+	if ((id & 0xF00) == 0xA00)

What's about macros instead of hard coded values?

drivers/serial/arm_dcc.c line 134

Quoted 2 lines
drivers/serial/arm_dcc.c new file +2 -0
+		arm_type = arm10;
+	else if (id >= 0xb00)

ditto

drivers/serial/arm_dcc.c line 139

Quoted 5 lines
drivers/serial/arm_dcc.c new file +5 -0
+		arm_type = arm11_and_later;
+	else
+		arm_type = arm9_and_earlier;
+
+	return 0;

Can this function return something else than 0 ? If not, why then have a return value?

drivers/serial/arm_dcc.c line 264

Quoted 2 lines
drivers/serial/arm_dcc.c new file +2 -0
+	if (rc == 0) {
+		arm_dcc_init();

Here you don't check the return value of arm_dcc_init(), so it makes no sense to have arm_dcc_init() returning anything?

drivers/serial/arm_dcc.c line 141

Quoted 2 lines
drivers/serial/arm_dcc.c new file +2 -0
+		return 1;
+	}

...

I'm not sure if this does matter, and if I have a recent version of Linux checkpatch script, but my version of checkpatch reports for this patch:

-- cut --
WARNING: space prohibited between function name and open parenthesis '(' #29: FILE: common/devices.c:219:
+ drv_arm_dcc_init ();

WARNING: line over 80 characters
#165: FILE: drivers/serial/arm_dcc.c:115:
+static enum {arm9_and_earlier, arm10, arm11_and_later} arm_type = arm9_and_earlier;

WARNING: space prohibited between function name and open parenthesis '(' #301: FILE: drivers/serial/arm_dcc.c:251:
+ memset (&arm_dcc_dev, 0, sizeof (arm_dcc_dev));

WARNING: space prohibited between function name and open parenthesis '(' #301: FILE: drivers/serial/arm_dcc.c:251:
+ memset (&arm_dcc_dev, 0, sizeof (arm_dcc_dev));

WARNING: space prohibited between function name and open parenthesis '(' #303: FILE: drivers/serial/arm_dcc.c:253:
+ strcpy (arm_dcc_dev.name, "dcc");

WARNING: space prohibited between function name and open parenthesis '(' #311: FILE: drivers/serial/arm_dcc.c:261:
+ rc = device_register (&arm_dcc_dev);
-- cut --

Best regards

Dirk

#2 lore raw

PATCH 1/1 arm: add uart dcc support

Quoted 6 lines · Dirk Behme

Dear Jean-Christophe,

Jean-Christophe PLAGNIOL-VILLARD wrote:

Do you like to add some words going to git describing this patch here? E.g. what DCC is and what it might be used for?

You maybe need to read arm documentation

Quoted 25 lines
Quoted 25 lines
---
 common/devices.c         |    3 +
 drivers/serial/Makefile  |    1 +
 drivers/serial/arm_dcc.c |  270 ++++++++++++++++++++++++++++++++++++++++++++++
 include/devices.h        |    3 +
 lib_arm/board.c          |    3 +
 5 files changed, 280 insertions(+), 0 deletions(-)
 create mode 100644 drivers/serial/arm_dcc.c
common/devices.c +2 -0
index 38f1bbc..ba53c9b 100644
@@ -215,6 +215,9 @@ int devices_init (void)
 	/* Initialize the list */
 	INIT_LIST_HEAD(&(devs.list));
 +#ifdef CONFIG_ARM_DCC_MULTI
+	drv_arm_dcc_init ();
+#endif
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
 #endif
drivers/serial/Makefile +0 -0
Quoted 8 lines

drivers/serial/Makefile include $(TOPDIR)/config.mk · line 26

Quoted 6 lines

index b6fd0d7..af121a2 100644

drivers/serial/Makefile +0 -0
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
  LIB	:= $(obj)libserial.a
 +COBJS-$(CONFIG_ARM_DCC) += arm_dcc.o

Above you use CONFIG_ARM_DCC_MULTI, here you use CONFIG_ARM_DCC.

maybe you need to re-read the code
it's an option of the driver

Quoted 2 lines

Why do you introduce two (new?) macros? Wouldn't one be sufficient?

no you may also need to read u-boot implementation about multiple serial and std serial

which both are implemented here

Quoted 3 lines

For which board do want to enable this? There is no enable of these two macros in this patch?

at91 which will come after or nearly any arm cpu

Quoted 8 lines

--- /dev/null

drivers/serial/Makefile line 3

Quoted 5 lines
drivers/serial/Makefile +4 -0
+++ b/drivers/serial/arm_dcc.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2004-2007 ARM Limited.
+ * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>

2009?

no I've wrote it in 2008

Quoted 38 lines
Quoted 25 lines
drivers/serial/Makefile +24 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ *
+ * As a special exception, if other files instantiate templates or use macros
+ * or inline functions from this file, or you compile this file and link it
+ * with other works to produce a work based on this file, this file does not
+ * by itself cause the resulting work to be covered by the GNU General Public
+ * License. However the source code for this file must still be made available
+ * in accordance with section (3) of the GNU General Public License.
+
+ * This exception does not invalidate any other reasons why a work based on
+ * this file might be covered by the GNU General Public License.
+ */

drivers/serial/Makefile line 37

Quoted 10 lines
drivers/serial/Makefile +10 -0
+
+#include <common.h>
+#include <devices.h>
+
+#define DCC_ARM9_RBIT	(1 << 0)
+#define DCC_ARM9_WBIT	(1 << 1)
+#define DCC_ARM10_RBIT	(1 << 7)
+#define DCC_ARM10_WBIT	(1 << 6)
+#define DCC_ARM11_RBIT	(1 << 30)
+#define DCC_ARM11_WBIT	(1 << 29)

Should something like this go to a header file?

Quoted 5 lines

drivers/serial/Makefile line 40

Quoted 3 lines
drivers/serial/Makefile +3 -0
+#define read_core_id(x)	do {						\
+		__asm__ ("mrc p15, 0, %0, c0, c0, 0\n" : "=r" (x));	\
+		x = (x >> 4) & 0xFFF;					\

What's about macros instead of hard coded values?

no way it's a mask

Quoted 78 lines
Quoted 78 lines
drivers/serial/Makefile +77 -0
+		} while (0);
+
+/*
+ * ARM9
+ */
+#define write_arm9_dcc(x)	\
+		__asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
+
+#define read_arm9_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
+
+#define status_arm9_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
+
+#define can_read_arm9_dcc(x)	do {	\
+		status_arm9_dcc(x);	\
+		x &= DCC_ARM9_RBIT;	\
+		} while (0);
+
+#define can_write_arm9_dcc(x)	do {	\
+		status_arm9_dcc(x);	\
+		x &= DCC_ARM9_WBIT;	\
+		x = (x == 0);		\
+		} while (0);
+
+/*
+ * ARM10
+ */
+#define write_arm10_dcc(x)	\
+		__asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
+
+#define read_arm10_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
+
+#define status_arm10_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
+
+#define can_read_arm10_dcc(x)	do {	\
+		status_arm10_dcc(x);	\
+		x &= DCC_ARM10_RBIT;	\
+		} while (0);
+
+#define can_write_arm10_dcc(x)	do {	\
+		status_arm10_dcc(x);	\
+		x &= DCC_ARM10_WBIT;	\
+		x = (x == 0);		\
+		} while (0);
+
+/*
+ * ARM11
+ */
+#define write_arm11_dcc(x)	\
+		__asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
+
+#define read_arm11_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
+
+#define status_arm11_dcc(x)	\
+		__asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
+
+#define can_read_arm11_dcc(x)	do {	\
+		status_arm11_dcc(x);	\
+		x &= DCC_ARM11_RBIT;	\
+		} while (0);
+
+#define can_write_arm11_dcc(x)	do {	\
+		status_arm11_dcc(x);	\
+		x &= DCC_ARM11_WBIT;	\
+		x = (x == 0);		\
+		} while (0);
+
+#define TIMEOUT_COUNT 0x4000000
+
+static enum {arm9_and_earlier, arm10, arm11_and_later} arm_type = arm9_and_earlier;
+
+#ifndef CONFIG_ARM_DCC_MULTI
+#define arm_dcc_init serial_init
Quoted 8 lines

drivers/serial/Makefile line 123

Quoted 6 lines
drivers/serial/Makefile +6 -0
+void serial_setbrg(void) {}
+#define arm_dcc_getc serial_getc
+#define arm_dcc_putc serial_putc
+#define arm_dcc_puts serial_puts
+#define arm_dcc_tstc serial_tstc
+#endif

Why are all these #defines above in a .c file and not in a header file?

maybe because it's dual api

Quoted 16 lines

drivers/serial/Makefile line 130

Quoted 8 lines
drivers/serial/Makefile +7 -0
+int arm_dcc_init(void)
+{
+	register unsigned int id;
+
+	read_core_id(id);
+
+	if ((id & 0xF00) == 0xA00)

What's about macros instead of hard coded values?

drivers/serial/Makefile line 132

Quoted 2 lines
drivers/serial/Makefile +2 -0
+		arm_type = arm10;
+	else if (id >= 0xb00)

ditto

Quoted 8 lines

drivers/serial/Makefile line 137

Quoted 5 lines
drivers/serial/Makefile +5 -0
+		arm_type = arm11_and_later;
+	else
+		arm_type = arm9_and_earlier;
+
+	return 0;

Can this function return something else than 0 ? If not, why then have a return value?

why? it will not fail

Quoted 6 lines

drivers/serial/Makefile line 139

Quoted 3 lines
drivers/serial/Makefile +2 -0
+	if (rc == 0) {
+		arm_dcc_init();

Here you don't check the return value of arm_dcc_init(), so it makes no sense to have arm_dcc_init() returning anything?

no it will never fail

Quoted 3 lines

drivers/serial/Makefile line 141

Quoted 3 lines
drivers/serial/Makefile +2 -0
+		return 1;
+	}

Best Regards,
J.

#3 lore raw

PATCH 1/1 arm: add uart dcc support

Dear Jean-Christophe PLAGNIOL-VILLARD,

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

Dear Jean-Christophe,

Jean-Christophe PLAGNIOL-VILLARD wrote:

Do you like to add some words going to git describing this patch here? E.g. what DCC is and what it might be used for?

You maybe need to read arm documentation

I think it is a perfectly reasonable request to explain at least what we are talking about. Please do not expect that everybody understands immediately what DCC means, or even is capable of finding out what the best context for searching might be.

So please do add such an explanation.

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
An Elephant is a mouse with an Operating System.              - Knuth