From patchwork Tue Nov 19 21:11:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 3213301 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1D126C045B for ; Wed, 20 Nov 2013 14:38:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6504420122 for ; Wed, 20 Nov 2013 14:38:41 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9115820121 for ; Wed, 20 Nov 2013 14:38:39 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vj8uu-0006zS-TI; Wed, 20 Nov 2013 14:38:09 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vj8un-0001Os-Ty; Wed, 20 Nov 2013 14:38:01 +0000 Received: from mail-pd0-x232.google.com ([2607:f8b0:400e:c02::232]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vj8ua-0001MI-Oi for linux-arm-kernel@lists.infradead.org; Wed, 20 Nov 2013 14:37:50 +0000 Received: by mail-pd0-f178.google.com with SMTP id y10so2808064pdj.37 for ; Wed, 20 Nov 2013 06:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=YYQfugZ6nWnmaJgiN8E2sTM4GD8BR0vj4EDYlogFFCw=; b=ojP9plX3oVqykjNQpn9sWLvHeL8VdXvXFkiZ7leRAyGW/yn+F8GGx/LIK4hTieri7N Spa2aI01lbhKbeE00KJZhETGtBtTqc+PAc5L2YKJ8CDlJStDmCsb1vuTpneuL0NHXkyh 8eeydChKco086bFM7ndkoR7CH3AdhZHpowmHSbzB+ACkcyKId0C8E1vkGgEtT7H4fK8U QPU9MkleSA/OISOA1YHZbHpj8FNqFuStGrqkq5vR4zASBXkc4OzHFZUWtcsfRIdyjMk3 fvrpQNCg8+kFFH9uYioq7lq/ctUB2BX//hz4UZ2+bDu8ObrSFoPJUpgfZ+ZvsQnh62Ci Nq1Q== X-Received: by 10.66.179.143 with SMTP id dg15mr1107179pac.52.1384958243190; Wed, 20 Nov 2013 06:37:23 -0800 (PST) Received: from mailhub.coreip.homeip.net (c-67-188-112-76.hsd1.ca.comcast.net. [67.188.112.76]) by mx.google.com with ESMTPSA id oa3sm5224522pbb.15.2013.11.20.06.37.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 20 Nov 2013 06:37:22 -0800 (PST) Date: Tue, 19 Nov 2013 13:11:02 -0800 From: Dmitry Torokhov To: Denis Carikli Subject: Re: [PATCHv9][ 1/3] Input: tsc2007: Add device tree support. Message-ID: <20131119211102.GA14888@core.coreip.homeip.net> References: <1383916659-9988-1-git-send-email-denis@eukrea.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1383916659-9988-1-git-send-email-denis@eukrea.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131120_093748_982563_44D4160C X-CRM114-Status: GOOD ( 30.75 ) X-Spam-Score: -1.0 (-) Cc: Mark Rutland , devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, Eric =?iso-8859-1?Q?B=E9nard?= , Pawel Moll , Stephen Warren , Ian Campbell , Rob Herring , Tomi Valkeinen , Sascha Hauer , linux-input@vger.kernel.org, Grant Likely , Shawn Guo , Jean-Christophe Plagniol-Villard , linux-arm-kernel@lists.infradead.org, Lothar =?iso-8859-1?Q?Wa=DFmann?= 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DATE_IN_PAST_12_24, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Denis, On Fri, Nov 08, 2013 at 02:17:37PM +0100, Denis Carikli wrote: > Cc: Rob Herring > Cc: Pawel Moll > Cc: Mark Rutland > Cc: Stephen Warren > Cc: Ian Campbell > Cc: Grant Likely > Cc: devicetree@vger.kernel.org > Cc: Dmitry Torokhov > Cc: linux-input@vger.kernel.org > Cc: Sascha Hauer > Cc: linux-arm-kernel@lists.infradead.org > Cc: Lothar Waßmann > Cc: Shawn Guo > Cc: Eric Bénard > Signed-off-by: Denis Carikli > --- > ChangeLog v8->v9: > - Added Grant Likely in the Cc list. > - Removed the mention of the pinctrl properties in the documentation. > > ChangeLog v7->v8: > - Fixed the lack of x and z fuzz properties. > - The pendown gpio is better documented. > - Added Shawn Guo in the cc list. Does the device still work if you drop the patch below on top of yours? Thanks! Tested-by: Denis Carikli diff --git a/arch/arm/mach-imx/mach-cpuimx35.c b/arch/arm/mach-imx/mach-cpuimx35.c index 771362d..65e4c53 100644 --- a/arch/arm/mach-imx/mach-cpuimx35.c +++ b/arch/arm/mach-imx/mach-cpuimx35.c @@ -53,7 +53,7 @@ static const struct imxi2c_platform_data }; #define TSC2007_IRQGPIO IMX_GPIO_NR(3, 2) -static int tsc2007_get_pendown_state(void) +static int tsc2007_get_pendown_state(struct device *dev) { return !gpio_get_value(TSC2007_IRQGPIO); } diff --git a/arch/arm/mach-imx/mach-cpuimx51sd.c b/arch/arm/mach-imx/mach-cpuimx51sd.c index 9b5ddf5..1fba2b8 100644 --- a/arch/arm/mach-imx/mach-cpuimx51sd.c +++ b/arch/arm/mach-imx/mach-cpuimx51sd.c @@ -121,7 +121,7 @@ static const struct imxuart_platform_data uart_pdata __initconst = { .flags = IMXUART_HAVE_RTSCTS, }; -static int tsc2007_get_pendown_state(void) +static int tsc2007_get_pendown_state(struct device *dev) { if (mx51_revision() < IMX_CHIP_REVISION_3_0) return !gpio_get_value(TSC2007_IRQGPIO_REV2); diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c index 1fa8be4..23d7e45 100644 --- a/arch/sh/boards/mach-ecovec24/setup.c +++ b/arch/sh/boards/mach-ecovec24/setup.c @@ -501,7 +501,7 @@ static struct platform_device keysc_device = { /* TouchScreen */ #define IRQ0 evt2irq(0x600) -static int ts_get_pendown_state(void) +static int ts_get_pendown_state(struct device *dev) { int val = 0; gpio_free(GPIO_FN_INTC_IRQ0); diff --git a/drivers/input/touchscreen/tsc2007.c b/drivers/input/touchscreen/tsc2007.c index 3168a99..390148c 100644 --- a/drivers/input/touchscreen/tsc2007.c +++ b/drivers/input/touchscreen/tsc2007.c @@ -88,15 +88,10 @@ struct tsc2007 { wait_queue_head_t wait; bool stopped; - int (*get_pendown_state)(void); + int (*get_pendown_state)(struct device *); void (*clear_penirq)(void); }; -static int tsc2007_get_pendown_state_dt(struct tsc2007 *ts) -{ - return !gpio_get_value(ts->gpio); -} - static inline int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd) { s32 data; @@ -155,14 +150,6 @@ static u32 tsc2007_calculate_pressure(struct tsc2007 *tsc, struct ts_event *tc) return rt; } -static bool tsc2007_is_pen_down_valid(struct tsc2007 *ts) -{ - if (ts->of) - return gpio_is_valid(ts->gpio); - else - return ts->get_pendown_state ? true : false; -} - static bool tsc2007_is_pen_down(struct tsc2007 *ts) { /* @@ -179,13 +166,10 @@ static bool tsc2007_is_pen_down(struct tsc2007 *ts) * to fall back on the pressure reading. */ - if (!tsc2007_is_pen_down_valid(ts)) + if (!ts->get_pendown_state) return true; - if (ts->of) - return tsc2007_get_pendown_state_dt(ts); - else - return ts->get_pendown_state(); + return ts->get_pendown_state(&ts->client->dev); } static irqreturn_t tsc2007_soft_irq(int irq, void *handle) @@ -202,7 +186,7 @@ static irqreturn_t tsc2007_soft_irq(int irq, void *handle) rt = tsc2007_calculate_pressure(ts, &tc); - if (!rt && !tsc2007_is_pen_down_valid(ts)) { + if (!rt && !ts->get_pendown_state) { /* * If pressure reported is 0 and we don't have * callback to check pendown state, we have to @@ -298,13 +282,25 @@ static void tsc2007_close(struct input_dev *input_dev) } #ifdef CONFIG_OF -static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts, - struct device_node *np) +static int tsc2007_get_pendown_state_gpio(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct tsc2007 *ts = i2c_get_clientdata(client); + + return !gpio_get_value(ts->gpio); +} + +static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts) { - int err = 0; + struct device_node *np = client->dev.of_node; u32 val32; u64 val64; + if (!np) { + dev_err(&client->dev, "missing device tree data\n"); + return -EINVAL; + } + if (!of_property_read_u32(np, "ti,max-rt", &val32)) ts->max_rt = val32; else @@ -327,42 +323,32 @@ static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts, if (!of_property_read_u32(np, "ti,x-plate-ohms", &val32)) { ts->x_plate_ohms = val32; } else { - dev_err(&client->dev, - "Error: lacking ti,x-plate-ohms devicetree property. (err %d).", - err); + dev_err(&client->dev, "missing ti,x-plate-ohms devicetree property."); return -EINVAL; } ts->gpio = of_get_gpio(np, 0); - if (!gpio_is_valid(ts->gpio)) - dev_err(&client->dev, - "GPIO not found (of_get_gpio returned %d)\n", - ts->gpio); - - /* Used to detect if it is probed trough the device tree, - * in order to be able to use that information in the IRQ handler. - */ - ts->of = 1; + if (gpio_is_valid(ts->gpio)) + ts->get_pendown_state = tsc2007_get_pendown_state_gpio; + else + dev_warn(&client->dev, + "GPIO not specified in DT (of_get_gpio returned %d)\n", + ts->gpio); return 0; } #else -static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts, - struct device_node *np) +static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts) { - return -ENODEV; + dev_err(&client->dev, "platform data is required!\n"); + return -EINVAL; } #endif static int tsc2007_probe_pdev(struct i2c_client *client, struct tsc2007 *ts, - struct tsc2007_platform_data *pdata, + const struct tsc2007_platform_data *pdata, const struct i2c_device_id *id) { - if (!pdata) { - dev_err(&client->dev, "platform data is required!\n"); - return -EINVAL; - } - ts->model = pdata->model; ts->x_plate_ohms = pdata->x_plate_ohms; ts->max_rt = pdata->max_rt ? : MAX_12BIT; @@ -379,45 +365,40 @@ static int tsc2007_probe_pdev(struct i2c_client *client, struct tsc2007 *ts, return -EINVAL; } - /* Used to detect if it is probed trough the device tree, - * in order to be able to use that information in the IRQ handler. - */ - ts->of = 0; - return 0; } static int tsc2007_probe(struct i2c_client *client, const struct i2c_device_id *id) { - struct device_node *np = client->dev.of_node; - struct tsc2007_platform_data *pdata = client->dev.platform_data; + const struct tsc2007_platform_data *pdata = dev_get_platdata(&client->dev); struct tsc2007 *ts; struct input_dev *input_dev; - int err = 0; + int err; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_WORD_DATA)) + return -EIO; ts = devm_kzalloc(&client->dev, sizeof(struct tsc2007), GFP_KERNEL); if (!ts) return -ENOMEM; - if (np) - err = tsc2007_probe_dt(client, ts, np); - else + if (pdata) err = tsc2007_probe_pdev(client, ts, pdata, id); - + else + err = tsc2007_probe_dt(client, ts); if (err) return err; - if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) - return -EIO; - input_dev = input_allocate_device(); if (!input_dev) { err = -ENOMEM; goto err_free_input; }; + i2c_set_clientdata(client, ts); + ts->client = client; ts->irq = client->irq; ts->input = input_dev; @@ -443,10 +424,8 @@ static int tsc2007_probe(struct i2c_client *client, input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT, ts->fuzzz, 0); - if (!np) { - if (pdata->init_platform_hw) - pdata->init_platform_hw(); - } + if (pdata && pdata->init_platform_hw) + pdata->init_platform_hw(); err = request_threaded_irq(ts->irq, tsc2007_hard_irq, tsc2007_soft_irq, IRQF_ONESHOT, client->dev.driver->name, ts); @@ -461,16 +440,12 @@ static int tsc2007_probe(struct i2c_client *client, if (err) goto err_free_irq; - i2c_set_clientdata(client, ts); - return 0; err_free_irq: free_irq(ts->irq, ts); - if (!np) { - if (pdata->exit_platform_hw) - pdata->exit_platform_hw(); - } + if (pdata && pdata->exit_platform_hw) + pdata->exit_platform_hw(); err_free_input: input_free_device(input_dev); return err; @@ -478,16 +453,13 @@ static int tsc2007_probe(struct i2c_client *client, static int tsc2007_remove(struct i2c_client *client) { - struct device_node *np = client->dev.of_node; - struct tsc2007 *ts = i2c_get_clientdata(client); - struct tsc2007_platform_data *pdata = client->dev.platform_data; + const struct tsc2007_platform_data *pdata = dev_get_platdata(&client->dev); + struct tsc2007 *ts = i2c_get_clientdata(client); free_irq(ts->irq, ts); - if (!np) { - if (pdata->exit_platform_hw) - pdata->exit_platform_hw(); - } + if (pdata && pdata->exit_platform_hw) + pdata->exit_platform_hw(); input_unregister_device(ts->input); kfree(ts); diff --git a/include/linux/i2c/tsc2007.h b/include/linux/i2c/tsc2007.h index 506a9f7..041c8e8 100644 --- a/include/linux/i2c/tsc2007.h +++ b/include/linux/i2c/tsc2007.h @@ -14,9 +14,9 @@ struct tsc2007_platform_data { int fuzzy; int fuzzz; - int (*get_pendown_state)(void); - void (*clear_penirq)(void); /* If needed, clear 2nd level - interrupt source */ + int (*get_pendown_state)(struct device *); + /* If needed, clear 2nd level interrupt source */ + void (*clear_penirq)(void); int (*init_platform_hw)(void); void (*exit_platform_hw)(void); };