From patchwork Fri Feb 1 08:11:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kurtz X-Patchwork-Id: 2077591 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 49CC7DFE75 for ; Fri, 1 Feb 2013 08:12:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755969Ab3BAIMU (ORCPT ); Fri, 1 Feb 2013 03:12:20 -0500 Received: from mail-pb0-f41.google.com ([209.85.160.41]:52450 "EHLO mail-pb0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755925Ab3BAIMM (ORCPT ); Fri, 1 Feb 2013 03:12:12 -0500 Received: by mail-pb0-f41.google.com with SMTP id ro12so2062961pbb.0 for ; Fri, 01 Feb 2013 00:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=oPnjZJfc1xl5PS/QaXD+lVhPRqeyv9SnP/fIENdCsWc=; b=Dj4pygjNRSKQWgYgcKWbqgcz2WdlYN6sId/v0iWgvS2XQz0VgaVcBVP8lkcbluh4yJ CAVPqBkjQKR14U7DcmRfezQ23lKGSLbOMxiZR8KFL/wCg6oByL5BdHGNTeZ314li+kYz ny9eS9A8qDoL3KgK/LkwzNxQS7NKsoEGCNwmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=oPnjZJfc1xl5PS/QaXD+lVhPRqeyv9SnP/fIENdCsWc=; b=DuLlFhlSeLxGm4jqYnAH0RvDD5X+tlF7NxyAAmudDSRiJsy3PpGj7om6HW51EVKK8w 246YtjuLDzisuAGq9J2+81lmNNJTS6PaDlLOhbxKcVHxnm1DNojswOjHEviCfjKkW6XL MInYMNKRbwpJrpinA8FCTOrY2+EXw247+mqO8enLvSdbSem48c+F7UCSkt+0wXst6JEw PcVsaQSx3ob8CFcUA2ET/F0hafqy7yiAnehcRkPXwpQfyKY7DNmI1Aahki3RJmC5p4As msFca2RQ0fRQzDwovRyne5d8IrOZP5005TbakQiW74/FIiPlu8mt2rDkA3Uc96PuuhT4 H2Mw== X-Received: by 10.68.233.7 with SMTP id ts7mr29883078pbc.136.1359706332038; Fri, 01 Feb 2013 00:12:12 -0800 (PST) Received: from djkurtz-z620.tpe.corp.google.com (djkurtz-z620.tpe.corp.google.com [172.30.210.61]) by mx.google.com with ESMTPS id bi8sm8398002pab.15.2013.02.01.00.12.08 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Feb 2013 00:12:11 -0800 (PST) From: Daniel Kurtz To: Dmitry Torokhov , Henrik Rydberg , Benson Leung , Yufeng Shen , Nick Dyer Cc: Joonyoung Shim , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, olofj@chromium.org, Daniel Kurtz Subject: [PATCH 03/10] Input: atmel_mxt_ts - refactor input device creation Date: Fri, 1 Feb 2013 16:11:45 +0800 Message-Id: <1359706312-24642-4-git-send-email-djkurtz@chromium.org> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1359706312-24642-1-git-send-email-djkurtz@chromium.org> References: <1359706312-24642-1-git-send-email-djkurtz@chromium.org> X-Gm-Message-State: ALoCoQm0McHnQOADjcbGUFMP9RQr00HAlxeJAy/lb+2LTxHnhOWoxq5Lpu2X1R1K9vdNxZ4GiU3P Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Move input device initialization to its own helper function. This is in preparation of a future patch that makes input device conditional on the device not being in its bootloader. Signed-off-by: Daniel Kurtz --- drivers/input/touchscreen/atmel_mxt_ts.c | 91 ++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 84f0408..9afc26e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1111,52 +1111,23 @@ static void mxt_input_close(struct input_dev *dev) mxt_stop(data); } -static int mxt_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int mxt_input_dev_create(struct mxt_data *data) { - const struct mxt_platform_data *pdata = client->dev.platform_data; - struct mxt_data *data; struct input_dev *input_dev; int error; unsigned int num_mt_slots; - if (!pdata) - return -EINVAL; - - data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); - if (!data) { - dev_err(&client->dev, "Failed to allocate memory\n"); + data->input_dev = input_dev = input_allocate_device(); + if (!input_dev) return -ENOMEM; - } - - input_dev = input_allocate_device(); - if (!input_dev) { - dev_err(&client->dev, "Failed to allocate memory\n"); - error = -ENOMEM; - goto err_free_mem; - } input_dev->name = "Atmel maXTouch Touchscreen"; - snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", - client->adapter->nr, client->addr); input_dev->phys = data->phys; - input_dev->id.bustype = BUS_I2C; - input_dev->dev.parent = &client->dev; + input_dev->dev.parent = &data->client->dev; input_dev->open = mxt_input_open; input_dev->close = mxt_input_close; - data->client = client; - data->input_dev = input_dev; - data->pdata = pdata; - data->irq = client->irq; - - mxt_calc_resolution(data); - - error = mxt_initialize(data); - if (error) - goto err_free_mem; - __set_bit(EV_ABS, input_dev->evbit); __set_bit(EV_KEY, input_dev->evbit); __set_bit(BTN_TOUCH, input_dev->keybit); @@ -1172,10 +1143,8 @@ static int mxt_probe(struct i2c_client *client, /* For multi touch */ num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; error = input_mt_init_slots(input_dev, num_mt_slots, 0); - if (error) { - input_free_device(input_dev); - goto err_free_object; - } + if (error) + goto err_free_device; input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, MXT_MAX_AREA, 0, 0); @@ -1187,14 +1156,54 @@ static int mxt_probe(struct i2c_client *client, 0, 255, 0, 0); input_set_drvdata(input_dev, data); - i2c_set_clientdata(client, data); error = input_register_device(input_dev); - if (error) { - input_free_device(input_dev); - goto err_free_object; + if (error) + goto err_free_device; + + return 0; + +err_free_device: + input_free_device(data->input_dev); + data->input_dev = NULL; + return error; +} + +static int __devinit mxt_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + const struct mxt_platform_data *pdata = client->dev.platform_data; + struct mxt_data *data; + int error; + + if (!pdata) + return -EINVAL; + + data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); + if (!data) { + dev_err(&client->dev, "Failed to allocate memory\n"); + return -ENOMEM; } + snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", + client->adapter->nr, client->addr); + + data->client = client; + i2c_set_clientdata(client, data); + + data->pdata = pdata; + data->irq = client->irq; + + mxt_calc_resolution(data); + + error = mxt_initialize(data); + if (error) + goto err_free_mem; + + error = mxt_input_dev_create(data); + if (error) + goto err_free_object; + error = request_threaded_irq(client->irq, NULL, mxt_interrupt, pdata->irqflags | IRQF_ONESHOT, client->name, data);