cpm2: Implement GPIO LIB API on CPM2 Freescale SoC.
authorLaurent Pinchart <laurentp@cse-semaphore.com>
Mon, 28 Jul 2008 08:43:22 +0000 (10:43 +0200)
committerKumar Gala <galak@kernel.crashing.org>
Mon, 28 Jul 2008 12:40:48 +0000 (07:40 -0500)
This patch implement GPIO LIB support for the CPM2 GPIOs. The code can
also be used for CPM1 GPIO port E, as both cores are compatible at the
register level.

Based on earlier work by Laurent Pinchart.

Signed-off-by: Jochen Friedrich <jochen@scram.de>
Cc: Laurent Pinchart <laurentp@cse-semaphore.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
arch/powerpc/platforms/Kconfig
arch/powerpc/sysdev/cpm2.c
arch/powerpc/sysdev/cpm_common.c
include/asm-powerpc/cpm.h

index 1d0968775c0a855a84c8eee2b2366301f0de9950..18a71839dc9e297acb40f62f57901065f23a9f3d 100644 (file)
@@ -254,6 +254,8 @@ config CPM2
        select CPM
        select PPC_LIB_RHEAP
        select PPC_PCI_CHOICE
+       select ARCH_REQUIRE_GPIOLIB
+       select GENERIC_GPIO
        help
          The CPM2 (Communications Processor Module) is a coprocessor on
          embedded CPUs made by Freescale.  Selecting this option means that
index 5a6c5dfc53ef1e0a3096aadc77a3d43958ae804b..9311778a5082ba56d262aff8c449a8af5f4f81ae 100644 (file)
@@ -377,3 +377,14 @@ void cpm2_set_pin(int port, int pin, int flags)
        else
                clrbits32(&iop[port].odr, pin);
 }
+
+static int cpm_init_par_io(void)
+{
+       struct device_node *np;
+
+       for_each_compatible_node(np, NULL, "fsl,cpm2-pario-bank")
+               cpm2_gpiochip_add32(np);
+       return 0;
+}
+arch_initcall(cpm_init_par_io);
+
index e4b7296acb2c7cbc9aa14ce3b9cf56641688f18d..53da8a079f96f7f15e8c4f5b94b5e59d0a42e0e3 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <linux/init.h>
 #include <linux/of_device.h>
+#include <linux/spinlock.h>
+#include <linux/of.h>
 
 #include <asm/udbg.h>
 #include <asm/io.h>
 
 #include <mm/mmu_decl.h>
 
+#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
+#include <linux/of_gpio.h>
+#endif
+
 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
 static u32 __iomem *cpm_udbg_txdesc =
        (u32 __iomem __force *)CONFIG_PPC_EARLY_DEBUG_CPM_ADDR;
@@ -207,3 +213,120 @@ dma_addr_t cpm_muram_dma(void __iomem *addr)
        return muram_pbase + ((u8 __iomem *)addr - muram_vbase);
 }
 EXPORT_SYMBOL(cpm_muram_dma);
+
+#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
+
+struct cpm2_ioports {
+       u32 dir, par, sor, odr, dat;
+       u32 res[3];
+};
+
+struct cpm2_gpio32_chip {
+       struct of_mm_gpio_chip mm_gc;
+       spinlock_t lock;
+
+       /* shadowed data register to clear/set bits safely */
+       u32 cpdata;
+};
+
+static inline struct cpm2_gpio32_chip *
+to_cpm2_gpio32_chip(struct of_mm_gpio_chip *mm_gc)
+{
+       return container_of(mm_gc, struct cpm2_gpio32_chip, mm_gc);
+}
+
+static void cpm2_gpio32_save_regs(struct of_mm_gpio_chip *mm_gc)
+{
+       struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
+       struct cpm2_ioports __iomem *iop = mm_gc->regs;
+
+       cpm2_gc->cpdata = in_be32(&iop->dat);
+}
+
+static int cpm2_gpio32_get(struct gpio_chip *gc, unsigned int gpio)
+{
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct cpm2_ioports __iomem *iop = mm_gc->regs;
+       u32 pin_mask;
+
+       pin_mask = 1 << (31 - gpio);
+
+       return !!(in_be32(&iop->dat) & pin_mask);
+}
+
+static void cpm2_gpio32_set(struct gpio_chip *gc, unsigned int gpio, int value)
+{
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
+       struct cpm2_ioports __iomem *iop = mm_gc->regs;
+       unsigned long flags;
+       u32 pin_mask = 1 << (31 - gpio);
+
+       spin_lock_irqsave(&cpm2_gc->lock, flags);
+
+       if (value)
+               cpm2_gc->cpdata |= pin_mask;
+       else
+               cpm2_gc->cpdata &= ~pin_mask;
+
+       out_be32(&iop->dat, cpm2_gc->cpdata);
+
+       spin_unlock_irqrestore(&cpm2_gc->lock, flags);
+}
+
+static int cpm2_gpio32_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
+{
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct cpm2_ioports __iomem *iop = mm_gc->regs;
+       u32 pin_mask;
+
+       pin_mask = 1 << (31 - gpio);
+
+       setbits32(&iop->dir, pin_mask);
+
+       cpm2_gpio32_set(gc, gpio, val);
+
+       return 0;
+}
+
+static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
+{
+       struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
+       struct cpm2_ioports __iomem *iop = mm_gc->regs;
+       u32 pin_mask;
+
+       pin_mask = 1 << (31 - gpio);
+
+       clrbits32(&iop->dir, pin_mask);
+
+       return 0;
+}
+
+int cpm2_gpiochip_add32(struct device_node *np)
+{
+       struct cpm2_gpio32_chip *cpm2_gc;
+       struct of_mm_gpio_chip *mm_gc;
+       struct of_gpio_chip *of_gc;
+       struct gpio_chip *gc;
+
+       cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL);
+       if (!cpm2_gc)
+               return -ENOMEM;
+
+       spin_lock_init(&cpm2_gc->lock);
+
+       mm_gc = &cpm2_gc->mm_gc;
+       of_gc = &mm_gc->of_gc;
+       gc = &of_gc->gc;
+
+       mm_gc->save_regs = cpm2_gpio32_save_regs;
+       of_gc->gpio_cells = 2;
+       gc->ngpio = 32;
+       gc->direction_input = cpm2_gpio32_dir_in;
+       gc->direction_output = cpm2_gpio32_dir_out;
+       gc->get = cpm2_gpio32_get;
+       gc->set = cpm2_gpio32_set;
+
+       return of_mm_gpiochip_add(np, mm_gc);
+}
+#endif /* CONFIG_CPM2 || CONFIG_8xx_GPIO */
index 63a55337c2deca37d12b34d4fd5a48c4a1aeef4d..24d79e3abd8e9499decfe8bb0b5bd50c94d9c0be 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/compiler.h>
 #include <linux/types.h>
+#include <linux/of.h>
 
 /* Opcodes common to CPM1 and CPM2
 */
@@ -100,4 +101,6 @@ unsigned long cpm_muram_offset(void __iomem *addr);
 dma_addr_t cpm_muram_dma(void __iomem *addr);
 int cpm_command(u32 command, u8 opcode);
 
+int cpm2_gpiochip_add32(struct device_node *np);
+
 #endif
This page took 0.029302 seconds and 5 git commands to generate.