/* * GPIO functions for Au1000, Au1500, Au1100, Au1550, Au1200 * * Copyright (c) 2009 Manuel Lauss. * * Licensed under the terms outlined in the file COPYING.
*/
/* The default GPIO numberspace as documented in the Alchemy manuals. * GPIO0-31 from GPIO1 block, GPIO200-215 from GPIO2 block.
*/ #define ALCHEMY_GPIO1_BASE 0 #define ALCHEMY_GPIO2_BASE 200
staticinlineint alchemy_gpio1_direction_output(int gpio, int v)
{ /* hardware switches to "output" mode when one of the two * "set_value" registers is accessed.
*/
alchemy_gpio1_set_value(gpio, v); return 0;
}
staticinlineint alchemy_gpio1_to_irq(int gpio)
{ switch (alchemy_get_cputype()) { case ALCHEMY_CPU_AU1000: return au1000_gpio1_to_irq(gpio); case ALCHEMY_CPU_AU1100: return au1100_gpio1_to_irq(gpio); case ALCHEMY_CPU_AU1500: return au1500_gpio1_to_irq(gpio); case ALCHEMY_CPU_AU1550: return au1550_gpio1_to_irq(gpio); case ALCHEMY_CPU_AU1200: return au1200_gpio1_to_irq(gpio);
} return -ENXIO;
}
/* On Au1000, Au1500 and Au1100 GPIOs won't work as inputs before * SYS_PININPUTEN is written to at least once. On Au1550/Au1200/Au1300 this * register enables use of GPIOs as wake source.
*/ staticinlinevoid alchemy_gpio1_input_enable(void)
{ void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR);
__raw_writel(0, base + 0x110); /* the write op is key */
wmb();
}
/* * GPIO2 block macros for common linux GPIO functions. The 'gpio' * parameter must be in range of ALCHEMY_GPIO2_BASE..ALCHEMY_GPIO2_MAX.
*/ staticinlinevoid __alchemy_gpio2_mod_dir(int gpio, int to_out)
{ void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); unsignedlong mask = 1 << (gpio - ALCHEMY_GPIO2_BASE); unsignedlong d = __raw_readl(base + AU1000_GPIO2_DIR);
if (to_out)
d |= mask; else
d &= ~mask;
__raw_writel(d, base + AU1000_GPIO2_DIR);
wmb();
}
staticinlinevoid __alchemy_gpio2_mod_int(int gpio2, int en)
{ void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR); unsignedlong r = __raw_readl(base + AU1000_GPIO2_INTENABLE); if (en)
r |= 1 << gpio2; else
r &= ~(1 << gpio2);
__raw_writel(r, base + AU1000_GPIO2_INTENABLE);
wmb();
}
/** * alchemy_gpio2_enable_int - Enable a GPIO2 pins' shared irq contribution. * @gpio2: The GPIO2 pin to activate (200...215). * * GPIO208-215 have one shared interrupt line to the INTC. They are * and'ed with a per-pin enable bit and finally or'ed together to form * a single irq request (useful for active-high sources). * With this function, a pins' individual contribution to the int request * can be enabled. As with all other GPIO-based interrupts, the INTC * must be programmed to accept the GPIO208_215 interrupt as well. * * NOTE: Calling this macro is only necessary for GPIO208-215; all other * GPIO2-based interrupts have their own request to the INTC. Please * consult your Alchemy databook for more information! * * NOTE: On the Au1550, GPIOs 201-205 also have a shared interrupt request * line to the INTC, GPIO201_205. This function can be used for those * as well. * * NOTE: 'gpio2' parameter must be in range of the GPIO2 numberspace * (200-215 by default). No sanity checks are made,
*/ staticinlinevoid alchemy_gpio2_enable_int(int gpio2)
{ unsignedlong flags;
gpio2 -= ALCHEMY_GPIO2_BASE;
/* Au1100/Au1500 have GPIO208-215 enable bits at 0..7 */ switch (alchemy_get_cputype()) { case ALCHEMY_CPU_AU1100: case ALCHEMY_CPU_AU1500:
gpio2 -= 8;
}
/** * alchemy_gpio2_disable_int - Disable a GPIO2 pins' shared irq contribution. * @gpio2: The GPIO2 pin to activate (200...215). * * see function alchemy_gpio2_enable_int() for more information.
*/ staticinlinevoid alchemy_gpio2_disable_int(int gpio2)
{ unsignedlong flags;
gpio2 -= ALCHEMY_GPIO2_BASE;
/* Au1100/Au1500 have GPIO208-215 enable bits at 0..7 */ switch (alchemy_get_cputype()) { case ALCHEMY_CPU_AU1100: case ALCHEMY_CPU_AU1500:
gpio2 -= 8;
}
/** * alchemy_gpio2_enable - Activate GPIO2 block. * * The GPIO2 block must be enabled explicitly to work. On systems * where this isn't done by the bootloader, this macro can be used.
*/ staticinlinevoid alchemy_gpio2_enable(void)
{ void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
__raw_writel(3, base + AU1000_GPIO2_ENABLE); /* reset, clock enabled */
wmb();
__raw_writel(1, base + AU1000_GPIO2_ENABLE); /* clock enabled */
wmb();
}
/** * alchemy_gpio2_disable - disable GPIO2 block. * * Disable and put GPIO2 block in low-power mode.
*/ staticinlinevoid alchemy_gpio2_disable(void)
{ void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
__raw_writel(2, base + AU1000_GPIO2_ENABLE); /* reset, clock disabled */
wmb();
}
/* wrappers for on-chip gpios; can be used before gpio chips have been * registered with gpiolib.
*/ staticinlineint alchemy_gpio_direction_input(int gpio)
{ return (gpio >= ALCHEMY_GPIO2_BASE) ?
alchemy_gpio2_direction_input(gpio) :
alchemy_gpio1_direction_input(gpio);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.