From patchwork Mon Apr 23 09:15:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 8030 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E3E5A23E23 for ; Mon, 23 Apr 2012 09:15:21 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id AB3BEA1835A for ; Mon, 23 Apr 2012 09:15:21 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so22452743iag.11 for ; Mon, 23 Apr 2012 02:15:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:mime-version:content-type :x-gm-message-state; bh=NtAPCzlu9/3c+IItwpyOj3XTknDXxRh5rj1BoHSd6No=; b=Hg5//1mJLBxJXlvdx1TjFT6SF/C2W2XEcKk0Ug4tUJgZ0AO1OB2/0fe2pDvxn7pdps bOwqa8DB3klh9wEBYr1FMc2UI3mO/f4XCbztbIXSlnC3VFG4D1/4snvareSqjvTL0YT8 lUU9+SZ3TgujtoCdC2hBexlpRYYvnBV53zvvEsQe+8NsK/dh2aMVzj2C5fZFcS0G0loK 4yas8llxfx72AR1+Cff/kMgqZExOj77m7XEc36ab0UiVvyMVE0S/3M5QgQPZw7j1WFNI UJhWSK3ba3x0nn99pCUVVbb/kwIG5QCqDft73ZSVlPsrc3wpLlpHlktIYxRxitfvlWy1 pXtA== Received: by 10.50.194.163 with SMTP id hx3mr5523360igc.49.1335172521465; Mon, 23 Apr 2012 02:15:21 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp97983ibt; Mon, 23 Apr 2012 02:15:20 -0700 (PDT) Received: by 10.213.16.140 with SMTP id o12mr1134419eba.150.1335172520116; Mon, 23 Apr 2012 02:15:20 -0700 (PDT) Received: from eu1sys200aog113.obsmtp.com (eu1sys200aog113.obsmtp.com. [207.126.144.135]) by mx.google.com with SMTP id a2si4197871eeg.98.2012.04.23.02.15.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Apr 2012 02:15:20 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.135 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.135; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.135 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob113.postini.com ([207.126.147.11]) with SMTP ID DSNKT5UdoIkr+bvibkdOf0FE1PFXxyWzWax7@postini.com; Mon, 23 Apr 2012 09:15:19 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id C1F1510A; Mon, 23 Apr 2012 09:06:47 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 54148147F; Mon, 23 Apr 2012 09:15:09 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 5903024C07C; Mon, 23 Apr 2012 11:15:03 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 23 Apr 2012 11:15:08 +0200 From: Linus Walleij To: , Cc: Grant Likely , Philippe LANGLAIS , Rabin Vincent , Jonas Aberg , Lee Jones , Linus Walleij Subject: [PATCH 8/9] ARM: ux500: implement pin API Date: Mon, 23 Apr 2012 11:15:06 +0200 Message-ID: <1335172506-27755-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.9.2 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlGkwBfCDsty8rART2W5y8Cu6YOo07xkvFsRsJmabN2SnqnALjqeQfZGbyRJ4CJJm/SciA/ From: Rabin Vincent Implement an API to allow a list of pincfgs to be remuxed to active and sleep modes, for power saving. This is not exported on purpose, because it is not to be called by drivers directly. Signed-off-by: Rabin Vincent Reviewed-by: Srinidhi Kasagar Signed-off-by: Linus Walleij --- arch/arm/mach-ux500/Makefile | 2 +- arch/arm/mach-ux500/board-mop500-pins.c | 1 + arch/arm/mach-ux500/pins.c | 88 +++++++++++++++++++++++++++++++ arch/arm/mach-ux500/pins.h | 46 ++++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-ux500/pins.c create mode 100644 arch/arm/mach-ux500/pins.h diff --git a/arch/arm/mach-ux500/Makefile b/arch/arm/mach-ux500/Makefile index 465b9ec..bfd902d 100644 --- a/arch/arm/mach-ux500/Makefile +++ b/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/arch/arm/mach-ux500/board-mop500-pins.c b/arch/arm/mach-ux500/board-mop500-pins.c index f5413dc..e2a2e50 100644 --- a/arch/arm/mach-ux500/board-mop500-pins.c +++ b/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/arch/arm/mach-ux500/pins.c b/arch/arm/mach-ux500/pins.c new file mode 100644 index 0000000..38c1d47 --- /dev/null +++ b/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/arch/arm/mach-ux500/pins.h b/arch/arm/mach-ux500/pins.h new file mode 100644 index 0000000..0d36af2 --- /dev/null +++ b/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