[EMAIL PROTECTED] wrote:
From: Trilok Soni <[EMAIL PROTECTED]>

- Addes common.c which implements bootloader tag passing support,
  as well board config structure passing support from board specific
  file. e.g for DAVINCI_TAG_UART, to specify enabled uarts pattern,
  and DAVINCI_TAG_SERIAL_CONSOLE to specify console UART and it's baudrate.

- This patch code is mostly derived from the OMAP TAG support code and it is
  tested on DaVinci DM6446 based custom board.

Signed-off-by: Trilok Soni <[EMAIL PROTECTED]>

Hi Trilok,

Can you fix the checkpatch warnings/errors in this patch? Running scripts/checkpatch.pl, I get:

total: 4 errors, 1 warnings, 282 lines checked

The DAVINCI_TAG_UART patch looks ok, and I'll apply both after the fixups.

Thanks,

Kevin


diff --git a/arch/arm/mach-davinci/Kconfig b/arch/arm/mach-davinci/Kconfig
index e722c0f..aed1e70 100644
--- a/arch/arm/mach-davinci/Kconfig
+++ b/arch/arm/mach-davinci/Kconfig
@@ -43,6 +43,14 @@ config DAVINCI_MCBSP
        ---help---
        DaVinci McBSP driver.  Auto-enabled by DaVinci sound driver.
+config DAVINCI_BOOT_TAG
+       bool "DaVinci bootloader information passing"
+        depends on ARCH_DAVINCI644x
+        default n
+        help
+          Say Y, if you have a bootloader which passes information
+          about your board and its peripheral configuration.
+
 comment "DaVinci Options"
config DAVINCI_BLK_DEV_CF
diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile
index 9a8b68f..00ed24c 100644
--- a/arch/arm/mach-davinci/Makefile
+++ b/arch/arm/mach-davinci/Makefile
@@ -5,7 +5,7 @@
# Common objects
 obj-y                  := time.o irq.o clock.o serial.o io.o id.o psc.o \
-                          gpio.o mux.o dma.o devices.o
+                          gpio.o mux.o dma.o devices.o common.o
# Board specific
 obj-$(CONFIG_MACH_DAVINCI_EVM)         += board-evm.o i2c-emac.o
diff --git a/arch/arm/mach-davinci/common.c b/arch/arm/mach-davinci/common.c
new file mode 100644
index 0000000..1529b23
--- /dev/null
+++ b/arch/arm/mach-davinci/common.c
@@ -0,0 +1,186 @@
+/*
+ * linux/arch/arm/mach-davinci/common.c
+ *
+ * Code common to all DaVinci machines.
+ *
+ * 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.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/console.h>
+#include <linux/serial.h>
+#include <linux/tty.h>
+#include <linux/serial_8250.h>
+#include <linux/serial_reg.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <asm/hardware.h>
+#include <asm/system.h>
+#include <asm/pgtable.h>
+#include <asm/mach/map.h>
+#include <asm/setup.h>
+
+#include <asm/arch/board.h>
+#include <asm/arch/serial.h>
+#include <asm/arch/mux.h>
+
+#include <asm/arch/clock.h>
+
+#define NO_LENGTH_CHECK 0xffffffff
+
+unsigned char davinci_bootloader_tag[1024];
+int davinci_bootloader_tag_len;
+
+struct davinci_board_config_kernel *davinci_board_config;
+int davinci_board_config_size;
+
+#ifdef CONFIG_DAVINCI_BOOT_TAG
+
+static int __init parse_tag_davinci(const struct tag *tag)
+{
+       u32 size = tag->hdr.size - (sizeof(tag->hdr) >> 2);
+
+       size <<= 2;
+       if (size > sizeof(davinci_bootloader_tag))
+               return -1;
+
+       memcpy(davinci_bootloader_tag, tag->u.davinci.data, size);
+       davinci_bootloader_tag_len = size;
+
+       return 0;
+}
+
+__tagtable(ATAG_BOARD, parse_tag_davinci);
+
+#endif
+
+static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
+{
+       struct davinci_board_config_kernel *kinfo = NULL;
+       int i;
+
+#ifdef CONFIG_DAVINCI_BOOT_TAG
+       struct davinci_board_config_entry *info = NULL;
+
+       if (davinci_bootloader_tag_len > 4)
+               info = (struct davinci_board_config_entry *) 
davinci_bootloader_tag;
+       while (info != NULL) {
+               u8 *next;
+
+               if (info->tag == tag) {
+                       if (skip == 0)
+                               break;
+                       skip--;
+               }
+
+               if ((info->len & 0x03) != 0) {
+                       /* We bail out to avoid an alignment fault */
+                       printk(KERN_ERR "DAVINCI peripheral config: Length (%d)"
+                                "not word-aligned (tag %04x)\n", info->len,
+                                info->tag);
+                       return NULL;
+               }
+               next = (u8 *) info + sizeof(*info) + info->len;
+               if (next >= davinci_bootloader_tag + davinci_bootloader_tag_len)
+                       info = NULL;
+               else
+                       info = (struct davinci_board_config_entry *) next;
+       }
+       if (info != NULL) {
+               /* Check the length as a lame attempt to check for
+                * binary inconsistency. */
+               if (len != NO_LENGTH_CHECK) {
+                       /* Word-align len */
+                       if (len & 0x03)
+                               len = (len + 3) & ~0x03;
+                       if (info->len != len) {
+                               printk(KERN_ERR "DaVinci peripheral config: "
+                                       "Length mismatch with tag %x"
+                                       " (want %d, got %d)\n", tag, len,
+                                        info->len);
+                               return NULL;
+                       }
+               }
+               if (len_out != NULL)
+                       *len_out = info->len;
+               return info->data;
+       }
+#endif
+       /* Try to find the config from the board-specific structures
+        * in the kernel. */
+       for (i = 0; i < davinci_board_config_size; i++) {
+               if (davinci_board_config[i].tag == tag) {
+                       if (skip == 0) {
+                               kinfo = &davinci_board_config[i];
+                               break;
+                       } else {
+                               skip--;
+                       }
+               }
+       }
+       if (kinfo == NULL)
+               return NULL;
+       return kinfo->data;
+}
+
+const void *__davinci_get_config(u16 tag, size_t len, int nr)
+{
+       return get_config(tag, len, nr, NULL);
+}
+EXPORT_SYMBOL(__davinci_get_config);
+
+const void *davinci_get_var_config(u16 tag, size_t *len)
+{
+       return get_config(tag, NO_LENGTH_CHECK, 0, len);
+}
+EXPORT_SYMBOL(davinci_get_var_config);
+
+static int __init davinci_add_serial_console(void)
+{
+       const struct davinci_serial_console_config *con_info;
+       const struct davinci_uart_config *uart_info;
+       static char speed[11], *opt;
+       int line, i, uart_idx;
+
+       uart_info = davinci_get_config(DAVINCI_TAG_UART,
+                                        struct davinci_uart_config);
+       con_info = davinci_get_config(DAVINCI_TAG_SERIAL_CONSOLE,
+                                       struct davinci_serial_console_config);
+       if (uart_info == NULL || con_info == NULL)
+               return 0;
+
+       if (con_info->console_uart == 0)
+               return 0;
+
+       if (con_info->console_speed) {
+               snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
+               opt = speed;
+       }
+
+       uart_idx = con_info->console_uart - 1;
+       if (uart_idx >= DAVINCI_MAX_NR_UARTS) {
+               printk(KERN_INFO "Console: external UART#%d. "
+                       "Not adding it as console this time.\n",
+                       uart_idx + 1);
+               return 0;
+       }
+       if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
+               printk(KERN_ERR "Console: Selected UART#%d is "
+                       "not enabled for this platform\n",
+                       uart_idx + 1);
+               return -1;
+       }
+       line = 0;
+       for (i = 0; i < uart_idx; i++) {
+               if (uart_info->enabled_uarts & (1 << i))
+                       line++;
+       }
+       return add_preferred_console("ttyS", line, opt);
+}
+console_initcall(davinci_add_serial_console);
diff --git a/include/asm-arm/arch-davinci/board.h 
b/include/asm-arm/arch-davinci/board.h
new file mode 100644
index 0000000..f1554b3
--- /dev/null
+++ b/include/asm-arm/arch-davinci/board.h
@@ -0,0 +1,53 @@
+/*
+ *  linux/include/asm-arm/arch-davinci/board.h
+ *
+ *  Information structures for board-specific data
+ *
+ *  Derived from OMAP board.h:
+ *     Copyright (C) 2004      Nokia Corporation
+ *     Written by Juha Yrjölä <[EMAIL PROTECTED]>
+ */
+
+#ifndef _DAVINCI_BOARD_H
+#define _DAVINCI_BOARD_H
+
+#include <linux/types.h>
+
+/* Different peripheral ids */
+#define DAVINCI_TAG_UART               0x4f01
+#define DAVINCI_TAG_SERIAL_CONSOLE     0x4f02
+
+struct davinci_serial_console_config {
+       u8 console_uart;
+       u32 console_speed;
+};
+
+struct davinci_uart_config {
+       /* Bit field of UARTs present; bit 0 --> UART1 */
+       unsigned int enabled_uarts;
+};
+
+struct davinci_board_config_entry {
+       u16 tag;
+       u16 len;
+       u8  data[0];
+};
+
+struct davinci_board_config_kernel {
+       u16 tag;
+       const void *data;
+};
+
+extern const void *__davinci_get_config(u16 tag, size_t len, int nr);
+
+#define davinci_get_config(tag, type) \
+       ((const type *) __davinci_get_config((tag), sizeof(type), 0))
+#define davinci_get_nr_config(tag, type, nr) \
+       ((const type *) __davinci_get_config((tag), sizeof(type), (nr)))
+
+extern const void *davinci_get_var_config(u16 tag, size_t *len);
+
+extern struct davinci_board_config_kernel *davinci_board_config;
+extern int davinci_board_config_size;
+
+#endif
diff --git a/include/asm-arm/setup.h b/include/asm-arm/setup.h
index da78617..3d12d91 100644
--- a/include/asm-arm/setup.h
+++ b/include/asm-arm/setup.h
@@ -143,6 +143,10 @@ struct tag_omap {
        u8 data[0];
 };
+struct tag_davinci {
+       u8 data[0];
+};
+
 /* footbridge memory clock, see arch/arm/mach-footbridge/arch.c */
 #define ATAG_MEMCLK    0x41000402
@@ -174,6 +178,11 @@ struct tag {
                 struct tag_omap         omap;
/*
+                * DaVinci specific
+                 */
+                struct tag_davinci     davinci;
+
+               /*
                 * DC21285 specific
                 */
                struct tag_memclk       memclk;

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to