From 70e8413b7bff5c019d84b40123d0ec31ccc80a50 Mon Sep 17 00:00:00 2001 From: Rabin Vincent Date: Tue, 17 Apr 2012 13:35:31 +0200 Subject: [PATCH] --- yaml --- r: 303294 b: refs/heads/master c: 339bcf3b49832b6c6826f3549355fc8dcb6f5810 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/arch/arm/mach-ux500/Makefile | 2 +- trunk/arch/arm/mach-ux500/board-mop500-pins.c | 1 + trunk/arch/arm/mach-ux500/pins.c | 88 +++++++++++++++++++ trunk/arch/arm/mach-ux500/pins.h | 46 ++++++++++ 5 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 trunk/arch/arm/mach-ux500/pins.c create mode 100644 trunk/arch/arm/mach-ux500/pins.h diff --git a/[refs] b/[refs] index 5f28f604636d..cd9887890759 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 68293b3ad2e407f8d6b407f3e60811e068e5fe40 +refs/heads/master: 339bcf3b49832b6c6826f3549355fc8dcb6f5810 diff --git a/trunk/arch/arm/mach-ux500/Makefile b/trunk/arch/arm/mach-ux500/Makefile index 465b9ec9510a..bfd902dc9911 100644 --- a/trunk/arch/arm/mach-ux500/Makefile +++ b/trunk/arch/arm/mach-ux500/Makefile @@ -3,7 +3,7 @@ # obj-y := clock.o cpu.o devices.o devices-common.o \ - id.o usb.o timer.o + id.o pins.o usb.o timer.o obj-$(CONFIG_CACHE_L2X0) += cache-l2x0.o obj-$(CONFIG_UX500_SOC_DB5500) += cpu-db5500.o dma-db5500.o obj-$(CONFIG_UX500_SOC_DB8500) += cpu-db8500.o devices-db8500.o diff --git a/trunk/arch/arm/mach-ux500/board-mop500-pins.c b/trunk/arch/arm/mach-ux500/board-mop500-pins.c index f5413dca532c..e2a2e501b697 100644 --- a/trunk/arch/arm/mach-ux500/board-mop500-pins.c +++ b/trunk/arch/arm/mach-ux500/board-mop500-pins.c @@ -14,6 +14,7 @@ #include #include "pins-db8500.h" +#include "pins.h" static pin_cfg_t mop500_pins_common[] = { /* I2C */ diff --git a/trunk/arch/arm/mach-ux500/pins.c b/trunk/arch/arm/mach-ux500/pins.c new file mode 100644 index 000000000000..38c1d47b29a1 --- /dev/null +++ b/trunk/arch/arm/mach-ux500/pins.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Rabin Vincent for ST-Ericsson + * License terms: GNU General Public License (GPL), version 2 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "pins.h" + +static LIST_HEAD(pin_lookups); +static DEFINE_MUTEX(pin_lookups_mutex); +static DEFINE_SPINLOCK(pins_lock); + +void __init ux500_pins_add(struct ux500_pin_lookup *pl, size_t num) +{ + mutex_lock(&pin_lookups_mutex); + + while (num--) { + list_add_tail(&pl->node, &pin_lookups); + pl++; + } + + mutex_unlock(&pin_lookups_mutex); +} + +struct ux500_pins *ux500_pins_get(const char *name) +{ + struct ux500_pins *pins = NULL; + struct ux500_pin_lookup *pl; + + mutex_lock(&pin_lookups_mutex); + + list_for_each_entry(pl, &pin_lookups, node) { + if (!strcmp(pl->name, name)) { + pins = pl->pins; + goto out; + } + } + +out: + mutex_unlock(&pin_lookups_mutex); + return pins; +} + +int ux500_pins_enable(struct ux500_pins *pins) +{ + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&pins_lock, flags); + + if (pins->usage++ == 0) + ret = nmk_config_pins(pins->cfg, pins->num); + + spin_unlock_irqrestore(&pins_lock, flags); + return ret; +} + +int ux500_pins_disable(struct ux500_pins *pins) +{ + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&pins_lock, flags); + + if (WARN_ON(pins->usage == 0)) + goto out; + + if (--pins->usage == 0) + ret = nmk_config_pins_sleep(pins->cfg, pins->num); + +out: + spin_unlock_irqrestore(&pins_lock, flags); + return ret; +} + +void ux500_pins_put(struct ux500_pins *pins) +{ + WARN_ON(!pins); +} diff --git a/trunk/arch/arm/mach-ux500/pins.h b/trunk/arch/arm/mach-ux500/pins.h new file mode 100644 index 000000000000..0d36af2e7d92 --- /dev/null +++ b/trunk/arch/arm/mach-ux500/pins.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) ST-Ericsson SA 2010 + * + * Author: Rabin Vincent for ST-Ericsson + * License terms: GNU General Public License (GPL), version 2 + */ + +#ifndef __MACH_UX500_PINS_H +#define __MACH_UX500_PINS_H + +#include +#include + +#define PIN_LOOKUP(_name, _pins) \ +{ \ + .name = _name, \ + .pins = _pins, \ +} + +#define UX500_PINS(name, pins...) \ +struct ux500_pins name = { \ + .cfg = (pin_cfg_t[]) {pins}, \ + .num = ARRAY_SIZE(((pin_cfg_t[]) {pins})), \ +} + +struct ux500_pins { + int usage; + int num; + pin_cfg_t *cfg; +}; + +struct ux500_pin_lookup { + struct list_head node; + const char *name; + struct ux500_pins *pins; +}; + +void __init ux500_pins_add(struct ux500_pin_lookup *pl, size_t num); +void __init ux500_offchip_gpio_init(struct ux500_pins *pins); +struct ux500_pins *ux500_pins_get(const char *name); +int ux500_pins_enable(struct ux500_pins *pins); +int ux500_pins_disable(struct ux500_pins *pins); +void ux500_pins_put(struct ux500_pins *pins); +int pins_for_u9500(void); + +#endif