From patchwork Fri Mar 22 13:36:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lartey X-Patchwork-Id: 2320271 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 7D2A13FD8C for ; Fri, 22 Mar 2013 13:46:05 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UJ2FF-0007uM-Ta; Fri, 22 Mar 2013 13:42:57 +0000 Received: from slimlogic.co.uk ([89.16.172.20]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UJ28r-00058n-25 for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2013 13:36:34 +0000 Received: from localhost.localdomain (cpc3-sgyl22-0-0-cust168.18-2.cable.virginmedia.com [82.42.202.169]) by slimlogic.co.uk (Postfix) with ESMTPSA id 52C9D130A59; Fri, 22 Mar 2013 13:36:12 +0000 (GMT) From: Ian Lartey To: linux-kernel@vger.kernel.org Subject: [PATCH v9 05/11] gpio: palmas: add in GPIO support for palmas charger Date: Fri, 22 Mar 2013 13:36:07 +0000 Message-Id: <1363959373-10671-6-git-send-email-ian@slimlogic.co.uk> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1363959373-10671-1-git-send-email-ian@slimlogic.co.uk> References: <1363959373-10671-1-git-send-email-ian@slimlogic.co.uk> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130322_093621_459751_AE9B0112 X-CRM114-Status: GOOD ( 16.93 ) X-Spam-Score: -4.4 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-doc@vger.kernel.org, linus.walleij@linaro.org, grant.likely@secretlab.ca, wim@iguana.be, ldewangan@nvidia.com, gg@slimlogic.co.uk, linux-leds@vger.kernel.org, sfr@canb.auug.org.au, mturquette@linaro.org, sameo@linux.intel.com, linux-watchdog@vger.kernel.org, swarren@wwwdotorg.org, devicetree-discuss@lists.ozlabs.org, cooloney@gmail.com, rob.herring@calxeda.com, linux-arm-kernel@lists.infradead.org, j-keerthy@ti.com, broonie@opensource.wolfsonmicro.com, lgirdwood@gmail.com, t-kristo@ti.com, rpurdie@rpsys.net, rob@landley.net, akpm@linux-foundation.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Palmas charger has 16 GPIOs add palmas_gpio_[read|write|update] api to take account second bank of GPIOs Signed-off-by: Ian Lartey Signed-off-by: Graeme Gregory --- drivers/gpio/gpio-palmas.c | 77 ++++++++++++++++++++++++++++++++++++-------- include/linux/mfd/palmas.h | 12 ++++++- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c index e3a4e56..636648c 100644 --- a/drivers/gpio/gpio-palmas.c +++ b/drivers/gpio/gpio-palmas.c @@ -1,7 +1,7 @@ /* - * TI Palma series PMIC's GPIO driver. + * TI Palmas series PMIC's GPIO driver. * - * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2012-2012, NVIDIA CORPORATION. All rights reserved. * * Author: Laxman Dewangan * @@ -31,6 +31,36 @@ struct palmas_gpio { struct palmas *palmas; }; +static int palmas_gpio_read(struct palmas *palmas, unsigned int reg, + int gpio, unsigned int *dest) +{ + /* registers for second bank are identical and offset by 0x9 */ + if (gpio > 7) + reg += PALMAS_GPIO_DATA_IN2; + + return palmas_read(palmas, PALMAS_GPIO_BASE, reg, dest); +} + +static int palmas_gpio_write(struct palmas *palmas, unsigned int reg, + int gpio, unsigned int data) +{ + /* registers for second bank are identical and offset by 0x9 */ + if (gpio > 7) + reg += PALMAS_GPIO_DATA_IN2; + + return palmas_write(palmas, PALMAS_GPIO_BASE, reg, data); +} + +static int palmas_gpio_update_bits(struct palmas *palmas, unsigned int reg, + int gpio, unsigned int mask, unsigned int data) +{ + /* registers for second bank are identical and offset by 0x9 */ + if (gpio > 7) + reg += PALMAS_GPIO_DATA_IN2; + + return palmas_update_bits(palmas, PALMAS_GPIO_BASE, reg, mask, data); +} + static inline struct palmas_gpio *to_palmas_gpio(struct gpio_chip *chip) { return container_of(chip, struct palmas_gpio, gpio_chip); @@ -43,12 +73,12 @@ static int palmas_gpio_get(struct gpio_chip *gc, unsigned offset) unsigned int val; int ret; - ret = palmas_read(palmas, PALMAS_GPIO_BASE, PALMAS_GPIO_DATA_IN, &val); + ret = palmas_gpio_read(palmas, PALMAS_GPIO_DATA_IN, offset, &val); if (ret < 0) { dev_err(gc->dev, "GPIO_DATA_IN read failed, err = %d\n", ret); return ret; } - return !!(val & BIT(offset)); + return !!(val & BIT(offset % 8)); } static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset, @@ -59,11 +89,11 @@ static void palmas_gpio_set(struct gpio_chip *gc, unsigned offset, int ret; if (value) - ret = palmas_write(palmas, PALMAS_GPIO_BASE, - PALMAS_GPIO_SET_DATA_OUT, BIT(offset)); + ret = palmas_gpio_write(palmas, PALMAS_GPIO_SET_DATA_OUT, + offset, BIT(offset % 8)); else - ret = palmas_write(palmas, PALMAS_GPIO_BASE, - PALMAS_GPIO_CLEAR_DATA_OUT, BIT(offset)); + ret = palmas_gpio_write(palmas, PALMAS_GPIO_CLEAR_DATA_OUT, + offset, BIT(offset % 8)); if (ret < 0) dev_err(gc->dev, "%s write failed, err = %d\n", (value) ? "GPIO_SET_DATA_OUT" : "GPIO_CLEAR_DATA_OUT", @@ -80,8 +110,8 @@ static int palmas_gpio_output(struct gpio_chip *gc, unsigned offset, /* Set the initial value */ palmas_gpio_set(gc, offset, value); - ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, - PALMAS_GPIO_DATA_DIR, BIT(offset), BIT(offset)); + ret = palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR, + offset, 1 << (offset % 8), 1 << (offset % 8)); if (ret < 0) dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret); return ret; @@ -93,8 +123,8 @@ static int palmas_gpio_input(struct gpio_chip *gc, unsigned offset) struct palmas *palmas = pg->palmas; int ret; - ret = palmas_update_bits(palmas, PALMAS_GPIO_BASE, - PALMAS_GPIO_DATA_DIR, BIT(offset), 0); + ret = palmas_gpio_update_bits(palmas, PALMAS_GPIO_DATA_DIR, + offset, 1 << (offset % 8), 0); if (ret < 0) dev_err(gc->dev, "GPIO_DATA_DIR write failed, err = %d\n", ret); return ret; @@ -108,7 +138,21 @@ static int palmas_gpio_to_irq(struct gpio_chip *gc, unsigned offset) return palmas_irq_get_virq(palmas, PALMAS_GPIO_0_IRQ + offset); } -static int palmas_gpio_probe(struct platform_device *pdev) +static int palmas_gpio_set_debounce(struct gpio_chip *gc, unsigned offset, + unsigned debounce) +{ + struct palmas_gpio *palmas_gpio = to_palmas_gpio(gc); + struct palmas *palmas = palmas_gpio->palmas; + unsigned int data = 0; + + if (debounce) + data = 0xff; + + return palmas_gpio_update_bits(palmas, PALMAS_GPIO_DEBOUNCE_EN, + offset, 1 << (offset % 8), data); +} + +static int palmas_gpio_probe(struct platform_device *pdev) { struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); struct palmas_platform_data *palmas_pdata; @@ -125,10 +169,15 @@ static int palmas_gpio_probe(struct platform_device *pdev) palmas_gpio->palmas = palmas; palmas_gpio->gpio_chip.owner = THIS_MODULE; palmas_gpio->gpio_chip.label = dev_name(&pdev->dev); - palmas_gpio->gpio_chip.ngpio = 8; + /* palmas charger has 16 gpios */ + if (is_palmas_charger(palmas->product_id)) + palmas_gpio->gpio_chip.ngpio = 16; + else + palmas_gpio->gpio_chip.ngpio = 8; palmas_gpio->gpio_chip.can_sleep = 1; palmas_gpio->gpio_chip.direction_input = palmas_gpio_input; palmas_gpio->gpio_chip.direction_output = palmas_gpio_output; + palmas_gpio->gpio_chip.set_debounce = palmas_gpio_set_debounce, palmas_gpio->gpio_chip.to_irq = palmas_gpio_to_irq; palmas_gpio->gpio_chip.set = palmas_gpio_set; palmas_gpio->gpio_chip.get = palmas_gpio_get; diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h index 4cffe31..d8c303b 100644 --- a/include/linux/mfd/palmas.h +++ b/include/linux/mfd/palmas.h @@ -244,7 +244,7 @@ struct palmas_platform_data { * then the two value to load into the registers if true */ int mux_from_pdata; - u8 pad1, pad2; + u8 pad1, pad2, pad3, pad4; struct palmas_pmic_platform_data *pmic_pdata; struct palmas_gpadc_platform_data *gpadc_pdata; @@ -2513,6 +2513,16 @@ enum usb_irq_events { #define PALMAS_PU_PD_GPIO_CTRL1 0x6 #define PALMAS_PU_PD_GPIO_CTRL2 0x7 #define PALMAS_OD_OUTPUT_GPIO_CTRL 0x8 +#define PALMAS_GPIO_DATA_IN2 0x9 +#define PALMAS_GPIO_DATA_DIR2 0xA +#define PALMAS_GPIO_DATA_OUT2 0xB +#define PALMAS_GPIO_DEBOUNCE_EN2 0xC +#define PALMAS_GPIO_CLEAR_DATA_OUT2 0xD +#define PALMAS_GPIO_SET_DATA_OUT2 0xE +#define PALMAS_PU_PD_GPIO_CTRL3 0xF +#define PALMAS_PU_PD_GPIO_CTRL4 0x10 +#define PALMAS_OD_OUTPUT_GPIO_CTRL2 0x11 +#define PALMAS_GPO_CTRL 0x12 /* Bit definitions for GPIO_DATA_IN */ #define PALMAS_GPIO_DATA_IN_GPIO_7_IN 0x80