cns3xxx: Fix laguna arm11mpcore watchdog
[librecmc/librecmc.git] / target / linux / cns3xxx / patches-3.3 / 300-laguna_support.patch
index 3d866c66691a4e11b1dcd4d77b7ea2c8ffa1e0e6..a4602f929298e2ee322e9dd7e5f42abe3a68696c 100644 (file)
@@ -1,6 +1,6 @@
 --- /dev/null
 +++ b/arch/arm/mach-cns3xxx/laguna.c
-@@ -0,0 +1,765 @@
+@@ -0,0 +1,935 @@
 +/*
 + * Gateworks Corporation Laguna Platform
 + *
@@ -12,6 +12,8 @@
 + *              Anton Vorontsov <avorontsov@mvista.com>
 + * Copyright 2011 Gateworks Corporation
 + *              Chris Lang <clang@gateworks.com>
++ * Copyright 2012 Gateworks Corporation
++ *              Tim Harvey <tharvey@gateworks.com>
 + *
 + * This file is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License, Version 2, as
@@ -22,6 +24,7 @@
 +#include <linux/kernel.h>
 +#include <linux/compiler.h>
 +#include <linux/io.h>
++#include <linux/gpio.h>
 +#include <linux/dma-mapping.h>
 +#include <linux/serial_core.h>
 +#include <linux/serial_8250.h>
@@ -49,6 +52,8 @@
 +#include "core.h"
 +#include "devices.h"
 +
++#define ARRAY_AND_SIZE(x)       (x), ARRAY_SIZE(x)
++
 +// Config 1 Bitmap
 +#define ETH0_LOAD           BIT(0)
 +#define ETH1_LOAD           BIT(1)
 +      u8 spi_flash_size;
 +};
 +
-+static struct laguna_board_info laguna_info;
++static struct laguna_board_info laguna_info __initdata;
 +
 +/*
 + * NOR Flash
 +
 +static struct resource laguna_watchdog_resources[] = {
 +      [0] = {
-+              .start  = CNS3XXX_TC11MP_TWD_BASE,
++              .start  = CNS3XXX_TC11MP_TWD_BASE + 0x100, // CPU0 watchdog
 +              .end    = CNS3XXX_TC11MP_TWD_BASE + SZ_4K - 1,
 +              .flags  = IORESOURCE_MEM,
 +      },
 +};
 +
 +/*
-+ * Initialization
++ * GPIO
 + */
++static struct platform_device laguna_gpio_dev = {
++      .name = "GPIODEV",
++      .id = -1,
++};
 +
++static struct gpio laguna_gpio_gw2391[] = {
++      {   0, GPIOF_IN           , "*GPS_PPS" },
++      {   1, GPIOF_IN           , "*GSC_IRQ#" },
++      {   2, GPIOF_IN           , "*USB_FAULT#" },
++      {   5, GPIOF_OUT_INIT_LOW , "*USB0_PCI_SEL" },
++      {   6, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
++      {   7, GPIOF_OUT_INIT_LOW , "*USB1_PCI_SEL" },
++      {   8, GPIOF_OUT_INIT_HIGH, "*PERST#" },
++      {   9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN#" },
++      { 100, GPIOF_IN           , "*USER_PB#" },
++      { 103, GPIOF_OUT_INIT_HIGH, "*V5_EN" },
++      { 108, GPIOF_IN           , "DIO0" },
++      { 109, GPIOF_IN           , "DIO1" },
++      { 110, GPIOF_IN           , "DIO2" },
++      { 111, GPIOF_IN           , "DIO3" },
++      { 112, GPIOF_IN           , "DIO4" },
++};
++
++static struct gpio laguna_gpio_gw2388[] = {
++      {   0, GPIOF_IN           , "*GPS_PPS" },
++      {   1, GPIOF_IN           , "*GSC_IRQ#" },
++      {   3, GPIOF_IN           , "*USB_FAULT#" },
++      {   6, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
++      {   7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
++      {   8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
++      {   9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN" },
++      { 100, GPIOF_OUT_INIT_HIGH, "*USER_PB#" },
++      { 108, GPIOF_IN           , "DIO0" },
++      { 109, GPIOF_IN           , "DIO1" },
++      { 110, GPIOF_IN           , "DIO2" },
++      { 111, GPIOF_IN           , "DIO3" },
++      { 112, GPIOF_IN           , "DIO4" },
++};
++
++static struct gpio laguna_gpio_gw2387[] = {
++      {   0, GPIOF_IN           , "*GPS_PPS" },
++      {   1, GPIOF_IN           , "*GSC_IRQ#" },
++      {   2, GPIOF_IN           , "*USB_FAULT#" },
++      {   5, GPIOF_OUT_INIT_LOW , "*USB_PCI_SEL" },
++      {   6, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
++      {   7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
++      {   8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
++      {   9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN" },
++      { 100, GPIOF_IN           , "*USER_PB#" },
++      { 103, GPIOF_OUT_INIT_HIGH, "*V5_EN" },
++      { 108, GPIOF_IN           , "DIO0" },
++      { 109, GPIOF_IN           , "DIO1" },
++      { 110, GPIOF_IN           , "DIO2" },
++      { 111, GPIOF_IN           , "DIO3" },
++      { 112, GPIOF_IN           , "DIO4" },
++      { 113, GPIOF_IN           , "DIO5" },
++};
++
++static struct gpio laguna_gpio_gw2384[] = {
++      {   0, GPIOF_IN           , "*GSC_IRQ#" },
++      {   1, GPIOF_OUT_INIT_HIGH, "*USB_HST_VBUS_EN" },
++      {   2, GPIOF_IN           , "*USB_HST_FAULT#" },
++      {   5, GPIOF_IN           , "*USB_OTG_FAULT#" },
++      {   6, GPIOF_OUT_INIT_LOW , "*USB_HST_PCI_SEL" },
++      {   7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
++      {   8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
++      {   9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN" },
++      {  12, GPIOF_OUT_INIT_LOW , "J10_DIOLED0" },
++      {  13, GPIOF_OUT_INIT_HIGH, "*I2CMUX_RST#" },
++      {  14, GPIOF_OUT_INIT_LOW , "J10_DIOLED1" },
++      {  15, GPIOF_OUT_INIT_LOW , "J10_DIOLED2" },
++      { 100, GPIOF_IN           , "*USER_PB#" },
++      { 103, GPIOF_OUT_INIT_HIGH, "V5_EN" },
++      { 108, GPIOF_IN           , "J9_DIOGSC0" },
++};
++
++static struct gpio laguna_gpio_gw2383[] = {
++      {   0, GPIOF_IN           , "*GPS_PPS" },
++      {   1, GPIOF_IN           , "*GSC_IRQ#" },
++      {   2, GPIOF_OUT_INIT_HIGH, "*PCIE_RST#" },
++      {   3, GPIOF_IN           , "GPIO0" },
++      {   8, GPIOF_IN           , "GPIO1" },
++      { 100, GPIOF_IN           , "DIO0" },
++      { 101, GPIOF_IN           , "DIO1" },
++};
++
++static struct gpio laguna_gpio_gw2382[] = {
++      {   0, GPIOF_IN           , "*GPS_PPS" },
++      {   1, GPIOF_IN           , "*GSC_IRQ#" },
++      {   2, GPIOF_OUT_INIT_HIGH, "*PCIE_RST#" },
++      {   3, GPIOF_IN           , "GPIO0" },
++      {   4, GPIOF_IN           , "GPIO1" },
++      {   9, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
++      {  10, GPIOF_OUT_INIT_HIGH, "*USB_PCI_SEL#" },
++      { 100, GPIOF_IN           , "DIO0" },
++      { 101, GPIOF_IN           , "DIO1" },
++};
++
++static struct gpio laguna_gpio_gw2380[] = {
++      {   0, GPIOF_IN           , "*GPS_PPS" },
++      {   1, GPIOF_IN           , "*GSC_IRQ#" },
++      {   3, GPIOF_IN           , "GPIO0" },
++      {   8, GPIOF_IN           , "GPIO1" },
++      { 100, GPIOF_IN           , "DIO0" },
++      { 101, GPIOF_IN           , "DIO1" },
++      { 102, GPIOF_IN           , "DIO2" },
++      { 103, GPIOF_IN           , "DIO3" },
++};
++
++/*
++ * Initialization
++ */
 +static void __init laguna_init(void)
 +{
 +      cns3xxx_l2x0_init();
 +
 +      platform_device_register(&laguna_i2c_controller);
 +
-+      i2c_register_board_info(0, laguna_i2c_devices,
-+                      ARRAY_SIZE(laguna_i2c_devices));
++      i2c_register_board_info(0, ARRAY_AND_SIZE(laguna_i2c_devices));
 +
 +      pm_power_off = cns3xxx_power_off;
 +}
 +{
 +      cns3xxx_common_init();
 +      cns3xxx_pcie_iotable_init(0x3);
-+      iotable_init(laguna_io_desc, ARRAY_SIZE(laguna_io_desc));
++      iotable_init(ARRAY_AND_SIZE(laguna_io_desc));
 +      laguna_early_serial_setup();
 +}
 +
++static int laguna_register_gpio(struct gpio *array, size_t num)
++{
++      int i, err, ret;
++
++      ret = 0;
++      for (i = 0; i < num; i++, array++) {
++              const char *label = array->label;
++              if (label[0] == '*')
++                      label++;
++              err = gpio_request_one(array->gpio, array->flags, label);
++              if (err)
++                      ret = err;
++              else {
++                      err = gpio_export(array->gpio, array->label[0] != '*');
++              }
++      }
++      return ret;
++}
++
 +static int __init laguna_model_setup(void)
 +{
 +      u32 __iomem *mem;
 +                                      laguna_spi_partitions[3].size = SZ_64M - SZ_2M;
 +                              break;
 +                      }
-+                      spi_register_board_info(laguna_spi_devices, ARRAY_SIZE(laguna_spi_devices));
++                      spi_register_board_info(ARRAY_AND_SIZE(laguna_spi_devices));
 +              }
 +
 +              if ((laguna_info.config_bitmap & SPI0_LOAD) ||
 +               *  the first 6 characters of the model name
 +               */
 +
-+              if (strncmp(laguna_info.model, "GW2388", 6) == 0) {
++              if ( (strncmp(laguna_info.model, "GW2388", 6) == 0)
++                || (strncmp(laguna_info.model, "GW2389", 6) == 0) )
++              {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2388));
++                      // configure LED's
++                      laguna_gpio_leds_data.num_leds = 2;
++              } else if (strncmp(laguna_info.model, "GW2387", 6) == 0) {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2387));
++                      // configure LED's
 +                      laguna_gpio_leds_data.num_leds = 2;
++              } else if (strncmp(laguna_info.model, "GW2384", 6) == 0) {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2384));
++                      // configure LED's
++                      laguna_gpio_leds_data.num_leds = 1;
++              } else if (strncmp(laguna_info.model, "GW2383", 6) == 0) {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2383));
++                      // configure LED's
++                      laguna_gpio_leds[0].gpio = 107;
++                      laguna_gpio_leds_data.num_leds = 1;
++              } else if (strncmp(laguna_info.model, "GW2382", 6) == 0) {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2382));
++                      // configure LED's
++                      laguna_gpio_leds[0].gpio = 107;
++                      laguna_gpio_leds_data.num_leds = 1;
 +              } else if (strncmp(laguna_info.model, "GW2380", 6) == 0) {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2380));
++                      // configure LED's
 +                      laguna_gpio_leds[0].gpio = 107;
 +                      laguna_gpio_leds[1].gpio = 106;
 +                      laguna_gpio_leds_data.num_leds = 2;
++              } else if (strncmp(laguna_info.model, "GW2391", 6) == 0) {
++                      // configure GPIO's
++                      laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2391));
++                      // configure LED's
++                      laguna_gpio_leds_data.num_leds = 2;
 +              }
 +              platform_device_register(&laguna_gpio_leds_device);
++              platform_device_register(&laguna_gpio_dev);
 +      } else {
 +              // Do some defaults here, not sure what yet
 +      }
 +        for USB, USB-OTG, MMC/SD/SDIO, SATA, PCI-E, I2C, GIG, etc.
 +
  endmenu
---- a/arch/arm/Kconfig
-+++ b/arch/arm/Kconfig
-@@ -366,6 +366,7 @@ config ARCH_CLPS711X
- config ARCH_CNS3XXX
-       bool "Cavium Networks CNS3XXX family"
-       select CPU_V6K
-+      select ARCH_WANT_OPTIONAL_GPIOLIB
-       select GENERIC_CLOCKEVENTS
-       select ARM_GIC
-       select CLKDEV_LOOKUP
---- /dev/null
-+++ b/arch/arm/mach-cns3xxx/include/mach/gpio.h
-@@ -0,0 +1,98 @@
-+/*
-+ * arch/arm/mach-cns3xxx/include/mach/gpio.h
-+ *
-+ * CNS3xxx GPIO wrappers for arch-neutral GPIO calls
-+ *
-+ * Copyright 2011 Gateworks Corporation
-+ *              Chris Lang <clang@gateworks.com>
-+ *
-+ * Based on IXP implementation by Milan Svoboda <msvoboda@ra.rockwell.com>
-+ * Based on PXA implementation by Philipp Zabel <philipp.zabel@gmail.com>
-+ *
-+ * 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 __ASM_ARCH_CNS3XXX_GPIO_H
-+#define __ASM_ARCH_CNS3XXX_GPIO_H
-+
-+#include <linux/kernel.h>
-+#include <linux/io.h>
-+#include <mach/platform.h>
-+#include <asm-generic/gpio.h>                 /* cansleep wrappers */
-+
-+#define NR_BUILTIN_GPIO 64
-+
-+#define CNS3XXX_GPIO_IN    0x0
-+#define CNS3XXX_GPIO_OUT   0x1
-+
-+#define CNS3XXX_GPIO_LO   0
-+#define CNS3XXX_GPIO_HI   1
-+
-+#define CNS3XXX_GPIO_OUTPUT         0x00
-+#define CNS3XXX_GPIO_INPUT          0x04
-+#define CNS3XXX_GPIO_DIR            0x08
-+#define CNS3XXX_GPIO_SET            0x10
-+#define CNS3XXX_GPIO_CLEAR          0x14
-+
-+static inline void gpio_line_get(u8 line, int *value)
-+{
-+      if (line < 32)
-+              *value = ((__raw_readl(CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_INPUT) >> line) & 0x1);
-+      else
-+              *value = ((__raw_readl(CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_INPUT) >> (line - 32)) & 0x1);
-+}
-+
-+static inline void gpio_line_set(u8 line, int value)
-+{
-+      if (line < 32) {
-+              if (value)
-+                      __raw_writel((1 << line), CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_SET);
-+              else
-+                      __raw_writel((1 << line), CNS3XXX_GPIOA_BASE_VIRT + CNS3XXX_GPIO_CLEAR);
-+      } else {
-+              if (value)
-+                      __raw_writel((1 << line), CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_SET);
-+              else
-+                      __raw_writel((1 << line), CNS3XXX_GPIOB_BASE_VIRT + CNS3XXX_GPIO_CLEAR);
-+      }
-+}
-+
-+static inline int gpio_get_value(unsigned gpio)
-+{
-+      if (gpio < NR_BUILTIN_GPIO)
-+      {
-+              int value;
-+              gpio_line_get(gpio, &value);
-+              return value;
-+      }
-+      else
-+              return __gpio_get_value(gpio);
-+}
-+
-+static inline void gpio_set_value(unsigned gpio, int value)
-+{
-+      if (gpio < NR_BUILTIN_GPIO)
-+              gpio_line_set(gpio, value);
-+      else
-+              __gpio_set_value(gpio, value);
-+}
-+
-+#define gpio_cansleep __gpio_cansleep
-+
-+extern int gpio_to_irq(int gpio);
-+extern int irq_to_gpio(int gpio);
-+
-+#endif
 --- a/arch/arm/mach-cns3xxx/Makefile
 +++ b/arch/arm/mach-cns3xxx/Makefile
 @@ -1,6 +1,7 @@