From patchwork Fri Jul 30 17:08:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 115561 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6UH958L021406 for ; Fri, 30 Jul 2010 17:09:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752036Ab0G3RJE (ORCPT ); Fri, 30 Jul 2010 13:09:04 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:36028 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751921Ab0G3RJD (ORCPT ); Fri, 30 Jul 2010 13:09:03 -0400 Received: by pvc7 with SMTP id 7so617117pvc.19 for ; Fri, 30 Jul 2010 10:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=EtWiJQupPx7QI178LC/y992wSwUvpGEH04vj0KQETN4=; b=OXfTPPMqRs36U70dxHxYWV9ybJh91/QTuNI9nDIA3qdRGjzy1uJC5hz+2gUCdnQyi/ 1V0o7qJSteMxO0Yf9+hv10wfEmSb/P8c67nw1vGpzqbykA3smKP3bum4chjWBL1QQF76 +vXNY8MYFiZVpxyK2gDfPis7B+pi/TYr17pOc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=X0A1Vr+6VhWppSAYffN0RNdXM83iQLL1eQaDCDqMEh2zo+luQFWUs8j/nUbw10IsJp HnTuARKdOO4ApzMFNhD3f4WbIMx8jodGRftyazvhzswb4+DxRwjnC6D478ei90c7az36 RAHEPnkW+hERaiJ/L9QOie6JEDPgD2jZ+w2Bg= Received: by 10.114.125.12 with SMTP id x12mr2699365wac.91.1280509741635; Fri, 30 Jul 2010 10:09:01 -0700 (PDT) Received: from mailhub.coreip.homeip.net (c-24-6-153-206.hsd1.ca.comcast.net [24.6.153.206]) by mx.google.com with ESMTPS id c24sm4101813wam.7.2010.07.30.10.08.58 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 30 Jul 2010 10:08:58 -0700 (PDT) Date: Fri, 30 Jul 2010 10:08:54 -0700 From: Dmitry Torokhov To: "Hennerich, Michael" Cc: Xiaolong Chen , "david-b@pacbell.net" , Michael Hennerich , "linux-input@vger.kernel.org" , TAO HU , "Yuan.Bo YE" , Xiaolong CHEN , uclinux-dist-devel Subject: Re: Fwd: [RFC] [PATCH] Input: ADP5588 - Support gpio function on unused pin Message-ID: <20100730170854.GA22450@core.coreip.homeip.net> References: <4c459b70.0aee8c0a.1c29.3e9e@mx.google.com> <4C4DADA7.9000201@gmail.com> <20100726173844.GC14609@core.coreip.homeip.net> <544AC56F16B56944AEC3BD4E3D5917712E7EC2301D@LIMKCMBX1.ad.analog.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <544AC56F16B56944AEC3BD4E3D5917712E7EC2301D@LIMKCMBX1.ad.analog.com> User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 30 Jul 2010 17:09:05 +0000 (UTC) diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c index c39ec93..4208ff5 100644 --- a/drivers/input/keyboard/adp5588-keys.c +++ b/drivers/input/keyboard/adp5588-keys.c @@ -173,41 +173,47 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip, return ret; } -static int __devinit adp5588_gpio_add(struct device *dev) +static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad, + const struct adp5588_kpad_platform_data *pdata) { - struct adp5588_kpad *kpad = dev_get_drvdata(dev); - const struct adp5588_kpad_platform_data *pdata = dev->platform_data; - const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data; - int i, error; + bool pin_used[MAXGPIO]; + int n_unused = 0; + int i; - if (gpio_data) { - int j = 0; - bool pin_used[MAXGPIO]; + for (i = 0; i < pdata->rows; i++) + pin_used[i] = true; - for (i = 0; i < pdata->rows; i++) - pin_used[i] = true; + for (i = 0; i < pdata->cols; i++) + pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true; - for (i = 0; i < pdata->cols; i++) - pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true; + for (i = 0; i < kpad->gpimapsize; i++) + pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true; - for (i = 0; i < kpad->gpimapsize; i++) - pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true; + for (i = 0; i < MAXGPIO; i++) + if (!pin_used[i]) + kpad->gpiomap[n_unused++] = i; - for (i = 0; i < MAXGPIO; i++) { - if (!pin_used[i]) - kpad->gpiomap[j++] = i; - } - kpad->gc.ngpio = j; + return n_unused; +} - if (kpad->gc.ngpio) - kpad->export_gpio = true; - } +static int __devinit adp5588_gpio_add(struct adp5588_kpad *kpad) +{ + struct device *dev = &kpad->client->dev; + const struct adp5588_kpad_platform_data *pdata = dev->platform_data; + const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data; + int i, error; - if (!kpad->export_gpio) { + if (!gpio_data) + return 0; + + kpad->gc.ngpio = adp5588_build_gpiomap(kpad, pdata); + if (kpad->gc.ngpio == 0) { dev_info(dev, "No unused gpios left to export\n"); return 0; } + kpad->export_gpio = true; + kpad->gc.direction_input = adp5588_gpio_direction_input; kpad->gc.direction_output = adp5588_gpio_direction_output; kpad->gc.get = adp5588_gpio_get_value; @@ -243,9 +249,9 @@ static int __devinit adp5588_gpio_add(struct device *dev) return 0; } -static void __devexit adp5588_gpio_remove(struct device *dev) +static void __devexit adp5588_gpio_remove(struct adp5588_kpad *kpad) { - struct adp5588_kpad *kpad = dev_get_drvdata(dev); + struct device *dev = &kpad->client->dev; const struct adp5588_kpad_platform_data *pdata = dev->platform_data; const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data; int error; @@ -266,12 +272,12 @@ static void __devexit adp5588_gpio_remove(struct device *dev) dev_warn(dev, "gpiochip_remove failed %d\n", error); } #else -static inline int adp5588_gpio_add(struct device *dev) +static inline int adp5588_gpio_add(struct adp5588_kpad *kpad) { return 0; } -static inline void adp5588_gpio_remove(struct device *dev) +static inline void adp5588_gpio_remove(struct adp5588_kpad *kpad) { } #endif @@ -581,7 +587,7 @@ static int __devinit adp5588_probe(struct i2c_client *client, if (kpad->gpimapsize) adp5588_report_switch_state(kpad); - error = adp5588_gpio_add(&client->dev); + error = adp5588_gpio_add(kpad); if (error) goto err_free_irq; @@ -611,7 +617,7 @@ static int __devexit adp5588_remove(struct i2c_client *client) free_irq(client->irq, kpad); cancel_delayed_work_sync(&kpad->work); input_unregister_device(kpad->input); - adp5588_gpio_remove(&client->dev); + adp5588_gpio_remove(kpad); kfree(kpad); return 0;