public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] use "boot selecr" jumper on NGW100 to select USART
@ 2009-11-05  3:55 Thomas Sprinkmeier
  2009-11-05 20:08 ` Wolfgang Denk
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Sprinkmeier @ 2009-11-05  3:55 UTC (permalink / raw)
  To: u-boot

Without the "boot select" jumper U-Boot will use the USART selected
using the CONFIG_USART1, CONFIG_USART2, directive.

If  CONFIG_ALT_USART1 (or ..2, ..3, ..0) is defined then,
with the jumper in place, that USART is used instead.

Signed-off-by: Thomas Sprinkmeier <thomas.sprinkmeier@gmail.com>
---
 board/atmel/atngw100/atngw100.c |   40 ++++++++++++++++++++++++++++
 drivers/serial/atmel_usart.c    |   54 ++++++++++++++++++++++++++++++++++++++-
 drivers/serial/atmel_usart.h    |    9 +++---
 include/configs/atngw100.h      |    1 +
 4 files changed, 98 insertions(+), 6 deletions(-)

diff --git a/board/atmel/atngw100/atngw100.c b/board/atmel/atngw100/atngw100.c
index 004d8da..a2ffdb4 100644
--- a/board/atmel/atngw100/atngw100.c
+++ b/board/atmel/atngw100/atngw100.c
@@ -53,7 +53,47 @@ int board_early_init_f(void)
        hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));

        portmux_enable_ebi(16, 23, 0, PORTMUX_DRIVE_HIGH);
+
+#if defined(CONFIG_ALT_USART0) || defined(CONFIG_ALT_USART1) || \
+    defined(CONFIG_ALT_USART2) || defined(CONFIG_ALT_USART3)
+#define USART_USE_ALT  (!gpio_get_value(GPIO_PIN_PB(30)))
+
+       /* PB30, the 'boot' jumper with external pull-up resistor */
+       /* PORTMUX_DIR_INPUT == 0 as high-impedance input is the default state.
+          In other words, I don't think this actually does anything... */
+       portmux_select_gpio(PORTMUX_PORT_B,
+                           (1 << 30),
+                           PORTMUX_DIR_INPUT);
+       /* Now to read the state of the pin and use it to determine which
+          USART to initialise. Should I sleep first to make sure the
+          pin settles down (just in case the above call did actually
+          do something)? */
+       if (USART_USE_ALT) {
+#if   defined(CONFIG_ALT_USART0)
+         portmux_enable_usart0(PORTMUX_DRIVE_MIN);
+#elif defined(CONFIG_ALT_USART1)
+         portmux_enable_usart1(PORTMUX_DRIVE_MIN);
+#elif defined(CONFIG_ALT_USART2)
+         portmux_enable_usart2(PORTMUX_DRIVE_MIN);
+#elif defined(CONFIG_ALT_USART3)
+         portmux_enable_usart3(PORTMUX_DRIVE_MIN);
+#endif
+       } else {
+#endif
+#if   defined(CONFIG_USART0)
+       portmux_enable_usart0(PORTMUX_DRIVE_MIN);
+#elif defined(CONFIG_USART1)
        portmux_enable_usart1(PORTMUX_DRIVE_MIN);
+#elif defined(CONFIG_USART2)
+       portmux_enable_usart2(PORTMUX_DRIVE_MIN);
+#elif defined(CONFIG_USART3)
+       portmux_enable_usart3(PORTMUX_DRIVE_MIN);
+#else
+       #error "Define CONFIG_USART0..3"
+#endif
+#ifdef USART_USE_ALT
+       }
+#endif

 #if defined(CONFIG_MACB)
        portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH);
diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c
index f50552a..ffafe9e 100644
--- a/drivers/serial/atmel_usart.c
+++ b/drivers/serial/atmel_usart.c
@@ -34,6 +34,33 @@
 #elif defined(CONFIG_USART3)
 # define USART_ID      3
 # define USART_BASE    USART3_BASE
+#else
+#warning "You need to define CONFIG_USART[0..3]"
+#endif
+
+#if defined(CONFIG_ALT_USART0)
+# define USART_ALT_ID  0
+# define USART_ALT_BASE        USART0_BASE
+#elif defined(CONFIG_ALT_USART1)
+# define USART_ALT_ID  1
+# define USART_ALT_BASE        USART1_BASE
+#elif defined(CONFIG_ALT_USART2)
+# define USART_ALT_ID  2
+# define USART_ALT_BASE        USART2_BASE
+#elif defined(CONFIG_ALT_USART3)
+# define USART_ALT_ID  3
+# define USART_ALT_BASE        USART3_BASE
+#endif
+
+#ifdef USART_ALT_ID
+#if USART_ID == USART_ALT_ID
+#warning "Alternate USART should be different from primary"
+#warning "   change CONFIG_USARTn and/or CONFIG_ALT_USARTn"
+#endif
+
+/* true iff jumper in place */
+#define USART_USE_ALT  (!gpio_get_value(GPIO_PIN_PB(30)))
+
 #endif

 #include "atmel_usart.h"
@@ -50,7 +77,13 @@ void serial_setbrg(void)
         * Baud Rate = --------------
         *                16 * CD
         */
-       usart_hz = get_usart_clk_rate(USART_ID);
+#ifdef USART_ALT_ID
+       if (USART_USE_ALT)
+         usart_hz = get_usart_clk_rate(USART_ALT_ID);
+       else
+#endif
+         usart_hz = get_usart_clk_rate(USART_ID);
+
        divisor = (usart_hz / 16 + gd->baudrate / 2) / gd->baudrate;
        usart3_writel(BRGR, USART3_BF(CD, divisor));
 }
@@ -97,3 +130,22 @@ int serial_tstc(void)
 {
        return (usart3_readl(CSR) & USART3_BIT(RXRDY)) != 0;
 }
+
+int atmel_serial_read(int reg)
+{
+#ifdef USART_ALT_ID
+  if (USART_USE_ALT)
+    return readl(USART_ALT_BASE + reg);
+#endif
+  return readl(USART_BASE + reg);
+}
+
+void atmel_serial_write(int reg, int value)
+{
+#ifdef USART_ALT_ID
+  if (USART_USE_ALT)
+    writel(value, (void *)USART_ALT_BASE + reg);
+  else
+#endif
+    writel(value, (void *)USART_BASE + reg);
+}
diff --git a/drivers/serial/atmel_usart.h b/drivers/serial/atmel_usart.h
index af3773a..4fc5f50 100644
--- a/drivers/serial/atmel_usart.h
+++ b/drivers/serial/atmel_usart.h
@@ -305,10 +305,9 @@
                    << USART3_##name##_OFFSET))         \
         | USART3_BF(name,value))

-/* Register access macros */
-#define usart3_readl(reg)                              \
-       readl((void *)USART_BASE + USART3_##reg)
-#define usart3_writel(reg,value)                       \
-       writel((value), (void *)USART_BASE + USART3_##reg)
+int atmel_serial_read(int reg);
+void atmel_serial_write(int reg, int value);
+#define usart3_readl(reg) atmel_serial_read(USART3_##reg)
+#define usart3_writel(reg, value) atmel_serial_write(USART3_##reg, value)

 #endif /* __DRIVERS_ATMEL_USART_H__ */
diff --git a/include/configs/atngw100.h b/include/configs/atngw100.h
index 4ed5514..d5a6e83 100644
--- a/include/configs/atngw100.h
+++ b/include/configs/atngw100.h
@@ -59,6 +59,7 @@
 #define CONFIG_SYS_PLL0_OPT                    0x04

 #define CONFIG_USART1                  1
+#define CONFIG_ALT_USART1              3

 /* User serviceable stuff */
 #define CONFIG_DOS_PARTITION           1
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] use "boot selecr" jumper on NGW100 to select USART
  2009-11-05  3:55 [U-Boot] [PATCH] use "boot selecr" jumper on NGW100 to select USART Thomas Sprinkmeier
@ 2009-11-05 20:08 ` Wolfgang Denk
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Denk @ 2009-11-05 20:08 UTC (permalink / raw)
  To: u-boot

Dear Thomas Sprinkmeier,

In message <e355f1140911041955q1adf2c1fp75375e4b98cfdc00@mail.gmail.com> you wrote:
> Without the "boot select" jumper U-Boot will use the USART selected
> using the CONFIG_USART1, CONFIG_USART2, directive.

Please fix the typo in the Subject:

> If  CONFIG_ALT_USART1 (or ..2, ..3, ..0) is defined then,
> with the jumper in place, that USART is used instead.
> 
> Signed-off-by: Thomas Sprinkmeier <thomas.sprinkmeier@gmail.com>
> ---
>  board/atmel/atngw100/atngw100.c |   40 ++++++++++++++++++++++++++++
>  drivers/serial/atmel_usart.c    |   54 ++++++++++++++++++++++++++++++++++++++-
>  drivers/serial/atmel_usart.h    |    9 +++---
>  include/configs/atngw100.h      |    1 +
>  4 files changed, 98 insertions(+), 6 deletions(-)
> 
> diff --git a/board/atmel/atngw100/atngw100.c b/board/atmel/atngw100/atngw100.c
> index 004d8da..a2ffdb4 100644
> --- a/board/atmel/atngw100/atngw100.c
> +++ b/board/atmel/atngw100/atngw100.c
> @@ -53,7 +53,47 @@ int board_early_init_f(void)
>         hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE));
> 
>         portmux_enable_ebi(16, 23, 0, PORTMUX_DRIVE_HIGH);
> +
> +#if defined(CONFIG_ALT_USART0) || defined(CONFIG_ALT_USART1) || \
> +    defined(CONFIG_ALT_USART2) || defined(CONFIG_ALT_USART3)
> +#define USART_USE_ALT  (!gpio_get_value(GPIO_PIN_PB(30)))

Your patch is white space corrupted. All "original" indentation was by
TABs, but in your patch it's all spaces.

> +       /* PB30, the 'boot' jumper with external pull-up resistor */
> +       /* PORTMUX_DIR_INPUT == 0 as high-impedance input is the default state.
> +          In other words, I don't think this actually does anything... */

Incorrect multiline comment style. Please fix globally.

> +       if (USART_USE_ALT) {
> +#if   defined(CONFIG_ALT_USART0)
> +         portmux_enable_usart0(PORTMUX_DRIVE_MIN);
> +#elif defined(CONFIG_ALT_USART1)
> +         portmux_enable_usart1(PORTMUX_DRIVE_MIN);
> +#elif defined(CONFIG_ALT_USART2)
> +         portmux_enable_usart2(PORTMUX_DRIVE_MIN);
> +#elif defined(CONFIG_ALT_USART3)
> +         portmux_enable_usart3(PORTMUX_DRIVE_MIN);
> +#endif

Incorrect indentation. Please fix globally.


> +       } else {
> +#endif
> +#if   defined(CONFIG_USART0)
> +       portmux_enable_usart0(PORTMUX_DRIVE_MIN);
> +#elif defined(CONFIG_USART1)
>         portmux_enable_usart1(PORTMUX_DRIVE_MIN);
> +#elif defined(CONFIG_USART2)
> +       portmux_enable_usart2(PORTMUX_DRIVE_MIN);
> +#elif defined(CONFIG_USART3)
> +       portmux_enable_usart3(PORTMUX_DRIVE_MIN);
> +#else

If only one CONFIG_USARTx is allowed, you should think opf a way to
get rid of these long, repeated #if...#elif...#elif constructs.
> 
> -/* Register access macros */
> -#define usart3_readl(reg)                              \
> -       readl((void *)USART_BASE + USART3_##reg)
> -#define usart3_writel(reg,value)                       \
> -       writel((value), (void *)USART_BASE + USART3_##reg)
> +int atmel_serial_read(int reg);
> +void atmel_serial_write(int reg, int value);
> +#define usart3_readl(reg) atmel_serial_read(USART3_##reg)
> +#define usart3_writel(reg, value) atmel_serial_write(USART3_##reg, value)

Instead of making code more AT91 specific, we should try the opposite:
make it _less_ so.


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
I really hate this damned machine     It never does quite what I want
I wish that they would sell it.              But only what I tell it.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-05 20:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-05  3:55 [U-Boot] [PATCH] use "boot selecr" jumper on NGW100 to select USART Thomas Sprinkmeier
2009-11-05 20:08 ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox